LibreOffice Module registry (master) 1
registry.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#include <registry/registry.hxx>
22
23#include "keyimpl.hxx"
24#include "regimpl.hxx"
25#include "regkey.hxx"
26
27#if defined(_WIN32)
28#include <io.h>
29#endif
30
31extern "C" {
32
34{
35 ORegistry* pReg = static_cast<ORegistry*>(hReg);
36
37 if (pReg != nullptr)
38 pReg->acquire();
39}
40
42{
43 ORegistry* pReg = static_cast<ORegistry*>(hReg);
44
45 if (pReg && pReg->release() == 0)
46 {
47 delete pReg;
48 hReg = nullptr;
49 }
50}
51
52static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
53{
54 if (hReg)
55 {
56 ORegistry* pReg = static_cast<ORegistry*>(hReg);
57 if ( pReg->isOpen() )
58 {
59 rtl_uString_assign(pName, pReg->getName().pData);
60 return RegError::NO_ERROR;
61 } else
62 {
63 rtl_uString_new(pName);
65 }
66 }
67
68 rtl_uString_new(pName);
70}
71
73{
74 if (hReg)
75 return static_cast<ORegistry*>(hReg)->isReadOnly();
76 else
77 return false;
78}
79
80static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
81 RegHandle* phRegistry)
82{
83 RegError ret;
84
85 ORegistry* pReg = new ORegistry();
86 if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)) != RegError::NO_ERROR)
87 {
88 delete pReg;
89 *phRegistry = nullptr;
90 return ret;
91 }
92
93 *phRegistry = pReg;
94
95 return RegError::NO_ERROR;
96}
97
99 RegKeyHandle* phRootKey)
100{
101 ORegistry* pReg;
102
103 if (hReg)
104 {
105 pReg = static_cast<ORegistry*>(hReg);
106 if (!pReg->isOpen())
108 } else
109 {
110 phRootKey = nullptr;
112 }
113
114 *phRootKey = pReg->getRootKey();
115
116 return RegError::NO_ERROR;
117}
118
119static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
120 RegHandle* phRegistry,
121 RegAccessMode accessMode)
122{
123 RegError _ret;
124
125 ORegistry* pReg = new ORegistry();
126 if ((_ret = pReg->initRegistry(registryName, accessMode)) != RegError::NO_ERROR)
127 {
128 *phRegistry = nullptr;
129 delete pReg;
130 return _ret;
131 }
132
133
134 *phRegistry = pReg;
135
136 return RegError::NO_ERROR;
137}
138
140{
141 if (hReg)
142 {
143 ORegistry *pReg = static_cast<ORegistry*>(hReg);
144 if (!pReg->isOpen())
146
148 if (pReg->release() == 0)
149 {
150 delete pReg;
151 hReg = nullptr;
152 }
153 else
154 ret = pReg->closeRegistry();
155
156 return ret;
157 } else
158 {
160 }
161}
162
164 rtl_uString* registryName)
165{
166 if (hReg)
167 {
168 ORegistry *pReg = static_cast<ORegistry*>(hReg);
169 if (!pReg->isOpen())
171
172 RegError ret = pReg->destroyRegistry(registryName);
173 if (ret == RegError::NO_ERROR)
174 {
175 if (!registryName->length)
176 {
177 delete pReg;
178 hReg = nullptr;
179 }
180 }
181 return ret;
182 } else
183 {
185 }
186}
187
188
189// dumpRegistry
190
192 RegKeyHandle hKey)
193{
194 ORegistry* pReg = static_cast< ORegistry* >(hReg);
195 if (!pReg)
197 if (!pReg->isOpen())
199
200 ORegKey* pKey = static_cast< ORegKey* >(hKey);
201 if (!pKey)
203 if (pKey->getRegistry() != pReg)
205 if (pKey->isDeleted())
207
208 return pReg->dumpRegistry(hKey);
209}
210
212{
213 static Registry_Api aApi= {&acquire,
214 &release,
215 &isReadOnly,
217 &getName,
222 &acquireKey,
223 &releaseKey,
225 &getKeyName,
226 &createKey,
227 &openKey,
230 &deleteKey,
231 &closeKey,
232 &setValue,
237 &getValue,
244 &freeKeyNames};
245
246 return (&aApi);
247}
248
249}
250
252 RegKeyHandle* phRootKey)
253{
254 return openRootKey(hRegistry, phRootKey);
255}
256
258 RegHandle* phRegistry)
259{
260 RegError _ret;
261
262 ORegistry* pReg = new ORegistry();
263 if ((_ret = pReg->initRegistry(registryName, RegAccessMode::READONLY)) != RegError::NO_ERROR)
264 {
265 delete pReg;
266 *phRegistry = nullptr;
267 return _ret;
268 }
269
270 *phRegistry = pReg;
271
272 return RegError::NO_ERROR;
273}
274
276{
277 if (hRegistry)
278 {
279 ORegistry* pReg = static_cast<ORegistry*>(hRegistry);
280 delete pReg;
281 return RegError::NO_ERROR;
282 } else
283 {
285 }
286}
287
289{
290 ORegKey *pKey;
291
292 if (hKey)
293 pKey = static_cast<ORegKey*>(hKey);
294 else
296
297 return dumpRegistry(pKey->getRegistry(), hKey);
298}
299
300
301/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
ORegistry * getRegistry() const
Definition: keyimpl.hxx:116
bool isDeleted() const
Definition: keyimpl.hxx:99
ORegKey * getRootKey()
Definition: regimpl.cxx:849
RegError initRegistry(const OUString &name, RegAccessMode accessMode, bool bCreate=false)
Definition: regimpl.cxx:437
bool isOpen() const
Definition: regimpl.hxx:84
RegError dumpRegistry(RegKeyHandle hKey) const
Definition: regimpl.cxx:855
sal_uInt32 acquire()
Definition: regimpl.hxx:48
sal_uInt32 release()
Definition: regimpl.hxx:51
const OUString & getName() const
Definition: regimpl.hxx:92
RegError destroyRegistry(const OUString &name)
Definition: regimpl.cxx:516
RegError closeRegistry()
Definition: regimpl.cxx:500
RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey)
This function reports the complete registry information of a key and all of its subkeys.
Definition: registry.cxx:288
RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString *registryName, RegHandle *phRegistry)
This function opens a registry with the specified name.
Definition: registry.cxx:257
Registry_Api *REGISTRY_CALLTYPE initRegistry_Api()
the API initialization function.
Definition: registry.cxx:211
static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
Definition: registry.cxx:139
static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString *registryName, RegHandle *phRegistry)
Definition: registry.cxx:80
static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
Definition: registry.cxx:72
static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg, RegKeyHandle *phRootKey)
Definition: registry.cxx:98
static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString *registryName, RegHandle *phRegistry, RegAccessMode accessMode)
Definition: registry.cxx:119
static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
Definition: registry.cxx:33
RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry, RegKeyHandle *phRootKey)
This function opens the root key of a registry.
Definition: registry.cxx:251
RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
This function closes a registry.
Definition: registry.cxx:275
static void REGISTRY_CALLTYPE release(RegHandle hReg)
Definition: registry.cxx:41
static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString **pName)
Definition: registry.cxx:52
static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg, rtl_uString *registryName)
Definition: registry.cxx:163
static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg, RegKeyHandle hKey)
Definition: registry.cxx:191
RegError REGISTRY_CALLTYPE setUnicodeListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Unicode **pValueList, sal_uInt32 len)
Definition: regkey.cxx:279
RegError REGISTRY_CALLTYPE setLongListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Int32 const *pValueList, sal_uInt32 len)
Definition: regkey.cxx:201
RegError REGISTRY_CALLTYPE createKey(RegKeyHandle hKey, rtl_uString *keyName, RegKeyHandle *phNewKey)
Definition: regkey.cxx:67
RegError REGISTRY_CALLTYPE setStringListValue(RegKeyHandle hKey, rtl_uString *keyName, char **pValueList, sal_uInt32 len)
Definition: regkey.cxx:240
void REGISTRY_CALLTYPE acquireKey(RegKeyHandle hKey)
Definition: regkey.cxx:27
RegError REGISTRY_CALLTYPE getValueInfo(RegKeyHandle hKey, rtl_uString *keyName, RegValueType *pValueType, sal_uInt32 *pValueSize)
Definition: regkey.cxx:318
RegError REGISTRY_CALLTYPE getStringListValue(RegKeyHandle hKey, rtl_uString *keyName, char ***pValueList, sal_uInt32 *pLen)
Definition: regkey.cxx:437
void REGISTRY_CALLTYPE releaseKey(RegKeyHandle hKey)
Definition: regkey.cxx:37
RegError REGISTRY_CALLTYPE getKeyNames(RegKeyHandle hKey, rtl_uString *keyName, rtl_uString ***pSubKeyNames, sal_uInt32 *pnSubKeys)
Definition: regkey.cxx:571
RegError REGISTRY_CALLTYPE getLongListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Int32 **pValueList, sal_uInt32 *pLen)
Definition: regkey.cxx:400
RegError REGISTRY_CALLTYPE getKeyName(RegKeyHandle hKey, rtl_uString **pKeyName)
Definition: regkey.cxx:53
RegError REGISTRY_CALLTYPE deleteKey(RegKeyHandle hKey, rtl_uString *keyName)
Definition: regkey.cxx:136
RegError REGISTRY_CALLTYPE getResolvedKeyName(RegKeyHandle hKey, rtl_uString *keyName, SAL_UNUSED_PARAMETER sal_Bool, rtl_uString **pResolvedName)
Definition: regkey.cxx:552
RegError REGISTRY_CALLTYPE closeSubKeys(RegKeyHandle *phSubKeys, sal_uInt32 nSubKeys)
Definition: regkey.cxx:120
RegError REGISTRY_CALLTYPE freeKeyNames(rtl_uString **pKeyNames, sal_uInt32 nKeys)
Definition: regkey.cxx:586
RegError REGISTRY_CALLTYPE freeValueList(RegValueType valueType, RegValue pValueList, sal_uInt32 len)
Definition: regkey.cxx:511
sal_Bool REGISTRY_CALLTYPE isKeyReadOnly(RegKeyHandle hKey)
Definition: regkey.cxx:47
RegError REGISTRY_CALLTYPE openKey(RegKeyHandle hKey, rtl_uString *keyName, RegKeyHandle *phOpenKey)
Definition: regkey.cxx:86
RegError REGISTRY_CALLTYPE openSubKeys(RegKeyHandle hKey, rtl_uString *keyName, RegKeyHandle **pphSubKeys, sal_uInt32 *pnSubKeys)
Definition: regkey.cxx:102
RegError REGISTRY_CALLTYPE closeKey(RegKeyHandle hKey)
Definition: regkey.cxx:152
RegError REGISTRY_CALLTYPE getValue(RegKeyHandle hKey, rtl_uString *keyName, RegValue pValue)
Definition: regkey.cxx:368
RegError REGISTRY_CALLTYPE getUnicodeListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Unicode ***pValueList, sal_uInt32 *pLen)
Definition: regkey.cxx:474
RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, rtl_uString *keyName, RegValueType valueType, RegValue pData, sal_uInt32 valueSize)
Definition: regkey.cxx:161
void * RegHandle
defines the type of a registry handle used in the C API.
Definition: regtype.h:26
INVALID_REGISTRY
registry is in an invalid state or the registry does not point to a valid registry data file.
Definition: regtype.h:101
void * RegKeyHandle
defines the type of a registry key handle used in the C API.
Definition: regtype.h:29
REGISTRY_NOT_OPEN
registry is not open.
Definition: regtype.h:87
INVALID_KEY
the key is not in a valid state.
Definition: regtype.h:116
RegAccessMode
defines the open/access mode of the registry.
Definition: regtype.h:41
@ READWRITE
This mode allows readonly access.
#define REGISTRY_CALLTYPE
specify the calling convention for the registry API
Definition: regtype.h:129
NO_ERROR
no error.
Definition: regtype.h:84
enum SAL_DLLPUBLIC_RTTI RegError
specifies the possible error codes which can occur using the registry API.
Definition: regtype.h:82
specifies a collection of function pointers which represents the complete registry C-API.
Definition: registry.hxx:33
unsigned char sal_Bool