VirtualBox

Changeset 103480 in vbox


Ignore:
Timestamp:
Feb 20, 2024 3:21:35 PM (9 months ago)
Author:
vboxsync
Message:

Shared Clipboard: Added a ShClTransferTransformPath() function to make the paths more uniform. bugref:9437

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/SharedClipboard-transfers.h

    r103442 r103480  
    345345typedef struct _SHCLOBJOPENCREATEPARMS
    346346{
    347     /** Path to object to open / create. */
     347    /** Path to object to open / create.
     348     *  Always stored as UNIX-style paths ('/').
     349     *  Backslashes ('\') can be part of a UNIX path though. */
    348350    char                       *pszPath;
    349351    /** Size (in bytes) of path to to object. */
     
    421423    /** Size (in bytes) of the listing path. */
    422424    uint32_t cbPath;
    423     /** Listing path (absolute). If empty or NULL the listing's root path will be opened. */
     425    /** Listing path (absolute). If empty or NULL the listing's root path will be opened.
     426     *  We always use UNIX-style paths. */
    424427    char    *pszPath;
    425428} SHCLLISTOPENPARMS;
     
    12661269int ShClPathSanitize(char *pszPath, size_t cbPath);
    12671270const char *ShClTransferStatusToStr(SHCLTRANSFERSTATUS enmStatus);
     1271int ShClTransferTransformPath(char *pszPath, size_t cbPath);
    12681272int ShClTransferValidatePath(const char *pcszPath, bool fMustExist);
    12691273int ShClTransferResolvePathAbs(PSHCLTRANSFER pTransfer, const char *pszPath, uint32_t fFlags, char **ppszResolved);
  • trunk/include/VBox/HostServices/VBoxClipboardSvc.h

    r100367 r103480  
    990990    /** pointer, in: Filter string. */
    991991    HGCMFunctionParameter pvFilter;
    992     /** pointer, in: Listing poth. If empty or NULL the listing's root path will be opened. */
     992    /** pointer, in: Listing path. If empty or NULL the listing's root path will be opened.
     993     *  We always use UNIX-style paths. */
    993994    HGCMFunctionParameter pvPath;
    994995    /** uint64_t, out: List handle. */
     
    11101111    /** uint64_t, out: Object handle. */
    11111112    HGCMFunctionParameter uHandle;
    1112     /** pointer, in: Absoulte path of object to open/create. */
     1113    /** pointer, in: Absoulte path of object to open/create.
     1114     *  We always use UNIX-style paths. */
    11131115    HGCMFunctionParameter szPath;
    11141116    /** uint32_t in: Open / Create flags of type SHCL_OBJ_CF_. */
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp

    r103442 r103480  
    11961196    AssertPtrReturn(phList,     VERR_INVALID_POINTER);
    11971197
     1198    int rc = ShClTransferTransformPath(pOpenParms->pszPath, pOpenParms->cbPath);
     1199    AssertRCReturn(rc, rc);
     1200
    11981201    VBoxShClListOpenMsg Msg;
    11991202    VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
     
    12061209    Msg.uHandle.SetUInt64(0);
    12071210
    1208     int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
    1209     if (RT_SUCCESS(rc))
    1210     {
     1211    rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
     1212    if (RT_SUCCESS(rc))
    12111213        rc = Msg.uHandle.GetUInt64(phList); AssertRC(rc);
    1212     }
    12131214
    12141215    LogFlowFuncLeaveRC(rc);
     
    17011702    AssertPtrReturn(phObj,        VERR_INVALID_POINTER);
    17021703
     1704    int rc = ShClTransferTransformPath(pCreateParms->pszPath, pCreateParms->cbPath);
     1705    AssertRCReturn(rc, rc);
     1706
    17031707    VBoxShClObjOpenMsg Msg;
    17041708    VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
     
    17101714    Msg.fCreate.SetUInt32(pCreateParms->fCreate);
    17111715
    1712     int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
    1713     if (RT_SUCCESS(rc))
    1714     {
     1716    rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
     1717    if (RT_SUCCESS(rc))
    17151718        Msg.uHandle.GetUInt64(phObj);
    1716     }
    17171719
    17181720    LogFlowFuncLeaveRC(rc);
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardStreamImpl-win.cpp

    r100665 r103480  
    3838
    3939#include <VBox/GuestHost/SharedClipboard.h>
     40#include <VBox/GuestHost/SharedClipboard-transfers.h>
    4041#include <VBox/GuestHost/SharedClipboard-win.h>
    4142
     
    211212            rc = RTStrCopy(openParms.pszPath, openParms.cbPath, m_strPath.c_str());
    212213            if (RT_SUCCESS(rc))
    213                 rc = ShClTransferObjOpen(m_pTransfer, &openParms, &m_hObj);
     214            {
     215                rc = ShClTransferTransformPath(openParms.pszPath, openParms.cbPath);
     216                if (RT_SUCCESS(rc))
     217                    rc = ShClTransferObjOpen(m_pTransfer, &openParms, &m_hObj);
     218            }
    214219
    215220            ShClTransferObjOpenParmsDestroy(&openParms);
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers.cpp

    r103477 r103480  
    33683368    }
    33693369    return "Unknown";
     3370}
     3371
     3372/**
     3373 * Transforms a path so that it can be sent over to the other party.
     3374 *
     3375 * @returns VBox status code.
     3376 * @param   pszPath             Path to transform. Will be modified in place.
     3377 * @param   cbPath              Size (in bytes) of \a pszPath.
     3378 *
     3379 * @note    Shared Clipboard file paths always are sent over as UNIX-style paths.
     3380 *          Sending over back slashes ('\') could happen on non-Windows OSes as part of a path or file name.
     3381 */
     3382int ShClTransferTransformPath(char *pszPath, size_t cbPath)
     3383{
     3384#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
     3385    RT_NOREF(cbPath);
     3386    RTPathChangeToUnixSlashes(pszPath, true /* fForce */);
     3387#else
     3388    RT_NOREF(pszPath, cbPath);
     3389#endif
     3390    return VINF_SUCCESS;
    33703391}
    33713392
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-transfers.cpp

    r103442 r103480  
    4343#include <iprt/file.h>
    4444#include <iprt/path.h>
     45
     46#include <VBox/GuestHost/SharedClipboard-transfers.h>
    4547
    4648#include "VBoxSharedClipboardSvc-internal.h"
     
    326328                                                   pEvent->idEvent);
    327329
    328             rc = shClSvcTransferSetListOpen(pMsg->cParms, pMsg->aParms, pMsg->idCtx, pOpenParms);
     330            rc = ShClTransferTransformPath(pOpenParms->pszPath, pOpenParms->cbPath);
     331            if (RT_SUCCESS(rc))
     332                rc = shClSvcTransferSetListOpen(pMsg->cParms, pMsg->aParms, pMsg->idCtx, pOpenParms);
    329333            if (RT_SUCCESS(rc))
    330334            {
     
    604608            LogFlowFunc(("pszPath=%s, fCreate=0x%x\n", pCreateParms->pszPath, pCreateParms->fCreate));
    605609
    606             const uint32_t cbPath = (uint32_t)strlen(pCreateParms->pszPath) + 1; /* Include terminating zero */
    607 
    608             HGCMSvcSetU64(&pMsg->aParms[0], VBOX_SHCL_CONTEXTID_MAKE(pClient->State.uSessionID,
    609                                                                      pCtx->pTransfer->State.uID, pEvent->idEvent));
    610             HGCMSvcSetU64(&pMsg->aParms[1], 0); /* uHandle */
    611             HGCMSvcSetPv (&pMsg->aParms[2], pCreateParms->pszPath, cbPath);
    612             HGCMSvcSetU32(&pMsg->aParms[3], pCreateParms->fCreate);
    613 
    614             shClSvcClientLock(pClient);
    615 
    616             shClSvcMsgAdd(pClient, pMsg, true /* fAppend */);
    617             rc = shClSvcClientWakeup(pClient);
    618 
    619             shClSvcClientUnlock(pClient);
    620 
     610            rc = ShClTransferTransformPath(pCreateParms->pszPath, pCreateParms->cbPath);
    621611            if (RT_SUCCESS(rc))
    622612            {
    623                 int               rcEvent;
    624                 PSHCLEVENTPAYLOAD pPayload;
    625                 rc = ShClEventWaitEx(pEvent, pCtx->pTransfer->uTimeoutMs, &rcEvent, &pPayload);
     613                const uint32_t cbPath = (uint32_t)strlen(pCreateParms->pszPath) + 1; /* Include terminating zero */
     614
     615                HGCMSvcSetU64(&pMsg->aParms[0], VBOX_SHCL_CONTEXTID_MAKE(pClient->State.uSessionID,
     616                                                                         pCtx->pTransfer->State.uID, pEvent->idEvent));
     617                HGCMSvcSetU64(&pMsg->aParms[1], 0); /* uHandle */
     618                HGCMSvcSetPv (&pMsg->aParms[2], pCreateParms->pszPath, cbPath);
     619                HGCMSvcSetU32(&pMsg->aParms[3], pCreateParms->fCreate);
     620
     621                shClSvcClientLock(pClient);
     622
     623                shClSvcMsgAdd(pClient, pMsg, true /* fAppend */);
     624                rc = shClSvcClientWakeup(pClient);
     625
     626                shClSvcClientUnlock(pClient);
     627
    626628                if (RT_SUCCESS(rc))
    627629                {
    628                     Assert(pPayload->cbData == sizeof(SHCLREPLY));
    629 
    630                     PSHCLREPLY pReply = (PSHCLREPLY)pPayload->pvData;
    631                     AssertPtr(pReply);
    632 
    633                     Assert(pReply->uType == VBOX_SHCL_TX_REPLYMSGTYPE_OBJ_OPEN);
    634 
    635                     LogFlowFunc(("hObj=%RU64\n", pReply->u.ObjOpen.uHandle));
    636 
    637                     *phObj = pReply->u.ObjOpen.uHandle;
    638 
    639                     ShClPayloadFree(pPayload);
     630                    int               rcEvent;
     631                    PSHCLEVENTPAYLOAD pPayload;
     632                    rc = ShClEventWaitEx(pEvent, pCtx->pTransfer->uTimeoutMs, &rcEvent, &pPayload);
     633                    if (RT_SUCCESS(rc))
     634                    {
     635                        Assert(pPayload->cbData == sizeof(SHCLREPLY));
     636
     637                        PSHCLREPLY pReply = (PSHCLREPLY)pPayload->pvData;
     638                        AssertPtr(pReply);
     639
     640                        Assert(pReply->uType == VBOX_SHCL_TX_REPLYMSGTYPE_OBJ_OPEN);
     641
     642                        LogFlowFunc(("hObj=%RU64\n", pReply->u.ObjOpen.uHandle));
     643
     644                        *phObj = pReply->u.ObjOpen.uHandle;
     645
     646                        ShClPayloadFree(pPayload);
     647                    }
     648                    else
     649                        rc = rcEvent;
    640650                }
    641                 else
    642                     rc = rcEvent;
    643651            }
    644652
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