X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcurl_json.c;h=a9db92501af819a56ccc5a2d7a603a81883a203e;hb=22ba280197b0ab9befc9d74f4b06ccd04b22d0c2;hp=511863e39f12e98b3914f83ebc0ba446f5db4f20;hpb=d0bf11d455b9da5770382f3cd20667723f1bbdb5;p=collectd.git diff --git a/src/curl_json.c b/src/curl_json.c index 511863e3..a9db9250 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -53,10 +53,10 @@ struct cj_key_s; typedef struct cj_key_s cj_key_t; struct cj_key_s /* {{{ */ { + unsigned long magic; char *path; char *type; char *instance; - unsigned long magic; }; /* }}} */ @@ -71,6 +71,7 @@ struct cj_s /* {{{ */ char *user; char *pass; char *credentials; + _Bool digest; _Bool verify_peer; _Bool verify_host; char *cacert; @@ -549,6 +550,7 @@ static int cj_config_add_key (cj_t *db, /* {{{ */ 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) @@ -586,8 +588,7 @@ static int cj_init_curl (cj_t *db) /* {{{ */ curl_easy_setopt (db->curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (db->curl, CURLOPT_WRITEFUNCTION, cj_curl_callback); curl_easy_setopt (db->curl, CURLOPT_WRITEDATA, db); - curl_easy_setopt (db->curl, CURLOPT_USERAGENT, - PACKAGE_NAME"/"PACKAGE_VERSION); + curl_easy_setopt (db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); curl_easy_setopt (db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf); curl_easy_setopt (db->curl, CURLOPT_URL, db->url); @@ -609,6 +610,13 @@ static int cj_init_curl (cj_t *db) /* {{{ */ ssnprintf (db->credentials, credentials_size, "%s:%s", db->user, (db->pass == NULL) ? "" : db->pass); curl_easy_setopt (db->curl, CURLOPT_USERPWD, db->credentials); + + if (db->digest) + { + curl_easy_setopt (db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + curl_easy_setopt (db->curl, CURLOPT_USERNAME, db->user); + curl_easy_setopt (db->curl, CURLOPT_PASSWORD, db->pass); + } } curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYPEER, (long) db->verify_peer); @@ -675,6 +683,8 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string (child, &db->user); else if (db->url && strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &db->pass); + else if (strcasecmp ("Digest", child->key) == 0) + status = cf_util_get_boolean (child, &db->digest); else if (db->url && strcasecmp ("VerifyPeer", child->key) == 0) status = cf_util_get_boolean (child, &db->verify_peer); else if (db->url && strcasecmp ("VerifyHost", child->key) == 0) @@ -859,17 +869,17 @@ static int cj_curl_perform(cj_t *db) /* {{{ */ int status; long rc; char *url; - url = NULL; - curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url); + url = db->url; status = curl_easy_perform (db->curl); if (status != CURLE_OK) { ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)", - status, db->curl_errbuf, (url != NULL) ? url : ""); + status, db->curl_errbuf, url); return (-1); } + curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url); curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc); /* The response code is zero if a non-HTTP transport was used. */