mcl_http_request.h File Reference

HTTP request module interface header file. More...

Include dependency graph for mcl_http_request.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mcl_http_request_t
 

Typedefs

typedef mcl_size_t(* mcl_http_payload_callback) (char *buffer, mcl_size_t size, mcl_size_t count, void *user_context)
 

Enumerations

enum  E_MCL_HTTP_METHOD {
  MCL_HTTP_GET = 0, MCL_HTTP_HEAD, MCL_HTTP_POST, MCL_HTTP_PUT,
  MCL_HTTP_DELETE, MCL_HTTP_PATCH, MCL_HTTP_CONNECT, MCL_HTTP_OPTIONS,
  MCL_HTTP_TRACE, MCL_HTTP_END
}
 
enum  E_MCL_HTTP_REQUEST_PARAMETER {
  MCL_HTTP_REQUEST_PARAMETER_METHOD = 0, MCL_HTTP_REQUEST_PARAMETER_URL, MCL_HTTP_REQUEST_PARAMETER_BODY, MCL_HTTP_REQUEST_PARAMETER_BODY_SIZE,
  MCL_HTTP_REQUEST_PARAMETER_STREAM_CALLBACK, MCL_HTTP_REQUEST_PARAMETER_STREAM_DATA, MCL_HTTP_REQUEST_PARAMETER_END
}
 

Functions

MCL_CORE_EXPORT mcl_error_t mcl_http_request_initialize (mcl_http_request_t **http_request)
 
MCL_CORE_EXPORT mcl_error_t mcl_http_request_add_header (mcl_http_request_t *http_request, const char *header_name, const char *header_value)
 
MCL_CORE_EXPORT mcl_error_t mcl_http_request_set_parameter (mcl_http_request_t *http_request, E_MCL_HTTP_REQUEST_PARAMETER parameter, const void *value)
 
MCL_CORE_EXPORT void mcl_http_request_destroy (mcl_http_request_t **http_request)
 

Detailed Description

HTTP request module interface header file.

This module is used internally by other MCL modules to prepare an HTTP request before mcl_http_client_send is called. HTTP request (mcl_http_request_t) can be initialized with mcl_http_request_initialize function. Following initialization, header fields can be set with mcl_http_request_add_header function. HTTP request options listed in E_MCL_HTTP_REQUEST_PARAMETER can be set using mcl_http_request_set_parameter function. After HTTP request is sent, it has to be destroyed using mcl_http_request_destroy function.

Definition in file mcl_http_request.h.

Typedef Documentation

typedef mcl_size_t(* mcl_http_payload_callback) (char *buffer, mcl_size_t size, mcl_size_t count, void *user_context)

Callback function prototype for adding payload to HTTP request.

Parameters
[in]bufferDestination address for payload.
[in]sizeSize, in bytes, of each element to be read.
[in]countNumber of elements, each one with a size of size bytes.
[in]user_contextSource address for payload.
Returns
The total number of bytes successfully written is returned.

Definition at line 66 of file mcl_http_request.h.

Enumeration Type Documentation

HTTP method types.

Enumerator
MCL_HTTP_GET 

Http get method.

MCL_HTTP_HEAD 

Http head method.

MCL_HTTP_POST 

Http post method.

MCL_HTTP_PUT 

Http put method.

MCL_HTTP_DELETE 

Http delete method.

MCL_HTTP_PATCH 

Http patch method.

MCL_HTTP_CONNECT 

Http connect method.

MCL_HTTP_OPTIONS 

Http options method.

MCL_HTTP_TRACE 

Http trace method.

MCL_HTTP_END 

Definition at line 29 of file mcl_http_request.h.

HTTP request options.

Enumerator
MCL_HTTP_REQUEST_PARAMETER_METHOD 

Method of the http request as E_MCL_HTTP_METHOD.

MCL_HTTP_REQUEST_PARAMETER_URL 

Url of the http request as char*.

MCL_HTTP_REQUEST_PARAMETER_BODY 

Body of the http request as char*. HTTP Request neither copies the buffer, nor takes ownership.

MCL_HTTP_REQUEST_PARAMETER_BODY_SIZE 

Size of the body of the http request in bytes as mcl_size_t.

MCL_HTTP_REQUEST_PARAMETER_STREAM_CALLBACK 

Stream callback.

MCL_HTTP_REQUEST_PARAMETER_STREAM_DATA 

Stream data.

MCL_HTTP_REQUEST_PARAMETER_END 

Definition at line 46 of file mcl_http_request.h.

Function Documentation

MCL_CORE_EXPORT mcl_error_t mcl_http_request_add_header ( mcl_http_request_t http_request,
const char *  header_name,
const char *  header_value 
)

This function is used to add an HTTP header to the request with its value.

Parameters
[in]http_requestHTTP request handle to be used.
[in]header_nameHeader name.
[in]header_valueHeader value.
Returns

Definition at line 57 of file http_request.c.

References mcl_http_request_t::header, MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_FUNCTION_LEAVE_LABEL, mcl_list_add(), MCL_MALLOC, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, string_util_snprintf(), and string_util_strlen().

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:

MCL_CORE_EXPORT void mcl_http_request_destroy ( mcl_http_request_t **  http_request)

This function destroys HTTP request data structure.

Parameters
[in]http_requestHTTP request handle to be freed.

Definition at line 155 of file http_request.c.

References _http_request_header_destroy(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, mcl_list_destroy_with_content(), and MCL_NULL.

Referenced by core_processor_get_access_token(), core_processor_register(), and mcl_http_request_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

MCL_CORE_EXPORT mcl_error_t mcl_http_request_initialize ( mcl_http_request_t **  http_request)

This function creates and initializes an mcl_http_request_t.

Parameters
[out]http_requestThe newly initialized HTTP request.
Returns

Definition at line 18 of file http_request.c.

References MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_HTTP_GET, mcl_http_request_destroy(), mcl_list_initialize(), MCL_NEW, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.

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:

MCL_CORE_EXPORT mcl_error_t mcl_http_request_set_parameter ( mcl_http_request_t http_request,
E_MCL_HTTP_REQUEST_PARAMETER  parameter,
const void *  value 
)

This function is used to set a parameter of HTTP request.

Parameters
[in]http_requestHTTP request handle to be used.
[in]parameterOne of the parameters listed in E_MCL_HTTP_REQUEST_PARAMETER.
[in]valueNew value of the parameter.
Returns

Definition at line 97 of file http_request.c.

References MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_HTTP_END, MCL_HTTP_REQUEST_PARAMETER_BODY, MCL_HTTP_REQUEST_PARAMETER_BODY_SIZE, MCL_HTTP_REQUEST_PARAMETER_METHOD, MCL_HTTP_REQUEST_PARAMETER_STREAM_CALLBACK, MCL_HTTP_REQUEST_PARAMETER_STREAM_DATA, MCL_HTTP_REQUEST_PARAMETER_URL, MCL_INVALID_PARAMETER, MCL_NULL, MCL_OK, mcl_http_request_t::method, mcl_http_request_t::payload, mcl_http_request_t::payload_size, mcl_http_request_t::stream_callback, mcl_http_request_t::stream_data, string_util_reset(), and mcl_http_request_t::uri.

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: