3 * $Id: HttpMsg.h,v 1.15 2007/04/06 04:50:04 rousskov Exp $
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
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.
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.
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.
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.
34 #ifndef SQUID_HTTPMSG_H
35 #define SQUID_HTTPMSG_H
38 #include "HttpHeader.h"
39 #include "HttpVersion.h"
42 // common parts of HttpRequest and HttpReply
48 HttpMsg(http_hdr_owner_type owner
);
51 virtual void reset() = 0; // will have body when http*Clean()s are gone
53 void packInto(Packer
* p
, bool full_uri
) const;
55 virtual HttpMsg
*_lock(); // please use HTTPMSGLOCK()
56 virtual void _unlock(); // please use HTTPMSGUNLOCK()
63 HttpHdrCc
*cache_control
;
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 */
74 HttpMsgParseState pstate
; /* the current parsing state */
76 BodyPipe::Pointer body_pipe
; // optional pipeline to receive message body
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
);
83 bool parseCharBuf(const char *buf
, ssize_t end
);
85 int httpMsgParseStep(const char *buf
, int len
, int atEnd
);
87 virtual int httpMsgParseError();
89 virtual bool expectingBody(method_t
, ssize_t
&) const = 0;
91 void firstLineBuf(MemBuf
&);
94 virtual bool sanityCheckStartLine(MemBuf
*buf
, http_status
*error
) = 0;
96 virtual void packFirstLineInto(Packer
* p
, bool full_uri
) const = 0;
98 virtual bool parseFirstLine(const char *blk_start
, const char *blk_end
) = 0;
100 virtual void hdrCacheInit();
106 /* Temporary parsing state; might turn into the replacement parser later on */
111 int req_start
, req_end
;
112 int hdr_start
, hdr_end
;
118 typedef struct _HttpParser HttpParser
;
120 extern void HttpParserInit(HttpParser
*, const char *buf
, int len
);
121 extern int HttpParserParseReqLine(HttpParser
*hp
);
125 extern int HttpParserReqSz(HttpParser
*);
126 extern int HttpParserHdrSz(HttpParser
*);
127 extern const char * HttpParserHdrBuf(HttpParser
*);
128 extern int HttpParserRequestLen(HttpParser
*hp
);
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 )
136 SQUIDCEXTERN
int httpMsgIsolateHeaders(const char **parse_start
, int len
, const char **blk_start
, const char **blk_end
);
138 #define HTTPMSGUNLOCK(a) if(a){(a)->_unlock();(a)=NULL;}
139 #define HTTPMSGLOCK(a) (a)->_lock()
141 #endif /* SQUID_HTTPMSG_H */