update credits
[LibreOffice.git] / store / source / stordir.cxx
blob4acb51b1dd767f45630422aaf7b955532dcb23f5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "stordir.hxx"
23 #include <sal/types.h>
25 #include <rtl/textcvt.h>
26 #include <rtl/ref.hxx>
28 #include <osl/mutex.hxx>
30 #include "store/types.h"
31 #include "object.hxx"
33 #include "storbase.hxx"
34 #include "stordata.hxx"
35 #include "storpage.hxx"
37 using namespace store;
39 /*========================================================================
41 * OStore... internals.
43 *======================================================================*/
45 * __store_convertTextToUnicode.
47 inline sal_Size __store_convertTextToUnicode (
48 rtl_TextToUnicodeConverter hConverter,
49 const sal_Char *pSrcBuffer, sal_Size nSrcLength,
50 sal_Unicode *pDstBuffer, sal_Size nDstLength)
52 sal_uInt32 nCvtInfo = 0;
53 sal_Size nCvtBytes = 0;
54 return rtl_convertTextToUnicode (
55 hConverter, 0,
56 pSrcBuffer, nSrcLength,
57 pDstBuffer, nDstLength,
58 OSTRING_TO_OUSTRING_CVTFLAGS,
59 &nCvtInfo, &nCvtBytes);
62 /*========================================================================
64 * OStoreDirectory_Impl implementation.
66 *======================================================================*/
67 const sal_uInt32 OStoreDirectory_Impl::m_nTypeId = sal_uInt32(0x89191107);
70 * OStoreDirectory_Impl.
72 OStoreDirectory_Impl::OStoreDirectory_Impl (void)
73 : m_xManager (),
74 m_aDescr (0, 0, 0),
75 m_nPath (0),
76 m_hTextCvt (NULL)
80 * ~OStoreDirectory_Impl.
82 OStoreDirectory_Impl::~OStoreDirectory_Impl (void)
84 if (m_xManager.is())
86 if (m_aDescr.m_nAddr != STORE_PAGE_NULL)
87 m_xManager->releasePage (m_aDescr);
89 rtl_destroyTextToUnicodeConverter (m_hTextCvt);
93 * isKindOf.
95 sal_Bool SAL_CALL OStoreDirectory_Impl::isKindOf (sal_uInt32 nTypeId)
97 return (nTypeId == m_nTypeId);
101 * create.
103 storeError OStoreDirectory_Impl::create (
104 OStorePageManager *pManager,
105 rtl_String *pPath,
106 rtl_String *pName,
107 storeAccessMode eMode)
109 rtl::Reference<OStorePageManager> xManager (pManager);
110 if (!xManager.is())
111 return store_E_InvalidAccess;
113 if (!(pPath && pName))
114 return store_E_InvalidParameter;
116 OStoreDirectoryPageObject aPage;
117 storeError eErrCode = xManager->iget (
118 aPage, STORE_ATTRIB_ISDIR,
119 pPath, pName, eMode);
120 if (eErrCode != store_E_None)
121 return eErrCode;
123 if (!(aPage.attrib() & STORE_ATTRIB_ISDIR))
124 return store_E_NotDirectory;
126 inode_holder_type xNode (aPage.get());
127 eErrCode = xManager->acquirePage (xNode->m_aDescr, store_AccessReadOnly);
128 if (eErrCode != store_E_None)
129 return eErrCode;
131 // Evaluate iteration path.
132 m_nPath = aPage.path();
133 m_nPath = rtl_crc32 (m_nPath, "/", 1);
135 // Save page manager, and descriptor.
136 m_xManager = xManager;
137 m_aDescr = xNode->m_aDescr;
139 return store_E_None;
143 * iterate.
145 storeError OStoreDirectory_Impl::iterate (storeFindData &rFindData)
147 if (!m_xManager.is())
148 return store_E_InvalidAccess;
150 storeError eErrCode = store_E_NoMoreFiles;
151 if (!rFindData.m_nReserved)
152 return eErrCode;
154 // Acquire exclusive access.
155 osl::MutexGuard aGuard (*m_xManager);
157 // Check TextConverter.
158 if (m_hTextCvt == NULL)
159 m_hTextCvt = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF8);
161 // Setup iteration key.
162 OStorePageKey aKey (rFindData.m_nReserved, m_nPath);
164 // Iterate.
165 for (;;)
167 OStorePageLink aLink;
168 eErrCode = m_xManager->iterate (aKey, aLink, rFindData.m_nAttrib);
169 if (!((eErrCode == store_E_None) && (aKey.m_nHigh == store::htonl(m_nPath))))
170 break;
172 if (!(rFindData.m_nAttrib & STORE_ATTRIB_ISLINK))
174 // Load page.
175 OStoreDirectoryPageObject aPage;
176 eErrCode = m_xManager->loadObjectAt (aPage, aLink.location());
177 if (eErrCode == store_E_None)
179 inode_holder_type xNode (aPage.get());
181 // Setup FindData.
182 sal_Char *p = xNode->m_aNameBlock.m_pData;
183 sal_Size n = rtl_str_getLength (p);
184 sal_Size k = rFindData.m_nLength;
186 n = __store_convertTextToUnicode (
187 m_hTextCvt, p, n,
188 rFindData.m_pszName, STORE_MAXIMUM_NAMESIZE - 1);
189 if (k > n)
191 k = (k - n) * sizeof(sal_Unicode);
192 memset (&rFindData.m_pszName[n], 0, k);
195 rFindData.m_nLength = n;
196 rFindData.m_nAttrib |= aPage.attrib();
197 rFindData.m_nSize = aPage.dataLength();
199 // Leave.
200 rFindData.m_nReserved = store::ntohl(aKey.m_nLow);
201 return store_E_None;
205 if (aKey.m_nLow == 0)
206 break;
207 aKey.m_nLow = store::htonl(store::ntohl(aKey.m_nLow) - 1);
210 // Finished.
211 memset (&rFindData, 0, sizeof (storeFindData));
212 return store_E_NoMoreFiles;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */