#include <BinaryTokenizer.h>

Collaboration diagram for Parser::BinaryTokenizer:

Public Types

typedef ::Parser::InsufficientInput InsufficientInput
 
typedef uint64_t size_type
 

Public Member Functions

 BinaryTokenizer ()
 
 BinaryTokenizer (const SBuf &data, const bool expectMore=false)
 
void reset (const SBuf &data, const bool expectMore)
 
void reinput (const SBuf &data, const bool expectMore)
 
void commit ()
 make progress: future parsing failures will not rollback beyond this point More...
 
void rollback ()
 resume [incremental] parsing from the last commit point More...
 
bool atEnd () const
 no more bytes to parse or skip More...
 
uint8_t uint8 (const char *description)
 parse a single-byte unsigned integer More...
 
uint16_t uint16 (const char *description)
 parse a two-byte unsigned integer More...
 
uint32_t uint24 (const char *description)
 parse a three-byte unsigned integer (returned as uint32_t) More...
 
uint32_t uint32 (const char *description)
 parse a four-byte unsigned integer More...
 
SBuf area (uint64_t size, const char *description)
 parse size consecutive bytes as an opaque blob More...
 
Ip::Address inet4 (const char *description)
 interpret the next 4 bytes as a raw in_addr structure More...
 
Ip::Address inet6 (const char *description)
 interpret the next 16 bytes as a raw in6_addr structure More...
 
SBuf pstring8 (const char *description)
 up to 255 byte-long p-string More...
 
SBuf pstring16 (const char *description)
 up to 64 KiB-long p-string More...
 
SBuf pstring24 (const char *description)
 up to 16 MiB-long p-string! More...
 
void skip (uint64_t size, const char *description)
 ignore the next size bytes More...
 
uint64_t parsed () const
 the number of already parsed bytes More...
 
SBuf leftovers () const
 yet unparsed bytes More...
 
void got (uint64_t size, const char *description) const
 debugging helper for parsed multi-field structures More...
 

Public Attributes

const BinaryTokenizerContextcontext
 debugging: thing being parsed More...
 

Protected Member Functions

uint32_t octet ()
 
void want (uint64_t size, const char *description) const
 logs and throws if fewer than size octets remain; no other side effects More...
 
void got (uint32_t value, uint64_t size, const char *description) const
 debugging helper for parsed number fields More...
 
void got (const SBuf &value, uint64_t size, const char *description) const
 debugging helper for parsed areas/blobs More...
 
void got (const Ip::Address &value, uint64_t size, const char *description) const
 debugging helper for parsed addresses More...
 
void skipped (uint64_t size, const char *description) const
 debugging helper for skipped fields More...
 

Private Member Functions

template<class InAddr >
Ip::Address inetAny (const char *description)
 

Private Attributes

SBuf data_
 
uint64_t parsed_
 number of data bytes parsed or skipped More...
 
uint64_t syncPoint_
 where to re-start the next parsing attempt More...
 
bool expectMore_
 whether more data bytes may arrive in the future More...
 

Detailed Description

Safely extracts byte-oriented (i.e., non-textual) fields from raw input. Assume that the integers are stored in network byte order. Supports commit points for atomic incremental parsing of multi-part fields. Throws InsufficientInput when more input is needed to parse the next field. Throws on errors.

Definition at line 46 of file BinaryTokenizer.h.

Member Typedef Documentation

◆ InsufficientInput

◆ size_type

Definition at line 50 of file BinaryTokenizer.h.

Constructor & Destructor Documentation

◆ BinaryTokenizer() [1/2]

Parser::BinaryTokenizer::BinaryTokenizer ( )

Definition at line 15 of file BinaryTokenizer.cc.

Referenced by reset().

◆ BinaryTokenizer() [2/2]

Parser::BinaryTokenizer::BinaryTokenizer ( const SBuf data,
const bool  expectMore = false 
)
explicit

Definition at line 19 of file BinaryTokenizer.cc.

Member Function Documentation

◆ area()

SBuf Parser::BinaryTokenizer::area ( uint64_t  size,
const char *  description 
)

◆ atEnd()

◆ commit()

◆ got() [1/4]

void Parser::BinaryTokenizer::got ( uint64_t  size,
const char *  description 
) const

◆ got() [2/4]

void Parser::BinaryTokenizer::got ( uint32_t  value,
uint64_t  size,
const char *  description 
) const
protected

Definition at line 63 of file BinaryTokenizer.cc.

References BinaryTokenizer_tail, context, debugs, and parsed_.

◆ got() [3/4]

void Parser::BinaryTokenizer::got ( const SBuf value,
uint64_t  size,
const char *  description 
) const
protected

◆ got() [4/4]

void Parser::BinaryTokenizer::got ( const Ip::Address value,
uint64_t  size,
const char *  description 
) const
protected

Definition at line 81 of file BinaryTokenizer.cc.

References BinaryTokenizer_tail, context, debugs, and parsed_.

◆ inet4()

Ip::Address Parser::BinaryTokenizer::inet4 ( const char *  description)

Definition at line 191 of file BinaryTokenizer.cc.

Referenced by ProxyProtocol::Two::ParseAddresses().

◆ inet6()

Ip::Address Parser::BinaryTokenizer::inet6 ( const char *  description)

Definition at line 197 of file BinaryTokenizer.cc.

Referenced by ProxyProtocol::Two::ParseAddresses().

◆ inetAny()

template<class InAddr >
Ip::Address Parser::BinaryTokenizer::inetAny ( const char *  description)
private

Definition at line 178 of file BinaryTokenizer.cc.

References addr, data_, got(), parsed_, SBuf::rawContent(), size, and want().

◆ leftovers()

SBuf Parser::BinaryTokenizer::leftovers ( ) const
inline

Definition at line 108 of file BinaryTokenizer.h.

References SBuf::substr().

Referenced by Security::HandshakeParser::skipMessage().

◆ octet()

uint32_t Parser::BinaryTokenizer::octet ( )
protected

Returns the next ready-for-shift byte, adjusting the number of parsed bytes. The larger 32-bit return type helps callers shift/merge octets into numbers. This internal method does not perform out-of-bounds checks.

Definition at line 99 of file BinaryTokenizer.cc.

References data_, and parsed_.

Referenced by uint16(), uint24(), uint32(), and uint8().

◆ parsed()

uint64_t Parser::BinaryTokenizer::parsed ( ) const
inline

◆ pstring16()

◆ pstring24()

SBuf Parser::BinaryTokenizer::pstring24 ( const char *  description)

◆ pstring8()

SBuf Parser::BinaryTokenizer::pstring8 ( const char *  description)

◆ reinput()

void Parser::BinaryTokenizer::reinput ( const SBuf data,
const bool  expectMore 
)
inline

change input state without changing parsing state this method avoids append overheads during incremental parsing

Definition at line 61 of file BinaryTokenizer.h.

References data, and size.

Referenced by Security::HandshakeParser::parseHello().

◆ reset()

void Parser::BinaryTokenizer::reset ( const SBuf data,
const bool  expectMore 
)

restart parsing from the very beginning this method is for using one BinaryTokenizer to parse independent inputs

Definition at line 107 of file BinaryTokenizer.cc.

References BinaryTokenizer().

Referenced by Security::HandshakeParser::parseMessages().

◆ rollback()

void Parser::BinaryTokenizer::rollback ( )

Definition at line 113 of file BinaryTokenizer.cc.

References parsed_, and syncPoint_.

Referenced by Security::HandshakeParser::parseHello().

◆ skip()

void Parser::BinaryTokenizer::skip ( uint64_t  size,
const char *  description 
)

◆ skipped()

void Parser::BinaryTokenizer::skipped ( uint64_t  size,
const char *  description 
) const
protected

Definition at line 89 of file BinaryTokenizer.cc.

References BinaryTokenizer_tail, context, debugs, and parsed_.

Referenced by skip().

◆ uint16()

◆ uint24()

uint32_t Parser::BinaryTokenizer::uint24 ( const char *  description)

Definition at line 149 of file BinaryTokenizer.cc.

References got(), octet(), and want().

Referenced by pstring24().

◆ uint32()

uint32_t Parser::BinaryTokenizer::uint32 ( const char *  description)

Definition at line 158 of file BinaryTokenizer.cc.

References got(), octet(), and want().

◆ uint8()

◆ want()

void Parser::BinaryTokenizer::want ( uint64_t  size,
const char *  description 
) const
protected

Member Data Documentation

◆ context

◆ data_

SBuf Parser::BinaryTokenizer::data_
private

Definition at line 127 of file BinaryTokenizer.h.

Referenced by area(), atEnd(), inetAny(), octet(), and want().

◆ expectMore_

bool Parser::BinaryTokenizer::expectMore_
private

Definition at line 130 of file BinaryTokenizer.h.

Referenced by want().

◆ parsed_

uint64_t Parser::BinaryTokenizer::parsed_
private

Definition at line 128 of file BinaryTokenizer.h.

Referenced by area(), atEnd(), commit(), got(), inetAny(), octet(), rollback(), skip(), skipped(), and want().

◆ syncPoint_

uint64_t Parser::BinaryTokenizer::syncPoint_
private

Definition at line 129 of file BinaryTokenizer.h.

Referenced by commit(), and rollback().


The documentation for this class was generated from the following files:

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors