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