5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
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.
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.
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.
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.
33 #ifndef SQUID_HTTPMSG_H
34 #define SQUID_HTTPMSG_H
37 #include "HttpHeader.h"
38 #include "HttpRequestMethod.h"
39 #include "HttpStatusCode.h"
40 #include "HttpVersion.h"
43 // common parts of HttpRequest and HttpReply
46 class HttpMsgPointerT
;
53 typedef HttpMsgPointerT
<HttpMsg
> Pointer
;
55 HttpMsg(http_hdr_owner_type owner
);
58 virtual void reset() = 0; // will have body when http*Clean()s are gone
60 void packInto(Packer
* p
, bool full_uri
) const;
62 virtual HttpMsg
*_lock(); // please use HTTPMSGLOCK()
63 virtual void _unlock(); // please use HTTPMSGUNLOCK()
65 ///< produce a message copy, except for a few connection-specific settings
66 virtual HttpMsg
*clone() const = 0; ///< \todo rename: not a true copy?
68 /// [re]sets Content-Length header and cached value
69 void setContentLength(int64_t clen
);
72 * \retval true the message sender asks to keep the connection open.
73 * \retval false the message sender will close the connection.
75 * Factors other than the headers may result in connection closure.
77 bool persistent() const;
84 HttpHdrCc
*cache_control
;
86 /* Unsupported, writable, may disappear/change in the future
87 * For replies, sums _stored_ status-line, headers, and <CRLF>.
88 * Also used to report parsed header size if parse() is successful */
91 int64_t content_length
;
93 AnyP::ProtocolType protocol
;
95 HttpMsgParseState pstate
; /* the current parsing state */
97 BodyPipe::Pointer body_pipe
; // optional pipeline to receive message body
99 // returns true and sets hdr_sz on success
100 // returns false and sets *error to zero when needs more data
101 // returns false and sets *error to a positive http_status code on error
102 bool parse(MemBuf
*buf
, bool eol
, http_status
*error
);
104 bool parseCharBuf(const char *buf
, ssize_t end
);
106 int httpMsgParseStep(const char *buf
, int len
, int atEnd
);
108 virtual int httpMsgParseError();
110 virtual bool expectingBody(const HttpRequestMethod
&, int64_t&) const = 0;
112 void firstLineBuf(MemBuf
&);
114 virtual bool inheritProperties(const HttpMsg
*aMsg
) = 0;
118 * Validate the message start line is syntactically correct.
119 * Set HTTP error status according to problems found.
121 * \retval true Status line has no serious problems.
122 * \retval false Status line has a serious problem. Correct response is indicated by error.
124 virtual bool sanityCheckStartLine(MemBuf
*buf
, const size_t hdr_len
, http_status
*error
) = 0;
126 virtual void packFirstLineInto(Packer
* p
, bool full_uri
) const = 0;
128 virtual bool parseFirstLine(const char *blk_start
, const char *blk_end
) = 0;
130 virtual void hdrCacheInit();
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 // TODO: replace HTTPMSGLOCK with general RefCounting and delete this class
142 /// safe HttpMsg pointer wrapper that locks and unlocks the message
144 class HttpMsgPointerT
147 HttpMsgPointerT(): msg(NULL
) {}
148 explicit HttpMsgPointerT(Msg
*m
): msg(m
) { lock(); }
149 virtual ~HttpMsgPointerT() { unlock(); }
151 HttpMsgPointerT(const HttpMsgPointerT
&p
): msg(p
.msg
) { lock(); }
152 HttpMsgPointerT
&operator =(const HttpMsgPointerT
&p
)
153 { if (msg
!= p
.msg
) { unlock(); msg
= p
.msg
; lock(); } return *this; }
154 HttpMsgPointerT
&operator =(Msg
*newM
)
155 { if (msg
!= newM
) { unlock(); msg
= newM
; lock(); } return *this; }
157 /// support converting a child msg pointer into a parent msg pointer
158 template <typename Other
>
159 HttpMsgPointerT(const HttpMsgPointerT
<Other
> &o
): msg(o
.raw()) { lock(); }
161 /// support assigning a child msg pointer to a parent msg pointer
162 template <typename Other
>
163 HttpMsgPointerT
&operator =(const HttpMsgPointerT
<Other
> &o
)
164 { if (msg
!= o
.raw()) { unlock(); msg
= o
.raw(); lock(); } return *this; }
166 Msg
&operator *() { return *msg
; }
167 const Msg
&operator *() const { return *msg
; }
168 Msg
*operator ->() { return msg
; }
169 const Msg
*operator ->() const { return msg
; }
170 operator Msg
*() const { return msg
; }
171 // add more as needed
173 /// public access for HttpMsgPointerT copying and assignment; avoid
174 Msg
*raw() const { return msg
; }
177 void lock() { if (msg
) HTTPMSGLOCK(msg
); } ///< prevent msg destruction
178 void unlock() { HTTPMSGUNLOCK(msg
); } ///< allows/causes msg destruction
184 /// convenience wrapper to create HttpMsgPointerT<> object based on msg type
187 HttpMsgPointerT
<Msg
> HttpMsgPointer(Msg
*msg
)
189 return HttpMsgPointerT
<Msg
>(msg
);
192 #endif /* SQUID_HTTPMSG_H */