fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / registry / source / registry.cxx
blob345e0bf6f8be44832302022af657d832f657a108
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.h>
22 #include <registry/registry.hxx>
24 #include <osl/process.h>
26 #include "keyimpl.hxx"
27 #include "regimpl.hxx"
28 #include "regkey.hxx"
30 #if defined(WIN32) || defined(WNT)
31 #include <io.h>
32 #endif
34 #include <string.h>
35 #if defined(UNX)
36 #include <stdlib.h>
37 #include <unistd.h>
38 #endif
40 extern "C" {
43 // acquire
45 static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
47 ORegistry* pReg = static_cast<ORegistry*>(hReg);
49 if (pReg != NULL)
50 pReg->acquire();
55 // release
57 static void REGISTRY_CALLTYPE release(RegHandle hReg)
59 ORegistry* pReg = static_cast<ORegistry*>(hReg);
61 if (pReg)
63 if (pReg->release() == 0)
65 delete pReg;
66 hReg = NULL;
73 // getName
75 static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
77 if (hReg)
79 ORegistry* pReg = static_cast<ORegistry*>(hReg);
80 if ( pReg->isOpen() )
82 rtl_uString_assign(pName, pReg->getName().pData);
83 return RegError::NO_ERROR;
84 } else
86 rtl_uString_new(pName);
87 return RegError::REGISTRY_NOT_OPEN;
91 rtl_uString_new(pName);
92 return RegError::INVALID_REGISTRY;
97 // isReadOnly
99 static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
101 if (hReg)
102 return static_cast<ORegistry*>(hReg)->isReadOnly();
103 else
104 return sal_False;
109 // createRegistry
111 static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
112 RegHandle* phRegistry)
114 RegError ret;
116 ORegistry* pReg = new ORegistry();
117 if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)) != RegError::NO_ERROR)
119 delete pReg;
120 *phRegistry = NULL;
121 return ret;
124 *phRegistry = pReg;
126 return RegError::NO_ERROR;
130 // openRootKey
132 static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg,
133 RegKeyHandle* phRootKey)
135 ORegistry* pReg;
137 if (hReg)
139 pReg = static_cast<ORegistry*>(hReg);
140 if (!pReg->isOpen())
141 return RegError::REGISTRY_NOT_OPEN;
142 } else
144 phRootKey = NULL;
145 return RegError::INVALID_REGISTRY;
148 *phRootKey = pReg->getRootKey();
150 return RegError::NO_ERROR;
155 // openRegistry
157 static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
158 RegHandle* phRegistry,
159 RegAccessMode accessMode)
161 RegError _ret;
163 ORegistry* pReg = new ORegistry();
164 if ((_ret = pReg->initRegistry(registryName, accessMode)) != RegError::NO_ERROR)
166 *phRegistry = NULL;
167 delete pReg;
168 return _ret;
172 *phRegistry = pReg;
174 return RegError::NO_ERROR;
178 // closeRegistry
180 static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
182 ORegistry *pReg;
184 if (hReg)
186 pReg = static_cast<ORegistry*>(hReg);
187 if (!pReg->isOpen())
188 return RegError::REGISTRY_NOT_OPEN;
190 RegError ret = RegError::NO_ERROR;
191 if (pReg->release() == 0)
193 delete(pReg);
194 hReg = NULL;
196 else
197 ret = pReg->closeRegistry();
199 return ret;
200 } else
202 return RegError::INVALID_REGISTRY;
208 // destroyRegistry
210 static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg,
211 rtl_uString* registryName)
213 ORegistry *pReg;
215 if (hReg)
217 pReg = static_cast<ORegistry*>(hReg);
218 if (!pReg->isOpen())
219 return RegError::INVALID_REGISTRY;
221 RegError ret = pReg->destroyRegistry(registryName);
222 if (ret == RegError::NO_ERROR)
224 if (!registryName->length)
226 delete(pReg);
227 hReg = NULL;
230 return ret;
231 } else
233 return RegError::INVALID_REGISTRY;
239 // loadRegKey
241 static RegError REGISTRY_CALLTYPE loadKey(RegHandle hReg,
242 RegKeyHandle hKey,
243 rtl_uString* keyName,
244 rtl_uString* regFileName)
247 ORegistry* pReg = static_cast< ORegistry* >(hReg);
248 if (!pReg)
249 return RegError::INVALID_REGISTRY;
251 if (!pReg->isOpen())
252 return RegError::REGISTRY_NOT_OPEN;
254 ORegKey* pKey = static_cast< ORegKey* >(hKey);
255 if (!pKey)
256 return RegError::INVALID_KEY;
258 if (pKey->getRegistry() != pReg)
259 return RegError::INVALID_KEY;
260 if (pKey->isDeleted())
261 return RegError::INVALID_KEY;
262 if (pKey->isReadOnly())
263 return RegError::REGISTRY_READONLY;
266 ORegKey* pNewKey = 0;
267 RegError _ret = pKey->openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pNewKey));
268 if (_ret == RegError::NO_ERROR)
270 pKey->releaseKey(pNewKey);
271 pKey->deleteKey(keyName);
274 _ret = pKey->createKey(keyName, reinterpret_cast<RegKeyHandle*>(&pNewKey));
275 if (_ret != RegError::NO_ERROR)
276 return _ret;
278 _ret = pReg->loadKey(pNewKey, regFileName);
279 if (_ret != RegError::NO_ERROR)
281 pKey->releaseKey(pNewKey);
282 pKey->deleteKey(keyName);
283 return _ret;
286 return pKey->closeKey(pNewKey);
290 // saveKey
292 static RegError REGISTRY_CALLTYPE saveKey(RegHandle hReg,
293 RegKeyHandle hKey,
294 rtl_uString* keyName,
295 rtl_uString* regFileName)
298 ORegistry* pReg = static_cast< ORegistry* >(hReg);
299 if (!pReg)
300 return RegError::INVALID_REGISTRY;
302 if (!pReg->isOpen())
303 return RegError::REGISTRY_NOT_OPEN;
305 ORegKey* pKey = static_cast< ORegKey* >(hKey);
306 if (!pKey)
307 return RegError::INVALID_KEY;
309 if (pKey->getRegistry() != pReg)
310 return RegError::INVALID_KEY;
311 if (pKey->isDeleted())
312 return RegError::INVALID_KEY;
314 ORegKey* pNewKey = 0;
315 RegError _ret = pKey->openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pNewKey));
316 if (_ret != RegError::NO_ERROR)
317 return _ret;
319 _ret = pReg->saveKey(pNewKey, regFileName);
320 if (_ret != RegError::NO_ERROR)
322 (void) pKey->releaseKey(pNewKey);
323 return _ret;
326 return pKey->releaseKey(pNewKey);
330 // mergeKey
332 static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg,
333 RegKeyHandle hKey,
334 rtl_uString* keyName,
335 rtl_uString* regFileName,
336 sal_Bool bWarnings,
337 sal_Bool bReport)
339 ORegistry* pReg = static_cast< ORegistry* >(hReg);
340 if (!pReg)
341 return RegError::INVALID_REGISTRY;
342 if (!pReg->isOpen())
343 return RegError::REGISTRY_NOT_OPEN;
345 ORegKey* pKey = static_cast< ORegKey* >(hKey);
346 if (!pKey)
347 return RegError::INVALID_KEY;
348 if (pKey->getRegistry() != pReg)
349 return RegError::INVALID_KEY;
350 if (pKey->isDeleted())
351 return RegError::INVALID_KEY;
352 if (pKey->isReadOnly())
353 return RegError::REGISTRY_READONLY;
355 if (keyName->length)
357 ORegKey* pNewKey = 0;
358 RegError _ret = pKey->createKey(keyName, reinterpret_cast<RegKeyHandle*>(&pNewKey));
359 if (_ret != RegError::NO_ERROR)
360 return _ret;
362 _ret = pReg->loadKey(pNewKey, regFileName, bWarnings, bReport);
363 if (_ret != RegError::NO_ERROR && (_ret != RegError::MERGE_CONFLICT || bWarnings))
365 if (pNewKey != pKey)
366 (void) pKey->closeKey(pNewKey);
367 else
368 (void) pKey->releaseKey(pNewKey);
369 return _ret;
372 return (pNewKey != pKey) ? pKey->closeKey(pNewKey) : pKey->releaseKey(pNewKey);
375 return pReg->loadKey(pKey, regFileName, bWarnings, bReport);
379 // dumpRegistry
381 static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg,
382 RegKeyHandle hKey)
384 ORegistry* pReg = static_cast< ORegistry* >(hReg);
385 if (!pReg)
386 return RegError::INVALID_REGISTRY;
387 if (!pReg->isOpen())
388 return RegError::REGISTRY_NOT_OPEN;
390 ORegKey* pKey = static_cast< ORegKey* >(hKey);
391 if (!pKey)
392 return RegError::INVALID_KEY;
393 if (pKey->getRegistry() != pReg)
394 return RegError::INVALID_KEY;
395 if (pKey->isDeleted())
396 return RegError::INVALID_KEY;
398 return pReg->dumpRegistry(hKey);
402 // initRegistry_Api
404 Registry_Api* REGISTRY_CALLTYPE initRegistry_Api()
406 static Registry_Api aApi= {&acquire,
407 &release,
408 &isReadOnly,
409 &openRootKey,
410 &getName,
411 &createRegistry,
412 &openRegistry,
413 &closeRegistry,
414 &destroyRegistry,
415 &loadKey,
416 &saveKey,
417 &mergeKey,
418 &dumpRegistry,
419 &acquireKey,
420 &releaseKey,
421 &isKeyReadOnly,
422 &getKeyName,
423 &createKey,
424 &openKey,
425 &openSubKeys,
426 &closeSubKeys,
427 &deleteKey,
428 &closeKey,
429 &setValue,
430 &setLongListValue,
431 &setStringListValue,
432 &setUnicodeListValue,
433 &getValueInfo,
434 &getValue,
435 &getLongListValue,
436 &getStringListValue,
437 &getUnicodeListValue,
438 &freeValueList,
439 &getResolvedKeyName,
440 &getKeyNames,
441 &freeKeyNames};
443 return (&aApi);
449 // reg_loadRegKey
451 RegError REGISTRY_CALLTYPE reg_loadKey(RegKeyHandle hKey,
452 rtl_uString* keyName,
453 rtl_uString* regFileName)
455 ORegKey *pKey;
457 if (hKey)
458 pKey = static_cast<ORegKey*>(hKey);
459 else
460 return RegError::INVALID_KEY;
462 return loadKey(pKey->getRegistry(), hKey, keyName, regFileName);
466 // reg_saveKey
468 RegError REGISTRY_CALLTYPE reg_saveKey(RegKeyHandle hKey,
469 rtl_uString* keyName,
470 rtl_uString* regFileName)
472 ORegKey *pKey;
474 if (hKey)
475 pKey = static_cast<ORegKey*>(hKey);
476 else
477 return RegError::INVALID_KEY;
479 return saveKey(pKey->getRegistry(), hKey, keyName, regFileName);
483 // reg_mergeKey
485 RegError REGISTRY_CALLTYPE reg_mergeKey(RegKeyHandle hKey,
486 rtl_uString* keyName,
487 rtl_uString* regFileName,
488 sal_Bool bWarnings,
489 sal_Bool bReport)
491 ORegKey *pKey;
493 if (hKey)
494 pKey = static_cast<ORegKey*>(hKey);
495 else
496 return RegError::INVALID_KEY;
498 return mergeKey(pKey->getRegistry(), hKey, keyName, regFileName, bWarnings, bReport);
502 // reg_createRegistry
504 RegError REGISTRY_CALLTYPE reg_createRegistry(rtl_uString* registryName,
505 RegHandle* phRegistry)
507 RegError ret;
509 ORegistry* pReg = new ORegistry();
510 if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)) != RegError::NO_ERROR)
512 delete pReg;
513 *phRegistry = NULL;
514 return ret;
517 *phRegistry = pReg;
519 return RegError::NO_ERROR;
523 // reg_openRootKey
525 RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
526 RegKeyHandle* phRootKey)
528 return openRootKey(hRegistry, phRootKey);
533 // reg_getName
535 RegError REGISTRY_CALLTYPE reg_getName(RegHandle hRegistry, rtl_uString** pName)
537 return getName(hRegistry, pName);
542 // reg_isReadOnly
544 sal_Bool REGISTRY_CALLTYPE reg_isReadOnly(RegHandle hRegistry)
546 return isReadOnly(hRegistry);
551 // reg_openRegistry
553 RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
554 RegHandle* phRegistry,
555 RegAccessMode accessMode)
557 RegError _ret;
559 ORegistry* pReg = new ORegistry();
560 if ((_ret = pReg->initRegistry(registryName, accessMode)) != RegError::NO_ERROR)
562 delete pReg;
563 *phRegistry = NULL;
564 return _ret;
567 *phRegistry = pReg;
569 return RegError::NO_ERROR;
573 // reg_closeRegistry
575 RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
577 if (hRegistry)
579 ORegistry* pReg = static_cast<ORegistry*>(hRegistry);
580 delete(pReg);
581 return RegError::NO_ERROR;
582 } else
584 return RegError::REGISTRY_NOT_OPEN;
590 // reg_destroyRegistry
592 RegError REGISTRY_CALLTYPE reg_destroyRegistry(RegHandle hRegistry,
593 rtl_uString* registryName)
595 return destroyRegistry(hRegistry, registryName);
600 // reg_dumpRegistry
602 RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey)
604 ORegKey *pKey;
606 if (hKey)
607 pKey = static_cast<ORegKey*>(hKey);
608 else
609 return RegError::INVALID_KEY;
611 return dumpRegistry(pKey->getRegistry(), hKey);
615 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */