vbox的更動 13574 路徑 trunk/include/VBox
- 時間撮記:
- 2008-10-27 下午12:13:56 (16 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/include/VBox/HostServices/GuestPropertySvc.h
r13558 r13574 65 65 enum ePropFlags 66 66 { 67 NILFLAG = 0, 68 TRANSIENT = RT_BIT(1), 69 HOSTWRITE = RT_BIT(2), 70 GUESTWRITE = RT_BIT(3), 71 READONLY = RT_BIT(4) 67 NILFLAG = 0, 68 TRANSIENT = RT_BIT(1), 69 RDONLYGUEST = RT_BIT(2), 70 RDONLYHOST = RT_BIT(3), 71 READONLY = RDONLYGUEST | RDONLYHOST, 72 ALLFLAGS = TRANSIENT | READONLY 72 73 }; 73 74 74 75 /** 75 * A structure to map the guest property flag values to names. I know it is 76 * ugly to have constants inline, but it has to be accessible in different 77 * modules and it does not seem reasonable to put it into its own library. 78 */ 79 const struct 80 { 81 /** The flag value */ 82 uint32_t fFlag; 83 /** And the name of the flag */ 84 const char *pcszName; 85 } flagNames[] = 86 { 87 { TRANSIENT, "TRANSIENT" }, 88 { HOSTWRITE, "HOSTWRITE" }, 89 { GUESTWRITE, "GUESTWRITE" }, 90 { READONLY, "READONLY" }, 91 { NILFLAG, NULL } 92 }; 93 94 /** Maximum length for the property flags field */ 95 enum { MAX_FLAGS_LEN = sizeof(flagNames[0]) + 2 /* + 2 for ", " */ 96 + sizeof(flagNames[1]) + 2 97 + sizeof(flagNames[2]) + 2 98 + sizeof(flagNames[3]) + 1 /* + 1 for '\0' */ 99 }; 100 101 /** 102 * Parse a guest properties flags string for the flags in flagNames. 76 * Get the name of a flag as a string. 77 * @returns the name, or NULL if fFlag is invalid. 78 * @param fFlag the flag. Must be a value from the ePropFlags enumeration 79 * list. 80 */ 81 DECLINLINE(const char *) flagName(uint32_t fFlag) 82 { 83 switch(fFlag) 84 { 85 case TRANSIENT: 86 return "TRANSIENT"; 87 case RDONLYGUEST: 88 return "RDONLYGUEST"; 89 case RDONLYHOST: 90 return "RDONLYHOST"; 91 case READONLY: 92 return "READONLY"; 93 default: 94 return NULL; 95 } 96 } 97 98 /** 99 * Get the length of a flag name as returned by flagName. 100 * @returns the length, or 0 if fFlag is invalid. 101 * @param fFlag the flag. Must be a value from the ePropFlags enumeration 102 * list. 103 */ 104 DECLINLINE(size_t) flagNameLen(uint32_t fFlag) 105 { 106 const char *pcszName = flagName(fFlag); 107 return RT_LIKELY(pcszName != NULL) ? strlen(pcszName) : 0; 108 } 109 110 /** 111 * Maximum length for the property flags field. We only ever return one of 112 * RDONLYGUEST, RDONLYHOST and RDONLY 113 */ 114 enum { MAX_FLAGS_LEN = sizeof("TRANSIENT, RDONLYGUEST") }; 115 116 /** 117 * Parse a guest properties flags string for flag names and make sure that 118 * there is no junk text in the string. 103 119 * @returns IPRT status code 104 120 * @returns VERR_INVALID_PARAM if the flag string is not valid … … 111 127 DECLINLINE(int) validateFlags(const char *pcszFlags, uint32_t *pfFlags) 112 128 { 129 static uint32_t flagList[] = 130 { 131 TRANSIENT, READONLY, RDONLYGUEST, RDONLYHOST 132 }; 113 133 const char *pcszNext = pcszFlags; 114 134 int rc = VINF_SUCCESS; … … 120 140 while ((*pcszNext != '\0') && RT_SUCCESS(rc)) 121 141 { 122 int i = 0; 123 for (; flagNames[i].fFlag != NILFLAG; ++i) 124 if (strncasecmp(pcszNext, flagNames[i].pcszName, 125 strlen(flagNames[i].pcszName)) == 0) 142 unsigned i = 0; 143 for (; i < RT_ELEMENTS(flagList); ++i) 144 if (strncasecmp(pcszNext, flagName(flagList[i]), 145 flagNameLen(flagList[i]) 146 ) == 0 147 ) 126 148 break; 127 if ( NILFLAG == flagNames[i].fFlag)128 rc = VERR_INVALID_PARAMETER;149 if (RT_ELEMENTS(flagList) == i) 150 rc = VERR_INVALID_PARAMETER; 129 151 else 130 152 { 131 fFlags |= flagNames[i].fFlag; 132 pcszNext += strlen(flagNames[i].pcszName); 153 fFlags |= flagList[i]; 154 pcszNext += flagNameLen(flagList[i]); 155 while (' ' == *pcszNext) 156 ++pcszNext; 157 if (',' == *pcszNext) 158 ++pcszNext; 159 while (' ' == *pcszNext) 160 ++pcszNext; 133 161 } 134 while (' ' == *pcszNext)135 ++pcszNext;136 if (',' == *pcszNext)137 ++pcszNext;138 while (' ' == *pcszNext)139 ++pcszNext;140 162 } 141 163 if (RT_SUCCESS(rc)) … … 149 171 * @param fFlags the flags to write out 150 172 * @param pszFlags where to write the flags string. This must point to 151 * a buffer of size (at least) MAX_FLAGS_LEN + 1.173 * a buffer of size (at least) MAX_FLAGS_LEN. 152 174 */ 153 175 DECLINLINE(int) writeFlags(uint32_t fFlags, char *pszFlags) 154 176 { 177 static uint32_t flagList[] = 178 { 179 TRANSIENT, READONLY, RDONLYGUEST, RDONLYHOST 180 }; 155 181 char *pszNext = pszFlags; 156 182 int rc = VINF_SUCCESS; 157 183 AssertLogRelReturn(VALID_PTR(pszFlags), VERR_INVALID_POINTER); 158 int i = 0; 159 for (; flagNames[i].fFlag != NILFLAG; ++i) 184 if ((fFlags & ~ALLFLAGS) != NILFLAG) 185 rc = VERR_INVALID_PARAMETER; 186 if (RT_SUCCESS(rc)) 160 187 { 161 if (fFlags & flagNames[i].fFlag) 188 unsigned i = 0; 189 for (; i < RT_ELEMENTS(flagList); ++i) 162 190 { 163 strcpy(pszNext, flagNames[i].pcszName); 164 pszNext += strlen(flagNames[i].pcszName); 165 fFlags &= ~flagNames[i].fFlag; 166 if ((flagNames[i + 1].fFlag != NILFLAG) && (fFlags != NILFLAG)) 191 if (fFlags & flagList[i]) 167 192 { 168 strcpy(pszNext, ", "); 169 pszNext += 2; 193 strcpy(pszNext, flagName(flagList[i])); 194 pszNext += flagNameLen(flagList[i]); 195 fFlags &= ~flagList[i]; 196 if (fFlags != NILFLAG) 197 { 198 strcpy(pszNext, ", "); 199 pszNext += 2; 200 } 170 201 } 171 202 } 203 *pszNext = '\0'; 204 if (fFlags != NILFLAG) 205 rc = VERR_INVALID_PARAMETER; /* But pszFlags will still be set right. */ 172 206 } 173 *pszNext = '\0';174 if (fFlags != NILFLAG)175 rc = VERR_INVALID_PARAMETER; /* But pszFlags will still be set right. */176 207 return rc; 177 208 }
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器