]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- added httpHeaderGetLastStr() to find last X-Cache
authorrousskov <>
Sat, 4 Apr 1998 05:26:32 +0000 (05:26 +0000)
committerrousskov <>
Sat, 4 Apr 1998 05:26:32 +0000 (05:26 +0000)
  the implementation is not optimized yet (searches from the beginning)

src/HttpHeader.cc
src/protos.h

index 365f6d0468d8fa49994d8e24f989c6de816360f5..5295e856620c8dd4f186ea9e0111059a6df72c01 100644 (file)
@@ -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)
 {
index 710fd12ab70f07db7aa798bbc5b6b2f25d8ba2e4..8427d0581060d4cc52a209e258a9eb78e592b788 100644 (file)
@@ -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);