X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcurl_json.c;h=3ba55603d329342e6a30fa86b6908531e3e36e73;hb=81a5fd5046c6a39f580a8fc1a3af837fd5f5aa5c;hp=4cd4aec91d5155b08339d1a4c6ca72cc68325e47;hpb=39a1828548656b7f1fe486d48b8a08bf475277f1;p=collectd.git diff --git a/src/curl_json.c b/src/curl_json.c index 4cd4aec9..3ba55603 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -503,6 +503,7 @@ static int cj_config_add_key (cj_t *db, /* {{{ */ { ERROR ("curl_json plugin: cj_config: " "Invalid key: %s", ci->key); + cj_key_free (key); return (-1); } @@ -552,7 +553,6 @@ static int cj_config_add_key (cj_t *db, /* {{{ */ db->tree = cj_avl_create(); tree = db->tree; - name = key->path; ptr = key->path; if (*ptr == '/') ++ptr; @@ -650,10 +650,17 @@ static int cj_init_curl (cj_t *db) /* {{{ */ curl_easy_setopt (db->curl, CURLOPT_HTTPHEADER, db->headers); if (db->post_body != NULL) curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body); - curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, - db->timeout > 0 ? - db->timeout : - ( db->interval > 0 ? db->interval : cf_get_default_interval () )); + +#ifdef HAVE_CURLOPT_TIMEOUT_MS + if (db->timeout >= 0) + curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) db->timeout); + else if (db->interval > 0) + curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, + CDTIME_T_TO_MS(db->timeout)); + else + curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, + CDTIME_T_TO_MS(plugin_get_interval())); +#endif return (0); } /* }}} int cj_init_curl */ @@ -680,6 +687,8 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ } memset (db, 0, sizeof (*db)); + db->timeout = -1; + if (strcasecmp ("URL", ci->key) == 0) status = cf_util_get_string (ci, &db->url); else if (strcasecmp ("Sock", ci->key) == 0) @@ -688,6 +697,7 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ { ERROR ("curl_json plugin: cj_config: " "Invalid key: %s", ci->key); + cj_free (db); return (-1); } if (status != 0)