aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2014-05-09 18:35:20 +0200
committerTobias Brunner <tobias@strongswan.org>2014-05-19 14:28:40 +0200
commit703a0b4c3e11ceee936c795efdb630fbc45faa75 (patch)
treec01216f8018ea83b926449a51d910e8c016114cd
parentdeb8975bd2cabc57422af05989c59940b695ee78 (diff)
downloadstrongswan-703a0b4c3e11ceee936c795efdb630fbc45faa75.tar.bz2
strongswan-703a0b4c3e11ceee936c795efdb630fbc45faa75.tar.xz
curl: Add support to return the response code
-rw-r--r--src/libstrongswan/plugins/curl/curl_fetcher.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/libstrongswan/plugins/curl/curl_fetcher.c b/src/libstrongswan/plugins/curl/curl_fetcher.c
index 644f27709..573c4c369 100644
--- a/src/libstrongswan/plugins/curl/curl_fetcher.c
+++ b/src/libstrongswan/plugins/curl/curl_fetcher.c
@@ -50,6 +50,11 @@ struct private_curl_fetcher_t {
fetcher_callback_t cb;
/**
+ * Variable that receives the response code
+ */
+ u_int *result;
+
+ /**
* Timeout for a transfer
*/
long timeout;
@@ -82,6 +87,7 @@ METHOD(fetcher_t, fetch, status_t,
{
char error[CURL_ERROR_SIZE], *enc_uri;
status_t status;
+ long result = 0;
cb_data_t data = {
.cb = this->cb,
.user = userdata,
@@ -123,10 +129,25 @@ METHOD(fetcher_t, fetch, status_t,
status = NOT_SUPPORTED;
break;
case CURLE_OK:
+ if (this->result)
+ {
+ curl_easy_getinfo(this->curl, CURLINFO_RESPONSE_CODE,
+ &result);
+ *this->result = result;
+ }
status = SUCCESS;
break;
default:
- DBG1(DBG_LIB, "libcurl http request failed: %s", error);
+ if (this->result)
+ { /* don't log an error in this case */
+ curl_easy_getinfo(this->curl, CURLINFO_RESPONSE_CODE,
+ &result);
+ *this->result = result;
+ }
+ else
+ {
+ DBG1(DBG_LIB, "libcurl http request failed: %s", error);
+ }
status = FAILED;
break;
}
@@ -188,6 +209,11 @@ METHOD(fetcher_t, set_option, bool,
this->cb = va_arg(args, fetcher_callback_t);
break;
}
+ case FETCH_RESPONSE_CODE:
+ {
+ this->result = va_arg(args, u_int*);
+ break;
+ }
case FETCH_SOURCEIP:
{
char buf[64];