Changeset 10814 in vbox for trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp
- Timestamp:
- Jul 22, 2008 1:50:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp
r10797 r10814 91 91 * @param pszFlags The flags for the property 92 92 */ 93 VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, c har *pszName, char *pszValue,char *pszFlags)93 VBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, const char *pszName, const char *pszValue, const char *pszFlags) 94 94 { 95 95 int rc; … … 103 103 Msg.hdr.u32Function = SET_PROP_VALUE; 104 104 Msg.hdr.cParms = 2; 105 VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);106 VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1);107 VbglHGCMParmPtrSet(&Msg.flags, pszFlags, strlen(pszFlags) + 1);105 VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 106 VbglHGCMParmPtrSet(&Msg.value, const_cast<char *>(pszValue), strlen(pszValue) + 1); 107 VbglHGCMParmPtrSet(&Msg.flags, const_cast<char *>(pszFlags), strlen(pszFlags) + 1); 108 108 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 109 109 if (RT_SUCCESS(rc)) … … 118 118 Msg.hdr.u32Function = DEL_PROP; 119 119 Msg.hdr.cParms = 1; 120 VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);120 VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 121 121 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 122 122 if (RT_SUCCESS(rc)) … … 138 138 * property's flags field will be left unchanged 139 139 */ 140 VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, c har *pszName,char *pszValue)140 VBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, const char *pszName, const char *pszValue) 141 141 { 142 142 int rc; … … 150 150 Msg.hdr.u32Function = SET_PROP_VALUE; 151 151 Msg.hdr.cParms = 2; 152 VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);153 VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1);152 VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 153 VbglHGCMParmPtrSet(&Msg.value, const_cast<char *>(pszValue), strlen(pszValue) + 1); 154 154 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 155 155 if (RT_SUCCESS(rc)) … … 164 164 Msg.hdr.u32Function = DEL_PROP; 165 165 Msg.hdr.cParms = 1; 166 VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);166 VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1); 167 167 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg)); 168 168 if (RT_SUCCESS(rc)) … … 228 228 if (RT_SUCCESS(rc) && (ppszFlags != NULL)) 229 229 { 230 bool found = false; 231 size_t i = 0; 232 char *pcBuf = reinterpret_cast<char *>(pvBuf); 233 for (; i < cbBuf && !found; ++i) 234 if (0 == pcBuf[i]) 235 found = true; 236 if (!found) 237 /* To my mind this is an internal error, but whatever */ 230 char *pszEos = reinterpret_cast<char *>(memchr(pvBuf, '\0', cbBuf)); 231 if (pszEos) 232 *ppszFlags = pszEos + 1; 233 else 238 234 rc = VERR_TOO_MUCH_DATA; 239 else240 *ppszFlags = pcBuf + i;241 235 } 242 236 return rc; … … 248 242 * 249 243 * @returns VBox status code. 250 * @retval VINF_SUCCESS on success, pszValue containing valid data. 251 * @retval VERR_NOT_FOUND if the key wasn't found. 244 * @retval VINF_SUCCESS on success, *ppszValue containing valid data. 245 * @retval VERR_NOT_FOUND if the key wasn't found and *ppszValue set to NULL. 246 * @retval VERR_TOO_MUCH_DATA if we were unable to determine the right size 247 * to allocate for the buffer. This can happen as the result of a 248 * race between our allocating space and the host changing the 249 * property value. 252 250 * 253 251 * @param u32ClientId The client id returned by VbglR3ClipboardConnect(). … … 263 261 void *pvBuf = RTMemAlloc(cchBuf); 264 262 char *pszValue = NULL; 263 *ppszValue = NULL; 265 264 if (NULL == pvBuf) 266 265 rc = VERR_NO_MEMORY; 267 266 if (RT_SUCCESS(rc)) 268 267 { 269 rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 270 &pszValue, NULL, NULL, &cchBuf); 268 /* There is a race here between our reading the property size and the 269 * host changing the value before we read it. Try up to ten times and 270 * report the problem if that fails. */ 271 bool finish = false; 272 for (unsigned i = 0; (i < 10) && !finish; ++i) 273 { 274 rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 275 &pszValue, NULL, NULL, &cchBuf); 276 if (VERR_BUFFER_OVERFLOW == rc) 277 { 278 pvBuf = RTMemRealloc(pvBuf, cchBuf); 279 if (NULL == pvBuf) 280 rc = VERR_NO_MEMORY; 281 } 282 if (rc != VERR_BUFFER_OVERFLOW) 283 finish = true; 284 } 271 285 if (VERR_BUFFER_OVERFLOW == rc) 272 { 273 /** @todo how should we handle the race condition here? */ 274 pvBuf = RTMemRealloc(pvBuf, cchBuf); 275 if (pvBuf != NULL) 276 rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 277 &pszValue, NULL, NULL, NULL); 278 else 279 rc = VERR_NO_MEMORY; 280 if (VERR_BUFFER_OVERFLOW == rc) 281 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 282 * return code */ 283 rc = VERR_TOO_MUCH_DATA; 284 } 286 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 287 * return code, but we need to report the race. */ 288 rc = VERR_TOO_MUCH_DATA; 285 289 } 286 290 if (RT_SUCCESS(rc))
Note:
See TracChangeset
for help on using the changeset viewer.