libmicrohttpd

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

commit ce6e698b741be754d2e1073b7e4f964d9ec4c36d
parent 994a1c47eca8ee6ac26d13e039f793d6d1083b40
Author: lv-426 <oxcafebaby@yahoo.com>
Date:   Tue, 24 Jun 2008 01:42:07 +0000

fixed some build issues
MHDS state machine

Diffstat:
Msrc/daemon/Makefile.am | 18++++++++----------
Msrc/daemon/connection.c | 93++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Msrc/daemon/connection.h | 1+
Msrc/daemon/daemon.c | 7++++++-
Msrc/daemon/internal.h | 2++
Msrc/examples/Makefile.am | 2+-
6 files changed, 86 insertions(+), 37 deletions(-)

diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am @@ -1,9 +1,3 @@ -SUBDIRS = . - -if ENABLE_HTTPS - SUBDIRS += https -endif - AM_CPPFLAGS = -I$(top_srcdir)/src/include \ -I$(top_srcdir)/src/daemon \ -I$(top_srcdir)/src/daemon/https/lgl \ @@ -24,6 +18,14 @@ EXTRA_DIST = SYMBOLS lib_LTLIBRARIES = \ libmicrohttpd.la +SUBDIRS = +libmicrohttpd_la_LIBADD = + +if ENABLE_HTTPS +SUBDIRS += https . +libmicrohttpd_la_LIBADD += https/libhttps.la +endif + libmicrohttpd_la_SOURCES = \ connection.c connection.h \ reason_phrase.c reason_phrase.h \ @@ -36,10 +38,6 @@ response.c response.h libmicrohttpd_la_LDFLAGS = \ -export-dynamic -version-info 4:3:0 $(retaincommand) -if ENABLE_HTTPS - libmicrohttpd_la_LIBADD = https/libhttps.la -endif - check_PROGRAMS = \ postprocessor_test \ postprocessor_large_test \ diff --git a/src/daemon/connection.c b/src/daemon/connection.c @@ -1477,10 +1477,19 @@ MHDS_connection_handle_read (struct MHD_Connection *connection) while (1) { +#if HAVE_MESSAGES + MHD_DLOG (connection->daemon, "MHDS reached case: %d, l: %d, f: %s\n", + connection->s_state, __LINE__, __FUNCTION__); +#endif switch (connection->s_state) { + /* thest cases shouldn't occur */ case MHDS_CONNECTION_INIT: - case MHDS_HANDSHAKE_COMPLETE: + case MHDS_HANDSHAKE_FAILED: + return MHD_NO; + + case MHDS_REPLY_READY: + /* req read & another came in */ case MHDS_REQUEST_READ: if (MHD_YES == connection->read_closed) { @@ -1488,19 +1497,16 @@ MHDS_connection_handle_read (struct MHD_Connection *connection) continue; } break; - case MHDS_REQUEST_READING: + /* switch to reading state */ + case MHDS_HANDSHAKE_COMPLETE: + case MHDS_REPLY_SENT: + connection->s_state = MHDS_REQUEST_READING; do_read (connection); break; - - /* thest cases shouldn't occur */ - case MHDS_REPLY_READY: + case MHDS_REQUEST_READING: + /* req comes in while sending previous reply - wait until reply sent */ case MHDS_REPLY_SENDING: - case MHDS_HANDSHAKE_FAILED: -#if HAVE_MESSAGES - MHD_DLOG (connection->daemon, "MHDS reached case: %d\n", - connection->s_state); -#endif - return MHD_NO; + break; case MHD_CONNECTION_CLOSED: if (connection->socket_fd != -1) @@ -1752,26 +1758,41 @@ MHD_connection_handle_write (struct MHD_Connection *connection) int MHDS_connection_handle_write (struct MHD_Connection *connection) { + connection->last_activity = time (NULL); + while (1) { +#if HAVE_MESSAGES + MHD_DLOG (connection->daemon, "MHDS reached case: %d, l: %d, f: %s\n", + connection->s_state, __LINE__, __FUNCTION__); +#endif switch (connection->s_state) { + /* these cases shouldn't occur */ case MHDS_CONNECTION_INIT: + // TODO do we have to write back a responce ? case MHDS_HANDSHAKE_FAILED: - case MHDS_HANDSHAKE_COMPLETE: - abort (); + /* we should first exit MHDS_REPLY_SENDING */ + case MHDS_REQUEST_READING: + /* these should go through the idle state at first */ + case MHDS_REQUEST_READ: break; case MHDS_CONNECTION_CLOSED: + if (connection->socket_fd != -1) + connection_close_error (connection); + return MHD_NO; + case MHDS_HANDSHAKE_COMPLETE: + + case MHDS_REPLY_SENDING: do_write (connection); + // TODO check write done break; case MHDS_REPLY_READY: - return MHD_connection_handle_idle (connection); - + /* switch to MHDS_REPLY_SENDING through idle */ break; - } } return MHD_YES; @@ -2107,29 +2128,31 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) } +#if HTTPS_SUPPORT int MHDS_connection_handle_idle (struct MHD_Connection *connection) { unsigned int timeout; const char *end; char *line; + ssize_t msgLength; while (1) { -#if DEBUG_STATES - fprintf (stderr, "`%s' in state %u\n", __FUNCTION__, connection->state); +#if HAVE_MESSAGES + MHD_DLOG (connection->daemon, "MHDS reached case: %d, l: %d, f: %s\n", + connection->s_state, __LINE__, __FUNCTION__); #endif switch (connection->s_state) { + case MHDS_HANDSHAKE_FAILED: + connection->socket_fd = -1; case MHDS_CONNECTION_INIT: - break; - case MHDS_REQUEST_READ: - /* pipe data to HTTP state machine */ + /* wait for request */ + case MHDS_HANDSHAKE_COMPLETE: - memcpy (connection->tls_session->internals.application_data_buffer. - data, connection->read_buffer, - connection->tls_session->internals.application_data_buffer. - length); + case MHDS_REPLY_SENDING: + connection->s_state = MHDS_REPLY_SENT; break; case MHDS_REPLY_READY: @@ -2137,6 +2160,25 @@ MHDS_connection_handle_idle (struct MHD_Connection *connection) memcpy (connection->write_buffer, connection->tls_session->internals.application_data_buffer. data, connection->write_buffer_size); + connection->s_state = MHDS_REPLY_SENDING; + break; + + case MHDS_REQUEST_READING: + // TODO mv handshake here + connection->s_state = MHDS_REQUEST_READ; + + case MHDS_REQUEST_READ: + /* pipe data to HTTP state machine */ + + msgLength + = + connection->tls_session->internals.application_data_buffer.length; + memcpy (connection->tls_session->internals.application_data_buffer. + data, connection->read_buffer, msgLength); + connection->read_buffer_offset = msgLength; + /* pass connection to MHD */ + MHD_connection_handle_idle (connection); + break; case MHDS_CONNECTION_CLOSED: @@ -2161,5 +2203,6 @@ MHDS_connection_handle_idle (struct MHD_Connection *connection) } return MHD_YES; } +#endif /* end of connection.c */ diff --git a/src/daemon/connection.h b/src/daemon/connection.h @@ -27,6 +27,7 @@ #ifndef CONNECTION_H #define CONNECTION_H +#include "config.h" /** * Obtain the select sets for this connection. diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -248,7 +248,7 @@ MHDS_handle_connection (void *data) } // printf ("TLS Handshake completed\n"); - con->state = MHDS_HANDSHAKE_COMPLETE; + con->s_state = MHDS_HANDSHAKE_COMPLETE; MHD_handle_connection (data); } @@ -343,6 +343,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon) CLOSE (s); return MHD_NO; } + + /* apply connection acceptance policy if present */ if ((daemon->apc != NULL) && (MHD_NO == daemon->apc (daemon->apc_cls, addr, addrlen))) { @@ -609,6 +611,8 @@ MHD_select (struct MHD_Daemon *daemon, int may_block) ds = daemon->socket_fd; if (ds == -1) return MHD_YES; + + /* select connection thread handling type */ if (__FD_ISSET (ds, &rs)) MHD_accept_connection (daemon); if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) @@ -621,6 +625,7 @@ MHD_select (struct MHD_Daemon *daemon, int may_block) ds = pos->socket_fd; if (ds != -1) { + // TODO call con->read handler if (FD_ISSET (ds, &rs)) MHD_connection_handle_read (pos); if ((pos->socket_fd != -1) && (FD_ISSET (ds, &ws))) diff --git a/src/daemon/internal.h b/src/daemon/internal.h @@ -308,6 +308,8 @@ enum MHDS_CONNECTION_STATE /* while receiving an HTTP request through the encrypted channel */ MHDS_REPLY_SENDING, + + MHDS_REPLY_SENT, MHDS_CONNECTION_CLOSED }; diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am @@ -12,7 +12,7 @@ fileserver_example \ fileserver_example_external_select if ENABLE_HTTPS - noinst_PROGRAMS += https_server_example +noinst_PROGRAMS += https_server_example endif minimal_example_SOURCES = \