• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# nghttp2 - HTTP/2 C Library
2
3# Copyright (c) 2013 Tatsuhiro Tsujikawa
4
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:
12
13# The above copyright notice and this permission notice shall be
14# included in all copies or substantial portions of the Software.
15
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.
23from libc.stdint cimport uint8_t, uint16_t, uint32_t, int32_t
24
25cdef extern from 'nghttp2/nghttp2.h':
26
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
31
32    ctypedef struct nghttp2_session:
33        pass
34
35    ctypedef enum nghttp2_error:
36        NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE
37        NGHTTP2_ERR_DEFERRED
38
39    ctypedef enum nghttp2_flag:
40        NGHTTP2_FLAG_NONE
41        NGHTTP2_FLAG_END_STREAM
42        NGHTTP2_FLAG_ACK
43
44    ctypedef enum nghttp2_error_code:
45        NGHTTP2_NO_ERROR
46        NGHTTP2_PROTOCOL_ERROR
47        NGHTTP2_INTERNAL_ERROR
48        NGHTTP2_SETTINGS_TIMEOUT
49
50    ctypedef enum nghttp2_frame_type:
51        NGHTTP2_DATA
52        NGHTTP2_HEADERS
53        NGHTTP2_RST_STREAM
54        NGHTTP2_SETTINGS
55        NGHTTP2_PUSH_PROMISE
56        NGHTTP2_GOAWAY
57
58    ctypedef enum nghttp2_nv_flag:
59        NGHTTP2_NV_FLAG_NONE
60        NGHTTP2_NV_FLAG_NO_INDEX
61
62    ctypedef struct nghttp2_nv:
63        uint8_t *name
64        uint8_t *value
65        uint16_t namelen
66        uint16_t valuelen
67        uint8_t flags
68
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
75
76    ctypedef struct nghttp2_settings_entry:
77        int32_t settings_id
78        uint32_t value
79
80    ctypedef struct nghttp2_frame_hd:
81        size_t length
82        int32_t stream_id
83        uint8_t type
84        uint8_t flags
85
86    ctypedef struct nghttp2_data:
87        nghttp2_frame_hd hd
88        size_t padlen
89
90    ctypedef enum nghttp2_headers_category:
91        NGHTTP2_HCAT_REQUEST
92        NGHTTP2_HCAT_RESPONSE
93        NGHTTP2_HCAT_PUSH_RESPONSE
94        NGHTTP2_HCAT_HEADERS
95
96    ctypedef struct nghttp2_headers:
97        nghttp2_frame_hd hd
98        size_t padlen
99        nghttp2_nv *nva
100        size_t nvlen
101        nghttp2_headers_category cat
102        int32_t pri
103
104    ctypedef struct nghttp2_rst_stream:
105        nghttp2_frame_hd hd
106        uint32_t error_code
107
108
109    ctypedef struct nghttp2_push_promise:
110        nghttp2_frame_hd hd
111        nghttp2_nv *nva
112        size_t nvlen
113        int32_t promised_stream_id
114
115    ctypedef struct nghttp2_goaway:
116        nghttp2_frame_hd hd
117        int32_t last_stream_id
118        uint32_t error_code
119        uint8_t *opaque_data
120        size_t opaque_data_len
121
122    ctypedef union nghttp2_frame:
123        nghttp2_frame_hd hd
124        nghttp2_data data
125        nghttp2_headers headers
126        nghttp2_rst_stream rst_stream
127        nghttp2_push_promise push_promise
128        nghttp2_goaway goaway
129
130    ctypedef ssize_t (*nghttp2_send_callback)\
131        (nghttp2_session *session, const uint8_t *data, size_t length,
132         int flags, void *user_data)
133
134    ctypedef int (*nghttp2_on_frame_recv_callback)\
135        (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
136
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)
140
141    ctypedef int (*nghttp2_before_frame_send_callback)\
142        (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
143
144    ctypedef int (*nghttp2_on_stream_close_callback)\
145        (nghttp2_session *session, int32_t stream_id,
146         uint32_t error_code, void *user_data)
147
148    ctypedef int (*nghttp2_on_begin_headers_callback)\
149        (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
150
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,
156         uint8_t flags,
157         void *user_data)
158
159    ctypedef int (*nghttp2_on_frame_send_callback)\
160        (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
161
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)
165
166    ctypedef struct nghttp2_session_callbacks:
167        pass
168
169    int nghttp2_session_callbacks_new(
170        nghttp2_session_callbacks **callbacks_ptr)
171
172    void nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks)
173
174    void nghttp2_session_callbacks_set_send_callback(
175        nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback)
176
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)
180
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)
184
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)
188
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)
192
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)
196
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)
200
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)
204
205    void nghttp2_session_callbacks_set_on_header_callback(
206        nghttp2_session_callbacks *cbs,
207        nghttp2_on_header_callback on_header_callback)
208
209    int nghttp2_session_client_new(nghttp2_session **session_ptr,
210                                   const nghttp2_session_callbacks *callbacks,
211                                   void *user_data)
212
213    int nghttp2_session_server_new(nghttp2_session **session_ptr,
214                                   const nghttp2_session_callbacks *callbacks,
215                                   void *user_data)
216
217    void nghttp2_session_del(nghttp2_session *session)
218
219
220    ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
221                                     const uint8_t *data, size_t datalen)
222
223    ssize_t nghttp2_session_mem_send(nghttp2_session *session,
224                                     const uint8_t **data_ptr)
225
226    int nghttp2_session_send(nghttp2_session *session)
227
228    int nghttp2_session_want_read(nghttp2_session *session)
229
230    int nghttp2_session_want_write(nghttp2_session *session)
231
232    ctypedef union nghttp2_data_source:
233        int fd
234        void *ptr
235
236    ctypedef enum nghttp2_data_flag:
237        NGHTTP2_DATA_FLAG_NONE
238        NGHTTP2_DATA_FLAG_EOF
239
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)
244
245    ctypedef struct nghttp2_data_provider:
246        nghttp2_data_source source
247        nghttp2_data_source_read_callback read_callback
248
249    ctypedef struct nghttp2_priority_spec:
250        int32_t stream_id
251        int32_t weight
252        uint8_t exclusive
253
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)
258
259    int nghttp2_submit_response(nghttp2_session *session,
260                                int32_t stream_id,
261                                const nghttp2_nv *nva, size_t nvlen,
262                                const nghttp2_data_provider *data_prd)
263
264    int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
265                                    int32_t stream_id,
266                                    const nghttp2_nv *nva, size_t nvlen,
267                                    void *stream_user_data)
268
269    int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
270                                const nghttp2_settings_entry *iv, size_t niv)
271
272    int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags,
273                                  int32_t stream_id,
274                                  uint32_t error_code)
275
276    void* nghttp2_session_get_stream_user_data(nghttp2_session *session,
277                                               uint32_t stream_id)
278
279    int nghttp2_session_set_stream_user_data(nghttp2_session *session,
280                                             uint32_t stream_id,
281                                             void *stream_user_data)
282
283    int nghttp2_session_terminate_session(nghttp2_session *session,
284                                          uint32_t error_code)
285
286    int nghttp2_session_resume_data(nghttp2_session *session,
287                                    int32_t stream_id)
288
289    const char* nghttp2_strerror(int lib_error_code)
290
291    int nghttp2_session_check_server_session(nghttp2_session *session)
292
293    int nghttp2_session_get_stream_remote_close(nghttp2_session *session, int32_t stream_id)
294
295    int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
296                               size_t deflate_hd_table_bufsize_max)
297
298    void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater)
299
300    int nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
301                                             size_t hd_table_bufsize_max)
302
303    ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
304                                  uint8_t *buf, size_t buflen,
305                                  const nghttp2_nv *nva, size_t nvlen)
306
307    size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
308                                    const nghttp2_nv *nva, size_t nvlen)
309
310    int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr)
311
312    void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater)
313
314    int nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
315                                             size_t hd_table_bufsize_max)
316
317    ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater,
318                                   nghttp2_nv *nv_out, int *inflate_flags,
319                                   const uint8_t *input, size_t inlen,
320                                   int in_final)
321
322    int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater)
323
324    ctypedef enum nghttp2_hd_inflate_flag:
325        NGHTTP2_HD_INFLATE_EMIT
326        NGHTTP2_HD_INFLATE_FINAL
327
328    ctypedef struct nghttp2_hd_deflater:
329        pass
330
331    ctypedef struct nghttp2_hd_inflater:
332        pass
333
334    size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater)
335
336    const nghttp2_nv * nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx)
337
338    size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater)
339
340    const nghttp2_nv *nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx)
341