Skip to content

Commit

Permalink
lib: more conn->data cleanups
Browse files Browse the repository at this point in the history
Closes curl#6479
  • Loading branch information
bagder committed Jan 19, 2021
1 parent bbe3aa9 commit a304051
Show file tree
Hide file tree
Showing 30 changed files with 572 additions and 574 deletions.
2 changes: 1 addition & 1 deletion lib/asyn-ares.c
Expand Up @@ -463,7 +463,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
if(result || conn->async.done)
break;

if(Curl_pgrsUpdate(conn))
if(Curl_pgrsUpdate(data))
result = CURLE_ABORTED_BY_CALLBACK;
else {
struct curltime now2 = Curl_now();
Expand Down
4 changes: 2 additions & 2 deletions lib/c-hyper.c
Expand Up @@ -144,7 +144,7 @@ static int hyper_each_header(void *userdata,

Curl_debug(data, CURLINFO_HEADER_IN, headp, len);

result = Curl_client_write(data->conn, CLIENTWRITE_HEADER, headp, len);
result = Curl_client_write(data, CLIENTWRITE_HEADER, headp, len);
if(result) {
data->state.hresult = CURLE_ABORTED_BY_CALLBACK;
return HYPER_ITER_BREAK;
Expand Down Expand Up @@ -175,7 +175,7 @@ static int hyper_body_chunk(void *userdata, const hyper_buf *chunk)
if(k->ignorebody)
return HYPER_ITER_CONTINUE;
Curl_debug(data, CURLINFO_DATA_IN, buf, len);
result = Curl_client_write(data->conn, CLIENTWRITE_BODY, buf, len);
result = Curl_client_write(data, CLIENTWRITE_BODY, buf, len);

if(result) {
data->state.hresult = result;
Expand Down
36 changes: 19 additions & 17 deletions lib/conncache.c
Expand Up @@ -179,12 +179,14 @@ size_t Curl_conncache_size(struct Curl_easy *data)
connectdata struct is setup to use.
**NOTE**: When it returns, it holds the connection cache lock! */
struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
struct conncache *connc,
const char **hostp)
struct connectbundle *
Curl_conncache_find_bundle(struct Curl_easy *data,
struct connectdata *conn,
struct conncache *connc,
const char **hostp)
{
struct connectbundle *bundle = NULL;
CONNCACHE_LOCK(conn->data);
CONNCACHE_LOCK(data);
if(connc) {
char key[HASHKEY_SIZE];
hashkey(conn, key, sizeof(key), hostp);
Expand Down Expand Up @@ -227,15 +229,17 @@ static void conncache_remove_bundle(struct conncache *connc,
}
}

CURLcode Curl_conncache_add_conn(struct conncache *connc,
struct connectdata *conn)
CURLcode Curl_conncache_add_conn(struct Curl_easy *data)
{
CURLcode result = CURLE_OK;
struct connectbundle *bundle = NULL;
struct Curl_easy *data = conn->data;
struct connectdata *conn = data->conn;
struct conncache *connc = data->state.conn_cache;
DEBUGASSERT(conn);

/* *find_bundle() locks the connection cache */
bundle = Curl_conncache_find_bundle(conn, data->state.conn_cache, NULL);
bundle = Curl_conncache_find_bundle(data, conn, data->state.conn_cache,
NULL);
if(!bundle) {
int rc;
char key[HASHKEY_SIZE];
Expand All @@ -259,7 +263,7 @@ CURLcode Curl_conncache_add_conn(struct conncache *connc,
conn->connection_id = connc->next_connection_id++;
connc->num_conn++;

DEBUGF(infof(conn->data, "Added connection %ld. "
DEBUGF(infof(data, "Added connection %ld. "
"The cache now contains %zu members\n",
conn->connection_id, connc->num_conn));

Expand All @@ -270,8 +274,8 @@ CURLcode Curl_conncache_add_conn(struct conncache *connc,
}

/*
* Removes the connectdata object from the connection cache, but does *not*
* clear the conn->data association. The transfer still owns this connection.
* Removes the connectdata object from the connection cache, but the transfer
* still owns this connection.
*
* Pass TRUE/FALSE in the 'lock' argument depending on if the parent function
* already holds the lock or not.
Expand Down Expand Up @@ -445,7 +449,7 @@ Curl_conncache_extract_bundle(struct Curl_easy *data,
while(curr) {
conn = curr->ptr;

if(!CONN_INUSE(conn) && !conn->data) {
if(!CONN_INUSE(conn)) {
/* Set higher score for the age passed since the connection was used */
score = Curl_timediff(now, conn->lastused);

Expand Down Expand Up @@ -503,7 +507,7 @@ Curl_conncache_extract_oldest(struct Curl_easy *data)
while(curr) {
conn = curr->ptr;

if(!CONN_INUSE(conn) && !conn->data && !conn->bits.close &&
if(!CONN_INUSE(conn) && !conn->bits.close &&
!conn->bits.connect_only) {
/* Set higher score for the age passed since the connection was used */
score = Curl_timediff(now, conn->lastused);
Expand Down Expand Up @@ -544,12 +548,10 @@ void Curl_conncache_close_all_connections(struct conncache *connc)
conn = conncache_find_first_connection(connc);
while(conn) {
SIGPIPE_VARIABLE(pipe_st);
conn->data = connc->closure_handle;

sigpipe_ignore(conn->data, &pipe_st);
sigpipe_ignore(connc->closure_handle, &pipe_st);
/* This will remove the connection from the cache */
connclose(conn, "kill all");
Curl_conncache_remove_conn(conn->data, conn, TRUE);
Curl_conncache_remove_conn(connc->closure_handle, conn, TRUE);
(void)Curl_disconnect(connc->closure_handle, conn, FALSE);
sigpipe_restore(&pipe_st);

Expand Down
6 changes: 3 additions & 3 deletions lib/conncache.h
Expand Up @@ -85,16 +85,16 @@ int Curl_conncache_init(struct conncache *, int size);
void Curl_conncache_destroy(struct conncache *connc);

/* return the correct bundle, to a host or a proxy */
struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
struct connectbundle *Curl_conncache_find_bundle(struct Curl_easy *data,
struct connectdata *conn,
struct conncache *connc,
const char **hostp);
/* returns number of connections currently held in the connection cache */
size_t Curl_conncache_size(struct Curl_easy *data);

bool Curl_conncache_return_conn(struct Curl_easy *data,
struct connectdata *conn);
CURLcode Curl_conncache_add_conn(struct conncache *connc,
struct connectdata *conn) WARN_UNUSED_RESULT;
CURLcode Curl_conncache_add_conn(struct Curl_easy *data) WARN_UNUSED_RESULT;
void Curl_conncache_remove_conn(struct Curl_easy *data,
struct connectdata *conn,
bool lock);
Expand Down
4 changes: 2 additions & 2 deletions lib/connect.c
Expand Up @@ -788,13 +788,13 @@ static CURLcode connect_SOCKS(struct Curl_easy *data, int sockindex,
case CURLPROXY_SOCKS5:
case CURLPROXY_SOCKS5_HOSTNAME:
pxresult = Curl_SOCKS5(conn->socks_proxy.user, conn->socks_proxy.passwd,
host, port, sockindex, conn, done);
host, port, sockindex, data, done);
break;

case CURLPROXY_SOCKS4:
case CURLPROXY_SOCKS4A:
pxresult = Curl_SOCKS4(conn->socks_proxy.user, host, port, sockindex,
conn, done);
data, done);
break;

default:
Expand Down
8 changes: 4 additions & 4 deletions lib/file.c
Expand Up @@ -338,12 +338,12 @@ static CURLcode file_upload(struct Curl_easy *data)

Curl_pgrsSetUploadCounter(data, bytecount);

if(Curl_pgrsUpdate(data->conn))
if(Curl_pgrsUpdate(data))
result = CURLE_ABORTED_BY_CALLBACK;
else
result = Curl_speedcheck(data, Curl_now());
}
if(!result && Curl_pgrsUpdate(data->conn))
if(!result && Curl_pgrsUpdate(data))
result = CURLE_ABORTED_BY_CALLBACK;

close(fd);
Expand Down Expand Up @@ -527,12 +527,12 @@ static CURLcode file_do(struct Curl_easy *data, bool *done)

Curl_pgrsSetDownloadCounter(data, bytecount);

if(Curl_pgrsUpdate(conn))
if(Curl_pgrsUpdate(data))
result = CURLE_ABORTED_BY_CALLBACK;
else
result = Curl_speedcheck(data, Curl_now());
}
if(Curl_pgrsUpdate(conn))
if(Curl_pgrsUpdate(data))
result = CURLE_ABORTED_BY_CALLBACK;

return result;
Expand Down
4 changes: 2 additions & 2 deletions lib/ftp.c
Expand Up @@ -678,7 +678,7 @@ CURLcode Curl_GetFTPResponse(struct Curl_easy *data,
return CURLE_RECV_ERROR;

case 0: /* timeout */
if(Curl_pgrsUpdate(conn))
if(Curl_pgrsUpdate(data))
return CURLE_ABORTED_BY_CALLBACK;
continue; /* just continue in our loop for the timeout duration */

Expand Down Expand Up @@ -2656,7 +2656,7 @@ static CURLcode ftp_statemachine(struct Curl_easy *data,
size_t nread = 0;

if(pp->sendleft)
return Curl_pp_flushsend(pp);
return Curl_pp_flushsend(data, pp);

result = ftp_readresp(data, sock, pp, &ftpcode, &nread);
if(result)
Expand Down
6 changes: 3 additions & 3 deletions lib/http.c
Expand Up @@ -690,7 +690,7 @@ output_auth_headers(struct Curl_easy *data,
#ifdef USE_NTLM
if(authstatus->picked == CURLAUTH_NTLM) {
auth = "NTLM";
result = Curl_output_ntlm(conn, proxy);
result = Curl_output_ntlm(data, proxy);
if(result)
return result;
}
Expand Down Expand Up @@ -966,7 +966,7 @@ CURLcode Curl_http_input_auth(struct Curl_easy *data, bool proxy,
if(authp->picked == CURLAUTH_NTLM ||
authp->picked == CURLAUTH_NTLM_WB) {
/* NTLM authentication is picked and activated */
CURLcode result = Curl_input_ntlm(conn, proxy, auth);
CURLcode result = Curl_input_ntlm(data, proxy, auth);
if(!result) {
data->state.authproblem = FALSE;
#ifdef NTLM_WB_ENABLED
Expand Down Expand Up @@ -3184,7 +3184,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
/* if a request-body has been sent off, we make sure this progress is noted
properly */
Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
if(Curl_pgrsUpdate(conn))
if(Curl_pgrsUpdate(data))
result = CURLE_ABORTED_BY_CALLBACK;

if(!http->postsize) {
Expand Down
34 changes: 17 additions & 17 deletions lib/http_ntlm.c
Expand Up @@ -5,7 +5,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
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -59,7 +59,7 @@
# define DEBUG_OUT(x) Curl_nop_stmt
#endif

CURLcode Curl_input_ntlm(struct connectdata *conn,
CURLcode Curl_input_ntlm(struct Curl_easy *data,
bool proxy, /* if proxy or not */
const char *header) /* rest of the www-authenticate:
header */
Expand All @@ -68,6 +68,7 @@ CURLcode Curl_input_ntlm(struct connectdata *conn,
struct ntlmdata *ntlm;
curlntlm *state;
CURLcode result = CURLE_OK;
struct connectdata *conn = data->conn;

ntlm = proxy ? &conn->proxyntlm : &conn->ntlm;
state = proxy ? &conn->proxy_ntlm_state : &conn->http_ntlm_state;
Expand All @@ -79,25 +80,25 @@ CURLcode Curl_input_ntlm(struct connectdata *conn,
header++;

if(*header) {
result = Curl_auth_decode_ntlm_type2_message(conn->data, header, ntlm);
result = Curl_auth_decode_ntlm_type2_message(data, header, ntlm);
if(result)
return result;

*state = NTLMSTATE_TYPE2; /* We got a type-2 message */
}
else {
if(*state == NTLMSTATE_LAST) {
infof(conn->data, "NTLM auth restarted\n");
infof(data, "NTLM auth restarted\n");
Curl_http_auth_cleanup_ntlm(conn);
}
else if(*state == NTLMSTATE_TYPE3) {
infof(conn->data, "NTLM handshake rejected\n");
infof(data, "NTLM handshake rejected\n");
Curl_http_auth_cleanup_ntlm(conn);
*state = NTLMSTATE_NONE;
return CURLE_REMOTE_ACCESS_DENIED;
}
else if(*state >= NTLMSTATE_TYPE1) {
infof(conn->data, "NTLM handshake failure (internal error)\n");
infof(data, "NTLM handshake failure (internal error)\n");
return CURLE_REMOTE_ACCESS_DENIED;
}

Expand All @@ -111,7 +112,7 @@ CURLcode Curl_input_ntlm(struct connectdata *conn,
/*
* This is for creating ntlm header output
*/
CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy)
{
char *base64 = NULL;
size_t len = 0;
Expand All @@ -131,8 +132,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
struct ntlmdata *ntlm;
curlntlm *state;
struct auth *authp;
struct Curl_easy *data = conn->data;

struct connectdata *conn = data->conn;

DEBUGASSERT(conn);
DEBUGASSERT(data);
Expand All @@ -142,12 +142,12 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
allocuserpwd = &data->state.aptr.proxyuserpwd;
userp = conn->http_proxy.user;
passwdp = conn->http_proxy.passwd;
service = conn->data->set.str[STRING_PROXY_SERVICE_NAME] ?
conn->data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP";
service = data->set.str[STRING_PROXY_SERVICE_NAME] ?
data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP";
hostname = conn->http_proxy.host.name;
ntlm = &conn->proxyntlm;
state = &conn->proxy_ntlm_state;
authp = &conn->data->state.authproxy;
authp = &data->state.authproxy;
#else
return CURLE_NOT_BUILT_IN;
#endif
Expand All @@ -156,12 +156,12 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
allocuserpwd = &data->state.aptr.userpwd;
userp = conn->user;
passwdp = conn->passwd;
service = conn->data->set.str[STRING_SERVICE_NAME] ?
conn->data->set.str[STRING_SERVICE_NAME] : "HTTP";
service = data->set.str[STRING_SERVICE_NAME] ?
data->set.str[STRING_SERVICE_NAME] : "HTTP";
hostname = conn->host.name;
ntlm = &conn->ntlm;
state = &conn->http_ntlm_state;
authp = &conn->data->state.authhost;
authp = &data->state.authhost;
}
authp->done = FALSE;

Expand All @@ -188,7 +188,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
case NTLMSTATE_TYPE1:
default: /* for the weird cases we (re)start here */
/* Create a type-1 message */
result = Curl_auth_create_ntlm_type1_message(conn->data, userp, passwdp,
result = Curl_auth_create_ntlm_type1_message(data, userp, passwdp,
service, hostname,
ntlm, &base64,
&len);
Expand All @@ -210,7 +210,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)

case NTLMSTATE_TYPE2:
/* We already received the type-2 message, create a type-3 message */
result = Curl_auth_create_ntlm_type3_message(conn->data, userp, passwdp,
result = Curl_auth_create_ntlm_type3_message(data, userp, passwdp,
ntlm, &base64, &len);
if(result)
return result;
Expand Down
6 changes: 3 additions & 3 deletions lib/http_ntlm.h
Expand Up @@ -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
* you should have received as part of this distribution. The terms
Expand All @@ -27,11 +27,11 @@
#if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM)

/* this is for ntlm header input */
CURLcode Curl_input_ntlm(struct connectdata *conn, bool proxy,
CURLcode Curl_input_ntlm(struct Curl_easy *data, bool proxy,
const char *header);

/* this is for creating ntlm header output */
CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy);
CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy);

void Curl_http_auth_cleanup_ntlm(struct connectdata *conn);

Expand Down
4 changes: 2 additions & 2 deletions lib/http_proxy.c
Expand Up @@ -347,7 +347,7 @@ static CURLcode CONNECT(struct connectdata *conn,
/* socket buffer drained, return */
return CURLE_OK;

if(Curl_pgrsUpdate(conn))
if(Curl_pgrsUpdate(data))
return CURLE_ABORTED_BY_CALLBACK;

if(result) {
Expand Down Expand Up @@ -560,7 +560,7 @@ static CURLcode CONNECT(struct connectdata *conn,
Curl_dyn_reset(&s->rcvbuf);
} /* while there's buffer left and loop is requested */

if(Curl_pgrsUpdate(conn))
if(Curl_pgrsUpdate(data))
return CURLE_ABORTED_BY_CALLBACK;

if(error)
Expand Down

0 comments on commit a304051

Please sign in to comment.