Skip to content

Commit

Permalink
Added detection for the version of libjson used in the system
Browse files Browse the repository at this point in the history
Also, fixed printing of entire json objects
(cherry picked from commit 6f9c8c3)

Conflicts:
	modules/json/json.c
  • Loading branch information
vladpaiu committed Jul 1, 2014
1 parent 7b4c52f commit e937b35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion modules/json/Makefile
Expand Up @@ -23,7 +23,8 @@ ifeq ($(JSON_BUILDER),)
DEFS += -I$(LOCALBASE)/include -I$(SYSBASE)/include
LIBS += -L$(LOCALBASE)/lib -ljson
else
DEFS += $(shell $(JSON_BUILDER) --cflags)
JSON_LIB_VER = $(shell $(JSON_BUILDER) --modversion | sed "s/\.\([0-9]\)\./.0\1./g" | sed "s/\.\([0-9]\)\$$/.0\1/g" | tr -d "." | sed -e "s/^0*//" )
DEFS += $(shell $(JSON_BUILDER) --cflags) -DJSON_LIB_VERSION=$(JSON_LIB_VER)
LIBS += $(shell $(JSON_BUILDER) --libs)
endif

Expand Down
32 changes: 24 additions & 8 deletions modules/json/json.c
Expand Up @@ -225,7 +225,7 @@ int fixup_json_bind(void** param, int param_no)



struct json_object* json_parse(const char *str,int len)
struct json_object* json_parse(const char *str,int len,enum json_tokener_error *status)
{
struct json_tokener* tok;
struct json_object* obj;
Expand All @@ -235,9 +235,11 @@ struct json_object* json_parse(const char *str,int len)

if( tok-> err == json_tokener_continue )
obj = json_tokener_parse_ex(tok, "", -1);

if(tok->err != json_tokener_success)
obj = (struct json_object*)error_ptr((long)(-tok->err));
if(tok->err != json_tokener_success) {
obj = NULL;
if (status)
*status = tok->err;
}

json_tokener_free(tok);
return obj;
Expand Down Expand Up @@ -406,11 +408,19 @@ int pv_get_json (struct sip_msg* msg, pv_param_t* pvp, pv_value_t* val)
val->flags |= PV_VAL_INT|PV_TYPE_INT;

}
else
else if( json_object_is_type(obj, json_type_string))
{
val->flags = PV_VAL_STR;
val->rs.s = (char*)json_object_get_string( obj );
#if JSON_LIB_VERSION >= 10
val->rs.len = json_object_get_string_len( obj );
#else
val->rs.len = strlen(val->rs.s);
#endif
} else {
val->flags = PV_VAL_STR;
val->rs.s = (char*)json_object_to_json_string( obj );
val->rs.len = strlen(val->rs.s);
}

return 0;
Expand Down Expand Up @@ -543,6 +553,7 @@ int pv_set_json (struct sip_msg* msg, pv_param_t* pvp, int flag ,
{

json_t * obj;
enum json_tokener_error parse_status;


if( expand_tag_list( msg, ((json_name *)pvp->pvn.u.dname)->tags ) < 0)
Expand All @@ -568,12 +579,17 @@ int pv_set_json (struct sip_msg* msg, pv_param_t* pvp, int flag ,
return -1;
}

obj = json_parse( val->rs.s, val->rs.len);
obj = json_parse( val->rs.s, val->rs.len,&parse_status);

if (is_error(obj))
if (obj == NULL)
{
LM_ERR("Error parsing json: %s\n",
json_tokener_errors[-(unsigned long)obj]);
#if JSON_LIB_VERSION >= 10
json_tokener_error_desc(parse_status)
#else
json_tokener_errors[(unsigned long)obj]
#endif
);
return -1;

}
Expand Down

0 comments on commit e937b35

Please sign in to comment.