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