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 <osl/diagnose.h>
24 #include "regimpl.hxx"
25 #include "keyimpl.hxx"
30 void REGISTRY_CALLTYPE
acquireKey(RegKeyHandle hKey
)
32 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
35 ORegistry
* pReg
= pKey
->getRegistry();
36 (void) pReg
->acquireKey(pKey
);
43 void REGISTRY_CALLTYPE
releaseKey(RegKeyHandle hKey
)
45 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
48 ORegistry
* pReg
= pKey
->getRegistry();
49 (void) pReg
->releaseKey(pKey
);
56 sal_Bool REGISTRY_CALLTYPE
isKeyReadOnly(RegKeyHandle hKey
)
58 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
59 return pKey
!= nullptr && pKey
->isReadOnly();
65 RegError REGISTRY_CALLTYPE
getKeyName(RegKeyHandle hKey
, rtl_uString
** pKeyName
)
67 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
70 rtl_uString_assign( pKeyName
, pKey
->getName().pData
);
71 return RegError::NO_ERROR
;
74 rtl_uString_new(pKeyName
);
75 return RegError::INVALID_KEY
;
82 RegError REGISTRY_CALLTYPE
createKey(RegKeyHandle hKey
,
84 RegKeyHandle
* phNewKey
)
88 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
90 return RegError::INVALID_KEY
;
92 if (pKey
->isDeleted())
93 return RegError::INVALID_KEY
;
95 if (pKey
->isReadOnly())
96 return RegError::REGISTRY_READONLY
;
98 return pKey
->createKey(keyName
, phNewKey
);
104 RegError REGISTRY_CALLTYPE
openKey(RegKeyHandle hKey
,
105 rtl_uString
* keyName
,
106 RegKeyHandle
* phOpenKey
)
108 *phOpenKey
= nullptr;
110 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
112 return RegError::INVALID_KEY
;
114 if (pKey
->isDeleted())
115 return RegError::INVALID_KEY
;
117 return pKey
->openKey(keyName
, phOpenKey
);
123 RegError REGISTRY_CALLTYPE
openSubKeys(RegKeyHandle hKey
,
124 rtl_uString
* keyName
,
125 RegKeyHandle
** pphSubKeys
,
126 sal_uInt32
* pnSubKeys
)
128 *pphSubKeys
= nullptr;
131 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
133 return RegError::INVALID_KEY
;
135 if (pKey
->isDeleted())
136 return RegError::INVALID_KEY
;
138 return pKey
->openSubKeys(keyName
, pphSubKeys
, pnSubKeys
);
144 RegError REGISTRY_CALLTYPE
closeSubKeys(RegKeyHandle
* phSubKeys
,
147 if (phSubKeys
== nullptr || nSubKeys
== 0)
148 return RegError::INVALID_KEY
;
150 ORegistry
* pReg
= static_cast<ORegKey
*>(phSubKeys
[0])->getRegistry();
151 for (sal_uInt32 i
= 0; i
< nSubKeys
; i
++)
153 (void) pReg
->closeKey(phSubKeys
[i
]);
155 std::free(phSubKeys
);
157 return RegError::NO_ERROR
;
163 RegError REGISTRY_CALLTYPE
deleteKey(RegKeyHandle hKey
,
164 rtl_uString
* keyName
)
166 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
168 return RegError::INVALID_KEY
;
170 if (pKey
->isDeleted())
171 return RegError::INVALID_KEY
;
173 if (pKey
->isReadOnly())
174 return RegError::REGISTRY_READONLY
;
176 return pKey
->deleteKey(keyName
);
182 RegError REGISTRY_CALLTYPE
closeKey(RegKeyHandle hKey
)
184 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
186 return RegError::INVALID_KEY
;
188 return pKey
->closeKey(hKey
);
194 RegError REGISTRY_CALLTYPE
setValue(RegKeyHandle hKey
,
195 rtl_uString
* keyName
,
196 RegValueType valueType
,
198 sal_uInt32 valueSize
)
200 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
202 return RegError::INVALID_KEY
;
204 if (pKey
->isDeleted())
205 return RegError::INVALID_KEY
;
207 if (pKey
->isReadOnly())
208 return RegError::REGISTRY_READONLY
;
210 OUString
valueName("value");
213 ORegKey
* pSubKey
= nullptr;
214 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
215 if (_ret1
!= RegError::NO_ERROR
)
218 _ret1
= pSubKey
->setValue(valueName
, valueType
, pData
, valueSize
);
219 if (_ret1
!= RegError::NO_ERROR
)
221 RegError _ret2
= pKey
->closeKey(pSubKey
);
222 if (_ret2
!= RegError::NO_ERROR
)
228 return pKey
->closeKey(pSubKey
);
231 return pKey
->setValue(valueName
, valueType
, pData
, valueSize
);
237 RegError REGISTRY_CALLTYPE
setLongListValue(RegKeyHandle hKey
,
238 rtl_uString
* keyName
,
239 sal_Int32
const * pValueList
,
242 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
244 return RegError::INVALID_KEY
;
246 if (pKey
->isDeleted())
247 return RegError::INVALID_KEY
;
249 if (pKey
->isReadOnly())
250 return RegError::REGISTRY_READONLY
;
252 OUString
valueName("value");
255 ORegKey
* pSubKey
= nullptr;
256 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
257 if (_ret1
!= RegError::NO_ERROR
)
260 _ret1
= pSubKey
->setLongListValue(valueName
, pValueList
, len
);
261 if (_ret1
!= RegError::NO_ERROR
)
263 RegError _ret2
= pKey
->closeKey(pSubKey
);
264 if (_ret2
!= RegError::NO_ERROR
)
270 return pKey
->closeKey(pSubKey
);
273 return pKey
->setLongListValue(valueName
, pValueList
, len
);
277 // setStringValueList
279 RegError REGISTRY_CALLTYPE
setStringListValue(RegKeyHandle hKey
,
280 rtl_uString
* keyName
,
284 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
286 return RegError::INVALID_KEY
;
288 if (pKey
->isDeleted())
289 return RegError::INVALID_KEY
;
291 if (pKey
->isReadOnly())
292 return RegError::REGISTRY_READONLY
;
294 OUString
valueName("value");
297 ORegKey
* pSubKey
= nullptr;
298 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
299 if (_ret1
!= RegError::NO_ERROR
)
302 _ret1
= pSubKey
->setStringListValue(valueName
, pValueList
, len
);
303 if (_ret1
!= RegError::NO_ERROR
)
305 RegError _ret2
= pKey
->closeKey(pSubKey
);
306 if (_ret2
!= RegError::NO_ERROR
)
312 return pKey
->closeKey(pSubKey
);
315 return pKey
->setStringListValue(valueName
, pValueList
, len
);
319 // setUnicodeValueList
321 RegError REGISTRY_CALLTYPE
setUnicodeListValue(RegKeyHandle hKey
,
322 rtl_uString
* keyName
,
323 sal_Unicode
** pValueList
,
326 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
328 return RegError::INVALID_KEY
;
330 if (pKey
->isDeleted())
331 return RegError::INVALID_KEY
;
333 if (pKey
->isReadOnly())
334 return RegError::REGISTRY_READONLY
;
336 OUString
valueName("value");
339 ORegKey
* pSubKey
= nullptr;
340 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
341 if (_ret1
!= RegError::NO_ERROR
)
344 _ret1
= pSubKey
->setUnicodeListValue(valueName
, pValueList
, len
);
345 if (_ret1
!= RegError::NO_ERROR
)
347 RegError _ret2
= pKey
->closeKey(pSubKey
);
348 if (_ret2
!= RegError::NO_ERROR
)
354 return pKey
->closeKey(pSubKey
);
357 return pKey
->setUnicodeListValue(valueName
, pValueList
, len
);
363 RegError REGISTRY_CALLTYPE
getValueInfo(RegKeyHandle hKey
,
364 rtl_uString
* keyName
,
365 RegValueType
* pValueType
,
366 sal_uInt32
* pValueSize
)
368 *pValueType
= RegValueType::NOT_DEFINED
;
371 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
373 return RegError::INVALID_KEY
;
375 if (pKey
->isDeleted())
376 return RegError::INVALID_KEY
;
378 RegValueType valueType
;
379 sal_uInt32 valueSize
;
381 OUString
valueName("value");
384 ORegKey
* pSubKey
= nullptr;
385 RegError _ret
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
386 if (_ret
!= RegError::NO_ERROR
)
389 if (pSubKey
->getValueInfo(valueName
, &valueType
, &valueSize
) != RegError::NO_ERROR
)
391 (void) pKey
->releaseKey(pSubKey
);
392 return RegError::INVALID_VALUE
;
395 *pValueType
= valueType
;
396 *pValueSize
= valueSize
;
398 return pKey
->releaseKey(pSubKey
);
402 if (pKey
->getValueInfo(valueName
, &valueType
, &valueSize
) != RegError::NO_ERROR
)
404 return RegError::INVALID_VALUE
;
407 *pValueType
= valueType
;
408 *pValueSize
= valueSize
;
410 return RegError::NO_ERROR
;
416 RegError REGISTRY_CALLTYPE
getValue(RegKeyHandle hKey
,
417 rtl_uString
* keyName
,
420 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
422 return RegError::INVALID_KEY
;
424 if (pKey
->isDeleted())
425 return RegError::INVALID_KEY
;
427 OUString
valueName("value");
430 ORegKey
* pSubKey
= nullptr;
431 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
432 if (_ret1
!= RegError::NO_ERROR
)
435 _ret1
= pSubKey
->getValue(valueName
, pValue
);
436 if (_ret1
!= RegError::NO_ERROR
)
438 (void) pKey
->releaseKey(pSubKey
);
442 return pKey
->releaseKey(pSubKey
);
445 return pKey
->getValue(valueName
, pValue
);
451 RegError REGISTRY_CALLTYPE
getLongListValue(RegKeyHandle hKey
,
452 rtl_uString
* keyName
,
453 sal_Int32
** pValueList
,
456 assert((pValueList
!= nullptr) && (pLen
!= nullptr) && "registry::getLongListValue(): invalid parameter");
457 *pValueList
= nullptr;
460 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
462 return RegError::INVALID_KEY
;
464 if (pKey
->isDeleted())
465 return RegError::INVALID_KEY
;
467 OUString
valueName("value");
470 ORegKey
* pSubKey
= nullptr;
471 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
472 if (_ret1
!= RegError::NO_ERROR
)
475 _ret1
= pSubKey
->getLongListValue(valueName
, pValueList
, pLen
);
476 if (_ret1
!= RegError::NO_ERROR
)
478 (void) pKey
->releaseKey(pSubKey
);
482 return pKey
->releaseKey(pSubKey
);
485 return pKey
->getLongListValue(valueName
, pValueList
, pLen
);
489 // getStringValueList
491 RegError REGISTRY_CALLTYPE
getStringListValue(RegKeyHandle hKey
,
492 rtl_uString
* keyName
,
496 OSL_PRECOND((pValueList
!= nullptr) && (pLen
!= nullptr), "registry::getStringListValue(): invalid parameter");
497 *pValueList
= nullptr;
500 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
502 return RegError::INVALID_KEY
;
504 if (pKey
->isDeleted())
505 return RegError::INVALID_KEY
;
507 OUString
valueName("value");
510 ORegKey
* pSubKey
= nullptr;
511 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
512 if (_ret1
!= RegError::NO_ERROR
)
515 _ret1
= pSubKey
->getStringListValue(valueName
, pValueList
, pLen
);
516 if (_ret1
!= RegError::NO_ERROR
)
518 (void) pKey
->releaseKey(pSubKey
);
522 return pKey
->releaseKey(pSubKey
);
525 return pKey
->getStringListValue(valueName
, pValueList
, pLen
);
528 // getUnicodeListValue
529 RegError REGISTRY_CALLTYPE
getUnicodeListValue(RegKeyHandle hKey
,
530 rtl_uString
* keyName
,
531 sal_Unicode
*** pValueList
,
534 assert((pValueList
!= nullptr) && (pLen
!= nullptr) && "registry::getUnicodeListValue(): invalid parameter");
535 *pValueList
= nullptr;
538 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
540 return RegError::INVALID_KEY
;
542 if (pKey
->isDeleted())
543 return RegError::INVALID_KEY
;
545 OUString
valueName("value");
548 ORegKey
* pSubKey
= nullptr;
549 RegError _ret1
= pKey
->openKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
550 if (_ret1
!= RegError::NO_ERROR
)
553 _ret1
= pSubKey
->getUnicodeListValue(valueName
, pValueList
, pLen
);
554 if (_ret1
!= RegError::NO_ERROR
)
556 (void) pKey
->releaseKey(pSubKey
);
560 return pKey
->releaseKey(pSubKey
);
563 return pKey
->getUnicodeListValue(valueName
, pValueList
, pLen
);
569 RegError REGISTRY_CALLTYPE
freeValueList(RegValueType valueType
,
575 case RegValueType::LONGLIST
:
577 std::free(pValueList
);
580 case RegValueType::STRINGLIST
:
582 char** pVList
= static_cast<char**>(pValueList
);
583 for (sal_uInt32 i
=0; i
< len
; i
++)
585 std::free(pVList
[i
]);
591 case RegValueType::UNICODELIST
:
593 sal_Unicode
** pVList
= static_cast<sal_Unicode
**>(pValueList
);
594 for (sal_uInt32 i
=0; i
< len
; i
++)
596 std::free(pVList
[i
]);
603 return RegError::INVALID_VALUE
;
606 pValueList
= nullptr;
607 return RegError::NO_ERROR
;
613 RegError REGISTRY_CALLTYPE
getResolvedKeyName(RegKeyHandle hKey
,
614 rtl_uString
* keyName
,
615 SAL_UNUSED_PARAMETER sal_Bool
,
616 rtl_uString
** pResolvedName
)
618 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
620 return RegError::INVALID_KEY
;
622 if (pKey
->isDeleted())
623 return RegError::INVALID_KEY
;
625 OUString resolvedName
;
626 RegError _ret
= pKey
->getResolvedKeyName(keyName
, resolvedName
);
627 if (_ret
== RegError::NO_ERROR
)
628 rtl_uString_assign(pResolvedName
, resolvedName
.pData
);
635 RegError REGISTRY_CALLTYPE
getKeyNames(RegKeyHandle hKey
,
636 rtl_uString
* keyName
,
637 rtl_uString
*** pSubKeyNames
,
638 sal_uInt32
* pnSubKeys
)
640 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
642 return RegError::INVALID_KEY
;
644 if (pKey
->isDeleted())
645 return RegError::INVALID_KEY
;
647 return pKey
->getKeyNames(keyName
, pSubKeyNames
, pnSubKeys
);
653 RegError REGISTRY_CALLTYPE
freeKeyNames(rtl_uString
** pKeyNames
,
656 for (sal_uInt32 i
=0; i
< nKeys
; i
++)
658 rtl_uString_release(pKeyNames
[i
]);
661 std::free(pKeyNames
);
663 return RegError::NO_ERROR
;
672 RegError REGISTRY_CALLTYPE
reg_openKey(RegKeyHandle hKey
,
673 rtl_uString
* keyName
,
674 RegKeyHandle
* phOpenKey
)
677 return RegError::INVALID_KEY
;
679 return openKey(hKey
, keyName
, phOpenKey
);
685 RegError REGISTRY_CALLTYPE
reg_closeKey(RegKeyHandle hKey
)
688 return RegError::INVALID_KEY
;
690 return closeKey(hKey
);
694 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */