Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / registry / source / registry.cxx
blobc498f113c7c682da8a8bcd73895c8f576c06abd3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
25 #include "regkey.hxx"
27 #if defined(_WIN32)
28 #include <io.h>
29 #endif
31 extern "C" {
33 static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
35 ORegistry* pReg = static_cast<ORegistry*>(hReg);
37 if (pReg != nullptr)
38 pReg->acquire();
41 static void REGISTRY_CALLTYPE release(RegHandle hReg)
43 ORegistry* pReg = static_cast<ORegistry*>(hReg);
45 if (pReg && pReg->release() == 0)
47 delete pReg;
48 hReg = nullptr;
52 static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
54 if (hReg)
56 ORegistry* pReg = static_cast<ORegistry*>(hReg);
57 if ( pReg->isOpen() )
59 rtl_uString_assign(pName, pReg->getName().pData);
60 return RegError::NO_ERROR;
61 } else
63 rtl_uString_new(pName);
64 return RegError::REGISTRY_NOT_OPEN;
68 rtl_uString_new(pName);
69 return RegError::INVALID_REGISTRY;
72 static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
74 if (hReg)
75 return static_cast<ORegistry*>(hReg)->isReadOnly();
76 else
77 return false;
80 static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
81 RegHandle* phRegistry)
83 RegError ret;
85 ORegistry* pReg = new ORegistry();
86 if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)) != RegError::NO_ERROR)
88 delete pReg;
89 *phRegistry = nullptr;
90 return ret;
93 *phRegistry = pReg;
95 return RegError::NO_ERROR;
98 static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg,
99 RegKeyHandle* phRootKey)
101 ORegistry* pReg;
103 if (hReg)
105 pReg = static_cast<ORegistry*>(hReg);
106 if (!pReg->isOpen())
107 return RegError::REGISTRY_NOT_OPEN;
108 } else
110 phRootKey = nullptr;
111 return RegError::INVALID_REGISTRY;
114 *phRootKey = pReg->getRootKey();
116 return RegError::NO_ERROR;
119 static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
120 RegHandle* phRegistry,
121 RegAccessMode accessMode)
123 RegError _ret;
125 ORegistry* pReg = new ORegistry();
126 if ((_ret = pReg->initRegistry(registryName, accessMode)) != RegError::NO_ERROR)
128 *phRegistry = nullptr;
129 delete pReg;
130 return _ret;
134 *phRegistry = pReg;
136 return RegError::NO_ERROR;
139 static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
141 if (hReg)
143 ORegistry *pReg = static_cast<ORegistry*>(hReg);
144 if (!pReg->isOpen())
145 return RegError::REGISTRY_NOT_OPEN;
147 RegError ret = RegError::NO_ERROR;
148 if (pReg->release() == 0)
150 delete pReg;
151 hReg = nullptr;
153 else
154 ret = pReg->closeRegistry();
156 return ret;
157 } else
159 return RegError::INVALID_REGISTRY;
163 static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg,
164 rtl_uString* registryName)
166 if (hReg)
168 ORegistry *pReg = static_cast<ORegistry*>(hReg);
169 if (!pReg->isOpen())
170 return RegError::INVALID_REGISTRY;
172 RegError ret = pReg->destroyRegistry(registryName);
173 if (ret == RegError::NO_ERROR)
175 if (!registryName->length)
177 delete pReg;
178 hReg = nullptr;
181 return ret;
182 } else
184 return RegError::INVALID_REGISTRY;
189 // dumpRegistry
191 static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg,
192 RegKeyHandle hKey)
194 ORegistry* pReg = static_cast< ORegistry* >(hReg);
195 if (!pReg)
196 return RegError::INVALID_REGISTRY;
197 if (!pReg->isOpen())
198 return RegError::REGISTRY_NOT_OPEN;
200 ORegKey* pKey = static_cast< ORegKey* >(hKey);
201 if (!pKey)
202 return RegError::INVALID_KEY;
203 if (pKey->getRegistry() != pReg)
204 return RegError::INVALID_KEY;
205 if (pKey->isDeleted())
206 return RegError::INVALID_KEY;
208 return pReg->dumpRegistry(hKey);
211 Registry_Api* REGISTRY_CALLTYPE initRegistry_Api()
213 static Registry_Api aApi= {&acquire,
214 &release,
215 &isReadOnly,
216 &openRootKey,
217 &getName,
218 &createRegistry,
219 &openRegistry,
220 &closeRegistry,
221 &destroyRegistry,
222 &acquireKey,
223 &releaseKey,
224 &isKeyReadOnly,
225 &getKeyName,
226 &createKey,
227 &openKey,
228 &openSubKeys,
229 &closeSubKeys,
230 &deleteKey,
231 &closeKey,
232 &setValue,
233 &setLongListValue,
234 &setStringListValue,
235 &setUnicodeListValue,
236 &getValueInfo,
237 &getValue,
238 &getLongListValue,
239 &getStringListValue,
240 &getUnicodeListValue,
241 &freeValueList,
242 &getResolvedKeyName,
243 &getKeyNames,
244 &freeKeyNames};
246 return (&aApi);
251 RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
252 RegKeyHandle* phRootKey)
254 return openRootKey(hRegistry, phRootKey);
257 RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
258 RegHandle* phRegistry)
260 RegError _ret;
262 ORegistry* pReg = new ORegistry();
263 if ((_ret = pReg->initRegistry(registryName, RegAccessMode::READONLY)) != RegError::NO_ERROR)
265 delete pReg;
266 *phRegistry = nullptr;
267 return _ret;
270 *phRegistry = pReg;
272 return RegError::NO_ERROR;
275 RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
277 if (hRegistry)
279 ORegistry* pReg = static_cast<ORegistry*>(hRegistry);
280 delete pReg;
281 return RegError::NO_ERROR;
282 } else
284 return RegError::REGISTRY_NOT_OPEN;
288 RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey)
290 ORegKey *pKey;
292 if (hKey)
293 pKey = static_cast<ORegKey*>(hKey);
294 else
295 return RegError::INVALID_KEY;
297 return dumpRegistry(pKey->getRegistry(), hKey);
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */