Ver código fonte

-define HTTPS-structures for upgrade only when we have upgrade

Christian Grothoff 9 anos atrás
pai
commit
b48801f80b
3 arquivos alterados com 41 adições e 32 exclusões
  1. 11 1
      src/microhttpd/daemon.c
  2. 18 18
      src/microhttpd/internal.h
  3. 12 13
      src/microhttpd/response.c

+ 11 - 1
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;
 }

+ 18 - 18
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.
    */
@@ -905,13 +912,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).
    */
@@ -932,7 +932,7 @@ struct MHD_UpgradeResponseHandle
    * IO-state of the @e connection's socket.
    */
   enum MHD_EpollState celi_client;
-
+#endif
 
 };
 
@@ -1027,16 +1027,6 @@ struct MHD_Daemon
   struct MHD_Connection *eready_tail;
 #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
@@ -1283,6 +1273,16 @@ struct MHD_Daemon
   uint16_t port;
 
 #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.
    */

+ 12 - 13
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,