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 static int cj_cb_map_key(void *ctx, const unsigned char *val, yajl_len_t len);
179 static void cj_cb_inc_array_index(void *ctx, _Bool update_key) {
180 cj_t *db = (cj_t *)ctx;
182 if (!db->state[db->depth].in_array)
185 db->state[db->depth].index++;
188 char name[DATA_MAX_NAME_LEN];
190 ssnprintf(name, sizeof(name), "%d", db->state[db->depth].index - 1);
192 cj_cb_map_key(ctx, (unsigned char *)name, (yajl_len_t)strlen(name));
197 #define CJ_CB_ABORT 0
198 #define CJ_CB_CONTINUE 1
200 static int cj_cb_boolean(void *ctx, int boolVal) {
201 cj_cb_inc_array_index(ctx, /* update_key = */ 0);
202 return (CJ_CB_CONTINUE);
205 static int cj_cb_null(void *ctx) {
206 cj_cb_inc_array_index(ctx, /* update_key = */ 0);
207 return (CJ_CB_CONTINUE);
210 static int cj_cb_number(void *ctx, const char *number, yajl_len_t number_len) {
211 char buffer[number_len + 1];
213 cj_t *db = (cj_t *)ctx;
214 cj_key_t *key = db->state[db->depth].key;
219 /* Create a null-terminated version of the string. */
220 memcpy(buffer, number, number_len);
221 buffer[sizeof(buffer) - 1] = 0;
223 if ((key == NULL) || !CJ_IS_KEY(key)) {
225 !db->state[db->depth].in_array /*can be inhomogeneous*/) {
226 NOTICE("curl_json plugin: Found \"%s\", but the configuration expects"
229 return (CJ_CB_CONTINUE);
232 cj_cb_inc_array_index(ctx, /* update_key = */ 1);
233 key = db->state[db->depth].key;
234 if ((key == NULL) || !CJ_IS_KEY(key)) {
235 return (CJ_CB_CONTINUE);
238 cj_cb_inc_array_index(ctx, /* update_key = */ 1);
241 type = cj_get_type(key);
242 status = parse_value(buffer, &vt, type);
244 NOTICE("curl_json plugin: Unable to parse number: \"%s\"", buffer);
245 return (CJ_CB_CONTINUE);
248 cj_submit(db, key, &vt);
249 return (CJ_CB_CONTINUE);
250 } /* int cj_cb_number */
252 /* Queries the key-tree of the parent context for "in_name" and, if found,
253 * updates the "key" field of the current context. Otherwise, "key" is set to
255 static int cj_cb_map_key(void *ctx, unsigned char const *in_name,
256 yajl_len_t in_name_len) {
257 cj_t *db = (cj_t *)ctx;
260 tree = db->state[db->depth - 1].tree;
263 cj_key_t *value = NULL;
267 /* Create a null-terminated version of the name. */
268 name = db->state[db->depth].name;
270 COUCH_MIN((size_t)in_name_len, sizeof(db->state[db->depth].name) - 1);
271 memcpy(name, in_name, name_len);
274 if (c_avl_get(tree, name, (void *)&value) == 0) {
275 if (CJ_IS_KEY((cj_key_t *)value)) {
276 db->state[db->depth].key = value;
278 db->state[db->depth].tree = (c_avl_tree_t *)value;
280 } else if (c_avl_get(tree, CJ_ANY, (void *)&value) == 0)
281 if (CJ_IS_KEY((cj_key_t *)value)) {
282 db->state[db->depth].key = value;
284 db->state[db->depth].tree = (c_avl_tree_t *)value;
287 db->state[db->depth].key = NULL;
290 return (CJ_CB_CONTINUE);
293 static int cj_cb_string(void *ctx, const unsigned char *val, yajl_len_t len) {
294 /* Handle the string as if it was a number. */
295 return (cj_cb_number(ctx, (const char *)val, len));
296 } /* int cj_cb_string */
298 static int cj_cb_start(void *ctx) {
299 cj_t *db = (cj_t *)ctx;
300 if (++db->depth >= YAJL_MAX_DEPTH) {
301 ERROR("curl_json plugin: %s depth exceeds max, aborting.",
302 db->url ? db->url : db->sock);
303 return (CJ_CB_ABORT);
305 return (CJ_CB_CONTINUE);
308 static int cj_cb_end(void *ctx) {
309 cj_t *db = (cj_t *)ctx;
310 db->state[db->depth].tree = NULL;
312 return (CJ_CB_CONTINUE);
315 static int cj_cb_start_map(void *ctx) {
316 cj_cb_inc_array_index(ctx, /* update_key = */ 1);
317 return cj_cb_start(ctx);
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;
324 cj_cb_inc_array_index(ctx, /* update_key = */ 1);
325 if (db->depth + 1 < YAJL_MAX_DEPTH) {
326 db->state[db->depth + 1].in_array = 1;
327 db->state[db->depth + 1].index = 0;
329 return cj_cb_start(ctx);
332 static int cj_cb_end_array(void *ctx) {
333 cj_t *db = (cj_t *)ctx;
334 db->state[db->depth].in_array = 0;
335 return cj_cb_end(ctx);
338 static yajl_callbacks ycallbacks = {
339 cj_cb_null, /* null */
340 cj_cb_boolean, /* boolean */
343 cj_cb_number, cj_cb_string, cj_cb_start_map, cj_cb_map_key,
344 cj_cb_end_map, cj_cb_start_array, cj_cb_end_array};
346 /* end yajl callbacks */
348 static void cj_key_free(cj_key_t *key) /* {{{ */
355 sfree(key->instance);
358 } /* }}} void cj_key_free */
360 static void cj_tree_free(c_avl_tree_t *tree) /* {{{ */
365 while (c_avl_pick(tree, (void *)&name, (void *)&value) == 0) {
366 cj_key_t *key = (cj_key_t *)value;
371 cj_tree_free((c_avl_tree_t *)value);
377 } /* }}} void cj_tree_free */
379 static void cj_free(void *arg) /* {{{ */
383 DEBUG("curl_json plugin: cj_free (arg = %p);", arg);
390 if (db->curl != NULL)
391 curl_easy_cleanup(db->curl);
394 if (db->tree != NULL)
395 cj_tree_free(db->tree);
406 sfree(db->credentials);
408 sfree(db->post_body);
409 curl_slist_free_all(db->headers);
410 curl_stats_destroy(db->stats);
413 } /* }}} void cj_free */
415 /* Configuration handling functions {{{ */
417 static c_avl_tree_t *cj_avl_create(void) {
418 return c_avl_create((int (*)(const void *, const void *))strcmp);
421 static int cj_config_append_string(const char *name,
422 struct curl_slist **dest, /* {{{ */
423 oconfig_item_t *ci) {
424 struct curl_slist *temp = NULL;
425 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
426 WARNING("curl_json plugin: `%s' needs exactly one string argument.", name);
430 temp = curl_slist_append(*dest, ci->values[0].value.string);
437 } /* }}} int cj_config_append_string */
439 /* cj_append_key adds key to the configuration stored in db.
442 * "httpd/requests/count",
443 * "httpd/requests/current" ->
444 * { "httpd": { "requests": { "count": $key, "current": $key } } }
446 static int cj_append_key(cj_t *db, cj_key_t *key) { /* {{{ */
447 if (db->tree == NULL)
448 db->tree = cj_avl_create();
450 c_avl_tree_t *tree = db->tree;
452 char const *start = key->path;
457 while ((end = strchr(start, '/')) != NULL) {
460 size_t len = end - start;
464 len = COUCH_MIN(len, sizeof(name) - 1);
465 sstrncpy(name, start, len + 1);
468 if (c_avl_get(tree, name, (void *)&value) != 0) {
469 value = cj_avl_create();
470 c_avl_insert(tree, strdup(name), value);
477 if (strlen(start) == 0) {
478 ERROR("curl_json plugin: invalid key: %s", key->path);
482 c_avl_insert(tree, strdup(start), key);
484 } /* }}} int cj_append_key */
486 static int cj_config_add_key(cj_t *db, /* {{{ */
487 oconfig_item_t *ci) {
491 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
492 WARNING("curl_json plugin: The `Key' block "
493 "needs exactly one string argument.");
497 key = calloc(1, sizeof(*key));
499 ERROR("curl_json plugin: calloc failed.");
502 key->magic = CJ_KEY_MAGIC;
504 if (strcasecmp("Key", ci->key) == 0) {
505 status = cf_util_get_string(ci, &key->path);
511 ERROR("curl_json plugin: cj_config: "
519 for (int i = 0; i < ci->children_num; i++) {
520 oconfig_item_t *child = ci->children + i;
522 if (strcasecmp("Type", child->key) == 0)
523 status = cf_util_get_string(child, &key->type);
524 else if (strcasecmp("Instance", child->key) == 0)
525 status = cf_util_get_string(child, &key->instance);
527 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
533 } /* for (i = 0; i < ci->children_num; i++) */
540 if (key->type == NULL) {
541 WARNING("curl_json plugin: `Type' missing in `Key' block.");
546 status = cj_append_key(db, key);
553 } /* }}} int cj_config_add_key */
555 static int cj_init_curl(cj_t *db) /* {{{ */
557 db->curl = curl_easy_init();
558 if (db->curl == NULL) {
559 ERROR("curl_json plugin: curl_easy_init failed.");
563 curl_easy_setopt(db->curl, CURLOPT_NOSIGNAL, 1L);
564 curl_easy_setopt(db->curl, CURLOPT_WRITEFUNCTION, cj_curl_callback);
565 curl_easy_setopt(db->curl, CURLOPT_WRITEDATA, db);
566 curl_easy_setopt(db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
567 curl_easy_setopt(db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
568 curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
569 curl_easy_setopt(db->curl, CURLOPT_FOLLOWLOCATION, 1L);
570 curl_easy_setopt(db->curl, CURLOPT_MAXREDIRS, 50L);
572 if (db->user != NULL) {
573 #ifdef HAVE_CURLOPT_USERNAME
574 curl_easy_setopt(db->curl, CURLOPT_USERNAME, db->user);
575 curl_easy_setopt(db->curl, CURLOPT_PASSWORD,
576 (db->pass == NULL) ? "" : db->pass);
578 size_t credentials_size;
580 credentials_size = strlen(db->user) + 2;
581 if (db->pass != NULL)
582 credentials_size += strlen(db->pass);
584 db->credentials = malloc(credentials_size);
585 if (db->credentials == NULL) {
586 ERROR("curl_json plugin: malloc failed.");
590 ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
591 (db->pass == NULL) ? "" : db->pass);
592 curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials);
596 curl_easy_setopt(db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
599 curl_easy_setopt(db->curl, CURLOPT_SSL_VERIFYPEER, (long)db->verify_peer);
600 curl_easy_setopt(db->curl, CURLOPT_SSL_VERIFYHOST, db->verify_host ? 2L : 0L);
601 if (db->cacert != NULL)
602 curl_easy_setopt(db->curl, CURLOPT_CAINFO, db->cacert);
603 if (db->headers != NULL)
604 curl_easy_setopt(db->curl, CURLOPT_HTTPHEADER, db->headers);
605 if (db->post_body != NULL)
606 curl_easy_setopt(db->curl, CURLOPT_POSTFIELDS, db->post_body);
608 #ifdef HAVE_CURLOPT_TIMEOUT_MS
609 if (db->timeout >= 0)
610 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS, (long)db->timeout);
611 else if (db->interval > 0)
612 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS,
613 (long)CDTIME_T_TO_MS(db->interval));
615 curl_easy_setopt(db->curl, CURLOPT_TIMEOUT_MS,
616 (long)CDTIME_T_TO_MS(plugin_get_interval()));
620 } /* }}} int cj_init_curl */
622 static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */
627 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
628 WARNING("curl_json plugin: The `URL' block "
629 "needs exactly one string argument.");
633 db = calloc(1, sizeof(*db));
635 ERROR("curl_json plugin: calloc failed.");
641 if (strcasecmp("URL", ci->key) == 0)
642 status = cf_util_get_string(ci, &db->url);
643 else if (strcasecmp("Sock", ci->key) == 0)
644 status = cf_util_get_string(ci, &db->sock);
646 ERROR("curl_json plugin: cj_config: "
657 /* Fill the `cj_t' structure.. */
658 for (int i = 0; i < ci->children_num; i++) {
659 oconfig_item_t *child = ci->children + i;
661 if (strcasecmp("Instance", child->key) == 0)
662 status = cf_util_get_string(child, &db->instance);
663 else if (strcasecmp("Host", child->key) == 0)
664 status = cf_util_get_string(child, &db->host);
665 else if (db->url && strcasecmp("User", child->key) == 0)
666 status = cf_util_get_string(child, &db->user);
667 else if (db->url && strcasecmp("Password", child->key) == 0)
668 status = cf_util_get_string(child, &db->pass);
669 else if (strcasecmp("Digest", child->key) == 0)
670 status = cf_util_get_boolean(child, &db->digest);
671 else if (db->url && strcasecmp("VerifyPeer", child->key) == 0)
672 status = cf_util_get_boolean(child, &db->verify_peer);
673 else if (db->url && strcasecmp("VerifyHost", child->key) == 0)
674 status = cf_util_get_boolean(child, &db->verify_host);
675 else if (db->url && strcasecmp("CACert", child->key) == 0)
676 status = cf_util_get_string(child, &db->cacert);
677 else if (db->url && strcasecmp("Header", child->key) == 0)
678 status = cj_config_append_string("Header", &db->headers, child);
679 else if (db->url && strcasecmp("Post", child->key) == 0)
680 status = cf_util_get_string(child, &db->post_body);
681 else if (strcasecmp("Key", child->key) == 0)
682 status = cj_config_add_key(db, child);
683 else if (strcasecmp("Interval", child->key) == 0)
684 status = cf_util_get_cdtime(child, &db->interval);
685 else if (strcasecmp("Timeout", child->key) == 0)
686 status = cf_util_get_int(child, &db->timeout);
687 else if (strcasecmp("Statistics", child->key) == 0) {
688 db->stats = curl_stats_from_config(child);
689 if (db->stats == NULL)
692 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
701 if (db->tree == NULL) {
702 WARNING("curl_json plugin: No (valid) `Key' block within `%s' \"`%s'\".",
703 db->url ? "URL" : "Sock", db->url ? db->url : db->sock);
706 if (status == 0 && db->url)
707 status = cj_init_curl(db);
710 /* If all went well, register this database for reading */
714 if (db->instance == NULL)
715 db->instance = strdup("default");
717 DEBUG("curl_json plugin: Registering new read callback: %s", db->instance);
719 cb_name = ssnprintf_alloc("curl_json-%s-%s", db->instance,
720 db->url ? db->url : db->sock);
722 plugin_register_complex_read(/* group = */ NULL, cb_name, cj_read,
723 /* interval = */ db->interval,
725 .data = db, .free_func = cj_free,
735 /* }}} int cj_config_add_database */
737 static int cj_config(oconfig_item_t *ci) /* {{{ */
746 for (int i = 0; i < ci->children_num; i++) {
747 oconfig_item_t *child = ci->children + i;
749 if (strcasecmp("Sock", child->key) == 0 ||
750 strcasecmp("URL", child->key) == 0) {
751 status = cj_config_add_url(child);
757 WARNING("curl_json plugin: Option `%s' not allowed here.", child->key);
762 if ((success == 0) && (errors > 0)) {
763 ERROR("curl_json plugin: All statements failed.");
768 } /* }}} int cj_config */
770 /* }}} End of configuration handling functions */
772 static const char *cj_host(cj_t *db) /* {{{ */
774 if ((db->host == NULL) || (strcmp("", db->host) == 0) ||
775 (strcmp(CJ_DEFAULT_HOST, db->host) == 0))
780 static void cj_submit_impl(cj_t *db, cj_key_t *key, value_t *value) /* {{{ */
782 value_list_t vl = VALUE_LIST_INIT;
787 if (key->instance == NULL) {
789 for (int i = 0; i < db->depth; i++)
790 len += ssnprintf(vl.type_instance + len, sizeof(vl.type_instance) - len,
791 i ? "-%s" : "%s", db->state[i + 1].name);
793 sstrncpy(vl.type_instance, key->instance, sizeof(vl.type_instance));
795 sstrncpy(vl.host, cj_host(db), sizeof(vl.host));
796 sstrncpy(vl.plugin, "curl_json", sizeof(vl.plugin));
797 sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance));
798 sstrncpy(vl.type, key->type, sizeof(vl.type));
800 if (db->interval > 0)
801 vl.interval = db->interval;
803 plugin_dispatch_values(&vl);
804 } /* }}} int cj_submit_impl */
806 static int cj_sock_perform(cj_t *db) /* {{{ */
809 struct sockaddr_un sa_unix = {
810 .sun_family = AF_UNIX,
812 sstrncpy(sa_unix.sun_path, db->sock, sizeof(sa_unix.sun_path));
814 int fd = socket(AF_UNIX, SOCK_STREAM, 0);
817 if (connect(fd, (struct sockaddr *)&sa_unix, sizeof(sa_unix)) < 0) {
818 ERROR("curl_json plugin: connect(%s) failed: %s",
819 (db->sock != NULL) ? db->sock : "<null>",
820 sstrerror(errno, errbuf, sizeof(errbuf)));
827 unsigned char buffer[4096];
828 red = read(fd, buffer, sizeof(buffer));
830 ERROR("curl_json plugin: read(%s) failed: %s",
831 (db->sock != NULL) ? db->sock : "<null>",
832 sstrerror(errno, errbuf, sizeof(errbuf)));
836 if (!cj_curl_callback(buffer, red, 1, db))
841 } /* }}} int cj_sock_perform */
843 static int cj_curl_perform(cj_t *db) /* {{{ */
850 status = curl_easy_perform(db->curl);
851 if (status != CURLE_OK) {
852 ERROR("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
853 status, db->curl_errbuf, url);
856 if (db->stats != NULL)
857 curl_stats_dispatch(db->stats, db->curl, cj_host(db), "curl_json",
860 curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
861 curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc);
863 /* The response code is zero if a non-HTTP transport was used. */
864 if ((rc != 0) && (rc != 200)) {
865 ERROR("curl_json plugin: curl_easy_perform failed with "
866 "response code %ld (%s)",
871 } /* }}} int cj_curl_perform */
873 static int cj_perform(cj_t *db) /* {{{ */
876 yajl_handle yprev = db->yajl;
878 db->yajl = yajl_alloc(&ycallbacks,
880 /* alloc funcs = */ NULL,
882 /* alloc funcs = */ NULL, NULL,
884 /* context = */ (void *)db);
885 if (db->yajl == NULL) {
886 ERROR("curl_json plugin: yajl_alloc failed.");
892 status = cj_curl_perform(db);
894 status = cj_sock_perform(db);
902 status = yajl_complete_parse(db->yajl);
904 status = yajl_parse_complete(db->yajl);
906 if (status != yajl_status_ok) {
907 unsigned char *errmsg;
909 errmsg = yajl_get_error(db->yajl, /* verbose = */ 0,
910 /* jsonText = */ NULL, /* jsonTextLen = */ 0);
911 ERROR("curl_json plugin: yajl_parse_complete failed: %s", (char *)errmsg);
912 yajl_free_error(db->yajl, errmsg);
921 } /* }}} int cj_perform */
923 static int cj_read(user_data_t *ud) /* {{{ */
927 if ((ud == NULL) || (ud->data == NULL)) {
928 ERROR("curl_json plugin: cj_read: Invalid user data.");
932 db = (cj_t *)ud->data;
935 memset(&db->state, 0, sizeof(db->state));
936 db->state[db->depth].tree = db->tree;
938 return cj_perform(db);
939 } /* }}} int cj_read */
941 static int cj_init(void) /* {{{ */
943 /* Call this while collectd is still single-threaded to avoid
944 * initialization issues in libgcrypt. */
945 curl_global_init(CURL_GLOBAL_SSL);
947 } /* }}} int cj_init */
949 void module_register(void) {
950 plugin_register_complex_config("curl_json", cj_config);
951 plugin_register_init("curl_json", cj_init);
952 } /* void module_register */