Changeset 78725 in vbox for trunk/src/VBox/Additions/common
- Timestamp:
- May 24, 2019 1:15:59 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp
r78684 r78725 36 36 #include <VBox/err.h> 37 37 #include <iprt/assert.h> 38 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 39 # include <iprt/dir.h> 40 # include <iprt/file.h> 41 # include <iprt/path.h> 42 #endif 38 43 #include <iprt/string.h> 39 44 #include <iprt/cpp/ministring.h> 45 40 46 #include "VBoxGuestR3LibInternal.h" 41 47 … … 45 51 *********************************************************************************************************************************/ 46 52 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 47 static int vbglR3ClipboardSendErrorInternal(HGCMCLIENTID idClient, int rcErr); 48 static int vbglR3ClipboardSendURIData(HGCMCLIENTID idClient, const void *pvData, size_t cbData); 53 static int vbglR3ClipboardWriteErrorInternal(HGCMCLIENTID idClient, int rcErr); 54 static int vbglR3ClipboardReadURIData(HGCMCLIENTID idClient, PVBOXCLIPBOARDDATAHDR pDataHdr); 55 static int vbglR3ClipboardWriteURIData(HGCMCLIENTID idClient, const void *pvData, size_t cbData); 49 56 #endif 50 57 … … 154 161 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 155 162 /** 156 * Reads the metadata header from the host.163 * Reads a (meta) data header from the host. 157 164 * 158 165 * @returns IPRT status code. … … 160 167 * @param pDataHdr Where to store the read meta data header. 161 168 */ 162 static int vbglR3ClipboardRead MetaDataHdr(HGCMCLIENTID idClient, PVBOXDNDSNDDATAHDR pDataHdr)169 static int vbglR3ClipboardReadDataHdr(HGCMCLIENTID idClient, PVBOXCLIPBOARDDATAHDR pDataHdr) 163 170 { 164 171 AssertPtrReturn(pDataHdr, VERR_INVALID_POINTER); 165 172 166 VB OXDNDHGSENDDATAHDRMSGMsg;173 VBoxClipboardReadDataHdrMsg Msg; 167 174 RT_ZERO(Msg); 168 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, HOST_DND_HG_SND_DATA_HDR, 12); 175 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, 176 VBOX_SHARED_CLIPBOARD_FN_READ_DATA_HDR, VBOX_SHARED_CLIPBOARD_CPARMS_READ_DATA_HDR); 169 177 Msg.uContext.SetUInt32(0); 170 178 Msg.uFlags.SetUInt32(0); … … 200 208 201 209 /** 202 * Helper function for reading the actual clipboard meta data from the host. Do not call directly. 210 * Reads a (meta) data chunk from the host. 211 * 212 * @returns IPRT status code. 213 * @param idClient The client id returned by VbglR3ClipboardConnect(). 214 * @param pDataHdr Data header to use. Need for accounting and stuff. 215 * @param pvData Where to store the received data from the host. 216 * @param cbData Size (in bytes) of where to store the received data. 217 * @param pcbDataRecv Where to store the received amount of data (in bytes). 218 */ 219 static int vbglR3ClipboardReadDataChunk(HGCMCLIENTID idClient, PVBOXCLIPBOARDDATAHDR pDataHdr, 220 void *pvData, uint32_t cbData, uint32_t *pcbDataRecv) 221 { 222 AssertPtrReturn(pDataHdr, VERR_INVALID_POINTER); 223 AssertPtrReturn(pvData, VERR_INVALID_POINTER); 224 AssertReturn(cbData, VERR_INVALID_PARAMETER); 225 AssertPtrNullReturn(pcbDataRecv, VERR_INVALID_POINTER); 226 227 LogFlowFunc(("pvDate=%p, cbData=%RU32\n", pvData, cbData)); 228 229 VBoxClipboardReadDataChunkMsg Msg; 230 RT_ZERO(Msg); 231 232 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, 233 VBOX_SHARED_CLIPBOARD_FN_READ_DATA_CHUNK, VBOX_SHARED_CLIPBOARD_CPARMS_READ_DATA_CHUNK); 234 Msg.pvData.SetPtr(pvData, cbData); 235 Msg.cbData.SetUInt32(0); 236 Msg.pvChecksum.SetPtr(NULL, 0); 237 Msg.cbChecksum.SetUInt32(0); 238 239 int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg)); 240 if (RT_SUCCESS(rc)) 241 { 242 uint32_t cbDataRecv; 243 rc = Msg.cbData.GetUInt32(&cbDataRecv); 244 AssertRC(rc); 245 if (RT_SUCCESS(rc)) 246 { 247 /** @todo Use checksum for validating the received data. */ 248 if (pcbDataRecv) 249 *pcbDataRecv = cbDataRecv; 250 LogFlowFuncLeaveRC(rc); 251 return rc; 252 } 253 } 254 255 /* failure */ 256 LogFlowFuncLeaveRC(rc); 257 return rc; 258 } 259 260 /** 261 * Helper function for reading the actual clipboard (meta) data from the host. Do not call directly. 203 262 * 204 263 * @returns IPRT status code. … … 208 267 * @param pcbData Where to store the size (in bytes) of the received meta data. 209 268 */ 210 static int vbglR3ClipboardReadMetaDataLoop(HGCMCLIENTID idClient, PVBOX DNDSNDDATAHDR pDataHdr,269 static int vbglR3ClipboardReadMetaDataLoop(HGCMCLIENTID idClient, PVBOXCLIPBOARDDATAHDR pDataHdr, 211 270 void **ppvData, uint64_t *pcbData) 212 271 { … … 220 279 LogFlowFuncEnter(); 221 280 222 rc = vbglR3 DnDHGRecvDataHdr(pCtx, pDataHdr);281 rc = vbglR3ClipboardReadDataHdr(idClient, pDataHdr); 223 282 if (RT_FAILURE(rc)) 224 283 return rc; … … 234 293 if (RT_SUCCESS(rc)) 235 294 { 295 const uint32_t cbMaxChunkSize = VBOX_SHARED_CLIPBOARD_MAX_CHUNK_SIZE; 296 236 297 uint8_t *pvDataOff = (uint8_t *)pvDataTmp; 237 298 while (cbDataTmp < pDataHdr->cbMeta) 238 299 { 239 rc = vbglR3 DnDHGRecvDataRaw(pCtx, pDataHdr,240 pvDataOff, RT_MIN(pDataHdr->cbMeta - cbDataTmp, pCtx->cbMaxChunkSize),241 &cbDataRecv);300 rc = vbglR3ClipboardReadDataChunk(idClient, pDataHdr, 301 pvDataOff, RT_MIN(pDataHdr->cbMeta - cbDataTmp, cbMaxChunkSize), 302 &cbDataRecv); 242 303 if (RT_SUCCESS(rc)) 243 304 { … … 290 351 /* The rest is optional. */ 291 352 292 VBOX DNDDATAHDR dataHdr;353 VBOXCLIPBOARDDATAHDR dataHdr; 293 354 RT_ZERO(dataHdr); 294 355 295 AssertMsg(pCtx->cbMaxChunkSize, ("Maximum chunk size must not be 0\n")); 296 297 dataHdr.cbMetaFmt = pCtx->cbMaxChunkSize; 356 dataHdr.cbMetaFmt = VBOX_SHARED_CLIPBOARD_MAX_CHUNK_SIZE; 298 357 dataHdr.pvMetaFmt = RTMemAlloc(dataHdr.cbMetaFmt); 299 358 if (!dataHdr.pvMetaFmt) 300 359 return VERR_NO_MEMORY; 301 360 302 DnDURIList lstURI; 303 DnDDroppedFiles droppedFiles; 361 SharedClipboardURIList lstURI; 304 362 305 363 void *pvData = NULL; 306 364 uint64_t cbData = 0; 307 365 308 int rc = vbglR3 DnDHGRecvDataLoop(pCtx, &dataHdr, &pvData, &cbData);366 int rc = vbglR3ClipboardReadMetaDataLoop(idClient, &dataHdr, &pvData, &cbData); 309 367 if (RT_SUCCESS(rc)) 310 368 { … … 319 377 Assert(dataHdr.cbMetaFmt); 320 378 AssertPtr(dataHdr.pvMetaFmt); 321 if ( DnDMIMEHasFileURLs((char *)dataHdr.pvMetaFmt, dataHdr.cbMetaFmt)) /* URI data. */379 if (SharedClipboardMIMEHasFileURLs((char *)dataHdr.pvMetaFmt, dataHdr.cbMetaFmt)) /* URI data. */ 322 380 { 323 381 AssertPtr(pvData); … … 326 384 rc = lstURI.SetFromURIData(pvData, cbData, 0 /* fFlags */); 327 385 if (RT_SUCCESS(rc)) 328 rc = vbglR3 DnDHGRecvURIData(pCtx, &dataHdr, &droppedFiles);386 rc = vbglR3ClipboardReadURIData(idClient, &dataHdr); 329 387 330 388 if (RT_SUCCESS(rc)) /** @todo Remove this block as soon as we hand in DnDURIList. */ … … 337 395 } 338 396 339 RTCString strData = lstURI.GetRootEntries(droppedFiles.GetDirAbs()); 397 #if 0 398 RTCString strData = lstURI.GetRootEntries(clipboardCache.GetDirAbs()); 340 399 Assert(!strData.isEmpty()); 341 400 … … 353 412 else 354 413 rc = VERR_NO_MEMORY; 414 #endif 355 415 } 356 416 } … … 383 443 if (pvData) 384 444 RTMemFree(pvData); 385 386 int rc2 = VbglR3DnDHGSendProgress(pCtx, DND_PROGRESS_ERROR, 100 /* Percent */, rc);387 if (RT_FAILURE(rc2))388 LogFlowFunc(("Unable to send progress error %Rrc to host: %Rrc\n", rc, rc2));389 445 } 390 446 … … 409 465 &pMeta->cbMeta); 410 466 return rc; 467 } 468 469 /** 470 * Utility function to read a directory entry from the host. 471 * 472 * @returns IPRT status code. 473 * @param idClient The client id returned by VbglR3ClipboardConnect(). 474 * @param pszDirname Where to store the directory name of the directory being created. 475 * @param cbDirname Size (in bytes) of where to store the directory name of the directory being created. 476 * @param pcbDirnameRecv Size (in bytes) of the actual directory name received. 477 * @param pfMode Where to store the directory creation mode. 478 */ 479 static int vbglR3ClipboardReadDir(HGCMCLIENTID idClient, 480 char *pszDirname, 481 uint32_t cbDirname, 482 uint32_t *pcbDirnameRecv, 483 uint32_t *pfMode) 484 { 485 AssertPtrReturn(pszDirname, VERR_INVALID_POINTER); 486 AssertReturn(cbDirname, VERR_INVALID_PARAMETER); 487 AssertPtrReturn(pcbDirnameRecv, VERR_INVALID_POINTER); 488 AssertPtrReturn(pfMode, VERR_INVALID_POINTER); 489 490 VBoxClipboardReadDirMsg Msg; 491 RT_ZERO(Msg); 492 493 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHARED_CLIPBOARD_FN_READ_DIR, VBOX_SHARED_CLIPBOARD_CPARMS_READ_DIR); 494 /** @todo Context ID not used yet. */ 495 Msg.uContext.SetUInt32(0); 496 Msg.pvName.SetPtr(pszDirname, cbDirname); 497 Msg.cbName.SetUInt32(cbDirname); 498 Msg.fMode.SetUInt32(0); 499 500 int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg)); 501 if (RT_SUCCESS(rc)) 502 { 503 /** @todo Context ID not used yet. */ 504 rc = Msg.cbName.GetUInt32(pcbDirnameRecv); AssertRC(rc); 505 rc = Msg.fMode.GetUInt32(pfMode); AssertRC(rc); 506 507 AssertReturn(cbDirname >= *pcbDirnameRecv, VERR_TOO_MUCH_DATA); 508 } 509 510 return rc; 511 } 512 513 /** 514 * Utility function to receive a file header from the host. 515 * 516 * @returns IPRT status code. 517 * @param idClient The client id returned by VbglR3ClipboardConnect(). 518 * @param pszFilename Where to store the file name of the file being transferred. 519 * @param cbFilename Size (in bytes) of where to store the file name of the file being transferred. 520 * @param puFlags File transfer flags. Currently not being used. 521 * @param pfMode Where to store the file creation mode. 522 * @param pcbTotal Where to store the file size (in bytes). 523 */ 524 static int vbglR3ClipboardReadFileHdr(HGCMCLIENTID idClient, 525 char *pszFilename, 526 uint32_t cbFilename, 527 uint32_t *puFlags, 528 uint32_t *pfMode, 529 uint64_t *pcbTotal) 530 { 531 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER); 532 AssertReturn(cbFilename, VERR_INVALID_PARAMETER); 533 AssertPtrReturn(puFlags, VERR_INVALID_POINTER); 534 AssertPtrReturn(pfMode, VERR_INVALID_POINTER); 535 AssertReturn(pcbTotal, VERR_INVALID_POINTER); 536 537 VBoxClipboardReadFileHdrMsg Msg; 538 RT_ZERO(Msg); 539 540 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, 541 VBOX_SHARED_CLIPBOARD_FN_READ_FILE_HDR, VBOX_SHARED_CLIPBOARD_CPARMS_READ_FILE_HDR); 542 Msg.uContext.SetUInt32(0); /** @todo Not used yet. */ 543 Msg.pvName.SetPtr(pszFilename, cbFilename); 544 Msg.cbName.SetUInt32(cbFilename); 545 Msg.uFlags.SetUInt32(0); 546 Msg.fMode.SetUInt32(0); 547 Msg.cbTotal.SetUInt64(0); 548 549 int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg)); 550 if (RT_SUCCESS(rc)) 551 { 552 /** @todo Get context ID. */ 553 rc = Msg.uFlags.GetUInt32(puFlags); AssertRC(rc); 554 rc = Msg.fMode.GetUInt32(pfMode); AssertRC(rc); 555 rc = Msg.cbTotal.GetUInt64(pcbTotal); AssertRC(rc); 556 } 557 558 return rc; 559 } 560 561 /** 562 * Utility function to receive a file data chunk from the host. 563 * 564 * @returns IPRT status code. 565 * @param idClient The client id returned by VbglR3ClipboardConnect(). 566 * @param pvData Where to store the file data chunk. 567 * @param cbData Size (in bytes) of where to store the data chunk. 568 * @param pcbDataRecv Size (in bytes) of the actual data chunk size received. 569 */ 570 static int vbglR3ClipboardReadFileData(HGCMCLIENTID idClient, 571 void *pvData, 572 uint32_t cbData, 573 uint32_t *pcbDataRecv) 574 { 575 AssertPtrReturn(pvData, VERR_INVALID_POINTER); 576 AssertReturn(cbData, VERR_INVALID_PARAMETER); 577 AssertPtrReturn(pcbDataRecv, VERR_INVALID_POINTER); 578 579 VBoxClipboardReadFileDataMsg Msg; 580 RT_ZERO(Msg); 581 582 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, 583 VBOX_SHARED_CLIPBOARD_FN_READ_FILE_DATA, VBOX_SHARED_CLIPBOARD_CPARMS_READ_FILE_DATA); 584 Msg.uContext.SetUInt32(0); 585 Msg.pvData.SetPtr(pvData, cbData); 586 Msg.cbData.SetUInt32(0); 587 Msg.pvChecksum.SetPtr(NULL, 0); 588 Msg.cbChecksum.SetUInt32(0); 589 590 int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg)); 591 if (RT_SUCCESS(rc)) 592 { 593 /** @todo Context ID not used yet. */ 594 rc = Msg.cbData.GetUInt32(pcbDataRecv); AssertRC(rc); 595 AssertReturn(cbData >= *pcbDataRecv, VERR_TOO_MUCH_DATA); 596 /** @todo Add checksum support. */ 597 } 598 599 return rc; 600 } 601 602 /** 603 * Helper function for receiving URI data from the host. Do not call directly. 604 * This function also will take care of the file creation / locking on the guest. 605 * 606 * @returns IPRT status code. 607 * @param idClient The client id returned by VbglR3ClipboardConnect(). 608 * @param pDataHdr Data header to use. Needed for accounting. 609 */ 610 static int vbglR3ClipboardReadURIData(HGCMCLIENTID idClient, PVBOXCLIPBOARDDATAHDR pDataHdr) 611 { 612 AssertPtrReturn(pDataHdr, VERR_INVALID_POINTER); 613 614 RT_NOREF(idClient, pDataHdr); 615 616 #if 0 617 618 /* Only count the raw data minus the already received meta data. */ 619 Assert(pDataHdr->cbTotal >= pDataHdr->cbMeta); 620 uint64_t cbToRecvBytes = pDataHdr->cbTotal - pDataHdr->cbMeta; 621 uint64_t cToRecvObjs = pDataHdr->cObjects; 622 623 LogFlowFunc(("cbToRecvBytes=%RU64, cToRecvObjs=%RU64, (cbTotal=%RU64, cbMeta=%RU32)\n", 624 cbToRecvBytes, cToRecvObjs, pDataHdr->cbTotal, pDataHdr->cbMeta)); 625 626 /* Anything to do at all? */ 627 /* Note: Do not check for cbToRecvBytes == 0 here, as this might be just 628 * a bunch of 0-byte files to be transferred. */ 629 if (!cToRecvObjs) 630 return VINF_SUCCESS; 631 632 /* 633 * Allocate temporary chunk buffer. 634 */ 635 uint32_t cbChunkMax = VBOX_SHARED_CLIPBOARD_MAX_CHUNK_SIZE; 636 void *pvChunk = RTMemAlloc(cbChunkMax); 637 if (!pvChunk) 638 return VERR_NO_MEMORY; 639 uint32_t cbChunkRead = 0; 640 641 uint64_t cbFileSize = 0; /* Total file size (in bytes). */ 642 uint64_t cbFileWritten = 0; /* Written bytes. */ 643 644 char *pszDropDir = NULL; 645 646 int rc; 647 648 /* 649 * Enter the main loop of retieving files + directories. 650 */ 651 SharedClipboardURIObject objFile(SharedClipboardURIObject::Type_File); 652 653 char szPathName[RTPATH_MAX] = { 0 }; 654 uint32_t cbPathName = 0; 655 uint32_t fFlags = 0; 656 uint32_t fMode = 0; 657 658 do 659 { 660 LogFlowFunc(("Wating for new message ...\n")); 661 662 uint32_t uNextMsg; 663 uint32_t cNextParms; 664 rc = vbglR3DnDGetNextMsgType(idClient, &uNextMsg, &cNextParms, true /* fWait */); 665 if (RT_SUCCESS(rc)) 666 { 667 LogFlowFunc(("uNextMsg=%RU32, cNextParms=%RU32\n", uNextMsg, cNextParms)); 668 669 switch (uNextMsg) 670 { 671 case HOST_DND_HG_SND_DIR: 672 { 673 rc = vbglR3ClipboardReadDir(idClient, 674 szPathName, 675 sizeof(szPathName), 676 &cbPathName, 677 &fMode); 678 LogFlowFunc(("HOST_DND_HG_SND_DIR pszPathName=%s, cbPathName=%RU32, fMode=0x%x, rc=%Rrc\n", 679 szPathName, cbPathName, fMode, rc)); 680 681 char *pszPathAbs = RTPathJoinA(pszDropDir, szPathName); 682 if (pszPathAbs) 683 { 684 #ifdef RT_OS_WINDOWS 685 uint32_t fCreationMode = (fMode & RTFS_DOS_MASK) | RTFS_DOS_NT_NORMAL; 686 #else 687 uint32_t fCreationMode = (fMode & RTFS_UNIX_MASK) | RTFS_UNIX_IRWXU; 688 #endif 689 rc = RTDirCreate(pszPathAbs, fCreationMode, 0); 690 /*if (RT_SUCCESS(rc)) 691 rc = pDroppedFiles->AddDir(pszPathAbs);*/ 692 693 if (RT_SUCCESS(rc)) 694 { 695 Assert(cToRecvObjs); 696 cToRecvObjs--; 697 } 698 699 RTStrFree(pszPathAbs); 700 } 701 else 702 rc = VERR_NO_MEMORY; 703 break; 704 } 705 case HOST_DND_HG_SND_FILE_HDR: 706 case HOST_DND_HG_SND_FILE_DATA: 707 { 708 if (uNextMsg == HOST_DND_HG_SND_FILE_HDR) 709 { 710 rc = vbglR3ClipboardReadFileHdr(idClient, 711 szPathName, 712 sizeof(szPathName), 713 &fFlags, 714 &fMode, 715 &cbFileSize); 716 LogFlowFunc(("HOST_DND_HG_SND_FILE_HDR: " 717 "szPathName=%s, fFlags=0x%x, fMode=0x%x, cbFileSize=%RU64, rc=%Rrc\n", 718 szPathName, fFlags, fMode, cbFileSize, rc)); 719 } 720 else 721 { 722 rc = vbglR3ClipboardReadFileData(idClient, 723 pvChunk, 724 cbChunkMax, 725 &cbChunkRead); 726 LogFlowFunc(("HOST_DND_HG_SND_FILE_DATA: " 727 "cbChunkRead=%RU32, rc=%Rrc\n", cbChunkRead, rc)); 728 } 729 730 if ( RT_SUCCESS(rc) 731 && uNextMsg == HOST_DND_HG_SND_FILE_HDR) 732 { 733 char *pszPathAbs = RTPathJoinA(pszDropDir, szPathName); 734 if (pszPathAbs) 735 { 736 LogFlowFunc(("Opening pszPathName=%s, cbPathName=%RU32, fMode=0x%x, cbFileSize=%zu\n", 737 szPathName, cbPathName, fMode, cbFileSize)); 738 739 uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_WRITE 740 | RTFILE_O_CREATE_REPLACE; 741 742 /* Is there already a file open, e.g. in transfer? */ 743 if (!objFile.IsOpen()) 744 { 745 RTCString strPathAbs(pszPathAbs); 746 #ifdef RT_OS_WINDOWS 747 uint32_t fCreationMode = (fMode & RTFS_DOS_MASK) | RTFS_DOS_NT_NORMAL; 748 #else 749 uint32_t fCreationMode = (fMode & RTFS_UNIX_MASK) | RTFS_UNIX_IRUSR | RTFS_UNIX_IWUSR; 750 #endif 751 rc = objFile.OpenEx(strPathAbs, SharedClipboardURIObject::View_Target, fOpen, fCreationMode); 752 if (RT_SUCCESS(rc)) 753 { 754 //rc = pDroppedFiles->AddFile(strPathAbs.c_str()); 755 if (RT_SUCCESS(rc)) 756 { 757 cbFileWritten = 0; 758 objFile.SetSize(cbFileSize); 759 } 760 } 761 } 762 else 763 { 764 AssertMsgFailed(("ObjType=%RU32\n", objFile.GetType())); 765 rc = VERR_WRONG_ORDER; 766 } 767 768 RTStrFree(pszPathAbs); 769 } 770 else 771 rc = VERR_NO_MEMORY; 772 } 773 774 if ( RT_SUCCESS(rc) 775 && uNextMsg == HOST_DND_HG_SND_FILE_DATA 776 && cbChunkRead) 777 { 778 uint32_t cbChunkWritten; 779 rc = objFile.Write(pvChunk, cbChunkRead, &cbChunkWritten); 780 if (RT_SUCCESS(rc)) 781 { 782 LogFlowFunc(("HOST_DND_HG_SND_FILE_DATA " 783 "cbChunkRead=%RU32, cbChunkWritten=%RU32, cbFileWritten=%RU64 cbFileSize=%RU64\n", 784 cbChunkRead, cbChunkWritten, cbFileWritten + cbChunkWritten, cbFileSize)); 785 786 cbFileWritten += cbChunkWritten; 787 788 Assert(cbChunkRead <= cbToRecvBytes); 789 cbToRecvBytes -= cbChunkRead; 790 } 791 } 792 793 /* Data transfer complete? Close the file. */ 794 bool fClose = objFile.IsComplete(); 795 if (fClose) 796 { 797 Assert(cToRecvObjs); 798 cToRecvObjs--; 799 } 800 801 /* Only since protocol v2 we know the file size upfront. */ 802 Assert(cbFileWritten <= cbFileSize); 803 804 if (fClose) 805 { 806 LogFlowFunc(("Closing file\n")); 807 objFile.Close(); 808 } 809 810 break; 811 } 812 default: 813 { 814 LogFlowFunc(("Message %RU32 not supported\n", uNextMsg)); 815 rc = VERR_NOT_SUPPORTED; 816 break; 817 } 818 } 819 } 820 821 if (RT_FAILURE(rc)) 822 break; 823 824 LogFlowFunc(("cbToRecvBytes=%RU64, cToRecvObjs=%RU64\n", cbToRecvBytes, cToRecvObjs)); 825 if ( !cbToRecvBytes 826 && !cToRecvObjs) 827 { 828 break; 829 } 830 831 } while (RT_SUCCESS(rc)); 832 833 LogFlowFunc(("Loop ended with %Rrc\n", rc)); 834 835 /* All URI data processed? */ 836 if (rc == VERR_NO_DATA) 837 rc = VINF_SUCCESS; 838 839 /* Delete temp buffer again. */ 840 if (pvChunk) 841 RTMemFree(pvChunk); 842 843 /* Cleanup on failure or if the user has canceled the operation or 844 * something else went wrong. */ 845 if (RT_FAILURE(rc)) 846 { 847 objFile.Close(); 848 } 849 else 850 { 851 /** @todo Compare the URI list with the dirs/files we really transferred. */ 852 /** @todo Implement checksum verification, if any. */ 853 } 854 855 LogFlowFuncLeaveRC(rc); 856 return rc; 857 #endif 858 return 0; 411 859 } 412 860 #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */ … … 469 917 if (fFormat == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST) 470 918 { 471 rc = vbglR3Clipboard SendURIData(idClient, pv, cb);919 rc = vbglR3ClipboardWriteURIData(idClient, pv, cb); 472 920 } 473 921 else … … 480 928 if (RT_FAILURE(rc)) 481 929 { 482 int rc2 = vbglR3Clipboard SendErrorInternal(idClient, rc);930 int rc2 = vbglR3ClipboardWriteErrorInternal(idClient, rc); 483 931 if (RT_FAILURE(rc2)) 484 932 LogFlowFunc(("Unable to send error (%Rrc) to host, rc=%Rrc\n", rc, rc2)); … … 491 939 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 492 940 /** 493 * Guest -> Host 494 * Utility function to send clipboard data from guest to the host. 941 * Utility function to write clipboard data from guest to the host. 495 942 * 496 943 * @returns IPRT status code. … … 500 947 * @param pDataHdr Data header to use -- needed for accounting. 501 948 */ 502 static int vbglR3Clipboard SendDataInternal(HGCMCLIENTID idClient,503 void *pvData, uint64_t cbData, PVBOXCLIPBOARDDATAHDR pDataHdr)949 static int vbglR3ClipboardWriteDataInternal(HGCMCLIENTID idClient, 950 void *pvData, uint64_t cbData, PVBOXCLIPBOARDDATAHDR pDataHdr) 504 951 { 505 952 AssertPtrReturn(pvData, VERR_INVALID_POINTER); … … 571 1018 572 1019 /** 573 * Guest -> Host 574 * Utility function to send a guest directory to the host. 1020 * Utility function to write a guest directory to the host. 575 1021 * 576 1022 * @returns IPRT status code. … … 578 1024 * @param pObj URI object containing the directory to send. 579 1025 */ 580 static int vbglR3Clipboard SendDir(HGCMCLIENTID idClient, SharedClipboardURIObject *pObj)1026 static int vbglR3ClipboardWriteDir(HGCMCLIENTID idClient, SharedClipboardURIObject *pObj) 581 1027 { 582 1028 AssertPtrReturn(pObj, VERR_INVALID_POINTER); … … 605 1051 606 1052 /** 607 * Guest -> Host 608 * Utility function to send a file from the guest to the host. 1053 * Utility function to write a file from the guest to the host. 609 1054 * 610 1055 * @returns IPRT status code. … … 612 1057 * @param pObj URI object containing the file to send. 613 1058 */ 614 static int vbglR3Clipboard SendFile(HGCMCLIENTID idClient, SharedClipboardURIObject *pObj)1059 static int vbglR3ClipboardWriteFile(HGCMCLIENTID idClient, SharedClipboardURIObject *pObj) 615 1060 { 616 1061 AssertPtrReturn(pObj, VERR_INVALID_POINTER); … … 699 1144 700 1145 /** 701 * Guest -> Host 702 * Utility function to send an URI object from guest to the host. 1146 * Utility function to write an URI object from guest to the host. 703 1147 * 704 1148 * @returns IPRT status code. … … 706 1150 * @param pObj URI object to send from guest to the host. 707 1151 */ 708 static int vbglR3Clipboard SendURIObject(HGCMCLIENTID idClient, SharedClipboardURIObject *pObj)1152 static int vbglR3ClipboardWriteURIObject(HGCMCLIENTID idClient, SharedClipboardURIObject *pObj) 709 1153 { 710 1154 AssertPtrReturn(pObj, VERR_INVALID_POINTER); … … 715 1159 { 716 1160 case SharedClipboardURIObject::Type_Directory: 717 rc = vbglR3Clipboard SendDir(idClient, pObj);1161 rc = vbglR3ClipboardWriteDir(idClient, pObj); 718 1162 break; 719 1163 720 1164 case SharedClipboardURIObject::Type_File: 721 rc = vbglR3Clipboard SendFile(idClient, pObj);1165 rc = vbglR3ClipboardWriteFile(idClient, pObj); 722 1166 break; 723 1167 … … 732 1176 733 1177 /** 734 * Guest -> Host 735 * Utility function to send URI data from guest to the host. 1178 * Utility function to write URI data from guest to the host. 736 1179 * 737 1180 * @returns IPRT status code. … … 740 1183 * @param cbData Size (in bytes) of URI data to send. 741 1184 */ 742 static int vbglR3Clipboard SendURIData(HGCMCLIENTID idClient, const void *pvData, size_t cbData)1185 static int vbglR3ClipboardWriteURIData(HGCMCLIENTID idClient, const void *pvData, size_t cbData) 743 1186 { 744 1187 AssertPtrReturn(pvData, VERR_INVALID_POINTER); … … 782 1225 dataHdr.cObjects = lstURI.GetTotalCount(); 783 1226 784 rc = vbglR3Clipboard SendDataInternal(idClient,785 pvURIList, cbURLIist, &dataHdr);1227 rc = vbglR3ClipboardWriteDataInternal(idClient, 1228 pvURIList, cbURLIist, &dataHdr); 786 1229 } 787 1230 else … … 795 1238 SharedClipboardURIObject *pNextObj = lstURI.First(); 796 1239 797 rc = vbglR3Clipboard SendURIObject(idClient, pNextObj);1240 rc = vbglR3ClipboardWriteURIObject(idClient, pNextObj); 798 1241 if (RT_FAILURE(rc)) 799 1242 break; … … 807 1250 808 1251 /** 809 * Guest -> Host 810 * Sends an error back to the host. 1252 * Writes an error to the host. 811 1253 * 812 1254 * @returns IPRT status code. … … 814 1256 * @param rcErr Error (IPRT-style) to send. 815 1257 */ 816 static int vbglR3Clipboard SendErrorInternal(HGCMCLIENTID idClient, int rcErr)1258 static int vbglR3ClipboardWriteErrorInternal(HGCMCLIENTID idClient, int rcErr) 817 1259 { 818 1260 VBoxClipboardWriteErrorMsg Msg; … … 844 1286 845 1287 /** 846 * Guest -> Host 847 * Send an error back to the host. 1288 * Writes an error back to the host. 848 1289 * 849 1290 * @returns IPRT status code. … … 851 1292 * @param rcErr Error (IPRT-style) to send. 852 1293 */ 853 VBGLR3DECL(int) VbglR3ClipboardSendError(HGCMCLIENTID idClient, int rcErr)854 { 855 return vbglR3Clipboard SendErrorInternal(idClient, rcErr);1294 VBGLR3DECL(int) vbglR3ClipboardWriteError(HGCMCLIENTID idClient, int rcErr) 1295 { 1296 return vbglR3ClipboardWriteErrorInternal(idClient, rcErr); 856 1297 } 857 1298 #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
Note:
See TracChangeset
for help on using the changeset viewer.