RegisteredHeaders.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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 
12 #include <ostream>
13 #include <vector>
14 
15 namespace Http
16 {
17 /* glue to code generated by gperf */
19 
21  name(n)
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 {}
30 
31 const HeaderTableRecord&
32 HeaderLookupTable_t::lookup (const char *buf, const std::size_t len) const {
34  if (!r || r->id == Http::HdrType::OTHER)
35  return BadHdr;
36  return *r;
37 }
38 const HeaderTableRecord HeaderLookupTable_t::BadHdr {"*INVALID*:", Http::HdrType::BAD_HDR, Http::HdrFieldType::ftInvalid, HdrKind::None};
39 
41 {
42  initCache();
43 }
44 
45 void
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)] =
53  }
54  }
55  //check after the fact. The cache array must be full
56  for (auto e : idCache) {
57  assert(e->name);
58  }
59 }
61 
62 }; /* namespace Http */
63 
64 std::ostream&
65 operator<< (std::ostream &s, Http::HdrType id)
66 {
68  s << Http::HeaderLookupTable.lookup(id).name << '[' << static_cast<int>(id) << ']';
69  else
70  s << "Invalid-Header[" << static_cast<int>(id) << ']';
71  return s;
72 }
73 
@ MAX_HASH_VALUE
@ TOTAL_KEYWORDS
int type
Definition: errorpage.cc:153
std::vector< const HeaderTableRecord * > idCache
Definition: forward.h:22
int const char size_t
Definition: stub_liblog.cc:86
std::ostream & operator<<(std::ostream &s, Http::HdrType id)
bool any_HdrType_enum_value(const Http::HdrType id)
match any known header type, including OTHER and BAD
static const HeaderTableRecord BadHdr
used to signal "not found" from lookups
#define assert(EX)
Definition: assert.h:19
@ MIN_HASH_VALUE
const HeaderTableRecord & lookup(const char *buf, const std::size_t len) const
look record type up by name (C-string and length)
const HeaderLookupTable_t HeaderLookupTable
static const class HeaderTableRecord HttpHeaderDefinitionsTable[]
static StatHist s
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
static const class HeaderTableRecord * lookup(const char *str, size_t len)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors