Index: trunk/src/VBox/GuestHost/SharedClipboard/ClipboardCache.cpp
===================================================================
--- trunk/src/VBox/GuestHost/SharedClipboard/ClipboardCache.cpp	(revision 78651)
+++ trunk/src/VBox/GuestHost/SharedClipboard/ClipboardCache.cpp	(revision 78683)
@@ -37,5 +37,6 @@
     : m_cRefs(0)
     , m_fOpen(0)
-    , m_hDir(NULL)
+    , m_hDir(NIL_RTDIR)
+    , m_uID(NIL_SHAREDCLIPBOARDAREAID)
 {
     int rc = initInternal();
@@ -45,8 +46,10 @@
 
 SharedClipboardCache::SharedClipboardCache(const char *pszPath,
+                                           SHAREDCLIPBOARDAREAID uID /* = NIL_SHAREDCLIPBOARDAREAID */,
                                            SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
     : m_cRefs(0)
     , m_fOpen(0)
-    , m_hDir(NULL)
+    , m_hDir(NIL_RTDIR)
+    , m_uID(uID)
 {
     int rc = initInternal();
@@ -140,17 +143,53 @@
 {
     int rc;
-    if (this->m_hDir != NULL)
+    if (this->m_hDir != NIL_RTDIR)
     {
         rc = RTDirClose(this->m_hDir);
         if (RT_SUCCESS(rc))
-            this->m_hDir = NULL;
+            this->m_hDir = NIL_RTDIR;
     }
     else
         rc = VINF_SUCCESS;
 
+    this->m_fOpen = SHAREDCLIPBOARDCACHE_FLAGS_NONE;
+    this->m_uID   = NIL_SHAREDCLIPBOARDAREAID;
+
     LogFlowFuncLeaveRC(rc);
     return rc;
 }
 
+/**
+ * Construcuts the cache's base path.
+ *
+ * @returns VBox status code.
+ * @param   pszBase             Base path to use for the cache.
+ * @param   pszPath             Where to store the constructured cache base path.
+ * @param   cbPath              Size (in bytes) of the constructured cache base path.
+ */
+int SharedClipboardCache::pathConstruct(const char *pszBase, char *pszPath, size_t cbPath)
+{
+    RTStrPrintf(pszPath, cbPath, "%s", pszBase);
+
+    /** @todo On Windows we also could use the registry to override
+     *        this path, on Posix a dotfile and/or a guest property
+     *        can be used. */
+
+    /* Append our base cache directory. */
+    int rc = RTPathAppend(pszPath, sizeof(pszPath), "VirtualBox Shared Clipboards"); /** @todo Make this tag configurable? */
+    if (RT_FAILURE(rc))
+        return rc;
+
+    /* Create it when necessary. */
+    if (!RTDirExists(pszPath))
+    {
+        rc = RTDirCreateFullPath(pszPath, RTFS_UNIX_IRWXU);
+        if (RT_FAILURE(rc))
+            return rc;
+    }
+
+    rc = RTPathAppend(pszPath, sizeof(pszPath), "Clipboard");
+    return rc;
+}
+
 int SharedClipboardCache::Close(void)
 {
@@ -158,4 +197,9 @@
 }
 
+SHAREDCLIPBOARDAREAID SharedClipboardCache::GetAreaID(void) const
+{
+    return this->m_uID;
+}
+
 const char *SharedClipboardCache::GetDirAbs(void) const
 {
@@ -168,66 +212,30 @@
 }
 
-int SharedClipboardCache::OpenEx(const char *pszPath, SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
+int SharedClipboardCache::OpenEx(const char *pszPath,
+                                 SHAREDCLIPBOARDAREAID uID /* = NIL_SHAREDCLIPBOARDAREAID */,
+                                 SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
 {
     AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
     AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */
 
-    int rc;
-
-    do
-    {
-        char pszDropDir[RTPATH_MAX];
-        RTStrPrintf(pszDropDir, sizeof(pszDropDir), "%s", pszPath);
-
-        /** @todo On Windows we also could use the registry to override
-         *        this path, on Posix a dotfile and/or a guest property
-         *        can be used. */
-
-        /* Append our base drop directory. */
-        rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), "VirtualBox Shared Clipboard Files"); /** @todo Make this tag configurable? */
-        if (RT_FAILURE(rc))
-            break;
-
-        /* Create it when necessary. */
-        if (!RTDirExists(pszDropDir))
-        {
-            rc = RTDirCreateFullPath(pszDropDir, RTFS_UNIX_IRWXU);
-            if (RT_FAILURE(rc))
-                break;
-        }
-
-        /* The actually drop directory consist of the current time stamp and a
-         * unique number when necessary. */
-        char pszTime[64];
-        RTTIMESPEC time;
-        if (!RTTimeSpecToString(RTTimeNow(&time), pszTime, sizeof(pszTime)))
-        {
-            rc = VERR_BUFFER_OVERFLOW;
-            break;
-        }
-
-        rc = SharedClipboardPathSanitizeFilename(pszTime, sizeof(pszTime));
-        if (RT_FAILURE(rc))
-            break;
-
-        rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), pszTime);
-        if (RT_FAILURE(rc))
-            break;
-
+    char szCacheDir[RTPATH_MAX];
+    int rc = pathConstruct(pszPath, szCacheDir, sizeof(szCacheDir));
+    if (RT_SUCCESS(rc))
+    {
         /* Create it (only accessible by the current user) */
-        rc = RTDirCreateUniqueNumbered(pszDropDir, sizeof(pszDropDir), RTFS_UNIX_IRWXU, 3, '-');
+        rc = RTDirCreateUniqueNumbered(szCacheDir, sizeof(szCacheDir), RTFS_UNIX_IRWXU, 3, '-');
         if (RT_SUCCESS(rc))
         {
             RTDIR hDir;
-            rc = RTDirOpen(&hDir, pszDropDir);
+            rc = RTDirOpen(&hDir, szCacheDir);
             if (RT_SUCCESS(rc))
             {
                 this->m_hDir       = hDir;
-                this->m_strPathAbs = pszDropDir;
+                this->m_strPathAbs = szCacheDir;
                 this->m_fOpen      = fFlags;
+                this->m_uID        = uID;
             }
         }
-
-    } while (0);
+    }
 
     LogFlowFuncLeaveRC(rc);
@@ -235,5 +243,6 @@
 }
 
-int SharedClipboardCache::OpenTemp(SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
+int SharedClipboardCache::OpenTemp(SHAREDCLIPBOARDAREAID uID,
+                                   SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */)
 {
     AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */
@@ -247,5 +256,5 @@
     int rc = RTPathTemp(szTemp, sizeof(szTemp));
     if (RT_SUCCESS(rc))
-        rc = OpenEx(szTemp, fFlags);
+        rc = OpenEx(szTemp, uID, fFlags);
 
     return rc;
Index: trunk/src/VBox/GuestHost/SharedClipboard/ClipboardMetaData.cpp
===================================================================
--- trunk/src/VBox/GuestHost/SharedClipboard/ClipboardMetaData.cpp	(revision 78651)
+++ trunk/src/VBox/GuestHost/SharedClipboard/ClipboardMetaData.cpp	(revision 78683)
@@ -23,4 +23,10 @@
 #include <VBox/GuestHost/SharedClipboard-uri.h>
 
+/**
+ * Initializes a clipboard meta data struct.
+ *
+ * @returns VBox status code.
+ * @param   pMeta               Meta data struct to initialize.
+ */
 int SharedClipboardMetaDataInit(PSHAREDCLIPBOARDMETADATA pMeta)
 {
@@ -36,4 +42,9 @@
 }
 
+/**
+ * Destroys a clipboard meta data struct by free'ing all its data.
+ *
+ * @param   pMeta               Meta data struct to destroy.
+ */
 void SharedClipboardMetaDataDestroy(PSHAREDCLIPBOARDMETADATA pMeta)
 {
@@ -54,4 +65,10 @@
 }
 
+/**
+ * Adds new meta data to a meta data struct.
+ *
+ * @returns VBox status code.
+ * @param   pMeta               Meta data struct to add data to.
+ */
 int SharedClipboardMetaDataAdd(PSHAREDCLIPBOARDMETADATA pMeta, const void *pvDataAdd, uint32_t cbDataAdd)
 {
@@ -74,4 +91,12 @@
 }
 
+/**
+ * Resizes the data buffer of a meta data struct.
+ * Note: At the moment only supports growing the data buffer.
+ *
+ * @returns VBox status code.
+ * @param   pMeta               Meta data struct to resize.
+ * @param   cbNewSize           New size (in bytes) to use for resizing.
+ */
 int SharedClipboardMetaDataResize(PSHAREDCLIPBOARDMETADATA pMeta, size_t cbNewSize)
 {
@@ -86,4 +111,7 @@
     if (cbNewSize == pMeta->cbMeta)
         return VINF_SUCCESS;
+
+    if (cbNewSize > _32M) /* Meta data can be up to 32MB. */
+        return VERR_INVALID_PARAMETER;
 
     void *pvTmp = NULL;
@@ -110,4 +138,10 @@
 }
 
+/**
+ * Returns the actual used bytes of a meta data struct.
+ *
+ * @returns Actual used bytes of a meta data struct.
+ * @param   pMeta               Meta data struct to return used bytes for.
+ */
 size_t SharedClipboardMetaDataGetUsed(PSHAREDCLIPBOARDMETADATA pMeta)
 {
@@ -116,4 +150,10 @@
 }
 
+/**
+ * Returns the overall (allocated) size in bytes of a meta data struct.
+ *
+ * @returns Overall (allocated) size of a meta data struct.
+ * @param   pMeta               Meta data struct to return size for.
+ */
 size_t SharedClipboardMetaDataGetSize(PSHAREDCLIPBOARDMETADATA pMeta)
 {
@@ -122,4 +162,21 @@
 }
 
+/**
+ * Returns the a mutable raw pointer to the actual meta data.
+ *
+ * @returns Mutable raw pointer to the actual meta data.
+ * @param   pMeta               Meta data struct to return mutable data pointer for.
+ */
+void *SharedClipboardMetaDataMutableRaw(PSHAREDCLIPBOARDMETADATA pMeta)
+{
+    return pMeta->pvMeta;
+}
+
+/**
+ * Returns the a const'ed raw pointer to the actual meta data.
+ *
+ * @returns Const'ed raw pointer to the actual meta data.
+ * @param   pMeta               Meta data struct to return const'ed data pointer for.
+ */
 const void *SharedClipboardMetaDataRaw(PSHAREDCLIPBOARDMETADATA pMeta)
 {
