gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
hpack_parser.h
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 
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;
55 
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  /* the value we're currently parsing */
66  union {
67  gpr_uint32 *value;
69  } parsing;
70  /* string parameters for each chunk */
73  /* parsed index */
74  gpr_uint32 index;
75  /* length of source bytes for the currently parsing string */
76  gpr_uint32 strlen;
77  /* number of source bytes read for the currently parsing string */
78  gpr_uint32 strgot;
79  /* huffman decoding state */
80  gpr_uint16 huff_state;
81  /* is the string being decoded binary? */
82  gpr_uint8 binary;
83  /* is the current string huffman encoded? */
84  gpr_uint8 huff;
85  /* set by higher layers, used by grpc_chttp2_header_parser_parse to signal
86  it should append a metadata boundary at the end of frame */
87  gpr_uint8 is_boundary;
88  gpr_uint8 is_eof;
89  gpr_uint32 base64_buffer;
90 
91  /* hpack table */
92  grpc_chttp2_hptbl table;
93 };
94 
95 void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p,
96  grpc_mdctx *mdctx);
97 void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p);
98 
99 void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p);
100 
101 /* returns 1 on success, 0 on error */
102 int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p,
103  const gpr_uint8 *beg, const gpr_uint8 *end);
104 
105 /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for
106  the transport */
107 grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
108  void *hpack_parser, grpc_chttp2_parse_state *state, gpr_slice slice,
109  int is_last);
110 
111 #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HPACK_PARSER_H */
Definition: hpack_table.h:59
Definition: hpack_parser.h:56
Definition: frame.h:48
Definition: metadata.c:83
Definition: metadata.h:78
Definition: hpack_parser.h:50
Definition: slice.h:79