77 Commits
Author SHA1 Message Date
Evgeny Grin (Karlson2k) 916886cdf6 Added Lawrence Sebald to the AUTHORS file 2021-10-23 13:42:36 +03:00
Christian Grothoff 58552e93ac applying patch from Tim 2019-04-30 15:39:10 +02:00
Christian Grothoff 2add933d4f add JM 2018-12-08 23:18:48 +01:00
Christian Grothoff 3fc686e335 initialize epoll_fd even if we have no listen fd, patch by Jose Bollo 2018-11-01 16:31:03 +01:00
Christian Grothoff a7c0b04cce properly recognize Dirk B. 2018-07-14 13:27:46 +02:00
Christian Grothoff 2c47a23dec integrate TLS PSK patch from Tal Moaz (plus documentation, plus style and bugfixes 2018-07-14 13:27:45 +02:00
Christian Grothoff 8abd74f3dc add suspend_resume_epoll example (from mailinglist) 2018-03-14 05:31:09 +01:00
Christian Grothoff 76cf7d7f58 documentation, adding MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE, releasing 0.9.54 2017-05-02 18:53:50 +02:00
silvioprog abb31c0a77 Added i18n example: msgs_i18n.c 2017-02-28 15:51:32 -03:00
Christian Grothoff 94ff070774 adding test from Markus (adapted by me to C and MHD-style) 2016-11-04 21:57:17 +01:00
Christian Grothoff 322941446c Evgeny is now officially co-maintainer 2015-12-21 06:36:34 +00:00
Evgeny Grin (Karlson2k) cec4f5eb37 Remove traces of libmicrospdy 2015-12-03 13:41:23 +00:00
Christian Grothoff 9e87c9a225 patch from FC to fix use of resume in combination with external select 2015-09-02 14:45:28 +00:00
Christian Grothoff 4680ad00f7 removing minus 2015-08-14 15:12:59 +00:00
Christian Grothoff b86f93acaf HI,
The MHD goes in a busy loop when it is configured with MHD_USE_POLL_INTERNALLY and a connection times out.
When the connection times out, the connection is closed at connection.c:2646, which sets connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP.
When the loop info is set to MHD_EVENT_LOOP_INFO_CLEANUP, the main function of the thread loop, MHD_poll_all, never calls back the connection idle callback, which would have cleaned the connection and exit the loop.
I resolved the issue in my development code by adding pos->idle_handler (pos) at daemon.c:2477 in MHD_poll_all (SVN 35533).

The busy loop could be tested using a small enough connection timeout and netcat:
nc -v -w 100 <IP ADDRESS> <IP PORT>

CPU usage will reach 100% in one of the CPU and will remain at that level even when the netcat has closed its end of the connection.

Thanks,

Louis Benoit
2015-04-14 22:34:15 +00:00
Christian Grothoff 086ba366b7 Hi all,
I was trying to use MHD_suspend_connection() and MHD_resume_connection() to implement long polling on a request. I am using options MHD_USE_SELECT_INTERNALLY and MHD_USE_POLL options. I noticed the server thread went to 100% CPU after the first MHD_resume_connection() call. Looking at the code in MHD_poll_all() I can see that the file descriptor from daemon->wpipe[0] gets inserted into the list of file descriptors to poll but this file descriptor is never read so every time this function is called it returns immediately. The code works fine if I drop to using just MHD_USE_SELECT_INTERNALLY.

The patch below fixes the problem.

Regards,
Denis
2015-04-09 07:03:26 +00:00
Christian Grothoff a05803df4f Robert Gronenberg wrote:
I am using libmicrohttpd in a multithreaded application in the
thread-per-connection mode. In order to maintain statistics and such on
the various clients, the application should be notified about
connections being started and stopped. Something like the
MHD_OPTION_NOTIFY_COMPLETED for requests, but then for connections. As
far as I could find libmicrohttpd does not (yet) provide that functionality.

Attached is a patch that does add this functionality by registering a
connection notification callback function: MHD_OPTION_NOTIFY_CONNECTION
(inspired by the MHD_OPTION_NOTIFY_COMPLETED option).

Could this be included in libmicrohttpd?

=>

The patch was only working for multithreaded apps, so I adjusted it
to cover other threading models, fixed a merge issue and added the
ability to associate a void* with the callbacks (and obtain it via
MHD connection info).  And I updated the manual & ChangeLog. Now
I think it can be included ;-).
2015-03-31 08:38:33 +00:00
Christian Grothoff d50980a765 From: Milan Straka <fox@ucw.cz>
Date: Wed, 29 Oct 2014 09:59:09 +0100
Subject: [PATCH 2/2] Add MHD_DAEMON_INFO_CURRENT_CONNECTIONS to
 MHD_DaemonInfoType.

The MHD_DAEMON_INFO_CURRENT_CONNECTIONS returns number of current
connections handled by the daemon.

Useful after MHD_quiesce_daemon to find out whether all connections
have been served.
2014-10-29 15:29:31 +00:00
Christian Grothoff 312d11ec19 fix #3392 as suggested by reporter 2014-05-02 18:23:58 +00:00
Christian Grothoff f46a9bc5fb -bump Evgeny 2014-04-07 11:28:03 +00:00
Christian Grothoff ca3a7d621c add MHD_OPTION_HTTPS_MEM_DHPARAMS to support PFS 2014-04-07 11:27:18 +00:00
Evgeny Grin (Karlson2k) b33a2d2436 ChangeLog and AUTHORS update 2014-02-26 17:55:54 +00:00
Sree Harsha Totakura bc1137bd60 Add support for TCP FASTOPEN connections. 2014-02-24 16:25:43 +00:00
Christian Grothoff dd902f337b Luke-Jr wrote:
MHD_USE_DUAL_STACK in libmicrohttpd currently just *inhibits setting* the 
IPV6_V6ONLY socket option, but per Microsoft's documentation 
http://msdn.microsoft.com/en-us/library/windows/desktop/bb513665(v=vs.85).aspx
the default on Windows is that this is enabled, thus MHD_USE_DUAL_STACK will 
not work (since it leaves the default). libmicrohttpd should probably just 
unconditionally set IPV6_V6ONLY to the desired value when the option is 
available.

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 0a33b77..3cbf28e 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3493,8 +3493,7 @@ MHD_start_daemon_va (unsigned int flags,
 	}
       daemon->socket_fd = socket_fd;
 
-      if ( (0 != (flags & MHD_USE_IPv6)) &&
-	   (MHD_USE_DUAL_STACK != (flags & MHD_USE_DUAL_STACK)) )
+      if (0 != (flags & MHD_USE_IPv6))
 	{
 #ifdef IPPROTO_IPV6
 #ifdef IPV6_V6ONLY
@@ -3503,10 +3502,11 @@ MHD_start_daemon_va (unsigned int flags,
 	     and may also be missing on older POSIX systems; good luck if you have 
any of those,
 	     your IPv6 socket may then also bind against IPv4 anyway... */
 #ifndef WINDOWS
-	  const int on = 1;
+	  const int
 #else
-	  const char on = 1;
+	  const char
 #endif
+		 on = (MHD_USE_DUAL_STACK != (flags & MHD_USE_DUAL_STACK));
 	  if ( (0 > SETSOCKOPT (socket_fd,
 				IPPROTO_IPV6, IPV6_V6ONLY,
 				&on, sizeof (on))) &&
2014-01-22 08:47:48 +00:00
Christian Grothoff 74e0a68567 -fixes to MHD_suspend_connection 2013-11-25 21:51:08 +00:00
Christian Grothoff 36ac797380 -use more portable rand instead of random 2013-08-07 06:19:33 +00:00
Christian Grothoff 6e07994a8b -fixing #2899: allow clients to customize MHD_BUF_INC_SIZE via option 2013-07-05 10:12:10 +00:00
Christian Grothoff 639c6a9880 merging libmicrospdy into tree 2013-05-05 19:21:40 +00:00
Christian Grothoff 8e796aefcc adding testcase for quiesce from Scott Goldman 2013-04-26 09:51:33 +00:00
Christian Grothoff 2027b939dd Matthew Mundell wrote:
Hi

We've been having some mysterious parameter loss of POST parameters in
OpenVAS's GSA.  This only happens with IE8 and Chrome.  We saw this with
libmicrohttpd 0.9.19 and 0.9.20.

The cause looks to be an error in libmicrohttpd.  Patch to 0.9.20 to
resolve below.

In post_process_multipart in postprocessor.c the PP_Init state calls
find_boundary to find the first boundary.  If there is junk before the
first boundary it just reads over the junk.  However, it is also reading
over the actual boundary when there was too little data to determine
whether the next character is the start of the boundary.

In the error case Chrome seems to sends the POST request in multiple
writes.  The first chunk includes a single "-" from the first boundary at
end of the headers.  Thus libmicrohttpd has a partial boundary to deal
with.

I guess Chrome intends to send just the headers but gets the count wrong
due to sending the initial P of the POST on its own (all the browsers do
that for some reason).  Firefox on the other hand sends the headers and the
body in a single write, so it always works.

Thanks, and thanks for libmicrohttpd!

Matt
2012-12-05 18:28:17 +00:00
Christian Grothoff 802d1322f2 Ship its own version of tsearch and friends if not provided by platform.
On GNU based systems the tree related functions (tsearch, tfind, tdestroy)
are provided by the libc (with the interface specification in search.h). On
non-GNU systems this functionality may or may not be available. That's the
case for Android which ships its own, simplified, version of libc called
Bionic. Bionic does not contains neither search.h nor an implementation of
the above mentioned functions.

This patch adds detection for the presence of search.h and if the header file
is not found, it uses an internal version of search.h and functions tsearch,
tfind, and tdestroy. The internal version is based on the source code from
FreeBSD and is compiled if and only if the configure script did not find the
search.h header file.
 -- Jan Janak
2012-11-08 21:35:38 +00:00
Christian Grothoff 912620e3f9 BS: fixing compilation problem on MinGW 2012-02-01 08:40:41 +00:00
Christian Grothoff 9816a8f598 -typo 2012-01-31 16:58:37 +00:00
Christian Grothoff 59f9cb3179 -ack 2012-01-31 16:57:18 +00:00
Christian Grothoff de35faa11a Hi there,
am I right in the assumption, that the documentation at
http://www.gnu.org/s/libmicrohttpd/tutorial.html#Supporting-basic-authentication
is newer than authorization_example.c in the src/examples/ subdirectory?

If so here is a patch to make authorization_example.c use the functions from
the tutorial instead of raw base64 strings.

Regards

Sven
-
2011-12-01 14:24:24 +00:00
Christian Grothoff 5f6d6b2ccc email 2011-11-29 19:26:17 +00:00
Christian Grothoff 2160c66589 LRN: w32 test case fixes 2011-10-07 17:51:10 +00:00
Christian Grothoff 7ef544c9be From:
Will Bryant <will.bryant@gmail.com>
  To: 
libmicrohttpd development and user mailinglist <libmicrohttpd@gnu.org>
  Date: 
Yesterday 03:59:23 PM
  Attachments: 
 0001-use-a-pipe-to-signal-shutdown-to-select-and-poll.patch
   
I attach my current work.  I have attempted to preserve and restore as much of the 'old' pipe shutdown code that was present in earlier versions of the library, but have removed the sections that aren't relevant now that there is a socket-by-socket client shutdown procedure.

On OS X, all the 'regular' tests pass.  The two perf test programs both fail on a random subset of the tests with "Failed to bind to port 1081: Address already in use" (or the other ports that the perf tests use).

I initially thought that this was a problem with this patch, but after I couldn't find any problem with it I tried backporting the perf test programs to the older 0.9.7 version of libmicrohttpd, which is before the listening socket shutdown code went in, and it turned out that the older versions failed in the same way.

On OpenIndiana (oi_151a - but should behave the same as other SunOS/Solaris/OpenSolaris/Illumos kernels), the same problem occurs.  (I haven't tried the backport there too.)

Linux is known to have slightly different behavior for the SOL_REUSEADDR option which might explain this, but it's quite possible that this is just a timing issue with the cleanup of the client threads in these perf test programs (if you wait for 1s between the tests then the problem goes away).  

On OS X, using both debugging printfs and shelling out to lsof -itcp, I have confirmed that the listening socket has been closed successfully before the error occurs.   So I am starting to suspect that it is not possible to bind to an address that was used as a server socket until all the client sockets have also been cleaned up - but that's just a theory at this point.

Anyway, as far as this patch goes, OS X looks a lot healthier - as healthy as it was in 0.9.7 (0.9.8 and 0.9.9 both failed to build entirely).

There is one further test failure on openindiana, which I believe is not related to this patch - all the same 'regular' tests pass except daemontest_get_response_cleanup, which dies due to an unhandled SIGPIPE when trying to write to the socket after killing the curl process:

Program received signal SIGPIPE, Broken pipe.
[Switching to Thread 2 (LWP 2)]
0xfed634f7 in __so_send () from /lib/libc.so.1
(gdb) bt
#0  0xfed634f7 in __so_send () from /lib/libc.so.1
#1  0xfed511d7 in _so_send () from /lib/libc.so.1
#2  0xfe7dcb26 in send () from /lib/libsocket.so.1
#3  0xfef56d29 in send_param_adapter (connection=0x20, other=0xfe99080f, i=0) at daemon.c:764
#4  0xfef54a0b in do_write (connection=0x8073ad0) at connection.c:1495
#5  0xfef54f6f in MHD_connection_handle_write (connection=0x8073ad0) at connection.c:1909
#6  0xfef57b3c in MHD_select (daemon=0x80737a8, may_block=0) at daemon.c:1367
#7  0xfef57ff4 in MHD_select_thread (cls=0x80737a8) at daemon.c:1615
#8  0xfed5f0f3 in _thrp_setup () from /lib/libc.so.1
#9  0xfed5f3a0 in ?? () from /lib/libc.so.1
#10 0xfe9a0240 in ?? ()
#11 0x00000000 in ?? ()
(gdb) info threads
* 4 Thread 2 (LWP 2)  0xfed634f7 in __so_send () from /lib/libc.so.1
  3 LWP    2          0xfed634f7 in __so_send () from /lib/libc.so.1
  2 Thread 1 (LWP 1)  0xfed63e87 in __waitid () from /lib/libc.so.1
  1 LWP    1          0xfed63e87 in __waitid () from /lib/libc.so.1
(gdb) thread 2
[Switching to thread 2 (Thread 1 (LWP 1))]#0  0xfed63e87 in __waitid () from /lib/libc.so.1
(gdb) bt
#0  0xfed63e87 in __waitid () from /lib/libc.so.1
#1  0xfed515bd in waitid () from /lib/libc.so.1
#2  0xfed00035 in waitpid () from /lib/libc.so.1
#3  0x08051423 in kill_curl (pid=4479) at daemontest_get_response_cleanup.c:70
#4  0x0805157d in main (argc=1, argv=0x6b) at daemontest_get_response_cleanup.c:141

0001-use-a-pipe-to-signal-shutdown-to-select-and-poll.patch
2011-09-21 07:47:03 +00:00
Christian Grothoff 764c0fd56b bugfix 2011-08-18 09:08:53 +00:00
Christian Grothoff e91e6d3a37 bugfix by hzm 2011-05-12 12:42:46 +00:00
Christian Grothoff 8515088370 mantis 1674 2011-04-08 09:49:41 +00:00
Christian Grothoff cd8920a28d libmicrohttpd] bug in MHD_create_response_from_fd_at_offset()
From: 
Eivind Sarto <ivan@espial.com>
  To: 
"libmicrohttpd@gnu.org" <libmicrohttpd@gnu.org>
  Date: 
Today 09:32:21 pm
   
  Spam Status: Spamassassin 0% probability of being spam.

Full report:
Probability=No, score=-2.6 required=7.0 tests=BAYES_00 autolearn=ham version=3.2.5-tuminfo_1  
There appears to be a bug in  MHD_create_response_from_fd_at_offset().
Calling this function with anything other than a zero offset will cause wrong data
or no data (sendfile fails if length < 0).

If you use this call with any application that uses ranges, this bug will trigger.

In src/daemon/daemon.c: send_param_adapter()
      .....
      /* can use sendfile */
      offset = (off_t) connection->response_write_position + connection->response->fd_off;
#ifdef BUGFIX
      /* correct */
      left = connection->response->total_size -  connection->response_write_position;
#else
      left = connection->response->total_size - offset;
#endif
      if (left > SSIZE_MAX)
        left = SSIZE_MAX; /* cap at return value limit */
      ret = sendfile (connection->socket_fd,
                      fd,
                      &offset,
                      left);


-eivind
2011-03-11 21:30:24 +00:00
Christian Grothoff 5a6952fe90 [libmicrohttpd] [digest-auth]: bug in hash algorithm
From: 
Andreas Wehrmann <a.wehrmann@centersystems.com>
  To: 
libmicrohttpd@gnu.org
  Date: 
Today 08:58:43 am
   
  Spam Status: Spamassassin 0% probability of being spam.

Full report:
Probability=No, score=-3.2 required=7.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5-tuminfo_1  
Hello!

I wrote a little testpage that I deliver using libmicrohttpd using 
digest authentication.
The testpage consists of four files (framed page + image file).
When I initially connected to the webserver via the browser it correctly 
challenged me
for my credentials. However, after entering the username and password 
the index file
got loaded but it happened that the browser then challenged me again for 
each
additional file to be loaded.
Since this is very annoying I tried increasing the nonce table size to 3000
(was default) but it was no good.
I then dug a little deeper and found out, that the hash algorithm to 
determine the index
for a given nonce always returned zero thus overwriting other nonces.
The offending line is at check_nonce_nc() in digestauth.c:313:

off = (off << 8) | (*np & (off >> 24));

whereas is should be:

off = (off << 8) | (*np ^ (off >> 24));

Since "off" is initialized with zero and an unsigned integer
a logical AND returns zero which is not right obviously.
After this fix, the server challenged me only once and I got "random" 
indices.
I found the problem in libmicrohttpd 0.9.5.

Best regards,
Andreas Wehrmann

-- 
Dipl.-Ing. (FH) Andreas Wehrmann
Software Development
--------------------------------------------------------------
Center Communication Systems GmbH
A-1210 Wien, Ignaz-Köck-Straße 19
Sitz in Wien
FN 796 88p, Firmenbuchgericht Wien
www.centersystems.com

Tel.: +43 (0) 190 199 - 3616
Mobile: +43 (0) 664 884 75916
Fax: +43 (0) 190 199 - 2110
E-Mail: a.wehrmann@centersystems.com
2011-01-18 23:00:02 +00:00
Christian Grothoff fe4e71ecaa client certs and basic auth support, unmodified patch from MS 2010-12-25 20:58:06 +00:00
Christian Grothoff bb9de15b30 Re: [libmicrohttpd] Cleanup callback isn't called
From: 
Erik Slagter <erik@slagter.name>
  To: 
Christian Grothoff <grothoff@net.in.tum.de>
  CC: 
libmicrohttpd@gnu.org
  Date: 
Yesterday 17:31:46
   
  Spam Status: Spamassassin 0% probability of being spam.

Full report:
Probability=No, score=-2.6 required=7.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VERIFIED autolearn=ham version=3.2.5-tuminfo_1  
> >> I think I found & fixed the issue in SVN 12778.  Please try SVN HEAD and
> > > report if it fixes the problem.

> > Okay, will do so. But first I'll be on vacation for two weeks.

> Sure.

The issue indeed has been solved. It's quite a pity the distribution's
packages lag behind by ages, so again I'll have to make my own packages
now.

I've run into another problem and also I think I have found the cause.

When a connection is closed by the peer, my application tends to
segfault.

GDB says:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6a6c710 (LWP 27005)]
0x00007ffff77a4db0 in pthread_mutex_lock () from /lib64/libpthread.so.0
Missing separate debuginfos, use: debuginfo-install glibc-2.11.2-1.x86_64 libgcc-4.4.4-10.fc12.x86_64 libid3tag-0.15.1b-9.fc12.x86_64 libstdc++-4.4.4-10.fc12.x86_64 zlib-1.2.3-23.fc12.x86_64
(gdb) where
#0  0x00007ffff77a4db0 in pthread_mutex_lock () from /lib64/libpthread.so.0
#1  0x00007ffff7bd97ce in MHD_destroy_response (response=0x7ffff7ed5010) at response.c:341
#2  0x00007ffff7bd760f in MHD_cleanup_connections (daemon=0x62eb60) at daemon.c:964
#3  0x00007ffff7bd8fbc in MHD_select_thread (cls=0x62eb60) at daemon.c:1205
#4  0x00007ffff77a2a3a in start_thread () from /lib64/libpthread.so.0
#5  0x00007ffff6d6077d in clone () from /lib64/libc.so.6
#6  0x0000000000000000 in ?? ()

It looks like pos->response is being "destroyed" twice. If I remove one of the instances, the segfault is gone.

Index: src/daemon/daemon.c
===================================================================
--- src/daemon/daemon.c (revision 12985)
+++ src/daemon/daemon.c (working copy)
@@ -952,7 +952,7 @@
                  abort();
                }
             }
-          MHD_destroy_response (pos->response);
+          // MHD_destroy_response (pos->response);
           MHD_pool_destroy (pos->pool);
 #if HTTPS_SUPPORT
           if (pos->tls_session != NULL)
2010-09-15 07:36:41 +00:00
Christian Grothoff 7b221e3a6a initial draft for digest authentication (based on patch R3) 2010-08-22 14:49:48 +00:00
Christian Grothoff 02dc5b39a1 [libmicrohttpd] Patches for Windows version of libmicrohttpd
From: 
Gerrit Telkamp <g.telkamp@domologic.de>
  To: 
libmicrohttpd@gnu.org
  Date: 
Today 11:42:30
  Attachments: 
 libmicrohttpd-windows.patch
   
  It was a bit tricky to build libmicrohttpd (SVN trunk) for Windows. 
I'm using the newest MSYS/MinGW environment (GCC 4.5.1).
I've optimized the autoconf feature, so this should be easier in future. 
Please find enclosed my patches.

In detail:
1- libmicrohttpd needs the "PlibC" library under Windows (libplibc.a). 
Methods of PlibC are referenced by src/daemon/daemon.c.
autoconf assumes that PlibC is installed on the Build environment and 
does not check this.
If PlibC is not installed, the pthreads check (see "acinclude.m4") will 
fail and stops with the wrong error message "Your system is not 
supporting pthreads". This is very confusing.

The patch includes an additional check for PlibC, before pthreads is 
used. The check is only done under cygwin and mingw environments.

Furthermore, an older version of plibc.h was in the include directory. 
This gives some problems if you are using a newer version of the PlibC 
library. So I propose to exclude src/include/plibc.h from the SVN

Files affected:
acinclude.m4 (modified)
configure.ac (modified)
src/include/plibc.h (deleted)

2- setsockopt() uses a different parameter type under Windows ("optval" 
is const char). This caused an error when src/daemon/daemon.c was compiled.

The patch enclosed includes a different call of the setsockopt() on 
Windows machines.
Important: IPV6_V6ONLY is not available on Windows machines < Windows 7! 
So this parameter is "0". But there is a TODO comment, maybe someone has 
an idea how to solve this on Windows XP machines.

Files affected:
src/daemon/daemon.c (modified)

I have tested the patch on a MinGW / MSYS environment only.

Best regards

Gerrit.

libmicrohttpd-windows.patch
2010-08-19 11:27:17 +00:00
Christian Grothoff d728fa1b45 fixing memory leak 2010-08-06 10:52:44 +00:00
Christian Grothoff 761267757c ready for 0.9.0 2010-07-26 16:57:47 +00:00
Christian Grothoff 6d61fa3461 better version handling 2010-04-23 07:57:18 +00:00