string_type.h File Reference

String type module header file. More...

#include "list.h"
#include "string_util.h"
Include dependency graph for string_type.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  string_t
 

Enumerations

enum  E_MCL_STRING_TYPE { MCL_STRING_COPY_DESTROY, MCL_STRING_NOT_COPY_DESTROY, MCL_STRING_NOT_COPY_NOT_DESTROY }
 This type defines the different kind of string behaviors during string initialization and destroy. More...
 

Functions

E_MCL_ERROR_CODE string_initialize (const string_t *other, string_t **string)
 Initializes an string_t object with another one. More...
 
E_MCL_ERROR_CODE string_initialize_new (const char *value, mcl_size_t value_length, string_t **string)
 Initializes a new string_t object with the given value and length. More...
 
E_MCL_ERROR_CODE string_initialize_dynamic (const char *value, mcl_size_t value_length, string_t **string)
 Initializes a dynamic string_t object with the given value and length. More...
 
E_MCL_ERROR_CODE string_initialize_static (const char *value, mcl_size_t value_length, string_t **string)
 Initializes a static string_t object with the given value and length. More...
 
E_MCL_ERROR_CODE string_set (string_t *string, const char *value, mcl_size_t value_length)
 Sets the buffer of the string with a new value. More...
 
E_MCL_ERROR_CODE string_compare (const string_t *string, const string_t *other)
 Compare the contents of two string_t's. More...
 
E_MCL_ERROR_CODE string_compare_with_cstr (const string_t *string, const char *other)
 Compare the contents of string_t with a C string. More...
 
E_MCL_ERROR_CODE string_split (string_t *string, const char token, list_t **string_list)
 Splits the string with the given char and returns the result as an list_t of string_t's. More...
 
E_MCL_ERROR_CODE string_convert_binary_to_hex (const mcl_uint8_t *buffer, mcl_size_t buffer_size, string_t **hex_data)
 
void string_release (string_t *string)
 Clears the content of the string. And deallocates the memory. More...
 
void string_destroy (string_t **string)
 Destroys the allocated resources of the string. More...
 
E_MCL_ERROR_CODE string_concatenate_cstr (string_t *string, char *c_string, string_t **result)
 Concatenates two strings of type string_t into a string_t. More...
 
E_MCL_ERROR_CODE string_concatenate (string_t *string_1, string_t *string_2, string_t **result)
 Concatenates a C string (i.e. a char array) More...
 
E_MCL_ERROR_CODE string_replace (string_t *source, const char *old_string, const char *new_string, string_t **result)
 Replaces old_string with new_string. More...
 

Variables

const char * hex_table
 

Detailed Description

String type module header file.


Date
Aug 2, 2016 This module introduces string_t type which holds the C string inside along with length information. Operations that can be performed on this type are also defined in this module.

Definition in file string_type.h.

Enumeration Type Documentation

This type defines the different kind of string behaviors during string initialization and destroy.

The type of a string will be determined by which initialize function has called for it.

Enumerator
MCL_STRING_COPY_DESTROY 

Strings with this type will allocates its buffer during initialization (copies the initial value to its buffer) and free its buffer during destroy.

MCL_STRING_NOT_COPY_DESTROY 

Strings with this type will NOT allocate its buffer during initialization (buffer only points of the initial value) and free its buffer during destroy.

MCL_STRING_NOT_COPY_NOT_DESTROY 

Strings with this type will NOT allocate its buffer during initialization (buffer only points of the initial value) and NOT free its buffer during destroy (freeing the buffer will be responsibility of the caller).

Definition at line 33 of file string_type.h.

Function Documentation

E_MCL_ERROR_CODE string_compare ( const string_t string,
const string_t other 
)

Compare the contents of two string_t's.

Parameters
[in]stringString handler to compare.
[in]otherOther string handler to compare.
Returns
MCL_OK if two are the same. MCL_FAIL if they are not.
  • MCL_OK in case string is the same as other.
  • MCL_FAIL in case string is not the same as other.

Definition at line 129 of file string_type.c.

References string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, and string_compare_with_cstr().

Referenced by _add_item_meta_payload_details(), and http_request_add_header().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_compare_with_cstr ( const string_t string,
const char *  other 
)

Compare the contents of string_t with a C string.

Parameters
[in]stringString handler to compare.
[in]otherZero terminating C string to compare.
Returns
  • MCL_OK in case string is the same as other.
  • MCL_FAIL in case string is not the same as other.

Definition at line 139 of file string_type.c.

References string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, string_t::length, MCL_DEBUG, MCL_FAIL, MCL_NULL, MCL_OK, string_util_strlen(), and string_util_strncmp().

Referenced by _compare_item_meta_of_event(), http_processor_update_security_information(), mcl_store_new_event(), and string_compare().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_concatenate ( string_t string_1,
string_t string_2,
string_t **  result 
)

Concatenates a C string (i.e. a char array)

Parameters
[in]string_1String to which the string_2 will be concatenated.
[in]string_2String which will be concatenated to string_1.
[out]resultThe string that is result of the concatenation.
Returns

Definition at line 416 of file string_type.c.

References ASSERT_STATEMENT_CODE_MESSAGE, string_t::buffer, string_t::length, MCL_FAIL, MCL_NULL, MCL_OK, string_destroy(), string_initialize_new(), string_util_snprintf(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_authentication_header_to_request(), and _compose_access_token_request_payload().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_concatenate_cstr ( string_t string,
char *  c_string,
string_t **  result 
)

Concatenates two strings of type string_t into a string_t.

Parameters
[in]stringString to which the cstring will be concatenated.
[in]c_stringChar array which will be concatenated to string.
[out]resultThe string that is result of the concatenation.
Returns

Definition at line 465 of file string_type.c.

References ASSERT_STATEMENT_CODE_MESSAGE, string_t::buffer, MCL_NULL, MCL_OK, string_destroy(), string_initialize_new(), string_util_snprintf(), string_util_strlen(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Here is the call graph for this function:

E_MCL_ERROR_CODE string_convert_binary_to_hex ( const mcl_uint8_t buffer,
mcl_size_t  buffer_size,
string_t **  hex_data 
)

Converts given buffer to its hex representation as string. Allocates a new memory for resulting string with the size of

1 2*buffer_size + 1

. The returned string is zero terminated.

Parameters
[in]bufferThe buffer which contains data to be converted.
[in]buffer_sizeThe length of the buffer.
[out]hex_dataThe newly allocated string which contains conversion result and which is zero terminated.
Returns

Definition at line 272 of file string_type.c.

References ASSERT_CODE_MESSAGE, hex_table, MCL_CALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_OK, MCL_OUT_OF_MEMORY, string_initialize_new(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Here is the call graph for this function:

void string_destroy ( string_t **  string)

Destroys the allocated resources of the string.

After destroy operation, string handler shouldn't be used.

Parameters
[in]stringAddress of the string handler to destroy. It's value will be set to MCL_NULL after destroying.

Definition at line 326 of file string_type.c.

References MCL_FREE, MCL_NULL, string_release(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_authentication_header_to_request(), _compose_access_token_request_payload(), _concatenate_host_and_endpoint(), _create_self_issued_jwt_payload(), _destroy_data_point(), _destroy_data_source(), _destroy_value_set(), _destroy_value_set_value(), _exchange_prepare_data(), _generate_correlation_id_string(), _generate_random_boundary(), _generate_token(), _get_header_and_payload_encoded_base64_url(), _join_with_dot(), _process_registration_response_rsa_3072(), _process_registration_response_shared_secret(), _response_header_callback(), _store_list_destroy_callback(), custom_data_destroy(), data_source_configuration_destroy(), event_destroy(), event_list_destroy(), file_destroy(), http_client_initialize(), http_processor_destroy(), http_processor_exchange(), http_processor_get_access_token(), http_processor_register(), http_processor_stream(), http_processor_update_security_information(), http_request_add_header(), http_request_add_tuple(), http_request_destroy(), http_response_get_header(), jwt_get_token(), mcl_communication_destroy(), mcl_communication_process(), mcl_event_set_option(), security_handler_destroy(), storage_load_rsa_registration_information(), storage_load_shared_secret_registration_information(), string_array_destroy(), string_concatenate(), string_concatenate_cstr(), string_split(), time_series_destroy(), and time_util_convert_to_iso_8601_format().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_initialize ( const string_t other,
string_t **  string 
)

Initializes an string_t object with another one.

The content of the buffer of the other string will be copied into the new string's buffer. The type of the string will be MCL_STRING_COPY_DESTROY.

Parameters
[in]otherOther string_t object to initialize from.
[out]stringWill point to the initialized string_t object.
Returns

Definition at line 24 of file string_type.c.

References _initialize(), ASSERT_CODE_MESSAGE, string_t::buffer, string_t::length, MCL_ERROR, MCL_FREE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_STRING_COPY_DESTROY, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by http_request_initialize(), http_response_get_header(), and mcl_data_source_configuration_get_id().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_initialize_dynamic ( const char *  value,
mcl_size_t  value_length,
string_t **  string 
)

Initializes a dynamic string_t object with the given value and length.

A Dynamic string means that it will not allocate any memory space for its buffer. Its buffer will point to the address of the initial value but it frees the buffer when string_destroy() is called.
This is good for usage like this :

string_t *string;
string_initialize_dynamic(cJSON_Print(), 0, &string);

If received length is zero, length of the string will be calculated.

Warning
The given value must be a zero-terminated C string.
Parameters
[in]valueThe content to initialize the string with. If it is not NULL it will be copied into the buffer of the string. If it is NULL, an empty string with NULL buffer will be created.
[in]value_lengthThe length of the value. If this length is non zero it will be accepted as the correct length of the string. If the length is not known can be passed as zero and initialize function will calculate the length itself.
[out]stringWill point to the initialized string_t object.
Returns

Definition at line 68 of file string_type.c.

References _initialize(), ASSERT_CODE_MESSAGE, MCL_ERROR, MCL_FREE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_STRING_NOT_COPY_DESTROY, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _compose_rsa_key_rotation_json(), _compose_rsa_onboarding_json(), _custom_load_register_info(), _encode_with_table(), _process_registration_response_rsa_3072(), http_processor_update_security_information(), json_from_data_source_configuration_payload(), json_from_event_payload(), json_from_item_meta(), json_from_time_series_payload(), jwt_get_token(), random_generate_guid(), string_array_to_string(), and string_replace().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_initialize_new ( const char *  value,
mcl_size_t  value_length,
string_t **  string 
)

Initializes a new string_t object with the given value and length.

A New string means that it will copy the content of value into its buffer and frees the buffer when string_destroy() is called. If received length is zero, length of the string will be calculated.
This is good for usage like this :

string_t *string;
string_initialize_new("Hello World!", 0, &string);
Warning
The given value must be a zero-terminated C string.
Parameters
[in]valueThe content to initialize the string with. If it is not NULL it will be copied into the buffer of the string. If it is NULL, an empty string with NULL buffer will be created.
[in]value_lengthThe length of the value. If this length is non zero it will be accepted as the correct length of the string. If the length is not known can be passed as zero and initialize function will calculate the length itself.
[out]stringWill point to the initialized string_t object.
Returns

Definition at line 46 of file string_type.c.

References _initialize(), ASSERT_CODE_MESSAGE, MCL_ERROR, MCL_FREE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_STRING_COPY_DESTROY, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _concatenate_host_and_endpoint(), _generate_correlation_id_string(), _generate_random_boundary(), _initialize_custom_data_meta_fields(), _initialize_meta(), _process_registration_response_rsa_3072(), _response_header_callback(), event_initialize(), file_initialize(), http_client_initialize(), http_processor_register(), http_request_add_header(), json_util_get_string(), mcl_communication_initialize(), mcl_communication_process(), mcl_data_source_configuration_add_data_point(), mcl_data_source_configuration_add_data_source(), mcl_event_set_option(), mcl_time_series_add_value(), mcl_time_series_new_value_set(), storage_load_rsa_registration_information(), storage_load_shared_secret_registration_information(), string_concatenate(), string_concatenate_cstr(), string_convert_binary_to_hex(), string_split(), and time_util_convert_to_iso_8601_format().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_initialize_static ( const char *  value,
mcl_size_t  value_length,
string_t **  string 
)

Initializes a static string_t object with the given value and length.

A Static string means that it will not allocate any memory space for its buffer. Its buffer will point to the address of the initial value and also it will not free the buffer when string_destroy() is called. If received length is zero, length of the string will be calculated.
This is good for usage like this :

void func(char *in_cstr)
{
string_t *string;
string_initialize_static(in_cstr, 0, &string);
}
Warning
The given value must be a zero-terminated C string.
Parameters
[in]valueThe content to initialize the string with. If it is not NULL it will be copied into the buffer of the string. If it is NULL, an empty string with NULL buffer will be created.
[in]value_lengthThe length of the value. If this length is non zero it will be accepted as the correct length of the string. If the length is not known can be passed as zero and initialize function will calculate the length itself.
[out]stringWill point to the initialized string_t object.
Returns

Definition at line 90 of file string_type.c.

References _initialize(), ASSERT_CODE_MESSAGE, MCL_ERROR, MCL_FREE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_STRING_NOT_COPY_NOT_DESTROY, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_authentication_header_to_request(), _compose_access_token_request_payload(), _initialize_custom_data_meta_fields(), _initialize_meta(), file_initialize(), and http_processor_get_access_token().

Here is the call graph for this function:

Here is the caller graph for this function:

void string_release ( string_t string)

Clears the content of the string. And deallocates the memory.

Clears the content of the string, sets the buffer to MCL_NULL and the length to zero.

Parameters
[in]stringString to be released.

Definition at line 298 of file string_type.c.

References string_t::buffer, MCL_FREE, MCL_NULL, MCL_STRING_COPY_DESTROY, MCL_STRING_NOT_COPY_DESTROY, MCL_VERBOSE, string_t::type, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by string_destroy(), and string_set().

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_replace ( string_t source,
const char *  old_string,
const char *  new_string,
string_t **  result 
)

Replaces old_string with new_string.

Parameters
[in]sourceThe string in which the replacement will be done.
[in]old_stringPart of source that will be replaced.
[in]new_stringNew string which will be replaced with old_string.
[out]resultString that is created as result of the replacement.
Returns

Definition at line 433 of file string_type.c.

References ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, string_t::buffer, string_t::length, MCL_CALLOC, MCL_FAIL, MCL_FREE, MCL_NULL, MCL_OUT_OF_MEMORY, MCL_TRUE, string_initialize_dynamic(), string_util_find(), string_util_strlen(), string_util_strncat(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Here is the call graph for this function:

E_MCL_ERROR_CODE string_set ( string_t string,
const char *  value,
mcl_size_t  value_length 
)

Sets the buffer of the string with a new value.

First string_release() is called and the buffer is released with or without freeing it depending on the string type. Then buffer assigned to the new value again either by copying or by referencing depending on string type. String type and behavior will not be changed with this function.

Parameters
[in]stringString handle to be set.
[in]valueThe new value to be set to the string. This must be a zero terminated C string.
[in]value_lengthIf value length is known, by passing it with this parameter would reduce operation cost by avoiding to calculate it again. If this parameter is given as 0, string_set will calculate the length.
Returns

Definition at line 112 of file string_type.c.

References _initialize(), ASSERT_CODE_MESSAGE, MCL_OK, string_release(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Here is the call graph for this function:

E_MCL_ERROR_CODE string_split ( string_t string,
const char  token,
list_t **  string_list 
)

Splits the string with the given char and returns the result as an list_t of string_t's.

Parameters
[in]stringString handler to split.
[in]tokenChar value to split the string.
[out]string_listThe prepared list containing the splitted strings.
Returns

Definition at line 179 of file string_type.c.

References ASSERT_CODE_MESSAGE, string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, list_add(), list_destroy_with_content(), list_initialize(), MCL_DEBUG, MCL_ERROR, MCL_NULL, MCL_NULL_CHAR, MCL_OK, string_destroy(), and string_initialize_new().

Referenced by http_response_get_header().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char* hex_table

Definition at line 19 of file string_type.c.

Referenced by string_convert_binary_to_hex().