Parser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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  virtual ~Parser() {}
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 
73  size_type headerBlockSize() const {return mimeHeaderBlock_.length();}
74 
78  size_type messageHeaderSize() const {return firstLineSize() + headerBlockSize();}
79 
81  SBuf mimeHeader() const {return mimeHeaderBlock_;}
82 
85 
95  char *getHeaderField(const char *name);
96 
98  const SBuf &remaining() const {return buf_;}
99 
109 
113  static const CharacterSet &WhitespaceCharacters();
114 
120  static const CharacterSet &DelimiterCharacters();
121 
122 protected:
131  void skipLineTerminator(Tokenizer &) const;
132 
142  bool grabMimeBlock(const char *which, const size_t limit);
143 
145  static const SBuf Http1magic;
146 
149 
152 
155 
158 
160  bool hackExpectsMime_ = false;
161 
162 private:
163  void cleanMimePrefix();
164  void unfoldMime();
165 };
166 
170 
172 int ErrorLevel();
173 
174 } // namespace One
175 } // namespace Http
176 
177 #endif /* _SQUID_SRC_HTTP_ONE_PARSER_H */
178 
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:404
AnyP::ProtocolVersion msgProtocol_
what protocol label has been found in the first line (if any)
Definition: Parser.h:154
size_type messageHeaderSize() const
Definition: Parser.h:78
static const CharacterSet & DelimiterCharacters()
Definition: Parser.cc:59
ParseState
Definition: Parser.h:22
const SBuf & remaining() const
the remaining unprocessed section of buffer
Definition: Parser.h:98
size_type headerBlockSize() const
Definition: Parser.h:73
Definition: SBuf.h:86
SBuf::size_type size_type
Definition: Parser.h:43
void cleanMimePrefix()
Definition: Parser.cc:103
int ErrorLevel()
the right debugs() level for logging HTTP violation messages
Definition: Parser.cc:269
Http::StatusCode parseStatusCode
Definition: Parser.h:108
char * getHeaderField(const char *name)
Definition: Parser.cc:219
HTTP/1 mime-header block.
Definition: Parser.h:28
Generic protocol-agnostic parsing tools.
Definition: RequestParser.h:15
virtual size_type firstLineSize() const =0
size in bytes of the first line including CRLF terminator
StatusCode
Definition: StatusCode.h:20
void ParseBws(Parser::Tokenizer &)
Definition: Parser.cc:276
bool needsMoreData() const
Definition: Parser.h:66
initialized, but nothing usefully parsed yet
Definition: Parser.h:23
HTTP/1.1 chunked encoding chunk-data.
Definition: Parser.h:27
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:17
static const CharacterSet & WhitespaceCharacters()
Definition: Parser.cc:52
parsed a message header, or reached a terminal syntax error
Definition: Parser.h:29
HTTP/1 message first-line.
Definition: Parser.h:24
virtual ~Parser()
Definition: Parser.h:51
SBuf mimeHeaderBlock_
buffer holding the mime headers (if any)
Definition: Parser.h:157
virtual void clear()=0
Definition: Parser.cc:27
Parser & operator=(const Parser &)=default
SBuf buf_
bytes remaining to be parsed
Definition: Parser.h:148
bool grabMimeBlock(const char *which, const size_t limit)
Definition: Parser.cc:163
HTTP/1.1 chunked encoding chunk-ext.
Definition: Parser.h:26
::Parser::Tokenizer Tokenizer
Definition: Parser.h:44
virtual bool parse(const SBuf &aBuf)=0
bool hackExpectsMime_
Whether the invalid HTTP as HTTP/0.9 hack expects a mime header block.
Definition: Parser.h:160
void unfoldMime()
Definition: Parser.cc:138
const AnyP::ProtocolVersion & messageProtocol() const
the protocol label for this message
Definition: Parser.h:84
HTTP/1.1 chunked encoding chunk-size.
Definition: Parser.h:25
MemBlob::size_type size_type
Definition: SBuf.h:89
Definition: forward.h:21
void skipLineTerminator(Tokenizer &) const
Definition: Parser.cc:66
static const SBuf Http1magic
RFC 7230 section 2.6 - 7 magic octets.
Definition: Parser.h:145
SBuf mimeHeader() const
buffer containing HTTP mime headers, excluding message first-line.
Definition: Parser.h:81
ParseState parsingStage_
what stage the parser is currently up to
Definition: Parser.h:151

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors