gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 04/05: Added calculation of request headers total size


From: gnunet
Subject: [libmicrohttpd] 04/05: Added calculation of request headers total size
Date: Tue, 26 Sep 2023 15:46:57 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 449717db69384cafd740c7324fdf87aeadac22f7
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Tue Sep 19 15:13:51 2023 +0300

    Added calculation of request headers total size
---
 src/microhttpd/connection.c | 22 ++++++++++++++++++++--
 src/microhttpd/internal.h   | 30 ++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 346b4125..0adc15a7 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -4163,6 +4163,19 @@ reset_rq_header_processing_state (struct MHD_Connection 
*c)
 }
 
 
+/**
+ * Switch to request headers (field lines) processing state.
+ * @param c the connection to process
+ */
+_MHD_static_inline void
+switch_to_rq_headers_processing (struct MHD_Connection *c)
+{
+  c->rq.field_lines.start = c->read_buffer;
+  memset (&c->rq.hdrs.hdr, 0, sizeof(c->rq.hdrs.hdr));
+  c->state = MHD_CONNECTION_REQ_HEADERS_RECEIVING;
+}
+
+
 #ifndef MHD_MAX_EMPTY_LINES_SKIP
 /**
  * The maximum number of ignored empty line before the request line
@@ -5614,6 +5627,11 @@ get_req_headers (struct MHD_Connection *c, bool 
process_footers)
   if (! process_footers)
   {
     c->rq.header_size = (size_t) (c->read_buffer - c->rq.method);
+    mhd_assert (NULL != c->rq.field_lines.start);
+    c->rq.field_lines.size =
+      (size_t) ((c->read_buffer - c->rq.field_lines.start) - 1);
+    if ('\r' == *(c->read_buffer - 2))
+      c->rq.field_lines.size--;
     c->state = MHD_CONNECTION_HEADERS_RECEIVED;
 
     if (MHD_BUF_INC_SIZE > c->read_buffer_size)
@@ -6513,8 +6531,8 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       mhd_assert (MHD_CONNECTION_REQ_LINE_RECEIVING >= connection->state);
       break;
     case MHD_CONNECTION_REQ_LINE_RECEIVED:
-      reset_rq_header_processing_state (connection);
-      connection->state = MHD_CONNECTION_REQ_HEADERS_RECEIVING;
+      switch_to_rq_headers_processing (connection);
+      mhd_assert (MHD_CONNECTION_REQ_LINE_RECEIVED != connection->state);
       continue;
     case MHD_CONNECTION_REQ_HEADERS_RECEIVING:
       if (get_req_headers (connection, false))
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 512e313f..e9020cf9 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -1041,6 +1041,26 @@ union MHD_HeadersProcessing
   struct MHD_HeaderProcessing hdr;
 };
 
+
+/**
+ * The union of text staring point and the size of the text
+ */
+union MHD_StartOrSize
+{
+  /**
+   * The starting point of the text.
+   * Valid when the text is being processed and the end of the text
+   * is not yet determined.
+   */
+  const char *start;
+  /**
+   * The size of the text.
+   * Valid when the text has been processed and the end of the text
+   * is known.
+   */
+  size_t size;
+};
+
 /**
  * Request-specific values.
  *
@@ -1103,6 +1123,16 @@ struct MHD_Request
    */
   size_t header_size;
 
+  /**
+   * The union of the size of all request field lines (headers) and
+   * the starting point of the first request field line (the first header).
+   * Until #MHD_CONNECTION_HEADERS_RECEIVED the @a start member is valid,
+   * staring with #MHD_CONNECTION_HEADERS_RECEIVED the @a size member is valid.
+   * The size includes CRLF (or LR) characters, but does not include
+   * the terminating empty line.
+   */
+  union MHD_StartOrSize field_lines;
+
   /**
    * How many more bytes of the body do we expect
    * to read? #MHD_SIZE_UNKNOWN for unknown.

-- 
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]