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.c198
1 files changed, 99 insertions, 99 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index c388e6ad..9bd32607 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -49,10 +49,10 @@
49#include "tsearch.h" 49#include "tsearch.h"
50#endif 50#endif
51 51
52#if HTTPS_SUPPORT 52#ifdef HTTPS_SUPPORT
53#include "connection_https.h" 53#include "connection_https.h"
54#include <gcrypt.h> 54#include <gcrypt.h>
55#endif 55#endif /* HTTPS_SUPPORT */
56 56
57#ifdef LINUX 57#ifdef LINUX
58#include <sys/sendfile.h> 58#include <sys/sendfile.h>
@@ -415,7 +415,7 @@ MHD_ip_limit_del (struct MHD_Daemon *daemon,
415} 415}
416 416
417 417
418#if HTTPS_SUPPORT 418#ifdef HTTPS_SUPPORT
419/** 419/**
420 * Callback for receiving data from the socket. 420 * Callback for receiving data from the socket.
421 * 421 *
@@ -622,7 +622,7 @@ MHD_TLS_init (struct MHD_Daemon *daemon)
622 return -1; 622 return -1;
623 } 623 }
624} 624}
625#endif 625#endif /* HTTPS_SUPPORT */
626 626
627 627
628#undef MHD_get_fdset 628#undef MHD_get_fdset
@@ -662,7 +662,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
662} 662}
663 663
664 664
665#if HTTPS_SUPPORT 665#ifdef HTTPS_SUPPORT
666/** 666/**
667 * Obtain the select() file descriptor sets for the 667 * Obtain the select() file descriptor sets for the
668 * given @a urh. 668 * given @a urh.
@@ -743,7 +743,7 @@ urh_from_fdset (struct MHD_UpgradeResponseHandle *urh,
743 FD_ISSET (mhd_sckt, ws)) 743 FD_ISSET (mhd_sckt, ws))
744 urh->mhd.celi |= MHD_EPOLL_STATE_WRITE_READY; 744 urh->mhd.celi |= MHD_EPOLL_STATE_WRITE_READY;
745} 745}
746#endif 746#endif /* HTTPS_SUPPORT */
747 747
748 748
749/** 749/**
@@ -844,7 +844,7 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
844 break; 844 break;
845 } 845 }
846 } 846 }
847#if HTTPS_SUPPORT 847#ifdef HTTPS_SUPPORT
848 { 848 {
849 struct MHD_UpgradeResponseHandle *urh; 849 struct MHD_UpgradeResponseHandle *urh;
850 850
@@ -867,7 +867,7 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
867 _("Maximum socket in select set: %d\n"), 867 _("Maximum socket in select set: %d\n"),
868 *max_fd); 868 *max_fd);
869#endif 869#endif
870#endif 870#endif /* HTTPS_SUPPORT */
871 return result; 871 return result;
872} 872}
873 873
@@ -895,10 +895,10 @@ call_handlers (struct MHD_Connection *con,
895 int had_response_before_idle; 895 int had_response_before_idle;
896 int ret; 896 int ret;
897 897
898#if HTTPS_SUPPORT 898#ifdef HTTPS_SUPPORT
899 if (MHD_YES == con->tls_read_ready) 899 if (MHD_YES == con->tls_read_ready)
900 read_ready = MHD_YES; 900 read_ready = MHD_YES;
901#endif 901#endif /* HTTPS_SUPPORT */
902 if (read_ready) 902 if (read_ready)
903 con->read_handler (con); 903 con->read_handler (con);
904 if (write_ready) 904 if (write_ready)
@@ -957,7 +957,7 @@ MHD_cleanup_upgraded_connection_ (struct MHD_Connection *connection)
957} 957}
958 958
959 959
960#if HTTPS_SUPPORT 960#ifdef HTTPS_SUPPORT
961/** 961/**
962 * Performs bi-directional forwarding on upgraded HTTPS connections 962 * Performs bi-directional forwarding on upgraded HTTPS connections
963 * based on the readyness state stored in the @a urh handle. 963 * based on the readyness state stored in the @a urh handle.
@@ -1216,7 +1216,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
1216 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY; 1216 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
1217 } 1217 }
1218} 1218}
1219#endif 1219#endif /* HTTPS_SUPPORT */
1220 1220
1221 1221
1222/** 1222/**
@@ -1231,7 +1231,7 @@ static void
1231thread_main_connection_upgrade (struct MHD_Connection *con) 1231thread_main_connection_upgrade (struct MHD_Connection *con)
1232{ 1232{
1233 struct MHD_UpgradeResponseHandle *urh = con->urh; 1233 struct MHD_UpgradeResponseHandle *urh = con->urh;
1234#if HTTPS_SUPPORT 1234#ifdef HTTPS_SUPPORT
1235 struct MHD_Daemon *daemon = con->daemon; 1235 struct MHD_Daemon *daemon = con->daemon;
1236 1236
1237 /* Here, we need to bi-directionally forward 1237 /* Here, we need to bi-directionally forward
@@ -1359,7 +1359,7 @@ thread_main_connection_upgrade (struct MHD_Connection *con)
1359 /* end POLL */ 1359 /* end POLL */
1360#endif 1360#endif
1361 /* end HTTPS */ 1361 /* end HTTPS */
1362#endif 1362#endif /* HTTPS_SUPPORT */
1363 /* TLS forwarding was finished. Cleanup socketpair. */ 1363 /* TLS forwarding was finished. Cleanup socketpair. */
1364 MHD_connection_finish_forward_ (con); 1364 MHD_connection_finish_forward_ (con);
1365 /* Do not set 'urh->clean_ready' yet as 'urh' will be used 1365 /* Do not set 'urh->clean_ready' yet as 'urh' will be used
@@ -1474,7 +1474,7 @@ thread_main_handle_connection (void *data)
1474 } 1474 }
1475 1475
1476 tvp = NULL; 1476 tvp = NULL;
1477#if HTTPS_SUPPORT 1477#ifdef HTTPS_SUPPORT
1478 if (MHD_YES == con->tls_read_ready) 1478 if (MHD_YES == con->tls_read_ready)
1479 { 1479 {
1480 /* do not block (more data may be inside of TLS buffers waiting for us) */ 1480 /* do not block (more data may be inside of TLS buffers waiting for us) */
@@ -1482,7 +1482,7 @@ thread_main_handle_connection (void *data)
1482 tv.tv_usec = 0; 1482 tv.tv_usec = 0;
1483 tvp = &tv; 1483 tvp = &tv;
1484 } 1484 }
1485#endif 1485#endif /* HTTPS_SUPPORT */
1486 if ( (NULL == tvp) && 1486 if ( (NULL == tvp) &&
1487 (timeout > 0) ) 1487 (timeout > 0) )
1488 { 1488 {
@@ -2128,7 +2128,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
2128 } 2128 }
2129 } 2129 }
2130 2130
2131#if HTTPS_SUPPORT 2131#ifdef HTTPS_SUPPORT
2132 if (0 != (daemon->options & MHD_USE_TLS)) 2132 if (0 != (daemon->options & MHD_USE_TLS))
2133 { 2133 {
2134 connection->recv_cls = &recv_tls_adapter; 2134 connection->recv_cls = &recv_tls_adapter;
@@ -2176,7 +2176,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
2176 gnutls_certificate_server_set_request (connection->tls_session, 2176 gnutls_certificate_server_set_request (connection->tls_session,
2177 GNUTLS_CERT_REQUEST); 2177 GNUTLS_CERT_REQUEST);
2178 } 2178 }
2179#endif 2179#endif /* HTTPS_SUPPORT */
2180 2180
2181 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2181 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2182 { 2182 {
@@ -2742,10 +2742,10 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
2742 if (NULL != pos->urh) 2742 if (NULL != pos->urh)
2743 MHD_cleanup_upgraded_connection_ (pos); 2743 MHD_cleanup_upgraded_connection_ (pos);
2744 MHD_pool_destroy (pos->pool); 2744 MHD_pool_destroy (pos->pool);
2745#if HTTPS_SUPPORT 2745#ifdef HTTPS_SUPPORT
2746 if (NULL != pos->tls_session) 2746 if (NULL != pos->tls_session)
2747 gnutls_deinit (pos->tls_session); 2747 gnutls_deinit (pos->tls_session);
2748#endif 2748#endif /* HTTPS_SUPPORT */
2749 daemon->connections--; 2749 daemon->connections--;
2750 daemon->at_limit = MHD_NO; 2750 daemon->at_limit = MHD_NO;
2751 2751
@@ -2839,7 +2839,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
2839 return MHD_NO; 2839 return MHD_NO;
2840 } 2840 }
2841 2841
2842#if HTTPS_SUPPORT 2842#ifdef HTTPS_SUPPORT
2843 if (0 != daemon->num_tls_read_ready) 2843 if (0 != daemon->num_tls_read_ready)
2844 { 2844 {
2845 /* if there is any TLS connection with data ready for 2845 /* if there is any TLS connection with data ready for
@@ -2847,7 +2847,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
2847 *timeout = 0; 2847 *timeout = 0;
2848 return MHD_YES; 2848 return MHD_YES;
2849 } 2849 }
2850#endif 2850#endif /* HTTPS_SUPPORT */
2851 2851
2852 have_timeout = MHD_NO; 2852 have_timeout = MHD_NO;
2853 earliest_deadline = 0; /* avoid compiler warnings */ 2853 earliest_deadline = 0; /* avoid compiler warnings */
@@ -2858,11 +2858,11 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
2858 if ( (! have_timeout) || 2858 if ( (! have_timeout) ||
2859 (earliest_deadline > pos->last_activity + pos->connection_timeout) ) 2859 (earliest_deadline > pos->last_activity + pos->connection_timeout) )
2860 earliest_deadline = pos->last_activity + pos->connection_timeout; 2860 earliest_deadline = pos->last_activity + pos->connection_timeout;
2861#if HTTPS_SUPPORT 2861#ifdef HTTPS_SUPPORT
2862 if ( (0 != (daemon->options & MHD_USE_TLS)) && 2862 if ( (0 != (daemon->options & MHD_USE_TLS)) &&
2863 (0 != gnutls_record_check_pending (pos->tls_session)) ) 2863 (0 != gnutls_record_check_pending (pos->tls_session)) )
2864 earliest_deadline = 0; 2864 earliest_deadline = 0;
2865#endif 2865#endif /* HTTPS_SUPPORT */
2866 have_timeout = MHD_YES; 2866 have_timeout = MHD_YES;
2867 } 2867 }
2868 } 2868 }
@@ -2874,11 +2874,11 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
2874 if ( (! have_timeout) || 2874 if ( (! have_timeout) ||
2875 (earliest_deadline > pos->last_activity + pos->connection_timeout) ) 2875 (earliest_deadline > pos->last_activity + pos->connection_timeout) )
2876 earliest_deadline = pos->last_activity + pos->connection_timeout; 2876 earliest_deadline = pos->last_activity + pos->connection_timeout;
2877#if HTTPS_SUPPORT 2877#ifdef HTTPS_SUPPORT
2878 if ( (0 != (daemon->options & MHD_USE_TLS)) && 2878 if ( (0 != (daemon->options & MHD_USE_TLS)) &&
2879 (0 != gnutls_record_check_pending (pos->tls_session)) ) 2879 (0 != gnutls_record_check_pending (pos->tls_session)) )
2880 earliest_deadline = 0; 2880 earliest_deadline = 0;
2881#endif 2881#endif /* HTTPS_SUPPORT */
2882 have_timeout = MHD_YES; 2882 have_timeout = MHD_YES;
2883 } 2883 }
2884 2884
@@ -2927,10 +2927,10 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
2927 MHD_socket ds; 2927 MHD_socket ds;
2928 struct MHD_Connection *pos; 2928 struct MHD_Connection *pos;
2929 struct MHD_Connection *next; 2929 struct MHD_Connection *next;
2930#if HTTPS_SUPPORT 2930#ifdef HTTPS_SUPPORT
2931 struct MHD_UpgradeResponseHandle *urh; 2931 struct MHD_UpgradeResponseHandle *urh;
2932 struct MHD_UpgradeResponseHandle *urhn; 2932 struct MHD_UpgradeResponseHandle *urhn;
2933#endif 2933#endif /* HTTPS_SUPPORT */
2934 unsigned int mask = MHD_USE_SUSPEND_RESUME | MHD_USE_EPOLL_INTERNALLY | 2934 unsigned int mask = MHD_USE_SUSPEND_RESUME | MHD_USE_EPOLL_INTERNALLY |
2935 MHD_USE_SELECT_INTERNALLY | MHD_USE_POLL_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION; 2935 MHD_USE_SELECT_INTERNALLY | MHD_USE_POLL_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION;
2936 2936
@@ -2987,7 +2987,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
2987 } 2987 }
2988 2988
2989 /* handle upgraded HTTPS connections */ 2989 /* handle upgraded HTTPS connections */
2990#if HTTPS_SUPPORT 2990#ifdef HTTPS_SUPPORT
2991 for (urh = daemon->urh_head; NULL != urh; urh = urhn) 2991 for (urh = daemon->urh_head; NULL != urh; urh = urhn)
2992 { 2992 {
2993 urhn = urh->next; 2993 urhn = urh->next;
@@ -3009,7 +3009,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
3009 MHD_resume_connection(urh->connection); 3009 MHD_resume_connection(urh->connection);
3010 } 3010 }
3011 } 3011 }
3012#endif 3012#endif /* HTTPS_SUPPORT */
3013 MHD_cleanup_connections (daemon); 3013 MHD_cleanup_connections (daemon);
3014 return MHD_YES; 3014 return MHD_YES;
3015} 3015}
@@ -3193,10 +3193,10 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3193 unsigned int num_connections; 3193 unsigned int num_connections;
3194 struct MHD_Connection *pos; 3194 struct MHD_Connection *pos;
3195 struct MHD_Connection *next; 3195 struct MHD_Connection *next;
3196#if HTTPS_SUPPORT 3196#ifdef HTTPS_SUPPORT
3197 struct MHD_UpgradeResponseHandle *urh; 3197 struct MHD_UpgradeResponseHandle *urh;
3198 struct MHD_UpgradeResponseHandle *urhn; 3198 struct MHD_UpgradeResponseHandle *urhn;
3199#endif 3199#endif /* HTTPS_SUPPORT */
3200 3200
3201 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) && 3201 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) &&
3202 (MHD_YES == resume_suspended_connections (daemon)) ) 3202 (MHD_YES == resume_suspended_connections (daemon)) )
@@ -3206,10 +3206,10 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3206 num_connections = 0; 3206 num_connections = 0;
3207 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 3207 for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
3208 num_connections++; 3208 num_connections++;
3209#if HTTPS_SUPPORT 3209#ifdef HTTPS_SUPPORT
3210 for (urh = daemon->urh_head; NULL != urh; urh = urh->next) 3210 for (urh = daemon->urh_head; NULL != urh; urh = urh->next)
3211 num_connections += 2; 3211 num_connections += 2;
3212#endif 3212#endif /* HTTPS_SUPPORT */
3213 { 3213 {
3214 MHD_UNSIGNED_LONG_LONG ltimeout; 3214 MHD_UNSIGNED_LONG_LONG ltimeout;
3215 unsigned int i; 3215 unsigned int i;
@@ -3287,7 +3287,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3287 } 3287 }
3288 i++; 3288 i++;
3289 } 3289 }
3290#if HTTPS_SUPPORT 3290#ifdef HTTPS_SUPPORT
3291 for (urh = daemon->urh_head; NULL != urh; urh = urh->next) 3291 for (urh = daemon->urh_head; NULL != urh; urh = urh->next)
3292 { 3292 {
3293 p[poll_server+i].fd = urh->connection->socket_fd; 3293 p[poll_server+i].fd = urh->connection->socket_fd;
@@ -3303,7 +3303,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3303 p[poll_server+i].events |= POLLOUT; 3303 p[poll_server+i].events |= POLLOUT;
3304 i++; 3304 i++;
3305 } 3305 }
3306#endif 3306#endif /* HTTPS_SUPPORT */
3307 if (0 == poll_server + num_connections) 3307 if (0 == poll_server + num_connections)
3308 { 3308 {
3309 free(p); 3309 free(p);
@@ -3356,7 +3356,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3356 MHD_NO); 3356 MHD_NO);
3357 i++; 3357 i++;
3358 } 3358 }
3359#if HTTPS_SUPPORT 3359#ifdef HTTPS_SUPPORT
3360 for (urh = daemon->urh_head; NULL != urh; urh = urhn) 3360 for (urh = daemon->urh_head; NULL != urh; urh = urhn)
3361 { 3361 {
3362 if (i >= num_connections) 3362 if (i >= num_connections)
@@ -3401,7 +3401,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
3401 MHD_resume_connection(urh->connection); 3401 MHD_resume_connection(urh->connection);
3402 } 3402 }
3403 } 3403 }
3404#endif 3404#endif /* HTTPS_SUPPORT */
3405 /* handle 'listen' FD */ 3405 /* handle 'listen' FD */
3406 if ( (-1 != poll_listen) && 3406 if ( (-1 != poll_listen) &&
3407 (0 != (p[poll_listen].revents & POLLIN)) ) 3407 (0 != (p[poll_listen].revents & POLLIN)) )
@@ -3526,7 +3526,7 @@ MHD_poll (struct MHD_Daemon *daemon,
3526#define MAX_EVENTS 128 3526#define MAX_EVENTS 128
3527 3527
3528 3528
3529#if HTTPS_SUPPORT 3529#ifdef HTTPS_SUPPORT
3530 3530
3531/** 3531/**
3532 * Do epoll()-based processing for TLS connections that have been 3532 * Do epoll()-based processing for TLS connections that have been
@@ -3600,7 +3600,7 @@ run_epoll_for_upgrade (struct MHD_Daemon *daemon)
3600 } 3600 }
3601 return MHD_YES; 3601 return MHD_YES;
3602} 3602}
3603#endif 3603#endif /* HTTPS_SUPPORT */
3604 3604
3605 3605
3606/** 3606/**
@@ -3615,9 +3615,9 @@ static int
3615MHD_epoll (struct MHD_Daemon *daemon, 3615MHD_epoll (struct MHD_Daemon *daemon,
3616 int may_block) 3616 int may_block)
3617{ 3617{
3618#if HTTPS_SUPPORT 3618#ifdef HTTPS_SUPPORT
3619 static const char *upgrade_marker = "upgrade_ptr"; 3619 static const char *upgrade_marker = "upgrade_ptr";
3620#endif 3620#endif /* HTTPS_SUPPORT */
3621 struct MHD_Connection *pos; 3621 struct MHD_Connection *pos;
3622 struct MHD_Connection *next; 3622 struct MHD_Connection *next;
3623 struct epoll_event events[MAX_EVENTS]; 3623 struct epoll_event events[MAX_EVENTS];
@@ -3627,9 +3627,9 @@ MHD_epoll (struct MHD_Daemon *daemon,
3627 int num_events; 3627 int num_events;
3628 unsigned int i; 3628 unsigned int i;
3629 unsigned int series_length; 3629 unsigned int series_length;
3630#if HTTPS_SUPPORT 3630#ifdef HTTPS_SUPPORT
3631 _MHD_bool run_upgraded = 0; 3631 _MHD_bool run_upgraded = 0;
3632#endif 3632#endif /* HTTPS_SUPPORT */
3633 3633
3634 if (-1 == daemon->epoll_fd) 3634 if (-1 == daemon->epoll_fd)
3635 return MHD_NO; /* we're down! */ 3635 return MHD_NO; /* we're down! */
@@ -3656,7 +3656,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
3656 } 3656 }
3657 daemon->listen_socket_in_epoll = MHD_YES; 3657 daemon->listen_socket_in_epoll = MHD_YES;
3658 } 3658 }
3659#if HTTPS_SUPPORT 3659#ifdef HTTPS_SUPPORT
3660 if ( (MHD_NO == daemon->upgrade_fd_in_epoll) && 3660 if ( (MHD_NO == daemon->upgrade_fd_in_epoll) &&
3661 (-1 != daemon->epoll_upgrade_fd) ) 3661 (-1 != daemon->epoll_upgrade_fd) )
3662 { 3662 {
@@ -3676,7 +3676,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
3676 } 3676 }
3677 daemon->upgrade_fd_in_epoll = MHD_YES; 3677 daemon->upgrade_fd_in_epoll = MHD_YES;
3678 } 3678 }
3679#endif 3679#endif /* HTTPS_SUPPORT */
3680 if ( ( (MHD_YES == daemon->listen_socket_in_epoll) && 3680 if ( ( (MHD_YES == daemon->listen_socket_in_epoll) &&
3681 (daemon->connections == daemon->connection_limit) ) || 3681 (daemon->connections == daemon->connection_limit) ) ||
3682 (MHD_YES == daemon->at_limit) ) 3682 (MHD_YES == daemon->at_limit) )
@@ -3736,7 +3736,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
3736 that this event is not about a normal connection. */ 3736 that this event is not about a normal connection. */
3737 if (NULL == events[i].data.ptr) 3737 if (NULL == events[i].data.ptr)
3738 continue; /* shutdown signal! */ 3738 continue; /* shutdown signal! */
3739#if HTTPS_SUPPORT 3739#ifdef HTTPS_SUPPORT
3740 if (upgrade_marker == events[i].data.ptr) 3740 if (upgrade_marker == events[i].data.ptr)
3741 { 3741 {
3742 /* activity on an upgraded connection, we process 3742 /* activity on an upgraded connection, we process
@@ -3744,7 +3744,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
3744 run_upgraded = !0; 3744 run_upgraded = !0;
3745 continue; 3745 continue;
3746 } 3746 }
3747#endif 3747#endif /* HTTPS_SUPPORT */
3748 /* UGH: we're storing pointers and fds in the same union 3748 /* UGH: we're storing pointers and fds in the same union
3749 here; incredibly ugly and somewhat risky, even though a 3749 here; incredibly ugly and somewhat risky, even though a
3750 pointer with the same numeric value as the itc.fd[0] can 3750 pointer with the same numeric value as the itc.fd[0] can
@@ -4190,10 +4190,10 @@ parse_options_va (struct MHD_Daemon *daemon,
4190 enum MHD_OPTION opt; 4190 enum MHD_OPTION opt;
4191 struct MHD_OptionItem *oa; 4191 struct MHD_OptionItem *oa;
4192 unsigned int i; 4192 unsigned int i;
4193#if HTTPS_SUPPORT 4193#ifdef HTTPS_SUPPORT
4194 int ret; 4194 int ret;
4195 const char *pstr; 4195 const char *pstr;
4196#endif 4196#endif /* HTTPS_SUPPORT */
4197 4197
4198 while (MHD_OPTION_END != (opt = (enum MHD_OPTION) va_arg (ap, int))) 4198 while (MHD_OPTION_END != (opt = (enum MHD_OPTION) va_arg (ap, int)))
4199 { 4199 {
@@ -4254,7 +4254,7 @@ parse_options_va (struct MHD_Daemon *daemon,
4254 return MHD_NO; 4254 return MHD_NO;
4255 } 4255 }
4256 break; 4256 break;
4257#if HTTPS_SUPPORT 4257#ifdef HTTPS_SUPPORT
4258 case MHD_OPTION_HTTPS_MEM_KEY: 4258 case MHD_OPTION_HTTPS_MEM_KEY:
4259 if (0 != (daemon->options & MHD_USE_TLS)) 4259 if (0 != (daemon->options & MHD_USE_TLS))
4260 daemon->https_mem_key = va_arg (ap, 4260 daemon->https_mem_key = va_arg (ap,
@@ -4376,7 +4376,7 @@ parse_options_va (struct MHD_Daemon *daemon,
4376 gnutls_certificate_retrieve_function2 *); 4376 gnutls_certificate_retrieve_function2 *);
4377 break; 4377 break;
4378#endif 4378#endif
4379#endif 4379#endif /* HTTPS_SUPPORT */
4380#ifdef DAUTH_SUPPORT 4380#ifdef DAUTH_SUPPORT
4381 case MHD_OPTION_DIGEST_AUTH_RANDOM: 4381 case MHD_OPTION_DIGEST_AUTH_RANDOM:
4382 daemon->digest_auth_rand_size = va_arg (ap, 4382 daemon->digest_auth_rand_size = va_arg (ap,
@@ -4603,14 +4603,14 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
4603 daemon->epoll_fd = setup_epoll_fd (daemon); 4603 daemon->epoll_fd = setup_epoll_fd (daemon);
4604 if (-1 == daemon->epoll_fd) 4604 if (-1 == daemon->epoll_fd)
4605 return MHD_NO; 4605 return MHD_NO;
4606#if HTTPS_SUPPORT 4606#ifdef HTTPS_SUPPORT
4607 if (0 != (MHD_ALLOW_UPGRADE & daemon->options)) 4607 if (0 != (MHD_ALLOW_UPGRADE & daemon->options))
4608 { 4608 {
4609 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon); 4609 daemon->epoll_upgrade_fd = setup_epoll_fd (daemon);
4610 if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd) 4610 if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd)
4611 return MHD_NO; 4611 return MHD_NO;
4612 } 4612 }
4613#endif 4613#endif /* HTTPS_SUPPORT */
4614 if (MHD_INVALID_SOCKET == daemon->socket_fd) 4614 if (MHD_INVALID_SOCKET == daemon->socket_fd)
4615 return MHD_YES; /* non-listening daemon */ 4615 return MHD_YES; /* non-listening daemon */
4616 event.events = EPOLLIN; 4616 event.events = EPOLLIN;
@@ -4697,10 +4697,10 @@ MHD_start_daemon_va (unsigned int flags,
4697 if (0 != (flags & MHD_USE_POLL)) 4697 if (0 != (flags & MHD_USE_POLL))
4698 return NULL; 4698 return NULL;
4699#endif 4699#endif
4700#if ! HTTPS_SUPPORT 4700#ifndef HTTPS_SUPPORT
4701 if (0 != (flags & MHD_USE_TLS)) 4701 if (0 != (flags & MHD_USE_TLS))
4702 return NULL; 4702 return NULL;
4703#endif 4703#endif /* ! HTTPS_SUPPORT */
4704#ifndef TCP_FASTOPEN 4704#ifndef TCP_FASTOPEN
4705 if (0 != (flags & MHD_USE_TCP_FASTOPEN)) 4705 if (0 != (flags & MHD_USE_TCP_FASTOPEN))
4706 return NULL; 4706 return NULL;
@@ -4714,19 +4714,19 @@ MHD_start_daemon_va (unsigned int flags,
4714 sizeof (struct MHD_Daemon)); 4714 sizeof (struct MHD_Daemon));
4715#ifdef EPOLL_SUPPORT 4715#ifdef EPOLL_SUPPORT
4716 daemon->epoll_fd = -1; 4716 daemon->epoll_fd = -1;
4717#if HTTPS_SUPPORT 4717#ifdef HTTPS_SUPPORT
4718 daemon->epoll_upgrade_fd = -1; 4718 daemon->epoll_upgrade_fd = -1;
4719#endif 4719#endif /* HTTPS_SUPPORT */
4720#endif 4720#endif
4721 /* try to open listen socket */ 4721 /* try to open listen socket */
4722#if HTTPS_SUPPORT 4722#ifdef HTTPS_SUPPORT
4723 if (0 != (flags & MHD_USE_TLS)) 4723 if (0 != (flags & MHD_USE_TLS))
4724 { 4724 {
4725 gnutls_priority_init (&daemon->priority_cache, 4725 gnutls_priority_init (&daemon->priority_cache,
4726 "NORMAL", 4726 "NORMAL",
4727 NULL); 4727 NULL);
4728 } 4728 }
4729#endif 4729#endif /* HTTPS_SUPPORT */
4730 daemon->socket_fd = MHD_INVALID_SOCKET; 4730 daemon->socket_fd = MHD_INVALID_SOCKET;
4731 daemon->listening_address_reuse = 0; 4731 daemon->listening_address_reuse = 0;
4732 daemon->options = flags; 4732 daemon->options = flags;
@@ -4794,23 +4794,23 @@ MHD_start_daemon_va (unsigned int flags,
4794 daemon->digest_auth_random = NULL; 4794 daemon->digest_auth_random = NULL;
4795 daemon->nonce_nc_size = 4; /* tiny */ 4795 daemon->nonce_nc_size = 4; /* tiny */
4796#endif 4796#endif
4797#if HTTPS_SUPPORT 4797#ifdef HTTPS_SUPPORT
4798 if (0 != (flags & MHD_USE_TLS)) 4798 if (0 != (flags & MHD_USE_TLS))
4799 { 4799 {
4800 daemon->cred_type = GNUTLS_CRD_CERTIFICATE; 4800 daemon->cred_type = GNUTLS_CRD_CERTIFICATE;
4801 } 4801 }
4802#endif 4802#endif /* HTTPS_SUPPORT */
4803 4803
4804 4804
4805 if (MHD_YES != parse_options_va (daemon, 4805 if (MHD_YES != parse_options_va (daemon,
4806 &servaddr, 4806 &servaddr,
4807 ap)) 4807 ap))
4808 { 4808 {
4809#if HTTPS_SUPPORT 4809#ifdef HTTPS_SUPPORT
4810 if ( (0 != (flags & MHD_USE_TLS)) && 4810 if ( (0 != (flags & MHD_USE_TLS)) &&
4811 (NULL != daemon->priority_cache) ) 4811 (NULL != daemon->priority_cache) )
4812 gnutls_priority_deinit (daemon->priority_cache); 4812 gnutls_priority_deinit (daemon->priority_cache);
4813#endif 4813#endif /* HTTPS_SUPPORT */
4814 free (daemon); 4814 free (daemon);
4815 return NULL; 4815 return NULL;
4816 } 4816 }
@@ -4824,10 +4824,10 @@ MHD_start_daemon_va (unsigned int flags,
4824 MHD_DLOG (daemon, 4824 MHD_DLOG (daemon,
4825 _("Specified value for NC_SIZE too large\n")); 4825 _("Specified value for NC_SIZE too large\n"));
4826#endif 4826#endif
4827#if HTTPS_SUPPORT 4827#ifdef HTTPS_SUPPORT
4828 if (0 != (flags & MHD_USE_TLS)) 4828 if (0 != (flags & MHD_USE_TLS))
4829 gnutls_priority_deinit (daemon->priority_cache); 4829 gnutls_priority_deinit (daemon->priority_cache);
4830#endif 4830#endif /* HTTPS_SUPPORT */
4831 free (daemon); 4831 free (daemon);
4832 return NULL; 4832 return NULL;
4833 } 4833 }
@@ -4839,10 +4839,10 @@ MHD_start_daemon_va (unsigned int flags,
4839 _("Failed to allocate memory for nonce-nc map: %s\n"), 4839 _("Failed to allocate memory for nonce-nc map: %s\n"),
4840 MHD_strerror_ (errno)); 4840 MHD_strerror_ (errno));
4841#endif 4841#endif
4842#if HTTPS_SUPPORT 4842#ifdef HTTPS_SUPPORT
4843 if (0 != (flags & MHD_USE_TLS)) 4843 if (0 != (flags & MHD_USE_TLS))
4844 gnutls_priority_deinit (daemon->priority_cache); 4844 gnutls_priority_deinit (daemon->priority_cache);
4845#endif 4845#endif /* HTTPS_SUPPORT */
4846 free (daemon); 4846 free (daemon);
4847 return NULL; 4847 return NULL;
4848 } 4848 }
@@ -4854,10 +4854,10 @@ MHD_start_daemon_va (unsigned int flags,
4854 MHD_DLOG (daemon, 4854 MHD_DLOG (daemon,
4855 _("MHD failed to initialize nonce-nc mutex\n")); 4855 _("MHD failed to initialize nonce-nc mutex\n"));
4856#endif 4856#endif
4857#if HTTPS_SUPPORT 4857#ifdef HTTPS_SUPPORT
4858 if (0 != (flags & MHD_USE_TLS)) 4858 if (0 != (flags & MHD_USE_TLS))
4859 gnutls_priority_deinit (daemon->priority_cache); 4859 gnutls_priority_deinit (daemon->priority_cache);
4860#endif 4860#endif /* HTTPS_SUPPORT */
4861 free (daemon->nnc); 4861 free (daemon->nnc);
4862 free (daemon); 4862 free (daemon);
4863 return NULL; 4863 return NULL;
@@ -5192,7 +5192,7 @@ MHD_start_daemon_va (unsigned int flags,
5192 goto free_and_fail; 5192 goto free_and_fail;
5193 } 5193 }
5194 5194
5195#if HTTPS_SUPPORT 5195#ifdef HTTPS_SUPPORT
5196 /* initialize HTTPS daemon certificate aspects & send / recv functions */ 5196 /* initialize HTTPS daemon certificate aspects & send / recv functions */
5197 if ( (0 != (flags & MHD_USE_TLS)) && 5197 if ( (0 != (flags & MHD_USE_TLS)) &&
5198 (0 != MHD_TLS_init (daemon)) ) 5198 (0 != MHD_TLS_init (daemon)) )
@@ -5207,7 +5207,7 @@ MHD_start_daemon_va (unsigned int flags,
5207 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex); 5207 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
5208 goto free_and_fail; 5208 goto free_and_fail;
5209 } 5209 }
5210#endif 5210#endif /* HTTPS_SUPPORT */
5211 if ( ( (0 != (flags & MHD_USE_THREAD_PER_CONNECTION)) || 5211 if ( ( (0 != (flags & MHD_USE_THREAD_PER_CONNECTION)) ||
5212 ( (0 != (flags & MHD_USE_SELECT_INTERNALLY)) && 5212 ( (0 != (flags & MHD_USE_SELECT_INTERNALLY)) &&
5213 (0 == daemon->worker_pool_size)) ) && 5213 (0 == daemon->worker_pool_size)) ) &&
@@ -5328,7 +5328,7 @@ MHD_start_daemon_va (unsigned int flags,
5328 } 5328 }
5329 } 5329 }
5330 } 5330 }
5331#if HTTPS_SUPPORT 5331#ifdef HTTPS_SUPPORT
5332 /* API promises to never use the password after initialization, 5332 /* API promises to never use the password after initialization,
5333 so we additionally NULL it here to not deref a dangling pointer. */ 5333 so we additionally NULL it here to not deref a dangling pointer. */
5334 daemon->https_key_password = NULL; 5334 daemon->https_key_password = NULL;
@@ -5363,7 +5363,7 @@ thread_failed:
5363 free_and_fail: 5363 free_and_fail:
5364 /* clean up basic memory state in 'daemon' and return NULL to 5364 /* clean up basic memory state in 'daemon' and return NULL to
5365 indicate failure */ 5365 indicate failure */
5366#if HTTPS_SUPPORT 5366#ifdef HTTPS_SUPPORT
5367#ifdef EPOLL_SUPPORT 5367#ifdef EPOLL_SUPPORT
5368 if (MHD_YES == daemon->upgrade_fd_in_epoll) 5368 if (MHD_YES == daemon->upgrade_fd_in_epoll)
5369 { 5369 {
@@ -5376,20 +5376,20 @@ thread_failed:
5376 } 5376 }
5377 if (-1 != daemon->epoll_fd) 5377 if (-1 != daemon->epoll_fd)
5378 close (daemon->epoll_fd); 5378 close (daemon->epoll_fd);
5379#if HTTPS_SUPPORT 5379#ifdef HTTPS_SUPPORT
5380 if (-1 != daemon->epoll_upgrade_fd) 5380 if (-1 != daemon->epoll_upgrade_fd)
5381 close (daemon->epoll_upgrade_fd); 5381 close (daemon->epoll_upgrade_fd);
5382#endif /* HTTPS_SUPPORT */
5382#endif 5383#endif
5383#endif 5384#endif /* HTTPS_SUPPORT */
5384#endif
5385#ifdef DAUTH_SUPPORT 5385#ifdef DAUTH_SUPPORT
5386 free (daemon->nnc); 5386 free (daemon->nnc);
5387 MHD_mutex_destroy_chk_ (&daemon->nnc_lock); 5387 MHD_mutex_destroy_chk_ (&daemon->nnc_lock);
5388#endif 5388#endif
5389#if HTTPS_SUPPORT 5389#ifdef HTTPS_SUPPORT
5390 if (0 != (flags & MHD_USE_TLS)) 5390 if (0 != (flags & MHD_USE_TLS))
5391 gnutls_priority_deinit (daemon->priority_cache); 5391 gnutls_priority_deinit (daemon->priority_cache);
5392#endif 5392#endif /* HTTPS_SUPPORT */
5393 if (MHD_ITC_IS_VALID_(daemon->itc)) 5393 if (MHD_ITC_IS_VALID_(daemon->itc))
5394 MHD_itc_destroy_chk_ (daemon->itc); 5394 MHD_itc_destroy_chk_ (daemon->itc);
5395 free (daemon); 5395 free (daemon);
@@ -5602,10 +5602,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
5602#ifdef EPOLL_SUPPORT 5602#ifdef EPOLL_SUPPORT
5603 if (-1 != daemon->worker_pool[i].epoll_fd) 5603 if (-1 != daemon->worker_pool[i].epoll_fd)
5604 MHD_fd_close_chk_ (daemon->worker_pool[i].epoll_fd); 5604 MHD_fd_close_chk_ (daemon->worker_pool[i].epoll_fd);
5605#if HTTPS_SUPPORT 5605#ifdef HTTPS_SUPPORT
5606 if (-1 != daemon->worker_pool[i].epoll_upgrade_fd) 5606 if (-1 != daemon->worker_pool[i].epoll_upgrade_fd)
5607 MHD_fd_close_chk_ (daemon->worker_pool[i].epoll_upgrade_fd); 5607 MHD_fd_close_chk_ (daemon->worker_pool[i].epoll_upgrade_fd);
5608#endif 5608#endif /* HTTPS_SUPPORT */
5609#endif 5609#endif
5610 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].itc) ) 5610 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].itc) )
5611 MHD_itc_destroy_chk_ (daemon->worker_pool[i].itc); 5611 MHD_itc_destroy_chk_ (daemon->worker_pool[i].itc);
@@ -5651,15 +5651,15 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
5651 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 5651 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
5652 (-1 != daemon->epoll_fd) ) 5652 (-1 != daemon->epoll_fd) )
5653 MHD_socket_close_chk_ (daemon->epoll_fd); 5653 MHD_socket_close_chk_ (daemon->epoll_fd);
5654#if HTTPS_SUPPORT 5654#ifdef HTTPS_SUPPORT
5655 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 5655 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
5656 (-1 != daemon->epoll_upgrade_fd) ) 5656 (-1 != daemon->epoll_upgrade_fd) )
5657 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd); 5657 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd);
5658#endif 5658#endif /* HTTPS_SUPPORT */
5659#endif 5659#endif
5660 5660
5661 /* TLS clean up */ 5661 /* TLS clean up */
5662#if HTTPS_SUPPORT 5662#ifdef HTTPS_SUPPORT
5663 if (MHD_YES == daemon->have_dhparams) 5663 if (MHD_YES == daemon->have_dhparams)
5664 { 5664 {
5665 gnutls_dh_params_deinit (daemon->https_mem_dhparams); 5665 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
@@ -5671,7 +5671,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
5671 if (daemon->x509_cred) 5671 if (daemon->x509_cred)
5672 gnutls_certificate_free_credentials (daemon->x509_cred); 5672 gnutls_certificate_free_credentials (daemon->x509_cred);
5673 } 5673 }
5674#endif 5674#endif /* HTTPS_SUPPORT */
5675 5675
5676#ifdef DAUTH_SUPPORT 5676#ifdef DAUTH_SUPPORT
5677 free (daemon->nnc); 5677 free (daemon->nnc);
@@ -5810,17 +5810,17 @@ MHD_is_feature_supported(enum MHD_FEATURE feature)
5810 return MHD_NO; 5810 return MHD_NO;
5811#endif 5811#endif
5812 case MHD_FEATURE_SSL: 5812 case MHD_FEATURE_SSL:
5813#if HTTPS_SUPPORT 5813#ifdef HTTPS_SUPPORT
5814 return MHD_YES; 5814 return MHD_YES;
5815#else 5815#else /* ! HTTPS_SUPPORT */
5816 return MHD_NO; 5816 return MHD_NO;
5817#endif 5817#endif /* ! HTTPS_SUPPORT */
5818 case MHD_FEATURE_HTTPS_CERT_CALLBACK: 5818 case MHD_FEATURE_HTTPS_CERT_CALLBACK:
5819#if HTTPS_SUPPORT && GNUTLS_VERSION_MAJOR >= 3 5819#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_MAJOR >= 3
5820 return MHD_YES; 5820 return MHD_YES;
5821#else 5821#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */
5822 return MHD_NO; 5822 return MHD_NO;
5823#endif 5823#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_MAJOR < 3 */
5824 case MHD_FEATURE_IPv6: 5824 case MHD_FEATURE_IPv6:
5825#ifdef HAVE_INET6 5825#ifdef HAVE_INET6
5826 return MHD_YES; 5826 return MHD_YES;
@@ -5882,11 +5882,11 @@ MHD_is_feature_supported(enum MHD_FEATURE feature)
5882 return MHD_NO; 5882 return MHD_NO;
5883#endif 5883#endif
5884 case MHD_FEATURE_HTTPS_KEY_PASSWORD: 5884 case MHD_FEATURE_HTTPS_KEY_PASSWORD:
5885#if HTTPS_SUPPORT && GNUTLS_VERSION_NUMBER >= 0x030111 5885#if defined(HTTPS_SUPPORT) && GNUTLS_VERSION_NUMBER >= 0x030111
5886 return MHD_YES; 5886 return MHD_YES;
5887#else 5887#else /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */
5888 return MHD_NO; 5888 return MHD_NO;
5889#endif 5889#endif /* !HTTPS_SUPPORT || GNUTLS_VERSION_NUMBER < 0x030111 */
5890 case MHD_FEATURE_LARGE_FILE: 5890 case MHD_FEATURE_LARGE_FILE:
5891#if defined(HAVE___LSEEKI64) || defined(HAVE_LSEEK64) 5891#if defined(HAVE___LSEEKI64) || defined(HAVE_LSEEK64)
5892 return MHD_YES; 5892 return MHD_YES;
@@ -5904,7 +5904,7 @@ MHD_is_feature_supported(enum MHD_FEATURE feature)
5904} 5904}
5905 5905
5906 5906
5907#if HTTPS_SUPPORT && GCRYPT_VERSION_NUMBER < 0x010600 5907#if defined(HTTPS_SUPPORT) && GCRYPT_VERSION_NUMBER < 0x010600
5908#if defined(MHD_USE_POSIX_THREADS) 5908#if defined(MHD_USE_POSIX_THREADS)
5909GCRY_THREAD_OPTION_PTHREAD_IMPL; 5909GCRY_THREAD_OPTION_PTHREAD_IMPL;
5910#elif defined(MHD_W32_MUTEX_) 5910#elif defined(MHD_W32_MUTEX_)
@@ -5981,7 +5981,7 @@ MHD_init(void)
5981 if (2 != LOBYTE(wsd.wVersion) && 2 != HIBYTE(wsd.wVersion)) 5981 if (2 != LOBYTE(wsd.wVersion) && 2 != HIBYTE(wsd.wVersion))
5982 MHD_PANIC (_("Winsock version 2.2 is not available\n")); 5982 MHD_PANIC (_("Winsock version 2.2 is not available\n"));
5983#endif 5983#endif
5984#if HTTPS_SUPPORT 5984#ifdef HTTPS_SUPPORT
5985#if GCRYPT_VERSION_NUMBER < 0x010600 5985#if GCRYPT_VERSION_NUMBER < 0x010600
5986#if defined(MHD_USE_POSIX_THREADS) 5986#if defined(MHD_USE_POSIX_THREADS)
5987 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS, 5987 if (0 != gcry_control (GCRYCTL_SET_THREAD_CBS,
@@ -5998,7 +5998,7 @@ MHD_init(void)
5998 MHD_PANIC (_("libgcrypt is too old. MHD was compiled for libgcrypt 1.6.0 or newer\n")); 5998 MHD_PANIC (_("libgcrypt is too old. MHD was compiled for libgcrypt 1.6.0 or newer\n"));
5999#endif 5999#endif
6000 gnutls_global_init (); 6000 gnutls_global_init ();
6001#endif 6001#endif /* HTTPS_SUPPORT */
6002 MHD_monotonic_sec_counter_init(); 6002 MHD_monotonic_sec_counter_init();
6003} 6003}
6004 6004
@@ -6006,9 +6006,9 @@ MHD_init(void)
6006void 6006void
6007MHD_fini(void) 6007MHD_fini(void)
6008{ 6008{
6009#if HTTPS_SUPPORT 6009#ifdef HTTPS_SUPPORT
6010 gnutls_global_deinit (); 6010 gnutls_global_deinit ();
6011#endif 6011#endif /* HTTPS_SUPPORT */
6012#ifdef _WIN32 6012#ifdef _WIN32
6013 if (mhd_winsock_inited_) 6013 if (mhd_winsock_inited_)
6014 WSACleanup(); 6014 WSACleanup();