diff options
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index e198b6cd..a99cbd2a 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -262,7 +262,7 @@ MHD_connection_close (struct MHD_Connection *connection, | |||
262 | 262 | ||
263 | daemon = connection->daemon; | 263 | daemon = connection->daemon; |
264 | if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) | 264 | if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) |
265 | SHUTDOWN (connection->socket_fd, | 265 | shutdown (connection->socket_fd, |
266 | (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR); | 266 | (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR); |
267 | connection->state = MHD_CONNECTION_CLOSED; | 267 | connection->state = MHD_CONNECTION_CLOSED; |
268 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; | 268 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; |
@@ -566,7 +566,7 @@ add_extra_headers (struct MHD_Connection *connection) | |||
566 | Note that the change from 'SHOULD NOT' to 'MUST NOT' is | 566 | Note that the change from 'SHOULD NOT' to 'MUST NOT' is |
567 | a recent development of the HTTP 1.1 specification. | 567 | a recent development of the HTTP 1.1 specification. |
568 | */ | 568 | */ |
569 | SPRINTF (buf, | 569 | sprintf (buf, |
570 | MHD_UNSIGNED_LONG_LONG_PRINTF, | 570 | MHD_UNSIGNED_LONG_LONG_PRINTF, |
571 | (MHD_UNSIGNED_LONG_LONG) connection->response->total_size); | 571 | (MHD_UNSIGNED_LONG_LONG) connection->response->total_size); |
572 | MHD_add_response_header (connection->response, | 572 | MHD_add_response_header (connection->response, |
@@ -598,15 +598,19 @@ get_date_string (char *date) | |||
598 | time_t t; | 598 | time_t t; |
599 | 599 | ||
600 | time (&t); | 600 | time (&t); |
601 | #ifndef WINDOWS | ||
601 | gmtime_r (&t, &now); | 602 | gmtime_r (&t, &now); |
602 | SPRINTF (date, | 603 | #else |
604 | gmtime_s (&now, &t); | ||
605 | #endif | ||
606 | sprintf (date, | ||
603 | "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n", | 607 | "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n", |
604 | days[now.tm_wday % 7], | 608 | days[now.tm_wday % 7], |
605 | (unsigned int) now.tm_mday, | 609 | (unsigned int) now.tm_mday, |
606 | mons[now.tm_mon % 12], | 610 | mons[now.tm_mon % 12], |
607 | (unsigned int) (1900 + now.tm_year), | 611 | (unsigned int) (1900 + now.tm_year), |
608 | (unsigned int) now.tm_hour, | 612 | (unsigned int) now.tm_hour, |
609 | (unsigned int) now.tm_min, | 613 | (unsigned int) now.tm_min, |
610 | (unsigned int) now.tm_sec); | 614 | (unsigned int) now.tm_sec); |
611 | } | 615 | } |
612 | 616 | ||
@@ -681,21 +685,21 @@ build_header_response (struct MHD_Connection *connection) | |||
681 | add_extra_headers (connection); | 685 | add_extra_headers (connection); |
682 | rc = connection->responseCode & (~MHD_ICY_FLAG); | 686 | rc = connection->responseCode & (~MHD_ICY_FLAG); |
683 | reason_phrase = MHD_get_reason_phrase_for (rc); | 687 | reason_phrase = MHD_get_reason_phrase_for (rc); |
684 | SPRINTF (code, | 688 | sprintf (code, |
685 | "%s %u %s\r\n", | 689 | "%s %u %s\r\n", |
686 | (0 != (connection->responseCode & MHD_ICY_FLAG)) | 690 | (0 != (connection->responseCode & MHD_ICY_FLAG)) |
687 | ? "ICY" | 691 | ? "ICY" |
688 | : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0, | 692 | : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0, |
689 | connection->version)) | 693 | connection->version)) |
690 | ? MHD_HTTP_VERSION_1_0 | 694 | ? MHD_HTTP_VERSION_1_0 |
691 | : MHD_HTTP_VERSION_1_1), | 695 | : MHD_HTTP_VERSION_1_1), |
692 | rc, | 696 | rc, |
693 | reason_phrase); | 697 | reason_phrase); |
694 | off = strlen (code); | 698 | off = strlen (code); |
695 | /* estimate size */ | 699 | /* estimate size */ |
696 | size = off + 2; /* extra \r\n at the end */ | 700 | size = off + 2; /* extra \r\n at the end */ |
697 | kind = MHD_HEADER_KIND; | 701 | kind = MHD_HEADER_KIND; |
698 | if ( (0 == (connection->daemon->options & MHD_SUPPRESS_DATE_NO_CLOCK)) && | 702 | if ( (0 == (connection->daemon->options & MHD_SUPPRESS_DATE_NO_CLOCK)) && |
699 | (NULL == MHD_get_response_header (connection->response, | 703 | (NULL == MHD_get_response_header (connection->response, |
700 | MHD_HTTP_HEADER_DATE)) ) | 704 | MHD_HTTP_HEADER_DATE)) ) |
701 | get_date_string (date); | 705 | get_date_string (date); |
@@ -745,9 +749,9 @@ build_header_response (struct MHD_Connection *connection) | |||
745 | } | 749 | } |
746 | for (pos = connection->response->first_header; NULL != pos; pos = pos->next) | 750 | for (pos = connection->response->first_header; NULL != pos; pos = pos->next) |
747 | if (pos->kind == kind) | 751 | if (pos->kind == kind) |
748 | off += SPRINTF (&data[off], | 752 | off += sprintf (&data[off], |
749 | "%s: %s\r\n", | 753 | "%s: %s\r\n", |
750 | pos->header, | 754 | pos->header, |
751 | pos->value); | 755 | pos->value); |
752 | if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED) | 756 | if (connection->state == MHD_CONNECTION_FOOTERS_RECEIVED) |
753 | { | 757 | { |
@@ -1507,9 +1511,9 @@ do_read (struct MHD_Connection *connection) | |||
1507 | "Failed to receive data: %s\n", | 1511 | "Failed to receive data: %s\n", |
1508 | gnutls_strerror (bytes_read)); | 1512 | gnutls_strerror (bytes_read)); |
1509 | else | 1513 | else |
1510 | #endif | 1514 | #endif |
1511 | MHD_DLOG (connection->daemon, | 1515 | MHD_DLOG (connection->daemon, |
1512 | "Failed to receive data: %s\n", STRERROR (errno)); | 1516 | "Failed to receive data: %s\n", strerror (errno)); |
1513 | #endif | 1517 | #endif |
1514 | CONNECTION_CLOSE_ERROR (connection, NULL); | 1518 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1515 | return MHD_YES; | 1519 | return MHD_YES; |
@@ -1520,7 +1524,7 @@ do_read (struct MHD_Connection *connection) | |||
1520 | connection->read_closed = MHD_YES; | 1524 | connection->read_closed = MHD_YES; |
1521 | /* shutdown is not required here, as the other side already | 1525 | /* shutdown is not required here, as the other side already |
1522 | knows; so flagging this internally should suffice */ | 1526 | knows; so flagging this internally should suffice */ |
1523 | /* SHUTDOWN (connection->socket_fd, SHUT_RD); */ | 1527 | /* shutdown (connection->socket_fd, SHUT_RD); */ |
1524 | return MHD_YES; | 1528 | return MHD_YES; |
1525 | } | 1529 | } |
1526 | connection->read_buffer_offset += bytes_read; | 1530 | connection->read_buffer_offset += bytes_read; |
@@ -1556,9 +1560,9 @@ do_write (struct MHD_Connection *connection) | |||
1556 | "Failed to send data: %s\n", | 1560 | "Failed to send data: %s\n", |
1557 | gnutls_strerror (ret)); | 1561 | gnutls_strerror (ret)); |
1558 | else | 1562 | else |
1559 | #endif | 1563 | #endif |
1560 | MHD_DLOG (connection->daemon, | 1564 | MHD_DLOG (connection->daemon, |
1561 | "Failed to send data: %s\n", STRERROR (errno)); | 1565 | "Failed to send data: %s\n", strerror (errno)); |
1562 | #endif | 1566 | #endif |
1563 | CONNECTION_CLOSE_ERROR (connection, NULL); | 1567 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1564 | return MHD_YES; | 1568 | return MHD_YES; |
@@ -1914,7 +1918,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1914 | break; | 1918 | break; |
1915 | #if HAVE_MESSAGES | 1919 | #if HAVE_MESSAGES |
1916 | MHD_DLOG (connection->daemon, | 1920 | MHD_DLOG (connection->daemon, |
1917 | "Failed to send data: %s\n", STRERROR (errno)); | 1921 | "Failed to send data: %s\n", strerror (errno)); |
1918 | #endif | 1922 | #endif |
1919 | CONNECTION_CLOSE_ERROR (connection, NULL); | 1923 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1920 | return MHD_YES; | 1924 | return MHD_YES; |
@@ -1976,7 +1980,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1976 | return MHD_YES; | 1980 | return MHD_YES; |
1977 | #if HAVE_MESSAGES | 1981 | #if HAVE_MESSAGES |
1978 | MHD_DLOG (connection->daemon, | 1982 | MHD_DLOG (connection->daemon, |
1979 | "Failed to send data: %s\n", STRERROR (errno)); | 1983 | "Failed to send data: %s\n", strerror (errno)); |
1980 | #endif | 1984 | #endif |
1981 | CONNECTION_CLOSE_ERROR (connection, NULL); | 1985 | CONNECTION_CLOSE_ERROR (connection, NULL); |
1982 | return MHD_YES; | 1986 | return MHD_YES; |
@@ -2527,7 +2531,7 @@ MHD_connection_epoll_update_ (struct MHD_Connection *connection) | |||
2527 | if (0 != (daemon->options & MHD_USE_DEBUG)) | 2531 | if (0 != (daemon->options & MHD_USE_DEBUG)) |
2528 | MHD_DLOG (daemon, | 2532 | MHD_DLOG (daemon, |
2529 | "Call to epoll_ctl failed: %s\n", | 2533 | "Call to epoll_ctl failed: %s\n", |
2530 | STRERROR (errno)); | 2534 | strerror (errno)); |
2531 | #endif | 2535 | #endif |
2532 | connection->state = MHD_CONNECTION_CLOSED; | 2536 | connection->state = MHD_CONNECTION_CLOSED; |
2533 | cleanup_connection (connection); | 2537 | cleanup_connection (connection); |
@@ -2686,7 +2690,7 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
2686 | refuse to read body / footers or further | 2690 | refuse to read body / footers or further |
2687 | requests! */ | 2691 | requests! */ |
2688 | if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) | 2692 | if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) |
2689 | (void) SHUTDOWN (connection->socket_fd, SHUT_RD); | 2693 | (void) shutdown (connection->socket_fd, SHUT_RD); |
2690 | connection->read_closed = MHD_YES; | 2694 | connection->read_closed = MHD_YES; |
2691 | connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; | 2695 | connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; |
2692 | } | 2696 | } |