21 #define USER_AGENT_HEADER_FORMAT "MCL/" MCL_VERSION_ " (%s)" 28 DEBUG_ENTRY(
"mcl_configuration_t *configuration = <%p>, mcl_communication_t **communication = <%p>", configuration, communication)
100 (*communication)->state.initialized =
MCL_FALSE;
101 (*communication)->http_processor =
MCL_NULL;
102 (*communication)->configuration.mindsphere_hostname =
MCL_NULL;
103 (*communication)->configuration.mindsphere_port = 0;
104 (*communication)->configuration.mindsphere_certificate =
MCL_NULL;
105 (*communication)->configuration.proxy_hostname =
MCL_NULL;
106 (*communication)->configuration.proxy_port = 0;
108 (*communication)->configuration.proxy_username =
MCL_NULL;
109 (*communication)->configuration.proxy_password =
MCL_NULL;
110 (*communication)->configuration.proxy_domain =
MCL_NULL;
112 (*communication)->configuration.initial_access_token =
MCL_NULL;
113 (*communication)->configuration.tenant =
MCL_NULL;
114 (*communication)->configuration.store_path =
MCL_NULL;
115 (*communication)->configuration.load_function.rsa =
MCL_NULL;
116 (*communication)->configuration.save_function.rsa =
MCL_NULL;
117 (*communication)->configuration.access_token_endpoint =
MCL_NULL;
118 (*communication)->configuration.exchange_endpoint =
MCL_NULL;
119 (*communication)->configuration.registration_endpoint =
MCL_NULL;
120 (*communication)->configuration.enter_critical_section =
MCL_NULL;
121 (*communication)->configuration.leave_critical_section =
MCL_NULL;
125 (*communication)->configuration.user_agent =
MCL_NULL;
132 (*communication)->configuration.mindsphere_port = configuration->
mindsphere_port;
142 (*communication)->configuration.security_profile = configuration->
security_profile;
157 (*communication)->configuration.proxy_port = configuration->
proxy_port;
160 (*communication)->configuration.proxy_type = configuration->
proxy_type;
185 user_agent_length += 4 + MCL_VERSION_LENGTH_ + 3;
188 ASSERT_CODE_MESSAGE(
MCL_OK == return_code, return_code,
"Memory can not be allocated for the <User-Agent> header line.");
197 if (0 < initial_access_token_length)
201 "Memory can not be allocated for initial access token.");
212 if (0 < store_path_length)
220 (*communication)->configuration.load_function = configuration->
load_function;
221 (*communication)->configuration.save_function = configuration->
save_function;
232 (*communication)->state.initialized =
MCL_TRUE;
234 MCL_INFO(
"Communication structure is initialized.");
243 DEBUG_ENTRY(
"mcl_communication_t **communication = <%p>", communication)
251 string_destroy(&((*communication)->configuration.mindsphere_hostname));
252 string_destroy(&((*communication)->configuration.mindsphere_certificate));
253 string_destroy(&((*communication)->configuration.proxy_hostname));
254 string_destroy(&((*communication)->configuration.proxy_username));
255 string_destroy(&((*communication)->configuration.proxy_password));
258 string_destroy(&((*communication)->configuration.initial_access_token));
268 MCL_DEBUG(
"Communication handle is destroyed.");
272 MCL_DEBUG(
"Communication handle is already null.");
281 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>", communication)
284 mcl_bool_t critical_section_callbacks_are_used;
289 critical_section_callbacks_are_used =
MCL_NULL != communication->configuration.enter_critical_section &&
MCL_NULL != communication->configuration.leave_critical_section;
290 if(critical_section_callbacks_are_used)
292 result = communication->configuration.enter_critical_section();
306 MCL_INFO(
"Agent is successfully onboarded.");
310 MCL_ERROR(
"Onboarding of agent failed.");
315 MCL_INFO(
"Agent is already onboarded.");
323 MCL_INFO(
"New access token is obtained.");
327 MCL_INFO(
"New access token can not be obtained.");
332 if(critical_section_callbacks_are_used)
334 communication->configuration.leave_critical_section();
343 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>", communication)
346 mcl_bool_t critical_section_callbacks_are_used;
351 critical_section_callbacks_are_used =
MCL_NULL != communication->configuration.enter_critical_section &&
MCL_NULL != communication->configuration.leave_critical_section;
352 if (critical_section_callbacks_are_used)
354 result = communication->configuration.enter_critical_section();
371 MCL_INFO(
"Key successfully rotated.");
375 MCL_INFO(
"New access token is obtained.");
379 MCL_INFO(
"New access token can not be obtained.");
393 if(critical_section_callbacks_are_used)
395 communication->configuration.leave_critical_section();
404 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>", communication)
407 mcl_bool_t critical_section_callbacks_are_used;
411 critical_section_callbacks_are_used =
MCL_NULL != communication->configuration.enter_critical_section &&
MCL_NULL != communication->configuration.leave_critical_section;
412 if (critical_section_callbacks_are_used)
414 result = communication->configuration.enter_critical_section();
439 MCL_INFO(
"Security information is updated, new access token has been acquired.");
443 MCL_INFO(
"Security information is updated, new access token could not be acquired.");
447 if(critical_section_callbacks_are_used)
449 communication->configuration.leave_critical_section();
458 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>", communication)
475 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>, mcl_store_t *store = <%p>, void **reserved = <%p>", communication, store, reserved)
506 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>, mcl_store_t *store = <%p>, void **reserved = <%p>", communication, store, reserved)
517 MCL_INFO(
"Exchange has failed. Trying to get / renew access token.");
521 MCL_INFO(
"Access token is obtained. Trying to exchange again.");
525 MCL_INFO(
"Store is successfully exchanged.");
534 MCL_INFO(
"Access token can not be obtained. Trying to rotate key.");
538 MCL_INFO(
"Key rotated. Trying to exchange again.");
542 MCL_INFO(
"Store is successfully exchanged.");
551 MCL_INFO(
"Access token can not be obtained. Exchange is terminating.");
560 #if MCL_FILE_DOWNLOAD_ENABLED 564 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>, mcl_uint8_t *buffer = <%p>, mcl_size_t buffer_size = <%u>, mcl_size_t start_byte = <%u>, mcl_size_t end_byte = <%u>, char *file_id = <%p>, mcl_file_t **file = <%p>",
565 communication, buffer, buffer_size, start_byte, end_byte, file_id, file)
578 mcl_bool_t with_range = !((0 == start_byte) && (0 == end_byte));
589 result = http_processor_download(communication->http_processor, buffer, buffer_size, start_byte, end_byte, file_id_string, with_range, file);
600 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>", communication)
606 is_initialized = communication->state.initialized;
609 return is_initialized;
614 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>", communication)
620 is_onboarded = (
MCL_NULL == communication->http_processor->security_handler->registration_access_token) ?
MCL_FALSE :
MCL_TRUE;
628 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>, char **token = <%p>", communication, token)
637 token_length = communication->http_processor->security_handler->access_token->length + 1;
641 code =
string_util_snprintf(*token, token_length,
"%s", communication->http_processor->security_handler->access_token->buffer);
650 DEBUG_ENTRY(
"mcl_communication_t *communication = <%p>, char **token_time = <%p>", communication, token_time)
660 if(
MCL_NULL == communication->http_processor->security_handler->last_token_time)
665 token_time_length = communication->http_processor->security_handler->last_token_time->length + 1;
666 *token_time =
MCL_CALLOC(token_time_length, 1);
669 code =
string_util_snprintf(*token_time, token_time_length,
"%s", communication->http_processor->security_handler->last_token_time->buffer);
678 DEBUG_ENTRY(
"mcl_configuration_t *configuration = <%p>", configuration)
686 MCL_INFO(
"Mindsphere Certificate: Provided");
690 MCL_INFO(
"Mindsphere Certificate: Not provided");
701 MCL_INFO(
"Proxy Type: MCL_PROXY_HTTP");
705 MCL_INFO(
"Proxy Type: MCL_PROXY_HTTP_1_0");
709 MCL_INFO(
"Proxy Type: MCL_PROXY_SOCKS4");
713 MCL_INFO(
"Proxy Type: MCL_PROXY_SOCKS5");
717 MCL_INFO(
"Proxy Type: MCL_PROXY_SOCKS4A");
721 MCL_INFO(
"Proxy Type: MCL_PROXY_SOCKS5_HOSTNAME");
725 MCL_INFO(
"Proxy Type: MCL_PROXY_UNKNOWN");
747 MCL_INFO(
"Security Profile: MCL_SECURITY_SHARED_SECRET");
752 MCL_INFO(
"Security Profile: MCL_SECURITY_RSA_3072");
761 MCL_INFO(
"Initial Access Token: Provided");
765 MCL_INFO(
"Initial Access Token: Not provided");
772 MCL_INFO(
"Security Information: Callback functions will be used");
776 MCL_INFO(
"Security Information: File system will be used (not safe)");
781 MCL_INFO(
"Security Information: Will not be saved");
786 MCL_INFO(
"Critical Section: Callback functions are provided");
790 MCL_INFO(
"Critical Section: Callback functions are not provided");
E_MCL_SECURITY_PROFILE security_profile
Security levels E_MCL_SECURITY_PROFILE.
char * user_agent
User agent.
mcl_uint16_t proxy_port
Proxy port no. Optional if proxy_hostname is not used.
E_MCL_ERROR_CODE mcl_communication_exchange(mcl_communication_t *communication, mcl_store_t *store, void **reserved)
Communication module header file.
void string_destroy(string_t **string)
Destroys the allocated resources of the string.
Agent is not onboarded to the server yet and does not possess an authentication key.
mcl_enter_critical_section_callback_t enter_critical_section
Custom function for entering critical section (Optional, default is NULL).
char * proxy_password
Proxy password. Optional if proxy_hostname and proxy_username are not used.
mcl_size_t string_util_strnlen(const char *buffer, mcl_size_t maximum_length)
Standard library strnlen wrapper.
Memory module header file.
E_MCL_ERROR_CODE mcl_communication_onboard(mcl_communication_t *communication)
#define DEFAULT_HTTP_PAYLOAD_SIZE
MindSphere proxy password given as a configuration parameter is either NULL or of inappropriate size...
char * tenant
Tenant name which is used in self issued JWT.
E_MCL_ERROR_CODE string_initialize_new(const char *value, mcl_size_t value_length, string_t **string)
Initializes a new string_t object with the given value and length.
mcl_load_registration_information_callback_t load_function
Custom function for loading registration information; if both load_function and save_function are non...
E_MCL_ERROR_CODE mcl_communication_get_access_token(mcl_communication_t *communication)
Host name given as a configuration parameter is either NULL or of inappropriate size.
#define ASSERT_NOT_NULL(argument)
#define MCL_FALSE
MCL bool type.
E_MCL_ERROR_CODE http_processor_register(http_processor_t *http_processor)
mcl_uint16_t mindsphere_port
Mindsphere port no.
#define USER_AGENT_HEADER_FORMAT
Log utility module header file.
E_MCL_ERROR_CODE
MCL Error code definitions. Every function returning an error code uses this enum values...
E_MCL_ERROR_CODE string_util_snprintf(char *string, mcl_size_t length, const char *format,...)
Standard library snprintf wrapper.
Max HTTP payload size for every HTTP request given as configuration parameter is inappropriate size...
Security profile given as a configuration parameter is invalid. Please check the security profile opt...
mcl_leave_critical_section_callback_t leave_critical_section
Custom function for leaving critical section (Optional, default is NULL).
No access token exists in mcl_communication_t handle.
struct mcl_store_t mcl_store_t
#define ASSERT_STATEMENT_CODE_MESSAGE(condition, statement, return_code,...)
char * proxy_hostname
Proxy hostname. Optional.
static void _log_configuration(mcl_configuration_t *configuration)
General invalid parameter fail.
char * mindsphere_hostname
Mindsphere hostname.
#define MCL_CALLOC(count, bytes)
#define ASSERT_CODE_MESSAGE(condition, return_code,...)
Definitions module header file.
User-Agent for every HTTP request given as configuration parameter is either NULL or longer than 32 c...
mcl_uint32_t http_request_timeout
Timeout value (in seconds) for HTTP requests. Default timeout is 300 seconds.
mcl_bool_t mcl_communication_is_onboarded(mcl_communication_t *communication)
Can be used to determine if communication handle is onboarded.
#define MAXIMUM_HOST_NAME_LENGTH
MindSphere proxy user name given as a configuration parameter is either NULL or of inappropriate size...
If the response of server is HTTP 400.
E_MCL_ERROR_CODE mcl_communication_destroy(mcl_communication_t **communication)
MindSphere proxy domain given as a configuration parameter is either NULL or of inappropriate size...
char * proxy_username
Proxy username. Optional if proxy_hostname is not used.
E_MCL_ERROR_CODE http_processor_update_security_information(http_processor_t *http_processor)
E_MCL_PROXY proxy_type
Proxy type E_MCL_PROXY. Optional if proxy_hostname is not used.
E_MCL_ERROR_CODE http_processor_initialize(configuration_t *configuration, http_processor_t **http_processor)
Http Processor Initialize function.
#define ASSERT_CODE(condition, return_code)
mcl_save_registration_information_callback_t save_function
Custom function for saving registration information; if both load_function and save_function are non-...
E_MCL_ERROR_CODE http_processor_stream(http_processor_t *http_processor, store_t *store, void **reserved)
Exchange operation logic with streaming.
E_MCL_ERROR_CODE mcl_communication_rotate_key(mcl_communication_t *communication)
E_MCL_ERROR_CODE http_processor_exchange(http_processor_t *http_processor, store_t *store, void **reserved)
Exchange operation logic.
E_MCL_ERROR_CODE mcl_communication_process(mcl_communication_t *communication, mcl_store_t *store, void **reserved)
char * store_path
Path of the file the library uses to save registration artifacts such as registration access token...
#define MAXIMUM_PROXY_DOMAIN_LENGTH
char * proxy_domain
Proxy domain. Optional if proxy_hostname and proxy_username are not used.
E_MCL_ERROR_CODE mcl_communication_initialize(mcl_configuration_t *configuration, mcl_communication_t **communication)
E_MCL_ERROR_CODE mcl_communication_get_last_token_time(mcl_communication_t *communication, char **token_time)
Returns the time when lastly received oauth access token is received.
MCL is not initialized, mcl_communication_initialize() function must be called first.
E_MCL_ERROR_CODE http_processor_get_access_token(http_processor_t *http_processor)
char * initial_access_token
Initial access token. Not used by the library if a registration access token is present in store_path...
#define MIN_HTTP_PAYLOAD_SIZE
#define MAXIMUM_PROXY_PASSWORD_LENGTH
mcl_bool_t mcl_communication_is_initialized(mcl_communication_t *communication)
Can be used to determine if communication handle is initialized.
E_MCL_ERROR_CODE mcl_communication_get_last_access_token(mcl_communication_t *communication, char **token)
Returns the lastly received oauth access token, NULL if server time is not received.
Communication module interface header file.
#define MCL_MAXIMUM_HTTP_PAYLOAD_SIZE
Http request payload size limit for MindSphere.
Agent is already onboarded to the server, hence the library did not try to onboard again...
Server time is not received from the server.
struct mcl_communication_t mcl_communication_t
Event list module header file.
struct mcl_file_t mcl_file_t
This struct is used for building the complete message of file.
MindSphere proxy host name given as a configuration parameter is either NULL or of inappropriate size...
#define MAXIMUM_USER_AGENT_LENGTH
#define MAXIMUM_PROXY_USER_NAME_LENGTH
mcl_size_t string_util_strlen(const char *buffer)
Standard library strlen wrapper.
If the response of server is HTTP 401.
mcl_size_t max_http_payload_size
Not valid for streamable request. Default value is 16K Bytes. Minimum value is 400 Bytes and maximum ...
void http_processor_destroy(http_processor_t **http_processor)
To destroy the HTTP Processor Handler.
E_MCL_ERROR_CODE mcl_communication_update_security_information(mcl_communication_t *communication)
char * mindsphere_certificate
Mindsphere certificate. Optional. If set to NULL, MCL will use default CA certificate store (if provi...
#define MCL_ERROR_RETURN(return_value,...)