aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/internal.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/internal.h')
-rw-r--r--src/daemon/internal.h201
1 files changed, 161 insertions, 40 deletions
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
index de4ae725..4749d10d 100644
--- a/src/daemon/internal.h
+++ b/src/daemon/internal.h
@@ -85,21 +85,9 @@ struct MHD_HTTP_Header
85 char *value; 85 char *value;
86 86
87 enum MHD_ValueKind kind; 87 enum MHD_ValueKind kind;
88};
89
90
91struct MHD_Access_Handler
92{
93 struct MHD_Access_Handler *next;
94
95 char *uri_prefix;
96
97 MHD_AccessHandlerCallback dh;
98 88
99 void *dh_cls;
100}; 89};
101 90
102
103/** 91/**
104 * Representation of a response. 92 * Representation of a response.
105 */ 93 */
@@ -172,7 +160,129 @@ struct MHD_Response
172 160
173}; 161};
174 162
163/**
164 * States in a state machine for a connection.
165 *
166 * Transitions are any-state to CLOSED, any state to state+1,
167 * FOOTERS_SENT to INIT. CLOSED is the terminal state and
168 * INIT the initial state.
169 *
170 * Note that transitions for *reading* happen only after
171 * the input has been processed; transitions for
172 * *writing* happen after the respective data has been
173 * put into the write buffer (the write does not have
174 * to be completed yet). A transition to CLOSED or INIT
175 * requires the write to be complete.
176 */
177enum MHD_CONNECTION_STATE
178{
179 /**
180 * Connection just started (no headers received).
181 * Waiting for the line with the request type, URL and version.
182 */
183 MHD_CONNECTION_INIT = 0,
184
185 /**
186 * 1: We got the URL (and request type and version). Wait for a header line.
187 */
188 MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1,
189
190 /**
191 * 2: We got part of a multi-line request header. Wait for the rest.
192 */
193 MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1,
194
195 /**
196 * 3: We got the request headers. Process them.
197 */
198 MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1,
199
200 /**
201 * 4: We have processed the request headers. Send 100 continue.
202 */
203 MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1,
204
205 /**
206 * 5: We have processed the headers and need to send 100 CONTINUE.
207 */
208 MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1,
209
210 /**
211 * 6: We have sent 100 CONTINUE (or do not need to). Read the message body.
212 */
213 MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1,
214
215 /**
216 * 7: We got the request body. Wait for a line of the footer.
217 */
218 MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1,
175 219
220 /**
221 * 8: We got part of a line of the footer. Wait for the
222 * rest.
223 */
224 MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1,
225
226 /**
227 * 9: We received the entire footer. Wait for a response to be queued
228 * and prepare the response headers.
229 */
230 MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1,
231
232 /**
233 * 10: We have prepared the response headers in the writ buffer.
234 * Send the response headers.
235 */
236 MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1,
237
238 /**
239 * 11: We have sent the response headers. Get ready to send the body.
240 */
241 MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
242
243 /**
244 * 12: We are ready to send a part of a non-chunked body. Send it.
245 */
246 MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
247
248 /**
249 * 13: We are waiting for the client to provide more
250 * data of a non-chunked body.
251 */
252 MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
253
254 /**
255 * 14: We are ready to send a chunk.
256 */
257 MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
258
259 /**
260 * 15: We are waiting for the client to provide a chunk of the body.
261 */
262 MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
263
264 /**
265 * 16: We have sent the response body. Prepare the footers.
266 */
267 MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
268
269 /**
270 * 17: We have prepared the response footer. Send it.
271 */
272 MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
273
274 /**
275 * 18: We have sent the response footer. Shutdown or restart.
276 */
277 MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1,
278
279 /**
280 * 19: This connection is closed (no more activity
281 * allowed).
282 */
283 MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
284
285};
176 286
177struct MHD_Connection 287struct MHD_Connection
178{ 288{
@@ -250,6 +360,21 @@ struct MHD_Connection
250 char *write_buffer; 360 char *write_buffer;
251 361
252 /** 362 /**
363 * Last incomplete header line during parsing of headers.
364 * Allocated in pool. Only valid if state is
365 * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED.
366 */
367 char *last;
368
369 /**
370 * Position after the colon on the last incomplete header
371 * line during parsing of headers.
372 * Allocated in pool. Only valid if state is
373 * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED.
374 */
375 char *colon;
376
377 /**
253 * Foreign address (of length addr_len). MALLOCED (not 378 * Foreign address (of length addr_len). MALLOCED (not
254 * in pool!). 379 * in pool!).
255 */ 380 */
@@ -292,6 +417,12 @@ struct MHD_Connection
292 size_t write_buffer_append_offset; 417 size_t write_buffer_append_offset;
293 418
294 /** 419 /**
420 * How many more bytes of the body do we expect
421 * to read? "-1" for unknown.
422 */
423 size_t remaining_upload_size;
424
425 /**
295 * Current write position in the actual response 426 * Current write position in the actual response
296 * (excluding headers, content only; should be 0 427 * (excluding headers, content only; should be 0
297 * while sending headers). 428 * while sending headers).
@@ -299,13 +430,6 @@ struct MHD_Connection
299 size_t response_write_position; 430 size_t response_write_position;
300 431
301 /** 432 /**
302 * Remaining (!) number of bytes in the upload.
303 * Set to -1 for unknown (connection will close
304 * to indicate end of upload).
305 */
306 size_t remaining_upload_size;
307
308 /**
309 * Position in the 100 CONTINUE message that 433 * Position in the 100 CONTINUE message that
310 * we need to send when receiving http 1.1 requests. 434 * we need to send when receiving http 1.1 requests.
311 */ 435 */
@@ -333,29 +457,15 @@ struct MHD_Connection
333 * Has this socket been closed for reading (i.e. 457 * Has this socket been closed for reading (i.e.
334 * other side closed the connection)? If so, 458 * other side closed the connection)? If so,
335 * we must completely close the connection once 459 * we must completely close the connection once
336 * we are done sending our response. 460 * we are done sending our response (and stop
337 */ 461 * trying to read from this socket).
338 int read_close;
339
340 /**
341 * Have we finished receiving all of the headers yet?
342 * Set to 1 once we are done processing all of the
343 * headers. Note that due to pipelining, it is
344 * possible that the NEXT request is already
345 * (partially) waiting in the read buffer.
346 */
347 int have_received_headers;
348
349 /**
350 * Have we finished receiving the data from a
351 * potential file-upload?
352 */ 462 */
353 int have_received_body; 463 int read_closed;
354 464
355 /** 465 /**
356 * Have we finished sending all of the headers yet? 466 * State in the FSM for this connection.
357 */ 467 */
358 int have_sent_headers; 468 enum MHD_CONNECTION_STATE state;
359 469
360 /** 470 /**
361 * HTTP response code. Only valid if response object 471 * HTTP response code. Only valid if response object
@@ -373,6 +483,11 @@ struct MHD_Connection
373 int response_unready; 483 int response_unready;
374 484
375 /** 485 /**
486 * Are we sending with chunked encoding?
487 */
488 int have_chunked_response;
489
490 /**
376 * Are we receiving with chunked encoding? This will be set to 491 * Are we receiving with chunked encoding? This will be set to
377 * MHD_YES after we parse the headers and are processing the body 492 * MHD_YES after we parse the headers and are processing the body
378 * with chunks. After we are done with the body and we are 493 * with chunks. After we are done with the body and we are
@@ -402,9 +517,15 @@ struct MHD_Connection
402struct MHD_Daemon 517struct MHD_Daemon
403{ 518{
404 519
405 struct MHD_Access_Handler *handlers; 520 /**
521 * Callback function for all requests.
522 */
523 MHD_AccessHandlerCallback default_handler;
406 524
407 struct MHD_Access_Handler default_handler; 525 /**
526 * Closure argument to default_handler.
527 */
528 void * default_handler_cls;
408 529
409 /** 530 /**
410 * Linked list of our current connections. 531 * Linked list of our current connections.