#include "auth/digest/UserRequest.h"
#include "auth/Gadgets.h"
#include "auth/State.h"
+#include "base/LookupTable.h"
#include "base64.h"
#include "cache_cf.h"
#include "event.h"
}
DigestFieldsLookupTable_t DigestFieldsLookupTable;
+
+static const LookupTable<http_digest_attr_type>::Record
+ DigestAttrs_Exp[] = {
+ {"username", DIGEST_USERNAME},
+ {"realm", DIGEST_REALM},
+ {"qop", DIGEST_QOP},
+ {"algorithm", DIGEST_ALGORITHM},
+ {"uri", DIGEST_URI},
+ {"nonce", DIGEST_NONCE},
+ {"nc", DIGEST_NC},
+ {"cnonce", DIGEST_CNONCE},
+ {"response", DIGEST_RESPONSE},
+ {nullptr, DIGEST_ENUM_END}
+};
+
+LookupTable<http_digest_attr_type>
+ExpDigestFieldsLookupTable(DIGEST_ENUM_END, DigestAttrs_Exp);
+
/*
*
* Nonce Functions
/* find type */
const http_digest_attr_type t = DigestFieldsLookupTable.lookup(keyName);
+ const http_digest_attr_type t2 = ExpDigestFieldsLookupTable.lookup(keyName);
+ assert(t==t2);
switch (t) {
case DIGEST_USERNAME:
--- /dev/null
+#ifndef SQUID_LOOKUPTABLE_H_
+#define SQUID_LOOKUPTABLE_H_
+
+#include "SBuf.h"
+
+#include <map>
+
+/**
+ * SBuf -> enum lookup table.
+ */
+template<class EnumType>
+class LookupTable
+{
+public:
+ typedef struct {
+ const char *name;
+ EnumType id;
+ } Record;
+
+ LookupTable(const EnumType theInvalid, const Record data[]) :
+ invalidValue(theInvalid)
+ {
+ for (auto i = 0; data[i].name != nullptr; ++i) {
+ lookupTable[SBuf(data[i].name)] = data[i].id;
+ }
+ }
+ EnumType lookup(const SBuf &key) const {
+ auto r = lookupTable.find(key);
+ if (r == lookupTable.end())
+ return invalidValue;
+ return r->second;
+ }
+
+private:
+ typedef std::map<const SBuf, EnumType> lookupTable_t;
+ lookupTable_t lookupTable;
+ EnumType invalidValue;
+};
+
+#endif /* SQUID_LOOKUPTABLE_H_ */