GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hpack_parser.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HPACK_PARSER_H
35 #define GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HPACK_PARSER_H
36
37 #include <stddef.h>
38
39 #include <grpc/support/port_platform.h>
40 #include "src/core/transport/chttp2/frame.h"
41 #include "src/core/transport/chttp2/hpack_table.h"
42 #include "src/core/transport/metadata.h"
43
44 typedef struct grpc_chttp2_hpack_parser grpc_chttp2_hpack_parser;
45
46 typedef int (*grpc_chttp2_hpack_parser_state)(grpc_chttp2_hpack_parser *p,
47 const gpr_uint8 *beg,
48 const gpr_uint8 *end);
49
50 typedef struct {
51 char *str;
52 gpr_uint32 length;
53 gpr_uint32 capacity;
54 } grpc_chttp2_hpack_parser_string;
55
56 struct grpc_chttp2_hpack_parser {
57 /* user specified callback for each header output */
58 void (*on_header)(void *user_data, grpc_mdelem *md);
59 void *on_header_user_data;
60
61 /* current parse state - or a function that implements it */
62 grpc_chttp2_hpack_parser_state state;
63 /* future states dependent on the opening op code */
64 const grpc_chttp2_hpack_parser_state *next_state;
65 /* what to do after skipping prioritization data */
66 grpc_chttp2_hpack_parser_state after_prioritization;
67 /* the value we're currently parsing */
68 union {
69 gpr_uint32 *value;
70 grpc_chttp2_hpack_parser_string *str;
71 } parsing;
72 /* string parameters for each chunk */
73 grpc_chttp2_hpack_parser_string key;
74 grpc_chttp2_hpack_parser_string value;
75 /* parsed index */
76 gpr_uint32 index;
77 /* length of source bytes for the currently parsing string */
78 gpr_uint32 strlen;
79 /* number of source bytes read for the currently parsing string */
80 gpr_uint32 strgot;
81 /* huffman decoding state */
82 gpr_uint16 huff_state;
83 /* is the string being decoded binary? */
84 gpr_uint8 binary;
85 /* is the current string huffman encoded? */
86 gpr_uint8 huff;
87 /* set by higher layers, used by grpc_chttp2_header_parser_parse to signal
88 it should append a metadata boundary at the end of frame */
89 gpr_uint8 is_boundary;
90 gpr_uint8 is_eof;
91 gpr_uint32 base64_buffer;
92
93 /* hpack table */
94 grpc_chttp2_hptbl table;
95 };
96
97 void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p,
98 grpc_mdctx *mdctx);
99 void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p);
100
101 void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p);
102
103 /* returns 1 on success, 0 on error */
104 int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p,
105 const gpr_uint8 *beg, const gpr_uint8 *end);
106
107 /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for
108 the transport */
109 grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
110 void *hpack_parser, grpc_chttp2_transport_parsing *transport_parsing,
111 grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last);
112
113 #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HPACK_PARSER_H */
grpc_chttp2_hpack_parser_init
void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p, grpc_mdctx *mdctx)
Definition: hpack_parser.c:1343
port_platform.h
gpr_uint8
uint8_t gpr_uint8
Definition: port_platform.h:307
grpc_chttp2_hpack_parser_parse
int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p, const gpr_uint8 *beg, const gpr_uint8 *end)
Definition: hpack_parser.c:1368
grpc_chttp2_hptbl
Definition: hpack_table.h:59
grpc_chttp2_parse_error
grpc_chttp2_parse_error
Definition: frame.h:42
metadata.h
grpc_chttp2_hpack_parser
Definition: hpack_parser.h:56
gpr_uint32
uint32_t gpr_uint32
Definition: port_platform.h:309
grpc_chttp2_hpack_parser_string::capacity
gpr_uint32 capacity
Definition: hpack_parser.h:53
grpc_chttp2_hpack_parser::state
grpc_chttp2_hpack_parser_state state
Definition: hpack_parser.h:62
grpc_chttp2_hpack_parser::huff
gpr_uint8 huff
Definition: hpack_parser.h:86
hpack_table.h
grpc_chttp2_hpack_parser::after_prioritization
grpc_chttp2_hpack_parser_state after_prioritization
Definition: hpack_parser.h:66
grpc_chttp2_hpack_parser::huff_state
gpr_uint16 huff_state
Definition: hpack_parser.h:82
grpc_chttp2_hpack_parser::strlen
gpr_uint32 strlen
Definition: hpack_parser.h:78
grpc_chttp2_hpack_parser_string::length
gpr_uint32 length
Definition: hpack_parser.h:52
frame.h
grpc_chttp2_hpack_parser_destroy
void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p)
Definition: hpack_parser.c:1362
grpc_chttp2_hpack_parser::is_boundary
gpr_uint8 is_boundary
Definition: hpack_parser.h:89
grpc_chttp2_hpack_parser::base64_buffer
gpr_uint32 base64_buffer
Definition: hpack_parser.h:91
grpc_mdctx
Definition: metadata.c:98
grpc_chttp2_hpack_parser::binary
gpr_uint8 binary
Definition: hpack_parser.h:84
grpc_mdelem
Definition: metadata.h:78
grpc_chttp2_transport_parsing
Definition: internal.h:215
grpc_chttp2_hpack_parser::table
grpc_chttp2_hptbl table
Definition: hpack_parser.h:94
gpr_uint16
uint16_t gpr_uint16
Definition: port_platform.h:308
grpc_chttp2_hpack_parser::strgot
gpr_uint32 strgot
Definition: hpack_parser.h:80
grpc_chttp2_hpack_parser_string
Definition: hpack_parser.h:50
grpc_chttp2_hpack_parser_set_has_priority
void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p)
Definition: hpack_parser.c:1357
grpc_chttp2_hpack_parser::next_state
const grpc_chttp2_hpack_parser_state * next_state
Definition: hpack_parser.h:64
grpc_chttp2_stream_parsing
Definition: internal.h:412
grpc_chttp2_hpack_parser::on_header
void(* on_header)(void *user_data, grpc_mdelem *md)
Definition: hpack_parser.h:58
grpc_chttp2_hpack_parser_string::str
char * str
Definition: hpack_parser.h:51
grpc_chttp2_hpack_parser::value
grpc_chttp2_hpack_parser_string value
Definition: hpack_parser.h:74
grpc_chttp2_hpack_parser_state
int(* grpc_chttp2_hpack_parser_state)(grpc_chttp2_hpack_parser *p, const gpr_uint8 *beg, const gpr_uint8 *end)
Definition: hpack_parser.h:46
grpc_chttp2_hpack_parser::is_eof
gpr_uint8 is_eof
Definition: hpack_parser.h:90
grpc_chttp2_hpack_parser::key
grpc_chttp2_hpack_parser_string key
Definition: hpack_parser.h:73
grpc_chttp2_hpack_parser::index
gpr_uint32 index
Definition: hpack_parser.h:76
grpc_chttp2_hpack_parser::str
grpc_chttp2_hpack_parser_string * str
Definition: hpack_parser.h:70
grpc_chttp2_header_parser_parse
grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(void *hpack_parser, grpc_chttp2_transport_parsing *transport_parsing, grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last)
Definition: hpack_parser.c:1377
grpc_chttp2_hpack_parser::parsing
union grpc_chttp2_hpack_parser::@19 parsing
gpr_slice
Definition: slice.h:79
grpc_chttp2_hpack_parser::on_header_user_data
void * on_header_user_data
Definition: hpack_parser.h:59
grpc_chttp2_hpack_parser::value
gpr_uint32 * value
Definition: hpack_parser.h:69