aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/transport/chttp2/hpack_parser.c
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2015-06-29 21:53:10 +0200
committerGravatar Julien Boeuf <jboeuf@google.com>2015-06-29 21:53:10 +0200
commitaeff1b9aa052b209d894d89d4a8addcaf0d725ff (patch)
tree5c1b0c5aedad0b573a276a1297b5fda5095bae5e /src/core/transport/chttp2/hpack_parser.c
parentc141772c61af4c7f98c41ba3af8b5faa6e51939f (diff)
parenta6de02f5ef15646c12f495f11c410326d34e5dfe (diff)
Merge branch 'master' of https://github.com/grpc/grpc into slice_to_cstring
Diffstat (limited to 'src/core/transport/chttp2/hpack_parser.c')
-rw-r--r--src/core/transport/chttp2/hpack_parser.c52
1 files changed, 34 insertions, 18 deletions
diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c
index d164d0720f..c729e0f22f 100644
--- a/src/core/transport/chttp2/hpack_parser.c
+++ b/src/core/transport/chttp2/hpack_parser.c
@@ -32,6 +32,7 @@
*/
#include "src/core/transport/chttp2/hpack_parser.h"
+#include "src/core/transport/chttp2/internal.h"
#include <stddef.h>
#include <string.h>
@@ -149,10 +150,12 @@ typedef enum {
/* jump table of parse state functions -- order must match first_byte_type
above */
static const grpc_chttp2_hpack_parser_state first_byte_action[] = {
- parse_indexed_field, parse_indexed_field_x, parse_lithdr_incidx,
- parse_lithdr_incidx_x, parse_lithdr_incidx_v, parse_lithdr_notidx,
- parse_lithdr_notidx_x, parse_lithdr_notidx_v, parse_lithdr_nvridx,
- parse_lithdr_nvridx_x, parse_lithdr_nvridx_v, parse_max_tbl_size,
+ parse_indexed_field, parse_indexed_field_x,
+ parse_lithdr_incidx, parse_lithdr_incidx_x,
+ parse_lithdr_incidx_v, parse_lithdr_notidx,
+ parse_lithdr_notidx_x, parse_lithdr_notidx_v,
+ parse_lithdr_nvridx, parse_lithdr_nvridx_x,
+ parse_lithdr_nvridx_v, parse_max_tbl_size,
parse_max_tbl_size_x, parse_error};
/* indexes the first byte to a parse state function - generated by
@@ -221,7 +224,8 @@ static const gpr_uint8 first_byte_lut[256] = {
INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X, };
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X,
+};
/* state table for huffman decoding: given a state, gives an index/16 into
next_sub_tbl. Taking that index and adding the value of the nibble being
@@ -241,7 +245,8 @@ static const gpr_uint8 next_tbl[256] = {
38, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 2, 2, 26, 3, 3, 39, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 40, 2,
41, 1, 1, 1, 42, 43, 1, 1, 44, 1, 1, 1, 1, 15, 2, 2, 2, 2, 2, 2,
- 3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2, };
+ 3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2,
+};
/* next state, based upon current state and the current nibble: see above.
generated by gen_hpack_tables.c */
static const gpr_int16 next_sub_tbl[48 * 16] = {
@@ -296,7 +301,8 @@ static const gpr_int16 next_sub_tbl[48 * 16] = {
4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 245, 246, 247, 248, 249, 250, 251, 252,
253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 255, };
+ 0, 0, 255,
+};
/* emission table: indexed like next_tbl, ultimately gives the byte to be
emitted, or -1 for no byte, or 256 for end of stream
@@ -319,7 +325,8 @@ static const gpr_uint16 emit_tbl[256] = {
204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
219, 220, 221, 0, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
- 248, };
+ 248,
+};
/* generated by gen_hpack_tables.c */
static const gpr_int16 emit_sub_tbl[249 * 16] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -587,7 +594,8 @@ static const gpr_int16 emit_sub_tbl[249 * 16] = {
251, 251, 252, 252, 253, 253, 254, 254, 2, 3, 4, 5, 6, 7, 8,
11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27,
28, 29, 30, 31, 127, 220, 249, -1, 10, 10, 10, 10, 13, 13, 13,
- 13, 22, 22, 22, 22, 256, 256, 256, 256, };
+ 13, 22, 22, 22, 22, 256, 256, 256, 256,
+};
static const gpr_uint8 inverse_base64[256] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
@@ -607,7 +615,8 @@ static const gpr_uint8 inverse_base64[256] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, };
+ 255,
+};
/* emission helpers */
static void on_hdr(grpc_chttp2_hpack_parser *p, grpc_mdelem *md,
@@ -945,7 +954,7 @@ static int parse_value1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
return 1;
}
- *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 7;
+ *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 7;
if ((*cur) & 0x80) {
return parse_value2(p, cur + 1, end);
@@ -963,7 +972,7 @@ static int parse_value2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
return 1;
}
- *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 14;
+ *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 14;
if ((*cur) & 0x80) {
return parse_value3(p, cur + 1, end);
@@ -981,7 +990,7 @@ static int parse_value3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
return 1;
}
- *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 21;
+ *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 21;
if ((*cur) & 0x80) {
return parse_value4(p, cur + 1, end);
@@ -1366,8 +1375,8 @@ int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p,
}
grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
- void *hpack_parser, grpc_chttp2_parse_state *state, gpr_slice slice,
- int is_last) {
+ void *hpack_parser, grpc_chttp2_transport_parsing *transport_parsing,
+ grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last) {
grpc_chttp2_hpack_parser *parser = hpack_parser;
if (!grpc_chttp2_hpack_parser_parse(parser, GPR_SLICE_START_PTR(slice),
GPR_SLICE_END_PTR(slice))) {
@@ -1379,9 +1388,16 @@ grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
"end of header frame not aligned with a hpack record boundary");
return GRPC_CHTTP2_CONNECTION_ERROR;
}
- state->metadata_boundary = parser->is_boundary;
- state->end_of_stream = parser->is_eof;
- state->need_flush_reads = parser->is_eof;
+ if (parser->is_boundary) {
+ grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into(
+ &stream_parsing->incoming_metadata,
+ &stream_parsing->data_parser.incoming_sopb);
+ grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
+ stream_parsing);
+ }
+ if (parser->is_eof) {
+ stream_parsing->received_close = 1;
+ }
parser->on_header = on_header_not_set;
parser->on_header_user_data = NULL;
parser->is_boundary = 0xde;