1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include <registry/registry.hxx>
24 #include <rtl/alloc.h>
25 #include <osl/diagnose.h>
26 #include "regimpl.hxx"
27 #include "keyimpl.hxx"
33 void REGISTRY_CALLTYPE
acquireKey(RegKeyHandle hKey
)
35 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
38 ORegistry
* pReg
= pKey
->getRegistry();
39 (void) pReg
->acquireKey(pKey
);
47 void REGISTRY_CALLTYPE
releaseKey(RegKeyHandle hKey
)
49 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
52 ORegistry
* pReg
= pKey
->getRegistry();
53 (void) pReg
->releaseKey(pKey
);
61 sal_Bool REGISTRY_CALLTYPE
isKeyReadOnly(RegKeyHandle hKey
)
63 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
64 return (pKey
!= 0) ? pKey
->isReadOnly() : sal_False
;
71 RegError REGISTRY_CALLTYPE
getKeyName(RegKeyHandle hKey
, rtl_uString
** pKeyName
)
73 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
76 rtl_uString_assign( pKeyName
, pKey
->getName().pData
);
77 return RegError::NO_ERROR
;
80 rtl_uString_new(pKeyName
);
81 return RegError::INVALID_KEY
;
89 RegError REGISTRY_CALLTYPE
createKey(RegKeyHandle hKey
,
91 RegKeyHandle
* phNewKey
)
95 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
97 return RegError::INVALID_KEY
;
99 if (pKey
->isDeleted())
100 return RegError::INVALID_KEY
;
102 if (pKey
->isReadOnly())
103 return RegError::REGISTRY_READONLY
;
105 return pKey
->createKey(keyName
, phNewKey
);
111 RegError REGISTRY_CALLTYPE
openKey(RegKeyHandle hKey
,
112 rtl_uString
* keyName
,
113 RegKeyHandle
* phOpenKey
)
117 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
119 return RegError::INVALID_KEY
;
121 if (pKey
->isDeleted())
122 return RegError::INVALID_KEY
;
124 return pKey
->openKey(keyName
, phOpenKey
);
130 RegError REGISTRY_CALLTYPE
openSubKeys(RegKeyHandle hKey
,
131 rtl_uString
* keyName
,
132 RegKeyHandle
** pphSubKeys
,
133 sal_uInt32
* pnSubKeys
)
138 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
140 return RegError::INVALID_KEY
;
142 if (pKey
->isDeleted())
143 return RegError::INVALID_KEY
;
145 return pKey
->openSubKeys(keyName
, pphSubKeys
, pnSubKeys
);
151 RegError REGISTRY_CALLTYPE
closeSubKeys(RegKeyHandle
* phSubKeys
,
154 if (phSubKeys
== 0 || nSubKeys
== 0)
155 return RegError::INVALID_KEY
;
157 ORegistry
* pReg
= static_cast<ORegKey
*>(phSubKeys
[0])->getRegistry();
158 for (sal_uInt32 i
= 0; i
< nSubKeys
; i
++)
160 (void) pReg
->closeKey(phSubKeys
[i
]);
162 rtl_freeMemory(phSubKeys
);
164 return RegError::NO_ERROR
;
170 RegError REGISTRY_CALLTYPE
deleteKey(RegKeyHandle hKey
,
171 rtl_uString
* keyName
)
173 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
175 return RegError::INVALID_KEY
;
177 if (pKey
->isDeleted())
178 return RegError::INVALID_KEY
;
180 if (pKey
->isReadOnly())
181 return RegError::REGISTRY_READONLY
;
183 return pKey
->deleteKey(keyName
);
189 RegError REGISTRY_CALLTYPE
closeKey(RegKeyHandle hKey
)
191 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
193 return RegError::INVALID_KEY
;
195 return pKey
->closeKey(hKey
);
201 RegError REGISTRY_CALLTYPE
setValue(RegKeyHandle hKey
,
202 rtl_uString
* keyName
,
203 RegValueType valueType
,
205 sal_uInt32 valueSize
)
207 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
209 return RegError::INVALID_KEY
;
211 if (pKey
->isDeleted())
212 return RegError::INVALID_KEY
;
214 if (pKey
->isReadOnly())
215 return RegError::REGISTRY_READONLY
;
217 OUString
valueName("value");
220 ORegKey
* pSubKey
= 0;
221 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
222 if (_ret1
!= RegError::NO_ERROR
)
225 _ret1
= pSubKey
->setValue(valueName
, valueType
, pData
, valueSize
);
226 if (_ret1
!= RegError::NO_ERROR
)
228 RegError _ret2
= pKey
->closeKey(pSubKey
);
229 if (_ret2
!= RegError::NO_ERROR
)
235 return pKey
->closeKey(pSubKey
);
238 return pKey
->setValue(valueName
, valueType
, pData
, valueSize
);
244 RegError REGISTRY_CALLTYPE
setLongListValue(RegKeyHandle hKey
,
245 rtl_uString
* keyName
,
246 sal_Int32
* pValueList
,
249 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
251 return RegError::INVALID_KEY
;
253 if (pKey
->isDeleted())
254 return RegError::INVALID_KEY
;
256 if (pKey
->isReadOnly())
257 return RegError::REGISTRY_READONLY
;
259 OUString
valueName("value");
262 ORegKey
* pSubKey
= 0;
263 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
264 if (_ret1
!= RegError::NO_ERROR
)
267 _ret1
= pSubKey
->setLongListValue(valueName
, pValueList
, len
);
268 if (_ret1
!= RegError::NO_ERROR
)
270 RegError _ret2
= pKey
->closeKey(pSubKey
);
271 if (_ret2
!= RegError::NO_ERROR
)
277 return pKey
->closeKey(pSubKey
);
280 return pKey
->setLongListValue(valueName
, pValueList
, len
);
284 // setStringValueList
286 RegError REGISTRY_CALLTYPE
setStringListValue(RegKeyHandle hKey
,
287 rtl_uString
* keyName
,
288 sal_Char
** pValueList
,
291 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
293 return RegError::INVALID_KEY
;
295 if (pKey
->isDeleted())
296 return RegError::INVALID_KEY
;
298 if (pKey
->isReadOnly())
299 return RegError::REGISTRY_READONLY
;
301 OUString
valueName("value");
304 ORegKey
* pSubKey
= 0;
305 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
306 if (_ret1
!= RegError::NO_ERROR
)
309 _ret1
= pSubKey
->setStringListValue(valueName
, pValueList
, len
);
310 if (_ret1
!= RegError::NO_ERROR
)
312 RegError _ret2
= pKey
->closeKey(pSubKey
);
313 if (_ret2
!= RegError::NO_ERROR
)
319 return pKey
->closeKey(pSubKey
);
322 return pKey
->setStringListValue(valueName
, pValueList
, len
);
326 // setUnicodeValueList
328 RegError REGISTRY_CALLTYPE
setUnicodeListValue(RegKeyHandle hKey
,
329 rtl_uString
* keyName
,
330 sal_Unicode
** pValueList
,
333 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
335 return RegError::INVALID_KEY
;
337 if (pKey
->isDeleted())
338 return RegError::INVALID_KEY
;
340 if (pKey
->isReadOnly())
341 return RegError::REGISTRY_READONLY
;
343 OUString
valueName("value");
346 ORegKey
* pSubKey
= 0;
347 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
348 if (_ret1
!= RegError::NO_ERROR
)
351 _ret1
= pSubKey
->setUnicodeListValue(valueName
, pValueList
, len
);
352 if (_ret1
!= RegError::NO_ERROR
)
354 RegError _ret2
= pKey
->closeKey(pSubKey
);
355 if (_ret2
!= RegError::NO_ERROR
)
361 return pKey
->closeKey(pSubKey
);
364 return pKey
->setUnicodeListValue(valueName
, pValueList
, len
);
370 RegError REGISTRY_CALLTYPE
getValueInfo(RegKeyHandle hKey
,
371 rtl_uString
* keyName
,
372 RegValueType
* pValueType
,
373 sal_uInt32
* pValueSize
)
375 *pValueType
= RegValueType::NOT_DEFINED
;
378 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
380 return RegError::INVALID_KEY
;
382 if (pKey
->isDeleted())
383 return RegError::INVALID_KEY
;
385 RegValueType valueType
;
386 sal_uInt32 valueSize
;
388 OUString
valueName("value");
391 ORegKey
* pSubKey
= 0;
392 RegError _ret
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
393 if (_ret
!= RegError::NO_ERROR
)
396 if (pSubKey
->getValueInfo(valueName
, &valueType
, &valueSize
) != RegError::NO_ERROR
)
398 (void) pKey
->releaseKey(pSubKey
);
399 return RegError::INVALID_VALUE
;
402 *pValueType
= valueType
;
403 *pValueSize
= valueSize
;
405 return pKey
->releaseKey(pSubKey
);
409 if (pKey
->getValueInfo(valueName
, &valueType
, &valueSize
) != RegError::NO_ERROR
)
411 return RegError::INVALID_VALUE
;
414 *pValueType
= valueType
;
415 *pValueSize
= valueSize
;
417 return RegError::NO_ERROR
;
423 RegError REGISTRY_CALLTYPE
getValue(RegKeyHandle hKey
,
424 rtl_uString
* keyName
,
427 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
429 return RegError::INVALID_KEY
;
431 if (pKey
->isDeleted())
432 return RegError::INVALID_KEY
;
434 OUString
valueName("value");
437 ORegKey
* pSubKey
= 0;
438 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
439 if (_ret1
!= RegError::NO_ERROR
)
442 _ret1
= pSubKey
->getValue(valueName
, pValue
);
443 if (_ret1
!= RegError::NO_ERROR
)
445 (void) pKey
->releaseKey(pSubKey
);
449 return pKey
->releaseKey(pSubKey
);
452 return pKey
->getValue(valueName
, pValue
);
458 RegError REGISTRY_CALLTYPE
getLongListValue(RegKeyHandle hKey
,
459 rtl_uString
* keyName
,
460 sal_Int32
** pValueList
,
463 assert((pValueList
!= 0) && (pLen
!= 0) && "registry::getLongListValue(): invalid parameter");
464 *pValueList
= 0, *pLen
= 0;
466 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
468 return RegError::INVALID_KEY
;
470 if (pKey
->isDeleted())
471 return RegError::INVALID_KEY
;
473 OUString
valueName("value");
476 ORegKey
* pSubKey
= 0;
477 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
478 if (_ret1
!= RegError::NO_ERROR
)
481 _ret1
= pSubKey
->getLongListValue(valueName
, pValueList
, pLen
);
482 if (_ret1
!= RegError::NO_ERROR
)
484 (void) pKey
->releaseKey(pSubKey
);
488 return pKey
->releaseKey(pSubKey
);
491 return pKey
->getLongListValue(valueName
, pValueList
, pLen
);
495 // getStringValueList
497 RegError REGISTRY_CALLTYPE
getStringListValue(RegKeyHandle hKey
,
498 rtl_uString
* keyName
,
499 sal_Char
*** pValueList
,
502 OSL_PRECOND((pValueList
!= 0) && (pLen
!= 0), "registry::getStringListValue(): invalid parameter");
503 *pValueList
= 0, *pLen
= 0;
505 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
507 return RegError::INVALID_KEY
;
509 if (pKey
->isDeleted())
510 return RegError::INVALID_KEY
;
512 OUString
valueName("value");
515 ORegKey
* pSubKey
= 0;
516 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
517 if (_ret1
!= RegError::NO_ERROR
)
520 _ret1
= pSubKey
->getStringListValue(valueName
, pValueList
, pLen
);
521 if (_ret1
!= RegError::NO_ERROR
)
523 (void) pKey
->releaseKey(pSubKey
);
527 return pKey
->releaseKey(pSubKey
);
530 return pKey
->getStringListValue(valueName
, pValueList
, pLen
);
533 // getUnicodeListValue
534 RegError REGISTRY_CALLTYPE
getUnicodeListValue(RegKeyHandle hKey
,
535 rtl_uString
* keyName
,
536 sal_Unicode
*** pValueList
,
539 assert((pValueList
!= 0) && (pLen
!= 0) && "registry::getUnicodeListValue(): invalid parameter");
540 *pValueList
= 0, *pLen
= 0;
542 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
544 return RegError::INVALID_KEY
;
546 if (pKey
->isDeleted())
547 return RegError::INVALID_KEY
;
549 OUString
valueName("value");
552 ORegKey
* pSubKey
= 0;
553 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
554 if (_ret1
!= RegError::NO_ERROR
)
557 _ret1
= pSubKey
->getUnicodeListValue(valueName
, pValueList
, pLen
);
558 if (_ret1
!= RegError::NO_ERROR
)
560 (void) pKey
->releaseKey(pSubKey
);
564 return pKey
->releaseKey(pSubKey
);
567 return pKey
->getUnicodeListValue(valueName
, pValueList
, pLen
);
573 RegError REGISTRY_CALLTYPE
freeValueList(RegValueType valueType
,
579 case RegValueType::LONGLIST
:
581 rtl_freeMemory(pValueList
);
584 case RegValueType::STRINGLIST
:
586 sal_Char
** pVList
= static_cast<sal_Char
**>(pValueList
);
587 for (sal_uInt32 i
=0; i
< len
; i
++)
589 rtl_freeMemory(pVList
[i
]);
592 rtl_freeMemory(pVList
);
595 case RegValueType::UNICODELIST
:
597 sal_Unicode
** pVList
= static_cast<sal_Unicode
**>(pValueList
);
598 for (sal_uInt32 i
=0; i
< len
; i
++)
600 rtl_freeMemory(pVList
[i
]);
603 rtl_freeMemory(pVList
);
607 return RegError::INVALID_VALUE
;
611 return RegError::NO_ERROR
;
617 RegError REGISTRY_CALLTYPE
getResolvedKeyName(RegKeyHandle hKey
,
618 rtl_uString
* keyName
,
619 SAL_UNUSED_PARAMETER sal_Bool
,
620 rtl_uString
** pResolvedName
)
622 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
624 return RegError::INVALID_KEY
;
626 if (pKey
->isDeleted())
627 return RegError::INVALID_KEY
;
629 OUString resolvedName
;
630 RegError _ret
= pKey
->getResolvedKeyName(keyName
, resolvedName
);
631 if (_ret
== RegError::NO_ERROR
)
632 rtl_uString_assign(pResolvedName
, resolvedName
.pData
);
639 RegError REGISTRY_CALLTYPE
getKeyNames(RegKeyHandle hKey
,
640 rtl_uString
* keyName
,
641 rtl_uString
*** pSubKeyNames
,
642 sal_uInt32
* pnSubKeys
)
644 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
646 return RegError::INVALID_KEY
;
648 if (pKey
->isDeleted())
649 return RegError::INVALID_KEY
;
651 return pKey
->getKeyNames(keyName
, pSubKeyNames
, pnSubKeys
);
657 RegError REGISTRY_CALLTYPE
freeKeyNames(rtl_uString
** pKeyNames
,
660 for (sal_uInt32 i
=0; i
< nKeys
; i
++)
662 rtl_uString_release(pKeyNames
[i
]);
665 rtl_freeMemory(pKeyNames
);
667 return RegError::NO_ERROR
;
677 RegError REGISTRY_CALLTYPE
reg_createKey(RegKeyHandle hKey
,
678 rtl_uString
* keyName
,
679 RegKeyHandle
* phNewKey
)
682 return RegError::INVALID_KEY
;
684 return createKey(hKey
, keyName
, phNewKey
);
690 RegError REGISTRY_CALLTYPE
reg_openKey(RegKeyHandle hKey
,
691 rtl_uString
* keyName
,
692 RegKeyHandle
* phOpenKey
)
695 return RegError::INVALID_KEY
;
697 return openKey(hKey
, keyName
, phOpenKey
);
703 RegError REGISTRY_CALLTYPE
reg_openSubKeys(RegKeyHandle hKey
,
704 rtl_uString
* keyName
,
705 RegKeyHandle
** pphSubKeys
,
706 sal_uInt32
* pnSubKeys
)
709 return RegError::INVALID_KEY
;
711 return openSubKeys(hKey
, keyName
, pphSubKeys
, pnSubKeys
);
717 RegError REGISTRY_CALLTYPE
reg_closeSubKeys(RegKeyHandle
* pphSubKeys
,
721 return RegError::INVALID_KEY
;
723 return closeSubKeys(pphSubKeys
, nSubKeys
);
729 RegError REGISTRY_CALLTYPE
reg_deleteKey(RegKeyHandle hKey
,
730 rtl_uString
* keyName
)
733 return RegError::INVALID_KEY
;
735 return deleteKey(hKey
, keyName
);
741 RegError REGISTRY_CALLTYPE
reg_closeKey(RegKeyHandle hKey
)
744 return RegError::INVALID_KEY
;
746 return closeKey(hKey
);
753 RegError REGISTRY_CALLTYPE
reg_getKeyName(RegKeyHandle hKey
, rtl_uString
** pKeyName
)
757 rtl_uString_assign( pKeyName
, static_cast<ORegKey
*>(hKey
)->getName().pData
);
758 return RegError::NO_ERROR
;
761 rtl_uString_new( pKeyName
);
762 return RegError::INVALID_KEY
;
769 RegError REGISTRY_CALLTYPE
reg_setValue(RegKeyHandle hKey
,
770 rtl_uString
* keyName
,
771 RegValueType valueType
,
773 sal_uInt32 valueSize
)
776 return RegError::INVALID_KEY
;
778 return setValue(hKey
, keyName
, valueType
, pData
, valueSize
);
782 // reg_setLongListValue
784 RegError REGISTRY_CALLTYPE
reg_setLongListValue(RegKeyHandle hKey
,
785 rtl_uString
* keyName
,
786 sal_Int32
* pValueList
,
790 return RegError::INVALID_KEY
;
792 return setLongListValue(hKey
, keyName
, pValueList
, len
);
796 // reg_setStringListValue
798 RegError REGISTRY_CALLTYPE
reg_setStringListValue(RegKeyHandle hKey
,
799 rtl_uString
* keyName
,
800 sal_Char
** pValueList
,
804 return RegError::INVALID_KEY
;
806 return setStringListValue(hKey
, keyName
, pValueList
, len
);
810 // reg_setUnicodeListValue
812 RegError REGISTRY_CALLTYPE
reg_setUnicodeListValue(RegKeyHandle hKey
,
813 rtl_uString
* keyName
,
814 sal_Unicode
** pValueList
,
818 return RegError::INVALID_KEY
;
820 return setUnicodeListValue(hKey
, keyName
, pValueList
, len
);
826 RegError REGISTRY_CALLTYPE
reg_getValueInfo(RegKeyHandle hKey
,
827 rtl_uString
* keyName
,
828 RegValueType
* pValueType
,
829 sal_uInt32
* pValueSize
)
832 return RegError::INVALID_KEY
;
834 return getValueInfo(hKey
, keyName
, pValueType
, pValueSize
);
840 RegError REGISTRY_CALLTYPE
reg_getValue(RegKeyHandle hKey
,
841 rtl_uString
* keyName
,
845 return RegError::INVALID_KEY
;
847 return getValue(hKey
, keyName
, pData
);
851 // reg_getLongListValue
853 RegError REGISTRY_CALLTYPE
reg_getLongListValue(RegKeyHandle hKey
,
854 rtl_uString
* keyName
,
855 sal_Int32
** pValueList
,
859 return RegError::INVALID_KEY
;
861 return getLongListValue(hKey
, keyName
, pValueList
, pLen
);
865 // reg_getStringListValue
867 RegError REGISTRY_CALLTYPE
reg_getStringListValue(RegKeyHandle hKey
,
868 rtl_uString
* keyName
,
869 sal_Char
*** pValueList
,
873 return RegError::INVALID_KEY
;
875 return getStringListValue(hKey
, keyName
, pValueList
, pLen
);
879 // reg_getUnicodeListValue
881 RegError REGISTRY_CALLTYPE
reg_getUnicodeListValue(RegKeyHandle hKey
,
882 rtl_uString
* keyName
,
883 sal_Unicode
*** pValueList
,
887 return RegError::INVALID_KEY
;
889 return getUnicodeListValue(hKey
, keyName
, pValueList
, pLen
);
895 RegError REGISTRY_CALLTYPE
reg_freeValueList(RegValueType valueType
,
900 return freeValueList(valueType
, pValueList
, len
);
902 return RegError::INVALID_VALUE
;
906 // reg_getResolvedKeyName
908 RegError REGISTRY_CALLTYPE
reg_getResolvedKeyName(RegKeyHandle hKey
,
909 rtl_uString
* keyName
,
910 sal_Bool firstLinkOnly
,
911 rtl_uString
** pResolvedName
)
914 return RegError::INVALID_KEY
;
916 return getResolvedKeyName(hKey
, keyName
, firstLinkOnly
, pResolvedName
);
919 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */