update dev300-m58
[ooovba.git] / registry / source / registry.cxx
blobca3647df352ce972df5182f0e7312b3b70e022b3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: registry.cxx,v $
10 * $Revision: 1.20.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_registry.hxx"
33 #include <registry/registry.h>
34 #include <registry/registry.hxx>
35 #include <osl/process.h>
36 #include "regimpl.hxx"
37 #ifndef _REGKEY_HXX_
38 #include "keyimpl.hxx"
39 #endif
40 #include "regkey.hxx"
42 #if defined(WIN32) || defined(WNT) || defined(OS2)
43 #include <io.h>
44 #endif
46 #include <string.h>
47 #if defined(UNX)
48 #include <stdlib.h>
49 #include <unistd.h>
50 #endif
52 #if defined ( GCC ) && ( defined ( SCO ) )
53 ORealDynamicLoader* ODynamicLoader<Registry_Api>::m_pLoader = NULL;
54 #endif
56 extern "C" {
58 //*********************************************************************
59 // acquire
61 static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
63 ORegistry* pReg = (ORegistry*) hReg;
65 if (pReg != NULL)
66 pReg->acquire();
70 //*********************************************************************
71 // release
73 static void REGISTRY_CALLTYPE release(RegHandle hReg)
75 ORegistry* pReg = (ORegistry*) hReg;
77 if (pReg)
79 if (pReg->release() == 0)
81 delete pReg;
82 hReg = NULL;
88 //*********************************************************************
89 // getName
91 static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
93 ORegistry* pReg;
95 if (hReg)
97 pReg = (ORegistry*)hReg;
98 if ( pReg->isOpen() )
100 rtl_uString_assign(pName, pReg->getName().pData);
101 return REG_NO_ERROR;
102 } else
104 rtl_uString_new(pName);
105 return REG_REGISTRY_NOT_OPEN;
109 rtl_uString_new(pName);
110 return REG_INVALID_REGISTRY;
114 //*********************************************************************
115 // isReadOnly
117 static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
119 if (hReg)
120 return ((ORegistry*)hReg)->isReadOnly();
121 else
122 return sal_False;
126 //*********************************************************************
127 // createRegistry
129 static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
130 RegHandle* phRegistry)
132 RegError ret;
134 ORegistry* pReg = new ORegistry();
135 if ((ret = pReg->initRegistry(registryName, REG_CREATE)))
137 *phRegistry = NULL;
138 return ret;
141 *phRegistry = pReg;
143 return REG_NO_ERROR;
146 //*********************************************************************
147 // openRootKey
149 static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg,
150 RegKeyHandle* phRootKey)
152 ORegistry* pReg;
154 if (hReg)
156 pReg = (ORegistry*)hReg;
157 if (!pReg->isOpen())
158 return REG_REGISTRY_NOT_OPEN;
159 } else
161 phRootKey = NULL;
162 return REG_INVALID_REGISTRY;
165 *phRootKey = pReg->getRootKey();
167 return REG_NO_ERROR;
171 //*********************************************************************
172 // openRegistry
174 static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
175 RegHandle* phRegistry,
176 RegAccessMode accessMode)
178 RegError _ret;
180 ORegistry* pReg = new ORegistry();
181 if ((_ret = pReg->initRegistry(registryName, accessMode)))
183 *phRegistry = NULL;
184 delete pReg;
185 return _ret;
189 *phRegistry = pReg;
191 return REG_NO_ERROR;
194 //*********************************************************************
195 // closeRegistry
197 static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
199 ORegistry *pReg;
201 if (hReg)
203 pReg = (ORegistry*)hReg;
204 if (!pReg->isOpen())
205 return REG_REGISTRY_NOT_OPEN;
207 RegError ret = REG_NO_ERROR;
208 if (pReg->release() == 0)
210 delete(pReg);
211 hReg = NULL;
213 else
214 ret = pReg->closeRegistry();
216 return ret;
217 } else
219 return REG_INVALID_REGISTRY;
224 //*********************************************************************
225 // destroyRegistry
227 static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg,
228 rtl_uString* registryName)
230 ORegistry *pReg;
232 if (hReg)
234 pReg = (ORegistry*)hReg;
235 if (!pReg->isOpen())
236 return REG_INVALID_REGISTRY;
238 RegError ret = pReg->destroyRegistry(registryName);
239 if (!ret)
241 if (!registryName->length)
243 delete(pReg);
244 hReg = NULL;
247 return ret;
248 } else
250 return REG_INVALID_REGISTRY;
255 //*********************************************************************
256 // loadRegKey
258 static RegError REGISTRY_CALLTYPE loadKey(RegHandle hReg,
259 RegKeyHandle hKey,
260 rtl_uString* keyName,
261 rtl_uString* regFileName)
263 ORegistry *pReg;
264 ORegKey *pKey, *pNewKey;
265 RegError _ret;
267 if (hReg)
269 pReg = (ORegistry*)hReg;
270 if (!pReg->isOpen())
271 return REG_REGISTRY_NOT_OPEN;
272 } else
274 return REG_INVALID_REGISTRY;
277 if (hKey)
279 pKey = (ORegKey*)hKey;
281 if (pKey->getRegistry() != pReg || pKey->isDeleted())
282 return REG_INVALID_KEY;
283 } else
285 return REG_INVALID_KEY;
288 if (pKey->isReadOnly())
289 return REG_REGISTRY_READONLY;
291 if (!pKey->openKey(keyName, (RegKeyHandle*)&pNewKey))
293 pKey->closeKey(pNewKey);
294 pKey->deleteKey(keyName);
297 if ((_ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey)))
298 return _ret;
300 if ((_ret = pReg->loadKey(pNewKey, regFileName)))
302 pKey->closeKey(pNewKey);
303 pKey->deleteKey(keyName);
304 return _ret;
307 return pKey->closeKey(pNewKey);
310 //*********************************************************************
311 // saveKey
313 static RegError REGISTRY_CALLTYPE saveKey(RegHandle hReg,
314 RegKeyHandle hKey,
315 rtl_uString* keyName,
316 rtl_uString* regFileName)
318 ORegistry *pReg;
319 ORegKey *pKey, *pNewKey;
320 RegError _ret;
322 if (hReg)
324 pReg = (ORegistry*)hReg;
325 if (!pReg->isOpen())
326 return REG_REGISTRY_NOT_OPEN;
327 } else
329 return REG_INVALID_REGISTRY;
332 if (hKey)
334 pKey = (ORegKey*)hKey;
336 if (pKey->getRegistry() != pReg || pKey->isDeleted())
337 return REG_INVALID_KEY;
338 } else
340 return REG_INVALID_KEY;
343 if ((_ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey)))
344 return _ret;
346 if ((_ret = pReg->saveKey(pNewKey, regFileName)))
348 pKey->closeKey(pNewKey);
349 return _ret;
352 return pKey->closeKey(pNewKey);
355 //*********************************************************************
356 // mergeKey
358 static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg,
359 RegKeyHandle hKey,
360 rtl_uString* keyName,
361 rtl_uString* regFileName,
362 sal_Bool bWarnings,
363 sal_Bool bReport)
365 ORegistry *pReg;
366 ORegKey *pKey, *pNewKey;
367 RegError _ret;
369 if (hReg)
371 pReg = (ORegistry*)hReg;
372 if (!pReg->isOpen())
373 return(REG_REGISTRY_NOT_OPEN);
374 } else
376 return REG_INVALID_REGISTRY;
379 if (hKey)
381 pKey = (ORegKey*)hKey;
383 if (pKey->getRegistry() != pReg || pKey->isDeleted())
384 return REG_INVALID_KEY;
385 } else
387 return REG_INVALID_KEY;
390 if (pKey->isReadOnly())
391 return REG_REGISTRY_READONLY;
393 if (keyName->length)
395 if ((_ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey) ))
396 return _ret;
397 } else
399 pNewKey = pKey;
402 _ret = pKey->getRegistry()->loadKey(pNewKey, regFileName, bWarnings, bReport);
404 if (_ret == REG_MERGE_ERROR ||
405 (_ret == REG_MERGE_CONFLICT && bWarnings))
407 pKey->closeKey(pNewKey);
408 return _ret;
412 if (_ret)
414 if (_ret == REG_MERGE_ERROR ||
415 (_ret == REG_MERGE_CONFLICT && bWarnings))
417 pKey->closeKey(pNewKey);
418 pKey->deleteKey(keyName);
419 pKey->createKey(keyName, (RegKeyHandle*)&pNewKey);
420 pReg->loadKey(pNewKey, tmpName, sal_False, sal_False);
423 destroyRegistry(hReg, tmpName);
425 pKey->closeKey(pNewKey);
426 return _ret;
429 destroyRegistry(hReg, tmpName);
431 _ret = pKey->closeKey(pNewKey);
433 return _ret;
437 //*********************************************************************
438 // dumpRegistry
440 static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg,
441 RegKeyHandle hKey)
443 ORegistry *pReg;
444 ORegKey *pKey;
446 if (hReg)
448 pReg = (ORegistry*)hReg;
449 if (!pReg->isOpen())
450 return REG_REGISTRY_NOT_OPEN;
451 } else
453 return REG_INVALID_REGISTRY;
456 if (hKey)
458 pKey = (ORegKey*)hKey;
460 if (pKey->getRegistry() != pReg || pKey->isDeleted())
461 return REG_INVALID_KEY;
462 } else
464 return REG_INVALID_KEY;
467 return pReg->dumpRegistry(hKey);
471 //*********************************************************************
472 // initRegistry_Api
474 Registry_Api* REGISTRY_CALLTYPE initRegistry_Api(void)
476 static Registry_Api aApi= {&acquire,
477 &release,
478 &isReadOnly,
479 &openRootKey,
480 &getName,
481 &createRegistry,
482 &openRegistry,
483 &closeRegistry,
484 &destroyRegistry,
485 &loadKey,
486 &saveKey,
487 &mergeKey,
488 &dumpRegistry,
489 &acquireKey,
490 &releaseKey,
491 &isKeyReadOnly,
492 &getKeyName,
493 &createKey,
494 &openKey,
495 &openSubKeys,
496 &closeSubKeys,
497 &deleteKey,
498 &closeKey,
499 &setValue,
500 &setLongListValue,
501 &setStringListValue,
502 &setUnicodeListValue,
503 &getValueInfo,
504 &getValue,
505 &getLongListValue,
506 &getStringListValue,
507 &getUnicodeListValue,
508 &freeValueList,
509 &createLink,
510 &deleteLink,
511 &getKeyType,
512 &getLinkTarget,
513 &getResolvedKeyName,
514 &getKeyNames,
515 &freeKeyNames};
517 return (&aApi);
522 //*********************************************************************
523 // reg_loadRegKey
525 RegError REGISTRY_CALLTYPE reg_loadKey(RegKeyHandle hKey,
526 rtl_uString* keyName,
527 rtl_uString* regFileName)
529 ORegKey *pKey;
531 if (hKey)
532 pKey = (ORegKey*)hKey;
533 else
534 return REG_INVALID_KEY;
536 return loadKey(pKey->getRegistry(), hKey, keyName, regFileName);
539 //*********************************************************************
540 // reg_saveKey
542 RegError REGISTRY_CALLTYPE reg_saveKey(RegKeyHandle hKey,
543 rtl_uString* keyName,
544 rtl_uString* regFileName)
546 ORegKey *pKey;
548 if (hKey)
549 pKey = (ORegKey*)hKey;
550 else
551 return REG_INVALID_KEY;
553 return saveKey(pKey->getRegistry(), hKey, keyName, regFileName);
556 //*********************************************************************
557 // reg_mergeKey
559 RegError REGISTRY_CALLTYPE reg_mergeKey(RegKeyHandle hKey,
560 rtl_uString* keyName,
561 rtl_uString* regFileName,
562 sal_Bool bWarnings,
563 sal_Bool bReport)
565 ORegKey *pKey;
567 if (hKey)
568 pKey = (ORegKey*)hKey;
569 else
570 return REG_INVALID_KEY;
572 return mergeKey(pKey->getRegistry(), hKey, keyName, regFileName, bWarnings, bReport);
575 //*********************************************************************
576 // reg_createRegistry
578 RegError REGISTRY_CALLTYPE reg_createRegistry(rtl_uString* registryName,
579 RegHandle* phRegistry)
581 RegError ret;
583 ORegistry* pReg = new ORegistry();
584 if ((ret = pReg->initRegistry(registryName, REG_CREATE)))
586 *phRegistry = NULL;
587 return ret;
590 *phRegistry = pReg;
592 return REG_NO_ERROR;
595 //*********************************************************************
596 // reg_openRootKey
598 RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
599 RegKeyHandle* phRootKey)
601 return openRootKey(hRegistry, phRootKey);
605 //*********************************************************************
606 // reg_getName
608 RegError REGISTRY_CALLTYPE reg_getName(RegHandle hRegistry, rtl_uString** pName)
610 return getName(hRegistry, pName);
614 //*********************************************************************
615 // reg_isReadOnly
617 sal_Bool REGISTRY_CALLTYPE reg_isReadOnly(RegHandle hRegistry)
619 return isReadOnly(hRegistry);
623 //*********************************************************************
624 // reg_openRegistry
626 RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
627 RegHandle* phRegistry,
628 RegAccessMode accessMode)
630 RegError _ret;
632 ORegistry* pReg = new ORegistry();
633 if ((_ret = pReg->initRegistry(registryName, accessMode)))
635 *phRegistry = NULL;
636 return _ret;
639 *phRegistry = pReg;
641 return REG_NO_ERROR;
644 //*********************************************************************
645 // reg_closeRegistry
647 RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
649 ORegistry* pReg;
651 if (hRegistry)
653 pReg = (ORegistry*)hRegistry;
654 delete(pReg);
655 return REG_NO_ERROR;
656 } else
658 return REG_REGISTRY_NOT_OPEN;
663 //*********************************************************************
664 // reg_destroyRegistry
666 RegError REGISTRY_CALLTYPE reg_destroyRegistry(RegHandle hRegistry,
667 rtl_uString* registryName)
669 return destroyRegistry(hRegistry, registryName);
673 //*********************************************************************
674 // reg_dumpRegistry
676 RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey)
678 ORegKey *pKey;
680 if (hKey)
681 pKey = (ORegKey*)hKey;
682 else
683 return REG_INVALID_KEY;
685 return dumpRegistry(pKey->getRegistry(), hKey);