summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/curl/curl_fetcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/plugins/curl/curl_fetcher.c')
-rw-r--r--src/libstrongswan/plugins/curl/curl_fetcher.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libstrongswan/plugins/curl/curl_fetcher.c b/src/libstrongswan/plugins/curl/curl_fetcher.c
index 644f27709..620cf74f3 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,
@@ -102,7 +108,7 @@ METHOD(fetcher_t, fetch, status_t,
goto out;
}
curl_easy_setopt(this->curl, CURLOPT_ERRORBUFFER, error);
- curl_easy_setopt(this->curl, CURLOPT_FAILONERROR, TRUE);
+ curl_easy_setopt(this->curl, CURLOPT_FAILONERROR, FALSE);
curl_easy_setopt(this->curl, CURLOPT_NOSIGNAL, TRUE);
if (this->timeout)
{
@@ -123,7 +129,13 @@ METHOD(fetcher_t, fetch, status_t,
status = NOT_SUPPORTED;
break;
case CURLE_OK:
- status = SUCCESS;
+ curl_easy_getinfo(this->curl, CURLINFO_RESPONSE_CODE,
+ &result);
+ if (this->result)
+ {
+ *this->result = result;
+ }
+ status = (result >= 200 && result < 300) ? SUCCESS : FAILED;
break;
default:
DBG1(DBG_LIB, "libcurl http request failed: %s", error);
@@ -188,6 +200,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];