Changeset 78683 in vbox for trunk/src/VBox/GuestHost/SharedClipboard
- Timestamp:
- May 23, 2019 10:07:21 AM (6 years ago)
- Location:
- trunk/src/VBox/GuestHost/SharedClipboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardCache.cpp
r78618 r78683 37 37 : m_cRefs(0) 38 38 , m_fOpen(0) 39 , m_hDir(NULL) 39 , m_hDir(NIL_RTDIR) 40 , m_uID(NIL_SHAREDCLIPBOARDAREAID) 40 41 { 41 42 int rc = initInternal(); … … 45 46 46 47 SharedClipboardCache::SharedClipboardCache(const char *pszPath, 48 SHAREDCLIPBOARDAREAID uID /* = NIL_SHAREDCLIPBOARDAREAID */, 47 49 SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */) 48 50 : m_cRefs(0) 49 51 , m_fOpen(0) 50 , m_hDir(NULL) 52 , m_hDir(NIL_RTDIR) 53 , m_uID(uID) 51 54 { 52 55 int rc = initInternal(); … … 140 143 { 141 144 int rc; 142 if (this->m_hDir != N ULL)145 if (this->m_hDir != NIL_RTDIR) 143 146 { 144 147 rc = RTDirClose(this->m_hDir); 145 148 if (RT_SUCCESS(rc)) 146 this->m_hDir = N ULL;149 this->m_hDir = NIL_RTDIR; 147 150 } 148 151 else 149 152 rc = VINF_SUCCESS; 150 153 154 this->m_fOpen = SHAREDCLIPBOARDCACHE_FLAGS_NONE; 155 this->m_uID = NIL_SHAREDCLIPBOARDAREAID; 156 151 157 LogFlowFuncLeaveRC(rc); 152 158 return rc; 153 159 } 154 160 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 */ 169 int 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 155 194 int SharedClipboardCache::Close(void) 156 195 { … … 158 197 } 159 198 199 SHAREDCLIPBOARDAREAID SharedClipboardCache::GetAreaID(void) const 200 { 201 return this->m_uID; 202 } 203 160 204 const char *SharedClipboardCache::GetDirAbs(void) const 161 205 { … … 168 212 } 169 213 170 int SharedClipboardCache::OpenEx(const char *pszPath, SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */) 214 int SharedClipboardCache::OpenEx(const char *pszPath, 215 SHAREDCLIPBOARDAREAID uID /* = NIL_SHAREDCLIPBOARDAREAID */, 216 SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */) 171 217 { 172 218 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); 173 219 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */ 174 220 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 { 217 225 /* 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, '-'); 219 227 if (RT_SUCCESS(rc)) 220 228 { 221 229 RTDIR hDir; 222 rc = RTDirOpen(&hDir, pszDropDir);230 rc = RTDirOpen(&hDir, szCacheDir); 223 231 if (RT_SUCCESS(rc)) 224 232 { 225 233 this->m_hDir = hDir; 226 this->m_strPathAbs = pszDropDir;234 this->m_strPathAbs = szCacheDir; 227 235 this->m_fOpen = fFlags; 236 this->m_uID = uID; 228 237 } 229 238 } 230 231 } while (0); 239 } 232 240 233 241 LogFlowFuncLeaveRC(rc); … … 235 243 } 236 244 237 int SharedClipboardCache::OpenTemp(SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */) 245 int SharedClipboardCache::OpenTemp(SHAREDCLIPBOARDAREAID uID, 246 SHAREDCLIPBOARDCACHEFLAGS fFlags /* = SHAREDCLIPBOARDCACHE_FLAGS_NONE */) 238 247 { 239 248 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */ … … 247 256 int rc = RTPathTemp(szTemp, sizeof(szTemp)); 248 257 if (RT_SUCCESS(rc)) 249 rc = OpenEx(szTemp, fFlags);258 rc = OpenEx(szTemp, uID, fFlags); 250 259 251 260 return rc; -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardMetaData.cpp
r78651 r78683 23 23 #include <VBox/GuestHost/SharedClipboard-uri.h> 24 24 25 /** 26 * Initializes a clipboard meta data struct. 27 * 28 * @returns VBox status code. 29 * @param pMeta Meta data struct to initialize. 30 */ 25 31 int SharedClipboardMetaDataInit(PSHAREDCLIPBOARDMETADATA pMeta) 26 32 { … … 36 42 } 37 43 44 /** 45 * Destroys a clipboard meta data struct by free'ing all its data. 46 * 47 * @param pMeta Meta data struct to destroy. 48 */ 38 49 void SharedClipboardMetaDataDestroy(PSHAREDCLIPBOARDMETADATA pMeta) 39 50 { … … 54 65 } 55 66 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 */ 56 73 int SharedClipboardMetaDataAdd(PSHAREDCLIPBOARDMETADATA pMeta, const void *pvDataAdd, uint32_t cbDataAdd) 57 74 { … … 74 91 } 75 92 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 */ 76 101 int SharedClipboardMetaDataResize(PSHAREDCLIPBOARDMETADATA pMeta, size_t cbNewSize) 77 102 { … … 86 111 if (cbNewSize == pMeta->cbMeta) 87 112 return VINF_SUCCESS; 113 114 if (cbNewSize > _32M) /* Meta data can be up to 32MB. */ 115 return VERR_INVALID_PARAMETER; 88 116 89 117 void *pvTmp = NULL; … … 110 138 } 111 139 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 */ 112 146 size_t SharedClipboardMetaDataGetUsed(PSHAREDCLIPBOARDMETADATA pMeta) 113 147 { … … 116 150 } 117 151 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 */ 118 158 size_t SharedClipboardMetaDataGetSize(PSHAREDCLIPBOARDMETADATA pMeta) 119 159 { … … 122 162 } 123 163 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 */ 170 void *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 */ 124 181 const void *SharedClipboardMetaDataRaw(PSHAREDCLIPBOARDMETADATA pMeta) 125 182 {
Note:
See TracChangeset
for help on using the changeset viewer.