1 # nghttp2 - HTTP/2 C Library
3 # Copyright (c) 2013 Tatsuhiro Tsujikawa
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 from libc.stdint cimport uint8_t, uint16_t, uint32_t, int32_t
25 cdef extern from 'nghttp2/nghttp2.h':
27 const char NGHTTP2_PROTO_VERSION_ID[]
28 const char NGHTTP2_CLIENT_CONNECTION_PREFACE[]
29 const size_t NGHTTP2_INITIAL_WINDOW_SIZE
30 const size_t NGHTTP2_DEFAULT_HEADER_TABLE_SIZE
32 ctypedef struct nghttp2_session:
35 ctypedef enum nghttp2_error:
36 NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE
38 ctypedef enum nghttp2_flag:
40 NGHTTP2_FLAG_END_STREAM
43 ctypedef enum nghttp2_error_code:
45 NGHTTP2_PROTOCOL_ERROR
46 NGHTTP2_INTERNAL_ERROR
47 NGHTTP2_SETTINGS_TIMEOUT
49 ctypedef enum nghttp2_frame_type:
57 ctypedef enum nghttp2_nv_flag:
59 NGHTTP2_NV_FLAG_NO_INDEX
61 ctypedef struct nghttp2_nv:
68 ctypedef enum nghttp2_settings_id:
69 SETTINGS_HEADER_TABLE_SIZE
70 NGHTTP2_SETTINGS_HEADER_TABLE_SIZE
71 NGHTTP2_SETTINGS_ENABLE_PUSH
72 NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS
73 NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE
75 ctypedef struct nghttp2_settings_entry:
79 ctypedef struct nghttp2_frame_hd:
85 ctypedef struct nghttp2_data:
89 ctypedef enum nghttp2_headers_category:
92 NGHTTP2_HCAT_PUSH_RESPONSE
95 ctypedef struct nghttp2_headers:
100 nghttp2_headers_category cat
103 ctypedef struct nghttp2_rst_stream:
108 ctypedef struct nghttp2_push_promise:
112 int32_t promised_stream_id
114 ctypedef struct nghttp2_goaway:
116 int32_t last_stream_id
119 size_t opaque_data_len
121 ctypedef union nghttp2_frame:
124 nghttp2_headers headers
125 nghttp2_rst_stream rst_stream
126 nghttp2_push_promise push_promise
127 nghttp2_goaway goaway
129 ctypedef ssize_t (*nghttp2_send_callback)\
130 (nghttp2_session *session, const uint8_t *data, size_t length,
131 int flags, void *user_data)
133 ctypedef int (*nghttp2_on_frame_recv_callback)\
134 (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
136 ctypedef int (*nghttp2_on_data_chunk_recv_callback)\
137 (nghttp2_session *session, uint8_t flags, int32_t stream_id,
138 const uint8_t *data, size_t length, void *user_data)
140 ctypedef int (*nghttp2_before_frame_send_callback)\
141 (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
143 ctypedef int (*nghttp2_on_stream_close_callback)\
144 (nghttp2_session *session, int32_t stream_id,
145 uint32_t error_code, void *user_data)
147 ctypedef int (*nghttp2_on_begin_headers_callback)\
148 (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
150 ctypedef int (*nghttp2_on_header_callback)\
151 (nghttp2_session *session,
152 const nghttp2_frame *frame,
153 const uint8_t *name, size_t namelen,
154 const uint8_t *value, size_t valuelen,
158 ctypedef int (*nghttp2_on_frame_send_callback)\
159 (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
161 ctypedef int (*nghttp2_on_frame_not_send_callback)\
162 (nghttp2_session *session, const nghttp2_frame *frame,
163 int lib_error_code, void *user_data)
165 ctypedef struct nghttp2_session_callbacks:
168 int nghttp2_session_callbacks_new(
169 nghttp2_session_callbacks **callbacks_ptr)
171 void nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks)
173 void nghttp2_session_callbacks_set_send_callback(
174 nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback)
176 void nghttp2_session_callbacks_set_on_frame_recv_callback(
177 nghttp2_session_callbacks *cbs,
178 nghttp2_on_frame_recv_callback on_frame_recv_callback)
180 void nghttp2_session_callbacks_set_on_data_chunk_recv_callback(
181 nghttp2_session_callbacks *cbs,
182 nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback)
184 void nghttp2_session_callbacks_set_before_frame_send_callback(
185 nghttp2_session_callbacks *cbs,
186 nghttp2_before_frame_send_callback before_frame_send_callback)
188 void nghttp2_session_callbacks_set_on_frame_send_callback(
189 nghttp2_session_callbacks *cbs,
190 nghttp2_on_frame_send_callback on_frame_send_callback)
192 void nghttp2_session_callbacks_set_on_frame_not_send_callback(
193 nghttp2_session_callbacks *cbs,
194 nghttp2_on_frame_not_send_callback on_frame_not_send_callback)
196 void nghttp2_session_callbacks_set_on_stream_close_callback(
197 nghttp2_session_callbacks *cbs,
198 nghttp2_on_stream_close_callback on_stream_close_callback)
200 void nghttp2_session_callbacks_set_on_begin_headers_callback(
201 nghttp2_session_callbacks *cbs,
202 nghttp2_on_begin_headers_callback on_begin_headers_callback)
204 void nghttp2_session_callbacks_set_on_header_callback(
205 nghttp2_session_callbacks *cbs,
206 nghttp2_on_header_callback on_header_callback)
208 int nghttp2_session_client_new(nghttp2_session **session_ptr,
209 const nghttp2_session_callbacks *callbacks,
212 int nghttp2_session_server_new(nghttp2_session **session_ptr,
213 const nghttp2_session_callbacks *callbacks,
216 void nghttp2_session_del(nghttp2_session *session)
219 ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
220 const uint8_t *data, size_t datalen)
222 ssize_t nghttp2_session_mem_send(nghttp2_session *session,
223 const uint8_t **data_ptr)
225 int nghttp2_session_send(nghttp2_session *session)
227 int nghttp2_session_want_read(nghttp2_session *session)
229 int nghttp2_session_want_write(nghttp2_session *session)
231 ctypedef union nghttp2_data_source:
235 ctypedef enum nghttp2_data_flag:
236 NGHTTP2_DATA_FLAG_NONE
237 NGHTTP2_DATA_FLAG_EOF
239 ctypedef ssize_t (*nghttp2_data_source_read_callback)\
240 (nghttp2_session *session, int32_t stream_id,
241 uint8_t *buf, size_t length, uint32_t *data_flags,
242 nghttp2_data_source *source, void *user_data)
244 ctypedef struct nghttp2_data_provider:
245 nghttp2_data_source source
246 nghttp2_data_source_read_callback read_callback
248 ctypedef struct nghttp2_priority_spec:
253 int nghttp2_submit_request(nghttp2_session *session, const nghttp2_priority_spec *pri_spec,
254 const nghttp2_nv *nva, size_t nvlen,
255 const nghttp2_data_provider *data_prd,
256 void *stream_user_data)
258 int nghttp2_submit_response(nghttp2_session *session,
260 const nghttp2_nv *nva, size_t nvlen,
261 const nghttp2_data_provider *data_prd)
263 int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
265 const nghttp2_nv *nva, size_t nvlen,
266 void *stream_user_data)
268 int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
269 const nghttp2_settings_entry *iv, size_t niv)
271 int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags,
275 void* nghttp2_session_get_stream_user_data(nghttp2_session *session,
278 int nghttp2_session_set_stream_user_data(nghttp2_session *session,
280 void *stream_user_data)
282 int nghttp2_session_terminate_session(nghttp2_session *session,
285 const char* nghttp2_strerror(int lib_error_code)
287 int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
288 size_t deflate_hd_table_bufsize_max)
290 void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater)
292 int nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
293 size_t hd_table_bufsize_max)
295 ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
296 uint8_t *buf, size_t buflen,
297 const nghttp2_nv *nva, size_t nvlen)
299 size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
300 const nghttp2_nv *nva, size_t nvlen)
302 int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr)
304 void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater)
306 int nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
307 size_t hd_table_bufsize_max)
309 ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
310 nghttp2_nv *nv_out, int *inflate_flags,
311 uint8_t *input, size_t inlen, int in_final)
313 int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater)
315 cdef extern from 'nghttp2_hd.h':
318 int NGHTTP2_HD_ENTRY_OVERHEAD
320 ctypedef enum nghttp2_hd_inflate_flag:
321 NGHTTP2_HD_INFLATE_EMIT
322 NGHTTP2_HD_INFLATE_FINAL
324 ctypedef struct nghttp2_hd_entry:
328 ctypedef struct nghttp2_hd_ringbuf:
331 ctypedef struct nghttp2_hd_context:
332 nghttp2_hd_ringbuf hd_table
334 ctypedef struct nghttp2_hd_deflater:
335 nghttp2_hd_context ctx
337 ctypedef struct nghttp2_hd_inflater:
338 nghttp2_hd_context ctx
340 nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context,