--------------------- PatchSet 2811 Date: 2001/08/22 18:18:40 Author: adri Branch: newhttp Tag: (none) Log: Starting the parser. I can already tell the parsing will be inefficient, but I've commented what it should look like eventually. Members: src/structs.h:1.1.1.3.4.1.4.12.2.26.2.11->1.1.1.3.4.1.4.12.2.26.2.12 src/typedefs.h:1.1.1.3.8.7.4.24.2.6->1.1.1.3.8.7.4.24.2.7 src/modules/new_http_client/http_request.c:1.1.2.2->1.1.2.3 src/modules/new_http_client/http_request.h:1.1.2.1->1.1.2.2 Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.1.1.3.4.1.4.12.2.26.2.11 retrieving revision 1.1.1.3.4.1.4.12.2.26.2.12 diff -u -r1.1.1.3.4.1.4.12.2.26.2.11 -r1.1.1.3.4.1.4.12.2.26.2.12 --- squid/src/structs.h 9 Aug 2001 18:58:13 -0000 1.1.1.3.4.1.4.12.2.26.2.11 +++ squid/src/structs.h 22 Aug 2001 18:18:40 -0000 1.1.1.3.4.1.4.12.2.26.2.12 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.26.2.11 2001/08/09 18:58:13 adri Exp $ + * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.26.2.12 2001/08/22 18:18:40 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1393,6 +1393,14 @@ stmem_type_t strtype; /* ST_NONE or ST_SETUP */ }; +/* A pointer into inside an stmem_ref_pos */ +struct _stmem_ref_pos { + stmem_ref_t *st; /* which one we're referring to */ + int strofs; /* The string offset */ + mem_node *node; /* The node of the current offset */ + int nodeofs; /* Offset inside the current node */ +}; + /* keep track each client receiving data from that particular StoreEntry */ struct _store_client { int type; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.1.1.3.8.7.4.24.2.6 retrieving revision 1.1.1.3.8.7.4.24.2.7 diff -u -r1.1.1.3.8.7.4.24.2.6 -r1.1.1.3.8.7.4.24.2.7 --- squid/src/typedefs.h 7 Aug 2001 19:57:46 -0000 1.1.1.3.8.7.4.24.2.6 +++ squid/src/typedefs.h 22 Aug 2001 18:18:40 -0000 1.1.1.3.8.7.4.24.2.7 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.1.1.3.8.7.4.24.2.6 2001/08/07 19:57:46 adri Exp $ + * $Id: typedefs.h,v 1.1.1.3.8.7.4.24.2.7 2001/08/22 18:18:40 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -138,6 +138,7 @@ typedef struct _mem_node mem_node; typedef struct _mem_hdr mem_hdr; typedef struct _stmem_ref stmem_ref_t; +typedef struct _stmem_ref_pos stmem_ref_pos_t; typedef struct _store_client store_client; typedef struct _MemObject MemObject; typedef struct _StoreEntry StoreEntry; 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.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/modules/new_http_client/http_request.c 9 Aug 2001 19:14:12 -0000 1.1.2.2 +++ squid/src/modules/new_http_client/http_request.c 22 Aug 2001 18:18:40 -0000 1.1.2.3 @@ -6,6 +6,96 @@ /* + * Set the string offset to the given offset + * + * Return 0 if the offset doesn't exist, 1 if we're sucessful + */ +int +stmem_ref_pos_set(stmem_ref_pos_t *pos, stmem_ref_t *st, int strofs) +{ + dlink_node *node; + mem_node *mnode; + int curofs = st->mem.origin_offset; + + /* Set the initial stuff */ + pos->st = st; + pos->strofs = strofs; + + /* + * Now, loop through to find our node/offset + * noting that each mem_node is sized in SM_PAGE_SIZE chunks + */ + + node = st->mem.list.head; + while (node != NULL) { + mnode = node->data; + /* Check if the current node is what we want */ + if (strofs < curofs + SM_PAGE_SIZE) { + /* Whee! */ + pos->node = mnode; + pos->nodeofs = strofs - curofs; + return 1; + } + /* Next .. */ + node = node->next; + } + + /* If we get here, we didn't find our offset */ + return 0; +} + + +/* + * Advance the pointer to the next char in the string + * + * If there are no more characters, 0 is returned. Else 1 is returned. + */ +int +stmem_ref_pos_getnext(stmem_ref_pos_t *pos) +{ + assert(pos->st != NULL); + assert(pos->node != NULL); + + /* Do we have any chars left in this node? */ + if (pos->nodeofs < pos->node->len) { + /* Yes, advance to the next char, return */ + pos->nodeofs++; + return 1; + } + + /* Do we have any nodes left? */ + if (pos->node->node.next != NULL) { + /* Yes, advance to the next node */ + pos->node = pos->node->node.next->data; + pos->nodeofs = 0; + /* Assert there's data _in_ this node */ + assert(pos->node->len != 0); + /* Return */ + return 1; + } + + /* We're at the end of string - return 0 */ + return 0; +} + + +/* + * Grab the char at the given pos + * + * This could be a macro, but for testing this is easier.. + */ +char +stmem_ref_pos_getchar(stmem_ref_pos_t *pos) +{ + /* make sure we've got a valid position */ + assert(pos->st != NULL); + assert(pos->node != NULL); + + return pos->node->data[pos->nodeofs]; +} + + +/* * http_client_read_request - attempt to parse the buffer * as a request * @@ -18,10 +108,19 @@ * If we succeed in nabbing a request we upgrade the connection to * the relevant type (CONNECT, REQUESTBODY, NORMAL) and then call * its handler function to try parsing some more. + * + * Notes: + * - this isn't going to be the most efficient way of parsing. + * What we'll want to do is get the number of characters left in the + * current buffer and then only parse until then before getting a new + * buffer. This code however lets us *test* things out (as you can + * rewrite this code at a later date without impacting on the rest of + * the client code.) */ int http_client_read_request(int fd, http_client_conn_state_t *conn) { + stmem_ref_pos_t stpos; /* * Note that during any of the below finds: @@ -35,6 +134,7 @@ * start of the request. For pipelined requests this may or * may not be true. */ + stmem_ref_pos_set(&stpos, &conn->st, 0); /* Find the first non-whitespace character in the buffer */ /* This is the start of the request method */ @@ -63,5 +163,5 @@ /* At this stage we've got a request but we don't know if its valid */ /* For now, succeed */ - return 1; + return HTTP_REQUEST_OK; } Index: squid/src/modules/new_http_client/http_request.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/modules/new_http_client/Attic/http_request.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/modules/new_http_client/http_request.h 9 Aug 2001 18:58:13 -0000 1.1.2.1 +++ squid/src/modules/new_http_client/http_request.h 22 Aug 2001 18:18:40 -0000 1.1.2.2 @@ -1,6 +1,14 @@ #ifndef __HTTP_REQUEST_H__ #define __HTTP_REQUEST_H__ +/* http_client_read_request status */ +typedef enum { + HTTP_REQUEST_PARTIAL, + HTTP_REQUEST_ERROR, + HTTP_REQUEST_TOOBIG, + HTTP_REQUEST_OK +} http_client_request_status_t; + /* Functions */ extern int http_client_read_request(int fd, http_client_conn_state_t *conn);