LCOV - code coverage report
Current view: top level - desktop/source/deployment/manager - dp_activepackages.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 85 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
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           0 : OString oldKey(OUString const & fileName) {
      55           0 :     return OUStringToOString(fileName, RTL_TEXTENCODING_UTF8);
      56             : }
      57             : 
      58           0 : OString newKey(OUString const & id) {
      59           0 :     OStringBuffer b;
      60           0 :     b.append(separator);
      61           0 :     b.append(OUStringToOString(id, RTL_TEXTENCODING_UTF8));
      62           0 :     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           0 : ::dp_manager::ActivePackages::Data decodeNewData(OString const & value) {
      80           0 :     ::dp_manager::ActivePackages::Data d;
      81           0 :     sal_Int32 i1 = value.indexOf(separator);
      82             :     OSL_ASSERT(i1 >= 0);
      83           0 :     d.temporaryName = OUString(
      84           0 :         value.getStr(), i1, RTL_TEXTENCODING_UTF8);
      85           0 :     sal_Int32 i2 = value.indexOf(separator, i1 + 1);
      86             :     OSL_ASSERT(i2 >= 0);
      87           0 :     d.fileName = OUString(
      88           0 :         value.getStr() + i1 + 1, i2 - i1 - 1, RTL_TEXTENCODING_UTF8);
      89           0 :     sal_Int32 i3 = value.indexOf(separator, i2 + 1);
      90             : 
      91           0 :     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           0 :         sal_Int32 i4 = value.indexOf(separator, i3 + 1);
     101           0 :         d.mediaType = OUString(
     102           0 :             value.getStr() + i2 + 1, i3 - i2 -1, RTL_TEXTENCODING_UTF8);
     103           0 :         d.version = OUString(
     104           0 :             value.getStr() + i3 + 1, i4 - i3 - 1,
     105           0 :             RTL_TEXTENCODING_UTF8);
     106           0 :         d.failedPrerequisites = OUString(
     107           0 :             value.getStr() + i4 + 1, value.getLength() - i4 - 1,
     108           0 :             RTL_TEXTENCODING_UTF8);
     109             :     }
     110           0 :     return d;
     111             : }
     112             : 
     113             : }
     114             : #endif
     115             : 
     116             : namespace dp_manager {
     117             : 
     118           0 : ActivePackages::ActivePackages() {}
     119             : 
     120           0 : ActivePackages::ActivePackages(OUString const & url, bool readOnly)
     121             : #if HAVE_FEATURE_EXTENSIONS
     122           0 :     : m_map(url, readOnly)
     123             : #endif
     124             : {
     125             :     (void) url;
     126             :     (void) readOnly;
     127           0 : }
     128             : 
     129           0 : ActivePackages::~ActivePackages() {}
     130             : 
     131           0 : bool ActivePackages::has(
     132             :     OUString const & id, OUString const & fileName) const
     133             : {
     134           0 :     return get(NULL, id, fileName);
     135             : }
     136             : 
     137           0 : bool ActivePackages::get(
     138             :     Data * data, OUString const & id, OUString const & fileName)
     139             :     const
     140             : {
     141             : #if HAVE_FEATURE_EXTENSIONS
     142           0 :     OString v;
     143           0 :     if (m_map.get(&v, newKey(id))) {
     144           0 :         if (data != NULL) {
     145           0 :             *data = decodeNewData(v);
     146             :         }
     147           0 :         return true;
     148           0 :     } 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           0 :         return false;
     155           0 :     }
     156             : #else
     157             :     (void) data;
     158             :     (void) id;
     159             :     (void) fileName;
     160             :     return false;
     161             : #endif
     162             : }
     163             : 
     164           0 : ActivePackages::Entries ActivePackages::getEntries() const {
     165           0 :     Entries es;
     166             : #if HAVE_FEATURE_EXTENSIONS
     167           0 :     ::dp_misc::t_string2string_map m(m_map.getEntries());
     168           0 :     for (::dp_misc::t_string2string_map::const_iterator i(m.begin());
     169           0 :          i != m.end(); ++i)
     170             :     {
     171           0 :         if (!i->first.isEmpty() && i->first[0] == separator) {
     172             :             es.push_back(
     173             :                 ::std::make_pair(
     174             :                     OUString(
     175           0 :                         i->first.getStr() + 1, i->first.getLength() - 1,
     176             :                         RTL_TEXTENCODING_UTF8),
     177           0 :                     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           0 :     return es;
     189             : }
     190             : 
     191           0 : void ActivePackages::put(OUString const & id, Data const & data) {
     192             : #if HAVE_FEATURE_EXTENSIONS
     193           0 :     OStringBuffer b;
     194             :     b.append(
     195           0 :         OUStringToOString(data.temporaryName, RTL_TEXTENCODING_UTF8));
     196           0 :     b.append(separator);
     197           0 :     b.append(OUStringToOString(data.fileName, RTL_TEXTENCODING_UTF8));
     198           0 :     b.append(separator);
     199           0 :     b.append(OUStringToOString(data.mediaType, RTL_TEXTENCODING_UTF8));
     200           0 :     b.append(separator);
     201           0 :     b.append(OUStringToOString(data.version, RTL_TEXTENCODING_UTF8));
     202           0 :     b.append(separator);
     203           0 :     b.append(OUStringToOString(data.failedPrerequisites, RTL_TEXTENCODING_UTF8));
     204           0 :     m_map.put(newKey(id), b.makeStringAndClear());
     205             : #else
     206             :     (void) id;
     207             :     (void) data;
     208             : #endif
     209           0 : }
     210             : 
     211           0 : void ActivePackages::erase(
     212             :     OUString const & id, OUString const & fileName)
     213             : {
     214             : #if HAVE_FEATURE_EXTENSIONS
     215           0 :     m_map.erase(newKey(id), true) || m_map.erase(oldKey(fileName), true);
     216             : #else
     217             :     (void) id;
     218             :     (void) fileName;
     219             : #endif
     220           0 : }
     221             : 
     222             : }
     223             : 
     224             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10