Parser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 "sbuf/SBuf.h"
16 
17 namespace Http {
18 namespace One {
19 
20 // Parser states
21 enum ParseState {
29 };
30 
39 class Parser : public RefCountable
40 {
41 public:
43 
44  Parser() = default;
45  Parser(const Parser &) = default;
46  Parser &operator =(const Parser &) = default;
47  Parser(Parser &&) = default;
48  Parser &operator =(Parser &&) = default;
49  virtual ~Parser() {}
50 
53  virtual void clear() = 0;
54 
58  virtual bool parse(const SBuf &aBuf) = 0;
59 
65 
67  virtual size_type firstLineSize() const = 0;
68 
72 
77 
79  SBuf mimeHeader() const {return mimeHeaderBlock_;}
80 
83 
93  char *getHeaderField(const char *name);
94 
96  const SBuf &remaining() const {return buf_;}
97 
107 
111  static const CharacterSet &WhitespaceCharacters();
112 
118  static const CharacterSet &DelimiterCharacters();
119 
120 protected:
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 
167 bool ParseBws(Tokenizer &tok);
168 
170 int ErrorLevel();
171 
172 } // namespace One
173 } // namespace Http
174 
175 #endif /* _SQUID_SRC_HTTP_ONE_PARSER_H */
176 
AnyP::ProtocolVersion msgProtocol_
what protocol label has been found in the first line (if any)
Definition: Parser.h:152
static const CharacterSet & DelimiterCharacters()
Definition: Parser.cc:58
ParseState
Definition: Parser.h:21
bool ParseBws(Tokenizer &tok)
Definition: Parser.cc:276
Definition: SBuf.h:87
SBuf::size_type size_type
Definition: Parser.h:42
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:106
char * getHeaderField(const char *name)
Definition: Parser.cc:219
HTTP/1 mime-header block.
Definition: Parser.h:27
const AnyP::ProtocolVersion & messageProtocol() const
the protocol label for this message
Definition: Parser.h:82
size_type messageHeaderSize() const
Definition: Parser.h:76
virtual size_type firstLineSize() const =0
size in bytes of the first line including CRLF terminator
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:405
StatusCode
Definition: StatusCode.h:20
initialized, but nothing usefully parsed yet
Definition: Parser.h:22
HTTP/1.1 chunked encoding chunk-data.
Definition: Parser.h:26
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:17
Definition: parse.c:160
static const CharacterSet & WhitespaceCharacters()
Definition: Parser.cc:51
parsed a message header, or reached a terminal syntax error
Definition: Parser.h:28
HTTP/1 message first-line.
Definition: Parser.h:23
bool skipLineTerminator(Http1::Tokenizer &tok) const
Definition: Parser.cc:65
virtual ~Parser()
Definition: Parser.h:49
SBuf mimeHeader() const
buffer containing HTTP mime headers, excluding message first-line.
Definition: Parser.h:79
SBuf mimeHeaderBlock_
buffer holding the mime headers (if any)
Definition: Parser.h:155
virtual void clear()=0
Definition: Parser.cc:26
Parser & operator=(const Parser &)=default
SBuf buf_
bytes remaining to be parsed
Definition: Parser.h:146
bool grabMimeBlock(const char *which, const size_t limit)
Definition: Parser.cc:163
HTTP/1.1 chunked encoding chunk-ext.
Definition: Parser.h:25
bool needsMoreData() const
Definition: Parser.h:64
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:158
const SBuf & remaining() const
the remaining unprocessed section of buffer
Definition: Parser.h:96
void unfoldMime()
Definition: Parser.cc:138
HTTP/1.1 chunked encoding chunk-size.
Definition: Parser.h:24
MemBlob::size_type size_type
Definition: SBuf.h:90
static const SBuf Http1magic
RFC 7230 section 2.6 - 7 magic octets.
Definition: Parser.h:143
size_type headerBlockSize() const
Definition: Parser.h:71
ParseState parsingStage_
what stage the parser is currently up to
Definition: Parser.h:149

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors