Index: trunk/include/VBox/GuestHost/SharedClipboard-transfers.h
===================================================================
--- trunk/include/VBox/GuestHost/SharedClipboard-transfers.h	(revision 87082)
+++ trunk/include/VBox/GuestHost/SharedClipboard-transfers.h	(revision 87452)
@@ -595,7 +595,7 @@
 /**
  * Structure maintaining clipboard transfer provider context data.
- * This is handed in to the provider implementation callbacks.
- */
-typedef struct SHCLPROVIDERCTX
+ * This is handed in to the provider interface implementations.
+ */
+typedef struct _SHCLTXPROVIDERCTX
 {
     /** Pointer to the related Shared Clipboard transfer. */
@@ -603,81 +603,60 @@
     /** User-defined data pointer. Can be NULL if not needed. */
     void         *pvUser;
-} SHCLPROVIDERCTX, *PSHCLPROVIDERCTX;
-
-/**
- * Shared Clipboard transfer provider interface table.
- */
-typedef struct SHCLPROVIDERINTERFACE
-{
-    DECLCALLBACKMEMBER(int, pfnTransferOpen,(PSHCLPROVIDERCTX pCtx));
-    DECLCALLBACKMEMBER(int, pfnTransferClose,(PSHCLPROVIDERCTX pCtx));
-    DECLCALLBACKMEMBER(int, pfnRootsGet,(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList));
-    DECLCALLBACKMEMBER(int, pfnListOpen,(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList));
-    DECLCALLBACKMEMBER(int, pfnListClose,(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList));
-    DECLCALLBACKMEMBER(int, pfnListHdrRead,(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr));
-    DECLCALLBACKMEMBER(int, pfnListHdrWrite,(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr));
-    DECLCALLBACKMEMBER(int, pfnListEntryRead,(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pEntry));
-    DECLCALLBACKMEMBER(int, pfnListEntryWrite,(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pEntry));
-    DECLCALLBACKMEMBER(int, pfnObjOpen,(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms, PSHCLOBJHANDLE phObj));
-    DECLCALLBACKMEMBER(int, pfnObjClose,(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj));
-    DECLCALLBACKMEMBER(int, pfnObjRead,(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj, void *pvData, uint32_t cbData,
-                                        uint32_t fFlags, uint32_t *pcbRead));
-    DECLCALLBACKMEMBER(int, pfnObjWrite,(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj, void *pvData, uint32_t cbData,
-                                         uint32_t fFlags, uint32_t *pcbWritten));
-} SHCLPROVIDERINTERFACE, *PSHCLPROVIDERINTERFACE;
-
-/**
- * Structure for the Shared Clipboard provider creation context.
- */
-typedef struct _SHCLPROVIDERCREATIONCTX
-{
-    /** Specifies what the source of the provider is. */
-    SHCLSOURCE             enmSource;
-    /** The provider interface table. */
-    SHCLPROVIDERINTERFACE  Interface;
-    /** Provider callback data. */
-    void                  *pvUser;
-} SHCLPROVIDERCREATIONCTX, *PSHCLPROVIDERCREATIONCTX;
-
-
-/**
- * Structure for storing Shared Clipboard transfer callback data.
- */
-typedef struct _SHCLTRANSFERCALLBACKDATA
-{
-    /** Pointer to related Shared Clipboard transfer. */
-    PSHCLTRANSFER pTransfer;
-    /** Saved user pointer. */
-    void         *pvUser;
     /** Size (in bytes) of data at user pointer. */
     size_t        cbUser;
-} SHCLTRANSFERCALLBACKDATA, *PSHCLTRANSFERCALLBACKDATA;
-
-/**
- * Function callback table for Shared Clipboard transfers.
- *
- * All callbacks are optional and therefore can be NULL.
- */
-typedef struct SHCLTRANSFERCALLBACKS
-{
-    /** User pointer to data. Optional and can be NULL. */
-    void  *pvUser;
-    /** Size (in bytes) of user data pointing at. Optional and can be 0. */
-    size_t cbUser;
-    /** Called after the transfer has been initialized. */
-    DECLCALLBACKMEMBER(int, pfnTransferInitialize,(PSHCLTRANSFERCALLBACKDATA pData));
+} SHCLTXPROVIDERCTX, *PSHCLTXPROVIDERCTX;
+
+struct SHCLTRANSFERCTX;
+typedef struct SHCLTRANSFERCTX *PSHCLTRANSFERCTX;
+
+/**
+ * Shared Clipboard transfer provider interface table.
+ */
+typedef struct _SHCLTXPROVIDERIFACE
+{
+    /** Called when the transfer gets initialized. */
+    DECLCALLBACKMEMBER(int,  pfnInitialize,(PSHCLTXPROVIDERCTX pCtx));
     /** Called before the transfer will be started. */
-    DECLCALLBACKMEMBER(int, pfnTransferStart,(PSHCLTRANSFERCALLBACKDATA pData));
-    /** Called when reading / writing the list header is complete. */
-    DECLCALLBACKMEMBER(void, pfnListHeaderComplete,(PSHCLTRANSFERCALLBACKDATA pData));
-    /** Called when reading / writing a list entry is complete. */
-    DECLCALLBACKMEMBER(void, pfnListEntryComplete,(PSHCLTRANSFERCALLBACKDATA pData));
-    /** Called when the transfer is complete. */
-    DECLCALLBACKMEMBER(void, pfnTransferComplete,(PSHCLTRANSFERCALLBACKDATA pData, int rc));
+    DECLCALLBACKMEMBER(int,  pfnStart,(PSHCLTXPROVIDERCTX pCtx));
+    /** Called when the transfer has been complete. */
+    DECLCALLBACKMEMBER(void, pfnCompleted,(PSHCLTXPROVIDERCTX pCtx, int rc));
     /** Called when the transfer has been canceled. */
-    DECLCALLBACKMEMBER(void, pfnTransferCanceled,(PSHCLTRANSFERCALLBACKDATA pData));
+    DECLCALLBACKMEMBER(void, pfnCanceled,(PSHCLTXPROVIDERCTX pCtx));
     /** Called when transfer resulted in an unrecoverable error. */
-    DECLCALLBACKMEMBER(void, pfnTransferError,(PSHCLTRANSFERCALLBACKDATA pData, int rc));
-} SHCLTRANSFERCALLBACKS, *PSHCLTRANSFERCALLBACKS;
+    DECLCALLBACKMEMBER(void, pfnError,(PSHCLTXPROVIDERCTX pCtx, int rc));
+    /** Called when transfer got registered to a transfer context. */
+    DECLCALLBACKMEMBER(void, pfnRegistered,(PSHCLTXPROVIDERCTX pCtx, PSHCLTRANSFERCTX pTransferCtx));
+    /** Called when transfer got unregistered from a transfer context. */
+    DECLCALLBACKMEMBER(void, pfnUnregistered,(PSHCLTXPROVIDERCTX pCtx, PSHCLTRANSFERCTX pTransferCtx));
+
+    DECLCALLBACKMEMBER(int, pfnRootsGet,(PSHCLTXPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList));
+    DECLCALLBACKMEMBER(int, pfnListOpen,(PSHCLTXPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList));
+    DECLCALLBACKMEMBER(int, pfnListClose,(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList));
+    DECLCALLBACKMEMBER(int, pfnListHdrRead,(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr));
+    DECLCALLBACKMEMBER(int, pfnListHdrWrite,(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr));
+    DECLCALLBACKMEMBER(int, pfnListEntryRead,(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pEntry));
+    DECLCALLBACKMEMBER(int, pfnListEntryWrite,(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pEntry));
+    DECLCALLBACKMEMBER(int, pfnObjOpen,(PSHCLTXPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms, PSHCLOBJHANDLE phObj));
+    DECLCALLBACKMEMBER(int, pfnObjClose,(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj));
+    DECLCALLBACKMEMBER(int, pfnObjRead,(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj, void *pvData, uint32_t cbData,
+                                        uint32_t fFlags, uint32_t *pcbRead));
+    DECLCALLBACKMEMBER(int, pfnObjWrite,(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj, void *pvData, uint32_t cbData,
+                                         uint32_t fFlags, uint32_t *pcbWritten));
+} SHCLTXPROVIDERIFACE, *PSHCLTXPROVIDERIFACE;
+
+/**
+ * Structure for the Shared Clipboard transfer provider creation context.
+ */
+typedef struct _SHCLTXPROVIDERCREATIONCTX
+{
+    /** Specifies what the source of the provider is. */
+    SHCLSOURCE           enmSource;
+    /** The provider interface table. */
+    SHCLTXPROVIDERIFACE  Interface;
+    /** User-provided callback data. */
+    void                *pvUser;
+    /** Size (in bytes) of data at user pointer. */
+    size_t               cbUser;
+} SHCLTXPROVIDERCREATIONCTX, *PSHCLTXPROVIDERCREATIONCTX;
 
 /**
@@ -737,9 +716,7 @@
     RTLISTANCHOR             lstObj;
     /** The transfer's own provider context. */
-    SHCLPROVIDERCTX          ProviderCtx;
+    SHCLTXPROVIDERCTX        ProviderCtx;
     /** The transfer's provider interface. */
-    SHCLPROVIDERINTERFACE    ProviderIface;
-    /** The transfer's (optional) callback table. */
-    SHCLTRANSFERCALLBACKS    Callbacks;
+    SHCLTXPROVIDERIFACE      ProviderIface;
     /** Opaque pointer to implementation-specific parameters. */
     void                    *pvUser;
@@ -782,4 +759,12 @@
 } SHCLHTTPSERVER;
 typedef SHCLHTTPSERVER *PSHCLHTTPSERVER;
+
+typedef struct _SHCLHTTPCONTEXT
+{
+    /** HTTP server instance data. */
+    SHCLHTTPSERVER      HttpServer;
+} SHCLHTTPCONTEXT;
+typedef SHCLHTTPCONTEXT *PSHCLHTTPCONTEXT;
+
 #endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP */
 
@@ -787,5 +772,5 @@
  * Structure for keeping Shared Clipboard transfer context around.
  */
-typedef struct _SHCLTRANSFERCTX
+struct SHCLTRANSFERCTX
 {
     /** Critical section for serializing access. */
@@ -805,5 +790,5 @@
     SHCLHTTPSERVER              HttpServer;
 #endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP */
-} SHCLTRANSFERCTX, *PSHCLTRANSFERCTX;
+};
 
 int ShClTransferObjCtxInit(PSHCLCLIENTTRANSFEROBJCTX pObjCtx);
@@ -828,9 +813,6 @@
 
 int ShClTransferCreate(PSHCLTRANSFER *ppTransfer);
+int ShClTransferInit(PSHCLTRANSFER pTransfer, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource);
 int ShClTransferDestroy(PSHCLTRANSFER pTransfer);
-
-int ShClTransferInit(PSHCLTRANSFER pTransfer, SHCLTRANSFERID uID, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource);
-int ShClTransferOpen(PSHCLTRANSFER pTransfer);
-int ShClTransferClose(PSHCLTRANSFER pTransfer);
 
 int ShClTransferListOpen(PSHCLTRANSFER pTransfer, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
@@ -881,5 +863,5 @@
 bool ShClTransferListEntryIsValid(PSHCLLISTENTRY pListEntry);
 
-int ShClTransferSetInterface(PSHCLTRANSFER pTransfer, PSHCLPROVIDERCREATIONCTX pCreationCtx);
+int ShClTransferSetProviderIface(PSHCLTRANSFER pTransfer, PSHCLTXPROVIDERCREATIONCTX pCreationCtx);
 int ShClTransferRootsSet(PSHCLTRANSFER pTransfer, const char *pszRoots, size_t cbRoots);
 void ShClTransferReset(PSHCLTRANSFER pTransfer);
@@ -895,10 +877,10 @@
 int ShClTransferRun(PSHCLTRANSFER pTransfer, PFNRTTHREAD pfnThreadFunc, void *pvUser);
 int ShClTransferStart(PSHCLTRANSFER pTransfer);
-void ShClTransferSetCallbacks(PSHCLTRANSFER pTransfer, PSHCLTRANSFERCALLBACKS pCallbacks);
 
 int ShClTransferCtxInit(PSHCLTRANSFERCTX pTransferCtx);
 void ShClTransferCtxDestroy(PSHCLTRANSFERCTX pTransferCtx);
 void ShClTransferCtxReset(PSHCLTRANSFERCTX pTransferCtx);
-PSHCLTRANSFER ShClTransferCtxGetTransfer(PSHCLTRANSFERCTX pTransferCtx, uint32_t uIdx);
+PSHCLTRANSFER ShClTransferCtxGetTransferById(PSHCLTRANSFERCTX pTransferCtx, uint32_t uID);
+PSHCLTRANSFER ShClTransferCtxGetTransferByIndex(PSHCLTRANSFERCTX pTransferCtx, uint32_t uIdx);
 uint32_t ShClTransferCtxGetRunningTransfers(PSHCLTRANSFERCTX pTransferCtx);
 uint32_t ShClTransferCtxGetTotalTransfers(PSHCLTRANSFERCTX pTransferCtx);
@@ -906,8 +888,11 @@
 bool ShClTransferCtxTransfersMaximumReached(PSHCLTRANSFERCTX pTransferCtx);
 int ShClTransferCtxTransferRegister(PSHCLTRANSFERCTX pTransferCtx, PSHCLTRANSFER pTransfer, SHCLTRANSFERID *pidTransfer);
-int ShClTransferCtxTransferRegisterByIndex(PSHCLTRANSFERCTX pTransferCtx, PSHCLTRANSFER pTransfer, SHCLTRANSFERID idTransfer);
+int ShClTransferCtxTransferRegisterById(PSHCLTRANSFERCTX pTransferCtx, PSHCLTRANSFER pTransfer, SHCLTRANSFERID idTransfer);
 int ShClTransferCtxTransferUnregister(PSHCLTRANSFERCTX pTransferCtx, SHCLTRANSFERID idTransfer);
 
 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
+int ShClHttpTransferCreate(PSHCLHTTPCONTEXT pCtx, PSHCLTRANSFER pTransfer);
+int ShClHttpTransferDestroy(PSHCLHTTPCONTEXT pCtx, PSHCLTRANSFER pTransfer);
+
 int ShClTransferHttpServerCreate(PSHCLHTTPSERVER pSrv, uint16_t *puPort);
 int ShClTransferHttpServerCreateEx(PSHCLHTTPSERVER pSrv, uint16_t uPort);
@@ -922,5 +907,5 @@
 char *ShClTransferHttpServerGetUrlA(PSHCLHTTPSERVER pSrv, SHCLTRANSFERID idTransfer);
 bool ShClTransferHttpServerIsRunning(PSHCLHTTPSERVER pSrv);
-#endif
+#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP */
 
 void ShClFsObjFromIPRT(PSHCLFSOBJINFO pDst, PCRTFSOBJINFO pSrc);
Index: trunk/include/VBox/GuestHost/SharedClipboard-x11.h
===================================================================
--- trunk/include/VBox/GuestHost/SharedClipboard-x11.h	(revision 87082)
+++ trunk/include/VBox/GuestHost/SharedClipboard-x11.h	(revision 87452)
@@ -35,4 +35,7 @@
 
 #include <VBox/GuestHost/SharedClipboard.h>
+#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
+# include <VBox/GuestHost/SharedClipboard-transfers.h>
+#endif
 
 /** Enables the Xt busy / update handling. */
@@ -105,5 +108,9 @@
 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     /** The best HTML format X11 has to offer, as an index into the formats table. */
-    SHCLX11FMTIDX idxFmtURI;
+    SHCLX11FMTIDX   idxFmtURI;
+# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
+    /** HTTP transfer context data. */
+    SHCLHTTPCONTEXT HttpCtx;
+# endif
 #endif
     /** What kind of formats does VBox have to offer? */
@@ -148,7 +155,41 @@
  *  @{
  */
-DECLCALLBACK(int)  ShClX11RequestDataForX11Callback(SHCLCONTEXT *pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb);
-DECLCALLBACK(void) ShClX11ReportFormatsCallback(SHCLCONTEXT *pCtx, SHCLFORMATS fFormats);
-DECLCALLBACK(void) ShClX11RequestFromX11CompleteCallback(SHCLCONTEXT *pCtx, int rc, CLIPREADCBREQ *pReq, void *pv, uint32_t cb);
+/**
+ * Callback for reading clipboard data from the guest.
+ * The function will be invoked for every single target the clipboard requests.
+ *
+ * @note Runs in Xt event thread.
+ *
+ * @returns VBox status code. VERR_NO_DATA if no data available.
+ * @param   pCtx                Pointer to the host clipboard structure.
+ * @param   uFmt                The format in which the data should be transferred
+ *                              (VBOX_SHCL_FMT_XXX).
+ * @param   ppv                 Returns an allocated buffer with data read from the guest on success.
+ *                              Needs to be free'd with RTMemFree() by the caller.
+ * @param   pcb                 Returns the amount of data read (in bytes) on success.
+ */
+DECLCALLBACK(int)  ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb);
+
+/**
+ * Reports formats available in the X11 clipboard to VBox.
+ *
+ * @note   Runs in Xt event thread.
+ *
+ * @param  pCtx                 Opaque context pointer for the glue code.
+ * @param  fFormats             The formats available.
+ */
+DECLCALLBACK(void) ShClX11ReportFormatsCallback(PSHCLCONTEXT pCtx, SHCLFORMATS fFormats);
+
+/**
+ * Called by the backend to tell us that a request for data from X11 has completed.
+ *
+ * @param  pCtx                 Our context information.
+ * @param  rcCompletion         The completion status of the request.
+ * @param  pReq                 The request structure that we passed in when we started
+ *                              the request.  We RTMemFree() this in this function.
+ * @param  pv                   The clipboard data returned from X11 if the request succeeded (see @a rcCompletion).
+ * @param  cb                   The size of the data in @a pv.
+ */
+DECLCALLBACK(void) ShClX11RequestFromX11CompleteCallback(PSHCLCONTEXT pCtx, int rc, CLIPREADCBREQ *pReq, void *pv, uint32_t cb);
 /** @} */
 
