In preparation to allow connection reuse after forwarding POST requests, save the...
authorFabian Keil <fk@fabiankeil.de>
Wed, 19 Aug 2009 15:57:13 +0000 (15:57 +0000)
committerFabian Keil <fk@fabiankeil.de>
Wed, 19 Aug 2009 15:57:13 +0000 (15:57 +0000)
jcc.c
parsers.c
project.h

diff --git a/jcc.c b/jcc.c
index faf224f..bb742c5 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.274 2009/07/19 11:19:50 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.275 2009/07/22 22:31:54 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -2398,6 +2398,7 @@ static void serve(struct client_state *csp)
             csp->content_type = 0;
             csp->content_length = 0;
             csp->expected_content_length = 0;
+            csp->expected_client_content_length = 0;
             list_remove_all(csp->headers);
             freez(csp->iob->buf);
             memset(csp->iob, 0, sizeof(csp->iob));
index 9a699ae..489aa38 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 1.204 2009/08/19 15:25:31 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.205 2009/08/19 15:26:36 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/parsers.c,v $
@@ -158,6 +158,7 @@ static jb_err server_save_content_length(struct client_state *csp, char **header
 static jb_err server_keep_alive(struct client_state *csp, char **header);
 static jb_err server_proxy_connection(struct client_state *csp, char **header);
 static jb_err client_keep_alive(struct client_state *csp, char **header);
+static jb_err client_save_content_length(struct client_state *csp, char **header);
 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
 
 static jb_err client_host_adder       (struct client_state *csp);
@@ -204,6 +205,7 @@ static const struct parsers client_patterns[] = {
    { "if-modified-since:",       18,   client_if_modified_since },
 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
    { "Keep-Alive:",              11,   client_keep_alive },
+   { "Content-Length:",          15,   client_save_content_length },
 #else
    { "Keep-Alive:",              11,   crumble },
 #endif
@@ -1750,6 +1752,52 @@ static jb_err client_keep_alive(struct client_state *csp, char **header)
 
    return JB_ERR_OK;
 }
+
+
+/*********************************************************************
+ *
+ * Function    :  client_save_content_length
+ *
+ * Description :  Save the Content-Length sent by the client.
+ *
+ *                XXX: Shares code with the server version
+ *                     that should be factored out.
+ *
+ * Parameters  :
+ *          1  :  csp = Current client state (buffers, headers, etc...)
+ *          2  :  header = On input, pointer to header to modify.
+ *                On output, pointer to the modified header, or NULL
+ *                to remove the header.  This function frees the
+ *                original string if necessary.
+ *
+ * Returns     :  JB_ERR_OK on success, or
+ *                JB_ERR_MEMORY on out-of-memory error.
+ *
+ *********************************************************************/
+static jb_err client_save_content_length(struct client_state *csp, char **header)
+{
+   unsigned long long content_length = 0;
+
+   assert(*(*header+14) == ':');
+
+#ifdef _WIN32
+   if (1 != sscanf(*header+14, ": %I64u", &content_length))
+#else
+   if (1 != sscanf(*header+14, ": %llu", &content_length))
+#endif
+   {
+      log_error(LOG_LEVEL_ERROR, "Crunching invalid header: %s", *header);
+      freez(*header);
+   }
+   else
+   {
+      log_error(LOG_LEVEL_CONNECT,
+         "Setting client content lenght %llu", content_length);
+      csp->expected_client_content_length = content_length;
+   }
+
+   return JB_ERR_OK;
+}
 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
 
 
index f30f4bb..d53aab4 100644 (file)
--- a/project.h
+++ b/project.h
@@ -1,7 +1,7 @@
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
 /** Version string. */
-#define PROJECT_H_VERSION "$Id: project.h,v 1.147 2009/07/14 17:50:34 fabiankeil Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 1.148 2009/07/18 12:20:05 fabiankeil Exp $"
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
@@ -878,11 +878,17 @@ struct client_state
    unsigned long long content_length;
 
 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
+   /* XXX: is this the right location? */
+
    /** Expected length of content after which we
     * should stop reading from the server socket.
     */
-   /* XXX: is this the right location? */
    unsigned long long expected_content_length;
+
+   /** Expected length of content after which we
+    *  should stop reading from the client socket.
+    */
+   unsigned long long expected_client_content_length;
 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
 
 #ifdef FEATURE_TRUST