Don't provide get_header() with the whole client state
[privoxy.git] / parsers.c
index 3b08cf9..77568b8 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 1.121 2008/01/05 21:37:03 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.126 2008/05/03 16:40:45 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/parsers.c,v $
@@ -44,6 +44,26 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.121 2008/01/05 21:37:03 fabiankei
  *
  * Revisions   :
  *    $Log: parsers.c,v $
+ *    Revision 1.126  2008/05/03 16:40:45  fabiankeil
+ *    Change content_filters_enabled()'s parameter from
+ *    csp->action to action so it can be also used in the
+ *    CGI code. Don't bother checking if there are filters
+ *    loaded, as that's somewhat besides the point.
+ *
+ *    Revision 1.125  2008/04/17 14:40:49  fabiankeil
+ *    Provide get_http_time() with the buffer size so it doesn't
+ *    have to blindly assume that the buffer is big enough.
+ *
+ *    Revision 1.124  2008/04/16 16:38:21  fabiankeil
+ *    Don't pass the whole csp structure to flush_socket()
+ *    when it only needs a file descriptor and a buffer.
+ *
+ *    Revision 1.123  2008/03/29 12:13:46  fabiankeil
+ *    Remove send-wafer and send-vanilla-wafer actions.
+ *
+ *    Revision 1.122  2008/03/28 15:13:39  fabiankeil
+ *    Remove inspect-jpegs action.
+ *
  *    Revision 1.121  2008/01/05 21:37:03  fabiankeil
  *    Let client_range() also handle Request-Range headers
  *    which apparently are still supported by many servers.
@@ -853,7 +873,6 @@ static jb_err server_last_modified      (struct client_state *csp, char **header
 static jb_err server_content_disposition(struct client_state *csp, char **header);
 
 static jb_err client_host_adder       (struct client_state *csp);
-static jb_err client_cookie_adder     (struct client_state *csp);
 static jb_err client_xtra_adder       (struct client_state *csp);
 static jb_err connection_close_adder  (struct client_state *csp); 
 
@@ -915,7 +934,6 @@ const struct parsers server_patterns_light[] = {
 
 const add_header_func_ptr add_client_headers[] = {
    client_host_adder,
-   client_cookie_adder,
    client_xtra_adder,
    /* Temporarily disabled:    client_accept_encoding_adder, */
    connection_close_adder,
@@ -927,16 +945,6 @@ const add_header_func_ptr add_server_headers[] = {
    NULL
 };
 
-/* The vanilla wafer. */
-static const char VANILLA_WAFER[] =
-   "NOTICE=TO_WHOM_IT_MAY_CONCERN_"
-   "Do_not_send_me_any_copyrighted_information_other_than_the_"
-   "document_that_I_am_requesting_or_any_of_its_necessary_components._"
-   "In_particular_do_not_send_me_any_cookies_that_"
-   "are_subject_to_a_claim_of_copyright_by_anybody._"
-   "Take_notice_that_I_refuse_to_be_bound_by_any_license_condition_"
-   "(copyright_or_otherwise)_applying_to_any_cookie._";
-
 /*********************************************************************
  *
  * Function    :  flush_socket
@@ -945,7 +953,7 @@ static const char VANILLA_WAFER[] =
  *
  * Parameters  :
  *          1  :  fd = file descriptor of the socket to read
- *          2  :  csp = Current client state (buffers, headers, etc...)
+ *          2  :  iob = The I/O buffer to flush, usually csp->iob.
  *
  * Returns     :  On success, the number of bytes written are returned (zero
  *                indicates nothing was written).  On error, -1 is returned,
@@ -955,9 +963,8 @@ static const char VANILLA_WAFER[] =
  *                file, the results are not portable.
  *
  *********************************************************************/
-int flush_socket(jb_socket fd, struct client_state *csp)
+int flush_socket(jb_socket fd, struct iob *iob)
 {
-   struct iob *iob = csp->iob;
    int len = iob->eod - iob->cur;
 
    if (len <= 0)
@@ -1432,7 +1439,7 @@ jb_err decompress_iob(struct client_state *csp)
  * Description :  This (odd) routine will parse the csp->iob
  *
  * Parameters  :
- *          1  :  csp = Current client state (buffers, headers, etc...)
+ *          1  :  iob = The I/O buffer to parse, usually csp->iob.
  *
  * Returns     :  Any one of the following:
  *
@@ -1442,11 +1449,9 @@ jb_err decompress_iob(struct client_state *csp)
  *          a complete header line.
  *
  *********************************************************************/
-char *get_header(struct client_state *csp)
+char *get_header(struct iob *iob)
 {
-   struct iob *iob;
    char *p, *q, *ret;
-   iob = csp->iob;
 
    if ((iob->cur == NULL)
       || ((p = strchr(iob->cur, '\n')) == NULL))
@@ -2589,7 +2594,7 @@ static jb_err server_last_modified(struct client_state *csp, char **header)
       /*
        * Setting Last-Modified Header to now.
        */
-      get_http_time(0, buf);
+      get_http_time(0, buf, sizeof(buf));
       freez(*header);
       *header = strdup("Last-Modified: ");
       string_append(header, buf);   
@@ -3474,7 +3479,7 @@ jb_err client_x_filter(struct client_state *csp, char **header)
  *********************************************************************/
 static jb_err client_range(struct client_state *csp, char **header)
 {
-   if (content_filters_enabled(csp))
+   if (content_filters_enabled(csp->action))
    {
       log_error(LOG_LEVEL_HEADER, "Content filtering is enabled."
          " Crunching: \'%s\' to prevent range-mismatch problems.", *header);
@@ -3538,69 +3543,6 @@ static jb_err client_host_adder(struct client_state *csp)
 }
 
 
-/*********************************************************************
- *
- * Function    :  client_cookie_adder
- *
- * Description :  Used in the add_client_headers list to add "wafers".
- *                Called from `sed'.
- *
- * Parameters  :
- *          1  :  csp = Current client state (buffers, headers, etc...)
- *
- * Returns     :  JB_ERR_OK on success, or
- *                JB_ERR_MEMORY on out-of-memory error.
- *
- *********************************************************************/
-jb_err client_cookie_adder(struct client_state *csp)
-{
-   char *tmp;
-   struct list_entry *wafer;
-   struct list_entry *wafer_list;
-   jb_err err;
-
-   /*
-    * If the user has not supplied any wafers, and the user has not
-    * told us to suppress the vanilla wafer, then send the vanilla wafer.
-    */
-   if ((0 != (csp->action->flags & ACTION_VANILLA_WAFER))
-      && list_is_empty(csp->action->multi[ACTION_MULTI_WAFER]))
-   {
-      enlist(csp->action->multi[ACTION_MULTI_WAFER], VANILLA_WAFER);
-   }
-
-   wafer_list = csp->action->multi[ACTION_MULTI_WAFER]->first;
-
-   if (NULL == wafer_list)
-   {
-      /* Nothing to do */
-      return JB_ERR_OK;
-   }
-
-   tmp = strdup("Cookie: ");
-
-   for (wafer = wafer_list; (NULL != tmp) && (NULL != wafer); wafer = wafer->next)
-   {
-      if (wafer != wafer_list)
-      {
-         /* As this isn't the first wafer, we need a delimiter. */
-         string_append(&tmp, "; ");
-      }
-      string_join(&tmp, cookie_encode(wafer->str));
-   }
-
-   if (tmp == NULL)
-   {
-      return JB_ERR_MEMORY;
-   }
-
-   log_error(LOG_LEVEL_HEADER, "addh: %s", tmp);
-   err = enlist(csp->headers, tmp);
-   free(tmp);
-   return err;
-}
-
-
 #if 0
 /*********************************************************************
  *