]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Turn field_type into a strongly-typed enum
authorFrancesco Chemolli <kinkie@squid-cache.org>
Sun, 2 Aug 2015 15:09:46 +0000 (17:09 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Sun, 2 Aug 2015 15:09:46 +0000 (17:09 +0200)
src/HttpHeader.cc
src/HttpHeader.h
src/HttpHeaderFieldInfo.h
src/HttpHeaderTools.cc
src/http/RegisteredHeaders.cc
src/http/RegisteredHeaders.h

index 18e00c1ece00a2dca28c14730e423c79789adcbf..8f9fc2dd837e5a84f8db3f392155f7ac66baf5dd 100644 (file)
@@ -1087,7 +1087,7 @@ void
 HttpHeader::putInt(http_hdr_type id, int number)
 {
     assert_eid(id);
-    assert(headerTable[id].type == ftInt);  /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftInt);  /* must be of an appropriate type */
     assert(number >= 0);
     addEntry(new HttpHeaderEntry(id, NULL, xitoa(number)));
 }
@@ -1096,7 +1096,7 @@ void
 HttpHeader::putInt64(http_hdr_type id, int64_t number)
 {
     assert_eid(id);
-    assert(headerTable[id].type == ftInt64);    /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftInt64);    /* must be of an appropriate type */
     assert(number >= 0);
     addEntry(new HttpHeaderEntry(id, NULL, xint64toa(number)));
 }
@@ -1105,7 +1105,7 @@ void
 HttpHeader::putTime(http_hdr_type id, time_t htime)
 {
     assert_eid(id);
-    assert(headerTable[id].type == ftDate_1123);    /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftDate_1123);    /* must be of an appropriate type */
     assert(htime >= 0);
     addEntry(new HttpHeaderEntry(id, NULL, mkrfc1123(htime)));
 }
@@ -1114,7 +1114,7 @@ void
 HttpHeader::insertTime(http_hdr_type id, time_t htime)
 {
     assert_eid(id);
-    assert(headerTable[id].type == ftDate_1123);    /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftDate_1123);    /* must be of an appropriate type */
     assert(htime >= 0);
     insertEntry(new HttpHeaderEntry(id, NULL, mkrfc1123(htime)));
 }
@@ -1123,7 +1123,7 @@ void
 HttpHeader::putStr(http_hdr_type id, const char *str)
 {
     assert_eid(id);
-    assert(headerTable[id].type == ftStr);  /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftStr);  /* must be of an appropriate type */
     assert(str);
     addEntry(new HttpHeaderEntry(id, NULL, str));
 }
@@ -1220,7 +1220,7 @@ int
 HttpHeader::getInt(http_hdr_type id) const
 {
     assert_eid(id);
-    assert(headerTable[id].type == ftInt);  /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftInt);  /* must be of an appropriate type */
     HttpHeaderEntry *e;
 
     if ((e = findEntry(id)))
@@ -1233,7 +1233,7 @@ int64_t
 HttpHeader::getInt64(http_hdr_type id) const
 {
     assert_eid(id);
-    assert(headerTable[id].type == ftInt64);    /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftInt64);    /* must be of an appropriate type */
     HttpHeaderEntry *e;
 
     if ((e = findEntry(id)))
@@ -1248,7 +1248,7 @@ HttpHeader::getTime(http_hdr_type id) const
     HttpHeaderEntry *e;
     time_t value = -1;
     assert_eid(id);
-    assert(headerTable[id].type == ftDate_1123);    /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftDate_1123);    /* must be of an appropriate type */
 
     if ((e = findEntry(id))) {
         value = parse_rfc1123(e->value.termedBuf());
@@ -1264,7 +1264,7 @@ HttpHeader::getStr(http_hdr_type id) const
 {
     HttpHeaderEntry *e;
     assert_eid(id);
-    assert(headerTable[id].type == ftStr);  /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftStr);  /* must be of an appropriate type */
 
     if ((e = findEntry(id))) {
         httpHeaderNoteParsedEntry(e->id, e->value, 0);  /* no errors are possible */
@@ -1280,7 +1280,7 @@ HttpHeader::getLastStr(http_hdr_type id) const
 {
     HttpHeaderEntry *e;
     assert_eid(id);
-    assert(headerTable[id].type == ftStr);  /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftStr);  /* must be of an appropriate type */
 
     if ((e = findLastEntry(id))) {
         httpHeaderNoteParsedEntry(e->id, e->value, 0);  /* no errors are possible */
@@ -1418,7 +1418,7 @@ HttpHeader::getETag(http_hdr_type id) const
 {
     ETag etag = {NULL, -1};
     HttpHeaderEntry *e;
-    assert(headerTable[id].type == ftETag);     /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftETag);     /* must be of an appropriate type */
 
     if ((e = findEntry(id)))
         etagParseInit(&etag, e->value.termedBuf());
@@ -1431,7 +1431,7 @@ HttpHeader::getTimeOrTag(http_hdr_type id) const
 {
     TimeOrTag tot;
     HttpHeaderEntry *e;
-    assert(headerTable[id].type == ftDate_1123_or_ETag);    /* must be of an appropriate type */
+    assert(headerTable[id].type == field_type::ftDate_1123_or_ETag);    /* must be of an appropriate type */
     memset(&tot, 0, sizeof(tot));
 
     if ((e = findEntry(id))) {
index f1b1af17fc4708c3b45bc8c846ed402a3fcae720..5ac12e3e7fd27fdbf6f2a1bc5e94ae74175a516a 100644 (file)
@@ -43,8 +43,8 @@ typedef enum {
 class HttpHeaderFieldAttrs
 {
 public:
-    HttpHeaderFieldAttrs() : name(NULL), id(HDR_BAD_HDR), type(ftInvalid) {}
-    HttpHeaderFieldAttrs(const char *aName, http_hdr_type anId, field_type aType = ftInvalid) : name(aName), id(anId), type(aType) {}
+    HttpHeaderFieldAttrs() : name(NULL), id(HDR_BAD_HDR), type(field_type::ftInvalid) {}
+    HttpHeaderFieldAttrs(const char *aName, http_hdr_type anId, field_type aType = field_type::ftInvalid) : name(aName), id(anId), type(aType) {}
 #if __cplusplus >= 201103L
     HttpHeaderFieldAttrs(const HttpHeaderFieldAttrs &) = default;
     HttpHeaderFieldAttrs(HttpHeaderFieldAttrs &&) = default;
index 2deb06191188f23fc1d4ec5b9dfdbb8b822be464..a1bd5b2a8c7eb80af842c7f2deef1f7d2bbdb974 100644 (file)
 #define SQUID_HTTPHEADERFIELDINFO_H_
 
 #include "HttpHeaderFieldStat.h"
+#include "http/RegisteredHeaders.h"
 #include "SquidString.h"
 
 /// compiled version of HttpHeaderFieldAttrs plus stats. Currently a POD.
 class HttpHeaderFieldInfo
 {
 public:
-    HttpHeaderFieldInfo() : id(HDR_ACCEPT), type(ftInvalid) {}
+    HttpHeaderFieldInfo() : id(HDR_ACCEPT), type(field_type::ftInvalid) {}
 
     http_hdr_type id;
     String name;
index 0f39f64030827fe21324448e14b6fead92ab3381..efdaaf4800bd8277ed7ff8cf0487c013ab58b504 100644 (file)
@@ -54,7 +54,7 @@ httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count)
         /* sanity checks */
         assert(id >= 0 && id < count);
         assert(attrs[i].name);
-        assert(info->id == HDR_ACCEPT && info->type == ftInvalid);  /* was not set before */
+        assert(info->id == HDR_ACCEPT && info->type == field_type::ftInvalid);  /* was not set before */
         /* copy and init fields */
         info->id = id;
         info->type = attrs[i].type;
index f03af2825f4746e895708dbdafa7d4a90e2c4cbc..368d942b8d9359242d8a7c53d68c4e4d6dee002b 100644 (file)
  * for each index in headerTable, (int)headerTable[index] = index
  */
 const HeaderTableRecord headerTable[] = {
-    {"Accept", HDR_ACCEPT, ftStr},
-    {"Accept-Charset", HDR_ACCEPT_CHARSET, ftStr},
-    {"Accept-Encoding", HDR_ACCEPT_ENCODING, ftStr},
-    {"Accept-Language", HDR_ACCEPT_LANGUAGE, ftStr},
-    {"Accept-Ranges", HDR_ACCEPT_RANGES, ftStr},
-    {"Age", HDR_AGE, ftInt},
-    {"Allow", HDR_ALLOW, ftStr},
-    {"Alternate-Protocol", HDR_ALTERNATE_PROTOCOL, ftStr},
-    {"Authentication-Info", HDR_AUTHENTICATION_INFO, ftStr},
-    {"Authorization", HDR_AUTHORIZATION, ftStr},    /* for now */
-    {"Cache-Control", HDR_CACHE_CONTROL, ftPCc},
-    {"Connection", HDR_CONNECTION, ftStr},
-    {"Content-Base", HDR_CONTENT_BASE, ftStr},
-    {"Content-Disposition", HDR_CONTENT_DISPOSITION, ftStr},  /* for now */
-    {"Content-Encoding", HDR_CONTENT_ENCODING, ftStr},
-    {"Content-Language", HDR_CONTENT_LANGUAGE, ftStr},
-    {"Content-Length", HDR_CONTENT_LENGTH, ftInt64},
-    {"Content-Location", HDR_CONTENT_LOCATION, ftStr},
-    {"Content-MD5", HDR_CONTENT_MD5, ftStr},    /* for now */
-    {"Content-Range", HDR_CONTENT_RANGE, ftPContRange},
-    {"Content-Type", HDR_CONTENT_TYPE, ftStr},
-    {"Cookie", HDR_COOKIE, ftStr},
-    {"Cookie2", HDR_COOKIE2, ftStr},
-    {"Date", HDR_DATE, ftDate_1123},
-    {"ETag", HDR_ETAG, ftETag},
-    {"Expect", HDR_EXPECT, ftStr},
-    {"Expires", HDR_EXPIRES, ftDate_1123},
-    {"Forwarded", HDR_FORWARDED, ftStr},
-    {"From", HDR_FROM, ftStr},
-    {"Host", HDR_HOST, ftStr},
-    {"HTTP2-Settings", HDR_HTTP2_SETTINGS, ftStr}, /* for now */
-    {"If-Match", HDR_IF_MATCH, ftStr},  /* for now */
-    {"If-Modified-Since", HDR_IF_MODIFIED_SINCE, ftDate_1123},
-    {"If-None-Match", HDR_IF_NONE_MATCH, ftStr},    /* for now */
-    {"If-Range", HDR_IF_RANGE, ftDate_1123_or_ETag},
-    {"If-Unmodified-Since", HDR_IF_UNMODIFIED_SINCE, ftDate_1123},
-    {"Keep-Alive", HDR_KEEP_ALIVE, ftStr},
-    {"Key", HDR_KEY, ftStr},
-    {"Last-Modified", HDR_LAST_MODIFIED, ftDate_1123},
-    {"Link", HDR_LINK, ftStr},
-    {"Location", HDR_LOCATION, ftStr},
-    {"Max-Forwards", HDR_MAX_FORWARDS, ftInt64},
-    {"Mime-Version", HDR_MIME_VERSION, ftStr},  /* for now */
-    {"Negotiate", HDR_NEGOTIATE, ftStr},
-    {"Origin", HDR_ORIGIN, ftStr},
-    {"Pragma", HDR_PRAGMA, ftStr},
-    {"Proxy-Authenticate", HDR_PROXY_AUTHENTICATE, ftStr},
-    {"Proxy-Authentication-Info", HDR_PROXY_AUTHENTICATION_INFO, ftStr},
-    {"Proxy-Authorization", HDR_PROXY_AUTHORIZATION, ftStr},
-    {"Proxy-Connection", HDR_PROXY_CONNECTION, ftStr},
-    {"Proxy-support", HDR_PROXY_SUPPORT, ftStr},
-    {"Public", HDR_PUBLIC, ftStr},
-    {"Range", HDR_RANGE, ftPRange},
-    {"Referer", HDR_REFERER, ftStr},
-    {"Request-Range", HDR_REQUEST_RANGE, ftPRange}, /* usually matches HDR_RANGE */
-    {"Retry-After", HDR_RETRY_AFTER, ftStr},    /* for now (ftDate_1123 or ftInt!} */
-    {"Server", HDR_SERVER, ftStr},
-    {"Set-Cookie", HDR_SET_COOKIE, ftStr},
-    {"Set-Cookie2", HDR_SET_COOKIE2, ftStr},
-    {"TE", HDR_TE, ftStr},
-    {"Title", HDR_TITLE, ftStr},
-    {"Trailer", HDR_TRAILER, ftStr},
-    {"Transfer-Encoding", HDR_TRANSFER_ENCODING, ftStr},
-    {"Translate", HDR_TRANSLATE, ftStr},    /* for now. may need to crop */
-    {"Unless-Modified-Since", HDR_UNLESS_MODIFIED_SINCE, ftStr},  /* for now ignore. may need to crop */
-    {"Upgrade", HDR_UPGRADE, ftStr},    /* for now */
-    {"User-Agent", HDR_USER_AGENT, ftStr},
-    {"Vary", HDR_VARY, ftStr},  /* for now */
-    {"Via", HDR_VIA, ftStr},    /* for now */
-    {"Warning", HDR_WARNING, ftStr},    /* for now */
-    {"WWW-Authenticate", HDR_WWW_AUTHENTICATE, ftStr},
-    {"X-Cache", HDR_X_CACHE, ftStr},
-    {"X-Cache-Lookup", HDR_X_CACHE_LOOKUP, ftStr},
-    {"X-Forwarded-For", HDR_X_FORWARDED_FOR, ftStr},
-    {"X-Request-URI", HDR_X_REQUEST_URI, ftStr},
-    {"X-Squid-Error", HDR_X_SQUID_ERROR, ftStr},
+    {"Accept", HDR_ACCEPT, field_type::ftStr},
+    {"Accept-Charset", HDR_ACCEPT_CHARSET, field_type::ftStr},
+    {"Accept-Encoding", HDR_ACCEPT_ENCODING, field_type::ftStr},
+    {"Accept-Language", HDR_ACCEPT_LANGUAGE, field_type::ftStr},
+    {"Accept-Ranges", HDR_ACCEPT_RANGES, field_type::ftStr},
+    {"Age", HDR_AGE, field_type::ftInt},
+    {"Allow", HDR_ALLOW, field_type::ftStr},
+    {"Alternate-Protocol", HDR_ALTERNATE_PROTOCOL, field_type::ftStr},
+    {"Authentication-Info", HDR_AUTHENTICATION_INFO, field_type::ftStr},
+    {"Authorization", HDR_AUTHORIZATION, field_type::ftStr},    /* for now */
+    {"Cache-Control", HDR_CACHE_CONTROL, field_type::ftPCc},
+    {"Connection", HDR_CONNECTION, field_type::ftStr},
+    {"Content-Base", HDR_CONTENT_BASE, field_type::ftStr},
+    {"Content-Disposition", HDR_CONTENT_DISPOSITION, field_type::ftStr},  /* for now */
+    {"Content-Encoding", HDR_CONTENT_ENCODING, field_type::ftStr},
+    {"Content-Language", HDR_CONTENT_LANGUAGE, field_type::ftStr},
+    {"Content-Length", HDR_CONTENT_LENGTH, field_type::ftInt64},
+    {"Content-Location", HDR_CONTENT_LOCATION, field_type::ftStr},
+    {"Content-MD5", HDR_CONTENT_MD5, field_type::ftStr},    /* for now */
+    {"Content-Range", HDR_CONTENT_RANGE, field_type::ftPContRange},
+    {"Content-Type", HDR_CONTENT_TYPE, field_type::ftStr},
+    {"Cookie", HDR_COOKIE, field_type::ftStr},
+    {"Cookie2", HDR_COOKIE2, field_type::ftStr},
+    {"Date", HDR_DATE, field_type::ftDate_1123},
+    {"ETag", HDR_ETAG, field_type::ftETag},
+    {"Expect", HDR_EXPECT, field_type::ftStr},
+    {"Expires", HDR_EXPIRES, field_type::ftDate_1123},
+    {"Forwarded", HDR_FORWARDED, field_type::ftStr},
+    {"From", HDR_FROM, field_type::ftStr},
+    {"Host", HDR_HOST, field_type::ftStr},
+    {"HTTP2-Settings", HDR_HTTP2_SETTINGS, field_type::ftStr}, /* for now */
+    {"If-Match", HDR_IF_MATCH, field_type::ftStr},  /* for now */
+    {"If-Modified-Since", HDR_IF_MODIFIED_SINCE, field_type::ftDate_1123},
+    {"If-None-Match", HDR_IF_NONE_MATCH, field_type::ftStr},    /* for now */
+    {"If-Range", HDR_IF_RANGE, field_type::ftDate_1123_or_ETag},
+    {"If-Unmodified-Since", HDR_IF_UNMODIFIED_SINCE, field_type::ftDate_1123},
+    {"Keep-Alive", HDR_KEEP_ALIVE, field_type::ftStr},
+    {"Key", HDR_KEY, field_type::ftStr},
+    {"Last-Modified", HDR_LAST_MODIFIED, field_type::ftDate_1123},
+    {"Link", HDR_LINK, field_type::ftStr},
+    {"Location", HDR_LOCATION, field_type::ftStr},
+    {"Max-Forwards", HDR_MAX_FORWARDS, field_type::ftInt64},
+    {"Mime-Version", HDR_MIME_VERSION, field_type::ftStr},  /* for now */
+    {"Negotiate", HDR_NEGOTIATE, field_type::ftStr},
+    {"Origin", HDR_ORIGIN, field_type::ftStr},
+    {"Pragma", HDR_PRAGMA, field_type::ftStr},
+    {"Proxy-Authenticate", HDR_PROXY_AUTHENTICATE, field_type::ftStr},
+    {"Proxy-Authentication-Info", HDR_PROXY_AUTHENTICATION_INFO, field_type::ftStr},
+    {"Proxy-Authorization", HDR_PROXY_AUTHORIZATION, field_type::ftStr},
+    {"Proxy-Connection", HDR_PROXY_CONNECTION, field_type::ftStr},
+    {"Proxy-support", HDR_PROXY_SUPPORT, field_type::ftStr},
+    {"Public", HDR_PUBLIC, field_type::ftStr},
+    {"Range", HDR_RANGE, field_type::ftPRange},
+    {"Referer", HDR_REFERER, field_type::ftStr},
+    {"Request-Range", HDR_REQUEST_RANGE, field_type::ftPRange}, /* usually matches HDR_RANGE */
+    {"Retry-Afield_type::fter", HDR_RETRY_AFTER, field_type::ftStr},    /* for now (field_type::ftDate_1123 or field_type::ftInt!} */
+    {"Server", HDR_SERVER, field_type::ftStr},
+    {"Set-Cookie", HDR_SET_COOKIE, field_type::ftStr},
+    {"Set-Cookie2", HDR_SET_COOKIE2, field_type::ftStr},
+    {"TE", HDR_TE, field_type::ftStr},
+    {"Title", HDR_TITLE, field_type::ftStr},
+    {"Trailer", HDR_TRAILER, field_type::ftStr},
+    {"Transfer-Encoding", HDR_TRANSFER_ENCODING, field_type::ftStr},
+    {"Translate", HDR_TRANSLATE, field_type::ftStr},    /* for now. may need to crop */
+    {"Unless-Modified-Since", HDR_UNLESS_MODIFIED_SINCE, field_type::ftStr},  /* for now ignore. may need to crop */
+    {"Upgrade", HDR_UPGRADE, field_type::ftStr},    /* for now */
+    {"User-Agent", HDR_USER_AGENT, field_type::ftStr},
+    {"Vary", HDR_VARY, field_type::ftStr},  /* for now */
+    {"Via", HDR_VIA, field_type::ftStr},    /* for now */
+    {"Warning", HDR_WARNING, field_type::ftStr},    /* for now */
+    {"WWW-Authenticate", HDR_WWW_AUTHENTICATE, field_type::ftStr},
+    {"X-Cache", HDR_X_CACHE, field_type::ftStr},
+    {"X-Cache-Lookup", HDR_X_CACHE_LOOKUP, field_type::ftStr},
+    {"X-Forwarded-For", HDR_X_FORWARDED_FOR, field_type::ftStr},
+    {"X-Request-URI", HDR_X_REQUEST_URI, field_type::ftStr},
+    {"X-Squid-Error", HDR_X_SQUID_ERROR, field_type::ftStr},
 #if X_ACCELERATOR_VARY
-    {"X-Accelerator-Vary", HDR_X_ACCELERATOR_VARY, ftStr},
+    {"X-Accelerator-Vary", HDR_X_ACCELERATOR_VARY, field_type::ftStr},
 #endif
 #if USE_ADAPTATION
-    {"X-Next-Services", HDR_X_NEXT_SERVICES, ftStr},
+    {"X-Next-Services", HDR_X_NEXT_SERVICES, field_type::ftStr},
 #endif
-    {"Surrogate-Capability", HDR_SURROGATE_CAPABILITY, ftStr},
-    {"Surrogate-Control", HDR_SURROGATE_CONTROL, ftPSc},
-    {"Front-End-Https", HDR_FRONT_END_HTTPS, ftStr},
-    {"FTP-Command", HDR_FTP_COMMAND, ftStr},
-    {"FTP-Arguments", HDR_FTP_ARGUMENTS, ftStr},
-    {"FTP-Pre", HDR_FTP_PRE, ftStr},
-    {"FTP-Status", HDR_FTP_STATUS, ftInt},
-    {"FTP-Reason", HDR_FTP_REASON, ftStr},
-    {"Other:", HDR_OTHER, ftStr},    /* ':' will not allow matches */
-    {nullptr, HDR_BAD_HDR}    /* end of table */
+    {"Surrogate-Capability", HDR_SURROGATE_CAPABILITY, field_type::ftStr},
+    {"Surrogate-Control", HDR_SURROGATE_CONTROL, field_type::ftPSc},
+    {"Front-End-Https", HDR_FRONT_END_HTTPS, field_type::ftStr},
+    {"FTP-Command", HDR_FTP_COMMAND, field_type::ftStr},
+    {"FTP-Arguments", HDR_FTP_ARGUMENTS, field_type::ftStr},
+    {"FTP-Pre", HDR_FTP_PRE, field_type::ftStr},
+    {"FTP-Status", HDR_FTP_STATUS, field_type::ftInt},
+    {"FTP-Reason", HDR_FTP_REASON, field_type::ftStr},
+    {"Other:", HDR_OTHER, field_type::ftStr},    /* ':' will not allow matches */
+    {nullptr, HDR_BAD_HDR, field_type::ftInvalid}    /* end of table */
 };
index b44c37be519778225f271baf06dc0cbadccc3ea1..41474a46de2b61ff5d625beb2859ac36a240c04e 100644 (file)
@@ -121,8 +121,8 @@ typedef enum {
 
 /** possible types for http header fields */
 //TODO: move to strongly-typed enums? (enum class)
-typedef enum {
-    ftInvalid = HDR_ENUM_END,   /**< to catch nasty errors with hdr_id<->fld_type clashes */
+enum class field_type {
+    ftInvalid,// = HDR_ENUM_END,   /**< to catch nasty errors with hdr_id<->fld_type clashes */
     ftInt,
     ftInt64,
     ftStr,
@@ -133,7 +133,7 @@ typedef enum {
     ftPRange,
     ftPSc,
     ftDate_1123_or_ETag
-} field_type;
+};
 
 /* POD for headerTable */
 class HeaderTableRecord {