RegisteredHeaders.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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(""), id(HdrType::BAD_HDR), type(HdrFieldType::ftInvalid),
22  list(false), request(false), reply(false), hopbyhop(false), denied304(false)
23 {}
24 
26  name(n), id(HdrType::BAD_HDR), type(HdrFieldType::ftInvalid),
27  list(false), request(false), reply(false), hopbyhop(false), denied304(false)
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 {}
36 
37 const HeaderTableRecord&
38 HeaderLookupTable_t::lookup (const char *buf, const std::size_t len) const {
40  if (!r)
41  return BadHdr;
42  return *r;
43 }
45 
47 {
48  initCache();
49 }
50 
51 void
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)] =
59  }
60  }
61  //check after the fact. The cache array must be full
62  for (auto e : idCache) {
63  assert(e->name);
64  }
65 }
67 
68 }; /* namespace Http */
69 
70 std::ostream&
71 operator<< (std::ostream &s, Http::HdrType id)
72 {
74  s << Http::HeaderLookupTable.lookup(id).name << '[' << static_cast<int>(id) << ']';
75  else
76  s << "Invalid-Header[" << static_cast<int>(id) << ']';
77  return s;
78 }
79 
std::vector< const HeaderTableRecord * > idCache
static const HeaderTableRecord BadHdr
used to signal "not found" from lookups
#define assert(EX)
Definition: assert.h:17
static const struct HeaderTableRecord * lookup(const char *str, unsigned int len)
int type
Definition: errorpage.cc:79
bool any_HdrType_enum_value(const Http::HdrType id)
match any known header type, including OTHER and BAD
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
const HeaderTableRecord & lookup(const char *buf, const std::size_t len) const
look record type up by name (C-string and length)
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void const char * buf
Definition: stub_helper.cc:16
const HeaderLookupTable_t HeaderLookupTable
int const char size_t
Definition: stub_liblog.cc:84
std::ostream & operator<<(std::ostream &s, Http::HdrType id)
#define false
Definition: GnuRegex.c:233
static const struct HeaderTableRecord HttpHeaderDefinitionsTable[]

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors