Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/package/inc/ZipPackageFolder.hxx
Line
Count
Source
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
#ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGEFOLDER_HXX
20
#define INCLUDED_PACKAGE_INC_ZIPPACKAGEFOLDER_HXX
21
22
#include <com/sun/star/container/XNameContainer.hpp>
23
#include <com/sun/star/container/XEnumerationAccess.hpp>
24
#include <com/sun/star/beans/StringPair.hpp>
25
#include <com/sun/star/uno/XComponentContext.hpp>
26
#include "ZipPackageEntry.hxx"
27
#include <cppuhelper/implbase.hxx>
28
#include <rtl/ref.hxx>
29
30
#include <string_view>
31
#include <unordered_map>
32
#include <vector>
33
34
class ZipOutputStream;
35
class ZipPackageFolder;
36
class ZipPackageStream;
37
38
struct ZipContentInfo
39
{
40
    rtl::Reference < ZipPackageEntry > xPackageEntry;
41
    bool bFolder;
42
    union
43
    {
44
        ZipPackageFolder *pFolder;
45
        ZipPackageStream *pStream;
46
    };
47
    ZipContentInfo( ZipPackageStream * pNewStream );
48
    ZipContentInfo( ZipPackageFolder * pNewFolder );
49
    ZipContentInfo( const ZipContentInfo& );
50
    ZipContentInfo( ZipContentInfo&& );
51
    ZipContentInfo& operator=( const ZipContentInfo& );
52
    ZipContentInfo& operator=( ZipContentInfo&& );
53
54
    ~ZipContentInfo();
55
};
56
57
struct OUStringHashImpl {
58
    using hash_type = std::hash<std::string_view>;
59
    using is_transparent = void;
60
61
    size_t operator()(const OUString& rString) const
62
555k
        { return std::hash<std::u16string_view>{}(rString); }
63
64
    size_t operator()(const std::u16string_view aString) const
65
1.61M
        { return std::hash<std::u16string_view>{}(aString); }
66
67
};
68
69
typedef std::unordered_map < OUString,
70
                             ZipContentInfo,
71
                             OUStringHashImpl,
72
                             std::equal_to<>> ContentHash;
73
74
class ZipPackageFolder final : public cppu::ImplInheritanceHelper
75
<
76
    ZipPackageEntry,
77
    css::container::XNameContainer,
78
    css::container::XEnumerationAccess
79
>
80
{
81
private:
82
    ContentHash maContents;
83
    OUString m_sVersion;
84
85
public:
86
87
    ZipPackageFolder( const css::uno::Reference < css::uno::XComponentContext >& xContext,
88
                      sal_Int32 nFormat,
89
                      bool bAllowRemoveOnInsert );
90
    virtual ~ZipPackageFolder() override;
91
92
0
    const OUString& GetVersion() const { return m_sVersion; }
93
0
    void SetVersion( const OUString& aVersion ) { m_sVersion = aVersion; }
94
95
    bool LookForUnexpectedODF12Streams(std::u16string_view aPath, bool isWholesomeEncryption);
96
97
    void setChildStreamsTypeByExtension( const css::beans::StringPair& aPair );
98
99
    void removeByName( std::u16string_view aName );
100
    css::uno::Any getByName( std::u16string_view aName );
101
    bool hasByName( std::u16string_view aName );
102
103
104
    /// @throws css::lang::IllegalArgumentException
105
    /// @throws css::container::ElementExistException
106
    /// @throws css::lang::WrappedTargetException
107
    /// @throws css::uno::RuntimeException
108
    void doInsertByName ( ZipPackageEntry *pEntry, bool bSetParent );
109
110
    ZipContentInfo& doGetByName( std::u16string_view aName );
111
112
23.0k
    void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; }
113
160k
    void setRemoveOnInsertMode_Impl( bool bRemove ) { mbAllowRemoveOnInsert = bRemove; }
114
115
    virtual bool saveChild( const OUString &rPath,
116
                            std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
117
                            ZipOutputStream & rZipOut,
118
                            const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
119
                            ::std::optional<sal_Int32> oPBKDF2IterationCount,
120
                            ::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args) override;
121
122
    // Recursive functions
123
    /// @throws css::uno::RuntimeException
124
    void saveContents(
125
            const OUString &rPath,
126
            std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
127
            ZipOutputStream & rZipOut,
128
            const css::uno::Sequence< sal_Int8 > &rEncryptionKey,
129
            ::std::optional<sal_Int32> oPBKDF2IterationCount,
130
            ::std::optional<::std::tuple<sal_Int32, sal_Int32, sal_Int32>> oArgon2Args) const;
131
132
    // XNameContainer
133
    virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override;
134
    virtual void SAL_CALL removeByName( const OUString& Name ) override;
135
136
    // XEnumerationAccess
137
    virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration(  ) override;
138
139
    // XElementAccess
140
    virtual css::uno::Type SAL_CALL getElementType(  ) override;
141
    virtual sal_Bool SAL_CALL hasElements(  ) override;
142
143
    // XNameAccess
144
    virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
145
    virtual css::uno::Sequence< OUString > SAL_CALL getElementNames(  ) override;
146
    virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
147
148
    // XNameReplace
149
    virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
150
151
    // XPropertySet
152
    virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
153
    virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
154
155
    // XServiceInfo
156
    virtual OUString SAL_CALL getImplementationName(  ) override;
157
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
158
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) override;
159
};
160
#endif
161
162
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */