Soletta™ Framework
|
API to handle Hypertext Transfer Protocol (HTTP). More...
Modules | |
HTTP Client | |
API to perform HTTP(s) requests. | |
HTTP Server | |
API to make it possible to run an HTTP server to deliver and set values from other components. | |
Data Structures | |
struct | sol_http_content_type_priority |
Used to rank content type priorities. More... | |
struct | sol_http_param_value |
Used to define an HTTP parameter. More... | |
struct | sol_http_params |
Keep vector of HTTP parameters to be sent in a request. More... | |
struct | sol_http_response |
Handle for an HTTP response. More... | |
struct | sol_http_url |
Handle for an HTTP URL. More... | |
Macros | |
#define | SOL_HTTP_PARAMS_CHECK_API_VERSION(params_,...) |
Macro used to check if a struct sol_http_params has the expected API version. More... | |
#define | SOL_HTTP_PARAMS_CHECK_API_VERSION_GOTO(params_, label_) |
Macro used to check if a struct sol_http_params has the expected API version. More... | |
#define | SOL_HTTP_PARAMS_FOREACH_IDX(param, itrvar, idx) |
Macro used to iterate over a vector of HTTP parameters. More... | |
#define | SOL_HTTP_REQUEST_PARAM_ALLOW_REDIR(setting_) SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_ALLOW_REDIR, setting_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_ALLOW_REDIR and true or false as value. More... | |
#define | SOL_HTTP_REQUEST_PARAM_AUTH_BASIC(username_, password_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_AUTH_BASIC, username and password. More... | |
#define | SOL_HTTP_REQUEST_PARAM_BOOL(type_, setting_) |
Macro to set a struct sol_http_param_value with a boolean and type passed as argument. More... | |
#define | SOL_HTTP_REQUEST_PARAM_COOKIE(key_, value_) SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_COOKIE, key_, value_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_COOKIE and key-value. More... | |
#define | SOL_HTTP_REQUEST_PARAM_HEADER(header_, content_) SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_HEADER, header_, content_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_HEADER, a header and content. More... | |
#define | SOL_HTTP_REQUEST_PARAM_KEY_VALUE(type_, key_, value_) |
Macro to set a struct sol_http_param_value with key-value and type passed as argument. More... | |
#define | SOL_HTTP_REQUEST_PARAM_POST_DATA_CONTENTS(key_, value_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_DATA and the given value. More... | |
#define | SOL_HTTP_REQUEST_PARAM_POST_DATA_FILE(key_, filename_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_DATA and the contents of filename_ . More... | |
#define | SOL_HTTP_REQUEST_PARAM_POST_FIELD(key_, value_) SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_POST_FIELD, key_, value_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_FIELD and key-value. More... | |
#define | SOL_HTTP_REQUEST_PARAM_QUERY(key_, value_) SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_QUERY_PARAM, key_, value_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_QUERY_PARAM and key-value. More... | |
#define | SOL_HTTP_REQUEST_PARAM_TIMEOUT(setting_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_TIMEOUT and timeout value. More... | |
#define | SOL_HTTP_REQUEST_PARAM_VERBOSE(setting_) SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_VERBOSE, setting_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_VERBOSE and true or false as value. More... | |
#define | SOL_HTTP_REQUEST_PARAMS_INIT |
Macro used to initialize a struct sol_http_params with empty vector. More... | |
#define | SOL_HTTP_RESPONSE_CHECK_API(response_,...) |
Macro used to check if a struct sol_http_response is valid (different from NULL ) and has the expected API version or return. More... | |
#define | SOL_HTTP_RESPONSE_CHECK_API_GOTO(response_, label) |
Macro used to check if a struct sol_http_response is valid (different from NULL ) and has the expected API version or goto a label. More... | |
#define | SOL_HTTP_RESPONSE_CHECK_API_VERSION(response_,...) |
Macro used to check if a struct sol_http_response has the expected API version or return. More... | |
#define | SOL_HTTP_RESPONSE_CHECK_API_VERSION_GOTO(response_, label) |
Macro used to check if a struct sol_http_response has the expected API version or goto a label. More... | |
Typedefs | |
typedef struct sol_http_param_value | sol_http_param_value |
Used to define an HTTP parameter. More... | |
typedef struct sol_http_params | sol_http_params |
Keep vector of HTTP parameters to be sent in a request. More... | |
typedef struct sol_http_response | sol_http_response |
Handle for an HTTP response. More... | |
typedef struct sol_http_url | sol_http_url |
Handle for an HTTP URL. More... | |
Functions | |
void | sol_http_content_type_priorities_array_clear (struct sol_vector *priorities) |
Clears the priorities array. More... | |
int | sol_http_create_full_uri (struct sol_buffer *buf, const struct sol_http_url url, const struct sol_http_params *params) |
Creates an URI based on struct sol_http_url and its parameters. More... | |
int | sol_http_create_uri (struct sol_buffer *buf, const struct sol_str_slice base_uri, const struct sol_http_params *params) |
A simpler version of sol_http_create_full_uri(). More... | |
static int | sol_http_create_uri_from_str (struct sol_buffer *buf, const char *base_url, const struct sol_http_params *params) |
A wrapper on top of sol_http_create_uri() More... | |
int | sol_http_decode_params (const struct sol_str_slice params_slice, enum sol_http_param_type type, struct sol_http_params *params) |
Decodes HTTP parameters of a given type. More... | |
int | sol_http_decode_slice (struct sol_buffer *buf, const struct sol_str_slice value) |
Decodes an URL string. More... | |
int | sol_http_encode_params (struct sol_buffer *buf, enum sol_http_param_type type, const struct sol_http_params *params) |
Encodes HTTP parameters of a given type. More... | |
int | sol_http_encode_slice (struct sol_buffer *buf, const struct sol_str_slice value) |
Encodes an URL string. More... | |
int | sol_http_params_add (struct sol_http_params *params, struct sol_http_param_value value) |
Add a new parameter to HTTP parameters vector. More... | |
int | sol_http_params_add_copy (struct sol_http_params *params, struct sol_http_param_value value) |
Add a new parameter to HTTP parameters vector copying strings. More... | |
void | sol_http_params_clear (struct sol_http_params *params) |
Clear vector of HTTP parameters. More... | |
static void | sol_http_params_init (struct sol_http_params *params) |
Initialize HTTP parameters struct with an empty vector. More... | |
int | sol_http_parse_content_type_priorities (const struct sol_str_slice content_type, struct sol_vector *priorities) |
Sort the content type slice based on its priorities. More... | |
int | sol_http_split_post_field (const char *query, struct sol_http_params *params) |
Split post/field string into parameters. More... | |
int | sol_http_split_query (const char *query, struct sol_http_params *params) |
Split query into parameters. More... | |
int | sol_http_split_uri (const struct sol_str_slice full_uri, struct sol_http_url *url) |
Split an URI. More... | |
API to handle Hypertext Transfer Protocol (HTTP).
#define SOL_HTTP_PARAMS_CHECK_API_VERSION | ( | params_, | |
... | |||
) |
Macro used to check if a struct sol_http_params has the expected API version.
In case it's a wrong version, it'll return extra arguments passed to the macro.
#define SOL_HTTP_PARAMS_CHECK_API_VERSION_GOTO | ( | params_, | |
label_ | |||
) |
Macro used to check if a struct sol_http_params has the expected API version.
In case it's a wrong version, it'll go to label.
#define SOL_HTTP_PARAMS_FOREACH_IDX | ( | param, | |
itrvar, | |||
idx | |||
) |
Macro used to iterate over a vector of HTTP parameters.
Referenced by response_cb().
#define SOL_HTTP_REQUEST_PARAM_ALLOW_REDIR | ( | setting_ | ) | SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_ALLOW_REDIR, setting_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_ALLOW_REDIR and true
or false
as value.
#define SOL_HTTP_REQUEST_PARAM_AUTH_BASIC | ( | username_, | |
password_ | |||
) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_AUTH_BASIC, username and password.
#define SOL_HTTP_REQUEST_PARAM_BOOL | ( | type_, | |
setting_ | |||
) |
Macro to set a struct sol_http_param_value with a boolean and type passed as argument.
#define SOL_HTTP_REQUEST_PARAM_COOKIE | ( | key_, | |
value_ | |||
) | SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_COOKIE, key_, value_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_COOKIE and key-value.
#define SOL_HTTP_REQUEST_PARAM_HEADER | ( | header_, | |
content_ | |||
) | SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_HEADER, header_, content_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_HEADER, a header and content.
Referenced by request_cb(), and sol_http_response_set_sse_headers().
#define SOL_HTTP_REQUEST_PARAM_KEY_VALUE | ( | type_, | |
key_, | |||
value_ | |||
) |
Macro to set a struct sol_http_param_value with key-value and type passed as argument.
#define SOL_HTTP_REQUEST_PARAM_POST_DATA_CONTENTS | ( | key_, | |
value_ | |||
) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_DATA and the given value.
#define SOL_HTTP_REQUEST_PARAM_POST_DATA_FILE | ( | key_, | |
filename_ | |||
) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_DATA and the contents of filename_
.
#define SOL_HTTP_REQUEST_PARAM_POST_FIELD | ( | key_, | |
value_ | |||
) | SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_POST_FIELD, key_, value_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_FIELD and key-value.
#define SOL_HTTP_REQUEST_PARAM_QUERY | ( | key_, | |
value_ | |||
) | SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_QUERY_PARAM, key_, value_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_QUERY_PARAM and key-value.
#define SOL_HTTP_REQUEST_PARAM_TIMEOUT | ( | setting_ | ) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_TIMEOUT and timeout value.
#define SOL_HTTP_REQUEST_PARAM_VERBOSE | ( | setting_ | ) | SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_VERBOSE, setting_) |
Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_VERBOSE and true
or false
as value.
#define SOL_HTTP_REQUEST_PARAMS_INIT |
Macro used to initialize a struct sol_http_params with empty vector.
Referenced by request_cb(), request_events_cb(), and startup().
#define SOL_HTTP_RESPONSE_CHECK_API | ( | response_, | |
... | |||
) |
Macro used to check if a struct sol_http_response is valid (different from NULL
) and has the expected API version or return.
In case it's NULL
or a wrong version, it'll return extra arguments passed to the macro.
#define SOL_HTTP_RESPONSE_CHECK_API_GOTO | ( | response_, | |
label | |||
) |
Macro used to check if a struct sol_http_response is valid (different from NULL
) and has the expected API version or goto a label.
In case it's NULL
or a wrong version, it'll go to label.
#define SOL_HTTP_RESPONSE_CHECK_API_VERSION | ( | response_, | |
... | |||
) |
Macro used to check if a struct sol_http_response has the expected API version or return.
In case it's a wrong version, it'll return extra arguments passed to the macro.
#define SOL_HTTP_RESPONSE_CHECK_API_VERSION_GOTO | ( | response_, | |
label | |||
) |
Macro used to check if a struct sol_http_response has the expected API version or goto a label.
In case it's a wrong version, it'll go to label.
typedef struct sol_http_param_value sol_http_param_value |
Used to define an HTTP parameter.
A parameter is defined by its type (one of enum sol_http_param_type) and its value. It may be a key-value parameter, authentication (user-password), or data.
typedef struct sol_http_params sol_http_params |
Keep vector of HTTP parameters to be sent in a request.
It's required to make requests, with sol_http_client_request() or sol_http_client_request_with_interface() or to create URIs, with sol_http_create_uri() and variants.
typedef struct sol_http_response sol_http_response |
Handle for an HTTP response.
A response is composed by a response code, that may be one of enum sol_http_status_code, a vector of parameters, URL, definition of content type, like "text" or "application/json", and the response content itself.
typedef struct sol_http_url sol_http_url |
Handle for an HTTP URL.
Uniform Resource Locator conforms to the following syntax:
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment
]
enum sol_http_method |
Type of HTTP method.
One of these must be chosen to make a request, with sol_http_client_request() or sol_http_client_request_with_interface()
enum sol_http_param_type |
Type of HTTP parameter.
It should be used to encode and decode parameters, with sol_http_encode_params() and sol_http_decode_params().
enum sol_http_status_code |
Status codes as defined by HTTP protocol.
Most frequently used status are supported.
void sol_http_content_type_priorities_array_clear | ( | struct sol_vector * | priorities | ) |
Clears the priorities array.
priorities | An array of sol_http_content_type_priority. |
int sol_http_create_full_uri | ( | struct sol_buffer * | buf, |
const struct sol_http_url | url, | ||
const struct sol_http_params * | params | ||
) |
Creates an URI based on struct sol_http_url and its parameters.
buf | Where the created URI should be appended (the buffer must be already initialized) |
url | The URL parameters. |
params | The query and cookies params. |
int sol_http_create_uri | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | base_uri, | ||
const struct sol_http_params * | params | ||
) |
A simpler version of sol_http_create_full_uri().
buf | Where the created URI should be appended (the buffer must be already initialized) |
base_uri | The base URI to be used. |
params | The query and cookies params. |
Referenced by sol_http_create_uri_from_str().
|
inlinestatic |
A wrapper on top of sol_http_create_uri()
buf | Where the created URI should be appended (the buffer must be already initialized) |
base_url | The base URI to be used. |
params | The query and cookies params. |
References sol_http_create_uri(), and sol_str_slice_from_str().
int sol_http_decode_params | ( | const struct sol_str_slice | params_slice, |
enum sol_http_param_type | type, | ||
struct sol_http_params * | params | ||
) |
Decodes HTTP parameters of a given type.
params_slice | Where the decoded parameters will be stored as string. |
type | The parameter that should be decoded. |
params | The parameters to be decoded. |
int sol_http_decode_slice | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | value | ||
) |
Decodes an URL string.
If the string was not decoded this function will simply copy the slice's contents to the buffer and set SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED
on the buffer's flags.
buf | The buffer that will hold the decoded string (it will be initialized by this function) |
value | A slice to be decoded. |
int sol_http_encode_params | ( | struct sol_buffer * | buf, |
enum sol_http_param_type | type, | ||
const struct sol_http_params * | params | ||
) |
Encodes HTTP parameters of a given type.
buf | Where the encoded parameters will be stored as string. |
type | The parameter that should be encoded. |
params | The parameters to be encoded. |
int sol_http_encode_slice | ( | struct sol_buffer * | buf, |
const struct sol_str_slice | value | ||
) |
Encodes an URL string.
If the string was not encoded this function will simply copy the slice's content to the buffer and set SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED
on the buffer's flags.
buf | The buffer that will hold the encoded string (it will be initialized by this function) |
value | A slice to be encoded. |
int sol_http_params_add | ( | struct sol_http_params * | params, |
struct sol_http_param_value | value | ||
) |
Add a new parameter to HTTP parameters vector.
params | Parameters handle. |
value | Parameter to be added to the vector. |
true
on success and false
on error. Referenced by request_cb(), and sol_http_response_set_sse_headers().
int sol_http_params_add_copy | ( | struct sol_http_params * | params, |
struct sol_http_param_value | value | ||
) |
Add a new parameter to HTTP parameters vector copying strings.
params | Parameters handle. |
value | Parameter to be added to the vector. |
0
on success and -errno
on error. Referenced by create_header_params(), and create_post_data_params().
void sol_http_params_clear | ( | struct sol_http_params * | params | ) |
Clear vector of HTTP parameters.
It clear parameters vector and also any eventual copy of slices done with sol_http_params_add_copy()
0
on success and -errno
on error.params | Parameters handle. |
Referenced by request_cb(), request_events_cb(), and startup().
|
inlinestatic |
Initialize HTTP parameters struct with an empty vector.
params | Parameters handle to be initialized. |
References sol_http_params::api_version, sol_http_params::arena, sol_http_params::params, SOL_HTTP_PARAM_API_VERSION, SOL_SET_API_VERSION, and sol_vector_init().
int sol_http_parse_content_type_priorities | ( | const struct sol_str_slice | content_type, |
struct sol_vector * | priorities | ||
) |
Sort the content type slice based on its priorities.
For more information about how the content type is sorted check: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
content_type | A content type slice. Example: "text/html, application/json;q=0.5" |
priorities | An array to store the content type prioriries (it will be initialized by this function) |
int sol_http_split_post_field | ( | const char * | query, |
struct sol_http_params * | params | ||
) |
Split post/field string into parameters.
This function will receive a string and split and store its values in the sol_http_params
.
query | A string to be splitted. |
params | Where the post/field parameters will be stored. |
Referenced by create_post_field_params().
int sol_http_split_query | ( | const char * | query, |
struct sol_http_params * | params | ||
) |
Split query into parameters.
This function will receive a query and split and store its values in the sol_http_params
struct.
query | A query to be splitted. |
params | Where the query parameters will be stored. |
int sol_http_split_uri | ( | const struct sol_str_slice | full_uri, |
struct sol_http_url * | url | ||
) |
Split an URI.
This function will receive a complete URI and split and store its values in the sol_http_url struct.
full_uri | An URI to be splitted. |
url | Where the URL parts will be stored. |