aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 7f814ec0..d3b9958d 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2376,6 +2376,7 @@ psk_gnutls_adapter (gnutls_session_t session,
2376 * @param non_blck indicate that socket in non-blocking mode 2376 * @param non_blck indicate that socket in non-blocking mode
2377 * @param sk_spipe_supprs indicate that the @a client_socket has 2377 * @param sk_spipe_supprs indicate that the @a client_socket has
2378 * set SIGPIPE suppression 2378 * set SIGPIPE suppression
2379 * @param sk_is_unix true if this is a UNIX domain socket (AF_UNIX)
2379 * @return pointer to the connection on success, NULL if this daemon could 2380 * @return pointer to the connection on success, NULL if this daemon could
2380 * not handle the connection (i.e. malloc failed, etc). 2381 * not handle the connection (i.e. malloc failed, etc).
2381 * The socket will be closed in case of error; 'errno' is 2382 * The socket will be closed in case of error; 'errno' is
@@ -2388,7 +2389,8 @@ new_connection_prepare_ (struct MHD_Daemon *daemon,
2388 socklen_t addrlen, 2389 socklen_t addrlen,
2389 bool external_add, 2390 bool external_add,
2390 bool non_blck, 2391 bool non_blck,
2391 bool sk_spipe_supprs) 2392 bool sk_spipe_supprs,
2393 bool sk_is_unix)
2392{ 2394{
2393 struct MHD_Connection *connection; 2395 struct MHD_Connection *connection;
2394 int eno = 0; 2396 int eno = 0;
@@ -2490,6 +2492,7 @@ new_connection_prepare_ (struct MHD_Daemon *daemon,
2490 connection->addr_len = addrlen; 2492 connection->addr_len = addrlen;
2491 connection->socket_fd = client_socket; 2493 connection->socket_fd = client_socket;
2492 connection->sk_nonblck = non_blck; 2494 connection->sk_nonblck = non_blck;
2495 connection->is_unix = sk_is_unix;
2493 connection->sk_spipe_suppress = sk_spipe_supprs; 2496 connection->sk_spipe_suppress = sk_spipe_supprs;
2494 connection->daemon = daemon; 2497 connection->daemon = daemon;
2495 connection->last_activity = MHD_monotonic_sec_counter (); 2498 connection->last_activity = MHD_monotonic_sec_counter ();
@@ -2860,6 +2863,7 @@ cleanup:
2860 * @param non_blck indicate that socket in non-blocking mode 2863 * @param non_blck indicate that socket in non-blocking mode
2861 * @param sk_spipe_supprs indicate that the @a client_socket has 2864 * @param sk_spipe_supprs indicate that the @a client_socket has
2862 * set SIGPIPE suppression 2865 * set SIGPIPE suppression
2866 * @param sk_is_unix true if this is a UNIX domain socket (AF_UNIX)
2863 * @return #MHD_YES on success, #MHD_NO if this daemon could 2867 * @return #MHD_YES on success, #MHD_NO if this daemon could
2864 * not handle the connection (i.e. malloc failed, etc). 2868 * not handle the connection (i.e. malloc failed, etc).
2865 * The socket will be closed in any case; 'errno' is 2869 * The socket will be closed in any case; 'errno' is
@@ -2872,7 +2876,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
2872 socklen_t addrlen, 2876 socklen_t addrlen,
2873 bool external_add, 2877 bool external_add,
2874 bool non_blck, 2878 bool non_blck,
2875 bool sk_spipe_supprs) 2879 bool sk_spipe_supprs,
2880 bool sk_is_unix)
2876{ 2881{
2877 struct MHD_Connection *connection; 2882 struct MHD_Connection *connection;
2878 2883
@@ -2912,9 +2917,13 @@ internal_add_connection (struct MHD_Daemon *daemon,
2912 return MHD_NO; 2917 return MHD_NO;
2913 } 2918 }
2914 2919
2915 connection = new_connection_prepare_ (daemon, client_socket, addr, addrlen, 2920 connection = new_connection_prepare_ (daemon,
2916 external_add, non_blck, 2921 client_socket,
2917 sk_spipe_supprs); 2922 addr, addrlen,
2923 external_add,
2924 non_blck,
2925 sk_spipe_supprs,
2926 sk_is_unix);
2918 if (NULL == connection) 2927 if (NULL == connection)
2919 return MHD_NO; 2928 return MHD_NO;
2920 2929
@@ -3339,6 +3348,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
3339{ 3348{
3340 bool sk_nonbl; 3349 bool sk_nonbl;
3341 bool sk_spipe_supprs; 3350 bool sk_spipe_supprs;
3351 bool sk_is_unix = false;
3342 3352
3343 /* NOT thread safe with internal thread. TODO: fix thread safety. */ 3353 /* NOT thread safe with internal thread. TODO: fix thread safety. */
3344 if ((0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) && 3354 if ((0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) &&
@@ -3409,6 +3419,20 @@ MHD_add_connection (struct MHD_Daemon *daemon,
3409 _ ("Failed to set noninheritable mode on new client socket.\n")); 3419 _ ("Failed to set noninheritable mode on new client socket.\n"));
3410#endif 3420#endif
3411 } 3421 }
3422#ifdef SO_DOMAIN
3423 {
3424 int af;
3425 socklen_t len = sizeof (af);
3426
3427 if ( (0 == getsockopt (daemon->listen_fd,
3428 SOL_SOCKET,
3429 SO_DOMAIN,
3430 &af,
3431 &len)) &&
3432 (AF_UNIX == af) )
3433 sk_is_unix = true;
3434 }
3435#endif
3412 3436
3413#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 3437#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3414 if (NULL != daemon->worker_pool) 3438 if (NULL != daemon->worker_pool)
@@ -3428,7 +3452,8 @@ MHD_add_connection (struct MHD_Daemon *daemon,
3428 addrlen, 3452 addrlen,
3429 true, 3453 true,
3430 sk_nonbl, 3454 sk_nonbl,
3431 sk_spipe_supprs); 3455 sk_spipe_supprs,
3456 sk_is_unix);
3432 } 3457 }
3433 /* all pools are at their connection limit, must refuse */ 3458 /* all pools are at their connection limit, must refuse */
3434 MHD_socket_close_chk_ (client_socket); 3459 MHD_socket_close_chk_ (client_socket);
@@ -3445,7 +3470,8 @@ MHD_add_connection (struct MHD_Daemon *daemon,
3445 addrlen, 3470 addrlen,
3446 true, 3471 true,
3447 sk_nonbl, 3472 sk_nonbl,
3448 sk_spipe_supprs); 3473 sk_spipe_supprs,
3474 sk_is_unix);
3449} 3475}
3450 3476
3451 3477
@@ -3627,7 +3653,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
3627 addrlen, 3653 addrlen,
3628 false, 3654 false,
3629 sk_nonbl, 3655 sk_nonbl,
3630 sk_spipe_supprs); 3656 sk_spipe_supprs,
3657 daemon->listen_is_unix);
3631 return MHD_YES; 3658 return MHD_YES;
3632} 3659}
3633 3660
@@ -5810,8 +5837,24 @@ parse_options_va (struct MHD_Daemon *daemon,
5810 return MHD_NO; 5837 return MHD_NO;
5811 } 5838 }
5812 else 5839 else
5840 {
5813 daemon->listen_fd = va_arg (ap, 5841 daemon->listen_fd = va_arg (ap,
5814 MHD_socket); 5842 MHD_socket);
5843#ifdef SO_DOMAIN
5844 {
5845 int af;
5846 socklen_t len = sizeof (af);
5847
5848 if ( (0 == getsockopt (daemon->listen_fd,
5849 SOL_SOCKET,
5850 SO_DOMAIN,
5851 &af,
5852 &len)) &&
5853 (AF_UNIX == af) )
5854 daemon->listen_is_unix = true;
5855 }
5856#endif
5857 }
5815 break; 5858 break;
5816 case MHD_OPTION_EXTERNAL_LOGGER: 5859 case MHD_OPTION_EXTERNAL_LOGGER:
5817#ifdef HAVE_MESSAGES 5860#ifdef HAVE_MESSAGES
@@ -6680,7 +6723,6 @@ MHD_start_daemon_va (unsigned int flags,
6680 } 6723 }
6681 } 6724 }
6682 daemon->listen_fd = listen_fd; 6725 daemon->listen_fd = listen_fd;
6683
6684 if (0 != (*pflags & MHD_USE_IPv6)) 6726 if (0 != (*pflags & MHD_USE_IPv6))
6685 { 6727 {
6686#ifdef IPPROTO_IPV6 6728#ifdef IPPROTO_IPV6