From 14b463aa1899f0bd167d4c40b160b69c4c71deb5 Mon Sep 17 00:00:00 2001 From: hno <> Date: Mon, 17 Jun 2002 02:05:53 +0000 Subject: [PATCH] Added some functions for accessing HTTP list header values 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 | 59 ++++++++++++++++++++++++++++++++++++++++++++++- src/protos.h | 4 +++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 640ab52f3e..19fcf218dd 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -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) diff --git a/src/protos.h b/src/protos.h index 3156cecb23..0787751e80 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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); -- 2.47.3