]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added some functions for accessing HTTP list header values
authorhno <>
Mon, 17 Jun 2002 02:05:53 +0000 (02:05 +0000)
committerhno <>
Mon, 17 Jun 2002 02:05:53 +0000 (02:05 +0000)
extern String httpHeaderGetListMember(const HttpHeader * hdr, http_hdr_type id, const char *member, const char separator);

extern String httpHeaderGetByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator);

src/HttpHeader.cc
src/protos.h

index 640ab52f3e021c7811ca6cb9309e2ae2de47aba7..19fcf218dd9f652ae76943b498a8f46352eda0ee 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHeader.cc,v 1.76 2002/06/16 19:48:04 hno Exp $
+ * $Id: HttpHeader.cc,v 1.77 2002/06/16 20:05:53 hno Exp $
  *
  * DEBUG: section 55    HTTP Header
  * AUTHOR: Alex Rousskov
@@ -661,6 +661,63 @@ httpHeaderGetByName(const HttpHeader * hdr, const char *name)
     return result;
 }
 
+/*
+ * returns a pointer to a specified entry if any 
+ * note that we return one entry so it does not make much sense to ask for
+ * "list" headers
+ */
+String
+httpHeaderGetByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator)
+{
+    String result = StringNull;
+    String header;
+    const char *pos = NULL;
+    const char *item;
+    int ilen;
+    int mlen = strlen(member);
+
+    assert(hdr);
+    assert(name);
+
+    header = httpHeaderGetByName(hdr, name);
+
+    while (strListGetItem(&header, separator, &item, &ilen, &pos)) {
+       if (strncmp(item, member, mlen) == 0 && item[mlen] == '=') {
+           stringAppend(&result, item + mlen + 1, ilen - mlen - 1);
+           break;
+       }
+    }
+    return result;
+}
+
+/*
+ * returns a the value of the specified list member, if any.
+ */
+String
+httpHeaderGetListMember(const HttpHeader * hdr, http_hdr_type id, const char *member, const char separator)
+{
+    String result = StringNull;
+    String header;
+    const char *pos = NULL;
+    const char *item;
+    int ilen;
+    int mlen = strlen(member);
+
+    assert(hdr);
+    assert(id >= 0);
+
+    header = httpHeaderGetStrOrList(hdr, id);
+
+    while (strListGetItem(&header, separator, &item, &ilen, &pos)) {
+       if (strncmp(item, member, mlen) == 0 && item[mlen] == '=') {
+           stringAppend(&result, item + mlen + 1, ilen - mlen - 1);
+           break;
+       }
+    }
+    stringClean(&header);
+    return result;
+}
+
 /* test if a field is present */
 int
 httpHeaderHas(const HttpHeader * hdr, http_hdr_type id)
index 3156cecb2313d7ce3ebc855fd3ad57760279a626..0787751e8018ab7e2878161942da4653daa200de 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.438 2002/06/16 17:46:26 hno Exp $
+ * $Id: protos.h,v 1.439 2002/06/16 20:05:53 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -453,6 +453,8 @@ extern const char *httpHeaderGetAuth(const HttpHeader * hdr, http_hdr_type id, c
 extern String httpHeaderGetList(const HttpHeader * hdr, http_hdr_type id);
 extern String httpHeaderGetStrOrList(const HttpHeader * hdr, http_hdr_type id);
 extern String httpHeaderGetByName(const HttpHeader * hdr, const char *name);
+extern String httpHeaderGetListMember(const HttpHeader * hdr, http_hdr_type id, const char *member, const char separator);
+extern String httpHeaderGetByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator);
 extern int httpHeaderDelByName(HttpHeader * hdr, const char *name);
 extern int httpHeaderDelById(HttpHeader * hdr, http_hdr_type id);
 extern void httpHeaderDelAt(HttpHeader * hdr, HttpHeaderPos pos);