aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-08 23:38:07 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-08 23:38:07 +0200
commit89d2ef97322ff5276e9a437e616a1e07529e0b26 (patch)
treec556b686eb323ca61036d69774553056ac8e2361
parentde872dea2d88f183c3f434c694acdcdb373f639c (diff)
parentda0585902ce08aacf97f7711b85343d4d45c80fe (diff)
downloadlibmicrohttpd-89d2ef97322ff5276e9a437e616a1e07529e0b26.tar.gz
libmicrohttpd-89d2ef97322ff5276e9a437e616a1e07529e0b26.zip
define and use 'enum MHD_Result' (merge)
-rw-r--r--ChangeLog24
-rw-r--r--configure.ac8
-rwxr-xr-xcontrib/uncrustify_precommit2
-rw-r--r--doc/chapters/basicauthentication.inc4
-rw-r--r--doc/chapters/hellobrowser.inc4
-rw-r--r--doc/chapters/introduction.inc2
-rw-r--r--doc/chapters/largerpost.inc2
-rw-r--r--doc/chapters/responseheaders.inc6
-rw-r--r--doc/chapters/tlsauthentication.inc2
-rw-r--r--doc/examples/responseheaders.c2
-rw-r--r--doc/examples/sessions.c2
-rw-r--r--doc/libmicrohttpd.texi4
-rw-r--r--m4/libgcrypt.m42
-rw-r--r--m4/mhd_sys_extentions.m46
-rw-r--r--m4/pkg.m42
-rw-r--r--po/libmicrohttpd.pot2
-rw-r--r--src/examples/.gitignore1
-rw-r--r--src/examples/Makefile.am11
-rw-r--r--src/examples/demo.c2
-rw-r--r--src/examples/demo_https.c2
-rw-r--r--src/examples/msgs_i18n.c2
-rw-r--r--src/examples/post_example.c2
-rw-r--r--src/examples/websocket_threaded_example.c863
-rw-r--r--src/include/microhttpd.h22
-rw-r--r--src/include/microhttpd2.h16
-rw-r--r--src/lib/connection_add.c2
-rw-r--r--src/lib/connection_call_handlers.c2
-rw-r--r--src/lib/daemon_destroy.c2
-rw-r--r--src/lib/daemon_options.c8
-rw-r--r--src/lib/internal.h2
-rw-r--r--src/microhttpd/connection.c2
-rw-r--r--src/microhttpd/daemon.c2
-rw-r--r--src/microhttpd/digestauth.c4
-rw-r--r--src/microhttpd/internal.h2
-rw-r--r--src/microhttpd/memorypool.h2
-rw-r--r--src/microhttpd/mhd_bithelpers.h12
-rw-r--r--src/microhttpd/mhd_send.c8
-rw-r--r--src/microhttpd/test_md5.c8
-rw-r--r--src/microhttpd/test_sha256.c8
-rw-r--r--src/microhttpd/test_upgrade.c4
-rw-r--r--src/microhttpd/test_upgrade_large.c4
-rw-r--r--src/testcurl/https/test_empty_response.c2
-rw-r--r--src/testcurl/https/test_https_get_parallel.c4
-rw-r--r--src/testcurl/https/test_https_get_parallel_threads.c6
-rw-r--r--src/testcurl/https/tls_test_common.c2
45 files changed, 980 insertions, 101 deletions
diff --git a/ChangeLog b/ChangeLog
index 3ce14755..9fede6ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,12 @@ Wed 08 Apr 2020 10:53:01 PM CEST
6 the code more robust in the future. For conditional compilation, test 6 the code more robust in the future. For conditional compilation, test
7 for "MHD_VERSION >= 0x00097002". -CG 7 for "MHD_VERSION >= 0x00097002". -CG
8 8
9Tue 07 Apr 2020 02:58:39 PM BRT
10 Fixed #5501 (Added example for how to provide a tiny threaded websocket server). -SC
11
12Tue 31 Mar 2020 02:36:40 PM BRT
13 Fixed #6142 (applied several spelling fixes). -DKG/-SC
14
9Sat 07 Mar 2020 05:20:33 PM CET 15Sat 07 Mar 2020 05:20:33 PM CET
10 Fixed #6090 (misc. severe socket handling bugs on OS X). -CG 16 Fixed #6090 (misc. severe socket handling bugs on OS X). -CG
11 17
@@ -581,7 +587,7 @@ Sun Apr 23 20:05:44 CEST 2017
581 field names if MHD_USE_PEDANTIC_CHECKS is set. -CG 587 field names if MHD_USE_PEDANTIC_CHECKS is set. -CG
582 588
583Sun Apr 23 19:20:33 CEST 2017 589Sun Apr 23 19:20:33 CEST 2017
584 Replace remaining occurences of sprintf() with 590 Replace remaining occurrences of sprintf() with
585 MHD_snprintf_(). Thanks to Ram for pointing this out. -CG 591 MHD_snprintf_(). Thanks to Ram for pointing this out. -CG
586 592
587Sat Apr 22 20:39:00 MSK 2017 593Sat Apr 22 20:39:00 MSK 2017
@@ -1180,7 +1186,7 @@ Tue Dec 1 10:01:12 CET 2015
1180 1186
1181Wed Nov 25 17:02:53 CET 2015 1187Wed Nov 25 17:02:53 CET 2015
1182 Remove 200ms delay observable with keep-alive on Darwin 1188 Remove 200ms delay observable with keep-alive on Darwin
1183 and *BSD platfroms. -EG 1189 and *BSD platforms. -EG
1184 1190
1185Tue Nov 10 15:25:48 CET 2015 1191Tue Nov 10 15:25:48 CET 2015
1186 Fix issue with shutdown if connection was resumed just 1192 Fix issue with shutdown if connection was resumed just
@@ -1544,7 +1550,7 @@ Wed Mar 05 13:15:05 CET 2014
1544 Changed configure flag from '--disable-pipe' to 1550 Changed configure flag from '--disable-pipe' to
1545 '--enable-socketpair'. 1551 '--enable-socketpair'.
1546 Added configure flags '--disable-doc' and '--disable-examples'. 1552 Added configure flags '--disable-doc' and '--disable-examples'.
1547 Narrowed down extrenal lib specific compiler and linker flags 1553 Narrowed down external lib specific compiler and linker flags
1548 usage. -EG 1554 usage. -EG
1549 1555
1550Wed Feb 26 17:42:34 CET 2014 1556Wed Feb 26 17:42:34 CET 2014
@@ -1650,7 +1656,7 @@ Tue Dec 3 21:05:38 CET 2013
1650Fri Nov 29 20:17:03 CET 2013 1656Fri Nov 29 20:17:03 CET 2013
1651 Eliminating theoretical stack overflow by limiting length 1657 Eliminating theoretical stack overflow by limiting length
1652 of URIs in authentication headers to 32k (only applicable 1658 of URIs in authentication headers to 32k (only applicable
1653 if the application explicitly raised the memroy limits, 1659 if the application explicitly raised the memory limits,
1654 and only applies to MHD_digest_auth_check). Issue was 1660 and only applies to MHD_digest_auth_check). Issue was
1655 reported by Florian Weimer. -CG 1661 reported by Florian Weimer. -CG
1656 1662
@@ -1878,7 +1884,7 @@ Sun Mar 31 20:03:48 CEST 2013
1878 at ~1500 MB/s on this system). -CG 1884 at ~1500 MB/s on this system). -CG
1879 1885
1880Fri Mar 29 16:44:29 CET 2013 1886Fri Mar 29 16:44:29 CET 2013
1881 Renaming testcases to consistenly begin with test_; 1887 Renaming testcases to consistently begin with test_;
1882 Changing build system to build examples in doc/. 1888 Changing build system to build examples in doc/.
1883 Releasing libmicrohttpd 0.9.26. -CG 1889 Releasing libmicrohttpd 0.9.26. -CG
1884 1890
@@ -2598,11 +2604,11 @@ Sun May 17 03:29:46 MDT 2009
2598 2604
2599Fri May 15 11:00:20 MDT 2009 2605Fri May 15 11:00:20 MDT 2009
2600 Grow reserved read buffer more aggressively so that we are not 2606 Grow reserved read buffer more aggressively so that we are not
2601 needlessly stuck reading only a handfull of bytes in each iteration. -CG 2607 needlessly stuck reading only a handful of bytes in each iteration. -CG
2602 2608
2603Thu May 14 21:20:30 MDT 2009 2609Thu May 14 21:20:30 MDT 2009
2604 Fixed issue where the "NOTIFY_COMPLETED" handler could be called 2610 Fixed issue where the "NOTIFY_COMPLETED" handler could be called
2605 twice (if a socket error or timeout occured for a pipelined 2611 twice (if a socket error or timeout occurred for a pipelined
2606 connection after successfully completing a request and before 2612 connection after successfully completing a request and before
2607 the next request was successfully transmitted). This could 2613 the next request was successfully transmitted). This could
2608 confuse applications not expecting to see a connection "complete" 2614 confuse applications not expecting to see a connection "complete"
@@ -2766,7 +2772,7 @@ Sat Apr 12 15:14:05 MDT 2008
2766 Fixed a problem (introduced in 0.2.3) with handling very 2772 Fixed a problem (introduced in 0.2.3) with handling very
2767 large requests (the code did not return proper error code). 2773 large requests (the code did not return proper error code).
2768 If "--enable-messages" is specified, the code now includes 2774 If "--enable-messages" is specified, the code now includes
2769 reasonable default HTML webpages for various build-in 2775 reasonable default HTML webpages for various built-in
2770 errors (such as request too large and malformed requests). 2776 errors (such as request too large and malformed requests).
2771 Without that flag, the webpages returned will still be 2777 Without that flag, the webpages returned will still be
2772 empty. 2778 empty.
@@ -2892,7 +2898,7 @@ Sun Aug 26 03:11:46 MDT 2007
2892 HTTP 400 status back if this is violated). - CG 2898 HTTP 400 status back if this is violated). - CG
2893 2899
2894Tue Aug 21 01:01:46 MDT 2007 2900Tue Aug 21 01:01:46 MDT 2007
2895 Fixing assertion failure that occured when a client 2901 Fixing assertion failure that occurred when a client
2896 closed the connection after sending some data but 2902 closed the connection after sending some data but
2897 not the full headers. - CG 2903 not the full headers. - CG
2898 2904
diff --git a/configure.ac b/configure.ac
index 52789081..ae85dc0c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -243,7 +243,7 @@ AX_CHECK_COMPILE_FLAG([[-Werror=attributes]],
243 CFLAGS="$save_CFLAGS" 243 CFLAGS="$save_CFLAGS"
244 ], 244 ],
245 [[errattr_CFLAGS=""]], [], []) 245 [[errattr_CFLAGS=""]], [], [])
246AC_MSG_CHECKING([[for function inline keywords suppoted by $CC]]) 246AC_MSG_CHECKING([[for function inline keywords supported by $CC]])
247save_CFLAGS="$CFLAGS" 247save_CFLAGS="$CFLAGS"
248CFLAGS="$CFLAGS $errattr_CFLAGS" 248CFLAGS="$CFLAGS $errattr_CFLAGS"
249inln_prfx="none" 249inln_prfx="none"
@@ -319,7 +319,7 @@ AS_CASE(["$host_os"],
319 AC_MSG_RESULT([[$mhd_host_os]])], 319 AC_MSG_RESULT([[$mhd_host_os]])],
320 [*solaris*], 320 [*solaris*],
321 [AC_DEFINE_UNQUOTED(SOLARIS,1,[This is a Solaris system]) 321 [AC_DEFINE_UNQUOTED(SOLARIS,1,[This is a Solaris system])
322 AC_DEFINE_UNQUOTED(_REENTRANT,1,[Need with solaris or errno doesnt work]) 322 AC_DEFINE_UNQUOTED(_REENTRANT,1,[Need with solaris or errno does not work])
323 mhd_host_os='Solaris' 323 mhd_host_os='Solaris'
324 AC_MSG_RESULT([[$mhd_host_os]]) 324 AC_MSG_RESULT([[$mhd_host_os]])
325 AC_SEARCH_LIBS(gethostbyname, nsl) 325 AC_SEARCH_LIBS(gethostbyname, nsl)
@@ -525,7 +525,7 @@ AC_INCLUDES_DEFAULT
525 ) 525 )
526 ]) 526 ])
527 527
528 # Try to find how to set thread name for started thread - less convinent 528 # Try to find how to set thread name for started thread - less convenient
529 # than setting name by attributes. 529 # than setting name by attributes.
530 # If pthread_setname_np(3) is not declared, it's not possible to detect 530 # If pthread_setname_np(3) is not declared, it's not possible to detect
531 # form of pthread_setname_np(3) due to C "feature" "implicit declaration". 531 # form of pthread_setname_np(3) due to C "feature" "implicit declaration".
@@ -1095,7 +1095,7 @@ AC_INCLUDES_DEFAULT
1095 ]) 1095 ])
1096]) 1096])
1097 1097
1098AS_IF([[test -z "$use_itc"]], [AC_MSG_ERROR([[cannot find useable type of inter-thread communication]])]) 1098AS_IF([[test -z "$use_itc"]], [AC_MSG_ERROR([[cannot find usable type of inter-thread communication]])])
1099 1099
1100 1100
1101AC_CHECK_FUNCS_ONCE([accept4 gmtime_r memmem snprintf]) 1101AC_CHECK_FUNCS_ONCE([accept4 gmtime_r memmem snprintf])
diff --git a/contrib/uncrustify_precommit b/contrib/uncrustify_precommit
index fd29998c..24873330 100755
--- a/contrib/uncrustify_precommit
+++ b/contrib/uncrustify_precommit
@@ -30,6 +30,6 @@ if [ $RET = 1 ];
30then 30then
31 echo "Run" 31 echo "Run"
32 echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}" 32 echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}"
33 echo "before commiting." 33 echo "before committing."
34fi 34fi
35exit $RET 35exit $RET
diff --git a/doc/chapters/basicauthentication.inc b/doc/chapters/basicauthentication.inc
index bbdd3641..cfcc96ff 100644
--- a/doc/chapters/basicauthentication.inc
+++ b/doc/chapters/basicauthentication.inc
@@ -14,7 +14,7 @@ GET /picture.png?mypassword
14 14
15In the rare situation where the client is customized enough and the connection occurs 15In the rare situation where the client is customized enough and the connection occurs
16through secured lines (e.g., a embedded device directly attached to another via wire) 16through secured lines (e.g., a embedded device directly attached to another via wire)
17and where the ability to embedd a password in the URI or to pass on a URI with a 17and where the ability to embed a password in the URI or to pass on a URI with a
18password are desired, this can be a reasonable choice. 18password are desired, this can be a reasonable choice.
19 19
20But when it is assumed that the user connecting does so with an ordinary Internet browser, 20But when it is assumed that the user connecting does so with an ordinary Internet browser,
@@ -37,7 +37,7 @@ Initially, the pointer this parameter references is set by @emph{MHD} in the cal
37also be "remembered" on the next call (for the same connection). 37also be "remembered" on the next call (for the same connection).
38Thus, we will generate no response until the parameter is non-null---implying the callback was 38Thus, we will generate no response until the parameter is non-null---implying the callback was
39called before at least once. We do not need to share information between different calls of the callback, 39called before at least once. We do not need to share information between different calls of the callback,
40so we can set the parameter to any adress that is assured to be not null. The pointer to the 40so we can set the parameter to any address that is assured to be not null. The pointer to the
41@code{connection} structure will be pointing to a legal address, so we take this. 41@code{connection} structure will be pointing to a legal address, so we take this.
42 42
43The first time @code{answer_to_connection} is called, we will not even look at the headers. 43The first time @code{answer_to_connection} is called, we will not even look at the headers.
diff --git a/doc/chapters/hellobrowser.inc b/doc/chapters/hellobrowser.inc
index 983cfb6a..ac7a5fe1 100644
--- a/doc/chapters/hellobrowser.inc
+++ b/doc/chapters/hellobrowser.inc
@@ -116,7 +116,7 @@ information (which could be passed via the next parameter) so the next (sixth) p
116we do not need to pass extra options to the daemon so we just write the MHD_OPTION_END as the last parameter. 116we do not need to pass extra options to the daemon so we just write the MHD_OPTION_END as the last parameter.
117 117
118As the server daemon runs in the background in its own thread, the execution flow in our main 118As the server daemon runs in the background in its own thread, the execution flow in our main
119function will contine right after the call. Because of this, we must delay the execution flow in the 119function will continue right after the call. Because of this, we must delay the execution flow in the
120main thread or else the program will terminate prematurely. We let it pause in a processing-time 120main thread or else the program will terminate prematurely. We let it pause in a processing-time
121friendly manner by waiting for the enter key to be pressed. In the end, we stop the daemon so it can 121friendly manner by waiting for the enter key to be pressed. In the end, we stop the daemon so it can
122do its cleanup tasks. 122do its cleanup tasks.
@@ -161,7 +161,7 @@ right after the response has been transferred then. This is typically not what
161disables HTTP pipelining. The correct approach is to simply not queue a message on the first 161disables HTTP pipelining. The correct approach is to simply not queue a message on the first
162callback unless there is an error. The @code{void**} argument to the callback provides a location 162callback unless there is an error. The @code{void**} argument to the callback provides a location
163for storing information about the history of the connection; for the first call, the pointer 163for storing information about the history of the connection; for the first call, the pointer
164will point to NULL. A simplistic way to differenciate the first call from others is to check 164will point to NULL. A simplistic way to differentiate the first call from others is to check
165if the pointer is NULL and set it to a non-NULL value during the first call. 165if the pointer is NULL and set it to a non-NULL value during the first call.
166 166
167Both of these issues you will find addressed in the official @code{minimal_example.c} residing in 167Both of these issues you will find addressed in the official @code{minimal_example.c} residing in
diff --git a/doc/chapters/introduction.inc b/doc/chapters/introduction.inc
index 95caf9a5..2845d35b 100644
--- a/doc/chapters/introduction.inc
+++ b/doc/chapters/introduction.inc
@@ -19,5 +19,5 @@ built on similar systems.
19@section History 19@section History
20 20
21This tutorial was originally written by Sebastian Gerhardt for MHD 21This tutorial was originally written by Sebastian Gerhardt for MHD
220.4.0. It was slighly polished and updated to MHD 0.9.0 by Christian 220.4.0. It was slightly polished and updated to MHD 0.9.0 by Christian
23Grothoff. \ No newline at end of file 23Grothoff. \ No newline at end of file
diff --git a/doc/chapters/largerpost.inc b/doc/chapters/largerpost.inc
index 1f60028f..11479382 100644
--- a/doc/chapters/largerpost.inc
+++ b/doc/chapters/largerpost.inc
@@ -49,7 +49,7 @@ We want the server to report internal errors, such as memory shortage or file ac
49adequately. 49adequately.
50@verbatim 50@verbatim
51const char* servererrorpage 51const char* servererrorpage
52 = "<html><body>An internal server error has occured.</body></html>"; 52 = "<html><body>An internal server error has occurred.</body></html>";
53const char* fileexistspage 53const char* fileexistspage
54 = "<html><body>This file already exists.</body></html>"; 54 = "<html><body>This file already exists.</body></html>";
55@end verbatim 55@end verbatim
diff --git a/doc/chapters/responseheaders.inc b/doc/chapters/responseheaders.inc
index ece7ce1c..0b1c67e2 100644
--- a/doc/chapters/responseheaders.inc
+++ b/doc/chapters/responseheaders.inc
@@ -60,7 +60,7 @@ server side and if so, the client should be informed with @code{MHD_HTTP_INTERNA
60 /* error accessing file */ 60 /* error accessing file */
61 if (fd != -1) close (fd); 61 if (fd != -1) close (fd);
62 const char *errorstr = 62 const char *errorstr =
63 "<html><body>An internal server error has occured!\ 63 "<html><body>An internal server error has occurred!\
64 </body></html>"; 64 </body></html>";
65 response = 65 response =
66 MHD_create_response_from_buffer (strlen (errorstr), 66 MHD_create_response_from_buffer (strlen (errorstr),
@@ -79,7 +79,7 @@ server side and if so, the client should be informed with @code{MHD_HTTP_INTERNA
79 return MHD_NO; 79 return MHD_NO;
80 if (!ret) 80 if (!ret)
81 { 81 {
82 const char *errorstr = "<html><body>An internal server error has occured!\ 82 const char *errorstr = "<html><body>An internal server error has occurred!\
83 </body></html>"; 83 </body></html>";
84 84
85 if (buffer) free(buffer); 85 if (buffer) free(buffer);
@@ -120,7 +120,7 @@ But in the case of success a response will be constructed directly from the file
120@end verbatim 120@end verbatim
121@noindent 121@noindent
122 122
123Note that the response object will take care of closing the file desciptor for us. 123Note that the response object will take care of closing the file descriptor for us.
124 124
125Up to this point, there was little new. The actual novelty is that we enhance the header with the 125Up to this point, there was little new. The actual novelty is that we enhance the header with the
126meta data about the content. Aware of the field's name we want to add, it is as easy as that: 126meta data about the content. Aware of the field's name we want to add, it is as easy as that:
diff --git a/doc/chapters/tlsauthentication.inc b/doc/chapters/tlsauthentication.inc
index 8bdfa764..fdb3d920 100644
--- a/doc/chapters/tlsauthentication.inc
+++ b/doc/chapters/tlsauthentication.inc
@@ -65,7 +65,7 @@ main ()
65@end verbatim 65@end verbatim
66@noindent 66@noindent
67 67
68and then we point the @emph{MHD} daemon to it upon initalization. 68and then we point the @emph{MHD} daemon to it upon initialization.
69@verbatim 69@verbatim
70 70
71 daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_SSL, 71 daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_SSL,
diff --git a/doc/examples/responseheaders.c b/doc/examples/responseheaders.c
index 5c0580b6..f1cf939c 100644
--- a/doc/examples/responseheaders.c
+++ b/doc/examples/responseheaders.c
@@ -43,7 +43,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection,
43 (0 != fstat (fd, &sbuf)) ) 43 (0 != fstat (fd, &sbuf)) )
44 { 44 {
45 const char *errorstr = 45 const char *errorstr =
46 "<html><body>An internal server error has occured!\ 46 "<html><body>An internal server error has occurred!\
47 </body></html>"; 47 </body></html>";
48 /* error accessing file */ 48 /* error accessing file */
49 if (fd != -1) 49 if (fd != -1)
diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c
index adabc610..6d6cf5ba 100644
--- a/doc/examples/sessions.c
+++ b/doc/examples/sessions.c
@@ -557,7 +557,7 @@ post_iterator (void *cls,
557 * can be set with the MHD_OPTION_NOTIFY_COMPLETED). 557 * can be set with the MHD_OPTION_NOTIFY_COMPLETED).
558 * Initially, <tt>*con_cls</tt> will be NULL. 558 * Initially, <tt>*con_cls</tt> will be NULL.
559 * @return MHS_YES if the connection was handled successfully, 559 * @return MHS_YES if the connection was handled successfully,
560 * MHS_NO if the socket must be closed due to a serios 560 * MHS_NO if the socket must be closed due to a serious
561 * error while handling the request 561 * error while handling the request
562 */ 562 */
563static enum MHD_Result 563static enum MHD_Result
diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi
index e89f75ed..419cf44a 100644
--- a/doc/libmicrohttpd.texi
+++ b/doc/libmicrohttpd.texi
@@ -539,7 +539,7 @@ connections).
539Enable optimizations to aggressively improve performance. 539Enable optimizations to aggressively improve performance.
540 540
541Currently, the optimizations this option enables are based on 541Currently, the optimizations this option enables are based on
542opportunistic reads and writes. Bascially, MHD will simply try to 542opportunistic reads and writes. Basically, MHD will simply try to
543read or write or accept on a socket before checking that the socket is 543read or write or accept on a socket before checking that the socket is
544ready for IO using the event loop mechanism. As the sockets are 544ready for IO using the event loop mechanism. As the sockets are
545non-blocking, this may fail (at a loss of performance), but generally 545non-blocking, this may fail (at a loss of performance), but generally
@@ -1761,7 +1761,7 @@ will be set to the timeout (in milliseconds).
1761@end table 1761@end table
1762 1762
1763Return @code{MHD_YES} on success, @code{MHD_NO} if timeouts are not used 1763Return @code{MHD_YES} on success, @code{MHD_NO} if timeouts are not used
1764(or no connections exist that would necessiate the use of a timeout 1764(or no connections exist that would necessitate the use of a timeout
1765right now). 1765right now).
1766@end deftypefun 1766@end deftypefun
1767 1767
diff --git a/m4/libgcrypt.m4 b/m4/libgcrypt.m4
index d89fe113..dd167f81 100644
--- a/m4/libgcrypt.m4
+++ b/m4/libgcrypt.m4
@@ -15,7 +15,7 @@
15dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION, 15dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,
16dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) 16dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
17dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS. 17dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS.
18dnl MINIMUM-VERSION is a string with the version number optionalliy prefixed 18dnl MINIMUM-VERSION is a string with the version number optionally prefixed
19dnl with the API version to also check the API compatibility. Example: 19dnl with the API version to also check the API compatibility. Example:
20dnl a MINIMUM-VERSION of 1:1.2.5 won't pass the test unless the installed 20dnl a MINIMUM-VERSION of 1:1.2.5 won't pass the test unless the installed
21dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1. Using 21dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1. Using
diff --git a/m4/mhd_sys_extentions.m4 b/m4/mhd_sys_extentions.m4
index 51b8aeca..13da648e 100644
--- a/m4/mhd_sys_extentions.m4
+++ b/m4/mhd_sys_extentions.m4
@@ -333,7 +333,7 @@ ${mhd_mse_sys_features_src}
333 m4_ifblank([$1], [dnl 333 m4_ifblank([$1], [dnl
334 AH_TEMPLATE([[_XOPEN_SOURCE]], [Define to maximum value supported by system headers])dnl 334 AH_TEMPLATE([[_XOPEN_SOURCE]], [Define to maximum value supported by system headers])dnl
335 AH_TEMPLATE([[_XOPEN_SOURCE_EXTENDED]], [Define to 1 if _XOPEN_SOURCE is defined to value less than 500 ]dnl 335 AH_TEMPLATE([[_XOPEN_SOURCE_EXTENDED]], [Define to 1 if _XOPEN_SOURCE is defined to value less than 500 ]dnl
336 [and system headers requre this symbol])dnl 336 [and system headers require this symbol])dnl
337 AH_TEMPLATE([[_XOPEN_VERSION]], [Define to maximum value supported by system headers if _XOPEN_SOURCE ]dnl 337 AH_TEMPLATE([[_XOPEN_VERSION]], [Define to maximum value supported by system headers if _XOPEN_SOURCE ]dnl
338 [is defined to value less than 500 and headers do not support _XOPEN_SOURCE_EXTENDED])dnl 338 [is defined to value less than 500 and headers do not support _XOPEN_SOURCE_EXTENDED])dnl
339 AH_TEMPLATE([[_GNU_SOURCE]], [Define to 1 to enable GNU-related header features])dnl 339 AH_TEMPLATE([[_GNU_SOURCE]], [Define to 1 to enable GNU-related header features])dnl
@@ -436,8 +436,8 @@ AC_DEFUN([_MHD_CHECK_POSIX2008], [dnl
436 _MHD_CHECK_POSIX_FEATURES_SINGLE([ 436 _MHD_CHECK_POSIX_FEATURES_SINGLE([
437_MHD_BASIC_INCLUDES 437_MHD_BASIC_INCLUDES
438[ 438[
439/* Check will be passed if ALL features are avalable 439/* Check will be passed if ALL features are available
440 * and failed if ANY feature is not avalable. */ 440 * and failed if ANY feature is not available. */
441int main() 441int main()
442{ 442{
443 443
diff --git a/m4/pkg.m4 b/m4/pkg.m4
index 13a88901..f9075e56 100644
--- a/m4/pkg.m4
+++ b/m4/pkg.m4
@@ -86,7 +86,7 @@ dnl Check to see whether a particular set of modules exists. Similar to
86dnl PKG_CHECK_MODULES(), but does not set variables or print errors. 86dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
87dnl 87dnl
88dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 88dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
89dnl only at the first occurence in configure.ac, so if the first place 89dnl only at the first occurrence in configure.ac, so if the first place
90dnl it's called might be skipped (such as if it is within an "if", you 90dnl it's called might be skipped (such as if it is within an "if", you
91dnl have to call PKG_CHECK_EXISTS manually 91dnl have to call PKG_CHECK_EXISTS manually
92AC_DEFUN([PKG_CHECK_EXISTS], 92AC_DEFUN([PKG_CHECK_EXISTS],
diff --git a/po/libmicrohttpd.pot b/po/libmicrohttpd.pot
index b6df2361..e36cd81e 100644
--- a/po/libmicrohttpd.pot
+++ b/po/libmicrohttpd.pot
@@ -72,7 +72,7 @@ msgid "Authentication failed, arguments do not match.\n"
72msgstr "" 72msgstr ""
73 73
74#: src/microhttpd/digestauth.c:1281 74#: src/microhttpd/digestauth.c:1281
75msgid "digest size missmatch" 75msgid "digest size mismatch"
76msgstr "" 76msgstr ""
77 77
78#: src/microhttpd/digestauth.c:1374 78#: src/microhttpd/digestauth.c:1374
diff --git a/src/examples/.gitignore b/src/examples/.gitignore
index 7fa3e9b8..7a64ff40 100644
--- a/src/examples/.gitignore
+++ b/src/examples/.gitignore
@@ -32,6 +32,7 @@
32/https_echo_client_example.c 32/https_echo_client_example.c
33/authorization_example 33/authorization_example
34upgrade_example 34upgrade_example
35websocket_threaded_example
35/timeout 36/timeout
36http_chunked_compression 37http_chunked_compression
37http_compression 38http_compression
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index 5dcee4d2..1f0a65af 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -67,7 +67,8 @@ endif
67if HAVE_POSIX_THREADS 67if HAVE_POSIX_THREADS
68if ENABLE_UPGRADE 68if ENABLE_UPGRADE
69noinst_PROGRAMS += \ 69noinst_PROGRAMS += \
70 upgrade_example 70 upgrade_example \
71 websocket_threaded_example
71endif 72endif
72endif 73endif
73 74
@@ -104,6 +105,14 @@ upgrade_example_LDADD = \
104 $(top_builddir)/src/microhttpd/libmicrohttpd.la \ 105 $(top_builddir)/src/microhttpd/libmicrohttpd.la \
105 $(PTHREAD_LIBS) 106 $(PTHREAD_LIBS)
106 107
108websocket_threaded_example_SOURCES = \
109 websocket_threaded_example.c
110websocket_threaded_example_CFLAGS = \
111 $(PTHREAD_CFLAGS) $(AM_CFLAGS)
112websocket_threaded_example_LDADD = \
113 $(top_builddir)/src/microhttpd/libmicrohttpd.la \
114 $(PTHREAD_LIBS)
115
107timeout_SOURCES = \ 116timeout_SOURCES = \
108 timeout.c 117 timeout.c
109timeout_LDADD = \ 118timeout_LDADD = \
diff --git a/src/examples/demo.c b/src/examples/demo.c
index 978bd235..eb974d3a 100644
--- a/src/examples/demo.c
+++ b/src/examples/demo.c
@@ -204,7 +204,7 @@ static magic_t magic;
204 204
205 205
206/** 206/**
207 * Mark the given response as HTML for the brower. 207 * Mark the given response as HTML for the browser.
208 * 208 *
209 * @param response response to mark 209 * @param response response to mark
210 */ 210 */
diff --git a/src/examples/demo_https.c b/src/examples/demo_https.c
index 2a60fcda..6e42f3a5 100644
--- a/src/examples/demo_https.c
+++ b/src/examples/demo_https.c
@@ -207,7 +207,7 @@ static magic_t magic;
207 207
208 208
209/** 209/**
210 * Mark the given response as HTML for the brower. 210 * Mark the given response as HTML for the browser.
211 * 211 *
212 * @param response response to mark 212 * @param response response to mark
213 */ 213 */
diff --git a/src/examples/msgs_i18n.c b/src/examples/msgs_i18n.c
index e5f92bb5..56f9f501 100644
--- a/src/examples/msgs_i18n.c
+++ b/src/examples/msgs_i18n.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26/* 26/*
27 * suposing you are in Brazil: 27 * supposing you are in Brazil:
28 * 28 *
29 * # generate the PO file 29 * # generate the PO file
30 * $ msginit --input=po/libmicrohttpd.pot --locale=pt_BR --output=libmicrohttpd.po 30 * $ msginit --input=po/libmicrohttpd.pot --locale=pt_BR --output=libmicrohttpd.po
diff --git a/src/examples/post_example.c b/src/examples/post_example.c
index 55ca3aa8..9f4fbcf9 100644
--- a/src/examples/post_example.c
+++ b/src/examples/post_example.c
@@ -551,7 +551,7 @@ post_iterator (void *cls,
551 * can be set with the MHD_OPTION_NOTIFY_COMPLETED). 551 * can be set with the MHD_OPTION_NOTIFY_COMPLETED).
552 * Initially, <tt>*con_cls</tt> will be NULL. 552 * Initially, <tt>*con_cls</tt> will be NULL.
553 * @return MHS_YES if the connection was handled successfully, 553 * @return MHS_YES if the connection was handled successfully,
554 * MHS_NO if the socket must be closed due to a serios 554 * MHS_NO if the socket must be closed due to a serious
555 * error while handling the request 555 * error while handling the request
556 */ 556 */
557static enum MHD_Result 557static enum MHD_Result
diff --git a/src/examples/websocket_threaded_example.c b/src/examples/websocket_threaded_example.c
new file mode 100644
index 00000000..69abb0f3
--- /dev/null
+++ b/src/examples/websocket_threaded_example.c
@@ -0,0 +1,863 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2020 Christian Grothoff (and other contributing authors)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 USA
19*/
20
21/**
22 * @file websocket_threaded_example.c
23 * @brief example for how to provide a tiny threaded websocket server
24 * @author Silvio Clecio (silvioprog)
25 */
26
27#include "platform.h"
28#include <pthread.h>
29#include <microhttpd.h>
30
31#define CHAT_PAGE \
32 "<html>\n" \
33 "<head>\n" \
34 "<title>WebSocket chat</title>\n" \
35 "<script>\n" \
36 "document.addEventListener('DOMContentLoaded', function() {\n" \
37 " const ws = new WebSocket('ws://' + window.location.host);\n" \
38 " const btn = document.getElementById('send');\n" \
39 " const msg = document.getElementById('msg');\n" \
40 " const log = document.getElementById('log');\n" \
41 " ws.onopen = function() {\n" \
42 " log.value += 'Connected\\n';\n" \
43 " };\n" \
44 " ws.onclose = function() {\n" \
45 " log.value += 'Disconnected\\n';\n" \
46 " };\n" \
47 " ws.onmessage = function(ev) {\n" \
48 " log.value += ev.data + '\\n';\n" \
49 " };\n" \
50 " btn.onclick = function() {\n" \
51 " log.value += '<You>: ' + msg.value + '\\n';\n" \
52 " ws.send(msg.value);\n" \
53 " };\n" \
54 " msg.onkeyup = function(ev) {\n" \
55 " if (ev.keyCode === 13) {\n" \
56 " ev.preventDefault();\n" \
57 " ev.stopPropagation();\n" \
58 " btn.click();\n" \
59 " msg.value = '';\n" \
60 " }\n" \
61 " };\n" \
62 "});\n" \
63 "</script>\n" \
64 "</head>\n" \
65 "<body>\n" \
66 "<input type='text' id='msg' autofocus/>\n" \
67 "<input type='button' id='send' value='Send' /><br /><br />\n" \
68 "<textarea id='log' rows='20' cols='28'></textarea>\n" \
69 "</body>\n" \
70 "</html>"
71#define BAD_REQUEST_PAGE \
72 "<html>\n" \
73 "<head>\n" \
74 "<title>WebSocket chat</title>\n" \
75 "</head>\n" \
76 "<body>\n" \
77 "Bad Request\n" \
78 "</body>\n" \
79 "</html>\n"
80#define UPGRADE_REQUIRED_PAGE \
81 "<html>\n" \
82 "<head>\n" \
83 "<title>WebSocket chat</title>\n" \
84 "</head>\n" \
85 "<body>\n" \
86 "Upgrade required\n" \
87 "</body>\n" \
88 "</html>\n"
89
90#define WS_SEC_WEBSOCKET_VERSION "13"
91#define WS_UPGRADE_VALUE "websocket"
92#define WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
93#define WS_GUID_LEN 36
94#define WS_KEY_LEN 24
95#define WS_KEY_GUID_LEN ((WS_KEY_LEN) + (WS_GUID_LEN))
96#define WS_FIN 128
97#define WS_OPCODE_TEXT_FRAME 1
98#define WS_OPCODE_CON_CLOSE_FRAME 8
99
100#define MAX_CLIENTS 10
101
102static int CLIENT_SOCKS[MAX_CLIENTS];
103
104static pthread_mutex_t MUTEX = PTHREAD_MUTEX_INITIALIZER;
105
106struct WsData
107{
108 struct MHD_UpgradeResponseHandle *urh;
109 MHD_socket sock;
110};
111
112/********** begin SHA-1 **********/
113
114#define SHA1HashSize 20
115
116#define SHA1CircularShift(bits, word) \
117 (((word) << (bits)) | ((word) >> (32 - (bits))))
118
119enum SHA1_RESULT
120{
121 SHA1_RESULT_SUCCESS = 0,
122 SHA1_RESULT_NULL = 1,
123 SHA1_RESULT_STATE_ERROR = 2
124};
125
126struct SHA1Context
127{
128 uint32_t intermediate_hash[SHA1HashSize / 4];
129 uint32_t length_low;
130 uint32_t length_high;
131 int_least16_t message_block_index;
132 uint8_t message_block[64];
133 int computed;
134 int corrupted;
135};
136
137static void
138SHA1ProcessMessageBlock (struct SHA1Context *context)
139{
140 const uint32_t K[] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 };
141 int i;
142 uint32_t temp;
143 uint32_t W[80];
144 uint32_t A, B, C, D, E;
145 for (i = 0; i < 16; i++)
146 {
147 W[i] = context->message_block[i * 4] << 24;
148 W[i] |= context->message_block[i * 4 + 1] << 16;
149 W[i] |= context->message_block[i * 4 + 2] << 8;
150 W[i] |= context->message_block[i * 4 + 3];
151 }
152 for (i = 16; i < 80; i++)
153 {
154 W[i]
155 = SHA1CircularShift (1, W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]);
156 }
157 A = context->intermediate_hash[0];
158 B = context->intermediate_hash[1];
159 C = context->intermediate_hash[2];
160 D = context->intermediate_hash[3];
161 E = context->intermediate_hash[4];
162 for (i = 0; i < 20; i++)
163 {
164 temp = SHA1CircularShift (5, A) + ((B & C) | ((~B) & D)) + E + W[i]
165 + K[0];
166 E = D;
167 D = C;
168 C = SHA1CircularShift (30, B);
169 B = A;
170 A = temp;
171 }
172 for (i = 20; i < 40; i++)
173 {
174 temp = SHA1CircularShift (5, A) + (B ^ C ^ D) + E + W[i] + K[1];
175 E = D;
176 D = C;
177 C = SHA1CircularShift (30, B);
178 B = A;
179 A = temp;
180 }
181 for (i = 40; i < 60; i++)
182 {
183 temp = SHA1CircularShift (5, A) + ((B & C) | (B & D) | (C & D)) + E
184 + W[i] + K[2];
185 E = D;
186 D = C;
187 C = SHA1CircularShift (30, B);
188 B = A;
189 A = temp;
190 }
191 for (i = 60; i < 80; i++)
192 {
193 temp = SHA1CircularShift (5, A) + (B ^ C ^ D) + E + W[i] + K[3];
194 E = D;
195 D = C;
196 C = SHA1CircularShift (30, B);
197 B = A;
198 A = temp;
199 }
200 context->intermediate_hash[0] += A;
201 context->intermediate_hash[1] += B;
202 context->intermediate_hash[2] += C;
203 context->intermediate_hash[3] += D;
204 context->intermediate_hash[4] += E;
205 context->message_block_index = 0;
206}
207
208
209static void
210SHA1PadMessage (struct SHA1Context *context)
211{
212 if (context->message_block_index > 55)
213 {
214 context->message_block[context->message_block_index++] = 0x80;
215 while (context->message_block_index < 64)
216 {
217 context->message_block[context->message_block_index++] = 0;
218 }
219 SHA1ProcessMessageBlock (context);
220 while (context->message_block_index < 56)
221 {
222 context->message_block[context->message_block_index++] = 0;
223 }
224 }
225 else
226 {
227 context->message_block[context->message_block_index++] = 0x80;
228 while (context->message_block_index < 56)
229 {
230 context->message_block[context->message_block_index++] = 0;
231 }
232 }
233 context->message_block[56] = context->length_high >> 24;
234 context->message_block[57] = context->length_high >> 16;
235 context->message_block[58] = context->length_high >> 8;
236 context->message_block[59] = context->length_high;
237 context->message_block[60] = context->length_low >> 24;
238 context->message_block[61] = context->length_low >> 16;
239 context->message_block[62] = context->length_low >> 8;
240 context->message_block[63] = context->length_low;
241 SHA1ProcessMessageBlock (context);
242}
243
244
245static enum SHA1_RESULT
246SHA1Reset (struct SHA1Context *context)
247{
248 if (! context)
249 {
250 return SHA1_RESULT_NULL;
251 }
252 context->length_low = 0;
253 context->length_high = 0;
254 context->message_block_index = 0;
255 context->intermediate_hash[0] = 0x67452301;
256 context->intermediate_hash[1] = 0xEFCDAB89;
257 context->intermediate_hash[2] = 0x98BADCFE;
258 context->intermediate_hash[3] = 0x10325476;
259 context->intermediate_hash[4] = 0xC3D2E1F0;
260 context->computed = 0;
261 context->corrupted = 0;
262 return SHA1_RESULT_SUCCESS;
263}
264
265
266static enum SHA1_RESULT
267SHA1Result (struct SHA1Context *context, uint8_t Message_Digest[SHA1HashSize])
268{
269 int i;
270 if (! context || ! Message_Digest)
271 {
272 return SHA1_RESULT_NULL;
273 }
274 if (context->corrupted)
275 {
276 return context->corrupted;
277 }
278 if (! context->computed)
279 {
280 SHA1PadMessage (context);
281 for (i = 0; i < 64; ++i)
282 {
283 context->message_block[i] = 0;
284 }
285 context->length_low = 0;
286 context->length_high = 0;
287 context->computed = 1;
288 }
289 for (i = 0; i < SHA1HashSize; ++i)
290 {
291 Message_Digest[i]
292 = context->intermediate_hash[i >> 2] >> 8 * (3 - (i & 0x03));
293 }
294 return SHA1_RESULT_SUCCESS;
295}
296
297
298static enum SHA1_RESULT
299SHA1Input (struct SHA1Context *context, const uint8_t *message_array,
300 unsigned length)
301{
302 if (! length)
303 {
304 return SHA1_RESULT_SUCCESS;
305 }
306 if (! context || ! message_array)
307 {
308 return SHA1_RESULT_NULL;
309 }
310 if (context->computed)
311 {
312 context->corrupted = SHA1_RESULT_STATE_ERROR;
313 return SHA1_RESULT_STATE_ERROR;
314 }
315 if (context->corrupted)
316 {
317 return context->corrupted;
318 }
319 while (length-- && ! context->corrupted)
320 {
321 context->message_block[context->message_block_index++]
322 = (*message_array & 0xFF);
323 context->length_low += 8;
324 if (context->length_low == 0)
325 {
326 context->length_high++;
327 if (context->length_high == 0)
328 {
329 context->corrupted = 1;
330 }
331 }
332 if (context->message_block_index == 64)
333 {
334 SHA1ProcessMessageBlock (context);
335 }
336 message_array++;
337 }
338 return SHA1_RESULT_SUCCESS;
339}
340
341
342/********** end SHA-1 **********/
343
344/********** begin Base64 **********/
345
346ssize_t
347BASE64Encode (const void *in, size_t len, unsigned char **output)
348{
349#define FILLCHAR '='
350 const unsigned char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
351 "abcdefghijklmnopqrstuvwxyz"
352 "0123456789+/";
353 const unsigned char *data = in;
354 unsigned char *opt;
355 ssize_t ret;
356 ssize_t i;
357 char c;
358 ret = 0;
359 opt = malloc (2 + (len * 4 / 3) + 8);
360 if (NULL == opt)
361 {
362 return -1;
363 }
364 for (i = 0; i < len; ++i)
365 {
366 c = (data[i] >> 2) & 0x3F;
367 opt[ret++] = cvt[(unsigned int) c];
368 c = (data[i] << 4) & 0x3F;
369 if (++i < len)
370 {
371 c |= (data[i] >> 4) & 0x0F;
372 }
373 opt[ret++] = cvt[(unsigned int) c];
374 if (i < len)
375 {
376 c = (data[i] << 2) & 0x3F;
377 if (++i < len)
378 {
379 c |= (data[i] >> 6) & 0x03;
380 }
381 opt[ret++] = cvt[(unsigned int) c];
382 }
383 else
384 {
385 ++i;
386 opt[ret++] = FILLCHAR;
387 }
388 if (i < len)
389 {
390 c = data[i] & 0x3F;
391 opt[ret++] = cvt[(unsigned int) c];
392 }
393 else
394 {
395 opt[ret++] = FILLCHAR;
396 }
397 }
398 *output = opt;
399 return ret;
400}
401
402
403/********** end Base64 **********/
404
405static int
406is_websocket_request (struct MHD_Connection *con, const char *upg_header,
407 const char *con_header)
408{
409 return (upg_header != NULL) && (con_header != NULL)
410 && (0 == strcmp (upg_header, WS_UPGRADE_VALUE))
411 && (NULL != strstr (con_header, "Upgrade"))
412 ? MHD_YES
413 : MHD_NO;
414}
415
416
417static int
418send_chat_page (struct MHD_Connection *con, uint16_t port)
419{
420 struct MHD_Response *res;
421 int ret;
422 res = MHD_create_response_from_buffer (strlen (CHAT_PAGE), (void *) CHAT_PAGE,
423 MHD_RESPMEM_PERSISTENT);
424 ret = MHD_queue_response (con, MHD_HTTP_OK, res);
425 MHD_destroy_response (res);
426 return ret;
427}
428
429
430static int
431send_bad_request (struct MHD_Connection *con)
432{
433 struct MHD_Response *res;
434 int ret;
435 res = MHD_create_response_from_buffer (strlen (BAD_REQUEST_PAGE),
436 (void *) BAD_REQUEST_PAGE,
437 MHD_RESPMEM_PERSISTENT);
438 ret = MHD_queue_response (con, MHD_HTTP_BAD_REQUEST, res);
439 MHD_destroy_response (res);
440 return ret;
441}
442
443
444static int
445send_upgrade_required (struct MHD_Connection *con)
446{
447 struct MHD_Response *res;
448 int ret;
449 res = MHD_create_response_from_buffer (strlen (UPGRADE_REQUIRED_PAGE),
450 (void *) UPGRADE_REQUIRED_PAGE,
451 MHD_RESPMEM_PERSISTENT);
452 MHD_add_response_header (res, MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION,
453 WS_SEC_WEBSOCKET_VERSION);
454 ret = MHD_queue_response (con, MHD_HTTP_UPGRADE_REQUIRED, res);
455 MHD_destroy_response (res);
456 return ret;
457}
458
459
460static int
461ws_get_accept_value (char *key, unsigned char **val)
462{
463 struct SHA1Context ctx;
464 unsigned char hash[SHA1HashSize];
465 char *str;
466 ssize_t len;
467 if (NULL == key)
468 {
469 return MHD_NO;
470 }
471 str = malloc (WS_KEY_LEN + WS_GUID_LEN + 1);
472 if (NULL == str)
473 {
474 return MHD_NO;
475 }
476 strcpy (str, key);
477 strcat (str, WS_GUID);
478 SHA1Reset (&ctx);
479 SHA1Input (&ctx, (const uint8_t *) str, WS_KEY_GUID_LEN);
480 SHA1Result (&ctx, hash);
481 free (str);
482 len = BASE64Encode (hash, SHA1HashSize, val);
483 if (-1 == len)
484 {
485 return MHD_NO;
486 }
487 (*val)[len] = '\0';
488 return MHD_YES;
489}
490
491
492static void
493make_blocking (MHD_socket fd)
494{
495#if defined(MHD_POSIX_SOCKETS)
496 int flags;
497 flags = fcntl (fd, F_GETFL);
498 if (-1 == flags)
499 return;
500 if ((flags & ~O_NONBLOCK) != flags)
501 if (-1 == fcntl (fd, F_SETFL, flags & ~O_NONBLOCK))
502 abort ();
503#elif defined(MHD_WINSOCK_SOCKETS)
504 unsigned long flags = 1;
505 ioctlsocket (fd, FIONBIO, &flags);
506#endif /* MHD_WINSOCK_SOCKETS */
507}
508
509
510static size_t
511send_all (MHD_socket sock, const char *buf, size_t len)
512{
513 ssize_t ret;
514 size_t off;
515 for (off = 0; off < len; off += ret)
516 {
517 ret = send (sock, &buf[off], len - off, 0);
518 if (0 > ret)
519 {
520 if (EAGAIN == errno)
521 {
522 ret = 0;
523 continue;
524 }
525 break;
526 }
527 if (0 == ret)
528 {
529 break;
530 }
531 }
532 return off;
533}
534
535
536static int
537ws_send_frame (int sock, const char *msg, size_t length)
538{
539 unsigned char *response;
540 unsigned char frame[10];
541 uint8_t idx_first_rdata;
542 int idx_response;
543 int output;
544 int isock;
545 int i;
546 frame[0] = (WS_FIN | WS_OPCODE_TEXT_FRAME);
547 if (length <= 125)
548 {
549 frame[1] = length & 0x7F;
550 idx_first_rdata = 2;
551 }
552 else if ((length >= 126) && (length <= 0xFFFF))
553 {
554 frame[1] = 126;
555 frame[2] = (length >> 8) & 0xFF;
556 frame[3] = length & 0xFF;
557 idx_first_rdata = 4;
558 }
559 else
560 {
561 frame[1] = 127;
562 frame[2] = (unsigned char) ((length >> 56) & 0xFF);
563 frame[3] = (unsigned char) ((length >> 48) & 0xFF);
564 frame[4] = (unsigned char) ((length >> 40) & 0xFF);
565 frame[5] = (unsigned char) ((length >> 32) & 0xFF);
566 frame[6] = (unsigned char) ((length >> 24) & 0xFF);
567 frame[7] = (unsigned char) ((length >> 16) & 0xFF);
568 frame[8] = (unsigned char) ((length >> 8) & 0xFF);
569 frame[9] = (unsigned char) (length & 0xFF);
570 idx_first_rdata = 10;
571 }
572 idx_response = 0;
573 response = malloc (idx_first_rdata + length + 1);
574 if (NULL == response)
575 {
576 return -1;
577 }
578 for (i = 0; i < idx_first_rdata; i++)
579 {
580 response[i] = frame[i];
581 idx_response++;
582 }
583 for (i = 0; i < length; i++)
584 {
585 response[idx_response] = msg[i];
586 idx_response++;
587 }
588 response[idx_response] = '\0';
589 output = 0;
590 pthread_mutex_lock (&MUTEX);
591 for (i = 0; i < MAX_CLIENTS; i++)
592 {
593 isock = CLIENT_SOCKS[i];
594 if ((isock > -1) && (isock != sock))
595 {
596 output += send_all (isock, response, idx_response);
597 }
598 }
599 pthread_mutex_unlock (&MUTEX);
600 free (response);
601 return output;
602}
603
604
605static unsigned char *
606ws_receive_frame (unsigned char *frame, ssize_t *length, int *type)
607{
608 unsigned char *msg;
609 uint8_t masks[4];
610 uint8_t mask;
611 uint8_t flength;
612 uint8_t idx_first_mask;
613 uint8_t idx_first_data;
614 ssize_t data_length;
615 int i;
616 int j;
617 msg = NULL;
618 if (frame[0] == (WS_FIN | WS_OPCODE_TEXT_FRAME))
619 {
620 *type = WS_OPCODE_TEXT_FRAME;
621 idx_first_mask = 2;
622 mask = frame[1];
623 flength = mask & 0x7F;
624 if (flength == 126)
625 {
626 idx_first_mask = 4;
627 }
628 else if (flength == 127)
629 {
630 idx_first_mask = 10;
631 }
632 idx_first_data = idx_first_mask + 4;
633 data_length = *length - idx_first_data;
634 masks[0] = frame[idx_first_mask + 0];
635 masks[1] = frame[idx_first_mask + 1];
636 masks[2] = frame[idx_first_mask + 2];
637 masks[3] = frame[idx_first_mask + 3];
638 msg = malloc (data_length + 1);
639 if (NULL != msg)
640 {
641 for (i = idx_first_data, j = 0; i < *length; i++, j++)
642 {
643 msg[j] = frame[i] ^ masks[j % 4];
644 }
645 *length = data_length;
646 msg[j] = '\0';
647 }
648 }
649 else if (frame[0] == (WS_FIN | WS_OPCODE_CON_CLOSE_FRAME))
650 {
651 *type = WS_OPCODE_CON_CLOSE_FRAME;
652 }
653 else
654 {
655 *type = frame[0] & 0x0F;
656 }
657 return msg;
658}
659
660
661static void *
662run_usock (void *cls)
663{
664 struct WsData *ws = cls;
665 struct MHD_UpgradeResponseHandle *urh = ws->urh;
666 unsigned char *msg;
667 unsigned char *text;
668 unsigned char client[20];
669 char buf[2048];
670 ssize_t got;
671 size_t size;
672 int type;
673 int sent;
674 int i;
675 make_blocking (ws->sock);
676 while (1)
677 {
678 got = recv (ws->sock, buf, sizeof (buf), 0);
679 if (0 >= got)
680 {
681 break;
682 }
683 msg = ws_receive_frame (buf, &got, &type);
684 if (NULL == msg)
685 {
686 break;
687 }
688 if (type == WS_OPCODE_TEXT_FRAME)
689 {
690 size = sprintf (client, "User#%d: ", ws->sock);
691 size += got;
692 text = malloc (size);
693 if (NULL != buf)
694 {
695 sprintf (text, "%s%s", client, msg);
696 sent = ws_send_frame (ws->sock, text, size);
697 }
698 else
699 {
700 sent = -1;
701 }
702 free (text);
703 free (msg);
704 if (-1 == sent)
705 {
706 break;
707 }
708 }
709 else
710 {
711 if (type == WS_OPCODE_CON_CLOSE_FRAME)
712 {
713 free (msg);
714 pthread_mutex_lock (&MUTEX);
715 for (i = 0; i < MAX_CLIENTS; i++)
716 {
717 if (CLIENT_SOCKS[i] == ws->sock)
718 {
719 CLIENT_SOCKS[i] = -1;
720 break;
721 }
722 }
723 pthread_mutex_unlock (&MUTEX);
724 break;
725 }
726 }
727 }
728 free (ws);
729 MHD_upgrade_action (urh, MHD_UPGRADE_ACTION_CLOSE);
730 return NULL;
731}
732
733
734static int
735uh_cb (void *cls, struct MHD_Connection *con, void *con_cls,
736 const char *extra_in, size_t extra_in_size, MHD_socket sock,
737 struct MHD_UpgradeResponseHandle *urh)
738{
739 struct WsData *ws;
740 pthread_t pt;
741 int sock_overflow;
742 int i;
743 (void) cls;
744 (void) con;
745 (void) con_cls;
746 sock_overflow = MHD_YES;
747 ws = malloc (sizeof (struct WsData));
748 if (NULL == ws)
749 abort ();
750 memset (ws, 0, sizeof (struct WsData));
751 ws->sock = sock;
752 ws->urh = urh;
753 pthread_mutex_lock (&MUTEX);
754 for (i = 0; i < MAX_CLIENTS; i++)
755 {
756 if (-1 == CLIENT_SOCKS[i])
757 {
758 CLIENT_SOCKS[i] = ws->sock;
759 sock_overflow = MHD_NO;
760 break;
761 }
762 }
763 if (sock_overflow)
764 {
765 free (ws);
766 MHD_upgrade_action (urh, MHD_UPGRADE_ACTION_CLOSE);
767 return;
768 }
769 pthread_mutex_unlock (&MUTEX);
770 if (0 != pthread_create (&pt, NULL, &run_usock, ws))
771 abort ();
772 /* Note that by detaching like this we make it impossible to ensure
773 a clean shutdown, as the we stop the daemon even if a worker thread
774 is still running. Alas, this is a simple example... */
775 pthread_detach (pt);
776}
777
778
779static int
780ahc_cb (void *cls, struct MHD_Connection *con, const char *url,
781 const char *method, const char *version, const char *upload_data,
782 size_t *upload_data_size, void **ptr)
783{
784 struct MHD_Response *res;
785 const char *upg_header;
786 const char *con_header;
787 const char *ws_version_header;
788 const char *ws_key_header;
789 char ws_ac_header[60];
790 char *ws_ac_value;
791 int ret;
792 (void) url;
793 (void) upload_data;
794 (void) upload_data_size;
795 if (NULL == *ptr)
796 {
797 *ptr = (void *) 1;
798 return MHD_YES;
799 }
800 *ptr = NULL;
801 upg_header = MHD_lookup_connection_value (con, MHD_HEADER_KIND,
802 MHD_HTTP_HEADER_UPGRADE);
803 con_header = MHD_lookup_connection_value (con, MHD_HEADER_KIND,
804 MHD_HTTP_HEADER_CONNECTION);
805 if (MHD_NO == is_websocket_request (con, upg_header, con_header))
806 {
807 return send_chat_page (con, *(uint16_t *) cls);
808 }
809 if ((0 != strcmp (method, MHD_HTTP_METHOD_GET))
810 || (0 != strcmp (version, MHD_HTTP_VERSION_1_1)))
811 {
812 return send_bad_request (con);
813 }
814 ws_version_header = MHD_lookup_connection_value (
815 con, MHD_HEADER_KIND, MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION);
816 if ((NULL == ws_version_header)
817 || (0 != strcmp (ws_version_header, WS_SEC_WEBSOCKET_VERSION)))
818 {
819 return send_upgrade_required (con);
820 }
821 ws_key_header = MHD_lookup_connection_value (
822 con, MHD_HEADER_KIND, MHD_HTTP_HEADER_SEC_WEBSOCKET_KEY);
823 if ((NULL == ws_key_header) || (strlen (ws_key_header) != 24))
824 {
825 return send_bad_request (con);
826 }
827 ret = ws_get_accept_value (ws_key_header, &ws_ac_value);
828 if (MHD_NO == ret)
829 {
830 return ret;
831 }
832 res = MHD_create_response_for_upgrade (&uh_cb, NULL);
833 MHD_add_response_header (res, MHD_HTTP_HEADER_UPGRADE, WS_UPGRADE_VALUE);
834 MHD_add_response_header (res, MHD_HTTP_HEADER_SEC_WEBSOCKET_ACCEPT,
835 ws_ac_value);
836 free (ws_ac_value);
837 ret = MHD_queue_response (con, MHD_HTTP_SWITCHING_PROTOCOLS, res);
838 MHD_destroy_response (res);
839 return ret;
840}
841
842
843int
844main (int argc, char *const *argv)
845{
846 struct MHD_Daemon *d;
847 uint16_t port;
848 if (argc != 2)
849 {
850 printf ("%s PORT\n", argv[0]);
851 return 1;
852 }
853 port = atoi (argv[1]);
854 d = MHD_start_daemon (MHD_ALLOW_UPGRADE | MHD_USE_AUTO_INTERNAL_THREAD
855 | MHD_USE_ERROR_LOG,
856 port, NULL, NULL, &ahc_cb, &port, MHD_OPTION_END);
857 if (NULL == d)
858 return 1;
859 memset (CLIENT_SOCKS, -1, sizeof (CLIENT_SOCKS));
860 (void) getc (stdin);
861 MHD_stop_daemon (d);
862 return 0;
863}
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index f0daa3df..00d4f9bd 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -43,7 +43,7 @@
43 * 43 *
44 * MHD understands POST data and is able to decode certain formats 44 * MHD understands POST data and is able to decode certain formats
45 * (at the moment only "application/x-www-form-urlencoded" and 45 * (at the moment only "application/x-www-form-urlencoded" and
46 * "mulitpart/formdata"). Unsupported encodings and large POST 46 * "multipart/formdata"). Unsupported encodings and large POST
47 * submissions may require the application to manually process 47 * submissions may require the application to manually process
48 * the stream, which is provided to the main application (and thus can be 48 * the stream, which is provided to the main application (and thus can be
49 * processed, just not conveniently by MHD). 49 * processed, just not conveniently by MHD).
@@ -132,7 +132,7 @@ typedef intptr_t ssize_t;
132 * Current version of the library. 132 * Current version of the library.
133 * 0x01093001 = 1.9.30-1. 133 * 0x01093001 = 1.9.30-1.
134 */ 134 */
135#define MHD_VERSION 0x00097001 135#define MHD_VERSION 0x00097002
136 136
137/** 137/**
138 * Operational results from MHD calls. 138 * Operational results from MHD calls.
@@ -530,7 +530,7 @@ MHD_get_reason_phrase_for (unsigned int code);
530/** 530/**
531 * Flag to be or-ed with MHD_HTTP status code for 531 * Flag to be or-ed with MHD_HTTP status code for
532 * SHOUTcast. This will cause the response to begin 532 * SHOUTcast. This will cause the response to begin
533 * with the SHOUTcast "ICY" line instad of "HTTP". 533 * with the SHOUTcast "ICY" line instead of "HTTP".
534 * @ingroup specialized 534 * @ingroup specialized
535 */ 535 */
536#define MHD_ICY_FLAG ((uint32_t) (((uint32_t) 1) << 31)) 536#define MHD_ICY_FLAG ((uint32_t) (((uint32_t) 1) << 31))
@@ -1570,7 +1570,7 @@ enum MHD_OPTION
1570 * of the buffer pointed to by the second argument in bytes. 1570 * of the buffer pointed to by the second argument in bytes.
1571 * Note that the application must ensure that the buffer of the 1571 * Note that the application must ensure that the buffer of the
1572 * second argument remains allocated and unmodified while the 1572 * second argument remains allocated and unmodified while the
1573 * deamon is running. 1573 * daemon is running.
1574 */ 1574 */
1575 MHD_OPTION_DIGEST_AUTH_RANDOM = 17, 1575 MHD_OPTION_DIGEST_AUTH_RANDOM = 17,
1576 1576
@@ -1636,7 +1636,7 @@ enum MHD_OPTION
1636 * If present and set to true, allow reusing address:port socket 1636 * If present and set to true, allow reusing address:port socket
1637 * (by using SO_REUSEPORT on most platform, or platform-specific ways). 1637 * (by using SO_REUSEPORT on most platform, or platform-specific ways).
1638 * If present and set to false, disallow reusing address:port socket 1638 * If present and set to false, disallow reusing address:port socket
1639 * (does nothing on most plaform, but uses SO_EXCLUSIVEADDRUSE on Windows). 1639 * (does nothing on most platform, but uses SO_EXCLUSIVEADDRUSE on Windows).
1640 * This option must be followed by a `unsigned int` argument. 1640 * This option must be followed by a `unsigned int` argument.
1641 */ 1641 */
1642 MHD_OPTION_LISTENING_ADDRESS_REUSE = 25, 1642 MHD_OPTION_LISTENING_ADDRESS_REUSE = 25,
@@ -2046,7 +2046,7 @@ enum MHD_ConnectionInfoType
2046 2046
2047/** 2047/**
2048 * Values of this enum are used to specify what 2048 * Values of this enum are used to specify what
2049 * information about a deamon is desired. 2049 * information about a daemon is desired.
2050 */ 2050 */
2051enum MHD_DaemonInfoType 2051enum MHD_DaemonInfoType
2052{ 2052{
@@ -2107,8 +2107,8 @@ enum MHD_DaemonInfoType
2107 * an error message and `abort()`. 2107 * an error message and `abort()`.
2108 * 2108 *
2109 * @param cls user specified value 2109 * @param cls user specified value
2110 * @param file where the error occured 2110 * @param file where the error occurred
2111 * @param line where the error occured 2111 * @param line where the error occurred
2112 * @param reason error detail, may be NULL 2112 * @param reason error detail, may be NULL
2113 * @ingroup logging 2113 * @ingroup logging
2114 */ 2114 */
@@ -2168,7 +2168,7 @@ typedef enum MHD_Result
2168 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED). 2168 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
2169 * Initially, `*con_cls` will be NULL. 2169 * Initially, `*con_cls` will be NULL.
2170 * @return #MHD_YES if the connection was handled successfully, 2170 * @return #MHD_YES if the connection was handled successfully,
2171 * #MHD_NO if the socket must be closed due to a serios 2171 * #MHD_NO if the socket must be closed due to a serious
2172 * error while handling the request 2172 * error while handling the request
2173 */ 2173 */
2174typedef enum MHD_Result 2174typedef enum MHD_Result
@@ -3348,7 +3348,7 @@ MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
3348 * Destroy a response object and associated resources. Note that 3348 * Destroy a response object and associated resources. Note that
3349 * libmicrohttpd may keep some of the resources around if the response 3349 * libmicrohttpd may keep some of the resources around if the response
3350 * is still in the queue for some clients, so the memory may not 3350 * is still in the queue for some clients, so the memory may not
3351 * necessarily be freed immediatley. 3351 * necessarily be freed immediately.
3352 * 3352 *
3353 * @param response response to destroy 3353 * @param response response to destroy
3354 * @ingroup response 3354 * @ingroup response
@@ -3584,7 +3584,7 @@ MHD_digest_auth_check2 (struct MHD_Connection *connection,
3584 * Uses #MHD_DIGEST_ALG_MD5 (for now, for backwards-compatibility). 3584 * Uses #MHD_DIGEST_ALG_MD5 (for now, for backwards-compatibility).
3585 * Note that this MAY change to #MHD_DIGEST_ALG_AUTO in the future. 3585 * Note that this MAY change to #MHD_DIGEST_ALG_AUTO in the future.
3586 * If you want to be sure you get MD5, use #MHD_digest_auth_check2() 3586 * If you want to be sure you get MD5, use #MHD_digest_auth_check2()
3587 * and specifiy MD5 explicitly. 3587 * and specify MD5 explicitly.
3588 * 3588 *
3589 * @param connection The MHD connection structure 3589 * @param connection The MHD connection structure
3590 * @param realm The realm presented to the client 3590 * @param realm The realm presented to the client
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
index 1262c7a8..7c1b5187 100644
--- a/src/include/microhttpd2.h
+++ b/src/include/microhttpd2.h
@@ -536,7 +536,7 @@ enum MHD_StatusCode
536 MHD_SC_TLS_DISABLED = 50000, 536 MHD_SC_TLS_DISABLED = 50000,
537 537
538 /** 538 /**
539 * The application attempted to setup TLS paramters before 539 * The application attempted to setup TLS parameters before
540 * enabling TLS. 540 * enabling TLS.
541 */ 541 */
542 MHD_SC_TLS_BACKEND_UNINITIALIZED = 50003, 542 MHD_SC_TLS_BACKEND_UNINITIALIZED = 50003,
@@ -1469,7 +1469,7 @@ enum MHD_Method
1469 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 1469 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
1470 * #MHD_HTTP_METHOD_PUT, etc.) 1470 * #MHD_HTTP_METHOD_PUT, etc.)
1471 * @return action how to proceed, NULL 1471 * @return action how to proceed, NULL
1472 * if the socket must be closed due to a serios 1472 * if the socket must be closed due to a serious
1473 * error while handling the request 1473 * error while handling the request
1474 */ 1474 */
1475typedef const struct MHD_Action * 1475typedef const struct MHD_Action *
@@ -2005,7 +2005,7 @@ MHD_NONNULL (1);
2005 * If present true, allow reusing address:port socket (by using 2005 * If present true, allow reusing address:port socket (by using
2006 * SO_REUSEPORT on most platform, or platform-specific ways). If 2006 * SO_REUSEPORT on most platform, or platform-specific ways). If
2007 * present and set to false, disallow reusing address:port socket 2007 * present and set to false, disallow reusing address:port socket
2008 * (does nothing on most plaform, but uses SO_EXCLUSIVEADDRUSE on 2008 * (does nothing on most platform, but uses SO_EXCLUSIVEADDRUSE on
2009 * Windows). 2009 * Windows).
2010 * Ineffective in conjunction with #MHD_daemon_listen_socket(). 2010 * Ineffective in conjunction with #MHD_daemon_listen_socket().
2011 * 2011 *
@@ -2124,7 +2124,7 @@ MHD_NONNULL (1);
2124 2124
2125/** 2125/**
2126 * Use SHOUTcast. This will cause the response to begin 2126 * Use SHOUTcast. This will cause the response to begin
2127 * with the SHOUTcast "ICY" line instad of "HTTP". 2127 * with the SHOUTcast "ICY" line instead of "HTTP".
2128 * 2128 *
2129 * @param daemon daemon to set SHOUTcast option for 2129 * @param daemon daemon to set SHOUTcast option for
2130 */ 2130 */
@@ -2566,7 +2566,7 @@ MHD_NONNULL (1);
2566/** 2566/**
2567 * Set random values to be used by the Digest Auth module. Note that 2567 * Set random values to be used by the Digest Auth module. Note that
2568 * the application must ensure that @a buf remains allocated and 2568 * the application must ensure that @a buf remains allocated and
2569 * unmodified while the deamon is running. 2569 * unmodified while the daemon is running.
2570 * 2570 *
2571 * @param daemon daemon to configure 2571 * @param daemon daemon to configure
2572 * @param buf_size number of bytes in @a buf 2572 * @param buf_size number of bytes in @a buf
@@ -3886,7 +3886,7 @@ MHD_NONNULL (1,3);
3886 3886
3887/** 3887/**
3888 * Values of this enum are used to specify what 3888 * Values of this enum are used to specify what
3889 * information about a deamon is desired. 3889 * information about a daemon is desired.
3890 */ 3890 */
3891enum MHD_DaemonInformationType 3891enum MHD_DaemonInformationType
3892{ 3892{
@@ -3996,8 +3996,8 @@ MHD_NONNULL (1,3);
3996 * an error message and `abort()`. 3996 * an error message and `abort()`.
3997 * 3997 *
3998 * @param cls user specified value 3998 * @param cls user specified value
3999 * @param file where the error occured 3999 * @param file where the error occurred
4000 * @param line where the error occured 4000 * @param line where the error occurred
4001 * @param reason error detail, may be NULL 4001 * @param reason error detail, may be NULL
4002 * @ingroup logging 4002 * @ingroup logging
4003 */ 4003 */
diff --git a/src/lib/connection_add.c b/src/lib/connection_add.c
index be75946d..878380ae 100644
--- a/src/lib/connection_add.c
+++ b/src/lib/connection_add.c
@@ -1044,7 +1044,7 @@ MHD_accept_connection_ (struct MHD_Daemon *daemon)
1044 { 1044 {
1045 const int err = MHD_socket_get_error_ (); 1045 const int err = MHD_socket_get_error_ ();
1046 1046
1047 /* This could be a common occurance with multiple worker threads */ 1047 /* This could be a common occurrence with multiple worker threads */
1048 if (MHD_SCKT_ERR_IS_ (err, 1048 if (MHD_SCKT_ERR_IS_ (err,
1049 MHD_SCKT_EINVAL_)) 1049 MHD_SCKT_EINVAL_))
1050 return MHD_SC_DAEMON_ALREADY_SHUTDOWN; /* can happen during shutdown, let's hope this is the cause... */ 1050 return MHD_SC_DAEMON_ALREADY_SHUTDOWN; /* can happen during shutdown, let's hope this is the cause... */
diff --git a/src/lib/connection_call_handlers.c b/src/lib/connection_call_handlers.c
index 148e6345..fa79952b 100644
--- a/src/lib/connection_call_handlers.c
+++ b/src/lib/connection_call_handlers.c
@@ -158,7 +158,7 @@ MHD_conn_init_static_ (void)
158 158
159 159
160/** 160/**
161 * A serious error occured, close the 161 * A serious error occurred, close the
162 * connection (and notify the application). 162 * connection (and notify the application).
163 * 163 *
164 * @param connection connection to close with error 164 * @param connection connection to close with error
diff --git a/src/lib/daemon_destroy.c b/src/lib/daemon_destroy.c
index 41e5c057..e40ff520 100644
--- a/src/lib/daemon_destroy.c
+++ b/src/lib/daemon_destroy.c
@@ -30,7 +30,7 @@
30/** 30/**
31 * Stop all worker threads from the worker pool. 31 * Stop all worker threads from the worker pool.
32 * 32 *
33 * @param daemon master daemon controling the workers 33 * @param daemon master daemon controlling the workers
34 */ 34 */
35static void 35static void
36stop_workers (struct MHD_Daemon *daemon) 36stop_workers (struct MHD_Daemon *daemon)
diff --git a/src/lib/daemon_options.c b/src/lib/daemon_options.c
index 04c9cb2f..fa84fe83 100644
--- a/src/lib/daemon_options.c
+++ b/src/lib/daemon_options.c
@@ -233,7 +233,7 @@ MHD_daemon_listen_backlog (struct MHD_Daemon *daemon,
233 * If present true, allow reusing address:port socket (by using 233 * If present true, allow reusing address:port socket (by using
234 * SO_REUSEPORT on most platform, or platform-specific ways). If 234 * SO_REUSEPORT on most platform, or platform-specific ways). If
235 * present and set to false, disallow reusing address:port socket 235 * present and set to false, disallow reusing address:port socket
236 * (does nothing on most plaform, but uses SO_EXCLUSIVEADDRUSE on 236 * (does nothing on most platform, but uses SO_EXCLUSIVEADDRUSE on
237 * Windows). 237 * Windows).
238 * Ineffective in conjunction with #MHD_daemon_listen_socket(). 238 * Ineffective in conjunction with #MHD_daemon_listen_socket().
239 * 239 *
@@ -248,7 +248,7 @@ MHD_daemon_listen_allow_address_reuse (struct MHD_Daemon *daemon)
248 248
249/** 249/**
250 * Use SHOUTcast. This will cause the response to begin 250 * Use SHOUTcast. This will cause the response to begin
251 * with the SHOUTcast "ICY" line instad of "HTTP". 251 * with the SHOUTcast "ICY" line instead of "HTTP".
252 * 252 *
253 * @param daemon daemon to set SHOUTcast option for 253 * @param daemon daemon to set SHOUTcast option for
254 */ 254 */
@@ -452,7 +452,7 @@ MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon,
452 452
453/** 453/**
454 * Memory pointer for the certificate (ca.pem) to be used by the 454 * Memory pointer for the certificate (ca.pem) to be used by the
455 * HTTPS daemon for client authentification. 455 * HTTPS daemon for client authentication.
456 * 456 *
457 * @param daemon daemon to configure tls for 457 * @param daemon daemon to configure tls for
458 * @param mem_trust memory pointer to the certificate 458 * @param mem_trust memory pointer to the certificate
@@ -707,7 +707,7 @@ MHD_daemon_unescape_cb (struct MHD_Daemon *daemon,
707/** 707/**
708 * Set random values to be used by the Digest Auth module. Note that 708 * Set random values to be used by the Digest Auth module. Note that
709 * the application must ensure that @a buf remains allocated and 709 * the application must ensure that @a buf remains allocated and
710 * unmodified while the deamon is running. 710 * unmodified while the daemon is running.
711 * 711 *
712 * @param daemon daemon to configure 712 * @param daemon daemon to configure
713 * @param buf_size number of bytes in @a buf 713 * @param buf_size number of bytes in @a buf
diff --git a/src/lib/internal.h b/src/lib/internal.h
index 6c43fc20..c9971999 100644
--- a/src/lib/internal.h
+++ b/src/lib/internal.h
@@ -1410,7 +1410,7 @@ struct MHD_Daemon
1410 struct MHD_itc_ itc; 1410 struct MHD_itc_ itc;
1411 1411
1412 /** 1412 /**
1413 * Which threading mode do we use? Postive 1413 * Which threading mode do we use? Positive
1414 * numbers indicate the number of worker threads to be used. 1414 * numbers indicate the number of worker threads to be used.
1415 * Values larger than 1 imply a thread pool. 1415 * Values larger than 1 imply a thread pool.
1416 */ 1416 */
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 5d4df248..44fc86a2 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -835,7 +835,7 @@ MHD_connection_finish_forward_ (struct MHD_Connection *connection)
835 835
836 836
837/** 837/**
838 * A serious error occured, close the 838 * A serious error occurred, close the
839 * connection (and notify the application). 839 * connection (and notify the application).
840 * 840 *
841 * @param connection connection to close with error 841 * @param connection connection to close with error
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index f23080ef..660ee61e 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3223,7 +3223,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
3223 { 3223 {
3224 const int err = MHD_socket_get_error_ (); 3224 const int err = MHD_socket_get_error_ ();
3225 3225
3226 /* This could be a common occurance with multiple worker threads */ 3226 /* This could be a common occurrence with multiple worker threads */
3227 if (MHD_SCKT_ERR_IS_ (err, 3227 if (MHD_SCKT_ERR_IS_ (err,
3228 MHD_SCKT_EINVAL_)) 3228 MHD_SCKT_EINVAL_))
3229 return MHD_NO; /* can happen during shutdown */ 3229 return MHD_NO; /* can happen during shutdown */
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 1fc931ad..49ce4dce 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -1140,7 +1140,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
1140 * Uses #MHD_DIGEST_ALG_MD5 (for now, for backwards-compatibility). 1140 * Uses #MHD_DIGEST_ALG_MD5 (for now, for backwards-compatibility).
1141 * Note that this MAY change to #MHD_DIGEST_ALG_AUTO in the future. 1141 * Note that this MAY change to #MHD_DIGEST_ALG_AUTO in the future.
1142 * If you want to be sure you get MD5, use #MHD_digest_auth_check2 1142 * If you want to be sure you get MD5, use #MHD_digest_auth_check2
1143 * and specifiy MD5 explicitly. 1143 * and specify MD5 explicitly.
1144 * 1144 *
1145 * @param connection The MHD connection structure 1145 * @param connection The MHD connection structure
1146 * @param realm The realm presented to the client 1146 * @param realm The realm presented to the client
@@ -1278,7 +1278,7 @@ MHD_digest_auth_check_digest2 (struct MHD_Connection *connection,
1278 1278
1279 mhd_assert (NULL != digest); 1279 mhd_assert (NULL != digest);
1280 if (da.digest_size != digest_size) 1280 if (da.digest_size != digest_size)
1281 MHD_PANIC (_ ("digest size missmatch")); /* API violation! */ 1281 MHD_PANIC (_ ("digest size mismatch")); /* API violation! */
1282 return digest_auth_check_all (connection, 1282 return digest_auth_check_all (connection,
1283 &da, 1283 &da,
1284 realm, 1284 realm,
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index d5d9b0d1..4cec6787 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -1546,7 +1546,7 @@ struct MHD_Daemon
1546 volatile bool shutdown; 1546 volatile bool shutdown;
1547 1547
1548 /** 1548 /**
1549 * Has this deamon been quiesced via #MHD_quiesce_daemon()? 1549 * Has this daemon been quiesced via #MHD_quiesce_daemon()?
1550 * If so, we should no longer use the @e listen_fd (including 1550 * If so, we should no longer use the @e listen_fd (including
1551 * removing it from the @e epoll_fd when possible). 1551 * removing it from the @e epoll_fd when possible).
1552 */ 1552 */
diff --git a/src/microhttpd/memorypool.h b/src/microhttpd/memorypool.h
index 6f5d539d..2d1fd119 100644
--- a/src/microhttpd/memorypool.h
+++ b/src/microhttpd/memorypool.h
@@ -44,7 +44,7 @@
44struct MemoryPool; 44struct MemoryPool;
45 45
46/** 46/**
47 * Initilise values for memory pools 47 * Initialize values for memory pools
48 */ 48 */
49void 49void
50MHD_init_mem_pools_ (void); 50MHD_init_mem_pools_ (void);
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h
index 34e49d15..e023bf12 100644
--- a/src/microhttpd/mhd_bithelpers.h
+++ b/src/microhttpd/mhd_bithelpers.h
@@ -100,7 +100,7 @@
100#define _MHD_PUT_64BIT_LE(addr, value64) \ 100#define _MHD_PUT_64BIT_LE(addr, value64) \
101 ((*(uint64_t*) (addr)) = _MHD_BYTES_SWAP64 (value64)) 101 ((*(uint64_t*) (addr)) = _MHD_BYTES_SWAP64 (value64))
102#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 102#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
103/* Endianess was not detected or non-standard like PDP-endian */ 103/* Endianness was not detected or non-standard like PDP-endian */
104#define _MHD_PUT_64BIT_LE(addr, value64) do { \ 104#define _MHD_PUT_64BIT_LE(addr, value64) do { \
105 ((uint8_t*) (addr))[0] = (uint8_t) ((uint64_t) (value64)); \ 105 ((uint8_t*) (addr))[0] = (uint8_t) ((uint64_t) (value64)); \
106 ((uint8_t*) (addr))[1] = (uint8_t) (((uint64_t) (value64)) >> 8); \ 106 ((uint8_t*) (addr))[1] = (uint8_t) (((uint64_t) (value64)) >> 8); \
@@ -124,7 +124,7 @@
124#define _MHD_PUT_32BIT_LE(addr, value32) \ 124#define _MHD_PUT_32BIT_LE(addr, value32) \
125 ((*(uint32_t*) (addr)) = _MHD_BYTES_SWAP32 (value32)) 125 ((*(uint32_t*) (addr)) = _MHD_BYTES_SWAP32 (value32))
126#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 126#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
127/* Endianess was not detected or non-standard like PDP-endian */ 127/* Endianness was not detected or non-standard like PDP-endian */
128#define _MHD_PUT_32BIT_LE(addr, value32) do { \ 128#define _MHD_PUT_32BIT_LE(addr, value32) do { \
129 ((uint8_t*) (addr))[0] = (uint8_t) ((uint32_t) (value32)); \ 129 ((uint8_t*) (addr))[0] = (uint8_t) ((uint32_t) (value32)); \
130 ((uint8_t*) (addr))[1] = (uint8_t) (((uint32_t) (value32)) >> 8); \ 130 ((uint8_t*) (addr))[1] = (uint8_t) (((uint32_t) (value32)) >> 8); \
@@ -144,7 +144,7 @@
144#define _MHD_GET_32BIT_LE(addr) \ 144#define _MHD_GET_32BIT_LE(addr) \
145 _MHD_BYTES_SWAP32 (*(const uint32_t*) (addr)) 145 _MHD_BYTES_SWAP32 (*(const uint32_t*) (addr))
146#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 146#else /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
147/* Endianess was not detected or non-standard like PDP-endian */ 147/* Endianness was not detected or non-standard like PDP-endian */
148#define _MHD_GET_32BIT_LE(addr) \ 148#define _MHD_GET_32BIT_LE(addr) \
149 ( ( (uint32_t) (((const uint8_t*) addr)[0])) \ 149 ( ( (uint32_t) (((const uint8_t*) addr)[0])) \
150 | (((uint32_t) (((const uint8_t*) addr)[1])) << 8) \ 150 | (((uint32_t) (((const uint8_t*) addr)[1])) << 8) \
@@ -164,7 +164,7 @@
164#define _MHD_PUT_64BIT_BE(addr, value64) \ 164#define _MHD_PUT_64BIT_BE(addr, value64) \
165 ((*(uint64_t*) (addr)) = _MHD_BYTES_SWAP64 (value64)) 165 ((*(uint64_t*) (addr)) = _MHD_BYTES_SWAP64 (value64))
166#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 166#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
167/* Endianess was not detected or non-standard like PDP-endian */ 167/* Endianness was not detected or non-standard like PDP-endian */
168#define _MHD_PUT_64BIT_BE(addr, value64) do { \ 168#define _MHD_PUT_64BIT_BE(addr, value64) do { \
169 ((uint8_t*) (addr))[7] = (uint8_t) ((uint64_t) (value64)); \ 169 ((uint8_t*) (addr))[7] = (uint8_t) ((uint64_t) (value64)); \
170 ((uint8_t*) (addr))[6] = (uint8_t) (((uint64_t) (value64)) >> 8); \ 170 ((uint8_t*) (addr))[6] = (uint8_t) (((uint64_t) (value64)) >> 8); \
@@ -188,7 +188,7 @@
188#define _MHD_PUT_32BIT_BE(addr, value32) \ 188#define _MHD_PUT_32BIT_BE(addr, value32) \
189 ((*(uint32_t*) (addr)) = _MHD_BYTES_SWAP32 (value32)) 189 ((*(uint32_t*) (addr)) = _MHD_BYTES_SWAP32 (value32))
190#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 190#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
191/* Endianess was not detected or non-standard like PDP-endian */ 191/* Endianness was not detected or non-standard like PDP-endian */
192#define _MHD_PUT_32BIT_BE(addr, value32) do { \ 192#define _MHD_PUT_32BIT_BE(addr, value32) do { \
193 ((uint8_t*) (addr))[3] = (uint8_t) ((uint32_t) (value32)); \ 193 ((uint8_t*) (addr))[3] = (uint8_t) ((uint32_t) (value32)); \
194 ((uint8_t*) (addr))[2] = (uint8_t) (((uint32_t) (value32)) >> 8); \ 194 ((uint8_t*) (addr))[2] = (uint8_t) (((uint32_t) (value32)) >> 8); \
@@ -208,7 +208,7 @@
208#define _MHD_GET_32BIT_BE(addr) \ 208#define _MHD_GET_32BIT_BE(addr) \
209 _MHD_BYTES_SWAP32 (*(const uint32_t*) (addr)) 209 _MHD_BYTES_SWAP32 (*(const uint32_t*) (addr))
210#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ 210#else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
211/* Endianess was not detected or non-standard like PDP-endian */ 211/* Endianness was not detected or non-standard like PDP-endian */
212#define _MHD_GET_32BIT_BE(addr) \ 212#define _MHD_GET_32BIT_BE(addr) \
213 ( (((uint32_t) (((const uint8_t*) addr)[0])) << 24) \ 213 ( (((uint32_t) (((const uint8_t*) addr)[0])) << 24) \
214 | (((uint32_t) (((const uint8_t*) addr)[1])) << 16) \ 214 | (((uint32_t) (((const uint8_t*) addr)[1])) << 16) \
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index b0c0842b..cc75bbde 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -86,11 +86,11 @@ pre_cork_setsockopt (struct MHD_Connection *connection,
86#endif 86#endif
87 break; 87 break;
88 case EFAULT: 88 case EFAULT:
89 /* wopsie, should at leats log this, FIXME: maybe die */ 89 /* wopsie, should at least log this, FIXME: maybe die */
90#ifdef HAVE_MESSAGES 90#ifdef HAVE_MESSAGES
91 MHD_DLOG (connection->daemon, 91 MHD_DLOG (connection->daemon,
92 _ ( 92 _ (
93 "The addresss pointed to by optval is not a valid part of the process address space: %s\n"), 93 "The address pointed to by optval is not a valid part of the process address space: %s\n"),
94 MHD_socket_last_strerr_ ()); 94 MHD_socket_last_strerr_ ());
95#endif 95#endif
96 break; 96 break;
@@ -173,11 +173,11 @@ post_cork_setsockopt (struct MHD_Connection *connection,
173#endif 173#endif
174 break; 174 break;
175 case EFAULT: 175 case EFAULT:
176 /* wopsie, should at leats log this, FIXME: maybe die */ 176 /* wopsie, should at least log this, FIXME: maybe die */
177#ifdef HAVE_MESSAGES 177#ifdef HAVE_MESSAGES
178 MHD_DLOG (connection->daemon, 178 MHD_DLOG (connection->daemon,
179 _ ( 179 _ (
180 "The addresss pointed to by optval is not a valid part of the process address space: %s\n"), 180 "The address pointed to by optval is not a valid part of the process address space: %s\n"),
181 MHD_socket_last_strerr_ ()); 181 MHD_socket_last_strerr_ ());
182#endif 182#endif
183 break; 183 break;
diff --git a/src/microhttpd/test_md5.c b/src/microhttpd/test_md5.c
index 2825c09f..9d3ff63f 100644
--- a/src/microhttpd/test_md5.c
+++ b/src/microhttpd/test_md5.c
@@ -243,16 +243,16 @@ bin2hex (const uint8_t *bin,
243static int 243static int
244check_result (const char *test_name, 244check_result (const char *test_name,
245 unsigned int check_num, 245 unsigned int check_num,
246 const uint8_t calcualted[MD5_DIGEST_SIZE], 246 const uint8_t calculated[MD5_DIGEST_SIZE],
247 const uint8_t expected[MD5_DIGEST_SIZE]) 247 const uint8_t expected[MD5_DIGEST_SIZE])
248{ 248{
249 int failed = memcmp (calcualted, expected, MD5_DIGEST_SIZE); 249 int failed = memcmp (calculated, expected, MD5_DIGEST_SIZE);
250 check_num++; /* Print 1-based numbers */ 250 check_num++; /* Print 1-based numbers */
251 if (failed) 251 if (failed)
252 { 252 {
253 char calc_str[MD5_DIGEST_STRING_LENGTH]; 253 char calc_str[MD5_DIGEST_STRING_LENGTH];
254 char expc_str[MD5_DIGEST_STRING_LENGTH]; 254 char expc_str[MD5_DIGEST_STRING_LENGTH];
255 bin2hex (calcualted, MD5_DIGEST_SIZE, calc_str); 255 bin2hex (calculated, MD5_DIGEST_SIZE, calc_str);
256 bin2hex (expected, MD5_DIGEST_SIZE, expc_str); 256 bin2hex (expected, MD5_DIGEST_SIZE, expc_str);
257 fprintf (stderr, 257 fprintf (stderr,
258 "FAILED: %s check %u: calculated digest %s, expected digest %s.\n", 258 "FAILED: %s check %u: calculated digest %s, expected digest %s.\n",
@@ -262,7 +262,7 @@ check_result (const char *test_name,
262 else if (verbose) 262 else if (verbose)
263 { 263 {
264 char calc_str[MD5_DIGEST_STRING_LENGTH]; 264 char calc_str[MD5_DIGEST_STRING_LENGTH];
265 bin2hex (calcualted, MD5_DIGEST_SIZE, calc_str); 265 bin2hex (calculated, MD5_DIGEST_SIZE, calc_str);
266 printf ( 266 printf (
267 "PASSED: %s check %u: calculated digest %s match expected digest.\n", 267 "PASSED: %s check %u: calculated digest %s match expected digest.\n",
268 test_name, check_num, calc_str); 268 test_name, check_num, calc_str);
diff --git a/src/microhttpd/test_sha256.c b/src/microhttpd/test_sha256.c
index 54cdf027..7ad5f399 100644
--- a/src/microhttpd/test_sha256.c
+++ b/src/microhttpd/test_sha256.c
@@ -289,16 +289,16 @@ bin2hex (const uint8_t *bin,
289static int 289static int
290check_result (const char *test_name, 290check_result (const char *test_name,
291 unsigned int check_num, 291 unsigned int check_num,
292 const uint8_t calcualted[SHA256_DIGEST_SIZE], 292 const uint8_t calculated[SHA256_DIGEST_SIZE],
293 const uint8_t expected[SHA256_DIGEST_SIZE]) 293 const uint8_t expected[SHA256_DIGEST_SIZE])
294{ 294{
295 int failed = memcmp (calcualted, expected, SHA256_DIGEST_SIZE); 295 int failed = memcmp (calculated, expected, SHA256_DIGEST_SIZE);
296 check_num++; /* Print 1-based numbers */ 296 check_num++; /* Print 1-based numbers */
297 if (failed) 297 if (failed)
298 { 298 {
299 char calc_str[SHA256_DIGEST_STRING_SIZE]; 299 char calc_str[SHA256_DIGEST_STRING_SIZE];
300 char expc_str[SHA256_DIGEST_STRING_SIZE]; 300 char expc_str[SHA256_DIGEST_STRING_SIZE];
301 bin2hex (calcualted, SHA256_DIGEST_SIZE, calc_str); 301 bin2hex (calculated, SHA256_DIGEST_SIZE, calc_str);
302 bin2hex (expected, SHA256_DIGEST_SIZE, expc_str); 302 bin2hex (expected, SHA256_DIGEST_SIZE, expc_str);
303 fprintf (stderr, 303 fprintf (stderr,
304 "FAILED: %s check %u: calculated digest %s, expected digest %s.\n", 304 "FAILED: %s check %u: calculated digest %s, expected digest %s.\n",
@@ -308,7 +308,7 @@ check_result (const char *test_name,
308 else if (verbose) 308 else if (verbose)
309 { 309 {
310 char calc_str[SHA256_DIGEST_STRING_SIZE]; 310 char calc_str[SHA256_DIGEST_STRING_SIZE];
311 bin2hex (calcualted, SHA256_DIGEST_SIZE, calc_str); 311 bin2hex (calculated, SHA256_DIGEST_SIZE, calc_str);
312 printf ( 312 printf (
313 "PASSED: %s check %u: calculated digest %s match expected digest.\n", 313 "PASSED: %s check %u: calculated digest %s match expected digest.\n",
314 test_name, check_num, calc_str); 314 test_name, check_num, calc_str);
diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c
index b3aecafa..fd9c2537 100644
--- a/src/microhttpd/test_upgrade.c
+++ b/src/microhttpd/test_upgrade.c
@@ -279,7 +279,7 @@ wr_create_from_plain_sckt (MHD_socket plain_sk)
279 * Connect socket to specified address. 279 * Connect socket to specified address.
280 * @param s socket to use 280 * @param s socket to use
281 * @param addr address to connect 281 * @param addr address to connect
282 * @param length of sturcture pointed by @a addr 282 * @param length of structure pointed by @a addr
283 * @return zero on success, -1 otherwise. 283 * @return zero on success, -1 otherwise.
284 */ 284 */
285static int 285static int
@@ -840,7 +840,7 @@ upgrade_cb (void *cls,
840 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED). 840 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
841 * Initially, `*con_cls` will be NULL. 841 * Initially, `*con_cls` will be NULL.
842 * @return #MHD_YES if the connection was handled successfully, 842 * @return #MHD_YES if the connection was handled successfully,
843 * #MHD_NO if the socket must be closed due to a serios 843 * #MHD_NO if the socket must be closed due to a serious
844 * error while handling the request 844 * error while handling the request
845 */ 845 */
846static enum MHD_Result 846static enum MHD_Result
diff --git a/src/microhttpd/test_upgrade_large.c b/src/microhttpd/test_upgrade_large.c
index d8d35838..43c04b7f 100644
--- a/src/microhttpd/test_upgrade_large.c
+++ b/src/microhttpd/test_upgrade_large.c
@@ -289,7 +289,7 @@ wr_create_from_plain_sckt (MHD_socket plain_sk)
289 * Connect socket to specified address. 289 * Connect socket to specified address.
290 * @param s socket to use 290 * @param s socket to use
291 * @param addr address to connect 291 * @param addr address to connect
292 * @param length of sturcture pointed by @a addr 292 * @param length of structure pointed by @a addr
293 * @return zero on success, -1 otherwise. 293 * @return zero on success, -1 otherwise.
294 */ 294 */
295static int 295static int
@@ -864,7 +864,7 @@ upgrade_cb (void *cls,
864 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED). 864 * can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
865 * Initially, `*con_cls` will be NULL. 865 * Initially, `*con_cls` will be NULL.
866 * @return #MHD_YES if the connection was handled successfully, 866 * @return #MHD_YES if the connection was handled successfully,
867 * #MHD_NO if the socket must be closed due to a serios 867 * #MHD_NO if the socket must be closed due to a serious
868 * error while handling the request 868 * error while handling the request
869 */ 869 */
870static enum MHD_Result 870static enum MHD_Result
diff --git a/src/testcurl/https/test_empty_response.c b/src/testcurl/https/test_empty_response.c
index 28430388..8e1ef1a8 100644
--- a/src/testcurl/https/test_empty_response.c
+++ b/src/testcurl/https/test_empty_response.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file test_empty_response.c 22 * @file test_empty_response.c
23 * @brief Testcase for libmicrohttpd HTTPS GET operations with emtpy reply 23 * @brief Testcase for libmicrohttpd HTTPS GET operations with empty reply
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
diff --git a/src/testcurl/https/test_https_get_parallel.c b/src/testcurl/https/test_https_get_parallel.c
index e4040874..aa7f8d58 100644
--- a/src/testcurl/https/test_https_get_parallel.c
+++ b/src/testcurl/https/test_https_get_parallel.c
@@ -60,7 +60,7 @@ https_transfer_thread_adapter (void *args)
60 struct https_test_data *cargs = args; 60 struct https_test_data *cargs = args;
61 int ret; 61 int ret;
62 62
63 /* time spread incomming requests */ 63 /* time spread incoming requests */
64 usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX)); 64 usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
65 ret = test_https_transfer (NULL, cargs->port, 65 ret = test_https_transfer (NULL, cargs->port,
66 cargs->cipher_suite, cargs->proto_version); 66 cargs->cipher_suite, cargs->proto_version);
@@ -98,7 +98,7 @@ test_single_client (void *cls, int port, const char *cipher_suite,
98 * 98 *
99 * @return: 0 upon all client requests returning '0', -1 otherwise. 99 * @return: 0 upon all client requests returning '0', -1 otherwise.
100 * 100 *
101 * TODO : make client_count a parameter - numver of curl client threads to spawn 101 * TODO : make client_count a parameter - number of curl client threads to spawn
102 */ 102 */
103static int 103static int
104test_parallel_clients (void *cls, int port, const char *cipher_suite, 104test_parallel_clients (void *cls, int port, const char *cipher_suite,
diff --git a/src/testcurl/https/test_https_get_parallel_threads.c b/src/testcurl/https/test_https_get_parallel_threads.c
index 3fc0e189..470072cb 100644
--- a/src/testcurl/https/test_https_get_parallel_threads.c
+++ b/src/testcurl/https/test_https_get_parallel_threads.c
@@ -61,7 +61,7 @@ https_transfer_thread_adapter (void *args)
61 struct https_test_data *cargs = args; 61 struct https_test_data *cargs = args;
62 int ret; 62 int ret;
63 63
64 /* time spread incomming requests */ 64 /* time spread incoming requests */
65 usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX)); 65 usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
66 ret = test_https_transfer (cargs->cls, cargs->port, 66 ret = test_https_transfer (cargs->cls, cargs->port,
67 cargs->cipher_suite, cargs->proto_version); 67 cargs->cipher_suite, cargs->proto_version);
@@ -76,7 +76,7 @@ https_transfer_thread_adapter (void *args)
76 * 76 *
77 * @return: 0 upon all client requests returning '0', -1 otherwise. 77 * @return: 0 upon all client requests returning '0', -1 otherwise.
78 * 78 *
79 * TODO : make client_count a parameter - numver of curl client threads to spawn 79 * TODO : make client_count a parameter - number of curl client threads to spawn
80 */ 80 */
81static int 81static int
82test_single_client (void *cls, int port, const char *cipher_suite, 82test_single_client (void *cls, int port, const char *cipher_suite,
@@ -99,7 +99,7 @@ test_single_client (void *cls, int port, const char *cipher_suite,
99 * 99 *
100 * @return: 0 upon all client requests returning '0', -1 otherwise. 100 * @return: 0 upon all client requests returning '0', -1 otherwise.
101 * 101 *
102 * TODO : make client_count a parameter - numver of curl client threads to spawn 102 * TODO : make client_count a parameter - number of curl client threads to spawn
103 */ 103 */
104static int 104static int
105test_parallel_clients (void *cls, int port, const char *cipher_suite, 105test_parallel_clients (void *cls, int port, const char *cipher_suite,
diff --git a/src/testcurl/https/tls_test_common.c b/src/testcurl/https/tls_test_common.c
index a704be5f..1d24c701 100644
--- a/src/testcurl/https/tls_test_common.c
+++ b/src/testcurl/https/tls_test_common.c
@@ -401,7 +401,7 @@ test_https_transfer (void *cls,
401 goto cleanup; 401 goto cleanup;
402 } 402 }
403 403
404 /* compare test file & daemon responce */ 404 /* compare test file & daemon response */
405 if ( (len != strlen (test_data)) || 405 if ( (len != strlen (test_data)) ||
406 (memcmp (cbc.buf, 406 (memcmp (cbc.buf,
407 test_data, 407 test_data,