LibreOffice Module registry (master)  1
regimpl.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_REGISTRY_SOURCE_REGIMPL_HXX
21 #define INCLUDED_REGISTRY_SOURCE_REGIMPL_HXX
22 
23 #include <sal/config.h>
24 
25 #include <string_view>
26 #include <unordered_map>
27 
28 #include <regapi.hxx>
29 #include <registry/regtype.h>
30 #include <rtl/ustring.hxx>
31 #include <osl/mutex.hxx>
32 #include <store/store.hxx>
33 
34 // 5 bytes = 1 (byte for the type) + 4 (bytes for the size of the data)
35 #define VALUE_HEADERSIZE 5
36 #define VALUE_TYPEOFFSET 1
37 #define VALUE_HEADEROFFSET 5
38 
39 #define REG_GUARD(mutex) \
40  osl::Guard< osl::Mutex > aGuard( mutex );
41 
42 class ORegKey;
43 class RegistryTypeReader;
44 
45 class ORegistry
46 {
47 public:
48  ORegistry();
49 
50  sal_uInt32 acquire()
51  { return ++m_refCount; }
52 
53  sal_uInt32 release()
54  { return --m_refCount; }
55 
56  RegError initRegistry(const OUString& name,
57  RegAccessMode accessMode,
58  bool bCreate = false);
59 
61 
62  RegError destroyRegistry(const OUString& name);
63 
66 
68  const OUString& keyName,
69  RegKeyHandle* phNewKey);
70 
72  const OUString& keyName,
73  RegKeyHandle* phOpenKey);
74 
76 
77  RegError deleteKey(RegKeyHandle hKey, const OUString& keyName);
78 
80  const OUString& regFileName,
81  bool bWarnings,
82  bool bReport);
83 
85 
86  ~ORegistry();
87 
88  bool isReadOnly() const
89  { return m_readOnly; }
90 
91  bool isOpen() const
92  { return m_isOpen; }
93 
95 
97  { return m_file; }
98 
99  const OUString& getName() const
100  { return m_name; }
101 
102  friend class ORegKey;
103 
104 private:
105  RegError eraseKey(ORegKey* pKey, const OUString& keyName);
106 
108 
109  static RegError loadAndSaveValue(ORegKey* pTargetKey,
110  ORegKey const * pSourceKey,
111  const OUString& valueName,
112  sal_uInt32 nCut,
113  bool bWarnings,
114  bool bReport);
115 
116  static RegError checkBlop(store::OStoreStream& rValue,
117  std::u16string_view sTargetPath,
118  sal_uInt32 srcValueSize,
119  sal_uInt8 const * pSrcBuffer,
120  bool bReport);
121 
122  static RegError mergeModuleValue(store::OStoreStream& rTargetValue,
123  RegistryTypeReader const & reader,
124  RegistryTypeReader const & reader2);
125 
126  RegError loadAndSaveKeys(ORegKey* pTargetKey,
127  ORegKey* pSourceKey,
128  const OUString& keyName,
129  sal_uInt32 nCut,
130  bool bWarnings,
131  bool bReport);
132 
133  RegError dumpValue(const OUString& sPath,
134  const OUString& sName,
135  sal_Int16 nSpace) const;
136 
137  RegError dumpKey(const OUString& sPath,
138  const OUString& sName,
139  sal_Int16 nSpace) const;
140 
141  typedef std::unordered_map< OUString, ORegKey* > KeyMap;
142 
143  sal_uInt32 m_refCount;
144  osl::Mutex m_mutex;
146  bool m_isOpen;
147  OUString m_name;
150 
151  static constexpr OUStringLiteral ROOT { u"/" };
152 };
153 
154 #endif
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static constexpr OUStringLiteral ROOT u
Definition: regimpl.hxx:151
sal_uInt32 acquire()
Definition: regimpl.hxx:50
RegistryTypeReades reads a binary type blob.
Definition: reflread.hxx:37
sal_uInt32 m_refCount
Definition: regimpl.hxx:143
RegAccessMode
defines the open/access mode of the registry.
Definition: regtype.h:41
const OUString & getName() const
Definition: regimpl.hxx:99
RegError acquireKey(RegKeyHandle hKey)
Definition: regimpl.cxx:579
static RegError checkBlop(store::OStoreStream &rValue, std::u16string_view sTargetPath, sal_uInt32 srcValueSize, sal_uInt8 const *pSrcBuffer, bool bReport)
Definition: regimpl.cxx:1007
RegError deleteKey(RegKeyHandle hKey, const OUString &keyName)
Definition: regimpl.cxx:738
RegError createKey(RegKeyHandle hKey, const OUString &keyName, RegKeyHandle *phNewKey)
Definition: regimpl.cxx:606
ORegKey * getRootKey()
Definition: regimpl.cxx:1249
bool isReadOnly() const
Definition: regimpl.hxx:88
RegError closeRegistry()
Definition: regimpl.cxx:504
enum SAL_DLLPUBLIC_RTTI RegError
specifies the possible error codes which can occur using the registry API.
Definition: regtype.h:82
std::unordered_map< OUString, ORegKey * > KeyMap
Definition: regimpl.hxx:141
store::OStoreFile m_file
Definition: regimpl.hxx:148
osl::Mutex m_mutex
Definition: regimpl.hxx:144
bool m_readOnly
Definition: regimpl.hxx:145
bool isOpen() const
Definition: regimpl.hxx:91
static RegError loadAndSaveValue(ORegKey *pTargetKey, ORegKey const *pSourceKey, const OUString &valueName, sal_uInt32 nCut, bool bWarnings, bool bReport)
Definition: regimpl.cxx:896
RegError dumpRegistry(RegKeyHandle hKey) const
Definition: regimpl.cxx:1255
OUString m_name
Definition: regimpl.hxx:147
RegError loadKey(RegKeyHandle hKey, const OUString &regFileName, bool bWarnings, bool bReport)
Definition: regimpl.cxx:853
RegError dumpValue(const OUString &sPath, const OUString &sName, sal_Int16 nSpace) const
Definition: regimpl.cxx:1291
~ORegistry()
Definition: regimpl.cxx:431
unsigned char sal_uInt8
RegError eraseKey(ORegKey *pKey, const OUString &keyName)
Definition: regimpl.cxx:753
void * RegKeyHandle
defines the type of a registry key handle used in the C API.
Definition: regtype.h:30
RegError releaseKey(RegKeyHandle hKey)
Definition: regimpl.cxx:591
RegError closeKey(RegKeyHandle hKey)
Definition: regimpl.cxx:708
KeyMap m_openKeyTable
Definition: regimpl.hxx:149
RegError loadAndSaveKeys(ORegKey *pTargetKey, ORegKey *pSourceKey, const OUString &keyName, sal_uInt32 nCut, bool bWarnings, bool bReport)
Definition: regimpl.cxx:1184
RegError dumpKey(const OUString &sPath, const OUString &sName, sal_Int16 nSpace) const
Definition: regimpl.cxx:1519
sal_uInt32 release()
Definition: regimpl.hxx:53
ROOT
RegError initRegistry(const OUString &name, RegAccessMode accessMode, bool bCreate=false)
Definition: regimpl.cxx:441
RegError deleteSubkeysAndValues(ORegKey *pKey)
Definition: regimpl.cxx:816
RegError destroyRegistry(const OUString &name)
Definition: regimpl.cxx:520
static RegError mergeModuleValue(store::OStoreStream &rTargetValue, RegistryTypeReader const &reader, RegistryTypeReader const &reader2)
Definition: regimpl.cxx:1118
const store::OStoreFile & getStoreFile() const
Definition: regimpl.hxx:96
bool m_isOpen
Definition: regimpl.hxx:146
RegError openKey(RegKeyHandle hKey, const OUString &keyName, RegKeyHandle *phOpenKey)
Definition: regimpl.cxx:663