00001 /** @file 00002 00003 SpdyCallbacks.h 00004 00005 @section license License 00006 00007 Licensed to the Apache Software Foundation (ASF) under one 00008 or more contributor license agreements. See the NOTICE file 00009 distributed with this work for additional information 00010 regarding copyright ownership. The ASF licenses this file 00011 to you under the Apache License, Version 2.0 (the 00012 "License"); you may not use this file except in compliance 00013 with the License. You may obtain a copy of the License at 00014 00015 http://www.apache.org/licenses/LICENSE-2.0 00016 00017 Unless required by applicable law or agreed to in writing, software 00018 distributed under the License is distributed on an "AS IS" BASIS, 00019 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 See the License for the specific language governing permissions and 00021 limitations under the License. 00022 */ 00023 00024 #ifndef __P_SPDY_CALLBACKS_H__ 00025 #define __P_SPDY_CALLBACKS_H__ 00026 00027 #include <spdylay/spdylay.h> 00028 class SpdyClientSession; 00029 00030 void spdy_callbacks_init(spdylay_session_callbacks *callbacks); 00031 void spdy_prepare_status_response_and_clean_request(SpdyClientSession *sm, int stream_id, const char *status); 00032 00033 /** 00034 * @functypedef 00035 * 00036 * Callback function invoked when |session| wants to send data to the 00037 * remote peer. The implementation of this function must send at most 00038 * |length| bytes of data stored in |data|. The |flags| is currently 00039 * not used and always 0. It must return the number of bytes sent if 00040 * it succeeds. If it cannot send any single byte without blocking, 00041 * it must return :enum:`SPDYLAY_ERR_WOULDBLOCK`. For other errors, it 00042 * must return :enum:`SPDYLAY_ERR_CALLBACK_FAILURE`. 00043 */ 00044 ssize_t spdy_send_callback 00045 (spdylay_session *session, 00046 const uint8_t *data, size_t length, int flags, void *user_data); 00047 00048 /** 00049 * @functypedef 00050 * 00051 * Callback function invoked when |session| wants to receive data from 00052 * the remote peer. The implementation of this function must read at 00053 * most |length| bytes of data and store it in |buf|. The |flags| is 00054 * currently not used and always 0. It must return the number of bytes 00055 * written in |buf| if it succeeds. If it cannot read any single byte 00056 * without blocking, it must return :enum:`SPDYLAY_ERR_WOULDBLOCK`. If 00057 * it gets EOF before it reads any single byte, it must return 00058 * :enum:`SPDYLAY_ERR_EOF`. For other errors, it must return 00059 * :enum:`SPDYLAY_ERR_CALLBACK_FAILURE`. 00060 */ 00061 ssize_t spdy_recv_callback 00062 (spdylay_session *session, 00063 uint8_t *buf, size_t length, int flags, void *user_data); 00064 00065 /** 00066 * @functypedef 00067 * 00068 * Callback function invoked by `spdylay_session_recv()` when a 00069 * control frame is received. 00070 */ 00071 void spdy_on_ctrl_recv_callback 00072 (spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, 00073 void *user_data); 00074 00075 /** 00076 * @functypedef 00077 * 00078 * Callback function invoked by `spdylay_session_recv()` when an 00079 * invalid control frame is received. The |status_code| is one of the 00080 * :enum:`spdylay_status_code` and indicates the error. When this 00081 * callback function is invoked, the library automatically submits 00082 * either RST_STREAM or GOAWAY frame. 00083 */ 00084 void spdy_on_invalid_ctrl_recv_callback 00085 (spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, 00086 uint32_t status_code, void *user_data); 00087 00088 /** 00089 * @functypedef 00090 * 00091 * Callback function invoked when a chunk of data in DATA frame is 00092 * received. The |stream_id| is the stream ID this DATA frame belongs 00093 * to. The |flags| is the flags of DATA frame which this data chunk is 00094 * contained. ``(flags & SPDYLAY_DATA_FLAG_FIN) != 0`` does not 00095 * necessarily mean this chunk of data is the last one in the 00096 * stream. You should use :type:`spdylay_on_data_recv_callback` to 00097 * know all data frames are received. 00098 */ 00099 void spdy_on_data_chunk_recv_callback 00100 (spdylay_session *session, uint8_t flags, int32_t stream_id, 00101 const uint8_t *data, size_t len, void *user_data); 00102 00103 /** 00104 * @functypedef 00105 * 00106 * Callback function invoked when DATA frame is received. The actual 00107 * data it contains are received by 00108 * :type:`spdylay_on_data_chunk_recv_callback`. 00109 */ 00110 void spdy_on_data_recv_callback 00111 (spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length, 00112 void *user_data); 00113 00114 /** 00115 * @functypedef 00116 * 00117 * Callback function invoked before the control frame |frame| of type 00118 * |type| is sent. This may be useful, for example, to know the stream 00119 * ID of SYN_STREAM frame (see also 00120 * `spdylay_session_get_stream_user_data()`), which is not assigned 00121 * when it was queued. 00122 */ 00123 void spdy_before_ctrl_send_callback 00124 (spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, 00125 void *user_data); 00126 00127 /** 00128 * @functypedef 00129 * 00130 * Callback function invoked after the control frame |frame| of type 00131 * |type| is sent. 00132 */ 00133 void spdy_on_ctrl_send_callback 00134 (spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, 00135 void *user_data); 00136 00137 /** 00138 * @functypedef 00139 * 00140 * Callback function invoked after the control frame |frame| of type 00141 * |type| is not sent because of the error. The error is indicated by 00142 * the |error_code|, which is one of the values defined in 00143 * :type:`spdylay_error`. 00144 */ 00145 void spdy_on_ctrl_not_send_callback 00146 (spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, 00147 int error_code, void *user_data); 00148 00149 /** 00150 * @functypedef 00151 * 00152 * Callback function invoked after DATA frame is sent. 00153 */ 00154 void spdy_on_data_send_callback 00155 (spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length, 00156 void *user_data); 00157 00158 /** 00159 * @functypedef 00160 * 00161 * Callback function invoked when the stream |stream_id| is 00162 * closed. The reason of closure is indicated by the 00163 * |status_code|. The stream_user_data, which was specified in 00164 * `spdylay_submit_request()` or `spdylay_submit_syn_stream()`, is 00165 * still available in this function. 00166 */ 00167 void spdy_on_stream_close_callback 00168 (spdylay_session *session, int32_t stream_id, spdylay_status_code status_code, 00169 void *user_data); 00170 00171 /** 00172 * @functypedef 00173 * 00174 * Callback function invoked when the library needs the cryptographic 00175 * proof that the client has possession of the private key associated 00176 * with the certificate for the given |origin|. If called with 00177 * |prooflen| == 0, the implementation of this function must return 00178 * the length of the proof in bytes. If called with |prooflen| > 0, 00179 * write proof into |proof| exactly |prooflen| bytes and return 0. 00180 * 00181 * Because the client certificate vector has limited number of slots, 00182 * the application code may be required to pass the same proof more 00183 * than once. 00184 */ 00185 ssize_t spdy_get_credential_proof 00186 (spdylay_session *session, const spdylay_origin *origin, 00187 uint8_t *proof, size_t prooflen, void *user_data); 00188 00189 /** 00190 * @functypedef 00191 * 00192 * Callback function invoked when the library needs the length of the 00193 * client certificate chain for the given |origin|. The 00194 * implementation of this function must return the length of the 00195 * client certificate chain. If no client certificate is required for 00196 * the given |origin|, return 0. If positive integer is returned, 00197 * :type:`spdylay_get_credential_proof` and 00198 * :type:`spdylay_get_credential_cert` callback functions will be used 00199 * to get the cryptographic proof and certificate respectively. 00200 */ 00201 ssize_t spdy_get_credential_ncerts 00202 (spdylay_session *session, const spdylay_origin *origin, void *user_data); 00203 00204 /** 00205 * @functypedef 00206 * 00207 * Callback function invoked when the library needs the client 00208 * certificate for the given |origin|. The |idx| is the index of the 00209 * certificate chain and 0 means the leaf certificate of the chain. 00210 * If called with |certlen| == 0, the implementation of this function 00211 * must return the length of the certificate in bytes. If called with 00212 * |certlen| > 0, write certificate into |cert| exactly |certlen| 00213 * bytes and return 0. 00214 */ 00215 ssize_t spdy_get_credential_cert 00216 (spdylay_session *session, const spdylay_origin *origin, size_t idx, 00217 uint8_t *cert, size_t certlen, void *user_data); 00218 00219 /** 00220 * @functypedef 00221 * 00222 * Callback function invoked when the request from the remote peer is 00223 * received. In other words, the frame with FIN flag set is received. 00224 * In HTTP, this means HTTP request, including request body, is fully 00225 * received. 00226 */ 00227 void spdy_on_request_recv_callback 00228 (spdylay_session *session, int32_t stream_id, void *user_data); 00229 00230 /** 00231 * @functypedef 00232 * 00233 * Callback function invoked when the received control frame octets 00234 * could not be parsed correctly. The |type| indicates the type of 00235 * received control frame. The |head| is the pointer to the header of 00236 * the received frame. The |headlen| is the length of the 00237 * |head|. According to the SPDY spec, the |headlen| is always 8. In 00238 * other words, the |head| is the first 8 bytes of the received frame. 00239 * The |payload| is the pointer to the data portion of the received 00240 * frame. The |payloadlen| is the length of the |payload|. This is 00241 * the data after the length field. The |error_code| is one of the 00242 * error code defined in :enum:`spdylay_error` and indicates the 00243 * error. 00244 */ 00245 void spdy_on_ctrl_recv_parse_error_callback 00246 (spdylay_session *session, spdylay_frame_type type, 00247 const uint8_t *head, size_t headlen, 00248 const uint8_t *payload, size_t payloadlen, 00249 int error_code, void *user_data); 00250 00251 /** 00252 * @functypedef 00253 * 00254 * Callback function invoked when the received control frame type is 00255 * unknown. The |head| is the pointer to the header of the received 00256 * frame. The |headlen| is the length of the |head|. According to the 00257 * SPDY spec, the |headlen| is always 8. In other words, the |head| is 00258 * the first 8 bytes of the received frame. The |payload| is the 00259 * pointer to the data portion of the received frame. The 00260 * |payloadlen| is the length of the |payload|. This is the data after 00261 * the length field. 00262 */ 00263 void spdy_on_unknown_ctrl_recv_callback 00264 (spdylay_session *session, 00265 const uint8_t *head, size_t headlen, 00266 const uint8_t *payload, size_t payloadlen, 00267 void *user_data); 00268 00269 #endif