summaryrefslogtreecommitdiffstats
path: root/registry
diff options
context:
space:
mode:
Diffstat (limited to 'registry')
-rw-r--r--registry/Executable_regview.mk34
-rw-r--r--registry/IwyuFilter_registry.yaml14
-rw-r--r--registry/Library_reg.mk37
-rw-r--r--registry/Makefile14
-rw-r--r--registry/Module_registry.mk20
-rw-r--r--registry/README.md15
-rw-r--r--registry/StaticLibrary_registry_helper.mk17
-rw-r--r--registry/inc/regapi.hxx87
-rw-r--r--registry/source/keyimpl.cxx927
-rw-r--r--registry/source/keyimpl.hxx140
-rw-r--r--registry/source/reflcnst.hxx188
-rw-r--r--registry/source/reflread.cxx1609
-rw-r--r--registry/source/reflwrit.cxx79
-rw-r--r--registry/source/regimpl.cxx1177
-rw-r--r--registry/source/regimpl.hxx123
-rw-r--r--registry/source/registry.cxx301
-rw-r--r--registry/source/regkey.cxx618
-rw-r--r--registry/source/regkey.hxx66
-rw-r--r--registry/test/makefile.mk81
-rw-r--r--registry/test/regdiagnose.h38
-rw-r--r--registry/test/testmerge.cxx405
-rw-r--r--registry/test/testregcpp.cxx696
-rw-r--r--registry/tools/fileurl.cxx77
-rw-r--r--registry/tools/fileurl.hxx33
-rw-r--r--registry/tools/regview.cxx113
25 files changed, 6909 insertions, 0 deletions
diff --git a/registry/Executable_regview.mk b/registry/Executable_regview.mk
new file mode 100644
index 0000000000..9ff1052362
--- /dev/null
+++ b/registry/Executable_regview.mk
@@ -0,0 +1,34 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,regview))
+
+$(eval $(call gb_Executable_set_include,regview, \
+ $$(INCLUDE) \
+ -I$(SRCDIR)/registry/inc \
+))
+
+$(eval $(call gb_Executable_use_libraries,regview,\
+ reg \
+ $(if $(filter TRUE,$(DISABLE_DYNLOADING)),store) \
+ $(if $(filter TRUE,$(DISABLE_DYNLOADING)),salhelper) \
+ sal \
+))
+
+$(eval $(call gb_Executable_use_static_libraries,regview,\
+ registry_helper \
+))
+
+$(eval $(call gb_Executable_add_exception_objects,regview,\
+ registry/tools/regview \
+))
+
+$(eval $(call gb_Executable_add_default_nativeres,regview))
+
+# vim:set noet sw=4 ts=4:
diff --git a/registry/IwyuFilter_registry.yaml b/registry/IwyuFilter_registry.yaml
new file mode 100644
index 0000000000..4b2a6b7aa3
--- /dev/null
+++ b/registry/IwyuFilter_registry.yaml
@@ -0,0 +1,14 @@
+---
+assumeFilename: registry/source/registry.cxx
+excludelist:
+ registry/source/regimpl.hxx:
+ # Needed for correct linker visibility
+ - regapi.hxx
+ registry/source/reflwrit.cxx:
+ # OSL_BIGENDIAN is being checked
+ - osl/endian.h
+ registry/source/reflread.cxx:
+ # OSL_BIGENDIAN is being checked
+ - osl/endian.h
+ # Needed for correct linker visibility
+ - registry/typereg_reader.hxx
diff --git a/registry/Library_reg.mk b/registry/Library_reg.mk
new file mode 100644
index 0000000000..d17b119699
--- /dev/null
+++ b/registry/Library_reg.mk
@@ -0,0 +1,37 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Library_Library,reg))
+
+$(eval $(call gb_Library_add_defs,reg,\
+ -DREG_DLLIMPLEMENTATION \
+))
+
+$(eval $(call gb_Library_set_include,reg, \
+ $$(INCLUDE) \
+ -I$(SRCDIR)/registry/inc \
+))
+
+$(eval $(call gb_Library_use_external,reg,boost_headers))
+
+$(eval $(call gb_Library_use_libraries,reg,\
+ sal \
+ store \
+))
+
+$(eval $(call gb_Library_add_exception_objects,reg,\
+ registry/source/keyimpl \
+ registry/source/reflread \
+ registry/source/reflwrit \
+ registry/source/regimpl \
+ registry/source/registry \
+ registry/source/regkey \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/registry/Makefile b/registry/Makefile
new file mode 100644
index 0000000000..0997e62848
--- /dev/null
+++ b/registry/Makefile
@@ -0,0 +1,14 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
+
+include $(module_directory)/../solenv/gbuild/partial_build.mk
+
+# vim: set noet sw=4 ts=4:
diff --git a/registry/Module_registry.mk b/registry/Module_registry.mk
new file mode 100644
index 0000000000..45c23bd617
--- /dev/null
+++ b/registry/Module_registry.mk
@@ -0,0 +1,20 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Module_Module,registry))
+
+$(eval $(call gb_Module_add_targets,registry,\
+ Library_reg \
+ $(call gb_CondExeRegistryTools, \
+ Executable_regview \
+ StaticLibrary_registry_helper \
+ ) \
+))
+
+# vim:set noet sw=4 ts=4:
diff --git a/registry/README.md b/registry/README.md
new file mode 100644
index 0000000000..617ef4a73b
--- /dev/null
+++ b/registry/README.md
@@ -0,0 +1,15 @@
+# Registry Reading, etc
+
+This provides tools for dealing with the legacy binary types database
+format, still in use by extensions and the core code. While the actual
+binary file format is implemented by the `store` code, the wrapper
+that turns this into a type registry is implemented here.
+
+While this code is primarily used in only two modes:
+
+* linear write / concatenate
+* random access read
+
+The API unfortunately exposes a random-access write approach, which -
+while ~unused needs before we can re-write this away from the store
+backend.
diff --git a/registry/StaticLibrary_registry_helper.mk b/registry/StaticLibrary_registry_helper.mk
new file mode 100644
index 0000000000..cffd7a22da
--- /dev/null
+++ b/registry/StaticLibrary_registry_helper.mk
@@ -0,0 +1,17 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_StaticLibrary_StaticLibrary,registry_helper))
+
+$(eval $(call gb_StaticLibrary_add_exception_objects,registry_helper,\
+ registry/tools/fileurl \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/registry/inc/regapi.hxx b/registry/inc/regapi.hxx
new file mode 100644
index 0000000000..6d1ed00f53
--- /dev/null
+++ b/registry/inc/regapi.hxx
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <rtl/ustring.h>
+#include <registry/regtype.h>
+#include <registry/regdllapi.h>
+
+/** This function opens the specified key.
+
+ @param hKey identifies a currently open key. The key which will be opened by this function
+ is a subkey of the key identified by hKey
+ @param keyName points to a null terminated string specifying the name of a key.
+ @param phOpenKey points to a variable that receives the handle of the opened key.
+ The memory to store this variable will be allocated and will be freed by the function
+ reg_closeKey. If the function fails, phNewKey is NULL.
+ @return REG_NO_ERROR if succeeds else an error code.
+*/
+REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_openKey(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegKeyHandle* phOpenKey);
+
+
+/** This function closes the specified key.
+
+ @param hKey identifies a currently open key which will be closed by this function.
+ The memory of the variable specifying the key will be freed.
+ @return REG_NO_ERROR if succeeds else an error code.
+*/
+REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_closeKey(RegKeyHandle hKey);
+
+
+/** This function opens the root key of a registry.
+
+ @param hRegistry identifies a currently open registry whose rootKey will be returned.
+ @param phRootKey points to a handle of the open root key if the function succeeds otherwise NULL.
+ @return REG_NO_ERROR if succeeds else an error code.
+*/
+REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
+ RegKeyHandle* phRootKey);
+
+
+/** This function opens a registry with the specified name. in readonly mode.
+
+ @param registryName points to a null terminated string specifying the name of the registry.
+ @param phRegistry points to a handle of the opened registry if the function succeeds otherwise NULL.
+ @return REG_NO_ERROR if succeeds else an error code.
+*/
+REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
+ RegHandle* phRegistry);
+
+
+/** This function closes a registry.
+
+ @param hRegistry identifies a currently open registry which should be closed.
+ @return REG_NO_ERROR if succeeds else an error code.
+*/
+REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry);
+
+
+/** This function reports the complete registry information of a key and all of its subkeys.
+
+ All information which are available (keynames, value types, values, ...)
+ will be printed to stdout for report issues only.
+ @param hKey identifies a currently open key which content will be reported.
+ @return REG_NO_ERROR if succeeds else an error code.
+*/
+REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/keyimpl.cxx b/registry/source/keyimpl.cxx
new file mode 100644
index 0000000000..34e51483e7
--- /dev/null
+++ b/registry/source/keyimpl.cxx
@@ -0,0 +1,927 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <string.h>
+#include <string_view>
+
+#include "keyimpl.hxx"
+
+#include "reflcnst.hxx"
+#include <rtl/alloc.h>
+#include <rtl/ustrbuf.hxx>
+#include <osl/diagnose.h>
+#include <sal/log.hxx>
+#include <memory>
+#include <utility>
+
+using namespace store;
+
+namespace { char const VALUE_PREFIX[] = "$VL_"; }
+
+ORegKey::ORegKey(OUString keyName, ORegistry* pReg)
+ : m_refCount(1)
+ , m_name(std::move(keyName))
+ , m_bDeleted(false)
+ , m_bModified(false)
+ , m_pRegistry(pReg)
+{
+}
+
+ORegKey::~ORegKey()
+{
+ SAL_WARN_IF(m_refCount != 0, "registry", "registry::ORegKey::dtor(): refcount not zero.");
+}
+
+RegError ORegKey::releaseKey(RegKeyHandle hKey)
+{
+ return m_pRegistry->releaseKey(hKey);
+}
+
+RegError ORegKey::createKey(std::u16string_view keyName, RegKeyHandle* phNewKey)
+{
+ return m_pRegistry->createKey(this, keyName, phNewKey);
+}
+
+RegError ORegKey::openKey(std::u16string_view keyName, RegKeyHandle* phOpenKey)
+{
+ return m_pRegistry->openKey(this, keyName, phOpenKey);
+}
+
+RegError ORegKey::openSubKeys(std::u16string_view keyName, RegKeyHandle** phOpenSubKeys, sal_uInt32* pnSubKeys)
+{
+ RegError _ret = RegError::NO_ERROR;
+
+ *phOpenSubKeys = nullptr;
+ *pnSubKeys = 0;
+
+ ORegKey* pKey = this;
+ if ( !keyName.empty() )
+ {
+ _ret = openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pKey));
+ if (_ret != RegError::NO_ERROR)
+ return _ret;
+ }
+
+ sal_uInt32 nSubKeys = pKey->countSubKeys();
+ *pnSubKeys = nSubKeys;
+
+ ORegKey** pSubKeys;
+ pSubKeys = static_cast<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 )
+ {
+ OUString const sSubKeyName(iter.m_pszName, iter.m_nLength);
+
+ ORegKey* pOpenSubKey = nullptr;
+ _ret = pKey->openKey(sSubKeyName, reinterpret_cast<RegKeyHandle*>(&pOpenSubKey));
+ if (_ret != RegError::NO_ERROR)
+ {
+ *phOpenSubKeys = nullptr;
+ *pnSubKeys = 0;
+ std::free(pSubKeys); // @@@ leaking 'pSubKeys[0...nSubkeys-1]'
+ return _ret; // @@@ leaking 'pKey'
+ }
+
+ pSubKeys[nSubKeys] = pOpenSubKey;
+
+ nSubKeys++;
+ }
+
+ _err = rStoreDir.next(iter);
+ }
+
+ *phOpenSubKeys = reinterpret_cast<RegKeyHandle*>(pSubKeys);
+ if (!keyName.empty())
+ {
+ (void) releaseKey(pKey);
+ }
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::getKeyNames(std::u16string_view keyName,
+ rtl_uString*** pSubKeyNames,
+ sal_uInt32* pnSubKeys)
+{
+ *pSubKeyNames = nullptr;
+ *pnSubKeys = 0;
+
+ ORegKey* pKey = this;
+ if (!keyName.empty())
+ {
+ RegError _ret = openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pKey));
+ if (_ret != RegError::NO_ERROR)
+ return _ret;
+ }
+
+ sal_uInt32 nSubKeys = pKey->countSubKeys();
+ *pnSubKeys = nSubKeys;
+
+ rtl_uString** pSubKeys
+ = static_cast<rtl_uString**>(rtl_allocateZeroMemory(nSubKeys * sizeof(rtl_uString*)));
+
+ 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)
+ {
+ OUString const sSubKeyName(iter.m_pszName, iter.m_nLength);
+
+ OUString sFullKeyName(pKey->getName());
+ if (sFullKeyName.getLength() > 1)
+ sFullKeyName += ORegistry::ROOT;
+ sFullKeyName += sSubKeyName;
+
+ rtl_uString_newFromString(&pSubKeys[nSubKeys], sFullKeyName.pData);
+
+ nSubKeys++;
+ }
+
+ _err = rStoreDir.next(iter);
+ }
+
+ *pSubKeyNames = pSubKeys;
+ if (!keyName.empty())
+ {
+ releaseKey(pKey);
+ }
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::closeKey(RegKeyHandle hKey)
+{
+ return m_pRegistry->closeKey(hKey);
+}
+
+RegError ORegKey::deleteKey(std::u16string_view keyName)
+{
+ return m_pRegistry->deleteKey(this, keyName);
+}
+
+RegError ORegKey::getValueInfo(std::u16string_view valueName, RegValueType* pValueType, sal_uInt32* pValueSize) const
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if ( rValue.create(m_pRegistry->getStoreFile(), m_name + ORegistry::ROOT, sImplValueName, accessMode) )
+ {
+ *pValueType = RegValueType::NOT_DEFINED;
+ *pValueSize = 0;
+ return RegError::VALUE_NOT_EXISTS;
+ }
+
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE]);
+
+ sal_uInt32 readBytes;
+ if ( rValue.readAt(0, pBuffer.get(), VALUE_HEADERSIZE, readBytes) )
+ {
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != VALUE_HEADERSIZE)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt32 size;
+ sal_uInt8 type = pBuffer[0];
+ readUINT32(pBuffer.get()+VALUE_TYPEOFFSET, size);
+
+ *pValueType = static_cast<RegValueType>(type);
+ if (*pValueType > RegValueType::BINARY)
+ {
+ pBuffer.reset(new sal_uInt8[4]);
+ rValue.readAt(VALUE_HEADEROFFSET, pBuffer.get(), 4, readBytes);
+
+ readUINT32(pBuffer.get(), size);
+ }
+
+ *pValueSize = size;
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::setValue(std::u16string_view valueName, RegValueType vType, RegValue value, sal_uInt32 vSize)
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ return RegError::REGISTRY_READONLY;
+ }
+
+ if (vType > RegValueType::BINARY)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if ( rValue.create(getStoreFile(), m_name + ORegistry::ROOT , sImplValueName, storeAccessMode::Create) )
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+
+ sal_uInt32 size = vSize;
+
+ sal_uInt8 type = static_cast<sal_uInt8>(vType);
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE + size]);
+ memcpy(pBuffer.get(), &type, 1);
+
+ writeUINT32(pBuffer.get()+VALUE_TYPEOFFSET, size);
+
+ switch (vType)
+ {
+ case RegValueType::NOT_DEFINED:
+ memcpy(pBuffer.get()+VALUE_HEADEROFFSET, value, size);
+ break;
+ case RegValueType::LONG:
+ writeINT32(pBuffer.get()+VALUE_HEADEROFFSET, *static_cast<sal_Int32*>(value));
+ break;
+ case RegValueType::STRING:
+ writeUtf8(pBuffer.get()+VALUE_HEADEROFFSET, static_cast<const char*>(value));
+ break;
+ case RegValueType::UNICODE:
+ writeString(pBuffer.get()+VALUE_HEADEROFFSET, static_cast<const sal_Unicode*>(value));
+ break;
+ case RegValueType::BINARY:
+ memcpy(pBuffer.get()+VALUE_HEADEROFFSET, value, size);
+ break;
+ default:
+ OSL_ASSERT(false);
+ break;
+ }
+
+ sal_uInt32 writenBytes;
+ if ( rValue.writeAt(0, pBuffer.get(), VALUE_HEADERSIZE+size, writenBytes) )
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+ if (writenBytes != (VALUE_HEADERSIZE+size))
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+ setModified();
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::setLongListValue(std::u16string_view valueName, sal_Int32 const * pValueList, sal_uInt32 len)
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ return RegError::REGISTRY_READONLY;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if (rValue.create(getStoreFile(), m_name + ORegistry::ROOT, sImplValueName, storeAccessMode::Create) )
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+
+ sal_uInt32 size = 4; // 4 bytes (sal_uInt32) for the length
+
+ size += len * 4;
+
+ sal_uInt8 type = sal_uInt8(RegValueType::LONGLIST);
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE + size]);
+ memcpy(pBuffer.get(), &type, 1);
+
+ writeUINT32(pBuffer.get()+VALUE_TYPEOFFSET, size);
+ writeUINT32(pBuffer.get()+VALUE_HEADEROFFSET, len);
+
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
+
+ for (sal_uInt32 i=0; i < len; i++)
+ {
+ writeINT32(pBuffer.get()+VALUE_HEADEROFFSET+offset, pValueList[i]);
+ offset += 4;
+ }
+
+ sal_uInt32 writenBytes;
+ if ( rValue.writeAt(0, pBuffer.get(), VALUE_HEADERSIZE+size, writenBytes) )
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+ if (writenBytes != (VALUE_HEADEROFFSET+size))
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+ setModified();
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::setStringListValue(
+ std::u16string_view valueName, char** pValueList, sal_uInt32 len)
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ return RegError::REGISTRY_READONLY;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if (rValue.create(getStoreFile(), m_name + ORegistry::ROOT, sImplValueName, storeAccessMode::Create) )
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+
+ sal_uInt32 size = 4; // 4 bytes (sal_uInt32) for the length
+
+ sal_uInt32 i;
+ for (i=0; i < len; i++)
+ {
+ size += 4 + strlen(pValueList[i]) + 1;
+ }
+
+ sal_uInt8 type = sal_uInt8(RegValueType::STRINGLIST);
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE + size]);
+ memcpy(pBuffer.get(), &type, 1);
+
+ writeUINT32(pBuffer.get()+VALUE_TYPEOFFSET, size);
+ writeUINT32(pBuffer.get()+VALUE_HEADEROFFSET, len);
+
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array;
+ sal_uInt32 sLen = 0;
+
+ for (i=0; i < len; i++)
+ {
+ sLen = strlen(pValueList[i]) + 1;
+ writeUINT32(pBuffer.get()+VALUE_HEADEROFFSET+offset, sLen);
+
+ offset += 4;
+ writeUtf8(pBuffer.get()+VALUE_HEADEROFFSET+offset, pValueList[i]);
+ offset += sLen;
+ }
+
+ sal_uInt32 writenBytes;
+ if ( rValue.writeAt(0, pBuffer.get(), VALUE_HEADERSIZE+size, writenBytes) )
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+ if (writenBytes != (VALUE_HEADERSIZE+size))
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+ setModified();
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::setUnicodeListValue(std::u16string_view valueName, sal_Unicode** pValueList, sal_uInt32 len)
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ return RegError::REGISTRY_READONLY;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if (rValue.create(getStoreFile(), m_name + ORegistry::ROOT, sImplValueName, storeAccessMode::Create) )
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+
+ sal_uInt32 size = 4; // 4 bytes (sal_uInt32) for the length
+
+ sal_uInt32 i;
+ for (i=0; i < len; i++)
+ {
+ size += 4 + ((rtl_ustr_getLength(pValueList[i]) +1) * 2);
+ }
+
+ sal_uInt8 type = sal_uInt8(RegValueType::UNICODELIST);
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE + size]);
+ memcpy(pBuffer.get(), &type, 1);
+
+ writeUINT32(pBuffer.get()+VALUE_TYPEOFFSET, size);
+ writeUINT32(pBuffer.get()+VALUE_HEADEROFFSET, len);
+
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array;
+ sal_uInt32 sLen = 0;
+
+ for (i=0; i < len; i++)
+ {
+ sLen = (rtl_ustr_getLength(pValueList[i]) + 1) * 2;
+ writeUINT32(pBuffer.get()+VALUE_HEADEROFFSET+offset, sLen);
+
+ offset += 4;
+ writeString(pBuffer.get()+VALUE_HEADEROFFSET+offset, pValueList[i]);
+ offset += sLen;
+ }
+
+ sal_uInt32 writenBytes;
+ if ( rValue.writeAt(0, pBuffer.get(), VALUE_HEADERSIZE+size, writenBytes) )
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+ if (writenBytes != (VALUE_HEADERSIZE+size))
+ {
+ return RegError::SET_VALUE_FAILED;
+ }
+ setModified();
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::getValue(std::u16string_view valueName, RegValue value) const
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if (rValue.create(getStoreFile(), m_name + ORegistry::ROOT, sImplValueName, accessMode) )
+ {
+ return RegError::VALUE_NOT_EXISTS;
+ }
+
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE]);
+
+ sal_uInt32 readBytes;
+ if ( rValue.readAt(0, pBuffer.get(), VALUE_HEADERSIZE, readBytes) )
+ {
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != VALUE_HEADERSIZE)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt8 type = pBuffer[0];
+ valueType = static_cast<RegValueType>(type);
+ readUINT32(pBuffer.get()+VALUE_TYPEOFFSET, valueSize);
+
+ if (valueType > RegValueType::BINARY)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ pBuffer.reset(new sal_uInt8[valueSize]);
+
+ if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer.get(), valueSize, readBytes) )
+ {
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != valueSize)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ switch (valueType)
+ {
+ case RegValueType::LONG:
+ readINT32(pBuffer.get(), *static_cast<sal_Int32*>(value));
+ break;
+ case RegValueType::STRING:
+ readUtf8(pBuffer.get(), static_cast<char*>(value), valueSize);
+ break;
+ case RegValueType::UNICODE:
+ readString(pBuffer.get(), static_cast<sal_Unicode*>(value), valueSize);
+ break;
+ case RegValueType::BINARY:
+ memcpy(value, pBuffer.get(), valueSize);
+ break;
+ default:
+ memcpy(value, pBuffer.get(), valueSize);
+ break;
+ }
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::getLongListValue(std::u16string_view valueName, sal_Int32** pValueList, sal_uInt32* pLen) const
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if (rValue.create(getStoreFile(), m_name + ORegistry::ROOT, sImplValueName, accessMode) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::VALUE_NOT_EXISTS;
+ }
+
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE]);
+
+ sal_uInt32 readBytes;
+ if ( rValue.readAt(0, pBuffer.get(), VALUE_HEADERSIZE, readBytes) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != VALUE_HEADERSIZE)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt8 type = pBuffer[0];
+ valueType = static_cast<RegValueType>(type);
+
+ if (valueType != RegValueType::LONGLIST)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ readUINT32(pBuffer.get()+VALUE_TYPEOFFSET, valueSize);
+
+ /* check for 'reasonable' value */
+ /* surely 10 millions entry in a registry list should be enough */
+ if(valueSize > 40000000)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+ pBuffer.reset(new sal_uInt8[valueSize]);
+
+ if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer.get(), valueSize, readBytes) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != valueSize)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt32 len = 0;
+ readUINT32(pBuffer.get(), len);
+
+ /* make sure the declared size of the array is consistent with the amount of data we have read */
+ if(len > (valueSize - 4) / 4)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+ *pLen = len;
+ sal_Int32* pVList = static_cast<sal_Int32*>(rtl_allocateZeroMemory(len * sizeof(sal_Int32)));
+
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array;
+
+ for (sal_uInt32 i = 0; i < len; i++)
+ {
+ readINT32(pBuffer.get()+offset, pVList[i]);
+ offset += 4;
+ }
+
+ *pValueList = pVList;
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::getStringListValue(std::u16string_view valueName, char*** pValueList, sal_uInt32* pLen) const
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if ( rValue.create(getStoreFile(), m_name + ORegistry::ROOT, sImplValueName, accessMode) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::VALUE_NOT_EXISTS;
+ }
+
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE]);
+
+ sal_uInt32 readBytes;
+ if ( rValue.readAt(0, pBuffer.get(), VALUE_HEADERSIZE, readBytes) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != VALUE_HEADERSIZE)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt8 type = pBuffer[0];
+ valueType = static_cast<RegValueType>(type);
+
+ if (valueType != RegValueType::STRINGLIST)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ readUINT32(pBuffer.get()+VALUE_TYPEOFFSET, valueSize);
+
+ pBuffer.reset(new sal_uInt8[valueSize]);
+
+ if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer.get(), valueSize, readBytes) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != valueSize)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt32 len = 0;
+ readUINT32(pBuffer.get(), len);
+
+ *pLen = len;
+ char** pVList = static_cast<char**>(rtl_allocateZeroMemory(len * sizeof(char*)));
+
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array;
+ sal_uInt32 sLen = 0;
+
+ char *pValue;
+ for (sal_uInt32 i=0; i < len; i++)
+ {
+ readUINT32(pBuffer.get()+offset, sLen);
+
+ offset += 4;
+
+ pValue = static_cast<char*>(std::malloc(sLen));
+ readUtf8(pBuffer.get()+offset, pValue, sLen);
+ pVList[i] = pValue;
+
+ offset += sLen;
+ }
+
+ *pValueList = pVList;
+ return RegError::NO_ERROR;
+}
+
+RegError ORegKey::getUnicodeListValue(std::u16string_view valueName, sal_Unicode*** pValueList, sal_uInt32* pLen) const
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ OUString sImplValueName = OUString::Concat(VALUE_PREFIX) + valueName;
+
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ if ( rValue.create(getStoreFile(), m_name + ORegistry::ROOT, sImplValueName, accessMode) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::VALUE_NOT_EXISTS;
+ }
+
+ pBuffer.reset(new sal_uInt8[VALUE_HEADERSIZE]);
+
+ sal_uInt32 readBytes;
+ if ( rValue.readAt(0, pBuffer.get(), VALUE_HEADERSIZE, readBytes) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != VALUE_HEADERSIZE)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt8 type = pBuffer[0];
+ valueType = static_cast<RegValueType>(type);
+
+ if (valueType != RegValueType::UNICODELIST)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ readUINT32(pBuffer.get()+VALUE_TYPEOFFSET, valueSize);
+
+ pBuffer.reset(new sal_uInt8[valueSize]);
+
+ if ( rValue.readAt(VALUE_HEADEROFFSET, pBuffer.get(), valueSize, readBytes) )
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+ if (readBytes != valueSize)
+ {
+ pValueList = nullptr;
+ *pLen = 0;
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt32 len = 0;
+ readUINT32(pBuffer.get(), len);
+
+ *pLen = len;
+ sal_Unicode** pVList = static_cast<sal_Unicode**>(rtl_allocateZeroMemory(len * sizeof(sal_Unicode*)));
+
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array;
+ sal_uInt32 sLen = 0;
+
+ sal_Unicode *pValue;
+ for (sal_uInt32 i=0; i < len; i++)
+ {
+ readUINT32(pBuffer.get()+offset, sLen);
+
+ offset += 4;
+
+ pValue = static_cast<sal_Unicode*>(std::malloc((sLen / 2) * sizeof(sal_Unicode)));
+ readString(pBuffer.get()+offset, pValue, sLen);
+ pVList[i] = pValue;
+
+ offset += sLen;
+ }
+
+ *pValueList = pVList;
+ return RegError::NO_ERROR;
+}
+
+
+RegError ORegKey::getResolvedKeyName(std::u16string_view keyName,
+ OUString& resolvedName) const
+{
+ if (keyName.empty())
+ return RegError::INVALID_KEYNAME;
+
+ resolvedName = getFullPath(keyName);
+ return RegError::NO_ERROR;
+}
+
+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;
+}
+
+OStoreDirectory ORegKey::getStoreDir() const
+{
+ OStoreDirectory rStoreDir;
+ OUString fullPath;
+ OUString relativName;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+
+ if ( m_name == ORegistry::ROOT )
+ {
+ fullPath.clear();
+ relativName.clear();
+ } else
+ {
+ fullPath = m_name.copy(0, m_name.lastIndexOf('/') + 1);
+ relativName = m_name.copy(m_name.lastIndexOf('/') + 1);
+ }
+
+ if (m_pRegistry->isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ rStoreDir.create(getStoreFile(), fullPath, relativName, accessMode);
+
+ return rStoreDir;
+}
+
+OUString ORegKey::getFullPath(std::u16string_view path) const {
+ OSL_ASSERT(!m_name.isEmpty() && !path.empty());
+ OUStringBuffer b(32);
+ b.append(m_name);
+ if (!b.isEmpty() && b[b.getLength() - 1] == '/') {
+ if (path[0] == '/') {
+ b.append(path.substr(1));
+ } else {
+ b.append(path);
+ }
+ } else {
+ if (path[0] != '/') {
+ b.append('/');
+ }
+ b.append(path);
+ }
+ return b.makeStringAndClear();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/keyimpl.hxx b/registry/source/keyimpl.hxx
new file mode 100644
index 0000000000..4bfbcec3b7
--- /dev/null
+++ b/registry/source/keyimpl.hxx
@@ -0,0 +1,140 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_REGISTRY_SOURCE_KEYIMPL_HXX
+#define INCLUDED_REGISTRY_SOURCE_KEYIMPL_HXX
+
+#include <sal/config.h>
+
+#include <string_view>
+
+#include "regimpl.hxx"
+#include <rtl/ustring.hxx>
+
+class ORegKey
+{
+public:
+
+ ORegKey(OUString keyName, ORegistry* pReg);
+ ~ORegKey();
+
+ void acquire()
+ { ++m_refCount; }
+
+ sal_uInt32 release()
+ { return --m_refCount; }
+
+ RegError releaseKey(RegKeyHandle hKey);
+
+ RegError createKey(std::u16string_view keyName, RegKeyHandle* phNewKey);
+
+ RegError openKey(std::u16string_view keyName, RegKeyHandle* phOpenKey);
+
+ RegError openSubKeys(std::u16string_view keyName,
+ RegKeyHandle** phOpenSubKeys,
+ sal_uInt32* pnSubKeys);
+
+ RegError getKeyNames(std::u16string_view keyName,
+ rtl_uString*** pSubKeyNames,
+ sal_uInt32* pnSubKeys);
+
+ RegError closeKey(RegKeyHandle hKey);
+
+ RegError deleteKey(std::u16string_view keyName);
+
+ RegError getValueInfo(std::u16string_view valueName,
+ RegValueType* pValueTye,
+ sal_uInt32* pValueSize) const;
+
+ RegError setValue(std::u16string_view valueName,
+ RegValueType vType,
+ RegValue value,
+ sal_uInt32 vSize);
+
+ RegError setLongListValue(std::u16string_view valueName,
+ sal_Int32 const * pValueList,
+ sal_uInt32 len);
+
+ RegError setStringListValue(std::u16string_view valueName,
+ char** pValueList,
+ sal_uInt32 len);
+
+ RegError setUnicodeListValue(std::u16string_view valueName,
+ sal_Unicode** pValueList,
+ sal_uInt32 len);
+
+ RegError getValue(std::u16string_view valueName, RegValue value) const;
+
+ RegError getLongListValue(std::u16string_view valueName,
+ sal_Int32** pValueList,
+ sal_uInt32* pLen) const;
+
+ RegError getStringListValue(std::u16string_view valueName,
+ char*** pValueList,
+ sal_uInt32* pLen) const;
+
+ RegError getUnicodeListValue(std::u16string_view valueName,
+ sal_Unicode*** pValueList,
+ sal_uInt32* pLen) const;
+
+ RegError getResolvedKeyName(std::u16string_view keyName,
+ OUString& resolvedName) const;
+
+ bool isDeleted() const
+ { return m_bDeleted; }
+
+ void setDeleted (bool bKeyDeleted)
+ { m_bDeleted = bKeyDeleted; }
+
+ bool isModified() const
+ { return m_bModified; }
+
+ void setModified (bool bModified = true)
+ { m_bModified = bModified; }
+
+ bool isReadOnly() const
+ { return m_pRegistry->isReadOnly(); }
+
+ sal_uInt32 countSubKeys();
+
+ ORegistry* getRegistry() const
+ { return m_pRegistry; }
+
+ const store::OStoreFile& getStoreFile() const
+ { return m_pRegistry->getStoreFile(); }
+
+ store::OStoreDirectory getStoreDir() const;
+
+ const OUString& getName() const
+ { return m_name; }
+
+ OUString getFullPath(std::u16string_view path) const;
+
+private:
+ sal_uInt32 m_refCount;
+ OUString m_name;
+ bool m_bDeleted:1;
+ bool m_bModified:1;
+ ORegistry* m_pRegistry;
+};
+
+#endif
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/reflcnst.hxx b/registry/source/reflcnst.hxx
new file mode 100644
index 0000000000..2c93a9cd22
--- /dev/null
+++ b/registry/source/reflcnst.hxx
@@ -0,0 +1,188 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <registry/types.hxx>
+
+#include <string.h>
+
+#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 static_cast<sal_uInt32>(OFFSET_MAGIC + sizeof(magic))
+#define OFFSET_MINOR_VERSION static_cast<sal_uInt32>(OFFSET_SIZE + sizeof(sal_uInt32))
+#define OFFSET_MAJOR_VERSION static_cast<sal_uInt32>(OFFSET_MINOR_VERSION + sizeof(minorVersion))
+#define OFFSET_N_ENTRIES static_cast<sal_uInt32>(OFFSET_MAJOR_VERSION + sizeof(majorVersion))
+#define OFFSET_TYPE_SOURCE static_cast<sal_uInt32>(OFFSET_N_ENTRIES + sizeof(sal_uInt16))
+#define OFFSET_TYPE_CLASS static_cast<sal_uInt32>(OFFSET_TYPE_SOURCE + sizeof(sal_uInt16))
+#define OFFSET_THIS_TYPE static_cast<sal_uInt32>(OFFSET_TYPE_CLASS + sizeof(sal_uInt16))
+#define OFFSET_UIK static_cast<sal_uInt32>(OFFSET_THIS_TYPE + sizeof(sal_uInt16))
+#define OFFSET_DOKU static_cast<sal_uInt32>(OFFSET_UIK + sizeof(sal_uInt16))
+#define OFFSET_FILENAME static_cast<sal_uInt32>(OFFSET_DOKU + sizeof(sal_uInt16))
+
+#define OFFSET_N_SUPERTYPES static_cast<sal_uInt32>(OFFSET_FILENAME + sizeof(sal_uInt16))
+#define OFFSET_SUPERTYPES static_cast<sal_uInt32>(OFFSET_N_SUPERTYPES + sizeof(sal_uInt16))
+
+#define OFFSET_CP_SIZE static_cast<sal_uInt32>(OFFSET_SUPERTYPES + sizeof(sal_uInt16))
+#define OFFSET_CP static_cast<sal_uInt32>(OFFSET_CP_SIZE + sizeof(sal_uInt16))
+
+#define CP_OFFSET_ENTRY_SIZE 0
+#define CP_OFFSET_ENTRY_TAG static_cast<sal_uInt32>(CP_OFFSET_ENTRY_SIZE + sizeof(sal_uInt32))
+#define CP_OFFSET_ENTRY_DATA static_cast<sal_uInt32>(CP_OFFSET_ENTRY_TAG + sizeof(sal_uInt16))
+
+#define FIELD_OFFSET_ACCESS 0
+#define FIELD_OFFSET_NAME static_cast<sal_uInt32>(FIELD_OFFSET_ACCESS + sizeof(sal_uInt16))
+#define FIELD_OFFSET_TYPE static_cast<sal_uInt32>(FIELD_OFFSET_NAME + sizeof(sal_uInt16))
+#define FIELD_OFFSET_VALUE static_cast<sal_uInt32>(FIELD_OFFSET_TYPE + sizeof(sal_uInt16))
+#define FIELD_OFFSET_DOKU static_cast<sal_uInt32>(FIELD_OFFSET_VALUE + sizeof(sal_uInt16))
+#define FIELD_OFFSET_FILENAME static_cast<sal_uInt32>(FIELD_OFFSET_DOKU + sizeof(sal_uInt16))
+
+#define PARAM_OFFSET_TYPE 0
+#define PARAM_OFFSET_MODE static_cast<sal_uInt32>(PARAM_OFFSET_TYPE + sizeof(sal_uInt16))
+#define PARAM_OFFSET_NAME static_cast<sal_uInt32>(PARAM_OFFSET_MODE + sizeof(sal_uInt16))
+
+#define METHOD_OFFSET_SIZE 0
+#define METHOD_OFFSET_MODE static_cast<sal_uInt32>(METHOD_OFFSET_SIZE + sizeof(sal_uInt16))
+#define METHOD_OFFSET_NAME static_cast<sal_uInt32>(METHOD_OFFSET_MODE + sizeof(sal_uInt16))
+#define METHOD_OFFSET_RETURN static_cast<sal_uInt32>(METHOD_OFFSET_NAME + sizeof(sal_uInt16))
+#define METHOD_OFFSET_DOKU static_cast<sal_uInt32>(METHOD_OFFSET_RETURN + sizeof(sal_uInt16))
+#define METHOD_OFFSET_PARAM_COUNT static_cast<sal_uInt32>(METHOD_OFFSET_DOKU + sizeof(sal_uInt16))
+
+#define REFERENCE_OFFSET_TYPE 0
+#define REFERENCE_OFFSET_NAME static_cast<sal_uInt32>(REFERENCE_OFFSET_TYPE + sizeof(sal_uInt16))
+#define REFERENCE_OFFSET_DOKU static_cast<sal_uInt32>(REFERENCE_OFFSET_NAME + sizeof(sal_uInt16))
+#define REFERENCE_OFFSET_ACCESS static_cast<sal_uInt32>(REFERENCE_OFFSET_DOKU + 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
+};
+
+inline sal_uInt32 writeUINT16(sal_uInt8* buffer, sal_uInt16 v)
+{
+ buffer[0] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
+ buffer[1] = static_cast<sal_uInt8>((v >> 0) & 0xFF);
+
+ return sizeof(sal_uInt16);
+}
+
+inline sal_uInt32 readUINT16(const sal_uInt8* buffer, sal_uInt16& v)
+{
+ //This is untainted data which comes from a controlled source
+ //so, using a byte-swapping pattern which coverity doesn't
+ //detect as such
+ //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
+ v = *buffer++; v <<= 8;
+ v |= *buffer;
+ return sizeof(sal_uInt16);
+}
+
+inline sal_uInt32 writeINT32(sal_uInt8* buffer, sal_Int32 v)
+{
+ buffer[0] = static_cast<sal_uInt8>((v >> 24) & 0xFF);
+ buffer[1] = static_cast<sal_uInt8>((v >> 16) & 0xFF);
+ buffer[2] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
+ buffer[3] = static_cast<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] = static_cast<sal_uInt8>((v >> 24) & 0xFF);
+ buffer[1] = static_cast<sal_uInt8>((v >> 16) & 0xFF);
+ buffer[2] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
+ buffer[3] = static_cast<sal_uInt8>((v >> 0) & 0xFF);
+
+ return sizeof(sal_uInt32);
+}
+
+inline sal_uInt32 readUINT32(const sal_uInt8* buffer, sal_uInt32& v)
+{
+ //This is untainted data which comes from a controlled source
+ //so, using a byte-swapping pattern which coverity doesn't
+ //detect as such
+ //http://security.coverity.com/blog/2014/Apr/on-detecting-heartbleed-with-static-analysis.html
+ v = *buffer++; v <<= 8;
+ v |= *buffer++; v <<= 8;
+ v |= *buffer++; v <<= 8;
+ v |= *buffer;
+ return sizeof(sal_uInt32);
+}
+
+inline sal_uInt32 writeUtf8(sal_uInt8* buffer, const char* v)
+{
+ sal_uInt32 size = strlen(v) + 1;
+
+ memcpy(buffer, v, size);
+
+ return size;
+}
+
+inline sal_uInt32 readUtf8(const sal_uInt8* buffer, char* v, sal_uInt32 maxSize)
+{
+ sal_uInt32 size = strlen(reinterpret_cast<const char*>(buffer)) + 1;
+ if(size > maxSize)
+ {
+ size = maxSize;
+ }
+
+ memcpy(v, buffer, size);
+
+ if (size == maxSize) v[size - 1] = '\0';
+
+ return size;
+}
+
+
+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);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/reflread.cxx b/registry/source/reflread.cxx
new file mode 100644
index 0000000000..fe223c7b46
--- /dev/null
+++ b/registry/source/reflread.cxx
@@ -0,0 +1,1609 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <cstring>
+#include <memory>
+#include <new>
+#include <vector>
+
+#include <sal/types.h>
+#include <osl/endian.h>
+#include <osl/diagnose.h>
+#include <sal/log.hxx>
+
+#include <registry/refltype.hxx>
+#include <registry/typereg_reader.hxx>
+#include <registry/version.h>
+
+#include "reflcnst.hxx"
+
+#include <cstddef>
+
+const char NULL_STRING[1] = { 0 };
+const sal_Unicode NULL_WSTRING[1] = { 0 };
+
+const sal_uInt32 magic = 0x12345678;
+const sal_uInt16 minorVersion = 0x0000;
+const sal_uInt16 majorVersion = 0x0001;
+
+namespace {
+
+/**
+ Holds any data in a flat memory buffer
+ */
+class BlopObject
+{
+public:
+ struct BoundsError {};
+
+ const sal_uInt8* m_pBuffer;
+ sal_uInt32 m_bufferLen;
+
+ BlopObject(const sal_uInt8* buffer, sal_uInt32 len);
+ // throws std::bad_alloc
+
+ sal_uInt8 readBYTE(sal_uInt32 index) const
+ {
+ if (index >= m_bufferLen) {
+ throw BoundsError();
+ }
+ return m_pBuffer[index];
+ }
+
+ sal_Int16 readINT16(sal_uInt32 index) const
+ {
+ if (m_bufferLen < 2 || index >= m_bufferLen - 1) {
+ throw BoundsError();
+ }
+ return ((m_pBuffer[index] << 8) | (m_pBuffer[index+1] << 0));
+ }
+
+ sal_uInt16 readUINT16(sal_uInt32 index) const
+ {
+ if (m_bufferLen < 2 || index >= m_bufferLen - 1) {
+ throw BoundsError();
+ }
+ return ((m_pBuffer[index] << 8) | (m_pBuffer[index+1] << 0));
+ }
+
+ sal_Int32 readINT32(sal_uInt32 index) const
+ {
+ if (m_bufferLen < 4 || index >= m_bufferLen - 3) {
+ throw BoundsError();
+ }
+ return (
+ (m_pBuffer[index] << 24) |
+ (m_pBuffer[index+1] << 16) |
+ (m_pBuffer[index+2] << 8) |
+ (m_pBuffer[index+3] << 0)
+ );
+ }
+
+ sal_uInt32 readUINT32(sal_uInt32 index) const
+ {
+ if (m_bufferLen < 4 || index >= m_bufferLen - 3) {
+ throw BoundsError();
+ }
+ return (
+ (m_pBuffer[index] << 24) |
+ (m_pBuffer[index+1] << 16) |
+ (m_pBuffer[index+2] << 8) |
+ (m_pBuffer[index+3] << 0)
+ );
+ }
+
+ sal_Int64 readINT64(sal_uInt32 index) const
+ {
+ if (m_bufferLen < 8 || index >= m_bufferLen - 7) {
+ throw BoundsError();
+ }
+ return (
+ (static_cast<sal_Int64>(m_pBuffer[index]) << 56) |
+ (static_cast<sal_Int64>(m_pBuffer[index+1]) << 48) |
+ (static_cast<sal_Int64>(m_pBuffer[index+2]) << 40) |
+ (static_cast<sal_Int64>(m_pBuffer[index+3]) << 32) |
+ (static_cast<sal_Int64>(m_pBuffer[index+4]) << 24) |
+ (static_cast<sal_Int64>(m_pBuffer[index+5]) << 16) |
+ (static_cast<sal_Int64>(m_pBuffer[index+6]) << 8) |
+ (static_cast<sal_Int64>(m_pBuffer[index+7]) << 0)
+ );
+ }
+
+ sal_uInt64 readUINT64(sal_uInt32 index) const
+ {
+ if (m_bufferLen < 8 || index >= m_bufferLen - 7) {
+ throw BoundsError();
+ }
+ return (
+ (static_cast<sal_uInt64>(m_pBuffer[index]) << 56) |
+ (static_cast<sal_uInt64>(m_pBuffer[index+1]) << 48) |
+ (static_cast<sal_uInt64>(m_pBuffer[index+2]) << 40) |
+ (static_cast<sal_uInt64>(m_pBuffer[index+3]) << 32) |
+ (static_cast<sal_uInt64>(m_pBuffer[index+4]) << 24) |
+ (static_cast<sal_uInt64>(m_pBuffer[index+5]) << 16) |
+ (static_cast<sal_uInt64>(m_pBuffer[index+6]) << 8) |
+ (static_cast<sal_uInt64>(m_pBuffer[index+7]) << 0)
+ );
+ }
+};
+
+}
+
+BlopObject::BlopObject(const sal_uInt8* buffer, sal_uInt32 len)
+ : m_bufferLen(len)
+{
+ m_pBuffer = buffer;
+}
+
+namespace {
+
+class StringCache
+{
+public:
+ std::vector<std::unique_ptr<sal_Unicode[]>> m_stringTable;
+ sal_uInt16 m_stringsCopied;
+
+ explicit StringCache(sal_uInt16 size); // throws std::bad_alloc
+
+ const sal_Unicode* getString(sal_uInt16 index) const;
+ sal_uInt16 createString(const sal_uInt8* buffer); // throws std::bad_alloc
+};
+
+}
+
+StringCache::StringCache(sal_uInt16 size)
+ : m_stringTable(size)
+ , m_stringsCopied(0)
+{
+}
+
+const sal_Unicode* StringCache::getString(sal_uInt16 index) const
+{
+ if ((index > 0) && (index <= m_stringsCopied))
+ return m_stringTable[index - 1].get();
+ else
+ return nullptr;
+}
+
+sal_uInt16 StringCache::createString(const sal_uInt8* buffer)
+{
+ if (m_stringsCopied < m_stringTable.size())
+ {
+ sal_uInt32 len = UINT16StringLen(buffer);
+
+ m_stringTable[m_stringsCopied].reset( new sal_Unicode[len + 1] );
+
+ readString(buffer, m_stringTable[m_stringsCopied].get(), (len + 1) * sizeof(sal_Unicode));
+
+ return ++m_stringsCopied;
+ }
+ else
+ return 0;
+}
+
+namespace {
+
+class ConstantPool : public BlopObject
+{
+public:
+
+ sal_uInt16 m_numOfEntries;
+ std::unique_ptr<sal_Int32[]> m_pIndex; // index values may be < 0 for cached string constants
+
+ std::unique_ptr<StringCache> m_pStringCache;
+
+ ConstantPool(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries)
+ : BlopObject(buffer, len)
+ , m_numOfEntries(numEntries)
+ {
+ }
+
+ sal_uInt32 parseIndex(); // throws std::bad_alloc
+
+ CPInfoTag readTag(sal_uInt16 index) const;
+
+ const char* readUTF8NameConstant(sal_uInt16 index) const;
+ bool readBOOLConstant(sal_uInt16 index) const;
+ sal_Int8 readBYTEConstant(sal_uInt16 index) const;
+ sal_Int16 readINT16Constant(sal_uInt16 index) const;
+ sal_uInt16 readUINT16Constant(sal_uInt16 index) const;
+ sal_Int32 readINT32Constant(sal_uInt16 index) const;
+ sal_uInt32 readUINT32Constant(sal_uInt16 index) const;
+ sal_Int64 readINT64Constant(sal_uInt16 index) const;
+ sal_uInt64 readUINT64Constant(sal_uInt16 index) const;
+ float readFloatConstant(sal_uInt16 index) const;
+ double readDoubleConstant(sal_uInt16 index) const;
+ const sal_Unicode* readStringConstant(sal_uInt16 index) const;
+ // throws std::bad_alloc
+};
+
+}
+
+sal_uInt32 ConstantPool::parseIndex()
+{
+ m_pIndex.reset();
+ m_pStringCache.reset();
+
+ sal_uInt32 offset = 0;
+ sal_uInt16 numOfStrings = 0;
+
+ if (m_numOfEntries)
+ {
+ m_pIndex.reset( new sal_Int32[m_numOfEntries] );
+
+ for (int i = 0; i < m_numOfEntries; i++)
+ {
+ m_pIndex[i] = offset;
+
+ offset += readUINT32(offset);
+
+ if ( static_cast<CPInfoTag>(readUINT16(m_pIndex[i] + CP_OFFSET_ENTRY_TAG)) ==
+ CP_TAG_CONST_STRING )
+ {
+ numOfStrings++;
+ }
+
+ }
+ }
+
+ if (numOfStrings)
+ {
+ m_pStringCache.reset( new StringCache(numOfStrings) );
+ }
+
+ m_bufferLen = offset;
+
+ return offset;
+}
+
+CPInfoTag ConstantPool::readTag(sal_uInt16 index) const
+{
+ CPInfoTag tag = CP_TAG_INVALID;
+
+ if (m_pIndex && (index > 0) && (index <= m_numOfEntries))
+ {
+ tag = static_cast<CPInfoTag>(readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG));
+ }
+
+ return tag;
+}
+
+const char* ConstantPool::readUTF8NameConstant(sal_uInt16 index) const
+{
+ const 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)
+ {
+ sal_uInt32 n = m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA;
+ if (n < m_bufferLen
+ && std::memchr(m_pBuffer + n, 0, m_bufferLen - n) != nullptr)
+ {
+ aName = reinterpret_cast<const char*>(m_pBuffer + n);
+ }
+ }
+ }
+
+ return aName;
+}
+
+bool ConstantPool::readBOOLConstant(sal_uInt16 index) const
+{
+ bool aBool = false;
+
+ if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
+ {
+ if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_BOOL)
+ {
+ aBool = readBYTE(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA) != 0;
+ }
+ }
+
+ return aBool;
+}
+
+sal_Int8 ConstantPool::readBYTEConstant(sal_uInt16 index) const
+{
+ sal_Int8 aByte = 0;
+
+ if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
+ {
+ if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_BYTE)
+ {
+ aByte = static_cast< sal_Int8 >(
+ readBYTE(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA));
+ }
+ }
+
+ return aByte;
+}
+
+sal_Int16 ConstantPool::readINT16Constant(sal_uInt16 index) const
+{
+ sal_Int16 aINT16 = 0;
+
+ 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) const
+{
+ sal_uInt16 asal_uInt16 = 0;
+
+ 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) const
+{
+ sal_Int32 aINT32 = 0;
+
+ 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) const
+{
+ sal_uInt32 aUINT32 = 0;
+
+ 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;
+}
+
+sal_Int64 ConstantPool::readINT64Constant(sal_uInt16 index) const
+{
+ sal_Int64 aINT64 = 0;
+
+ if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
+ {
+ if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_INT64)
+ {
+ aINT64 = readINT64(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
+ }
+ }
+
+ return aINT64;
+}
+
+sal_uInt64 ConstantPool::readUINT64Constant(sal_uInt16 index) const
+{
+ sal_uInt64 aUINT64 = 0;
+
+ if (m_pIndex && (index> 0) && (index <= m_numOfEntries))
+ {
+ if (readUINT16(m_pIndex[index - 1] + CP_OFFSET_ENTRY_TAG) == CP_TAG_CONST_UINT64)
+ {
+ aUINT64 = readUINT64(m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA);
+ }
+ }
+
+ return aUINT64;
+}
+
+float ConstantPool::readFloatConstant(sal_uInt16 index) const
+{
+ union
+ {
+ float v;
+ sal_uInt32 b;
+ } x = { 0.0f };
+
+ 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) const
+{
+ union
+ {
+ double v;
+ struct
+ {
+ sal_uInt32 b1;
+ sal_uInt32 b2;
+ } b;
+ } x = { 0.0 };
+
+ 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
+{
+ 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)
+ {
+ sal_uInt32 n = m_pIndex[index - 1] + CP_OFFSET_ENTRY_DATA;
+ if (n >= m_bufferLen
+ || (std::memchr(m_pBuffer + n, 0, m_bufferLen - n)
+ == nullptr))
+ {
+ throw BoundsError();
+ }
+ m_pIndex[index - 1] = -1 * m_pStringCache->createString(m_pBuffer + n);
+ }
+ }
+
+ aString = m_pStringCache->getString(static_cast<sal_uInt16>(m_pIndex[index - 1] * -1));
+ }
+
+ return aString;
+}
+
+namespace {
+
+class FieldList : public BlopObject
+{
+public:
+
+ sal_uInt16 m_numOfEntries;
+ size_t m_FIELD_ENTRY_SIZE;
+ ConstantPool* m_pCP;
+
+ FieldList(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries, ConstantPool* pCP)
+ : BlopObject(buffer, len)
+ , m_numOfEntries(numEntries)
+ , m_pCP(pCP)
+ {
+ if ( m_numOfEntries > 0 )
+ {
+ sal_uInt16 numOfFieldEntries = readUINT16(0);
+ m_FIELD_ENTRY_SIZE = numOfFieldEntries * sizeof(sal_uInt16);
+ } else
+ {
+ m_FIELD_ENTRY_SIZE = 0;
+ }
+ }
+
+ sal_uInt32 parseIndex() const { return ((m_numOfEntries ? sizeof(sal_uInt16) : 0) + (m_numOfEntries * m_FIELD_ENTRY_SIZE));}
+
+ const char* getFieldName(sal_uInt16 index) const;
+ const char* getFieldType(sal_uInt16 index) const;
+ RTFieldAccess getFieldAccess(sal_uInt16 index) const;
+ RTValueType getFieldConstValue(sal_uInt16 index, RTConstValueUnion* value) const;
+ // throws std::bad_alloc
+ const char* getFieldDoku(sal_uInt16 index) const;
+ const char* getFieldFileName(sal_uInt16 index) const;
+};
+
+}
+
+const char* FieldList::getFieldName(sal_uInt16 index) const
+{
+ const char* aName = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aName = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_NAME));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aName;
+}
+
+const char* FieldList::getFieldType(sal_uInt16 index) const
+{
+ const char* aName = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aName = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_TYPE));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aName;
+}
+
+RTFieldAccess FieldList::getFieldAccess(sal_uInt16 index) const
+{
+ RTFieldAccess aAccess = RTFieldAccess::INVALID;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aAccess = static_cast<RTFieldAccess>(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_ACCESS));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aAccess;
+}
+
+RTValueType FieldList::getFieldConstValue(sal_uInt16 index, RTConstValueUnion* value) const
+{
+ RTValueType ret = RT_TYPE_NONE;
+ try {
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ sal_uInt16 cpIndex = readUINT16(sizeof(sal_uInt16) + (index * m_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;
+ }
+ }
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ return ret;
+}
+
+const char* FieldList::getFieldDoku(sal_uInt16 index) const
+{
+ const char* aDoku = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aDoku = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_DOKU));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aDoku;
+}
+
+const char* FieldList::getFieldFileName(sal_uInt16 index) const
+{
+ const char* aFileName = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aFileName = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_FIELD_ENTRY_SIZE) + FIELD_OFFSET_FILENAME));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aFileName;
+}
+
+namespace {
+
+class ReferenceList : public BlopObject
+{
+public:
+
+ sal_uInt16 m_numOfEntries;
+ size_t m_REFERENCE_ENTRY_SIZE;
+ ConstantPool* m_pCP;
+
+ ReferenceList(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries, ConstantPool* pCP)
+ : BlopObject(buffer, len)
+ , m_numOfEntries(numEntries)
+ , m_pCP(pCP)
+ {
+ if ( m_numOfEntries > 0 )
+ {
+ sal_uInt16 numOfReferenceEntries = readUINT16(0);
+ m_REFERENCE_ENTRY_SIZE = numOfReferenceEntries * sizeof(sal_uInt16);
+ } else
+ {
+ m_REFERENCE_ENTRY_SIZE = 0;
+ }
+ }
+
+ const char* getReferenceName(sal_uInt16 index) const;
+ RTReferenceType getReferenceType(sal_uInt16 index) const;
+ const char* getReferenceDoku(sal_uInt16 index) const;
+ RTFieldAccess getReferenceAccess(sal_uInt16 index) const;
+};
+
+}
+
+const char* ReferenceList::getReferenceName(sal_uInt16 index) const
+{
+ const char* aName = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aName = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_NAME));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aName;
+}
+
+RTReferenceType ReferenceList::getReferenceType(sal_uInt16 index) const
+{
+ RTReferenceType refType = RTReferenceType::INVALID;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ refType = static_cast<RTReferenceType>(readUINT16(sizeof(sal_uInt16) + (index * m_REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_TYPE));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return refType;
+}
+
+const char* ReferenceList::getReferenceDoku(sal_uInt16 index) const
+{
+ const char* aDoku = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aDoku = m_pCP->readUTF8NameConstant(readUINT16(sizeof(sal_uInt16) + (index * m_REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_DOKU));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aDoku;
+}
+
+RTFieldAccess ReferenceList::getReferenceAccess(sal_uInt16 index) const
+{
+ RTFieldAccess aAccess = RTFieldAccess::INVALID;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aAccess = static_cast<RTFieldAccess>(readUINT16(sizeof(sal_uInt16) + (index * m_REFERENCE_ENTRY_SIZE) + REFERENCE_OFFSET_ACCESS));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aAccess;
+}
+
+namespace {
+
+class MethodList : public BlopObject
+{
+public:
+
+ sal_uInt16 m_numOfEntries;
+ size_t m_PARAM_ENTRY_SIZE;
+ std::unique_ptr<sal_uInt32[]> m_pIndex;
+ ConstantPool* m_pCP;
+
+ MethodList(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries, ConstantPool* pCP)
+ : BlopObject(buffer, len)
+ , m_numOfEntries(numEntries)
+ , m_pCP(pCP)
+ {
+ if ( m_numOfEntries > 0 )
+ {
+ readUINT16(0) /* numOfMethodEntries */;
+ sal_uInt16 numOfParamEntries = readUINT16(sizeof(sal_uInt16));
+ m_PARAM_ENTRY_SIZE = numOfParamEntries * sizeof(sal_uInt16);
+ } else
+ {
+ m_PARAM_ENTRY_SIZE = 0;
+ }
+ }
+
+ sal_uInt32 parseIndex(); // throws std::bad_alloc
+
+ const char* getMethodName(sal_uInt16 index) const;
+ sal_uInt16 getMethodParamCount(sal_uInt16 index) const;
+ const char* getMethodParamType(sal_uInt16 index, sal_uInt16 paramIndex) const;
+ const char* getMethodParamName(sal_uInt16 index, sal_uInt16 paramIndex) const;
+ RTParamMode getMethodParamMode(sal_uInt16 index, sal_uInt16 paramIndex) const;
+ sal_uInt16 getMethodExcCount(sal_uInt16 index) const;
+ const char* getMethodExcType(sal_uInt16 index, sal_uInt16 excIndex) const;
+ const char* getMethodReturnType(sal_uInt16 index) const;
+ RTMethodMode getMethodMode(sal_uInt16 index) const;
+ const char* getMethodDoku(sal_uInt16 index) const;
+
+private:
+ sal_uInt16 calcMethodParamIndex( const sal_uInt16 index ) const;
+};
+
+}
+
+sal_uInt16 MethodList::calcMethodParamIndex( const sal_uInt16 index ) const
+{
+ return (METHOD_OFFSET_PARAM_COUNT + sizeof(sal_uInt16) + (index * m_PARAM_ENTRY_SIZE));
+}
+
+sal_uInt32 MethodList::parseIndex()
+{
+ m_pIndex.reset();
+
+ sal_uInt32 offset = 0;
+
+ if (m_numOfEntries)
+ {
+ offset = 2 * sizeof(sal_uInt16);
+ m_pIndex.reset( new sal_uInt32[m_numOfEntries] );
+
+ for (int i = 0; i < m_numOfEntries; i++)
+ {
+ m_pIndex[i] = offset;
+
+ offset += readUINT16(offset);
+ }
+ }
+
+ return offset;
+}
+
+const char* MethodList::getMethodName(sal_uInt16 index) const
+{
+ const char* aName = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aName = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_NAME));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aName;
+}
+
+sal_uInt16 MethodList::getMethodParamCount(sal_uInt16 index) const
+{
+ sal_uInt16 aCount = 0;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aCount = readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT);
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aCount;
+}
+
+const char* MethodList::getMethodParamType(sal_uInt16 index, sal_uInt16 paramIndex) const
+{
+ const char* aName = nullptr;
+ try {
+ if ((m_numOfEntries > 0) &&
+ (index <= m_numOfEntries) &&
+ (paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)))
+ {
+ aName = m_pCP->readUTF8NameConstant(
+ readUINT16(
+ m_pIndex[index] +
+ calcMethodParamIndex(paramIndex) +
+ PARAM_OFFSET_TYPE));
+ }
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ return aName;
+}
+
+const char* MethodList::getMethodParamName(sal_uInt16 index, sal_uInt16 paramIndex) const
+{
+ const char* aName = nullptr;
+ try {
+ if ((m_numOfEntries > 0) &&
+ (index <= m_numOfEntries) &&
+ (paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)))
+ {
+ aName = m_pCP->readUTF8NameConstant(
+ readUINT16(
+ m_pIndex[index] +
+ calcMethodParamIndex(paramIndex) +
+ PARAM_OFFSET_NAME));
+ }
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ return aName;
+}
+
+RTParamMode MethodList::getMethodParamMode(sal_uInt16 index, sal_uInt16 paramIndex) const
+{
+ RTParamMode aMode = RT_PARAM_INVALID;
+ try {
+ if ((m_numOfEntries > 0) &&
+ (index <= m_numOfEntries) &&
+ (paramIndex <= readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)))
+ {
+ aMode = static_cast<RTParamMode>(readUINT16(
+ m_pIndex[index] +
+ calcMethodParamIndex(paramIndex) +
+ PARAM_OFFSET_MODE));
+ }
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ return aMode;
+}
+
+#if defined(__COVERITY__)
+extern "C" void __coverity_tainted_data_sanitize__(void *);
+#endif
+
+sal_uInt16 MethodList::getMethodExcCount(sal_uInt16 index) const
+{
+ sal_uInt16 aCount = 0;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aCount = readUINT16(m_pIndex[index] + calcMethodParamIndex(readUINT16(m_pIndex[index] + METHOD_OFFSET_PARAM_COUNT)));
+#if defined(__COVERITY__)
+ __coverity_tainted_data_sanitize__(&aCount);
+#endif
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aCount;
+}
+
+const char* MethodList::getMethodExcType(sal_uInt16 index, sal_uInt16 excIndex) const
+{
+ const char* aName = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ sal_uInt32 excOffset = m_pIndex[index] + calcMethodParamIndex(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))));
+ }
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aName;
+}
+
+const char* MethodList::getMethodReturnType(sal_uInt16 index) const
+{
+ const char* aName = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aName = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_RETURN));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aName;
+}
+
+RTMethodMode MethodList::getMethodMode(sal_uInt16 index) const
+{
+ RTMethodMode aMode = RTMethodMode::INVALID;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aMode = static_cast<RTMethodMode>(readUINT16(m_pIndex[index] + METHOD_OFFSET_MODE));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aMode;
+}
+
+const char* MethodList::getMethodDoku(sal_uInt16 index) const
+{
+ const char* aDoku = nullptr;
+
+ if ((m_numOfEntries > 0) && (index <= m_numOfEntries))
+ {
+ try {
+ aDoku = m_pCP->readUTF8NameConstant(readUINT16(m_pIndex[index] + METHOD_OFFSET_DOKU));
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+
+ return aDoku;
+}
+
+namespace {
+
+class TypeRegistryEntry: public BlopObject {
+public:
+ std::unique_ptr<ConstantPool> m_pCP;
+ std::unique_ptr<FieldList> m_pFields;
+ std::unique_ptr<MethodList> m_pMethods;
+ std::unique_ptr<ReferenceList> m_pReferences;
+ sal_uInt32 m_refCount;
+ sal_uInt16 m_nSuperTypes;
+ sal_uInt32 m_offset_SUPERTYPES;
+
+ TypeRegistryEntry(
+ const sal_uInt8* buffer, sal_uInt32 len);
+ // throws std::bad_alloc
+
+ typereg_Version getVersion() const;
+};
+
+}
+
+TypeRegistryEntry::TypeRegistryEntry(
+ const sal_uInt8* buffer, sal_uInt32 len):
+ BlopObject(buffer, len), m_refCount(1), m_nSuperTypes(0),
+ m_offset_SUPERTYPES(0)
+{
+ std::size_t const entrySize = sizeof(sal_uInt16);
+ sal_uInt16 nHeaderEntries = readUINT16(OFFSET_N_ENTRIES);
+ sal_uInt32 offset_N_SUPERTYPES = OFFSET_N_ENTRIES + entrySize + (nHeaderEntries * entrySize); // cannot overflow
+ m_offset_SUPERTYPES = offset_N_SUPERTYPES + entrySize; // cannot overflow
+ m_nSuperTypes = readUINT16(offset_N_SUPERTYPES);
+
+ sal_uInt32 offset_CP_SIZE = m_offset_SUPERTYPES + (m_nSuperTypes * entrySize); // cannot overflow
+ sal_uInt32 offset_CP = offset_CP_SIZE + entrySize; // cannot overflow
+
+ if (offset_CP > m_bufferLen) {
+ throw BoundsError();
+ }
+ m_pCP.reset(
+ new ConstantPool(
+ m_pBuffer + offset_CP, m_bufferLen - offset_CP,
+ readUINT16(offset_CP_SIZE)));
+
+ sal_uInt32 offset = offset_CP + m_pCP->parseIndex(); //TODO: overflow
+
+ assert(m_bufferLen >= entrySize);
+ if (offset > m_bufferLen - entrySize) {
+ throw BoundsError();
+ }
+ m_pFields.reset(
+ new FieldList(
+ m_pBuffer + offset + entrySize, m_bufferLen - (offset + entrySize),
+ readUINT16(offset), m_pCP.get()));
+
+ offset += sizeof(sal_uInt16) + m_pFields->parseIndex(); //TODO: overflow
+
+ assert(m_bufferLen >= entrySize);
+ if (offset > m_bufferLen - entrySize) {
+ throw BoundsError();
+ }
+ m_pMethods.reset(
+ new MethodList(
+ m_pBuffer + offset + entrySize, m_bufferLen - (offset + entrySize),
+ readUINT16(offset), m_pCP.get()));
+
+ offset += sizeof(sal_uInt16) + m_pMethods->parseIndex(); //TODO: overflow
+
+ assert(m_bufferLen >= entrySize);
+ if (offset > m_bufferLen - entrySize) {
+ throw BoundsError();
+ }
+ m_pReferences.reset(
+ new ReferenceList(
+ m_pBuffer + offset + entrySize, m_bufferLen - (offset + entrySize),
+ readUINT16(offset), m_pCP.get()));
+}
+
+typereg_Version TypeRegistryEntry::getVersion() const {
+ // Assumes two's complement arithmetic with modulo-semantics:
+ return static_cast< typereg_Version >(readUINT32(OFFSET_MAGIC) - magic);
+}
+
+bool TYPEREG_CALLTYPE typereg_reader_create(
+ void const * buffer, sal_uInt32 length,
+ void ** result)
+{
+ if (length < OFFSET_CP || length > SAL_MAX_UINT32) {
+ *result = nullptr;
+ return true;
+ }
+ std::unique_ptr< TypeRegistryEntry > entry;
+ try {
+ try {
+ entry.reset(
+ new TypeRegistryEntry(
+ static_cast< sal_uInt8 const * >(buffer), length));
+ } catch (std::bad_alloc &) {
+ return false;
+ }
+ if (entry->readUINT32(OFFSET_SIZE) != length) {
+ *result = nullptr;
+ return true;
+ }
+ typereg_Version version = entry->getVersion();
+ if (version < TYPEREG_VERSION_0 || version > TYPEREG_VERSION_1) {
+ *result = nullptr;
+ return true;
+ }
+ *result = entry.release();
+ return true;
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ return false;
+ }
+}
+
+void TYPEREG_CALLTYPE typereg_reader_acquire(void * hEntry)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry != nullptr)
+ pEntry->m_refCount++;
+}
+
+void TYPEREG_CALLTYPE typereg_reader_release(void * hEntry)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry != nullptr)
+ {
+ if (--pEntry->m_refCount == 0)
+ delete pEntry;
+ }
+}
+
+typereg_Version TYPEREG_CALLTYPE typereg_reader_getVersion(void const * handle) {
+ if (handle != nullptr) {
+ try {
+ return static_cast< TypeRegistryEntry const * >(handle)->getVersion();
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+ return TYPEREG_VERSION_0;
+}
+
+RTTypeClass TYPEREG_CALLTYPE typereg_reader_getTypeClass(void * hEntry)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+ if (pEntry != nullptr) {
+ try {
+ return static_cast<RTTypeClass>(pEntry->readUINT16(OFFSET_TYPE_CLASS) & ~RT_TYPE_PUBLISHED);
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+ return RT_TYPE_INVALID;
+}
+
+bool TYPEREG_CALLTYPE typereg_reader_isPublished(void * hEntry)
+{
+ TypeRegistryEntry * entry = static_cast< TypeRegistryEntry * >(hEntry);
+ if (entry != nullptr) {
+ try {
+ return (entry->readUINT16(OFFSET_TYPE_CLASS) & RT_TYPE_PUBLISHED) != 0;
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+ return false;
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getTypeName(void * hEntry, rtl_uString** pTypeName)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+ if (pEntry != nullptr) {
+ try {
+ const char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_THIS_TYPE));
+ rtl_string2UString(
+ pTypeName, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+ return;
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+ rtl_uString_new(pTypeName);
+}
+
+
+void TYPEREG_CALLTYPE typereg_reader_getDocumentation(void * hEntry, rtl_uString** pDoku)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+ if (pEntry != nullptr) {
+ try {
+ const char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_DOKU));
+ rtl_string2UString(
+ pDoku, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+ return;
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+ rtl_uString_new(pDoku);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getFileName(void * hEntry, rtl_uString** pFileName)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+ if (pEntry != nullptr) {
+ try {
+ const char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(OFFSET_FILENAME));
+ rtl_string2UString(
+ pFileName, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+ return;
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+ rtl_uString_new(pFileName);
+}
+
+
+sal_uInt16 TYPEREG_CALLTYPE typereg_reader_getFieldCount(void * hEntry)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return 0;
+
+ return pEntry->m_pFields->m_numOfEntries;
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getFieldName(void * hEntry, rtl_uString** pFieldName, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pFieldName);
+ return;
+ }
+ const char* pTmp = pEntry->m_pFields->getFieldName(index);
+ rtl_string2UString(
+ pFieldName, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getFieldTypeName(void * hEntry, rtl_uString** pFieldType, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pFieldType);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pFields->getFieldType(index);
+ rtl_string2UString(
+ pFieldType, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+RTFieldAccess TYPEREG_CALLTYPE typereg_reader_getFieldFlags(void * hEntry, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return RTFieldAccess::INVALID;
+
+ return pEntry->m_pFields->getFieldAccess(index);
+}
+
+bool TYPEREG_CALLTYPE typereg_reader_getFieldValue(
+ void * hEntry, sal_uInt16 index, RTValueType * type,
+ RTConstValueUnion * value)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) {
+ *type = RT_TYPE_NONE;
+ return true;
+ }
+
+ try {
+ *type = pEntry->m_pFields->getFieldConstValue(index, value);
+ } catch (std::bad_alloc &) {
+ return false;
+ }
+ return true;
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getFieldDocumentation(void * hEntry, rtl_uString** pDoku, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pDoku);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pFields->getFieldDoku(index);
+ rtl_string2UString(
+ pDoku, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getFieldFileName(void * hEntry, rtl_uString** pFieldFileName, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pFieldFileName);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pFields->getFieldFileName(index);
+ rtl_string2UString(
+ pFieldFileName, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+
+sal_uInt16 TYPEREG_CALLTYPE typereg_reader_getMethodCount(void * hEntry)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return 0;
+
+ return pEntry->m_pMethods->m_numOfEntries;
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getMethodName(void * hEntry, rtl_uString** pMethodName, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pMethodName);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pMethods->getMethodName(index);
+ rtl_string2UString(
+ pMethodName, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+sal_uInt16 TYPEREG_CALLTYPE typereg_reader_getMethodParameterCount(
+ void * hEntry, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return 0;
+
+ return pEntry->m_pMethods->getMethodParamCount(index);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getMethodParameterTypeName(void * hEntry, rtl_uString** pMethodParamType, sal_uInt16 index, sal_uInt16 paramIndex)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pMethodParamType);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pMethods->getMethodParamType(index, paramIndex);
+ rtl_string2UString(
+ pMethodParamType, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getMethodParameterName(void * hEntry, rtl_uString** pMethodParamName, sal_uInt16 index, sal_uInt16 paramIndex)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pMethodParamName);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pMethods->getMethodParamName(index, paramIndex);
+ rtl_string2UString(
+ pMethodParamName, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+RTParamMode TYPEREG_CALLTYPE typereg_reader_getMethodParameterFlags(void * hEntry, sal_uInt16 index, sal_uInt16 paramIndex)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return RT_PARAM_INVALID;
+
+ return pEntry->m_pMethods->getMethodParamMode(index, paramIndex);
+}
+
+sal_uInt16 TYPEREG_CALLTYPE typereg_reader_getMethodExceptionCount(
+ void * hEntry, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return 0;
+
+ return pEntry->m_pMethods->getMethodExcCount(index);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getMethodExceptionTypeName(void * hEntry, rtl_uString** pMethodExcpType, sal_uInt16 index, sal_uInt16 excIndex)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pMethodExcpType);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pMethods->getMethodExcType(index, excIndex);
+ rtl_string2UString(
+ pMethodExcpType, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getMethodReturnTypeName(void * hEntry, rtl_uString** pMethodReturnType, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pMethodReturnType);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pMethods->getMethodReturnType(index);
+ rtl_string2UString(
+ pMethodReturnType, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+RTMethodMode TYPEREG_CALLTYPE typereg_reader_getMethodFlags(void * hEntry, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return RTMethodMode::INVALID;
+
+ return pEntry->m_pMethods->getMethodMode(index);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getMethodDocumentation(void * hEntry, rtl_uString** pMethodDoku, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pMethodDoku);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pMethods->getMethodDoku(index);
+ rtl_string2UString(
+ pMethodDoku, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+sal_uInt16 TYPEREG_CALLTYPE typereg_reader_getReferenceCount(void * hEntry)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return 0;
+
+ return pEntry->m_pReferences->m_numOfEntries;
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getReferenceTypeName(void * hEntry, rtl_uString** pReferenceName, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pReferenceName);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pReferences->getReferenceName(index);
+ rtl_string2UString(
+ pReferenceName, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+RTReferenceType TYPEREG_CALLTYPE typereg_reader_getReferenceSort(void * hEntry, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return RTReferenceType::INVALID;
+
+ return pEntry->m_pReferences->getReferenceType(index);
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getReferenceDocumentation(void * hEntry, rtl_uString** pReferenceDoku, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr)
+ {
+ rtl_uString_new(pReferenceDoku);
+ return;
+ }
+
+ const char* pTmp = pEntry->m_pReferences->getReferenceDoku(index);
+ rtl_string2UString(
+ pReferenceDoku, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
+
+RTFieldAccess TYPEREG_CALLTYPE typereg_reader_getReferenceFlags(void * hEntry, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return RTFieldAccess::INVALID;
+
+ return pEntry->m_pReferences->getReferenceAccess(index);
+}
+
+sal_uInt16 TYPEREG_CALLTYPE typereg_reader_getSuperTypeCount(void * hEntry)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+
+ if (pEntry == nullptr) return 0;
+
+ return pEntry->m_nSuperTypes;
+}
+
+void TYPEREG_CALLTYPE typereg_reader_getSuperTypeName(
+ void * hEntry, rtl_uString ** pSuperTypeName, sal_uInt16 index)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+ if (pEntry != nullptr) {
+ try {
+ OSL_ASSERT(index < pEntry->m_nSuperTypes);
+ const char* pTmp = pEntry->m_pCP->readUTF8NameConstant(pEntry->readUINT16(pEntry->m_offset_SUPERTYPES + (index * sizeof(sal_uInt16))));
+ rtl_string2UString(
+ pSuperTypeName, pTmp, pTmp == nullptr ? 0 : rtl_str_getLength(pTmp),
+ RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+ return;
+ } catch (BlopObject::BoundsError &) {
+ SAL_WARN("registry", "bad data");
+ }
+ }
+ rtl_uString_new(pSuperTypeName);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/reflwrit.cxx b/registry/source/reflwrit.cxx
new file mode 100644
index 0000000000..5304d03463
--- /dev/null
+++ b/registry/source/reflwrit.cxx
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <sal/types.h>
+#include <rtl/ustring.h>
+
+#include <registry/refltype.hxx>
+
+#include "reflcnst.hxx"
+
+
+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, static_cast<sal_uInt16>(v[i]));
+ }
+
+ return (buff - buffer);
+}
+
+sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize)
+{
+ sal_uInt32 len = UINT16StringLen(buffer) + 1;
+ sal_uInt32 i;
+ sal_uInt8* buff = const_cast<sal_uInt8*>(buffer);
+
+ if(len > maxSize / 2)
+ {
+ len = maxSize / 2;
+ }
+
+ for (i = 0; i < (len - 1); i++)
+ {
+ sal_uInt16 aChar;
+
+ buff += readUINT16(buff, aChar);
+
+ v[i] = static_cast<sal_Unicode>(aChar);
+ }
+
+ v[len - 1] = L'\0';
+
+ return (buff - buffer);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/regimpl.cxx b/registry/source/regimpl.cxx
new file mode 100644
index 0000000000..7dcbaa272d
--- /dev/null
+++ b/registry/source/regimpl.cxx
@@ -0,0 +1,1177 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "regimpl.hxx"
+
+#include <cstddef>
+#include <memory>
+#include <set>
+#include <string_view>
+#include <vector>
+#include <string.h>
+#include <stdio.h>
+
+#if defined(UNX)
+#include <unistd.h>
+#endif
+
+#include <registry/reader.hxx>
+#include <registry/refltype.hxx>
+#include <registry/types.hxx>
+
+#include "reflcnst.hxx"
+#include "keyimpl.hxx"
+
+#include <osl/thread.h>
+#include <rtl/ustring.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <osl/file.hxx>
+
+using namespace osl;
+using namespace store;
+
+
+namespace {
+
+void printString(std::u16string_view s) {
+ printf("\"");
+ for (std::size_t i = 0; i < s.size(); ++i) {
+ sal_Unicode c = s[i];
+ if (c == '"' || c == '\\') {
+ printf("\\%c", static_cast< char >(c));
+ } else if (s[i] >= ' ' && s[i] <= '~') {
+ printf("%c", static_cast< char >(c));
+ } else {
+ printf("\\u%04X", static_cast< unsigned int >(c));
+ }
+ }
+ printf("\"");
+}
+
+void printFieldOrReferenceFlag(
+ RTFieldAccess * flags, RTFieldAccess flag, char const * name, bool * first)
+{
+ if ((*flags & flag) != RTFieldAccess::NONE) {
+ if (!*first) {
+ printf("|");
+ }
+ *first = false;
+ printf("%s", name);
+ *flags &= ~flag;
+ }
+}
+
+void printFieldOrReferenceFlags(RTFieldAccess flags) {
+ if (flags == RTFieldAccess::NONE) {
+ printf("none");
+ } else {
+ bool first = true;
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::READONLY, "readonly", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::OPTIONAL, "optional", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::MAYBEVOID, "maybevoid", &first);
+ printFieldOrReferenceFlag(&flags, RTFieldAccess::BOUND, "bound", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::CONSTRAINED, "constrained", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::TRANSIENT, "transient", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::MAYBEAMBIGUOUS, "maybeambiguous", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::MAYBEDEFAULT, "maybedefault", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::REMOVABLE, "removable", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::ATTRIBUTE, "attribute", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::PROPERTY, "property", &first);
+ printFieldOrReferenceFlag(&flags, RTFieldAccess::CONST, "const", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::READWRITE, "readwrite", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::PARAMETERIZED_TYPE, "parameterized type", &first);
+ printFieldOrReferenceFlag(
+ &flags, RTFieldAccess::PUBLISHED, "published", &first);
+ if (flags != RTFieldAccess::NONE) {
+ if (!first) {
+ printf("|");
+ }
+ printf("<invalid (0x%04X)>", static_cast< unsigned int >(flags));
+ }
+ }
+}
+
+void dumpType(typereg::Reader const & reader, OString const & indent) {
+ if (reader.isValid()) {
+ printf("version: %ld\n", static_cast< long >(reader.getVersion()));
+ printf("%sdocumentation: ", indent.getStr());
+ printString(reader.getDocumentation());
+ printf("\n");
+ printf("%sfile name: ", indent.getStr());
+ printString(reader.getFileName());
+ printf("\n");
+ printf("%stype class: ", indent.getStr());
+ if (reader.isPublished()) {
+ printf("published ");
+ }
+ switch (reader.getTypeClass()) {
+ case RT_TYPE_INTERFACE:
+ printf("interface");
+ break;
+
+ case RT_TYPE_MODULE:
+ printf("module");
+ break;
+
+ case RT_TYPE_STRUCT:
+ printf("struct");
+ break;
+
+ case RT_TYPE_ENUM:
+ printf("enum");
+ break;
+
+ case RT_TYPE_EXCEPTION:
+ printf("exception");
+ break;
+
+ case RT_TYPE_TYPEDEF:
+ printf("typedef");
+ break;
+
+ case RT_TYPE_SERVICE:
+ printf("service");
+ break;
+
+ case RT_TYPE_SINGLETON:
+ printf("singleton");
+ break;
+
+ case RT_TYPE_CONSTANTS:
+ printf("constants");
+ break;
+
+ default:
+ printf(
+ "<invalid (%ld)>", static_cast< long >(reader.getTypeClass()));
+ break;
+ }
+ printf("\n");
+ printf("%stype name: ", indent.getStr());
+ printString(reader.getTypeName());
+ printf("\n");
+ printf(
+ "%ssuper type count: %u\n", indent.getStr(),
+ static_cast< unsigned int >(reader.getSuperTypeCount()));
+ for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
+ printf(
+ "%ssuper type name %u: ", indent.getStr(),
+ static_cast< unsigned int >(i));
+ printString(reader.getSuperTypeName(i));
+ printf("\n");
+ }
+ printf(
+ "%sfield count: %u\n", indent.getStr(),
+ static_cast< unsigned int >(reader.getFieldCount()));
+ for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
+ printf(
+ "%sfield %u:\n", indent.getStr(),
+ static_cast< unsigned int >(i));
+ printf("%s documentation: ", indent.getStr());
+ printString(reader.getFieldDocumentation(i));
+ printf("\n");
+ printf("%s file name: ", indent.getStr());
+ printString(reader.getFieldFileName(i));
+ printf("\n");
+ printf("%s flags: ", indent.getStr());
+ printFieldOrReferenceFlags(reader.getFieldFlags(i));
+ printf("\n");
+ printf("%s name: ", indent.getStr());
+ printString(reader.getFieldName(i));
+ printf("\n");
+ printf("%s type name: ", indent.getStr());
+ printString(reader.getFieldTypeName(i));
+ printf("\n");
+ printf("%s value: ", indent.getStr());
+ RTConstValue value(reader.getFieldValue(i));
+ switch (value.m_type) {
+ case RT_TYPE_NONE:
+ printf("none");
+ break;
+
+ case RT_TYPE_BOOL:
+ printf("boolean %s", value.m_value.aBool ? "true" : "false");
+ break;
+
+ case RT_TYPE_BYTE:
+ printf("byte %d", static_cast< int >(value.m_value.aByte));
+ break;
+
+ case RT_TYPE_INT16:
+ printf("short %d", static_cast< int >(value.m_value.aShort));
+ break;
+
+ case RT_TYPE_UINT16:
+ printf(
+ "unsigned short %u",
+ static_cast< unsigned int >(value.m_value.aUShort));
+ break;
+
+ case RT_TYPE_INT32:
+ printf("long %ld", static_cast< long >(value.m_value.aLong));
+ break;
+
+ case RT_TYPE_UINT32:
+ printf(
+ "unsigned long %lu",
+ static_cast< unsigned long >(value.m_value.aULong));
+ break;
+
+ case RT_TYPE_INT64:
+ // TODO: no portable way to print hyper values
+ printf("hyper");
+ break;
+
+ case RT_TYPE_UINT64:
+ // TODO: no portable way to print unsigned hyper values
+ printf("unsigned hyper");
+ break;
+
+ case RT_TYPE_FLOAT:
+ // TODO: no portable way to print float values
+ printf("float");
+ break;
+
+ case RT_TYPE_DOUBLE:
+ // TODO: no portable way to print double values
+ printf("double");
+ break;
+
+ case RT_TYPE_STRING:
+ printf("string ");
+ printString(value.m_value.aString);
+ break;
+
+ default:
+ printf("<invalid (%ld)>", static_cast< long >(value.m_type));
+ break;
+ }
+ printf("\n");
+ }
+ printf(
+ "%smethod count: %u\n", indent.getStr(),
+ static_cast< unsigned int >(reader.getMethodCount()));
+ for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) {
+ printf(
+ "%smethod %u:\n", indent.getStr(),
+ static_cast< unsigned int >(i));
+ printf("%s documentation: ", indent.getStr());
+ printString(reader.getMethodDocumentation(i));
+ printf("\n");
+ printf("%s flags: ", indent.getStr());
+ switch (reader.getMethodFlags(i)) {
+ case RTMethodMode::ONEWAY:
+ printf("oneway");
+ break;
+
+ case RTMethodMode::TWOWAY:
+ printf("synchronous");
+ break;
+
+ case RTMethodMode::ATTRIBUTE_GET:
+ printf("attribute get");
+ break;
+
+ case RTMethodMode::ATTRIBUTE_SET:
+ printf("attribute set");
+ break;
+
+ default:
+ printf(
+ "<invalid (%ld)>",
+ static_cast< long >(reader.getMethodFlags(i)));
+ break;
+ }
+ printf("\n");
+ printf("%s name: ", indent.getStr());
+ printString(reader.getMethodName(i));
+ printf("\n");
+ printf("%s return type name: ", indent.getStr());
+ printString(reader.getMethodReturnTypeName(i));
+ printf("\n");
+ printf(
+ "%s parameter count: %u\n", indent.getStr(),
+ static_cast< unsigned int >(reader.getMethodParameterCount(i)));
+ // coverity[tainted_data] - cid#1215304 unhelpfully warns about untrusted loop bound
+ for (sal_uInt16 j = 0; j < reader.getMethodParameterCount(i); ++j)
+ {
+ printf(
+ "%s parameter %u:\n", indent.getStr(),
+ static_cast< unsigned int >(j));
+ printf("%s flags: ", indent.getStr());
+ RTParamMode flags = reader.getMethodParameterFlags(i, j);
+ bool rest = (flags & RT_PARAM_REST) != 0;
+ switch (flags & ~RT_PARAM_REST) {
+ case RT_PARAM_IN:
+ printf("in");
+ break;
+
+ case RT_PARAM_OUT:
+ printf("out");
+ break;
+
+ case RT_PARAM_INOUT:
+ printf("inout");
+ break;
+
+ default:
+ printf("<invalid (%ld)>", static_cast< long >(flags));
+ rest = false;
+ break;
+ }
+ if (rest) {
+ printf("|rest");
+ }
+ printf("\n");
+ printf("%s name: ", indent.getStr());
+ printString(reader.getMethodParameterName(i, j));
+ printf("\n");
+ printf("%s type name: ", indent.getStr());
+ printString(reader.getMethodParameterTypeName(i, j));
+ printf("\n");
+ }
+ printf(
+ "%s exception count: %u\n", indent.getStr(),
+ static_cast< unsigned int >(reader.getMethodExceptionCount(i)));
+ // coverity[tainted_data] - cid#1215304 unhelpfully warns about untrusted loop bound
+ for (sal_uInt16 j = 0; j < reader.getMethodExceptionCount(i); ++j)
+ {
+ printf(
+ "%s exception type name %u: ", indent.getStr(),
+ static_cast< unsigned int >(j));
+ printString(reader.getMethodExceptionTypeName(i, j));
+ printf("\n");
+ }
+ }
+ printf(
+ "%sreference count: %u\n", indent.getStr(),
+ static_cast< unsigned int >(reader.getReferenceCount()));
+ for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) {
+ printf(
+ "%sreference %u:\n", indent.getStr(),
+ static_cast< unsigned int >(i));
+ printf("%s documentation: ", indent.getStr());
+ printString(reader.getReferenceDocumentation(i));
+ printf("\n");
+ printf("%s flags: ", indent.getStr());
+ printFieldOrReferenceFlags(reader.getReferenceFlags(i));
+ printf("\n");
+ printf("%s sort: ", indent.getStr());
+ switch (reader.getReferenceSort(i)) {
+ case RTReferenceType::SUPPORTS:
+ printf("supports");
+ break;
+
+ case RTReferenceType::EXPORTS:
+ printf("exports");
+ break;
+
+ case RTReferenceType::TYPE_PARAMETER:
+ printf("type parameter");
+ break;
+
+ default:
+ printf(
+ "<invalid (%ld)>",
+ static_cast< long >(reader.getReferenceSort(i)));
+ break;
+ }
+ printf("\n");
+ printf("%s type name: ", indent.getStr());
+ printString(reader.getReferenceTypeName(i));
+ printf("\n");
+ }
+ } else {
+ printf("<invalid>\n");
+ }
+}
+
+}
+
+ORegistry::ORegistry()
+ : m_refCount(1)
+ , m_readOnly(false)
+ , m_isOpen(false)
+{
+}
+
+ORegistry::~ORegistry()
+{
+ ORegKey* pRootKey = m_openKeyTable[ROOT];
+ if (pRootKey != nullptr)
+ (void) releaseKey(pRootKey);
+
+ if (m_file.isValid())
+ m_file.close();
+}
+
+RegError ORegistry::initRegistry(const OUString& regName, RegAccessMode accessMode, bool bCreate)
+{
+ RegError eRet = RegError::INVALID_REGISTRY;
+ OStoreFile rRegFile;
+ storeAccessMode sAccessMode = storeAccessMode::ReadWrite;
+ storeError errCode;
+
+ if (bCreate)
+ {
+ sAccessMode = storeAccessMode::Create;
+ }
+ else if (accessMode & RegAccessMode::READONLY)
+ {
+ sAccessMode = storeAccessMode::ReadOnly;
+ m_readOnly = true;
+ }
+
+ if (regName.isEmpty() &&
+ storeAccessMode::Create == sAccessMode)
+ {
+ errCode = rRegFile.createInMemory();
+ }
+ else
+ {
+ errCode = rRegFile.create(regName, sAccessMode);
+ }
+
+ if (errCode)
+ {
+ switch (errCode)
+ {
+ case store_E_NotExists:
+ eRet = RegError::REGISTRY_NOT_EXISTS;
+ break;
+ case store_E_LockingViolation:
+ eRet = RegError::CANNOT_OPEN_FOR_READWRITE;
+ break;
+ default:
+ eRet = RegError::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 = true;
+
+ m_openKeyTable[ROOT] = new ORegKey(ROOT, this);
+ eRet = RegError::NO_ERROR;
+ }
+ else
+ eRet = RegError::INVALID_REGISTRY;
+ }
+
+ return eRet;
+}
+
+RegError ORegistry::closeRegistry()
+{
+ REG_GUARD(m_mutex);
+
+ if (m_file.isValid())
+ {
+ (void) releaseKey(m_openKeyTable[ROOT]);
+ m_file.close();
+ m_isOpen = false;
+ return RegError::NO_ERROR;
+ } else
+ {
+ return RegError::REGISTRY_NOT_EXISTS;
+ }
+}
+
+RegError ORegistry::destroyRegistry(const OUString& regName)
+{
+ REG_GUARD(m_mutex);
+
+ if (!regName.isEmpty())
+ {
+ std::unique_ptr<ORegistry> pReg(new ORegistry());
+
+ if (pReg->initRegistry(regName, RegAccessMode::READWRITE) == RegError::NO_ERROR)
+ {
+ pReg.reset();
+
+ OUString systemName;
+ if (FileBase::getSystemPathFromFileURL(regName, systemName) != FileBase::E_None)
+ systemName = regName;
+
+ OString name(OUStringToOString(systemName, osl_getThreadTextEncoding()));
+ if (unlink(name.getStr()) != 0)
+ {
+ return RegError::DESTROY_REGISTRY_FAILED;
+ }
+ } else
+ {
+ return RegError::DESTROY_REGISTRY_FAILED;
+ }
+ } else
+ {
+ if (m_refCount != 1 || isReadOnly())
+ {
+ return RegError::DESTROY_REGISTRY_FAILED;
+ }
+
+ if (m_file.isValid())
+ {
+ releaseKey(m_openKeyTable[ROOT]);
+ m_file.close();
+ m_isOpen = false;
+
+ if (!m_name.isEmpty())
+ {
+ OUString systemName;
+ if (FileBase::getSystemPathFromFileURL(m_name, systemName) != FileBase::E_None)
+ systemName = m_name;
+
+ OString name(OUStringToOString(systemName, osl_getThreadTextEncoding()));
+ if (unlink(name.getStr()) != 0)
+ {
+ return RegError::DESTROY_REGISTRY_FAILED;
+ }
+ }
+ } else
+ {
+ return RegError::REGISTRY_NOT_EXISTS;
+ }
+ }
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::acquireKey (RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ REG_GUARD(m_mutex);
+ pKey->acquire();
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::releaseKey (RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ REG_GUARD(m_mutex);
+ if (pKey->release() == 0)
+ {
+ m_openKeyTable.erase(pKey->getName());
+ delete pKey;
+ }
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::createKey(RegKeyHandle hKey, std::u16string_view keyName,
+ RegKeyHandle* phNewKey)
+{
+ ORegKey* pKey;
+
+ *phNewKey = nullptr;
+
+ if (keyName.empty())
+ return RegError::INVALID_KEYNAME;
+
+ REG_GUARD(m_mutex);
+
+ if (hKey)
+ pKey = static_cast<ORegKey*>(hKey);
+ else
+ pKey = m_openKeyTable[ROOT];
+
+ OUString sFullKeyName = pKey->getFullPath(keyName);
+
+ if (m_openKeyTable.count(sFullKeyName) > 0)
+ {
+ *phNewKey = m_openKeyTable[sFullKeyName];
+ static_cast<ORegKey*>(*phNewKey)->acquire();
+ static_cast<ORegKey*>(*phNewKey)->setDeleted(false);
+ return RegError::NO_ERROR;
+ }
+
+ OStoreDirectory rStoreDir;
+ OUStringBuffer sFullPath(sFullKeyName.getLength()+16);
+ OUString token;
+
+ sFullPath.append('/');
+
+ sal_Int32 nIndex = 0;
+ do
+ {
+ token = sFullKeyName.getToken(0, '/', nIndex);
+ if (!token.isEmpty())
+ {
+ if (rStoreDir.create(pKey->getStoreFile(), sFullPath.toString(), token, storeAccessMode::Create))
+ {
+ return RegError::CREATE_KEY_FAILED;
+ }
+
+ sFullPath.append(token + "/");
+ }
+ } while(nIndex != -1);
+
+
+ pKey = new ORegKey(sFullKeyName, this);
+ *phNewKey = pKey;
+ m_openKeyTable[sFullKeyName] = pKey;
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::openKey(RegKeyHandle hKey, std::u16string_view keyName,
+ RegKeyHandle* phOpenKey)
+{
+ ORegKey* pKey;
+
+ *phOpenKey = nullptr;
+
+ if (keyName.empty())
+ {
+ return RegError::INVALID_KEYNAME;
+ }
+
+ REG_GUARD(m_mutex);
+
+ if (hKey)
+ pKey = static_cast<ORegKey*>(hKey);
+ else
+ pKey = m_openKeyTable[ROOT];
+
+ OUString path(pKey->getFullPath(keyName));
+ KeyMap::iterator i(m_openKeyTable.find(path));
+ if (i == m_openKeyTable.end()) {
+ sal_Int32 n = path.lastIndexOf('/') + 1;
+ switch (OStoreDirectory().create(
+ pKey->getStoreFile(), path.copy(0, n), path.copy(n),
+ isReadOnly() ? storeAccessMode::ReadOnly : storeAccessMode::ReadWrite))
+ {
+ case store_E_NotExists:
+ return RegError::KEY_NOT_EXISTS;
+ case store_E_WrongFormat:
+ return RegError::INVALID_KEY;
+ default:
+ break;
+ }
+
+ std::unique_ptr< ORegKey > p(new ORegKey(path, this));
+ i = m_openKeyTable.insert(std::make_pair(path, p.get())).first;
+ // coverity[leaked_storage : FALSE] - ownership transferred to m_openKeyTable
+ p.release();
+ } else {
+ i->second->acquire();
+ }
+ *phOpenKey = i->second;
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::closeKey(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+
+ REG_GUARD(m_mutex);
+
+ OUString const aKeyName (pKey->getName());
+ if (m_openKeyTable.count(aKeyName) <= 0)
+ return RegError::KEY_NOT_OPEN;
+
+ if (pKey->isModified())
+ {
+ ORegKey * pRootKey = getRootKey();
+ if (pKey != pRootKey)
+ {
+ // propagate "modified" state to RootKey.
+ pRootKey->setModified();
+ }
+ else
+ {
+ // closing modified RootKey, flush registry file.
+ (void) m_file.flush();
+ }
+ pKey->setModified(false);
+ (void) releaseKey(pRootKey);
+ }
+
+ return releaseKey(pKey);
+}
+
+RegError ORegistry::deleteKey(RegKeyHandle hKey, std::u16string_view keyName)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (keyName.empty())
+ return RegError::INVALID_KEYNAME;
+
+ REG_GUARD(m_mutex);
+
+ if (!pKey)
+ pKey = m_openKeyTable[ROOT];
+
+ OUString sFullKeyName(pKey->getFullPath(keyName));
+ return eraseKey(m_openKeyTable[ROOT], sFullKeyName);
+}
+
+RegError ORegistry::eraseKey(ORegKey* pKey, std::u16string_view keyName)
+{
+ RegError _ret = RegError::NO_ERROR;
+
+ if (keyName.empty())
+ {
+ return RegError::INVALID_KEYNAME;
+ }
+
+ OUString sFullKeyName(pKey->getName());
+ OUString sFullPath(sFullKeyName);
+ OUString sRelativKey;
+ size_t lastIndex = keyName.rfind('/');
+
+ if (lastIndex != std::u16string_view::npos)
+ {
+ sRelativKey += keyName.substr(lastIndex + 1);
+
+ if (sFullKeyName.getLength() > 1)
+ sFullKeyName += keyName;
+ else
+ sFullKeyName += keyName.substr(1);
+
+ sFullPath = sFullKeyName.copy(0, keyName.rfind('/') + 1);
+ } else
+ {
+ if (sFullKeyName.getLength() > 1)
+ sFullKeyName += ROOT;
+
+ sRelativKey += keyName;
+ sFullKeyName += keyName;
+
+ if (sFullPath.getLength() > 1)
+ sFullPath += ROOT;
+ }
+
+ ORegKey* pOldKey = nullptr;
+ _ret = pKey->openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pOldKey));
+ if (_ret != RegError::NO_ERROR)
+ return _ret;
+
+ _ret = deleteSubkeysAndValues(pOldKey);
+ if (_ret != RegError::NO_ERROR)
+ {
+ pKey->closeKey(pOldKey);
+ return _ret;
+ }
+
+ OUString tmpName = sRelativKey + ROOT;
+
+ OStoreFile sFile(pKey->getStoreFile());
+ if (sFile.isValid() && sFile.remove(sFullPath, tmpName))
+ {
+ return RegError::DELETE_KEY_FAILED;
+ }
+ pOldKey->setModified();
+
+ // set flag deleted !!!
+ pOldKey->setDeleted(true);
+
+ return pKey->closeKey(pOldKey);
+}
+
+RegError ORegistry::deleteSubkeysAndValues(ORegKey* pKey)
+{
+ OStoreDirectory::iterator iter;
+ RegError _ret = RegError::NO_ERROR;
+ OStoreDirectory rStoreDir(pKey->getStoreDir());
+ storeError _err = rStoreDir.first(iter);
+
+ while (_err == store_E_None)
+ {
+ OUString const keyName(iter.m_pszName, iter.m_nLength);
+
+ if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
+ {
+ _ret = eraseKey(pKey, keyName);
+ if (_ret != RegError::NO_ERROR)
+ return _ret;
+ }
+ else
+ {
+ OUString sFullPath(pKey->getName());
+
+ if (sFullPath.getLength() > 1)
+ sFullPath += ROOT;
+
+ if (const_cast<OStoreFile&>(pKey->getStoreFile()).remove(sFullPath, keyName))
+ {
+ return RegError::DELETE_VALUE_FAILED;
+ }
+ pKey->setModified();
+ }
+
+ _err = rStoreDir.next(iter);
+ }
+
+ return RegError::NO_ERROR;
+}
+
+ORegKey* ORegistry::getRootKey()
+{
+ m_openKeyTable[ROOT]->acquire();
+ return m_openKeyTable[ROOT];
+}
+
+RegError ORegistry::dumpRegistry(RegKeyHandle hKey) const
+{
+ ORegKey *pKey = static_cast<ORegKey*>(hKey);
+ OUString sName;
+ RegError _ret = RegError::NO_ERROR;
+ OStoreDirectory::iterator iter;
+ OStoreDirectory rStoreDir(pKey->getStoreDir());
+ storeError _err = rStoreDir.first(iter);
+
+ OString regName(OUStringToOString(getName(), osl_getThreadTextEncoding()));
+ 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 = OUString(iter.m_pszName, iter.m_nLength);
+
+ if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
+ {
+ _ret = dumpKey(pKey->getName(), sName, 1);
+ } else
+ {
+ _ret = dumpValue(pKey->getName(), sName, 1);
+ }
+
+ if (_ret != RegError::NO_ERROR)
+ {
+ return _ret;
+ }
+
+ _err = rStoreDir.next(iter);
+ }
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::dumpValue(const OUString& sPath, const OUString& sName, sal_Int16 nSpc) const
+{
+ OStoreStream rValue;
+ sal_uInt32 valueSize;
+ RegValueType valueType;
+ OUString sFullPath(sPath);
+ OString sIndent;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+
+ if (isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ for (int i= 0; i < nSpc; i++) sIndent += " ";
+
+ if (sFullPath.getLength() > 1)
+ {
+ sFullPath += ROOT;
+ }
+ if (rValue.create(m_file, sFullPath, sName, accessMode))
+ {
+ return RegError::VALUE_NOT_EXISTS;
+ }
+
+ std::vector<sal_uInt8> aBuffer(VALUE_HEADERSIZE);
+
+ sal_uInt32 rwBytes;
+ if (rValue.readAt(0, aBuffer.data(), VALUE_HEADERSIZE, rwBytes))
+ {
+ return RegError::INVALID_VALUE;
+ }
+ if (rwBytes != (VALUE_HEADERSIZE))
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ sal_uInt8 type = aBuffer[0];
+ valueType = static_cast<RegValueType>(type);
+ readUINT32(aBuffer.data() + VALUE_TYPEOFFSET, valueSize);
+
+ aBuffer.resize(valueSize);
+ if (rValue.readAt(VALUE_HEADEROFFSET, aBuffer.data(), valueSize, rwBytes))
+ {
+ return RegError::INVALID_VALUE;
+ }
+ if (rwBytes != valueSize)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ const char* indent = sIndent.getStr();
+ switch (valueType)
+ {
+ case RegValueType::NOT_DEFINED:
+ fprintf(stdout, "%sValue: Type = VALUETYPE_NOT_DEFINED\n", indent);
+ break;
+ case RegValueType::LONG:
+ {
+ fprintf(stdout, "%sValue: Type = RegValueType::LONG\n", indent);
+ fprintf(
+ stdout, "%s Size = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(valueSize));
+ fprintf(stdout, "%s Data = ", indent);
+
+ sal_Int32 value;
+ readINT32(aBuffer.data(), value);
+ fprintf(stdout, "%ld\n", sal::static_int_cast< long >(value));
+ }
+ break;
+ case RegValueType::STRING:
+ {
+ char* value = static_cast<char*>(std::malloc(valueSize));
+ readUtf8(aBuffer.data(), value, valueSize);
+ fprintf(stdout, "%sValue: Type = RegValueType::STRING\n", indent);
+ fprintf(
+ stdout, "%s Size = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(valueSize));
+ fprintf(stdout, "%s Data = \"%s\"\n", indent, value);
+ std::free(value);
+ }
+ break;
+ case RegValueType::UNICODE:
+ {
+ sal_uInt32 size = (valueSize / 2) * sizeof(sal_Unicode);
+ fprintf(stdout, "%sValue: Type = RegValueType::UNICODE\n", indent);
+ fprintf(
+ stdout, "%s Size = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(valueSize));
+ fprintf(stdout, "%s Data = ", indent);
+
+ std::unique_ptr<sal_Unicode[]> value(new sal_Unicode[size]);
+ readString(aBuffer.data(), value.get(), size);
+
+ OString uStr(value.get(), rtl_ustr_getLength(value.get()), RTL_TEXTENCODING_UTF8);
+ fprintf(stdout, "L\"%s\"\n", uStr.getStr());
+ }
+ break;
+ case RegValueType::BINARY:
+ {
+ fprintf(stdout, "%sValue: Type = RegValueType::BINARY\n", indent);
+ fprintf(
+ stdout, "%s Size = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(valueSize));
+ fprintf(stdout, "%s Data = ", indent);
+ dumpType(
+ typereg::Reader(aBuffer.data(), valueSize),
+ sIndent + " ");
+ }
+ break;
+ case RegValueType::LONGLIST:
+ {
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
+ sal_uInt32 len = 0;
+
+ readUINT32(aBuffer.data(), len);
+
+ fprintf(stdout, "%sValue: Type = RegValueType::LONGLIST\n", indent);
+ fprintf(
+ stdout, "%s Size = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(valueSize));
+ fprintf(
+ stdout, "%s Len = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(len));
+ fprintf(stdout, "%s Data = ", indent);
+
+ sal_Int32 longValue;
+ for (sal_uInt32 i=0; i < len; i++)
+ {
+ readINT32(aBuffer.data() + offset, longValue);
+
+ if (offset > 4)
+ fprintf(stdout, "%s ", indent);
+
+ fprintf(
+ stdout, "%lu = %ld\n",
+ sal::static_int_cast< unsigned long >(i),
+ sal::static_int_cast< long >(longValue));
+ offset += 4; // 4 Bytes for sal_Int32
+ }
+ }
+ break;
+ case RegValueType::STRINGLIST:
+ {
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
+ sal_uInt32 sLen = 0;
+ sal_uInt32 len = 0;
+
+ readUINT32(aBuffer.data(), len);
+
+ fprintf(stdout, "%sValue: Type = RegValueType::STRINGLIST\n", indent);
+ fprintf(
+ stdout, "%s Size = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(valueSize));
+ fprintf(
+ stdout, "%s Len = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(len));
+ fprintf(stdout, "%s Data = ", indent);
+
+ for (sal_uInt32 i=0; i < len; i++)
+ {
+ readUINT32(aBuffer.data() + offset, sLen);
+
+ offset += 4; // 4 bytes (sal_uInt32) for the string size
+
+ char *pValue = static_cast<char*>(std::malloc(sLen));
+ readUtf8(aBuffer.data() + offset, pValue, sLen);
+
+ if (offset > 8)
+ fprintf(stdout, "%s ", indent);
+
+ fprintf(
+ stdout, "%lu = \"%s\"\n",
+ sal::static_int_cast< unsigned long >(i), pValue);
+ std::free(pValue);
+ offset += sLen;
+ }
+ }
+ break;
+ case RegValueType::UNICODELIST:
+ {
+ sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
+ sal_uInt32 sLen = 0;
+ sal_uInt32 len = 0;
+
+ readUINT32(aBuffer.data(), len);
+
+ fprintf(stdout, "%sValue: Type = RegValueType::UNICODELIST\n", indent);
+ fprintf(
+ stdout, "%s Size = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(valueSize));
+ fprintf(
+ stdout, "%s Len = %lu\n", indent,
+ sal::static_int_cast< unsigned long >(len));
+ fprintf(stdout, "%s Data = ", indent);
+
+ OString uStr;
+ for (sal_uInt32 i=0; i < len; i++)
+ {
+ readUINT32(aBuffer.data() + offset, sLen);
+
+ offset += 4; // 4 bytes (sal_uInt32) for the string size
+
+ sal_Unicode *pValue = static_cast<sal_Unicode*>(std::malloc((sLen / 2) * sizeof(sal_Unicode)));
+ readString(aBuffer.data() + offset, pValue, sLen);
+
+ if (offset > 8)
+ fprintf(stdout, "%s ", indent);
+
+ uStr = OString(pValue, rtl_ustr_getLength(pValue), RTL_TEXTENCODING_UTF8);
+ fprintf(
+ stdout, "%lu = L\"%s\"\n",
+ sal::static_int_cast< unsigned long >(i),
+ uStr.getStr());
+
+ offset += sLen;
+
+ std::free(pValue);
+ }
+ }
+ break;
+ }
+
+ fprintf(stdout, "\n");
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::dumpKey(const OUString& sPath, const OUString& sName, sal_Int16 nSpace) const
+{
+ OStoreDirectory rStoreDir;
+ OUString sFullPath(sPath);
+ OString sIndent;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+ RegError _ret = RegError::NO_ERROR;
+
+ if (isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ 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 RegError::KEY_NOT_EXISTS;
+ else if (_err == store_E_WrongFormat)
+ return RegError::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 = OUString(iter.m_pszName, iter.m_nLength);
+
+ if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
+ {
+ _ret = dumpKey(sSubPath, sSubName, nSpace+2);
+ } else
+ {
+ _ret = dumpValue(sSubPath, sSubName, nSpace+2);
+ }
+
+ if (_ret != RegError::NO_ERROR)
+ {
+ return _ret;
+ }
+
+ _err = rStoreDir.next(iter);
+ }
+
+ return RegError::NO_ERROR;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/regimpl.hxx b/registry/source/regimpl.hxx
new file mode 100644
index 0000000000..d13d42b6d3
--- /dev/null
+++ b/registry/source/regimpl.hxx
@@ -0,0 +1,123 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <string_view>
+#include <unordered_map>
+
+#include <regapi.hxx>
+#include <registry/regtype.h>
+#include <rtl/ustring.hxx>
+#include <osl/mutex.hxx>
+#include <store/store.hxx>
+
+// 5 bytes = 1 (byte for the type) + 4 (bytes for the size of the data)
+#define VALUE_HEADERSIZE 5
+#define VALUE_TYPEOFFSET 1
+#define VALUE_HEADEROFFSET 5
+
+#define REG_GUARD(mutex) \
+ osl::Guard< osl::Mutex > aGuard( mutex );
+
+class ORegKey;
+
+class ORegistry
+{
+public:
+ ORegistry();
+
+ sal_uInt32 acquire()
+ { return ++m_refCount; }
+
+ sal_uInt32 release()
+ { return --m_refCount; }
+
+ RegError initRegistry(const OUString& name,
+ RegAccessMode accessMode,
+ bool bCreate = false);
+
+ RegError closeRegistry();
+
+ RegError destroyRegistry(const OUString& name);
+
+ RegError acquireKey(RegKeyHandle hKey);
+ RegError releaseKey(RegKeyHandle hKey);
+
+ RegError createKey(RegKeyHandle hKey,
+ std::u16string_view keyName,
+ RegKeyHandle* phNewKey);
+
+ RegError openKey(RegKeyHandle hKey,
+ std::u16string_view keyName,
+ RegKeyHandle* phOpenKey);
+
+ RegError closeKey(RegKeyHandle hKey);
+
+ RegError deleteKey(RegKeyHandle hKey, std::u16string_view keyName);
+
+ RegError dumpRegistry(RegKeyHandle hKey) const;
+
+ ~ORegistry();
+
+ bool isReadOnly() const
+ { return m_readOnly; }
+
+ bool isOpen() const
+ { return m_isOpen; }
+
+ ORegKey* getRootKey();
+
+ const store::OStoreFile& getStoreFile() const
+ { return m_file; }
+
+ const OUString& getName() const
+ { return m_name; }
+
+ friend class ORegKey;
+
+private:
+ RegError eraseKey(ORegKey* pKey, std::u16string_view keyName);
+
+ RegError deleteSubkeysAndValues(ORegKey* pKey);
+
+ RegError dumpValue(const OUString& sPath,
+ const OUString& sName,
+ sal_Int16 nSpace) const;
+
+ RegError dumpKey(const OUString& sPath,
+ const OUString& sName,
+ sal_Int16 nSpace) const;
+
+ typedef std::unordered_map< OUString, ORegKey* > KeyMap;
+
+ sal_uInt32 m_refCount;
+ osl::Mutex m_mutex;
+ bool m_readOnly;
+ bool m_isOpen;
+ OUString m_name;
+ store::OStoreFile m_file;
+ KeyMap m_openKeyTable;
+
+ static constexpr OUString ROOT { u"/"_ustr };
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/registry.cxx b/registry/source/registry.cxx
new file mode 100644
index 0000000000..c498f113c7
--- /dev/null
+++ b/registry/source/registry.cxx
@@ -0,0 +1,301 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <registry/registry.hxx>
+
+#include "keyimpl.hxx"
+#include "regimpl.hxx"
+#include "regkey.hxx"
+
+#if defined(_WIN32)
+#include <io.h>
+#endif
+
+extern "C" {
+
+static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
+{
+ ORegistry* pReg = static_cast<ORegistry*>(hReg);
+
+ if (pReg != nullptr)
+ pReg->acquire();
+}
+
+static void REGISTRY_CALLTYPE release(RegHandle hReg)
+{
+ ORegistry* pReg = static_cast<ORegistry*>(hReg);
+
+ if (pReg && pReg->release() == 0)
+ {
+ delete pReg;
+ hReg = nullptr;
+ }
+}
+
+static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
+{
+ if (hReg)
+ {
+ ORegistry* pReg = static_cast<ORegistry*>(hReg);
+ if ( pReg->isOpen() )
+ {
+ rtl_uString_assign(pName, pReg->getName().pData);
+ return RegError::NO_ERROR;
+ } else
+ {
+ rtl_uString_new(pName);
+ return RegError::REGISTRY_NOT_OPEN;
+ }
+ }
+
+ rtl_uString_new(pName);
+ return RegError::INVALID_REGISTRY;
+}
+
+static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
+{
+ if (hReg)
+ return static_cast<ORegistry*>(hReg)->isReadOnly();
+ else
+ return false;
+}
+
+static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
+ RegHandle* phRegistry)
+{
+ RegError ret;
+
+ ORegistry* pReg = new ORegistry();
+ if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)) != RegError::NO_ERROR)
+ {
+ delete pReg;
+ *phRegistry = nullptr;
+ return ret;
+ }
+
+ *phRegistry = pReg;
+
+ return RegError::NO_ERROR;
+}
+
+static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg,
+ RegKeyHandle* phRootKey)
+{
+ ORegistry* pReg;
+
+ if (hReg)
+ {
+ pReg = static_cast<ORegistry*>(hReg);
+ if (!pReg->isOpen())
+ return RegError::REGISTRY_NOT_OPEN;
+ } else
+ {
+ phRootKey = nullptr;
+ return RegError::INVALID_REGISTRY;
+ }
+
+ *phRootKey = pReg->getRootKey();
+
+ return RegError::NO_ERROR;
+}
+
+static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
+ RegHandle* phRegistry,
+ RegAccessMode accessMode)
+{
+ RegError _ret;
+
+ ORegistry* pReg = new ORegistry();
+ if ((_ret = pReg->initRegistry(registryName, accessMode)) != RegError::NO_ERROR)
+ {
+ *phRegistry = nullptr;
+ delete pReg;
+ return _ret;
+ }
+
+
+ *phRegistry = pReg;
+
+ return RegError::NO_ERROR;
+}
+
+static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
+{
+ if (hReg)
+ {
+ ORegistry *pReg = static_cast<ORegistry*>(hReg);
+ if (!pReg->isOpen())
+ return RegError::REGISTRY_NOT_OPEN;
+
+ RegError ret = RegError::NO_ERROR;
+ if (pReg->release() == 0)
+ {
+ delete pReg;
+ hReg = nullptr;
+ }
+ else
+ ret = pReg->closeRegistry();
+
+ return ret;
+ } else
+ {
+ return RegError::INVALID_REGISTRY;
+ }
+}
+
+static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg,
+ rtl_uString* registryName)
+{
+ if (hReg)
+ {
+ ORegistry *pReg = static_cast<ORegistry*>(hReg);
+ if (!pReg->isOpen())
+ return RegError::INVALID_REGISTRY;
+
+ RegError ret = pReg->destroyRegistry(registryName);
+ if (ret == RegError::NO_ERROR)
+ {
+ if (!registryName->length)
+ {
+ delete pReg;
+ hReg = nullptr;
+ }
+ }
+ return ret;
+ } else
+ {
+ return RegError::INVALID_REGISTRY;
+ }
+}
+
+
+// dumpRegistry
+
+static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg,
+ RegKeyHandle hKey)
+{
+ ORegistry* pReg = static_cast< ORegistry* >(hReg);
+ if (!pReg)
+ return RegError::INVALID_REGISTRY;
+ if (!pReg->isOpen())
+ return RegError::REGISTRY_NOT_OPEN;
+
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+ if (pKey->getRegistry() != pReg)
+ return RegError::INVALID_KEY;
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ return pReg->dumpRegistry(hKey);
+}
+
+Registry_Api* REGISTRY_CALLTYPE initRegistry_Api()
+{
+ static Registry_Api aApi= {&acquire,
+ &release,
+ &isReadOnly,
+ &openRootKey,
+ &getName,
+ &createRegistry,
+ &openRegistry,
+ &closeRegistry,
+ &destroyRegistry,
+ &acquireKey,
+ &releaseKey,
+ &isKeyReadOnly,
+ &getKeyName,
+ &createKey,
+ &openKey,
+ &openSubKeys,
+ &closeSubKeys,
+ &deleteKey,
+ &closeKey,
+ &setValue,
+ &setLongListValue,
+ &setStringListValue,
+ &setUnicodeListValue,
+ &getValueInfo,
+ &getValue,
+ &getLongListValue,
+ &getStringListValue,
+ &getUnicodeListValue,
+ &freeValueList,
+ &getResolvedKeyName,
+ &getKeyNames,
+ &freeKeyNames};
+
+ return (&aApi);
+}
+
+}
+
+RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
+ RegKeyHandle* phRootKey)
+{
+ return openRootKey(hRegistry, phRootKey);
+}
+
+RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
+ RegHandle* phRegistry)
+{
+ RegError _ret;
+
+ ORegistry* pReg = new ORegistry();
+ if ((_ret = pReg->initRegistry(registryName, RegAccessMode::READONLY)) != RegError::NO_ERROR)
+ {
+ delete pReg;
+ *phRegistry = nullptr;
+ return _ret;
+ }
+
+ *phRegistry = pReg;
+
+ return RegError::NO_ERROR;
+}
+
+RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
+{
+ if (hRegistry)
+ {
+ ORegistry* pReg = static_cast<ORegistry*>(hRegistry);
+ delete pReg;
+ return RegError::NO_ERROR;
+ } else
+ {
+ return RegError::REGISTRY_NOT_OPEN;
+ }
+}
+
+RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey)
+{
+ ORegKey *pKey;
+
+ if (hKey)
+ pKey = static_cast<ORegKey*>(hKey);
+ else
+ return RegError::INVALID_KEY;
+
+ return dumpRegistry(pKey->getRegistry(), hKey);
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/regkey.cxx b/registry/source/regkey.cxx
new file mode 100644
index 0000000000..b2eeb63e67
--- /dev/null
+++ b/registry/source/regkey.cxx
@@ -0,0 +1,618 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "regkey.hxx"
+
+#include <osl/diagnose.h>
+#include "regimpl.hxx"
+#include "keyimpl.hxx"
+
+void REGISTRY_CALLTYPE acquireKey(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (pKey != nullptr)
+ {
+ ORegistry* pReg = pKey->getRegistry();
+ (void) pReg->acquireKey(pKey);
+ }
+}
+
+void REGISTRY_CALLTYPE releaseKey(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (pKey != nullptr)
+ {
+ ORegistry* pReg = pKey->getRegistry();
+ (void) pReg->releaseKey(pKey);
+ }
+}
+
+sal_Bool REGISTRY_CALLTYPE isKeyReadOnly(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ return pKey != nullptr && pKey->isReadOnly();
+}
+
+RegError REGISTRY_CALLTYPE getKeyName(RegKeyHandle hKey, rtl_uString** pKeyName)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (pKey)
+ {
+ rtl_uString_assign( pKeyName, pKey->getName().pData );
+ return RegError::NO_ERROR;
+ } else
+ {
+ rtl_uString_new(pKeyName);
+ return RegError::INVALID_KEY;
+ }
+}
+
+RegError REGISTRY_CALLTYPE createKey(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegKeyHandle* phNewKey)
+{
+ *phNewKey = nullptr;
+
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ if (pKey->isReadOnly())
+ return RegError::REGISTRY_READONLY;
+
+ return pKey->createKey(OUString::unacquired(&keyName), phNewKey);
+}
+
+RegError REGISTRY_CALLTYPE openKey(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegKeyHandle* phOpenKey)
+{
+ *phOpenKey = nullptr;
+
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ return pKey->openKey(OUString::unacquired(&keyName), phOpenKey);
+}
+
+RegError REGISTRY_CALLTYPE openSubKeys(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegKeyHandle** pphSubKeys,
+ sal_uInt32* pnSubKeys)
+{
+ *pphSubKeys = nullptr;
+ *pnSubKeys = 0;
+
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ return pKey->openSubKeys(OUString::unacquired(&keyName), pphSubKeys, pnSubKeys);
+}
+
+RegError REGISTRY_CALLTYPE closeSubKeys(RegKeyHandle* phSubKeys,
+ sal_uInt32 nSubKeys)
+{
+ if (phSubKeys == nullptr || nSubKeys == 0)
+ return RegError::INVALID_KEY;
+
+ ORegistry* pReg = static_cast<ORegKey*>(phSubKeys[0])->getRegistry();
+ for (sal_uInt32 i = 0; i < nSubKeys; i++)
+ {
+ (void) pReg->closeKey(phSubKeys[i]);
+ }
+ std::free(phSubKeys);
+
+ return RegError::NO_ERROR;
+}
+
+RegError REGISTRY_CALLTYPE deleteKey(RegKeyHandle hKey,
+ rtl_uString* keyName)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ if (pKey->isReadOnly())
+ return RegError::REGISTRY_READONLY;
+
+ return pKey->deleteKey(OUString::unacquired(&keyName));
+}
+
+RegError REGISTRY_CALLTYPE closeKey(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ return pKey->closeKey(hKey);
+}
+
+RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegValueType valueType,
+ RegValue pData,
+ sal_uInt32 valueSize)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ if (pKey->isReadOnly())
+ return RegError::REGISTRY_READONLY;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret1 = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret1 != RegError::NO_ERROR)
+ return _ret1;
+
+ _ret1 = pSubKey->setValue(valueName, valueType, pData, valueSize);
+ if (_ret1 != RegError::NO_ERROR)
+ {
+ RegError _ret2 = pKey->closeKey(pSubKey);
+ if (_ret2 != RegError::NO_ERROR)
+ return _ret2;
+ else
+ return _ret1;
+ }
+
+ return pKey->closeKey(pSubKey);
+ }
+
+ return pKey->setValue(valueName, valueType, pData, valueSize);
+}
+
+RegError REGISTRY_CALLTYPE setLongListValue(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ sal_Int32 const * pValueList,
+ sal_uInt32 len)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ if (pKey->isReadOnly())
+ return RegError::REGISTRY_READONLY;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret1 = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret1 != RegError::NO_ERROR)
+ return _ret1;
+
+ _ret1 = pSubKey->setLongListValue(valueName, pValueList, len);
+ if (_ret1 != RegError::NO_ERROR)
+ {
+ RegError _ret2 = pKey->closeKey(pSubKey);
+ if (_ret2 != RegError::NO_ERROR)
+ return _ret2;
+ else
+ return _ret1;
+ }
+
+ return pKey->closeKey(pSubKey);
+ }
+
+ return pKey->setLongListValue(valueName, pValueList, len);
+}
+
+RegError REGISTRY_CALLTYPE setStringListValue(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ char** pValueList,
+ sal_uInt32 len)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ if (pKey->isReadOnly())
+ return RegError::REGISTRY_READONLY;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret1 = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret1 != RegError::NO_ERROR)
+ return _ret1;
+
+ _ret1 = pSubKey->setStringListValue(valueName, pValueList, len);
+ if (_ret1 != RegError::NO_ERROR)
+ {
+ RegError _ret2 = pKey->closeKey(pSubKey);
+ if (_ret2 != RegError::NO_ERROR)
+ return _ret2;
+ else
+ return _ret1;
+ }
+
+ return pKey->closeKey(pSubKey);
+ }
+
+ return pKey->setStringListValue(valueName, pValueList, len);
+}
+
+RegError REGISTRY_CALLTYPE setUnicodeListValue(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ sal_Unicode** pValueList,
+ sal_uInt32 len)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ if (pKey->isReadOnly())
+ return RegError::REGISTRY_READONLY;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret1 = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret1 != RegError::NO_ERROR)
+ return _ret1;
+
+ _ret1 = pSubKey->setUnicodeListValue(valueName, pValueList, len);
+ if (_ret1 != RegError::NO_ERROR)
+ {
+ RegError _ret2 = pKey->closeKey(pSubKey);
+ if (_ret2 != RegError::NO_ERROR)
+ return _ret2;
+ else
+ return _ret1;
+ }
+
+ return pKey->closeKey(pSubKey);
+ }
+
+ return pKey->setUnicodeListValue(valueName, pValueList, len);
+}
+
+RegError REGISTRY_CALLTYPE getValueInfo(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegValueType* pValueType,
+ sal_uInt32* pValueSize)
+{
+ *pValueType = RegValueType::NOT_DEFINED;
+ *pValueSize = 0;
+
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret != RegError::NO_ERROR)
+ return _ret;
+
+ if (pSubKey->getValueInfo(valueName, &valueType, &valueSize) != RegError::NO_ERROR)
+ {
+ (void) pKey->releaseKey(pSubKey);
+ return RegError::INVALID_VALUE;
+ }
+
+ *pValueType = valueType;
+ *pValueSize = valueSize;
+
+ return pKey->releaseKey(pSubKey);
+ }
+
+
+ if (pKey->getValueInfo(valueName, &valueType, &valueSize) != RegError::NO_ERROR)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ *pValueType = valueType;
+ *pValueSize = valueSize;
+
+ return RegError::NO_ERROR;
+}
+
+RegError REGISTRY_CALLTYPE getValue(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegValue pValue)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret1 = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret1 != RegError::NO_ERROR)
+ return _ret1;
+
+ _ret1 = pSubKey->getValue(valueName, pValue);
+ if (_ret1 != RegError::NO_ERROR)
+ {
+ (void) pKey->releaseKey(pSubKey);
+ return _ret1;
+ }
+
+ return pKey->releaseKey(pSubKey);
+ }
+
+ return pKey->getValue(valueName, pValue);
+}
+
+RegError REGISTRY_CALLTYPE getLongListValue(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ sal_Int32** pValueList,
+ sal_uInt32* pLen)
+{
+ assert((pValueList != nullptr) && (pLen != nullptr) && "registry::getLongListValue(): invalid parameter");
+ *pValueList = nullptr;
+ *pLen = 0;
+
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret1 = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret1 != RegError::NO_ERROR)
+ return _ret1;
+
+ _ret1 = pSubKey->getLongListValue(valueName, pValueList, pLen);
+ if (_ret1 != RegError::NO_ERROR)
+ {
+ (void) pKey->releaseKey(pSubKey);
+ return _ret1;
+ }
+
+ return pKey->releaseKey(pSubKey);
+ }
+
+ return pKey->getLongListValue(valueName, pValueList, pLen);
+}
+
+RegError REGISTRY_CALLTYPE getStringListValue(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ char*** pValueList,
+ sal_uInt32* pLen)
+{
+ OSL_PRECOND((pValueList != nullptr) && (pLen != nullptr), "registry::getStringListValue(): invalid parameter");
+ *pValueList = nullptr;
+ *pLen = 0;
+
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret1 = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret1 != RegError::NO_ERROR)
+ return _ret1;
+
+ _ret1 = pSubKey->getStringListValue(valueName, pValueList, pLen);
+ if (_ret1 != RegError::NO_ERROR)
+ {
+ (void) pKey->releaseKey(pSubKey);
+ return _ret1;
+ }
+
+ return pKey->releaseKey(pSubKey);
+ }
+
+ return pKey->getStringListValue(valueName, pValueList, pLen);
+}
+
+RegError REGISTRY_CALLTYPE getUnicodeListValue(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ sal_Unicode*** pValueList,
+ sal_uInt32* pLen)
+{
+ assert((pValueList != nullptr) && (pLen != nullptr) && "registry::getUnicodeListValue(): invalid parameter");
+ *pValueList = nullptr;
+ *pLen = 0;
+
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ OUString valueName("value");
+ if (keyName->length)
+ {
+ ORegKey* pSubKey = nullptr;
+ RegError _ret1 = pKey->openKey(OUString::unacquired(&keyName), reinterpret_cast<RegKeyHandle*>(&pSubKey));
+ if (_ret1 != RegError::NO_ERROR)
+ return _ret1;
+
+ _ret1 = pSubKey->getUnicodeListValue(valueName, pValueList, pLen);
+ if (_ret1 != RegError::NO_ERROR)
+ {
+ (void) pKey->releaseKey(pSubKey);
+ return _ret1;
+ }
+
+ return pKey->releaseKey(pSubKey);
+ }
+
+ return pKey->getUnicodeListValue(valueName, pValueList, pLen);
+}
+
+RegError REGISTRY_CALLTYPE freeValueList(RegValueType valueType,
+ RegValue pValueList,
+ sal_uInt32 len)
+{
+ switch (valueType)
+ {
+ case RegValueType::LONGLIST:
+ {
+ std::free(pValueList);
+ }
+ break;
+ case RegValueType::STRINGLIST:
+ {
+ char** pVList = static_cast<char**>(pValueList);
+ for (sal_uInt32 i=0; i < len; i++)
+ {
+ std::free(pVList[i]);
+ }
+
+ std::free(pVList);
+ }
+ break;
+ case RegValueType::UNICODELIST:
+ {
+ sal_Unicode** pVList = static_cast<sal_Unicode**>(pValueList);
+ for (sal_uInt32 i=0; i < len; i++)
+ {
+ std::free(pVList[i]);
+ }
+
+ std::free(pVList);
+ }
+ break;
+ default:
+ return RegError::INVALID_VALUE;
+ }
+
+ pValueList = nullptr;
+ return RegError::NO_ERROR;
+}
+
+RegError REGISTRY_CALLTYPE getResolvedKeyName(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ SAL_UNUSED_PARAMETER sal_Bool,
+ rtl_uString** pResolvedName)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ OUString resolvedName;
+ RegError _ret = pKey->getResolvedKeyName(OUString::unacquired(&keyName), resolvedName);
+ if (_ret == RegError::NO_ERROR)
+ rtl_uString_assign(pResolvedName, resolvedName.pData);
+ return _ret;
+}
+
+RegError REGISTRY_CALLTYPE getKeyNames(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ rtl_uString*** pSubKeyNames,
+ sal_uInt32* pnSubKeys)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ return pKey->getKeyNames(OUString::unacquired(&keyName), pSubKeyNames, pnSubKeys);
+}
+
+RegError REGISTRY_CALLTYPE freeKeyNames(rtl_uString** pKeyNames,
+ sal_uInt32 nKeys)
+{
+ for (sal_uInt32 i=0; i < nKeys; i++)
+ {
+ rtl_uString_release(pKeyNames[i]);
+ }
+
+ std::free(pKeyNames);
+
+ return RegError::NO_ERROR;
+}
+
+RegError REGISTRY_CALLTYPE reg_openKey(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegKeyHandle* phOpenKey)
+{
+ if (!hKey)
+ return RegError::INVALID_KEY;
+
+ return openKey(hKey, keyName, phOpenKey);
+}
+
+RegError REGISTRY_CALLTYPE reg_closeKey(RegKeyHandle hKey)
+{
+ if (!hKey)
+ return RegError::INVALID_KEY;
+
+ return closeKey(hKey);
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/regkey.hxx b/registry/source/regkey.hxx
new file mode 100644
index 0000000000..51114e5ccc
--- /dev/null
+++ b/registry/source/regkey.hxx
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/config.h>
+#include <registry/regtype.h>
+#include <rtl/ustring.h>
+#include <sal/types.h>
+
+extern "C" {
+
+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 const *, sal_uInt32);
+RegError REGISTRY_CALLTYPE setStringListValue(
+ RegKeyHandle, rtl_uString*, 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*, 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 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);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/test/makefile.mk b/registry/test/makefile.mk
new file mode 100644
index 0000000000..f6d99120f1
--- /dev/null
+++ b/registry/test/makefile.mk
@@ -0,0 +1,81 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+#
+
+PRJ=..
+
+PRJNAME=registry
+TARGET=regtest
+
+USE_LDUMP2=TRUE
+
+ENABLE_EXCEPTIONS := TRUE
+
+# --- Settings -----------------------------------------------------
+.INCLUDE : settings.mk
+
+
+# ------------------------------------------------------------------
+CDEFS += -DDLL_VERSION=$(EMQ)"$(DLLPOSTFIX)$(EMQ)"
+
+CXXFILES= \
+ testregcpp.cxx \
+ testmerge.cxx
+
+
+LIB1TARGET= $(SLB)$/$(TARGET).lib
+
+LIB1OBJFILES= \
+ $(SLO)$/testregcpp.obj \
+ $(SLO)$/testmerge.obj
+
+
+SHL1TARGET= rgt$(DLLPOSTFIX)
+SHL1IMPLIB= rgt
+SHL1STDLIBS= \
+ $(SALLIB) \
+ $(SALHELPERLIB) \
+ $(REGLIB) \
+ $(STDLIBCPP)
+
+SHL1LIBS= $(LIB1TARGET)
+SHL1DEPN= $(LIB1TARGET)
+SHL1DEF= $(MISC)$/$(SHL1TARGET).def
+DEF1NAME= $(SHL1TARGET)
+
+DEF1DEPN =$(MISC)$/rgt$(DLLPOSTFIX).flt $(SLOFILES)
+DEFLIB1NAME =$(TARGET)
+DEF1DES =Registry Runtime - TestDll
+
+# --- Targets ------------------------------------------------------
+
+#all: \
+# ALLTAR
+
+.INCLUDE : target.mk
+
+# --- SO2-Filter-Datei ---
+
+
+$(MISC)$/rgt$(DLLPOSTFIX).flt:
+ @echo ------------------------------
+ @echo Making: $@
+ @echo WEP>$@
+ @echo LIBMAIN>>$@
+ @echo LibMain>>$@
+
+
diff --git a/registry/test/regdiagnose.h b/registry/test/regdiagnose.h
new file mode 100644
index 0000000000..9d4562d9ed
--- /dev/null
+++ b/registry/test/regdiagnose.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#ifndef INCLUDED_REGISTRY_TEST_REGDIAGNOSE_H
+#define INCLUDED_REGISTRY_TEST_REGDIAGNOSE_H
+
+#include <osl/diagnose.h>
+
+#define REG_ENSURE(c, m) _REG_ENSURE(c, __FILE__, __LINE__, m)
+
+#define _REG_ENSURE(c, f, l, m) \
+ do \
+ { \
+ if (!(c) && ::osl_assertFailedLine(f, l, m)) \
+ ::osl_breakDebug(); \
+ } while (0)
+
+
+#endif // INCLUDED_REGISTRY_TEST_REGDIAGNOSE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/test/testmerge.cxx b/registry/test/testmerge.cxx
new file mode 100644
index 0000000000..d16100c5c3
--- /dev/null
+++ b/registry/test/testmerge.cxx
@@ -0,0 +1,405 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <iostream>
+#include <stdio.h>
+#include <string.h>
+
+#include "registry/registry.hxx"
+#include "registry/reflread.hxx"
+#include "registry/reflwrit.hxx"
+#include "regdiagnose.h"
+#include <rtl/alloc.h>
+#include <rtl/ustring.hxx>
+
+
+sal_Int32 lValue1 = 123456789;
+sal_Int32 lValue2 = 54321;
+sal_Int32 lValue3 = 111333111;
+sal_Int32 lValue4 = 333111333;
+char* sValue = (char*)"string Value";
+OUString wValue("unicode Value");
+
+
+void test_generateMerge1()
+{
+ Registry *myRegistry = new Registry();
+
+ RegistryKey rootKey, key1, key2, key3, key4, key5, key6, key7, key8, key9;
+
+ REG_ENSURE(!myRegistry->create(OUString("merge1.rdb")), "testGenerateMerge1 error 1");
+ REG_ENSURE(!myRegistry->openRootKey(rootKey), "testGenerateMerge1 error 2");
+
+ REG_ENSURE(!rootKey.createKey(OUString("MergeKey1"), key1), "testGenerateMerge1 error 3");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1/MK1SubKey1"), key2), "testGenerateMerge1 error 4");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1/MK1SubKey1/KeyWithLongValue"), key3), "testGenerateMerge1 error 5");
+ REG_ENSURE(!key3.setValue(OUString(), RegValueType::LONG, &lValue1, sizeof(sal_Int32)), "testGenerateMerge1 error 5a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1/MK1SubKey2"), key4), "testGenerateMerge1 error 6");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1/MK1SubKey2/KeyWithStringValue"), key5), "testGenerateMerge1 error 7");
+ REG_ENSURE(!key5.setValue(OUString(), RegValueType::STRING, sValue, strlen(sValue)+1), "testGenerateMerge1 error 7a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1/MK1SubKey3"), key6), "testGenerateMerge1 error 8");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1/MK1SubKey3/KeyWithUnicodeValue"), key7), "testGenerateMerge1 error 9");
+ REG_ENSURE(!key7.setValue(OUString(), RegValueType::UNICODE, (void*)wValue.getStr(), ((wValue.getLength()+1)*sizeof(sal_Unicode))), "testGenerateMerge1 error 9a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1/MK1SubKey4"), key8), "testGenerateMerge1 error 10");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1/MK1SubKey4/KeyWithBinaryValue"), key9), "testGenerateMerge1 error 11");
+ REG_ENSURE(!key9.setValue(OUString(), RegValueType::BINARY, (void*)"abcdefghijklmnopqrstuvwxyz", 27), "testGenerateMerge1 error 11a");
+
+
+ REG_ENSURE(!key1.closeKey() &&
+ !key2.closeKey() &&
+ !key3.closeKey() &&
+ !key4.closeKey() &&
+ !key5.closeKey() &&
+ !key6.closeKey() &&
+ !key7.closeKey() &&
+ !key8.closeKey() &&
+ !key9.closeKey(), "testGenerateMerge1 error 12");
+
+ REG_ENSURE(!rootKey.createKey(OUString("MergeKey1u2"), key1), "testGenerateMerge1 error 13");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK1SubKey11"), key2), "testGenerateMerge1 error 14");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK1SubKey11/KeyWithLongValue"), key3), "testGenerateMerge1 error 15");
+ REG_ENSURE(!key3.setValue(OUString(), RegValueType::LONG, &lValue2, sizeof(sal_Int32)), "testGenerateMerge1 error 15a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK1SubKey12"), key4), "testGenerateMerge1 error 16");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK1SubKey12/KeyWithStringValue"), key5), "testGenerateMerge1 error 17");
+ REG_ENSURE(!key5.setValue(OUString(), RegValueType::STRING, sValue, strlen(sValue)+1), "testGenerateMerge1 error 17a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK1SubKey13"), key6), "testGenerateMerge1 error 18");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK1SubKey13/KeyWithUnicodeValue"), key7), "testGenerateMerge1 error 19");
+ REG_ENSURE(!key7.setValue(OUString(), RegValueType::UNICODE, (void*)wValue.getStr(), ((wValue.getLength()+1)*sizeof(sal_Unicode))), "testGenerateMerge1 error 19a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK12SubKey1u2"), key8), "testGenerateMerge1 error 20");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK12SubKey1u2/KeyWithLongValue"), key9), "testGenerateMerge1 error 21");
+ REG_ENSURE(!key9.setValue(OUString(), RegValueType::LONG, &lValue3, sizeof(sal_Int32)), "testGenerateMerge1 error 21a");
+
+ REG_ENSURE(!rootKey.closeKey() &&
+ !key1.closeKey() &&
+ !key2.closeKey() &&
+ !key3.closeKey() &&
+ !key4.closeKey() &&
+ !key5.closeKey() &&
+ !key6.closeKey() &&
+ !key7.closeKey() &&
+ !key8.closeKey() &&
+ !key9.closeKey(), "testGenerateMerge1 error 22");
+
+
+ delete myRegistry;
+
+ std::cout << "test_generateMerge1() Ok!\n";
+ return;
+}
+
+void test_generateMerge2()
+{
+ Registry *myRegistry = new Registry();
+
+ RegistryKey rootKey, key1, key2, key3, key4, key5, key6, key7, key8, key9;
+
+ REG_ENSURE(!myRegistry->create(OUString("merge2.rdb")), "testGenerateMerge2 error 1");
+ REG_ENSURE(!myRegistry->openRootKey(rootKey), "testGenerateMerge2 error 2");
+
+ REG_ENSURE(!rootKey.createKey(OUString("MergeKey2"), key1), "testGenerateMerge2 error 3");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey2/MK2SubKey1"), key2), "testGenerateMerge2 error 4");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey2/MK2SubKey1/KeyWithBinaryValue"), key3), "testGenerateMerge2 error 5");
+ REG_ENSURE(!key3.setValue(OUString(), RegValueType::BINARY, (void*)"1234567890", 11), "testGenerateMerge1 error 5a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey2/MK2SubKey2"), key4), "testGenerateMerge2 error 6");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey2/MK2SubKey2/KeyWithUnicodeValue"), key5), "testGenerateMerge2 error 7");
+ REG_ENSURE(!key5.setValue(OUString(), RegValueType::UNICODE, (void*)wValue.getStr(), ((wValue.getLength()+1)*sizeof(sal_Unicode))), "testGenerateMerge1 error 7a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey2/MK2SubKey3"), key6), "testGenerateMerge2 error 8");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey2/MK2SubKey3/KeyWithStringValue"), key7), "testGenerateMerge2 error 9");
+ REG_ENSURE(!key7.setValue(OUString(), RegValueType::STRING, sValue, strlen(sValue)+1), "testGenerateMerge1 error 9a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey2/MK2SubKey4"), key8), "testGenerateMerge2 error 10");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey2/MK2SubKey4/KeyWithLongValue"), key9), "testGenerateMerge2 error 11");
+ REG_ENSURE(!key9.setValue(OUString(), RegValueType::LONG, &lValue1, sizeof(sal_Int32)), "testGenerateMerge1 error 11a");
+
+ REG_ENSURE(!key1.closeKey() &&
+ !key2.closeKey() &&
+ !key3.closeKey() &&
+ !key4.closeKey() &&
+ !key5.closeKey() &&
+ !key6.closeKey() &&
+ !key7.closeKey() &&
+ !key8.closeKey() &&
+ !key9.closeKey(), "testGenerateMerge2 error 12");
+
+ REG_ENSURE(!rootKey.createKey(OUString("MergeKey1u2"), key1), "testGenerateMerge2 error 13");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK2SubKey21"), key2), "testGenerateMerge2 error 14");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK2SubKey21/KeyWithBinaryValue"), key3), "testGenerateMerge2 error 15");
+ REG_ENSURE(!key3.setValue(OUString(), RegValueType::BINARY, (void*)"a1b2c3d4e5f6g7h8i9", 19), "testGenerateMerge1 error 15a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK2SubKey22"), key4), "testGenerateMerge2 error 16");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK2SubKey22/KeyWithLongValue"), key5), "testGenerateMerge2 error 17");
+ REG_ENSURE(!key5.setValue(OUString(), RegValueType::LONG, &lValue2, sizeof(sal_Int32)), "testGenerateMerge1 error 17a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK2SubKey23"), key6), "testGenerateMerge2 error 18");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK2SubKey23/KeyWithStringValue"), key7), "testGenerateMerge2 error 19");
+ REG_ENSURE(!key7.setValue(OUString(), RegValueType::STRING, sValue, strlen(sValue)+1), "testGenerateMerge1 error 19a");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK12SubKey1u2"), key8), "testGenerateMerge2 error 20");
+ REG_ENSURE(!rootKey.createKey(OUString("/MergeKey1u2/MK12SubKey1u2/KeyWithLongValue"), key9), "testGenerateMerge2 error 21");
+ REG_ENSURE(!key9.setValue(OUString(), RegValueType::LONG, &lValue4, sizeof(sal_Int32)), "testGenerateMerge1 error 21a");
+
+ REG_ENSURE(!rootKey.closeKey() &&
+ !key1.closeKey() &&
+ !key2.closeKey() &&
+ !key3.closeKey() &&
+ !key4.closeKey() &&
+ !key5.closeKey() &&
+ !key6.closeKey() &&
+ !key7.closeKey() &&
+ !key8.closeKey() &&
+ !key9.closeKey(), "testGenerateMerge2 error 22");
+
+
+ delete myRegistry;
+
+ std::cout << "test_generateMerge2() Ok!\n";
+ return;
+}
+
+void test_merge()
+{
+ Registry *myRegistry = new Registry();
+
+ RegistryKey rootKey, key1, mkey1, key2, mkey2, key1u2, mkey1u2;
+
+ REG_ENSURE(!myRegistry->create(OUString("mergetest.rdb")), "testMerge error 1");
+ REG_ENSURE(myRegistry->getName() == "mergetest.rdb", "testMerge error 1.a)");
+ REG_ENSURE(!myRegistry->openRootKey(rootKey), "testMerge error 2");
+ REG_ENSURE(!myRegistry->loadKey(rootKey, OUString("/stardiv/IchbineinMergeKey"),
+ OUString("merge1.rdb")), "testMerge error 3");
+ REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("/stardiv/IchbineinMergeKey"),
+ OUString("merge2.rdb")), "testMerge error 4");
+
+
+ REG_ENSURE(!rootKey.openKey("/stardiv/IchbineinMergeKey", key1), "testMerge error 5");
+
+ REG_ENSURE(!key1.openKey("MergeKey1", mkey1), "testMerge error 6");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 7");
+
+ REG_ENSURE(!key1.openKey("/MergeKey1/MK1SubKey1", mkey1), "testMerge error 8");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 9");
+ REG_ENSURE(!key1.openKey("/MergeKey1/MK1SubKey1/KeyWithLongValue", mkey1), "testMerge error 10");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 11");
+
+ REG_ENSURE(!key1.openKey("/MergeKey1/MK1SubKey2", mkey1), "testMerge error 12");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 13");
+ REG_ENSURE(!key1.openKey("/MergeKey1/MK1SubKey2/KeyWithStringValue", mkey1), "testMerge error 14");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 15");
+
+ REG_ENSURE(!key1.openKey("/MergeKey1/MK1SubKey3", mkey1), "testMerge error 16");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 17");
+ REG_ENSURE(!key1.openKey("/MergeKey1/MK1SubKey3/KeyWithUnicodeValue", mkey1), "testMerge error 18");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 19");
+
+ REG_ENSURE(!key1.openKey("/MergeKey1/MK1SubKey4", mkey1), "testMerge error 20");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 21");
+ REG_ENSURE(!key1.openKey("/MergeKey1/MK1SubKey4/KeyWithBinaryValue", mkey1), "testMerge error 22");
+ REG_ENSURE(!mkey1.closeKey(), "testMerge error 23");
+
+ REG_ENSURE(!key1.closeKey(), "testMerge error 24");
+
+
+ REG_ENSURE(!rootKey.openKey("/stardiv/IchbineinMergeKey", key2), "testMerge error 25");
+
+ REG_ENSURE(!key2.openKey("MergeKey2", mkey2), "testMerge error 26");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 27");
+
+ REG_ENSURE(!key2.openKey("/MergeKey2/MK2SubKey1", mkey2), "testMerge error 28");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 29");
+ REG_ENSURE(!key2.openKey("/MergeKey2/MK2SubKey1/KeyWithBinaryValue", mkey2), "testMerge error 30");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 31");
+
+ REG_ENSURE(!key2.openKey("/MergeKey2/MK2SubKey2", mkey2), "testMerge error 31");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 33");
+ REG_ENSURE(!key2.openKey("/MergeKey2/MK2SubKey2/KeyWithUnicodeValue", mkey2), "testMerge error 34");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 35");
+
+ REG_ENSURE(!key2.openKey("/MergeKey2/MK2SubKey3", mkey2), "testMerge error 36");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 37");
+ REG_ENSURE(!key2.openKey("/MergeKey2/MK2SubKey3/KeyWithStringValue", mkey2), "testMerge error 38");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 39");
+
+ REG_ENSURE(!key2.openKey("/MergeKey2/MK2SubKey4", mkey2), "testMerge error 40");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 41");
+ REG_ENSURE(!key2.openKey("/MergeKey2/MK2SubKey4/KeyWithLongValue", mkey2), "testMerge error 42");
+ REG_ENSURE(!mkey2.closeKey(), "testMerge error 43");
+
+ REG_ENSURE(!key2.closeKey(), "testMerge error 44");
+
+
+ REG_ENSURE(!rootKey.openKey("/stardiv/IchbineinMergeKey", key1u2), "testMerge error 40");
+
+ REG_ENSURE(!key1u2.openKey("MergeKey1u2", mkey1u2), "testMerge error 41");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 42");
+
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK1SubKey11", mkey1u2), "testMerge error 43");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 44");
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK1SubKey11/KeyWithLongValue", mkey1u2), "testMerge error 45");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 46");
+
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK1SubKey12", mkey1u2), "testMerge error 47");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 48");
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK1SubKey12/KeyWithStringValue", mkey1u2), "testMerge error 49");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 50");
+
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK1SubKey13", mkey1u2), "testMerge error 51");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 52");
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK1SubKey13/KeyWithUnicodeValue", mkey1u2), "testMerge error 53");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 54");
+
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK2SubKey21", mkey1u2), "testMerge error 55");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 56");
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK2SubKey21/KeyWithBinaryValue", mkey1u2), "testMerge error 57");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 58");
+
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK2SubKey22", mkey1u2), "testMerge error 59");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 60");
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK2SubKey22/KeyWithLongValue", mkey1u2), "testMerge error 61");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 62");
+
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK2SubKey23", mkey1u2), "testMerge error 63");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 64");
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK2SubKey23/KeyWithStringValue", mkey1u2), "testMerge error 65");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 66");
+
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK12SubKey1u2", mkey1u2), "testMerge error 67");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 68");
+ REG_ENSURE(!key1u2.openKey("/MergeKey1u2/MK12SubKey1u2/KeyWithLongValue", mkey1u2), "testMerge error 69");
+ REG_ENSURE(!mkey1u2.closeKey(), "testMerge error 70");
+
+ REG_ENSURE(!key1u2.closeKey(), "testMerge error 71");
+
+
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+ sal_Int32 int32Value;
+ sal_uInt8 *Value;
+
+ REG_ENSURE(!rootKey.openKey("/stardiv/IchbineinMergeKey", key1), "testMerge error 72");
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1/MK1SubKey1/KeyWithLongValue"), &valueType, &valueSize), "testMerge error 73");
+ REG_ENSURE(valueType == RegValueType::LONG && valueSize == sizeof(sal_Int32), "testMerge error 74");
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1/MK1SubKey1/KeyWithLongValue"), (RegValue)&int32Value), "testMerge error 74.a)");
+ REG_ENSURE(int32Value == lValue1, "testMerge error 74.b)");
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1/MK1SubKey2/KeyWithStringValue"), &valueType, &valueSize), "testMerge error 75");
+ REG_ENSURE(valueType == RegValueType::STRING && valueSize == strlen(sValue)+1, "testMerge error 76");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1/MK1SubKey2/KeyWithStringValue"), (RegValue)Value), "testMerge error 76.a)");
+ REG_ENSURE(strcmp((const char*)Value, sValue) == 0, "testMerge error 76.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1/MK1SubKey3/KeyWithUnicodeValue"), &valueType, &valueSize), "testMerge error 77");
+ REG_ENSURE(valueType == RegValueType::UNICODE && valueSize == (wValue.getLength()+1)*sizeof(sal_Unicode), "testMerge error 78");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1/MK1SubKey3/KeyWithUnicodeValue"), (RegValue)Value), "testMerge error 78.a)");
+ REG_ENSURE(wValue.equals( (const sal_Unicode*)Value ), "testMerge error 78.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1/MK1SubKey4/KeyWithBinaryValue"), &valueType, &valueSize), "testMerge error 79");
+ REG_ENSURE(valueType == RegValueType::BINARY && valueSize == 27, "testMerge error 80");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1/MK1SubKey4/KeyWithBinaryValue"), (RegValue)Value), "testMerge error 80.a)");
+ REG_ENSURE(strcmp((const char*)Value, "abcdefghijklmnopqrstuvwxyz") == 0, "testMerge error 80.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey2/MK2SubKey1/KeyWithBinaryValue"), &valueType, &valueSize), "testMerge error 81");
+ REG_ENSURE(valueType == RegValueType::BINARY && valueSize == 11, "testMerge error 82");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey2/MK2SubKey1/KeyWithBinaryValue"), (RegValue)Value), "testMerge error 82.a)");
+ REG_ENSURE(strcmp((const char*)Value, "1234567890") == 0, "testMerge error 82.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey2/MK2SubKey2/KeyWithUnicodeValue"), &valueType, &valueSize), "testMerge error 83");
+ REG_ENSURE(valueType == RegValueType::UNICODE&& valueSize == (wValue.getLength()+1)*sizeof(sal_Unicode), "testMerge error 84");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey2/MK2SubKey2/KeyWithUnicodeValue"), (RegValue)Value), "testMerge error 84.a)");
+ REG_ENSURE(wValue.equals( (const sal_Unicode*)Value ), "testMerge error 84.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey2/MK2SubKey3/KeyWithStringValue"), &valueType, &valueSize), "testMerge error 85");
+ REG_ENSURE(valueType == RegValueType::STRING && valueSize == strlen(sValue)+1, "testMerge error 86");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey2/MK2SubKey3/KeyWithStringValue"), (RegValue)Value), "testMerge error 86.a)");
+ REG_ENSURE(strcmp((const char*)Value, sValue) == 0, "testMerge error 86.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey2/MK2SubKey4/KeyWithLongValue"), &valueType, &valueSize), "testMerge error 87");
+ REG_ENSURE(valueType == RegValueType::LONG && valueSize == sizeof(sal_Int32), "testMerge error 88");
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey2/MK2SubKey4/KeyWithLongValue"), (RegValue)&int32Value), "testMerge error 88.a)");
+ REG_ENSURE(int32Value == lValue1, "testMerge error 88.b)");
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1u2/MK1SubKey11/KeyWithLongValue"), &valueType, &valueSize), "testMerge error 89");
+ REG_ENSURE(valueType == RegValueType::LONG && valueSize == sizeof(sal_Int32), "testMerge error 90");
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1u2/MK1SubKey11/KeyWithLongValue"), (RegValue)&int32Value), "testMerge error 90.a)");
+ REG_ENSURE(int32Value == lValue2, "testMerge error 90.b)");
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1u2/MK1SubKey12/KeyWithStringValue"), &valueType, &valueSize), "testMerge error 91");
+ REG_ENSURE(valueType == RegValueType::STRING && valueSize == strlen(sValue)+1, "testMerge error 92");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1u2/MK1SubKey12/KeyWithStringValue"), (RegValue)Value), "testMerge error 92.a)");
+ REG_ENSURE(strcmp((const char*)Value, sValue) == 0, "testMerge error 92.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1u2/MK1SubKey13/KeyWithUnicodeValue"), &valueType, &valueSize), "testMerge error 93");
+ REG_ENSURE(valueType == RegValueType::UNICODE && valueSize == (wValue.getLength()+1)*sizeof(sal_Unicode), "testMerge error 94");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1u2/MK1SubKey13/KeyWithUnicodeValue"), (RegValue)Value), "testMerge error 94.a)");
+ REG_ENSURE(wValue.equals( (const sal_Unicode*)Value ), "testMerge error 94.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1u2/MK2SubKey21/KeyWithBinaryValue"), &valueType, &valueSize), "testMerge error 95");
+ REG_ENSURE(valueType == RegValueType::BINARY && valueSize == 19, "testMerge error 96");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1u2/MK2SubKey21/KeyWithBinaryValue"), (RegValue)Value), "testMerge error 96.a)");
+ REG_ENSURE(strcmp((const char*)Value, "a1b2c3d4e5f6g7h8i9") == 0, "testMerge error 96.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1u2/MK2SubKey22/KeyWithLongValue"), &valueType, &valueSize), "testMerge error 97");
+ REG_ENSURE(valueType == RegValueType::LONG && valueSize == sizeof(sal_Int32), "testMerge error 98");
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1u2/MK2SubKey22/KeyWithLongValue"), (RegValue)&int32Value), "testMerge error 98.a)");
+ REG_ENSURE(int32Value == lValue2, "testMerge error 98.b)");
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1u2/MK2SubKey23/KeyWithStringValue"), &valueType, &valueSize), "testMerge error 99");
+ REG_ENSURE(valueType == RegValueType::STRING && valueSize == strlen(sValue)+1, "testMerge error 100");
+ Value = new sal_uInt8[valueSize];
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1u2/MK2SubKey23/KeyWithStringValue"), (RegValue)Value), "testMerge error 100.a)");
+ REG_ENSURE(strcmp((const char*)Value, sValue) == 0, "testMerge error 100.b)");
+ delete [] Value;
+
+ REG_ENSURE(!key1.getValueInfo(OUString("/MergeKey1u2/MK12SubKey1u2/KeyWithLongValue"), &valueType, &valueSize), "testMerge error 101");
+ REG_ENSURE(valueType == RegValueType::LONG && valueSize == sizeof(sal_Int32), "testMerge error 102");
+ REG_ENSURE(!key1.getValue(OUString("/MergeKey1u2/MK12SubKey1u2/KeyWithLongValue"), (RegValue)&int32Value), "testMerge error 102.a)");
+ REG_ENSURE(int32Value == lValue4, "testMerge error 102.b)");
+
+
+ REG_ENSURE(!key1.closeKey(), "testMerge error 24");
+
+
+ REG_ENSURE(!rootKey.closeKey(), "testMerge error 10");
+
+ REG_ENSURE(!myRegistry->destroy( OUString("merge1.rdb") ), "test_registry_CppApi error 11");
+ REG_ENSURE(!myRegistry->destroy( OUString("merge2.rdb") ), "test_registry_CppApi error 12");
+ REG_ENSURE(!myRegistry->destroy( OUString() ), "test_registry_CppApi error 13");
+
+ delete myRegistry;
+
+ std::cout << "test_merge() Ok!\n";
+ return;
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/test/testregcpp.cxx b/registry/test/testregcpp.cxx
new file mode 100644
index 0000000000..6d545359b6
--- /dev/null
+++ b/registry/test/testregcpp.cxx
@@ -0,0 +1,696 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <iostream>
+#include <stdio.h>
+#include <string.h>
+
+#include "registry/registry.hxx"
+#include "registry/reflread.hxx"
+#include "registry/reflwrit.hxx"
+#include "regdiagnose.h"
+#include <rtl/alloc.h>
+#include <rtl/ustring.hxx>
+
+
+void test_coreReflection()
+{
+ Registry *myRegistry = new Registry();
+
+ RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8;
+
+ REG_ENSURE(!myRegistry->create(OUString("ucrtest.rdb")), "testCoreReflection error 1");
+ REG_ENSURE(!myRegistry->openRootKey(rootKey), "testCoreReflection error 2");
+
+ REG_ENSURE(!rootKey.createKey(OUString("UCR"), key1), "testCoreReflection error 3");
+ REG_ENSURE(!key1.createKey(OUString("ModuleA"), key2), "testCoreReflection error 4");
+ REG_ENSURE(!key2.createKey(OUString("StructA"), key3), "testCoreReflection error 5");
+ REG_ENSURE(!key2.createKey(OUString("EnumA"), key4), "testCoreReflection error 6");
+ REG_ENSURE(!key2.createKey(OUString("XInterfaceA"), key5), "testCoreReflection error 7");
+ REG_ENSURE(!key2.createKey(OUString("ExceptionA"), key6), "testCoreReflection error 8");
+ REG_ENSURE(!key2.createKey(OUString("ServiceA"), key7), "testCoreReflection error 8a");
+ REG_ENSURE(!key2.createKey(OUString("ConstantsA"), key8), "testCoreReflection error 8b");
+
+ {
+ RegistryTypeWriter writer(RT_TYPE_MODULE,
+ OUString("ModuleA"),
+ OUString(), 11, 0, 0);
+
+ RTConstValue aConst;
+
+ writer.setDoku(OUString("Hello I am a module"));
+ writer.setFileName(OUString("DummyFile"));
+
+ aConst.m_type = RT_TYPE_BOOL;
+ aConst.m_value.aBool = sal_True;
+ writer.setFieldData(0, OUString("aConstBool"),
+ OUString("boolean"),
+ OUString("I am a boolean"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_BYTE;
+ aConst.m_value.aByte = 127;
+ writer.setFieldData(1, OUString("aConstByte"),
+ OUString("byte"),
+ OUString("I am a byte"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_INT16;
+ aConst.m_value.aShort = -10;
+ writer.setFieldData(2, OUString("aConstShort"),
+ OUString("short"),
+ OUString("I am a short"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_UINT16;
+ aConst.m_value.aUShort = 10;
+ writer.setFieldData(3, OUString("aConstUShort"),
+ OUString("unsigned short"),
+ OUString("I am an unsigned short"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_INT32;
+ aConst.m_value.aLong = -100000;
+ writer.setFieldData(4, OUString("aConstLong"),
+ OUString("long"),
+ OUString("I am a long"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_UINT32;
+ aConst.m_value.aULong = 100000;
+ writer.setFieldData(5, OUString("aConstULong"),
+ OUString("unsigned long"),
+ OUString("I am an unsigned long"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_INT64;
+ aConst.m_value.aHyper = -100000000;
+ writer.setFieldData(6, OUString("aConstHyper"),
+ OUString("hyper"),
+ OUString("I am an hyper"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_UINT64;
+ aConst.m_value.aUHyper = 100000000;
+ writer.setFieldData(7, OUString("aConstULong"),
+ OUString("unsigned long"),
+ OUString("I am an unsigned long"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_FLOAT;
+ aConst.m_value.aFloat = -2e-10f;
+ writer.setFieldData(8, OUString("aConstFloat"),
+ OUString("float"),
+ OUString("I am a float"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_DOUBLE;
+ aConst.m_value.aDouble = -2e-100; writer.setFieldData(9, OUString("aConstDouble"),
+ OUString("double"),
+ OUString("I am a double"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_STRING;
+ OUString tmpStr("this is a unicode string");
+ aConst.m_value.aString = tmpStr.getStr();
+
+ writer.setFieldData(10, OUString("aConstString"),
+ OUString("string"),
+ OUString("I am a string"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+
+ const sal_uInt8* pBlop = writer.getBlop();
+ sal_uInt32 aBlopSize = writer.getBlopSize();
+
+ REG_ENSURE(!key2.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9");
+
+ sal_uInt8* readBlop = (sal_uInt8*)std::malloc(aBlopSize);
+ REG_ENSURE(!key2.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9a");
+
+ RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
+
+ if (reader.isValid())
+ {
+ REG_ENSURE(reader.getTypeName() == "ModuleA", "testCoreReflection error 9a2");
+
+ RTConstValue aReadConst = reader.getFieldConstValue(4);
+ REG_ENSURE( aReadConst.m_type == RT_TYPE_INT32, "testCoreReflection error 9a3");
+ REG_ENSURE( aReadConst.m_value.aLong == -100000, "testCoreReflection error 9a4");
+
+ aReadConst = reader.getFieldConstValue(6);
+ REG_ENSURE( aReadConst.m_type == RT_TYPE_INT64, "testCoreReflection error 9a5");
+ REG_ENSURE( aReadConst.m_value.aHyper == -100000000, "testCoreReflection error 9a6");
+
+ aReadConst = reader.getFieldConstValue(10);
+ OString aConstStr = OUStringToOString(aConst.m_value.aString, RTL_TEXTENCODING_ASCII_US);
+ REG_ENSURE(aConstStr.equals("this is a unicode string"), "testCoreReflection error 9b");
+ }
+
+ }
+
+ {
+ RegistryTypeWriter writer(RT_TYPE_STRUCT,
+ OUString("ModuleA/StructA"),
+ OUString(), 3, 0, 0);
+
+ writer.setDoku(OUString("Hello I am a structure"));
+ writer.setFileName(OUString("DummyFile"));
+
+ writer.setFieldData(0, OUString("asal_uInt32"),
+ OUString("unsigned long"),
+ OUString(), OUString(), RTFieldAccess::READWRITE);
+ writer.setFieldData(1, OUString("aXInterface"),
+ OUString("stardiv/uno/XInterface"),
+ OUString(), OUString(), RTFieldAccess::READWRITE);
+ writer.setFieldData(2, OUString("aSequence"),
+ OUString("[]ModuleA/EnumA"),
+ OUString(), OUString(), RTFieldAccess::READWRITE);
+
+ const sal_uInt8* pBlop = writer.getBlop();
+ sal_uInt32 aBlopSize = writer.getBlopSize();
+
+ REG_ENSURE(!key3.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9a");
+ }
+
+ {
+ RegistryTypeWriter writer(RT_TYPE_ENUM,
+ OUString("ModuleA/EnumA"),
+ OUString(), 2, 0, 0);
+
+ RTConstValue aConst;
+
+ aConst.m_type = RT_TYPE_UINT32;
+ aConst.m_value.aULong = 10;
+
+ writer.setDoku(OUString("Hello I am an enum"));
+ writer.setFileName(OUString("DummyFile"));
+
+ writer.setFieldData(0, OUString("ENUM_VAL_1"),
+ OUString(), OUString("I am an enum value"),
+ OUString(), RTFieldAccess::CONST, aConst);
+
+ aConst.m_value.aULong = 10;
+ writer.setFieldData(1, OUString("ENUM_VAL_2"),
+ OUString(), OUString(), OUString(), RTFieldAccess::CONST, aConst);
+
+ const sal_uInt8* pBlop = writer.getBlop();
+ sal_uInt32 aBlopSize = writer.getBlopSize();
+
+ REG_ENSURE(!key4.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9b");
+ }
+
+ {
+ RegistryTypeWriter writer(RT_TYPE_INTERFACE,
+ OUString("ModuleA/XInterfaceA"),
+ OUString("stardiv/uno/XInterface"),
+ 4, 1, 0);
+ RTConstValue aConst;
+
+ RTUik aUik = {1,2,3,4,5};
+
+ writer.setUik(aUik);
+ writer.setDoku(OUString("Hello I am an interface"));
+ writer.setFileName(OUString("DummyFile"));
+
+ writer.setFieldData(0, OUString("aString"),
+ OUString("string"), OUString(), OUString(), RTFieldAccess::READWRITE);
+ writer.setFieldData(1, OUString("aStruct"),
+ OUString("ModuleA/StructA"),
+ OUString(), OUString(), RTFieldAccess::READONLY);
+ writer.setFieldData(2, OUString("aEnum"),
+ OUString("ModuleA/EnumA"), OUString(), OUString(), RTFieldAccess::BOUND);
+ aConst.m_type = RT_TYPE_UINT16;
+ aConst.m_value.aUShort = 12;
+ writer.setFieldData(3, OUString("aConstUShort"),
+ OUString("unsigned short"), OUString(),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+
+ writer.setMethodData(0, OUString("methodA"),
+ OUString("double"), RTMethodMode::TWOWAY, 2, 1,
+ OUString("Hello I am the methodA"));
+ writer.setParamData(0, 0, OUString("ModuleA/StructA"),
+ OUString("aStruct"), RT_PARAM_IN);
+ writer.setParamData(0, 1, OUString("unsigned short"),
+ OUString("aShort"), RT_PARAM_INOUT);
+ writer.setExcData(0, 0, OUString("ModuleA/ExceptionA"));
+
+ const sal_uInt8* pBlop = writer.getBlop();
+ sal_uInt32 aBlopSize = writer.getBlopSize();
+
+ REG_ENSURE(!key5.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9c");
+
+ sal_uInt8* readBlop = (sal_uInt8*)std::malloc(aBlopSize);
+ REG_ENSURE(!key5.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9c1");
+
+ RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
+
+ if (reader.isValid())
+ {
+ REG_ENSURE(reader.getTypeName() == "ModuleA/XInterfaceA", "testCoreReflection error 9c2");
+
+ RTUik retUik;
+ reader.getUik(retUik);
+ REG_ENSURE(retUik.m_Data1 = 1, "testCoreReflection error 9c3");
+ REG_ENSURE(retUik.m_Data2 = 2, "testCoreReflection error 9c4");
+ REG_ENSURE(retUik.m_Data3 = 3, "testCoreReflection error 9c5");
+ REG_ENSURE(retUik.m_Data4 = 4, "testCoreReflection error 9c6");
+ REG_ENSURE(retUik.m_Data5 = 5, "testCoreReflection error 9c7");
+ }
+
+ }
+
+ {
+ RegistryTypeWriter writer(RT_TYPE_EXCEPTION,
+ OUString("ModuleA/ExceptionA"),
+ OUString(), 1, 0, 0);
+
+ writer.setDoku(OUString("Hello I am an exception"));
+
+ writer.setFieldData(0, OUString("aSource"),
+ OUString("stardiv/uno/XInterface"),
+ OUString("I am an interface member"),
+ OUString(), RTFieldAccess::READWRITE);
+
+ const sal_uInt8* pBlop = writer.getBlop();
+ sal_uInt32 aBlopSize = writer.getBlopSize();
+
+ REG_ENSURE(!key6.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9d");
+ }
+
+ {
+ RegistryTypeWriter writer(RT_TYPE_SERVICE,
+ OUString("ModuleA/ServiceA"),
+ OUString(), 1, 0, 4);
+
+ writer.setDoku(OUString("Hello I am a service"));
+ writer.setFileName(OUString("DummyFile"));
+
+ writer.setFieldData(0, OUString("aProperty"),
+ OUString("stardiv/uno/XInterface"),
+ OUString("I am a property"),
+ OUString(), RTFieldAccess::READWRITE);
+
+ writer.setReferenceData(0, OUString("ModuleA/XInterfaceA"), RTReferenceType::SUPPORTS,
+ OUString("Hello I am a reference to a supported interface"),
+ RTFieldAccess::OPTIONAL);
+ writer.setReferenceData(1, OUString("ModuleA/XInterfaceA"), RTReferenceType::OBSERVES,
+ OUString("Hello I am a reference to an observed interface"));
+ writer.setReferenceData(2, OUString("ModuleA/ServiceB"), RTReferenceType::EXPORTS,
+ OUString("Hello I am a reference to an exported service"));
+ writer.setReferenceData(3, OUString("ModuleA/ServiceB"), RTReferenceType::NEEDS,
+ OUString("Hello I am a reference to a needed service"));
+
+ const sal_uInt8* pBlop = writer.getBlop();
+ sal_uInt32 aBlopSize = writer.getBlopSize();
+
+ REG_ENSURE(!key7.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9e");
+ sal_uInt8* readBlop = (sal_uInt8*)std::malloc(aBlopSize);
+ REG_ENSURE(!key7.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9e2");
+
+ RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
+
+ if (reader.isValid())
+ {
+ REG_ENSURE(reader.getTypeName() == "ModuleA/ServiceA", "testCoreReflection error 9e3");
+
+ sal_uInt32 referenceCount = reader.getReferenceCount();
+ REG_ENSURE( referenceCount == 4, "testCoreReflection error 9e4");
+
+ OUString refName = reader.getReferenceName(0);
+ REG_ENSURE(refName == "ModuleA/XInterfaceA", "testCoreReflection error 9e5");
+ }
+ }
+
+ {
+ RegistryTypeWriter writer(RT_TYPE_CONSTANTS,
+ OUString("ModuleA/ConstansA"),
+ OUString(), 3, 0, 0);
+
+ RTConstValue aConst;
+
+ writer.setDoku(OUString("Hello I am a constants group"));
+ writer.setFileName(OUString("DummyFile"));
+
+ aConst.m_type = RT_TYPE_BOOL;
+ aConst.m_value.aBool = sal_True;
+ writer.setFieldData(0, OUString("ConstantsA_aConstBool"),
+ OUString("boolean"),
+ OUString("I am a boolean"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_BYTE;
+ aConst.m_value.aByte = 127;
+ writer.setFieldData(1, OUString("ConstantsA_aConstByte"),
+ OUString("byte"),
+ OUString("I am a byte"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+ aConst.m_type = RT_TYPE_INT16;
+ aConst.m_value.aShort = -10;
+ writer.setFieldData(2, OUString("ConstantsA_aConstShort"),
+ OUString("short"),
+ OUString("I am a short"),
+ OUString("DummyFile"), RTFieldAccess::CONST, aConst);
+
+ const sal_uInt8* pBlop = writer.getBlop();
+ sal_uInt32 aBlopSize = writer.getBlopSize();
+
+ REG_ENSURE(!key8.setValue(OUString(), RegValueType::BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9f");
+ }
+
+// REG_ENSURE(!myRegistry->destroy(NULL), "testCoreReflection error 10");
+ delete myRegistry;
+
+ std::cout << "test_coreReflection() Ok!\n";
+}
+
+void test_registry_CppApi()
+{
+ Registry *myRegistry = new Registry();
+
+ RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8, key9;
+
+ REG_ENSURE(!myRegistry->create(OUString("test.rdb")), "test_registry_CppApi error 1");
+ REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 2");
+
+ REG_ENSURE(!rootKey.createKey(OUString("myFirstKey"), key1), "test_registry_CppApi error 3");
+ REG_ENSURE(!rootKey.createKey(OUString("mySecondKey"), key2), "test_registry_CppApi error 4");
+ REG_ENSURE(!key1.createKey(OUString("X"), key3), "test_registry_CppApi error 5");
+ REG_ENSURE(!key1.createKey(OUString("mySecondSubKey"), key4), "test_registry_CppApi error 6");
+ REG_ENSURE(!rootKey.createKey(OUString("myThirdKey"), key5), "test_registry_CppApi error 6a");
+
+ REG_ENSURE(!key5.createKey(OUString("1"), key4), "test_registry_CppApi error 6b");
+ REG_ENSURE(!key4.createKey(OUString("2"), key3), "test_registry_CppApi error 6c");
+ REG_ENSURE(!key5.openKey("1", key4), "test_registry_CppApi error 6d");
+ REG_ENSURE(!rootKey.openKey("/myThirdKey/1", key4), "test_registry_CppApi error 6e");
+ REG_ENSURE(key4.getName() == "/myThirdKey/1", "test_registry_CppApi error 6f");
+
+ REG_ENSURE(!rootKey.createKey(OUString("myFourthKey"), key6), "test_registry_CppApi error 7");
+ REG_ENSURE(!rootKey.createKey(OUString("myFifthKey"), key6), "test_registry_CppApi error 7a");
+ REG_ENSURE(!rootKey.createKey(OUString("mySixthKey"), key6), "test_registry_CppApi error 7b");
+
+ // Link Test
+
+
+ REG_ENSURE(!rootKey.createKey(OUString("/myFourthKey/X"), key7), "test_registry_CppApi error 7c)");
+ REG_ENSURE(!key6.createLink(OUString("myFirstLink"), OUString("/myFourthKey/X")), "test_registry_CppApi error 7d");
+ REG_ENSURE(!key6.createKey(OUString("mySixthSubKey"), key7), "test_registry_CppApi error 7e");
+
+ OUString linkTarget;
+ REG_ENSURE(!key6.getLinkTarget(OUString("myFirstLink"), linkTarget), "test_registry_CppApi error 7f");
+ REG_ENSURE(linkTarget == "/myFourthKey/X", "test_registry_CppApi error 7g");
+
+ RegistryKeyNames* pSubKeyNames = new RegistryKeyNames();
+ sal_uInt32 nSubKeys=0;
+
+ REG_ENSURE(!rootKey.getKeyNames(OUString("mySixthKey"), *pSubKeyNames), "test_registry_CppApi error 7h)");
+ REG_ENSURE(pSubKeyNames->getLength() == 2, "test_registry_CppApi error 7i)");
+
+ for (sal_uInt32 i=0; i < pSubKeyNames->getLength(); i++)
+ {
+ if ( pSubKeyNames->getElement(i) == "/mySixthKey/myFirstLink" )
+ {
+ RegKeyType keyType;
+ REG_ENSURE(!rootKey.getKeyType(pSubKeyNames->getElement(i), &keyType), "test_registry_CppApi error 7j");
+ REG_ENSURE(keyType == RG_LINKTYPE, "test_registry_CppApi error 7k");
+ }
+ }
+
+ REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7k1");
+ delete pSubKeyNames;
+
+ REG_ENSURE(!rootKey.openKey("/mySixthKey/myFirstLink", key6), "test_registry_CppApi error 7l");
+// REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m");
+
+ REG_ENSURE(!rootKey.openKey("myFifthKey", key6), "test_registry_CppApi error 7m1");
+ REG_ENSURE(!key6.createLink(OUString("mySecondLink"),
+ OUString("/mySixthKey/myFirstLink")), "test_registry_CppApi error 7m2");
+
+ REG_ENSURE(!rootKey.openKey("/myFifthKey/mySecondLink", key6), "test_registry_CppApi error 7m3");
+// REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m4");
+
+ REG_ENSURE(!rootKey.createKey(OUString("/myFifthKey/mySecondLink/myFirstLinkSubKey"), key7), "test_registry_CppApi error 7m5");
+ REG_ENSURE(key7.getName() == "/myFourthKey/X/myFirstLinkSubKey", "test_registry_CppApi error 7m6");
+
+ REG_ENSURE(!key7.createLink(OUString("myThirdLink"), OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m7");
+ REG_ENSURE(!rootKey.openKey("/myFourthKey/X/myFirstLinkSubKey/myThirdLink", key7), "test_registry_CppApi error 7m8");
+// REG_ENSURE(!key7.openKey("/myFirstLinkSubKey/myThirdLink/myFirstLinkSubKey/myThirdLink", key6), "test_registry_CppApi error 7m9");
+// REG_ENSURE(key7.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m10");
+ REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7m11");
+
+ REG_ENSURE(!rootKey.deleteLink(OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m12");
+
+ REG_ENSURE(!rootKey.createLink(OUString("/myFifthKey/mySecondLink"),
+ OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink")),
+ "test_registry_CppApi error 7m13");
+
+// REG_ENSURE(rootKey.openKey("/myFourthKey/X/myFirstLinkSubKey/myThirdLink", key7) == REG_DETECT_RECURSION,
+// "test_registry_CppApi error 7m14");
+
+// REG_ENSURE(key7.closeKey() == REG_INVALID_KEY, "test_registry_CppApi error 7m11");
+
+ RegistryKeyNames subKeyNames;
+ nSubKeys=0;
+
+ REG_ENSURE(!rootKey.getKeyNames(OUString("mySixthKey"), subKeyNames), "test_registry_CppApi error 7n");
+
+ nSubKeys = subKeyNames.getLength();
+ REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7n1");
+ REG_ENSURE(subKeyNames.getElement(0) == "/mySixthKey/myFirstLink", "test_registry_CppApi error 7p1)");
+ REG_ENSURE(subKeyNames.getElement(1) =="/mySixthKey/mySixthSubKey", "test_registry_CppApi error 7p2");
+
+
+ RegistryKeyArray subKeys;
+ nSubKeys=0;
+
+ REG_ENSURE(!rootKey.openSubKeys(OUString("myFirstKey"), subKeys), "test_registry_CppApi error 7o");
+
+ nSubKeys = subKeys.getLength();
+ REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7o1");
+ REG_ENSURE(subKeys.getElement(0).getName() == "/myFirstKey/mySecondSubKey", "test_registry_CppApi error 7p1)");
+ REG_ENSURE(subKeys.getElement(1).getName() == "/myFirstKey/X", "test_registry_CppApi error 7p2");
+
+ REG_ENSURE(!rootKey.closeSubKeys(subKeys), "test_registry_CppApi error 7q)");
+
+
+ REG_ENSURE(!rootKey.createKey(OUString("/TEST"), key8), "test_registry_CppApi error 8");
+ REG_ENSURE(!rootKey.createKey(OUString("/TEST/Child1"), key8), "test_registry_CppApi error 8a");
+ REG_ENSURE(!rootKey.createKey(OUString("/TEST/Child2"), key8), "test_registry_CppApi error 8a1");
+ REG_ENSURE(!rootKey.openKey("/TEST", key9), "test_registry_CppApi error 8b");
+ REG_ENSURE(!key8.closeKey() && !key9.closeKey(), "test_registry_CppApi error 8b1");
+ REG_ENSURE(!rootKey.openKey("/TEST", key8), "test_registry_CppApi error 8b");
+ REG_ENSURE(!key8.closeKey(), "test_registry_CppApi error 8c");
+ REG_ENSURE(!rootKey.openKey("TEST", key8), "test_registry_CppApi error 8c");
+ REG_ENSURE(!key8.closeKey(), "test_registry_CppApi error 8d");
+
+
+ char* Value=(char*)"My first value";
+ REG_ENSURE(!rootKey.setValue(OUString("mySecondKey"), RegValueType::STRING, Value, 18), "test_registry_CppApi error 9");
+
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+ char* readValue;
+ REG_ENSURE(!rootKey.getValueInfo(OUString("mySecondKey"), &valueType, &valueSize), "test_registry_CppApi error 9a");
+
+ readValue = (char*)std::malloc(valueSize);
+ REG_ENSURE(!key2.getValue(OUString(), readValue), "test_registry_CppApi error 10");
+
+ REG_ENSURE(valueType == RegValueType::STRING, "test_registry_CppApi error 11");
+ REG_ENSURE(valueSize == 18, "test_registry_CppApi error 12");
+ REG_ENSURE(strcmp(readValue, Value) == 0, "test_registry_CppApi error 13");
+ std::free(readValue);
+
+ const char* pList[3];
+ const char* n1= "Hello";
+ const char* n2= "now I";
+ const char* n3= "come";
+
+ pList[0]=n1;
+ pList[1]=n2;
+ pList[2]=n3;
+
+ REG_ENSURE(!rootKey.setStringListValue(OUString("myFourthKey"), (char**)pList, 3), "test_registry_CppApi error 13a");
+
+ RegistryValueList<char*> valueList;
+ REG_ENSURE(!rootKey.getStringListValue(OUString("myFourthKey"), valueList), "test_registry_CppApi error 13b");
+
+ REG_ENSURE(strcmp(n1, valueList.getElement(0)) == 0, "test_registry_CppApi error 13c");
+ REG_ENSURE(strcmp(n2, valueList.getElement(1)) == 0, "test_registry_CppApi error 13d");
+ REG_ENSURE(strcmp(n3, valueList.getElement(2)) == 0, "test_registry_CppApi error 13e");
+
+ REG_ENSURE(!rootKey.getValueInfo(OUString("myFourthKey"), &valueType, &valueSize), "test_registry_CppApi error 13e1");
+ REG_ENSURE(valueType == RegValueType::STRINGLIST, "test_registry_CppApi error 13e2");
+ REG_ENSURE(valueSize == 3, "test_registry_CppApi error 13e3");
+
+ sal_Int32 pLong[3];
+ pLong[0] = 123;
+ pLong[1] = 456;
+ pLong[2] = 789;
+
+ REG_ENSURE(!rootKey.setLongListValue(OUString("myFifthKey"), pLong, 3), "test_registry_CppApi error 13f");
+
+ RegistryValueList<sal_Int32> longList;
+ REG_ENSURE(!rootKey.getLongListValue(OUString("myFifthKey"), longList), "test_registry_CppApi error 13g");
+
+ REG_ENSURE(pLong[0] == longList.getElement(0), "test_registry_CppApi error 13h");
+ REG_ENSURE(pLong[1] == longList.getElement(1), "test_registry_CppApi error 13i");
+ REG_ENSURE(pLong[2] == longList.getElement(2), "test_registry_CppApi error 13j");
+
+
+ OUString sWTestValue("My first unicode value");
+ const sal_Unicode* wTestValue= sWTestValue.getStr();
+ REG_ENSURE(!rootKey.setValue(OUString("mySixthKey"), RegValueType::UNICODE, (void*)wTestValue,
+ (rtl_ustr_getLength(wTestValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 13j1");
+
+ REG_ENSURE(!rootKey.getValueInfo(OUString("mySixthKey"), &valueType, &valueSize), "test_registry_CppApi error 13j2");
+ sal_Unicode* pTmpValue = (sal_Unicode*)std::malloc(valueSize);
+ REG_ENSURE(!rootKey.getValue(OUString("mySixthKey"), pTmpValue), "test_registry_CppApi error 13j3");
+ REG_ENSURE(rtl_ustr_getLength(wTestValue) == rtl_ustr_getLength(pTmpValue), "test_registry_CppApi error 13j4");
+ REG_ENSURE(rtl_ustr_compare(wTestValue, pTmpValue) == 0, "test_registry_CppApi error 13j4");
+
+ const sal_Unicode* pUnicode[3];
+ OUString w1("Hello");
+ OUString w2("now I");
+ OUString w3("come as unicode");
+
+ pUnicode[0]=w1.getStr();
+ pUnicode[1]=w2.getStr();
+ pUnicode[2]=w3.getStr();
+
+ REG_ENSURE(!rootKey.setUnicodeListValue(OUString("mySixthKey"), (sal_Unicode**)pUnicode, 3), "test_registry_CppApi error 13k");
+
+ RegistryValueList<sal_Unicode*> unicodeList;
+ REG_ENSURE(!rootKey.getUnicodeListValue(OUString("mySixthKey"), unicodeList), "test_registry_CppApi error 13l");
+
+ REG_ENSURE(rtl_ustr_compare(w1, unicodeList.getElement(0)) == 0, "test_registry_CppApi error 13m");
+ REG_ENSURE(rtl_ustr_compare(w2, unicodeList.getElement(1)) == 0, "test_registry_CppApi error 13n");
+ REG_ENSURE(rtl_ustr_compare(w3, unicodeList.getElement(2)) == 0, "test_registry_CppApi error 13o");
+
+ REG_ENSURE(!key6.closeKey(), "test_registry_CppApi error 14");
+
+ REG_ENSURE(!key1.closeKey() &&
+ !key3.closeKey() &&
+ !key4.closeKey(), "test_registry_CppApi error 14");
+
+ REG_ENSURE(!rootKey.deleteKey(OUString("myFirstKey")), "test_registry_CppApi error 15");
+
+ REG_ENSURE(!key2.closeKey(), "test_registry_CppApi error 16");
+ REG_ENSURE(!rootKey.openKey("mySecondKey", key2), "test_registry_CppApi error 17");
+
+ REG_ENSURE(!key5.closeKey(), "test_registry_CppApi error 18");
+
+ REG_ENSURE(!rootKey.deleteKey(OUString("myThirdKey")), "test_registry_CppApi error 19");
+
+ REG_ENSURE(rootKey.openKey("myThirdKey", key5), "test_registry_CppApi error 20");
+
+ REG_ENSURE(!key2.closeKey() &&
+ !rootKey.closeKey(), "test_registry_CppApi error 21");
+
+ REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 22");
+
+ // Test loadkey
+ RegistryKey rootKey2, key21, key22, key23, key24 , key25;
+
+ REG_ENSURE(!myRegistry->create(OUString("test2.rdb")), "test_registry_CppApi error 23");
+ REG_ENSURE(!myRegistry->openRootKey(rootKey2), "test_registry_CppApi error 24");
+
+ REG_ENSURE(!rootKey2.createKey(OUString("reg2FirstKey"), key21), "test_registry_CppApi error 25");
+ REG_ENSURE(!rootKey2.createKey(OUString("reg2SecondKey"), key22), "test_registry_CppApi error 26");
+ REG_ENSURE(!key21.createKey(OUString("reg2FirstSubKey"), key23), "test_registry_CppApi error 27");
+ REG_ENSURE(!key21.createKey(OUString("reg2SecondSubKey"), key24), "test_registry_CppApi error 28");
+ REG_ENSURE(!rootKey2.createKey(OUString("reg2ThirdKey"), key25), "test_registry_CppApi error 29");
+
+ sal_uInt32 nValue= 123456789;
+ REG_ENSURE(!key23.setValue(OUString(), RegValueType::LONG, &nValue, sizeof(sal_uInt32)), "test_registry_CppApi error 30");
+
+ REG_ENSURE(!key21.closeKey() &&
+ !key22.closeKey() &&
+ !key23.closeKey() &&
+ !key24.closeKey() &&
+ !key25.closeKey() &&
+ !rootKey2.closeKey(), "test_registry_CppApi error 31");
+
+ REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 32");
+
+ REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 33");
+ REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 34");
+
+ REG_ENSURE(!myRegistry->loadKey(rootKey, OUString("allFromTest2"),
+ OUString("test2.rdb")), "test_registry_CppApi error 35");
+ REG_ENSURE(!myRegistry->saveKey(rootKey, OUString("allFromTest2"),
+ OUString("test3.rdb")), "test_registry_CppApi error 36");
+
+ REG_ENSURE(!rootKey.createKey(OUString("allFromTest3"), key1), "test_registry_CppApi error 37");
+ REG_ENSURE(!key1.createKey(OUString("myFirstKey2"), key2), "test_registry_CppApi error 38");
+ REG_ENSURE(!key1.createKey(OUString("mySecondKey2"), key3), "test_registry_CppApi error 39");
+
+ REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
+ OUString("test3.rdb")), "test_registry_CppApi error 40");
+ REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
+ OUString("ucrtest.rdb"), sal_True), "test_registry_CppApi error 40.a)");
+
+// REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"), OUString("ucrtest.rdb"), sal_True)
+// == REG_NO_ERROR/*REG_MERGE_CONFLICT*/, "test_registry_CppApi error 40.b)");
+
+ REG_ENSURE(!key1.closeKey() &&
+ !key2.closeKey(), "test_registry_CppApi error 41");
+
+ const sal_Unicode* wValue= OUString("My first unicode value").getStr();
+ REG_ENSURE(!key3.setValue(OUString(), RegValueType::UNICODE, (void*)wValue,
+ (rtl_ustr_getLength(wValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 42");
+
+ REG_ENSURE(!key3.closeKey(), "test_registry_CppApi error 43");
+
+ REG_ENSURE(!rootKey.openKey("/allFromTest3/reg2FirstKey/reg2FirstSubKey", key1),
+ "test_registry_CppApi error 43.a)");
+ REG_ENSURE(!rootKey.deleteKey(OUString("/allFromTest3/reg2FirstKey/reg2FirstSubKey")), "test_registry_CppApi error 44");
+ REG_ENSURE(key1.getValueInfo(OUString(), &valueType, &valueSize) == REG_INVALID_KEY,
+ "test_registry_CppApi error 44.a)");
+ REG_ENSURE(!key1.closeKey(), "test_registry_CppApi error 44.b)");
+
+ REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 45");
+
+ REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 46");
+
+ REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 47");
+
+ REG_ENSURE(!myRegistry->destroy(OUString("test2.rdb")), "test_registry_CppApi error 48");
+// REG_ENSURE(!myRegistry->destroy("test3.rdb"), "test_registry_CppApi error 49");
+
+ Registry *myRegistry2 = new Registry(*myRegistry);
+
+ REG_ENSURE(myRegistry->destroy(OUString()), "test_registry_CppApi error 50");
+
+ delete(myRegistry2);
+
+ REG_ENSURE(!myRegistry->create(OUString("destroytest.rdb")), "test_registry_CppApi error 51");
+ REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 52");
+ REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), RegAccessMode::READONLY), "test_registry_CppApi error 53");
+ REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 54");
+
+ REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
+ OUString("test3.rdb")), "test_registry_CppApi error 55");
+ REG_ENSURE(!myRegistry->destroy(OUString("test3.rdb")), "test_registry_CppApi error 56");
+
+ REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 57");
+ REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 58");
+ REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 59");
+ REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 60");
+
+ REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 61");
+ REG_ENSURE(!myRegistry->destroy(OUString("ucrtest.rdb")), "test_registry_CppApi error 62");
+ REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 63");
+ delete(myRegistry);
+
+ std::cout << "test_registry_CppApi() Ok!\n";
+
+ return;
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/tools/fileurl.cxx b/registry/tools/fileurl.cxx
new file mode 100644
index 0000000000..ce99be5a19
--- /dev/null
+++ b/registry/tools/fileurl.cxx
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "fileurl.hxx"
+
+#include <rtl/ustring.hxx>
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <osl/thread.h>
+
+#include <string.h>
+
+#ifdef SAL_UNX
+#define SEPARATOR '/'
+#else
+#define SEPARATOR '\\'
+#endif
+
+using osl::FileBase;
+
+namespace registry::tools
+{
+OUString convertToFileUrl(char const* filename, sal_Int32 length)
+{
+ OUString const uFileName(filename, length, osl_getThreadTextEncoding());
+ if (strncmp(filename, "file://", 7) == 0)
+ {
+ // already a FileUrl.
+ return uFileName;
+ }
+
+ OUString uFileUrl;
+ if (length <= 0)
+ return uFileUrl;
+ if (filename[0] != SEPARATOR)
+ {
+ // relative path name.
+ OUString uWorkingDir;
+ if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
+ {
+ assert(false);
+ }
+ if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uFileUrl) != FileBase::E_None)
+ {
+ assert(false);
+ }
+ }
+ else
+ {
+ // absolute path name.
+ if (FileBase::getFileURLFromSystemPath(uFileName, uFileUrl) != FileBase::E_None)
+ {
+ assert(false);
+ }
+ }
+ return uFileUrl;
+}
+
+} // namespace registry::tools
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/tools/fileurl.hxx b/registry/tools/fileurl.hxx
new file mode 100644
index 0000000000..c09c7ff6a9
--- /dev/null
+++ b/registry/tools/fileurl.hxx
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_REGISTRY_TOOLS_FILEURL_HXX
+#define INCLUDED_REGISTRY_TOOLS_FILEURL_HXX
+
+#include <rtl/ustring.hxx>
+
+namespace registry::tools
+{
+OUString convertToFileUrl(char const* filename, sal_Int32 length);
+
+} // namespace registry::tools
+
+#endif /* INCLUDED_REGISTRY_TOOLS_FILEURL_HXX */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/tools/regview.cxx b/registry/tools/regview.cxx
new file mode 100644
index 0000000000..56aa343f42
--- /dev/null
+++ b/registry/tools/regview.cxx
@@ -0,0 +1,113 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <regapi.hxx>
+#include "fileurl.hxx"
+
+#include <rtl/ustring.hxx>
+
+#include <stdio.h>
+#include <string.h>
+
+using namespace registry::tools;
+
+#if (defined UNX)
+int main( int argc, char * argv[] )
+#else
+int __cdecl main( int argc, char * argv[] )
+#endif
+{
+ try
+ {
+ RegHandle hReg;
+ RegKeyHandle hRootKey, hKey;
+
+ if (argc < 2 || argc > 3)
+ {
+ fprintf(stderr, "using: regview registryfile [keyName]\n");
+ exit(1);
+ }
+
+ OUString regName( convertToFileUrl(argv[1], strlen(argv[1])) );
+ if (reg_openRegistry(regName.pData, &hReg) != RegError::NO_ERROR)
+ {
+ fprintf(stderr, "open registry \"%s\" failed\n", argv[1]);
+ exit(1);
+ }
+
+ if (reg_openRootKey(hReg, &hRootKey) == RegError::NO_ERROR)
+ {
+ if (argc == 3)
+ {
+ OUString keyName( OUString::createFromAscii(argv[2]) );
+ if (reg_openKey(hRootKey, keyName.pData, &hKey) == RegError::NO_ERROR)
+ {
+ if (reg_dumpRegistry(hKey) != RegError::NO_ERROR)
+ {
+ fprintf(stderr, "dumping registry \"%s\" failed\n", argv[1]);
+ }
+
+ if (reg_closeKey(hKey) != RegError::NO_ERROR)
+ {
+ fprintf(stderr, "closing key \"%s\" of registry \"%s\" failed\n",
+ argv[2], argv[1]);
+ }
+ }
+ else
+ {
+ fprintf(stderr, "key \"%s\" not exists in registry \"%s\"\n",
+ argv[2], argv[1]);
+ }
+ }
+ else
+ {
+ if (reg_dumpRegistry(hRootKey) != RegError::NO_ERROR)
+ {
+ fprintf(stderr, "dumping registry \"%s\" failed\n", argv[1]);
+ }
+ }
+
+ if (reg_closeKey(hRootKey) != RegError::NO_ERROR)
+ {
+ fprintf(stderr, "closing root key of registry \"%s\" failed\n", argv[1]);
+ }
+ }
+ else
+ {
+ fprintf(stderr, "open root key of registry \"%s\" failed\n", argv[1]);
+ }
+
+ if (reg_closeRegistry(hReg) != RegError::NO_ERROR)
+ {
+ fprintf(stderr, "closing registry \"%s\" failed\n", argv[1]);
+ exit(1);
+ }
+
+ return 0;
+ }
+ catch (std::exception& e)
+ {
+ fprintf(stderr, "failure: \"%s\"\n", e.what());
+ return 1;
+ }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */