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
39 ctypedef enum nghttp2_flag:
41 NGHTTP2_FLAG_END_STREAM
44 ctypedef enum nghttp2_error_code:
46 NGHTTP2_PROTOCOL_ERROR
47 NGHTTP2_INTERNAL_ERROR
48 NGHTTP2_SETTINGS_TIMEOUT
50 ctypedef enum nghttp2_frame_type:
58 ctypedef enum nghttp2_nv_flag:
60 NGHTTP2_NV_FLAG_NO_INDEX
62 ctypedef struct nghttp2_nv:
69 ctypedef enum nghttp2_settings_id:
70 SETTINGS_HEADER_TABLE_SIZE
71 NGHTTP2_SETTINGS_HEADER_TABLE_SIZE
72 NGHTTP2_SETTINGS_ENABLE_PUSH
73 NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS
74 NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE
76 ctypedef struct nghttp2_settings_entry:
80 ctypedef struct nghttp2_frame_hd:
86 ctypedef struct nghttp2_data:
90 ctypedef enum nghttp2_headers_category:
93 NGHTTP2_HCAT_PUSH_RESPONSE
96 ctypedef struct nghttp2_headers:
101 nghttp2_headers_category cat
104 ctypedef struct nghttp2_rst_stream:
109 ctypedef struct nghttp2_push_promise:
113 int32_t promised_stream_id
115 ctypedef struct nghttp2_goaway:
117 int32_t last_stream_id
120 size_t opaque_data_len
122 ctypedef union nghttp2_frame:
125 nghttp2_headers headers
126 nghttp2_rst_stream rst_stream
127 nghttp2_push_promise push_promise
128 nghttp2_goaway goaway
130 ctypedef ssize_t (*nghttp2_send_callback)\
131 (nghttp2_session *session, const uint8_t *data, size_t length,
132 int flags, void *user_data)
134 ctypedef int (*nghttp2_on_frame_recv_callback)\
135 (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
137 ctypedef int (*nghttp2_on_data_chunk_recv_callback)\
138 (nghttp2_session *session, uint8_t flags, int32_t stream_id,
139 const uint8_t *data, size_t length, void *user_data)
141 ctypedef int (*nghttp2_before_frame_send_callback)\
142 (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
144 ctypedef int (*nghttp2_on_stream_close_callback)\
145 (nghttp2_session *session, int32_t stream_id,
146 uint32_t error_code, void *user_data)
148 ctypedef int (*nghttp2_on_begin_headers_callback)\
149 (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
151 ctypedef int (*nghttp2_on_header_callback)\
152 (nghttp2_session *session,
153 const nghttp2_frame *frame,
154 const uint8_t *name, size_t namelen,
155 const uint8_t *value, size_t valuelen,
159 ctypedef int (*nghttp2_on_frame_send_callback)\
160 (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
162 ctypedef int (*nghttp2_on_frame_not_send_callback)\
163 (nghttp2_session *session, const nghttp2_frame *frame,
164 int lib_error_code, void *user_data)
166 ctypedef struct nghttp2_session_callbacks:
169 int nghttp2_session_callbacks_new(
170 nghttp2_session_callbacks **callbacks_ptr)
172 void nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks)
174 void nghttp2_session_callbacks_set_send_callback(
175 nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback)
177 void nghttp2_session_callbacks_set_on_frame_recv_callback(
178 nghttp2_session_callbacks *cbs,
179 nghttp2_on_frame_recv_callback on_frame_recv_callback)
181 void nghttp2_session_callbacks_set_on_data_chunk_recv_callback(
182 nghttp2_session_callbacks *cbs,
183 nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback)
185 void nghttp2_session_callbacks_set_before_frame_send_callback(
186 nghttp2_session_callbacks *cbs,
187 nghttp2_before_frame_send_callback before_frame_send_callback)
189 void nghttp2_session_callbacks_set_on_frame_send_callback(
190 nghttp2_session_callbacks *cbs,
191 nghttp2_on_frame_send_callback on_frame_send_callback)
193 void nghttp2_session_callbacks_set_on_frame_not_send_callback(
194 nghttp2_session_callbacks *cbs,
195 nghttp2_on_frame_not_send_callback on_frame_not_send_callback)
197 void nghttp2_session_callbacks_set_on_stream_close_callback(
198 nghttp2_session_callbacks *cbs,
199 nghttp2_on_stream_close_callback on_stream_close_callback)
201 void nghttp2_session_callbacks_set_on_begin_headers_callback(
202 nghttp2_session_callbacks *cbs,
203 nghttp2_on_begin_headers_callback on_begin_headers_callback)
205 void nghttp2_session_callbacks_set_on_header_callback(
206 nghttp2_session_callbacks *cbs,
207 nghttp2_on_header_callback on_header_callback)
209 int nghttp2_session_client_new(nghttp2_session **session_ptr,
210 const nghttp2_session_callbacks *callbacks,
213 int nghttp2_session_server_new(nghttp2_session **session_ptr,
214 const nghttp2_session_callbacks *callbacks,
217 void nghttp2_session_del(nghttp2_session *session)
220 ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
221 const uint8_t *data, size_t datalen)
223 ssize_t nghttp2_session_mem_send(nghttp2_session *session,
224 const uint8_t **data_ptr)
226 int nghttp2_session_send(nghttp2_session *session)
228 int nghttp2_session_want_read(nghttp2_session *session)
230 int nghttp2_session_want_write(nghttp2_session *session)
232 ctypedef union nghttp2_data_source:
236 ctypedef enum nghttp2_data_flag:
237 NGHTTP2_DATA_FLAG_NONE
238 NGHTTP2_DATA_FLAG_EOF
240 ctypedef ssize_t (*nghttp2_data_source_read_callback)\
241 (nghttp2_session *session, int32_t stream_id,
242 uint8_t *buf, size_t length, uint32_t *data_flags,
243 nghttp2_data_source *source, void *user_data)
245 ctypedef struct nghttp2_data_provider:
246 nghttp2_data_source source
247 nghttp2_data_source_read_callback read_callback
249 ctypedef struct nghttp2_priority_spec:
254 int nghttp2_submit_request(nghttp2_session *session, const nghttp2_priority_spec *pri_spec,
255 const nghttp2_nv *nva, size_t nvlen,
256 const nghttp2_data_provider *data_prd,
257 void *stream_user_data)
259 int nghttp2_submit_response(nghttp2_session *session,
261 const nghttp2_nv *nva, size_t nvlen,
262 const nghttp2_data_provider *data_prd)
264 int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
266 const nghttp2_nv *nva, size_t nvlen,
267 void *stream_user_data)
269 int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
270 const nghttp2_settings_entry *iv, size_t niv)
272 int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags,
276 void* nghttp2_session_get_stream_user_data(nghttp2_session *session,
279 int nghttp2_session_set_stream_user_data(nghttp2_session *session,
281 void *stream_user_data)
283 int nghttp2_session_terminate_session(nghttp2_session *session,
286 int nghttp2_session_resume_data(nghttp2_session *session,
289 const char* nghttp2_strerror(int lib_error_code)
291 int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
292 size_t deflate_hd_table_bufsize_max)
294 void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater)
296 int nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
297 size_t hd_table_bufsize_max)
299 ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
300 uint8_t *buf, size_t buflen,
301 const nghttp2_nv *nva, size_t nvlen)
303 size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
304 const nghttp2_nv *nva, size_t nvlen)
306 int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr)
308 void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater)
310 int nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
311 size_t hd_table_bufsize_max)
313 ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
314 nghttp2_nv *nv_out, int *inflate_flags,
315 uint8_t *input, size_t inlen, int in_final)
317 int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater)
319 cdef extern from 'nghttp2_hd.h':
322 int NGHTTP2_HD_ENTRY_OVERHEAD
324 ctypedef enum nghttp2_hd_inflate_flag:
325 NGHTTP2_HD_INFLATE_EMIT
326 NGHTTP2_HD_INFLATE_FINAL
328 ctypedef struct nghttp2_hd_entry:
332 ctypedef struct nghttp2_hd_ringbuf:
335 ctypedef struct nghttp2_hd_context:
336 nghttp2_hd_ringbuf hd_table
338 ctypedef struct nghttp2_hd_deflater:
339 nghttp2_hd_context ctx
341 ctypedef struct nghttp2_hd_inflater:
342 nghttp2_hd_context ctx
344 nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context,