summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: af65708)
raw | patch | inline | side by side (parent: af65708)
author | Florian Forster <octo@collectd.org> | |
Wed, 9 Dec 2015 08:44:24 +0000 (09:44 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 9 Dec 2015 08:44:24 +0000 (09:44 +0100) |
CID: 37991
src/curl_json.c | patch | blob | history |
diff --git a/src/curl_json.c b/src/curl_json.c
index 6fdae51d2bf74b29ed4028ee2e77e5c66ca33954..5875feaef1c334b40aa56e2827c021713a0e5ac9 100644 (file)
--- a/src/curl_json.c
+++ b/src/curl_json.c
break;
} /* for (i = 0; i < ci->children_num; i++) */
- while (status == 0)
+ if (status != 0)
{
- if (key->type == NULL)
- {
- WARNING ("curl_json plugin: `Type' missing in `Key' block.");
- status = -1;
- }
+ cj_key_free (key);
+ return (-1);
+ }
- break;
- } /* while (status == 0) */
+ if (key->type == NULL)
+ {
+ WARNING ("curl_json plugin: `Type' missing in `Key' block.");
+ cj_key_free (key);
+ return (-1);
+ }
/* store path in a tree that will match the json map structure, example:
* "httpd/requests/count",
* "httpd/requests/current" ->
* { "httpd": { "requests": { "count": $key, "current": $key } } }
*/
- if (status == 0)
+ char *ptr;
+ char *name;
+ c_avl_tree_t *tree;
+
+ if (db->tree == NULL)
+ db->tree = cj_avl_create();
+
+ tree = db->tree;
+ ptr = key->path;
+ if (*ptr == '/')
+ ++ptr;
+
+ name = ptr;
+ while ((ptr = strchr (name, '/')) != NULL)
{
- char *ptr;
- char *name;
char ent[PATH_MAX];
- c_avl_tree_t *tree;
+ c_avl_tree_t *value;
+ size_t len;
- if (db->tree == NULL)
- db->tree = cj_avl_create();
+ len = ptr - name;
+ if (len == 0)
+ break;
- tree = db->tree;
- ptr = key->path;
- if (*ptr == '/')
- ++ptr;
+ len = COUCH_MIN(len, sizeof (ent)-1);
+ sstrncpy (ent, name, len+1);
- name = ptr;
- while (*ptr)
+ if (c_avl_get (tree, ent, (void *) &value) != 0)
{
- if (*ptr == '/')
- {
- c_avl_tree_t *value;
- int len;
-
- len = ptr-name;
- if (len == 0)
- break;
- len = COUCH_MIN(len, sizeof (ent)-1);
- sstrncpy (ent, name, len+1);
-
- if (c_avl_get (tree, ent, (void *) &value) != 0)
- {
- value = cj_avl_create ();
- c_avl_insert (tree, strdup (ent), value);
- }
-
- tree = value;
- name = ptr+1;
- }
- ++ptr;
- }
- if (*name)
- c_avl_insert (tree, strdup(name), key);
- else
- {
- ERROR ("curl_json plugin: invalid key: %s", key->path);
- status = -1;
+ value = cj_avl_create ();
+ c_avl_insert (tree, strdup (ent), value);
}
+
+ tree = value;
+ name = ptr + 1;
+ }
+
+ if (strlen (name) == 0)
+ {
+ ERROR ("curl_json plugin: invalid key: %s", key->path);
+ cj_key_free (key);
+ return (-1);
}
+ c_avl_insert (tree, strdup (name), key);
return (status);
} /* }}} int cj_config_add_key */