--------------------- PatchSet 2850 Date: 2001/08/24 22:52:32 Author: adri Branch: newhttp Tag: (none) Log: Start the parsing loop, fill out some comments explaining what I'm going to do. This looks like it'll be prototyped as a state engine for now. Members: src/modules/new_http_client/http_request.c:1.1.2.3->1.1.2.4 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.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/src/modules/new_http_client/http_request.c 22 Aug 2001 18:18:40 -0000 1.1.2.3 +++ squid/src/modules/new_http_client/http_request.c 24 Aug 2001 22:52:32 -0000 1.1.2.4 @@ -4,6 +4,16 @@ #include "http_request.h" +typedef enum { + HTTP_NONE, + HTTP_METHOD_PREWS, + HTTP_METHOD, + HTTP_URL_PREWS, + HTTP_URL, + HTTP_VERSION_PREWS, + HTTP_VERSION, + HTTP_CRLF +} http_request_parse_t; /* * Set the string offset to the given offset @@ -120,7 +130,21 @@ int http_client_read_request(int fd, http_client_conn_state_t *conn) { - stmem_ref_pos_t stpos; + stmem_ref_pos_t stpos; /* Current position */ + + stmem_ref_pos_t method_start, method_end; /* Method */ + stmem_ref_pos_t url_start, url_end; /* URL */ + stmem_ref_pos_t version_start, version_end; /* Version */ + int gotcrlf = 0; + http_request_parse_t mode = HTTP_METHOD_PREWS; + char ch; + + /* + * For now we assume the first character in the buffer is the + * start of the request. For pipelined requests this may or + * may not be true. + */ + stmem_ref_pos_set(&stpos, &conn->st, 0); /* * Note that during any of the below finds: @@ -129,12 +153,49 @@ * buffer */ - /* - * For now we assume the first character in the buffer is the - * start of the request. For pipelined requests this may or - * may not be true. - */ - stmem_ref_pos_set(&stpos, &conn->st, 0); + while (1) { + ch = stmem_ref_pos_getchar(&stpos); + + /* If we have a CR or an LF, its the end .. */ + if (ch == '\012' || ch == '\015') { + gotcrlf = 1; + break; + } + + /* Now, do the per-state magic */ + switch (mode) { + case HTTP_METHOD_PREWS: + break; + case HTTP_METHOD: + break; + case HTTP_URL_PREWS: + break; + case HTTP_URL: + break; + case HTTP_VERSION_PREWS: + break; + case HTTP_VERSION: + break; + case HTTP_CRLF: + break; + default: + fatal("Unknown HTTP parse state!"); + } + + /* Finally, advance characters */ + if (stmem_ref_pos_getnext(&stpos) == 0) + break; + } + + /* Now, check the current mode - if we have a CRLF but we're not + * at the CRLF state, we hit a parse error */ + + /* If we're not at the CRLF state but we get here, we've parsed + * a partial buffer, so return that */ + + /* If we're at the CRLF *and* we're at the CRLF state, we've got + * a potentially valid buffer */ + /* Find the first non-whitespace character in the buffer */ /* This is the start of the request method */