UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
httpparser.cpp File Reference

Contains functions for scanner and parser for http messages. More...

#include <httpparser.hpp>
#include <statcodes.hpp>
#include <upnpdebug.hpp>
#include <UPnPsdk/synclog.hpp>
+ Include dependency graph for httpparser.cpp:

Go to the source code of this file.

Enumerations

enum  anonymous_namespace{httpparser.cpp}::token_type_t {
  TT_IDENTIFIER , TT_WHITESPACE , TT_CRLF , TT_CTRL ,
  TT_SEPARATOR , TT_QUOTEDSTRING
}
 Used to represent different types of tokens in input. More...
 

Functions

void anonymous_namespace{httpparser.cpp}::scanner_init (scanner_t *scanner, membuffer *bufptr)
 Initialize scanner.
 
int anonymous_namespace{httpparser.cpp}::is_separator_char (int c)
 Determines if the passed value is a separator.
 
int anonymous_namespace{httpparser.cpp}::is_identifier_char (int c)
 Determines if the passed value is permissible in token.
 
int anonymous_namespace{httpparser.cpp}::is_control_char (int c)
 Determines if the passed value is a control character.
 
int anonymous_namespace{httpparser.cpp}::is_qdtext_char (int c)
 Determines if the passed value is permissible in qdtext.
 
parse_status_t anonymous_namespace{httpparser.cpp}::scanner_get_token (scanner_t *scanner, memptr *token, token_type_t *tok_type)
 Reads next token from the input stream.
 
char * anonymous_namespace{httpparser.cpp}::scanner_get_str (scanner_t *scanner)
 Get pointer to next character in string.
 
int anonymous_namespace{httpparser.cpp}::httpmsg_compare (void *param1, void *param2)
 Compares name id in the http headers.
 
void anonymous_namespace{httpparser.cpp}::httpheader_free (void *msg)
 Free memory allocated for the http header.
 
parse_status_t anonymous_namespace{httpparser.cpp}::skip_blank_lines (scanner_t *scanner)
 Skips blank lines at the start of a msg.
 
parse_status_t anonymous_namespace{httpparser.cpp}::skip_lws (scanner_t *scanner)
 Skip linear whitespace.
 
parse_status_t anonymous_namespace{httpparser.cpp}::match_non_ws_string (scanner_t *scanner, memptr *str)
 Match a string without whitespace or CRLF (S)
 
parse_status_t anonymous_namespace{httpparser.cpp}::match_raw_value (scanner_t *scanner, memptr *raw_value)
 Matches a raw value in a the input.
 
parse_status_t anonymous_namespace{httpparser.cpp}::match_int (scanner_t *scanner, int base, int *value)
 Matches an unsigned integer value in the input.
 
parse_status_t anonymous_namespace{httpparser.cpp}::read_until_crlf (scanner_t *scanner, memptr *str)
 Reads data until end of line.
 
parse_status_t anonymous_namespace{httpparser.cpp}::match_char (scanner_t *scanner, char c, int case_sensitive)
 Compares a character to the next char in the scanner.
 
parse_status_t anonymous_namespace{httpparser.cpp}::vfmatch (scanner_t *scanner, const char *fmt, va_list argp)
 Extracts variable parameters depending on the passed in format parameter.
 
parse_status_t anonymous_namespace{httpparser.cpp}::match (scanner_t *scanner, const char *fmt,...)
 Matches a variable parameter list and takes necessary actions based on the data type specified.
 
void anonymous_namespace{httpparser.cpp}::httpmsg_init (http_message_t *msg)
 Initialize and allocate memory for http message.
 
void anonymous_namespace{httpparser.cpp}::parser_init (http_parser_t *parser)
 Initializes the parser object.
 
parse_status_t anonymous_namespace{httpparser.cpp}::parser_parse_requestline (http_parser_t *parser)
 Get HTTP Method, URL location and version information.
 
parse_status_t anonymous_namespace{httpparser.cpp}::parser_parse_entity_using_clen (http_parser_t *parser)
 Reads entity using content-length.
 
parse_status_t anonymous_namespace{httpparser.cpp}::parser_parse_chunky_body (http_parser_t *parser)
 Read data in the chunks.
 
parse_status_t anonymous_namespace{httpparser.cpp}::parser_parse_chunky_headers (http_parser_t *parser)
 Read headers at the end of the chunked entity.
 
parse_status_t anonymous_namespace{httpparser.cpp}::parser_parse_chunky_entity (http_parser_t *parser)
 Read entity using chunked transfer encoding.
 
parse_status_t anonymous_namespace{httpparser.cpp}::parser_parse_entity_until_close (http_parser_t *parser)
 Keep reading entity until the connection is closed.
 
void httpmsg_destroy (http_message_t *msg)
 Free memory allocated for the http message.
 
http_header_thttpmsg_find_hdr_str (http_message_t *msg, const char *header_name)
 Compares the header name with the header names stored in the linked list of messages.
 
http_header_thttpmsg_find_hdr (http_message_t *msg, int header_name_id, memptr *value)
 Finds header from a list, with the given 'name_id'.
 
parse_status_t matchstr (char *str, size_t slen, const char *fmt,...)
 Matches a variable parameter list with a string and takes actions based on the data type specified.
 
parse_status_t parser_parse_responseline (http_parser_t *parser)
 Get HTTP Method, URL location and version information.
 
parse_status_t parser_parse_headers (http_parser_t *parser)
 Get HTTP Method, URL location and version information.
 
parse_status_t parser_get_entity_read_method (http_parser_t *parser)
 Determines method to read entity.
 
parse_status_t parser_parse_entity (http_parser_t *parser)
 Determines method to read entity.
 
void parser_request_init (http_parser_t *parser)
 Initializes parser object for a request.
 
void parser_response_init (http_parser_t *parser, http_method_t request_method)
 Initializes parser object for a response.
 
parse_status_t parser_parse (http_parser_t *parser)
 The parser function.
 
parse_status_t parser_append (http_parser_t *parser, const char *buf, size_t buf_length)
 Append date to HTTP parser, and do the parsing.
 
int raw_to_int (memptr *raw_value, int base)
 Converts raw character data to integer value.
 
int raw_find_str (memptr *raw_value, const char *str)
 Find a substring from raw character string buffer.
 
const char * method_to_str (http_method_t method)
 A wrapper function that maps a method id to a method.
 
void print_http_headers (std::string_view log_msg, http_message_t *hmsg)
 Print the HTTP headers.
 

Variables

constexpr std::array< const UPnPsdk::str_int_entry, 11 > anonymous_namespace{httpparser.cpp}::Http_Method_Table
 Defines the HTTP methods.
 

Detailed Description

Contains functions for scanner and parser for http messages.

Definition in file httpparser.cpp.

Function Documentation

◆ httpmsg_destroy()

void httpmsg_destroy ( http_message_t msg)

Free memory allocated for the http message.

Parameters
[in,out]msgHTTP Message Object.

Definition at line 1273 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ httpmsg_find_hdr_str()

http_header_t * httpmsg_find_hdr_str ( http_message_t msg,
const char *  header_name 
)

Compares the header name with the header names stored in the linked list of messages.

Returns
  • Pointer to a header on success
  • nullptr on failure
Parameters
[in]msgHTTP Message Object.
[in]header_nameHeader name to be compared with.

Definition at line 1286 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ httpmsg_find_hdr()

http_header_t * httpmsg_find_hdr ( http_message_t msg,
int  header_name_id,
memptr value 
)

Finds header from a list, with the given 'name_id'.

Returns
  • Pointer to a header on success
  • nullptr on failure
Parameters
[in]msgHTTP Message Object.
[in]header_name_idHeader Name ID to be compared with.
[out]valueBuffer to get the ouput to.

Definition at line 1307 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matchstr()

parse_status_t matchstr ( char *  str,
size_t  slen,
const char *  fmt,
  ... 
)

Matches a variable parameter list with a string and takes actions based on the data type specified.

Returns
  • PARSE_OK
  • PARSE_NO_MATCH – failure to match pattern 'fmt'
  • PARSE_FAILURE – 'str' is bad input
Parameters
[in]strString to be matched.
[in]slenLength of the string.
[in]fmtPattern format for arguments (like printf()).
[in]...Variable list of arguments (like printf()).

Definition at line 1328 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_parse_responseline()

parse_status_t parser_parse_responseline ( http_parser_t parser)

Get HTTP Method, URL location and version information.

Returns
  • PARSE_OK
  • PARSE_SUCCESS
  • PARSE_FAILURE
Todo:
Check what function description is the right one. There was another found.
Parameters
[in,out]parserHTTP Parser object.

Definition at line 1362 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_parse_headers()

parse_status_t parser_parse_headers ( http_parser_t parser)

Get HTTP Method, URL location and version information.

Returns
  • PARSE_OK
  • PARSE_SUCCESS
  • PARSE_FAILURE
Todo:
Check what function description is the right one. There was another found.
Parameters
[in,out]parserHTTP Parser object.

Definition at line 1429 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_get_entity_read_method()

parse_status_t parser_get_entity_read_method ( http_parser_t parser)

Determines method to read entity.

Returns
On success: PARSE_CONTINUE_1
On error:
  • PARSE_FAILURE
  • PARSE_SUCCESS – no more reading to do
Parameters
[in,out]parserHTTP Parser object.

Definition at line 1552 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_parse_entity()

parse_status_t parser_parse_entity ( http_parser_t parser)

Determines method to read entity.

Returns
  • PARSE_OK
  • PARSE_FAILURE
  • PARSE_COMPLETE – no more reading to do
Todo:
Check what function description is the right one. There was another found.
Parameters
[in,out]parserHTTP Parser object.

Definition at line 1637 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_request_init()

void parser_request_init ( http_parser_t parser)

Initializes parser object for a request.

Parameters
[out]parserHTTP Parser Object.

Definition at line 1679 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_response_init()

void parser_response_init ( http_parser_t parser,
http_method_t  request_method 
)

Initializes parser object for a response.

Parameters
[out]parserHTTP Parser object.
[in]request_methodRequest method.

Definition at line 1686 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_parse()

parse_status_t parser_parse ( http_parser_t parser)

The parser function.

Depending on the position of the parser object the actual parsing function is invoked.

Returns
On success: PARSE_SUCCESS
On error:
  • PARSE_FAILURE
  • PARSE_INCOMPLETE
  • PARSE_INCOMPLETE_ENTITY
  • PARSE_NO_MATCH
Parameters
[in,out]parserHTTP Parser Object.

Definition at line 1695 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_append()

parse_status_t parser_append ( http_parser_t parser,
const char *  buf,
size_t  buf_length 
)

Append date to HTTP parser, and do the parsing.

Returns
On success: PARSE_SUCCESS
On error:
  • PARSE_FAILURE
  • PARSE_INCOMPLETE
  • PARSE_INCOMPLETE_ENTITY
  • PARSE_NO_MATCH
Parameters
[in,out]parserHTTP Parser object.
[in]bufbuffer to be appended to the parser.
[in]buf_lengthSize of the buffer.

Definition at line 1736 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raw_to_int()

int raw_to_int ( memptr raw_value,
int  base 
)

Converts raw character data to integer value.

Returns
integer
Parameters
[in]raw_valueBuffer to be converted.
baseBase to use for conversion.

Definition at line 1753 of file httpparser.cpp.

+ Here is the caller graph for this function:

◆ raw_find_str()

int raw_find_str ( memptr raw_value,
const char *  str 
)

Find a substring from raw character string buffer.

Side effects: raw_value is transformed to lowercase.

Returns
integer - index at which the substring is found.
Parameters
[in]raw_valueBuffer containg the string.
[in]strSubstring to be found.

Definition at line 1771 of file httpparser.cpp.

+ Here is the caller graph for this function:

◆ method_to_str()

const char * method_to_str ( http_method_t  method)

A wrapper function that maps a method id to a method.

nameConverts a http_method id stored in the HTTP Method.

Returns
Pointer to the HTTP Method.
Parameters
[in]methodHTTP method.

Definition at line 1801 of file httpparser.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_http_headers()

void print_http_headers ( std::string_view  log_msg,
http_message_t hmsg 
)

Print the HTTP headers.

Function is mainly used for debugging.

Parameters
[in]log_msglog message number ("MSGxxxx").
[in]hmsgHTTP Message object.

Definition at line 1815 of file httpparser.cpp.

+ Here is the call graph for this function: