aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2007-12-20 04:45:24 +0000
committerChristian Grothoff <christian@grothoff.org>2007-12-20 04:45:24 +0000
commit6c99e978861b6b0bd0a50d7e7190e3fbdaf7aacf (patch)
tree70e2b2ba2b7d0e1d190d2933a2e740c100190cca
parentc490e64780fd1c45592f5528bf755956f0f2eddb (diff)
downloadlibmicrohttpd-6c99e978861b6b0bd0a50d7e7190e3fbdaf7aacf.tar.gz
libmicrohttpd-6c99e978861b6b0bd0a50d7e7190e3fbdaf7aacf.zip
formatting
-rw-r--r--src/daemon/connection.c1420
-rw-r--r--src/daemon/connection.h11
-rw-r--r--src/daemon/daemon.c39
-rw-r--r--src/daemon/daemontest_get.c11
-rw-r--r--src/daemon/daemontest_large_put.c34
-rw-r--r--src/daemon/daemontest_post_loop.c4
-rw-r--r--src/daemon/daemontest_postform.c8
-rw-r--r--src/daemon/daemontest_put_chunked.c4
-rw-r--r--src/daemon/fileserver_example.c4
-rw-r--r--src/daemon/internal.h22
-rw-r--r--src/daemon/memorypool.c17
-rw-r--r--src/daemon/memorypool.h6
-rw-r--r--src/daemon/minimal_example.c4
-rw-r--r--src/daemon/postprocessor.c14
-rw-r--r--src/include/microhttpd.h24
15 files changed, 784 insertions, 838 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index d07a2544..188eea6b 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -47,7 +47,7 @@
47 * Response text used when the request (http header) is too big to 47 * Response text used when the request (http header) is too big to
48 * be processed. 48 * be processed.
49 * 49 *
50 * Intentionally empty here to keep our memory footprint 50 * Intentionally empty here to keep our memory footprint
51 * minimal. 51 * minimal.
52 */ 52 */
53#define REQUEST_TOO_BIG "" 53#define REQUEST_TOO_BIG ""
@@ -56,7 +56,7 @@
56 * Response text used when the request (http header) does not 56 * Response text used when the request (http header) does not
57 * contain a "Host:" header and still claims to be HTTP 1.1. 57 * contain a "Host:" header and still claims to be HTTP 1.1.
58 * 58 *
59 * Intentionally empty here to keep our memory footprint 59 * Intentionally empty here to keep our memory footprint
60 * minimal. 60 * minimal.
61 */ 61 */
62#define REQUEST_LACKS_HOST "" 62#define REQUEST_LACKS_HOST ""
@@ -159,11 +159,11 @@ int
159MHD_queue_response (struct MHD_Connection *connection, 159MHD_queue_response (struct MHD_Connection *connection,
160 unsigned int status_code, struct MHD_Response *response) 160 unsigned int status_code, struct MHD_Response *response)
161{ 161{
162 if ( (connection == NULL) || 162 if ((connection == NULL) ||
163 (response == NULL) || 163 (response == NULL) ||
164 (connection->response != NULL) || 164 (connection->response != NULL) ||
165 ( (connection->state != MHD_CONNECTION_HEADERS_PROCESSED) && 165 ((connection->state != MHD_CONNECTION_HEADERS_PROCESSED) &&
166 (connection->state != MHD_CONNECTION_FOOTERS_RECEIVED) ) ) 166 (connection->state != MHD_CONNECTION_FOOTERS_RECEIVED)))
167 return MHD_NO; 167 return MHD_NO;
168 MHD_increment_response_rc (response); 168 MHD_increment_response_rc (response);
169 connection->response = response; 169 connection->response = response;
@@ -175,17 +175,16 @@ MHD_queue_response (struct MHD_Connection *connection,
175 have already sent the full message body */ 175 have already sent the full message body */
176 connection->response_write_position = response->total_size; 176 connection->response_write_position = response->total_size;
177 } 177 }
178 if ( (response->total_size == -1) && 178 if ((response->total_size == -1) &&
179 (0 == strcasecmp(connection->version, 179 (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1)))
180 MHD_HTTP_VERSION_1_1)) )
181 connection->have_chunked_response = MHD_YES; 180 connection->have_chunked_response = MHD_YES;
182 else 181 else
183 connection->have_chunked_response = MHD_NO; 182 connection->have_chunked_response = MHD_NO;
184 if (connection->state == MHD_CONNECTION_HEADERS_PROCESSED) 183 if (connection->state == MHD_CONNECTION_HEADERS_PROCESSED)
185 { 184 {
186 /* response was queued "early", 185 /* response was queued "early",
187 refuse to read body / footers or further 186 refuse to read body / footers or further
188 requests! */ 187 requests! */
189 SHUTDOWN (connection->socket_fd, SHUT_RD); 188 SHUTDOWN (connection->socket_fd, SHUT_RD);
190 connection->read_closed = MHD_YES; 189 connection->read_closed = MHD_YES;
191 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; 190 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
@@ -203,7 +202,7 @@ need_100_continue (struct MHD_Connection *connection)
203 const char *expect; 202 const char *expect;
204 203
205 return ((connection->response == NULL) && 204 return ((connection->response == NULL) &&
206 (connection->version != NULL) && 205 (connection->version != NULL) &&
207 (0 == strcasecmp (connection->version, 206 (0 == strcasecmp (connection->version,
208 MHD_HTTP_VERSION_1_1)) && 207 MHD_HTTP_VERSION_1_1)) &&
209 (NULL != (expect = MHD_lookup_connection_value (connection, 208 (NULL != (expect = MHD_lookup_connection_value (connection,
@@ -234,11 +233,11 @@ connection_close_error (struct MHD_Connection *connection)
234 233
235/** 234/**
236 * Prepare the response buffer of this connection for 235 * Prepare the response buffer of this connection for
237 * sending. Assumes that the response mutex is 236 * sending. Assumes that the response mutex is
238 * already held. If the transmission is complete, 237 * already held. If the transmission is complete,
239 * this function may close the socket (and return 238 * this function may close the socket (and return
240 * MHD_NO). 239 * MHD_NO).
241 * 240 *
242 * @return MHD_NO if readying the response failed 241 * @return MHD_NO if readying the response failed
243 */ 242 */
244static int 243static int
@@ -259,7 +258,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
259 if (ret == -1) 258 if (ret == -1)
260 { 259 {
261 /* either error or http 1.0 transfer, close 260 /* either error or http 1.0 transfer, close
262 socket! */ 261 socket! */
263#if DEBUG_CLOSE 262#if DEBUG_CLOSE
264#if HAVE_MESSAGES 263#if HAVE_MESSAGES
265 MHD_DLOG (connection->daemon, "Closing connection (end of response)\n"); 264 MHD_DLOG (connection->daemon, "Closing connection (end of response)\n");
@@ -268,7 +267,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
268 response->total_size = connection->response_write_position; 267 response->total_size = connection->response_write_position;
269 connection_close_error (connection); 268 connection_close_error (connection);
270 return MHD_NO; 269 return MHD_NO;
271 } 270 }
272 response->data_start = connection->response_write_position; 271 response->data_start = connection->response_write_position;
273 response->data_size = ret; 272 response->data_size = ret;
274 if (ret == 0) 273 if (ret == 0)
@@ -278,49 +277,48 @@ try_ready_normal_body (struct MHD_Connection *connection)
278 277
279/** 278/**
280 * Prepare the response buffer of this connection for 279 * Prepare the response buffer of this connection for
281 * sending. Assumes that the response mutex is 280 * sending. Assumes that the response mutex is
282 * already held. If the transmission is complete, 281 * already held. If the transmission is complete,
283 * this function may close the socket (and return 282 * this function may close the socket (and return
284 * MHD_NO). 283 * MHD_NO).
285 * 284 *
286 * @return MHD_NO if readying the response failed 285 * @return MHD_NO if readying the response failed
287 */ 286 */
288static int 287static int
289try_ready_chunked_body (struct MHD_Connection *connection) 288try_ready_chunked_body (struct MHD_Connection *connection)
290{ 289{
291 int ret; 290 int ret;
292 char * buf; 291 char *buf;
293 struct MHD_Response *response; 292 struct MHD_Response *response;
294 unsigned int size; 293 unsigned int size;
295 char cbuf[9]; 294 char cbuf[9];
296 295
297 response = connection->response; 296 response = connection->response;
298 if (connection->write_buffer_size == 0) 297 if (connection->write_buffer_size == 0)
299 { 298 {
300 size = connection->daemon->pool_size; 299 size = connection->daemon->pool_size;
301 do 300 do
302 { 301 {
303 size /= 2; 302 size /= 2;
304 if (size < 128) 303 if (size < 128)
305 { 304 {
306 /* not enough memory */ 305 /* not enough memory */
307#if DEBUG_CLOSE 306#if DEBUG_CLOSE
308#if HAVE_MESSAGES 307#if HAVE_MESSAGES
309 MHD_DLOG (connection->daemon, "Closing connection (out of memory)\n"); 308 MHD_DLOG (connection->daemon,
309 "Closing connection (out of memory)\n");
310#endif 310#endif
311#endif 311#endif
312 connection_close_error (connection); 312 connection_close_error (connection);
313 return MHD_NO; 313 return MHD_NO;
314 } 314 }
315 buf = MHD_pool_allocate (connection->pool, 315 buf = MHD_pool_allocate (connection->pool, size, MHD_NO);
316 size, 316 }
317 MHD_NO);
318 }
319 while (buf == NULL); 317 while (buf == NULL);
320 connection->write_buffer_size = size; 318 connection->write_buffer_size = size;
321 connection->write_buffer = buf; 319 connection->write_buffer = buf;
322 } 320 }
323 321
324 ret = response->crc (response->crc_cls, 322 ret = response->crc (response->crc_cls,
325 connection->response_write_position, 323 connection->response_write_position,
326 &connection->write_buffer[8], 324 &connection->write_buffer[8],
@@ -328,8 +326,7 @@ try_ready_chunked_body (struct MHD_Connection *connection)
328 if (ret == -1) 326 if (ret == -1)
329 { 327 {
330 /* end of message, signal other side! */ 328 /* end of message, signal other side! */
331 strcpy(connection->write_buffer, 329 strcpy (connection->write_buffer, "0\r\n");
332 "0\r\n");
333 connection->write_buffer_append_offset = 3; 330 connection->write_buffer_append_offset = 3;
334 connection->write_buffer_send_offset = 0; 331 connection->write_buffer_send_offset = 0;
335 response->total_size = connection->response_write_position; 332 response->total_size = connection->response_write_position;
@@ -342,19 +339,12 @@ try_ready_chunked_body (struct MHD_Connection *connection)
342 } 339 }
343 if (ret > 0xFFFFFF) 340 if (ret > 0xFFFFFF)
344 ret = 0xFFFFFF; 341 ret = 0xFFFFFF;
345 snprintf(cbuf, 342 snprintf (cbuf, 8, "%X\r\n", ret);
346 8, 343 memcpy (&connection->write_buffer[8 - strlen (cbuf)], cbuf, strlen (cbuf));
347 "%X\r\n", 344 memcpy (&connection->write_buffer[8 + ret], "\r\n", 2);
348 ret);
349 memcpy(&connection->write_buffer[8 - strlen(cbuf)],
350 cbuf,
351 strlen(cbuf));
352 memcpy(&connection->write_buffer[8 + ret],
353 "\r\n",
354 2);
355 connection->response_write_position += ret; 345 connection->response_write_position += ret;
356 connection->write_buffer_send_offset = 8 - strlen(cbuf); 346 connection->write_buffer_send_offset = 8 - strlen (cbuf);
357 connection->write_buffer_append_offset = 8 + ret + 2; 347 connection->write_buffer_append_offset = 8 + ret + 2;
358 return MHD_YES; 348 return MHD_YES;
359} 349}
360 350
@@ -370,30 +360,28 @@ add_extra_headers (struct MHD_Connection *connection)
370 360
371 connection->have_chunked_upload = MHD_NO; 361 connection->have_chunked_upload = MHD_NO;
372 if (connection->response->total_size == -1) 362 if (connection->response->total_size == -1)
373 { 363 {
374 have = MHD_get_response_header (connection->response, 364 have = MHD_get_response_header (connection->response,
375 MHD_HTTP_HEADER_CONNECTION); 365 MHD_HTTP_HEADER_CONNECTION);
376 if ( (have == NULL) || 366 if ((have == NULL) || (0 != strcasecmp (have, "close")))
377 (0 != strcasecmp(have, "close")) ) 367 {
378 { 368 if ((connection->version != NULL) &&
379 if ( (connection->version != NULL) && 369 (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1)))
380 (0 == strcasecmp(connection->version, 370 {
381 MHD_HTTP_VERSION_1_1)) ) 371 connection->have_chunked_upload = MHD_YES;
382 { 372 have = MHD_get_response_header (connection->response,
383 connection->have_chunked_upload = MHD_YES; 373 MHD_HTTP_HEADER_TRANSFER_ENCODING);
384 have = MHD_get_response_header (connection->response, 374 if (have == NULL)
385 MHD_HTTP_HEADER_TRANSFER_ENCODING); 375 MHD_add_response_header (connection->response,
386 if (have == NULL) 376 MHD_HTTP_HEADER_TRANSFER_ENCODING,
387 MHD_add_response_header (connection->response, 377 "chunked");
388 MHD_HTTP_HEADER_TRANSFER_ENCODING, 378 }
389 "chunked"); 379 else
390 } 380 {
391 else 381 MHD_add_response_header (connection->response,
392 { 382 MHD_HTTP_HEADER_CONNECTION, "close");
393 MHD_add_response_header (connection->response, 383 }
394 MHD_HTTP_HEADER_CONNECTION, "close"); 384 }
395 }
396 }
397 } 385 }
398 else if (NULL == MHD_get_response_header (connection->response, 386 else if (NULL == MHD_get_response_header (connection->response,
399 MHD_HTTP_HEADER_CONTENT_LENGTH)) 387 MHD_HTTP_HEADER_CONTENT_LENGTH))
@@ -440,22 +428,22 @@ get_date_string (char *date, unsigned int max)
440 * @return MHD_YES on success, MHD_NO on failure 428 * @return MHD_YES on success, MHD_NO on failure
441 */ 429 */
442static int 430static int
443try_grow_read_buffer(struct MHD_Connection * connection) 431try_grow_read_buffer (struct MHD_Connection *connection)
444{ 432{
445 void * buf; 433 void *buf;
446 434
447 buf = MHD_pool_reallocate (connection->pool, 435 buf = MHD_pool_reallocate (connection->pool,
448 connection->read_buffer, 436 connection->read_buffer,
449 connection->read_buffer_size, 437 connection->read_buffer_size,
450 connection->read_buffer_size * 2 + 438 connection->read_buffer_size * 2 +
451 MHD_BUF_INC_SIZE + 1); 439 MHD_BUF_INC_SIZE + 1);
452 if (buf == NULL) 440 if (buf == NULL)
453 return MHD_NO; 441 return MHD_NO;
454 /* we can actually grow the buffer, do it! */ 442 /* we can actually grow the buffer, do it! */
455 connection->read_buffer = buf; 443 connection->read_buffer = buf;
456 connection->read_buffer_size = 444 connection->read_buffer_size =
457 connection->read_buffer_size * 2 + MHD_BUF_INC_SIZE; 445 connection->read_buffer_size * 2 + MHD_BUF_INC_SIZE;
458 return MHD_YES; 446 return MHD_YES;
459} 447}
460 448
461/** 449/**
@@ -475,23 +463,22 @@ build_header_response (struct MHD_Connection *connection)
475 char *data; 463 char *data;
476 enum MHD_ValueKind kind; 464 enum MHD_ValueKind kind;
477 const char *reason_phrase; 465 const char *reason_phrase;
478 466
479 if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED) 467 if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED)
480 { 468 {
481 add_extra_headers (connection); 469 add_extra_headers (connection);
482 reason_phrase = 470 reason_phrase = MHD_get_reason_phrase_for (connection->responseCode);
483 MHD_get_reason_phrase_for (connection->responseCode);
484 _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1, 471 _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1,
485 connection->responseCode, reason_phrase); 472 connection->responseCode, reason_phrase);
486 off = strlen (code); 473 off = strlen (code);
487 /* estimate size */ 474 /* estimate size */
488 size = off + 2; /* extra \r\n at the end */ 475 size = off + 2; /* extra \r\n at the end */
489 kind = MHD_HEADER_KIND; 476 kind = MHD_HEADER_KIND;
490 if (NULL == MHD_get_response_header (connection->response, 477 if (NULL == MHD_get_response_header (connection->response,
491 MHD_HTTP_HEADER_DATE)) 478 MHD_HTTP_HEADER_DATE))
492 get_date_string (date, sizeof (date)); 479 get_date_string (date, sizeof (date));
493 else 480 else
494 date[0] = '\0'; 481 date[0] = '\0';
495 size += strlen (date); 482 size += strlen (date);
496 } 483 }
497 else 484 else
@@ -504,10 +491,10 @@ build_header_response (struct MHD_Connection *connection)
504 while (pos != NULL) 491 while (pos != NULL)
505 { 492 {
506 if (pos->kind == kind) 493 if (pos->kind == kind)
507 size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */ 494 size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */
508 pos = pos->next; 495 pos = pos->next;
509 } 496 }
510 /* produce data */ 497 /* produce data */
511 data = MHD_pool_allocate (connection->pool, size + 1, MHD_YES); 498 data = MHD_pool_allocate (connection->pool, size + 1, MHD_YES);
512 if (data == NULL) 499 if (data == NULL)
513 { 500 {
@@ -523,11 +510,11 @@ build_header_response (struct MHD_Connection *connection)
523 pos = connection->response->first_header; 510 pos = connection->response->first_header;
524 while (pos != NULL) 511 while (pos != NULL)
525 { 512 {
526 if (pos->kind == kind) 513 if (pos->kind == kind)
527 { 514 {
528 SPRINTF (&data[off], "%s: %s\r\n", pos->header, pos->value); 515 SPRINTF (&data[off], "%s: %s\r\n", pos->header, pos->value);
529 off += strlen (pos->header) + strlen (pos->value) + 4; 516 off += strlen (pos->header) + strlen (pos->value) + 4;
530 } 517 }
531 pos = pos->next; 518 pos = pos->next;
532 } 519 }
533 if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED) 520 if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED)
@@ -555,7 +542,7 @@ build_header_response (struct MHD_Connection *connection)
555 */ 542 */
556static void 543static void
557excessive_data_handler (struct MHD_Connection *connection, 544excessive_data_handler (struct MHD_Connection *connection,
558 unsigned int status_code) 545 unsigned int status_code)
559{ 546{
560 struct MHD_Response *response; 547 struct MHD_Response *response;
561 548
@@ -569,21 +556,21 @@ excessive_data_handler (struct MHD_Connection *connection,
569 response = MHD_create_response_from_data (strlen (REQUEST_TOO_BIG), 556 response = MHD_create_response_from_data (strlen (REQUEST_TOO_BIG),
570 REQUEST_TOO_BIG, MHD_NO, MHD_NO); 557 REQUEST_TOO_BIG, MHD_NO, MHD_NO);
571 MHD_queue_response (connection, status_code, response); 558 MHD_queue_response (connection, status_code, response);
572 EXTRA_CHECK(connection->response != NULL); 559 EXTRA_CHECK (connection->response != NULL);
573 MHD_destroy_response (response); 560 MHD_destroy_response (response);
574 if (MHD_NO == build_header_response (connection)) 561 if (MHD_NO == build_header_response (connection))
575 { 562 {
576 /* oops - close! */ 563 /* oops - close! */
577#if HAVE_MESSAGES 564#if HAVE_MESSAGES
578 MHD_DLOG (connection->daemon, 565 MHD_DLOG (connection->daemon,
579 "Closing connection (failed to create response header)\n"); 566 "Closing connection (failed to create response header)\n");
580#endif 567#endif
581 connection->state = MHD_CONNECTION_CLOSED; 568 connection->state = MHD_CONNECTION_CLOSED;
582 } 569 }
583 else 570 else
584 { 571 {
585 connection->state = MHD_CONNECTION_HEADERS_SENDING; 572 connection->state = MHD_CONNECTION_HEADERS_SENDING;
586 } 573 }
587} 574}
588 575
589/** 576/**
@@ -591,9 +578,7 @@ excessive_data_handler (struct MHD_Connection *connection,
591 * greater than "*max", set "*max" to fd. 578 * greater than "*max", set "*max" to fd.
592 */ 579 */
593static void 580static void
594do_fd_set(int fd, 581do_fd_set (int fd, fd_set * set, int *max_fd)
595 fd_set * set,
596 int * max_fd)
597{ 582{
598 FD_SET (fd, set); 583 FD_SET (fd, set);
599 if (fd > *max_fd) 584 if (fd > *max_fd)
@@ -626,108 +611,106 @@ MHD_connection_get_fdset (struct MHD_Connection *connection,
626 fd = connection->socket_fd; 611 fd = connection->socket_fd;
627 if (fd == -1) 612 if (fd == -1)
628 return MHD_YES; 613 return MHD_YES;
629 while (1) { 614 while (1)
615 {
630#if DEBUG_STATES 616#if DEBUG_STATES
631 fprintf(stderr, 617 fprintf (stderr, "`%s' in state %u\n", __FUNCTION__, connection->state);
632 "`%s' in state %u\n", 618#endif
633 __FUNCTION__, 619 switch (connection->state)
634 connection->state); 620 {
635#endif 621 case MHD_CONNECTION_INIT:
636 switch (connection->state) 622 case MHD_CONNECTION_URL_RECEIVED:
637 { 623 case MHD_CONNECTION_HEADER_PART_RECEIVED:
638 case MHD_CONNECTION_INIT: 624 /* while reading headers, we always grow the
639 case MHD_CONNECTION_URL_RECEIVED: 625 read buffer if needed, no size-check required */
640 case MHD_CONNECTION_HEADER_PART_RECEIVED: 626 if ((connection->read_closed) &&
641 /* while reading headers, we always grow the 627 (connection->read_buffer_offset == 0))
642 read buffer if needed, no size-check required */ 628 {
643 if ( (connection->read_closed) && 629 connection->state = MHD_CONNECTION_CLOSED;
644 (connection->read_buffer_offset == 0) ) 630 continue;
645 { 631 }
646 connection->state = MHD_CONNECTION_CLOSED; 632 if ((connection->read_buffer_offset == connection->read_buffer_size)
647 continue; 633 && (MHD_NO == try_grow_read_buffer (connection)))
648 } 634 {
649 if ( (connection->read_buffer_offset == connection->read_buffer_size) && 635 excessive_data_handler (connection,
650 (MHD_NO == try_grow_read_buffer(connection)) ) 636 (connection->url != NULL)
651 { 637 ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE
652 excessive_data_handler (connection, 638 : MHD_HTTP_REQUEST_URI_TOO_LONG);
653 (connection->url != NULL) 639 continue;
654 ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE 640 }
655 : MHD_HTTP_REQUEST_URI_TOO_LONG); 641 if (MHD_NO == connection->read_closed)
656 continue; 642 do_fd_set (fd, read_fd_set, max_fd);
657 } 643 break;
658 if (MHD_NO == connection->read_closed) 644 case MHD_CONNECTION_HEADERS_RECEIVED:
659 do_fd_set (fd, read_fd_set, max_fd); 645 /* we should never get here */
660 break; 646 EXTRA_CHECK (0);
661 case MHD_CONNECTION_HEADERS_RECEIVED: 647 break;
662 /* we should never get here */ 648 case MHD_CONNECTION_HEADERS_PROCESSED:
663 EXTRA_CHECK(0); 649 EXTRA_CHECK (0);
664 break; 650 break;
665 case MHD_CONNECTION_HEADERS_PROCESSED: 651 case MHD_CONNECTION_CONTINUE_SENDING:
666 EXTRA_CHECK(0); 652 do_fd_set (fd, write_fd_set, max_fd);
667 break; 653 break;
668 case MHD_CONNECTION_CONTINUE_SENDING: 654 case MHD_CONNECTION_CONTINUE_SENT:
669 do_fd_set (fd, write_fd_set, max_fd); 655 if (connection->read_buffer_offset == connection->read_buffer_size)
670 break; 656 try_grow_read_buffer (connection);
671 case MHD_CONNECTION_CONTINUE_SENT: 657 if (connection->read_buffer_offset < connection->read_buffer_size)
672 if (connection->read_buffer_offset == connection->read_buffer_size) 658 do_fd_set (fd, read_fd_set, max_fd);
673 try_grow_read_buffer(connection); 659 break;
674 if (connection->read_buffer_offset < connection->read_buffer_size) 660 case MHD_CONNECTION_BODY_RECEIVED:
675 do_fd_set (fd, read_fd_set, max_fd); 661 case MHD_CONNECTION_FOOTER_PART_RECEIVED:
676 break; 662 /* while reading footers, we always grow the
677 case MHD_CONNECTION_BODY_RECEIVED: 663 read buffer if needed, no size-check required */
678 case MHD_CONNECTION_FOOTER_PART_RECEIVED: 664 if (MHD_YES == connection->read_closed)
679 /* while reading footers, we always grow the 665 {
680 read buffer if needed, no size-check required */ 666 connection->state = MHD_CONNECTION_CLOSED;
681 if (MHD_YES == connection->read_closed) 667 continue;
682 { 668 }
683 connection->state = MHD_CONNECTION_CLOSED; 669 do_fd_set (fd, read_fd_set, max_fd);
684 continue; 670 /* transition to FOOTERS_RECEIVED
685 } 671 happens in read handler */
686 do_fd_set (fd, read_fd_set, max_fd); 672 break;
687 /* transition to FOOTERS_RECEIVED 673 case MHD_CONNECTION_FOOTERS_RECEIVED:
688 happens in read handler */ 674 /* no socket action, wait for client
689 break; 675 to provide response */
690 case MHD_CONNECTION_FOOTERS_RECEIVED: 676 break;
691 /* no socket action, wait for client 677 case MHD_CONNECTION_HEADERS_SENDING:
692 to provide response */ 678 /* headers in buffer, keep writing */
693 break; 679 do_fd_set (fd, write_fd_set, max_fd);
694 case MHD_CONNECTION_HEADERS_SENDING: 680 break;
695 /* headers in buffer, keep writing */ 681 case MHD_CONNECTION_HEADERS_SENT:
696 do_fd_set(fd, write_fd_set, max_fd); 682 EXTRA_CHECK (0);
697 break; 683 break;
698 case MHD_CONNECTION_HEADERS_SENT: 684 case MHD_CONNECTION_NORMAL_BODY_READY:
699 EXTRA_CHECK(0); 685 do_fd_set (fd, write_fd_set, max_fd);
700 break; 686 break;
701 case MHD_CONNECTION_NORMAL_BODY_READY: 687 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
702 do_fd_set (fd, write_fd_set, max_fd); 688 /* not ready, no socket action */
703 break; 689 break;
704 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 690 case MHD_CONNECTION_CHUNKED_BODY_READY:
705 /* not ready, no socket action */ 691 do_fd_set (fd, write_fd_set, max_fd);
706 break; 692 break;
707 case MHD_CONNECTION_CHUNKED_BODY_READY: 693 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
708 do_fd_set (fd, write_fd_set, max_fd); 694 /* not ready, no socket action */
709 break; 695 break;
710 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 696 case MHD_CONNECTION_BODY_SENT:
711 /* not ready, no socket action */ 697 EXTRA_CHECK (0);
712 break; 698 break;
713 case MHD_CONNECTION_BODY_SENT: 699 case MHD_CONNECTION_FOOTERS_SENDING:
714 EXTRA_CHECK(0); 700 do_fd_set (fd, write_fd_set, max_fd);
715 break; 701 break;
716 case MHD_CONNECTION_FOOTERS_SENDING: 702 case MHD_CONNECTION_FOOTERS_SENT:
717 do_fd_set (fd, write_fd_set, max_fd); 703 EXTRA_CHECK (0);
718 break; 704 break;
719 case MHD_CONNECTION_FOOTERS_SENT: 705 case MHD_CONNECTION_CLOSED:
720 EXTRA_CHECK(0); 706 if (connection->socket_fd != -1)
721 break; 707 connection_close_error (connection);
722 case MHD_CONNECTION_CLOSED: 708 return MHD_YES; /* do nothing, not even reading */
723 if (connection->socket_fd != -1) 709 default:
724 connection_close_error(connection); 710 EXTRA_CHECK (0);
725 return MHD_YES; /* do nothing, not even reading */ 711 }
726 default: 712 break;
727 EXTRA_CHECK(0); 713 }
728 }
729 break;
730 }
731 return MHD_YES; 714 return MHD_YES;
732} 715}
733 716
@@ -765,9 +748,9 @@ get_next_header_line (struct MHD_Connection *connection)
765 if (rbuf == NULL) 748 if (rbuf == NULL)
766 { 749 {
767 excessive_data_handler (connection, 750 excessive_data_handler (connection,
768 (connection->url != NULL) 751 (connection->url != NULL)
769 ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE 752 ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE
770 : MHD_HTTP_REQUEST_URI_TOO_LONG); 753 : MHD_HTTP_REQUEST_URI_TOO_LONG);
771 } 754 }
772 else 755 else
773 { 756 {
@@ -793,7 +776,7 @@ get_next_header_line (struct MHD_Connection *connection)
793 */ 776 */
794static int 777static int
795connection_add_header (struct MHD_Connection *connection, 778connection_add_header (struct MHD_Connection *connection,
796 char *key, char *value, enum MHD_ValueKind kind) 779 char *key, char *value, enum MHD_ValueKind kind)
797{ 780{
798 struct MHD_HTTP_Header *hdr; 781 struct MHD_HTTP_Header *hdr;
799 782
@@ -805,8 +788,7 @@ connection_add_header (struct MHD_Connection *connection,
805 MHD_DLOG (connection->daemon, 788 MHD_DLOG (connection->daemon,
806 "Not enough memory to allocate header record!\n"); 789 "Not enough memory to allocate header record!\n");
807#endif 790#endif
808 excessive_data_handler (connection, 791 excessive_data_handler (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE);
809 MHD_HTTP_REQUEST_ENTITY_TOO_LARGE);
810 return MHD_NO; 792 return MHD_NO;
811 } 793 }
812 hdr->next = connection->headers_received; 794 hdr->next = connection->headers_received;
@@ -842,8 +824,7 @@ parse_arguments (enum MHD_ValueKind kind,
842 } 824 }
843 MHD_http_unescape (args); 825 MHD_http_unescape (args);
844 MHD_http_unescape (equals); 826 MHD_http_unescape (equals);
845 if (MHD_NO == connection_add_header (connection, 827 if (MHD_NO == connection_add_header (connection, args, equals, kind))
846 args, equals, kind))
847 return MHD_NO; 828 return MHD_NO;
848 args = amper; 829 args = amper;
849 } 830 }
@@ -874,8 +855,7 @@ parse_cookie_header (struct MHD_Connection *connection)
874#if HAVE_MESSAGES 855#if HAVE_MESSAGES
875 MHD_DLOG (connection->daemon, "Not enough memory to parse cookies!\n"); 856 MHD_DLOG (connection->daemon, "Not enough memory to parse cookies!\n");
876#endif 857#endif
877 excessive_data_handler (connection, 858 excessive_data_handler (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE);
878 MHD_HTTP_REQUEST_ENTITY_TOO_LARGE);
879 return MHD_NO; 859 return MHD_NO;
880 } 860 }
881 memcpy (cpy, hdr, strlen (hdr) + 1); 861 memcpy (cpy, hdr, strlen (hdr) + 1);
@@ -911,7 +891,7 @@ parse_cookie_header (struct MHD_Connection *connection)
911 equals++; 891 equals++;
912 } 892 }
913 if (MHD_NO == connection_add_header (connection, 893 if (MHD_NO == connection_add_header (connection,
914 pos, equals, MHD_COOKIE_KIND)) 894 pos, equals, MHD_COOKIE_KIND))
915 return MHD_NO; 895 return MHD_NO;
916 pos = semicolon; 896 pos = semicolon;
917 } 897 }
@@ -977,13 +957,13 @@ call_connection_handler (struct MHD_Connection *connection)
977 int malformed; 957 int malformed;
978 958
979 if (connection->response != NULL) 959 if (connection->response != NULL)
980 return; /* already queued a response */ 960 return; /* already queued a response */
981 do 961 do
982 { 962 {
983 instant_retry = MHD_NO; 963 instant_retry = MHD_NO;
984 available = connection->read_buffer_offset; 964 available = connection->read_buffer_offset;
985 if ( (connection->have_chunked_upload == MHD_YES) && 965 if ((connection->have_chunked_upload == MHD_YES) &&
986 (connection->remaining_upload_size == -1) ) 966 (connection->remaining_upload_size == -1))
987 { 967 {
988 if ((connection->current_chunk_offset == 968 if ((connection->current_chunk_offset ==
989 connection->current_chunk_size) 969 connection->current_chunk_size)
@@ -1044,16 +1024,17 @@ call_connection_handler (struct MHD_Connection *connection)
1044 } 1024 }
1045 if (i >= available) 1025 if (i >= available)
1046 return; /* need more data... */ 1026 return; /* need more data... */
1047 malformed = (i >= 6); 1027 malformed = (i >= 6);
1048 if (! malformed) 1028 if (!malformed)
1049 { 1029 {
1050 connection->read_buffer[i] = '\0'; 1030 connection->read_buffer[i] = '\0';
1051 malformed = (1 != sscanf (connection->read_buffer, 1031 malformed = (1 != sscanf (connection->read_buffer,
1052 "%X", 1032 "%X",
1053 &connection->current_chunk_size)) && 1033 &connection->current_chunk_size))
1054 (1 != sscanf (connection->read_buffer, 1034 && (1 !=
1055 "%x", &connection->current_chunk_size)); 1035 sscanf (connection->read_buffer, "%x",
1056 } 1036 &connection->current_chunk_size));
1037 }
1057 if (malformed) 1038 if (malformed)
1058 { 1039 {
1059 /* malformed encoding */ 1040 /* malformed encoding */
@@ -1088,13 +1069,15 @@ call_connection_handler (struct MHD_Connection *connection)
1088 available = 0; 1069 available = 0;
1089 } 1070 }
1090 used = processed; 1071 used = processed;
1091 if (MHD_NO == connection->daemon->default_handler (connection->daemon->default_handler_cls, 1072 if (MHD_NO ==
1092 connection, 1073 connection->daemon->default_handler (connection->daemon->
1093 connection->url, 1074 default_handler_cls,
1094 connection->method, 1075 connection, connection->url,
1095 connection->version, 1076 connection->method,
1096 connection->read_buffer, &processed, 1077 connection->version,
1097 &connection->client_context)) 1078 connection->read_buffer,
1079 &processed,
1080 &connection->client_context))
1098 { 1081 {
1099 /* serious internal error, close connection */ 1082 /* serious internal error, close connection */
1100#if HAVE_MESSAGES 1083#if HAVE_MESSAGES
@@ -1105,7 +1088,7 @@ call_connection_handler (struct MHD_Connection *connection)
1105 return; 1088 return;
1106 } 1089 }
1107 if (processed > used) 1090 if (processed > used)
1108 abort(); /* fatal client API violation! */ 1091 abort (); /* fatal client API violation! */
1109 if (processed != 0) 1092 if (processed != 0)
1110 instant_retry = MHD_NO; /* client did not process everything */ 1093 instant_retry = MHD_NO; /* client did not process everything */
1111 used -= processed; 1094 used -= processed;
@@ -1117,7 +1100,7 @@ call_connection_handler (struct MHD_Connection *connection)
1117 &connection->read_buffer[used], processed + available); 1100 &connection->read_buffer[used], processed + available);
1118 if (connection->remaining_upload_size != -1) 1101 if (connection->remaining_upload_size != -1)
1119 connection->remaining_upload_size -= used; 1102 connection->remaining_upload_size -= used;
1120 connection->read_buffer_offset = processed + available; 1103 connection->read_buffer_offset = processed + available;
1121 } 1104 }
1122 while (instant_retry == MHD_YES); 1105 while (instant_retry == MHD_YES);
1123} 1106}
@@ -1131,10 +1114,10 @@ call_connection_handler (struct MHD_Connection *connection)
1131 * no space was available 1114 * no space was available
1132 */ 1115 */
1133static int 1116static int
1134do_read(struct MHD_Connection * connection) 1117do_read (struct MHD_Connection *connection)
1135{ 1118{
1136 int bytes_read; 1119 int bytes_read;
1137 1120
1138 if (connection->read_buffer_size == connection->read_buffer_offset) 1121 if (connection->read_buffer_size == connection->read_buffer_offset)
1139 return MHD_NO; 1122 return MHD_NO;
1140 bytes_read = RECV (connection->socket_fd, 1123 bytes_read = RECV (connection->socket_fd,
@@ -1168,8 +1151,7 @@ do_read(struct MHD_Connection * connection)
1168 * to process. 1151 * to process.
1169 */ 1152 */
1170static void 1153static void
1171process_header_line(struct MHD_Connection * connection, 1154process_header_line (struct MHD_Connection *connection, char *line)
1172 char * line)
1173{ 1155{
1174 char *colon; 1156 char *colon;
1175 1157
@@ -1180,14 +1162,14 @@ process_header_line(struct MHD_Connection * connection,
1180 /* error in header line, die hard */ 1162 /* error in header line, die hard */
1181#if HAVE_MESSAGES 1163#if HAVE_MESSAGES
1182 MHD_DLOG (connection->daemon, 1164 MHD_DLOG (connection->daemon,
1183 "Received malformed line (no colon), closing connection.\n"); 1165 "Received malformed line (no colon), closing connection.\n");
1184#endif 1166#endif
1185 connection->state = MHD_CONNECTION_CLOSED; 1167 connection->state = MHD_CONNECTION_CLOSED;
1186 return; 1168 return;
1187 } 1169 }
1188 /* zero-terminate header */ 1170 /* zero-terminate header */
1189 colon[0] = '\0'; 1171 colon[0] = '\0';
1190 colon++; /* advance to value */ 1172 colon++; /* advance to value */
1191 while ((colon[0] != '\0') && ((colon[0] == ' ') || (colon[0] == '\t'))) 1173 while ((colon[0] != '\0') && ((colon[0] == ' ') || (colon[0] == '\t')))
1192 colon++; 1174 colon++;
1193 /* we do the actual adding of the connection 1175 /* we do the actual adding of the connection
@@ -1201,55 +1183,50 @@ process_header_line(struct MHD_Connection * connection,
1201 1183
1202/** 1184/**
1203 * Process a header value that spans multiple lines. 1185 * Process a header value that spans multiple lines.
1204 * The previous line(s) are in connection->last. 1186 * The previous line(s) are in connection->last.
1205 * 1187 *
1206 * @param line the current input line 1188 * @param line the current input line
1207 * @param kind if the line is complete, add a header 1189 * @param kind if the line is complete, add a header
1208 * of the given kind 1190 * of the given kind
1209 */ 1191 */
1210static void 1192static void
1211process_broken_line(struct MHD_Connection * connection, 1193process_broken_line (struct MHD_Connection *connection,
1212 char * line, 1194 char *line, enum MHD_ValueKind kind)
1213 enum MHD_ValueKind kind)
1214{ 1195{
1215 char * last; 1196 char *last;
1216 char * tmp; 1197 char *tmp;
1217 1198
1218 last = connection->last; 1199 last = connection->last;
1219 if ((line[0] == ' ') || (line[0] == '\t')) 1200 if ((line[0] == ' ') || (line[0] == '\t'))
1220 { 1201 {
1221 /* value was continued on the next line, see 1202 /* value was continued on the next line, see
1222 http://www.jmarshall.com/easy/http/ */ 1203 http://www.jmarshall.com/easy/http/ */
1223 last = MHD_pool_reallocate (connection->pool, 1204 last = MHD_pool_reallocate (connection->pool,
1224 last, 1205 last,
1225 strlen (last) + 1, 1206 strlen (last) + 1,
1226 strlen (line) + strlen (last) + 1); 1207 strlen (line) + strlen (last) + 1);
1227 if (last == NULL) 1208 if (last == NULL)
1228 { 1209 {
1229 excessive_data_handler (connection, 1210 excessive_data_handler (connection,
1230 MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); 1211 MHD_HTTP_REQUEST_ENTITY_TOO_LARGE);
1231 return; 1212 return;
1232 } 1213 }
1233 tmp = line; 1214 tmp = line;
1234 while ((tmp[0] == ' ') || (tmp[0] == '\t')) 1215 while ((tmp[0] == ' ') || (tmp[0] == '\t'))
1235 tmp++; /* skip whitespace at start of 2nd line */ 1216 tmp++; /* skip whitespace at start of 2nd line */
1236 strcat (last, tmp); 1217 strcat (last, tmp);
1237 connection->last = last; 1218 connection->last = last;
1238 return; /* possibly more than 2 lines... */ 1219 return; /* possibly more than 2 lines... */
1239 } 1220 }
1240 if (MHD_NO == connection_add_header (connection, 1221 if (MHD_NO == connection_add_header (connection,
1241 last, 1222 last, connection->colon, kind))
1242 connection->colon,
1243 kind))
1244 { 1223 {
1245 excessive_data_handler (connection, 1224 excessive_data_handler (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE);
1246 MHD_HTTP_REQUEST_ENTITY_TOO_LARGE);
1247 return; 1225 return;
1248 } 1226 }
1249 /* we still have the current line to deal with... */ 1227 /* we still have the current line to deal with... */
1250 if (strlen(line) != 0) 1228 if (strlen (line) != 0)
1251 process_header_line(connection, 1229 process_header_line (connection, line);
1252 line);
1253} 1230}
1254 1231
1255/** 1232/**
@@ -1258,7 +1235,7 @@ process_broken_line(struct MHD_Connection * connection,
1258 * the protocol. Advance to the appropriate state. 1235 * the protocol. Advance to the appropriate state.
1259 */ 1236 */
1260static void 1237static void
1261parse_connection_headers(struct MHD_Connection * connection) 1238parse_connection_headers (struct MHD_Connection *connection)
1262{ 1239{
1263 const char *clen; 1240 const char *clen;
1264 unsigned long long cval; 1241 unsigned long long cval;
@@ -1269,63 +1246,61 @@ parse_connection_headers(struct MHD_Connection * connection)
1269 && (NULL != connection->version) 1246 && (NULL != connection->version)
1270 && (0 == strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)) 1247 && (0 == strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))
1271 && (NULL == 1248 && (NULL ==
1272 MHD_lookup_connection_value (connection, MHD_HEADER_KIND, 1249 MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
1273 MHD_HTTP_HEADER_HOST))) 1250 MHD_HTTP_HEADER_HOST)))
1274 { 1251 {
1275 /* die, http 1.1 request without host and we are pedantic */ 1252 /* die, http 1.1 request without host and we are pedantic */
1276 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; 1253 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
1277 connection->read_closed = MHD_YES; 1254 connection->read_closed = MHD_YES;
1278#if HAVE_MESSAGES 1255#if HAVE_MESSAGES
1279 MHD_DLOG (connection->daemon, 1256 MHD_DLOG (connection->daemon,
1280 "Received `%s' request without `%s' header.\n", 1257 "Received `%s' request without `%s' header.\n",
1281 MHD_HTTP_VERSION_1_1, MHD_HTTP_HEADER_HOST); 1258 MHD_HTTP_VERSION_1_1, MHD_HTTP_HEADER_HOST);
1282#endif 1259#endif
1283 response = 1260 response =
1284 MHD_create_response_from_data (strlen (REQUEST_LACKS_HOST), 1261 MHD_create_response_from_data (strlen (REQUEST_LACKS_HOST),
1285 REQUEST_LACKS_HOST, MHD_NO, 1262 REQUEST_LACKS_HOST, MHD_NO, MHD_NO);
1286 MHD_NO);
1287 MHD_queue_response (connection, MHD_HTTP_BAD_REQUEST, response); 1263 MHD_queue_response (connection, MHD_HTTP_BAD_REQUEST, response);
1288 MHD_destroy_response (response); 1264 MHD_destroy_response (response);
1289 return; 1265 return;
1290 } 1266 }
1291 1267
1292 clen = MHD_lookup_connection_value (connection, 1268 clen = MHD_lookup_connection_value (connection,
1293 MHD_HEADER_KIND, 1269 MHD_HEADER_KIND,
1294 MHD_HTTP_HEADER_CONTENT_LENGTH); 1270 MHD_HTTP_HEADER_CONTENT_LENGTH);
1295 if (clen != NULL) 1271 if (clen != NULL)
1296 { 1272 {
1297 if (1 != sscanf (clen, "%llu", &cval)) 1273 if (1 != sscanf (clen, "%llu", &cval))
1298 { 1274 {
1299#if HAVE_MESSAGES 1275#if HAVE_MESSAGES
1300 MHD_DLOG (connection->daemon, 1276 MHD_DLOG (connection->daemon,
1301 "Failed to parse `%s' header `%s', closing connection.\n", 1277 "Failed to parse `%s' header `%s', closing connection.\n",
1302 MHD_HTTP_HEADER_CONTENT_LENGTH, clen); 1278 MHD_HTTP_HEADER_CONTENT_LENGTH, clen);
1303#endif 1279#endif
1304 connection->state = MHD_CONNECTION_CLOSED; 1280 connection->state = MHD_CONNECTION_CLOSED;
1305 return; 1281 return;
1306 } 1282 }
1307 connection->remaining_upload_size = cval; 1283 connection->remaining_upload_size = cval;
1308 } 1284 }
1309 else 1285 else
1310 { 1286 {
1311 if (NULL == MHD_lookup_connection_value (connection, 1287 if (NULL == MHD_lookup_connection_value (connection,
1312 MHD_HEADER_KIND, 1288 MHD_HEADER_KIND,
1313 MHD_HTTP_HEADER_TRANSFER_ENCODING)) 1289 MHD_HTTP_HEADER_TRANSFER_ENCODING))
1314 { 1290 {
1315 /* this request does not have a body */ 1291 /* this request does not have a body */
1316 connection->remaining_upload_size = 0; 1292 connection->remaining_upload_size = 0;
1317 } 1293 }
1318 else 1294 else
1319 { 1295 {
1320 connection->remaining_upload_size = -1; /* unknown size */ 1296 connection->remaining_upload_size = -1; /* unknown size */
1321 if (0 == 1297 if (0 ==
1322 strcasecmp (MHD_lookup_connection_value 1298 strcasecmp (MHD_lookup_connection_value
1323 (connection, MHD_HEADER_KIND, 1299 (connection, MHD_HEADER_KIND,
1324 MHD_HTTP_HEADER_TRANSFER_ENCODING), 1300 MHD_HTTP_HEADER_TRANSFER_ENCODING), "chunked"))
1325 "chunked")) 1301 connection->have_chunked_upload = MHD_YES;
1326 connection->have_chunked_upload = MHD_YES; 1302 }
1327 } 1303 }
1328 }
1329} 1304}
1330 1305
1331/** 1306/**
@@ -1333,57 +1308,55 @@ parse_connection_headers(struct MHD_Connection * connection)
1333 * determined that there is data to be read off a socket. All 1308 * determined that there is data to be read off a socket. All
1334 * implementations (multithreaded, external select, internal select) 1309 * implementations (multithreaded, external select, internal select)
1335 * call this function to handle reads. 1310 * call this function to handle reads.
1336 * 1311 *
1337 * @return MHD_YES if we should continue to process the 1312 * @return MHD_YES if we should continue to process the
1338 * connection (not dead yet), MHD_NO if it died 1313 * connection (not dead yet), MHD_NO if it died
1339 */ 1314 */
1340int 1315int
1341MHD_connection_handle_read (struct MHD_Connection *connection) 1316MHD_connection_handle_read (struct MHD_Connection *connection)
1342{ 1317{
1343 connection->last_activity = time(NULL); 1318 connection->last_activity = time (NULL);
1344 if (connection->state == MHD_CONNECTION_CLOSED) 1319 if (connection->state == MHD_CONNECTION_CLOSED)
1345 return MHD_NO; 1320 return MHD_NO;
1346 if (MHD_NO == do_read(connection)) 1321 if (MHD_NO == do_read (connection))
1347 return MHD_YES; 1322 return MHD_YES;
1348 while (1) { 1323 while (1)
1324 {
1349#if DEBUG_STATES 1325#if DEBUG_STATES
1350 fprintf(stderr, 1326 fprintf (stderr, "`%s' in state %u\n", __FUNCTION__, connection->state);
1351 "`%s' in state %u\n", 1327#endif
1352 __FUNCTION__, 1328 switch (connection->state)
1353 connection->state); 1329 {
1354#endif 1330 case MHD_CONNECTION_INIT:
1355 switch (connection->state) 1331 case MHD_CONNECTION_URL_RECEIVED:
1356 { 1332 case MHD_CONNECTION_HEADER_PART_RECEIVED:
1357 case MHD_CONNECTION_INIT: 1333 case MHD_CONNECTION_HEADERS_RECEIVED:
1358 case MHD_CONNECTION_URL_RECEIVED: 1334 case MHD_CONNECTION_HEADERS_PROCESSED:
1359 case MHD_CONNECTION_HEADER_PART_RECEIVED: 1335 case MHD_CONNECTION_CONTINUE_SENDING:
1360 case MHD_CONNECTION_HEADERS_RECEIVED: 1336 case MHD_CONNECTION_CONTINUE_SENT:
1361 case MHD_CONNECTION_HEADERS_PROCESSED: 1337 case MHD_CONNECTION_BODY_RECEIVED:
1362 case MHD_CONNECTION_CONTINUE_SENDING: 1338 case MHD_CONNECTION_FOOTER_PART_RECEIVED:
1363 case MHD_CONNECTION_CONTINUE_SENT: 1339 /* nothing to do but default action */
1364 case MHD_CONNECTION_BODY_RECEIVED: 1340 if (MHD_YES == connection->read_closed)
1365 case MHD_CONNECTION_FOOTER_PART_RECEIVED: 1341 {
1366 /* nothing to do but default action */ 1342 connection->state = MHD_CONNECTION_CLOSED;
1367 if (MHD_YES == connection->read_closed) 1343 continue;
1368 { 1344 }
1369 connection->state = MHD_CONNECTION_CLOSED; 1345 break;
1370 continue; 1346 case MHD_CONNECTION_CLOSED:
1371 } 1347 if (connection->socket_fd != -1)
1372 break; 1348 connection_close_error (connection);
1373 case MHD_CONNECTION_CLOSED: 1349 return MHD_NO;
1374 if (connection->socket_fd != -1) 1350 default:
1375 connection_close_error (connection); 1351 /* shrink read buffer to how much is actually used */
1376 return MHD_NO; 1352 MHD_pool_reallocate (connection->pool,
1377 default: 1353 connection->read_buffer,
1378 /* shrink read buffer to how much is actually used */ 1354 connection->read_buffer_size + 1,
1379 MHD_pool_reallocate (connection->pool, 1355 connection->read_buffer_offset);
1380 connection->read_buffer, 1356 break;
1381 connection->read_buffer_size + 1, 1357 }
1382 connection->read_buffer_offset); 1358 break;
1383 break; 1359 }
1384 }
1385 break;
1386 }
1387 return MHD_YES; 1360 return MHD_YES;
1388} 1361}
1389 1362
@@ -1392,35 +1365,34 @@ MHD_connection_handle_read (struct MHD_Connection *connection)
1392 * write buffer of the connection. 1365 * write buffer of the connection.
1393 * 1366 *
1394 * @return MHD_YES if something changed, 1367 * @return MHD_YES if something changed,
1395 * MHD_NO if we were interrupted 1368 * MHD_NO if we were interrupted
1396 */ 1369 */
1397static int 1370static int
1398do_write(struct MHD_Connection * connection) 1371do_write (struct MHD_Connection *connection)
1399{ 1372{
1400 int ret; 1373 int ret;
1401 1374
1402 ret = SEND (connection->socket_fd, 1375 ret = SEND (connection->socket_fd,
1403 &connection->write_buffer[connection-> 1376 &connection->write_buffer[connection->
1404 write_buffer_send_offset], 1377 write_buffer_send_offset],
1405 connection->write_buffer_append_offset - 1378 connection->write_buffer_append_offset -
1406 connection->write_buffer_send_offset, MSG_NOSIGNAL); 1379 connection->write_buffer_send_offset, MSG_NOSIGNAL);
1407 if (ret < 0) 1380 if (ret < 0)
1408 { 1381 {
1409 if (errno == EINTR) 1382 if (errno == EINTR)
1410 return MHD_NO; 1383 return MHD_NO;
1411#if HAVE_MESSAGES 1384#if HAVE_MESSAGES
1412 MHD_DLOG (connection->daemon, 1385 MHD_DLOG (connection->daemon,
1413 "Failed to send data: %s\n", STRERROR (errno)); 1386 "Failed to send data: %s\n", STRERROR (errno));
1414#endif 1387#endif
1415 connection_close_error (connection); 1388 connection_close_error (connection);
1416 return MHD_YES; 1389 return MHD_YES;
1417 } 1390 }
1418#if DEBUG_SEND_DATA 1391#if DEBUG_SEND_DATA
1419 fprintf (stderr, 1392 fprintf (stderr,
1420 "Sent HEADER response: `%.*s'\n", 1393 "Sent HEADER response: `%.*s'\n",
1421 ret, 1394 ret,
1422 &connection->write_buffer[connection-> 1395 &connection->write_buffer[connection->write_buffer_send_offset]);
1423 write_buffer_send_offset]);
1424#endif 1396#endif
1425 connection->write_buffer_send_offset += ret; 1397 connection->write_buffer_send_offset += ret;
1426 return MHD_YES; 1398 return MHD_YES;
@@ -1432,18 +1404,18 @@ do_write(struct MHD_Connection * connection)
1432 * @return MHY_NO if we are not done, MHD_YES if we are 1404 * @return MHY_NO if we are not done, MHD_YES if we are
1433 */ 1405 */
1434static int 1406static int
1435check_write_done(struct MHD_Connection * connection, 1407check_write_done (struct MHD_Connection *connection,
1436 enum MHD_CONNECTION_STATE next_state) 1408 enum MHD_CONNECTION_STATE next_state)
1437{ 1409{
1438 if (connection->write_buffer_append_offset != 1410 if (connection->write_buffer_append_offset !=
1439 connection->write_buffer_send_offset) 1411 connection->write_buffer_send_offset)
1440 return MHD_NO; 1412 return MHD_NO;
1441 connection->write_buffer_append_offset = 0; 1413 connection->write_buffer_append_offset = 0;
1442 connection->write_buffer_send_offset = 0; 1414 connection->write_buffer_send_offset = 0;
1443 connection->state = next_state; 1415 connection->state = next_state;
1444 MHD_pool_reallocate (connection->pool, 1416 MHD_pool_reallocate (connection->pool,
1445 connection->write_buffer, 1417 connection->write_buffer,
1446 connection->write_buffer_size, 0); 1418 connection->write_buffer_size, 0);
1447 connection->write_buffer = NULL; 1419 connection->write_buffer = NULL;
1448 connection->write_buffer_size = 0; 1420 connection->write_buffer_size = 0;
1449 return MHD_YES; 1421 return MHD_YES;
@@ -1454,7 +1426,7 @@ check_write_done(struct MHD_Connection * connection,
1454 * been determined that the socket can be written to. All 1426 * been determined that the socket can be written to. All
1455 * implementations (multithreaded, external select, internal select) 1427 * implementations (multithreaded, external select, internal select)
1456 * call this function 1428 * call this function
1457 * 1429 *
1458 * @return MHD_YES if we should continue to process the 1430 * @return MHD_YES if we should continue to process the
1459 * connection (not dead yet), MHD_NO if it died 1431 * connection (not dead yet), MHD_NO if it died
1460 */ 1432 */
@@ -1464,133 +1436,135 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1464 struct MHD_Response *response; 1436 struct MHD_Response *response;
1465 int ret; 1437 int ret;
1466 1438
1467 connection->last_activity = time(NULL); 1439 connection->last_activity = time (NULL);
1468 while (1) { 1440 while (1)
1441 {
1469#if DEBUG_STATES 1442#if DEBUG_STATES
1470 fprintf(stderr, 1443 fprintf (stderr, "`%s' in state %u\n", __FUNCTION__, connection->state);
1471 "`%s' in state %u\n", 1444#endif
1472 __FUNCTION__, 1445 switch (connection->state)
1473 connection->state); 1446 {
1474#endif 1447 case MHD_CONNECTION_INIT:
1475 switch (connection->state) 1448 case MHD_CONNECTION_URL_RECEIVED:
1476 { 1449 case MHD_CONNECTION_HEADER_PART_RECEIVED:
1477 case MHD_CONNECTION_INIT: 1450 case MHD_CONNECTION_HEADERS_RECEIVED:
1478 case MHD_CONNECTION_URL_RECEIVED: 1451 EXTRA_CHECK (0);
1479 case MHD_CONNECTION_HEADER_PART_RECEIVED: 1452 break;
1480 case MHD_CONNECTION_HEADERS_RECEIVED: 1453 case MHD_CONNECTION_HEADERS_PROCESSED:
1481 EXTRA_CHECK(0); 1454 break;
1482 break; 1455 case MHD_CONNECTION_CONTINUE_SENDING:
1483 case MHD_CONNECTION_HEADERS_PROCESSED: 1456 ret = SEND (connection->socket_fd,
1484 break; 1457 &HTTP_100_CONTINUE[connection->
1485 case MHD_CONNECTION_CONTINUE_SENDING: 1458 continue_message_write_offset],
1486 ret = SEND (connection->socket_fd, 1459 strlen (HTTP_100_CONTINUE) -
1487 &HTTP_100_CONTINUE[connection-> 1460 connection->continue_message_write_offset,
1488 continue_message_write_offset], 1461 MSG_NOSIGNAL);
1489 strlen (HTTP_100_CONTINUE) - 1462 if (ret < 0)
1490 connection->continue_message_write_offset, MSG_NOSIGNAL); 1463 {
1491 if (ret < 0) 1464 if (errno == EINTR)
1492 { 1465 break;
1493 if (errno == EINTR)
1494 break;
1495#if HAVE_MESSAGES 1466#if HAVE_MESSAGES
1496 MHD_DLOG (connection->daemon, 1467 MHD_DLOG (connection->daemon,
1497 "Failed to send data: %s\n", STRERROR (errno)); 1468 "Failed to send data: %s\n", STRERROR (errno));
1498#endif 1469#endif
1499 connection_close_error (connection); 1470 connection_close_error (connection);
1500 return MHD_NO; 1471 return MHD_NO;
1501 } 1472 }
1502#if DEBUG_SEND_DATA 1473#if DEBUG_SEND_DATA
1503 fprintf (stderr, 1474 fprintf (stderr,
1504 "Sent 100 continue response: `%.*s'\n", 1475 "Sent 100 continue response: `%.*s'\n",
1505 ret, 1476 ret,
1506 &HTTP_100_CONTINUE[connection->continue_message_write_offset]); 1477 &HTTP_100_CONTINUE[connection->
1478 continue_message_write_offset]);
1507#endif 1479#endif
1508 connection->continue_message_write_offset += ret; 1480 connection->continue_message_write_offset += ret;
1509 break; 1481 break;
1510 case MHD_CONNECTION_CONTINUE_SENT: 1482 case MHD_CONNECTION_CONTINUE_SENT:
1511 case MHD_CONNECTION_BODY_RECEIVED: 1483 case MHD_CONNECTION_BODY_RECEIVED:
1512 case MHD_CONNECTION_FOOTER_PART_RECEIVED: 1484 case MHD_CONNECTION_FOOTER_PART_RECEIVED:
1513 case MHD_CONNECTION_FOOTERS_RECEIVED: 1485 case MHD_CONNECTION_FOOTERS_RECEIVED:
1514 EXTRA_CHECK(0); 1486 EXTRA_CHECK (0);
1515 break; 1487 break;
1516 case MHD_CONNECTION_HEADERS_SENDING: 1488 case MHD_CONNECTION_HEADERS_SENDING:
1517 do_write(connection); 1489 do_write (connection);
1518 check_write_done(connection, 1490 check_write_done (connection, MHD_CONNECTION_HEADERS_SENT);
1519 MHD_CONNECTION_HEADERS_SENT); 1491 break;
1520 break; 1492 case MHD_CONNECTION_HEADERS_SENT:
1521 case MHD_CONNECTION_HEADERS_SENT: 1493 EXTRA_CHECK (0);
1522 EXTRA_CHECK(0); 1494 break;
1523 break; 1495 case MHD_CONNECTION_NORMAL_BODY_READY:
1524 case MHD_CONNECTION_NORMAL_BODY_READY: 1496 response = connection->response;
1525 response = connection->response; 1497 if (response->crc != NULL)
1526 if (response->crc != NULL) 1498 pthread_mutex_lock (&response->mutex);
1527 pthread_mutex_lock (&response->mutex); 1499 if (MHD_YES != try_ready_normal_body (connection))
1528 if (MHD_YES != try_ready_normal_body(connection)) 1500 {
1529 { 1501 if (response->crc != NULL)
1530 if (response->crc != NULL) 1502 pthread_mutex_unlock (&response->mutex);
1531 pthread_mutex_unlock (&response->mutex); 1503 connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY;
1532 connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; 1504 break;
1533 break; 1505 }
1534 } 1506 ret = SEND (connection->socket_fd,
1535 ret = SEND (connection->socket_fd, 1507 &response->data[connection->response_write_position -
1536 &response->data[connection->response_write_position - 1508 response->data_start],
1537 response->data_start], 1509 response->data_size -
1538 response->data_size - (connection->response_write_position - 1510 (connection->response_write_position -
1539 response->data_start), MSG_NOSIGNAL); 1511 response->data_start), MSG_NOSIGNAL);
1540#if DEBUG_SEND_DATA 1512#if DEBUG_SEND_DATA
1541 if (ret > 0) 1513 if (ret > 0)
1542 fprintf (stderr, 1514 fprintf (stderr,
1543 "Sent DATA response: `%.*s'\n", 1515 "Sent DATA response: `%.*s'\n",
1544 ret, 1516 ret,
1545 &response->data[connection->response_write_position - 1517 &response->data[connection->response_write_position -
1546 response->data_start]); 1518 response->data_start]);
1547#endif 1519#endif
1548 if (response->crc != NULL) 1520 if (response->crc != NULL)
1549 pthread_mutex_unlock (&response->mutex); 1521 pthread_mutex_unlock (&response->mutex);
1550 if (ret < 0) 1522 if (ret < 0)
1551 { 1523 {
1552 if (errno == EINTR) 1524 if (errno == EINTR)
1553 return MHD_YES; 1525 return MHD_YES;
1554#if HAVE_MESSAGES 1526#if HAVE_MESSAGES
1555 MHD_DLOG (connection->daemon, 1527 MHD_DLOG (connection->daemon,
1556 "Failed to send data: %s\n", STRERROR (errno)); 1528 "Failed to send data: %s\n", STRERROR (errno));
1557#endif 1529#endif
1558 connection_close_error (connection); 1530 connection_close_error (connection);
1559 return MHD_NO; 1531 return MHD_NO;
1560 } 1532 }
1561 connection->response_write_position += ret; 1533 connection->response_write_position += ret;
1562 if (connection->response_write_position == connection->response->total_size) 1534 if (connection->response_write_position ==
1563 connection->state = MHD_CONNECTION_FOOTERS_SENT; /* have no footers... */ 1535 connection->response->total_size)
1564 break; 1536 connection->state = MHD_CONNECTION_FOOTERS_SENT; /* have no footers... */
1565 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 1537 break;
1566 EXTRA_CHECK(0); 1538 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
1567 break; 1539 EXTRA_CHECK (0);
1568 case MHD_CONNECTION_CHUNKED_BODY_READY: 1540 break;
1569 do_write(connection); 1541 case MHD_CONNECTION_CHUNKED_BODY_READY:
1570 check_write_done(connection, 1542 do_write (connection);
1571 (connection->response->total_size == connection->response_write_position) 1543 check_write_done (connection,
1572 ? MHD_CONNECTION_BODY_SENT 1544 (connection->response->total_size ==
1573 : MHD_CONNECTION_CHUNKED_BODY_UNREADY); 1545 connection->
1574 break; 1546 response_write_position) ?
1575 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 1547 MHD_CONNECTION_BODY_SENT :
1576 case MHD_CONNECTION_BODY_SENT: 1548 MHD_CONNECTION_CHUNKED_BODY_UNREADY);
1577 EXTRA_CHECK(0); 1549 break;
1578 break; 1550 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
1579 case MHD_CONNECTION_FOOTERS_SENDING: 1551 case MHD_CONNECTION_BODY_SENT:
1580 do_write(connection); 1552 EXTRA_CHECK (0);
1581 check_write_done(connection, 1553 break;
1582 MHD_CONNECTION_FOOTERS_SENT); 1554 case MHD_CONNECTION_FOOTERS_SENDING:
1583 break; 1555 do_write (connection);
1584 case MHD_CONNECTION_FOOTERS_SENT: 1556 check_write_done (connection, MHD_CONNECTION_FOOTERS_SENT);
1585 EXTRA_CHECK(0); 1557 break;
1586 break; 1558 case MHD_CONNECTION_FOOTERS_SENT:
1587 case MHD_CONNECTION_CLOSED: 1559 EXTRA_CHECK (0);
1588 if (connection->socket_fd != -1) 1560 break;
1589 connection_close_error(connection); 1561 case MHD_CONNECTION_CLOSED:
1590 return MHD_NO; 1562 if (connection->socket_fd != -1)
1591 } 1563 connection_close_error (connection);
1592 break; 1564 return MHD_NO;
1593 } 1565 }
1566 break;
1567 }
1594 return MHD_YES; 1568 return MHD_YES;
1595} 1569}
1596 1570
@@ -1599,7 +1573,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1599 * has to happen even if the socket cannot be read or written to. All 1573 * has to happen even if the socket cannot be read or written to. All
1600 * implementations (multithreaded, external select, internal select) 1574 * implementations (multithreaded, external select, internal select)
1601 * call this function. 1575 * call this function.
1602 * 1576 *
1603 * @return MHD_YES if we should continue to process the 1577 * @return MHD_YES if we should continue to process the
1604 * connection (not dead yet), MHD_NO if it died 1578 * connection (not dead yet), MHD_NO if it died
1605 */ 1579 */
@@ -1607,258 +1581,252 @@ int
1607MHD_connection_handle_idle (struct MHD_Connection *connection) 1581MHD_connection_handle_idle (struct MHD_Connection *connection)
1608{ 1582{
1609 unsigned int timeout; 1583 unsigned int timeout;
1610 const char * end; 1584 const char *end;
1611 char * line; 1585 char *line;
1612 1586
1613 while (1) { 1587 while (1)
1588 {
1614#if DEBUG_STATES 1589#if DEBUG_STATES
1615 fprintf(stderr, 1590 fprintf (stderr, "`%s' in state %u\n", __FUNCTION__, connection->state);
1616 "`%s' in state %u\n", 1591#endif
1617 __FUNCTION__, 1592 switch (connection->state)
1618 connection->state); 1593 {
1619#endif 1594 case MHD_CONNECTION_INIT:
1620 switch (connection->state) 1595 line = get_next_header_line (connection);
1621 { 1596 if (line == NULL)
1622 case MHD_CONNECTION_INIT: 1597 break;
1623 line = get_next_header_line(connection); 1598 if (MHD_NO == parse_initial_message_line (connection, line))
1624 if (line == NULL) 1599 connection->state = MHD_CONNECTION_CLOSED;
1625 break; 1600 else
1626 if (MHD_NO == parse_initial_message_line (connection, line)) 1601 connection->state = MHD_CONNECTION_URL_RECEIVED;
1627 connection->state = MHD_CONNECTION_CLOSED; 1602 continue;
1628 else 1603 case MHD_CONNECTION_URL_RECEIVED:
1629 connection->state = MHD_CONNECTION_URL_RECEIVED; 1604 line = get_next_header_line (connection);
1630 continue; 1605 if (line == NULL)
1631 case MHD_CONNECTION_URL_RECEIVED: 1606 break;
1632 line = get_next_header_line(connection); 1607 if (strlen (line) == 0)
1633 if (line == NULL) 1608 {
1634 break; 1609 connection->state = MHD_CONNECTION_HEADERS_RECEIVED;
1635 if (strlen(line) == 0) 1610 continue;
1636 { 1611 }
1637 connection->state = MHD_CONNECTION_HEADERS_RECEIVED; 1612 process_header_line (connection, line);
1638 continue; 1613 connection->state = MHD_CONNECTION_HEADER_PART_RECEIVED;
1639 } 1614 continue;
1640 process_header_line(connection, line); 1615 case MHD_CONNECTION_HEADER_PART_RECEIVED:
1641 connection->state = MHD_CONNECTION_HEADER_PART_RECEIVED; 1616 line = get_next_header_line (connection);
1642 continue; 1617 if (line == NULL)
1643 case MHD_CONNECTION_HEADER_PART_RECEIVED: 1618 break;
1644 line = get_next_header_line(connection); 1619 process_broken_line (connection, line, MHD_HEADER_KIND);
1645 if (line == NULL) 1620 if (strlen (line) == 0)
1646 break; 1621 {
1647 process_broken_line(connection, 1622 connection->state = MHD_CONNECTION_HEADERS_RECEIVED;
1648 line, 1623 continue;
1649 MHD_HEADER_KIND); 1624 }
1650 if (strlen(line) == 0) 1625 continue;
1651 { 1626 case MHD_CONNECTION_HEADERS_RECEIVED:
1652 connection->state = MHD_CONNECTION_HEADERS_RECEIVED; 1627 parse_connection_headers (connection);
1653 continue; 1628 if (connection->state == MHD_CONNECTION_CLOSED)
1654 } 1629 continue;
1655 continue; 1630 connection->state = MHD_CONNECTION_HEADERS_PROCESSED;
1656 case MHD_CONNECTION_HEADERS_RECEIVED: 1631 continue;
1657 parse_connection_headers (connection); 1632 case MHD_CONNECTION_HEADERS_PROCESSED:
1658 if (connection->state == MHD_CONNECTION_CLOSED) 1633 call_connection_handler (connection); /* first call */
1659 continue; 1634 if (need_100_continue (connection))
1660 connection->state = MHD_CONNECTION_HEADERS_PROCESSED; 1635 {
1661 continue; 1636 connection->state = MHD_CONNECTION_CONTINUE_SENDING;
1662 case MHD_CONNECTION_HEADERS_PROCESSED: 1637 break;
1663 call_connection_handler (connection); /* first call */ 1638 }
1664 if (need_100_continue(connection)) 1639 connection->state = (connection->remaining_upload_size == 0)
1665 { 1640 ? MHD_CONNECTION_FOOTERS_RECEIVED : MHD_CONNECTION_CONTINUE_SENT;
1666 connection->state = MHD_CONNECTION_CONTINUE_SENDING; 1641 continue;
1667 break; 1642 case MHD_CONNECTION_CONTINUE_SENDING:
1668 } 1643 if (connection->continue_message_write_offset ==
1669 connection->state = (connection->remaining_upload_size == 0) 1644 strlen (HTTP_100_CONTINUE))
1670 ? MHD_CONNECTION_FOOTERS_RECEIVED 1645 {
1671 : MHD_CONNECTION_CONTINUE_SENT; 1646 connection->state = MHD_CONNECTION_CONTINUE_SENT;
1672 continue; 1647 continue;
1673 case MHD_CONNECTION_CONTINUE_SENDING: 1648 }
1674 if (connection->continue_message_write_offset == 1649 break;
1675 strlen (HTTP_100_CONTINUE)) 1650 case MHD_CONNECTION_CONTINUE_SENT:
1676 { 1651 if (connection->read_buffer_offset != 0)
1677 connection->state = MHD_CONNECTION_CONTINUE_SENT; 1652 {
1678 continue; 1653 call_connection_handler (connection); /* loop call */
1679 } 1654 if (connection->state == MHD_CONNECTION_CLOSED)
1680 break; 1655 continue;
1681 case MHD_CONNECTION_CONTINUE_SENT: 1656 }
1682 if (connection->read_buffer_offset != 0) { 1657 if ((connection->remaining_upload_size == 0) ||
1683 call_connection_handler(connection); /* loop call */ 1658 ((connection->remaining_upload_size == -1) &&
1684 if (connection->state == MHD_CONNECTION_CLOSED) 1659 (connection->read_buffer_offset == 0) &&
1685 continue; 1660 (MHD_YES == connection->read_closed)))
1686 } 1661 {
1687 if ( (connection->remaining_upload_size == 0) || 1662 if ((MHD_YES == connection->have_chunked_upload) &&
1688 ( (connection->remaining_upload_size == -1) && 1663 (MHD_NO == connection->read_closed))
1689 (connection->read_buffer_offset == 0) && 1664 connection->state = MHD_CONNECTION_BODY_RECEIVED;
1690 (MHD_YES == connection->read_closed) ) ) 1665 else
1691 { 1666 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
1692 if ( (MHD_YES == connection->have_chunked_upload) && 1667 continue;
1693 (MHD_NO == connection->read_closed) ) 1668 }
1694 connection->state = MHD_CONNECTION_BODY_RECEIVED; 1669 break;
1695 else 1670 case MHD_CONNECTION_BODY_RECEIVED:
1696 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; 1671 line = get_next_header_line (connection);
1697 continue; 1672 if (line == NULL)
1698 } 1673 break;
1699 break; 1674 if (strlen (line) == 0)
1700 case MHD_CONNECTION_BODY_RECEIVED: 1675 {
1701 line = get_next_header_line(connection); 1676 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
1702 if (line == NULL) 1677 continue;
1703 break; 1678 }
1704 if (strlen(line) == 0) 1679 process_header_line (connection, line);
1705 { 1680 connection->state = MHD_CONNECTION_FOOTER_PART_RECEIVED;
1706 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; 1681 continue;
1707 continue; 1682 case MHD_CONNECTION_FOOTER_PART_RECEIVED:
1708 } 1683 line = get_next_header_line (connection);
1709 process_header_line(connection, line); 1684 if (line == NULL)
1710 connection->state = MHD_CONNECTION_FOOTER_PART_RECEIVED; 1685 break;
1711 continue; 1686 process_broken_line (connection, line, MHD_FOOTER_KIND);
1712 case MHD_CONNECTION_FOOTER_PART_RECEIVED: 1687 if (strlen (line) == 0)
1713 line = get_next_header_line(connection); 1688 {
1714 if (line == NULL) 1689 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
1715 break; 1690 continue;
1716 process_broken_line(connection, 1691 }
1717 line, 1692 continue;
1718 MHD_FOOTER_KIND); 1693 case MHD_CONNECTION_FOOTERS_RECEIVED:
1719 if (strlen(line) == 0) 1694 call_connection_handler (connection); /* "final" call */
1720 { 1695 if (connection->state == MHD_CONNECTION_CLOSED)
1721 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; 1696 continue;
1722 continue; 1697 if (connection->response == NULL)
1723 } 1698 break; /* try again next time */
1724 continue; 1699 if (MHD_NO == build_header_response (connection))
1725 case MHD_CONNECTION_FOOTERS_RECEIVED: 1700 {
1726 call_connection_handler (connection); /* "final" call */ 1701 /* oops - close! */
1727 if (connection->state == MHD_CONNECTION_CLOSED)
1728 continue;
1729 if (connection->response == NULL)
1730 break; /* try again next time */
1731 if (MHD_NO == build_header_response (connection))
1732 {
1733 /* oops - close! */
1734#if HAVE_MESSAGES 1702#if HAVE_MESSAGES
1735 MHD_DLOG (connection->daemon, 1703 MHD_DLOG (connection->daemon,
1736 "Closing connection (failed to create response header)\n"); 1704 "Closing connection (failed to create response header)\n");
1737#endif 1705#endif
1738 connection->state = MHD_CONNECTION_CLOSED; 1706 connection->state = MHD_CONNECTION_CLOSED;
1739 continue; 1707 continue;
1740 } 1708 }
1741 connection->state = MHD_CONNECTION_HEADERS_SENDING; 1709 connection->state = MHD_CONNECTION_HEADERS_SENDING;
1742 break; 1710 break;
1743 case MHD_CONNECTION_HEADERS_SENDING: 1711 case MHD_CONNECTION_HEADERS_SENDING:
1744 /* no default action */ 1712 /* no default action */
1745 break; 1713 break;
1746 case MHD_CONNECTION_HEADERS_SENT: 1714 case MHD_CONNECTION_HEADERS_SENT:
1747 if (connection->have_chunked_upload) 1715 if (connection->have_chunked_upload)
1748 connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY; 1716 connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY;
1749 else 1717 else
1750 connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; 1718 connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY;
1751 continue; 1719 continue;
1752 case MHD_CONNECTION_NORMAL_BODY_READY: 1720 case MHD_CONNECTION_NORMAL_BODY_READY:
1753 /* nothing to do here */ 1721 /* nothing to do here */
1754 break; 1722 break;
1755 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 1723 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
1756 if (connection->response->crc != NULL) 1724 if (connection->response->crc != NULL)
1757 pthread_mutex_lock (&connection->response->mutex); 1725 pthread_mutex_lock (&connection->response->mutex);
1758 if (MHD_YES == try_ready_normal_body(connection)) 1726 if (MHD_YES == try_ready_normal_body (connection))
1759 { 1727 {
1760 if (connection->response->crc != NULL) 1728 if (connection->response->crc != NULL)
1761 pthread_mutex_unlock (&connection->response->mutex); 1729 pthread_mutex_unlock (&connection->response->mutex);
1762 connection->state = MHD_CONNECTION_NORMAL_BODY_READY; 1730 connection->state = MHD_CONNECTION_NORMAL_BODY_READY;
1763 break; 1731 break;
1764 } 1732 }
1765 if (connection->response->crc != NULL) 1733 if (connection->response->crc != NULL)
1766 pthread_mutex_unlock (&connection->response->mutex); 1734 pthread_mutex_unlock (&connection->response->mutex);
1767 /* not ready, no socket action */ 1735 /* not ready, no socket action */
1768 break; 1736 break;
1769 case MHD_CONNECTION_CHUNKED_BODY_READY: 1737 case MHD_CONNECTION_CHUNKED_BODY_READY:
1770 /* nothing to do here */ 1738 /* nothing to do here */
1771 break; 1739 break;
1772 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 1740 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
1773 if (connection->response->crc != NULL) 1741 if (connection->response->crc != NULL)
1774 pthread_mutex_lock (&connection->response->mutex); 1742 pthread_mutex_lock (&connection->response->mutex);
1775 if (MHD_YES == try_ready_chunked_body(connection)) 1743 if (MHD_YES == try_ready_chunked_body (connection))
1776 { 1744 {
1777 if (connection->response->crc != NULL) 1745 if (connection->response->crc != NULL)
1778 pthread_mutex_unlock (&connection->response->mutex); 1746 pthread_mutex_unlock (&connection->response->mutex);
1779 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; 1747 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY;
1780 continue; 1748 continue;
1781 } 1749 }
1782 if (connection->response->crc != NULL) 1750 if (connection->response->crc != NULL)
1783 pthread_mutex_unlock (&connection->response->mutex); 1751 pthread_mutex_unlock (&connection->response->mutex);
1784 break; 1752 break;
1785 case MHD_CONNECTION_BODY_SENT: 1753 case MHD_CONNECTION_BODY_SENT:
1786 build_header_response(connection); 1754 build_header_response (connection);
1787 if (connection->write_buffer_send_offset == connection->write_buffer_append_offset) 1755 if (connection->write_buffer_send_offset ==
1788 connection->state = MHD_CONNECTION_FOOTERS_SENT; 1756 connection->write_buffer_append_offset)
1789 else 1757 connection->state = MHD_CONNECTION_FOOTERS_SENT;
1790 connection->state = MHD_CONNECTION_FOOTERS_SENDING; 1758 else
1791 continue; 1759 connection->state = MHD_CONNECTION_FOOTERS_SENDING;
1792 case MHD_CONNECTION_FOOTERS_SENDING: 1760 continue;
1793 /* no default action */ 1761 case MHD_CONNECTION_FOOTERS_SENDING:
1794 break; 1762 /* no default action */
1795 case MHD_CONNECTION_FOOTERS_SENT: 1763 break;
1796 MHD_destroy_response (connection->response); 1764 case MHD_CONNECTION_FOOTERS_SENT:
1797 if (connection->daemon->notify_completed != NULL) 1765 MHD_destroy_response (connection->response);
1798 connection->daemon->notify_completed (connection->daemon-> 1766 if (connection->daemon->notify_completed != NULL)
1799 notify_completed_cls, 1767 connection->daemon->notify_completed (connection->daemon->
1800 connection, 1768 notify_completed_cls,
1801 &connection->client_context, 1769 connection,
1802 MHD_REQUEST_TERMINATED_COMPLETED_OK); 1770 &connection->client_context,
1803 end = MHD_lookup_connection_value (connection, 1771 MHD_REQUEST_TERMINATED_COMPLETED_OK);
1804 MHD_HEADER_KIND, 1772 end = MHD_lookup_connection_value (connection,
1805 MHD_HTTP_HEADER_CONNECTION); 1773 MHD_HEADER_KIND,
1806 connection->client_context = NULL; 1774 MHD_HTTP_HEADER_CONNECTION);
1807 connection->continue_message_write_offset = 0; 1775 connection->client_context = NULL;
1808 connection->responseCode = 0; 1776 connection->continue_message_write_offset = 0;
1809 connection->response = NULL; 1777 connection->responseCode = 0;
1810 connection->headers_received = NULL; 1778 connection->response = NULL;
1811 connection->response_write_position = 0; 1779 connection->headers_received = NULL;
1812 connection->have_chunked_upload = MHD_NO; 1780 connection->response_write_position = 0;
1813 connection->method = NULL; 1781 connection->have_chunked_upload = MHD_NO;
1814 connection->url = NULL; 1782 connection->method = NULL;
1815 connection->write_buffer = NULL; 1783 connection->url = NULL;
1816 connection->write_buffer_size = 0; 1784 connection->write_buffer = NULL;
1817 connection->write_buffer_send_offset = 0; 1785 connection->write_buffer_size = 0;
1818 connection->write_buffer_append_offset = 0; 1786 connection->write_buffer_send_offset = 0;
1819 if ((end != NULL) && (0 == strcasecmp (end, "close"))) 1787 connection->write_buffer_append_offset = 0;
1820 { 1788 if ((end != NULL) && (0 == strcasecmp (end, "close")))
1821 connection->read_closed = MHD_YES; 1789 {
1822 connection->read_buffer_offset = 0; 1790 connection->read_closed = MHD_YES;
1823 } 1791 connection->read_buffer_offset = 0;
1824 if ( ( (MHD_YES == connection->read_closed) && 1792 }
1825 (0 == connection->read_buffer_offset) ) || 1793 if (((MHD_YES == connection->read_closed) &&
1826 (connection->version == NULL) || 1794 (0 == connection->read_buffer_offset)) ||
1827 (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)) ) 1795 (connection->version == NULL) ||
1828 { 1796 (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)))
1829 connection->state = MHD_CONNECTION_CLOSED; 1797 {
1830 MHD_pool_destroy (connection->pool); 1798 connection->state = MHD_CONNECTION_CLOSED;
1831 connection->pool = NULL; 1799 MHD_pool_destroy (connection->pool);
1832 connection->read_buffer = NULL; 1800 connection->pool = NULL;
1833 connection->read_buffer_size = 0; 1801 connection->read_buffer = NULL;
1834 connection->read_buffer_offset = 0; 1802 connection->read_buffer_size = 0;
1835 } 1803 connection->read_buffer_offset = 0;
1836 else 1804 }
1837 { 1805 else
1838 connection->version = NULL; 1806 {
1839 connection->state = MHD_CONNECTION_INIT; 1807 connection->version = NULL;
1840 connection->read_buffer 1808 connection->state = MHD_CONNECTION_INIT;
1841 = MHD_pool_reset(connection->pool, 1809 connection->read_buffer
1842 connection->read_buffer, 1810 = MHD_pool_reset (connection->pool,
1843 connection->read_buffer_size); 1811 connection->read_buffer,
1844 } 1812 connection->read_buffer_size);
1845 continue; 1813 }
1846 case MHD_CONNECTION_CLOSED: 1814 continue;
1847 if (connection->socket_fd != -1) 1815 case MHD_CONNECTION_CLOSED:
1848 connection_close_error (connection); 1816 if (connection->socket_fd != -1)
1849 break; 1817 connection_close_error (connection);
1850 default: 1818 break;
1851 EXTRA_CHECK(0); 1819 default:
1852 break; 1820 EXTRA_CHECK (0);
1853 } 1821 break;
1854 break; 1822 }
1855 } 1823 break;
1824 }
1856 timeout = connection->daemon->connection_timeout; 1825 timeout = connection->daemon->connection_timeout;
1857 if ( (timeout != 0) && 1826 if ((timeout != 0) && (time (NULL) - timeout > connection->last_activity))
1858 (time(NULL) - timeout > connection->last_activity) )
1859 { 1827 {
1860 connection_close_error (connection); 1828 connection_close_error (connection);
1861 return MHD_NO; 1829 return MHD_NO;
1862 } 1830 }
1863 return MHD_YES; 1831 return MHD_YES;
1864 1832
diff --git a/src/daemon/connection.h b/src/daemon/connection.h
index a1763b55..75d26293 100644
--- a/src/daemon/connection.h
+++ b/src/daemon/connection.h
@@ -44,7 +44,7 @@ MHD_connection_get_fdset (struct MHD_Connection *connection,
44 * determined that there is data to be read off a socket. All implementations 44 * determined that there is data to be read off a socket. All implementations
45 * (multithreaded, external select, internal select) call this function 45 * (multithreaded, external select, internal select) call this function
46 * to handle reads. 46 * to handle reads.
47 * 47 *
48 * @return MHD_YES if we should continue to process the 48 * @return MHD_YES if we should continue to process the
49 * connection (not dead yet), MHD_NO if it died 49 * connection (not dead yet), MHD_NO if it died
50 */ 50 */
@@ -56,7 +56,7 @@ int MHD_connection_handle_read (struct MHD_Connection *connection);
56 * determined that the socket can be written to. If there is no data 56 * determined that the socket can be written to. If there is no data
57 * to be written, however, the function call does nothing. All implementations 57 * to be written, however, the function call does nothing. All implementations
58 * (multithreaded, external select, internal select) call this function 58 * (multithreaded, external select, internal select) call this function
59 * 59 *
60 * @return MHD_YES if we should continue to process the 60 * @return MHD_YES if we should continue to process the
61 * connection (not dead yet), MHD_NO if it died 61 * connection (not dead yet), MHD_NO if it died
62 */ 62 */
@@ -68,11 +68,10 @@ int MHD_connection_handle_write (struct MHD_Connection *connection);
68 * has to happen even if the socket cannot be read or written to. All 68 * has to happen even if the socket cannot be read or written to. All
69 * implementations (multithreaded, external select, internal select) 69 * implementations (multithreaded, external select, internal select)
70 * call this function. 70 * call this function.
71 * 71 *
72 * @return MHD_YES if we should continue to process the 72 * @return MHD_YES if we should continue to process the
73 * connection (not dead yet), MHD_NO if it died 73 * connection (not dead yet), MHD_NO if it died
74 */ 74 */
75int 75int MHD_connection_handle_idle (struct MHD_Connection *connection);
76MHD_connection_handle_idle (struct MHD_Connection *connection); 76
77
78#endif 77#endif
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index b6f1e9f3..6a0e4ab2 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -42,13 +42,13 @@
42 42
43/** 43/**
44 * Print extra messages with reasons for closing 44 * Print extra messages with reasons for closing
45 * sockets? (only adds non-error messages). 45 * sockets? (only adds non-error messages).
46 */ 46 */
47#define DEBUG_CLOSE MHD_NO 47#define DEBUG_CLOSE MHD_NO
48 48
49/** 49/**
50 * Print extra messages when establishing 50 * Print extra messages when establishing
51 * connections? (only adds non-error messages). 51 * connections? (only adds non-error messages).
52 */ 52 */
53#define DEBUG_CONNECT MHD_NO 53#define DEBUG_CONNECT MHD_NO
54 54
@@ -116,20 +116,19 @@ MHD_handle_connection (void *data)
116 if (con == NULL) 116 if (con == NULL)
117 abort (); 117 abort ();
118 timeout = con->daemon->connection_timeout; 118 timeout = con->daemon->connection_timeout;
119 while ( (!con->daemon->shutdown) && 119 while ((!con->daemon->shutdown) && (con->socket_fd != -1))
120 (con->socket_fd != -1) )
121 { 120 {
122 FD_ZERO (&rs); 121 FD_ZERO (&rs);
123 FD_ZERO (&ws); 122 FD_ZERO (&ws);
124 FD_ZERO (&es); 123 FD_ZERO (&es);
125 max = 0; 124 max = 0;
126 MHD_connection_get_fdset (con, &rs, &ws, &es, &max); 125 MHD_connection_get_fdset (con, &rs, &ws, &es, &max);
127 now = time(NULL); 126 now = time (NULL);
128 tv.tv_usec = 0; 127 tv.tv_usec = 0;
129 if ( timeout > (now - con->last_activity) ) 128 if (timeout > (now - con->last_activity))
130 tv.tv_sec = timeout - (now - con->last_activity); 129 tv.tv_sec = timeout - (now - con->last_activity);
131 else 130 else
132 tv.tv_sec = 0; 131 tv.tv_sec = 0;
133 num_ready = SELECT (max + 1, 132 num_ready = SELECT (max + 1,
134 &rs, &ws, &es, (timeout != 0) ? &tv : NULL); 133 &rs, &ws, &es, (timeout != 0) ? &tv : NULL);
135 if (num_ready < 0) 134 if (num_ready < 0)
@@ -143,12 +142,11 @@ MHD_handle_connection (void *data)
143 break; 142 break;
144 } 143 }
145 if (FD_ISSET (con->socket_fd, &rs)) 144 if (FD_ISSET (con->socket_fd, &rs))
146 MHD_connection_handle_read (con); 145 MHD_connection_handle_read (con);
147 if ((con->socket_fd != -1) && 146 if ((con->socket_fd != -1) && (FD_ISSET (con->socket_fd, &ws)))
148 (FD_ISSET (con->socket_fd, &ws)) ) 147 MHD_connection_handle_write (con);
149 MHD_connection_handle_write (con); 148 if (con->socket_fd != -1)
150 if (con->socket_fd != -1) 149 MHD_connection_handle_idle (con);
151 MHD_connection_handle_idle (con);
152 } 150 }
153 if (con->socket_fd != -1) 151 if (con->socket_fd != -1)
154 { 152 {
@@ -309,7 +307,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
309 pthread_kill (pos->pid, SIGALRM); 307 pthread_kill (pos->pid, SIGALRM);
310 pthread_join (pos->pid, &unused); 308 pthread_join (pos->pid, &unused);
311 } 309 }
312 MHD_destroy_response (pos->response); 310 MHD_destroy_response (pos->response);
313 MHD_pool_destroy (pos->pool); 311 MHD_pool_destroy (pos->pool);
314 free (pos->addr); 312 free (pos->addr);
315 free (pos); 313 free (pos);
@@ -455,12 +453,11 @@ MHD_select (struct MHD_Daemon *daemon, int may_block)
455 if (ds != -1) 453 if (ds != -1)
456 { 454 {
457 if (FD_ISSET (ds, &rs)) 455 if (FD_ISSET (ds, &rs))
458 MHD_connection_handle_read (pos); 456 MHD_connection_handle_read (pos);
459 if ( (pos->socket_fd != -1) && 457 if ((pos->socket_fd != -1) && (FD_ISSET (ds, &ws)))
460 (FD_ISSET (ds, &ws)) ) 458 MHD_connection_handle_write (pos);
461 MHD_connection_handle_write (pos); 459 if (pos->socket_fd != -1)
462 if (pos->socket_fd != -1) 460 MHD_connection_handle_idle (pos);
463 MHD_connection_handle_idle(pos);
464 } 461 }
465 pos = pos->next; 462 pos = pos->next;
466 } 463 }
diff --git a/src/daemon/daemontest_get.c b/src/daemon/daemontest_get.c
index 1a6ca12a..2d5729c1 100644
--- a/src/daemon/daemontest_get.c
+++ b/src/daemon/daemontest_get.c
@@ -73,17 +73,18 @@ ahc_echo (void *cls,
73 73
74 if (0 != strcmp (me, method)) 74 if (0 != strcmp (me, method))
75 return MHD_NO; /* unexpected method */ 75 return MHD_NO; /* unexpected method */
76 if (&ptr != *unused) { 76 if (&ptr != *unused)
77 *unused = &ptr; 77 {
78 return MHD_YES; 78 *unused = &ptr;
79 } 79 return MHD_YES;
80 }
80 *unused = NULL; 81 *unused = NULL;
81 response = MHD_create_response_from_data (strlen (url), 82 response = MHD_create_response_from_data (strlen (url),
82 (void *) url, MHD_NO, MHD_YES); 83 (void *) url, MHD_NO, MHD_YES);
83 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 84 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
84 MHD_destroy_response (response); 85 MHD_destroy_response (response);
85 if (ret == MHD_NO) 86 if (ret == MHD_NO)
86 abort(); 87 abort ();
87 return ret; 88 return ret;
88} 89}
89 90
diff --git a/src/daemon/daemontest_large_put.c b/src/daemon/daemontest_large_put.c
index 3bbf707e..b0c7bf37 100644
--- a/src/daemon/daemontest_large_put.c
+++ b/src/daemon/daemontest_large_put.c
@@ -96,16 +96,15 @@ ahc_echo (void *cls,
96 return MHD_NO; /* unexpected method */ 96 return MHD_NO; /* unexpected method */
97 if ((*done) == 0) 97 if ((*done) == 0)
98 { 98 {
99 if (*upload_data_size != PUT_SIZE) 99 if (*upload_data_size != PUT_SIZE)
100 { 100 {
101#if 0 101#if 0
102 fprintf(stderr, 102 fprintf (stderr,
103 "Waiting for more data (%u/%u)...\n", 103 "Waiting for more data (%u/%u)...\n",
104 *upload_data_size, 104 *upload_data_size, PUT_SIZE);
105 PUT_SIZE);
106#endif 105#endif
107 return MHD_YES; /* not yet ready */ 106 return MHD_YES; /* not yet ready */
108 } 107 }
109 if (0 == memcmp (upload_data, put_buffer, PUT_SIZE)) 108 if (0 == memcmp (upload_data, put_buffer, PUT_SIZE))
110 { 109 {
111 *upload_data_size = 0; 110 *upload_data_size = 0;
@@ -236,10 +235,7 @@ testMultithreadedPut ()
236 MHD_stop_daemon (d); 235 MHD_stop_daemon (d);
237 if (cbc.pos != strlen ("/hello_world")) 236 if (cbc.pos != strlen ("/hello_world"))
238 { 237 {
239 fprintf(stderr, 238 fprintf (stderr, "Got invalid response `%.*s'\n", cbc.pos, cbc.buf);
240 "Got invalid response `%.*s'\n",
241 cbc.pos,
242 cbc.buf);
243 return 64; 239 return 64;
244 } 240 }
245 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 241 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
@@ -274,10 +270,9 @@ testExternalPut ()
274 multi = NULL; 270 multi = NULL;
275 d = MHD_start_daemon (MHD_USE_DEBUG, 271 d = MHD_start_daemon (MHD_USE_DEBUG,
276 1082, 272 1082,
277 NULL, NULL, &ahc_echo, &done_flag, 273 NULL, NULL, &ahc_echo, &done_flag,
278 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 274 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
279 PUT_SIZE * 4, 275 PUT_SIZE * 4, MHD_OPTION_END);
280 MHD_OPTION_END);
281 if (d == NULL) 276 if (d == NULL)
282 return 256; 277 return 256;
283 c = curl_easy_init (); 278 c = curl_easy_init ();
@@ -375,10 +370,7 @@ testExternalPut ()
375 MHD_stop_daemon (d); 370 MHD_stop_daemon (d);
376 if (cbc.pos != strlen ("/hello_world")) 371 if (cbc.pos != strlen ("/hello_world"))
377 { 372 {
378 fprintf(stderr, 373 fprintf (stderr, "Got invalid response `%.*s'\n", cbc.pos, cbc.buf);
379 "Got invalid response `%.*s'\n",
380 cbc.pos,
381 cbc.buf);
382 return 8192; 374 return 8192;
383 } 375 }
384 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 376 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
@@ -403,7 +395,7 @@ main (int argc, char *const *argv)
403 errorCount += testInternalPut (); 395 errorCount += testInternalPut ();
404 errorCount += testMultithreadedPut (); 396 errorCount += testMultithreadedPut ();
405 } 397 }
406 errorCount += testExternalPut (); 398 errorCount += testExternalPut ();
407 free (put_buffer); 399 free (put_buffer);
408 if (errorCount != 0) 400 if (errorCount != 0)
409 fprintf (stderr, "Error (code: %u)\n", errorCount); 401 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/daemon/daemontest_post_loop.c b/src/daemon/daemontest_post_loop.c
index 65689dba..8630304e 100644
--- a/src/daemon/daemontest_post_loop.c
+++ b/src/daemon/daemontest_post_loop.c
@@ -311,7 +311,7 @@ testExternalPost ()
311 MHD_stop_daemon (d); 311 MHD_stop_daemon (d);
312 return 2048; 312 return 2048;
313 } 313 }
314 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 314 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
315 { 315 {
316 curl_multi_remove_handle (multi, c); 316 curl_multi_remove_handle (multi, c);
317 curl_multi_cleanup (multi); 317 curl_multi_cleanup (multi);
@@ -320,7 +320,7 @@ testExternalPost ()
320 return 4096; 320 return 4096;
321 } 321 }
322 if (MHD_NO == MHD_get_timeout (d, &timeout)) 322 if (MHD_NO == MHD_get_timeout (d, &timeout))
323 timeout = 100; /* 100ms == INFTY -- CURL bug... */ 323 timeout = 100; /* 100ms == INFTY -- CURL bug... */
324 if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) && 324 if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) &&
325 (ctimeout < timeout) && (ctimeout >= 0)) 325 (ctimeout < timeout) && (ctimeout >= 0))
326 timeout = ctimeout; 326 timeout = ctimeout;
diff --git a/src/daemon/daemontest_postform.c b/src/daemon/daemontest_postform.c
index 00734df6..4142b138 100644
--- a/src/daemon/daemontest_postform.c
+++ b/src/daemon/daemontest_postform.c
@@ -73,11 +73,7 @@ post_iterator (void *cls,
73 int *eok = cls; 73 int *eok = cls;
74 74
75#if 0 75#if 0
76 fprintf(stderr, 76 fprintf (stderr, "PI sees %s-%.*s\n", key, size, value);
77 "PI sees %s-%.*s\n",
78 key,
79 size,
80 value);
81#endif 77#endif
82 if ((0 == strcmp (key, "name")) && 78 if ((0 == strcmp (key, "name")) &&
83 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size))) 79 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size)))
@@ -102,7 +98,7 @@ ahc_echo (void *cls,
102 struct MHD_PostProcessor *pp; 98 struct MHD_PostProcessor *pp;
103 int ret; 99 int ret;
104 100
105 if (0 != strcmp ("POST", method)) 101 if (0 != strcmp ("POST", method))
106 { 102 {
107 printf ("METHOD: %s\n", method); 103 printf ("METHOD: %s\n", method);
108 return MHD_NO; /* unexpected method */ 104 return MHD_NO; /* unexpected method */
diff --git a/src/daemon/daemontest_put_chunked.c b/src/daemon/daemontest_put_chunked.c
index 84afc444..0cc3eb8f 100644
--- a/src/daemon/daemontest_put_chunked.c
+++ b/src/daemon/daemontest_put_chunked.c
@@ -106,9 +106,7 @@ ahc_echo (void *cls,
106 return MHD_NO; 106 return MHD_NO;
107 } 107 }
108#if 0 108#if 0
109 fprintf(stderr, 109 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8);
110 "Not ready for response: %u/%u\n",
111 *done, 8);
112#endif 110#endif
113 return MHD_YES; 111 return MHD_YES;
114 } 112 }
diff --git a/src/daemon/fileserver_example.c b/src/daemon/fileserver_example.c
index 9f86fd2c..866c2463 100644
--- a/src/daemon/fileserver_example.c
+++ b/src/daemon/fileserver_example.c
@@ -62,13 +62,13 @@ ahc_echo (void *cls,
62 62
63 if (0 != strcmp (method, "GET")) 63 if (0 != strcmp (method, "GET"))
64 return MHD_NO; /* unexpected method */ 64 return MHD_NO; /* unexpected method */
65 if (&aptr != *ptr) 65 if (&aptr != *ptr)
66 { 66 {
67 /* do never respond on first call */ 67 /* do never respond on first call */
68 *ptr = &aptr; 68 *ptr = &aptr;
69 return MHD_YES; 69 return MHD_YES;
70 } 70 }
71 *ptr = NULL; /* reset when done */ 71 *ptr = NULL; /* reset when done */
72 file = fopen (&url[1], "r"); 72 file = fopen (&url[1], "r");
73 if (file == NULL) 73 if (file == NULL)
74 { 74 {
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
index 4749d10d..43599149 100644
--- a/src/daemon/internal.h
+++ b/src/daemon/internal.h
@@ -239,12 +239,12 @@ enum MHD_CONNECTION_STATE
239 * 11: We have sent the response headers. Get ready to send the body. 239 * 11: We have sent the response headers. Get ready to send the body.
240 */ 240 */
241 MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1, 241 MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
242 242
243 /** 243 /**
244 * 12: We are ready to send a part of a non-chunked body. Send it. 244 * 12: We are ready to send a part of a non-chunked body. Send it.
245 */ 245 */
246 MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1, 246 MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
247 247
248 /** 248 /**
249 * 13: We are waiting for the client to provide more 249 * 13: We are waiting for the client to provide more
250 * data of a non-chunked body. 250 * data of a non-chunked body.
@@ -260,16 +260,16 @@ enum MHD_CONNECTION_STATE
260 * 15: We are waiting for the client to provide a chunk of the body. 260 * 15: We are waiting for the client to provide a chunk of the body.
261 */ 261 */
262 MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1, 262 MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
263 263
264 /** 264 /**
265 * 16: We have sent the response body. Prepare the footers. 265 * 16: We have sent the response body. Prepare the footers.
266 */ 266 */
267 MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1, 267 MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
268 268
269 /** 269 /**
270 * 17: We have prepared the response footer. Send it. 270 * 17: We have prepared the response footer. Send it.
271 */ 271 */
272 MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1, 272 MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
273 273
274 /** 274 /**
275 * 18: We have sent the response footer. Shutdown or restart. 275 * 18: We have sent the response footer. Shutdown or restart.
@@ -281,7 +281,7 @@ enum MHD_CONNECTION_STATE
281 * allowed). 281 * allowed).
282 */ 282 */
283 MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1, 283 MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
284 284
285}; 285};
286 286
287struct MHD_Connection 287struct MHD_Connection
@@ -367,7 +367,7 @@ struct MHD_Connection
367 char *last; 367 char *last;
368 368
369 /** 369 /**
370 * Position after the colon on the last incomplete header 370 * Position after the colon on the last incomplete header
371 * line during parsing of headers. 371 * line during parsing of headers.
372 * Allocated in pool. Only valid if state is 372 * Allocated in pool. Only valid if state is
373 * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED. 373 * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED.
@@ -389,7 +389,7 @@ struct MHD_Connection
389 /** 389 /**
390 * Size of read_buffer (in bytes). This value indicates 390 * Size of read_buffer (in bytes). This value indicates
391 * how many bytes we're willing to read into the buffer; 391 * how many bytes we're willing to read into the buffer;
392 * the real buffer is one byte longer to allow for 392 * the real buffer is one byte longer to allow for
393 * adding zero-termination (when needed). 393 * adding zero-termination (when needed).
394 */ 394 */
395 size_t read_buffer_size; 395 size_t read_buffer_size;
@@ -419,7 +419,7 @@ struct MHD_Connection
419 /** 419 /**
420 * How many more bytes of the body do we expect 420 * How many more bytes of the body do we expect
421 * to read? "-1" for unknown. 421 * to read? "-1" for unknown.
422 */ 422 */
423 size_t remaining_upload_size; 423 size_t remaining_upload_size;
424 424
425 /** 425 /**
@@ -476,7 +476,7 @@ struct MHD_Connection
476 /** 476 /**
477 * Set to MHD_YES if the response's content reader 477 * Set to MHD_YES if the response's content reader
478 * callback failed to provide data the last time 478 * callback failed to provide data the last time
479 * we tried to read from it. In that case, the 479 * we tried to read from it. In that case, the
480 * write socket should be marked as unready until 480 * write socket should be marked as unready until
481 * the CRC call succeeds. 481 * the CRC call succeeds.
482 */ 482 */
@@ -525,7 +525,7 @@ struct MHD_Daemon
525 /** 525 /**
526 * Closure argument to default_handler. 526 * Closure argument to default_handler.
527 */ 527 */
528 void * default_handler_cls; 528 void *default_handler_cls;
529 529
530 /** 530 /**
531 * Linked list of our current connections. 531 * Linked list of our current connections.
diff --git a/src/daemon/memorypool.c b/src/daemon/memorypool.c
index 1bb12bae..e58cab38 100644
--- a/src/daemon/memorypool.c
+++ b/src/daemon/memorypool.c
@@ -191,24 +191,21 @@ MHD_pool_reallocate (struct MemoryPool *pool,
191/** 191/**
192 * Clear all entries from the memory pool except 192 * Clear all entries from the memory pool except
193 * for "keep" of the given "size". 193 * for "keep" of the given "size".
194 * 194 *
195 * @param keep pointer to the entry to keep (maybe NULL) 195 * @param keep pointer to the entry to keep (maybe NULL)
196 * @param size how many bytes need to be kept at this address 196 * @param size how many bytes need to be kept at this address
197 * @return addr new address of "keep" (if it had to change) 197 * @return addr new address of "keep" (if it had to change)
198 */ 198 */
199void *MHD_pool_reset(struct MemoryPool * pool, 199void *
200 void * keep, 200MHD_pool_reset (struct MemoryPool *pool, void *keep, unsigned int size)
201 unsigned int size)
202{ 201{
203 if (keep != NULL) 202 if (keep != NULL)
204 { 203 {
205 if (keep != pool->memory) 204 if (keep != pool->memory)
206 { 205 {
207 memmove(pool->memory, 206 memmove (pool->memory, keep, size);
208 keep, 207 keep = pool->memory;
209 size); 208 }
210 keep = pool->memory;
211 }
212 pool->pos = size; 209 pool->pos = size;
213 } 210 }
214 pool->end = pool->size; 211 pool->end = pool->size;
diff --git a/src/daemon/memorypool.h b/src/daemon/memorypool.h
index 1d8ffb32..537fb61e 100644
--- a/src/daemon/memorypool.h
+++ b/src/daemon/memorypool.h
@@ -84,13 +84,11 @@ void *MHD_pool_reallocate (struct MemoryPool *pool,
84/** 84/**
85 * Clear all entries from the memory pool except 85 * Clear all entries from the memory pool except
86 * for "keep" of the given "size". 86 * for "keep" of the given "size".
87 * 87 *
88 * @param keep pointer to the entry to keep (maybe NULL) 88 * @param keep pointer to the entry to keep (maybe NULL)
89 * @param size how many bytes need to be kept at this address 89 * @param size how many bytes need to be kept at this address
90 * @return addr new address of "keep" (if it had to change) 90 * @return addr new address of "keep" (if it had to change)
91 */ 91 */
92void *MHD_pool_reset(struct MemoryPool * pool, 92void *MHD_pool_reset (struct MemoryPool *pool, void *keep, unsigned int size);
93 void * keep,
94 unsigned int size);
95 93
96#endif 94#endif
diff --git a/src/daemon/minimal_example.c b/src/daemon/minimal_example.c
index badff7a2..68b4a3d6 100644
--- a/src/daemon/minimal_example.c
+++ b/src/daemon/minimal_example.c
@@ -50,13 +50,13 @@ ahc_echo (void *cls,
50 50
51 if (0 != strcmp (method, "GET")) 51 if (0 != strcmp (method, "GET"))
52 return MHD_NO; /* unexpected method */ 52 return MHD_NO; /* unexpected method */
53 if (&aptr != *ptr) 53 if (&aptr != *ptr)
54 { 54 {
55 /* do never respond on first call */ 55 /* do never respond on first call */
56 *ptr = &aptr; 56 *ptr = &aptr;
57 return MHD_YES; 57 return MHD_YES;
58 } 58 }
59 *ptr = NULL; /* reset when done */ 59 *ptr = NULL; /* reset when done */
60 response = MHD_create_response_from_data (strlen (me), 60 response = MHD_create_response_from_data (strlen (me),
61 (void *) me, MHD_NO, MHD_NO); 61 (void *) me, MHD_NO, MHD_NO);
62 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 62 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
diff --git a/src/daemon/postprocessor.c b/src/daemon/postprocessor.c
index 87de25a0..e1fd6d9c 100644
--- a/src/daemon/postprocessor.c
+++ b/src/daemon/postprocessor.c
@@ -130,7 +130,7 @@ struct MHD_PostProcessor
130 130
131/** 131/**
132 * Create a PostProcessor. 132 * Create a PostProcessor.
133 * 133 *
134 * A PostProcessor can be used to (incrementally) 134 * A PostProcessor can be used to (incrementally)
135 * parse the data portion of a POST request. 135 * parse the data portion of a POST request.
136 * 136 *
@@ -260,7 +260,7 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
260 else if ((delta > 1) && (xbuf[delta - 2] == '%')) 260 else if ((delta > 1) && (xbuf[delta - 2] == '%'))
261 delta -= 2; 261 delta -= 2;
262 262
263 /* if we have an incomplete escape sequence, save it to 263 /* if we have an incomplete escape sequence, save it to
264 pp->xbuf for later */ 264 pp->xbuf for later */
265 if (delta < xoff) 265 if (delta < xoff)
266 { 266 {
@@ -332,14 +332,14 @@ try_match_header (const char *prefix, char *line, char **suffix)
332} 332}
333 333
334/** 334/**
335 * Decode multipart POST data. 335 * Decode multipart POST data.
336 * 336 *
337 * TODO: If the content-type is multipart/mixed, we do not do anything 337 * TODO: If the content-type is multipart/mixed, we do not do anything
338 * special. However, we should probably break the individual values 338 * special. However, we should probably break the individual values
339 * apart and give them to the callback individually (will require some 339 * apart and give them to the callback individually (will require some
340 * additional states & state). 340 * additional states & state).
341 * 341 *
342 * See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4 342 * See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
343 */ 343 */
344static int 344static int
345post_process_multipart (struct MHD_PostProcessor *pp, 345post_process_multipart (struct MHD_PostProcessor *pp,
@@ -507,7 +507,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
507 newline++; 507 newline++;
508 if (newline + blen + 4 > pp->buffer_size) 508 if (newline + blen + 4 > pp->buffer_size)
509 { 509 {
510 /* boundary not in sight -- 510 /* boundary not in sight --
511 process data, then make room for more! */ 511 process data, then make room for more! */
512 if (MHD_NO == pp->ikvi (pp->cls, 512 if (MHD_NO == pp->ikvi (pp->cls,
513 MHD_POSTDATA_KIND, 513 MHD_POSTDATA_KIND,
@@ -622,9 +622,9 @@ END:
622 * Parse and process POST data. 622 * Parse and process POST data.
623 * Call this function when POST data is available 623 * Call this function when POST data is available
624 * (usually during an MHD_AccessHandlerCallback) 624 * (usually during an MHD_AccessHandlerCallback)
625 * with the upload_data and upload_data_size. 625 * with the upload_data and upload_data_size.
626 * Whenever possible, this will then cause calls 626 * Whenever possible, this will then cause calls
627 * to the MHD_IncrementalKeyValueIterator. 627 * to the MHD_IncrementalKeyValueIterator.
628 * 628 *
629 * @param pp the post processor 629 * @param pp the post processor
630 * @param post_data post_data_len bytes of POST data 630 * @param post_data post_data_len bytes of POST data
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 2197d9d9..b8dfc426 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -39,10 +39,10 @@
39 * The library also understands headers that control connection 39 * The library also understands headers that control connection
40 * management (specifically, "Connection: close" and "Expect: 100 40 * management (specifically, "Connection: close" and "Expect: 100
41 * continue" are understood and handled automatically).<p> 41 * continue" are understood and handled automatically).<p>
42 * 42 *
43 * MHD understands POST data and is able to decode certain formats 43 * MHD understands POST data and is able to decode certain formats
44 * (at the moment only "application/x-www-form-urlencoded") if the 44 * (at the moment only "application/x-www-form-urlencoded") if the
45 * entire data fits into the allowed amount of memory for the 45 * entire data fits into the allowed amount of memory for the
46 * connection. Unsupported encodings and large POST submissions are 46 * connection. Unsupported encodings and large POST submissions are
47 * provided as a stream to the main application (and thus can be 47 * provided as a stream to the main application (and thus can be
48 * processed, just not conveniently by MHD).<p> 48 * processed, just not conveniently by MHD).<p>
@@ -325,7 +325,7 @@ enum MHD_OPTION
325 * up). Requests that have never been presented to the application 325 * up). Requests that have never been presented to the application
326 * (via MHD_AccessHandlerCallback) will not result in 326 * (via MHD_AccessHandlerCallback) will not result in
327 * notifications.<p> 327 * notifications.<p>
328 * 328 *
329 * This option should be followed by TWO pointers. First a pointer 329 * This option should be followed by TWO pointers. First a pointer
330 * to a function of type "MHD_RequestCompletedCallback" and second a 330 * to a function of type "MHD_RequestCompletedCallback" and second a
331 * pointer to a closure to pass to the request completed callback. 331 * pointer to a closure to pass to the request completed callback.
@@ -407,7 +407,7 @@ enum MHD_RequestTerminationCode
407 MHD_REQUEST_TERMINATED_TIMEOUT_REACHED = 2, 407 MHD_REQUEST_TERMINATED_TIMEOUT_REACHED = 2,
408 408
409 /** 409 /**
410 * We had to close the session since MHD was being 410 * We had to close the session since MHD was being
411 * shut down. 411 * shut down.
412 */ 412 */
413 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN = 3, 413 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN = 3,
@@ -497,13 +497,13 @@ typedef int
497 497
498/** 498/**
499 * Signature of the callback used by MHD to notify the 499 * Signature of the callback used by MHD to notify the
500 * application about completed requests. 500 * application about completed requests.
501 * 501 *
502 * @param cls client-defined closure 502 * @param cls client-defined closure
503 * @param connection connection handle 503 * @param connection connection handle
504 * @param con_cls value as set by the last call to 504 * @param con_cls value as set by the last call to
505 * the MHD_AccessHandlerCallback 505 * the MHD_AccessHandlerCallback
506 * @param toe reason for request termination 506 * @param toe reason for request termination
507 * @see MHD_OPTION_NOTIFY_COMPLETED 507 * @see MHD_OPTION_NOTIFY_COMPLETED
508 */ 508 */
509typedef void 509typedef void
@@ -551,10 +551,10 @@ typedef int
551 * obtained from the content reader so far. 551 * obtained from the content reader so far.
552 * @return -1 for the end of transmission (or on error); 552 * @return -1 for the end of transmission (or on error);
553 * if a content transfer size was pre-set and the callback 553 * if a content transfer size was pre-set and the callback
554 * has provided fewer than that amount of data, 554 * has provided fewer than that amount of data,
555 * MHD will close the connection with the client; 555 * MHD will close the connection with the client;
556 * if no content size was specified and this is an 556 * if no content size was specified and this is an
557 * http 1.1 connection using chunked encoding, MHD will 557 * http 1.1 connection using chunked encoding, MHD will
558 * interpret "-1" as the normal end of the transfer 558 * interpret "-1" as the normal end of the transfer
559 * (possibly allowing the client to perform additional 559 * (possibly allowing the client to perform additional
560 * requests using the same TCP connection). 560 * requests using the same TCP connection).
@@ -585,7 +585,7 @@ typedef void (*MHD_ContentReaderFreeCallback) (void *cls);
585 * @param data pointer to size bytes of data at the 585 * @param data pointer to size bytes of data at the
586 * specified offset 586 * specified offset
587 * @param off offset of data in the overall value 587 * @param off offset of data in the overall value
588 * @param size number of bytes in data available 588 * @param size number of bytes in data available
589 * @return MHD_YES to continue iterating, 589 * @return MHD_YES to continue iterating,
590 * MHD_NO to abort the iteration 590 * MHD_NO to abort the iteration
591 */ 591 */
@@ -796,7 +796,7 @@ const char *MHD_get_response_header (struct MHD_Response *response,
796 796
797/** 797/**
798 * Create a PostProcessor. 798 * Create a PostProcessor.
799 * 799 *
800 * A PostProcessor can be used to (incrementally) 800 * A PostProcessor can be used to (incrementally)
801 * parse the data portion of a POST request. 801 * parse the data portion of a POST request.
802 * 802 *
@@ -823,9 +823,9 @@ struct MHD_PostProcessor *MHD_create_post_processor (struct MHD_Connection
823 * Parse and process POST data. 823 * Parse and process POST data.
824 * Call this function when POST data is available 824 * Call this function when POST data is available
825 * (usually during an MHD_AccessHandlerCallback) 825 * (usually during an MHD_AccessHandlerCallback)
826 * with the upload_data and upload_data_size. 826 * with the upload_data and upload_data_size.
827 * Whenever possible, this will then cause calls 827 * Whenever possible, this will then cause calls
828 * to the MHD_IncrementalKeyValueIterator. 828 * to the MHD_IncrementalKeyValueIterator.
829 * 829 *
830 * @param pp the post processor 830 * @param pp the post processor
831 * @param post_data post_data_len bytes of POST data 831 * @param post_data post_data_len bytes of POST data