Module: kamailio
Branch: master
Commit: 48034ab61482f6b3d9e77ccfc9e0743c44ff4458
URL:
https://github.com/kamailio/kamailio/commit/48034ab61482f6b3d9e77ccfc9e0743…
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: added path evaluatian mode for helper functions
---
Modified: src/modules/jansson/jansson_funcs.c
Modified: src/modules/jansson/jansson_path.c
Modified: src/modules/jansson/jansson_path.h
---
Diff:
https://github.com/kamailio/kamailio/commit/48034ab61482f6b3d9e77ccfc9e0743…
Patch:
https://github.com/kamailio/kamailio/commit/48034ab61482f6b3d9e77ccfc9e0743…
---
diff --git a/src/modules/jansson/jansson_funcs.c b/src/modules/jansson/jansson_funcs.c
index 926ed34c266..8e154e7bff4 100644
--- a/src/modules/jansson/jansson_funcs.c
+++ b/src/modules/jansson/jansson_funcs.c
@@ -52,7 +52,7 @@ int janssonmod_get_helper(
char *path = path_s->s;
- json_t *v = json_path_get(json, path);
+ json_t *v = json_path_get(json, path, 0);
if(!v) {
goto fail;
}
@@ -252,7 +252,7 @@ int janssonmod_set(unsigned int append, struct sip_msg *msg, char
*type_in,
goto fail;
}
- if(json_path_set(result_json, path, value, append) < 0) {
+ if(json_path_set(result_json, path, 0, value, append) < 0) {
goto fail;
}
@@ -307,7 +307,7 @@ int janssonmod_array_size(
char *path = path_s.s;
- json_t *v = json_path_get(json, path);
+ json_t *v = json_path_get(json, path, 0);
if(!v) {
ERR("failed to find %s in json\n", path);
goto fail;
diff --git a/src/modules/jansson/jansson_path.c b/src/modules/jansson/jansson_path.c
index cc38c380260..d4148591aac 100644
--- a/src/modules/jansson/jansson_path.c
+++ b/src/modules/jansson/jansson_path.c
@@ -25,7 +25,7 @@ static char *jsonp_strdup(const char *str);
static json_malloc_t do_malloc = malloc;
static json_free_t do_free = free;
-json_t *json_path_get(const json_t *json, const char *path)
+json_t *json_path_get(const json_t *json, const char *path, const int pmode)
{
static const char array_open = '[';
static const char *path_delims = ".[", *array_close = "]";
@@ -50,7 +50,11 @@ json_t *json_path_get(const json_t *json, const char *path)
while(peek && *peek && cursor) {
char *last_peek = peek;
- peek = strpbrk(peek, expect);
+ if(pmode == 0) {
+ peek = strpbrk(peek, expect);
+ } else {
+ peek = NULL;
+ }
if(peek) {
if(!token && peek != last_peek)
goto fail;
@@ -85,8 +89,8 @@ json_t *json_path_get(const json_t *json, const char *path)
return NULL;
}
-int json_path_set(
- json_t *json, const char *path, json_t *value, unsigned int append)
+int json_path_set(json_t *json, const char *path, const int pmode,
+ json_t *value, unsigned int append)
{
static const char array_open = '[';
static const char object_delim = '.';
@@ -117,8 +121,11 @@ int json_path_set(
while(peek && *peek && cursor) {
char *last_peek = peek;
- peek = strpbrk(last_peek, expect);
-
+ if(pmode == 0) {
+ peek = strpbrk(last_peek, expect);
+ } else {
+ peek = NULL;
+ }
if(peek) {
if(!token && peek != last_peek) {
ERR("unexpected trailing chars in JSON path at pos %zu\n",
diff --git a/src/modules/jansson/jansson_path.h b/src/modules/jansson/jansson_path.h
index 79e1614c6fd..22fc562fee7 100644
--- a/src/modules/jansson/jansson_path.h
+++ b/src/modules/jansson/jansson_path.h
@@ -10,8 +10,8 @@
#define _JANSSON_PATH_H_
#include <jansson.h>
-json_t *json_path_get(const json_t *json, const char *path);
-int json_path_set(
- json_t *json, const char *path, json_t *value, unsigned int append);
+json_t *json_path_get(const json_t *json, const char *path, const int pmode);
+int json_path_set(json_t *json, const char *path, const int pmode,
+ json_t *value, unsigned int append);
#endif