1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 //*********************************************************************
46 ORegKey::ORegKey(const OUString
& keyName
, ORegistry
* pReg
)
49 , m_bDeleted(sal_False
)
53 //*********************************************************************
56 RegError
ORegKey::createKey(const OUString
& keyName
, RegKeyHandle
* phNewKey
)
58 return m_pRegistry
->createKey(this, keyName
, phNewKey
);
62 //*********************************************************************
65 RegError
ORegKey::openKey(const OUString
& keyName
, RegKeyHandle
* phOpenKey
)
67 return (m_pRegistry
->openKey(this, keyName
, phOpenKey
));
71 //*********************************************************************
74 RegError
ORegKey::openSubKeys(const OUString
& keyName
, RegKeyHandle
** phOpenSubKeys
, sal_uInt32
* pnSubKeys
)
77 OUString sFullKeyName
, sSubKeyName
;
78 RegKeyHandle hSKey
= 0, hSubKey
;
79 RegError _ret
= REG_NO_ERROR
;
83 if ( keyName
.getLength() )
85 _ret
= openKey(keyName
, &hSKey
);
88 *phOpenSubKeys
= NULL
;
93 pKey
= (ORegKey
*)hSKey
;
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
);
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
);
122 *phOpenSubKeys
= NULL
;
124 rtl_freeMemory(subKeys
);
128 subKeys
[nSubKeys
] = ((ORegKey
*)hSubKey
);
133 _err
= rStoreDir
.next(iter
);
136 *phOpenSubKeys
= (RegKeyHandle
*)subKeys
;
137 if (keyName
.getLength())
145 //*********************************************************************
148 RegError
ORegKey::getKeyNames(const OUString
& keyName
,
149 rtl_uString
*** pSubKeyNames
,
150 sal_uInt32
* pnSubKeys
)
153 OUString sFullKeyName
, sSubKeyName
;
154 RegError _ret
= REG_NO_ERROR
;
156 rtl_uString
** pSubKeys
;
158 if (keyName
.getLength())
160 _ret
= openKey(keyName
, (RegKeyHandle
*)&pKey
);
163 *pSubKeyNames
= NULL
;
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
);
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
);
200 _err
= rStoreDir
.next(iter
);
203 *pSubKeyNames
= pSubKeys
;
204 if (keyName
.getLength())
206 closeKey((RegKeyHandle
)pKey
);
212 //*********************************************************************
215 RegError
ORegKey::closeKey(RegKeyHandle hKey
)
217 return (m_pRegistry
->closeKey(hKey
));
221 //*********************************************************************
224 RegError
ORegKey::deleteKey(const OUString
& keyName
)
226 return (m_pRegistry
->deleteKey(this, keyName
));
230 //*********************************************************************
233 RegError
ORegKey::getValueInfo(const OUString
& valueName
, RegValueType
* pValueType
, sal_uInt32
* pValueSize
) const
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
;
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
;
271 sal_uInt8 type
= *((sal_uInt8
*)pBuffer
);
272 readUINT32(pBuffer
+VALUE_TYPEOFFSET
, size
);
274 *pValueType
= (RegValueType
)type
;
275 // if (*pValueType == RG_VALUETYPE_UNICODE)
277 // *pValueSize = (size / 2) * sizeof(sal_Unicode);
282 rtl_freeMemory(pBuffer
);
283 pBuffer
= (sal_uInt8
*)rtl_allocateMemory(4);
284 rValue
.readAt(VALUE_HEADEROFFSET
, pBuffer
, 4, readBytes
);
286 readUINT32(pBuffer
, size
);
292 rtl_freeMemory(pBuffer
);
297 //*********************************************************************
300 RegError
ORegKey::setValue(const OUString
& valueName
, RegValueType vType
, RegValue value
, sal_uInt32 vSize
)
305 if (m_pRegistry
->isReadOnly())
307 return REG_REGISTRY_READONLY
;
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
);
335 case RG_VALUETYPE_NOT_DEFINED
:
336 rtl_copyMemory(pBuffer
+VALUE_HEADEROFFSET
, value
, size
);
338 case RG_VALUETYPE_LONG
:
339 writeINT32(pBuffer
+VALUE_HEADEROFFSET
, *((sal_Int32
*)value
));
341 case RG_VALUETYPE_STRING
:
342 writeUtf8(pBuffer
+VALUE_HEADEROFFSET
, (const sal_Char
*)value
);
344 case RG_VALUETYPE_UNICODE
:
345 writeString(pBuffer
+VALUE_HEADEROFFSET
, (const sal_Unicode
*)value
);
347 case RG_VALUETYPE_BINARY
:
348 rtl_copyMemory(pBuffer
+VALUE_HEADEROFFSET
, value
, size
);
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
);
372 //*********************************************************************
375 RegError
ORegKey::setLongListValue(const OUString
& valueName
, sal_Int32
* pValueList
, sal_uInt32 len
)
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
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
]);
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
);
430 //*********************************************************************
431 // setStringListValue
433 RegError
ORegKey::setStringListValue(const OUString
& valueName
, sal_Char
** pValueList
, sal_uInt32 len
)
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
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;
471 for (i
=0; i
< len
; i
++)
473 sLen
= strlen(pValueList
[i
]) + 1;
474 writeUINT32(pBuffer
+VALUE_HEADEROFFSET
+offset
, sLen
);
477 writeUtf8(pBuffer
+VALUE_HEADEROFFSET
+offset
, pValueList
[i
]);
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
);
497 //*********************************************************************
498 // setUnicodeListValue
500 RegError
ORegKey::setUnicodeListValue(const OUString
& valueName
, sal_Unicode
** pValueList
, sal_uInt32 len
)
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
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;
538 for (i
=0; i
< len
; i
++)
540 sLen
= (rtl_ustr_getLength(pValueList
[i
]) + 1) * 2;
541 writeUINT32(pBuffer
+VALUE_HEADEROFFSET
+offset
, sLen
);
544 writeString(pBuffer
+VALUE_HEADEROFFSET
+offset
, pValueList
[i
]);
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
);
564 //*********************************************************************
567 RegError
ORegKey::getValue(const OUString
& valueName
, RegValue value
) const
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
);
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);
631 case RG_VALUETYPE_NOT_DEFINED
:
632 rtl_copyMemory(value
, pBuffer
, valueSize
);
634 case RG_VALUETYPE_LONG
:
635 readINT32(pBuffer
, *((sal_Int32
*)value
));
637 case RG_VALUETYPE_STRING
:
638 readUtf8(pBuffer
, (sal_Char
*)value
, valueSize
);
640 case RG_VALUETYPE_UNICODE
:
641 readString(pBuffer
, (sal_Unicode
*)value
, valueSize
);
643 case RG_VALUETYPE_BINARY
:
644 rtl_copyMemory(value
, pBuffer
, valueSize
);
646 case RG_VALUETYPE_LONGLIST
:
647 case RG_VALUETYPE_STRINGLIST
:
648 case RG_VALUETYPE_UNICODELIST
:
649 rtl_copyMemory(value
, pBuffer
, valueSize
);
654 rtl_freeMemory(pBuffer
);
658 //*********************************************************************
661 RegError
ORegKey::getLongListValue(const OUString
& valueName
, sal_Int32
** pValueList
, sal_uInt32
* pLen
) const
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
) )
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
) )
693 rtl_freeMemory(pBuffer
);
694 return REG_INVALID_VALUE
;
696 if (readBytes
!= VALUE_HEADERSIZE
)
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
)
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
) )
725 rtl_freeMemory(pBuffer
);
726 return REG_INVALID_VALUE
;
728 if (readBytes
!= valueSize
)
732 rtl_freeMemory(pBuffer
);
733 return REG_INVALID_VALUE
;
737 readUINT32(pBuffer
, 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
]);
750 *pValueList
= pVList
;
751 rtl_freeMemory(pBuffer
);
755 //*********************************************************************
756 // getStringListValue
758 RegError
ORegKey::getStringListValue(const OUString
& valueName
, sal_Char
*** pValueList
, sal_uInt32
* pLen
) const
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
) )
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
) )
790 rtl_freeMemory(pBuffer
);
791 return REG_INVALID_VALUE
;
793 if (readBytes
!= VALUE_HEADERSIZE
)
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
)
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
) )
822 rtl_freeMemory(pBuffer
);
823 return REG_INVALID_VALUE
;
825 if (readBytes
!= valueSize
)
829 rtl_freeMemory(pBuffer
);
830 return REG_INVALID_VALUE
;
834 readUINT32(pBuffer
, 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;
843 for (sal_uInt32 i
=0; i
< len
; i
++)
845 readUINT32(pBuffer
+offset
, sLen
);
849 pValue
= (sal_Char
*)rtl_allocateMemory(sLen
);
850 readUtf8(pBuffer
+offset
, pValue
, sLen
);
856 *pValueList
= pVList
;
857 rtl_freeMemory(pBuffer
);
861 //*********************************************************************
862 // getUnicodeListValue
864 RegError
ORegKey::getUnicodeListValue(const OUString
& valueName
, sal_Unicode
*** pValueList
, sal_uInt32
* pLen
) const
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
) )
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
) )
896 rtl_freeMemory(pBuffer
);
897 return REG_INVALID_VALUE
;
899 if (readBytes
!= VALUE_HEADERSIZE
)
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
)
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
) )
928 rtl_freeMemory(pBuffer
);
929 return REG_INVALID_VALUE
;
931 if (readBytes
!= valueSize
)
935 rtl_freeMemory(pBuffer
);
936 return REG_INVALID_VALUE
;
940 readUINT32(pBuffer
, 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;
949 for (sal_uInt32 i
=0; i
< len
; i
++)
951 readUINT32(pBuffer
+offset
, sLen
);
955 pValue
= (sal_Unicode
*)rtl_allocateMemory((sLen
/ 2) * sizeof(sal_Unicode
));
956 readString(pBuffer
+offset
, pValue
, sLen
);
962 *pValueList
= pVList
;
963 rtl_freeMemory(pBuffer
);
967 //*********************************************************************
970 RegError
ORegKey::getKeyType(const OUString
& name
, RegKeyType
* pKeyType
) const
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
);
985 ((ORegKey
*)this)->closeKey((RegKeyHandle
)pKey
);
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 //*********************************************************************
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
)
1022 _err
= rStoreDir
.next(iter
);
1028 OStoreDirectory
ORegKey::getStoreDir()
1030 OStoreDirectory rStoreDir
;
1032 OUString relativName
;
1033 storeAccessMode accessMode
= KEY_MODE_OPEN
;
1035 if ( m_name
.equals(m_pRegistry
->ROOT
) )
1037 fullPath
= OUString();
1038 relativName
= OUString();
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
);
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);
1065 if (path
[0] != '/') {
1066 b
.append(sal_Unicode('/'));
1070 return b
.makeStringAndClear();