]>
| Commit | Line | Data |
|---|---|---|
| e3f110af | 1 | /* |
| 1f7b830e | 2 | * Copyright (C) 1996-2025 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 | ||
| 81ab22b6 | 20 | HeaderTableRecord::HeaderTableRecord(const char *n) : |
| 8b082ed9 | 21 | name(n) |
| 81ab22b6 FC |
22 | {} |
| 23 | ||
| 24 | HeaderTableRecord::HeaderTableRecord(const char *n, HdrType theId, HdrFieldType theType, int theKind) : | |
| 25 | name(n), id(theId), type(theType), | |
| 26 | list(theKind & HdrKind::ListHeader), request(theKind & HdrKind::RequestHeader), | |
| 27 | reply(theKind & HdrKind::ReplyHeader), hopbyhop(theKind & HdrKind::HopByHopHeader), | |
| 28 | denied304(theKind & HdrKind::Denied304Header) | |
| 29 | {} | |
| f7ad4af5 | 30 | |
| 81ab22b6 FC |
31 | const HeaderTableRecord& |
| 32 | HeaderLookupTable_t::lookup (const char *buf, const std::size_t len) const { | |
| 33 | const HeaderTableRecord *r = HttpHeaderHashTable::lookup(buf, len); | |
| 05182492 | 34 | if (!r || r->id == Http::HdrType::OTHER) |
| 81ab22b6 FC |
35 | return BadHdr; |
| 36 | return *r; | |
| 37 | } | |
| 38 | const HeaderTableRecord HeaderLookupTable_t::BadHdr {"*INVALID*:", Http::HdrType::BAD_HDR, Http::HdrFieldType::ftInvalid, HdrKind::None}; | |
| 39 | ||
| 40 | HeaderLookupTable_t::HeaderLookupTable_t() | |
| 41 | { | |
| 42 | initCache(); | |
| 43 | } | |
| 44 | ||
| 45 | void | |
| 46 | HeaderLookupTable_t::initCache() | |
| 47 | { | |
| 48 | idCache.resize(TOTAL_KEYWORDS); | |
| 49 | for (int j = MIN_HASH_VALUE; j <= MAX_HASH_VALUE; ++j) { //MAX_HASH_VALUE is exported by gperf | |
| 50 | if (HttpHeaderDefinitionsTable[j].name[0] != '\0') { //some slots are empty | |
| 51 | idCache[static_cast<int>(HttpHeaderDefinitionsTable[j].id)] = | |
| 52 | & HttpHeaderDefinitionsTable[j]; | |
| 53 | } | |
| 54 | } | |
| 55 | //check after the fact. The cache array must be full | |
| 56 | for (auto e : idCache) { | |
| 57 | assert(e->name); | |
| 58 | } | |
| 59 | } | |
| 60 | const HeaderLookupTable_t HeaderLookupTable; | |
| 92991271 FC |
61 | |
| 62 | }; /* namespace Http */ | |
| 789217a2 | 63 | |
| 2c20b348 | 64 | std::ostream& |
| 25ecffe5 | 65 | Http::operator<< (std::ostream &s, const HdrType id) |
| 2c20b348 | 66 | { |
| 25ecffe5 AR |
67 | if (any_HdrType_enum_value(id)) |
| 68 | s << HeaderLookupTable.lookup(id).name << '[' << static_cast<int>(id) << ']'; | |
| 5308d137 SM |
69 | else |
| 70 | s << "Invalid-Header[" << static_cast<int>(id) << ']'; | |
| 71 | return s; | |
| 2c20b348 | 72 | } |
| 5308d137 | 73 |