blob: da404a42c68b65d5062fb3d9e1b329c35a480d7e [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
David Garcia Quintas3598d442016-03-15 14:53:05 -07003 * Copyright 2015-2016, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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
Craig Tiller9a4dddd2016-03-25 17:08:13 -070034#ifndef GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_DATA_H
35#define GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_DATA_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
37/* Parser for GRPC streams embedded in DATA frames */
38
39#include <grpc/support/slice.h>
40#include <grpc/support/slice_buffer.h>
Craig Tiller9533d042016-03-25 17:11:06 -070041#include "src/core/lib/iomgr/exec_ctx.h"
42#include "src/core/lib/transport/byte_stream.h"
43#include "src/core/lib/transport/chttp2/frame.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080044
Craig Tillera82950e2015-09-22 12:33:20 -070045typedef enum {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080046 GRPC_CHTTP2_DATA_FH_0,
47 GRPC_CHTTP2_DATA_FH_1,
48 GRPC_CHTTP2_DATA_FH_2,
49 GRPC_CHTTP2_DATA_FH_3,
50 GRPC_CHTTP2_DATA_FH_4,
51 GRPC_CHTTP2_DATA_FRAME
52} grpc_chttp2_stream_state;
53
Craig Tiller9d35a1f2015-11-02 14:16:12 -080054typedef struct grpc_chttp2_incoming_byte_stream
55 grpc_chttp2_incoming_byte_stream;
56
57typedef struct grpc_chttp2_incoming_frame_queue {
58 grpc_chttp2_incoming_byte_stream *head;
59 grpc_chttp2_incoming_byte_stream *tail;
60} grpc_chttp2_incoming_frame_queue;
61
Craig Tillera82950e2015-09-22 12:33:20 -070062typedef struct {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080063 grpc_chttp2_stream_state state;
Craig Tiller7536af02015-12-22 13:49:30 -080064 uint8_t is_last_frame;
65 uint8_t frame_type;
66 uint32_t frame_size;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080067
David Garcia Quintas55b4ea12015-06-16 14:27:32 -070068 int is_frame_compressed;
Craig Tiller9d35a1f2015-11-02 14:16:12 -080069 grpc_chttp2_incoming_frame_queue incoming_frames;
70 grpc_chttp2_incoming_byte_stream *parsing_frame;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080071} grpc_chttp2_data_parser;
72
Craig Tiller9d35a1f2015-11-02 14:16:12 -080073void grpc_chttp2_incoming_frame_queue_merge(
74 grpc_chttp2_incoming_frame_queue *head_dst,
75 grpc_chttp2_incoming_frame_queue *tail_src);
76grpc_byte_stream *grpc_chttp2_incoming_frame_queue_pop(
77 grpc_chttp2_incoming_frame_queue *q);
78
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080079/* initialize per-stream state for data frame parsing */
Craig Tillera82950e2015-09-22 12:33:20 -070080grpc_chttp2_parse_error grpc_chttp2_data_parser_init(
81 grpc_chttp2_data_parser *parser);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080082
Craig Tiller7be556e2015-11-06 12:29:33 -080083void grpc_chttp2_data_parser_destroy(grpc_exec_ctx *exec_ctx,
84 grpc_chttp2_data_parser *parser);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080085
86/* start processing a new data frame */
Craig Tillera82950e2015-09-22 12:33:20 -070087grpc_chttp2_parse_error grpc_chttp2_data_parser_begin_frame(
Craig Tiller7536af02015-12-22 13:49:30 -080088 grpc_chttp2_data_parser *parser, uint8_t flags);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080089
90/* handle a slice of a data frame - is_last indicates the last slice of a
91 frame */
Craig Tillera82950e2015-09-22 12:33:20 -070092grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
93 grpc_exec_ctx *exec_ctx, void *parser,
94 grpc_chttp2_transport_parsing *transport_parsing,
95 grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080096
Craig Tiller7536af02015-12-22 13:49:30 -080097void grpc_chttp2_encode_data(uint32_t id, gpr_slice_buffer *inbuf,
98 uint32_t write_bytes, int is_eof,
Craig Tiller9d35a1f2015-11-02 14:16:12 -080099 gpr_slice_buffer *outbuf);
100
Craig Tiller9a4dddd2016-03-25 17:08:13 -0700101#endif /* GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_DATA_H */