Jelajahi Sumber

addressing 1433

Christian Grothoff 17 tahun lalu
induk
melakukan
82381396ff

+ 14 - 13
README

@@ -70,18 +70,18 @@ reasonably complete.
 
 Missing features:
 =================
+- MHD_get_daemon_info is not implemented
 - SSL code is still too large:
-  - plenty of dead or unnecessary code imported from gnuTLS
-  => hunt for more dead code!
-  - some code is replicated (also in libgcrypt)
-  - libgcrypt is used, and is also bloated
+  * libgcrypt is used, and is also bloated
   => integrate required portions of libgcrypt into our tree
      instead of linking against it
+  * still some bloat in the SSL code;
+    consider removing "client" functionality
+  * most likely some headers declare functions, constants 
+    and types that are no longer present or used
+  * possibly other dead code
 - Make sure SSL works on non-GNU/Linux platforms
 
-- MHD_tls_connection_close is not called in any testcase!???
-  (is it used properly in the code!?)
-
 
 Untested features:
 ==================
@@ -99,12 +99,13 @@ Untested features:
 
 Functions not covered by "make check":
 ======================================
-- MHD_get_connection_values is not called in any testcase
-- MHD_set_connection_value is not called in any testcase
-- parse_cookie_header is not tested by any testcase
-- parse_arguments is not tested by any testcase
-- MHD_del_response_header is not called by any testcase
-- MHD_get_response_headers is not called by any testcase
+- MHD_get_connection_values
+- MHD_set_connection_value
+- parse_cookie_header
+- parse_arguments
+- MHD_del_response_header 
+- MHD_get_response_headers
+- MHD_tls_connection_close
 
 
 Missing documentation:

+ 2 - 2
configure.ac

@@ -21,8 +21,8 @@
 #
 #
 AC_PREREQ(2.57)
-AC_INIT([libmicrohttpd], [0.4.0pre0],[[email protected]])
-AM_INIT_AUTOMAKE([libmicrohttpd], [0.4.0pre0])
+AC_INIT([libmicrohttpd], [0.4.0],[[email protected]])
+AM_INIT_AUTOMAKE([libmicrohttpd], [0.4.0])
 AM_CONFIG_HEADER([MHD_config.h])
 
 AH_TOP([#define _GNU_SOURCE  1])

+ 21 - 4
doc/microhttpd.texi

@@ -292,6 +292,27 @@ the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6},
 otherwise to a @code{struct sockaddr_in}.  If this option is not specified,
 the daemon will listen to incomming connections from anywhere.
 
+@item MHD_OPTION_URI_LOG_CALLBACK
+Specify a function that should be called before parsing the URI from
+the client.  The specified callback function can be used for processing
+the URI (including the options) before it is parsed.  The URI after
+parsing will no longer contain the options, which maybe inconvenient for
+logging.  This option should be followed by two arguments, the first
+one must be of the form
+@example
+ void * my_logger(void * cls, const char * uri)
+@end example
+where the return value will be passed as
+@code{*con_cls} in calls to the @code{MHD_AccessHandlerCallback}
+when this request is processed later; returning a
+value of NULL has no special significance; (however,
+note that if you return non-NULL, you can no longer
+rely on the first call to the access handler having
+@code{NULL == *con_cls on entry} on entry)
+@code{cls} will be set to the second argument following
+MHD_OPTION_URI_LOG_CALLBACK.  Finally, @code{uri} will
+be the 0-terminated URI of the request.
+
 @item MHD_OPTION_HTTPS_MEM_KEY
 Memory pointer to the private key to be used by the
 HTTPS daemon.  This option should be followed by an
@@ -419,10 +440,6 @@ all builds of MHD.
 
 @item MHD_GNUTLS_CIPHER_ARCFOUR_40
 
-@item MHD_GNUTLS_CIPHER_CAMELLIA_128_CBC
-
-@item MHD_GNUTLS_CIPHER_CAMELLIA_256_CBC
-
 @item MHD_GNUTLS_CIPHER_RC2_40_CBC
 
 @item MHD_GNUTLS_CIPHER_DES_CBC

+ 1 - 1
src/daemon/Makefile.am

@@ -9,7 +9,7 @@ AM_CPPFLAGS = \
 
 if HAVE_GNU_LD
 #  If you want to debug with gdb, comment out this line:
-#  retaincommand=-Wl,--retain-symbols-file -Wl,$(srcdir)/SYMBOLS
+  retaincommand=-Wl,--retain-symbols-file -Wl,$(srcdir)/SYMBOLS
 endif
 
 EXTRA_DIST = SYMBOLS

+ 22 - 5
src/daemon/connection.c

@@ -275,12 +275,14 @@ need_100_continue (struct MHD_Connection *connection)
 }
 
 /**
- * A serious error occured, close the
- * connection (and notify the application).
+ * Close the given connection and give the
+ * specified termination code to the user.
  */
-static void
-connection_close_error (struct MHD_Connection *connection)
+void 
+MHD_connection_close (struct MHD_Connection *connection,
+		      enum MHD_RequestTerminationCode termination_code)
 {
+
   SHUTDOWN (connection->socket_fd, SHUT_RDWR);
   CLOSE (connection->socket_fd);
   connection->socket_fd = -1;
@@ -290,7 +292,18 @@ connection_close_error (struct MHD_Connection *connection)
                                           daemon->notify_completed_cls,
                                           connection,
                                           &connection->client_context,
-                                          MHD_REQUEST_TERMINATED_WITH_ERROR);
+                                          termination_code);
+}
+
+/**
+ * A serious error occured, close the
+ * connection (and notify the application).
+ */
+static void
+connection_close_error (struct MHD_Connection *connection)
+{
+  MHD_connection_close(connection,
+		       MHD_REQUEST_TERMINATED_WITH_ERROR);
 }
 
 /**
@@ -1024,6 +1037,10 @@ parse_initial_message_line (struct MHD_Connection *connection, char *line)
       httpVersion[0] = '\0';
       httpVersion++;
     }
+  if (connection->daemon->uri_log_callback != NULL)
+    connection->client_context 
+      = connection->daemon->uri_log_callback(connection->daemon->uri_log_callback_cls,
+					     uri);
   args = strstr (uri, "?");
   if (args != NULL)
     {

+ 8 - 0
src/daemon/connection.h

@@ -43,8 +43,16 @@ MHD_connection_get_fdset (struct MHD_Connection *connection,
 void MHD_set_http_calbacks (struct MHD_Connection *connection);
 
 int MHD_connection_handle_read (struct MHD_Connection *connection);
+
 int MHD_connection_handle_write (struct MHD_Connection *connection);
+
 int MHD_connection_handle_idle (struct MHD_Connection *connection);
 
+/**
+ * Close the given connection and give the
+ * specified termination code to the user.
+ */
+void MHD_connection_close (struct MHD_Connection *connection,
+			   enum MHD_RequestTerminationCode termination_code);
 
 #endif

+ 2 - 10
src/daemon/connection_https.c

@@ -100,16 +100,8 @@ MHD_tls_connection_close (struct MHD_Connection *connection,
 {
   MHD__gnutls_bye (connection->tls_session, GNUTLS_SHUT_WR);
   connection->tls_session->internals.read_eof = 1;
-  SHUTDOWN (connection->socket_fd, SHUT_RDWR);
-  CLOSE (connection->socket_fd);
-  connection->socket_fd = -1;
-  connection->state = MHD_CONNECTION_CLOSED;
-  if (connection->daemon->notify_completed != NULL)
-    connection->daemon->notify_completed (connection->
-                                          daemon->notify_completed_cls,
-                                          connection,
-                                          &connection->client_context,
-                                          termination_code);
+  MHD_connection_close(connection,
+		       termination_code);
 }
 
 /**

+ 8 - 11
src/daemon/daemon.c

@@ -274,9 +274,8 @@ MHD_handle_connection (void *data)
                 "Processing thread terminating, closing connection\n");
 #endif
 #endif
-      SHUTDOWN (con->socket_fd, SHUT_RDWR);
-      CLOSE (con->socket_fd);
-      con->socket_fd = -1;
+      MHD_connection_close(con,
+			   MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
     }
   return NULL;
 }
@@ -871,6 +870,10 @@ MHD_start_daemon_va (unsigned int options,
         case MHD_OPTION_SOCK_ADDR:
           servaddr = va_arg (ap, struct sockaddr *);
           break;
+	case MHD_OPTION_URI_LOG_CALLBACK:
+	  retVal->uri_log_callback = va_arg(ap, void* (*)(void * cls, const char* uri));
+	  retVal->uri_log_callback_cls = va_arg(ap, void*);
+	  break;
 #if HTTPS_SUPPORT
         case MHD_OPTION_PROTOCOL_VERSION:
           _set_priority (&retVal->priority_cache->protocol,
@@ -1065,14 +1068,8 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
           MHD_DLOG (daemon, "MHD shutdown, closing active connections\n");
 #endif
 #endif
-          if (daemon->notify_completed != NULL)
-            daemon->notify_completed (daemon->notify_completed_cls,
-                                      daemon->connections,
-                                      &daemon->connections->client_context,
-                                      MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
-          SHUTDOWN (daemon->connections->socket_fd, SHUT_RDWR);
-          CLOSE (daemon->connections->socket_fd);
-          daemon->connections->socket_fd = -1;
+	  MHD_connection_close(daemon->connections,
+			       MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
         }
       MHD_cleanup_connections (daemon);
     }

+ 4 - 0
src/daemon/internal.h

@@ -599,6 +599,10 @@ struct MHD_Daemon
 
   void *notify_completed_cls;
 
+  void * (*uri_log_callback)(void * cls, const char * uri);
+
+  void * uri_log_callback_cls;
+
     /**
      * PID of the select thread (if we have internal select)
      */

+ 28 - 7
src/include/microhttpd.h

@@ -341,13 +341,36 @@ enum MHD_OPTION
    */
   MHD_OPTION_PER_IP_CONNECTION_LIMIT = 5,
 
- /**
-  * Bind daemon to the supplied sockaddr. this option should be followed by a
-  * 'struct sockaddr *'.  If 'MHD_USE_IPv6' is specified, the 'struct sockaddr*'
-  * should point to a 'struct sockaddr_in6', otherwise to a 'struct sockaddr_in'.
-  */
+  /**
+   * Bind daemon to the supplied sockaddr. this option should be followed by a
+   * 'struct sockaddr *'.  If 'MHD_USE_IPv6' is specified, the 'struct sockaddr*'
+   * should point to a 'struct sockaddr_in6', otherwise to a 'struct sockaddr_in'.
+   */
   MHD_OPTION_SOCK_ADDR = 6,
 
+  /**
+   * Specify a function that should be called before parsing the URI from
+   * the client.  The specified callback function can be used for processing
+   * the URI (including the options) before it is parsed.  The URI after
+   * parsing will no longer contain the options, which maybe inconvenient for
+   * logging.  This option should be followed by two arguments, the first
+   * one must be of the form
+   * <pre>
+   *  void * my_logger(void * cls, const char * uri)
+   * </pre>
+   * where the return value will be passed as
+   * (*con_cls) in calls to the MHD_AccessHandlerCallback
+   * when this request is processed later; returning a
+   * value of NULL has no special significance (however,
+   * note that if you return non-NULL, you can no longer
+   * rely on the first call to the access handler having
+   * NULL == *con_cls on entry;)
+   * "cls" will be set to the second argument following
+   * MHD_OPTION_URI_LOG_CALLBACK.  Finally, uri will
+   * be the 0-terminated URI of the request.
+   */
+  MHD_OPTION_URI_LOG_CALLBACK = 7,
+
   /**
    * Memory pointer for the private key (key.pem) to be used by the
    * HTTPS daemon.  This option should be followed by an
@@ -513,8 +536,6 @@ enum MHD_GNUTLS_CipherAlgorithm
   MHD_GNUTLS_CIPHER_AES_128_CBC,
   MHD_GNUTLS_CIPHER_AES_256_CBC,
   MHD_GNUTLS_CIPHER_ARCFOUR_40,
-  MHD_GNUTLS_CIPHER_CAMELLIA_128_CBC,
-  MHD_GNUTLS_CIPHER_CAMELLIA_256_CBC,
   MHD_GNUTLS_CIPHER_RC2_40_CBC = 90,
   MHD_GNUTLS_CIPHER_DES_CBC
 };