Module: kamailio
Branch: master
Commit: d7b76608595046001cab3ced06d29c1e9a84cb99
URL:
https://github.com/kamailio/kamailio/commit/d7b76608595046001cab3ced06d29c1…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-11-28T10:20:40+01:00
jansson: use key as field name for jansson_get_field()
- do no try to evaluate it as json path
---
Modified: src/modules/jansson/jansson_funcs.c
Modified: src/modules/jansson/jansson_funcs.h
Modified: src/modules/jansson/jansson_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/d7b76608595046001cab3ced06d29c1…
Patch:
https://github.com/kamailio/kamailio/commit/d7b76608595046001cab3ced06d29c1…
---
diff --git a/src/modules/jansson/jansson_funcs.c b/src/modules/jansson/jansson_funcs.c
index 8e154e7bff4..58a698446ca 100644
--- a/src/modules/jansson/jansson_funcs.c
+++ b/src/modules/jansson/jansson_funcs.c
@@ -34,7 +34,7 @@
#include "jansson_utils.h"
int janssonmod_get_helper(
- sip_msg_t *msg, str *path_s, str *src_s, pv_spec_t *dst_pv)
+ sip_msg_t *msg, str *path_s, int pmode, str *src_s, pv_spec_t *dst_pv)
{
char c;
pv_value_t dst_val;
@@ -52,7 +52,7 @@ int janssonmod_get_helper(
char *path = path_s->s;
- json_t *v = json_path_get(json, path, 0);
+ json_t *v = json_path_get(json, path, pmode);
if(!v) {
goto fail;
}
@@ -91,7 +91,26 @@ int janssonmod_get(struct sip_msg *msg, char *path_in, char *src_in,
char *dst)
return -1;
}
- return janssonmod_get_helper(msg, &path_s, &src_s, (pv_spec_t *)dst);
+ return janssonmod_get_helper(msg, &path_s, 0, &src_s, (pv_spec_t *)dst);
+}
+
+int janssonmod_get_field(
+ struct sip_msg *msg, char *path_in, char *src_in, char *dst)
+{
+ str src_s;
+ str path_s;
+
+ if(fixup_get_svalue(msg, (gparam_p)src_in, &src_s) != 0) {
+ ERR("cannot get json string value\n");
+ return -1;
+ }
+
+ if(fixup_get_svalue(msg, (gparam_p)path_in, &path_s) != 0) {
+ ERR("cannot get path string value\n");
+ return -1;
+ }
+
+ return janssonmod_get_helper(msg, &path_s, 1, &src_s, (pv_spec_t *)dst);
}
int janssonmod_pv_get(
@@ -111,7 +130,7 @@ int janssonmod_pv_get(
return -1;
}
- ret = janssonmod_get_helper(msg, &path_s, &val.rs, (pv_spec_t *)dst);
+ ret = janssonmod_get_helper(msg, &path_s, 0, &val.rs, (pv_spec_t *)dst);
pv_value_destroy(&val);
diff --git a/src/modules/jansson/jansson_funcs.h b/src/modules/jansson/jansson_funcs.h
index f59074a210b..ab1c029821f 100644
--- a/src/modules/jansson/jansson_funcs.h
+++ b/src/modules/jansson/jansson_funcs.h
@@ -27,6 +27,8 @@
int janssonmod_get(
struct sip_msg *msg, char *path_in, char *json_in, char *result);
+int janssonmod_get_field(
+ struct sip_msg *msg, char *path_in, char *src_in, char *dst);
int janssonmod_pv_get(
struct sip_msg *msg, char *path_in, char *json_in, char *result);
int janssonmod_set(unsigned int append, struct sip_msg *msg, char *type_in,
@@ -34,7 +36,7 @@ int janssonmod_set(unsigned int append, struct sip_msg *msg, char
*type_in,
int janssonmod_array_size(
struct sip_msg *msg, char *json_in, char *path_in, char *dst);
int janssonmod_get_helper(
- sip_msg_t *msg, str *path_s, str *src_s, pv_spec_t *dst_pv);
+ sip_msg_t *msg, str *path_s, int pmode, str *src_s, pv_spec_t *dst_pv);
int jansson_xdecode(struct sip_msg *msg, char *src_in, char *xavp_in);
int jansson_xencode(struct sip_msg *msg, char *xavp, char *dst);
diff --git a/src/modules/jansson/jansson_mod.c b/src/modules/jansson/jansson_mod.c
index 816cb130fa9..e7dd58ee3fc 100644
--- a/src/modules/jansson/jansson_mod.c
+++ b/src/modules/jansson/jansson_mod.c
@@ -55,11 +55,6 @@ int janssonmod_set_append(struct sip_msg *msg, char *type_in, char
*path_in,
{
return janssonmod_set(1, msg, type_in, path_in, value_in, result);
}
-int janssonmod_get_field(
- struct sip_msg *msg, char *jansson_in, char *path_in, char *result)
-{
- return janssonmod_get(msg, path_in, jansson_in, result);
-}
/* clang-format off */
/* Exported functions */
@@ -246,7 +241,7 @@ static int ki_jansson_get(sip_msg_t *msg, str *spath, str *sdoc, str
*spv)
return -1;
}
- return janssonmod_get_helper(msg, spath, sdoc, pvs);
+ return janssonmod_get_helper(msg, spath, 0, sdoc, pvs);
}
/**