--------------------- PatchSet 2923 Date: 2001/08/30 23:32:50 Author: adri Branch: newhttp Tag: (none) Log: More refstring parser work. I (think! heh) I have a refstring_cat_c() function that'll work. but I dunno yet. :) Members: src/protos.h:1.1.1.3.8.11.2.20.2.13->1.1.1.3.8.11.2.20.2.14 src/refstring.c:1.1.2.3->1.1.2.4 src/stmem.c:1.1.1.2.12.3.4.1.2.6->1.1.1.2.12.3.4.1.2.7 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.13 retrieving revision 1.1.1.3.8.11.2.20.2.14 diff -u -r1.1.1.3.8.11.2.20.2.13 -r1.1.1.3.8.11.2.20.2.14 --- squid/src/protos.h 28 Aug 2001 23:08:30 -0000 1.1.1.3.8.11.2.20.2.13 +++ squid/src/protos.h 30 Aug 2001 23:32:50 -0000 1.1.1.3.8.11.2.20.2.14 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.1.1.3.8.11.2.20.2.13 2001/08/28 23:08:30 adri Exp $ + * $Id: protos.h,v 1.1.1.3.8.11.2.20.2.14 2001/08/30 23:32:50 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -862,6 +862,7 @@ extern int stmemFreeDataUpto(mem_hdr *, int); extern void stmemAppend(mem_hdr *, const char *, int); extern ssize_t stmemCopy(const mem_hdr *, off_t, char *, size_t); +extern void stmemAddBuffer(mem_hdr *); extern void stmemFree(mem_hdr *); extern void stmemFreeData(mem_hdr *); extern void stmemRefNew(stmem_ref_t *); Index: squid/src/refstring.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/refstring.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/refstring.c 28 Aug 2001 23:42:58 -0000 1.1.2.3 +++ squid/src/refstring.c 30 Aug 2001 23:32:50 -0000 1.1.2.4 @@ -3,7 +3,7 @@ * * Adrian Chadd * - * $Id: refstring.c,v 1.1.2.3 2001/08/28 23:42:58 adri Exp $ + * $Id: refstring.c,v 1.1.2.4 2001/08/30 23:32:50 adri Exp $ */ @@ -16,6 +16,11 @@ * and offset where we start. In the case of a private buffer it points * to position 0. This means all the manipulation routines can just * work with the stuff inside the pos and all will work out fine. + * + * NOTE: These routines are _intentionally_ really inefficient - I'm + * using them to test out the whole idea first. Once the actual code + * is working and there's a working parser, these string routines + * can be heavily, heavily optimised. */ #include "squid.h" @@ -28,14 +33,15 @@ * with a read-only reference to that. */ void -refstring_init(refstring_t *rs, stmem_ref_t *st, stmem_ref_pos_t *pos) +refstring_init(refstring_t *rs, stmem_ref_t *st, stmem_ref_pos_t *pos, + int len) { /* Make sure its not initialised */ assert(rs->type == RS_NONE); /* Initialise the string */ rs->type = RS_BLANK; - rs->len = NULL; + rs->len = 0; /* blank out the pos */ bzero(&rs->pos, sizeof(stmem_ref_pos_t)); @@ -46,7 +52,11 @@ rs->type = RS_SHARED; rs->ro_string = st; rs->pos = *pos; + rs->len = len; stmemRefRef(st); + } else { + /* Don't get a length when we have no ro string! */ + assert(len == 0); } /* Done! */ @@ -58,10 +68,15 @@ * * Create a new writeable string, and copy the contents * of the read-only stmem_ref and unlock it if it exists + * If the string is already RW, do nothing. */ void refstring_makerw(refstring_t *rs) { + /* Return if the string is already RW */ + if (rs->type == RS_LOCAL) + return; + /* Create a rw string */ stmemRefNew(&rs->rw_string); @@ -92,8 +107,49 @@ /* + * refstring_cmp_c - compare a refstring to a C string + */ + + +/* * refstring_cat_c - append a C string to a refstring */ +void +refstring_cat_c(refstring_t *rs, char *c_str, int len) +{ + mem_node *node; + + /* Assert the string is setup */ + assert(rs->type != RS_BLANK); + + /* Make the string a rw string */ + refstring_makerw(rs); + + /* + * Now, start appending characters from our c_str to the + * end of our refstring + */ + while (len != 0) { + node = rs->pos.st->mem.list.tail->data; + /* Do we have space in the buf? */ + if (node->len == SM_PAGE_SIZE) + /* No, extend it */ + stmemAddBuffer(&rs->pos.st->mem); + + /* Get this pointer again, in case she changed */ + node = rs->pos.st->mem.list.tail->data; + + /* Copy char into buf */ + node->data[node->len] = *c_str; + + /* Increase buffer len pointer */ + node->len++; + + /* Next .. */ + len--; + c_str++; + } +} /* 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.6 retrieving revision 1.1.1.2.12.3.4.1.2.7 diff -u -r1.1.1.2.12.3.4.1.2.6 -r1.1.1.2.12.3.4.1.2.7 --- squid/src/stmem.c 28 Aug 2001 23:08:30 -0000 1.1.1.2.12.3.4.1.2.6 +++ squid/src/stmem.c 30 Aug 2001 23:32:50 -0000 1.1.1.2.12.3.4.1.2.7 @@ -1,6 +1,6 @@ /* - * $Id: stmem.c,v 1.1.1.2.12.3.4.1.2.6 2001/08/28 23:08:30 adri Exp $ + * $Id: stmem.c,v 1.1.1.2.12.3.4.1.2.7 2001/08/30 23:32:50 adri Exp $ * * DEBUG: section 19 Store Memory Primitives * AUTHOR: Harvest Derived @@ -38,7 +38,7 @@ static int stmem_initialised = 0; -static void +void stmemAddBuffer(mem_hdr *mem) { mem_node *p;