X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=filters.c;h=dd554ba0f936fcef635b3d4352bab401fedbe8e3;hp=ed5a3736d2feafca69d9e24e5c2a8584692711e0;hb=2b846688545bf947722a0437608a793202f80cf6;hpb=6270660d48a8c2dfe80c98c0bd802133899ccdd7 diff --git a/filters.c b/filters.c index ed5a3736..dd554ba0 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.129 2010/05/01 18:20:50 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.140 2011/03/03 14:47:28 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -50,11 +50,6 @@ const char filters_rcs[] = "$Id: filters.c,v 1.129 2010/05/01 18:20:50 fabiankei #include #include -#ifdef HAVE_RFC2553 -#include -#include -#endif /* def HAVE_RFC2553 */ - #ifndef _WIN32 #ifndef __OS2__ #include @@ -98,6 +93,8 @@ const char filters_h_rcs[] = FILTERS_H_VERSION; */ #define ijb_isdigit(__X) isdigit((int)(unsigned char)(__X)) +typedef char *(*filter_function_ptr)(); +static filter_function_ptr get_filter_function(const struct client_state *csp); static jb_err remove_chunked_transfer_coding(char *buffer, size_t *size); static jb_err prepare_for_filtering(struct client_state *csp); @@ -292,6 +289,10 @@ int block_acl(const struct access_control_addr *dst, const struct client_state * { return(0); } + else + { + return(1); + } } else if ( #ifdef HAVE_RFC2553 @@ -727,11 +728,11 @@ struct http_response *block_url(struct client_state *csp) && !strstr(p, "compatible") /* MSIE */ && !strstr(p, "Opera")) /* and Opera. */ { - rsp->status = strdup("200 Request for blocked URL"); + rsp->status = strdup("200 Request blocked by Privoxy"); } else { - rsp->status = strdup("403 Request for blocked URL"); + rsp->status = strdup("403 Request blocked by Privoxy"); } if (rsp->status == NULL) @@ -1001,10 +1002,9 @@ pcrs_job *compile_dynamic_pcrs_job_list(const struct client_state *csp, const st dummy = pcrs_compile_dynamic_command(pattern->str, variables, &error); if (NULL == dummy) { - assert(error < 0); log_error(LOG_LEVEL_ERROR, - "Adding filter job \'%s\' to dynamic filter %s failed: %s", - pattern->str, b->name, pcrs_strerror(error)); + "Compiling dynamic pcrs job '%s' for '%s' failed with error code %d: %s", + pattern->str, b->name, error, pcrs_strerror(error)); continue; } else @@ -1738,48 +1738,10 @@ static char *gif_deanimate_response(struct client_state *csp) * NULL if no content filter is active * *********************************************************************/ -filter_function_ptr get_filter_function(struct client_state *csp) +static filter_function_ptr get_filter_function(const struct client_state *csp) { filter_function_ptr filter_function = NULL; - if ((csp->content_type & CT_TABOO) - && !(csp->action->flags & ACTION_FORCE_TEXT_MODE)) - { - return NULL; - } - - /* - * Are we enabling text mode by force? - */ - if (csp->action->flags & ACTION_FORCE_TEXT_MODE) - { - /* - * Do we really have to? - */ - if (csp->content_type & CT_TEXT) - { - log_error(LOG_LEVEL_HEADER, "Text mode is already enabled."); - } - else - { - csp->content_type |= CT_TEXT; - log_error(LOG_LEVEL_HEADER, "Text mode enabled by force. Take cover!"); - } - } - - if (!(csp->content_type & CT_DECLARED)) - { - /* - * The server didn't bother to declare a MIME-Type. - * Assume it's text that can be filtered. - * - * This also regulary happens with 304 responses, - * therefore logging anything here would cause - * too much noise. - */ - csp->content_type |= CT_TEXT; - } - /* * Choose the applying filter function based on * the content type and action settings. @@ -1842,8 +1804,14 @@ static jb_err remove_chunked_transfer_coding(char *buffer, size_t *size) if ((newsize += chunksize) >= *size) { + /* + * XXX: The message is a bit confusing. Isn't the real problem that + * the specified chunk size is greater than the number of bytes + * left in the buffer? This probably means the connection got + * closed prematurely. To be investigated after 3.0.17 is out. + */ log_error(LOG_LEVEL_ERROR, - "Chunk size %d exceeds buffer size %d in \"chunked\" transfer coding", + "Chunk size %d exceeds buffer size %d in \"chunked\" transfer coding", chunksize, *size); return JB_ERR_PARSE; } @@ -1947,20 +1915,23 @@ static jb_err prepare_for_filtering(struct client_state *csp) /********************************************************************* * - * Function : execute_content_filter + * Function : execute_content_filters * * Description : Executes a given content filter. * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) - * 2 : content_filter = The filter function to execute * * Returns : Pointer to the modified buffer, or * NULL if filtering failed or wasn't necessary. * *********************************************************************/ -char *execute_content_filter(struct client_state *csp, filter_function_ptr content_filter) +char *execute_content_filters(struct client_state *csp) { + filter_function_ptr content_filter; + + assert(content_filters_enabled(csp->action)); + if (0 == csp->iob->eod - csp->iob->cur) { /* @@ -1986,6 +1957,8 @@ char *execute_content_filter(struct client_state *csp, filter_function_ptr conte return NULL; } + content_filter = get_filter_function(csp); + return ((*content_filter)(csp)); } @@ -2301,6 +2274,81 @@ struct http_response *direct_response(struct client_state *csp) } +/********************************************************************* + * + * Function : content_requires_filtering + * + * Description : Checks whether there are any content filters + * enabled for the current request and if they + * can actually be applied.. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * + * Returns : TRUE for yes, FALSE otherwise + * + *********************************************************************/ +int content_requires_filtering(struct client_state *csp) +{ + if ((csp->content_type & CT_TABOO) + && !(csp->action->flags & ACTION_FORCE_TEXT_MODE)) + { + return FALSE; + } + + /* + * Are we enabling text mode by force? + */ + if (csp->action->flags & ACTION_FORCE_TEXT_MODE) + { + /* + * Do we really have to? + */ + if (csp->content_type & CT_TEXT) + { + log_error(LOG_LEVEL_HEADER, "Text mode is already enabled."); + } + else + { + csp->content_type |= CT_TEXT; + log_error(LOG_LEVEL_HEADER, "Text mode enabled by force. Take cover!"); + } + } + + if (!(csp->content_type & CT_DECLARED)) + { + /* + * The server didn't bother to declare a MIME-Type. + * Assume it's text that can be filtered. + * + * This also regulary happens with 304 responses, + * therefore logging anything here would cause + * too much noise. + */ + csp->content_type |= CT_TEXT; + } + + /* + * Choose the applying filter function based on + * the content type and action settings. + */ + if ((csp->content_type & CT_TEXT) && + (csp->rlist != NULL) && + (!list_is_empty(csp->action->multi[ACTION_MULTI_FILTER]))) + { + return TRUE; + } + else if ((csp->content_type & CT_GIF) && + (csp->action->flags & ACTION_DEANIMATE)) + { + return TRUE; + } + + return FALSE; + +} + + /********************************************************************* * * Function : content_filters_enabled