diff options
author | Christian Grothoff <christian@grothoff.org> | 2007-09-09 21:32:12 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2007-09-09 21:32:12 +0000 |
commit | fb36fb2009a35e48be28df422af5a4b42d099cda (patch) | |
tree | 103c9372286a794293b36bcc0e18e091bde49f3d /src/daemon/connection.c | |
parent | 8ce09efc5e3c19d413727e8b80c5f2eff9406b38 (diff) | |
download | libmicrohttpd-fb36fb2009a35e48be28df422af5a4b42d099cda.tar.gz libmicrohttpd-fb36fb2009a35e48be28df422af5a4b42d099cda.zip |
release
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 48f93dfd..01163154 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -221,9 +221,11 @@ ready_response (struct MHD_Connection *connection) | |||
221 | if (ret == -1) | 221 | if (ret == -1) |
222 | { | 222 | { |
223 | /* end of message, signal other side by closing! */ | 223 | /* end of message, signal other side by closing! */ |
224 | #if DEBUG_CLOSE | 224 | #if DEBUG_CLOSE |
225 | #if HAVE_MESSAGES | ||
225 | MHD_DLOG (connection->daemon, "Closing connection (end of response)\n"); | 226 | MHD_DLOG (connection->daemon, "Closing connection (end of response)\n"); |
226 | #endif | 227 | #endif |
228 | #endif | ||
227 | response->total_size = connection->messagePos; | 229 | response->total_size = connection->messagePos; |
228 | connection_close_error (connection); | 230 | connection_close_error (connection); |
229 | return MHD_NO; | 231 | return MHD_NO; |
@@ -335,8 +337,10 @@ MHD_excessive_data_handler (struct MHD_Connection *connection, | |||
335 | connection->read_close = MHD_YES; | 337 | connection->read_close = MHD_YES; |
336 | connection->headersReceived = MHD_YES; | 338 | connection->headersReceived = MHD_YES; |
337 | connection->bodyReceived = MHD_YES; | 339 | connection->bodyReceived = MHD_YES; |
340 | #if HAVE_MESSAGES | ||
338 | MHD_DLOG (connection->daemon, | 341 | MHD_DLOG (connection->daemon, |
339 | "Received excessively long header, closing connection.\n"); | 342 | "Received excessively long header, closing connection.\n"); |
343 | #endif | ||
340 | response = MHD_create_response_from_data (strlen (REQUEST_TOO_BIG), | 344 | response = MHD_create_response_from_data (strlen (REQUEST_TOO_BIG), |
341 | REQUEST_TOO_BIG, MHD_NO, MHD_NO); | 345 | REQUEST_TOO_BIG, MHD_NO, MHD_NO); |
342 | MHD_queue_response (connection, status_code, response); | 346 | MHD_queue_response (connection, status_code, response); |
@@ -413,8 +417,10 @@ MHD_connection_add_header (struct MHD_Connection *connection, | |||
413 | sizeof (struct MHD_HTTP_Header), MHD_YES); | 417 | sizeof (struct MHD_HTTP_Header), MHD_YES); |
414 | if (hdr == NULL) | 418 | if (hdr == NULL) |
415 | { | 419 | { |
420 | #if HAVE_MESSAGES | ||
416 | MHD_DLOG (connection->daemon, | 421 | MHD_DLOG (connection->daemon, |
417 | "Not enough memory to allocate header record!\n"); | 422 | "Not enough memory to allocate header record!\n"); |
423 | #endif | ||
418 | MHD_excessive_data_handler (connection, | 424 | MHD_excessive_data_handler (connection, |
419 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); | 425 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); |
420 | return MHD_NO; | 426 | return MHD_NO; |
@@ -481,7 +487,9 @@ MHD_parse_cookie_header (struct MHD_Connection *connection) | |||
481 | cpy = MHD_pool_allocate (connection->pool, strlen (hdr) + 1, MHD_YES); | 487 | cpy = MHD_pool_allocate (connection->pool, strlen (hdr) + 1, MHD_YES); |
482 | if (cpy == NULL) | 488 | if (cpy == NULL) |
483 | { | 489 | { |
490 | #if HAVE_MESSAGES | ||
484 | MHD_DLOG (connection->daemon, "Not enough memory to parse cookies!\n"); | 491 | MHD_DLOG (connection->daemon, "Not enough memory to parse cookies!\n"); |
492 | #endif | ||
485 | MHD_excessive_data_handler (connection, | 493 | MHD_excessive_data_handler (connection, |
486 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); | 494 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); |
487 | return MHD_NO; | 495 | return MHD_NO; |
@@ -649,9 +657,11 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
649 | { | 657 | { |
650 | if (1 != sscanf (clen, "%llu", &cval)) | 658 | if (1 != sscanf (clen, "%llu", &cval)) |
651 | { | 659 | { |
660 | #if HAVE_MESSAGES | ||
652 | MHD_DLOG (connection->daemon, | 661 | MHD_DLOG (connection->daemon, |
653 | "Failed to parse `%s' header `%s', closing connection.\n", | 662 | "Failed to parse `%s' header `%s', closing connection.\n", |
654 | MHD_HTTP_HEADER_CONTENT_LENGTH, clen); | 663 | MHD_HTTP_HEADER_CONTENT_LENGTH, clen); |
664 | #endif | ||
655 | goto DIE; | 665 | goto DIE; |
656 | } | 666 | } |
657 | connection->uploadSize = cval; | 667 | connection->uploadSize = cval; |
@@ -694,9 +704,11 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
694 | /* die, http 1.1 request without host and we are pedantic */ | 704 | /* die, http 1.1 request without host and we are pedantic */ |
695 | connection->bodyReceived = MHD_YES; | 705 | connection->bodyReceived = MHD_YES; |
696 | connection->read_close = MHD_YES; | 706 | connection->read_close = MHD_YES; |
707 | #if HAVE_MESSAGES | ||
697 | MHD_DLOG (connection->daemon, | 708 | MHD_DLOG (connection->daemon, |
698 | "Received `%s' request without `%s' header.\n", | 709 | "Received `%s' request without `%s' header.\n", |
699 | MHD_HTTP_VERSION_1_1, MHD_HTTP_HEADER_HOST); | 710 | MHD_HTTP_VERSION_1_1, MHD_HTTP_HEADER_HOST); |
711 | #endif | ||
700 | response = | 712 | response = |
701 | MHD_create_response_from_data (strlen (REQUEST_LACKS_HOST), | 713 | MHD_create_response_from_data (strlen (REQUEST_LACKS_HOST), |
702 | REQUEST_LACKS_HOST, MHD_NO, | 714 | REQUEST_LACKS_HOST, MHD_NO, |
@@ -712,8 +724,10 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
712 | if (colon == NULL) | 724 | if (colon == NULL) |
713 | { | 725 | { |
714 | /* error in header line, die hard */ | 726 | /* error in header line, die hard */ |
727 | #if HAVE_MESSAGES | ||
715 | MHD_DLOG (connection->daemon, | 728 | MHD_DLOG (connection->daemon, |
716 | "Received malformed line (no colon), closing connection.\n"); | 729 | "Received malformed line (no colon), closing connection.\n"); |
730 | #endif | ||
717 | goto DIE; | 731 | goto DIE; |
718 | } | 732 | } |
719 | /* zero-terminate header */ | 733 | /* zero-terminate header */ |
@@ -735,8 +749,10 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
735 | MHD_parse_cookie_header (connection); | 749 | MHD_parse_cookie_header (connection); |
736 | return; | 750 | return; |
737 | DIE: | 751 | DIE: |
752 | #if HAVE_MESSAGES | ||
738 | MHD_DLOG (connection->daemon, | 753 | MHD_DLOG (connection->daemon, |
739 | "Closing connection (problem parsing headers)\n"); | 754 | "Closing connection (problem parsing headers)\n"); |
755 | #endif | ||
740 | connection_close_error (connection); | 756 | connection_close_error (connection); |
741 | } | 757 | } |
742 | 758 | ||
@@ -785,8 +801,10 @@ MHD_call_connection_handler (struct MHD_Connection *connection) | |||
785 | &connection->client_context)) | 801 | &connection->client_context)) |
786 | { | 802 | { |
787 | /* serios internal error, close connection */ | 803 | /* serios internal error, close connection */ |
804 | #if HAVE_MESSAGES | ||
788 | MHD_DLOG (connection->daemon, | 805 | MHD_DLOG (connection->daemon, |
789 | "Internal application error, closing connection.\n"); | 806 | "Internal application error, closing connection.\n"); |
807 | #endif | ||
790 | connection_close_error (connection); | 808 | connection_close_error (connection); |
791 | return; | 809 | return; |
792 | } | 810 | } |
@@ -831,7 +849,9 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
831 | connection->pool = MHD_pool_create (connection->daemon->pool_size); | 849 | connection->pool = MHD_pool_create (connection->daemon->pool_size); |
832 | if (connection->pool == NULL) | 850 | if (connection->pool == NULL) |
833 | { | 851 | { |
852 | #if HAVE_MESSAGES | ||
834 | MHD_DLOG (connection->daemon, "Failed to create memory pool!\n"); | 853 | MHD_DLOG (connection->daemon, "Failed to create memory pool!\n"); |
854 | #endif | ||
835 | connection_close_error (connection); | 855 | connection_close_error (connection); |
836 | return MHD_NO; | 856 | return MHD_NO; |
837 | } | 857 | } |
@@ -846,8 +866,10 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
846 | MHD_BUF_INC_SIZE + 1); | 866 | MHD_BUF_INC_SIZE + 1); |
847 | if (tmp == NULL) | 867 | if (tmp == NULL) |
848 | { | 868 | { |
869 | #if HAVE_MESSAGES | ||
849 | MHD_DLOG (connection->daemon, | 870 | MHD_DLOG (connection->daemon, |
850 | "Not enough memory for reading headers!\n"); | 871 | "Not enough memory for reading headers!\n"); |
872 | #endif | ||
851 | MHD_excessive_data_handler (connection, | 873 | MHD_excessive_data_handler (connection, |
852 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); | 874 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); |
853 | return MHD_NO; | 875 | return MHD_NO; |
@@ -858,7 +880,9 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
858 | } | 880 | } |
859 | if (connection->readLoc >= connection->read_buffer_size) | 881 | if (connection->readLoc >= connection->read_buffer_size) |
860 | { | 882 | { |
883 | #if HAVE_MESSAGES | ||
861 | MHD_DLOG (connection->daemon, "Unexpected call to %s.\n", __FUNCTION__); | 884 | MHD_DLOG (connection->daemon, "Unexpected call to %s.\n", __FUNCTION__); |
885 | #endif | ||
862 | return MHD_NO; | 886 | return MHD_NO; |
863 | } | 887 | } |
864 | bytes_read = RECV (connection->socket_fd, | 888 | bytes_read = RECV (connection->socket_fd, |
@@ -868,8 +892,10 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
868 | { | 892 | { |
869 | if (errno == EINTR) | 893 | if (errno == EINTR) |
870 | return MHD_NO; | 894 | return MHD_NO; |
895 | #if HAVE_MESSAGES | ||
871 | MHD_DLOG (connection->daemon, | 896 | MHD_DLOG (connection->daemon, |
872 | "Failed to receive data: %s\n", STRERROR (errno)); | 897 | "Failed to receive data: %s\n", STRERROR (errno)); |
898 | #endif | ||
873 | connection_close_error (connection); | 899 | connection_close_error (connection); |
874 | return MHD_YES; | 900 | return MHD_YES; |
875 | } | 901 | } |
@@ -880,9 +906,11 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
880 | if ((connection->headersReceived == 1) && (connection->readLoc > 0)) | 906 | if ((connection->headersReceived == 1) && (connection->readLoc > 0)) |
881 | MHD_call_connection_handler (connection); | 907 | MHD_call_connection_handler (connection); |
882 | #if DEBUG_CLOSE | 908 | #if DEBUG_CLOSE |
909 | #if HAVE_MESSAGES | ||
883 | MHD_DLOG (connection->daemon, | 910 | MHD_DLOG (connection->daemon, |
884 | "Shutting down connection for reading (other side closed connection)\n"); | 911 | "Shutting down connection for reading (other side closed connection)\n"); |
885 | #endif | 912 | #endif |
913 | #endif | ||
886 | shutdown (connection->socket_fd, SHUT_RD); | 914 | shutdown (connection->socket_fd, SHUT_RD); |
887 | return MHD_YES; | 915 | return MHD_YES; |
888 | } | 916 | } |
@@ -983,7 +1011,9 @@ MHD_build_header_response (struct MHD_Connection *connection) | |||
983 | data = MHD_pool_allocate (connection->pool, size + 1, MHD_YES); | 1011 | data = MHD_pool_allocate (connection->pool, size + 1, MHD_YES); |
984 | if (data == NULL) | 1012 | if (data == NULL) |
985 | { | 1013 | { |
1014 | #if HAVE_MESSAGES | ||
986 | MHD_DLOG (connection->daemon, "Not enough memory for write!\n"); | 1015 | MHD_DLOG (connection->daemon, "Not enough memory for write!\n"); |
1016 | #endif | ||
987 | return MHD_NO; | 1017 | return MHD_NO; |
988 | } | 1018 | } |
989 | memcpy (data, code, off); | 1019 | memcpy (data, code, off); |
@@ -1028,8 +1058,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1028 | { | 1058 | { |
1029 | if (errno == EINTR) | 1059 | if (errno == EINTR) |
1030 | return MHD_YES; | 1060 | return MHD_YES; |
1061 | #if HAVE_MESSAGES | ||
1031 | MHD_DLOG (connection->daemon, | 1062 | MHD_DLOG (connection->daemon, |
1032 | "Failed to send data: %s\n", STRERROR (errno)); | 1063 | "Failed to send data: %s\n", STRERROR (errno)); |
1064 | #endif | ||
1033 | connection_close_error (connection); | 1065 | connection_close_error (connection); |
1034 | return MHD_YES; | 1066 | return MHD_YES; |
1035 | } | 1067 | } |
@@ -1044,7 +1076,9 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1044 | response = connection->response; | 1076 | response = connection->response; |
1045 | if (response == NULL) | 1077 | if (response == NULL) |
1046 | { | 1078 | { |
1079 | #if HAVE_MESSAGES | ||
1047 | MHD_DLOG (connection->daemon, "Unexpected call to %s.\n", __FUNCTION__); | 1080 | MHD_DLOG (connection->daemon, "Unexpected call to %s.\n", __FUNCTION__); |
1081 | #endif | ||
1048 | return MHD_NO; | 1082 | return MHD_NO; |
1049 | } | 1083 | } |
1050 | if (!connection->headersSent) | 1084 | if (!connection->headersSent) |
@@ -1053,8 +1087,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1053 | (MHD_NO == MHD_build_header_response (connection))) | 1087 | (MHD_NO == MHD_build_header_response (connection))) |
1054 | { | 1088 | { |
1055 | /* oops - close! */ | 1089 | /* oops - close! */ |
1090 | #if HAVE_MESSAGES | ||
1056 | MHD_DLOG (connection->daemon, | 1091 | MHD_DLOG (connection->daemon, |
1057 | "Closing connection (failed to create response header)\n"); | 1092 | "Closing connection (failed to create response header)\n"); |
1093 | #endif | ||
1058 | connection_close_error (connection); | 1094 | connection_close_error (connection); |
1059 | return MHD_NO; | 1095 | return MHD_NO; |
1060 | } | 1096 | } |
@@ -1065,8 +1101,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1065 | { | 1101 | { |
1066 | if (errno == EINTR) | 1102 | if (errno == EINTR) |
1067 | return MHD_YES; | 1103 | return MHD_YES; |
1104 | #if HAVE_MESSAGES | ||
1068 | MHD_DLOG (connection->daemon, | 1105 | MHD_DLOG (connection->daemon, |
1069 | "Failed to send data: %s\n", STRERROR (errno)); | 1106 | "Failed to send data: %s\n", STRERROR (errno)); |
1107 | #endif | ||
1070 | connection_close_error (connection); | 1108 | connection_close_error (connection); |
1071 | return MHD_YES; | 1109 | return MHD_YES; |
1072 | } | 1110 | } |
@@ -1114,8 +1152,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1114 | { | 1152 | { |
1115 | if (errno == EINTR) | 1153 | if (errno == EINTR) |
1116 | return MHD_YES; | 1154 | return MHD_YES; |
1155 | #if HAVE_MESSAGES | ||
1117 | MHD_DLOG (connection->daemon, | 1156 | MHD_DLOG (connection->daemon, |
1118 | "Failed to send data: %s\n", STRERROR (errno)); | 1157 | "Failed to send data: %s\n", STRERROR (errno)); |
1158 | #endif | ||
1119 | connection_close_error (connection); | 1159 | connection_close_error (connection); |
1120 | return MHD_YES; | 1160 | return MHD_YES; |
1121 | } | 1161 | } |
@@ -1158,9 +1198,11 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1158 | if (connection->socket_fd != -1) | 1198 | if (connection->socket_fd != -1) |
1159 | { | 1199 | { |
1160 | #if DEBUG_CLOSE | 1200 | #if DEBUG_CLOSE |
1201 | #if HAVE_MESSAGES | ||
1161 | MHD_DLOG (connection->daemon, | 1202 | MHD_DLOG (connection->daemon, |
1162 | "Closing connection (http 1.0 or end-of-stream for unknown content length)\n"); | 1203 | "Closing connection (http 1.0 or end-of-stream for unknown content length)\n"); |
1163 | #endif | 1204 | #endif |
1205 | #endif | ||
1164 | SHUTDOWN (connection->socket_fd, SHUT_RDWR); | 1206 | SHUTDOWN (connection->socket_fd, SHUT_RDWR); |
1165 | CLOSE (connection->socket_fd); | 1207 | CLOSE (connection->socket_fd); |
1166 | } | 1208 | } |