VirtualBox

Ignore:
Timestamp:
Dec 9, 2019 1:21:55 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135366
Message:

SharedClipboardSvc,Vbgl: Reviewed and adjusted the handling of the VBOX_SHCL_GUEST_FN_REPORT_FORMATS message, paddling back the parameter changes from the 6.1 dev cycle and fixing a couple of bugs introduced. Also documented the message and renamed it to a more sensible name. Dropped the new Vbgl method, renaming the old one. bugref:9437

Location:
trunk/src/VBox/HostServices/SharedClipboard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp

    r82503 r82513  
    361361            LogFunc(("SHCL_WIN_WM_REPORT_FORMATS: fFormats=0x%x\n", fFormats));
    362362
    363             if (fFormats == VBOX_SHCL_FMT_NONE) /* Could arrive with some older GA versions. */
    364                 break; /** @todo r=bird: Old code would do EmptyClipboard() here.  */
    365 
    366363#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    367364            if (fFormats & VBOX_SHCL_FMT_URI_LIST)
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp

    r82506 r82513  
    5757 * only supports a single simultaneous GET call from one client guest.
    5858 *
    59  * The second guest message is VBOX_SHCL_GUEST_FN_FORMATS_REPORT, which tells
     59 * The second guest message is VBOX_SHCL_GUEST_FN_REPORT_FORMATS, which tells
    6060 * the host that the guest has new clipboard data available.  The third is
    6161 * VBOX_SHCL_GUEST_FN_DATA_READ, which asks the host to send its clipboard data
     
    12901290}
    12911291
     1292
     1293/**
     1294 * Handles the VBOX_SHCL_GUEST_FN_REPORT_FORMATS message from the guest.
     1295 */
     1296static int shClSvcGuestReportFormats(PSHCLCLIENT pClient, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     1297{
     1298    /*
     1299     * Check if the service mode allows this operation and whether the guest is
     1300     * supposed to be reading from the host.
     1301     */
     1302    uint32_t uMode = ShClSvcGetMode();
     1303    if (   uMode == VBOX_SHCL_MODE_BIDIRECTIONAL
     1304        || uMode == VBOX_SHCL_MODE_GUEST_TO_HOST)
     1305    { /* likely */ }
     1306    else
     1307        return VERR_ACCESS_DENIED;
     1308
     1309    /*
     1310     * Digest parameters.
     1311     */
     1312    ASSERT_GUEST_RETURN(   cParms == VBOX_SHCL_CPARMS_REPORT_FORMATS
     1313                        || (   cParms == VBOX_SHCL_CPARMS_REPORT_FORMATS_61B
     1314                            && (pClient->State.fGuestFeatures0 & VBOX_SHCL_GF_0_CONTEXT_ID)),
     1315                        VERR_WRONG_PARAMETER_COUNT);
     1316
     1317    uintptr_t iParm = 0;
     1318    if (cParms == VBOX_SHCL_CPARMS_REPORT_FORMATS_61B)
     1319    {
     1320        ASSERT_GUEST_RETURN(paParms[iParm].type == VBOX_HGCM_SVC_PARM_64BIT, VERR_WRONG_PARAMETER_TYPE);
     1321        /* no defined value, so just ignore it */
     1322        iParm++;
     1323    }
     1324    ASSERT_GUEST_RETURN(paParms[iParm].type == VBOX_HGCM_SVC_PARM_32BIT, VERR_WRONG_PARAMETER_TYPE);
     1325    uint32_t const fFormats = paParms[iParm].u.uint32;
     1326    iParm++;
     1327    if (cParms == VBOX_SHCL_CPARMS_REPORT_FORMATS_61B)
     1328    {
     1329        ASSERT_GUEST_RETURN(paParms[iParm].type == VBOX_HGCM_SVC_PARM_32BIT, VERR_WRONG_PARAMETER_TYPE);
     1330        ASSERT_GUEST_RETURN(paParms[iParm].u.uint32 == 0, VERR_INVALID_FLAGS);
     1331        iParm++;
     1332    }
     1333    Assert(iParm == cParms);
     1334
     1335    /*
     1336     * Report the formats.
     1337     */
     1338    int rc = shClSvcSetSource(pClient, SHCLSOURCE_REMOTE);
     1339    if (RT_SUCCESS(rc))
     1340    {
     1341        if (g_ExtState.pfnExtension)
     1342        {
     1343            SHCLEXTPARMS parms;
     1344            RT_ZERO(parms);
     1345            parms.uFormat = fFormats;
     1346
     1347            g_ExtState.pfnExtension(g_ExtState.pvExtension, VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE, &parms, sizeof(parms));
     1348        }
     1349        else
     1350        {
     1351            SHCLCLIENTCMDCTX CmdCtx;
     1352            RT_ZERO(CmdCtx);
     1353
     1354            SHCLFORMATDATA FormatData;
     1355            FormatData.fFlags  = 0;
     1356            FormatData.Formats = fFormats;
     1357            rc = ShClSvcImplFormatAnnounce(pClient, &CmdCtx, &FormatData);
     1358        }
     1359
     1360        /** @todo r=bird: I'm not sure if the guest should be automatically allowed
     1361         *        to write the host clipboard now.  It would make more sense to disallow
     1362         *        host clipboard reads until the host reports formats.
     1363         *
     1364         *        The writes should only really be allowed upon request from the host,
     1365         *        shouldn't they? (Though, I'm not sure, maybe there are situations
     1366         *        where the guest side will just want to push the content over
     1367         *        immediately while it's still available, I don't quite recall now...
     1368         */
     1369        if (RT_SUCCESS(rc))
     1370            pClient->State.fFlags |= SHCLCLIENTSTATE_FLAGS_WRITE_ACTIVE;
     1371    }
     1372
     1373    return rc;
     1374}
     1375
    12921376/**
    12931377 * Handles the VBOX_SHCL_GUEST_FN_DATA_READ message from the guest.
     
    17491833    {
    17501834        case VBOX_SHCL_GUEST_FN_GET_HOST_MSG_OLD:
    1751         {
    17521835            rc = shClSvcMsgGetOld(pClient, callHandle, cParms, paParms);
    17531836            break;
    1754         }
    17551837
    17561838        case VBOX_SHCL_GUEST_FN_CONNECT:
     
    17771859                rc = VINF_SUCCESS;
    17781860            }
    1779 
    17801861            break;
    17811862        }
    17821863
    17831864        case VBOX_SHCL_GUEST_FN_REPORT_FEATURES:
    1784         {
    17851865            rc = shClSvcClientReportFeatures(pClient, callHandle, cParms, paParms);
    17861866            break;
    1787         }
    17881867
    17891868        case VBOX_SHCL_GUEST_FN_QUERY_FEATURES:
    1790         {
    17911869            rc = shClSvcClientQueryFeatures(callHandle, cParms, paParms);
    17921870            break;
    1793         }
    17941871
    17951872        case VBOX_SHCL_GUEST_FN_MSG_PEEK_NOWAIT:
    1796         {
    17971873            rc = shClSvcMsgPeek(pClient, callHandle, cParms, paParms, false /*fWait*/);
    17981874            break;
    1799         }
    18001875
    18011876        case VBOX_SHCL_GUEST_FN_MSG_PEEK_WAIT:
    1802         {
    18031877            rc = shClSvcMsgPeek(pClient, callHandle, cParms, paParms, true /*fWait*/);
    18041878            break;
    1805         }
    18061879
    18071880        case VBOX_SHCL_GUEST_FN_MSG_GET:
    1808         {
    18091881            rc = shClSvcMsgGet(pClient, callHandle, cParms, paParms);
    18101882            break;
    1811         }
    1812 
    1813         case VBOX_SHCL_GUEST_FN_FORMATS_REPORT:
    1814         {
    1815             uint32_t uFormats = 0;
    1816 
    1817             if (!(pClient->State.fGuestFeatures0 & VBOX_SHCL_GF_0_CONTEXT_ID)) /* Legacy, Guest Additions < 6.1. */
    1818             {
    1819                 if (cParms != 1)
    1820                 {
    1821                     rc = VERR_INVALID_PARAMETER;
    1822                 }
    1823                 else if (paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT) /* uFormats */
    1824                 {
    1825                     rc = VERR_INVALID_PARAMETER;
    1826                 }
    1827                 else
    1828                 {
    1829                     rc = HGCMSvcGetU32(&paParms[0], &uFormats);
    1830                 }
    1831             }
    1832             else
    1833             {
    1834                 if (cParms != 3)
    1835                 {
    1836                     rc = VERR_INVALID_PARAMETER;
    1837                 }
    1838                 else if (   paParms[0].type != VBOX_HGCM_SVC_PARM_64BIT  /* uContextID */
    1839                          || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT  /* uFormats */
    1840                          || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT) /* fFlags */
    1841                 {
    1842                     rc = VERR_INVALID_PARAMETER;
    1843                 }
    1844                 else
    1845                 {
    1846                     rc = HGCMSvcGetU32(&paParms[1], &uFormats);
    1847 
    1848                     /** @todo Handle rest. */
    1849                 }
    1850             }
    1851 
    1852             if (RT_SUCCESS(rc))
    1853             {
    1854                 if (   ShClSvcGetMode() != VBOX_SHCL_MODE_GUEST_TO_HOST
    1855                     && ShClSvcGetMode() != VBOX_SHCL_MODE_BIDIRECTIONAL)
    1856                 {
    1857                     rc = VERR_ACCESS_DENIED;
    1858                 }
    1859                 else if (uFormats != VBOX_SHCL_FMT_NONE) /* Only announce formats if we actually *have* formats to announce! */
    1860                 {
    1861                     rc = shClSvcSetSource(pClient, SHCLSOURCE_REMOTE);
    1862                     if (RT_SUCCESS(rc))
    1863                     {
    1864                         if (g_ExtState.pfnExtension)
    1865                         {
    1866                             SHCLEXTPARMS parms;
    1867                             RT_ZERO(parms);
    1868 
    1869                             parms.uFormat = uFormats;
    1870 
    1871                             g_ExtState.pfnExtension(g_ExtState.pvExtension, VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
    1872                                                     &parms, sizeof(parms));
    1873                         }
    1874                         else
    1875                         {
    1876 
    1877                             SHCLCLIENTCMDCTX cmdCtx;
    1878                             RT_ZERO(cmdCtx);
    1879 
    1880                             SHCLFORMATDATA formatData;
    1881                             RT_ZERO(formatData);
    1882 
    1883                             formatData.Formats = uFormats;
    1884                             Assert(formatData.Formats != VBOX_SHCL_FMT_NONE); /* Sanity. */
    1885 
    1886                             rc = ShClSvcImplFormatAnnounce(pClient, &cmdCtx, &formatData);
    1887                         }
    1888 
    1889                         /** @todo r=bird: I'm not sure if the guest should be automatically allowed
    1890                          *        to write the host clipboard now.  It would make more sense to disallow
    1891                          *        host clipboard reads until the host reports formats.
    1892                          *
    1893                          *        The writes should only really be allowed upon request from the host,
    1894                          *        shouldn't they? (Though, I'm not sure, maybe there are situations
    1895                          *        where the guest side will just want to push the content over
    1896                          *        immediately while it's still available, I don't quite recall now...
    1897                          */
    1898                         if (RT_SUCCESS(rc))
    1899                             pClient->State.fFlags |= SHCLCLIENTSTATE_FLAGS_WRITE_ACTIVE;
    1900                     }
    1901                 }
    1902             }
    1903 
     1883
     1884        case VBOX_SHCL_GUEST_FN_REPORT_FORMATS:
     1885            rc = shClSvcGuestReportFormats(pClient, cParms, paParms);
    19041886            break;
    1905         }
    19061887
    19071888        case VBOX_SHCL_GUEST_FN_DATA_READ:
Note: See TracChangeset for help on using the changeset viewer.

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