/* DEBUG: section 90 HTTP Cache Control Header */
#include "squid.h"
+#include "base/LookupTable.h"
#include "HttpHdrSc.h"
#include "HttpHeader.h"
-#include "HttpHeaderFieldInfo.h"
#include "HttpHeaderFieldStat.h"
#include "HttpHeaderStat.h"
#include "HttpHeaderTools.h"
#include "util.h"
#include <map>
+#include <vector>
/* a row in the table used for parsing surrogate-control header and statistics */
typedef struct {
/* this table is used for parsing surrogate control header */
/* order must match that of enum http_hdr_sc_type. The constraint is verified at initialization time */
//todo: implement constraint
-static const HttpHeaderFieldAttrs ScAttrs[SC_ENUM_END] = {
- HttpHeaderFieldAttrs("no-store", (http_hdr_type)SC_NO_STORE),
- HttpHeaderFieldAttrs("no-store-remote", (http_hdr_type)SC_NO_STORE_REMOTE),
- HttpHeaderFieldAttrs("max-age", (http_hdr_type)SC_MAX_AGE),
- HttpHeaderFieldAttrs("content", (http_hdr_type)SC_CONTENT),
- HttpHeaderFieldAttrs("Other,", (http_hdr_type)SC_OTHER) /* ',' will protect from matches */
+static const LookupTable<http_hdr_sc_type>::Record ScAttrs[] {
+ {"no-store", SC_NO_STORE},
+ {"no-store-remote", SC_NO_STORE_REMOTE},
+ {"max-age", SC_MAX_AGE},
+ {"content", SC_CONTENT},
+ {"Other,", SC_OTHER}, /* ',' will protect from matches */
+ {nullptr, SC_ENUM_END} /* SC_ENUM_END taken as invalid value */
};
-
-HttpHeaderFieldInfo *ScFieldsInfo = NULL;
+LookupTable<http_hdr_sc_type> scLookupTable(SC_ENUM_END, ScAttrs);
+std::vector<HttpHeaderFieldStat> scHeaderStats(SC_ENUM_END);
http_hdr_sc_type &operator++ (http_hdr_sc_type &aHeader)
{
void
httpHdrScInitModule(void)
{
- ScFieldsInfo = httpHeaderBuildFieldsInfo(ScAttrs, SC_ENUM_END);
+ // check invariant on ScAttrs
+ for (int i = 0; ScAttrs[i].name != nullptr; ++i)
+ assert(i == ScAttrs[i].id);
}
void
httpHdrScCleanModule(void)
{
- httpHeaderDestroyFieldsInfo(ScFieldsInfo, SC_ENUM_END);
- ScFieldsInfo = NULL;
}
/* implementation */
const char *pos = NULL;
const char *target = NULL; /* ;foo */
const char *temp = NULL; /* temp buffer */
- int type;
+ http_hdr_sc_type type;
int ilen, vlen;
int initiallen;
HttpHdrScTarget *sct;
}
/* find type */
- /* TODO: use a type-safe map-based lookup */
- type = httpHeaderIdByName(item, ilen,
- ScFieldsInfo, SC_ENUM_END);
+ type = scLookupTable.lookup(SBuf(item,ilen));
- if (type < 0) {
+ if (type == SC_ENUM_END) {
debugs(90, 2, "hdr sc: unknown control-directive: near '" << item << "' in '" << str << "'");
type = SC_OTHER;
}
safe_free (temp);
- if (sct->isSet(static_cast<http_hdr_sc_type>(type))) {
+ if (sct->isSet(type)) {
if (type != SC_OTHER)
debugs(90, 2, "hdr sc: ignoring duplicate control-directive: near '" << item << "' in '" << str << "'");
- ++ ScFieldsInfo[type].stat.repCount;
+ ++ scHeaderStats[type].repCount;
continue;
}
if (isSet(flag) && flag != SC_OTHER) {
/* print option name */
- p->appendf((pcount ? ", " SQUIDSTRINGPH : SQUIDSTRINGPH),
- SQUIDSTRINGPRINT(ScFieldsInfo[flag].name));
+ p->appendf((pcount ? ", %s" : "%s"), ScAttrs[flag].name);
/* handle options with values */
{
extern const HttpHeaderStat *dump_stat; /* argh! */
const int id = (int) val;
- const int valid_id = id >= 0 && id < SC_ENUM_END;
- const char *name = valid_id ? ScFieldsInfo[id].name.termedBuf() : "INVALID";
+ const bool valid_id = id >= 0 && id < SC_ENUM_END;
+ const char *name = valid_id ? ScAttrs[id].name : "INVALID";
if (count || valid_id)
storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n",
{
extern const HttpHeaderStat *dump_stat; /* argh! */
const int id = (int) val;
- const int valid_id = id >= 0 && id < SC_ENUM_END;
- const char *name = valid_id ? ScFieldsInfo[id].name.termedBuf() : "INVALID";
+ const bool valid_id = id >= 0 && id < SC_ENUM_END;
+ const char *name = valid_id ? ScAttrs[id].name : "INVALID";
if (count || valid_id)
storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n",
#include "ConfigParser.h"
#include "fde.h"
#include "globals.h"
+#include "http/RegisteredHeaders.h"
#include "HttpHdrContRange.h"
#include "HttpHeader.h"
#include "HttpHeaderFieldInfo.h"
void
HeaderManglers::dumpAccess(StoreEntry * entry, const char *name) const
{
- for (int i = 0; i < HDR_ENUM_END; ++i) {
- header_mangler_dump_access(entry, name, known[i],
- httpHeaderNameById(i));
+ for (int i = 0; headerTable[i].name != nullptr; ++i) {
+ header_mangler_dump_access(entry, name, known[i], headerTable[i].name);
}
typedef ManglersByName::const_iterator MBNCI;
void
HeaderManglers::dumpReplacement(StoreEntry * entry, const char *name) const
{
- for (int i = 0; i < HDR_ENUM_END; ++i) {
- header_mangler_dump_replacement(entry, name, known[i],
- httpHeaderNameById(i));
+ for (int i = 0; headerTable[i].name != nullptr; ++i) {
+ header_mangler_dump_replacement(entry, name, known[i],headerTable[i].name);
}
typedef ManglersByName::const_iterator MBNCI;