Parser.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_SRC_HTTP_ONE_PARSER_H
10 #define SQUID_SRC_HTTP_ONE_PARSER_H
11 
12 #include "anyp/ProtocolVersion.h"
13 #include "http/one/forward.h"
14 #include "http/StatusCode.h"
15 #include "parser/forward.h"
16 #include "sbuf/SBuf.h"
17 
18 namespace Http {
19 namespace One {
20 
21 // Parser states
22 enum ParseState {
30 };
31 
40 class Parser : public RefCountable
41 {
42 public:
44  typedef ::Parser::Tokenizer Tokenizer;
45 
46  Parser() = default;
47  Parser(const Parser &) = default;
48  Parser &operator =(const Parser &) = default;
49  Parser(Parser &&) = default;
50  Parser &operator =(Parser &&) = default;
51  ~Parser() override {}
52 
55  virtual void clear() = 0;
56 
60  virtual bool parse(const SBuf &aBuf) = 0;
61 
67 
69  virtual size_type firstLineSize() const = 0;
70 
74 
79 
81  SBuf mimeHeader() const {return mimeHeaderBlock_;}
82 
85 
95  char *getHostHeaderField();
96 
98  const SBuf &remaining() const {return buf_;}
99 
109 
113  static const CharacterSet &WhitespaceCharacters();
114 
120  static const CharacterSet &DelimiterCharacters();
121 
122 protected:
129  void skipLineTerminator(Tokenizer &) const;
130 
140  bool grabMimeBlock(const char *which, const size_t limit);
141 
143  static const SBuf Http1magic;
144 
147 
150 
153 
156 
158  bool hackExpectsMime_ = false;
159 
160 private:
161  void cleanMimePrefix();
162  void unfoldMime();
163 };
164 
170 
175 
177 int ErrorLevel();
178 
179 } // namespace One
180 } // namespace Http
181 
182 #endif /* SQUID_SRC_HTTP_ONE_PARSER_H */
183 
static const CharacterSet & DelimiterCharacters()
Definition: Parser.cc:59
void cleanMimePrefix()
Definition: Parser.cc:97
Parser & operator=(const Parser &)=default
@ scNone
Definition: StatusCode.h:21
size_type messageHeaderSize() const
Definition: Parser.h:78
@ HTTP_PARSE_MIME
HTTP/1 mime-header block.
Definition: Parser.h:28
Definition: SBuf.h:93
virtual void clear()=0
Definition: Parser.cc:27
ParseState parsingStage_
what stage the parser is currently up to
Definition: Parser.h:149
bool needsMoreData() const
Definition: Parser.h:66
StatusCode
Definition: StatusCode.h:20
size_type headerBlockSize() const
Definition: Parser.h:73
Definition: forward.h:17
SBuf mimeHeader() const
buffer containing HTTP mime headers, excluding message first-line.
Definition: Parser.h:81
~Parser() override
Definition: Parser.h:51
@ HTTP_PARSE_CHUNK
HTTP/1.1 chunked encoding chunk-data.
Definition: Parser.h:27
SBuf::size_type size_type
Definition: Parser.h:43
static const CharacterSet & WhitespaceCharacters()
Definition: Parser.cc:52
Generic protocol-agnostic parsing tools.
Definition: RequestParser.h:15
MemBlob::size_type size_type
Definition: SBuf.h:96
virtual bool parse(const SBuf &aBuf)=0
void skipLineTerminator(Tokenizer &) const
Definition: Parser.cc:66
bool grabMimeBlock(const char *which, const size_t limit)
Definition: Parser.cc:157
SBuf mimeHeaderBlock_
buffer holding the mime headers (if any)
Definition: Parser.h:155
@ HTTP_PARSE_NONE
initialized, but nothing usefully parsed yet
Definition: Parser.h:23
ParseState
Definition: Parser.h:22
SBuf buf_
bytes remaining to be parsed
Definition: Parser.h:146
const SBuf & remaining() const
the remaining unprocessed section of buffer
Definition: Parser.h:98
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:419
char * getHostHeaderField()
Definition: Parser.cc:213
const AnyP::ProtocolVersion & messageProtocol() const
the protocol label for this message
Definition: Parser.h:84
bool hackExpectsMime_
Whether the invalid HTTP as HTTP/0.9 hack expects a mime header block.
Definition: Parser.h:158
virtual size_type firstLineSize() const =0
size in bytes of the first line including CRLF terminator
@ HTTP_PARSE_FIRST
HTTP/1 message first-line.
Definition: Parser.h:24
void ParseStrictBws(Parser::Tokenizer &)
Definition: Parser.cc:303
static const SBuf Http1magic
RFC 7230 section 2.6 - 7 magic octets.
Definition: Parser.h:143
void unfoldMime()
Definition: Parser.cc:132
Http::StatusCode parseStatusCode
Definition: Parser.h:108
void ParseBws(Parser::Tokenizer &)
Definition: Parser.cc:297
@ HTTP_PARSE_DONE
parsed a message header, or reached a terminal syntax error
Definition: Parser.h:29
::Parser::Tokenizer Tokenizer
Definition: Parser.h:44
@ HTTP_PARSE_CHUNK_SZ
HTTP/1.1 chunked encoding chunk-size.
Definition: Parser.h:25
AnyP::ProtocolVersion msgProtocol_
what protocol label has been found in the first line (if any)
Definition: Parser.h:152
@ HTTP_PARSE_CHUNK_EXT
HTTP/1.1 chunked encoding chunk-ext.
Definition: Parser.h:26
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:17
int ErrorLevel()
the right debugs() level for logging HTTP violation messages
Definition: Parser.cc:269

 

Introduction

Documentation

Support

Miscellaneous