Message.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef SQUID_HTTP_MESSAGE_H
10#define SQUID_HTTP_MESSAGE_H
11
12#include "base/Lock.h"
13#include "BodyPipe.h"
14#include "enums.h"
15#include "http/forward.h"
17#include "http/StatusCode.h"
18#include "HttpHeader.h"
19#include <type_traits>
20
21namespace Http
22{
23
25class Message : public RefCountable
26{
27public:
29 enum Sources {
31
32 /* flags in 0xFFFF zone are for "secure" or "encrypted" sources */
33 srcHttps = 1 << 0,
34 srcFtps = 1 << 1,
35 srcIcaps = 1 << 2,
36 srcEcaps = 1 << 3,
37
38 /* these flags "taint" the message: it may have been observed or mangled outside Squid */
39 srcHttp = 1 << (16 + 0),
40 srcFtp = 1 << (16 + 1),
41 srcIcap = 1 << (16 + 2),
42 srcEcap = 1 << (16 + 3),
43 srcWhois = 1 << (16 + 15),
44 srcUnsafe = 0xFFFF0000,
45 srcSafe = 0x0000FFFF
46 };
47
49 ~Message() override;
50
51 virtual void reset() = 0; // will have body when http*Clean()s are gone
52
53 void packInto(Packable *, bool full_uri) const;
54
56 virtual Http::Message *clone() const = 0; // TODO rename: not a true copy?
57
59 void setContentLength(int64_t);
60
67 bool persistent() const;
68
69public:
73
75
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 */
81 int hdr_sz = 0;
82
83 int64_t content_length = 0;
84
91 };
92
95
98
99 uint32_t sources = 0;
100
103 void putCc(const HttpHdrCc &);
104
105 // returns true and sets hdr_sz on success
106 // returns false and sets *error to zero when needs more data
107 // returns false and sets *error to a positive Http::StatusCode on error
108 bool parse(const char *buf, const size_t sz, bool eol, Http::StatusCode *error);
109
110 bool parseCharBuf(const char *buf, ssize_t end);
111
112 int httpMsgParseStep(const char *buf, int len, int atEnd);
113
114 virtual int httpMsgParseError();
115
116 virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0;
117
118 void firstLineBuf(MemBuf&);
119
120 virtual bool inheritProperties(const Http::Message *) = 0;
121
122protected:
131 virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) = 0;
132
133 virtual void packFirstLineInto(Packable * p, bool full_uri) const = 0;
134
135 virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
136
137 virtual void hdrCacheInit();
138
141
142 // Parser-NG transitional parsing of mime headers
143 bool parseHeader(Http1::Parser &, Http::ContentLengthInterpreter &); // TODO move this function to the parser
144};
145
146} // namespace Http
147
148template <class M>
149inline void
151{
152 static_assert(std::is_base_of<Http::Message, M>::value, "M must inherit from Http::Message");
153 if (a) {
154 if (a->unlock() == 0)
155 delete a;
156 a = nullptr;
157 }
158}
159
160inline void
162{
163 if (a)
164 a->lock();
165}
166
167#endif /* SQUID_HTTPMSG_H */
168
http_hdr_owner_type
Definition: HttpHeader.h:31
#define RefCountable
The locking interface for use on Reference-Counted classes.
Definition: Lock.h:66
void error(char *format,...)
common parts of HttpRequest and HttpReply
Definition: Message.h:26
virtual void hdrCacheInit()
Definition: Message.cc:261
virtual void configureContentLengthInterpreter(Http::ContentLengthInterpreter &)=0
configures the interpreter as needed
~Message() override
Definition: Message.cc:27
Sources
Who may have created or modified this message?
Definition: Message.h:29
@ srcHttp
http_port or HTTP server
Definition: Message.h:39
@ srcEcap
eCAP service that uses insecure libraries/daemons
Definition: Message.h:42
@ srcFtps
ftps_port or SFTP server; currently unused
Definition: Message.h:34
@ srcIcaps
Secure ICAP service.
Definition: Message.h:35
@ srcHttps
https_port or bumped http_port tunnel; HTTPS server
Definition: Message.h:33
@ srcSafe
Safe sources mask.
Definition: Message.h:45
@ srcFtp
ftp_port or FTP server
Definition: Message.h:40
@ srcIcap
traditional ICAP service without encryption
Definition: Message.h:41
@ srcWhois
Whois server.
Definition: Message.h:43
@ srcUnsafe
Unsafe sources mask.
Definition: Message.h:44
@ srcEcaps
eCAP service that is considered secure; currently unused
Definition: Message.h:36
void packInto(Packable *, bool full_uri) const
produce a message copy, except for a few connection-specific settings
Definition: Message.cc:253
virtual void reset()=0
void setContentLength(int64_t)
[re]sets Content-Length header and cached value
Definition: Message.cc:228
virtual bool expectingBody(const HttpRequestMethod &, int64_t &) const =0
virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error)=0
bool persistent() const
Definition: Message.cc:236
int httpMsgParseStep(const char *buf, int len, int atEnd)
Definition: Message.cc:151
uint32_t sources
The message sources.
Definition: Message.h:99
Message(http_hdr_owner_type)
Definition: Message.cc:22
virtual int httpMsgParseError()
Definition: Message.cc:221
void firstLineBuf(MemBuf &)
useful for debugging
Definition: Message.cc:270
virtual void packFirstLineInto(Packable *p, bool full_uri) const =0
virtual Http::Message * clone() const =0
ParseState
parse state of HttpReply or HttpRequest
Definition: Message.h:86
@ psReadyToParseStartLine
Definition: Message.h:87
@ psReadyToParseHeaders
Definition: Message.h:88
HttpHeader header
Definition: Message.h:74
int hdr_sz
Definition: Message.h:81
ParseState pstate
the current parsing state
Definition: Message.h:94
int64_t content_length
Definition: Message.h:83
bool parseHeader(Http1::Parser &, Http::ContentLengthInterpreter &)
Definition: Message.cc:201
virtual bool inheritProperties(const Http::Message *)=0
bool parse(const char *buf, const size_t sz, bool eol, Http::StatusCode *error)
Definition: Message.cc:68
bool parseCharBuf(const char *buf, ssize_t end)
Definition: Message.cc:129
virtual bool parseFirstLine(const char *blk_start, const char *blk_end)=0
BodyPipe::Pointer body_pipe
optional pipeline to receive message body
Definition: Message.h:97
HttpHdrCc * cache_control
Definition: Message.h:76
void putCc(const HttpHdrCc &)
Definition: Message.cc:33
AnyP::ProtocolVersion http_ver
Definition: Message.h:72
Definition: MemBuf.h:24
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:150
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161
Definition: forward.h:18
StatusCode
Definition: StatusCode.h:20

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors