Branch data 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 : :
21 : : #include <registry/registry.h>
22 : : #include <registry/registry.hxx>
23 : :
24 : : #include <osl/process.h>
25 : :
26 : : #include "keyimpl.hxx"
27 : : #include "regimpl.hxx"
28 : : #include "regkey.hxx"
29 : :
30 : : #if defined(WIN32) || defined(WNT)
31 : : #include <io.h>
32 : : #endif
33 : :
34 : : #include <string.h>
35 : : #if defined(UNX)
36 : : #include <stdlib.h>
37 : : #include <unistd.h>
38 : : #endif
39 : :
40 : : extern "C" {
41 : :
42 : : //*********************************************************************
43 : : // acquire
44 : : //
45 : 2434180 : static void REGISTRY_CALLTYPE acquire(RegHandle hReg)
46 : : {
47 : 2434180 : ORegistry* pReg = (ORegistry*) hReg;
48 : :
49 [ + - ]: 2434180 : if (pReg != NULL)
50 : 2434180 : pReg->acquire();
51 : 2434180 : }
52 : :
53 : :
54 : : //*********************************************************************
55 : : // release
56 : : //
57 : 2433997 : static void REGISTRY_CALLTYPE release(RegHandle hReg)
58 : : {
59 : 2433997 : ORegistry* pReg = (ORegistry*) hReg;
60 : :
61 [ + - ]: 2433997 : if (pReg)
62 : : {
63 [ + + ]: 2433997 : if (pReg->release() == 0)
64 : : {
65 [ + - ]: 6912 : delete pReg;
66 : 6912 : hReg = NULL;
67 : : }
68 : : }
69 : 2433997 : }
70 : :
71 : :
72 : : //*********************************************************************
73 : : // getName
74 : : //
75 : 0 : static RegError REGISTRY_CALLTYPE getName(RegHandle hReg, rtl_uString** pName)
76 : : {
77 : : ORegistry* pReg;
78 : :
79 [ # # ]: 0 : if (hReg)
80 : : {
81 : 0 : pReg = (ORegistry*)hReg;
82 [ # # ]: 0 : if ( pReg->isOpen() )
83 : : {
84 : 0 : rtl_uString_assign(pName, pReg->getName().pData);
85 : 0 : return REG_NO_ERROR;
86 : : } else
87 : : {
88 : 0 : rtl_uString_new(pName);
89 : 0 : return REG_REGISTRY_NOT_OPEN;
90 : : }
91 : : }
92 : :
93 : 0 : rtl_uString_new(pName);
94 : 0 : return REG_INVALID_REGISTRY;
95 : : }
96 : :
97 : :
98 : : //*********************************************************************
99 : : // isReadOnly
100 : : //
101 : 0 : static sal_Bool REGISTRY_CALLTYPE isReadOnly(RegHandle hReg)
102 : : {
103 [ # # ]: 0 : if (hReg)
104 : 0 : return ((ORegistry*)hReg)->isReadOnly();
105 : : else
106 : 0 : return sal_False;
107 : : }
108 : :
109 : :
110 : : //*********************************************************************
111 : : // createRegistry
112 : : //
113 : 6251 : static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
114 : : RegHandle* phRegistry)
115 : : {
116 : : RegError ret;
117 : :
118 [ + - ]: 6251 : ORegistry* pReg = new ORegistry();
119 [ + - ][ - + ]: 6251 : if ((ret = pReg->initRegistry(registryName, REG_CREATE)))
120 : : {
121 : 0 : *phRegistry = NULL;
122 : 0 : return ret;
123 : : }
124 : :
125 : 6251 : *phRegistry = pReg;
126 : :
127 : 6251 : return REG_NO_ERROR;
128 : : }
129 : :
130 : : //*********************************************************************
131 : : // openRootKey
132 : : //
133 : 1311914 : static RegError REGISTRY_CALLTYPE openRootKey(RegHandle hReg,
134 : : RegKeyHandle* phRootKey)
135 : : {
136 : : ORegistry* pReg;
137 : :
138 [ + - ]: 1311914 : if (hReg)
139 : : {
140 : 1311914 : pReg = (ORegistry*)hReg;
141 [ - + ]: 1311914 : if (!pReg->isOpen())
142 : 0 : return REG_REGISTRY_NOT_OPEN;
143 : : } else
144 : : {
145 : 0 : phRootKey = NULL;
146 : 0 : return REG_INVALID_REGISTRY;
147 : : }
148 : :
149 : 1311914 : *phRootKey = pReg->getRootKey();
150 : :
151 : 1311914 : return REG_NO_ERROR;
152 : : }
153 : :
154 : :
155 : : //*********************************************************************
156 : : // openRegistry
157 : : //
158 : 2532 : static RegError REGISTRY_CALLTYPE openRegistry(rtl_uString* registryName,
159 : : RegHandle* phRegistry,
160 : : RegAccessMode accessMode)
161 : : {
162 : : RegError _ret;
163 : :
164 [ + - ]: 2532 : ORegistry* pReg = new ORegistry();
165 [ + - ][ + + ]: 2532 : if ((_ret = pReg->initRegistry(registryName, accessMode)))
166 : : {
167 : 866 : *phRegistry = NULL;
168 [ + - ]: 866 : delete pReg;
169 : 866 : return _ret;
170 : : }
171 : :
172 : :
173 : 1666 : *phRegistry = pReg;
174 : :
175 : 2532 : return REG_NO_ERROR;
176 : : }
177 : :
178 : : //*********************************************************************
179 : : // closeRegistry
180 : : //
181 : 6256 : static RegError REGISTRY_CALLTYPE closeRegistry(RegHandle hReg)
182 : : {
183 : : ORegistry *pReg;
184 : :
185 [ + - ]: 6256 : if (hReg)
186 : : {
187 : 6256 : pReg = (ORegistry*)hReg;
188 [ - + ]: 6256 : if (!pReg->isOpen())
189 : 0 : return REG_REGISTRY_NOT_OPEN;
190 : :
191 : 6256 : RegError ret = REG_NO_ERROR;
192 [ + + ]: 6256 : if (pReg->release() == 0)
193 : : {
194 [ + - ]: 254 : delete(pReg);
195 : 254 : hReg = NULL;
196 : : }
197 : : else
198 : 6002 : ret = pReg->closeRegistry();
199 : :
200 : 6256 : return ret;
201 : : } else
202 : : {
203 : 6256 : return REG_INVALID_REGISTRY;
204 : : }
205 : : }
206 : :
207 : :
208 : : //*********************************************************************
209 : : // destroyRegistry
210 : : //
211 : 0 : static RegError REGISTRY_CALLTYPE destroyRegistry(RegHandle hReg,
212 : : rtl_uString* registryName)
213 : : {
214 : : ORegistry *pReg;
215 : :
216 [ # # ]: 0 : if (hReg)
217 : : {
218 : 0 : pReg = (ORegistry*)hReg;
219 [ # # ]: 0 : if (!pReg->isOpen())
220 : 0 : return REG_INVALID_REGISTRY;
221 : :
222 [ # # ]: 0 : RegError ret = pReg->destroyRegistry(registryName);
223 [ # # ]: 0 : if (!ret)
224 : : {
225 [ # # ]: 0 : if (!registryName->length)
226 : : {
227 [ # # ]: 0 : delete(pReg);
228 : 0 : hReg = NULL;
229 : : }
230 : : }
231 : 0 : return ret;
232 : : } else
233 : : {
234 : 0 : return REG_INVALID_REGISTRY;
235 : : }
236 : : }
237 : :
238 : :
239 : : //*********************************************************************
240 : : // loadRegKey
241 : : //
242 : 0 : static RegError REGISTRY_CALLTYPE loadKey(RegHandle hReg,
243 : : RegKeyHandle hKey,
244 : : rtl_uString* keyName,
245 : : rtl_uString* regFileName)
246 : : {
247 : :
248 : 0 : ORegistry* pReg = static_cast< ORegistry* >(hReg);
249 [ # # ]: 0 : if (!pReg)
250 : 0 : return REG_INVALID_REGISTRY;
251 : :
252 [ # # ]: 0 : if (!pReg->isOpen())
253 : 0 : return REG_REGISTRY_NOT_OPEN;
254 : :
255 : 0 : ORegKey* pKey = static_cast< ORegKey* >(hKey);
256 [ # # ]: 0 : if (!pKey)
257 : 0 : return REG_INVALID_KEY;
258 : :
259 [ # # ]: 0 : if (pKey->getRegistry() != pReg)
260 : 0 : return REG_INVALID_KEY;
261 [ # # ]: 0 : if (pKey->isDeleted())
262 : 0 : return REG_INVALID_KEY;
263 [ # # ]: 0 : if (pKey->isReadOnly())
264 : 0 : return REG_REGISTRY_READONLY;
265 : :
266 : :
267 : 0 : ORegKey* pNewKey = 0;
268 [ # # ]: 0 : RegError _ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey);
269 [ # # ]: 0 : if (_ret == REG_NO_ERROR)
270 : : {
271 [ # # ]: 0 : pKey->releaseKey(pNewKey);
272 [ # # ]: 0 : pKey->deleteKey(keyName);
273 : : }
274 : :
275 [ # # ]: 0 : _ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey);
276 [ # # ]: 0 : if (_ret != REG_NO_ERROR)
277 : 0 : return _ret;
278 : :
279 [ # # ]: 0 : _ret = pReg->loadKey(pNewKey, regFileName);
280 [ # # ]: 0 : if (_ret != REG_NO_ERROR)
281 : : {
282 [ # # ]: 0 : pKey->releaseKey(pNewKey);
283 [ # # ]: 0 : pKey->deleteKey(keyName);
284 : 0 : return _ret;
285 : : }
286 : :
287 [ # # ]: 0 : return pKey->closeKey(pNewKey);
288 : : }
289 : :
290 : : //*********************************************************************
291 : : // saveKey
292 : : //
293 : 0 : static RegError REGISTRY_CALLTYPE saveKey(RegHandle hReg,
294 : : RegKeyHandle hKey,
295 : : rtl_uString* keyName,
296 : : rtl_uString* regFileName)
297 : : {
298 : :
299 : 0 : ORegistry* pReg = static_cast< ORegistry* >(hReg);
300 [ # # ]: 0 : if (!pReg)
301 : 0 : return REG_INVALID_REGISTRY;
302 : :
303 [ # # ]: 0 : if (!pReg->isOpen())
304 : 0 : return REG_REGISTRY_NOT_OPEN;
305 : :
306 : 0 : ORegKey* pKey = static_cast< ORegKey* >(hKey);
307 [ # # ]: 0 : if (!pKey)
308 : 0 : return REG_INVALID_KEY;
309 : :
310 [ # # ]: 0 : if (pKey->getRegistry() != pReg)
311 : 0 : return REG_INVALID_KEY;
312 [ # # ]: 0 : if (pKey->isDeleted())
313 : 0 : return REG_INVALID_KEY;
314 : :
315 : 0 : ORegKey* pNewKey = 0;
316 [ # # ]: 0 : RegError _ret = pKey->openKey(keyName, (RegKeyHandle*)&pNewKey);
317 [ # # ]: 0 : if (_ret != REG_NO_ERROR)
318 : 0 : return _ret;
319 : :
320 [ # # ]: 0 : _ret = pReg->saveKey(pNewKey, regFileName);
321 [ # # ]: 0 : if (_ret != REG_NO_ERROR)
322 : : {
323 [ # # ]: 0 : (void) pKey->releaseKey(pNewKey);
324 : 0 : return _ret;
325 : : }
326 : :
327 [ # # ]: 0 : return pKey->releaseKey(pNewKey);
328 : : }
329 : :
330 : : //*********************************************************************
331 : : // mergeKey
332 : : //
333 : 9474 : static RegError REGISTRY_CALLTYPE mergeKey(RegHandle hReg,
334 : : RegKeyHandle hKey,
335 : : rtl_uString* keyName,
336 : : rtl_uString* regFileName,
337 : : sal_Bool bWarnings,
338 : : sal_Bool bReport)
339 : : {
340 : 9474 : ORegistry* pReg = static_cast< ORegistry* >(hReg);
341 [ - + ]: 9474 : if (!pReg)
342 : 0 : return REG_INVALID_REGISTRY;
343 [ - + ]: 9474 : if (!pReg->isOpen())
344 : 0 : return REG_REGISTRY_NOT_OPEN;
345 : :
346 : 9474 : ORegKey* pKey = static_cast< ORegKey* >(hKey);
347 [ - + ]: 9474 : if (!pKey)
348 : 0 : return REG_INVALID_KEY;
349 [ - + ]: 9474 : if (pKey->getRegistry() != pReg)
350 : 0 : return REG_INVALID_KEY;
351 [ - + ]: 9474 : if (pKey->isDeleted())
352 : 0 : return REG_INVALID_KEY;
353 [ - + ]: 9474 : if (pKey->isReadOnly())
354 : 0 : return REG_REGISTRY_READONLY;
355 : :
356 [ + - ]: 9474 : if (keyName->length)
357 : : {
358 : 9474 : ORegKey* pNewKey = 0;
359 [ + - ]: 9474 : RegError _ret = pKey->createKey(keyName, (RegKeyHandle*)&pNewKey);
360 [ - + ]: 9474 : if (_ret != REG_NO_ERROR)
361 : 0 : return _ret;
362 : :
363 [ + - ]: 9474 : _ret = pReg->loadKey(pNewKey, regFileName, bWarnings, bReport);
364 [ + + ][ - + ]: 9474 : if (_ret == REG_MERGE_ERROR || (_ret == REG_MERGE_CONFLICT && bWarnings))
[ + - ]
365 : : {
366 [ # # ]: 0 : if (pNewKey != pKey)
367 [ # # ]: 0 : (void) pKey->closeKey(pNewKey);
368 : : else
369 [ # # ]: 0 : (void) pKey->releaseKey(pNewKey);
370 : 0 : return _ret;
371 : : }
372 : :
373 [ + + ][ + - ]: 9474 : return (pNewKey != pKey) ? pKey->closeKey(pNewKey) : pKey->releaseKey(pNewKey);
[ + - ]
374 : : }
375 : :
376 [ # # ]: 9474 : return pReg->loadKey(pKey, regFileName, bWarnings, bReport);
377 : : }
378 : :
379 : : //*********************************************************************
380 : : // dumpRegistry
381 : : //
382 : 0 : static RegError REGISTRY_CALLTYPE dumpRegistry(RegHandle hReg,
383 : : RegKeyHandle hKey)
384 : : {
385 : 0 : ORegistry* pReg = static_cast< ORegistry* >(hReg);
386 [ # # ]: 0 : if (!pReg)
387 : 0 : return REG_INVALID_REGISTRY;
388 [ # # ]: 0 : if (!pReg->isOpen())
389 : 0 : return REG_REGISTRY_NOT_OPEN;
390 : :
391 : 0 : ORegKey* pKey = static_cast< ORegKey* >(hKey);
392 [ # # ]: 0 : if (!pKey)
393 : 0 : return REG_INVALID_KEY;
394 [ # # ]: 0 : if (pKey->getRegistry() != pReg)
395 : 0 : return REG_INVALID_KEY;
396 [ # # ]: 0 : if (pKey->isDeleted())
397 : 0 : return REG_INVALID_KEY;
398 : :
399 : 0 : return pReg->dumpRegistry(hKey);
400 : : }
401 : :
402 : : //*********************************************************************
403 : : // initRegistry_Api
404 : : //
405 : 2077425 : REG_DLLPUBLIC Registry_Api* REGISTRY_CALLTYPE initRegistry_Api(void)
406 : : {
407 : : static Registry_Api aApi= {&acquire,
408 : : &release,
409 : : &isReadOnly,
410 : : &openRootKey,
411 : : &getName,
412 : : &createRegistry,
413 : : &openRegistry,
414 : : &closeRegistry,
415 : : &destroyRegistry,
416 : : &loadKey,
417 : : &saveKey,
418 : : &mergeKey,
419 : : &dumpRegistry,
420 : : &acquireKey,
421 : : &releaseKey,
422 : : &isKeyReadOnly,
423 : : &getKeyName,
424 : : &createKey,
425 : : &openKey,
426 : : &openSubKeys,
427 : : &closeSubKeys,
428 : : &deleteKey,
429 : : &closeKey,
430 : : &setValue,
431 : : &setLongListValue,
432 : : &setStringListValue,
433 : : &setUnicodeListValue,
434 : : &getValueInfo,
435 : : &getValue,
436 : : &getLongListValue,
437 : : &getStringListValue,
438 : : &getUnicodeListValue,
439 : : &freeValueList,
440 : : &createLink,
441 : : &deleteLink,
442 : : &getKeyType,
443 : : &getLinkTarget,
444 : : &getResolvedKeyName,
445 : : &getKeyNames,
446 : : &freeKeyNames};
447 : :
448 : 2077425 : return (&aApi);
449 : : }
450 : :
451 : : }
452 : :
453 : : //*********************************************************************
454 : : // reg_loadRegKey
455 : : //
456 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_loadKey(RegKeyHandle hKey,
457 : : rtl_uString* keyName,
458 : : rtl_uString* regFileName)
459 : : {
460 : : ORegKey *pKey;
461 : :
462 [ # # ]: 0 : if (hKey)
463 : 0 : pKey = (ORegKey*)hKey;
464 : : else
465 : 0 : return REG_INVALID_KEY;
466 : :
467 : 0 : return loadKey(pKey->getRegistry(), hKey, keyName, regFileName);
468 : : }
469 : :
470 : : //*********************************************************************
471 : : // reg_saveKey
472 : : //
473 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_saveKey(RegKeyHandle hKey,
474 : : rtl_uString* keyName,
475 : : rtl_uString* regFileName)
476 : : {
477 : : ORegKey *pKey;
478 : :
479 [ # # ]: 0 : if (hKey)
480 : 0 : pKey = (ORegKey*)hKey;
481 : : else
482 : 0 : return REG_INVALID_KEY;
483 : :
484 : 0 : return saveKey(pKey->getRegistry(), hKey, keyName, regFileName);
485 : : }
486 : :
487 : : //*********************************************************************
488 : : // reg_mergeKey
489 : : //
490 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_mergeKey(RegKeyHandle hKey,
491 : : rtl_uString* keyName,
492 : : rtl_uString* regFileName,
493 : : sal_Bool bWarnings,
494 : : sal_Bool bReport)
495 : : {
496 : : ORegKey *pKey;
497 : :
498 [ # # ]: 0 : if (hKey)
499 : 0 : pKey = (ORegKey*)hKey;
500 : : else
501 : 0 : return REG_INVALID_KEY;
502 : :
503 : 0 : return mergeKey(pKey->getRegistry(), hKey, keyName, regFileName, bWarnings, bReport);
504 : : }
505 : :
506 : : //*********************************************************************
507 : : // reg_createRegistry
508 : : //
509 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_createRegistry(rtl_uString* registryName,
510 : : RegHandle* phRegistry)
511 : : {
512 : : RegError ret;
513 : :
514 [ # # ]: 0 : ORegistry* pReg = new ORegistry();
515 [ # # ][ # # ]: 0 : if ((ret = pReg->initRegistry(registryName, REG_CREATE)))
516 : : {
517 : 0 : *phRegistry = NULL;
518 : 0 : return ret;
519 : : }
520 : :
521 : 0 : *phRegistry = pReg;
522 : :
523 : 0 : return REG_NO_ERROR;
524 : : }
525 : :
526 : : //*********************************************************************
527 : : // reg_openRootKey
528 : : //
529 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_openRootKey(RegHandle hRegistry,
530 : : RegKeyHandle* phRootKey)
531 : : {
532 : 0 : return openRootKey(hRegistry, phRootKey);
533 : : }
534 : :
535 : :
536 : : //*********************************************************************
537 : : // reg_getName
538 : : //
539 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_getName(RegHandle hRegistry, rtl_uString** pName)
540 : : {
541 : 0 : return getName(hRegistry, pName);
542 : : }
543 : :
544 : :
545 : : //*********************************************************************
546 : : // reg_isReadOnly
547 : : //
548 : 0 : REG_DLLPUBLIC sal_Bool REGISTRY_CALLTYPE reg_isReadOnly(RegHandle hRegistry)
549 : : {
550 : 0 : return isReadOnly(hRegistry);
551 : : }
552 : :
553 : :
554 : : //*********************************************************************
555 : : // reg_openRegistry
556 : : //
557 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
558 : : RegHandle* phRegistry,
559 : : RegAccessMode accessMode)
560 : : {
561 : : RegError _ret;
562 : :
563 [ # # ]: 0 : ORegistry* pReg = new ORegistry();
564 [ # # ][ # # ]: 0 : if ((_ret = pReg->initRegistry(registryName, accessMode)))
565 : : {
566 : 0 : *phRegistry = NULL;
567 : 0 : return _ret;
568 : : }
569 : :
570 : 0 : *phRegistry = pReg;
571 : :
572 : 0 : return REG_NO_ERROR;
573 : : }
574 : :
575 : : //*********************************************************************
576 : : // reg_closeRegistry
577 : : //
578 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_closeRegistry(RegHandle hRegistry)
579 : : {
580 : : ORegistry* pReg;
581 : :
582 [ # # ]: 0 : if (hRegistry)
583 : : {
584 : 0 : pReg = (ORegistry*)hRegistry;
585 [ # # ]: 0 : delete(pReg);
586 : 0 : return REG_NO_ERROR;
587 : : } else
588 : : {
589 : 0 : return REG_REGISTRY_NOT_OPEN;
590 : : }
591 : : }
592 : :
593 : :
594 : : //*********************************************************************
595 : : // reg_destroyRegistry
596 : : //
597 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_destroyRegistry(RegHandle hRegistry,
598 : : rtl_uString* registryName)
599 : : {
600 : 0 : return destroyRegistry(hRegistry, registryName);
601 : : }
602 : :
603 : :
604 : : //*********************************************************************
605 : : // reg_dumpRegistry
606 : : //
607 : 0 : REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_dumpRegistry(RegKeyHandle hKey)
608 : : {
609 : : ORegKey *pKey;
610 : :
611 [ # # ]: 0 : if (hKey)
612 : 0 : pKey = (ORegKey*)hKey;
613 : : else
614 : 0 : return REG_INVALID_KEY;
615 : :
616 : 0 : return dumpRegistry(pKey->getRegistry(), hKey);
617 : : }
618 : :
619 : :
620 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|