#include "squid.h"
#include "AccessLogEntry.h"
#include "acl/Checklist.h"
+#include "sbuf/Algorithms.h"
#if USE_ADAPTATION
#include "adaptation/Config.h"
#endif
+#include "base/PackableStream.h"
#include "CachePeer.h"
#include "error/Detail.h"
#include "errorpage.h"
#include "MemBuf.h"
#include "mgr/Registration.h"
#include "rfc1738.h"
+#include "sbuf/SBuf.h"
#include "SquidConfig.h"
#include "SquidTime.h"
#include "Store.h"
#include "eui/Eui64.h"
#endif
+#include <unordered_map>
+
#if HEADERS_LOG
static Logfile *headerslog = NULL;
#endif
hash_link hash;
int n;
} fvdb_entry;
-static hash_table *via_table = NULL;
+
+using HeaderValueCountsElement = std::pair<SBuf, uint64_t>;
+/// counts the number of header field value occurrences
+using HeaderValueCounts = std::unordered_map<SBuf, uint64_t, std::hash<SBuf>, std::equal_to<SBuf>, PoolingAllocator<HeaderValueCountsElement> >;
+
+/// counts the number of HTTP Via header field value occurrences
+static HeaderValueCounts TheViaCounts;
+
static hash_table *forw_table = NULL;
static void fvdbInit();
static void fvdbDumpTable(StoreEntry * e, hash_table * hash);
static void
fvdbInit(void)
{
- via_table = hash_create((HASHCMP *) strcmp, 977, hash4);
forw_table = hash_create((HASHCMP *) strcmp, 977, hash4);
}
}
void
-fvdbCountVia(const char *key)
+fvdbCountVia(const SBuf &headerValue)
{
- fvdbCount(via_table, key);
+ ++TheViaCounts[headerValue];
}
void
}
}
+static void
+fvdbDumpCounts(StoreEntry &e, const HeaderValueCounts &counts)
+{
+ PackableStream os(e);
+ for (const auto &i : counts)
+ os << std::setw(9) << i.second << ' ' << i.first << "\n";
+}
+
static void
fvdbDumpVia(StoreEntry * e)
{
- fvdbDumpTable(e, via_table);
+ assert(e);
+ fvdbDumpCounts(*e, TheViaCounts);
}
static void
static void
fvdbClear(void)
{
- hashFreeItems(via_table, fvdbFreeEntry);
- hashFreeMemory(via_table);
- via_table = hash_create((HASHCMP *) strcmp, 977, hash4);
+ TheViaCounts.clear();
hashFreeItems(forw_table, fvdbFreeEntry);
hashFreeMemory(forw_table);
forw_table = hash_create((HASHCMP *) strcmp, 977, hash4);