diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-02-07 11:49:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-02-07 12:42:05 +0000 |
commit | 2e85f9325a797977eea9dfea0a925775ddd211d9 (patch) | |
tree | 452c7f30d62fca5755f659b99e4e53c7b03afc21 /libnetdata/json/json.c | |
parent | Releasing debian version 1.19.0-4. (diff) | |
download | netdata-2e85f9325a797977eea9dfea0a925775ddd211d9.tar.xz netdata-2e85f9325a797977eea9dfea0a925775ddd211d9.zip |
Merging upstream version 1.29.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/json/json.c')
-rw-r--r-- | libnetdata/json/json.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/libnetdata/json/json.c b/libnetdata/json/json.c index 3ccc561c..bd164aef 100644 --- a/libnetdata/json/json.c +++ b/libnetdata/json/json.c @@ -137,10 +137,12 @@ int json_callback_print(JSON_ENTRY *e) * @param e the output structure */ static inline void json_jsonc_set_string(JSON_ENTRY *e,char *key,const char *value) { - size_t length = strlen(key); + size_t len = strlen(key); + if(len > JSON_NAME_LEN) + len = JSON_NAME_LEN; e->type = JSON_STRING; - memcpy(e->name,key,length); - e->name[length] = 0x00; + memcpy(e->name,key,len); + e->name[len] = 0x00; e->data.string = (char *) value; } @@ -159,6 +161,16 @@ static inline void json_jsonc_set_boolean(JSON_ENTRY *e,int value) { e->data.boolean = value; } +static inline void json_jsonc_set_integer(JSON_ENTRY *e, char *key, int64_t value) { + size_t len = strlen(key); + if(len > JSON_NAME_LEN) + len = JSON_NAME_LEN; + e->type = JSON_NUMBER; + memcpy(e->name, key, len); + e->name[len] = 0; + e->data.number = value; +} + /** * Parse Array * @@ -299,7 +311,7 @@ size_t json_walk_array(char *js, jsmntok_t *t, size_t nest, size_t start, JSON_E memcpy(&ne, e, sizeof(JSON_ENTRY)); ne.type = JSON_ARRAY; ne.data.items = t[start].size; - ne.callback_function = NULL; + ne.callback_function = e->callback_function; ne.name[0]='\0'; ne.fullname[0]='\0'; if(e->callback_function) e->callback_function(&ne); @@ -365,7 +377,7 @@ size_t json_walk_object(char *js, jsmntok_t *t, size_t nest, size_t start, JSON_ ne.original_string = &js[t[start].start]; memcpy(&ne, e, sizeof(JSON_ENTRY)); ne.type = JSON_OBJECT; - ne.callback_function = NULL; + ne.callback_function = e->callback_function; if(e->callback_function) e->callback_function(&ne); js[t[start].end] = old; @@ -447,6 +459,9 @@ size_t json_walk(json_object *t, void *callback_data, int (*callback_function)(s } else if (type == json_type_boolean) { json_jsonc_set_boolean(&e,json_object_get_boolean(val)); callback_function(&e); + } else if (type == json_type_int) { + json_jsonc_set_integer(&e,key,json_object_get_int64(val)); + callback_function(&e); } } |