/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "HttpHeaderFieldStat.h"
#include "HttpHeaderStat.h"
#include "HttpHeaderTools.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
#include "StatHist.h"
#include "Store.h"
#include "StrList.h"
{"min-fresh", HttpHdrCcType::CC_MIN_FRESH},
{"only-if-cached", HttpHdrCcType::CC_ONLY_IF_CACHED},
{"stale-if-error", HttpHdrCcType::CC_STALE_IF_ERROR},
+ {"immutable", HttpHdrCcType::CC_IMMUTABLE},
{"Other,", HttpHdrCcType::CC_OTHER}, /* ',' will protect from matches */
{nullptr, HttpHdrCcType::CC_ENUM_END}
};
std::vector<HttpHeaderFieldStat> ccHeaderStats(HttpHdrCcType::CC_ENUM_END);
/// used to walk a table of http_header_cc_type structs
-HttpHdrCcType &operator++ (HttpHdrCcType &aHeader)
+static HttpHdrCcType &
+operator++ (HttpHdrCcType &aHeader)
{
int tmp = (int)aHeader;
aHeader = (HttpHdrCcType)(++tmp);
{
// check invariant on initialization table
for (unsigned int j = 0; CcAttrs[j].name != nullptr; ++j) {
- assert (static_cast<int>(CcAttrs[j].id) == j);
+ assert(static_cast<decltype(j)>(CcAttrs[j].id) == j);
}
}
*this=HttpHdrCc();
}
+/// set a data member to a new value, and set the corresponding mask-bit.
+/// if setting is false, then the mask-bit is cleared.
+void
+HttpHdrCc::setValue(int32_t &value, int32_t new_value, HttpHdrCcType hdr, bool setting)
+{
+ if (setting) {
+ if (new_value < 0) {
+ debugs(65, 3, "rejecting negative-value Cache-Control directive " << hdr
+ << " value " << new_value);
+ return;
+ }
+ } else {
+ new_value = -1; //rely on the convention that "unknown" is -1
+ }
+
+ value = new_value;
+ setMask(hdr,setting);
+}
+
bool
HttpHdrCc::parse(const String & str)
{
const char *item;
const char *p; /* '=' parameter */
- const char *pos = NULL;
+ const char *pos = nullptr;
int ilen;
int nlen;
case HttpHdrCcType::CC_ONLY_IF_CACHED:
onlyIfCached(true);
break;
+ case HttpHdrCcType::CC_IMMUTABLE:
+ Immutable(true);
+ break;
case HttpHdrCcType::CC_OTHER:
if (other.size())
if (isSet(flag) && flag != HttpHdrCcType::CC_OTHER) {
/* print option name for all options */
- p->appendf((pcount ? ", %s": "%s") , CcAttrs[flag].name);
+ p->appendf((pcount ? ", %s": "%s"), CcAttrs[flag].name);
/* for all options having values, "=value" after the name */
switch (flag) {
+ case HttpHdrCcType::CC_PUBLIC:
+ break;
+ case HttpHdrCcType::CC_PRIVATE:
+ if (private_.size())
+ p->appendf("=\"" SQUIDSTRINGPH "\"", SQUIDSTRINGPRINT(private_));
+ break;
+
+ case HttpHdrCcType::CC_NO_CACHE:
+ if (no_cache.size())
+ p->appendf("=\"" SQUIDSTRINGPH "\"", SQUIDSTRINGPRINT(no_cache));
+ break;
+ case HttpHdrCcType::CC_NO_STORE:
+ break;
+ case HttpHdrCcType::CC_NO_TRANSFORM:
+ break;
+ case HttpHdrCcType::CC_MUST_REVALIDATE:
+ break;
+ case HttpHdrCcType::CC_PROXY_REVALIDATE:
+ break;
case HttpHdrCcType::CC_MAX_AGE:
- p->appendf("=%d", maxAge());
+ p->appendf("=%d", max_age);
break;
case HttpHdrCcType::CC_S_MAXAGE:
- p->appendf("=%d", sMaxAge());
+ p->appendf("=%d", s_maxage);
break;
case HttpHdrCcType::CC_MAX_STALE:
/* max-stale's value is optional.
If we didn't receive it, don't send it */
- if (maxStale()!=MAX_STALE_ANY)
- p->appendf("=%d", maxStale());
+ if (max_stale != MAX_STALE_ANY)
+ p->appendf("=%d", max_stale);
break;
case HttpHdrCcType::CC_MIN_FRESH:
- p->appendf("=%d", minFresh());
+ p->appendf("=%d", min_fresh);
+ break;
+ case HttpHdrCcType::CC_ONLY_IF_CACHED:
+ break;
+ case HttpHdrCcType::CC_STALE_IF_ERROR:
+ p->appendf("=%d", stale_if_error);
break;
- default:
- /* do nothing, directive was already printed */
+ case HttpHdrCcType::CC_IMMUTABLE:
+ break;
+ case HttpHdrCcType::CC_OTHER:
+ case HttpHdrCcType::CC_ENUM_END:
+ // done below after the loop
break;
}
{
extern const HttpHeaderStat *dump_stat; /* argh! */
const int id = static_cast<int>(val);
- const bool valid_id = id < HttpHdrCcType::CC_ENUM_END;
+ const bool valid_id = id >= 0 && id < static_cast<int>(HttpHdrCcType::CC_ENUM_END);
const char *name = valid_id ? CcAttrs[id].name : "INVALID";
if (count || valid_id)
return s;
}
-#if !_USE_INLINE_
-#include "HttpHdrCc.cci"
-#endif
-