curl: Add support to return the response code
This commit is contained in:
@@ -49,6 +49,11 @@ struct private_curl_fetcher_t {
|
|||||||
*/
|
*/
|
||||||
fetcher_callback_t cb;
|
fetcher_callback_t cb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variable that receives the response code
|
||||||
|
*/
|
||||||
|
u_int *result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timeout for a transfer
|
* Timeout for a transfer
|
||||||
*/
|
*/
|
||||||
@@ -82,6 +87,7 @@ METHOD(fetcher_t, fetch, status_t,
|
|||||||
{
|
{
|
||||||
char error[CURL_ERROR_SIZE], *enc_uri;
|
char error[CURL_ERROR_SIZE], *enc_uri;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
long result = 0;
|
||||||
cb_data_t data = {
|
cb_data_t data = {
|
||||||
.cb = this->cb,
|
.cb = this->cb,
|
||||||
.user = userdata,
|
.user = userdata,
|
||||||
@@ -123,10 +129,25 @@ METHOD(fetcher_t, fetch, status_t,
|
|||||||
status = NOT_SUPPORTED;
|
status = NOT_SUPPORTED;
|
||||||
break;
|
break;
|
||||||
case CURLE_OK:
|
case CURLE_OK:
|
||||||
|
if (this->result)
|
||||||
|
{
|
||||||
|
curl_easy_getinfo(this->curl, CURLINFO_RESPONSE_CODE,
|
||||||
|
&result);
|
||||||
|
*this->result = result;
|
||||||
|
}
|
||||||
status = SUCCESS;
|
status = SUCCESS;
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
status = FAILED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -188,6 +209,11 @@ METHOD(fetcher_t, set_option, bool,
|
|||||||
this->cb = va_arg(args, fetcher_callback_t);
|
this->cb = va_arg(args, fetcher_callback_t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case FETCH_RESPONSE_CODE:
|
||||||
|
{
|
||||||
|
this->result = va_arg(args, u_int*);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case FETCH_SOURCEIP:
|
case FETCH_SOURCEIP:
|
||||||
{
|
{
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
|||||||
Reference in New Issue
Block a user