LCOV - code coverage report
Current view: top level - registry/source - regimpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 295 837 35.2 %
Date: 2012-08-25 Functions: 17 28 60.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 222 963 23.1 %

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

Generated by: LCOV version 1.10