Hilight a few more log messages in the Windows log viewer.
[privoxy.git] / parsers.c
index 489aa38..1fb9983 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 1.205 2009/08/19 15:26:36 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.208 2009/09/06 14:10:07 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/parsers.c,v $
@@ -1754,15 +1754,45 @@ static jb_err client_keep_alive(struct client_state *csp, char **header)
 }
 
 
+/*********************************************************************
+ *
+ * Function    :  get_content_length
+ *
+ * Description :  Gets the content length specified in a
+ *                Content-Length header.
+ *
+ * Parameters  :
+ *          1  :  header = The Content-Length header.
+ *          2  :  length = Storage to return the value.
+ *
+ * Returns     :  JB_ERR_OK on success, or
+ *                JB_ERR_PARSE if no value is recognized.
+ *
+ *********************************************************************/
+static jb_err get_content_length(const char *header, unsigned long long *length)
+{
+   assert(header[14] == ':');
+
+#ifdef _WIN32
+   assert(sizeof(unsigned long long) > 4);
+   if (1 != sscanf(header+14, ": %I64u", length))
+#else
+   if (1 != sscanf(header+14, ": %llu", length))
+#endif
+   {
+      return JB_ERR_PARSE;
+   }
+
+   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.
@@ -1780,19 +1810,13 @@ static jb_err client_save_content_length(struct client_state *csp, char **header
 
    assert(*(*header+14) == ':');
 
-#ifdef _WIN32
-   if (1 != sscanf(*header+14, ": %I64u", &content_length))
-#else
-   if (1 != sscanf(*header+14, ": %llu", &content_length))
-#endif
+   if (JB_ERR_OK != get_content_length(*header, &content_length))
    {
       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;
    }
 
@@ -2265,11 +2289,7 @@ static jb_err server_save_content_length(struct client_state *csp, char **header
 
    assert(*(*header+14) == ':');
 
-#ifdef _WIN32
-   if (1 != sscanf(*header+14, ": %I64u", &content_length))
-#else
-   if (1 != sscanf(*header+14, ": %llu", &content_length))
-#endif
+   if (JB_ERR_OK != get_content_length(*header, &content_length))
    {
       log_error(LOG_LEVEL_ERROR, "Crunching invalid header: %s", *header);
       freez(*header);