1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: stordir.cxx,v $
9 * last change: $Author: mhu $ $Date: 2008/10/17 16:30:17 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_store.hxx"
39 #include "stordir.hxx"
42 #include <sal/types.h>
45 #ifndef _RTL_TEXTCVT_H_
46 #include <rtl/textcvt.h>
49 #include <rtl/ref.hxx>
52 #ifndef _OSL_MUTEX_HXX_
53 #include <osl/mutex.hxx>
56 #ifndef _STORE_TYPES_H_
57 #include "store/types.h"
59 #ifndef _STORE_OBJECT_HXX_
63 #ifndef _STORE_STORBASE_HXX_
64 #include "storbase.hxx"
66 #ifndef _STORE_STORDATA_HXX_
67 #include "stordata.hxx"
69 #ifndef _STORE_STORPAGE_HXX_
70 #include "storpage.hxx"
73 using namespace store
;
75 /*========================================================================
77 * OStore... internals.
79 *======================================================================*/
81 * __store_convertTextToUnicode.
83 inline sal_Size
__store_convertTextToUnicode (
84 rtl_TextToUnicodeConverter hConverter
,
85 const sal_Char
*pSrcBuffer
, sal_Size nSrcLength
,
86 sal_Unicode
*pDstBuffer
, sal_Size nDstLength
)
88 sal_uInt32 nCvtInfo
= 0;
89 sal_Size nCvtBytes
= 0;
90 return rtl_convertTextToUnicode (
92 pSrcBuffer
, nSrcLength
,
93 pDstBuffer
, nDstLength
,
94 OSTRING_TO_OUSTRING_CVTFLAGS
,
95 &nCvtInfo
, &nCvtBytes
);
98 /*========================================================================
100 * OStoreDirectory_Impl implementation.
102 *======================================================================*/
103 const sal_uInt32
OStoreDirectory_Impl::m_nTypeId
= sal_uInt32(0x89191107);
106 * OStoreDirectory_Impl.
108 OStoreDirectory_Impl::OStoreDirectory_Impl (void)
116 * ~OStoreDirectory_Impl.
118 OStoreDirectory_Impl::~OStoreDirectory_Impl (void)
122 if (m_aDescr
.m_nAddr
!= STORE_PAGE_NULL
)
123 m_xManager
->releasePage (m_aDescr
, store_AccessReadOnly
);
125 rtl_destroyTextToUnicodeConverter (m_hTextCvt
);
131 sal_Bool SAL_CALL
OStoreDirectory_Impl::isKindOf (sal_uInt32 nTypeId
)
133 return (nTypeId
== m_nTypeId
);
139 storeError
OStoreDirectory_Impl::create (
140 OStorePageManager
*pManager
,
143 storeAccessMode eMode
)
145 rtl::Reference
<OStorePageManager
> xManager (pManager
);
147 return store_E_InvalidAccess
;
149 if (!(pPath
&& pName
))
150 return store_E_InvalidParameter
;
152 OStoreDirectoryPageObject aPage
;
153 storeError eErrCode
= xManager
->iget (
154 aPage
, STORE_ATTRIB_ISDIR
,
155 pPath
, pName
, eMode
);
156 if (eErrCode
!= store_E_None
)
159 if (!(aPage
.attrib() & STORE_ATTRIB_ISDIR
))
160 return store_E_NotDirectory
;
162 inode_holder_type
xNode (aPage
.get());
163 eErrCode
= xManager
->acquirePage (xNode
->m_aDescr
, store_AccessReadOnly
);
164 if (eErrCode
!= store_E_None
)
167 // Evaluate iteration path.
168 m_nPath
= aPage
.path();
169 m_nPath
= rtl_crc32 (m_nPath
, "/", 1);
171 // Save page manager, and descriptor.
172 m_xManager
= xManager
;
173 m_aDescr
= xNode
->m_aDescr
;
181 storeError
OStoreDirectory_Impl::iterate (storeFindData
&rFindData
)
183 if (!m_xManager
.is())
184 return store_E_InvalidAccess
;
186 storeError eErrCode
= store_E_NoMoreFiles
;
187 if (!rFindData
.m_nReserved
)
190 // Acquire exclusive access.
191 osl::MutexGuard
aGuard (*m_xManager
);
193 // Check TextConverter.
194 if (m_hTextCvt
== NULL
)
195 m_hTextCvt
= rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF8
);
197 // Setup iteration key.
198 OStorePageKey
aKey (rFindData
.m_nReserved
, m_nPath
);
203 OStorePageLink aLink
;
204 eErrCode
= m_xManager
->iterate (aKey
, aLink
, rFindData
.m_nAttrib
);
205 if (!((eErrCode
== store_E_None
) && (aKey
.m_nHigh
== store::htonl(m_nPath
))))
208 if (!(rFindData
.m_nAttrib
& STORE_ATTRIB_ISLINK
))
211 OStoreDirectoryPageObject aPage
;
212 eErrCode
= m_xManager
->loadObjectAt (aPage
, aLink
.location());
213 if (eErrCode
== store_E_None
)
215 inode_holder_type
xNode (aPage
.get());
218 sal_Char
*p
= xNode
->m_aNameBlock
.m_pData
;
219 sal_Size n
= rtl_str_getLength (p
);
220 sal_Size k
= rFindData
.m_nLength
;
222 n
= __store_convertTextToUnicode (
224 rFindData
.m_pszName
, STORE_MAXIMUM_NAMESIZE
- 1);
227 k
= (k
- n
) * sizeof(sal_Unicode
);
228 memset (&rFindData
.m_pszName
[n
], 0, k
);
231 rFindData
.m_nLength
= n
;
232 rFindData
.m_nAttrib
|= aPage
.attrib();
233 rFindData
.m_nSize
= aPage
.dataLength();
236 rFindData
.m_nReserved
= store::ntohl(aKey
.m_nLow
);
241 if (aKey
.m_nLow
== 0)
243 aKey
.m_nLow
= store::htonl(store::ntohl(aKey
.m_nLow
) - 1);
247 memset (&rFindData
, 0, sizeof (storeFindData
));
248 return store_E_NoMoreFiles
;