]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpMsg.h
Real: Fix NO DEFAULT compile errors
[thirdparty/squid.git] / src / HttpMsg.h
CommitLineData
f1974911 1
2/*
60745f24 3 * $Id: HttpMsg.h,v 1.17 2008/01/20 08:54:28 amosjeffries Exp $
f1974911 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"
5f8252d2 40#include "BodyPipe.h"
f1974911 41
42// common parts of HttpRequest and HttpReply
43
44class HttpMsg
45{
46
47public:
48 HttpMsg(http_hdr_owner_type owner);
4a56ee8d 49 virtual ~HttpMsg();
f1974911 50
51 virtual void reset() = 0; // will have body when http*Clean()s are gone
52
f1974911 53 void packInto(Packer * p, bool full_uri) const;
54
6dd9f4bd 55 virtual HttpMsg *_lock(); // please use HTTPMSGLOCK()
56 virtual void _unlock(); // please use HTTPMSGUNLOCK()
4a56ee8d 57
fa0e6114
AR
58 ///< produce a message copy, except for a few connection-specific settings
59 virtual HttpMsg *clone() const = 0; ///< \todo rename: not a true copy?
60
f1974911 61public:
62 HttpVersion http_ver;
4a56ee8d 63
f1974911 64 HttpHeader header;
65
66 HttpHdrCc *cache_control;
67
68 /* Unsupported, writable, may disappear/change in the future
69 * For replies, sums _stored_ status-line, headers, and <CRLF>.
70 * Also used to report parsed header size if parse() is successful */
71 int hdr_sz;
72
47f6e231 73 int64_t content_length;
4a56ee8d 74
f1974911 75 protocol_t protocol;
76
e3ab4be3 77 HttpMsgParseState pstate; /* the current parsing state */
4a56ee8d 78
5f8252d2 79 BodyPipe::Pointer body_pipe; // optional pipeline to receive message body
80
e3ab4be3 81 // returns true and sets hdr_sz on success
82 // returns false and sets *error to zero when needs more data
83 // returns false and sets *error to a positive http_status code on error
f1974911 84 bool parse(MemBuf *buf, bool eol, http_status *error);
4a56ee8d 85
59eed7dc 86 bool parseCharBuf(const char *buf, ssize_t end);
4a56ee8d 87
666f514b 88 int httpMsgParseStep(const char *buf, int len, int atEnd);
4a56ee8d 89
fb525683 90 virtual int httpMsgParseError();
4a56ee8d 91
60745f24 92 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0;
e3ab4be3 93
4a56ee8d 94 void firstLineBuf(MemBuf&);
f1974911 95
96protected:
e3ab4be3 97 virtual bool sanityCheckStartLine(MemBuf *buf, http_status *error) = 0;
4a56ee8d 98
f1974911 99 virtual void packFirstLineInto(Packer * p, bool full_uri) const = 0;
4a56ee8d 100
429f7150 101 virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
4a56ee8d 102
07947ad8 103 virtual void hdrCacheInit();
3cfc19b3 104
4a56ee8d 105 int lock_count;
3cfc19b3 106
f1974911 107};
108
a5baffba 109/* Temporary parsing state; might turn into the replacement parser later on */
110struct _HttpParser {
111 char state;
112 const char *buf;
113 int bufsiz;
a5baffba 114 int req_start, req_end;
115 int hdr_start, hdr_end;
84cc2635 116 int m_start, m_end;
117 int u_start, u_end;
118 int v_start, v_end;
119 int v_maj, v_min;
a5baffba 120};
121typedef struct _HttpParser HttpParser;
122
123extern void HttpParserInit(HttpParser *, const char *buf, int len);
52512f28 124extern int HttpParserParseReqLine(HttpParser *hp);
125
4c29340e 126#define MSGDODEBUG 0
52512f28 127#if MSGDODEBUG
a5baffba 128extern int HttpParserReqSz(HttpParser *);
129extern int HttpParserHdrSz(HttpParser *);
130extern const char * HttpParserHdrBuf(HttpParser *);
131extern int HttpParserRequestLen(HttpParser *hp);
52512f28 132#else
133#define HttpParserReqSz(hp) ( (hp)->req_end - (hp)->req_start + 1 )
134#define HttpParserHdrSz(hp) ( (hp)->hdr_end - (hp)->hdr_start + 1 )
135#define HttpParserHdrBuf(hp) ( (hp)->buf + (hp)->hdr_start )
136#define HttpParserRequestLen(hp) ( (hp)->hdr_end - (hp)->req_start + 1 )
137#endif
f1974911 138
666f514b 139SQUIDCEXTERN int httpMsgIsolateHeaders(const char **parse_start, int len, const char **blk_start, const char **blk_end);
f1974911 140
6dd9f4bd 141#define HTTPMSGUNLOCK(a) if(a){(a)->_unlock();(a)=NULL;}
142#define HTTPMSGLOCK(a) (a)->_lock()
143
f1974911 144#endif /* SQUID_HTTPMSG_H */