From fb36fb2009a35e48be28df422af5a4b42d099cda Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 9 Sep 2007 21:32:12 +0000 Subject: release --- src/daemon/Makefile.am | 8 +++++++- src/daemon/connection.c | 44 +++++++++++++++++++++++++++++++++++++++++++- src/daemon/daemon.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/daemon/internal.c | 3 ++- src/daemon/internal.h | 2 ++ src/daemon/memorypool.c | 2 +- 6 files changed, 95 insertions(+), 5 deletions(-) (limited to 'src') 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 = . INCLUDES = -I$(top_srcdir)/src/include +if HAVE_GNU_LD + retaincommand=-Wl,--retain-symbols-file -Wl,SYMBOLS +endif + +EXTRA_DIST = SYMBOLS + lib_LTLIBRARIES = \ libmicrohttpd.la libmicrohttpd_la_LDFLAGS = \ - -export-dynamic -version-info 2:0:0 + -export-dynamic -version-info 2:0:0 $(retaincommand) libmicrohttpd_la_SOURCES = \ connection.c connection.h \ 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,8 +221,10 @@ ready_response (struct MHD_Connection *connection) if (ret == -1) { /* end of message, signal other side by closing! */ -#if DEBUG_CLOSE +#if DEBUG_CLOSE +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Closing connection (end of response)\n"); +#endif #endif response->total_size = connection->messagePos; connection_close_error (connection); @@ -335,8 +337,10 @@ MHD_excessive_data_handler (struct MHD_Connection *connection, connection->read_close = MHD_YES; connection->headersReceived = MHD_YES; connection->bodyReceived = MHD_YES; +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Received excessively long header, closing connection.\n"); +#endif response = MHD_create_response_from_data (strlen (REQUEST_TOO_BIG), REQUEST_TOO_BIG, MHD_NO, MHD_NO); MHD_queue_response (connection, status_code, response); @@ -413,8 +417,10 @@ MHD_connection_add_header (struct MHD_Connection *connection, sizeof (struct MHD_HTTP_Header), MHD_YES); if (hdr == NULL) { +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Not enough memory to allocate header record!\n"); +#endif MHD_excessive_data_handler (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); return MHD_NO; @@ -481,7 +487,9 @@ MHD_parse_cookie_header (struct MHD_Connection *connection) cpy = MHD_pool_allocate (connection->pool, strlen (hdr) + 1, MHD_YES); if (cpy == NULL) { +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Not enough memory to parse cookies!\n"); +#endif MHD_excessive_data_handler (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); return MHD_NO; @@ -649,9 +657,11 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) { if (1 != sscanf (clen, "%llu", &cval)) { +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Failed to parse `%s' header `%s', closing connection.\n", MHD_HTTP_HEADER_CONTENT_LENGTH, clen); +#endif goto DIE; } connection->uploadSize = cval; @@ -694,9 +704,11 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) /* die, http 1.1 request without host and we are pedantic */ connection->bodyReceived = MHD_YES; connection->read_close = MHD_YES; +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Received `%s' request without `%s' header.\n", MHD_HTTP_VERSION_1_1, MHD_HTTP_HEADER_HOST); +#endif response = MHD_create_response_from_data (strlen (REQUEST_LACKS_HOST), REQUEST_LACKS_HOST, MHD_NO, @@ -712,8 +724,10 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) if (colon == NULL) { /* error in header line, die hard */ +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Received malformed line (no colon), closing connection.\n"); +#endif goto DIE; } /* zero-terminate header */ @@ -735,8 +749,10 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) MHD_parse_cookie_header (connection); return; DIE: +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Closing connection (problem parsing headers)\n"); +#endif connection_close_error (connection); } @@ -785,8 +801,10 @@ MHD_call_connection_handler (struct MHD_Connection *connection) &connection->client_context)) { /* serios internal error, close connection */ +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Internal application error, closing connection.\n"); +#endif connection_close_error (connection); return; } @@ -831,7 +849,9 @@ MHD_connection_handle_read (struct MHD_Connection *connection) connection->pool = MHD_pool_create (connection->daemon->pool_size); if (connection->pool == NULL) { +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Failed to create memory pool!\n"); +#endif connection_close_error (connection); return MHD_NO; } @@ -846,8 +866,10 @@ MHD_connection_handle_read (struct MHD_Connection *connection) MHD_BUF_INC_SIZE + 1); if (tmp == NULL) { +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Not enough memory for reading headers!\n"); +#endif MHD_excessive_data_handler (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE); return MHD_NO; @@ -858,7 +880,9 @@ MHD_connection_handle_read (struct MHD_Connection *connection) } if (connection->readLoc >= connection->read_buffer_size) { +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Unexpected call to %s.\n", __FUNCTION__); +#endif return MHD_NO; } bytes_read = RECV (connection->socket_fd, @@ -868,8 +892,10 @@ MHD_connection_handle_read (struct MHD_Connection *connection) { if (errno == EINTR) return MHD_NO; +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Failed to receive data: %s\n", STRERROR (errno)); +#endif connection_close_error (connection); return MHD_YES; } @@ -880,8 +906,10 @@ MHD_connection_handle_read (struct MHD_Connection *connection) if ((connection->headersReceived == 1) && (connection->readLoc > 0)) MHD_call_connection_handler (connection); #if DEBUG_CLOSE +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Shutting down connection for reading (other side closed connection)\n"); +#endif #endif shutdown (connection->socket_fd, SHUT_RD); return MHD_YES; @@ -983,7 +1011,9 @@ MHD_build_header_response (struct MHD_Connection *connection) data = MHD_pool_allocate (connection->pool, size + 1, MHD_YES); if (data == NULL) { +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Not enough memory for write!\n"); +#endif return MHD_NO; } memcpy (data, code, off); @@ -1028,8 +1058,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) { if (errno == EINTR) return MHD_YES; +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Failed to send data: %s\n", STRERROR (errno)); +#endif connection_close_error (connection); return MHD_YES; } @@ -1044,7 +1076,9 @@ MHD_connection_handle_write (struct MHD_Connection *connection) response = connection->response; if (response == NULL) { +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Unexpected call to %s.\n", __FUNCTION__); +#endif return MHD_NO; } if (!connection->headersSent) @@ -1053,8 +1087,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) (MHD_NO == MHD_build_header_response (connection))) { /* oops - close! */ +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Closing connection (failed to create response header)\n"); +#endif connection_close_error (connection); return MHD_NO; } @@ -1065,8 +1101,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) { if (errno == EINTR) return MHD_YES; +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Failed to send data: %s\n", STRERROR (errno)); +#endif connection_close_error (connection); return MHD_YES; } @@ -1114,8 +1152,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) { if (errno == EINTR) return MHD_YES; +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Failed to send data: %s\n", STRERROR (errno)); +#endif connection_close_error (connection); return MHD_YES; } @@ -1158,8 +1198,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) if (connection->socket_fd != -1) { #if DEBUG_CLOSE +#if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Closing connection (http 1.0 or end-of-stream for unknown content length)\n"); +#endif #endif SHUTDOWN (connection->socket_fd, SHUT_RDWR); CLOSE (connection->socket_fd); 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, ah = malloc (sizeof (struct MHD_Access_Handler)); if (ah == NULL) { +#if HAVE_MESSAGES MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); +#endif return MHD_NO; } @@ -204,8 +206,10 @@ MHD_handle_connection (void *data) { if (errno == EINTR) continue; +#if HAVE_MESSAGES MHD_DLOG (con->daemon, "Error during select (%d): `%s'\n", max, STRERROR (errno)); +#endif break; } if (((FD_ISSET (con->socket_fd, &rs)) && @@ -224,8 +228,10 @@ MHD_handle_connection (void *data) if (con->socket_fd != -1) { #if DEBUG_CLOSE +#if HAVE_MESSAGES MHD_DLOG (con->daemon, "Processing thread terminating, closing connection\n"); +#endif #endif SHUTDOWN (con->socket_fd, SHUT_RDWR); CLOSE (con->socket_fd); @@ -257,7 +263,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) s = ACCEPT (daemon->socket_fd, addr, &addrlen); if ((s < 0) || (addrlen <= 0)) { +#if HAVE_MESSAGES MHD_DLOG (daemon, "Error accepting connection: %s\n", STRERROR (errno)); +#endif if (s != -1) { SHUTDOWN (s, SHUT_RDWR); @@ -268,8 +276,10 @@ MHD_accept_connection (struct MHD_Daemon *daemon) if (daemon->max_connections == 0) { /* above connection limit - reject */ +#if HAVE_MESSAGES MHD_DLOG (daemon, "Server reached connection limit (closing inbound connection)\n"); +#endif SHUTDOWN (s, SHUT_RDWR); CLOSE (s); return MHD_NO; @@ -278,7 +288,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) (MHD_NO == daemon->apc (daemon->apc_cls, addr, addrlen))) { #if DEBUG_CLOSE +#if HAVE_MESSAGES MHD_DLOG (daemon, "Connection rejected, closing connection\n"); +#endif #endif SHUTDOWN (s, SHUT_RDWR); CLOSE (s); @@ -287,7 +299,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) connection = malloc (sizeof (struct MHD_Connection)); if (connection == NULL) { +#if HAVE_MESSAGES MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); +#endif SHUTDOWN (s, SHUT_RDWR); CLOSE (s); return MHD_NO; @@ -297,7 +311,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) connection->addr = malloc (addrlen); if (connection->addr == NULL) { +#if HAVE_MESSAGES MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); +#endif SHUTDOWN (s, SHUT_RDWR); CLOSE (s); free (connection); @@ -311,7 +327,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon) (0 != pthread_create (&connection->pid, NULL, &MHD_handle_connection, connection))) { +#if HAVE_MESSAGES MHD_DLOG (daemon, "Failed to create a thread: %s\n", STRERROR (errno)); +#endif SHUTDOWN (s, SHUT_RDWR); CLOSE (s); free (connection->addr); @@ -356,7 +374,9 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) if ((pos->last_activity < timeout) && (pos->socket_fd != -1)) { #if DEBUG_CLOSE +#if HAVE_MESSAGES MHD_DLOG (daemon, "Connection timed out, closing connection\n"); +#endif #endif SHUTDOWN (pos->socket_fd, SHUT_RDWR); CLOSE (pos->socket_fd); @@ -508,7 +528,9 @@ MHD_select (struct MHD_Daemon *daemon, int may_block) { if (errno == EINTR) return MHD_YES; +#if HAVE_MESSAGES MHD_DLOG (daemon, "Select failed: %s\n", STRERROR (errno)); +#endif return MHD_NO; } ds = daemon->socket_fd; @@ -622,15 +644,20 @@ MHD_start_daemon (unsigned int options, socket_fd = SOCKET (PF_INET, SOCK_STREAM, 0); if (socket_fd < 0) { +#if HAVE_MESSAGES if ((options & MHD_USE_DEBUG) != 0) fprintf (stderr, "Call to socket failed: %s\n", STRERROR (errno)); +#endif return NULL; } if ((SETSOCKOPT (socket_fd, SOL_SOCKET, SO_REUSEADDR, - &on, sizeof (on)) < 0) && (options & MHD_USE_DEBUG) != 0) + &on, sizeof (on)) < 0) && (options & MHD_USE_DEBUG) != 0) { +#if HAVE_MESSAGES fprintf (stderr, "setsockopt failed: %s\n", STRERROR (errno)); +#endif + } if ((options & MHD_USE_IPv6) != 0) { memset (&servaddr6, 0, sizeof (struct sockaddr_in6)); @@ -649,17 +676,21 @@ MHD_start_daemon (unsigned int options, } if (BIND (socket_fd, servaddr, addrlen) < 0) { +#if HAVE_MESSAGES if ((options & MHD_USE_DEBUG) != 0) fprintf (stderr, "Failed to bind to port %u: %s\n", port, STRERROR (errno)); +#endif CLOSE (socket_fd); return NULL; } if (LISTEN (socket_fd, 20) < 0) { +#if HAVE_MESSAGES if ((options & MHD_USE_DEBUG) != 0) fprintf (stderr, "Failed to listen for connections: %s\n", STRERROR (errno)); +#endif CLOSE (socket_fd); return NULL; } @@ -697,8 +728,10 @@ MHD_start_daemon (unsigned int options, retVal->notify_completed_cls = va_arg (ap, void *); break; default: +#if HAVE_MESSAGES fprintf (stderr, "Invalid MHD_OPTION argument! (Did you terminate the list with MHD_OPTION_END?)\n"); +#endif abort (); } } @@ -707,8 +740,10 @@ MHD_start_daemon (unsigned int options, (0 != (options & MHD_USE_SELECT_INTERNALLY))) && (0 != pthread_create (&retVal->pid, NULL, &MHD_select_thread, retVal))) { +#if HAVE_MESSAGES MHD_DLOG (retVal, "Failed to create listen thread: %s\n", STRERROR (errno)); +#endif free (retVal); CLOSE (socket_fd); return NULL; @@ -731,7 +766,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) fd = daemon->socket_fd; daemon->socket_fd = -1; #if DEBUG_CLOSE +#if HAVE_MESSAGES MHD_DLOG (daemon, "MHD shutdown, closing listen socket\n"); +#endif #endif CLOSE (fd); if ((0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || @@ -745,7 +782,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) if (-1 != daemon->connections->socket_fd) { #if DEBUG_CLOSE +#if HAVE_MESSAGES MHD_DLOG (daemon, "MHD shutdown, closing active connections\n"); +#endif #endif if (daemon->notify_completed != NULL) daemon->notify_completed (daemon->notify_completed_cls, 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 @@ #include "internal.h" - +#if HAVE_MESSAGES /** * fprintf-like helper function for logging debug * messages. @@ -42,6 +42,7 @@ MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...) VFPRINTF (stderr, format, va); va_end (va); } +#endif /** * 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 @@ */ #define MHD_BUF_INC_SIZE 2048 +#if HAVE_MESSAGES /** * fprintf-like helper function for logging debug * messages. */ void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...); +#endif /** * 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 @@ #include "memorypool.h" -// define MAP_ANONYMOUS for Mac OS X +/* define MAP_ANONYMOUS for Mac OS X */ #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) #define MAP_ANONYMOUS MAP_ANON #endif -- cgit v1.2.3