--------------------- PatchSet 2851 Date: 2001/08/24 23:37:55 Author: adri Branch: newhttp Tag: (none) Log: Fill out some more of the HTTP request parsing code. It still doesn't work right just yet. Members: src/modules/new_http_client/http_request.c:1.1.2.4->1.1.2.5 Index: squid/src/modules/new_http_client/http_request.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/modules/new_http_client/Attic/http_request.c,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid/src/modules/new_http_client/http_request.c 24 Aug 2001 22:52:32 -0000 1.1.2.4 +++ squid/src/modules/new_http_client/http_request.c 24 Aug 2001 23:37:55 -0000 1.1.2.5 @@ -15,6 +15,15 @@ HTTP_CRLF } http_request_parse_t; +static char reqtypes[] = { "NONE", "METHOD_PREWS", "METHOD", "URL_PREWS", "URL", "VERSION_PREWS", "VERSION", "CRLF" }; + +static void +stmem_ref_pos_print(stmem_ref_pos_t *pos) +{ + debug(1, 1) ("pos: str=%d, node=%x, offset=%d\n", pos->strofs, pos->node, pos->nodeofs); +} + + /* * Set the string offset to the given offset * @@ -136,7 +145,9 @@ stmem_ref_pos_t url_start, url_end; /* URL */ stmem_ref_pos_t version_start, version_end; /* Version */ int gotcrlf = 0; + int breakloop = 0; http_request_parse_t mode = HTTP_METHOD_PREWS; + http_request_parse_t oldmode; char ch; /* @@ -153,37 +164,94 @@ * buffer */ - while (1) { + while (breakloop == 0) { + oldmode = mode; ch = stmem_ref_pos_getchar(&stpos); + debug(1, 1)("offset %d, char %c\n", stpos.strofs, ch); /* If we have a CR or an LF, its the end .. */ - if (ch == '\012' || ch == '\015') { + if (ch == '\r' || ch == '\n') { + debug(1, 1) ("Got a CRLF, breaking..\n"); gotcrlf = 1; break; } /* Now, do the per-state magic */ + debug(1, 1) ("Mode: %d\n", mode); switch (mode) { case HTTP_METHOD_PREWS: + /* + * If we've hit a non-whitespace char, upgrade + * the state + */ + if (ch != ' ' && ch != '\t') { + method_start = stpos; + mode = HTTP_METHOD; + } break; case HTTP_METHOD: + /* + * If we've hit a whitespace char, upgrade + * the state + */ + if (ch == ' ' || ch == '\t') { + method_end = stpos; + mode = HTTP_URL_PREWS; + } break; case HTTP_URL_PREWS: + /* + * If we've hit a non-whitespace char, upgrade + * the state + */ + if (ch != ' ' && ch != '\t') { + url_start = stpos; + mode = HTTP_URL; + } break; case HTTP_URL: + /* + * If we've hit a whitespace char, upgrade + * the state + */ + if (ch == ' ' || ch == '\t') { + url_end = stpos; + mode = HTTP_VERSION_PREWS; + } break; case HTTP_VERSION_PREWS: + /* + * If we've hit a non-whitespace char, upgrade + * the state + */ + if (ch != ' ' && ch != '\t') { + version_start = stpos; + mode = HTTP_VERSION; + } break; case HTTP_VERSION: + /* + * If we've hit a whitespace char, upgrade + * the state + */ + if (ch == ' ' || ch == '\t') { + version_end = stpos; + mode = HTTP_CRLF; + } break; case HTTP_CRLF: + if (ch == '\r' || ch == '\n') { + breakloop = 1; + } break; default: fatal("Unknown HTTP parse state!"); } /* Finally, advance characters */ - if (stmem_ref_pos_getnext(&stpos) == 0) + if (oldmode == mode && stmem_ref_pos_getnext(&stpos) == 0) + break; + if (breakloop) break; } @@ -197,29 +265,12 @@ * a potentially valid buffer */ - /* Find the first non-whitespace character in the buffer */ - /* This is the start of the request method */ - - /* Find the first whitespace character in the buffer */ - /* This is the end of the request method */ - - /* Find the next non-whitespace character in the buffer */ - /* This is the start of the URI */ - - /* Find the next whitespace character in the buffer */ - /* This is the end of the URI */ - - /* Find the next non-whitespace character in the buffer */ - /* This is the beginning of the version */ - - /* Find the next whitespace or cr/lf/crlf character in the buffer */ - /* This is the end of the version */ - - /* - * Find the next cr/lf/crlf character in the buffer (unless of course - * the previous find _hit_ a cr/lf/crlf!) - this is the end of the - * request line - */ + stmem_ref_pos_print(&method_start); + stmem_ref_pos_print(&method_end); + stmem_ref_pos_print(&url_start); + stmem_ref_pos_print(&url_end); + stmem_ref_pos_print(&version_start); + stmem_ref_pos_print(&version_end); /* At this stage we've got a request but we don't know if its valid */