HTTP client interface header file. More...
#include "mcl_core/mcl_core_common.h"
#include "mcl_core/mcl_http_response.h"
#include "mcl_core/mcl_http_request.h"
Go to the source code of this file.
Data Structures | |
struct | mcl_http_client_configuration_t |
Functions | |
MCL_CORE_EXPORT mcl_error_t | mcl_http_client_initialize (mcl_http_client_configuration_t *configuration, mcl_http_client_t **http_client) |
MCL_CORE_EXPORT mcl_error_t | mcl_http_client_add_certificate (mcl_http_client_t *http_client, const char *certificate, mcl_bool_t is_file) |
MCL_CORE_EXPORT mcl_error_t | mcl_http_client_send (mcl_http_client_t *http_client, mcl_http_request_t *http_request, mcl_http_response_t **http_response) |
MCL_CORE_EXPORT void | mcl_http_client_destroy (mcl_http_client_t **http_client) |
HTTP client interface header file.
MCL presents an HTTP client interface for which different implementations can be provided. This module is used internally by other MCL modules though it can also be used by the agent as a generic HTTP client. Agent can initialize an HTTP client with mcl_http_client_initialize function based on the configuration in mcl_http_client_configuration_t data structure. Following initialization, agent can send HTTP requests (mcl_http_request_t) and receive HTTP responses (mcl_http_response_t) using mcl_http_client_send function. Agent is expected to destroy the HTTP client when it is no longer needed using mcl_http_client_destroy function.
Definition in file mcl_http_client.h.
MCL_CORE_EXPORT mcl_error_t mcl_http_client_add_certificate | ( | mcl_http_client_t * | http_client, |
const char * | certificate, | ||
mcl_bool_t | is_file | ||
) |
This function adds server certificate to certificate list of http client. The certificate list is used by the http client to identify server(s).
[in] | http_client | HTTP client handle. |
[in] | certificate | Certificate. |
[in] | is_file | MCL_TRUE if certificate is given as file. |
Definition at line 109 of file http_client_basic.c.
References _certificate_list_destroy_callback(), _ssl_context_callback(), mcl_http_client_t::certificate_chain, mcl_http_client_t::certificates, mcl_certificate_t::content, mcl_list_t::count, mcl_http_client_t::curl, mcl_certificate_t::is_file, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, mcl_list_add(), MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, mcl_tls_ca_chain_add_certificate(), MCL_TRUE, and string_util_strdup().
Referenced by mcl_http_client_initialize().
MCL_CORE_EXPORT void mcl_http_client_destroy | ( | mcl_http_client_t ** | http_client | ) |
This function will release the resources of HTTP client handle.
[in] | http_client | HTTP client handle. |
Definition at line 239 of file http_client_basic.c.
References _certificate_list_destroy_callback(), MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, mcl_list_destroy_with_content(), MCL_NULL, and mcl_tls_ca_chain_destroy().
Referenced by core_processor_destroy(), and mcl_http_client_initialize().
MCL_CORE_EXPORT mcl_error_t mcl_http_client_initialize | ( | mcl_http_client_configuration_t * | configuration, |
mcl_http_client_t ** | http_client | ||
) |
This function initializes the underlying implementation (like libcurl) with the given configuration data.
[in] | configuration | Pointer to preinitialized mcl_http_client_configuration_t struct. |
[out] | http_client | Handle for the http client initialized. |
Definition at line 58 of file http_client_basic.c.
References _response_header_callback(), _response_payload_callback(), mcl_http_client_configuration_t::certificate, mcl_http_client_configuration_t::certificate_is_file, curl_global_initialized, DOMAIN_SEPERATOR, mcl_http_client_configuration_t::http_request_timeout, MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR_STRING, MCL_FAIL, MCL_FALSE, MCL_FUNCTION_LEAVE_LABEL, mcl_http_client_add_certificate(), mcl_http_client_destroy(), MCL_INVALID_PARAMETER, mcl_list_initialize(), MCL_MALLOC, mcl_memory_calloc(), mcl_memory_free(), mcl_memory_malloc(), mcl_memory_realloc(), MCL_NEW, MCL_NULL, MCL_NULL_CHAR_SIZE, MCL_OK, MCL_OUT_OF_MEMORY, mcl_tls_ca_chain_add_certificate(), mcl_tls_ca_chain_init(), MCL_TRIGGERED_WITH_NULL, MCL_TRUE, mcl_http_client_configuration_t::port, mcl_http_client_configuration_t::proxy_domain, mcl_http_client_configuration_t::proxy_hostname, mcl_http_client_configuration_t::proxy_password, mcl_http_client_configuration_t::proxy_port, mcl_http_client_configuration_t::proxy_type, mcl_http_client_configuration_t::proxy_username, string_util_memcpy(), string_util_strdup(), string_util_strlen(), SUPPORTED_CIPHERS_LIST, and mcl_http_client_configuration_t::user_agent.
Referenced by core_processor_initialize().
MCL_CORE_EXPORT mcl_error_t mcl_http_client_send | ( | mcl_http_client_t * | http_client, |
mcl_http_request_t * | http_request, | ||
mcl_http_response_t ** | http_response | ||
) |
This function sends the given request to the pre-configured destination and returns the response using underlying implementation. It is blocking until response is received or timeout occurred.
[in] | http_client | HTTP client handle. |
[in] | http_request | HTTP request object. |
[out] | http_response | HTTP response object. |
Definition at line 125 of file http_client_basic.c.
References _convert_to_mcl_return_code(), _header_list_destroy_callback(), _set_request_options(), mcl_http_client_t::certificate_chain, CONTENT_LENGTH_BUFFER_SIZE, content_length_header, crlf, CRLF_SIZE, mcl_http_client_t::curl, libcurl_payload_t::data, get_response(), mcl_http_request_t::header, https_prefix, HTTPS_PREFIX_SIZE, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR_STRING, MCL_FREE, MCL_FUNCTION_LEAVE_LABEL, MCL_HTTP_GET, mcl_http_response_initialize(), MCL_INFO, MCL_INVALID_PARAMETER, mcl_list_destroy_with_content(), mcl_list_initialize(), MCL_NEW, MCL_NULL, MCL_OK, MCL_OPERATION_NOT_SUPPORTED, MCL_OUT_OF_MEMORY, mcl_string_util_snprintf(), mcl_string_util_strncmp(), mcl_tls_socket_destroy(), mcl_tls_socket_init(), mcl_tls_socket_open(), MCL_TLS_SOCKET_PARAMETER_CERTIFICATE_CHAIN, MCL_TLS_SOCKET_PARAMETER_TIMEOUT, mcl_tls_socket_set_parameter(), mcl_http_request_t::method, mcl_http_request_t::payload, mcl_http_request_t::payload_size, send_buffer(), send_header(), send_header_list(), send_with_callback(), libcurl_payload_t::size, start_http(), mcl_http_request_t::stream_callback, mcl_http_request_t::stream_data, mcl_http_client_t::timeout, transfer_encoding_header, TRANSFER_ENCODING_SIZE, mcl_http_request_t::uri, and mcl_http_client_t::user_agent.
Referenced by core_processor_get_access_token(), and core_processor_register().