Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
David Garcia Quintas | 3598d44 | 2016-03-15 14:53:05 -0700 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 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 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_DATA_H |
| 35 | #define GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_DATA_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
| 37 | /* Parser for GRPC streams embedded in DATA frames */ |
| 38 | |
| 39 | #include <grpc/support/slice.h> |
| 40 | #include <grpc/support/slice_buffer.h> |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 41 | #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 Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 44 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 45 | typedef enum { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 46 | 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 Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 54 | typedef struct grpc_chttp2_incoming_byte_stream |
| 55 | grpc_chttp2_incoming_byte_stream; |
| 56 | |
| 57 | typedef 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 Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 62 | typedef struct { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 63 | grpc_chttp2_stream_state state; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 64 | uint8_t is_last_frame; |
| 65 | uint8_t frame_type; |
| 66 | uint32_t frame_size; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 67 | |
David Garcia Quintas | 55b4ea1 | 2015-06-16 14:27:32 -0700 | [diff] [blame] | 68 | int is_frame_compressed; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 69 | grpc_chttp2_incoming_frame_queue incoming_frames; |
| 70 | grpc_chttp2_incoming_byte_stream *parsing_frame; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 71 | } grpc_chttp2_data_parser; |
| 72 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 73 | void grpc_chttp2_incoming_frame_queue_merge( |
| 74 | grpc_chttp2_incoming_frame_queue *head_dst, |
| 75 | grpc_chttp2_incoming_frame_queue *tail_src); |
| 76 | grpc_byte_stream *grpc_chttp2_incoming_frame_queue_pop( |
| 77 | grpc_chttp2_incoming_frame_queue *q); |
| 78 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 79 | /* initialize per-stream state for data frame parsing */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 80 | grpc_chttp2_parse_error grpc_chttp2_data_parser_init( |
| 81 | grpc_chttp2_data_parser *parser); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 82 | |
Craig Tiller | 7be556e | 2015-11-06 12:29:33 -0800 | [diff] [blame] | 83 | void grpc_chttp2_data_parser_destroy(grpc_exec_ctx *exec_ctx, |
| 84 | grpc_chttp2_data_parser *parser); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 85 | |
| 86 | /* start processing a new data frame */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 87 | grpc_chttp2_parse_error grpc_chttp2_data_parser_begin_frame( |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 88 | grpc_chttp2_data_parser *parser, uint8_t flags); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 89 | |
| 90 | /* handle a slice of a data frame - is_last indicates the last slice of a |
| 91 | frame */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 92 | grpc_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 Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 96 | |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 97 | void grpc_chttp2_encode_data(uint32_t id, gpr_slice_buffer *inbuf, |
| 98 | uint32_t write_bytes, int is_eof, |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 99 | gpr_slice_buffer *outbuf); |
| 100 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 101 | #endif /* GRPC_CORE_LIB_TRANSPORT_CHTTP2_FRAME_DATA_H */ |