14 #include "cJSON/cJSON.h" 41 DEBUG_ENTRY(
"E_MCL_JSON_TYPE json_type = <%d>, mcl_json_t **root = <%p>", json_type, root)
55 VERBOSE_ENTRY(
"E_JSON_TYPE json_type = <%p>, json_t **root = <%p>", &json_type, root)
65 (*root)->root_handle = cJSON_CreateArray();
69 (*root)->root_handle = cJSON_CreateObject();
73 MCL_VERBOSE(
"json_type = <%d> is out of valid types.", json_type);
86 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *array_name = <%p>, mcl_json_t **json_array = <%p>", root, array_name, json_array)
102 VERBOSE_ENTRY(
"json_t *root = <%p>, const char *array_name = <%p>, json_t **json_array = <%p>", root, array_name, json_array)
114 cJSON_AddItemToObject(root->
root_handle, array_name, (*json_array)->root_handle);
128 DEBUG_ENTRY(
"mcl_json_t *array = <%p>, int index = <%d>, mcl_json_t **item = <%p>", array, index, item)
143 VERBOSE_ENTRY(
"json_t *root = <%p>, int index = <%d>", array, index, item)
152 item_cjson = cJSON_GetArrayItem(array->
root_handle, index);
153 (*item)->root_handle = cJSON_Duplicate(item_cjson,
MCL_TRUE);
162 DEBUG_ENTRY(
"mcl_json_t *array = <%p>, int *size = <%p>", array, size)
175 VERBOSE_ENTRY(
"json_t *array = <%p>, mcl_size_t *size = <%p>", array, size)
184 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *object_name = <%p>, mcl_json_t **json_object = <%p>", root, object_name, json_object)
200 VERBOSE_ENTRY(
"json_t *root = <%p>, const char *object_name = <%p>, json_t **json_object = <%p>", root, object_name, json_object)
216 cJSON_AddItemToObject(root->
root_handle, object_name, (*json_object)->root_handle);
224 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *object_name = <%p>, const char *object_value = <%p>", root, object_name, object_value)
239 VERBOSE_ENTRY(
"json_t *root = <%p>, const char *object_name = <%p>, const char *object_value = <%p>", root, object_name, object_value)
245 cJSON *
string = cJSON_CreateString(object_value);
259 cJSON_AddStringToObject(root->
root_handle, object_name, object_value);
273 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *object_name = <%p>, const mcl_size_t number = <%u>", root, object_name, &number)
287 VERBOSE_ENTRY(
"json_t *root = <%p>, char *object_name = <%p>, mcl_size_t number = <%u>", root, object_name, number)
293 cJSON *json_number = cJSON_CreateNumber((
double)number);
294 cJSON_AddItemToArray(root->
root_handle, json_number);
307 cJSON_AddNumberToObject(root->
root_handle, object_name, (
double)number);
321 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *object_name = <%p>, const float number = <%p>", root, object_name, &number)
331 VERBOSE_ENTRY(
"json_t *root = <%p>, const char *object_name = <%p>, const float number = <%f>", root, object_name, number)
346 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *object_name = <%p>, const double number = <%f>", root, object_name, &number)
360 VERBOSE_ENTRY(
"json_t *root = <%p>, const char *object_name = <%p>, const double number = <%f>", root, object_name, number)
366 cJSON *json_number = cJSON_CreateNumber(number);
367 cJSON_AddItemToArray(root->
root_handle, json_number);
380 cJSON_AddNumberToObject(root->
root_handle, object_name, number);
394 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *object_name = <%p>, const mcl_bool_t bool_value = <%d>", root, object_name, &bool_value)
408 VERBOSE_ENTRY(
"json_t *root = <%p>, const char *object_name = <%p>, const mcl_bool_t bool_value = <%d>", root, object_name, bool_value)
414 cJSON *json_bool = cJSON_CreateBool(bool_value);
415 cJSON_AddItemToArray(root->
root_handle, json_bool);
428 cJSON_AddBoolToObject(root->
root_handle, object_name, bool_value);
442 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *object_name = <%p>", root, object_name)
456 VERBOSE_ENTRY(
"json_t *root = <%p>, const char *object_name = <%p>", root, object_name)
462 cJSON *json_null = cJSON_CreateNull();
463 cJSON_AddItemToArray(root->
root_handle, json_null);
476 cJSON_AddNullToObject(root->
root_handle, object_name);
490 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, const char *object_name = <%p>, mcl_json_t *object = <%p>", root, object_name,
object)
506 VERBOSE_ENTRY(
"json_t *root = <%p>, const char *object_name = <%p>, json_t *object = <%p>", root, object_name,
object)
529 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, mcl_json_t *object = <%p>", root,
object)
542 VERBOSE_ENTRY(
"json_t *root = <%p>, json_t *object = <%p>", root,
object)
551 DEBUG_ENTRY(
"mcl_json_t *json_parent = <%p>, const char *child_name = <%p>, mcl_json_t **json_child = <%p>", json_parent, child_name, json_child)
567 VERBOSE_ENTRY(
"json_t *json_parent = <%p>, const char *child_name = <%p>, json_t **json_child = <%p>", json_parent, child_name, json_child)
574 (*json_child)->root_handle = cJSON_GetObjectItem(json_parent->
root_handle, child_name);
577 if (
MCL_NULL == (*json_child)->root_handle)
589 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, mcl_bool_t *result = <%p>", root, result)
618 DEBUG_ENTRY(
"mcl_json_t *json = <%p>, mcl_int32_t *number_value = <%p>", json, number_value)
631 VERBOSE_ENTRY(
"json_t *json = <%p>, mcl_int32_t *number_value = <%p>", json, number_value)
640 DEBUG_ENTRY(
"mcl_json_t *json = <%p>, double *double_value = <%p>", json, double_value)
653 VERBOSE_ENTRY(
"json_t *json = <%p>, double *double_value = <%p>", json, double_value)
662 DEBUG_ENTRY(
"json_t *json = <%p>, mcl_bool_t *bool_value = <%p>", json, bool_value)
675 VERBOSE_ENTRY(
"json_t *json = <%p>, mcl_bool_t *bool_value = <%p>", json, bool_value)
691 DEBUG_ENTRY(
"mcl_json_t *json_item = <%p>, char **string_value = <%p>", json_item, string_value)
702 *string_value = string_value_local->
buffer;
713 VERBOSE_ENTRY(
"json_t *json_item = <%p>, char **string_value = <%p>", json_item, string_value)
716 "Memory can not be allocated for string_value.");
724 DEBUG_ENTRY(
"mcl_json_t *root = <%p>, char **json_string = <%p>", root, json_string)
739 VERBOSE_ENTRY(
"json_t *root = <%p>, char **json_string = <%p>", root, json_string)
741 *json_string = cJSON_PrintUnformatted(root->
root_handle);
750 DEBUG_ENTRY(
"const char *json_string = <%p>, mcl_size_t size = <%u>, mcl_json_t **root = <%p>", json_string, size, root);
765 VERBOSE_ENTRY(
"const char *json_string = <%p>, size_t size = <%u>, json_t **root = <%p>", json_string, size, root);
769 (*root)->root_handle = cJSON_Parse(json_string);
779 VERBOSE_ENTRY(
"const char *json_string = <%p>, size_t size = <%u>, json_t **root = <%p>", json_string, size, root);
787 (*root)->root_handle = cJSON_Parse(json_string);
791 (*root)->root_handle = cJSON_ParseWithSize(json_string, size);
807 VERBOSE_ENTRY(
"const json_t *source_json = <%p>, mcl_bool_t with_children = <%d>, json_t **duplicated_json = <%p>", source_json, with_children, duplicated_json)
810 (*duplicated_json)->root_handle =
MCL_NULL;
811 (*duplicated_json)->root_handle = cJSON_Duplicate(source_json->
root_handle, with_children);
820 DEBUG_ENTRY(
"json_t **json_array = <%p>", json_array)
838 DEBUG_ENTRY(
"json_t **json_object = <%p>", json_object)
869 cJSON_Delete((*root)->root_handle);
890 VERBOSE_ENTRY(
"E_MCL_JSON_TYPE mcl_json_type = <%d>", mcl_json_type)
894 switch (mcl_json_type)
905 MCL_VERBOSE(
"mcl_json_type = <%d> is out of valid types.", mcl_json_type);
struct mcl_json_t mcl_json_t
This struct is used for json handling.
mcl_bool_t json_util_has_child(json_t *root)
This function checks whether root object has child object or not.
E_MCL_ERROR_CODE mcl_json_util_get_double_value(mcl_json_t *json, double *double_value)
This function gets the double value of a given json object.
Memory module header file.
E_MCL_ERROR_CODE mcl_json_util_start_object(mcl_json_t *root, const char *object_name, mcl_json_t **json_object)
This function creates an object in root.
#define VERBOSE_LEAVE(...)
E_MCL_ERROR_CODE json_util_parse(const char *json_string, json_t **root)
This function parses the given string to the given json object.
E_MCL_ERROR_CODE json_util_add_uint(json_t *root, const char *object_name, const mcl_size_t number)
This function adds integer number to root which can be object or array.
E_MCL_ERROR_CODE mcl_json_util_get_array_size(mcl_json_t *array, mcl_size_t *size)
This function returns the size of array.
E_MCL_ERROR_CODE json_util_add_bool(json_t *root, const char *object_name, const mcl_bool_t bool_value)
This function adds bool_value to root which can be object or array.
cJSON * root_handle
Root cJson object.
E_MCL_ERROR_CODE json_util_get_string(json_t *json_item, string_t **string_value)
This function gets the string value of a given json object.
Json util module header file.
If a particular operation is not supported.
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.
E_MCL_ERROR_CODE mcl_json_util_has_child(mcl_json_t *root, mcl_bool_t *result)
This function checks whether root object has child object or not.
char * buffer
Buffer of string handle.
E_MCL_ERROR_CODE mcl_json_util_add_object(mcl_json_t *root, const char *object_name, mcl_json_t *object)
This function adds object to root.
E_MCL_ERROR_CODE json_util_start_array(json_t *root, const char *array_name, json_t **json_array)
This function creates an array in root.
#define ASSERT_NOT_NULL(argument)
#define MCL_FALSE
MCL bool type.
E_MCL_ERROR_CODE mcl_json_util_get_object_item(mcl_json_t *json_parent, const char *child_name, mcl_json_t **json_child)
This function gives the value of json_child object, when the child_name in json_parent object is give...
E_MCL_ERROR_CODE json_util_add_float(json_t *root, const char *object_name, const float number)
This function adds floating number to root.
E_MCL_ERROR_CODE mcl_json_util_get_array_item(mcl_json_t *array, int index, mcl_json_t **item)
This function gets the item at given index from array.
Log utility module header file.
String utility module implementation file.
E_MCL_ERROR_CODE mcl_json_util_add_string(mcl_json_t *root, const char *object_name, const char *object_value)
This function adds string to root which can be object or array.
E_MCL_ERROR_CODE mcl_json_util_get_number_value(mcl_json_t *json, mcl_int32_t *number_value)
This function gets the number value of a given json object.
E_MCL_ERROR_CODE
MCL Error code definitions. Every function returning an error code uses this enum values...
E_MCL_ERROR_CODE mcl_json_util_get_string(mcl_json_t *json_item, char **string_value)
This function gets the string value of a given json object.
void json_util_destroy(json_t **root)
This function destroys root.
void * memory_malloc(mcl_size_t size)
malloc wrapper
void json_util_get_number_value(json_t *json, mcl_int32_t *number_value)
This function gets the number value of a given json object.
void mcl_json_util_finish_object(mcl_json_t **json_object)
This function destroys json_object data struct. But the object still exists in root json object...
E_MCL_ERROR_CODE mcl_json_util_add_item_to_array(mcl_json_t *root, mcl_json_t *object)
This function adds object to root array.
#define VERBOSE_ENTRY(...)
#define ASSERT_STATEMENT_CODE_MESSAGE(condition, statement, return_code,...)
void json_util_get_double_value(json_t *json, double *double_value)
This function gets the double value of a given json object.
E_MCL_JSON_TYPE
Json type definitions.
E_MCL_ERROR_CODE mcl_json_util_to_string(mcl_json_t *root, char **json_string)
This function gives the string of root in json format.
General invalid parameter fail.
void mcl_json_util_finish_array(mcl_json_t **json_array)
This function destroys json_array data struct. But the array still exists in root json object...
void json_util_get_array_size(json_t *array, mcl_size_t *size)
This function returns the size of array.
void json_util_finish_array(json_t **json_array)
This function destroys json_array data struct. But the array still exists in root json object...
E_MCL_ERROR_CODE json_util_get_object_item(json_t *json_parent, const char *child_name, json_t **json_child)
This function gives the value of json_child object, when the child_name in json_parent object is give...
void json_util_initialize_json_library()
This function initializes json library.
static E_JSON_TYPE _convert_mcl_json_type_to_json_type(E_MCL_JSON_TYPE mcl_json_type)
#define ASSERT_CODE_MESSAGE(condition, return_code,...)
Definitions module header file.
void memory_free(void *p)
free wrapper
Json utility module interface header file.
E_MCL_ERROR_CODE json_util_add_string(json_t *root, const char *object_name, const char *object_value)
This function adds string to root which can be object or array.
E_MCL_ERROR_CODE json_util_add_object(json_t *root, const char *object_name, json_t *object)
This function adds object to root.
E_MCL_ERROR_CODE mcl_json_util_add_uint(mcl_json_t *root, const char *object_name, const mcl_size_t number)
This function adds integer number to root which can be object or array.
E_MCL_ERROR_CODE json_util_add_null(json_t *root, const char *object_name)
This function adds null to root which can be object or array.
void json_util_finish_object(json_t **json_object)
This function destroys json_object data struct. But the object still exists in root json object...
E_MCL_ERROR_CODE json_util_parse_with_size(const char *json_string, mcl_size_t size, json_t **root)
This function parses the given string to the given json object.
E_MCL_ERROR_CODE mcl_json_util_parse(const char *json_string, mcl_json_t **root)
This function parses the given string to the given json object.
E_MCL_ERROR_CODE json_util_duplicate(const json_t *source_json, mcl_bool_t with_children, json_t **duplicated_json)
This function duplicates source_json as duplicated_json.
Json child which we try to get doesn't exist in the parent Json object.
E_MCL_ERROR_CODE mcl_json_util_add_null(mcl_json_t *root, const char *object_name)
This function adds null to root which can be object or array.
E_MCL_ERROR_CODE mcl_json_util_start_array(mcl_json_t *root, const char *array_name, mcl_json_t **json_array)
This function creates an array in root.
The same name can not be added in the same level of json object.
E_MCL_ERROR_CODE json_util_to_string(json_t *root, char **json_string)
This function gives the string of root in json format.
static cJSON_Hooks cjson_hooks
E_MCL_ERROR_CODE mcl_json_util_initialize(E_MCL_JSON_TYPE json_type, mcl_json_t **root)
This function initializes the given root json.
void json_util_get_bool_value(json_t *json, mcl_bool_t *bool_value)
This function gets the boolean value of a given json object.
E_MCL_ERROR_CODE mcl_json_util_get_bool_value(mcl_json_t *json, mcl_bool_t *bool_value)
This function gets the boolean value of a given json object.
void json_util_add_item_to_array(json_t *root, json_t *object)
This function adds object to root array.
E_MCL_ERROR_CODE mcl_json_util_add_float(mcl_json_t *root, const char *object_name, const float number)
This function adds floating number to root.
E_MCL_ERROR_CODE json_util_get_array_item(json_t *array, int index, json_t **item)
This function gets the item at given index from array.
E_MCL_ERROR_CODE mcl_json_util_add_double(mcl_json_t *root, const char *object_name, const double number)
This function adds double number to root which can be object or array.
void mcl_json_util_destroy(mcl_json_t **root)
This function destroys root.
E_MCL_ERROR_CODE json_util_start_object(json_t *root, const char *object_name, json_t **json_object)
This function creates an object in root.
E_MCL_ERROR_CODE json_util_initialize(E_JSON_TYPE json_type, json_t **root)
This function initializes the given root json.
static void _finish_json_item(json_t **json_item)
This struct is used for json handling.
E_MCL_ERROR_CODE mcl_json_util_add_bool(mcl_json_t *root, const char *object_name, const mcl_bool_t bool_value)
This function adds bool_value to root which can be object or array.
E_MCL_ERROR_CODE json_util_add_double(json_t *root, const char *object_name, const double number)
This function adds double number to root which can be object or array.