--------------------- PatchSet 10375 Date: 2008/01/06 09:56:00 Author: adri Branch: s27_adri Tag: (none) Log: ... and flesh out the bare minimum for the new parser to function. This works fine for a single request but polygraph is failing, so my offsets are probably all broken in the persistent connection case. Members: libcore/tools.h:1.1.2.3->1.1.2.4 libhttp/HttpHeader.c:1.1.2.2->1.1.2.3 libhttp/HttpHeader.h:1.1.2.2->1.1.2.3 libhttp/HttpHeaderEntry.c:1.1.2.1->1.1.2.2 src/HttpHeader.c:1.28.6.1.4.25->1.28.6.1.4.26 src/defines.h:1.43.8.5->1.43.8.6 Index: squid/libcore/tools.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libcore/Attic/tools.h,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/libcore/tools.h 16 Dec 2007 16:14:23 -0000 1.1.2.3 +++ squid/libcore/tools.h 6 Jan 2008 09:56:00 -0000 1.1.2.4 @@ -5,7 +5,7 @@ * * Adrian Chadd * - * $Id: tools.h,v 1.1.2.3 2007/12/16 16:14:23 adri Exp $ + * $Id: tools.h,v 1.1.2.4 2008/01/06 09:56:00 adri Exp $ */ #ifndef __LIBCORE_TOOLS_H__ #define __LIBCORE_TOOLS_H__ @@ -54,4 +54,16 @@ #define XMIN(x,y) ((x)<(y)? (x) : (y)) +#define EBIT_SET(flag, bit) ((void)((flag) |= ((1L<<(bit))))) +#define EBIT_CLR(flag, bit) ((void)((flag) &= ~((1L<<(bit))))) +#define EBIT_TEST(flag, bit) ((flag) & ((1L<<(bit)))) + +/* bit opearations on a char[] mask of unlimited length */ +#define CBIT_BIT(bit) (1<<((bit)%8)) +#define CBIT_BIN(mask, bit) (mask)[(bit)>>3] +#define CBIT_SET(mask, bit) ((void)(CBIT_BIN(mask, bit) |= CBIT_BIT(bit))) +#define CBIT_CLR(mask, bit) ((void)(CBIT_BIN(mask, bit) &= ~CBIT_BIT(bit))) +#define CBIT_TEST(mask, bit) ((CBIT_BIN(mask, bit) & CBIT_BIT(bit)) != 0) + + #endif /* __LIBCORE_TOOLS_H__ */ Index: squid/libhttp/HttpHeader.c =================================================================== RCS file: /cvsroot/squid-sf//squid/libhttp/Attic/HttpHeader.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/libhttp/HttpHeader.c 6 Jan 2008 09:19:52 -0000 1.1.2.2 +++ squid/libhttp/HttpHeader.c 6 Jan 2008 09:56:00 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.c,v 1.1.2.2 2008/01/06 09:19:52 adri Exp $ + * $Id: HttpHeader.c,v 1.1.2.3 2008/01/06 09:56:00 adri Exp $ */ #include @@ -16,6 +16,7 @@ #include "../libcore/varargs.h" #include "../libcore/debug.h" #include "../libcore/tools.h" +#include "../libmem/mem.h" #include "../libbuf/buf.h" #include "../libbuf/String.h" @@ -30,17 +31,44 @@ static int hdr_add(HttpHeader *hdr, buf_t *b, int fs, int fe, int vs, int ve) { + HttpHeaderEntry *e, *e2; + int id; + + e = memAllocate(MEM_HTTP_HDR_ENTRY); + /* Look up the field name - is it a field we know? */ + id = httpHeaderIdByName(buf_buf(b) + fs, fe - fs + 1, Headers, HDR_ENUM_END); /* No, then allocate a string for that field name */ + if (id < 0) { + e->id = HDR_OTHER; + e->name = strSubBuf(b, fs, fe - fs + 1); + } else { + e->id = id; + e->name = stringDup(&Headers[id].name); + } + + /* Assign value string */ + e->value = strSubBuf(b, vs, ve - vs + 1); /* Content-Length header? Sanity-check it */ /* White-space in field name? Bad bad! */ /* At this point; add and return successful */ - + Headers[e->id].stat.seenCount++; + Headers[e->id].stat.aliveCount++; + httpHeaderAddEntry(hdr, e); + /* e isn't ours anymore */ + e = NULL; return 1; +bad: + if (e) { + stringClean(&e->name); + stringClean(&e->value); + memFree(e, MEM_HTTP_HDR_ENTRY); + } + return 0; } @@ -187,3 +215,45 @@ return retcode; } +/* + * appends an entry; + * does not call httpHeaderEntryClone() so one should not reuse "*e" + */ +void +httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e) +{ + assert(hdr && e); + assert_eid(e->id); + + debug(55, 7) ("%p adding entry: %d at %d\n", + hdr, e->id, hdr->entries.count); + if (CBIT_TEST(hdr->mask, e->id)) + Headers[e->id].stat.repCount++; + else + CBIT_SET(hdr->mask, e->id); + arrayAppend(&hdr->entries, e); + /* increment header length, allow for ": " and crlf */ + hdr->len += strLen(e->name) + 2 + strLen(e->value) + 2; +} + +/* + * inserts an entry at the given position; + * does not call httpHeaderEntryClone() so one should not reuse "*e" + */ +void +httpHeaderInsertEntry(HttpHeader * hdr, HttpHeaderEntry * e, int pos) +{ + assert(hdr && e); + assert_eid(e->id); + + debug(55, 7) ("%p adding entry: %d at %d\n", + hdr, e->id, hdr->entries.count); + if (CBIT_TEST(hdr->mask, e->id)) + Headers[e->id].stat.repCount++; + else + CBIT_SET(hdr->mask, e->id); + arrayInsert(&hdr->entries, e, pos); + /* increment header length, allow for ": " and crlf */ + hdr->len += strLen(e->name) + 2 + strLen(e->value) + 2; +} + Index: squid/libhttp/HttpHeader.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libhttp/Attic/HttpHeader.h,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/libhttp/HttpHeader.h 6 Jan 2008 09:19:52 -0000 1.1.2.2 +++ squid/libhttp/HttpHeader.h 6 Jan 2008 09:56:00 -0000 1.1.2.3 @@ -23,6 +23,7 @@ typedef struct _HttpHeader HttpHeader; extern int httpHeaderParseBuf(HttpHeader *hdr, buf_t *buf, int offset); - +extern void httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e); +extern void httpHeaderInsertEntry(HttpHeader * hdr, HttpHeaderEntry * e, int pos); #endif Index: squid/libhttp/HttpHeaderEntry.c =================================================================== RCS file: /cvsroot/squid-sf//squid/libhttp/Attic/HttpHeaderEntry.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/libhttp/HttpHeaderEntry.c 6 Jan 2008 09:19:52 -0000 1.1.2.1 +++ squid/libhttp/HttpHeaderEntry.c 6 Jan 2008 09:56:00 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeaderEntry.c,v 1.1.2.1 2008/01/06 09:19:52 adri Exp $ + * $Id: HttpHeaderEntry.c,v 1.1.2.2 2008/01/06 09:56:00 adri Exp $ */ #include @@ -51,7 +51,7 @@ e = memAllocate(MEM_HTTP_HDR_ENTRY); e->id = id; if (id != HDR_OTHER) - e->name = Headers[id].name; + e->name = stringDup(&Headers[id].name); else stringInit(&e->name, name); stringInit(&e->value, value); @@ -68,7 +68,7 @@ e = memAllocate(MEM_HTTP_HDR_ENTRY); e->id = id; if (id != HDR_OTHER) - e->name = Headers[id].name; + e->name = stringDup(&Headers[id].name); else e->name = stringDup(&name); e->value = stringDup(&value); @@ -83,9 +83,7 @@ assert(e); assert_eid(e->id); debug(55, 9) ("destroying entry %p: '%.*s: %.*s'\n", e, strLen2(e->name), strBuf2(e->name), strLen2(e->value), strBuf2(e->value)); - /* clean name if needed */ - if (e->id == HDR_OTHER) - stringClean(&e->name); + stringClean(&e->name); stringClean(&e->value); assert(Headers[e->id].stat.aliveCount); Headers[e->id].stat.aliveCount--; @@ -145,7 +143,7 @@ if (id == HDR_OTHER) stringLimitInit(&e->name, field_start, name_len); else - e->name = Headers[id].name; + e->name = stringDup(&Headers[id].name); /* trim field value */ while (value_start < field_end && xisspace(*value_start)) value_start++; Index: squid/src/HttpHeader.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpHeader.c,v retrieving revision 1.28.6.1.4.25 retrieving revision 1.28.6.1.4.26 diff -u -r1.28.6.1.4.25 -r1.28.6.1.4.26 --- squid/src/HttpHeader.c 6 Jan 2008 09:19:53 -0000 1.28.6.1.4.25 +++ squid/src/HttpHeader.c 6 Jan 2008 09:56:01 -0000 1.28.6.1.4.26 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.c,v 1.28.6.1.4.25 2008/01/06 09:19:53 adri Exp $ + * $Id: HttpHeader.c,v 1.28.6.1.4.26 2008/01/06 09:56:01 adri Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -721,46 +721,6 @@ -/* appends an entry; - * does not call httpHeaderEntryClone() so one should not reuse "*e" - */ -void -httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e) -{ - assert(hdr && e); - assert_eid(e->id); - - debug(55, 7) ("%p adding entry: %d at %d\n", - hdr, e->id, hdr->entries.count); - if (CBIT_TEST(hdr->mask, e->id)) - Headers[e->id].stat.repCount++; - else - CBIT_SET(hdr->mask, e->id); - arrayAppend(&hdr->entries, e); - /* increment header length, allow for ": " and crlf */ - hdr->len += strLen(e->name) + 2 + strLen(e->value) + 2; -} - -/* inserts an entry at the given position; - * does not call httpHeaderEntryClone() so one should not reuse "*e" - */ -void -httpHeaderInsertEntry(HttpHeader * hdr, HttpHeaderEntry * e, int pos) -{ - assert(hdr && e); - assert_eid(e->id); - - debug(55, 7) ("%p adding entry: %d at %d\n", - hdr, e->id, hdr->entries.count); - if (CBIT_TEST(hdr->mask, e->id)) - Headers[e->id].stat.repCount++; - else - CBIT_SET(hdr->mask, e->id); - arrayInsert(&hdr->entries, e, pos); - /* increment header length, allow for ": " and crlf */ - hdr->len += strLen(e->name) + 2 + strLen(e->value) + 2; -} - /* return a list of entries with the same id separated by ',' and ws */ String httpHeaderGetList(const HttpHeader * hdr, http_hdr_type id) Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.43.8.5 retrieving revision 1.43.8.6 diff -u -r1.43.8.5 -r1.43.8.6 --- squid/src/defines.h 2 Jan 2008 17:29:33 -0000 1.43.8.5 +++ squid/src/defines.h 6 Jan 2008 09:56:01 -0000 1.43.8.6 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.43.8.5 2008/01/02 17:29:33 adri Exp $ + * $Id: defines.h,v 1.43.8.6 2008/01/06 09:56:01 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -162,17 +162,6 @@ #define SM_PAGE_SIZE 4096 -#define EBIT_SET(flag, bit) ((void)((flag) |= ((1L<<(bit))))) -#define EBIT_CLR(flag, bit) ((void)((flag) &= ~((1L<<(bit))))) -#define EBIT_TEST(flag, bit) ((flag) & ((1L<<(bit)))) - -/* bit opearations on a char[] mask of unlimited length */ -#define CBIT_BIT(bit) (1<<((bit)%8)) -#define CBIT_BIN(mask, bit) (mask)[(bit)>>3] -#define CBIT_SET(mask, bit) ((void)(CBIT_BIN(mask, bit) |= CBIT_BIT(bit))) -#define CBIT_CLR(mask, bit) ((void)(CBIT_BIN(mask, bit) &= ~CBIT_BIT(bit))) -#define CBIT_TEST(mask, bit) ((CBIT_BIN(mask, bit) & CBIT_BIT(bit)) != 0) - #define MAX_FILES_PER_DIR (1<<20) #define MAX_URL 4096