Browse code

json: add get_object API and fix str init

Emmanuel Schmidbauer authored on 29/01/2018 14:32:11
Showing 2 changed files
... ...
@@ -25,11 +25,12 @@
25 25
 #include "../../core/sr_module.h"
26 26
 
27 27
 typedef struct json_object *(*json_parse_f) (const char *str);
28
-typedef str (*json_extract_field_f)(
29
-		struct json_object *json_obj, char *json_name);
28
+typedef struct json_object *(*json_get_object_f) (struct json_object *json_obj, const char *str);
29
+typedef str (*json_extract_field_f) (struct json_object *json_obj, char *json_name);
30 30
 
31 31
 typedef struct json_api {
32 32
 	json_parse_f json_parse;
33
+	json_get_object_f get_object;
33 34
 	json_extract_field_f extract_field;
34 35
 } json_api_t;
35 36
 
... ...
@@ -65,9 +65,8 @@ struct module_exports exports = {
65 65
 		0						 /* per-child init function */
66 66
 };
67 67
 
68
-str _json_extract_field(struct json_object *json_obj, char *json_name)
69
-{
70
-	str val;
68
+str _json_extract_field(struct json_object *json_obj, char *json_name) {
69
+	str val = {0, 0};
71 70
 	json_extract_field(json_name, val);
72 71
 	return val;
73 72
 }
... ...
@@ -81,6 +80,7 @@ int bind_json(json_api_t *api) {
81 80
 		return -1;
82 81
 	}
83 82
 	api->json_parse = json_parse;
83
+	api->get_object = json_get_object;
84 84
 	api->extract_field = _json_extract_field;
85 85
 	return 0;
86 86
 }