LCOV - code coverage report
Current view: top level - libreoffice/desktop/source/deployment/manager - dp_activepackages.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 78 0.0 %
Date: 2012-12-27 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             : 
      21             : #include "sal/config.h"
      22             : 
      23             : #include <cstddef>
      24             : #include <utility>
      25             : #include <vector>
      26             : 
      27             : #include "osl/diagnose.h"
      28             : #include "rtl/strbuf.hxx"
      29             : #include "rtl/string.hxx"
      30             : #include "rtl/textenc.h"
      31             : #include "rtl/uri.h"
      32             : #include "rtl/uri.hxx"
      33             : #include "rtl/ustring.hxx"
      34             : #include <boost/unordered_map.hpp>
      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 !defined(ANDROID) && !defined(IOS)
      47             : 
      48             : namespace {
      49             : 
      50             : static char const separator = static_cast< char >(
      51             :     static_cast< unsigned char >(0xFF));
      52             : 
      53           0 : ::rtl::OString oldKey(::rtl::OUString const & fileName) {
      54           0 :     return ::rtl::OUStringToOString(fileName, RTL_TEXTENCODING_UTF8);
      55             : }
      56             : 
      57           0 : ::rtl::OString newKey(::rtl::OUString const & id) {
      58           0 :     ::rtl::OStringBuffer b;
      59           0 :     b.append(separator);
      60           0 :     b.append(::rtl::OUStringToOString(id, RTL_TEXTENCODING_UTF8));
      61           0 :     return b.makeStringAndClear();
      62             : }
      63             : 
      64           0 : ::dp_manager::ActivePackages::Data decodeOldData(
      65             :     ::rtl::OUString const & fileName, ::rtl::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 = ::rtl::OUString(value.getStr(), i, RTL_TEXTENCODING_UTF8);
      71           0 :     d.fileName = fileName;
      72             :     d.mediaType = ::rtl::OUString(
      73           0 :         value.getStr() + i + 1, value.getLength() - i - 1,
      74           0 :         RTL_TEXTENCODING_UTF8);
      75           0 :     return d;
      76             : }
      77             : 
      78           0 : ::dp_manager::ActivePackages::Data decodeNewData(::rtl::OString const & value) {
      79           0 :     ::dp_manager::ActivePackages::Data d;
      80           0 :     sal_Int32 i1 = value.indexOf(separator);
      81             :     OSL_ASSERT(i1 >= 0);
      82             :     d.temporaryName = ::rtl::OUString(
      83           0 :         value.getStr(), i1, RTL_TEXTENCODING_UTF8);
      84           0 :     sal_Int32 i2 = value.indexOf(separator, i1 + 1);
      85             :     OSL_ASSERT(i2 >= 0);
      86             :     d.fileName = ::rtl::OUString(
      87           0 :         value.getStr() + i1 + 1, i2 - i1 - 1, RTL_TEXTENCODING_UTF8);
      88           0 :     sal_Int32 i3 = value.indexOf(separator, i2 + 1);
      89             : 
      90           0 :     if (i3 < 0)
      91             :     {
      92             :         //Before ActivePackages::Data::version was added
      93             :         d.mediaType = ::rtl::OUString(
      94           0 :             value.getStr() + i2 + 1, value.getLength() - i2 - 1,
      95           0 :             RTL_TEXTENCODING_UTF8);
      96             :     }
      97             :     else
      98             :     {
      99           0 :         sal_Int32 i4 = value.indexOf(separator, i3 + 1);
     100             :         d.mediaType = ::rtl::OUString(
     101           0 :             value.getStr() + i2 + 1, i3 - i2 -1, RTL_TEXTENCODING_UTF8);
     102             :         d.version = ::rtl::OUString(
     103           0 :             value.getStr() + i3 + 1, i4 - i3 - 1,
     104           0 :             RTL_TEXTENCODING_UTF8);
     105             :         d.failedPrerequisites = ::rtl::OUString(
     106           0 :             value.getStr() + i4 + 1, value.getLength() - i4 - 1,
     107           0 :             RTL_TEXTENCODING_UTF8);
     108             :     }
     109           0 :     return d;
     110             : }
     111             : 
     112             : }
     113             : #endif
     114             : 
     115             : namespace dp_manager {
     116             : 
     117           0 : ActivePackages::ActivePackages() {}
     118             : 
     119           0 : ActivePackages::ActivePackages(::rtl::OUString const & url, bool readOnly)
     120             : #if !defined(ANDROID) && !defined(IOS)
     121           0 :     : m_map(url, readOnly)
     122             : #endif
     123             : {
     124             : #if defined(ANDROID) || defined(IOS)
     125             :     (void)url; (void)readOnly;
     126             : #endif
     127           0 : }
     128             : 
     129           0 : ActivePackages::~ActivePackages() {}
     130             : 
     131           0 : bool ActivePackages::has(
     132             :     ::rtl::OUString const & id, ::rtl::OUString const & fileName) const
     133             : {
     134           0 :     return get(NULL, id, fileName);
     135             : }
     136             : 
     137           0 : bool ActivePackages::get(
     138             :     Data * data, ::rtl::OUString const & id, ::rtl::OUString const & fileName)
     139             :     const
     140             : {
     141             : #if !defined(ANDROID) && !defined(IOS)
     142           0 :     ::rtl::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 !defined(ANDROID) && !defined(IOS)
     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             :                     ::rtl::OUString(
     175           0 :                         i->first.getStr() + 1, i->first.getLength() - 1,
     176             :                         RTL_TEXTENCODING_UTF8),
     177           0 :                     decodeNewData(i->second)));
     178             :         } else {
     179             :             ::rtl::OUString fn(
     180           0 :                 ::rtl::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(::rtl::OUString const & id, Data const & data) {
     192             : #if !defined(ANDROID) && !defined(IOS)
     193           0 :     ::rtl::OStringBuffer b;
     194             :     b.append(
     195           0 :         ::rtl::OUStringToOString(data.temporaryName, RTL_TEXTENCODING_UTF8));
     196           0 :     b.append(separator);
     197           0 :     b.append(::rtl::OUStringToOString(data.fileName, RTL_TEXTENCODING_UTF8));
     198           0 :     b.append(separator);
     199           0 :     b.append(::rtl::OUStringToOString(data.mediaType, RTL_TEXTENCODING_UTF8));
     200           0 :     b.append(separator);
     201           0 :     b.append(::rtl::OUStringToOString(data.version, RTL_TEXTENCODING_UTF8));
     202           0 :     b.append(separator);
     203           0 :     b.append(::rtl::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             :     ::rtl::OUString const & id, ::rtl::OUString const & fileName)
     213             : {
     214             : #if !defined(ANDROID) && !defined(IOS)
     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