From 56c7b21899e44b57b5031a21ca3652b30f4fc1aa Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 6 Feb 2013 23:35:04 +0100 Subject: [PATCH] curl_xml plugin: Check for a curl_easy_perform() error first The value of CURLINFO_RESPONSE_CODE isn't valid otherwise. Also, use the symbolic name CURLE_OK in all plugins where appropriate. Change-Id: I17ae9c7eea393ee4641296b5484c93809a662dd9 Signed-off-by: Florian Forster --- src/apache.c | 2 +- src/ascent.c | 2 +- src/bind.c | 2 +- src/curl.c | 2 +- src/curl_json.c | 17 ++++++++--------- src/curl_xml.c | 13 ++++++------- src/nginx.c | 2 +- src/write_http.c | 2 +- 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/apache.c b/src/apache.c index b1f9eaa3..899c21ee 100644 --- a/src/apache.c +++ b/src/apache.c @@ -643,7 +643,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 23783862..94a39386 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 32e9d04b..19d95d41 100644 --- a/src/bind.c +++ b/src/bind.c @@ -1405,7 +1405,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 39d8e02f..3899aaab 100644 --- a/src/curl.c +++ b/src/curl.c @@ -618,7 +618,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 a7997907..24e1df1e 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -818,6 +818,14 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */ } status = curl_easy_perform (curl); + if (status != CURLE_OK) + { + ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)", + status, db->curl_errbuf, url); + yajl_free (db->yajl); + db->yajl = yprev; + return (-1); + } curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc); @@ -832,15 +840,6 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */ return (-1); } - if (status != 0) - { - ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)", - status, db->curl_errbuf, url); - yajl_free (db->yajl); - db->yajl = yprev; - return (-1); - } - #if HAVE_YAJL_V2 status = yajl_complete_parse(db->yajl); #else diff --git a/src/curl_xml.c b/src/curl_xml.c index c22172a7..75f5cc33 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -553,6 +553,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); @@ -565,13 +571,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 a73e4d24..a0fa74f0 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -214,7 +214,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 e08594cd..62c73b09 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", -- 2.30.2