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