mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-08 00:02:03 -04:00
winhttp: Support new response code fetcher option
This commit is contained in:
parent
6f90fc8061
commit
2e0816e1df
@ -72,6 +72,11 @@ struct private_winhttp_fetcher_t {
|
|||||||
* Timeout for operations, in ms
|
* Timeout for operations, in ms
|
||||||
*/
|
*/
|
||||||
u_long timeout;
|
u_long timeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User pointer to store HTTP status code to
|
||||||
|
*/
|
||||||
|
u_int *result;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,12 +120,33 @@ static bool read_result(private_winhttp_fetcher_t *this, HINTERNET request,
|
|||||||
{
|
{
|
||||||
DWORD received;
|
DWORD received;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
u_int32_t code;
|
||||||
|
DWORD codelen = sizeof(code);
|
||||||
|
|
||||||
if (!WinHttpReceiveResponse(request, NULL))
|
if (!WinHttpReceiveResponse(request, NULL))
|
||||||
{
|
{
|
||||||
DBG1(DBG_LIB, "reading HTTP response header failed: %u", GetLastError());
|
DBG1(DBG_LIB, "reading HTTP response header failed: %u", GetLastError());
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
if (!WinHttpQueryHeaders(request,
|
||||||
|
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
|
||||||
|
NULL, &code, &codelen, NULL))
|
||||||
|
{
|
||||||
|
DBG1(DBG_LIB, "reading HTTP status code failed: %u", GetLastError());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (this->result)
|
||||||
|
{
|
||||||
|
*this->result = code;
|
||||||
|
}
|
||||||
|
if (code < 200 || code >= 300)
|
||||||
|
{ /* non-successful HTTP status code */
|
||||||
|
if (!this->result)
|
||||||
|
{
|
||||||
|
DBG1(DBG_LIB, "HTTP request failed with status %u", code);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
if (this->cb == fetcher_default_callback)
|
if (this->cb == fetcher_default_callback)
|
||||||
{
|
{
|
||||||
*(chunk_t*)user = chunk_empty;
|
*(chunk_t*)user = chunk_empty;
|
||||||
@ -207,6 +233,11 @@ METHOD(fetcher_t, fetch, status_t,
|
|||||||
method = L"GET";
|
method = L"GET";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->result)
|
||||||
|
{ /* zero-initialize for early failures */
|
||||||
|
*this->result = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (parse_uri(this, uri, host, countof(host), path, countof(path),
|
if (parse_uri(this, uri, host, countof(host), path, countof(path),
|
||||||
&flags, &port))
|
&flags, &port))
|
||||||
{
|
{
|
||||||
@ -291,6 +322,9 @@ METHOD(fetcher_t, set_option, bool,
|
|||||||
case FETCH_CALLBACK:
|
case FETCH_CALLBACK:
|
||||||
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:
|
||||||
/* not supported, FALL */
|
/* not supported, FALL */
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user