xref: /AOO41X/main/store/source/store.cxx (revision 73d9b18ad12b526a229c2c5ca3fb0f85a41c2f42)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_store.hxx"
26 
27 #include "store/store.h"
28 
29 #include <sal/types.h>
30 #include <rtl/memory.h>
31 #include <rtl/string.hxx>
32 #include <rtl/ref.hxx>
33 
34 #include "object.hxx"
35 #include "lockbyte.hxx"
36 
37 #include "storbase.hxx"
38 #include "storpage.hxx"
39 #include "stordir.hxx"
40 #include "storlckb.hxx"
41 
42 using rtl::Reference;
43 using rtl::OString;
44 
45 namespace store
46 {
47 /** Template helper class as type safe Reference to store_handle_type.
48  */
49 template<class store_handle_type>
50 class OStoreHandle : public rtl::Reference<store_handle_type>
51 {
52 public:
OStoreHandle(store_handle_type * pHandle)53     OStoreHandle (store_handle_type * pHandle)
54         : rtl::Reference<store_handle_type> (pHandle)
55     {}
56 
query(void * pHandle)57     static store_handle_type * SAL_CALL query (void * pHandle)
58     {
59         return store::query (
60             static_cast<IStoreHandle*>(pHandle),
61             static_cast<store_handle_type*>(0));
62     }
63 };
64 }
65 
66 
67 using namespace store;
68 
69 /*========================================================================
70  *
71  * storeHandle implementation.
72  *
73  *======================================================================*/
74 /*
75  * store_acquireHandle.
76  */
store_acquireHandle(storeHandle Handle)77 storeError SAL_CALL store_acquireHandle (
78     storeHandle Handle
79 ) SAL_THROW_EXTERN_C()
80 {
81     IStoreHandle *pHandle = static_cast<IStoreHandle*>(Handle);
82     if (!pHandle)
83         return store_E_InvalidHandle;
84 
85     pHandle->acquire();
86     return store_E_None;
87 }
88 
89 /*
90  * store_releaseHandle.
91  */
store_releaseHandle(storeHandle Handle)92 storeError SAL_CALL store_releaseHandle (
93     storeHandle Handle
94 ) SAL_THROW_EXTERN_C()
95 {
96     IStoreHandle *pHandle = static_cast<IStoreHandle*>(Handle);
97     if (!pHandle)
98         return store_E_InvalidHandle;
99 
100     pHandle->release();
101     return store_E_None;
102 }
103 
104 /*========================================================================
105  *
106  * storeFileHandle implementation.
107  *
108  *======================================================================*/
109 /*
110  * store_createMemoryFile.
111  */
store_createMemoryFile(sal_uInt16 nPageSize,storeFileHandle * phFile)112 storeError SAL_CALL store_createMemoryFile (
113     sal_uInt16       nPageSize,
114     storeFileHandle *phFile
115 ) SAL_THROW_EXTERN_C()
116 {
117     if (!phFile)
118         return store_E_InvalidParameter;
119     *phFile = NULL;
120 
121     Reference<ILockBytes> xLockBytes;
122 
123     storeError eErrCode = MemoryLockBytes_createInstance(xLockBytes);
124     if (eErrCode != store_E_None)
125         return eErrCode;
126     OSL_ASSERT(xLockBytes.is());
127 
128     Reference<OStorePageManager> xManager (new OStorePageManager());
129     if (!xManager.is())
130         return store_E_OutOfMemory;
131 
132     eErrCode = xManager->initialize (
133         &*xLockBytes, store_AccessCreate, nPageSize);
134     if (eErrCode != store_E_None)
135         return eErrCode;
136 
137     xManager->acquire();
138 
139     *phFile = (storeFileHandle)&(*xManager);
140     return store_E_None;
141 }
142 
143 /*
144  * store_openFile.
145  */
store_openFile(rtl_uString * pFilename,storeAccessMode eAccessMode,sal_uInt16 nPageSize,storeFileHandle * phFile)146 storeError SAL_CALL store_openFile (
147     rtl_uString     *pFilename,
148     storeAccessMode  eAccessMode,
149     sal_uInt16       nPageSize,
150     storeFileHandle *phFile
151 ) SAL_THROW_EXTERN_C()
152 {
153     if (phFile)
154         *phFile = NULL;
155 
156     if (!(pFilename && phFile))
157         return store_E_InvalidParameter;
158 
159     Reference<ILockBytes> xLockBytes;
160 
161     storeError eErrCode = FileLockBytes_createInstance (xLockBytes, pFilename, eAccessMode);
162     if (eErrCode != store_E_None)
163         return eErrCode;
164     OSL_ASSERT(xLockBytes.is());
165 
166     Reference<OStorePageManager> xManager (new OStorePageManager());
167     if (!xManager.is())
168         return store_E_OutOfMemory;
169 
170     eErrCode = xManager->initialize (
171         &*xLockBytes, eAccessMode, nPageSize);
172     if (eErrCode != store_E_None)
173         return eErrCode;
174 
175     xManager->acquire();
176 
177     *phFile = (storeFileHandle)&(*xManager);
178     return store_E_None;
179 }
180 
181 /*
182  * store_closeFile.
183  */
store_closeFile(storeFileHandle Handle)184 storeError SAL_CALL store_closeFile (
185     storeFileHandle Handle
186 ) SAL_THROW_EXTERN_C()
187 {
188     OStorePageManager *pManager =
189         OStoreHandle<OStorePageManager>::query (Handle);
190     if (!pManager)
191         return store_E_InvalidHandle;
192 
193     storeError eErrCode = pManager->close();
194     pManager->release();
195     return eErrCode;
196 }
197 
198 /*
199  * store_flushFile.
200  */
store_flushFile(storeFileHandle Handle)201 storeError SAL_CALL store_flushFile (
202     storeFileHandle Handle
203 ) SAL_THROW_EXTERN_C()
204 {
205     OStoreHandle<OStorePageManager> xManager (
206         OStoreHandle<OStorePageManager>::query (Handle));
207     if (!xManager.is())
208         return store_E_InvalidHandle;
209 
210     return xManager->flush();
211 }
212 
213 /*
214  * store_getFileRefererCount.
215  */
store_getFileRefererCount(storeFileHandle Handle,sal_uInt32 * pnRefCount)216 storeError SAL_CALL store_getFileRefererCount (
217     storeFileHandle  Handle,
218     sal_uInt32      *pnRefCount
219 ) SAL_THROW_EXTERN_C()
220 {
221     OStoreHandle<OStorePageManager> xManager (
222         OStoreHandle<OStorePageManager>::query (Handle));
223     if (!xManager.is())
224         return store_E_InvalidHandle;
225 
226     if (!pnRefCount)
227         return store_E_InvalidParameter;
228 
229     *pnRefCount = xManager->getRefererCount();
230     return store_E_None;
231 }
232 
233 /*
234  * store_getFileSize.
235  */
store_getFileSize(storeFileHandle Handle,sal_uInt32 * pnSize)236 storeError SAL_CALL store_getFileSize (
237     storeFileHandle  Handle,
238     sal_uInt32      *pnSize
239 ) SAL_THROW_EXTERN_C()
240 {
241     OStoreHandle<OStorePageManager> xManager (
242         OStoreHandle<OStorePageManager>::query (Handle));
243     if (!xManager.is())
244         return store_E_InvalidHandle;
245 
246     if (!pnSize)
247         return store_E_InvalidParameter;
248 
249     return xManager->size (*pnSize);
250 }
251 
252 /*
253  * store_rebuildFile.
254  */
store_rebuildFile(rtl_uString * pSrcFilename,rtl_uString * pDstFilename)255 storeError SAL_CALL store_rebuildFile (
256     rtl_uString *pSrcFilename,
257     rtl_uString *pDstFilename
258 ) SAL_THROW_EXTERN_C()
259 {
260     storeError eErrCode = store_E_None;
261 
262     if (!(pSrcFilename && pDstFilename))
263         return store_E_InvalidParameter;
264 
265     Reference<OStorePageManager> xManager (new OStorePageManager());
266     if (!xManager.is())
267         return store_E_OutOfMemory;
268 
269     Reference<ILockBytes> xSrcLB;
270     eErrCode = FileLockBytes_createInstance (xSrcLB, pSrcFilename, store_AccessReadOnly);
271     if (eErrCode != store_E_None)
272         return eErrCode;
273     OSL_ASSERT(xSrcLB.is());
274 
275     Reference<ILockBytes> xDstLB;
276     eErrCode = FileLockBytes_createInstance (xDstLB, pDstFilename, store_AccessCreate);
277     if (eErrCode != store_E_None)
278         return eErrCode;
279     OSL_ASSERT(xDstLB.is());
280 
281     return xManager->rebuild (&*xSrcLB, &*xDstLB);
282 }
283 
284 /*========================================================================
285  *
286  * storeDirectoryHandle implementation.
287  *
288  *======================================================================*/
289 /*
290  * store_openDirectory.
291  */
store_openDirectory(storeFileHandle hFile,rtl_uString * pPath,rtl_uString * pName,storeAccessMode eAccessMode,storeDirectoryHandle * phDirectory)292 storeError SAL_CALL store_openDirectory (
293     storeFileHandle       hFile,
294     rtl_uString          *pPath,
295     rtl_uString          *pName,
296     storeAccessMode       eAccessMode,
297     storeDirectoryHandle *phDirectory
298 ) SAL_THROW_EXTERN_C()
299 {
300     storeError eErrCode = store_E_None;
301     if (phDirectory)
302         *phDirectory = NULL;
303 
304     OStoreHandle<OStorePageManager> xManager (
305         OStoreHandle<OStorePageManager>::query (hFile));
306     if (!xManager.is())
307         return store_E_InvalidHandle;
308 
309     if (!(pPath && pName && phDirectory))
310         return store_E_InvalidParameter;
311 
312     Reference<OStoreDirectory_Impl> xDirectory (new OStoreDirectory_Impl());
313     if (!xDirectory.is())
314         return store_E_OutOfMemory;
315 
316     OString aPath (pPath->buffer, pPath->length, RTL_TEXTENCODING_UTF8);
317     OString aName (pName->buffer, pName->length, RTL_TEXTENCODING_UTF8);
318 
319     eErrCode = xDirectory->create (&*xManager, aPath.pData, aName.pData, eAccessMode);
320     if (eErrCode != store_E_None)
321         return eErrCode;
322 
323     xDirectory->acquire();
324 
325     *phDirectory = (storeDirectoryHandle)&(*xDirectory);
326     return store_E_None;
327 }
328 
329 /*
330  * store_closeDirectory.
331  */
store_closeDirectory(storeDirectoryHandle Handle)332 storeError SAL_CALL store_closeDirectory (
333     storeDirectoryHandle Handle
334 ) SAL_THROW_EXTERN_C()
335 {
336     OStoreDirectory_Impl *pDirectory =
337         OStoreHandle<OStoreDirectory_Impl>::query (Handle);
338     if (!pDirectory)
339         return store_E_InvalidHandle;
340 
341     pDirectory->release();
342     return store_E_None;
343 }
344 
345 /*
346  * store_findFirst.
347  */
store_findFirst(storeDirectoryHandle Handle,storeFindData * pFindData)348 storeError SAL_CALL store_findFirst (
349     storeDirectoryHandle  Handle,
350     storeFindData        *pFindData
351 ) SAL_THROW_EXTERN_C()
352 {
353     OStoreHandle<OStoreDirectory_Impl> xDirectory (
354         OStoreHandle<OStoreDirectory_Impl>::query (Handle));
355     if (!xDirectory.is())
356         return store_E_InvalidHandle;
357 
358     if (!pFindData)
359         return store_E_InvalidParameter;
360 
361     // Initialize FindData.
362     rtl_zeroMemory (pFindData, sizeof (storeFindData));
363 
364     // Find first.
365     pFindData->m_nReserved = (sal_uInt32)(~0);
366     return xDirectory->iterate (*pFindData);
367 }
368 
369 /*
370  * store_findNext.
371  */
store_findNext(storeDirectoryHandle Handle,storeFindData * pFindData)372 storeError SAL_CALL store_findNext (
373     storeDirectoryHandle  Handle,
374     storeFindData        *pFindData
375 ) SAL_THROW_EXTERN_C()
376 {
377     OStoreHandle<OStoreDirectory_Impl> xDirectory (
378         OStoreHandle<OStoreDirectory_Impl>::query (Handle));
379     if (!xDirectory.is())
380         return store_E_InvalidHandle;
381 
382     if (!pFindData)
383         return store_E_InvalidParameter;
384 
385     // Check FindData.
386     if (!pFindData->m_nReserved)
387         return store_E_NoMoreFiles;
388 
389     // Find next.
390     pFindData->m_nReserved -= 1;
391     return xDirectory->iterate (*pFindData);
392 }
393 
394 /*========================================================================
395  *
396  * storeStreamHandle implementation.
397  *
398  *======================================================================*/
399 /*
400  * store_openStream
401  */
store_openStream(storeFileHandle hFile,rtl_uString * pPath,rtl_uString * pName,storeAccessMode eAccessMode,storeStreamHandle * phStream)402 storeError SAL_CALL store_openStream (
403     storeFileHandle    hFile,
404     rtl_uString       *pPath,
405     rtl_uString       *pName,
406     storeAccessMode    eAccessMode,
407     storeStreamHandle *phStream
408 ) SAL_THROW_EXTERN_C()
409 {
410     storeError eErrCode = store_E_None;
411     if (phStream)
412         *phStream = NULL;
413 
414     OStoreHandle<OStorePageManager> xManager (
415         OStoreHandle<OStorePageManager>::query (hFile));
416     if (!xManager.is())
417         return store_E_InvalidHandle;
418 
419     if (!(pPath && pName && phStream))
420         return store_E_InvalidParameter;
421 
422     Reference<OStoreLockBytes> xLockBytes (new OStoreLockBytes());
423     if (!xLockBytes.is())
424         return store_E_OutOfMemory;
425 
426     OString aPath (pPath->buffer, pPath->length, RTL_TEXTENCODING_UTF8);
427     OString aName (pName->buffer, pName->length, RTL_TEXTENCODING_UTF8);
428 
429     eErrCode = xLockBytes->create (&*xManager, aPath.pData, aName.pData, eAccessMode);
430     if (eErrCode != store_E_None)
431         return eErrCode;
432 
433     xLockBytes->acquire();
434 
435     *phStream = (storeStreamHandle)&(*xLockBytes);
436     return store_E_None;
437 }
438 
439 /*
440  * store_closeStream.
441  */
store_closeStream(storeStreamHandle Handle)442 storeError SAL_CALL store_closeStream (
443     storeStreamHandle Handle
444 ) SAL_THROW_EXTERN_C()
445 {
446     OStoreLockBytes *pLockBytes =
447         OStoreHandle<OStoreLockBytes>::query (Handle);
448     if (!pLockBytes)
449         return store_E_InvalidHandle;
450 
451     pLockBytes->release();
452     return store_E_None;
453 }
454 
455 /*
456  * store_readStream.
457  */
store_readStream(storeStreamHandle Handle,sal_uInt32 nOffset,void * pBuffer,sal_uInt32 nBytes,sal_uInt32 * pnDone)458 storeError SAL_CALL store_readStream (
459     storeStreamHandle  Handle,
460     sal_uInt32         nOffset,
461     void              *pBuffer,
462     sal_uInt32         nBytes,
463     sal_uInt32        *pnDone
464 ) SAL_THROW_EXTERN_C()
465 {
466     OStoreHandle<OStoreLockBytes> xLockBytes (
467         OStoreHandle<OStoreLockBytes>::query (Handle));
468     if (!xLockBytes.is())
469         return store_E_InvalidHandle;
470 
471     if (!(pBuffer && pnDone))
472         return store_E_InvalidParameter;
473 
474     return xLockBytes->readAt (nOffset, pBuffer, nBytes, *pnDone);
475 }
476 
477 /*
478  * store_writeStream.
479  */
store_writeStream(storeStreamHandle Handle,sal_uInt32 nOffset,const void * pBuffer,sal_uInt32 nBytes,sal_uInt32 * pnDone)480 storeError SAL_CALL store_writeStream (
481     storeStreamHandle  Handle,
482     sal_uInt32         nOffset,
483     const void        *pBuffer,
484     sal_uInt32         nBytes,
485     sal_uInt32        *pnDone
486 ) SAL_THROW_EXTERN_C()
487 {
488     OStoreHandle<OStoreLockBytes> xLockBytes (
489         OStoreHandle<OStoreLockBytes>::query (Handle));
490     if (!xLockBytes.is())
491         return store_E_InvalidHandle;
492 
493     if (!(pBuffer && pnDone))
494         return store_E_InvalidParameter;
495 
496     return xLockBytes->writeAt (nOffset, pBuffer, nBytes, *pnDone);
497 }
498 
499 /*
500  * store_flushStream.
501  */
store_flushStream(storeStreamHandle Handle)502 storeError SAL_CALL store_flushStream (
503     storeStreamHandle Handle
504 ) SAL_THROW_EXTERN_C()
505 {
506     OStoreHandle<OStoreLockBytes> xLockBytes (
507         OStoreHandle<OStoreLockBytes>::query (Handle));
508     if (!xLockBytes.is())
509         return store_E_InvalidHandle;
510 
511     return xLockBytes->flush();
512 }
513 
514 /*
515  * store_getStreamSize.
516  */
store_getStreamSize(storeStreamHandle Handle,sal_uInt32 * pnSize)517 storeError SAL_CALL store_getStreamSize (
518     storeStreamHandle  Handle,
519     sal_uInt32        *pnSize
520 ) SAL_THROW_EXTERN_C()
521 {
522     OStoreHandle<OStoreLockBytes> xLockBytes (
523         OStoreHandle<OStoreLockBytes>::query (Handle));
524     if (!xLockBytes.is())
525         return store_E_InvalidHandle;
526 
527     if (!pnSize)
528         return store_E_InvalidParameter;
529 
530     return xLockBytes->stat (*pnSize);
531 }
532 
533 /*
534  * store_setStreamSize.
535  */
store_setStreamSize(storeStreamHandle Handle,sal_uInt32 nSize)536 storeError SAL_CALL store_setStreamSize (
537     storeStreamHandle Handle,
538     sal_uInt32        nSize
539 ) SAL_THROW_EXTERN_C()
540 {
541     OStoreHandle<OStoreLockBytes> xLockBytes (
542         OStoreHandle<OStoreLockBytes>::query (Handle));
543     if (!xLockBytes.is())
544         return store_E_InvalidHandle;
545 
546     return xLockBytes->setSize (nSize);
547 }
548 
549 /*========================================================================
550  *
551  * Common storeDirectoryHandle and storeStreamHandle operations.
552  *
553  *======================================================================*/
554 /*
555  * store_attrib.
556  */
store_attrib(storeFileHandle Handle,rtl_uString * pPath,rtl_uString * pName,sal_uInt32 nMask1,sal_uInt32 nMask2,sal_uInt32 * pnAttrib)557 storeError SAL_CALL store_attrib (
558     storeFileHandle Handle,
559     rtl_uString    *pPath,
560     rtl_uString    *pName,
561     sal_uInt32      nMask1,
562     sal_uInt32      nMask2,
563     sal_uInt32     *pnAttrib
564 ) SAL_THROW_EXTERN_C()
565 {
566     storeError eErrCode = store_E_None;
567     if (pnAttrib)
568         *pnAttrib = 0;
569 
570     OStoreHandle<OStorePageManager> xManager (
571         OStoreHandle<OStorePageManager>::query (Handle));
572     if (!xManager.is())
573         return store_E_InvalidHandle;
574 
575     if (!(pPath && pName))
576         return store_E_InvalidParameter;
577 
578     // Setup page key.
579     OString aPath (pPath->buffer, pPath->length, RTL_TEXTENCODING_UTF8);
580     OString aName (pName->buffer, pName->length, RTL_TEXTENCODING_UTF8);
581     OStorePageKey aKey;
582 
583     eErrCode = OStorePageManager::namei (aPath.pData, aName.pData, aKey);
584     if (eErrCode != store_E_None)
585         return eErrCode;
586 
587     // Obtain or modify page attributes.
588     sal_uInt32 nAttrib = 0;
589     eErrCode = xManager->attrib (aKey, nMask1, nMask2, nAttrib);
590     if (pnAttrib)
591         *pnAttrib = nAttrib;
592     return eErrCode;
593 }
594 
595 /*
596  * store_link.
597  */
store_link(storeFileHandle Handle,rtl_uString * pSrcPath,rtl_uString * pSrcName,rtl_uString * pDstPath,rtl_uString * pDstName)598 storeError SAL_CALL store_link (
599     storeFileHandle Handle,
600     rtl_uString *pSrcPath, rtl_uString *pSrcName,
601     rtl_uString *pDstPath, rtl_uString *pDstName
602 ) SAL_THROW_EXTERN_C()
603 {
604     storeError eErrCode = store_E_None;
605 
606     OStoreHandle<OStorePageManager> xManager (
607         OStoreHandle<OStorePageManager>::query (Handle));
608     if (!xManager.is())
609         return store_E_InvalidHandle;
610 
611     if (!(pSrcPath && pSrcName))
612         return store_E_InvalidParameter;
613 
614     if (!(pDstPath && pDstName))
615         return store_E_InvalidParameter;
616 
617     // Setup 'Source' page key.
618     OString aSrcPath (
619         pSrcPath->buffer, pSrcPath->length, RTL_TEXTENCODING_UTF8);
620     OString aSrcName (
621         pSrcName->buffer, pSrcName->length, RTL_TEXTENCODING_UTF8);
622     OStorePageKey aSrcKey;
623 
624     eErrCode = OStorePageManager::namei (
625         aSrcPath.pData, aSrcName.pData, aSrcKey);
626     if (eErrCode != store_E_None)
627         return eErrCode;
628 
629     // Setup 'Destination' page key.
630     OString aDstPath (
631         pDstPath->buffer, pDstPath->length, RTL_TEXTENCODING_UTF8);
632     OString aDstName (
633         pDstName->buffer, pDstName->length, RTL_TEXTENCODING_UTF8);
634     OStorePageKey aDstKey;
635 
636     eErrCode = OStorePageManager::namei (
637         aDstPath.pData, aDstName.pData, aDstKey);
638     if (eErrCode != store_E_None)
639         return eErrCode;
640 
641     // Link 'Source' hard to 'Destination'.
642     return xManager->link (aSrcKey, aDstKey);
643 }
644 
645 /*
646  * store_symlink.
647  */
store_symlink(storeFileHandle Handle,rtl_uString * pSrcPath,rtl_uString * pSrcName,rtl_uString * pDstPath,rtl_uString * pDstName)648 storeError SAL_CALL store_symlink (
649     storeFileHandle Handle,
650     rtl_uString *pSrcPath, rtl_uString *pSrcName,
651     rtl_uString *pDstPath, rtl_uString *pDstName
652 ) SAL_THROW_EXTERN_C()
653 {
654     storeError eErrCode = store_E_None;
655 
656     OStoreHandle<OStorePageManager> xManager (
657         OStoreHandle<OStorePageManager>::query (Handle));
658     if (!xManager.is())
659         return store_E_InvalidHandle;
660 
661     if (!(pSrcPath && pSrcName))
662         return store_E_InvalidParameter;
663 
664     if (!(pDstPath && pDstName))
665         return store_E_InvalidParameter;
666 
667     // Setup 'Destination' page key.
668     OString aDstPath (
669         pDstPath->buffer, pDstPath->length, RTL_TEXTENCODING_UTF8);
670     OString aDstName (
671         pDstName->buffer, pDstName->length, RTL_TEXTENCODING_UTF8);
672     OStorePageKey aDstKey;
673 
674     eErrCode = OStorePageManager::namei (
675         aDstPath.pData, aDstName.pData, aDstKey);
676     if (eErrCode != store_E_None)
677         return eErrCode;
678 
679     // Insert 'Source' as symlink to 'Destination'.
680     OString aSrcPath (
681         pSrcPath->buffer, pSrcPath->length, RTL_TEXTENCODING_UTF8);
682     OString aSrcName (
683         pSrcName->buffer, pSrcName->length, RTL_TEXTENCODING_UTF8);
684 
685     return xManager->symlink (aSrcPath.pData, aSrcName.pData, aDstKey);
686 }
687 
688 /*
689  * store_rename.
690  */
store_rename(storeFileHandle Handle,rtl_uString * pSrcPath,rtl_uString * pSrcName,rtl_uString * pDstPath,rtl_uString * pDstName)691 storeError SAL_CALL store_rename (
692     storeFileHandle Handle,
693     rtl_uString *pSrcPath, rtl_uString *pSrcName,
694     rtl_uString *pDstPath, rtl_uString *pDstName
695 ) SAL_THROW_EXTERN_C()
696 {
697     storeError eErrCode = store_E_None;
698 
699     OStoreHandle<OStorePageManager> xManager (
700         OStoreHandle<OStorePageManager>::query (Handle));
701     if (!xManager.is())
702         return store_E_InvalidHandle;
703 
704     if (!(pSrcPath && pSrcName))
705         return store_E_InvalidParameter;
706 
707     if (!(pDstPath && pDstName))
708         return store_E_InvalidParameter;
709 
710     // Setup 'Source' page key.
711     OString aSrcPath (
712         pSrcPath->buffer, pSrcPath->length, RTL_TEXTENCODING_UTF8);
713     OString aSrcName (
714         pSrcName->buffer, pSrcName->length, RTL_TEXTENCODING_UTF8);
715     OStorePageKey aSrcKey;
716 
717     eErrCode = OStorePageManager::namei (
718         aSrcPath.pData, aSrcName.pData, aSrcKey);
719     if (eErrCode != store_E_None)
720         return eErrCode;
721 
722     // Rename 'Source' into 'Destination'.
723     OString aDstPath (
724         pDstPath->buffer, pDstPath->length, RTL_TEXTENCODING_UTF8);
725     OString aDstName (
726         pDstName->buffer, pDstName->length, RTL_TEXTENCODING_UTF8);
727 
728     return xManager->rename (aSrcKey, aDstPath.pData, aDstName.pData);
729 }
730 
731 /*
732  * store_remove.
733  */
store_remove(storeFileHandle Handle,rtl_uString * pPath,rtl_uString * pName)734 storeError SAL_CALL store_remove (
735     storeFileHandle Handle,
736     rtl_uString    *pPath,
737     rtl_uString    *pName
738 ) SAL_THROW_EXTERN_C()
739 {
740     storeError eErrCode = store_E_None;
741 
742     OStoreHandle<OStorePageManager> xManager (
743         OStoreHandle<OStorePageManager>::query (Handle));
744     if (!xManager.is())
745         return store_E_InvalidHandle;
746 
747     if (!(pPath && pName))
748         return store_E_InvalidParameter;
749 
750     // Setup page key.
751     OString aPath (pPath->buffer, pPath->length, RTL_TEXTENCODING_UTF8);
752     OString aName (pName->buffer, pName->length, RTL_TEXTENCODING_UTF8);
753     OStorePageKey aKey;
754 
755     eErrCode = OStorePageManager::namei (aPath.pData, aName.pData, aKey);
756     if (eErrCode != store_E_None)
757         return eErrCode;
758 
759     // Remove.
760     return xManager->remove (aKey);
761 }
762