-const char parsers_rcs[] = "$Id: parsers.c,v 1.4 2001/05/22 18:46:04 oes Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.7 2001/05/27 13:19:06 oes Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
* `client_x_forwarded_adder', `client_xtra_adder',
* `content_type', `crumble', `destroy_list', `enlist',
* `flush_socket', `free_http_request', `get_header',
- * `list_to_text', `match', `parse_http_request', `sed',
+ * `list_to_text', `parse_http_request', `sed',
* and `server_set_cookie'.
*
* Copyright : Written by and Copyright (C) 2001 the SourceForge
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.7 2001/05/27 13:19:06 oes
+ * Patched Joergs solution for the content-length in.
+ *
+ * Revision 1.6 2001/05/26 13:39:32 jongfoster
+ * Only crunches Content-Length header if applying RE filtering.
+ * Without this fix, Microsoft Windows Update wouldn't work.
+ *
+ * Revision 1.5 2001/05/26 00:28:36 jongfoster
+ * Automatic reloading of config file.
+ * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
+ * Most of the global variables have been moved to a new
+ * struct configuration_spec, accessed through csp->config->globalname
+ * Most of the globals remaining are used by the Win32 GUI.
+ *
* Revision 1.4 2001/05/22 18:46:04 oes
*
* - Enabled filtering banners by size rather than URL
{ "connection:", 11, crumble },
#if defined(PCRS) || defined(KILLPOPUPS)
{ "Content-Type:", 13, content_type },
- { "Content-Length:", 15, crumble },
#endif /* defined(PCRS) || defined(KILLPOPUPS) */
+#ifdef PCRS
+ { "Content-Length:", 15, content_length },
+#endif /* def PCRS */
{ NULL, 0, NULL }
};
};
-/*********************************************************************
- *
- * Function : match
- *
- * Description : Do a `strncmpic' on every pattern in pats.
- *
- * Parameters :
- * 1 : buf = a string to match to a list of patterns
- * 2 : pats = list of strings to compare against buf.
- *
- * Returns : Return the matching "struct parsers *",
- * or NULL if no pattern matches.
- *
- *********************************************************************/
-static const struct parsers *match(char *buf, const struct parsers *pats)
-{
- const struct parsers *v;
-
- if (buf == NULL)
- {
- /* hit me */
- log_error(LOG_LEVEL_ERROR, "NULL parameter to match()");
- return(NULL);
- }
-
- for (v = pats; v->str ; v++)
- {
- if (strncmpic(buf, v->str, v->len) == 0)
- {
- return(v);
- }
- }
- return(NULL);
-
-}
-
-
/*********************************************************************
*
* Function : flush_socket
char *hdr;
void (* const *f)();
- for (p = csp->headers->next; p ; p = p->next)
+ for (v = pats; v->str ; v++)
{
- log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
-
- if ((v = match(p->str, pats)))
+ for (p = csp->headers->next; p ; p = p->next)
{
- hdr = v->parser(v, p->str, csp);
- freez(p->str);
- p->str = hdr;
- }
+ /* Header crunch()ed in previous run? -> ignore */
+ if (p->str == NULL) continue;
+ if (v == pats) log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
+
+ if (strncmpic(p->str, v->str, v->len) == 0)
+ {
+ hdr = v->parser(v, p->str, csp);
+ freez(p->str);
+ p->str = hdr;
+ }
+ }
}
/* place any additional headers on the csp->headers list */
(*f)(csp);
}
- /* add the blank line at the end of the header */
- enlist(csp->headers, "");
+ /* add the blank line at the end of the header, if necessary */
+ if(strlen(csp->headers->last->str) != 0)
+ {
+ enlist(csp->headers, "");
+ }
hdr = list_to_text(csp->headers);
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.
+ *
+ * Parameters :
+ * 1 : v = ignored
+ * 2 : s = header string we are "considering"
+ * 3 : csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns : A duplicate string pointer to this header (ie. pass thru)
+ *
+ *********************************************************************/
+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);
+ snprintf(s, 100, "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 */
+
+
/*********************************************************************
*
* Function : client_referrer
{
char *p = NULL;
- if (csp->config->add_forwarded == 0)\r
- {\r
- return;\r
+ if (csp->config->add_forwarded == 0)
+ {
+ return;
}
if (csp->x_forwarded)