aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/url.c
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.ru>2022-04-23 01:34:18 +0300
committerrobot-contrib <robot-contrib@yandex-team.ru>2022-04-23 01:34:18 +0300
commit70d823f7ee62199b67f5fbe469005124ffe1fe93 (patch)
tree82277ba9117d43c5a5f973825b38a2ffe7d95818 /contrib/libs/curl/lib/url.c
parent19b525690e0c7788c39d741ea94023b64ae31a89 (diff)
downloadydb-70d823f7ee62199b67f5fbe469005124ffe1fe93.tar.gz
Update contrib/libs/curl to 7.82.0
ref:0a102f02466c720a2ee37f41ed197348e7b727bd
Diffstat (limited to 'contrib/libs/curl/lib/url.c')
-rw-r--r--contrib/libs/curl/lib/url.c204
1 files changed, 101 insertions, 103 deletions
diff --git a/contrib/libs/curl/lib/url.c b/contrib/libs/curl/lib/url.c
index 3fdf02d8ec..75f43db3d8 100644
--- a/contrib/libs/curl/lib/url.c
+++ b/contrib/libs/curl/lib/url.c
@@ -99,7 +99,6 @@ bool curl_win32_idn_to_ascii(const char *in, char **out);
#include "easyif.h"
#include "speedcheck.h"
#include "warnless.h"
-#include "non-ascii.h"
#include "getinfo.h"
#include "urlapi-int.h"
#include "system_win32.h"
@@ -137,15 +136,6 @@ bool curl_win32_idn_to_ascii(const char *in, char **out);
#include "curl_memory.h"
#include "memdebug.h"
-/* Count of the backend ssl objects to allocate */
-#ifdef USE_SSL
-# ifndef CURL_DISABLE_PROXY
-# define SSL_BACKEND_CNT 4
-# else
-# define SSL_BACKEND_CNT 2
-# endif
-#endif
-
static void conn_free(struct connectdata *conn);
/* Some parts of the code (e.g. chunked encoding) assume this buffer has at
@@ -445,7 +435,6 @@ CURLcode Curl_close(struct Curl_easy **datap)
Curl_resolver_cleanup(data->state.async.resolver);
Curl_http2_cleanup_dependencies(data);
- Curl_convert_close(data);
/* No longer a dirty share, if it exists */
if(data->share) {
@@ -509,11 +498,6 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data)
set->seek_func = ZERO_NULL;
set->seek_client = ZERO_NULL;
- /* conversion callbacks for non-ASCII hosts */
- set->convfromnetwork = ZERO_NULL;
- set->convtonetwork = ZERO_NULL;
- set->convfromutf8 = ZERO_NULL;
-
set->filesize = -1; /* we don't know the size */
set->postfieldsize = -1; /* unknown size */
set->maxredirs = -1; /* allow any amount by default */
@@ -677,7 +661,6 @@ CURLcode Curl_open(struct Curl_easy **curl)
result = Curl_init_userdefined(data);
if(!result) {
Curl_dyn_init(&data->state.headerb, CURL_MAX_HTTP_HEADER);
- Curl_convert_init(data);
Curl_initinfo(data);
/* most recent connection is not yet defined */
@@ -760,7 +743,9 @@ static void conn_shutdown(struct Curl_easy *data, struct connectdata *conn)
/* close the SSL stuff before we close any sockets since they will/may
write to the sockets */
Curl_ssl_close(data, conn, FIRSTSOCKET);
+#ifndef CURL_DISABLE_FTP
Curl_ssl_close(data, conn, SECONDARYSOCKET);
+#endif
/* close possibly still open sockets */
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
@@ -830,8 +815,8 @@ static void conn_free(struct connectdata *conn)
*
*/
-CURLcode Curl_disconnect(struct Curl_easy *data,
- struct connectdata *conn, bool dead_connection)
+void Curl_disconnect(struct Curl_easy *data,
+ struct connectdata *conn, bool dead_connection)
{
/* there must be a connection to close */
DEBUGASSERT(conn);
@@ -851,7 +836,7 @@ CURLcode Curl_disconnect(struct Curl_easy *data,
*/
if(CONN_INUSE(conn) && !dead_connection) {
DEBUGF(infof(data, "Curl_disconnect when inuse: %zu", CONN_INUSE(conn)));
- return CURLE_OK;
+ return;
}
if(conn->dns_entry) {
@@ -883,7 +868,6 @@ CURLcode Curl_disconnect(struct Curl_easy *data,
Curl_detach_connnection(data);
conn_free(conn);
- return CURLE_OK;
}
/*
@@ -949,7 +933,7 @@ socks_proxy_info_matches(const struct proxy_info *data,
/* the user information is case-sensitive
or at least it is not defined as case-insensitive
- see https://tools.ietf.org/html/rfc3986#section-3.2.1 */
+ see https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1 */
if(!data->user != !needle->user)
return FALSE;
/* curl_strequal does a case insentive comparison, so do not use it here! */
@@ -1105,7 +1089,7 @@ static void prune_dead_connections(struct Curl_easy *data)
Curl_conncache_remove_conn(data, prune.extracted, TRUE);
/* disconnect it */
- (void)Curl_disconnect(data, prune.extracted, TRUE);
+ Curl_disconnect(data, prune.extracted, TRUE);
}
CONNCACHE_LOCK(data);
data->state.conn_cache->last_cleanup = now;
@@ -1209,7 +1193,7 @@ ConnectionExists(struct Curl_easy *data,
if(extract_if_dead(check, data)) {
/* disconnect it */
- (void)Curl_disconnect(data, check, TRUE);
+ Curl_disconnect(data, check, TRUE);
continue;
}
@@ -1575,20 +1559,6 @@ bool Curl_is_ASCII_name(const char *hostname)
}
/*
- * Strip single trailing dot in the hostname,
- * primarily for SNI and http host header.
- */
-static void strip_trailing_dot(struct hostname *host)
-{
- size_t len;
- if(!host || !host->name)
- return;
- len = strlen(host->name);
- if(len && (host->name[len-1] == '.'))
- host->name[len-1] = 0;
-}
-
-/*
* Perform any necessary IDN conversion of hostname
*/
CURLcode Curl_idnconvert_hostname(struct Curl_easy *data,
@@ -1690,18 +1660,35 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
Note that these backend pointers can be swapped by vtls (eg ssl backend
data becomes proxy backend data). */
{
- size_t sslsize = Curl_ssl->sizeof_ssl_backend_data;
- char *ssl = calloc(SSL_BACKEND_CNT, sslsize);
+ size_t onesize = Curl_ssl->sizeof_ssl_backend_data;
+ size_t totalsize = onesize;
+ char *ssl;
+
+#ifndef CURL_DISABLE_FTP
+ totalsize *= 2;
+#endif
+#ifndef CURL_DISABLE_PROXY
+ totalsize *= 2;
+#endif
+
+ ssl = calloc(1, totalsize);
if(!ssl) {
free(conn);
return NULL;
}
conn->ssl_extra = ssl;
- conn->ssl[0].backend = (void *)ssl;
- conn->ssl[1].backend = (void *)(ssl + sslsize);
+ conn->ssl[FIRSTSOCKET].backend = (void *)ssl;
+#ifndef CURL_DISABLE_FTP
+ ssl += onesize;
+ conn->ssl[SECONDARYSOCKET].backend = (void *)ssl;
+#endif
#ifndef CURL_DISABLE_PROXY
- conn->proxy_ssl[0].backend = (void *)(ssl + 2 * sslsize);
- conn->proxy_ssl[1].backend = (void *)(ssl + 3 * sslsize);
+ ssl += onesize;
+ conn->proxy_ssl[FIRSTSOCKET].backend = (void *)ssl;
+#ifndef CURL_DISABLE_FTP
+ ssl += onesize;
+ conn->proxy_ssl[SECONDARYSOCKET].backend = (void *)ssl;
+#endif
#endif
}
#endif
@@ -1761,7 +1748,6 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
conn->bits.tunnel_proxy = data->set.tunnel_thru_httpproxy;
#endif /* CURL_DISABLE_PROXY */
- conn->bits.user_passwd = (data->state.aptr.user) ? TRUE : FALSE;
#ifndef CURL_DISABLE_FTP
conn->bits.ftp_use_epsv = data->set.ftp_use_epsv;
conn->bits.ftp_use_eprt = data->set.ftp_use_eprt;
@@ -1882,6 +1868,7 @@ CURLcode Curl_uc_to_curlcode(CURLUcode uc)
}
}
+#ifdef ENABLE_IPV6
/*
* If the URL was set with an IPv6 numerical address with a zone id part, set
* the scope_id based on that!
@@ -1931,6 +1918,9 @@ static void zonefrom_url(CURLU *uh, struct Curl_easy *data,
free(zoneid);
}
}
+#else
+#define zonefrom_url(a,b,c) Curl_nop_stmt
+#endif
/*
* Parse URL and fill in the relevant members of the connection struct.
@@ -2038,45 +2028,47 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
* User name and password set with their own options override the
* credentials possibly set in the URL.
*/
- if(!data->state.aptr.user) {
- /* we don't use the URL API's URL decoder option here since it rejects
- control codes and we want to allow them for some schemes in the user
- and password fields */
- uc = curl_url_get(uh, CURLUPART_USER, &data->state.up.user, 0);
+ if(!data->state.aptr.passwd) {
+ uc = curl_url_get(uh, CURLUPART_PASSWORD, &data->state.up.password, 0);
if(!uc) {
char *decoded;
- result = Curl_urldecode(NULL, data->state.up.user, 0, &decoded, NULL,
+ result = Curl_urldecode(data->state.up.password, 0, &decoded, NULL,
conn->handler->flags&PROTOPT_USERPWDCTRL ?
REJECT_ZERO : REJECT_CTRL);
if(result)
return result;
- conn->user = decoded;
- conn->bits.user_passwd = TRUE;
- result = Curl_setstropt(&data->state.aptr.user, decoded);
+ conn->passwd = decoded;
+ result = Curl_setstropt(&data->state.aptr.passwd, decoded);
if(result)
return result;
}
- else if(uc != CURLUE_NO_USER)
+ else if(uc != CURLUE_NO_PASSWORD)
return Curl_uc_to_curlcode(uc);
}
- if(!data->state.aptr.passwd) {
- uc = curl_url_get(uh, CURLUPART_PASSWORD, &data->state.up.password, 0);
+ if(!data->state.aptr.user) {
+ /* we don't use the URL API's URL decoder option here since it rejects
+ control codes and we want to allow them for some schemes in the user
+ and password fields */
+ uc = curl_url_get(uh, CURLUPART_USER, &data->state.up.user, 0);
if(!uc) {
char *decoded;
- result = Curl_urldecode(NULL, data->state.up.password, 0, &decoded, NULL,
+ result = Curl_urldecode(data->state.up.user, 0, &decoded, NULL,
conn->handler->flags&PROTOPT_USERPWDCTRL ?
REJECT_ZERO : REJECT_CTRL);
if(result)
return result;
- conn->passwd = decoded;
- conn->bits.user_passwd = TRUE;
- result = Curl_setstropt(&data->state.aptr.passwd, decoded);
- if(result)
- return result;
+ conn->user = decoded;
+ result = Curl_setstropt(&data->state.aptr.user, decoded);
}
- else if(uc != CURLUE_NO_PASSWORD)
+ else if(uc != CURLUE_NO_USER)
return Curl_uc_to_curlcode(uc);
+ else if(data->state.aptr.passwd) {
+ /* no user was set but a password, set a blank user */
+ result = Curl_setstropt(&data->state.aptr.user, "");
+ }
+ if(result)
+ return result;
}
uc = curl_url_get(uh, CURLUPART_OPTIONS, &data->state.up.options,
@@ -2128,9 +2120,11 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
return CURLE_OUT_OF_MEMORY;
conn->host.name = conn->host.rawalloc;
+#ifdef ENABLE_IPV6
if(data->set.scope_id)
/* Override any scope that was set above. */
conn->scope_id = data->set.scope_id;
+#endif
return CURLE_OK;
}
@@ -2560,14 +2554,14 @@ static CURLcode parse_proxy_auth(struct Curl_easy *data,
CURLcode result = CURLE_OK;
if(proxyuser) {
- result = Curl_urldecode(data, proxyuser, 0, &conn->http_proxy.user, NULL,
+ result = Curl_urldecode(proxyuser, 0, &conn->http_proxy.user, NULL,
REJECT_ZERO);
if(!result)
result = Curl_setstropt(&data->state.aptr.proxyuser,
conn->http_proxy.user);
}
if(!result && proxypasswd) {
- result = Curl_urldecode(data, proxypasswd, 0, &conn->http_proxy.passwd,
+ result = Curl_urldecode(proxypasswd, 0, &conn->http_proxy.passwd,
NULL, REJECT_ZERO);
if(!result)
result = Curl_setstropt(&data->state.aptr.proxypasswd,
@@ -2922,10 +2916,10 @@ static CURLcode override_login(struct Curl_easy *data,
char **optionsp = &conn->options;
#ifndef CURL_DISABLE_NETRC
- if(data->set.use_netrc == CURL_NETRC_REQUIRED && conn->bits.user_passwd) {
+ if(data->set.use_netrc == CURL_NETRC_REQUIRED && data->state.aptr.user) {
Curl_safefree(*userp);
Curl_safefree(*passwdp);
- conn->bits.user_passwd = FALSE; /* disable user+password */
+ Curl_safefree(data->state.aptr.user); /* disable user+password */
}
#endif
@@ -2942,6 +2936,13 @@ static CURLcode override_login(struct Curl_easy *data,
bool netrc_user_changed = FALSE;
bool netrc_passwd_changed = FALSE;
int ret;
+ bool url_provided = FALSE;
+
+ if(data->state.up.user) {
+ /* there was a user name in the URL */
+ userp = &data->state.up.user;
+ url_provided = TRUE;
+ }
ret = Curl_parsenetrc(conn->host.name,
userp, passwdp,
@@ -2959,29 +2960,37 @@ static CURLcode override_login(struct Curl_easy *data,
file, so that it is safe to use even if we followed a Location: to a
different host or similar. */
conn->bits.netrc = TRUE;
- conn->bits.user_passwd = TRUE; /* enable user+password */
+ }
+ if(url_provided) {
+ Curl_safefree(conn->user);
+ conn->user = strdup(*userp);
+ if(!conn->user)
+ return CURLE_OUT_OF_MEMORY;
+ /* don't update the user name below */
+ userp = NULL;
}
}
#endif
/* for updated strings, we update them in the URL */
- if(*userp) {
- CURLcode result = Curl_setstropt(&data->state.aptr.user, *userp);
- if(result)
- return result;
- }
- if(data->state.aptr.user) {
- uc = curl_url_set(data->state.uh, CURLUPART_USER, data->state.aptr.user,
- CURLU_URLENCODE);
- if(uc)
- return Curl_uc_to_curlcode(uc);
- if(!*userp) {
- *userp = strdup(data->state.aptr.user);
- if(!*userp)
- return CURLE_OUT_OF_MEMORY;
+ if(userp) {
+ if(*userp) {
+ CURLcode result = Curl_setstropt(&data->state.aptr.user, *userp);
+ if(result)
+ return result;
+ }
+ if(data->state.aptr.user) {
+ uc = curl_url_set(data->state.uh, CURLUPART_USER, data->state.aptr.user,
+ CURLU_URLENCODE);
+ if(uc)
+ return Curl_uc_to_curlcode(uc);
+ if(!*userp) {
+ *userp = strdup(data->state.aptr.user);
+ if(!*userp)
+ return CURLE_OUT_OF_MEMORY;
+ }
}
}
-
if(*passwdp) {
CURLcode result = Curl_setstropt(&data->state.aptr.passwd, *passwdp);
if(result)
@@ -3005,14 +3014,15 @@ static CURLcode override_login(struct Curl_easy *data,
/*
* Set the login details so they're available in the connection
*/
-static CURLcode set_login(struct connectdata *conn)
+static CURLcode set_login(struct Curl_easy *data,
+ struct connectdata *conn)
{
CURLcode result = CURLE_OK;
const char *setuser = CURL_DEFAULT_USER;
const char *setpasswd = CURL_DEFAULT_PASSWORD;
/* If our protocol needs a password and we have none, use the defaults */
- if((conn->handler->flags & PROTOPT_NEEDSPWD) && !conn->bits.user_passwd)
+ if((conn->handler->flags & PROTOPT_NEEDSPWD) && !data->state.aptr.user)
;
else {
setuser = "";
@@ -3389,7 +3399,7 @@ static CURLcode resolve_server(struct Curl_easy *data,
else
#endif
- if(!conn->bits.proxy) {
+ if(!CONN_IS_PROXIED(conn)) {
struct hostname *connhost;
if(conn->bits.conn_to_host)
connhost = &conn->conn_to_host;
@@ -3486,8 +3496,7 @@ static void reuse_conn(struct Curl_easy *data,
/* get the user+password information from the old_conn struct since it may
* be new for this request even when we re-use an existing connection */
- conn->bits.user_passwd = old_conn->bits.user_passwd;
- if(conn->bits.user_passwd) {
+ if(old_conn->user) {
/* use the new user name and password though */
Curl_safefree(conn->user);
Curl_safefree(conn->passwd);
@@ -3665,7 +3674,7 @@ static CURLcode create_conn(struct Curl_easy *data,
if(result)
goto out;
- result = set_login(conn); /* default credentials */
+ result = set_login(data, conn); /* default credentials */
if(result)
goto out;
@@ -3947,7 +3956,7 @@ static CURLcode create_conn(struct Curl_easy *data,
CONNCACHE_UNLOCK(data);
if(conn_candidate)
- (void)Curl_disconnect(data, conn_candidate, FALSE);
+ Curl_disconnect(data, conn_candidate, FALSE);
else {
infof(data, "No more connections allowed to host %s: %zu",
bundlehost, max_host_connections);
@@ -3967,7 +3976,7 @@ 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)
- (void)Curl_disconnect(data, conn_candidate, FALSE);
+ Curl_disconnect(data, conn_candidate, FALSE);
else {
infof(data, "No connections available in cache");
connections_available = FALSE;
@@ -4038,17 +4047,6 @@ static CURLcode create_conn(struct Curl_easy *data,
*************************************************************/
result = resolve_server(data, conn, async);
- /* Strip trailing dots. resolve_server copied the name. */
- strip_trailing_dot(&conn->host);
-#ifndef CURL_DISABLE_PROXY
- if(conn->bits.httpproxy)
- strip_trailing_dot(&conn->http_proxy.host);
- if(conn->bits.socksproxy)
- strip_trailing_dot(&conn->socks_proxy.host);
-#endif
- if(conn->bits.conn_to_host)
- strip_trailing_dot(&conn->conn_to_host);
-
out:
return result;
}