Contains functions for scanner and parser for http messages. More...
#include <httpparser.hpp>
#include <statcodes.hpp>
#include <upnpdebug.hpp>
#include <UPnPsdk/synclog.hpp>
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_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. | |
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'. | |
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. | |
Contains functions for scanner and parser for http messages.
Definition in file httpparser.cpp.
void httpmsg_destroy | ( | http_message_t * | msg | ) |
Free memory allocated for the http message.
[in,out] | msg | HTTP Message Object. |
Definition at line 1273 of file httpparser.cpp.
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.
[in] | msg | HTTP Message Object. |
[in] | header_name | Header name to be compared with. |
Definition at line 1286 of file httpparser.cpp.
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'.
[in] | msg | HTTP Message Object. |
[in] | header_name_id | Header Name ID to be compared with. |
[out] | value | Buffer to get the ouput to. |
Definition at line 1307 of file httpparser.cpp.
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.
[in] | str | String to be matched. |
[in] | slen | Length of the string. |
[in] | fmt | Pattern format for arguments (like printf()). |
[in] | ... | Variable list of arguments (like printf()). |
Definition at line 1328 of file httpparser.cpp.
parse_status_t parser_parse_responseline | ( | http_parser_t * | parser | ) |
Get HTTP Method, URL location and version information.
[in,out] | parser | HTTP Parser object. |
Definition at line 1362 of file httpparser.cpp.
parse_status_t parser_parse_headers | ( | http_parser_t * | parser | ) |
Get HTTP Method, URL location and version information.
[in,out] | parser | HTTP Parser object. |
Definition at line 1429 of file httpparser.cpp.
parse_status_t parser_get_entity_read_method | ( | http_parser_t * | parser | ) |
Determines method to read entity.
[in,out] | parser | HTTP Parser object. |
Definition at line 1552 of file httpparser.cpp.
parse_status_t parser_parse_entity | ( | http_parser_t * | parser | ) |
Determines method to read entity.
[in,out] | parser | HTTP Parser object. |
Definition at line 1637 of file httpparser.cpp.
void parser_request_init | ( | http_parser_t * | parser | ) |
Initializes parser object for a request.
[out] | parser | HTTP Parser Object. |
Definition at line 1679 of file httpparser.cpp.
void parser_response_init | ( | http_parser_t * | parser, |
http_method_t | request_method | ||
) |
Initializes parser object for a response.
[out] | parser | HTTP Parser object. |
[in] | request_method | Request method. |
Definition at line 1686 of file httpparser.cpp.
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.
[in,out] | parser | HTTP Parser Object. |
Definition at line 1695 of file httpparser.cpp.
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.
[in,out] | parser | HTTP Parser object. |
[in] | buf | buffer to be appended to the parser. |
[in] | buf_length | Size of the buffer. |
Definition at line 1736 of file httpparser.cpp.
int raw_to_int | ( | memptr * | raw_value, |
int | base | ||
) |
Converts raw character data to integer value.
[in] | raw_value | Buffer to be converted. |
base | Base to use for conversion. |
Definition at line 1753 of file httpparser.cpp.
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.
[in] | raw_value | Buffer containg the string. |
[in] | str | Substring to be found. |
Definition at line 1771 of file httpparser.cpp.
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.
[in] | method | HTTP method. |
Definition at line 1801 of file httpparser.cpp.
void print_http_headers | ( | std::string_view | log_msg, |
http_message_t * | hmsg | ||
) |
Print the HTTP headers.
Function is mainly used for debugging.
[in] | log_msg | log message number ("MSGxxxx"). |
[in] | hmsg | HTTP Message object. |
Definition at line 1815 of file httpparser.cpp.