VirtualBox

Ignore:
Timestamp:
Feb 14, 2014 9:46:58 AM (11 years ago)
Author:
vboxsync
Message:

DnD: Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDragAndDrop.cpp

    r50305 r50460  
    3939
    4040#include "VBGLR3Internal.h"
     41#include "VBox/GuestHost/DragAndDrop.h"
    4142#include "VBox/HostServices/DragAndDropSvc.h"
    4243
     
    4748 * Todo:
    4849 * - Sending dirs/files in the G->H case
    49  * - Maybe the EOL converting of text mime-types (not fully sure, eventually
     50 * - Maybe the EOL converting of text MIME types (not fully sure, eventually
    5051 *   better done on the host side)
    5152 */
    52 
    53 static int vbglR3DnDPathSanitize(char *pszPath, size_t cbPath);
    5453
    5554/******************************************************************************
    5655 *    Private internal functions                                              *
    5756 ******************************************************************************/
    58 
    59 static int vbglR3DnDCreateDropDir(char* pszDropDir, size_t cbSize)
    60 {
    61     AssertPtrReturn(pszDropDir, VERR_INVALID_POINTER);
    62     AssertReturn(cbSize,        VERR_INVALID_PARAMETER);
    63 
    64     /** @todo On Windows we also could use the registry to override
    65      *        this path, on Posix a dotfile and/or a guest property
    66      *        can be used. */
    67 
    68     /* Get the users temp directory. Don't use the user's root directory (or
    69      * something inside it) because we don't know for how long/if the data will
    70      * be kept after the guest OS used it. */
    71     int rc = RTPathTemp(pszDropDir, cbSize);
    72     if (RT_FAILURE(rc))
    73         return rc;
    74 
    75     /* Append our base drop directory. */
    76     rc = RTPathAppend(pszDropDir, cbSize, "VirtualBox Dropped Files");
    77     if (RT_FAILURE(rc))
    78         return rc;
    79 
    80     /* Create it when necessary. */
    81     if (!RTDirExists(pszDropDir))
    82     {
    83         rc = RTDirCreateFullPath(pszDropDir, RTFS_UNIX_IRWXU);
    84         if (RT_FAILURE(rc))
    85             return rc;
    86     }
    87 
    88     /* The actually drop directory consist of the current time stamp and a
    89      * unique number when necessary. */
    90     char pszTime[64];
    91     RTTIMESPEC time;
    92     if (!RTTimeSpecToString(RTTimeNow(&time), pszTime, sizeof(pszTime)))
    93         return VERR_BUFFER_OVERFLOW;
    94     rc = vbglR3DnDPathSanitize(pszTime, sizeof(pszTime));
    95     if (RT_FAILURE(rc))
    96         return rc;
    97 
    98     rc = RTPathAppend(pszDropDir, cbSize, pszTime);
    99     if (RT_FAILURE(rc))
    100         return rc;
    101 
    102     /* Create it (only accessible by the current user) */
    103     return RTDirCreateUniqueNumbered(pszDropDir, cbSize, RTFS_UNIX_IRWXU, 3, '-');
    104 }
    10557
    10658static int vbglR3DnDQueryNextHostMessageType(uint32_t uClientId, uint32_t *puMsg, uint32_t *pcParms, bool fWait)
     
    319271    AssertPtrReturn(pcbDataRecv, VERR_INVALID_POINTER);
    320272
     273    if (!*pcbDataRecv)
     274        return VERR_INVALID_PARAMETER;
     275
    321276    /* Make a string list out of the uri data. */
    322     RTCList<RTCString> uriList = RTCString(static_cast<char*>(*ppvData), *pcbDataRecv - 1).split("\r\n");
     277    RTCList<RTCString> uriList =
     278        RTCString(static_cast<char*>(*ppvData), *pcbDataRecv - 1).split("\r\n");
    323279    if (uriList.isEmpty())
    324280        return VINF_SUCCESS;
     
    331287    /* Create and query the (unique) drop target directory. */
    332288    char pszDropDir[RTPATH_MAX];
    333     int rc = vbglR3DnDCreateDropDir(pszDropDir, sizeof(pszDropDir));
     289    int rc = DnDDirCreateDroppedFiles(pszDropDir, sizeof(pszDropDir));
    334290    if (RT_FAILURE(rc))
    335291    {
     
    349305        if (pszFilePath)
    350306        {
    351             rc = vbglR3DnDPathSanitize(pszFilePath, strlen(pszFilePath));
     307            rc = DnDPathSanitize(pszFilePath, strlen(pszFilePath));
    352308            if (RT_FAILURE(rc))
    353309                break;
    354310
    355311            /** @todo Use RTPathJoin? */
    356             RTCString strFullPath = RTCString().printf("%s%c%s", pszDropDir, RTPATH_SLASH, pszFilePath);
     312            RTCString strFullPath
     313                = RTCString().printf("%s%c%s", pszDropDir, RTPATH_SLASH, pszFilePath);
    357314            char *pszNewUri = RTUriFileCreate(strFullPath.c_str());
    358315            if (pszNewUri)
     
    376333    }
    377334
    378     /* Lists for holding created files & directories in the case of a
    379      * rollback. */
     335    /* Lists for holding created files & directories
     336     * in the case of a rollback. */
    380337    RTCList<RTCString> guestDirList;
    381338    RTCList<RTCString> guestFileList;
    382     char pszPathname[RTPATH_MAX];
     339    char pszPathName[RTPATH_MAX];
    383340    uint32_t cbPathname = 0;
    384341    bool fLoop = RT_SUCCESS(rc); /* No error occurred yet? */
     
    396353                    uint32_t fMode = 0;
    397354                    rc = vbglR3DnDHGProcessSendDirMessage(uClientId,
    398                                                           pszPathname,
    399                                                           sizeof(pszPathname),
     355                                                          pszPathName,
     356                                                          sizeof(pszPathName),
    400357                                                          &cbPathname,
    401358                                                          &fMode);
    402359                    if (RT_SUCCESS(rc))
    403                         rc = vbglR3DnDPathSanitize(pszPathname, sizeof(pszPathname));
     360                        rc = DnDPathSanitize(pszPathName, sizeof(pszPathName));
    404361                    if (RT_SUCCESS(rc))
    405362                    {
    406                         char *pszNewDir = RTPathJoinA(pszDropDir, pszPathname);
     363                        char *pszNewDir = RTPathJoinA(pszDropDir, pszPathName);
    407364                        if (pszNewDir)
    408365                        {
     
    423380                    uint32_t fMode = 0;
    424381                    rc = vbglR3DnDHGProcessSendFileMessage(uClientId,
    425                                                            pszPathname,
    426                                                            sizeof(pszPathname),
     382                                                           pszPathName,
     383                                                           sizeof(pszPathName),
    427384                                                           &cbPathname,
    428385                                                           pvTmpData,
     
    431388                                                           &fMode);
    432389                    if (RT_SUCCESS(rc))
    433                         rc = vbglR3DnDPathSanitize(pszPathname, sizeof(pszPathname));
     390                        rc = DnDPathSanitize(pszPathName, sizeof(pszPathName));
    434391                    if (RT_SUCCESS(rc))
    435392                    {
    436                         char *pszNewFile = RTPathJoinA(pszDropDir, pszPathname);
     393                        char *pszNewFile = RTPathJoinA(pszDropDir, pszPathName);
    437394                        if (pszNewFile)
    438395                        {
     
    666623    {
    667624        /* Check if this is an URI event. If so, let VbglR3 do all the actual
    668          * data transfer + file /directory creation internally without letting
     625         * data transfer + file/directory creation internally without letting
    669626         * the caller know.
    670627         *
     
    747704    }
    748705
    749     return rc;
    750 }
    751 
    752 static int vbglR3DnDPathSanitize(char *pszPath, size_t cbPath)
    753 {
    754     int rc = VINF_SUCCESS;
    755 #ifdef RT_OS_WINDOWS
    756     /* Filter out characters not allowed on Windows platforms, put in by
    757        RTTimeSpecToString(). */
    758     /** @todo Use something like RTPathSanitize() when available. Later. */
    759     RTUNICP aCpSet[] =
    760         { ' ', ' ', '(', ')', '-', '.', '0', '9', 'A', 'Z', 'a', 'z', '_', '_',
    761           0xa0, 0xd7af, '\0' };
    762     ssize_t cReplaced = RTStrPurgeComplementSet(pszPath, aCpSet, '_' /* Replacement */);
    763     if (cReplaced < 0)
    764         rc = VERR_INVALID_UTF8_ENCODING;
    765 #endif
    766706    return rc;
    767707}
     
    886826                break;
    887827            }
     828#ifdef VBOX_WITH_DRAG_AND_DROP_GH
    888829            case DragAndDropSvc::HOST_DND_GH_REQ_PENDING:
    889830            {
     
    908849                break;
    909850            }
     851#endif
    910852            default:
     853            {
     854                pEvent->uType = uMsg;
     855
    911856                rc = VERR_NOT_SUPPORTED;
    912857                break;
     858            }
    913859        }
    914860    }
     
    979925}
    980926
    981 VBGLR3DECL(int) VbglR3DnDGHSendData(uint32_t u32ClientId, void *pvData, uint32_t cbData)
     927VBGLR3DECL(int) VbglR3DnDGHSendData(uint32_t u32ClientId,
     928                                    void *pvData, uint32_t cbData)
    982929{
    983930    AssertPtrReturn(pvData, VERR_INVALID_POINTER);
     
    993940
    994941    int rc          = VINF_SUCCESS;
    995     uint32_t cbMax  = _1M; /** @todo Remove 1 MB limit. */
     942    uint32_t cbMax  = _64K; /* Transfer max. 64K chunks per message. */
    996943    uint32_t cbSent = 0;
    997944
    998945    while (cbSent < cbData)
    999946    {
    1000         /* Initialize parameter */
    1001947        uint32_t cbToSend = RT_MIN(cbData - cbSent, cbMax);
    1002948        Msg.pData.SetPtr(static_cast<uint8_t*>(pvData) + cbSent, cbToSend);
    1003         /* Do request */
     949
    1004950        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
    1005951        if (RT_SUCCESS(rc))
    1006         {
    1007952            rc = Msg.hdr.result;
    1008             /* Did the host cancel the event? */
    1009             if (rc == VERR_CANCELLED)
    1010                 break;
    1011         }
    1012         else
     953
     954        if (RT_FAILURE(rc))
    1013955            break;
     956
    1014957        cbSent += cbToSend;
    1015 //        RTThreadSleep(500);
    1016     }
     958    }
     959
     960    if (RT_SUCCESS(rc))
     961        Assert(cbSent == cbData);
    1017962
    1018963    return rc;
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