VirtualBox

Ignore:
Timestamp:
May 23, 2019 10:07:21 AM (6 years ago)
Author:
vboxsync
Message:

Shared Clipboard/URI: Update.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardCache.cpp

    r78618 r78683  
    3737    : m_cRefs(0)
    3838    , m_fOpen(0)
    39     , m_hDir(NULL)
     39    , m_hDir(NIL_RTDIR)
     40    , m_uID(NIL_SHAREDCLIPBOARDAREAID)
    4041{
    4142    int rc = initInternal();
     
    4546
    4647SharedClipboardCache::SharedClipboardCache(const char *pszPath,
     48                                           SHAREDCLIPBOARDAREAID uID /* = NIL_SHAREDCLIPBOARDAREAID */,
    4749                                           SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
    4850    : m_cRefs(0)
    4951    , m_fOpen(0)
    50     , m_hDir(NULL)
     52    , m_hDir(NIL_RTDIR)
     53    , m_uID(uID)
    5154{
    5255    int rc = initInternal();
     
    140143{
    141144    int rc;
    142     if (this->m_hDir != NULL)
     145    if (this->m_hDir != NIL_RTDIR)
    143146    {
    144147        rc = RTDirClose(this->m_hDir);
    145148        if (RT_SUCCESS(rc))
    146             this->m_hDir = NULL;
     149            this->m_hDir = NIL_RTDIR;
    147150    }
    148151    else
    149152        rc = VINF_SUCCESS;
    150153
     154    this->m_fOpen = SHAREDCLIPBOARDCACHE_FLAGS_NONE;
     155    this->m_uID   = NIL_SHAREDCLIPBOARDAREAID;
     156
    151157    LogFlowFuncLeaveRC(rc);
    152158    return rc;
    153159}
    154160
     161/**
     162 * Construcuts the cache's base path.
     163 *
     164 * @returns VBox status code.
     165 * @param   pszBase             Base path to use for the cache.
     166 * @param   pszPath             Where to store the constructured cache base path.
     167 * @param   cbPath              Size (in bytes) of the constructured cache base path.
     168 */
     169int SharedClipboardCache::pathConstruct(const char *pszBase, char *pszPath, size_t cbPath)
     170{
     171    RTStrPrintf(pszPath, cbPath, "%s", pszBase);
     172
     173    /** @todo On Windows we also could use the registry to override
     174     *        this path, on Posix a dotfile and/or a guest property
     175     *        can be used. */
     176
     177    /* Append our base cache directory. */
     178    int rc = RTPathAppend(pszPath, sizeof(pszPath), "VirtualBox Shared Clipboards"); /** @todo Make this tag configurable? */
     179    if (RT_FAILURE(rc))
     180        return rc;
     181
     182    /* Create it when necessary. */
     183    if (!RTDirExists(pszPath))
     184    {
     185        rc = RTDirCreateFullPath(pszPath, RTFS_UNIX_IRWXU);
     186        if (RT_FAILURE(rc))
     187            return rc;
     188    }
     189
     190    rc = RTPathAppend(pszPath, sizeof(pszPath), "Clipboard");
     191    return rc;
     192}
     193
    155194int SharedClipboardCache::Close(void)
    156195{
     
    158197}
    159198
     199SHAREDCLIPBOARDAREAID SharedClipboardCache::GetAreaID(void) const
     200{
     201    return this->m_uID;
     202}
     203
    160204const char *SharedClipboardCache::GetDirAbs(void) const
    161205{
     
    168212}
    169213
    170 int SharedClipboardCache::OpenEx(const char *pszPath, SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
     214int SharedClipboardCache::OpenEx(const char *pszPath,
     215                                 SHAREDCLIPBOARDAREAID uID /* = NIL_SHAREDCLIPBOARDAREAID */,
     216                                 SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
    171217{
    172218    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
    173219    AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */
    174220
    175     int rc;
    176 
    177     do
    178     {
    179         char pszDropDir[RTPATH_MAX];
    180         RTStrPrintf(pszDropDir, sizeof(pszDropDir), "%s", pszPath);
    181 
    182         /** @todo On Windows we also could use the registry to override
    183          *        this path, on Posix a dotfile and/or a guest property
    184          *        can be used. */
    185 
    186         /* Append our base drop directory. */
    187         rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), "VirtualBox Shared Clipboard Files"); /** @todo Make this tag configurable? */
    188         if (RT_FAILURE(rc))
    189             break;
    190 
    191         /* Create it when necessary. */
    192         if (!RTDirExists(pszDropDir))
    193         {
    194             rc = RTDirCreateFullPath(pszDropDir, RTFS_UNIX_IRWXU);
    195             if (RT_FAILURE(rc))
    196                 break;
    197         }
    198 
    199         /* The actually drop directory consist of the current time stamp and a
    200          * unique number when necessary. */
    201         char pszTime[64];
    202         RTTIMESPEC time;
    203         if (!RTTimeSpecToString(RTTimeNow(&time), pszTime, sizeof(pszTime)))
    204         {
    205             rc = VERR_BUFFER_OVERFLOW;
    206             break;
    207         }
    208 
    209         rc = SharedClipboardPathSanitizeFilename(pszTime, sizeof(pszTime));
    210         if (RT_FAILURE(rc))
    211             break;
    212 
    213         rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), pszTime);
    214         if (RT_FAILURE(rc))
    215             break;
    216 
     221    char szCacheDir[RTPATH_MAX];
     222    int rc = pathConstruct(pszPath, szCacheDir, sizeof(szCacheDir));
     223    if (RT_SUCCESS(rc))
     224    {
    217225        /* Create it (only accessible by the current user) */
    218         rc = RTDirCreateUniqueNumbered(pszDropDir, sizeof(pszDropDir), RTFS_UNIX_IRWXU, 3, '-');
     226        rc = RTDirCreateUniqueNumbered(szCacheDir, sizeof(szCacheDir), RTFS_UNIX_IRWXU, 3, '-');
    219227        if (RT_SUCCESS(rc))
    220228        {
    221229            RTDIR hDir;
    222             rc = RTDirOpen(&hDir, pszDropDir);
     230            rc = RTDirOpen(&hDir, szCacheDir);
    223231            if (RT_SUCCESS(rc))
    224232            {
    225233                this->m_hDir       = hDir;
    226                 this->m_strPathAbs = pszDropDir;
     234                this->m_strPathAbs = szCacheDir;
    227235                this->m_fOpen      = fFlags;
     236                this->m_uID        = uID;
    228237            }
    229238        }
    230 
    231     } while (0);
     239    }
    232240
    233241    LogFlowFuncLeaveRC(rc);
     
    235243}
    236244
    237 int SharedClipboardCache::OpenTemp(SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
     245int SharedClipboardCache::OpenTemp(SHAREDCLIPBOARDAREAID uID,
     246                                   SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
    238247{
    239248    AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */
     
    247256    int rc = RTPathTemp(szTemp, sizeof(szTemp));
    248257    if (RT_SUCCESS(rc))
    249         rc = OpenEx(szTemp, fFlags);
     258        rc = OpenEx(szTemp, uID, fFlags);
    250259
    251260    return rc;
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardMetaData.cpp

    r78651 r78683  
    2323#include <VBox/GuestHost/SharedClipboard-uri.h>
    2424
     25/**
     26 * Initializes a clipboard meta data struct.
     27 *
     28 * @returns VBox status code.
     29 * @param   pMeta               Meta data struct to initialize.
     30 */
    2531int SharedClipboardMetaDataInit(PSHAREDCLIPBOARDMETADATA pMeta)
    2632{
     
    3642}
    3743
     44/**
     45 * Destroys a clipboard meta data struct by free'ing all its data.
     46 *
     47 * @param   pMeta               Meta data struct to destroy.
     48 */
    3849void SharedClipboardMetaDataDestroy(PSHAREDCLIPBOARDMETADATA pMeta)
    3950{
     
    5465}
    5566
     67/**
     68 * Adds new meta data to a meta data struct.
     69 *
     70 * @returns VBox status code.
     71 * @param   pMeta               Meta data struct to add data to.
     72 */
    5673int SharedClipboardMetaDataAdd(PSHAREDCLIPBOARDMETADATA pMeta, const void *pvDataAdd, uint32_t cbDataAdd)
    5774{
     
    7491}
    7592
     93/**
     94 * Resizes the data buffer of a meta data struct.
     95 * Note: At the moment only supports growing the data buffer.
     96 *
     97 * @returns VBox status code.
     98 * @param   pMeta               Meta data struct to resize.
     99 * @param   cbNewSize           New size (in bytes) to use for resizing.
     100 */
    76101int SharedClipboardMetaDataResize(PSHAREDCLIPBOARDMETADATA pMeta, size_t cbNewSize)
    77102{
     
    86111    if (cbNewSize == pMeta->cbMeta)
    87112        return VINF_SUCCESS;
     113
     114    if (cbNewSize > _32M) /* Meta data can be up to 32MB. */
     115        return VERR_INVALID_PARAMETER;
    88116
    89117    void *pvTmp = NULL;
     
    110138}
    111139
     140/**
     141 * Returns the actual used bytes of a meta data struct.
     142 *
     143 * @returns Actual used bytes of a meta data struct.
     144 * @param   pMeta               Meta data struct to return used bytes for.
     145 */
    112146size_t SharedClipboardMetaDataGetUsed(PSHAREDCLIPBOARDMETADATA pMeta)
    113147{
     
    116150}
    117151
     152/**
     153 * Returns the overall (allocated) size in bytes of a meta data struct.
     154 *
     155 * @returns Overall (allocated) size of a meta data struct.
     156 * @param   pMeta               Meta data struct to return size for.
     157 */
    118158size_t SharedClipboardMetaDataGetSize(PSHAREDCLIPBOARDMETADATA pMeta)
    119159{
     
    122162}
    123163
     164/**
     165 * Returns the a mutable raw pointer to the actual meta data.
     166 *
     167 * @returns Mutable raw pointer to the actual meta data.
     168 * @param   pMeta               Meta data struct to return mutable data pointer for.
     169 */
     170void *SharedClipboardMetaDataMutableRaw(PSHAREDCLIPBOARDMETADATA pMeta)
     171{
     172    return pMeta->pvMeta;
     173}
     174
     175/**
     176 * Returns the a const'ed raw pointer to the actual meta data.
     177 *
     178 * @returns Const'ed raw pointer to the actual meta data.
     179 * @param   pMeta               Meta data struct to return const'ed data pointer for.
     180 */
    124181const void *SharedClipboardMetaDataRaw(PSHAREDCLIPBOARDMETADATA pMeta)
    125182{
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