- Timestamp:
- Jul 21, 2023 11:26:04 AM (21 months ago)
- svn:sync-xref-src-repo-rev:
- 158516
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/GuestHost/SharedClipboard-transfers.h
r100660 r100676 1188 1188 int ShClTransferSetProvider(PSHCLTRANSFER pTransfer, PSHCLTXPROVIDER pProvider); 1189 1189 1190 int ShClTransferRootsInitFromStringListEx(PSHCLTRANSFER pTransfer, const char *pszRoots, size_t cbRoots, const char *pszSep); 1190 1191 int ShClTransferRootsInitFromStringList(PSHCLTRANSFER pTransfer, const char *pszRoots, size_t cbRoots); 1191 1192 int ShClTransferRootsInitFromStringListUnicode(PSHCLTRANSFER pTransfer, PRTUTF16 pwszRoots, size_t cbRoots); … … 1243 1244 uint32_t ShClTransferHttpServerGetTransferCount(PSHCLHTTPSERVER pSrv); 1244 1245 char *ShClTransferHttpServerGetAddressA(PSHCLHTTPSERVER pSrv); 1245 char *ShClTransferHttpServerGetUrlA(PSHCLHTTPSERVER pSrv, SHCLTRANSFERID idTransfer );1246 char *ShClTransferHttpServerGetUrlA(PSHCLHTTPSERVER pSrv, SHCLTRANSFERID idTransfer, uint64_t idxEntry); 1246 1247 bool ShClTransferHttpServerIsInitialized(PSHCLHTTPSERVER pSrv); 1247 1248 bool ShClTransferHttpServerIsRunning(PSHCLHTTPSERVER pSrv); -
trunk/src/VBox/Additions/x11/VBoxClient/clipboard-x11.cpp
r100367 r100676 95 95 PSHCLX11RESPONSE pResp = (PSHCLX11RESPONSE)pPayload->pvData; 96 96 97 rc = ShClTransferRootsInitFromStringList(pTransfer, (const char *)pResp->Read.pvData, pResp->Read.cbData); 97 rc = ShClTransferRootsInitFromStringListEx(pTransfer, (const char *)pResp->Read.pvData, pResp->Read.cbData, 98 "\n" /* X11-based Desktop environments separate entries with "\n" */); 98 99 99 100 RTMemFree(pResp->Read.pvData); … … 329 330 if (RT_SUCCESS(rc)) 330 331 { 331 char *pszURL = ShClTransferHttpServerGetUrlA(pSrv, pTransfer->State.uID); 332 if (pszURL) 332 char *pszURL = NULL; 333 334 uint64_t const cRoots = ShClTransferRootsCount(pTransfer); 335 for (uint32_t i = 0; i < cRoots; i++) 336 { 337 char *pszEntry = ShClTransferHttpServerGetUrlA(pSrv, ShClTransferGetID(pTransfer), i /* Entry index */); 338 AssertPtrBreakStmt(pszEntry, rc = VERR_NO_MEMORY); 339 340 if (i > 0) 341 { 342 rc = RTStrAAppend(&pszURL, "\n"); /* Separate entries with a newline. */ 343 AssertRCBreak(rc); 344 } 345 346 rc = RTStrAAppend(&pszURL, pszEntry); 347 AssertRCBreak(rc); 348 349 RTStrFree(pszEntry); 350 } 351 352 if (RT_SUCCESS(rc)) 333 353 { 334 354 *ppv = pszURL; … … 339 359 /* ppv has ownership of pszURL. */ 340 360 } 341 else342 rc = VERR_NO_MEMORY;343 361 } 344 362 } -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers-http.cpp
r100675 r100676 69 69 *********************************************************************************************************************************/ 70 70 71 #ifdef DEBUG_andy 71 #ifdef DEBUG_andy_0 72 72 /** When enabled, this lets the HTTP server run at a predictable URL and port for debugging: 73 73 * URL: http://localhost:49200/transfer<ID> */ … … 401 401 RT_NOREF(ppszMIMEHint); 402 402 403 AssertReturn(RTStrIsValidEncoding(pReq->pszUrl), VERR_INVALID_PARAMETER); 404 405 size_t const cchUrl = strlen(pReq->pszUrl); 406 AssertReturn(cchUrl, VERR_INVALID_PARAMETER); 407 403 408 int rc; 404 409 410 /* For now we only know the transfer -- now we need to figure out the entry we want to serve. */ 405 411 PSHCLHTTPSERVERTRANSFER pSrvTx = (PSHCLHTTPSERVERTRANSFER)pReq->pvUser; 406 412 if (pSrvTx) 407 413 { 414 size_t const cchBase = strlen(pSrvTx->szPathVirtual) + 1 /* Skip slash separating the base from the rest */; 415 AssertReturn(cchUrl >= cchBase, VERR_INVALID_PARAMETER); 416 408 417 SHCLOBJOPENCREATEPARMS openParms; 409 418 rc = ShClTransferObjOpenParmsInit(&openParms); … … 416 425 AssertPtr(pTx); 417 426 418 /** @todo For now we only serve single files, hence index 0 below. */ 419 PCSHCLLISTENTRY pEntry = ShClTransferRootsEntryGet(pTx, 0 /* First file */); 420 if (pEntry) 427 rc = VERR_NOT_FOUND; /* Must find the matching root entry first. */ 428 429 uint64_t const cRoots = ShClTransferRootsCount(pTx); 430 for (uint32_t i = 0; i < cRoots; i++) 421 431 { 432 PCSHCLLISTENTRY pEntry = ShClTransferRootsEntryGet(pTx, i); 433 AssertPtrBreakStmt(pEntry, rc = VERR_NOT_FOUND); 434 435 const char *pszName = pReq->pszUrl + cchBase; 436 437 Log3Func(("pReqUrl=%s -> pszName=%s vs. pEntry=%s\n", pReq->pszUrl, pszName, pEntry->pszName)); 438 439 if (RTStrCmp(pEntry->pszName, pszName)) /* Case-sensitive! */ 440 continue; 441 422 442 LogRel2(("Shared Clipboard: Querying HTTP transfer information for '%s' ...\n", pEntry->pszName)); 423 443 … … 449 469 } 450 470 } 471 472 break; 451 473 } 452 else453 rc = VERR_NOT_FOUND;454 474 455 475 ShClTransferObjOpenParmsDestroy(&openParms); … … 856 876 uint64_t const cRoots = ShClTransferRootsCount(pTransfer); 857 877 AssertMsgReturn(cRoots > 0, ("Transfer has no root entries\n"), VERR_INVALID_PARAMETER); 858 AssertMsgReturn(cRoots == 1, ("Only single files are supported for now\n"), VERR_NOT_SUPPORTED);859 878 /** @todo Check for directories? */ 860 879 … … 875 894 AssertRCReturn(rc, rc); 876 895 877 PCSHCLLISTENTRY pEntry = ShClTransferRootsEntryGet(pTransfer, 0 /* First file */); 878 if (pEntry) 879 { 880 /* Create the virtual HTTP path for the transfer. 881 * Every transfer has a dedicated HTTP path (but live in the same URL namespace). */ 882 char *pszPath; 896 /* Create the virtual HTTP path for the transfer. 897 * Every transfer has a dedicated HTTP path (but live in the same URL namespace). */ 898 char *pszPath; 883 899 #ifdef VBOX_SHCL_DEBUG_HTTPSERVER 884 900 # ifdef DEBUG_andy /** Too lazy to specify a different transfer ID for debugging. */ 885 901 ssize_t cch = RTStrAPrintf(&pszPath, "//transfer"); 886 902 # else 887 903 ssize_t cch = RTStrAPrintf(&pszPath, "//transfer%RU16", pTransfer->State.uID); 888 904 # endif 889 905 #else /* Release mode */ 890 ssize_t cch = RTStrAPrintf(&pszPath, "//%s/%s/%s", SHCL_HTTPT_URL_NAMESPACE, szUuid, pEntry->pszName);906 ssize_t cch = RTStrAPrintf(&pszPath, "//%s/%s", SHCL_HTTPT_URL_NAMESPACE, szUuid); 891 907 #endif 892 AssertReturn(cch, VERR_NO_MEMORY); 893 894 const char szScheme[] = "http"; /** @todo For now we only support HTTP. */ 895 const size_t cchScheme = strlen(szScheme) + 3 /* "://" */; 896 897 char *pszURI = RTUriCreate(szScheme, NULL /* pszAuthority */, pszPath, NULL /* pszQuery */, NULL /* pszFragment */); 898 if (pszURI) 908 AssertReturn(cch, VERR_NO_MEMORY); 909 910 const char szScheme[] = "http"; /** @todo For now we only support HTTP. */ 911 const size_t cchScheme = strlen(szScheme) + 3 /* "://" */; 912 913 char *pszURI = RTUriCreate(szScheme, NULL /* pszAuthority */, pszPath, NULL /* pszQuery */, NULL /* pszFragment */); 914 if (pszURI) 915 { 916 if (strlen(pszURI) >= cchScheme) 899 917 { 900 if (strlen(pszURI) >= cchScheme) 901 { 902 /* For the virtual path we only keep everything after the full scheme (e.g. "http://"). 903 * The virtual path always has to start with a "/". */ 904 if (RTStrPrintf2(pSrvTx->szPathVirtual, sizeof(pSrvTx->szPathVirtual), "/%s", pszURI + cchScheme) <= 0) 905 rc = VERR_BUFFER_OVERFLOW; 906 } 907 else 908 rc = VERR_INVALID_PARAMETER; 909 910 RTStrFree(pszURI); 911 pszURI = NULL; 918 /* For the virtual path we only keep everything after the full scheme (e.g. "http://"). 919 * The virtual path always has to start with a "/". */ 920 if (RTStrPrintf2(pSrvTx->szPathVirtual, sizeof(pSrvTx->szPathVirtual), "/%s", pszURI + cchScheme) <= 0) 921 rc = VERR_BUFFER_OVERFLOW; 912 922 } 913 923 else 914 rc = VERR_NO_MEMORY; 915 916 RTStrFree(pszPath); 917 pszPath = NULL; 918 919 AssertRCReturn(rc, rc); 920 921 pSrvTx->pTransfer = pTransfer; 922 pSrvTx->hObj = NIL_SHCLOBJHANDLE; 923 924 RTListAppend(&pSrv->lstTransfers, &pSrvTx->Node); 925 pSrv->cTransfers++; 926 927 shclTransferHttpServerSetStatusLocked(pSrv, SHCLHTTPSERVERSTATUS_TRANSFER_REGISTERED); 928 929 LogFunc(("pTransfer=%p, idTransfer=%RU16, szPath=%s -> %RU32 transfers\n", 930 pSrvTx->pTransfer, pSrvTx->pTransfer->State.uID, pSrvTx->szPathVirtual, pSrv->cTransfers)); 931 932 LogRel2(("Shared Clipboard: Registered HTTP transfer %RU16, now %RU32 HTTP transfers total\n", 933 pTransfer->State.uID, pSrv->cTransfers)); 924 rc = VERR_INVALID_PARAMETER; 925 926 RTStrFree(pszURI); 927 pszURI = NULL; 934 928 } 929 else 930 rc = VERR_NO_MEMORY; 931 932 RTStrFree(pszPath); 933 pszPath = NULL; 934 935 AssertRCReturn(rc, rc); 936 937 pSrvTx->pTransfer = pTransfer; 938 pSrvTx->hObj = NIL_SHCLOBJHANDLE; 939 940 RTListAppend(&pSrv->lstTransfers, &pSrvTx->Node); 941 pSrv->cTransfers++; 942 943 shclTransferHttpServerSetStatusLocked(pSrv, SHCLHTTPSERVERSTATUS_TRANSFER_REGISTERED); 944 945 LogFunc(("pTransfer=%p, idTransfer=%RU16, szPath=%s -> %RU32 transfers\n", 946 pSrvTx->pTransfer, pSrvTx->pTransfer->State.uID, pSrvTx->szPathVirtual, pSrv->cTransfers)); 947 948 LogRel2(("Shared Clipboard: Registered HTTP transfer %RU16, now %RU32 HTTP transfers total\n", 949 pTransfer->State.uID, pSrv->cTransfers)); 935 950 } 951 936 952 } 937 953 … … 1126 1142 * @param pSrv HTTP server instance to return URL for. 1127 1143 * @param idTransfer Transfer ID to return the URL for. 1128 */ 1129 char *ShClTransferHttpServerGetUrlA(PSHCLHTTPSERVER pSrv, SHCLTRANSFERID idTransfer) 1144 * @param idxEntry Index of transfer entry to return URL for. 1145 */ 1146 char *ShClTransferHttpServerGetUrlA(PSHCLHTTPSERVER pSrv, SHCLTRANSFERID idTransfer, uint64_t idxEntry) 1130 1147 { 1131 1148 AssertPtrReturn(pSrv, NULL); … … 1142 1159 } 1143 1160 1144 AssertReturn(RTStrNLen(pSrvTx->szPathVirtual, RTPATH_MAX), NULL); 1145 char *pszUrl = RTStrAPrintf2("%s:%RU16%s", shClTransferHttpServerGetHost(pSrv), pSrv->uPort, pSrvTx->szPathVirtual); 1146 AssertPtr(pszUrl); 1147 1148 shClTransferHttpServerUnlock(pSrv); 1161 PSHCLTRANSFER pTx = pSrvTx->pTransfer; 1162 AssertPtr(pTx); 1163 1164 char *pszUrl = NULL; 1165 1166 /* For now this only supports root entries. */ 1167 PCSHCLLISTENTRY pEntry = ShClTransferRootsEntryGet(pTx, idxEntry); 1168 if (pEntry) 1169 { 1170 AssertReturn(RTStrNLen(pSrvTx->szPathVirtual, RTPATH_MAX), NULL); 1171 pszUrl = RTStrAPrintf2("%s:%RU16%s/%s", shClTransferHttpServerGetHost(pSrv), pSrv->uPort, pSrvTx->szPathVirtual, pEntry->pszName); 1172 AssertPtr(pszUrl); 1173 1174 shClTransferHttpServerUnlock(pSrv); 1175 } 1149 1176 1150 1177 return pszUrl; -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers.cpp
r100660 r100676 1811 1811 1812 1812 /** 1813 * Initializes the root list entries for a given clipboard transfer .1813 * Initializes the root list entries for a given clipboard transfer, extended version. 1814 1814 * 1815 1815 * @returns VBox status code. 1816 1816 * @param pTransfer Transfer to set transfer list entries for. 1817 * @param pszRoots String list (separated by CRLF) of root entries to set.1817 * @param pszRoots String list (separated by \a pszSep) of root entries to set. 1818 1818 * All entries must have the same root path. 1819 1819 * @param cbRoots Size (in bytes) of string list. Includes zero terminator. 1820 * @param pszSep String separator to use for splitting up the root entries. 1820 1821 * 1821 1822 * @note Accepts local paths or URI string lists (absolute only). 1822 1823 */ 1823 int ShClTransferRootsInitFromStringList (PSHCLTRANSFER pTransfer, const char *pszRoots, size_t cbRoots)1824 int ShClTransferRootsInitFromStringListEx(PSHCLTRANSFER pTransfer, const char *pszRoots, size_t cbRoots, const char *pszSep) 1824 1825 { 1825 1826 AssertPtrReturn(pTransfer, VERR_INVALID_POINTER); 1826 1827 AssertPtrReturn(pszRoots, VERR_INVALID_POINTER); 1827 1828 AssertReturn(cbRoots, VERR_INVALID_PARAMETER); 1829 AssertPtrReturn(pszSep, VERR_INVALID_POINTER); 1828 1830 1829 1831 #ifdef DEBUG_andy … … 1843 1845 char *pszPathRootAbs = NULL; 1844 1846 1845 RTCList<RTCString> lstRootEntries = RTCString(pszRoots, cbRoots).split( SHCL_TRANSFER_URI_LIST_SEP_STR);1847 RTCList<RTCString> lstRootEntries = RTCString(pszRoots, cbRoots).split(pszSep); 1846 1848 if (!lstRootEntries.size()) 1847 1849 { … … 1971 1973 LogFlowFuncLeaveRC(rc); 1972 1974 return rc; 1975 } 1976 1977 /** 1978 * Initializes the root list entries for a given clipboard transfer. 1979 * 1980 * @returns VBox status code. 1981 * @param pTransfer Transfer to set transfer list entries for. 1982 * @param pszRoots String list (separated by SHCL_TRANSFER_URI_LIST_SEP_STR) of root entries to set. 1983 * All entries must have the same root path. 1984 * @param cbRoots Size (in bytes) of string list. Includes zero terminator. 1985 * 1986 * @note Accepts local paths or URI string lists (absolute only). 1987 */ 1988 int ShClTransferRootsInitFromStringList(PSHCLTRANSFER pTransfer, const char *pszRoots, size_t cbRoots) 1989 { 1990 return ShClTransferRootsInitFromStringListEx(pTransfer, pszRoots, cbRoots, SHCL_TRANSFER_URI_LIST_SEP_STR); 1973 1991 } 1974 1992 -
trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardHttpServer.cpp
r100668 r100676 251 251 252 252 uint16_t const uID = ShClTransferGetID(pTx); 253 char *pszURL = ShClTransferHttpServerGetUrlA(&HttpSrv, uID );253 char *pszURL = ShClTransferHttpServerGetUrlA(&HttpSrv, uID, 0 /* Entry index */); 254 254 RTTEST_CHECK(hTest, pszURL != NULL); 255 255 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "URL #%02RU32: %s\n", i, pszURL); … … 275 275 276 276 uint16_t const uID = ShClTransferGetID(pTx); 277 char *pszURL = ShClTransferHttpServerGetUrlA(&HttpSrv, uID );277 char *pszURL = ShClTransferHttpServerGetUrlA(&HttpSrv, uID, 0 /* Entry index */); 278 278 RTTEST_CHECK(hTest, pszURL != NULL); 279 279 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Downloading: %s -> %s\n", pszURL, szFileTemp); -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp
r100656 r100676 615 615 if (RT_SUCCESS(rc)) 616 616 { 617 char *pszURL = ShClTransferHttpServerGetUrlA(pHttpSrv, pTransfer->State.uID); 618 if (pszURL) 617 char *pszURL = NULL; 618 619 uint64_t const cRoots = ShClTransferRootsCount(pTransfer); 620 for (uint32_t i = 0; i < cRoots; i++) 621 { 622 char *pszEntry = ShClTransferHttpServerGetUrlA(pHttpSrv, ShClTransferGetID(pTransfer), i /* Entry index */); 623 AssertPtrBreakStmt(pszEntry, rc = VERR_NO_MEMORY); 624 625 if (i > 0) 626 { 627 rc = RTStrAAppend(&pszURL, "\n"); /* Separate entries with a newline. */ 628 AssertRCBreak(rc); 629 } 630 631 rc = RTStrAAppend(&pszURL, pszEntry); 632 AssertRCBreak(rc); 633 634 RTStrFree(pszEntry); 635 } 636 637 if (RT_SUCCESS(rc)) 619 638 { 620 639 *ppv = pszURL; … … 624 643 625 644 /* ppv has ownership of pszURL. */ 626 627 rc = VINF_SUCCESS;628 645 } 629 else630 rc = VERR_NO_MEMORY;631 646 } 632 647 # else
Note:
See TracChangeset
for help on using the changeset viewer.