]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeaderTools.h
Remove no longer needed includes of typedefs.h
[thirdparty/squid.git] / src / HttpHeaderTools.h
1 /*
2 * Copyright (C) 1996-2015 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 #ifndef SQUID_HTTPHEADERTOOLS_H
10 #define SQUID_HTTPHEADERTOOLS_H
11
12 #include "acl/forward.h"
13 #include "format/Format.h"
14 #include "HttpHeader.h"
15
16 #include <functional>
17 #include <list>
18 #include <map>
19 #include <string>
20 #if HAVE_STRINGS_H
21 #include <strings.h>
22 #endif
23
24 class HeaderWithAcl;
25 class HttpHeader;
26 class HttpRequest;
27 class StoreEntry;
28 class String;
29
30 typedef std::list<HeaderWithAcl> HeaderWithAclList;
31
32 // Currently a POD
33 class headerMangler
34 {
35 public:
36 acl_access *access_list;
37 char *replacement;
38 };
39
40 /// A collection of headerMangler objects for a given message kind.
41 class HeaderManglers
42 {
43 public:
44 HeaderManglers();
45 ~HeaderManglers();
46
47 /// returns a header mangler for field e or nil if none was specified
48 const headerMangler *find(const HttpHeaderEntry &e) const;
49
50 /// returns a mangler for the named header (known or custom)
51 headerMangler *track(const char *name);
52
53 /// updates mangler for the named header with a replacement value
54 void setReplacement(const char *name, const char *replacementValue);
55
56 /// report the *_header_access part of the configuration
57 void dumpAccess(StoreEntry *entry, const char *optionName) const;
58 /// report the *_header_replace part of the configuration
59 void dumpReplacement(StoreEntry *entry, const char *optionName) const;
60
61 private:
62 /// Case-insensitive std::string "less than" comparison functor.
63 /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
64 class NoCaseLessThan: public std::binary_function<std::string, std::string, bool>
65 {
66 public:
67 bool operator()(const std::string &lhs, const std::string &rhs) const {
68 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
69 }
70 };
71
72 /// a name:mangler map; optimize: use unordered map or some such
73 typedef std::map<std::string, headerMangler, NoCaseLessThan> ManglersByName;
74
75 /// one mangler for each known header
76 headerMangler known[static_cast<int>(Http::HdrType::ENUM_END)];
77
78 /// one mangler for each custom header
79 ManglersByName custom;
80
81 /// configured if some mangling ACL applies to all header names
82 headerMangler all;
83
84 private:
85 /* not implemented */
86 HeaderManglers(const HeaderManglers &);
87 HeaderManglers &operator =(const HeaderManglers &);
88 };
89
90 class HeaderWithAcl
91 {
92 public:
93 HeaderWithAcl() : aclList(NULL), valueFormat(NULL), fieldId(Http::HdrType::BAD_HDR), quoted(false) {}
94
95 /// HTTP header field name
96 std::string fieldName;
97
98 /// HTTP header field value, possibly with macros
99 std::string fieldValue;
100
101 /// when the header field should be added (always if nil)
102 ACLList *aclList;
103
104 /// compiled HTTP header field value (no macros)
105 Format::Format *valueFormat;
106
107 /// internal ID for "known" headers or HDR_OTHER
108 Http::HdrType fieldId;
109
110 /// whether fieldValue may contain macros
111 bool quoted;
112 };
113
114 int httpHeaderParseOffset(const char *start, int64_t * off);
115
116 int httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive);
117 int httpHeaderParseInt(const char *start, int *val);
118 void httpHeaderPutStrf(HttpHeader * hdr, Http::HdrType id, const char *fmt,...) PRINTF_FORMAT_ARG3;
119
120 const char *getStringPrefix(const char *str, size_t len);
121
122 void httpHdrMangleList(HttpHeader *, HttpRequest *, int req_or_rep);
123
124 #endif
125