Changeset 81025 in vbox for trunk/src/VBox/HostServices
- Timestamp:
- Sep 26, 2019 4:13:25 PM (5 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedClipboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-transfers.cpp
r80995 r81025 84 84 85 85 PSHCLCLIENTMSG pMsgHdr = shclSvcMsgAlloc(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_HDR_READ, 86 VBOX_SHCL_CPARMS_ROOT_LIST_HDR_READ );86 VBOX_SHCL_CPARMS_ROOT_LIST_HDR_READ_REQ); 87 87 if (pMsgHdr) 88 88 { … … 652 652 653 653 /** 654 * Returns whether a HGCM message is allowed in a certain service mode or not. 655 * 656 * @returns \c true if message is allowed, \c false if not. 657 * @param uMode Service mode to check allowance for. 658 * @param uMsg HGCM message to check allowance for. 659 */ 660 bool shclSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg) 661 { 662 const bool fHostToGuest = uMode == VBOX_SHCL_MODE_HOST_TO_GUEST 663 || uMode == VBOX_SHCL_MODE_BIDIRECTIONAL; 664 665 const bool fGuestToHost = uMode == VBOX_SHCL_MODE_GUEST_TO_HOST 666 || uMode == VBOX_SHCL_MODE_BIDIRECTIONAL; 667 668 bool fAllowed = false; /* If in doubt, don't allow. */ 669 670 switch (uMsg) 671 { 672 case VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_WRITE: 673 RT_FALL_THROUGH(); 674 case VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_WRITE: 675 RT_FALL_THROUGH(); 676 case VBOX_SHCL_GUEST_FN_LIST_HDR_WRITE: 677 RT_FALL_THROUGH(); 678 case VBOX_SHCL_GUEST_FN_LIST_ENTRY_WRITE: 679 RT_FALL_THROUGH(); 680 case VBOX_SHCL_GUEST_FN_OBJ_WRITE: 681 fAllowed = fGuestToHost; 682 break; 683 684 case VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_READ: 685 RT_FALL_THROUGH(); 686 case VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_READ: 687 RT_FALL_THROUGH(); 688 case VBOX_SHCL_GUEST_FN_LIST_HDR_READ: 689 RT_FALL_THROUGH(); 690 case VBOX_SHCL_GUEST_FN_LIST_ENTRY_READ: 691 RT_FALL_THROUGH(); 692 case VBOX_SHCL_GUEST_FN_OBJ_READ: 693 fAllowed = fHostToGuest; 694 break; 695 696 case VBOX_SHCL_GUEST_FN_CONNECT: 697 RT_FALL_THROUGH(); 698 case VBOX_SHCL_GUEST_FN_MSG_PEEK_WAIT: 699 RT_FALL_THROUGH(); 700 case VBOX_SHCL_GUEST_FN_MSG_PEEK_NOWAIT: 701 RT_FALL_THROUGH(); 702 case VBOX_SHCL_GUEST_FN_MSG_GET: 703 RT_FALL_THROUGH(); 704 case VBOX_SHCL_GUEST_FN_REPLY: 705 RT_FALL_THROUGH(); 706 case VBOX_SHCL_GUEST_FN_CANCEL: 707 RT_FALL_THROUGH(); 708 case VBOX_SHCL_GUEST_FN_ERROR: 709 RT_FALL_THROUGH(); 710 case VBOX_SHCL_GUEST_FN_LIST_OPEN: 711 RT_FALL_THROUGH(); 712 case VBOX_SHCL_GUEST_FN_LIST_CLOSE: 713 RT_FALL_THROUGH(); 714 case VBOX_SHCL_GUEST_FN_OBJ_OPEN: 715 RT_FALL_THROUGH(); 716 case VBOX_SHCL_GUEST_FN_OBJ_CLOSE: 717 fAllowed = fHostToGuest || fGuestToHost; 718 break; 719 720 default: 721 break; 722 } 723 724 LogFlowFunc(("uMsg=%RU32 (%s), uMode=%RU32 -> fAllowed=%RTbool\n", uMsg, VBoxShClGuestMsgToStr(uMsg), uMode, fAllowed)); 725 return fAllowed; 726 } 727 728 /** 654 729 * Gets a transfer message reply from HGCM service parameters. 655 730 * … … 740 815 int rc; 741 816 742 if (cParms == VBOX_SHCL_CPARMS_ROOT_LIST_HDR )817 if (cParms == VBOX_SHCL_CPARMS_ROOT_LIST_HDR_WRITE) 743 818 { 744 819 rc = HGCMSvcGetU32(&paParms[1], &pRootLstHdr->fRoots); … … 766 841 int rc; 767 842 768 if (cParms == VBOX_SHCL_CPARMS_ROOT_LIST_ENTRY )843 if (cParms == VBOX_SHCL_CPARMS_ROOT_LIST_ENTRY_WRITE) 769 844 { 770 845 rc = HGCMSvcGetU32(&paParms[1], &pListEntry->fInfo); … … 1220 1295 pClient->State.uClientID, u32Function, VBoxShClGuestMsgToStr(u32Function), cParms, g_ExtState.pfnExtension)); 1221 1296 1222 #if 01223 1297 /* Check if we've the right mode set. */ 1224 1298 if (!shclSvcTransferMsgIsAllowed(shclSvcGetMode(), u32Function)) … … 1227 1301 return VERR_ACCESS_DENIED; 1228 1302 } 1229 #endif1230 1303 1231 1304 /* A (valid) service extension is needed because VBoxSVC needs to keep track of the … … 1250 1323 switch (u32Function) 1251 1324 { 1252 case VBOX_SHCL_GUEST_FN_STATUS:1253 break;1254 1325 default: 1255 1326 { … … 1287 1358 switch (u32Function) 1288 1359 { 1289 #if 0 1290 case VBOX_SHCL_GUEST_FN_STATUS: 1291 { 1292 if (cParms != VBOX_SHCL_CPARMS_STATUS) 1360 case VBOX_SHCL_GUEST_FN_REPLY: 1361 { 1362 rc = shclSvcTransferHandleReply(pClient, pTransfer, cParms, paParms); 1363 break; 1364 } 1365 1366 case VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_READ: 1367 { 1368 if (cParms != VBOX_SHCL_CPARMS_ROOT_LIST_HDR_READ) 1293 1369 break; 1294 1370 1295 SHCLTRANSFERSTATUS uStatus = SHCLTRANSFERSTATUS_NONE; 1296 rc = HGCMSvcGetU32(&paParms[1], &uStatus); 1297 if (RT_FAILURE(rc)) 1298 break; 1299 1300 LogFlowFunc(("uStatus: %RU32\n", uStatus)); 1301 1302 SharedClipboardTransferCtxTransfersCleanup(&pClient->URI); 1303 1304 if (SharedClipboardTransferCtxTransfersMaximumReached(&pClient->URI)) 1305 { 1306 rc = VERR_SHCLPB_MAX_TRANSFERS_REACHED; 1307 break; 1308 } 1309 1310 if (uStatus == SHCLTRANSFERSTATUS_RUNNING) 1311 { 1312 const SHCLTRANSFERDIR enmDir = SHCLTRANSFERDIR_READ; 1313 1314 PSHCLTRANSFER pTransfer; 1315 rc = SharedClipboardTransferCreate(enmDir, 1316 SHCLSOURCE_REMOTE, &pTransfer); 1317 if (RT_SUCCESS(rc)) 1318 { 1319 rc = shclSvcTransferAreaRegister(&pClient->State, pTransfer); 1320 if (RT_SUCCESS(rc)) 1321 { 1322 SHCLPROVIDERCREATIONCTX creationCtx; 1323 RT_ZERO(creationCtx); 1324 1325 creationCtx.enmSource = pClient->State.enmSource; 1326 1327 creationCtx.Interface.pfnTransferOpen = shclSvcTransferOpen; 1328 creationCtx.Interface.pfnTransferClose = shclSvcTransferClose; 1329 creationCtx.Interface.pfnListOpen = shclSvcTransferListOpen; 1330 creationCtx.Interface.pfnListClose = shclSvcTransferListClose; 1331 creationCtx.Interface.pfnObjOpen = shclSvcTransferObjOpen; 1332 creationCtx.Interface.pfnObjClose = shclSvcTransferObjClose; 1333 1334 if (enmDir == SHCLTRANSFERDIR_READ) 1335 { 1336 creationCtx.Interface.pfnRootsGet = shclSvcTransferGetRoots; 1337 creationCtx.Interface.pfnListHdrRead = shclSvcTransferListHdrRead; 1338 creationCtx.Interface.pfnListEntryRead = shclSvcTransferListEntryRead; 1339 creationCtx.Interface.pfnObjRead = shclSvcTransferObjRead; 1340 } 1341 else 1342 { 1343 AssertFailed(); 1344 } 1345 1346 creationCtx.pvUser = pClient; 1347 1348 /* Register needed callbacks so that we can wait for the meta data to arrive here. */ 1349 SHCLTRANSFERCALLBACKS Callbacks; 1350 RT_ZERO(Callbacks); 1351 1352 Callbacks.pvUser = pClient; 1353 1354 Callbacks.pfnTransferPrepare = VBoxSvcClipboardTransferPrepareCallback; 1355 Callbacks.pfnTransferComplete = VBoxSvcClipboardTransferCompleteCallback; 1356 Callbacks.pfnTransferCanceled = VBoxSvcClipboardTransferCanceledCallback; 1357 Callbacks.pfnTransferError = VBoxSvcClipboardTransferErrorCallback; 1358 1359 SharedClipboardTransferSetCallbacks(pTransfer, &Callbacks); 1360 1361 rc = SharedClipboardTransferSetInterface(pTransfer, &creationCtx); 1362 if (RT_SUCCESS(rc)) 1363 rc = SharedClipboardTransferCtxTransferAdd(&pClient->URI, pTransfer); 1364 } 1365 1366 if (RT_SUCCESS(rc)) 1367 { 1368 rc = ShClSvcImplTransferCreate(pClient, pTransfer); 1369 if (RT_SUCCESS(rc)) 1370 rc = ShClSvcImplFormatAnnounce(pClient, VBOX_SHCL_FMT_URI_LIST); 1371 } 1372 1373 if (RT_FAILURE(rc)) 1374 { 1375 ShClSvcImplTransferDestroy(pClient, pTransfer); 1376 SharedClipboardTransferDestroy(pTransfer); 1377 } 1378 } 1379 } 1380 1381 LogFlowFunc(("[Client %RU32] VBOX_SHCL_GUEST_FN_STATUS: %Rrc\n", pClient->uClientID, rc)); 1382 1383 if (RT_FAILURE(rc)) 1384 LogRel(("Shared Clipboard: Initializing transfer failed with %Rrc\n", rc)); 1385 1386 break; 1387 } 1388 #endif 1389 1390 case VBOX_SHCL_GUEST_FN_REPLY: 1391 { 1392 rc = shclSvcTransferHandleReply(pClient, pTransfer, cParms, paParms); 1393 break; 1394 } 1395 1396 case VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_READ: 1397 { 1371 SHCLROOTLISTHDR rootListHdr; 1372 RT_ZERO(rootListHdr); 1373 1374 rootListHdr.cRoots = SharedClipboardTransferRootsCount(pTransfer); 1375 1376 HGCMSvcSetU32(&paParms[0], 0 /* Context ID */); 1377 HGCMSvcSetU32(&paParms[1], rootListHdr.fRoots); 1378 HGCMSvcSetU32(&paParms[2], rootListHdr.cRoots); 1379 1380 rc = VINF_SUCCESS; 1398 1381 break; 1399 1382 } … … 1424 1407 case VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_READ: 1425 1408 { 1426 #if 0 1427 SHCLROOTLISTENTRY lstEntry; 1428 rc = VBoxSvcClipboardGetRootListEntry(cParms, paParms, &lstEntry); 1429 if (RT_SUCCESS(rc)) 1430 { 1431 void *pvData = SharedClipboardTransferRootListEntryDup(&lstEntry); 1432 uint32_t cbData = sizeof(SHCLROOTLISTENTRY); 1433 1434 PSHCLTRANSFERPAYLOAD pPayload; 1435 rc = SharedClipboardTransferPayloadAlloc(SHCLTRANSFEREVENTTYPE_ROOT_LIST_HDR_READ, 1436 pvData, cbData, &pPayload); 1409 if (cParms != VBOX_SHCL_CPARMS_ROOT_LIST_ENTRY_READ) 1410 break; 1411 1412 /* paParms[1] contains fInfo flags, currently unused. */ 1413 uint32_t uIndex; 1414 rc = HGCMSvcGetU32(&paParms[2], &uIndex); 1415 if (RT_SUCCESS(rc)) 1416 { 1417 SHCLROOTLISTENTRY rootListEntry; 1418 rc = SharedClipboardTransferRootsEntry(pTransfer, uIndex, &rootListEntry); 1437 1419 if (RT_SUCCESS(rc)) 1438 rc = SharedClipboardTransferEventSignal(pTransfer, SHCLTRANSFEREVENTTYPE_ROOT_LIST_HDR_READ, 1439 pPayload); 1440 } 1441 break; 1442 #endif 1420 { 1421 HGCMSvcSetPv (&paParms[3], rootListEntry.pszName, rootListEntry.cbName); 1422 HGCMSvcSetU32(&paParms[4], rootListEntry.cbName); 1423 HGCMSvcSetPv (&paParms[5], rootListEntry.pvInfo, rootListEntry.cbInfo); 1424 } 1425 } 1426 break; 1443 1427 } 1444 1428 -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-utils.cpp
r80995 r81025 32 32 33 33 34 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS35 /**36 * Returns whether a HGCM message is allowed in a certain service mode or not.37 *38 * @returns \c true if message is allowed, \c false if not.39 * @param uMode Service mode to check allowance for.40 * @param uMsg HGCM message to check allowance for.41 */42 bool vboxSvcClipboardURIMsgIsAllowed(uint32_t uMode, uint32_t uMsg)43 {44 const bool fHostToGuest = uMode == VBOX_SHCL_MODE_HOST_TO_GUEST45 || uMode == VBOX_SHCL_MODE_BIDIRECTIONAL;46 47 const bool fGuestToHost = uMode == VBOX_SHCL_MODE_GUEST_TO_HOST48 || uMode == VBOX_SHCL_MODE_BIDIRECTIONAL;49 50 bool fAllowed = false; /* If in doubt, don't allow. */51 52 switch (uMsg)53 {54 case VBOX_SHCL_GUEST_FN_LIST_OPEN:55 RT_FALL_THROUGH();56 case VBOX_SHCL_GUEST_FN_LIST_CLOSE:57 RT_FALL_THROUGH();58 case VBOX_SHCL_GUEST_FN_LIST_HDR_READ:59 RT_FALL_THROUGH();60 case VBOX_SHCL_GUEST_FN_LIST_ENTRY_READ:61 RT_FALL_THROUGH();62 case VBOX_SHCL_GUEST_FN_OBJ_OPEN:63 RT_FALL_THROUGH();64 case VBOX_SHCL_GUEST_FN_OBJ_CLOSE:65 RT_FALL_THROUGH();66 case VBOX_SHCL_GUEST_FN_OBJ_READ:67 fAllowed = fHostToGuest;68 break;69 70 case VBOX_SHCL_GUEST_FN_MSG_PEEK_WAIT:71 RT_FALL_THROUGH();72 case VBOX_SHCL_GUEST_FN_MSG_PEEK_NOWAIT:73 RT_FALL_THROUGH();74 case VBOX_SHCL_GUEST_FN_MSG_GET:75 RT_FALL_THROUGH();76 case VBOX_SHCL_GUEST_FN_STATUS:77 RT_FALL_THROUGH();78 case VBOX_SHCL_GUEST_FN_CANCEL:79 RT_FALL_THROUGH();80 case VBOX_SHCL_GUEST_FN_ERROR:81 fAllowed = fHostToGuest || fGuestToHost;82 break;83 84 default:85 break;86 }87 88 fAllowed = true; /** @todo FIX !!!! */89 90 LogFlowFunc(("uMsg=%RU32, uMode=%RU32 -> fAllowed=%RTbool\n", uMsg, uMode, fAllowed));91 return fAllowed;92 }93 94 #if 095 int vboxSvcClipboardURIReportMsg(PSHCLCLIENT pClient, uint32_t uMsg, uint32_t uParm)96 {97 AssertPtrReturn(pClient, VERR_INVALID_POINTER);98 99 int rc = VINF_SUCCESS;100 101 switch (uMsg)102 {103 case VBOX_SHCL_HOST_MSG_TRANSFER_TRANSFER_START:104 {105 Assert(pClient->State.URI.fTransferStart == false);106 107 LogFlowFunc(("VBOX_SHCL_HOST_MSG_TRANSFER_TRANSFER_START\n"));108 109 if ( shclSvcGetMode() != VBOX_SHCL_MODE_HOST_TO_GUEST110 && shclSvcGetMode() != VBOX_SHCL_MODE_BIDIRECTIONAL)111 {112 LogFlowFunc(("Wrong clipboard mode, skipping\n"));113 break;114 }115 116 pClient->State.URI.fTransferStart = true;117 pClient->State.URI.enmTransferDir = (SHCLTRANSFERDIR)uParm;118 break;119 120 }121 122 default:123 AssertMsgFailed(("Invalid message %RU32\n", uMsg));124 rc = VERR_INVALID_PARAMETER;125 break;126 }127 128 LogFlowFuncLeaveRC(rc);129 return rc;130 }131 132 bool shclSvcTransferReturnMsg(PSHCLCLIENT pClient, uint32_t cParms, VBOXHGCMSVCPARM paParms[])133 {134 RT_NOREF(pClient, cParms, paParms);135 136 bool fHandled = false;137 138 if ( pClient->State.URI.fTransferStart139 && cParms >= 2)140 {141 HGCMSvcSetU32(&paParms[0], VBOX_SHCL_HOST_MSG_TRANSFER_TRANSFER_START);142 HGCMSvcSetU32(&paParms[1], pClient->State.URI.enmTransferDir);143 pClient->State.URI.fTransferStart = false;144 145 fHandled = true;146 }147 148 LogFlowFunc(("fHandled=%RTbool\n", fHandled));149 return fHandled;150 }151 #endif152 #endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */153
Note:
See TracChangeset
for help on using the changeset viewer.