diff --git a/src/curl_json.c b/src/curl_json.c
index 9e0f6723c35c363198a3f1df165a6c5e8dcdb444..2314bfe9bd2c98a464b836dd21b175b3feee2460 100644 (file)
--- a/src/curl_json.c
+++ b/src/curl_json.c
return (len);
#endif
- if (status != yajl_status_ok)
- {
- unsigned char *msg =
- yajl_get_error(db->yajl, /* verbose = */ 1,
- /* jsonText = */ (unsigned char *) buf, (unsigned int) len);
- ERROR ("curl_json plugin: yajl_parse failed: %s", msg);
- yajl_free_error(db->yajl, msg);
- return (0); /* abort write callback */
- }
-
- return (len);
+ unsigned char *msg = yajl_get_error(db->yajl, /* verbose = */ 1,
+ /* jsonText = */ (unsigned char *) buf, (unsigned int) len);
+ ERROR ("curl_json plugin: yajl_parse failed: %s", msg);
+ yajl_free_error(db->yajl, msg);
+ return (0); /* abort write callback */
} /* }}} size_t cj_curl_callback */
static int cj_get_type (cj_key_t *key)
if (key != NULL)
NOTICE ("curl_json plugin: Found \"%s\", but the configuration expects"
" a map.", buffer);
- cj_cb_inc_array_index (ctx, /* update_key = */ 0);
- return (CJ_CB_CONTINUE);
- } else {
+ cj_cb_inc_array_index (ctx, /* update_key = */ 1);
+ key = db->state[db->depth].key;
+ if (key == NULL) {
+ return (CJ_CB_CONTINUE);
+ }
+ }
+ else
+ {
cj_cb_inc_array_index (ctx, /* update_key = */ 1);
}
memcpy (name, in_name, name_len);
name[name_len] = 0;
- if (c_avl_get (tree, name, (void *) &value) == 0)
- db->state[db->depth].key = value;
+ if (c_avl_get (tree, name, (void *) &value) == 0) {
+ if (CJ_IS_KEY((cj_key_t*)value)) {
+ db->state[db->depth].key = value;
+ }
+ else {
+ db->state[db->depth].tree = (c_avl_tree_t*) value;
+ }
+ }
else if (c_avl_get (tree, CJ_ANY, (void *) &value) == 0)
- db->state[db->depth].key = value;
+ if (CJ_IS_KEY((cj_key_t*)value)) {
+ db->state[db->depth].key = value;
+ }
+ else {
+ db->state[db->depth].tree = (c_avl_tree_t*) value;
+ }
else
db->state[db->depth].key = NULL;
}
static int cj_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */
oconfig_item_t *ci)
{
+ struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
WARNING ("curl_json plugin: `%s' needs exactly one string argument.", name);
return (-1);
}
- *dest = curl_slist_append(*dest, ci->values[0].value.string);
- if (*dest == NULL)
+ temp = curl_slist_append(*dest, ci->values[0].value.string);
+ if (temp == NULL)
return (-1);
+ *dest = temp;
+
return (0);
} /* }}} int cj_config_append_string */
{
ERROR ("curl_json plugin: cj_config: "
"Invalid key: %s", ci->key);
+ cj_key_free (key);
return (-1);
}
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;
- name = key->path;
- 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 */
{
ERROR ("curl_json plugin: cj_config: "
"Invalid key: %s", ci->key);
+ cj_free (db);
return (-1);
}
if (status != 0)