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.hxx>
23 #include "keyimpl.hxx"
24 #include "regimpl.hxx"
36 static void REGISTRY_CALLTYPE
acquire(RegHandle hReg
)
38 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
47 static void REGISTRY_CALLTYPE
release(RegHandle hReg
)
49 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
51 if (pReg
&& pReg
->release() == 0)
61 static RegError REGISTRY_CALLTYPE
getName(RegHandle hReg
, rtl_uString
** pName
)
65 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
68 rtl_uString_assign(pName
, pReg
->getName().pData
);
69 return RegError::NO_ERROR
;
72 rtl_uString_new(pName
);
73 return RegError::REGISTRY_NOT_OPEN
;
77 rtl_uString_new(pName
);
78 return RegError::INVALID_REGISTRY
;
84 static sal_Bool REGISTRY_CALLTYPE
isReadOnly(RegHandle hReg
)
87 return static_cast<ORegistry
*>(hReg
)->isReadOnly();
95 static RegError REGISTRY_CALLTYPE
createRegistry(rtl_uString
* registryName
,
96 RegHandle
* phRegistry
)
100 ORegistry
* pReg
= new ORegistry();
101 if ((ret
= pReg
->initRegistry(registryName
, RegAccessMode::READWRITE
, true/*bCreate*/)) != RegError::NO_ERROR
)
104 *phRegistry
= nullptr;
110 return RegError::NO_ERROR
;
116 static RegError REGISTRY_CALLTYPE
openRootKey(RegHandle hReg
,
117 RegKeyHandle
* phRootKey
)
123 pReg
= static_cast<ORegistry
*>(hReg
);
125 return RegError::REGISTRY_NOT_OPEN
;
129 return RegError::INVALID_REGISTRY
;
132 *phRootKey
= pReg
->getRootKey();
134 return RegError::NO_ERROR
;
140 static RegError REGISTRY_CALLTYPE
openRegistry(rtl_uString
* registryName
,
141 RegHandle
* phRegistry
,
142 RegAccessMode accessMode
)
146 ORegistry
* pReg
= new ORegistry();
147 if ((_ret
= pReg
->initRegistry(registryName
, accessMode
)) != RegError::NO_ERROR
)
149 *phRegistry
= nullptr;
157 return RegError::NO_ERROR
;
163 static RegError REGISTRY_CALLTYPE
closeRegistry(RegHandle hReg
)
169 pReg
= static_cast<ORegistry
*>(hReg
);
171 return RegError::REGISTRY_NOT_OPEN
;
173 RegError ret
= RegError::NO_ERROR
;
174 if (pReg
->release() == 0)
180 ret
= pReg
->closeRegistry();
185 return RegError::INVALID_REGISTRY
;
192 static RegError REGISTRY_CALLTYPE
destroyRegistry(RegHandle hReg
,
193 rtl_uString
* registryName
)
199 pReg
= static_cast<ORegistry
*>(hReg
);
201 return RegError::INVALID_REGISTRY
;
203 RegError ret
= pReg
->destroyRegistry(registryName
);
204 if (ret
== RegError::NO_ERROR
)
206 if (!registryName
->length
)
215 return RegError::INVALID_REGISTRY
;
222 static RegError REGISTRY_CALLTYPE
mergeKey(RegHandle hReg
,
224 rtl_uString
* keyName
,
225 rtl_uString
* regFileName
,
229 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
231 return RegError::INVALID_REGISTRY
;
233 return RegError::REGISTRY_NOT_OPEN
;
235 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
237 return RegError::INVALID_KEY
;
238 if (pKey
->getRegistry() != pReg
)
239 return RegError::INVALID_KEY
;
240 if (pKey
->isDeleted())
241 return RegError::INVALID_KEY
;
242 if (pKey
->isReadOnly())
243 return RegError::REGISTRY_READONLY
;
247 ORegKey
* pNewKey
= nullptr;
248 RegError _ret
= pKey
->createKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pNewKey
));
249 if (_ret
!= RegError::NO_ERROR
)
252 _ret
= pReg
->loadKey(pNewKey
, regFileName
, bWarnings
, bReport
);
253 if (_ret
!= RegError::NO_ERROR
&& (_ret
!= RegError::MERGE_CONFLICT
|| bWarnings
))
256 (void) pKey
->closeKey(pNewKey
);
258 (void) pKey
->releaseKey(pNewKey
);
262 return (pNewKey
!= pKey
) ? pKey
->closeKey(pNewKey
) : pKey
->releaseKey(pNewKey
);
265 return pReg
->loadKey(pKey
, regFileName
, bWarnings
, bReport
);
271 static RegError REGISTRY_CALLTYPE
dumpRegistry(RegHandle hReg
,
274 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
276 return RegError::INVALID_REGISTRY
;
278 return RegError::REGISTRY_NOT_OPEN
;
280 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
282 return RegError::INVALID_KEY
;
283 if (pKey
->getRegistry() != pReg
)
284 return RegError::INVALID_KEY
;
285 if (pKey
->isDeleted())
286 return RegError::INVALID_KEY
;
288 return pReg
->dumpRegistry(hKey
);
294 Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api()
296 static Registry_Api aApi
= {&acquire
,
319 &setUnicodeListValue
,
324 &getUnicodeListValue
,
338 RegError REGISTRY_CALLTYPE
reg_openRootKey(RegHandle hRegistry
,
339 RegKeyHandle
* phRootKey
)
341 return openRootKey(hRegistry
, phRootKey
);
347 RegError REGISTRY_CALLTYPE
reg_openRegistry(rtl_uString
* registryName
,
348 RegHandle
* phRegistry
)
352 ORegistry
* pReg
= new ORegistry();
353 if ((_ret
= pReg
->initRegistry(registryName
, RegAccessMode::READONLY
)) != RegError::NO_ERROR
)
356 *phRegistry
= nullptr;
362 return RegError::NO_ERROR
;
368 RegError REGISTRY_CALLTYPE
reg_closeRegistry(RegHandle hRegistry
)
372 ORegistry
* pReg
= static_cast<ORegistry
*>(hRegistry
);
374 return RegError::NO_ERROR
;
377 return RegError::REGISTRY_NOT_OPEN
;
384 RegError REGISTRY_CALLTYPE
reg_dumpRegistry(RegKeyHandle hKey
)
389 pKey
= static_cast<ORegKey
*>(hKey
);
391 return RegError::INVALID_KEY
;
393 return dumpRegistry(pKey
->getRegistry(), hKey
);
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */