VirtualBox

source: vbox/trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers-provider-local.cpp@ 103914

Last change on this file since 103914 was 103251, checked in by vboxsync, 10 months ago

Shared Clipboard: More implicit fallthrough fixes (found by Parfait). bugref:3409

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.7 KB
Line 
1/* $Id: clipboard-transfers-provider-local.cpp 103251 2024-02-07 13:16:41Z vboxsync $ */
2/** @file
3 * Shared Clipboard - Transfers interface implementation for local file systems.
4 */
5
6/*
7 * Copyright (C) 2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
33#include <VBox/GuestHost/SharedClipboard-transfers.h>
34
35#include <iprt/dir.h>
36#include <iprt/err.h>
37#include <iprt/file.h>
38#include <iprt/path.h>
39#include <iprt/string.h>
40
41
42/**
43 * Adds a file to a transfer list header.
44 *
45 * @returns VBox status code.
46 * @param pHdr List header to add file to.
47 * @param pszPath Path of file to add.
48 */
49static int shclTransferLocalListHdrAddFile(PSHCLLISTHDR pHdr, const char *pszPath)
50{
51 AssertPtrReturn(pHdr, VERR_INVALID_POINTER);
52 AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
53
54 uint64_t cbSize = 0;
55 int rc = RTFileQuerySizeByPath(pszPath, &cbSize);
56 if (RT_SUCCESS(rc))
57 {
58 pHdr->cbTotalSize += cbSize;
59 pHdr->cEntries++;
60 }
61
62 LogFlowFuncLeaveRC(rc);
63 return rc;
64}
65
66/**
67 * Builds a transfer list header, internal version.
68 *
69 * @returns VBox status code.
70 * @param pHdr Where to store the build list header.
71 * @param pcszPathAbs Absolute path to use for building the transfer list.
72 */
73static int shclTransferLocalListHdrFromDir(PSHCLLISTHDR pHdr, const char *pcszPathAbs)
74{
75 AssertPtrReturn(pcszPathAbs, VERR_INVALID_POINTER);
76
77 LogFlowFunc(("pcszPathAbs=%s\n", pcszPathAbs));
78
79 RTFSOBJINFO objInfo;
80 int rc = RTPathQueryInfo(pcszPathAbs, &objInfo, RTFSOBJATTRADD_NOTHING);
81 if (RT_SUCCESS(rc))
82 {
83 if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode))
84 {
85 RTDIR hDir;
86 rc = RTDirOpen(&hDir, pcszPathAbs);
87 if (RT_SUCCESS(rc))
88 {
89 size_t cbDirEntry = 0;
90 PRTDIRENTRYEX pDirEntry = NULL;
91 do
92 {
93 /* Retrieve the next directory entry. */
94 rc = RTDirReadExA(hDir, &pDirEntry, &cbDirEntry, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
95 if (RT_FAILURE(rc))
96 {
97 if (rc == VERR_NO_MORE_FILES)
98 rc = VINF_SUCCESS;
99 break;
100 }
101
102 switch (pDirEntry->Info.Attr.fMode & RTFS_TYPE_MASK)
103 {
104 case RTFS_TYPE_DIRECTORY:
105 {
106 /* Skip "." and ".." entries. */
107 if (RTDirEntryExIsStdDotLink(pDirEntry))
108 break;
109
110 pHdr->cEntries++;
111 break;
112 }
113 case RTFS_TYPE_FILE:
114 {
115 char *pszSrc = RTPathJoinA(pcszPathAbs, pDirEntry->szName);
116 if (pszSrc)
117 {
118 rc = shclTransferLocalListHdrAddFile(pHdr, pszSrc);
119 RTStrFree(pszSrc);
120 }
121 else
122 rc = VERR_NO_MEMORY;
123 break;
124 }
125 case RTFS_TYPE_SYMLINK:
126 {
127 /** @todo Not implemented yet. */
128 break;
129 }
130
131 default:
132 break;
133 }
134
135 } while (RT_SUCCESS(rc));
136
137 RTDirReadExAFree(&pDirEntry, &cbDirEntry);
138 RTDirClose(hDir);
139 }
140 }
141 else if (RTFS_IS_FILE(objInfo.Attr.fMode))
142 {
143 rc = shclTransferLocalListHdrAddFile(pHdr, pcszPathAbs);
144 }
145 else if (RTFS_IS_SYMLINK(objInfo.Attr.fMode))
146 {
147 /** @todo Not implemented yet. */
148 }
149 else
150 rc = VERR_NOT_SUPPORTED;
151 }
152
153 LogFlowFuncLeaveRC(rc);
154 return rc;
155}
156
157/**
158 * Creates a new list handle (local only).
159 *
160 * @returns New List handle on success, or NIL_SHCLLISTHANDLE on error.
161 * @param pTransfer Clipboard transfer to create new list handle for.
162 */
163DECLINLINE(SHCLLISTHANDLE) shClTransferLocalListHandleNew(PSHCLTRANSFER pTransfer)
164{
165 return pTransfer->uListHandleNext++; /** @todo Good enough for now. Improve this later. */
166}
167
168/**
169 * Queries information about a local list entry.
170 *
171 * @returns VBox status code.
172 * @param pszPathRootAbs Absolute root path to use for the entry.
173 * @param pListEntry List entry to query information for.
174 * @param pFsObjInfo Where to store the queried information on success.
175 */
176static int shClTransferLocalListEntryQueryFsInfo(const char *pszPathRootAbs, PSHCLLISTENTRY pListEntry, PSHCLFSOBJINFO pFsObjInfo)
177{
178 AssertPtrReturn(pszPathRootAbs, VERR_INVALID_POINTER);
179 AssertPtrReturn(pListEntry, VERR_INVALID_POINTER);
180
181 const char *pszSrcPathAbs = RTPathJoinA(pszPathRootAbs, pListEntry->pszName);
182 AssertPtrReturn(pszSrcPathAbs, VERR_NO_MEMORY);
183
184 RTFSOBJINFO fsObjInfo;
185 int rc = RTPathQueryInfo(pszSrcPathAbs, &fsObjInfo, RTFSOBJATTRADD_NOTHING);
186 if (RT_SUCCESS(rc))
187 rc = ShClFsObjInfoFromIPRT(pFsObjInfo, &fsObjInfo);
188
189 return rc;
190}
191
192/** @copydoc SHCLTXPROVIDERIFACE::pfnRootListRead */
193static DECLCALLBACK(int) shclTransferIfaceLocalRootListRead(PSHCLTXPROVIDERCTX pCtx)
194{
195 LogFlowFuncEnter();
196
197 int rc = VINF_SUCCESS;
198
199 PSHCLLISTENTRY pEntry;
200 RTListForEach(&pCtx->pTransfer->lstRoots.lstEntries, pEntry, SHCLLISTENTRY, Node)
201 {
202 AssertBreakStmt(pEntry->cbInfo == sizeof(SHCLFSOBJINFO), rc = VERR_WRONG_ORDER);
203 rc = shClTransferLocalListEntryQueryFsInfo(pCtx->pTransfer->pszPathRootAbs, pEntry, (PSHCLFSOBJINFO)pEntry->pvInfo);
204 if (RT_FAILURE(rc)) /* Currently this is an all-or-nothing op. */
205 break;
206 }
207
208 LogFlowFuncLeaveRC(rc);
209 return rc;
210}
211
212/** @copydoc SHCLTXPROVIDERIFACE::pfnListOpen */
213static DECLCALLBACK(int) shclTransferIfaceLocalListOpen(PSHCLTXPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms,
214 PSHCLLISTHANDLE phList)
215{
216 LogFlowFunc(("pszPath=%s\n", pOpenParms->pszPath));
217
218 int rc;
219
220 PSHCLTRANSFER const pTransfer = pCtx->pTransfer;
221 AssertPtr(pTransfer);
222
223 PSHCLLISTHANDLEINFO pInfo
224 = (PSHCLLISTHANDLEINFO)RTMemAllocZ(sizeof(SHCLLISTHANDLEINFO));
225 if (pInfo)
226 {
227 rc = ShClTransferListHandleInfoInit(pInfo);
228 if (RT_SUCCESS(rc))
229 {
230 rc = ShClTransferResolvePathAbs(pTransfer, pOpenParms->pszPath, 0 /* fFlags */, &pInfo->pszPathLocalAbs);
231 if (RT_SUCCESS(rc))
232 {
233 RTFSOBJINFO objInfo;
234 rc = RTPathQueryInfo(pInfo->pszPathLocalAbs, &objInfo, RTFSOBJATTRADD_NOTHING);
235 if (RT_SUCCESS(rc))
236 {
237 if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode))
238 {
239 rc = RTDirOpen(&pInfo->u.Local.hDir, pInfo->pszPathLocalAbs);
240 if (RT_SUCCESS(rc))
241 {
242 pInfo->enmType = SHCLOBJTYPE_DIRECTORY;
243
244 LogRel2(("Shared Clipboard: Opening directory '%s'\n", pInfo->pszPathLocalAbs));
245 }
246 else
247 LogRel(("Shared Clipboard: Opening directory '%s' failed with %Rrc\n", pInfo->pszPathLocalAbs, rc));
248
249 }
250 else if (RTFS_IS_FILE(objInfo.Attr.fMode))
251 {
252 rc = RTFileOpen(&pInfo->u.Local.hFile, pInfo->pszPathLocalAbs,
253 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
254 if (RT_SUCCESS(rc))
255 {
256 pInfo->enmType = SHCLOBJTYPE_FILE;
257
258 LogRel2(("Shared Clipboard: Opening file '%s'\n", pInfo->pszPathLocalAbs));
259 }
260 else
261 LogRel(("Shared Clipboard: Opening file '%s' failed with %Rrc\n", pInfo->pszPathLocalAbs, rc));
262 }
263 else
264 rc = VERR_NOT_SUPPORTED;
265
266 if (RT_SUCCESS(rc))
267 {
268 pInfo->hList = shClTransferLocalListHandleNew(pTransfer);
269
270 RTListAppend(&pTransfer->lstHandles, &pInfo->Node);
271 pTransfer->cListHandles++;
272
273 if (phList)
274 *phList = pInfo->hList;
275
276 LogFlowFunc(("pszPathLocalAbs=%s, hList=%RU64, cListHandles=%RU32\n",
277 pInfo->pszPathLocalAbs, pInfo->hList, pTransfer->cListHandles));
278 }
279 else
280 {
281 if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode))
282 {
283 if (RTDirIsValid(pInfo->u.Local.hDir))
284 RTDirClose(pInfo->u.Local.hDir);
285 }
286 else if (RTFS_IS_FILE(objInfo.Attr.fMode))
287 {
288 if (RTFileIsValid(pInfo->u.Local.hFile))
289 RTFileClose(pInfo->u.Local.hFile);
290 }
291 }
292 }
293 }
294 }
295
296 if (RT_FAILURE(rc))
297 {
298 ShClTransferListHandleInfoDestroy(pInfo);
299
300 RTMemFree(pInfo);
301 pInfo = NULL;
302 }
303 }
304 else
305 rc = VERR_NO_MEMORY;
306
307 LogFlowFuncLeaveRC(rc);
308 return rc;
309}
310
311/** @copydoc SHCLTXPROVIDERIFACE::pfnListClose */
312static DECLCALLBACK(int) shclTransferIfaceLocalListClose(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList)
313{
314 LogFlowFuncEnter();
315
316 int rc = VINF_SUCCESS;
317
318 PSHCLTRANSFER const pTransfer = pCtx->pTransfer;
319 AssertPtr(pTransfer);
320
321 PSHCLLISTHANDLEINFO pInfo = ShClTransferListGetByHandle(pTransfer, hList);
322 if (pInfo)
323 {
324 switch (pInfo->enmType)
325 {
326 case SHCLOBJTYPE_DIRECTORY:
327 {
328 if (RTDirIsValid(pInfo->u.Local.hDir))
329 {
330 RTDirClose(pInfo->u.Local.hDir);
331 pInfo->u.Local.hDir = NIL_RTDIR;
332 }
333 break;
334 }
335
336 default:
337 rc = VERR_NOT_SUPPORTED;
338 break;
339 }
340
341 RTListNodeRemove(&pInfo->Node);
342
343 Assert(pTransfer->cListHandles);
344 pTransfer->cListHandles--;
345
346 RTMemFree(pInfo);
347 }
348 else
349 rc = VERR_NOT_FOUND;
350
351 LogFlowFuncLeaveRC(rc);
352 return rc;
353}
354
355/** @copydoc SHCLTXPROVIDERIFACE::pfnListHdrRead */
356static DECLCALLBACK(int) shclTransferIfaceLocalListHdrRead(PSHCLTXPROVIDERCTX pCtx,
357 SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr)
358{
359 LogFlowFuncEnter();
360
361 PSHCLTRANSFER const pTransfer = pCtx->pTransfer;
362 AssertPtr(pTransfer);
363
364 int rc;
365
366 PSHCLLISTHANDLEINFO pInfo = ShClTransferListGetByHandle(pTransfer, hList);
367 if (pInfo)
368 {
369 rc = ShClTransferListHdrInit(pListHdr);
370 if (RT_SUCCESS(rc))
371 {
372 switch (pInfo->enmType)
373 {
374 case SHCLOBJTYPE_DIRECTORY:
375 {
376 LogFlowFunc(("DirAbs: %s\n", pInfo->pszPathLocalAbs));
377
378 rc = shclTransferLocalListHdrFromDir(pListHdr, pInfo->pszPathLocalAbs);
379 break;
380 }
381
382 case SHCLOBJTYPE_FILE:
383 {
384 LogFlowFunc(("FileAbs: %s\n", pInfo->pszPathLocalAbs));
385
386 pListHdr->cEntries = 1;
387
388 RTFSOBJINFO objInfo;
389 rc = RTFileQueryInfo(pInfo->u.Local.hFile, &objInfo, RTFSOBJATTRADD_NOTHING);
390 if (RT_SUCCESS(rc))
391 {
392 pListHdr->cbTotalSize = objInfo.cbObject;
393 }
394 break;
395 }
396
397 /* We don't support symlinks (yet). */
398
399 default:
400 rc = VERR_NOT_SUPPORTED;
401 break;
402 }
403 }
404
405 LogFlowFunc(("cTotalObj=%RU64, cbTotalSize=%RU64\n", pListHdr->cEntries, pListHdr->cbTotalSize));
406 }
407 else
408 rc = VERR_NOT_FOUND;
409
410 LogFlowFuncLeaveRC(rc);
411 return rc;
412}
413
414/**
415 * Initializes a local list entry.
416 *
417 * @returns VBox status code.
418 * @param pEntry List entry to init.
419 * @param pszName File name to use.
420 * @param pObjInfo Object information to use.
421 */
422static int shclTransferIfaceLocalListEntryInit(PSHCLLISTENTRY pEntry, const char *pszName, PRTFSOBJINFO pObjInfo)
423{
424 PSHCLFSOBJINFO pFsObjInfo = (PSHCLFSOBJINFO)RTMemAllocZ(sizeof(SHCLFSOBJINFO));
425 AssertPtrReturn(pFsObjInfo, VERR_NO_MEMORY);
426
427 int rc = ShClFsObjInfoFromIPRT(pFsObjInfo, pObjInfo);
428 if (RT_SUCCESS(rc))
429 {
430 rc = ShClTransferListEntryInitEx(pEntry, VBOX_SHCL_INFO_F_FSOBJINFO, pszName, pFsObjInfo, sizeof(SHCLFSOBJINFO));
431 /* pEntry has taken ownership of pFsObjInfo on success. */
432 }
433
434 if (RT_FAILURE(rc))
435 {
436 RTMemFree(pFsObjInfo);
437 pFsObjInfo = NULL;
438 }
439
440 if (RT_FAILURE(rc))
441 LogRel(("Shared Clipboard: Initializing list entry '%s' failed: %Rrc\n", pszName, rc));
442
443 return rc;
444}
445
446/** @copydoc SHCLTXPROVIDERIFACE::pfnListEntryRead */
447static DECLCALLBACK(int) shclTransferIfaceLocalListEntryRead(PSHCLTXPROVIDERCTX pCtx,
448 SHCLLISTHANDLE hList, PSHCLLISTENTRY pEntry)
449{
450 LogFlowFuncEnter();
451
452 int rc;
453
454 PSHCLTRANSFER const pTransfer = pCtx->pTransfer;
455 AssertPtr(pTransfer);
456
457 PSHCLLISTHANDLEINFO pInfo = ShClTransferListGetByHandle(pTransfer, hList);
458 if (pInfo)
459 {
460 switch (pInfo->enmType)
461 {
462 case SHCLOBJTYPE_DIRECTORY:
463 {
464 LogFlowFunc(("\tDirectory: %s\n", pInfo->pszPathLocalAbs));
465
466 for (;;)
467 {
468 bool fSkipEntry = false; /* Whether to skip an entry in the enumeration. */
469
470 size_t cbDirEntry = 0;
471 PRTDIRENTRYEX pDirEntry = NULL;
472 rc = RTDirReadExA(pInfo->u.Local.hDir, &pDirEntry, &cbDirEntry, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
473 if (RT_SUCCESS(rc))
474 {
475 switch (pDirEntry->Info.Attr.fMode & RTFS_TYPE_MASK)
476 {
477 case RTFS_TYPE_DIRECTORY:
478 {
479 /* Skip "." and ".." entries. */
480 if (RTDirEntryExIsStdDotLink(pDirEntry))
481 {
482 fSkipEntry = true;
483 break;
484 }
485
486 LogFlowFunc(("Directory: %s\n", pDirEntry->szName));
487 break;
488 }
489
490 case RTFS_TYPE_FILE:
491 {
492 LogFlowFunc(("File: %s\n", pDirEntry->szName));
493 break;
494 }
495
496 case RTFS_TYPE_SYMLINK:
497 {
498 rc = VERR_NOT_IMPLEMENTED; /** @todo Not implemented yet. */
499 break;
500 }
501
502 default:
503 break;
504 }
505
506 if ( RT_SUCCESS(rc)
507 && !fSkipEntry)
508 rc = shclTransferIfaceLocalListEntryInit(pEntry, pDirEntry->szName, &pDirEntry->Info);
509
510 RTDirReadExAFree(&pDirEntry, &cbDirEntry);
511 }
512
513 if ( !fSkipEntry /* Do we have a valid entry? Bail out. */
514 || RT_FAILURE(rc))
515 {
516 break;
517 }
518 }
519
520 break;
521 }
522
523 case SHCLOBJTYPE_FILE:
524 {
525 LogFlowFunc(("\tSingle file: %s\n", pInfo->pszPathLocalAbs));
526
527 RTFSOBJINFO objInfo;
528 rc = RTFileQueryInfo(pInfo->u.Local.hFile, &objInfo, RTFSOBJATTRADD_NOTHING);
529 if (RT_SUCCESS(rc))
530 rc = shclTransferIfaceLocalListEntryInit(pEntry, pInfo->pszPathLocalAbs, &objInfo);
531
532 break;
533 }
534
535 default:
536 rc = VERR_NOT_SUPPORTED;
537 break;
538 }
539 }
540 else
541 rc = VERR_NOT_FOUND;
542
543 LogFlowFuncLeaveRC(rc);
544 return rc;
545}
546
547/** @copydoc SHCLTXPROVIDERIFACE::pfnObjOpen */
548static DECLCALLBACK(int) shclTransferIfaceLocalObjOpen(PSHCLTXPROVIDERCTX pCtx,
549 PSHCLOBJOPENCREATEPARMS pCreateParms, PSHCLOBJHANDLE phObj)
550{
551 LogFlowFuncEnter();
552
553 int rc;
554
555 PSHCLTRANSFER const pTransfer = pCtx->pTransfer;
556 AssertPtr(pTransfer);
557
558 PSHCLTRANSFEROBJ pInfo = (PSHCLTRANSFEROBJ)RTMemAllocZ(sizeof(SHCLTRANSFEROBJ));
559 if (pInfo)
560 {
561 rc = ShClTransferObjInit(pInfo);
562 if (RT_SUCCESS(rc))
563 {
564 uint64_t fOpen = 0; /* Shut up GCC. */
565 rc = ShClTransferConvertFileCreateFlags(pCreateParms->fCreate, &fOpen);
566 if (RT_SUCCESS(rc))
567 {
568 rc = ShClTransferResolvePathAbs(pTransfer, pCreateParms->pszPath, 0 /* fFlags */,
569 &pInfo->pszPathLocalAbs);
570 if (RT_SUCCESS(rc))
571 {
572 rc = RTFileOpen(&pInfo->u.Local.hFile, pInfo->pszPathLocalAbs, fOpen);
573 if (RT_SUCCESS(rc))
574 LogRel2(("Shared Clipboard: Opened file '%s'\n", pInfo->pszPathLocalAbs));
575 else
576 LogRel(("Shared Clipboard: Error opening file '%s': rc=%Rrc\n", pInfo->pszPathLocalAbs, rc));
577 }
578 }
579 }
580
581 if (RT_SUCCESS(rc))
582 {
583 pInfo->hObj = pTransfer->uObjHandleNext++;
584 pInfo->enmType = SHCLOBJTYPE_FILE;
585
586 RTListAppend(&pTransfer->lstObj, &pInfo->Node);
587 pTransfer->cObjHandles++;
588
589 LogFlowFunc(("cObjHandles=%RU32\n", pTransfer->cObjHandles));
590
591 *phObj = pInfo->hObj;
592 }
593 else
594 {
595 ShClTransferObjDestroy(pInfo);
596 RTMemFree(pInfo);
597 }
598 }
599 else
600 rc = VERR_NO_MEMORY;
601
602 LogFlowFuncLeaveRC(rc);
603 return rc;
604}
605
606/** @copydoc SHCLTXPROVIDERIFACE::pfnObjClose */
607static DECLCALLBACK(int) shclTransferIfaceLocalObjClose(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj)
608{
609 LogFlowFuncEnter();
610
611 int rc;
612
613 PSHCLTRANSFER const pTransfer = pCtx->pTransfer;
614 AssertPtr(pTransfer);
615
616 PSHCLTRANSFEROBJ pInfo = ShClTransferObjGet(pTransfer, hObj);
617 if (pInfo)
618 {
619 switch (pInfo->enmType)
620 {
621 case SHCLOBJTYPE_DIRECTORY:
622 {
623 rc = RTDirClose(pInfo->u.Local.hDir);
624 if (RT_SUCCESS(rc))
625 {
626 pInfo->u.Local.hDir = NIL_RTDIR;
627
628 LogRel2(("Shared Clipboard: Closed directory '%s'\n", pInfo->pszPathLocalAbs));
629 }
630 else
631 LogRel(("Shared Clipboard: Closing directory '%s' failed with %Rrc\n", pInfo->pszPathLocalAbs, rc));
632 break;
633 }
634
635 case SHCLOBJTYPE_FILE:
636 {
637 rc = RTFileClose(pInfo->u.Local.hFile);
638 if (RT_SUCCESS(rc))
639 {
640 pInfo->u.Local.hFile = NIL_RTFILE;
641
642 LogRel2(("Shared Clipboard: Closed file '%s'\n", pInfo->pszPathLocalAbs));
643 }
644 else
645 LogRel(("Shared Clipboard: Closing file '%s' failed with %Rrc\n", pInfo->pszPathLocalAbs, rc));
646 break;
647 }
648
649 default:
650 rc = VERR_NOT_IMPLEMENTED;
651 break;
652 }
653
654 RTListNodeRemove(&pInfo->Node);
655
656 Assert(pTransfer->cObjHandles);
657 pTransfer->cObjHandles--;
658
659 ShClTransferObjDestroy(pInfo);
660
661 RTMemFree(pInfo);
662 pInfo = NULL;
663 }
664 else
665 rc = VERR_NOT_FOUND;
666
667 LogFlowFuncLeaveRC(rc);
668 return rc;
669}
670
671/** @copydoc SHCLTXPROVIDERIFACE::pfnObjRead */
672static DECLCALLBACK(int) shclTransferIfaceLocalObjRead(PSHCLTXPROVIDERCTX pCtx,
673 SHCLOBJHANDLE hObj, void *pvData, uint32_t cbData,
674 uint32_t fFlags, uint32_t *pcbRead)
675{
676 RT_NOREF(fFlags);
677
678 LogFlowFuncEnter();
679
680 int rc;
681
682 PSHCLTRANSFER const pTransfer = pCtx->pTransfer;
683 AssertPtr(pTransfer);
684
685 PSHCLTRANSFEROBJ pInfo = ShClTransferObjGet(pTransfer, hObj);
686 if (pInfo)
687 {
688 switch (pInfo->enmType)
689 {
690 case SHCLOBJTYPE_FILE:
691 {
692 size_t cbRead;
693 rc = RTFileRead(pInfo->u.Local.hFile, pvData, cbData, &cbRead);
694 if (RT_SUCCESS(rc))
695 {
696 if (pcbRead)
697 *pcbRead = (uint32_t)cbRead;
698 }
699 break;
700 }
701
702 default:
703 rc = VERR_NOT_SUPPORTED;
704 break;
705 }
706 }
707 else
708 rc = VERR_NOT_FOUND;
709
710 LogFlowFuncLeaveRC(rc);
711 return rc;
712}
713
714/** @copydoc SHCLTXPROVIDERIFACE::pfnObjWrite */
715static DECLCALLBACK(int) shclTransferIfaceLocalObjWrite(PSHCLTXPROVIDERCTX pCtx,
716 SHCLOBJHANDLE hObj, void *pvData, uint32_t cbData, uint32_t fFlags,
717 uint32_t *pcbWritten)
718{
719 RT_NOREF(fFlags);
720
721 LogFlowFuncEnter();
722
723 int rc;
724
725 PSHCLTRANSFER const pTransfer = pCtx->pTransfer;
726 AssertPtr(pTransfer);
727
728 PSHCLTRANSFEROBJ pInfo = ShClTransferObjGet(pTransfer, hObj);
729 if (pInfo)
730 {
731 switch (pInfo->enmType)
732 {
733 case SHCLOBJTYPE_FILE:
734 {
735 rc = RTFileWrite(pInfo->u.Local.hFile, pvData, cbData, (size_t *)pcbWritten);
736 break;
737 }
738
739 default:
740 rc = VERR_NOT_SUPPORTED;
741 break;
742 }
743 }
744 else
745 rc = VERR_NOT_FOUND;
746
747 LogFlowFuncLeaveRC(rc);
748 return rc;
749}
750
751/**
752 * Queries (assigns) the local provider to an interface.
753 *
754 * The local provider is being used for accessing files on local file systems.
755 *
756 * @returns Interface pointer assigned to the provider.
757 * @param pProvider Provider to assign interface to.
758 */
759PSHCLTXPROVIDERIFACE ShClTransferProviderLocalQueryInterface(PSHCLTXPROVIDER pProvider)
760{
761 pProvider->Interface.pfnRootListRead = shclTransferIfaceLocalRootListRead;
762 pProvider->Interface.pfnListOpen = shclTransferIfaceLocalListOpen;
763 pProvider->Interface.pfnListClose = shclTransferIfaceLocalListClose;
764 pProvider->Interface.pfnListHdrRead = shclTransferIfaceLocalListHdrRead;
765 pProvider->Interface.pfnListEntryRead = shclTransferIfaceLocalListEntryRead;
766 pProvider->Interface.pfnObjOpen = shclTransferIfaceLocalObjOpen;
767 pProvider->Interface.pfnObjClose = shclTransferIfaceLocalObjClose;
768 pProvider->Interface.pfnObjRead = shclTransferIfaceLocalObjRead;
769 pProvider->Interface.pfnObjWrite = shclTransferIfaceLocalObjWrite;
770
771 return &pProvider->Interface;
772}
773
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette