diff options
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/EXPORT.sym | 1 | ||||
-rw-r--r-- | src/daemon/connection.c | 14 | ||||
-rw-r--r-- | src/daemon/daemon.c | 58 | ||||
-rw-r--r-- | src/daemon/internal.h | 7 | ||||
-rw-r--r-- | src/daemon/postprocessor.c | 8 |
5 files changed, 62 insertions, 26 deletions
diff --git a/src/daemon/EXPORT.sym b/src/daemon/EXPORT.sym index 9d776799..b57c5233 100644 --- a/src/daemon/EXPORT.sym +++ b/src/daemon/EXPORT.sym | |||
@@ -20,3 +20,4 @@ MHD_post_process | |||
20 | MHD_destroy_post_processor | 20 | MHD_destroy_post_processor |
21 | MHD_get_daemon_info | 21 | MHD_get_daemon_info |
22 | MHD_get_connection_info | 22 | MHD_get_connection_info |
23 | MHD_set_panic_func | ||
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 4871f41f..0532cc13 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -296,7 +296,7 @@ MHD_connection_close (struct MHD_Connection *connection, | |||
296 | connection->daemon->notify_completed (connection->daemon-> | 296 | connection->daemon->notify_completed (connection->daemon-> |
297 | notify_completed_cls, connection, | 297 | notify_completed_cls, connection, |
298 | &connection->client_context, | 298 | &connection->client_context, |
299 | termination_code); | 299 | termination_code); |
300 | connection->client_aware = MHD_NO; | 300 | connection->client_aware = MHD_NO; |
301 | } | 301 | } |
302 | 302 | ||
@@ -341,7 +341,7 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
341 | connection->response_write_position)); | 341 | connection->response_write_position)); |
342 | if ((ret == 0) && | 342 | if ((ret == 0) && |
343 | (0 != (connection->daemon->options & MHD_USE_SELECT_INTERNALLY))) | 343 | (0 != (connection->daemon->options & MHD_USE_SELECT_INTERNALLY))) |
344 | abort (); /* serious client API violation */ | 344 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, "API violation"); |
345 | if (ret == -1) | 345 | if (ret == -1) |
346 | { | 346 | { |
347 | /* either error or http 1.0 transfer, close | 347 | /* either error or http 1.0 transfer, close |
@@ -494,7 +494,7 @@ add_extra_headers (struct MHD_Connection *connection) | |||
494 | MHD_HTTP_HEADER_CONTENT_LENGTH)) | 494 | MHD_HTTP_HEADER_CONTENT_LENGTH)) |
495 | { | 495 | { |
496 | SPRINTF (buf, | 496 | SPRINTF (buf, |
497 | "%llu", | 497 | "%llu", |
498 | (unsigned long long)connection->response->total_size); | 498 | (unsigned long long)connection->response->total_size); |
499 | MHD_add_response_header (connection->response, | 499 | MHD_add_response_header (connection->response, |
500 | MHD_HTTP_HEADER_CONTENT_LENGTH, buf); | 500 | MHD_HTTP_HEADER_CONTENT_LENGTH, buf); |
@@ -630,7 +630,7 @@ build_header_response (struct MHD_Connection *connection) | |||
630 | memcpy (&data[off], "\r\n", 2); | 630 | memcpy (&data[off], "\r\n", 2); |
631 | off += 2; | 631 | off += 2; |
632 | if (off != size) | 632 | if (off != size) |
633 | abort (); | 633 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); |
634 | connection->write_buffer = data; | 634 | connection->write_buffer = data; |
635 | connection->write_buffer_append_offset = size; | 635 | connection->write_buffer_append_offset = size; |
636 | connection->write_buffer_send_offset = 0; | 636 | connection->write_buffer_send_offset = 0; |
@@ -986,8 +986,8 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
986 | char old; | 986 | char old; |
987 | int quotes; | 987 | int quotes; |
988 | 988 | ||
989 | hdr = MHD_lookup_connection_value (connection, | 989 | hdr = MHD_lookup_connection_value (connection, |
990 | MHD_HEADER_KIND, | 990 | MHD_HEADER_KIND, |
991 | MHD_HTTP_HEADER_COOKIE); | 991 | MHD_HTTP_HEADER_COOKIE); |
992 | if (hdr == NULL) | 992 | if (hdr == NULL) |
993 | return MHD_YES; | 993 | return MHD_YES; |
@@ -1259,7 +1259,7 @@ call_connection_handler (struct MHD_Connection *connection) | |||
1259 | return; | 1259 | return; |
1260 | } | 1260 | } |
1261 | if (processed > used) | 1261 | if (processed > used) |
1262 | abort (); /* fatal client API violation! */ | 1262 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, "API violation"); |
1263 | if (processed != 0) | 1263 | if (processed != 0) |
1264 | instant_retry = MHD_NO; /* client did not process everything */ | 1264 | instant_retry = MHD_NO; /* client did not process everything */ |
1265 | used -= processed; | 1265 | used -= processed; |
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 6559bde8..8eb32f29 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -76,6 +76,20 @@ static void pthread_kill (int, int) { | |||
76 | #endif // __SYMBIAN32__ | 76 | #endif // __SYMBIAN32__ |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Default implementation of the panic function | ||
80 | */ | ||
81 | void mhd_panic_std(void *cls, | ||
82 | const char *file, | ||
83 | unsigned int line, | ||
84 | const char *reason) | ||
85 | { | ||
86 | abort (); | ||
87 | } | ||
88 | |||
89 | MHD_PanicCallback mhd_panic; | ||
90 | void *mhd_panic_cls; | ||
91 | |||
92 | /** | ||
79 | * Trace up to and return master daemon. If the supplied daemon | 93 | * Trace up to and return master daemon. If the supplied daemon |
80 | * is a master, then return the daemon itself. | 94 | * is a master, then return the daemon itself. |
81 | */ | 95 | */ |
@@ -465,7 +479,7 @@ MHD_handle_connection (void *data) | |||
465 | unsigned int now; | 479 | unsigned int now; |
466 | 480 | ||
467 | if (con == NULL) | 481 | if (con == NULL) |
468 | abort (); | 482 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); |
469 | timeout = con->daemon->connection_timeout; | 483 | timeout = con->daemon->connection_timeout; |
470 | while ((!con->daemon->shutdown) && (con->socket_fd != -1)) | 484 | while ((!con->daemon->shutdown) && (con->socket_fd != -1)) |
471 | { | 485 | { |
@@ -486,7 +500,7 @@ MHD_handle_connection (void *data) | |||
486 | { | 500 | { |
487 | /* do not block (we're waiting for our callback to succeed) */ | 501 | /* do not block (we're waiting for our callback to succeed) */ |
488 | tv.tv_sec = 0; | 502 | tv.tv_sec = 0; |
489 | } | 503 | } |
490 | } | 504 | } |
491 | else | 505 | else |
492 | { | 506 | { |
@@ -586,7 +600,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
586 | 600 | ||
587 | #if HAVE_INET6 | 601 | #if HAVE_INET6 |
588 | if (sizeof (struct sockaddr) > sizeof (struct sockaddr_in6)) | 602 | if (sizeof (struct sockaddr) > sizeof (struct sockaddr_in6)) |
589 | abort (); /* fatal, serious error */ | 603 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); /* fatal, serious error */ |
590 | #endif | 604 | #endif |
591 | addrlen = sizeof (addrstorage); | 605 | addrlen = sizeof (addrstorage); |
592 | memset (addr, 0, sizeof (addrstorage)); | 606 | memset (addr, 0, sizeof (addrstorage)); |
@@ -615,7 +629,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
615 | "Socket descriptor larger than FD_SETSIZE: %d > %d\n", | 629 | "Socket descriptor larger than FD_SETSIZE: %d > %d\n", |
616 | s, | 630 | s, |
617 | FD_SETSIZE); | 631 | FD_SETSIZE); |
618 | #endif | 632 | #endif |
619 | CLOSE (s); | 633 | CLOSE (s); |
620 | return MHD_NO; | 634 | return MHD_NO; |
621 | } | 635 | } |
@@ -720,7 +734,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
720 | "Failed to setup TLS credentials: unknown credential type %d\n", | 734 | "Failed to setup TLS credentials: unknown credential type %d\n", |
721 | connection->daemon->cred_type); | 735 | connection->daemon->cred_type); |
722 | #endif | 736 | #endif |
723 | abort (); | 737 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, "Unknown credential type"); |
724 | } | 738 | } |
725 | MHD__gnutls_transport_set_ptr (connection->tls_session, | 739 | MHD__gnutls_transport_set_ptr (connection->tls_session, |
726 | (MHD_gnutls_transport_ptr_t) connection); | 740 | (MHD_gnutls_transport_ptr_t) connection); |
@@ -792,7 +806,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
792 | MHD_DLOG (daemon, "Failed to join a thread: %s\n", | 806 | MHD_DLOG (daemon, "Failed to join a thread: %s\n", |
793 | STRERROR (rc)); | 807 | STRERROR (rc)); |
794 | #endif | 808 | #endif |
795 | abort(); | 809 | abort(); |
796 | } | 810 | } |
797 | } | 811 | } |
798 | MHD_destroy_response (pos->response); | 812 | MHD_destroy_response (pos->response); |
@@ -880,7 +894,7 @@ MHD_select (struct MHD_Daemon *daemon, int may_block) | |||
880 | timeout.tv_sec = 0; | 894 | timeout.tv_sec = 0; |
881 | timeout.tv_usec = 0; | 895 | timeout.tv_usec = 0; |
882 | if (daemon == NULL) | 896 | if (daemon == NULL) |
883 | abort (); | 897 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); |
884 | if (daemon->shutdown == MHD_YES) | 898 | if (daemon->shutdown == MHD_YES) |
885 | return MHD_NO; | 899 | return MHD_NO; |
886 | FD_ZERO (&rs); | 900 | FD_ZERO (&rs); |
@@ -907,11 +921,11 @@ MHD_select (struct MHD_Daemon *daemon, int may_block) | |||
907 | return MHD_NO; | 921 | return MHD_NO; |
908 | FD_SET (max, &rs); | 922 | FD_SET (max, &rs); |
909 | } | 923 | } |
910 | 924 | ||
911 | /* in case we are missing the SIGALRM, keep going after | 925 | /* in case we are missing the SIGALRM, keep going after |
912 | at most 1s; see http://lists.gnu.org/archive/html/libmicrohttpd/2009-10/msg00013.html */ | 926 | at most 1s; see http://lists.gnu.org/archive/html/libmicrohttpd/2009-10/msg00013.html */ |
913 | timeout.tv_usec = 0; | 927 | timeout.tv_usec = 0; |
914 | timeout.tv_sec = 1; | 928 | timeout.tv_sec = 1; |
915 | if (may_block == MHD_NO) | 929 | if (may_block == MHD_NO) |
916 | { | 930 | { |
917 | timeout.tv_usec = 0; | 931 | timeout.tv_usec = 0; |
@@ -1188,7 +1202,7 @@ MHD_start_daemon_va (unsigned int options, | |||
1188 | opt); | 1202 | opt); |
1189 | } | 1203 | } |
1190 | #endif | 1204 | #endif |
1191 | abort (); | 1205 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); |
1192 | } | 1206 | } |
1193 | } | 1207 | } |
1194 | 1208 | ||
@@ -1228,7 +1242,7 @@ MHD_start_daemon_va (unsigned int options, | |||
1228 | } | 1242 | } |
1229 | #endif | 1243 | #endif |
1230 | else | 1244 | else |
1231 | socket_fd = SOCKET (PF_INET, SOCK_STREAM, 0); | 1245 | socket_fd = SOCKET (PF_INET, SOCK_STREAM, 0); |
1232 | if (socket_fd < 0) | 1246 | if (socket_fd < 0) |
1233 | { | 1247 | { |
1234 | #if HAVE_MESSAGES | 1248 | #if HAVE_MESSAGES |
@@ -1247,9 +1261,9 @@ MHD_start_daemon_va (unsigned int options, | |||
1247 | "Socket descriptor larger than FD_SETSIZE: %d > %d\n", | 1261 | "Socket descriptor larger than FD_SETSIZE: %d > %d\n", |
1248 | socket_fd, | 1262 | socket_fd, |
1249 | FD_SETSIZE); | 1263 | FD_SETSIZE); |
1250 | #endif | 1264 | #endif |
1251 | CLOSE (socket_fd); | 1265 | CLOSE (socket_fd); |
1252 | free (retVal); | 1266 | free (retVal); |
1253 | return NULL; | 1267 | return NULL; |
1254 | } | 1268 | } |
1255 | #endif | 1269 | #endif |
@@ -1528,7 +1542,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
1528 | MHD_DLOG (daemon, "Failed to join a thread: %s\n", | 1542 | MHD_DLOG (daemon, "Failed to join a thread: %s\n", |
1529 | STRERROR (rc)); | 1543 | STRERROR (rc)); |
1530 | #endif | 1544 | #endif |
1531 | abort(); | 1545 | abort(); |
1532 | } | 1546 | } |
1533 | MHD_close_connections (&daemon->worker_pool[i]); | 1547 | MHD_close_connections (&daemon->worker_pool[i]); |
1534 | } | 1548 | } |
@@ -1612,6 +1626,17 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon, | |||
1612 | } | 1626 | } |
1613 | 1627 | ||
1614 | /** | 1628 | /** |
1629 | * Sets the global error handler to a different implementation | ||
1630 | * @param cb new error handler | ||
1631 | * @param cls passed to error handler | ||
1632 | */ | ||
1633 | void MHD_set_panic_func (MHD_PanicCallback cb, void *cls) | ||
1634 | { | ||
1635 | mhd_panic = cb; | ||
1636 | mhd_panic_cls = cls; | ||
1637 | } | ||
1638 | |||
1639 | /** | ||
1615 | * Obtain the version of this library | 1640 | * Obtain the version of this library |
1616 | * | 1641 | * |
1617 | * @return static version string, e.g. "0.4.1" | 1642 | * @return static version string, e.g. "0.4.1" |
@@ -1648,6 +1673,9 @@ sigalrmHandler (int sig) | |||
1648 | */ | 1673 | */ |
1649 | void ATTRIBUTE_CONSTRUCTOR MHD_init () | 1674 | void ATTRIBUTE_CONSTRUCTOR MHD_init () |
1650 | { | 1675 | { |
1676 | mhd_panic = mhd_panic_std; | ||
1677 | mhd_panic_cls = NULL; | ||
1678 | |||
1651 | #ifndef WINDOWS | 1679 | #ifndef WINDOWS |
1652 | /* make sure SIGALRM does not kill us */ | 1680 | /* make sure SIGALRM does not kill us */ |
1653 | memset (&sig, 0, sizeof (struct sigaction)); | 1681 | memset (&sig, 0, sizeof (struct sigaction)); |
@@ -1668,7 +1696,7 @@ void ATTRIBUTE_DESTRUCTOR MHD_fini () | |||
1668 | { | 1696 | { |
1669 | #if HTTPS_SUPPORT | 1697 | #if HTTPS_SUPPORT |
1670 | if (0 != pthread_mutex_destroy(&MHD_gnutls_init_mutex)) | 1698 | if (0 != pthread_mutex_destroy(&MHD_gnutls_init_mutex)) |
1671 | abort (); | 1699 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); |
1672 | #endif | 1700 | #endif |
1673 | #ifndef WINDOWS | 1701 | #ifndef WINDOWS |
1674 | sigaction (SIGALRM, &old, &sig); | 1702 | sigaction (SIGALRM, &old, &sig); |
diff --git a/src/daemon/internal.h b/src/daemon/internal.h index 22fb2da4..7dc43b5a 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h | |||
@@ -45,6 +45,13 @@ | |||
45 | */ | 45 | */ |
46 | #define MHD_BUF_INC_SIZE 2048 | 46 | #define MHD_BUF_INC_SIZE 2048 |
47 | 47 | ||
48 | /** | ||
49 | * Error handler | ||
50 | */ | ||
51 | extern MHD_PanicCallback mhd_panic; | ||
52 | extern void *mhd_panic_cls; | ||
53 | |||
54 | |||
48 | #if HAVE_MESSAGES | 55 | #if HAVE_MESSAGES |
49 | /** | 56 | /** |
50 | * fprintf-like helper function for logging debug | 57 | * fprintf-like helper function for logging debug |
diff --git a/src/daemon/postprocessor.c b/src/daemon/postprocessor.c index 7cc11dde..4d075839 100644 --- a/src/daemon/postprocessor.c +++ b/src/daemon/postprocessor.c | |||
@@ -256,7 +256,7 @@ MHD_create_post_processor (struct MHD_Connection *connection, | |||
256 | size_t blen; | 256 | size_t blen; |
257 | 257 | ||
258 | if ((buffer_size < 256) || (connection == NULL) || (ikvi == NULL)) | 258 | if ((buffer_size < 256) || (connection == NULL) || (ikvi == NULL)) |
259 | abort (); | 259 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); |
260 | encoding = MHD_lookup_connection_value (connection, | 260 | encoding = MHD_lookup_connection_value (connection, |
261 | MHD_HEADER_KIND, | 261 | MHD_HEADER_KIND, |
262 | MHD_HTTP_HEADER_CONTENT_TYPE); | 262 | MHD_HTTP_HEADER_CONTENT_TYPE); |
@@ -304,7 +304,7 @@ MHD_create_post_processor (struct MHD_Connection *connection, | |||
304 | */ | 304 | */ |
305 | static int | 305 | static int |
306 | post_process_urlencoded (struct MHD_PostProcessor *pp, | 306 | post_process_urlencoded (struct MHD_PostProcessor *pp, |
307 | const char *post_data, | 307 | const char *post_data, |
308 | size_t post_data_len) | 308 | size_t post_data_len) |
309 | { | 309 | { |
310 | size_t equals; | 310 | size_t equals; |
@@ -440,7 +440,7 @@ post_process_urlencoded (struct MHD_PostProcessor *pp, | |||
440 | } | 440 | } |
441 | return MHD_NO; | 441 | return MHD_NO; |
442 | default: | 442 | default: |
443 | abort (); /* should never happen! */ | 443 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); /* should never happen! */ |
444 | } | 444 | } |
445 | } | 445 | } |
446 | return MHD_YES; | 446 | return MHD_YES; |
@@ -960,7 +960,7 @@ post_process_multipart (struct MHD_PostProcessor *pp, | |||
960 | state_changed = 1; | 960 | state_changed = 1; |
961 | break; | 961 | break; |
962 | default: | 962 | default: |
963 | abort (); /* should never happen! */ | 963 | mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); /* should never happen! */ |
964 | } | 964 | } |
965 | AGAIN: | 965 | AGAIN: |
966 | if (ioff > 0) | 966 | if (ioff > 0) |