diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-02-14 04:46:37 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-02-14 04:46:37 +0100 |
commit | b14541751ff614f00867ceaf4c0fa21f7c484c58 (patch) | |
tree | d86b4a1237bf444ba6f5aa163586c3d2641283cb | |
parent | 0849d359802d7b02d188230bcda269b330b3b1f0 (diff) | |
download | libmicrohttpd-b14541751ff614f00867ceaf4c0fa21f7c484c58.tar.gz libmicrohttpd-b14541751ff614f00867ceaf4c0fa21f7c484c58.zip |
more work on new src/lib/
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/include/microhttpd2.h | 12 | ||||
-rw-r--r-- | src/lib/action_continue.c | 2 | ||||
-rw-r--r-- | src/lib/action_from_response.c | 4 | ||||
-rw-r--r-- | src/lib/action_suspend.c | 6 | ||||
-rw-r--r-- | src/lib/connection_options.c | 9 | ||||
-rw-r--r-- | src/lib/daemon_create.c | 9 | ||||
-rw-r--r-- | src/lib/daemon_options.c | 2 | ||||
-rw-r--r-- | src/lib/internal.h | 123 |
9 files changed, 122 insertions, 46 deletions
@@ -44,3 +44,4 @@ po/Makevars.template | |||
44 | po/POTFILES | 44 | po/POTFILES |
45 | po/configargs.stamp | 45 | po/configargs.stamp |
46 | **~ | 46 | **~ |
47 | doc/libmicrohttpd.log | ||
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index 4302d8ae..aa0fa0ae 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h | |||
@@ -2969,6 +2969,18 @@ MHD_set_panic_func (MHD_PanicCallback cb, | |||
2969 | void *cls); | 2969 | void *cls); |
2970 | 2970 | ||
2971 | 2971 | ||
2972 | /** | ||
2973 | * Process escape sequences ('%HH') Updates val in place; the | ||
2974 | * result should be UTF-8 encoded and cannot be larger than the input. | ||
2975 | * The result must also still be 0-terminated. | ||
2976 | * | ||
2977 | * @param val value to unescape (modified in the process) | ||
2978 | * @return length of the resulting val (`strlen(val)` may be | ||
2979 | * shorter afterwards due to elimination of escape sequences) | ||
2980 | */ | ||
2981 | _MHD_EXTERN size_t | ||
2982 | MHD_http_unescape (char *val); | ||
2983 | |||
2972 | 2984 | ||
2973 | /** | 2985 | /** |
2974 | * Types of information about MHD features, | 2986 | * Types of information about MHD features, |
diff --git a/src/lib/action_continue.c b/src/lib/action_continue.c index 84d98d9e..40cb4a12 100644 --- a/src/lib/action_continue.c +++ b/src/lib/action_continue.c | |||
@@ -37,6 +37,8 @@ static enum MHD_StatusCode | |||
37 | cont_action (void *cls, | 37 | cont_action (void *cls, |
38 | struct MHD_Request *request) | 38 | struct MHD_Request *request) |
39 | { | 39 | { |
40 | (void) cls; | ||
41 | (void) request; | ||
40 | /* not sure yet, but this function body may | 42 | /* not sure yet, but this function body may |
41 | just legitimately stay empty... */ | 43 | just legitimately stay empty... */ |
42 | return MHD_SC_OK; | 44 | return MHD_SC_OK; |
diff --git a/src/lib/action_from_response.c b/src/lib/action_from_response.c index 883fcb98..9c303e0c 100644 --- a/src/lib/action_from_response.c +++ b/src/lib/action_from_response.c | |||
@@ -80,8 +80,8 @@ response_action (void *cls, | |||
80 | request->response_write_position = response->total_size; | 80 | request->response_write_position = response->total_size; |
81 | } | 81 | } |
82 | if ( (MHD_REQUEST_HEADERS_PROCESSED == request->state) && | 82 | if ( (MHD_REQUEST_HEADERS_PROCESSED == request->state) && |
83 | (MHD_METHOD_POST == request->method) || | 83 | ( (MHD_METHOD_POST == request->method) || |
84 | (MHD_METHOD_PUT == request->method) ) | 84 | (MHD_METHOD_PUT == request->method) ) ) |
85 | { | 85 | { |
86 | /* response was queued "early", refuse to read body / footers or | 86 | /* response was queued "early", refuse to read body / footers or |
87 | further requests! */ | 87 | further requests! */ |
diff --git a/src/lib/action_suspend.c b/src/lib/action_suspend.c index 6ebaf02d..9e5e1301 100644 --- a/src/lib/action_suspend.c +++ b/src/lib/action_suspend.c | |||
@@ -37,6 +37,7 @@ static enum MHD_StatusCode | |||
37 | suspend_action (void *cls, | 37 | suspend_action (void *cls, |
38 | struct MHD_Request *request) | 38 | struct MHD_Request *request) |
39 | { | 39 | { |
40 | (void) cls; | ||
40 | struct MHD_Connection *connection = request->connection; | 41 | struct MHD_Connection *connection = request->connection; |
41 | struct MHD_Daemon *daemon = connection->daemon; | 42 | struct MHD_Daemon *daemon = connection->daemon; |
42 | 43 | ||
@@ -48,9 +49,10 @@ suspend_action (void *cls, | |||
48 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 49 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); |
49 | return MHD_SC_OK; | 50 | return MHD_SC_OK; |
50 | } | 51 | } |
51 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 52 | if (daemon->threading_model != MHD_TM_THREAD_PER_CONNECTION) |
52 | { | 53 | { |
53 | if (connection->connection_timeout == daemon->connection_timeout) | 54 | if (connection->connection_timeout == |
55 | daemon->connection_default_timeout) | ||
54 | XDLL_remove (daemon->normal_timeout_head, | 56 | XDLL_remove (daemon->normal_timeout_head, |
55 | daemon->normal_timeout_tail, | 57 | daemon->normal_timeout_tail, |
56 | connection); | 58 | connection); |
diff --git a/src/lib/connection_options.c b/src/lib/connection_options.c index 118da122..cbcbf0bb 100644 --- a/src/lib/connection_options.c +++ b/src/lib/connection_options.c | |||
@@ -50,7 +50,8 @@ MHD_connection_set_timeout (struct MHD_Connection *connection, | |||
50 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 50 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
51 | if (! connection->suspended) | 51 | if (! connection->suspended) |
52 | { | 52 | { |
53 | if (connection->connection_timeout == daemon->connection_timeout) | 53 | if (connection->connection_timeout == |
54 | daemon->connection_default_timeout) | ||
54 | XDLL_remove (daemon->normal_timeout_head, | 55 | XDLL_remove (daemon->normal_timeout_head, |
55 | daemon->normal_timeout_tail, | 56 | daemon->normal_timeout_tail, |
56 | connection); | 57 | connection); |
@@ -62,7 +63,8 @@ MHD_connection_set_timeout (struct MHD_Connection *connection, | |||
62 | connection->connection_timeout = (time_t) timeout_s; | 63 | connection->connection_timeout = (time_t) timeout_s; |
63 | if (! connection->suspended) | 64 | if (! connection->suspended) |
64 | { | 65 | { |
65 | if (connection->connection_timeout == daemon->connection_timeout) | 66 | if (connection->connection_timeout == |
67 | daemon->connection_default_timeout) | ||
66 | XDLL_insert (daemon->normal_timeout_head, | 68 | XDLL_insert (daemon->normal_timeout_head, |
67 | daemon->normal_timeout_tail, | 69 | daemon->normal_timeout_tail, |
68 | connection); | 70 | connection); |
@@ -97,7 +99,8 @@ MHD_update_last_activity_ (struct MHD_Connection *connection) | |||
97 | if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_model) | 99 | if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_model) |
98 | return; /* each connection has personal timeout */ | 100 | return; /* each connection has personal timeout */ |
99 | 101 | ||
100 | if (connection->connection_timeout != daemon->connection_timeout) | 102 | if (connection->connection_timeout != |
103 | daemon->connection_default_timeout) | ||
101 | return; /* custom timeout, no need to move it in "normal" DLL */ | 104 | return; /* custom timeout, no need to move it in "normal" DLL */ |
102 | 105 | ||
103 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 106 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
diff --git a/src/lib/daemon_create.c b/src/lib/daemon_create.c index 6d903677..f1042789 100644 --- a/src/lib/daemon_create.c +++ b/src/lib/daemon_create.c | |||
@@ -100,8 +100,7 @@ MHD_daemon_create (MHD_RequestCallback cb, | |||
100 | daemon->logger = &file_logger; | 100 | daemon->logger = &file_logger; |
101 | daemon->logger_cls = stderr; | 101 | daemon->logger_cls = stderr; |
102 | daemon->unescape_cb = &unescape_wrapper; | 102 | daemon->unescape_cb = &unescape_wrapper; |
103 | daemon->tls_ciphers = TLS_CIPHERS_DEFAULT; | 103 | daemon->connection_memory_limit_b = POOL_SIZE_DEFAULT; |
104 | daemon->connection_memory_limit_b = MHD_POOL_SIZE_DEFAULT; | ||
105 | daemon->connection_memory_increment_b = BUF_INC_SIZE_DEFAULT; | 104 | daemon->connection_memory_increment_b = BUF_INC_SIZE_DEFAULT; |
106 | #if ENABLE_DAUTH | 105 | #if ENABLE_DAUTH |
107 | daemon->digest_nc_length = DIGEST_NC_LENGTH_DEFAULT; | 106 | daemon->digest_nc_length = DIGEST_NC_LENGTH_DEFAULT; |
@@ -117,15 +116,15 @@ MHD_daemon_create (MHD_RequestCallback cb, | |||
117 | } | 116 | } |
118 | if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex)) | 117 | if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex)) |
119 | { | 118 | { |
120 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); | 119 | (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); |
121 | free (daemon); | 120 | free (daemon); |
122 | return NULL; | 121 | return NULL; |
123 | } | 122 | } |
124 | #ifdef DAUTH_SUPPORT | 123 | #ifdef DAUTH_SUPPORT |
125 | if (! MHD_mutex_init_ (&daemon->nnc_lock)) | 124 | if (! MHD_mutex_init_ (&daemon->nnc_lock)) |
126 | { | 125 | { |
127 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); | 126 | (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); |
128 | MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); | 127 | (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); |
129 | free (daemon); | 128 | free (daemon); |
130 | return NULL; | 129 | return NULL; |
131 | } | 130 | } |
diff --git a/src/lib/daemon_options.c b/src/lib/daemon_options.c index db0be522..640f70c8 100644 --- a/src/lib/daemon_options.c +++ b/src/lib/daemon_options.c | |||
@@ -644,7 +644,7 @@ void | |||
644 | MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon, | 644 | MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon, |
645 | unsigned int timeout_s) | 645 | unsigned int timeout_s) |
646 | { | 646 | { |
647 | daemon->connection_default_timeout_s = timeout_s; | 647 | daemon->connection_default_timeout = (time_t) timeout_s; |
648 | } | 648 | } |
649 | 649 | ||
650 | 650 | ||
diff --git a/src/lib/internal.h b/src/lib/internal.h index 7829efc4..4c3ceddc 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h | |||
@@ -33,6 +33,7 @@ | |||
33 | #include "microhttpd_tls.h" | 33 | #include "microhttpd_tls.h" |
34 | #include "mhd_assert.h" | 34 | #include "mhd_assert.h" |
35 | #include "mhd_compat.h" | 35 | #include "mhd_compat.h" |
36 | #include "mhd_mono_clock.h" | ||
36 | #include "memorypool.h" | 37 | #include "memorypool.h" |
37 | 38 | ||
38 | #ifdef HTTPS_SUPPORT | 39 | #ifdef HTTPS_SUPPORT |
@@ -748,34 +749,6 @@ struct MHD_Connection | |||
748 | struct MHD_Request request; | 749 | struct MHD_Request request; |
749 | 750 | ||
750 | /** | 751 | /** |
751 | * Is the connection suspended? | ||
752 | */ | ||
753 | bool suspended; | ||
754 | |||
755 | /** | ||
756 | * Is the connection wanting to resume? | ||
757 | */ | ||
758 | bool resuming; | ||
759 | |||
760 | /** | ||
761 | * Set to `true` if the thread has been joined. | ||
762 | */ | ||
763 | bool thread_joined; | ||
764 | |||
765 | /** | ||
766 | * true if #socket_fd is non-blocking, false otherwise. | ||
767 | */ | ||
768 | bool sk_nonblck; | ||
769 | |||
770 | /** | ||
771 | * Has this socket been closed for reading (i.e. other side closed | ||
772 | * the connection)? If so, we must completely close the connection | ||
773 | * once we are done sending our response (and stop trying to read | ||
774 | * from this socket). | ||
775 | */ | ||
776 | bool read_closed; | ||
777 | |||
778 | /** | ||
779 | * Length of the foreign address. | 752 | * Length of the foreign address. |
780 | */ | 753 | */ |
781 | socklen_t addr_len; | 754 | socklen_t addr_len; |
@@ -799,7 +772,6 @@ struct MHD_Connection | |||
799 | */ | 772 | */ |
800 | MHD_socket socket_fd; | 773 | MHD_socket socket_fd; |
801 | 774 | ||
802 | |||
803 | #ifdef EPOLL_SUPPORT | 775 | #ifdef EPOLL_SUPPORT |
804 | /** | 776 | /** |
805 | * What is the state of this socket in relation to epoll? | 777 | * What is the state of this socket in relation to epoll? |
@@ -807,11 +779,35 @@ struct MHD_Connection | |||
807 | enum MHD_EpollState epoll_state; | 779 | enum MHD_EpollState epoll_state; |
808 | #endif | 780 | #endif |
809 | 781 | ||
810 | 782 | /** | |
811 | }; | 783 | * Is the connection suspended? |
784 | */ | ||
785 | bool suspended; | ||
812 | 786 | ||
787 | /** | ||
788 | * Is the connection wanting to resume? | ||
789 | */ | ||
790 | bool resuming; | ||
813 | 791 | ||
792 | /** | ||
793 | * Set to `true` if the thread has been joined. | ||
794 | */ | ||
795 | bool thread_joined; | ||
796 | |||
797 | /** | ||
798 | * true if #socket_fd is non-blocking, false otherwise. | ||
799 | */ | ||
800 | bool sk_nonblck; | ||
814 | 801 | ||
802 | /** | ||
803 | * Has this socket been closed for reading (i.e. other side closed | ||
804 | * the connection)? If so, we must completely close the connection | ||
805 | * once we are done sending our response (and stop trying to read | ||
806 | * from this socket). | ||
807 | */ | ||
808 | bool read_closed; | ||
809 | |||
810 | }; | ||
815 | 811 | ||
816 | 812 | ||
817 | /** | 813 | /** |
@@ -1002,6 +998,35 @@ struct MHD_Daemon | |||
1002 | #endif /* UPGRADE_SUPPORT */ | 998 | #endif /* UPGRADE_SUPPORT */ |
1003 | #endif /* EPOLL_SUPPORT */ | 999 | #endif /* EPOLL_SUPPORT */ |
1004 | 1000 | ||
1001 | #ifdef DAUTH_SUPPORT | ||
1002 | |||
1003 | /** | ||
1004 | * Character array of random values. | ||
1005 | */ | ||
1006 | const char *digest_auth_random; | ||
1007 | |||
1008 | /** | ||
1009 | * An array that contains the map nonce-nc. | ||
1010 | */ | ||
1011 | struct MHD_NonceNc *nnc; | ||
1012 | |||
1013 | /** | ||
1014 | * A rw-lock for synchronizing access to @e nnc. | ||
1015 | */ | ||
1016 | MHD_mutex_ nnc_lock; | ||
1017 | |||
1018 | /** | ||
1019 | * Size of `digest_auth_random. | ||
1020 | */ | ||
1021 | size_t digest_auth_rand_size; | ||
1022 | |||
1023 | /** | ||
1024 | * Size of the nonce-nc array. | ||
1025 | */ | ||
1026 | unsigned int nonce_nc_size; | ||
1027 | |||
1028 | #endif | ||
1029 | |||
1005 | /** | 1030 | /** |
1006 | * Socket address to bind to for the listen socket. | 1031 | * Socket address to bind to for the listen socket. |
1007 | */ | 1032 | */ |
@@ -1024,9 +1049,13 @@ struct MHD_Daemon | |||
1024 | */ | 1049 | */ |
1025 | size_t listen_sa_len; | 1050 | size_t listen_sa_len; |
1026 | 1051 | ||
1052 | /** | ||
1053 | * Default size of the per-connection memory pool. | ||
1054 | */ | ||
1055 | #define POOL_SIZE_DEFAULT (32 * 1024) | ||
1027 | /** | 1056 | /** |
1028 | * Buffer size to use for each connection. Default | 1057 | * Buffer size to use for each connection. Default |
1029 | * is #MHD_POOL_SIZE_DEFAULT. | 1058 | * is #POOL_SIZE_DEFAULT. |
1030 | */ | 1059 | */ |
1031 | size_t connection_memory_limit_b; | 1060 | size_t connection_memory_limit_b; |
1032 | 1061 | ||
@@ -1108,7 +1137,7 @@ struct MHD_Daemon | |||
1108 | /** | 1137 | /** |
1109 | * Default timeout in seconds for idle connections. | 1138 | * Default timeout in seconds for idle connections. |
1110 | */ | 1139 | */ |
1111 | unsigned int connection_default_timeout_s; | 1140 | time_t connection_default_timeout; |
1112 | 1141 | ||
1113 | /** | 1142 | /** |
1114 | * Listen socket we should use, MHD_INVALID_SOCKET means | 1143 | * Listen socket we should use, MHD_INVALID_SOCKET means |
@@ -1116,6 +1145,34 @@ struct MHD_Daemon | |||
1116 | */ | 1145 | */ |
1117 | MHD_socket listen_socket; | 1146 | MHD_socket listen_socket; |
1118 | 1147 | ||
1148 | #ifdef EPOLL_SUPPORT | ||
1149 | /** | ||
1150 | * File descriptor associated with our epoll loop. | ||
1151 | */ | ||
1152 | int epoll_fd; | ||
1153 | |||
1154 | /** | ||
1155 | * true if the listen socket is in the 'epoll' set, | ||
1156 | * false if not. | ||
1157 | */ | ||
1158 | bool listen_socket_in_epoll; | ||
1159 | |||
1160 | #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) | ||
1161 | /** | ||
1162 | * File descriptor associated with the #run_epoll_for_upgrade() loop. | ||
1163 | * Only available if #MHD_USE_HTTPS_EPOLL_UPGRADE is set. | ||
1164 | */ | ||
1165 | int epoll_upgrade_fd; | ||
1166 | |||
1167 | /** | ||
1168 | * true if @e epoll_upgrade_fd is in the 'epoll' set, | ||
1169 | * false if not. | ||
1170 | */ | ||
1171 | bool upgrade_fd_in_epoll; | ||
1172 | #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ | ||
1173 | |||
1174 | #endif | ||
1175 | |||
1119 | /** | 1176 | /** |
1120 | * Inter-thread communication channel. | 1177 | * Inter-thread communication channel. |
1121 | */ | 1178 | */ |