Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/sot/stg.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
20
#ifndef INCLUDED_SOT_STG_HXX
21
#define INCLUDED_SOT_STG_HXX
22
23
#include <tools/stream.hxx>
24
#include <tools/globname.hxx>
25
#include <sot/storinfo.hxx>
26
#include <sot/sotdllapi.h>
27
#include <config_options.h>
28
29
namespace com::sun::star::ucb { class XProgressHandler; }
30
namespace com::sun::star::uno { class Any; }
31
namespace com::sun::star::uno { template <typename > class Reference; }
32
33
class StgIo;
34
class StgDirEntry;
35
typedef struct SvGUID ClsId;
36
37
class StorageBase : public SvRefBase
38
{
39
protected:
40
    mutable ErrCode m_nError;                   // error code
41
    StreamMode      m_nMode;                    // open mode
42
    bool            m_bAutoCommit;
43
                    StorageBase();
44
    virtual         ~StorageBase() override;
45
public:
46
    virtual bool    Validate( bool=false ) const = 0;
47
    virtual bool    ValidateMode( StreamMode ) const = 0;
48
    void            ResetError() const;
49
    void            SetError( ErrCode ) const;
50
    ErrCode         GetError() const;
51
7.00M
    bool            Good() const          { return m_nError == ERRCODE_NONE; }
52
340k
    StreamMode      GetMode() const  { return m_nMode;  }
53
    void            SetAutoCommit( bool bSet )
54
2.99M
                    { m_bAutoCommit = bSet; }
55
};
56
57
class BaseStorageStream : public StorageBase
58
{
59
public:
60
    virtual sal_Int32   Read( void * pData, sal_Int32 nSize ) = 0;
61
    virtual sal_Int32   Write( const void* pData, sal_Int32 nSize ) = 0;
62
    virtual sal_uInt64  Seek( sal_uInt64 nPos ) = 0;
63
    virtual sal_uInt64  Tell() = 0;
64
    virtual void        Flush() = 0;
65
    virtual bool        SetSize( sal_uInt64 nNewSize ) = 0;
66
    virtual sal_uInt64  GetSize() const = 0;
67
    virtual void        CopyTo( BaseStorageStream * pDestStm ) = 0;
68
    virtual bool        Commit() = 0;
69
    virtual bool        Equals( const BaseStorageStream& rStream ) const = 0;
70
};
71
72
enum class SotClipboardFormatId : sal_uInt32;
73
74
class SAL_DLLPUBLIC_RTTI BaseStorage : public StorageBase
75
{
76
public:
77
    virtual const OUString&     GetName() const = 0;
78
    virtual bool                IsRoot() const = 0;
79
    virtual void                SetClassId( const ClsId& ) = 0;
80
    virtual const ClsId&        GetClassId() const = 0;
81
    virtual void                SetDirty() = 0;
82
    virtual void                SetClass( const SvGlobalName & rClass,
83
                                          SotClipboardFormatId nOriginalClipFormat,
84
                                          const OUString & rUserTypeName ) = 0;
85
    virtual SvGlobalName        GetClassName() = 0;
86
    virtual SotClipboardFormatId         GetFormat() = 0;
87
    virtual OUString            GetUserName() = 0;
88
    virtual void                FillInfoList( SvStorageInfoList* ) const = 0;
89
    virtual bool                CopyTo( BaseStorage& rDestStg ) const = 0;
90
    virtual bool                Commit() = 0;
91
    virtual bool                Revert() = 0;
92
    virtual BaseStorageStream*  OpenStream( const OUString & rEleName,
93
                                            StreamMode = StreamMode::STD_READWRITE,
94
                                            bool bDirect = true ) = 0;
95
    virtual BaseStorage*        OpenStorage( const OUString & rEleName,
96
                                             StreamMode = StreamMode::STD_READWRITE,
97
                                             bool bDirect = false ) = 0;
98
    virtual BaseStorage*        OpenUCBStorage( const OUString & rEleName,
99
                                                StreamMode = StreamMode::STD_READWRITE,
100
                                                bool bDirect = false ) = 0;
101
    virtual BaseStorage*        OpenOLEStorage( const OUString & rEleName,
102
                                                StreamMode = StreamMode::STD_READWRITE,
103
                                                bool bDirect = false ) = 0;
104
    virtual bool                IsStream( const OUString& rEleName ) const = 0;
105
    virtual bool                IsStorage( const OUString& rEleName ) const = 0;
106
    virtual bool                IsContained( const OUString& rEleName ) const = 0;
107
    virtual void                Remove( const OUString & rEleName ) = 0;
108
    virtual bool                CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) = 0;
109
    virtual bool                ValidateFAT() = 0;
110
    virtual bool                Equals( const BaseStorage& rStream ) const = 0;
111
};
112
113
class OLEStorageBase
114
{
115
protected:
116
    StreamMode&     nStreamMode;              // open mode
117
    StgIo*          pIo;                      // I/O subsystem
118
    StgDirEntry*    pEntry;                   // the dir entry
119
                    OLEStorageBase( StgIo*, StgDirEntry*, StreamMode& );
120
                    ~OLEStorageBase();
121
    bool            Validate_Impl( bool ) const;
122
    static bool     ValidateMode_Impl( StreamMode, StgDirEntry const * p = nullptr );
123
};
124
125
class StorageStream final : public BaseStorageStream, public OLEStorageBase
126
{
127
//friend class Storage;
128
    sal_uInt64          nPos;                             // current position
129
130
                        virtual ~StorageStream() override;
131
public:
132
                        StorageStream( StgIo*, StgDirEntry*, StreamMode );
133
    virtual sal_Int32   Read( void * pData, sal_Int32 nSize ) override;
134
    virtual sal_Int32   Write( const void* pData, sal_Int32 nSize ) override;
135
    virtual sal_uInt64  Seek( sal_uInt64 nPos ) override;
136
762k
    virtual sal_uInt64  Tell() override { return nPos; }
137
    virtual void        Flush() override;
138
    virtual bool        SetSize( sal_uInt64 nNewSize ) override;
139
    virtual sal_uInt64  GetSize() const override;
140
    virtual void        CopyTo( BaseStorageStream * pDestStm ) override;
141
    virtual bool        Commit() final override;
142
    virtual bool        Validate( bool=false ) const override;
143
    virtual bool        ValidateMode( StreamMode ) const override;
144
    virtual bool        Equals( const BaseStorageStream& rStream ) const override;
145
};
146
147
class UCBStorageStream;
148
149
class UNLESS_MERGELIBS(SOT_DLLPUBLIC) Storage final : public BaseStorage, public OLEStorageBase
150
{
151
    OUString                    aName;
152
    bool                        bIsRoot;
153
    void                        Init( bool bCreate );
154
                                Storage( StgIo*, StgDirEntry*, StreamMode );
155
                                virtual ~Storage() override;
156
public:
157
                                Storage( OUString, StreamMode, bool bDirect );
158
                                Storage( SvStream& rStrm, bool bDirect );
159
                                Storage( UCBStorageStream& rStrm, bool bDirect );
160
161
    static bool                 IsStorageFile( const OUString & rFileName );
162
    static bool                 IsStorageFile( SvStream* );
163
164
    virtual const OUString&     GetName() const final override;
165
150k
    virtual bool                IsRoot() const override { return bIsRoot; }
166
    virtual void                SetClassId( const ClsId& ) override;
167
    virtual const ClsId&        GetClassId() const override;
168
    virtual void                SetDirty() override;
169
    virtual void                SetClass( const SvGlobalName & rClass,
170
                                          SotClipboardFormatId nOriginalClipFormat,
171
                                          const OUString & rUserTypeName ) override;
172
    virtual SvGlobalName        GetClassName() override;
173
    virtual SotClipboardFormatId         GetFormat() override;
174
    virtual OUString            GetUserName() override;
175
    virtual void                FillInfoList( SvStorageInfoList* ) const override;
176
    virtual bool                CopyTo( BaseStorage& rDestStg ) const override;
177
    virtual bool                Commit() final override;
178
    virtual bool                Revert() override;
179
    virtual BaseStorageStream*  OpenStream( const OUString & rEleName,
180
                                            StreamMode = StreamMode::STD_READWRITE,
181
                                            bool bDirect = true ) override;
182
    virtual BaseStorage*        OpenStorage( const OUString & rEleName,
183
                                             StreamMode = StreamMode::STD_READWRITE,
184
                                             bool bDirect = false ) override;
185
    virtual BaseStorage*        OpenUCBStorage( const OUString & rEleName,
186
                                                StreamMode = StreamMode::STD_READWRITE,
187
                                                bool bDirect = false ) override;
188
    virtual BaseStorage*        OpenOLEStorage( const OUString & rEleName,
189
                                                StreamMode = StreamMode::STD_READWRITE,
190
                                                bool bDirect = false ) override;
191
    virtual bool                IsStream( const OUString& rEleName ) const override;
192
    virtual bool                IsStorage( const OUString& rEleName ) const override;
193
    virtual bool                IsContained( const OUString& rEleName ) const override;
194
    virtual void                Remove( const OUString & rEleName ) override;
195
    virtual bool                CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) override;
196
    virtual bool                ValidateFAT() override;
197
    virtual bool                Validate( bool=false ) const override;
198
    virtual bool                ValidateMode( StreamMode ) const override;
199
    bool                        ValidateMode( StreamMode, StgDirEntry const * p ) const;
200
    virtual bool                Equals( const BaseStorage& rStream ) const override;
201
};
202
203
class UCBStorageStream_Impl;
204
class UCBStorageStream final : public BaseStorageStream
205
{
206
friend class UCBStorage;
207
208
    UCBStorageStream_Impl*
209
            pImp;
210
                                virtual ~UCBStorageStream() override;
211
public:
212
                                UCBStorageStream( const OUString& rName, StreamMode nMode, bool bDirect, bool bRepair, css::uno::Reference< css::ucb::XProgressHandler > const & xProgress );
213
                                UCBStorageStream( UCBStorageStream_Impl* );
214
215
    virtual sal_Int32           Read( void * pData, sal_Int32 nSize ) override;
216
    virtual sal_Int32           Write( const void* pData, sal_Int32 nSize ) override;
217
    virtual sal_uInt64          Seek( sal_uInt64 nPos ) override;
218
    virtual sal_uInt64          Tell() override;
219
    virtual void                Flush() override;
220
    virtual bool                SetSize( sal_uInt64 nNewSize ) override;
221
    virtual sal_uInt64          GetSize() const override;
222
    virtual void                CopyTo( BaseStorageStream * pDestStm ) override;
223
    virtual bool                Commit() override;
224
    virtual bool                Validate( bool=false ) const override;
225
    virtual bool                ValidateMode( StreamMode ) const override;
226
    virtual bool                Equals( const BaseStorageStream& rStream ) const override;
227
    bool                        SetProperty( const OUString& rName, const css::uno::Any& rValue );
228
229
    SvStream*                   GetModifySvStream();
230
};
231
232
namespace ucbhelper
233
{
234
    class Content;
235
}
236
237
class UCBStorage_Impl;
238
struct UCBStorageElement_Impl;
239
class UCBStorage final : public BaseStorage
240
{
241
    UCBStorage_Impl*            pImp;
242
243
                                virtual ~UCBStorage() override;
244
public:
245
    SOT_DLLPUBLIC static bool   IsStorageFile( SvStream* );
246
247
    SOT_DLLPUBLIC               UCBStorage( const ::ucbhelper::Content& rContent,
248
                                            const OUString& rName,
249
                                            StreamMode nMode,
250
                                            bool bDirect,
251
                                            bool bIsRoot );
252
253
                                UCBStorage( const OUString& rName,
254
                                            StreamMode nMode,
255
                                            bool bDirect,
256
                                            bool bIsRoot );
257
258
                                UCBStorage( const OUString& rName,
259
                                            StreamMode nMode,
260
                                            bool bDirect,
261
                                            bool bIsRoot,
262
                                            bool bIsRepair,
263
                                            css::uno::Reference< css::ucb::XProgressHandler > const &
264
                                            xProgressHandler );
265
266
                                UCBStorage( UCBStorage_Impl* );
267
268
                                UCBStorage( SvStream& rStrm, bool bDirect );
269
270
    virtual const OUString&     GetName() const override;
271
    virtual bool                IsRoot() const override;
272
    virtual void                SetClassId( const ClsId& ) override;
273
    virtual const ClsId&        GetClassId() const override;
274
    virtual void                SetDirty() override;
275
    virtual void                SetClass( const SvGlobalName & rClass,
276
                                          SotClipboardFormatId nOriginalClipFormat,
277
                                          const OUString & rUserTypeName ) override;
278
    virtual SvGlobalName        GetClassName() override;
279
    virtual SotClipboardFormatId         GetFormat() override;
280
    virtual OUString            GetUserName() override;
281
    virtual void                FillInfoList( SvStorageInfoList* ) const override;
282
    virtual bool                CopyTo( BaseStorage& rDestStg ) const override;
283
    virtual bool                Commit() final override;
284
    virtual bool                Revert() override;
285
    virtual BaseStorageStream*  OpenStream( const OUString & rEleName,
286
                                            StreamMode = StreamMode::STD_READWRITE,
287
                                            bool bDirect = true ) override;
288
    virtual BaseStorage*        OpenStorage( const OUString & rEleName,
289
                                             StreamMode = StreamMode::STD_READWRITE,
290
                                             bool bDirect = false ) override;
291
    virtual BaseStorage*        OpenUCBStorage( const OUString & rEleName,
292
                                                StreamMode = StreamMode::STD_READWRITE,
293
                                                bool bDirect = false ) override;
294
    virtual BaseStorage*        OpenOLEStorage( const OUString & rEleName,
295
                                                StreamMode = StreamMode::STD_READWRITE,
296
                                                bool bDirect = false ) override;
297
    virtual bool                IsStream( const OUString& rEleName ) const override;
298
    virtual bool                IsStorage( const OUString& rEleName ) const override;
299
    virtual bool                IsContained( const OUString& rEleName ) const override;
300
    virtual void                Remove( const OUString & rEleName ) override;
301
    virtual bool                CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) override;
302
    virtual bool                ValidateFAT() override;
303
    virtual bool                Validate( bool=false ) const override;
304
    virtual bool                ValidateMode( StreamMode ) const override;
305
    virtual bool                Equals( const BaseStorage& rStream ) const override;
306
307
    UCBStorageElement_Impl*     FindElement_Impl( std::u16string_view rName ) const;
308
    bool                        CopyStorageElement_Impl( UCBStorageElement_Impl const & rElement,
309
                                                         BaseStorage* pDest, const OUString& rNew ) const;
310
    BaseStorage*                OpenStorage_Impl( const OUString & rEleName,
311
                                                  StreamMode, bool bDirect, bool bForceUCBStorage );
312
313
};
314
315
#endif
316
317
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */