"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/altsvc.c" between
curl-7.65.3.tar.xz and curl-7.66.0.tar.xz

About: cURL is a powerful commandline tool to transfer data from or to a server, using one of the supported protocols HTTP(S), FTP(S), SCP, SFTP, TFTP, DICT, TELNET, LDAP(S) or FILE.

altsvc.c  (curl-7.65.3.tar.xz):altsvc.c  (curl-7.66.0.tar.xz)
skipping to change at line 57 skipping to change at line 57
#define MAX_ALTSVC_HOSTLEN 512 #define MAX_ALTSVC_HOSTLEN 512
#define MAX_ALTSVC_ALPNLENSTR "10" #define MAX_ALTSVC_ALPNLENSTR "10"
#define MAX_ALTSVC_ALPNLEN 10 #define MAX_ALTSVC_ALPNLEN 10
static enum alpnid alpn2alpnid(char *name) static enum alpnid alpn2alpnid(char *name)
{ {
if(strcasecompare(name, "h1")) if(strcasecompare(name, "h1"))
return ALPN_h1; return ALPN_h1;
if(strcasecompare(name, "h2")) if(strcasecompare(name, "h2"))
return ALPN_h2; return ALPN_h2;
if(strcasecompare(name, "h2c")) #if (defined(USE_QUICHE) || defined(USE_NGHTTP2)) && !defined(UNITTESTS)
return ALPN_h2c; if(strcasecompare(name, "h3-22"))
return ALPN_h3;
#else
if(strcasecompare(name, "h3")) if(strcasecompare(name, "h3"))
return ALPN_h3; return ALPN_h3;
#endif
return ALPN_none; /* unknown, probably rubbish input */ return ALPN_none; /* unknown, probably rubbish input */
} }
/* Given the ALPN ID, return the name */ /* Given the ALPN ID, return the name */
const char *Curl_alpnid2str(enum alpnid id) const char *Curl_alpnid2str(enum alpnid id)
{ {
switch(id) { switch(id) {
case ALPN_h1: case ALPN_h1:
return "h1"; return "h1";
case ALPN_h2: case ALPN_h2:
return "h2"; return "h2";
case ALPN_h2c:
return "h2c";
case ALPN_h3: case ALPN_h3:
#if (defined(USE_QUICHE) || defined(USE_NGHTTP2)) && !defined(UNITTESTS)
return "h3-22";
#else
return "h3"; return "h3";
#endif
default: default:
return ""; /* bad */ return ""; /* bad */
} }
} }
static void altsvc_free(struct altsvc *as) static void altsvc_free(struct altsvc *as)
{ {
free(as->srchost); free(as->src.host);
free(as->dsthost); free(as->dst.host);
free(as); free(as);
} }
static struct altsvc *altsvc_createid(const char *srchost, static struct altsvc *altsvc_createid(const char *srchost,
const char *dsthost, const char *dsthost,
enum alpnid srcalpnid, enum alpnid srcalpnid,
enum alpnid dstalpnid, enum alpnid dstalpnid,
unsigned int srcport, unsigned int srcport,
unsigned int dstport) unsigned int dstport)
{ {
struct altsvc *as = calloc(sizeof(struct altsvc), 1); struct altsvc *as = calloc(sizeof(struct altsvc), 1);
if(!as) if(!as)
return NULL; return NULL;
as->srchost = strdup(srchost); as->src.host = strdup(srchost);
if(!as->srchost) if(!as->src.host)
goto error; goto error;
as->dsthost = strdup(dsthost); as->dst.host = strdup(dsthost);
if(!as->dsthost) if(!as->dst.host)
goto error; goto error;
as->srcalpnid = srcalpnid; as->src.alpnid = srcalpnid;
as->dstalpnid = dstalpnid; as->dst.alpnid = dstalpnid;
as->srcport = curlx_ultous(srcport); as->src.port = curlx_ultous(srcport);
as->dstport = curlx_ultous(dstport); as->dst.port = curlx_ultous(dstport);
return as; return as;
error: error:
altsvc_free(as); altsvc_free(as);
return NULL; return NULL;
} }
static struct altsvc *altsvc_create(char *srchost, static struct altsvc *altsvc_create(char *srchost,
char *dsthost, char *dsthost,
char *srcalpn, char *srcalpn,
skipping to change at line 228 skipping to change at line 233
CURLcode result = Curl_gmtime(as->expires, &stamp); CURLcode result = Curl_gmtime(as->expires, &stamp);
if(result) if(result)
return result; return result;
fprintf(fp, fprintf(fp,
"%s %s %u " "%s %s %u "
"%s %s %u " "%s %s %u "
"\"%d%02d%02d " "\"%d%02d%02d "
"%02d:%02d:%02d\" " "%02d:%02d:%02d\" "
"%u %d\n", "%u %d\n",
Curl_alpnid2str(as->srcalpnid), as->srchost, as->srcport, Curl_alpnid2str(as->src.alpnid), as->src.host, as->src.port,
Curl_alpnid2str(as->dstalpnid), as->dsthost, as->dstport, Curl_alpnid2str(as->dst.alpnid), as->dst.host, as->dst.port,
stamp.tm_year + 1900, stamp.tm_mon + 1, stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_mon + 1, stamp.tm_mday,
stamp.tm_hour, stamp.tm_min, stamp.tm_sec, stamp.tm_hour, stamp.tm_min, stamp.tm_sec,
as->persist, as->prio); as->persist, as->prio);
return CURLE_OK; return CURLE_OK;
} }
/* ---- library-wide functions below ---- */ /* ---- library-wide functions below ---- */
/* /*
* Curl_altsvc_init() creates a new altsvc cache. * Curl_altsvc_init() creates a new altsvc cache.
skipping to change at line 254 skipping to change at line 259
struct altsvcinfo *asi = calloc(sizeof(struct altsvcinfo), 1); struct altsvcinfo *asi = calloc(sizeof(struct altsvcinfo), 1);
if(!asi) if(!asi)
return NULL; return NULL;
Curl_llist_init(&asi->list, NULL); Curl_llist_init(&asi->list, NULL);
/* set default behavior */ /* set default behavior */
asi->flags = CURLALTSVC_H1 asi->flags = CURLALTSVC_H1
#ifdef USE_NGHTTP2 #ifdef USE_NGHTTP2
| CURLALTSVC_H2 | CURLALTSVC_H2
#endif #endif
#ifdef USE_HTTP3 #ifdef ENABLE_QUIC
| CURLALTSVC_H3 | CURLALTSVC_H3
#endif #endif
; ;
return asi; return asi;
} }
/* /*
* Curl_altsvc_load() loads alt-svc from file. * Curl_altsvc_load() loads alt-svc from file.
*/ */
CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file) CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file)
skipping to change at line 345 skipping to change at line 350
} }
static CURLcode getalnum(const char **ptr, char *alpnbuf, size_t buflen) static CURLcode getalnum(const char **ptr, char *alpnbuf, size_t buflen)
{ {
size_t len; size_t len;
const char *protop; const char *protop;
const char *p = *ptr; const char *p = *ptr;
while(*p && ISBLANK(*p)) while(*p && ISBLANK(*p))
p++; p++;
protop = p; protop = p;
while(*p && ISALNUM(*p)) while(*p && !ISBLANK(*p) && (*p != ';') && (*p != '='))
p++; p++;
len = p - protop; len = p - protop;
if(!len || (len >= buflen)) if(!len || (len >= buflen))
return CURLE_BAD_FUNCTION_ARGUMENT; return CURLE_BAD_FUNCTION_ARGUMENT;
memcpy(alpnbuf, protop, len); memcpy(alpnbuf, protop, len);
alpnbuf[len] = 0; alpnbuf[len] = 0;
*ptr = p; *ptr = p;
return CURLE_OK; return CURLE_OK;
} }
skipping to change at line 367 skipping to change at line 372
/* altsvc_flush() removes all alternatives for this source origin from the /* altsvc_flush() removes all alternatives for this source origin from the
list */ list */
static void altsvc_flush(struct altsvcinfo *asi, enum alpnid srcalpnid, static void altsvc_flush(struct altsvcinfo *asi, enum alpnid srcalpnid,
const char *srchost, unsigned short srcport) const char *srchost, unsigned short srcport)
{ {
struct curl_llist_element *e; struct curl_llist_element *e;
struct curl_llist_element *n; struct curl_llist_element *n;
for(e = asi->list.head; e; e = n) { for(e = asi->list.head; e; e = n) {
struct altsvc *as = e->ptr; struct altsvc *as = e->ptr;
n = e->next; n = e->next;
if((srcalpnid == as->srcalpnid) && if((srcalpnid == as->src.alpnid) &&
(srcport == as->srcport) && (srcport == as->src.port) &&
strcasecompare(srchost, as->srchost)) { strcasecompare(srchost, as->src.host)) {
Curl_llist_remove(&asi->list, e, NULL); Curl_llist_remove(&asi->list, e, NULL);
altsvc_free(as); altsvc_free(as);
asi->num--; asi->num--;
} }
} }
} }
#ifdef DEBUGBUILD #ifdef DEBUGBUILD
/* to play well with debug builds, we can *set* a fixed time this will /* to play well with debug builds, we can *set* a fixed time this will
return */ return */
skipping to change at line 537 skipping to change at line 542
return CURLE_OK; return CURLE_OK;
} }
/* /*
* Return TRUE on a match * Return TRUE on a match
*/ */
bool Curl_altsvc_lookup(struct altsvcinfo *asi, bool Curl_altsvc_lookup(struct altsvcinfo *asi,
enum alpnid srcalpnid, const char *srchost, enum alpnid srcalpnid, const char *srchost,
int srcport, int srcport,
enum alpnid *dstalpnid, const char **dsthost, struct altsvc **dstentry,
int *dstport) const int versions) /* one or more bits */
{ {
struct curl_llist_element *e; struct curl_llist_element *e;
struct curl_llist_element *n; struct curl_llist_element *n;
time_t now = time(NULL); time_t now = time(NULL);
DEBUGASSERT(asi); DEBUGASSERT(asi);
DEBUGASSERT(srchost); DEBUGASSERT(srchost);
DEBUGASSERT(dsthost); DEBUGASSERT(dstentry);
for(e = asi->list.head; e; e = n) { for(e = asi->list.head; e; e = n) {
struct altsvc *as = e->ptr; struct altsvc *as = e->ptr;
n = e->next; n = e->next;
if(as->expires < now) { if(as->expires < now) {
/* an expired entry, remove */ /* an expired entry, remove */
Curl_llist_remove(&asi->list, e, NULL);
altsvc_free(as); altsvc_free(as);
continue; continue;
} }
if((as->srcalpnid == srcalpnid) && if((as->src.alpnid == srcalpnid) &&
strcasecompare(as->srchost, srchost) && strcasecompare(as->src.host, srchost) &&
as->srcport == srcport) { (as->src.port == srcport) &&
(versions & as->dst.alpnid)) {
/* match */ /* match */
*dstalpnid = as->dstalpnid; *dstentry = as;
*dsthost = as->dsthost;
*dstport = as->dstport;
return TRUE; return TRUE;
} }
} }
return FALSE; return FALSE;
} }
#endif /* CURL_DISABLE_HTTP || USE_ALTSVC */ #endif /* CURL_DISABLE_HTTP || USE_ALTSVC */
 End of changes. 18 change blocks. 
30 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)