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 .
21 #include <registry/registry.h>
22 #include <registry/registry.hxx>
24 #include <osl/process.h>
26 #include "keyimpl.hxx"
27 #include "regimpl.hxx"
30 #if defined(WIN32) || defined(WNT)
45 static void REGISTRY_CALLTYPE
acquire(RegHandle hReg
)
47 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
57 static void REGISTRY_CALLTYPE
release(RegHandle hReg
)
59 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
63 if (pReg
->release() == 0)
75 static RegError REGISTRY_CALLTYPE
getName(RegHandle hReg
, rtl_uString
** pName
)
79 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
82 rtl_uString_assign(pName
, pReg
->getName().pData
);
83 return RegError::NO_ERROR
;
86 rtl_uString_new(pName
);
87 return RegError::REGISTRY_NOT_OPEN
;
91 rtl_uString_new(pName
);
92 return RegError::INVALID_REGISTRY
;
99 static sal_Bool REGISTRY_CALLTYPE
isReadOnly(RegHandle hReg
)
102 return static_cast<ORegistry
*>(hReg
)->isReadOnly();
111 static RegError REGISTRY_CALLTYPE
createRegistry(rtl_uString
* registryName
,
112 RegHandle
* phRegistry
)
116 ORegistry
* pReg
= new ORegistry();
117 if ((ret
= pReg
->initRegistry(registryName
, RegAccessMode::READWRITE
, true/*bCreate*/)) != RegError::NO_ERROR
)
126 return RegError::NO_ERROR
;
132 static RegError REGISTRY_CALLTYPE
openRootKey(RegHandle hReg
,
133 RegKeyHandle
* phRootKey
)
139 pReg
= static_cast<ORegistry
*>(hReg
);
141 return RegError::REGISTRY_NOT_OPEN
;
145 return RegError::INVALID_REGISTRY
;
148 *phRootKey
= pReg
->getRootKey();
150 return RegError::NO_ERROR
;
157 static RegError REGISTRY_CALLTYPE
openRegistry(rtl_uString
* registryName
,
158 RegHandle
* phRegistry
,
159 RegAccessMode accessMode
)
163 ORegistry
* pReg
= new ORegistry();
164 if ((_ret
= pReg
->initRegistry(registryName
, accessMode
)) != RegError::NO_ERROR
)
174 return RegError::NO_ERROR
;
180 static RegError REGISTRY_CALLTYPE
closeRegistry(RegHandle hReg
)
186 pReg
= static_cast<ORegistry
*>(hReg
);
188 return RegError::REGISTRY_NOT_OPEN
;
190 RegError ret
= RegError::NO_ERROR
;
191 if (pReg
->release() == 0)
197 ret
= pReg
->closeRegistry();
202 return RegError::INVALID_REGISTRY
;
210 static RegError REGISTRY_CALLTYPE
destroyRegistry(RegHandle hReg
,
211 rtl_uString
* registryName
)
217 pReg
= static_cast<ORegistry
*>(hReg
);
219 return RegError::INVALID_REGISTRY
;
221 RegError ret
= pReg
->destroyRegistry(registryName
);
222 if (ret
== RegError::NO_ERROR
)
224 if (!registryName
->length
)
233 return RegError::INVALID_REGISTRY
;
241 static RegError REGISTRY_CALLTYPE
loadKey(RegHandle hReg
,
243 rtl_uString
* keyName
,
244 rtl_uString
* regFileName
)
247 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
249 return RegError::INVALID_REGISTRY
;
252 return RegError::REGISTRY_NOT_OPEN
;
254 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
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
)
278 _ret
= pReg
->loadKey(pNewKey
, regFileName
);
279 if (_ret
!= RegError::NO_ERROR
)
281 pKey
->releaseKey(pNewKey
);
282 pKey
->deleteKey(keyName
);
286 return pKey
->closeKey(pNewKey
);
292 static RegError REGISTRY_CALLTYPE
saveKey(RegHandle hReg
,
294 rtl_uString
* keyName
,
295 rtl_uString
* regFileName
)
298 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
300 return RegError::INVALID_REGISTRY
;
303 return RegError::REGISTRY_NOT_OPEN
;
305 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
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
)
319 _ret
= pReg
->saveKey(pNewKey
, regFileName
);
320 if (_ret
!= RegError::NO_ERROR
)
322 (void) pKey
->releaseKey(pNewKey
);
326 return pKey
->releaseKey(pNewKey
);
332 static RegError REGISTRY_CALLTYPE
mergeKey(RegHandle hReg
,
334 rtl_uString
* keyName
,
335 rtl_uString
* regFileName
,
339 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
341 return RegError::INVALID_REGISTRY
;
343 return RegError::REGISTRY_NOT_OPEN
;
345 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
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
;
357 ORegKey
* pNewKey
= 0;
358 RegError _ret
= pKey
->createKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pNewKey
));
359 if (_ret
!= RegError::NO_ERROR
)
362 _ret
= pReg
->loadKey(pNewKey
, regFileName
, bWarnings
, bReport
);
363 if (_ret
!= RegError::NO_ERROR
&& (_ret
!= RegError::MERGE_CONFLICT
|| bWarnings
))
366 (void) pKey
->closeKey(pNewKey
);
368 (void) pKey
->releaseKey(pNewKey
);
372 return (pNewKey
!= pKey
) ? pKey
->closeKey(pNewKey
) : pKey
->releaseKey(pNewKey
);
375 return pReg
->loadKey(pKey
, regFileName
, bWarnings
, bReport
);
381 static RegError REGISTRY_CALLTYPE
dumpRegistry(RegHandle hReg
,
384 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
386 return RegError::INVALID_REGISTRY
;
388 return RegError::REGISTRY_NOT_OPEN
;
390 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
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
);
404 Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api()
406 static Registry_Api aApi
= {&acquire
,
432 &setUnicodeListValue
,
437 &getUnicodeListValue
,
451 RegError REGISTRY_CALLTYPE
reg_loadKey(RegKeyHandle hKey
,
452 rtl_uString
* keyName
,
453 rtl_uString
* regFileName
)
458 pKey
= static_cast<ORegKey
*>(hKey
);
460 return RegError::INVALID_KEY
;
462 return loadKey(pKey
->getRegistry(), hKey
, keyName
, regFileName
);
468 RegError REGISTRY_CALLTYPE
reg_saveKey(RegKeyHandle hKey
,
469 rtl_uString
* keyName
,
470 rtl_uString
* regFileName
)
475 pKey
= static_cast<ORegKey
*>(hKey
);
477 return RegError::INVALID_KEY
;
479 return saveKey(pKey
->getRegistry(), hKey
, keyName
, regFileName
);
485 RegError REGISTRY_CALLTYPE
reg_mergeKey(RegKeyHandle hKey
,
486 rtl_uString
* keyName
,
487 rtl_uString
* regFileName
,
494 pKey
= static_cast<ORegKey
*>(hKey
);
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
)
509 ORegistry
* pReg
= new ORegistry();
510 if ((ret
= pReg
->initRegistry(registryName
, RegAccessMode::READWRITE
, true/*bCreate*/)) != RegError::NO_ERROR
)
519 return RegError::NO_ERROR
;
525 RegError REGISTRY_CALLTYPE
reg_openRootKey(RegHandle hRegistry
,
526 RegKeyHandle
* phRootKey
)
528 return openRootKey(hRegistry
, phRootKey
);
535 RegError REGISTRY_CALLTYPE
reg_getName(RegHandle hRegistry
, rtl_uString
** pName
)
537 return getName(hRegistry
, pName
);
544 sal_Bool REGISTRY_CALLTYPE
reg_isReadOnly(RegHandle hRegistry
)
546 return isReadOnly(hRegistry
);
553 RegError REGISTRY_CALLTYPE
reg_openRegistry(rtl_uString
* registryName
,
554 RegHandle
* phRegistry
,
555 RegAccessMode accessMode
)
559 ORegistry
* pReg
= new ORegistry();
560 if ((_ret
= pReg
->initRegistry(registryName
, accessMode
)) != RegError::NO_ERROR
)
569 return RegError::NO_ERROR
;
575 RegError REGISTRY_CALLTYPE
reg_closeRegistry(RegHandle hRegistry
)
579 ORegistry
* pReg
= static_cast<ORegistry
*>(hRegistry
);
581 return RegError::NO_ERROR
;
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
);
602 RegError REGISTRY_CALLTYPE
reg_dumpRegistry(RegKeyHandle hKey
)
607 pKey
= static_cast<ORegKey
*>(hKey
);
609 return RegError::INVALID_KEY
;
611 return dumpRegistry(pKey
->getRegistry(), hKey
);
615 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */