xref: /aoo41x/main/registry/source/keyimpl.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 "keyimpl.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "reflcnst.hxx"
34*cdf0e10cSrcweir #include "rtl/alloc.h"
35*cdf0e10cSrcweir #include "rtl/memory.h"
36*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using rtl::OUString;
39*cdf0e10cSrcweir using rtl::OUStringBuffer;
40*cdf0e10cSrcweir using namespace store;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace { static char const VALUE_PREFIX[] = "$VL_"; }
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir //*********************************************************************
45*cdf0e10cSrcweir //  ORegKey()
46*cdf0e10cSrcweir //
47*cdf0e10cSrcweir ORegKey::ORegKey(const OUString& keyName, ORegistry* pReg)
48*cdf0e10cSrcweir 	: m_refCount(1)
49*cdf0e10cSrcweir 	, m_name(keyName)
50*cdf0e10cSrcweir 	, m_bDeleted(0)
51*cdf0e10cSrcweir 	, m_bModified(0)
52*cdf0e10cSrcweir     , m_pRegistry(pReg)
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir //*********************************************************************
57*cdf0e10cSrcweir //  ~ORegKey()
58*cdf0e10cSrcweir //
59*cdf0e10cSrcweir ORegKey::~ORegKey()
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir 	OSL_POSTCOND(m_refCount == 0, "registry::ORegKey::dtor(): refcount not zero.");
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir //*********************************************************************
65*cdf0e10cSrcweir //  acquireKey
66*cdf0e10cSrcweir //
67*cdf0e10cSrcweir RegError ORegKey::acquireKey(RegKeyHandle hKey)
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir     return m_pRegistry->acquireKey(hKey);
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir //*********************************************************************
73*cdf0e10cSrcweir //  releaseKey
74*cdf0e10cSrcweir //
75*cdf0e10cSrcweir RegError ORegKey::releaseKey(RegKeyHandle hKey)
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     return m_pRegistry->releaseKey(hKey);
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir //*********************************************************************
81*cdf0e10cSrcweir //  createKey
82*cdf0e10cSrcweir //
83*cdf0e10cSrcweir RegError ORegKey::createKey(const OUString& keyName, RegKeyHandle* phNewKey)
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     return m_pRegistry->createKey(this, keyName, phNewKey);
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir //*********************************************************************
90*cdf0e10cSrcweir //  openKey
91*cdf0e10cSrcweir //
92*cdf0e10cSrcweir RegError ORegKey::openKey(const OUString& keyName, RegKeyHandle* phOpenKey)
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     return m_pRegistry->openKey(this, keyName, phOpenKey);
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir //*********************************************************************
99*cdf0e10cSrcweir //  openSubKeys
100*cdf0e10cSrcweir //
101*cdf0e10cSrcweir RegError ORegKey::openSubKeys(const OUString& keyName, RegKeyHandle** phOpenSubKeys, sal_uInt32* pnSubKeys)
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir     RegError _ret = REG_NO_ERROR;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	*phOpenSubKeys = 0;
106*cdf0e10cSrcweir 	*pnSubKeys = 0;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     ORegKey* pKey = this;
109*cdf0e10cSrcweir     if ( keyName.getLength() )
110*cdf0e10cSrcweir     {
111*cdf0e10cSrcweir         _ret = openKey(keyName, (RegKeyHandle*)&pKey);
112*cdf0e10cSrcweir         if (_ret != REG_NO_ERROR)
113*cdf0e10cSrcweir             return _ret;
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     sal_uInt32 nSubKeys = pKey->countSubKeys();
117*cdf0e10cSrcweir     *pnSubKeys = nSubKeys;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     ORegKey** pSubKeys;
120*cdf0e10cSrcweir     pSubKeys = (ORegKey**)rtl_allocateZeroMemory(nSubKeys * sizeof(ORegKey*));
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
123*cdf0e10cSrcweir     OStoreDirectory             rStoreDir(pKey->getStoreDir());
124*cdf0e10cSrcweir     storeError                  _err = rStoreDir.first(iter);
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     nSubKeys = 0;
127*cdf0e10cSrcweir     while ( _err == store_E_None )
128*cdf0e10cSrcweir     {
129*cdf0e10cSrcweir         if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR )
130*cdf0e10cSrcweir         {
131*cdf0e10cSrcweir 			OUString const sSubKeyName = iter.m_pszName;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 			ORegKey* pOpenSubKey = 0;
134*cdf0e10cSrcweir             _ret = pKey->openKey(sSubKeyName, (RegKeyHandle*)&pOpenSubKey);
135*cdf0e10cSrcweir             if (_ret != REG_NO_ERROR)
136*cdf0e10cSrcweir             {
137*cdf0e10cSrcweir                 *phOpenSubKeys = NULL;
138*cdf0e10cSrcweir                 *pnSubKeys = 0;
139*cdf0e10cSrcweir 				rtl_freeMemory(pSubKeys); // @@@ leaking 'pSubKeys[0...nSubkeys-1]'
140*cdf0e10cSrcweir                 return _ret;              // @@@ leaking 'pKey'
141*cdf0e10cSrcweir             }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir             pSubKeys[nSubKeys] = pOpenSubKey;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir             nSubKeys++;
146*cdf0e10cSrcweir         }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         _err = rStoreDir.next(iter);
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     *phOpenSubKeys = (RegKeyHandle*)pSubKeys;
152*cdf0e10cSrcweir     if (keyName.getLength())
153*cdf0e10cSrcweir     {
154*cdf0e10cSrcweir 		(void) releaseKey(pKey);
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir     return REG_NO_ERROR;
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir //*********************************************************************
161*cdf0e10cSrcweir //  getKeyNames
162*cdf0e10cSrcweir //
163*cdf0e10cSrcweir RegError ORegKey::getKeyNames(const OUString& keyName,
164*cdf0e10cSrcweir                               rtl_uString*** pSubKeyNames,
165*cdf0e10cSrcweir                               sal_uInt32* pnSubKeys)
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     RegError _ret = REG_NO_ERROR;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	*pSubKeyNames = 0;
170*cdf0e10cSrcweir 	*pnSubKeys = 0;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     ORegKey* pKey = this;
173*cdf0e10cSrcweir     if (keyName.getLength())
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         _ret = openKey(keyName, (RegKeyHandle*)&pKey);
176*cdf0e10cSrcweir         if (_ret != REG_NO_ERROR)
177*cdf0e10cSrcweir             return _ret;
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     sal_uInt32 nSubKeys = pKey->countSubKeys();
181*cdf0e10cSrcweir     *pnSubKeys = nSubKeys;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     rtl_uString** pSubKeys = 0;
184*cdf0e10cSrcweir     pSubKeys = (rtl_uString**)rtl_allocateZeroMemory(nSubKeys * sizeof(rtl_uString*));
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
187*cdf0e10cSrcweir     OStoreDirectory             rStoreDir(pKey->getStoreDir());
188*cdf0e10cSrcweir     storeError                  _err = rStoreDir.first(iter);
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     nSubKeys = 0;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     while ( _err == store_E_None )
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR)
195*cdf0e10cSrcweir         {
196*cdf0e10cSrcweir 			OUString const sSubKeyName = iter.m_pszName;
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 			OUString sFullKeyName(pKey->getName());
199*cdf0e10cSrcweir             if (sFullKeyName.getLength() > 1)
200*cdf0e10cSrcweir                 sFullKeyName += m_pRegistry->ROOT;
201*cdf0e10cSrcweir             sFullKeyName += sSubKeyName;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 			rtl_uString_newFromString(&pSubKeys[nSubKeys], sFullKeyName.pData);
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir             nSubKeys++;
206*cdf0e10cSrcweir         }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir         _err = rStoreDir.next(iter);
209*cdf0e10cSrcweir     }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     *pSubKeyNames = pSubKeys;
212*cdf0e10cSrcweir     if (keyName.getLength())
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir 		releaseKey(pKey);
215*cdf0e10cSrcweir     }
216*cdf0e10cSrcweir     return REG_NO_ERROR;
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir //*********************************************************************
221*cdf0e10cSrcweir //  closeKey
222*cdf0e10cSrcweir //
223*cdf0e10cSrcweir RegError ORegKey::closeKey(RegKeyHandle hKey)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     return (m_pRegistry->closeKey(hKey));
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir //*********************************************************************
230*cdf0e10cSrcweir //  deleteKey
231*cdf0e10cSrcweir //
232*cdf0e10cSrcweir RegError ORegKey::deleteKey(const OUString& keyName)
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     return (m_pRegistry->deleteKey(this, keyName));
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir //*********************************************************************
239*cdf0e10cSrcweir //  getValueType
240*cdf0e10cSrcweir //
241*cdf0e10cSrcweir RegError ORegKey::getValueInfo(const OUString& valueName, RegValueType* pValueType, sal_uInt32* pValueSize) const
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     OStoreStream    rValue;
244*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
245*cdf0e10cSrcweir     storeAccessMode accessMode = VALUE_MODE_OPEN;
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         accessMode = VALUE_MODE_OPENREAD;
250*cdf0e10cSrcweir     }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
253*cdf0e10cSrcweir     sImplValueName += valueName;
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir     if ( rValue.create(m_pRegistry->getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir         *pValueType = RG_VALUETYPE_NOT_DEFINED;
260*cdf0e10cSrcweir         *pValueSize = 0;
261*cdf0e10cSrcweir         return REG_VALUE_NOT_EXISTS;
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir     sal_uInt32  readBytes;
267*cdf0e10cSrcweir     if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
268*cdf0e10cSrcweir     {
269*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
270*cdf0e10cSrcweir         return REG_INVALID_VALUE;
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir     if (readBytes != VALUE_HEADERSIZE)
273*cdf0e10cSrcweir     {
274*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
275*cdf0e10cSrcweir         return REG_INVALID_VALUE;
276*cdf0e10cSrcweir     }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     sal_uInt32  size;
279*cdf0e10cSrcweir     sal_uInt8   type = *((sal_uInt8*)pBuffer);
280*cdf0e10cSrcweir     readUINT32(pBuffer+VALUE_TYPEOFFSET, size);
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     *pValueType = (RegValueType)type;
283*cdf0e10cSrcweir //    if (*pValueType == RG_VALUETYPE_UNICODE)
284*cdf0e10cSrcweir //    {
285*cdf0e10cSrcweir //        *pValueSize = (size / 2) * sizeof(sal_Unicode);
286*cdf0e10cSrcweir //    } else
287*cdf0e10cSrcweir //    {
288*cdf0e10cSrcweir         if (*pValueType > 4)
289*cdf0e10cSrcweir         {
290*cdf0e10cSrcweir             rtl_freeMemory(pBuffer);
291*cdf0e10cSrcweir             pBuffer = (sal_uInt8*)rtl_allocateMemory(4);
292*cdf0e10cSrcweir             rValue.readAt(VALUE_HEADEROFFSET, pBuffer, 4, readBytes);
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir             readUINT32(pBuffer, size);
295*cdf0e10cSrcweir         }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir         *pValueSize = size;
298*cdf0e10cSrcweir //    }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
301*cdf0e10cSrcweir     return REG_NO_ERROR;
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir //*********************************************************************
306*cdf0e10cSrcweir //  setValue
307*cdf0e10cSrcweir //
308*cdf0e10cSrcweir RegError ORegKey::setValue(const OUString& valueName, RegValueType vType, RegValue value, sal_uInt32 vSize)
309*cdf0e10cSrcweir {
310*cdf0e10cSrcweir     OStoreStream    rValue;
311*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         return REG_REGISTRY_READONLY;
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     if (vType > 4)
319*cdf0e10cSrcweir     {
320*cdf0e10cSrcweir         return REG_INVALID_VALUE;
321*cdf0e10cSrcweir     }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
324*cdf0e10cSrcweir     sImplValueName += valueName;
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     if ( rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT , sImplValueName, VALUE_MODE_CREATE) )
329*cdf0e10cSrcweir     {
330*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
331*cdf0e10cSrcweir     }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir     sal_uInt32 size = vSize;
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir     sal_uInt8 type = (sal_uInt8)vType;
336*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size);
337*cdf0e10cSrcweir     rtl_copyMemory(pBuffer, &type, 1);
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir     writeUINT32(pBuffer+VALUE_TYPEOFFSET, size);
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir     switch (vType)
342*cdf0e10cSrcweir     {
343*cdf0e10cSrcweir         case RG_VALUETYPE_NOT_DEFINED:
344*cdf0e10cSrcweir             rtl_copyMemory(pBuffer+VALUE_HEADEROFFSET, value, size);
345*cdf0e10cSrcweir             break;
346*cdf0e10cSrcweir         case RG_VALUETYPE_LONG:
347*cdf0e10cSrcweir             writeINT32(pBuffer+VALUE_HEADEROFFSET, *((sal_Int32*)value));
348*cdf0e10cSrcweir             break;
349*cdf0e10cSrcweir         case RG_VALUETYPE_STRING:
350*cdf0e10cSrcweir             writeUtf8(pBuffer+VALUE_HEADEROFFSET, (const sal_Char*)value);
351*cdf0e10cSrcweir             break;
352*cdf0e10cSrcweir         case RG_VALUETYPE_UNICODE:
353*cdf0e10cSrcweir             writeString(pBuffer+VALUE_HEADEROFFSET, (const sal_Unicode*)value);
354*cdf0e10cSrcweir             break;
355*cdf0e10cSrcweir         case RG_VALUETYPE_BINARY:
356*cdf0e10cSrcweir             rtl_copyMemory(pBuffer+VALUE_HEADEROFFSET, value, size);
357*cdf0e10cSrcweir             break;
358*cdf0e10cSrcweir         default:
359*cdf0e10cSrcweir             OSL_ASSERT(false);
360*cdf0e10cSrcweir             break;
361*cdf0e10cSrcweir     }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir     sal_uInt32  writenBytes;
364*cdf0e10cSrcweir     if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) )
365*cdf0e10cSrcweir     {
366*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
367*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir     if (writenBytes != (VALUE_HEADERSIZE+size))
370*cdf0e10cSrcweir     {
371*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
372*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
373*cdf0e10cSrcweir     }
374*cdf0e10cSrcweir 	setModified();
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
377*cdf0e10cSrcweir     return REG_NO_ERROR;
378*cdf0e10cSrcweir }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir //*********************************************************************
381*cdf0e10cSrcweir //  setLongListValue
382*cdf0e10cSrcweir //
383*cdf0e10cSrcweir RegError ORegKey::setLongListValue(const OUString& valueName, sal_Int32* pValueList, sal_uInt32 len)
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir     OStoreStream    rValue;
386*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
389*cdf0e10cSrcweir     {
390*cdf0e10cSrcweir         return REG_REGISTRY_READONLY;
391*cdf0e10cSrcweir     }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
394*cdf0e10cSrcweir     sImplValueName += valueName;
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) )
399*cdf0e10cSrcweir     {
400*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
401*cdf0e10cSrcweir     }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir     size += len * 4;
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir     sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_LONGLIST;
408*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size);
409*cdf0e10cSrcweir     rtl_copyMemory(pBuffer, &type, 1);
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir     writeUINT32(pBuffer+VALUE_TYPEOFFSET, size);
412*cdf0e10cSrcweir     writeUINT32(pBuffer+VALUE_HEADEROFFSET, len);
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir     sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     for (sal_uInt32 i=0; i < len; i++)
417*cdf0e10cSrcweir     {
418*cdf0e10cSrcweir         writeINT32(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]);
419*cdf0e10cSrcweir         offset += 4;
420*cdf0e10cSrcweir     }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir     sal_uInt32  writenBytes;
423*cdf0e10cSrcweir     if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) )
424*cdf0e10cSrcweir     {
425*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
426*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
427*cdf0e10cSrcweir     }
428*cdf0e10cSrcweir     if (writenBytes != (VALUE_HEADEROFFSET+size))
429*cdf0e10cSrcweir     {
430*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
431*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
432*cdf0e10cSrcweir     }
433*cdf0e10cSrcweir 	setModified();
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
436*cdf0e10cSrcweir     return REG_NO_ERROR;
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir //*********************************************************************
440*cdf0e10cSrcweir //  setStringListValue
441*cdf0e10cSrcweir //
442*cdf0e10cSrcweir RegError ORegKey::setStringListValue(const OUString& valueName, sal_Char** pValueList, sal_uInt32 len)
443*cdf0e10cSrcweir {
444*cdf0e10cSrcweir     OStoreStream    rValue;
445*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
448*cdf0e10cSrcweir     {
449*cdf0e10cSrcweir         return REG_REGISTRY_READONLY;
450*cdf0e10cSrcweir     }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
453*cdf0e10cSrcweir     sImplValueName += valueName;
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir     if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) )
458*cdf0e10cSrcweir     {
459*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
460*cdf0e10cSrcweir     }
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir     sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir     sal_uInt32 i;
465*cdf0e10cSrcweir     for (i=0; i < len; i++)
466*cdf0e10cSrcweir     {
467*cdf0e10cSrcweir         size +=  4 + strlen(pValueList[i]) + 1;
468*cdf0e10cSrcweir     }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir     sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_STRINGLIST;
471*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size);
472*cdf0e10cSrcweir     rtl_copyMemory(pBuffer, &type, 1);
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir     writeUINT32(pBuffer+VALUE_TYPEOFFSET, size);
475*cdf0e10cSrcweir     writeUINT32(pBuffer+VALUE_HEADEROFFSET, len);
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir     sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
478*cdf0e10cSrcweir     sal_uInt32 sLen = 0;
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     for (i=0; i < len; i++)
481*cdf0e10cSrcweir     {
482*cdf0e10cSrcweir         sLen = strlen(pValueList[i]) + 1;
483*cdf0e10cSrcweir         writeUINT32(pBuffer+VALUE_HEADEROFFSET+offset, sLen);
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir         offset += 4;
486*cdf0e10cSrcweir         writeUtf8(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]);
487*cdf0e10cSrcweir         offset += sLen;
488*cdf0e10cSrcweir     }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir     sal_uInt32  writenBytes;
491*cdf0e10cSrcweir     if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) )
492*cdf0e10cSrcweir     {
493*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
494*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
495*cdf0e10cSrcweir     }
496*cdf0e10cSrcweir     if (writenBytes != (VALUE_HEADERSIZE+size))
497*cdf0e10cSrcweir     {
498*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
499*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
500*cdf0e10cSrcweir     }
501*cdf0e10cSrcweir 	setModified();
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
504*cdf0e10cSrcweir     return REG_NO_ERROR;
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir //*********************************************************************
508*cdf0e10cSrcweir //  setUnicodeListValue
509*cdf0e10cSrcweir //
510*cdf0e10cSrcweir RegError ORegKey::setUnicodeListValue(const OUString& valueName, sal_Unicode** pValueList, sal_uInt32 len)
511*cdf0e10cSrcweir {
512*cdf0e10cSrcweir     OStoreStream    rValue;
513*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
516*cdf0e10cSrcweir     {
517*cdf0e10cSrcweir         return REG_REGISTRY_READONLY;
518*cdf0e10cSrcweir     }
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
521*cdf0e10cSrcweir     sImplValueName += valueName;
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir     if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) )
526*cdf0e10cSrcweir     {
527*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
528*cdf0e10cSrcweir     }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir     sal_uInt32 i;
533*cdf0e10cSrcweir     for (i=0; i < len; i++)
534*cdf0e10cSrcweir     {
535*cdf0e10cSrcweir         size +=  4 + ((rtl_ustr_getLength(pValueList[i]) +1) * 2);
536*cdf0e10cSrcweir     }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir     sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_UNICODELIST;
539*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size);
540*cdf0e10cSrcweir     rtl_copyMemory(pBuffer, &type, 1);
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir     writeUINT32(pBuffer+VALUE_TYPEOFFSET, size);
543*cdf0e10cSrcweir     writeUINT32(pBuffer+VALUE_HEADEROFFSET, len);
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir     sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
546*cdf0e10cSrcweir     sal_uInt32 sLen = 0;
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir     for (i=0; i < len; i++)
549*cdf0e10cSrcweir     {
550*cdf0e10cSrcweir         sLen = (rtl_ustr_getLength(pValueList[i]) + 1) * 2;
551*cdf0e10cSrcweir         writeUINT32(pBuffer+VALUE_HEADEROFFSET+offset, sLen);
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir         offset += 4;
554*cdf0e10cSrcweir         writeString(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]);
555*cdf0e10cSrcweir         offset += sLen;
556*cdf0e10cSrcweir     }
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir     sal_uInt32  writenBytes;
559*cdf0e10cSrcweir     if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) )
560*cdf0e10cSrcweir     {
561*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
562*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
563*cdf0e10cSrcweir     }
564*cdf0e10cSrcweir     if (writenBytes != (VALUE_HEADERSIZE+size))
565*cdf0e10cSrcweir     {
566*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
567*cdf0e10cSrcweir         return REG_SET_VALUE_FAILED;
568*cdf0e10cSrcweir     }
569*cdf0e10cSrcweir 	setModified();
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
572*cdf0e10cSrcweir     return REG_NO_ERROR;
573*cdf0e10cSrcweir }
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir //*********************************************************************
576*cdf0e10cSrcweir //  getValue
577*cdf0e10cSrcweir //
578*cdf0e10cSrcweir RegError ORegKey::getValue(const OUString& valueName, RegValue value) const
579*cdf0e10cSrcweir {
580*cdf0e10cSrcweir     OStoreStream    rValue;
581*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
582*cdf0e10cSrcweir     RegValueType    valueType;
583*cdf0e10cSrcweir     sal_uInt32      valueSize;
584*cdf0e10cSrcweir     storeAccessMode accessMode = VALUE_MODE_OPEN;
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
587*cdf0e10cSrcweir     {
588*cdf0e10cSrcweir         accessMode = VALUE_MODE_OPENREAD;
589*cdf0e10cSrcweir     }
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
592*cdf0e10cSrcweir     sImplValueName += valueName;
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir     if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
597*cdf0e10cSrcweir     {
598*cdf0e10cSrcweir         return REG_VALUE_NOT_EXISTS;
599*cdf0e10cSrcweir     }
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir     sal_uInt32  readBytes;
604*cdf0e10cSrcweir     if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
605*cdf0e10cSrcweir     {
606*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
607*cdf0e10cSrcweir         return REG_INVALID_VALUE;
608*cdf0e10cSrcweir     }
609*cdf0e10cSrcweir     if (readBytes != VALUE_HEADERSIZE)
610*cdf0e10cSrcweir     {
611*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
612*cdf0e10cSrcweir         return REG_INVALID_VALUE;
613*cdf0e10cSrcweir     }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir     sal_uInt8   type = *((sal_uInt8*)pBuffer);
616*cdf0e10cSrcweir     valueType = (RegValueType)type;
617*cdf0e10cSrcweir     readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir     if (valueType > 4)
622*cdf0e10cSrcweir     {
623*cdf0e10cSrcweir         return REG_INVALID_VALUE;
624*cdf0e10cSrcweir     }
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir     if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) )
629*cdf0e10cSrcweir     {
630*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
631*cdf0e10cSrcweir         return REG_INVALID_VALUE;
632*cdf0e10cSrcweir     }
633*cdf0e10cSrcweir     if (readBytes != valueSize)
634*cdf0e10cSrcweir     {
635*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
636*cdf0e10cSrcweir         return REG_INVALID_VALUE;
637*cdf0e10cSrcweir     }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir     switch (valueType)
640*cdf0e10cSrcweir     {
641*cdf0e10cSrcweir         case RG_VALUETYPE_NOT_DEFINED:
642*cdf0e10cSrcweir             rtl_copyMemory(value, pBuffer, valueSize);
643*cdf0e10cSrcweir             break;
644*cdf0e10cSrcweir         case RG_VALUETYPE_LONG:
645*cdf0e10cSrcweir             readINT32(pBuffer, *((sal_Int32*)value));
646*cdf0e10cSrcweir             break;
647*cdf0e10cSrcweir         case RG_VALUETYPE_STRING:
648*cdf0e10cSrcweir             readUtf8(pBuffer, (sal_Char*)value, valueSize);
649*cdf0e10cSrcweir             break;
650*cdf0e10cSrcweir         case RG_VALUETYPE_UNICODE:
651*cdf0e10cSrcweir             readString(pBuffer, (sal_Unicode*)value, valueSize);
652*cdf0e10cSrcweir             break;
653*cdf0e10cSrcweir         case RG_VALUETYPE_BINARY:
654*cdf0e10cSrcweir             rtl_copyMemory(value, pBuffer, valueSize);
655*cdf0e10cSrcweir             break;
656*cdf0e10cSrcweir         case RG_VALUETYPE_LONGLIST:
657*cdf0e10cSrcweir         case RG_VALUETYPE_STRINGLIST:
658*cdf0e10cSrcweir         case RG_VALUETYPE_UNICODELIST:
659*cdf0e10cSrcweir             rtl_copyMemory(value, pBuffer, valueSize);
660*cdf0e10cSrcweir             break;
661*cdf0e10cSrcweir     }
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
665*cdf0e10cSrcweir     return REG_NO_ERROR;
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir //*********************************************************************
669*cdf0e10cSrcweir //  getLongListValue
670*cdf0e10cSrcweir //
671*cdf0e10cSrcweir RegError ORegKey::getLongListValue(const OUString& valueName, sal_Int32** pValueList, sal_uInt32* pLen) const
672*cdf0e10cSrcweir {
673*cdf0e10cSrcweir     OStoreStream    rValue;
674*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
675*cdf0e10cSrcweir     RegValueType    valueType;
676*cdf0e10cSrcweir     sal_uInt32      valueSize;
677*cdf0e10cSrcweir     storeAccessMode accessMode = VALUE_MODE_OPEN;
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
680*cdf0e10cSrcweir     {
681*cdf0e10cSrcweir         accessMode = VALUE_MODE_OPENREAD;
682*cdf0e10cSrcweir     }
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
685*cdf0e10cSrcweir     sImplValueName += valueName;
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir     if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
690*cdf0e10cSrcweir     {
691*cdf0e10cSrcweir         pValueList = NULL;
692*cdf0e10cSrcweir         *pLen = 0;
693*cdf0e10cSrcweir         return REG_VALUE_NOT_EXISTS;
694*cdf0e10cSrcweir     }
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir     sal_uInt32  readBytes;
699*cdf0e10cSrcweir     if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
700*cdf0e10cSrcweir     {
701*cdf0e10cSrcweir         pValueList = NULL;
702*cdf0e10cSrcweir         *pLen = 0;
703*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
704*cdf0e10cSrcweir         return REG_INVALID_VALUE;
705*cdf0e10cSrcweir     }
706*cdf0e10cSrcweir     if (readBytes != VALUE_HEADERSIZE)
707*cdf0e10cSrcweir     {
708*cdf0e10cSrcweir         pValueList = NULL;
709*cdf0e10cSrcweir         *pLen = 0;
710*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
711*cdf0e10cSrcweir         return REG_INVALID_VALUE;
712*cdf0e10cSrcweir     }
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir     sal_uInt8   type = *((sal_uInt8*)pBuffer);
715*cdf0e10cSrcweir     valueType = (RegValueType)type;
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir     if (valueType != RG_VALUETYPE_LONGLIST)
718*cdf0e10cSrcweir     {
719*cdf0e10cSrcweir         pValueList = NULL;
720*cdf0e10cSrcweir         *pLen = 0;
721*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
722*cdf0e10cSrcweir         return REG_INVALID_VALUE;
723*cdf0e10cSrcweir     }
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir     readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir     if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) )
732*cdf0e10cSrcweir     {
733*cdf0e10cSrcweir         pValueList = NULL;
734*cdf0e10cSrcweir         *pLen = 0;
735*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
736*cdf0e10cSrcweir         return REG_INVALID_VALUE;
737*cdf0e10cSrcweir     }
738*cdf0e10cSrcweir     if (readBytes != valueSize)
739*cdf0e10cSrcweir     {
740*cdf0e10cSrcweir         pValueList = NULL;
741*cdf0e10cSrcweir         *pLen = 0;
742*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
743*cdf0e10cSrcweir         return REG_INVALID_VALUE;
744*cdf0e10cSrcweir     }
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir     sal_uInt32 len = 0;
747*cdf0e10cSrcweir     readUINT32(pBuffer, len);
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir     *pLen = len;
750*cdf0e10cSrcweir     sal_Int32* pVList = (sal_Int32*)rtl_allocateZeroMemory(len * sizeof(sal_Int32));
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir     sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir     for (sal_uInt32 i=0; i < len; i++)
755*cdf0e10cSrcweir     {
756*cdf0e10cSrcweir         readINT32(pBuffer+offset, pVList[i]);
757*cdf0e10cSrcweir         offset += 4;
758*cdf0e10cSrcweir     }
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir     *pValueList = pVList;
761*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
762*cdf0e10cSrcweir     return REG_NO_ERROR;
763*cdf0e10cSrcweir }
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir //*********************************************************************
766*cdf0e10cSrcweir //  getStringListValue
767*cdf0e10cSrcweir //
768*cdf0e10cSrcweir RegError ORegKey::getStringListValue(const OUString& valueName, sal_Char*** pValueList, sal_uInt32* pLen) const
769*cdf0e10cSrcweir {
770*cdf0e10cSrcweir     OStoreStream    rValue;
771*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
772*cdf0e10cSrcweir     RegValueType    valueType;
773*cdf0e10cSrcweir     sal_uInt32      valueSize;
774*cdf0e10cSrcweir     storeAccessMode accessMode = VALUE_MODE_OPEN;
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
777*cdf0e10cSrcweir     {
778*cdf0e10cSrcweir         accessMode = VALUE_MODE_OPENREAD;
779*cdf0e10cSrcweir     }
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
782*cdf0e10cSrcweir     sImplValueName += valueName;
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir     if ( rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
787*cdf0e10cSrcweir     {
788*cdf0e10cSrcweir         pValueList = NULL;
789*cdf0e10cSrcweir         *pLen = 0;
790*cdf0e10cSrcweir         return REG_VALUE_NOT_EXISTS;
791*cdf0e10cSrcweir     }
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir     sal_uInt32  readBytes;
796*cdf0e10cSrcweir     if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
797*cdf0e10cSrcweir     {
798*cdf0e10cSrcweir         pValueList = NULL;
799*cdf0e10cSrcweir         *pLen = 0;
800*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
801*cdf0e10cSrcweir         return REG_INVALID_VALUE;
802*cdf0e10cSrcweir     }
803*cdf0e10cSrcweir     if (readBytes != VALUE_HEADERSIZE)
804*cdf0e10cSrcweir     {
805*cdf0e10cSrcweir         pValueList = NULL;
806*cdf0e10cSrcweir         *pLen = 0;
807*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
808*cdf0e10cSrcweir         return REG_INVALID_VALUE;
809*cdf0e10cSrcweir     }
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir     sal_uInt8   type = *((sal_uInt8*)pBuffer);
812*cdf0e10cSrcweir     valueType = (RegValueType)type;
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir     if (valueType != RG_VALUETYPE_STRINGLIST)
815*cdf0e10cSrcweir     {
816*cdf0e10cSrcweir         pValueList = NULL;
817*cdf0e10cSrcweir         *pLen = 0;
818*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
819*cdf0e10cSrcweir         return REG_INVALID_VALUE;
820*cdf0e10cSrcweir     }
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir     readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir     if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) )
829*cdf0e10cSrcweir     {
830*cdf0e10cSrcweir         pValueList = NULL;
831*cdf0e10cSrcweir         *pLen = 0;
832*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
833*cdf0e10cSrcweir         return REG_INVALID_VALUE;
834*cdf0e10cSrcweir     }
835*cdf0e10cSrcweir     if (readBytes != valueSize)
836*cdf0e10cSrcweir     {
837*cdf0e10cSrcweir         pValueList = NULL;
838*cdf0e10cSrcweir         *pLen = 0;
839*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
840*cdf0e10cSrcweir         return REG_INVALID_VALUE;
841*cdf0e10cSrcweir     }
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir     sal_uInt32 len = 0;
844*cdf0e10cSrcweir     readUINT32(pBuffer, len);
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir     *pLen = len;
847*cdf0e10cSrcweir     sal_Char** pVList = (sal_Char**)rtl_allocateZeroMemory(len * sizeof(sal_Char*));
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir     sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
850*cdf0e10cSrcweir     sal_uInt32 sLen = 0;
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir     sal_Char *pValue;
853*cdf0e10cSrcweir     for (sal_uInt32 i=0; i < len; i++)
854*cdf0e10cSrcweir     {
855*cdf0e10cSrcweir         readUINT32(pBuffer+offset, sLen);
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir         offset += 4;
858*cdf0e10cSrcweir 
859*cdf0e10cSrcweir         pValue = (sal_Char*)rtl_allocateMemory(sLen);
860*cdf0e10cSrcweir         readUtf8(pBuffer+offset, pValue, sLen);
861*cdf0e10cSrcweir         pVList[i] = pValue;
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir         offset += sLen;
864*cdf0e10cSrcweir     }
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir     *pValueList = pVList;
867*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
868*cdf0e10cSrcweir     return REG_NO_ERROR;
869*cdf0e10cSrcweir }
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir //*********************************************************************
872*cdf0e10cSrcweir //  getUnicodeListValue
873*cdf0e10cSrcweir //
874*cdf0e10cSrcweir RegError ORegKey::getUnicodeListValue(const OUString& valueName, sal_Unicode*** pValueList, sal_uInt32* pLen) const
875*cdf0e10cSrcweir {
876*cdf0e10cSrcweir     OStoreStream    rValue;
877*cdf0e10cSrcweir     sal_uInt8*      pBuffer;
878*cdf0e10cSrcweir     RegValueType    valueType;
879*cdf0e10cSrcweir     sal_uInt32      valueSize;
880*cdf0e10cSrcweir     storeAccessMode accessMode = VALUE_MODE_OPEN;
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
883*cdf0e10cSrcweir     {
884*cdf0e10cSrcweir         accessMode = VALUE_MODE_OPENREAD;
885*cdf0e10cSrcweir     }
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir     OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
888*cdf0e10cSrcweir     sImplValueName += valueName;
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir     if ( rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
893*cdf0e10cSrcweir     {
894*cdf0e10cSrcweir         pValueList = NULL;
895*cdf0e10cSrcweir         *pLen = 0;
896*cdf0e10cSrcweir         return REG_VALUE_NOT_EXISTS;
897*cdf0e10cSrcweir     }
898*cdf0e10cSrcweir 
899*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir     sal_uInt32  readBytes;
902*cdf0e10cSrcweir     if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
903*cdf0e10cSrcweir     {
904*cdf0e10cSrcweir         pValueList = NULL;
905*cdf0e10cSrcweir         *pLen = 0;
906*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
907*cdf0e10cSrcweir         return REG_INVALID_VALUE;
908*cdf0e10cSrcweir     }
909*cdf0e10cSrcweir     if (readBytes != VALUE_HEADERSIZE)
910*cdf0e10cSrcweir     {
911*cdf0e10cSrcweir         pValueList = NULL;
912*cdf0e10cSrcweir         *pLen = 0;
913*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
914*cdf0e10cSrcweir         return REG_INVALID_VALUE;
915*cdf0e10cSrcweir     }
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir     sal_uInt8   type = *((sal_uInt8*)pBuffer);
918*cdf0e10cSrcweir     valueType = (RegValueType)type;
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir     if (valueType != RG_VALUETYPE_UNICODELIST)
921*cdf0e10cSrcweir     {
922*cdf0e10cSrcweir         pValueList = NULL;
923*cdf0e10cSrcweir         *pLen = 0;
924*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
925*cdf0e10cSrcweir         return REG_INVALID_VALUE;
926*cdf0e10cSrcweir     }
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir     readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir     if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) )
935*cdf0e10cSrcweir     {
936*cdf0e10cSrcweir         pValueList = NULL;
937*cdf0e10cSrcweir         *pLen = 0;
938*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
939*cdf0e10cSrcweir         return REG_INVALID_VALUE;
940*cdf0e10cSrcweir     }
941*cdf0e10cSrcweir     if (readBytes != valueSize)
942*cdf0e10cSrcweir     {
943*cdf0e10cSrcweir         pValueList = NULL;
944*cdf0e10cSrcweir         *pLen = 0;
945*cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
946*cdf0e10cSrcweir         return REG_INVALID_VALUE;
947*cdf0e10cSrcweir     }
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir     sal_uInt32 len = 0;
950*cdf0e10cSrcweir     readUINT32(pBuffer, len);
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir     *pLen = len;
953*cdf0e10cSrcweir     sal_Unicode** pVList = (sal_Unicode**)rtl_allocateZeroMemory(len * sizeof(sal_Unicode*));
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir     sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
956*cdf0e10cSrcweir     sal_uInt32 sLen = 0;
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir     sal_Unicode *pValue;
959*cdf0e10cSrcweir     for (sal_uInt32 i=0; i < len; i++)
960*cdf0e10cSrcweir     {
961*cdf0e10cSrcweir         readUINT32(pBuffer+offset, sLen);
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir         offset += 4;
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir         pValue = (sal_Unicode*)rtl_allocateMemory((sLen / 2) * sizeof(sal_Unicode));
966*cdf0e10cSrcweir         readString(pBuffer+offset, pValue, sLen);
967*cdf0e10cSrcweir         pVList[i] = pValue;
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir         offset += sLen;
970*cdf0e10cSrcweir     }
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir     *pValueList = pVList;
973*cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
974*cdf0e10cSrcweir     return REG_NO_ERROR;
975*cdf0e10cSrcweir }
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir //*********************************************************************
978*cdf0e10cSrcweir //  getKeyType()
979*cdf0e10cSrcweir //
980*cdf0e10cSrcweir RegError ORegKey::getKeyType(const OUString& name, RegKeyType* pKeyType) const
981*cdf0e10cSrcweir {
982*cdf0e10cSrcweir     *pKeyType = RG_KEYTYPE;
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
985*cdf0e10cSrcweir 
986*cdf0e10cSrcweir     if ( name.getLength() )
987*cdf0e10cSrcweir     {
988*cdf0e10cSrcweir 		ORegKey* pThis = const_cast< ORegKey* >(this);
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir 		RegKeyHandle hKey = 0;
991*cdf0e10cSrcweir         RegError _ret = pThis->openKey(name, &hKey);
992*cdf0e10cSrcweir         if (_ret != REG_NO_ERROR)
993*cdf0e10cSrcweir             return _ret;
994*cdf0e10cSrcweir         (void) pThis->releaseKey(hKey);
995*cdf0e10cSrcweir     }
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir 	return REG_NO_ERROR;
998*cdf0e10cSrcweir }
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir RegError ORegKey::getResolvedKeyName(const OUString& keyName,
1001*cdf0e10cSrcweir                                      OUString& resolvedName)
1002*cdf0e10cSrcweir {
1003*cdf0e10cSrcweir     if (keyName.getLength() == 0)
1004*cdf0e10cSrcweir         return REG_INVALID_KEYNAME;
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir     resolvedName = getFullPath(keyName);
1007*cdf0e10cSrcweir     return REG_NO_ERROR;
1008*cdf0e10cSrcweir }
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir //*********************************************************************
1011*cdf0e10cSrcweir //  countSubKeys()
1012*cdf0e10cSrcweir //
1013*cdf0e10cSrcweir sal_uInt32 ORegKey::countSubKeys()
1014*cdf0e10cSrcweir {
1015*cdf0e10cSrcweir     REG_GUARD(m_pRegistry->m_mutex);
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
1018*cdf0e10cSrcweir     OStoreDirectory             rStoreDir = getStoreDir();
1019*cdf0e10cSrcweir     storeError                  _err = rStoreDir.first(iter);
1020*cdf0e10cSrcweir     sal_uInt32                  count = 0;
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir     while ( _err == store_E_None )
1023*cdf0e10cSrcweir     {
1024*cdf0e10cSrcweir         if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR )
1025*cdf0e10cSrcweir         {
1026*cdf0e10cSrcweir             count++;
1027*cdf0e10cSrcweir         }
1028*cdf0e10cSrcweir 
1029*cdf0e10cSrcweir         _err = rStoreDir.next(iter);
1030*cdf0e10cSrcweir     }
1031*cdf0e10cSrcweir 
1032*cdf0e10cSrcweir     return count;
1033*cdf0e10cSrcweir }
1034*cdf0e10cSrcweir 
1035*cdf0e10cSrcweir OStoreDirectory ORegKey::getStoreDir()
1036*cdf0e10cSrcweir {
1037*cdf0e10cSrcweir     OStoreDirectory rStoreDir;
1038*cdf0e10cSrcweir     OUString        fullPath;
1039*cdf0e10cSrcweir     OUString        relativName;
1040*cdf0e10cSrcweir     storeAccessMode accessMode = KEY_MODE_OPEN;
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir     if ( m_name.equals(m_pRegistry->ROOT) )
1043*cdf0e10cSrcweir     {
1044*cdf0e10cSrcweir         fullPath = OUString();
1045*cdf0e10cSrcweir         relativName = OUString();
1046*cdf0e10cSrcweir     } else
1047*cdf0e10cSrcweir 	{
1048*cdf0e10cSrcweir     	fullPath = m_name.copy(0, m_name.lastIndexOf('/') + 1);
1049*cdf0e10cSrcweir     	relativName = m_name.copy(m_name.lastIndexOf('/') + 1);
1050*cdf0e10cSrcweir 	}
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir     if (m_pRegistry->isReadOnly())
1053*cdf0e10cSrcweir     {
1054*cdf0e10cSrcweir         accessMode = KEY_MODE_OPENREAD;
1055*cdf0e10cSrcweir     }
1056*cdf0e10cSrcweir 
1057*cdf0e10cSrcweir     rStoreDir.create(getStoreFile(), fullPath, relativName, accessMode);
1058*cdf0e10cSrcweir 
1059*cdf0e10cSrcweir     return rStoreDir;
1060*cdf0e10cSrcweir }
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir OUString ORegKey::getFullPath(OUString const & path) const {
1063*cdf0e10cSrcweir     OSL_ASSERT(m_name.getLength() != 0 && path.getLength() != 0);
1064*cdf0e10cSrcweir     OUStringBuffer b(m_name);
1065*cdf0e10cSrcweir     if (b.charAt(b.getLength() - 1) == '/') {
1066*cdf0e10cSrcweir         if (path[0] == '/') {
1067*cdf0e10cSrcweir             b.append(path.getStr() + 1, path.getLength() - 1);
1068*cdf0e10cSrcweir         } else {
1069*cdf0e10cSrcweir             b.append(path);
1070*cdf0e10cSrcweir         }
1071*cdf0e10cSrcweir     } else {
1072*cdf0e10cSrcweir         if (path[0] != '/') {
1073*cdf0e10cSrcweir             b.append(sal_Unicode('/'));
1074*cdf0e10cSrcweir         }
1075*cdf0e10cSrcweir         b.append(path);
1076*cdf0e10cSrcweir     }
1077*cdf0e10cSrcweir     return b.makeStringAndClear();
1078*cdf0e10cSrcweir }
1079