]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpMsg.h
- ICAP-unrelated improvements from the squid3-icap branch on SF
[thirdparty/squid.git] / src / HttpMsg.h
1
2 /*
3 * $Id: HttpMsg.h,v 1.15 2007/04/06 04:50:04 rousskov 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 public:
59 HttpVersion http_ver;
60
61 HttpHeader header;
62
63 HttpHdrCc *cache_control;
64
65 /* Unsupported, writable, may disappear/change in the future
66 * For replies, sums _stored_ status-line, headers, and <CRLF>.
67 * Also used to report parsed header size if parse() is successful */
68 int hdr_sz;
69
70 int content_length;
71
72 protocol_t protocol;
73
74 HttpMsgParseState pstate; /* the current parsing state */
75
76 BodyPipe::Pointer body_pipe; // optional pipeline to receive message body
77
78 // returns true and sets hdr_sz on success
79 // returns false and sets *error to zero when needs more data
80 // returns false and sets *error to a positive http_status code on error
81 bool parse(MemBuf *buf, bool eol, http_status *error);
82
83 bool parseCharBuf(const char *buf, ssize_t end);
84
85 int httpMsgParseStep(const char *buf, int len, int atEnd);
86
87 virtual int httpMsgParseError();
88
89 virtual bool expectingBody(method_t, ssize_t&) const = 0;
90
91 void firstLineBuf(MemBuf&);
92
93 protected:
94 virtual bool sanityCheckStartLine(MemBuf *buf, http_status *error) = 0;
95
96 virtual void packFirstLineInto(Packer * p, bool full_uri) const = 0;
97
98 virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
99
100 virtual void hdrCacheInit();
101
102 int lock_count;
103
104 };
105
106 /* Temporary parsing state; might turn into the replacement parser later on */
107 struct _HttpParser {
108 char state;
109 const char *buf;
110 int bufsiz;
111 int req_start, req_end;
112 int hdr_start, hdr_end;
113 int m_start, m_end;
114 int u_start, u_end;
115 int v_start, v_end;
116 int v_maj, v_min;
117 };
118 typedef struct _HttpParser HttpParser;
119
120 extern void HttpParserInit(HttpParser *, const char *buf, int len);
121 extern int HttpParserParseReqLine(HttpParser *hp);
122
123 #define MSGDODEBUG 0
124 #if MSGDODEBUG
125 extern int HttpParserReqSz(HttpParser *);
126 extern int HttpParserHdrSz(HttpParser *);
127 extern const char * HttpParserHdrBuf(HttpParser *);
128 extern int HttpParserRequestLen(HttpParser *hp);
129 #else
130 #define HttpParserReqSz(hp) ( (hp)->req_end - (hp)->req_start + 1 )
131 #define HttpParserHdrSz(hp) ( (hp)->hdr_end - (hp)->hdr_start + 1 )
132 #define HttpParserHdrBuf(hp) ( (hp)->buf + (hp)->hdr_start )
133 #define HttpParserRequestLen(hp) ( (hp)->hdr_end - (hp)->req_start + 1 )
134 #endif
135
136 SQUIDCEXTERN int httpMsgIsolateHeaders(const char **parse_start, int len, const char **blk_start, const char **blk_end);
137
138 #define HTTPMSGUNLOCK(a) if(a){(a)->_unlock();(a)=NULL;}
139 #define HTTPMSGLOCK(a) (a)->_lock()
140
141 #endif /* SQUID_HTTPMSG_H */