From: Marc Fournier Date: Mon, 1 Sep 2014 08:29:34 +0000 (+0200) Subject: Merge pull request #695 from mfournier/curlopt_username-fixups X-Git-Tag: collectd-5.5.0~215 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f2a6ed9f5064319ddc27292ab784e135bc955289;hp=e4ab153f9dc8d56325ed22bc35fd8eb89f9aed24;p=collectd.git Merge pull request #695 from mfournier/curlopt_username-fixups Allow curl digest feature to build against older libcurl versions --- diff --git a/configure.ac b/configure.ac index 0d0d0435..bee5f72a 100644 --- a/configure.ac +++ b/configure.ac @@ -1689,6 +1689,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" @@ -1697,6 +1701,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/collectd.conf.in b/src/collectd.conf.in index 21de8440..eed7bc81 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -313,7 +313,15 @@ # URL "http://finance.google.com/finance?q=NYSE%3AAMD" # User "foo" # Password "bar" +# Digest false +# VerifyPeer true +# VerifyHost true +# CACert "/path/to/ca.crt" +# Header "X-Custom-Header: foobar" +# Post "foo=bar" +# # MeasureResponseTime false +# MeasureResponseCode false # # Regex "]*> *([0-9]*\\.[0-9]+) *" # DSType "GaugeAverage" @@ -360,9 +368,12 @@ # Instance "some_instance" # User "collectd" # Password "thaiNg0I" +# Digest false # VerifyPeer true # VerifyHost true # CACert "/path/to/ca.crt" +# Header "X-Custom-Header: foobar" +# Post "foo=bar" # # # Type "magic_level" diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index bba90557..9293445e 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1209,6 +1209,16 @@ finance page and dispatch the value to collectd. URL "http://finance.google.com/finance?q=NYSE%3AAMD" User "foo" Password "bar" + Digest false + VerifyPeer true + VerifyHost true + CACert "/path/to/ca.crt" + Header "X-Custom-Header: foobar" + Post "foo=bar" + + MeasureResponseTime false + MeasureResponseCode false + Regex "]*> *([0-9]*\\.[0-9]+) *" DSType "GaugeAverage" @@ -1281,13 +1291,19 @@ C). Measure response time for the request. If this setting is enabled, B blocks (see below) are optional. Disabled by default. +=item B B|B + +Measure response code for the request. If this setting is enabled, B +blocks (see below) are optional. Disabled by default. + =item BMatchE> One or more B blocks that define how to match information in the data returned by C. The C plugin uses the same infrastructure that's used by the C plugin, so please see the documentation of the C -plugin below on how matches are defined. If the B option -is set to B, B blocks are optional. +plugin below on how matches are defined. If the B or +B options are set to B, B blocks are +optional. =back @@ -1410,6 +1426,8 @@ The B uses B (L) and B VerifyPeer true VerifyHost true CACert "/path/to/ca.crt" + Header "X-Custom-Header: foobar" + Post "foo=bar" Type "magic_level" diff --git a/src/curl.c b/src/curl.c index f605c078..9de8d3d7 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,13 +394,10 @@ 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); - curl_easy_setopt (wp->curl, CURLOPT_USERNAME, wp->user); - curl_easy_setopt (wp->curl, CURLOPT_PASSWORD, wp->pass); - } } curl_easy_setopt (wp->curl, CURLOPT_SSL_VERIFYPEER, (long) wp->verify_peer); diff --git a/src/curl_json.c b/src/curl_json.c index a84cba04..8a084fed 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,13 +616,10 @@ 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); - 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); diff --git a/src/curl_xml.c b/src/curl_xml.c index a743753e..c0ab6fdb 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,13 +866,10 @@ 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); - 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, db->verify_peer ? 1L : 0L);