xref: /AOO41X/main/registry/source/regimpl.cxx (revision 24c56ab9f1bd1305754aa2f564704f38ff57627e)
151134e9eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
351134e9eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
451134e9eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
551134e9eSAndrew Rist  * distributed with this work for additional information
651134e9eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
751134e9eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
851134e9eSAndrew Rist  * "License"); you may not use this file except in compliance
951134e9eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1151134e9eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1351134e9eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1451134e9eSAndrew Rist  * software distributed under the License is distributed on an
1551134e9eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1651134e9eSAndrew Rist  * KIND, either express or implied.  See the License for the
1751134e9eSAndrew Rist  * specific language governing permissions and limitations
1851134e9eSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2051134e9eSAndrew Rist  *************************************************************/
2151134e9eSAndrew Rist 
2251134e9eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_registry.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include    "regimpl.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <memory>
30cdf0e10cSrcweir #include    <string.h>
31cdf0e10cSrcweir #include	<stdio.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #if defined(UNX) || defined(OS2)
34cdf0e10cSrcweir #include    <unistd.h>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifdef __MINGW32__
37cdf0e10cSrcweir #include    <unistd.h>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #ifndef __REGISTRY_REFLREAD_HXX__
41cdf0e10cSrcweir #include    <registry/reflread.hxx>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #ifndef __REGISTRY_REFLWRIT_HXX__
45cdf0e10cSrcweir #include    <registry/reflwrit.hxx>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include "registry/reader.hxx"
49cdf0e10cSrcweir #include "registry/refltype.hxx"
50cdf0e10cSrcweir #include "registry/types.h"
51cdf0e10cSrcweir #include "registry/version.h"
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #include    "reflcnst.hxx"
54cdf0e10cSrcweir #include    "keyimpl.hxx"
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include    <osl/thread.h>
57cdf0e10cSrcweir #include    <rtl/alloc.h>
58cdf0e10cSrcweir #include    <rtl/memory.h>
59cdf0e10cSrcweir #include    <rtl/ustring.hxx>
60cdf0e10cSrcweir #include    <rtl/ustrbuf.hxx>
61cdf0e10cSrcweir #include    <osl/file.hxx>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir using namespace rtl;
64cdf0e10cSrcweir using namespace osl;
65cdf0e10cSrcweir using namespace store;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir #if defined ( GCC ) && ( defined ( SCO ) )
68cdf0e10cSrcweir sal_helper::ORealDynamicLoader* sal_helper::ODynamicLoader<RegistryTypeReader_Api>::m_pLoader = NULL;
69cdf0e10cSrcweir #endif
70cdf0e10cSrcweir 
71cdf0e10cSrcweir namespace {
72cdf0e10cSrcweir 
printString(rtl::OUString const & s)73cdf0e10cSrcweir void printString(rtl::OUString const & s) {
74cdf0e10cSrcweir     printf("\"");
75cdf0e10cSrcweir     for (sal_Int32 i = 0; i < s.getLength(); ++i) {
76cdf0e10cSrcweir         sal_Unicode c = s[i];
77cdf0e10cSrcweir         if (c == '"' || c == '\\') {
78cdf0e10cSrcweir             printf("\\%c", static_cast< char >(c));
79cdf0e10cSrcweir         } else if (s[i] >= ' ' && s[i] <= '~') {
80cdf0e10cSrcweir             printf("%c", static_cast< char >(c));
81cdf0e10cSrcweir         } else {
82cdf0e10cSrcweir             printf("\\u%04X", static_cast< unsigned int >(c));
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir     printf("\"");
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
printFieldOrReferenceFlag(RTFieldAccess * flags,RTFieldAccess flag,char const * name,bool * first)88cdf0e10cSrcweir void printFieldOrReferenceFlag(
89cdf0e10cSrcweir     RTFieldAccess * flags, RTFieldAccess flag, char const * name, bool * first)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     if ((*flags & flag) != 0) {
92cdf0e10cSrcweir         if (!*first) {
93cdf0e10cSrcweir             printf("|");
94cdf0e10cSrcweir         }
95cdf0e10cSrcweir         *first = false;
96cdf0e10cSrcweir         printf("%s", name);
97cdf0e10cSrcweir         *flags &= ~flag;
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
printFieldOrReferenceFlags(RTFieldAccess flags)101cdf0e10cSrcweir void printFieldOrReferenceFlags(RTFieldAccess flags) {
102cdf0e10cSrcweir     if (flags == 0) {
103cdf0e10cSrcweir         printf("none");
104cdf0e10cSrcweir     } else {
105cdf0e10cSrcweir         bool first = true;
106cdf0e10cSrcweir         printFieldOrReferenceFlag(
107cdf0e10cSrcweir             &flags, RT_ACCESS_READONLY, "readonly", &first);
108cdf0e10cSrcweir         printFieldOrReferenceFlag(
109cdf0e10cSrcweir             &flags, RT_ACCESS_OPTIONAL, "optional", &first);
110cdf0e10cSrcweir         printFieldOrReferenceFlag(
111cdf0e10cSrcweir             &flags, RT_ACCESS_MAYBEVOID, "maybevoid", &first);
112cdf0e10cSrcweir         printFieldOrReferenceFlag(&flags, RT_ACCESS_BOUND, "bound", &first);
113cdf0e10cSrcweir         printFieldOrReferenceFlag(
114cdf0e10cSrcweir             &flags, RT_ACCESS_CONSTRAINED, "constrained", &first);
115cdf0e10cSrcweir         printFieldOrReferenceFlag(
116cdf0e10cSrcweir             &flags, RT_ACCESS_TRANSIENT, "transient", &first);
117cdf0e10cSrcweir         printFieldOrReferenceFlag(
118cdf0e10cSrcweir             &flags, RT_ACCESS_MAYBEAMBIGUOUS, "maybeambiguous", &first);
119cdf0e10cSrcweir         printFieldOrReferenceFlag(
120cdf0e10cSrcweir             &flags, RT_ACCESS_MAYBEDEFAULT, "maybedefault", &first);
121cdf0e10cSrcweir         printFieldOrReferenceFlag(
122cdf0e10cSrcweir             &flags, RT_ACCESS_REMOVEABLE, "removeable", &first);
123cdf0e10cSrcweir         printFieldOrReferenceFlag(
124cdf0e10cSrcweir             &flags, RT_ACCESS_ATTRIBUTE, "attribute", &first);
125cdf0e10cSrcweir         printFieldOrReferenceFlag(
126cdf0e10cSrcweir             &flags, RT_ACCESS_PROPERTY, "property", &first);
127cdf0e10cSrcweir         printFieldOrReferenceFlag(&flags, RT_ACCESS_CONST, "const", &first);
128cdf0e10cSrcweir         printFieldOrReferenceFlag(
129cdf0e10cSrcweir             &flags, RT_ACCESS_READWRITE, "readwrite", &first);
130cdf0e10cSrcweir         printFieldOrReferenceFlag(
131cdf0e10cSrcweir             &flags, RT_ACCESS_PARAMETERIZED_TYPE, "parameterized type", &first);
132cdf0e10cSrcweir         printFieldOrReferenceFlag(
133cdf0e10cSrcweir             &flags, RT_ACCESS_PUBLISHED, "published", &first);
134cdf0e10cSrcweir         if (flags != 0) {
135cdf0e10cSrcweir             if (!first) {
136cdf0e10cSrcweir                 printf("|");
137cdf0e10cSrcweir             }
138cdf0e10cSrcweir             printf("<invalid (0x%04X)>", static_cast< unsigned int >(flags));
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
dumpType(typereg::Reader const & reader,rtl::OString const & indent)143cdf0e10cSrcweir void dumpType(typereg::Reader const & reader, rtl::OString const & indent) {
144cdf0e10cSrcweir     if (reader.isValid()) {
145cdf0e10cSrcweir         printf("version: %ld\n", static_cast< long >(reader.getVersion()));
146cdf0e10cSrcweir         printf("%sdocumentation: ", indent.getStr());
147cdf0e10cSrcweir         printString(reader.getDocumentation());
148cdf0e10cSrcweir         printf("\n");
149cdf0e10cSrcweir         printf("%sfile name: ", indent.getStr());
150cdf0e10cSrcweir         printString(reader.getFileName());
151cdf0e10cSrcweir         printf("\n");
152cdf0e10cSrcweir         printf("%stype class: ", indent.getStr());
153cdf0e10cSrcweir         if (reader.isPublished()) {
154cdf0e10cSrcweir             printf("published ");
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir         switch (reader.getTypeClass()) {
157cdf0e10cSrcweir         case RT_TYPE_INTERFACE:
158cdf0e10cSrcweir             printf("interface");
159cdf0e10cSrcweir             break;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         case RT_TYPE_MODULE:
162cdf0e10cSrcweir             printf("module");
163cdf0e10cSrcweir             break;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         case RT_TYPE_STRUCT:
166cdf0e10cSrcweir             printf("struct");
167cdf0e10cSrcweir             break;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         case RT_TYPE_ENUM:
170cdf0e10cSrcweir             printf("enum");
171cdf0e10cSrcweir             break;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         case RT_TYPE_EXCEPTION:
174cdf0e10cSrcweir             printf("exception");
175cdf0e10cSrcweir             break;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         case RT_TYPE_TYPEDEF:
178cdf0e10cSrcweir             printf("typedef");
179cdf0e10cSrcweir             break;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         case RT_TYPE_SERVICE:
182cdf0e10cSrcweir             printf("service");
183cdf0e10cSrcweir             break;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         case RT_TYPE_SINGLETON:
186cdf0e10cSrcweir             printf("singleton");
187cdf0e10cSrcweir             break;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         case RT_TYPE_CONSTANTS:
190cdf0e10cSrcweir             printf("constants");
191cdf0e10cSrcweir             break;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         default:
194cdf0e10cSrcweir             printf(
195cdf0e10cSrcweir                 "<invalid (%ld)>", static_cast< long >(reader.getTypeClass()));
196cdf0e10cSrcweir             break;
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir         printf("\n");
199cdf0e10cSrcweir         printf("%stype name: ", indent.getStr());
200cdf0e10cSrcweir         printString(reader.getTypeName());
201cdf0e10cSrcweir         printf("\n");
202cdf0e10cSrcweir         printf(
203cdf0e10cSrcweir             "%ssuper type count: %u\n", indent.getStr(),
204cdf0e10cSrcweir             static_cast< unsigned int >(reader.getSuperTypeCount()));
205cdf0e10cSrcweir         {for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
206cdf0e10cSrcweir             printf(
207cdf0e10cSrcweir                 "%ssuper type name %u: ", indent.getStr(),
208cdf0e10cSrcweir                 static_cast< unsigned int >(i));
209cdf0e10cSrcweir             printString(reader.getSuperTypeName(i));
210cdf0e10cSrcweir             printf("\n");
211cdf0e10cSrcweir         }}
212cdf0e10cSrcweir         printf(
213cdf0e10cSrcweir             "%sfield count: %u\n", indent.getStr(),
214cdf0e10cSrcweir             static_cast< unsigned int >(reader.getFieldCount()));
215cdf0e10cSrcweir         {for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
216cdf0e10cSrcweir             printf(
217cdf0e10cSrcweir                 "%sfield %u:\n", indent.getStr(),
218cdf0e10cSrcweir                 static_cast< unsigned int >(i));
219cdf0e10cSrcweir             printf("%s    documentation: ", indent.getStr());
220cdf0e10cSrcweir             printString(reader.getFieldDocumentation(i));
221cdf0e10cSrcweir             printf("\n");
222cdf0e10cSrcweir             printf("%s    file name: ", indent.getStr());
223cdf0e10cSrcweir             printString(reader.getFieldFileName(i));
224cdf0e10cSrcweir             printf("\n");
225cdf0e10cSrcweir             printf("%s    flags: ", indent.getStr());
226cdf0e10cSrcweir             printFieldOrReferenceFlags(reader.getFieldFlags(i));
227cdf0e10cSrcweir             printf("\n");
228cdf0e10cSrcweir             printf("%s    name: ", indent.getStr());
229cdf0e10cSrcweir             printString(reader.getFieldName(i));
230cdf0e10cSrcweir             printf("\n");
231cdf0e10cSrcweir             printf("%s    type name: ", indent.getStr());
232cdf0e10cSrcweir             printString(reader.getFieldTypeName(i));
233cdf0e10cSrcweir             printf("\n");
234cdf0e10cSrcweir             printf("%s    value: ", indent.getStr());
235cdf0e10cSrcweir             RTConstValue value(reader.getFieldValue(i));
236cdf0e10cSrcweir             switch (value.m_type) {
237cdf0e10cSrcweir             case RT_TYPE_NONE:
238cdf0e10cSrcweir                 printf("none");
239cdf0e10cSrcweir                 break;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir             case RT_TYPE_BOOL:
242cdf0e10cSrcweir                 printf("boolean %s", value.m_value.aBool ? "true" : "false");
243cdf0e10cSrcweir                 break;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir             case RT_TYPE_BYTE:
246cdf0e10cSrcweir                 printf(
247cdf0e10cSrcweir                     "byte 0x%02X",
248cdf0e10cSrcweir                     static_cast< unsigned int >(value.m_value.aByte));
249cdf0e10cSrcweir                 break;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir             case RT_TYPE_INT16:
252cdf0e10cSrcweir                 printf("short %d", static_cast< int >(value.m_value.aShort));
253cdf0e10cSrcweir                 break;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir             case RT_TYPE_UINT16:
256cdf0e10cSrcweir                 printf(
257cdf0e10cSrcweir                     "unsigned short %u",
258cdf0e10cSrcweir                     static_cast< unsigned int >(value.m_value.aUShort));
259cdf0e10cSrcweir                 break;
260cdf0e10cSrcweir 
261cdf0e10cSrcweir             case RT_TYPE_INT32:
262cdf0e10cSrcweir                 printf("long %ld", static_cast< long >(value.m_value.aLong));
263cdf0e10cSrcweir                 break;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir             case RT_TYPE_UINT32:
266cdf0e10cSrcweir                 printf(
267cdf0e10cSrcweir                     "unsigned long %lu",
268cdf0e10cSrcweir                     static_cast< unsigned long >(value.m_value.aULong));
269cdf0e10cSrcweir                 break;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir             case RT_TYPE_INT64:
272cdf0e10cSrcweir                 // TODO: no portable way to print hyper values
273cdf0e10cSrcweir                 printf("hyper");
274cdf0e10cSrcweir                 break;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir             case RT_TYPE_UINT64:
277cdf0e10cSrcweir                 // TODO: no portable way to print unsigned hyper values
278cdf0e10cSrcweir                 printf("unsigned hyper");
279cdf0e10cSrcweir                 break;
280cdf0e10cSrcweir 
281cdf0e10cSrcweir             case RT_TYPE_FLOAT:
282cdf0e10cSrcweir                 // TODO: no portable way to print float values
283cdf0e10cSrcweir                 printf("float");
284cdf0e10cSrcweir                 break;
285cdf0e10cSrcweir 
286cdf0e10cSrcweir             case RT_TYPE_DOUBLE:
287cdf0e10cSrcweir                 // TODO: no portable way to print double values
288cdf0e10cSrcweir                 printf("double");
289cdf0e10cSrcweir                 break;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir             case RT_TYPE_STRING:
292cdf0e10cSrcweir                 printf("string ");
293cdf0e10cSrcweir                 printString(value.m_value.aString);
294cdf0e10cSrcweir                 break;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir             default:
297cdf0e10cSrcweir                 printf("<invalid (%ld)>", static_cast< long >(value.m_type));
298cdf0e10cSrcweir                 break;
299cdf0e10cSrcweir             }
300cdf0e10cSrcweir             printf("\n");
301cdf0e10cSrcweir         }}
302cdf0e10cSrcweir         printf(
303cdf0e10cSrcweir             "%smethod count: %u\n", indent.getStr(),
304cdf0e10cSrcweir             static_cast< unsigned int >(reader.getMethodCount()));
305cdf0e10cSrcweir         {for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) {
306cdf0e10cSrcweir             printf(
307cdf0e10cSrcweir                 "%smethod %u:\n", indent.getStr(),
308cdf0e10cSrcweir                 static_cast< unsigned int >(i));
309cdf0e10cSrcweir             printf("%s    documentation: ", indent.getStr());
310cdf0e10cSrcweir             printString(reader.getMethodDocumentation(i));
311cdf0e10cSrcweir             printf("\n");
312cdf0e10cSrcweir             printf("%s    flags: ", indent.getStr());
313cdf0e10cSrcweir             switch (reader.getMethodFlags(i)) {
314cdf0e10cSrcweir             case RT_MODE_ONEWAY:
315cdf0e10cSrcweir                 printf("oneway");
316cdf0e10cSrcweir                 break;
317cdf0e10cSrcweir 
318cdf0e10cSrcweir             case RT_MODE_TWOWAY:
319cdf0e10cSrcweir                 printf("synchronous");
320cdf0e10cSrcweir                 break;
321cdf0e10cSrcweir 
322cdf0e10cSrcweir             case RT_MODE_ATTRIBUTE_GET:
323cdf0e10cSrcweir                 printf("attribute get");
324cdf0e10cSrcweir                 break;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir             case RT_MODE_ATTRIBUTE_SET:
327cdf0e10cSrcweir                 printf("attribute set");
328cdf0e10cSrcweir                 break;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir             default:
331cdf0e10cSrcweir                 printf(
332cdf0e10cSrcweir                     "<invalid (%ld)>",
333cdf0e10cSrcweir                     static_cast< long >(reader.getMethodFlags(i)));
334cdf0e10cSrcweir                 break;
335cdf0e10cSrcweir             }
336cdf0e10cSrcweir             printf("\n");
337cdf0e10cSrcweir             printf("%s    name: ", indent.getStr());
338cdf0e10cSrcweir             printString(reader.getMethodName(i));
339cdf0e10cSrcweir             printf("\n");
340cdf0e10cSrcweir             printf("%s    return type name: ", indent.getStr());
341cdf0e10cSrcweir             printString(reader.getMethodReturnTypeName(i));
342cdf0e10cSrcweir             printf("\n");
343cdf0e10cSrcweir             printf(
344cdf0e10cSrcweir                 "%s    parameter count: %u\n", indent.getStr(),
345cdf0e10cSrcweir                 static_cast< unsigned int >(reader.getMethodParameterCount(i)));
346cdf0e10cSrcweir             for (sal_uInt16 j = 0; j < reader.getMethodParameterCount(i); ++j)
347cdf0e10cSrcweir             {
348cdf0e10cSrcweir                 printf(
349cdf0e10cSrcweir                     "%s    parameter %u:\n", indent.getStr(),
350cdf0e10cSrcweir                     static_cast< unsigned int >(j));
351cdf0e10cSrcweir                 printf("%s        flags: ", indent.getStr());
352cdf0e10cSrcweir                 RTParamMode flags = reader.getMethodParameterFlags(i, j);
353cdf0e10cSrcweir                 bool rest = (flags & RT_PARAM_REST) != 0;
354cdf0e10cSrcweir                 switch (flags & ~RT_PARAM_REST) {
355cdf0e10cSrcweir                 case RT_PARAM_IN:
356cdf0e10cSrcweir                     printf("in");
357cdf0e10cSrcweir                     break;
358cdf0e10cSrcweir 
359cdf0e10cSrcweir                 case RT_PARAM_OUT:
360cdf0e10cSrcweir                     printf("out");
361cdf0e10cSrcweir                     break;
362cdf0e10cSrcweir 
363cdf0e10cSrcweir                 case RT_PARAM_INOUT:
364cdf0e10cSrcweir                     printf("inout");
365cdf0e10cSrcweir                     break;
366cdf0e10cSrcweir 
367cdf0e10cSrcweir                 default:
368cdf0e10cSrcweir                     printf("<invalid (%ld)>", static_cast< long >(flags));
369cdf0e10cSrcweir                     rest = false;
370cdf0e10cSrcweir                     break;
371cdf0e10cSrcweir                 }
372cdf0e10cSrcweir                 if (rest) {
373cdf0e10cSrcweir                     printf("|rest");
374cdf0e10cSrcweir                 }
375cdf0e10cSrcweir                 printf("\n");
376cdf0e10cSrcweir                 printf("%s        name: ", indent.getStr());
377cdf0e10cSrcweir                 printString(reader.getMethodParameterName(i, j));
378cdf0e10cSrcweir                 printf("\n");
379cdf0e10cSrcweir                 printf("%s        type name: ", indent.getStr());
380cdf0e10cSrcweir                 printString(reader.getMethodParameterTypeName(i, j));
381cdf0e10cSrcweir                 printf("\n");
382cdf0e10cSrcweir             }
383cdf0e10cSrcweir             printf(
384cdf0e10cSrcweir                 "%s    exception count: %u\n", indent.getStr(),
385cdf0e10cSrcweir                 static_cast< unsigned int >(reader.getMethodExceptionCount(i)));
386cdf0e10cSrcweir             for (sal_uInt16 j = 0; j < reader.getMethodExceptionCount(i); ++j)
387cdf0e10cSrcweir             {
388cdf0e10cSrcweir                 printf(
389cdf0e10cSrcweir                     "%s    exception type name %u: ", indent.getStr(),
390cdf0e10cSrcweir                     static_cast< unsigned int >(j));
391cdf0e10cSrcweir                 printString(reader.getMethodExceptionTypeName(i, j));
392cdf0e10cSrcweir                 printf("\n");
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir         }}
395cdf0e10cSrcweir         printf(
396cdf0e10cSrcweir             "%sreference count: %u\n", indent.getStr(),
397cdf0e10cSrcweir             static_cast< unsigned int >(reader.getReferenceCount()));
398cdf0e10cSrcweir         {for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) {
399cdf0e10cSrcweir             printf(
400cdf0e10cSrcweir                 "%sreference %u:\n", indent.getStr(),
401cdf0e10cSrcweir                 static_cast< unsigned int >(i));
402cdf0e10cSrcweir             printf("%s    documentation: ", indent.getStr());
403cdf0e10cSrcweir             printString(reader.getReferenceDocumentation(i));
404cdf0e10cSrcweir             printf("\n");
405cdf0e10cSrcweir             printf("%s    flags: ", indent.getStr());
406cdf0e10cSrcweir             printFieldOrReferenceFlags(reader.getReferenceFlags(i));
407cdf0e10cSrcweir             printf("\n");
408cdf0e10cSrcweir             printf("%s    sort: ", indent.getStr());
409cdf0e10cSrcweir             switch (reader.getReferenceSort(i)) {
410cdf0e10cSrcweir             case RT_REF_SUPPORTS:
411cdf0e10cSrcweir                 printf("supports");
412cdf0e10cSrcweir                 break;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir             case RT_REF_EXPORTS:
415cdf0e10cSrcweir                 printf("exports");
416cdf0e10cSrcweir                 break;
417cdf0e10cSrcweir 
418cdf0e10cSrcweir             case RT_REF_TYPE_PARAMETER:
419cdf0e10cSrcweir                 printf("type parameter");
420cdf0e10cSrcweir                 break;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir             default:
423cdf0e10cSrcweir                 printf(
424cdf0e10cSrcweir                     "<invalid (%ld)>",
425cdf0e10cSrcweir                     static_cast< long >(reader.getReferenceSort(i)));
426cdf0e10cSrcweir                 break;
427cdf0e10cSrcweir             }
428cdf0e10cSrcweir             printf("\n");
429cdf0e10cSrcweir             printf("%s    type name: ", indent.getStr());
430cdf0e10cSrcweir             printString(reader.getReferenceTypeName(i));
431cdf0e10cSrcweir             printf("\n");
432cdf0e10cSrcweir         }}
433cdf0e10cSrcweir     } else {
434cdf0e10cSrcweir         printf("<invalid>\n");
435cdf0e10cSrcweir     }
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir //*********************************************************************
441cdf0e10cSrcweir //  ORegistry()
442cdf0e10cSrcweir //
ORegistry()443cdf0e10cSrcweir ORegistry::ORegistry()
444cdf0e10cSrcweir     : m_refCount(1)
445cdf0e10cSrcweir     , m_readOnly(sal_False)
446cdf0e10cSrcweir     , m_isOpen(sal_False)
447cdf0e10cSrcweir 	, ROOT( RTL_CONSTASCII_USTRINGPARAM("/") )
448cdf0e10cSrcweir {
449cdf0e10cSrcweir }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir //*********************************************************************
452cdf0e10cSrcweir //  ~ORegistry()
453cdf0e10cSrcweir //
~ORegistry()454cdf0e10cSrcweir ORegistry::~ORegistry()
455cdf0e10cSrcweir {
456cdf0e10cSrcweir 	ORegKey* pRootKey = m_openKeyTable[ROOT];
457cdf0e10cSrcweir 	if (pRootKey != 0)
458cdf0e10cSrcweir 		(void) releaseKey(pRootKey);
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     if (m_file.isValid())
461cdf0e10cSrcweir         m_file.close();
462cdf0e10cSrcweir }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 
465cdf0e10cSrcweir //*********************************************************************
466cdf0e10cSrcweir //  initRegistry
467cdf0e10cSrcweir //
initRegistry(const OUString & regName,RegAccessMode accessMode)468cdf0e10cSrcweir RegError ORegistry::initRegistry(const OUString& regName, RegAccessMode accessMode)
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     OStoreFile      rRegFile;
471cdf0e10cSrcweir     storeAccessMode sAccessMode = REG_MODE_OPEN;
472cdf0e10cSrcweir     storeError      errCode;
473cdf0e10cSrcweir 
474cdf0e10cSrcweir     if (accessMode & REG_CREATE)
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir         sAccessMode = REG_MODE_CREATE;
477cdf0e10cSrcweir     } else
478cdf0e10cSrcweir     if (accessMode & REG_READONLY)
479cdf0e10cSrcweir     {
480cdf0e10cSrcweir         sAccessMode = REG_MODE_OPENREAD;
481cdf0e10cSrcweir         m_readOnly = sal_True;
482cdf0e10cSrcweir     }
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     if (0 == regName.getLength() &&
485cdf0e10cSrcweir         store_AccessCreate == sAccessMode)
486cdf0e10cSrcweir     {
487cdf0e10cSrcweir         errCode = rRegFile.createInMemory();
488cdf0e10cSrcweir     }
489cdf0e10cSrcweir     else
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         errCode = rRegFile.create(regName, sAccessMode, REG_PAGESIZE);
492cdf0e10cSrcweir     }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     if (errCode)
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir         switch (errCode)
497cdf0e10cSrcweir         {
498cdf0e10cSrcweir             case  store_E_NotExists:
499cdf0e10cSrcweir                 return REG_REGISTRY_NOT_EXISTS;
500cdf0e10cSrcweir             case store_E_LockingViolation:
501cdf0e10cSrcweir                 return REG_CANNOT_OPEN_FOR_READWRITE;
502cdf0e10cSrcweir             default:
503cdf0e10cSrcweir                 return REG_INVALID_REGISTRY;
504cdf0e10cSrcweir         }
505cdf0e10cSrcweir     } else
506cdf0e10cSrcweir     {
507cdf0e10cSrcweir         OStoreDirectory rStoreDir;
508cdf0e10cSrcweir         storeError      _err = rStoreDir.create(rRegFile, OUString(), OUString(), sAccessMode);
509cdf0e10cSrcweir 
510cdf0e10cSrcweir         if ( _err == store_E_None )
511cdf0e10cSrcweir         {
512cdf0e10cSrcweir             m_file = rRegFile;
513cdf0e10cSrcweir             m_name = regName;
514cdf0e10cSrcweir             m_isOpen = sal_True;
515cdf0e10cSrcweir 
516cdf0e10cSrcweir             m_openKeyTable[ROOT] = new ORegKey(ROOT, this);
517cdf0e10cSrcweir             return REG_NO_ERROR;
518cdf0e10cSrcweir         } else
519cdf0e10cSrcweir             return REG_INVALID_REGISTRY;
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 
524cdf0e10cSrcweir //*********************************************************************
525cdf0e10cSrcweir //  closeRegistry
526cdf0e10cSrcweir //
closeRegistry()527cdf0e10cSrcweir RegError ORegistry::closeRegistry()
528cdf0e10cSrcweir {
529cdf0e10cSrcweir     REG_GUARD(m_mutex);
530cdf0e10cSrcweir 
531cdf0e10cSrcweir     if (m_file.isValid())
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         (void) releaseKey(m_openKeyTable[ROOT]);
534cdf0e10cSrcweir         m_file.close();
535cdf0e10cSrcweir         m_isOpen = sal_False;
536cdf0e10cSrcweir         return REG_NO_ERROR;
537cdf0e10cSrcweir     } else
538cdf0e10cSrcweir     {
539cdf0e10cSrcweir         return REG_REGISTRY_NOT_EXISTS;
540cdf0e10cSrcweir     }
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir 
544cdf0e10cSrcweir //*********************************************************************
545cdf0e10cSrcweir //  destroyRegistry
546cdf0e10cSrcweir //
destroyRegistry(const OUString & regName)547cdf0e10cSrcweir RegError ORegistry::destroyRegistry(const OUString& regName)
548cdf0e10cSrcweir {
549cdf0e10cSrcweir     REG_GUARD(m_mutex);
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     if (regName.getLength())
552cdf0e10cSrcweir     {
553cdf0e10cSrcweir         ORegistry* pReg = new ORegistry();
554cdf0e10cSrcweir 
555cdf0e10cSrcweir         if (!pReg->initRegistry(regName, REG_READWRITE))
556cdf0e10cSrcweir         {
557cdf0e10cSrcweir             delete pReg;
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 			OUString systemName;
560cdf0e10cSrcweir 			if ( FileBase::getSystemPathFromFileURL(regName, systemName) != FileBase::E_None )
561cdf0e10cSrcweir 				systemName = regName;
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 			OString name( OUStringToOString(systemName, osl_getThreadTextEncoding()) );
564*24c56ab9SHerbert Dürr             if( unlink( name.getStr()) != 0)
565cdf0e10cSrcweir             {
566cdf0e10cSrcweir                 return REG_DESTROY_REGISTRY_FAILED;
567cdf0e10cSrcweir             }
568cdf0e10cSrcweir         } else
569cdf0e10cSrcweir         {
570cdf0e10cSrcweir             return REG_DESTROY_REGISTRY_FAILED;
571cdf0e10cSrcweir         }
572cdf0e10cSrcweir     } else
573cdf0e10cSrcweir     {
574cdf0e10cSrcweir         if (m_refCount != 1 || isReadOnly())
575cdf0e10cSrcweir         {
576cdf0e10cSrcweir             return REG_DESTROY_REGISTRY_FAILED;
577cdf0e10cSrcweir         }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir         if (m_file.isValid())
580cdf0e10cSrcweir         {
581cdf0e10cSrcweir             releaseKey(m_openKeyTable[ROOT]);
582cdf0e10cSrcweir             m_file.close();
583cdf0e10cSrcweir             m_isOpen = sal_False;
584cdf0e10cSrcweir 
585cdf0e10cSrcweir             if (m_name.getLength())
586cdf0e10cSrcweir             {
587cdf0e10cSrcweir                 OUString systemName;
588cdf0e10cSrcweir                 if ( FileBase::getSystemPathFromFileURL(m_name, systemName) != FileBase::E_None )
589cdf0e10cSrcweir                     systemName = m_name;
590cdf0e10cSrcweir 
591cdf0e10cSrcweir                 OString name( OUStringToOString(systemName, osl_getThreadTextEncoding()) );
592cdf0e10cSrcweir                 if (unlink(name.getStr()) != 0)
593cdf0e10cSrcweir                 {
594cdf0e10cSrcweir                     return REG_DESTROY_REGISTRY_FAILED;
595cdf0e10cSrcweir                 }
596cdf0e10cSrcweir             }
597cdf0e10cSrcweir         } else
598cdf0e10cSrcweir         {
599cdf0e10cSrcweir             return REG_REGISTRY_NOT_EXISTS;
600cdf0e10cSrcweir         }
601cdf0e10cSrcweir     }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir     return REG_NO_ERROR;
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir //*********************************************************************
607cdf0e10cSrcweir //  acquireKey
608cdf0e10cSrcweir //
acquireKey(RegKeyHandle hKey)609cdf0e10cSrcweir RegError ORegistry::acquireKey (RegKeyHandle hKey)
610cdf0e10cSrcweir {
611cdf0e10cSrcweir 	ORegKey* pKey = static_cast< ORegKey* >(hKey);
612cdf0e10cSrcweir 	if (!pKey)
613cdf0e10cSrcweir 		return REG_INVALID_KEY;
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 	REG_GUARD(m_mutex);
616cdf0e10cSrcweir 	pKey->acquire();
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 	return REG_NO_ERROR;
619cdf0e10cSrcweir }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir //*********************************************************************
622cdf0e10cSrcweir //  releaseKey
623cdf0e10cSrcweir //
releaseKey(RegKeyHandle hKey)624cdf0e10cSrcweir RegError ORegistry::releaseKey (RegKeyHandle hKey)
625cdf0e10cSrcweir {
626cdf0e10cSrcweir 	ORegKey* pKey = static_cast< ORegKey* >(hKey);
627cdf0e10cSrcweir 	if (!pKey)
628cdf0e10cSrcweir 		return REG_INVALID_KEY;
629cdf0e10cSrcweir 
630cdf0e10cSrcweir 	REG_GUARD(m_mutex);
631cdf0e10cSrcweir 	if (pKey->release() == 0)
632cdf0e10cSrcweir 	{
633cdf0e10cSrcweir 		m_openKeyTable.erase(pKey->getName());
634cdf0e10cSrcweir 		delete pKey;
635cdf0e10cSrcweir 	}
636cdf0e10cSrcweir 	return REG_NO_ERROR;
637cdf0e10cSrcweir }
638cdf0e10cSrcweir 
639cdf0e10cSrcweir //*********************************************************************
640cdf0e10cSrcweir //  createKey
641cdf0e10cSrcweir //
createKey(RegKeyHandle hKey,const OUString & keyName,RegKeyHandle * phNewKey)642cdf0e10cSrcweir RegError ORegistry::createKey(RegKeyHandle hKey, const OUString& keyName,
643cdf0e10cSrcweir                               RegKeyHandle* phNewKey)
644cdf0e10cSrcweir {
645cdf0e10cSrcweir     ORegKey*    pKey;
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     *phNewKey = NULL;
648cdf0e10cSrcweir 
649cdf0e10cSrcweir     if ( !keyName.getLength() )
650cdf0e10cSrcweir         return REG_INVALID_KEYNAME;
651cdf0e10cSrcweir 
652cdf0e10cSrcweir     REG_GUARD(m_mutex);
653cdf0e10cSrcweir 
654cdf0e10cSrcweir     if (hKey)
655cdf0e10cSrcweir         pKey = (ORegKey*)hKey;
656cdf0e10cSrcweir     else
657cdf0e10cSrcweir         pKey = m_openKeyTable[ROOT];
658cdf0e10cSrcweir 
659cdf0e10cSrcweir     OUString sFullKeyName = pKey->getFullPath(keyName);
660cdf0e10cSrcweir 
661cdf0e10cSrcweir     if (m_openKeyTable.count(sFullKeyName) > 0)
662cdf0e10cSrcweir     {
663cdf0e10cSrcweir         *phNewKey = m_openKeyTable[sFullKeyName];
664cdf0e10cSrcweir         ((ORegKey*)*phNewKey)->acquire();
665cdf0e10cSrcweir         ((ORegKey*)*phNewKey)->setDeleted(sal_False);
666cdf0e10cSrcweir         return REG_NO_ERROR;
667cdf0e10cSrcweir     }
668cdf0e10cSrcweir 
669cdf0e10cSrcweir     OStoreDirectory rStoreDir;
670cdf0e10cSrcweir     OUStringBuffer  sFullPath(sFullKeyName.getLength());
671cdf0e10cSrcweir     OUString        token;
672cdf0e10cSrcweir 
673cdf0e10cSrcweir     sFullPath.append((sal_Unicode)'/');
674cdf0e10cSrcweir 
675cdf0e10cSrcweir     sal_Int32 nIndex = 0;
676cdf0e10cSrcweir     do
677cdf0e10cSrcweir     {
678cdf0e10cSrcweir         token = sFullKeyName.getToken( 0, '/', nIndex );
679cdf0e10cSrcweir         if (token.getLength())
680cdf0e10cSrcweir         {
681cdf0e10cSrcweir             if (rStoreDir.create(pKey->getStoreFile(), sFullPath.getStr(), token, KEY_MODE_CREATE))
682cdf0e10cSrcweir             {
683cdf0e10cSrcweir                 return REG_CREATE_KEY_FAILED;
684cdf0e10cSrcweir             }
685cdf0e10cSrcweir 
686cdf0e10cSrcweir             sFullPath.append(token);
687cdf0e10cSrcweir             sFullPath.append((sal_Unicode)'/');
688cdf0e10cSrcweir         }
689cdf0e10cSrcweir     } while( nIndex != -1 );
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 
692cdf0e10cSrcweir     pKey = new ORegKey(sFullKeyName, this);
693cdf0e10cSrcweir     *phNewKey = pKey;
694cdf0e10cSrcweir     m_openKeyTable[sFullKeyName] = pKey;
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     return REG_NO_ERROR;
697cdf0e10cSrcweir }
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 
700cdf0e10cSrcweir //*********************************************************************
701cdf0e10cSrcweir //  openKey
702cdf0e10cSrcweir //
openKey(RegKeyHandle hKey,const OUString & keyName,RegKeyHandle * phOpenKey)703cdf0e10cSrcweir RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName,
704cdf0e10cSrcweir                             RegKeyHandle* phOpenKey)
705cdf0e10cSrcweir {
706cdf0e10cSrcweir     ORegKey*        pKey;
707cdf0e10cSrcweir 
708cdf0e10cSrcweir     *phOpenKey = NULL;
709cdf0e10cSrcweir 
710cdf0e10cSrcweir     if ( !keyName.getLength() )
711cdf0e10cSrcweir     {
712cdf0e10cSrcweir         return REG_INVALID_KEYNAME;
713cdf0e10cSrcweir     }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir     REG_GUARD(m_mutex);
716cdf0e10cSrcweir 
717cdf0e10cSrcweir     if (hKey)
718cdf0e10cSrcweir         pKey = (ORegKey*)hKey;
719cdf0e10cSrcweir     else
720cdf0e10cSrcweir         pKey = m_openKeyTable[ROOT];
721cdf0e10cSrcweir 
722cdf0e10cSrcweir     OUString path(pKey->getFullPath(keyName));
723cdf0e10cSrcweir     KeyMap::iterator i(m_openKeyTable.find(path));
724cdf0e10cSrcweir     if (i == m_openKeyTable.end()) {
725cdf0e10cSrcweir         sal_Int32 n = path.lastIndexOf('/') + 1;
726cdf0e10cSrcweir         switch (OStoreDirectory().create(
727cdf0e10cSrcweir                     pKey->getStoreFile(), path.copy(0, n), path.copy(n),
728cdf0e10cSrcweir                     isReadOnly() ? KEY_MODE_OPENREAD : KEY_MODE_OPEN))
729cdf0e10cSrcweir         {
730cdf0e10cSrcweir         case store_E_NotExists:
731cdf0e10cSrcweir             return REG_KEY_NOT_EXISTS;
732cdf0e10cSrcweir         case store_E_WrongFormat:
733cdf0e10cSrcweir             return REG_INVALID_KEY;
734cdf0e10cSrcweir         default:
735cdf0e10cSrcweir             break;
736cdf0e10cSrcweir         }
737cdf0e10cSrcweir 
738cdf0e10cSrcweir         std::auto_ptr< ORegKey > p(new ORegKey(path, this));
739cdf0e10cSrcweir         i = m_openKeyTable.insert(std::make_pair(path, p.get())).first;
740cdf0e10cSrcweir         p.release();
741cdf0e10cSrcweir     } else {
742cdf0e10cSrcweir         i->second->acquire();
743cdf0e10cSrcweir     }
744cdf0e10cSrcweir     *phOpenKey = i->second;
745cdf0e10cSrcweir     return REG_NO_ERROR;
746cdf0e10cSrcweir }
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 
749cdf0e10cSrcweir //*********************************************************************
750cdf0e10cSrcweir //  closeKey
751cdf0e10cSrcweir //
closeKey(RegKeyHandle hKey)752cdf0e10cSrcweir RegError ORegistry::closeKey(RegKeyHandle hKey)
753cdf0e10cSrcweir {
754cdf0e10cSrcweir     ORegKey* pKey = static_cast< ORegKey* >(hKey);
755cdf0e10cSrcweir 
756cdf0e10cSrcweir     REG_GUARD(m_mutex);
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 	OUString const aKeyName (pKey->getName());
759cdf0e10cSrcweir     if (!(m_openKeyTable.count(aKeyName) > 0))
760cdf0e10cSrcweir         return REG_KEY_NOT_OPEN;
761cdf0e10cSrcweir 
762cdf0e10cSrcweir 	if (pKey->isModified())
763cdf0e10cSrcweir 	{
764cdf0e10cSrcweir 		ORegKey * pRootKey = getRootKey();
765cdf0e10cSrcweir 		if (pKey != pRootKey)
766cdf0e10cSrcweir 		{
767cdf0e10cSrcweir 			// propagate "modified" state to RootKey.
768cdf0e10cSrcweir 			pRootKey->setModified();
769cdf0e10cSrcweir 		}
770cdf0e10cSrcweir 		else
771cdf0e10cSrcweir 		{
772cdf0e10cSrcweir 			// closing modified RootKey, flush registry file.
773cdf0e10cSrcweir 			OSL_TRACE("registry::ORegistry::closeKey(): flushing modified RootKey");
774cdf0e10cSrcweir 			(void) m_file.flush();
775cdf0e10cSrcweir 		}
776cdf0e10cSrcweir 		pKey->setModified(false);
777cdf0e10cSrcweir 		(void) releaseKey(pRootKey);
778cdf0e10cSrcweir 	}
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 	return releaseKey(pKey);
781cdf0e10cSrcweir }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir //*********************************************************************
784cdf0e10cSrcweir //  deleteKey
785cdf0e10cSrcweir //
deleteKey(RegKeyHandle hKey,const OUString & keyName)786cdf0e10cSrcweir RegError ORegistry::deleteKey(RegKeyHandle hKey, const OUString& keyName)
787cdf0e10cSrcweir {
788cdf0e10cSrcweir     ORegKey* pKey = static_cast< ORegKey* >(hKey);
789cdf0e10cSrcweir     if ( !keyName.getLength() )
790cdf0e10cSrcweir         return REG_INVALID_KEYNAME;
791cdf0e10cSrcweir 
792cdf0e10cSrcweir     REG_GUARD(m_mutex);
793cdf0e10cSrcweir 
794cdf0e10cSrcweir 	if (!pKey)
795cdf0e10cSrcweir 		pKey = m_openKeyTable[ROOT];
796cdf0e10cSrcweir 
797cdf0e10cSrcweir     OUString sFullKeyName(pKey->getFullPath(keyName));
798cdf0e10cSrcweir     return eraseKey(m_openKeyTable[ROOT], sFullKeyName);
799cdf0e10cSrcweir }
800cdf0e10cSrcweir 
eraseKey(ORegKey * pKey,const OUString & keyName)801cdf0e10cSrcweir RegError ORegistry::eraseKey(ORegKey* pKey, const OUString& keyName)
802cdf0e10cSrcweir {
803cdf0e10cSrcweir     RegError _ret = REG_NO_ERROR;
804cdf0e10cSrcweir 
805cdf0e10cSrcweir     if ( !keyName.getLength() )
806cdf0e10cSrcweir     {
807cdf0e10cSrcweir         return REG_INVALID_KEYNAME;
808cdf0e10cSrcweir     }
809cdf0e10cSrcweir 
810cdf0e10cSrcweir     OUString     sFullKeyName(pKey->getName());
811cdf0e10cSrcweir     OUString     sFullPath(sFullKeyName);
812cdf0e10cSrcweir     OUString     sRelativKey;
813cdf0e10cSrcweir     sal_Int32	 lastIndex = keyName.lastIndexOf('/');
814cdf0e10cSrcweir 
815cdf0e10cSrcweir     if ( lastIndex >= 0 )
816cdf0e10cSrcweir     {
817cdf0e10cSrcweir         sRelativKey += keyName.copy(lastIndex + 1);
818cdf0e10cSrcweir 
819cdf0e10cSrcweir         if (sFullKeyName.getLength() > 1)
820cdf0e10cSrcweir             sFullKeyName += keyName;
821cdf0e10cSrcweir         else
822*24c56ab9SHerbert Dürr             sFullKeyName += keyName.getStr() + 1;
823cdf0e10cSrcweir 
824cdf0e10cSrcweir         sFullPath = sFullKeyName.copy(0, keyName.lastIndexOf('/') + 1);
825cdf0e10cSrcweir     } else
826cdf0e10cSrcweir     {
827cdf0e10cSrcweir         if (sFullKeyName.getLength() > 1)
828cdf0e10cSrcweir             sFullKeyName += ROOT;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir         sRelativKey += keyName;
831cdf0e10cSrcweir         sFullKeyName += keyName;
832cdf0e10cSrcweir 
833cdf0e10cSrcweir         if (sFullPath.getLength() > 1)
834cdf0e10cSrcweir             sFullPath += ROOT;
835cdf0e10cSrcweir     }
836cdf0e10cSrcweir 
837cdf0e10cSrcweir     ORegKey* pOldKey = 0;
838cdf0e10cSrcweir     _ret = pKey->openKey(keyName, (RegKeyHandle*)&pOldKey);
839cdf0e10cSrcweir     if (_ret != REG_NO_ERROR)
840cdf0e10cSrcweir         return _ret;
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     _ret = deleteSubkeysAndValues(pOldKey);
843cdf0e10cSrcweir     if (_ret != REG_NO_ERROR)
844cdf0e10cSrcweir     {
845cdf0e10cSrcweir         pKey->closeKey(pOldKey);
846cdf0e10cSrcweir         return _ret;
847cdf0e10cSrcweir     }
848cdf0e10cSrcweir 
849cdf0e10cSrcweir     OUString tmpName(sRelativKey);
850cdf0e10cSrcweir     tmpName += ROOT;
851cdf0e10cSrcweir 
852cdf0e10cSrcweir     OStoreFile sFile(pKey->getStoreFile());
853cdf0e10cSrcweir     if ( sFile.isValid() && sFile.remove(sFullPath, tmpName) )
854cdf0e10cSrcweir     {
855cdf0e10cSrcweir         return REG_DELETE_KEY_FAILED;
856cdf0e10cSrcweir     }
857cdf0e10cSrcweir 	pOldKey->setModified();
858cdf0e10cSrcweir 
859cdf0e10cSrcweir     // set flag deleted !!!
860cdf0e10cSrcweir     pOldKey->setDeleted(sal_True);
861cdf0e10cSrcweir 
862cdf0e10cSrcweir     return pKey->closeKey(pOldKey);
863cdf0e10cSrcweir }
864cdf0e10cSrcweir 
865cdf0e10cSrcweir //*********************************************************************
866cdf0e10cSrcweir //  deleteSubKeysAndValues
867cdf0e10cSrcweir //
deleteSubkeysAndValues(ORegKey * pKey)868cdf0e10cSrcweir RegError ORegistry::deleteSubkeysAndValues(ORegKey* pKey)
869cdf0e10cSrcweir {
870cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
871cdf0e10cSrcweir     RegError                    _ret = REG_NO_ERROR;
872cdf0e10cSrcweir     OStoreDirectory             rStoreDir(pKey->getStoreDir());
873cdf0e10cSrcweir     storeError                  _err = rStoreDir.first(iter);
874cdf0e10cSrcweir 
875cdf0e10cSrcweir     while ( _err == store_E_None )
876cdf0e10cSrcweir     {
877cdf0e10cSrcweir         OUString const keyName = iter.m_pszName;
878cdf0e10cSrcweir 
879cdf0e10cSrcweir         if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
880cdf0e10cSrcweir         {
881cdf0e10cSrcweir             _ret = eraseKey(pKey, keyName);
882cdf0e10cSrcweir             if (_ret)
883cdf0e10cSrcweir                 return _ret;
884cdf0e10cSrcweir         }
885cdf0e10cSrcweir 		else
886cdf0e10cSrcweir         {
887cdf0e10cSrcweir             OUString sFullPath(pKey->getName());
888cdf0e10cSrcweir 
889cdf0e10cSrcweir             if (sFullPath.getLength() > 1)
890cdf0e10cSrcweir                 sFullPath += ROOT;
891cdf0e10cSrcweir 
892cdf0e10cSrcweir             if ( ((OStoreFile&)pKey->getStoreFile()).remove(sFullPath, keyName) )
893cdf0e10cSrcweir             {
894cdf0e10cSrcweir                 return REG_DELETE_VALUE_FAILED;
895cdf0e10cSrcweir             }
896cdf0e10cSrcweir 			pKey->setModified();
897cdf0e10cSrcweir         }
898cdf0e10cSrcweir 
899cdf0e10cSrcweir         _err = rStoreDir.next(iter);
900cdf0e10cSrcweir     }
901cdf0e10cSrcweir 
902cdf0e10cSrcweir     return REG_NO_ERROR;
903cdf0e10cSrcweir }
904cdf0e10cSrcweir 
905cdf0e10cSrcweir 
906cdf0e10cSrcweir //*********************************************************************
907cdf0e10cSrcweir //  loadKey
908cdf0e10cSrcweir //
loadKey(RegKeyHandle hKey,const OUString & regFileName,sal_Bool bWarnings,sal_Bool bReport)909cdf0e10cSrcweir RegError ORegistry::loadKey(RegKeyHandle hKey, const OUString& regFileName,
910cdf0e10cSrcweir                             sal_Bool bWarnings, sal_Bool bReport)
911cdf0e10cSrcweir {
912cdf0e10cSrcweir     RegError _ret = REG_NO_ERROR;
913cdf0e10cSrcweir     ORegKey* pKey = static_cast< ORegKey* >(hKey);
914cdf0e10cSrcweir 
915cdf0e10cSrcweir     std::auto_ptr< ORegistry > pReg (new ORegistry());
916cdf0e10cSrcweir     _ret = pReg->initRegistry(regFileName, REG_READONLY);
917cdf0e10cSrcweir     if (_ret != REG_NO_ERROR)
918cdf0e10cSrcweir         return _ret;
919cdf0e10cSrcweir     ORegKey* pRootKey = pReg->getRootKey();
920cdf0e10cSrcweir 
921cdf0e10cSrcweir     REG_GUARD(m_mutex);
922cdf0e10cSrcweir 
923cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
924cdf0e10cSrcweir     OStoreDirectory             rStoreDir(pRootKey->getStoreDir());
925cdf0e10cSrcweir     storeError                  _err = rStoreDir.first(iter);
926cdf0e10cSrcweir 
927cdf0e10cSrcweir     while ( _err == store_E_None )
928cdf0e10cSrcweir     {
929cdf0e10cSrcweir 		OUString const keyName = iter.m_pszName;
930cdf0e10cSrcweir 
931cdf0e10cSrcweir         if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR )
932cdf0e10cSrcweir         {
933cdf0e10cSrcweir             _ret = loadAndSaveKeys(pKey, pRootKey, keyName, 0, bWarnings, bReport);
934cdf0e10cSrcweir         }
935cdf0e10cSrcweir 		else
936cdf0e10cSrcweir         {
937cdf0e10cSrcweir             _ret = loadAndSaveValue(pKey, pRootKey, keyName, 0, bWarnings, bReport);
938cdf0e10cSrcweir         }
939cdf0e10cSrcweir 
940cdf0e10cSrcweir         if (_ret == REG_MERGE_ERROR)
941cdf0e10cSrcweir 			break;
942cdf0e10cSrcweir 		if (_ret == REG_MERGE_CONFLICT && bWarnings)
943cdf0e10cSrcweir 			break;
944cdf0e10cSrcweir 
945cdf0e10cSrcweir         _err = rStoreDir.next(iter);
946cdf0e10cSrcweir     }
947cdf0e10cSrcweir 
948cdf0e10cSrcweir     rStoreDir = OStoreDirectory();
949cdf0e10cSrcweir     (void) pReg->releaseKey(pRootKey);
950cdf0e10cSrcweir     return _ret;
951cdf0e10cSrcweir }
952cdf0e10cSrcweir 
953cdf0e10cSrcweir 
954cdf0e10cSrcweir //*********************************************************************
955cdf0e10cSrcweir //  saveKey
956cdf0e10cSrcweir //
saveKey(RegKeyHandle hKey,const OUString & regFileName,sal_Bool bWarnings,sal_Bool bReport)957cdf0e10cSrcweir RegError ORegistry::saveKey(RegKeyHandle hKey, const OUString& regFileName,
958cdf0e10cSrcweir                             sal_Bool bWarnings, sal_Bool bReport)
959cdf0e10cSrcweir {
960cdf0e10cSrcweir     RegError _ret = REG_NO_ERROR;
961cdf0e10cSrcweir     ORegKey* pKey = static_cast< ORegKey* >(hKey);
962cdf0e10cSrcweir 
963cdf0e10cSrcweir     std::auto_ptr< ORegistry > pReg (new ORegistry());
964cdf0e10cSrcweir     _ret = pReg->initRegistry(regFileName, REG_CREATE);
965cdf0e10cSrcweir     if (_ret != REG_NO_ERROR)
966cdf0e10cSrcweir         return _ret;
967cdf0e10cSrcweir     ORegKey* pRootKey = pReg->getRootKey();
968cdf0e10cSrcweir 
969cdf0e10cSrcweir     REG_GUARD(m_mutex);
970cdf0e10cSrcweir 
971cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
972cdf0e10cSrcweir     OStoreDirectory             rStoreDir(pKey->getStoreDir());
973cdf0e10cSrcweir     storeError                  _err = rStoreDir.first(iter);
974cdf0e10cSrcweir 
975cdf0e10cSrcweir     while ( _err == store_E_None )
976cdf0e10cSrcweir     {
977cdf0e10cSrcweir 		OUString const keyName = iter.m_pszName;
978cdf0e10cSrcweir 
979cdf0e10cSrcweir         if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR )
980cdf0e10cSrcweir         {
981cdf0e10cSrcweir             _ret = loadAndSaveKeys(pRootKey, pKey, keyName,
982cdf0e10cSrcweir                                    pKey->getName().getLength(),
983cdf0e10cSrcweir                                    bWarnings, bReport);
984cdf0e10cSrcweir         }
985cdf0e10cSrcweir 		else
986cdf0e10cSrcweir         {
987cdf0e10cSrcweir             _ret = loadAndSaveValue(pRootKey, pKey, keyName,
988cdf0e10cSrcweir                                     pKey->getName().getLength(),
989cdf0e10cSrcweir                                     bWarnings, bReport);
990cdf0e10cSrcweir         }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir         if (_ret != REG_NO_ERROR)
993cdf0e10cSrcweir 			break;
994cdf0e10cSrcweir 
995cdf0e10cSrcweir         _err = rStoreDir.next(iter);
996cdf0e10cSrcweir     }
997cdf0e10cSrcweir 
998cdf0e10cSrcweir     (void) pReg->releaseKey(pRootKey);
999cdf0e10cSrcweir     return _ret;
1000cdf0e10cSrcweir }
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir //*********************************************************************
1004cdf0e10cSrcweir //  loadAndSaveValue()
1005cdf0e10cSrcweir //
loadAndSaveValue(ORegKey * pTargetKey,ORegKey * pSourceKey,const OUString & valueName,sal_uInt32 nCut,sal_Bool bWarnings,sal_Bool bReport)1006cdf0e10cSrcweir RegError ORegistry::loadAndSaveValue(ORegKey* pTargetKey,
1007cdf0e10cSrcweir                                      ORegKey* pSourceKey,
1008cdf0e10cSrcweir                                      const OUString& valueName,
1009cdf0e10cSrcweir                                      sal_uInt32 nCut,
1010cdf0e10cSrcweir                                      sal_Bool bWarnings,
1011cdf0e10cSrcweir                                      sal_Bool bReport)
1012cdf0e10cSrcweir {
1013cdf0e10cSrcweir     OStoreStream    rValue;
1014cdf0e10cSrcweir     sal_uInt8*      pBuffer;
1015cdf0e10cSrcweir     RegValueType    valueType;
1016cdf0e10cSrcweir     sal_uInt32      valueSize;
1017cdf0e10cSrcweir     sal_uInt32      nSize;
1018cdf0e10cSrcweir     storeAccessMode sourceAccess = VALUE_MODE_OPEN;
1019cdf0e10cSrcweir     OUString        sTargetPath(pTargetKey->getName());
1020cdf0e10cSrcweir     OUString        sSourcePath(pSourceKey->getName());
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir     if (pSourceKey->isReadOnly())
1023cdf0e10cSrcweir     {
1024cdf0e10cSrcweir         sourceAccess = VALUE_MODE_OPENREAD;
1025cdf0e10cSrcweir     }
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir     if (nCut)
1028cdf0e10cSrcweir     {
1029cdf0e10cSrcweir         sTargetPath = sSourcePath.copy(nCut);
1030cdf0e10cSrcweir     } else
1031cdf0e10cSrcweir     {
1032cdf0e10cSrcweir         if (sTargetPath.getLength() > 1)
1033cdf0e10cSrcweir         {
1034cdf0e10cSrcweir             if (sSourcePath.getLength() > 1)
1035cdf0e10cSrcweir                 sTargetPath += sSourcePath;
1036cdf0e10cSrcweir         } else
1037cdf0e10cSrcweir             sTargetPath = sSourcePath;
1038cdf0e10cSrcweir     }
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir     if (sTargetPath.getLength() > 1) sTargetPath += ROOT;
1041cdf0e10cSrcweir     if (sSourcePath.getLength() > 1) sSourcePath += ROOT;
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir     if (rValue.create(pSourceKey->getStoreFile(), sSourcePath, valueName, sourceAccess))
1044cdf0e10cSrcweir     {
1045cdf0e10cSrcweir         return REG_VALUE_NOT_EXISTS;
1046cdf0e10cSrcweir     }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir     sal_uInt32  rwBytes;
1051cdf0e10cSrcweir     if (rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes))
1052cdf0e10cSrcweir     {
1053cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1054cdf0e10cSrcweir         return REG_INVALID_VALUE;
1055cdf0e10cSrcweir     }
1056cdf0e10cSrcweir     if (rwBytes != VALUE_HEADERSIZE)
1057cdf0e10cSrcweir     {
1058cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1059cdf0e10cSrcweir         return REG_INVALID_VALUE;
1060cdf0e10cSrcweir     }
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir     RegError _ret = REG_NO_ERROR;
1063cdf0e10cSrcweir     sal_uInt8   type = *((sal_uInt8*)pBuffer);
1064cdf0e10cSrcweir     valueType = (RegValueType)type;
1065cdf0e10cSrcweir     readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
1066cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir     nSize = VALUE_HEADERSIZE + valueSize;
1069cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(nSize);
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir     if (rValue.readAt(0, pBuffer, nSize, rwBytes))
1072cdf0e10cSrcweir     {
1073cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1074cdf0e10cSrcweir         return REG_INVALID_VALUE;
1075cdf0e10cSrcweir     }
1076cdf0e10cSrcweir     if (rwBytes != nSize)
1077cdf0e10cSrcweir     {
1078cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1079cdf0e10cSrcweir         return REG_INVALID_VALUE;
1080cdf0e10cSrcweir     }
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir     OStoreFile  rTargetFile(pTargetKey->getStoreFile());
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir     if (!rValue.create(rTargetFile, sTargetPath, valueName, VALUE_MODE_OPEN))
1085cdf0e10cSrcweir     {
1086cdf0e10cSrcweir         if (valueType == RG_VALUETYPE_BINARY)
1087cdf0e10cSrcweir         {
1088cdf0e10cSrcweir             _ret = checkBlop(
1089cdf0e10cSrcweir                 rValue, sTargetPath, valueSize, pBuffer+VALUE_HEADEROFFSET,
1090cdf0e10cSrcweir                 bReport);
1091cdf0e10cSrcweir             if (_ret)
1092cdf0e10cSrcweir             {
1093cdf0e10cSrcweir                 if (_ret == REG_MERGE_ERROR ||
1094cdf0e10cSrcweir                     (_ret == REG_MERGE_CONFLICT && bWarnings))
1095cdf0e10cSrcweir                 {
1096cdf0e10cSrcweir                     rtl_freeMemory(pBuffer);
1097cdf0e10cSrcweir                     return _ret;
1098cdf0e10cSrcweir                 }
1099cdf0e10cSrcweir             } else
1100cdf0e10cSrcweir             {
1101cdf0e10cSrcweir                 rtl_freeMemory(pBuffer);
1102cdf0e10cSrcweir                 return _ret;
1103cdf0e10cSrcweir             }
1104cdf0e10cSrcweir         }
1105cdf0e10cSrcweir     }
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir     // write
1108cdf0e10cSrcweir     if (rValue.create(rTargetFile, sTargetPath, valueName, VALUE_MODE_CREATE))
1109cdf0e10cSrcweir     {
1110cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1111cdf0e10cSrcweir         return REG_INVALID_VALUE;
1112cdf0e10cSrcweir     }
1113cdf0e10cSrcweir     if (rValue.writeAt(0, pBuffer, nSize, rwBytes))
1114cdf0e10cSrcweir     {
1115cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1116cdf0e10cSrcweir         return REG_INVALID_VALUE;
1117cdf0e10cSrcweir     }
1118cdf0e10cSrcweir 
1119cdf0e10cSrcweir     if (rwBytes != nSize)
1120cdf0e10cSrcweir     {
1121cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1122cdf0e10cSrcweir         return REG_INVALID_VALUE;
1123cdf0e10cSrcweir     }
1124cdf0e10cSrcweir 	pTargetKey->setModified();
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
1127cdf0e10cSrcweir     return _ret;
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir //*********************************************************************
1132cdf0e10cSrcweir //  checkblop()
1133cdf0e10cSrcweir //
checkBlop(OStoreStream & rValue,const OUString & sTargetPath,sal_uInt32 srcValueSize,sal_uInt8 * pSrcBuffer,sal_Bool bReport)1134cdf0e10cSrcweir RegError ORegistry::checkBlop(OStoreStream& rValue,
1135cdf0e10cSrcweir                               const OUString& sTargetPath,
1136cdf0e10cSrcweir                               sal_uInt32 srcValueSize,
1137cdf0e10cSrcweir                               sal_uInt8* pSrcBuffer,
1138cdf0e10cSrcweir                               sal_Bool bReport)
1139cdf0e10cSrcweir {
1140cdf0e10cSrcweir     RegistryTypeReader reader(pSrcBuffer, srcValueSize, sal_False);
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir     if (reader.getTypeClass() == RT_TYPE_INVALID)
1143cdf0e10cSrcweir     {
1144cdf0e10cSrcweir         return REG_INVALID_VALUE;
1145cdf0e10cSrcweir     }
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir     sal_uInt8*      pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
1148cdf0e10cSrcweir     RegValueType    valueType;
1149cdf0e10cSrcweir     sal_uInt32      valueSize;
1150cdf0e10cSrcweir     sal_uInt32      rwBytes;
1151cdf0e10cSrcweir 	OString 		targetPath( OUStringToOString(sTargetPath, RTL_TEXTENCODING_UTF8) );
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir     if (!rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes) &&
1154cdf0e10cSrcweir         (rwBytes == VALUE_HEADERSIZE))
1155cdf0e10cSrcweir     {
1156cdf0e10cSrcweir         sal_uInt8 type = *((sal_uInt8*)pBuffer);
1157cdf0e10cSrcweir         valueType = (RegValueType)type;
1158cdf0e10cSrcweir         readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
1159cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir         if (valueType == RG_VALUETYPE_BINARY)
1162cdf0e10cSrcweir         {
1163cdf0e10cSrcweir             pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
1164cdf0e10cSrcweir             if (!rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, rwBytes) &&
1165cdf0e10cSrcweir                 (rwBytes == valueSize))
1166cdf0e10cSrcweir             {
1167cdf0e10cSrcweir                 RegistryTypeReader reader2(pBuffer, valueSize, sal_False);
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir                 if ((reader.getTypeClass() != reader2.getTypeClass())
1170cdf0e10cSrcweir                     || reader2.getTypeClass() == RT_TYPE_INVALID)
1171cdf0e10cSrcweir                 {
1172cdf0e10cSrcweir                     rtl_freeMemory(pBuffer);
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir                     if (bReport)
1175cdf0e10cSrcweir                     {
1176cdf0e10cSrcweir                         fprintf(stdout, "ERROR: values of blop from key \"%s\" has different types.\n",
1177cdf0e10cSrcweir                                 targetPath.getStr());
1178cdf0e10cSrcweir                     }
1179cdf0e10cSrcweir                     return REG_MERGE_ERROR;
1180cdf0e10cSrcweir                 }
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir                 if (reader.getTypeClass() == RT_TYPE_MODULE)
1183cdf0e10cSrcweir                 {
1184cdf0e10cSrcweir                     if (reader.getFieldCount() > 0 &&
1185cdf0e10cSrcweir                         reader2.getFieldCount() > 0)
1186cdf0e10cSrcweir                     {
1187cdf0e10cSrcweir                         mergeModuleValue(rValue, reader, reader2);
1188cdf0e10cSrcweir 
1189cdf0e10cSrcweir                         rtl_freeMemory(pBuffer);
1190cdf0e10cSrcweir                         return REG_NO_ERROR;
1191cdf0e10cSrcweir                     } else
1192cdf0e10cSrcweir                     if (reader2.getFieldCount() > 0)
1193cdf0e10cSrcweir                     {
1194cdf0e10cSrcweir                         rtl_freeMemory(pBuffer);
1195cdf0e10cSrcweir                         return REG_NO_ERROR;
1196cdf0e10cSrcweir                     } else
1197cdf0e10cSrcweir                     {
1198cdf0e10cSrcweir                         rtl_freeMemory(pBuffer);
1199cdf0e10cSrcweir                         return REG_MERGE_CONFLICT;
1200cdf0e10cSrcweir                     }
1201cdf0e10cSrcweir                 } else
1202cdf0e10cSrcweir                 {
1203cdf0e10cSrcweir                     rtl_freeMemory(pBuffer);
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir                     if (bReport)
1206cdf0e10cSrcweir                     {
1207cdf0e10cSrcweir                         fprintf(stdout, "WARNING: value of key \"%s\" already exists.\n",
1208cdf0e10cSrcweir                                 targetPath.getStr());
1209cdf0e10cSrcweir                     }
1210cdf0e10cSrcweir                     return REG_MERGE_CONFLICT;
1211cdf0e10cSrcweir                 }
1212cdf0e10cSrcweir             } else
1213cdf0e10cSrcweir             {
1214cdf0e10cSrcweir                 rtl_freeMemory(pBuffer);
1215cdf0e10cSrcweir                 if (bReport)
1216cdf0e10cSrcweir                 {
1217cdf0e10cSrcweir                     fprintf(stdout, "ERROR: values of key \"%s\" contains bad data.\n",
1218cdf0e10cSrcweir                             targetPath.getStr());
1219cdf0e10cSrcweir                 }
1220cdf0e10cSrcweir                 return REG_MERGE_ERROR;
1221cdf0e10cSrcweir             }
1222cdf0e10cSrcweir         } else
1223cdf0e10cSrcweir         {
1224cdf0e10cSrcweir             rtl_freeMemory(pBuffer);
1225cdf0e10cSrcweir             if (bReport)
1226cdf0e10cSrcweir             {
1227cdf0e10cSrcweir                 fprintf(stdout, "ERROR: values of key \"%s\" has different types.\n",
1228cdf0e10cSrcweir                         targetPath.getStr());
1229cdf0e10cSrcweir             }
1230cdf0e10cSrcweir             return REG_MERGE_ERROR;
1231cdf0e10cSrcweir         }
1232cdf0e10cSrcweir     } else
1233cdf0e10cSrcweir     {
1234cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1235cdf0e10cSrcweir         return REG_INVALID_VALUE;
1236cdf0e10cSrcweir     }
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir 
checkTypeReaders(RegistryTypeReader & reader1,RegistryTypeReader & reader2,std::set<OUString> & nameSet)1239cdf0e10cSrcweir static sal_uInt32 checkTypeReaders(RegistryTypeReader& reader1,
1240cdf0e10cSrcweir                                    RegistryTypeReader& reader2,
1241cdf0e10cSrcweir                                    std::set< OUString >& nameSet)
1242cdf0e10cSrcweir {
1243cdf0e10cSrcweir     sal_uInt32 count=0;
1244cdf0e10cSrcweir     sal_uInt16 i;
1245cdf0e10cSrcweir     for (i=0 ; i < reader1.getFieldCount(); i++)
1246cdf0e10cSrcweir     {
1247cdf0e10cSrcweir         nameSet.insert(reader1.getFieldName(i));
1248cdf0e10cSrcweir         count++;
1249cdf0e10cSrcweir     }
1250cdf0e10cSrcweir     for (i=0 ; i < reader2.getFieldCount(); i++)
1251cdf0e10cSrcweir     {
1252cdf0e10cSrcweir         if (nameSet.find(reader2.getFieldName(i)) == nameSet.end())
1253cdf0e10cSrcweir         {
1254cdf0e10cSrcweir             nameSet.insert(reader2.getFieldName(i));
1255cdf0e10cSrcweir             count++;
1256cdf0e10cSrcweir         }
1257cdf0e10cSrcweir     }
1258cdf0e10cSrcweir     return count;
1259cdf0e10cSrcweir }
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir //*********************************************************************
1262cdf0e10cSrcweir //  mergeModuleValue()
1263cdf0e10cSrcweir //
mergeModuleValue(OStoreStream & rTargetValue,RegistryTypeReader & reader,RegistryTypeReader & reader2)1264cdf0e10cSrcweir RegError ORegistry::mergeModuleValue(OStoreStream& rTargetValue,
1265cdf0e10cSrcweir                                      RegistryTypeReader& reader,
1266cdf0e10cSrcweir                                      RegistryTypeReader& reader2)
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir     sal_uInt16                  index = 0;
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir     std::set< OUString > nameSet;
1271cdf0e10cSrcweir     sal_uInt32 count = checkTypeReaders(reader, reader2, nameSet);
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir     if (count != reader.getFieldCount())
1274cdf0e10cSrcweir     {
1275cdf0e10cSrcweir         RegistryTypeWriter writer(reader.getTypeClass(),
1276cdf0e10cSrcweir                                   reader.getTypeName(),
1277cdf0e10cSrcweir                                   reader.getSuperTypeName(),
1278cdf0e10cSrcweir                                   (sal_uInt16)count,
1279cdf0e10cSrcweir                                   0,
1280cdf0e10cSrcweir                                   0);
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir         sal_uInt16 i;
1283cdf0e10cSrcweir         for (i=0 ; i < reader.getFieldCount(); i++)
1284cdf0e10cSrcweir         {
1285cdf0e10cSrcweir             writer.setFieldData(index,
1286cdf0e10cSrcweir                                reader.getFieldName(i),
1287cdf0e10cSrcweir                                reader.getFieldType(i),
1288cdf0e10cSrcweir                                reader.getFieldDoku(i),
1289cdf0e10cSrcweir                                reader.getFieldFileName(i),
1290cdf0e10cSrcweir                                reader.getFieldAccess(i),
1291cdf0e10cSrcweir                                reader.getFieldConstValue(i));
1292cdf0e10cSrcweir             index++;
1293cdf0e10cSrcweir         }
1294cdf0e10cSrcweir         for (i=0 ; i < reader2.getFieldCount(); i++)
1295cdf0e10cSrcweir         {
1296cdf0e10cSrcweir             if (nameSet.find(reader2.getFieldName(i)) == nameSet.end())
1297cdf0e10cSrcweir             {
1298cdf0e10cSrcweir                 writer.setFieldData(index,
1299cdf0e10cSrcweir                                    reader2.getFieldName(i),
1300cdf0e10cSrcweir                                    reader2.getFieldType(i),
1301cdf0e10cSrcweir                                    reader2.getFieldDoku(i),
1302cdf0e10cSrcweir                                    reader2.getFieldFileName(i),
1303cdf0e10cSrcweir                                    reader2.getFieldAccess(i),
1304cdf0e10cSrcweir                                    reader2.getFieldConstValue(i));
1305cdf0e10cSrcweir                 index++;
1306cdf0e10cSrcweir             }
1307cdf0e10cSrcweir         }
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir         const sal_uInt8*    pBlop = writer.getBlop();
1310cdf0e10cSrcweir         sal_uInt32          aBlopSize = writer.getBlopSize();
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir         sal_uInt8   type = (sal_uInt8)RG_VALUETYPE_BINARY;
1313cdf0e10cSrcweir         sal_uInt8*  pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE + aBlopSize);
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir         rtl_copyMemory(pBuffer, &type, 1);
1316cdf0e10cSrcweir         writeUINT32(pBuffer+VALUE_TYPEOFFSET, aBlopSize);
1317cdf0e10cSrcweir         rtl_copyMemory(pBuffer+VALUE_HEADEROFFSET, pBlop, aBlopSize);
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir         sal_uInt32  rwBytes;
1320cdf0e10cSrcweir         if (rTargetValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+aBlopSize, rwBytes))
1321cdf0e10cSrcweir         {
1322cdf0e10cSrcweir             rtl_freeMemory(pBuffer);
1323cdf0e10cSrcweir             return REG_INVALID_VALUE;
1324cdf0e10cSrcweir         }
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir         if (rwBytes != VALUE_HEADERSIZE+aBlopSize)
1327cdf0e10cSrcweir         {
1328cdf0e10cSrcweir             rtl_freeMemory(pBuffer);
1329cdf0e10cSrcweir             return REG_INVALID_VALUE;
1330cdf0e10cSrcweir         }
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1333cdf0e10cSrcweir     }
1334cdf0e10cSrcweir     return REG_NO_ERROR;
1335cdf0e10cSrcweir }
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir //*********************************************************************
1338cdf0e10cSrcweir //  loadAndSaveKeys()
1339cdf0e10cSrcweir //
loadAndSaveKeys(ORegKey * pTargetKey,ORegKey * pSourceKey,const OUString & keyName,sal_uInt32 nCut,sal_Bool bWarnings,sal_Bool bReport)1340cdf0e10cSrcweir RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey,
1341cdf0e10cSrcweir                                     ORegKey* pSourceKey,
1342cdf0e10cSrcweir                                     const OUString& keyName,
1343cdf0e10cSrcweir                                     sal_uInt32 nCut,
1344cdf0e10cSrcweir                                     sal_Bool bWarnings,
1345cdf0e10cSrcweir                                     sal_Bool bReport)
1346cdf0e10cSrcweir {
1347cdf0e10cSrcweir     RegError    _ret = REG_NO_ERROR;
1348cdf0e10cSrcweir     OUString    sRelPath(pSourceKey->getName().copy(nCut));
1349cdf0e10cSrcweir     OUString    sFullPath;
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir     if(pTargetKey->getName().getLength() > 1)
1352cdf0e10cSrcweir         sFullPath += pTargetKey->getName();
1353cdf0e10cSrcweir     sFullPath += sRelPath;
1354cdf0e10cSrcweir     if (sRelPath.getLength() > 1 || sFullPath.getLength() == 0)
1355cdf0e10cSrcweir         sFullPath += ROOT;
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir     OUString sFullKeyName = sFullPath;
1358cdf0e10cSrcweir     sFullKeyName += keyName;
1359cdf0e10cSrcweir 
1360cdf0e10cSrcweir     OStoreDirectory rStoreDir;
1361cdf0e10cSrcweir     if (rStoreDir.create(pTargetKey->getStoreFile(), sFullPath, keyName, KEY_MODE_CREATE))
1362cdf0e10cSrcweir     {
1363cdf0e10cSrcweir         return REG_CREATE_KEY_FAILED;
1364cdf0e10cSrcweir     }
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir     if (m_openKeyTable.count(sFullKeyName) > 0)
1367cdf0e10cSrcweir     {
1368cdf0e10cSrcweir         m_openKeyTable[sFullKeyName]->setDeleted(sal_False);
1369cdf0e10cSrcweir     }
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir     ORegKey* pTmpKey = 0;
1372cdf0e10cSrcweir     _ret = pSourceKey->openKey(keyName, (RegKeyHandle*)&pTmpKey);
1373cdf0e10cSrcweir     if (_ret != REG_NO_ERROR)
1374cdf0e10cSrcweir         return _ret;
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
1377cdf0e10cSrcweir     OStoreDirectory             rTmpStoreDir(pTmpKey->getStoreDir());
1378cdf0e10cSrcweir     storeError                  _err = rTmpStoreDir.first(iter);
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir     while ( _err == store_E_None)
1381cdf0e10cSrcweir     {
1382cdf0e10cSrcweir 		OUString const sName = iter.m_pszName;
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir         if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
1385cdf0e10cSrcweir         {
1386cdf0e10cSrcweir             _ret = loadAndSaveKeys(pTargetKey, pTmpKey,
1387cdf0e10cSrcweir                                    sName, nCut, bWarnings, bReport);
1388cdf0e10cSrcweir         } else
1389cdf0e10cSrcweir         {
1390cdf0e10cSrcweir             _ret = loadAndSaveValue(pTargetKey, pTmpKey,
1391cdf0e10cSrcweir                                     sName, nCut, bWarnings, bReport);
1392cdf0e10cSrcweir         }
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir         if (_ret == REG_MERGE_ERROR)
1395cdf0e10cSrcweir 			break;
1396cdf0e10cSrcweir 		if (_ret == REG_MERGE_CONFLICT && bWarnings)
1397cdf0e10cSrcweir 			break;
1398cdf0e10cSrcweir 
1399cdf0e10cSrcweir         _err = rTmpStoreDir.next(iter);
1400cdf0e10cSrcweir     }
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir     pSourceKey->releaseKey(pTmpKey);
1403cdf0e10cSrcweir     return _ret;
1404cdf0e10cSrcweir }
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir //*********************************************************************
1408cdf0e10cSrcweir //  getRootKey()
1409cdf0e10cSrcweir //
getRootKey()1410cdf0e10cSrcweir ORegKey* ORegistry::getRootKey()
1411cdf0e10cSrcweir {
1412cdf0e10cSrcweir     m_openKeyTable[ROOT]->acquire();
1413cdf0e10cSrcweir     return m_openKeyTable[ROOT];
1414cdf0e10cSrcweir }
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir //*********************************************************************
1418cdf0e10cSrcweir //  dumpRegistry()
1419cdf0e10cSrcweir //
dumpRegistry(RegKeyHandle hKey) const1420cdf0e10cSrcweir RegError ORegistry::dumpRegistry(RegKeyHandle hKey) const
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir     ORegKey                     *pKey = (ORegKey*)hKey;
1423cdf0e10cSrcweir     OUString                    sName;
1424cdf0e10cSrcweir     RegError                    _ret = REG_NO_ERROR;
1425cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
1426cdf0e10cSrcweir     OStoreDirectory             rStoreDir(pKey->getStoreDir());
1427cdf0e10cSrcweir     storeError                  _err = rStoreDir.first(iter);
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 	OString regName( OUStringToOString( getName(), osl_getThreadTextEncoding() ) );
1430cdf0e10cSrcweir 	OString keyName( OUStringToOString( pKey->getName(), RTL_TEXTENCODING_UTF8 ) );
1431cdf0e10cSrcweir     fprintf(stdout, "Registry \"%s\":\n\n%s\n", regName.getStr(), keyName.getStr());
1432cdf0e10cSrcweir 
1433cdf0e10cSrcweir     while ( _err == store_E_None )
1434cdf0e10cSrcweir     {
1435cdf0e10cSrcweir         sName = iter.m_pszName;
1436cdf0e10cSrcweir 
1437cdf0e10cSrcweir         if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
1438cdf0e10cSrcweir         {
1439cdf0e10cSrcweir             _ret = dumpKey(pKey->getName(), sName, 1);
1440cdf0e10cSrcweir         } else
1441cdf0e10cSrcweir         {
1442cdf0e10cSrcweir             _ret = dumpValue(pKey->getName(), sName, 1);
1443cdf0e10cSrcweir         }
1444cdf0e10cSrcweir 
1445cdf0e10cSrcweir         if (_ret)
1446cdf0e10cSrcweir         {
1447cdf0e10cSrcweir             return _ret;
1448cdf0e10cSrcweir         }
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir         _err = rStoreDir.next(iter);
1451cdf0e10cSrcweir     }
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir     return REG_NO_ERROR;
1454cdf0e10cSrcweir }
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir //*********************************************************************
1457cdf0e10cSrcweir //  dumpValue()
1458cdf0e10cSrcweir //
dumpValue(const OUString & sPath,const OUString & sName,sal_Int16 nSpc) const1459cdf0e10cSrcweir RegError ORegistry::dumpValue(const OUString& sPath, const OUString& sName, sal_Int16 nSpc) const
1460cdf0e10cSrcweir {
1461cdf0e10cSrcweir     OStoreStream    rValue;
1462cdf0e10cSrcweir     sal_uInt8*      pBuffer;
1463cdf0e10cSrcweir     sal_uInt32      valueSize;
1464cdf0e10cSrcweir     RegValueType    valueType;
1465cdf0e10cSrcweir     OUString        sFullPath(sPath);
1466cdf0e10cSrcweir     OString         sIndent;
1467cdf0e10cSrcweir     storeAccessMode accessMode = VALUE_MODE_OPEN;
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir     if (isReadOnly())
1470cdf0e10cSrcweir     {
1471cdf0e10cSrcweir         accessMode = VALUE_MODE_OPENREAD;
1472cdf0e10cSrcweir     }
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir     for (int i= 0; i < nSpc; i++) sIndent += " ";
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir     if (sFullPath.getLength() > 1)
1477cdf0e10cSrcweir 	{
1478cdf0e10cSrcweir         sFullPath += ROOT;
1479cdf0e10cSrcweir 	}
1480cdf0e10cSrcweir     if (rValue.create(m_file, sFullPath, sName, accessMode))
1481cdf0e10cSrcweir     {
1482cdf0e10cSrcweir         return REG_VALUE_NOT_EXISTS;
1483cdf0e10cSrcweir     }
1484cdf0e10cSrcweir 
1485cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(VALUE_HEADERSIZE);
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir     sal_uInt32  rwBytes;
1488cdf0e10cSrcweir     if (rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes))
1489cdf0e10cSrcweir     {
1490cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1491cdf0e10cSrcweir         return REG_INVALID_VALUE;
1492cdf0e10cSrcweir     }
1493cdf0e10cSrcweir     if (rwBytes != (VALUE_HEADERSIZE))
1494cdf0e10cSrcweir     {
1495cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1496cdf0e10cSrcweir         return REG_INVALID_VALUE;
1497cdf0e10cSrcweir     }
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir     sal_uInt8 type = *((sal_uInt8*)pBuffer);
1500cdf0e10cSrcweir     valueType = (RegValueType)type;
1501cdf0e10cSrcweir     readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
1502cdf0e10cSrcweir 
1503cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
1504cdf0e10cSrcweir     if (rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, rwBytes))
1505cdf0e10cSrcweir     {
1506cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1507cdf0e10cSrcweir         return REG_INVALID_VALUE;
1508cdf0e10cSrcweir     }
1509cdf0e10cSrcweir     if (rwBytes != valueSize)
1510cdf0e10cSrcweir     {
1511cdf0e10cSrcweir         rtl_freeMemory(pBuffer);
1512cdf0e10cSrcweir         return REG_INVALID_VALUE;
1513cdf0e10cSrcweir     }
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir     const sal_Char* indent = sIndent.getStr();
1516cdf0e10cSrcweir     switch (valueType)
1517cdf0e10cSrcweir     {
1518cdf0e10cSrcweir         case 0:
1519cdf0e10cSrcweir             fprintf(stdout, "%sValue: Type = VALUETYPE_NOT_DEFINED\n", indent);
1520cdf0e10cSrcweir             break;
1521cdf0e10cSrcweir         case 1:
1522cdf0e10cSrcweir             {
1523cdf0e10cSrcweir                 fprintf(stdout, "%sValue: Type = RG_VALUETYPE_LONG\n", indent);
1524cdf0e10cSrcweir                 fprintf(
1525cdf0e10cSrcweir                     stdout, "%s       Size = %lu\n", indent,
1526cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(valueSize));
1527cdf0e10cSrcweir                 fprintf(stdout, "%s       Data = ", indent);
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir                 sal_Int32 value;
1530cdf0e10cSrcweir                 readINT32(pBuffer, value);
1531cdf0e10cSrcweir                 fprintf(stdout, "%ld\n", sal::static_int_cast< long >(value));
1532cdf0e10cSrcweir             }
1533cdf0e10cSrcweir             break;
1534cdf0e10cSrcweir         case 2:
1535cdf0e10cSrcweir             {
1536cdf0e10cSrcweir                 sal_Char* value = (sal_Char*)rtl_allocateMemory(valueSize);
1537cdf0e10cSrcweir                 readUtf8(pBuffer, value, valueSize);
1538cdf0e10cSrcweir                 fprintf(stdout, "%sValue: Type = RG_VALUETYPE_STRING\n", indent);
1539cdf0e10cSrcweir                 fprintf(
1540cdf0e10cSrcweir                     stdout, "%s       Size = %lu\n", indent,
1541cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(valueSize));
1542cdf0e10cSrcweir                 fprintf(stdout, "%s       Data = \"%s\"\n", indent, value);
1543cdf0e10cSrcweir                 rtl_freeMemory(value);
1544cdf0e10cSrcweir             }
1545cdf0e10cSrcweir             break;
1546cdf0e10cSrcweir         case 3:
1547cdf0e10cSrcweir             {
1548cdf0e10cSrcweir                 sal_uInt32 size = (valueSize / 2) * sizeof(sal_Unicode);
1549cdf0e10cSrcweir                 fprintf(stdout, "%sValue: Type = RG_VALUETYPE_UNICODE\n", indent);
1550cdf0e10cSrcweir                 fprintf(
1551cdf0e10cSrcweir                     stdout, "%s       Size = %lu\n", indent,
1552cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(valueSize));
1553cdf0e10cSrcweir                 fprintf(stdout, "%s       Data = ", indent);
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir                 sal_Unicode* value = new sal_Unicode[size];
1556cdf0e10cSrcweir                 readString(pBuffer, value, size);
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir                 OString uStr = OUStringToOString(value, RTL_TEXTENCODING_UTF8);
1559cdf0e10cSrcweir                 fprintf(stdout, "L\"%s\"\n", uStr.getStr());
1560cdf0e10cSrcweir                 delete[] value;
1561cdf0e10cSrcweir             }
1562cdf0e10cSrcweir             break;
1563cdf0e10cSrcweir         case 4:
1564cdf0e10cSrcweir             {
1565cdf0e10cSrcweir                 fprintf(stdout, "%sValue: Type = RG_VALUETYPE_BINARY\n", indent);
1566cdf0e10cSrcweir                 fprintf(
1567cdf0e10cSrcweir                     stdout, "%s       Size = %lu\n", indent,
1568cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(valueSize));
1569cdf0e10cSrcweir                 fprintf(stdout, "%s       Data = ", indent);
1570cdf0e10cSrcweir                 dumpType(
1571cdf0e10cSrcweir                     typereg::Reader(
1572cdf0e10cSrcweir                         pBuffer, valueSize, false, TYPEREG_VERSION_1),
1573cdf0e10cSrcweir                     sIndent + "              ");
1574cdf0e10cSrcweir             }
1575cdf0e10cSrcweir             break;
1576cdf0e10cSrcweir         case 5:
1577cdf0e10cSrcweir             {
1578cdf0e10cSrcweir                 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays
1579cdf0e10cSrcweir                 sal_uInt32 len = 0;
1580cdf0e10cSrcweir 
1581cdf0e10cSrcweir                 readUINT32(pBuffer, len);
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir                 fprintf(stdout, "%sValue: Type = RG_VALUETYPE_LONGLIST\n", indent);
1584cdf0e10cSrcweir                 fprintf(
1585cdf0e10cSrcweir                     stdout, "%s       Size = %lu\n", indent,
1586cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(valueSize));
1587cdf0e10cSrcweir                 fprintf(
1588cdf0e10cSrcweir                     stdout, "%s       Len  = %lu\n", indent,
1589cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(len));
1590cdf0e10cSrcweir                 fprintf(stdout, "%s       Data = ", indent);
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir                 sal_Int32 longValue;
1593cdf0e10cSrcweir                 for (sal_uInt32 i=0; i < len; i++)
1594cdf0e10cSrcweir                 {
1595cdf0e10cSrcweir                     readINT32(pBuffer+offset, longValue);
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir                     if (offset > 4)
1598cdf0e10cSrcweir                         fprintf(stdout, "%s              ", indent);
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir                     fprintf(
1601cdf0e10cSrcweir                         stdout, "%lu = %ld\n",
1602cdf0e10cSrcweir                         sal::static_int_cast< unsigned long >(i),
1603cdf0e10cSrcweir                         sal::static_int_cast< long >(longValue));
1604cdf0e10cSrcweir                     offset += 4; // 4 Bytes fuer sal_Int32
1605cdf0e10cSrcweir                 }
1606cdf0e10cSrcweir             }
1607cdf0e10cSrcweir             break;
1608cdf0e10cSrcweir         case 6:
1609cdf0e10cSrcweir             {
1610cdf0e10cSrcweir                 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays
1611cdf0e10cSrcweir                 sal_uInt32 sLen = 0;
1612cdf0e10cSrcweir                 sal_uInt32 len = 0;
1613cdf0e10cSrcweir 
1614cdf0e10cSrcweir                 readUINT32(pBuffer, len);
1615cdf0e10cSrcweir 
1616cdf0e10cSrcweir                 fprintf(stdout, "%sValue: Type = RG_VALUETYPE_STRINGLIST\n", indent);
1617cdf0e10cSrcweir                 fprintf(
1618cdf0e10cSrcweir                     stdout, "%s       Size = %lu\n", indent,
1619cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(valueSize));
1620cdf0e10cSrcweir                 fprintf(
1621cdf0e10cSrcweir                     stdout, "%s       Len  = %lu\n", indent,
1622cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(len));
1623cdf0e10cSrcweir                 fprintf(stdout, "%s       Data = ", indent);
1624cdf0e10cSrcweir 
1625cdf0e10cSrcweir                 sal_Char *pValue;
1626cdf0e10cSrcweir                 for (sal_uInt32 i=0; i < len; i++)
1627cdf0e10cSrcweir                 {
1628cdf0e10cSrcweir                     readUINT32(pBuffer+offset, sLen);
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir                     offset += 4; // 4 Bytes (sal_uInt32) fuer die Groesse des strings in Bytes
1631cdf0e10cSrcweir 
1632cdf0e10cSrcweir                     pValue = (sal_Char*)rtl_allocateMemory(sLen);
1633cdf0e10cSrcweir                     readUtf8(pBuffer+offset, pValue, sLen);
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir                     if (offset > 8)
1636cdf0e10cSrcweir                         fprintf(stdout, "%s              ", indent);
1637cdf0e10cSrcweir 
1638cdf0e10cSrcweir                     fprintf(
1639cdf0e10cSrcweir                         stdout, "%lu = \"%s\"\n",
1640cdf0e10cSrcweir                         sal::static_int_cast< unsigned long >(i), pValue);
1641cdf0e10cSrcweir                     offset += sLen;
1642cdf0e10cSrcweir                 }
1643cdf0e10cSrcweir             }
1644cdf0e10cSrcweir             break;
1645cdf0e10cSrcweir         case 7:
1646cdf0e10cSrcweir             {
1647cdf0e10cSrcweir                 sal_uInt32 offset = 4; // initial 4 Bytes fuer die Laenge des Arrays
1648cdf0e10cSrcweir                 sal_uInt32 sLen = 0;
1649cdf0e10cSrcweir                 sal_uInt32 len = 0;
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir                 readUINT32(pBuffer, len);
1652cdf0e10cSrcweir 
1653cdf0e10cSrcweir                 fprintf(stdout, "%sValue: Type = RG_VALUETYPE_UNICODELIST\n", indent);
1654cdf0e10cSrcweir                 fprintf(
1655cdf0e10cSrcweir                     stdout, "%s       Size = %lu\n", indent,
1656cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(valueSize));
1657cdf0e10cSrcweir                 fprintf(
1658cdf0e10cSrcweir                     stdout, "%s       Len  = %lu\n", indent,
1659cdf0e10cSrcweir                     sal::static_int_cast< unsigned long >(len));
1660cdf0e10cSrcweir                 fprintf(stdout, "%s       Data = ", indent);
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir                 sal_Unicode *pValue;
1663cdf0e10cSrcweir                 OString uStr;
1664cdf0e10cSrcweir                 for (sal_uInt32 i=0; i < len; i++)
1665cdf0e10cSrcweir                 {
1666cdf0e10cSrcweir                     readUINT32(pBuffer+offset, sLen);
1667cdf0e10cSrcweir 
1668cdf0e10cSrcweir                     offset += 4; // 4 Bytes (sal_uInt32) fuer die Groesse des strings in Bytes
1669cdf0e10cSrcweir 
1670cdf0e10cSrcweir                     pValue = (sal_Unicode*)rtl_allocateMemory((sLen / 2) * sizeof(sal_Unicode));
1671cdf0e10cSrcweir                     readString(pBuffer+offset, pValue, sLen);
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir                     if (offset > 8)
1674cdf0e10cSrcweir                         fprintf(stdout, "%s              ", indent);
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir                     uStr = OUStringToOString(pValue, RTL_TEXTENCODING_UTF8);
1677cdf0e10cSrcweir                     fprintf(
1678cdf0e10cSrcweir                         stdout, "%lu = L\"%s\"\n",
1679cdf0e10cSrcweir                         sal::static_int_cast< unsigned long >(i),
1680cdf0e10cSrcweir                         uStr.getStr());
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir                     offset += sLen;
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir                     rtl_freeMemory(pValue);
1685cdf0e10cSrcweir                 }
1686cdf0e10cSrcweir             }
1687cdf0e10cSrcweir             break;
1688cdf0e10cSrcweir     }
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir     fprintf(stdout, "\n");
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir     rtl_freeMemory(pBuffer);
1693cdf0e10cSrcweir     return REG_NO_ERROR;
1694cdf0e10cSrcweir }
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir //*********************************************************************
1697cdf0e10cSrcweir //  dumpKey()
1698cdf0e10cSrcweir //
dumpKey(const OUString & sPath,const OUString & sName,sal_Int16 nSpace) const1699cdf0e10cSrcweir RegError ORegistry::dumpKey(const OUString& sPath, const OUString& sName, sal_Int16 nSpace) const
1700cdf0e10cSrcweir {
1701cdf0e10cSrcweir     OStoreDirectory 	rStoreDir;
1702cdf0e10cSrcweir     OUString          	sFullPath(sPath);
1703cdf0e10cSrcweir     OString             sIndent;
1704cdf0e10cSrcweir     storeAccessMode     accessMode = KEY_MODE_OPEN;
1705cdf0e10cSrcweir     RegError            _ret = REG_NO_ERROR;
1706cdf0e10cSrcweir 
1707cdf0e10cSrcweir     if (isReadOnly())
1708cdf0e10cSrcweir     {
1709cdf0e10cSrcweir         accessMode = KEY_MODE_OPENREAD;
1710cdf0e10cSrcweir     }
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir     for (int i= 0; i < nSpace; i++) sIndent += " ";
1713cdf0e10cSrcweir 
1714cdf0e10cSrcweir     if (sFullPath.getLength() > 1)
1715cdf0e10cSrcweir         sFullPath += ROOT;
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir     storeError _err = rStoreDir.create(m_file, sFullPath, sName, accessMode);
1718cdf0e10cSrcweir 
1719cdf0e10cSrcweir     if (_err == store_E_NotExists)
1720cdf0e10cSrcweir         return REG_KEY_NOT_EXISTS;
1721cdf0e10cSrcweir     else
1722cdf0e10cSrcweir     if (_err == store_E_WrongFormat)
1723cdf0e10cSrcweir         return REG_INVALID_KEY;
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir     fprintf(stdout, "%s/ %s\n", sIndent.getStr(), OUStringToOString(sName, RTL_TEXTENCODING_UTF8).getStr());
1726cdf0e10cSrcweir 
1727cdf0e10cSrcweir     OUString sSubPath(sFullPath);
1728cdf0e10cSrcweir     OUString sSubName;
1729cdf0e10cSrcweir     sSubPath += sName;
1730cdf0e10cSrcweir 
1731cdf0e10cSrcweir     OStoreDirectory::iterator   iter;
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir     _err = rStoreDir.first(iter);
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir     while ( _err == store_E_None)
1736cdf0e10cSrcweir     {
1737cdf0e10cSrcweir         sSubName = iter.m_pszName;
1738cdf0e10cSrcweir 
1739cdf0e10cSrcweir         if ( iter.m_nAttrib & STORE_ATTRIB_ISDIR )
1740cdf0e10cSrcweir         {
1741cdf0e10cSrcweir             _ret = dumpKey(sSubPath, sSubName, nSpace+2);
1742cdf0e10cSrcweir         } else
1743cdf0e10cSrcweir         {
1744cdf0e10cSrcweir             _ret = dumpValue(sSubPath, sSubName, nSpace+2);
1745cdf0e10cSrcweir         }
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir         if (_ret)
1748cdf0e10cSrcweir         {
1749cdf0e10cSrcweir             return _ret;
1750cdf0e10cSrcweir         }
1751cdf0e10cSrcweir 
1752cdf0e10cSrcweir         _err = rStoreDir.next(iter);
1753cdf0e10cSrcweir     }
1754cdf0e10cSrcweir 
1755cdf0e10cSrcweir     return REG_NO_ERROR;
1756cdf0e10cSrcweir }
1757