libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 25e0d426214de820a2590f5895622ac0583a3c42
parent 2d37df8af0103f2c22180259a278c1cab64cc36f
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 24 Jan 2012 15:08:41 +0000

add check for sin_len

Diffstat:
MChangeLog | 4++++
Mconfigure.ac | 12++++++++++++
Msrc/daemon/daemon.c | 6++++++
Msrc/include/microhttpd.h | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/testcurl/daemontest_get.c | 2+-
5 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Tue Jan 24 16:07:53 CET 2012 + Added configure check for sin_len in 'struct sockaddr' and adding + code to initialize this field if it exists now. -CG + Mon Jan 23 14:02:26 CET 2012 Fixed double-free if specified cipher was not valid (during MHD_daemon_start). Releasing 0.9.18. -CG diff --git a/configure.ac b/configure.ac @@ -64,6 +64,18 @@ AM_PROG_CC_C_O AC_LIBTOOL_WIN32_DLL AC_PROG_LIBTOOL AC_C_BIGENDIAN + + +AC_CHECK_MEMBER([struct sockaddr_in.sin_len], + [ AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [Do we have sockaddr_in.sin_len?]) + ], + [], + [ + #include <sys/types.h> + #include <sys/socket.h> + #include <netinet/in.h> + ]) + AC_CHECK_PROG(HAVE_CURL_BINARY,[curl],true,false) AM_CONDITIONAL(HAVE_CURL_BINARY,$HAVE_CURL_BINARY) diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -2187,6 +2187,9 @@ MHD_start_daemon_va (unsigned int options, memset (&servaddr6, 0, sizeof (struct sockaddr_in6)); servaddr6.sin6_family = AF_INET6; servaddr6.sin6_port = htons (port); +#if HAVE_SOCKADDR_IN_SIN_LEN + servaddr6.sin6_len = sizeof (struct sockaddr_in6); +#endif servaddr = (struct sockaddr *) &servaddr6; } else @@ -2195,6 +2198,9 @@ MHD_start_daemon_va (unsigned int options, memset (&servaddr4, 0, sizeof (struct sockaddr_in)); servaddr4.sin_family = AF_INET; servaddr4.sin_port = htons (port); +#if HAVE_SOCKADDR_IN_SIN_LEN + servaddr4.sin_len = sizeof (struct sockaddr_in); +#endif servaddr = (struct sockaddr *) &servaddr4; } } diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -1378,6 +1378,69 @@ MHD_create_response_from_fd_at_offset (size_t size, /** + * Function called after a protocol upgrade response was sent + * successfully and the socket should now be controlled by some + * protocol other than HTTP. Note that from this point on, MHD will + * consider this connection to be "complete", so it will no longer be + * counted as an active connection for the + * MHD_OPTION_PER_IP_CONNECTION_LIMIT or the + * MHD_OPTION_CONNECTION_LIMIT. After this function returns, the + * MHD_RequestCompletedCallback will be called and all resources of + * the connection (except for the socket itself) will be released. + * + * @param cls closure + * @param connection original HTTP connection handle, + * giving the function a last chance + * to inspect the original HTTP request + * @param con_cls value as set by the last call to the + * MHD_AccessHandlerCallback; will afterwards + * be also given to the MHD_RequestCompletedCallback + * @param upgrade_socket TCP socket that was upgraded from HTTP + * to some other protocol. This function must + * take over the communication and is ultimately + * responsible for closing the socket. + */ +typedef void (*MHD_UpgradeHandler)(void *cls, + struct MHD_Connection *connection, + void **con_cls, + int upgrade_socket); + + +/** + * Create a response object that can be used for 101 UPGRADE + * responses, for example to implement websockets. After sending the + * response, control over the socket is given to the callback (which + * can then, for example, start some bi-directional communication). + * If the response is queued for multiple connections, the callback + * will be called with a socket for each connection. The callback + * will ONLY be called if the response header was successfully passed + * to the OS; if there are communication errors before, the usual MHD + * connection error handling code will be performed. + * + * Setting the correct HTTP code (i.e. MHD_HTTP_SWITCHING_PROTOCOLS) + * and setting correct HTTP headers for the upgrade must be done + * manually (this way, it is possible to implement most existing + * WebSocket version using this API; in fact, this API might be useful + * for any protocol switch, not just web sockets). Note that + * draft-ietf-hybi-thewebsocketprotocol-00 cannot be implemented this + * way as the header "HTTP/1.1 101 WebSocket Protocol Handshake" + * cannot be generated; instead, MHD will always produce "HTTP/1.1 101 + * Switching Protocols" (if the response 101 is used). + * + * As usual, the response object can be extended with header + * information and then be used any number of times (as long as the + * header information is not connection-specific). + * + * @param upgrade_handler function to call with the 'upgraded' socket + * @param upgrade_handler_cls closure for 'upgrade_handler' + * @return NULL on error (i.e. invalid arguments, out of memory) + */ +struct MHD_Response * +MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, + void *upgrade_handler_cls); + + +/** * Destroy a response object and associated resources. Note that * libmicrohttpd may keep some of the resources around if the response * is still in the queue for some clients, so the memory may not diff --git a/src/testcurl/daemontest_get.c b/src/testcurl/daemontest_get.c @@ -257,7 +257,7 @@ testExternalGet () fd_set ws; fd_set es; int max; - int running; + int running; struct CURLMsg *msg; time_t start; struct timeval tv;