HTTP client libcurl implementation file. More...
#include "http_client_libcurl.h"
#include "string_util.h"
#include "http_definitions.h"
#include "mcl_core/mcl_assert.h"
#include "mcl_core/mcl_memory.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
Go to the source code of this file.
Data Structures | |
struct | libcurl_payload_t |
struct | mcl_certificate_t |
struct | default_callback_user_context_t |
Macros | |
#define | CARRIAGE_RETURN '\r' |
#define | LINE_FEED '\n' |
#define | DOMAIN_SEPERATOR '\\' |
#define | CRLF_LENGTH 2 |
#define | SUPPORTED_CIPHERS_LIST |
#define | CURL_2GB_LIMIT 0x80000000UL |
Variables | |
static mcl_bool_t | curl_global_initialized = MCL_FALSE |
HTTP client libcurl implementation file.
HTTP client implementation file using LibCurl.
Definition in file http_client_libcurl.c.
#define CARRIAGE_RETURN '\r' |
Definition at line 19 of file http_client_libcurl.c.
Referenced by _is_empty_line().
#define CRLF_LENGTH 2 |
Definition at line 22 of file http_client_libcurl.c.
Referenced by _response_header_callback().
#define CURL_2GB_LIMIT 0x80000000UL |
Definition at line 29 of file http_client_libcurl.c.
Referenced by _set_in_file_size().
#define DOMAIN_SEPERATOR '\\' |
Definition at line 21 of file http_client_libcurl.c.
Referenced by mcl_http_client_initialize().
#define LINE_FEED '\n' |
Definition at line 20 of file http_client_libcurl.c.
Referenced by _is_empty_line().
#define SUPPORTED_CIPHERS_LIST |
Definition at line 24 of file http_client_libcurl.c.
Referenced by mcl_http_client_initialize().
|
static |
Definition at line 862 of file http_client_libcurl.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, and MCL_NULL.
Referenced by mcl_http_client_add_certificate(), and mcl_http_client_destroy().
|
static |
Definition at line 796 of file http_client_libcurl.c.
References MCL_COULD_NOT_CONNECT, MCL_COULD_NOT_RESOLVE_HOST, MCL_COULD_NOT_RESOLVE_PROXY, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_IMPROPER_CERTIFICATE, MCL_NETWORK_RECEIVE_FAIL, MCL_NETWORK_SEND_FAIL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_REQUEST_TIMEOUT, MCL_SERVER_CERTIFICATE_NOT_VERIFIED, and MCL_SSL_HANDSHAKE_FAIL.
Referenced by mcl_http_client_send().
|
static |
Definition at line 857 of file http_client_libcurl.c.
References MCL_FREE.
Referenced by mcl_http_client_send().
|
static |
Definition at line 593 of file http_client_libcurl.c.
References CARRIAGE_RETURN, LINE_FEED, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FALSE, and MCL_TRUE.
Referenced by _response_header_callback().
|
static |
Definition at line 568 of file http_client_libcurl.c.
References default_callback_user_context_t::callback_offset, default_callback_user_context_t::http_request, MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, mcl_http_request_t::payload, mcl_http_request_t::payload_size, and string_util_memcpy().
Referenced by _set_payload_options().
|
static |
Definition at line 522 of file http_client_libcurl.c.
References _is_empty_line(), CRLF_LENGTH, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, mcl_list_add(), MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_OK, MCL_TRUE, and string_util_memcpy().
Referenced by mcl_http_client_initialize().
|
static |
Definition at line 492 of file http_client_libcurl.c.
References libcurl_payload_t::data, MCL_ASSERT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_MALLOC, MCL_NULL, MCL_RESIZE, libcurl_payload_t::size, and string_util_memcpy().
Referenced by mcl_http_client_initialize().
|
static |
Definition at line 735 of file http_client_libcurl.c.
References CURL_2GB_LIMIT, libcurl_payload_t::data, MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and libcurl_payload_t::size.
Referenced by _set_payload_options().
|
static |
Definition at line 695 of file http_client_libcurl.c.
References _request_payload_callback_for_put(), _set_in_file_size(), default_callback_user_context_t::callback_offset, http_header_names, HTTP_HEADER_TRANSFER_ENCODING_CHUNKED, default_callback_user_context_t::http_request, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, mcl_http_request_t::payload_size, mcl_http_request_t::stream_callback, and mcl_http_request_t::stream_data.
Referenced by _set_request_options().
|
static |
Definition at line 606 of file http_client_libcurl.c.
References _set_payload_options(), mcl_list_t::count, mcl_list_t::current, mcl_list_node_t::data, mcl_http_request_t::header, http_header_names, HTTP_HEADER_TRANSFER_ENCODING_CHUNKED, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR_RETURN, MCL_HTTP_GET, MCL_HTTP_PATCH, MCL_HTTP_POST, MCL_HTTP_PUT, mcl_list_reset(), MCL_NULL, mcl_http_request_t::method, mcl_list_node_t::next, mcl_http_request_t::payload, mcl_http_request_t::payload_size, mcl_http_request_t::stream_callback, mcl_http_request_t::stream_data, and mcl_http_request_t::uri.
Referenced by mcl_http_client_send().
|
static |
Definition at line 381 of file http_client_libcurl.c.
References mcl_certificate_t::content, mcl_list_t::count, mcl_list_node_t::data, mcl_certificate_t::is_file, MCL_ASSERT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_ERROR_STRING, MCL_INFO, mcl_list_next(), mcl_list_reset(), MCL_NULL, MCL_OK, MCL_TRUE, and string_util_strlen().
Referenced by mcl_http_client_add_certificate().
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 223 of file http_client_libcurl.c.
References _certificate_list_destroy_callback(), _ssl_context_callback(), 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_TRUE, and string_util_strdup().
Referenced by mcl_http_client_initialize().
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 356 of file http_client_libcurl.c.
References _certificate_list_destroy_callback(), MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, mcl_list_destroy_with_content(), and MCL_NULL.
Referenced by core_processor_destroy(), and mcl_http_client_initialize().
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 70 of file http_client_libcurl.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_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_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_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 279 of file http_client_libcurl.c.
References _convert_to_mcl_return_code(), _header_list_destroy_callback(), _set_request_options(), mcl_http_client_t::curl, libcurl_payload_t::data, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, mcl_http_response_initialize(), MCL_INFO, mcl_list_destroy_with_content(), mcl_list_initialize(), MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, and libcurl_payload_t::size.
Referenced by core_processor_get_access_token(), and core_processor_register().
|
static |
Definition at line 51 of file http_client_libcurl.c.
Referenced by mcl_http_client_initialize().