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