diff --git a/python/cnghttp2.pxd b/python/cnghttp2.pxd index f34abb36..31218382 100644 --- a/python/cnghttp2.pxd +++ b/python/cnghttp2.pxd @@ -102,7 +102,7 @@ cdef extern from 'nghttp2/nghttp2.h': ctypedef struct nghttp2_rst_stream: nghttp2_frame_hd hd - nghttp2_error_code error_code + uint32_t error_code ctypedef struct nghttp2_push_promise: @@ -114,7 +114,7 @@ cdef extern from 'nghttp2/nghttp2.h': ctypedef struct nghttp2_goaway: nghttp2_frame_hd hd int32_t last_stream_id - nghttp2_error_code error_code + uint32_t error_code uint8_t *opaque_data size_t opaque_data_len @@ -142,7 +142,7 @@ cdef extern from 'nghttp2/nghttp2.h': ctypedef int (*nghttp2_on_stream_close_callback)\ (nghttp2_session *session, int32_t stream_id, - nghttp2_error_code error_code, void *user_data) + uint32_t error_code, void *user_data) ctypedef int (*nghttp2_on_begin_headers_callback)\ (nghttp2_session *session, const nghttp2_frame *frame, void *user_data) @@ -163,15 +163,47 @@ cdef extern from 'nghttp2/nghttp2.h': int lib_error_code, void *user_data) ctypedef struct nghttp2_session_callbacks: - nghttp2_send_callback send_callback - nghttp2_on_frame_recv_callback on_frame_recv_callback - nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback - nghttp2_before_frame_send_callback before_frame_send_callback - nghttp2_on_frame_send_callback on_frame_send_callback - nghttp2_on_frame_not_send_callback on_frame_not_send_callback - nghttp2_on_stream_close_callback on_stream_close_callback - nghttp2_on_begin_headers_callback on_begin_headers_callback - nghttp2_on_header_callback on_header_callback + pass + + int nghttp2_session_callbacks_new( + nghttp2_session_callbacks **callbacks_ptr) + + void nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks) + + void nghttp2_session_callbacks_set_send_callback( + nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback) + + void nghttp2_session_callbacks_set_on_frame_recv_callback( + nghttp2_session_callbacks *cbs, + nghttp2_on_frame_recv_callback on_frame_recv_callback) + + void nghttp2_session_callbacks_set_on_data_chunk_recv_callback( + nghttp2_session_callbacks *cbs, + nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback) + + void nghttp2_session_callbacks_set_before_frame_send_callback( + nghttp2_session_callbacks *cbs, + nghttp2_before_frame_send_callback before_frame_send_callback) + + void nghttp2_session_callbacks_set_on_frame_send_callback( + nghttp2_session_callbacks *cbs, + nghttp2_on_frame_send_callback on_frame_send_callback) + + void nghttp2_session_callbacks_set_on_frame_not_send_callback( + nghttp2_session_callbacks *cbs, + nghttp2_on_frame_not_send_callback on_frame_not_send_callback) + + void nghttp2_session_callbacks_set_on_stream_close_callback( + nghttp2_session_callbacks *cbs, + nghttp2_on_stream_close_callback on_stream_close_callback) + + void nghttp2_session_callbacks_set_on_begin_headers_callback( + nghttp2_session_callbacks *cbs, + nghttp2_on_begin_headers_callback on_begin_headers_callback) + + void nghttp2_session_callbacks_set_on_header_callback( + nghttp2_session_callbacks *cbs, + nghttp2_on_header_callback on_header_callback) int nghttp2_session_client_new(nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks, @@ -233,7 +265,7 @@ cdef extern from 'nghttp2/nghttp2.h': int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags, int32_t stream_id, - nghttp2_error_code error_code) + uint32_t error_code) void* nghttp2_session_get_stream_user_data(nghttp2_session *session, uint32_t stream_id) @@ -243,7 +275,7 @@ cdef extern from 'nghttp2/nghttp2.h': void *stream_user_data) int nghttp2_session_terminate_session(nghttp2_session *session, - nghttp2_error_code error_code) + uint32_t error_code) const char* nghttp2_strerror(int lib_error_code) diff --git a/python/nghttp2.pyx b/python/nghttp2.pyx index fa7f6e8c..22fc7532 100644 --- a/python/nghttp2.pyx +++ b/python/nghttp2.pyx @@ -430,7 +430,7 @@ cdef int server_on_frame_not_send(cnghttp2.nghttp2_session *session, cdef int server_on_stream_close(cnghttp2.nghttp2_session *session, int32_t stream_id, - cnghttp2.nghttp2_error_code error_code, + uint32_t error_code, void *user_data): cdef http2 = <_HTTP2SessionCore>user_data @@ -479,7 +479,7 @@ cdef class _HTTP2SessionCore: cdef settings_timer def __cinit__(self, transport, handler_class): - cdef cnghttp2.nghttp2_session_callbacks callbacks + cdef cnghttp2.nghttp2_session_callbacks *callbacks cdef cnghttp2.nghttp2_settings_entry iv[2] cdef int rv @@ -490,17 +490,32 @@ cdef class _HTTP2SessionCore: self.handlers = set() self.settings_timer = None - memset(&callbacks, 0, sizeof(callbacks)) - callbacks.on_header_callback = server_on_header - callbacks.on_begin_headers_callback = server_on_begin_headers - callbacks.on_frame_recv_callback = server_on_frame_recv - callbacks.on_stream_close_callback = server_on_stream_close - callbacks.on_frame_send_callback = server_on_frame_send - callbacks.on_frame_not_send_callback = server_on_frame_not_send - callbacks.on_data_chunk_recv_callback = server_on_data_chunk_recv + rv = cnghttp2.nghttp2_session_callbacks_new(&callbacks) - rv = cnghttp2.nghttp2_session_server_new(&self.session, &callbacks, + if rv != 0: + raise Exception('nghttp2_session_callbacks_new failed: {}'.format\ + (_strerror(rv))) + + cnghttp2.nghttp2_session_callbacks_set_on_header_callback( + callbacks, server_on_header) + cnghttp2.nghttp2_session_callbacks_set_on_begin_headers_callback( + callbacks, server_on_begin_headers) + cnghttp2.nghttp2_session_callbacks_set_on_frame_recv_callback( + callbacks, server_on_frame_recv) + cnghttp2.nghttp2_session_callbacks_set_on_stream_close_callback( + callbacks, server_on_stream_close) + cnghttp2.nghttp2_session_callbacks_set_on_frame_send_callback( + callbacks, server_on_frame_send) + cnghttp2.nghttp2_session_callbacks_set_on_frame_not_send_callback( + callbacks, server_on_frame_not_send) + cnghttp2.nghttp2_session_callbacks_set_on_data_chunk_recv_callback( + callbacks, server_on_data_chunk_recv) + + rv = cnghttp2.nghttp2_session_server_new(&self.session, callbacks, self) + + cnghttp2.nghttp2_session_callbacks_del(callbacks) + if rv != 0: raise Exception('nghttp2_session_server_new failed: {}'.format\ (_strerror(rv)))