summaryrefslogtreecommitdiffstats
path: root/mkstatichdtbl.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 19:37:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 19:37:08 +0000
commitd710a65c8b50bc3d4d0920dc6e865296f42edd5e (patch)
treed3bf9843448af9398b55f49a50a194bbaacd724e /mkstatichdtbl.py
parentInitial commit. (diff)
downloadnghttp2-d710a65c8b50bc3d4d0920dc6e865296f42edd5e.tar.xz
nghttp2-d710a65c8b50bc3d4d0920dc6e865296f42edd5e.zip
Adding upstream version 1.59.0.upstream/1.59.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mkstatichdtbl.py')
-rwxr-xr-xmkstatichdtbl.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/mkstatichdtbl.py b/mkstatichdtbl.py
new file mode 100755
index 0000000..20f0c15
--- /dev/null
+++ b/mkstatichdtbl.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+# -*- 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.
+#
+# [1] https://httpwg.org/specs/rfc7541.html
+
+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
+
+entries = []
+for line in sys.stdin:
+ 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))
+
+print('static nghttp2_hd_entry static_table[] = {')
+idx = 0
+for i, ent in enumerate(entries):
+ if entries[idx][1] != ent[1]:
+ idx = i
+ print('MAKE_STATIC_ENT("{}", "{}", {}, {}u),'\
+ .format(ent[1], ent[2], entries[idx][0] - 1, hd_map_hash(ent[1])))
+print('};')