|
|
@ -23,10 +23,14 @@ import subprocess |
|
|
|
import re |
|
|
|
import re |
|
|
|
import perfection |
|
|
|
import perfection |
|
|
|
|
|
|
|
|
|
|
|
# configuration: a list of either strings or 2-tuples of strings |
|
|
|
# Configuration: a list of either strings or 2-tuples of strings or 3-tuples of |
|
|
|
# a single string represents a static grpc_mdstr |
|
|
|
# strings. |
|
|
|
# a 2-tuple represents a static grpc_mdelem (and appropriate grpc_mdstrs will |
|
|
|
# A single string represents a static grpc_mdstr. |
|
|
|
# also be created) |
|
|
|
# A 2-tuple represents a static grpc_mdelem (and appropriate grpc_mdstrs will |
|
|
|
|
|
|
|
# also be created). |
|
|
|
|
|
|
|
# A 3-tuple represents a static grpc_mdelem (and appropriate grpc_mdstrs will |
|
|
|
|
|
|
|
# also be created), with the last value equivalent to the mdelem's static hpack |
|
|
|
|
|
|
|
# table index as defined by RFC 7541 |
|
|
|
|
|
|
|
|
|
|
|
CONFIG = [ |
|
|
|
CONFIG = [ |
|
|
|
# metadata strings |
|
|
|
# metadata strings |
|
|
@ -72,74 +76,74 @@ CONFIG = [ |
|
|
|
('grpc-encoding', 'deflate'), |
|
|
|
('grpc-encoding', 'deflate'), |
|
|
|
('te', 'trailers'), |
|
|
|
('te', 'trailers'), |
|
|
|
('content-type', 'application/grpc'), |
|
|
|
('content-type', 'application/grpc'), |
|
|
|
(':method', 'POST'), |
|
|
|
(':method', 'POST', 3), |
|
|
|
(':status', '200'), |
|
|
|
(':status', '200', 8), |
|
|
|
(':status', '404'), |
|
|
|
(':status', '404', 13), |
|
|
|
(':scheme', 'http'), |
|
|
|
(':scheme', 'http', 6), |
|
|
|
(':scheme', 'https'), |
|
|
|
(':scheme', 'https', 7), |
|
|
|
(':scheme', 'grpc'), |
|
|
|
(':scheme', 'grpc', 0), |
|
|
|
(':authority', ''), |
|
|
|
(':authority', '', 1), |
|
|
|
(':method', 'GET'), |
|
|
|
(':method', 'GET', 2), |
|
|
|
(':method', 'PUT'), |
|
|
|
(':method', 'PUT'), |
|
|
|
(':path', '/'), |
|
|
|
(':path', '/', 4), |
|
|
|
(':path', '/index.html'), |
|
|
|
(':path', '/index.html', 5), |
|
|
|
(':status', '204'), |
|
|
|
(':status', '204', 9), |
|
|
|
(':status', '206'), |
|
|
|
(':status', '206', 10), |
|
|
|
(':status', '304'), |
|
|
|
(':status', '304', 11), |
|
|
|
(':status', '400'), |
|
|
|
(':status', '400', 12), |
|
|
|
(':status', '500'), |
|
|
|
(':status', '500', 14), |
|
|
|
('accept-charset', ''), |
|
|
|
('accept-charset', '', 15), |
|
|
|
('accept-encoding', ''), |
|
|
|
('accept-encoding', ''), |
|
|
|
('accept-encoding', 'gzip, deflate'), |
|
|
|
('accept-encoding', 'gzip, deflate', 16), |
|
|
|
('accept-language', ''), |
|
|
|
('accept-language', '', 17), |
|
|
|
('accept-ranges', ''), |
|
|
|
('accept-ranges', '', 18), |
|
|
|
('accept', ''), |
|
|
|
('accept', '', 19), |
|
|
|
('access-control-allow-origin', ''), |
|
|
|
('access-control-allow-origin', '', 20), |
|
|
|
('age', ''), |
|
|
|
('age', '', 21), |
|
|
|
('allow', ''), |
|
|
|
('allow', '', 22), |
|
|
|
('authorization', ''), |
|
|
|
('authorization', '', 23), |
|
|
|
('cache-control', ''), |
|
|
|
('cache-control', '', 24), |
|
|
|
('content-disposition', ''), |
|
|
|
('content-disposition', '', 25), |
|
|
|
('content-encoding', 'identity'), |
|
|
|
('content-encoding', 'identity'), |
|
|
|
('content-encoding', 'gzip'), |
|
|
|
('content-encoding', 'gzip'), |
|
|
|
('content-encoding', ''), |
|
|
|
('content-encoding', '', 26), |
|
|
|
('content-language', ''), |
|
|
|
('content-language', '', 27), |
|
|
|
('content-length', ''), |
|
|
|
('content-length', '', 28), |
|
|
|
('content-location', ''), |
|
|
|
('content-location', '', 29), |
|
|
|
('content-range', ''), |
|
|
|
('content-range', '', 30), |
|
|
|
('content-type', ''), |
|
|
|
('content-type', '', 31), |
|
|
|
('cookie', ''), |
|
|
|
('cookie', '', 32), |
|
|
|
('date', ''), |
|
|
|
('date', '', 33), |
|
|
|
('etag', ''), |
|
|
|
('etag', '', 34), |
|
|
|
('expect', ''), |
|
|
|
('expect', '', 35), |
|
|
|
('expires', ''), |
|
|
|
('expires', '', 36), |
|
|
|
('from', ''), |
|
|
|
('from', '', 37), |
|
|
|
('host', ''), |
|
|
|
('host', '', 38), |
|
|
|
('if-match', ''), |
|
|
|
('if-match', '', 39), |
|
|
|
('if-modified-since', ''), |
|
|
|
('if-modified-since', '', 40), |
|
|
|
('if-none-match', ''), |
|
|
|
('if-none-match', '', 41), |
|
|
|
('if-range', ''), |
|
|
|
('if-range', '', 42), |
|
|
|
('if-unmodified-since', ''), |
|
|
|
('if-unmodified-since', '', 43), |
|
|
|
('last-modified', ''), |
|
|
|
('last-modified', '', 44), |
|
|
|
('lb-token', ''), |
|
|
|
('lb-token', ''), |
|
|
|
('lb-cost-bin', ''), |
|
|
|
('lb-cost-bin', ''), |
|
|
|
('link', ''), |
|
|
|
('link', '', 45), |
|
|
|
('location', ''), |
|
|
|
('location', '', 46), |
|
|
|
('max-forwards', ''), |
|
|
|
('max-forwards', '', 47), |
|
|
|
('proxy-authenticate', ''), |
|
|
|
('proxy-authenticate', '', 48), |
|
|
|
('proxy-authorization', ''), |
|
|
|
('proxy-authorization', '', 49), |
|
|
|
('range', ''), |
|
|
|
('range', '', 50), |
|
|
|
('referer', ''), |
|
|
|
('referer', '', 51), |
|
|
|
('refresh', ''), |
|
|
|
('refresh', '', 52), |
|
|
|
('retry-after', ''), |
|
|
|
('retry-after', '', 53), |
|
|
|
('server', ''), |
|
|
|
('server', '', 54), |
|
|
|
('set-cookie', ''), |
|
|
|
('set-cookie', '', 55), |
|
|
|
('strict-transport-security', ''), |
|
|
|
('strict-transport-security', '', 56), |
|
|
|
('transfer-encoding', ''), |
|
|
|
('transfer-encoding', '', 57), |
|
|
|
('user-agent', ''), |
|
|
|
('user-agent', '', 58), |
|
|
|
('vary', ''), |
|
|
|
('vary', '', 59), |
|
|
|
('via', ''), |
|
|
|
('via', '', 60), |
|
|
|
('www-authenticate', ''), |
|
|
|
('www-authenticate', '', 61), |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
# Entries marked with is_default=True are ignored when counting |
|
|
|
# Entries marked with is_default=True are ignored when counting |
|
|
@ -323,6 +327,17 @@ else: |
|
|
|
os.path.dirname(sys.argv[0]), |
|
|
|
os.path.dirname(sys.argv[0]), |
|
|
|
'../../../test/core/end2end/fuzzers/hpack.dictionary'), 'w') |
|
|
|
'../../../test/core/end2end/fuzzers/hpack.dictionary'), 'w') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HPACK_H = open( |
|
|
|
|
|
|
|
os.path.join( |
|
|
|
|
|
|
|
os.path.dirname(sys.argv[0]), |
|
|
|
|
|
|
|
'../../../src/core/ext/transport/chttp2/transport/hpack_mapping.h'), |
|
|
|
|
|
|
|
'w') |
|
|
|
|
|
|
|
HPACK_C = open( |
|
|
|
|
|
|
|
os.path.join( |
|
|
|
|
|
|
|
os.path.dirname(sys.argv[0]), |
|
|
|
|
|
|
|
'../../../src/core/ext/transport/chttp2/transport/hpack_mapping.cc'), |
|
|
|
|
|
|
|
'w') |
|
|
|
|
|
|
|
|
|
|
|
# copy-paste copyright notice from this file |
|
|
|
# copy-paste copyright notice from this file |
|
|
|
with open(sys.argv[0]) as my_source: |
|
|
|
with open(sys.argv[0]) as my_source: |
|
|
|
copyright = [] |
|
|
|
copyright = [] |
|
|
@ -337,7 +352,8 @@ with open(sys.argv[0]) as my_source: |
|
|
|
if line[0] != '#': |
|
|
|
if line[0] != '#': |
|
|
|
break |
|
|
|
break |
|
|
|
copyright.append(line) |
|
|
|
copyright.append(line) |
|
|
|
put_banner([H, C], [line[2:].rstrip() for line in copyright]) |
|
|
|
put_banner([H, C, HPACK_H, HPACK_C], |
|
|
|
|
|
|
|
[line[2:].rstrip() for line in copyright]) |
|
|
|
|
|
|
|
|
|
|
|
hex_bytes = [ord(c) for c in 'abcdefABCDEF0123456789'] |
|
|
|
hex_bytes = [ord(c) for c in 'abcdefABCDEF0123456789'] |
|
|
|
|
|
|
|
|
|
|
@ -364,16 +380,44 @@ See metadata.h for an explanation of the interface here, and metadata.cc for |
|
|
|
an explanation of what's going on. |
|
|
|
an explanation of what's going on. |
|
|
|
""".splitlines()) |
|
|
|
""".splitlines()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
put_banner([HPACK_H, HPACK_C], """WARNING: Auto-generated code. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
To make changes to this file, change |
|
|
|
|
|
|
|
tools/codegen/core/gen_static_metadata.py, and then re-run it. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This file contains the mapping from the index of each metadata element in the |
|
|
|
|
|
|
|
grpc static metadata table to the index of that element in the hpack static |
|
|
|
|
|
|
|
metadata table. If the element is not contained in the static hpack table, then |
|
|
|
|
|
|
|
the returned index is 0. |
|
|
|
|
|
|
|
""".splitlines()) |
|
|
|
|
|
|
|
|
|
|
|
print >> H, '#ifndef GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H' |
|
|
|
print >> H, '#ifndef GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H' |
|
|
|
print >> H, '#define GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H' |
|
|
|
print >> H, '#define GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H' |
|
|
|
print >> H |
|
|
|
print >> H |
|
|
|
|
|
|
|
print >> H, '#include <grpc/support/port_platform.h>' |
|
|
|
|
|
|
|
print >> H |
|
|
|
print >> H, '#include "src/core/lib/transport/metadata.h"' |
|
|
|
print >> H, '#include "src/core/lib/transport/metadata.h"' |
|
|
|
print >> H |
|
|
|
print >> H |
|
|
|
|
|
|
|
print >> C, '#include <grpc/support/port_platform.h>' |
|
|
|
|
|
|
|
print >> C |
|
|
|
print >> C, '#include "src/core/lib/transport/static_metadata.h"' |
|
|
|
print >> C, '#include "src/core/lib/transport/static_metadata.h"' |
|
|
|
print >> C |
|
|
|
print >> C |
|
|
|
print >> C, '#include "src/core/lib/slice/slice_internal.h"' |
|
|
|
print >> C, '#include "src/core/lib/slice/slice_internal.h"' |
|
|
|
print >> C |
|
|
|
print >> C |
|
|
|
|
|
|
|
print >> HPACK_H, ('#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_' |
|
|
|
|
|
|
|
'MAPPING_H') |
|
|
|
|
|
|
|
print >> HPACK_H, ('#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_' |
|
|
|
|
|
|
|
'MAPPING_H') |
|
|
|
|
|
|
|
print >> HPACK_H |
|
|
|
|
|
|
|
print >> HPACK_H, '#include <grpc/support/port_platform.h>' |
|
|
|
|
|
|
|
print >> HPACK_H |
|
|
|
|
|
|
|
print >> HPACK_H, '#include "src/core/lib/transport/static_metadata.h"' |
|
|
|
|
|
|
|
print >> HPACK_H |
|
|
|
|
|
|
|
print >> HPACK_C, '#include <grpc/support/port_platform.h>' |
|
|
|
|
|
|
|
print >> HPACK_C |
|
|
|
|
|
|
|
print >> HPACK_C, ('#include ' |
|
|
|
|
|
|
|
'"src/core/ext/transport/chttp2/transport/hpack_mapping.h"') |
|
|
|
|
|
|
|
print >> HPACK_C |
|
|
|
|
|
|
|
|
|
|
|
str_ofs = 0 |
|
|
|
str_ofs = 0 |
|
|
|
id2strofs = {} |
|
|
|
id2strofs = {} |
|
|
@ -450,10 +494,28 @@ print >> H, ('extern grpc_mdelem_data ' |
|
|
|
print >> H, ('extern uintptr_t ' |
|
|
|
print >> H, ('extern uintptr_t ' |
|
|
|
'grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];') |
|
|
|
'grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];') |
|
|
|
for i, elem in enumerate(all_elems): |
|
|
|
for i, elem in enumerate(all_elems): |
|
|
|
print >> H, '/* "%s": "%s" */' % elem |
|
|
|
print >> H, '/* "%s": "%s" */' % (elem[0], elem[1]) |
|
|
|
print >> H, ('#define %s (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[%d], ' |
|
|
|
print >> H, ('#define %s (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[%d], ' |
|
|
|
'GRPC_MDELEM_STORAGE_STATIC))') % (mangle(elem).upper(), i) |
|
|
|
'GRPC_MDELEM_STORAGE_STATIC))') % (mangle(elem).upper(), i) |
|
|
|
print >> H |
|
|
|
print >> H |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print out the chttp2 mapping between static mdelem index and the hpack static |
|
|
|
|
|
|
|
# table index |
|
|
|
|
|
|
|
print >> HPACK_H, ('extern const uint8_t grpc_hpack_static_mdelem_indices[' |
|
|
|
|
|
|
|
'GRPC_STATIC_MDELEM_COUNT];') |
|
|
|
|
|
|
|
print >> HPACK_H |
|
|
|
|
|
|
|
print >> HPACK_C, ('const uint8_t grpc_hpack_static_mdelem_indices[' |
|
|
|
|
|
|
|
'GRPC_STATIC_MDELEM_COUNT] = {') |
|
|
|
|
|
|
|
indices = '' |
|
|
|
|
|
|
|
for elem in all_elems: |
|
|
|
|
|
|
|
index = 0 |
|
|
|
|
|
|
|
if len(elem) == 3: |
|
|
|
|
|
|
|
index = elem[2] |
|
|
|
|
|
|
|
indices += '%d,' % index |
|
|
|
|
|
|
|
print >> HPACK_C, ' %s' % indices |
|
|
|
|
|
|
|
print >> HPACK_C, '};' |
|
|
|
|
|
|
|
print >> HPACK_C |
|
|
|
|
|
|
|
|
|
|
|
print >> C, ('uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] ' |
|
|
|
print >> C, ('uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] ' |
|
|
|
'= {') |
|
|
|
'= {') |
|
|
|
print >> C, ' %s' % ','.join( |
|
|
|
print >> C, ' %s' % ','.join( |
|
|
@ -546,8 +608,9 @@ print >> C, '}' |
|
|
|
print >> C |
|
|
|
print >> C |
|
|
|
|
|
|
|
|
|
|
|
print >> C, 'grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {' |
|
|
|
print >> C, 'grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {' |
|
|
|
for a, b in all_elems: |
|
|
|
for elem in all_elems: |
|
|
|
print >> C, '{%s,%s},' % (slice_def(str_idx(a)), slice_def(str_idx(b))) |
|
|
|
print >> C, '{%s,%s},' % (slice_def(str_idx(elem[0])), |
|
|
|
|
|
|
|
slice_def(str_idx(elem[1]))) |
|
|
|
print >> C, '};' |
|
|
|
print >> C, '};' |
|
|
|
|
|
|
|
|
|
|
|
print >> H, 'typedef enum {' |
|
|
|
print >> H, 'typedef enum {' |
|
|
@ -599,5 +662,8 @@ print >> H, '#define GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS(algs) (GR |
|
|
|
|
|
|
|
|
|
|
|
print >> H, '#endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */' |
|
|
|
print >> H, '#endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print >> HPACK_H, ('#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_' |
|
|
|
|
|
|
|
'MAPPING_H */') |
|
|
|
|
|
|
|
|
|
|
|
H.close() |
|
|
|
H.close() |
|
|
|
C.close() |
|
|
|
C.close() |
|
|
|