Manages the multipart message structure of HTTP request. More...
#include "multipart.h"
#include "mcl_connectivity/mcl_connectivity_common.h"
#include "mcl_core/mcl_memory.h"
#include "mcl_core/mcl_random.h"
#include "mcl_core/mcl_string_util.h"
#include "json.h"
Go to the source code of this file.
Macros | |
#define | BOUNDARY_SIGN_LENGTH (sizeof(boundary_sign) - 1) |
#define | CONTENT_TYPE_LENGTH (sizeof(content_type) - 1) |
#define | BOUNDARY_KEY_LENGTH (sizeof(boundary_key) - 1) |
#define | DOUBLE_ENDLINE_LENGTH (sizeof(endline) - 1) |
#define | ENDLINE_LENGTH (DOUBLE_ENDLINE_LENGTH / 2) |
#define | BOUNDARY_LENGTH 20 |
#define | CONTENT_TYPE_MULTIPART_RELATED_LENGTH (sizeof(content_type_multipart_related) - 1) |
#define | CONTENT_TYPE_META_JSON_LENGTH (sizeof(content_type_meta_json) - 1) |
#define | CONTENT_TYPE_APPLICATION_JSON_LENGTH (sizeof(content_type_application_json) - 1) |
#define | MULTIPART_BASE_SIZE |
#define | MULTIPART_CLOSE_LENGTH (BOUNDARY_LENGTH + 2 * BOUNDARY_SIGN_LENGTH) |
Functions | |
static void | _add_boundary (char *buffer, const char *boundary, mcl_bool_t add_and_close) |
static mcl_error_t | _add_item_meta_json (char **position, mcl_size_t *remaining_size, void *item) |
static mcl_error_t | _add_item_payload_content_type (char **position, mcl_size_t *remaining_size, const char *payload_content_type) |
static mcl_error_t | _add_item_payload (char **position, mcl_size_t *remaining_size, void *item, multipart_add_payload_callback callback, void *user_context) |
mcl_error_t | multipart_add_tuple (char *buffer, mcl_size_t *buffer_size, void *item, const char *boundary) |
mcl_error_t | multipart_add_tuple_with_callback (char *buffer, mcl_size_t *buffer_size, void *item, const char *boundary, const char *payload_content_type, multipart_add_payload_callback callback, void *user_context) |
mcl_size_t | multipart_get_tuple_size (void *item, const char *payload_content_type) |
mcl_error_t | multipart_close (char *buffer, mcl_size_t *buffer_size, const char *boundary) |
mcl_size_t | multipart_get_overhead_size (void) |
mcl_error_t | multipart_generate_boundary (char **boundary) |
Variables | |
static const char | boundary_sign [] = "--" |
static const char | content_type [] = "Content-Type: " |
static const char | boundary_key [] = ";boundary=" |
static const char | endline [] = "\r\n\r\n" |
static const char | boundary_characters [] = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
static const char | content_type_multipart_related [] = "multipart/related" |
static const char | content_type_meta_json [] = "application/vnd.siemens.mindsphere.meta+json" |
static const char | content_type_application_json [] = "application/json" |
static const mcl_size_t | _space_needed_for_state [MULTIPART_STATE_END] |
Manages the multipart message structure of HTTP request.
Definition in file multipart.c.
#define BOUNDARY_KEY_LENGTH (sizeof(boundary_key) - 1) |
Definition at line 27 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
#define BOUNDARY_LENGTH 20 |
Definition at line 30 of file multipart.c.
Referenced by _add_boundary(), multipart_add_tuple_with_callback(), multipart_close(), and multipart_generate_boundary().
#define BOUNDARY_SIGN_LENGTH (sizeof(boundary_sign) - 1) |
Definition at line 25 of file multipart.c.
Referenced by _add_boundary(), and multipart_close().
#define CONTENT_TYPE_APPLICATION_JSON_LENGTH (sizeof(content_type_application_json) - 1) |
Definition at line 33 of file multipart.c.
Referenced by _add_item_payload_content_type().
#define CONTENT_TYPE_LENGTH (sizeof(content_type) - 1) |
Definition at line 26 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
#define CONTENT_TYPE_META_JSON_LENGTH (sizeof(content_type_meta_json) - 1) |
Definition at line 32 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
#define CONTENT_TYPE_MULTIPART_RELATED_LENGTH (sizeof(content_type_multipart_related) - 1) |
Definition at line 31 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
#define DOUBLE_ENDLINE_LENGTH (sizeof(endline) - 1) |
Definition at line 28 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
#define ENDLINE_LENGTH (DOUBLE_ENDLINE_LENGTH / 2) |
Definition at line 29 of file multipart.c.
Referenced by _add_boundary(), and multipart_add_tuple_with_callback().
#define MULTIPART_BASE_SIZE |
Definition at line 35 of file multipart.c.
Referenced by multipart_get_tuple_size().
#define MULTIPART_CLOSE_LENGTH (BOUNDARY_LENGTH + 2 * BOUNDARY_SIGN_LENGTH) |
Definition at line 38 of file multipart.c.
Referenced by multipart_close(), and multipart_get_overhead_size().
enum E_MULTIPART_STATE |
Multipart states.
Definition at line 43 of file multipart.c.
|
static |
Definition at line 308 of file multipart.c.
References BOUNDARY_LENGTH, boundary_sign, BOUNDARY_SIGN_LENGTH, endline, ENDLINE_LENGTH, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, mcl_string_util_memcpy(), and MCL_TRUE.
Referenced by multipart_add_tuple_with_callback().
|
static |
Definition at line 331 of file multipart.c.
References json_from_item_meta(), MCL_DEBUG_LEAVE, MCL_FAIL, MCL_FREE, MCL_NULL, MCL_OK, mcl_string_util_memcpy(), and mcl_string_util_strlen().
Referenced by multipart_add_tuple_with_callback().
|
static |
Definition at line 391 of file multipart.c.
References json_from_item_payload(), MCL_FAIL, MCL_FREE, MCL_NULL, MCL_OK, mcl_string_util_memcpy(), and mcl_string_util_strlen().
Referenced by multipart_add_tuple_with_callback().
|
static |
Definition at line 360 of file multipart.c.
References content_type_application_json, CONTENT_TYPE_APPLICATION_JSON_LENGTH, MCL_FAIL, MCL_NULL, MCL_OK, mcl_string_util_memcpy(), and mcl_string_util_strlen().
Referenced by multipart_add_tuple_with_callback().
mcl_error_t multipart_add_tuple | ( | char * | buffer, |
mcl_size_t * | buffer_size, | ||
void * | item, | ||
const char * | boundary | ||
) |
This function is used to add a connectivity item to the HTTP request as a multipart content (meta + payload).
[in] | buffer | Buffer to be used. |
[in,out] | buffer_size | Size of the buffer. Remaining size will be returned via this pointer. |
[in] | item | Item to be added. |
[in] | boundary | Multipart boundary. |
Definition at line 117 of file multipart.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, and multipart_add_tuple_with_callback().
Referenced by _add_item_to_buffer().
mcl_error_t multipart_add_tuple_with_callback | ( | char * | buffer, |
mcl_size_t * | buffer_size, | ||
void * | item, | ||
const char * | boundary, | ||
const char * | payload_content_type, | ||
multipart_add_payload_callback | callback, | ||
void * | user_context | ||
) |
This function is used to add a connectivity item to the HTTP request using callback as a multipart content (meta + payload).
[in] | buffer | Buffer to be used. |
[in,out] | buffer_size | Size of the buffer. Remaining size will be returned via this pointer. |
[in] | item | Item to be added. |
[in] | boundary | Multipart boundary. |
[in] | payload_content_type | Content type of payload. |
[in] | callback | Callback function to be used to copy the payload to http_request . |
[in] | user_context | User context pointer to pass to the callback function. |
Definition at line 130 of file multipart.c.
References _add_boundary(), _add_item_meta_json(), _add_item_payload(), _add_item_payload_content_type(), _space_needed_for_state, boundary_key, BOUNDARY_KEY_LENGTH, BOUNDARY_LENGTH, content_type, CONTENT_TYPE_LENGTH, content_type_meta_json, CONTENT_TYPE_META_JSON_LENGTH, content_type_multipart_related, CONTENT_TYPE_MULTIPART_RELATED_LENGTH, DOUBLE_ENDLINE_LENGTH, endline, ENDLINE_LENGTH, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_FALSE, MCL_FREE, MCL_NULL, MCL_OK, mcl_string_util_memcpy(), MCL_TRUE, multipart_generate_boundary(), MULTIPART_STATE_BOUNDARY_KEY, MULTIPART_STATE_BOUNDARY_VALUE_SUB_BOUNDARY, MULTIPART_STATE_CLOSE_SUB_BOUNDARY, MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_META_JSON, MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_MULTIPART_RELATED, MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_PAYLOAD, MULTIPART_STATE_CONTENT_TYPE_VALUE_META_JSON, MULTIPART_STATE_CONTENT_TYPE_VALUE_MULTIPART_RELATED, MULTIPART_STATE_CONTENT_TYPE_VALUE_PAYLOAD, MULTIPART_STATE_DOUBLE_ENDLINE_FIRST, MULTIPART_STATE_DOUBLE_ENDLINE_SECOND, MULTIPART_STATE_DOUBLE_ENDLINE_THIRD, MULTIPART_STATE_END, MULTIPART_STATE_ENDLINE_FIRST, MULTIPART_STATE_ENDLINE_SECOND, MULTIPART_STATE_ITEM_META_JSON, MULTIPART_STATE_ITEM_PAYLOAD, MULTIPART_STATE_OPEN_MAIN_BOUNDARY, MULTIPART_STATE_OPEN_SUB_BOUNDARY_FIRST, and MULTIPART_STATE_OPEN_SUB_BOUNDARY_SECOND.
Referenced by _add_custom_data_to_buffer(), _add_item_to_buffer(), and multipart_add_tuple().
mcl_error_t multipart_close | ( | char * | buffer, |
mcl_size_t * | buffer_size, | ||
const char * | boundary | ||
) |
This function is used to close the multipart section of HTTP request with closing boundary.
[in] | buffer | Buffer to be used. |
[in,out] | buffer_size | Size of the buffer. Remaining size will be returned via this pointer. |
[in] | boundary | Closing boundary. |
Definition at line 250 of file multipart.c.
References BOUNDARY_LENGTH, boundary_sign, BOUNDARY_SIGN_LENGTH, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_OK, mcl_string_util_memcpy(), and MULTIPART_CLOSE_LENGTH.
Referenced by _prepare_body(), and _prepare_body_for_store().
mcl_error_t multipart_generate_boundary | ( | char ** | boundary | ) |
This function is used to generate random boundary to be used in multipart messages.
[out] | boundary | Generated boundary. |
boundary
is null. Definition at line 280 of file multipart.c.
References boundary_characters, BOUNDARY_LENGTH, MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_STATEMENT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_OK, MCL_OUT_OF_MEMORY, and mcl_random_generate_bytes().
Referenced by connectivity_processor_exchange(), and multipart_add_tuple_with_callback().
mcl_size_t multipart_get_overhead_size | ( | void | ) |
This function is used to get multipart overhead size.
Definition at line 273 of file multipart.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and MULTIPART_CLOSE_LENGTH.
Referenced by _check_store_size(), _prepare_body(), and _select_store_items_to_exchange().
mcl_size_t multipart_get_tuple_size | ( | void * | item, |
const char * | payload_content_type | ||
) |
This function calculates the tuple size of an item.
[in] | item | Item to calculate its tuple size. |
[in] | payload_content_type | Content type of payload. |
Definition at line 237 of file multipart.c.
References json_get_item_size(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, mcl_string_util_strlen(), and MULTIPART_BASE_SIZE.
Referenced by _get_item_size().
|
static |
Definition at line 67 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
|
static |
Definition at line 20 of file multipart.c.
Referenced by multipart_generate_boundary().
|
static |
Definition at line 18 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
|
static |
Definition at line 16 of file multipart.c.
Referenced by _add_boundary(), and multipart_close().
|
static |
Definition at line 17 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
|
static |
Definition at line 23 of file multipart.c.
Referenced by _add_item_payload_content_type().
|
static |
Definition at line 22 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
|
static |
Definition at line 21 of file multipart.c.
Referenced by multipart_add_tuple_with_callback().
|
static |
Definition at line 19 of file multipart.c.
Referenced by _add_boundary(), and multipart_add_tuple_with_callback().