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