VirtualBox

Changeset 81768 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Nov 11, 2019 4:36:41 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134559
Message:

Shared Clipboard: Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp

    r81559 r81768  
    211211
    212212/**
    213  * Receives a host request to read clipboard data request from the guest.
     213 * Receives a host request to read clipboard data from the guest.
    214214 *
    215215 * @returns VBox status code.
     
    225225
    226226    VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID,
    227                        VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_READ_DATA);
     227                       VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_READ_DATA_REQ);
    228228
    229229    Msg.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_READ_DATA);
     230    Msg.fFlags.SetUInt32(0);
    230231    Msg.uFormat.SetUInt32(0);
    231232    Msg.cbSize.SetUInt32(0);
     
    290291 * Reads data from the host clipboard.
    291292 *
     293 * Legacy function, do not use anymore.
     294 *
    292295 * @returns VBox status code.
    293296 * @retval  VINF_BUFFER_OVERFLOW    If there is more data available than the caller provided buffer space for.
     
    295298 * @param   idClient        The client id returned by VbglR3ClipboardConnect().
    296299 * @param   fFormat         The format we're requesting the data in.
    297  * @param   pv              Where to store the data.
    298  * @param   cb              The size of the buffer pointed to by pv.
    299  * @param   pcb             The actual size of the host clipboard data. May be larger than cb.
    300  */
    301 VBGLR3DECL(int) VbglR3ClipboardReadData(HGCMCLIENTID idClient, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcb)
     300 * @param   pvData          Where to store the data.
     301 * @param   cbData          The size of the buffer pointed to by \a pvData.
     302 * @param   pcbRead         The actual size of the host clipboard data. May be larger than \a cbData.
     303 */
     304VBGLR3DECL(int) VbglR3ClipboardReadData(HGCMCLIENTID idClient, uint32_t fFormat, void *pvData, uint32_t cbData,
     305                                        uint32_t *pcbRead)
    302306{
    303307    VBoxShClReadDataMsg Msg;
    304308
    305     VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHCL_GUEST_FN_DATA_READ, VBOX_SHCL_CPARMS_READ_DATA);
    306     VbglHGCMParmUInt32Set(&Msg.format, fFormat);
    307     VbglHGCMParmPtrSet(&Msg.ptr, pv, cb);
    308     VbglHGCMParmUInt32Set(&Msg.size, 0);
    309 
    310     int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
    311     if (RT_SUCCESS(rc))
    312     {
    313         uint32_t cbActual;
    314         int rc2 = VbglHGCMParmUInt32Get(&Msg.size, &cbActual);
    315         if (RT_SUCCESS(rc2))
    316         {
    317             *pcb = cbActual;
    318             if (cbActual > cb)
    319                 return VINF_BUFFER_OVERFLOW;
    320             return rc;
    321         }
    322         rc = rc2;
    323     }
     309    LogFlowFuncEnter();
     310
     311    VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHCL_GUEST_FN_DATA_READ, 3);
     312
     313    VbglHGCMParmUInt32Set(&Msg.u.v0.format, fFormat);
     314    VbglHGCMParmPtrSet(&Msg.u.v0.ptr, pvData, cbData);
     315    VbglHGCMParmUInt32Set(&Msg.u.v0.size, 0);
     316
     317    int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg.hdr) + sizeof(Msg.u.v0));
     318    if (RT_SUCCESS(rc))
     319    {
     320        uint32_t cbRead;
     321        rc = VbglHGCMParmUInt32Get(&Msg.u.v0.size, &cbRead);
     322        if (RT_SUCCESS(rc))
     323        {
     324            LogFlowFunc(("cbRead=%RU32\n", cbRead));
     325
     326            if (cbRead > cbData)
     327                rc = VINF_BUFFER_OVERFLOW;
     328
     329            *pcbRead = cbRead;
     330        }
     331    }
     332
     333    LogFlowFuncLeaveRC(rc);
     334    return rc;
     335}
     336
     337/**
     338 * Reads clipboard data from the host clipboard.
     339 *
     340 * @returns VBox status code.
     341 * @retval  VINF_BUFFER_OVERFLOW    If there is more data available than the caller provided buffer space for.
     342 *
     343 * @param   pCtx                The command context returned by VbglR3ClipboardConnectEx().
     344 * @param   pData               Where to store the clipboard data read.
     345 * @param   pcbRead             The actual size of the host clipboard data.
     346 */
     347VBGLR3DECL(int) VbglR3ClipboardReadDataEx(PVBGLR3SHCLCMDCTX pCtx, PSHCLDATABLOCK pData, uint32_t *pcbRead)
     348{
     349    AssertPtrReturn(pCtx,  VERR_INVALID_POINTER);
     350    AssertPtrReturn(pData, VERR_INVALID_POINTER);
     351
     352    int rc;
     353
     354    LogFlowFuncEnter();
     355
     356    if (pCtx->fUseLegacyProtocol)
     357    {
     358        rc = VbglR3ClipboardReadData(pCtx->uClientID, pData->uFormat, pData->pvData, pData->cbData, pcbRead);
     359    }
     360    else
     361    {
     362        VBoxShClReadDataMsg Msg;
     363
     364        VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, VBOX_SHCL_GUEST_FN_DATA_READ, VBOX_SHCL_CPARMS_READ_DATA);
     365
     366        VbglHGCMParmUInt64Set(&Msg.u.v1.uContext, pCtx->uContextID);
     367        VbglHGCMParmUInt32Set(&Msg.u.v1.fFlags, 0);
     368        VbglHGCMParmUInt32Set(&Msg.u.v1.uFormat, pData->uFormat);
     369        VbglHGCMParmUInt32Set(&Msg.u.v1.cbData, pData->cbData);
     370        VbglHGCMParmPtrSet(&Msg.u.v1.pvData, pData->pvData, pData->cbData);
     371
     372        rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg.hdr) + sizeof(Msg.u.v1));
     373        if (RT_SUCCESS(rc))
     374        {
     375            uint32_t cbRead;
     376            rc = VbglHGCMParmUInt32Get(&Msg.u.v1.cbData, &cbRead);
     377            if (RT_SUCCESS(rc))
     378            {
     379                LogFlowFunc(("cbRead=%RU32\n", cbRead));
     380
     381                if (cbRead > pData->cbData)
     382                    rc = VINF_BUFFER_OVERFLOW;
     383
     384                *pcbRead = cbRead;
     385            }
     386        }
     387    }
     388
     389    LogFlowFuncLeaveRC(rc);
    324390    return rc;
    325391}
     
    23402406    VbglHGCMParmUInt32Set(&Msg.u.v0.uFormats, fFormats);
    23412407
    2342     return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg.hdr) + sizeof(Msg.u.v0));
    2343 }
    2344 
    2345 /**
    2346  * Sends guest clipboard data to the host. Legacy function kept for compatibility, do not use anymore.
     2408    int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg.hdr) + sizeof(Msg.u.v0));
     2409
     2410    LogFlowFuncLeaveRC(rc);
     2411    return rc;
     2412}
     2413
     2414/**
     2415 * Sends guest clipboard data to the host.
     2416 *
     2417 * Legacy function kept for compatibility, do not use anymore.
    23472418 *
    23482419 * This is usually called in reply to a VBOX_SHCL_HOST_MSG_READ_DATA message
     
    23572428VBGLR3DECL(int) VbglR3ClipboardWriteData(HGCMCLIENTID idClient, uint32_t fFormat, void *pv, uint32_t cb)
    23582429{
    2359     AssertReturn   (idClient, VERR_INVALID_PARAMETER);
    2360     AssertPtrReturn(pv,       VERR_INVALID_POINTER);
    2361     AssertReturn   (cb,       VERR_INVALID_PARAMETER);
     2430    LogFlowFuncEnter();
    23622431
    23632432    VBoxShClWriteDataMsg Msg;
     
    23932462    int rc;
    23942463
     2464    LogFlowFuncEnter();
     2465
    23952466    if (pCtx->fUseLegacyProtocol)
    23962467    {
     
    24092480        Msg.u.v1.uContext.SetUInt64(pCtx->uContextID);
    24102481        Msg.u.v1.uFormat.SetUInt32(pData->uFormat);
     2482        Msg.u.v1.fFlags.SetUInt32(0);
    24112483        Msg.u.v1.cbData.SetUInt32(pData->cbData);
    24122484        Msg.u.v1.pvData.SetPtr(pData->pvData, pData->cbData);
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