aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/altsvc.c
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2024-10-04 11:15:32 +0300
committerthegeorg <thegeorg@yandex-team.com>2024-10-04 11:29:39 +0300
commit37112f646e6da1c3eb50de15cbbb8793b383b27e (patch)
treef32d6652f26110a47441c8cf8a08216eca1a52b6 /contrib/libs/curl/lib/altsvc.c
parent9a6b8cb5c502ba2b158c337ce13e983e3c3dc78f (diff)
downloadydb-37112f646e6da1c3eb50de15cbbb8793b383b27e.tar.gz
Update contrib/libs/curl to 8.10.1
commit_hash:428ef806a15515cdaa325530aa8cc6903fac5fb6
Diffstat (limited to 'contrib/libs/curl/lib/altsvc.c')
-rw-r--r--contrib/libs/curl/lib/altsvc.c105
1 files changed, 48 insertions, 57 deletions
diff --git a/contrib/libs/curl/lib/altsvc.c b/contrib/libs/curl/lib/altsvc.c
index 35450d6b1c..dcedc491c5 100644
--- a/contrib/libs/curl/lib/altsvc.c
+++ b/contrib/libs/curl/lib/altsvc.c
@@ -106,9 +106,11 @@ static struct altsvc *altsvc_createid(const char *srchost,
dlen = strlen(dsthost);
DEBUGASSERT(hlen);
DEBUGASSERT(dlen);
- if(!hlen || !dlen)
+ if(!hlen || !dlen) {
/* bad input */
+ free(as);
return NULL;
+ }
if((hlen > 2) && srchost[0] == '[') {
/* IPv6 address, strip off brackets */
srchost++;
@@ -123,11 +125,11 @@ static struct altsvc *altsvc_createid(const char *srchost,
dlen -= 2;
}
- as->src.host = Curl_strndup(srchost, hlen);
+ as->src.host = Curl_memdup0(srchost, hlen);
if(!as->src.host)
goto error;
- as->dst.host = Curl_strndup(dsthost, dlen);
+ as->dst.host = Curl_memdup0(dsthost, dlen);
if(!as->dst.host)
goto error;
@@ -189,7 +191,7 @@ static CURLcode altsvc_add(struct altsvcinfo *asi, char *line)
as->expires = expires;
as->prio = prio;
as->persist = persist ? 1 : 0;
- Curl_llist_insert_next(&asi->list, asi->list.tail, as, &as->node);
+ Curl_llist_append(&asi->list, as, &as->node);
}
}
@@ -207,10 +209,9 @@ static CURLcode altsvc_add(struct altsvcinfo *asi, char *line)
static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file)
{
CURLcode result = CURLE_OK;
- char *line = NULL;
FILE *fp;
- /* we need a private copy of the file name so that the altsvc cache file
+ /* we need a private copy of the filename so that the altsvc cache file
name survives an easy handle reset */
free(asi->filename);
asi->filename = strdup(file);
@@ -219,11 +220,10 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file)
fp = fopen(file, FOPEN_READTEXT);
if(fp) {
- line = malloc(MAX_ALTSVC_LINE);
- if(!line)
- goto fail;
- while(Curl_get_line(line, MAX_ALTSVC_LINE, fp)) {
- char *lineptr = line;
+ struct dynbuf buf;
+ Curl_dyn_init(&buf, MAX_ALTSVC_LINE);
+ while(Curl_get_line(&buf, fp)) {
+ char *lineptr = Curl_dyn_ptr(&buf);
while(*lineptr && ISBLANK(*lineptr))
lineptr++;
if(*lineptr == '#')
@@ -232,16 +232,10 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file)
altsvc_add(asi, lineptr);
}
- free(line); /* free the line buffer */
+ Curl_dyn_free(&buf); /* free the line buffer */
fclose(fp);
}
return result;
-
-fail:
- Curl_safefree(asi->filename);
- free(line);
- fclose(fp);
- return CURLE_OUT_OF_MEMORY;
}
/*
@@ -258,7 +252,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp)
CURLcode result = Curl_gmtime(as->expires, &stamp);
if(result)
return result;
-#ifdef ENABLE_IPV6
+#ifdef USE_IPV6
else {
char ipv6_unused[16];
if(1 == Curl_inet_pton(AF_INET6, as->dst.host, ipv6_unused)) {
@@ -276,7 +270,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp)
"%s %s%s%s %u "
"\"%d%02d%02d "
"%02d:%02d:%02d\" "
- "%u %d\n",
+ "%u %u\n",
Curl_alpnid2str(as->src.alpnid),
src6_pre, as->src.host, src6_post,
as->src.port,
@@ -309,7 +303,7 @@ struct altsvcinfo *Curl_altsvc_init(void)
#ifdef USE_HTTP2
| CURLALTSVC_H2
#endif
-#ifdef ENABLE_QUIC
+#ifdef USE_HTTP3
| CURLALTSVC_H3
#endif
;
@@ -333,9 +327,6 @@ CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file)
CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl)
{
DEBUGASSERT(asi);
- if(!ctrl)
- /* unexpected */
- return CURLE_BAD_FUNCTION_ARGUMENT;
asi->flags = ctrl;
return CURLE_OK;
}
@@ -346,13 +337,13 @@ CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl)
*/
void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp)
{
- struct Curl_llist_element *e;
- struct Curl_llist_element *n;
if(*altsvcp) {
+ struct Curl_llist_node *e;
+ struct Curl_llist_node *n;
struct altsvcinfo *altsvc = *altsvcp;
- for(e = altsvc->list.head; e; e = n) {
- struct altsvc *as = e->ptr;
- n = e->next;
+ for(e = Curl_llist_head(&altsvc->list); e; e = n) {
+ struct altsvc *as = Curl_node_elem(e);
+ n = Curl_node_next(e);
altsvc_free(as);
}
free(altsvc->filename);
@@ -367,8 +358,6 @@ void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp)
CURLcode Curl_altsvc_save(struct Curl_easy *data,
struct altsvcinfo *altsvc, const char *file)
{
- struct Curl_llist_element *e;
- struct Curl_llist_element *n;
CURLcode result = CURLE_OK;
FILE *out;
char *tempstore = NULL;
@@ -382,17 +371,19 @@ CURLcode Curl_altsvc_save(struct Curl_easy *data,
file = altsvc->filename;
if((altsvc->flags & CURLALTSVC_READONLYFILE) || !file || !file[0])
- /* marked as read-only, no file or zero length file name */
+ /* marked as read-only, no file or zero length filename */
return CURLE_OK;
result = Curl_fopen(data, file, &out, &tempstore);
if(!result) {
+ struct Curl_llist_node *e;
+ struct Curl_llist_node *n;
fputs("# Your alt-svc cache. https://curl.se/docs/alt-svc.html\n"
"# This file was generated by libcurl! Edit at your own risk.\n",
out);
- for(e = altsvc->list.head; e; e = n) {
- struct altsvc *as = e->ptr;
- n = e->next;
+ for(e = Curl_llist_head(&altsvc->list); e; e = n) {
+ struct altsvc *as = Curl_node_elem(e);
+ n = Curl_node_next(e);
result = altsvc_out(as, out);
if(result)
break;
@@ -439,7 +430,7 @@ static bool hostcompare(const char *host, const char *check)
if(hlen && (host[hlen - 1] == '.'))
hlen--;
if(hlen != clen)
- /* they can't match if they have different lengths */
+ /* they cannot match if they have different lengths */
return FALSE;
return strncasecompare(host, check, hlen);
}
@@ -449,15 +440,15 @@ static bool hostcompare(const char *host, const char *check)
static void altsvc_flush(struct altsvcinfo *asi, enum alpnid srcalpnid,
const char *srchost, unsigned short srcport)
{
- struct Curl_llist_element *e;
- struct Curl_llist_element *n;
- for(e = asi->list.head; e; e = n) {
- struct altsvc *as = e->ptr;
- n = e->next;
+ struct Curl_llist_node *e;
+ struct Curl_llist_node *n;
+ for(e = Curl_llist_head(&asi->list); e; e = n) {
+ struct altsvc *as = Curl_node_elem(e);
+ n = Curl_node_next(e);
if((srcalpnid == as->src.alpnid) &&
(srcport == as->src.port) &&
hostcompare(srchost, as->src.host)) {
- Curl_llist_remove(&asi->list, e, NULL);
+ Curl_node_remove(e);
altsvc_free(as);
}
}
@@ -471,7 +462,7 @@ static time_t altsvc_debugtime(void *unused)
char *timestr = getenv("CURL_TIME");
(void)unused;
if(timestr) {
- unsigned long val = strtol(timestr, NULL, 10);
+ long val = strtol(timestr, NULL, 10);
return (time_t)val;
}
return time(NULL);
@@ -486,11 +477,11 @@ static time_t altsvc_debugtime(void *unused)
* Curl_altsvc_parse() takes an incoming alt-svc response header and stores
* the data correctly in the cache.
*
- * 'value' points to the header *value*. That's contents to the right of the
+ * 'value' points to the header *value*. That is contents to the right of the
* header name.
*
* Currently this function rejects invalid data without returning an error.
- * Invalid host name, port number will result in the specific alternative
+ * Invalid hostname, port number will result in the specific alternative
* being rejected. Unknown protocols are skipped.
*/
CURLcode Curl_altsvc_parse(struct Curl_easy *data,
@@ -540,7 +531,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
bool valid = TRUE;
p++;
if(*p != ':') {
- /* host name starts here */
+ /* hostname starts here */
const char *hostp = p;
if(*p == '[') {
/* pass all valid IPv6 letters - does not handle zone id */
@@ -558,7 +549,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
len = p - hostp;
}
if(!len || (len >= MAX_ALTSVC_HOSTLEN)) {
- infof(data, "Excessive alt-svc host name, ignoring.");
+ infof(data, "Excessive alt-svc hostname, ignoring.");
valid = FALSE;
}
else {
@@ -633,7 +624,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
num = strtoul(value_ptr, &end_ptr, 10);
if((end_ptr != value_ptr) && (num < ULONG_MAX)) {
if(strcasecompare("ma", option))
- maxage = num;
+ maxage = (time_t)num;
else if(strcasecompare("persist", option) && (num == 1))
persist = TRUE;
}
@@ -652,7 +643,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
account. [See RFC 7838 section 3.1] */
as->expires = maxage + time(NULL);
as->persist = persist;
- Curl_llist_insert_next(&asi->list, asi->list.tail, as, &as->node);
+ Curl_llist_append(&asi->list, as, &as->node);
infof(data, "Added alt-svc: %s:%d over %s", dsthost, dstport,
Curl_alpnid2str(dstalpnid));
}
@@ -660,7 +651,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
}
else
break;
- /* after the double quote there can be a comma if there's another
+ /* after the double quote there can be a comma if there is another
string or a semicolon if no more */
if(*p == ',') {
/* comma means another alternative is presented */
@@ -686,26 +677,26 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi,
struct altsvc **dstentry,
const int versions) /* one or more bits */
{
- struct Curl_llist_element *e;
- struct Curl_llist_element *n;
+ struct Curl_llist_node *e;
+ struct Curl_llist_node *n;
time_t now = time(NULL);
DEBUGASSERT(asi);
DEBUGASSERT(srchost);
DEBUGASSERT(dstentry);
- for(e = asi->list.head; e; e = n) {
- struct altsvc *as = e->ptr;
- n = e->next;
+ for(e = Curl_llist_head(&asi->list); e; e = n) {
+ struct altsvc *as = Curl_node_elem(e);
+ n = Curl_node_next(e);
if(as->expires < now) {
/* an expired entry, remove */
- Curl_llist_remove(&asi->list, e, NULL);
+ Curl_node_remove(e);
altsvc_free(as);
continue;
}
if((as->src.alpnid == srcalpnid) &&
hostcompare(srchost, as->src.host) &&
(as->src.port == srcport) &&
- (versions & as->dst.alpnid)) {
+ (versions & (int)as->dst.alpnid)) {
/* match */
*dstentry = as;
return TRUE;