-const char parsers_rcs[] = "$Id: parsers.c,v 1.225 2011/07/08 13:30:08 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.226 2011/08/31 13:35:21 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
{
/** The header prefix to match */
const char *str;
-
+
/** The length of the prefix to match */
const size_t len;
-
+
/** The function to apply to this line */
const parser_func_ptr parser;
};
{
want *= 2;
}
-
+
if (want <= csp->config->buffer_limit && NULL != (p = (char *)realloc(iob->buf, want)))
{
iob->size = want;
jb_err decompress_iob(struct client_state *csp)
{
char *buf; /* new, uncompressed buffer */
- char *cur; /* Current iob position (to keep the original
+ char *cur; /* Current iob position (to keep the original
* iob->cur unmodified if we return early) */
size_t bufsize; /* allocated size of the new buffer */
size_t old_size; /* Content size before decompression */
*
* Fortunately, add_to_iob() has thoughtfully null-terminated
* the buffer; we can just increment the end pointer to include
- * the dummy byte.
+ * the dummy byte.
*/
csp->iob->eod++;
}
{
bufsize = csp->config->buffer_limit;
}
-
+
/* Try to allocate the new buffer. */
tmpbuf = realloc(buf, bufsize);
if (NULL == tmpbuf)
csp->iob->cur = csp->iob->buf + skip_size;
csp->iob->eod = (char *)zstr.next_out;
csp->iob->size = bufsize;
-
+
/*
* Make sure the new uncompressed iob obeys some minimal
* consistency conditions.
* Header spans multiple lines, append the next one.
*/
char *continued_header;
-
+
continued_header = get_header_line(iob);
if ((continued_header == NULL) || (*continued_header == '\0'))
{
}
}
- /*
+ /*
* Not found
*/
return NULL;
*
* Function : scan_headers
*
- * Description : Scans headers, applies tags and updates action bits.
+ * Description : Scans headers, applies tags and updates action bits.
*
* Parameters :
* 1 : csp = Current client state (buffers, headers, etc...)
b->name);
continue;
}
-
+
if (!list_contains_item(csp->tags, tag))
{
if (JB_ERR_OK != enlist(csp->tags, tag))
matches = pcrs_execute(job, *header, size, &newheader, &size);
if ( 0 < matches )
{
- current_hits += matches;
+ current_hits += matches;
log_error(LOG_LEVEL_HEADER, "Transforming \"%s\" to \"%s\"", *header, newheader);
freez(*header);
*header = newheader;
* Function : client_connection
*
* Description : Makes sure a proper "Connection:" header is
- * set and signals connection_header_adder
+ * set and signals connection_header_adder
* to do nothing.
*
* Parameters :
/* Is the current header the lucky one? */
if (strstr(*header, crunch_pattern))
{
- log_error(LOG_LEVEL_HEADER, "Crunching server header: %s (contains: %s)", *header, crunch_pattern);
+ log_error(LOG_LEVEL_HEADER, "Crunching server header: %s (contains: %s)", *header, crunch_pattern);
freez(*header);
}
}
{
/*
* Make sure the user doesn't accidentally
- * change the content type of binary documents.
+ * change the content type of binary documents.
*/
if ((csp->content_type & CT_TEXT) || (csp->action->flags & ACTION_FORCE_TEXT_MODE))
{
*
* If FEATURE_ZLIB is enabled and the compression type
* supported, the content is marked for decompression.
- *
+ *
* XXX: Doesn't properly deal with multiple or with
* unsupported but unknown encodings.
* Is case-sensitive but shouldn't be.
return JB_ERR_OK;
}
else
- {
+ {
/*
* Replacing Content-Disposition header
*/
return JB_ERR_OK;
}
else if (0 == strcmpic(newval, "reset-to-request-time"))
- {
+ {
/*
* Setting Last-Modified Header to now.
*/
get_http_time(0, buf, sizeof(buf));
freez(*header);
*header = strdup("Last-Modified: ");
- string_append(header, buf);
+ string_append(header, buf);
if (*header == NULL)
{
- log_error(LOG_LEVEL_HEADER, "Insufficient memory. Last-Modified header got lost, boohoo.");
+ log_error(LOG_LEVEL_HEADER, "Insufficient memory. Last-Modified header got lost, boohoo.");
}
else
{
if (negative_delta)
{
- rtime *= -1;
+ rtime *= -1;
log_error(LOG_LEVEL_HEADER, "Server time in the future.");
}
rtime = pick_from_range(rtime);
if (*header == NULL)
{
log_error(LOG_LEVEL_ERROR, "Insufficient memory, header crunched without replacement.");
- return JB_ERR_MEMORY;
+ return JB_ERR_MEMORY;
}
days = rtime / (3600 * 24);
/* booleans for parameters we have to check multiple times */
int parameter_conditional_block;
int parameter_conditional_forge;
-
+
#ifdef FEATURE_FORCE_LOAD
/*
* Since the referrer can include the prefix even
return JB_ERR_OK;
}
else
- {
+ {
/*
* Replacing Accept-Language header
*/
freez(*header);
*header = strdup("Accept-Language: ");
- string_append(header, newval);
+ string_append(header, newval);
if (*header == NULL)
{
log_error(LOG_LEVEL_ERROR,
- "Insufficient memory. Accept-Language header crunched without replacement.");
+ "Insufficient memory. Accept-Language header crunched without replacement.");
}
else
{
/* Is the current header the lucky one? */
if (strstr(*header, crunch_pattern))
{
- log_error(LOG_LEVEL_HEADER, "Crunching client header: %s (contains: %s)", *header, crunch_pattern);
+ log_error(LOG_LEVEL_HEADER, "Crunching client header: %s (contains: %s)", *header, crunch_pattern);
freez(*header);
}
}
return JB_ERR_OK;
}
- if (!csp->http->hostport || (*csp->http->hostport == '*') ||
+ if (!csp->http->hostport || (*csp->http->hostport == '*') ||
*csp->http->hostport == ' ' || *csp->http->hostport == '\0')
{
-
+
if (NULL == (p = strdup((*header)+6)))
{
return JB_ERR_MEMORY;
struct tm gmt;
#endif
struct tm *timeptr = NULL;
- time_t tm = 0;
+ time_t tm = 0;
const char *newval;
char * endptr;
-
+
if ( 0 == strcmpic(*header, "If-Modified-Since: Wed, 08 Jun 1955 12:00:00 GMT"))
{
- /*
+ /*
* The client got an error message because of a temporary problem,
* the problem is gone and the client now tries to revalidate our
* error message on the real server. The revalidation would always
*header, rtime, (rtime == 1 || rtime == -1) ? "e": "es");
if (negative_range)
{
- rtime *= -1;
+ rtime *= -1;
}
rtime *= 60;
rtime = pick_from_range(rtime);
if (*header == NULL)
{
log_error(LOG_LEVEL_HEADER, "Insufficient memory, header crunched without replacement.");
- return JB_ERR_MEMORY;
+ return JB_ERR_MEMORY;
}
hours = rtime / 3600;
static jb_err client_if_none_match(struct client_state *csp, char **header)
{
if (csp->action->flags & ACTION_CRUNCH_IF_NONE_MATCH)
- {
+ {
log_error(LOG_LEVEL_HEADER, "Crunching %s", *header);
freez(*header);
}
"force-text-mode overruled the client's request to fetch without filtering!");
}
else
- {
+ {
csp->content_type = CT_TABOO; /* XXX: This hack shouldn't be necessary */
csp->flags |= CSP_FLAG_NO_FILTERING;
log_error(LOG_LEVEL_HEADER, "Accepted the client's request to fetch without filtering.");
freez(*header);
}
}
- return JB_ERR_OK;
+ return JB_ERR_OK;
}
freez(*header);
}
- return JB_ERR_OK;
+ return JB_ERR_OK;
}
/* the following functions add headers directly to the header list */
static jb_err server_set_cookie(struct client_state *csp, char **header)
{
time_t now;
- time_t cookie_time;
+ time_t cookie_time;
time(&now);
* to get the numerical respresentation.
*
* Parameters :
- * 1 : header_time = HTTP header time as string.
+ * 1 : header_time = HTTP header time as string.
* 2 : result = storage for header_time in seconds
*
* Returns : JB_ERR_OK if the time format was recognized, or
* Parameters :
* 1 : headers = List of headers (one of them hopefully being
* the "Host:" header)
- * 2 : http = storage for the result (host, port and hostport).
+ * 2 : http = storage for the result (host, port and hostport).
*
* Returns : JB_ERR_MEMORY in case of memory problems,
* JB_ERR_PARSE if the host header couldn't be found,
*
* Description : Helper for client_referrer to forge a referer as
* 'http://[hostname:port/' to fool stupid
- * checks for in-site links
+ * checks for in-site links
*
* Parameters :
* 1 : header = Pointer to header pointer