http_client_libcurl.c File Reference

HTTP client libcurl implementation file. More...

#include "http_client_libcurl.h"
#include "log_util.h"
#include "memory.h"
#include "definitions.h"
Include dependency graph for http_client_libcurl.c:

Go to the source code of this file.

Data Structures

struct  libcurl_payload_t
 

Macros

#define CARRIAGE_RETURN   '\r'
 
#define LINE_FEED   '\n'
 
#define DOMAIN_SEPERATOR   '\\'
 
#define SUPPORTED_CIPHERS_LIST
 

Functions

static CURLcode _ssl_context_callback (CURL *curl, void *ssl_context, void *certificate)
 
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 *http_request)
 
static mcl_bool_t _is_empty_line (char *line)
 
static struct curl_slist * _set_request_options (CURL *curl, http_request_t *http_request, http_client_send_callback_info_t *callback_info)
 
static int _curl_debug_callback (CURL *curl, curl_infotype info_type, char *data, mcl_size_t size, void *debug_data)
 
static E_MCL_ERROR_CODE _convert_to_mcl_error_code (CURLcode curl_code)
 
E_MCL_ERROR_CODE http_client_initialize (configuration_t *configuration, http_client_t **http_client)
 HTTP Client initializer. More...
 
E_MCL_ERROR_CODE http_client_send (http_client_t *http_client, http_request_t *http_request, http_client_send_callback_info_t *callback_info, http_response_t **http_response)
 Send/Receive function. More...
 
mcl_size_t http_client_get_callback_termination_code ()
 To get the implementation specific code for returning from callback function in order to terminate the send operation. More...
 
void http_client_destroy (http_client_t **http_client)
 To destroy the HTTP Client Handler. More...
 

Variables

static mcl_bool_t curl_global_initialized = MCL_FALSE
 

Detailed Description

HTTP client libcurl implementation file.


Date
Jul 20, 2016 HTTP client implementation file using LibCurl.

Definition in file http_client_libcurl.c.

Macro Definition Documentation

#define CARRIAGE_RETURN   '\r'

Definition at line 26 of file http_client_libcurl.c.

Referenced by _is_empty_line().

#define DOMAIN_SEPERATOR   '\\'

Definition at line 28 of file http_client_libcurl.c.

Referenced by http_client_initialize().

#define LINE_FEED   '\n'

Definition at line 27 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 30 of file http_client_libcurl.c.

Referenced by http_client_initialize().

Function Documentation

static int _curl_debug_callback ( CURL *  curl,
curl_infotype  info_type,
char *  data,
mcl_size_t  size,
void *  debug_data 
)
static

Referenced by _set_request_options(), and http_client_initialize().

Here is the caller graph for this function:

static mcl_bool_t _is_empty_line ( char *  line)
static

Definition at line 416 of file http_client_libcurl.c.

References CARRIAGE_RETURN, DEBUG_ENTRY, DEBUG_LEAVE, LINE_FEED, 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 *  http_request 
)
static

Definition at line 390 of file http_client_libcurl.c.

References DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, http_request_t::payload, http_request_t::payload_offset, http_request_t::payload_size, and string_util_memcpy().

Referenced by _set_request_options().

Here is the call graph for this function:

Here is the caller graph for this function:

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 352 of file http_client_libcurl.c.

References _is_empty_line(), DEBUG_ENTRY, DEBUG_LEAVE, MCL_ERROR, MCL_NULL, MCL_OK, MCL_TRUE, string_array_add(), string_destroy(), and string_initialize_new().

Referenced by 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 322 of file http_client_libcurl.c.

References ASSERT_CODE_MESSAGE, libcurl_payload_t::data, DEBUG_ENTRY, DEBUG_LEAVE, MCL_MALLOC, MCL_NULL, MCL_RESIZE, libcurl_payload_t::size, and string_util_memcpy().

Referenced by http_client_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

static CURLcode _ssl_context_callback ( CURL *  curl,
void *  ssl_context,
void *  certificate 
)
static

Definition at line 250 of file http_client_libcurl.c.

References ASSERT_CODE_MESSAGE, string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, string_t::length, MCL_ERROR_RETURN, MCL_INFO, and MCL_NULL.

Referenced by http_client_initialize().

Here is the caller graph for this function:

void http_client_destroy ( http_client_t **  http_client)

To destroy the HTTP Client Handler.

Will release the resources of HTTP Request. After destroy operation, handler shouldn't be used.

Parameters
[in]http_clientHTTP Client Handler.

Definition at line 230 of file http_client_libcurl.c.

References DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_FREE, and MCL_NULL.

Referenced by http_processor_destroy().

Here is the caller graph for this function:

mcl_size_t http_client_get_callback_termination_code ( )

To get the implementation specific code for returning from callback function in order to terminate the send operation.

Returns
Returns the termination code.

Definition at line 220 of file http_client_libcurl.c.

References DEBUG_ENTRY, and DEBUG_LEAVE.

Referenced by _get_payload_from_file().

Here is the caller graph for this function:

E_MCL_ERROR_CODE http_client_initialize ( configuration_t configuration,
http_client_t **  http_client 
)

HTTP Client initializer.

Initializes the underlying implementation (like libcurl) with the given configuration data.

Parameters
[in]configurationThe configuration data. This is the same configuration data given to configuration_t when initializing it.
[out]http_clientHandle for the http client initialized.
Returns

Definition at line 52 of file http_client_libcurl.c.

References _curl_debug_callback(), _response_header_callback(), _response_payload_callback(), _ssl_context_callback(), ASSERT_CODE_MESSAGE, string_t::buffer, curl_global_initialized, DEBUG_ENTRY, DEBUG_LEAVE, DOMAIN_SEPERATOR, configuration_t::http_request_timeout, string_t::length, MCL_DEBUG, MCL_FALSE, MCL_INITIALIZATION_FAIL, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_TRUE, memory_calloc(), memory_free(), memory_malloc(), memory_realloc(), configuration_t::mindsphere_certificate, configuration_t::mindsphere_port, configuration_t::proxy_domain, configuration_t::proxy_hostname, configuration_t::proxy_password, configuration_t::proxy_port, configuration_t::proxy_type, configuration_t::proxy_username, SSL_CERTIFICATE_TYPE_PEM, string_destroy(), string_initialize_new(), string_util_snprintf(), string_util_strdup(), and SUPPORTED_CIPHERS_LIST.

Referenced by http_processor_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE http_client_send ( http_client_t http_client,
http_request_t http_request,
http_client_send_callback_info_t callback_info,
http_response_t **  http_response 
)

Send/Receive function.

Using underlying implementation, it sends the given data to the pre-configured destination and returns the response. This function is blocking until response received or timeout occurred.

Parameters
[in]http_clientHTTP Client Handler.
[in]http_requestHTTP Request object.
[in]callback_infoStruct holding callback information. Refer to its definition http_client_send_callback_info_t.
[out]http_responseHTTP Response object.
Returns

Definition at line 156 of file http_client_libcurl.c.

References _convert_to_mcl_error_code(), _set_request_options(), ASSERT_STATEMENT_CODE_MESSAGE, http_client_t::curl, libcurl_payload_t::data, DEBUG_ENTRY, DEBUG_LEAVE, http_response_initialize(), MCL_ERROR_RETURN, MCL_FREE, MCL_INFO, MCL_NEW, MCL_NULL, MCL_OK, libcurl_payload_t::size, string_array_destroy(), and string_array_initialize().

Referenced by http_processor_exchange(), http_processor_get_access_token(), http_processor_register(), and http_processor_stream().

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 41 of file http_client_libcurl.c.

Referenced by http_client_initialize().