2 * collectd - src/curl_json.c
3 * Copyright (C) 2009 Doug MacEachern
4 * Copyright (C) 2006-2013 Florian octo Forster
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; only version 2 of the License is applicable.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Doug MacEachern <dougm at hyperic.com>
21 * Florian octo Forster <octo at collectd.org>
28 #include "utils_avltree.h"
29 #include "utils_complain.h"
30 #include "utils_curl_stats.h"
32 #include <sys/types.h>
35 #include <curl/curl.h>
37 #include <yajl/yajl_parse.h>
38 #if HAVE_YAJL_YAJL_VERSION_H
39 #include <yajl/yajl_version.h>
42 #if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
43 #define HAVE_YAJL_V2 1
46 #define CJ_DEFAULT_HOST "localhost"
47 #define CJ_KEY_MAGIC 0x43484b59UL /* CHKY */
48 #define CJ_IS_KEY(key) ((key)->magic == CJ_KEY_MAGIC)
50 #define COUCH_MIN(x, y) ((x) < (y) ? (x) : (y))
53 typedef struct cj_key_s cj_key_t;
54 struct cj_key_s /* {{{ */
78 struct curl_slist *headers;
85 char curl_errbuf[CURL_ERROR_SIZE];
97 char name[DATA_MAX_NAME_LEN];
98 } state[YAJL_MAX_DEPTH];
100 typedef struct cj_s cj_t; /* }}} */
103 typedef size_t yajl_len_t;
105 typedef unsigned int yajl_len_t;
108 static int cj_read(user_data_t *ud);
109 static void cj_submit_impl(cj_t *db, cj_key_t *key, value_t *value);
111 /* cj_submit is a function pointer to cj_submit_impl, allowing the unit-test to
112 * overwrite which function is called. */
113 static void (*cj_submit)(cj_t *, cj_key_t *, value_t *) = cj_submit_impl;
115 static size_t cj_curl_callback(void *buf, /* {{{ */
116 size_t size, size_t nmemb, void *user_data) {
130 status = yajl_parse(db->yajl, (unsigned char *)buf, len);
131 if (status == yajl_status_ok)
134 else if (status == yajl_status_insufficient_data)
139 yajl_get_error(db->yajl, /* verbose = */ 1,
140 /* jsonText = */ (unsigned char *)buf, (unsigned int)len);
141 ERROR("curl_json plugin: yajl_parse failed: %s", msg);
142 yajl_free_error(db->yajl, msg);
143 return (0); /* abort write callback */
144 } /* }}} size_t cj_curl_callback */
146 static int cj_get_type(cj_key_t *key) {
147 const data_set_t *ds;
149 if ((key == NULL) || !CJ_IS_KEY(key))
152 ds = plugin_get_ds(key->type);
154 static char type[DATA_MAX_NAME_LEN] = "!!!invalid!!!";
156 assert(key->type != NULL);
157 if (strcmp(type, key->type) != 0) {
158 ERROR("curl_json plugin: Unable to look up DS type \"%s\".", key->type);
159 sstrncpy(type, key->type, sizeof(type));
163 } else if (ds->ds_num > 1) {
164 static c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
167 LOG_WARNING, &complaint,
168 "curl_json plugin: The type \"%s\" has more than one data source. "
169 "This is currently not supported. I will return the type of the "
170 "first data source, but this will likely lead to problems later on.",
174 return ds->ds[0].type;
177 /* cj_load_key loads the configuration for "key" from the parent context and
178 * sets either .key or .tree in the current context. */
179 static int cj_load_key(cj_t *db, char const *key) {
180 if (db == NULL || key == NULL || db->depth <= 0)
183 sstrncpy(db->state[db->depth].name, key, sizeof(db->state[db->depth].name));
185 c_avl_tree_t *tree = db->state[db->depth - 1].tree;
190 /* the parent has a key, so the tree pointer is invalid. */
191 if (CJ_IS_KEY(db->state[db->depth - 1].key)) {
196 if (c_avl_get(tree, key, (void *)&value) == 0) {
197 if (CJ_IS_KEY((cj_key_t *)value)) {
198 db->state[db->depth].key = value;
200 db->state[db->depth].tree = value;
202 } else if (c_avl_get(tree, CJ_ANY, (void *)&value) == 0) {
203 if (CJ_IS_KEY((cj_key_t *)value)) {
204 db->state[db->depth].key = value;
206 db->state[db->depth].tree = value;
209 db->state[db->depth].key = NULL;
215 static void cj_advance_array(cj_t *db) {
216 if (!db->state[db->depth].in_array)
219 db->state[db->depth].index++;
221 char name[DATA_MAX_NAME_LEN];
222 ssnprintf(name, sizeof(name), "%d", db->state[db->depth].index);
223 cj_load_key(db, name);
227 #define CJ_CB_ABORT 0
228 #define CJ_CB_CONTINUE 1
230 static int cj_cb_boolean(void *ctx, int boolVal) {
231 cj_advance_array(ctx);
232 return (CJ_CB_CONTINUE);
235 static int cj_cb_null(void *ctx) {
236 cj_advance_array(ctx);
237 return (CJ_CB_CONTINUE);
240 static int cj_cb_number(void *ctx, const char *number, yajl_len_t number_len) {
241 char buffer[number_len + 1];
243 cj_t *db = (cj_t *)ctx;
244 cj_key_t *key = db->state[db->depth].key;
246 /* Create a null-terminated version of the string. */
247 memcpy(buffer, number, number_len);
248 buffer[sizeof(buffer) - 1] = 0;
253 /* no config for this element. */
254 cj_advance_array(ctx);
255 return CJ_CB_CONTINUE;
256 } else if (!CJ_IS_KEY(key)) {
257 /* the config expects a map or an array. */
259 "curl_json plugin: Found \"%s\", but the configuration expects a map.",
261 cj_advance_array(ctx);
262 return CJ_CB_CONTINUE;
265 int type = cj_get_type(key);
267 int status = parse_value(buffer, &vt, type);
269 NOTICE("curl_json plugin: Unable to parse number: \"%s\"", buffer);
270 cj_advance_array(ctx);
271 return (CJ_CB_CONTINUE);
274 cj_submit(db, key, &vt);
275 cj_advance_array(ctx);
276 return (CJ_CB_CONTINUE);
277 } /* int cj_cb_number */
279 /* Queries the key-tree of the parent context for "in_name" and, if found,
280 * updates the "key" field of the current context. Otherwise, "key" is set to
282 static int cj_cb_map_key(void *ctx, unsigned char const *in_name,
283 yajl_len_t in_name_len) {
284 char name[in_name_len + 1];
286 memmove(name, in_name, in_name_len);
287 name[sizeof(name) - 1] = 0;
289 if (cj_load_key(ctx, name) != 0)
292 return CJ_CB_CONTINUE;
295 static int cj_cb_string(void *ctx, const unsigned char *val, yajl_len_t len) {
296 /* Handle the string as if it was a number. */
297 return (cj_cb_number(ctx, (const char *)val, len));
298 } /* int cj_cb_string */
300 static int cj_cb_end(void *ctx) {
301 cj_t *db = (cj_t *)ctx;
302 db->state[db->depth].tree = NULL;
304 cj_advance_array(ctx);
305 return (CJ_CB_CONTINUE);
308 static int cj_cb_start_map(void *ctx) {
309 cj_t *db = (cj_t *)ctx;
311 if ((db->depth + 1) >= YAJL_MAX_DEPTH) {
312 ERROR("curl_json plugin: %s depth exceeds max, aborting.",
313 db->url ? db->url : db->sock);
314 return (CJ_CB_ABORT);
317 return (CJ_CB_CONTINUE);
320 static int cj_cb_end_map(void *ctx) { return cj_cb_end(ctx); }
322 static int cj_cb_start_array(void *ctx) {
323 cj_t *db = (cj_t *)ctx;
325 if ((db->depth + 1) >= YAJL_MAX_DEPTH) {
326 ERROR("curl_json plugin: %s depth exceeds max, aborting.",
327 db->url ? db->url : db->sock);
331 db->state[db->depth].in_array = 1;
332 db->state[db->depth].index = 0;
334 cj_load_key(db, "0");
336 return CJ_CB_CONTINUE;
339 static int cj_cb_end_array(void *ctx) {
340 cj_t *db = (cj_t *)ctx;
341 db->state[db->depth].in_array = 0;
342 return cj_cb_end(ctx);
345 static yajl_callbacks ycallbacks = {
346 cj_cb_null, /* null */
347 cj_cb_boolean, /* boolean */
350 cj_cb_number, cj_cb_string, cj_cb_start_map, cj_cb_map_key,
351 cj_cb_end_map, cj_cb_start_array, cj_cb_end_array};
353 /* end yajl callbacks */
355 static void cj_key_free(cj_key_t *key) /* {{{ */
362 sfree(key->instance);
365 } /* }}} void cj_key_free */
367 static void cj_tree_free(c_avl_tree_t *tree) /* {{{ */
372 while (c_avl_pick(tree, (void *)&name, (void *)&value) == 0) {
373 cj_key_t *key = (cj_key_t *)value;
378 cj_tree_free((c_avl_tree_t *)value);
384 } /* }}} void cj_tree_free */
386 static void cj_free(void *arg) /* {{{ */
390 DEBUG("curl_json plugin: cj_free (arg = %p);", arg);
397 if (db->curl != NULL)
398 curl_easy_cleanup(db->curl);
401 if (db->tree != NULL)
402 cj_tree_free(db->tree);
413 sfree(db->credentials);
415 sfree(db->post_body);
416 curl_slist_free_all(db->headers);
417 curl_stats_destroy(db->stats);
420 } /* }}} void cj_free */
422 /* Configuration handling functions {{{ */
424 static c_avl_tree_t *cj_avl_create(void) {
425 return c_avl_create((int (*)(const void *, const void *))strcmp);
428 static int cj_config_append_string(const char *name,
429 struct curl_slist **dest, /* {{{ */
430 oconfig_item_t *ci) {
431 struct curl_slist *temp = NULL;
432 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
433 WARNING("curl_json plugin: `%s' needs exactly one string argument.", name);
437 temp = curl_slist_append(*dest, ci->values[0].value.string);
444 } /* }}} int cj_config_append_string */
446 /* cj_append_key adds key to the configuration stored in db.
449 * "httpd/requests/count",
450 * "httpd/requests/current" ->
451 * { "httpd": { "requests": { "count": $key, "current": $key } } }
453 static int cj_append_key(cj_t *db, cj_key_t *key) { /* {{{ */
454 if (db->tree == NULL)
455 db->tree = cj_avl_create();
457 c_avl_tree_t *tree = db->tree;
459 char const *start = key->path;
464 while ((end = strchr(start, '/')) != NULL) {
467 size_t len = end - start;
471 len = COUCH_MIN(len, sizeof(name) - 1);
472 sstrncpy(name, start, len + 1);
475 if (c_avl_get(tree, name, (void *)&value) != 0) {
476 value = cj_avl_create();
477 c_avl_insert(tree, strdup(name), value);
484 if (strlen(start) == 0) {
485 ERROR("curl_json plugin: invalid key: %s", key->path);
489 c_avl_insert(tree, strdup(start), key);
491 } /* }}} int cj_append_key */
493 static int cj_config_add_key(cj_t *db, /* {{{ */
494 oconfig_item_t *ci) {
498 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
499 WARNING("curl_json plugin: The `Key' block "
500 "needs exactly one string argument.");
504 key = calloc(1, sizeof(*key));
506 ERROR("curl_json plugin: calloc failed.");
509 key->magic = CJ_KEY_MAGIC;
511 if (strcasecmp("Key", ci->key) == 0) {
512 status = cf_util_get_string(ci, &key->path);
518 ERROR("curl_json plugin: cj_config: "
526 for (int i = 0; i < ci->children_num; i++) {
527 oconfig_item_t *child = ci->children + i;
529 if (strcasecmp("Type", child->key) == 0)
530 status = cf_util_get_string(child, &key->type);
531 else if (strcasecmp("Instance", child->key) == 0)
532 status = cf_util_get_string(child, &key->instance);
534 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
540 } /* for (i = 0; i < ci->children_num; i++) */
547 if (key->type == NULL) {
548 WARNING("curl_json plugin: `Type' missing in `Key' block.");
553 status = cj_append_key(db, key);
560 } /* }}} int cj_config_add_key */
562 static int cj_init_curl(cj_t *db) /* {{{ */
564 db->curl = curl_easy_init();
565 if (db->curl == NULL) {
566 ERROR("curl_json plugin: curl_easy_init failed.");
570 curl_easy_setopt(db->curl, CURLOPT_NOSIGNAL, 1L);
571 curl_easy_setopt(db->curl, CURLOPT_WRITEFUNCTION, cj_curl_callback);
572 curl_easy_setopt(db->curl, CURLOPT_WRITEDATA, db);
573 curl_easy_setopt(db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
574 curl_easy_setopt(db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
575 curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
576 curl_easy_setopt(db->curl, CURLOPT_FOLLOWLOCATION, 1L);
577 curl_easy_setopt(db->curl, CURLOPT_MAXREDIRS, 50L);
579 if (db->user != NULL) {
580 #ifdef HAVE_CURLOPT_USERNAME
581 curl_easy_setopt(db->curl, CURLOPT_USERNAME, db->user);
582 curl_easy_setopt(db->curl, CURLOPT_PASSWORD,
583 (db->pass == NULL) ? "" : db->pass);
585 size_t credentials_size;
587 credentials_size = strlen(db->user) + 2;
588 if (db->pass != NULL)
589 credentials_size += strlen(db->pass);
591 db->credentials = malloc(credentials_size);
592 if (db->credentials == NULL) {
593 ERROR("curl_json plugin: malloc failed.");
597 ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
598 (db->pass == NULL) ? "" : db->pass);
599 curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials);
603 curl_easy_setopt(db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
606 curl_easy_setopt(db->curl, CURLOPT_SSL_VERIFYPEER, (long)db->verify_peer);
607 curl_easy_setopt(db->curl, CURLOPT_SSL_VERIFYHOST, db->verify_host ? 2L : 0L);
608 if (db->cacert != NULL)
609 curl_easy_setopt(db->curl, CURLOPT_CAINFO, db->cacert);
610 if (db->headers != NULL)
611 curl_easy_setopt(db->curl, CURLOPT_HTTPHEADER, db->headers);
612 if (db->post_body != NULL)
613 curl_easy_setopt(db->curl, CURLOPT_POSTFIELDS, db->post_body);
615 #ifdef HAVE_CURLOPT_TIMEOUT_MS
616 if (db->timeout >= 0)
617 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS, (long)db->timeout);
618 else if (db->interval > 0)
619 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS,
620 (long)CDTIME_T_TO_MS(db->interval));
622 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS,
623 (long)CDTIME_T_TO_MS(plugin_get_interval()));
627 } /* }}} int cj_init_curl */
629 static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */
634 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
635 WARNING("curl_json plugin: The `URL' block "
636 "needs exactly one string argument.");
640 db = calloc(1, sizeof(*db));
642 ERROR("curl_json plugin: calloc failed.");
648 if (strcasecmp("URL", ci->key) == 0)
649 status = cf_util_get_string(ci, &db->url);
650 else if (strcasecmp("Sock", ci->key) == 0)
651 status = cf_util_get_string(ci, &db->sock);
653 ERROR("curl_json plugin: cj_config: "
664 /* Fill the `cj_t' structure.. */
665 for (int i = 0; i < ci->children_num; i++) {
666 oconfig_item_t *child = ci->children + i;
668 if (strcasecmp("Instance", child->key) == 0)
669 status = cf_util_get_string(child, &db->instance);
670 else if (strcasecmp("Host", child->key) == 0)
671 status = cf_util_get_string(child, &db->host);
672 else if (db->url && strcasecmp("User", child->key) == 0)
673 status = cf_util_get_string(child, &db->user);
674 else if (db->url && strcasecmp("Password", child->key) == 0)
675 status = cf_util_get_string(child, &db->pass);
676 else if (strcasecmp("Digest", child->key) == 0)
677 status = cf_util_get_boolean(child, &db->digest);
678 else if (db->url && strcasecmp("VerifyPeer", child->key) == 0)
679 status = cf_util_get_boolean(child, &db->verify_peer);
680 else if (db->url && strcasecmp("VerifyHost", child->key) == 0)
681 status = cf_util_get_boolean(child, &db->verify_host);
682 else if (db->url && strcasecmp("CACert", child->key) == 0)
683 status = cf_util_get_string(child, &db->cacert);
684 else if (db->url && strcasecmp("Header", child->key) == 0)
685 status = cj_config_append_string("Header", &db->headers, child);
686 else if (db->url && strcasecmp("Post", child->key) == 0)
687 status = cf_util_get_string(child, &db->post_body);
688 else if (strcasecmp("Key", child->key) == 0)
689 status = cj_config_add_key(db, child);
690 else if (strcasecmp("Interval", child->key) == 0)
691 status = cf_util_get_cdtime(child, &db->interval);
692 else if (strcasecmp("Timeout", child->key) == 0)
693 status = cf_util_get_int(child, &db->timeout);
694 else if (strcasecmp("Statistics", child->key) == 0) {
695 db->stats = curl_stats_from_config(child);
696 if (db->stats == NULL)
699 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
708 if (db->tree == NULL) {
709 WARNING("curl_json plugin: No (valid) `Key' block within `%s' \"`%s'\".",
710 db->url ? "URL" : "Sock", db->url ? db->url : db->sock);
713 if (status == 0 && db->url)
714 status = cj_init_curl(db);
717 /* If all went well, register this database for reading */
721 if (db->instance == NULL)
722 db->instance = strdup("default");
724 DEBUG("curl_json plugin: Registering new read callback: %s", db->instance);
726 cb_name = ssnprintf_alloc("curl_json-%s-%s", db->instance,
727 db->url ? db->url : db->sock);
729 plugin_register_complex_read(/* group = */ NULL, cb_name, cj_read,
730 /* interval = */ db->interval,
732 .data = db, .free_func = cj_free,
742 /* }}} int cj_config_add_database */
744 static int cj_config(oconfig_item_t *ci) /* {{{ */
753 for (int i = 0; i < ci->children_num; i++) {
754 oconfig_item_t *child = ci->children + i;
756 if (strcasecmp("Sock", child->key) == 0 ||
757 strcasecmp("URL", child->key) == 0) {
758 status = cj_config_add_url(child);
764 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
769 if ((success == 0) && (errors > 0)) {
770 ERROR("curl_json plugin: All statements failed.");
775 } /* }}} int cj_config */
777 /* }}} End of configuration handling functions */
779 static const char *cj_host(cj_t *db) /* {{{ */
781 if ((db->host == NULL) || (strcmp("", db->host) == 0) ||
782 (strcmp(CJ_DEFAULT_HOST, db->host) == 0))
787 static void cj_submit_impl(cj_t *db, cj_key_t *key, value_t *value) /* {{{ */
789 value_list_t vl = VALUE_LIST_INIT;
794 if (key->instance == NULL) {
796 for (int i = 0; i < db->depth; i++)
797 len += ssnprintf(vl.type_instance + len, sizeof(vl.type_instance) - len,
798 i ? "-%s" : "%s", db->state[i + 1].name);
800 sstrncpy(vl.type_instance, key->instance, sizeof(vl.type_instance));
802 sstrncpy(vl.host, cj_host(db), sizeof(vl.host));
803 sstrncpy(vl.plugin, "curl_json", sizeof(vl.plugin));
804 sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance));
805 sstrncpy(vl.type, key->type, sizeof(vl.type));
807 if (db->interval > 0)
808 vl.interval = db->interval;
810 plugin_dispatch_values(&vl);
811 } /* }}} int cj_submit_impl */
813 static int cj_sock_perform(cj_t *db) /* {{{ */
816 struct sockaddr_un sa_unix = {
817 .sun_family = AF_UNIX,
819 sstrncpy(sa_unix.sun_path, db->sock, sizeof(sa_unix.sun_path));
821 int fd = socket(AF_UNIX, SOCK_STREAM, 0);
824 if (connect(fd, (struct sockaddr *)&sa_unix, sizeof(sa_unix)) < 0) {
825 ERROR("curl_json plugin: connect(%s) failed: %s",
826 (db->sock != NULL) ? db->sock : "<null>",
827 sstrerror(errno, errbuf, sizeof(errbuf)));
834 unsigned char buffer[4096];
835 red = read(fd, buffer, sizeof(buffer));
837 ERROR("curl_json plugin: read(%s) failed: %s",
838 (db->sock != NULL) ? db->sock : "<null>",
839 sstrerror(errno, errbuf, sizeof(errbuf)));
843 if (!cj_curl_callback(buffer, red, 1, db))
848 } /* }}} int cj_sock_perform */
850 static int cj_curl_perform(cj_t *db) /* {{{ */
857 status = curl_easy_perform(db->curl);
858 if (status != CURLE_OK) {
859 ERROR("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
860 status, db->curl_errbuf, url);
863 if (db->stats != NULL)
864 curl_stats_dispatch(db->stats, db->curl, cj_host(db), "curl_json",
867 curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
868 curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc);
870 /* The response code is zero if a non-HTTP transport was used. */
871 if ((rc != 0) && (rc != 200)) {
872 ERROR("curl_json plugin: curl_easy_perform failed with "
873 "response code %ld (%s)",
878 } /* }}} int cj_curl_perform */
880 static int cj_perform(cj_t *db) /* {{{ */
883 yajl_handle yprev = db->yajl;
885 db->yajl = yajl_alloc(&ycallbacks,
887 /* alloc funcs = */ NULL,
889 /* alloc funcs = */ NULL, NULL,
891 /* context = */ (void *)db);
892 if (db->yajl == NULL) {
893 ERROR("curl_json plugin: yajl_alloc failed.");
899 status = cj_curl_perform(db);
901 status = cj_sock_perform(db);
909 status = yajl_complete_parse(db->yajl);
911 status = yajl_parse_complete(db->yajl);
913 if (status != yajl_status_ok) {
914 unsigned char *errmsg;
916 errmsg = yajl_get_error(db->yajl, /* verbose = */ 0,
917 /* jsonText = */ NULL, /* jsonTextLen = */ 0);
918 ERROR("curl_json plugin: yajl_parse_complete failed: %s", (char *)errmsg);
919 yajl_free_error(db->yajl, errmsg);
928 } /* }}} int cj_perform */
930 static int cj_read(user_data_t *ud) /* {{{ */
934 if ((ud == NULL) || (ud->data == NULL)) {
935 ERROR("curl_json plugin: cj_read: Invalid user data.");
939 db = (cj_t *)ud->data;
942 memset(&db->state, 0, sizeof(db->state));
943 db->state[db->depth].tree = db->tree;
945 return cj_perform(db);
946 } /* }}} int cj_read */
948 static int cj_init(void) /* {{{ */
950 /* Call this while collectd is still single-threaded to avoid
951 * initialization issues in libgcrypt. */
952 curl_global_init(CURL_GLOBAL_SSL);
954 } /* }}} int cj_init */
956 void module_register(void) {
957 plugin_register_complex_config("curl_json", cj_config);
958 plugin_register_init("curl_json", cj_init);
959 } /* void module_register */