summaryrefslogtreecommitdiff
path: root/Utilities/cmcurl/lib/url.c
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/cmcurl/lib/url.c')
-rw-r--r--Utilities/cmcurl/lib/url.c219
1 files changed, 106 insertions, 113 deletions
diff --git a/Utilities/cmcurl/lib/url.c b/Utilities/cmcurl/lib/url.c
index 701f83ab3b..f159008898 100644
--- a/Utilities/cmcurl/lib/url.c
+++ b/Utilities/cmcurl/lib/url.c
@@ -127,7 +127,6 @@ bool curl_win32_idn_to_ascii(const char *in, char **out);
static void conn_free(struct connectdata *conn);
static void free_fixed_hostname(struct hostname *host);
-static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke);
static CURLcode parse_url_login(struct Curl_easy *data,
struct connectdata *conn,
char **userptr, char **passwdptr,
@@ -368,11 +367,9 @@ CURLcode Curl_close(struct Curl_easy *data)
Curl_safefree(data->state.buffer);
Curl_safefree(data->state.headerbuff);
-
+ Curl_safefree(data->state.ulbuf);
Curl_flush_cookies(data, 1);
-
Curl_digest_cleanup(data);
-
Curl_safefree(data->info.contenttype);
Curl_safefree(data->info.wouldredirect);
@@ -535,6 +532,7 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data)
set->expect_100_timeout = 1000L; /* Wait for a second by default. */
set->sep_headers = TRUE; /* separated header lists by default */
set->buffer_size = READBUFFER_SIZE;
+ set->upload_buffer_size = UPLOAD_BUFSIZE;
set->happy_eyeballs_timeout = CURL_HET_DEFAULT;
Curl_http2_init_userset(set);
@@ -734,20 +732,23 @@ static void conn_free(struct connectdata *conn)
* primary connection, like when freeing room in the connection cache or
* killing of a dead old connection.
*
+ * A connection needs an easy handle when closing down. We support this passed
+ * in separately since the connection to get closed here is often already
+ * disassociated from an easy handle.
+ *
* This function MUST NOT reset state in the Curl_easy struct if that
* isn't strictly bound to the life-time of *this* particular connection.
*
*/
-CURLcode Curl_disconnect(struct connectdata *conn, bool dead_connection)
+CURLcode Curl_disconnect(struct Curl_easy *data,
+ struct connectdata *conn, bool dead_connection)
{
- struct Curl_easy *data;
if(!conn)
return CURLE_OK; /* this is closed and fine already */
- data = conn->data;
if(!data) {
- DEBUGF(fprintf(stderr, "DISCONNECT without easy handle, ignoring\n"));
+ DEBUGF(infof(data, "DISCONNECT without easy handle, ignoring\n"));
return CURLE_OK;
}
@@ -755,13 +756,12 @@ CURLcode Curl_disconnect(struct connectdata *conn, bool dead_connection)
* If this connection isn't marked to force-close, leave it open if there
* are other users of it
*/
- if(!conn->bits.close &&
- (conn->send_pipe.size + conn->recv_pipe.size)) {
- DEBUGF(infof(data, "Curl_disconnect, usecounter: %d\n",
- conn->send_pipe.size + conn->recv_pipe.size));
+ if(CONN_INUSE(conn) && !dead_connection) {
+ DEBUGF(infof(data, "Curl_disconnect when inuse: %zu\n", CONN_INUSE(conn)));
return CURLE_OK;
}
+ conn->data = data;
if(conn->dns_entry != NULL) {
Curl_resolv_unlock(data, conn->dns_entry);
conn->dns_entry = NULL;
@@ -787,16 +787,12 @@ CURLcode Curl_disconnect(struct connectdata *conn, bool dead_connection)
free_fixed_hostname(&conn->http_proxy.host);
free_fixed_hostname(&conn->socks_proxy.host);
+ DEBUGASSERT(conn->data == data);
+ /* this assumes that the pointer is still there after the connection was
+ detected from the cache */
Curl_ssl_close(conn, FIRSTSOCKET);
- /* Indicate to all handles on the pipe that we're dead */
- if(Curl_pipeline_wanted(data->multi, CURLPIPE_ANY)) {
- signalPipeClose(&conn->send_pipe, TRUE);
- signalPipeClose(&conn->recv_pipe, TRUE);
- }
-
conn_free(conn);
-
return CURLE_OK;
}
@@ -848,6 +844,7 @@ static int IsPipeliningPossible(const struct Curl_easy *handle,
return avail;
}
+/* Returns non-zero if a handle was removed */
int Curl_removeHandleFromPipeline(struct Curl_easy *handle,
struct curl_llist *pipeline)
{
@@ -884,6 +881,16 @@ static void Curl_printPipeline(struct curl_llist *pipeline)
static struct Curl_easy* gethandleathead(struct curl_llist *pipeline)
{
struct curl_llist_element *curr = pipeline->head;
+#ifdef DEBUGBUILD
+ {
+ struct curl_llist_element *p = pipeline->head;
+ while(p) {
+ struct Curl_easy *e = p->ptr;
+ DEBUGASSERT(GOOD_EASY_HANDLE(e));
+ p = p->next;
+ }
+ }
+#endif
if(curr) {
return (struct Curl_easy *) curr->ptr;
}
@@ -896,41 +903,22 @@ static struct Curl_easy* gethandleathead(struct curl_llist *pipeline)
void Curl_getoff_all_pipelines(struct Curl_easy *data,
struct connectdata *conn)
{
- bool recv_head = (conn->readchannel_inuse &&
- Curl_recvpipe_head(data, conn));
- bool send_head = (conn->writechannel_inuse &&
- Curl_sendpipe_head(data, conn));
-
- if(Curl_removeHandleFromPipeline(data, &conn->recv_pipe) && recv_head)
- Curl_pipeline_leave_read(conn);
- if(Curl_removeHandleFromPipeline(data, &conn->send_pipe) && send_head)
- Curl_pipeline_leave_write(conn);
-}
-
-static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke)
-{
- struct curl_llist_element *curr;
-
- if(!pipeline)
+ if(!conn->bundle)
return;
+ if(conn->bundle->multiuse == BUNDLE_PIPELINING) {
+ bool recv_head = (conn->readchannel_inuse &&
+ Curl_recvpipe_head(data, conn));
+ bool send_head = (conn->writechannel_inuse &&
+ Curl_sendpipe_head(data, conn));
- curr = pipeline->head;
- while(curr) {
- struct curl_llist_element *next = curr->next;
- struct Curl_easy *data = (struct Curl_easy *) curr->ptr;
-
-#ifdef DEBUGBUILD /* debug-only code */
- if(data->magic != CURLEASY_MAGIC_NUMBER) {
- /* MAJOR BADNESS */
- infof(data, "signalPipeClose() found BAAD easy handle\n");
- }
-#endif
-
- if(pipe_broke)
- data->state.pipe_broke = TRUE;
- Curl_multi_handlePipeBreak(data);
- Curl_llist_remove(pipeline, curr, NULL);
- curr = next;
+ if(Curl_removeHandleFromPipeline(data, &conn->recv_pipe) && recv_head)
+ Curl_pipeline_leave_read(conn);
+ if(Curl_removeHandleFromPipeline(data, &conn->send_pipe) && send_head)
+ Curl_pipeline_leave_write(conn);
+ }
+ else {
+ (void)Curl_removeHandleFromPipeline(data, &conn->recv_pipe);
+ (void)Curl_removeHandleFromPipeline(data, &conn->send_pipe);
}
}
@@ -959,12 +947,13 @@ static bool extract_if_dead(struct connectdata *conn,
struct Curl_easy *data)
{
size_t pipeLen = conn->send_pipe.size + conn->recv_pipe.size;
- if(!pipeLen && !conn->inuse) {
+ if(!pipeLen && !CONN_INUSE(conn)) {
/* The check for a dead socket makes sense only if there are no
handles in pipeline and the connection isn't already marked in
use */
bool dead;
+ conn->data = data;
if(conn->handler->connection_check) {
/* The protocol has a special method for checking the state of the
connection. Use it to check if the connection is dead. */
@@ -979,9 +968,9 @@ static bool extract_if_dead(struct connectdata *conn,
}
if(dead) {
- conn->data = data;
infof(data, "Connection %ld seems to be dead!\n", conn->connection_id);
Curl_conncache_remove_conn(conn, FALSE);
+ conn->data = NULL; /* detach */
return TRUE;
}
}
@@ -1025,7 +1014,7 @@ static void prune_dead_connections(struct Curl_easy *data)
while(Curl_conncache_foreach(data, data->state.conn_cache, &prune,
call_extract_if_dead)) {
/* disconnect it */
- (void)Curl_disconnect(prune.extracted, /* dead_connection */TRUE);
+ (void)Curl_disconnect(data, prune.extracted, /* dead_connection */TRUE);
}
data->state.conn_cache->last_cleanup = now;
}
@@ -1139,7 +1128,7 @@ ConnectionExists(struct Curl_easy *data,
if(extract_if_dead(check, data)) {
/* disconnect it */
- (void)Curl_disconnect(check, /* dead_connection */TRUE);
+ (void)Curl_disconnect(data, check, /* dead_connection */TRUE);
continue;
}
@@ -1267,12 +1256,12 @@ ConnectionExists(struct Curl_easy *data,
}
}
- if(!canpipe && check->inuse)
+ if(!canpipe && CONN_INUSE(check))
/* this request can't be pipelined but the checked connection is
already in use so we skip it */
continue;
- if((check->inuse) && (check->data->multi != needle->data->multi))
+ if(CONN_INUSE(check) && (check->data->multi != needle->data->multi))
/* this could be subject for pipeline/multiplex use, but only
if they belong to the same multi handle */
continue;
@@ -1464,7 +1453,7 @@ ConnectionExists(struct Curl_easy *data,
if(chosen) {
/* mark it as used before releasing the lock */
- chosen->inuse = TRUE;
+ chosen->data = data; /* own it! */
Curl_conncache_unlock(needle);
*usethis = chosen;
return TRUE; /* yes, we found one to use! */
@@ -1554,7 +1543,11 @@ int Curl_protocol_getsock(struct connectdata *conn,
{
if(conn->handler->proto_getsock)
return conn->handler->proto_getsock(conn, socks, numsocks);
- return GETSOCK_BLANK;
+ /* Backup getsock logic. Since there is a live socket in use, we must wait
+ for it or it will be removed from watching when the multi_socket API is
+ used. */
+ socks[0] = conn->sock[FIRSTSOCKET];
+ return GETSOCK_READSOCK(0) | GETSOCK_WRITESOCK(0);
}
int Curl_doing_getsock(struct connectdata *conn,
@@ -1999,7 +1992,6 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
char *fragment;
char *path = data->state.path;
char *query;
- int i;
int rc;
const char *protop = "";
CURLcode result;
@@ -2051,6 +2043,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
; /* do nothing */
}
else { /* check for a scheme */
+ int i;
for(i = 0; i < 16 && data->change.url[i]; ++i) {
if(data->change.url[i] == '/')
break;
@@ -2203,7 +2196,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
size_t s = strlen(slashbuf);
protop = protobuf;
if(s != 2) {
- infof(data, "Unwillingly accepted illegal URL using %d slash%s!\n",
+ infof(data, "Unwillingly accepted illegal URL using %zu slash%s!\n",
s, s>1?"es":"");
if(data->change.url_alloc)
@@ -2449,7 +2442,7 @@ static CURLcode setup_range(struct Curl_easy *data)
free(s->range);
if(s->resume_from)
- s->range = aprintf("%" CURL_FORMAT_CURL_OFF_TU "-", s->resume_from);
+ s->range = aprintf("%" CURL_FORMAT_CURL_OFF_T "-", s->resume_from);
else
s->range = strdup(data->set.str[STRING_SET_RANGE]);
@@ -2481,18 +2474,6 @@ static CURLcode setup_connection_internals(struct connectdata *conn)
{
const struct Curl_handler * p;
CURLcode result;
- struct Curl_easy *data = conn->data;
-
- /* in some case in the multi state-machine, we go back to the CONNECT state
- and then a second (or third or...) call to this function will be made
- without doing a DISCONNECT or DONE in between (since the connection is
- yet in place) and therefore this function needs to first make sure
- there's no lingering previous data allocated. */
- Curl_free_request_state(data);
-
- memset(&data->req, 0, sizeof(struct SingleRequest));
- data->req.maxdownload = -1;
-
conn->socktype = SOCK_STREAM; /* most of them are TCP streams */
/* Perform setup complement if some. */
@@ -2539,14 +2520,13 @@ static bool check_noproxy(const char *name, const char *no_proxy)
* not be proxied, or an asterisk to override
* all proxy variables)
*/
- size_t tok_start;
- size_t tok_end;
- const char *separator = ", ";
- size_t no_proxy_len;
- size_t namelen;
- char *endptr;
-
if(no_proxy && no_proxy[0]) {
+ size_t tok_start;
+ size_t tok_end;
+ const char *separator = ", ";
+ size_t no_proxy_len;
+ size_t namelen;
+ char *endptr;
if(strcasecompare("*", no_proxy)) {
return TRUE;
}
@@ -3166,6 +3146,13 @@ static CURLcode parse_url_login(struct Curl_easy *data,
if(userp) {
char *newname;
+ if(data->set.disallow_username_in_url) {
+ failf(data, "Option DISALLOW_USERNAME_IN_URL is set "
+ "and url contains username.");
+ result = CURLE_LOGIN_DENIED;
+ goto out;
+ }
+
/* We have a user in the URL */
conn->bits.userpwd_in_url = TRUE;
conn->bits.user_passwd = TRUE; /* enable user+password */
@@ -3982,6 +3969,7 @@ static void reuse_conn(struct connectdata *old_conn,
Curl_safefree(old_conn->user);
Curl_safefree(old_conn->passwd);
+ Curl_safefree(old_conn->options);
Curl_safefree(old_conn->http_proxy.user);
Curl_safefree(old_conn->socks_proxy.user);
Curl_safefree(old_conn->http_proxy.passwd);
@@ -4297,7 +4285,9 @@ static CURLcode create_conn(struct Curl_easy *data,
conn->data = data;
conn->bits.tcpconnect[FIRSTSOCKET] = TRUE; /* we are "connected */
- Curl_conncache_add_conn(data->state.conn_cache, conn);
+ result = Curl_conncache_add_conn(data->state.conn_cache, conn);
+ if(result)
+ goto out;
/*
* Setup whatever necessary for a resumed transfer
@@ -4343,6 +4333,10 @@ static CURLcode create_conn(struct Curl_easy *data,
data->set.str[STRING_SSL_CIPHER_LIST_ORIG];
data->set.proxy_ssl.primary.cipher_list =
data->set.str[STRING_SSL_CIPHER_LIST_PROXY];
+ data->set.ssl.primary.cipher_list13 =
+ data->set.str[STRING_SSL_CIPHER13_LIST_ORIG];
+ data->set.proxy_ssl.primary.cipher_list13 =
+ data->set.str[STRING_SSL_CIPHER13_LIST_PROXY];
data->set.ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_ORIG];
data->set.proxy_ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_PROXY];
@@ -4468,13 +4462,11 @@ static CURLcode create_conn(struct Curl_easy *data,
conn_candidate = Curl_conncache_extract_bundle(data, bundle);
Curl_conncache_unlock(conn);
- if(conn_candidate) {
- /* Set the connection's owner correctly, then kill it */
- conn_candidate->data = data;
- (void)Curl_disconnect(conn_candidate, /* dead_connection */ FALSE);
- }
+ if(conn_candidate)
+ (void)Curl_disconnect(data, conn_candidate,
+ /* dead_connection */ FALSE);
else {
- infof(data, "No more connections allowed to host: %d\n",
+ infof(data, "No more connections allowed to host: %zu\n",
max_host_connections);
connections_available = FALSE;
}
@@ -4491,12 +4483,9 @@ static CURLcode create_conn(struct Curl_easy *data,
/* The cache is full. Let's see if we can kill a connection. */
conn_candidate = Curl_conncache_extract_oldest(data);
-
- if(conn_candidate) {
- /* Set the connection's owner correctly, then kill it */
- conn_candidate->data = data;
- (void)Curl_disconnect(conn_candidate, /* dead_connection */ FALSE);
- }
+ if(conn_candidate)
+ (void)Curl_disconnect(data, conn_candidate,
+ /* dead_connection */ FALSE);
else {
infof(data, "No connections available in cache\n");
connections_available = FALSE;
@@ -4513,14 +4502,13 @@ static CURLcode create_conn(struct Curl_easy *data,
goto out;
}
else {
- /* Mark the connection as used, before we add it */
- conn->inuse = TRUE;
-
/*
* This is a brand new connection, so let's store it in the connection
* cache of ours!
*/
- Curl_conncache_add_conn(data->state.conn_cache, conn);
+ result = Curl_conncache_add_conn(data->state.conn_cache, conn);
+ if(result)
+ goto out;
}
#if defined(USE_NTLM)
@@ -4656,12 +4644,16 @@ CURLcode Curl_connect(struct Curl_easy *data,
*asyncp = FALSE; /* assume synchronous resolves by default */
+ /* init the single-transfer specific data */
+ Curl_free_request_state(data);
+ memset(&data->req, 0, sizeof(struct SingleRequest));
+ data->req.maxdownload = -1;
+
/* call the stuff that needs to be called */
result = create_conn(data, in_connect, asyncp);
if(!result) {
- /* no error */
- if((*in_connect)->send_pipe.size || (*in_connect)->recv_pipe.size)
+ if(CONN_INUSE(*in_connect))
/* pipelining */
*protocol_done = TRUE;
else if(!*asyncp) {
@@ -4676,12 +4668,11 @@ CURLcode Curl_connect(struct Curl_easy *data,
*in_connect = NULL;
return result;
}
-
- if(result && *in_connect) {
- /* We're not allowed to return failure with memory left allocated
- in the connectdata struct, free those here */
- Curl_disconnect(*in_connect, FALSE); /* close the connection */
- *in_connect = NULL; /* return a NULL */
+ else if(result && *in_connect) {
+ /* We're not allowed to return failure with memory left allocated in the
+ connectdata struct, free those here */
+ Curl_disconnect(data, *in_connect, TRUE);
+ *in_connect = NULL; /* return a NULL */
}
return result;
@@ -4701,16 +4692,18 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn)
{
struct SingleRequest *k = &data->req;
- conn->bits.do_more = FALSE; /* by default there's no curl_do_more() to
- use */
+ if(conn) {
+ conn->bits.do_more = FALSE; /* by default there's no curl_do_more() to
+ use */
+ /* if the protocol used doesn't support wildcards, switch it off */
+ if(data->state.wildcardmatch &&
+ !(conn->handler->flags & PROTOPT_WILDCARD))
+ data->state.wildcardmatch = FALSE;
+ }
data->state.done = FALSE; /* *_done() is not called yet */
data->state.expect100header = FALSE;
- /* if the protocol used doesn't support wildcards, switch it off */
- if(data->state.wildcardmatch &&
- !(conn->handler->flags & PROTOPT_WILDCARD))
- data->state.wildcardmatch = FALSE;
if(data->set.opt_no_body)
/* in HTTP lingo, no body means using the HEAD request... */