diff options
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/Makefile.am | 8 | ||||
-rw-r--r-- | src/daemon/connection.c | 44 | ||||
-rw-r--r-- | src/daemon/daemon.c | 41 | ||||
-rw-r--r-- | src/daemon/internal.c | 3 | ||||
-rw-r--r-- | src/daemon/internal.h | 2 | ||||
-rw-r--r-- | src/daemon/memorypool.c | 2 |
6 files changed, 95 insertions, 5 deletions
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index 7a4696fc..c9b73287 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am | |||
@@ -2,11 +2,17 @@ SUBDIRS = . | |||
2 | 2 | ||
3 | INCLUDES = -I$(top_srcdir)/src/include | 3 | INCLUDES = -I$(top_srcdir)/src/include |
4 | 4 | ||
5 | if HAVE_GNU_LD | ||
6 | retaincommand=-Wl,--retain-symbols-file -Wl,SYMBOLS | ||
7 | endif | ||
8 | |||
9 | EXTRA_DIST = SYMBOLS | ||
10 | |||
5 | lib_LTLIBRARIES = \ | 11 | lib_LTLIBRARIES = \ |
6 | libmicrohttpd.la | 12 | libmicrohttpd.la |
7 | 13 | ||
8 | libmicrohttpd_la_LDFLAGS = \ | 14 | libmicrohttpd_la_LDFLAGS = \ |
9 | -export-dynamic -version-info 2:0:0 | 15 | -export-dynamic -version-info 2:0:0 $(retaincommand) |
10 | libmicrohttpd_la_SOURCES = \ | 16 | libmicrohttpd_la_SOURCES = \ |
11 | connection.c connection.h \ | 17 | connection.c connection.h \ |
12 | daemon.c \ | 18 | daemon.c \ |
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 | } |
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 02cdfe21..d35be3a6 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -72,7 +72,9 @@ MHD_register_handler (struct MHD_Daemon *daemon, | |||
72 | ah = malloc (sizeof (struct MHD_Access_Handler)); | 72 | ah = malloc (sizeof (struct MHD_Access_Handler)); |
73 | if (ah == NULL) | 73 | if (ah == NULL) |
74 | { | 74 | { |
75 | #if HAVE_MESSAGES | ||
75 | MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); | 76 | MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); |
77 | #endif | ||
76 | return MHD_NO; | 78 | return MHD_NO; |
77 | } | 79 | } |
78 | 80 | ||
@@ -204,8 +206,10 @@ MHD_handle_connection (void *data) | |||
204 | { | 206 | { |
205 | if (errno == EINTR) | 207 | if (errno == EINTR) |
206 | continue; | 208 | continue; |
209 | #if HAVE_MESSAGES | ||
207 | MHD_DLOG (con->daemon, "Error during select (%d): `%s'\n", | 210 | MHD_DLOG (con->daemon, "Error during select (%d): `%s'\n", |
208 | max, STRERROR (errno)); | 211 | max, STRERROR (errno)); |
212 | #endif | ||
209 | break; | 213 | break; |
210 | } | 214 | } |
211 | if (((FD_ISSET (con->socket_fd, &rs)) && | 215 | if (((FD_ISSET (con->socket_fd, &rs)) && |
@@ -224,9 +228,11 @@ MHD_handle_connection (void *data) | |||
224 | if (con->socket_fd != -1) | 228 | if (con->socket_fd != -1) |
225 | { | 229 | { |
226 | #if DEBUG_CLOSE | 230 | #if DEBUG_CLOSE |
231 | #if HAVE_MESSAGES | ||
227 | MHD_DLOG (con->daemon, | 232 | MHD_DLOG (con->daemon, |
228 | "Processing thread terminating, closing connection\n"); | 233 | "Processing thread terminating, closing connection\n"); |
229 | #endif | 234 | #endif |
235 | #endif | ||
230 | SHUTDOWN (con->socket_fd, SHUT_RDWR); | 236 | SHUTDOWN (con->socket_fd, SHUT_RDWR); |
231 | CLOSE (con->socket_fd); | 237 | CLOSE (con->socket_fd); |
232 | con->socket_fd = -1; | 238 | con->socket_fd = -1; |
@@ -257,7 +263,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
257 | s = ACCEPT (daemon->socket_fd, addr, &addrlen); | 263 | s = ACCEPT (daemon->socket_fd, addr, &addrlen); |
258 | if ((s < 0) || (addrlen <= 0)) | 264 | if ((s < 0) || (addrlen <= 0)) |
259 | { | 265 | { |
266 | #if HAVE_MESSAGES | ||
260 | MHD_DLOG (daemon, "Error accepting connection: %s\n", STRERROR (errno)); | 267 | MHD_DLOG (daemon, "Error accepting connection: %s\n", STRERROR (errno)); |
268 | #endif | ||
261 | if (s != -1) | 269 | if (s != -1) |
262 | { | 270 | { |
263 | SHUTDOWN (s, SHUT_RDWR); | 271 | SHUTDOWN (s, SHUT_RDWR); |
@@ -268,8 +276,10 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
268 | if (daemon->max_connections == 0) | 276 | if (daemon->max_connections == 0) |
269 | { | 277 | { |
270 | /* above connection limit - reject */ | 278 | /* above connection limit - reject */ |
279 | #if HAVE_MESSAGES | ||
271 | MHD_DLOG (daemon, | 280 | MHD_DLOG (daemon, |
272 | "Server reached connection limit (closing inbound connection)\n"); | 281 | "Server reached connection limit (closing inbound connection)\n"); |
282 | #endif | ||
273 | SHUTDOWN (s, SHUT_RDWR); | 283 | SHUTDOWN (s, SHUT_RDWR); |
274 | CLOSE (s); | 284 | CLOSE (s); |
275 | return MHD_NO; | 285 | return MHD_NO; |
@@ -278,8 +288,10 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
278 | (MHD_NO == daemon->apc (daemon->apc_cls, addr, addrlen))) | 288 | (MHD_NO == daemon->apc (daemon->apc_cls, addr, addrlen))) |
279 | { | 289 | { |
280 | #if DEBUG_CLOSE | 290 | #if DEBUG_CLOSE |
291 | #if HAVE_MESSAGES | ||
281 | MHD_DLOG (daemon, "Connection rejected, closing connection\n"); | 292 | MHD_DLOG (daemon, "Connection rejected, closing connection\n"); |
282 | #endif | 293 | #endif |
294 | #endif | ||
283 | SHUTDOWN (s, SHUT_RDWR); | 295 | SHUTDOWN (s, SHUT_RDWR); |
284 | CLOSE (s); | 296 | CLOSE (s); |
285 | return MHD_YES; | 297 | return MHD_YES; |
@@ -287,7 +299,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
287 | connection = malloc (sizeof (struct MHD_Connection)); | 299 | connection = malloc (sizeof (struct MHD_Connection)); |
288 | if (connection == NULL) | 300 | if (connection == NULL) |
289 | { | 301 | { |
302 | #if HAVE_MESSAGES | ||
290 | MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); | 303 | MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); |
304 | #endif | ||
291 | SHUTDOWN (s, SHUT_RDWR); | 305 | SHUTDOWN (s, SHUT_RDWR); |
292 | CLOSE (s); | 306 | CLOSE (s); |
293 | return MHD_NO; | 307 | return MHD_NO; |
@@ -297,7 +311,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
297 | connection->addr = malloc (addrlen); | 311 | connection->addr = malloc (addrlen); |
298 | if (connection->addr == NULL) | 312 | if (connection->addr == NULL) |
299 | { | 313 | { |
314 | #if HAVE_MESSAGES | ||
300 | MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); | 315 | MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); |
316 | #endif | ||
301 | SHUTDOWN (s, SHUT_RDWR); | 317 | SHUTDOWN (s, SHUT_RDWR); |
302 | CLOSE (s); | 318 | CLOSE (s); |
303 | free (connection); | 319 | free (connection); |
@@ -311,7 +327,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
311 | (0 != pthread_create (&connection->pid, | 327 | (0 != pthread_create (&connection->pid, |
312 | NULL, &MHD_handle_connection, connection))) | 328 | NULL, &MHD_handle_connection, connection))) |
313 | { | 329 | { |
330 | #if HAVE_MESSAGES | ||
314 | MHD_DLOG (daemon, "Failed to create a thread: %s\n", STRERROR (errno)); | 331 | MHD_DLOG (daemon, "Failed to create a thread: %s\n", STRERROR (errno)); |
332 | #endif | ||
315 | SHUTDOWN (s, SHUT_RDWR); | 333 | SHUTDOWN (s, SHUT_RDWR); |
316 | CLOSE (s); | 334 | CLOSE (s); |
317 | free (connection->addr); | 335 | free (connection->addr); |
@@ -356,8 +374,10 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
356 | if ((pos->last_activity < timeout) && (pos->socket_fd != -1)) | 374 | if ((pos->last_activity < timeout) && (pos->socket_fd != -1)) |
357 | { | 375 | { |
358 | #if DEBUG_CLOSE | 376 | #if DEBUG_CLOSE |
377 | #if HAVE_MESSAGES | ||
359 | MHD_DLOG (daemon, "Connection timed out, closing connection\n"); | 378 | MHD_DLOG (daemon, "Connection timed out, closing connection\n"); |
360 | #endif | 379 | #endif |
380 | #endif | ||
361 | SHUTDOWN (pos->socket_fd, SHUT_RDWR); | 381 | SHUTDOWN (pos->socket_fd, SHUT_RDWR); |
362 | CLOSE (pos->socket_fd); | 382 | CLOSE (pos->socket_fd); |
363 | pos->socket_fd = -1; | 383 | pos->socket_fd = -1; |
@@ -508,7 +528,9 @@ MHD_select (struct MHD_Daemon *daemon, int may_block) | |||
508 | { | 528 | { |
509 | if (errno == EINTR) | 529 | if (errno == EINTR) |
510 | return MHD_YES; | 530 | return MHD_YES; |
531 | #if HAVE_MESSAGES | ||
511 | MHD_DLOG (daemon, "Select failed: %s\n", STRERROR (errno)); | 532 | MHD_DLOG (daemon, "Select failed: %s\n", STRERROR (errno)); |
533 | #endif | ||
512 | return MHD_NO; | 534 | return MHD_NO; |
513 | } | 535 | } |
514 | ds = daemon->socket_fd; | 536 | ds = daemon->socket_fd; |
@@ -622,15 +644,20 @@ MHD_start_daemon (unsigned int options, | |||
622 | socket_fd = SOCKET (PF_INET, SOCK_STREAM, 0); | 644 | socket_fd = SOCKET (PF_INET, SOCK_STREAM, 0); |
623 | if (socket_fd < 0) | 645 | if (socket_fd < 0) |
624 | { | 646 | { |
647 | #if HAVE_MESSAGES | ||
625 | if ((options & MHD_USE_DEBUG) != 0) | 648 | if ((options & MHD_USE_DEBUG) != 0) |
626 | fprintf (stderr, "Call to socket failed: %s\n", STRERROR (errno)); | 649 | fprintf (stderr, "Call to socket failed: %s\n", STRERROR (errno)); |
650 | #endif | ||
627 | return NULL; | 651 | return NULL; |
628 | } | 652 | } |
629 | if ((SETSOCKOPT (socket_fd, | 653 | if ((SETSOCKOPT (socket_fd, |
630 | SOL_SOCKET, | 654 | SOL_SOCKET, |
631 | SO_REUSEADDR, | 655 | SO_REUSEADDR, |
632 | &on, sizeof (on)) < 0) && (options & MHD_USE_DEBUG) != 0) | 656 | &on, sizeof (on)) < 0) && (options & MHD_USE_DEBUG) != 0) { |
657 | #if HAVE_MESSAGES | ||
633 | fprintf (stderr, "setsockopt failed: %s\n", STRERROR (errno)); | 658 | fprintf (stderr, "setsockopt failed: %s\n", STRERROR (errno)); |
659 | #endif | ||
660 | } | ||
634 | if ((options & MHD_USE_IPv6) != 0) | 661 | if ((options & MHD_USE_IPv6) != 0) |
635 | { | 662 | { |
636 | memset (&servaddr6, 0, sizeof (struct sockaddr_in6)); | 663 | memset (&servaddr6, 0, sizeof (struct sockaddr_in6)); |
@@ -649,17 +676,21 @@ MHD_start_daemon (unsigned int options, | |||
649 | } | 676 | } |
650 | if (BIND (socket_fd, servaddr, addrlen) < 0) | 677 | if (BIND (socket_fd, servaddr, addrlen) < 0) |
651 | { | 678 | { |
679 | #if HAVE_MESSAGES | ||
652 | if ((options & MHD_USE_DEBUG) != 0) | 680 | if ((options & MHD_USE_DEBUG) != 0) |
653 | fprintf (stderr, | 681 | fprintf (stderr, |
654 | "Failed to bind to port %u: %s\n", port, STRERROR (errno)); | 682 | "Failed to bind to port %u: %s\n", port, STRERROR (errno)); |
683 | #endif | ||
655 | CLOSE (socket_fd); | 684 | CLOSE (socket_fd); |
656 | return NULL; | 685 | return NULL; |
657 | } | 686 | } |
658 | if (LISTEN (socket_fd, 20) < 0) | 687 | if (LISTEN (socket_fd, 20) < 0) |
659 | { | 688 | { |
689 | #if HAVE_MESSAGES | ||
660 | if ((options & MHD_USE_DEBUG) != 0) | 690 | if ((options & MHD_USE_DEBUG) != 0) |
661 | fprintf (stderr, | 691 | fprintf (stderr, |
662 | "Failed to listen for connections: %s\n", STRERROR (errno)); | 692 | "Failed to listen for connections: %s\n", STRERROR (errno)); |
693 | #endif | ||
663 | CLOSE (socket_fd); | 694 | CLOSE (socket_fd); |
664 | return NULL; | 695 | return NULL; |
665 | } | 696 | } |
@@ -697,8 +728,10 @@ MHD_start_daemon (unsigned int options, | |||
697 | retVal->notify_completed_cls = va_arg (ap, void *); | 728 | retVal->notify_completed_cls = va_arg (ap, void *); |
698 | break; | 729 | break; |
699 | default: | 730 | default: |
731 | #if HAVE_MESSAGES | ||
700 | fprintf (stderr, | 732 | fprintf (stderr, |
701 | "Invalid MHD_OPTION argument! (Did you terminate the list with MHD_OPTION_END?)\n"); | 733 | "Invalid MHD_OPTION argument! (Did you terminate the list with MHD_OPTION_END?)\n"); |
734 | #endif | ||
702 | abort (); | 735 | abort (); |
703 | } | 736 | } |
704 | } | 737 | } |
@@ -707,8 +740,10 @@ MHD_start_daemon (unsigned int options, | |||
707 | (0 != (options & MHD_USE_SELECT_INTERNALLY))) && | 740 | (0 != (options & MHD_USE_SELECT_INTERNALLY))) && |
708 | (0 != pthread_create (&retVal->pid, NULL, &MHD_select_thread, retVal))) | 741 | (0 != pthread_create (&retVal->pid, NULL, &MHD_select_thread, retVal))) |
709 | { | 742 | { |
743 | #if HAVE_MESSAGES | ||
710 | MHD_DLOG (retVal, | 744 | MHD_DLOG (retVal, |
711 | "Failed to create listen thread: %s\n", STRERROR (errno)); | 745 | "Failed to create listen thread: %s\n", STRERROR (errno)); |
746 | #endif | ||
712 | free (retVal); | 747 | free (retVal); |
713 | CLOSE (socket_fd); | 748 | CLOSE (socket_fd); |
714 | return NULL; | 749 | return NULL; |
@@ -731,8 +766,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
731 | fd = daemon->socket_fd; | 766 | fd = daemon->socket_fd; |
732 | daemon->socket_fd = -1; | 767 | daemon->socket_fd = -1; |
733 | #if DEBUG_CLOSE | 768 | #if DEBUG_CLOSE |
769 | #if HAVE_MESSAGES | ||
734 | MHD_DLOG (daemon, "MHD shutdown, closing listen socket\n"); | 770 | MHD_DLOG (daemon, "MHD shutdown, closing listen socket\n"); |
735 | #endif | 771 | #endif |
772 | #endif | ||
736 | CLOSE (fd); | 773 | CLOSE (fd); |
737 | if ((0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || | 774 | if ((0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || |
738 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY))) | 775 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY))) |
@@ -745,8 +782,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
745 | if (-1 != daemon->connections->socket_fd) | 782 | if (-1 != daemon->connections->socket_fd) |
746 | { | 783 | { |
747 | #if DEBUG_CLOSE | 784 | #if DEBUG_CLOSE |
785 | #if HAVE_MESSAGES | ||
748 | MHD_DLOG (daemon, "MHD shutdown, closing active connections\n"); | 786 | MHD_DLOG (daemon, "MHD shutdown, closing active connections\n"); |
749 | #endif | 787 | #endif |
788 | #endif | ||
750 | if (daemon->notify_completed != NULL) | 789 | if (daemon->notify_completed != NULL) |
751 | daemon->notify_completed (daemon->notify_completed_cls, | 790 | daemon->notify_completed (daemon->notify_completed_cls, |
752 | daemon->connections, | 791 | daemon->connections, |
diff --git a/src/daemon/internal.c b/src/daemon/internal.c index 85c17b16..433d4886 100644 --- a/src/daemon/internal.c +++ b/src/daemon/internal.c | |||
@@ -26,7 +26,7 @@ | |||
26 | 26 | ||
27 | #include "internal.h" | 27 | #include "internal.h" |
28 | 28 | ||
29 | 29 | #if HAVE_MESSAGES | |
30 | /** | 30 | /** |
31 | * fprintf-like helper function for logging debug | 31 | * fprintf-like helper function for logging debug |
32 | * messages. | 32 | * messages. |
@@ -42,6 +42,7 @@ MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...) | |||
42 | VFPRINTF (stderr, format, va); | 42 | VFPRINTF (stderr, format, va); |
43 | va_end (va); | 43 | va_end (va); |
44 | } | 44 | } |
45 | #endif | ||
45 | 46 | ||
46 | /** | 47 | /** |
47 | * Process escape sequences ('+'=space, %HH) | 48 | * Process escape sequences ('+'=space, %HH) |
diff --git a/src/daemon/internal.h b/src/daemon/internal.h index 3f3f91b0..1596e8df 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h | |||
@@ -59,11 +59,13 @@ | |||
59 | */ | 59 | */ |
60 | #define MHD_BUF_INC_SIZE 2048 | 60 | #define MHD_BUF_INC_SIZE 2048 |
61 | 61 | ||
62 | #if HAVE_MESSAGES | ||
62 | /** | 63 | /** |
63 | * fprintf-like helper function for logging debug | 64 | * fprintf-like helper function for logging debug |
64 | * messages. | 65 | * messages. |
65 | */ | 66 | */ |
66 | void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...); | 67 | void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...); |
68 | #endif | ||
67 | 69 | ||
68 | /** | 70 | /** |
69 | * Process escape sequences ('+'=space, %HH). | 71 | * Process escape sequences ('+'=space, %HH). |
diff --git a/src/daemon/memorypool.c b/src/daemon/memorypool.c index 4a183bcb..1721fcfe 100644 --- a/src/daemon/memorypool.c +++ b/src/daemon/memorypool.c | |||
@@ -25,7 +25,7 @@ | |||
25 | 25 | ||
26 | #include "memorypool.h" | 26 | #include "memorypool.h" |
27 | 27 | ||
28 | // define MAP_ANONYMOUS for Mac OS X | 28 | /* define MAP_ANONYMOUS for Mac OS X */ |
29 | #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) | 29 | #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) |
30 | #define MAP_ANONYMOUS MAP_ANON | 30 | #define MAP_ANONYMOUS MAP_ANON |
31 | #endif | 31 | #endif |