Mstdlib-1.24.0
|
Typedefs | |
typedef struct M_http_simple_read | M_http_simple_read_t |
Reads a full HTTP message. Useful for small messages. All data is contained within on object for easy processing.
Will attempt to decode body data based on the detected charset unless M_HTTP_SIMPLE_READ_NODECODE_BODY is set.
Use M_http_simple_read_is_body_form_data() to determine which accessors to use. M_http_simple_read_codec will dictated the current encoding of the body data. If form encoded this is the encoding of the key value pairs not the raw body data. If not form data this is the encoding of the body data. M_http_simple_read_is_body will always return body data. If from encoded the data will still be form encoded.
Codec will be set to the codec of the body data. Unless form encoded, in which case it is the codec for the key value pairs from M_http_simple_read_is_body_form_data().
If the encoding could not be detected or is not supported the codec will be unknown. Use M_http_simple_read_charset() to determine the charset of the data.
Charset and codec will only be read from the Content-Type header. Content type and encoding set in an HTML tag is not supported.
typedef struct M_http_simple_read M_http_simple_read_t |
M_http_error_t M_http_simple_read | ( | M_http_simple_read_t ** | simple, |
const unsigned char * | data, | ||
size_t | data_len, | ||
M_uint32 | flags, | ||
size_t * | len_read | ||
) |
Read the next HTTP message from the given buffer, store results in a new M_http_simple_read_t object.
Will return M_HTTP_ERROR_MOREDATA if we need to wait for more data to get a complete message.
[out] | simple | Place to store new M_http_simple_read_t object. Can be NULL to check for valid message. Will only be set on M_HTTP_ERROR_SUCCESS, and M_HTTP_ERROR_SUCCESS_MORE_POSSIBLE. |
[in] | data | Buffer containing HTTP messages to read. |
[in] | data_len | Length of data. |
[in] | flags | Read options (OR'd combo of M_http_simple_read_flags_t). |
[in] | len_read | Num bytes consumed from data (may be NULL, if caller doesn't need this info). Will be set on error indicating the location in the message that generated the error. |
M_http_error_t M_http_simple_read_parser | ( | M_http_simple_read_t ** | simple, |
M_parser_t * | parser, | ||
M_uint32 | flags | ||
) |
Read the next HTTP message from the given parser.
Will return M_HTTP_ERROR_MOREDATA if we need to wait for more data to get a complete message. No data will be dropped from the parser, in this case.
On all other return values the parser will advance and data consumed. On a hard ERROR condition the parser will start at the point of the error. If this is undesirable, the parser should be marked and rewound after this function is called.
[out] | simple | Place to store new M_http_simple_read_t object. Can be NULL to check for valid message. |
[in] | parser | Buffer containing HTTP messages to read. |
[in] | flags | Read options (OR'd combo of M_http_simple_read_flags_t). |
void M_http_simple_read_destroy | ( | M_http_simple_read_t * | http | ) |
Destroy the given M_http_simple_read_t object.
[in] | http | object to destroy |
M_http_message_type_t M_http_simple_read_message_type | ( | const M_http_simple_read_t * | simple | ) |
Return the type of the parsed message.
[in] | simple | Parsed HTTP message. |
M_http_version_t M_http_simple_read_version | ( | const M_http_simple_read_t * | simple | ) |
Return the HTTP protocol version of the parsed message.
[in] | simple | Parsed HTTP message. |
M_uint32 M_http_simple_read_status_code | ( | const M_http_simple_read_t * | simple | ) |
Return the HTTP status code of the parsed message.
The status code is only set for response messages (type == M_HTTP_MESSAGE_TYPE_RESPONSE). If the parsed message wasn't a response, the returned status code will be 0.
[in] | simple | Parsed HTTP message. |
const char * M_http_simple_read_reason_phrase | ( | const M_http_simple_read_t * | simple | ) |
Return the human-readable status of the parsed message.
This is the text that goes with the HTTP status code in the message.
The reason phrase is only set for response messages (type == M_HTTP_MESSAGE_TYPE_RESPONSE). If the parsed message wasn't a response, the returned string will be NULL
.
[in] | simple | Parsed HTTP message. |
NULL
if this isn't a response.M_http_method_t M_http_simple_read_method | ( | const M_http_simple_read_t * | simple | ) |
Return the HTTP method (GET, POST, etc) of the parsed message.
The method is only set for request messages (type == M_HTTP_MESSAGE_TYPE_REQUEST). If the parsed message wasn't a request, M_HTTP_METHOD_UNKNOWN will be returned.
[in] | simple | Parsed HTTP message. |
const char * M_http_simple_read_uri | ( | const M_http_simple_read_t * | simple | ) |
Return the full URI (port, path and query) of the parsed message.
Only request messages have a URI. If the parsed message wasn't a request, the returned string will be NULL
.
[in] | simple | Parsed HTTP message. |
NULL
if this isn't a request.const char * M_http_simple_read_path | ( | const M_http_simple_read_t * | simple | ) |
Return the path component of the URI from the parsed message.
Only request messages have a URI. If the parsed message wasn't a request, the function will return NULL
.
The path may be relative or absolute.
[in] | simple | Parsed HTTP message. |
NULL
if this isn't a request.const char * M_http_simple_read_query_string | ( | const M_http_simple_read_t * | simple | ) |
Return the query component of the URI from the parsed message.
The returned query string hasn't been processed in any way. Call M_http_simple_read_query_args() instead to process the query and return its contents as a set of key-value pairs.
Only request messages have a URI. If the parsed message wasn't a request, the function will return NULL
.
Not all requests have a query string embedded in the URI. This is normally seen in GET requests, but it's not always present even there.
[in] | simple | Parsed HTTP message. |
NULL
if not present.const M_hash_dict_t * M_http_simple_read_query_args | ( | const M_http_simple_read_t * | simple | ) |
Parse arguments from query component of URI as key-value pairs.
Processes the query string (if any), then returns a key->value mapping of all the values present in the string.
[in] | simple | Parsed HTTP message. |
NULL
if there were none.const char * M_http_simple_read_host | ( | const M_http_simple_read_t * | simple | ) |
Return the host.
Only request messages have a host. If the parsed message wasn't a request, the function will return NULL.
The host will be read from the URI and fall back to the Host header. If neither are present the host will be NULL.
[in] | simple | Parsed HTTP message. |
M_bool M_http_simple_read_port | ( | const M_http_simple_read_t * | simple, |
M_uint16 * | port | ||
) |
Return the port number.
Only request messages have a port. If the parsed message wasn't a request, the function will return M_FALSE and set port to 0.
The port will be read from the URI and fall back to the Host header. If neither are present the port will be returned as 0. In this case it should be assumed to be 80.
[in] | simple | Parsed HTTP message. |
[out] | port | Place to store port number. May be NULL , if you're just checking to see if a port is present. |
M_hash_dict_t * M_http_simple_read_headers_dict | ( | const M_http_simple_read_t * | simple | ) |
Get headers from parsed message as key-multivalue pairs.
Note that some headers may contain a list of multiple values, so the returned M_hash_dict_t is a multimap (one key may map to a list of values). The first entry in the list is the first item in the value list if there are multiple values.
Modfiers that are part of the value are included with the value.
Header names are not case-sensitive, when doing lookups into the returned dictionary.
[in] | simple | Parsed HTTP message. |
M_list_str_t * M_http_simple_read_headers | ( | const M_http_simple_read_t * | simple | ) |
Get a list of headers.
Header names are not case-sensitive.
[in] | simple | Parsed HTTP message. |
char * M_http_simple_read_header | ( | const M_http_simple_read_t * | simple, |
const char * | key | ||
) |
Get value of the named header from the parsed message.
The key is not case-sensitive - it will match header names that only differ because of capitalization.
Note that some headers may contain a list of multiple values. For these headers, this function will return a comma-delimited list of values. Some extra white space may be added in addition to the commas.
[in] | simple | Parsed HTTP message. |
[in] | key | Name of header to retrieve values from. |
NULL
if no data found.const M_list_str_t * M_http_simple_read_get_set_cookie | ( | const M_http_simple_read_t * | simple | ) |
Return list of values from all Set-Cookie headers in the parsed message.
The returned list of values is stable-sorted alphabetically.
[in] | simple | Parsed HTTP message. |
M_bool M_http_simple_read_is_body_form_data | ( | const M_http_simple_read_t * | simple | ) |
Whether the decoded body data is form encoded and can be accessed using M_http_simple_read_body_form_data(). If the text codec is set, the codec represents the codec of the form data key value pairs. While M_http_simple_read_body() will still be encoded as form data.
[in] | simple | Parsed HTTP message. |
const unsigned char * M_http_simple_read_body | ( | const M_http_simple_read_t * | simple, |
size_t * | len | ||
) |
Return the body of the parsed message (if any).
If the body is application/x-www-form-urlencoded this will return the raw form data encoded body. Form data decodes to key value pairs so accessing the data will need to be used through M_http_simple_read_body_form_data().
When not form encoded. The body data will be in be represented by the codec from M_http_simple_read_codec().
[in] | simple | Parsed HTTP message. |
[out] | len | Place to store length of body (may be NULL ). |
const M_hash_dict_t * M_http_simple_read_body_form_data | ( | const M_http_simple_read_t * | simple | ) |
Return the body of the parsed message (if any) if it was form data encoded.
This will only be filled when the content-type is application/x-www-form-urlencoded and there is key value pair body data. The data within the key value pairs will have be represented by the codec from M_http_simple_read_codec().
[in] | simple | Parsed HTTP message. |
const char * M_http_simple_read_content_type | ( | const M_http_simple_read_t * | simple | ) |
Get the content type.
May be empty if the content type was not set. Or if it was application/x-www-form-urlencoded and the body was auto decoded.
application/x-www-form-urlencoded does not allows allow the encoding to be known. Preventing auto deciding from taking place. Leaving this as application/x-www-form-urlencoded and the codec as unknown.
[in] | simple | Parsed HTTP message. |
M_textcodec_codec_t M_http_simple_read_codec | ( | const M_http_simple_read_t * | simple | ) |
Get the codec of the data.
Codec is detected by charset from the Content-Type header. May be unknown if charset was not present or if the charset is not supported by mstdlib's text encoding functionality.
If body decoding takes place and the data will have been be decoded to utf-8. The codec will have been updated to utf-8 and the content length will have been updated to match the new body length.
[in] | simple | Parsed HTTP message. |
const char * M_http_simple_read_charset | ( | const M_http_simple_read_t * | simple | ) |
Get the text charset of the data.
The charater set as defined in the Content-Type header. This should correspond to codec returned by M_http_simple_read_codec. However, if codec is unknown due to not being supported by mstdlib's text codec, this is the charset used by the data. Body decoding will not take place if codec is unknown. It is up to the application to determine how to decoded the body data in this situation.
[in] | simple | Parsed HTTP message. |