summaryrefslogtreecommitdiffstats
path: root/registry
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /registry
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'registry')
-rw-r--r--registry/CustomTarget_regcompare_test.mk213
-rw-r--r--registry/Executable_regmerge.mk29
-rw-r--r--registry/Executable_regview.mk34
-rw-r--r--registry/IwyuFilter_registry.yaml16
-rw-r--r--registry/Library_reg.mk37
-rw-r--r--registry/Makefile14
-rw-r--r--registry/Module_registry.mk34
-rw-r--r--registry/README15
-rw-r--r--registry/StaticLibrary_registry_helper.mk18
-rw-r--r--registry/inc/regapi.hxx90
-rw-r--r--registry/source/keyimpl.cxx990
-rw-r--r--registry/source/keyimpl.hxx136
-rw-r--r--registry/source/reflcnst.hxx229
-rw-r--r--registry/source/reflread.cxx1760
-rw-r--r--registry/source/reflread.hxx114
-rw-r--r--registry/source/reflwrit.cxx1335
-rw-r--r--registry/source/reflwrit.hxx103
-rw-r--r--registry/source/regimpl.cxx1576
-rw-r--r--registry/source/regimpl.hxx153
-rw-r--r--registry/source/registry.cxx397
-rw-r--r--registry/source/regkey.cxx694
-rw-r--r--registry/source/regkey.hxx69
-rw-r--r--registry/test/makefile.mk81
-rw-r--r--registry/test/regcompare/other1.idl1
-rw-r--r--registry/test/regcompare/other2.idl1
-rw-r--r--registry/test/regcompare/pe.idl1
-rw-r--r--registry/test/regcompare/psa.idl1
-rw-r--r--registry/test/regcompare/psb.idl1
-rw-r--r--registry/test/regcompare/ue.idl1
-rw-r--r--registry/test/regcompare/usa.idl1
-rw-r--r--registry/test/regcompare/usb.idl1
-rw-r--r--registry/test/regdiagnose.h38
-rw-r--r--registry/test/testmerge.cxx408
-rw-r--r--registry/test/testregcpp.cxx698
-rw-r--r--registry/tools/fileurl.cxx79
-rw-r--r--registry/tools/fileurl.hxx37
-rw-r--r--registry/tools/options.cxx144
-rw-r--r--registry/tools/options.hxx60
-rw-r--r--registry/tools/regmerge.cxx183
-rw-r--r--registry/tools/regview.cxx113
40 files changed, 9905 insertions, 0 deletions
diff --git a/registry/CustomTarget_regcompare_test.mk b/registry/CustomTarget_regcompare_test.mk
new file mode 100644
index 000000000..e7816301f
--- /dev/null
+++ b/registry/CustomTarget_regcompare_test.mk
@@ -0,0 +1,213 @@
+# -*- 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/.
+#
+# 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 .
+#
+
+$(eval $(call gb_CustomTarget_CustomTarget,registry/regcompare_test))
+
+.PHONY: $(call gb_CustomTarget_get_target,registry/regcompare_test)
+
+$(call gb_CustomTarget_get_target,registry/regcompare_test): \
+ $(call gb_Executable_get_runtime_dependencies,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other1.rdb \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other2.rdb \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/pe.rdb \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psb.rdb \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/ue.rdb \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usb.rdb
+ifneq ($(gb_SUPPRESS_TESTS),)
+ @true
+else
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psb.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usb.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/pe.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/ue.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other1.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other2.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psb.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usb.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/pe.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/ue.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other1.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other2.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psb.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usb.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/pe.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/ue.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other1.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) --ignore-unpublished \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other2.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psa.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/psb.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usb.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/pe.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/ue.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other1.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+ $(call gb_Helper_abbreviate_dirs,( \
+ ! $(call gb_Executable_get_command,unoidl-check) \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/usa.rdb \
+ -- $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/other2.rdb) \
+ > $@.log 2>&1 || (cat $@.log && false))
+endif
+
+$(call gb_CustomTarget_get_workdir,registry/regcompare_test)/%.rdb: \
+ $(call gb_CustomTarget_get_workdir,registry/regcompare_test)/%.urd \
+ $(call gb_Executable_get_runtime_dependencies,regmerge)
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,regmerge) $@ /UCR $<))
+
+$(call gb_CustomTarget_get_workdir,registry/regcompare_test)/%.urd: \
+ $(SRCDIR)/registry/test/regcompare/%.idl \
+ $(call gb_Executable_get_runtime_dependencies,idlc)
+ $(call gb_Helper_abbreviate_dirs,( \
+ $(call gb_Executable_get_command,idlc) \
+ -O$(call gb_CustomTarget_get_workdir,registry/regcompare_test) \
+ -cid -we $<))
+
+# vim: set noet sw=4 ts=4:
diff --git a/registry/Executable_regmerge.mk b/registry/Executable_regmerge.mk
new file mode 100644
index 000000000..a55acf885
--- /dev/null
+++ b/registry/Executable_regmerge.mk
@@ -0,0 +1,29 @@
+# -*- 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,regmerge))
+
+$(eval $(call gb_Executable_use_libraries,regmerge,\
+ reg \
+ $(if $(filter TRUE,$(DISABLE_DYNLOADING)),store) \
+ $(if $(filter TRUE,$(DISABLE_DYNLOADING)),salhelper) \
+ sal \
+))
+
+$(eval $(call gb_Executable_use_static_libraries,regmerge,\
+ registry_helper \
+))
+
+$(eval $(call gb_Executable_add_exception_objects,regmerge,\
+ registry/tools/regmerge \
+))
+
+$(eval $(call gb_Executable_add_default_nativeres,regmerge))
+
+# vim:set noet sw=4 ts=4:
diff --git a/registry/Executable_regview.mk b/registry/Executable_regview.mk
new file mode 100644
index 000000000..9ff105236
--- /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 000000000..d7d93bdc6
--- /dev/null
+++ b/registry/IwyuFilter_registry.yaml
@@ -0,0 +1,16 @@
+---
+assumeFilename: registry/source/registry.cxx
+blacklist:
+ registry/source/regimpl.hxx:
+ # Needed for correct linker visibility
+ - regapi.hxx
+ registry/source/reflwrit.cxx:
+ # OSL_BIGENDIAN is being checked
+ - osl/endian.h
+ # Needed for correct linker visibility
+ - registry/writer.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 000000000..d17b11969
--- /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 000000000..0997e6284
--- /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 000000000..90f783367
--- /dev/null
+++ b/registry/Module_registry.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_Module_Module,registry))
+
+$(eval $(call gb_Module_add_targets,registry,\
+ Library_reg \
+ $(if $(filter-out $(OS),iOS), \
+ $(if $(ENABLE_MACOSX_SANDBOX),, \
+ Executable_regmerge \
+ Executable_regview \
+ ) \
+ StaticLibrary_registry_helper \
+ ) \
+))
+
+ifneq ($(OS),iOS) # missing regmerge (see above), needed within test
+
+ifeq ($(ENABLE_MACOSX_SANDBOX),) # ditto
+
+$(eval $(call gb_Module_add_check_targets,registry, \
+ CustomTarget_regcompare_test \
+))
+
+endif
+endif
+
+# vim:set noet sw=4 ts=4:
diff --git a/registry/README b/registry/README
new file mode 100644
index 000000000..914db30a2
--- /dev/null
+++ b/registry/README
@@ -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 000000000..a0c11428e
--- /dev/null
+++ b/registry/StaticLibrary_registry_helper.mk
@@ -0,0 +1,18 @@
+# -*- 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 \
+ registry/tools/options \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/registry/inc/regapi.hxx b/registry/inc/regapi.hxx
new file mode 100644
index 000000000..ae5b7e119
--- /dev/null
+++ b/registry/inc/regapi.hxx
@@ -0,0 +1,90 @@
+/* -*- 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_INC_REGAPI_HXX
+#define INCLUDED_REGISTRY_INC_REGAPI_HXX
+
+#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);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/keyimpl.cxx b/registry/source/keyimpl.cxx
new file mode 100644
index 000000000..e14a88ec2
--- /dev/null
+++ b/registry/source/keyimpl.cxx
@@ -0,0 +1,990 @@
+/* -*- 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>
+
+using namespace store;
+
+namespace { static char const VALUE_PREFIX[] = "$VL_"; }
+
+
+// ORegKey()
+
+ORegKey::ORegKey(const OUString& keyName, ORegistry* pReg)
+ : m_refCount(1)
+ , m_name(keyName)
+ , m_bDeleted(false)
+ , m_bModified(false)
+ , m_pRegistry(pReg)
+{
+}
+
+
+// ~ORegKey()
+
+ORegKey::~ORegKey()
+{
+ SAL_WARN_IF(m_refCount != 0, "registry", "registry::ORegKey::dtor(): refcount not zero.");
+}
+
+
+// releaseKey
+
+RegError ORegKey::releaseKey(RegKeyHandle hKey)
+{
+ return m_pRegistry->releaseKey(hKey);
+}
+
+
+// createKey
+
+RegError ORegKey::createKey(const OUString& keyName, RegKeyHandle* phNewKey)
+{
+ return m_pRegistry->createKey(this, keyName, phNewKey);
+}
+
+
+// openKey
+
+RegError ORegKey::openKey(const OUString& keyName, RegKeyHandle* phOpenKey)
+{
+ return m_pRegistry->openKey(this, keyName, phOpenKey);
+}
+
+
+// openSubKeys
+
+RegError ORegKey::openSubKeys(const OUString& keyName, RegKeyHandle** phOpenSubKeys, sal_uInt32* pnSubKeys)
+{
+ RegError _ret = RegError::NO_ERROR;
+
+ *phOpenSubKeys = nullptr;
+ *pnSubKeys = 0;
+
+ ORegKey* pKey = this;
+ if ( !keyName.isEmpty() )
+ {
+ _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;
+
+ 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.isEmpty())
+ {
+ (void) releaseKey(pKey);
+ }
+ return RegError::NO_ERROR;
+}
+
+
+// getKeyNames
+
+RegError ORegKey::getKeyNames(const OUString& keyName,
+ rtl_uString*** pSubKeyNames,
+ sal_uInt32* pnSubKeys)
+{
+ RegError _ret = RegError::NO_ERROR;
+
+ *pSubKeyNames = nullptr;
+ *pnSubKeys = 0;
+
+ ORegKey* pKey = this;
+ if (!keyName.isEmpty())
+ {
+ _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;
+
+ 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.isEmpty())
+ {
+ releaseKey(pKey);
+ }
+ return RegError::NO_ERROR;
+}
+
+
+// closeKey
+
+RegError ORegKey::closeKey(RegKeyHandle hKey)
+{
+ return m_pRegistry->closeKey(hKey);
+}
+
+
+// deleteKey
+
+RegError ORegKey::deleteKey(const OUString& keyName)
+{
+ return m_pRegistry->deleteKey(this, keyName);
+}
+
+
+// getValueType
+
+RegError ORegKey::getValueInfo(const OUString& valueName, RegValueType* pValueType, sal_uInt32* pValueSize) const
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+ storeAccessMode accessMode = storeAccessMode::ReadWrite;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ accessMode = storeAccessMode::ReadOnly;
+ }
+
+ OUString sImplValueName = 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;
+}
+
+
+// setValue
+
+RegError ORegKey::setValue(const OUString& 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 = 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;
+}
+
+
+// setLongListValue
+
+RegError ORegKey::setLongListValue(const OUString& 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 = 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;
+}
+
+
+// setStringListValue
+
+RegError ORegKey::setStringListValue(const OUString& valueName, char** pValueList, sal_uInt32 len)
+{
+ OStoreStream rValue;
+ std::unique_ptr<sal_uInt8[]> pBuffer;
+
+ if (m_pRegistry->isReadOnly())
+ {
+ return RegError::REGISTRY_READONLY;
+ }
+
+ OUString sImplValueName = 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;
+}
+
+
+// setUnicodeListValue
+
+RegError ORegKey::setUnicodeListValue(const OUString& 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 = 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;
+}
+
+
+// getValue
+
+RegError ORegKey::getValue(const OUString& 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 = 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::NOT_DEFINED:
+ memcpy(value, pBuffer.get(), valueSize);
+ break;
+ 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;
+ // coverity[dead_error_begin] - following conditions exist to avoid compiler warning
+ case RegValueType::LONGLIST:
+ case RegValueType::STRINGLIST:
+ case RegValueType::UNICODELIST:
+ memcpy(value, pBuffer.get(), valueSize);
+ break;
+ }
+
+ return RegError::NO_ERROR;
+}
+
+
+// getLongListValue
+
+RegError ORegKey::getLongListValue(const OUString& 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 = 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;
+}
+
+
+// getStringListValue
+
+RegError ORegKey::getStringListValue(const OUString& 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 = 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;
+}
+
+
+// getUnicodeListValue
+
+RegError ORegKey::getUnicodeListValue(const OUString& 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 = 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(const OUString& keyName,
+ OUString& resolvedName) const
+{
+ if (keyName.isEmpty())
+ return RegError::INVALID_KEYNAME;
+
+ resolvedName = getFullPath(keyName);
+ return RegError::NO_ERROR;
+}
+
+
+// countSubKeys()
+
+sal_uInt32 ORegKey::countSubKeys()
+{
+ REG_GUARD(m_pRegistry->m_mutex);
+
+ OStoreDirectory::iterator iter;
+ OStoreDirectory rStoreDir = getStoreDir();
+ storeError _err = rStoreDir.first(iter);
+ sal_uInt32 count = 0;
+
+ while ( _err == store_E_None )
+ {
+ if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR )
+ {
+ count++;
+ }
+
+ _err = rStoreDir.next(iter);
+ }
+
+ return count;
+}
+
+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(OUString const & path) const {
+ OSL_ASSERT(!m_name.isEmpty() && !path.isEmpty());
+ OUStringBuffer b(32);
+ b.append(m_name);
+ if (!b.isEmpty() && b[b.getLength() - 1] == '/') {
+ if (path[0] == '/') {
+ b.append(std::u16string_view(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 000000000..3233bcad8
--- /dev/null
+++ b/registry/source/keyimpl.hxx
@@ -0,0 +1,136 @@
+/* -*- 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 "regimpl.hxx"
+#include <rtl/ustring.hxx>
+
+class ORegKey
+{
+public:
+
+ ORegKey(const OUString& keyName, ORegistry* pReg);
+ ~ORegKey();
+
+ void acquire()
+ { ++m_refCount; }
+
+ sal_uInt32 release()
+ { return --m_refCount; }
+
+ RegError releaseKey(RegKeyHandle hKey);
+
+ RegError createKey(const OUString& keyName, RegKeyHandle* phNewKey);
+
+ RegError openKey(const OUString& keyName, RegKeyHandle* phOpenKey);
+
+ RegError openSubKeys(const OUString& keyName,
+ RegKeyHandle** phOpenSubKeys,
+ sal_uInt32* pnSubKeys);
+
+ RegError getKeyNames(const OUString& keyName,
+ rtl_uString*** pSubKeyNames,
+ sal_uInt32* pnSubKeys);
+
+ RegError closeKey(RegKeyHandle hKey);
+
+ RegError deleteKey(const OUString& keyName);
+
+ RegError getValueInfo(const OUString& valueName,
+ RegValueType* pValueTye,
+ sal_uInt32* pValueSize) const;
+
+ RegError setValue(const OUString& valueName,
+ RegValueType vType,
+ RegValue value,
+ sal_uInt32 vSize);
+
+ RegError setLongListValue(const OUString& valueName,
+ sal_Int32 const * pValueList,
+ sal_uInt32 len);
+
+ RegError setStringListValue(const OUString& valueName,
+ char** pValueList,
+ sal_uInt32 len);
+
+ RegError setUnicodeListValue(const OUString& valueName,
+ sal_Unicode** pValueList,
+ sal_uInt32 len);
+
+ RegError getValue(const OUString& valueName, RegValue value) const;
+
+ RegError getLongListValue(const OUString& valueName,
+ sal_Int32** pValueList,
+ sal_uInt32* pLen) const;
+
+ RegError getStringListValue(const OUString& valueName,
+ char*** pValueList,
+ sal_uInt32* pLen) const;
+
+ RegError getUnicodeListValue(const OUString& valueName,
+ sal_Unicode*** pValueList,
+ sal_uInt32* pLen) const;
+
+ RegError getResolvedKeyName(const OUString& 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(OUString const & 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 000000000..2254b94b5
--- /dev/null
+++ b/registry/source/reflcnst.hxx
@@ -0,0 +1,229 @@
+/* -*- 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_REFLCNST_HXX
+#define INCLUDED_REGISTRY_SOURCE_REFLCNST_HXX
+
+#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 CP_OFFSET_ENTRY_UIK1 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_DATA)
+#define CP_OFFSET_ENTRY_UIK2 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_UIK1 + sizeof(sal_uInt32))
+#define CP_OFFSET_ENTRY_UIK3 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_UIK2 + sizeof(sal_uInt16))
+#define CP_OFFSET_ENTRY_UIK4 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_UIK3 + sizeof(sal_uInt16))
+#define CP_OFFSET_ENTRY_UIK5 static_cast<sal_uInt32>(CP_OFFSET_ENTRY_UIK4 + sizeof(sal_uInt32))
+
+#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,
+ CP_TAG_UIK
+};
+
+inline sal_uInt32 writeBYTE(sal_uInt8* buffer, sal_uInt8 v)
+{
+ buffer[0] = v;
+
+ return sizeof(sal_uInt8);
+}
+
+inline sal_uInt32 writeINT16(sal_uInt8* buffer, sal_Int16 v)
+{
+ buffer[0] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
+ buffer[1] = static_cast<sal_uInt8>((v >> 0) & 0xFF);
+
+ return sizeof(sal_Int16);
+}
+
+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 writeUINT64(sal_uInt8* buffer, sal_uInt64 v)
+{
+ buffer[0] = static_cast<sal_uInt8>((v >> 56) & 0xFF);
+ buffer[1] = static_cast<sal_uInt8>((v >> 48) & 0xFF);
+ buffer[2] = static_cast<sal_uInt8>((v >> 40) & 0xFF);
+ buffer[3] = static_cast<sal_uInt8>((v >> 32) & 0xFF);
+ buffer[4] = static_cast<sal_uInt8>((v >> 24) & 0xFF);
+ buffer[5] = static_cast<sal_uInt8>((v >> 16) & 0xFF);
+ buffer[6] = static_cast<sal_uInt8>((v >> 8) & 0xFF);
+ buffer[7] = static_cast<sal_uInt8>((v >> 0) & 0xFF);
+
+ return sizeof(sal_uInt64);
+}
+
+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 writeFloat(sal_uInt8* buffer, float v);
+sal_uInt32 writeDouble(sal_uInt8* buffer, double v);
+sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v);
+sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize);
+
+sal_uInt32 UINT16StringLen(const sal_uInt8* wstring);
+
+#endif
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/reflread.cxx b/registry/source/reflread.cxx
new file mode 100644
index 000000000..89c9cbf9c
--- /dev/null
+++ b/registry/source/reflread.cxx
@@ -0,0 +1,1760 @@
+/* -*- 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 "reflread.hxx"
+#include <sal/log.hxx>
+
+#include <registry/typereg_reader.hxx>
+#include <registry/version.h>
+
+#include "reflcnst.hxx"
+
+#include <cstddef>
+
+static const char NULL_STRING[1] = { 0 };
+static const sal_Unicode NULL_WSTRING[1] = { 0 };
+
+const sal_uInt32 magic = 0x12345678;
+const sal_uInt16 minorVersion = 0x0000;
+const sal_uInt16 majorVersion = 0x0001;
+
+/**************************************************************************
+
+ class BlopObject
+
+ holds any data in a flat memory buffer
+
+**************************************************************************/
+
+namespace {
+
+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;
+}
+
+/**************************************************************************
+
+ class StringCache
+
+**************************************************************************/
+
+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;
+}
+
+/**************************************************************************
+
+ class ConstantPool
+
+**************************************************************************/
+
+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;
+}
+
+/**************************************************************************
+
+ class FieldList
+
+**************************************************************************/
+
+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;
+}
+
+/**************************************************************************
+
+ class ReferenceList
+
+**************************************************************************/
+
+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;
+}
+
+/**************************************************************************
+
+ class MethodList
+
+**************************************************************************/
+
+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;
+}
+
+/**************************************************************************
+
+ class TypeRegistryEntry
+
+**************************************************************************/
+
+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);
+}
+
+/**************************************************************************
+
+ C-API
+
+**************************************************************************/
+
+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;
+ }
+}
+
+static TypeReaderImpl TYPEREG_CALLTYPE createEntry(const sal_uInt8* buffer, sal_uInt32 len)
+{
+ void * handle;
+ typereg_reader_create(buffer, len, &handle);
+ return handle;
+}
+
+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);
+}
+
+
+static void TYPEREG_CALLTYPE getSuperTypeName(TypeReaderImpl hEntry, rtl_uString** pSuperTypeName)
+{
+ TypeRegistryEntry* pEntry = static_cast<TypeRegistryEntry*>(hEntry);
+ if (pEntry != nullptr && pEntry->m_nSuperTypes != 0) {
+ try {
+ 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);
+}
+
+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;
+}
+
+static sal_uInt32 TYPEREG_CALLTYPE getFieldCount(TypeReaderImpl hEntry)
+{
+ return typereg_reader_getFieldCount(hEntry);
+}
+
+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;
+}
+
+static RTValueType TYPEREG_CALLTYPE getFieldConstValue(TypeReaderImpl hEntry, sal_uInt16 index, RTConstValueUnion* value)
+{
+ RTValueType t = RT_TYPE_NONE;
+ typereg_reader_getFieldValue(hEntry, index, &t, value);
+ return t;
+}
+
+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);
+}
+
+RegistryTypeReader::RegistryTypeReader(const sal_uInt8* buffer,
+ sal_uInt32 bufferLen)
+ : m_hImpl(nullptr)
+{
+ m_hImpl = createEntry(buffer, bufferLen);
+}
+
+RegistryTypeReader::~RegistryTypeReader()
+{ typereg_reader_release(m_hImpl); }
+
+RTTypeClass RegistryTypeReader::getTypeClass() const
+{ return typereg_reader_getTypeClass(m_hImpl); }
+
+OUString RegistryTypeReader::getTypeName() const
+{
+ OUString sRet;
+ typereg_reader_getTypeName(m_hImpl, &sRet.pData);
+ return sRet;
+}
+
+OUString RegistryTypeReader::getSuperTypeName() const
+{
+ OUString sRet;
+ ::getSuperTypeName(m_hImpl, &sRet.pData);
+ return sRet;
+}
+
+sal_uInt32 RegistryTypeReader::getFieldCount() const
+{ return ::getFieldCount(m_hImpl); }
+
+OUString RegistryTypeReader::getFieldName( sal_uInt16 index ) const
+{
+ OUString sRet;
+ typereg_reader_getFieldName(m_hImpl, &sRet.pData, index);
+ return sRet;
+}
+
+OUString RegistryTypeReader::getFieldType( sal_uInt16 index ) const
+{
+ OUString sRet;
+ typereg_reader_getFieldTypeName(m_hImpl, &sRet.pData, index);
+ return sRet;
+}
+
+RTFieldAccess RegistryTypeReader::getFieldAccess( sal_uInt16 index ) const
+{ return typereg_reader_getFieldFlags(m_hImpl, index); }
+
+RTConstValue RegistryTypeReader::getFieldConstValue( sal_uInt16 index ) const
+{
+ RTConstValue ret;
+ ret.m_type = ::getFieldConstValue(m_hImpl, index, &ret.m_value);
+ return ret;
+}
+
+OUString RegistryTypeReader::getFieldDoku( sal_uInt16 index ) const
+{
+ OUString sRet;
+ typereg_reader_getFieldDocumentation(m_hImpl, &sRet.pData, index);
+ return sRet;
+}
+
+OUString RegistryTypeReader::getFieldFileName( sal_uInt16 index ) const
+{
+ OUString sRet;
+ typereg_reader_getFieldFileName(m_hImpl, &sRet.pData, index);
+ return sRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/reflread.hxx b/registry/source/reflread.hxx
new file mode 100644
index 000000000..5fc428212
--- /dev/null
+++ b/registry/source/reflread.hxx
@@ -0,0 +1,114 @@
+/* -*- 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_REFLREAD_HXX
+#define INCLUDED_REGISTRY_SOURCE_REFLREAD_HXX
+
+#include <registry/refltype.hxx>
+#include <rtl/ustring.hxx>
+
+/// Implementation handle
+typedef void* TypeReaderImpl;
+
+/** RegistryTypeReades reads a binary type blob.
+
+ This class provides the necessary functions to read type information
+ for all kinds of types of a type blob.
+
+ @deprecated
+ use typereg::Reader instead
+*/
+class RegistryTypeReader
+{
+public:
+
+ /** Constructor.
+
+ @param buffer points to the binary data block.
+ @param bufferLen specifies the size of the binary data block.
+ */
+ RegistryTypeReader(const sal_uInt8* buffer,
+ sal_uInt32 bufferLen);
+
+ /// Destructor. The Destructor frees the data block if the copyData flag was TRUE.
+ ~RegistryTypeReader();
+
+ /** returns the typeclass of the type represented by this blob.
+
+ This function will always return the type class without the internal
+ RT_TYPE_PUBLISHED flag set.
+ */
+ RTTypeClass getTypeClass() const;
+
+ /** returns the full qualified name of the type.
+ */
+ OUString getTypeName() const;
+
+ /** returns the full qualified name of the supertype.
+ */
+ OUString getSuperTypeName() const;
+
+ /** returns the number of fields (attributes/properties, enum values or number
+ of constants in a module).
+
+ */
+ sal_uInt32 getFieldCount() const;
+
+ /** returns the name of the field specified by index.
+ */
+ OUString getFieldName( sal_uInt16 index ) const;
+
+ /** returns the full qualified name of the field specified by index.
+ */
+ OUString getFieldType( sal_uInt16 index ) const;
+
+ /** returns the access mode of the field specified by index.
+ */
+ RTFieldAccess getFieldAccess( sal_uInt16 index ) const;
+
+ /** returns the value of the field specified by index.
+
+ This function returns the value of an enum value or of a constant.
+ */
+ RTConstValue getFieldConstValue( sal_uInt16 index ) const;
+
+ /** returns the documentation string for the field specified by index.
+
+ Each field of a type can have their own documentation.
+ */
+ OUString getFieldDoku( sal_uInt16 index ) const;
+
+ /** returns the IDL filename of the field specified by index.
+
+ The IDL filename of a field can differ from the filename of the ype itself
+ because modules and also constants can be defined in different IDL files.
+ */
+ OUString getFieldFileName( sal_uInt16 index ) const;
+
+private:
+ RegistryTypeReader(RegistryTypeReader const &) = delete;
+ void operator =(RegistryTypeReader const &) = delete;
+
+ /// stores the handle of an implementation class
+ TypeReaderImpl m_hImpl;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/reflwrit.cxx b/registry/source/reflwrit.cxx
new file mode 100644
index 000000000..48d28ab87
--- /dev/null
+++ b/registry/source/reflwrit.cxx
@@ -0,0 +1,1335 @@
+/* -*- 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 <new>
+#include <memory>
+#include <algorithm>
+#include <sal/types.h>
+#include <osl/endian.h>
+#include <rtl/string.hxx>
+#include <rtl/ustring.hxx>
+
+#include "reflwrit.hxx"
+#include <registry/refltype.hxx>
+#include <registry/version.h>
+#include <registry/writer.h>
+
+#include "reflcnst.hxx"
+
+
+namespace {
+
+OString toByteString(rtl_uString const * str) {
+ return OString(
+ str->buffer, str->length, RTL_TEXTENCODING_UTF8,
+ OUSTRING_TO_OSTRING_CVTFLAGS);
+}
+
+}
+
+static const sal_Unicode NULL_WSTRING[1] = { 0 };
+
+#define BLOP_OFFSET_MAGIC 0
+#define BLOP_OFFSET_SIZE (BLOP_OFFSET_MAGIC + sizeof(sal_uInt32))
+#define BLOP_OFFSET_MINOR (BLOP_OFFSET_SIZE + sizeof(sal_uInt32))
+#define BLOP_OFFSET_MAJOR (BLOP_OFFSET_MINOR + sizeof(sal_uInt16))
+#define BLOP_OFFSET_N_ENTRIES (BLOP_OFFSET_MAJOR + sizeof(sal_uInt16))
+#define BLOP_HEADER_N_ENTRIES 6
+
+#define BLOP_FIELD_N_ENTRIES 6
+
+#define BLOP_METHOD_N_ENTRIES 5
+
+#define BLOP_PARAM_N_ENTRIES 3
+
+#define BLOP_REFERENCE_N_ENTRIES 4
+
+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);
+}
+
+sal_uInt32 writeFloat(sal_uInt8* buffer, float v)
+{
+ union
+ {
+ float v;
+ sal_uInt32 b;
+ } x;
+
+ x.v = v;
+
+#ifdef REGTYPE_IEEE_NATIVE
+ writeUINT32(buffer, x.b);
+#else
+# error no IEEE
+#endif
+
+ return sizeof(sal_uInt32);
+}
+
+sal_uInt32 writeDouble(sal_uInt8* buffer, double v)
+{
+ union
+ {
+ double v;
+ struct
+ {
+ sal_uInt32 b1;
+ sal_uInt32 b2;
+ } b;
+ } x;
+
+ x.v = v;
+
+#ifdef REGTYPE_IEEE_NATIVE
+# ifdef OSL_BIGENDIAN
+ writeUINT32(buffer, x.b.b1);
+ writeUINT32(buffer + sizeof(sal_uInt32), x.b.b2);
+# else
+ writeUINT32(buffer, x.b.b2);
+ writeUINT32(buffer + sizeof(sal_uInt32), x.b.b1);
+# endif
+#else
+# error no IEEE
+#endif
+
+ return (sizeof(sal_uInt32) + sizeof(sal_uInt32));
+}
+
+/**************************************************************************
+
+ buffer write functions
+
+**************************************************************************/
+
+namespace {
+
+/**************************************************************************
+
+ struct CPInfo
+
+**************************************************************************/
+
+struct CPInfo
+{
+ union
+ {
+ const char* aUtf8;
+ RTUik* aUik;
+ RTConstValueUnion aConst;
+ } m_value;
+ struct CPInfo* m_next;
+ CPInfoTag m_tag;
+ sal_uInt16 m_index;
+
+ CPInfo(CPInfoTag tag, struct CPInfo* prev);
+
+ sal_uInt32 getBlopSize() const;
+
+ sal_uInt32 toBlop(sal_uInt8* buffer);
+};
+
+CPInfo::CPInfo(CPInfoTag tag, struct CPInfo* prev)
+ : m_next(nullptr)
+ , m_tag(tag)
+ , m_index(0)
+{
+ if (prev)
+ {
+ m_index = prev->m_index + 1;
+ prev->m_next = this;
+ }
+}
+
+sal_uInt32 CPInfo::getBlopSize() const
+{
+ sal_uInt32 size = sizeof(sal_uInt32) /* size */ + sizeof(sal_uInt16) /* tag */;
+
+ switch (m_tag)
+ {
+ case CP_TAG_CONST_BOOL:
+ size += sizeof(sal_uInt8);
+ break;
+ case CP_TAG_CONST_BYTE:
+ size += sizeof(sal_uInt8);
+ break;
+ case CP_TAG_CONST_INT16:
+ size += sizeof(sal_Int16);
+ break;
+ case CP_TAG_CONST_UINT16:
+ size += sizeof(sal_uInt16);
+ break;
+ case CP_TAG_CONST_INT32:
+ size += sizeof(sal_Int32);
+ break;
+ case CP_TAG_CONST_UINT32:
+ size += sizeof(sal_uInt32);
+ break;
+ case CP_TAG_CONST_INT64:
+ size += sizeof(sal_Int64);
+ break;
+ case CP_TAG_CONST_UINT64:
+ size += sizeof(sal_uInt64);
+ break;
+ case CP_TAG_CONST_FLOAT:
+ size += sizeof(sal_uInt32);
+ break;
+ case CP_TAG_CONST_DOUBLE:
+ size += sizeof(sal_uInt32) + sizeof(sal_uInt32);
+ break;
+ case CP_TAG_CONST_STRING:
+ size += (rtl_ustr_getLength(m_value.aConst.aString) + 1) * sizeof(sal_uInt16);
+ break;
+ case CP_TAG_UTF8_NAME:
+ size += strlen(m_value.aUtf8) + 1;
+ break;
+ case CP_TAG_UIK:
+ size += sizeof(sal_uInt32) + sizeof(sal_uInt16) + sizeof(sal_uInt16) + sizeof(sal_uInt32) + sizeof(sal_uInt32);
+ break;
+ default:
+ break;
+ }
+
+ return size;
+}
+
+
+sal_uInt32 CPInfo::toBlop(sal_uInt8* buffer)
+{
+ sal_uInt8* buff = buffer;
+
+ buff += writeUINT32(buff, getBlopSize());
+ buff += writeUINT16(buff, static_cast<sal_uInt16>(m_tag));
+
+ switch (m_tag)
+ {
+ case CP_TAG_CONST_BOOL:
+ buff += writeBYTE(buff, static_cast<sal_uInt8>(m_value.aConst.aBool));
+ break;
+ case CP_TAG_CONST_BYTE:
+ buff += writeBYTE(
+ buff, static_cast< sal_uInt8 >(m_value.aConst.aByte));
+ break;
+ case CP_TAG_CONST_INT16:
+ buff += writeINT16(buff, m_value.aConst.aShort);
+ break;
+ case CP_TAG_CONST_UINT16:
+ buff += writeINT16(buff, m_value.aConst.aUShort);
+ break;
+ case CP_TAG_CONST_INT32:
+ buff += writeINT32(buff, m_value.aConst.aLong);
+ break;
+ case CP_TAG_CONST_UINT32:
+ buff += writeUINT32(buff, m_value.aConst.aULong);
+ break;
+ case CP_TAG_CONST_INT64:
+ buff += writeUINT64(buff, m_value.aConst.aHyper);
+ break;
+ case CP_TAG_CONST_UINT64:
+ buff += writeUINT64(buff, m_value.aConst.aUHyper);
+ break;
+ case CP_TAG_CONST_FLOAT:
+ buff += writeFloat(buff, m_value.aConst.aFloat);
+ break;
+ case CP_TAG_CONST_DOUBLE:
+ buff += writeDouble(buff, m_value.aConst.aDouble);
+ break;
+ case CP_TAG_CONST_STRING:
+ buff += writeString(buff, m_value.aConst.aString);
+ break;
+ case CP_TAG_UTF8_NAME:
+ buff += writeUtf8(buff, m_value.aUtf8);
+ break;
+ case CP_TAG_UIK:
+ buff += writeUINT32(buff, m_value.aUik->m_Data1);
+ buff += writeUINT16(buff, m_value.aUik->m_Data2);
+ buff += writeUINT16(buff, m_value.aUik->m_Data3);
+ buff += writeUINT32(buff, m_value.aUik->m_Data4);
+ buff += writeUINT32(buff, m_value.aUik->m_Data5);
+ break;
+ default:
+ break;
+ }
+
+ return (buff - buffer);
+}
+
+
+/**************************************************************************
+
+ class FieldEntry
+
+**************************************************************************/
+
+class FieldEntry
+{
+
+public:
+
+ OString m_name;
+ OString m_typeName;
+ OString m_doku;
+ OString m_fileName;
+ RTFieldAccess m_access;
+ RTValueType m_constValueType;
+ RTConstValueUnion m_constValue;
+
+ FieldEntry();
+ ~FieldEntry();
+
+ void setData(const OString& name,
+ const OString& typeName,
+ const OString& doku,
+ const OString& fileName,
+ RTFieldAccess access,
+ RTValueType constValueType,
+ RTConstValueUnion constValue);
+ // throws std::bad_alloc
+};
+
+FieldEntry::FieldEntry()
+ : m_access(RTFieldAccess::INVALID)
+ , m_constValueType(RT_TYPE_NONE)
+{
+}
+
+FieldEntry::~FieldEntry()
+{
+ if (
+ (m_constValueType == RT_TYPE_STRING) &&
+ m_constValue.aString &&
+ (m_constValue.aString != NULL_WSTRING)
+ )
+ {
+ delete[] m_constValue.aString;
+ }
+}
+
+void FieldEntry::setData(const OString& name,
+ const OString& typeName,
+ const OString& doku,
+ const OString& fileName,
+ RTFieldAccess access,
+ RTValueType constValueType,
+ RTConstValueUnion constValue)
+{
+ std::unique_ptr<sal_Unicode[]> newValue;
+ if (constValueType == RT_TYPE_STRING && constValue.aString != nullptr) {
+ sal_Int32 n = rtl_ustr_getLength(constValue.aString) + 1;
+ newValue.reset(new sal_Unicode[n]);
+ memcpy(newValue.get(), constValue.aString, n * sizeof (sal_Unicode));
+ }
+
+ m_name = name;
+ m_typeName = typeName;
+ m_doku = doku;
+ m_fileName = fileName;
+
+ if (
+ (m_constValueType == RT_TYPE_STRING) &&
+ m_constValue.aString &&
+ (m_constValue.aString != NULL_WSTRING)
+ )
+ {
+ delete[] m_constValue.aString;
+ }
+
+ m_access = access;
+ m_constValueType = constValueType;
+
+ if (m_constValueType == RT_TYPE_STRING)
+ {
+ if (constValue.aString == nullptr)
+ m_constValue.aString = NULL_WSTRING;
+ else
+ {
+ m_constValue.aString = newValue.release();
+ }
+ }
+ else
+ {
+ m_constValue = constValue;
+ }
+}
+
+/**************************************************************************
+
+ class ParamEntry
+
+**************************************************************************/
+
+class ParamEntry
+{
+public:
+
+ OString m_typeName;
+ OString m_name;
+ RTParamMode m_mode;
+
+ ParamEntry();
+
+ void setData(const OString& typeName,
+ const OString& name,
+ RTParamMode mode);
+};
+
+ParamEntry::ParamEntry()
+ : m_mode(RT_PARAM_INVALID)
+{
+}
+
+void ParamEntry::setData(const OString& typeName,
+ const OString& name,
+ RTParamMode mode)
+{
+ m_name = name;
+ m_typeName = typeName;
+ m_mode = mode;
+}
+
+/**************************************************************************
+
+ class ReferenceEntry
+
+**************************************************************************/
+
+class ReferenceEntry
+{
+public:
+
+ OString m_name;
+ OString m_doku;
+ RTReferenceType m_type;
+ RTFieldAccess m_access;
+
+ ReferenceEntry();
+
+ void setData(const OString& name,
+ RTReferenceType refType,
+ const OString& doku,
+ RTFieldAccess access);
+};
+
+ReferenceEntry::ReferenceEntry()
+ : m_type(RTReferenceType::INVALID)
+ , m_access(RTFieldAccess::INVALID)
+{
+}
+
+void ReferenceEntry::setData(const OString& name,
+ RTReferenceType refType,
+ const OString& doku,
+ RTFieldAccess access)
+{
+ m_name = name;
+ m_doku = doku;
+ m_type = refType;
+ m_access = access;
+}
+
+/**************************************************************************
+
+ class MethodEntry
+
+**************************************************************************/
+
+class MethodEntry
+{
+public:
+
+ OString m_name;
+ OString m_returnTypeName;
+ RTMethodMode m_mode;
+ sal_uInt16 m_paramCount;
+ std::unique_ptr<ParamEntry[]> m_params;
+ sal_uInt16 m_excCount;
+ std::unique_ptr<OString[]> m_excNames;
+ OString m_doku;
+
+ MethodEntry();
+
+ void setData(const OString& name,
+ const OString& returnTypeName,
+ RTMethodMode mode,
+ sal_uInt16 paramCount,
+ sal_uInt16 excCount,
+ const OString& doku);
+
+ void setExcName(sal_uInt16 excIndex, const OString& name) const;
+
+protected:
+
+ void reallocParams(sal_uInt16 size);
+ void reallocExcs(sal_uInt16 size);
+};
+
+MethodEntry::MethodEntry()
+ : m_mode(RTMethodMode::INVALID)
+ , m_paramCount(0)
+ , m_excCount(0)
+{
+}
+
+void MethodEntry::setData(const OString& name,
+ const OString& returnTypeName,
+ RTMethodMode mode,
+ sal_uInt16 paramCount,
+ sal_uInt16 excCount,
+ const OString& doku)
+{
+ m_name = name;
+ m_returnTypeName = returnTypeName;
+ m_doku = doku;
+
+ m_mode = mode;
+
+ reallocParams(paramCount);
+ reallocExcs(excCount);
+}
+
+void MethodEntry::setExcName(sal_uInt16 excIndex, const OString& name) const
+{
+ if (excIndex < m_excCount)
+ {
+ m_excNames[excIndex] = name;
+ }
+}
+
+void MethodEntry::reallocParams(sal_uInt16 size)
+{
+ ParamEntry* newParams;
+
+ if (size)
+ newParams = new ParamEntry[size];
+ else
+ newParams = nullptr;
+
+ if (m_paramCount)
+ {
+ sal_uInt16 i;
+ sal_uInt16 mn = std::min(size, m_paramCount);
+
+ for (i = 0; i < mn; i++)
+ {
+ newParams[i].setData(m_params[i].m_typeName, m_params[i].m_name, m_params[i].m_mode);
+ }
+
+ m_params.reset();
+ }
+
+ m_paramCount = size;
+ m_params.reset( newParams );
+}
+
+void MethodEntry::reallocExcs(sal_uInt16 size)
+{
+ OString* newExcNames;
+
+ if (size)
+ newExcNames = new OString[size];
+ else
+ newExcNames = nullptr;
+
+ sal_uInt16 i;
+ sal_uInt16 mn = std::min(size, m_excCount);
+
+ for (i = 0; i < mn; i++)
+ {
+ newExcNames[i] = m_excNames[i];
+ }
+
+ m_excCount = size;
+ m_excNames.reset( newExcNames );
+}
+
+
+/**************************************************************************
+
+ class TypeRegistryEntry
+
+**************************************************************************/
+
+class TypeWriter
+{
+
+public:
+
+ sal_uInt32 m_refCount;
+ typereg_Version m_version;
+ RTTypeClass m_typeClass;
+ OString m_typeName;
+ sal_uInt16 m_nSuperTypes;
+ std::unique_ptr<OString[]>
+ m_superTypeNames;
+ OString m_doku;
+ OString m_fileName;
+ sal_uInt16 m_fieldCount;
+ FieldEntry* m_fields;
+ sal_uInt16 m_methodCount;
+ MethodEntry* m_methods;
+ sal_uInt16 m_referenceCount;
+ ReferenceEntry* m_references;
+
+ std::unique_ptr<sal_uInt8[]> m_blop;
+ sal_uInt32 m_blopSize;
+
+ TypeWriter(typereg_Version version,
+ OString const & documentation,
+ OString const & fileName,
+ RTTypeClass RTTypeClass,
+ bool published,
+ const OString& typeName,
+ sal_uInt16 superTypeCount,
+ sal_uInt16 FieldCount,
+ sal_uInt16 methodCount,
+ sal_uInt16 referenceCount);
+
+ ~TypeWriter();
+
+ void setSuperType(sal_uInt16 index, OString const & name) const;
+
+ void createBlop(); // throws std::bad_alloc
+};
+
+TypeWriter::TypeWriter(typereg_Version version,
+ OString const & documentation,
+ OString const & fileName,
+ RTTypeClass RTTypeClass,
+ bool published,
+ const OString& typeName,
+ sal_uInt16 superTypeCount,
+ sal_uInt16 fieldCount,
+ sal_uInt16 methodCount,
+ sal_uInt16 referenceCount)
+ : m_refCount(1)
+ , m_version(version)
+ , m_typeClass(
+ static_cast< enum RTTypeClass >(
+ RTTypeClass | (published ? RT_TYPE_PUBLISHED : 0)))
+ , m_typeName(typeName)
+ , m_nSuperTypes(superTypeCount)
+ , m_doku(documentation)
+ , m_fileName(fileName)
+ , m_fieldCount(fieldCount)
+ , m_fields(nullptr)
+ , m_methodCount(methodCount)
+ , m_methods(nullptr)
+ , m_referenceCount(referenceCount)
+ , m_references(nullptr)
+ , m_blopSize(0)
+{
+ if (m_nSuperTypes > 0)
+ {
+ m_superTypeNames.reset( new OString[m_nSuperTypes] );
+ }
+
+ if (m_fieldCount)
+ m_fields = new FieldEntry[fieldCount];
+
+ if (m_methodCount)
+ m_methods = new MethodEntry[methodCount];
+
+ if (m_referenceCount)
+ m_references = new ReferenceEntry[referenceCount];
+}
+
+TypeWriter::~TypeWriter()
+{
+ if (m_fieldCount)
+ delete[] m_fields;
+
+ if (m_methodCount)
+ delete[] m_methods;
+
+ if (m_referenceCount)
+ delete[] m_references;
+}
+
+void TypeWriter::setSuperType(sal_uInt16 index, OString const & name) const
+{
+ m_superTypeNames[index] = name;
+}
+
+void TypeWriter::createBlop()
+{
+ //TODO: Fix memory leaks that occur when std::bad_alloc is thrown
+
+ std::unique_ptr<sal_uInt8[]> pBlopFields;
+ std::unique_ptr<sal_uInt8[]> pBlopMethods;
+ std::unique_ptr<sal_uInt8[]> pBlopReferences;
+ sal_uInt8* pBuffer = nullptr;
+ sal_uInt32 blopFieldsSize = 0;
+ sal_uInt32 blopMethodsSize = 0;
+ sal_uInt32 blopReferenceSize = 0;
+
+ CPInfo root(CP_TAG_INVALID, nullptr);
+ sal_uInt16 cpIndexThisName = 0;
+ std::unique_ptr<sal_uInt16[]> cpIndexSuperNames;
+ sal_uInt16 cpIndexDoku = 0;
+ sal_uInt16 cpIndexFileName = 0;
+ CPInfo* pInfo = nullptr;
+
+ sal_uInt16 entrySize = sizeof(sal_uInt16);
+ sal_uInt32 blopHeaderEntrySize = BLOP_OFFSET_N_ENTRIES + entrySize + (BLOP_HEADER_N_ENTRIES * entrySize);
+ sal_uInt32 blopFieldEntrySize = BLOP_FIELD_N_ENTRIES * entrySize;
+ sal_uInt32 blopMethodEntrySize = BLOP_METHOD_N_ENTRIES * entrySize;
+ sal_uInt32 blopParamEntrySize = BLOP_PARAM_N_ENTRIES * entrySize;
+ sal_uInt32 blopReferenceEntrySize = BLOP_REFERENCE_N_ENTRIES * entrySize;
+
+ sal_uInt32 blopSize = blopHeaderEntrySize;
+
+ // create CP entry for this name
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, &root);
+ pInfo->m_value.aUtf8 = m_typeName.getStr();
+ cpIndexThisName = pInfo->m_index;
+
+ // nSuperTypes
+ blopSize += entrySize;
+
+ // create CP entry for super names
+ if (m_nSuperTypes)
+ {
+ blopSize += m_nSuperTypes * entrySize;
+
+ cpIndexSuperNames.reset(new sal_uInt16[m_nSuperTypes]);
+
+ for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_superTypeNames[i].getStr();
+ cpIndexSuperNames[i] = pInfo->m_index;
+ }
+ }
+
+ // create CP entry for doku
+ if (!m_doku.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_doku.getStr();
+ cpIndexDoku = pInfo->m_index;
+ }
+
+ // create CP entry for idl source filename
+ if (!m_fileName.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_fileName.getStr();
+ cpIndexFileName = pInfo->m_index;
+ }
+
+ // fields blop
+ blopSize += sizeof(sal_uInt16); // fieldCount + nFieldEntries
+
+ if (m_fieldCount)
+ {
+ sal_uInt16 cpIndexName = 0;
+ sal_uInt16 cpIndexTypeName = 0;
+ sal_uInt16 cpIndexValue = 0;
+ sal_uInt16 cpIndexDoku2 = 0;
+ sal_uInt16 cpIndexFileName2 = 0;
+
+ // nFieldEntries + n fields
+ blopFieldsSize = sizeof(sal_uInt16) + (m_fieldCount * blopFieldEntrySize);
+
+ blopSize += blopFieldsSize;
+
+ pBlopFields.reset(new sal_uInt8[blopFieldsSize]);
+ pBuffer = pBlopFields.get();
+
+ pBuffer += writeUINT16(pBuffer, BLOP_FIELD_N_ENTRIES);
+
+ for (sal_uInt16 i = 0; i < m_fieldCount; i++)
+ {
+ cpIndexName = 0;
+ cpIndexTypeName = 0;
+ cpIndexValue = 0;
+ cpIndexDoku2 = 0;
+ cpIndexFileName2 = 0;
+
+ pBuffer += writeUINT16(pBuffer, static_cast<sal_uInt16>(m_fields[i].m_access));
+
+ if (!m_fields[i].m_name.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_fields[i].m_name.getStr();
+ cpIndexName = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexName);
+
+ if (!m_fields[i].m_typeName.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_fields[i].m_typeName.getStr();
+ cpIndexTypeName = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexTypeName);
+
+ if (m_fields[i].m_constValueType != RT_TYPE_NONE)
+ {
+ pInfo = new CPInfo(static_cast<CPInfoTag>(m_fields[i].m_constValueType), pInfo);
+ pInfo->m_value.aConst = m_fields[i].m_constValue;
+ cpIndexValue = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexValue);
+
+ if (!m_fields[i].m_doku.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_fields[i].m_doku.getStr();
+ cpIndexDoku2 = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
+
+ if (!m_fields[i].m_fileName.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_fields[i].m_fileName.getStr();
+ cpIndexFileName2 = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexFileName2);
+ }
+ }
+
+ // methods blop
+ blopSize += sizeof(sal_uInt16); // methodCount
+
+ if (m_methodCount)
+ {
+ std::unique_ptr<sal_uInt16[]> pMethodEntrySize( new sal_uInt16[m_methodCount] );
+ sal_uInt16 cpIndexName = 0;
+ sal_uInt16 cpIndexReturn = 0;
+ sal_uInt16 cpIndexDoku2 = 0;
+
+ // nMethodEntries + nParamEntries
+ blopMethodsSize = (2 * sizeof(sal_uInt16));
+
+ for (sal_uInt16 i = 0; i < m_methodCount; i++)
+ {
+ pMethodEntrySize[i] = static_cast<sal_uInt16>( blopMethodEntrySize + // header
+ sizeof(sal_uInt16) + // parameterCount
+ (m_methods[i].m_paramCount * blopParamEntrySize) + // exceptions
+ sizeof(sal_uInt16) + // exceptionCount
+ (m_methods[i].m_excCount * sizeof(sal_uInt16)) ); // exceptions
+
+ blopMethodsSize += pMethodEntrySize[i];
+ }
+
+ pBlopMethods.reset(new sal_uInt8[blopMethodsSize]);
+
+ blopSize += blopMethodsSize;
+
+ pBuffer = pBlopMethods.get();
+
+ pBuffer += writeUINT16(pBuffer, BLOP_METHOD_N_ENTRIES);
+ pBuffer += writeUINT16(pBuffer, BLOP_PARAM_N_ENTRIES );
+
+ for (sal_uInt16 i = 0; i < m_methodCount; i++)
+ {
+ cpIndexReturn = 0;
+ cpIndexDoku2 = 0;
+
+ pBuffer += writeUINT16(pBuffer, pMethodEntrySize[i]);
+ pBuffer += writeUINT16(
+ pBuffer,
+ sal::static_int_cast< sal_uInt16 >(m_methods[i].m_mode));
+
+ if (!m_methods[i].m_name.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_methods[i].m_name.getStr();
+ cpIndexName = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexName);
+ cpIndexName = 0;
+
+ if (!m_methods[i].m_returnTypeName.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_methods[i].m_returnTypeName.getStr();
+ cpIndexReturn = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexReturn);
+
+ if (!m_methods[i].m_doku.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_methods[i].m_doku.getStr();
+ cpIndexDoku2 = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
+
+ sal_uInt16 j;
+
+ pBuffer += writeUINT16(pBuffer, m_methods[i].m_paramCount);
+
+ for (j = 0; j < m_methods[i].m_paramCount; j++)
+ {
+ if (!m_methods[i].m_params[j].m_typeName.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_typeName.getStr();
+ cpIndexName = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexName);
+ cpIndexName = 0;
+
+ pBuffer += writeUINT16(
+ pBuffer,
+ sal::static_int_cast< sal_uInt16 >(
+ m_methods[i].m_params[j].m_mode));
+
+ if (!m_methods[i].m_params[j].m_name.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_name.getStr();
+ cpIndexName = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexName);
+ cpIndexName = 0;
+ }
+
+ pBuffer += writeUINT16(pBuffer, m_methods[i].m_excCount);
+
+ for (j = 0; j < m_methods[i].m_excCount; j++)
+ {
+ if (!m_methods[i].m_excNames[j].isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_methods[i].m_excNames[j].getStr();
+ cpIndexName = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexName);
+ cpIndexName = 0;
+ }
+ }
+ }
+
+ // reference blop
+ blopSize += entrySize; // referenceCount
+
+ if (m_referenceCount)
+ {
+ sal_uInt16 cpIndexName = 0;
+ sal_uInt16 cpIndexDoku2 = 0;
+
+ // nReferenceEntries + n references
+ blopReferenceSize = entrySize + (m_referenceCount * blopReferenceEntrySize);
+
+ blopSize += blopReferenceSize;
+
+ pBlopReferences.reset(new sal_uInt8[blopReferenceSize]);
+ pBuffer = pBlopReferences.get();
+
+ pBuffer += writeUINT16(pBuffer, BLOP_REFERENCE_N_ENTRIES);
+
+ for (sal_uInt16 i = 0; i < m_referenceCount; i++)
+ {
+ pBuffer += writeUINT16(
+ pBuffer,
+ sal::static_int_cast< sal_uInt16 >(m_references[i].m_type));
+
+ cpIndexName = 0;
+ cpIndexDoku2 = 0;
+
+ if (!m_references[i].m_name.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_references[i].m_name.getStr();
+ cpIndexName = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexName);
+
+ if (!m_references[i].m_doku.isEmpty())
+ {
+ pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
+ pInfo->m_value.aUtf8 = m_references[i].m_doku.getStr();
+ cpIndexDoku2 = pInfo->m_index;
+ }
+ pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
+
+ pBuffer += writeUINT16(pBuffer, static_cast<sal_uInt16>(m_references[i].m_access));
+ }
+ }
+
+
+ // get CP infos blop-length
+ pInfo = root.m_next;
+ sal_uInt32 cpBlopSize = 0;
+ sal_uInt16 cpCount = 0;
+
+ while (pInfo)
+ {
+ cpBlopSize += pInfo->getBlopSize();
+ cpCount++;
+ pInfo = pInfo->m_next;
+ }
+
+ blopSize += cpBlopSize;
+ blopSize += sizeof(sal_uInt16); // constantPoolCount
+
+ // write all in flat buffer
+
+ sal_uInt8 * blop = new sal_uInt8[blopSize];
+
+ pBuffer = blop;
+
+ // Assumes two's complement arithmetic with modulo-semantics:
+ pBuffer += writeUINT32(pBuffer, magic + m_version);
+ pBuffer += writeUINT32(pBuffer, blopSize);
+ pBuffer += writeUINT16(pBuffer, minorVersion);
+ pBuffer += writeUINT16(pBuffer, majorVersion);
+ pBuffer += writeUINT16(pBuffer, BLOP_HEADER_N_ENTRIES);
+
+ pBuffer += writeUINT16(pBuffer, sal_uInt16(RT_UNO_IDL));
+ pBuffer += writeUINT16(pBuffer, static_cast<sal_uInt16>(m_typeClass));
+ pBuffer += writeUINT16(pBuffer, cpIndexThisName);
+ pBuffer += writeUINT16(pBuffer, 0); // cpIndexUik
+ pBuffer += writeUINT16(pBuffer, cpIndexDoku);
+ pBuffer += writeUINT16(pBuffer, cpIndexFileName);
+
+ // write supertypes
+ pBuffer += writeUINT16(pBuffer, m_nSuperTypes);
+ if (m_nSuperTypes)
+ {
+ for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
+ {
+ pBuffer += writeUINT16(pBuffer, cpIndexSuperNames[i]);
+ }
+ cpIndexSuperNames.reset();
+ }
+
+ pBuffer += writeUINT16(pBuffer, cpCount);
+
+ // write and delete CP infos
+ pInfo = root.m_next;
+
+ while (pInfo)
+ {
+ CPInfo* pNextInfo = pInfo->m_next;
+
+ pBuffer += pInfo->toBlop(pBuffer);
+ delete pInfo;
+
+ pInfo = pNextInfo;
+ }
+
+ auto writeList = [&pBuffer](
+ sal_uInt16 count, sal_uInt8 * data, sal_uInt32 size)
+ {
+ pBuffer += writeUINT16(pBuffer, count);
+ if (size != 0) {
+ memcpy(pBuffer, data, size);
+ pBuffer += size;
+ }
+ };
+
+ // write fields
+ writeList(m_fieldCount, pBlopFields.get(), blopFieldsSize);
+
+ // write methods
+ writeList(m_methodCount, pBlopMethods.get(), blopMethodsSize);
+
+ // write references
+ writeList(m_referenceCount, pBlopReferences.get(), blopReferenceSize);
+
+ m_blop.reset( blop );
+ m_blopSize = blopSize;
+}
+
+} // unnamed namespace
+
+/**************************************************************************
+
+ C-API
+
+**************************************************************************/
+
+extern "C" {
+
+static void TYPEREG_CALLTYPE release(TypeWriterImpl hEntry)
+{
+ TypeWriter* pEntry = static_cast<TypeWriter*>(hEntry);
+
+ if (pEntry != nullptr)
+ {
+ if (--pEntry->m_refCount == 0)
+ delete pEntry;
+ }
+}
+
+sal_Bool TYPEREG_CALLTYPE typereg_writer_setFieldData(
+ void * handle, sal_uInt16 index, rtl_uString const * documentation,
+ rtl_uString const * fileName, RTFieldAccess flags, rtl_uString const * name,
+ rtl_uString const * typeName, RTValueType valueType,
+ RTConstValueUnion valueValue)
+ SAL_THROW_EXTERN_C()
+{
+ try {
+ static_cast< TypeWriter * >(handle)->m_fields[index].setData(
+ toByteString(name), toByteString(typeName),
+ toByteString(documentation), toByteString(fileName), flags,
+ valueType, valueValue);
+ } catch (std::bad_alloc &) {
+ return false;
+ }
+ return true;
+}
+
+static void TYPEREG_CALLTYPE setFieldData(TypeWriterImpl hEntry,
+ sal_uInt16 index,
+ rtl_uString const * name,
+ rtl_uString const * typeName,
+ rtl_uString const * doku,
+ rtl_uString const * fileName,
+ RTFieldAccess access,
+ RTValueType valueType,
+ RTConstValueUnion constValue)
+{
+ typereg_writer_setFieldData(
+ hEntry, index, doku, fileName, access, name, typeName, valueType,
+ constValue);
+}
+
+sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodData(
+ void * handle, sal_uInt16 index, rtl_uString const * documentation,
+ RTMethodMode flags, rtl_uString const * name,
+ rtl_uString const * returnTypeName, sal_uInt16 parameterCount,
+ sal_uInt16 exceptionCount)
+ SAL_THROW_EXTERN_C()
+{
+ try {
+ static_cast< TypeWriter * >(handle)->m_methods[index].setData(
+ toByteString(name), toByteString(returnTypeName), flags,
+ parameterCount, exceptionCount, toByteString(documentation));
+ } catch (std::bad_alloc &) {
+ return false;
+ }
+ return true;
+}
+
+sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodParameterData(
+ void const * handle, sal_uInt16 methodIndex, sal_uInt16 parameterIndex,
+ RTParamMode flags, rtl_uString const * name, rtl_uString const * typeName)
+ SAL_THROW_EXTERN_C()
+{
+ try {
+ static_cast< TypeWriter const * >(handle)->
+ m_methods[methodIndex].m_params[parameterIndex].setData(
+ toByteString(typeName), toByteString(name), flags);
+ } catch (std::bad_alloc &) {
+ return false;
+ }
+ return true;
+}
+
+sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodExceptionTypeName(
+ void const * handle, sal_uInt16 methodIndex, sal_uInt16 exceptionIndex,
+ rtl_uString const * typeName)
+ SAL_THROW_EXTERN_C()
+{
+ try {
+ static_cast< TypeWriter const * >(handle)->m_methods[methodIndex].setExcName(
+ exceptionIndex, toByteString(typeName));
+ } catch (std::bad_alloc &) {
+ return false;
+ }
+ return true;
+}
+
+void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * size)
+ SAL_THROW_EXTERN_C()
+{
+ TypeWriter * writer = static_cast< TypeWriter * >(handle);
+ if (!writer->m_blop) {
+ try {
+ writer->createBlop();
+ } catch (std::bad_alloc &) {
+ return nullptr;
+ }
+ }
+ *size = writer->m_blopSize;
+ return writer->m_blop.get();
+}
+
+static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry)
+{
+ sal_uInt32 size;
+ return static_cast< sal_uInt8 const * >(
+ typereg_writer_getBlob(hEntry, &size));
+}
+
+static sal_uInt32 TYPEREG_CALLTYPE getBlopSize(TypeWriterImpl hEntry)
+{
+ sal_uInt32 size;
+ typereg_writer_getBlob(hEntry, &size);
+ return size;
+}
+
+sal_Bool TYPEREG_CALLTYPE typereg_writer_setReferenceData(
+ void * handle, sal_uInt16 index, rtl_uString const * documentation,
+ RTReferenceType sort, RTFieldAccess flags, rtl_uString const * typeName)
+ SAL_THROW_EXTERN_C()
+{
+ try {
+ static_cast< TypeWriter * >(handle)->m_references[index].setData(
+ toByteString(typeName), sort, toByteString(documentation), flags);
+ } catch (std::bad_alloc &) {
+ return false;
+ }
+ return true;
+}
+
+void * TYPEREG_CALLTYPE typereg_writer_create(
+ typereg_Version version, rtl_uString const * documentation,
+ rtl_uString const * fileName, RTTypeClass typeClass, sal_Bool published,
+ rtl_uString const * typeName, sal_uInt16 superTypeCount,
+ sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
+ SAL_THROW_EXTERN_C()
+{
+ try {
+ return new TypeWriter(
+ version, toByteString(documentation), toByteString(fileName),
+ typeClass, published, toByteString(typeName), superTypeCount,
+ fieldCount, methodCount, referenceCount);
+ } catch (std::bad_alloc &) {
+ return nullptr;
+ }
+}
+
+void TYPEREG_CALLTYPE typereg_writer_destroy(void * handle) SAL_THROW_EXTERN_C() {
+ delete static_cast< TypeWriter * >(handle);
+}
+
+sal_Bool TYPEREG_CALLTYPE typereg_writer_setSuperTypeName(
+ void const * handle, sal_uInt16 index, rtl_uString const * typeName)
+ SAL_THROW_EXTERN_C()
+{
+ try {
+ static_cast< TypeWriter const * >(handle)->setSuperType(
+ index, toByteString(typeName));
+ } catch (std::bad_alloc &) {
+ return false;
+ }
+ return true;
+}
+
+static TypeWriterImpl TYPEREG_CALLTYPE createEntry(
+ RTTypeClass typeClass, rtl_uString const * typeName, rtl_uString const * superTypeName,
+ sal_uInt16 fieldCount)
+{
+ OUString empty;
+ sal_uInt16 superTypeCount = rtl_uString_getLength(superTypeName) == 0
+ ? 0 : 1;
+ TypeWriterImpl t = typereg_writer_create(
+ TYPEREG_VERSION_0, empty.pData, empty.pData, typeClass, false, typeName,
+ superTypeCount, fieldCount, 0/*methodCount*/, 0/*referenceCount*/);
+ if (superTypeCount > 0) {
+ typereg_writer_setSuperTypeName(t, 0, superTypeName);
+ }
+ return t;
+}
+
+}
+
+RegistryTypeWriter::RegistryTypeWriter(RTTypeClass RTTypeClass,
+ const OUString& typeName,
+ const OUString& superTypeName,
+ sal_uInt16 fieldCount)
+ : m_hImpl(nullptr)
+{
+ m_hImpl = createEntry(RTTypeClass,
+ typeName.pData,
+ superTypeName.pData,
+ fieldCount);
+}
+
+RegistryTypeWriter::~RegistryTypeWriter()
+{
+ release(m_hImpl);
+}
+
+void RegistryTypeWriter::setFieldData( sal_uInt16 index,
+ const OUString& name,
+ const OUString& typeName,
+ const OUString& doku,
+ const OUString& fileName,
+ RTFieldAccess access,
+ const RTConstValue& constValue)
+{
+ ::setFieldData(m_hImpl, index, name.pData, typeName.pData, doku.pData, fileName.pData, access, constValue.m_type, constValue.m_value);
+}
+
+const sal_uInt8* RegistryTypeWriter::getBlop()
+{
+ return ::getBlop(m_hImpl);
+}
+
+sal_uInt32 RegistryTypeWriter::getBlopSize()
+{
+ return ::getBlopSize(m_hImpl);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/reflwrit.hxx b/registry/source/reflwrit.hxx
new file mode 100644
index 000000000..93cee0697
--- /dev/null
+++ b/registry/source/reflwrit.hxx
@@ -0,0 +1,103 @@
+/* -*- 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_REFLWRIT_HXX
+#define INCLUDED_REGISTRY_SOURCE_REFLWRIT_HXX
+
+#include <registry/types.hxx>
+#include <rtl/ustring.hxx>
+
+class RTConstValue;
+
+/// Implementation handle
+typedef void* TypeWriterImpl;
+
+/** RegistryTypeWriter writes/creates a binary type blob.
+
+ This class provides the necessary functions to write type information
+ for all kinds of types into a blob.
+
+ @deprecated
+ use typereg::Writer instead
+*/
+class RegistryTypeWriter
+{
+public:
+
+ /** Constructor.
+
+ @param RTTypeClass specifies the type of the new blob.
+ @param typeName specifies the full qualified type name with '/' as separator.
+ @param superTypeName specifies the full qualified type name of the base type
+ with '/' as separator.
+ @param fieldCount specifies the number of fields (eg. number of attributes/properties,
+ enum values or constants).
+ */
+ RegistryTypeWriter(RTTypeClass RTTypeClass,
+ const OUString& typeName,
+ const OUString& superTypeName,
+ sal_uInt16 fieldCount);
+
+ /** Destructor. The Destructor frees the internal data block.
+
+ The pointer (returned by getBlop) will be set to NULL.
+ */
+ ~RegistryTypeWriter();
+
+ /** sets the data for a field member of a type blob.
+
+ @param index indicates the index of the field.
+ @param name specifies the name.
+ @param typeName specifies the full qualified typename.
+ @param doku specifies the documentation string of the field.
+ @param fileName specifies the name of the IDL file where the field is defined.
+ @param access specifies the access mode of the field.
+ @param constValue specifies the value of the field. The value is only interesting
+ for enum values or constants.
+ */
+ void setFieldData( sal_uInt16 index,
+ const OUString& name,
+ const OUString& typeName,
+ const OUString& doku,
+ const OUString& fileName,
+ RTFieldAccess access,
+ const RTConstValue& constValue);
+
+ /** returns a pointer to the new type blob.
+
+ The pointer will be invalid (NULL) if the instance of
+ the RegistryTypeWriter will be destroyed.
+ */
+ const sal_uInt8* getBlop();
+
+ /** returns the size of the new type blob in bytes.
+ */
+ sal_uInt32 getBlopSize();
+
+private:
+ RegistryTypeWriter(RegistryTypeWriter const &) = delete;
+ void operator =(RegistryTypeWriter const &) = delete;
+
+ /// stores the handle of an implementation class
+ TypeWriterImpl m_hImpl;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/regimpl.cxx b/registry/source/regimpl.cxx
new file mode 100644
index 000000000..e58e99b4c
--- /dev/null
+++ b/registry/source/regimpl.cxx
@@ -0,0 +1,1576 @@
+/* -*- 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 <memory>
+#include <set>
+#include <vector>
+#include <string.h>
+#include <stdio.h>
+
+#if defined(UNX)
+#include <unistd.h>
+#endif
+
+#include "reflread.hxx"
+
+#include "reflwrit.hxx"
+
+#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(OUString const & s) {
+ printf("\"");
+ for (sal_Int32 i = 0; i < s.getLength(); ++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, const OUString& keyName,
+ RegKeyHandle* phNewKey)
+{
+ ORegKey* pKey;
+
+ *phNewKey = nullptr;
+
+ if (keyName.isEmpty())
+ 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.getStr(), token, storeAccessMode::Create))
+ {
+ return RegError::CREATE_KEY_FAILED;
+ }
+
+ sFullPath.append(token);
+ sFullPath.append('/');
+ }
+ } while(nIndex != -1);
+
+
+ pKey = new ORegKey(sFullKeyName, this);
+ *phNewKey = pKey;
+ m_openKeyTable[sFullKeyName] = pKey;
+
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName,
+ RegKeyHandle* phOpenKey)
+{
+ ORegKey* pKey;
+
+ *phOpenKey = nullptr;
+
+ if (keyName.isEmpty())
+ {
+ 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;
+ 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, const OUString& keyName)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (keyName.isEmpty())
+ 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, const OUString& keyName)
+{
+ RegError _ret = RegError::NO_ERROR;
+
+ if (keyName.isEmpty())
+ {
+ return RegError::INVALID_KEYNAME;
+ }
+
+ OUString sFullKeyName(pKey->getName());
+ OUString sFullPath(sFullKeyName);
+ OUString sRelativKey;
+ sal_Int32 lastIndex = keyName.lastIndexOf('/');
+
+ if (lastIndex >= 0)
+ {
+ sRelativKey += keyName.copy(lastIndex + 1);
+
+ if (sFullKeyName.getLength() > 1)
+ sFullKeyName += keyName;
+ else
+ sFullKeyName += keyName.copy(1);
+
+ sFullPath = sFullKeyName.copy(0, keyName.lastIndexOf('/') + 1);
+ } else
+ {
+ if (sFullKeyName.getLength() > 1)
+ sFullKeyName += ROOT;
+
+ sRelativKey += keyName;
+ sFullKeyName += keyName;
+
+ if (sFullPath.getLength() > 1)
+ sFullPath += ROOT;
+ }
+
+ 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;
+
+ 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;
+}
+
+RegError ORegistry::loadKey(RegKeyHandle hKey, const OUString& regFileName,
+ bool bWarnings, bool bReport)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+
+ std::unique_ptr< ORegistry > pReg (new ORegistry());
+ RegError _ret = pReg->initRegistry(regFileName, RegAccessMode::READONLY);
+ if (_ret != RegError::NO_ERROR)
+ return _ret;
+ ORegKey* pRootKey = pReg->getRootKey();
+
+ REG_GUARD(m_mutex);
+
+ OStoreDirectory::iterator iter;
+ OStoreDirectory rStoreDir(pRootKey->getStoreDir());
+ storeError _err = rStoreDir.first(iter);
+
+ while (_err == store_E_None)
+ {
+ OUString const keyName = iter.m_pszName;
+
+ if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
+ {
+ _ret = loadAndSaveKeys(pKey, pRootKey, keyName, 0, bWarnings, bReport);
+ }
+ else
+ {
+ _ret = loadAndSaveValue(pKey, pRootKey, keyName, 0, bWarnings, bReport);
+ }
+
+ if (_ret == RegError::MERGE_ERROR)
+ break;
+ if (_ret == RegError::MERGE_CONFLICT && bWarnings)
+ break;
+
+ _err = rStoreDir.next(iter);
+ }
+
+ rStoreDir = OStoreDirectory();
+ (void) pReg->releaseKey(pRootKey);
+ return _ret;
+}
+
+RegError ORegistry::loadAndSaveValue(ORegKey* pTargetKey,
+ ORegKey const * pSourceKey,
+ const OUString& valueName,
+ sal_uInt32 nCut,
+ bool bWarnings,
+ bool bReport)
+{
+ OStoreStream rValue;
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+ sal_uInt32 nSize;
+ storeAccessMode sourceAccess = storeAccessMode::ReadWrite;
+ OUString sTargetPath(pTargetKey->getName());
+ OUString sSourcePath(pSourceKey->getName());
+
+ if (pSourceKey->isReadOnly())
+ {
+ sourceAccess = storeAccessMode::ReadOnly;
+ }
+
+ if (nCut)
+ {
+ sTargetPath = sSourcePath.copy(nCut);
+ } else
+ {
+ if (sTargetPath.getLength() > 1)
+ {
+ if (sSourcePath.getLength() > 1)
+ sTargetPath += sSourcePath;
+ } else
+ sTargetPath = sSourcePath;
+ }
+
+ if (sTargetPath.getLength() > 1) sTargetPath += ROOT;
+ if (sSourcePath.getLength() > 1) sSourcePath += ROOT;
+
+ if (rValue.create(pSourceKey->getStoreFile(), sSourcePath, valueName, sourceAccess))
+ {
+ return 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;
+ }
+
+ RegError _ret = RegError::NO_ERROR;
+ sal_uInt8 type = aBuffer[0];
+ valueType = static_cast<RegValueType>(type);
+ readUINT32(aBuffer.data() + VALUE_TYPEOFFSET, valueSize);
+
+ nSize = VALUE_HEADERSIZE + valueSize;
+ aBuffer.resize(nSize);
+
+ if (rValue.readAt(0, aBuffer.data(), nSize, rwBytes))
+ {
+ return RegError::INVALID_VALUE;
+ }
+ if (rwBytes != nSize)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ OStoreFile rTargetFile(pTargetKey->getStoreFile());
+
+ if (!rValue.create(rTargetFile, sTargetPath, valueName, storeAccessMode::ReadWrite))
+ {
+ if (valueType == RegValueType::BINARY)
+ {
+ _ret = checkBlop(
+ rValue, sTargetPath, valueSize, aBuffer.data() + VALUE_HEADEROFFSET,
+ bReport);
+ if (_ret != RegError::NO_ERROR)
+ {
+ if (_ret == RegError::MERGE_ERROR ||
+ (_ret == RegError::MERGE_CONFLICT && bWarnings))
+ {
+ return _ret;
+ }
+ } else
+ {
+ return _ret;
+ }
+ }
+ }
+
+ if (rValue.create(rTargetFile, sTargetPath, valueName, storeAccessMode::Create))
+ {
+ return RegError::INVALID_VALUE;
+ }
+ if (rValue.writeAt(0, aBuffer.data(), nSize, rwBytes))
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ if (rwBytes != nSize)
+ {
+ return RegError::INVALID_VALUE;
+ }
+ pTargetKey->setModified();
+
+ return _ret;
+}
+
+RegError ORegistry::checkBlop(OStoreStream& rValue,
+ const OUString& sTargetPath,
+ sal_uInt32 srcValueSize,
+ sal_uInt8 const * pSrcBuffer,
+ bool bReport)
+{
+ RegistryTypeReader reader(pSrcBuffer, srcValueSize);
+
+ if (reader.getTypeClass() == RT_TYPE_INVALID)
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ std::vector<sal_uInt8> aBuffer(VALUE_HEADERSIZE);
+ RegValueType valueType;
+ sal_uInt32 valueSize;
+ sal_uInt32 rwBytes;
+ OString targetPath(OUStringToOString(sTargetPath, RTL_TEXTENCODING_UTF8));
+
+ if (!rValue.readAt(0, aBuffer.data(), VALUE_HEADERSIZE, rwBytes) &&
+ (rwBytes == VALUE_HEADERSIZE))
+ {
+ sal_uInt8 type = aBuffer[0];
+ valueType = static_cast<RegValueType>(type);
+ readUINT32(aBuffer.data() + VALUE_TYPEOFFSET, valueSize);
+
+ if (valueType == RegValueType::BINARY)
+ {
+ aBuffer.resize(valueSize);
+ if (!rValue.readAt(VALUE_HEADEROFFSET, aBuffer.data(), valueSize, rwBytes) &&
+ (rwBytes == valueSize))
+ {
+ RegistryTypeReader reader2(aBuffer.data(), valueSize);
+
+ if ((reader.getTypeClass() != reader2.getTypeClass())
+ || reader2.getTypeClass() == RT_TYPE_INVALID)
+ {
+ if (bReport)
+ {
+ fprintf(stdout, "ERROR: values of blop from key \"%s\" has different types.\n",
+ targetPath.getStr());
+ }
+ return RegError::MERGE_ERROR;
+ }
+
+ if (reader.getTypeClass() == RT_TYPE_MODULE)
+ {
+ if (reader.getFieldCount() > 0 &&
+ reader2.getFieldCount() > 0)
+ {
+ mergeModuleValue(rValue, reader, reader2);
+
+ return RegError::NO_ERROR;
+ } else
+ if (reader2.getFieldCount() > 0)
+ {
+ return RegError::NO_ERROR;
+ } else
+ {
+ return RegError::MERGE_CONFLICT;
+ }
+ } else
+ {
+ if (bReport)
+ {
+ fprintf(stderr, "WARNING: value of key \"%s\" already exists.\n",
+ targetPath.getStr());
+ }
+ return RegError::MERGE_CONFLICT;
+ }
+ } else
+ {
+ if (bReport)
+ {
+ fprintf(stderr, "ERROR: values of key \"%s\" contains bad data.\n",
+ targetPath.getStr());
+ }
+ return RegError::MERGE_ERROR;
+ }
+ } else
+ {
+ if (bReport)
+ {
+ fprintf(stderr, "ERROR: values of key \"%s\" has different types.\n",
+ targetPath.getStr());
+ }
+ return RegError::MERGE_ERROR;
+ }
+ } else
+ {
+ return RegError::INVALID_VALUE;
+ }
+}
+
+static sal_uInt32 checkTypeReaders(RegistryTypeReader const & reader1,
+ RegistryTypeReader const & reader2,
+ std::set< OUString >& nameSet)
+{
+ sal_uInt32 count=0;
+ for (sal_uInt32 i=0 ; i < reader1.getFieldCount(); i++)
+ {
+ nameSet.insert(reader1.getFieldName(i));
+ count++;
+ }
+ for (sal_uInt32 i=0 ; i < reader2.getFieldCount(); i++)
+ {
+ if (nameSet.insert(reader2.getFieldName(i)).second)
+ count++;
+ }
+ return count;
+}
+
+RegError ORegistry::mergeModuleValue(OStoreStream& rTargetValue,
+ RegistryTypeReader const & reader,
+ RegistryTypeReader const & reader2)
+{
+ std::set< OUString > nameSet;
+ sal_uInt32 count = checkTypeReaders(reader, reader2, nameSet);
+
+ if (count != reader.getFieldCount())
+ {
+ sal_uInt16 index = 0;
+
+ RegistryTypeWriter writer(reader.getTypeClass(),
+ reader.getTypeName(),
+ reader.getSuperTypeName(),
+ static_cast<sal_uInt16>(count));
+
+ for (sal_uInt32 i=0 ; i < reader.getFieldCount(); i++)
+ {
+ writer.setFieldData(index,
+ reader.getFieldName(i),
+ reader.getFieldType(i),
+ reader.getFieldDoku(i),
+ reader.getFieldFileName(i),
+ reader.getFieldAccess(i),
+ reader.getFieldConstValue(i));
+ index++;
+ }
+ for (sal_uInt32 i=0 ; i < reader2.getFieldCount(); i++)
+ {
+ if (nameSet.find(reader2.getFieldName(i)) == nameSet.end())
+ {
+ writer.setFieldData(index,
+ reader2.getFieldName(i),
+ reader2.getFieldType(i),
+ reader2.getFieldDoku(i),
+ reader2.getFieldFileName(i),
+ reader2.getFieldAccess(i),
+ reader2.getFieldConstValue(i));
+ index++;
+ }
+ }
+
+ const sal_uInt8* pBlop = writer.getBlop();
+ sal_uInt32 aBlopSize = writer.getBlopSize();
+
+ sal_uInt8 type = sal_uInt8(RegValueType::BINARY);
+ std::vector<sal_uInt8> aBuffer(VALUE_HEADERSIZE + aBlopSize);
+
+ memcpy(aBuffer.data(), &type, 1);
+ writeUINT32(aBuffer.data() + VALUE_TYPEOFFSET, aBlopSize);
+ memcpy(aBuffer.data() + VALUE_HEADEROFFSET, pBlop, aBlopSize);
+
+ sal_uInt32 rwBytes;
+ if (rTargetValue.writeAt(0, aBuffer.data(), VALUE_HEADERSIZE+aBlopSize, rwBytes))
+ {
+ return RegError::INVALID_VALUE;
+ }
+
+ if (rwBytes != VALUE_HEADERSIZE+aBlopSize)
+ {
+ return RegError::INVALID_VALUE;
+ }
+ }
+ return RegError::NO_ERROR;
+}
+
+RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey,
+ ORegKey* pSourceKey,
+ const OUString& keyName,
+ sal_uInt32 nCut,
+ bool bWarnings,
+ bool bReport)
+{
+ RegError _ret = RegError::NO_ERROR;
+ OUString sRelPath(pSourceKey->getName().copy(nCut));
+ OUString sFullPath;
+
+ if(pTargetKey->getName().getLength() > 1)
+ sFullPath += pTargetKey->getName();
+ sFullPath += sRelPath;
+ if (sRelPath.getLength() > 1 || sFullPath.isEmpty())
+ sFullPath += ROOT;
+
+ OUString sFullKeyName = sFullPath + keyName;
+
+ OStoreDirectory rStoreDir;
+ if (rStoreDir.create(pTargetKey->getStoreFile(), sFullPath, keyName, storeAccessMode::Create))
+ {
+ return RegError::CREATE_KEY_FAILED;
+ }
+
+ if (m_openKeyTable.count(sFullKeyName) > 0)
+ {
+ m_openKeyTable[sFullKeyName]->setDeleted(false);
+ }
+
+ ORegKey* pTmpKey = nullptr;
+ _ret = pSourceKey->openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pTmpKey));
+ if (_ret != RegError::NO_ERROR)
+ return _ret;
+
+ OStoreDirectory::iterator iter;
+ OStoreDirectory rTmpStoreDir(pTmpKey->getStoreDir());
+ storeError _err = rTmpStoreDir.first(iter);
+
+ while (_err == store_E_None)
+ {
+ OUString const sName = iter.m_pszName;
+
+ if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
+ {
+ _ret = loadAndSaveKeys(pTargetKey, pTmpKey,
+ sName, nCut, bWarnings, bReport);
+ } else
+ {
+ _ret = loadAndSaveValue(pTargetKey, pTmpKey,
+ sName, nCut, bWarnings, bReport);
+ }
+
+ if (_ret == RegError::MERGE_ERROR)
+ break;
+ if (_ret == RegError::MERGE_CONFLICT && bWarnings)
+ break;
+
+ _err = rTmpStoreDir.next(iter);
+ }
+
+ pSourceKey->releaseKey(pTmpKey);
+ return _ret;
+}
+
+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 = iter.m_pszName;
+
+ if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
+ {
+ _ret = dumpKey(pKey->getName(), sName, 1);
+ } else
+ {
+ _ret = dumpValue(pKey->getName(), sName, 1);
+ }
+
+ if (_ret != 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 = OUStringToOString(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 = OUStringToOString(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 = iter.m_pszName;
+
+ if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
+ {
+ _ret = dumpKey(sSubPath, sSubName, nSpace+2);
+ } else
+ {
+ _ret = dumpValue(sSubPath, sSubName, nSpace+2);
+ }
+
+ if (_ret != 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 000000000..d8a77394f
--- /dev/null
+++ b/registry/source/regimpl.hxx
@@ -0,0 +1,153 @@
+/* -*- 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_REGIMPL_HXX
+#define INCLUDED_REGISTRY_SOURCE_REGIMPL_HXX
+
+#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 RegistryTypeReader;
+
+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,
+ const OUString& keyName,
+ RegKeyHandle* phNewKey);
+
+ RegError openKey(RegKeyHandle hKey,
+ const OUString& keyName,
+ RegKeyHandle* phOpenKey);
+
+ RegError closeKey(RegKeyHandle hKey);
+
+ RegError deleteKey(RegKeyHandle hKey, const OUString& keyName);
+
+ RegError loadKey(RegKeyHandle hKey,
+ const OUString& regFileName,
+ bool bWarnings,
+ bool bReport);
+
+ 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, const OUString& keyName);
+
+ RegError deleteSubkeysAndValues(ORegKey* pKey);
+
+ static RegError loadAndSaveValue(ORegKey* pTargetKey,
+ ORegKey const * pSourceKey,
+ const OUString& valueName,
+ sal_uInt32 nCut,
+ bool bWarnings,
+ bool bReport);
+
+ static RegError checkBlop(store::OStoreStream& rValue,
+ const OUString& sTargetPath,
+ sal_uInt32 srcValueSize,
+ sal_uInt8 const * pSrcBuffer,
+ bool bReport);
+
+ static RegError mergeModuleValue(store::OStoreStream& rTargetValue,
+ RegistryTypeReader const & reader,
+ RegistryTypeReader const & reader2);
+
+ RegError loadAndSaveKeys(ORegKey* pTargetKey,
+ ORegKey* pSourceKey,
+ const OUString& keyName,
+ sal_uInt32 nCut,
+ bool bWarnings,
+ bool bReport);
+
+ 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 OUStringLiteral ROOT { "/" };
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/registry.cxx b/registry/source/registry.cxx
new file mode 100644
index 000000000..166354aa5
--- /dev/null
+++ b/registry/source/registry.cxx
@@ -0,0 +1,397 @@
+/* -*- 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" {
+
+
+// acquire
+
+static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
+{
+ ORegistry* pReg = static_cast<ORegistry*>(hReg);
+
+ if (pReg != nullptr)
+ pReg->acquire();
+}
+
+
+// release
+
+static void REGISTRY_CALLTYPE release(RegHandle hReg)
+{
+ ORegistry* pReg = static_cast<ORegistry*>(hReg);
+
+ if (pReg && pReg->release() == 0)
+ {
+ delete pReg;
+ hReg = nullptr;
+ }
+}
+
+
+// getName
+
+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;
+}
+
+
+// isReadOnly
+
+static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
+{
+ if (hReg)
+ return static_cast<ORegistry*>(hReg)->isReadOnly();
+ else
+ return false;
+}
+
+
+// createRegistry
+
+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;
+}
+
+
+// openRootKey
+
+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;
+}
+
+
+// openRegistry
+
+static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
+ RegHandle* phRegistry,
+ RegAccessMode accessMode)
+{
+ RegError _ret;
+
+ ORegistry* pReg = new ORegistry();
+ if ((_ret = pReg->initRegistry(registryName, accessMode)) != RegError::NO_ERROR)
+ {
+ *phRegistry = nullptr;
+ delete pReg;
+ return _ret;
+ }
+
+
+ *phRegistry = pReg;
+
+ return RegError::NO_ERROR;
+}
+
+
+// closeRegistry
+
+static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
+{
+ ORegistry *pReg;
+
+ if (hReg)
+ {
+ 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;
+ }
+}
+
+
+// destroyRegistry
+
+static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg,
+ rtl_uString* registryName)
+{
+ ORegistry *pReg;
+
+ if (hReg)
+ {
+ 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;
+ }
+}
+
+
+// mergeKey
+
+static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg,
+ RegKeyHandle hKey,
+ rtl_uString* keyName,
+ rtl_uString* regFileName,
+ sal_Bool bWarnings,
+ sal_Bool bReport)
+{
+ 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;
+ if (pKey->isReadOnly())
+ return RegError::REGISTRY_READONLY;
+
+ if (keyName->length)
+ {
+ ORegKey* pNewKey = nullptr;
+ RegError _ret = pKey->createKey(keyName, reinterpret_cast<RegKeyHandle*>(&pNewKey));
+ if (_ret != RegError::NO_ERROR)
+ return _ret;
+
+ _ret = pReg->loadKey(pNewKey, regFileName, bWarnings, bReport);
+ if (_ret != RegError::NO_ERROR && (_ret != RegError::MERGE_CONFLICT || bWarnings))
+ {
+ if (pNewKey != pKey)
+ (void) pKey->closeKey(pNewKey);
+ else
+ (void) pKey->releaseKey(pNewKey);
+ return _ret;
+ }
+
+ return (pNewKey != pKey) ? pKey->closeKey(pNewKey) : pKey->releaseKey(pNewKey);
+ }
+
+ return pReg->loadKey(pKey, regFileName, bWarnings, bReport);
+}
+
+
+// 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);
+}
+
+
+// initRegistry_Api
+
+Registry_Api* REGISTRY_CALLTYPE initRegistry_Api()
+{
+ static Registry_Api aApi= {&acquire,
+ &release,
+ &isReadOnly,
+ &openRootKey,
+ &getName,
+ &createRegistry,
+ &openRegistry,
+ &closeRegistry,
+ &destroyRegistry,
+ &mergeKey,
+ &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);
+}
+
+}
+
+
+// reg_openRootKey
+
+RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
+ RegKeyHandle* phRootKey)
+{
+ return openRootKey(hRegistry, phRootKey);
+}
+
+
+// reg_openRegistry
+
+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;
+}
+
+
+// reg_closeRegistry
+
+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;
+ }
+}
+
+
+// reg_dumpRegistry
+
+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 000000000..55b0bc809
--- /dev/null
+++ b/registry/source/regkey.cxx
@@ -0,0 +1,694 @@
+/* -*- 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"
+
+
+// acquireKey
+
+void REGISTRY_CALLTYPE acquireKey(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (pKey != nullptr)
+ {
+ ORegistry* pReg = pKey->getRegistry();
+ (void) pReg->acquireKey(pKey);
+ }
+}
+
+
+// releaseKey
+
+void REGISTRY_CALLTYPE releaseKey(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (pKey != nullptr)
+ {
+ ORegistry* pReg = pKey->getRegistry();
+ (void) pReg->releaseKey(pKey);
+ }
+}
+
+
+// isKeyReadOnly
+
+sal_Bool REGISTRY_CALLTYPE isKeyReadOnly(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ return pKey != nullptr && pKey->isReadOnly();
+}
+
+
+// getKeyName
+
+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;
+ }
+}
+
+
+// createKey
+
+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(keyName, phNewKey);
+}
+
+
+// openKey
+
+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(keyName, phOpenKey);
+}
+
+
+// openSubKeys
+
+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(keyName, pphSubKeys, pnSubKeys);
+}
+
+
+// closeSubKeys
+
+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;
+}
+
+
+// deleteKey
+
+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(keyName);
+}
+
+
+// closeKey
+
+RegError REGISTRY_CALLTYPE closeKey(RegKeyHandle hKey)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ return pKey->closeKey(hKey);
+}
+
+
+// setValue
+
+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(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);
+}
+
+
+// setLongValueList
+
+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(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);
+}
+
+
+// setStringValueList
+
+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(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);
+}
+
+
+// setUnicodeValueList
+
+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(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);
+}
+
+
+// getValueInfo
+
+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(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;
+}
+
+
+// getValueInfo
+
+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(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);
+}
+
+
+// getLongValueList
+
+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(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);
+}
+
+
+// getStringValueList
+
+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(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);
+}
+
+// getUnicodeListValue
+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(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);
+}
+
+
+// freeValueList
+
+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;
+}
+
+
+// getName
+
+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(keyName, resolvedName);
+ if (_ret == RegError::NO_ERROR)
+ rtl_uString_assign(pResolvedName, resolvedName.pData);
+ return _ret;
+}
+
+
+// getKeyNames
+
+RegError REGISTRY_CALLTYPE getKeyNames(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ rtl_uString*** pSubKeyNames,
+ sal_uInt32* pnSubKeys)
+{
+ ORegKey* pKey = static_cast< ORegKey* >(hKey);
+ if (!pKey)
+ return RegError::INVALID_KEY;
+
+ if (pKey->isDeleted())
+ return RegError::INVALID_KEY;
+
+ return pKey->getKeyNames(keyName, pSubKeyNames, pnSubKeys);
+}
+
+
+// freeKeyNames
+
+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;
+}
+
+
+// C API
+
+
+// reg_openKey
+
+RegError REGISTRY_CALLTYPE reg_openKey(RegKeyHandle hKey,
+ rtl_uString* keyName,
+ RegKeyHandle* phOpenKey)
+{
+ if (!hKey)
+ return RegError::INVALID_KEY;
+
+ return openKey(hKey, keyName, phOpenKey);
+}
+
+
+// reg_closeKey
+
+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 000000000..76e8c2993
--- /dev/null
+++ b/registry/source/regkey.hxx
@@ -0,0 +1,69 @@
+/* -*- 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_REGKEY_HXX
+#define INCLUDED_REGISTRY_SOURCE_REGKEY_HXX
+
+#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);
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/test/makefile.mk b/registry/test/makefile.mk
new file mode 100644
index 000000000..f6d99120f
--- /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/regcompare/other1.idl b/registry/test/regcompare/other1.idl
new file mode 100644
index 000000000..75473015b
--- /dev/null
+++ b/registry/test/regcompare/other1.idl
@@ -0,0 +1 @@
+module M { enum X { V }; };
diff --git a/registry/test/regcompare/other2.idl b/registry/test/regcompare/other2.idl
new file mode 100644
index 000000000..f6c94ef66
--- /dev/null
+++ b/registry/test/regcompare/other2.idl
@@ -0,0 +1 @@
+enum X { V };
diff --git a/registry/test/regcompare/pe.idl b/registry/test/regcompare/pe.idl
new file mode 100644
index 000000000..c597b29f0
--- /dev/null
+++ b/registry/test/regcompare/pe.idl
@@ -0,0 +1 @@
+module M { published enum N { V }; };
diff --git a/registry/test/regcompare/psa.idl b/registry/test/regcompare/psa.idl
new file mode 100644
index 000000000..b8079c9ad
--- /dev/null
+++ b/registry/test/regcompare/psa.idl
@@ -0,0 +1 @@
+module M { published struct N { long m; }; };
diff --git a/registry/test/regcompare/psb.idl b/registry/test/regcompare/psb.idl
new file mode 100644
index 000000000..03d02b302
--- /dev/null
+++ b/registry/test/regcompare/psb.idl
@@ -0,0 +1 @@
+module M { published struct N { short m; }; };
diff --git a/registry/test/regcompare/ue.idl b/registry/test/regcompare/ue.idl
new file mode 100644
index 000000000..0face3356
--- /dev/null
+++ b/registry/test/regcompare/ue.idl
@@ -0,0 +1 @@
+module M { enum N { V }; };
diff --git a/registry/test/regcompare/usa.idl b/registry/test/regcompare/usa.idl
new file mode 100644
index 000000000..80fe2c2f4
--- /dev/null
+++ b/registry/test/regcompare/usa.idl
@@ -0,0 +1 @@
+module M { struct N { long m; }; };
diff --git a/registry/test/regcompare/usb.idl b/registry/test/regcompare/usb.idl
new file mode 100644
index 000000000..08e7e9daa
--- /dev/null
+++ b/registry/test/regcompare/usb.idl
@@ -0,0 +1 @@
+module M { struct N { short m; }; };
diff --git a/registry/test/regdiagnose.h b/registry/test/regdiagnose.h
new file mode 100644
index 000000000..9d4562d9e
--- /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 000000000..2e8cbbcc5
--- /dev/null
+++ b/registry/test/testmerge.cxx
@@ -0,0 +1,408 @@
+/* -*- 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>
+
+
+using namespace std;
+
+
+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;
+
+ 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;
+
+ 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;
+
+ 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 000000000..8b9531194
--- /dev/null
+++ b/registry/test/testregcpp.cxx
@@ -0,0 +1,698 @@
+/* -*- 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>
+
+using namespace std;
+
+
+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;
+
+ 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);
+
+ 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 000000000..dec3be5e5
--- /dev/null
+++ b/registry/tools/fileurl.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 "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)
+ {
+ 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 000000000..684ca8c3c
--- /dev/null
+++ b/registry/tools/fileurl.hxx
@@ -0,0 +1,37 @@
+/* -*- 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
+{
+namespace tools
+{
+
+OUString convertToFileUrl(char const * filename, sal_Int32 length);
+
+} // namespace tools
+} // namespace registry
+
+#endif /* INCLUDED_REGISTRY_TOOLS_FILEURL_HXX */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/tools/options.cxx b/registry/tools/options.cxx
new file mode 100644
index 000000000..81d1131f7
--- /dev/null
+++ b/registry/tools/options.cxx
@@ -0,0 +1,144 @@
+/* -*- 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 "options.hxx"
+
+#include <osl/diagnose.h>
+
+#include <stdio.h>
+
+namespace registry::tools
+{
+
+Options::Options (char const * program)
+ : m_program (program)
+{}
+
+Options::~Options()
+{}
+
+// static
+bool Options::checkArgument(std::vector< std::string> & rArgs, char const * arg, size_t len)
+{
+ bool result = ((arg != nullptr) && (len > 0));
+ OSL_PRECOND(result, "registry::tools::Options::checkArgument(): invalid arguments");
+ if (result)
+ {
+ switch (arg[0])
+ {
+ case '@':
+ result = len > 1;
+ if (result)
+ {
+ // "@<cmdfile>"
+ result = Options::checkCommandFile(rArgs, &(arg[1]));
+ }
+ break;
+ case '-':
+ result = len > 1;
+ if (result)
+ {
+ // "-<option>"
+ std::string option (&(arg[0]), 2);
+ rArgs.push_back(option);
+ if (len > 2)
+ {
+ // "-<option><param>"
+ std::string param(&(arg[2]), len - 2);
+ rArgs.push_back(param);
+ }
+ }
+ break;
+ default:
+ rArgs.push_back(std::string(arg, len));
+ break;
+ }
+ }
+ return result;
+}
+
+// static
+bool Options::checkCommandFile(std::vector< std::string > & rArgs, char const * filename)
+{
+ FILE * fp = fopen(filename, "r");
+ if (fp == nullptr)
+ {
+ fprintf(stderr, "ERROR: Can't open command file \"%s\"\n", filename);
+ return false;
+ }
+
+ std::string buffer;
+ buffer.reserve(256);
+
+ bool quoted = false;
+ int c = EOF;
+ while ((c = fgetc(fp)) != EOF)
+ {
+ switch(c)
+ {
+ case '\"':
+ quoted = !quoted;
+ break;
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ if (!quoted)
+ {
+ if (!buffer.empty())
+ {
+ if (!checkArgument(rArgs, buffer.c_str(), buffer.size()))
+ {
+ // failure.
+ (void) fclose(fp);
+ return false;
+ }
+ buffer.clear();
+ }
+ break;
+ }
+ [[fallthrough]];
+ default:
+ buffer.push_back(sal::static_int_cast<char>(c));
+ break;
+ }
+ }
+ return fclose(fp) == 0;
+}
+
+bool Options::initOptions (std::vector< std::string > & rArgs)
+{
+ return initOptions_Impl (rArgs);
+}
+
+bool Options::badOption (char const * reason, char const * option) const
+{
+ (void) fprintf(stderr, "%s: %s option '%s'\n", m_program.c_str(), reason, option);
+ return printUsage();
+}
+
+bool Options::printUsage() const
+{
+ printUsage_Impl();
+ return false;
+}
+
+} // namespace registry::tools
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/tools/options.hxx b/registry/tools/options.hxx
new file mode 100644
index 000000000..a0ae71b49
--- /dev/null
+++ b/registry/tools/options.hxx
@@ -0,0 +1,60 @@
+/* -*- 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_OPTIONS_HXX
+#define INCLUDED_REGISTRY_TOOLS_OPTIONS_HXX
+
+#include <string>
+#include <vector>
+
+namespace registry
+{
+namespace tools
+{
+class Options
+{
+ std::string m_program;
+
+ Options (Options const &) = delete;
+ Options & operator= (Options const &) = delete;
+
+public:
+ explicit Options (char const * program);
+ virtual ~Options();
+
+ static bool checkArgument (std::vector< std::string > & rArgs, char const * arg, size_t len);
+
+ bool initOptions (std::vector< std::string > & rArgs);
+ bool badOption (char const * reason, char const * option) const;
+
+ bool printUsage() const;
+
+protected:
+ static bool checkCommandFile(std::vector< std::string > & rArgs, char const * filename);
+
+ virtual bool initOptions_Impl(std::vector< std::string > & rArgs) = 0;
+ virtual void printUsage_Impl() const = 0;
+};
+
+} // namespace tools
+} // namespace registry
+
+#endif /* INCLUDED_REGISTRY_TOOLS_OPTIONS_HXX */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/tools/regmerge.cxx b/registry/tools/regmerge.cxx
new file mode 100644
index 000000000..409773a70
--- /dev/null
+++ b/registry/tools/regmerge.cxx
@@ -0,0 +1,183 @@
+/* -*- 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 "fileurl.hxx"
+#include "options.hxx"
+
+#include <rtl/ustring.hxx>
+#include <sal/log.hxx>
+
+#include <stdio.h>
+#include <string.h>
+
+using namespace registry::tools;
+
+namespace {
+
+class Options_Impl : public Options
+{
+ bool m_bVerbose;
+
+public:
+ explicit Options_Impl (char const * program)
+ : Options(program), m_bVerbose(false)
+ {}
+ bool isVerbose() const { return m_bVerbose; }
+
+protected:
+ virtual void printUsage_Impl() const override;
+ virtual bool initOptions_Impl(std::vector< std::string > & rArgs) override;
+};
+
+}
+
+void Options_Impl::printUsage_Impl() const
+{
+ fprintf(stderr, "using: regmerge [-v|--verbose] mergefile mergeKeyName regfile_1 ... regfile_n\n");
+ fprintf(stderr, " regmerge @regcmds\nOptions:\n");
+ fprintf(stderr, " -v, --verbose : verbose output on stdout.\n");
+ fprintf(stderr, " mergefile : specifies the merged registry file. If this file doesn't exists,\n");
+ fprintf(stderr, " it is created.\n");
+ fprintf(stderr, " mergeKeyName : specifies the merge key, everything is merged under this key.\n");
+ fprintf(stderr, " If this key doesn't exists, it is created.\n");
+ fprintf(stderr, " regfile_1..n : specifies one or more registry files which are merged.\n");
+}
+
+bool Options_Impl::initOptions_Impl (std::vector< std::string > & rArgs)
+{
+ std::vector< std::string >::iterator first = rArgs.begin(), last = rArgs.end();
+ if ((first != last) && ((*first)[0] == '-'))
+ {
+ std::string option(*first);
+ if ((option.compare("-v") == 0) || (option.compare("--verbose") == 0))
+ {
+ m_bVerbose = true;
+ }
+ else if ((option.compare("-h") == 0) || (option.compare("-?") == 0))
+ {
+ return printUsage();
+ }
+ else
+ {
+ return badOption("unknown", option.c_str());
+ }
+ (void) rArgs.erase(first);
+ }
+ return true;
+}
+
+#if (defined UNX)
+int main( int argc, char * argv[] )
+#else
+int __cdecl main( int argc, char * argv[] )
+#endif
+{
+ try
+ {
+ Options_Impl options(argv[0]);
+
+ std::vector< std::string > args;
+ for (int i = 1; i < argc; i++)
+ {
+ if (!Options::checkArgument(args, argv[i], strlen(argv[i])))
+ {
+ options.printUsage();
+ return 1;
+ }
+ }
+ if (!options.initOptions(args))
+ {
+ return 1;
+ }
+ if (args.size() < 3)
+ {
+ options.printUsage();
+ return 1;
+ }
+
+ Registry reg;
+ OUString regName( convertToFileUrl(args[0].c_str(), args[0].size()) );
+ if (reg.open(regName, RegAccessMode::READWRITE) != RegError::NO_ERROR)
+ {
+ if (reg.create(regName) != RegError::NO_ERROR)
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "open registry \"%s\" failed\n", args[0].c_str());
+ return -1;
+ }
+ }
+
+ RegistryKey rootKey;
+ if (reg.openRootKey(rootKey) != RegError::NO_ERROR)
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "open root key of registry \"%s\" failed\n", args[0].c_str());
+ return -4;
+ }
+
+ OUString mergeKeyName( OUString::createFromAscii(args[1].c_str()) );
+ for (size_t i = 2; i < args.size(); i++)
+ {
+ OUString targetRegName( convertToFileUrl(args[i].c_str(), args[i].size()) );
+ RegError _ret = reg.mergeKey(rootKey, mergeKeyName, targetRegName, options.isVerbose());
+ if (_ret != RegError::NO_ERROR)
+ {
+ if (_ret == RegError::MERGE_CONFLICT)
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
+ args[i].c_str(), args[1].c_str(), args[0].c_str());
+ }
+ else
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "ERROR: merging registry \"%s\" under key \"%s\" in registry \"%s\" failed.\n",
+ args[i].c_str(), args[1].c_str(), args[0].c_str());
+ return -2;
+ }
+ }
+ else
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
+ args[i].c_str(), args[1].c_str(), args[0].c_str());
+ }
+ }
+
+ rootKey.releaseKey();
+ if (reg.close() != RegError::NO_ERROR)
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "closing registry \"%s\" failed\n", args[0].c_str());
+ return -5;
+ }
+ }
+ catch (const std::exception &e)
+ {
+ SAL_WARN("registry", "Fatal exception: " << e.what());
+ return -5;
+ }
+
+
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/tools/regview.cxx b/registry/tools/regview.cxx
new file mode 100644
index 000000000..56aa343f4
--- /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: */