LCOV - code coverage report
Current view: top level - desktop/source/deployment/manager - dp_activepackages.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 64 85 75.3 %
Date: 2015-06-13 12:38:46 Functions: 10 12 83.3 %
Legend: Lines: hit not hit

          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             : #include <config_features.h>
      21             : 
      22             : #include <sal/config.h>
      23             : 
      24             : #include <cstddef>
      25             : #include <utility>
      26             : #include <vector>
      27             : 
      28             : #include <osl/diagnose.h>
      29             : #include <rtl/strbuf.hxx>
      30             : #include <rtl/string.hxx>
      31             : #include <rtl/textenc.h>
      32             : #include <rtl/uri.h>
      33             : #include <rtl/uri.hxx>
      34             : #include <rtl/ustring.hxx>
      35             : 
      36             : #include "dp_identifier.hxx"
      37             : #include "dp_activepackages.hxx"
      38             : 
      39             : // Old format of database entry:
      40             : //   key: UTF8(filename)
      41             : //   value: UTF8(tempname ";" mediatype)
      42             : // New format of database entry:
      43             : //   key: 0xFF UTF8(identifier)
      44             : //   value: UTF8(tempname) 0xFF UTF8(filename) 0xFF UTF8(mediatype)
      45             : 
      46             : #if HAVE_FEATURE_EXTENSIONS
      47             : 
      48             : namespace {
      49             : 
      50             : static char const separator = static_cast< char >(
      51             :     static_cast< unsigned char >(0xFF));
      52             : 
      53          14 : OString oldKey(OUString const & fileName) {
      54          14 :     return OUStringToOString(fileName, RTL_TEXTENCODING_UTF8);
      55             : }
      56             : 
      57          27 : OString newKey(OUString const & id) {
      58          27 :     OStringBuffer b;
      59          27 :     b.append(separator);
      60          27 :     b.append(OUStringToOString(id, RTL_TEXTENCODING_UTF8));
      61          27 :     return b.makeStringAndClear();
      62             : }
      63             : 
      64           0 : ::dp_manager::ActivePackages::Data decodeOldData(
      65             :     OUString const & fileName, OString const & value)
      66             : {
      67           0 :     ::dp_manager::ActivePackages::Data d;
      68           0 :     sal_Int32 i = value.indexOf(';');
      69             :     OSL_ASSERT(i >= 0);
      70           0 :     d.temporaryName = OUString(value.getStr(), i, RTL_TEXTENCODING_UTF8);
      71           0 :     d.fileName = fileName;
      72           0 :     d.mediaType = OUString(
      73           0 :         value.getStr() + i + 1, value.getLength() - i - 1,
      74           0 :         RTL_TEXTENCODING_UTF8);
      75           0 :     return d;
      76             : }
      77             : 
      78           7 : ::dp_manager::ActivePackages::Data decodeNewData(OString const & value) {
      79           7 :     ::dp_manager::ActivePackages::Data d;
      80           7 :     sal_Int32 i1 = value.indexOf(separator);
      81             :     OSL_ASSERT(i1 >= 0);
      82          14 :     d.temporaryName = OUString(
      83           7 :         value.getStr(), i1, RTL_TEXTENCODING_UTF8);
      84           7 :     sal_Int32 i2 = value.indexOf(separator, i1 + 1);
      85             :     OSL_ASSERT(i2 >= 0);
      86          21 :     d.fileName = OUString(
      87          21 :         value.getStr() + i1 + 1, i2 - i1 - 1, RTL_TEXTENCODING_UTF8);
      88           7 :     sal_Int32 i3 = value.indexOf(separator, i2 + 1);
      89             : 
      90           7 :     if (i3 < 0)
      91             :     {
      92             :         //Before ActivePackages::Data::version was added
      93           0 :         d.mediaType = OUString(
      94           0 :             value.getStr() + i2 + 1, value.getLength() - i2 - 1,
      95           0 :             RTL_TEXTENCODING_UTF8);
      96             :     }
      97             :     else
      98             :     {
      99           7 :         sal_Int32 i4 = value.indexOf(separator, i3 + 1);
     100          21 :         d.mediaType = OUString(
     101          21 :             value.getStr() + i2 + 1, i3 - i2 -1, RTL_TEXTENCODING_UTF8);
     102          21 :         d.version = OUString(
     103          14 :             value.getStr() + i3 + 1, i4 - i3 - 1,
     104           7 :             RTL_TEXTENCODING_UTF8);
     105          21 :         d.failedPrerequisites = OUString(
     106          14 :             value.getStr() + i4 + 1, value.getLength() - i4 - 1,
     107           7 :             RTL_TEXTENCODING_UTF8);
     108             :     }
     109           7 :     return d;
     110             : }
     111             : 
     112             : }
     113             : #endif
     114             : 
     115             : namespace dp_manager {
     116             : 
     117           0 : ActivePackages::ActivePackages() {}
     118             : 
     119         339 : ActivePackages::ActivePackages(OUString const & url, bool readOnly)
     120             : #if HAVE_FEATURE_EXTENSIONS
     121         339 :     : m_map(url, readOnly)
     122             : #endif
     123             : {
     124             :     (void) url;
     125             :     (void) readOnly;
     126         339 : }
     127             : 
     128         339 : ActivePackages::~ActivePackages() {}
     129             : 
     130           3 : bool ActivePackages::has(
     131             :     OUString const & id, OUString const & fileName) const
     132             : {
     133           3 :     return get(NULL, id, fileName);
     134             : }
     135             : 
     136          21 : bool ActivePackages::get(
     137             :     Data * data, OUString const & id, OUString const & fileName)
     138             :     const
     139             : {
     140             : #if HAVE_FEATURE_EXTENSIONS
     141          21 :     OString v;
     142          21 :     if (m_map.get(&v, newKey(id))) {
     143           7 :         if (data != NULL) {
     144           7 :             *data = decodeNewData(v);
     145             :         }
     146           7 :         return true;
     147          14 :     } else if (m_map.get(&v, oldKey(fileName))) {
     148           0 :         if (data != NULL) {
     149           0 :             *data = decodeOldData(fileName, v);
     150             :         }
     151           0 :         return true;
     152             :     } else {
     153          14 :         return false;
     154          21 :     }
     155             : #else
     156             :     (void) data;
     157             :     (void) id;
     158             :     (void) fileName;
     159             :     return false;
     160             : #endif
     161             : }
     162             : 
     163        5484 : ActivePackages::Entries ActivePackages::getEntries() const {
     164        5484 :     Entries es;
     165             : #if HAVE_FEATURE_EXTENSIONS
     166       10968 :     ::dp_misc::t_string2string_map m(m_map.getEntries());
     167       16452 :     for (::dp_misc::t_string2string_map::const_iterator i(m.begin());
     168       10968 :          i != m.end(); ++i)
     169             :     {
     170           0 :         if (!i->first.isEmpty() && i->first[0] == separator) {
     171             :             es.push_back(
     172             :                 ::std::make_pair(
     173             :                     OUString(
     174           0 :                         i->first.getStr() + 1, i->first.getLength() - 1,
     175             :                         RTL_TEXTENCODING_UTF8),
     176           0 :                     decodeNewData(i->second)));
     177             :         } else {
     178             :             OUString fn(
     179           0 :                 OStringToOUString(i->first, RTL_TEXTENCODING_UTF8));
     180             :             es.push_back(
     181             :                 ::std::make_pair(
     182             :                     ::dp_misc::generateLegacyIdentifier(fn),
     183           0 :                     decodeOldData(fn, i->second)));
     184             :         }
     185             :     }
     186             : #endif
     187       10968 :     return es;
     188             : }
     189             : 
     190           3 : void ActivePackages::put(OUString const & id, Data const & data) {
     191             : #if HAVE_FEATURE_EXTENSIONS
     192           3 :     OStringBuffer b;
     193             :     b.append(
     194           3 :         OUStringToOString(data.temporaryName, RTL_TEXTENCODING_UTF8));
     195           3 :     b.append(separator);
     196           3 :     b.append(OUStringToOString(data.fileName, RTL_TEXTENCODING_UTF8));
     197           3 :     b.append(separator);
     198           3 :     b.append(OUStringToOString(data.mediaType, RTL_TEXTENCODING_UTF8));
     199           3 :     b.append(separator);
     200           3 :     b.append(OUStringToOString(data.version, RTL_TEXTENCODING_UTF8));
     201           3 :     b.append(separator);
     202           3 :     b.append(OUStringToOString(data.failedPrerequisites, RTL_TEXTENCODING_UTF8));
     203           3 :     m_map.put(newKey(id), b.makeStringAndClear());
     204             : #else
     205             :     (void) id;
     206             :     (void) data;
     207             : #endif
     208           3 : }
     209             : 
     210           3 : void ActivePackages::erase(
     211             :     OUString const & id, OUString const & fileName)
     212             : {
     213             : #if HAVE_FEATURE_EXTENSIONS
     214           3 :     m_map.erase(newKey(id), true) || m_map.erase(oldKey(fileName), true);
     215             : #else
     216             :     (void) id;
     217             :     (void) fileName;
     218             : #endif
     219           3 : }
     220             : 
     221             : }
     222             : 
     223             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11