Added support for linking with POSIX threads library
[privoxy.git] / parsers.c
index 359f6c5..11b511e 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 1.12 2001/05/31 17:33:13 oes Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.17 2001/06/29 21:45:41 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/parsers.c,v $
@@ -41,6 +41,26 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.12 2001/05/31 17:33:13 oes Exp $"
  *
  * Revisions   :
  *    $Log: parsers.c,v $
+ *    Revision 1.17  2001/06/29 21:45:41  oes
+ *    Indentation, CRLF->LF, Tab-> Space
+ *
+ *    Revision 1.16  2001/06/29 13:32:42  oes
+ *    - Fixed a comment
+ *    - Adapted free_http_request
+ *    - Removed logentry from cancelled commit
+ *
+ *    Revision 1.15  2001/06/03 19:12:38  oes
+ *    deleted const struct interceptors
+ *
+ *    Revision 1.14  2001/06/01 18:49:17  jongfoster
+ *    Replaced "list_share" with "list" - the tiny memory gain was not
+ *    worth the extra complexity.
+ *
+ *    Revision 1.13  2001/05/31 21:30:33  jongfoster
+ *    Removed list code - it's now in list.[ch]
+ *    Renamed "permission" to "action", and changed many features
+ *    to use the actions file rather than the global config.
+ *
  *    Revision 1.12  2001/05/31 17:33:13  oes
  *
  *    CRLF -> LF
@@ -194,6 +214,7 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.12 2001/05/31 17:33:13 oes Exp $"
 #include "errlog.h"
 #include "jbsockets.h"
 #include "miscutil.h"
+#include "cgi.h"
 
 const char parsers_h_rcs[] = PARSERS_H_VERSION;
 
@@ -232,25 +253,12 @@ const struct parsers client_patterns[] = {
    { NULL,                       0,    NULL }
 };
 
-const struct interceptors intercept_patterns[] = {
-   { "show-proxy-args",    14, show_proxy_args },
-   { "ijb-send-banner",    14, ijb_send_banner },
-#ifdef TRUST_FILES
-   { "ij-untrusted-url",   15, ij_untrusted_url },
-#endif /* def TRUST_FILES */
-   { "show-url-info",      13, ijb_show_url_info },
-   { NULL, 0, NULL }
-};
 
 const struct parsers server_patterns[] = {
    { "set-cookie:",        11, server_set_cookie },
    { "connection:",        11, crumble },
-#if defined(PCRS) || defined(KILLPOPUPS)
    { "Content-Type:",      13, content_type },
-#endif /* defined(PCRS) || defined(KILLPOPUPS) */
-#ifdef PCRS
    { "Content-Length:",    15, content_length },
-#endif /* def PCRS */
    { NULL, 0, NULL }
 };
 
@@ -511,6 +519,7 @@ void free_http_request(struct http_request *http)
    freez(http->hostport);
    freez(http->path);
    freez(http->ver);
+   freez(http->host_ip_addr_str);
 
 }
 
@@ -540,7 +549,6 @@ void parse_http_request(char *req, struct http_request *http, struct client_stat
    http->cmd = strdup(req);
 
    buf = strdup(req);
-
    n = ssplit(buf, " \r\n", v, SZ(v), 1, 1);
 
    if (n == 3)
@@ -602,11 +610,29 @@ void parse_http_request(char *req, struct http_request *http, struct client_stat
             url = NULL;
          }
 
-         if (url && (p = strchr(url, '/')))
+         if (url)
          {
-            http->path = strdup(p);
-            *p = '\0';
-            http->hostport = strdup(url);
+            if (p = strchr(url, '/'))
+            {
+               http->path = strdup(p);
+               *p = '\0';
+               http->hostport = strdup(url);
+            }
+            /* 
+             * Repair broken HTTP requests that don't contain a path
+             */
+            else
+            {
+               /* Repair hostport & path */
+               http->path = strdup("/");
+               http->hostport = strdup(url);
+
+               /* Even repair cmd in case we're just forwarding. Boy are we nice ;-)  */
+               freez(http->cmd);
+               http->cmd = strsav(http->cmd, http->gpc);
+               http->cmd = strsav(http->cmd, " / ");
+               http->cmd = strsav(http->cmd, http->ver);
+            }
          }
       }
    }
@@ -688,8 +714,6 @@ char *crumble(const struct parsers *v, char *s, struct client_state *csp)
 }
 
 
-#if defined(PCRS) || defined(KILLPOPUPS)
-
 /*********************************************************************
  *
  * Function    :  content_type
@@ -706,24 +730,24 @@ char *crumble(const struct parsers *v, char *s, struct client_state *csp)
  *********************************************************************/
 char *content_type(const struct parsers *v, char *s, struct client_state *csp)
 {
-   if (strstr (s, " text/") || strstr (s, "application/x-javascript"))
-      csp->is_text = 1;
+   if (strstr(s, " text/") || strstr(s, "application/x-javascript"))
+      csp->content_type = CT_TEXT;
+   else if (strstr(s, " image/gif"))
+      csp->content_type = CT_GIF;
    else
-      csp->is_text = 0;
+      csp->content_type = 0;
 
    return(strdup(s));
 
 }
-#endif /* defined(PCRS) || defined(KILLPOPUPS) */
 
 
-#ifdef PCRS
 /*********************************************************************
  *
  * Function    :  content_length
  *
- * Description :  Crunch Content-Length header if & only if we are
- *                filtering this page through PCRS.
+ * Description :  Adjust Content-Length header if we modified
+ *                the body.
  *
  * Parameters  :
  *          1  :  v = ignored
@@ -736,19 +760,19 @@ char *content_type(const struct parsers *v, char *s, struct client_state *csp)
 char *content_length(const struct parsers *v, char *s, struct client_state *csp)
 {
    if (csp->content_length != 0) /* Content has been modified */
-       {
-          s = (char *) zalloc(100);
-          sprintf(s, "Content-Length: %d", csp->content_length);
-               log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", csp->content_length);
-          return(s);
-       }
+   {
+      s = (char *) zalloc(100);
+      sprintf(s, "Content-Length: %d", csp->content_length);
+
+       log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", csp->content_length);
+      return(s);
+   }
    else
    {
       return(strdup(s));
    }
-}
 
-#endif /* def PCRS */
+}
 
 
 /*********************************************************************
@@ -1102,7 +1126,6 @@ char *client_accept(const struct parsers *v, char *s, struct client_state *csp)
 void client_cookie_adder(struct client_state *csp)
 {
    struct list *lst;
-   struct list_share *lsts;
    char *tmp = NULL;
    char *e;
 
@@ -1115,14 +1138,14 @@ void client_cookie_adder(struct client_state *csp)
       tmp = strsav(tmp, lst->str);
    }
 
-   for (lsts = csp->action->multi[ACTION_MULTI_WAFER]->next;  lsts ; lsts = lsts->next)
+   for (lst = csp->action->multi[ACTION_MULTI_WAFER]->next;  lst ; lst = lst->next)
    {
       if (tmp)
       {
          tmp = strsav(tmp, "; ");
       }
 
-      if ((e = cookie_encode(lsts->str)))
+      if ((e = cookie_encode(lst->str)))
       {
          tmp = strsav(tmp, e);
          freez(e);
@@ -1158,12 +1181,12 @@ void client_cookie_adder(struct client_state *csp)
  *********************************************************************/
 void client_xtra_adder(struct client_state *csp)
 {
-   struct list_share *l = csp->action->multi[ACTION_MULTI_ADD_HEADER];
+   struct list *lst = csp->action->multi[ACTION_MULTI_ADD_HEADER];
 
-   for (l = l->next; l ; l = l->next)
+   for (lst = lst->next; lst ; lst = lst->next)
    {
-      log_error(LOG_LEVEL_HEADER, "addh: %s", l->str);
-      enlist(csp->headers, l->str);
+      log_error(LOG_LEVEL_HEADER, "addh: %s", lst->str);
+      enlist(csp->headers, lst->str);
    }
 
 }