multipart.c File Reference

Manages the multipart message structure of HTTP request. More...

Include dependency graph for multipart.c:

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)
 

Enumerations

enum  E_MULTIPART_STATE {
  MULTIPART_STATE_OPEN_MAIN_BOUNDARY = 0, MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_MULTIPART_RELATED, MULTIPART_STATE_CONTENT_TYPE_VALUE_MULTIPART_RELATED, MULTIPART_STATE_BOUNDARY_KEY,
  MULTIPART_STATE_BOUNDARY_VALUE_SUB_BOUNDARY, MULTIPART_STATE_DOUBLE_ENDLINE_FIRST, MULTIPART_STATE_OPEN_SUB_BOUNDARY_FIRST, MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_META_JSON,
  MULTIPART_STATE_CONTENT_TYPE_VALUE_META_JSON, MULTIPART_STATE_DOUBLE_ENDLINE_SECOND, MULTIPART_STATE_ITEM_META_JSON, MULTIPART_STATE_ENDLINE_FIRST,
  MULTIPART_STATE_OPEN_SUB_BOUNDARY_SECOND, MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_PAYLOAD, MULTIPART_STATE_CONTENT_TYPE_VALUE_PAYLOAD, MULTIPART_STATE_DOUBLE_ENDLINE_THIRD,
  MULTIPART_STATE_ITEM_PAYLOAD, MULTIPART_STATE_ENDLINE_SECOND, MULTIPART_STATE_CLOSE_SUB_BOUNDARY, MULTIPART_STATE_END
}
 

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]
 

Detailed Description

Manages the multipart message structure of HTTP request.

Definition in file multipart.c.

Macro Definition Documentation

#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
#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
Value:
#define ENDLINE_LENGTH
Definition: multipart.c:29
#define CONTENT_TYPE_LENGTH
Definition: multipart.c:26
#define BOUNDARY_SIGN_LENGTH
Definition: multipart.c:25
#define CONTENT_TYPE_MULTIPART_RELATED_LENGTH
Definition: multipart.c:31
#define CONTENT_TYPE_META_JSON_LENGTH
Definition: multipart.c:32
#define BOUNDARY_LENGTH
Definition: multipart.c:30
#define BOUNDARY_KEY_LENGTH
Definition: multipart.c:27

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().

Enumeration Type Documentation

Multipart states.

Enumerator
MULTIPART_STATE_OPEN_MAIN_BOUNDARY 
MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_MULTIPART_RELATED 
MULTIPART_STATE_CONTENT_TYPE_VALUE_MULTIPART_RELATED 
MULTIPART_STATE_BOUNDARY_KEY 
MULTIPART_STATE_BOUNDARY_VALUE_SUB_BOUNDARY 
MULTIPART_STATE_DOUBLE_ENDLINE_FIRST 
MULTIPART_STATE_OPEN_SUB_BOUNDARY_FIRST 
MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_META_JSON 
MULTIPART_STATE_CONTENT_TYPE_VALUE_META_JSON 
MULTIPART_STATE_DOUBLE_ENDLINE_SECOND 
MULTIPART_STATE_ITEM_META_JSON 
MULTIPART_STATE_ENDLINE_FIRST 
MULTIPART_STATE_OPEN_SUB_BOUNDARY_SECOND 
MULTIPART_STATE_CONTENT_TYPE_KEY_FOR_PAYLOAD 
MULTIPART_STATE_CONTENT_TYPE_VALUE_PAYLOAD 
MULTIPART_STATE_DOUBLE_ENDLINE_THIRD 
MULTIPART_STATE_ITEM_PAYLOAD 
MULTIPART_STATE_ENDLINE_SECOND 
MULTIPART_STATE_CLOSE_SUB_BOUNDARY 
MULTIPART_STATE_END 

Definition at line 43 of file multipart.c.

Function Documentation

static void _add_boundary ( char *  buffer,
const char *  boundary,
mcl_bool_t  add_and_close 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_error_t _add_item_meta_json ( char **  position,
mcl_size_t remaining_size,
void *  item 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_error_t _add_item_payload ( char **  position,
mcl_size_t remaining_size,
void *  item,
multipart_add_payload_callback  callback,
void *  user_context 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_error_t _add_item_payload_content_type ( char **  position,
mcl_size_t remaining_size,
const char *  payload_content_type 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

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).

Parameters
[in]bufferBuffer to be used.
[in,out]buffer_sizeSize of the buffer. Remaining size will be returned via this pointer.
[in]itemItem to be added.
[in]boundaryMultipart boundary.
Returns

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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).

Parameters
[in]bufferBuffer to be used.
[in,out]buffer_sizeSize of the buffer. Remaining size will be returned via this pointer.
[in]itemItem to be added.
[in]boundaryMultipart boundary.
[in]payload_content_typeContent type of payload.
[in]callbackCallback function to be used to copy the payload to http_request.
[in]user_contextUser context pointer to pass to the callback function.
Returns

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]bufferBuffer to be used.
[in,out]buffer_sizeSize of the buffer. Remaining size will be returned via this pointer.
[in]boundaryClosing boundary.
Returns
  • MCL_OK in case of success.
  • MCL_FAIL in case of an internal error in MCL.

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().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_error_t multipart_generate_boundary ( char **  boundary)

This function is used to generate random boundary to be used in multipart messages.

Parameters
[out]boundaryGenerated boundary.
Returns

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().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_size_t multipart_get_overhead_size ( void  )

This function is used to get multipart overhead size.

Returns
The size of multipart overhead.

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().

Here is the caller graph for this function:

mcl_size_t multipart_get_tuple_size ( void *  item,
const char *  payload_content_type 
)

This function calculates the tuple size of an item.

Parameters
[in]itemItem to calculate its tuple size.
[in]payload_content_typeContent type of payload.
Returns
Tuple size of the item.

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().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const mcl_size_t _space_needed_for_state[MULTIPART_STATE_END]
static

Definition at line 67 of file multipart.c.

Referenced by multipart_add_tuple_with_callback().

const char boundary_characters[] = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
static

Definition at line 20 of file multipart.c.

Referenced by multipart_generate_boundary().

const char boundary_key[] = ";boundary="
static

Definition at line 18 of file multipart.c.

Referenced by multipart_add_tuple_with_callback().

const char boundary_sign[] = "--"
static

Definition at line 16 of file multipart.c.

Referenced by _add_boundary(), and multipart_close().

const char content_type[] = "Content-Type: "
static

Definition at line 17 of file multipart.c.

Referenced by multipart_add_tuple_with_callback().

const char content_type_application_json[] = "application/json"
static

Definition at line 23 of file multipart.c.

Referenced by _add_item_payload_content_type().

const char content_type_meta_json[] = "application/vnd.siemens.mindsphere.meta+json"
static

Definition at line 22 of file multipart.c.

Referenced by multipart_add_tuple_with_callback().

const char content_type_multipart_related[] = "multipart/related"
static

Definition at line 21 of file multipart.c.

Referenced by multipart_add_tuple_with_callback().

const char endline[] = "\r\n\r\n"
static

Definition at line 19 of file multipart.c.

Referenced by _add_boundary(), and multipart_add_tuple_with_callback().