diff --git a/modules/json/array_del.c b/modules/json/array_del.c index 77f370402cb..cb93507be0c 100644 --- a/modules/json/array_del.c +++ b/modules/json/array_del.c @@ -23,33 +23,26 @@ * --------- * 2009-09-04 first version (andreidragus) * 2017-12-12 use opensips_json_c_helper.h (besser82) + * 2017-12-12 improve readability (besser82) */ #include "opensips_json_c_helper.h" -#if JSON_C_VERSION_NUM < JSON_C_VERSION_013 -void array_list_del_idx(struct array_list * arr, int idx) +void json_object_array_del(struct json_object* obj, int idx) { - int i; - - if(idx >= arr->length) +#if JSON_C_VERSION_NUM >= JSON_C_VERSION_013 + array_list_del_idx(json_object_get_array(obj), idx, + json_object_get_array(obj)->length); +#else + if(idx >= obj->o.c_array->length) return; + int i = 0; - arr->free_fn(arr->array[idx]); - arr->length--; + obj->o.c_array->free_fn(obj->o.c_array->array[idx]); + obj->o.c_array->length--; - for(i=idx; ilength; i++) - arr->array[i] = arr->array[i+1]; -}; -#endif - -void json_object_array_del(struct json_object* obj, int idx) -{ -#if JSON_C_VERSION_NUM >= JSON_C_VERSION_013 - struct array_list * arr = json_object_get_array(obj); - array_list_del_idx(arr, idx, arr->length); -#else - array_list_del_idx(obj->o.c_array, idx); + for(i = idx; i < obj->o.c_array->length; i++) + obj->o.c_array->array[i] = obj->o.c_array->array[i+1]; #endif }; diff --git a/modules/json/json.c b/modules/json/json.c index a5c1942914f..3fe6c79f03f 100644 --- a/modules/json/json.c +++ b/modules/json/json.c @@ -94,7 +94,6 @@ char buff[JSON_FILE_BUF_SIZE]; static int mod_init(void); static int child_init(int ); static void mod_destroy(void); -void json_object_array_del(struct json_object* , int ); static int fixup_json_bind(void**, int ); static int pv_set_json (struct sip_msg*, pv_param_t*, int , pv_value_t* ); static int pv_get_json (struct sip_msg*, pv_param_t*, pv_value_t* ); diff --git a/modules/json/opensips_json_c_helper.h b/modules/json/opensips_json_c_helper.h index c4584e38362..be566bd1c2b 100644 --- a/modules/json/opensips_json_c_helper.h +++ b/modules/json/opensips_json_c_helper.h @@ -73,4 +73,7 @@ #define JSON_FILE_BUF_SIZE 4096 #endif +/* Declaration of helper functions. */ +void json_object_array_del(struct json_object* obj, int idx); + #endif /* OPENSIPS_JSON_C_HELPER_H */