From e3a6ad7173d8746af0fde87a1ead69c1c7d61bfa Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Wed, 27 Dec 2023 19:12:07 +0000 Subject: Fetch/curl: expose socket open/close via fetch vtable This allows frontends to customise the behaviour of sockets. The default implementation simply maps to socket(2)/close(2). --- content/fetchers/curl.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'content/fetchers') diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index b1907448e..680e60456 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -1792,6 +1792,24 @@ fetch_curl_debug(CURL *handle, } +static curl_socket_t fetch_curl_socket_open(void *clientp, + curlsocktype purpose, struct curl_sockaddr *address) +{ + (void) clientp; + (void) purpose; + + return (curl_socket_t) guit->fetch->socket_open( + address->family, address->socktype, + address->protocol); +} + +static int fetch_curl_socket_close(void *clientp, curl_socket_t item) +{ + (void) clientp; + + return guit->fetch->socket_close((int) item); +} + /** * Callback function for cURL. */ @@ -2047,6 +2065,8 @@ nserror fetch_curl_register(void) SETOPT(CURLOPT_LOW_SPEED_TIME, 180L); SETOPT(CURLOPT_NOSIGNAL, 1L); SETOPT(CURLOPT_CONNECTTIMEOUT, nsoption_uint(curl_fetch_timeout)); + SETOPT(CURLOPT_OPENSOCKETFUNCTION, fetch_curl_socket_open); + SETOPT(CURLOPT_CLOSESOCKETFUNCTION, fetch_curl_socket_close); if (nsoption_charp(ca_bundle) && strcmp(nsoption_charp(ca_bundle), "")) { -- cgit v1.2.3