Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move HTTP base Parser to namespace Http #894

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/HttpReply.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ HttpReply::configureContentLengthInterpreter(Http::ContentLengthInterpreter &int
}

bool
HttpReply::parseHeader(Http1::Parser &hp)
HttpReply::parseHeader(Http::Parser &hp)
{
Http::ContentLengthInterpreter clen;
return Message::parseHeader(hp, clen);
Expand Down
2 changes: 1 addition & 1 deletion src/HttpReply.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class HttpReply: public Http::Message

virtual void configureContentLengthInterpreter(Http::ContentLengthInterpreter &);
/// parses reply header using Parser
bool parseHeader(Http1::Parser &hp);
bool parseHeader(Http::Parser &hp);

private:
/** initialize */
Expand Down
2 changes: 1 addition & 1 deletion src/HttpRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ HttpRequest::checkEntityFraming() const
}

bool
HttpRequest::parseHeader(Http1::Parser &hp)
HttpRequest::parseHeader(Http::Parser &hp)
{
Http::ContentLengthInterpreter clen;
return Message::parseHeader(hp, clen);
Expand Down
2 changes: 1 addition & 1 deletion src/HttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class HttpRequest: public Http::Message

/// Parses request header using Parser.
/// Use it in contexts where the Parser object is available.
bool parseHeader(Http1::Parser &hp);
bool parseHeader(Http::Parser &hp);
/// Parses request header from the buffer.
/// Use it in contexts where the Parser object not available.
bool parseHeader(const char *buffer, const size_t size);
Expand Down
6 changes: 3 additions & 3 deletions src/http/ContentLengthInterpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "base/CharacterSet.h"
#include "Debug.h"
#include "http/ContentLengthInterpreter.h"
#include "http/one/Parser.h"
#include "http/Parser.h"
#include "HttpHeaderTools.h"
#include "SquidConfig.h"
#include "SquidString.h"
Expand All @@ -35,7 +35,7 @@ const char *
Http::ContentLengthInterpreter::findDigits(const char *prefix, const char * const valueEnd) const
{
// skip leading OWS in RFC 7230's `OWS field-value OWS`
const CharacterSet &whitespace = Http::One::Parser::WhitespaceCharacters();
const CharacterSet &whitespace = Http::Parser::WhitespaceCharacters();
while (prefix < valueEnd) {
const auto ch = *prefix;
if (CharacterSet::DIGIT[ch])
Expand All @@ -55,7 +55,7 @@ Http::ContentLengthInterpreter::goodSuffix(const char *suffix, const char * cons
if (suffix == end)
return true;

for (const CharacterSet &delimiters = Http::One::Parser::DelimiterCharacters();
for (const CharacterSet &delimiters = Http::Parser::DelimiterCharacters();
suffix < end; ++suffix) {
if (!delimiters[*suffix])
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/http/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ libhttp_la_SOURCES = \
Message.h \
MethodType.cc \
MethodType.h \
Parser.cc \
Parser.h \
ProtocolVersion.h \
RegisteredHeaders.cc \
RegisteredHeaders.h \
Expand Down
4 changes: 2 additions & 2 deletions src/http/Message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "Debug.h"
#include "http/ContentLengthInterpreter.h"
#include "http/Message.h"
#include "http/one/Parser.h"
#include "http/Parser.h"
#include "HttpHdrCc.h"
#include "HttpHeaderTools.h"
#include "MemBuf.h"
Expand Down Expand Up @@ -216,7 +216,7 @@ Http::Message::httpMsgParseStep(const char *buf, int len, int atEnd)
}

bool
Http::Message::parseHeader(Http1::Parser &hp, Http::ContentLengthInterpreter &clen)
Http::Message::parseHeader(Http::Parser &hp, Http::ContentLengthInterpreter &clen)
{
// HTTP/1 message contains "zero or more header fields"
// zero does not need parsing
Expand Down
2 changes: 1 addition & 1 deletion src/http/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Message : public RefCountable
virtual void configureContentLengthInterpreter(Http::ContentLengthInterpreter &) = 0;

// Parser-NG transitional parsing of mime headers
bool parseHeader(Http1::Parser &, Http::ContentLengthInterpreter &); // TODO move this function to the parser
bool parseHeader(Http::Parser &, Http::ContentLengthInterpreter &); // TODO move this function to the parser
};

} // namespace Http
Expand Down
28 changes: 14 additions & 14 deletions src/http/one/Parser.cc → src/http/Parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include "squid.h"
#include "base/CharacterSet.h"
#include "Debug.h"
#include "http/one/Parser.h"
#include "http/Parser.h"
#include "mime_header.h"
#include "parser/Tokenizer.h"
#include "SquidConfig.h"

/// RFC 7230 section 2.6 - 7 magic octets
const SBuf Http::One::Parser::Http1magic("HTTP/1.");
const SBuf Http::Parser::Http1magic("HTTP/1.");

const SBuf &Http::One::CrLf()
{
Expand All @@ -24,7 +24,7 @@ const SBuf &Http::One::CrLf()
}

void
Http::One::Parser::clear()
Http::Parser::clear()
{
parsingStage_ = HTTP_PARSE_NONE;
buf_ = NULL;
Expand All @@ -49,21 +49,21 @@ RelaxedDelimiterCharacters()
}

const CharacterSet &
Http::One::Parser::WhitespaceCharacters()
Http::Parser::WhitespaceCharacters()
{
return Config.onoff.relaxed_header_parser ?
RelaxedDelimiterCharacters() : CharacterSet::WSP;
}

const CharacterSet &
Http::One::Parser::DelimiterCharacters()
Http::Parser::DelimiterCharacters()
{
return Config.onoff.relaxed_header_parser ?
RelaxedDelimiterCharacters() : CharacterSet::SP;
}

void
Http::One::Parser::skipLineTerminator(Tokenizer &tok) const
Http::Parser::skipLineTerminator(Tokenizer &tok) const
{
if (tok.skip(Http1::CrLf()))
return;
Expand All @@ -72,7 +72,7 @@ Http::One::Parser::skipLineTerminator(Tokenizer &tok) const
return;

if (tok.atEnd() || (tok.remaining().length() == 1 && tok.remaining().at(0) == '\r'))
throw InsufficientInput();
throw ::Parser::InsufficientInput();

throw TexcHere("garbage instead of CRLF line terminator");
}
Expand Down Expand Up @@ -100,7 +100,7 @@ LineCharacters()
* sequences of CRLF will be pruned, but not sequences of bare-LF.
*/
void
Http::One::Parser::cleanMimePrefix()
Http::Parser::cleanMimePrefix()
{
Tokenizer tok(mimeHeaderBlock_);
while (tok.skipOne(RelaxedDelimiterCharacters())) {
Expand Down Expand Up @@ -135,7 +135,7 @@ Http::One::Parser::cleanMimePrefix()
* the field value or forwarding the message downstream."
*/
void
Http::One::Parser::unfoldMime()
Http::Parser::unfoldMime()
{
Tokenizer tok(mimeHeaderBlock_);
const auto szLimit = mimeHeaderBlock_.length();
Expand All @@ -160,7 +160,7 @@ Http::One::Parser::unfoldMime()
}

bool
Http::One::Parser::grabMimeBlock(const char *which, const size_t limit)
Http::Parser::grabMimeBlock(const char *which, const size_t limit)
{
// MIME headers block exist in (only) HTTP/1.x and ICY
const bool expectMime = (msgProtocol_.protocol == AnyP::PROTO_HTTP && msgProtocol_.major == 1) ||
Expand Down Expand Up @@ -216,7 +216,7 @@ Http::One::Parser::grabMimeBlock(const char *which, const size_t limit)
// BUG: returns only the first header line with given name,
// ignores multi-line headers and obs-fold headers
char *
Http::One::Parser::getHostHeaderField()
Http::Parser::getHostHeaderField()
{
if (!headerBlockSize())
return NULL;
Expand Down Expand Up @@ -272,19 +272,19 @@ Http::One::Parser::getHostHeaderField()
}

int
Http::One::ErrorLevel()
Http::ErrorLevel()
{
return Config.onoff.relaxed_header_parser < 0 ? DBG_IMPORTANT : 5;
}

// BWS = *( SP / HTAB ) ; WhitespaceCharacters() may relax this RFC 7230 rule
void
Http::One::ParseBws(Parser::Tokenizer &tok)
Http::ParseBws(Parser::Tokenizer &tok)
{
const auto count = tok.skipAll(Parser::WhitespaceCharacters());

if (tok.atEnd())
throw InsufficientInput(); // even if count is positive
throw ::Parser::InsufficientInput(); // even if count is positive

if (count) {
// Generating BWS is a MUST-level violation so warn about it as needed.
Expand Down
14 changes: 6 additions & 8 deletions src/http/one/Parser.h → src/http/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
* Please see the COPYING and CONTRIBUTORS files for details.
*/

#ifndef _SQUID_SRC_HTTP_ONE_PARSER_H
#define _SQUID_SRC_HTTP_ONE_PARSER_H
#ifndef _SQUID_SRC_HTTP_PARSER_H
#define _SQUID_SRC_HTTP_PARSER_H

#include "anyp/ProtocolVersion.h"
#include "http/one/forward.h"
#include "http/forward.h"
#include "http/StatusCode.h"
#include "parser/forward.h"
#include "sbuf/SBuf.h"

namespace Http {
namespace One {

// Parser states
enum ParseState {
Expand All @@ -29,10 +28,10 @@ enum ParseState {
HTTP_PARSE_DONE ///< parsed a message header, or reached a terminal syntax error
};

/** HTTP/1.x protocol parser
/** HTTP protocol parser
*
* Works on a raw character I/O buffer and tokenizes the content into
* the major CRLF delimited segments of an HTTP/1 procotol message:
* the major CRLF delimited segments of an HTTP/1 protocol message:
*
* \li first-line (request-line / simple-request / status-line)
* \li mime-header 0*( header-name ':' SP field-value CRLF)
Expand Down Expand Up @@ -171,8 +170,7 @@ void ParseBws(Parser::Tokenizer &);
/// the right debugs() level for logging HTTP violation messages
int ErrorLevel();

} // namespace One
} // namespace Http

#endif /* _SQUID_SRC_HTTP_ONE_PARSER_H */
#endif /* _SQUID_SRC_HTTP_PARSER_H */

2 changes: 1 addition & 1 deletion src/http/StatusLine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Http::StatusLine::parse(const String &protoPrefix, const char *start, const char
Parser::Tokenizer tok(statusBuf);
try {
One::ResponseParser::ParseResponseStatus(tok, status_);
} catch (const Parser::InsufficientInput &) {
} catch (const ::Parser::InsufficientInput &) {
debugs(57, 7, "need more; have " << unparsedLength);
return false;
} catch (...) {
Expand Down
3 changes: 3 additions & 0 deletions src/http/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class ContentLengthInterpreter;
class Message;
typedef RefCount<Http::Message> MessagePointer;

class Parser;
typedef RefCount<Http::Parser> ParserPointer;

class Stream;
typedef RefCount<Http::Stream> StreamPointer;

Expand Down
2 changes: 0 additions & 2 deletions src/http/one/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ include $(top_srcdir)/src/TestHeaders.am
noinst_LTLIBRARIES = libhttp1.la

libhttp1_la_SOURCES = \
Parser.cc \
Parser.h \
RequestParser.cc \
RequestParser.h \
ResponseParser.cc \
Expand Down
2 changes: 1 addition & 1 deletion src/http/one/RequestParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "profiler/Profiler.h"
#include "SquidConfig.h"

Http1::Parser::size_type
Http::Parser::size_type
Http::One::RequestParser::firstLineSize() const
{
// RFC 7230 section 2.6
Expand Down
8 changes: 4 additions & 4 deletions src/http/one/RequestParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H
#define _SQUID_SRC_HTTP_ONE_REQUESTPARSER_H

#include "http/one/Parser.h"
#include "http/Parser.h"
#include "http/RequestMethod.h"

namespace Parser {
Expand All @@ -27,7 +27,7 @@ namespace One {
* \li request-line (method, URL, protocol, version)
* \li mime-header (set of RFC2616 syntax header fields)
*/
class RequestParser : public Http1::Parser
class RequestParser : public Http::Parser
{
public:
RequestParser() = default;
Expand All @@ -38,9 +38,9 @@ class RequestParser : public Http1::Parser
RequestParser &operator =(RequestParser &&) = default;
virtual ~RequestParser() {}

/* Http::One::Parser API */
/* Http::Parser API */
virtual void clear() {*this = RequestParser();}
virtual Http1::Parser::size_type firstLineSize() const;
virtual Http::Parser::size_type firstLineSize() const;
virtual bool parse(const SBuf &aBuf);

/// the HTTP method if this is a request message
Expand Down
4 changes: 2 additions & 2 deletions src/http/one/ResponseParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

const SBuf Http::One::ResponseParser::IcyMagic("ICY ");

Http1::Parser::size_type
Http::Parser::size_type
Http::One::ResponseParser::firstLineSize() const
{
Http1::Parser::size_type result = 0;
Http::Parser::size_type result = 0;

switch (msgProtocol_.protocol)
{
Expand Down
8 changes: 4 additions & 4 deletions src/http/one/ResponseParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef _SQUID_SRC_HTTP_ONE_RESPONSEPARSER_H
#define _SQUID_SRC_HTTP_ONE_RESPONSEPARSER_H

#include "http/one/Parser.h"
#include "http/Parser.h"
#include "http/StatusCode.h"

namespace Http {
Expand All @@ -26,7 +26,7 @@ namespace One {
* \li status-line (version SP status SP reash-phrase)
* \li mime-header (set of RFC2616 syntax header fields)
*/
class ResponseParser : public Http1::Parser
class ResponseParser : public Http::Parser
{
public:
ResponseParser() = default;
Expand All @@ -36,9 +36,9 @@ class ResponseParser : public Http1::Parser
ResponseParser &operator =(ResponseParser &&) = default;
virtual ~ResponseParser() {}

/* Http::One::Parser API */
/* Http::Parser API */
virtual void clear() {*this=ResponseParser();}
virtual Http1::Parser::size_type firstLineSize() const;
virtual Http::Parser::size_type firstLineSize() const;
virtual bool parse(const SBuf &aBuf);

/* respone specific fields, read-only */
Expand Down
Loading