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
13#include "http/one/forward.h"
14#include "http/StatusCode.h"
15#include "parser/forward.h"
16#include "sbuf/SBuf.h"
17
18namespace Http {
19namespace One {
20
21// Parser states
30};
31
40class Parser : public RefCountable
41{
42public:
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
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
122protected:
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
160private:
161 void cleanMimePrefix();
162 void unfoldMime();
163};
164
168
170int ErrorLevel();
171
172} // namespace One
173} // namespace Http
174
175#endif /* _SQUID_SRC_HTTP_ONE_PARSER_H */
176
#define RefCountable
The locking interface for use on Reference-Counted classes.
Definition: Lock.h:66
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:18
SBuf::size_type size_type
Definition: Parser.h:43
const AnyP::ProtocolVersion & messageProtocol() const
the protocol label for this message
Definition: Parser.h:84
Http::StatusCode parseStatusCode
Definition: Parser.h:108
char * getHostHeaderField()
Definition: Parser.cc:213
AnyP::ProtocolVersion msgProtocol_
what protocol label has been found in the first line (if any)
Definition: Parser.h:152
Parser(Parser &&)=default
static const CharacterSet & WhitespaceCharacters()
Definition: Parser.cc:52
bool hackExpectsMime_
Whether the invalid HTTP as HTTP/0.9 hack expects a mime header block.
Definition: Parser.h:158
SBuf buf_
bytes remaining to be parsed
Definition: Parser.h:146
void cleanMimePrefix()
Definition: Parser.cc:97
void skipLineTerminator(Tokenizer &) const
Definition: Parser.cc:66
const SBuf & remaining() const
the remaining unprocessed section of buffer
Definition: Parser.h:98
Parser(const Parser &)=default
bool grabMimeBlock(const char *which, const size_t limit)
Definition: Parser.cc:157
ParseState parsingStage_
what stage the parser is currently up to
Definition: Parser.h:149
static const CharacterSet & DelimiterCharacters()
Definition: Parser.cc:59
size_type headerBlockSize() const
Definition: Parser.h:73
~Parser() override
Definition: Parser.h:51
virtual size_type firstLineSize() const =0
size in bytes of the first line including CRLF terminator
virtual bool parse(const SBuf &aBuf)=0
SBuf mimeHeader() const
buffer containing HTTP mime headers, excluding message first-line.
Definition: Parser.h:81
size_type messageHeaderSize() const
Definition: Parser.h:78
virtual void clear()=0
Definition: Parser.cc:27
Parser & operator=(const Parser &)=default
void unfoldMime()
Definition: Parser.cc:132
bool needsMoreData() const
Definition: Parser.h:66
SBuf mimeHeaderBlock_
buffer holding the mime headers (if any)
Definition: Parser.h:155
::Parser::Tokenizer Tokenizer
Definition: Parser.h:44
static const SBuf Http1magic
RFC 7230 section 2.6 - 7 magic octets.
Definition: Parser.h:143
Definition: SBuf.h:94
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:415
MemBlob::size_type size_type
Definition: SBuf.h:96
void ParseBws(Parser::Tokenizer &)
Definition: Parser.cc:276
ParseState
Definition: Parser.h:22
@ HTTP_PARSE_CHUNK_EXT
HTTP/1.1 chunked encoding chunk-ext.
Definition: Parser.h:26
@ HTTP_PARSE_CHUNK_SZ
HTTP/1.1 chunked encoding chunk-size.
Definition: Parser.h:25
@ HTTP_PARSE_FIRST
HTTP/1 message first-line.
Definition: Parser.h:24
@ HTTP_PARSE_DONE
parsed a message header, or reached a terminal syntax error
Definition: Parser.h:29
@ HTTP_PARSE_MIME
HTTP/1 mime-header block.
Definition: Parser.h:28
@ HTTP_PARSE_NONE
initialized, but nothing usefully parsed yet
Definition: Parser.h:23
@ HTTP_PARSE_CHUNK
HTTP/1.1 chunked encoding chunk-data.
Definition: Parser.h:27
int ErrorLevel()
the right debugs() level for logging HTTP violation messages
Definition: Parser.cc:269
Definition: forward.h:18
StatusCode
Definition: StatusCode.h:20
@ scNone
Definition: StatusCode.h:21
Generic protocol-agnostic parsing tools.
Definition: RequestParser.h:15

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors