--------------------- PatchSet 2891 Date: 2001/08/28 23:08:30 Author: adri Branch: newhttp Tag: (none) Log: * start fleshing out the refstring implementation * move the stmem_pos manipulation routines over to stmem.c, since the refstring code is about to abuse them Members: src/enums.h:1.1.1.3.8.8.4.7.2.5->1.1.1.3.8.8.4.7.2.6 src/protos.h:1.1.1.3.8.11.2.20.2.12->1.1.1.3.8.11.2.20.2.13 src/refstring.c:1.1.2.1->1.1.2.2 src/stmem.c:1.1.1.2.12.3.4.1.2.5->1.1.1.2.12.3.4.1.2.6 src/structs.h:1.1.1.3.4.1.4.12.2.26.2.12->1.1.1.3.4.1.4.12.2.26.2.13 src/typedefs.h:1.1.1.3.8.7.4.24.2.7->1.1.1.3.8.7.4.24.2.8 src/modules/new_http_client/http_request.c:1.1.2.8->1.1.2.9 Index: squid/src/enums.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/enums.h,v retrieving revision 1.1.1.3.8.8.4.7.2.5 retrieving revision 1.1.1.3.8.8.4.7.2.6 diff -u -r1.1.1.3.8.8.4.7.2.5 -r1.1.1.3.8.8.4.7.2.6 --- squid/src/enums.h 9 Aug 2001 18:58:13 -0000 1.1.1.3.8.8.4.7.2.5 +++ squid/src/enums.h 28 Aug 2001 23:08:30 -0000 1.1.1.3.8.8.4.7.2.6 @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.1.1.3.8.8.4.7.2.5 2001/08/09 18:58:13 adri Exp $ + * $Id: enums.h,v 1.1.1.3.8.8.4.7.2.6 2001/08/28 23:08:30 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -701,6 +701,7 @@ typedef enum { RS_NONE, /* Shouldn't normally see this */ + RS_BLANK, /* Setup, but neither shared or local */ RS_SHARED, /* We're using the shared ro string */ RS_LOCAL /* We're using our own string */ } refstring_type_t; Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.1.1.3.8.11.2.20.2.12 retrieving revision 1.1.1.3.8.11.2.20.2.13 diff -u -r1.1.1.3.8.11.2.20.2.12 -r1.1.1.3.8.11.2.20.2.13 --- squid/src/protos.h 8 Aug 2001 13:37:30 -0000 1.1.1.3.8.11.2.20.2.12 +++ squid/src/protos.h 28 Aug 2001 23:08:30 -0000 1.1.1.3.8.11.2.20.2.13 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.1.1.3.8.11.2.20.2.12 2001/08/08 13:37:30 adri Exp $ + * $Id: protos.h,v 1.1.1.3.8.11.2.20.2.13 2001/08/28 23:08:30 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -869,6 +869,12 @@ extern int stmemRefUnref(stmem_ref_t *); extern int stmemRead(int, stmem_ref_t *); +extern void stmem_ref_pos_print(stmem_ref_pos_t *pos); +extern int stmem_ref_pos_set(stmem_ref_pos_t *pos, stmem_ref_t *st, int strofs); +extern int stmem_ref_pos_getnext(stmem_ref_pos_t *pos); +extern char stmem_ref_pos_getchar(stmem_ref_pos_t *pos); + + /* ----------------------------------------------------------------- */ /* Index: squid/src/refstring.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/refstring.c,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/refstring.c 28 Aug 2001 19:49:19 -0000 1.1.2.1 +++ squid/src/refstring.c 28 Aug 2001 23:08:30 -0000 1.1.2.2 @@ -3,7 +3,7 @@ * * Adrian Chadd * - * $Id: refstring.c,v 1.1.2.1 2001/08/28 19:49:19 adri Exp $ + * $Id: refstring.c,v 1.1.2.2 2001/08/28 23:08:30 adri Exp $ */ #include "squid.h" @@ -16,6 +16,27 @@ * If a stmem_ref_pos_t and len are given, then initialise the string * with a read-only reference to that. */ +void +refstring_init(refstring_t *rs, stmem_ref_t *st, stmem_ref_pos_t *pos) +{ + /* Make sure its not initialised */ + assert(rs->type == RS_NONE); + + /* Initialise the string */ + rs->type = RS_BLANK; + rs->len = NULL; + + /* If we have a read-only string position */ + if (pos != NULL) { + /* Set this string up to be a read-only string */ + rs->type = RS_SHARED; + rs->ro_string = st; + rs->ro_pos = *pos; + stmemRefRef(st); + } + + /* Done! */ +} /* @@ -24,10 +45,32 @@ * Create a new writeable string, and copy the contents * of the read-only stmem_ref and unlock it if it exists */ +void +refstring_makerw(refstring_t *rs) +{ + /* Create a rw string */ + stmemRefNew(&rs->rw_string); + + /* Do we have a ro string? */ + if (rs->ro_string != NULL) { + /* Yes */ + assert(rs->type == RS_SHARED); + + /* Copy it over */ + fatal("Dude, write this bit of code!"); + + /* Unreference the string */ + stmemRefUnref(rs->ro_string); + } + + /* Upgrade the string type to a rw string */ + rs->type = RS_LOCAL; +} /* * refstring_cmp - compare two strings + * Same return values as strcmp */ Index: squid/src/stmem.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/stmem.c,v retrieving revision 1.1.1.2.12.3.4.1.2.5 retrieving revision 1.1.1.2.12.3.4.1.2.6 diff -u -r1.1.1.2.12.3.4.1.2.5 -r1.1.1.2.12.3.4.1.2.6 --- squid/src/stmem.c 25 Aug 2001 00:04:03 -0000 1.1.1.2.12.3.4.1.2.5 +++ squid/src/stmem.c 28 Aug 2001 23:08:30 -0000 1.1.1.2.12.3.4.1.2.6 @@ -1,6 +1,6 @@ /* - * $Id: stmem.c,v 1.1.1.2.12.3.4.1.2.5 2001/08/25 00:04:03 adri Exp $ + * $Id: stmem.c,v 1.1.1.2.12.3.4.1.2.6 2001/08/28 23:08:30 adri Exp $ * * DEBUG: section 19 Store Memory Primitives * AUTHOR: Harvest Derived @@ -291,3 +291,107 @@ return retval; } + + +/* + * stmem_ref_pos_t manipulation routines + */ + +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 + * + * 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); + + debug(1, 1) ("getnext; nodeofs=%d, nodelen=%d\n", pos->nodeofs, pos->node->len); + /* Do we have any chars left in this node? */ + if (pos->nodeofs < pos->node->len) { + /* Yes, advance to the next char, return */ + pos->nodeofs++; + pos->strofs++; + 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; + pos->strofs++; + /* 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]; +} 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.12 retrieving revision 1.1.1.3.4.1.4.12.2.26.2.13 diff -u -r1.1.1.3.4.1.4.12.2.26.2.12 -r1.1.1.3.4.1.4.12.2.26.2.13 --- squid/src/structs.h 22 Aug 2001 18:18:40 -0000 1.1.1.3.4.1.4.12.2.26.2.12 +++ squid/src/structs.h 28 Aug 2001 23:08:30 -0000 1.1.1.3.4.1.4.12.2.26.2.13 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.26.2.12 2001/08/22 18:18:40 adri Exp $ + * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.26.2.13 2001/08/28 23:08:30 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2162,8 +2162,7 @@ */ struct _refstring { stmem_ref_t *ro_string; /* Pointer to a read-only string */ - mem_node *ro_string_node; /* Local string starting node */ - off_t ro_string_off; /* offset inside node of string start */ + stmem_ref_pos_t ro_pos; /* Where in which string we're in */ stmem_ref_t rw_string; /* Local string, if we're using it */ refstring_type_t type; /* String type */ int len; /* String length */ 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.7 retrieving revision 1.1.1.3.8.7.4.24.2.8 diff -u -r1.1.1.3.8.7.4.24.2.7 -r1.1.1.3.8.7.4.24.2.8 --- squid/src/typedefs.h 22 Aug 2001 18:18:40 -0000 1.1.1.3.8.7.4.24.2.7 +++ squid/src/typedefs.h 28 Aug 2001 23:08:30 -0000 1.1.1.3.8.7.4.24.2.8 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.1.1.3.8.7.4.24.2.7 2001/08/22 18:18:40 adri Exp $ + * $Id: typedefs.h,v 1.1.1.3.8.7.4.24.2.8 2001/08/28 23:08:30 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -194,6 +194,8 @@ typedef struct _http_version_t http_version_t; +typedef struct _refstring refstring_t; + /* modules.c */ typedef struct _modConfig modConfig; typedef struct _modNode modNode; 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.8 retrieving revision 1.1.2.9 diff -u -r1.1.2.8 -r1.1.2.9 --- squid/src/modules/new_http_client/http_request.c 28 Aug 2001 19:48:38 -0000 1.1.2.8 +++ squid/src/modules/new_http_client/http_request.c 28 Aug 2001 23:08:31 -0000 1.1.2.9 @@ -17,105 +17,6 @@ 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 - * - * 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); - - debug(1, 1) ("getnext; nodeofs=%d, nodelen=%d\n", pos->nodeofs, pos->node->len); - /* Do we have any chars left in this node? */ - if (pos->nodeofs < pos->node->len) { - /* Yes, advance to the next char, return */ - pos->nodeofs++; - pos->strofs++; - 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; - pos->strofs++; - /* 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