diff options
author | Matthias Huetsch [mhu] <matthias.huetsch@sun.com> | 2010-03-04 15:19:41 +0100 |
---|---|---|
committer | Matthias Huetsch [mhu] <matthias.huetsch@sun.com> | 2010-03-04 15:19:41 +0100 |
commit | 709ee7e9b098fa7074d84d3faab7aa5cd5ebf73b (patch) | |
tree | d58e2e95e278a2c864877950904c7bc27dbe3e41 | |
parent | ffca8743e16d5afd101df88aa50f2c8735830e53 (diff) |
mhu22: #i105430# #i108349# Fixed registry:ORegKey reference counting to avoid redundant closeKey()/flush() calls.
-rw-r--r-- | idlc/source/astdump.cxx | 4 | ||||
-rw-r--r-- | idlc/source/idlcproduce.cxx | 22 | ||||
-rw-r--r-- | registry/inc/registry/registry.hxx | 36 | ||||
-rw-r--r-- | registry/source/keyimpl.cxx | 160 | ||||
-rw-r--r-- | registry/source/keyimpl.hxx | 74 | ||||
-rw-r--r-- | registry/source/regimpl.cxx | 276 | ||||
-rw-r--r-- | registry/source/regimpl.hxx | 62 | ||||
-rw-r--r-- | registry/source/registry.cxx | 201 | ||||
-rw-r--r-- | registry/source/regkey.cxx | 545 | ||||
-rw-r--r-- | registry/tools/checksingleton.cxx | 9 | ||||
-rw-r--r-- | registry/tools/regcompare.cxx | 9 | ||||
-rw-r--r-- | registry/tools/regmerge.cxx | 31 | ||||
-rwxr-xr-x[-rw-r--r--] | store/source/lockbyte.cxx | 0 |
13 files changed, 576 insertions, 853 deletions
diff --git a/idlc/source/astdump.cxx b/idlc/source/astdump.cxx index d9c51b567e2a..217616b60198 100644 --- a/idlc/source/astdump.cxx +++ b/idlc/source/astdump.cxx @@ -137,6 +137,10 @@ sal_Bool AstModule::dump(RegistryKey& rKey) } } } + if ( getNodeType() == NT_root ) + { + localKey.releaseKey(); + } return AstDeclaration::dump(rKey); } diff --git a/idlc/source/idlcproduce.cxx b/idlc/source/idlcproduce.cxx index b0c84239c83d..75007ecc9b91 100644 --- a/idlc/source/idlcproduce.cxx +++ b/idlc/source/idlcproduce.cxx @@ -149,11 +149,11 @@ sal_Int32 SAL_CALL produceFile(const OString& regFileName) return 1; } - Registry regFile; - removeIfExists(regTmpName); OString urlRegTmpName = convertToFileUrl(regTmpName); - if ( regFile.create(OStringToOUString(urlRegTmpName, RTL_TEXTENCODING_UTF8)) ) + + Registry regFile; + if ( regFile.create(OStringToOUString(urlRegTmpName, RTL_TEXTENCODING_UTF8)) != REG_NO_ERROR ) { fprintf(stderr, "%s: could not create registry file '%s'\n", pOptions->getProgramName().getStr(), regTmpName.getStr()); @@ -164,7 +164,7 @@ sal_Int32 SAL_CALL produceFile(const OString& regFileName) } RegistryKey rootKey; - if ( regFile.openRootKey(rootKey) ) + if ( regFile.openRootKey(rootKey) != REG_NO_ERROR ) { fprintf(stderr, "%s: could not open root of registry file '%s'\n", pOptions->getProgramName().getStr(), regFileName.getStr()); @@ -177,7 +177,7 @@ sal_Int32 SAL_CALL produceFile(const OString& regFileName) // produce registry file if ( !idlc()->getRoot()->dump(rootKey) ) { - rootKey.closeKey(); + rootKey.releaseKey(); regFile.close(); regFile.destroy(OStringToOUString(regFileName, RTL_TEXTENCODING_UTF8)); removeIfExists(regFileName); @@ -185,16 +185,8 @@ sal_Int32 SAL_CALL produceFile(const OString& regFileName) return 1; } - if ( rootKey.closeKey() ) - { - fprintf(stderr, "%s: could not close root of registry file '%s'\n", - pOptions->getProgramName().getStr(), regFileName.getStr()); - removeIfExists(regTmpName); - removeIfExists(regFileName); - cleanPath(); - return 1; - } - if ( regFile.close() ) + rootKey.releaseKey(); + if ( regFile.close() != REG_NO_ERROR ) { fprintf(stderr, "%s: could not close registry file '%s'\n", pOptions->getProgramName().getStr(), regFileName.getStr()); diff --git a/registry/inc/registry/registry.hxx b/registry/inc/registry/registry.hxx index e3ee4574023d..fe31978c5ca0 100644 --- a/registry/inc/registry/registry.hxx +++ b/registry/inc/registry/registry.hxx @@ -486,6 +486,9 @@ public: /// closes explicitly the current key inline RegError closeKey(); + /// releases the current key + inline void releaseKey(); + /** sets a value of a key. @param keyName specifies the name of the key which value will be set. @@ -810,19 +813,18 @@ inline void RegistryKey::setRegistry(Registry& registry) inline RegistryKey::~RegistryKey() { if (m_hImpl) - m_registry.m_pApi->closeKey(m_hImpl); + m_registry.m_pApi->releaseKey(m_hImpl); } inline RegistryKey& RegistryKey::operator = (const RegistryKey& toAssign) { m_registry = toAssign.m_registry; - if (m_hImpl != toAssign.m_hImpl) - { + if (toAssign.m_hImpl) + m_registry.m_pApi->acquireKey(toAssign.m_hImpl); + if (m_hImpl) m_registry.m_pApi->releaseKey(m_hImpl); - m_hImpl = toAssign.m_hImpl; - m_registry.m_pApi->acquireKey(m_hImpl); - } + m_hImpl = toAssign.m_hImpl; return *this; } @@ -948,6 +950,14 @@ inline RegError RegistryKey::closeKey() return REG_INVALID_KEY; } +inline void RegistryKey::releaseKey() +{ + if (m_registry.isValid() && (m_hImpl != 0)) + { + m_registry.m_pApi->releaseKey(m_hImpl), m_hImpl = 0; + } +} + inline RegError RegistryKey::setValue(const ::rtl::OUString& keyName, RegValueType valueType, RegValue pValue, @@ -1166,15 +1176,13 @@ inline Registry::~Registry() inline Registry& Registry::operator = (const Registry& toAssign) { - - if (m_hImpl != toAssign.m_hImpl) - { - m_pApi->release(m_hImpl); - m_pApi = toAssign.m_pApi; - m_hImpl = toAssign.m_hImpl; - } + if (toAssign.m_hImpl) + toAssign.m_pApi->acquire(toAssign.m_hImpl); if (m_hImpl) - m_pApi->acquire(m_hImpl); + m_pApi->release(m_hImpl); + + m_pApi = toAssign.m_pApi; + m_hImpl = toAssign.m_hImpl; return *this; } diff --git a/registry/source/keyimpl.cxx b/registry/source/keyimpl.cxx index f8de7e20b148..5300b158769d 100644 --- a/registry/source/keyimpl.cxx +++ b/registry/source/keyimpl.cxx @@ -31,13 +31,17 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_registry.hxx" -#include "reflcnst.hxx" - #include "keyimpl.hxx" -#include <rtl/alloc.h> -#include <rtl/memory.h> + +#include "reflcnst.hxx" +#include "rtl/alloc.h" +#include "rtl/memory.h" #include "rtl/ustrbuf.hxx" +using rtl::OUString; +using rtl::OUStringBuffer; +using namespace store; + namespace { static char const VALUE_PREFIX[] = "$VL_"; } //********************************************************************* @@ -46,9 +50,35 @@ namespace { static char const VALUE_PREFIX[] = "$VL_"; } ORegKey::ORegKey(const OUString& keyName, ORegistry* pReg) : m_refCount(1) , m_name(keyName) - , m_bDeleted(sal_False) + , m_bDeleted(0) + , m_bModified(0) , m_pRegistry(pReg) -{} +{ +} + +//********************************************************************* +// ~ORegKey() +// +ORegKey::~ORegKey() +{ + OSL_POSTCOND(m_refCount == 0, "registry::ORegKey::dtor(): refcount not zero."); +} + +//********************************************************************* +// acquireKey +// +RegError ORegKey::acquireKey(RegKeyHandle hKey) +{ + return m_pRegistry->acquireKey(hKey); +} + +//********************************************************************* +// releaseKey +// +RegError ORegKey::releaseKey(RegKeyHandle hKey) +{ + return m_pRegistry->releaseKey(hKey); +} //********************************************************************* // createKey @@ -64,7 +94,7 @@ RegError ORegKey::createKey(const OUString& keyName, RegKeyHandle* phNewKey) // RegError ORegKey::openKey(const OUString& keyName, RegKeyHandle* phOpenKey) { - return (m_pRegistry->openKey(this, keyName, phOpenKey)); + return m_pRegistry->openKey(this, keyName, phOpenKey); } @@ -73,33 +103,24 @@ RegError ORegKey::openKey(const OUString& keyName, RegKeyHandle* phOpenKey) // RegError ORegKey::openSubKeys(const OUString& keyName, RegKeyHandle** phOpenSubKeys, sal_uInt32* pnSubKeys) { - ORegKey* pKey; - OUString sFullKeyName, sSubKeyName; - RegKeyHandle hSKey = 0, hSubKey; - RegError _ret = REG_NO_ERROR; - sal_uInt32 nSubKeys; - ORegKey* *subKeys; + RegError _ret = REG_NO_ERROR; + + *phOpenSubKeys = 0; + *pnSubKeys = 0; + ORegKey* pKey = this; if ( keyName.getLength() ) { - _ret = openKey(keyName, &hSKey); - if (_ret) - { - *phOpenSubKeys = NULL; - *pnSubKeys = 0; + _ret = openKey(keyName, (RegKeyHandle*)&pKey); + if (_ret != REG_NO_ERROR) return _ret; - } - - pKey = (ORegKey*)hSKey; - } else - { - pKey = this; } - nSubKeys = pKey->countSubKeys(); - + sal_uInt32 nSubKeys = pKey->countSubKeys(); *pnSubKeys = nSubKeys; - subKeys = (ORegKey**)rtl_allocateZeroMemory(nSubKeys * sizeof(ORegKey*)); + + ORegKey** pSubKeys; + pSubKeys = (ORegKey**)rtl_allocateZeroMemory(nSubKeys * sizeof(ORegKey*)); OStoreDirectory::iterator iter; OStoreDirectory rStoreDir(pKey->getStoreDir()); @@ -110,22 +131,19 @@ RegError ORegKey::openSubKeys(const OUString& keyName, RegKeyHandle** phOpenSubK { if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR ) { - sSubKeyName = iter.m_pszName; - sFullKeyName = pKey->getName(); - if (sFullKeyName.getLength() > 1) - sFullKeyName += m_pRegistry->ROOT; - sFullKeyName += sSubKeyName; + OUString const sSubKeyName = iter.m_pszName; - _ret = pKey->openKey(sSubKeyName, &hSubKey); - if (_ret) + ORegKey* pOpenSubKey = 0; + _ret = pKey->openKey(sSubKeyName, (RegKeyHandle*)&pOpenSubKey); + if (_ret != REG_NO_ERROR) { *phOpenSubKeys = NULL; *pnSubKeys = 0; - rtl_freeMemory(subKeys); - return _ret; + rtl_freeMemory(pSubKeys); // @@@ leaking 'pSubKeys[0...nSubkeys-1]' + return _ret; // @@@ leaking 'pKey' } - subKeys[nSubKeys] = ((ORegKey*)hSubKey); + pSubKeys[nSubKeys] = pOpenSubKey; nSubKeys++; } @@ -133,10 +151,10 @@ RegError ORegKey::openSubKeys(const OUString& keyName, RegKeyHandle** phOpenSubK _err = rStoreDir.next(iter); } - *phOpenSubKeys = (RegKeyHandle*)subKeys; + *phOpenSubKeys = (RegKeyHandle*)pSubKeys; if (keyName.getLength()) { - closeKey(hSKey); + (void) releaseKey(pKey); } return REG_NO_ERROR; } @@ -149,35 +167,28 @@ RegError ORegKey::getKeyNames(const OUString& keyName, rtl_uString*** pSubKeyNames, sal_uInt32* pnSubKeys) { - ORegKey* pKey; - OUString sFullKeyName, sSubKeyName; - RegError _ret = REG_NO_ERROR; - sal_uInt32 nSubKeys; - rtl_uString** pSubKeys; + RegError _ret = REG_NO_ERROR; + + *pSubKeyNames = 0; + *pnSubKeys = 0; + ORegKey* pKey = this; if (keyName.getLength()) { _ret = openKey(keyName, (RegKeyHandle*)&pKey); - if (_ret) - { - *pSubKeyNames = NULL; - *pnSubKeys = 0; + if (_ret != REG_NO_ERROR) return _ret; - } - } else - { - pKey = this; } - nSubKeys = pKey->countSubKeys(); - + sal_uInt32 nSubKeys = pKey->countSubKeys(); *pnSubKeys = nSubKeys; + + rtl_uString** pSubKeys = 0; pSubKeys = (rtl_uString**)rtl_allocateZeroMemory(nSubKeys * sizeof(rtl_uString*)); OStoreDirectory::iterator iter; OStoreDirectory rStoreDir(pKey->getStoreDir()); storeError _err = rStoreDir.first(iter); - OUString subKey; nSubKeys = 0; @@ -185,14 +196,14 @@ RegError ORegKey::getKeyNames(const OUString& keyName, { if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR) { - sSubKeyName = iter.m_pszName; - sFullKeyName = pKey->getName(); + OUString const sSubKeyName = iter.m_pszName; + + OUString sFullKeyName(pKey->getName()); if (sFullKeyName.getLength() > 1) sFullKeyName += m_pRegistry->ROOT; sFullKeyName += sSubKeyName; - subKey = sFullKeyName; - rtl_uString_newFromString(&pSubKeys[nSubKeys], subKey.pData); + rtl_uString_newFromString(&pSubKeys[nSubKeys], sFullKeyName.pData); nSubKeys++; } @@ -203,7 +214,7 @@ RegError ORegKey::getKeyNames(const OUString& keyName, *pSubKeyNames = pSubKeys; if (keyName.getLength()) { - closeKey((RegKeyHandle)pKey); + releaseKey(pKey); } return REG_NO_ERROR; } @@ -352,7 +363,6 @@ RegError ORegKey::setValue(const OUString& valueName, RegValueType vType, RegVal break; } - sal_uInt32 writenBytes; if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) ) { @@ -364,6 +374,7 @@ RegError ORegKey::setValue(const OUString& valueName, RegValueType vType, RegVal rtl_freeMemory(pBuffer); return REG_SET_VALUE_FAILED; } + setModified(); rtl_freeMemory(pBuffer); return REG_NO_ERROR; @@ -422,6 +433,7 @@ RegError ORegKey::setLongListValue(const OUString& valueName, sal_Int32* pValueL rtl_freeMemory(pBuffer); return REG_SET_VALUE_FAILED; } + setModified(); rtl_freeMemory(pBuffer); return REG_NO_ERROR; @@ -489,6 +501,7 @@ RegError ORegKey::setStringListValue(const OUString& valueName, sal_Char** pValu rtl_freeMemory(pBuffer); return REG_SET_VALUE_FAILED; } + setModified(); rtl_freeMemory(pBuffer); return REG_NO_ERROR; @@ -556,6 +569,7 @@ RegError ORegKey::setUnicodeListValue(const OUString& valueName, sal_Unicode** p rtl_freeMemory(pBuffer); return REG_SET_VALUE_FAILED; } + setModified(); rtl_freeMemory(pBuffer); return REG_NO_ERROR; @@ -625,7 +639,6 @@ RegError ORegKey::getValue(const OUString& valueName, RegValue value) const return REG_INVALID_VALUE; } -// rtl_copyMemory(value, pBuffer, valueSize); switch (valueType) { case RG_VALUETYPE_NOT_DEFINED: @@ -969,33 +982,30 @@ RegError ORegKey::getUnicodeListValue(const OUString& valueName, sal_Unicode*** // RegError ORegKey::getKeyType(const OUString& name, RegKeyType* pKeyType) const { - ORegKey* pKey; - RegError _ret = REG_NO_ERROR; - *pKeyType = RG_KEYTYPE; REG_GUARD(m_pRegistry->m_mutex); if ( name.getLength() ) { - _ret = ((ORegKey*)this)->openKey( - name, (RegKeyHandle*)&pKey); - if (_ret) + ORegKey* pThis = const_cast< ORegKey* >(this); + + RegKeyHandle hKey = 0; + RegError _ret = pThis->openKey(name, &hKey); + if (_ret != REG_NO_ERROR) return _ret; - ((ORegKey*)this)->closeKey((RegKeyHandle)pKey); - return _ret; - } else - { - return _ret; + (void) pThis->releaseKey(hKey); } + + return REG_NO_ERROR; } RegError ORegKey::getResolvedKeyName(const OUString& keyName, OUString& resolvedName) { - if (keyName.getLength() == 0) { + if (keyName.getLength() == 0) return REG_INVALID_KEYNAME; - } + resolvedName = getFullPath(keyName); return REG_NO_ERROR; } diff --git a/registry/source/keyimpl.hxx b/registry/source/keyimpl.hxx index 4e99696bcd44..ab0de6710e31 100644 --- a/registry/source/keyimpl.hxx +++ b/registry/source/keyimpl.hxx @@ -33,16 +33,14 @@ #include <registry/registry.h> #include "regimpl.hxx" -#include <rtl/string.hxx> - -using namespace rtl; -using namespace store; +#include <rtl/ustring.hxx> class ORegKey { public: - ORegKey(const OUString& keyName, ORegistry* pReg); + ORegKey(const rtl::OUString& keyName, ORegistry* pReg); + ~ORegKey(); sal_uInt32 acquire() { return ++m_refCount; } @@ -50,68 +48,77 @@ public: sal_uInt32 release() { return --m_refCount; } - RegError createKey(const OUString& keyName, RegKeyHandle* phNewKey); + RegError acquireKey(RegKeyHandle hKey); + RegError releaseKey(RegKeyHandle hKey); + + RegError createKey(const rtl::OUString& keyName, RegKeyHandle* phNewKey); - RegError openKey(const OUString& keyName, RegKeyHandle* phOpenKey); + RegError openKey(const rtl::OUString& keyName, RegKeyHandle* phOpenKey); - RegError openSubKeys(const OUString& keyName, + RegError openSubKeys(const rtl::OUString& keyName, RegKeyHandle** phOpenSubKeys, sal_uInt32* pnSubKeys); - RegError getKeyNames(const OUString& keyName, + RegError getKeyNames(const rtl::OUString& keyName, rtl_uString*** pSubKeyNames, sal_uInt32* pnSubKeys); RegError closeKey(RegKeyHandle hKey); - RegError deleteKey(const OUString& keyName); + RegError deleteKey(const rtl::OUString& keyName); - RegError getValueInfo(const OUString& valueName, + RegError getValueInfo(const rtl::OUString& valueName, RegValueType* pValueTye, sal_uInt32* pValueSize) const; - RegError setValue(const OUString& valueName, + RegError setValue(const rtl::OUString& valueName, RegValueType vType, RegValue value, sal_uInt32 vSize); - RegError setLongListValue(const OUString& valueName, + RegError setLongListValue(const rtl::OUString& valueName, sal_Int32* pValueList, sal_uInt32 len); - RegError setStringListValue(const OUString& valueName, + RegError setStringListValue(const rtl::OUString& valueName, sal_Char** pValueList, sal_uInt32 len); - RegError setUnicodeListValue(const OUString& valueName, + RegError setUnicodeListValue(const rtl::OUString& valueName, sal_Unicode** pValueList, sal_uInt32 len); - RegError getValue(const OUString& valueName, RegValue value) const; + RegError getValue(const rtl::OUString& valueName, RegValue value) const; - RegError getLongListValue(const OUString& valueName, + RegError getLongListValue(const rtl::OUString& valueName, sal_Int32** pValueList, sal_uInt32* pLen) const; - RegError getStringListValue(const OUString& valueName, + RegError getStringListValue(const rtl::OUString& valueName, sal_Char*** pValueList, sal_uInt32* pLen) const; - RegError getUnicodeListValue(const OUString& valueName, + RegError getUnicodeListValue(const rtl::OUString& valueName, sal_Unicode*** pValueList, sal_uInt32* pLen) const; - RegError getKeyType(const OUString& name, + RegError getKeyType(const rtl::OUString& name, RegKeyType* pKeyType) const; - RegError getResolvedKeyName(const OUString& keyName, - OUString& resolvedName); + RegError getResolvedKeyName(const rtl::OUString& keyName, + rtl::OUString& resolvedName); + + bool isDeleted() const + { return m_bDeleted != 0; } - sal_Bool isDeleted() const - { return m_bDeleted; } + void setDeleted (sal_Bool bKeyDeleted) + { m_bDeleted = bKeyDeleted ? 1 : 0; } - void setDeleted(sal_Bool bKeyDeleted) - { m_bDeleted = bKeyDeleted; } + bool isModified() const + { return m_bModified != 0; } + + void setModified (bool bModified = true) + { m_bModified = bModified ? 1 : 0; } sal_Bool isReadOnly() const { return m_pRegistry->isReadOnly(); } @@ -121,28 +128,27 @@ public: ORegistry* getRegistry() const { return m_pRegistry; } - const OStoreFile& getStoreFile() const + const store::OStoreFile& getStoreFile() const { return m_pRegistry->getStoreFile(); } - OStoreDirectory getStoreDir(); + store::OStoreDirectory getStoreDir(); - const OUString& getName() const + const rtl::OUString& getName() const { return m_name; } sal_uInt32 getRefCount() const { return m_refCount; } - OUString getFullPath(OUString const & path) const; + rtl::OUString getFullPath(rtl::OUString const & path) const; private: sal_uInt32 m_refCount; - OUString m_name; - sal_Bool m_bDeleted; + rtl::OUString m_name; + int m_bDeleted:1; + int m_bModified:1; ORegistry* m_pRegistry; }; - - #endif diff --git a/registry/source/regimpl.cxx b/registry/source/regimpl.cxx index 7a4e8fc44083..3b0587a5a433 100644 --- a/registry/source/regimpl.cxx +++ b/registry/source/regimpl.cxx @@ -31,6 +31,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_registry.hxx" +#include "regimpl.hxx" + #include <memory> #include <string.h> #include <stdio.h> @@ -42,18 +44,6 @@ #include <unistd.h> #endif -#ifdef MACOSX -// Get the store.hxx inlines non-inline, solves crashes in cppumaker -#define inline -#endif - -#include "regimpl.hxx" - -#ifdef MACOSX -// Get the store.hxx inlines non-inline, solves crashes in cppumaker -#undef inline -#endif - #ifndef __REGISTRY_REFLREAD_HXX__ #include <registry/reflread.hxx> #endif @@ -67,19 +57,19 @@ #include "registry/types.h" #include "registry/version.h" -#ifndef __REFLCNST_HXX__ #include "reflcnst.hxx" -#endif #include "keyimpl.hxx" + #include <osl/thread.h> #include <rtl/alloc.h> #include <rtl/memory.h> #include <rtl/ustring.hxx> #include <rtl/ustrbuf.hxx> -#ifndef _ODL_FILE_HXX_ #include <osl/file.hxx> -#endif +using namespace rtl; +using namespace osl; +using namespace store; #if defined ( GCC ) && ( defined ( SCO ) ) sal_helper::ORealDynamicLoader* sal_helper::ODynamicLoader<RegistryTypeReader_Api>::m_pLoader = NULL; @@ -470,11 +460,9 @@ ORegistry::ORegistry() // ORegistry::~ORegistry() { - if (m_openKeyTable.count(ROOT) > 0) - { - m_openKeyTable[ROOT]->release(); - delete(m_openKeyTable[ROOT]); - } + ORegKey* pRootKey = m_openKeyTable[ROOT]; + if (pRootKey != 0) + (void) releaseKey(pRootKey); if (m_file.isValid()) m_file.close(); @@ -549,7 +537,7 @@ RegError ORegistry::closeRegistry() if (m_file.isValid()) { - closeKey(m_openKeyTable[ROOT]); + (void) releaseKey(m_openKeyTable[ROOT]); m_file.close(); m_isOpen = sal_False; return REG_NO_ERROR; @@ -597,7 +585,7 @@ RegError ORegistry::destroyRegistry(const OUString& regName) if (m_file.isValid()) { - closeKey(m_openKeyTable[ROOT]); + releaseKey(m_openKeyTable[ROOT]); m_file.close(); m_isOpen = sal_False; @@ -623,6 +611,39 @@ RegError ORegistry::destroyRegistry(const OUString& regName) } //********************************************************************* +// acquireKey +// +RegError ORegistry::acquireKey (RegKeyHandle hKey) +{ + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; + + REG_GUARD(m_mutex); + pKey->acquire(); + + return REG_NO_ERROR; +} + +//********************************************************************* +// releaseKey +// +RegError ORegistry::releaseKey (RegKeyHandle hKey) +{ + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; + + REG_GUARD(m_mutex); + if (pKey->release() == 0) + { + m_openKeyTable.erase(pKey->getName()); + delete pKey; + } + return REG_NO_ERROR; +} + +//********************************************************************* // createKey // RegError ORegistry::createKey(RegKeyHandle hKey, const OUString& keyName, @@ -720,6 +741,7 @@ RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName, default: break; } + std::auto_ptr< ORegKey > p(new ORegKey(path, this)); i = m_openKeyTable.insert(std::make_pair(path, p.get())).first; p.release(); @@ -736,56 +758,51 @@ RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName, // RegError ORegistry::closeKey(RegKeyHandle hKey) { - ORegKey* pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); REG_GUARD(m_mutex); - if (m_openKeyTable.count(pKey->getName()) > 0) + OUString const aKeyName (pKey->getName()); + if (!(m_openKeyTable.count(aKeyName) > 0)) + return REG_KEY_NOT_OPEN; + + if (pKey->isModified()) { - if (pKey->getRefCount() == 1) + ORegKey * pRootKey = getRootKey(); + if (pKey != pRootKey) { - m_openKeyTable.erase(pKey->getName()); - delete(pKey); - hKey = NULL; - } else + // propagate "modified" state to RootKey. + pRootKey->setModified(); + } + else { - pKey->release(); + // closing modified RootKey, flush registry file. + OSL_TRACE("registry::ORegistry::closeKey(): flushing modified RootKey"); + (void) m_file.flush(); } - - return REG_NO_ERROR; - } else - { - return REG_KEY_NOT_OPEN; + pKey->setModified(false); + (void) releaseKey(pRootKey); } -} + return releaseKey(pKey); +} //********************************************************************* // deleteKey // RegError ORegistry::deleteKey(RegKeyHandle hKey, const OUString& keyName) { - ORegKey* pKey; - RegError _ret = REG_NO_ERROR; - + ORegKey* pKey = static_cast< ORegKey* >(hKey); if ( !keyName.getLength() ) - { return REG_INVALID_KEYNAME; - } REG_GUARD(m_mutex); - if (hKey) - pKey = (ORegKey*)hKey; - else + if (!pKey) pKey = m_openKeyTable[ROOT]; - OUString sFullKeyName = pKey->getFullPath(keyName); - - pKey = m_openKeyTable[ROOT]; - _ret = eraseKey(pKey, sFullKeyName); - - return _ret; + OUString sFullKeyName(pKey->getFullPath(keyName)); + return eraseKey(m_openKeyTable[ROOT], sFullKeyName); } RegError ORegistry::eraseKey(ORegKey* pKey, const OUString& keyName) @@ -824,17 +841,15 @@ RegError ORegistry::eraseKey(ORegKey* pKey, const OUString& keyName) sFullPath += ROOT; } - RegKeyHandle hOldKey; - _ret = pKey->openKey(keyName, &hOldKey); - if (_ret) - { + ORegKey* pOldKey = 0; + _ret = pKey->openKey(keyName, (RegKeyHandle*)&pOldKey); + if (_ret != REG_NO_ERROR) return _ret; - } - _ret = deleteSubkeysAndValues((ORegKey*)hOldKey); - if (_ret) + _ret = deleteSubkeysAndValues(pOldKey); + if (_ret != REG_NO_ERROR) { - pKey->closeKey(hOldKey); + pKey->closeKey(pOldKey); return _ret; } @@ -842,46 +857,39 @@ RegError ORegistry::eraseKey(ORegKey* pKey, const OUString& keyName) tmpName += ROOT; OStoreFile sFile(pKey->getStoreFile()); - if ( sFile.isValid() && sFile.remove(sFullPath, tmpName) ) { return REG_DELETE_KEY_FAILED; } + pOldKey->setModified(); // set flag deleted !!! - ((ORegKey*)hOldKey)->setDeleted(sal_True); + pOldKey->setDeleted(sal_True); - _ret = pKey->closeKey(hOldKey); - if (_ret) - { - return _ret; - } - - return REG_NO_ERROR; + return pKey->closeKey(pOldKey); } - //********************************************************************* -// deleteSubKeys +// deleteSubKeysAndValues // RegError ORegistry::deleteSubkeysAndValues(ORegKey* pKey) { OStoreDirectory::iterator iter; - OUString keyName; RegError _ret = REG_NO_ERROR; OStoreDirectory rStoreDir(pKey->getStoreDir()); storeError _err = rStoreDir.first(iter); while ( _err == store_E_None ) { - keyName = iter.m_pszName; + OUString const keyName = iter.m_pszName; if (iter.m_nAttrib & STORE_ATTRIB_ISDIR) { _ret = eraseKey(pKey, keyName); if (_ret) return _ret; - } else + } + else { OUString sFullPath(pKey->getName()); @@ -892,6 +900,7 @@ RegError ORegistry::deleteSubkeysAndValues(ORegKey* pKey) { return REG_DELETE_VALUE_FAILED; } + pKey->setModified(); } _err = rStoreDir.next(iter); @@ -907,119 +916,99 @@ RegError ORegistry::deleteSubkeysAndValues(ORegKey* pKey) RegError ORegistry::loadKey(RegKeyHandle hKey, const OUString& regFileName, sal_Bool bWarnings, sal_Bool bReport) { - RegError _ret = REG_NO_ERROR; - ORegistry* pReg; - ORegKey *pKey, *pRootKey; + RegError _ret = REG_NO_ERROR; + ORegKey* pKey = static_cast< ORegKey* >(hKey); - pReg = new ORegistry(); + std::auto_ptr< ORegistry > pReg (new ORegistry()); _ret = pReg->initRegistry(regFileName, REG_READONLY); - if (_ret) - { + if (_ret != REG_NO_ERROR) return _ret; - } - - pKey = (ORegKey*)hKey; - pRootKey = pReg->getRootKey(); + ORegKey* pRootKey = pReg->getRootKey(); REG_GUARD(m_mutex); OStoreDirectory::iterator iter; - OUString keyName; OStoreDirectory rStoreDir(pRootKey->getStoreDir()); storeError _err = rStoreDir.first(iter); while ( _err == store_E_None ) { - keyName = iter.m_pszName; + OUString const keyName = iter.m_pszName; if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR ) { _ret = loadAndSaveKeys(pKey, pRootKey, keyName, 0, bWarnings, bReport); - } else + } + else { _ret = loadAndSaveValue(pKey, pRootKey, keyName, 0, bWarnings, bReport); } - if (_ret == REG_MERGE_ERROR || - (_ret == REG_MERGE_CONFLICT && bWarnings)) - { - rStoreDir = OStoreDirectory(); - pRootKey->release(); - delete(pReg); - return _ret; - } + if (_ret == REG_MERGE_ERROR) + break; + if (_ret == REG_MERGE_CONFLICT && bWarnings) + break; _err = rStoreDir.next(iter); } rStoreDir = OStoreDirectory(); - pRootKey->release(); - delete(pReg); + (void) pReg->releaseKey(pRootKey); return _ret; } //********************************************************************* -// loadKey +// saveKey // RegError ORegistry::saveKey(RegKeyHandle hKey, const OUString& regFileName, sal_Bool bWarnings, sal_Bool bReport) { - RegError _ret = REG_NO_ERROR; - ORegistry* pReg; - ORegKey *pKey, *pRootKey; + RegError _ret = REG_NO_ERROR; + ORegKey* pKey = static_cast< ORegKey* >(hKey); - pReg = new ORegistry(); + std::auto_ptr< ORegistry > pReg (new ORegistry()); _ret = pReg->initRegistry(regFileName, REG_CREATE); - if (_ret) - { + if (_ret != REG_NO_ERROR) return _ret; - } - - pKey = (ORegKey*)hKey; - pRootKey = pReg->getRootKey(); + ORegKey* pRootKey = pReg->getRootKey(); REG_GUARD(m_mutex); OStoreDirectory::iterator iter; - OUString keyName; OStoreDirectory rStoreDir(pKey->getStoreDir()); storeError _err = rStoreDir.first(iter); while ( _err == store_E_None ) { - keyName = iter.m_pszName; + OUString const keyName = iter.m_pszName; if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR ) { _ret = loadAndSaveKeys(pRootKey, pKey, keyName, pKey->getName().getLength(), bWarnings, bReport); - } else + } + else { _ret = loadAndSaveValue(pRootKey, pKey, keyName, pKey->getName().getLength(), bWarnings, bReport); } - if (_ret) - { - pRootKey->release(); - delete(pReg); - return _ret; - } + if (_ret != REG_NO_ERROR) + break; _err = rStoreDir.next(iter); } - pRootKey->release(); - delete(pReg); - return REG_NO_ERROR; + (void) pReg->releaseKey(pRootKey); + return _ret; } //********************************************************************* -// loadValue() +// loadAndSaveValue() // RegError ORegistry::loadAndSaveValue(ORegKey* pTargetKey, ORegKey* pSourceKey, @@ -1139,6 +1128,7 @@ RegError ORegistry::loadAndSaveValue(ORegKey* pTargetKey, rtl_freeMemory(pBuffer); return REG_INVALID_VALUE; } + pTargetKey->setModified(); rtl_freeMemory(pBuffer); return _ret; @@ -1352,7 +1342,7 @@ RegError ORegistry::mergeModuleValue(OStoreStream& rTargetValue, } //********************************************************************* -// loadKeys() +// loadAndSaveKeys() // RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey, ORegKey* pSourceKey, @@ -1361,7 +1351,6 @@ RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey, sal_Bool bWarnings, sal_Bool bReport) { - ORegKey* pTmpKey; RegError _ret = REG_NO_ERROR; OUString sRelPath(pSourceKey->getName().copy(nCut)); OUString sFullPath; @@ -1372,11 +1361,10 @@ RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey, if (sRelPath.getLength() > 1 || sFullPath.getLength() == 0) sFullPath += ROOT; - OUString sFullKeyName = sFullPath; - OStoreDirectory rStoreDir; - + OUString sFullKeyName = sFullPath; sFullKeyName += keyName; + OStoreDirectory rStoreDir; if (rStoreDir.create(pTargetKey->getStoreFile(), sFullPath, keyName, KEY_MODE_CREATE)) { return REG_CREATE_KEY_FAILED; @@ -1387,21 +1375,18 @@ RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey, m_openKeyTable[sFullKeyName]->setDeleted(sal_False); } - _ret = pSourceKey->openKey( - keyName, (RegKeyHandle*)&pTmpKey); - if (_ret) - { + ORegKey* pTmpKey = 0; + _ret = pSourceKey->openKey(keyName, (RegKeyHandle*)&pTmpKey); + if (_ret != REG_NO_ERROR) return _ret; - } OStoreDirectory::iterator iter; - OUString sName; OStoreDirectory rTmpStoreDir(pTmpKey->getStoreDir()); storeError _err = rTmpStoreDir.first(iter); while ( _err == store_E_None) { - sName = iter.m_pszName; + OUString const sName = iter.m_pszName; if (iter.m_nAttrib & STORE_ATTRIB_ISDIR) { @@ -1413,17 +1398,15 @@ RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey, sName, nCut, bWarnings, bReport); } - if (_ret == REG_MERGE_ERROR || - (_ret == REG_MERGE_CONFLICT && bWarnings)) - { - pSourceKey->closeKey(pTmpKey); - return _ret; - } + if (_ret == REG_MERGE_ERROR) + break; + if (_ret == REG_MERGE_CONFLICT && bWarnings) + break; _err = rTmpStoreDir.next(iter); } - pSourceKey->closeKey(pTmpKey); + pSourceKey->releaseKey(pTmpKey); return _ret; } @@ -1477,21 +1460,6 @@ RegError ORegistry::dumpRegistry(RegKeyHandle hKey) const return REG_NO_ERROR; } -RegError ORegistry::flush() -{ - REG_GUARD(m_mutex); - - if (m_file.isValid()) - { - m_file.flush(); - return REG_NO_ERROR; - } else - { - return REG_REGISTRY_NOT_EXISTS; - } -} - - //********************************************************************* // dumpValue() // diff --git a/registry/source/regimpl.hxx b/registry/source/regimpl.hxx index 32baf9cc6ed5..54048584d7f7 100644 --- a/registry/source/regimpl.hxx +++ b/registry/source/regimpl.hxx @@ -32,10 +32,10 @@ #define _REGIMPL_HXX_ #include <set> - #include <hash_map> #include <registry/registry.h> +#include <rtl/ustring.hxx> #include <osl/mutex.hxx> #include <store/store.hxx> @@ -62,11 +62,10 @@ #define REG_CREATE 0x0004 // allow write accesses #define REG_GUARD(mutex) \ - Guard< Mutex > aGuard( mutex ); + osl::Guard< osl::Mutex > aGuard( mutex ); -using namespace rtl; -using namespace osl; -using namespace store; +// @@@ using namespace rtl; +// @@@ using namespace osl; class ORegKey; class RegistryTypeReader; @@ -82,39 +81,40 @@ public: sal_uInt32 release() { return --m_refCount; } - RegError initRegistry(const OUString& name, + RegError initRegistry(const rtl::OUString& name, RegAccessMode accessMode); RegError closeRegistry(); - RegError destroyRegistry(const OUString& name); + RegError destroyRegistry(const rtl::OUString& name); + + RegError acquireKey(RegKeyHandle hKey); + RegError releaseKey(RegKeyHandle hKey); RegError createKey(RegKeyHandle hKey, - const OUString& keyName, + const rtl::OUString& keyName, RegKeyHandle* phNewKey); RegError openKey(RegKeyHandle hKey, - const OUString& keyName, + const rtl::OUString& keyName, RegKeyHandle* phOpenKey); RegError closeKey(RegKeyHandle hKey); - RegError deleteKey(RegKeyHandle hKey, const OUString& keyName); + RegError deleteKey(RegKeyHandle hKey, const rtl::OUString& keyName); RegError loadKey(RegKeyHandle hKey, - const OUString& regFileName, + const rtl::OUString& regFileName, sal_Bool bWarings=sal_False, sal_Bool bReport=sal_False); RegError saveKey(RegKeyHandle hKey, - const OUString& regFileName, + const rtl::OUString& regFileName, sal_Bool bWarings=sal_False, sal_Bool bReport=sal_False); RegError dumpRegistry(RegKeyHandle hKey) const; - RegError flush(); - ~ORegistry(); sal_Bool isReadOnly() const @@ -125,62 +125,62 @@ public: ORegKey* getRootKey(); - const OStoreFile& getStoreFile() + const store::OStoreFile& getStoreFile() { return m_file; } - const OUString& getName() const + const rtl::OUString& getName() const { return m_name; } friend class ORegKey; private: - RegError eraseKey(ORegKey* pKey, const OUString& keyName); + RegError eraseKey(ORegKey* pKey, const rtl::OUString& keyName); RegError deleteSubkeysAndValues(ORegKey* pKey); RegError loadAndSaveValue(ORegKey* pTargetKey, ORegKey* pSourceKey, - const OUString& valueName, + const rtl::OUString& valueName, sal_uInt32 nCut, sal_Bool bWarnings=sal_False, sal_Bool bReport=sal_False); - RegError checkBlop(OStoreStream& rValue, - const OUString& sTargetPath, + RegError checkBlop(store::OStoreStream& rValue, + const rtl::OUString& sTargetPath, sal_uInt32 srcValueSize, sal_uInt8* pSrcBuffer, sal_Bool bReport=sal_False); - RegError mergeModuleValue(OStoreStream& rTargetValue, + RegError mergeModuleValue(store::OStoreStream& rTargetValue, RegistryTypeReader& reader, RegistryTypeReader& reader2); RegError loadAndSaveKeys(ORegKey* pTargetKey, ORegKey* pSourceKey, - const OUString& keyName, + const rtl::OUString& keyName, sal_uInt32 nCut, sal_Bool bWarnings=sal_False, sal_Bool bReport=sal_False); - RegError dumpValue(const OUString& sPath, - const OUString& sName, + RegError dumpValue(const rtl::OUString& sPath, + const rtl::OUString& sName, sal_Int16 nSpace) const; - RegError dumpKey(const OUString& sPath, - const OUString& sName, + RegError dumpKey(const rtl::OUString& sPath, + const rtl::OUString& sName, sal_Int16 nSpace) const; - typedef std::hash_map< OUString, ORegKey*, OUStringHash > KeyMap; + typedef std::hash_map< rtl::OUString, ORegKey*, rtl::OUStringHash > KeyMap; sal_uInt32 m_refCount; - Mutex m_mutex; + osl::Mutex m_mutex; sal_Bool m_readOnly; sal_Bool m_isOpen; - OUString m_name; - OStoreFile m_file; + rtl::OUString m_name; + store::OStoreFile m_file; KeyMap m_openKeyTable; - const OUString ROOT; + const rtl::OUString ROOT; }; #endif diff --git a/registry/source/registry.cxx b/registry/source/registry.cxx index 139646f7cdc7..cef3630f8b7e 100644 --- a/registry/source/registry.cxx +++ b/registry/source/registry.cxx @@ -30,13 +30,13 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_registry.hxx" + #include <registry/registry.h> #include <registry/registry.hxx> #include <osl/process.h> -#include "regimpl.hxx" -#ifndef _REGKEY_HXX_ + #include "keyimpl.hxx" -#endif +#include "regimpl.hxx" #include "regkey.hxx" #if defined(WIN32) || defined(WNT) || defined(OS2) @@ -260,46 +260,42 @@ static RegError REGISTRY_CALLTYPE loadKey(RegHandle hReg, rtl_uString* keyName, rtl_uString* regFileName) { - ORegistry *pReg; - ORegKey *pKey, *pNewKey; - RegError _ret; - if (hReg) - { - pReg = (ORegistry*)hReg; - if (!pReg->isOpen()) - return REG_REGISTRY_NOT_OPEN; - } else - { + ORegistry* pReg = static_cast< ORegistry* >(hReg); + if (!pReg) return REG_INVALID_REGISTRY; - } - if (hKey) - { - pKey = (ORegKey*)hKey; + if (!pReg->isOpen()) + return REG_REGISTRY_NOT_OPEN; - if (pKey->getRegistry() != pReg || pKey->isDeleted()) - return REG_INVALID_KEY; - } else - { + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) return REG_INVALID_KEY; - } + if (pKey->getRegistry() != pReg) + return REG_INVALID_KEY; + if (pKey->isDeleted()) + return REG_INVALID_KEY; if (pKey->isReadOnly()) return REG_REGISTRY_READONLY; - if (!pKey->openKey(keyName, (RegKeyHandle*)&pNewKey)) + + ORegKey* pNewKey = 0; + RegError _ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey); + if (_ret == REG_NO_ERROR) { - pKey->closeKey(pNewKey); + pKey->releaseKey(pNewKey); pKey->deleteKey(keyName); } - if ((_ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey))) + _ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey); + if (_ret != REG_NO_ERROR) return _ret; - if ((_ret = pReg->loadKey(pNewKey, regFileName))) + _ret = pReg->loadKey(pNewKey, regFileName); + if (_ret != REG_NO_ERROR) { - pKey->closeKey(pNewKey); + pKey->releaseKey(pNewKey); pKey->deleteKey(keyName); return _ret; } @@ -315,41 +311,36 @@ static RegError REGISTRY_CALLTYPE saveKey(RegHandle hReg, rtl_uString* keyName, rtl_uString* regFileName) { - ORegistry *pReg; - ORegKey *pKey, *pNewKey; - RegError _ret; - if (hReg) - { - pReg = (ORegistry*)hReg; - if (!pReg->isOpen()) - return REG_REGISTRY_NOT_OPEN; - } else - { + ORegistry* pReg = static_cast< ORegistry* >(hReg); + if (!pReg) return REG_INVALID_REGISTRY; - } - if (hKey) - { - pKey = (ORegKey*)hKey; + if (!pReg->isOpen()) + return REG_REGISTRY_NOT_OPEN; - if (pKey->getRegistry() != pReg || pKey->isDeleted()) - return REG_INVALID_KEY; - } else - { + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; + + if (pKey->getRegistry() != pReg) + return REG_INVALID_KEY; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } - if ((_ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey))) + ORegKey* pNewKey = 0; + RegError _ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey); + if (_ret != REG_NO_ERROR) return _ret; - if ((_ret = pReg->saveKey(pNewKey, regFileName))) + _ret = pReg->saveKey(pNewKey, regFileName); + if (_ret != REG_NO_ERROR) { - pKey->closeKey(pNewKey); + (void) pKey->releaseKey(pNewKey); return _ret; } - return pKey->closeKey(pNewKey); + return pKey->releaseKey(pNewKey); } //********************************************************************* @@ -362,114 +353,68 @@ static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg, sal_Bool bWarnings, sal_Bool bReport) { - ORegistry *pReg; - ORegKey *pKey, *pNewKey; - RegError _ret; - - if (hReg) - { - pReg = (ORegistry*)hReg; - if (!pReg->isOpen()) - return(REG_REGISTRY_NOT_OPEN); - } else - { + ORegistry* pReg = static_cast< ORegistry* >(hReg); + if (!pReg) return REG_INVALID_REGISTRY; - } - - if (hKey) - { - pKey = (ORegKey*)hKey; + if (!pReg->isOpen()) + return REG_REGISTRY_NOT_OPEN; - if (pKey->getRegistry() != pReg || pKey->isDeleted()) - return REG_INVALID_KEY; - } else - { + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; + if (pKey->getRegistry() != pReg) + return REG_INVALID_KEY; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } - if (pKey->isReadOnly()) return REG_REGISTRY_READONLY; if (keyName->length) { - if ((_ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey) )) + ORegKey* pNewKey = 0; + RegError _ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey); + if (_ret != REG_NO_ERROR) return _ret; - } else - { - pNewKey = pKey; - } - - _ret = pKey->getRegistry()->loadKey(pNewKey, regFileName, bWarnings, bReport); - - if (_ret == REG_MERGE_ERROR || - (_ret == REG_MERGE_CONFLICT && bWarnings)) - { - pKey->closeKey(pNewKey); - return _ret; - } - /* - if (_ret) - { - if (_ret == REG_MERGE_ERROR || - (_ret == REG_MERGE_CONFLICT && bWarnings)) + _ret = pReg->loadKey(pNewKey, regFileName, bWarnings, bReport); + if (_ret == REG_MERGE_ERROR || (_ret == REG_MERGE_CONFLICT && bWarnings)) { - pKey->closeKey(pNewKey); - pKey->deleteKey(keyName); - pKey->createKey(keyName, (RegKeyHandle*)&pNewKey); - pReg->loadKey(pNewKey, tmpName, sal_False, sal_False); + if (pNewKey != pKey) + (void) pKey->closeKey(pNewKey); + else + (void) pKey->releaseKey(pNewKey); + return _ret; } - destroyRegistry(hReg, tmpName); - - pKey->closeKey(pNewKey); - return _ret; + return (pNewKey != pKey) ? pKey->closeKey(pNewKey) : pKey->releaseKey(pNewKey); } - destroyRegistry(hReg, tmpName); - */ - _ret = pKey->closeKey(pNewKey); - - if (_ret == REG_NO_ERROR ) - _ret = pReg->flush(); - return _ret; + return pReg->loadKey(pKey, regFileName, bWarnings, bReport); } - //********************************************************************* // dumpRegistry // static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg, RegKeyHandle hKey) { - ORegistry *pReg; - ORegKey *pKey; - - if (hReg) - { - pReg = (ORegistry*)hReg; - if (!pReg->isOpen()) - return REG_REGISTRY_NOT_OPEN; - } else - { + ORegistry* pReg = static_cast< ORegistry* >(hReg); + if (!pReg) return REG_INVALID_REGISTRY; - } - - if (hKey) - { - pKey = (ORegKey*)hKey; + if (!pReg->isOpen()) + return REG_REGISTRY_NOT_OPEN; - if (pKey->getRegistry() != pReg || pKey->isDeleted()) - return REG_INVALID_KEY; - } else - { + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; + if (pKey->getRegistry() != pReg) + return REG_INVALID_KEY; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } return pReg->dumpRegistry(hKey); } - //********************************************************************* // initRegistry_Api // diff --git a/registry/source/regkey.cxx b/registry/source/regkey.cxx index 1d828a862a96..4ea3e9345e0b 100644 --- a/registry/source/regkey.cxx +++ b/registry/source/regkey.cxx @@ -32,21 +32,25 @@ #include "precompiled_registry.hxx" #include "regkey.hxx" + #include <registry/registry.hxx> #include <rtl/alloc.h> #include "regimpl.hxx" #include "keyimpl.hxx" +using rtl::OUString; //********************************************************************* // acquireKey // void REGISTRY_CALLTYPE acquireKey(RegKeyHandle hKey) { - ORegKey* pKey = (ORegKey*) hKey; - - if (pKey != NULL) - pKey->acquire(); + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (pKey != 0) + { + ORegistry* pReg = pKey->getRegistry(); + (void) pReg->acquireKey(pKey); + } } @@ -55,12 +59,11 @@ void REGISTRY_CALLTYPE acquireKey(RegKeyHandle hKey) // void REGISTRY_CALLTYPE releaseKey(RegKeyHandle hKey) { - ORegKey* pKey = (ORegKey*) hKey; - - if (pKey) + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (pKey != 0) { - if (pKey->release() == 0) - delete pKey; + ORegistry* pReg = pKey->getRegistry(); + (void) pReg->releaseKey(pKey); } } @@ -70,13 +73,8 @@ void REGISTRY_CALLTYPE releaseKey(RegKeyHandle hKey) // sal_Bool REGISTRY_CALLTYPE isKeyReadOnly(RegKeyHandle hKey) { - if (hKey) - { - return ((ORegKey*)hKey)->isReadOnly(); - } else - { - return sal_False; - } + ORegKey* pKey = static_cast< ORegKey* >(hKey); + return (pKey != 0) ? pKey->isReadOnly() : sal_False; } @@ -85,9 +83,10 @@ sal_Bool REGISTRY_CALLTYPE isKeyReadOnly(RegKeyHandle hKey) // RegError REGISTRY_CALLTYPE getKeyName(RegKeyHandle hKey, rtl_uString** pKeyName) { - if (hKey) + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (pKey) { - rtl_uString_assign( pKeyName, ((ORegKey*)hKey)->getName().pData ); + rtl_uString_assign( pKeyName, pKey->getName().pData ); return REG_NO_ERROR; } else { @@ -104,22 +103,14 @@ RegError REGISTRY_CALLTYPE createKey(RegKeyHandle hKey, rtl_uString* keyName, RegKeyHandle* phNewKey) { - ORegKey* pKey; + *phNewKey = 0; - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - { - phNewKey = NULL; - return REG_INVALID_KEY; - } - } else - { - phNewKey = NULL; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } if (pKey->isReadOnly()) return REG_REGISTRY_READONLY; @@ -134,22 +125,14 @@ RegError REGISTRY_CALLTYPE openKey(RegKeyHandle hKey, rtl_uString* keyName, RegKeyHandle* phOpenKey) { - ORegKey* pKey; + *phOpenKey = 0; - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - { - phOpenKey = NULL; - return REG_INVALID_KEY; - } - } else - { - phOpenKey = NULL; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } return pKey->openKey(keyName, phOpenKey); } @@ -162,24 +145,15 @@ RegError REGISTRY_CALLTYPE openSubKeys(RegKeyHandle hKey, RegKeyHandle** pphSubKeys, sal_uInt32* pnSubKeys) { - ORegKey* pKey; + *pphSubKeys = NULL; + *pnSubKeys = 0; - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - { - *pphSubKeys = NULL; - *pnSubKeys = 0; - return REG_INVALID_KEY; - } - } else - { - *pphSubKeys = NULL; - *pnSubKeys = 0; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } return pKey->openSubKeys(keyName, pphSubKeys, pnSubKeys); } @@ -190,43 +164,30 @@ RegError REGISTRY_CALLTYPE openSubKeys(RegKeyHandle hKey, RegError REGISTRY_CALLTYPE closeSubKeys(RegKeyHandle* phSubKeys, sal_uInt32 nSubKeys) { - RegError _ret = REG_NO_ERROR; + if (phSubKeys == 0 || nSubKeys == 0) + return REG_INVALID_KEY; - if (phSubKeys != 0 && nSubKeys != 0) + ORegistry* pReg = ((ORegKey*)(phSubKeys[0]))->getRegistry(); + for (sal_uInt32 i = 0; i < nSubKeys; i++) { - ORegistry* pReg = NULL; - - pReg = ((ORegKey*)phSubKeys[0])->getRegistry(); - - for (sal_uInt32 i=0; (i < nSubKeys) && (_ret == REG_NO_ERROR); i++) - { - _ret = pReg->closeKey(phSubKeys[i]); - } - - rtl_freeMemory(phSubKeys); + (void) pReg->closeKey(phSubKeys[i]); } - else - _ret = REG_INVALID_KEY; + rtl_freeMemory(phSubKeys); - return _ret; + return REG_NO_ERROR; } - //********************************************************************* // deleteKey // RegError REGISTRY_CALLTYPE deleteKey(RegKeyHandle hKey, rtl_uString* keyName) { - ORegKey* pKey; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; if (pKey->isReadOnly()) @@ -240,24 +201,13 @@ RegError REGISTRY_CALLTYPE deleteKey(RegKeyHandle hKey, // RegError REGISTRY_CALLTYPE closeKey(RegKeyHandle hKey) { - ORegKey* pKey; - ORegistry* pReg; - - if (hKey) - { - pKey = (ORegKey*)hKey; - - pReg = pKey->getRegistry(); - - if (pReg->closeKey(hKey)) - return REG_INVALID_KEY; - } else + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) return REG_INVALID_KEY; - return REG_NO_ERROR; + return pKey->closeKey(hKey); } - //********************************************************************* // setValue // @@ -267,15 +217,11 @@ RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, RegValue pData, sal_uInt32 valueSize) { - ORegKey* pKey; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; if (pKey->isReadOnly()) @@ -284,24 +230,22 @@ RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret1 = pKey->openKey(keyName, &hSubKey); - if (_ret1) + ORegKey* pSubKey = 0; + RegError _ret1 = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret1 != REG_NO_ERROR) return _ret1; - pSubKey = (ORegKey*)hSubKey; _ret1 = pSubKey->setValue(valueName, valueType, pData, valueSize); - if (_ret1) + if (_ret1 != REG_NO_ERROR) { - RegError _ret2 = pKey->closeKey(hSubKey); + RegError _ret2 = pKey->closeKey(pSubKey); if (_ret2) return _ret2; else return _ret1; } - return pKey->closeKey(hSubKey); + return pKey->closeKey(pSubKey); } return pKey->setValue(valueName, valueType, pData, valueSize); @@ -315,15 +259,11 @@ RegError REGISTRY_CALLTYPE setLongListValue(RegKeyHandle hKey, sal_Int32* pValueList, sal_uInt32 len) { - ORegKey* pKey; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; if (pKey->isReadOnly()) @@ -332,24 +272,22 @@ RegError REGISTRY_CALLTYPE setLongListValue(RegKeyHandle hKey, OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret1 = pKey->openKey(keyName, &hSubKey); - if (_ret1) + ORegKey* pSubKey = 0; + RegError _ret1 = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret1 != REG_NO_ERROR) return _ret1; - pSubKey = (ORegKey*)hSubKey; _ret1 = pSubKey->setLongListValue(valueName, pValueList, len); - if (_ret1) + if (_ret1 != REG_NO_ERROR) { - RegError _ret2 = pKey->closeKey(hSubKey); - if (_ret2) + RegError _ret2 = pKey->closeKey(pSubKey); + if (_ret2 != REG_NO_ERROR) return _ret2; else return _ret1; } - return pKey->closeKey(hSubKey); + return pKey->closeKey(pSubKey); } return pKey->setLongListValue(valueName, pValueList, len); @@ -363,15 +301,11 @@ RegError REGISTRY_CALLTYPE setStringListValue(RegKeyHandle hKey, sal_Char** pValueList, sal_uInt32 len) { - ORegKey* pKey; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; if (pKey->isReadOnly()) @@ -380,24 +314,22 @@ RegError REGISTRY_CALLTYPE setStringListValue(RegKeyHandle hKey, OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret1 = pKey->openKey(keyName, &hSubKey); - if (_ret1) + ORegKey* pSubKey = 0; + RegError _ret1 = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret1 != REG_NO_ERROR) return _ret1; - pSubKey = (ORegKey*)hSubKey; _ret1 = pSubKey->setStringListValue(valueName, pValueList, len); - if (_ret1) + if (_ret1 != REG_NO_ERROR) { - RegError _ret2 = pKey->closeKey(hSubKey); - if (_ret2) + RegError _ret2 = pKey->closeKey(pSubKey); + if (_ret2 != REG_NO_ERROR) return _ret2; else return _ret1; } - return pKey->closeKey(hSubKey); + return pKey->closeKey(pSubKey); } return pKey->setStringListValue(valueName, pValueList, len); @@ -411,15 +343,11 @@ RegError REGISTRY_CALLTYPE setUnicodeListValue(RegKeyHandle hKey, sal_Unicode** pValueList, sal_uInt32 len) { - ORegKey* pKey; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; if (pKey->isReadOnly()) @@ -428,24 +356,22 @@ RegError REGISTRY_CALLTYPE setUnicodeListValue(RegKeyHandle hKey, OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret1 = pKey->openKey(keyName, &hSubKey); - if (_ret1) + ORegKey* pSubKey = 0; + RegError _ret1 = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret1 != REG_NO_ERROR) return _ret1; - pSubKey = (ORegKey*)hSubKey; _ret1 = pSubKey->setUnicodeListValue(valueName, pValueList, len); - if (_ret1) + if (_ret1 != REG_NO_ERROR) { - RegError _ret2 = pKey->closeKey(hSubKey); - if (_ret2) + RegError _ret2 = pKey->closeKey(pSubKey); + if (_ret2 != REG_NO_ERROR) return _ret2; else return _ret1; } - return pKey->closeKey(hSubKey); + return pKey->closeKey(pSubKey); } return pKey->setUnicodeListValue(valueName, pValueList, len); @@ -459,49 +385,41 @@ RegError REGISTRY_CALLTYPE getValueInfo(RegKeyHandle hKey, RegValueType* pValueType, sal_uInt32* pValueSize) { - ORegKey* pKey; - RegValueType valueType; - sal_uInt32 valueSize; - *pValueType = RG_VALUETYPE_NOT_DEFINED; *pValueSize = 0; - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; + RegValueType valueType; + sal_uInt32 valueSize; + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret = pKey->openKey(keyName, &hSubKey); - if (_ret) + ORegKey* pSubKey = 0; + RegError _ret = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret != REG_NO_ERROR) return _ret; - pSubKey = (ORegKey*)hSubKey; - if (pSubKey->getValueInfo(valueName, &valueType, &valueSize)) + if (pSubKey->getValueInfo(valueName, &valueType, &valueSize) != REG_NO_ERROR) { - _ret = pKey->closeKey(hSubKey); - if (_ret) - return _ret; - else - return REG_INVALID_VALUE; + (void) pKey->releaseKey(pSubKey); + return REG_INVALID_VALUE; } *pValueType = valueType; *pValueSize = valueSize; - return pKey->closeKey(hSubKey); + return pKey->releaseKey(pSubKey); } - if (pKey->getValueInfo(valueName, &valueType, &valueSize)) + if (pKey->getValueInfo(valueName, &valueType, &valueSize) != REG_NO_ERROR) { return REG_INVALID_VALUE; } @@ -519,52 +437,29 @@ RegError REGISTRY_CALLTYPE getValue(RegKeyHandle hKey, rtl_uString* keyName, RegValue pValue) { - ORegKey* pKey; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - { - pValue = NULL; - return REG_INVALID_KEY; - } - } else - { - pValue = NULL; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret1 = pKey->openKey(keyName, &hSubKey); - if (_ret1) - { - pValue = NULL; + ORegKey* pSubKey = 0; + RegError _ret1 = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret1 != REG_NO_ERROR) return _ret1; - } - pSubKey = (ORegKey*)hSubKey; _ret1 = pSubKey->getValue(valueName, pValue); - if (_ret1) + if (_ret1 != REG_NO_ERROR) { - RegError _ret2 = pKey->closeKey(hSubKey); - if (_ret2) - { - pValue = NULL; - return _ret2; - } else - { - pValue = NULL; - return _ret1; - } + (void) pKey->releaseKey(pSubKey); + return _ret1; } - return pKey->closeKey(hSubKey); + return pKey->releaseKey(pSubKey); } return pKey->getValue(valueName, pValue); @@ -578,58 +473,32 @@ RegError REGISTRY_CALLTYPE getLongListValue(RegKeyHandle hKey, sal_Int32** pValueList, sal_uInt32* pLen) { - ORegKey* pKey; + OSL_PRECOND((pValueList != 0) && (pLen != 0), "registry::getLongListValue(): invalid parameter"); + *pValueList = 0, *pLen = 0; - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - { - pValueList = NULL; - *pLen = 0; - return REG_INVALID_KEY; - } - } else - { - pValueList = NULL; - *pLen = 0; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret1 = pKey->openKey(keyName, &hSubKey); - if (_ret1) - { - pValueList = NULL; - *pLen = 0; + ORegKey* pSubKey = 0; + RegError _ret1 = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret1 != REG_NO_ERROR) return _ret1; - } - - pSubKey = (ORegKey*)hSubKey; _ret1 = pSubKey->getLongListValue(valueName, pValueList, pLen); - if (_ret1) + if (_ret1 != REG_NO_ERROR) { - RegError _ret2 = pKey->closeKey(hSubKey); - if (_ret2) - { - pValueList = NULL; - *pLen = 0; - return _ret2; - } else - { - pValueList = NULL; - *pLen = 0; - return _ret1; - } + (void) pKey->releaseKey(pSubKey); + return _ret1; } - return pKey->closeKey(hSubKey); + return pKey->releaseKey(pSubKey); } return pKey->getLongListValue(valueName, pValueList, pLen); @@ -643,58 +512,32 @@ RegError REGISTRY_CALLTYPE getStringListValue(RegKeyHandle hKey, sal_Char*** pValueList, sal_uInt32* pLen) { - ORegKey* pKey; + OSL_PRECOND((pValueList != 0) && (pLen != 0), "registry::getStringListValue(): invalid parameter"); + *pValueList = 0, *pLen = 0; - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - { - pValueList = NULL; - *pLen = 0; - return REG_INVALID_KEY; - } - } else - { - pValueList = NULL; - *pLen = 0; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret1 = pKey->openKey(keyName, &hSubKey); - if (_ret1) - { - pValueList = NULL; - *pLen = 0; + ORegKey* pSubKey = 0; + RegError _ret1 = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret1 != REG_NO_ERROR) return _ret1; - } - - pSubKey = (ORegKey*)hSubKey; _ret1 = pSubKey->getStringListValue(valueName, pValueList, pLen); - if (_ret1) + if (_ret1 != REG_NO_ERROR) { - RegError _ret2 = pKey->closeKey(hSubKey); - if (_ret2) - { - pValueList = NULL; - *pLen = 0; - return _ret2; - } else - { - pValueList = NULL; - *pLen = 0; - return _ret1; - } + (void) pKey->releaseKey(pSubKey); + return _ret1; } - return pKey->closeKey(hSubKey); + return pKey->releaseKey(pSubKey); } return pKey->getStringListValue(valueName, pValueList, pLen); @@ -708,58 +551,32 @@ RegError REGISTRY_CALLTYPE getUnicodeListValue(RegKeyHandle hKey, sal_Unicode*** pValueList, sal_uInt32* pLen) { - ORegKey* pKey; + OSL_PRECOND((pValueList != 0) && (pLen != 0), "registry::getUnicodeListValue(): invalid parameter"); + *pValueList = 0, *pLen = 0; - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - { - pValueList = NULL; - *pLen = 0; - return REG_INVALID_KEY; - } - } else - { - pValueList = NULL; - *pLen = 0; + if (pKey->isDeleted()) return REG_INVALID_KEY; - } OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); if (keyName->length) { - RegKeyHandle hSubKey; - ORegKey* pSubKey; - RegError _ret1 = pKey->openKey(keyName, &hSubKey); - if (_ret1) - { - pValueList = NULL; - *pLen = 0; + ORegKey* pSubKey = 0; + RegError _ret1 = pKey->openKey(keyName, (RegKeyHandle*)&pSubKey); + if (_ret1 != REG_NO_ERROR) return _ret1; - } - - pSubKey = (ORegKey*)hSubKey; _ret1 = pSubKey->getUnicodeListValue(valueName, pValueList, pLen); - if (_ret1) + if (_ret1 != REG_NO_ERROR) { - RegError _ret2 = pKey->closeKey(hSubKey); - if (_ret2) - { - pValueList = NULL; - *pLen = 0; - return _ret2; - } else - { - pValueList = NULL; - *pLen = 0; - return _ret1; - } + (void) pKey->releaseKey(pSubKey); + return _ret1; } - return pKey->closeKey(hSubKey); + return pKey->releaseKey(pSubKey); } return pKey->getUnicodeListValue(valueName, pValueList, pLen); @@ -809,7 +626,6 @@ RegError REGISTRY_CALLTYPE freeValueList(RegValueType valueType, return REG_NO_ERROR; } - //********************************************************************* // createLink // @@ -833,15 +649,11 @@ RegError REGISTRY_CALLTYPE getKeyType(RegKeyHandle hKey, rtl_uString* keyName, RegKeyType* pKeyType) { - ORegKey* pKey; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; return pKey->getKeyType(keyName, pKeyType); @@ -864,26 +676,20 @@ RegError REGISTRY_CALLTYPE getResolvedKeyName(RegKeyHandle hKey, sal_Bool, rtl_uString** pResolvedName) { - ORegKey *pKey; - RegError _ret = REG_NO_ERROR; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; OUString resolvedName; - _ret = pKey->getResolvedKeyName(keyName, resolvedName); - if (!_ret) + RegError _ret = pKey->getResolvedKeyName(keyName, resolvedName); + if (_ret == REG_NO_ERROR) rtl_uString_assign(pResolvedName, resolvedName.pData); return _ret; } - //********************************************************************* // getKeyNames // @@ -892,15 +698,11 @@ RegError REGISTRY_CALLTYPE getKeyNames(RegKeyHandle hKey, rtl_uString*** pSubKeyNames, sal_uInt32* pnSubKeys) { - ORegKey* pKey; - - if (hKey) - { - pKey = (ORegKey*)hKey; + ORegKey* pKey = static_cast< ORegKey* >(hKey); + if (!pKey) + return REG_INVALID_KEY; - if (pKey->isDeleted()) - return REG_INVALID_KEY; - } else + if (pKey->isDeleted()) return REG_INVALID_KEY; return pKey->getKeyNames(keyName, pSubKeyNames, pnSubKeys); @@ -1208,7 +1010,6 @@ RegError REGISTRY_CALLTYPE reg_getLinkTarget(RegKeyHandle hKey, return getLinkTarget(hKey, linkName, pLinkTarget); } - //********************************************************************* // reg_getResolvedKeyName // @@ -1217,14 +1018,8 @@ RegError REGISTRY_CALLTYPE reg_getResolvedKeyName(RegKeyHandle hKey, sal_Bool firstLinkOnly, rtl_uString** pResolvedName) { - ORegKey *pKey; - - if (hKey) - pKey = (ORegKey*)hKey; - else + if (!hKey) return REG_INVALID_KEY; return getResolvedKeyName(hKey, keyName, firstLinkOnly, pResolvedName); } - - diff --git a/registry/tools/checksingleton.cxx b/registry/tools/checksingleton.cxx index 7900b1db7a62..ba32ae038ba8 100644 --- a/registry/tools/checksingleton.cxx +++ b/registry/tools/checksingleton.cxx @@ -30,6 +30,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_registry.hxx" + #include <stdio.h> #include <string.h> @@ -455,10 +456,10 @@ int _cdecl main( int argc, char * argv[] ) sal_Bool bSingletonsExist = checkSingletons(singletonKey, typeKey); - indexRoot.closeKey(); - typeRoot.closeKey(); - typeKey.closeKey(); - singletonKey.closeKey(); + indexRoot.releaseKey(); + typeRoot.releaseKey(); + typeKey.releaseKey(); + singletonKey.releaseKey(); if ( indexReg.close() ) { fprintf(stderr, "%s: closing registry \"%s\" failed\n", diff --git a/registry/tools/regcompare.cxx b/registry/tools/regcompare.cxx index f41103afb826..73662007dcad 100644 --- a/registry/tools/regcompare.cxx +++ b/registry/tools/regcompare.cxx @@ -30,6 +30,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_registry.hxx" + #include <stdio.h> #include <string.h> @@ -2276,8 +2277,8 @@ static sal_uInt32 compareKeys(RegistryKey& key1, RegistryKey& key2) { nError += compareKeys(subKey1, subKey2); } - subKey1.closeKey(); - subKey2.closeKey(); + subKey1.releaseKey(); + subKey2.releaseKey(); ++iter; } @@ -2380,8 +2381,8 @@ int _cdecl main( int argc, char * argv[] ) } } - key1.closeKey(); - key2.closeKey(); + key1.releaseKey(); + key2.releaseKey(); if ( reg1.close() ) { fprintf(stdout, "%s: closing registry \"%s\" failed\n", diff --git a/registry/tools/regmerge.cxx b/registry/tools/regmerge.cxx index 45cab0927b10..4fcb19a03c00 100644 --- a/registry/tools/regmerge.cxx +++ b/registry/tools/regmerge.cxx @@ -34,7 +34,7 @@ #include <stdio.h> #include <string.h> -#include "registry/registry.h" +#include "registry/registry.hxx" #include <rtl/ustring.hxx> #include <rtl/alloc.h> #include <osl/process.h> @@ -207,9 +207,7 @@ int main( int argc, char * argv[] ) int _cdecl main( int argc, char * argv[] ) #endif { - RegHandle hReg; - RegKeyHandle hRootKey; - bool bVerbose = checkCommandArgs(argc, argv); + bool bVerbose = checkCommandArgs(argc, argv); if (realargc < 4) { @@ -219,9 +217,11 @@ int _cdecl main( int argc, char * argv[] ) } ::rtl::OUString regName( convertToFileUrl(realargv[1]) ); - if (reg_openRegistry(regName.pData, &hReg, REG_READWRITE)) + + Registry reg; + if (reg.open(regName, REG_READWRITE) != REG_NO_ERROR) { - if (reg_createRegistry(regName.pData, &hReg)) + if (reg.create(regName) != REG_NO_ERROR) { if (bVerbose) fprintf(stderr, "open registry \"%s\" failed\n", realargv[1]); @@ -230,17 +230,16 @@ int _cdecl main( int argc, char * argv[] ) } } - if (!reg_openRootKey(hReg, &hRootKey)) + RegistryKey rootKey; + if (reg.openRootKey(rootKey) == REG_NO_ERROR) { ::rtl::OUString mergeKeyName( ::rtl::OUString::createFromAscii(realargv[2]) ); ::rtl::OUString targetRegName; for (int i = 3; i < realargc; i++) { targetRegName = convertToFileUrl(realargv[i]); - RegError _ret = reg_mergeKey( - hRootKey, mergeKeyName.pData, targetRegName.pData, sal_False, - bVerbose); - if (_ret) + RegError _ret = reg.mergeKey(rootKey, mergeKeyName, targetRegName, sal_False, bVerbose); + if (_ret != REG_NO_ERROR) { if (_ret == REG_MERGE_CONFLICT) { @@ -262,13 +261,7 @@ int _cdecl main( int argc, char * argv[] ) } } - if (reg_closeKey(hRootKey)) - { - if (bVerbose) - fprintf(stderr, "closing root key of registry \"%s\" failed\n", - realargv[1]); - exit(-3); - } + rootKey.releaseKey(); } else { if (bVerbose) @@ -277,7 +270,7 @@ int _cdecl main( int argc, char * argv[] ) exit(-4); } - if (reg_closeRegistry(hReg)) + if (reg.close() != REG_NO_ERROR) { if (bVerbose) fprintf(stderr, "closing registry \"%s\" failed\n", realargv[1]); diff --git a/store/source/lockbyte.cxx b/store/source/lockbyte.cxx index 551c7c737127..551c7c737127 100644..100755 --- a/store/source/lockbyte.cxx +++ b/store/source/lockbyte.cxx |