LibreOffice Module store (master) 1
stordir.cxx
Go to the documentation of this file.
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 "stordir.hxx"
21
22#include <sal/types.h>
23
24#include <rtl/textcvt.h>
25#include <rtl/ref.hxx>
26#include <rtl/ustring.h>
27
28#include <osl/mutex.hxx>
29
30#include <store/types.h>
31
32#include "storbase.hxx"
33#include "stordata.hxx"
34#include "storpage.hxx"
35
36using namespace store;
37
38static sal_Size convertTextToUnicode (
39 rtl_TextToUnicodeConverter hConverter,
40 const char *pSrcBuffer, sal_Size nSrcLength,
41 sal_Unicode *pDstBuffer, sal_Size nDstLength)
42{
43 sal_uInt32 nCvtInfo = 0;
44 sal_Size nCvtBytes = 0;
45 return rtl_convertTextToUnicode (
46 hConverter, nullptr,
47 pSrcBuffer, nSrcLength,
48 pDstBuffer, nDstLength,
49 OSTRING_TO_OUSTRING_CVTFLAGS,
50 &nCvtInfo, &nCvtBytes);
51}
52
53const sal_uInt32 OStoreDirectory_Impl::m_nTypeId(0x89191107);
54
55OStoreDirectory_Impl::OStoreDirectory_Impl()
56 : m_aDescr (0, 0, 0),
57 m_nPath (0),
58 m_hTextCvt (nullptr)
59{}
60
62{
63 if (m_xManager.is())
64 {
66 m_xManager->releasePage (m_aDescr);
67 }
68 rtl_destroyTextToUnicodeConverter (m_hTextCvt);
69}
70
71bool OStoreDirectory_Impl::isKindOf (sal_uInt32 nTypeId)
72{
73 return (nTypeId == m_nTypeId);
74}
75
77 OStorePageManager *pManager,
78 rtl_String const *pPath,
79 rtl_String const *pName,
80 storeAccessMode eMode)
81{
82 rtl::Reference<OStorePageManager> xManager (pManager);
83 if (!xManager.is())
85
86 if (!(pPath && pName))
88
90 storeError eErrCode = xManager->iget (
91 aPage, STORE_ATTRIB_ISDIR,
92 pPath, pName, eMode);
93 if (eErrCode != store_E_None)
94 return eErrCode;
95
96 if (!(aPage.attrib() & STORE_ATTRIB_ISDIR))
98
99 inode_holder_type xNode (aPage.get());
100 eErrCode = xManager->acquirePage (xNode->m_aDescr, storeAccessMode::ReadOnly);
101 if (eErrCode != store_E_None)
102 return eErrCode;
103
104 // Evaluate iteration path.
105 m_nPath = aPage.path();
106 m_nPath = rtl_crc32 (m_nPath, "/", 1);
107
108 // Save page manager, and descriptor.
109 m_xManager = xManager;
110 m_aDescr = xNode->m_aDescr;
111
112 return store_E_None;
113}
114
116{
117 if (!m_xManager.is())
119
121 if (!rFindData.m_nReserved)
122 return eErrCode;
123
124 // Acquire exclusive access.
125 osl::MutexGuard aGuard (*m_xManager);
126
127 // Check TextConverter.
128 if (m_hTextCvt == nullptr)
129 m_hTextCvt = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF8);
130
131 // Setup iteration key.
132 OStorePageKey aKey (rFindData.m_nReserved, m_nPath);
133
134 // Iterate.
135 for (;;)
136 {
137 OStorePageLink aLink;
138 eErrCode = m_xManager->iterate (aKey, aLink, rFindData.m_nAttrib);
139 if (eErrCode != store_E_None || aKey.m_nHigh != store::htonl(m_nPath))
140 break;
141
142 if (!(rFindData.m_nAttrib & STORE_ATTRIB_ISLINK))
143 {
144 // Load page.
146 eErrCode = m_xManager->loadObjectAt (aPage, aLink.location());
147 if (eErrCode == store_E_None)
148 {
149 inode_holder_type xNode (aPage.get());
150
151 // Setup FindData.
152 char *p = xNode->m_aNameBlock.m_pData;
153 sal_Int32 n = rtl_str_getLength (p);
154 sal_Int32 k = rFindData.m_nLength;
155
157 m_hTextCvt, p, n,
158 rFindData.m_pszName, STORE_MAXIMUM_NAMESIZE - 1);
159 if (k > n)
160 {
161 k = (k - n) * sizeof(sal_Unicode);
162 memset (&rFindData.m_pszName[n], 0, k);
163 }
164
165 rFindData.m_nLength = n;
166 rFindData.m_nAttrib |= aPage.attrib();
167
168 // Leave.
169 rFindData.m_nReserved = store::ntohl(aKey.m_nLow);
170 return store_E_None;
171 }
172 }
173
174 if (aKey.m_nLow == 0)
175 break;
176 aKey.m_nLow = store::htonl(store::ntohl(aKey.m_nLow) - 1);
177 }
178
179 // Finished.
180 memset (&rFindData, 0, sizeof (storeFindData));
181 return store_E_NoMoreFiles;
182}
183
184/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
sal_uInt32 attrib() const
attrib.
Definition: stordata.hxx:608
sal_uInt32 path() const
path.
Definition: stordata.hxx:628
OStorePageDescriptor m_aDescr
Definition: stordir.hxx:83
storeError create(OStorePageManager *pManager, rtl_String const *pPath, rtl_String const *pName, storeAccessMode eAccessMode)
create (two-phase construction).
Definition: stordir.cxx:76
static const sal_uInt32 m_nTypeId
IStoreHandle TypeId.
Definition: stordir.hxx:71
rtl::Reference< OStorePageManager > m_xManager
Definition: stordir.hxx:81
virtual ~OStoreDirectory_Impl() override
Definition: stordir.cxx:61
storeError iterate(storeFindData &rFindData)
iterate.
Definition: stordir.cxx:115
rtl_TextToUnicodeConverter m_hTextCvt
Definition: stordir.hxx:85
virtual bool isKindOf(sal_uInt32 nTypeId) override
Replaces dynamic_cast type checking.
Definition: stordir.cxx:71
std::shared_ptr< PageData > & get()
Definition: storbase.hxx:580
Mode eMode
void * p
sal_Int64 n
Old OStorePageCache implementation.
Definition: lockbyte.cxx:133
sal_uInt32 htonl(sal_uInt32 h)
Definition: storbase.hxx:69
sal_uInt32 ntohl(sal_uInt32 n)
Definition: storbase.hxx:70
#define STORE_PAGE_NULL
Definition: storbase.hxx:114
static sal_Size convertTextToUnicode(rtl_TextToUnicodeConverter hConverter, const char *pSrcBuffer, sal_Size nSrcLength, sal_Unicode *pDstBuffer, sal_Size nDstLength)
Definition: stordir.cxx:38
Find Data structure.
Definition: types.h:105
sal_Unicode m_pszName[STORE_MAXIMUM_NAMESIZE]
Name.
Definition: types.h:109
sal_uInt32 m_nAttrib
Attributes.
Definition: types.h:119
sal_Int32 m_nLength
Name Length.
Definition: types.h:114
sal_uInt32 m_nReserved
Reserved for internal use.
Definition: types.h:123
NameBlock m_aNameBlock
Representation.
Definition: stordata.hxx:491
sal_uInt32 m_nAddr
Representation.
Definition: storbase.hxx:120
sal_uInt32 m_nLow
Representation.
Definition: storbase.hxx:169
sal_uInt32 m_nHigh
Definition: storbase.hxx:170
char m_pData[STORE_MAXIMUM_NAMESIZE]
Definition: stordata.hxx:281
constexpr sal_uInt32 STORE_ATTRIB_ISDIR
Definition: types.h:52
storeAccessMode
Access Mode enumeration.
Definition: types.h:62
storeError
Error Code enumeration.
Definition: types.h:73
@ store_E_InvalidParameter
Definition: types.h:82
@ store_E_NotDirectory
Definition: types.h:86
@ store_E_None
Definition: types.h:74
@ store_E_InvalidAccess
Definition: types.h:80
@ store_E_NoMoreFiles
Definition: types.h:88
constexpr sal_uInt32 STORE_ATTRIB_ISLINK
Attributes (predefined).
Definition: types.h:51
sal_uInt16 sal_Unicode
constexpr auto STORE_MAXIMUM_NAMESIZE
NameSize (enforced) limit.
Definition: types.h:45