-const char parsers_rcs[] = "$Id: parsers.c,v 1.281 2013/12/24 13:34:22 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.287 2014/07/25 11:55:11 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Purpose : Declares functions to parse/crunch headers and pages.
*
- * Copyright : Written by and Copyright (C) 2001-2012 the
+ * Copyright : Written by and Copyright (C) 2001-2014 the
* Privoxy team. http://www.privoxy.org/
*
* Based on the Internet Junkbuster originally written
static jb_err crunch_client_header (struct client_state *csp, char **header);
static jb_err client_x_filter (struct client_state *csp, char **header);
static jb_err client_range (struct client_state *csp, char **header);
+static jb_err client_expect (struct client_state *csp, char **header);
static jb_err server_set_cookie (struct client_state *csp, char **header);
static jb_err server_connection (struct client_state *csp, char **header);
static jb_err server_content_type (struct client_state *csp, char **header);
#if 0
{ "Transfer-Encoding:", 18, client_transfer_encoding },
#endif
+ { "Expect:", 7, client_expect },
{ "*", 0, crunch_client_header },
{ "*", 0, filter_header },
{ NULL, 0, NULL }
* to a single space in accordance with RFC 2616 2.2.
* This simplifies parsing and filtering later on.
*
- * XXX: Remove log messages before
- * the next stable release?
- *
* Parameters :
* 1 : header = A header with linear white space to reduce.
*
*********************************************************************/
static jb_err header_tagger(struct client_state *csp, char *header)
{
- int wanted_filter_type;
+ enum filter_type wanted_filter_type;
int multi_action_index;
pcrs_job *job;
struct re_filterfile_spec *b;
struct list_entry *filtername;
- int wanted_filter_type;
+ enum filter_type wanted_filter_type;
int multi_action_index;
if (csp->flags & CSP_FLAG_NO_FILTERING)
static jb_err client_keep_alive(struct client_state *csp, char **header)
{
unsigned int keep_alive_timeout;
- const char *timeout_position = strstr(*header, ": ");
+ char *timeout_position;
if (!(csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE))
{
return JB_ERR_OK;
}
+ /* Check for parameter-less format "Keep-Alive: 100" */
+ timeout_position = strstr(*header, ": ");
if ((NULL == timeout_position)
|| (1 != sscanf(timeout_position, ": %u", &keep_alive_timeout)))
{
- log_error(LOG_LEVEL_ERROR, "Couldn't parse: %s", *header);
- }
- else
- {
- if (keep_alive_timeout < csp->config->keep_alive_timeout)
+ /* Assume parameter format "Keep-Alive: timeout=100" */
+ timeout_position = strstr(*header, "timeout=");
+ if ((NULL == timeout_position)
+ || (1 != sscanf(timeout_position, "timeout=%u", &keep_alive_timeout)))
{
log_error(LOG_LEVEL_HEADER,
- "Reducing keep-alive timeout from %u to %u.",
- csp->config->keep_alive_timeout, keep_alive_timeout);
- csp->server_connection.keep_alive_timeout = keep_alive_timeout;
- }
- else
- {
- /* XXX: Is this log worthy? */
- log_error(LOG_LEVEL_HEADER,
- "Client keep-alive timeout is %u. Sticking with %u.",
- keep_alive_timeout, csp->config->keep_alive_timeout);
+ "Couldn't parse: '%s'. Using default timeout %u",
+ *header, csp->config->keep_alive_timeout);
+ freez(*header);
+
+ return JB_ERR_OK;
}
}
+ if (keep_alive_timeout < csp->config->keep_alive_timeout)
+ {
+ log_error(LOG_LEVEL_HEADER,
+ "Reducing keep-alive timeout from %u to %u.",
+ csp->config->keep_alive_timeout, keep_alive_timeout);
+ csp->server_connection.keep_alive_timeout = keep_alive_timeout;
+ }
+ else
+ {
+ /* XXX: Is this log worthy? */
+ log_error(LOG_LEVEL_HEADER,
+ "Client keep-alive timeout is %u. Sticking with %u.",
+ keep_alive_timeout, csp->config->keep_alive_timeout);
+ freez(*header);
+ }
+
return JB_ERR_OK;
}
}
+/*********************************************************************
+ *
+ * Function : client_expect
+ *
+ * Description : Raise the CSP_FLAG_UNSUPPORTED_CLIENT_EXPECTATION
+ * if the Expect header value is unsupported.
+ *
+ * Rejecting unsupported expectations is a RFC 7231 5.1.1
+ * MAY and a RFC 2616 (obsolete) MUST.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : header = On input, pointer to header to modify.
+ * On output, pointer to the modified header, or NULL
+ * to remove the header. This function frees the
+ * original string if necessary.
+ *
+ * Returns : JB_ERR_OK on success, or
+ *
+ *********************************************************************/
+jb_err client_expect(struct client_state *csp, char **header)
+{
+ if (0 != strcmpic(*header, "Expect: 100-continue"))
+ {
+ csp->flags |= CSP_FLAG_UNSUPPORTED_CLIENT_EXPECTATION;
+ log_error(LOG_LEVEL_HEADER,
+ "Unsupported client expectaction: %s", *header);
+ }
+
+ return JB_ERR_OK;
+
+}
+
+
/*********************************************************************
*
* Function : crumble