1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

hostip/proxy: remove conn->data use

Closes #6513
This commit is contained in:
Daniel Stenberg 2021-01-24 23:41:58 +01:00
parent 560fc170ec
commit 1dc8aa870e
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
10 changed files with 43 additions and 40 deletions

View File

@ -708,7 +708,7 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
return NULL; return NULL;
} }
failf(conn->data, "getaddrinfo() thread failed"); failf(data, "getaddrinfo() thread failed");
return NULL; return NULL;
} }

View File

@ -3543,7 +3543,7 @@ static CURLcode ftp_do_more(struct Curl_easy *data, int *completep)
if(Curl_connect_ongoing(conn)) { if(Curl_connect_ongoing(conn)) {
/* As we're in TUNNEL_CONNECT state now, we know the proxy name and port /* As we're in TUNNEL_CONNECT state now, we know the proxy name and port
aren't used so we blank their arguments. */ aren't used so we blank their arguments. */
result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, NULL, 0); result = Curl_proxyCONNECT(data, SECONDARYSOCKET, NULL, 0);
return result; return result;
} }
@ -3565,7 +3565,7 @@ static CURLcode ftp_do_more(struct Curl_easy *data, int *completep)
} }
#ifndef CURL_DISABLE_PROXY #ifndef CURL_DISABLE_PROXY
result = Curl_proxy_connect(conn, SECONDARYSOCKET); result = Curl_proxy_connect(data, SECONDARYSOCKET);
if(result) if(result)
return result; return result;

View File

@ -309,11 +309,10 @@ static struct Curl_dns_entry *fetch_addr(struct Curl_easy *data,
* use, or we'll leak memory! * use, or we'll leak memory!
*/ */
struct Curl_dns_entry * struct Curl_dns_entry *
Curl_fetch_addr(struct connectdata *conn, Curl_fetch_addr(struct Curl_easy *data,
const char *hostname, const char *hostname,
int port) int port)
{ {
struct Curl_easy *data = conn->data;
struct Curl_dns_entry *dns = NULL; struct Curl_dns_entry *dns = NULL;
if(data->share) if(data->share)

View File

@ -177,7 +177,7 @@ void Curl_printable_address(const struct Curl_addrinfo *ip,
* use, or we'll leak memory! * use, or we'll leak memory!
*/ */
struct Curl_dns_entry * struct Curl_dns_entry *
Curl_fetch_addr(struct connectdata *conn, Curl_fetch_addr(struct Curl_easy *data,
const char *hostname, const char *hostname,
int port); int port);

View File

@ -1433,7 +1433,7 @@ CURLcode Curl_http_connect(struct Curl_easy *data, bool *done)
#ifndef CURL_DISABLE_PROXY #ifndef CURL_DISABLE_PROXY
/* the CONNECT procedure might not have been completed */ /* the CONNECT procedure might not have been completed */
result = Curl_proxy_connect(conn, FIRSTSOCKET); result = Curl_proxy_connect(data, FIRSTSOCKET);
if(result) if(result)
return result; return result;

View File

@ -50,15 +50,16 @@
* proxy_ssl_connected connection bit when complete. Can be * proxy_ssl_connected connection bit when complete. Can be
* called multiple times. * called multiple times.
*/ */
static CURLcode https_proxy_connect(struct connectdata *conn, int sockindex) static CURLcode https_proxy_connect(struct Curl_easy *data, int sockindex)
{ {
#ifdef USE_SSL #ifdef USE_SSL
struct connectdata *conn = data->conn;
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
DEBUGASSERT(conn->http_proxy.proxytype == CURLPROXY_HTTPS); DEBUGASSERT(conn->http_proxy.proxytype == CURLPROXY_HTTPS);
if(!conn->bits.proxy_ssl_connected[sockindex]) { if(!conn->bits.proxy_ssl_connected[sockindex]) {
/* perform SSL initialization for this socket */ /* perform SSL initialization for this socket */
result = result =
Curl_ssl_connect_nonblocking(conn->data, conn, sockindex, Curl_ssl_connect_nonblocking(data, conn, sockindex,
&conn->bits.proxy_ssl_connected[sockindex]); &conn->bits.proxy_ssl_connected[sockindex]);
if(result) if(result)
/* a failed connection is marked for closure to prevent (bad) re-use or /* a failed connection is marked for closure to prevent (bad) re-use or
@ -67,17 +68,17 @@ static CURLcode https_proxy_connect(struct connectdata *conn, int sockindex)
} }
return result; return result;
#else #else
(void) conn; (void) data;
(void) sockindex; (void) sockindex;
return CURLE_NOT_BUILT_IN; return CURLE_NOT_BUILT_IN;
#endif #endif
} }
CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex) CURLcode Curl_proxy_connect(struct Curl_easy *data, int sockindex)
{ {
struct Curl_easy *data = conn->data; struct connectdata *conn = data->conn;
if(conn->http_proxy.proxytype == CURLPROXY_HTTPS) { if(conn->http_proxy.proxytype == CURLPROXY_HTTPS) {
const CURLcode result = https_proxy_connect(conn, sockindex); const CURLcode result = https_proxy_connect(data, sockindex);
if(result) if(result)
return result; return result;
if(!conn->bits.proxy_ssl_connected[sockindex]) if(!conn->bits.proxy_ssl_connected[sockindex])
@ -105,9 +106,9 @@ CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex)
* This function might be called several times in the multi interface case * This function might be called several times in the multi interface case
* if the proxy's CONNECT response is not instant. * if the proxy's CONNECT response is not instant.
*/ */
prot_save = conn->data->req.p.http; prot_save = data->req.p.http;
memset(&http_proxy, 0, sizeof(http_proxy)); memset(&http_proxy, 0, sizeof(http_proxy));
conn->data->req.p.http = &http_proxy; data->req.p.http = &http_proxy;
connkeep(conn, "HTTP proxy CONNECT"); connkeep(conn, "HTTP proxy CONNECT");
/* for the secondary socket (FTP), use the "connect to host" /* for the secondary socket (FTP), use the "connect to host"
@ -127,8 +128,8 @@ CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex)
remote_port = conn->conn_to_port; remote_port = conn->conn_to_port;
else else
remote_port = conn->remote_port; remote_port = conn->remote_port;
result = Curl_proxyCONNECT(conn, sockindex, hostname, remote_port); result = Curl_proxyCONNECT(data, sockindex, hostname, remote_port);
conn->data->req.p.http = prot_save; data->req.p.http = prot_save;
if(CURLE_OK != result) if(CURLE_OK != result)
return result; return result;
Curl_safefree(data->state.aptr.proxyuserpwd); Curl_safefree(data->state.aptr.proxyuserpwd);
@ -152,15 +153,16 @@ bool Curl_connect_ongoing(struct connectdata *conn)
(conn->connect_state->tunnel_state != TUNNEL_COMPLETE); (conn->connect_state->tunnel_state != TUNNEL_COMPLETE);
} }
static CURLcode connect_init(struct connectdata *conn, bool reinit) static CURLcode connect_init(struct Curl_easy *data, bool reinit)
{ {
struct http_connect_state *s; struct http_connect_state *s;
struct connectdata *conn = data->conn;
if(!reinit) { if(!reinit) {
DEBUGASSERT(!conn->connect_state); DEBUGASSERT(!conn->connect_state);
s = calloc(1, sizeof(struct http_connect_state)); s = calloc(1, sizeof(struct http_connect_state));
if(!s) if(!s)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
infof(conn->data, "allocate connect buffer!\n"); infof(data, "allocate connect buffer!\n");
conn->connect_state = s; conn->connect_state = s;
Curl_dyn_init(&s->rcvbuf, DYN_PROXY_CONNECT_HEADERS); Curl_dyn_init(&s->rcvbuf, DYN_PROXY_CONNECT_HEADERS);
} }
@ -176,12 +178,13 @@ static CURLcode connect_init(struct connectdata *conn, bool reinit)
return CURLE_OK; return CURLE_OK;
} }
static void connect_done(struct connectdata *conn) static void connect_done(struct Curl_easy *data)
{ {
struct connectdata *conn = data->conn;
struct http_connect_state *s = conn->connect_state; struct http_connect_state *s = conn->connect_state;
s->tunnel_state = TUNNEL_COMPLETE; s->tunnel_state = TUNNEL_COMPLETE;
Curl_dyn_free(&s->rcvbuf); Curl_dyn_free(&s->rcvbuf);
infof(conn->data, "CONNECT phase completed!\n"); infof(data, "CONNECT phase completed!\n");
} }
static CURLcode CONNECT_host(struct Curl_easy *data, static CURLcode CONNECT_host(struct Curl_easy *data,
@ -216,16 +219,16 @@ static CURLcode CONNECT_host(struct Curl_easy *data,
return CURLE_OK; return CURLE_OK;
} }
static CURLcode CONNECT(struct connectdata *conn, static CURLcode CONNECT(struct Curl_easy *data,
int sockindex, int sockindex,
const char *hostname, const char *hostname,
int remote_port) int remote_port)
#ifndef USE_HYPER #ifndef USE_HYPER
{ {
int subversion = 0; int subversion = 0;
struct Curl_easy *data = conn->data;
struct SingleRequest *k = &data->req; struct SingleRequest *k = &data->req;
CURLcode result; CURLcode result;
struct connectdata *conn = data->conn;
curl_socket_t tunnelsocket = conn->sock[sockindex]; curl_socket_t tunnelsocket = conn->sock[sockindex];
struct http_connect_state *s = conn->connect_state; struct http_connect_state *s = conn->connect_state;
char *linep; char *linep;
@ -592,7 +595,7 @@ static CURLcode CONNECT(struct connectdata *conn,
* means the HTTP authentication is still going on so if the tunnel * means the HTTP authentication is still going on so if the tunnel
* is complete we start over in INIT state */ * is complete we start over in INIT state */
if(data->req.newurl && (TUNNEL_COMPLETE == s->tunnel_state)) { if(data->req.newurl && (TUNNEL_COMPLETE == s->tunnel_state)) {
connect_init(conn, TRUE); /* reinit */ connect_init(data, TRUE); /* reinit */
} }
} while(data->req.newurl); } while(data->req.newurl);
@ -601,7 +604,7 @@ static CURLcode CONNECT(struct connectdata *conn,
if(s->close_connection && data->req.newurl) { if(s->close_connection && data->req.newurl) {
conn->bits.proxy_connect_closed = TRUE; conn->bits.proxy_connect_closed = TRUE;
infof(data, "Connect me again please\n"); infof(data, "Connect me again please\n");
connect_done(conn); connect_done(data);
} }
else { else {
free(data->req.newurl); free(data->req.newurl);
@ -646,7 +649,7 @@ static CURLcode CONNECT(struct connectdata *conn,
#else #else
/* The Hyper version of CONNECT */ /* The Hyper version of CONNECT */
{ {
struct Curl_easy *data = conn->data; struct connectdata *conn = data->conn;
struct hyptransfer *h = &data->hyp; struct hyptransfer *h = &data->hyp;
curl_socket_t tunnelsocket = conn->sock[sockindex]; curl_socket_t tunnelsocket = conn->sock[sockindex];
struct http_connect_state *s = conn->connect_state; struct http_connect_state *s = conn->connect_state;
@ -879,21 +882,22 @@ void Curl_connect_free(struct Curl_easy *data)
* this proxy. After that, the socket can be used just as a normal socket. * this proxy. After that, the socket can be used just as a normal socket.
*/ */
CURLcode Curl_proxyCONNECT(struct connectdata *conn, CURLcode Curl_proxyCONNECT(struct Curl_easy *data,
int sockindex, int sockindex,
const char *hostname, const char *hostname,
int remote_port) int remote_port)
{ {
CURLcode result; CURLcode result;
struct connectdata *conn = data->conn;
if(!conn->connect_state) { if(!conn->connect_state) {
result = connect_init(conn, FALSE); result = connect_init(data, FALSE);
if(result) if(result)
return result; return result;
} }
result = CONNECT(conn, sockindex, hostname, remote_port); result = CONNECT(data, sockindex, hostname, remote_port);
if(result || Curl_connect_complete(conn)) if(result || Curl_connect_complete(conn))
connect_done(conn); connect_done(data);
return result; return result;
} }

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -27,14 +27,14 @@
#if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
/* ftp can use this as well */ /* ftp can use this as well */
CURLcode Curl_proxyCONNECT(struct connectdata *conn, CURLcode Curl_proxyCONNECT(struct Curl_easy *data,
int tunnelsocket, int tunnelsocket,
const char *hostname, int remote_port); const char *hostname, int remote_port);
/* Default proxy timeout in milliseconds */ /* Default proxy timeout in milliseconds */
#define PROXY_TIMEOUT (3600*1000) #define PROXY_TIMEOUT (3600*1000)
CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex); CURLcode Curl_proxy_connect(struct Curl_easy *data, int sockindex);
bool Curl_connect_complete(struct connectdata *conn); bool Curl_connect_complete(struct connectdata *conn);
bool Curl_connect_ongoing(struct connectdata *conn); bool Curl_connect_ongoing(struct connectdata *conn);

View File

@ -1499,7 +1499,7 @@ static CURLcode protocol_connect(struct Curl_easy *data,
if(!conn->bits.protoconnstart) { if(!conn->bits.protoconnstart) {
#ifndef CURL_DISABLE_PROXY #ifndef CURL_DISABLE_PROXY
result = Curl_proxy_connect(conn, FIRSTSOCKET); result = Curl_proxy_connect(data, FIRSTSOCKET);
if(result) if(result)
return result; return result;
@ -1729,7 +1729,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
hostname = conn->host.name; hostname = conn->host.name;
/* check if we have the name resolved by now */ /* check if we have the name resolved by now */
dns = Curl_fetch_addr(conn, hostname, (int)conn->port); dns = Curl_fetch_addr(data, hostname, (int)conn->port);
if(dns) { if(dns) {
#ifdef CURLRES_ASYNCH #ifdef CURLRES_ASYNCH

View File

@ -188,7 +188,7 @@ static CURLcode ldap_setup_connection(struct Curl_easy *data,
status = CURLE_OUT_OF_MEMORY; status = CURLE_OUT_OF_MEMORY;
msg = url_errs[rc]; msg = url_errs[rc];
} }
failf(conn->data, "LDAP local: %s", msg); failf(data, "LDAP local: %s", msg);
return status; return status;
} }
proto = ldap_pvt_url_scheme2proto(lud->lud_scheme); proto = ldap_pvt_url_scheme2proto(lud->lud_scheme);
@ -401,7 +401,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done)
status = CURLE_OUT_OF_MEMORY; status = CURLE_OUT_OF_MEMORY;
msg = url_errs[rc]; msg = url_errs[rc];
} }
failf(conn->data, "LDAP local: %s", msg); failf(data, "LDAP local: %s", msg);
return status; return status;
} }
@ -439,7 +439,7 @@ static CURLcode ldap_done(struct Curl_easy *data, CURLcode res,
ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL); ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL);
lr->msgid = 0; lr->msgid = 0;
} }
conn->data->req.p.ldap = NULL; data->req.p.ldap = NULL;
free(lr); free(lr);
} }

View File

@ -257,7 +257,7 @@ CURLproxycode Curl_SOCKS4(const char *proxy_user,
case CONNECT_RESOLVING: case CONNECT_RESOLVING:
/* check if we have the name resolved by now */ /* check if we have the name resolved by now */
dns = Curl_fetch_addr(conn, hostname, (int)conn->port); dns = Curl_fetch_addr(data, hostname, (int)conn->port);
if(dns) { if(dns) {
#ifdef CURLRES_ASYNCH #ifdef CURLRES_ASYNCH
@ -771,7 +771,7 @@ CURLproxycode Curl_SOCKS5(const char *proxy_user,
case CONNECT_RESOLVING: case CONNECT_RESOLVING:
/* check if we have the name resolved by now */ /* check if we have the name resolved by now */
dns = Curl_fetch_addr(conn, hostname, remote_port); dns = Curl_fetch_addr(data, hostname, remote_port);
if(dns) { if(dns) {
#ifdef CURLRES_ASYNCH #ifdef CURLRES_ASYNCH