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.h1024
1 files changed, 521 insertions, 503 deletions
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
index e22de32f..a06d7ae2 100644
--- a/src/daemon/internal.h
+++ b/src/daemon/internal.h
@@ -1,21 +1,21 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Daniel Pittman and Christian Grothoff 3 (C) 2007 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version. 8 version 2.1 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details. 13 Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU Lesser General Public 15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software 16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/ 18 */
19 19
20/** 20/**
21 * @file internal.h 21 * @file internal.h
@@ -27,7 +27,6 @@
27#ifndef INTERNAL_H 27#ifndef INTERNAL_H
28#define INTERNAL_H 28#define INTERNAL_H
29 29
30
31#include <stdio.h> 30#include <stdio.h>
32#include <stdlib.h> 31#include <stdlib.h>
33#include <string.h> 32#include <string.h>
@@ -64,101 +63,101 @@
64 * fprintf-like helper function for logging debug 63 * fprintf-like helper function for logging debug
65 * messages. 64 * messages.
66 */ 65 */
67void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...); 66void MHD_DLOG(const struct MHD_Daemon *daemon, const char *format, ...);
68#endif 67#endif
69 68
70/** 69/**
71 * Process escape sequences ('+'=space, %HH). 70 * Process escape sequences ('+'=space, %HH).
72 * Updates val in place. 71 * Updates val in place.
73 */ 72 */
74void MHD_http_unescape (char *val); 73void MHD_http_unescape(char *val);
75 74
76/** 75/**
77 * Header or cookie in HTTP request or response. 76 * Header or cookie in HTTP request or response.
78 */ 77 */
79struct MHD_HTTP_Header 78struct MHD_HTTP_Header
80{ 79 {
81 struct MHD_HTTP_Header *next; 80 struct MHD_HTTP_Header *next;
82 81
83 char *header; 82 char *header;
84 83
85 char *value; 84 char *value;
86 85
87 enum MHD_ValueKind kind; 86 enum MHD_ValueKind kind;
88 87
89}; 88 };
90 89
91/** 90/**
92 * Representation of a response. 91 * Representation of a response.
93 */ 92 */
94struct MHD_Response 93struct MHD_Response
95{ 94 {
96 95
97 /** 96 /**
98 * Headers to send for the response. Initially 97 * Headers to send for the response. Initially
99 * the linked list is created in inverse order; 98 * the linked list is created in inverse order;
100 * the order should be inverted before sending! 99 * the order should be inverted before sending!
101 */ 100 */
102 struct MHD_HTTP_Header *first_header; 101 struct MHD_HTTP_Header *first_header;
103 102
104 /** 103 /**
105 * Buffer pointing to data that we are supposed 104 * Buffer pointing to data that we are supposed
106 * to send as a response. 105 * to send as a response.
107 */ 106 */
108 char *data; 107 char *data;
109 108
110 /** 109 /**
111 * Closure to give to the content reader 110 * Closure to give to the content reader
112 * free callback. 111 * free callback.
113 */ 112 */
114 void *crc_cls; 113 void *crc_cls;
115 114
116 /** 115 /**
117 * How do we get more data? NULL if we are 116 * How do we get more data? NULL if we are
118 * given all of the data up front. 117 * given all of the data up front.
119 */ 118 */
120 MHD_ContentReaderCallback crc; 119 MHD_ContentReaderCallback crc;
121 120
122 /** 121 /**
123 * NULL if data must not be freed, otherwise 122 * NULL if data must not be freed, otherwise
124 * either user-specified callback or "&free". 123 * either user-specified callback or "&free".
125 */ 124 */
126 MHD_ContentReaderFreeCallback crfc; 125 MHD_ContentReaderFreeCallback crfc;
127 126
128 /** 127 /**
129 * Mutex to synchronize access to data/size and 128 * Mutex to synchronize access to data/size and
130 * reference counts. 129 * reference counts.
131 */ 130 */
132 pthread_mutex_t mutex; 131 pthread_mutex_t mutex;
133 132
134 /** 133 /**
135 * Reference count for this response. Free 134 * Reference count for this response. Free
136 * once the counter hits zero. 135 * once the counter hits zero.
137 */ 136 */
138 unsigned int reference_count; 137 unsigned int reference_count;
139 138
140 /** 139 /**
141 * Set to -1 if size is not known. 140 * Set to -1 if size is not known.
142 */ 141 */
143 size_t total_size; 142 size_t total_size;
144 143
145 /** 144 /**
146 * Size of data. 145 * Size of data.
147 */ 146 */
148 size_t data_size; 147 size_t data_size;
149 148
150 /** 149 /**
151 * Size of the data buffer. 150 * Size of the data buffer.
152 */ 151 */
153 size_t data_buffer_size; 152 size_t data_buffer_size;
154 153
155 /** 154 /**
156 * At what offset in the stream is the 155 * At what offset in the stream is the
157 * beginning of data located? 156 * beginning of data located?
158 */ 157 */
159 size_t data_start; 158 size_t data_start;
160 159
161}; 160 };
162 161
163/** 162/**
164 * States in a state machine for a connection. 163 * States in a state machine for a connection.
@@ -175,419 +174,438 @@ struct MHD_Response
175 * requires the write to be complete. 174 * requires the write to be complete.
176 */ 175 */
177enum MHD_CONNECTION_STATE 176enum MHD_CONNECTION_STATE
178{ 177 {
179 /** 178 /**
180 * Connection just started (no headers received). 179 * Connection just started (no headers received).
181 * Waiting for the line with the request type, URL and version. 180 * Waiting for the line with the request type, URL and version.
182 */ 181 */
183 MHD_CONNECTION_INIT = 0, 182 MHD_CONNECTION_INIT = 0,
184 183
185 /** 184 /**
186 * 1: We got the URL (and request type and version). Wait for a header line. 185 * 1: We got the URL (and request type and version). Wait for a header line.
187 */ 186 */
188 MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1, 187 MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1,
189 188
190 /** 189 /**
191 * 2: We got part of a multi-line request header. Wait for the rest. 190 * 2: We got part of a multi-line request header. Wait for the rest.
192 */ 191 */
193 MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1, 192 MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1,
194 193
195 /** 194 /**
196 * 3: We got the request headers. Process them. 195 * 3: We got the request headers. Process them.
197 */ 196 */
198 MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1, 197 MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1,
199 198
200 /** 199 /**
201 * 4: We have processed the request headers. Send 100 continue. 200 * 4: We have processed the request headers. Send 100 continue.
202 */ 201 */
203 MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1, 202 MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1,
204 203
205 /** 204 /**
206 * 5: We have processed the headers and need to send 100 CONTINUE. 205 * 5: We have processed the headers and need to send 100 CONTINUE.
207 */ 206 */
208 MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1, 207 MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1,
209 208
210 /** 209 /**
211 * 6: We have sent 100 CONTINUE (or do not need to). Read the message body. 210 * 6: We have sent 100 CONTINUE (or do not need to). Read the message body.
212 */ 211 */
213 MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1, 212 MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1,
214 213
215 /** 214 /**
216 * 7: We got the request body. Wait for a line of the footer. 215 * 7: We got the request body. Wait for a line of the footer.
217 */ 216 */
218 MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1, 217 MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1,
219 218
220 /** 219 /**
221 * 8: We got part of a line of the footer. Wait for the 220 * 8: We got part of a line of the footer. Wait for the
222 * rest. 221 * rest.
223 */ 222 */
224 MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1, 223 MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1,
225 224
226 /** 225 /**
227 * 9: We received the entire footer. Wait for a response to be queued 226 * 9: We received the entire footer. Wait for a response to be queued
228 * and prepare the response headers. 227 * and prepare the response headers.
229 */ 228 */
230 MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1, 229 MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1,
231 230
232 /** 231 /**
233 * 10: We have prepared the response headers in the writ buffer. 232 * 10: We have prepared the response headers in the writ buffer.
234 * Send the response headers. 233 * Send the response headers.
235 */ 234 */
236 MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1, 235 MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1,
237 236
238 /** 237 /**
239 * 11: We have sent the response headers. Get ready to send the body. 238 * 11: We have sent the response headers. Get ready to send the body.
240 */ 239 */
241 MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1, 240 MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
242 241
243 /** 242 /**
244 * 12: We are ready to send a part of a non-chunked body. Send it. 243 * 12: We are ready to send a part of a non-chunked body. Send it.
245 */ 244 */
246 MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1, 245 MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
247 246
248 /** 247 /**
249 * 13: We are waiting for the client to provide more 248 * 13: We are waiting for the client to provide more
250 * data of a non-chunked body. 249 * data of a non-chunked body.
251 */ 250 */
252 MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1, 251 MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
253 252
254 /** 253 /**
255 * 14: We are ready to send a chunk. 254 * 14: We are ready to send a chunk.
256 */ 255 */
257 MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1, 256 MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
258 257
259 /** 258 /**
260 * 15: We are waiting for the client to provide a chunk of the body. 259 * 15: We are waiting for the client to provide a chunk of the body.
261 */ 260 */
262 MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1, 261 MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
263 262
264 /** 263 /**
265 * 16: We have sent the response body. Prepare the footers. 264 * 16: We have sent the response body. Prepare the footers.
266 */ 265 */
267 MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1, 266 MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
268 267
269 /** 268 /**
270 * 17: We have prepared the response footer. Send it. 269 * 17: We have prepared the response footer. Send it.
271 */ 270 */
272 MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1, 271 MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
273 272
274 /** 273 /**
275 * 18: We have sent the response footer. Shutdown or restart. 274 * 18: We have sent the response footer. Shutdown or restart.
276 */ 275 */
277 MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1, 276 MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1,
278 277
279 /** 278 /**
280 * 19: This connection is closed (no more activity 279 * 19: This connection is closed (no more activity
281 * allowed). 280 * allowed).
282 */ 281 */
283 MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1, 282 MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
284 283
285}; 284 };
285
286enum MHDS_CONNECTION_STATE
287 {
288 MHDS_CONNECTION_INIT = 0,
289
290 /**
291 * 1: We got the URL (and request type and version). Wait for a header line.
292 */
293 MHDS_HANDSHAKE_COMPLETE = MHDS_CONNECTION_INIT + 1,
294
295 MHDS_CONNECTION_CONTINUE_SENDING = MHDS_HANDSHAKE_COMPLETE + 1,
296
297 MHDS_CONNECTION_CLOSED = MHDS_CONNECTION_CONTINUE_SENDING + 1
298 };
286 299
287struct MHD_Connection 300struct MHD_Connection
288{ 301 {
289 302
290 /** 303 /**
291 * This is a linked list. 304 * This is a linked list.
292 */ 305 */
293 struct MHD_Connection *next; 306 struct MHD_Connection *next;
294 307
295 /** 308 /**
296 * Reference to the MHD_Daemon struct. 309 * Reference to the MHD_Daemon struct.
297 */ 310 */
298 struct MHD_Daemon *daemon; 311 struct MHD_Daemon *daemon;
299 312
300 /** 313 /**
301 * Linked list of parsed headers. 314 * Linked list of parsed headers.
302 */ 315 */
303 struct MHD_HTTP_Header *headers_received; 316 struct MHD_HTTP_Header *headers_received;
304 317
305 /** 318 /**
306 * Response to transmit (initially NULL). 319 * Response to transmit (initially NULL).
307 */ 320 */
308 struct MHD_Response *response; 321 struct MHD_Response *response;
309 322
310 /** 323 /**
311 * The memory pool is created whenever we first read 324 * The memory pool is created whenever we first read
312 * from the TCP stream and destroyed at the end of 325 * from the TCP stream and destroyed at the end of
313 * each request (and re-created for the next request). 326 * each request (and re-created for the next request).
314 * In the meantime, this pointer is NULL. The 327 * In the meantime, this pointer is NULL. The
315 * pool is used for all connection-related data 328 * pool is used for all connection-related data
316 * except for the response (which maybe shared between 329 * except for the response (which maybe shared between
317 * connections) and the IP address (which persists 330 * connections) and the IP address (which persists
318 * across individual requests). 331 * across individual requests).
319 */ 332 */
320 struct MemoryPool *pool; 333 struct MemoryPool *pool;
321 334
322 /** 335 /**
323 * We allow the main application to associate some 336 * We allow the main application to associate some
324 * pointer with the connection. Here is where we 337 * pointer with the connection. Here is where we
325 * store it. (MHD does not know or care what it 338 * store it. (MHD does not know or care what it
326 * is). 339 * is).
327 */ 340 */
328 void *client_context; 341 void *client_context;
329 342
330 /** 343 /**
331 * Request method. Should be GET/POST/etc. Allocated 344 * Request method. Should be GET/POST/etc. Allocated
332 * in pool. 345 * in pool.
333 */ 346 */
334 char *method; 347 char *method;
335 348
336 /** 349 /**
337 * Requested URL (everything after "GET" only). Allocated 350 * Requested URL (everything after "GET" only). Allocated
338 * in pool. 351 * in pool.
339 */ 352 */
340 char *url; 353 char *url;
341 354
342 /** 355 /**
343 * HTTP version string (i.e. http/1.1). Allocated 356 * HTTP version string (i.e. http/1.1). Allocated
344 * in pool. 357 * in pool.
345 */ 358 */
346 char *version; 359 char *version;
347 360
348 /** 361 /**
349 * Buffer for reading requests. Allocated 362 * Buffer for reading requests. Allocated
350 * in pool. Actually one byte larger than 363 * in pool. Actually one byte larger than
351 * read_buffer_size (if non-NULL) to allow for 364 * read_buffer_size (if non-NULL) to allow for
352 * 0-termination. 365 * 0-termination.
353 */ 366 */
354 char *read_buffer; 367 char *read_buffer;
355 368
356 /** 369 /**
357 * Buffer for writing response (headers only). Allocated 370 * Buffer for writing response (headers only). Allocated
358 * in pool. 371 * in pool.
359 */ 372 */
360 char *write_buffer; 373 char *write_buffer;
361 374
362 /** 375 /**
363 * Last incomplete header line during parsing of headers. 376 * Last incomplete header line during parsing of headers.
364 * Allocated in pool. Only valid if state is 377 * Allocated in pool. Only valid if state is
365 * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED. 378 * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED.
366 */ 379 */
367 char *last; 380 char *last;
368 381
369 /** 382 /**
370 * Position after the colon on the last incomplete header 383 * Position after the colon on the last incomplete header
371 * line during parsing of headers. 384 * line during parsing of headers.
372 * Allocated in pool. Only valid if state is 385 * Allocated in pool. Only valid if state is
373 * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED. 386 * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED.
374 */ 387 */
375 char *colon; 388 char *colon;
376 389
377 /** 390 /**
378 * Foreign address (of length addr_len). MALLOCED (not 391 * Foreign address (of length addr_len). MALLOCED (not
379 * in pool!). 392 * in pool!).
380 */ 393 */
381 struct sockaddr_in *addr; 394 struct sockaddr_in *addr;
382 395
383 /** 396 /**
384 * Thread for this connection (if we are using 397 * Thread for this connection (if we are using
385 * one thread per connection). 398 * one thread per connection).
386 */ 399 */
387 pthread_t pid; 400 pthread_t pid;
388 401
389 /** 402 /**
390 * Size of read_buffer (in bytes). This value indicates 403 * Size of read_buffer (in bytes). This value indicates
391 * how many bytes we're willing to read into the buffer; 404 * how many bytes we're willing to read into the buffer;
392 * the real buffer is one byte longer to allow for 405 * the real buffer is one byte longer to allow for
393 * adding zero-termination (when needed). 406 * adding zero-termination (when needed).
394 */ 407 */
395 size_t read_buffer_size; 408 size_t read_buffer_size;
396 409
397 /** 410 /**
398 * Position where we currently append data in 411 * Position where we currently append data in
399 * read_buffer (last valid position). 412 * read_buffer (last valid position).
400 */ 413 */
401 size_t read_buffer_offset; 414 size_t read_buffer_offset;
402 415
403 /** 416 /**
404 * Size of write_buffer (in bytes). 417 * Size of write_buffer (in bytes).
405 */ 418 */
406 size_t write_buffer_size; 419 size_t write_buffer_size;
407 420
408 /** 421 /**
409 * Offset where we are with sending from write_buffer. 422 * Offset where we are with sending from write_buffer.
410 */ 423 */
411 size_t write_buffer_send_offset; 424 size_t write_buffer_send_offset;
412 425
413 /** 426 /**
414 * Last valid location in write_buffer (where do we 427 * Last valid location in write_buffer (where do we
415 * append and up to where is it safe to send?) 428 * append and up to where is it safe to send?)
416 */ 429 */
417 size_t write_buffer_append_offset; 430 size_t write_buffer_append_offset;
418 431
419 /** 432 /**
420 * How many more bytes of the body do we expect 433 * How many more bytes of the body do we expect
421 * to read? "-1" for unknown. 434 * to read? "-1" for unknown.
422 */ 435 */
423 size_t remaining_upload_size; 436 size_t remaining_upload_size;
424 437
425 /** 438 /**
426 * Current write position in the actual response 439 * Current write position in the actual response
427 * (excluding headers, content only; should be 0 440 * (excluding headers, content only; should be 0
428 * while sending headers). 441 * while sending headers).
429 */ 442 */
430 size_t response_write_position; 443 size_t response_write_position;
431 444
432 /** 445 /**
433 * Position in the 100 CONTINUE message that 446 * Position in the 100 CONTINUE message that
434 * we need to send when receiving http 1.1 requests. 447 * we need to send when receiving http 1.1 requests.
435 */ 448 */
436 size_t continue_message_write_offset; 449 size_t continue_message_write_offset;
437 450
438 /** 451 /**
439 * Length of the foreign address. 452 * Length of the foreign address.
440 */ 453 */
441 socklen_t addr_len; 454 socklen_t addr_len;
442 455
443 /** 456 /**
444 * Last time this connection had any activity 457 * Last time this connection had any activity
445 * (reading or writing). 458 * (reading or writing).
446 */ 459 */
447 time_t last_activity; 460 time_t last_activity;
448 461
449 /** 462 /**
450 * Socket for this connection. Set to -1 if 463 * Socket for this connection. Set to -1 if
451 * this connection has died (daemon should clean 464 * this connection has died (daemon should clean
452 * up in that case). 465 * up in that case).
453 */ 466 */
454 int socket_fd; 467 int socket_fd;
455 468
456 /** 469 /**
457 * Has this socket been closed for reading (i.e. 470 * Has this socket been closed for reading (i.e.
458 * other side closed the connection)? If so, 471 * other side closed the connection)? If so,
459 * we must completely close the connection once 472 * we must completely close the connection once
460 * we are done sending our response (and stop 473 * we are done sending our response (and stop
461 * trying to read from this socket). 474 * trying to read from this socket).
462 */ 475 */
463 int read_closed; 476 int read_closed;
464 477
465 /** 478 /**
466 * State in the FSM for this connection. 479 * State in the FSM for this connection.
467 */ 480 */
468 enum MHD_CONNECTION_STATE state; 481 enum MHD_CONNECTION_STATE state;
469 482
470 /** 483 /**
471 * HTTP response code. Only valid if response object 484 * HTTP response code. Only valid if response object
472 * is already set. 485 * is already set.
473 */ 486 */
474 unsigned int responseCode; 487 unsigned int responseCode;
475 488
476 /** 489 /**
477 * Set to MHD_YES if the response's content reader 490 * Set to MHD_YES if the response's content reader
478 * callback failed to provide data the last time 491 * callback failed to provide data the last time
479 * we tried to read from it. In that case, the 492 * we tried to read from it. In that case, the
480 * write socket should be marked as unready until 493 * write socket should be marked as unready until
481 * the CRC call succeeds. 494 * the CRC call succeeds.
482 */ 495 */
483 int response_unready; 496 int response_unready;
484 497
485 /** 498 /**
486 * Are we sending with chunked encoding? 499 * Are we sending with chunked encoding?
487 */ 500 */
488 int have_chunked_response; 501 int have_chunked_response;
489 502
490 /** 503 /**
491 * Are we receiving with chunked encoding? This will be set to 504 * Are we receiving with chunked encoding? This will be set to
492 * MHD_YES after we parse the headers and are processing the body 505 * MHD_YES after we parse the headers and are processing the body
493 * with chunks. After we are done with the body and we are 506 * with chunks. After we are done with the body and we are
494 * processing the footers; once the footers are also done, this will 507 * processing the footers; once the footers are also done, this will
495 * be set to MHD_NO again (before the final call to the handler). 508 * be set to MHD_NO again (before the final call to the handler).
496 */ 509 */
497 int have_chunked_upload; 510 int have_chunked_upload;
498 511
499 /** 512 /**
500 * If we are receiving with chunked encoding, where are we right 513 * If we are receiving with chunked encoding, where are we right
501 * now? Set to 0 if we are waiting to receive the chunk size; 514 * now? Set to 0 if we are waiting to receive the chunk size;
502 * otherwise, this is the size of the current chunk. A value of 515 * otherwise, this is the size of the current chunk. A value of
503 * zero is also used when we're at the end of the chunks. 516 * zero is also used when we're at the end of the chunks.
504 */ 517 */
505 unsigned int current_chunk_size; 518 unsigned int current_chunk_size;
506 519
507 /** 520 /**
508 * If we are receiving with chunked encoding, where are we currently 521 * If we are receiving with chunked encoding, where are we currently
509 * with respect to the current chunk (at what offset / position)? 522 * with respect to the current chunk (at what offset / position)?
510 */ 523 */
511 unsigned int current_chunk_offset; 524 unsigned int current_chunk_offset;
512 525
513}; 526 };
514 527
515 528typedef struct MHD_Connection MHD_Connection_t;
516 529
517struct MHD_Daemon 530struct MHD_Daemon
518{ 531 {
519 532
520 /** 533 /**
521 * Callback function for all requests. 534 * Callback function for all requests.
522 */ 535 */
523 MHD_AccessHandlerCallback default_handler; 536 MHD_AccessHandlerCallback default_handler;
524 537
525 /** 538 /**
526 * Closure argument to default_handler. 539 * Closure argument to default_handler.
527 */ 540 */
528 void *default_handler_cls; 541 void *default_handler_cls;
529 542
530 /** 543 /**
531 * Linked list of our current connections. 544 * Linked list of our current connections.
532 */ 545 */
533 struct MHD_Connection *connections; 546 struct MHD_Connection *connections;
534 547
535 MHD_AcceptPolicyCallback apc; 548 /**
536 549 * Linked list of our current connections.
537 void *apc_cls; 550 */
538 551 // TODO switch to a dedicated tls connection struct
539 MHD_RequestCompletedCallback notify_completed; 552 struct MHD_Connection *tls_connections;
540 553
541 void *notify_completed_cls; 554 MHD_AcceptPolicyCallback apc;
542 555
543 /** 556 void *apc_cls;
544 * PID of the select thread (if we have internal select) 557
545 */ 558 MHD_RequestCompletedCallback notify_completed;
546 pthread_t pid; 559
547 560 void *notify_completed_cls;
548 /** 561
549 * Listen socket. 562 /**
550 */ 563 * PID of the select thread (if we have internal select)
551 int socket_fd; 564 */
552 565 pthread_t pid;
553 /** 566
554 * Are we shutting down? 567 /**
555 */ 568 * Listen socket.
556 int shutdown; 569 */
557 570 int socket_fd;
558 /** 571
559 * Size of the per-connection memory pools. 572 /**
560 */ 573 * Are we shutting down?
561 unsigned int pool_size; 574 */
562 575 int shutdown;
563 /** 576
564 * Limit on the number of parallel connections. 577 /**
565 */ 578 * Size of the per-connection memory pools.
566 unsigned int max_connections; 579 */
567 580 unsigned int pool_size;
568 /** 581
569 * After how many seconds of inactivity should 582 /**
570 * connections time out? Zero for no timeout. 583 * Limit on the number of parallel connections.
571 */ 584 */
572 unsigned int connection_timeout; 585 unsigned int max_connections;
573 586
574 /** 587 /**
575 * Maximum number of connections per IP, or 0 for 588 * After how many seconds of inactivity should
576 * unlimited. 589 * connections time out? Zero for no timeout.
577 */ 590 */
578 unsigned int per_ip_connection_limit; 591 unsigned int connection_timeout;
579 592
580 /** 593 /**
581 * Daemon's options. 594 * Maximum number of connections per IP, or 0 for
582 */ 595 * unlimited.
583 enum MHD_OPTION options; 596 */
584 597 unsigned int per_ip_connection_limit;
585 /** 598
586 * Listen port. 599 /**
587 */ 600 * Daemon's options.
588 unsigned short port; 601 */
589 602 enum MHD_OPTION options;
590}; 603
591 604 /**
605 * Listen port.
606 */
607 unsigned short port;
608
609 };
592 610
593#endif 611#endif