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