From: rousskov <> Date: Sat, 4 Apr 1998 05:26:32 +0000 (+0000) Subject: - added httpHeaderGetLastStr() to find last X-Cache X-Git-Tag: SQUID_3_0_PRE1~3638 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a622fff0e90e2cfef129e5dc16280067723ee3da;p=thirdparty%2Fsquid.git - added httpHeaderGetLastStr() to find last X-Cache the implementation is not optimized yet (searches from the beginning) --- diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 365f6d0468..5295e85662 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.cc,v 1.28 1998/03/31 17:52:08 rousskov Exp $ + * $Id: HttpHeader.cc,v 1.29 1998/04/03 22:26:32 rousskov Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -396,6 +396,32 @@ httpHeaderFindEntry(const HttpHeader * hdr, http_hdr_type id) return NULL; /* not reached */ } +/* + * same as httpHeaderFindEntry + */ +static HttpHeaderEntry * +httpHeaderFindLastEntry(const HttpHeader * hdr, http_hdr_type id) +{ + HttpHeaderPos pos = HttpHeaderInitPos; + HttpHeaderEntry *e; + HttpHeaderEntry *result = NULL; + assert(hdr); + assert_eid(id); + assert(!CBIT_TEST(ListHeadersMask, id)); + + debug(55, 8) ("finding entry %d in hdr %p\n", id, hdr); + /* check mask first */ + if (!CBIT_TEST(hdr->mask, id)) + return NULL; + /* looks like we must have it, do linear search */ + while ((e = httpHeaderGetEntry(hdr, &pos))) { + if (e->id == id) + result = e; + } + assert(result); /* must be there! */ + return result; +} + /* * deletes all fields with a given name if any, returns #fields deleted; */ @@ -580,6 +606,7 @@ httpHeaderGetTime(const HttpHeader * hdr, http_hdr_type id) return value; } +/* sync httpHeaderGetLastStr */ const char * httpHeaderGetStr(const HttpHeader * hdr, http_hdr_type id) { @@ -593,6 +620,20 @@ httpHeaderGetStr(const HttpHeader * hdr, http_hdr_type id) return NULL; } +/* unusual */ +const char * +httpHeaderGetLastStr(const HttpHeader * hdr, http_hdr_type id) +{ + HttpHeaderEntry *e; + assert_eid(id); + assert(Headers[id].type == ftStr); /* must be of an appropriate type */ + if ((e = httpHeaderFindLastEntry(hdr, id))) { + httpHeaderNoteParsedEntry(e->id, e->value, 0); /* no errors are possible */ + return strBuf(e->value); + } + return NULL; +} + HttpHdrCc * httpHeaderGetCc(const HttpHeader * hdr) { diff --git a/src/protos.h b/src/protos.h index 710fd12ab7..8427d05810 100644 --- a/src/protos.h +++ b/src/protos.h @@ -326,6 +326,7 @@ extern HttpHdrCc *httpHeaderGetCc(const HttpHeader * hdr); extern HttpHdrRange *httpHeaderGetRange(const HttpHeader * hdr); extern HttpHdrContRange *httpHeaderGetContRange(const HttpHeader * hdr); extern const char *httpHeaderGetStr(const HttpHeader * hdr, http_hdr_type id); +extern const char *httpHeaderGetLastStr(const HttpHeader * hdr, http_hdr_type id); extern int httpHeaderDelByName(HttpHeader * hdr, const char *name); extern HttpHeaderEntry *httpHeaderFindEntry(const HttpHeader * hdr, http_hdr_type id); extern void httpHeaderEntryPackInto(const HttpHeaderEntry * e, Packer * p);