third_party_nghttp2/mkstatichdtbl.py

37 lines
909 B
Python
Raw Permalink Normal View History

2020-12-29 08:01:31 +00:00
#!/usr/bin/env python3
2014-10-25 09:12:49 +00:00
# -*- coding: utf-8 -*-
# This scripts reads static table entries [1] and generates
# nghttp2_hd_static_entry table. This table is used in
# lib/nghttp2_hd.c.
#
2020-12-29 08:31:46 +00:00
# [1] https://httpwg.org/specs/rfc7541.html
2014-10-25 09:12:49 +00:00
2013-10-15 16:23:10 +00:00
import re, sys
def hd_map_hash(name):
h = 2166136261
# FNV hash variant: http://isthe.com/chongo/tech/comp/fnv/
for c in name:
h ^= ord(c)
h *= 16777619
h &= 0xffffffff
return h
2014-01-07 14:41:09 +00:00
entries = []
2013-10-15 16:23:10 +00:00
for line in sys.stdin:
2014-06-14 13:24:47 +00:00
m = re.match(r'(\d+)\s+(\S+)\s+(\S.*)?', line)
val = m.group(3).strip() if m.group(3) else ''
entries.append((int(m.group(1)), m.group(2), val))
2020-12-29 08:01:31 +00:00
print('static nghttp2_hd_entry static_table[] = {')
idx = 0
for i, ent in enumerate(entries):
if entries[idx][1] != ent[1]:
idx = i
2020-12-29 08:01:31 +00:00
print('MAKE_STATIC_ENT("{}", "{}", {}, {}u),'\
.format(ent[1], ent[2], entries[idx][0] - 1, hd_map_hash(ent[1])))
print('};')