179 #ifndef SOL_NO_API_VERSION
180 #define SOL_HTTP_PARAM_API_VERSION (1)
249 #ifndef SOL_NO_API_VERSION
250 #define SOL_HTTP_RESPONSE_API_VERSION (1)
279 #ifndef SOL_NO_API_VERSION
287 #define SOL_HTTP_RESPONSE_CHECK_API_VERSION(response_, ...) \
288 if (SOL_UNLIKELY((response_)->api_version != \
289 SOL_HTTP_RESPONSE_API_VERSION)) { \
290 SOL_ERR("Unexpected API version (response is %" PRIu16 ", expected %" PRIu16 ")", \
291 (response_)->api_version, SOL_HTTP_RESPONSE_API_VERSION); \
292 return __VA_ARGS__; \
295 #define SOL_HTTP_RESPONSE_CHECK_API_VERSION(response_, ...)
305 #define SOL_HTTP_RESPONSE_CHECK_API(response_, ...) \
307 if (SOL_UNLIKELY(!(response_))) { \
308 SOL_WRN("Error while reaching service."); \
309 return __VA_ARGS__; \
311 SOL_HTTP_RESPONSE_CHECK_API_VERSION((response_), __VA_ARGS__) \
314 #ifndef SOL_NO_API_VERSION
321 #define SOL_HTTP_RESPONSE_CHECK_API_VERSION_GOTO(response_, label) \
322 if (SOL_UNLIKELY((response_)->api_version != \
323 SOL_HTTP_RESPONSE_API_VERSION)) { \
324 SOL_ERR("Unexpected API version (response is %" PRIu16 ", expected %" PRIu16 ")", \
325 (response_)->api_version, SOL_HTTP_RESPONSE_API_VERSION); \
329 #define SOL_HTTP_RESPONSE_CHECK_API_VERSION_GOTO(response_, label)
339 #define SOL_HTTP_RESPONSE_CHECK_API_GOTO(response_, label) \
341 if (SOL_UNLIKELY(!(response_))) { \
342 SOL_WRN("Error while reaching service."); \
345 SOL_HTTP_RESPONSE_CHECK_API_VERSION_GOTO((response_), label) \
358 #define SOL_HTTP_REQUEST_PARAMS_INIT \
359 (struct sol_http_params) { \
360 SOL_SET_API_VERSION(.api_version = SOL_HTTP_PARAM_API_VERSION, ) \
361 .params = SOL_VECTOR_INIT(struct sol_http_param_value), \
365 #ifndef SOL_NO_API_VERSION
373 #define SOL_HTTP_PARAMS_CHECK_API_VERSION(params_, ...) \
374 if (SOL_UNLIKELY((params_)->api_version != \
375 SOL_HTTP_PARAM_API_VERSION)) { \
376 SOL_ERR("Unexpected API version (response is %" PRIu16 ", expected %" PRIu16 ")", \
377 (params_)->api_version, SOL_HTTP_PARAM_API_VERSION); \
378 return __VA_ARGS__; \
381 #define SOL_HTTP_PARAMS_CHECK_API_VERSION(params_, ...)
384 #ifndef SOL_NO_API_VERSION
391 #define SOL_HTTP_PARAMS_CHECK_API_VERSION_GOTO(params_, label_) \
392 if (SOL_UNLIKELY((params_)->api_version != \
393 SOL_HTTP_PARAM_API_VERSION)) { \
394 SOL_ERR("Unexpected API version (params is %" PRIu16 ", expected %" PRIu16 ")", \
395 (params_)->api_version, SOL_HTTP_PARAM_API_VERSION); \
399 #define SOL_HTTP_PARAMS_CHECK_API_VERSION_GOTO(params_, label_)
406 #define SOL_HTTP_REQUEST_PARAM_KEY_VALUE(type_, key_, value_) \
407 (struct sol_http_param_value) { \
411 .key = sol_str_slice_from_str((key_ ? : "")), \
412 .value = sol_str_slice_from_str((value_ ? : "")) \
421 #define SOL_HTTP_REQUEST_PARAM_BOOL(type_, setting_) \
422 (struct sol_http_param_value) { \
424 .value = { .boolean = { .value = (setting_) } } \
431 #define SOL_HTTP_REQUEST_PARAM_COOKIE(key_, value_) \
432 SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_COOKIE, key_, value_)
438 #define SOL_HTTP_REQUEST_PARAM_HEADER(header_, content_) \
439 SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_HEADER, header_, content_)
445 #define SOL_HTTP_REQUEST_PARAM_AUTH_BASIC(username_, password_) \
446 (struct sol_http_param_value) { \
447 .type = SOL_HTTP_PARAM_AUTH_BASIC, \
450 .user = sol_str_slice_from_str((username_ ? : "")), \
451 .password = sol_str_slice_from_str((password_ ? : "")) \
460 #define SOL_HTTP_REQUEST_PARAM_QUERY(key_, value_) \
461 SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_QUERY_PARAM, key_, value_)
467 #define SOL_HTTP_REQUEST_PARAM_POST_FIELD(key_, value_) \
468 SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_POST_FIELD, key_, value_)
474 #define SOL_HTTP_REQUEST_PARAM_ALLOW_REDIR(setting_) \
475 SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_ALLOW_REDIR, setting_)
481 #define SOL_HTTP_REQUEST_PARAM_VERBOSE(setting_) \
482 SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_VERBOSE, setting_)
488 #define SOL_HTTP_REQUEST_PARAM_TIMEOUT(setting_) \
489 (struct sol_http_param_value) { \
490 .type = SOL_HTTP_PARAM_TIMEOUT, \
492 .integer = { .value = (setting_) } \
501 #define SOL_HTTP_REQUEST_PARAM_POST_DATA_FILE(key_, filename_) \
502 (struct sol_http_param_value) { \
503 .type = SOL_HTTP_PARAM_POST_DATA, \
506 .key = sol_str_slice_from_str((key_ ? : "")), \
507 .value = SOL_STR_SLICE_EMPTY, \
508 .filename = sol_str_slice_from_str((filename_ ? : "")) \
517 #define SOL_HTTP_REQUEST_PARAM_POST_DATA_CONTENTS(key_, value_) \
518 (struct sol_http_param_value) { \
519 .type = SOL_HTTP_PARAM_POST_DATA, \
522 .key = sol_str_slice_from_str((key_ ? : "")), \
524 .filename = SOL_STR_SLICE_EMPTY, \
543 #define SOL_HTTP_PARAMS_FOREACH_IDX(param, itrvar, idx) \
545 param && idx < (param)->params.len && (itrvar = (struct sol_http_param_value *)sol_vector_get(&(param)->params, idx), true); \
559 params->
arena = NULL;
int sol_http_params_add(struct sol_http_params *params, struct sol_http_param_value value)
Add a new parameter to HTTP parameters vector.
Handle for an HTTP response.
Definition: sol-http.h:248
Definition: sol-http.h:111
#define SOL_HTTP_PARAM_API_VERSION
Definition: sol-http.h:180
The request has been accepted for processing.
Definition: sol-http.h:127
struct sol_http_param_value::@3::@6 boolean
int response_code
Definition: sol-http.h:258
client makes an HTTP request by using an HTTP method that does not comply with the HTTP specification...
Definition: sol-http.h:92
double qvalue
The qvalue for the content type.
Definition: sol-http.h:203
struct sol_str_slice content_type
The content type itself.
Definition: sol-http.h:195
int sol_http_split_uri(const struct sol_str_slice full_uri, struct sol_http_url *url)
Split an URI.
uint16_t index
The original index as found in the content type/accept HTTP header.
Definition: sol-http.h:204
uint16_t api_version
Definition: sol-http.h:181
Definition: sol-http.h:110
struct sol_arena * arena
arena with copied parameter slices
Definition: sol-http.h:185
struct sol_http_param_value::@3::@7 integer
struct sol_http_response sol_http_response
Handle for an HTTP response.
struct sol_str_slice key
Definition: sol-http.h:219
Submits data to be processed to a specified resource.
Definition: sol-http.h:55
struct sol_str_slice query
Definition: sol-http.h:274
struct sol_str_slice filename
Definition: sol-http.h:235
Used to rank content type priorities.
Definition: sol-http.h:194
Same as GET, but transfers the status line and header section only.
Definition: sol-http.h:60
The requested resource could not be found.
Definition: sol-http.h:155
Performs a message loop-back test along the path to the target resource.
Definition: sol-http.h:83
struct sol_http_param_value::@3::@5 auth
These are routines that Soletta provides for its arena implementation.
int sol_http_decode_slice(struct sol_buffer *buf, const struct sol_str_slice value)
Decodes an URL string.
struct sol_str_slice password
Definition: sol-http.h:224
struct sol_str_slice password
Definition: sol-http.h:271
Handle for an HTTP URL.
Definition: sol-http.h:268
struct sol_str_slice user
Definition: sol-http.h:223
Definition: sol-http.h:108
struct sol_vector params
vector of parameters, struct sol_http_param_value
Definition: sol-http.h:184
Definition: sol-http.h:113
These are common Soletta macros.
int sol_http_encode_slice(struct sol_buffer *buf, const struct sol_str_slice value)
Encodes an URL string.
struct sol_vector tokens
An array of sol_str_slice.
Definition: sol-http.h:198
Definition: sol-http.h:107
static struct sol_buffer value
Definition: server.c:42
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.
struct sol_buffer content
Definition: sol-http.h:256
Definition: sol-http.h:106
Definition: sol-http.h:114
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.
String slice type.
Definition: sol-str-slice.h:84
struct sol_str_slice scheme
Definition: sol-http.h:269
These are routines that Soletta provides for its buffer implementation.
Definition: sol-http.h:109
struct sol_str_slice user
Definition: sol-http.h:270
#define SOL_ATTR_WARN_UNUSED_RESULT
Causes a warning to be emitted if a caller of the function with this attribute does not use its retur...
Definition: sol-macros.h:187
int sol_http_split_post_field(const char *query, struct sol_http_params *params)
Split post/field string into parameters.
enum sol_http_param_type type
Definition: sol-http.h:216
int32_t value
Definition: sol-http.h:230
struct sol_http_params param
Definition: sol-http.h:257
sol_http_status_code
Status codes as defined by HTTP protocol.
Definition: sol-http.h:123
void sol_http_params_clear(struct sol_http_params *params)
Clear vector of HTTP parameters.
static struct sol_str_slice sol_str_slice_from_str(const char *s)
Populates a slice from a string.
Definition: sol-str-slice.h:238
struct sol_arena sol_arena
Sol Arena type.
Definition: sol-arena.h:54
struct sol_http_url sol_http_url
Handle for an HTTP URL.
Used to define an HTTP parameter.
Definition: sol-http.h:215
struct sol_str_slice sub_type
The sub type.
Definition: sol-http.h:197
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.
sol_http_method
Type of HTTP method.
Definition: sol-http.h:47
Keep vector of HTTP parameters to be sent in a request.
Definition: sol-http.h:178
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().
Definition: sol-http.h:112
The request was a valid request, but the server is refusing to respond to it.
Definition: sol-http.h:151
Establishes a tunnel to the server identified by a given URI.
Definition: sol-http.h:74
sol_http_param_type
Type of HTTP parameter.
Definition: sol-http.h:105
struct sol_str_slice host
Definition: sol-http.h:272
struct sol_str_slice fragment
Definition: sol-http.h:275
Definition: sol-http.h:115
Replaces all current representations of the target resource with the uploaded content.
Definition: sol-http.h:70
void sol_vector_init(struct sol_vector *v, uint16_t elem_size)
Initializes a sol_vector structure.
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.
struct sol_http_param_value::@3::@8 data
struct sol_http_params sol_http_params
Keep vector of HTTP parameters to be sent in a request.
struct sol_str_slice path
Definition: sol-http.h:273
const char * content_type
Definition: sol-http.h:254
int sol_http_split_query(const char *query, struct sol_http_params *params)
Split query into parameters.
#define SOL_SET_API_VERSION(expression)
This macro will cope with SOL_NO_API_VERSION and allows easy declaration of api_version fields...
Definition: sol-mainloop.h:660
A generic error message.
Definition: sol-http.h:163
Describes the communication options for the target resource.
Definition: sol-http.h:78
These are routines that Soletta provides for its string slice implementation.
uint32_t port
If set to 0 it'll be ignored.
Definition: sol-http.h:276
const char * url
Definition: sol-http.h:255
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.
static void sol_http_params_init(struct sol_http_params *params)
Initialize HTTP parameters struct with an empty vector.
Definition: sol-http.h:556
struct sol_str_slice value
Definition: sol-http.h:220
uint16_t api_version
Definition: sol-http.h:251
Requests data from a specified resource.
Definition: sol-http.h:51
Soletta vector is an array that grows dynamically.
Definition: sol-vector.h:58
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()
Definition: sol-http.h:714
Provides an URL in the location header field.
Definition: sol-http.h:131
Indicates that the resource has not been modified since the version specified by the request headers...
Definition: sol-http.h:141
struct sol_str_slice type
The type.
Definition: sol-http.h:196
These are routines that Soletta provides for its vector implementation.
bool value
Definition: sol-http.h:227
A sol_buffer is a dynamic array, that can be resized if needed.
Definition: sol-buffer.h:130
The response to the request can be found under another URI using a GET method.
Definition: sol-http.h:136
The server either does not recognize the request method, or it lacks the ability to fulfill the reque...
Definition: sol-http.h:168
The server cannot or will not process the request due to an apparent client error.
Definition: sol-http.h:146
Used to update partial resources.
Definition: sol-http.h:87
void sol_http_content_type_priorities_array_clear(struct sol_vector *priorities)
Clears the priorities array.
A request method is not supported for the requested resource.
Definition: sol-http.h:159
Removes all current representations of the target resource given by a URI.
Definition: sol-http.h:65
struct sol_http_param_value::@3::@4 key_value
struct sol_http_param_value sol_http_param_value
Used to define an HTTP parameter.