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