1*647a425cSAndrew Rist /**************************************************************
2*647a425cSAndrew Rist  *
3*647a425cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647a425cSAndrew Rist  * distributed with this work for additional information
6*647a425cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647a425cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist  * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647a425cSAndrew Rist  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist  *
13*647a425cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist  * software distributed under the License is distributed on an
15*647a425cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647a425cSAndrew Rist  * specific language governing permissions and limitations
18*647a425cSAndrew Rist  * under the License.
19*647a425cSAndrew Rist  *
20*647a425cSAndrew Rist  *************************************************************/
21*647a425cSAndrew Rist 
22*647a425cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_stoc.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <cstdlib>
28cdf0e10cSrcweir #include <memory>
29cdf0e10cSrcweir #include <vector>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
32cdf0e10cSrcweir #include "com/sun/star/registry/InvalidRegistryException.hpp"
33cdf0e10cSrcweir #include "com/sun/star/registry/InvalidValueException.hpp"
34cdf0e10cSrcweir #include "com/sun/star/registry/MergeConflictException.hpp"
35cdf0e10cSrcweir #include "com/sun/star/registry/RegistryKeyType.hpp"
36cdf0e10cSrcweir #include "com/sun/star/registry/XRegistryKey.hpp"
37cdf0e10cSrcweir #include "com/sun/star/registry/XSimpleRegistry.hpp"
38cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
39cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
40cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
41cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
42cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
43cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
44cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
45cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
46cdf0e10cSrcweir #include "osl/mutex.hxx"
47cdf0e10cSrcweir #include "registry/registry.hxx"
48cdf0e10cSrcweir #include "registry/regtype.h"
49cdf0e10cSrcweir #include "rtl/ref.hxx"
50cdf0e10cSrcweir #include "rtl/string.h"
51cdf0e10cSrcweir #include "rtl/string.hxx"
52cdf0e10cSrcweir #include "rtl/textcvt.h"
53cdf0e10cSrcweir #include "rtl/textenc.h"
54cdf0e10cSrcweir #include "rtl/unload.h"
55cdf0e10cSrcweir #include "rtl/ustring.h"
56cdf0e10cSrcweir #include "rtl/ustring.hxx"
57cdf0e10cSrcweir #include "sal/types.h"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include "bootstrapservices.hxx"
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #include "textualservices.hxx"
62cdf0e10cSrcweir 
63cdf0e10cSrcweir extern rtl_StandardModuleCount g_moduleCount;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir namespace {
66cdf0e10cSrcweir 
67cdf0e10cSrcweir namespace css = com::sun::star;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir class SimpleRegistry:
70cdf0e10cSrcweir     public cppu::WeakImplHelper2<
71cdf0e10cSrcweir         css::registry::XSimpleRegistry, css::lang::XServiceInfo >
72cdf0e10cSrcweir {
73cdf0e10cSrcweir public:
SimpleRegistry()74cdf0e10cSrcweir     SimpleRegistry() { g_moduleCount.modCnt.acquire(&g_moduleCount.modCnt); }
75cdf0e10cSrcweir 
~SimpleRegistry()76cdf0e10cSrcweir     ~SimpleRegistry() { g_moduleCount.modCnt.release(&g_moduleCount.modCnt); }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     osl::Mutex mutex_;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir private:
81cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getURL() throw (css::uno::RuntimeException);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     virtual void SAL_CALL open(
84cdf0e10cSrcweir         rtl::OUString const & rURL, sal_Bool bReadOnly, sal_Bool bCreate)
85cdf0e10cSrcweir         throw (
86cdf0e10cSrcweir             css::registry::InvalidRegistryException,
87cdf0e10cSrcweir             css::uno::RuntimeException);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isValid() throw (css::uno::RuntimeException);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     virtual void SAL_CALL close() throw (
92cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     virtual void SAL_CALL destroy() throw(
95cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
98cdf0e10cSrcweir     getRootKey() throw(
99cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isReadOnly() throw(
102cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     virtual void SAL_CALL mergeKey(
105cdf0e10cSrcweir         rtl::OUString const & aKeyName, rtl::OUString const & aUrl)
106cdf0e10cSrcweir         throw (
107cdf0e10cSrcweir             css::registry::InvalidRegistryException,
108cdf0e10cSrcweir             css::registry::MergeConflictException, css::uno::RuntimeException);
109cdf0e10cSrcweir 
getImplementationName()110cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
111cdf0e10cSrcweir         throw (css::uno::RuntimeException)
112cdf0e10cSrcweir     { return stoc_bootstrap::simreg_getImplementationName(); }
113cdf0e10cSrcweir 
supportsService(rtl::OUString const & ServiceName)114cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
115cdf0e10cSrcweir         throw (css::uno::RuntimeException)
116cdf0e10cSrcweir     { return ServiceName == getSupportedServiceNames()[0]; }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()119cdf0e10cSrcweir     getSupportedServiceNames() throw (css::uno::RuntimeException)
120cdf0e10cSrcweir     { return stoc_bootstrap::simreg_getSupportedServiceNames(); }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     Registry registry_;
123cdf0e10cSrcweir     std::auto_ptr< stoc::simpleregistry::TextualServices > textual_;
124cdf0e10cSrcweir };
125cdf0e10cSrcweir 
126cdf0e10cSrcweir class Key: public cppu::WeakImplHelper1< css::registry::XRegistryKey > {
127cdf0e10cSrcweir public:
Key(rtl::Reference<SimpleRegistry> const & registry,RegistryKey const & key)128cdf0e10cSrcweir     Key(
129cdf0e10cSrcweir         rtl::Reference< SimpleRegistry > const & registry,
130cdf0e10cSrcweir         RegistryKey const & key):
131cdf0e10cSrcweir         registry_(registry), key_(key) {}
132cdf0e10cSrcweir 
133cdf0e10cSrcweir private:
134cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getKeyName()
135cdf0e10cSrcweir         throw (css::uno::RuntimeException);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isReadOnly() throw (
138cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isValid() throw(css::uno::RuntimeException);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     virtual css::registry::RegistryKeyType SAL_CALL getKeyType(
143cdf0e10cSrcweir         rtl::OUString const & rKeyName)
144cdf0e10cSrcweir         throw (
145cdf0e10cSrcweir             css::registry::InvalidRegistryException,
146cdf0e10cSrcweir             css::uno::RuntimeException);
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     virtual css::registry::RegistryValueType SAL_CALL getValueType() throw(
149cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getLongValue() throw (
152cdf0e10cSrcweir         css::registry::InvalidRegistryException,
153cdf0e10cSrcweir         css::registry::InvalidValueException, css::uno::RuntimeException);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     virtual void SAL_CALL setLongValue(sal_Int32 value) throw (
156cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     virtual css::uno::Sequence< sal_Int32 > SAL_CALL getLongListValue() throw(
159cdf0e10cSrcweir         css::registry::InvalidRegistryException,
160cdf0e10cSrcweir         css::registry::InvalidValueException, css::uno::RuntimeException);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     virtual void SAL_CALL setLongListValue(
163cdf0e10cSrcweir         com::sun::star::uno::Sequence< sal_Int32 > const & seqValue)
164cdf0e10cSrcweir         throw (
165cdf0e10cSrcweir             css::registry::InvalidRegistryException,
166cdf0e10cSrcweir             css::uno::RuntimeException);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getAsciiValue() throw (
169cdf0e10cSrcweir         css::registry::InvalidRegistryException,
170cdf0e10cSrcweir         css::registry::InvalidValueException, css::uno::RuntimeException);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     virtual void SAL_CALL setAsciiValue(rtl::OUString const & value) throw (
173cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue()
176cdf0e10cSrcweir         throw (
177cdf0e10cSrcweir             css::registry::InvalidRegistryException,
178cdf0e10cSrcweir             css::registry::InvalidValueException, css::uno::RuntimeException);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     virtual void SAL_CALL setAsciiListValue(
181cdf0e10cSrcweir         css::uno::Sequence< rtl::OUString > const & seqValue)
182cdf0e10cSrcweir         throw (
183cdf0e10cSrcweir             css::registry::InvalidRegistryException,
184cdf0e10cSrcweir             css::uno::RuntimeException);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getStringValue() throw(
187cdf0e10cSrcweir         css::registry::InvalidRegistryException,
188cdf0e10cSrcweir         css::registry::InvalidValueException, css::uno::RuntimeException);
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     virtual void SAL_CALL setStringValue(rtl::OUString const & value) throw (
191cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL getStringListValue()
194cdf0e10cSrcweir         throw (
195cdf0e10cSrcweir             css::registry::InvalidRegistryException,
196cdf0e10cSrcweir             css::registry::InvalidValueException, css::uno::RuntimeException);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     virtual void SAL_CALL setStringListValue(
199cdf0e10cSrcweir         css::uno::Sequence< rtl::OUString > const & seqValue)
200cdf0e10cSrcweir         throw (
201cdf0e10cSrcweir             css::registry::InvalidRegistryException,
202cdf0e10cSrcweir             css::uno::RuntimeException);
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue() throw (
205cdf0e10cSrcweir         css::registry::InvalidRegistryException,
206cdf0e10cSrcweir         css::registry::InvalidValueException, css::uno::RuntimeException);
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     virtual void SAL_CALL setBinaryValue(
209cdf0e10cSrcweir         css::uno::Sequence< sal_Int8 > const & value)
210cdf0e10cSrcweir         throw (
211cdf0e10cSrcweir             css::registry::InvalidRegistryException,
212cdf0e10cSrcweir             css::uno::RuntimeException);
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL openKey(
215cdf0e10cSrcweir         rtl::OUString const & aKeyName)
216cdf0e10cSrcweir         throw (
217cdf0e10cSrcweir             css::registry::InvalidRegistryException,
218cdf0e10cSrcweir             css::uno::RuntimeException);
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
221cdf0e10cSrcweir     createKey(rtl::OUString const & aKeyName) throw (
222cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     virtual void SAL_CALL closeKey() throw (
225cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     virtual void SAL_CALL deleteKey(rtl::OUString const & rKeyName) throw (
228cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     virtual
231cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
232cdf0e10cSrcweir     SAL_CALL openKeys() throw (
233cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL getKeyNames() throw (
236cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     virtual sal_Bool SAL_CALL createLink(
239cdf0e10cSrcweir         rtl::OUString const & aLinkName, rtl::OUString const & aLinkTarget)
240cdf0e10cSrcweir         throw (
241cdf0e10cSrcweir             css::registry::InvalidRegistryException,
242cdf0e10cSrcweir             css::uno::RuntimeException);
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     virtual void SAL_CALL deleteLink(rtl::OUString const & rLinkName) throw (
245cdf0e10cSrcweir         css::registry::InvalidRegistryException, css::uno::RuntimeException);
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getLinkTarget(
248cdf0e10cSrcweir         rtl::OUString const & rLinkName)
249cdf0e10cSrcweir         throw (
250cdf0e10cSrcweir             css::registry::InvalidRegistryException,
251cdf0e10cSrcweir             css::uno::RuntimeException);
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getResolvedName(
254cdf0e10cSrcweir         rtl::OUString const & aKeyName)
255cdf0e10cSrcweir         throw (
256cdf0e10cSrcweir             css::registry::InvalidRegistryException,
257cdf0e10cSrcweir             css::uno::RuntimeException);
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     rtl::Reference< SimpleRegistry > registry_;
260cdf0e10cSrcweir     RegistryKey key_;
261cdf0e10cSrcweir };
262cdf0e10cSrcweir 
getKeyName()263cdf0e10cSrcweir rtl::OUString Key::getKeyName() throw (css::uno::RuntimeException) {
264cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
265cdf0e10cSrcweir     return key_.getName();
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
isReadOnly()268cdf0e10cSrcweir sal_Bool Key::isReadOnly()
269cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
272cdf0e10cSrcweir     return key_.isReadOnly();
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
isValid()275cdf0e10cSrcweir sal_Bool Key::isValid() throw (css::uno::RuntimeException) {
276cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
277cdf0e10cSrcweir     return key_.isValid();
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
getKeyType(rtl::OUString const & rKeyName)280cdf0e10cSrcweir css::registry::RegistryKeyType Key::getKeyType(rtl::OUString const & rKeyName)
281cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
284cdf0e10cSrcweir     RegKeyType type;
285cdf0e10cSrcweir     RegError err = key_.getKeyType(rKeyName, &type);
286cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
287cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
288cdf0e10cSrcweir             (rtl::OUString(
289cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
290cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getKeyType:"
291cdf0e10cSrcweir                     " underlying RegistryKey::getKeyType() = ")) +
292cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
293cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
294cdf0e10cSrcweir     }
295cdf0e10cSrcweir     switch (type) {
296cdf0e10cSrcweir     default:
297cdf0e10cSrcweir         std::abort(); // this cannot happen
298cdf0e10cSrcweir         // pseudo-fall-through to avoid warnings on MSC
299cdf0e10cSrcweir     case RG_KEYTYPE:
300cdf0e10cSrcweir         return css::registry::RegistryKeyType_KEY;
301cdf0e10cSrcweir     case RG_LINKTYPE:
302cdf0e10cSrcweir         return css::registry::RegistryKeyType_LINK;
303cdf0e10cSrcweir     }
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
getValueType()306cdf0e10cSrcweir css::registry::RegistryValueType Key::getValueType()
307cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
310cdf0e10cSrcweir     RegValueType type;
311cdf0e10cSrcweir     sal_uInt32 size;
312cdf0e10cSrcweir     RegError err = key_.getValueInfo(rtl::OUString(), &type, &size);
313cdf0e10cSrcweir     switch (err) {
314cdf0e10cSrcweir     case REG_NO_ERROR:
315cdf0e10cSrcweir         break;
316cdf0e10cSrcweir     case REG_INVALID_VALUE:
317cdf0e10cSrcweir         type = RG_VALUETYPE_NOT_DEFINED;
318cdf0e10cSrcweir         break;
319cdf0e10cSrcweir     default:
320cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
321cdf0e10cSrcweir             (rtl::OUString(
322cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
323cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getValueType:"
324cdf0e10cSrcweir                     " underlying RegistryKey::getValueInfo() = ")) +
325cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
326cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir     switch (type) {
329cdf0e10cSrcweir     default:
330cdf0e10cSrcweir         std::abort(); // this cannot happen
331cdf0e10cSrcweir         // pseudo-fall-through to avoid warnings on MSC
332cdf0e10cSrcweir     case RG_VALUETYPE_NOT_DEFINED:
333cdf0e10cSrcweir         return css::registry::RegistryValueType_NOT_DEFINED;
334cdf0e10cSrcweir     case RG_VALUETYPE_LONG:
335cdf0e10cSrcweir         return css::registry::RegistryValueType_LONG;
336cdf0e10cSrcweir     case RG_VALUETYPE_STRING:
337cdf0e10cSrcweir         return css::registry::RegistryValueType_ASCII;
338cdf0e10cSrcweir     case RG_VALUETYPE_UNICODE:
339cdf0e10cSrcweir         return css::registry::RegistryValueType_STRING;
340cdf0e10cSrcweir     case RG_VALUETYPE_BINARY:
341cdf0e10cSrcweir         return css::registry::RegistryValueType_BINARY;
342cdf0e10cSrcweir     case RG_VALUETYPE_LONGLIST:
343cdf0e10cSrcweir         return css::registry::RegistryValueType_LONGLIST;
344cdf0e10cSrcweir     case RG_VALUETYPE_STRINGLIST:
345cdf0e10cSrcweir         return css::registry::RegistryValueType_ASCIILIST;
346cdf0e10cSrcweir     case RG_VALUETYPE_UNICODELIST:
347cdf0e10cSrcweir         return css::registry::RegistryValueType_STRINGLIST;
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
getLongValue()351cdf0e10cSrcweir sal_Int32 Key::getLongValue() throw (
352cdf0e10cSrcweir     css::registry::InvalidRegistryException,
353cdf0e10cSrcweir     css::registry::InvalidValueException, css::uno::RuntimeException)
354cdf0e10cSrcweir {
355cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
356cdf0e10cSrcweir     sal_Int32 value;
357cdf0e10cSrcweir     RegError err = key_.getValue(rtl::OUString(), &value);
358cdf0e10cSrcweir     switch (err) {
359cdf0e10cSrcweir     case REG_NO_ERROR:
360cdf0e10cSrcweir         break;
361cdf0e10cSrcweir     case REG_INVALID_VALUE:
362cdf0e10cSrcweir         throw css::registry::InvalidValueException(
363cdf0e10cSrcweir             rtl::OUString(
364cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
365cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getLongValue:"
366cdf0e10cSrcweir                     " underlying RegistryKey::getValue() = REG_INVALID_VALUE")),
367cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
368cdf0e10cSrcweir     default:
369cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
370cdf0e10cSrcweir             (rtl::OUString(
371cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
372cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getLongValue:"
373cdf0e10cSrcweir                     " underlying RegistryKey::getValue() = ")) +
374cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
375cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
376cdf0e10cSrcweir     }
377cdf0e10cSrcweir     return value;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir 
setLongValue(sal_Int32 value)380cdf0e10cSrcweir void Key::setLongValue(sal_Int32 value)
381cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
384cdf0e10cSrcweir     RegError err = key_.setValue(
385cdf0e10cSrcweir         rtl::OUString(), RG_VALUETYPE_LONG, &value, sizeof (sal_Int32));
386cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
387cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
388cdf0e10cSrcweir             (rtl::OUString(
389cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
390cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key setLongValue:"
391cdf0e10cSrcweir                     " underlying RegistryKey::setValue() = ")) +
392cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
393cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
394cdf0e10cSrcweir     }
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
getLongListValue()397cdf0e10cSrcweir css::uno::Sequence< sal_Int32 > Key::getLongListValue() throw (
398cdf0e10cSrcweir     css::registry::InvalidRegistryException,
399cdf0e10cSrcweir     css::registry::InvalidValueException, css::uno::RuntimeException)
400cdf0e10cSrcweir {
401cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
402cdf0e10cSrcweir     RegistryValueList< sal_Int32 > list;
403cdf0e10cSrcweir     RegError err = key_.getLongListValue(rtl::OUString(), list);
404cdf0e10cSrcweir     switch (err) {
405cdf0e10cSrcweir     case REG_NO_ERROR:
406cdf0e10cSrcweir         break;
407cdf0e10cSrcweir     case REG_VALUE_NOT_EXISTS:
408cdf0e10cSrcweir         return css::uno::Sequence< sal_Int32 >();
409cdf0e10cSrcweir     case REG_INVALID_VALUE:
410cdf0e10cSrcweir         throw css::registry::InvalidValueException(
411cdf0e10cSrcweir             rtl::OUString(
412cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
413cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getLongListValue:"
414cdf0e10cSrcweir                     " underlying RegistryKey::getLongListValue() ="
415cdf0e10cSrcweir                     " REG_INVALID_VALUE")),
416cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
417cdf0e10cSrcweir     default:
418cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
419cdf0e10cSrcweir             (rtl::OUString(
420cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
421cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getLongListValue:"
422cdf0e10cSrcweir                     " underlying RegistryKey::getLongListValue() = ")) +
423cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
424cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
425cdf0e10cSrcweir     }
426cdf0e10cSrcweir     sal_uInt32 n = list.getLength();
427cdf0e10cSrcweir     if (n > SAL_MAX_INT32) {
428cdf0e10cSrcweir         throw css::registry::InvalidValueException(
429cdf0e10cSrcweir             rtl::OUString(
430cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
431cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getLongListValue:"
432cdf0e10cSrcweir                     " underlying RegistryKey::getLongListValue() too large")),
433cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
434cdf0e10cSrcweir     }
435cdf0e10cSrcweir     css::uno::Sequence< sal_Int32 > value(static_cast< sal_Int32 >(n));
436cdf0e10cSrcweir     for (sal_uInt32 i = 0; i < n; ++i) {
437cdf0e10cSrcweir         value[static_cast< sal_Int32 >(i)] = list.getElement(i);
438cdf0e10cSrcweir     }
439cdf0e10cSrcweir     return value;
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
setLongListValue(css::uno::Sequence<sal_Int32> const & seqValue)442cdf0e10cSrcweir void Key::setLongListValue(css::uno::Sequence< sal_Int32 > const & seqValue)
443cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
444cdf0e10cSrcweir {
445cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
446cdf0e10cSrcweir     std::vector< sal_Int32 > list;
447cdf0e10cSrcweir     for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
448cdf0e10cSrcweir         list.push_back(seqValue[i]);
449cdf0e10cSrcweir     }
450cdf0e10cSrcweir     RegError err = key_.setLongListValue(
451cdf0e10cSrcweir         rtl::OUString(), list.empty() ? 0 : &list[0],
452cdf0e10cSrcweir         static_cast< sal_uInt32 >(list.size()));
453cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
454cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
455cdf0e10cSrcweir             (rtl::OUString(
456cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
457cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key setLongListValue:"
458cdf0e10cSrcweir                     " underlying RegistryKey::setLongListValue() = ")) +
459cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
460cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
461cdf0e10cSrcweir     }
462cdf0e10cSrcweir }
463cdf0e10cSrcweir 
getAsciiValue()464cdf0e10cSrcweir rtl::OUString Key::getAsciiValue() throw (
465cdf0e10cSrcweir     css::registry::InvalidRegistryException,
466cdf0e10cSrcweir     css::registry::InvalidValueException, css::uno::RuntimeException)
467cdf0e10cSrcweir {
468cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
469cdf0e10cSrcweir     RegValueType type;
470cdf0e10cSrcweir     sal_uInt32 size;
471cdf0e10cSrcweir     RegError err = key_.getValueInfo(rtl::OUString(), &type, &size);
472cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
473cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
474cdf0e10cSrcweir             (rtl::OUString(
475cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
476cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
477cdf0e10cSrcweir                     " underlying RegistryKey::getValueInfo() = ")) +
478cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
479cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
480cdf0e10cSrcweir     }
481cdf0e10cSrcweir     if (type != RG_VALUETYPE_STRING) {
482cdf0e10cSrcweir         throw css::registry::InvalidValueException(
483cdf0e10cSrcweir             (rtl::OUString(
484cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
485cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
486cdf0e10cSrcweir                     " underlying RegistryKey type = ")) +
487cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(type))),
488cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
489cdf0e10cSrcweir     }
490cdf0e10cSrcweir     // size contains terminating null (error in underlying registry.cxx):
491cdf0e10cSrcweir     if (size == 0) {
492cdf0e10cSrcweir         throw css::registry::InvalidValueException(
493cdf0e10cSrcweir             rtl::OUString(
494cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
495cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
496cdf0e10cSrcweir                     " underlying RegistryKey size 0 cannot happen due to"
497cdf0e10cSrcweir                     " design error")),
498cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
499cdf0e10cSrcweir     }
500cdf0e10cSrcweir     if (size > SAL_MAX_INT32) {
501cdf0e10cSrcweir         throw css::registry::InvalidValueException(
502cdf0e10cSrcweir             rtl::OUString(
503cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
504cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
505cdf0e10cSrcweir                     " underlying RegistryKey size too large")),
506cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
507cdf0e10cSrcweir     }
508cdf0e10cSrcweir     std::vector< char > list(size);
509cdf0e10cSrcweir     err = key_.getValue(rtl::OUString(), &list[0]);
510cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
511cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
512cdf0e10cSrcweir             (rtl::OUString(
513cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
514cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
515cdf0e10cSrcweir                     " underlying RegistryKey::getValue() = ")) +
516cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
517cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
518cdf0e10cSrcweir     }
519cdf0e10cSrcweir     if (list[size - 1] != '\0') {
520cdf0e10cSrcweir         throw css::registry::InvalidValueException(
521cdf0e10cSrcweir             rtl::OUString(
522cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
523cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
524cdf0e10cSrcweir                     " underlying RegistryKey value must be null-terminated due"
525cdf0e10cSrcweir                     " to design error")),
526cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
527cdf0e10cSrcweir     }
528cdf0e10cSrcweir     rtl::OUString value;
529cdf0e10cSrcweir     if (!rtl_convertStringToUString(
530cdf0e10cSrcweir             &value.pData, &list[0],
531cdf0e10cSrcweir             static_cast< sal_Int32 >(size - 1), RTL_TEXTENCODING_UTF8,
532cdf0e10cSrcweir             (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
533cdf0e10cSrcweir              RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
534cdf0e10cSrcweir              RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
535cdf0e10cSrcweir     {
536cdf0e10cSrcweir         throw css::registry::InvalidValueException(
537cdf0e10cSrcweir             rtl::OUString(
538cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
539cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
540cdf0e10cSrcweir                     " underlying RegistryKey not UTF-8")),
541cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
542cdf0e10cSrcweir     }
543cdf0e10cSrcweir     return value;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir 
setAsciiValue(rtl::OUString const & value)546cdf0e10cSrcweir void Key::setAsciiValue(rtl::OUString const & value)
547cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
548cdf0e10cSrcweir {
549cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
550cdf0e10cSrcweir     rtl::OString utf8;
551cdf0e10cSrcweir     if (!value.convertToString(
552cdf0e10cSrcweir             &utf8, RTL_TEXTENCODING_UTF8,
553cdf0e10cSrcweir             (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
554cdf0e10cSrcweir              RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
555cdf0e10cSrcweir     {
556cdf0e10cSrcweir         throw css::uno::RuntimeException(
557cdf0e10cSrcweir             rtl::OUString(
558cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
559cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key setAsciiValue:"
560cdf0e10cSrcweir                     " value not UTF-16")),
561cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
562cdf0e10cSrcweir     }
563cdf0e10cSrcweir     RegError err = key_.setValue(
564cdf0e10cSrcweir         rtl::OUString(), RG_VALUETYPE_STRING,
565cdf0e10cSrcweir         const_cast< char * >(utf8.getStr()), utf8.getLength() + 1);
566cdf0e10cSrcweir         // +1 for terminating null (error in underlying registry.cxx)
567cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
568cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
569cdf0e10cSrcweir             (rtl::OUString(
570cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
571cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key setAsciiValue:"
572cdf0e10cSrcweir                     " underlying RegistryKey::setValue() = ")) +
573cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
574cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
575cdf0e10cSrcweir     }
576cdf0e10cSrcweir }
577cdf0e10cSrcweir 
getAsciiListValue()578cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Key::getAsciiListValue() throw (
579cdf0e10cSrcweir     css::registry::InvalidRegistryException,
580cdf0e10cSrcweir     css::registry::InvalidValueException, css::uno::RuntimeException)
581cdf0e10cSrcweir {
582cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
583cdf0e10cSrcweir     RegistryValueList< char * > list;
584cdf0e10cSrcweir     RegError err = key_.getStringListValue(rtl::OUString(), list);
585cdf0e10cSrcweir     switch (err) {
586cdf0e10cSrcweir     case REG_NO_ERROR:
587cdf0e10cSrcweir         break;
588cdf0e10cSrcweir     case REG_VALUE_NOT_EXISTS:
589cdf0e10cSrcweir         return css::uno::Sequence< rtl::OUString >();
590cdf0e10cSrcweir     case REG_INVALID_VALUE:
591cdf0e10cSrcweir         throw css::registry::InvalidValueException(
592cdf0e10cSrcweir             rtl::OUString(
593cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
594cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key"
595cdf0e10cSrcweir                     " getAsciiListValue: underlying"
596cdf0e10cSrcweir                     " RegistryKey::getStringListValue() = REG_INVALID_VALUE")),
597cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
598cdf0e10cSrcweir     default:
599cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
600cdf0e10cSrcweir             (rtl::OUString(
601cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
602cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key"
603cdf0e10cSrcweir                     " getAsciiListValue: underlying"
604cdf0e10cSrcweir                     " RegistryKey::getStringListValue() = ")) +
605cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
606cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
607cdf0e10cSrcweir     }
608cdf0e10cSrcweir     sal_uInt32 n = list.getLength();
609cdf0e10cSrcweir     if (n > SAL_MAX_INT32) {
610cdf0e10cSrcweir         throw css::registry::InvalidValueException(
611cdf0e10cSrcweir             rtl::OUString(
612cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
613cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key"
614cdf0e10cSrcweir                     " getAsciiListValue: underlying"
615cdf0e10cSrcweir                     " RegistryKey::getStringListValue() too large")),
616cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
617cdf0e10cSrcweir     }
618cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > value(static_cast< sal_Int32 >(n));
619cdf0e10cSrcweir     for (sal_uInt32 i = 0; i < n; ++i) {
620cdf0e10cSrcweir         char * el = list.getElement(i);
621cdf0e10cSrcweir         sal_Int32 size = rtl_str_getLength(el);
622cdf0e10cSrcweir         if (!rtl_convertStringToUString(
623cdf0e10cSrcweir                 &value[static_cast< sal_Int32 >(i)].pData, el, size,
624cdf0e10cSrcweir                 RTL_TEXTENCODING_UTF8,
625cdf0e10cSrcweir                 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
626cdf0e10cSrcweir                  RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
627cdf0e10cSrcweir                  RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
628cdf0e10cSrcweir         {
629cdf0e10cSrcweir             throw css::registry::InvalidValueException(
630cdf0e10cSrcweir                 rtl::OUString(
631cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
632cdf0e10cSrcweir                         "com.sun.star.registry.SimpleRegistry key"
633cdf0e10cSrcweir                         " getAsciiListValue: underlying RegistryKey not"
634cdf0e10cSrcweir                         " UTF-8")),
635cdf0e10cSrcweir                 static_cast< OWeakObject * >(this));
636cdf0e10cSrcweir         }
637cdf0e10cSrcweir     }
638cdf0e10cSrcweir     return value;
639cdf0e10cSrcweir }
640cdf0e10cSrcweir 
setAsciiListValue(css::uno::Sequence<rtl::OUString> const & seqValue)641cdf0e10cSrcweir void Key::setAsciiListValue(
642cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > const & seqValue)
643cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
644cdf0e10cSrcweir {
645cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
646cdf0e10cSrcweir     std::vector< rtl::OString > list;
647cdf0e10cSrcweir     for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
648cdf0e10cSrcweir         rtl::OString utf8;
649cdf0e10cSrcweir         if (!seqValue[i].convertToString(
650cdf0e10cSrcweir                 &utf8, RTL_TEXTENCODING_UTF8,
651cdf0e10cSrcweir                 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
652cdf0e10cSrcweir                  RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
653cdf0e10cSrcweir         {
654cdf0e10cSrcweir             throw css::uno::RuntimeException(
655cdf0e10cSrcweir                 rtl::OUString(
656cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
657cdf0e10cSrcweir                         "com.sun.star.registry.SimpleRegistry key"
658cdf0e10cSrcweir                         " setAsciiListValue: value not UTF-16")),
659cdf0e10cSrcweir                 static_cast< OWeakObject * >(this));
660cdf0e10cSrcweir         }
661cdf0e10cSrcweir         list.push_back(utf8);
662cdf0e10cSrcweir     }
663cdf0e10cSrcweir     std::vector< char * > list2;
664cdf0e10cSrcweir     for (std::vector< rtl::OString >::iterator i(list.begin()); i != list.end();
665cdf0e10cSrcweir          ++i)
666cdf0e10cSrcweir     {
667cdf0e10cSrcweir         list2.push_back(const_cast< char * >(i->getStr()));
668cdf0e10cSrcweir     }
669cdf0e10cSrcweir     RegError err = key_.setStringListValue(
670cdf0e10cSrcweir         rtl::OUString(), list2.empty() ? 0 : &list2[0],
671cdf0e10cSrcweir         static_cast< sal_uInt32 >(list2.size()));
672cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
673cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
674cdf0e10cSrcweir             (rtl::OUString(
675cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
676cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key"
677cdf0e10cSrcweir                     " setAsciiListValue: underlying"
678cdf0e10cSrcweir                     " RegistryKey::setStringListValue() = ")) +
679cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
680cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
681cdf0e10cSrcweir     }
682cdf0e10cSrcweir }
683cdf0e10cSrcweir 
getStringValue()684cdf0e10cSrcweir rtl::OUString Key::getStringValue() throw (
685cdf0e10cSrcweir     css::registry::InvalidRegistryException,
686cdf0e10cSrcweir     css::registry::InvalidValueException, css::uno::RuntimeException)
687cdf0e10cSrcweir {
688cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
689cdf0e10cSrcweir     RegValueType type;
690cdf0e10cSrcweir     sal_uInt32 size;
691cdf0e10cSrcweir     RegError err = key_.getValueInfo(rtl::OUString(), &type, &size);
692cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
693cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
694cdf0e10cSrcweir             (rtl::OUString(
695cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
696cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getStringValue:"
697cdf0e10cSrcweir                     " underlying RegistryKey::getValueInfo() = ")) +
698cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
699cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
700cdf0e10cSrcweir     }
701cdf0e10cSrcweir     if (type != RG_VALUETYPE_UNICODE) {
702cdf0e10cSrcweir         throw css::registry::InvalidValueException(
703cdf0e10cSrcweir             (rtl::OUString(
704cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
705cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getStringValue:"
706cdf0e10cSrcweir                     " underlying RegistryKey type = ")) +
707cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(type))),
708cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
709cdf0e10cSrcweir     }
710cdf0e10cSrcweir     // size contains terminating null and is *2 (error in underlying
711cdf0e10cSrcweir     // registry.cxx):
712cdf0e10cSrcweir     if (size == 0 || (size & 1) == 1) {
713cdf0e10cSrcweir         throw css::registry::InvalidValueException(
714cdf0e10cSrcweir             rtl::OUString(
715cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
716cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getStringValue:"
717cdf0e10cSrcweir                     " underlying RegistryKey size 0 or odd cannot happen due to"
718cdf0e10cSrcweir                     " design error")),
719cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
720cdf0e10cSrcweir     }
721cdf0e10cSrcweir     if (size > SAL_MAX_INT32) {
722cdf0e10cSrcweir         throw css::registry::InvalidValueException(
723cdf0e10cSrcweir             rtl::OUString(
724cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
725cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getStringValue:"
726cdf0e10cSrcweir                     " underlying RegistryKey size too large")),
727cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
728cdf0e10cSrcweir     }
729cdf0e10cSrcweir     std::vector< sal_Unicode > list(size);
730cdf0e10cSrcweir     err = key_.getValue(rtl::OUString(), &list[0]);
731cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
732cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
733cdf0e10cSrcweir             (rtl::OUString(
734cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
735cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getStringValue:"
736cdf0e10cSrcweir                     " underlying RegistryKey::getValue() = ")) +
737cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
738cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
739cdf0e10cSrcweir     }
740cdf0e10cSrcweir     if (list[size/2 - 1] != 0) {
741cdf0e10cSrcweir         throw css::registry::InvalidValueException(
742cdf0e10cSrcweir             rtl::OUString(
743cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
744cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getStringValue:"
745cdf0e10cSrcweir                     " underlying RegistryKey value must be null-terminated due"
746cdf0e10cSrcweir                     " to design error")),
747cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
748cdf0e10cSrcweir     }
749cdf0e10cSrcweir     return rtl::OUString(&list[0], static_cast< sal_Int32 >(size/2 - 1));
750cdf0e10cSrcweir }
751cdf0e10cSrcweir 
setStringValue(rtl::OUString const & value)752cdf0e10cSrcweir void Key::setStringValue(rtl::OUString const & value)
753cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
754cdf0e10cSrcweir {
755cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
756cdf0e10cSrcweir     RegError err = key_.setValue(
757cdf0e10cSrcweir         rtl::OUString(), RG_VALUETYPE_UNICODE,
758cdf0e10cSrcweir         const_cast< sal_Unicode * >(value.getStr()),
759cdf0e10cSrcweir         (value.getLength() + 1) * sizeof (sal_Unicode));
760cdf0e10cSrcweir         // +1 for terminating null (error in underlying registry.cxx)
761cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
762cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
763cdf0e10cSrcweir             (rtl::OUString(
764cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
765cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key setStringValue:"
766cdf0e10cSrcweir                     " underlying RegistryKey::setValue() = ")) +
767cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
768cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
769cdf0e10cSrcweir     }
770cdf0e10cSrcweir }
771cdf0e10cSrcweir 
getStringListValue()772cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Key::getStringListValue() throw (
773cdf0e10cSrcweir     css::registry::InvalidRegistryException,
774cdf0e10cSrcweir     css::registry::InvalidValueException, css::uno::RuntimeException)
775cdf0e10cSrcweir {
776cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
777cdf0e10cSrcweir     RegistryValueList< sal_Unicode * > list;
778cdf0e10cSrcweir     RegError err = key_.getUnicodeListValue(rtl::OUString(), list);
779cdf0e10cSrcweir     switch (err) {
780cdf0e10cSrcweir     case REG_NO_ERROR:
781cdf0e10cSrcweir         break;
782cdf0e10cSrcweir     case REG_VALUE_NOT_EXISTS:
783cdf0e10cSrcweir         return css::uno::Sequence< rtl::OUString >();
784cdf0e10cSrcweir     case REG_INVALID_VALUE:
785cdf0e10cSrcweir         throw css::registry::InvalidValueException(
786cdf0e10cSrcweir             rtl::OUString(
787cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
788cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key"
789cdf0e10cSrcweir                     " getStringListValue: underlying"
790cdf0e10cSrcweir                     " RegistryKey::getUnicodeListValue() = REG_INVALID_VALUE")),
791cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
792cdf0e10cSrcweir     default:
793cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
794cdf0e10cSrcweir             (rtl::OUString(
795cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
796cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key"
797cdf0e10cSrcweir                     " getStringListValue: underlying"
798cdf0e10cSrcweir                     " RegistryKey::getUnicodeListValue() = ")) +
799cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
800cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
801cdf0e10cSrcweir     }
802cdf0e10cSrcweir     sal_uInt32 n = list.getLength();
803cdf0e10cSrcweir     if (n > SAL_MAX_INT32) {
804cdf0e10cSrcweir         throw css::registry::InvalidValueException(
805cdf0e10cSrcweir             rtl::OUString(
806cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
807cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key"
808cdf0e10cSrcweir                     " getStringListValue: underlying"
809cdf0e10cSrcweir                     " RegistryKey::getUnicodeListValue() too large")),
810cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
811cdf0e10cSrcweir     }
812cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > value(static_cast< sal_Int32 >(n));
813cdf0e10cSrcweir     for (sal_uInt32 i = 0; i < n; ++i) {
814cdf0e10cSrcweir         value[static_cast< sal_Int32 >(i)] = list.getElement(i);
815cdf0e10cSrcweir     }
816cdf0e10cSrcweir     return value;
817cdf0e10cSrcweir }
818cdf0e10cSrcweir 
setStringListValue(css::uno::Sequence<rtl::OUString> const & seqValue)819cdf0e10cSrcweir void Key::setStringListValue(
820cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > const & seqValue)
821cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
822cdf0e10cSrcweir {
823cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
824cdf0e10cSrcweir     std::vector< sal_Unicode * > list;
825cdf0e10cSrcweir     for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
826cdf0e10cSrcweir         list.push_back(const_cast< sal_Unicode * >(seqValue[i].getStr()));
827cdf0e10cSrcweir     }
828cdf0e10cSrcweir     RegError err = key_.setUnicodeListValue(
829cdf0e10cSrcweir         rtl::OUString(), list.empty() ? 0 : &list[0],
830cdf0e10cSrcweir         static_cast< sal_uInt32 >(list.size()));
831cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
832cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
833cdf0e10cSrcweir             (rtl::OUString(
834cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
835cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key"
836cdf0e10cSrcweir                     " setStringListValue: underlying"
837cdf0e10cSrcweir                     " RegistryKey::setUnicodeListValue() = ")) +
838cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
839cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir }
842cdf0e10cSrcweir 
getBinaryValue()843cdf0e10cSrcweir css::uno::Sequence< sal_Int8 > Key::getBinaryValue()
844cdf0e10cSrcweir     throw (
845cdf0e10cSrcweir         css::registry::InvalidRegistryException,
846cdf0e10cSrcweir         css::registry::InvalidValueException, css::uno::RuntimeException)
847cdf0e10cSrcweir {
848cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
849cdf0e10cSrcweir     RegValueType type;
850cdf0e10cSrcweir     sal_uInt32 size;
851cdf0e10cSrcweir     RegError err = key_.getValueInfo(rtl::OUString(), &type, &size);
852cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
853cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
854cdf0e10cSrcweir             (rtl::OUString(
855cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
856cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
857cdf0e10cSrcweir                     " underlying RegistryKey::getValueInfo() = ")) +
858cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
859cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
860cdf0e10cSrcweir     }
861cdf0e10cSrcweir     if (type != RG_VALUETYPE_BINARY) {
862cdf0e10cSrcweir         throw css::registry::InvalidValueException(
863cdf0e10cSrcweir             (rtl::OUString(
864cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
865cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
866cdf0e10cSrcweir                     " underlying RegistryKey type = ")) +
867cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(type))),
868cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
869cdf0e10cSrcweir     }
870cdf0e10cSrcweir     if (size > SAL_MAX_INT32) {
871cdf0e10cSrcweir         throw css::registry::InvalidValueException(
872cdf0e10cSrcweir             rtl::OUString(
873cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
874cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
875cdf0e10cSrcweir                     " underlying RegistryKey size too large")),
876cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
877cdf0e10cSrcweir     }
878cdf0e10cSrcweir     css::uno::Sequence< sal_Int8 > value(static_cast< sal_Int32 >(size));
879cdf0e10cSrcweir     err = key_.getValue(rtl::OUString(), value.getArray());
880cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
881cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
882cdf0e10cSrcweir             (rtl::OUString(
883cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
884cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
885cdf0e10cSrcweir                     " underlying RegistryKey::getValue() = ")) +
886cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
887cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
888cdf0e10cSrcweir     }
889cdf0e10cSrcweir     return value;
890cdf0e10cSrcweir }
891cdf0e10cSrcweir 
setBinaryValue(css::uno::Sequence<sal_Int8> const & value)892cdf0e10cSrcweir void Key::setBinaryValue(css::uno::Sequence< sal_Int8 > const & value)
893cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
894cdf0e10cSrcweir {
895cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
896cdf0e10cSrcweir     RegError err = key_.setValue(
897cdf0e10cSrcweir         rtl::OUString(), RG_VALUETYPE_BINARY,
898cdf0e10cSrcweir         const_cast< sal_Int8 * >(value.getConstArray()),
899cdf0e10cSrcweir         static_cast< sal_uInt32 >(value.getLength()));
900cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
901cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
902cdf0e10cSrcweir             (rtl::OUString(
903cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
904cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key setBinaryValue:"
905cdf0e10cSrcweir                     " underlying RegistryKey::setValue() = ")) +
906cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
907cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
908cdf0e10cSrcweir     }
909cdf0e10cSrcweir }
910cdf0e10cSrcweir 
openKey(rtl::OUString const & aKeyName)911cdf0e10cSrcweir css::uno::Reference< css::registry::XRegistryKey > Key::openKey(
912cdf0e10cSrcweir     rtl::OUString const & aKeyName)
913cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
914cdf0e10cSrcweir {
915cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
916cdf0e10cSrcweir     RegistryKey key;
917cdf0e10cSrcweir     RegError err = key_.openKey(aKeyName, key);
918cdf0e10cSrcweir     switch (err) {
919cdf0e10cSrcweir     case REG_NO_ERROR:
920cdf0e10cSrcweir         return new Key(registry_, key);
921cdf0e10cSrcweir     case REG_KEY_NOT_EXISTS:
922cdf0e10cSrcweir         return css::uno::Reference< css::registry::XRegistryKey >();
923cdf0e10cSrcweir     default:
924cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
925cdf0e10cSrcweir             (rtl::OUString(
926cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
927cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key openKey:"
928cdf0e10cSrcweir                     " underlying RegistryKey::openKey() = ")) +
929cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
930cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
931cdf0e10cSrcweir     }
932cdf0e10cSrcweir }
933cdf0e10cSrcweir 
createKey(rtl::OUString const & aKeyName)934cdf0e10cSrcweir css::uno::Reference< css::registry::XRegistryKey > Key::createKey(
935cdf0e10cSrcweir     rtl::OUString const & aKeyName)
936cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
937cdf0e10cSrcweir {
938cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
939cdf0e10cSrcweir     RegistryKey key;
940cdf0e10cSrcweir     RegError err = key_.createKey(aKeyName, key);
941cdf0e10cSrcweir     switch (err) {
942cdf0e10cSrcweir     case REG_NO_ERROR:
943cdf0e10cSrcweir         return new Key(registry_, key);
944cdf0e10cSrcweir     case REG_INVALID_KEYNAME:
945cdf0e10cSrcweir         return css::uno::Reference< css::registry::XRegistryKey >();
946cdf0e10cSrcweir     default:
947cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
948cdf0e10cSrcweir             (rtl::OUString(
949cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
950cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key createKey:"
951cdf0e10cSrcweir                     " underlying RegistryKey::createKey() = ")) +
952cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
953cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
954cdf0e10cSrcweir     }
955cdf0e10cSrcweir }
956cdf0e10cSrcweir 
closeKey()957cdf0e10cSrcweir void Key::closeKey()
958cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
959cdf0e10cSrcweir {
960cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
961cdf0e10cSrcweir     RegError err = key_.closeKey();
962cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
963cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
964cdf0e10cSrcweir             (rtl::OUString(
965cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
966cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key closeKey:"
967cdf0e10cSrcweir                     " underlying RegistryKey::closeKey() = ")) +
968cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
969cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
970cdf0e10cSrcweir     }
971cdf0e10cSrcweir }
972cdf0e10cSrcweir 
deleteKey(rtl::OUString const & rKeyName)973cdf0e10cSrcweir void Key::deleteKey(rtl::OUString const & rKeyName)
974cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
975cdf0e10cSrcweir {
976cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
977cdf0e10cSrcweir     RegError err = key_.deleteKey(rKeyName);
978cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
979cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
980cdf0e10cSrcweir             (rtl::OUString(
981cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
982cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key deleteKey:"
983cdf0e10cSrcweir                     " underlying RegistryKey::deleteKey() = ")) +
984cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
985cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
986cdf0e10cSrcweir     }
987cdf0e10cSrcweir }
988cdf0e10cSrcweir 
989cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
openKeys()990cdf0e10cSrcweir Key::openKeys()
991cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
992cdf0e10cSrcweir {
993cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
994cdf0e10cSrcweir     RegistryKeyArray list;
995cdf0e10cSrcweir     RegError err = key_.openSubKeys(rtl::OUString(), list);
996cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
997cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
998cdf0e10cSrcweir             (rtl::OUString(
999cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1000cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key openKeys:"
1001cdf0e10cSrcweir                     " underlying RegistryKey::openSubKeys() = ")) +
1002cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1003cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1004cdf0e10cSrcweir     }
1005cdf0e10cSrcweir     sal_uInt32 n = list.getLength();
1006cdf0e10cSrcweir     if (n > SAL_MAX_INT32) {
1007cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1008cdf0e10cSrcweir             rtl::OUString(
1009cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1010cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getKeyNames:"
1011cdf0e10cSrcweir                     " underlying RegistryKey::getKeyNames() too large")),
1012cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1013cdf0e10cSrcweir     }
1014cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
1015cdf0e10cSrcweir         keys(static_cast< sal_Int32 >(n));
1016cdf0e10cSrcweir     for (sal_uInt32 i = 0; i < n; ++i) {
1017cdf0e10cSrcweir         keys[static_cast< sal_Int32 >(i)] = new Key(
1018cdf0e10cSrcweir             registry_, list.getElement(i));
1019cdf0e10cSrcweir     }
1020cdf0e10cSrcweir     return keys;
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir 
getKeyNames()1023cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Key::getKeyNames()
1024cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1025cdf0e10cSrcweir {
1026cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
1027cdf0e10cSrcweir     RegistryKeyNames list;
1028cdf0e10cSrcweir     RegError err = key_.getKeyNames(rtl::OUString(), list);
1029cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
1030cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1031cdf0e10cSrcweir             (rtl::OUString(
1032cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1033cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getKeyNames:"
1034cdf0e10cSrcweir                     " underlying RegistryKey::getKeyNames() = ")) +
1035cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1036cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1037cdf0e10cSrcweir     }
1038cdf0e10cSrcweir     sal_uInt32 n = list.getLength();
1039cdf0e10cSrcweir     if (n > SAL_MAX_INT32) {
1040cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1041cdf0e10cSrcweir             rtl::OUString(
1042cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1043cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getKeyNames:"
1044cdf0e10cSrcweir                     " underlying RegistryKey::getKeyNames() too large")),
1045cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1046cdf0e10cSrcweir     }
1047cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > names(static_cast< sal_Int32 >(n));
1048cdf0e10cSrcweir     for (sal_uInt32 i = 0; i < n; ++i) {
1049cdf0e10cSrcweir         names[static_cast< sal_Int32 >(i)] = list.getElement(i);
1050cdf0e10cSrcweir     }
1051cdf0e10cSrcweir     return names;
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir 
createLink(rtl::OUString const & aLinkName,rtl::OUString const & aLinkTarget)1054cdf0e10cSrcweir sal_Bool Key::createLink(
1055cdf0e10cSrcweir     rtl::OUString const & aLinkName, rtl::OUString const & aLinkTarget)
1056cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
1059cdf0e10cSrcweir     RegError err = key_.createLink(aLinkName, aLinkTarget);
1060cdf0e10cSrcweir     switch (err) {
1061cdf0e10cSrcweir     case REG_NO_ERROR:
1062cdf0e10cSrcweir         return true;
1063cdf0e10cSrcweir     case REG_INVALID_KEY:
1064cdf0e10cSrcweir     case REG_DETECT_RECURSION:
1065cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1066cdf0e10cSrcweir             (rtl::OUString(
1067cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1068cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key createLink:"
1069cdf0e10cSrcweir                     " underlying RegistryKey::createLink() = ")) +
1070cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1071cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1072cdf0e10cSrcweir     default:
1073cdf0e10cSrcweir         return false;
1074cdf0e10cSrcweir     }
1075cdf0e10cSrcweir }
1076cdf0e10cSrcweir 
deleteLink(rtl::OUString const & rLinkName)1077cdf0e10cSrcweir void Key::deleteLink(rtl::OUString const & rLinkName)
1078cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1079cdf0e10cSrcweir {
1080cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
1081cdf0e10cSrcweir     RegError err = key_.deleteLink(rLinkName);
1082cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
1083cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1084cdf0e10cSrcweir             (rtl::OUString(
1085cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1086cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key deleteLink:"
1087cdf0e10cSrcweir                     " underlying RegistryKey::deleteLink() = ")) +
1088cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1089cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1090cdf0e10cSrcweir     }
1091cdf0e10cSrcweir }
1092cdf0e10cSrcweir 
getLinkTarget(rtl::OUString const & rLinkName)1093cdf0e10cSrcweir rtl::OUString Key::getLinkTarget(rtl::OUString const & rLinkName)
1094cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1095cdf0e10cSrcweir {
1096cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
1097cdf0e10cSrcweir     rtl::OUString target;
1098cdf0e10cSrcweir     RegError err = key_.getLinkTarget(rLinkName, target);
1099cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
1100cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1101cdf0e10cSrcweir             (rtl::OUString(
1102cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1103cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getLinkTarget:"
1104cdf0e10cSrcweir                     " underlying RegistryKey::getLinkTarget() = ")) +
1105cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1106cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1107cdf0e10cSrcweir     }
1108cdf0e10cSrcweir     return target;
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
getResolvedName(rtl::OUString const & aKeyName)1111cdf0e10cSrcweir rtl::OUString Key::getResolvedName(rtl::OUString const & aKeyName)
1112cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1113cdf0e10cSrcweir {
1114cdf0e10cSrcweir     osl::MutexGuard guard(registry_->mutex_);
1115cdf0e10cSrcweir     rtl::OUString resolved;
1116cdf0e10cSrcweir     RegError err = key_.getResolvedKeyName(aKeyName, true, resolved);
1117cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
1118cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1119cdf0e10cSrcweir             (rtl::OUString(
1120cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1121cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry key getResolvedName:"
1122cdf0e10cSrcweir                     " underlying RegistryKey::getResolvedName() = ")) +
1123cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1124cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1125cdf0e10cSrcweir     }
1126cdf0e10cSrcweir     return resolved;
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir 
getURL()1129cdf0e10cSrcweir rtl::OUString SimpleRegistry::getURL() throw (css::uno::RuntimeException) {
1130cdf0e10cSrcweir     osl::MutexGuard guard(mutex_);
1131cdf0e10cSrcweir     return textual_.get() == 0 ? registry_.getName() : textual_->getUri();
1132cdf0e10cSrcweir }
1133cdf0e10cSrcweir 
open(rtl::OUString const & rURL,sal_Bool bReadOnly,sal_Bool bCreate)1134cdf0e10cSrcweir void SimpleRegistry::open(
1135cdf0e10cSrcweir     rtl::OUString const & rURL, sal_Bool bReadOnly, sal_Bool bCreate)
1136cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1137cdf0e10cSrcweir {
1138cdf0e10cSrcweir     osl::MutexGuard guard(mutex_);
1139cdf0e10cSrcweir     if (textual_.get() != 0) {
1140cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1141cdf0e10cSrcweir             (rtl::OUString(
1142cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1143cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry.open(")) +
1144cdf0e10cSrcweir              rURL +
1145cdf0e10cSrcweir              rtl::OUString(
1146cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1147cdf0e10cSrcweir                     "): instance already open"))),
1148cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1149cdf0e10cSrcweir     }
1150cdf0e10cSrcweir     RegError err = (rURL.getLength() == 0 && bCreate)
1151cdf0e10cSrcweir         ? REG_REGISTRY_NOT_EXISTS
1152cdf0e10cSrcweir         : registry_.open(rURL, bReadOnly ? REG_READONLY : REG_READWRITE);
1153cdf0e10cSrcweir     if (err == REG_REGISTRY_NOT_EXISTS && bCreate) {
1154cdf0e10cSrcweir         err = registry_.create(rURL);
1155cdf0e10cSrcweir     }
1156cdf0e10cSrcweir     switch (err) {
1157cdf0e10cSrcweir     case REG_NO_ERROR:
1158cdf0e10cSrcweir         break;
1159cdf0e10cSrcweir     case REG_INVALID_REGISTRY:
1160cdf0e10cSrcweir         if (bReadOnly && !bCreate) {
1161cdf0e10cSrcweir             textual_.reset(new stoc::simpleregistry::TextualServices(rURL));
1162cdf0e10cSrcweir             break;
1163cdf0e10cSrcweir         }
1164cdf0e10cSrcweir         // fall through
1165cdf0e10cSrcweir     default:
1166cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1167cdf0e10cSrcweir             (rtl::OUString(
1168cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1169cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry.open(")) +
1170cdf0e10cSrcweir              rURL +
1171cdf0e10cSrcweir              rtl::OUString(
1172cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1173cdf0e10cSrcweir                     "): underlying Registry::open/create() = ")) +
1174cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1175cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1176cdf0e10cSrcweir     }
1177cdf0e10cSrcweir }
1178cdf0e10cSrcweir 
isValid()1179cdf0e10cSrcweir sal_Bool SimpleRegistry::isValid() throw (css::uno::RuntimeException) {
1180cdf0e10cSrcweir     osl::MutexGuard guard(mutex_);
1181cdf0e10cSrcweir     return textual_.get() != 0 || registry_.isValid();
1182cdf0e10cSrcweir }
1183cdf0e10cSrcweir 
close()1184cdf0e10cSrcweir void SimpleRegistry::close()
1185cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1186cdf0e10cSrcweir {
1187cdf0e10cSrcweir     osl::MutexGuard guard(mutex_);
1188cdf0e10cSrcweir     if (textual_.get() != 0) {
1189cdf0e10cSrcweir         textual_.reset();
1190cdf0e10cSrcweir         return;
1191cdf0e10cSrcweir     }
1192cdf0e10cSrcweir     RegError err = registry_.close();
1193cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
1194cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1195cdf0e10cSrcweir             (rtl::OUString(
1196cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1197cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry.close:"
1198cdf0e10cSrcweir                     " underlying Registry::close() = ")) +
1199cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1200cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1201cdf0e10cSrcweir     }
1202cdf0e10cSrcweir }
1203cdf0e10cSrcweir 
destroy()1204cdf0e10cSrcweir void SimpleRegistry::destroy()
1205cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1206cdf0e10cSrcweir {
1207cdf0e10cSrcweir     osl::MutexGuard guard(mutex_);
1208cdf0e10cSrcweir     if (textual_.get() != 0) {
1209cdf0e10cSrcweir         textual_.reset();
1210cdf0e10cSrcweir         return;
1211cdf0e10cSrcweir     }
1212cdf0e10cSrcweir     RegError err = registry_.destroy(rtl::OUString());
1213cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
1214cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1215cdf0e10cSrcweir             (rtl::OUString(
1216cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1217cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry.destroy:"
1218cdf0e10cSrcweir                     " underlying Registry::destroy() = ")) +
1219cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1220cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1221cdf0e10cSrcweir     }
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir 
getRootKey()1224cdf0e10cSrcweir css::uno::Reference< css::registry::XRegistryKey > SimpleRegistry::getRootKey()
1225cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1226cdf0e10cSrcweir {
1227cdf0e10cSrcweir     osl::MutexGuard guard(mutex_);
1228cdf0e10cSrcweir     if (textual_.get() != 0) {
1229cdf0e10cSrcweir         return textual_->getRootKey();
1230cdf0e10cSrcweir     }
1231cdf0e10cSrcweir     RegistryKey root;
1232cdf0e10cSrcweir     RegError err = registry_.openRootKey(root);
1233cdf0e10cSrcweir     if (err != REG_NO_ERROR) {
1234cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1235cdf0e10cSrcweir             (rtl::OUString(
1236cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1237cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry.getRootKey:"
1238cdf0e10cSrcweir                     " underlying Registry::getRootKey() = ")) +
1239cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1240cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1241cdf0e10cSrcweir     }
1242cdf0e10cSrcweir     return new Key(this, root);
1243cdf0e10cSrcweir }
1244cdf0e10cSrcweir 
isReadOnly()1245cdf0e10cSrcweir sal_Bool SimpleRegistry::isReadOnly()
1246cdf0e10cSrcweir     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir     osl::MutexGuard guard(mutex_);
1249cdf0e10cSrcweir     return textual_.get() != 0 || registry_.isReadOnly();
1250cdf0e10cSrcweir }
1251cdf0e10cSrcweir 
mergeKey(rtl::OUString const & aKeyName,rtl::OUString const & aUrl)1252cdf0e10cSrcweir void SimpleRegistry::mergeKey(
1253cdf0e10cSrcweir     rtl::OUString const & aKeyName, rtl::OUString const & aUrl)
1254cdf0e10cSrcweir     throw (
1255cdf0e10cSrcweir         css::registry::InvalidRegistryException,
1256cdf0e10cSrcweir         css::registry::MergeConflictException, css::uno::RuntimeException)
1257cdf0e10cSrcweir {
1258cdf0e10cSrcweir     osl::MutexGuard guard(mutex_);
1259cdf0e10cSrcweir     if (textual_.get() != 0) {
1260cdf0e10cSrcweir         throw css::uno::RuntimeException(
1261cdf0e10cSrcweir             rtl::OUString(
1262cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1263cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry.mergeKey: not"
1264cdf0e10cSrcweir                     " supported for textual representation")),
1265cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >(this));
1266cdf0e10cSrcweir     }
1267cdf0e10cSrcweir     RegistryKey root;
1268cdf0e10cSrcweir     RegError err = registry_.openRootKey(root);
1269cdf0e10cSrcweir     if (err == REG_NO_ERROR) {
1270cdf0e10cSrcweir         err = registry_.mergeKey(root, aKeyName, aUrl, false, false);
1271cdf0e10cSrcweir     }
1272cdf0e10cSrcweir     switch (err) {
1273cdf0e10cSrcweir     case REG_NO_ERROR:
1274cdf0e10cSrcweir     case REG_MERGE_CONFLICT:
1275cdf0e10cSrcweir         break;
1276cdf0e10cSrcweir     case REG_MERGE_ERROR:
1277cdf0e10cSrcweir         throw css::registry::MergeConflictException(
1278cdf0e10cSrcweir             rtl::OUString(
1279cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1280cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry.mergeKey:"
1281cdf0e10cSrcweir                     " underlying Registry::mergeKey() = REG_MERGE_ERROR")),
1282cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >(this));
1283cdf0e10cSrcweir     default:
1284cdf0e10cSrcweir         throw css::registry::InvalidRegistryException(
1285cdf0e10cSrcweir             (rtl::OUString(
1286cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1287cdf0e10cSrcweir                     "com.sun.star.registry.SimpleRegistry.mergeKey:"
1288cdf0e10cSrcweir                     " underlying Registry::getRootKey/mergeKey() = ")) +
1289cdf0e10cSrcweir              rtl::OUString::valueOf(static_cast< sal_Int32 >(err))),
1290cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
1291cdf0e10cSrcweir     }
1292cdf0e10cSrcweir }
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir }
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir namespace stoc_bootstrap {
1297cdf0e10cSrcweir 
SimpleRegistry_CreateInstance(css::uno::Reference<css::uno::XComponentContext> const &)1298cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SimpleRegistry_CreateInstance(
1299cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const &)
1300cdf0e10cSrcweir {
1301cdf0e10cSrcweir     return static_cast< cppu::OWeakObject * >(new SimpleRegistry);
1302cdf0e10cSrcweir }
1303cdf0e10cSrcweir 
simreg_getSupportedServiceNames()1304cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > simreg_getSupportedServiceNames() {
1305cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > names(1);
1306cdf0e10cSrcweir     names[0] = rtl::OUString(
1307cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.SimpleRegistry"));
1308cdf0e10cSrcweir     return names;
1309cdf0e10cSrcweir }
1310cdf0e10cSrcweir 
simreg_getImplementationName()1311cdf0e10cSrcweir rtl::OUString simreg_getImplementationName() {
1312cdf0e10cSrcweir     return rtl::OUString(
1313cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry"));
1314cdf0e10cSrcweir }
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir }
1317