summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-08-28 09:21:39 +0000
committerChristian Grothoff <christian@grothoff.org>2016-08-28 09:21:39 +0000
commitb48801f80b2c640b278aa41be83fd72c8d7787fb (patch)
treee3f86269d62b36731db5f0e2dca9bd7bffb61984
parent642fef8a5b2a4913bd8a97faea0fd227652c9f31 (diff)
-define HTTPS-structures for upgrade only when we have upgrade
-rw-r--r--src/microhttpd/daemon.c12
-rw-r--r--src/microhttpd/internal.h36
-rw-r--r--src/microhttpd/response.c25
3 files changed, 41 insertions, 32 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 79e8ab70..780ba28e 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2185,6 +2185,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
MHD_socket ds;
struct MHD_Connection *pos;
struct MHD_Connection *next;
+ struct MHD_UpgradeResponseHandle *urh;
unsigned int mask = MHD_USE_SUSPEND_RESUME | MHD_USE_EPOLL_INTERNALLY |
MHD_USE_SELECT_INTERNALLY | MHD_USE_POLL_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION;
@@ -2204,7 +2205,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
{
/* we're in epoll mode, the epoll FD stands for
the entire event set! */
- if (!MHD_SCKT_FD_FITS_FDSET_(daemon->epoll_fd, NULL))
+ if (! MHD_SCKT_FD_FITS_FDSET_(daemon->epoll_fd, NULL))
return MHD_NO; /* poll fd too big, fail hard */
if (FD_ISSET (daemon->epoll_fd, read_fd_set))
return MHD_run (daemon);
@@ -2233,6 +2234,15 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
MHD_NO);
}
}
+
+ /* handle upgraded HTTPS connections */
+#if HTTPS_SUPPORT
+ for (urh = daemon->urh_head; NULL != urh; urh = urh->next)
+ {
+ // if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->celi_mhd)) &&
+ // (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->celi_client)) )
+ }
+#endif
MHD_cleanup_connections (daemon);
return MHD_YES;
}
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 047300b1..01d72950 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -894,7 +894,14 @@ struct MHD_Connection
*/
struct MHD_UpgradeResponseHandle
{
+ /**
+ * The connection for which this is an upgrade handle. Note that
+ * because a response may be shared over many connections, this may
+ * not be the only upgrade handle for the response of this connection.
+ */
+ struct MHD_Connection *connection;
+#if HTTPS_SUPPORT
/**
* Kept in a DLL per daemon.
*/
@@ -906,13 +913,6 @@ struct MHD_UpgradeResponseHandle
struct MHD_UpgradeResponseHandle *prev;
/**
- * The connection for which this is an upgrade handle. Note that
- * because a response may be shared over many connections, this may
- * not be the only upgrade handle for the response of this connection.
- */
- struct MHD_Connection *connection;
-
- /**
* The socket we gave to the application (r/w).
*/
MHD_socket app_socket;
@@ -932,7 +932,7 @@ struct MHD_UpgradeResponseHandle
* IO-state of the @e connection's socket.
*/
enum MHD_EpollState celi_client;
-
+#endif
};
@@ -1028,16 +1028,6 @@ struct MHD_Daemon
#endif
/**
- * Head of DLL of upgrade response handles we are processing.
- */
- struct MHD_UpgradeResponseHandle *urh_head;
-
- /**
- * Tail of DLL of upgrade response handles we are processing.
- */
- struct MHD_UpgradeResponseHandle *urh_tail;
-
- /**
* Head of the XDLL of ALL connections with a default ('normal')
* timeout, sorted by timeout (earliest at the tail, most recently
* used connection at the head). MHD can just look at the tail of
@@ -1284,6 +1274,16 @@ struct MHD_Daemon
#if HTTPS_SUPPORT
/**
+ * Head of DLL of upgrade response handles we are processing.
+ */
+ struct MHD_UpgradeResponseHandle *urh_head;
+
+ /**
+ * Tail of DLL of upgrade response handles we are processing.
+ */
+ struct MHD_UpgradeResponseHandle *urh_tail;
+
+ /**
* Desired cipher algorithms.
*/
gnutls_priority_t priority_cache;
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 93803813..5b67b983 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -603,6 +603,7 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
{
case MHD_UPGRADE_ACTION_CLOSE:
/* Application is done with this connection, tear it down! */
+#if HTTPS_SUPPORT
if (0 != (daemon->options & MHD_USE_SSL) )
{
DLL_remove (daemon->urh_head,
@@ -610,13 +611,14 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
urh);
/* FIXME: if running in epoll()-mode, do we have
to remove any of the FDs from any epoll-sets here? */
+ if ( (MHD_INVALID_SOCKET != urh->app_socket) &&
+ (0 != MHD_socket_close_ (urh->app_socket)) )
+ MHD_PANIC ("close failed\n");
+ if ( (MHD_INVALID_SOCKET != urh->mhd_socket) &&
+ (0 != MHD_socket_close_ (urh->mhd_socket)) )
+ MHD_PANIC ("close failed\n");
}
- if ( (MHD_INVALID_SOCKET != urh->app_socket) &&
- (0 != MHD_socket_close_ (urh->app_socket)) )
- MHD_PANIC ("close failed\n");
- if ( (MHD_INVALID_SOCKET != urh->mhd_socket) &&
- (0 != MHD_socket_close_ (urh->mhd_socket)) )
- MHD_PANIC ("close failed\n");
+#endif
MHD_resume_connection (urh->connection);
MHD_connection_close_ (urh->connection,
MHD_REQUEST_TERMINATED_COMPLETED_OK);
@@ -665,6 +667,9 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
urh = malloc (sizeof (struct MHD_UpgradeResponseHandle));
if (NULL == urh)
return MHD_NO;
+ urh->connection = connection;
+ rbo = connection->read_buffer_offset;
+ connection->read_buffer_offset = 0;
#if HTTPS_SUPPORT
if (0 != (daemon->options & MHD_USE_SSL) )
{
@@ -696,9 +701,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
urh->app_socket = sv[0];
urh->mhd_socket = sv[1];
- urh->connection = connection;
- rbo = connection->read_buffer_offset;
- connection->read_buffer_offset = 0;
response->upgrade_handler (response->upgrade_handler_cls,
connection,
connection->client_context,
@@ -720,12 +722,9 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
urh);
return MHD_YES;
}
-#endif
- urh->connection = connection;
urh->app_socket = MHD_INVALID_SOCKET;
urh->mhd_socket = MHD_INVALID_SOCKET;
- rbo = connection->read_buffer_offset;
- connection->read_buffer_offset = 0;
+#endif
response->upgrade_handler (response->upgrade_handler_cls,
connection,
connection->client_context,