]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeader.h
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / HttpHeader.h
1 /*
2 * $Id$
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.
21 *
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.
26 *
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
36
37 /* because we pass a spec by value */
38 #include "HttpHeaderRange.h"
39 /* HttpHeader holds a HttpHeaderMask */
40 #include "HttpHeaderMask.h"
41
42 /* constant attributes of http header fields */
43
44 /** recognized or "known" header fields; @?@ add more! */
45 typedef enum {
46 HDR_BAD_HDR = -1,
47 HDR_ACCEPT = 0,
48 HDR_ACCEPT_CHARSET,
49 HDR_ACCEPT_ENCODING,
50 HDR_ACCEPT_LANGUAGE,
51 HDR_ACCEPT_RANGES,
52 HDR_AGE,
53 HDR_ALLOW,
54 HDR_AUTHORIZATION,
55 HDR_CACHE_CONTROL,
56 HDR_CONNECTION,
57 HDR_CONTENT_BASE,
58 HDR_CONTENT_ENCODING,
59 HDR_CONTENT_LANGUAGE,
60 HDR_CONTENT_LENGTH,
61 HDR_CONTENT_LOCATION,
62 HDR_CONTENT_MD5,
63 HDR_CONTENT_RANGE,
64 HDR_CONTENT_TYPE,
65 HDR_COOKIE,
66 HDR_DATE,
67 HDR_ETAG,
68 HDR_EXPIRES,
69 HDR_FROM,
70 HDR_HOST,
71 HDR_IF_MATCH,
72 HDR_IF_MODIFIED_SINCE,
73 HDR_IF_NONE_MATCH,
74 HDR_IF_RANGE,
75 HDR_KEEP_ALIVE,
76 HDR_LAST_MODIFIED,
77 HDR_LINK,
78 HDR_LOCATION,
79 HDR_MAX_FORWARDS,
80 HDR_MIME_VERSION,
81 HDR_PRAGMA,
82 HDR_PROXY_AUTHENTICATE,
83 HDR_PROXY_AUTHENTICATION_INFO,
84 HDR_PROXY_AUTHORIZATION,
85 HDR_PROXY_CONNECTION,
86 HDR_PROXY_SUPPORT,
87 HDR_PUBLIC,
88 HDR_RANGE,
89 HDR_REQUEST_RANGE, /**< some clients use this, sigh */
90 HDR_REFERER,
91 HDR_RETRY_AFTER,
92 HDR_SERVER,
93 HDR_SET_COOKIE,
94 HDR_TE,
95 HDR_TITLE,
96 HDR_TRAILERS,
97 HDR_TRANSFER_ENCODING,
98 HDR_UPGRADE,
99 HDR_USER_AGENT,
100 HDR_VARY,
101 HDR_VIA,
102 HDR_WARNING,
103 HDR_WWW_AUTHENTICATE,
104 HDR_AUTHENTICATION_INFO,
105 HDR_X_CACHE,
106 HDR_X_CACHE_LOOKUP, /**< tmp hack, remove later */
107 HDR_X_FORWARDED_FOR,
108 HDR_X_REQUEST_URI, /**< appended if ADD_X_REQUEST_URI is #defined */
109 HDR_X_SQUID_ERROR,
110 HDR_NEGOTIATE,
111 #if X_ACCELERATOR_VARY
112 HDR_X_ACCELERATOR_VARY,
113 #endif
114 HDR_SURROGATE_CAPABILITY,
115 HDR_SURROGATE_CONTROL,
116 HDR_FRONT_END_HTTPS,
117 HDR_OTHER,
118 HDR_ENUM_END
119 } http_hdr_type;
120
121 /** possible types for http header fields */
122 typedef enum {
123 ftInvalid = HDR_ENUM_END, /**< to catch nasty errors with hdr_id<->fld_type clashes */
124 ftInt,
125 ftInt64,
126 ftStr,
127 ftDate_1123,
128 ftETag,
129 ftPCc,
130 ftPContRange,
131 ftPRange,
132 ftPSc,
133 ftDate_1123_or_ETag
134 } field_type;
135
136 /** Possible owners of http header */
137 typedef enum {
138 hoNone =0,
139 #if USE_HTCP
140 hoHtcpReply,
141 #endif
142 hoRequest,
143 hoReply
144 } http_hdr_owner_type;
145
146 struct _HttpHeaderFieldAttrs {
147 const char *name;
148 http_hdr_type id;
149 field_type type;
150 };
151
152 class HttpVersion;
153
154 class HttpHdrContRange;
155
156 class HttpHdrCc;
157
158 class HttpHdrSc;
159
160 /** Iteration for headers; use HttpHeaderPos as opaque type, do not interpret */
161 typedef ssize_t HttpHeaderPos;
162
163 /* use this and only this to initialize HttpHeaderPos */
164 #define HttpHeaderInitPos (-1)
165
166 /* these two are defined in structs.h */
167
168 /// \todo CLEANUP: Kill this.
169 typedef struct _TimeOrTag TimeOrTag;
170
171 /// \todo CLEANUP: Kill this.
172 typedef struct _ETag ETag;
173
174 class HttpHeaderEntry
175 {
176
177 public:
178 HttpHeaderEntry(http_hdr_type id, const char *name, const char *value);
179 ~HttpHeaderEntry();
180 static HttpHeaderEntry *parse(const char *field_start, const char *field_end);
181 HttpHeaderEntry *clone() const;
182 void packInto(Packer *p) const;
183 int getInt() const;
184 int64_t getInt64() const;
185 MEMPROXY_CLASS(HttpHeaderEntry);
186 http_hdr_type id;
187 String name;
188 String value;
189 };
190
191 MEMPROXY_CLASS_INLINE(HttpHeaderEntry);
192
193 class HttpHeader
194 {
195
196 public:
197 HttpHeader();
198 HttpHeader(http_hdr_owner_type const &owner);
199 ~HttpHeader();
200 /* Interface functions */
201 void clean();
202 void append(const HttpHeader * src);
203 void update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask);
204 void compact();
205 int reset();
206 int parse(const char *header_start, const char *header_end);
207 void packInto(Packer * p) const;
208 HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const;
209 HttpHeaderEntry *findEntry(http_hdr_type id) const;
210 int delByName(const char *name);
211 int delById(http_hdr_type id);
212 void delAt(HttpHeaderPos pos, int &headers_deleted);
213 void refreshMask();
214 void addEntry(HttpHeaderEntry * e);
215 void insertEntry(HttpHeaderEntry * e);
216 String getList(http_hdr_type id) const;
217 bool getList(http_hdr_type id, String *s) const;
218 String getStrOrList(http_hdr_type id) const;
219 String getByName(const char *name) const;
220 String getByNameListMember(const char *name, const char *member, const char separator) const;
221 String getListMember(http_hdr_type id, const char *member, const char separator) const;
222 int has(http_hdr_type id) const;
223 void putInt(http_hdr_type id, int number);
224 void putInt64(http_hdr_type id, int64_t number);
225 void putTime(http_hdr_type id, time_t htime);
226 void insertTime(http_hdr_type id, time_t htime);
227 void putStr(http_hdr_type id, const char *str);
228 void putAuth(const char *auth_scheme, const char *realm);
229 void putCc(const HttpHdrCc * cc);
230 void putContRange(const HttpHdrContRange * cr);
231 void putRange(const HttpHdrRange * range);
232 void putSc(HttpHdrSc *sc);
233 void putExt(const char *name, const char *value);
234 int getInt(http_hdr_type id) const;
235 int64_t getInt64(http_hdr_type id) const;
236 time_t getTime(http_hdr_type id) const;
237 const char *getStr(http_hdr_type id) const;
238 const char *getLastStr(http_hdr_type id) const;
239 HttpHdrCc *getCc() const;
240 HttpHdrRange *getRange() const;
241 HttpHdrSc *getSc() const;
242 HttpHdrContRange *getContRange() const;
243 const char *getAuth(http_hdr_type id, const char *auth_scheme) const;
244 ETag getETag(http_hdr_type id) const;
245 TimeOrTag getTimeOrTag(http_hdr_type id) const;
246 int hasListMember(http_hdr_type id, const char *member, const char separator) const;
247 int hasByNameListMember(const char *name, const char *member, const char separator) const;
248 void removeHopByHopEntries();
249
250 /* protected, do not use these, use interface functions instead */
251 Vector<HttpHeaderEntry *> entries; /**< parsed fields in raw format */
252 HttpHeaderMask mask; /**< bit set <=> entry present */
253 http_hdr_owner_type owner; /**< request or reply */
254 int len; /**< length when packed, not counting terminating '\0' */
255
256 protected:
257 /** \deprecated Public access replaced by removeHopByHopEntries() */
258 void removeConnectionHeaderEntries();
259
260 private:
261 HttpHeaderEntry *findLastEntry(http_hdr_type id) const;
262 /// Made it non-copyable. Our destructor is a bit nasty...
263 HttpHeader(const HttpHeader &);
264 //assignment is used by the reset method, can't block it..
265 //const HttpHeader operator=(const HttpHeader &);
266 };
267
268
269 extern int httpHeaderParseQuotedString (const char *start, String *val);
270 SQUIDCEXTERN int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator);
271 SQUIDCEXTERN void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask);
272 int httpMsgIsPersistent(HttpVersion const &http_ver, const HttpHeader * hdr);
273
274 SQUIDCEXTERN void httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count);
275
276 #endif /* SQUID_HTTPHEADER_H */