]> git.ipfire.org Git - thirdparty/squid.git/blame - src/http/Message.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / http / Message.h
CommitLineData
f1974911 1/*
5b74111a 2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
f1974911 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
f1974911 7 */
8
63df1d28
AJ
9#ifndef SQUID_HTTP_MESSAGE_H
10#define SQUID_HTTP_MESSAGE_H
f1974911 11
5444ee48
AJ
12#include "base/Lock.h"
13#include "BodyPipe.h"
e1ba42a4 14#include "enums.h"
f35c0145 15#include "http/forward.h"
602d9612
A
16#include "http/ProtocolVersion.h"
17#include "http/StatusCode.h"
f1974911 18#include "HttpHeader.h"
f1974911 19
63df1d28 20namespace Http
f1974911 21{
22
63df1d28
AJ
23/// common parts of HttpRequest and HttpReply
24class Message : public RefCountable
25{
f1974911 26public:
88df846b
CT
27 /// Who may have created or modified this message?
28 enum Sources {
29 srcUnknown = 0,
30
31 /* flags in 0xFFFF zone are for "secure" or "encrypted" sources */
32 srcHttps = 1 << 0, ///< https_port or bumped http_port tunnel; HTTPS server
33 srcFtps = 1 << 1, ///< ftps_port or SFTP server; currently unused
34 srcIcaps = 1 << 2, ///< Secure ICAP service
35 srcEcaps = 1 << 3, ///< eCAP service that is considered secure; currently unused
36
37 /* these flags "taint" the message: it may have been observed or mangled outside Squid */
38 srcHttp = 1 << (16 + 0), ///< http_port or HTTP server
39 srcFtp = 1 << (16 + 1), ///< ftp_port or FTP server
40 srcIcap = 1 << (16 + 2), ///< traditional ICAP service without encryption
41 srcEcap = 1 << (16 + 3), ///< eCAP service that uses insecure libraries/daemons
42 srcGopher = 1 << (16 + 14), ///< Gopher server
43 srcWhois = 1 << (16 + 15), ///< Whois server
44 srcUnsafe = 0xFFFF0000, ///< Unsafe sources mask
45 srcSafe = 0x0000FFFF ///< Safe sources mask
46 };
db260341 47
63df1d28
AJ
48 Message(http_hdr_owner_type);
49 virtual ~Message();
f1974911 50
51 virtual void reset() = 0; // will have body when http*Clean()s are gone
52
63df1d28 53 void packInto(Packable *, bool full_uri) const;
f1974911 54
26ac0430 55 ///< produce a message copy, except for a few connection-specific settings
63df1d28 56 virtual Http::Message *clone() const = 0; // TODO rename: not a true copy?
fa0e6114 57
3ff65596 58 /// [re]sets Content-Length header and cached value
63df1d28 59 void setContentLength(int64_t);
3ff65596 60
cb1f4d34 61 /**
4a1acc56
AJ
62 * \retval true the message sender asks to keep the connection open.
63 * \retval false the message sender will close the connection.
64 *
65 * Factors other than the headers may result in connection closure.
66 */
67 bool persistent() const;
68
f1974911 69public:
4e3f4dc7 70 /// HTTP-Version field in the first line of the message.
bf484584 71 /// see RFC 7230 section 3.1
2592bc70 72 AnyP::ProtocolVersion http_ver;
4a56ee8d 73
f1974911 74 HttpHeader header;
75
63df1d28 76 HttpHdrCc *cache_control = nullptr;
f1974911 77
78 /* Unsupported, writable, may disappear/change in the future
79 * For replies, sums _stored_ status-line, headers, and <CRLF>.
80 * Also used to report parsed header size if parse() is successful */
63df1d28 81 int hdr_sz = 0;
f1974911 82
63df1d28 83 int64_t content_length = 0;
4a56ee8d 84
fb654382
AJ
85 /// parse state of HttpReply or HttpRequest
86 enum ParseState {
87 psReadyToParseStartLine = 0,
88 psReadyToParseHeaders,
89 psParsed,
90 psError
91 };
92
63df1d28 93 /// the current parsing state
fb654382 94 ParseState pstate = Http::Message::psReadyToParseStartLine;
4a56ee8d 95
63df1d28
AJ
96 /// optional pipeline to receive message body
97 BodyPipe::Pointer body_pipe;
5f8252d2 98
63df1d28 99 uint32_t sources = 0; ///< The message sources
88df846b 100
0c90d3b1
DD
101 /// copies Cache-Control header to this message
102 void putCc(const HttpHdrCc *otherCc);
103
e3ab4be3 104 // returns true and sets hdr_sz on success
105 // returns false and sets *error to zero when needs more data
955394ce 106 // returns false and sets *error to a positive Http::StatusCode on error
84ae6223 107 bool parse(const char *buf, const size_t sz, bool eol, Http::StatusCode *error);
4a56ee8d 108
59eed7dc 109 bool parseCharBuf(const char *buf, ssize_t end);
4a56ee8d 110
666f514b 111 int httpMsgParseStep(const char *buf, int len, int atEnd);
4a56ee8d 112
fb525683 113 virtual int httpMsgParseError();
4a56ee8d 114
af2980f3
AJ
115 // Parser-NG transitional parsing of mime headers
116 bool parseHeader(Http1::Parser &); // TODO move this function to the parser
117
60745f24 118 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0;
e3ab4be3 119
4a56ee8d 120 void firstLineBuf(MemBuf&);
26ac0430 121
63df1d28 122 virtual bool inheritProperties(const Http::Message *) = 0;
f1974911 123
124protected:
e1381638
AJ
125 /**
126 * Validate the message start line is syntactically correct.
127 * Set HTTP error status according to problems found.
128 *
129 * \retval true Status line has no serious problems.
130 * \retval false Status line has a serious problem. Correct response is indicated by error.
131 */
84ae6223 132 virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) = 0;
4a56ee8d 133
17802cf1 134 virtual void packFirstLineInto(Packable * p, bool full_uri) const = 0;
4a56ee8d 135
429f7150 136 virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
4a56ee8d 137
07947ad8 138 virtual void hdrCacheInit();
f1974911 139};
140
63df1d28
AJ
141} // namespace Http
142
e2cc8c07
AJ
143inline void
144HTTPMSGUNLOCK(Http::Message *a)
145{
146 if (a) {
147 if (a->unlock() == 0)
148 delete a;
6527a7f5 149 a = nullptr;
e2cc8c07
AJ
150 }
151}
152
153inline void
154HTTPMSGLOCK(Http::Message *a)
155{
156 if (a)
157 a->lock();
158}
66c38d9a 159
f1974911 160#endif /* SQUID_HTTPMSG_H */
f53969cc 161