LibreOffice Module registry (master)  1
regimpl.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
21 #include "regimpl.hxx"
22 
23 #include <memory>
24 #include <set>
25 #include <vector>
26 #include <string.h>
27 #include <stdio.h>
28 
29 #if defined(UNX)
30 #include <unistd.h>
31 #endif
32 
33 #include "reflread.hxx"
34 
35 #include "reflwrit.hxx"
36 
37 #include <registry/reader.hxx>
38 #include <registry/refltype.hxx>
39 #include <registry/types.hxx>
40 
41 #include "reflcnst.hxx"
42 #include "keyimpl.hxx"
43 
44 #include <osl/thread.h>
45 #include <rtl/ustring.hxx>
46 #include <rtl/ustrbuf.hxx>
47 #include <osl/file.hxx>
48 
49 using namespace osl;
50 using namespace store;
51 
52 
53 namespace {
54 
55 void printString(OUString const & s) {
56  printf("\"");
57  for (sal_Int32 i = 0; i < s.getLength(); ++i) {
58  sal_Unicode c = s[i];
59  if (c == '"' || c == '\\') {
60  printf("\\%c", static_cast< char >(c));
61  } else if (s[i] >= ' ' && s[i] <= '~') {
62  printf("%c", static_cast< char >(c));
63  } else {
64  printf("\\u%04X", static_cast< unsigned int >(c));
65  }
66  }
67  printf("\"");
68 }
69 
70 void printFieldOrReferenceFlag(
71  RTFieldAccess * flags, RTFieldAccess flag, char const * name, bool * first)
72 {
73  if ((*flags & flag) != RTFieldAccess::NONE) {
74  if (!*first) {
75  printf("|");
76  }
77  *first = false;
78  printf("%s", name);
79  *flags &= ~flag;
80  }
81 }
82 
83 void printFieldOrReferenceFlags(RTFieldAccess flags) {
84  if (flags == RTFieldAccess::NONE) {
85  printf("none");
86  } else {
87  bool first = true;
88  printFieldOrReferenceFlag(
89  &flags, RTFieldAccess::READONLY, "readonly", &first);
90  printFieldOrReferenceFlag(
91  &flags, RTFieldAccess::OPTIONAL, "optional", &first);
92  printFieldOrReferenceFlag(
93  &flags, RTFieldAccess::MAYBEVOID, "maybevoid", &first);
94  printFieldOrReferenceFlag(&flags, RTFieldAccess::BOUND, "bound", &first);
95  printFieldOrReferenceFlag(
96  &flags, RTFieldAccess::CONSTRAINED, "constrained", &first);
97  printFieldOrReferenceFlag(
98  &flags, RTFieldAccess::TRANSIENT, "transient", &first);
99  printFieldOrReferenceFlag(
100  &flags, RTFieldAccess::MAYBEAMBIGUOUS, "maybeambiguous", &first);
101  printFieldOrReferenceFlag(
102  &flags, RTFieldAccess::MAYBEDEFAULT, "maybedefault", &first);
103  printFieldOrReferenceFlag(
104  &flags, RTFieldAccess::REMOVABLE, "removable", &first);
105  printFieldOrReferenceFlag(
106  &flags, RTFieldAccess::ATTRIBUTE, "attribute", &first);
107  printFieldOrReferenceFlag(
108  &flags, RTFieldAccess::PROPERTY, "property", &first);
109  printFieldOrReferenceFlag(&flags, RTFieldAccess::CONST, "const", &first);
110  printFieldOrReferenceFlag(
111  &flags, RTFieldAccess::READWRITE, "readwrite", &first);
112  printFieldOrReferenceFlag(
113  &flags, RTFieldAccess::PARAMETERIZED_TYPE, "parameterized type", &first);
114  printFieldOrReferenceFlag(
115  &flags, RTFieldAccess::PUBLISHED, "published", &first);
116  if (flags != RTFieldAccess::NONE) {
117  if (!first) {
118  printf("|");
119  }
120  printf("<invalid (0x%04X)>", static_cast< unsigned int >(flags));
121  }
122  }
123 }
124 
125 void dumpType(typereg::Reader const & reader, OString const & indent) {
126  if (reader.isValid()) {
127  printf("version: %ld\n", static_cast< long >(reader.getVersion()));
128  printf("%sdocumentation: ", indent.getStr());
129  printString(reader.getDocumentation());
130  printf("\n");
131  printf("%sfile name: ", indent.getStr());
132  printString(reader.getFileName());
133  printf("\n");
134  printf("%stype class: ", indent.getStr());
135  if (reader.isPublished()) {
136  printf("published ");
137  }
138  switch (reader.getTypeClass()) {
139  case RT_TYPE_INTERFACE:
140  printf("interface");
141  break;
142 
143  case RT_TYPE_MODULE:
144  printf("module");
145  break;
146 
147  case RT_TYPE_STRUCT:
148  printf("struct");
149  break;
150 
151  case RT_TYPE_ENUM:
152  printf("enum");
153  break;
154 
155  case RT_TYPE_EXCEPTION:
156  printf("exception");
157  break;
158 
159  case RT_TYPE_TYPEDEF:
160  printf("typedef");
161  break;
162 
163  case RT_TYPE_SERVICE:
164  printf("service");
165  break;
166 
167  case RT_TYPE_SINGLETON:
168  printf("singleton");
169  break;
170 
171  case RT_TYPE_CONSTANTS:
172  printf("constants");
173  break;
174 
175  default:
176  printf(
177  "<invalid (%ld)>", static_cast< long >(reader.getTypeClass()));
178  break;
179  }
180  printf("\n");
181  printf("%stype name: ", indent.getStr());
182  printString(reader.getTypeName());
183  printf("\n");
184  printf(
185  "%ssuper type count: %u\n", indent.getStr(),
186  static_cast< unsigned int >(reader.getSuperTypeCount()));
187  for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
188  printf(
189  "%ssuper type name %u: ", indent.getStr(),
190  static_cast< unsigned int >(i));
191  printString(reader.getSuperTypeName(i));
192  printf("\n");
193  }
194  printf(
195  "%sfield count: %u\n", indent.getStr(),
196  static_cast< unsigned int >(reader.getFieldCount()));
197  for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
198  printf(
199  "%sfield %u:\n", indent.getStr(),
200  static_cast< unsigned int >(i));
201  printf("%s documentation: ", indent.getStr());
202  printString(reader.getFieldDocumentation(i));
203  printf("\n");
204  printf("%s file name: ", indent.getStr());
205  printString(reader.getFieldFileName(i));
206  printf("\n");
207  printf("%s flags: ", indent.getStr());
208  printFieldOrReferenceFlags(reader.getFieldFlags(i));
209  printf("\n");
210  printf("%s name: ", indent.getStr());
211  printString(reader.getFieldName(i));
212  printf("\n");
213  printf("%s type name: ", indent.getStr());
214  printString(reader.getFieldTypeName(i));
215  printf("\n");
216  printf("%s value: ", indent.getStr());
217  RTConstValue value(reader.getFieldValue(i));
218  switch (value.m_type) {
219  case RT_TYPE_NONE:
220  printf("none");
221  break;
222 
223  case RT_TYPE_BOOL:
224  printf("boolean %s", value.m_value.aBool ? "true" : "false");
225  break;
226 
227  case RT_TYPE_BYTE:
228  printf("byte %d", static_cast< int >(value.m_value.aByte));
229  break;
230 
231  case RT_TYPE_INT16:
232  printf("short %d", static_cast< int >(value.m_value.aShort));
233  break;
234 
235  case RT_TYPE_UINT16:
236  printf(
237  "unsigned short %u",
238  static_cast< unsigned int >(value.m_value.aUShort));
239  break;
240 
241  case RT_TYPE_INT32:
242  printf("long %ld", static_cast< long >(value.m_value.aLong));
243  break;
244 
245  case RT_TYPE_UINT32:
246  printf(
247  "unsigned long %lu",
248  static_cast< unsigned long >(value.m_value.aULong));
249  break;
250 
251  case RT_TYPE_INT64:
252  // TODO: no portable way to print hyper values
253  printf("hyper");
254  break;
255 
256  case RT_TYPE_UINT64:
257  // TODO: no portable way to print unsigned hyper values
258  printf("unsigned hyper");
259  break;
260 
261  case RT_TYPE_FLOAT:
262  // TODO: no portable way to print float values
263  printf("float");
264  break;
265 
266  case RT_TYPE_DOUBLE:
267  // TODO: no portable way to print double values
268  printf("double");
269  break;
270 
271  case RT_TYPE_STRING:
272  printf("string ");
273  printString(value.m_value.aString);
274  break;
275 
276  default:
277  printf("<invalid (%ld)>", static_cast< long >(value.m_type));
278  break;
279  }
280  printf("\n");
281  }
282  printf(
283  "%smethod count: %u\n", indent.getStr(),
284  static_cast< unsigned int >(reader.getMethodCount()));
285  for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) {
286  printf(
287  "%smethod %u:\n", indent.getStr(),
288  static_cast< unsigned int >(i));
289  printf("%s documentation: ", indent.getStr());
290  printString(reader.getMethodDocumentation(i));
291  printf("\n");
292  printf("%s flags: ", indent.getStr());
293  switch (reader.getMethodFlags(i)) {
295  printf("oneway");
296  break;
297 
299  printf("synchronous");
300  break;
301 
303  printf("attribute get");
304  break;
305 
307  printf("attribute set");
308  break;
309 
310  default:
311  printf(
312  "<invalid (%ld)>",
313  static_cast< long >(reader.getMethodFlags(i)));
314  break;
315  }
316  printf("\n");
317  printf("%s name: ", indent.getStr());
318  printString(reader.getMethodName(i));
319  printf("\n");
320  printf("%s return type name: ", indent.getStr());
321  printString(reader.getMethodReturnTypeName(i));
322  printf("\n");
323  printf(
324  "%s parameter count: %u\n", indent.getStr(),
325  static_cast< unsigned int >(reader.getMethodParameterCount(i)));
326  // coverity[tainted_data] - cid#1215304 unhelpfully warns about untrusted loop bound
327  for (sal_uInt16 j = 0; j < reader.getMethodParameterCount(i); ++j)
328  {
329  printf(
330  "%s parameter %u:\n", indent.getStr(),
331  static_cast< unsigned int >(j));
332  printf("%s flags: ", indent.getStr());
333  RTParamMode flags = reader.getMethodParameterFlags(i, j);
334  bool rest = (flags & RT_PARAM_REST) != 0;
335  switch (flags & ~RT_PARAM_REST) {
336  case RT_PARAM_IN:
337  printf("in");
338  break;
339 
340  case RT_PARAM_OUT:
341  printf("out");
342  break;
343 
344  case RT_PARAM_INOUT:
345  printf("inout");
346  break;
347 
348  default:
349  printf("<invalid (%ld)>", static_cast< long >(flags));
350  rest = false;
351  break;
352  }
353  if (rest) {
354  printf("|rest");
355  }
356  printf("\n");
357  printf("%s name: ", indent.getStr());
358  printString(reader.getMethodParameterName(i, j));
359  printf("\n");
360  printf("%s type name: ", indent.getStr());
361  printString(reader.getMethodParameterTypeName(i, j));
362  printf("\n");
363  }
364  printf(
365  "%s exception count: %u\n", indent.getStr(),
366  static_cast< unsigned int >(reader.getMethodExceptionCount(i)));
367  // coverity[tainted_data] - cid#1215304 unhelpfully warns about untrusted loop bound
368  for (sal_uInt16 j = 0; j < reader.getMethodExceptionCount(i); ++j)
369  {
370  printf(
371  "%s exception type name %u: ", indent.getStr(),
372  static_cast< unsigned int >(j));
373  printString(reader.getMethodExceptionTypeName(i, j));
374  printf("\n");
375  }
376  }
377  printf(
378  "%sreference count: %u\n", indent.getStr(),
379  static_cast< unsigned int >(reader.getReferenceCount()));
380  for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) {
381  printf(
382  "%sreference %u:\n", indent.getStr(),
383  static_cast< unsigned int >(i));
384  printf("%s documentation: ", indent.getStr());
385  printString(reader.getReferenceDocumentation(i));
386  printf("\n");
387  printf("%s flags: ", indent.getStr());
388  printFieldOrReferenceFlags(reader.getReferenceFlags(i));
389  printf("\n");
390  printf("%s sort: ", indent.getStr());
391  switch (reader.getReferenceSort(i)) {
393  printf("supports");
394  break;
395 
397  printf("exports");
398  break;
399 
401  printf("type parameter");
402  break;
403 
404  default:
405  printf(
406  "<invalid (%ld)>",
407  static_cast< long >(reader.getReferenceSort(i)));
408  break;
409  }
410  printf("\n");
411  printf("%s type name: ", indent.getStr());
412  printString(reader.getReferenceTypeName(i));
413  printf("\n");
414  }
415  } else {
416  printf("<invalid>\n");
417  }
418 }
419 
420 }
421 
423  : m_refCount(1)
424  , m_readOnly(false)
425  , m_isOpen(false)
426 {
427 }
428 
430 {
431  ORegKey* pRootKey = m_openKeyTable[ROOT];
432  if (pRootKey != nullptr)
433  (void) releaseKey(pRootKey);
434 
435  if (m_file.isValid())
436  m_file.close();
437 }
438 
439 RegError ORegistry::initRegistry(const OUString& regName, RegAccessMode accessMode, bool bCreate)
440 {
442  OStoreFile rRegFile;
443  storeAccessMode sAccessMode = storeAccessMode::ReadWrite;
444  storeError errCode;
445 
446  if (bCreate)
447  {
448  sAccessMode = storeAccessMode::Create;
449  }
450  else if (accessMode & RegAccessMode::READONLY)
451  {
452  sAccessMode = storeAccessMode::ReadOnly;
453  m_readOnly = true;
454  }
455 
456  if (regName.isEmpty() &&
457  storeAccessMode::Create == sAccessMode)
458  {
459  errCode = rRegFile.createInMemory();
460  }
461  else
462  {
463  errCode = rRegFile.create(regName, sAccessMode);
464  }
465 
466  if (errCode)
467  {
468  switch (errCode)
469  {
470  case store_E_NotExists:
472  break;
475  break;
476  default:
478  break;
479  }
480  }
481  else
482  {
483  OStoreDirectory rStoreDir;
484  storeError _err = rStoreDir.create(rRegFile, OUString(), OUString(), sAccessMode);
485 
486  if (_err == store_E_None)
487  {
488  m_file = rRegFile;
489  m_name = regName;
490  m_isOpen = true;
491 
492  m_openKeyTable[ROOT] = new ORegKey(ROOT, this);
493  eRet = RegError::NO_ERROR;
494  }
495  else
497  }
498 
499  return eRet;
500 }
501 
503 {
505 
506  if (m_file.isValid())
507  {
509  m_file.close();
510  m_isOpen = false;
511  return RegError::NO_ERROR;
512  } else
513  {
515  }
516 }
517 
518 RegError ORegistry::destroyRegistry(const OUString& regName)
519 {
521 
522  if (!regName.isEmpty())
523  {
524  std::unique_ptr<ORegistry> pReg(new ORegistry());
525 
526  if (pReg->initRegistry(regName, RegAccessMode::READWRITE) == RegError::NO_ERROR)
527  {
528  pReg.reset();
529 
530  OUString systemName;
531  if (FileBase::getSystemPathFromFileURL(regName, systemName) != FileBase::E_None)
532  systemName = regName;
533 
534  OString name(OUStringToOString(systemName, osl_getThreadTextEncoding()));
535  if (unlink(name.getStr()) != 0)
536  {
538  }
539  } else
540  {
542  }
543  } else
544  {
545  if (m_refCount != 1 || isReadOnly())
546  {
548  }
549 
550  if (m_file.isValid())
551  {
553  m_file.close();
554  m_isOpen = false;
555 
556  if (!m_name.isEmpty())
557  {
558  OUString systemName;
559  if (FileBase::getSystemPathFromFileURL(m_name, systemName) != FileBase::E_None)
560  systemName = m_name;
561 
562  OString name(OUStringToOString(systemName, osl_getThreadTextEncoding()));
563  if (unlink(name.getStr()) != 0)
564  {
566  }
567  }
568  } else
569  {
571  }
572  }
573 
574  return RegError::NO_ERROR;
575 }
576 
578 {
579  ORegKey* pKey = static_cast< ORegKey* >(hKey);
580  if (!pKey)
581  return RegError::INVALID_KEY;
582 
584  pKey->acquire();
585 
586  return RegError::NO_ERROR;
587 }
588 
590 {
591  ORegKey* pKey = static_cast< ORegKey* >(hKey);
592  if (!pKey)
593  return RegError::INVALID_KEY;
594 
596  if (pKey->release() == 0)
597  {
598  m_openKeyTable.erase(pKey->getName());
599  delete pKey;
600  }
601  return RegError::NO_ERROR;
602 }
603 
604 RegError ORegistry::createKey(RegKeyHandle hKey, const OUString& keyName,
605  RegKeyHandle* phNewKey)
606 {
607  ORegKey* pKey;
608 
609  *phNewKey = nullptr;
610 
611  if (keyName.isEmpty())
613 
615 
616  if (hKey)
617  pKey = static_cast<ORegKey*>(hKey);
618  else
619  pKey = m_openKeyTable[ROOT];
620 
621  OUString sFullKeyName = pKey->getFullPath(keyName);
622 
623  if (m_openKeyTable.count(sFullKeyName) > 0)
624  {
625  *phNewKey = m_openKeyTable[sFullKeyName];
626  static_cast<ORegKey*>(*phNewKey)->acquire();
627  static_cast<ORegKey*>(*phNewKey)->setDeleted(false);
628  return RegError::NO_ERROR;
629  }
630 
631  OStoreDirectory rStoreDir;
632  OUStringBuffer sFullPath(sFullKeyName.getLength()+16);
633  OUString token;
634 
635  sFullPath.append('/');
636 
637  sal_Int32 nIndex = 0;
638  do
639  {
640  token = sFullKeyName.getToken(0, '/', nIndex);
641  if (!token.isEmpty())
642  {
643  if (rStoreDir.create(pKey->getStoreFile(), sFullPath.getStr(), token, storeAccessMode::Create))
644  {
646  }
647 
648  sFullPath.append(token);
649  sFullPath.append('/');
650  }
651  } while(nIndex != -1);
652 
653 
654  pKey = new ORegKey(sFullKeyName, this);
655  *phNewKey = pKey;
656  m_openKeyTable[sFullKeyName] = pKey;
657 
658  return RegError::NO_ERROR;
659 }
660 
661 RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName,
662  RegKeyHandle* phOpenKey)
663 {
664  ORegKey* pKey;
665 
666  *phOpenKey = nullptr;
667 
668  if (keyName.isEmpty())
669  {
671  }
672 
674 
675  if (hKey)
676  pKey = static_cast<ORegKey*>(hKey);
677  else
678  pKey = m_openKeyTable[ROOT];
679 
680  OUString path(pKey->getFullPath(keyName));
681  KeyMap::iterator i(m_openKeyTable.find(path));
682  if (i == m_openKeyTable.end()) {
683  sal_Int32 n = path.lastIndexOf('/') + 1;
684  switch (OStoreDirectory().create(
685  pKey->getStoreFile(), path.copy(0, n), path.copy(n),
686  isReadOnly() ? storeAccessMode::ReadOnly : storeAccessMode::ReadWrite))
687  {
688  case store_E_NotExists:
690  case store_E_WrongFormat:
691  return RegError::INVALID_KEY;
692  default:
693  break;
694  }
695 
696  std::unique_ptr< ORegKey > p(new ORegKey(path, this));
697  i = m_openKeyTable.insert(std::make_pair(path, p.get())).first;
698  p.release();
699  } else {
700  i->second->acquire();
701  }
702  *phOpenKey = i->second;
703  return RegError::NO_ERROR;
704 }
705 
707 {
708  ORegKey* pKey = static_cast< ORegKey* >(hKey);
709 
711 
712  OUString const aKeyName (pKey->getName());
713  if (m_openKeyTable.count(aKeyName) <= 0)
714  return RegError::KEY_NOT_OPEN;
715 
716  if (pKey->isModified())
717  {
718  ORegKey * pRootKey = getRootKey();
719  if (pKey != pRootKey)
720  {
721  // propagate "modified" state to RootKey.
722  pRootKey->setModified();
723  }
724  else
725  {
726  // closing modified RootKey, flush registry file.
727  (void) m_file.flush();
728  }
729  pKey->setModified(false);
730  (void) releaseKey(pRootKey);
731  }
732 
733  return releaseKey(pKey);
734 }
735 
736 RegError ORegistry::deleteKey(RegKeyHandle hKey, const OUString& keyName)
737 {
738  ORegKey* pKey = static_cast< ORegKey* >(hKey);
739  if (keyName.isEmpty())
741 
743 
744  if (!pKey)
745  pKey = m_openKeyTable[ROOT];
746 
747  OUString sFullKeyName(pKey->getFullPath(keyName));
748  return eraseKey(m_openKeyTable[ROOT], sFullKeyName);
749 }
750 
751 RegError ORegistry::eraseKey(ORegKey* pKey, const OUString& keyName)
752 {
754 
755  if (keyName.isEmpty())
756  {
758  }
759 
760  OUString sFullKeyName(pKey->getName());
761  OUString sFullPath(sFullKeyName);
762  OUString sRelativKey;
763  sal_Int32 lastIndex = keyName.lastIndexOf('/');
764 
765  if (lastIndex >= 0)
766  {
767  sRelativKey += keyName.copy(lastIndex + 1);
768 
769  if (sFullKeyName.getLength() > 1)
770  sFullKeyName += keyName;
771  else
772  sFullKeyName += keyName.copy(1);
773 
774  sFullPath = sFullKeyName.copy(0, keyName.lastIndexOf('/') + 1);
775  } else
776  {
777  if (sFullKeyName.getLength() > 1)
778  sFullKeyName += ROOT;
779 
780  sRelativKey += keyName;
781  sFullKeyName += keyName;
782 
783  if (sFullPath.getLength() > 1)
784  sFullPath += ROOT;
785  }
786 
787  ORegKey* pOldKey = nullptr;
788  _ret = pKey->openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pOldKey));
789  if (_ret != RegError::NO_ERROR)
790  return _ret;
791 
792  _ret = deleteSubkeysAndValues(pOldKey);
793  if (_ret != RegError::NO_ERROR)
794  {
795  pKey->closeKey(pOldKey);
796  return _ret;
797  }
798 
799  OUString tmpName = sRelativKey + ROOT;
800 
801  OStoreFile sFile(pKey->getStoreFile());
802  if (sFile.isValid() && sFile.remove(sFullPath, tmpName))
803  {
805  }
806  pOldKey->setModified();
807 
808  // set flag deleted !!!
809  pOldKey->setDeleted(true);
810 
811  return pKey->closeKey(pOldKey);
812 }
813 
815 {
818  OStoreDirectory rStoreDir(pKey->getStoreDir());
819  storeError _err = rStoreDir.first(iter);
820 
821  while (_err == store_E_None)
822  {
823  OUString const keyName = iter.m_pszName;
824 
825  if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
826  {
827  _ret = eraseKey(pKey, keyName);
828  if (_ret != RegError::NO_ERROR)
829  return _ret;
830  }
831  else
832  {
833  OUString sFullPath(pKey->getName());
834 
835  if (sFullPath.getLength() > 1)
836  sFullPath += ROOT;
837 
838  if (const_cast<OStoreFile&>(pKey->getStoreFile()).remove(sFullPath, keyName))
839  {
841  }
842  pKey->setModified();
843  }
844 
845  _err = rStoreDir.next(iter);
846  }
847 
848  return RegError::NO_ERROR;
849 }
850 
851 RegError ORegistry::loadKey(RegKeyHandle hKey, const OUString& regFileName,
852  bool bWarnings, bool bReport)
853 {
854  ORegKey* pKey = static_cast< ORegKey* >(hKey);
855 
856  std::unique_ptr< ORegistry > pReg (new ORegistry());
857  RegError _ret = pReg->initRegistry(regFileName, RegAccessMode::READONLY);
858  if (_ret != RegError::NO_ERROR)
859  return _ret;
860  ORegKey* pRootKey = pReg->getRootKey();
861 
863 
865  OStoreDirectory rStoreDir(pRootKey->getStoreDir());
866  storeError _err = rStoreDir.first(iter);
867 
868  while (_err == store_E_None)
869  {
870  OUString const keyName = iter.m_pszName;
871 
872  if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
873  {
874  _ret = loadAndSaveKeys(pKey, pRootKey, keyName, 0, bWarnings, bReport);
875  }
876  else
877  {
878  _ret = loadAndSaveValue(pKey, pRootKey, keyName, 0, bWarnings, bReport);
879  }
880 
881  if (_ret == RegError::MERGE_ERROR)
882  break;
883  if (_ret == RegError::MERGE_CONFLICT && bWarnings)
884  break;
885 
886  _err = rStoreDir.next(iter);
887  }
888 
889  rStoreDir = OStoreDirectory();
890  (void) pReg->releaseKey(pRootKey);
891  return _ret;
892 }
893 
895  ORegKey const * pSourceKey,
896  const OUString& valueName,
897  sal_uInt32 nCut,
898  bool bWarnings,
899  bool bReport)
900 {
902  RegValueType valueType;
903  sal_uInt32 valueSize;
904  sal_uInt32 nSize;
905  storeAccessMode sourceAccess = storeAccessMode::ReadWrite;
906  OUString sTargetPath(pTargetKey->getName());
907  OUString sSourcePath(pSourceKey->getName());
908 
909  if (pSourceKey->isReadOnly())
910  {
911  sourceAccess = storeAccessMode::ReadOnly;
912  }
913 
914  if (nCut)
915  {
916  sTargetPath = sSourcePath.copy(nCut);
917  } else
918  {
919  if (sTargetPath.getLength() > 1)
920  {
921  if (sSourcePath.getLength() > 1)
922  sTargetPath += sSourcePath;
923  } else
924  sTargetPath = sSourcePath;
925  }
926 
927  if (sTargetPath.getLength() > 1) sTargetPath += ROOT;
928  if (sSourcePath.getLength() > 1) sSourcePath += ROOT;
929 
930  if (rValue.create(pSourceKey->getStoreFile(), sSourcePath, valueName, sourceAccess))
931  {
933  }
934 
935  std::vector<sal_uInt8> aBuffer(VALUE_HEADERSIZE);
936 
937  sal_uInt32 rwBytes;
938  if (rValue.readAt(0, aBuffer.data(), VALUE_HEADERSIZE, rwBytes))
939  {
941  }
942  if (rwBytes != VALUE_HEADERSIZE)
943  {
945  }
946 
948  sal_uInt8 type = aBuffer[0];
949  valueType = static_cast<RegValueType>(type);
950  readUINT32(aBuffer.data() + VALUE_TYPEOFFSET, valueSize);
951 
952  nSize = VALUE_HEADERSIZE + valueSize;
953  aBuffer.resize(nSize);
954 
955  if (rValue.readAt(0, aBuffer.data(), nSize, rwBytes))
956  {
958  }
959  if (rwBytes != nSize)
960  {
962  }
963 
964  OStoreFile rTargetFile(pTargetKey->getStoreFile());
965 
966  if (!rValue.create(rTargetFile, sTargetPath, valueName, storeAccessMode::ReadWrite))
967  {
968  if (valueType == RegValueType::BINARY)
969  {
970  _ret = checkBlop(
971  rValue, sTargetPath, valueSize, aBuffer.data() + VALUE_HEADEROFFSET,
972  bReport);
973  if (_ret != RegError::NO_ERROR)
974  {
975  if (_ret == RegError::MERGE_ERROR ||
976  (_ret == RegError::MERGE_CONFLICT && bWarnings))
977  {
978  return _ret;
979  }
980  } else
981  {
982  return _ret;
983  }
984  }
985  }
986 
987  if (rValue.create(rTargetFile, sTargetPath, valueName, storeAccessMode::Create))
988  {
990  }
991  if (rValue.writeAt(0, aBuffer.data(), nSize, rwBytes))
992  {
994  }
995 
996  if (rwBytes != nSize)
997  {
999  }
1000  pTargetKey->setModified();
1001 
1002  return _ret;
1003 }
1004 
1006  const OUString& sTargetPath,
1007  sal_uInt32 srcValueSize,
1008  sal_uInt8 const * pSrcBuffer,
1009  bool bReport)
1010 {
1011  RegistryTypeReader reader(pSrcBuffer, srcValueSize);
1012 
1013  if (reader.getTypeClass() == RT_TYPE_INVALID)
1014  {
1015  return RegError::INVALID_VALUE;
1016  }
1017 
1018  std::vector<sal_uInt8> aBuffer(VALUE_HEADERSIZE);
1019  RegValueType valueType;
1020  sal_uInt32 valueSize;
1021  sal_uInt32 rwBytes;
1022  OString targetPath(OUStringToOString(sTargetPath, RTL_TEXTENCODING_UTF8));
1023 
1024  if (!rValue.readAt(0, aBuffer.data(), VALUE_HEADERSIZE, rwBytes) &&
1025  (rwBytes == VALUE_HEADERSIZE))
1026  {
1027  sal_uInt8 type = aBuffer[0];
1028  valueType = static_cast<RegValueType>(type);
1029  readUINT32(aBuffer.data() + VALUE_TYPEOFFSET, valueSize);
1030 
1031  if (valueType == RegValueType::BINARY)
1032  {
1033  aBuffer.resize(valueSize);
1034  if (!rValue.readAt(VALUE_HEADEROFFSET, aBuffer.data(), valueSize, rwBytes) &&
1035  (rwBytes == valueSize))
1036  {
1037  RegistryTypeReader reader2(aBuffer.data(), valueSize);
1038 
1039  if ((reader.getTypeClass() != reader2.getTypeClass())
1040  || reader2.getTypeClass() == RT_TYPE_INVALID)
1041  {
1042  if (bReport)
1043  {
1044  fprintf(stdout, "ERROR: values of blop from key \"%s\" has different types.\n",
1045  targetPath.getStr());
1046  }
1047  return RegError::MERGE_ERROR;
1048  }
1049 
1050  if (reader.getTypeClass() == RT_TYPE_MODULE)
1051  {
1052  if (reader.getFieldCount() > 0 &&
1053  reader2.getFieldCount() > 0)
1054  {
1055  mergeModuleValue(rValue, reader, reader2);
1056 
1057  return RegError::NO_ERROR;
1058  } else
1059  if (reader2.getFieldCount() > 0)
1060  {
1061  return RegError::NO_ERROR;
1062  } else
1063  {
1064  return RegError::MERGE_CONFLICT;
1065  }
1066  } else
1067  {
1068  if (bReport)
1069  {
1070  fprintf(stderr, "WARNING: value of key \"%s\" already exists.\n",
1071  targetPath.getStr());
1072  }
1073  return RegError::MERGE_CONFLICT;
1074  }
1075  } else
1076  {
1077  if (bReport)
1078  {
1079  fprintf(stderr, "ERROR: values of key \"%s\" contains bad data.\n",
1080  targetPath.getStr());
1081  }
1082  return RegError::MERGE_ERROR;
1083  }
1084  } else
1085  {
1086  if (bReport)
1087  {
1088  fprintf(stderr, "ERROR: values of key \"%s\" has different types.\n",
1089  targetPath.getStr());
1090  }
1091  return RegError::MERGE_ERROR;
1092  }
1093  } else
1094  {
1095  return RegError::INVALID_VALUE;
1096  }
1097 }
1098 
1099 static sal_uInt32 checkTypeReaders(RegistryTypeReader const & reader1,
1100  RegistryTypeReader const & reader2,
1101  std::set< OUString >& nameSet)
1102 {
1103  sal_uInt32 count=0;
1104  for (sal_uInt32 i=0 ; i < reader1.getFieldCount(); i++)
1105  {
1106  nameSet.insert(reader1.getFieldName(i));
1107  count++;
1108  }
1109  for (sal_uInt32 i=0 ; i < reader2.getFieldCount(); i++)
1110  {
1111  if (nameSet.insert(reader2.getFieldName(i)).second)
1112  count++;
1113  }
1114  return count;
1115 }
1116 
1118  RegistryTypeReader const & reader,
1119  RegistryTypeReader const & reader2)
1120 {
1121  std::set< OUString > nameSet;
1122  sal_uInt32 count = checkTypeReaders(reader, reader2, nameSet);
1123 
1124  if (count != reader.getFieldCount())
1125  {
1126  sal_uInt16 index = 0;
1127 
1128  RegistryTypeWriter writer(reader.getTypeClass(),
1129  reader.getTypeName(),
1130  reader.getSuperTypeName(),
1131  static_cast<sal_uInt16>(count));
1132 
1133  for (sal_uInt32 i=0 ; i < reader.getFieldCount(); i++)
1134  {
1135  writer.setFieldData(index,
1136  reader.getFieldName(i),
1137  reader.getFieldType(i),
1138  reader.getFieldDoku(i),
1139  reader.getFieldFileName(i),
1140  reader.getFieldAccess(i),
1141  reader.getFieldConstValue(i));
1142  index++;
1143  }
1144  for (sal_uInt32 i=0 ; i < reader2.getFieldCount(); i++)
1145  {
1146  if (nameSet.find(reader2.getFieldName(i)) == nameSet.end())
1147  {
1148  writer.setFieldData(index,
1149  reader2.getFieldName(i),
1150  reader2.getFieldType(i),
1151  reader2.getFieldDoku(i),
1152  reader2.getFieldFileName(i),
1153  reader2.getFieldAccess(i),
1154  reader2.getFieldConstValue(i));
1155  index++;
1156  }
1157  }
1158 
1159  const sal_uInt8* pBlop = writer.getBlop();
1160  sal_uInt32 aBlopSize = writer.getBlopSize();
1161 
1163  std::vector<sal_uInt8> aBuffer(VALUE_HEADERSIZE + aBlopSize);
1164 
1165  memcpy(aBuffer.data(), &type, 1);
1166  writeUINT32(aBuffer.data() + VALUE_TYPEOFFSET, aBlopSize);
1167  memcpy(aBuffer.data() + VALUE_HEADEROFFSET, pBlop, aBlopSize);
1168 
1169  sal_uInt32 rwBytes;
1170  if (rTargetValue.writeAt(0, aBuffer.data(), VALUE_HEADERSIZE+aBlopSize, rwBytes))
1171  {
1172  return RegError::INVALID_VALUE;
1173  }
1174 
1175  if (rwBytes != VALUE_HEADERSIZE+aBlopSize)
1176  {
1177  return RegError::INVALID_VALUE;
1178  }
1179  }
1180  return RegError::NO_ERROR;
1181 }
1182 
1184  ORegKey* pSourceKey,
1185  const OUString& keyName,
1186  sal_uInt32 nCut,
1187  bool bWarnings,
1188  bool bReport)
1189 {
1191  OUString sRelPath(pSourceKey->getName().copy(nCut));
1192  OUString sFullPath;
1193 
1194  if(pTargetKey->getName().getLength() > 1)
1195  sFullPath += pTargetKey->getName();
1196  sFullPath += sRelPath;
1197  if (sRelPath.getLength() > 1 || sFullPath.isEmpty())
1198  sFullPath += ROOT;
1199 
1200  OUString sFullKeyName = sFullPath + keyName;
1201 
1202  OStoreDirectory rStoreDir;
1203  if (rStoreDir.create(pTargetKey->getStoreFile(), sFullPath, keyName, storeAccessMode::Create))
1204  {
1206  }
1207 
1208  if (m_openKeyTable.count(sFullKeyName) > 0)
1209  {
1210  m_openKeyTable[sFullKeyName]->setDeleted(false);
1211  }
1212 
1213  ORegKey* pTmpKey = nullptr;
1214  _ret = pSourceKey->openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pTmpKey));
1215  if (_ret != RegError::NO_ERROR)
1216  return _ret;
1217 
1219  OStoreDirectory rTmpStoreDir(pTmpKey->getStoreDir());
1220  storeError _err = rTmpStoreDir.first(iter);
1221 
1222  while (_err == store_E_None)
1223  {
1224  OUString const sName = iter.m_pszName;
1225 
1226  if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
1227  {
1228  _ret = loadAndSaveKeys(pTargetKey, pTmpKey,
1229  sName, nCut, bWarnings, bReport);
1230  } else
1231  {
1232  _ret = loadAndSaveValue(pTargetKey, pTmpKey,
1233  sName, nCut, bWarnings, bReport);
1234  }
1235 
1236  if (_ret == RegError::MERGE_ERROR)
1237  break;
1238  if (_ret == RegError::MERGE_CONFLICT && bWarnings)
1239  break;
1240 
1241  _err = rTmpStoreDir.next(iter);
1242  }
1243 
1244  pSourceKey->releaseKey(pTmpKey);
1245  return _ret;
1246 }
1247 
1249 {
1250  m_openKeyTable[ROOT]->acquire();
1251  return m_openKeyTable[ROOT];
1252 }
1253 
1255 {
1256  ORegKey *pKey = static_cast<ORegKey*>(hKey);
1257  OUString sName;
1260  OStoreDirectory rStoreDir(pKey->getStoreDir());
1261  storeError _err = rStoreDir.first(iter);
1262 
1263  OString regName(OUStringToOString(getName(), osl_getThreadTextEncoding()));
1264  OString keyName(OUStringToOString(pKey->getName(), RTL_TEXTENCODING_UTF8));
1265  fprintf(stdout, "Registry \"%s\":\n\n%s\n", regName.getStr(), keyName.getStr());
1266 
1267  while (_err == store_E_None)
1268  {
1269  sName = iter.m_pszName;
1270 
1271  if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
1272  {
1273  _ret = dumpKey(pKey->getName(), sName, 1);
1274  } else
1275  {
1276  _ret = dumpValue(pKey->getName(), sName, 1);
1277  }
1278 
1279  if (_ret != RegError::NO_ERROR)
1280  {
1281  return _ret;
1282  }
1283 
1284  _err = rStoreDir.next(iter);
1285  }
1286 
1287  return RegError::NO_ERROR;
1288 }
1289 
1290 RegError ORegistry::dumpValue(const OUString& sPath, const OUString& sName, sal_Int16 nSpc) const
1291 {
1293  sal_uInt32 valueSize;
1294  RegValueType valueType;
1295  OUString sFullPath(sPath);
1296  OString sIndent;
1297  storeAccessMode accessMode = storeAccessMode::ReadWrite;
1298 
1299  if (isReadOnly())
1300  {
1301  accessMode = storeAccessMode::ReadOnly;
1302  }
1303 
1304  for (int i= 0; i < nSpc; i++) sIndent += " ";
1305 
1306  if (sFullPath.getLength() > 1)
1307  {
1308  sFullPath += ROOT;
1309  }
1310  if (rValue.create(m_file, sFullPath, sName, accessMode))
1311  {
1313  }
1314 
1315  std::vector<sal_uInt8> aBuffer(VALUE_HEADERSIZE);
1316 
1317  sal_uInt32 rwBytes;
1318  if (rValue.readAt(0, aBuffer.data(), VALUE_HEADERSIZE, rwBytes))
1319  {
1320  return RegError::INVALID_VALUE;
1321  }
1322  if (rwBytes != (VALUE_HEADERSIZE))
1323  {
1324  return RegError::INVALID_VALUE;
1325  }
1326 
1327  sal_uInt8 type = aBuffer[0];
1328  valueType = static_cast<RegValueType>(type);
1329  readUINT32(aBuffer.data() + VALUE_TYPEOFFSET, valueSize);
1330 
1331  aBuffer.resize(valueSize);
1332  if (rValue.readAt(VALUE_HEADEROFFSET, aBuffer.data(), valueSize, rwBytes))
1333  {
1334  return RegError::INVALID_VALUE;
1335  }
1336  if (rwBytes != valueSize)
1337  {
1338  return RegError::INVALID_VALUE;
1339  }
1340 
1341  const char* indent = sIndent.getStr();
1342  switch (valueType)
1343  {
1345  fprintf(stdout, "%sValue: Type = VALUETYPE_NOT_DEFINED\n", indent);
1346  break;
1347  case RegValueType::LONG:
1348  {
1349  fprintf(stdout, "%sValue: Type = RegValueType::LONG\n", indent);
1350  fprintf(
1351  stdout, "%s Size = %lu\n", indent,
1352  sal::static_int_cast< unsigned long >(valueSize));
1353  fprintf(stdout, "%s Data = ", indent);
1354 
1355  sal_Int32 value;
1356  readINT32(aBuffer.data(), value);
1357  fprintf(stdout, "%ld\n", sal::static_int_cast< long >(value));
1358  }
1359  break;
1360  case RegValueType::STRING:
1361  {
1362  char* value = static_cast<char*>(std::malloc(valueSize));
1363  readUtf8(aBuffer.data(), value, valueSize);
1364  fprintf(stdout, "%sValue: Type = RegValueType::STRING\n", indent);
1365  fprintf(
1366  stdout, "%s Size = %lu\n", indent,
1367  sal::static_int_cast< unsigned long >(valueSize));
1368  fprintf(stdout, "%s Data = \"%s\"\n", indent, value);
1369  std::free(value);
1370  }
1371  break;
1372  case RegValueType::UNICODE:
1373  {
1374  sal_uInt32 size = (valueSize / 2) * sizeof(sal_Unicode);
1375  fprintf(stdout, "%sValue: Type = RegValueType::UNICODE\n", indent);
1376  fprintf(
1377  stdout, "%s Size = %lu\n", indent,
1378  sal::static_int_cast< unsigned long >(valueSize));
1379  fprintf(stdout, "%s Data = ", indent);
1380 
1381  std::unique_ptr<sal_Unicode[]> value(new sal_Unicode[size]);
1382  readString(aBuffer.data(), value.get(), size);
1383 
1384  OString uStr = OUStringToOString(value.get(), RTL_TEXTENCODING_UTF8);
1385  fprintf(stdout, "L\"%s\"\n", uStr.getStr());
1386  }
1387  break;
1388  case RegValueType::BINARY:
1389  {
1390  fprintf(stdout, "%sValue: Type = RegValueType::BINARY\n", indent);
1391  fprintf(
1392  stdout, "%s Size = %lu\n", indent,
1393  sal::static_int_cast< unsigned long >(valueSize));
1394  fprintf(stdout, "%s Data = ", indent);
1395  dumpType(
1396  typereg::Reader(aBuffer.data(), valueSize),
1397  sIndent + " ");
1398  }
1399  break;
1401  {
1402  sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
1403  sal_uInt32 len = 0;
1404 
1405  readUINT32(aBuffer.data(), len);
1406 
1407  fprintf(stdout, "%sValue: Type = RegValueType::LONGLIST\n", indent);
1408  fprintf(
1409  stdout, "%s Size = %lu\n", indent,
1410  sal::static_int_cast< unsigned long >(valueSize));
1411  fprintf(
1412  stdout, "%s Len = %lu\n", indent,
1413  sal::static_int_cast< unsigned long >(len));
1414  fprintf(stdout, "%s Data = ", indent);
1415 
1416  sal_Int32 longValue;
1417  for (sal_uInt32 i=0; i < len; i++)
1418  {
1419  readINT32(aBuffer.data() + offset, longValue);
1420 
1421  if (offset > 4)
1422  fprintf(stdout, "%s ", indent);
1423 
1424  fprintf(
1425  stdout, "%lu = %ld\n",
1426  sal::static_int_cast< unsigned long >(i),
1427  sal::static_int_cast< long >(longValue));
1428  offset += 4; // 4 Bytes for sal_Int32
1429  }
1430  }
1431  break;
1433  {
1434  sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
1435  sal_uInt32 sLen = 0;
1436  sal_uInt32 len = 0;
1437 
1438  readUINT32(aBuffer.data(), len);
1439 
1440  fprintf(stdout, "%sValue: Type = RegValueType::STRINGLIST\n", indent);
1441  fprintf(
1442  stdout, "%s Size = %lu\n", indent,
1443  sal::static_int_cast< unsigned long >(valueSize));
1444  fprintf(
1445  stdout, "%s Len = %lu\n", indent,
1446  sal::static_int_cast< unsigned long >(len));
1447  fprintf(stdout, "%s Data = ", indent);
1448 
1449  for (sal_uInt32 i=0; i < len; i++)
1450  {
1451  readUINT32(aBuffer.data() + offset, sLen);
1452 
1453  offset += 4; // 4 bytes (sal_uInt32) for the string size
1454 
1455  char *pValue = static_cast<char*>(std::malloc(sLen));
1456  readUtf8(aBuffer.data() + offset, pValue, sLen);
1457 
1458  if (offset > 8)
1459  fprintf(stdout, "%s ", indent);
1460 
1461  fprintf(
1462  stdout, "%lu = \"%s\"\n",
1463  sal::static_int_cast< unsigned long >(i), pValue);
1464  std::free(pValue);
1465  offset += sLen;
1466  }
1467  }
1468  break;
1469  case RegValueType::UNICODELIST:
1470  {
1471  sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
1472  sal_uInt32 sLen = 0;
1473  sal_uInt32 len = 0;
1474 
1475  readUINT32(aBuffer.data(), len);
1476 
1477  fprintf(stdout, "%sValue: Type = RegValueType::UNICODELIST\n", indent);
1478  fprintf(
1479  stdout, "%s Size = %lu\n", indent,
1480  sal::static_int_cast< unsigned long >(valueSize));
1481  fprintf(
1482  stdout, "%s Len = %lu\n", indent,
1483  sal::static_int_cast< unsigned long >(len));
1484  fprintf(stdout, "%s Data = ", indent);
1485 
1486  OString uStr;
1487  for (sal_uInt32 i=0; i < len; i++)
1488  {
1489  readUINT32(aBuffer.data() + offset, sLen);
1490 
1491  offset += 4; // 4 bytes (sal_uInt32) for the string size
1492 
1493  sal_Unicode *pValue = static_cast<sal_Unicode*>(std::malloc((sLen / 2) * sizeof(sal_Unicode)));
1494  readString(aBuffer.data() + offset, pValue, sLen);
1495 
1496  if (offset > 8)
1497  fprintf(stdout, "%s ", indent);
1498 
1499  uStr = OUStringToOString(pValue, RTL_TEXTENCODING_UTF8);
1500  fprintf(
1501  stdout, "%lu = L\"%s\"\n",
1502  sal::static_int_cast< unsigned long >(i),
1503  uStr.getStr());
1504 
1505  offset += sLen;
1506 
1507  std::free(pValue);
1508  }
1509  }
1510  break;
1511  }
1512 
1513  fprintf(stdout, "\n");
1514 
1515  return RegError::NO_ERROR;
1516 }
1517 
1518 RegError ORegistry::dumpKey(const OUString& sPath, const OUString& sName, sal_Int16 nSpace) const
1519 {
1520  OStoreDirectory rStoreDir;
1521  OUString sFullPath(sPath);
1522  OString sIndent;
1523  storeAccessMode accessMode = storeAccessMode::ReadWrite;
1525 
1526  if (isReadOnly())
1527  {
1528  accessMode = storeAccessMode::ReadOnly;
1529  }
1530 
1531  for (int i= 0; i < nSpace; i++) sIndent += " ";
1532 
1533  if (sFullPath.getLength() > 1)
1534  sFullPath += ROOT;
1535 
1536  storeError _err = rStoreDir.create(m_file, sFullPath, sName, accessMode);
1537 
1538  if (_err == store_E_NotExists)
1539  return RegError::KEY_NOT_EXISTS;
1540  else if (_err == store_E_WrongFormat)
1541  return RegError::INVALID_KEY;
1542 
1543  fprintf(stdout, "%s/ %s\n", sIndent.getStr(), OUStringToOString(sName, RTL_TEXTENCODING_UTF8).getStr());
1544 
1545  OUString sSubPath(sFullPath);
1546  OUString sSubName;
1547  sSubPath += sName;
1548 
1550 
1551  _err = rStoreDir.first(iter);
1552 
1553  while (_err == store_E_None)
1554  {
1555  sSubName = iter.m_pszName;
1556 
1557  if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
1558  {
1559  _ret = dumpKey(sSubPath, sSubName, nSpace+2);
1560  } else
1561  {
1562  _ret = dumpValue(sSubPath, sSubName, nSpace+2);
1563  }
1564 
1565  if (_ret != RegError::NO_ERROR)
1566  {
1567  return _ret;
1568  }
1569 
1570  _err = rStoreDir.next(iter);
1571  }
1572 
1573  return RegError::NO_ERROR;
1574 }
1575 
1576 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DESTROY_REGISTRY_FAILED
destroy a registry failed. There are may be any open keys.
Definition: regtype.h:83
Flag for published individual constants.
const OUString & getName() const
Definition: keyimpl.hxx:120
store_E_WrongFormat
OUString getFieldTypeName(sal_uInt16 index) const
Returns the type name of a field of this type reader.
Definition: reader.hxx:308
OUString getMethodParameterName(sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
Returns the name of a parameter of a method of this type reader.
Definition: reader.hxx:453
STRINGLIST
The key has a value of type ascii string list.
Definition: regtype.h:62
STRING
The key has a value of type ascii string.
Definition: regtype.h:62
store_E_LockingViolation
const size_t count(pCandidateA->getBorderLines().size())
NO_ERROR
no error.
Definition: regtype.h:83
RTParamMode
specifies the mode of a parameter.
Definition: types.hxx:269
sal_Int32 nIndex
sal_uInt16 getFieldCount() const
Returns the number of fields of this type reader.
Definition: reader.hxx:229
#define VALUE_HEADEROFFSET
Definition: regimpl.hxx:34
indicates a in and out parameter which is used also by reference
Definition: types.hxx:280
RegistryTypeReades reads a binary type blob.
Definition: reflread.hxx:37
Indicates an extended attribute getter (that has a 'raises' clause) of an interface type...
OUString getReferenceTypeName(sal_uInt16 index) const
Returns the type name of a reference of this type reader.
Definition: reader.hxx:589
storeError
sal_uInt32 m_refCount
Definition: regimpl.hxx:140
OUString getFieldFileName(sal_uInt16 index) const
returns the IDL filename of the field specified by index.
Definition: reflread.cxx:1753
storeAccessMode
RTConstValue getFieldConstValue(sal_uInt16 index) const
returns the value of the field specified by index.
Definition: reflread.cxx:1739
RegistryTypeWriter writes/creates a binary type blob.
Definition: reflwrit.hxx:39
RegAccessMode
defines the open/access mode of the registry.
Definition: regtype.h:41
OUString getDocumentation() const
Returns the documentation of this type reader.
Definition: reader.hxx:126
constexpr sal_uInt32 STORE_ATTRIB_ISDIR
ULONG m_refCount
const OUString & getName() const
Definition: regimpl.hxx:96
#define VALUE_HEADERSIZE
Definition: regimpl.hxx:32
OUString getFieldDoku(sal_uInt16 index) const
returns the documentation string for the field specified by index.
Definition: reflread.cxx:1746
sal_uInt16 getReferenceCount() const
Returns the number of references of this type reader.
Definition: reader.hxx:532
RegError acquireKey(RegKeyHandle hKey)
Definition: regimpl.cxx:577
specifies that the blob represents an enum type.
Definition: types.hxx:55
UNICODE
The key has a value of type unicode string.
Definition: regtype.h:62
specifies that the blob represents a service type.
Definition: types.hxx:71
storeError create(storeFileHandle hFile, OUString const &rPath, OUString const &rName, storeAccessMode eMode)
sal_Int64 n
store_E_None
bool isModified() const
Definition: keyimpl.hxx:101
LONG
The key has a value of type long.
Definition: regtype.h:62
OUString getMethodDocumentation(sal_uInt16 index) const
Returns the documentation of a method of this type reader.
Definition: reader.hxx:355
indicates the asynchronous mode of a method
LONGLIST
The key has a value of type long list.
Definition: regtype.h:62
MERGE_CONFLICT
conflicts exists during the merge process of a key.
Definition: regtype.h:83
sal_uInt16 getMethodCount() const
Returns the number of methods of this type reader.
Definition: reader.hxx:342
OUString getFieldName(sal_uInt16 index) const
returns the name of the field specified by index.
Definition: reflread.cxx:1722
RegError deleteKey(RegKeyHandle hKey, const OUString &keyName)
Definition: regimpl.cxx:736
RegError releaseKey(RegKeyHandle hKey)
Definition: keyimpl.cxx:60
specifies that the blob represents an interface type.
Definition: types.hxx:40
RTConstValue getFieldValue(sal_uInt16 index) const
Returns the value of a field of this type reader.
Definition: reader.hxx:326
RTFieldAccess getFieldFlags(sal_uInt16 index) const
Returns the flags of a field of this type reader.
Definition: reader.hxx:277
RegError createKey(RegKeyHandle hKey, const OUString &keyName, RegKeyHandle *phNewKey)
Definition: regimpl.cxx:604
MERGE_ERROR
merging a key, the value and all subkeys failed.
Definition: regtype.h:83
OUString getSuperTypeName() const
returns the full qualified name of the supertype.
Definition: reflread.cxx:1712
A type reader working on a binary blob that represents a UNOIDL type.
Definition: reader.hxx:42
NOT_DEFINED
The key has no value or the value type is unknown.
Definition: regtype.h:62
ORegKey * getRootKey()
Definition: regimpl.cxx:1248
RTParamMode getMethodParameterFlags(sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
Returns the flags of a parameter of a method of this type reader.
Definition: reader.hxx:433
sal_uInt32 readUINT32(const sal_uInt8 *buffer, sal_uInt32 &v)
Definition: reflcnst.hxx:167
bool isValid() const
Returns whether this type reader is valid.
Definition: reader.hxx:103
static sal_uInt32 checkTypeReaders(RegistryTypeReader const &reader1, RegistryTypeReader const &reader2, std::set< OUString > &nameSet)
Definition: regimpl.cxx:1099
css::uno::Any const & rValue
indicates a pure in parameter which is used by value
Definition: types.hxx:274
OUString getMethodName(sal_uInt16 index) const
Returns the name of a method of this type reader.
Definition: reader.hxx:384
sal_uInt16 sal_Unicode
specifies that the blob represents a struct type.
Definition: types.hxx:50
OUString getReferenceDocumentation(sal_uInt16 index) const
Returns the documentation of a reference of this type reader.
Definition: reader.hxx:546
specifies that the field is a constant or enum value
the service exports the specified service that means this service provides also the specified service...
CREATE_KEY_FAILED
the key with the specified keyname cannot be created.
Definition: regtype.h:83
bool isReadOnly() const
Definition: regimpl.hxx:85
specifies that the blob represents a singleton type (a named object) which refers exactly one existin...
Definition: types.hxx:76
storeError flush() const
RTTypeClass getTypeClass() const
Returns the type class of this type reader.
Definition: reader.hxx:163
RTMethodMode getMethodFlags(sal_uInt16 index) const
Returns the flags of a method of this type reader.
Definition: reader.hxx:371
RTFieldAccess getFieldAccess(sal_uInt16 index) const
returns the access mode of the field specified by index.
Definition: reflread.cxx:1736
bool isPublished() const
Returns whether this type reader is published.
Definition: reader.hxx:173
const sal_uInt8 * getBlop()
returns a pointer to the new type blob.
Definition: reflwrit.cxx:1325
This mode allows readonly access.
RegError closeRegistry()
Definition: regimpl.cxx:502
Indicates a rest parameter (currently only valid for service constructors).
Definition: types.hxx:292
storeError readAt(sal_uInt32 nOffset, void *pBuffer, sal_uInt32 nBytes, sal_uInt32 &rnDone)
enum SAL_DLLPUBLIC_RTTI RegError
specifies the possible error codes which can occur using the registry API.
Definition: regtype.h:80
Reference< deployment::XPackageRegistry > create(Reference< deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, Reference< XComponentContext > const &xComponentContext)
storeError first(iterator &it)
specifies that the structure of the given blob is unknown and can't be read.
Definition: types.hxx:35
sal_uInt32 readUtf8(const sal_uInt8 *buffer, char *v, sal_uInt32 maxSize)
Definition: reflcnst.hxx:203
const char * sName
BINARY
The key has a value of type binary.
Definition: regtype.h:62
RegError closeKey(RegKeyHandle hKey)
Definition: keyimpl.cxx:204
store::OStoreFile m_file
Definition: regimpl.hxx:145
OUString getFileName() const
Returns the file name of this type reader.
Definition: reader.hxx:144
osl::Mutex m_mutex
Definition: regimpl.hxx:141
specifies that the property/attribute has read/write access
indicates a pure out parameter which is used by reference
Definition: types.hxx:277
enum SAL_DLLPUBLIC_RTTI RegValueType
defines the type of a key value.
Definition: regtype.h:59
REGISTRY_NOT_EXISTS
registry does not exists.
Definition: regtype.h:83
sal_uInt16 getMethodParameterCount(sal_uInt16 index) const
Returns the number of parameters of a method of this type reader.
Definition: reader.hxx:418
VALUE_NOT_EXISTS
the key has no value
Definition: regtype.h:83
OUString getFieldName(sal_uInt16 index) const
Returns the name of a field of this type reader.
Definition: reader.hxx:290
the service support the interface that means an implementation of this service must implement this in...
bool isReadOnly() const
Definition: keyimpl.hxx:107
sal_uInt16 getMethodExceptionCount(sal_uInt16 index) const
Returns the number of exceptions of a method of this type reader.
Definition: reader.hxx:497
storeError create(storeFileHandle hFile, OUString const &rPath, OUString const &rName, storeAccessMode eMode)
int i
specifies that the blob represents an exception type.
Definition: types.hxx:60
DELETE_VALUE_FAILED
deleting of the key value failed.
Definition: regtype.h:83
bool m_readOnly
Definition: regimpl.hxx:142
store::OStoreDirectory getStoreDir() const
Definition: keyimpl.cxx:944
storeError writeAt(sal_uInt32 nOffset, void const *pBuffer, sal_uInt32 nBytes, sal_uInt32 &rnDone)
void setFieldData(sal_uInt16 index, const OUString &name, const OUString &typeName, const OUString &doku, const OUString &fileName, RTFieldAccess access, const RTConstValue &constValue)
sets the data for a field member of a type blob.
Definition: reflwrit.cxx:1314
INVALID_KEYNAME
the keyname is invalid.
Definition: regtype.h:83
OUString getTypeName() const
Returns the type name of this type reader.
Definition: reader.hxx:185
KEY_NOT_EXISTS
the specified keyname points to a nonexisting key.
Definition: regtype.h:83
static RegError loadAndSaveValue(ORegKey *pTargetKey, ORegKey const *pSourceKey, const OUString &valueName, sal_uInt32 nCut, bool bWarnings, bool bReport)
Definition: regimpl.cxx:894
OUString getMethodParameterTypeName(sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
Returns the type name of a parameter of a method of this type reader.
Definition: reader.hxx:478
Indicates an extended attribute setter (that has a 'raises' clause) of an interface type...
RegError dumpRegistry(RegKeyHandle hKey) const
Definition: regimpl.cxx:1254
void setDeleted(bool bKeyDeleted)
Definition: keyimpl.hxx:98
OUString m_name
Definition: regimpl.hxx:144
size
KEY_NOT_OPEN
the key or key handle points to an invalid key or closed key.
Definition: regtype.h:83
sal_uInt32 getFieldCount() const
returns the number of fields (attributes/properties, enum values or number of constants in a module)...
Definition: reflread.cxx:1719
indicated the synchronous mode of a method
OUString getSuperTypeName(sal_uInt16 index) const
Returns the type name of a super type of this type reader.
Definition: reader.hxx:214
sal_uInt32 readINT32(const sal_uInt8 *buffer, sal_Int32 &v)
Definition: reflcnst.hxx:145
tuple index
RegError loadKey(RegKeyHandle hKey, const OUString &regFileName, bool bWarnings, bool bReport)
Definition: regimpl.cxx:851
sal_uInt32 readString(const sal_uInt8 *buffer, sal_Unicode *v, sal_uInt32 maxSize)
Definition: reflwrit.cxx:89
#define REG_GUARD(mutex)
Definition: regimpl.hxx:36
INVALID_VALUE
the key has an invalid value or the value type is unknown.
Definition: regtype.h:83
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
void acquire()
Definition: keyimpl.hxx:33
friend class ORegKey
Definition: regimpl.hxx:99
Indicates that a member of a polymorphic struct type template is of a parameterized type...
specifies that the blob represents a typedef type.
Definition: types.hxx:65
INVALID_KEY
the key is not in a valid state.
Definition: regtype.h:83
RegError dumpValue(const OUString &sPath, const OUString &sName, sal_Int16 nSpace) const
Definition: regimpl.cxx:1290
sal_Unicode m_pszName[STORE_MAXIMUM_NAMESIZE]
RTTypeClass getTypeClass() const
returns the typeclass of the type represented by this blob.
Definition: reflread.cxx:1702
std::unique_ptr< char[]> aBuffer
~ORegistry()
Definition: regimpl.cxx:429
DELETE_KEY_FAILED
the specified key cannot be deleted. Maybe an open key handle exists to this key. ...
Definition: regtype.h:83
static RegError checkBlop(store::OStoreStream &rValue, const OUString &sTargetPath, sal_uInt32 srcValueSize, sal_uInt8 const *pSrcBuffer, bool bReport)
Definition: regimpl.cxx:1005
Indicates a type parameter of a polymorphic struct type template.
storeError createInMemory()
unsigned char sal_uInt8
RegError eraseKey(ORegKey *pKey, const OUString &keyName)
Definition: regimpl.cxx:751
void * RegKeyHandle
defines the type of a registry key handle used in the C API.
Definition: regtype.h:30
OUString getFieldDocumentation(sal_uInt16 index) const
Returns the documentation of a field of this type reader.
Definition: reader.hxx:242
RegError releaseKey(RegKeyHandle hKey)
Definition: regimpl.cxx:589
RegError closeKey(RegKeyHandle hKey)
Definition: regimpl.cxx:706
sal_uInt32 writeUINT32(sal_uInt8 *buffer, sal_uInt32 v)
Definition: reflcnst.hxx:157
KeyMap m_openKeyTable
Definition: regimpl.hxx:146
sal_uInt32 getBlopSize()
returns the size of the new type blob in bytes.
Definition: reflwrit.cxx:1330
sal_uInt32 release()
Definition: keyimpl.hxx:36
sal_uInt16 getSuperTypeCount() const
Returns the number of super types of this type reader.
Definition: reader.hxx:200
bool isValid() const
#define VALUE_TYPEOFFSET
Definition: regimpl.hxx:33
sal_uInt32 m_nAttrib
RegError loadAndSaveKeys(ORegKey *pTargetKey, ORegKey *pSourceKey, const OUString &keyName, sal_uInt32 nCut, bool bWarnings, bool bReport)
Definition: regimpl.cxx:1183
void * p
Any value
RegError dumpKey(const OUString &sPath, const OUString &sName, sal_Int16 nSpace) const
Definition: regimpl.cxx:1518
specifies a property as optional that means that it must not be implemented.
store_E_NotExists
void setModified(bool bModified=true)
Definition: keyimpl.hxx:104
RTFieldAccess getReferenceFlags(sal_uInt16 index) const
Returns the flags of a reference of this type reader.
Definition: reader.hxx:563
specifies that the blob represents a constants type.
Definition: types.hxx:84
specifies that the blob represents a module type.
Definition: types.hxx:45
ResultType type
OUString getMethodExceptionTypeName(sal_uInt16 methodIndex, sal_uInt16 exceptionIndex) const
Returns the type name of an exception of a method of this type reader.
Definition: reader.hxx:514
RegError initRegistry(const OUString &name, RegAccessMode accessMode, bool bCreate=false)
Definition: regimpl.cxx:439
RegError deleteSubkeysAndValues(ORegKey *pKey)
Definition: regimpl.cxx:814
RegError destroyRegistry(const OUString &name)
Definition: regimpl.cxx:518
RegError openKey(const OUString &keyName, RegKeyHandle *phOpenKey)
Definition: keyimpl.cxx:76
const store::OStoreFile & getStoreFile() const
Definition: keyimpl.hxx:115
typereg_Version getVersion() const
Returns the binary blob version of this type reader.
Definition: reader.hxx:114
static RegError mergeModuleValue(store::OStoreStream &rTargetValue, RegistryTypeReader const &reader, RegistryTypeReader const &reader2)
Definition: regimpl.cxx:1117
OUString getFieldType(sal_uInt16 index) const
returns the full qualified name of the field specified by index.
Definition: reflread.cxx:1729
static constexpr OUStringLiteral ROOT
Definition: regimpl.hxx:148
OUString getFieldFileName(sal_uInt16 index) const
Returns the file name of a field of this type reader.
Definition: reader.hxx:261
RTFieldAccess
specifies the type for the field access.
Definition: types.hxx:132
RTReferenceType getReferenceSort(sal_uInt16 index) const
Returns the sort of a reference of this type reader.
Definition: reader.hxx:575
OUString getMethodReturnTypeName(sal_uInt16 index) const
Returns the return type name of a method of this type reader.
Definition: reader.hxx:402
OUString getTypeName() const
returns the full qualified name of the type.
Definition: reflread.cxx:1705
CANNOT_OPEN_FOR_READWRITE
registry cannot be opened with readwrite access because the registry is already open with readwrite a...
Definition: regtype.h:83
storeError create(OUString const &rFilename, storeAccessMode eAccessMode)
INVALID_REGISTRY
registry is in an invalid state or the registry does not point to a valid registry data file...
Definition: regtype.h:83
OUString getFullPath(OUString const &path) const
Definition: keyimpl.cxx:971
bool m_isOpen
Definition: regimpl.hxx:143
specifies a readonly property/attribute
storeError next(iterator &it)
specifies that the field is a property
RegError openKey(RegKeyHandle hKey, const OUString &keyName, RegKeyHandle *phOpenKey)
Definition: regimpl.cxx:661
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
specifies a helper class for const values.
Definition: refltype.hxx:42