diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:18:43 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:18:43 +0000 |
commit | 9399c662f36c385b0c705eb34e636a9aec450282 (patch) | |
tree | f502e9d9258960ff214ab90e98e31d0075e60196 /registry/source |
initial import
Diffstat (limited to 'registry/source')
-rw-r--r-- | registry/source/keyimpl.cxx | 1260 | ||||
-rw-r--r-- | registry/source/keyimpl.hxx | 215 | ||||
-rw-r--r-- | registry/source/makefile.mk | 97 | ||||
-rw-r--r-- | registry/source/reflcnst.hxx | 268 | ||||
-rw-r--r-- | registry/source/reflread.cxx | 1602 | ||||
-rw-r--r-- | registry/source/reflwrit.cxx | 1452 | ||||
-rw-r--r-- | registry/source/regimpl.cxx | 2172 | ||||
-rw-r--r-- | registry/source/regimpl.hxx | 266 | ||||
-rw-r--r-- | registry/source/registry.cxx | 793 | ||||
-rw-r--r-- | registry/source/regkey.cxx | 1298 | ||||
-rw-r--r-- | registry/source/regmap.hxx | 117 |
11 files changed, 9540 insertions, 0 deletions
diff --git a/registry/source/keyimpl.cxx b/registry/source/keyimpl.cxx new file mode 100644 index 000000000000..88ab180472c7 --- /dev/null +++ b/registry/source/keyimpl.cxx @@ -0,0 +1,1260 @@ +/************************************************************************* + * + * $RCSfile: keyimpl.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef __REFLCNST_HXX__ +#include "reflcnst.hxx" +#endif + +#include "keyimpl.hxx" + +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + +#ifndef _RTL_MEMORY_H_ +#include <rtl/memory.h> +#endif + +//********************************************************************* +// ORegKey() +// +ORegKey::ORegKey(const OUString& keyName, const OStoreDirectory& rStoreDir, ORegistry* pReg) + : m_refCount(1) + , m_name(keyName) + , m_bDeleted(sal_False) + , m_isLink(sal_False) + , m_pRegistry(pReg) +{ + if (pReg) + { + m_storeFile = pReg->getStoreFile(); + } + + checkLink(); +} + +//********************************************************************* +// ORegKey() +// +ORegKey::ORegKey(const OUString& keyName, const OUString& linkName, + const OStoreDirectory& rStoreDir, ORegistry* pReg) + : m_refCount(1) + , m_name(keyName) + , m_bDeleted(sal_False) + , m_pRegistry(pReg) +{ + if (linkName.getLength()) + { + m_link = linkName; + m_isLink = sal_True; + + setValue(OUString( RTL_CONSTASCII_USTRINGPARAM("LINK_TARGET") ), RG_VALUETYPE_UNICODE, + (RegValue*)linkName.pData->buffer, linkName.getLength()+1); + } else + { + m_isLink = sal_False; + } +} + +//********************************************************************* +// ORegKey() +// +ORegKey::ORegKey() + : m_refCount(1) + , m_bDeleted(sal_False) + , m_isLink(sal_False) + , m_pRegistry(NULL) +{ +} + + +//********************************************************************* +// ~ORegKey() +// +ORegKey::~ORegKey() +{ +} + + +//********************************************************************* +// createKey +// +RegError ORegKey::createKey(const OUString& keyName, RegKeyHandle* phNewKey) +{ + return m_pRegistry->createKey(this, keyName, phNewKey); +} + + +//********************************************************************* +// openKey +// +RegError ORegKey::openKey(const OUString& keyName, RegKeyHandle* phOpenKey, RESOLVE eResolve) +{ + return (m_pRegistry->openKey(this, keyName, phOpenKey, eResolve)); +} + + +//********************************************************************* +// openSubKeys +// +RegError ORegKey::openSubKeys(const OUString& keyName, RegKeyHandle** phOpenSubKeys, sal_uInt32* pnSubKeys) +{ + ORegKey* pKey; + OUString sFullKeyName, sSubKeyName; + RegKeyHandle hSKey, hSubKey; + RegError _ret = REG_NO_ERROR; + sal_uInt32 nSubKeys; + ORegKey* *subKeys; + + if ( keyName.getLength() ) + { + if ((_ret = openKey(keyName, &hSKey))) + { + *phOpenSubKeys = NULL; + *pnSubKeys = 0; + return _ret; + } + + pKey = (ORegKey*)hSKey; + } else + { + pKey = this; + } + + nSubKeys = pKey->countSubKeys(); + + *pnSubKeys = nSubKeys; + subKeys = (ORegKey**)rtl_allocateZeroMemory(nSubKeys * sizeof(ORegKey*)); + + OStoreDirectory::iterator iter; + OStoreDirectory rStoreDir(pKey->getStoreDir()); + storeError _err = rStoreDir.first(iter); + + nSubKeys = 0; + while ( _err == store_E_None ) + { + if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR ) + { + sSubKeyName = iter.m_pszName; + sFullKeyName = pKey->getName(); + if (sFullKeyName.getLength() > 1) + sFullKeyName += m_pRegistry->ROOT; + sFullKeyName += sSubKeyName; + + if (_ret = pKey->openKey(sSubKeyName, &hSubKey)) + { + *phOpenSubKeys = NULL; + *pnSubKeys = 0; + rtl_freeMemory(subKeys); + return _ret; + } + + subKeys[nSubKeys] = ((ORegKey*)hSubKey); + + nSubKeys++; + } + + _err = rStoreDir.next(iter); + } + + *phOpenSubKeys = (RegKeyHandle*)subKeys; + if (keyName.getLength()) + { + closeKey(hSKey); + } + return REG_NO_ERROR; +} + + +//********************************************************************* +// getKeyNames +// +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; + + if (keyName.getLength()) + { + if (_ret = openKey(keyName, (RegKeyHandle*)&pKey, RESOLVE_PART)) + { + *pSubKeyNames = NULL; + *pnSubKeys = 0; + return _ret; + } + } else + { + pKey = this; + } + + nSubKeys = pKey->countSubKeys(); + + *pnSubKeys = nSubKeys; + 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; + + while ( _err == store_E_None ) + { + if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR) + { + sSubKeyName = iter.m_pszName; + sFullKeyName = pKey->getName(); + if (sFullKeyName.getLength() > 1) + sFullKeyName += m_pRegistry->ROOT; + sFullKeyName += sSubKeyName; + + subKey = sFullKeyName; + rtl_uString_newFromString(&pSubKeys[nSubKeys], subKey.pData); + + nSubKeys++; + } + + _err = rStoreDir.next(iter); + } + + *pSubKeyNames = pSubKeys; + if (keyName.getLength()) + { + closeKey((RegKeyHandle)pKey); + } + return REG_NO_ERROR; +} + + +//********************************************************************* +// closeSubKeys +// +RegError ORegKey::closeSubKeys(RegKeyHandle* phSubKeys, sal_uInt32 nSubKeys) +{ + RegError _ret = REG_NO_ERROR; + + for (int i=0; i < nSubKeys; i++) + { + _ret = closeKey(phSubKeys[i]); + } + + rtl_freeMemory(phSubKeys); + return _ret; +} + + +//********************************************************************* +// closeKey +// +RegError ORegKey::closeKey(RegKeyHandle hKey) +{ + return (m_pRegistry->closeKey(hKey)); +} + + +//********************************************************************* +// deleteKey +// +RegError ORegKey::deleteKey(const OUString& keyName) +{ + return (m_pRegistry->deleteKey(this, keyName)); +} + + +//********************************************************************* +// getValueType +// +RegError ORegKey::getValueInfo(const OUString& valueName, RegValueType* pValueType, sal_uInt32* pValueSize) const +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + storeAccessMode accessMode = VALUE_MODE_OPEN; + + if (m_pRegistry->isReadOnly()) + { + accessMode = VALUE_MODE_OPENREAD; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if ( rValue.create(m_storeFile, m_name + m_pRegistry->ROOT, sImplValueName, accessMode) ) + { + *pValueType = RG_VALUETYPE_NOT_DEFINED; + *pValueSize = 0; + return REG_VALUE_NOT_EXISTS; + } + + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE); + + sal_uInt32 readBytes; + if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) ) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != VALUE_HEADERSIZE) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt32 size; + sal_uInt8 type = *((sal_uInt8*)pBuffer); + readUINT32(pBuffer+VALUE_TYPEOFFSET, size); + + *pValueType = (RegValueType)type; +// if (*pValueType == RG_VALUETYPE_UNICODE) +// { +// *pValueSize = (size / 2) * sizeof(sal_Unicode); +// } else +// { + if (*pValueType > 4) + { + rtl_freeMemory(pBuffer); + pBuffer = (sal_uInt8*)rtl_allocateMemory(4); + rValue.readAt(VALUE_HEADEROFFSET, pBuffer, 4, readBytes); + + readUINT32(pBuffer, size); + } + + *pValueSize = size; +// } + + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + + +//********************************************************************* +// setValue +// +RegError ORegKey::setValue(const OUString& valueName, RegValueType vType, RegValue value, sal_uInt32 vSize) +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + + if (m_pRegistry->isReadOnly()) + { + return REG_REGISTRY_READONLY; + } + + if (vType > 4) + { + return REG_INVALID_VALUE; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if ( rValue.create(m_storeFile, m_name + m_pRegistry->ROOT , sImplValueName, VALUE_MODE_CREATE) ) + { + return REG_SET_VALUE_FAILED; + } + + sal_uInt32 size = vSize; + +// if (vType == RG_VALUETYPE_UNICODE) +// { +// size = (rtl_ustr_getLength((sal_Unicode*)value)+1) * 2; +// } + + sal_uInt8 type = (sal_uInt8)vType; + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size); + rtl_copyMemory(pBuffer, &type, 1); + + writeUINT32(pBuffer+VALUE_TYPEOFFSET, size); + + switch (vType) + { + case RG_VALUETYPE_NOT_DEFINED: + rtl_copyMemory(pBuffer+VALUE_HEADEROFFSET, value, size); + break; + case RG_VALUETYPE_LONG: + writeINT32(pBuffer+VALUE_HEADEROFFSET, *((sal_Int32*)value)); + break; + case RG_VALUETYPE_STRING: + writeUtf8(pBuffer+VALUE_HEADEROFFSET, (const sal_Char*)value); + break; + case RG_VALUETYPE_UNICODE: + writeString(pBuffer+VALUE_HEADEROFFSET, (const sal_Unicode*)value); + break; + case RG_VALUETYPE_BINARY: + rtl_copyMemory(pBuffer+VALUE_HEADEROFFSET, value, size); + break; + } + + + sal_uInt32 writenBytes; + if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) ) + { + rtl_freeMemory(pBuffer); + return REG_SET_VALUE_FAILED; + } + if (writenBytes != (VALUE_HEADERSIZE+size)) + { + rtl_freeMemory(pBuffer); + return REG_SET_VALUE_FAILED; + } + + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// setLongListValue +// +RegError ORegKey::setLongListValue(const OUString& valueName, sal_Int32* pValueList, sal_uInt32 len) +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + + if (m_pRegistry->isReadOnly()) + { + return REG_REGISTRY_READONLY; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if (rValue.create(m_storeFile, m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) ) + { + return REG_SET_VALUE_FAILED; + } + + sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge + + size += len * 4; + + sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_LONGLIST; + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size); + rtl_copyMemory(pBuffer, &type, 1); + + writeUINT32(pBuffer+VALUE_TYPEOFFSET, size); + writeUINT32(pBuffer+VALUE_HEADEROFFSET, len); + + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays + + for (int i=0; i < len; i++) + { + writeINT32(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]); + offset += 4; + } + + sal_uInt32 writenBytes; + if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) ) + { + rtl_freeMemory(pBuffer); + return REG_SET_VALUE_FAILED; + } + if (writenBytes != (VALUE_HEADEROFFSET+size)) + { + rtl_freeMemory(pBuffer); + return REG_SET_VALUE_FAILED; + } + + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// setStringListValue +// +RegError ORegKey::setStringListValue(const OUString& valueName, sal_Char** pValueList, sal_uInt32 len) +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + + if (m_pRegistry->isReadOnly()) + { + return REG_REGISTRY_READONLY; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if (rValue.create(m_storeFile, m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) ) + { + return REG_SET_VALUE_FAILED; + } + + sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge + + int i; + for (i=0; i < len; i++) + { + size += 4 + strlen(pValueList[i]) + 1; + } + + sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_STRINGLIST; + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size); + rtl_copyMemory(pBuffer, &type, 1); + + writeUINT32(pBuffer+VALUE_TYPEOFFSET, size); + writeUINT32(pBuffer+VALUE_HEADEROFFSET, len); + + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays; + sal_uInt32 sLen = 0; + + for (i=0; i < len; i++) + { + sLen = strlen(pValueList[i]) + 1; + writeUINT32(pBuffer+VALUE_HEADEROFFSET+offset, sLen); + + offset += 4; + writeUtf8(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]); + offset += sLen; + } + + sal_uInt32 writenBytes; + if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) ) + { + rtl_freeMemory(pBuffer); + return REG_SET_VALUE_FAILED; + } + if (writenBytes != (VALUE_HEADERSIZE+size)) + { + rtl_freeMemory(pBuffer); + return REG_SET_VALUE_FAILED; + } + + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// setUnicodeListValue +// +RegError ORegKey::setUnicodeListValue(const OUString& valueName, sal_Unicode** pValueList, sal_uInt32 len) +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + + if (m_pRegistry->isReadOnly()) + { + return REG_REGISTRY_READONLY; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if (rValue.create(m_storeFile, m_name + m_pRegistry->ROOT, sImplValueName, VALUE_MODE_CREATE) ) + { + return REG_SET_VALUE_FAILED; + } + + sal_uInt32 size = 4; // 4 Bytes (sal_uInt32) fuer die Laenge + + int i; + for (i=0; i < len; i++) + { + size += 4 + ((rtl_ustr_getLength(pValueList[i]) +1) * 2); + } + + sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_UNICODELIST; + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + size); + rtl_copyMemory(pBuffer, &type, 1); + + writeUINT32(pBuffer+VALUE_TYPEOFFSET, size); + writeUINT32(pBuffer+VALUE_HEADEROFFSET, len); + + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays; + sal_uInt32 sLen = 0; + + for (i=0; i < len; i++) + { + sLen = (rtl_ustr_getLength(pValueList[i]) + 1) * 2; + writeUINT32(pBuffer+VALUE_HEADEROFFSET+offset, sLen); + + offset += 4; + writeString(pBuffer+VALUE_HEADEROFFSET+offset, pValueList[i]); + offset += sLen; + } + + sal_uInt32 writenBytes; + if ( rValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+size, writenBytes) ) + { + rtl_freeMemory(pBuffer); + return REG_SET_VALUE_FAILED; + } + if (writenBytes != (VALUE_HEADERSIZE+size)) + { + rtl_freeMemory(pBuffer); + return REG_SET_VALUE_FAILED; + } + + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// getValue +// +RegError ORegKey::getValue(const OUString& valueName, RegValue value) const +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + RegValueType valueType; + sal_uInt32 valueSize; + storeAccessMode accessMode = VALUE_MODE_OPEN; + + if (m_pRegistry->isReadOnly()) + { + accessMode = VALUE_MODE_OPENREAD; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if (rValue.create(m_storeFile, m_name + m_pRegistry->ROOT, sImplValueName, accessMode) ) + { + return REG_VALUE_NOT_EXISTS; + } + + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE); + + sal_uInt32 readBytes; + if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) ) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != VALUE_HEADERSIZE) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt8 type = *((sal_uInt8*)pBuffer); + valueType = (RegValueType)type; + readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize); + + rtl_freeMemory(pBuffer); + + if (valueType > 4) + { + return REG_INVALID_VALUE; + } + + pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + + if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) ) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != valueSize) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + +// rtl_copyMemory(value, pBuffer, valueSize); + switch (valueType) + { + case RG_VALUETYPE_NOT_DEFINED: + rtl_copyMemory(value, pBuffer, valueSize); + break; + case RG_VALUETYPE_LONG: + readINT32(pBuffer, *((sal_Int32*)value)); + break; + case RG_VALUETYPE_STRING: + readUtf8(pBuffer, (sal_Char*)value, valueSize); + break; + case RG_VALUETYPE_UNICODE: + readString(pBuffer, (sal_Unicode*)value, valueSize); + break; + case RG_VALUETYPE_BINARY: + rtl_copyMemory(value, pBuffer, valueSize); + break; + case RG_VALUETYPE_LONGLIST: + case RG_VALUETYPE_STRINGLIST: + case RG_VALUETYPE_UNICODELIST: + rtl_copyMemory(value, pBuffer, valueSize); + break; + } + + + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// getLongListValue +// +RegError ORegKey::getLongListValue(const OUString& valueName, sal_Int32** pValueList, sal_uInt32* pLen) const +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + RegValueType valueType; + sal_uInt32 valueSize; + storeAccessMode accessMode = VALUE_MODE_OPEN; + + if (m_pRegistry->isReadOnly()) + { + accessMode = VALUE_MODE_OPENREAD; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if (rValue.create(m_storeFile, m_name + m_pRegistry->ROOT, sImplValueName, accessMode) ) + { + pValueList = NULL; + *pLen = 0; + return REG_VALUE_NOT_EXISTS; + } + + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE); + + sal_uInt32 readBytes; + if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) ) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != VALUE_HEADERSIZE) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt8 type = *((sal_uInt8*)pBuffer); + valueType = (RegValueType)type; + + if (valueType != RG_VALUETYPE_LONGLIST) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize); + + rtl_freeMemory(pBuffer); + + pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + + if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) ) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != valueSize) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt32 len = 0; + readUINT32(pBuffer, len); + + *pLen = len; + sal_Int32* pVList = (sal_Int32*)rtl_allocateZeroMemory(len * sizeof(sal_Int32)); + + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays; + + for (int i=0; i < len; i++) + { + readINT32(pBuffer+offset, pVList[i]); + offset += 4; + } + + *pValueList = pVList; + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// getStringListValue +// +RegError ORegKey::getStringListValue(const OUString& valueName, sal_Char*** pValueList, sal_uInt32* pLen) const +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + RegValueType valueType; + sal_uInt32 valueSize; + storeAccessMode accessMode = VALUE_MODE_OPEN; + + if (m_pRegistry->isReadOnly()) + { + accessMode = VALUE_MODE_OPENREAD; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if ( rValue.create(m_storeFile, m_name + m_pRegistry->ROOT, sImplValueName, accessMode) ) + { + pValueList = NULL; + *pLen = 0; + return REG_VALUE_NOT_EXISTS; + } + + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE); + + sal_uInt32 readBytes; + if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) ) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != VALUE_HEADERSIZE) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt8 type = *((sal_uInt8*)pBuffer); + valueType = (RegValueType)type; + + if (valueType != RG_VALUETYPE_STRINGLIST) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize); + + rtl_freeMemory(pBuffer); + + pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + + if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) ) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != valueSize) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt32 len = 0; + readUINT32(pBuffer, len); + + *pLen = len; + sal_Char** pVList = (sal_Char**)rtl_allocateZeroMemory(len * sizeof(sal_Char*)); + + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays; + sal_uInt32 sLen = 0; + + sal_Char *pValue; + for (int i=0; i < len; i++) + { + readUINT32(pBuffer+offset, sLen); + + offset += 4; + + pValue = (sal_Char*)rtl_allocateMemory(sLen); + readUtf8(pBuffer+offset, pValue, sLen); + pVList[i] = pValue; + + offset += sLen; + } + + *pValueList = pVList; + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// getUnicodeListValue +// +RegError ORegKey::getUnicodeListValue(const OUString& valueName, sal_Unicode*** pValueList, sal_uInt32* pLen) const +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + RegValueType valueType; + sal_uInt32 valueSize; + storeAccessMode accessMode = VALUE_MODE_OPEN; + + if (m_pRegistry->isReadOnly()) + { + accessMode = VALUE_MODE_OPENREAD; + } + + OUString sImplValueName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + sImplValueName += valueName; + + REG_GUARD(m_pRegistry->m_mutex); + + if ( rValue.create(m_storeFile, m_name + m_pRegistry->ROOT, sImplValueName, accessMode) ) + { + pValueList = NULL; + *pLen = 0; + return REG_VALUE_NOT_EXISTS; + } + + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE); + + sal_uInt32 readBytes; + if ( rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, readBytes) ) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != VALUE_HEADERSIZE) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt8 type = *((sal_uInt8*)pBuffer); + valueType = (RegValueType)type; + + if (valueType != RG_VALUETYPE_UNICODELIST) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize); + + rtl_freeMemory(pBuffer); + + pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + + if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, readBytes) ) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (readBytes != valueSize) + { + pValueList = NULL; + *pLen = 0; + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt32 len = 0; + readUINT32(pBuffer, len); + + *pLen = len; + sal_Unicode** pVList = (sal_Unicode**)rtl_allocateZeroMemory(len * sizeof(sal_Unicode*)); + + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays; + sal_uInt32 sLen = 0; + + sal_Unicode *pValue; + for (int i=0; i < len; i++) + { + readUINT32(pBuffer+offset, sLen); + + offset += 4; + + pValue = (sal_Unicode*)rtl_allocateMemory((sLen / 2) * sizeof(sal_Unicode)); + readString(pBuffer+offset, pValue, sLen); + pVList[i] = pValue; + + offset += sLen; + } + + *pValueList = pVList; + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// getKeyType() +// +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() ) + { + if ((_ret = ((ORegKey*)this)->openKey(name, (RegKeyHandle*)&pKey, RESOLVE_PART))) + return _ret; + + if (pKey->isLink()) + *pKeyType = RG_LINKTYPE; + + ((ORegKey*)this)->closeKey((RegKeyHandle)pKey); + return _ret; + } else + { + if (m_isLink) + *pKeyType = RG_LINKTYPE; + + return _ret; + } +} + +//********************************************************************* +// createLink() +// +RegError ORegKey::createLink(const OUString& linkName, const OUString& linkTarget) +{ + ORegKey* pKey; + RegError _ret = REG_NO_ERROR; + + if ( !linkName.getLength() ) + return REG_INVALID_LINKNAME; + + if ( !linkTarget.getLength() ) + return REG_INVALID_LINKTARGET; + + REG_GUARD(m_pRegistry->m_mutex); + + if (m_pRegistry->openKey(this, linkName, (RegKeyHandle*)&pKey, RESOLVE_PART)) + { + if (_ret = m_pRegistry->createKey(this, linkName, (RegKeyHandle*)&pKey)) + return _ret; + } else + { + if (!pKey->isLink()) + { + m_pRegistry->closeKey(pKey); + return REG_INVALID_LINK; + } + } + + if (_ret = pKey->setValue(OUString( RTL_CONSTASCII_USTRINGPARAM("LINK_TARGET") ), + RG_VALUETYPE_UNICODE, (RegValue)linkTarget.getStr(), (linkTarget.getLength()+1)*2)) + { + m_pRegistry->closeKey(pKey); + _ret = m_pRegistry->deleteKey(this, linkName); + return _ret; + } + + return m_pRegistry->closeKey(pKey); +} + +//********************************************************************* +// deleteLink() +// +RegError ORegKey::deleteLink(const OUString& linkName) +{ + return (m_pRegistry->deleteLink(this, linkName)); +} + +//********************************************************************* +// getLinkTarget() +// +RegError ORegKey::getLinkTarget(const OUString& linkName, OUString& linkTarget) const +{ + ORegKey* pKey; + RegError _ret = REG_NO_ERROR; + + REG_GUARD(m_pRegistry->m_mutex); + + if ( linkName.getLength() ) + { + if (_ret = ((ORegKey*)this)->openKey(linkName, (RegKeyHandle*)&pKey, RESOLVE_PART)) + return REG_INVALID_LINK; + + _ret = pKey->getLinkTarget(OUString(), linkTarget); + ((ORegKey*)this)->closeKey((RegKeyHandle)pKey); + return _ret; + } else + { + if (m_isLink) + { + linkTarget = m_link; + return REG_NO_ERROR; + } else + return REG_LINKTARGET_NOT_EXIST; + } +} + +RegError ORegKey::getResolvedKeyName(const OUString& keyName, + OUString& resolvedName, + sal_Bool firstLinkOnly) +{ + return m_pRegistry->getResolvedKeyName((ORegKey*)this, keyName, resolvedName, firstLinkOnly); +} + +//********************************************************************* +// countSubKeys() +// +sal_uInt32 ORegKey::countSubKeys() +{ + REG_GUARD(m_pRegistry->m_mutex); + + OStoreDirectory::iterator iter; + OStoreDirectory rStoreDir = getStoreDir(); + storeError _err = rStoreDir.first(iter); + sal_uInt32 count = 0; + + while ( _err == store_E_None ) + { + if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR ) + { + count++; + } + + _err = rStoreDir.next(iter); + } + + return count; +} + + +//********************************************************************* +// checkLink() +// +sal_Bool ORegKey::checkLink() +{ + RegValueType valueType = RG_VALUETYPE_NOT_DEFINED; + sal_uInt32 valueSize = 0; + + OUString linkTarget( OUString( RTL_CONSTASCII_USTRINGPARAM("LINK_TARGET") )); + if (!((ORegKey*)this)->getValueInfo( linkTarget, &valueType, &valueSize)) + { + sal_Unicode* value = (sal_Unicode*)rtl_allocateMemory(valueSize); + if (!((ORegKey*)this)->getValue( linkTarget, value)) + { + m_link = OUString(value); + m_isLink = sal_True; + } + + rtl_freeMemory(value); + + return sal_True; + } + + return sal_False; +} + +OStoreDirectory ORegKey::getStoreDir() +{ + OStoreDirectory rStoreDir; + OUString fullPath; + OUString relativName; + storeAccessMode accessMode = KEY_MODE_OPEN; + + if ( m_name.equals(m_pRegistry->ROOT) ) + { + fullPath = OUString(); + relativName = OUString(); + } else + { + fullPath = m_name.copy(0, m_name.lastIndexOf('/') + 1); + relativName = m_name.copy(m_name.lastIndexOf('/') + 1); + } + + if (m_pRegistry->isReadOnly()) + { + accessMode = KEY_MODE_OPENREAD; + } + + rStoreDir.create(m_storeFile, fullPath, relativName, accessMode); + + return rStoreDir; +} + diff --git a/registry/source/keyimpl.hxx b/registry/source/keyimpl.hxx new file mode 100644 index 000000000000..17a638026980 --- /dev/null +++ b/registry/source/keyimpl.hxx @@ -0,0 +1,215 @@ +/************************************************************************* + * + * $RCSfile: keyimpl.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _KEYIMPL_HXX_ +#define _KEYIMPL_HXX_ + +#ifndef _REGISTRY_REGISTRY_H_ +#include <registry/registry.h> +#endif + +#ifndef _REGIMPL_HXX_ +#include "regimpl.hxx" +#endif + +#ifndef _RTL_STRING_HXX_ +#include <rtl/string.hxx> +#endif + +using namespace rtl; +using namespace store; + +class ORegKey +{ +public: + + ORegKey(const OUString& keyName, const OStoreDirectory& rStoreDir, ORegistry* pReg); + ORegKey(const OUString& keyName, const OUString& linkName, + const OStoreDirectory& rStoreDir, ORegistry* pReg); + + sal_uInt32 acquire() + { return ++m_refCount; } + + sal_uInt32 release() + { return --m_refCount; } + + RegError createKey(const OUString& keyName, RegKeyHandle* phNewKey); + + RegError openKey(const OUString& keyName, RegKeyHandle* phOpenKey, + RESOLVE eResolve=RESOLVE_FULL); + + RegError openSubKeys(const OUString& keyName, + RegKeyHandle** phOpenSubKeys, + sal_uInt32* pnSubKeys); + + RegError getKeyNames(const OUString& keyName, + rtl_uString*** pSubKeyNames, + sal_uInt32* pnSubKeys); + + RegError closeSubKeys(RegKeyHandle* phSubKeys, sal_uInt32 len); + + RegError closeKey(RegKeyHandle hKey); + + RegError deleteKey(const OUString& keyName); + + RegError getValueInfo(const OUString& valueName, + RegValueType* pValueTye, + sal_uInt32* pValueSize) const; + + RegError setValue(const OUString& valueName, + RegValueType vType, + RegValue value, + sal_uInt32 vSize); + + RegError setLongListValue(const OUString& valueName, + sal_Int32* pValueList, + sal_uInt32 len); + + RegError setStringListValue(const OUString& valueName, + sal_Char** pValueList, + sal_uInt32 len); + + RegError setUnicodeListValue(const OUString& valueName, + sal_Unicode** pValueList, + sal_uInt32 len); + + RegError getValue(const OUString& valueName, RegValue value) const; + + RegError getLongListValue(const OUString& valueName, + sal_Int32** pValueList, + sal_uInt32* pLen) const; + + RegError getStringListValue(const OUString& valueName, + sal_Char*** pValueList, + sal_uInt32* pLen) const; + + RegError getUnicodeListValue(const OUString& valueName, + sal_Unicode*** pValueList, + sal_uInt32* pLen) const; + + RegError createLink(const OUString& linkName, const OUString& linkTarget); + + RegError deleteLink(const OUString& linkName); + + RegError getKeyType(const OUString& name, + RegKeyType* pKeyType) const; + + RegError getLinkTarget(const OUString& linkName, + OUString& pLinkTarget) const; + + RegError getResolvedKeyName(const OUString& keyName, + OUString& resolvedName, + sal_Bool firstLinkOnly=sal_False); + +public: + ORegKey(); + virtual ~ORegKey(); + + + sal_Bool isDeleted() const + { return m_bDeleted; } + + void setDeleted(sal_Bool bKeyDeleted) + { m_bDeleted = bKeyDeleted; } + + sal_Bool isReadOnly() const + { return m_pRegistry->isReadOnly(); } + + sal_uInt32 countSubKeys(); + + sal_Bool isLink() const + { return m_isLink; } + + const OUString& getLinkTarget() const + { return m_link; } + + ORegistry* getRegistry() const + { return m_pRegistry; } + + const OStoreFile& getStoreFile() const + { return m_storeFile; } + + OStoreDirectory getStoreDir(); + + const OUString& getName() const + { return m_name; } + + sal_uInt32 getRefCount() const + { return m_refCount; } + + friend class ORegistry; +protected: + sal_Bool checkLink(); + + sal_uInt32 m_refCount; + OUString m_name; + OUString m_link; + sal_Bool m_bDeleted; + sal_Bool m_isLink; + ORegistry* m_pRegistry; + OStoreFile m_storeFile; +}; + + + +#endif + + diff --git a/registry/source/makefile.mk b/registry/source/makefile.mk new file mode 100644 index 000000000000..93a3ba530111 --- /dev/null +++ b/registry/source/makefile.mk @@ -0,0 +1,97 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=.. + +PRJNAME=registry +TARGET=regcpp + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk +.INCLUDE : ..$/version.mk + +# ------------------------------------------------------------------ + +SLOFILES= \ + $(SLO)$/regimpl.obj \ + $(SLO)$/regkey.obj \ + $(SLO)$/registry.obj \ + $(SLO)$/keyimpl.obj \ + $(SLO)$/reflread.obj \ + $(SLO)$/reflwrit.obj + + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmb.obj +OBJFILES+=$(OBJ)$/staticmb.obj +.ENDIF + +# ------------------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/registry/source/reflcnst.hxx b/registry/source/reflcnst.hxx new file mode 100644 index 000000000000..a57addcce1cc --- /dev/null +++ b/registry/source/reflcnst.hxx @@ -0,0 +1,268 @@ +/************************************************************************* + * + * $RCSfile: reflcnst.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef __REFLCNST_HXX__ +#define __REFLCNST_HXX__ + +#ifndef __REGISTRY_REFLTYPE_HXX__ +#include <registry/refltype.hxx> +#endif + +#include <string.h> +#include <vos/macros.hxx> + +#define REGTYPE_IEEE_NATIVE 1 + +extern const sal_uInt32 magic; +extern const sal_uInt16 minorVersion; +extern const sal_uInt16 majorVersion; + +#define OFFSET_MAGIC 0 +#define OFFSET_SIZE (OFFSET_MAGIC + sizeof(magic)) +#define OFFSET_MINOR_VERSION (OFFSET_SIZE + sizeof(sal_uInt32)) +#define OFFSET_MAJOR_VERSION (OFFSET_MINOR_VERSION + sizeof(minorVersion)) +#define OFFSET_TYPE_CLASS (OFFSET_MAJOR_VERSION + sizeof(majorVersion)) +#define OFFSET_THIS_TYPE (OFFSET_TYPE_CLASS + sizeof(sal_uInt16)) +#define OFFSET_SUPER_TYPE (OFFSET_THIS_TYPE + sizeof(sal_uInt16)) +#define OFFSET_UIK (OFFSET_SUPER_TYPE + sizeof(sal_uInt16)) +#define OFFSET_DOKU (OFFSET_UIK + sizeof(sal_uInt16)) +#define OFFSET_FILENAME (OFFSET_DOKU + sizeof(sal_uInt16)) +#define OFFSET_CP_SIZE (OFFSET_FILENAME + sizeof(sal_uInt16)) +#define OFFSET_CP (OFFSET_CP_SIZE + sizeof(sal_uInt16)) + +#define CP_OFFSET_ENTRY_SIZE 0 +#define CP_OFFSET_ENTRY_TAG (CP_OFFSET_ENTRY_SIZE + sizeof(sal_uInt16)) +#define CP_OFFSET_ENTRY_DATA (CP_OFFSET_ENTRY_TAG + sizeof(sal_uInt16)) +#define CP_OFFSET_ENTRY_UIK1 CP_OFFSET_ENTRY_DATA +#define CP_OFFSET_ENTRY_UIK2 (CP_OFFSET_ENTRY_UIK1 + sizeof(sal_uInt32)) +#define CP_OFFSET_ENTRY_UIK3 (CP_OFFSET_ENTRY_UIK2 + sizeof(sal_uInt16)) +#define CP_OFFSET_ENTRY_UIK4 (CP_OFFSET_ENTRY_UIK3 + sizeof(sal_uInt16)) +#define CP_OFFSET_ENTRY_UIK5 (CP_OFFSET_ENTRY_UIK4 + sizeof(sal_uInt32)) + +#define FIELD_OFFSET_ACCESS 0 +#define FIELD_OFFSET_NAME (FIELD_OFFSET_ACCESS + sizeof(sal_uInt16)) +#define FIELD_OFFSET_TYPE (FIELD_OFFSET_NAME + sizeof(sal_uInt16)) +#define FIELD_OFFSET_VALUE (FIELD_OFFSET_TYPE + sizeof(sal_uInt16)) +#define FIELD_OFFSET_DOKU (FIELD_OFFSET_VALUE + sizeof(sal_uInt16)) +#define FIELD_OFFSET_FILENAME (FIELD_OFFSET_DOKU + sizeof(sal_uInt16)) +#define FIELD_ENTRY_SIZE (FIELD_OFFSET_FILENAME + sizeof(sal_uInt16)) + +#define PARAM_OFFSET_TYPE 0 +#define PARAM_OFFSET_MODE (PARAM_OFFSET_TYPE + sizeof(sal_uInt16)) +#define PARAM_OFFSET_NAME (PARAM_OFFSET_MODE + sizeof(sal_uInt16)) +#define PARAM_ENTRY_SIZE (PARAM_OFFSET_NAME + sizeof(sal_uInt16)) + +#define METHOD_OFFSET_SIZE 0 +#define METHOD_OFFSET_MODE (METHOD_OFFSET_SIZE + sizeof(sal_uInt16)) +#define METHOD_OFFSET_NAME (METHOD_OFFSET_MODE + sizeof(sal_uInt16)) +#define METHOD_OFFSET_RETURN (METHOD_OFFSET_NAME + sizeof(sal_uInt16)) +#define METHOD_OFFSET_DOKU (METHOD_OFFSET_RETURN + sizeof(sal_uInt16)) +#define METHOD_OFFSET_PARAM_COUNT (METHOD_OFFSET_DOKU + sizeof(sal_uInt16)) +#define METHOD_OFFSET_PARAM(i) (METHOD_OFFSET_PARAM_COUNT + sizeof(sal_uInt16) + (i * PARAM_ENTRY_SIZE)) + +#define REFERENCE_OFFSET_TYPE 0 +#define REFERENCE_OFFSET_NAME (REFERENCE_OFFSET_TYPE + sizeof(sal_uInt16)) +#define REFERENCE_OFFSET_DOKU (REFERENCE_OFFSET_NAME + sizeof(sal_uInt16)) +#define REFERENCE_OFFSET_ACCESS (REFERENCE_OFFSET_DOKU + sizeof(sal_uInt16)) +#define REFERENCE_ENTRY_SIZE (REFERENCE_OFFSET_ACCESS + sizeof(sal_uInt16)) + +enum CPInfoTag +{ + CP_TAG_INVALID = RT_TYPE_NONE, + CP_TAG_CONST_BOOL = RT_TYPE_BOOL, + CP_TAG_CONST_BYTE = RT_TYPE_BYTE, + CP_TAG_CONST_INT16 = RT_TYPE_INT16, + CP_TAG_CONST_UINT16 = RT_TYPE_UINT16, + CP_TAG_CONST_INT32 = RT_TYPE_INT32, + CP_TAG_CONST_UINT32 = RT_TYPE_UINT32, + CP_TAG_CONST_INT64 = RT_TYPE_INT64, + CP_TAG_CONST_UINT64 = RT_TYPE_UINT64, + CP_TAG_CONST_FLOAT = RT_TYPE_FLOAT, + CP_TAG_CONST_DOUBLE = RT_TYPE_DOUBLE, + CP_TAG_CONST_STRING = RT_TYPE_STRING, + CP_TAG_UTF8_NAME, + CP_TAG_UIK +}; + +inline sal_uInt32 writeBYTE(sal_uInt8* buffer, sal_uInt8 v) +{ + buffer[0] = v; + + return sizeof(sal_uInt8); +} + +inline sal_uInt16 readBYTE(const sal_uInt8* buffer, sal_uInt8& v) +{ + v = buffer[0]; + + return sizeof(sal_uInt8); +} + +inline sal_uInt32 writeINT16(sal_uInt8* buffer, sal_Int16 v) +{ + buffer[0] = (sal_uInt8)((v >> 8) & 0xFF); + buffer[1] = (sal_uInt8)((v >> 0) & 0xFF); + + return sizeof(sal_Int16); +} + +inline sal_uInt32 readINT16(const sal_uInt8* buffer, sal_Int16& v) +{ + v = ((buffer[0] << 8) | (buffer[1] << 0)); + + return sizeof(sal_Int16); +} + +inline sal_uInt32 writeUINT16(sal_uInt8* buffer, sal_uInt16 v) +{ + buffer[0] = (sal_uInt8)((v >> 8) & 0xFF); + buffer[1] = (sal_uInt8)((v >> 0) & 0xFF); + + return sizeof(sal_uInt16); +} + +inline sal_uInt32 readUINT16(const sal_uInt8* buffer, sal_uInt16& v) +{ + v = ((buffer[0] << 8) | (buffer[1] << 0)); + + return sizeof(sal_uInt16); +} + +inline sal_uInt32 writeINT32(sal_uInt8* buffer, sal_Int32 v) +{ + buffer[0] = (sal_uInt8)((v >> 24) & 0xFF); + buffer[1] = (sal_uInt8)((v >> 16) & 0xFF); + buffer[2] = (sal_uInt8)((v >> 8) & 0xFF); + buffer[3] = (sal_uInt8)((v >> 0) & 0xFF); + + return sizeof(sal_Int32); +} + +inline sal_uInt32 readINT32(const sal_uInt8* buffer, sal_Int32& v) +{ + v = ( + (buffer[0] << 24) | + (buffer[1] << 16) | + (buffer[2] << 8) | + (buffer[3] << 0) + ); + + return sizeof(sal_Int32); +} + +inline sal_uInt32 writeUINT32(sal_uInt8* buffer, sal_uInt32 v) +{ + buffer[0] = (sal_uInt8)((v >> 24) & 0xFF); + buffer[1] = (sal_uInt8)((v >> 16) & 0xFF); + buffer[2] = (sal_uInt8)((v >> 8) & 0xFF); + buffer[3] = (sal_uInt8)((v >> 0) & 0xFF); + + return sizeof(sal_uInt32); +} + +inline sal_uInt32 readUINT32(const sal_uInt8* buffer, sal_uInt32& v) +{ + v = ( + (buffer[0] << 24) | + (buffer[1] << 16) | + (buffer[2] << 8) | + (buffer[3] << 0) + ); + + return sizeof(sal_uInt32); +} + +inline sal_uInt32 writeUtf8(sal_uInt8* buffer, const sal_Char* v) +{ + sal_uInt32 size = strlen(v) + 1; + + memcpy(buffer, v, size); + + return (size); +} + +inline sal_uInt32 readUtf8(const sal_uInt8* buffer, sal_Char* v, sal_uInt32 maxSize) +{ + sal_uInt32 size = VOS_MIN(strlen((const sal_Char*) buffer) + 1, maxSize); + + memcpy(v, buffer, size); + + if (size == maxSize) v[size - 1] = '\0'; + + return (size); +} + + +sal_uInt32 writeFloat(sal_uInt8* buffer, float v); +sal_uInt32 readFloat(const sal_uInt8* buffer, float& v); +sal_uInt32 writeDouble(sal_uInt8* buffer, double v); +sal_uInt32 readDouble(const sal_uInt8* buffer, double& v); +sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v); +sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize); + +sal_uInt32 UINT16StringLen(const sal_uInt8* wstring); + +#endif + + + + + diff --git a/registry/source/reflread.cxx b/registry/source/reflread.cxx new file mode 100644 index 000000000000..cb462132db24 --- /dev/null +++ b/registry/source/reflread.cxx @@ -0,0 +1,1602 @@ +/************************************************************************* + * + * $RCSfile: reflread.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef MAC +#include <memory.h> +#endif +#include <osl/types.h> + +#include <registry/reflread.hxx> +#include "reflcnst.hxx" + +using namespace vos; + +static CPInfoTag aTag; + +static sal_Char NULL_STRING[1] = { 0 }; +static sal_Unicode NULL_WSTRING[1] = { 0 }; + +const sal_uInt32 magic = 0x12345678; +const sal_uInt16 minorVersion = 0x0000; +const sal_uInt16 majorVersion = 0x0001; + +#if defined ( GCC ) && ( defined ( SCO ) || defined ( NETBSD ) ) +ORealDynamicLoader* ODynamicLoader<RegistryTypeReader_Api>::m_pLoader = NULL; +#endif + +/************************************************************************** + + class BlopObject + + holds any data in a flat memory buffer + +**************************************************************************/ + +class BlopObject +{ +public: + const sal_uInt8* m_pBuffer; + sal_uInt32 m_bufferLen; + sal_Bool m_isCopied; + + BlopObject(const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer); + ~BlopObject(); + + inline sal_uInt8 readBYTE(sal_uInt32 index) const + { + return m_pBuffer[index]; + } + + inline sal_Int16 readINT16(sal_uInt32 index) const + { + return ((m_pBuffer[index] << 8) | (m_pBuffer[index+1] << 0)); + } + + inline sal_uInt16 readUINT16(sal_uInt32 index) const + { + return ((m_pBuffer[index] << 8) | (m_pBuffer[index+1] << 0)); + } + + inline sal_Int32 readINT32(sal_uInt32 index) const + { + return ( + (m_pBuffer[index] << 24) | + (m_pBuffer[index+1] << 16) | + (m_pBuffer[index+2] << 8) | + (m_pBuffer[index+3] << 0) + ); + } + + inline sal_uInt32 readUINT32(sal_uInt32 index) const + { + return ( + (m_pBuffer[index] << 24) | + (m_pBuffer[index+1] << 16) | + (m_pBuffer[index+2] << 8) | + (m_pBuffer[index+3] << 0) + ); + } +}; + +BlopObject::BlopObject(const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer) + : m_isCopied(copyBuffer) + , m_bufferLen(len) +{ + if (m_isCopied) + { + sal_uInt8* newBuffer = new sal_uInt8[len]; + memcpy(newBuffer, buffer, len); + m_pBuffer = newBuffer; + } + else + { + m_pBuffer = buffer; + } +} + +BlopObject::~BlopObject() +{ + if (m_isCopied && m_pBuffer) + { +#ifdef OS2 + delete (sal_uInt8 *)m_pBuffer; +#else + delete[] const_cast<sal_uInt8*>(m_pBuffer); +#endif + } +} + +/************************************************************************** + + class StringCache + +**************************************************************************/ + +class StringCache +{ +public: + sal_Unicode** m_stringTable; + sal_uInt16 m_numOfStrings; + sal_uInt16 m_stringsCopied; + + StringCache(sal_uInt16 size); + ~StringCache(); + + const sal_Unicode* getString(sal_uInt16 index); + sal_uInt16 createString(const sal_uInt8* buffer); +}; + +StringCache::StringCache(sal_uInt16 size) + : m_numOfStrings(size) + , m_stringsCopied(0) + , m_stringTable(NULL) +{ + m_stringTable = new sal_Unicode*[m_numOfStrings]; + + for (sal_uInt16 i = 0; i < m_numOfStrings; i++) + { + m_stringTable[i] = NULL; + } +} + +StringCache::~StringCache() +{ + if (m_stringTable) + { + for (sal_uInt16 i = 0; i < m_stringsCopied; i++) + { + delete[] m_stringTable[i]; + } + + delete[] m_stringTable; + } +} + +const sal_Unicode* StringCache::getString(sal_uInt16 index) +{ + if ((index > 0) && (index <= m_stringsCopied)) + return m_stringTable[index - 1]; + else + return NULL; +} + +sal_uInt16 StringCache::createString(const sal_uInt8* buffer) +{ + if (m_stringsCopied < m_numOfStrings) + { + sal_uInt32 len = UINT16StringLen(buffer); + + m_stringTable[m_stringsCopied] = new sal_Unicode[len + 1]; + + readString(buffer, m_stringTable[m_stringsCopied], (len + 1) * sizeof(sal_Unicode)); + + return ++m_stringsCopied; + } + else + return 0; +} + +/************************************************************************** + + class ConstantPool + +**************************************************************************/ + +class ConstantPool : public BlopObject +{ +public: + + sal_uInt16 m_numOfEntries; + sal_Int32* m_pIndex; // index values may be < 0 for cached string constants + + StringCache* m_pStringCache; + + ConstantPool(const sal_uInt8* buffer, sal_uInt16 numEntries) + : BlopObject(buffer, 0, sal_False) + , m_numOfEntries(numEntries) + , m_pIndex(NULL) + , m_pStringCache(NULL) + { + } + + ~ConstantPool(); + + sal_uInt32 parseIndex(); + + CPInfoTag readTag(sal_uInt16 index); + + const sal_Char* readUTF8NameConstant(sal_uInt16 index); + sal_Bool readBOOLConstant(sal_uInt16 index); + sal_uInt8 readBYTEConstant(sal_uInt16 index); + sal_Int16 readINT16Constant(sal_uInt16 index); + sal_uInt16 readUINT16Constant(sal_uInt16 index); + sal_Int32 readINT32Constant(sal_uInt16 index); + sal_uInt32 readUINT32Constant(sal_uInt16 index); + float readFloatConstant(sal_uInt16 index); + double readDoubleConstant(sal_uInt16 index); + const sal_Unicode* readStringConstant(sal_uInt16 index); + void readUIK(sal_uInt16 index, RTUik* uik); +}; + +ConstantPool::~ConstantPool() +{ + if (m_pIndex) delete[] m_pIndex; + + if (m_pStringCache) + { + delete m_pStringCache; + } +} + +sal_uInt32 ConstantPool::parseIndex() +{ + if (m_pIndex) + { + delete[] m_pIndex; + m_pIndex = NULL; + } + + if (m_pStringCache) + { + delete m_pStringCache; + m_pStringCache = NULL; + } + + sal_uInt32 offset = 0; + sal_uInt16 numOfStrings = 0; + + if (m_numOfEntries) + { + m_pIndex = new sal_Int32[m_numOfEntries]; + + for (int i = 0; i < m_numOfEntries; i++) + { + m_pIndex[i] = (sal_Int32) offset; + + offset += readUINT16(offset); + + if ( + ((CPInfoTag) readUINT16(m_pIndex[i] + CP_OFFSET_ENTRY_TAG)) == + CP_TAG_CONST_STRING + ) + { + numOfStrings++; + } + + } + } + + if (numOfStrings) + { + m_pStringCache = new StringCache(numOfStrings); + } + + m_bufferLen = offset; + + return offset; +} + +CPInfoTag ConstantPool::readTag(sal_uInt16 index) +{ + CPInfoTag tag = CP_TAG_INVALID; + + if (m_pIndex && (index > 0) && (index <= m_numOfEntries)) + { + tag = (CPInfoTag) readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG); + } + + return tag; +} + +const sal_Char* ConstantPool::readUTF8NameConstant(sal_uInt16 index) +{ + const sal_Char* aName = NULL_STRING; + + if (m_pIndex && (index > 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_UTF8_NAME) + { + aName = (const sal_Char*) (m_pBuffer + m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + } + } + + return aName; +} + +sal_Bool ConstantPool::readBOOLConstant(sal_uInt16 index) +{ + sal_Bool aBool = sal_False; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_BOOL) + { + aBool = (sal_Bool) readBYTE(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + } + } + + return aBool; +} + +sal_uInt8 ConstantPool::readBYTEConstant(sal_uInt16 index) +{ + sal_uInt8 aByte = sal_False; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_BYTE) + { + aByte = readBYTE(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + } + } + + return aByte; +} + +sal_Int16 ConstantPool::readINT16Constant(sal_uInt16 index) +{ + sal_Int16 aINT16 = sal_False; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_INT16) + { + aINT16 = readINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + } + } + + return aINT16; +} + +sal_uInt16 ConstantPool::readUINT16Constant(sal_uInt16 index) +{ + sal_uInt16 asal_uInt16 = sal_False; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_UINT16) + { + asal_uInt16 = readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + } + } + + return asal_uInt16; +} + +sal_Int32 ConstantPool::readINT32Constant(sal_uInt16 index) +{ + sal_Int32 aINT32 = sal_False; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_INT32) + { + aINT32 = readINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + } + } + + return aINT32; +} + +sal_uInt32 ConstantPool::readUINT32Constant(sal_uInt16 index) +{ + sal_uInt32 aUINT32 = sal_False; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_UINT32) + { + aUINT32 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + } + } + + return aUINT32; +} + +float ConstantPool::readFloatConstant(sal_uInt16 index) +{ + union + { + float v; + sal_uInt32 b; + } x; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_FLOAT) + { +#ifdef REGTYPE_IEEE_NATIVE + x.b = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); +#else +# error no IEEE +#endif + } + } + + return x.v; +} + +double ConstantPool::readDoubleConstant(sal_uInt16 index) +{ + union + { + double v; + struct + { + sal_uInt32 b1; + sal_uInt32 b2; + } b; + } x; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_DOUBLE) + { + +#ifdef REGTYPE_IEEE_NATIVE +# ifdef OSL_BIGENDIAN + x.b.b1 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + x.b.b2 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA + sizeof(sal_uInt32)); +# else + x.b.b1 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA + sizeof(sal_uInt32)); + x.b.b2 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); +# endif +#else +# error no IEEE +#endif + } + } + + return x.v; +} + +const sal_Unicode* ConstantPool::readStringConstant(sal_uInt16 index) +{ + const sal_Unicode* aString = NULL_WSTRING; + + if (m_pIndex && (index> 0) && (index <= m_numOfEntries) && m_pStringCache) + { + if (m_pIndex[index - 1] >= 0) + { + // create cached string now + + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_STRING) + { + m_pIndex[index - 1] = -1 * m_pStringCache->createString(m_pBuffer + m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA); + } + } + + aString = m_pStringCache->getString((sal_uInt16) (m_pIndex[index - 1] * -1)); + } + + return aString; +} + +void ConstantPool::readUIK(sal_uInt16 index, RTUik* uik) +{ + if (index == 0) + { + uik->m_Data1 = 0; + uik->m_Data2 = 0; + uik->m_Data3 = 0; + uik->m_Data4 = 0; + uik->m_Data5 = 0; + } + else if (m_pIndex && (index <= m_numOfEntries)) + { + if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_UIK) + { + uik->m_Data1 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK1); + uik->m_Data2 = readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK2); + uik->m_Data3 = readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK3); + uik->m_Data4 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK4); + uik->m_Data5 = readUINT32(m_pIndex[index - 1] + CP_OFFSET_ENTRY_UIK5); + } + } +} + +/************************************************************************** + + class FieldList + +**************************************************************************/ + +class FieldList : public BlopObject +{ +public: + + sal_uInt16 m_numOfEntries; + ConstantPool* m_pCP; + + FieldList(const sal_uInt8* buffer, sal_uInt16 numEntries, ConstantPool* pCP) + : BlopObject(buffer, 0, sal_False) + , m_numOfEntries(numEntries) + , m_pCP(pCP) + { + } + + sal_uInt32 parseIndex(); + + const sal_Char* getFieldName(sal_uInt16 index); + const sal_Char* getFieldType(sal_uInt16 index); + RTFieldAccess getFieldAccess(sal_uInt16 index); + RTValueType getFieldConstValue(sal_uInt16 index, RTConstValueUnion* value); + const sal_Char* getFieldDoku(sal_uInt16 index); + const sal_Char* getFieldFileName(sal_uInt16 index); +}; + +sal_uInt32 FieldList::parseIndex() +{ + return (m_numOfEntries * (sizeof(sal_uInt16) * 6)); +} + +const sal_Char* FieldList::getFieldName(sal_uInt16 index) +{ + const sal_Char* aName = NULL; + + if (index <= m_numOfEntries) + { + aName = m_pCP->readUTF8NameConstant(readUINT16((index * FIELD_ENTRY_SIZE) + FIELD_OFFSET_NAME)); + } + + return aName; +} + +const sal_Char* FieldList::getFieldType(sal_uInt16 index) +{ + const sal_Char* aName = NULL; + + if (index <= m_numOfEntries) + { + aName = m_pCP->readUTF8NameConstant(readUINT16((index * FIELD_ENTRY_SIZE) + FIELD_OFFSET_TYPE)); + } + + return aName; +} + +RTFieldAccess FieldList::getFieldAccess(sal_uInt16 index) +{ + RTFieldAccess aAccess; + + if (index <= m_numOfEntries) + { + aAccess = (RTFieldAccess) readUINT16((index * FIELD_ENTRY_SIZE) + FIELD_OFFSET_ACCESS); + } + + return aAccess; +} + +RTValueType FieldList::getFieldConstValue(sal_uInt16 index, RTConstValueUnion* value) +{ + RTValueType ret = RT_TYPE_NONE; + + if (index <= m_numOfEntries) + { + sal_uInt16 cpIndex = readUINT16((index * FIELD_ENTRY_SIZE) + FIELD_OFFSET_VALUE); + + switch (m_pCP->readTag(cpIndex)) + { + case CP_TAG_CONST_BOOL: + value->aBool = m_pCP->readBOOLConstant(cpIndex); + ret = RT_TYPE_BOOL; + break; + case CP_TAG_CONST_BYTE: + value->aByte = m_pCP->readBYTEConstant(cpIndex); + ret = RT_TYPE_BYTE; + break; + case CP_TAG_CONST_INT16: + value->aShort = m_pCP->readINT16Constant(cpIndex); + ret = RT_TYPE_INT16; + break; + case CP_TAG_CONST_UINT16: + value->aUShort = m_pCP->readUINT16Constant(cpIndex); + ret = RT_TYPE_UINT16; + break; + case CP_TAG_CONST_INT32: + value->aLong = m_pCP->readINT32Constant(cpIndex); + ret = RT_TYPE_INT32; + break; + case CP_TAG_CONST_UINT32: + value->aULong = m_pCP->readUINT32Constant(cpIndex); + ret = RT_TYPE_UINT32; + break; + case CP_TAG_CONST_INT64: +// value->aHyper = m_pCP->readINT64Constant(cpIndex); + ret = RT_TYPE_INT64; + break; + case CP_TAG_CONST_UINT64: +// value->aUHyper = m_pCP->readUINT64Constant(cpIndex); + ret = RT_TYPE_UINT64; + break; + case CP_TAG_CONST_FLOAT: + value->aFloat = m_pCP->readFloatConstant(cpIndex); + ret = RT_TYPE_FLOAT; + break; + case CP_TAG_CONST_DOUBLE: + value->aDouble = m_pCP->readDoubleConstant(cpIndex); + ret = RT_TYPE_DOUBLE; + break; + case CP_TAG_CONST_STRING: + value->aString = m_pCP->readStringConstant(cpIndex); + ret = RT_TYPE_STRING; + break; + default: + break; + } + } + + return ret; +} + +const sal_Char* FieldList::getFieldDoku(sal_uInt16 index) +{ + const sal_Char* aDoku = NULL; + + if (index <= m_numOfEntries) + { + aDoku = m_pCP->readUTF8NameConstant(readUINT16((index * FIELD_ENTRY_SIZE) + FIELD_OFFSET_DOKU)); + } + + return aDoku; +} + +const sal_Char* FieldList::getFieldFileName(sal_uInt16 index) +{ + const sal_Char* aFileName = NULL; + + if (index <= m_numOfEntries) + { + aFileName = m_pCP->readUTF8NameConstant(readUINT16((index * FIELD_ENTRY_SIZE) + FIELD_OFFSET_FILENAME)); + } + + return aFileName; +} + +/************************************************************************** + + class ReferenceList + +**************************************************************************/ + +class ReferenceList : public BlopObject +{ +public: + + sal_uInt16 m_numOfEntries; + ConstantPool* m_pCP; + + ReferenceList(const sal_uInt8* buffer, sal_uInt16 numEntries, ConstantPool* pCP) + : BlopObject(buffer, 0, sal_False) + , m_numOfEntries(numEntries) + , m_pCP(pCP) + { + } + + sal_uInt32 parseIndex(); + + const sal_Char* getReferenceName(sal_uInt16 index); + RTReferenceType getReferenceType(sal_uInt16 index); + const sal_Char* getReferenceDoku(sal_uInt16 index); + RTFieldAccess getReferenceAccess(sal_uInt16 index); +}; + +sal_uInt32 ReferenceList::parseIndex() +{ + return (m_numOfEntries * (sizeof(sal_uInt16) * 4)); +} + +const sal_Char* ReferenceList::getReferenceName(sal_uInt16 index) +{ + const sal_Char* aName = NULL; + + if (index <= m_numOfEntries) + { + aName = m_pCP->readUTF8NameConstant(readUINT16((index * REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_NAME)); + } + + return aName; +} + +RTReferenceType ReferenceList::getReferenceType(sal_uInt16 index) +{ + RTReferenceType refType; + + if (index <= m_numOfEntries) + { + refType = (RTReferenceType) readUINT16((index * REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_TYPE); + } + + return refType; +} + +const sal_Char* ReferenceList::getReferenceDoku(sal_uInt16 index) +{ + const sal_Char* aDoku = NULL; + + if (index <= m_numOfEntries) + { + aDoku = m_pCP->readUTF8NameConstant(readUINT16((index * REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_DOKU)); + } + + return aDoku; +} + +RTFieldAccess ReferenceList::getReferenceAccess(sal_uInt16 index) +{ + RTFieldAccess aAccess; + + if (index <= m_numOfEntries) + { + aAccess = (RTFieldAccess) readUINT16((index * REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_ACCESS); + } + + return aAccess; +} + +/************************************************************************** + + class MethodList + +**************************************************************************/ + +class MethodList : public BlopObject +{ +public: + + sal_uInt16 m_numOfEntries; + sal_uInt32* m_pIndex; + ConstantPool* m_pCP; + + MethodList(const sal_uInt8* buffer, sal_uInt16 numEntries, ConstantPool* pCP) + : BlopObject(buffer, 0, sal_False) + , m_numOfEntries(numEntries) + , m_pIndex(NULL) + , m_pCP(pCP) + { + } + + ~MethodList(); + + sal_uInt32 parseIndex(); + + const sal_Char* getMethodName(sal_uInt16 index); + sal_uInt16 getMethodParamCount(sal_uInt16 index); + const sal_Char* getMethodParamType(sal_uInt16 index, sal_uInt16 paramIndex); + const sal_Char* getMethodParamName(sal_uInt16 index, sal_uInt16 paramIndex); + RTParamMode getMethodParamMode(sal_uInt16 index, sal_uInt16 paramIndex); + sal_uInt16 getMethodExcCount(sal_uInt16 index); + const sal_Char* getMethodExcType(sal_uInt16 index, sal_uInt16 excIndex); + const sal_Char* getMethodReturnType(sal_uInt16 index); + RTMethodMode getMethodMode(sal_uInt16 index); + const sal_Char* getMethodDoku(sal_uInt16 index); +}; + +MethodList::~MethodList() +{ + if (m_pIndex) delete[] m_pIndex; +} + +sal_uInt32 MethodList::parseIndex() +{ + if (m_pIndex) + { + delete[] m_pIndex; + m_pIndex = NULL; + } + + sal_uInt32 offset = 0; + + if (m_numOfEntries) + { + m_pIndex = new sal_uInt32[m_numOfEntries]; + + for (int i = 0; i < m_numOfEntries; i++) + { + m_pIndex[i] = offset; + + offset += readUINT16(offset); + } + } + + return offset; +} + +const sal_Char* MethodList::getMethodName(sal_uInt16 index) +{ + const sal_Char* aName = NULL; + + if (index <= m_numOfEntries) + { + aName = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_NAME)); + } + + return aName; +} + +sal_uInt16 MethodList::getMethodParamCount(sal_uInt16 index) +{ + sal_uInt16 aCount = 0; + + if (index <= m_numOfEntries) + { + aCount = readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT); + } + + return aCount; +} + +const sal_Char* MethodList::getMethodParamType(sal_uInt16 index, sal_uInt16 paramIndex) +{ + const sal_Char* aName = NULL; + + if ((index <= m_numOfEntries) && (paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT))) + { + aName = m_pCP->readUTF8NameConstant( + readUINT16( + m_pIndex[index] + + METHOD_OFFSET_PARAM(paramIndex) + + PARAM_OFFSET_TYPE)); + } + + return aName; +} + +const sal_Char* MethodList::getMethodParamName(sal_uInt16 index, sal_uInt16 paramIndex) +{ + const sal_Char* aName = NULL; + + if ((index <= m_numOfEntries) && (paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT))) + { + aName = m_pCP->readUTF8NameConstant( + readUINT16( + m_pIndex[index] + + METHOD_OFFSET_PARAM(paramIndex) + + PARAM_OFFSET_NAME)); + } + + return aName; +} + +RTParamMode MethodList::getMethodParamMode(sal_uInt16 index, sal_uInt16 paramIndex) +{ + RTParamMode aMode = RT_PARAM_INVALID; + + if ((index <= m_numOfEntries) && (paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT))) + { + aMode = (RTParamMode) readUINT16( + m_pIndex[index] + + METHOD_OFFSET_PARAM(paramIndex) + + PARAM_OFFSET_MODE); + } + + return aMode; +} + +sal_uInt16 MethodList::getMethodExcCount(sal_uInt16 index) +{ + sal_uInt16 aCount = 0; + + if (index <= m_numOfEntries) + { + aCount = readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM(readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT))); + } + + return aCount; +} + +const sal_Char* MethodList::getMethodExcType(sal_uInt16 index, sal_uInt16 excIndex) +{ + const sal_Char* aName = NULL; + + if (index <= m_numOfEntries) + { + sal_uInt32 excOffset = m_pIndex[index] + METHOD_OFFSET_PARAM(readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)); + + if (excIndex <= readUINT16(excOffset)) + { + aName = m_pCP->readUTF8NameConstant( + readUINT16( + excOffset + + sizeof(sal_uInt16) + + (excIndex * sizeof(sal_uInt16)))); + } + } + + return aName; +} + +const sal_Char* MethodList::getMethodReturnType(sal_uInt16 index) +{ + const sal_Char* aName = NULL; + + if (index <= m_numOfEntries) + { + aName = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_RETURN)); + } + + return aName; +} + +RTMethodMode MethodList::getMethodMode(sal_uInt16 index) +{ + RTMethodMode aMode = RT_MODE_INVALID; + + if (index <= m_numOfEntries) + { + aMode = (RTMethodMode) readUINT16(m_pIndex[index] + METHOD_OFFSET_MODE); + } + + return aMode; +} + +const sal_Char* MethodList::getMethodDoku(sal_uInt16 index) +{ + const sal_Char* aDoku = NULL; + + if (index <= m_numOfEntries) + { + aDoku = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_DOKU)); + } + + return aDoku; +} + +/************************************************************************** + + class TypeRegistryEntry + +**************************************************************************/ + +class TypeRegistryEntry : public BlopObject +{ + +public: + + ConstantPool* m_pCP; + FieldList* m_pFields; + MethodList* m_pMethods; + ReferenceList* m_pReferences; + sal_uInt32 m_refCount; + + TypeRegistryEntry(const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer) + : BlopObject(buffer, len, copyBuffer) + , m_pCP(NULL) + , m_pFields(NULL) + , m_pMethods(NULL) + , m_pReferences(NULL) + , m_refCount(1) + { + } + + ~TypeRegistryEntry(); + + void init() const; + +}; + +TypeRegistryEntry::~TypeRegistryEntry() +{ + if (m_pCP) delete m_pCP; + if (m_pFields) delete m_pFields; + if (m_pMethods) delete m_pMethods; + if (m_pReferences) delete m_pReferences; +} + + +void TypeRegistryEntry::init() const +{ +#ifdef OS2 + TypeRegistryEntry* _This = (TypeRegistryEntry*)(this); +#else + TypeRegistryEntry* _This = const_cast<TypeRegistryEntry*>(this); +#endif + + if (m_pCP) + { + delete _This->m_pCP; + _This->m_pCP = NULL; + } + + _This->m_pCP = new ConstantPool(m_pBuffer + OFFSET_CP, readUINT16(OFFSET_CP_SIZE)); + + sal_uInt32 offset = OFFSET_CP + _This->m_pCP->parseIndex(); + + _This->m_pFields = new FieldList(m_pBuffer + offset + sizeof(sal_uInt16), readUINT16(offset), _This->m_pCP); + + offset += sizeof(sal_uInt16) + _This->m_pFields->parseIndex(); + + _This->m_pMethods = new MethodList(m_pBuffer + offset + sizeof(sal_uInt16), readUINT16(offset), _This->m_pCP); + + offset += sizeof(sal_uInt16) + _This->m_pMethods->parseIndex(); + + _This->m_pReferences = new ReferenceList(m_pBuffer + offset + sizeof(sal_uInt16), readUINT16(offset), _This->m_pCP); + + offset += sizeof(sal_uInt16) + _This->m_pReferences->parseIndex(); +} + + +/************************************************************************** + + C-API + +**************************************************************************/ + +static TypeReaderImpl TYPEREG_CALLTYPE createEntry(const sal_uInt8* buffer, sal_uInt32 len, sal_Bool copyBuffer) +{ + TypeRegistryEntry* ret = NULL; + + if (len >= OFFSET_CP) + { + ret = new TypeRegistryEntry(buffer, len, copyBuffer); + + if ( + (ret->readUINT32(OFFSET_MAGIC) != magic) || + (ret->readUINT32(OFFSET_SIZE) > len) + ) + { + delete ret; + ret = NULL; + } + } + + return ret; +} + +static void TYPEREG_CALLTYPE acquire(TypeReaderImpl hEntry) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry != NULL) + pEntry->m_refCount++; +} + +static void TYPEREG_CALLTYPE release(TypeReaderImpl hEntry) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry != NULL) + { + if (--pEntry->m_refCount == 0) + delete pEntry; + } +} + +static sal_uInt16 TYPEREG_CALLTYPE getMinorVersion(TypeReaderImpl hEntry) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return 0; + + return pEntry->readUINT16(OFFSET_MINOR_VERSION); +} + +static sal_uInt16 TYPEREG_CALLTYPE getMajorVersion(TypeReaderImpl hEntry) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return 0; + + return pEntry->readUINT16(OFFSET_MAJOR_VERSION); +} + +static RTTypeClass TYPEREG_CALLTYPE getTypeClass(TypeReaderImpl hEntry) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return RT_TYPE_INVALID; + + return (RTTypeClass) pEntry->readUINT16(OFFSET_TYPE_CLASS); +} + +static void TYPEREG_CALLTYPE getTypeName(TypeReaderImpl hEntry, rtl_uString** pTypeName) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pTypeName); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_THIS_TYPE)); + if ( pTmp ) + rtl_string2UString( pTypeName, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static void TYPEREG_CALLTYPE getSuperTypeName(TypeReaderImpl hEntry, rtl_uString** pSuperTypeName) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pSuperTypeName); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_SUPER_TYPE)); + if ( pTmp ) + rtl_string2UString( pSuperTypeName, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static void TYPEREG_CALLTYPE getUik(TypeReaderImpl hEntry, RTUik* uik) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry != NULL) + { + if (pEntry->m_pCP == NULL) pEntry->init(); + + pEntry->m_pCP->readUIK(pEntry->readUINT16(OFFSET_UIK), uik); + } +} + +static void TYPEREG_CALLTYPE getDoku(TypeReaderImpl hEntry, rtl_uString** pDoku) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pDoku); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_DOKU)); + if ( pTmp ) + rtl_string2UString( pDoku, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static void TYPEREG_CALLTYPE getFileName(TypeReaderImpl hEntry, rtl_uString** pFileName) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pFileName); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_FILENAME)); + if ( pTmp ) + rtl_string2UString( pFileName, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static sal_uInt32 TYPEREG_CALLTYPE getFieldCount(TypeReaderImpl hEntry) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return 0; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pFields->m_numOfEntries; +} + +static void TYPEREG_CALLTYPE getFieldName(TypeReaderImpl hEntry, rtl_uString** pFieldName, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pFieldName); + return; + } + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pFields->getFieldName(index); + if ( pTmp ) + rtl_string2UString( pFieldName, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static void TYPEREG_CALLTYPE getFieldType(TypeReaderImpl hEntry, rtl_uString** pFieldType, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pFieldType); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pFields->getFieldType(index); + if ( pTmp ) + rtl_string2UString( pFieldType, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static RTFieldAccess TYPEREG_CALLTYPE getFieldAccess(TypeReaderImpl hEntry, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return RT_ACCESS_INVALID; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pFields->getFieldAccess(index); +} + +static RTValueType TYPEREG_CALLTYPE getFieldConstValue(TypeReaderImpl hEntry, sal_uInt16 index, RTConstValueUnion* value) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return RT_TYPE_NONE; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pFields->getFieldConstValue(index, value); +} + +static void TYPEREG_CALLTYPE getFieldDoku(TypeReaderImpl hEntry, rtl_uString** pDoku, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pDoku); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pFields->getFieldDoku(index); + if ( pTmp ) + rtl_string2UString( pDoku, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static void TYPEREG_CALLTYPE getFieldFileName(TypeReaderImpl hEntry, rtl_uString** pFieldFileName, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pFieldFileName); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pFields->getFieldFileName(index); + if ( pTmp ) + rtl_string2UString( pFieldFileName, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static sal_uInt32 TYPEREG_CALLTYPE getMethodCount(TypeReaderImpl hEntry) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return 0; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pMethods->m_numOfEntries; +} + +static void TYPEREG_CALLTYPE getMethodName(TypeReaderImpl hEntry, rtl_uString** pMethodName, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pMethodName); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pMethods->getMethodName(index); + if ( pTmp ) + rtl_string2UString( pMethodName, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static sal_uInt32 TYPEREG_CALLTYPE getMethodParamCount(TypeReaderImpl hEntry, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return 0; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pMethods->getMethodParamCount(index); +} + +static void TYPEREG_CALLTYPE getMethodParamType(TypeReaderImpl hEntry, rtl_uString** pMethodParamType, sal_uInt16 index, sal_uInt16 paramIndex) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pMethodParamType); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pMethods->getMethodParamType(index, paramIndex); + if ( pTmp ) + rtl_string2UString( pMethodParamType, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static void TYPEREG_CALLTYPE getMethodParamName(TypeReaderImpl hEntry, rtl_uString** pMethodParamName, sal_uInt16 index, sal_uInt16 paramIndex) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pMethodParamName); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pMethods->getMethodParamName(index, paramIndex); + if ( pTmp ) + rtl_string2UString( pMethodParamName, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static RTParamMode TYPEREG_CALLTYPE getMethodParamMode(TypeReaderImpl hEntry, sal_uInt16 index, sal_uInt16 paramIndex) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return RT_PARAM_INVALID; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pMethods->getMethodParamMode(index, paramIndex); +} + +static sal_uInt32 TYPEREG_CALLTYPE getMethodExcCount(TypeReaderImpl hEntry, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return 0; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pMethods->getMethodExcCount(index); +} + +static void TYPEREG_CALLTYPE getMethodExcType(TypeReaderImpl hEntry, rtl_uString** pMethodExcpType, sal_uInt16 index, sal_uInt16 excIndex) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pMethodExcpType); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pMethods->getMethodExcType(index, excIndex); + if ( pTmp ) + rtl_string2UString( pMethodExcpType, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static void TYPEREG_CALLTYPE getMethodReturnType(TypeReaderImpl hEntry, rtl_uString** pMethodReturnType, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pMethodReturnType); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pMethods->getMethodReturnType(index); + if ( pTmp ) + rtl_string2UString( pMethodReturnType, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static RTMethodMode TYPEREG_CALLTYPE getMethodMode(TypeReaderImpl hEntry, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return RT_MODE_INVALID; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pMethods->getMethodMode(index); +} + +static void TYPEREG_CALLTYPE getMethodDoku(TypeReaderImpl hEntry, rtl_uString** pMethodDoku, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pMethodDoku); + return; + } + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pMethods->getMethodDoku(index); + if ( pTmp ) + rtl_string2UString( pMethodDoku, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static sal_uInt32 TYPEREG_CALLTYPE getReferenceCount(TypeReaderImpl hEntry) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return 0; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pReferences->m_numOfEntries; +} + +static void TYPEREG_CALLTYPE getReferenceName(TypeReaderImpl hEntry, rtl_uString** pReferenceName, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pReferenceName); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pReferences->getReferenceName(index); + if ( pTmp ) + rtl_string2UString( pReferenceName, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static RTReferenceType TYPEREG_CALLTYPE getReferenceType(TypeReaderImpl hEntry, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return RT_REF_INVALID; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pReferences->getReferenceType(index); +} + +static void TYPEREG_CALLTYPE getReferenceDoku(TypeReaderImpl hEntry, rtl_uString** pReferenceDoku, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) + { + rtl_uString_new(pReferenceDoku); + return; + } + + if (pEntry->m_pCP == NULL) pEntry->init(); + + const sal_Char* pTmp = pEntry->m_pReferences->getReferenceDoku(index); + if ( pTmp ) + rtl_string2UString( pReferenceDoku, pTmp, rtl_str_getLength(pTmp), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static RTFieldAccess TYPEREG_CALLTYPE getReferenceAccess(TypeReaderImpl hEntry, sal_uInt16 index) +{ + TypeRegistryEntry* pEntry = (TypeRegistryEntry*) hEntry; + + if (pEntry == NULL) return RT_ACCESS_INVALID; + + if (pEntry->m_pCP == NULL) pEntry->init(); + + return pEntry->m_pReferences->getReferenceAccess(index); +} + + +extern "C" RegistryTypeReader_Api* TYPEREG_CALLTYPE initRegistryTypeReader_Api(void) +{ + static RegistryTypeReader_Api aApi= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + if (!aApi.acquire) + { + aApi.createEntry = &createEntry; + aApi.acquire = &acquire; + aApi.release = &release; + aApi.getMinorVersion = &getMinorVersion; + aApi.getMajorVersion = &getMajorVersion; + aApi.getTypeClass = &getTypeClass; + aApi.getTypeName = &getTypeName; + aApi.getSuperTypeName = &getSuperTypeName; + aApi.getUik = &getUik; + aApi.getDoku = &getDoku; + aApi.getFileName = &getFileName; + aApi.getFieldCount = &getFieldCount; + aApi.getFieldName = &getFieldName; + aApi.getFieldType = &getFieldType; + aApi.getFieldAccess = &getFieldAccess; + aApi.getFieldConstValue = &getFieldConstValue; + aApi.getFieldDoku = &getFieldDoku; + aApi.getFieldFileName = &getFieldFileName; + aApi.getMethodCount = &getMethodCount; + aApi.getMethodName = &getMethodName; + aApi.getMethodParamCount = &getMethodParamCount; + aApi.getMethodParamType = &getMethodParamType; + aApi.getMethodParamName = &getMethodParamName; + aApi.getMethodParamMode = &getMethodParamMode; + aApi.getMethodExcCount = &getMethodExcCount; + aApi.getMethodExcType = &getMethodExcType; + aApi.getMethodReturnType = &getMethodReturnType; + aApi.getMethodMode = &getMethodMode; + aApi.getMethodDoku = &getMethodDoku; + aApi.getReferenceCount = &getReferenceCount; + aApi.getReferenceName = &getReferenceName; + aApi.getReferenceType = &getReferenceType; + aApi.getReferenceDoku = &getReferenceDoku; + aApi.getReferenceAccess = &getReferenceAccess; + + return (&aApi); + } + else + { + return (&aApi); + } +} + + + diff --git a/registry/source/reflwrit.cxx b/registry/source/reflwrit.cxx new file mode 100644 index 000000000000..d8e1e2c74350 --- /dev/null +++ b/registry/source/reflwrit.cxx @@ -0,0 +1,1452 @@ +/************************************************************************* + * + * $RCSfile: reflwrit.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <osl/types.h> + +#include <rtl/alloc.h> +#include <registry/reflwrit.hxx> + +#include "reflcnst.hxx" + +using namespace rtl; +using namespace vos; + +#ifdef MAC +#define strdup(str) strcpy((sal_Char*)malloc(strlen(str)+1),str) +#endif + +static sal_Char NULL_STRING[1] = { 0 }; +static sal_Unicode NULL_WSTRING[1] = { 0 }; + +#if defined ( GCC ) && ( defined ( SCO ) || defined ( NETBSD ) || defined ( OS2 ) ) +ORealDynamicLoader* ODynamicLoader<RegistryTypeWriter_Api>::m_pLoader = NULL; +#endif + +#define BLOP_OFFSET_MAGIC 0 +#define BLOP_OFFSET_SIZE (BLOP_OFFSET_MAGIC + sizeof(sal_uInt32)) +#define BLOP_OFFSET_MINOR (BLOP_OFFSET_SIZE + sizeof(sal_uInt32)) +#define BLOP_OFFSET_MAJOR (BLOP_OFFSET_MINOR + sizeof(sal_uInt16)) +#define BLOP_OFFSET_TYPE_CLASS (BLOP_OFFSET_MAJOR + sizeof(sal_uInt16)) +#define BLOP_OFFSET_THIS (BLOP_OFFSET_TYPE_CLASS + sizeof(sal_uInt16)) +#define BLOP_OFFSET_SUPER (BLOP_OFFSET_THIS + sizeof(sal_uInt16)) +#define BLOP_OFFSET_UIK (BLOP_OFFSET_SUPER + sizeof(sal_uInt16)) +#define BLOP_OFFSET_DOKU (BLOP_OFFSET_UIK + sizeof(sal_uInt16)) +#define BLOP_OFFSET_FILENAME (BLOP_OFFSET_DOKU + sizeof(sal_uInt16)) +#define BLOP_HEADER_SIZE (BLOP_OFFSET_FILENAME + sizeof(sal_uInt16)) + + +#define BLOP_FIELD_ENTRY_ACCESS 0 +#define BLOP_FIELD_ENTRY_NAME (BLOP_FIELD_ENTRY_ACCESS + sizeof(sal_uInt16)) +#define BLOP_FIELD_ENTRY_TYPE (BLOP_FIELD_ENTRY_NAME + sizeof(sal_uInt16)) +#define BLOP_FIELD_ENTRY_VALUE (BLOP_FIELD_ENTRY_TYPE + sizeof(sal_uInt16)) +#define BLOP_FIELD_ENTRY_DOKU (BLOP_FIELD_ENTRY_VALUE + sizeof(sal_uInt16)) +#define BLOP_FIELD_ENTRY_FILENAME (BLOP_FIELD_ENTRY_DOKU + sizeof(sal_uInt16)) +#define BLOP_FIELD_ENTRY_SIZE (BLOP_FIELD_ENTRY_FILENAME + sizeof(sal_uInt16)) + +#define BLOP_METHOD_SIZE 0 +#define BLOP_METHOD_MODE (BLOP_METHOD_SIZE + sizeof(sal_uInt16)) +#define BLOP_METHOD_NAME (BLOP_METHOD_MODE + sizeof(sal_uInt16)) +#define BLOP_METHOD_RETURN (BLOP_METHOD_NAME + sizeof(sal_uInt16)) +#define BLOP_METHOD_DOKU (BLOP_METHOD_RETURN + sizeof(sal_uInt16)) +#define BLOP_METHOD_HEADER_SIZE (BLOP_METHOD_DOKU + sizeof(sal_uInt16)) + +#define BLOP_PARAM_TYPE 0 +#define BLOP_PARAM_MODE (BLOP_PARAM_TYPE + sizeof(sal_uInt16)) +#define BLOP_PARAM_NAME (BLOP_PARAM_MODE + sizeof(sal_uInt16)) +#define BLOP_PARAM_ENTRY_SIZE (BLOP_PARAM_NAME + sizeof(sal_uInt16)) + +#define BLOP_REFERENCE_TYPE 0 +#define BLOP_REFERENCE_NAME (BLOP_REFERENCE_TYPE + sizeof(sal_uInt16)) +#define BLOP_REFERENCE_DOKU (BLOP_REFERENCE_NAME + sizeof(sal_uInt16)) +#define BLOP_REFERENCE_ACCESS (BLOP_REFERENCE_DOKU + sizeof(sal_uInt16)) +#define BLOP_REFERENCE_ENTRY_SIZE (BLOP_REFERENCE_ACCESS + sizeof(sal_uInt16)) + +sal_uInt32 UINT16StringLen(const sal_uInt8* wstring) +{ + if (!wstring) return 0; + + const sal_uInt8* b = wstring; + + while (b[0] || b[1]) b += sizeof(sal_uInt16); + + return ((b - wstring) / sizeof(sal_uInt16)); +} + +sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v) +{ + sal_uInt32 len = rtl_ustr_getLength(v) + 1; + sal_uInt32 i; + sal_uInt8* buff = buffer; + + for (i = 0; i < len; i++) + { + buff += writeUINT16(buff, (sal_uInt16) v[i]); + } + + return (buff - buffer); +} + +sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize) +{ + sal_uInt32 len = VOS_MIN(UINT16StringLen(buffer) + 1, maxSize / 2); + sal_uInt32 i; + sal_uInt8* buff = (sal_uInt8*)buffer; + + for (i = 0; i < (len - 1); i++) + { + sal_uInt16 aChar; + + buff += readUINT16(buff, aChar); + + v[i] = (sal_Unicode) aChar; + } + + v[len - 1] = L'\0'; + + return (buff - ((sal_uInt8*)buffer)); +} + +sal_uInt32 writeFloat(sal_uInt8* buffer, float v) +{ + union + { + float v; + sal_uInt32 b; + } x; + + x.v = v; + +#ifdef REGTYPE_IEEE_NATIVE + writeUINT32(buffer, x.b); +#else +# error no IEEE +#endif + + return sizeof(sal_uInt32); +} + +sal_uInt32 readFloat(const sal_uInt8* buffer, float& v) +{ + union + { + float v; + sal_uInt32 b; + } x; + +#ifdef REGTYPE_IEEE_NATIVE + readUINT32(buffer, x.b); +#else +# error no IEEE +#endif + + v = x.v; + + return sizeof(sal_uInt32); +} + +sal_uInt32 writeDouble(sal_uInt8* buffer, double v) +{ + union + { + double v; + struct + { + sal_uInt32 b1; + sal_uInt32 b2; + } b; + } x; + + x.v = v; + +#ifdef REGTYPE_IEEE_NATIVE +# ifdef OSL_BIGENDIAN + writeUINT32(buffer, x.b.b1); + writeUINT32(buffer + sizeof(sal_uInt32), x.b.b2); +# else + writeUINT32(buffer, x.b.b2); + writeUINT32(buffer + sizeof(sal_uInt32), x.b.b1); +# endif +#else +# error no IEEE +#endif + + return (sizeof(sal_uInt32) + sizeof(sal_uInt32)); +} + +sal_uInt32 readDouble(const sal_uInt8* buffer, double& v) +{ + union + { + double v; + struct + { + sal_uInt32 b1; + sal_uInt32 b2; + } b; + } x; + +#ifdef REGTYPE_IEEE_NATIVE +# ifdef OSL_BIGENDIAN + readUINT32(buffer, x.b.b1); + readUINT32(buffer + sizeof(sal_uInt32), x.b.b2); +# else + readUINT32(buffer, x.b.b2); + readUINT32(buffer + sizeof(sal_uInt32), x.b.b1); +# endif +#else +# error no IEEE +#endif + + v = x.v; + + return (sizeof(sal_uInt32) + sizeof(sal_uInt32)); +} + +/************************************************************************** + + buffer write functions + +**************************************************************************/ + + +/************************************************************************** + + struct CPInfo + +**************************************************************************/ + +struct CPInfo +{ + CPInfoTag m_tag; + union + { + const sal_Char* aUtf8; + RTUik* aUik; + RTConstValueUnion aConst; +/* sal_Bool aBool; + sal_uInt8 aByte; + sal_Int16 aShort; + sal_uInt16 aUShort; + sal_Int32 aLong; + sal_uInt32 aULong; +// INT64 aHyper; +// UINT64 aUHyper; + float aFloat; + double aDouble; + const sal_Unicode* aString;*/ + } m_value; + + sal_uInt16 m_index; + struct CPInfo* m_next; + + CPInfo(CPInfoTag tag, struct CPInfo* prev); + + sal_uInt32 getBlopSize(); + + sal_uInt32 toBlop(sal_uInt8* buffer, sal_uInt32 maxLen); +}; + +CPInfo::CPInfo(CPInfoTag tag, struct CPInfo* prev) + : m_tag(tag) + , m_index(0) + , m_next(NULL) +{ + if (prev) + { + m_index = prev->m_index + 1; + prev->m_next = this; + } +} + +sal_uInt32 CPInfo::getBlopSize() +{ + sal_uInt32 size = sizeof(sal_uInt16) /* size */ + sizeof(sal_uInt16) /* tag */; + + switch (m_tag) + { + case CP_TAG_CONST_BOOL: + size += sizeof(sal_uInt8); + break; + case CP_TAG_CONST_BYTE: + size += sizeof(sal_uInt8); + break; + case CP_TAG_CONST_INT16: + size += sizeof(sal_Int16); + break; + case CP_TAG_CONST_UINT16: + size += sizeof(sal_uInt16); + break; + case CP_TAG_CONST_INT32: + size += sizeof(sal_Int32); + break; + case CP_TAG_CONST_UINT32: + size += sizeof(sal_uInt32); + break; + case CP_TAG_CONST_INT64: +// size += sizeof(sal_Int64); + break; + case CP_TAG_CONST_UINT64: +// size += sizeof(sal_uInt64); + break; + case CP_TAG_CONST_FLOAT: + size += sizeof(sal_uInt32); + break; + case CP_TAG_CONST_DOUBLE: + size += sizeof(sal_uInt32) + sizeof(sal_uInt32); + break; + case CP_TAG_CONST_STRING: + size += (rtl_ustr_getLength(m_value.aConst.aString) + 1) * sizeof(sal_uInt16); + break; + case CP_TAG_UTF8_NAME: + size += strlen(m_value.aUtf8) + 1; + break; + case CP_TAG_UIK: + size += sizeof(sal_uInt32) + sizeof(sal_uInt16) + sizeof(sal_uInt16) + sizeof(sal_uInt32) + sizeof(sal_uInt32); + break; + default: + break; + } + + return size; +} + + +sal_uInt32 CPInfo::toBlop(sal_uInt8* buffer, sal_uInt32 maxLen) +{ + sal_uInt8* buff = buffer; + + buff += writeUINT16(buff, (sal_uInt16) getBlopSize()); + buff += writeUINT16(buff, (sal_uInt16) m_tag); + + switch (m_tag) + { + case CP_TAG_CONST_BOOL: + buff += writeBYTE(buff, (sal_uInt8) m_value.aConst.aBool); + break; + case CP_TAG_CONST_BYTE: + buff += writeBYTE(buff, m_value.aConst.aByte); + break; + case CP_TAG_CONST_INT16: + buff += writeINT16(buff, m_value.aConst.aShort); + break; + case CP_TAG_CONST_UINT16: + buff += writeINT16(buff, m_value.aConst.aUShort); + break; + case CP_TAG_CONST_INT32: + buff += writeINT32(buff, m_value.aConst.aLong); + break; + case CP_TAG_CONST_UINT32: + buff += writeUINT32(buff, m_value.aConst.aULong); + break; + case CP_TAG_CONST_INT64: +// buff += writeUINT64(buff, m_value.aConst.aHyper); + break; + case CP_TAG_CONST_UINT64: +// buff += writeUINT64(buff, m_value.aConst.aUHyper); + break; + case CP_TAG_CONST_FLOAT: + buff += writeFloat(buff, m_value.aConst.aFloat); + break; + case CP_TAG_CONST_DOUBLE: + buff += writeDouble(buff, m_value.aConst.aDouble); + break; + case CP_TAG_CONST_STRING: + buff += writeString(buff, m_value.aConst.aString); + break; + case CP_TAG_UTF8_NAME: + buff += writeUtf8(buff, m_value.aUtf8); + break; + case CP_TAG_UIK: + buff += writeUINT32(buff, m_value.aUik->m_Data1); + buff += writeUINT16(buff, m_value.aUik->m_Data2); + buff += writeUINT16(buff, m_value.aUik->m_Data3); + buff += writeUINT32(buff, m_value.aUik->m_Data4); + buff += writeUINT32(buff, m_value.aUik->m_Data5); + break; + default: + break; + } + + return (buff - buffer); +} + + +/************************************************************************** + + class FieldEntry + +**************************************************************************/ + +class FieldEntry +{ + +public: + + OString m_name; + OString m_typeName; + OString m_doku; + OString m_fileName; + RTFieldAccess m_access; + RTValueType m_constValueType; + RTConstValueUnion m_constValue; + + FieldEntry(); + ~FieldEntry(); + + void setData(const OString& name, + const OString& typeName, + const OString& doku, + const OString& fileName, + RTFieldAccess access, + RTValueType constValueType, + RTConstValueUnion constValue); +}; + +FieldEntry::FieldEntry() + : m_access(RT_ACCESS_INVALID) + , m_constValueType(RT_TYPE_NONE) +{ +} + +FieldEntry::~FieldEntry() +{ + if ( + (m_constValueType == RT_TYPE_STRING) && + m_constValue.aString && + (m_constValue.aString != NULL_WSTRING) + ) + { + delete[] (sal_Unicode*)m_constValue.aString; + } +} + +void FieldEntry::setData(const OString& name, + const OString& typeName, + const OString& doku, + const OString& fileName, + RTFieldAccess access, + RTValueType constValueType, + RTConstValueUnion constValue) +{ + m_name = name; + m_typeName = typeName; + m_doku = doku; + m_fileName = fileName; + + if ( + (m_constValueType == RT_TYPE_STRING) && + m_constValue.aString && + (m_constValue.aString != NULL_WSTRING) + ) + { + delete[] (sal_Unicode*)m_constValue.aString; + } + + m_access = access; + m_constValueType = constValueType; + + if (m_constValueType == RT_TYPE_STRING) + { + if (constValue.aString == NULL) + m_constValue.aString = NULL_WSTRING; + else + { + sal_uInt32 len = rtl_ustr_getLength(constValue.aString); + + m_constValue.aString = new sal_Unicode[len + 1]; + rtl_copyMemory( (sal_Unicode*)m_constValue.aString, constValue.aString, (len+1) * sizeof(sal_Unicode) ); + } + } + else + { + m_constValue = constValue; + } +} + +/************************************************************************** + + class ParamEntry + +**************************************************************************/ + +class ParamEntry +{ +public: + + OString m_typeName; + OString m_name; + RTParamMode m_mode; + + ParamEntry(); + ~ParamEntry(); + + void setData(const OString& typeName, + const OString& name, + RTParamMode mode); +}; + +ParamEntry::ParamEntry() + : m_mode(RT_PARAM_INVALID) +{ +} + +ParamEntry::~ParamEntry() +{ +} + +void ParamEntry::setData(const OString& typeName, + const OString& name, + RTParamMode mode) +{ + m_name = name; + m_typeName = typeName; + m_mode = mode; +} + +/************************************************************************** + + class ReferenceEntry + +**************************************************************************/ + +class ReferenceEntry +{ +public: + + OString m_name; + OString m_doku; + RTReferenceType m_type; + RTFieldAccess m_access; + + ReferenceEntry(); + ~ReferenceEntry(); + + void setData(const OString& name, + RTReferenceType refType, + const OString& doku, + RTFieldAccess access); +}; + +ReferenceEntry::ReferenceEntry() + : m_type(RT_REF_INVALID) + , m_access(RT_ACCESS_INVALID) +{ +} + +ReferenceEntry::~ReferenceEntry() +{ +} + +void ReferenceEntry::setData(const OString& name, + RTReferenceType refType, + const OString& doku, + RTFieldAccess access) +{ + m_name = name; + m_doku = doku; + m_type = refType; + m_access = access; +} + +/************************************************************************** + + class MethodEntry + +**************************************************************************/ + +class MethodEntry +{ +public: + + OString m_name; + OString m_returnTypeName; + RTMethodMode m_mode; + sal_uInt16 m_paramCount; + ParamEntry* m_params; + sal_uInt16 m_excCount; + OString* m_excNames; + OString m_doku; + + MethodEntry(); + ~MethodEntry(); + + void setData(const OString& name, + const OString& returnTypeName, + RTMethodMode mode, + sal_uInt16 paramCount, + sal_uInt16 excCount, + const OString& doku); + + void setExcName(sal_uInt16 excIndex, const OString& name); + +protected: + + void reallocParams(sal_uInt16 size); + void reallocExcs(sal_uInt16 size); +}; + +MethodEntry::MethodEntry() + : m_mode(RT_MODE_INVALID) + , m_paramCount(0) + , m_params(NULL) + , m_excCount(0) + , m_excNames(NULL) +{ +} + +MethodEntry::~MethodEntry() +{ + if (m_params) + delete[] m_params; + + if (m_excNames) + delete[] m_excNames; +} + +void MethodEntry::setData(const OString& name, + const OString& returnTypeName, + RTMethodMode mode, + sal_uInt16 paramCount, + sal_uInt16 excCount, + const OString& doku) +{ + m_name = name; + m_returnTypeName = returnTypeName; + m_doku = doku; + + m_mode = mode; + + reallocParams(paramCount); + reallocExcs(excCount); +} + +void MethodEntry::setExcName(sal_uInt16 excIndex, const OString& name) +{ + if (excIndex < m_excCount) + { + m_excNames[excIndex] = name; + } +} + +void MethodEntry::reallocParams(sal_uInt16 size) +{ + ParamEntry* newParams; + + if (size) + newParams = new ParamEntry[size]; + else + newParams = NULL; + + if (m_paramCount) + { + sal_uInt16 i; + + for (i = 0; i < VOS_MIN(size, m_paramCount); i++) + { + newParams[i].setData(m_params[i].m_typeName, m_params[i].m_name, m_params[i].m_mode); + } + + delete[] m_params; + } + + m_paramCount = size; + m_params = newParams; +} + +void MethodEntry::reallocExcs(sal_uInt16 size) +{ + OString* newExcNames; + + if (size) + newExcNames = new OString[size]; + else + newExcNames = NULL; + + sal_uInt16 i; + + for (i = 0; i < VOS_MIN(size, m_excCount); i++) + { + newExcNames[i] = m_excNames[i]; + } + + delete[] m_excNames; + + m_excCount = size; + m_excNames = newExcNames; +} + + +/************************************************************************** + + class TypeRegistryEntry + +**************************************************************************/ + +class TypeWriter +{ + +public: + + sal_uInt32 m_refCount; + RTTypeClass m_typeClass; + OString m_typeName; + OString m_superTypeName; + RTUik* m_pUik; + OString m_doku; + OString m_fileName; + sal_uInt16 m_fieldCount; + FieldEntry* m_fields; + sal_uInt16 m_methodCount; + MethodEntry* m_methods; + sal_uInt16 m_referenceCount; + ReferenceEntry* m_references; + + sal_uInt8* m_blop; + sal_uInt32 m_blopSize; + + TypeWriter(RTTypeClass RTTypeClass, + const OString& typeName, + const OString& superTypeName, + sal_uInt16 FieldCount, + sal_uInt16 methodCount, + sal_uInt16 referenceCount); + + ~TypeWriter(); + + void createBlop(); +}; + +TypeWriter::TypeWriter(RTTypeClass RTTypeClass, + const OString& typeName, + const OString& superTypeName, + sal_uInt16 fieldCount, + sal_uInt16 methodCount, + sal_uInt16 referenceCount) + : m_refCount(1) + , m_typeClass(RTTypeClass) + , m_typeName(typeName) + , m_superTypeName(superTypeName) + , m_fieldCount(fieldCount) + , m_methodCount(methodCount) + , m_referenceCount(referenceCount) + , m_blop(NULL) + , m_blopSize(0) + , m_pUik(NULL) +{ + if (m_fieldCount) + m_fields = new FieldEntry[fieldCount]; + + if (m_methodCount) + m_methods = new MethodEntry[methodCount]; + + if (m_referenceCount) + m_references = new ReferenceEntry[referenceCount]; +} + +TypeWriter::~TypeWriter() +{ + if (m_blop) + delete[] m_blop; + + if (m_fieldCount) + delete[] m_fields; + + if (m_methodCount) + delete[] m_methods; + + if (m_referenceCount) + delete[] m_references; + + if (m_pUik) + delete m_pUik; +} + +void TypeWriter::createBlop() +{ + sal_uInt8* pBlopFields = NULL; + sal_uInt8* pBlopMethods = NULL; + sal_uInt8* pBlopReferences = NULL; + sal_uInt8* pBuffer = NULL; + sal_uInt32 blopFieldsSize = 0; + sal_uInt32 blopMethodsSize = 0; + sal_uInt32 blopReferenceSize = 0; + sal_uInt16 i; + + if (m_blop) + delete[] m_blop; + + CPInfo root(CP_TAG_INVALID, NULL); + sal_uInt16 cpIndexThisName = 0; + sal_uInt16 cpIndexSuperName = 0; + sal_uInt16 cpIndexUik = 0; + sal_uInt16 cpIndexDoku = 0; + sal_uInt16 cpIndexFileName = 0; + CPInfo* pInfo = NULL; + + m_blopSize = BLOP_HEADER_SIZE; + + // create CP entry for this name + pInfo = new CPInfo(CP_TAG_UTF8_NAME, &root); + pInfo->m_value.aUtf8 = m_typeName.getStr(); + cpIndexThisName = pInfo->m_index; + + // create CP entry for super name + if (m_superTypeName.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_superTypeName.getStr(); + cpIndexSuperName = pInfo->m_index; + } + + // create CP entry for uik + if (m_pUik != NULL) + { + pInfo = new CPInfo(CP_TAG_UIK, pInfo); + pInfo->m_value.aUik = m_pUik; + cpIndexUik = pInfo->m_index; + } + + // create CP entry for doku + if (m_doku.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_doku.getStr(); + cpIndexDoku = pInfo->m_index; + } + + // create CP entry for idl source filename + if (m_fileName.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_fileName.getStr(); + cpIndexFileName = pInfo->m_index; + } + + // fields blop + + m_blopSize += sizeof(sal_uInt16); // fieldCount + + if (m_fieldCount) + { + sal_uInt16 cpIndexName = 0; + sal_uInt16 cpIndexTypeName = 0; + sal_uInt16 cpIndexValue = 0; + sal_uInt16 cpIndexDoku = 0; + sal_uInt16 cpIndexFileName = 0; + + blopFieldsSize = m_fieldCount * BLOP_FIELD_ENTRY_SIZE; + + m_blopSize += blopFieldsSize; + + pBlopFields = new sal_uInt8[blopFieldsSize]; + pBuffer = pBlopFields; + + for (i = 0; i < m_fieldCount; i++) + { + cpIndexName = 0; + cpIndexTypeName = 0; + cpIndexValue = 0; + cpIndexDoku = 0; + cpIndexFileName = 0; + + pBuffer += writeUINT16(pBuffer, m_fields[i].m_access); + + if (m_fields[i].m_name.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_fields[i].m_name.getStr(); + cpIndexName = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexName); + + if (m_fields[i].m_typeName.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_fields[i].m_typeName.getStr(); + cpIndexTypeName = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexTypeName); + + if (m_fields[i].m_constValueType != RT_TYPE_NONE) + { + pInfo = new CPInfo((CPInfoTag)m_fields[i].m_constValueType, pInfo); + pInfo->m_value.aConst = m_fields[i].m_constValue; + cpIndexValue = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexValue); + + if (m_fields[i].m_doku.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_fields[i].m_doku.getStr(); + cpIndexDoku = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexDoku); + + if (m_fields[i].m_fileName.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_fields[i].m_fileName.getStr(); + cpIndexFileName = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexFileName); + } + } + + // methods blop + + m_blopSize += sizeof(sal_uInt16); // methodCount + + if (m_methodCount) + { + sal_uInt16* pMethodEntrySize = new sal_uInt16[m_methodCount]; + sal_uInt16 cpIndexName = 0; + sal_uInt16 cpIndexReturn = 0; + sal_uInt16 cpIndexDoku = 0; + + blopMethodsSize = 0; + + for (i = 0; i < m_methodCount; i++) + { + pMethodEntrySize[i] = + BLOP_METHOD_HEADER_SIZE + // header + sizeof(sal_uInt16) + // parameterCount + (m_methods[i].m_paramCount * BLOP_PARAM_ENTRY_SIZE) + // exceptions + sizeof(sal_uInt16) + // exceptionCount + (m_methods[i].m_excCount * sizeof(sal_uInt16)); // exceptions + + blopMethodsSize += pMethodEntrySize[i]; + } + + pBlopMethods = new sal_uInt8[blopMethodsSize]; + + m_blopSize += blopMethodsSize; + + pBuffer = pBlopMethods; + + for (i = 0; i < m_methodCount; i++) + { + cpIndexReturn = 0; + cpIndexDoku = 0; + + pBuffer += writeUINT16(pBuffer, pMethodEntrySize[i]); + pBuffer += writeUINT16(pBuffer, m_methods[i].m_mode); + + if (m_methods[i].m_name.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_methods[i].m_name.getStr(); + cpIndexName = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexName); + cpIndexName = 0; + + if (m_methods[i].m_returnTypeName.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_methods[i].m_returnTypeName.getStr(); + cpIndexReturn = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexReturn); + + if (m_methods[i].m_doku.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_methods[i].m_doku.getStr(); + cpIndexDoku = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexDoku); + + sal_uInt16 j; + + pBuffer += writeUINT16(pBuffer, m_methods[i].m_paramCount); + + for (j = 0; j < m_methods[i].m_paramCount; j++) + { + if (m_methods[i].m_params[j].m_typeName.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_typeName.getStr(); + cpIndexName = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexName); + cpIndexName = 0; + + pBuffer += writeUINT16(pBuffer, m_methods[i].m_params[j].m_mode); + + if (m_methods[i].m_params[j].m_name.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_name.getStr(); + cpIndexName = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexName); + cpIndexName = 0; + } + + pBuffer += writeUINT16(pBuffer, m_methods[i].m_excCount); + + for (j = 0; j < m_methods[i].m_excCount; j++) + { + if (m_methods[i].m_excNames[j].getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_methods[i].m_excNames[j].getStr(); + cpIndexName = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexName); + cpIndexName = 0; + } + } + + delete[] pMethodEntrySize; + } + + // reference blop + + m_blopSize += sizeof(sal_uInt16); // referenceCount + + if (m_referenceCount) + { + sal_uInt16 cpIndexName = 0; + sal_uInt16 cpIndexDoku = 0; + + blopReferenceSize = m_referenceCount * BLOP_REFERENCE_ENTRY_SIZE; + + m_blopSize += blopReferenceSize; + + pBlopReferences = new sal_uInt8[blopReferenceSize]; + pBuffer = pBlopReferences; + + for (i = 0; i < m_referenceCount; i++) + { + pBuffer += writeUINT16(pBuffer, m_references[i].m_type); + + cpIndexName = 0; + cpIndexDoku = 0; + + if (m_references[i].m_name.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_references[i].m_name.getStr(); + cpIndexName = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexName); + + if (m_references[i].m_doku.getLength()) + { + pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo); + pInfo->m_value.aUtf8 = m_references[i].m_doku.getStr(); + cpIndexDoku = pInfo->m_index; + } + pBuffer += writeUINT16(pBuffer, cpIndexDoku); + + pBuffer += writeUINT16(pBuffer, m_references[i].m_access); + } + } + + + // CP infos blop-laenge holen + pInfo = root.m_next; + sal_uInt32 cpBlopSize = 0; + sal_uInt16 cpCount = 0; + + while (pInfo) + { + cpBlopSize += pInfo->getBlopSize(); + cpCount++; + pInfo = pInfo->m_next; + } + + m_blopSize += cpBlopSize; + m_blopSize += sizeof(sal_uInt16); // constantPoolCount + + // write all in flat buffer + + m_blop = new sal_uInt8[m_blopSize]; + + pBuffer = m_blop; + + pBuffer += writeUINT32(pBuffer, magic); + pBuffer += writeUINT32(pBuffer, m_blopSize); + pBuffer += writeUINT16(pBuffer, minorVersion); + pBuffer += writeUINT16(pBuffer, majorVersion); + pBuffer += writeUINT16(pBuffer, (sal_uInt16)m_typeClass); + pBuffer += writeUINT16(pBuffer, cpIndexThisName); + pBuffer += writeUINT16(pBuffer, cpIndexSuperName); + pBuffer += writeUINT16(pBuffer, cpIndexUik); + pBuffer += writeUINT16(pBuffer, cpIndexDoku); + pBuffer += writeUINT16(pBuffer, cpIndexFileName); + pBuffer += writeUINT16(pBuffer, cpCount); + + // write and delete CP infos + pInfo = root.m_next; + + while (pInfo) + { + CPInfo* pNextInfo = pInfo->m_next; + + pBuffer += pInfo->toBlop(pBuffer, m_blopSize - (pBuffer - m_blop)); + delete pInfo; + + pInfo = pNextInfo; + } + + // write fields + pBuffer += writeUINT16(pBuffer, m_fieldCount); + if (blopFieldsSize) + { + memcpy(pBuffer, pBlopFields, blopFieldsSize); + pBuffer += blopFieldsSize; + } + + // write methods + pBuffer += writeUINT16(pBuffer, m_methodCount); + if (blopMethodsSize) + { + memcpy(pBuffer, pBlopMethods, blopMethodsSize); + pBuffer += blopMethodsSize; + } + + // write references + pBuffer += writeUINT16(pBuffer, m_referenceCount); + if (blopReferenceSize) + { + memcpy(pBuffer, pBlopReferences, blopReferenceSize); + pBuffer += blopReferenceSize; + } + + delete[] pBlopFields; + delete[] pBlopMethods; + delete[] pBlopReferences; +} + + +/************************************************************************** + + C-API + +**************************************************************************/ + +static TypeWriterImpl TYPEREG_CALLTYPE createEntry(RTTypeClass RTTypeClass, + rtl_uString* typeName, + rtl_uString* superTypeName, + sal_uInt16 FieldCount, + sal_uInt16 methodCount, + sal_uInt16 referenceCount) +{ + OString rTypeName, rSuperTypeName; + + rtl_uString2String( &rTypeName.pData, typeName->buffer, typeName->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_uString2String( &rSuperTypeName.pData, superTypeName->buffer, superTypeName->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + + return new TypeWriter(RTTypeClass, + rTypeName, + rSuperTypeName, + FieldCount, + methodCount, + referenceCount); +} + +static void TYPEREG_CALLTYPE acquire(TypeWriterImpl hEntry) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if (pEntry != NULL) + pEntry->m_refCount++; +} + +static void TYPEREG_CALLTYPE release(TypeWriterImpl hEntry) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if (pEntry != NULL) + { + if (--pEntry->m_refCount == 0) + delete pEntry; + } +} + +static void TYPEREG_CALLTYPE setUik(TypeWriterImpl hEntry, const RTUik* uik) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if (pEntry != NULL) + { + if (pEntry->m_pUik) + { + pEntry->m_pUik->m_Data1 = uik->m_Data1; + pEntry->m_pUik->m_Data2 = uik->m_Data2; + pEntry->m_pUik->m_Data3 = uik->m_Data3; + pEntry->m_pUik->m_Data4 = uik->m_Data4; + pEntry->m_pUik->m_Data5 = uik->m_Data5; + } + else + pEntry->m_pUik = new RTUik(*uik); + } +} + +static void TYPEREG_CALLTYPE setDoku(TypeWriterImpl hEntry, rtl_uString* doku) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if (pEntry != NULL) + { + if (doku) + { + OString rDoku; + rtl_uString2String( &rDoku.pData, doku->buffer, doku->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + pEntry->m_doku = rDoku; + } else + { + pEntry->m_doku = NULL_STRING; + } + } +} + +static void TYPEREG_CALLTYPE setFileName(TypeWriterImpl hEntry, rtl_uString* fileName) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if (pEntry != NULL) + { + if (fileName) + { + OString rFileName; + rtl_uString2String( &rFileName.pData, fileName->buffer, fileName->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + pEntry->m_fileName = rFileName; + } else + { + pEntry->m_fileName = NULL_STRING; + } + } +} + +static void TYPEREG_CALLTYPE setFieldData(TypeWriterImpl hEntry, + sal_uInt16 index, + rtl_uString* name, + rtl_uString* typeName, + rtl_uString* doku, + rtl_uString* fileName, + RTFieldAccess access, + RTValueType valueType, + RTConstValueUnion constValue) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if ((pEntry != NULL) && (index < pEntry->m_fieldCount)) + { + OString rName, rTypeName, rDoku, rFileName; + rtl_uString2String( &rName.pData, name->buffer, name->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_uString2String( &rTypeName.pData, typeName->buffer, typeName->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_uString2String( &rDoku.pData, doku->buffer, doku->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_uString2String( &rFileName.pData, fileName->buffer, fileName->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + + pEntry->m_fields[index].setData(rName, rTypeName, rDoku, rFileName, access, valueType, constValue); + } +} + +static void TYPEREG_CALLTYPE setMethodData(TypeWriterImpl hEntry, + sal_uInt16 index, + rtl_uString* name, + rtl_uString* returnTypeName, + RTMethodMode mode, + sal_uInt16 paramCount, + sal_uInt16 excCount, + rtl_uString* doku) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if ((pEntry != NULL) && (index < pEntry->m_methodCount)) + { + OString rName, rReturnTypeName, rDoku; + rtl_uString2String( &rName.pData, name->buffer, name->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_uString2String( &rReturnTypeName.pData, returnTypeName->buffer, returnTypeName->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_uString2String( &rDoku.pData, doku->buffer, doku->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + + pEntry->m_methods[index].setData(rName, rReturnTypeName, mode, paramCount, excCount, rDoku); + } +} + +static void TYPEREG_CALLTYPE setParamData(TypeWriterImpl hEntry, + sal_uInt16 index, + sal_uInt16 paramIndex, + rtl_uString* type, + rtl_uString* name, + RTParamMode mode) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if ((pEntry != NULL) && + (index < pEntry->m_methodCount) && + (paramIndex < pEntry->m_methods[index].m_paramCount)) + { + OString rName, rType; + rtl_uString2String( &rName.pData, name->buffer, name->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_uString2String( &rType.pData, type->buffer, type->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + + pEntry->m_methods[index].m_params[paramIndex].setData(rType, rName, mode); + } +} + +static void TYPEREG_CALLTYPE setExcData(TypeWriterImpl hEntry, + sal_uInt16 index, + sal_uInt16 excIndex, + rtl_uString* type) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if ((pEntry != NULL) && (index < pEntry->m_methodCount)) + { + OString rType; + rtl_uString2String( &rType.pData, type->buffer, type->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + + pEntry->m_methods[index].setExcName(excIndex, rType); + } +} + +static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry) +{ + const sal_uInt8* blop = NULL; + + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if (pEntry != NULL) + { + if (!pEntry->m_blop) + pEntry->createBlop(); + + blop = pEntry->m_blop; + } + + return blop; +} + +static sal_uInt32 TYPEREG_CALLTYPE getBlopSize(TypeWriterImpl hEntry) +{ + sal_uInt32 aSize = 0; + + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if (pEntry != NULL) + { + if (!pEntry->m_blop) + pEntry->createBlop(); + + aSize = pEntry->m_blopSize; + } + + return aSize; +} + +static void TYPEREG_CALLTYPE setReferenceData(TypeWriterImpl hEntry, + sal_uInt16 index, + rtl_uString* name, + RTReferenceType refType, + rtl_uString* doku, + RTFieldAccess access) +{ + TypeWriter* pEntry = (TypeWriter*) hEntry; + + if ((pEntry != NULL) && (index < pEntry->m_referenceCount)) + { + OString rName, rDoku; + rtl_uString2String( &rName.pData, name->buffer, name->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + rtl_uString2String( &rDoku.pData, doku->buffer, doku->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + + pEntry->m_references[index].setData(rName, + refType, + rDoku, + access); + } +} + + +extern "C" RegistryTypeWriter_Api* TYPEREG_CALLTYPE initRegistryTypeWriter_Api(void) +{ + static RegistryTypeWriter_Api aApi= {0,0,0,0,0,0,0,0,0,0,0,0,0}; + if (!aApi.acquire) + { + aApi.createEntry = &createEntry; + aApi.acquire = &acquire; + aApi.release = &release; + aApi.setUik = &setUik; + aApi.setDoku = &setDoku; + aApi.setFileName = &setFileName; + aApi.setFieldData = &setFieldData; + aApi.setMethodData = &setMethodData; + aApi.setParamData = &setParamData; + aApi.setExcData = &setExcData; + aApi.getBlop = &getBlop; + aApi.getBlopSize = &getBlopSize; + aApi.setReferenceData = &setReferenceData; + + return (&aApi); + } + else + { + return (&aApi); + } +} + + + + + diff --git a/registry/source/regimpl.cxx b/registry/source/regimpl.cxx new file mode 100644 index 000000000000..af8c3809c51a --- /dev/null +++ b/registry/source/regimpl.cxx @@ -0,0 +1,2172 @@ +/************************************************************************* + * + * $RCSfile: regimpl.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <string.h> +#include <stdio.h> +#ifdef MAC +#include <unistd.h> +#define strdup(str) strcpy((sal_Char*)malloc(strlen(str)+1),str) +#endif +#ifdef UNX +#include <unistd.h> +#endif + +#include "regimpl.hxx" + +#ifndef __REGISTRY_REFLREAD_HXX__ +#include <registry/reflread.hxx> +#endif + +#ifndef __REGISTRY_REFLWRIT_HXX__ +#include <registry/reflwrit.hxx> +#endif + +#ifndef __REFLCNST_HXX__ +#include "reflcnst.hxx" +#endif + +#ifndef _KEYIMPL_HXX_ +#include "keyimpl.hxx" +#endif + +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + +#ifndef _RTL_MEMORY_H_ +#include <rtl/memory.h> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif + +#if defined ( GCC ) && ( defined ( SCO ) || defined ( NETBSD ) || defined ( OS2 ) ) +NAMESPACE_VOS(ORealDynamicLoader)* NAMESPACE_VOS(ODynamicLoader)<RegistryTypeReader_Api>::m_pLoader = NULL; +#endif + + +extern "C" RegistryTypeReader_Api* TYPEREG_CALLTYPE initRegistryTypeReader_Api(); +extern "C" RegistryTypeWriter_Api* TYPEREG_CALLTYPE initRegistryTypeWriter_Api(); + + +//********************************************************************* +// dumpType() +// +static sal_Bool dumpType(RegistryTypeReader& reader, const OString& sIndent) +{ + sal_uInt16 i, j; + sal_Bool ret = sal_True; + const sal_Char* indent = sIndent; + + if (reader.isValid()) + { + fprintf(stdout, "minor version: %d\n", reader.getMinorVersion()); + fprintf(stdout, "%smajor version: %d\n", indent, reader.getMajorVersion()); + fprintf(stdout, "%s" ,indent); + switch (reader.getTypeClass()) + { + case RT_TYPE_INVALID: + fprintf(stdout, "type: 'invalid'\n"); + break; + case RT_TYPE_INTERFACE: + { + fprintf(stdout, "type: 'interface'\n"); + RTUik uik; + + reader.getUik(uik); + + fprintf(stdout, "%suik: { 0x%.8x-0x%.4x-0x%.4x-0x%.8x-0x%.8x }\n", + indent, uik.m_Data1, uik.m_Data2, uik.m_Data3, uik.m_Data4, uik.m_Data5); + } + break; + case RT_TYPE_MODULE: + fprintf(stdout, "type: 'module'\n"); + break; + case RT_TYPE_STRUCT: + fprintf(stdout, "type: 'struct'\n"); + break; + case RT_TYPE_ENUM: + fprintf(stdout, "type: 'enum'\n"); + break; + case RT_TYPE_EXCEPTION: + fprintf(stdout, "type: 'exception'\n"); + break; + case RT_TYPE_TYPEDEF: + fprintf(stdout, "type: 'typedef'\n"); + break; + case RT_TYPE_SERVICE: + fprintf(stdout, "type: 'service'\n"); + break; + case RT_TYPE_CONSTANTS: + fprintf(stdout, "type: 'constants'\n"); + break; + default: + fprintf(stdout, "type: <unknown>\n"); + break; + } + + fprintf(stdout, "%sname: '%s'\n", indent, OUStringToOString(reader.getTypeName(), RTL_TEXTENCODING_UTF8).getStr()); + fprintf(stdout, "%ssuper name: '%s'\n", indent, OUStringToOString(reader.getSuperTypeName(), RTL_TEXTENCODING_UTF8).getStr()); + fprintf(stdout, "%sDoku: \"%s\"\n", indent, OUStringToOString(reader.getDoku(), RTL_TEXTENCODING_UTF8).getStr()); + fprintf(stdout, "%sIDL source file: \"%s\"\n", indent, OUStringToOString(reader.getFileName(), RTL_TEXTENCODING_UTF8).getStr()); + fprintf(stdout, "%snumber of fields: %d\n", indent, reader.getFieldCount()); + sal_uInt16 fieldAccess = RT_ACCESS_INVALID; + for (i = 0; i < reader.getFieldCount(); i++) + { + fprintf(stdout, "%sfield #%d:\n%s name='%s'\n%s type='%s'\n", indent, + i, indent, OUStringToOString(reader.getFieldName(i), RTL_TEXTENCODING_UTF8).getStr(), + indent, OUStringToOString(reader.getFieldType(i), RTL_TEXTENCODING_UTF8).getStr()); + + fieldAccess = reader.getFieldAccess(i); + if ( fieldAccess == RT_ACCESS_INVALID ) + { + fprintf(stdout, "%s access=INVALID\n", indent); + } + if ( (fieldAccess & RT_ACCESS_CONST) == RT_ACCESS_CONST ) + { + fprintf(stdout, "%s access=CONST\n", indent); + RTConstValue constVal = reader.getFieldConstValue(i); + + fprintf(stdout, "%s value = ", indent); + + switch (constVal.m_type) + { + case RT_TYPE_BOOL: + if (constVal.m_value.aBool) + fprintf(stdout, "TRUE"); + else + fprintf(stdout, "FALSE"); + break; + case RT_TYPE_BYTE: + fprintf(stdout, "%d", (int)constVal.m_value.aByte); + break; + case RT_TYPE_INT16: + fprintf(stdout, "%d", constVal.m_value.aShort); + break; + case RT_TYPE_UINT16: + fprintf(stdout, "%u", constVal.m_value.aUShort); + break; + case RT_TYPE_INT32: + fprintf(stdout, "%d", constVal.m_value.aLong); + break; + case RT_TYPE_UINT32: + fprintf(stdout, "%u", constVal.m_value.aULong); + break; + case RT_TYPE_FLOAT: + fprintf(stdout, "%f", constVal.m_value.aFloat); + break; + case RT_TYPE_DOUBLE: + fprintf(stdout, "%f", constVal.m_value.aDouble); + break; + case RT_TYPE_STRING: + fprintf(stdout, "%s", OUStringToOString(constVal.m_value.aString, RTL_TEXTENCODING_UTF8).getStr()); + break; + default: + break; + } + } + if ( (fieldAccess & RT_ACCESS_READONLY) == RT_ACCESS_READONLY ) + { + fprintf(stdout, "%s access=READONLY\n", indent); + } + if ( (fieldAccess & RT_ACCESS_READWRITE) == RT_ACCESS_READWRITE ) + { + fprintf(stdout, "%s access=READWRITE\n", indent); + } + if ( (fieldAccess & RT_ACCESS_OPTIONAL) == RT_ACCESS_OPTIONAL ) + { + fprintf(stdout, "%s access=OPTIONAL\n", indent); + } + if ( (fieldAccess & RT_ACCESS_MAYBEVOID) == RT_ACCESS_MAYBEVOID ) + { + fprintf(stdout, "%s access=MAYBEVOID\n", indent); + } + if ( (fieldAccess & RT_ACCESS_BOUND) == RT_ACCESS_BOUND ) + { + fprintf(stdout, "%s access=BOUND\n", indent); + } + if ( (fieldAccess & RT_ACCESS_CONSTRAINED) == RT_ACCESS_CONSTRAINED ) + { + fprintf(stdout, "%s access=CONSTRAINED\n", indent); + } + if ( (fieldAccess & RT_ACCESS_TRANSIENT) == RT_ACCESS_TRANSIENT ) + { + fprintf(stdout, "%s access=TRANSIENT\n", indent); + } + if ( (fieldAccess & RT_ACCESS_MAYBEAMBIGUOUS) == RT_ACCESS_MAYBEAMBIGUOUS ) + { + fprintf(stdout, "%s access=MAYBEAMBIGUOUS\n", indent); + } + if ( (fieldAccess & RT_ACCESS_MAYBEDEFAULT) == RT_ACCESS_MAYBEDEFAULT ) + { + fprintf(stdout, "%s access=MAYBEDEFAULT\n", indent); + } + if ( (fieldAccess & RT_ACCESS_REMOVEABLE) == RT_ACCESS_REMOVEABLE ) + { + fprintf(stdout, "%s access=REMOVEABLE\n", indent); + } + +/* + switch (reader.getFieldAccess(i)) + { + case RT_ACCESS_INVALID: + fprintf(stdout, "%s access=INVALID\n", indent); + break; + case RT_ACCESS_CONST: + { + fprintf(stdout, "%s access=CONST\n", indent); + RTConstValue constVal = reader.getFieldConstValue(i); + + fprintf(stdout, "%s value = ", indent); + + switch (constVal.m_type) + { + case RT_TYPE_BOOL: + if (constVal.m_value.aBool) + fprintf(stdout, "TRUE"); + else + fprintf(stdout, "FALSE"); + break; + case RT_TYPE_BYTE: + fprintf(stdout, "%d", (int)constVal.m_value.aByte); + break; + case RT_TYPE_INT16: + fprintf(stdout, "%d", constVal.m_value.aShort); + break; + case RT_TYPE_UINT16: + fprintf(stdout, "%u", constVal.m_value.aUShort); + break; + case RT_TYPE_INT32: + fprintf(stdout, "%d", constVal.m_value.aLong); + break; + case RT_TYPE_UINT32: + fprintf(stdout, "%u", constVal.m_value.aULong); + break; + case RT_TYPE_FLOAT: + fprintf(stdout, "%f", constVal.m_value.aFloat); + break; + case RT_TYPE_DOUBLE: + fprintf(stdout, "%f", constVal.m_value.aDouble); + break; + case RT_TYPE_STRING: + fprintf(stdout, "%s", OUStringToOString(constVal.m_value.aString, RTL_TEXTENCODING_UTF8).getStr()); + break; + default: + break; + } + } + break; + case RT_ACCESS_READONLY: + fprintf(stdout, "%s access=READONLY ", indent); + break; + case RT_ACCESS_WRITEONLY: + fprintf(stdout, "%s access=WRITEONLY ", indent); + break; + case RT_ACCESS_READWRITE: + fprintf(stdout, "%s access=READWRITE ", indent); + break; + case RT_ACCESS_READONLY_OPTIONAL: + fprintf(stdout, "%s access=READONLY, OPTIONAL ", indent); + break; + case RT_ACCESS_WRITEONLY_OPTIONAL: + fprintf(stdout, "%s access=WRITEONLY, OPTIONAL ", indent); + break; + case RT_ACCESS_READWRITE_OPTIONAL: + fprintf(stdout, "%s access=READWRITE, OPTIONAL ", indent); + break; + default: + fprintf(stdout, "%s access=<unknown> ", indent); + break; + } +*/ + fprintf(stdout, "\n%s Doku: \"%s\"", indent, OUStringToOString(reader.getFieldDoku(i), RTL_TEXTENCODING_UTF8).getStr()); + fprintf(stdout, "\n%s IDL source file: \"%s\"\n", indent, OUStringToOString(reader.getFieldFileName(i), RTL_TEXTENCODING_UTF8).getStr()); + } + + fprintf(stdout, "%snumber of methods: %d\n", indent, reader.getMethodCount()); + for (i = 0; i < reader.getMethodCount(); i++) + { + fprintf(stdout, "%smethod #%d: ", indent, i); + + switch (reader.getMethodMode(i)) + { + case RT_MODE_INVALID: + fprintf(stdout, "<invalid mode> "); + break; + case RT_MODE_ONEWAY: + fprintf(stdout, "[oneway] "); + break; + case RT_MODE_ONEWAY_CONST: + fprintf(stdout, "[oneway, const] "); + break; + case RT_MODE_TWOWAY: + break; + case RT_MODE_TWOWAY_CONST: + fprintf(stdout, "[const] "); + break; + default: + fprintf(stdout, "<unknown mode> "); + break; + } + + fprintf(stdout, "%s %s(", + OUStringToOString(reader.getMethodReturnType(i), RTL_TEXTENCODING_UTF8).getStr(), + OUStringToOString(reader.getMethodName(i), RTL_TEXTENCODING_UTF8).getStr()); + + for (j = 0; j < reader.getMethodParamCount(i); j++) + { + switch (reader.getMethodParamMode(i, j)) + { + case RT_PARAM_INVALID: + fprintf(stdout, "<invalid mode> "); + break; + case RT_PARAM_IN: + fprintf(stdout, "[in] "); + break; + case RT_PARAM_OUT: + fprintf(stdout, "[out] "); + break; + case RT_PARAM_INOUT: + fprintf(stdout, "[inout] "); + break; + default: + fprintf(stdout, "<unknown mode> "); + break; + } + + fprintf(stdout, "%s %s", + OUStringToOString(reader.getMethodParamType(i, j), RTL_TEXTENCODING_UTF8).getStr(), + OUStringToOString(reader.getMethodParamName(i, j), RTL_TEXTENCODING_UTF8).getStr()); + + if (j != reader.getMethodParamCount(i) - 1) + fprintf(stdout, ", "); + } + + fprintf(stdout, ") "); + + if (reader.getMethodExcCount(i)) + { + fprintf(stdout, "raises "); + for (j = 0; j < reader.getMethodExcCount(i); j++) + { + fprintf(stdout, "%s", + OUStringToOString(reader.getMethodExcType(i, j), RTL_TEXTENCODING_UTF8).getStr()); + if (j != reader.getMethodExcCount(i) - 1) + fprintf(stdout, ", "); + } + } + + fprintf(stdout, "\n%s Doku: \"%s\"\n", indent, + OUStringToOString(reader.getMethodDoku(i), RTL_TEXTENCODING_UTF8).getStr()); + } + + fprintf(stdout, "%snumber of references: %d\n", indent, reader.getReferenceCount()); + for (i = 0; i < reader.getReferenceCount(); i++) + { + fprintf(stdout, "%sreference #%d:\n%s name='%s'\n", indent, i, indent, + OUStringToOString(reader.getReferenceName(i), RTL_TEXTENCODING_UTF8).getStr()); + switch (reader.getReferenceType(i)) + { + case RT_REF_INVALID: + fprintf(stdout, "%s type=INVALID\n", indent); + break; + case RT_REF_SUPPORTS: + { + fprintf(stdout, "%s type=supported interface\n", indent); + if (reader.getReferenceAccess(i) == RT_ACCESS_OPTIONAL) + { + fprintf(stdout, "%s access=optional\n", indent); + } + } + break; + case RT_REF_OBSERVES: + fprintf(stdout, "%s type=observed interface\n", indent); + break; + case RT_REF_EXPORTS: + fprintf(stdout, "%s type=exported service\n", indent); + break; + case RT_REF_NEEDS: + fprintf(stdout, "%s type=needed service\n", indent); + break; + default: + fprintf(stdout, "%s type=<unknown>\n", indent); + break; + } + + fprintf(stdout, "%s Doku: \"%s\"\n", indent, + OUStringToOString(reader.getReferenceDoku(i), RTL_TEXTENCODING_UTF8).getStr()); + } + } + else + { + ret = sal_False; + } + + return ret; +} + + +//********************************************************************* +// ORegistry() +// +ORegistry::ORegistry() + : m_refCount(1) + , m_readOnly(sal_False) + , m_isOpen(sal_False) + , ROOT( RTL_CONSTASCII_USTRINGPARAM("/") ) +{ +} + +//********************************************************************* +// ~ORegistry() +// +ORegistry::~ORegistry() +{ + if (m_openKeyTable.count(ROOT) > 0) + { + m_openKeyTable[ROOT]->release(); + delete(m_openKeyTable[ROOT]); + } + + if (m_file.isValid()) + m_file.close(); +} + + +//********************************************************************* +// initRegistry +// +RegError ORegistry::initRegistry(const OUString& regName, RegAccessMode accessMode) +{ + OStoreFile rRegFile; + storeAccessMode sAccessMode = REG_MODE_OPEN; + storeError errCode; + + if (accessMode & REG_CREATE) + { + sAccessMode = REG_MODE_CREATE; + } else + if (accessMode & REG_READONLY) + { + sAccessMode = REG_MODE_OPENREAD; + m_readOnly = sal_True; + } + + if (errCode = rRegFile.create(regName, sAccessMode, REG_PAGESIZE)) + { + switch (errCode) + { + case store_E_NotExists: + return REG_REGISTRY_NOT_EXISTS; + break; + case store_E_LockingViolation: + return REG_CANNOT_OPEN_FOR_READWRITE; + break; + default: + return REG_INVALID_REGISTRY; + break; + } + } else + { + OStoreDirectory rStoreDir; + storeError _err = rStoreDir.create(rRegFile, OUString(), OUString(), sAccessMode); + + if ( _err == store_E_None ) + { + m_file = rRegFile; + m_name = regName; + m_isOpen = sal_True; + + + m_openKeyTable[ROOT] = new ORegKey(ROOT, rStoreDir, this); + return REG_NO_ERROR; + } else + return REG_INVALID_REGISTRY; + } +} + + +//********************************************************************* +// closeRegistry +// +RegError ORegistry::closeRegistry() +{ + REG_GUARD(m_mutex); + + if (m_file.isValid()) + { + closeKey(m_openKeyTable[ROOT]); + m_file.close(); + m_isOpen = sal_False; + return REG_NO_ERROR; + } else + { + return REG_REGISTRY_NOT_EXISTS; + } +} + + +//********************************************************************* +// destroyRegistry +// +RegError ORegistry::destroyRegistry(const OUString& regName) +{ + REG_GUARD(m_mutex); + + if (regName.getLength()) + { + ORegistry* pReg = new ORegistry(); + + if (!pReg->initRegistry(regName, REG_READWRITE)) + { + delete pReg; + + OString name( OUStringToOString(regName, RTL_TEXTENCODING_UTF8) ); + if (unlink(name) != 0) + { + return REG_DESTROY_REGISTRY_FAILED; + } + } else + { + return REG_DESTROY_REGISTRY_FAILED; + } + } else + { + if (m_refCount != 1 || isReadOnly()) + { + return REG_DESTROY_REGISTRY_FAILED; + } + + if (m_file.isValid()) + { + closeKey(m_openKeyTable[ROOT]); + m_file.close(); + m_isOpen = sal_False; + + OString name( OUStringToOString(m_name, RTL_TEXTENCODING_UTF8) ); + if (unlink(name) != 0) + { + return REG_DESTROY_REGISTRY_FAILED; + } + } else + { + return REG_REGISTRY_NOT_EXISTS; + } + } + + return REG_NO_ERROR; +} + +//********************************************************************* +// createKey +// +RegError ORegistry::createKey(RegKeyHandle hKey, const OUString& keyName, + RegKeyHandle* phNewKey) +{ + ORegKey* pKey; + + *phNewKey = NULL; + + if ( !keyName.getLength() ) + return REG_INVALID_KEYNAME; + + REG_GUARD(m_mutex); + + if (hKey) + pKey = (ORegKey*)hKey; + else + pKey = m_openKeyTable[ROOT]; + + OUString sFullKeyName = resolveLinks(pKey, keyName); + + if ( !sFullKeyName.getLength() ) + return REG_DETECT_RECURSION; + + if (m_openKeyTable.count(sFullKeyName) > 0) + { + *phNewKey = m_openKeyTable[sFullKeyName]; + ((ORegKey*)*phNewKey)->acquire(); + ((ORegKey*)*phNewKey)->setDeleted(sal_False); + return REG_NO_ERROR; + } + + OStoreDirectory rStoreDir; + OUStringBuffer sFullPath(sFullKeyName.getLength()); + sal_Int32 tokenCount = sFullKeyName.getTokenCount('/'); + OUString token; + + sFullPath.append((sal_Unicode)'/'); + + for (sal_Int32 i=0; i < tokenCount; i++) + { + token = sFullKeyName.getToken(i, '/'); + if (token.getLength()) + { + if (rStoreDir.create(pKey->getStoreFile(), sFullPath.getStr(), token, KEY_MODE_CREATE)) + { + return REG_CREATE_KEY_FAILED; + } + + sFullPath.append(token); + sFullPath.append((sal_Unicode)'/'); + } + } + + pKey = new ORegKey(sFullKeyName, rStoreDir, this); + *phNewKey = pKey; + m_openKeyTable[sFullKeyName] = pKey; + + return REG_NO_ERROR; +} + + +//********************************************************************* +// openKey +// +RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName, + RegKeyHandle* phOpenKey, RESOLVE eResolve) +{ + ORegKey* pKey; + storeAccessMode accessMode = KEY_MODE_OPEN; + + *phOpenKey = NULL; + + if ( !keyName.getLength() ) + { + return REG_INVALID_KEYNAME; + } + + if ( isReadOnly() ) + { + accessMode = KEY_MODE_OPENREAD; + } + + REG_GUARD(m_mutex); + + if (hKey) + pKey = (ORegKey*)hKey; + else + pKey = m_openKeyTable[ROOT]; + + OUString sFullKeyName; + OUString sFullPath; + OUString sRelativKey; + + switch (eResolve) + { + case RESOLVE_FULL: + { + sFullKeyName = resolveLinks(pKey, keyName); + + if ( !sFullKeyName.getLength() ) + return REG_DETECT_RECURSION; + + sal_Int32 lastIndex = sFullKeyName.lastIndexOf('/'); + sRelativKey = sFullKeyName.copy(lastIndex + 1); + sFullPath = sFullKeyName.copy(0, lastIndex + 1); + } + break; + case RESOLVE_PART: + { + sal_Int32 lastIndex = keyName.lastIndexOf('/'); + if ( lastIndex >= 0 ) + { + OUString sRelativ(keyName.copy(lastIndex)); + OUString tmpKey(keyName.copy(0, lastIndex + 1)); + sFullKeyName = resolveLinks(pKey, tmpKey); + + sFullPath = sFullKeyName; + sFullPath += ROOT; + sFullKeyName += sRelativ; + sRelativKey = sRelativ.copy(1); + } else + { + sFullKeyName = pKey->getName(); + sFullPath = sFullKeyName; + + sRelativKey = keyName; + + if ( sFullKeyName.getLength() > 1 ) + sFullKeyName += ROOT; + + sFullKeyName += keyName; + + if ( sFullPath.getLength() > 1 ) + sFullPath += ROOT; + } + } + break; + case RESOLVE_NOTHING: + { + sFullKeyName = pKey->getName(); + sFullPath = sFullKeyName; + + if (sFullKeyName.getLength() > 1) + sFullKeyName += ROOT; + + sal_Int32 lastIndex = keyName.lastIndexOf('/'); + if ( lastIndex >= 0 && lastIndex < keyName.getLength() ) + { + OUString sRelativ(keyName.copy(lastIndex+1)); + sRelativKey = sRelativ; + sFullKeyName += keyName.copy(1); + + sFullPath = sFullKeyName.copy(0, keyName.lastIndexOf('/') + 1); + } else + { + + sRelativKey += keyName; + sFullKeyName += keyName; + + if ( sFullPath.getLength() > 1 ) + sFullPath += ROOT; + } + } + break; + } + + if (m_openKeyTable.count(sFullKeyName) > 0) + { + m_openKeyTable[sFullKeyName]->acquire(); + *phOpenKey = m_openKeyTable[sFullKeyName]; + return REG_NO_ERROR; + } + + OStoreDirectory rStoreDir; + storeError _err = rStoreDir.create(pKey->getStoreFile(), sFullPath, sRelativKey, accessMode); + + if (_err == store_E_NotExists) + return REG_KEY_NOT_EXISTS; + else + if (_err == store_E_WrongFormat) + return REG_INVALID_KEY; + + pKey = new ORegKey(sFullKeyName, rStoreDir, this); + + *phOpenKey = pKey; + m_openKeyTable[sFullKeyName] = pKey; + + return REG_NO_ERROR; +} + + +//********************************************************************* +// closeKey +// +RegError ORegistry::closeKey(RegKeyHandle hKey) +{ + ORegKey* pKey = (ORegKey*)hKey; + + REG_GUARD(m_mutex); + + if (m_openKeyTable.count(pKey->getName()) > 0) + { + if (pKey->getRefCount() == 1) + { + m_openKeyTable.erase(pKey->getName()); + delete(pKey); + hKey = NULL; + } else + { + pKey->release(); + } + + return REG_NO_ERROR; + } else + { + return REG_KEY_NOT_OPEN; + } +} + + +//********************************************************************* +// deleteKey +// +RegError ORegistry::deleteKey(RegKeyHandle hKey, const OUString& keyName) +{ + ORegKey* pKey; + RegError _ret = REG_NO_ERROR; + + if ( !keyName.getLength() ) + { + return REG_INVALID_KEYNAME; + } + + REG_GUARD(m_mutex); + + if (hKey) + pKey = (ORegKey*)hKey; + else + pKey = m_openKeyTable[ROOT]; + + OUString sFullKeyName = resolveLinks(pKey, keyName); + + if ( !sFullKeyName.getLength() ) + return REG_DETECT_RECURSION; + + pKey = m_openKeyTable[ROOT]; + _ret = eraseKey(pKey, sFullKeyName, RESOLVE_NOTHING); + + return _ret; +} + +RegError ORegistry::eraseKey(ORegKey* pKey, const OUString& keyName, RESOLVE eResolve) +{ + RegError _ret = REG_NO_ERROR; + + if ( !keyName.getLength() ) + { + return REG_INVALID_KEYNAME; + } + + OUString sFullKeyName(pKey->getName()); + OUString sFullPath(sFullKeyName); + OUString sRelativKey; + sal_Int32 lastIndex = keyName.lastIndexOf('/'); + + if ( lastIndex >= 0 ) + { + sRelativKey += keyName.copy(lastIndex + 1); + + if (sFullKeyName.getLength() > 1) + sFullKeyName += keyName; + else + sFullKeyName += (keyName+1); + + sFullPath = sFullKeyName.copy(0, keyName.lastIndexOf('/') + 1); + } else + { + if (sFullKeyName.getLength() > 1) + sFullKeyName += ROOT; + + sRelativKey += keyName; + sFullKeyName += keyName; + + if (sFullPath.getLength() > 1) + sFullPath += ROOT; + } + + RegKeyHandle hOldKey; + if (_ret = pKey->openKey(keyName, &hOldKey, eResolve)) + { + return _ret; + } + + if (_ret = deleteSubkeysAndValues((ORegKey*)hOldKey, eResolve)) + { + pKey->closeKey(hOldKey); + return _ret; + } + + OUString tmpName(sRelativKey); + tmpName += ROOT; + + OStoreFile sFile(pKey->getStoreFile()); + + if ( sFile.isValid() && sFile.remove(sFullPath, tmpName) ) + { + return REG_DELETE_KEY_FAILED; + } + + // set flag deleted !!! + ((ORegKey*)hOldKey)->setDeleted(sal_True); + + if (_ret = pKey->closeKey(hOldKey)) + { + return _ret; + } + + return REG_NO_ERROR; +} + + +//********************************************************************* +// deleteSubKeys +// +RegError ORegistry::deleteSubkeysAndValues(ORegKey* pKey, RESOLVE eResolve) +{ + 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; + + if (iter.m_nAttrib & STORE_ATTRIB_ISDIR) + { + if ((_ret = eraseKey(pKey, keyName, eResolve))) + return _ret; + } else + { + OUString sFullPath(pKey->getName()); + + if (sFullPath.getLength() > 1) + sFullPath += ROOT; + + if ( ((OStoreFile&)pKey->getStoreFile()).remove(sFullPath, keyName) ) + { + return REG_DELETE_VALUE_FAILED; + } + } + + _err = rStoreDir.next(iter); + } + + return REG_NO_ERROR; +} + + +//********************************************************************* +// loadKey +// +RegError ORegistry::loadKey(RegKeyHandle hKey, const OUString& regFileName, + sal_Bool bWarnings, sal_Bool bReport) +{ + RegError _ret = REG_NO_ERROR; + ORegistry* pReg; + ORegKey *pKey, *pRootKey; + + pReg = new ORegistry(); + if (_ret = pReg->initRegistry(regFileName, REG_READONLY)) + { + return _ret; + } + + pKey = (ORegKey*)hKey; + 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; + + if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR ) + { + _ret = loadAndSaveKeys(pKey, pRootKey, keyName, 0, bWarnings, bReport); + } 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; + } + + _err = rStoreDir.next(iter); + } + + rStoreDir = OStoreDirectory(); + pRootKey->release(); + delete(pReg); + return _ret; +} + + +//********************************************************************* +// loadKey +// +RegError ORegistry::saveKey(RegKeyHandle hKey, const OUString& regFileName, + sal_Bool bWarnings, sal_Bool bReport) +{ + RegError _ret = REG_NO_ERROR; + ORegistry* pReg; + ORegKey *pKey, *pRootKey; + + pReg = new ORegistry(); + if (_ret = pReg->initRegistry(regFileName, REG_CREATE)) + { + return _ret; + } + + pKey = (ORegKey*)hKey; + 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; + + if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR ) + { + _ret = loadAndSaveKeys(pRootKey, pKey, keyName, + pKey->getName().getLength(), + bWarnings, bReport); + } else + { + _ret = loadAndSaveValue(pRootKey, pKey, keyName, + pKey->getName().getLength(), + bWarnings, bReport); + } + + if (_ret) + { + pRootKey->release(); + delete(pReg); + return _ret; + } + + _err = rStoreDir.next(iter); + } + + pRootKey->release(); + delete(pReg); + return REG_NO_ERROR; +} + + +//********************************************************************* +// isKeyOpen() +// +sal_Bool ORegistry::isKeyOpen(const OUString& keyName) const +{ + return(m_openKeyTable.count(keyName) > 0); +} + + + +//********************************************************************* +// countSubKeys() +// +sal_uInt32 ORegistry::countSubKeys(ORegKey* pKey) +{ + REG_GUARD(m_mutex); + + OStoreDirectory::iterator iter; + sal_uInt32 count = 0; + OStoreDirectory rStoreDir(pKey->getStoreDir()); + storeError _err = rStoreDir.first(iter); + + while ( _err == store_E_None) + { + if (iter.m_nAttrib & STORE_ATTRIB_ISDIR) + { + count++; + } + + _err = rStoreDir.next(iter); + } + + return count; +} + + +//********************************************************************* +// loadValue() +// +RegError ORegistry::loadAndSaveValue(ORegKey* pTargetKey, + ORegKey* pSourceKey, + const OUString& valueName, + sal_uInt32 nCut, + sal_Bool bWarnings, + sal_Bool bReport) +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + RegValueType valueType; + sal_uInt32 valueSize; + sal_uInt32 nSize; + storeAccessMode sourceAccess = VALUE_MODE_OPEN; + OUString sTargetPath(pTargetKey->getName()); + OUString sSourcePath(pSourceKey->getName()); + + if (pSourceKey->isReadOnly()) + { + sourceAccess = VALUE_MODE_OPENREAD; + } + + if (nCut) + { + sTargetPath = sSourcePath.copy(nCut); + } else + { + if (sTargetPath.getLength() > 1) + { + if (sSourcePath.getLength() > 1) + sTargetPath += sSourcePath; + } else + sTargetPath = sSourcePath; + } + + if (sTargetPath.getLength() > 1) sTargetPath += ROOT; + if (sSourcePath.getLength() > 1) sSourcePath += ROOT; + + if (rValue.create(pSourceKey->getStoreFile(), sSourcePath, valueName, sourceAccess)) + { + return REG_VALUE_NOT_EXISTS; + } + + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE); + + sal_uInt32 rwBytes; + if (rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes)) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (rwBytes != VALUE_HEADERSIZE) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + RegError _ret = REG_NO_ERROR; + sal_uInt8 type = *((sal_uInt8*)pBuffer); + valueType = (RegValueType)type; + readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize); + rtl_freeMemory(pBuffer); + + nSize = VALUE_HEADERSIZE + valueSize; + pBuffer = (sal_uInt8*)rtl_allocateMemory(nSize); + + if (rValue.readAt(0, pBuffer, nSize, rwBytes)) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (rwBytes != nSize) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + OStoreFile rTargetFile(pTargetKey->getStoreFile()); + + if (!rValue.create(rTargetFile, sTargetPath, valueName, VALUE_MODE_OPEN)) + { + if (valueType == RG_VALUETYPE_BINARY) + { + if (_ret = checkBlop(rValue, pTargetKey, sTargetPath, + valueName, valueSize, pBuffer+VALUE_HEADEROFFSET, + bReport)) + { + if (_ret == REG_MERGE_ERROR || + (_ret == REG_MERGE_CONFLICT && bWarnings)) + { + rtl_freeMemory(pBuffer); + return _ret; + } + } else + { + rtl_freeMemory(pBuffer); + return _ret; + } + } + } + + // write + if (rValue.create(rTargetFile, sTargetPath, valueName, VALUE_MODE_CREATE)) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (rValue.writeAt(0, pBuffer, nSize, rwBytes)) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + if (rwBytes != nSize) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + rtl_freeMemory(pBuffer); + return _ret; +} + + +//********************************************************************* +// checkblop() +// +RegError ORegistry::checkBlop(OStoreStream& rValue, + ORegKey* pTargetKey, + const OUString& sTargetPath, + const OUString& valueName, + sal_uInt32 srcValueSize, + sal_uInt8* pSrcBuffer, + sal_Bool bReport) +{ + RegistryTypeReader_Api* pReaderApi; + + pReaderApi = initRegistryTypeReader_Api(); + + RegistryTypeReader reader(pReaderApi, pSrcBuffer, srcValueSize, sal_False); + + if (reader.getTypeClass() == RT_TYPE_INVALID) + { + return REG_INVALID_VALUE; + } + + sal_uInt8* pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE); + RegValueType valueType; + sal_uInt32 valueSize; + sal_uInt32 rwBytes; + OString targetPath( OUStringToOString(sTargetPath, RTL_TEXTENCODING_UTF8) ); + + if (!rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes) && + (rwBytes == VALUE_HEADERSIZE)) + { + sal_uInt8 type = *((sal_uInt8*)pBuffer); + valueType = (RegValueType)type; + readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize); + rtl_freeMemory(pBuffer); + + if (valueType == RG_VALUETYPE_BINARY) + { + pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + if (!rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, rwBytes) && + (rwBytes == valueSize)) + { + RegistryTypeReader reader2(pReaderApi, pBuffer, valueSize, sal_False); + + if ((reader.getTypeClass() != reader2.getTypeClass()) + || reader2.getTypeClass() == RT_TYPE_INVALID) + { + rtl_freeMemory(pBuffer); + + if (bReport) + { + fprintf(stdout, "ERROR: values of blop from key \"%s\" has different types.\n", + targetPath.getStr()); + } + return REG_MERGE_ERROR; + } + + if (reader.getTypeClass() == RT_TYPE_MODULE) + { + if (reader.getFieldCount() > 0 && + reader2.getFieldCount() > 0) + { + mergeModuleValue(rValue, pTargetKey, sTargetPath, + valueName, reader, reader2); + + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; + } else + if (reader2.getFieldCount() > 0) + { + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; + } else + { + rtl_freeMemory(pBuffer); + return REG_MERGE_CONFLICT; + } + } else + { + rtl_freeMemory(pBuffer); + + if (bReport) + { + fprintf(stdout, "WARNING: value of key \"%s\" already exists.\n", + targetPath.getStr()); + } + return REG_MERGE_CONFLICT; + } + } else + { + rtl_freeMemory(pBuffer); + if (bReport) + { + fprintf(stdout, "ERROR: values of key \"%s\" contains bad data.\n", + targetPath.getStr()); + } + return REG_MERGE_ERROR; + } + } else + { + rtl_freeMemory(pBuffer); + if (bReport) + { + fprintf(stdout, "ERROR: values of key \"%s\" has different types.\n", + targetPath.getStr()); + } + return REG_MERGE_ERROR; + } + } else + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } +} + +static sal_uInt32 checkTypeReaders(RegistryTypeReader& reader1, + RegistryTypeReader& reader2, + StringSet& nameSet) +{ + sal_uInt32 count=0; + sal_uInt32 i; + for (i=0 ; i < reader1.getFieldCount(); i++) + { + nameSet.insert(reader1.getFieldName(i)); + count++; + } + for (i=0 ; i < reader2.getFieldCount(); i++) + { + if (nameSet.find(reader2.getFieldName(i)) == nameSet.end()) + { + nameSet.insert(reader2.getFieldName(i)); + count++; + } + } + return count; +} + +//********************************************************************* +// mergeModuleValue() +// +RegError ORegistry::mergeModuleValue(OStoreStream& rTargetValue, + ORegKey* pTargetKey, + const OUString& sTargetPath, + const OUString& valueName, + RegistryTypeReader& reader, + RegistryTypeReader& reader2) +{ + sal_uInt16 index = 0; + RegistryTypeWriter_Api* pWriterApi; + + StringSet nameSet; + sal_uInt32 count = checkTypeReaders(reader, reader2, nameSet); + + if (count != reader.getFieldCount()) + { + pWriterApi = initRegistryTypeWriter_Api(); + + RegistryTypeWriter writer(pWriterApi, + reader.getTypeClass(), + reader.getTypeName(), + reader.getSuperTypeName(), + count, + 0, + 0); + + int i; + for (i=0 ; i < reader.getFieldCount(); i++) + { + writer.setFieldData(index, + reader.getFieldName(i), + reader.getFieldType(i), + reader.getFieldDoku(i), + reader.getFieldFileName(i), + reader.getFieldAccess(i), + reader.getFieldConstValue(i)); + index++; + } + for (i=0 ; i < reader2.getFieldCount(); i++) + { + if (nameSet.find(reader2.getFieldName(i)) == nameSet.end()) + { + writer.setFieldData(index, + reader2.getFieldName(i), + reader2.getFieldType(i), + reader2.getFieldDoku(i), + reader2.getFieldFileName(i), + reader2.getFieldAccess(i), + reader2.getFieldConstValue(i)); + index++; + } + } + + const sal_uInt8* pBlop = writer.getBlop(); + sal_uInt32 aBlopSize = writer.getBlopSize(); + + sal_uInt8 type = (sal_uInt8)RG_VALUETYPE_BINARY; + sal_uInt8* pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + aBlopSize); + + rtl_copyMemory(pBuffer, &type, 1); + writeUINT32(pBuffer+VALUE_TYPEOFFSET, aBlopSize); + rtl_copyMemory(pBuffer+VALUE_HEADEROFFSET, pBlop, aBlopSize); + + sal_uInt32 rwBytes; + if (rTargetValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+aBlopSize, rwBytes)) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + if (rwBytes != VALUE_HEADERSIZE+aBlopSize) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + rtl_freeMemory(pBuffer); + } + return REG_NO_ERROR; +} + +//********************************************************************* +// loadKeys() +// +RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey, + ORegKey* pSourceKey, + const OUString& keyName, + sal_uInt32 nCut, + sal_Bool bWarnings, + sal_Bool bReport) +{ + ORegKey* pTmpKey; + RegError _ret = REG_NO_ERROR; + OUString sRelPath(pSourceKey->getName().copy(nCut)); + OUString sFullPath; + + if(pTargetKey->getName().getLength() > 1) + sFullPath += pTargetKey->getName(); + sFullPath += sRelPath; + if (sRelPath.getLength() > 1 || sFullPath.getLength() == 0) + sFullPath += ROOT; + + OUString sFullKeyName = sFullPath; + OStoreDirectory rStoreDir; + + sFullKeyName += keyName; + + if (rStoreDir.create(pTargetKey->getStoreFile(), sFullPath, keyName, KEY_MODE_CREATE)) + { + return REG_CREATE_KEY_FAILED; + } + + if (m_openKeyTable.count(sFullKeyName) > 0) + { + m_openKeyTable[sFullKeyName]->setDeleted(sal_False); + } + + + if (_ret = pSourceKey->openKey(keyName, (RegKeyHandle*)&pTmpKey, RESOLVE_NOTHING)) + { + 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; + + if (iter.m_nAttrib & STORE_ATTRIB_ISDIR) + { + _ret = loadAndSaveKeys(pTargetKey, pTmpKey, + sName, nCut, bWarnings, bReport); + } else + { + _ret = loadAndSaveValue(pTargetKey, pTmpKey, + sName, nCut, bWarnings, bReport); + } + + if (_ret == REG_MERGE_ERROR || + (_ret == REG_MERGE_CONFLICT && bWarnings)) + { + pSourceKey->closeKey(pTmpKey); + return _ret; + } + + _err = rTmpStoreDir.next(iter); + } + + pSourceKey->closeKey(pTmpKey); + return _ret; +} + + +//********************************************************************* +// getRootKey() +// +ORegKey* ORegistry::getRootKey() +{ + m_openKeyTable[ROOT]->acquire(); + return m_openKeyTable[ROOT]; +} + + +//********************************************************************* +// getResolvedKeyName() +// +RegError ORegistry::getResolvedKeyName(RegKeyHandle hKey, + const OUString& keyName, + OUString& resolvedName, + sal_Bool firstLinkOnly) +{ + ORegKey* pKey; + + if ( !keyName.getLength() ) + return REG_INVALID_KEYNAME; + + REG_GUARD(m_mutex); + + if (hKey) + pKey = (ORegKey*)hKey; + else + pKey = m_openKeyTable[ROOT]; + + resolvedName = resolveLinks(pKey, keyName, firstLinkOnly); + + if ( resolvedName.getLength() ) + return REG_NO_ERROR; + else + return REG_DETECT_RECURSION; +} + +//********************************************************************* +// dumpRegistry() +// +RegError ORegistry::dumpRegistry(RegKeyHandle hKey) const +{ + ORegKey *pKey = (ORegKey*)hKey; + OUString sName; + RegError _ret = REG_NO_ERROR; + OStoreDirectory::iterator iter; + OStoreDirectory rStoreDir(pKey->getStoreDir()); + storeError _err = rStoreDir.first(iter); + + OString regName( OUStringToOString( getName(), RTL_TEXTENCODING_UTF8 ) ); + OString keyName( OUStringToOString( pKey->getName(), RTL_TEXTENCODING_UTF8 ) ); + fprintf(stdout, "Registry \"%s\":\n\n%s\n", regName.getStr(), keyName.getStr()); + + while ( _err == store_E_None ) + { + sName = iter.m_pszName; + + if (iter.m_nAttrib & STORE_ATTRIB_ISDIR) + { + _ret = dumpKey(pKey->getName(), sName, 1); + } else + { + _ret = dumpValue(pKey->getName(), sName, 1); + } + + if (_ret) + { + return _ret; + } + + _err = rStoreDir.next(iter); + } + + return REG_NO_ERROR; +} + + +//********************************************************************* +// dumpValue() +// +RegError ORegistry::dumpValue(const OUString& sPath, const OUString& sName, sal_Int16 nSpc) const +{ + OStoreStream rValue; + sal_uInt8* pBuffer; + sal_uInt32 valueSize; + RegValueType valueType; + OUString sFullPath(sPath); + OString sIndent; + storeAccessMode accessMode = VALUE_MODE_OPEN; + sal_Bool bLinkValue = sal_False; + + if (isReadOnly()) + { + accessMode = VALUE_MODE_OPENREAD; + } + + for (int i= 0; i < nSpc; i++) sIndent += " "; + + if (sFullPath.getLength() > 1) + { + sFullPath += ROOT; + } + if (rValue.create(m_file, sFullPath, sName, accessMode)) + { + return REG_VALUE_NOT_EXISTS; + } + + OUString tmpName( RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX) ); + tmpName += OUString( RTL_CONSTASCII_USTRINGPARAM("LINK_TARGET") ); + if (sName == tmpName) + { + bLinkValue = sal_True; + } + pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE); + + sal_uInt32 rwBytes; + if (rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes)) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (rwBytes != (VALUE_HEADERSIZE)) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + sal_uInt8 type = *((sal_uInt8*)pBuffer); + valueType = (RegValueType)type; + readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize); + + pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + if (rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, rwBytes)) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + if (rwBytes != valueSize) + { + rtl_freeMemory(pBuffer); + return REG_INVALID_VALUE; + } + + const sal_Char* indent = sIndent.getStr(); + switch (valueType) + { + case 0: + fprintf(stdout, "%sValue: Type = VALUETYPE_NOT_DEFINED\n", indent); + break; + case 1: + { + fprintf(stdout, "%sValue: Type = RG_VALUETYPE_LONG\n", indent); + fprintf(stdout, "%s Size = %d\n", indent, valueSize); + fprintf(stdout, "%s Data = ", indent); + + sal_Int32 value; + readINT32(pBuffer, value); + fprintf(stdout, "%d\n", value); + } + break; + case 2: + { + sal_Char* value = (sal_Char*)rtl_allocateMemory(valueSize); + readUtf8(pBuffer, value, valueSize); + + if (bLinkValue) + { + fprintf(stdout, "%sKEY: Type = RG_LINKTYPE\n", indent); + fprintf(stdout, "%s LinkTarget = \"%s\"\n", indent, value); + } else + { + fprintf(stdout, "%sValue: Type = RG_VALUETYPE_STRING\n", indent); + fprintf(stdout, "%s Size = %d\n", indent, valueSize); + fprintf(stdout, "%s Data = \"%s\"\n", indent, value); + } + + rtl_freeMemory(value); + } + break; + case 3: + { + sal_uInt32 size = (valueSize / 2) * sizeof(sal_Unicode); + fprintf(stdout, "%sValue: Type = RG_VALUETYPE_UNICODE\n", indent); + fprintf(stdout, "%s Size = %d\n", indent, valueSize); + fprintf(stdout, "%s Data = ", indent); + + sal_Unicode* value = new sal_Unicode[size]; + readString(pBuffer, value, size); + + OString uStr = OUStringToOString(value, RTL_TEXTENCODING_UTF8); + fprintf(stdout, "L\"%s\"\n", uStr.getStr()); + delete[] value; + } + break; + case 4: + { + fprintf(stdout, "%sValue: Type = RG_VALUETYPE_BINARY\n", indent); + fprintf(stdout, "%s Size = %d\n", indent, valueSize); + fprintf(stdout, "%s Data = ", indent); + + RegistryTypeReader_Api* pReaderApi; + + pReaderApi = initRegistryTypeReader_Api(); + + RegistryTypeReader reader(pReaderApi, pBuffer, valueSize, sal_False); + + sIndent += " "; + if (!dumpType(reader, sIndent)) + { + fprintf(stdout, "<unknown>\n"); + } + + } + break; + case 5: + { + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays + sal_uInt32 len = 0; + + readUINT32(pBuffer, len); + + fprintf(stdout, "%sValue: Type = RG_VALUETYPE_LONGLIST\n", indent); + fprintf(stdout, "%s Size = %d\n", indent, valueSize); + fprintf(stdout, "%s Len = %d\n", indent, len); + fprintf(stdout, "%s Data = ", indent); + + sal_Int32 longValue; + for (int i=0; i < len; i++) + { + readINT32(pBuffer+offset, longValue); + + if (offset > 4) + fprintf(stdout, "%s ", indent); + + fprintf(stdout, "%d = %d\n", i, longValue); + offset += 4; // 4 Bytes fuer sal_Int32 + } + } + break; + case 6: + { + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays + sal_uInt32 sLen = 0; + sal_uInt32 len = 0; + + readUINT32(pBuffer, len); + + fprintf(stdout, "%sValue: Type = RG_VALUETYPE_STRINGLIST\n", indent); + fprintf(stdout, "%s Size = %d\n", indent, valueSize); + fprintf(stdout, "%s Len = %d\n", indent, len); + fprintf(stdout, "%s Data = ", indent); + + sal_Char *pValue; + for (int i=0; i < len; i++) + { + readUINT32(pBuffer+offset, sLen); + + offset += 4; // 4 Bytes (sal_uInt32) fuer die Groesse des strings in Bytes + + pValue = (sal_Char*)rtl_allocateMemory(sLen); + readUtf8(pBuffer+offset, pValue, sLen); + + if (offset > 8) + fprintf(stdout, "%s ", indent); + + fprintf(stdout, "%d = \"%s\"\n", i, pValue); + offset += sLen; + } + } + break; + case 7: + { + sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays + sal_uInt32 sLen = 0; + sal_uInt32 len = 0; + + readUINT32(pBuffer, len); + + fprintf(stdout, "%sValue: Type = RG_VALUETYPE_UNICODELIST\n", indent); + fprintf(stdout, "%s Size = %d\n", indent, valueSize); + fprintf(stdout, "%s Len = %d\n", indent, len); + fprintf(stdout, "%s Data = ", indent); + + sal_Unicode *pValue; + OString uStr; + for (int i=0; i < len; i++) + { + readUINT32(pBuffer+offset, sLen); + + offset += 4; // 4 Bytes (sal_uInt32) fuer die Groesse des strings in Bytes + + pValue = (sal_Unicode*)rtl_allocateMemory((sLen / 2) * sizeof(sal_Unicode)); + readString(pBuffer+offset, pValue, sLen); + + if (offset > 8) + fprintf(stdout, "%s ", indent); + + uStr = OUStringToOString(pValue, RTL_TEXTENCODING_UTF8); + fprintf(stdout, "%d = L\"%s\"\n", i, uStr.getStr()); + + offset += sLen; + + rtl_freeMemory(pValue); + } + } + break; + } + + fprintf(stdout, "\n"); + + rtl_freeMemory(pBuffer); + return REG_NO_ERROR; +} + +//********************************************************************* +// dumpKey() +// +RegError ORegistry::dumpKey(const OUString& sPath, const OUString& sName, sal_Int16 nSpace) const +{ + OStoreDirectory rStoreDir; + OUString sFullPath(sPath); + OString sIndent; + storeAccessMode accessMode = KEY_MODE_OPEN; + RegError _ret = REG_NO_ERROR; + + if (isReadOnly()) + { + accessMode = KEY_MODE_OPENREAD; + } + + for (int i= 0; i < nSpace; i++) sIndent += " "; + + if (sFullPath.getLength() > 1) + sFullPath += ROOT; + + storeError _err = rStoreDir.create(m_file, sFullPath, sName, accessMode); + + if (_err == store_E_NotExists) + return REG_KEY_NOT_EXISTS; + else + if (_err == store_E_WrongFormat) + return REG_INVALID_KEY; + + fprintf(stdout, "%s/ %s\n", sIndent.getStr(), OUStringToOString(sName, RTL_TEXTENCODING_UTF8).getStr()); + + OUString sSubPath(sFullPath); + OUString sSubName; + sSubPath += sName; + + OStoreDirectory::iterator iter; + + _err = rStoreDir.first(iter); + + while ( _err == store_E_None) + { + sSubName = iter.m_pszName; + + if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR ) + { + _ret = dumpKey(sSubPath, sSubName, nSpace+2); + } else + { + _ret = dumpValue(sSubPath, sSubName, nSpace+2); + } + + if (_ret) + { + return _ret; + } + + _err = rStoreDir.next(iter); + } + + return REG_NO_ERROR; +} + +//********************************************************************* +// createLink() +// +RegError ORegistry::createLink(RegKeyHandle hKey, + const OUString& linkName, + const OUString& linkTarget) +{ + ORegKey* pKey; + + if ( !linkName.getLength() ) + { + return REG_INVALID_LINKNAME; + } + + REG_GUARD(m_mutex); + + if (hKey) + pKey = (ORegKey*)hKey; + else + pKey = m_openKeyTable[ROOT]; + + OUString sFullLinkName = resolveLinks(pKey, linkName, sal_True); + + if (sFullLinkName.getLength() == 0) + return REG_DETECT_RECURSION; + + OStoreDirectory rStoreDir; + OUString sFullPath(ROOT); + + sal_uInt32 tokenCount = sFullLinkName.getTokenCount('/'); + sal_uInt32 actToken = 0; + OUString token; + + token = sFullLinkName.getToken(actToken, '/'); + + while ( actToken < tokenCount && token.getLength() > 0 ) + { + if (rStoreDir.create(pKey->getStoreFile(), sFullPath, token, KEY_MODE_CREATE)) + { + return REG_CREATE_KEY_FAILED; + } + + sFullPath += token; + sFullPath += ROOT; + + token = sFullLinkName.getToken(++actToken, '/'); + } + + pKey = new ORegKey(sFullLinkName, linkTarget, rStoreDir, this); + delete pKey; + + return REG_NO_ERROR; +} + +//********************************************************************* +// deleteLink() +// +RegError ORegistry::deleteLink(RegKeyHandle hKey, const OUString& linkName) +{ + ORegKey* pKey; + + if ( !linkName.getLength() ) + { + return REG_INVALID_LINKNAME; + } + + REG_GUARD(m_mutex); + + if (hKey) + pKey = (ORegKey*)hKey; + else + pKey = m_openKeyTable[ROOT]; + + OUString tmpPath(linkName); + OUString tmpName; + OUString resolvedPath; + sal_Int32 lastIndex = tmpPath.lastIndexOf('/'); + + if ( lastIndex > 0 && tmpPath.getStr()[0] == '/') + { + tmpName = tmpPath.copy(lastIndex); + + OUString linkPath = tmpPath.copy(0, lastIndex); + + resolvedPath = resolveLinks(pKey, linkPath); + + if ( !resolvedPath.getLength() ) + { + return REG_DETECT_RECURSION; + } + + resolvedPath += tmpName; + } else + { + resolvedPath = pKey->getName(); + + if (lastIndex != 0 && resolvedPath.getLength() > 1) + resolvedPath += ROOT; + + resolvedPath += linkName; + } + + pKey = m_openKeyTable[ROOT]; + + RegKeyType keyType; + RegError ret = REG_NO_ERROR; + if (ret = pKey->getKeyType(resolvedPath, &keyType)) + return ret; + + if (keyType != RG_LINKTYPE) + return REG_INVALID_LINK; + + return eraseKey(pKey, resolvedPath, RESOLVE_PART); +} + +//********************************************************************* +// resolveLinks() +// +OUString ORegistry::resolveLinks(ORegKey* pKey, const OUString& path, sal_Bool firstLinkOnly) +{ + OUString resolvedPath(pKey->getName()); + sal_uInt32 tokenCount = path.getTokenCount('/'); + sal_uInt32 actToken = 0; + OUString token; + ORegKey* pLink = NULL; + + if (resolvedPath.getLength() > 1) + resolvedPath += ROOT; + + if ( path.getStr()[0] == '/' ) + token = path.getToken(++actToken, '/'); + else + token = path.getToken(actToken, '/'); + + while ( actToken < tokenCount && token.getLength() > 0 ) + { + pLink = resolveLink(pKey, resolvedPath, token); + + if (pLink) + { + OUString tmpName; + sal_Int32 lastIndex; + + while(pLink) + { + if (!insertRecursionLink(pLink)) + { + resetRecursionLinks(); + delete pLink; + return OUString(); + } + + + lastIndex = resolvedPath.lastIndexOf('/'); + tmpName = resolvedPath.copy(lastIndex + 1); + resolvedPath = resolvedPath.copy(0, lastIndex + 1); + + pLink = resolveLink(pKey, resolvedPath, tmpName); + } + + resetRecursionLinks(); + } + + token = path.getToken(++actToken, '/'); + if ( token.getLength() ) + resolvedPath += ROOT; + } + + return resolvedPath; +} + +//********************************************************************* +// resolveLink() +// +ORegKey* ORegistry::resolveLink(ORegKey* pKey, OUString& resolvedPath, const OUString& name) +{ + OStoreDirectory rStoreDir; + ORegKey* pTmpKey = NULL; + + if ( !rStoreDir.create(pKey->getStoreFile(), resolvedPath, + name, KEY_MODE_OPENREAD) ) + { + resolvedPath += name; + pTmpKey = new ORegKey(resolvedPath, rStoreDir, pKey->getRegistry()); + RegKeyType keyType; + sal_Bool bIsLink=sal_False; + if (!pTmpKey->getKeyType(OUString(), &keyType) && (keyType == RG_LINKTYPE)) + { + resolvedPath = pTmpKey->getLinkTarget(); + return pTmpKey; + } + + delete pTmpKey; + return NULL; + } else + { + resolvedPath += name; + return NULL; + } +} + +sal_Bool ORegistry::insertRecursionLink(ORegKey* pLink) +{ + if (m_recursionList.empty()) + { + m_recursionList.push_back(pLink); + } else + { + LinkList::iterator iter = m_recursionList.begin(); + + while (iter != m_recursionList.end()) + { + if ((*iter)->getName() == pLink->getName()) + return sal_False; + + iter++; + } + m_recursionList.push_back(pLink); + } + + return sal_True; +} + +sal_Bool ORegistry::resetRecursionLinks() +{ + LinkList::iterator iter = m_recursionList.begin(); + + while (iter != m_recursionList.end()) + { + delete *iter; + iter++; + } + + m_recursionList.erase(m_recursionList.begin(), m_recursionList.end()); + + return sal_True; +} + + diff --git a/registry/source/regimpl.hxx b/registry/source/regimpl.hxx new file mode 100644 index 000000000000..458766bafe17 --- /dev/null +++ b/registry/source/regimpl.hxx @@ -0,0 +1,266 @@ +/************************************************************************* + * + * $RCSfile: regimpl.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _REGIMPL_HXX_ +#define _REGIMPL_HXX_ + +#include <registry/registry.h> + +#ifndef _REGMAP_HXX_ +#include "regmap.hxx" +#endif + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef _STORE_STORE_HXX_ +#include <store/store.hxx> +#endif + +#define REG_PAGESIZE 512 + +#define REG_MODE_CREATE store_AccessCreate +#define REG_MODE_OPEN store_AccessReadWrite +#define REG_MODE_OPENREAD store_AccessReadOnly + +#define KEY_MODE_CREATE store_AccessCreate +#define KEY_MODE_OPEN store_AccessReadWrite +#define KEY_MODE_OPENREAD store_AccessReadOnly + + +#define VALUE_MODE_CREATE store_AccessCreate +#define VALUE_MODE_OPEN store_AccessReadWrite +#define VALUE_MODE_OPENREAD store_AccessReadOnly + +#define VALUE_PREFIX "$VL_" +#define VALUE_LINKTARGET "$VL_LINK_TARGET" + +// 5 Bytes = 1 (Byte fuer den Typ) + 4 (Bytes fuer die Groesse der Daten) +#define VALUE_HEADERSIZE 5 +#define VALUE_TYPEOFFSET 1 +#define VALUE_HEADEROFFSET 5 + +#define REG_CREATE 0x0004 // allow write accesses + +#define REG_GUARD(mutex) \ + Guard< Mutex > aGuard( mutex ); + +using namespace rtl; +using namespace osl; +using namespace store; + +enum RESOLVE +{ + // alle Links werden aufgeloest + RESOLVE_FULL, + // alles bis zum letzten TeilStueck wird aufgeloest + RESOLVE_PART, + // kein Link wird aufgeloest + RESOLVE_NOTHING +}; + +class ORegManager; +class RegistryTypeReader; + +class ORegistry +{ +public: + ORegistry(); + + sal_uInt32 acquire() + { return ++m_refCount; } + + sal_uInt32 release() + { return --m_refCount; } + + RegError initRegistry(const OUString& name, + RegAccessMode accessMode); + + RegError closeRegistry(); + + RegError destroyRegistry(const OUString& name); + + RegError createKey(RegKeyHandle hKey, + const OUString& keyName, + RegKeyHandle* phNewKey); + + RegError openKey(RegKeyHandle hKey, + const OUString& keyName, + RegKeyHandle* phOpenKey, + RESOLVE eResolve=RESOLVE_FULL); + + RegError closeKey(RegKeyHandle hKey); + + RegError deleteKey(RegKeyHandle hKey, const OUString& keyName); + + RegError loadKey(RegKeyHandle hKey, + const OUString& regFileName, + sal_Bool bWarings=sal_False, + sal_Bool bReport=sal_False); + + RegError saveKey(RegKeyHandle hKey, + const OUString& regFileName, + sal_Bool bWarings=sal_False, + sal_Bool bReport=sal_False); + + RegError dumpRegistry(RegKeyHandle hKey) const; + + RegError createLink(RegKeyHandle hKey, + const OUString& linkName, + const OUString& linkTarget); + + RegError deleteLink(RegKeyHandle hKey, + const OUString& linkName); + +public: + virtual ~ORegistry(); + + sal_Bool isKeyOpen(const OUString& keyName) const; + sal_Bool isReadOnly() const + { return m_readOnly; } + + sal_Bool isOpen() const + { return m_isOpen; } + + ORegKey* getRootKey(); + + const OStoreFile& getStoreFile() + { return m_file; } + + const OUString& getName() const + { return m_name; } + + RegError getResolvedKeyName(RegKeyHandle hKey, + const OUString& keyName, + OUString& resolvedName, + sal_Bool firstLinkOnly=sal_False); + + friend class ORegKey; +protected: + RegError eraseKey(ORegKey* pKey, + const OUString& keyName, + RESOLVE eResolve=RESOLVE_FULL); + + RegError deleteSubkeysAndValues(ORegKey* pKey, + RESOLVE eResolve=RESOLVE_FULL); + + sal_uInt32 countSubKeys(ORegKey* pKey); + + RegError loadAndSaveValue(ORegKey* pTargetKey, + ORegKey* pSourceKey, + const OUString& valueName, + sal_uInt32 nCut, + sal_Bool bWarnings=sal_False, + sal_Bool bReport=sal_False); + + RegError checkBlop(OStoreStream& rValue, + ORegKey* pTargetKey, + const OUString& sTargetPath, + const OUString& valueName, + sal_uInt32 srcValueSize, + sal_uInt8* pSrcBuffer, + sal_Bool bReport=sal_False); + + RegError mergeModuleValue(OStoreStream& rTargetValue, + ORegKey* pTargetKey, + const OUString& sTargetPath, + const OUString& valueName, + RegistryTypeReader& reader, + RegistryTypeReader& reader2); + + RegError loadAndSaveKeys(ORegKey* pTargetKey, + ORegKey* pSourceKey, + const OUString& keyName, + sal_uInt32 nCut, + sal_Bool bWarnings=sal_False, + sal_Bool bReport=sal_False); + + RegError dumpValue(const OUString& sPath, + const OUString& sName, + sal_Int16 nSpace) const; + + RegError dumpKey(const OUString& sPath, + const OUString& sName, + sal_Int16 nSpace) const; + + OUString resolveLinks(ORegKey* pKey, const OUString& path, sal_Bool firstLinkOnly=sal_False); + ORegKey* resolveLink(ORegKey* pKey, OUString& resolvedPath, const OUString& name); + + sal_Bool insertRecursionLink(ORegKey* pLink); + sal_Bool resetRecursionLinks(); + +protected: + + sal_uInt32 m_refCount; + Mutex m_mutex; + sal_Bool m_readOnly; + sal_Bool m_isOpen; + OUString m_name; + OStoreFile m_file; + KeyMap m_openKeyTable; + LinkList m_recursionList; + + const OUString ROOT; +}; + +#endif + diff --git a/registry/source/registry.cxx b/registry/source/registry.cxx new file mode 100644 index 000000000000..1e6f4af4335b --- /dev/null +++ b/registry/source/registry.cxx @@ -0,0 +1,793 @@ +/************************************************************************* + * + * $RCSfile: registry.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <registry/registry.h> + +#ifndef _REGISTRY_REGISTRY_HXX_ +#include <registry/registry.hxx> +#endif + +#ifndef _REGIMPL_HXX_ +#include "regimpl.hxx" +#endif + +#ifndef _REGKEY_HXX_ +#include "keyimpl.hxx" +#endif + +#include <vos/process.hxx> + +#if defined(WIN32) || defined(WNT) || defined(__OS2__) +#include <io.h> +#endif + +#if defined(UNX) +#include <stdlib.h> +#include <unistd.h> +#endif + +using namespace vos; + +#if defined ( GCC ) && ( defined ( SCO ) || defined ( NETBSD ) ) +ORealDynamicLoader* ODynamicLoader<Registry_Api>::m_pLoader = NULL; +#endif + +OString getTempName() +{ + OUString uTmpPattern; + sal_Char tmpPattern[512] = ""; + sal_Char *pTmpName = NULL; + + OStartupInfo StartupInfo; + + if (StartupInfo.getEnvironment(OUString( RTL_CONSTASCII_USTRINGPARAM("TMP") ), + uTmpPattern) != OStartupInfo::E_None) + { + if (StartupInfo.getEnvironment( OUString( RTL_CONSTASCII_USTRINGPARAM("TEMP") ), + uTmpPattern) != NAMESPACE_VOS(OStartupInfo)::E_None) + { +#if defined(WIN32) || defined(WNT) || defined(OS2) + strcpy(tmpPattern, "."); +#else + strcpy(tmpPattern, "/tmp"); +#endif + } + } + + if ( uTmpPattern.getLength() ) + { + strcpy(tmpPattern, OUStringToOString(uTmpPattern, RTL_TEXTENCODING_UTF8).getStr()); + } + +#if defined(WIN32) || defined(WNT) + strcat(tmpPattern, "\\reg_XXXXXX"); + pTmpName = mktemp(tmpPattern); +#endif + +#ifdef __OS2__ + strcpy(tmpPattern, tempnam(NULL, "reg_")); + pTmpName = tmpPattern; +#endif + +#ifdef UNX + strcat(tmpPattern, "/reg_XXXXXX"); + pTmpName = mktemp(tmpPattern); +#endif + + return OString(pTmpName); +} + +//********************************************************************* +// acquire +// +static void REGISTRY_CALLTYPE acquire(RegHandle hReg) +{ + ORegistry* pReg = (ORegistry*) hReg; + + if (pReg != NULL) + pReg->acquire(); +} + + +//********************************************************************* +// release +// +static void REGISTRY_CALLTYPE release(RegHandle hReg) +{ + ORegistry* pReg = (ORegistry*) hReg; + + if (pReg) + { + if (pReg->release() == 0) + { + delete pReg; + hReg = NULL; + } + } +} + + +//********************************************************************* +// getName +// +static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName) +{ + ORegistry* pReg; + + if (hReg) + { + pReg = (ORegistry*)hReg; + if ( pReg->isOpen() ) + { + rtl_uString_assign(pName, pReg->getName().pData); + return REG_NO_ERROR; + } else + { + rtl_uString_new(pName); + return REG_REGISTRY_NOT_OPEN; + } + } + + rtl_uString_new(pName); + return REG_INVALID_REGISTRY; +} + + +//********************************************************************* +// isReadOnly +// +static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg) +{ + if (hReg) + return ((ORegistry*)hReg)->isReadOnly(); + else + return sal_False; +} + + +//********************************************************************* +// createRegistry +// +static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName, + RegHandle* phRegistry) +{ + RegError ret; + + ORegistry* pReg = new ORegistry(); + if (ret = pReg->initRegistry(registryName, REG_CREATE)) + { + *phRegistry = NULL; + return ret; + } + + *phRegistry = pReg; + + return REG_NO_ERROR; +} + +//********************************************************************* +// openRootKey +// +static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg, + RegKeyHandle* phRootKey) +{ + ORegistry* pReg; + + if (hReg) + { + pReg = (ORegistry*)hReg; + if (!pReg->isOpen()) + return REG_REGISTRY_NOT_OPEN; + } else + { + phRootKey = NULL; + return REG_INVALID_REGISTRY; + } + + *phRootKey = pReg->getRootKey(); + + return REG_NO_ERROR; +} + + +//********************************************************************* +// openRegistry +// +static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName, + RegHandle* phRegistry, + RegAccessMode accessMode) +{ + RegError _ret; + + ORegistry* pReg = new ORegistry(); + if (_ret = pReg->initRegistry(registryName, accessMode)) + { + *phRegistry = NULL; + delete pReg; + return _ret; + } + + + *phRegistry = pReg; + + return REG_NO_ERROR; +} + +//********************************************************************* +// closeRegistry +// +static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg) +{ + ORegistry *pReg; + + if (hReg) + { + pReg = (ORegistry*)hReg; + if (!pReg->isOpen()) + return REG_REGISTRY_NOT_OPEN; + + RegError ret = REG_NO_ERROR; + if (pReg->release() == 0) + { + delete(pReg); + hReg = NULL; + } + else + ret = pReg->closeRegistry(); + + return ret; + } else + { + return REG_INVALID_REGISTRY; + } +} + + +//********************************************************************* +// destroyRegistry +// +static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg, + rtl_uString* registryName) +{ + ORegistry *pReg; + + if (hReg) + { + pReg = (ORegistry*)hReg; + if (!pReg->isOpen()) + return REG_INVALID_REGISTRY; + + RegError ret = REG_NO_ERROR; + if (!(ret = pReg->destroyRegistry(registryName))) + { + if (!registryName->length) + { + delete(pReg); + hReg = NULL; + } + } + return ret; + } else + { + return REG_INVALID_REGISTRY; + } +} + + +//********************************************************************* +// loadRegKey +// +static RegError REGISTRY_CALLTYPE loadKey(RegHandle hReg, + RegKeyHandle hKey, + 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 + { + return REG_INVALID_REGISTRY; + } + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->getRegistry() != pReg || pKey->isDeleted()) + return REG_INVALID_KEY; + } else + { + return REG_INVALID_KEY; + } + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + if (!pKey->openKey(keyName, (RegKeyHandle*)&pNewKey)) + { + pKey->closeKey(pNewKey); + pKey->deleteKey(keyName); + } + + if (_ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey)) + return _ret; + + if (_ret = pReg->loadKey(pNewKey, regFileName)) + { + pKey->closeKey(pNewKey); + pKey->deleteKey(keyName); + return _ret; + } + + return pKey->closeKey(pNewKey); +} + +//********************************************************************* +// saveKey +// +static RegError REGISTRY_CALLTYPE saveKey(RegHandle hReg, + RegKeyHandle hKey, + 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 + { + return REG_INVALID_REGISTRY; + } + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->getRegistry() != pReg || pKey->isDeleted()) + return REG_INVALID_KEY; + } else + { + return REG_INVALID_KEY; + } + + if (_ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey)) + return _ret; + + if (_ret = pReg->saveKey(pNewKey, regFileName)) + { + pKey->closeKey(pNewKey); + return _ret; + } + + return pKey->closeKey(pNewKey); +} + +//********************************************************************* +// mergeKey +// +static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg, + RegKeyHandle hKey, + rtl_uString* keyName, + rtl_uString* regFileName, + 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 + { + return REG_INVALID_REGISTRY; + } + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->getRegistry() != pReg || pKey->isDeleted()) + return REG_INVALID_KEY; + } else + { + return REG_INVALID_KEY; + } + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + if (keyName->length) + { + if (_ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey) ) + return _ret; + } else + { + pNewKey = pKey; + } + + /* + OString tmpName = getTempName(); + pReg->saveKey(pNewKey, tmpName, sal_False, sal_False); + */ + _ret = pKey->getRegistry()->loadKey(pNewKey, regFileName, bWarnings, bReport); + /* + if (_ret) + { + 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); + } + + destroyRegistry(hReg, tmpName); + + pKey->closeKey(pNewKey); + return _ret; + } + + destroyRegistry(hReg, tmpName); + */ + if ( pKey != pNewKey ) + _ret = pKey->closeKey(pNewKey); + + return _ret; +} + + +//********************************************************************* +// 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 + { + return REG_INVALID_REGISTRY; + } + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->getRegistry() != pReg || pKey->isDeleted()) + return REG_INVALID_KEY; + } else + { + return REG_INVALID_KEY; + } + + return pReg->dumpRegistry(hKey); +} + + +//********************************************************************* +// initRegistry_Api +// +void REGISTRY_CALLTYPE acquireKey(RegKeyHandle); +void REGISTRY_CALLTYPE releaseKey(RegKeyHandle); +sal_Bool REGISTRY_CALLTYPE isKeyReadOnly(RegKeyHandle); +RegError REGISTRY_CALLTYPE getKeyName(RegKeyHandle, rtl_uString**); +RegError REGISTRY_CALLTYPE createKey(RegKeyHandle, rtl_uString*, RegKeyHandle*); +RegError REGISTRY_CALLTYPE openKey(RegKeyHandle, rtl_uString*, RegKeyHandle*); +RegError REGISTRY_CALLTYPE openSubKeys(RegKeyHandle, rtl_uString*, RegKeyHandle**, sal_uInt32*); +RegError REGISTRY_CALLTYPE closeSubKeys(RegKeyHandle*, sal_uInt32); +RegError REGISTRY_CALLTYPE deleteKey(RegKeyHandle, rtl_uString*); +RegError REGISTRY_CALLTYPE closeKey(RegKeyHandle); +RegError REGISTRY_CALLTYPE setValue(RegKeyHandle, rtl_uString*, RegValueType, RegValue, sal_uInt32); +RegError REGISTRY_CALLTYPE setLongListValue(RegKeyHandle, rtl_uString*, sal_Int32*, sal_uInt32); +RegError REGISTRY_CALLTYPE setStringListValue(RegKeyHandle, rtl_uString*, sal_Char**, sal_uInt32); +RegError REGISTRY_CALLTYPE setUnicodeListValue(RegKeyHandle, rtl_uString*, sal_Unicode**, sal_uInt32); +RegError REGISTRY_CALLTYPE getValueInfo(RegKeyHandle, rtl_uString*, RegValueType*, sal_uInt32*); +RegError REGISTRY_CALLTYPE getValue(RegKeyHandle, rtl_uString*, RegValue); +RegError REGISTRY_CALLTYPE getLongListValue(RegKeyHandle, rtl_uString*, sal_Int32**, sal_uInt32*); +RegError REGISTRY_CALLTYPE getStringListValue(RegKeyHandle, rtl_uString*, sal_Char***, sal_uInt32*); +RegError REGISTRY_CALLTYPE getUnicodeListValue(RegKeyHandle, rtl_uString*, sal_Unicode***, sal_uInt32*); +RegError REGISTRY_CALLTYPE freeValueList(RegValueType, RegValue, sal_uInt32); +RegError REGISTRY_CALLTYPE createLink(RegKeyHandle, rtl_uString*, rtl_uString*); +RegError REGISTRY_CALLTYPE deleteLink(RegKeyHandle, rtl_uString*); +RegError REGISTRY_CALLTYPE getKeyType(RegKeyHandle, rtl_uString*, RegKeyType*); +RegError REGISTRY_CALLTYPE getLinkTarget(RegKeyHandle, rtl_uString*, rtl_uString**); +RegError REGISTRY_CALLTYPE getResolvedKeyName(RegKeyHandle, rtl_uString*, sal_Bool, rtl_uString**); +RegError REGISTRY_CALLTYPE getKeyNames(RegKeyHandle, rtl_uString*, rtl_uString***, sal_uInt32*); +RegError REGISTRY_CALLTYPE freeKeyNames(rtl_uString**, sal_uInt32); + + +extern "C" Registry_Api* REGISTRY_CALLTYPE initRegistry_Api(void) +{ + static Registry_Api aApi= {&acquire, + &release, + &isReadOnly, + &openRootKey, + &getName, + &createRegistry, + &openRegistry, + &closeRegistry, + &destroyRegistry, + &loadKey, + &saveKey, + &mergeKey, + &dumpRegistry, + &acquireKey, + &releaseKey, + &isKeyReadOnly, + &getKeyName, + &createKey, + &openKey, + &openSubKeys, + &closeSubKeys, + &deleteKey, + &closeKey, + &setValue, + &setLongListValue, + &setStringListValue, + &setUnicodeListValue, + &getValueInfo, + &getValue, + &getLongListValue, + &getStringListValue, + &getUnicodeListValue, + &freeValueList, + &createLink, + &deleteLink, + &getKeyType, + &getLinkTarget, + &getResolvedKeyName, + &getKeyNames, + &freeKeyNames}; + + return (&aApi); +} + + +//********************************************************************* +// reg_loadRegKey +// +RegError REGISTRY_CALLTYPE reg_loadKey(RegKeyHandle hKey, + rtl_uString* keyName, + rtl_uString* regFileName) +{ + ORegKey *pKey; + + if (hKey) + pKey = (ORegKey*)hKey; + else + return REG_INVALID_KEY; + + return loadKey(pKey->getRegistry(), hKey, keyName, regFileName); +} + +//********************************************************************* +// reg_saveKey +// +RegError REGISTRY_CALLTYPE reg_saveKey(RegKeyHandle hKey, + rtl_uString* keyName, + rtl_uString* regFileName) +{ + ORegKey *pKey; + + if (hKey) + pKey = (ORegKey*)hKey; + else + return REG_INVALID_KEY; + + return saveKey(pKey->getRegistry(), hKey, keyName, regFileName); +} + +//********************************************************************* +// reg_mergeKey +// +RegError REGISTRY_CALLTYPE reg_mergeKey(RegKeyHandle hKey, + rtl_uString* keyName, + rtl_uString* regFileName, + sal_Bool bWarnings, + sal_Bool bReport) +{ + ORegKey *pKey; + + if (hKey) + pKey = (ORegKey*)hKey; + else + return REG_INVALID_KEY; + + return mergeKey(pKey->getRegistry(), hKey, keyName, regFileName, bWarnings, bReport); +} + +//********************************************************************* +// reg_createRegistry +// +RegError REGISTRY_CALLTYPE reg_createRegistry(rtl_uString* registryName, + RegHandle* phRegistry) +{ + RegError ret; + + ORegistry* pReg = new ORegistry(); + if (ret = pReg->initRegistry(registryName, REG_CREATE)) + { + *phRegistry = NULL; + return ret; + } + + *phRegistry = pReg; + + return REG_NO_ERROR; +} + +//********************************************************************* +// reg_openRootKey +// +RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry, + RegKeyHandle* phRootKey) +{ + return openRootKey(hRegistry, phRootKey); +} + + +//********************************************************************* +// reg_getName +// +const RegError REGISTRY_CALLTYPE reg_getName(RegHandle hRegistry, rtl_uString** pName) +{ + return getName(hRegistry, pName); +} + + +//********************************************************************* +// reg_isReadOnly +// +sal_Bool REGISTRY_CALLTYPE reg_isReadOnly(RegHandle hRegistry) +{ + return isReadOnly(hRegistry); +} + + +//********************************************************************* +// reg_openRegistry +// +RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName, + RegHandle* phRegistry, + RegAccessMode accessMode) +{ + RegError _ret; + + ORegistry* pReg = new ORegistry(); + if (_ret = pReg->initRegistry(registryName, accessMode)) + { + *phRegistry = NULL; + return _ret; + } + + *phRegistry = pReg; + + return REG_NO_ERROR; +} + +//********************************************************************* +// reg_closeRegistry +// +RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry) +{ + ORegistry* pReg; + + if (hRegistry) + { + pReg = (ORegistry*)hRegistry; + delete(pReg); + return REG_NO_ERROR; + } else + { + return REG_REGISTRY_NOT_OPEN; + } +} + + +//********************************************************************* +// reg_destroyRegistry +// +RegError REGISTRY_CALLTYPE reg_destroyRegistry(RegHandle hRegistry, + rtl_uString* registryName) +{ + return destroyRegistry(hRegistry, registryName); +} + + +//********************************************************************* +// reg_dumpRegistry +// +RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey) +{ + ORegKey *pKey; + + if (hKey) + pKey = (ORegKey*)hKey; + else + return REG_INVALID_KEY; + + return dumpRegistry(pKey->getRegistry(), hKey); +} + + diff --git a/registry/source/regkey.cxx b/registry/source/regkey.cxx new file mode 100644 index 000000000000..7da6044705a2 --- /dev/null +++ b/registry/source/regkey.cxx @@ -0,0 +1,1298 @@ +/************************************************************************* + * + * $RCSfile: regkey.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:43 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _REGISTRY_REGISTRY_HXX_ +#include <registry/registry.hxx> +#endif + +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + +#ifndef _REGIMPL_HXX_ +#include "regimpl.hxx" +#endif + +#ifndef _KEYIMPL_HXX_ +#include "keyimpl.hxx" +#endif + + +//********************************************************************* +// acquireKey +// +void REGISTRY_CALLTYPE acquireKey(RegKeyHandle hKey) +{ + ORegKey* pKey = (ORegKey*) hKey; + + if (pKey != NULL) + pKey->acquire(); +} + + +//********************************************************************* +// releaseKey +// +void REGISTRY_CALLTYPE releaseKey(RegKeyHandle hKey) +{ + ORegKey* pKey = (ORegKey*) hKey; + + if (pKey) + { + if (pKey->release() == 0) + delete pKey; + } +} + + +//********************************************************************* +// isKeyReadOnly +// +sal_Bool REGISTRY_CALLTYPE isKeyReadOnly(RegKeyHandle hKey) +{ + if (hKey) + { + return ((ORegKey*)hKey)->isReadOnly(); + } else + { + return sal_False; + } +} + + +//********************************************************************* +// getKeyName +// +RegError REGISTRY_CALLTYPE getKeyName(RegKeyHandle hKey, rtl_uString** pKeyName) +{ + if (hKey) + { + rtl_uString_assign( pKeyName, ((ORegKey*)hKey)->getName().pData ); + return REG_NO_ERROR; + } else + { + rtl_uString_new(pKeyName); + return REG_INVALID_KEY; + } +} + + +//********************************************************************* +// createKey +// +RegError REGISTRY_CALLTYPE createKey(RegKeyHandle hKey, + rtl_uString* keyName, + RegKeyHandle* phNewKey) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + { + phNewKey = NULL; + return REG_INVALID_KEY; + } + } else + { + phNewKey = NULL; + return REG_INVALID_KEY; + } + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + return pKey->createKey(keyName, phNewKey); +} + +//********************************************************************* +// openKey +// +RegError REGISTRY_CALLTYPE openKey(RegKeyHandle hKey, + rtl_uString* keyName, + RegKeyHandle* phOpenKey) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + { + phOpenKey = NULL; + return REG_INVALID_KEY; + } + } else + { + phOpenKey = NULL; + return REG_INVALID_KEY; + } + + return pKey->openKey(keyName, phOpenKey); +} + +//********************************************************************* +// openSubKeys +// +RegError REGISTRY_CALLTYPE openSubKeys(RegKeyHandle hKey, + rtl_uString* keyName, + RegKeyHandle** pphSubKeys, + sal_uInt32* pnSubKeys) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + { + pphSubKeys = NULL; + return REG_INVALID_KEY; + } + } else + { + pphSubKeys = NULL; + return REG_INVALID_KEY; + } + + return pKey->openSubKeys(keyName, pphSubKeys, pnSubKeys); +} + +//********************************************************************* +// closeSubKeys +// +RegError REGISTRY_CALLTYPE closeSubKeys(RegKeyHandle* phSubKeys, + sal_uInt32 nSubKeys) +{ + RegError _ret = REG_NO_ERROR; + + if (phSubKeys) + { + ORegistry* pReg = NULL; + + pReg = ((ORegKey*)phSubKeys[0])->getRegistry(); + + for (int i=0; (i < nSubKeys) && (_ret == REG_NO_ERROR); i++) + { + _ret = pReg->closeKey(phSubKeys[i]); + } + + rtl_freeMemory(phSubKeys); + } + else + _ret = REG_INVALID_KEY; + + return _ret; +} + + +//********************************************************************* +// deleteKey +// +RegError REGISTRY_CALLTYPE deleteKey(RegKeyHandle hKey, + rtl_uString* keyName) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + return pKey->deleteKey(keyName); +} + +//********************************************************************* +// closeKey +// +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 + return REG_INVALID_KEY; + + return REG_NO_ERROR; +} + + +//********************************************************************* +// setValue +// +RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, + rtl_uString* keyName, + RegValueType valueType, + RegValue pData, + sal_uInt32 valueSize) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret1, _ret2; + if (_ret1 = pKey->openKey(keyName, &hSubKey)) + return _ret1; + + pSubKey = (ORegKey*)hSubKey; + if (_ret1 = pSubKey->setValue(valueName, valueType, pData, valueSize)) + { + if (_ret2 = pKey->closeKey(hSubKey)) + return _ret2; + else + return _ret1; + } + + return pKey->closeKey(hSubKey); + } + + return pKey->setValue(valueName, valueType, pData, valueSize); +} + +//********************************************************************* +// setLongValueList +// +RegError REGISTRY_CALLTYPE setLongListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Int32* pValueList, + sal_uInt32 len) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret1, _ret2; + if (_ret1 = pKey->openKey(keyName, &hSubKey)) + return _ret1; + + pSubKey = (ORegKey*)hSubKey; + if (_ret1 = pSubKey->setLongListValue(valueName, pValueList, len)) + { + if (_ret2 = pKey->closeKey(hSubKey)) + return _ret2; + else + return _ret1; + } + + return pKey->closeKey(hSubKey); + } + + return pKey->setLongListValue(valueName, pValueList, len); +} + +//********************************************************************* +// setStringValueList +// +RegError REGISTRY_CALLTYPE setStringListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Char** pValueList, + sal_uInt32 len) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret1, _ret2; + if (_ret1 = pKey->openKey(keyName, &hSubKey)) + return _ret1; + + pSubKey = (ORegKey*)hSubKey; + if (_ret1 = pSubKey->setStringListValue(valueName, pValueList, len)) + { + if (_ret2 = pKey->closeKey(hSubKey)) + return _ret2; + else + return _ret1; + } + + return pKey->closeKey(hSubKey); + } + + return pKey->setStringListValue(valueName, pValueList, len); +} + +//********************************************************************* +// setUnicodeValueList +// +RegError REGISTRY_CALLTYPE setUnicodeListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Unicode** pValueList, + sal_uInt32 len) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret1, _ret2; + if (_ret1 = pKey->openKey(keyName, &hSubKey)) + return _ret1; + + pSubKey = (ORegKey*)hSubKey; + if (_ret1 = pSubKey->setUnicodeListValue(valueName, pValueList, len)) + { + if (_ret2 = pKey->closeKey(hSubKey)) + return _ret2; + else + return _ret1; + } + + return pKey->closeKey(hSubKey); + } + + return pKey->setUnicodeListValue(valueName, pValueList, len); +} + +//********************************************************************* +// getValueInfo +// +RegError REGISTRY_CALLTYPE getValueInfo(RegKeyHandle hKey, + rtl_uString* keyName, + RegValueType* pValueType, + sal_uInt32* pValueSize) +{ + ORegKey* pKey; + RegValueType valueType; + sal_uInt32 valueSize; + + *pValueType = RG_VALUETYPE_NOT_DEFINED; + *pValueSize = 0; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret; + if (_ret = pKey->openKey(keyName, &hSubKey)) + return _ret; + + pSubKey = (ORegKey*)hSubKey; + if (pSubKey->getValueInfo(valueName, &valueType, &valueSize)) + { + if (_ret = pKey->closeKey(hSubKey)) + return _ret; + else + return REG_INVALID_VALUE; + } + + *pValueType = valueType; + *pValueSize = valueSize; + + return pKey->closeKey(hSubKey); + } + + + if (pKey->getValueInfo(valueName, &valueType, &valueSize)) + { + return REG_INVALID_VALUE; + } + + *pValueType = valueType; + *pValueSize = valueSize; + + return REG_NO_ERROR; +} + +//********************************************************************* +// getValueInfo +// +RegError REGISTRY_CALLTYPE getValue(RegKeyHandle hKey, + rtl_uString* keyName, + RegValue pValue) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + { + pValue = NULL; + return REG_INVALID_KEY; + } + } else + { + pValue = NULL; + return REG_INVALID_KEY; + } + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret1, _ret2; + if (_ret1 = pKey->openKey(keyName, &hSubKey)) + { + pValue = NULL; + return _ret1; + } + + pSubKey = (ORegKey*)hSubKey; + if (_ret1 = pSubKey->getValue(valueName, pValue)) + { + if (_ret2 = pKey->closeKey(hSubKey)) + { + pValue = NULL; + return _ret2; + } else + { + pValue = NULL; + return _ret1; + } + } + + return pKey->closeKey(hSubKey); + } + + return pKey->getValue(valueName, pValue); +} + +//********************************************************************* +// getLongValueList +// +RegError REGISTRY_CALLTYPE getLongListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Int32** pValueList, + sal_uInt32* pLen) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + { + pValueList = NULL; + *pLen = 0; + return REG_INVALID_KEY; + } + } else + { + pValueList = NULL; + *pLen = 0; + return REG_INVALID_KEY; + } + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret1, _ret2; + if (_ret1 = pKey->openKey(keyName, &hSubKey)) + { + pValueList = NULL; + *pLen = 0; + return _ret1; + } + + pSubKey = (ORegKey*)hSubKey; + + if (_ret1 = pSubKey->getLongListValue(valueName, pValueList, pLen)) + { + if (_ret2 = pKey->closeKey(hSubKey)) + { + pValueList = NULL; + *pLen = 0; + return _ret2; + } else + { + pValueList = NULL; + *pLen = 0; + return _ret1; + } + } + + return pKey->closeKey(hSubKey); + } + + return pKey->getLongListValue(valueName, pValueList, pLen); +} + +//********************************************************************* +// getStringValueList +// +RegError REGISTRY_CALLTYPE getStringListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Char*** pValueList, + sal_uInt32* pLen) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + { + pValueList = NULL; + *pLen = 0; + return REG_INVALID_KEY; + } + } else + { + pValueList = NULL; + *pLen = 0; + return REG_INVALID_KEY; + } + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret1, _ret2; + if ((_ret1 = pKey->openKey(keyName, &hSubKey))) + { + pValueList = NULL; + *pLen = 0; + return _ret1; + } + + pSubKey = (ORegKey*)hSubKey; + + if (_ret1 = pSubKey->getStringListValue(valueName, pValueList, pLen)) + { + if (_ret2 = pKey->closeKey(hSubKey)) + { + pValueList = NULL; + *pLen = 0; + return _ret2; + } else + { + pValueList = NULL; + *pLen = 0; + return _ret1; + } + } + + return pKey->closeKey(hSubKey); + } + + return pKey->getStringListValue(valueName, pValueList, pLen); +} + +//********************************************************************* +// getUnicodeListValue +// +RegError REGISTRY_CALLTYPE getUnicodeListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Unicode*** pValueList, + sal_uInt32* pLen) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + { + pValueList = NULL; + *pLen = 0; + return REG_INVALID_KEY; + } + } else + { + pValueList = NULL; + *pLen = 0; + return REG_INVALID_KEY; + } + + OUString valueName( RTL_CONSTASCII_USTRINGPARAM("value") ); + if (keyName->length) + { + RegKeyHandle hSubKey; + ORegKey* pSubKey; + RegError _ret1, _ret2; + if (_ret1 = pKey->openKey(keyName, &hSubKey)) + { + pValueList = NULL; + *pLen = 0; + return _ret1; + } + + pSubKey = (ORegKey*)hSubKey; + + if (_ret1 = pSubKey->getUnicodeListValue(valueName, pValueList, pLen)) + { + if (_ret2 = pKey->closeKey(hSubKey)) + { + pValueList = NULL; + *pLen = 0; + return _ret2; + } else + { + pValueList = NULL; + *pLen = 0; + return _ret1; + } + } + + return pKey->closeKey(hSubKey); + } + + return pKey->getUnicodeListValue(valueName, pValueList, pLen); +} + +//********************************************************************* +// freeValueList +// +RegError REGISTRY_CALLTYPE freeValueList(RegValueType valueType, + RegValue pValueList, + sal_uInt32 len) +{ + switch (valueType) + { + case 5: + { + sal_Int32* pVList = (sal_Int32*)pValueList; + rtl_freeMemory(pValueList); + } + break; + case 6: + { + sal_Char** pVList = (sal_Char**)pValueList; + for (int i=0; i < len; i++) + { + rtl_freeMemory(pVList[i]); + } + + rtl_freeMemory(pVList); + } + break; + case 7: + { + sal_Unicode** pVList = (sal_Unicode**)pValueList; + for (int i=0; i < len; i++) + { + rtl_freeMemory(pVList[i]); + } + + rtl_freeMemory(pVList); + } + break; + default: + return REG_INVALID_VALUE; + } + + pValueList = NULL; + return REG_NO_ERROR; +} + + +//********************************************************************* +// createLink +// +RegError REGISTRY_CALLTYPE createLink(RegKeyHandle hKey, + rtl_uString* linkName, + rtl_uString* linkTarget) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + return pKey->createLink(linkName, linkTarget); +} + +//********************************************************************* +// deleteLink +// +RegError REGISTRY_CALLTYPE deleteLink(RegKeyHandle hKey, + rtl_uString* linkName) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + if (pKey->isReadOnly()) + return REG_REGISTRY_READONLY; + + return pKey->deleteLink(linkName); +} + +//********************************************************************* +// getKeyType +// +RegError REGISTRY_CALLTYPE getKeyType(RegKeyHandle hKey, + rtl_uString* keyName, + RegKeyType* pKeyType) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + return pKey->getKeyType(keyName, pKeyType); +} + +//********************************************************************* +// getLinkTarget +// +RegError REGISTRY_CALLTYPE getLinkTarget(RegKeyHandle hKey, + rtl_uString* linkName, + rtl_uString** pLinkTarget) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + OUString linkTarget; + RegError ret = pKey->getLinkTarget(linkName, linkTarget); + if (!ret) + rtl_uString_assign(pLinkTarget, linkTarget.pData); + return ret; +} + + +//********************************************************************* +// getName +// +RegError REGISTRY_CALLTYPE getResolvedKeyName(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Bool firstLinkOnly, + rtl_uString** pResolvedName) +{ + ORegKey *pKey; + RegError _ret = REG_NO_ERROR; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + OUString resolvedName; + _ret = pKey->getResolvedKeyName(keyName, resolvedName, firstLinkOnly); + if (!_ret) + rtl_uString_assign(pResolvedName, resolvedName.pData); + return _ret; +} + + +//********************************************************************* +// getKeyNames +// +RegError REGISTRY_CALLTYPE getKeyNames(RegKeyHandle hKey, + rtl_uString* keyName, + rtl_uString*** pSubKeyNames, + sal_uInt32* pnSubKeys) +{ + ORegKey* pKey; + + if (hKey) + { + pKey = (ORegKey*)hKey; + + if (pKey->isDeleted()) + return REG_INVALID_KEY; + } else + return REG_INVALID_KEY; + + return pKey->getKeyNames(keyName, pSubKeyNames, pnSubKeys); +} + +//********************************************************************* +// freeKeyNames +// +RegError REGISTRY_CALLTYPE freeKeyNames(rtl_uString** pKeyNames, + sal_uInt32 nKeys) +{ + for (int i=0; i <nKeys; i++) + { + rtl_uString_release(pKeyNames[i]); + } + + rtl_freeMemory(pKeyNames); + + return REG_NO_ERROR; +} + +//********************************************************************* +// C API +// + +//********************************************************************* +// reg_createKey +// +RegError REGISTRY_CALLTYPE reg_createKey(RegKeyHandle hKey, + rtl_uString* keyName, + RegKeyHandle* phNewKey) +{ + if (!hKey) + return REG_INVALID_KEY; + + return createKey(hKey, keyName, phNewKey); +} + +//********************************************************************* +// reg_openKey +// +RegError REGISTRY_CALLTYPE reg_openKey(RegKeyHandle hKey, + rtl_uString* keyName, + RegKeyHandle* phOpenKey) +{ + if (!hKey) + return REG_INVALID_KEY; + + return openKey(hKey, keyName, phOpenKey); +} + +//********************************************************************* +// reg_openSubKeys +// +RegError REGISTRY_CALLTYPE reg_openSubKeys(RegKeyHandle hKey, + rtl_uString* keyName, + RegKeyHandle** pphSubKeys, + sal_uInt32* pnSubKeys) +{ + if (!hKey) + return REG_INVALID_KEY; + + return openSubKeys(hKey, keyName, pphSubKeys, pnSubKeys); +} + +//********************************************************************* +// reg_closeSubKeys +// +RegError REGISTRY_CALLTYPE reg_closeSubKeys(RegKeyHandle* pphSubKeys, + sal_uInt32 nSubKeys) +{ + if (!pphSubKeys) + return REG_INVALID_KEY; + + return closeSubKeys(pphSubKeys, nSubKeys); +} + +//********************************************************************* +// reg_deleteKey +// +RegError REGISTRY_CALLTYPE reg_deleteKey(RegKeyHandle hKey, + rtl_uString* keyName) +{ + if (!hKey) + return REG_INVALID_KEY; + + return deleteKey(hKey, keyName); +} + +//********************************************************************* +// reg_closeKey +// +RegError REGISTRY_CALLTYPE reg_closeKey(RegKeyHandle hKey) +{ + if (!hKey) + return REG_INVALID_KEY; + + return closeKey(hKey); +} + + +//********************************************************************* +// reg_getKeyName +// +const RegError REGISTRY_CALLTYPE reg_getKeyName(RegKeyHandle hKey, rtl_uString** pKeyName) +{ + if (hKey) + { + rtl_uString_assign( pKeyName, ((ORegKey*)hKey)->getName().pData ); + return REG_NO_ERROR; + } else + { + rtl_uString_new( pKeyName ); + return REG_INVALID_KEY; + } +} + +//********************************************************************* +// reg_setValue +// +RegError REGISTRY_CALLTYPE reg_setValue(RegKeyHandle hKey, + rtl_uString* keyName, + RegValueType valueType, + RegValue pData, + sal_uInt32 valueSize) +{ + if (!hKey) + return REG_INVALID_KEY; + + return setValue(hKey, keyName, valueType, pData, valueSize); +} + +//********************************************************************* +// reg_setLongListValue +// +RegError REGISTRY_CALLTYPE reg_setLongListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Int32* pValueList, + sal_uInt32 len) +{ + if (!hKey) + return REG_INVALID_KEY; + + return setLongListValue(hKey, keyName, pValueList, len); +} + +//********************************************************************* +// reg_setStringListValue +// +RegError REGISTRY_CALLTYPE reg_setStringListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Char** pValueList, + sal_uInt32 len) +{ + if (!hKey) + return REG_INVALID_KEY; + + return setStringListValue(hKey, keyName, pValueList, len); +} + +//********************************************************************* +// reg_setUnicodeListValue +// +RegError REGISTRY_CALLTYPE reg_setUnicodeListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Unicode** pValueList, + sal_uInt32 len) +{ + if (!hKey) + return REG_INVALID_KEY; + + return setUnicodeListValue(hKey, keyName, pValueList, len); +} + +//********************************************************************* +// reg_getValueInfo +// +RegError REGISTRY_CALLTYPE reg_getValueInfo(RegKeyHandle hKey, + rtl_uString* keyName, + RegValueType* pValueType, + sal_uInt32* pValueSize) +{ + if (!hKey) + return REG_INVALID_KEY; + + return getValueInfo(hKey, keyName, pValueType, pValueSize); +} + +//********************************************************************* +// reg_getValueInfo +// +RegError REGISTRY_CALLTYPE reg_getValue(RegKeyHandle hKey, + rtl_uString* keyName, + RegValue pData) +{ + if (!hKey) + return REG_INVALID_KEY; + + return getValue(hKey, keyName, pData); +} + +//********************************************************************* +// reg_getLongListValue +// +RegError REGISTRY_CALLTYPE reg_getLongListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Int32** pValueList, + sal_uInt32* pLen) +{ + if (!hKey) + return REG_INVALID_KEY; + + return getLongListValue(hKey, keyName, pValueList, pLen); +} + +//********************************************************************* +// reg_getStringListValue +// +RegError REGISTRY_CALLTYPE reg_getStringListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Char*** pValueList, + sal_uInt32* pLen) +{ + if (!hKey) + return REG_INVALID_KEY; + + return getStringListValue(hKey, keyName, pValueList, pLen); +} + +//********************************************************************* +// reg_getUnicodeListValue +// +RegError REGISTRY_CALLTYPE reg_getUnicodeListValue(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Unicode*** pValueList, + sal_uInt32* pLen) +{ + if (!hKey) + return REG_INVALID_KEY; + + return getUnicodeListValue(hKey, keyName, pValueList, pLen); +} + +//********************************************************************* +// reg_freeValueList +// +RegError REGISTRY_CALLTYPE reg_freeValueList(RegValueType valueType, + RegValue pValueList, + sal_uInt32 len) +{ + if (pValueList) + return freeValueList(valueType, pValueList, len); + else + return REG_INVALID_VALUE; +} + +//********************************************************************* +// reg_createLink +// +RegError REGISTRY_CALLTYPE reg_createLink(RegKeyHandle hKey, + rtl_uString* linkName, + rtl_uString* linkTarget) +{ + if (!hKey) + return REG_INVALID_KEY; + + return createLink(hKey, linkName, linkTarget); +} + +//********************************************************************* +// reg_deleteLink +// +RegError REGISTRY_CALLTYPE reg_deleteLink(RegKeyHandle hKey, + rtl_uString* linkName) +{ + if (!hKey) + return REG_INVALID_KEY; + + return deleteLink(hKey, linkName); +} + +//********************************************************************* +// reg_getKeyType +// +RegError REGISTRY_CALLTYPE reg_getKeyType(RegKeyHandle hKey, + rtl_uString* keyName, + RegKeyType* pKeyType) +{ + if (!hKey) + return REG_INVALID_KEY; + + return getKeyType(hKey, keyName, pKeyType); +} + +//********************************************************************* +// reg_getLinkTarget +// +RegError REGISTRY_CALLTYPE reg_getLinkTarget(RegKeyHandle hKey, + rtl_uString* linkName, + rtl_uString** pLinkTarget) +{ + if (!hKey) + return REG_INVALID_KEY; + + return getLinkTarget(hKey, linkName, pLinkTarget); +} + + +//********************************************************************* +// reg_getResolvedKeyName +// +RegError REGISTRY_CALLTYPE reg_getResolvedKeyName(RegKeyHandle hKey, + rtl_uString* keyName, + sal_Bool firstLinkOnly, + rtl_uString** pResolvedName) +{ + ORegKey *pKey; + + if (hKey) + pKey = (ORegKey*)hKey; + else + return REG_INVALID_KEY; + + return getResolvedKeyName(hKey, keyName, firstLinkOnly, pResolvedName); +} + + diff --git a/registry/source/regmap.hxx b/registry/source/regmap.hxx new file mode 100644 index 000000000000..1bf07bb3a69a --- /dev/null +++ b/registry/source/regmap.hxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * $RCSfile: regmap.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:43 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _REGMAP_HXX_ +#define _REGMAP_HXX_ + +#if STLPORT_VERSION<321 +#include <hash_map.h> +#include <list.h> +#include <set.h> +#else +#include <hash_map> +#include <list> +#include <set> +#endif + +#ifndef _VOS_MACROS_HXX_ +#include <vos/macros.hxx> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +using namespace rtl; + +class ORegKey; + +struct EqualString +{ + bool operator()(const OUString& str1, const OUString& str2) const + { + return (str1 == str2); + } +}; + +struct HashString +{ + size_t operator()(const OUString& str) const + { + return str.hashCode(); + } +}; + +struct LessString +{ + bool operator()(const OUString& str1, const OUString& str2) const + { + return (str1 < str2); + } +}; + +typedef NAMESPACE_STD(hash_map) <OUString, ORegKey*, HashString, EqualString> KeyMap; + +typedef NAMESPACE_STD(list) <ORegKey*> LinkList; + +typedef NAMESPACE_STD(set) <OUString, LessString> StringSet; + +#endif |