소스 검색

jansson: added path evaluatian mode for helper functions

Daniel-Constantin Mierla 1 년 전
부모
커밋
48034ab614
3개의 변경된 파일19개의 추가작업 그리고 12개의 파일을 삭제
  1. 3 3
      src/modules/jansson/jansson_funcs.c
  2. 13 6
      src/modules/jansson/jansson_path.c
  3. 3 3
      src/modules/jansson/jansson_path.h

+ 3 - 3
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;

+ 13 - 6
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 @@ fail:
 	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",

+ 3 - 3
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