Module: kamailio
Branch: master
Commit: 8b9fd4fa40abfc40ecd537948036aa91b908615d
URL:
https://github.com/kamailio/kamailio/commit/8b9fd4fa40abfc40ecd537948036aa9…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2016-04-25T08:54:45+02:00
json: replaced use of obsolete function json_object_object_get()
- reported by Olle E. Johansson, GH #579
---
Modified: modules/json/json_funcs.c
---
Diff:
https://github.com/kamailio/kamailio/commit/8b9fd4fa40abfc40ecd537948036aa9…
Patch:
https://github.com/kamailio/kamailio/commit/8b9fd4fa40abfc40ecd537948036aa9…
---
diff --git a/modules/json/json_funcs.c b/modules/json/json_funcs.c
index 106eef1..4d73c73 100644
--- a/modules/json/json_funcs.c
+++ b/modules/json/json_funcs.c
@@ -39,6 +39,8 @@ int json_get_field(struct sip_msg* msg, char* json, char* field, char*
dst)
pv_value_t dst_val;
char *value;
struct json_object *j = NULL;
+ struct json_object *oj = NULL;
+ int ret;
if (fixup_get_svalue(msg, (gparam_p)json, &json_s) != 0) {
LM_ERR("cannot get json string value\n");
@@ -61,13 +63,18 @@ int json_get_field(struct sip_msg* msg, char* json, char* field, char*
dst)
return -1;
}
- value = (char*)json_object_to_json_string(json_object_object_get(j, field_s.s));
-
- dst_val.rs.s = value;
- dst_val.rs.len = strlen(value);
- dst_val.flags = PV_VAL_STR;
- dst_pv->setf(msg, &dst_pv->pvp, (int)EQ_T, &dst_val);
+ json_object_object_get_ex(j, field_s.s, &oj);
+ if(oj!=NULL) {
+ value = (char*)json_object_to_json_string(oj);
+ dst_val.rs.s = value;
+ dst_val.rs.len = strlen(value);
+ dst_val.flags = PV_VAL_STR;
+ dst_pv->setf(msg, &dst_pv->pvp, (int)EQ_T, &dst_val);
+ ret = 1;
+ } else {
+ ret = -1;
+ }
if(j!=NULL) json_object_put(j);
- return 1;
+ return ret;
}