http_client_libcurl.c File Reference

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>
Include dependency graph for http_client_libcurl.c:

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
 

Functions

static CURLcode _ssl_context_callback (CURL *curl, void *ssl_context, void *certificates)
 
static mcl_size_t _response_payload_callback (void *received_data, mcl_size_t size, mcl_size_t count, void *response_payload)
 
static mcl_size_t _response_header_callback (void *received_data, mcl_size_t size, mcl_size_t count, void *response_header)
 
static mcl_size_t _request_payload_callback_for_put (char *buffer, mcl_size_t size, mcl_size_t count, void *user_context)
 
static mcl_bool_t _is_empty_line (char *line)
 
static struct curl_slist * _set_request_options (CURL *curl, mcl_http_request_t *http_request, default_callback_user_context_t *user_context)
 
static struct curl_slist * _set_payload_options (CURL *curl, mcl_http_request_t *http_request, default_callback_user_context_t *user_context, struct curl_slist *header_list)
 
static void _set_in_file_size (CURL *curl, mcl_size_t payload_size)
 
static mcl_error_t _convert_to_mcl_return_code (CURLcode curl_code)
 
static void _header_list_destroy_callback (void **item)
 
static void _certificate_list_destroy_callback (mcl_certificate_t **certificate)
 
mcl_error_t mcl_http_client_initialize (mcl_http_client_configuration_t *configuration, mcl_http_client_t **http_client)
 
mcl_error_t mcl_http_client_add_certificate (mcl_http_client_t *http_client, const char *certificate, mcl_bool_t is_file)
 
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)
 
void mcl_http_client_destroy (mcl_http_client_t **http_client)
 

Variables

static mcl_bool_t curl_global_initialized = MCL_FALSE
 

Detailed Description

HTTP client libcurl implementation file.

HTTP client implementation file using LibCurl.

Definition in file http_client_libcurl.c.

Macro Definition Documentation

#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
Value:
"AES128-SHA256:AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:"\
"ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:"

Definition at line 24 of file http_client_libcurl.c.

Referenced by mcl_http_client_initialize().

Function Documentation

static void _certificate_list_destroy_callback ( mcl_certificate_t **  certificate)
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().

Here is the caller graph for this function:

static void _header_list_destroy_callback ( void **  item)
static

Definition at line 857 of file http_client_libcurl.c.

References MCL_FREE.

Referenced by mcl_http_client_send().

Here is the caller graph for this function:

static mcl_bool_t _is_empty_line ( char *  line)
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().

Here is the caller graph for this function:

static mcl_size_t _request_payload_callback_for_put ( char *  buffer,
mcl_size_t  size,
mcl_size_t  count,
void *  user_context 
)
static
static mcl_size_t _response_header_callback ( void *  received_data,
mcl_size_t  size,
mcl_size_t  count,
void *  response_header 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

static mcl_size_t _response_payload_callback ( void *  received_data,
mcl_size_t  size,
mcl_size_t  count,
void *  response_payload 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

static void _set_in_file_size ( CURL *  curl,
mcl_size_t  payload_size 
)
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().

Here is the caller graph for this function:

static struct curl_slist * _set_payload_options ( CURL *  curl,
mcl_http_request_t http_request,
default_callback_user_context_t user_context,
struct curl_slist *  header_list 
)
static
static CURLcode _ssl_context_callback ( CURL *  curl,
void *  ssl_context,
void *  certificates 
)
static
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).

Parameters
[in]http_clientHTTP client handle.
[in]certificateCertificate.
[in]is_fileMCL_TRUE if certificate is given as file.
Returns

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

Here is the call graph for this function:

Here is the caller graph for this function:

void mcl_http_client_destroy ( mcl_http_client_t **  http_client)

This function will release the resources of HTTP client handle.

Parameters
[in]http_clientHTTP 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]configurationPointer to preinitialized mcl_http_client_configuration_t struct.
[out]http_clientHandle for the http client initialized.
Returns

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]http_clientHTTP client handle.
[in]http_requestHTTP request object.
[out]http_responseHTTP response object.
Returns

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

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

mcl_bool_t curl_global_initialized = MCL_FALSE
static

Definition at line 51 of file http_client_libcurl.c.

Referenced by mcl_http_client_initialize().