Changeset 12812 in vbox for trunk/src/VBox/Additions/common
- Timestamp:
- Sep 29, 2008 4:27:32 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 37166
- Location:
- trunk/src/VBox/Additions/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp
r12719 r12812 1044 1044 static int enumGuestProperty(int argc, char *argv[]) 1045 1045 { 1046 /* 1047 * Check the syntax. We can deduce the correct syntax from the number of 1048 * arguments. 1049 */ 1050 const char *paszPatterns = NULL; 1051 if ((argc > 1) && (0 == strcmp(argv[0], "-patterns"))) 1052 paszPatterns = argv[1]; 1046 /* 1047 * Check the syntax. We can deduce the correct syntax from the number of 1048 * arguments. 1049 */ 1050 char const * const *papszPatterns = NULL; 1051 size_t cPatterns = 0; 1052 if ( argc > 1 1053 && !strcmp(argv[0], "-patterns")) 1054 { 1055 papszPatterns = (char const * const *)&argv[1]; 1056 cPatterns = argc - 1; 1057 } 1053 1058 else if (argc != 0) 1054 1059 { … … 1057 1062 } 1058 1063 1059 /*1060 * Do the actual enumeration.1061 */1064 /* 1065 * Do the actual enumeration. 1066 */ 1062 1067 uint32_t u32ClientId = 0; 1063 PVBGLR3GUESTPROPENUM pHandle = NULL; 1064 RTMemAutoPtr<VBGLR3GUESTPROPENUM, VbglR3GuestPropEnumFree> Handle; 1065 char *pszName = NULL, *pszValue = NULL, *pszFlags = NULL; 1066 uint64_t u64Timestamp = 0; 1067 int rc = VINF_SUCCESS; 1068 rc = VbglR3GuestPropConnect(&u32ClientId); 1069 if (!RT_SUCCESS(rc)) 1070 VBoxControlError("Failed to connect to the guest property service! Error: %Rrc\n", rc); 1068 int rc = VbglR3GuestPropConnect(&u32ClientId); 1071 1069 if (RT_SUCCESS(rc)) 1072 1070 { 1073 char **ppaszPatterns = argc > 1 ? argv + 1 : NULL; 1074 int cPatterns = argc > 1 ? argc - 1 : 0; 1075 rc = VbglR3GuestPropEnum(u32ClientId, ppaszPatterns, cPatterns, &pHandle, 1071 PVBGLR3GUESTPROPENUM pHandle; 1072 const char *pszName, *pszValue, *pszFlags; 1073 uint64_t u64Timestamp; 1074 1075 rc = VbglR3GuestPropEnum(u32ClientId, papszPatterns, cPatterns, &pHandle, 1076 1076 &pszName, &pszValue, &u64Timestamp, &pszFlags); 1077 1077 if (RT_SUCCESS(rc)) 1078 1078 { 1079 Handle = pHandle; 1079 while (RT_SUCCESS(rc) && !pszName) 1080 { 1081 RTPrintf("Name: %s, value: %s, timestamp: %lld, flags: %s\n", 1082 pszName, pszValue, u64Timestamp, pszFlags); 1083 1084 rc = VbglR3GuestPropEnumNext(pHandle, &pszName, &pszValue, &u64Timestamp, &pszFlags); 1085 if (RT_FAILURE(rc)) 1086 VBoxControlError("Error while enumerating guest properties: %Rrc\n", rc); 1087 } 1088 1089 VbglR3GuestPropEnumFree(pHandle); 1080 1090 } 1081 1091 else if (VERR_NOT_FOUND == rc) … … 1083 1093 else 1084 1094 VBoxControlError("Failed to enumerate the guest properties! Error: %Rrc\n", rc); 1085 }1086 while (RT_SUCCESS(rc) && (pszName != NULL))1087 {1088 RTPrintf("Name: %s, value: %s, timestamp: %lld, flags: %s\n",1089 pszName, pszValue, u64Timestamp, pszFlags);1090 rc = VbglR3GuestPropEnumNext(Handle.get(), &pszName, &pszValue, &u64Timestamp, &pszFlags);1091 if (!RT_SUCCESS(rc))1092 VBoxControlError("Error while enumerating guest properties: %Rrc\n", rc);1093 }1094 1095 if (u32ClientId != 0)1096 1095 VbglR3GuestPropDisconnect(u32ClientId); 1096 } 1097 else 1098 VBoxControlError("Failed to connect to the guest property service! Error: %Rrc\n", rc); 1097 1099 return RT_SUCCESS(rc) ? 0 : 1; 1098 1100 } -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp
r12810 r12812 523 523 * @param ppszFlags Where to store the first flags value on success. 524 524 * Should not be freed. 525 *526 * @todo Make papszPatterns char const * const *, and cPatterns size_t (so we527 * can use RT_ELEMENTS without getting warnings on Windows).528 * Most of the returns should also be made char const * to discourage529 * changes and encourage compiler optimizations.530 525 */ 531 526 VBGLR3DECL(int) VbglR3GuestPropEnum(uint32_t u32ClientId, 532 char **papszPatterns,533 int cPatterns,527 char const * const *papszPatterns, 528 size_t cPatterns, 534 529 PVBGLR3GUESTPROPENUM *ppHandle, 535 char **ppszName,536 char **ppszValue,530 char const **ppszName, 531 char const **ppszValue, 537 532 uint64_t *pu64Timestamp, 538 char **ppszFlags)533 char const **ppszFlags) 539 534 { 540 535 int rc = VINF_SUCCESS; 541 536 RTMemAutoPtr<VBGLR3GUESTPROPENUM, VbglR3GuestPropEnumFree> Handle; 542 Handle = (PVBGLR3GUESTPROPENUM) 537 Handle = (PVBGLR3GUESTPROPENUM)RTMemAllocZ(sizeof(VBGLR3GUESTPROPENUM)); 543 538 if (!Handle) 544 539 rc = VERR_NO_MEMORY; … … 546 541 /* Get the length of the pattern string, including the final terminator. */ 547 542 uint32_t cchPatterns = 1; 548 for ( inti = 0; i < cPatterns; ++i)543 for (unsigned i = 0; i < cPatterns; ++i) 549 544 cchPatterns += strlen(papszPatterns[i]) + 1; 545 550 546 /* Pack the pattern array */ 551 547 RTMemAutoPtr<char> Patterns; 552 Patterns = (char *) 548 Patterns = (char *)RTMemAlloc(cchPatterns); 553 549 size_t iOffs = 0; 554 for ( int i = 0; i < cPatterns; ++i)550 for (size_t i = 0; i < cPatterns; ++i) 555 551 { 556 552 size_t cb = strlen(papszPatterns[i]) + 1; … … 619 615 * set to NULL if there are no more properties to 620 616 * enumerate. This pointer should not be freed. 621 *622 * @todo return char const *.623 617 */ 624 618 VBGLR3DECL(int) VbglR3GuestPropEnumNext(PVBGLR3GUESTPROPENUM pHandle, 625 char **ppszName,626 char **ppszValue,619 char const **ppszName, 620 char const **ppszValue, 627 621 uint64_t *pu64Timestamp, 628 char **ppszFlags)622 char const **ppszFlags) 629 623 { 630 624 uint32_t iBuf = pHandle->iBuf; 631 625 char *pszName = pHandle->pchBuf + iBuf; 632 /** @todo replace these with safe memchr's and return an error if needed. */ 626 /** @todo replace these with safe memchr's and return an error if needed. A 627 * PLEASE add a comment about the layout because this is rather 628 * unreadable. */ 633 629 iBuf += strlen(pszName) + 1; 634 630 char *pszValue = pHandle->pchBuf + iBuf; … … 680 676 { 681 677 PVBGLR3GUESTPROPENUM pHandle; 682 char *pszName; 683 char *pszValue; 678 char const *pszName, *pszValue, *pszFlags; 684 679 uint64_t pu64Timestamp; 685 char *pszFlags;686 680 int rc = VbglR3GuestPropEnum(u32ClientId, 687 681 (char **)papszPatterns, /** @todo fix this cast. */
Note:
See TracChangeset
for help on using the changeset viewer.