Changeset 70222 in vbox for trunk/include/VBox
- Timestamp:
- Dec 19, 2017 2:01:21 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/HostServices/GuestPropertySvc.h
r70221 r70222 65 65 * Get the name of a flag as a string. 66 66 * @returns the name, or NULL if fFlag is invalid. 67 * @param fFlag the flag. Must be a value from the ePropFlags enumeration68 * list.69 */ 70 DECLINLINE(const char *) GuestPropFlagName (uint32_t fFlag)67 * @param fFlag The flag, GUEST_PROP_F_XXX. 68 * @param pcchName Where to return the name length. 69 */ 70 DECLINLINE(const char *) GuestPropFlagNameAndLen(uint32_t fFlag, size_t *pcchName) 71 71 { 72 72 switch (fFlag) 73 73 { 74 74 case GUEST_PROP_F_TRANSIENT: 75 *pcchName = sizeof("TRANSIENT") - 1; 75 76 return "TRANSIENT"; 76 77 case GUEST_PROP_F_RDONLYGUEST: 78 *pcchName = sizeof("RDONLYGUEST") - 1; 77 79 return "RDONLYGUEST"; 78 80 case GUEST_PROP_F_RDONLYHOST: 81 *pcchName = sizeof("RDONLYHOST") - 1; 79 82 return "RDONLYHOST"; 80 83 case GUEST_PROP_F_READONLY: 84 *pcchName = sizeof("READONLY") - 1; 81 85 return "READONLY"; 82 86 case GUEST_PROP_F_TRANSRESET: 87 *pcchName = sizeof("TRANSRESET") - 1; 83 88 return "TRANSRESET"; 84 89 default: 85 break; 90 *pcchName = 0; 91 return NULL; 86 92 } 87 return NULL;88 }89 90 /**91 * Get the length of a flag name as returned by flagName.92 * @returns the length, or 0 if fFlag is invalid.93 * @param fFlag the flag. Must be a value from the ePropFlags enumeration94 * list.95 */96 DECLINLINE(size_t) GuestPropFlagNameLen(uint32_t fFlag)97 {98 const char *pcszName = GuestPropFlagName(fFlag);99 return RT_LIKELY(pcszName != NULL) ? strlen(pcszName) : 0;100 93 } 101 94 … … 131 124 if (pcszFlags) 132 125 { 133 while ( ' ' == *pcszNext)126 while (*pcszNext == ' ') 134 127 ++pcszNext; 135 128 while ((*pcszNext != '\0') && RT_SUCCESS(rc)) 136 129 { 137 unsigned i = 0; 138 for (; i < RT_ELEMENTS(s_aFlagList); ++i) 139 if (RTStrNICmp(pcszNext, GuestPropFlagName(s_aFlagList[i]), GuestPropFlagNameLen(s_aFlagList[i])) == 0) 130 unsigned i; 131 rc = VERR_PARSE_ERROR; 132 for (i = 0; i < RT_ELEMENTS(s_aFlagList); ++i) 133 { 134 size_t cchFlagName; 135 const char *pszFlagName = GuestPropFlagNameAndLen(s_aFlagList[i], &cchFlagName); 136 if (RTStrNICmp(pcszNext, pszFlagName, cchFlagName) == 0) 137 { 138 char ch; 139 fFlags |= s_aFlagList[i]; 140 pcszNext += cchFlagName; 141 while ((ch = *pcszNext) == ' ') 142 ++pcszNext; 143 rc = VINF_SUCCESS; 144 if (ch == ',') 145 { 146 ++pcszNext; 147 while (*pcszNext == ' ') 148 ++pcszNext; 149 } 150 else if (ch != '\0') 151 rc = VERR_PARSE_ERROR; 140 152 break; 141 if (RT_ELEMENTS(s_aFlagList) == i) 142 rc = VERR_PARSE_ERROR; 143 else 144 { 145 fFlags |= s_aFlagList[i]; 146 pcszNext += GuestPropFlagNameLen(s_aFlagList[i]); 147 while (' ' == *pcszNext) 148 ++pcszNext; 149 if (',' == *pcszNext) 150 ++pcszNext; 151 else if (*pcszNext != '\0') 152 rc = VERR_PARSE_ERROR; 153 while (' ' == *pcszNext) 154 ++pcszNext; 153 } 155 154 } 156 155 } … … 167 166 * @param fFlags the flags to write out 168 167 * @param pszFlags where to write the flags string. This must point to 169 * a buffer of size (at least) MAX_FLAGS_LEN.168 * a buffer of size (at least) GUEST_PROP_MAX_FLAGS_LEN. 170 169 */ 171 170 DECLINLINE(int) GuestPropWriteFlags(uint32_t fFlags, char *pszFlags) … … 194 193 if (s_aFlagList[i] == (fFlags & s_aFlagList[i])) 195 194 { 196 strcpy(pszNext, GuestPropFlagName(s_aFlagList[i])); 197 pszNext += GuestPropFlagNameLen(s_aFlagList[i]); 195 size_t cchFlagName; 196 const char *pszFlagName = GuestPropFlagNameAndLen(s_aFlagList[i], &cchFlagName); 197 memcpy(pszNext, pszFlagName, cchFlagName); 198 pszNext += cchFlagName; 198 199 fFlags &= ~s_aFlagList[i]; 199 200 if (fFlags != GUEST_PROP_F_NILFLAG) 200 201 { 201 strcpy(pszNext, ", ");202 pszNext += 2;202 *pszNext++ = ','; 203 *pszNext++ = ' '; 203 204 } 204 205 } … … 206 207 *pszNext = '\0'; 207 208 209 Assert((uintptr_t)(pszNext - pszFlags) < GUEST_PROP_MAX_FLAGS_LEN); 208 210 Assert(fFlags == GUEST_PROP_F_NILFLAG); /* bad s_aFlagList */ 209 211 } … … 353 355 * The property flags (IN pointer) 354 356 * This is a comma-separated list of the format flag=value 355 * The length must be less than or equal to MAX_FLAGS_LEN and only357 * The length must be less than or equal to GUEST_PROP_MAX_FLAGS_LEN and only 356 358 * known flag names and values will be accepted. 357 359 */
Note:
See TracChangeset
for help on using the changeset viewer.