From: Jeremy Katz Date: Sun, 22 Sep 2013 19:50:05 +0000 (+0200) Subject: Add support for a custom user agent at compile-time X-Git-Tag: collectd-5.5.0~345 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9153bfdae3d92ddce750e174589cae1e96bab67f;p=collectd.git Add support for a custom user agent at compile-time Make it possible to specify a custom user agent at compile time and then use on all libcurl calls instead of just going with PACKAGE_NAME/PACKAGE_VERSION --- diff --git a/configure.in b/configure.in index c23df178..e137dabd 100644 --- a/configure.in +++ b/configure.in @@ -1665,6 +1665,17 @@ fi AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes") # }}} +# --with-useragent {{{ +AC_ARG_WITH(useragent, [AS_HELP_STRING([--with-useragent@<:@=OPTIONS@:>@], [User agent to use on http requests])], +[ + if test "x$withval" != "xno" && test "x$withval" != "xyes" + then + AC_DEFINE_UNQUOTED(COLLECTD_USERAGENT, ["$withval"], [User agent for http requests]) + fi +]) + +# }}} + # --with-libdbi {{{ with_libdbi_cppflags="" with_libdbi_ldflags="" diff --git a/src/apache.c b/src/apache.c index 8458ce15..c5f099f5 100644 --- a/src/apache.c +++ b/src/apache.c @@ -402,7 +402,7 @@ static int init_host (apache_t *st) /* {{{ */ curl_easy_setopt (st->curl, CURLOPT_WRITEHEADER, st); } - curl_easy_setopt (st->curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION); + curl_easy_setopt (st->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); curl_easy_setopt (st->curl, CURLOPT_ERRORBUFFER, st->apache_curl_error); if (st->user != NULL) diff --git a/src/ascent.c b/src/ascent.c index 94a39386..6809bac2 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -541,7 +541,7 @@ static int ascent_init (void) /* {{{ */ curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ascent_curl_callback); - curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION); + curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, ascent_curl_error); if (user != NULL) diff --git a/src/bind.c b/src/bind.c index ddde840a..2f990a21 100644 --- a/src/bind.c +++ b/src/bind.c @@ -1395,7 +1395,7 @@ static int bind_init (void) /* {{{ */ curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback); - curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION); + curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error); curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL); curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L); diff --git a/src/collectd.h b/src/collectd.h index 7cb405c0..969aedaa 100644 --- a/src/collectd.h +++ b/src/collectd.h @@ -262,6 +262,10 @@ typedef int _Bool; # define COLLECTD_DEFAULT_INTERVAL 10.0 #endif + #ifndef COLLECTD_USERAGENT + # define COLLECTD_USERAGENT PACKAGE_NAME"/"PACKAGE_VERSION + #endif + /* Remove GNU specific __attribute__ settings when using another compiler */ #if !__GNUC__ # define __attribute__(x) /**/ diff --git a/src/curl.c b/src/curl.c index 280e61c8..59903686 100644 --- a/src/curl.c +++ b/src/curl.c @@ -364,8 +364,7 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */ curl_easy_setopt (wp->curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (wp->curl, CURLOPT_WRITEFUNCTION, cc_curl_callback); curl_easy_setopt (wp->curl, CURLOPT_WRITEDATA, wp); - curl_easy_setopt (wp->curl, CURLOPT_USERAGENT, - PACKAGE_NAME"/"PACKAGE_VERSION); + curl_easy_setopt (wp->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); curl_easy_setopt (wp->curl, CURLOPT_ERRORBUFFER, wp->curl_errbuf); curl_easy_setopt (wp->curl, CURLOPT_URL, wp->url); curl_easy_setopt (wp->curl, CURLOPT_FOLLOWLOCATION, 1L); diff --git a/src/curl_json.c b/src/curl_json.c index 511863e3..251fee85 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -586,8 +586,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); diff --git a/src/curl_xml.c b/src/curl_xml.c index 5adaf067..3554d7e5 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -837,8 +837,7 @@ static int cx_init_curl (cx_t *db) /* {{{ */ curl_easy_setopt (db->curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (db->curl, CURLOPT_WRITEFUNCTION, cx_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); diff --git a/src/nginx.c b/src/nginx.c index de52262f..c356353e 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -122,7 +122,7 @@ static int init (void) curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, nginx_curl_callback); - curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION); + curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, nginx_curl_error); if (user != NULL) diff --git a/src/write_http.c b/src/write_http.c index 7f5943a2..25133c39 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -112,7 +112,7 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */ } curl_easy_setopt (cb->curl, CURLOPT_NOSIGNAL, 1L); - curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION); + curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); headers = NULL; headers = curl_slist_append (headers, "Accept: */*");