X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=filters.c;h=256b0c9dedda4fed5a1ef8a514a51d233d4c773d;hb=75b7e81c8588de2b55c34426e98e98bebea64b5c;hp=7e37c9b4d90dd4f3baa257fc3d7a31b1671310b6;hpb=c885b7ff0ffe914e0e26934c6bd62774315ce40f;p=privoxy.git diff --git a/filters.c b/filters.c index 7e37c9b4..256b0c9d 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.43 2002/01/22 23:51:59 jongfoster Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.45 2002/03/08 16:47:50 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -38,6 +38,16 @@ const char filters_rcs[] = "$Id: filters.c,v 1.43 2002/01/22 23:51:59 jongfoster * * Revisions : * $Log: filters.c,v $ + * Revision 1.45 2002/03/08 16:47:50 oes + * Added choice beween GIF and PNG built-in images + * + * Revision 1.44 2002/03/07 03:49:31 oes + * - Fixed compiler warnings etc + * - Changed built-in images from GIF to PNG + * (with regard to Unisys patent issue) + * - Added a 4x4 pattern PNG which is less intrusive + * than the logo but also clearly marks the deleted banners + * * Revision 1.43 2002/01/22 23:51:59 jongfoster * Replacing strsav() with the safer string_append(). * @@ -671,7 +681,7 @@ struct http_response *block_url(struct client_state *csp) } rsp->content_length = image_logo_length; - if (enlist_unique_header(rsp->headers, "Content-Type", "image/png")) + if (enlist_unique_header(rsp->headers, "Content-Type", BUILTIN_IMAGE_MIMETYPE)) { free_http_response(rsp); return cgi_error_memory(); @@ -688,7 +698,7 @@ struct http_response *block_url(struct client_state *csp) } rsp->content_length = image_blank_length; - if (enlist_unique_header(rsp->headers, "Content-Type", "image/png")) + if (enlist_unique_header(rsp->headers, "Content-Type", BUILTIN_IMAGE_MIMETYPE)) { free_http_response(rsp); return cgi_error_memory(); @@ -705,7 +715,7 @@ struct http_response *block_url(struct client_state *csp) } rsp->content_length = image_pattern_length; - if (enlist_unique_header(rsp->headers, "Content-Type", "image/png")) + if (enlist_unique_header(rsp->headers, "Content-Type", BUILTIN_IMAGE_MIMETYPE)) { free_http_response(rsp); return cgi_error_memory(); @@ -1181,16 +1191,17 @@ int is_untrusted_url(struct client_state *csp) * * Function : pcrs_filter_response * - * Description : Apply all the pcrs jobs from the joblist (re_filterfile) - * to the text buffer that's been accumulated in - * csp->iob->buf and set csp->content_length to the modified - * size and raise the CSP_FLAG_MODIFIED flag if appropriate. + * Description : Ecexute all text substitutions from all applying + * +filter actions on the text buffer that's been accumulated + * in csp->iob->buf. If this changes the contents, set + * csp->content_length to the modified size and raise the + * CSP_FLAG_MODIFIED flag. * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) * * Returns : a pointer to the (newly allocated) modified buffer. - * or NULL in case something went wrong + * or NULL if there were no hits or something went wrong * *********************************************************************/ char *pcrs_filter_response(struct client_state *csp) @@ -1203,14 +1214,23 @@ char *pcrs_filter_response(struct client_state *csp) struct file_list *fl; struct re_filterfile_spec *b; + struct list_entry *filtername; - /* Sanity first */ + /* + * Sanity first + */ if (csp->iob->cur >= csp->iob->eod) { return(NULL); } size = csp->iob->eod - csp->iob->cur; + if ( ( NULL == (fl = csp->rlist) ) || ( NULL == fl->f) ) + { + log_error(LOG_LEVEL_ERROR, "Unable to get current state of regexp filtering."); + return(NULL); + } + /* * If the body has a "chunked" transfer-encoding, * get rid of it first, adjusting size and iob->eod @@ -1226,31 +1246,40 @@ char *pcrs_filter_response(struct client_state *csp) csp->flags |= CSP_FLAG_MODIFIED; } - if ( ( NULL == (fl = csp->rlist) ) || ( NULL == (b = fl->f) ) ) + /* + * For all applying +filter actions, look if a filter by that + * name exists and if yes, execute it's pcrs_joblist on the + * buffer. + */ + for (b = fl->f; b; b = b->next) { - log_error(LOG_LEVEL_ERROR, "Unable to get current state of regexp filtering."); - return(NULL); - } + for (filtername = csp->action->multi[ACTION_MULTI_FILTER]->first; + filtername ; filtername = filtername->next) + { + if (strcmp(b->filtername, filtername->str) == 0) + { + if ( NULL == b->joblist ) + { + log_error(LOG_LEVEL_RE_FILTER, "Filter %s has empty joblist. Nothing to do.", b->filtername); + return(NULL); + } - if ( NULL == b->joblist ) - { - log_error(LOG_LEVEL_RE_FILTER, "Empty joblist. Nothing to do."); - return(NULL); - } + log_error(LOG_LEVEL_RE_FILTER, "re_filtering %s%s (size %d) with filter %s...", + csp->http->hostport, csp->http->path, size, b->filtername); - log_error(LOG_LEVEL_RE_FILTER, "re_filtering %s%s (size %d) ...", - csp->http->hostport, csp->http->path, size); + /* Apply all jobs from the joblist */ + for (job = b->joblist; NULL != job; job = job->next) + { + hits += pcrs_execute(job, old, size, &new, &size); + if (old != csp->iob->cur) free(old); + old=new; + } - /* Apply all jobs from the joblist */ - for (job = b->joblist; NULL != job; job = job->next) - { - hits += pcrs_execute(job, old, size, &new, &size); - if (old != csp->iob->cur) free(old); - old=new; + log_error(LOG_LEVEL_RE_FILTER, " ...produced %d hits (new size %d).", hits, size); + } + } } - log_error(LOG_LEVEL_RE_FILTER, " produced %d hits (new size %d).", hits, size); - /* * If there were no hits, destroy our copy and let * chat() use the original in csp->iob