Merge pull request #51 from kolbyjack/is_alpha

Group POST refinements, test all request methods, make IS_ALPHA use LOWER
v0.6
Peter Griess 14 years ago
commit 1786fdae36

@ -315,9 +315,9 @@ enum header_states
#define LF '\n' #define LF '\n'
#define LOWER(c) (unsigned char)(c | 0x20) #define LOWER(c) (unsigned char)(c | 0x20)
#define TOKEN(c) (tokens[(unsigned char)c]) #define TOKEN(c) (tokens[(unsigned char)c])
#define IS_ALPHA(c) ((c) >= 'a' && (c) <= 'z') #define IS_ALPHA(c) (LOWER(c) >= 'a' && LOWER(c) <= 'z')
#define IS_NUM(c) ((c) >= '0' && (c) <= '9') #define IS_NUM(c) ((c) >= '0' && (c) <= '9')
#define IS_ALPHANUM(c) (IS_ALPHA(LOWER(c)) || IS_NUM(c)) #define IS_ALPHANUM(c) (IS_ALPHA(c) || IS_NUM(c))
#if HTTP_PARSER_STRICT #if HTTP_PARSER_STRICT
#define IS_URL_CHAR(c) (normal_url_char[(unsigned char) (c)]) #define IS_URL_CHAR(c) (normal_url_char[(unsigned char) (c)])
@ -670,7 +670,7 @@ size_t http_parser_execute (http_parser *parser,
CALLBACK2(message_begin); CALLBACK2(message_begin);
if (!IS_ALPHA(LOWER(ch))) { if (!IS_ALPHA(ch)) {
SET_ERRNO(HPE_INVALID_METHOD); SET_ERRNO(HPE_INVALID_METHOD);
goto error; goto error;
} }
@ -734,12 +734,16 @@ size_t http_parser_execute (http_parser *parser,
} else { } else {
goto error; goto error;
} }
} else if (index == 1 && parser->method == HTTP_POST && ch == 'R') { } else if (index == 1 && parser->method == HTTP_POST) {
parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */ if (ch == 'R') {
} else if (index == 1 && parser->method == HTTP_POST && ch == 'U') { parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */
parser->method = HTTP_PUT; } else if (ch == 'U') {
} else if (index == 1 && parser->method == HTTP_POST && ch == 'A') { parser->method = HTTP_PUT;
parser->method = HTTP_PATCH; } else if (ch == 'A') {
parser->method = HTTP_PATCH;
} else {
goto error;
}
} else if (index == 2 && parser->method == HTTP_UNLOCK && ch == 'S') { } else if (index == 2 && parser->method == HTTP_UNLOCK && ch == 'S') {
parser->method = HTTP_UNSUBSCRIBE; parser->method = HTTP_UNSUBSCRIBE;
} else if (index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') { } else if (index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') {
@ -763,8 +767,6 @@ size_t http_parser_execute (http_parser *parser,
break; break;
} }
c = LOWER(ch);
/* Proxied requests are followed by scheme of an absolute URI (alpha). /* Proxied requests are followed by scheme of an absolute URI (alpha).
* CONNECT is followed by a hostname, which begins with alphanum. * CONNECT is followed by a hostname, which begins with alphanum.
* All other methods are followed by '/' or '*' (handled above). * All other methods are followed by '/' or '*' (handled above).
@ -781,9 +783,7 @@ size_t http_parser_execute (http_parser *parser,
case s_req_schema: case s_req_schema:
{ {
c = LOWER(ch); if (IS_ALPHA(ch)) break;
if (IS_ALPHA(c)) break;
if (ch == ':') { if (ch == ':') {
state = s_req_schema_slash; state = s_req_schema_slash;

@ -749,7 +749,7 @@ const struct message requests[] =
#define CONNECT_CAPS_REQUEST 27 #define CONNECT_CAPS_REQUEST 27
, {.name = "connect caps request" , {.name = "connect caps request"
,.type= HTTP_REQUEST ,.type= HTTP_REQUEST
,.raw= "CONNECT 0-HOME0.NETSCAPE.COM:443 HTTP/1.0\r\n" ,.raw= "CONNECT HOME0.NETSCAPE.COM:443 HTTP/1.0\r\n"
"User-agent: Mozilla/1.1N\r\n" "User-agent: Mozilla/1.1N\r\n"
"Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n" "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
"\r\n" "\r\n"
@ -761,7 +761,7 @@ const struct message requests[] =
,.query_string= "" ,.query_string= ""
,.fragment= "" ,.fragment= ""
,.request_path= "" ,.request_path= ""
,.request_url= "0-HOME0.NETSCAPE.COM:443" ,.request_url= "HOME0.NETSCAPE.COM:443"
,.num_headers= 2 ,.num_headers= 2
,.upgrade="" ,.upgrade=""
,.headers= { { "User-agent", "Mozilla/1.1N" } ,.headers= { { "User-agent", "Mozilla/1.1N" }
@ -2045,6 +2045,15 @@ main (void)
"PROPFIND", "PROPFIND",
"PROPPATCH", "PROPPATCH",
"UNLOCK", "UNLOCK",
"REPORT",
"MKACTIVITY",
"CHECKOUT",
"MERGE",
"M-SEARCH",
"NOTIFY",
"SUBSCRIBE",
"UNSUBSCRIBE",
"PATCH",
0 }; 0 };
const char **this_method; const char **this_method;
for (this_method = all_methods; *this_method; this_method++) { for (this_method = all_methods; *this_method; this_method++) {

Loading…
Cancel
Save