VirtualBox

Changeset 79672 in vbox


Ignore:
Timestamp:
Jul 10, 2019 1:02:50 PM (5 years ago)
Author:
vboxsync
Message:

Shared Clipboard/URI: More code for root entries handling.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/SharedClipboard-uri.h

    r79631 r79672  
    370370
    371371/**
     372 * Structure for keeping Shared Clipboard list root entries.
     373 */
     374typedef struct _VBOXCLIPBOARDROOTS
     375{
     376    /** Roots listing flags; unused at the moment. */
     377    uint32_t fRoots;
     378    /** Boolean indicating that more root items are following. */
     379    bool     fMore;
     380    /** Number of root items in this message. */
     381    uint32_t cRoots;
     382    /** Size (in bytes) of string list. */
     383    uint32_t cbRoots;
     384    /** String list (separated with \r\n) containing the root items. */
     385    char    *pszRoots;
     386} VBOXCLIPBOARDROOTS, *PVBOXCLIPBOARDROOTS;
     387
     388/**
    372389 * Structure for maintaining Shared Clipboard list open paramters.
    373390 */
     
    408425typedef struct _VBOXCLIPBOARDLISTENTRY
    409426{
     427    /** Entry name. */
     428    char    *pszName;
     429    /** Size (in bytes) of entry name. */
     430    uint32_t cbName;
    410431    /** Information flag(s). */
    411432    uint32_t fInfo;
     
    415436    void    *pvInfo;
    416437} VBOXCLIPBOARDLISTENTRY, *PVBOXCLIPBOARDLISTENTRY;
     438
     439#define VBOXCLIPBOARDLISTENTRY_MAX_NAME     RTPATH_MAX
    417440
    418441/**
     
    556579int SharedClipboardPathSanitize(char *pszPath, size_t cbPath);
    557580
     581PVBOXCLIPBOARDROOTS SharedClipboardURIRootsDup(PVBOXCLIPBOARDROOTS pRoots);
     582int SharedClipboardURIRootsInit(PVBOXCLIPBOARDROOTS pRoots);
     583void SharedClipboardURIRootsDestroy(PVBOXCLIPBOARDROOTS pRoots);
     584
    558585int SharedClipboardURIListHdrAlloc(PVBOXCLIPBOARDLISTHDR *ppListHdr);
    559586void SharedClipboardURIListHdrFree(PVBOXCLIPBOARDLISTHDR pListHdr);
     
    665692{
    666693    SHAREDCLIPBOARDURITRANSFEREVENTTYPE_UNKNOWN,
     694    SHAREDCLIPBOARDURITRANSFEREVENTTYPE_GET_ROOTS,
    667695    SHAREDCLIPBOARDURITRANSFEREVENTTYPE_LIST_OPEN,
    668696    SHAREDCLIPBOARDURITRANSFEREVENTTYPE_LIST_CLOSE,
     
    689717{
    690718    VBOXCLIPBOARDLISTOPENPARMS OpenParms;
    691     RTFMODE                     fMode;
     719    RTFMODE                    fMode;
    692720    union
    693721    {
     
    718746typedef std::map<SHAREDCLIPBOARDLISTHANDLE, SHAREDCLIPBOARDURILISTHANDLEINFO *> SharedClipboardURIListMap;
    719747
     748/** Map of URI object handles.
     749 *  The key specifies the object handle. */
    720750typedef std::map<SHAREDCLIPBOARDOBJHANDLE, SHAREDCLIPBOARDURILISTHANDLEINFO *> SharedClipboardURIObjMap;
     751
     752/** List of URI list root entries. */
     753typedef RTCList<RTCString> SharedClipboardURIListRootEntries;
    721754
    722755/**
     
    770803SHAREDCLIPBOARDPROVIDERFUNCDECLVOID(TRANSFEROPEN)
    771804SHAREDCLIPBOARDPROVIDERFUNCDECLVOID(TRANSFERCLOSE)
     805SHAREDCLIPBOARDPROVIDERFUNCDECL(GETROOTS, char **ppapszRoots, uint32_t *pcRoots)
    772806SHAREDCLIPBOARDPROVIDERFUNCDECL(LISTOPEN, PVBOXCLIPBOARDLISTOPENPARMS pOpenParms, PSHAREDCLIPBOARDLISTHANDLE phList)
    773807SHAREDCLIPBOARDPROVIDERFUNCDECL(LISTCLOSE, SHAREDCLIPBOARDLISTHANDLE hList);
     
    791825    SHAREDCLIPBOARDPROVIDERFUNCMEMBER(TRANSFEROPEN, pfnTransferOpen);
    792826    SHAREDCLIPBOARDPROVIDERFUNCMEMBER(TRANSFERCLOSE, pfnTransferClose);
     827    SHAREDCLIPBOARDPROVIDERFUNCMEMBER(GETROOTS, pfnGetRoots);
    793828    SHAREDCLIPBOARDPROVIDERFUNCMEMBER(LISTOPEN, pfnListOpen);
    794829    SHAREDCLIPBOARDPROVIDERFUNCMEMBER(LISTCLOSE, pfnListClose);
     
    907942    /** Events related to this transfer. */
    908943    SharedClipboardURITransferEventMap *pMapEvents;
     944    /** Map of all lists related to this transfer. */
    909945    SharedClipboardURIListMap          *pMapLists;
     946    /** List of root entries of this transfer. */
     947    SharedClipboardURIListRootEntries   lstRootEntries;
     948    /** Map of all objects related to this transfer. */
    910949    SharedClipboardURIObjMap           *pMapObj;
    911950    /** The transfer's own (local) area, if any (can be NULL if not needed).
     
    9701009
    9711010int SharedClipboardURITransferPrepare(PSHAREDCLIPBOARDURITRANSFER pTransfer);
     1011int SharedClipboardURITransferSetData(PSHAREDCLIPBOARDURITRANSFER pTransfer, SharedClipboardURIListRootEntries *pEntries);
    9721012int SharedClipboardURITransferSetInterface(PSHAREDCLIPBOARDURITRANSFER pTransfer,
    9731013                                           PSHAREDCLIPBOARDPROVIDERCREATIONCTX pCreationCtx);
     1014int SharedClipboardURILTransferSetRoots(PSHAREDCLIPBOARDURITRANSFER pTransfer, const char *papszRoots, size_t cbRoots);
    9741015void SharedClipboardURITransferReset(PSHAREDCLIPBOARDURITRANSFER pTransfer);
    9751016SharedClipboardArea *SharedClipboardURITransferGetArea(PSHAREDCLIPBOARDURITRANSFER pTransfer);
     1017int SharedClipboardURILTransferGetRoots(PSHAREDCLIPBOARDURITRANSFER pTransfer, char **ppapszRoots, uint32_t *pcRoots);
    9761018SHAREDCLIPBOARDSOURCE SharedClipboardURITransferGetSource(PSHAREDCLIPBOARDURITRANSFER pTransfer);
    9771019SHAREDCLIPBOARDURITRANSFERSTATUS SharedClipboardURITransferGetStatus(PSHAREDCLIPBOARDURITRANSFER pTransfer);
  • trunk/include/VBox/HostServices/VBoxClipboardSvc.h

    r79630 r79672  
    7575/** Initiates a new transfer (read / write) on the guest side. */
    7676#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START     50
     77/** Requests reading the root entries from the guest. */
     78#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ROOTS              51
    7779/** Open an URI list on the guest side. */
    78 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_OPEN          51
     80#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_OPEN          52
    7981/** Closes a formerly opened URI list on the guest side. */
    80 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_CLOSE         52
     82#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_CLOSE         53
    8183/** Reads a list header from the guest. */
    82 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_HDR_READ      53
     84#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_HDR_READ      54
    8385/** Writes a list header to the guest. */
    84 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_HDR_WRITE     54
     86#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_HDR_WRITE     55
    8587/** Reads a list entry from the guest. */
    86 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_ENTRY_READ    55
     88#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_ENTRY_READ    56
    8789/** Writes a list entry to the guest. */
    88 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_ENTRY_WRITE   56
     90#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_ENTRY_WRITE   57
    8991/** Open an URI object on the guest side. */
    90 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_OBJ_OPEN           57
     92#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_OBJ_OPEN           58
    9193/** Closes a formerly opened URI object on the guest side. */
    92 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_OBJ_CLOSE          58
     94#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_OBJ_CLOSE          59
    9395/** Reads from an object on the guest side. */
    94 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_OBJ_READ           59
     96#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_OBJ_READ           60
    9597/** Writes to an object on the guest side. */
    96 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_OBJ_WRITE          60
     98#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_OBJ_WRITE          61
    9799/** Indicates that the host has canceled a transfer. */
    98 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL             61
     100#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL             62
    99101/** Indicates that the an unrecoverable error on the host occurred . */
    100 #define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR              62
     102#define VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR              63
    101103
    102104/*
     
    129131 *  New since URI handling was implemented. */
    130132#define VBOX_SHARED_CLIPBOARD_GUEST_FN_REPLY             9
     133/** Reports the available root entries of a transfer.
     134  *  New since URI handling was implemented. */
     135#define VBOX_SHARED_CLIPBOARD_GUEST_FN_ROOTS             10
    131136/** Opens / gets a list handle from the host.
    132137 *  New since URI handling was implemented. */
    133 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_OPEN         10
     138#define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_OPEN         11
    134139/** Closes a list handle from the host.
    135140 *  New since URI handling was implemented. */
    136 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_CLOSE        11
     141#define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_CLOSE        12
    137142/** Reads a list header from the host.
    138143 *  New since URI handling was implemented. */
    139 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_HDR_READ     12
     144#define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_HDR_READ     13
    140145/** Writes a list header to the host.
    141146 *  New since URI handling was implemented. */
    142 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_HDR_WRITE    13
     147#define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_HDR_WRITE    14
    143148/** New since URI handling was implemented. */
    144 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_ENTRY_READ   14
     149#define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_ENTRY_READ   15
    145150/** New since URI handling was implemented. */
    146 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_ENTRY_WRITE  15
     151#define VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_ENTRY_WRITE  16
    147152/** New since URI handling was implemented. */
    148 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_OPEN          16
     153#define VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_OPEN          17
    149154/** New since URI handling was implemented. */
    150 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_CLOSE         17
     155#define VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_CLOSE         18
    151156/** New since URI handling was implemented. */
    152 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_READ          18
     157#define VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_READ          19
    153158/**  New since URI handling was implemented. */
    154 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_WRITE         19
     159#define VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_WRITE         20
    155160/** Reports cancellation of the current operation to the host.
    156161 *  New since URI handling was implemented. */
    157 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_CANCEL            20
     162#define VBOX_SHARED_CLIPBOARD_GUEST_FN_CANCEL            21
    158163/** Reports an error to the host.
    159164 *  New since URI handling was implemented. */
    160 #define VBOX_SHARED_CLIPBOARD_GUEST_FN_ERROR             21
     165#define VBOX_SHARED_CLIPBOARD_GUEST_FN_ERROR             22
    161166
    162167/**
     
    174179        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_REPORT_FORMATS);
    175180        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START);
     181        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ROOTS);
    176182        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_OPEN);
    177183        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_CLOSE);
     
    208214        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_STATUS);
    209215        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_REPLY);
     216        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_ROOTS);
    210217        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_OPEN);
    211218        RT_CASE_RET_STR(VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_CLOSE);
     
    328335#define VBOX_SHAREDCLIPBOARD_LISTHDR_FLAG_NONE       0
    329336
     337/** No additional information provided. */
    330338#define VBOX_SHAREDCLIPBOARD_INFO_FLAG_NONE          0
    331339/** Get object information of type SHAREDCLIPBOARDFSOBJINFO. */
     
    362370    VBGLIOCHGCMCALL hdr;
    363371
    364     /** uint32_t, in: Context ID. Unused at the moment. */
    365     HGCMFunctionParameter uContext;
    366     /** uint32_t, in: Message type of type VBOX_SHAREDCLIPBOARD_REPLYMSGTYPE_XXX. */
     372    /** uint32_t, out: Context ID. Unused at the moment. */
     373    HGCMFunctionParameter uContext;
     374    /** uint32_t, out: Message type of type VBOX_SHAREDCLIPBOARD_REPLYMSGTYPE_XXX. */
    367375    HGCMFunctionParameter enmType;
    368     /** uint32_t, in: IPRT result of overall operation. */
     376    /** uint32_t, out: IPRT result of overall operation. */
    369377    HGCMFunctionParameter rc;
    370     /** uint32_t, in: Size of optional payload of this reply, based on the message type. */
     378    /** uint32_t, out: Size of optional payload of this reply, based on the message type. */
    371379    HGCMFunctionParameter cbPayload;
    372     /** pointer, in: Optional payload of this reply, based on the message type. */
     380    /** pointer, out: Optional payload of this reply, based on the message type. */
    373381    HGCMFunctionParameter pvPayload;
    374382    union
     
    388396
    389397/**
     398 * Reads / Writes the roots list.
     399 */
     400typedef struct _VBoxClipboardRootsMsg
     401{
     402    VBGLIOCHGCMCALL hdr;
     403
     404    /** uint32_t, in: Context ID. Unused at the moment. */
     405    HGCMFunctionParameter uContext;
     406    /** uint32_t, in: Roots listing flags; unused at the moment. */
     407    HGCMFunctionParameter fRoots;
     408    /** uint32_t, out: Boolean indicating that more root items are following
     409     *                 (via another message). */
     410    HGCMFunctionParameter fMore;
     411    /** uint32_t, out: Number of root items in this message. */
     412    HGCMFunctionParameter cRoots;
     413    /** uin32_t, out: Size (in bytes) of string list. */
     414    HGCMFunctionParameter cbRoots;
     415    /** pointer, out: string list (separated with \r\n) containing the root items. */
     416    HGCMFunctionParameter pvRoots;
     417} VBoxClipboardRootsMsg;
     418
     419#define VBOX_SHARED_CLIPBOARD_CPARMS_ROOTS 6
     420
     421/**
    390422 * Opens a list.
    391423 */
     
    500532    VBGLIOCHGCMCALL hdr;
    501533
    502     /** in: Request parameters. */
     534    /** in/out: Request parameters. */
    503535    VBoxClipboardListEntryReqParms ReqParms;
     536    /** pointer, in/out: Entry name. */
     537    HGCMFunctionParameter          szName;
    504538    /** uint32_t, out: Bytes to be used for information/How many bytes were used.  */
    505539    HGCMFunctionParameter          cbInfo;
    506     /** pointer, out: Information to be set/get (SHAREDCLIPBOARDFSOBJINFO only currently).
     540    /** pointer, in/out: Information to be set/get (SHAREDCLIPBOARDFSOBJINFO only currently).
    507541     * Do not forget to set the SHAREDCLIPBOARDFSOBJINFO::Attr::enmAdditional for Get operation as well.  */
    508542    HGCMFunctionParameter          pvInfo;
    509543} VBoxClipboardListEntryMsg;
    510544
    511 #define VBOX_SHARED_CLIPBOARD_CPARMS_LIST_ENTRY 5
     545#define VBOX_SHARED_CLIPBOARD_CPARMS_LIST_ENTRY 6
    512546
    513547typedef struct _VBoxClipboardObjOpenMsg
  • trunk/include/VBox/VBoxGuestLib.h

    r79630 r79672  
    625625
    626626VBGLR3DECL(int)     VbglR3ClipboardTransferSendStatus(HGCMCLIENTID idClient, SHAREDCLIPBOARDURITRANSFERSTATUS uStatus);
     627
     628VBGLR3DECL(int)     VbglR3ClipboardRootsRecv(HGCMCLIENTID idClient, uint32_t *pfRoots);
     629VBGLR3DECL(int)     VbglR3ClipboardRootsWrite(HGCMCLIENTID idClient, uint32_t cRoots, const char *papszList, uint32_t cbList);
    627630
    628631VBGLR3DECL(int)     VbglR3ClipboardListOpenSend(HGCMCLIENTID idClient, PVBOXCLIPBOARDLISTOPENPARMS pOpenParms, PSHAREDCLIPBOARDLISTHANDLE phList);
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp

    r79630 r79672  
    8080    PVBOXCLIPBOARDCONTEXT       pClipboardCtx;
    8181    PSHAREDCLIPBOARDURITRANSFER pTransfer;
    82     char                       *papszURIList;
    83     uint32_t                    cbURIList;
    8482} VBOXCLIPBOARDURIWRITETHREADCTX, *PVBOXCLIPBOARDURIWRITETHREADCTX;
    8583#endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
     
    156154        VbglR3ClipboardDisconnect(uClientID);
    157155    }
    158 
    159     if (pCtx->papszURIList)
    160         RTStrFree(pCtx->papszURIList);
    161156
    162157    RTMemFree(pCtx);
     
    787782               if (RT_SUCCESS(rc))
    788783               {
    789             #if 0
    790                    SHAREDCLIPBOARDURITRANSFERCALLBACKS TransferCallbacks;
    791                    RT_ZERO(TransferCallbacks);
    792 
    793                    TransferCallbacks.pvUser              = &pCtx->URI;
    794                    TransferCallbacks.pfnTransferComplete = vboxClipboardURITransferCompleteCallback;
    795                    TransferCallbacks.pfnTransferError    = vboxClipboardURITransferErrorCallback;
    796 
    797                    SharedClipboardURITransferSetCallbacks(pTransfer, &TransferCallbacks);
    798 
    799                    SHAREDCLIPBOARDPROVIDERCREATIONCTX creationCtx;
    800                    RT_ZERO(creationCtx);
    801                    creationCtx.enmSource = SHAREDCLIPBOARDSOURCE_LOCAL;
    802 
    803                    RT_ZERO(creationCtx.Interface);
    804                    creationCtx.Interface.pfnListHdrWrite   = vboxClipboardURIListHdrWrite;
    805                    creationCtx.Interface.pfnListEntryWrite = vboxClipboardURIListEntryWrite;
    806                    creationCtx.Interface.pfnObjOpen        = vboxClipboardURIObjOpen;
    807                    creationCtx.Interface.pfnObjClose       = vboxClipboardURIObjClose;
    808                    creationCtx.Interface.pfnObjWrite       = vboxClipboardURIObjWrite;
    809 
    810                    creationCtx.pvUser = pCtx;
    811 
    812                    rc = SharedClipboardURITransferSetInterface(pTransfer, &creationCtx);
     784                   rc = SharedClipboardURICtxTransferAdd(&pCtx->URI, pTransfer);
    813785                   if (RT_SUCCESS(rc))
    814786                   {
    815             #endif
    816                        rc = SharedClipboardURICtxTransferAdd(&pCtx->URI, pTransfer);
    817                        if (RT_SUCCESS(rc))
     787                       /* The data data in CF_HDROP format, as the files are locally present and don't need to be
     788                       * presented as a IDataObject or IStream. */
     789                       HANDLE hClip = hClip = GetClipboardData(CF_HDROP);
     790                       if (hClip)
    818791                       {
    819                            /* The data data in CF_HDROP format, as the files are locally present and don't need to be
    820                            * presented as a IDataObject or IStream. */
    821                            HANDLE hClip = hClip = GetClipboardData(CF_HDROP);
    822                            if (hClip)
     792                           HDROP hDrop = (HDROP)GlobalLock(hClip);
     793                           if (hDrop)
    823794                           {
    824                                HDROP hDrop = (HDROP)GlobalLock(hClip);
    825                                if (hDrop)
     795                               char    *papszList;
     796                               uint32_t cbList;
     797                               rc = VBoxClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &papszList, &cbList);
     798
     799                               GlobalUnlock(hClip);
     800
     801                               if (RT_SUCCESS(rc))
    826802                               {
    827                                    char    *papszList;
    828                                    uint32_t cbList;
    829                                    rc = VBoxClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &papszList, &cbList);
     803                                   rc = SharedClipboardURILTransferSetRoots(pTransfer, papszList, cbList);
    830804                                   if (RT_SUCCESS(rc))
    831805                                   {
     
    836810                                           pThreadCtx->pClipboardCtx = pCtx;
    837811                                           pThreadCtx->pTransfer     = pTransfer;
    838                                            pThreadCtx->papszURIList  = papszList;
    839                                            pThreadCtx->cbURIList     = cbList;
    840 
    841                                            GlobalUnlock(hClip);
    842 
     812
     813                                           rc = SharedClipboardURITransferPrepare(pTransfer);
    843814                                           if (RT_SUCCESS(rc))
    844815                                           {
    845                                                rc = SharedClipboardURITransferPrepare(pTransfer);
    846                                                if (RT_SUCCESS(rc))
    847                                                {
    848                                                    rc = SharedClipboardURITransferRun(pTransfer, vboxClipboardURIWriteThread,
    849                                                                                       pThreadCtx /* pvUser */);
    850                                                    /* pThreadCtx now is owned by vboxClipboardURIWriteThread(). */
    851                                                }
     816                                               rc = SharedClipboardURITransferRun(pTransfer, vboxClipboardURIWriteThread,
     817                                                                                  pThreadCtx /* pvUser */);
     818                                               /* pThreadCtx now is owned by vboxClipboardURIWriteThread(). */
    852819                                           }
    853820                                       }
    854821                                       else
    855822                                           rc = VERR_NO_MEMORY;
    856 
    857                                        if (RT_FAILURE(rc))
    858                                        {
    859                                            RTStrFree(papszList);
    860                                        }
    861823                                   }
    862                                }
    863                                else
    864                                {
    865                                    hClip = NULL;
     824
     825                                   if (papszList)
     826                                       RTStrFree(papszList);
    866827                               }
    867828                           }
     829                           else
     830                           {
     831                               hClip = NULL;
     832                           }
    868833                       }
    869                    //}
     834                   }
    870835               }
    871836
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp

    r79630 r79672  
    278278}
    279279
     280VBGLR3DECL(int) VbglR3ClipboardRootsRecv(HGCMCLIENTID idClient, PVBOXCLIPBOARDROOTS pRoots)
     281{
     282    AssertPtrReturn(pRoots, VERR_INVALID_POINTER);
     283
     284    VBoxClipboardRootsMsg Msg;
     285    RT_ZERO(Msg);
     286
     287    VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient,
     288                       VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_GET, VBOX_SHARED_CLIPBOARD_CPARMS_ROOTS);
     289
     290    Msg.uContext.SetUInt32(VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ROOTS);
     291    Msg.fRoots.SetUInt32(0);
     292    Msg.fMore.SetUInt32(0);
     293    Msg.cRoots.SetUInt32(0);
     294    Msg.cbRoots.SetUInt32(pRoots->cbRoots);
     295    Msg.pvRoots.SetPtr((void *)pRoots->pszRoots, pRoots->cbRoots);
     296
     297    int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
     298    if (RT_SUCCESS(rc))
     299    {
     300        uint32_t fMore;
     301        rc = Msg.fMore.GetUInt32(&fMore); AssertRC(rc);
     302        if (RT_SUCCESS(rc))
     303        {
     304            pRoots->fMore = RT_BOOL(fMore);
     305        }
     306        if (RT_SUCCESS(rc))
     307            rc = Msg.fRoots.GetUInt32(&pRoots->fRoots); AssertRC(rc);
     308        if (RT_SUCCESS(rc))
     309            rc = Msg.cRoots.GetUInt32(&pRoots->cRoots); AssertRC(rc);
     310        if (RT_SUCCESS(rc))
     311            rc = Msg.cbRoots.GetUInt32(&pRoots->cbRoots); AssertRC(rc);
     312    }
     313
     314    LogFlowFuncLeaveRC(rc);
     315    return rc;
     316}
     317
     318VBGLR3DECL(int) VbglR3ClipboardRootsWrite(HGCMCLIENTID idClient, uint32_t cRoots, char *papszList, uint32_t cbList)
     319{
     320    AssertPtrReturn(papszList, VERR_INVALID_POINTER);
     321    AssertReturn(cbList,       VERR_INVALID_PARAMETER);
     322
     323    VBoxClipboardRootsMsg Msg;
     324    RT_ZERO(Msg);
     325
     326    VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient,
     327                       VBOX_SHARED_CLIPBOARD_GUEST_FN_ROOTS, VBOX_SHARED_CLIPBOARD_CPARMS_ROOTS);
     328
     329    Msg.uContext.SetUInt32(0); /** @todo Context ID not used yet. */
     330    Msg.fRoots.SetUInt32(0);
     331    Msg.fMore.SetUInt32(0);
     332    Msg.cRoots.SetUInt32(cRoots);
     333    Msg.cbRoots.SetUInt32(cbList);
     334    Msg.pvRoots.SetPtr(papszList, cbList);
     335
     336    int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
     337
     338    LogFlowFuncLeaveRC(rc);
     339    return rc;
     340}
     341
    280342VBGLR3DECL(int) VbglR3ClipboardListOpenSend(HGCMCLIENTID idClient, PVBOXCLIPBOARDLISTOPENPARMS pOpenParms,
    281343                                            PSHAREDCLIPBOARDLISTHANDLE phList)
     
    512574    Msg.ReqParms.fInfo.SetUInt32(0);
    513575
     576    Msg.szName.SetPtr(pListEntry->pszName, pListEntry->cbName);
    514577    Msg.cbInfo.SetUInt32(0);
    515578    Msg.pvInfo.SetPtr(pListEntry->pvInfo, pListEntry->cbInfo);
     
    567630    Msg.ReqParms.fInfo.SetUInt32(pListEntry->fInfo);
    568631
     632    Msg.szName.SetPtr(pListEntry->pszName, pListEntry->cbName);
    569633    Msg.cbInfo.SetUInt32(pListEntry->cbInfo);
    570634    Msg.pvInfo.SetPtr(pListEntry->pvInfo, pListEntry->cbInfo);
     
    596660        {
    597661#ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
     662            case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ROOTS:
     663            {
     664                LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ROOTS\n"));
     665
     666                VBOXCLIPBOARDROOTS Roots;
     667                rc = SharedClipboardURIRootsInit(&Roots);
     668                if (RT_SUCCESS(rc))
     669                {
     670                    rc = VbglR3ClipboardRootsRecv(idClient, &Roots);
     671                    if (RT_SUCCESS(rc))
     672                    {
     673                        /** @todo Handle fFlags. */
     674
     675                        char    *pszRoots = NULL;
     676                        uint32_t cRoots   = 0;
     677                        rc = SharedClipboardURILTransferGetRoots(pTransfer, &pszRoots, &cRoots);
     678                        if (RT_SUCCESS(rc))
     679                        {
     680                            /** @todo Split up transfers in _64K each. */
     681
     682                            rc = VbglR3ClipboardRootsWrite(idClient, cRoots,
     683                                                           pszRoots, pszRoots ? (uint32_t)strlen(pszRoots) : NULL);
     684                        }
     685                    }
     686                }
     687
     688                break;
     689            }
     690
    598691            case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_OPEN:
    599692            {
     
    607700                    if (RT_SUCCESS(rc))
    608701                    {
     702                        LogFlowFunc(("pszPath=%s\n", openParmsList.pszPath));
     703
    609704                        SHAREDCLIPBOARDLISTHANDLE hList = SHAREDCLIPBOARDLISTHANDLE_INVALID;
    610705                        rc = SharedClipboardURITransferListOpen(pTransfer, &openParmsList, &hList);
     
    613708                        int rc2 = VbglR3ClipboardListOpenReply(idClient, rc, hList);
    614709                        AssertRC(rc2);
     710
     711                        SharedClipboardURIListOpenParmsDestroy(&openParmsList);
    615712                    }
    616 
    617                     SharedClipboardURIListOpenParmsDestroy(&openParmsList);
    618713                }
     714
    619715                break;
    620716            }
     
    676772                LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_LIST_ENTRY_READ\n"));
    677773
    678                 VBOXCLIPBOARDLISTENTRY listEntry;
    679                 rc = SharedClipboardURIListEntryInit(&listEntry);
     774                VBOXCLIPBOARDLISTENTRY entryList;
     775                rc = SharedClipboardURIListEntryInit(&entryList);
    680776                if (RT_SUCCESS(rc))
    681777                {
     
    685781                    if (RT_SUCCESS(rc))
    686782                    {
    687                         rc = SharedClipboardURITransferListRead(pTransfer, hList, &listEntry);
     783                        rc = SharedClipboardURITransferListRead(pTransfer, hList, &entryList);
    688784                        if (RT_SUCCESS(rc))
    689785                        {
    690                             rc = VbglR3ClipboardListEntryWrite(idClient, hList, &listEntry);
     786                            PSHAREDCLIPBOARDFSOBJINFO pObjInfo = (PSHAREDCLIPBOARDFSOBJINFO)entryList.pvInfo;
     787                            Assert(entryList.cbInfo == sizeof(SHAREDCLIPBOARDFSOBJINFO));
     788
     789                            LogFlowFunc(("\t%s (%RU64 bytes)\n", entryList.pszName, pObjInfo->cbObject));
     790
     791                            rc = VbglR3ClipboardListEntryWrite(idClient, hList, &entryList);
    691792                        }
    692793                    }
    693794
    694                     SharedClipboardURIListEntryDestroy(&listEntry);
     795                    SharedClipboardURIListEntryDestroy(&entryList);
    695796                }
    696797
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp

    r79630 r79672  
    246246    RTThreadUserSignal(RTThreadSelf());
    247247
     248    LogRel2(("Shared Clipboard: Calculating transfer ....\n"));
     249
    248250    int rc = SharedClipboardURITransferOpen(pTransfer);
    249251    if (RT_SUCCESS(rc))
    250252    {
    251         VBOXCLIPBOARDLISTOPENPARMS openParmsList;
    252         rc = SharedClipboardURIListOpenParmsInit(&openParmsList);
     253        uint32_t cRoots;
     254        char    *pszRoots;
     255        rc = SharedClipboardURILTransferGetRoots(pTransfer, &pszRoots, &cRoots);
    253256        if (RT_SUCCESS(rc))
    254257        {
    255             SHAREDCLIPBOARDLISTHANDLE hList;
    256             rc = SharedClipboardURITransferListOpen(pTransfer, &openParmsList, &hList);
     258            SharedClipboardURIListRootEntries lstRoots = RTCString(pszRoots, strlen(pszRoots)).split("\r\n");
     259            Assert(lstRoots.size() == cRoots);
     260
     261            LogFlowFunc(("cRoots=%zu\n", lstRoots.size()));
     262
     263            for (uint32_t i = 0; i < lstRoots.size(); i++)
     264            {
     265                VBOXCLIPBOARDLISTOPENPARMS openParmsList;
     266                rc = SharedClipboardURIListOpenParmsInit(&openParmsList);
     267                if (RT_SUCCESS(rc))
     268                {
     269                    LogFlowFunc(("pszRoot=%s\n", lstRoots[i].c_str()));
     270
     271                    rc = RTStrCopy(openParmsList.pszPath, openParmsList.cbPath, lstRoots[i].c_str());
     272                    if (RT_FAILURE(rc))
     273                        break;
     274
     275                    SHAREDCLIPBOARDLISTHANDLE hList;
     276                    rc = SharedClipboardURITransferListOpen(pTransfer, &openParmsList, &hList);
     277                    if (RT_SUCCESS(rc))
     278                    {
     279                        LogFlowFunc(("hList=%RU64\n", hList));
     280
     281                        VBOXCLIPBOARDLISTHDR hdrList;
     282                        rc = SharedClipboardURITransferListGetHeader(pTransfer, hList, &hdrList);
     283                        if (RT_SUCCESS(rc))
     284                        {
     285                            LogFlowFunc(("cTotalObjects=%RU64, cbTotalSize=%RU64\n\n",
     286                                         hdrList.cTotalObjects, hdrList.cbTotalSize));
     287
     288                            for (uint64_t i = 0; i < hdrList.cTotalObjects; i++)
     289                            {
     290                                VBOXCLIPBOARDLISTENTRY entryList;
     291                                rc = SharedClipboardURITransferListRead(pTransfer, hList, &entryList);
     292                                if (RT_SUCCESS(rc))
     293                                {
     294                                    PSHAREDCLIPBOARDFSOBJINFO pObjInfo = (PSHAREDCLIPBOARDFSOBJINFO)entryList.pvInfo;
     295                                    Assert(entryList.cbInfo == sizeof(SHAREDCLIPBOARDFSOBJINFO));
     296
     297                                    LogFlowFunc(("\t%s (%RU64 bytes)\n", entryList.pszName, pObjInfo->cbObject));
     298                                }
     299                                else
     300                                    break;
     301
     302                                if (pTransfer->Thread.fStop)
     303                                    break;
     304                            }
     305                        }
     306
     307                        SharedClipboardURITransferListClose(pTransfer, hList);
     308                    }
     309
     310                    SharedClipboardURIListOpenParmsDestroy(&openParmsList);
     311                }
     312
     313                if (RT_FAILURE(rc))
     314                    break;
     315            }
     316
    257317            if (RT_SUCCESS(rc))
    258318            {
    259                 LogFlowFunc(("hList=%RU64\n", hList));
    260 
    261                 VBOXCLIPBOARDLISTHDR hdrList;
    262                 rc = SharedClipboardURITransferListGetHeader(pTransfer, hList, &hdrList);
    263                 if (RT_SUCCESS(rc))
    264                 {
    265                     LogFlowFunc(("cTotalObjects=%RU64, cbTotalSize=%RU64\n\n",
    266                                  hdrList.cTotalObjects, hdrList.cbTotalSize));
    267 
    268                     for (uint64_t i = 0; i < hdrList.cTotalObjects; i++)
    269                     {
    270                         VBOXCLIPBOARDLISTENTRY entryList;
    271                         rc = SharedClipboardURITransferListRead(pTransfer, hList, &entryList);
    272                         if (RT_SUCCESS(rc))
    273                         {
    274                         }
    275                         else
    276                             break;
    277 
    278                         if (pTransfer->Thread.fStop)
    279                             break;
    280                     }
    281 
    282                     if (RT_SUCCESS(rc))
    283                     {
    284                         /*
    285                          * Signal the "list complete" event so that this data object can return (valid) data via ::GetData().
    286                          * This in turn then will create IStream instances (by the OS) for each file system object to handle.
    287                          */
    288                         int rc2 = RTSemEventSignal(pThis->m_EventListComplete);
    289                         AssertRC(rc2);
    290 
    291                         LogFlowFunc(("Waiting for transfer to complete ...\n"));
    292 
    293                         /* Transferring stuff can take a while, so don't use any timeout here. */
    294                         rc2 = RTSemEventWait(pThis->m_EventTransferComplete, RT_INDEFINITE_WAIT);
    295                         AssertRC(rc2);
    296                     }
    297                 }
    298 
    299                 SharedClipboardURITransferListClose(pTransfer, hList);
     319                LogRel2(("Shared Clipboard: Calculation complete, starting transfer ...\n"));
     320
     321                /*
     322                 * Signal the "list complete" event so that this data object can return (valid) data via ::GetData().
     323                 * This in turn then will create IStream instances (by the OS) for each file system object to handle.
     324                 */
     325                int rc2 = RTSemEventSignal(pThis->m_EventListComplete);
     326                AssertRC(rc2);
     327
     328                LogFlowFunc(("Waiting for transfer to complete ...\n"));
     329
     330                /* Transferring stuff can take a while, so don't use any timeout here. */
     331                rc2 = RTSemEventWait(pThis->m_EventTransferComplete, RT_INDEFINITE_WAIT);
     332                AssertRC(rc2);
    300333            }
    301334
    302             SharedClipboardURIListOpenParmsDestroy(&openParmsList);
     335            RTStrFree(pszRoots);
    303336        }
    304337
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-uri.cpp

    r79630 r79672  
    3737
    3838
     39int SharedClipboardURIRootsInit(PVBOXCLIPBOARDROOTS pRoots)
     40{
     41    AssertPtrReturn(pRoots, VERR_INVALID_POINTER);
     42
     43    RT_BZERO(pRoots, sizeof(VBOXCLIPBOARDROOTS));
     44
     45    const uint32_t cbRoots = _64K;
     46
     47    pRoots->pszRoots = RTStrAlloc(cbRoots);
     48    if (!pRoots->pszRoots)
     49        return VERR_NO_MEMORY;
     50
     51    pRoots->cbRoots = cbRoots;
     52
     53    return VINF_SUCCESS;
     54}
     55
     56void SharedClipboardURIRootsDestroy(PVBOXCLIPBOARDROOTS pRoots)
     57{
     58    if (!pRoots)
     59        return;
     60
     61    if (pRoots->pszRoots)
     62        RTStrFree(pRoots->pszRoots);
     63}
     64
     65PVBOXCLIPBOARDROOTS SharedClipboardURIRootsDup(PVBOXCLIPBOARDROOTS pRoots)
     66{
     67    AssertPtrReturn(pRoots, NULL);
     68
     69    int rc = VINF_SUCCESS;
     70
     71    PVBOXCLIPBOARDROOTS pRootsDup = (PVBOXCLIPBOARDROOTS)RTMemAlloc(sizeof(VBOXCLIPBOARDROOTS));
     72    if (pRootsDup)
     73    {
     74        *pRootsDup = *pRoots;
     75
     76        if (pRoots->pszRoots)
     77        {
     78            pRootsDup->pszRoots = RTStrDup(pRoots->pszRoots);
     79            if (!pRootsDup->pszRoots)
     80                rc = VERR_NO_MEMORY;
     81        }
     82    }
     83
     84    if (RT_FAILURE(rc))
     85    {
     86        if (pRootsDup->pszRoots)
     87            RTStrFree(pRootsDup->pszRoots);
     88
     89        RTMemFree(pRootsDup);
     90        pRootsDup = NULL;
     91    }
     92
     93    return pRootsDup;
     94}
     95
    3996/**
    4097 * Allocates a VBOXCLIPBOARDListHdr structure.
     
    287344    *pDst = *pSrc;
    288345
    289     if (pSrc->pvInfo)
     346    if (pSrc->pszName)
     347    {
     348        pDst->pszName = RTStrDup(pSrc->pszName);
     349        if (!pDst->pszName)
     350            rc = VERR_NO_MEMORY;
     351    }
     352
     353    if (   RT_SUCCESS(rc)
     354        && pSrc->pvInfo)
    290355    {
    291356        pDst->pvInfo = RTMemDup(pSrc->pvInfo, pSrc->cbInfo);
     
    341406 * Initializes a clipboard list entry structure.
    342407 *
    343  * @param   pListEntry          clipboard list entry structure to initialize.
     408 * @returns VBox status code.
     409 * @param   pListEntry          Clipboard list entry structure to initialize.
    344410 */
    345411int SharedClipboardURIListEntryInit(PVBOXCLIPBOARDLISTENTRY pListEntry)
     
    347413    RT_BZERO(pListEntry, sizeof(VBOXCLIPBOARDLISTENTRY));
    348414
     415    pListEntry->pszName = RTStrAlloc(VBOXCLIPBOARDLISTENTRY_MAX_NAME);
     416    if (!pListEntry->pszName)
     417        return VERR_NO_MEMORY;
     418
     419    pListEntry->cbName = VBOXCLIPBOARDLISTENTRY_MAX_NAME;
     420
    349421    return VINF_SUCCESS;
    350422}
     
    353425 * Initializes a clipboard list entry structure.
    354426 *
    355  * @param   pListEntry          clipboard list entry structure to destroy.
     427 * @param   pListEntry          Clipboard list entry structure to destroy.
    356428 */
    357429void SharedClipboardURIListEntryDestroy(PVBOXCLIPBOARDLISTENTRY pListEntry)
     
    359431    if (!pListEntry)
    360432        return;
     433
     434    if (pListEntry->pszName)
     435    {
     436        RTStrFree(pListEntry->pszName);
     437
     438        pListEntry->pszName = NULL;
     439        pListEntry->cbName  = 0;
     440    }
    361441
    362442    if (pListEntry->pvInfo)
     
    382462    return true; /** @todo Implement this. */
    383463}
    384 
    385 #if 0
    386 /**
    387  * Creates (allocates) and initializes a VBOXCLIPBOARDDIRDATA structure.
    388  *
    389  * @param   ppDirData           Where to return the created VBOXCLIPBOARDDIRDATA structure on success.
    390  */
    391 int SharedClipboardURIDirDataAlloc(PVBOXCLIPBOARDDIRDATA *ppDirData)
    392 {
    393     PVBOXCLIPBOARDDIRDATA pDirData = (PVBOXCLIPBOARDDIRDATA)RTMemAlloc(sizeof(VBOXCLIPBOARDDIRDATA));
    394     if (!pDirData)
    395         return VERR_NO_MEMORY;
    396 
    397     int rc = SharedClipboardURIDirDataInit(pDirData);
    398     if (RT_SUCCESS(rc))
    399         *ppDirData = pDirData;
    400 
    401     return rc;
    402 }
    403 
    404 /**
    405  * Frees a VBOXCLIPBOARDDIRDATA structure.
    406  *
    407  * @param   pDirData           Where to return the created VBOXCLIPBOARDDIRDATA structure on success.
    408  */
    409 void SharedClipboardURIDirDataFree(PVBOXCLIPBOARDDIRDATA pDirData)
    410 {
    411     if (!pDirData)
    412         return;
    413 
    414     SharedClipboardURIDirDataDestroy(pDirData);
    415     RTMemFree(pDirData);
    416 }
    417 
    418 /**
    419  * Initializes a VBOXCLIPBOARDDIRDATA structure.
    420  *
    421  * @param   pDirData            VBOXCLIPBOARDDIRDATA structure to initialize.
    422  */
    423 int SharedClipboardURIDirDataInit(PVBOXCLIPBOARDDIRDATA pDirData)
    424 {
    425     RT_BZERO(pDirData, sizeof(VBOXCLIPBOARDDIRDATA));
    426 
    427     return VINF_SUCCESS;
    428 }
    429 
    430 /**
    431  * Destroys a VBOXCLIPBOARDDIRDATA structure.
    432  *
    433  * @param   pDirData            VBOXCLIPBOARDDIRDATA structure to destroy.
    434  */
    435 void SharedClipboardURIDirDataDestroy(PVBOXCLIPBOARDDIRDATA pDirData)
    436 {
    437     if (!pDirData)
    438         return;
    439 
    440     if (pDirData->pszPath)
    441     {
    442         Assert(pDirData->cbPath);
    443         RTStrFree(pDirData->pszPath);
    444         pDirData->pszPath = NULL;
    445     }
    446 }
    447 
    448 /**
    449  * Duplicates (allocates) a VBOXCLIPBOARDDIRDATA structure.
    450  *
    451  * @returns Duplicated VBOXCLIPBOARDDIRDATA structure on success.
    452  * @param   pDirData            VBOXCLIPBOARDDIRDATA to duplicate.
    453  */
    454 PVBOXCLIPBOARDDIRDATA SharedClipboardURIDirDataDup(PVBOXCLIPBOARDDIRDATA pDirData)
    455 {
    456     AssertPtrReturn(pDirData, NULL);
    457 
    458     PVBOXCLIPBOARDDIRDATA pDirDataDup = (PVBOXCLIPBOARDDIRDATA)RTMemAllocZ(sizeof(VBOXCLIPBOARDDIRDATA));
    459     if (pDirDataDup)
    460     {
    461         *pDirDataDup = *pDirData;
    462 
    463         if (pDirData->pszPath)
    464         {
    465             pDirDataDup->pszPath = RTStrDup(pDirData->pszPath);
    466             if (pDirDataDup->pszPath)
    467                 pDirDataDup->cbPath = pDirData->cbPath;
    468         }
    469     }
    470 
    471     return pDirDataDup;
    472 }
    473 
    474 /**
    475  * Returns whether given clipboard directory data is valid or not.
    476  *
    477  * @returns \c true if valid, \c false if not.
    478  * @param   pDirData            Clipboard directory data to validate.
    479  */
    480 bool SharedClipboardURIDirDataIsValid(PVBOXCLIPBOARDDIRDATA pDirData)
    481 {
    482     if (   !pDirData->cbPath
    483         || pDirData->cbPath > RTPATH_MAX)
    484         return false;
    485 
    486     if (!RTStrIsValidEncoding(pDirData->pszPath))
    487         return false;
    488 
    489     return true;
    490 }
    491 
    492 /**
    493  * Initializes a VBOXCLIPBOARDFILEHDR structure.
    494  *
    495  * @param   pDirData            VBOXCLIPBOARDFILEHDR structure to initialize.
    496  */
    497 int SharedClipboardURIFileHdrInit(PVBOXCLIPBOARDFILEHDR pFileHdr)
    498 {
    499     RT_BZERO(pFileHdr, sizeof(VBOXCLIPBOARDFILEHDR));
    500 
    501     return VINF_SUCCESS;
    502 }
    503 
    504 /**
    505  * Destroys a VBOXCLIPBOARDFILEHDR structure.
    506  *
    507  * @param   pFileHdr            VBOXCLIPBOARDFILEHDR structure to destroy.
    508  */
    509 void SharedClipboardURIFileHdrDestroy(PVBOXCLIPBOARDFILEHDR pFileHdr)
    510 {
    511     if (!pFileHdr)
    512         return;
    513 
    514     if (pFileHdr->pszFilePath)
    515     {
    516         Assert(pFileHdr->pszFilePath);
    517         RTStrFree(pFileHdr->pszFilePath);
    518         pFileHdr->pszFilePath = NULL;
    519     }
    520 }
    521 
    522 /**
    523  * Frees a VBOXCLIPBOARDFILEHDR structure.
    524  *
    525  * @param   pFileHdr            VBOXCLIPBOARDFILEHDR structure to free.
    526  */
    527 void SharedClipboardURIFileHdrFree(PVBOXCLIPBOARDFILEHDR pFileHdr)
    528 {
    529     if (!pFileHdr)
    530         return;
    531 
    532     SharedClipboardURIFileHdrDestroy(pFileHdr);
    533 
    534     RTMemFree(pFileHdr);
    535     pFileHdr = NULL;
    536 }
    537 
    538 /**
    539  * Duplicates (allocates) a VBOXCLIPBOARDFILEHDR structure.
    540  *
    541  * @returns Duplicated VBOXCLIPBOARDFILEHDR structure on success.
    542  * @param   pFileHdr            VBOXCLIPBOARDFILEHDR to duplicate.
    543  */
    544 PVBOXCLIPBOARDFILEHDR SharedClipboardURIFileHdrDup(PVBOXCLIPBOARDFILEHDR pFileHdr)
    545 {
    546     AssertPtrReturn(pFileHdr, NULL);
    547 
    548     PVBOXCLIPBOARDFILEHDR pFileHdrDup = (PVBOXCLIPBOARDFILEHDR)RTMemAllocZ(sizeof(VBOXCLIPBOARDFILEHDR));
    549     if (pFileHdrDup)
    550     {
    551         *pFileHdrDup = *pFileHdr;
    552 
    553         if (pFileHdr->pszFilePath)
    554         {
    555             pFileHdrDup->pszFilePath = RTStrDup(pFileHdr->pszFilePath);
    556             if (pFileHdrDup->pszFilePath)
    557                 pFileHdrDup->cbFilePath = pFileHdrDup->cbFilePath;
    558         }
    559     }
    560 
    561     return pFileHdrDup;
    562 }
    563 
    564 /**
    565  * Returns whether a given clipboard file header is valid or not.
    566  *
    567  * @returns \c true if valid, \c false if not.
    568  * @param   pFileHdr            Clipboard file header to validate.
    569  * @param   pListHdr            Data header to use for validation.
    570  */
    571 bool SharedClipboardURIFileHdrIsValid(PVBOXCLIPBOARDFILEHDR pFileHdr, PVBOXCLIPBOARDLISTHDR pListHdr)
    572 {
    573     if (   !pFileHdr->cbFilePath
    574         || pFileHdr->cbFilePath > RTPATH_MAX)
    575         return false;
    576 
    577     if (!RTStrIsValidEncoding(pFileHdr->pszFilePath))
    578         return false;
    579 
    580     if (pFileHdr->cbSize > pListHdr->cbTotalSize)
    581         return false;
    582 
    583     return true;
    584 }
    585 
    586 /**
    587  * Destroys a VBOXCLIPBOARDFILEDATA structure.
    588  *
    589  * @param   pFileData           VBOXCLIPBOARDFILEDATA structure to destroy.
    590  */
    591 void SharedClipboardURIFileDataDestroy(PVBOXCLIPBOARDFILEDATA pFileData)
    592 {
    593     if (!pFileData)
    594         return;
    595 
    596     if (pFileData->pvData)
    597     {
    598         Assert(pFileData->cbData);
    599         RTMemFree(pFileData->pvData);
    600         pFileData->pvData = NULL;
    601     }
    602 }
    603 
    604 /**
    605  * Duplicates (allocates) a VBOXCLIPBOARDFILEDATA structure.
    606  *
    607  * @returns Duplicated VBOXCLIPBOARDFILEDATA structure on success.
    608  * @param   pFileData           VBOXCLIPBOARDFILEDATA to duplicate.
    609  */
    610 PVBOXCLIPBOARDFILEDATA SharedClipboardURIFileDataDup(PVBOXCLIPBOARDFILEDATA pFileData)
    611 {
    612     AssertPtrReturn(pFileData, NULL);
    613 
    614     PVBOXCLIPBOARDFILEDATA pFileDataDup = (PVBOXCLIPBOARDFILEDATA)RTMemAllocZ(sizeof(VBOXCLIPBOARDFILEDATA));
    615     if (pFileDataDup)
    616     {
    617         *pFileDataDup = *pFileData;
    618 
    619         if (pFileData->pvData)
    620         {
    621             pFileDataDup->pvData = RTMemDup(pFileData->pvData, pFileData->cbData);
    622             if (pFileDataDup->pvData)
    623                 pFileDataDup->cbData = pFileDataDup->cbData;
    624         }
    625 
    626         if (pFileData->pvChecksum)
    627         {
    628             pFileDataDup->pvChecksum = RTMemDup(pFileData->pvChecksum, pFileData->cbChecksum);
    629             if (pFileDataDup->pvChecksum)
    630                 pFileDataDup->cbChecksum = pFileData->cbChecksum;
    631         }
    632     }
    633 
    634     return pFileDataDup;
    635 }
    636 
    637 /**
    638  * Returns whether given clipboard file data is valid or not.
    639  *
    640  * @returns \c true if valid, \c false if not.
    641  * @param   pFileData           Clipboard file data to validate.
    642  * @param   pListHdr            Data header to use for validation.
    643  */
    644 bool SharedClipboardURIFileDataIsValid(PVBOXCLIPBOARDFILEDATA pFileData, PVBOXCLIPBOARDLISTHDR pListHdr)
    645 {
    646     RT_NOREF(pFileData, pListHdr);
    647     return true;
    648 }
    649 #endif
    650464
    651465/**
     
    806620}
    807621
     622/**
     623 * Creates a new list handle (local only).
     624 *
     625 * @returns New List handle on success, or SHAREDCLIPBOARDLISTHANDLE_INVALID on error.
     626 * @param   pTransfer           URI clipboard transfer to create new list handle for.
     627 */
    808628static SHAREDCLIPBOARDLISTHANDLE sharedClipboardURITransferListHandleNew(PSHAREDCLIPBOARDURITRANSFER pTransfer)
    809629{
     
    813633}
    814634
     635/**
     636 * Opens a list.
     637 *
     638 * @returns VBox status code.
     639 * @param   pTransfer           URI clipboard transfer to handle.
     640 * @param   pOpenParms          List open parameters to use for opening.
     641 * @param   phList              Where to store the List handle of opened list on success.
     642 */
    815643int SharedClipboardURITransferListOpen(PSHAREDCLIPBOARDURITRANSFER pTransfer, PVBOXCLIPBOARDLISTOPENPARMS pOpenParms,
    816644                                       PSHAREDCLIPBOARDLISTHANDLE phList)
     
    830658        if (pInfo)
    831659        {
    832             if (   !pOpenParms->pszPath
    833                 || !strlen(pOpenParms->pszPath))
    834                 RTStrAPrintf(&pOpenParms->pszPath, "C:\\Temp"); /** @todo FIX !!!! */
    835 
    836660            RTFSOBJINFO objInfo;
    837661            rc = RTPathQueryInfo(pOpenParms->pszPath, &objInfo, RTFSOBJATTRADD_NOTHING);
     
    842666            else if (RTFS_IS_FILE(objInfo.Attr.fMode))
    843667            {
    844                 rc = RTFileOpen(&pInfo->u.Local.hFile, pOpenParms->pszPath, RTFILE_O_READ | RTFILE_O_DENY_WRITE);
     668                rc = RTFileOpen(&pInfo->u.Local.hFile, pOpenParms->pszPath,
     669                                RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
    845670            }
    846671            else if (RTFS_IS_SYMLINK(objInfo.Attr.fMode))
     
    902727}
    903728
     729/**
     730 * Closes a list.
     731 *
     732 * @returns VBox status code.
     733 * @param   pTransfer           URI clipboard transfer to handle.
     734 * @param   hList               Handle of list to close.
     735 */
    904736int SharedClipboardURITransferListClose(PSHAREDCLIPBOARDURITRANSFER pTransfer, SHAREDCLIPBOARDLISTHANDLE hList)
    905737{
     
    943775}
    944776
     777/**
     778 * Adds a file to a list heaer.
     779 *
     780 * @returns VBox status code.
     781 * @param   pHdr                List header to add file to.
     782 * @param   pszPath             Path of file to add.
     783 */
    945784static int sharedClipboardURITransferListHdrAddFile(PVBOXCLIPBOARDLISTHDR pHdr, const char *pszPath)
    946785{
     
    957796}
    958797
     798/**
     799 * Builds a list header, internal version.
     800 *
     801 * @returns VBox status code.
     802 * @param   pHdr                Where to store the build list header.
     803 * @param   pcszSrcPath         Source path of list.
     804 * @param   pcszDstPath         Destination path of list.
     805 * @param   pcszDstBase         Destination base path.
     806 * @param   cchDstBase          Number of charaters of destination base path.
     807 */
    959808static int sharedClipboardURITransferListHdrFromDir(PVBOXCLIPBOARDLISTHDR pHdr,
    960809                                                    const char *pcszSrcPath, const char *pcszDstPath,
     
    1067916}
    1068917
     918/**
     919 * Retrieves the header of a Shared Clipboard list.
     920 *
     921 * @returns VBox status code.
     922 * @param   pTransfer           URI clipboard transfer to handle.
     923 * @param   hList               Handle of list to get header for.
     924 * @param   pHdr                Where to store the returned list header information.
     925 */
    1069926int SharedClipboardURITransferListGetHeader(PSHAREDCLIPBOARDURITRANSFER pTransfer, SHAREDCLIPBOARDLISTHANDLE hList,
    1070927                                            PVBOXCLIPBOARDLISTHDR pHdr)
     
    11741031}
    11751032
     1033/**
     1034 * Reads a single Shared Clipboard list entry.
     1035 *
     1036 * @returns VBox status code.
     1037 * @param   pTransfer           URI clipboard transfer to handle.
     1038 * @param   hList               List handle of list to read from.
     1039 * @param   pEntry              Where to store the read information.
     1040 */
    11761041int SharedClipboardURITransferListRead(PSHAREDCLIPBOARDURITRANSFER pTransfer, SHAREDCLIPBOARDLISTHANDLE hList,
    11771042                                       PVBOXCLIPBOARDLISTENTRY pEntry)
     
    11921057            AssertPtr(pInfo);
    11931058
     1059            LogFlowFunc(("\tfMode=%RU32, pszPath=%s\n", pInfo->fMode, pInfo->OpenParms.pszPath));
     1060
    11941061            if (RTFS_IS_DIRECTORY(pInfo->fMode))
    11951062            {
    1196                 size_t        cbDirEntry = 0;
    1197                 PRTDIRENTRYEX pDirEntry  = NULL;
    1198                 rc = RTDirReadExA(pInfo->u.Local.hDirRoot, &pDirEntry, &cbDirEntry, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
    1199                 if (RT_SUCCESS(rc))
     1063                for (;;)
    12001064                {
    1201                     switch (pDirEntry->Info.Attr.fMode & RTFS_TYPE_MASK)
     1065                    bool fSkipEntry = false; /* Whether to skip an entry in the enumeration. */
     1066
     1067                    size_t        cbDirEntry = 0;
     1068                    PRTDIRENTRYEX pDirEntry  = NULL;
     1069                    rc = RTDirReadExA(pInfo->u.Local.hDirRoot, &pDirEntry, &cbDirEntry, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     1070                    if (RT_SUCCESS(rc))
    12021071                    {
    1203                         case RTFS_TYPE_DIRECTORY:
     1072                        switch (pDirEntry->Info.Attr.fMode & RTFS_TYPE_MASK)
    12041073                        {
    1205                             /* Skip "." and ".." entries. */
    1206                             if (RTDirEntryExIsStdDotLink(pDirEntry))
     1074                            case RTFS_TYPE_DIRECTORY:
     1075                            {
     1076                                LogFlowFunc(("Directory: %s\n", pDirEntry->szName));
     1077
     1078                                /* Skip "." and ".." entries. */
     1079                                if (RTDirEntryExIsStdDotLink(pDirEntry))
     1080                                    fSkipEntry = true;
     1081
     1082                                RT_FALL_THROUGH();
     1083                            }
     1084
     1085                            case RTFS_TYPE_FILE:
     1086                            {
     1087                                LogFlowFunc(("File: %s\n", pDirEntry->szName));
     1088
     1089                                pEntry->pvInfo = (PSHAREDCLIPBOARDFSOBJINFO)RTMemAlloc(sizeof(SHAREDCLIPBOARDFSOBJINFO));
     1090                                if (pEntry->pvInfo)
     1091                                {
     1092                                    rc = RTStrCopy(pEntry->pszName, pEntry->cbName, pDirEntry->szName);
     1093                                    if (RT_SUCCESS(rc))
     1094                                    {
     1095                                        SharedClipboardFsObjFromIPRT(PSHAREDCLIPBOARDFSOBJINFO(pEntry->pvInfo), &pDirEntry->Info);
     1096
     1097                                        pEntry->cbInfo = sizeof(SHAREDCLIPBOARDFSOBJINFO);
     1098                                        pEntry->fInfo  = VBOX_SHAREDCLIPBOARD_INFO_FLAG_FSOBJINFO;
     1099                                    }
     1100                                }
     1101                                else
     1102                                    rc = VERR_NO_MEMORY;
    12071103                                break;
    1208 
    1209                             RT_FALL_THROUGH();
     1104                            }
     1105
     1106                            case RTFS_TYPE_SYMLINK:
     1107                            {
     1108                                /** @todo Not implemented yet. */
     1109                                break;
     1110                            }
     1111
     1112                            default:
     1113                                break;
    12101114                        }
    12111115
    1212                         case RTFS_TYPE_FILE:
    1213                         {
    1214                             pEntry->pvInfo = (PSHAREDCLIPBOARDFSOBJINFO)RTMemAlloc(sizeof(SHAREDCLIPBOARDFSOBJINFO));
    1215                             if (pEntry->pvInfo)
    1216                             {
    1217                                 SharedClipboardFsObjFromIPRT(PSHAREDCLIPBOARDFSOBJINFO(pEntry->pvInfo), &pDirEntry->Info);
    1218 
    1219                                 pEntry->cbInfo = sizeof(SHAREDCLIPBOARDFSOBJINFO);
    1220                                 pEntry->fInfo  = 0; /** @todo Implement. */
    1221                             }
    1222                             else
    1223                                 rc = VERR_NO_MEMORY;
    1224                             break;
    1225                         }
    1226 
    1227                         case RTFS_TYPE_SYMLINK:
    1228                         {
    1229                             /** @todo Not implemented yet. */
    1230                             break;
    1231                         }
    1232 
    1233                         default:
    1234                             break;
     1116                        RTDirReadExAFree(&pDirEntry, &cbDirEntry);
    12351117                    }
    12361118
    1237                     RTDirReadExAFree(&pDirEntry, &cbDirEntry);
     1119                    if (   !fSkipEntry /* Do we have a valid entry? Bail out. */
     1120                        || RT_FAILURE(rc))
     1121                    {
     1122                        break;
     1123                    }
    12381124                }
    12391125            }
    12401126            else if (RTFS_IS_FILE(pInfo->fMode))
    12411127            {
     1128                LogFlowFunc(("\tSingle file: %s\n", pInfo->OpenParms.pszPath));
     1129
    12421130                RTFSOBJINFO objInfo;
    12431131                rc = RTFileQueryInfo(pInfo->u.Local.hFile, &objInfo, RTFSOBJATTRADD_NOTHING);
     
    12471135                    if (pEntry->pvInfo)
    12481136                    {
    1249                         SharedClipboardFsObjFromIPRT(PSHAREDCLIPBOARDFSOBJINFO(pEntry->pvInfo), &objInfo);
    1250 
    1251                         pEntry->cbInfo = sizeof(SHAREDCLIPBOARDFSOBJINFO);
    1252                         pEntry->fInfo  = 0; /** @todo Implement. */
     1137                        rc = RTStrCopy(pEntry->pszName, pEntry->cbName, pInfo->OpenParms.pszPath);
     1138                        if (RT_SUCCESS(rc))
     1139                        {
     1140                            SharedClipboardFsObjFromIPRT(PSHAREDCLIPBOARDFSOBJINFO(pEntry->pvInfo), &objInfo);
     1141
     1142                            pEntry->cbInfo = sizeof(SHAREDCLIPBOARDFSOBJINFO);
     1143                            pEntry->fInfo  = VBOX_SHAREDCLIPBOARD_INFO_FLAG_FSOBJINFO;
     1144                        }
    12531145                    }
    12541146                    else
     
    12941186}
    12951187
     1188/**
     1189 * Returns whether a given list handle is valid or not.
     1190 *
     1191 * @returns \c true if list handle is valid, \c false if not.
     1192 * @param   pTransfer           URI clipboard transfer to handle.
     1193 * @param   hList               List handle to check.
     1194 */
    12961195bool SharedClipboardURITransferListHandleIsValid(PSHAREDCLIPBOARDURITRANSFER pTransfer, SHAREDCLIPBOARDLISTHANDLE hList)
    12971196{
     
    13731272}
    13741273
     1274int SharedClipboardURILTransferSetRoots(PSHAREDCLIPBOARDURITRANSFER pTransfer, const char *pszRoots, size_t cbRoots)
     1275{
     1276    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
     1277    AssertPtrReturn(pszRoots,  VERR_INVALID_POINTER);
     1278    AssertReturn(cbRoots,      VERR_INVALID_PARAMETER);
     1279
     1280    if (!RTStrIsValidEncoding(pszRoots))
     1281        return VERR_INVALID_PARAMETER;
     1282
     1283    int rc = VINF_SUCCESS;
     1284
     1285    pTransfer->lstRootEntries.clear();
     1286
     1287    pTransfer->lstRootEntries = RTCString(pszRoots, cbRoots - 1).split("\r\n");
     1288
     1289    LogFlowFunc(("cRoots=%RU32\n", pTransfer->lstRootEntries.size()));
     1290
     1291    LogFlowFuncLeaveRC(rc);
     1292    return rc;
     1293}
     1294
    13751295/**
    13761296 * Resets an clipboard URI transfer.
     
    13981318
    13991319    return pTransfer->pArea;
     1320}
     1321
     1322int SharedClipboardURILTransferGetRoots(PSHAREDCLIPBOARDURITRANSFER pTransfer, char **ppszRoots, uint32_t *pcRoots)
     1323{
     1324    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
     1325    AssertPtrReturn(ppszRoots, VERR_INVALID_POINTER);
     1326
     1327    int rc = VINF_SUCCESS;
     1328
     1329    if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_LOCAL)
     1330    {
     1331        char *pszRoots = NULL;
     1332
     1333        for (size_t i = 0; i < pTransfer->lstRootEntries.size(); ++i)
     1334        {
     1335            if (pszRoots)
     1336                rc = RTStrAAppend(&pszRoots, "\r\n");
     1337            if (RT_SUCCESS(rc))
     1338                rc = RTStrAAppend(&pszRoots, pTransfer->lstRootEntries.at(i).c_str());
     1339
     1340            if (RT_FAILURE(rc))
     1341                break;
     1342        }
     1343
     1344        if (RT_SUCCESS(rc))
     1345        {
     1346            LogFlowFunc(("Roots (%RU32):\n%s\n", pTransfer->lstRootEntries.size(), pszRoots));
     1347
     1348            *ppszRoots = pszRoots;
     1349            *pcRoots     = (uint32_t)pTransfer->lstRootEntries.size();
     1350        }
     1351        else
     1352        {
     1353            if (pszRoots)
     1354                RTStrFree(pszRoots);
     1355        }
     1356    }
     1357    else if (pTransfer->State.enmSource == SHAREDCLIPBOARDSOURCE_REMOTE)
     1358    {
     1359        if (pTransfer->ProviderIface.pfnGetRoots)
     1360            rc = pTransfer->ProviderIface.pfnGetRoots(&pTransfer->ProviderCtx, ppszRoots, pcRoots);
     1361        else
     1362            rc = VERR_NOT_SUPPORTED;
     1363    }
     1364
     1365    LogFlowFuncLeaveRC(rc);
     1366    return rc;
    14001367}
    14011368
     
    15371504    }
    15381505    else
    1539         rc = VERR_ALREADY_EXISTS;
     1506        rc = VINF_SUCCESS;
    15401507
    15411508    LogFlowFuncLeaveRC(rc);
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp

    r79497 r79672  
    10301030            LogRel(("Shared Clipboard: Adding guest file '%s'\n", pszFileUtf8));
    10311031
    1032         #if 0
    1033             char    *pszFileURI;
    1034             uint32_t cchFileURI;
    1035             rc = SharedClipboardMetaDataConvertToFormat(pszFileUtf8, strlen(pszFileUtf8), SHAREDCLIPBOARDMETADATAFMT_URI_LIST,
    1036                                                         (void **)&pszFileURI, &cchFileURI);
    1037             if (RT_SUCCESS(rc))
    1038             {
    1039                 LogFlowFunc(("\tURI is: %s (%RU32)\n", pszFileURI, cchFileURI));
    1040 
    1041                 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, pszFileURI, cchFileURI);
    1042                 if (RT_SUCCESS(rc))
    1043                     cchFiles += cchFileURI;
    1044 
    1045                 RTStrFree(pszFileURI);
    1046             }
    1047         #endif
     1032            rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, pszFileUtf8, strlen(pszFileUtf8));
     1033            cchFiles += (uint32_t)strlen(pszFileUtf8);
    10481034        }
    10491035
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-uri.cpp

    r79630 r79672  
    7373}
    7474
     75DECLCALLBACK(int) vboxSvcClipboardURIGetRoots(PSHAREDCLIPBOARDPROVIDERCTX pCtx,
     76                                              char **ppapszRoots, uint32_t *pcRoots)
     77{
     78    LogFlowFuncEnter();
     79
     80    PVBOXCLIPBOARDCLIENT pClient = (PVBOXCLIPBOARDCLIENT)pCtx->pvUser;
     81    AssertPtr(pClient);
     82
     83    int rc;
     84
     85    size_t   cbRootsRecv = 0;
     86
     87    char    *pszRoots = NULL;
     88    uint32_t cRoots   = 0;
     89
     90    /* There might be more than one message needed for retrieving all root items. */
     91    for (;;)
     92    {
     93        PVBOXCLIPBOARDCLIENTMSG pMsg = vboxSvcClipboardMsgAlloc(VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ROOTS,
     94                                                                VBOX_SHARED_CLIPBOARD_CPARMS_ROOTS);
     95        if (pMsg)
     96        {
     97            HGCMSvcSetU32(&pMsg->m_paParms[0], 0 /* uContextID */);
     98            HGCMSvcSetU32(&pMsg->m_paParms[1], 0 /* fRoots */);
     99            HGCMSvcSetU32(&pMsg->m_paParms[2], 0 /* fMore */);
     100            HGCMSvcSetU32(&pMsg->m_paParms[3], 0 /* cRoots */);
     101
     102            uint32_t  cbData = _64K;
     103            void     *pvData = RTMemAlloc(cbData);
     104            AssertPtrBreakStmt(pvData, rc = VERR_NO_MEMORY);
     105
     106            HGCMSvcSetU32(&pMsg->m_paParms[4], cbData);
     107            HGCMSvcSetPv (&pMsg->m_paParms[5], pvData, cbData);
     108
     109            rc = vboxSvcClipboardMsgAdd(pClient->pData, pMsg, true /* fAppend */);
     110            if (RT_SUCCESS(rc))
     111            {
     112                int rc2 = SharedClipboardURITransferEventRegister(pCtx->pTransfer,
     113                                                                  SHAREDCLIPBOARDURITRANSFEREVENTTYPE_GET_ROOTS);
     114                AssertRC(rc2);
     115
     116                vboxSvcClipboardClientWakeup(pClient);
     117            }
     118        }
     119        else
     120            rc = VERR_NO_MEMORY;
     121
     122        if (RT_SUCCESS(rc))
     123        {
     124            PSHAREDCLIPBOARDURITRANSFERPAYLOAD pPayload;
     125            rc = SharedClipboardURITransferEventWait(pCtx->pTransfer, SHAREDCLIPBOARDURITRANSFEREVENTTYPE_GET_ROOTS,
     126                                                     30 * 1000 /* Timeout in ms */, &pPayload);
     127            if (RT_SUCCESS(rc))
     128            {
     129                PVBOXCLIPBOARDROOTS pRoots = (PVBOXCLIPBOARDROOTS)pPayload->pvData;
     130                Assert(pPayload->cbData == sizeof(VBOXCLIPBOARDROOTS));
     131
     132                LogFlowFunc(("cbRoots=%RU32, fRoots=%RU32, fMore=%RTbool\n", pRoots->cbRoots, pRoots->fRoots, pRoots->fMore));
     133
     134                if (!pRoots->cbRoots)
     135                    break;
     136                AssertPtr(pRoots->pszRoots);
     137
     138                if (pszRoots == NULL)
     139                    pszRoots = (char *)RTMemDup((void *)pRoots->pszRoots, pRoots->cbRoots);
     140                else
     141                    pszRoots = (char *)RTMemRealloc(pszRoots, cbRootsRecv + pRoots->cbRoots);
     142
     143                AssertPtrBreakStmt(pszRoots, rc = VERR_NO_MEMORY);
     144
     145                cbRootsRecv += pRoots->cbRoots;
     146
     147                if (cbRootsRecv > _32M) /* Don't allow more than 32MB root entries for now. */
     148                {
     149                    rc = VERR_ALLOCATION_TOO_BIG; /** @todo Find a better rc. */
     150                    break;
     151                }
     152
     153                cRoots += pRoots->cRoots;
     154
     155                const bool fDone = !RT_BOOL(pRoots->fMore); /* More root entries to be retrieved? Otherwise bail out. */
     156
     157                SharedClipboardURITransferPayloadFree(pPayload);
     158
     159                if (fDone)
     160                    break;
     161            }
     162        }
     163
     164        if (RT_FAILURE(rc))
     165            break;
     166    }
     167
     168    if (RT_SUCCESS(rc))
     169    {
     170        LogFlowFunc(("cRoots=%RU32\n", cRoots));
     171
     172        *ppapszRoots = pszRoots;
     173        *pcRoots     = cRoots;
     174    }
     175    else
     176    {
     177        RTMemFree(pszRoots);
     178        pszRoots = NULL;
     179    }
     180
     181    LogFlowFuncLeave();
     182    return rc;
     183}
     184
    75185DECLCALLBACK(int) vboxSvcClipboardURIListOpen(PSHAREDCLIPBOARDPROVIDERCTX pCtx,
    76186                                              PVBOXCLIPBOARDLISTOPENPARMS pOpenParms, PSHAREDCLIPBOARDLISTHANDLE phList)
     
    403513                    break;
    404514            }
     515        }
     516    }
     517    else
     518        rc = VERR_INVALID_PARAMETER;
     519
     520    LogFlowFuncLeaveRC(rc);
     521    return rc;
     522}
     523
     524int VBoxSvcClipboardURIGetRoots(uint32_t cParms, VBOXHGCMSVCPARM paParms[],
     525                                PVBOXCLIPBOARDROOTS pRoots)
     526{
     527    int rc;
     528
     529    if (cParms == VBOX_SHARED_CLIPBOARD_CPARMS_ROOTS)
     530    {
     531        /* Note: Context ID (paParms[0]) not used yet. */
     532        rc = HGCMSvcGetU32(&paParms[1], &pRoots->fRoots);
     533        if (RT_SUCCESS(rc))
     534        {
     535            uint32_t fMore;
     536            rc = HGCMSvcGetU32(&paParms[2], &fMore);
     537            if (RT_SUCCESS(rc))
     538                pRoots->fMore = RT_BOOL(fMore);
     539        }
     540        if (RT_SUCCESS(rc))
     541            rc = HGCMSvcGetU32(&paParms[3], &pRoots->cRoots);
     542        if (RT_SUCCESS(rc))
     543        {
     544            uint32_t cbRoots;
     545            rc = HGCMSvcGetU32(&paParms[4], &cbRoots);
     546            if (RT_SUCCESS(rc))
     547                rc = HGCMSvcGetPv(&paParms[5], (void **)&pRoots->pszRoots, &pRoots->cbRoots);
     548
     549            AssertReturn(cbRoots == pRoots->cbRoots, VERR_INVALID_PARAMETER);
    405550        }
    406551    }
     
    582727            rc = HGCMSvcGetU32(&paParms[2], &pListEntry->fInfo);
    583728        if (RT_SUCCESS(rc))
    584             rc = HGCMSvcGetU32(&paParms[3], &pListEntry->cbInfo);
    585         if (RT_SUCCESS(rc))
    586             rc = HGCMSvcGetPv(&paParms[4], &pListEntry->pvInfo, &pListEntry->cbInfo);
     729            rc = HGCMSvcGetPv(&paParms[3], (void **)&pListEntry->pszName, &pListEntry->cbName);
     730        if (RT_SUCCESS(rc))
     731        {
     732            uint32_t cbInfo;
     733            rc = HGCMSvcGetU32(&paParms[4], &cbInfo);
     734            if (RT_SUCCESS(rc))
     735            {
     736                rc = HGCMSvcGetPv(&paParms[5], &pListEntry->pvInfo, &pListEntry->cbInfo);
     737                AssertReturn(cbInfo == pListEntry->cbInfo, VERR_INVALID_PARAMETER);
     738            }
     739        }
    587740
    588741        if (RT_SUCCESS(rc))
     
    846999                        if (enmDir == SHAREDCLIPBOARDURITRANSFERDIR_READ)
    8471000                        {
     1001                            creationCtx.Interface.pfnGetRoots      = vboxSvcClipboardURIGetRoots;
    8481002                            creationCtx.Interface.pfnListHdrRead   = vboxSvcClipboardURIListHdrRead;
    8491003                            creationCtx.Interface.pfnListEntryRead = vboxSvcClipboardURIListEntryRead;
     
    9211075        {
    9221076            rc = VBoxSvcClipboardURITransferHandleReply(pClient, pTransfer, cParms, paParms);
     1077            break;
     1078        }
     1079
     1080        case VBOX_SHARED_CLIPBOARD_GUEST_FN_ROOTS:
     1081        {
     1082            VBOXCLIPBOARDROOTS Roots;
     1083            rc = VBoxSvcClipboardURIGetRoots(cParms, paParms, &Roots);
     1084            if (RT_SUCCESS(rc))
     1085            {
     1086                void    *pvData = SharedClipboardURIRootsDup(&Roots);
     1087                uint32_t cbData = sizeof(VBOXCLIPBOARDROOTS);
     1088
     1089                PSHAREDCLIPBOARDURITRANSFERPAYLOAD pPayload;
     1090                rc = SharedClipboardURITransferPayloadAlloc(SHAREDCLIPBOARDURITRANSFEREVENTTYPE_GET_ROOTS,
     1091                                                            pvData, cbData, &pPayload);
     1092                if (RT_SUCCESS(rc))
     1093                    rc = SharedClipboardURITransferEventSignal(pTransfer, SHAREDCLIPBOARDURITRANSFEREVENTTYPE_GET_ROOTS,
     1094                                                               pPayload);
     1095            }
    9231096            break;
    9241097        }
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp

    r79632 r79672  
    507507     * Return information about the first message if one is pending in the list.
    508508     */
    509     PVBOXCLIPBOARDCLIENTMSG pFirstMsg = pClient->pData->queueMsg.first();
    510     if (pFirstMsg)
    511     {
    512         LogFlowFunc(("First message is: %RU32 %s (%RU32 parms)\n",
    513                      pFirstMsg->m_uMsg, VBoxSvcClipboardHostMsgToStr(pFirstMsg->m_uMsg), pFirstMsg->m_cParms));
    514 
    515         ASSERT_GUEST_MSG_RETURN(pFirstMsg->m_uMsg == idMsgExpected || idMsgExpected == UINT32_MAX,
    516                                 ("idMsg=%u (%s) cParms=%u, caller expected %u (%s) and %u\n",
    517                                  pFirstMsg->m_uMsg, VBoxSvcClipboardHostMsgToStr(pFirstMsg->m_uMsg), pFirstMsg->m_uMsg,
    518                                  idMsgExpected, VBoxSvcClipboardHostMsgToStr(idMsgExpected), cParms),
    519                                 VERR_MISMATCH);
    520         ASSERT_GUEST_MSG_RETURN(pFirstMsg->m_cParms == cParms,
    521                                 ("idMsg=%u (%s) cParms=%u, caller expected %u (%s) and %u\n",
    522                                  pFirstMsg->m_uMsg, VBoxSvcClipboardHostMsgToStr(pFirstMsg->m_uMsg), pFirstMsg->m_cParms,
    523                                  idMsgExpected, VBoxSvcClipboardHostMsgToStr(idMsgExpected), cParms),
    524                                 VERR_WRONG_PARAMETER_COUNT);
    525 
    526         /* Check the parameter types. */
    527         for (uint32_t i = 0; i < cParms; i++)
    528             ASSERT_GUEST_MSG_RETURN(pFirstMsg->m_paParms[i].type == paParms[i].type,
    529                                     ("param #%u: type %u, caller expected %u (idMsg=%u %s)\n", i, pFirstMsg->m_paParms[i].type,
    530                                      paParms[i].type, pFirstMsg->m_uMsg, VBoxSvcClipboardHostMsgToStr(pFirstMsg->m_uMsg)),
    531                                     VERR_WRONG_PARAMETER_TYPE);
    532         /*
    533          * Copy out the parameters.
    534          *
    535          * No assertions on buffer overflows, and keep going till the end so we can
    536          * communicate all the required buffer sizes.
    537          */
    538         int rc = VINF_SUCCESS;
    539         for (uint32_t i = 0; i < cParms; i++)
    540             switch (pFirstMsg->m_paParms[i].type)
    541             {
    542                 case VBOX_HGCM_SVC_PARM_32BIT:
    543                     paParms[i].u.uint32 = pFirstMsg->m_paParms[i].u.uint32;
    544                     break;
    545 
    546                 case VBOX_HGCM_SVC_PARM_64BIT:
    547                     paParms[i].u.uint64 = pFirstMsg->m_paParms[i].u.uint64;
    548                     break;
    549 
    550                 case VBOX_HGCM_SVC_PARM_PTR:
     509    if (!pClient->pData->queueMsg.isEmpty())
     510    {
     511        PVBOXCLIPBOARDCLIENTMSG pFirstMsg = pClient->pData->queueMsg.first();
     512        if (pFirstMsg)
     513        {
     514            LogFlowFunc(("First message is: %RU32 %s (%RU32 parms)\n",
     515                         pFirstMsg->m_uMsg, VBoxSvcClipboardHostMsgToStr(pFirstMsg->m_uMsg), pFirstMsg->m_cParms));
     516
     517            ASSERT_GUEST_MSG_RETURN(pFirstMsg->m_uMsg == idMsgExpected || idMsgExpected == UINT32_MAX,
     518                                    ("idMsg=%u (%s) cParms=%u, caller expected %u (%s) and %u\n",
     519                                     pFirstMsg->m_uMsg, VBoxSvcClipboardHostMsgToStr(pFirstMsg->m_uMsg), pFirstMsg->m_cParms,
     520                                     idMsgExpected, VBoxSvcClipboardHostMsgToStr(idMsgExpected), cParms),
     521                                    VERR_MISMATCH);
     522            ASSERT_GUEST_MSG_RETURN(pFirstMsg->m_cParms == cParms,
     523                                    ("idMsg=%u (%s) cParms=%u, caller expected %u (%s) and %u\n",
     524                                     pFirstMsg->m_uMsg, VBoxSvcClipboardHostMsgToStr(pFirstMsg->m_uMsg), pFirstMsg->m_cParms,
     525                                     idMsgExpected, VBoxSvcClipboardHostMsgToStr(idMsgExpected), cParms),
     526                                    VERR_WRONG_PARAMETER_COUNT);
     527
     528            /* Check the parameter types. */
     529            for (uint32_t i = 0; i < cParms; i++)
     530                ASSERT_GUEST_MSG_RETURN(pFirstMsg->m_paParms[i].type == paParms[i].type,
     531                                        ("param #%u: type %u, caller expected %u (idMsg=%u %s)\n", i, pFirstMsg->m_paParms[i].type,
     532                                         paParms[i].type, pFirstMsg->m_uMsg, VBoxSvcClipboardHostMsgToStr(pFirstMsg->m_uMsg)),
     533                                        VERR_WRONG_PARAMETER_TYPE);
     534            /*
     535             * Copy out the parameters.
     536             *
     537             * No assertions on buffer overflows, and keep going till the end so we can
     538             * communicate all the required buffer sizes.
     539             */
     540            int rc = VINF_SUCCESS;
     541            for (uint32_t i = 0; i < cParms; i++)
     542                switch (pFirstMsg->m_paParms[i].type)
    551543                {
    552                     uint32_t const cbSrc = pFirstMsg->m_paParms[i].u.pointer.size;
    553                     uint32_t const cbDst = paParms[i].u.pointer.size;
    554                     paParms[i].u.pointer.size = cbSrc; /** @todo Check if this is safe in other layers...
    555                                                         * Update: Safe, yes, but VMMDevHGCM doesn't pass it along. */
    556                     if (cbSrc <= cbDst)
    557                         memcpy(paParms[i].u.pointer.addr, pFirstMsg->m_paParms[i].u.pointer.addr, cbSrc);
    558                     else
    559                         rc = VERR_BUFFER_OVERFLOW;
    560                     break;
     544                    case VBOX_HGCM_SVC_PARM_32BIT:
     545                        paParms[i].u.uint32 = pFirstMsg->m_paParms[i].u.uint32;
     546                        break;
     547
     548                    case VBOX_HGCM_SVC_PARM_64BIT:
     549                        paParms[i].u.uint64 = pFirstMsg->m_paParms[i].u.uint64;
     550                        break;
     551
     552                    case VBOX_HGCM_SVC_PARM_PTR:
     553                    {
     554                        uint32_t const cbSrc = pFirstMsg->m_paParms[i].u.pointer.size;
     555                        uint32_t const cbDst = paParms[i].u.pointer.size;
     556                        paParms[i].u.pointer.size = cbSrc; /** @todo Check if this is safe in other layers...
     557                                                            * Update: Safe, yes, but VMMDevHGCM doesn't pass it along. */
     558                        if (cbSrc <= cbDst)
     559                            memcpy(paParms[i].u.pointer.addr, pFirstMsg->m_paParms[i].u.pointer.addr, cbSrc);
     560                        else
     561                        {
     562                            AssertMsgFailed(("#%u: cbSrc=%RU32 is bigger than cbDst=%RU32\n", i, cbSrc, cbDst));
     563                            rc = VERR_BUFFER_OVERFLOW;
     564                        }
     565                        break;
     566                    }
     567
     568                    default:
     569                        AssertMsgFailed(("#%u: %u\n", i, pFirstMsg->m_paParms[i].type));
     570                        rc = VERR_INTERNAL_ERROR;
     571                        break;
    561572                }
    562 
    563                 default:
    564                     AssertMsgFailed(("#%u: %u\n", i, pFirstMsg->m_paParms[i].type));
    565                     rc = VERR_INTERNAL_ERROR;
    566                     break;
     573            if (RT_SUCCESS(rc))
     574            {
     575                /*
     576                 * Complete the message and remove the pending message unless the
     577                 * guest raced us and cancelled this call in the meantime.
     578                 */
     579                AssertPtr(g_pHelpers);
     580                rc = g_pHelpers->pfnCallComplete(hCall, rc);
     581
     582                LogFlowFunc(("[Client %RU32] pfnCallComplete -> %Rrc\n", pClient->uClientID, rc));
     583
     584                if (rc != VERR_CANCELLED)
     585                {
     586                    pClient->pData->queueMsg.removeFirst();
     587                    vboxSvcClipboardMsgFree(pFirstMsg);
     588                }
     589
     590                return VINF_HGCM_ASYNC_EXECUTE; /* The caller must not complete it. */
    567591            }
    568         if (RT_SUCCESS(rc))
    569         {
    570             /*
    571              * Complete the message and remove the pending message unless the
    572              * guest raced us and cancelled this call in the meantime.
    573              */
    574             AssertPtr(g_pHelpers);
    575             rc = g_pHelpers->pfnCallComplete(hCall, rc);
    576 
    577             LogFlowFunc(("[Client %RU32] pfnCallComplete -> %Rrc\n", pClient->uClientID, rc));
    578 
    579             if (rc != VERR_CANCELLED)
    580             {
    581                 pClient->pData->queueMsg.removeFirst();
    582                 vboxSvcClipboardMsgFree(pFirstMsg);
    583             }
    584 
    585             return VINF_HGCM_ASYNC_EXECUTE; /* The caller must not complete it. */
     592
     593            LogFlowFunc(("[Client %RU32] Returning %Rrc\n", pClient->uClientID, rc));
     594            return rc;
    586595        }
    587 
    588         LogFlowFunc(("[Client %RU32] Returning %Rrc\n", pClient->uClientID, rc));
    589         return rc;
    590596    }
    591597
     
    13911397#ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    13921398            rc = vboxSvcClipboardURIHandler(pClient, callHandle, u32Function, cParms, paParms, tsArrival);
    1393             if (RT_SUCCESS(rc))
    1394             {
    1395                 /* The URI handler does deferring on its own. */
    1396                 fDefer = true;
    1397             }
     1399
     1400            /* The URI handler does deferring on its own, so never do any call completion here. */
     1401            fDefer = true;
    13981402#else
    13991403            rc = VERR_NOT_IMPLEMENTED;
Note: See TracChangeset for help on using the changeset viewer.

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