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