From: Marc Fournier Date: Wed, 6 Aug 2014 13:24:33 +0000 (+0200) Subject: curl*: use CURLOPT_USERNAME if libcurl is recent enough X-Git-Tag: collectd-5.5.0~215^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0af75dc13d6e722284a9dafe83cb50da2b025b21;p=collectd.git curl*: use CURLOPT_USERNAME if libcurl is recent enough CURLOPT_USERNAME and CURLOPT_PASSWORD were introduced in curl 7.19.1. They supersed CURLOPT_USERPWD which couldn't handle colons in the username or password. --- diff --git a/configure.ac b/configure.ac index 1757e2fa..c843d31e 100644 --- a/configure.ac +++ b/configure.ac @@ -1664,6 +1664,10 @@ then [with_libcurl="yes"], [with_libcurl="no (symbol 'curl_easy_init' not found)"], [$with_curl_libs]) + AC_CHECK_DECL(CURLOPT_USERNAME, + [have_curlopt_username="yes"], + [have_curlopt_username="no"], + [[#include ]]) fi fi if test "x$with_libcurl" = "xyes" @@ -1672,6 +1676,11 @@ then BUILD_WITH_LIBCURL_LIBS="$with_curl_libs" AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS) AC_SUBST(BUILD_WITH_LIBCURL_LIBS) + + if test "x$have_curlopt_username" = "xyes" + then + AC_DEFINE(HAVE_CURLOPT_USERNAME, 1, [Define if libcurl supports CURLOPT_USERNAME option.]) + fi fi AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes") # }}} diff --git a/src/curl.c b/src/curl.c index 0e6596d4..c188c717 100644 --- a/src/curl.c +++ b/src/curl.c @@ -373,6 +373,11 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */ if (wp->user != NULL) { +#ifdef HAVE_CURLOPT_USERNAME + curl_easy_setopt (wp->curl, CURLOPT_USERNAME, wp->user); + curl_easy_setopt (wp->curl, CURLOPT_PASSWORD, + (wp->pass == NULL) ? "" : wp->pass); +#else size_t credentials_size; credentials_size = strlen (wp->user) + 2; @@ -389,6 +394,7 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */ ssnprintf (wp->credentials, credentials_size, "%s:%s", wp->user, (wp->pass == NULL) ? "" : wp->pass); curl_easy_setopt (wp->curl, CURLOPT_USERPWD, wp->credentials); +#endif if (wp->digest) curl_easy_setopt (wp->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); diff --git a/src/curl_json.c b/src/curl_json.c index 58f0b35c..860de616 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -595,6 +595,11 @@ static int cj_init_curl (cj_t *db) /* {{{ */ if (db->user != NULL) { +#ifdef HAVE_CURLOPT_USERNAME + curl_easy_setopt (db->curl, CURLOPT_USERNAME, db->user); + curl_easy_setopt (db->curl, CURLOPT_PASSWORD, + (db->pass == NULL) ? "" : db->pass); +#else size_t credentials_size; credentials_size = strlen (db->user) + 2; @@ -611,6 +616,7 @@ 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); +#endif if (db->digest) curl_easy_setopt (db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); diff --git a/src/curl_xml.c b/src/curl_xml.c index 850a4aa5..bbcbc04d 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -845,6 +845,11 @@ static int cx_init_curl (cx_t *db) /* {{{ */ if (db->user != NULL) { +#ifdef HAVE_CURLOPT_USERNAME + curl_easy_setopt (db->curl, CURLOPT_USERNAME, db->user); + curl_easy_setopt (db->curl, CURLOPT_PASSWORD, + (db->pass == NULL) ? "" : db->pass); +#else size_t credentials_size; credentials_size = strlen (db->user) + 2; @@ -861,6 +866,7 @@ static int cx_init_curl (cx_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); +#endif if (db->digest) curl_easy_setopt (db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);