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

Generated by: LCOV version 1.10