Packages
hackney
3.0.3
4.7.2
4.7.1
4.7.0
4.6.1
4.6.0
4.5.2
4.5.1
4.5.0
4.4.5
4.4.3
4.4.2
4.4.1
4.4.0
4.3.0
4.2.3
4.2.2
4.2.1
4.2.0
4.1.0
4.0.3
4.0.2
4.0.1
4.0.0
3.2.1
3.2.0
3.1.2
3.1.1
3.1.0
3.0.3
3.0.2
3.0.1
3.0.0
retired
2.0.1
2.0.0
2.0.0-beta.1
1.25.0
1.24.1
1.24.0
1.23.0
1.22.0
1.21.0
1.20.1
1.20.0
1.19.1
1.19.0
1.18.2
1.18.1
1.18.0
1.17.4
1.17.3
1.17.2
1.17.1
1.17.0
1.16.0
1.15.2
1.15.1
1.15.0
1.14.3
1.14.2
1.14.0
1.13.0
1.12.1
1.12.0
1.11.0
1.10.1
1.10.0
1.9.0
1.8.6
1.8.5
1.8.4
1.8.3
1.8.2
1.8.0
1.7.1
1.7.0
1.6.6
retired
1.6.5
1.6.4
retired
1.6.3
1.6.2
1.6.1
1.6.0
1.5.7
1.5.6
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.10
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.0
1.0.6
1.0.5
1.0.2
1.0.1
0.15.2
0.15.0
0.14.3
0.14.2
0.14.1
0.14.0
0.13.1
Simple HTTP client with HTTP/1.1, HTTP/2, and HTTP/3 support
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
c_src/lsquic/src/liblsquic/gen-verstrs.pl
#!/usr/bin/env perl
#
# Generate C file that contains version strings
($header # This is lsquic.h that contains version enum which we parse
, $outfile # This is destination C file
) = @ARGV;
open HEADER, $header
or die "cannot open $header for reading: $!";
open OUT, ">$outfile"
or die "cannot open $outfile for writing: $!";
while (<HEADER>) {
if (/^enum lsquic_version$/ .. /^}/) {
if (/^\s*(LSQVER_0*(\d+)),\s*$/ && $1 ne 'LSQVER_098') {
if ($2 < 50) {
push @enums, $1;
push @versions, $2;
}
push @all_versions, $1;
push @all_alpns, "h3-Q0$2";
}
if (/^\s*(LSQVER_ID(\d+))\b/) {
push @draft_versions, $2;
push @all_versions, $1;
push @all_alpns, "h3-$2";
}
if (/^\s*(LSQVER_I(\d{3}))\b/) {
push @all_versions, $1;
if (not grep 'h3' eq $_, @all_alpns) {
push @all_alpns, "h3";
}
}
}
}
close HEADER;
$timestamp = localtime;
print OUT <<C_CODE;
/*
* Auto-generated by $0 on $timestamp
*/
#include <assert.h>
#include <string.h>
#include "lsquic.h"
struct lsquic_engine;
static const char *const versions_to_string[ 1 << N_LSQVER ] = {
C_CODE
$max_mask = (1 << @versions) - 1;
for ($mask = 0; $mask <= $max_mask; ++$mask) {
my @indexes;
for ($i = 0; $i < @versions; ++$i) {
if ($mask & (1 << $i)) {
push @indexes, $i;
}
}
print OUT " [",
join('|', map "(1<<$_)", @enums[@indexes]) || 0,
"] = \"",
join(',', @versions[@indexes]),
"\",\n";
}
$enums = join '|', map "(1<<$_)", sort @enums;
print OUT <<"C_CODE";
};
const char *
lsquic_get_alt_svc_versions (unsigned versions)
{
/* Limit to versions in versions_to_string: */
versions &= ($enums);
return versions_to_string[ versions ];
}
C_CODE
$all_version_count_and_null = scalar(@all_versions) + 1;
print OUT <<"C_CODE";
static const struct {
unsigned versions;
const char *h3_alpns[$all_version_count_and_null];
} vers_2_h3_alnps[] = {
{ 0, { NULL }},
C_CODE
for ($i = 0; $i < (1 << @all_versions); ++$i)
{
my (@vers, @alpns);
for ($j = 0; $j < @all_versions; ++$j)
{
if ($i & (1 << $j))
{
push @vers, $all_versions[$j];
push @alpns, $all_alpns[$j];
}
}
if (@vers) {
print OUT " {", join("|", map "(1<<$_)", @vers), ", ",
"{ ", join(", ", (map qq("$_"), @alpns), "NULL"), " }},\n";
}
}
$all_versions = join "|", map "(1<<$_)", @all_versions;
print OUT <<"C_CODE";
};
const char *const *
lsquic_get_h3_alpns (unsigned versions)
{
unsigned i;
versions &= ($all_versions);
for (i = 0; i < sizeof(vers_2_h3_alnps) / sizeof(vers_2_h3_alnps[0]); ++i)
if (versions == vers_2_h3_alnps[i].versions)
return vers_2_h3_alnps[i].h3_alpns;
assert(0);
return vers_2_h3_alnps[0].h3_alpns;
}
C_CODE
print OUT <<'C_CODE';
enum lsquic_version
lsquic_alpn2ver (const char *alpn, size_t len)
{
static const struct el {
size_t len;
char alpn[10];
enum lsquic_version version;
} map[] = {
C_CODE
for ($i = 0; $i < @all_alpns; ++$i) {
print OUT " {sizeof(\"$all_alpns[$i]\")-1,\"$all_alpns[$i]\", $all_versions[$i]},\n";
}
print OUT <<'C_CODE';
};
const struct el *el;
if (alpn)
for (el = map; el < map + sizeof(map) / sizeof(map[0]); ++el)
if (el->len == len && 0 == strncmp(el->alpn, alpn, len))
return el->version;
return -1;
}
C_CODE
close OUT;