Changeset 10956 in vbox for trunk/src/VBox/Additions/common/VBoxGuestLib
- Timestamp:
- Jul 29, 2008 8:21:12 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33826
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp
r10930 r10956 28 28 #include <iprt/mem.h> 29 29 #include <iprt/assert.h> 30 #include <iprt/autores> 30 #if 0 /** @todo this isn't work. As noted elsewhere, avoid complicated templates. */ 31 # include <iprt/autores> 32 #endif 31 33 #include <iprt/stdarg.h> 32 34 #include <VBox/log.h> … … 35 37 #include "VBGLR3Internal.h" 36 38 39 37 40 /******************************************************************************* 38 41 * Structures and Typedefs * 39 42 *******************************************************************************/ 40 /** 43 /** 41 44 * Structure containing information needed to enumerate through guest 42 45 * properties. … … 44 47 struct VBGLR3GUESTPROPENUM 45 48 { 49 /** @todo add a magic and validate the handle. */ 46 50 /** The buffer containing the raw enumeration data */ 47 51 char *pchBuf; … … 340 344 * report the problem if that fails. 341 345 */ 342 uint32_t cchBuf = MAX_VALUE_LEN; 343 RTMemAutoPtr<char> pcBuf; 344 int rc = VERR_BUFFER_OVERFLOW; 346 char *pszValue = NULL; 347 void *pvBuf = NULL; 348 uint32_t cchBuf = MAX_VALUE_LEN; 349 int rc = VERR_BUFFER_OVERFLOW; 345 350 for (unsigned i = 0; i < 10 && rc == VERR_BUFFER_OVERFLOW; ++i) 346 351 { 347 352 /* We leave a bit of space here in case the maximum value is raised. */ 348 353 cchBuf += 1024; 349 if (!pcBuf.realloc<RTMemRealloc>(cchBuf)) 350 rc = VERR_NO_MEMORY; 351 if (RT_SUCCESS(rc)) 352 rc = VbglR3GuestPropRead(u32ClientId, pszName, pcBuf.get(), cchBuf, 353 NULL, NULL, NULL, &cchBuf); 354 void *pvTmpBuf = RTMemRealloc(pvBuf, cchBuf); 355 if (pvTmpBuf) 356 { 357 pvBuf = pvTmpBuf; 358 rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 359 &pszValue, NULL, NULL, &cchBuf); 360 } 354 361 else 355 362 rc = VERR_NO_MEMORY; 356 363 } 357 364 if (RT_SUCCESS(rc)) 358 *ppszValue = pcBuf.release(); 359 else if (rc == VERR_BUFFER_OVERFLOW) 360 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 361 * return code, but we need to report the race. */ 362 rc = VERR_TOO_MUCH_DATA; 363 364 return rc; 365 } 365 { 366 Assert(pszValue == (char *)pvBuf); 367 *ppszValue = pszValue; 368 } 369 else 370 { 371 RTMemFree(pvBuf); 372 if (rc == VERR_BUFFER_OVERFLOW) 373 /* VERR_BUFFER_OVERFLOW has a different meaning here as a 374 * return code, but we need to report the race. */ 375 rc = VERR_TOO_MUCH_DATA; 376 } 377 378 return rc; 379 } 380 366 381 367 382 /** … … 421 436 /** 422 437 * Raw API for enumerating guest properties which match a given pattern. 423 * 438 * 424 439 * @returns VINF_SUCCESS on success and pcBuf points to a packed array 425 440 * of the form <name>, <value>, <timestamp string>, <flags>, … … 480 495 * Start enumerating guest properties which match a given pattern. 481 496 * This function creates a handle which can be used to continue enumerating. 482 * @returns VINF_SUCCESS on success, ppHandle points to a handle for continuing 483 * the enumeration and ppszName, ppszValue, pu64Timestamp and 484 * ppszFlags are set. 485 * @returns VERR_NOT_FOUND if no matching properties were found. In this case 497 * 498 * @returns VBox status code. 499 * @retval VINF_SUCCESS on success, *ppHandle points to a handle for continuing 500 * the enumeration and *ppszName, *ppszValue, *pu64Timestamp and 501 * *ppszFlags are set. 502 * @retval VERR_NOT_FOUND if no matching properties were found. In this case 486 503 * the return parameters are not initialised. 487 * @ret urnsVERR_TOO_MUCH_DATA if it was not possible to determine the amount504 * @retval VERR_TOO_MUCH_DATA if it was not possible to determine the amount 488 505 * of local space needed to store all the enumeration data. This is 489 506 * due to a race between allocating space and the host adding new 490 507 * data, so retrying may help here. Other parameters are left 491 508 * uninitialised 492 * @returns IPRT status value otherwise. Other parameters are left 493 * uninitialised. 494 * @param ppaszPatterns the patterns against which the properties are 509 * 510 * @param papszPatterns The patterns against which the properties are 495 511 * matched. Pass NULL if everything should be matched. 496 * @param cPatterns the number of patterns in @a ppaszPatterns. 0 means512 * @param cPatterns The number of patterns in @a papszPatterns. 0 means 497 513 * match everything. 498 514 * @param ppHandle where the handle for continued enumeration is stored … … 508 524 */ 509 525 VBGLR3DECL(int) VbglR3GuestPropEnum(uint32_t u32ClientId, 510 char **p paszPatterns,526 char **papszPatterns, 511 527 int cPatterns, 512 528 PVBGLR3GUESTPROPENUM *ppHandle, … … 516 532 char **ppszFlags) 517 533 { 534 #if 1 /* the RTMemAutoPtr doesn't compile */ 535 return VERR_NOT_IMPLEMENTED; 536 #else 518 537 int rc = VINF_SUCCESS; 519 538 RTMemAutoPtr<VBGLR3GUESTPROPENUM, VbglR3GuestPropEnumFree> pHandle; … … 527 546 uint32_t cchPatterns = 1; 528 547 for (int i = 0; i < cPatterns; ++i) 529 cchPatterns += strlen(p paszPatterns[i]) + 1;548 cchPatterns += strlen(papszPatterns[i]) + 1; 530 549 /* Pack the pattern array */ 531 550 RTMemAutoPtr<char> pPatterns; 532 551 pPatterns = reinterpret_cast<char *>(RTMemAlloc(cchPatterns)); 533 char *p PatternsRaw = pPatterns.get();552 char *pchPatternsRaw = pPatterns.get(); 534 553 for (int i = 0; i < cPatterns; ++i) 535 pPatternsRaw = strcpy(pPatternsRaw, ppaszPatterns[i]) + strlen(ppaszPatterns[i]) + 1; 536 *pPatternsRaw = 0; 554 { 555 size_t cb = strlen(papszPatterns[i]) + 1; 556 memcpy(pchPatternsRaw, papszPatterns[i], cb); 557 pchPatternsRaw += cb; 558 } 559 *pchPatternsRaw = '\0'; 537 560 538 561 /* Randomly chosen initial size for the buffer to hold the enumeration … … 574 597 *ppHandle = pHandle.release(); 575 598 return rc; 599 #endif 576 600 } 577 601 … … 579 603 /** 580 604 * Get the next guest property. See @a VbglR3GuestPropEnum. 581 * @param pHandle handle obtained from @a VbglR3GuestPropEnum. 582 * @param ppszName where to store the next property name. This will be 605 * 606 * @returns VBox status code. 607 * 608 * @param pHandle Handle obtained from @a VbglR3GuestPropEnum. 609 * @param ppszName Where to store the next property name. This will be 583 610 * set to NULL if there are no more properties to 584 611 * enumerate. This pointer should not be freed. 585 * @param ppszValue where to store the next property value. This will be612 * @param ppszValue Where to store the next property value. This will be 586 613 * set to NULL if there are no more properties to 587 614 * enumerate. This pointer should not be freed. 588 * @param pu64Timestamp where to store the next property timestamp. This615 * @param pu64Timestamp Where to store the next property timestamp. This 589 616 * will be set to zero if there are no more properties 590 617 * to enumerate. 591 * @param ppszFlags where to store the next property flags. This will be618 * @param ppszFlags Where to store the next property flags. This will be 592 619 * set to NULL if there are no more properties to 593 620 * enumerate. This pointer should not be freed. … … 601 628 uint32_t iBuf = pHandle->iBuf; 602 629 char *pszName = pHandle->pchBuf + iBuf; 603 /** @todo replace these with safe strlen's and return an error if needed. */630 /** @todo replace these with safe memchr's and return an error if needed. */ 604 631 iBuf += strlen(pszName) + 1; 605 632 char *pszValue = pHandle->pchBuf + iBuf;
Note:
See TracChangeset
for help on using the changeset viewer.