curl: add an option to fetch bound to a local source address
This commit is contained in:
@@ -89,6 +89,12 @@ enum fetcher_option_t {
|
|||||||
*/
|
*/
|
||||||
FETCH_CALLBACK,
|
FETCH_CALLBACK,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source IP address to bind for a fetch.
|
||||||
|
* Additional argument is a host_t*, which may be NULL.
|
||||||
|
*/
|
||||||
|
FETCH_SOURCEIP,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* end of fetching options
|
* end of fetching options
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ METHOD(fetcher_manager_t, fetch, status_t,
|
|||||||
fetcher_option_t opt;
|
fetcher_option_t opt;
|
||||||
fetcher_t *fetcher;
|
fetcher_t *fetcher;
|
||||||
bool good = TRUE;
|
bool good = TRUE;
|
||||||
|
host_t *host;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
/* check URL support of fetcher */
|
/* check URL support of fetcher */
|
||||||
@@ -112,6 +113,13 @@ METHOD(fetcher_manager_t, fetch, status_t,
|
|||||||
good = fetcher->set_option(fetcher, opt,
|
good = fetcher->set_option(fetcher, opt,
|
||||||
va_arg(args, fetcher_callback_t));
|
va_arg(args, fetcher_callback_t));
|
||||||
continue;
|
continue;
|
||||||
|
case FETCH_SOURCEIP:
|
||||||
|
host = va_arg(args, host_t*);
|
||||||
|
if (host && !host->is_anyaddr(host))
|
||||||
|
{
|
||||||
|
good = fetcher->set_option(fetcher, opt, host);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
case FETCH_END:
|
case FETCH_END:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,15 @@ 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_SOURCEIP:
|
||||||
|
{
|
||||||
|
char buf[64];
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%H", va_arg(args, host_t*));
|
||||||
|
supported = curl_easy_setopt(this->curl, CURLOPT_INTERFACE,
|
||||||
|
buf) == CURLE_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
supported = FALSE;
|
supported = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user