]>
Commit | Line | Data |
---|---|---|
e6ccf245 | 1 | /* |
262a0e14 | 2 | * $Id$ |
e6ccf245 | 3 | * |
4 | * | |
5 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
6 | * ---------------------------------------------------------- | |
7 | * | |
8 | * Squid is the result of efforts by numerous individuals from | |
9 | * the Internet community; see the CONTRIBUTORS file for full | |
10 | * details. Many organizations have provided support for Squid's | |
11 | * development; see the SPONSORS file for full details. Squid is | |
12 | * Copyrighted (C) 2001 by the Regents of the University of | |
13 | * California; see the COPYRIGHT file for full details. Squid | |
14 | * incorporates software developed and/or copyrighted by other | |
15 | * sources; see the CREDITS file for full details. | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or modify | |
18 | * it under the terms of the GNU General Public License as published by | |
19 | * the Free Software Foundation; either version 2 of the License, or | |
20 | * (at your option) any later version. | |
26ac0430 | 21 | * |
e6ccf245 | 22 | * This program is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26ac0430 | 26 | * |
e6ccf245 | 27 | * You should have received a copy of the GNU General Public License |
28 | * along with this program; if not, write to the Free Software | |
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
30 | * | |
31 | */ | |
32 | ||
33 | #ifndef SQUID_HTTPHEADER_H | |
34 | #define SQUID_HTTPHEADER_H | |
35 | ||
528b2c61 | 36 | /* because we pass a spec by value */ |
37 | #include "HttpHeaderRange.h" | |
25b6a907 | 38 | /* HttpHeader holds a HttpHeaderMask */ |
39 | #include "HttpHeaderMask.h" | |
e6ccf245 | 40 | |
696a257c FC |
41 | |
42 | /* class forward declarations */ | |
696a257c FC |
43 | class HttpHdrContRange; |
44 | class HttpHdrCc; | |
45 | class HttpHdrSc; | |
46 | class HttpHdrRange; | |
47 | class String; | |
48 | ||
49 | ||
e6ccf245 | 50 | /* constant attributes of http header fields */ |
62e76326 | 51 | |
63be0a78 | 52 | /** recognized or "known" header fields; @?@ add more! */ |
25b6a907 | 53 | typedef enum { |
54 | HDR_BAD_HDR = -1, | |
55 | HDR_ACCEPT = 0, | |
56 | HDR_ACCEPT_CHARSET, | |
57 | HDR_ACCEPT_ENCODING, | |
58 | HDR_ACCEPT_LANGUAGE, | |
59 | HDR_ACCEPT_RANGES, | |
60 | HDR_AGE, | |
61 | HDR_ALLOW, | |
62 | HDR_AUTHORIZATION, | |
63 | HDR_CACHE_CONTROL, | |
64 | HDR_CONNECTION, | |
65 | HDR_CONTENT_BASE, | |
a585e13d | 66 | HDR_CONTENT_DISPOSITION, |
25b6a907 | 67 | HDR_CONTENT_ENCODING, |
68 | HDR_CONTENT_LANGUAGE, | |
69 | HDR_CONTENT_LENGTH, | |
70 | HDR_CONTENT_LOCATION, | |
71 | HDR_CONTENT_MD5, | |
72 | HDR_CONTENT_RANGE, | |
73 | HDR_CONTENT_TYPE, | |
74 | HDR_COOKIE, | |
75 | HDR_DATE, | |
76 | HDR_ETAG, | |
77 | HDR_EXPIRES, | |
52b601ff | 78 | HDR_EXPECT, |
25b6a907 | 79 | HDR_FROM, |
80 | HDR_HOST, | |
81 | HDR_IF_MATCH, | |
82 | HDR_IF_MODIFIED_SINCE, | |
83 | HDR_IF_NONE_MATCH, | |
84 | HDR_IF_RANGE, | |
1d7ab0f4 | 85 | HDR_KEEP_ALIVE, |
25b6a907 | 86 | HDR_LAST_MODIFIED, |
87 | HDR_LINK, | |
88 | HDR_LOCATION, | |
89 | HDR_MAX_FORWARDS, | |
90 | HDR_MIME_VERSION, | |
91 | HDR_PRAGMA, | |
92 | HDR_PROXY_AUTHENTICATE, | |
93 | HDR_PROXY_AUTHENTICATION_INFO, | |
94 | HDR_PROXY_AUTHORIZATION, | |
95 | HDR_PROXY_CONNECTION, | |
d67acb4e | 96 | HDR_PROXY_SUPPORT, |
25b6a907 | 97 | HDR_PUBLIC, |
98 | HDR_RANGE, | |
63be0a78 | 99 | HDR_REQUEST_RANGE, /**< some clients use this, sigh */ |
25b6a907 | 100 | HDR_REFERER, |
101 | HDR_RETRY_AFTER, | |
102 | HDR_SERVER, | |
103 | HDR_SET_COOKIE, | |
1d7ab0f4 | 104 | HDR_TE, |
25b6a907 | 105 | HDR_TITLE, |
a1651bad | 106 | HDR_TRAILER, |
25b6a907 | 107 | HDR_TRANSFER_ENCODING, |
af48ea68 AJ |
108 | HDR_TRANSLATE, /* IIS custom header we may need to cut off */ |
109 | HDR_UNLESS_MODIFIED_SINCE, /* IIS custom header we may need to cut off */ | |
25b6a907 | 110 | HDR_UPGRADE, |
111 | HDR_USER_AGENT, | |
112 | HDR_VARY, | |
113 | HDR_VIA, | |
114 | HDR_WARNING, | |
115 | HDR_WWW_AUTHENTICATE, | |
116 | HDR_AUTHENTICATION_INFO, | |
117 | HDR_X_CACHE, | |
63be0a78 | 118 | HDR_X_CACHE_LOOKUP, /**< tmp hack, remove later */ |
25b6a907 | 119 | HDR_X_FORWARDED_FOR, |
63be0a78 | 120 | HDR_X_REQUEST_URI, /**< appended if ADD_X_REQUEST_URI is #defined */ |
25b6a907 | 121 | HDR_X_SQUID_ERROR, |
122 | HDR_NEGOTIATE, | |
123 | #if X_ACCELERATOR_VARY | |
124 | HDR_X_ACCELERATOR_VARY, | |
a22e6cd3 AR |
125 | #endif |
126 | #if USE_ADAPTATION | |
127 | HDR_X_NEXT_SERVICES, | |
25b6a907 | 128 | #endif |
129 | HDR_SURROGATE_CAPABILITY, | |
130 | HDR_SURROGATE_CONTROL, | |
131 | HDR_FRONT_END_HTTPS, | |
132 | HDR_OTHER, | |
133 | HDR_ENUM_END | |
134 | } http_hdr_type; | |
135 | ||
63be0a78 | 136 | /** possible types for http header fields */ |
25b6a907 | 137 | typedef enum { |
63be0a78 | 138 | ftInvalid = HDR_ENUM_END, /**< to catch nasty errors with hdr_id<->fld_type clashes */ |
25b6a907 | 139 | ftInt, |
47f6e231 | 140 | ftInt64, |
25b6a907 | 141 | ftStr, |
142 | ftDate_1123, | |
143 | ftETag, | |
144 | ftPCc, | |
145 | ftPContRange, | |
146 | ftPRange, | |
147 | ftPSc, | |
148 | ftDate_1123_or_ETag | |
149 | } field_type; | |
150 | ||
63be0a78 | 151 | /** Possible owners of http header */ |
25b6a907 | 152 | typedef enum { |
0b57cb3d | 153 | hoNone =0, |
25b6a907 | 154 | #if USE_HTCP |
155 | hoHtcpReply, | |
156 | #endif | |
157 | hoRequest, | |
158 | hoReply | |
159 | } http_hdr_owner_type; | |
160 | ||
26ac0430 | 161 | struct _HttpHeaderFieldAttrs { |
e6ccf245 | 162 | const char *name; |
163 | http_hdr_type id; | |
164 | field_type type; | |
165 | }; | |
166 | ||
a9925b40 | 167 | |
63be0a78 | 168 | /** Iteration for headers; use HttpHeaderPos as opaque type, do not interpret */ |
985c86bc | 169 | typedef ssize_t HttpHeaderPos; |
170 | ||
171 | /* use this and only this to initialize HttpHeaderPos */ | |
172 | #define HttpHeaderInitPos (-1) | |
173 | ||
174 | /* these two are defined in structs.h */ | |
175 | ||
e1f7507e | 176 | /// \todo CLEANUP: Kill this. |
985c86bc | 177 | typedef struct _TimeOrTag TimeOrTag; |
178 | ||
e1f7507e | 179 | /// \todo CLEANUP: Kill this. |
985c86bc | 180 | typedef struct _ETag ETag; |
181 | ||
eede25e7 | 182 | class HttpHeaderEntry |
183 | { | |
184 | ||
185 | public: | |
eede25e7 | 186 | HttpHeaderEntry(http_hdr_type id, const char *name, const char *value); |
187 | ~HttpHeaderEntry(); | |
cdce6c61 | 188 | static HttpHeaderEntry *parse(const char *field_start, const char *field_end); |
eede25e7 | 189 | HttpHeaderEntry *clone() const; |
190 | void packInto(Packer *p) const; | |
191 | int getInt() const; | |
47f6e231 | 192 | int64_t getInt64() const; |
eede25e7 | 193 | MEMPROXY_CLASS(HttpHeaderEntry); |
194 | http_hdr_type id; | |
30abd221 | 195 | String name; |
196 | String value; | |
eede25e7 | 197 | }; |
198 | ||
63be0a78 | 199 | MEMPROXY_CLASS_INLINE(HttpHeaderEntry); |
eede25e7 | 200 | |
924f73bc | 201 | class HttpHeader |
202 | { | |
203 | ||
204 | public: | |
75faaa7a | 205 | HttpHeader(); |
206 | HttpHeader(http_hdr_owner_type const &owner); | |
207 | ~HttpHeader(); | |
924f73bc | 208 | /* Interface functions */ |
519e0948 | 209 | void clean(); |
a9925b40 | 210 | void append(const HttpHeader * src); |
211 | void update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask); | |
394499bd | 212 | void compact(); |
a9925b40 | 213 | int reset(); |
214 | int parse(const char *header_start, const char *header_end); | |
215 | void packInto(Packer * p) const; | |
216 | HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const; | |
217 | HttpHeaderEntry *findEntry(http_hdr_type id) const; | |
218 | int delByName(const char *name); | |
219 | int delById(http_hdr_type id); | |
ba9fb01d | 220 | void delAt(HttpHeaderPos pos, int &headers_deleted); |
221 | void refreshMask(); | |
a9925b40 | 222 | void addEntry(HttpHeaderEntry * e); |
223 | void insertEntry(HttpHeaderEntry * e); | |
30abd221 | 224 | String getList(http_hdr_type id) const; |
225 | bool getList(http_hdr_type id, String *s) const; | |
226 | String getStrOrList(http_hdr_type id) const; | |
227 | String getByName(const char *name) const; | |
228 | String getByNameListMember(const char *name, const char *member, const char separator) const; | |
229 | String getListMember(http_hdr_type id, const char *member, const char separator) const; | |
a9925b40 | 230 | int has(http_hdr_type id) const; |
231 | void putInt(http_hdr_type id, int number); | |
47f6e231 | 232 | void putInt64(http_hdr_type id, int64_t number); |
a9925b40 | 233 | void putTime(http_hdr_type id, time_t htime); |
234 | void insertTime(http_hdr_type id, time_t htime); | |
235 | void putStr(http_hdr_type id, const char *str); | |
236 | void putAuth(const char *auth_scheme, const char *realm); | |
237 | void putCc(const HttpHdrCc * cc); | |
238 | void putContRange(const HttpHdrContRange * cr); | |
239 | void putRange(const HttpHdrRange * range); | |
240 | void putSc(HttpHdrSc *sc); | |
241 | void putExt(const char *name, const char *value); | |
242 | int getInt(http_hdr_type id) const; | |
47f6e231 | 243 | int64_t getInt64(http_hdr_type id) const; |
a9925b40 | 244 | time_t getTime(http_hdr_type id) const; |
245 | const char *getStr(http_hdr_type id) const; | |
246 | const char *getLastStr(http_hdr_type id) const; | |
247 | HttpHdrCc *getCc() const; | |
248 | HttpHdrRange *getRange() const; | |
249 | HttpHdrSc *getSc() const; | |
250 | HttpHdrContRange *getContRange() const; | |
251 | const char *getAuth(http_hdr_type id, const char *auth_scheme) const; | |
252 | ETag getETag(http_hdr_type id) const; | |
253 | TimeOrTag getTimeOrTag(http_hdr_type id) const; | |
254 | int hasListMember(http_hdr_type id, const char *member, const char separator) const; | |
255 | int hasByNameListMember(const char *name, const char *member, const char separator) const; | |
2cdeea82 | 256 | void removeHopByHopEntries(); |
63be0a78 | 257 | |
924f73bc | 258 | /* protected, do not use these, use interface functions instead */ |
63be0a78 | 259 | Vector<HttpHeaderEntry *> entries; /**< parsed fields in raw format */ |
260 | HttpHeaderMask mask; /**< bit set <=> entry present */ | |
261 | http_hdr_owner_type owner; /**< request or reply */ | |
d85b8894 | 262 | int len; /**< length when packed, not counting terminating null-byte */ |
a9925b40 | 263 | |
2cdeea82 | 264 | protected: |
63be0a78 | 265 | /** \deprecated Public access replaced by removeHopByHopEntries() */ |
2cdeea82 | 266 | void removeConnectionHeaderEntries(); |
63be0a78 | 267 | |
a9925b40 | 268 | private: |
269 | HttpHeaderEntry *findLastEntry(http_hdr_type id) const; | |
63be0a78 | 270 | /// Made it non-copyable. Our destructor is a bit nasty... |
6e26baea | 271 | HttpHeader(const HttpHeader &); |
272 | //assignment is used by the reset method, can't block it.. | |
273 | //const HttpHeader operator=(const HttpHeader &); | |
924f73bc | 274 | }; |
528b2c61 | 275 | |
62ee09ca | 276 | |
30abd221 | 277 | extern int httpHeaderParseQuotedString (const char *start, String *val); |
25b6a907 | 278 | SQUIDCEXTERN int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator); |
279 | SQUIDCEXTERN void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask); | |
25b6a907 | 280 | SQUIDCEXTERN void httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count); |
281 | ||
e6ccf245 | 282 | #endif /* SQUID_HTTPHEADER_H */ |