1 /* 2 * nghttp2 - HTTP/2 C Library 3 * 4 * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sublicense, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be 15 * included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 #ifndef NGHTTP2_TEST_HELPER_H 26 #define NGHTTP2_TEST_HELPER_H 27 28 #ifdef HAVE_CONFIG_H 29 # include <config.h> 30 #endif /* HAVE_CONFIG_H */ 31 32 #include "nghttp2_frame.h" 33 #include "nghttp2_hd.h" 34 #include "nghttp2_session.h" 35 36 #define MAKE_NV(NAME, VALUE) \ 37 { \ 38 (uint8_t *)(NAME), (uint8_t *)(VALUE), sizeof((NAME)) - 1, \ 39 sizeof((VALUE)) - 1, NGHTTP2_NV_FLAG_NONE \ 40 } 41 #define ARRLEN(ARR) (sizeof(ARR) / sizeof(ARR[0])) 42 43 int unpack_framebuf(nghttp2_frame *frame, nghttp2_bufs *bufs); 44 45 int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len); 46 47 int strmemeq(const char *a, const uint8_t *b, size_t bn); 48 49 int nvnameeq(const char *a, nghttp2_nv *nv); 50 51 int nvvalueeq(const char *a, nghttp2_nv *nv); 52 53 typedef struct { 54 nghttp2_nv nva[256]; 55 size_t nvlen; 56 } nva_out; 57 58 void nva_out_init(nva_out *out); 59 void nva_out_reset(nva_out *out, nghttp2_mem *mem); 60 61 void add_out(nva_out *out, nghttp2_nv *nv, nghttp2_mem *mem); 62 63 nghttp2_ssize inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, 64 nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem); 65 66 int pack_headers(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater, 67 int32_t stream_id, uint8_t flags, const nghttp2_nv *nva, 68 size_t nvlen, nghttp2_mem *mem); 69 70 int pack_push_promise(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater, 71 int32_t stream_id, uint8_t flags, 72 int32_t promised_stream_id, const nghttp2_nv *nva, 73 size_t nvlen, nghttp2_mem *mem); 74 75 int frame_pack_bufs_init(nghttp2_bufs *bufs); 76 77 void bufs_large_init(nghttp2_bufs *bufs, size_t chunk_size); 78 79 nghttp2_stream *open_stream(nghttp2_session *session, int32_t stream_id); 80 81 nghttp2_stream *open_stream_with_dep(nghttp2_session *session, 82 int32_t stream_id, 83 nghttp2_stream *dep_stream); 84 85 nghttp2_stream *open_stream_with_dep_weight(nghttp2_session *session, 86 int32_t stream_id, int32_t weight, 87 nghttp2_stream *dep_stream); 88 89 nghttp2_stream *open_stream_with_dep_excl(nghttp2_session *session, 90 int32_t stream_id, 91 nghttp2_stream *dep_stream); 92 93 nghttp2_outbound_item *create_data_ob_item(nghttp2_mem *mem); 94 95 /* Opens stream. This stream is assumed to be sent from |session|, 96 and session->last_sent_stream_id and session->next_stream_id will 97 be adjusted accordingly. */ 98 nghttp2_stream *open_sent_stream(nghttp2_session *session, int32_t stream_id); 99 100 nghttp2_stream *open_sent_stream2(nghttp2_session *session, int32_t stream_id, 101 nghttp2_stream_state initial_state); 102 103 nghttp2_stream *open_sent_stream3(nghttp2_session *session, int32_t stream_id, 104 uint8_t flags, 105 nghttp2_priority_spec *pri_spec_in, 106 nghttp2_stream_state initial_state, 107 void *stream_user_data); 108 109 nghttp2_stream *open_sent_stream_with_dep(nghttp2_session *session, 110 int32_t stream_id, 111 nghttp2_stream *dep_stream); 112 113 nghttp2_stream *open_sent_stream_with_dep_weight(nghttp2_session *session, 114 int32_t stream_id, 115 int32_t weight, 116 nghttp2_stream *dep_stream); 117 118 /* Opens stream. This stream is assumed to be received by |session|, 119 and session->last_recv_stream_id will be adjusted accordingly. */ 120 nghttp2_stream *open_recv_stream(nghttp2_session *session, int32_t stream_id); 121 122 nghttp2_stream *open_recv_stream2(nghttp2_session *session, int32_t stream_id, 123 nghttp2_stream_state initial_state); 124 125 nghttp2_stream *open_recv_stream3(nghttp2_session *session, int32_t stream_id, 126 uint8_t flags, 127 nghttp2_priority_spec *pri_spec_in, 128 nghttp2_stream_state initial_state, 129 void *stream_user_data); 130 131 nghttp2_stream *open_recv_stream_with_dep(nghttp2_session *session, 132 int32_t stream_id, 133 nghttp2_stream *dep_stream); 134 135 nghttp2_stream *open_recv_stream_with_dep_weight(nghttp2_session *session, 136 int32_t stream_id, 137 int32_t weight, 138 nghttp2_stream *dep_stream); 139 140 #endif /* NGHTTP2_TEST_HELPER_H */ 141