gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (067628c6 -> 4d7d35d8)


From: gnunet
Subject: [libmicrohttpd] branch master updated (067628c6 -> 4d7d35d8)
Date: Sat, 21 Aug 2021 17:41:22 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 067628c6 -fix typo
     new 9d2588d9 enum MHD_CONNECTION_STATE: removed numbers from doxy
     new 55785fe9 enum MHD_CONNECTION_STATE: sorted states
     new 4fb57ae1 Added new connection flag "stop_with_error".
     new 66e6f4f2 connection.c: simplified request line processing, fix
     new 4d7d35d8 build_header_response(): clarified comment

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/connection.c | 106 ++++++++++++++++++++++----------------------
 src/microhttpd/internal.h   |  62 +++++++++++++++-----------
 2 files changed, 91 insertions(+), 77 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index a01ca32e..104df287 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -829,6 +829,7 @@ connection_close_error (struct MHD_Connection *connection,
                         const char *emsg)
 {
 #ifdef HAVE_MESSAGES
+  connection->stop_with_error = true;
   if (NULL != emsg)
     MHD_DLOG (connection->daemon,
               "%s\n",
@@ -865,7 +866,8 @@ connection_close_error_check (struct MHD_Connection 
*connection,
 {
   if ( (NULL != connection->response) &&
        (400 <= connection->responseCode) &&
-       (connection->read_closed) &&
+       (NULL == connection->response->crc) && /* Static response only! */
+       (connection->stop_with_error) &&
        (MHD_CONNECTION_HEADERS_SENDING == connection->state) )
     return; /* An error response was already queued */
 
@@ -1188,9 +1190,7 @@ keepalive_possible (struct MHD_Connection *connection)
   }
 #endif /* UPGRADE_SUPPORT */
 
-  /* TODO: use additional flags, like "error_closure" or
-   * "! read_completed" */
-  if (c->read_closed)
+  if ((c->read_closed) || (c->stop_with_error))
     return MHD_CONN_MUST_CLOSE;
 
   if (0 != (r->flags & MHD_RF_HTTP_1_0_COMPATIBLE_STRICT))
@@ -1872,9 +1872,10 @@ build_header_response (struct MHD_Connection *connection)
   else if (MHD_CONN_USE_KEEPALIVE == c->keepalive)
   {
     use_conn_close = false;
-    /* As "Keep-Alive" is default for HTTP/1.1, add "Connection: keep-alive"
-     * header only if explicitly requested by app (by using response flag),
-     * if request is HTTP/1.0 or if reply is HTTP/1.0. */
+    /* Add "Connection: keep-alive" if request is HTTP/1.0 or
+     * if reply is HTTP/1.0
+     * For HTTP/1.1 add header only if explicitly requested by app
+     * (by response flag), as "Keep-Alive" is default for HTTP/1.1. */
     if ((0 != (r->flags & MHD_RF_SEND_KEEP_ALIVE_HEADER)) ||
         (MHD_HTTP_VER_1_0 == c->http_ver) ||
         (0 != (r->flags & MHD_RF_HTTP_1_0_SERVER)))
@@ -2126,7 +2127,7 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
   enum MHD_Result iret;
 
   connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
-  connection->read_closed = true;
+  connection->stop_with_error = true;
   if (0 != connection->read_buffer_size)
   {
     /* Read buffer is not needed anymore, discard it
@@ -2254,7 +2255,7 @@ MHD_connection_update_event_loop_info (struct 
MHD_Connection *connection)
                                           REQUEST_TOO_BIG);
         continue;
       }
-      if (! connection->read_closed)
+      if (! connection->stop_with_error)
         connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
       else
         connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
@@ -2294,7 +2295,7 @@ MHD_connection_update_event_loop_info (struct 
MHD_Connection *connection)
         }
       }
       if ( (connection->read_buffer_offset < connection->read_buffer_size) &&
-           (! connection->read_closed) )
+           (! connection->stop_with_error) )
         connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
       else
         connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
@@ -2303,7 +2304,7 @@ MHD_connection_update_event_loop_info (struct 
MHD_Connection *connection)
     case MHD_CONNECTION_FOOTER_PART_RECEIVED:
       /* while reading footers, we always grow the
          read buffer if needed, no size-check required */
-      if (connection->read_closed)
+      if (connection->stop_with_error)
       {
         CONNECTION_CLOSE_ERROR (connection,
                                 NULL);
@@ -2930,8 +2931,9 @@ process_request_body (struct MHD_Connection *connection)
         {
           /* malformed encoding */
           CONNECTION_CLOSE_ERROR (connection,
-                                  _ (
-                                    "Received malformed HTTP request (bad 
chunked encoding). Closing connection."));
+                                  _ ("Received malformed HTTP request " \
+                                     "(bad chunked encoding). " \
+                                     "Closing connection."));
           return;
         }
         available -= i;
@@ -3009,8 +3011,9 @@ process_request_body (struct MHD_Connection *connection)
         {
           /* malformed encoding */
           CONNECTION_CLOSE_ERROR (connection,
-                                  _ (
-                                    "Received malformed HTTP request (bad 
chunked encoding). Closing connection."));
+                                  _ ("Received malformed HTTP request " \
+                                     "(bad chunked encoding). " \
+                                     "Closing connection."));
           return;
         }
         /* skip 2nd part of line feed */
@@ -3065,8 +3068,8 @@ process_request_body (struct MHD_Connection *connection)
     {
       /* serious internal error, close connection */
       CONNECTION_CLOSE_ERROR (connection,
-                              _ (
-                                "Application reported internal error, closing 
connection."));
+                              _ ("Application reported internal error, " \
+                                 "closing connection."));
       return;
     }
     if (left_unprocessed > to_be_processed)
@@ -3089,8 +3092,8 @@ process_request_body (struct MHD_Connection *connection)
       if ( (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) &&
            (! connection->suspended) )
         MHD_DLOG (daemon,
-                  _ (
-                    "WARNING: incomplete upload processing and connection not 
suspended may result in hung connection.\n"));
+                  _ ("WARNING: incomplete upload processing and connection " \
+                     "not suspended may result in hung connection.\n"));
 #endif
     }
     processed_size = to_be_processed - left_unprocessed;
@@ -3326,7 +3329,7 @@ parse_connection_headers (struct MHD_Connection 
*connection)
 
     /* die, http 1.1 request without host and we are pedantic */
     connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
-    connection->read_closed = true;
+    connection->stop_with_error = true;
 #ifdef HAVE_MESSAGES
     MHD_DLOG (connection->daemon,
               _ ("Received HTTP 1.1 request without `Host' header.\n"));
@@ -3535,7 +3538,7 @@ MHD_connection_handle_read (struct MHD_Connection 
*connection)
   case MHD_CONNECTION_BODY_RECEIVED:
   case MHD_CONNECTION_FOOTER_PART_RECEIVED:
     /* nothing to do but default action */
-    if (connection->read_closed)
+    if ((connection->read_closed) || (connection->stop_with_error))
     {
       MHD_connection_close_ (connection,
                              MHD_REQUEST_TERMINATED_READ_ERROR);
@@ -4102,34 +4105,32 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
     case MHD_CONNECTION_INIT:
       line = get_next_header_line (connection,
                                    &line_len);
-      /* Check for empty string, as we might want
-         to tolerate 'spurious' empty lines; also
-         NULL means we didn't get a full line yet;
-         line is not 0-terminated here. */
-      if ( (NULL == line) ||
-           (0 == line[0]) )
+      if (NULL != line)
       {
-        if (MHD_CONNECTION_INIT != connection->state)
-          continue;
-        if (connection->read_closed)
+        /* Check for empty string, as we might want
+           to tolerate 'spurious' empty lines */
+        if (0 == line[0])
+          /* TODO: Add MHD option to not tolerate it */
+          continue; /* Process the next line */
+        if (MHD_NO == parse_initial_message_line (connection,
+                                                  line,
+                                                  line_len))
+          CONNECTION_CLOSE_ERROR_CHECK (connection,
+                                        NULL);
+        else
         {
-          CONNECTION_CLOSE_ERROR (connection,
-                                  NULL);
-          continue;
+          mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (connection->http_ver));
+          connection->state = MHD_CONNECTION_URL_RECEIVED;
         }
-        break;
+        continue;
       }
-      if (MHD_NO == parse_initial_message_line (connection,
-                                                line,
-                                                line_len))
-        CONNECTION_CLOSE_ERROR_CHECK (connection,
-                                      NULL);
-      else
+      /* NULL means we didn't get a full line yet */
+      if (connection->stop_with_error)
       {
-        mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (connection->http_ver));
-        connection->state = MHD_CONNECTION_URL_RECEIVED;
+        mhd_assert (MHD_CONNECTION_INIT != connection->state);
+        continue;
       }
-      continue;
+      break;
     case MHD_CONNECTION_URL_RECEIVED:
       line = get_next_header_line (connection,
                                    NULL);
@@ -4137,7 +4138,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       {
         if (MHD_CONNECTION_URL_RECEIVED != connection->state)
           continue;
-        if (connection->read_closed)
+        if (connection->stop_with_error)
         {
           CONNECTION_CLOSE_ERROR (connection,
                                   NULL);
@@ -4169,7 +4170,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       {
         if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED)
           continue;
-        if (connection->read_closed)
+        if (connection->stop_with_error)
         {
           CONNECTION_CLOSE_ERROR (connection,
                                   NULL);
@@ -4216,7 +4217,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
         /* we refused (no upload allowed!) */
         connection->remaining_upload_size = 0;
         /* force close, in case client still tries to upload... */
-        connection->read_closed = true;
+        connection->stop_with_error = true;
       }
       connection->state = (0 == connection->remaining_upload_size)
                           ? MHD_CONNECTION_FOOTERS_RECEIVED
@@ -4242,10 +4243,10 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       if ( (0 == connection->remaining_upload_size) ||
            ( (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) &&
              (0 == connection->read_buffer_offset) &&
-             (connection->read_closed) ) )
+             (connection->stop_with_error) ) )
       {
         if ( (connection->have_chunked_upload) &&
-             (! connection->read_closed) )
+             (! connection->stop_with_error) )
           connection->state = MHD_CONNECTION_BODY_RECEIVED;
         else
           connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
@@ -4261,7 +4262,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       {
         if (connection->state != MHD_CONNECTION_BODY_RECEIVED)
           continue;
-        if (connection->read_closed)
+        if (connection->stop_with_error)
         {
           CONNECTION_CLOSE_ERROR (connection,
                                   NULL);
@@ -4293,7 +4294,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       {
         if (connection->state != MHD_CONNECTION_FOOTER_PART_RECEIVED)
           continue;
-        if (connection->read_closed)
+        if (connection->stop_with_error)
         {
           CONNECTION_CLOSE_ERROR (connection,
                                   NULL);
@@ -4471,7 +4472,8 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       /* Reset connection after complete reply */
       connection_reset (connection,
                         MHD_CONN_USE_KEEPALIVE == connection->keepalive &&
-                        ! connection->read_closed);
+                        ! connection->read_closed &&
+                        ! connection->stop_with_error);
       continue;
     case MHD_CONNECTION_CLOSED:
       cleanup_connection (connection);
@@ -4881,7 +4883,7 @@ MHD_queue_response (struct MHD_Connection *connection,
   {
     /* response was queued "early", refuse to read body / footers or
        further requests! */
-    connection->read_closed = true;
+    connection->stop_with_error = true;
     connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
     connection->remaining_upload_size = 0;
   }
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 1524ced3..a2a454f1 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -569,101 +569,101 @@ enum MHD_CONNECTION_STATE
   MHD_CONNECTION_INIT = 0,
 
   /**
-   * 1: We got the URL (and request type and version).  Wait for a header line.
+   * We got the URL (and request type and version).  Wait for a header line.
    */
   MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1,
 
   /**
-   * 2: We got part of a multi-line request header.  Wait for the rest.
+   * We got part of a multi-line request header.  Wait for the rest.
    */
   MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1,
 
   /**
-   * 3: We got the request headers.  Process them.
+   * We got the request headers.  Process them.
    */
   MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1,
 
   /**
-   * 4: We have processed the request headers.  Send 100 continue.
+   * We have processed the request headers.  Send 100 continue.
    */
   MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1,
 
   /**
-   * 5: We have processed the headers and need to send 100 CONTINUE.
+   * We have processed the headers and need to send 100 CONTINUE.
    */
   MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1,
 
   /**
-   * 6: We have sent 100 CONTINUE (or do not need to).  Read the message body.
+   * We have sent 100 CONTINUE (or do not need to).  Read the message body.
    */
   MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1,
 
   /**
-   * 7: We got the request body.  Wait for a line of the footer.
+   * We got the request body.  Wait for a line of the footer.
    */
   MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1,
 
   /**
-   * 8: We got part of a line of the footer.  Wait for the
+   * We got part of a line of the footer.  Wait for the
    * rest.
    */
   MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1,
 
   /**
-   * 9: We received the entire footer.  Wait for a response to be queued
+   * We received the entire footer.  Wait for a response to be queued
    * and prepare the response headers.
    */
   MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1,
 
   /**
-   * 10: We have prepared the response headers in the writ buffer.
+   * We have prepared the response headers in the writ buffer.
    * Send the response headers.
    */
   MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1,
 
   /**
-   * 11: We have sent the response headers.  Get ready to send the body.
+   * We have sent the response headers.  Get ready to send the body.
    */
   MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
 
   /**
-   * 12: We are ready to send a part of a non-chunked body.  Send it.
+   * We are waiting for the client to provide more
+   * data of a non-chunked body.
    */
-  MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
+  MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_HEADERS_SENT + 1,
 
   /**
-   * 13: We are waiting for the client to provide more
-   * data of a non-chunked body.
+   * We are ready to send a part of a non-chunked body.  Send it.
    */
-  MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
+  MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
 
   /**
-   * 14: We are ready to send a chunk.
+   * We are waiting for the client to provide a chunk of the body.
    */
-  MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
+  MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
 
   /**
-   * 15: We are waiting for the client to provide a chunk of the body.
+   * We are ready to send a chunk.
    */
-  MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
+  MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
 
   /**
-   * 16: We have sent the response body. Prepare the footers.
+   * We have sent the response body. Prepare the footers.
    */
-  MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
+  MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
 
   /**
-   * 17: We have prepared the response footer.  Send it.
+   * We have prepared the response footer.  Send it.
    */
   MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
 
   /**
-   * 18: We have sent the response footer.  Shutdown or restart.
+   * We have sent the response footer.  Shutdown or restart.
    */
   MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1,
 
   /**
-   * 19: This connection is to be closed.
+   * This connection is to be closed.
    */
   MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
 
@@ -1186,6 +1186,18 @@ struct MHD_Connection
    */
   bool read_closed;
 
+  /**
+   * Some error happens during processing the connection therefore this
+   * connection must be closed.
+   * The error may come from the client side (like wrong request format),
+   * from the application side (like data callback returned error), or from
+   * the OS side (like out-of-memory).
+   * The connection cannot be reused for additional requests as the current
+   * request may be incompletely read and it is unclear where is the initial
+   * byte of the next request.
+   */
+  bool stop_with_error;
+
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
   /**
    * Set to `true` if the thread has been joined.

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]