[collectd] [PATCH] curl_xml plugin: Check for a curl_easy_perform() error first
Dan Fandrich
dan at coneharvesters.com
Wed Feb 6 23:35:04 CET 2013
The value of CURLINFO_RESPONSE_CODE isn't valid otherwise.
Also, use the symbolic name CURLE_OK in all plugins where
appropriate.
---
src/apache.c | 2 +-
src/ascent.c | 2 +-
src/bind.c | 2 +-
src/curl.c | 2 +-
src/curl_json.c | 2 +-
src/curl_xml.c | 13 ++++++-------
src/nginx.c | 2 +-
src/write_http.c | 2 +-
8 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/apache.c b/src/apache.c
index e562138..8458ce1 100644
--- a/src/apache.c
+++ b/src/apache.c
@@ -612,7 +612,7 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */
assert (st->curl != NULL);
st->apache_buffer_fill = 0;
- if (curl_easy_perform (st->curl) != 0)
+ if (curl_easy_perform (st->curl) != CURLE_OK)
{
ERROR ("apache: curl_easy_perform failed: %s",
st->apache_curl_error);
diff --git a/src/ascent.c b/src/ascent.c
index 2378386..94a3938 100644
--- a/src/ascent.c
+++ b/src/ascent.c
@@ -597,7 +597,7 @@ static int ascent_read (void) /* {{{ */
}
ascent_buffer_fill = 0;
- if (curl_easy_perform (curl) != 0)
+ if (curl_easy_perform (curl) != CURLE_OK)
{
ERROR ("ascent plugin: curl_easy_perform failed: %s",
ascent_curl_error);
diff --git a/src/bind.c b/src/bind.c
index 7857a67..ddde840 100644
--- a/src/bind.c
+++ b/src/bind.c
@@ -1415,7 +1415,7 @@ static int bind_read (void) /* {{{ */
}
bind_buffer_fill = 0;
- if (curl_easy_perform (curl) != 0)
+ if (curl_easy_perform (curl) != CURLE_OK)
{
ERROR ("bind plugin: curl_easy_perform failed: %s",
bind_curl_error);
diff --git a/src/curl.c b/src/curl.c
index cb352bf..c6e2ae9 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -645,7 +645,7 @@ static int cc_read_page (web_page_t *wp) /* {{{ */
wp->buffer_fill = 0;
status = curl_easy_perform (wp->curl);
- if (status != 0)
+ if (status != CURLE_OK)
{
ERROR ("curl plugin: curl_easy_perform failed with staus %i: %s",
status, wp->curl_errbuf);
diff --git a/src/curl_json.c b/src/curl_json.c
index 1494327..2635772 100644
--- a/src/curl_json.c
+++ b/src/curl_json.c
@@ -798,7 +798,7 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
status = curl_easy_perform (curl);
- if (status != 0)
+ if (status != CURLE_OK)
{
ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
status, db->curl_errbuf, (url != NULL) ? url : "<null>");
diff --git a/src/curl_xml.c b/src/curl_xml.c
index 747e461..6ffad42 100644
--- a/src/curl_xml.c
+++ b/src/curl_xml.c
@@ -676,6 +676,12 @@ static int cx_curl_perform (cx_t *db, CURL *curl) /* {{{ */
db->buffer_fill = 0;
status = curl_easy_perform (curl);
+ if (status != CURLE_OK)
+ {
+ ERROR ("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
+ status, db->curl_errbuf, url);
+ return (-1);
+ }
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc);
@@ -688,13 +694,6 @@ static int cx_curl_perform (cx_t *db, CURL *curl) /* {{{ */
return (-1);
}
- if (status != 0)
- {
- ERROR ("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
- status, db->curl_errbuf, url);
- return (-1);
- }
-
ptr = db->buffer;
status = cx_parse_stats_xml(BAD_CAST ptr, db);
diff --git a/src/nginx.c b/src/nginx.c
index ecfb307..7568a2c 100644
--- a/src/nginx.c
+++ b/src/nginx.c
@@ -215,7 +215,7 @@ static int nginx_read (void)
return (-1);
nginx_buffer_len = 0;
- if (curl_easy_perform (curl) != 0)
+ if (curl_easy_perform (curl) != CURLE_OK)
{
WARNING ("nginx plugin: curl_easy_perform failed: %s", nginx_curl_error);
return (-1);
diff --git a/src/write_http.c b/src/write_http.c
index 6b1c64a..7f5943a 100644
--- a/src/write_http.c
+++ b/src/write_http.c
@@ -88,7 +88,7 @@ static int wh_send_buffer (wh_callback_t *cb) /* {{{ */
curl_easy_setopt (cb->curl, CURLOPT_POSTFIELDS, cb->send_buffer);
status = curl_easy_perform (cb->curl);
- if (status != 0)
+ if (status != CURLE_OK)
{
ERROR ("write_http plugin: curl_easy_perform failed with "
"status %i: %s",
--
1.7.10
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 308 bytes
Desc: not available
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20130206/8fb4d3ae/attachment.pgp>
More information about the collectd
mailing list