list.c File Reference

List module implementation file. More...

#include "list.h"
#include "mcl_core/mcl_assert.h"
#include "mcl_core/mcl_memory.h"
Include dependency graph for list.c:

Go to the source code of this file.

Functions

mcl_error_t mcl_list_initialize (mcl_list_t **list)
 
mcl_error_t mcl_list_add (mcl_list_t *list, void *data)
 
mcl_error_t mcl_list_next (mcl_list_t *list, mcl_list_node_t **node)
 
mcl_error_t mcl_list_remove (mcl_list_t *list, mcl_list_node_t *node)
 
mcl_error_t mcl_list_remove_with_content (mcl_list_t *list, mcl_list_node_t *node, mcl_list_item_destroy_callback callback)
 
mcl_error_t mcl_list_exist (mcl_list_t *list, const void *item_to_find, mcl_list_compare_callback compare_function, void **item)
 
void mcl_list_reset (mcl_list_t *list)
 
void mcl_list_destroy (mcl_list_t **list)
 
void mcl_list_destroy_with_content (mcl_list_t **list, mcl_list_item_destroy_callback callback)
 

Detailed Description

List module implementation file.

Definition in file list.c.

Function Documentation

mcl_error_t mcl_list_add ( mcl_list_t list,
void *  data 
)

This function adds a new item to list.

A new list item pointed by data is added to the list. No new memory is allocated and no memory copy operations done. The lifetime of data should be handled by the caller of this function.

Parameters
[in]listThe list to which the data is added.
[in]dataThe pointer to the list item to be added.
Returns

Definition at line 34 of file list.c.

References mcl_list_t::count, mcl_list_t::current, mcl_list_node_t::data, mcl_list_t::head, mcl_list_t::last, MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_LIMIT_EXCEEDED, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_SIZE_MAX, MCL_VERBOSE, mcl_list_node_t::next, and mcl_list_node_t::prev.

Referenced by _response_header_callback(), get_response(), mcl_http_client_add_certificate(), and mcl_http_request_add_header().

Here is the caller graph for this function:

void mcl_list_destroy ( mcl_list_t **  list)

This function destroys the list.

For every node in the list, it frees the node but not the data it holds. After all nodes freed, it frees the list itself and sets it's value to NULL.

User needs to free all the data that the list is holding before destroying it!

Parameters
[in]listThe address of the pointer of the list to be destroyed.

Definition at line 293 of file list.c.

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

Here is the call graph for this function:

void mcl_list_destroy_with_content ( mcl_list_t **  list,
mcl_list_item_destroy_callback  callback 
)

This function destroys the list and its items with a given callback function.

For every node in the list, it frees the node. The data of the node can also freed by given callback function. After all nodes freed, it frees the list itself and sets it's value to NULL.

Parameters
[in]listThe address of the pointer of the list to be destroyed.
[in]callbackThe callback function to destroy each node data within the list. If NULL no action will be performed.

Definition at line 302 of file list.c.

References mcl_list_node_t::data, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_NULL, MCL_VERBOSE, and mcl_list_node_t::next.

Referenced by get_response(), mcl_http_client_destroy(), mcl_http_client_send(), mcl_http_request_destroy(), mcl_http_response_destroy(), and mcl_list_destroy().

Here is the caller graph for this function:

mcl_error_t mcl_list_exist ( mcl_list_t list,
const void *  item_to_find,
mcl_list_compare_callback  compare_function,
void **  item 
)

This function searches item_to_find in the list.

Parameters
[in]listThe list to search in.
[in]item_to_findItem to search for.
[in]compare_functionCallback function used to compare.
[out]itemPointer to the item found.
Returns

Definition at line 239 of file list.c.

References mcl_list_node_t::data, mcl_list_t::head, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_FUNCTION_LEAVE_LABEL, MCL_NULL, MCL_OK, and mcl_list_node_t::next.

mcl_error_t mcl_list_initialize ( mcl_list_t **  list)

This function initializes a list with zero items in it.

Parameters
[out]listInitialized mcl_list_t instance.
Returns

Definition at line 13 of file list.c.

References MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_NEW, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.

Referenced by get_response(), mcl_http_client_initialize(), mcl_http_client_send(), and mcl_http_request_initialize().

Here is the caller graph for this function:

mcl_error_t mcl_list_next ( mcl_list_t list,
mcl_list_node_t **  node 
)

This function gets the next node from the list.

Last returned node is kept in list. This function can be called consequently to loop over the list. If there is no node left to return or the list is empty, node will be NULL.

Parameters
[in]listThe list.
[out]nodeAddress of next node.
Returns

Definition at line 76 of file list.c.

References mcl_list_t::current, mcl_list_t::head, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_FUNCTION_LEAVE_LABEL, MCL_NULL, MCL_OK, and mcl_list_node_t::next.

Referenced by _ssl_context_callback(), mcl_http_response_get_header(), and send_header_list().

Here is the caller graph for this function:

mcl_error_t mcl_list_remove ( mcl_list_t list,
mcl_list_node_t node 
)

This function removes a node from the list.

The list node is removed from the list and its handle of type mcl_list_node_t will be freed but the data that it holds will not. User needs to free the resource before it calls remove!

Parameters
[in]listThe list from which the node is removed.
[in]nodeThe node to be removed.
Returns

Definition at line 117 of file list.c.

References mcl_list_t::count, mcl_list_t::current, mcl_list_t::head, mcl_list_t::last, MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_FUNCTION_LEAVE_LABEL, MCL_LIST_IS_EMPTY, MCL_NULL, MCL_OK, MCL_VERBOSE, mcl_list_node_t::next, and mcl_list_node_t::prev.

Referenced by mcl_list_remove_with_content().

Here is the caller graph for this function:

mcl_error_t mcl_list_remove_with_content ( mcl_list_t list,
mcl_list_node_t node,
mcl_list_item_destroy_callback  callback 
)

This function removes a node from the list and destroys the removed item with the provided callback function.

The node (mcl_list_node_t) will be freed and the data that it holds is going to be destroyed by passing it to the provided callback function.

Parameters
[in]listThe list from which the node is removed.
[in]nodeThe node to be removed.
[in]callbackThe callback function to destroy the list item.
Returns

Definition at line 214 of file list.c.

References mcl_list_node_t::data, MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, mcl_list_remove(), MCL_NULL, and MCL_OK.

Here is the call graph for this function:

void mcl_list_reset ( mcl_list_t list)

This function resets the current node to head node.

The goal here is to be able to loop over the list from it's beginning.

Parameters
[in]listThe list which is used to reset it's current node to it's head node.

Definition at line 276 of file list.c.

References mcl_list_t::current, mcl_list_t::head, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, and MCL_VERBOSE.

Referenced by _set_request_options(), _ssl_context_callback(), mcl_http_response_get_header(), and send_header_list().

Here is the caller graph for this function: