- Timestamp:
- Jun 3, 2019 7:13:27 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp
r78942 r78943 417 417 } 418 418 419 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 419 420 /** 420 421 * Reads the actual meta data from the host. … … 675 676 return rc; 676 677 } 677 678 #if 0679 /**680 * Helper function for receiving URI data from the host. Do not call directly.681 * This function also will take care of the file creation / locking on the guest.682 *683 * @returns IPRT status code.684 * @param idClient The client id returned by VbglR3ClipboardConnect().685 * @param pDataHdr Data header to use. Needed for accounting.686 */687 static int vbglR3ClipboardReadURIData(HGCMCLIENTID idClient, PVBOXCLIPBOARDDATAHDR pDataHdr)688 {689 AssertPtrReturn(pDataHdr, VERR_INVALID_POINTER);690 691 RT_NOREF(idClient, pDataHdr);692 693 #if 0694 695 /* Only count the raw data minus the already received meta data. */696 Assert(pDataHdr->cbTotal >= pDataHdr->cbMeta);697 uint64_t cbToRecvBytes = pDataHdr->cbTotal - pDataHdr->cbMeta;698 uint64_t cToRecvObjs = pDataHdr->cObjects;699 700 LogFlowFunc(("cbToRecvBytes=%RU64, cToRecvObjs=%RU64, (cbTotal=%RU64, cbMeta=%RU32)\n",701 cbToRecvBytes, cToRecvObjs, pDataHdr->cbTotal, pDataHdr->cbMeta));702 703 /* Anything to do at all? */704 /* Note: Do not check for cbToRecvBytes == 0 here, as this might be just705 * a bunch of 0-byte files to be transferred. */706 if (!cToRecvObjs)707 return VINF_SUCCESS;708 709 /*710 * Allocate temporary chunk buffer.711 */712 uint32_t cbChunkMax = VBOX_SHARED_CLIPBOARD_MAX_CHUNK_SIZE;713 void *pvChunk = RTMemAlloc(cbChunkMax);714 if (!pvChunk)715 return VERR_NO_MEMORY;716 uint32_t cbChunkRead = 0;717 718 uint64_t cbFileSize = 0; /* Total file size (in bytes). */719 uint64_t cbFileWritten = 0; /* Written bytes. */720 721 char *pszDropDir = NULL;722 723 int rc;724 725 /*726 * Enter the main loop of retieving files + directories.727 */728 SharedClipboardURIObject objFile(SharedClipboardURIObject::Type_File);729 730 char szPathName[RTPATH_MAX] = { 0 };731 uint32_t cbPathName = 0;732 uint32_t fFlags = 0;733 uint32_t fMode = 0;734 735 do736 {737 LogFlowFunc(("Wating for new message ...\n"));738 739 uint32_t uNextMsg;740 uint32_t cNextParms;741 rc = vbglR3DnDGetNextMsgType(idClient, &uNextMsg, &cNextParms, true /* fWait */);742 if (RT_SUCCESS(rc))743 {744 LogFlowFunc(("uNextMsg=%RU32, cNextParms=%RU32\n", uNextMsg, cNextParms));745 746 switch (uNextMsg)747 {748 case HOST_DND_HG_SND_DIR:749 {750 rc = vbglR3ClipboardReadDir(idClient,751 szPathName,752 sizeof(szPathName),753 &cbPathName,754 &fMode);755 LogFlowFunc(("HOST_DND_HG_SND_DIR pszPathName=%s, cbPathName=%RU32, fMode=0x%x, rc=%Rrc\n",756 szPathName, cbPathName, fMode, rc));757 758 char *pszPathAbs = RTPathJoinA(pszDropDir, szPathName);759 if (pszPathAbs)760 {761 #ifdef RT_OS_WINDOWS762 uint32_t fCreationMode = (fMode & RTFS_DOS_MASK) | RTFS_DOS_NT_NORMAL;763 #else764 uint32_t fCreationMode = (fMode & RTFS_UNIX_MASK) | RTFS_UNIX_IRWXU;765 #endif766 rc = RTDirCreate(pszPathAbs, fCreationMode, 0);767 /*if (RT_SUCCESS(rc))768 rc = pDroppedFiles->AddDir(pszPathAbs);*/769 770 if (RT_SUCCESS(rc))771 {772 Assert(cToRecvObjs);773 cToRecvObjs--;774 }775 776 RTStrFree(pszPathAbs);777 }778 else779 rc = VERR_NO_MEMORY;780 break;781 }782 case HOST_DND_HG_SND_FILE_HDR:783 case HOST_DND_HG_SND_FILE_DATA:784 {785 if (uNextMsg == HOST_DND_HG_SND_FILE_HDR)786 {787 rc = vbglR3ClipboardReadFileHdr(idClient,788 szPathName,789 sizeof(szPathName),790 &fFlags,791 &fMode,792 &cbFileSize);793 LogFlowFunc(("HOST_DND_HG_SND_FILE_HDR: "794 "szPathName=%s, fFlags=0x%x, fMode=0x%x, cbFileSize=%RU64, rc=%Rrc\n",795 szPathName, fFlags, fMode, cbFileSize, rc));796 }797 else798 {799 rc = vbglR3ClipboardReadFileData(idClient,800 pvChunk,801 cbChunkMax,802 &cbChunkRead);803 LogFlowFunc(("HOST_DND_HG_SND_FILE_DATA: "804 "cbChunkRead=%RU32, rc=%Rrc\n", cbChunkRead, rc));805 }806 807 if ( RT_SUCCESS(rc)808 && uNextMsg == HOST_DND_HG_SND_FILE_HDR)809 {810 char *pszPathAbs = RTPathJoinA(pszDropDir, szPathName);811 if (pszPathAbs)812 {813 LogFlowFunc(("Opening pszPathName=%s, cbPathName=%RU32, fMode=0x%x, cbFileSize=%zu\n",814 szPathName, cbPathName, fMode, cbFileSize));815 816 uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_WRITE817 | RTFILE_O_CREATE_REPLACE;818 819 /* Is there already a file open, e.g. in transfer? */820 if (!objFile.IsOpen())821 {822 RTCString strPathAbs(pszPathAbs);823 #ifdef RT_OS_WINDOWS824 uint32_t fCreationMode = (fMode & RTFS_DOS_MASK) | RTFS_DOS_NT_NORMAL;825 #else826 uint32_t fCreationMode = (fMode & RTFS_UNIX_MASK) | RTFS_UNIX_IRUSR | RTFS_UNIX_IWUSR;827 #endif828 rc = objFile.OpenEx(strPathAbs, SharedClipboardURIObject::View_Target, fOpen, fCreationMode);829 if (RT_SUCCESS(rc))830 {831 //rc = pDroppedFiles->AddFile(strPathAbs.c_str());832 if (RT_SUCCESS(rc))833 {834 cbFileWritten = 0;835 objFile.SetSize(cbFileSize);836 }837 }838 }839 else840 {841 AssertMsgFailed(("ObjType=%RU32\n", objFile.GetType()));842 rc = VERR_WRONG_ORDER;843 }844 845 RTStrFree(pszPathAbs);846 }847 else848 rc = VERR_NO_MEMORY;849 }850 851 if ( RT_SUCCESS(rc)852 && uNextMsg == HOST_DND_HG_SND_FILE_DATA853 && cbChunkRead)854 {855 uint32_t cbChunkWritten;856 rc = objFile.Write(pvChunk, cbChunkRead, &cbChunkWritten);857 if (RT_SUCCESS(rc))858 {859 LogFlowFunc(("HOST_DND_HG_SND_FILE_DATA "860 "cbChunkRead=%RU32, cbChunkWritten=%RU32, cbFileWritten=%RU64 cbFileSize=%RU64\n",861 cbChunkRead, cbChunkWritten, cbFileWritten + cbChunkWritten, cbFileSize));862 863 cbFileWritten += cbChunkWritten;864 865 Assert(cbChunkRead <= cbToRecvBytes);866 cbToRecvBytes -= cbChunkRead;867 }868 }869 870 /* Data transfer complete? Close the file. */871 bool fClose = objFile.IsComplete();872 if (fClose)873 {874 Assert(cToRecvObjs);875 cToRecvObjs--;876 }877 878 /* Only since protocol v2 we know the file size upfront. */879 Assert(cbFileWritten <= cbFileSize);880 881 if (fClose)882 {883 LogFlowFunc(("Closing file\n"));884 objFile.Close();885 }886 887 break;888 }889 default:890 {891 LogFlowFunc(("Message %RU32 not supported\n", uNextMsg));892 rc = VERR_NOT_SUPPORTED;893 break;894 }895 }896 }897 898 if (RT_FAILURE(rc))899 break;900 901 LogFlowFunc(("cbToRecvBytes=%RU64, cToRecvObjs=%RU64\n", cbToRecvBytes, cToRecvObjs));902 if ( !cbToRecvBytes903 && !cToRecvObjs)904 {905 break;906 }907 908 } while (RT_SUCCESS(rc));909 910 LogFlowFunc(("Loop ended with %Rrc\n", rc));911 912 /* All URI data processed? */913 if (rc == VERR_NO_DATA)914 rc = VINF_SUCCESS;915 916 /* Delete temp buffer again. */917 if (pvChunk)918 RTMemFree(pvChunk);919 920 /* Cleanup on failure or if the user has canceled the operation or921 * something else went wrong. */922 if (RT_FAILURE(rc))923 {924 objFile.Close();925 }926 else927 {928 /** @todo Compare the URI list with the dirs/files we really transferred. */929 /** @todo Implement checksum verification, if any. */930 }931 932 LogFlowFuncLeaveRC(rc);933 return rc;934 #endif935 return 0;936 }937 #endif938 678 #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */ 939 679
Note:
See TracChangeset
for help on using the changeset viewer.