-const char parsers_rcs[] = "$Id: parsers.c,v 1.31 2001/10/05 14:25:02 oes Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.35 2001/10/09 22:39:21 jongfoster Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.35 2001/10/09 22:39:21 jongfoster
+ * assert.h is also required under Win32, so moving out of #ifndef _WIN32
+ * block.
+ *
+ * Revision 1.34 2001/10/07 18:50:55 oes
+ * Added server_content_encoding, renamed server_transfer_encoding
+ *
+ * Revision 1.33 2001/10/07 18:04:49 oes
+ * Changed server_http11 to server_http and its pattern to "HTTP".
+ * Additional functionality: it now saves the HTTP status into
+ * csp->http->status and sets CT_TABOO for Status 206 (partial range)
+ *
+ * Revision 1.32 2001/10/07 15:43:28 oes
+ * Removed FEATURE_DENY_GZIP and replaced it with client_accept_encoding,
+ * client_te and client_accept_encoding_adder, triggered by the new
+ * +no-compression action. For HTTP/1.1 the Accept-Encoding header is
+ * changed to allow only identity and chunked, and the TE header is
+ * crunched. For HTTP/1.0, Accept-Encoding is crunched.
+ *
+ * parse_http_request no longer does anything than parsing. The rewriting
+ * of http->cmd and version mangling are gone. It now also recognizes
+ * the put and delete methods and saves the url in http->url. Removed
+ * unused variable.
+ *
+ * renamed content_type and content_length to have the server_ prefix
+ *
+ * server_content_type now only works if csp->content_type != CT_TABOO
+ *
+ * added server_transfer_encoding, which
+ * - Sets CT_TABOO to prohibit filtering if encoding compresses
+ * - Raises the CSP_FLAG_CHUNKED flag if Encoding is "chunked"
+ * - Change from "chunked" to "identity" if body was chunked
+ * but has been de-chunked for filtering.
+ *
+ * added server_content_md5 which crunches any Content-MD5 headers
+ * if the body was modified.
+ *
+ * made server_http11 conditional on +downgrade action
+ *
+ * Replaced 6 boolean members of csp with one bitmap (csp->flags)
+ *
* Revision 1.31 2001/10/05 14:25:02 oes
* Crumble Keep-Alive from Server
*
#include <sys/types.h>
#include <stdlib.h>
#include <ctype.h>
-#include<assert.h>
#endif
+#include <assert.h>
#include <string.h>
#ifndef _WIN32
#if defined(FEATURE_IMAGE_DETECT_MSIE)
{ "Accept:", 7, client_accept },
#endif /* defined(FEATURE_IMAGE_DETECT_MSIE) */
-#ifdef FEATURE_FORCE_LOAD
- { "Host:", 5, client_host },
-#endif /* def FEATURE_FORCE_LOAD */
+ { "Host:", 5, crumble },
/* { "if-modified-since:", 18, crumble }, */
{ "Keep-Alive:", 11, crumble },
{ "connection:", 11, crumble },
const struct parsers server_patterns[] = {
- { "HTTP/1.1 ", 9, server_http11 },
+ { "HTTP", 4, server_http },
{ "set-cookie:", 11, server_set_cookie },
{ "connection:", 11, crumble },
{ "Content-Type:", 13, server_content_type },
{ "Content-Length:", 15, server_content_length },
{ "Content-MD5:", 12, server_content_md5 },
- { "Transfer-Encoding:", 18, server_transfer_encoding },
+ { "Content-Encoding:", 17, server_content_encoding },
+ { "Transfer-Encoding:", 18, server_transfer_coding },
{ "Keep-Alive:", 11, crumble },
{ NULL, 0, NULL }
};
void (* const add_client_headers[])(struct client_state *) = {
+ client_host_adder,
client_cookie_adder,
client_x_forwarded_adder,
client_xtra_adder,
/*********************************************************************
*
- * Function : server_transfer_encoding
+ * Function : server_transfer_coding
*
- * Description : - Prohibit filtering (CT_TABOO) if encoding compresses
- * - Raise the CSP_FLAG_CHUNKED flag if Encoding is "chunked"
+ * Description : - Prohibit filtering (CT_TABOO) if transfer coding compresses
+ * - Raise the CSP_FLAG_CHUNKED flag if coding is "chunked"
* - Change from "chunked" to "identity" if body was chunked
* but has been de-chunked for filtering.
*
* Returns : A duplicate string pointer to this header (ie. pass thru)
*
*********************************************************************/
-char *server_transfer_encoding(const struct parsers *v, const char *s, struct client_state *csp)
+char *server_transfer_coding(const struct parsers *v, const char *s, struct client_state *csp)
{
/*
* Turn off pcrs and gif filtering if body compressed
}
+/*********************************************************************
+ *
+ * Function : server_content_encoding
+ *
+ * Description : Prohibit filtering (CT_TABOO) if content encoding compresses
+ *
+ * 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 *server_content_encoding(const struct parsers *v, const char *s, struct client_state *csp)
+{
+ /*
+ * Turn off pcrs and gif filtering if body compressed
+ */
+ if (strstr(s, "gzip") || strstr(s, "compress") || strstr(s, "deflate"))
+ {
+ csp->content_type = CT_TABOO;
+ }
+
+ return(strdup(s));
+
+}
+
+
/*********************************************************************
*
* Function : server_content_length
/* the following functions add headers directly to the header list */
+/*********************************************************************
+ *
+ * Function : client_host_adder
+ *
+ * Description : (re)adds the host header. Called from `sed'.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void client_host_adder(struct client_state *csp)
+{
+ char *p = NULL;
+
+ p = strsav(p, "Host: ");
+ p = strsav(p, csp->http->hostport);
+
+ log_error(LOG_LEVEL_HEADER, "addh: %s", p);
+ enlist(csp->headers, p);
+
+ freez(p);
+}
+
+
/*********************************************************************
*
* Function : client_cookie_adder
/*********************************************************************
*
- * Function : server_http11
+ * Function : server_http
*
- * Description : Rewrite HTTP/1.1 answers to HTTP/1.0 if +downgrade
- * action applies.
+ * Description : - Save the HTTP Status into csp->http->status
+ * - Set CT_TABOO to prevent filtering if the answer
+ * is a partial range (HTTP status 206)
+ * - Rewrite HTTP/1.1 answers to HTTP/1.0 if +downgrade
+ * action applies.
*
* Parameters :
* 1 : v = parser pattern that matched this header
* Returns : Copy of changed or original answer.
*
*********************************************************************/
-char *server_http11(const struct parsers *v, const char *s, struct client_state *csp)
+char *server_http(const struct parsers *v, const char *s, struct client_state *csp)
{
- char *ret;
-
- if ((csp->action->flags & ACTION_DOWNGRADE) != 0)
+ char *ret = strdup(s);
+
+ sscanf(ret, "HTTP/%*d.%*d %d", &(csp->http->status));
+ if (csp->http->status == 206)
{
- /* "HTTP/1.1 ..." -> "HTTP/1.0 ..." */
- ret = strdup(s);
- ret[7] = '0';
-
- return(ret);
+ csp->content_type = CT_TABOO;
}
- else
+
+ if ((csp->action->flags & ACTION_DOWNGRADE) != 0)
{
- return(strdup(s));
+ ret[7] = '0';
+ log_error(LOG_LEVEL_HEADER, "Downgraded answer to HTTP/1.0");
}
+ return(ret);
}
}
-#ifdef FEATURE_FORCE_LOAD
-/*********************************************************************
- *
- * Function : client_host
- *
- * Description : Clean the FORCE_PREFIX out of the 'host' http
- * header, if we use force
- *
- * Parameters :
- * 1 : v = ignored
- * 2 : s = header (from sed) to clean
- * 3 : csp = Current client state (buffers, headers, etc...)
- *
- * Returns : A malloc'ed pointer to the cleaned host header
- *
- *********************************************************************/
-char *client_host(const struct parsers *v, const char *s, struct client_state *csp)
-{
- char *cleanhost = strdup(s);
-
- if(csp->flags & CSP_FLAG_FORCED)
- {
- strclean(cleanhost, FORCE_PREFIX);
- }
-
- return(cleanhost);
-}
-#endif /* def FEATURE_FORCE_LOAD */
-
-
#ifdef FEATURE_FORCE_LOAD
/*********************************************************************
*