]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpMsg.h
Merged from trunk.
[thirdparty/squid.git] / src / HttpMsg.h
1
2 /*
3 * $Id: HttpMsg.h,v 1.17 2008/01/20 08:54:28 amosjeffries Exp $
4 *
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 */
33
34 #ifndef SQUID_HTTPMSG_H
35 #define SQUID_HTTPMSG_H
36
37 #include "typedefs.h"
38 #include "HttpHeader.h"
39 #include "HttpVersion.h"
40 #include "BodyPipe.h"
41
42 // common parts of HttpRequest and HttpReply
43
44 class HttpMsg
45 {
46
47 public:
48 HttpMsg(http_hdr_owner_type owner);
49 virtual ~HttpMsg();
50
51 virtual void reset() = 0; // will have body when http*Clean()s are gone
52
53 void packInto(Packer * p, bool full_uri) const;
54
55 virtual HttpMsg *_lock(); // please use HTTPMSGLOCK()
56 virtual void _unlock(); // please use HTTPMSGUNLOCK()
57
58 virtual HttpMsg *clone() const = 0;
59
60 public:
61 HttpVersion http_ver;
62
63 HttpHeader header;
64
65 HttpHdrCc *cache_control;
66
67 /* Unsupported, writable, may disappear/change in the future
68 * For replies, sums _stored_ status-line, headers, and <CRLF>.
69 * Also used to report parsed header size if parse() is successful */
70 int hdr_sz;
71
72 int64_t content_length;
73
74 protocol_t protocol;
75
76 HttpMsgParseState pstate; /* the current parsing state */
77
78 BodyPipe::Pointer body_pipe; // optional pipeline to receive message body
79
80 // returns true and sets hdr_sz on success
81 // returns false and sets *error to zero when needs more data
82 // returns false and sets *error to a positive http_status code on error
83 bool parse(MemBuf *buf, bool eol, http_status *error);
84
85 bool parseCharBuf(const char *buf, ssize_t end);
86
87 int httpMsgParseStep(const char *buf, int len, int atEnd);
88
89 virtual int httpMsgParseError();
90
91 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0;
92
93 void firstLineBuf(MemBuf&);
94
95 protected:
96 virtual bool sanityCheckStartLine(MemBuf *buf, http_status *error) = 0;
97
98 virtual void packFirstLineInto(Packer * p, bool full_uri) const = 0;
99
100 virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
101
102 virtual void hdrCacheInit();
103
104 int lock_count;
105
106 };
107
108 /* Temporary parsing state; might turn into the replacement parser later on */
109 struct _HttpParser {
110 char state;
111 const char *buf;
112 int bufsiz;
113 int req_start, req_end;
114 int hdr_start, hdr_end;
115 int m_start, m_end;
116 int u_start, u_end;
117 int v_start, v_end;
118 int v_maj, v_min;
119 };
120 typedef struct _HttpParser HttpParser;
121
122 extern void HttpParserInit(HttpParser *, const char *buf, int len);
123 extern int HttpParserParseReqLine(HttpParser *hp);
124
125 #define MSGDODEBUG 0
126 #if MSGDODEBUG
127 extern int HttpParserReqSz(HttpParser *);
128 extern int HttpParserHdrSz(HttpParser *);
129 extern const char * HttpParserHdrBuf(HttpParser *);
130 extern int HttpParserRequestLen(HttpParser *hp);
131 #else
132 #define HttpParserReqSz(hp) ( (hp)->req_end - (hp)->req_start + 1 )
133 #define HttpParserHdrSz(hp) ( (hp)->hdr_end - (hp)->hdr_start + 1 )
134 #define HttpParserHdrBuf(hp) ( (hp)->buf + (hp)->hdr_start )
135 #define HttpParserRequestLen(hp) ( (hp)->hdr_end - (hp)->req_start + 1 )
136 #endif
137
138 SQUIDCEXTERN int httpMsgIsolateHeaders(const char **parse_start, int len, const char **blk_start, const char **blk_end);
139
140 #define HTTPMSGUNLOCK(a) if(a){(a)->_unlock();(a)=NULL;}
141 #define HTTPMSGLOCK(a) (a)->_lock()
142
143 #endif /* SQUID_HTTPMSG_H */