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"
27 void REGISTRY_CALLTYPE
acquireKey(RegKeyHandle hKey
)
29 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
32 ORegistry
* pReg
= pKey
->getRegistry();
33 (void) pReg
->acquireKey(pKey
);
37 void REGISTRY_CALLTYPE
releaseKey(RegKeyHandle hKey
)
39 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
42 ORegistry
* pReg
= pKey
->getRegistry();
43 (void) pReg
->releaseKey(pKey
);
47 sal_Bool REGISTRY_CALLTYPE
isKeyReadOnly(RegKeyHandle hKey
)
49 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
50 return pKey
!= nullptr && pKey
->isReadOnly();
53 RegError REGISTRY_CALLTYPE
getKeyName(RegKeyHandle hKey
, rtl_uString
** pKeyName
)
55 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
58 rtl_uString_assign( pKeyName
, pKey
->getName().pData
);
59 return RegError::NO_ERROR
;
62 rtl_uString_new(pKeyName
);
63 return RegError::INVALID_KEY
;
67 RegError REGISTRY_CALLTYPE
createKey(RegKeyHandle hKey
,
69 RegKeyHandle
* phNewKey
)
73 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
75 return RegError::INVALID_KEY
;
77 if (pKey
->isDeleted())
78 return RegError::INVALID_KEY
;
80 if (pKey
->isReadOnly())
81 return RegError::REGISTRY_READONLY
;
83 return pKey
->createKey(OUString::unacquired(&keyName
), phNewKey
);
86 RegError REGISTRY_CALLTYPE
openKey(RegKeyHandle hKey
,
88 RegKeyHandle
* phOpenKey
)
92 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
94 return RegError::INVALID_KEY
;
96 if (pKey
->isDeleted())
97 return RegError::INVALID_KEY
;
99 return pKey
->openKey(OUString::unacquired(&keyName
), phOpenKey
);
102 RegError REGISTRY_CALLTYPE
openSubKeys(RegKeyHandle hKey
,
103 rtl_uString
* keyName
,
104 RegKeyHandle
** pphSubKeys
,
105 sal_uInt32
* pnSubKeys
)
107 *pphSubKeys
= 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
->openSubKeys(OUString::unacquired(&keyName
), pphSubKeys
, pnSubKeys
);
120 RegError REGISTRY_CALLTYPE
closeSubKeys(RegKeyHandle
* phSubKeys
,
123 if (phSubKeys
== nullptr || nSubKeys
== 0)
124 return RegError::INVALID_KEY
;
126 ORegistry
* pReg
= static_cast<ORegKey
*>(phSubKeys
[0])->getRegistry();
127 for (sal_uInt32 i
= 0; i
< nSubKeys
; i
++)
129 (void) pReg
->closeKey(phSubKeys
[i
]);
131 std::free(phSubKeys
);
133 return RegError::NO_ERROR
;
136 RegError REGISTRY_CALLTYPE
deleteKey(RegKeyHandle hKey
,
137 rtl_uString
* keyName
)
139 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
141 return RegError::INVALID_KEY
;
143 if (pKey
->isDeleted())
144 return RegError::INVALID_KEY
;
146 if (pKey
->isReadOnly())
147 return RegError::REGISTRY_READONLY
;
149 return pKey
->deleteKey(OUString::unacquired(&keyName
));
152 RegError REGISTRY_CALLTYPE
closeKey(RegKeyHandle hKey
)
154 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
156 return RegError::INVALID_KEY
;
158 return pKey
->closeKey(hKey
);
161 RegError REGISTRY_CALLTYPE
setValue(RegKeyHandle hKey
,
162 rtl_uString
* keyName
,
163 RegValueType valueType
,
165 sal_uInt32 valueSize
)
167 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
169 return RegError::INVALID_KEY
;
171 if (pKey
->isDeleted())
172 return RegError::INVALID_KEY
;
174 if (pKey
->isReadOnly())
175 return RegError::REGISTRY_READONLY
;
177 OUString
valueName(u
"value"_ustr
);
180 ORegKey
* pSubKey
= nullptr;
181 RegError _ret1
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
182 if (_ret1
!= RegError::NO_ERROR
)
185 _ret1
= pSubKey
->setValue(valueName
, valueType
, pData
, valueSize
);
186 if (_ret1
!= RegError::NO_ERROR
)
188 RegError _ret2
= pKey
->closeKey(pSubKey
);
189 if (_ret2
!= RegError::NO_ERROR
)
195 return pKey
->closeKey(pSubKey
);
198 return pKey
->setValue(valueName
, valueType
, pData
, valueSize
);
201 RegError REGISTRY_CALLTYPE
setLongListValue(RegKeyHandle hKey
,
202 rtl_uString
* keyName
,
203 sal_Int32
const * pValueList
,
206 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
208 return RegError::INVALID_KEY
;
210 if (pKey
->isDeleted())
211 return RegError::INVALID_KEY
;
213 if (pKey
->isReadOnly())
214 return RegError::REGISTRY_READONLY
;
216 OUString
valueName(u
"value"_ustr
);
219 ORegKey
* pSubKey
= nullptr;
220 RegError _ret1
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
221 if (_ret1
!= RegError::NO_ERROR
)
224 _ret1
= pSubKey
->setLongListValue(valueName
, pValueList
, len
);
225 if (_ret1
!= RegError::NO_ERROR
)
227 RegError _ret2
= pKey
->closeKey(pSubKey
);
228 if (_ret2
!= RegError::NO_ERROR
)
234 return pKey
->closeKey(pSubKey
);
237 return pKey
->setLongListValue(valueName
, pValueList
, len
);
240 RegError REGISTRY_CALLTYPE
setStringListValue(RegKeyHandle hKey
,
241 rtl_uString
* keyName
,
245 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
247 return RegError::INVALID_KEY
;
249 if (pKey
->isDeleted())
250 return RegError::INVALID_KEY
;
252 if (pKey
->isReadOnly())
253 return RegError::REGISTRY_READONLY
;
255 OUString
valueName(u
"value"_ustr
);
258 ORegKey
* pSubKey
= nullptr;
259 RegError _ret1
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
260 if (_ret1
!= RegError::NO_ERROR
)
263 _ret1
= pSubKey
->setStringListValue(valueName
, pValueList
, len
);
264 if (_ret1
!= RegError::NO_ERROR
)
266 RegError _ret2
= pKey
->closeKey(pSubKey
);
267 if (_ret2
!= RegError::NO_ERROR
)
273 return pKey
->closeKey(pSubKey
);
276 return pKey
->setStringListValue(valueName
, pValueList
, len
);
279 RegError REGISTRY_CALLTYPE
setUnicodeListValue(RegKeyHandle hKey
,
280 rtl_uString
* keyName
,
281 sal_Unicode
** pValueList
,
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(u
"value"_ustr
);
297 ORegKey
* pSubKey
= nullptr;
298 RegError _ret1
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
299 if (_ret1
!= RegError::NO_ERROR
)
302 _ret1
= pSubKey
->setUnicodeListValue(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
->setUnicodeListValue(valueName
, pValueList
, len
);
318 RegError REGISTRY_CALLTYPE
getValueInfo(RegKeyHandle hKey
,
319 rtl_uString
* keyName
,
320 RegValueType
* pValueType
,
321 sal_uInt32
* pValueSize
)
323 *pValueType
= RegValueType::NOT_DEFINED
;
326 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
328 return RegError::INVALID_KEY
;
330 if (pKey
->isDeleted())
331 return RegError::INVALID_KEY
;
333 RegValueType valueType
;
334 sal_uInt32 valueSize
;
336 OUString
valueName(u
"value"_ustr
);
339 ORegKey
* pSubKey
= nullptr;
340 RegError _ret
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
341 if (_ret
!= RegError::NO_ERROR
)
344 if (pSubKey
->getValueInfo(valueName
, &valueType
, &valueSize
) != RegError::NO_ERROR
)
346 (void) pKey
->releaseKey(pSubKey
);
347 return RegError::INVALID_VALUE
;
350 *pValueType
= valueType
;
351 *pValueSize
= valueSize
;
353 return pKey
->releaseKey(pSubKey
);
357 if (pKey
->getValueInfo(valueName
, &valueType
, &valueSize
) != RegError::NO_ERROR
)
359 return RegError::INVALID_VALUE
;
362 *pValueType
= valueType
;
363 *pValueSize
= valueSize
;
365 return RegError::NO_ERROR
;
368 RegError REGISTRY_CALLTYPE
getValue(RegKeyHandle hKey
,
369 rtl_uString
* keyName
,
372 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
374 return RegError::INVALID_KEY
;
376 if (pKey
->isDeleted())
377 return RegError::INVALID_KEY
;
379 OUString
valueName(u
"value"_ustr
);
382 ORegKey
* pSubKey
= nullptr;
383 RegError _ret1
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
384 if (_ret1
!= RegError::NO_ERROR
)
387 _ret1
= pSubKey
->getValue(valueName
, pValue
);
388 if (_ret1
!= RegError::NO_ERROR
)
390 (void) pKey
->releaseKey(pSubKey
);
394 return pKey
->releaseKey(pSubKey
);
397 return pKey
->getValue(valueName
, pValue
);
400 RegError REGISTRY_CALLTYPE
getLongListValue(RegKeyHandle hKey
,
401 rtl_uString
* keyName
,
402 sal_Int32
** pValueList
,
405 assert((pValueList
!= nullptr) && (pLen
!= nullptr) && "registry::getLongListValue(): invalid parameter");
406 *pValueList
= nullptr;
409 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
411 return RegError::INVALID_KEY
;
413 if (pKey
->isDeleted())
414 return RegError::INVALID_KEY
;
416 OUString
valueName(u
"value"_ustr
);
419 ORegKey
* pSubKey
= nullptr;
420 RegError _ret1
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
421 if (_ret1
!= RegError::NO_ERROR
)
424 _ret1
= pSubKey
->getLongListValue(valueName
, pValueList
, pLen
);
425 if (_ret1
!= RegError::NO_ERROR
)
427 (void) pKey
->releaseKey(pSubKey
);
431 return pKey
->releaseKey(pSubKey
);
434 return pKey
->getLongListValue(valueName
, pValueList
, pLen
);
437 RegError REGISTRY_CALLTYPE
getStringListValue(RegKeyHandle hKey
,
438 rtl_uString
* keyName
,
442 assert(pValueList
!= nullptr && pLen
!= nullptr && "registry::getStringListValue(): invalid parameter");
443 *pValueList
= nullptr;
446 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
448 return RegError::INVALID_KEY
;
450 if (pKey
->isDeleted())
451 return RegError::INVALID_KEY
;
453 OUString
valueName(u
"value"_ustr
);
456 ORegKey
* pSubKey
= nullptr;
457 RegError _ret1
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
458 if (_ret1
!= RegError::NO_ERROR
)
461 _ret1
= pSubKey
->getStringListValue(valueName
, pValueList
, pLen
);
462 if (_ret1
!= RegError::NO_ERROR
)
464 (void) pKey
->releaseKey(pSubKey
);
468 return pKey
->releaseKey(pSubKey
);
471 return pKey
->getStringListValue(valueName
, pValueList
, pLen
);
474 RegError REGISTRY_CALLTYPE
getUnicodeListValue(RegKeyHandle hKey
,
475 rtl_uString
* keyName
,
476 sal_Unicode
*** pValueList
,
479 assert((pValueList
!= nullptr) && (pLen
!= nullptr) && "registry::getUnicodeListValue(): invalid parameter");
480 *pValueList
= nullptr;
483 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
485 return RegError::INVALID_KEY
;
487 if (pKey
->isDeleted())
488 return RegError::INVALID_KEY
;
490 OUString
valueName(u
"value"_ustr
);
493 ORegKey
* pSubKey
= nullptr;
494 RegError _ret1
= pKey
->openKey(OUString::unacquired(&keyName
), reinterpret_cast<RegKeyHandle
*>(&pSubKey
));
495 if (_ret1
!= RegError::NO_ERROR
)
498 _ret1
= pSubKey
->getUnicodeListValue(valueName
, pValueList
, pLen
);
499 if (_ret1
!= RegError::NO_ERROR
)
501 (void) pKey
->releaseKey(pSubKey
);
505 return pKey
->releaseKey(pSubKey
);
508 return pKey
->getUnicodeListValue(valueName
, pValueList
, pLen
);
511 RegError REGISTRY_CALLTYPE
freeValueList(RegValueType valueType
,
517 case RegValueType::LONGLIST
:
519 std::free(pValueList
);
522 case RegValueType::STRINGLIST
:
524 char** pVList
= static_cast<char**>(pValueList
);
525 for (sal_uInt32 i
=0; i
< len
; i
++)
527 std::free(pVList
[i
]);
533 case RegValueType::UNICODELIST
:
535 sal_Unicode
** pVList
= static_cast<sal_Unicode
**>(pValueList
);
536 for (sal_uInt32 i
=0; i
< len
; i
++)
538 std::free(pVList
[i
]);
545 return RegError::INVALID_VALUE
;
548 pValueList
= nullptr;
549 return RegError::NO_ERROR
;
552 RegError REGISTRY_CALLTYPE
getResolvedKeyName(RegKeyHandle hKey
,
553 rtl_uString
* keyName
,
554 SAL_UNUSED_PARAMETER sal_Bool
,
555 rtl_uString
** pResolvedName
)
557 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
559 return RegError::INVALID_KEY
;
561 if (pKey
->isDeleted())
562 return RegError::INVALID_KEY
;
564 OUString resolvedName
;
565 RegError _ret
= pKey
->getResolvedKeyName(OUString::unacquired(&keyName
), resolvedName
);
566 if (_ret
== RegError::NO_ERROR
)
567 rtl_uString_assign(pResolvedName
, resolvedName
.pData
);
571 RegError REGISTRY_CALLTYPE
getKeyNames(RegKeyHandle hKey
,
572 rtl_uString
* keyName
,
573 rtl_uString
*** pSubKeyNames
,
574 sal_uInt32
* pnSubKeys
)
576 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
578 return RegError::INVALID_KEY
;
580 if (pKey
->isDeleted())
581 return RegError::INVALID_KEY
;
583 return pKey
->getKeyNames(OUString::unacquired(&keyName
), pSubKeyNames
, pnSubKeys
);
586 RegError REGISTRY_CALLTYPE
freeKeyNames(rtl_uString
** pKeyNames
,
589 for (sal_uInt32 i
=0; i
< nKeys
; i
++)
591 rtl_uString_release(pKeyNames
[i
]);
594 std::free(pKeyNames
);
596 return RegError::NO_ERROR
;
599 RegError REGISTRY_CALLTYPE
reg_openKey(RegKeyHandle hKey
,
600 rtl_uString
* keyName
,
601 RegKeyHandle
* phOpenKey
)
604 return RegError::INVALID_KEY
;
606 return openKey(hKey
, keyName
, phOpenKey
);
609 RegError REGISTRY_CALLTYPE
reg_closeKey(RegKeyHandle hKey
)
612 return RegError::INVALID_KEY
;
614 return closeKey(hKey
);
618 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */