connectivity_processor.c File Reference

Connectivity processor module implementation file. More...

#include "connectivity_processor.h"
#include "multipart.h"
#include "store.h"
#include "event.h"
#include "data_source_configuration.h"
#include "timeseries.h"
#include "file.h"
#include "custom_data.h"
#include "json.h"
#include "mcl_core/mcl_memory.h"
#include "mcl_core/mcl_string_util.h"
#include "mcl_core/mcl_file_util.h"
#include "mcl_core/mcl_json_util.h"
#include "mcl_core/mcl_random.h"
Include dependency graph for connectivity_processor.c:

Go to the source code of this file.

Data Structures

struct  custom_data_callback_user_context
 

Macros

#define CORRELATION_ID_BYTE_LENGTH   16
 
#define CORRELATION_ID_BUFFER_LENGTH   ((CORRELATION_ID_BYTE_LENGTH * 2) + MCL_NULL_CHAR_SIZE)
 

Enumerations

enum  E_CONTENT_TYPE_VALUES {
  CONTENT_TYPE_APPLICATION_OCTET_STREAM, CONTENT_TYPE_TEXT_PLAIN, CONTENT_TYPE_APPLICATION_JSON, CONTENT_TYPE_MULTIPART_MIXED,
  CONTENT_TYPE_URL_ENCODED, TRANSFER_ENCODING_CHUNKED, CONTENT_TYPE_VALUES_END
}
 

Functions

static mcl_error_t _scan_store_after_exchange (store_t *store, mcl_bool_t *store_fully_processed, mcl_error_t exchange_response)
 
static mcl_error_t _add_http_headers_for_exchange (connectivity_processor_t *processor, mcl_http_request_t *request, const char *boundary)
 
static mcl_error_t _add_multipart_mixed_content_type_header (mcl_http_request_t *request, const char *boundary)
 
static mcl_error_t _add_authorization_header (mcl_http_request_t *request, const char *access_token)
 
static mcl_error_t _generate_correlation_id_string (char *correlation_id)
 
static mcl_error_t _evaluate_response_for_exchange (mcl_http_response_t *response, const char *correlation_id)
 
static mcl_size_t _file_payload_callback (char *buffer, mcl_size_t size, mcl_size_t count, void *user_context)
 
static mcl_size_t _custom_data_payload_callback (char *buffer, mcl_size_t size, mcl_size_t count, void *user_context)
 
static mcl_error_t _prepare_body_for_store (store_t *store, mcl_size_t max_http_payload_size, char *boundary, mcl_uint8_t **body, mcl_size_t *body_size)
 
static mcl_error_t _prepare_body (mcl_item_t *item, mcl_size_t max_http_payload_size, char *boundary, mcl_uint8_t **body, mcl_size_t *body_size)
 
static mcl_error_t _add_custom_data_to_buffer (char *buffer, mcl_size_t *buffer_size, custom_data_t *custom_data, const char *boundary)
 
static mcl_error_t _check_store_size (store_t *store, mcl_size_t max_http_payload_size)
 
static void _revert_store_item_status (store_t *store)
 
static mcl_bool_t _remove_uploaded_store_items (store_t *store)
 
static mcl_error_t _prepare_mapping_json (mapping_t *mapping, const char *agent_id, char **json)
 
mcl_error_t connectivity_processor_exchange (connectivity_processor_t *connectivity_processor, mcl_item_t *item)
 
mcl_error_t connectivity_processor_create_mapping (connectivity_processor_t *connectivity_processor, mapping_t *mapping)
 
mcl_error_t connectivity_processor_get_data_source_configuration (connectivity_processor_t *connectivity_processor, data_source_configuration_t **configuration)
 
static mcl_error_t _add_item_to_buffer (char *buffer, mcl_size_t *buffer_size, mcl_item_t *item, const char *boundary)
 
static mcl_size_t _get_item_size (mcl_item_t *item)
 
static mcl_size_t _select_store_items_to_exchange (store_t *store, mcl_size_t max_http_payload_size)
 
static store_item_t_get_next_selected_store_item (store_t *store)
 

Variables

static const char * content_type_values [CONTENT_TYPE_VALUES_END]
 

Detailed Description

Connectivity processor module implementation file.

Definition in file connectivity_processor.c.

Macro Definition Documentation

#define CORRELATION_ID_BUFFER_LENGTH   ((CORRELATION_ID_BYTE_LENGTH * 2) + MCL_NULL_CHAR_SIZE)
#define CORRELATION_ID_BYTE_LENGTH   16

Definition at line 99 of file connectivity_processor.c.

Referenced by _generate_correlation_id_string().

Enumeration Type Documentation

Content types.

This is used with content_type_values array to get the related string. ex: content_type_values[CONTENT_TYPE_APPLICATION_OCTET_STREAM] returns the string of "application/octet-stream".

Enumerator
CONTENT_TYPE_APPLICATION_OCTET_STREAM 

Content type is application octet stream.

CONTENT_TYPE_TEXT_PLAIN 

Content type is text plain.

CONTENT_TYPE_APPLICATION_JSON 

Content type is application json.

CONTENT_TYPE_MULTIPART_MIXED 

Content type is multipart mixed.

CONTENT_TYPE_URL_ENCODED 

Content type is application/x-www-form-urlencoded.

TRANSFER_ENCODING_CHUNKED 

Transfer encoding chunked.

CONTENT_TYPE_VALUES_END 

End of content type enumeration.

Definition at line 30 of file connectivity_processor.c.

Function Documentation

static mcl_error_t _add_authorization_header ( mcl_http_request_t request,
const char *  access_token 
)
static
static mcl_error_t _add_custom_data_to_buffer ( char *  buffer,
mcl_size_t buffer_size,
custom_data_t custom_data,
const char *  boundary 
)
static
static mcl_error_t _add_http_headers_for_exchange ( connectivity_processor_t processor,
mcl_http_request_t request,
const char *  boundary 
)
static
static mcl_error_t _add_multipart_mixed_content_type_header ( mcl_http_request_t request,
const char *  boundary 
)
static
static mcl_size_t _custom_data_payload_callback ( char *  buffer,
mcl_size_t  size,
mcl_size_t  count,
void *  user_context 
)
static

Definition at line 640 of file connectivity_processor.c.

References custom_data_payload_t::buffer, custom_data_callback_user_context::custom_data, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, mcl_string_util_memcpy(), custom_data_t::payload, and custom_data_payload_t::size.

Referenced by _add_custom_data_to_buffer().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_error_t _evaluate_response_for_exchange ( mcl_http_response_t response,
const char *  correlation_id 
)
static
static mcl_size_t _file_payload_callback ( char *  buffer,
mcl_size_t  size,
mcl_size_t  count,
void *  user_context 
)
static

Definition at line 628 of file connectivity_processor.c.

References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and mcl_file_util_fread().

Referenced by _add_item_to_buffer().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_error_t _generate_correlation_id_string ( char *  correlation_id)
static

Definition at line 609 of file connectivity_processor.c.

References CORRELATION_ID_BYTE_LENGTH, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_OK, mcl_random_generate_bytes(), and mcl_string_util_snprintf().

Referenced by connectivity_processor_create_mapping(), and connectivity_processor_exchange().

Here is the call graph for this function:

Here is the caller graph for this function:

static store_item_t* _get_next_selected_store_item ( store_t store)
static

Definition at line 799 of file connectivity_processor.c.

References mcl_list_node_t::data, store_t::item_list, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, mcl_list_next(), MCL_NULL, MCL_OK, store_item_t::status, and STORE_ITEM_STATUS_SELECTED.

Referenced by _prepare_body_for_store().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_error_t _prepare_body ( mcl_item_t item,
mcl_size_t  max_http_payload_size,
char *  boundary,
mcl_uint8_t **  body,
mcl_size_t body_size 
)
static
static mcl_error_t _prepare_body_for_store ( store_t store,
mcl_size_t  max_http_payload_size,
char *  boundary,
mcl_uint8_t **  body,
mcl_size_t body_size 
)
static
static mcl_error_t _prepare_mapping_json ( mapping_t mapping,
const char *  agent_id,
char **  json 
)
static
static mcl_bool_t _remove_uploaded_store_items ( store_t store)
static
static void _revert_store_item_status ( store_t store)
static

Definition at line 937 of file connectivity_processor.c.

References mcl_list_t::count, mcl_list_node_t::data, store_t::item_list, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, mcl_list_next(), mcl_list_reset(), MCL_NULL, and STORE_ITEM_STATUS_READY.

Referenced by _scan_store_after_exchange().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_error_t _scan_store_after_exchange ( store_t store,
mcl_bool_t store_fully_processed,
mcl_error_t  exchange_response 
)
static

Definition at line 472 of file connectivity_processor.c.

References _remove_uploaded_store_items(), _revert_store_item_status(), mcl_list_t::count, store_t::item_list, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ITEM_EXCEEDS_MAX_HTTP_REQUEST_SIZE, MCL_OK, and MCL_TRUE.

Referenced by connectivity_processor_exchange().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_size_t _select_store_items_to_exchange ( store_t store,
mcl_size_t  max_http_payload_size 
)
static
mcl_error_t connectivity_processor_create_mapping ( connectivity_processor_t connectivity_processor,
mapping_t mapping 
)

This function creates a data point mapping.

Parameters
[in]connectivity_processorConnectivity Processor handle to be used.
[in]mappingMapping handle.
Returns

Definition at line 256 of file connectivity_processor.c.

References _add_authorization_header(), _generate_correlation_id_string(), _prepare_mapping_json(), connectivity_processor_t::access_token, connectivity_processor_t::agent_id, CONTENT_TYPE_APPLICATION_JSON, content_type_values, CORRELATION_ID_BUFFER_LENGTH, connectivity_processor_t::http_client, connectivity_processor_t::mapping_url, mapping_validate(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_FREE, mcl_http_client_send(), MCL_HTTP_POST, mcl_http_request_add_header(), mcl_http_request_destroy(), mcl_http_request_initialize(), MCL_HTTP_REQUEST_PARAMETER_BODY, MCL_HTTP_REQUEST_PARAMETER_BODY_SIZE, MCL_HTTP_REQUEST_PARAMETER_METHOD, MCL_HTTP_REQUEST_PARAMETER_URL, mcl_http_request_set_parameter(), mcl_http_response_destroy(), mcl_http_response_get_status(), MCL_HTTP_STATUS_CODE_CREATED, MCL_INFO, MCL_NULL, MCL_OK, mcl_string_util_strlen(), MCL_UNEXPECTED_RESULT_CODE, mcl_http_response_t::payload, mcl_http_response_t::payload_size, and mcl_http_response_t::status_code.

Referenced by mcl_connectivity_create_mapping().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_error_t connectivity_processor_exchange ( connectivity_processor_t connectivity_processor,
mcl_item_t item 
)

This function exchanges data with MindSphere.

Parameters
[in]connectivity_processorConnectivity Processor handle to be used.
[in]itemData to be exchanged.
Returns

Definition at line 111 of file connectivity_processor.c.

References _add_http_headers_for_exchange(), _check_store_size(), _evaluate_response_for_exchange(), _generate_correlation_id_string(), _prepare_body(), _scan_store_after_exchange(), CORRELATION_ID_BUFFER_LENGTH, custom_data_validate(), data_source_configuration_validate(), event_validate(), connectivity_processor_t::exchange_url, file_validate(), connectivity_processor_t::http_client, connectivity_processor_t::max_http_payload_size, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_FALSE, MCL_FREE, mcl_http_client_send(), MCL_HTTP_POST, mcl_http_request_add_header(), mcl_http_request_destroy(), mcl_http_request_initialize(), MCL_HTTP_REQUEST_PARAMETER_BODY, MCL_HTTP_REQUEST_PARAMETER_BODY_SIZE, MCL_HTTP_REQUEST_PARAMETER_METHOD, MCL_HTTP_REQUEST_PARAMETER_URL, mcl_http_request_set_parameter(), mcl_http_response_destroy(), MCL_INVALID_PARAMETER, MCL_ITEM_PREAMBLE, MCL_ITEM_TYPE_CUSTOM_DATA, MCL_ITEM_TYPE_DATA_SOURCE_CONFIGURATION, MCL_ITEM_TYPE_EVENT, MCL_ITEM_TYPE_FILE, MCL_ITEM_TYPE_STORE, MCL_ITEM_TYPE_TIMESERIES, MCL_NULL, MCL_OK, MCL_TRUE, multipart_generate_boundary(), and timeseries_validate().

Referenced by mcl_connectivity_exchange().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_error_t connectivity_processor_get_data_source_configuration ( connectivity_processor_t connectivity_processor,
data_source_configuration_t **  configuration 
)

This function gets data source configuration.

Parameters
[in]connectivity_processorConnectivity Processor handle to be used.
[out]configurationData source configuration.
Returns

Definition at line 371 of file connectivity_processor.c.

References _add_authorization_header(), connectivity_processor_t::access_token, connectivity_processor_t::agent_id, CONTENT_TYPE_APPLICATION_JSON, content_type_values, connectivity_processor_t::hostname, connectivity_processor_t::http_client, json_parse_item(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, mcl_http_client_send(), MCL_HTTP_GET, mcl_http_request_add_header(), mcl_http_request_destroy(), mcl_http_request_initialize(), MCL_HTTP_REQUEST_PARAMETER_METHOD, MCL_HTTP_REQUEST_PARAMETER_URL, mcl_http_request_set_parameter(), mcl_http_response_destroy(), mcl_http_response_get_status(), MCL_HTTP_STATUS_CODE_SUCCESS, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR_SIZE, MCL_OK, MCL_OUT_OF_MEMORY, mcl_string_util_memcpy(), mcl_string_util_strlen(), mcl_http_response_t::payload, mcl_http_response_t::payload_size, and mcl_http_response_t::status_code.

Referenced by mcl_connectivity_get_data_source_configuration().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char* content_type_values[CONTENT_TYPE_VALUES_END]
static
Initial value:
=
{
"application/octet-stream",
"text/plain",
"application/json",
"multipart/mixed",
"application/x-www-form-urlencoded",
"chunked"
}

Content type values.

Definition at line 44 of file connectivity_processor.c.

Referenced by _add_http_headers_for_exchange(), _add_item_to_buffer(), _add_multipart_mixed_content_type_header(), _get_item_size(), connectivity_processor_create_mapping(), and connectivity_processor_get_data_source_configuration().