xref: /trunk/main/registry/source/registry.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_registry.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <registry/registry.h>
32*cdf0e10cSrcweir #include <registry/registry.hxx>
33*cdf0e10cSrcweir #include <osl/process.h>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "keyimpl.hxx"
36*cdf0e10cSrcweir #include "regimpl.hxx"
37*cdf0e10cSrcweir #include "regkey.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #if defined(WIN32) || defined(WNT) || defined(OS2)
40*cdf0e10cSrcweir #include <io.h>
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <string.h>
44*cdf0e10cSrcweir #if defined(UNX)
45*cdf0e10cSrcweir #include <stdlib.h>
46*cdf0e10cSrcweir #include <unistd.h>
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #if defined ( GCC ) && ( defined ( SCO ) )
50*cdf0e10cSrcweir ORealDynamicLoader* ODynamicLoader<Registry_Api>::m_pLoader = NULL;
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir extern "C" {
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir //*********************************************************************
56*cdf0e10cSrcweir //	acquire
57*cdf0e10cSrcweir //
58*cdf0e10cSrcweir static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir 	ORegistry* pReg = (ORegistry*) hReg;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 	if (pReg != NULL)
63*cdf0e10cSrcweir 		pReg->acquire();
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir //*********************************************************************
68*cdf0e10cSrcweir //	release
69*cdf0e10cSrcweir //
70*cdf0e10cSrcweir static void REGISTRY_CALLTYPE release(RegHandle hReg)
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir 	ORegistry* pReg = (ORegistry*) hReg;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 	if (pReg)
75*cdf0e10cSrcweir 	{
76*cdf0e10cSrcweir 		if (pReg->release() == 0)
77*cdf0e10cSrcweir 		{
78*cdf0e10cSrcweir 			delete pReg;
79*cdf0e10cSrcweir 			hReg = NULL;
80*cdf0e10cSrcweir 		}
81*cdf0e10cSrcweir 	}
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir //*********************************************************************
86*cdf0e10cSrcweir //	getName
87*cdf0e10cSrcweir //
88*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	ORegistry* 	pReg;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	if (hReg)
93*cdf0e10cSrcweir 	{
94*cdf0e10cSrcweir 		pReg = (ORegistry*)hReg;
95*cdf0e10cSrcweir 		if ( pReg->isOpen() )
96*cdf0e10cSrcweir 		{
97*cdf0e10cSrcweir 			rtl_uString_assign(pName, pReg->getName().pData);
98*cdf0e10cSrcweir 			return REG_NO_ERROR;
99*cdf0e10cSrcweir 		} else
100*cdf0e10cSrcweir 		{
101*cdf0e10cSrcweir 			rtl_uString_new(pName);
102*cdf0e10cSrcweir 			return REG_REGISTRY_NOT_OPEN;
103*cdf0e10cSrcweir 		}
104*cdf0e10cSrcweir 	}
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	rtl_uString_new(pName);
107*cdf0e10cSrcweir 	return REG_INVALID_REGISTRY;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir //*********************************************************************
112*cdf0e10cSrcweir //	isReadOnly
113*cdf0e10cSrcweir //
114*cdf0e10cSrcweir static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	if (hReg)
117*cdf0e10cSrcweir 		return ((ORegistry*)hReg)->isReadOnly();
118*cdf0e10cSrcweir 	else
119*cdf0e10cSrcweir 		return sal_False;
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir //*********************************************************************
124*cdf0e10cSrcweir //	createRegistry
125*cdf0e10cSrcweir //
126*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
127*cdf0e10cSrcweir 											     RegHandle* phRegistry)
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir 	RegError ret;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	ORegistry* pReg = new ORegistry();
132*cdf0e10cSrcweir 	if ((ret = pReg->initRegistry(registryName, REG_CREATE)))
133*cdf0e10cSrcweir 	{
134*cdf0e10cSrcweir 		*phRegistry = NULL;
135*cdf0e10cSrcweir 		return ret;
136*cdf0e10cSrcweir 	}
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	*phRegistry = pReg;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	return REG_NO_ERROR;
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir //*********************************************************************
144*cdf0e10cSrcweir //	openRootKey
145*cdf0e10cSrcweir //
146*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg,
147*cdf0e10cSrcweir 											  RegKeyHandle* phRootKey)
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	ORegistry* pReg;
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	if (hReg)
152*cdf0e10cSrcweir 	{
153*cdf0e10cSrcweir 		pReg = (ORegistry*)hReg;
154*cdf0e10cSrcweir 		if (!pReg->isOpen())
155*cdf0e10cSrcweir 			return REG_REGISTRY_NOT_OPEN;
156*cdf0e10cSrcweir 	} else
157*cdf0e10cSrcweir 	{
158*cdf0e10cSrcweir 		phRootKey = NULL;
159*cdf0e10cSrcweir 		return REG_INVALID_REGISTRY;
160*cdf0e10cSrcweir 	}
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	*phRootKey = pReg->getRootKey();
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	return REG_NO_ERROR;
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir //*********************************************************************
169*cdf0e10cSrcweir //	openRegistry
170*cdf0e10cSrcweir //
171*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
172*cdf0e10cSrcweir 											   RegHandle* phRegistry,
173*cdf0e10cSrcweir 											   RegAccessMode accessMode)
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir 	RegError _ret;
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	ORegistry* pReg = new ORegistry();
178*cdf0e10cSrcweir 	if ((_ret = pReg->initRegistry(registryName, accessMode)))
179*cdf0e10cSrcweir 	{
180*cdf0e10cSrcweir 		*phRegistry = NULL;
181*cdf0e10cSrcweir 		delete pReg;
182*cdf0e10cSrcweir 		return _ret;
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	*phRegistry = pReg;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	return REG_NO_ERROR;
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir //*********************************************************************
192*cdf0e10cSrcweir //	closeRegistry
193*cdf0e10cSrcweir //
194*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	ORegistry	*pReg;
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	if (hReg)
199*cdf0e10cSrcweir 	{
200*cdf0e10cSrcweir 		pReg = (ORegistry*)hReg;
201*cdf0e10cSrcweir 		if (!pReg->isOpen())
202*cdf0e10cSrcweir 			return REG_REGISTRY_NOT_OPEN;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 		RegError ret = REG_NO_ERROR;
205*cdf0e10cSrcweir 		if (pReg->release() == 0)
206*cdf0e10cSrcweir 		{
207*cdf0e10cSrcweir 			delete(pReg);
208*cdf0e10cSrcweir 			hReg = NULL;
209*cdf0e10cSrcweir 		}
210*cdf0e10cSrcweir 		else
211*cdf0e10cSrcweir 			ret = pReg->closeRegistry();
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 		return ret;
214*cdf0e10cSrcweir 	} else
215*cdf0e10cSrcweir 	{
216*cdf0e10cSrcweir 		return REG_INVALID_REGISTRY;
217*cdf0e10cSrcweir 	}
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir //*********************************************************************
222*cdf0e10cSrcweir //	destroyRegistry
223*cdf0e10cSrcweir //
224*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg,
225*cdf0e10cSrcweir 												  rtl_uString* registryName)
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir 	ORegistry	*pReg;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	if (hReg)
230*cdf0e10cSrcweir 	{
231*cdf0e10cSrcweir 		pReg = (ORegistry*)hReg;
232*cdf0e10cSrcweir 		if (!pReg->isOpen())
233*cdf0e10cSrcweir 			return REG_INVALID_REGISTRY;
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 		RegError ret = pReg->destroyRegistry(registryName);
236*cdf0e10cSrcweir 		if (!ret)
237*cdf0e10cSrcweir 		{
238*cdf0e10cSrcweir 			if (!registryName->length)
239*cdf0e10cSrcweir 			{
240*cdf0e10cSrcweir 				delete(pReg);
241*cdf0e10cSrcweir 				hReg = NULL;
242*cdf0e10cSrcweir 			}
243*cdf0e10cSrcweir 		}
244*cdf0e10cSrcweir 		return ret;
245*cdf0e10cSrcweir 	} else
246*cdf0e10cSrcweir 	{
247*cdf0e10cSrcweir 		return REG_INVALID_REGISTRY;
248*cdf0e10cSrcweir 	}
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir //*********************************************************************
253*cdf0e10cSrcweir //	loadRegKey
254*cdf0e10cSrcweir //
255*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE loadKey(RegHandle hReg,
256*cdf0e10cSrcweir 								   		   RegKeyHandle hKey,
257*cdf0e10cSrcweir 										   rtl_uString* keyName,
258*cdf0e10cSrcweir 										   rtl_uString* regFileName)
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 	ORegistry* pReg = static_cast< ORegistry* >(hReg);
262*cdf0e10cSrcweir 	if (!pReg)
263*cdf0e10cSrcweir 		return REG_INVALID_REGISTRY;
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	if (!pReg->isOpen())
266*cdf0e10cSrcweir 		return REG_REGISTRY_NOT_OPEN;
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	ORegKey* pKey = static_cast< ORegKey* >(hKey);
269*cdf0e10cSrcweir 	if (!pKey)
270*cdf0e10cSrcweir 		return REG_INVALID_KEY;
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 	if (pKey->getRegistry() != pReg)
273*cdf0e10cSrcweir 		return REG_INVALID_KEY;
274*cdf0e10cSrcweir 	if (pKey->isDeleted())
275*cdf0e10cSrcweir 		return REG_INVALID_KEY;
276*cdf0e10cSrcweir 	if (pKey->isReadOnly())
277*cdf0e10cSrcweir 		return REG_REGISTRY_READONLY;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	ORegKey* pNewKey = 0;
281*cdf0e10cSrcweir 	RegError _ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey);
282*cdf0e10cSrcweir 	if (_ret == REG_NO_ERROR)
283*cdf0e10cSrcweir 	{
284*cdf0e10cSrcweir 		pKey->releaseKey(pNewKey);
285*cdf0e10cSrcweir 		pKey->deleteKey(keyName);
286*cdf0e10cSrcweir 	}
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 	_ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey);
289*cdf0e10cSrcweir 	if (_ret != REG_NO_ERROR)
290*cdf0e10cSrcweir 		return _ret;
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 	_ret = pReg->loadKey(pNewKey, regFileName);
293*cdf0e10cSrcweir 	if (_ret != REG_NO_ERROR)
294*cdf0e10cSrcweir 	{
295*cdf0e10cSrcweir 		pKey->releaseKey(pNewKey);
296*cdf0e10cSrcweir 		pKey->deleteKey(keyName);
297*cdf0e10cSrcweir 		return _ret;
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 	return pKey->closeKey(pNewKey);
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir //*********************************************************************
304*cdf0e10cSrcweir //	saveKey
305*cdf0e10cSrcweir //
306*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE saveKey(RegHandle hReg,
307*cdf0e10cSrcweir 								   		   RegKeyHandle hKey,
308*cdf0e10cSrcweir 										   rtl_uString* keyName,
309*cdf0e10cSrcweir 										   rtl_uString* regFileName)
310*cdf0e10cSrcweir {
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 	ORegistry* pReg = static_cast< ORegistry* >(hReg);
313*cdf0e10cSrcweir 	if (!pReg)
314*cdf0e10cSrcweir 		return REG_INVALID_REGISTRY;
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 	if (!pReg->isOpen())
317*cdf0e10cSrcweir 		return REG_REGISTRY_NOT_OPEN;
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 	ORegKey* pKey = static_cast< ORegKey* >(hKey);
320*cdf0e10cSrcweir 	if (!pKey)
321*cdf0e10cSrcweir 		return REG_INVALID_KEY;
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 	if (pKey->getRegistry() != pReg)
324*cdf0e10cSrcweir 		return REG_INVALID_KEY;
325*cdf0e10cSrcweir 	if (pKey->isDeleted())
326*cdf0e10cSrcweir 		return REG_INVALID_KEY;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 	ORegKey* pNewKey = 0;
329*cdf0e10cSrcweir 	RegError _ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey);
330*cdf0e10cSrcweir 	if (_ret != REG_NO_ERROR)
331*cdf0e10cSrcweir 		return _ret;
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir 	_ret = pReg->saveKey(pNewKey, regFileName);
334*cdf0e10cSrcweir 	if (_ret != REG_NO_ERROR)
335*cdf0e10cSrcweir 	{
336*cdf0e10cSrcweir 		(void) pKey->releaseKey(pNewKey);
337*cdf0e10cSrcweir 		return _ret;
338*cdf0e10cSrcweir 	}
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	return pKey->releaseKey(pNewKey);
341*cdf0e10cSrcweir }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir //*********************************************************************
344*cdf0e10cSrcweir //	mergeKey
345*cdf0e10cSrcweir //
346*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg,
347*cdf0e10cSrcweir 								   		   RegKeyHandle hKey,
348*cdf0e10cSrcweir 										   rtl_uString* keyName,
349*cdf0e10cSrcweir 										   rtl_uString* regFileName,
350*cdf0e10cSrcweir 										   sal_Bool bWarnings,
351*cdf0e10cSrcweir 										   sal_Bool bReport)
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir 	ORegistry* pReg = static_cast< ORegistry* >(hReg);
354*cdf0e10cSrcweir 	if (!pReg)
355*cdf0e10cSrcweir 		return REG_INVALID_REGISTRY;
356*cdf0e10cSrcweir 	if (!pReg->isOpen())
357*cdf0e10cSrcweir 		return REG_REGISTRY_NOT_OPEN;
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 	ORegKey* pKey = static_cast< ORegKey* >(hKey);
360*cdf0e10cSrcweir 	if (!pKey)
361*cdf0e10cSrcweir 		return REG_INVALID_KEY;
362*cdf0e10cSrcweir 	if (pKey->getRegistry() != pReg)
363*cdf0e10cSrcweir 		return REG_INVALID_KEY;
364*cdf0e10cSrcweir 	if (pKey->isDeleted())
365*cdf0e10cSrcweir 		return REG_INVALID_KEY;
366*cdf0e10cSrcweir 	if (pKey->isReadOnly())
367*cdf0e10cSrcweir 		return REG_REGISTRY_READONLY;
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 	if (keyName->length)
370*cdf0e10cSrcweir 	{
371*cdf0e10cSrcweir 		ORegKey* pNewKey = 0;
372*cdf0e10cSrcweir 		RegError _ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey);
373*cdf0e10cSrcweir 		if (_ret != REG_NO_ERROR)
374*cdf0e10cSrcweir 			return _ret;
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 		_ret = pReg->loadKey(pNewKey, regFileName, bWarnings, bReport);
377*cdf0e10cSrcweir 		if (_ret == REG_MERGE_ERROR || (_ret == REG_MERGE_CONFLICT && bWarnings))
378*cdf0e10cSrcweir 		{
379*cdf0e10cSrcweir 			if (pNewKey != pKey)
380*cdf0e10cSrcweir 				(void) pKey->closeKey(pNewKey);
381*cdf0e10cSrcweir 			else
382*cdf0e10cSrcweir 				(void) pKey->releaseKey(pNewKey);
383*cdf0e10cSrcweir 			return _ret;
384*cdf0e10cSrcweir 		}
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 		return (pNewKey != pKey) ? pKey->closeKey(pNewKey) : pKey->releaseKey(pNewKey);
387*cdf0e10cSrcweir 	}
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 	return pReg->loadKey(pKey, regFileName, bWarnings, bReport);
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir //*********************************************************************
393*cdf0e10cSrcweir //	dumpRegistry
394*cdf0e10cSrcweir //
395*cdf0e10cSrcweir static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg,
396*cdf0e10cSrcweir 											   RegKeyHandle hKey)
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir 	ORegistry* pReg = static_cast< ORegistry* >(hReg);
399*cdf0e10cSrcweir 	if (!pReg)
400*cdf0e10cSrcweir 		return REG_INVALID_REGISTRY;
401*cdf0e10cSrcweir 	if (!pReg->isOpen())
402*cdf0e10cSrcweir 		return REG_REGISTRY_NOT_OPEN;
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	ORegKey* pKey = static_cast< ORegKey* >(hKey);
405*cdf0e10cSrcweir 	if (!pKey)
406*cdf0e10cSrcweir 		return REG_INVALID_KEY;
407*cdf0e10cSrcweir 	if (pKey->getRegistry() != pReg)
408*cdf0e10cSrcweir 		return REG_INVALID_KEY;
409*cdf0e10cSrcweir 	if (pKey->isDeleted())
410*cdf0e10cSrcweir 		return REG_INVALID_KEY;
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	return pReg->dumpRegistry(hKey);
413*cdf0e10cSrcweir }
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir //*********************************************************************
416*cdf0e10cSrcweir //	initRegistry_Api
417*cdf0e10cSrcweir //
418*cdf0e10cSrcweir Registry_Api* REGISTRY_CALLTYPE initRegistry_Api(void)
419*cdf0e10cSrcweir {
420*cdf0e10cSrcweir 	static Registry_Api aApi= {&acquire,
421*cdf0e10cSrcweir 							   &release,
422*cdf0e10cSrcweir 							   &isReadOnly,
423*cdf0e10cSrcweir 							   &openRootKey,
424*cdf0e10cSrcweir 							   &getName,
425*cdf0e10cSrcweir 							   &createRegistry,
426*cdf0e10cSrcweir 							   &openRegistry,
427*cdf0e10cSrcweir 							   &closeRegistry,
428*cdf0e10cSrcweir 							   &destroyRegistry,
429*cdf0e10cSrcweir 							   &loadKey,
430*cdf0e10cSrcweir 							   &saveKey,
431*cdf0e10cSrcweir 							   &mergeKey,
432*cdf0e10cSrcweir 							   &dumpRegistry,
433*cdf0e10cSrcweir 							   &acquireKey,
434*cdf0e10cSrcweir 							   &releaseKey,
435*cdf0e10cSrcweir 							   &isKeyReadOnly,
436*cdf0e10cSrcweir 							   &getKeyName,
437*cdf0e10cSrcweir 							   &createKey,
438*cdf0e10cSrcweir 							   &openKey,
439*cdf0e10cSrcweir 							   &openSubKeys,
440*cdf0e10cSrcweir 							   &closeSubKeys,
441*cdf0e10cSrcweir 							   &deleteKey,
442*cdf0e10cSrcweir 							   &closeKey,
443*cdf0e10cSrcweir 							   &setValue,
444*cdf0e10cSrcweir 							   &setLongListValue,
445*cdf0e10cSrcweir 							   &setStringListValue,
446*cdf0e10cSrcweir 							   &setUnicodeListValue,
447*cdf0e10cSrcweir 							   &getValueInfo,
448*cdf0e10cSrcweir 							   &getValue,
449*cdf0e10cSrcweir 							   &getLongListValue,
450*cdf0e10cSrcweir 							   &getStringListValue,
451*cdf0e10cSrcweir 							   &getUnicodeListValue,
452*cdf0e10cSrcweir 							   &freeValueList,
453*cdf0e10cSrcweir 							   &createLink,
454*cdf0e10cSrcweir 							   &deleteLink,
455*cdf0e10cSrcweir 							   &getKeyType,
456*cdf0e10cSrcweir 							   &getLinkTarget,
457*cdf0e10cSrcweir 							   &getResolvedKeyName,
458*cdf0e10cSrcweir 							   &getKeyNames,
459*cdf0e10cSrcweir 							   &freeKeyNames};
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir 	return (&aApi);
462*cdf0e10cSrcweir }
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir }
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir //*********************************************************************
467*cdf0e10cSrcweir //	reg_loadRegKey
468*cdf0e10cSrcweir //
469*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_loadKey(RegKeyHandle hKey,
470*cdf0e10cSrcweir 									   rtl_uString* keyName,
471*cdf0e10cSrcweir 									   rtl_uString* regFileName)
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir 	ORegKey *pKey;
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 	if (hKey)
476*cdf0e10cSrcweir 		pKey = (ORegKey*)hKey;
477*cdf0e10cSrcweir 	else
478*cdf0e10cSrcweir 		return REG_INVALID_KEY;
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir 	return loadKey(pKey->getRegistry(), hKey, keyName, regFileName);
481*cdf0e10cSrcweir }
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir //*********************************************************************
484*cdf0e10cSrcweir //	reg_saveKey
485*cdf0e10cSrcweir //
486*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_saveKey(RegKeyHandle hKey,
487*cdf0e10cSrcweir 									   rtl_uString* keyName,
488*cdf0e10cSrcweir 									   rtl_uString* regFileName)
489*cdf0e10cSrcweir {
490*cdf0e10cSrcweir 	ORegKey *pKey;
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 	if (hKey)
493*cdf0e10cSrcweir 		pKey = (ORegKey*)hKey;
494*cdf0e10cSrcweir 	else
495*cdf0e10cSrcweir 		return REG_INVALID_KEY;
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 	return saveKey(pKey->getRegistry(), hKey, keyName, regFileName);
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir //*********************************************************************
501*cdf0e10cSrcweir //	reg_mergeKey
502*cdf0e10cSrcweir //
503*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_mergeKey(RegKeyHandle hKey,
504*cdf0e10cSrcweir 									    rtl_uString* keyName,
505*cdf0e10cSrcweir 									    rtl_uString* regFileName,
506*cdf0e10cSrcweir 										sal_Bool bWarnings,
507*cdf0e10cSrcweir 										sal_Bool bReport)
508*cdf0e10cSrcweir {
509*cdf0e10cSrcweir 	ORegKey *pKey;
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 	if (hKey)
512*cdf0e10cSrcweir 		pKey = (ORegKey*)hKey;
513*cdf0e10cSrcweir 	else
514*cdf0e10cSrcweir 		return REG_INVALID_KEY;
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir 	return mergeKey(pKey->getRegistry(), hKey, keyName, regFileName, bWarnings, bReport);
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir //*********************************************************************
520*cdf0e10cSrcweir //	reg_createRegistry
521*cdf0e10cSrcweir //
522*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_createRegistry(rtl_uString* registryName,
523*cdf0e10cSrcweir 											  RegHandle* phRegistry)
524*cdf0e10cSrcweir {
525*cdf0e10cSrcweir 	RegError ret;
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 	ORegistry* pReg = new ORegistry();
528*cdf0e10cSrcweir 	if ((ret = pReg->initRegistry(registryName, REG_CREATE)))
529*cdf0e10cSrcweir 	{
530*cdf0e10cSrcweir 		*phRegistry = NULL;
531*cdf0e10cSrcweir 		return ret;
532*cdf0e10cSrcweir 	}
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 	*phRegistry = pReg;
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir 	return REG_NO_ERROR;
537*cdf0e10cSrcweir }
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir //*********************************************************************
540*cdf0e10cSrcweir //	reg_openRootKey
541*cdf0e10cSrcweir //
542*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
543*cdf0e10cSrcweir 										  RegKeyHandle* phRootKey)
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir 	return openRootKey(hRegistry, phRootKey);
546*cdf0e10cSrcweir }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir //*********************************************************************
550*cdf0e10cSrcweir //	reg_getName
551*cdf0e10cSrcweir //
552*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_getName(RegHandle hRegistry, rtl_uString** pName)
553*cdf0e10cSrcweir {
554*cdf0e10cSrcweir 	return getName(hRegistry, pName);
555*cdf0e10cSrcweir }
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir //*********************************************************************
559*cdf0e10cSrcweir //	reg_isReadOnly
560*cdf0e10cSrcweir //
561*cdf0e10cSrcweir sal_Bool REGISTRY_CALLTYPE reg_isReadOnly(RegHandle hRegistry)
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir 	return isReadOnly(hRegistry);
564*cdf0e10cSrcweir }
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir //*********************************************************************
568*cdf0e10cSrcweir //	reg_openRegistry
569*cdf0e10cSrcweir //
570*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
571*cdf0e10cSrcweir 											RegHandle* phRegistry,
572*cdf0e10cSrcweir 											RegAccessMode accessMode)
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir 	RegError _ret;
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir 	ORegistry* pReg = new ORegistry();
577*cdf0e10cSrcweir 	if ((_ret = pReg->initRegistry(registryName, accessMode)))
578*cdf0e10cSrcweir 	{
579*cdf0e10cSrcweir 		*phRegistry = NULL;
580*cdf0e10cSrcweir 		return _ret;
581*cdf0e10cSrcweir 	}
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir 	*phRegistry = pReg;
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir 	return REG_NO_ERROR;
586*cdf0e10cSrcweir }
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir //*********************************************************************
589*cdf0e10cSrcweir //	reg_closeRegistry
590*cdf0e10cSrcweir //
591*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
592*cdf0e10cSrcweir {
593*cdf0e10cSrcweir 	ORegistry* pReg;
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 	if (hRegistry)
596*cdf0e10cSrcweir 	{
597*cdf0e10cSrcweir 		pReg = (ORegistry*)hRegistry;
598*cdf0e10cSrcweir 		delete(pReg);
599*cdf0e10cSrcweir 		return REG_NO_ERROR;
600*cdf0e10cSrcweir 	} else
601*cdf0e10cSrcweir 	{
602*cdf0e10cSrcweir 		return REG_REGISTRY_NOT_OPEN;
603*cdf0e10cSrcweir 	}
604*cdf0e10cSrcweir }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir //*********************************************************************
608*cdf0e10cSrcweir //	reg_destroyRegistry
609*cdf0e10cSrcweir //
610*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_destroyRegistry(RegHandle hRegistry,
611*cdf0e10cSrcweir 											   rtl_uString* registryName)
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir 	return destroyRegistry(hRegistry, registryName);
614*cdf0e10cSrcweir }
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir //*********************************************************************
618*cdf0e10cSrcweir //	reg_dumpRegistry
619*cdf0e10cSrcweir //
620*cdf0e10cSrcweir RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey)
621*cdf0e10cSrcweir {
622*cdf0e10cSrcweir 	ORegKey *pKey;
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 	if (hKey)
625*cdf0e10cSrcweir 		pKey = (ORegKey*)hKey;
626*cdf0e10cSrcweir 	else
627*cdf0e10cSrcweir 		return REG_INVALID_KEY;
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir 	return dumpRegistry(pKey->getRegistry(), hKey);
630*cdf0e10cSrcweir }
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 
633