aboutsummaryrefslogtreecommitdiff
path: root/src/microspdy/session.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microspdy/session.h')
-rw-r--r--src/microspdy/session.h248
1 files changed, 248 insertions, 0 deletions
diff --git a/src/microspdy/session.h b/src/microspdy/session.h
new file mode 100644
index 00000000..cdfa8d15
--- /dev/null
+++ b/src/microspdy/session.h
@@ -0,0 +1,248 @@
1/*
2 This file is part of libmicrospdy
3 Copyright (C) 2012 Andrey Uzunov
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * @file session.h
21 * @brief TCP connection/SPDY session handling
22 * @author Andrey Uzunov
23 */
24
25#ifndef SESSION_H
26#define SESSION_H
27
28#include "platform.h"
29#include "structures.h"
30
31/**
32 * Called by the daemon when the socket for the session has available
33 * data to be read. Reads data from the TLS socket and puts it to the
34 * session's read buffer. The latte
35 *
36 * @param session SPDY_Session for which data will be read.
37 * @return SPDY_YES if something was read or session's status was
38 * changed. It is possible that error occurred but was handled
39 * and the status was therefore changed.
40 * SPDY_NO if nothing happened, e.g. the subsystem wants read/
41 * write to be called again.
42 */
43int
44SPDYF_session_read (struct SPDY_Session *session);
45
46
47/**
48 * Called by the daemon when the socket for the session is ready for some
49 * data to be written to it. For one or more objects on the response
50 * queue tries to fill in the write buffer, based on the frame on the
51 * queue, and to write data to the TLS socket.
52 *
53 * @param session SPDY_Session for which data will be written.
54 * @return TODO document after changes
55 * SPDY_YES if something was written, the status was changed or
56 * response callback was called but did not provide data
57 * @return SPDY_YES if something was written, session's status was
58 * changed or response callback was called but did not provide
59 * data. It is possible that error occurred but was handled
60 * and the status was therefore changed.
61 * SPDY_NO if nothing happened, e.g. the subsystem wants read/
62 * write to be called again. However, it is possible that some
63 * frames were discarded within the call, e.g. frames belonging
64 * to a closed stream.
65 */
66int
67SPDYF_session_write (struct SPDY_Session *session, bool only_one_frame);
68
69
70/**
71 * Called by the daemon on SPDY_run to handle the data in the read and write
72 * buffer of a session. Based on the state and the content of the read
73 * buffer new frames are received and interpreted, appropriate user
74 * callbacks are called and maybe something is put on the response queue
75 * ready to be handled by session_write.
76 *
77 * @param session SPDY_Session which will be handled.
78 * @return SPDY_YES if something from the read buffers was processed,
79 * session's status was changed and/or the session was closed.
80 * SPDY_NO if nothing happened, e.g. the session is in a state,
81 * not allowing processing read buffers.
82 */
83int
84SPDYF_session_idle (struct SPDY_Session *session);
85
86
87/**
88 * This function shutdowns the socket, moves the session structure to
89 * daemon's queue for sessions to be cleaned up.
90 *
91 * @param session SPDY_Session which will be handled.
92 */
93void
94SPDYF_session_close (struct SPDY_Session *session);
95
96
97/**
98 * Called to accept new TCP connection and create SPDY session.
99 *
100 * @param daemon SPDY_Daemon whose listening socket is used.
101 * @return SPDY_NO on any kind of error while accepting new TCP connection
102 * and initializing new SPDY_Session.
103 * SPDY_YES otherwise.
104 */
105int
106SPDYF_session_accept(struct SPDY_Daemon *daemon);
107
108
109/**
110 * Puts SPDYF_Response_Queue object on the queue to be sent to the
111 * client later.
112 *
113 * @param response_to_queue linked list of objects containing SPDY
114 * frame and data to be added to the queue
115 * @param session SPDY session for which the response is sent
116 * @param consider_priority if SPDY_NO, the list will be added to the
117 * end of the queue.
118 * If SPDY_YES, the response will be added after
119 * the last previously added response with priority of the
120 * request grater or equal to that of the current one.
121 * If -1, the object will be put at the head of the queue.
122 */
123void
124SPDYF_queue_response (struct SPDYF_Response_Queue *response_to_queue,
125 struct SPDY_Session *session,
126 int consider_priority);
127
128
129/**
130 * Cleans up the TSL context for the session, closes the TCP connection,
131 * cleans up any data pointed by members of the session structure
132 * (buffers, queue of responses, etc.) and frees the memory allocated by
133 * the session itself.
134 */
135void
136SPDYF_session_destroy(struct SPDY_Session *session);
137
138
139/**
140 * Prepares GOAWAY frame to tell the client to stop creating new streams.
141 * The session should be closed soon after this call.
142 *
143 * @param session SPDY session
144 * @param status code for the GOAWAY frame
145 * @param in_front whether or not to put the frame in front of everything
146 * on the response queue
147 * @return SPDY_NO on error (not enough memory) or
148 * SPDY_YES on success
149 */
150int
151SPDYF_prepare_goaway (struct SPDY_Session *session,
152 enum SPDY_GOAWAY_STATUS status,
153 bool in_front);
154
155
156/**
157 * Prepares RST_STREAM frame to terminate a stream. This frame may or
158 * not indicate an error. The frame will be put at the head of the queue.
159 * This means that frames for this stream which are still in the queue
160 * will be discarded soon.
161 *
162 * @param session SPDY session
163 * @param stream_id stream to terminate
164 * @param status code for the RST_STREAM frame
165 * @return SPDY_NO on memory error or
166 * SPDY_YES on success
167 */
168int
169SPDYF_prepare_rst_stream (struct SPDY_Session *session,
170 uint32_t stream_id,
171 enum SPDY_RST_STREAM_STATUS status);
172
173
174/**
175 * Handler called by session_write to fill the write buffer according to
176 * the data frame waiting in the response queue.
177 * When response data is given by user callback, the lib does not know
178 * how many frames are needed. In such case this call produces
179 * another ResponseQueue object and puts it on the queue while the the
180 * user callback says that there will be more data.
181 *
182 * @return SPDY_NO on error (not enough memory or the user calback for
183 * providing response data did something wrong). If
184 * the error is unrecoverable the handler changes session's
185 * status.
186 * SPDY_YES on success
187 */
188int
189SPDYF_handler_write_data (struct SPDY_Session *session);
190
191
192/**
193 * Handler called by session_write to fill the write buffer based on the
194 * control frame (SYN_REPLY) waiting in the response queue.
195 *
196 * @param session SPDY session
197 * @return SPDY_NO on error (zlib state is broken; the session MUST be
198 * closed). If
199 * the error is unrecoverable the handler changes session's
200 * status.
201 * SPDY_YES on success
202 */
203int
204SPDYF_handler_write_syn_reply (struct SPDY_Session *session);
205
206
207/**
208 * Handler called by session_write to fill the write buffer based on the
209 * control frame (GOAWAY) waiting in the response queue.
210 *
211 * @param session SPDY session
212 * @return SPDY_NO on error (not enough memory; by specification the
213 * session must be closed
214 * soon, thus there is no need to handle the error) or
215 * SPDY_YES on success
216 */
217int
218SPDYF_handler_write_goaway (struct SPDY_Session *session);
219
220
221/**
222 * Handler called by session_write to fill the write buffer based on the
223 * control frame (RST_STREAM) waiting in the response queue.
224 *
225 * @param session SPDY session
226 * @return SPDY_NO on error (not enough memory). If
227 * the error is unrecoverable the handler changes session's
228 * status.
229 * SPDY_YES on success
230 */
231int
232SPDYF_handler_write_rst_stream (struct SPDY_Session *session);
233
234
235/**
236 * Carefully ignore the full size of frames which are not yet supported
237 * by the lib.
238 * TODO Ignoring frames containing compressed bodies means that the
239 * compress state will be corrupted on next received frame. According to
240 * the draft the lib SHOULD try to decompress data also in corrupted
241 * frames just to keep right compression state.
242 *
243 * @param session SPDY_Session whose read buffer is used.
244 */
245void
246SPDYF_handler_ignore_frame (struct SPDY_Session *session);
247
248#endif