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