1 /*
2 * nghttp2 - HTTP/2 C Library
3 *
4 * Copyright (c) 2014 Tatsuhiro Tsujikawa
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #include "nghttp2_callbacks.h"
26
27 #include <stdlib.h>
28
nghttp2_session_callbacks_new(nghttp2_session_callbacks ** callbacks_ptr)29 int nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr) {
30 *callbacks_ptr = calloc(1, sizeof(nghttp2_session_callbacks));
31
32 if (*callbacks_ptr == NULL) {
33 return NGHTTP2_ERR_NOMEM;
34 }
35
36 return 0;
37 }
38
nghttp2_session_callbacks_del(nghttp2_session_callbacks * callbacks)39 void nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks) {
40 free(callbacks);
41 }
42
nghttp2_session_callbacks_set_send_callback(nghttp2_session_callbacks * cbs,nghttp2_send_callback send_callback)43 void nghttp2_session_callbacks_set_send_callback(
44 nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback) {
45 cbs->send_callback = send_callback;
46 }
47
nghttp2_session_callbacks_set_recv_callback(nghttp2_session_callbacks * cbs,nghttp2_recv_callback recv_callback)48 void nghttp2_session_callbacks_set_recv_callback(
49 nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback) {
50 cbs->recv_callback = recv_callback;
51 }
52
nghttp2_session_callbacks_set_on_frame_recv_callback(nghttp2_session_callbacks * cbs,nghttp2_on_frame_recv_callback on_frame_recv_callback)53 void nghttp2_session_callbacks_set_on_frame_recv_callback(
54 nghttp2_session_callbacks *cbs,
55 nghttp2_on_frame_recv_callback on_frame_recv_callback) {
56 cbs->on_frame_recv_callback = on_frame_recv_callback;
57 }
58
nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(nghttp2_session_callbacks * cbs,nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback)59 void nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(
60 nghttp2_session_callbacks *cbs,
61 nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback) {
62 cbs->on_invalid_frame_recv_callback = on_invalid_frame_recv_callback;
63 }
64
nghttp2_session_callbacks_set_on_data_chunk_recv_callback(nghttp2_session_callbacks * cbs,nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback)65 void nghttp2_session_callbacks_set_on_data_chunk_recv_callback(
66 nghttp2_session_callbacks *cbs,
67 nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback) {
68 cbs->on_data_chunk_recv_callback = on_data_chunk_recv_callback;
69 }
70
nghttp2_session_callbacks_set_before_frame_send_callback(nghttp2_session_callbacks * cbs,nghttp2_before_frame_send_callback before_frame_send_callback)71 void nghttp2_session_callbacks_set_before_frame_send_callback(
72 nghttp2_session_callbacks *cbs,
73 nghttp2_before_frame_send_callback before_frame_send_callback) {
74 cbs->before_frame_send_callback = before_frame_send_callback;
75 }
76
nghttp2_session_callbacks_set_on_frame_send_callback(nghttp2_session_callbacks * cbs,nghttp2_on_frame_send_callback on_frame_send_callback)77 void nghttp2_session_callbacks_set_on_frame_send_callback(
78 nghttp2_session_callbacks *cbs,
79 nghttp2_on_frame_send_callback on_frame_send_callback) {
80 cbs->on_frame_send_callback = on_frame_send_callback;
81 }
82
nghttp2_session_callbacks_set_on_frame_not_send_callback(nghttp2_session_callbacks * cbs,nghttp2_on_frame_not_send_callback on_frame_not_send_callback)83 void nghttp2_session_callbacks_set_on_frame_not_send_callback(
84 nghttp2_session_callbacks *cbs,
85 nghttp2_on_frame_not_send_callback on_frame_not_send_callback) {
86 cbs->on_frame_not_send_callback = on_frame_not_send_callback;
87 }
88
nghttp2_session_callbacks_set_on_stream_close_callback(nghttp2_session_callbacks * cbs,nghttp2_on_stream_close_callback on_stream_close_callback)89 void nghttp2_session_callbacks_set_on_stream_close_callback(
90 nghttp2_session_callbacks *cbs,
91 nghttp2_on_stream_close_callback on_stream_close_callback) {
92 cbs->on_stream_close_callback = on_stream_close_callback;
93 }
94
nghttp2_session_callbacks_set_on_begin_headers_callback(nghttp2_session_callbacks * cbs,nghttp2_on_begin_headers_callback on_begin_headers_callback)95 void nghttp2_session_callbacks_set_on_begin_headers_callback(
96 nghttp2_session_callbacks *cbs,
97 nghttp2_on_begin_headers_callback on_begin_headers_callback) {
98 cbs->on_begin_headers_callback = on_begin_headers_callback;
99 }
100
nghttp2_session_callbacks_set_on_header_callback(nghttp2_session_callbacks * cbs,nghttp2_on_header_callback on_header_callback)101 void nghttp2_session_callbacks_set_on_header_callback(
102 nghttp2_session_callbacks *cbs,
103 nghttp2_on_header_callback on_header_callback) {
104 cbs->on_header_callback = on_header_callback;
105 }
106
nghttp2_session_callbacks_set_on_header_callback2(nghttp2_session_callbacks * cbs,nghttp2_on_header_callback2 on_header_callback2)107 void nghttp2_session_callbacks_set_on_header_callback2(
108 nghttp2_session_callbacks *cbs,
109 nghttp2_on_header_callback2 on_header_callback2) {
110 cbs->on_header_callback2 = on_header_callback2;
111 }
112
nghttp2_session_callbacks_set_on_invalid_header_callback(nghttp2_session_callbacks * cbs,nghttp2_on_invalid_header_callback on_invalid_header_callback)113 void nghttp2_session_callbacks_set_on_invalid_header_callback(
114 nghttp2_session_callbacks *cbs,
115 nghttp2_on_invalid_header_callback on_invalid_header_callback) {
116 cbs->on_invalid_header_callback = on_invalid_header_callback;
117 }
118
nghttp2_session_callbacks_set_on_invalid_header_callback2(nghttp2_session_callbacks * cbs,nghttp2_on_invalid_header_callback2 on_invalid_header_callback2)119 void nghttp2_session_callbacks_set_on_invalid_header_callback2(
120 nghttp2_session_callbacks *cbs,
121 nghttp2_on_invalid_header_callback2 on_invalid_header_callback2) {
122 cbs->on_invalid_header_callback2 = on_invalid_header_callback2;
123 }
124
nghttp2_session_callbacks_set_select_padding_callback(nghttp2_session_callbacks * cbs,nghttp2_select_padding_callback select_padding_callback)125 void nghttp2_session_callbacks_set_select_padding_callback(
126 nghttp2_session_callbacks *cbs,
127 nghttp2_select_padding_callback select_padding_callback) {
128 cbs->select_padding_callback = select_padding_callback;
129 }
130
nghttp2_session_callbacks_set_data_source_read_length_callback(nghttp2_session_callbacks * cbs,nghttp2_data_source_read_length_callback data_source_read_length_callback)131 void nghttp2_session_callbacks_set_data_source_read_length_callback(
132 nghttp2_session_callbacks *cbs,
133 nghttp2_data_source_read_length_callback data_source_read_length_callback) {
134 cbs->read_length_callback = data_source_read_length_callback;
135 }
136
nghttp2_session_callbacks_set_on_begin_frame_callback(nghttp2_session_callbacks * cbs,nghttp2_on_begin_frame_callback on_begin_frame_callback)137 void nghttp2_session_callbacks_set_on_begin_frame_callback(
138 nghttp2_session_callbacks *cbs,
139 nghttp2_on_begin_frame_callback on_begin_frame_callback) {
140 cbs->on_begin_frame_callback = on_begin_frame_callback;
141 }
142
nghttp2_session_callbacks_set_send_data_callback(nghttp2_session_callbacks * cbs,nghttp2_send_data_callback send_data_callback)143 void nghttp2_session_callbacks_set_send_data_callback(
144 nghttp2_session_callbacks *cbs,
145 nghttp2_send_data_callback send_data_callback) {
146 cbs->send_data_callback = send_data_callback;
147 }
148
nghttp2_session_callbacks_set_pack_extension_callback(nghttp2_session_callbacks * cbs,nghttp2_pack_extension_callback pack_extension_callback)149 void nghttp2_session_callbacks_set_pack_extension_callback(
150 nghttp2_session_callbacks *cbs,
151 nghttp2_pack_extension_callback pack_extension_callback) {
152 cbs->pack_extension_callback = pack_extension_callback;
153 }
154
nghttp2_session_callbacks_set_unpack_extension_callback(nghttp2_session_callbacks * cbs,nghttp2_unpack_extension_callback unpack_extension_callback)155 void nghttp2_session_callbacks_set_unpack_extension_callback(
156 nghttp2_session_callbacks *cbs,
157 nghttp2_unpack_extension_callback unpack_extension_callback) {
158 cbs->unpack_extension_callback = unpack_extension_callback;
159 }
160
nghttp2_session_callbacks_set_on_extension_chunk_recv_callback(nghttp2_session_callbacks * cbs,nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback)161 void nghttp2_session_callbacks_set_on_extension_chunk_recv_callback(
162 nghttp2_session_callbacks *cbs,
163 nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback) {
164 cbs->on_extension_chunk_recv_callback = on_extension_chunk_recv_callback;
165 }
166
nghttp2_session_callbacks_set_error_callback(nghttp2_session_callbacks * cbs,nghttp2_error_callback error_callback)167 void nghttp2_session_callbacks_set_error_callback(
168 nghttp2_session_callbacks *cbs, nghttp2_error_callback error_callback) {
169 cbs->error_callback = error_callback;
170 }
171
nghttp2_session_callbacks_set_error_callback2(nghttp2_session_callbacks * cbs,nghttp2_error_callback2 error_callback2)172 void nghttp2_session_callbacks_set_error_callback2(
173 nghttp2_session_callbacks *cbs, nghttp2_error_callback2 error_callback2) {
174 cbs->error_callback2 = error_callback2;
175 }
176