Coverage Report

Created: 2023-06-07 07:02

/src/curl/lib/altsvc.c
Line
Count
Source (jump to first uncovered line)
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
 *
10
 * This software is licensed as described in the file COPYING, which
11
 * you should have received as part of this distribution. The terms
12
 * are also available at https://curl.se/docs/copyright.html.
13
 *
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
 * copies of the Software, and permit persons to whom the Software is
16
 * furnished to do so, under the terms of the COPYING file.
17
 *
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
 * KIND, either express or implied.
20
 *
21
 * SPDX-License-Identifier: curl
22
 *
23
 ***************************************************************************/
24
/*
25
 * The Alt-Svc: header is defined in RFC 7838:
26
 * https://datatracker.ietf.org/doc/html/rfc7838
27
 */
28
#include "curl_setup.h"
29
30
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC)
31
#include <curl/curl.h>
32
#include "urldata.h"
33
#include "altsvc.h"
34
#include "curl_get_line.h"
35
#include "strcase.h"
36
#include "parsedate.h"
37
#include "sendf.h"
38
#include "warnless.h"
39
#include "fopen.h"
40
#include "rename.h"
41
42
/* The last 3 #include files should be in this order */
43
#include "curl_printf.h"
44
#include "curl_memory.h"
45
#include "memdebug.h"
46
47
707
#define MAX_ALTSVC_LINE 4095
48
#define MAX_ALTSVC_DATELENSTR "64"
49
#define MAX_ALTSVC_DATELEN 64
50
#define MAX_ALTSVC_HOSTLENSTR "512"
51
0
#define MAX_ALTSVC_HOSTLEN 512
52
#define MAX_ALTSVC_ALPNLENSTR "10"
53
#define MAX_ALTSVC_ALPNLEN 10
54
55
0
#define H3VERSION "h3"
56
57
static enum alpnid alpn2alpnid(char *name)
58
0
{
59
0
  if(strcasecompare(name, "h1"))
60
0
    return ALPN_h1;
61
0
  if(strcasecompare(name, "h2"))
62
0
    return ALPN_h2;
63
0
  if(strcasecompare(name, H3VERSION))
64
0
    return ALPN_h3;
65
0
  return ALPN_none; /* unknown, probably rubbish input */
66
0
}
67
68
/* Given the ALPN ID, return the name */
69
const char *Curl_alpnid2str(enum alpnid id)
70
0
{
71
0
  switch(id) {
72
0
  case ALPN_h1:
73
0
    return "h1";
74
0
  case ALPN_h2:
75
0
    return "h2";
76
0
  case ALPN_h3:
77
0
    return H3VERSION;
78
0
  default:
79
0
    return ""; /* bad */
80
0
  }
81
0
}
82
83
84
static void altsvc_free(struct altsvc *as)
85
0
{
86
0
  free(as->src.host);
87
0
  free(as->dst.host);
88
0
  free(as);
89
0
}
90
91
static struct altsvc *altsvc_createid(const char *srchost,
92
                                      const char *dsthost,
93
                                      enum alpnid srcalpnid,
94
                                      enum alpnid dstalpnid,
95
                                      unsigned int srcport,
96
                                      unsigned int dstport)
97
0
{
98
0
  struct altsvc *as = calloc(sizeof(struct altsvc), 1);
99
0
  size_t hlen;
100
0
  if(!as)
101
0
    return NULL;
102
0
  hlen = strlen(srchost);
103
0
  DEBUGASSERT(hlen);
104
0
  as->src.host = strdup(srchost);
105
0
  if(!as->src.host)
106
0
    goto error;
107
0
  if(hlen && (srchost[hlen - 1] == '.'))
108
    /* strip off trailing any dot */
109
0
    as->src.host[--hlen] = 0;
110
0
  as->dst.host = strdup(dsthost);
111
0
  if(!as->dst.host)
112
0
    goto error;
113
114
0
  as->src.alpnid = srcalpnid;
115
0
  as->dst.alpnid = dstalpnid;
116
0
  as->src.port = curlx_ultous(srcport);
117
0
  as->dst.port = curlx_ultous(dstport);
118
119
0
  return as;
120
0
error:
121
0
  altsvc_free(as);
122
0
  return NULL;
123
0
}
124
125
static struct altsvc *altsvc_create(char *srchost,
126
                                    char *dsthost,
127
                                    char *srcalpn,
128
                                    char *dstalpn,
129
                                    unsigned int srcport,
130
                                    unsigned int dstport)
131
0
{
132
0
  enum alpnid dstalpnid = alpn2alpnid(dstalpn);
133
0
  enum alpnid srcalpnid = alpn2alpnid(srcalpn);
134
0
  if(!srcalpnid || !dstalpnid)
135
0
    return NULL;
136
0
  return altsvc_createid(srchost, dsthost, srcalpnid, dstalpnid,
137
0
                         srcport, dstport);
138
0
}
139
140
/* only returns SERIOUS errors */
141
static CURLcode altsvc_add(struct altsvcinfo *asi, char *line)
142
0
{
143
  /* Example line:
144
     h2 example.com 443 h3 shiny.example.com 8443 "20191231 10:00:00" 1
145
   */
146
0
  char srchost[MAX_ALTSVC_HOSTLEN + 1];
147
0
  char dsthost[MAX_ALTSVC_HOSTLEN + 1];
148
0
  char srcalpn[MAX_ALTSVC_ALPNLEN + 1];
149
0
  char dstalpn[MAX_ALTSVC_ALPNLEN + 1];
150
0
  char date[MAX_ALTSVC_DATELEN + 1];
151
0
  unsigned int srcport;
152
0
  unsigned int dstport;
153
0
  unsigned int prio;
154
0
  unsigned int persist;
155
0
  int rc;
156
157
0
  rc = sscanf(line,
158
0
              "%" MAX_ALTSVC_ALPNLENSTR "s %" MAX_ALTSVC_HOSTLENSTR "s %u "
159
0
              "%" MAX_ALTSVC_ALPNLENSTR "s %" MAX_ALTSVC_HOSTLENSTR "s %u "
160
0
              "\"%" MAX_ALTSVC_DATELENSTR "[^\"]\" %u %u",
161
0
              srcalpn, srchost, &srcport,
162
0
              dstalpn, dsthost, &dstport,
163
0
              date, &persist, &prio);
164
0
  if(9 == rc) {
165
0
    struct altsvc *as;
166
0
    time_t expires = Curl_getdate_capped(date);
167
0
    as = altsvc_create(srchost, dsthost, srcalpn, dstalpn, srcport, dstport);
168
0
    if(as) {
169
0
      as->expires = expires;
170
0
      as->prio = prio;
171
0
      as->persist = persist ? 1 : 0;
172
0
      Curl_llist_insert_next(&asi->list, asi->list.tail, as, &as->node);
173
0
    }
174
0
  }
175
176
0
  return CURLE_OK;
177
0
}
178
179
/*
180
 * Load alt-svc entries from the given file. The text based line-oriented file
181
 * format is documented here: https://curl.se/docs/alt-svc.html
182
 *
183
 * This function only returns error on major problems that prevent alt-svc
184
 * handling to work completely. It will ignore individual syntactical errors
185
 * etc.
186
 */
187
static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file)
188
707
{
189
707
  CURLcode result = CURLE_OK;
190
707
  char *line = NULL;
191
707
  FILE *fp;
192
193
  /* we need a private copy of the file name so that the altsvc cache file
194
     name survives an easy handle reset */
195
707
  free(asi->filename);
196
707
  asi->filename = strdup(file);
197
707
  if(!asi->filename)
198
0
    return CURLE_OUT_OF_MEMORY;
199
200
707
  fp = fopen(file, FOPEN_READTEXT);
201
707
  if(fp) {
202
707
    line = malloc(MAX_ALTSVC_LINE);
203
707
    if(!line)
204
0
      goto fail;
205
707
    while(Curl_get_line(line, MAX_ALTSVC_LINE, fp)) {
206
0
      char *lineptr = line;
207
0
      while(*lineptr && ISBLANK(*lineptr))
208
0
        lineptr++;
209
0
      if(*lineptr == '#')
210
        /* skip commented lines */
211
0
        continue;
212
213
0
      altsvc_add(asi, lineptr);
214
0
    }
215
707
    free(line); /* free the line buffer */
216
707
    fclose(fp);
217
707
  }
218
707
  return result;
219
220
0
fail:
221
0
  Curl_safefree(asi->filename);
222
0
  free(line);
223
0
  fclose(fp);
224
0
  return CURLE_OUT_OF_MEMORY;
225
707
}
226
227
/*
228
 * Write this single altsvc entry to a single output line
229
 */
230
231
static CURLcode altsvc_out(struct altsvc *as, FILE *fp)
232
0
{
233
0
  struct tm stamp;
234
0
  CURLcode result = Curl_gmtime(as->expires, &stamp);
235
0
  if(result)
236
0
    return result;
237
238
0
  fprintf(fp,
239
0
          "%s %s %u "
240
0
          "%s %s %u "
241
0
          "\"%d%02d%02d "
242
0
          "%02d:%02d:%02d\" "
243
0
          "%u %d\n",
244
0
          Curl_alpnid2str(as->src.alpnid), as->src.host, as->src.port,
245
0
          Curl_alpnid2str(as->dst.alpnid), as->dst.host, as->dst.port,
246
0
          stamp.tm_year + 1900, stamp.tm_mon + 1, stamp.tm_mday,
247
0
          stamp.tm_hour, stamp.tm_min, stamp.tm_sec,
248
0
          as->persist, as->prio);
249
0
  return CURLE_OK;
250
0
}
251
252
/* ---- library-wide functions below ---- */
253
254
/*
255
 * Curl_altsvc_init() creates a new altsvc cache.
256
 * It returns the new instance or NULL if something goes wrong.
257
 */
258
struct altsvcinfo *Curl_altsvc_init(void)
259
707
{
260
707
  struct altsvcinfo *asi = calloc(sizeof(struct altsvcinfo), 1);
261
707
  if(!asi)
262
0
    return NULL;
263
707
  Curl_llist_init(&asi->list, NULL);
264
265
  /* set default behavior */
266
707
  asi->flags = CURLALTSVC_H1
267
707
#ifdef USE_HTTP2
268
707
    | CURLALTSVC_H2
269
707
#endif
270
#ifdef ENABLE_QUIC
271
    | CURLALTSVC_H3
272
#endif
273
707
    ;
274
707
  return asi;
275
707
}
276
277
/*
278
 * Curl_altsvc_load() loads alt-svc from file.
279
 */
280
CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file)
281
707
{
282
707
  CURLcode result;
283
707
  DEBUGASSERT(asi);
284
707
  result = altsvc_load(asi, file);
285
707
  return result;
286
707
}
287
288
/*
289
 * Curl_altsvc_ctrl() passes on the external bitmask.
290
 */
291
CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl)
292
0
{
293
0
  DEBUGASSERT(asi);
294
0
  if(!ctrl)
295
    /* unexpected */
296
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
297
0
  asi->flags = ctrl;
298
0
  return CURLE_OK;
299
0
}
300
301
/*
302
 * Curl_altsvc_cleanup() frees an altsvc cache instance and all associated
303
 * resources.
304
 */
305
void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp)
306
1.18k
{
307
1.18k
  struct Curl_llist_element *e;
308
1.18k
  struct Curl_llist_element *n;
309
1.18k
  if(*altsvcp) {
310
707
    struct altsvcinfo *altsvc = *altsvcp;
311
707
    for(e = altsvc->list.head; e; e = n) {
312
0
      struct altsvc *as = e->ptr;
313
0
      n = e->next;
314
0
      altsvc_free(as);
315
0
    }
316
707
    free(altsvc->filename);
317
707
    free(altsvc);
318
707
    *altsvcp = NULL; /* clear the pointer */
319
707
  }
320
1.18k
}
321
322
/*
323
 * Curl_altsvc_save() writes the altsvc cache to a file.
324
 */
325
CURLcode Curl_altsvc_save(struct Curl_easy *data,
326
                          struct altsvcinfo *altsvc, const char *file)
327
1.18k
{
328
1.18k
  struct Curl_llist_element *e;
329
1.18k
  struct Curl_llist_element *n;
330
1.18k
  CURLcode result = CURLE_OK;
331
1.18k
  FILE *out;
332
1.18k
  char *tempstore = NULL;
333
334
1.18k
  if(!altsvc)
335
    /* no cache activated */
336
477
    return CURLE_OK;
337
338
  /* if not new name is given, use the one we stored from the load */
339
707
  if(!file && altsvc->filename)
340
0
    file = altsvc->filename;
341
342
707
  if((altsvc->flags & CURLALTSVC_READONLYFILE) || !file || !file[0])
343
    /* marked as read-only, no file or zero length file name */
344
0
    return CURLE_OK;
345
346
707
  result = Curl_fopen(data, file, &out, &tempstore);
347
707
  if(!result) {
348
707
    fputs("# Your alt-svc cache. https://curl.se/docs/alt-svc.html\n"
349
707
          "# This file was generated by libcurl! Edit at your own risk.\n",
350
707
          out);
351
707
    for(e = altsvc->list.head; e; e = n) {
352
0
      struct altsvc *as = e->ptr;
353
0
      n = e->next;
354
0
      result = altsvc_out(as, out);
355
0
      if(result)
356
0
        break;
357
0
    }
358
707
    fclose(out);
359
707
    if(!result && tempstore && Curl_rename(tempstore, file))
360
0
      result = CURLE_WRITE_ERROR;
361
362
707
    if(result && tempstore)
363
0
      unlink(tempstore);
364
707
  }
365
707
  free(tempstore);
366
707
  return result;
367
707
}
368
369
static CURLcode getalnum(const char **ptr, char *alpnbuf, size_t buflen)
370
0
{
371
0
  size_t len;
372
0
  const char *protop;
373
0
  const char *p = *ptr;
374
0
  while(*p && ISBLANK(*p))
375
0
    p++;
376
0
  protop = p;
377
0
  while(*p && !ISBLANK(*p) && (*p != ';') && (*p != '='))
378
0
    p++;
379
0
  len = p - protop;
380
0
  *ptr = p;
381
382
0
  if(!len || (len >= buflen))
383
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
384
0
  memcpy(alpnbuf, protop, len);
385
0
  alpnbuf[len] = 0;
386
0
  return CURLE_OK;
387
0
}
388
389
/* hostcompare() returns true if 'host' matches 'check'. The first host
390
 * argument may have a trailing dot present that will be ignored.
391
 */
392
static bool hostcompare(const char *host, const char *check)
393
0
{
394
0
  size_t hlen = strlen(host);
395
0
  size_t clen = strlen(check);
396
397
0
  if(hlen && (host[hlen - 1] == '.'))
398
0
    hlen--;
399
0
  if(hlen != clen)
400
    /* they can't match if they have different lengths */
401
0
    return FALSE;
402
0
  return strncasecompare(host, check, hlen);
403
0
}
404
405
/* altsvc_flush() removes all alternatives for this source origin from the
406
   list */
407
static void altsvc_flush(struct altsvcinfo *asi, enum alpnid srcalpnid,
408
                         const char *srchost, unsigned short srcport)
409
0
{
410
0
  struct Curl_llist_element *e;
411
0
  struct Curl_llist_element *n;
412
0
  for(e = asi->list.head; e; e = n) {
413
0
    struct altsvc *as = e->ptr;
414
0
    n = e->next;
415
0
    if((srcalpnid == as->src.alpnid) &&
416
0
       (srcport == as->src.port) &&
417
0
       hostcompare(srchost, as->src.host)) {
418
0
      Curl_llist_remove(&asi->list, e, NULL);
419
0
      altsvc_free(as);
420
0
    }
421
0
  }
422
0
}
423
424
#ifdef DEBUGBUILD
425
/* to play well with debug builds, we can *set* a fixed time this will
426
   return */
427
static time_t debugtime(void *unused)
428
0
{
429
0
  char *timestr = getenv("CURL_TIME");
430
0
  (void)unused;
431
0
  if(timestr) {
432
0
    unsigned long val = strtol(timestr, NULL, 10);
433
0
    return (time_t)val;
434
0
  }
435
0
  return time(NULL);
436
0
}
437
0
#define time(x) debugtime(x)
438
#endif
439
440
0
#define ISNEWLINE(x) (((x) == '\n') || (x) == '\r')
441
442
/*
443
 * Curl_altsvc_parse() takes an incoming alt-svc response header and stores
444
 * the data correctly in the cache.
445
 *
446
 * 'value' points to the header *value*. That's contents to the right of the
447
 * header name.
448
 *
449
 * Currently this function rejects invalid data without returning an error.
450
 * Invalid host name, port number will result in the specific alternative
451
 * being rejected. Unknown protocols are skipped.
452
 */
453
CURLcode Curl_altsvc_parse(struct Curl_easy *data,
454
                           struct altsvcinfo *asi, const char *value,
455
                           enum alpnid srcalpnid, const char *srchost,
456
                           unsigned short srcport)
457
0
{
458
0
  const char *p = value;
459
0
  size_t len;
460
0
  char namebuf[MAX_ALTSVC_HOSTLEN] = "";
461
0
  char alpnbuf[MAX_ALTSVC_ALPNLEN] = "";
462
0
  struct altsvc *as;
463
0
  unsigned short dstport = srcport; /* the same by default */
464
0
  CURLcode result = getalnum(&p, alpnbuf, sizeof(alpnbuf));
465
0
  size_t entries = 0;
466
#ifdef CURL_DISABLE_VERBOSE_STRINGS
467
  (void)data;
468
#endif
469
0
  if(result) {
470
0
    infof(data, "Excessive alt-svc header, ignoring.");
471
0
    return CURLE_OK;
472
0
  }
473
474
0
  DEBUGASSERT(asi);
475
476
  /* "clear" is a magic keyword */
477
0
  if(strcasecompare(alpnbuf, "clear")) {
478
    /* Flush cached alternatives for this source origin */
479
0
    altsvc_flush(asi, srcalpnid, srchost, srcport);
480
0
    return CURLE_OK;
481
0
  }
482
483
0
  do {
484
0
    if(*p == '=') {
485
      /* [protocol]="[host][:port]" */
486
0
      enum alpnid dstalpnid = alpn2alpnid(alpnbuf); /* the same by default */
487
0
      p++;
488
0
      if(*p == '\"') {
489
0
        const char *dsthost = "";
490
0
        const char *value_ptr;
491
0
        char option[32];
492
0
        unsigned long num;
493
0
        char *end_ptr;
494
0
        bool quoted = FALSE;
495
0
        time_t maxage = 24 * 3600; /* default is 24 hours */
496
0
        bool persist = FALSE;
497
0
        bool valid = TRUE;
498
0
        p++;
499
0
        if(*p != ':') {
500
          /* host name starts here */
501
0
          const char *hostp = p;
502
0
          while(*p && (ISALNUM(*p) || (*p == '.') || (*p == '-')))
503
0
            p++;
504
0
          len = p - hostp;
505
0
          if(!len || (len >= MAX_ALTSVC_HOSTLEN)) {
506
0
            infof(data, "Excessive alt-svc host name, ignoring.");
507
0
            valid = FALSE;
508
0
          }
509
0
          else {
510
0
            memcpy(namebuf, hostp, len);
511
0
            namebuf[len] = 0;
512
0
            dsthost = namebuf;
513
0
          }
514
0
        }
515
0
        else {
516
          /* no destination name, use source host */
517
0
          dsthost = srchost;
518
0
        }
519
0
        if(*p == ':') {
520
0
          unsigned long port = 0;
521
0
          p++;
522
0
          if(ISDIGIT(*p))
523
            /* a port number */
524
0
            port = strtoul(p, &end_ptr, 10);
525
0
          else
526
0
            end_ptr = (char *)p; /* not left uninitialized */
527
0
          if(!port || port > USHRT_MAX || end_ptr == p || *end_ptr != '\"') {
528
0
            infof(data, "Unknown alt-svc port number, ignoring.");
529
0
            valid = FALSE;
530
0
          }
531
0
          else {
532
0
            dstport = curlx_ultous(port);
533
0
            p = end_ptr;
534
0
          }
535
0
        }
536
0
        if(*p++ != '\"')
537
0
          break;
538
        /* Handle the optional 'ma' and 'persist' flags. Unknown flags
539
           are skipped. */
540
0
        for(;;) {
541
0
          while(ISBLANK(*p))
542
0
            p++;
543
0
          if(*p != ';')
544
0
            break;
545
0
          p++; /* pass the semicolon */
546
0
          if(!*p || ISNEWLINE(*p))
547
0
            break;
548
0
          result = getalnum(&p, option, sizeof(option));
549
0
          if(result) {
550
            /* skip option if name is too long */
551
0
            option[0] = '\0';
552
0
          }
553
0
          while(*p && ISBLANK(*p))
554
0
            p++;
555
0
          if(*p != '=')
556
0
            return CURLE_OK;
557
0
          p++;
558
0
          while(*p && ISBLANK(*p))
559
0
            p++;
560
0
          if(!*p)
561
0
            return CURLE_OK;
562
0
          if(*p == '\"') {
563
            /* quoted value */
564
0
            p++;
565
0
            quoted = TRUE;
566
0
          }
567
0
          value_ptr = p;
568
0
          if(quoted) {
569
0
            while(*p && *p != '\"')
570
0
              p++;
571
0
            if(!*p++)
572
0
              return CURLE_OK;
573
0
          }
574
0
          else {
575
0
            while(*p && !ISBLANK(*p) && *p!= ';' && *p != ',')
576
0
              p++;
577
0
          }
578
0
          num = strtoul(value_ptr, &end_ptr, 10);
579
0
          if((end_ptr != value_ptr) && (num < ULONG_MAX)) {
580
0
            if(strcasecompare("ma", option))
581
0
              maxage = num;
582
0
            else if(strcasecompare("persist", option) && (num == 1))
583
0
              persist = TRUE;
584
0
          }
585
0
        }
586
0
        if(dstalpnid && valid) {
587
0
          if(!entries++)
588
            /* Flush cached alternatives for this source origin, if any - when
589
               this is the first entry of the line. */
590
0
            altsvc_flush(asi, srcalpnid, srchost, srcport);
591
592
0
          as = altsvc_createid(srchost, dsthost,
593
0
                               srcalpnid, dstalpnid,
594
0
                               srcport, dstport);
595
0
          if(as) {
596
            /* The expires time also needs to take the Age: value (if any) into
597
               account. [See RFC 7838 section 3.1] */
598
0
            as->expires = maxage + time(NULL);
599
0
            as->persist = persist;
600
0
            Curl_llist_insert_next(&asi->list, asi->list.tail, as, &as->node);
601
0
            infof(data, "Added alt-svc: %s:%d over %s", dsthost, dstport,
602
0
                  Curl_alpnid2str(dstalpnid));
603
0
          }
604
0
        }
605
0
      }
606
0
      else
607
0
        break;
608
      /* after the double quote there can be a comma if there's another
609
         string or a semicolon if no more */
610
0
      if(*p == ',') {
611
        /* comma means another alternative is presented */
612
0
        p++;
613
0
        result = getalnum(&p, alpnbuf, sizeof(alpnbuf));
614
0
        if(result)
615
0
          break;
616
0
      }
617
0
    }
618
0
    else
619
0
      break;
620
0
  } while(*p && (*p != ';') && (*p != '\n') && (*p != '\r'));
621
622
0
  return CURLE_OK;
623
0
}
624
625
/*
626
 * Return TRUE on a match
627
 */
628
bool Curl_altsvc_lookup(struct altsvcinfo *asi,
629
                        enum alpnid srcalpnid, const char *srchost,
630
                        int srcport,
631
                        struct altsvc **dstentry,
632
                        const int versions) /* one or more bits */
633
0
{
634
0
  struct Curl_llist_element *e;
635
0
  struct Curl_llist_element *n;
636
0
  time_t now = time(NULL);
637
0
  DEBUGASSERT(asi);
638
0
  DEBUGASSERT(srchost);
639
0
  DEBUGASSERT(dstentry);
640
641
0
  for(e = asi->list.head; e; e = n) {
642
0
    struct altsvc *as = e->ptr;
643
0
    n = e->next;
644
0
    if(as->expires < now) {
645
      /* an expired entry, remove */
646
0
      Curl_llist_remove(&asi->list, e, NULL);
647
0
      altsvc_free(as);
648
0
      continue;
649
0
    }
650
0
    if((as->src.alpnid == srcalpnid) &&
651
0
       hostcompare(srchost, as->src.host) &&
652
0
       (as->src.port == srcport) &&
653
0
       (versions & as->dst.alpnid)) {
654
      /* match */
655
0
      *dstentry = as;
656
0
      return TRUE;
657
0
    }
658
0
  }
659
0
  return FALSE;
660
0
}
661
662
#endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_ALTSVC */