--------------------- PatchSet 11746 Date: 2007/11/19 12:21:41 Author: adrian Branch: HEAD Tag: (none) Log: Author: Adrian Chadd add httpHeaderPrint; pack header entries after the array has been modified. Not modified replies may update header entries; but the array operator only supports an "append" operation which may grow the array. Write and use a httpHeaderPack() function which moves entries to the front of the entries array and resets the array size so the array doesn't grow. Members: src/HttpHeader.c:1.95->1.96 Index: squid/src/HttpHeader.c =================================================================== RCS file: /cvsroot/squid/squid/src/HttpHeader.c,v retrieving revision 1.95 retrieving revision 1.96 diff -u -r1.95 -r1.96 --- squid/src/HttpHeader.c 11 Apr 2007 22:02:41 -0000 1.95 +++ squid/src/HttpHeader.c 19 Nov 2007 12:21:41 -0000 1.96 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.c,v 1.95 2007/04/11 22:02:41 hno Exp $ + * $Id: HttpHeader.c,v 1.96 2007/11/19 12:21:41 adrian Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -141,6 +141,8 @@ }; static HttpHeaderFieldInfo *Headers = NULL; +static void httpHeaderPrint(const HttpHeader * hdr); + /* * headers with field values defined as #(values) in HTTP/1.1 * Headers that are currently not recognized, are commented out. @@ -381,12 +383,34 @@ } } +static void +httpHeaderRepack(HttpHeader * hdr) +{ + HttpHeaderPos dp = HttpHeaderInitPos; + HttpHeaderPos pos = HttpHeaderInitPos; + + /* XXX breaks layering for now! ie, getting grubby fingers in without httpHeaderEntryGet() */ + dp = 0; + pos = 0; + while (dp < hdr->entries.count) { + for (; dp < hdr->entries.count && hdr->entries.items[dp] == NULL; dp++); + assert(dp < hdr->entries.count); + hdr->entries.items[pos] = hdr->entries.items[dp]; + if (dp != pos) + hdr->entries.items[dp] = NULL; + pos++; + dp++; + } + arrayShrink(&hdr->entries, pos); +} + /* use fresh entries to replace old ones */ void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask) { const HttpHeaderEntry *e; HttpHeaderPos pos = HttpHeaderInitPos; + assert(old && fresh); assert(old != fresh); debug(55, 7) ("updating hdr: %p <- %p\n", old, fresh); @@ -401,6 +425,9 @@ httpHeaderDelByName(old, strBuf(e->name)); httpHeaderAddClone(old, e); } + + /* And now, repack the array to "fill in the holes" */ + httpHeaderRepack(old); } /* just handy in parsing: resets and returns false */ @@ -1442,3 +1469,16 @@ assert(id >= 0 && id < HDR_ENUM_END); return strBuf(Headers[id].name); } + +static void +httpHeaderPrint(const HttpHeader * hdr) +{ + HttpHeaderEntry *he; + HttpHeaderPos i = HttpHeaderInitPos; + + debug(1, 1) ("httpHeaderPrint: %p\n", hdr); + while ((he = httpHeaderGetEntry(hdr, &i))) { + debug(2, 1) (" (%d): %s: %s\n", i, strBuf(he->name), strBuf(he->value)); + } + debug(1, 1) ("httpHeaderPrint: array size %d\n", hdr->entries.count); +}