36 #define MAX_FIELD_NAME (32) 37 #define MAX_CONTENT_LENGTH (24) 65 static BOOLEAN GetNextToken(U8BIT **data,
Token *token);
80 U8BIT name[MAX_FIELD_NAME];
82 char *sep =
"()<>@,;:\\\"/[]?={} \t";
84 *field = HTTP_FIELD_UNKNOWN;
86 while ((*data > 32) && (*data < 127) && (strchr(sep, *data) == NULL) &&
87 (nameLen < MAX_FIELD_NAME))
89 if (*data >=
'A' && *data <=
'Z')
92 name[nameLen] = *data -
'A' +
'a';
96 name[nameLen] = *data;
102 if (nameLen <= MAX_FIELD_NAME && *data ==
':')
105 if (nameLen == 14 && memcmp(name,
"content-length", 14) == 0)
107 *field = HTTP_FIELD_CONTENT_LENGTH;
109 else if (nameLen == 13 && memcmp(name,
"content-range", 13) == 0)
111 *field = HTTP_FIELD_CONTENT_RANGE;
113 else if (nameLen == 12 && memcmp(name,
"content-type", 12) == 0)
115 *field = HTTP_FIELD_CONTENT_TYPE;
117 else if (nameLen == 6 && memcmp(name,
"x-keys", 6) == 0)
119 *field = HTTP_FIELD_X_KEYS;
121 else if (nameLen == 13 && memcmp(name,
"x-keylocation", 13) == 0)
123 *field = HTTP_FIELD_X_KEY_LOCATION;
125 else if (nameLen == 16 && memcmp(name,
"x-bytespersecond", 16) == 0)
127 *field = HTTP_FIELD_X_BYTES_PER_SECOND;
131 while (*data ==
'\r' || *data ==
'\n' || *data ==
' ' || *data ==
'\t')
150 char buffer[MAX_CONTENT_LENGTH];
154 ULL_SetInvalid(contentLength);
157 success = GetNextToken(&data, &token);
160 if ((token.type == TOKEN_NUMBER) &&
161 (token.len < MAX_CONTENT_LENGTH))
163 memcpy(buffer, token.data, token.len);
164 buffer[token.len] =
'\0';
168 return contentLength;
180 char buffer[MAX_CONTENT_LENGTH];
187 success = GetNextToken(&data, &token);
188 if (success && token.type == TOKEN_BYTES)
190 success = GetNextToken(&data, &token);
192 if (success && token.type == TOKEN_SPACE)
194 success = GetNextToken(&data, &token);
196 if (success && token.type == TOKEN_NUMBER)
198 success = GetNextToken(&data, &token);
200 if (success && token.type == TOKEN_HYPHEN)
202 success = GetNextToken(&data, &token);
204 if (success && token.type == TOKEN_NUMBER)
206 success = GetNextToken(&data, &token);
208 if (success && token.type == TOKEN_SLASH)
210 success = GetNextToken(&data, &token);
218 (token.type == TOKEN_NUMBER) &&
219 (token.len < MAX_CONTENT_LENGTH))
221 memcpy(buffer, token.data, token.len);
222 buffer[token.len] =
'\0';
227 ULL_SetInvalid(contentLength);
229 return contentLength;
243 static BOOLEAN GetNextToken(U8BIT **data,
Token *token)
251 case '0':
case '1':
case '2':
case '3':
case '4':
252 case '5':
case '6':
case '7':
case '8':
case '9':
253 token->type = TOKEN_NUMBER;
258 while (*p >=
'0' && *p <=
'9');
259 token->len = p - *data;
267 while (*p >=
'a' && *p <=
'z');
268 if (p - *data == 5 && memcmp(*data,
"bytes", 5) == 0)
270 token->type = TOKEN_BYTES;
280 token->type = TOKEN_SPACE;
285 token->type = TOKEN_HYPHEN;
290 token->type = TOKEN_SLASH;
295 token->type = TOKEN_ASTERISK;
U64BIT ULONG_Atoi(char *str)
Convert a string to unsigned 64 bit. Only the numeric part of the string is converted (up to the firs...