aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-28 11:39:38 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-28 11:39:38 +0000
commitd1d5bf7cb9e99860fb0e9657b36436ac48690dbb (patch)
treefb10800c57a379129a1e1387646e4b641e25ae71 /src
parent54f9e798f2123d22c284f5ce55524018c8dea098 (diff)
downloadlibmicrohttpd-d1d5bf7cb9e99860fb0e9657b36436ac48690dbb.tar.gz
libmicrohttpd-d1d5bf7cb9e99860fb0e9657b36436ac48690dbb.zip
-introduce MHD_UNSIGNED_LONG_LONG, deprecate MHD_LONG_LONG, check for invalid options on start, document
Diffstat (limited to 'src')
-rw-r--r--src/daemon/connection.c12
-rw-r--r--src/daemon/daemon.c97
-rw-r--r--src/daemon/postprocessor.c9
-rw-r--r--src/examples/fileserver_example_external_select.c2
-rw-r--r--src/examples/post_example.c2
-rw-r--r--src/include/microhttpd.h23
-rw-r--r--src/testcurl/perf_get_concurrent.c2
7 files changed, 78 insertions, 69 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index 78627a8a..62c83ded 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -561,8 +561,8 @@ add_extra_headers (struct MHD_Connection *connection)
561 MHD_HTTP_HEADER_CONTENT_LENGTH)) 561 MHD_HTTP_HEADER_CONTENT_LENGTH))
562 { 562 {
563 SPRINTF (buf, 563 SPRINTF (buf,
564 "%" MHD_LONG_LONG_PRINTF "u", 564 MHD_UNSIGNED_LONG_LONG_PRINTF,
565 (unsigned MHD_LONG_LONG) connection->response->total_size); 565 (MHD_UNSIGNED_LONG_LONG) connection->response->total_size);
566 MHD_add_response_header (connection->response, 566 MHD_add_response_header (connection->response,
567 MHD_HTTP_HEADER_CONTENT_LENGTH, buf); 567 MHD_HTTP_HEADER_CONTENT_LENGTH, buf);
568 } 568 }
@@ -1517,11 +1517,11 @@ process_request_body (struct MHD_Connection *connection)
1517 return; 1517 return;
1518 } 1518 }
1519 if (processed > used) 1519 if (processed > used)
1520 mhd_panic (mhd_panic_cls, __FILE__, __LINE__, 1520 mhd_panic (mhd_panic_cls, __FILE__, __LINE__
1521#if HAVE_MESSAGES 1521#if HAVE_MESSAGES
1522 "API violation" 1522 , "API violation"
1523#else 1523#else
1524 NULL 1524 , NULL
1525#endif 1525#endif
1526 ); 1526 );
1527 if (processed != 0) 1527 if (processed != 0)
@@ -1771,7 +1771,7 @@ static void
1771parse_connection_headers (struct MHD_Connection *connection) 1771parse_connection_headers (struct MHD_Connection *connection)
1772{ 1772{
1773 const char *clen; 1773 const char *clen;
1774 unsigned MHD_LONG_LONG cval; 1774 MHD_UNSIGNED_LONG_LONG cval;
1775 struct MHD_Response *response; 1775 struct MHD_Response *response;
1776 const char *enc; 1776 const char *enc;
1777 char *end; 1777 char *end;
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 4246eecb..64ceaa26 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -1147,27 +1147,32 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1147 if (MHD_YES == need_fcntl) 1147 if (MHD_YES == need_fcntl)
1148 { 1148 {
1149 /* make socket non-inheritable */ 1149 /* make socket non-inheritable */
1150#if !WINDOWS 1150#if WINDOWS
1151 flags = fcntl (s, F_GETFD);
1152 if ( ( (-1 == flags) ||
1153 ( (flags != (flags | FD_CLOEXEC)) &&
1154 (0 != fcntl (s, F_SETFD, flags | FD_CLOEXEC)) ) ) )
1155#else
1156 DWORD dwFlags; 1151 DWORD dwFlags;
1157 if (!GetHandleInformation ((HANDLE) s, &dwFlags) || 1152 if (!GetHandleInformation ((HANDLE) s, &dwFlags) ||
1158 ((dwFlags != dwFlags & ~HANDLE_FLAG_INHERIT) && 1153 ((dwFlags != dwFlags & ~HANDLE_FLAG_INHERIT) &&
1159 !SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0))) 1154 !SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0)))
1160#endif
1161 { 1155 {
1162#if HAVE_MESSAGES 1156#if HAVE_MESSAGES
1163#if WINDOWS
1164 SetErrnoFromWinError (GetLastError ()); 1157 SetErrnoFromWinError (GetLastError ());
1158 MHD_DLOG (daemon,
1159 "Failed to make socket non-inheritable: %s\n",
1160 STRERROR (errno));
1165#endif 1161#endif
1162 }
1163#else
1164 flags = fcntl (s, F_GETFD);
1165 if ( ( (-1 == flags) ||
1166 ( (flags != (flags | FD_CLOEXEC)) &&
1167 (0 != fcntl (s, F_SETFD, flags | FD_CLOEXEC)) ) ) )
1168 {
1169#if HAVE_MESSAGES
1166 MHD_DLOG (daemon, 1170 MHD_DLOG (daemon,
1167 "Failed to make socket non-inheritable: %s\n", 1171 "Failed to make socket non-inheritable: %s\n",
1168 STRERROR (errno)); 1172 STRERROR (errno));
1169#endif 1173#endif
1170 } 1174 }
1175#endif
1171 } 1176 }
1172#if HAVE_MESSAGES 1177#if HAVE_MESSAGES
1173#if DEBUG_CONNECT 1178#if DEBUG_CONNECT
@@ -1249,7 +1254,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1249 */ 1254 */
1250int 1255int
1251MHD_get_timeout (struct MHD_Daemon *daemon, 1256MHD_get_timeout (struct MHD_Daemon *daemon,
1252 unsigned MHD_LONG_LONG *timeout) 1257 MHD_UNSIGNED_LONG_LONG *timeout)
1253{ 1258{
1254 time_t earliest_deadline; 1259 time_t earliest_deadline;
1255 time_t now; 1260 time_t now;
@@ -1266,17 +1271,18 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
1266 have_timeout = MHD_NO; 1271 have_timeout = MHD_NO;
1267 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 1272 for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
1268 { 1273 {
1269 if (0 != pos->connection_timeout) { 1274 if (0 != pos->connection_timeout)
1270 if (!have_timeout || 1275 {
1271 earliest_deadline > pos->last_activity + pos->connection_timeout) 1276 if (!have_timeout ||
1272 earliest_deadline = pos->last_activity + pos->connection_timeout; 1277 earliest_deadline > pos->last_activity + pos->connection_timeout)
1278 earliest_deadline = pos->last_activity + pos->connection_timeout;
1273#if HTTPS_SUPPORT 1279#if HTTPS_SUPPORT
1274 if ( (0 != (daemon->options & MHD_USE_SSL)) && 1280 if ( (0 != (daemon->options & MHD_USE_SSL)) &&
1275 (0 != gnutls_record_check_pending (pos->tls_session)) ) 1281 (0 != gnutls_record_check_pending (pos->tls_session)) )
1276 earliest_deadline = 0; 1282 earliest_deadline = 0;
1277#endif 1283#endif
1278 have_timeout = MHD_YES; 1284 have_timeout = MHD_YES;
1279 } 1285 }
1280 } 1286 }
1281 if (MHD_NO == have_timeout) 1287 if (MHD_NO == have_timeout)
1282 return MHD_NO; 1288 return MHD_NO;
@@ -1309,7 +1315,7 @@ MHD_select (struct MHD_Daemon *daemon,
1309 int max; 1315 int max;
1310 struct timeval timeout; 1316 struct timeval timeout;
1311 struct timeval *tv; 1317 struct timeval *tv;
1312 unsigned MHD_LONG_LONG ltimeout; 1318 MHD_UNSIGNED_LONG_LONG ltimeout;
1313 int ds; 1319 int ds;
1314 1320
1315 timeout.tv_sec = 0; 1321 timeout.tv_sec = 0;
@@ -1428,7 +1434,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1428 { 1434 {
1429 struct pollfd p[2 + num_connections]; 1435 struct pollfd p[2 + num_connections];
1430 struct MHD_Pollfd mp; 1436 struct MHD_Pollfd mp;
1431 unsigned MHD_LONG_LONG ltimeout; 1437 MHD_UNSIGNED_LONG_LONG ltimeout;
1432 unsigned int i; 1438 unsigned int i;
1433 int timeout; 1439 int timeout;
1434 unsigned int poll_server; 1440 unsigned int poll_server;
@@ -2073,11 +2079,24 @@ MHD_start_daemon_va (unsigned int options,
2073 int res_thread_create; 2079 int res_thread_create;
2074 int use_pipe; 2080 int use_pipe;
2075 2081
2082#ifndef HAVE_INET6
2083 if (0 != (options & MHD_USE_IPv6))
2084 return NULL;
2085#endif
2086#ifndef HAVE_POLL_H
2087 if (0 != (options & MHD_USE_POLL))
2088 return NULL;
2089#endif
2090#if ! HTTPS_SUPPORT
2091 if (0 != (options & MHD_USE_SSL))
2092 return NULL;
2093#endif
2076 if (NULL == dh) 2094 if (NULL == dh)
2077 return NULL; 2095 return NULL;
2078 if (NULL == (daemon = malloc (sizeof (struct MHD_Daemon)))) 2096 if (NULL == (daemon = malloc (sizeof (struct MHD_Daemon))))
2079 return NULL; 2097 return NULL;
2080 memset (daemon, 0, sizeof (struct MHD_Daemon)); 2098 memset (daemon, 0, sizeof (struct MHD_Daemon));
2099 /* try to open listen socket */
2081#if HTTPS_SUPPORT 2100#if HTTPS_SUPPORT
2082 if (0 != (options & MHD_USE_SSL)) 2101 if (0 != (options & MHD_USE_SSL))
2083 { 2102 {
@@ -2085,27 +2104,6 @@ MHD_start_daemon_va (unsigned int options,
2085 "NORMAL", 2104 "NORMAL",
2086 NULL); 2105 NULL);
2087 } 2106 }
2088#else
2089 if (0 != (options & MHD_USE_SSL))
2090 {
2091#if HAVE_MESSAGES
2092 MHD_DLOG (daemon,
2093 "HTTPS not supported\n");
2094#endif
2095 free (daemon);
2096 return NULL;
2097 }
2098#endif
2099#ifndef HAVE_POLL_H
2100 if (0 != (options & MHD_USE_POLL))
2101 {
2102#if HAVE_MESSAGES
2103 MHD_DLOG (daemon,
2104 "poll not supported\n");
2105#endif
2106 free (daemon);
2107 return NULL;
2108 }
2109#endif 2107#endif
2110 daemon->socket_fd = -1; 2108 daemon->socket_fd = -1;
2111 daemon->options = (enum MHD_OPTION) options; 2109 daemon->options = (enum MHD_OPTION) options;
@@ -2121,8 +2119,7 @@ MHD_start_daemon_va (unsigned int options,
2121 daemon->wpipe[0] = -1; 2119 daemon->wpipe[0] = -1;
2122 daemon->wpipe[1] = -1; 2120 daemon->wpipe[1] = -1;
2123#if HAVE_MESSAGES 2121#if HAVE_MESSAGES
2124 daemon->custom_error_log = 2122 daemon->custom_error_log = (MHD_LogCallback) &vfprintf;
2125 (void (*)(void *, const char *, va_list)) &vfprintf;
2126 daemon->custom_error_log_cls = stderr; 2123 daemon->custom_error_log_cls = stderr;
2127#endif 2124#endif
2128#ifdef HAVE_LISTEN_SHUTDOWN 2125#ifdef HAVE_LISTEN_SHUTDOWN
@@ -2178,7 +2175,6 @@ MHD_start_daemon_va (unsigned int options,
2178 free (daemon); 2175 free (daemon);
2179 return NULL; 2176 return NULL;
2180 } 2177 }
2181
2182#ifdef DAUTH_SUPPORT 2178#ifdef DAUTH_SUPPORT
2183 if (daemon->nonce_nc_size > 0) 2179 if (daemon->nonce_nc_size > 0)
2184 { 2180 {
@@ -2255,17 +2251,7 @@ MHD_start_daemon_va (unsigned int options,
2255 { 2251 {
2256 /* try to open listen socket */ 2252 /* try to open listen socket */
2257 if ((options & MHD_USE_IPv6) != 0) 2253 if ((options & MHD_USE_IPv6) != 0)
2258#if HAVE_INET6
2259 socket_fd = create_socket (PF_INET6, SOCK_STREAM, 0); 2254 socket_fd = create_socket (PF_INET6, SOCK_STREAM, 0);
2260#else
2261 {
2262#if HAVE_MESSAGES
2263 MHD_DLOG (daemon,
2264 "AF_INET6 not supported\n");
2265#endif
2266 goto free_and_fail;
2267 }
2268#endif
2269 else 2255 else
2270 socket_fd = create_socket (PF_INET, SOCK_STREAM, 0); 2256 socket_fd = create_socket (PF_INET, SOCK_STREAM, 0);
2271 if (-1 == socket_fd) 2257 if (-1 == socket_fd)
@@ -2479,10 +2465,11 @@ MHD_start_daemon_va (unsigned int options,
2479#if HAVE_PLIBC_FD 2465#if HAVE_PLIBC_FD
2480 if (SOCKET_ERROR == 2466 if (SOCKET_ERROR ==
2481 ioctlsocket (plibc_fd_get_handle (socket_fd), FIONBIO, &sk_flags)) 2467 ioctlsocket (plibc_fd_get_handle (socket_fd), FIONBIO, &sk_flags))
2468 goto thread_failed;
2482#else 2469#else
2483 if (ioctlsocket (socket_fd, FIONBIO, &sk_flags) == SOCKET_ERROR) 2470 if (ioctlsocket (socket_fd, FIONBIO, &sk_flags) == SOCKET_ERROR)
2484#endif // PLIBC_FD
2485 goto thread_failed; 2471 goto thread_failed;
2472#endif // PLIBC_FD
2486#endif // MINGW 2473#endif // MINGW
2487 2474
2488 /* Allocate memory for pooled objects */ 2475 /* Allocate memory for pooled objects */
diff --git a/src/daemon/postprocessor.c b/src/daemon/postprocessor.c
index 1f3cef5c..103e3cb7 100644
--- a/src/daemon/postprocessor.c
+++ b/src/daemon/postprocessor.c
@@ -58,10 +58,11 @@ enum PP_State
58 PP_Nested_PerformMarking, 58 PP_Nested_PerformMarking,
59 PP_Nested_ProcessEntryHeaders, 59 PP_Nested_ProcessEntryHeaders,
60 PP_Nested_ProcessValueToBoundary, 60 PP_Nested_ProcessValueToBoundary,
61 PP_Nested_PerformCleanup, 61 PP_Nested_PerformCleanup
62 62
63}; 63};
64 64
65
65enum RN_State 66enum RN_State
66{ 67{
67 /** 68 /**
@@ -90,9 +91,10 @@ enum RN_State
90 /** 91 /**
91 * Got a single dash, expect second dash. 92 * Got a single dash, expect second dash.
92 */ 93 */
93 RN_Dash2 = 4, 94 RN_Dash2 = 4
94}; 95};
95 96
97
96/** 98/**
97 * Bits for the globally known fields that 99 * Bits for the globally known fields that
98 * should not be deleted when we exit the 100 * should not be deleted when we exit the
@@ -104,9 +106,10 @@ enum NE_State
104 NE_content_name = 1, 106 NE_content_name = 1,
105 NE_content_type = 2, 107 NE_content_type = 2,
106 NE_content_filename = 4, 108 NE_content_filename = 4,
107 NE_content_transfer_encoding = 8, 109 NE_content_transfer_encoding = 8
108}; 110};
109 111
112
110/** 113/**
111 * Internal state of the post-processor. Note that the fields 114 * Internal state of the post-processor. Note that the fields
112 * are sorted by type to enable optimal packing by the compiler. 115 * are sorted by type to enable optimal packing by the compiler.
diff --git a/src/examples/fileserver_example_external_select.c b/src/examples/fileserver_example_external_select.c
index a7ab824a..7a562e98 100644
--- a/src/examples/fileserver_example_external_select.c
+++ b/src/examples/fileserver_example_external_select.c
@@ -110,7 +110,7 @@ main (int argc, char *const *argv)
110 fd_set ws; 110 fd_set ws;
111 fd_set es; 111 fd_set es;
112 int max; 112 int max;
113 unsigned MHD_LONG_LONG mhd_timeout; 113 MHD_UNSIGNED_LONG_LONG mhd_timeout;
114 114
115 if (argc != 3) 115 if (argc != 3)
116 { 116 {
diff --git a/src/examples/post_example.c b/src/examples/post_example.c
index 69091dc2..e70f7bf5 100644
--- a/src/examples/post_example.c
+++ b/src/examples/post_example.c
@@ -695,7 +695,7 @@ main (int argc, char *const *argv)
695 fd_set ws; 695 fd_set ws;
696 fd_set es; 696 fd_set es;
697 int max; 697 int max;
698 unsigned MHD_LONG_LONG mhd_timeout; 698 MHD_UNSIGNED_LONG_LONG mhd_timeout;
699 699
700 if (argc != 2) 700 if (argc != 2)
701 { 701 {
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 819ed6af..442c51f0 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -147,14 +147,22 @@ extern "C"
147 * standard int or a short. 147 * standard int or a short.
148 */ 148 */
149#ifndef MHD_LONG_LONG 149#ifndef MHD_LONG_LONG
150/**
151 * @deprecated use MHD_UNSIGNED_LONG_LONG instead!
152 */
150#define MHD_LONG_LONG long long 153#define MHD_LONG_LONG long long
154#define MHD_UNSIGNED_LONG_LONG unsigned long long
151#endif 155#endif
152#ifndef MHD_LONG_LONG_PRINTF
153/** 156/**
154 * Format string for printing a variable of type 'MHD_LONG_LONG'. 157 * Format string for printing a variable of type 'MHD_LONG_LONG'.
155 * You should only redefine this if you also define MHD_LONG_LONG. 158 * You should only redefine this if you also define MHD_LONG_LONG.
156 */ 159 */
160#ifndef MHD_LONG_LONG_PRINTF
161/**
162 * @deprecated use MHD_UNSIGNED_LONG_LONG_PRINTF instead!
163 */
157#define MHD_LONG_LONG_PRINTF "ll" 164#define MHD_LONG_LONG_PRINTF "ll"
165#define MHD_UNSIGNED_LONG_LONG_PRINTF "%llu"
158#endif 166#endif
159 167
160 168
@@ -390,6 +398,16 @@ enum MHD_FLAG
390 398
391 399
392/** 400/**
401 * Type of a callback function used for logging by MHD.
402 *
403 * @param cls closure
404 * @param fm format string (printf-style)
405 * @param ap arguments to 'fm'
406 */
407typedef void (*MHD_LogCallback)(void *cls, const char *fm, va_list ap);
408
409
410/**
393 * MHD options. Passed in the varargs portion of MHD_start_daemon. 411 * MHD options. Passed in the varargs portion of MHD_start_daemon.
394 */ 412 */
395enum MHD_OPTION 413enum MHD_OPTION
@@ -518,6 +536,7 @@ enum MHD_OPTION
518 * This option must be followed by two arguments; the 536 * This option must be followed by two arguments; the
519 * first must be a pointer to a function 537 * first must be a pointer to a function
520 * of type "void fun(void * arg, const char * fmt, va_list ap)" 538 * of type "void fun(void * arg, const char * fmt, va_list ap)"
539 * (also known as MHD_LogCallback)
521 * and the second a pointer "void*" which will 540 * and the second a pointer "void*" which will
522 * be passed as the "arg" argument to "fun". 541 * be passed as the "arg" argument to "fun".
523 * <p> 542 * <p>
@@ -1151,7 +1170,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
1151 * necessiate the use of a timeout right now). 1170 * necessiate the use of a timeout right now).
1152 */ 1171 */
1153int MHD_get_timeout (struct MHD_Daemon *daemon, 1172int MHD_get_timeout (struct MHD_Daemon *daemon,
1154 unsigned MHD_LONG_LONG *timeout); 1173 MHD_UNSIGNED_LONG_LONG *timeout);
1155 1174
1156 1175
1157/** 1176/**
diff --git a/src/testcurl/perf_get_concurrent.c b/src/testcurl/perf_get_concurrent.c
index 6781ec8d..1c68a657 100644
--- a/src/testcurl/perf_get_concurrent.c
+++ b/src/testcurl/perf_get_concurrent.c
@@ -282,7 +282,7 @@ testExternalGet (int port)
282 fd_set es; 282 fd_set es;
283 int max; 283 int max;
284 struct timeval tv; 284 struct timeval tv;
285 unsigned MHD_LONG_LONG tt; 285 MHD_UNSIGNED_LONG_LONG tt;
286 int tret; 286 int tret;
287 287
288 d = MHD_start_daemon (MHD_USE_DEBUG, 288 d = MHD_start_daemon (MHD_USE_DEBUG,