Skip to content

Commit

Permalink
modules/json: Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
besser82 committed Dec 13, 2017
1 parent 1906423 commit 5220f6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
31 changes: 12 additions & 19 deletions modules/json/array_del.c
Expand Up @@ -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; i<arr->length; 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
};
1 change: 0 additions & 1 deletion modules/json/json.c
Expand Up @@ -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* );
Expand Down
3 changes: 3 additions & 0 deletions modules/json/opensips_json_c_helper.h
Expand Up @@ -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 */

0 comments on commit 5220f6a

Please sign in to comment.