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 .
22 #include <registry/registry.hxx>
24 #include <osl/process.h>
26 #include "keyimpl.hxx"
27 #include "regimpl.hxx"
45 static void REGISTRY_CALLTYPE
acquire(RegHandle hReg
)
47 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
56 static void REGISTRY_CALLTYPE
release(RegHandle hReg
)
58 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
62 if (pReg
->release() == 0)
73 static RegError REGISTRY_CALLTYPE
getName(RegHandle hReg
, rtl_uString
** pName
)
77 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
80 rtl_uString_assign(pName
, pReg
->getName().pData
);
81 return RegError::NO_ERROR
;
84 rtl_uString_new(pName
);
85 return RegError::REGISTRY_NOT_OPEN
;
89 rtl_uString_new(pName
);
90 return RegError::INVALID_REGISTRY
;
96 static sal_Bool REGISTRY_CALLTYPE
isReadOnly(RegHandle hReg
)
99 return static_cast<ORegistry
*>(hReg
)->isReadOnly();
107 static RegError REGISTRY_CALLTYPE
createRegistry(rtl_uString
* registryName
,
108 RegHandle
* phRegistry
)
112 ORegistry
* pReg
= new ORegistry();
113 if ((ret
= pReg
->initRegistry(registryName
, RegAccessMode::READWRITE
, true/*bCreate*/)) != RegError::NO_ERROR
)
116 *phRegistry
= nullptr;
122 return RegError::NO_ERROR
;
128 static RegError REGISTRY_CALLTYPE
openRootKey(RegHandle hReg
,
129 RegKeyHandle
* phRootKey
)
135 pReg
= static_cast<ORegistry
*>(hReg
);
137 return RegError::REGISTRY_NOT_OPEN
;
141 return RegError::INVALID_REGISTRY
;
144 *phRootKey
= pReg
->getRootKey();
146 return RegError::NO_ERROR
;
152 static RegError REGISTRY_CALLTYPE
openRegistry(rtl_uString
* registryName
,
153 RegHandle
* phRegistry
,
154 RegAccessMode accessMode
)
158 ORegistry
* pReg
= new ORegistry();
159 if ((_ret
= pReg
->initRegistry(registryName
, accessMode
)) != RegError::NO_ERROR
)
161 *phRegistry
= nullptr;
169 return RegError::NO_ERROR
;
175 static RegError REGISTRY_CALLTYPE
closeRegistry(RegHandle hReg
)
181 pReg
= static_cast<ORegistry
*>(hReg
);
183 return RegError::REGISTRY_NOT_OPEN
;
185 RegError ret
= RegError::NO_ERROR
;
186 if (pReg
->release() == 0)
192 ret
= pReg
->closeRegistry();
197 return RegError::INVALID_REGISTRY
;
204 static RegError REGISTRY_CALLTYPE
destroyRegistry(RegHandle hReg
,
205 rtl_uString
* registryName
)
211 pReg
= static_cast<ORegistry
*>(hReg
);
213 return RegError::INVALID_REGISTRY
;
215 RegError ret
= pReg
->destroyRegistry(registryName
);
216 if (ret
== RegError::NO_ERROR
)
218 if (!registryName
->length
)
227 return RegError::INVALID_REGISTRY
;
234 static RegError REGISTRY_CALLTYPE
mergeKey(RegHandle hReg
,
236 rtl_uString
* keyName
,
237 rtl_uString
* regFileName
,
241 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
243 return RegError::INVALID_REGISTRY
;
245 return RegError::REGISTRY_NOT_OPEN
;
247 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
249 return RegError::INVALID_KEY
;
250 if (pKey
->getRegistry() != pReg
)
251 return RegError::INVALID_KEY
;
252 if (pKey
->isDeleted())
253 return RegError::INVALID_KEY
;
254 if (pKey
->isReadOnly())
255 return RegError::REGISTRY_READONLY
;
259 ORegKey
* pNewKey
= nullptr;
260 RegError _ret
= pKey
->createKey(keyName
, reinterpret_cast<RegKeyHandle
*>(&pNewKey
));
261 if (_ret
!= RegError::NO_ERROR
)
264 _ret
= pReg
->loadKey(pNewKey
, regFileName
, bWarnings
, bReport
);
265 if (_ret
!= RegError::NO_ERROR
&& (_ret
!= RegError::MERGE_CONFLICT
|| bWarnings
))
268 (void) pKey
->closeKey(pNewKey
);
270 (void) pKey
->releaseKey(pNewKey
);
274 return (pNewKey
!= pKey
) ? pKey
->closeKey(pNewKey
) : pKey
->releaseKey(pNewKey
);
277 return pReg
->loadKey(pKey
, regFileName
, bWarnings
, bReport
);
283 static RegError REGISTRY_CALLTYPE
dumpRegistry(RegHandle hReg
,
286 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
288 return RegError::INVALID_REGISTRY
;
290 return RegError::REGISTRY_NOT_OPEN
;
292 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
294 return RegError::INVALID_KEY
;
295 if (pKey
->getRegistry() != pReg
)
296 return RegError::INVALID_KEY
;
297 if (pKey
->isDeleted())
298 return RegError::INVALID_KEY
;
300 return pReg
->dumpRegistry(hKey
);
306 Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api()
308 static Registry_Api aApi
= {&acquire
,
331 &setUnicodeListValue
,
336 &getUnicodeListValue
,
350 RegError REGISTRY_CALLTYPE
reg_openRootKey(RegHandle hRegistry
,
351 RegKeyHandle
* phRootKey
)
353 return openRootKey(hRegistry
, phRootKey
);
359 RegError REGISTRY_CALLTYPE
reg_openRegistry(rtl_uString
* registryName
,
360 RegHandle
* phRegistry
)
364 ORegistry
* pReg
= new ORegistry();
365 if ((_ret
= pReg
->initRegistry(registryName
, RegAccessMode::READONLY
)) != RegError::NO_ERROR
)
368 *phRegistry
= nullptr;
374 return RegError::NO_ERROR
;
380 RegError REGISTRY_CALLTYPE
reg_closeRegistry(RegHandle hRegistry
)
384 ORegistry
* pReg
= static_cast<ORegistry
*>(hRegistry
);
386 return RegError::NO_ERROR
;
389 return RegError::REGISTRY_NOT_OPEN
;
396 RegError REGISTRY_CALLTYPE
reg_dumpRegistry(RegKeyHandle hKey
)
401 pKey
= static_cast<ORegKey
*>(hKey
);
403 return RegError::INVALID_KEY
;
405 return dumpRegistry(pKey
->getRegistry(), hKey
);
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */