Functions to parse UPnP messages like requests and responses. More...
#include <LinkedList.hpp>
#include <membuffer.hpp>
#include <upnp.hpp>
#include <uri.hpp>
#include <UPnPsdk/strintmap.hpp>
Go to the source code of this file.
Classes | |
struct | scanner_t |
Structure of a scanner object. More... | |
struct | http_header_t |
Structure of an HTTP header object. More... | |
struct | http_parser_t |
Structure of an HTTP parser object. More... | |
Macros | |
Constants that define the read method. | |
#define | ENTREAD_DETERMINE_READ_METHOD 1 |
Defines read method. | |
#define | ENTREAD_USING_CLEN 2 |
Defines read method. | |
#define | ENTREAD_USING_CHUNKED 3 |
Defines read method. | |
#define | ENTREAD_UNTIL_CLOSE 4 |
Defines read method. | |
#define | ENTREAD_CHUNKY_BODY 5 |
Defines read method. | |
#define | ENTREAD_CHUNKY_HEADERS 6 |
Defines read method. | |
Different types of HTTP headers. | |
#define | HDR_UNKNOWN -1 |
Type of a HTTP header. | |
#define | HDR_CACHE_CONTROL 1 |
Type of a HTTP header. | |
#define | HDR_CALLBACK 2 |
Type of a HTTP header. | |
#define | HDR_CONTENT_LENGTH 3 |
Type of a HTTP header. | |
#define | HDR_CONTENT_TYPE 4 |
Type of a HTTP header. | |
#define | HDR_DATE 5 |
Type of a HTTP header. | |
#define | HDR_EXT 6 |
Type of a HTTP header. | |
#define | HDR_HOST 7 |
Type of a HTTP header. | |
#define | HDR_LOCATION 11 |
Type of a HTTP header. | |
#define | HDR_MAN 12 |
Type of a HTTP header. | |
#define | HDR_MX 13 |
Type of a HTTP header. | |
#define | HDR_NT 14 |
Type of a HTTP header. | |
#define | HDR_NTS 15 |
Type of a HTTP header. | |
#define | HDR_SERVER 16 |
Type of a HTTP header. | |
#define | HDR_SEQ 17 |
Type of a HTTP header. | |
#define | HDR_SID 18 |
Type of a HTTP header. | |
#define | HDR_SOAPACTION 19 |
Type of a HTTP header. | |
#define | HDR_ST 20 |
Type of a HTTP header. | |
#define | HDR_TIMEOUT 21 |
Type of a HTTP header. | |
#define | HDR_TRANSFER_ENCODING 22 |
Type of a HTTP header. | |
#define | HDR_USN 23 |
Type of a HTTP header. | |
#define | HDR_USER_AGENT 24 |
Type of a HTTP header. | |
Adding new header definitions | |
#define | HDR_ACCEPT 25 |
Header definition. | |
#define | HDR_ACCEPT_ENCODING 26 |
Header definition. | |
#define | HDR_ACCEPT_CHARSET 27 |
Header definition. | |
#define | HDR_ACCEPT_LANGUAGE 28 |
Header definition. | |
#define | HDR_ACCEPT_RANGE 29 |
Header definition. | |
#define | HDR_CONTENT_ENCODING 30 |
Header definition. | |
#define | HDR_CONTENT_LANGUAGE 31 |
Header definition. | |
#define | HDR_CONTENT_LOCATION 32 |
Header definition. | |
#define | HDR_CONTENT_RANGE 33 |
Header definition. | |
#define | HDR_IF_RANGE 34 |
Header definition. | |
#define | HDR_RANGE 35 |
Header definition. | |
#define | HDR_TE 36 |
Header definition. | |
Enumerations | |
enum | parser_pos_t { POS_REQUEST_LINE , POS_RESPONSE_LINE , POS_HEADERS , POS_ENTITY , POS_COMPLETE } |
Type of a parser position. More... | |
enum | http_method_t { HTTPMETHOD_PUT = UPNP_HTTPMETHOD_PUT , HTTPMETHOD_DELETE = UPNP_HTTPMETHOD_DELETE , HTTPMETHOD_GET = UPNP_HTTPMETHOD_GET , HTTPMETHOD_HEAD = UPNP_HTTPMETHOD_HEAD , HTTPMETHOD_POST = UPNP_HTTPMETHOD_POST , HTTPMETHOD_MPOST , HTTPMETHOD_SUBSCRIBE , HTTPMETHOD_UNSUBSCRIBE , HTTPMETHOD_NOTIFY , HTTPMETHOD_MSEARCH , HTTPMETHOD_UNKNOWN , SOAPMETHOD_POST , HTTPMETHOD_SIMPLEGET } |
Method in a HTTP request. More... | |
enum | parse_status_t { PARSE_SUCCESS = 0 , PARSE_INCOMPLETE , PARSE_INCOMPLETE_ENTITY , PARSE_FAILURE , PARSE_OK , PARSE_NO_MATCH , PARSE_CONTINUE_1 } |
Status of parsing. More... | |
Functions | |
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'. | |
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_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_parse_entity (http_parser_t *parser) |
Determines method to read entity. | |
parse_status_t | parser_get_entity_read_method (http_parser_t *parser) |
Determines method to read entity. | |
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. | |
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. | |
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, 33 > | Http_Header_Names |
Assigns header-name id to its text representation. | |
Functions to parse UPnP messages like requests and responses.
Definition in file httpparser.hpp.
struct scanner_t |
Structure of a scanner object.
Definition at line 76 of file httpparser.hpp.
Class Members | ||
---|---|---|
membuffer * | msg | Raw http message. |
size_t | cursor | Current position in buffer. |
int | entire_msg_loaded |
Completeness of 'msg'.
|
struct http_header_t |
Structure of an HTTP header object.
Definition at line 211 of file httpparser.hpp.
Class Members | ||
---|---|---|
memptr | name | Header name as a string. |
int | name_id | Header name id (for a selective group of headers only). |
membuffer | value | Raw-value; could be multi-lined; min-length = 0. |
membuffer | name_buf | (Private use – don't touch.) |
struct http_message_t |
Structure of an HTTP message.
Definition at line 223 of file httpparser.hpp.
Class Members | ||
---|---|---|
int | initialized | Indicates if the object is initialized. |
http_method_t | method | Http method of an outgoing request. |
uri_type | uri | Type of a uri, e.g. absolute, relative, etc. |
http_method_t | request_method | Http method of an incoming response. |
int | status_code | ??? |
membuffer | status_msg | ??? |
size_t | amount_discarded | The amount of data that's been read by the user, that's no longer in the raw message buffer. |
int | is_request | If 1, msg is a request, else response. |
int | major_version | Http major version. |
int | minor_version | Http minor version. |
LinkedList | headers | List of headers. |
memptr | entity | message body(entity). |
membuffer | msg | entire raw message. |
char * | urlbuf | storage for url string. |
struct http_parser_t |
Structure of an HTTP parser object.
Definition at line 272 of file httpparser.hpp.
Class Members | ||
---|---|---|
http_message_t | msg |
entire raw message This contains the complete HTTP message with preceding header and message body. There is also the http_parser_t::entity_start_position available that points to the message body in the message. |
int | http_error_code | read-only; in case of parse error, this contains the HTTP error code (4XX or 5XX). |
int | valid_ssdp_notify_hack | read-only; this is set to 1 if a NOTIFY request has no content-length. used to read valid sspd notify msg. |
parser_pos_t | position | Private data – don't touch. |
int | ent_position | Private data – don't touch. |
unsigned int | content_length | Private data – don't touch. |
size_t | chunk_size | Private data – don't touch. |
size_t | entity_start_position | Offset in the raw message buffer, which contains the message body. preceding this are the headers of the message. |
scanner_t | scanner | ??? |
#define ENTREAD_DETERMINE_READ_METHOD 1 |
Defines read method.
Definition at line 58 of file httpparser.hpp.
#define ENTREAD_USING_CLEN 2 |
Defines read method.
Definition at line 59 of file httpparser.hpp.
#define ENTREAD_USING_CHUNKED 3 |
Defines read method.
Definition at line 60 of file httpparser.hpp.
#define ENTREAD_UNTIL_CLOSE 4 |
Defines read method.
Definition at line 61 of file httpparser.hpp.
#define ENTREAD_CHUNKY_BODY 5 |
Defines read method.
Definition at line 62 of file httpparser.hpp.
#define ENTREAD_CHUNKY_HEADERS 6 |
Defines read method.
Definition at line 63 of file httpparser.hpp.
#define HDR_UNKNOWN -1 |
Type of a HTTP header.
Definition at line 111 of file httpparser.hpp.
#define HDR_CACHE_CONTROL 1 |
Type of a HTTP header.
Definition at line 112 of file httpparser.hpp.
#define HDR_CALLBACK 2 |
Type of a HTTP header.
Definition at line 113 of file httpparser.hpp.
#define HDR_CONTENT_LENGTH 3 |
Type of a HTTP header.
Definition at line 114 of file httpparser.hpp.
#define HDR_CONTENT_TYPE 4 |
Type of a HTTP header.
Definition at line 115 of file httpparser.hpp.
#define HDR_DATE 5 |
Type of a HTTP header.
Definition at line 116 of file httpparser.hpp.
#define HDR_EXT 6 |
Type of a HTTP header.
Definition at line 117 of file httpparser.hpp.
#define HDR_HOST 7 |
Type of a HTTP header.
Definition at line 118 of file httpparser.hpp.
#define HDR_LOCATION 11 |
Type of a HTTP header.
Definition at line 122 of file httpparser.hpp.
#define HDR_MAN 12 |
Type of a HTTP header.
Definition at line 123 of file httpparser.hpp.
#define HDR_MX 13 |
Type of a HTTP header.
Definition at line 124 of file httpparser.hpp.
#define HDR_NT 14 |
Type of a HTTP header.
Definition at line 125 of file httpparser.hpp.
#define HDR_NTS 15 |
Type of a HTTP header.
Definition at line 126 of file httpparser.hpp.
#define HDR_SERVER 16 |
Type of a HTTP header.
Definition at line 127 of file httpparser.hpp.
#define HDR_SEQ 17 |
Type of a HTTP header.
Definition at line 128 of file httpparser.hpp.
#define HDR_SID 18 |
Type of a HTTP header.
Definition at line 129 of file httpparser.hpp.
#define HDR_SOAPACTION 19 |
Type of a HTTP header.
Definition at line 130 of file httpparser.hpp.
#define HDR_ST 20 |
Type of a HTTP header.
Definition at line 131 of file httpparser.hpp.
#define HDR_TIMEOUT 21 |
Type of a HTTP header.
Definition at line 132 of file httpparser.hpp.
#define HDR_TRANSFER_ENCODING 22 |
Type of a HTTP header.
Definition at line 133 of file httpparser.hpp.
#define HDR_USN 23 |
Type of a HTTP header.
Definition at line 134 of file httpparser.hpp.
#define HDR_USER_AGENT 24 |
Type of a HTTP header.
Definition at line 135 of file httpparser.hpp.
#define HDR_ACCEPT 25 |
Header definition.
Definition at line 141 of file httpparser.hpp.
#define HDR_ACCEPT_ENCODING 26 |
Header definition.
Definition at line 142 of file httpparser.hpp.
#define HDR_ACCEPT_CHARSET 27 |
Header definition.
Definition at line 143 of file httpparser.hpp.
#define HDR_ACCEPT_LANGUAGE 28 |
Header definition.
Definition at line 144 of file httpparser.hpp.
#define HDR_ACCEPT_RANGE 29 |
Header definition.
Definition at line 145 of file httpparser.hpp.
#define HDR_CONTENT_ENCODING 30 |
Header definition.
Definition at line 146 of file httpparser.hpp.
#define HDR_CONTENT_LANGUAGE 31 |
Header definition.
Definition at line 147 of file httpparser.hpp.
#define HDR_CONTENT_LOCATION 32 |
Header definition.
Definition at line 148 of file httpparser.hpp.
#define HDR_CONTENT_RANGE 33 |
Header definition.
Definition at line 149 of file httpparser.hpp.
#define HDR_IF_RANGE 34 |
Header definition.
Definition at line 150 of file httpparser.hpp.
#define HDR_RANGE 35 |
Header definition.
Definition at line 151 of file httpparser.hpp.
#define HDR_TE 36 |
Header definition.
Definition at line 152 of file httpparser.hpp.
enum parser_pos_t |
Type of a parser position.
Enumerator | |
---|---|
POS_REQUEST_LINE | Position request line. |
POS_RESPONSE_LINE | Position response line. |
POS_HEADERS | Position headers. |
POS_ENTITY | Position entity. |
POS_COMPLETE | Position complete. |
Definition at line 67 of file httpparser.hpp.
enum http_method_t |
Method in a HTTP request.
Definition at line 91 of file httpparser.hpp.
enum parse_status_t |
Status of parsing.
Definition at line 193 of file httpparser.hpp.
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.
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_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_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.
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_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.
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.
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.
|
inlineconstexpr |
Assigns header-name id to its text representation.
Definition at line 157 of file httpparser.hpp.