]>
Commit | Line | Data |
---|---|---|
e3f110af | 1 | /* |
f6e9a3ee | 2 | * Copyright (C) 1996-2019 The Squid Software Foundation and contributors |
e3f110af FC |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
9 | #include "squid.h" | |
10 | #include "RegisteredHeaders.h" | |
11 | ||
789217a2 | 12 | #include <ostream> |
81ab22b6 | 13 | #include <vector> |
789217a2 | 14 | |
92991271 FC |
15 | namespace Http |
16 | { | |
81ab22b6 FC |
17 | /* glue to code generated by gperf */ |
18 | #include "http/RegisteredHeadersHash.cci" | |
19 | ||
20 | HeaderTableRecord::HeaderTableRecord() : | |
b3d7a073 AJ |
21 | name(""), id(HdrType::BAD_HDR), type(HdrFieldType::ftInvalid), |
22 | list(false), request(false), reply(false), hopbyhop(false), denied304(false) | |
81ab22b6 FC |
23 | {} |
24 | ||
25 | HeaderTableRecord::HeaderTableRecord(const char *n) : | |
26 | name(n), id(HdrType::BAD_HDR), type(HdrFieldType::ftInvalid), | |
b3d7a073 | 27 | list(false), request(false), reply(false), hopbyhop(false), denied304(false) |
81ab22b6 FC |
28 | {} |
29 | ||
30 | HeaderTableRecord::HeaderTableRecord(const char *n, HdrType theId, HdrFieldType theType, int theKind) : | |
31 | name(n), id(theId), type(theType), | |
32 | list(theKind & HdrKind::ListHeader), request(theKind & HdrKind::RequestHeader), | |
33 | reply(theKind & HdrKind::ReplyHeader), hopbyhop(theKind & HdrKind::HopByHopHeader), | |
34 | denied304(theKind & HdrKind::Denied304Header) | |
35 | {} | |
f7ad4af5 | 36 | |
81ab22b6 FC |
37 | const HeaderTableRecord& |
38 | HeaderLookupTable_t::lookup (const char *buf, const std::size_t len) const { | |
39 | const HeaderTableRecord *r = HttpHeaderHashTable::lookup(buf, len); | |
40 | if (!r) | |
41 | return BadHdr; | |
42 | return *r; | |
43 | } | |
44 | const HeaderTableRecord HeaderLookupTable_t::BadHdr {"*INVALID*:", Http::HdrType::BAD_HDR, Http::HdrFieldType::ftInvalid, HdrKind::None}; | |
45 | ||
46 | HeaderLookupTable_t::HeaderLookupTable_t() | |
47 | { | |
48 | initCache(); | |
49 | } | |
50 | ||
51 | void | |
52 | HeaderLookupTable_t::initCache() | |
53 | { | |
54 | idCache.resize(TOTAL_KEYWORDS); | |
55 | for (int j = MIN_HASH_VALUE; j <= MAX_HASH_VALUE; ++j) { //MAX_HASH_VALUE is exported by gperf | |
56 | if (HttpHeaderDefinitionsTable[j].name[0] != '\0') { //some slots are empty | |
57 | idCache[static_cast<int>(HttpHeaderDefinitionsTable[j].id)] = | |
58 | & HttpHeaderDefinitionsTable[j]; | |
59 | } | |
60 | } | |
61 | //check after the fact. The cache array must be full | |
62 | for (auto e : idCache) { | |
63 | assert(e->name); | |
64 | } | |
65 | } | |
66 | const HeaderLookupTable_t HeaderLookupTable; | |
92991271 FC |
67 | |
68 | }; /* namespace Http */ | |
789217a2 | 69 | |
2c20b348 FC |
70 | std::ostream& |
71 | operator<< (std::ostream &s, Http::HdrType id) | |
72 | { | |
5308d137 | 73 | if (Http::any_HdrType_enum_value(id)) |
81ab22b6 | 74 | s << Http::HeaderLookupTable.lookup(id).name << '[' << static_cast<int>(id) << ']'; |
5308d137 SM |
75 | else |
76 | s << "Invalid-Header[" << static_cast<int>(id) << ']'; | |
77 | return s; | |
2c20b348 | 78 | } |
5308d137 | 79 |