merge the formfield patch from ooo-build
[ooovba.git] / registry / source / keyimpl.cxx
blobca0dc3d4010d16d013a4482c25969b9c27235486
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: keyimpl.cxx,v $
10 * $Revision: 1.9.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_registry.hxx"
34 #include "reflcnst.hxx"
36 #include "keyimpl.hxx"
37 #include <rtl/alloc.h>
38 #include <rtl/memory.h>
39 #include "rtl/ustrbuf.hxx"
41 namespace { static char const VALUE_PREFIX[] = "$VL_"; }
43 //*********************************************************************
44 // ORegKey()
46 ORegKey::ORegKey(const OUString& keyName, ORegistry* pReg)
47 : m_refCount(1)
48 , m_name(keyName)
49 , m_bDeleted(sal_False)
50 , m_pRegistry(pReg)
53 //*********************************************************************
54 // createKey
56 RegError ORegKey::createKey(const OUString& keyName, RegKeyHandle* phNewKey)
58 return m_pRegistry->createKey(this, keyName, phNewKey);
62 //*********************************************************************
63 // openKey
65 RegError ORegKey::openKey(const OUString& keyName, RegKeyHandle* phOpenKey)
67 return (m_pRegistry->openKey(this, keyName, phOpenKey));
71 //*********************************************************************
72 // openSubKeys
74 RegError ORegKey::openSubKeys(const OUString& keyName, RegKeyHandle** phOpenSubKeys, sal_uInt32* pnSubKeys)
76 ORegKey* pKey;
77 OUString sFullKeyName, sSubKeyName;
78 RegKeyHandle hSKey = 0, hSubKey;
79 RegError _ret = REG_NO_ERROR;
80 sal_uInt32 nSubKeys;
81 ORegKey* *subKeys;
83 if ( keyName.getLength() )
85 _ret = openKey(keyName, &hSKey);
86 if (_ret)
88 *phOpenSubKeys = NULL;
89 *pnSubKeys = 0;
90 return _ret;
93 pKey = (ORegKey*)hSKey;
94 } else
96 pKey = this;
99 nSubKeys = pKey->countSubKeys();
101 *pnSubKeys = nSubKeys;
102 subKeys = (ORegKey**)rtl_allocateZeroMemory(nSubKeys * sizeof(ORegKey*));
104 OStoreDirectory::iterator iter;
105 OStoreDirectory rStoreDir(pKey->getStoreDir());
106 storeError _err = rStoreDir.first(iter);
108 nSubKeys = 0;
109 while ( _err == store_E_None )
111 if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR )
113 sSubKeyName = iter.m_pszName;
114 sFullKeyName = pKey->getName();
115 if (sFullKeyName.getLength() > 1)
116 sFullKeyName += m_pRegistry->ROOT;
117 sFullKeyName += sSubKeyName;
119 _ret = pKey->openKey(sSubKeyName, &hSubKey);
120 if (_ret)
122 *phOpenSubKeys = NULL;
123 *pnSubKeys = 0;
124 rtl_freeMemory(subKeys);
125 return _ret;
128 subKeys[nSubKeys] = ((ORegKey*)hSubKey);
130 nSubKeys++;
133 _err = rStoreDir.next(iter);
136 *phOpenSubKeys = (RegKeyHandle*)subKeys;
137 if (keyName.getLength())
139 closeKey(hSKey);
141 return REG_NO_ERROR;
145 //*********************************************************************
146 // getKeyNames
148 RegError ORegKey::getKeyNames(const OUString& keyName,
149 rtl_uString*** pSubKeyNames,
150 sal_uInt32* pnSubKeys)
152 ORegKey* pKey;
153 OUString sFullKeyName, sSubKeyName;
154 RegError _ret = REG_NO_ERROR;
155 sal_uInt32 nSubKeys;
156 rtl_uString** pSubKeys;
158 if (keyName.getLength())
160 _ret = openKey(keyName, (RegKeyHandle*)&pKey);
161 if (_ret)
163 *pSubKeyNames = NULL;
164 *pnSubKeys = 0;
165 return _ret;
167 } else
169 pKey = this;
172 nSubKeys = pKey->countSubKeys();
174 *pnSubKeys = nSubKeys;
175 pSubKeys = (rtl_uString**)rtl_allocateZeroMemory(nSubKeys * sizeof(rtl_uString*));
177 OStoreDirectory::iterator iter;
178 OStoreDirectory rStoreDir(pKey->getStoreDir());
179 storeError _err = rStoreDir.first(iter);
180 OUString subKey;
182 nSubKeys = 0;
184 while ( _err == store_E_None )
186 if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR)
188 sSubKeyName = iter.m_pszName;
189 sFullKeyName = pKey->getName();
190 if (sFullKeyName.getLength() > 1)
191 sFullKeyName += m_pRegistry->ROOT;
192 sFullKeyName += sSubKeyName;
194 subKey = sFullKeyName;
195 rtl_uString_newFromString(&pSubKeys[nSubKeys], subKey.pData);
197 nSubKeys++;
200 _err = rStoreDir.next(iter);
203 *pSubKeyNames = pSubKeys;
204 if (keyName.getLength())
206 closeKey((RegKeyHandle)pKey);
208 return REG_NO_ERROR;
212 //*********************************************************************
213 // closeKey
215 RegError ORegKey::closeKey(RegKeyHandle hKey)
217 return (m_pRegistry->closeKey(hKey));
221 //*********************************************************************
222 // deleteKey
224 RegError ORegKey::deleteKey(const OUString& keyName)
226 return (m_pRegistry->deleteKey(this, keyName));
230 //*********************************************************************
231 // getValueType
233 RegError ORegKey::getValueInfo(const OUString& valueName, RegValueType* pValueType, sal_uInt32* pValueSize) const
235 OStoreStream rValue;
236 sal_uInt8* pBuffer;
237 storeAccessMode accessMode = VALUE_MODE_OPEN;
239 if (m_pRegistry->isReadOnly())
241 accessMode = VALUE_MODE_OPENREAD;
244 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
245 sImplValueName += valueName;
247 REG_GUARD(m_pRegistry->m_mutex);
249 if ( rValue.create(m_pRegistry->getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
251 *pValueType = RG_VALUETYPE_NOT_DEFINED;
252 *pValueSize = 0;
253 return REG_VALUE_NOT_EXISTS;
256 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
258 sal_uInt32 readBytes;
259 if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
261 rtl_freeMemory(pBuffer);
262 return REG_INVALID_VALUE;
264 if (readBytes != VALUE_HEADERSIZE)
266 rtl_freeMemory(pBuffer);
267 return REG_INVALID_VALUE;
270 sal_uInt32 size;
271 sal_uInt8 type = *((sal_uInt8*)pBuffer);
272 readUINT32(pBuffer+VALUE_TYPEOFFSET, size);
274 *pValueType = (RegValueType)type;
275 // if (*pValueType == RG_VALUETYPE_UNICODE)
276 // {
277 // *pValueSize = (size / 2) * sizeof(sal_Unicode);
278 // } else
279 // {
280 if (*pValueType > 4)
282 rtl_freeMemory(pBuffer);
283 pBuffer = (sal_uInt8*)rtl_allocateMemory(4);
284 rValue.readAt(VALUE_HEADEROFFSET, pBuffer, 4, readBytes);
286 readUINT32(pBuffer, size);
289 *pValueSize = size;
290 // }
292 rtl_freeMemory(pBuffer);
293 return REG_NO_ERROR;
297 //*********************************************************************
298 // setValue
300 RegError ORegKey::setValue(const OUString& valueName, RegValueType vType, RegValue value, sal_uInt32 vSize)
302 OStoreStream rValue;
303 sal_uInt8* pBuffer;
305 if (m_pRegistry->isReadOnly())
307 return REG_REGISTRY_READONLY;
310 if (vType > 4)
312 return REG_INVALID_VALUE;
315 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
316 sImplValueName += valueName;
318 REG_GUARD(m_pRegistry->m_mutex);
320 if ( rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT , sImplValueName, VALUE_MODE_CREATE) )
322 return REG_SET_VALUE_FAILED;
325 sal_uInt32 size = vSize;
327 sal_uInt8 type = (sal_uInt8)vType;
328 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size);
329 rtl_copyMemory(pBuffer, &type, 1);
331 writeUINT32(pBuffer+VALUE_TYPEOFFSET, size);
333 switch (vType)
335 case RG_VALUETYPE_NOT_DEFINED:
336 rtl_copyMemory(pBuffer+VALUE_HEADEROFFSET, value, size);
337 break;
338 case RG_VALUETYPE_LONG:
339 writeINT32(pBuffer+VALUE_HEADEROFFSET, *((sal_Int32*)value));
340 break;
341 case RG_VALUETYPE_STRING:
342 writeUtf8(pBuffer+VALUE_HEADEROFFSET, (const sal_Char*)value);
343 break;
344 case RG_VALUETYPE_UNICODE:
345 writeString(pBuffer+VALUE_HEADEROFFSET, (const sal_Unicode*)value);
346 break;
347 case RG_VALUETYPE_BINARY:
348 rtl_copyMemory(pBuffer+VALUE_HEADEROFFSET, value, size);
349 break;
350 default:
351 OSL_ASSERT(false);
352 break;
356 sal_uInt32 writenBytes;
357 if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) )
359 rtl_freeMemory(pBuffer);
360 return REG_SET_VALUE_FAILED;
362 if (writenBytes != (VALUE_HEADERSIZE+size))
364 rtl_freeMemory(pBuffer);
365 return REG_SET_VALUE_FAILED;
368 rtl_freeMemory(pBuffer);
369 return REG_NO_ERROR;
372 //*********************************************************************
373 // setLongListValue
375 RegError ORegKey::setLongListValue(const OUString& valueName, sal_Int32* pValueList, sal_uInt32 len)
377 OStoreStream rValue;
378 sal_uInt8* pBuffer;
380 if (m_pRegistry->isReadOnly())
382 return REG_REGISTRY_READONLY;
385 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
386 sImplValueName += valueName;
388 REG_GUARD(m_pRegistry->m_mutex);
390 if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) )
392 return REG_SET_VALUE_FAILED;
395 sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge
397 size += len * 4;
399 sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_LONGLIST;
400 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size);
401 rtl_copyMemory(pBuffer, &type, 1);
403 writeUINT32(pBuffer+VALUE_TYPEOFFSET, size);
404 writeUINT32(pBuffer+VALUE_HEADEROFFSET, len);
406 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays
408 for (sal_uInt32 i=0; i < len; i++)
410 writeINT32(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]);
411 offset += 4;
414 sal_uInt32 writenBytes;
415 if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) )
417 rtl_freeMemory(pBuffer);
418 return REG_SET_VALUE_FAILED;
420 if (writenBytes != (VALUE_HEADEROFFSET+size))
422 rtl_freeMemory(pBuffer);
423 return REG_SET_VALUE_FAILED;
426 rtl_freeMemory(pBuffer);
427 return REG_NO_ERROR;
430 //*********************************************************************
431 // setStringListValue
433 RegError ORegKey::setStringListValue(const OUString& valueName, sal_Char** pValueList, sal_uInt32 len)
435 OStoreStream rValue;
436 sal_uInt8* pBuffer;
438 if (m_pRegistry->isReadOnly())
440 return REG_REGISTRY_READONLY;
443 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
444 sImplValueName += valueName;
446 REG_GUARD(m_pRegistry->m_mutex);
448 if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) )
450 return REG_SET_VALUE_FAILED;
453 sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge
455 sal_uInt32 i;
456 for (i=0; i < len; i++)
458 size += 4 + strlen(pValueList[i]) + 1;
461 sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_STRINGLIST;
462 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size);
463 rtl_copyMemory(pBuffer, &type, 1);
465 writeUINT32(pBuffer+VALUE_TYPEOFFSET, size);
466 writeUINT32(pBuffer+VALUE_HEADEROFFSET, len);
468 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
469 sal_uInt32 sLen = 0;
471 for (i=0; i < len; i++)
473 sLen = strlen(pValueList[i]) + 1;
474 writeUINT32(pBuffer+VALUE_HEADEROFFSET+offset, sLen);
476 offset += 4;
477 writeUtf8(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]);
478 offset += sLen;
481 sal_uInt32 writenBytes;
482 if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) )
484 rtl_freeMemory(pBuffer);
485 return REG_SET_VALUE_FAILED;
487 if (writenBytes != (VALUE_HEADERSIZE+size))
489 rtl_freeMemory(pBuffer);
490 return REG_SET_VALUE_FAILED;
493 rtl_freeMemory(pBuffer);
494 return REG_NO_ERROR;
497 //*********************************************************************
498 // setUnicodeListValue
500 RegError ORegKey::setUnicodeListValue(const OUString& valueName, sal_Unicode** pValueList, sal_uInt32 len)
502 OStoreStream rValue;
503 sal_uInt8* pBuffer;
505 if (m_pRegistry->isReadOnly())
507 return REG_REGISTRY_READONLY;
510 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
511 sImplValueName += valueName;
513 REG_GUARD(m_pRegistry->m_mutex);
515 if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) )
517 return REG_SET_VALUE_FAILED;
520 sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge
522 sal_uInt32 i;
523 for (i=0; i < len; i++)
525 size += 4 + ((rtl_ustr_getLength(pValueList[i]) +1) * 2);
528 sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_UNICODELIST;
529 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size);
530 rtl_copyMemory(pBuffer, &type, 1);
532 writeUINT32(pBuffer+VALUE_TYPEOFFSET, size);
533 writeUINT32(pBuffer+VALUE_HEADEROFFSET, len);
535 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
536 sal_uInt32 sLen = 0;
538 for (i=0; i < len; i++)
540 sLen = (rtl_ustr_getLength(pValueList[i]) + 1) * 2;
541 writeUINT32(pBuffer+VALUE_HEADEROFFSET+offset, sLen);
543 offset += 4;
544 writeString(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]);
545 offset += sLen;
548 sal_uInt32 writenBytes;
549 if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) )
551 rtl_freeMemory(pBuffer);
552 return REG_SET_VALUE_FAILED;
554 if (writenBytes != (VALUE_HEADERSIZE+size))
556 rtl_freeMemory(pBuffer);
557 return REG_SET_VALUE_FAILED;
560 rtl_freeMemory(pBuffer);
561 return REG_NO_ERROR;
564 //*********************************************************************
565 // getValue
567 RegError ORegKey::getValue(const OUString& valueName, RegValue value) const
569 OStoreStream rValue;
570 sal_uInt8* pBuffer;
571 RegValueType valueType;
572 sal_uInt32 valueSize;
573 storeAccessMode accessMode = VALUE_MODE_OPEN;
575 if (m_pRegistry->isReadOnly())
577 accessMode = VALUE_MODE_OPENREAD;
580 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
581 sImplValueName += valueName;
583 REG_GUARD(m_pRegistry->m_mutex);
585 if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
587 return REG_VALUE_NOT_EXISTS;
590 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
592 sal_uInt32 readBytes;
593 if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
595 rtl_freeMemory(pBuffer);
596 return REG_INVALID_VALUE;
598 if (readBytes != VALUE_HEADERSIZE)
600 rtl_freeMemory(pBuffer);
601 return REG_INVALID_VALUE;
604 sal_uInt8 type = *((sal_uInt8*)pBuffer);
605 valueType = (RegValueType)type;
606 readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
608 rtl_freeMemory(pBuffer);
610 if (valueType > 4)
612 return REG_INVALID_VALUE;
615 pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
617 if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) )
619 rtl_freeMemory(pBuffer);
620 return REG_INVALID_VALUE;
622 if (readBytes != valueSize)
624 rtl_freeMemory(pBuffer);
625 return REG_INVALID_VALUE;
628 // rtl_copyMemory(value, pBuffer, valueSize);
629 switch (valueType)
631 case RG_VALUETYPE_NOT_DEFINED:
632 rtl_copyMemory(value, pBuffer, valueSize);
633 break;
634 case RG_VALUETYPE_LONG:
635 readINT32(pBuffer, *((sal_Int32*)value));
636 break;
637 case RG_VALUETYPE_STRING:
638 readUtf8(pBuffer, (sal_Char*)value, valueSize);
639 break;
640 case RG_VALUETYPE_UNICODE:
641 readString(pBuffer, (sal_Unicode*)value, valueSize);
642 break;
643 case RG_VALUETYPE_BINARY:
644 rtl_copyMemory(value, pBuffer, valueSize);
645 break;
646 case RG_VALUETYPE_LONGLIST:
647 case RG_VALUETYPE_STRINGLIST:
648 case RG_VALUETYPE_UNICODELIST:
649 rtl_copyMemory(value, pBuffer, valueSize);
650 break;
654 rtl_freeMemory(pBuffer);
655 return REG_NO_ERROR;
658 //*********************************************************************
659 // getLongListValue
661 RegError ORegKey::getLongListValue(const OUString& valueName, sal_Int32** pValueList, sal_uInt32* pLen) const
663 OStoreStream rValue;
664 sal_uInt8* pBuffer;
665 RegValueType valueType;
666 sal_uInt32 valueSize;
667 storeAccessMode accessMode = VALUE_MODE_OPEN;
669 if (m_pRegistry->isReadOnly())
671 accessMode = VALUE_MODE_OPENREAD;
674 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
675 sImplValueName += valueName;
677 REG_GUARD(m_pRegistry->m_mutex);
679 if (rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
681 pValueList = NULL;
682 *pLen = 0;
683 return REG_VALUE_NOT_EXISTS;
686 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
688 sal_uInt32 readBytes;
689 if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
691 pValueList = NULL;
692 *pLen = 0;
693 rtl_freeMemory(pBuffer);
694 return REG_INVALID_VALUE;
696 if (readBytes != VALUE_HEADERSIZE)
698 pValueList = NULL;
699 *pLen = 0;
700 rtl_freeMemory(pBuffer);
701 return REG_INVALID_VALUE;
704 sal_uInt8 type = *((sal_uInt8*)pBuffer);
705 valueType = (RegValueType)type;
707 if (valueType != RG_VALUETYPE_LONGLIST)
709 pValueList = NULL;
710 *pLen = 0;
711 rtl_freeMemory(pBuffer);
712 return REG_INVALID_VALUE;
715 readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
717 rtl_freeMemory(pBuffer);
719 pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
721 if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) )
723 pValueList = NULL;
724 *pLen = 0;
725 rtl_freeMemory(pBuffer);
726 return REG_INVALID_VALUE;
728 if (readBytes != valueSize)
730 pValueList = NULL;
731 *pLen = 0;
732 rtl_freeMemory(pBuffer);
733 return REG_INVALID_VALUE;
736 sal_uInt32 len = 0;
737 readUINT32(pBuffer, len);
739 *pLen = len;
740 sal_Int32* pVList = (sal_Int32*)rtl_allocateZeroMemory(len * sizeof(sal_Int32));
742 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
744 for (sal_uInt32 i=0; i < len; i++)
746 readINT32(pBuffer+offset, pVList[i]);
747 offset += 4;
750 *pValueList = pVList;
751 rtl_freeMemory(pBuffer);
752 return REG_NO_ERROR;
755 //*********************************************************************
756 // getStringListValue
758 RegError ORegKey::getStringListValue(const OUString& valueName, sal_Char*** pValueList, sal_uInt32* pLen) const
760 OStoreStream rValue;
761 sal_uInt8* pBuffer;
762 RegValueType valueType;
763 sal_uInt32 valueSize;
764 storeAccessMode accessMode = VALUE_MODE_OPEN;
766 if (m_pRegistry->isReadOnly())
768 accessMode = VALUE_MODE_OPENREAD;
771 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
772 sImplValueName += valueName;
774 REG_GUARD(m_pRegistry->m_mutex);
776 if ( rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
778 pValueList = NULL;
779 *pLen = 0;
780 return REG_VALUE_NOT_EXISTS;
783 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
785 sal_uInt32 readBytes;
786 if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
788 pValueList = NULL;
789 *pLen = 0;
790 rtl_freeMemory(pBuffer);
791 return REG_INVALID_VALUE;
793 if (readBytes != VALUE_HEADERSIZE)
795 pValueList = NULL;
796 *pLen = 0;
797 rtl_freeMemory(pBuffer);
798 return REG_INVALID_VALUE;
801 sal_uInt8 type = *((sal_uInt8*)pBuffer);
802 valueType = (RegValueType)type;
804 if (valueType != RG_VALUETYPE_STRINGLIST)
806 pValueList = NULL;
807 *pLen = 0;
808 rtl_freeMemory(pBuffer);
809 return REG_INVALID_VALUE;
812 readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
814 rtl_freeMemory(pBuffer);
816 pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
818 if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) )
820 pValueList = NULL;
821 *pLen = 0;
822 rtl_freeMemory(pBuffer);
823 return REG_INVALID_VALUE;
825 if (readBytes != valueSize)
827 pValueList = NULL;
828 *pLen = 0;
829 rtl_freeMemory(pBuffer);
830 return REG_INVALID_VALUE;
833 sal_uInt32 len = 0;
834 readUINT32(pBuffer, len);
836 *pLen = len;
837 sal_Char** pVList = (sal_Char**)rtl_allocateZeroMemory(len * sizeof(sal_Char*));
839 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
840 sal_uInt32 sLen = 0;
842 sal_Char *pValue;
843 for (sal_uInt32 i=0; i < len; i++)
845 readUINT32(pBuffer+offset, sLen);
847 offset += 4;
849 pValue = (sal_Char*)rtl_allocateMemory(sLen);
850 readUtf8(pBuffer+offset, pValue, sLen);
851 pVList[i] = pValue;
853 offset += sLen;
856 *pValueList = pVList;
857 rtl_freeMemory(pBuffer);
858 return REG_NO_ERROR;
861 //*********************************************************************
862 // getUnicodeListValue
864 RegError ORegKey::getUnicodeListValue(const OUString& valueName, sal_Unicode*** pValueList, sal_uInt32* pLen) const
866 OStoreStream rValue;
867 sal_uInt8* pBuffer;
868 RegValueType valueType;
869 sal_uInt32 valueSize;
870 storeAccessMode accessMode = VALUE_MODE_OPEN;
872 if (m_pRegistry->isReadOnly())
874 accessMode = VALUE_MODE_OPENREAD;
877 OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) );
878 sImplValueName += valueName;
880 REG_GUARD(m_pRegistry->m_mutex);
882 if ( rValue.create(getStoreFile(), m_name + m_pRegistry->ROOT, sImplValueName, accessMode) )
884 pValueList = NULL;
885 *pLen = 0;
886 return REG_VALUE_NOT_EXISTS;
889 pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
891 sal_uInt32 readBytes;
892 if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) )
894 pValueList = NULL;
895 *pLen = 0;
896 rtl_freeMemory(pBuffer);
897 return REG_INVALID_VALUE;
899 if (readBytes != VALUE_HEADERSIZE)
901 pValueList = NULL;
902 *pLen = 0;
903 rtl_freeMemory(pBuffer);
904 return REG_INVALID_VALUE;
907 sal_uInt8 type = *((sal_uInt8*)pBuffer);
908 valueType = (RegValueType)type;
910 if (valueType != RG_VALUETYPE_UNICODELIST)
912 pValueList = NULL;
913 *pLen = 0;
914 rtl_freeMemory(pBuffer);
915 return REG_INVALID_VALUE;
918 readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
920 rtl_freeMemory(pBuffer);
922 pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
924 if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) )
926 pValueList = NULL;
927 *pLen = 0;
928 rtl_freeMemory(pBuffer);
929 return REG_INVALID_VALUE;
931 if (readBytes != valueSize)
933 pValueList = NULL;
934 *pLen = 0;
935 rtl_freeMemory(pBuffer);
936 return REG_INVALID_VALUE;
939 sal_uInt32 len = 0;
940 readUINT32(pBuffer, len);
942 *pLen = len;
943 sal_Unicode** pVList = (sal_Unicode**)rtl_allocateZeroMemory(len * sizeof(sal_Unicode*));
945 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays;
946 sal_uInt32 sLen = 0;
948 sal_Unicode *pValue;
949 for (sal_uInt32 i=0; i < len; i++)
951 readUINT32(pBuffer+offset, sLen);
953 offset += 4;
955 pValue = (sal_Unicode*)rtl_allocateMemory((sLen / 2) * sizeof(sal_Unicode));
956 readString(pBuffer+offset, pValue, sLen);
957 pVList[i] = pValue;
959 offset += sLen;
962 *pValueList = pVList;
963 rtl_freeMemory(pBuffer);
964 return REG_NO_ERROR;
967 //*********************************************************************
968 // getKeyType()
970 RegError ORegKey::getKeyType(const OUString& name, RegKeyType* pKeyType) const
972 ORegKey* pKey;
973 RegError _ret = REG_NO_ERROR;
975 *pKeyType = RG_KEYTYPE;
977 REG_GUARD(m_pRegistry->m_mutex);
979 if ( name.getLength() )
981 _ret = ((ORegKey*)this)->openKey(
982 name, (RegKeyHandle*)&pKey);
983 if (_ret)
984 return _ret;
985 ((ORegKey*)this)->closeKey((RegKeyHandle)pKey);
986 return _ret;
987 } else
989 return _ret;
993 RegError ORegKey::getResolvedKeyName(const OUString& keyName,
994 OUString& resolvedName)
996 if (keyName.getLength() == 0) {
997 return REG_INVALID_KEYNAME;
999 resolvedName = getFullPath(keyName);
1000 return REG_NO_ERROR;
1003 //*********************************************************************
1004 // countSubKeys()
1006 sal_uInt32 ORegKey::countSubKeys()
1008 REG_GUARD(m_pRegistry->m_mutex);
1010 OStoreDirectory::iterator iter;
1011 OStoreDirectory rStoreDir = getStoreDir();
1012 storeError _err = rStoreDir.first(iter);
1013 sal_uInt32 count = 0;
1015 while ( _err == store_E_None )
1017 if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR )
1019 count++;
1022 _err = rStoreDir.next(iter);
1025 return count;
1028 OStoreDirectory ORegKey::getStoreDir()
1030 OStoreDirectory rStoreDir;
1031 OUString fullPath;
1032 OUString relativName;
1033 storeAccessMode accessMode = KEY_MODE_OPEN;
1035 if ( m_name.equals(m_pRegistry->ROOT) )
1037 fullPath = OUString();
1038 relativName = OUString();
1039 } else
1041 fullPath = m_name.copy(0, m_name.lastIndexOf('/') + 1);
1042 relativName = m_name.copy(m_name.lastIndexOf('/') + 1);
1045 if (m_pRegistry->isReadOnly())
1047 accessMode = KEY_MODE_OPENREAD;
1050 rStoreDir.create(getStoreFile(), fullPath, relativName, accessMode);
1052 return rStoreDir;
1055 OUString ORegKey::getFullPath(OUString const & path) const {
1056 OSL_ASSERT(m_name.getLength() != 0 && path.getLength() != 0);
1057 OUStringBuffer b(m_name);
1058 if (b.charAt(b.getLength() - 1) == '/') {
1059 if (path[0] == '/') {
1060 b.append(path.getStr() + 1, path.getLength() - 1);
1061 } else {
1062 b.append(path);
1064 } else {
1065 if (path[0] != '/') {
1066 b.append(sal_Unicode('/'));
1068 b.append(path);
1070 return b.makeStringAndClear();