nss: upgrade to release 3.73
[LibreOffice.git] / registry / source / registry.cxx
blobeb2a38f6ba5a03829acf000be064f6aad4659432
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <registry/registry.hxx>
23 #include "keyimpl.hxx"
24 #include "regimpl.hxx"
25 #include "regkey.hxx"
27 #if defined(_WIN32)
28 #include <io.h>
29 #endif
31 extern "C" {
34 // acquire
36 static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
38 ORegistry* pReg = static_cast<ORegistry*>(hReg);
40 if (pReg != nullptr)
41 pReg->acquire();
45 // release
47 static void REGISTRY_CALLTYPE release(RegHandle hReg)
49 ORegistry* pReg = static_cast<ORegistry*>(hReg);
51 if (pReg && pReg->release() == 0)
53 delete pReg;
54 hReg = nullptr;
59 // getName
61 static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
63 if (hReg)
65 ORegistry* pReg = static_cast<ORegistry*>(hReg);
66 if ( pReg->isOpen() )
68 rtl_uString_assign(pName, pReg->getName().pData);
69 return RegError::NO_ERROR;
70 } else
72 rtl_uString_new(pName);
73 return RegError::REGISTRY_NOT_OPEN;
77 rtl_uString_new(pName);
78 return RegError::INVALID_REGISTRY;
82 // isReadOnly
84 static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
86 if (hReg)
87 return static_cast<ORegistry*>(hReg)->isReadOnly();
88 else
89 return false;
93 // createRegistry
95 static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
96 RegHandle* phRegistry)
98 RegError ret;
100 ORegistry* pReg = new ORegistry();
101 if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)) != RegError::NO_ERROR)
103 delete pReg;
104 *phRegistry = nullptr;
105 return ret;
108 *phRegistry = pReg;
110 return RegError::NO_ERROR;
114 // openRootKey
116 static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg,
117 RegKeyHandle* phRootKey)
119 ORegistry* pReg;
121 if (hReg)
123 pReg = static_cast<ORegistry*>(hReg);
124 if (!pReg->isOpen())
125 return RegError::REGISTRY_NOT_OPEN;
126 } else
128 phRootKey = nullptr;
129 return RegError::INVALID_REGISTRY;
132 *phRootKey = pReg->getRootKey();
134 return RegError::NO_ERROR;
138 // openRegistry
140 static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
141 RegHandle* phRegistry,
142 RegAccessMode accessMode)
144 RegError _ret;
146 ORegistry* pReg = new ORegistry();
147 if ((_ret = pReg->initRegistry(registryName, accessMode)) != RegError::NO_ERROR)
149 *phRegistry = nullptr;
150 delete pReg;
151 return _ret;
155 *phRegistry = pReg;
157 return RegError::NO_ERROR;
161 // closeRegistry
163 static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
165 if (hReg)
167 ORegistry *pReg = static_cast<ORegistry*>(hReg);
168 if (!pReg->isOpen())
169 return RegError::REGISTRY_NOT_OPEN;
171 RegError ret = RegError::NO_ERROR;
172 if (pReg->release() == 0)
174 delete pReg;
175 hReg = nullptr;
177 else
178 ret = pReg->closeRegistry();
180 return ret;
181 } else
183 return RegError::INVALID_REGISTRY;
188 // destroyRegistry
190 static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg,
191 rtl_uString* registryName)
193 if (hReg)
195 ORegistry *pReg = static_cast<ORegistry*>(hReg);
196 if (!pReg->isOpen())
197 return RegError::INVALID_REGISTRY;
199 RegError ret = pReg->destroyRegistry(registryName);
200 if (ret == RegError::NO_ERROR)
202 if (!registryName->length)
204 delete pReg;
205 hReg = nullptr;
208 return ret;
209 } else
211 return RegError::INVALID_REGISTRY;
216 // mergeKey
218 static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg,
219 RegKeyHandle hKey,
220 rtl_uString* keyName,
221 rtl_uString* regFileName,
222 sal_Bool bWarnings,
223 sal_Bool bReport)
225 ORegistry* pReg = static_cast< ORegistry* >(hReg);
226 if (!pReg)
227 return RegError::INVALID_REGISTRY;
228 if (!pReg->isOpen())
229 return RegError::REGISTRY_NOT_OPEN;
231 ORegKey* pKey = static_cast< ORegKey* >(hKey);
232 if (!pKey)
233 return RegError::INVALID_KEY;
234 if (pKey->getRegistry() != pReg)
235 return RegError::INVALID_KEY;
236 if (pKey->isDeleted())
237 return RegError::INVALID_KEY;
238 if (pKey->isReadOnly())
239 return RegError::REGISTRY_READONLY;
241 if (keyName->length)
243 ORegKey* pNewKey = nullptr;
244 RegError _ret = pKey->createKey(keyName, reinterpret_cast<RegKeyHandle*>(&pNewKey));
245 if (_ret != RegError::NO_ERROR)
246 return _ret;
248 _ret = pReg->loadKey(pNewKey, regFileName, bWarnings, bReport);
249 if (_ret != RegError::NO_ERROR && (_ret != RegError::MERGE_CONFLICT || bWarnings))
251 if (pNewKey != pKey)
252 (void) pKey->closeKey(pNewKey);
253 else
254 (void) pKey->releaseKey(pNewKey);
255 return _ret;
258 return (pNewKey != pKey) ? pKey->closeKey(pNewKey) : pKey->releaseKey(pNewKey);
261 return pReg->loadKey(pKey, regFileName, bWarnings, bReport);
265 // dumpRegistry
267 static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg,
268 RegKeyHandle hKey)
270 ORegistry* pReg = static_cast< ORegistry* >(hReg);
271 if (!pReg)
272 return RegError::INVALID_REGISTRY;
273 if (!pReg->isOpen())
274 return RegError::REGISTRY_NOT_OPEN;
276 ORegKey* pKey = static_cast< ORegKey* >(hKey);
277 if (!pKey)
278 return RegError::INVALID_KEY;
279 if (pKey->getRegistry() != pReg)
280 return RegError::INVALID_KEY;
281 if (pKey->isDeleted())
282 return RegError::INVALID_KEY;
284 return pReg->dumpRegistry(hKey);
288 // initRegistry_Api
290 Registry_Api* REGISTRY_CALLTYPE initRegistry_Api()
292 static Registry_Api aApi= {&acquire,
293 &release,
294 &isReadOnly,
295 &openRootKey,
296 &getName,
297 &createRegistry,
298 &openRegistry,
299 &closeRegistry,
300 &destroyRegistry,
301 &mergeKey,
302 &acquireKey,
303 &releaseKey,
304 &isKeyReadOnly,
305 &getKeyName,
306 &createKey,
307 &openKey,
308 &openSubKeys,
309 &closeSubKeys,
310 &deleteKey,
311 &closeKey,
312 &setValue,
313 &setLongListValue,
314 &setStringListValue,
315 &setUnicodeListValue,
316 &getValueInfo,
317 &getValue,
318 &getLongListValue,
319 &getStringListValue,
320 &getUnicodeListValue,
321 &freeValueList,
322 &getResolvedKeyName,
323 &getKeyNames,
324 &freeKeyNames};
326 return (&aApi);
332 // reg_openRootKey
334 RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
335 RegKeyHandle* phRootKey)
337 return openRootKey(hRegistry, phRootKey);
341 // reg_openRegistry
343 RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
344 RegHandle* phRegistry)
346 RegError _ret;
348 ORegistry* pReg = new ORegistry();
349 if ((_ret = pReg->initRegistry(registryName, RegAccessMode::READONLY)) != RegError::NO_ERROR)
351 delete pReg;
352 *phRegistry = nullptr;
353 return _ret;
356 *phRegistry = pReg;
358 return RegError::NO_ERROR;
362 // reg_closeRegistry
364 RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
366 if (hRegistry)
368 ORegistry* pReg = static_cast<ORegistry*>(hRegistry);
369 delete pReg;
370 return RegError::NO_ERROR;
371 } else
373 return RegError::REGISTRY_NOT_OPEN;
378 // reg_dumpRegistry
380 RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey)
382 ORegKey *pKey;
384 if (hKey)
385 pKey = static_cast<ORegKey*>(hKey);
386 else
387 return RegError::INVALID_KEY;
389 return dumpRegistry(pKey->getRegistry(), hKey);
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */