Merge pull request #695 from mfournier/curlopt_username-fixups
authorMarc Fournier <marc.fournier@camptocamp.com>
Mon, 1 Sep 2014 08:29:34 +0000 (10:29 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Mon, 1 Sep 2014 08:29:34 +0000 (10:29 +0200)
Allow curl digest feature to build against older libcurl versions

configure.ac
src/collectd.conf.in
src/collectd.conf.pod
src/curl.c
src/curl_json.c
src/curl_xml.c

index 0d0d043..bee5f72 100644 (file)
@@ -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 <curl/curl.h>]])
        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")
 # }}}
index 21de844..eed7bc8 100644 (file)
 #    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
 #    <Match>
 #      Regex "<span +class=\"pr\"[^>]*> *([0-9]*\\.[0-9]+) *</span>"
 #      DSType "GaugeAverage"
 #    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"
 #
 #    <XPath "table[@id=\"magic_level\"]/tr">
 #      Type "magic_level"
index bba9055..9293445 100644 (file)
@@ -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
+
       <Match>
         Regex "<span +class=\"pr\"[^>]*> *([0-9]*\\.[0-9]+) *</span>"
         DSType "GaugeAverage"
@@ -1281,13 +1291,19 @@ C<application/x-www-form-urlencoded>).
 Measure response time for the request. If this setting is enabled, B<Match>
 blocks (see below) are optional. Disabled by default.
 
+=item B<MeasureResponseCode> B<true>|B<false>
+
+Measure response code for the request. If this setting is enabled, B<Match>
+blocks (see below) are optional. Disabled by default.
+
 =item B<E<lt>MatchE<gt>>
 
 One or more B<Match> blocks that define how to match information in the data
 returned by C<libcurl>. The C<curl> plugin uses the same infrastructure that's
 used by the C<tail> plugin, so please see the documentation of the C<tail>
-plugin below on how matches are defined. If the B<MeasureResponseTime> option
-is set to B<true>, B<Match> blocks are optional.
+plugin below on how matches are defined. If the B<MeasureResponseTime> or
+B<MeasureResponseCode> options are set to B<true>, B<Match> blocks are
+optional.
 
 =back
 
@@ -1410,6 +1426,8 @@ The B<curl_xml plugin> uses B<libcurl> (L<http://curl.haxx.se/>) and B<libxml2>
      VerifyPeer true
      VerifyHost true
      CACert "/path/to/ca.crt"
+     Header "X-Custom-Header: foobar"
+     Post "foo=bar"
 
      <XPath "table[@id=\"magic_level\"]/tr">
        Type "magic_level"
index f605c07..9de8d3d 100644 (file)
@@ -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);
index a84cba0..8a084fe 100644 (file)
@@ -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);
index a743753..c0ab6fd 100644 (file)
@@ -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);