tizen 2.4 release
[external/nghttp2.git] / python / cnghttp2.pxd
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.
23 from libc.stdint cimport uint8_t, uint16_t, uint32_t, int32_t
24
25 cdef 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
38     ctypedef enum nghttp2_flag:
39         NGHTTP2_FLAG_NONE
40         NGHTTP2_FLAG_END_STREAM
41         NGHTTP2_FLAG_ACK
42
43     ctypedef enum nghttp2_error_code:
44         NGHTTP2_NO_ERROR
45         NGHTTP2_PROTOCOL_ERROR
46         NGHTTP2_INTERNAL_ERROR
47         NGHTTP2_SETTINGS_TIMEOUT
48
49     ctypedef enum nghttp2_frame_type:
50         NGHTTP2_DATA
51         NGHTTP2_HEADERS
52         NGHTTP2_RST_STREAM
53         NGHTTP2_SETTINGS
54         NGHTTP2_PUSH_PROMISE
55         NGHTTP2_GOAWAY
56
57     ctypedef enum nghttp2_nv_flag:
58         NGHTTP2_NV_FLAG_NONE
59         NGHTTP2_NV_FLAG_NO_INDEX
60
61     ctypedef struct nghttp2_nv:
62         uint8_t *name
63         uint8_t *value
64         uint16_t namelen
65         uint16_t valuelen
66         uint8_t flags
67
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
74
75     ctypedef struct nghttp2_settings_entry:
76         int32_t settings_id
77         uint32_t value
78
79     ctypedef struct nghttp2_frame_hd:
80         size_t length
81         int32_t stream_id
82         uint8_t type
83         uint8_t flags
84
85     ctypedef struct nghttp2_data:
86         nghttp2_frame_hd hd
87         size_t padlen
88
89     ctypedef enum nghttp2_headers_category:
90         NGHTTP2_HCAT_REQUEST
91         NGHTTP2_HCAT_RESPONSE
92         NGHTTP2_HCAT_PUSH_RESPONSE
93         NGHTTP2_HCAT_HEADERS
94
95     ctypedef struct nghttp2_headers:
96         nghttp2_frame_hd hd
97         size_t padlen
98         nghttp2_nv *nva
99         size_t nvlen
100         nghttp2_headers_category cat
101         int32_t pri
102
103     ctypedef struct nghttp2_rst_stream:
104         nghttp2_frame_hd hd
105         uint32_t error_code
106
107
108     ctypedef struct nghttp2_push_promise:
109         nghttp2_frame_hd hd
110         nghttp2_nv *nva
111         size_t nvlen
112         int32_t promised_stream_id
113
114     ctypedef struct nghttp2_goaway:
115         nghttp2_frame_hd hd
116         int32_t last_stream_id
117         uint32_t error_code
118         uint8_t *opaque_data
119         size_t opaque_data_len
120
121     ctypedef union nghttp2_frame:
122         nghttp2_frame_hd hd
123         nghttp2_data data
124         nghttp2_headers headers
125         nghttp2_rst_stream rst_stream
126         nghttp2_push_promise push_promise
127         nghttp2_goaway goaway
128
129     ctypedef ssize_t (*nghttp2_send_callback)\
130         (nghttp2_session *session, const uint8_t *data, size_t length,
131          int flags, void *user_data)
132
133     ctypedef int (*nghttp2_on_frame_recv_callback)\
134         (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
135
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)
139
140     ctypedef int (*nghttp2_before_frame_send_callback)\
141         (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
142
143     ctypedef int (*nghttp2_on_stream_close_callback)\
144         (nghttp2_session *session, int32_t stream_id,
145          uint32_t error_code, void *user_data)
146
147     ctypedef int (*nghttp2_on_begin_headers_callback)\
148         (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
149
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,
155          uint8_t flags,
156          void *user_data)
157
158     ctypedef int (*nghttp2_on_frame_send_callback)\
159         (nghttp2_session *session, const nghttp2_frame *frame, void *user_data)
160
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)
164
165     ctypedef struct nghttp2_session_callbacks:
166         pass
167
168     int nghttp2_session_callbacks_new(
169         nghttp2_session_callbacks **callbacks_ptr)
170
171     void nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks)
172
173     void nghttp2_session_callbacks_set_send_callback(
174         nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback)
175
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)
179
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)
183
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)
187
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)
191
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)
195
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)
199
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)
203
204     void nghttp2_session_callbacks_set_on_header_callback(
205         nghttp2_session_callbacks *cbs,
206         nghttp2_on_header_callback on_header_callback)
207
208     int nghttp2_session_client_new(nghttp2_session **session_ptr,
209                                    const nghttp2_session_callbacks *callbacks,
210                                    void *user_data)
211
212     int nghttp2_session_server_new(nghttp2_session **session_ptr,
213                                    const nghttp2_session_callbacks *callbacks,
214                                    void *user_data)
215
216     void nghttp2_session_del(nghttp2_session *session)
217
218
219     ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
220                                      const uint8_t *data, size_t datalen)
221
222     ssize_t nghttp2_session_mem_send(nghttp2_session *session,
223                                      const uint8_t **data_ptr)
224
225     int nghttp2_session_send(nghttp2_session *session)
226
227     int nghttp2_session_want_read(nghttp2_session *session)
228
229     int nghttp2_session_want_write(nghttp2_session *session)
230
231     ctypedef union nghttp2_data_source:
232         int fd
233         void *ptr
234
235     ctypedef enum nghttp2_data_flag:
236         NGHTTP2_DATA_FLAG_NONE
237         NGHTTP2_DATA_FLAG_EOF
238
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)
243
244     ctypedef struct nghttp2_data_provider:
245         nghttp2_data_source source
246         nghttp2_data_source_read_callback read_callback
247
248     ctypedef struct nghttp2_priority_spec:
249         int32_t stream_id
250         int32_t weight
251         uint8_t exclusive
252
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)
257
258     int nghttp2_submit_response(nghttp2_session *session,
259                                 int32_t stream_id,
260                                 const nghttp2_nv *nva, size_t nvlen,
261                                 const nghttp2_data_provider *data_prd)
262
263     int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
264                                     int32_t stream_id,
265                                     const nghttp2_nv *nva, size_t nvlen,
266                                     void *stream_user_data)
267
268     int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
269                                 const nghttp2_settings_entry *iv, size_t niv)
270
271     int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags,
272                                   int32_t stream_id,
273                                   uint32_t error_code)
274
275     void* nghttp2_session_get_stream_user_data(nghttp2_session *session,
276                                                uint32_t stream_id)
277
278     int nghttp2_session_set_stream_user_data(nghttp2_session *session,
279                                              uint32_t stream_id,
280                                              void *stream_user_data)
281
282     int nghttp2_session_terminate_session(nghttp2_session *session,
283                                           uint32_t error_code)
284
285     const char* nghttp2_strerror(int lib_error_code)
286
287     int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
288                                size_t deflate_hd_table_bufsize_max)
289
290     void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater)
291
292     int nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
293                                              size_t hd_table_bufsize_max)
294
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)
298
299     size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
300                                     const nghttp2_nv *nva, size_t nvlen)
301
302     int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr)
303
304     void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater)
305
306     int nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
307                                              size_t hd_table_bufsize_max)
308
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)
312
313     int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater)
314
315 cdef extern from 'nghttp2_hd.h':
316
317     # This is macro
318     int NGHTTP2_HD_ENTRY_OVERHEAD
319
320     ctypedef enum nghttp2_hd_inflate_flag:
321         NGHTTP2_HD_INFLATE_EMIT
322         NGHTTP2_HD_INFLATE_FINAL
323
324     ctypedef struct nghttp2_hd_entry:
325         nghttp2_nv nv
326         uint8_t flags
327
328     ctypedef struct nghttp2_hd_ringbuf:
329         size_t len
330
331     ctypedef struct nghttp2_hd_context:
332         nghttp2_hd_ringbuf hd_table
333
334     ctypedef struct nghttp2_hd_deflater:
335         nghttp2_hd_context ctx
336
337     ctypedef struct nghttp2_hd_inflater:
338         nghttp2_hd_context ctx
339
340     nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context,
341                                            size_t index)