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 
31 extern "C" {
32 
33 
34 // acquire
35 
37 {
38  ORegistry* pReg = static_cast<ORegistry*>(hReg);
39 
40  if (pReg != nullptr)
41  pReg->acquire();
42 }
43 
44 
45 // release
46 
48 {
49  ORegistry* pReg = static_cast<ORegistry*>(hReg);
50 
51  if (pReg && pReg->release() == 0)
52  {
53  delete pReg;
54  hReg = nullptr;
55  }
56 }
57 
58 
59 // getName
60 
61 static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
62 {
63  if (hReg)
64  {
65  ORegistry* pReg = static_cast<ORegistry*>(hReg);
66  if ( pReg->isOpen() )
67  {
68  rtl_uString_assign(pName, pReg->getName().pData);
69  return RegError::NO_ERROR;
70  } else
71  {
72  rtl_uString_new(pName);
74  }
75  }
76 
77  rtl_uString_new(pName);
79 }
80 
81 
82 // isReadOnly
83 
85 {
86  if (hReg)
87  return static_cast<ORegistry*>(hReg)->isReadOnly();
88  else
89  return false;
90 }
91 
92 
93 // createRegistry
94 
95 static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
96  RegHandle* phRegistry)
97 {
98  RegError ret;
99 
100  ORegistry* pReg = new ORegistry();
101  if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)) != RegError::NO_ERROR)
102  {
103  delete pReg;
104  *phRegistry = nullptr;
105  return ret;
106  }
107 
108  *phRegistry = pReg;
109 
110  return RegError::NO_ERROR;
111 }
112 
113 
114 // openRootKey
115 
117  RegKeyHandle* phRootKey)
118 {
119  ORegistry* pReg;
120 
121  if (hReg)
122  {
123  pReg = static_cast<ORegistry*>(hReg);
124  if (!pReg->isOpen())
126  } else
127  {
128  phRootKey = nullptr;
130  }
131 
132  *phRootKey = pReg->getRootKey();
133 
134  return RegError::NO_ERROR;
135 }
136 
137 
138 // openRegistry
139 
140 static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
141  RegHandle* phRegistry,
142  RegAccessMode accessMode)
143 {
144  RegError _ret;
145 
146  ORegistry* pReg = new ORegistry();
147  if ((_ret = pReg->initRegistry(registryName, accessMode)) != RegError::NO_ERROR)
148  {
149  *phRegistry = nullptr;
150  delete pReg;
151  return _ret;
152  }
153 
154 
155  *phRegistry = pReg;
156 
157  return RegError::NO_ERROR;
158 }
159 
160 
161 // closeRegistry
162 
164 {
165  ORegistry *pReg;
166 
167  if (hReg)
168  {
169  pReg = static_cast<ORegistry*>(hReg);
170  if (!pReg->isOpen())
172 
174  if (pReg->release() == 0)
175  {
176  delete pReg;
177  hReg = nullptr;
178  }
179  else
180  ret = pReg->closeRegistry();
181 
182  return ret;
183  } else
184  {
186  }
187 }
188 
189 
190 // destroyRegistry
191 
193  rtl_uString* registryName)
194 {
195  ORegistry *pReg;
196 
197  if (hReg)
198  {
199  pReg = static_cast<ORegistry*>(hReg);
200  if (!pReg->isOpen())
202 
203  RegError ret = pReg->destroyRegistry(registryName);
204  if (ret == RegError::NO_ERROR)
205  {
206  if (!registryName->length)
207  {
208  delete pReg;
209  hReg = nullptr;
210  }
211  }
212  return ret;
213  } else
214  {
216  }
217 }
218 
219 
220 // mergeKey
221 
223  RegKeyHandle hKey,
224  rtl_uString* keyName,
225  rtl_uString* regFileName,
226  sal_Bool bWarnings,
227  sal_Bool bReport)
228 {
229  ORegistry* pReg = static_cast< ORegistry* >(hReg);
230  if (!pReg)
232  if (!pReg->isOpen())
234 
235  ORegKey* pKey = static_cast< ORegKey* >(hKey);
236  if (!pKey)
237  return RegError::INVALID_KEY;
238  if (pKey->getRegistry() != pReg)
239  return RegError::INVALID_KEY;
240  if (pKey->isDeleted())
241  return RegError::INVALID_KEY;
242  if (pKey->isReadOnly())
244 
245  if (keyName->length)
246  {
247  ORegKey* pNewKey = nullptr;
248  RegError _ret = pKey->createKey(keyName, reinterpret_cast<RegKeyHandle*>(&pNewKey));
249  if (_ret != RegError::NO_ERROR)
250  return _ret;
251 
252  _ret = pReg->loadKey(pNewKey, regFileName, bWarnings, bReport);
253  if (_ret != RegError::NO_ERROR && (_ret != RegError::MERGE_CONFLICT || bWarnings))
254  {
255  if (pNewKey != pKey)
256  (void) pKey->closeKey(pNewKey);
257  else
258  (void) pKey->releaseKey(pNewKey);
259  return _ret;
260  }
261 
262  return (pNewKey != pKey) ? pKey->closeKey(pNewKey) : pKey->releaseKey(pNewKey);
263  }
264 
265  return pReg->loadKey(pKey, regFileName, bWarnings, bReport);
266 }
267 
268 
269 // dumpRegistry
270 
272  RegKeyHandle hKey)
273 {
274  ORegistry* pReg = static_cast< ORegistry* >(hReg);
275  if (!pReg)
277  if (!pReg->isOpen())
279 
280  ORegKey* pKey = static_cast< ORegKey* >(hKey);
281  if (!pKey)
282  return RegError::INVALID_KEY;
283  if (pKey->getRegistry() != pReg)
284  return RegError::INVALID_KEY;
285  if (pKey->isDeleted())
286  return RegError::INVALID_KEY;
287 
288  return pReg->dumpRegistry(hKey);
289 }
290 
291 
292 // initRegistry_Api
293 
295 {
296  static Registry_Api aApi= {&acquire,
297  &release,
298  &isReadOnly,
299  &openRootKey,
300  &getName,
302  &openRegistry,
303  &closeRegistry,
305  &mergeKey,
306  &acquireKey,
307  &releaseKey,
308  &isKeyReadOnly,
309  &getKeyName,
310  &createKey,
311  &openKey,
312  &openSubKeys,
313  &closeSubKeys,
314  &deleteKey,
315  &closeKey,
316  &setValue,
320  &getValueInfo,
321  &getValue,
325  &freeValueList,
327  &getKeyNames,
328  &freeKeyNames};
329 
330  return (&aApi);
331 }
332 
333 }
334 
335 
336 // reg_openRootKey
337 
339  RegKeyHandle* phRootKey)
340 {
341  return openRootKey(hRegistry, phRootKey);
342 }
343 
344 
345 // reg_openRegistry
346 
347 RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
348  RegHandle* phRegistry)
349 {
350  RegError _ret;
351 
352  ORegistry* pReg = new ORegistry();
353  if ((_ret = pReg->initRegistry(registryName, RegAccessMode::READONLY)) != RegError::NO_ERROR)
354  {
355  delete pReg;
356  *phRegistry = nullptr;
357  return _ret;
358  }
359 
360  *phRegistry = pReg;
361 
362  return RegError::NO_ERROR;
363 }
364 
365 
366 // reg_closeRegistry
367 
369 {
370  if (hRegistry)
371  {
372  ORegistry* pReg = static_cast<ORegistry*>(hRegistry);
373  delete pReg;
374  return RegError::NO_ERROR;
375  } else
376  {
378  }
379 }
380 
381 
382 // reg_dumpRegistry
383 
385 {
386  ORegKey *pKey;
387 
388  if (hKey)
389  pKey = static_cast<ORegKey*>(hKey);
390  else
391  return RegError::INVALID_KEY;
392 
393  return dumpRegistry(pKey->getRegistry(), hKey);
394 }
395 
396 
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, rtl_uString *keyName, RegValueType valueType, RegValue pData, sal_uInt32 valueSize)
Definition: regkey.cxx:194
static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg, RegKeyHandle *phRootKey)
Definition: registry.cxx:116
NO_ERROR
no error.
Definition: regtype.h:83
sal_uInt32 acquire()
Definition: regimpl.hxx:47
RegError REGISTRY_CALLTYPE getStringListValue(RegKeyHandle hKey, rtl_uString *keyName, char ***pValueList, sal_uInt32 *pLen)
Definition: regkey.cxx:491
Registry_Api *REGISTRY_CALLTYPE initRegistry_Api()
the API initialization function.
Definition: registry.cxx:294
RegAccessMode
defines the open/access mode of the registry.
Definition: regtype.h:41
sal_Bool REGISTRY_CALLTYPE isKeyReadOnly(RegKeyHandle hKey)
Definition: regkey.cxx:56
const OUString & getName() const
Definition: regimpl.hxx:96
RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry, RegKeyHandle *phRootKey)
This function opens the root key of a registry.
Definition: registry.cxx:338
MERGE_CONFLICT
conflicts exists during the merge process of a key.
Definition: regtype.h:83
RegError REGISTRY_CALLTYPE closeKey(RegKeyHandle hKey)
Definition: regkey.cxx:182
RegError releaseKey(RegKeyHandle hKey)
Definition: keyimpl.cxx:60
static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString *registryName, RegHandle *phRegistry, RegAccessMode accessMode)
Definition: registry.cxx:140
RegError REGISTRY_CALLTYPE getUnicodeListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Unicode ***pValueList, sal_uInt32 *pLen)
Definition: regkey.cxx:529
static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
Definition: registry.cxx:36
ORegKey * getRootKey()
Definition: regimpl.cxx:1248
bool isDeleted() const
Definition: keyimpl.hxx:95
specifies a collection of function pointers which represents the complete registry C-API...
Definition: registry.hxx:32
RegError REGISTRY_CALLTYPE getValue(RegKeyHandle hKey, rtl_uString *keyName, RegValue pValue)
Definition: regkey.cxx:416
REGISTRY_NOT_OPEN
registry is not open.
Definition: regtype.h:83
RegError REGISTRY_CALLTYPE getResolvedKeyName(RegKeyHandle hKey, rtl_uString *keyName, SAL_UNUSED_PARAMETER sal_Bool, rtl_uString **pResolvedName)
Definition: regkey.cxx:613
static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
Definition: registry.cxx:84
void * RegHandle
defines the type of a registry handle used in the C API.
Definition: regtype.h:27
This mode allows readonly access.
RegError closeRegistry()
Definition: regimpl.cxx:502
RegError REGISTRY_CALLTYPE setUnicodeListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Unicode **pValueList, sal_uInt32 len)
Definition: regkey.cxx:321
enum SAL_DLLPUBLIC_RTTI RegError
specifies the possible error codes which can occur using the registry API.
Definition: regtype.h:80
RegError REGISTRY_CALLTYPE openKey(RegKeyHandle hKey, rtl_uString *keyName, RegKeyHandle *phOpenKey)
Definition: regkey.cxx:104
RegError closeKey(RegKeyHandle hKey)
Definition: keyimpl.cxx:204
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:384
sal_uInt16 char * pName
bool isReadOnly() const
Definition: keyimpl.hxx:107
RegError REGISTRY_CALLTYPE closeSubKeys(RegKeyHandle *phSubKeys, sal_uInt32 nSubKeys)
Definition: regkey.cxx:144
static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg, rtl_uString *registryName)
Definition: registry.cxx:192
bool isOpen() const
Definition: regimpl.hxx:88
RegError createKey(const OUString &keyName, RegKeyHandle *phNewKey)
Definition: keyimpl.cxx:68
unsigned char sal_Bool
RegError dumpRegistry(RegKeyHandle hKey) const
Definition: regimpl.cxx:1254
void REGISTRY_CALLTYPE acquireKey(RegKeyHandle hKey)
Definition: regkey.cxx:30
RegError REGISTRY_CALLTYPE setStringListValue(RegKeyHandle hKey, rtl_uString *keyName, char **pValueList, sal_uInt32 len)
Definition: regkey.cxx:279
RegError REGISTRY_CALLTYPE deleteKey(RegKeyHandle hKey, rtl_uString *keyName)
Definition: regkey.cxx:163
RegError REGISTRY_CALLTYPE freeValueList(RegValueType valueType, RegValue pValueList, sal_uInt32 len)
Definition: regkey.cxx:569
RegError loadKey(RegKeyHandle hKey, const OUString &regFileName, bool bWarnings, bool bReport)
Definition: regimpl.cxx:851
RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString *registryName, RegHandle *phRegistry)
This function opens a registry with the specified name.
Definition: registry.cxx:347
RegError REGISTRY_CALLTYPE setLongListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Int32 const *pValueList, sal_uInt32 len)
Definition: regkey.cxx:237
static void REGISTRY_CALLTYPE release(RegHandle hReg)
Definition: registry.cxx:47
INVALID_KEY
the key is not in a valid state.
Definition: regtype.h:83
static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
Definition: registry.cxx:163
static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg, RegKeyHandle hKey)
Definition: registry.cxx:271
static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString **pName)
Definition: registry.cxx:61
void * RegKeyHandle
defines the type of a registry key handle used in the C API.
Definition: regtype.h:30
REGISTRY_READONLY
registry is open with readonly access rights.
Definition: regtype.h:83
ORegistry * getRegistry() const
Definition: keyimpl.hxx:112
void REGISTRY_CALLTYPE releaseKey(RegKeyHandle hKey)
Definition: regkey.cxx:43
static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg, RegKeyHandle hKey, rtl_uString *keyName, rtl_uString *regFileName, sal_Bool bWarnings, sal_Bool bReport)
Definition: registry.cxx:222
RegError REGISTRY_CALLTYPE openSubKeys(RegKeyHandle hKey, rtl_uString *keyName, RegKeyHandle **pphSubKeys, sal_uInt32 *pnSubKeys)
Definition: regkey.cxx:123
sal_uInt32 release()
Definition: regimpl.hxx:50
RegError REGISTRY_CALLTYPE getLongListValue(RegKeyHandle hKey, rtl_uString *keyName, sal_Int32 **pValueList, sal_uInt32 *pLen)
Definition: regkey.cxx:451
RegError REGISTRY_CALLTYPE getKeyNames(RegKeyHandle hKey, rtl_uString *keyName, rtl_uString ***pSubKeyNames, sal_uInt32 *pnSubKeys)
Definition: regkey.cxx:635
RegError initRegistry(const OUString &name, RegAccessMode accessMode, bool bCreate=false)
Definition: regimpl.cxx:439
RegError destroyRegistry(const OUString &name)
Definition: regimpl.cxx:518
RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
This function closes a registry.
Definition: registry.cxx:368
static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString *registryName, RegHandle *phRegistry)
Definition: registry.cxx:95
#define REGISTRY_CALLTYPE
specify the calling convention for the registry API
Definition: regtype.h:135
RegError REGISTRY_CALLTYPE getKeyName(RegKeyHandle hKey, rtl_uString **pKeyName)
Definition: regkey.cxx:65
INVALID_REGISTRY
registry is in an invalid state or the registry does not point to a valid registry data file...
Definition: regtype.h:83
RegError REGISTRY_CALLTYPE getValueInfo(RegKeyHandle hKey, rtl_uString *keyName, RegValueType *pValueType, sal_uInt32 *pValueSize)
Definition: regkey.cxx:363
RegError REGISTRY_CALLTYPE createKey(RegKeyHandle hKey, rtl_uString *keyName, RegKeyHandle *phNewKey)
Definition: regkey.cxx:82
RegError REGISTRY_CALLTYPE freeKeyNames(rtl_uString **pKeyNames, sal_uInt32 nKeys)
Definition: regkey.cxx:653
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo