Message.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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"
16 #include "http/ProtocolVersion.h"
17 #include "http/StatusCode.h"
18 #include "HttpHeader.h"
19 #include <type_traits>
20 
21 namespace Http
22 {
23 
25 class Message : public RefCountable
26 {
27 public:
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  srcGopher = 1 << (16 + 14),
44  srcWhois = 1 << (16 + 15),
45  srcUnsafe = 0xFFFF0000,
46  srcSafe = 0x0000FFFF
47  };
48 
50  virtual ~Message();
51 
52  virtual void reset() = 0; // will have body when http*Clean()s are gone
53 
54  void packInto(Packable *, bool full_uri) const;
55 
57  virtual Http::Message *clone() const = 0; // TODO rename: not a true copy?
58 
60  void setContentLength(int64_t);
61 
68  bool persistent() const;
69 
70 public:
74 
76 
78 
79  /* Unsupported, writable, may disappear/change in the future
80  * For replies, sums _stored_ status-line, headers, and <CRLF>.
81  * Also used to report parsed header size if parse() is successful */
82  int hdr_sz = 0;
83 
84  int64_t content_length = 0;
85 
87  enum ParseState {
92  };
93 
96 
99 
100  uint32_t sources = 0;
101 
103  void putCc(const HttpHdrCc *otherCc);
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 
122 protected:
130  virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error) = 0;
131 
132  virtual void packFirstLineInto(Packable * p, bool full_uri) const = 0;
133 
134  virtual bool parseFirstLine(const char *blk_start, const char *blk_end) = 0;
135 
136  virtual void hdrCacheInit();
137 
140 
141  // Parser-NG transitional parsing of mime headers
142  bool parseHeader(Http1::Parser &, Http::ContentLengthInterpreter &); // TODO move this function to the parser
143 };
144 
145 } // namespace Http
146 
147 template <class M>
148 inline void
150 {
151  static_assert(std::is_base_of<Http::Message, M>::value, "M must inherit from Http::Message");
152  if (a) {
153  if (a->unlock() == 0)
154  delete a;
155  a = nullptr;
156  }
157 }
158 
159 inline void
161 {
162  if (a)
163  a->lock();
164 }
165 
166 #endif /* SQUID_HTTPMSG_H */
167 
virtual void packFirstLineInto(Packable *p, bool full_uri) const =0
http_hdr_owner_type
Definition: HttpHeader.h:31
https_port or bumped http_port tunnel; HTTPS server
Definition: Message.h:33
HttpHdrCc * cache_control
Definition: Message.h:77
ParseState pstate
the current parsing state
Definition: Message.h:95
int hdr_sz
Definition: Message.h:82
Safe sources mask.
Definition: Message.h:46
void firstLineBuf(MemBuf &)
useful for debugging
Definition: Message.cc:295
virtual void configureContentLengthInterpreter(Http::ContentLengthInterpreter &)=0
configures the interpreter as needed
void error(char *format,...)
http_port or HTTP server
Definition: Message.h:39
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:160
bool persistent() const
Definition: Message.cc:261
virtual void reset()=0
AnyP::ProtocolVersion http_ver
Definition: Message.h:73
char * p
Definition: membanger.c:43
virtual bool parseFirstLine(const char *blk_start, const char *blk_end)=0
traditional ICAP service without encryption
Definition: Message.h:41
ftp_port or FTP server
Definition: Message.h:40
Whois server.
Definition: Message.h:44
StatusCode
Definition: StatusCode.h:20
int64_t content_length
Definition: Message.h:84
virtual bool inheritProperties(const Http::Message *)=0
ftps_port or SFTP server; currently unused
Definition: Message.h:34
common parts of HttpRequest and HttpReply
Definition: Message.h:25
ParseState
parse state of HttpReply or HttpRequest
Definition: Message.h:87
bool parseHeader(Http1::Parser &, Http::ContentLengthInterpreter &)
Definition: Message.cc:226
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void setContentLength(int64_t)
[re]sets Content-Length header and cached value
Definition: Message.cc:253
void const char * buf
Definition: stub_helper.cc:16
HttpHeader header
Definition: Message.h:75
eCAP service that is considered secure; currently unused
Definition: Message.h:36
virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error)=0
void putCc(const HttpHdrCc *otherCc)
copies Cache-Control header to this message
Definition: Message.cc:34
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:149
virtual Http::Message * clone() const =0
Definition: MemBuf.h:23
bool parseCharBuf(const char *buf, ssize_t end)
Definition: Message.cc:148
virtual ~Message()
Definition: Message.cc:28
int a
Definition: membanger.c:50
BodyPipe::Pointer body_pipe
optional pipeline to receive message body
Definition: Message.h:98
void packInto(Packable *, bool full_uri) const
produce a message copy, except for a few connection-specific settings
Definition: Message.cc:278
int httpMsgParseStep(const char *buf, int len, int atEnd)
Definition: Message.cc:170
Gopher server.
Definition: Message.h:43
virtual void hdrCacheInit()
Definition: Message.cc:286
Sources
Who may have created or modified this message?
Definition: Message.h:29
bool parse(const char *buf, const size_t sz, bool eol, Http::StatusCode *error)
Definition: Message.cc:80
virtual int httpMsgParseError()
Definition: Message.cc:246
virtual bool expectingBody(const HttpRequestMethod &, int64_t &) const =0
eCAP service that uses insecure libraries/daemons
Definition: Message.h:42
Unsafe sources mask.
Definition: Message.h:45
Message(http_hdr_owner_type)
Definition: Message.cc:23
uint32_t sources
The message sources.
Definition: Message.h:100
Secure ICAP service.
Definition: Message.h:35

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors