From: Fabian Keil Date: Tue, 24 Dec 2013 13:32:51 +0000 (+0000) Subject: Factor get_filter() out of pcrs_filter_response() X-Git-Tag: v_3_0_22~203 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=17733b62b31ff476531e054b6fcf553eb8fb107b Factor get_filter() out of pcrs_filter_response() --- diff --git a/filters.c b/filters.c index 467b8029..fb5de235 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.177 2013/04/23 09:37:28 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.178 2013/11/24 14:22:51 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -1525,6 +1525,66 @@ int is_untrusted_url(const struct client_state *csp) #endif /* def FEATURE_TRUST */ +/********************************************************************* + * + * Function : get_filter + * + * Description : Get a filter with a given name and type. + * Note that taggers are filters, too. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * 2 : requested_name = Name of the content filter to get + * 3 : requested_type = Type of the filter to tagger to lookup + * + * Returns : A pointer to the requested filter + * or NULL if the filter wasn't found + * + *********************************************************************/ +struct re_filterfile_spec *get_filter(const struct client_state *csp, + const char *requested_name, + enum filter_type requested_type) +{ + int i; + struct re_filterfile_spec *b; + struct file_list *fl; + + for (i = 0; i < MAX_AF_FILES; i++) + { + fl = csp->rlist[i]; + if ((NULL == fl) || (NULL == fl->f)) + { + /* + * Either there are no filter files left or this + * filter file just contains no valid filters. + * + * Continue to be sure we don't miss valid filter + * files that are chained after empty or invalid ones. + */ + continue; + } + + for (b = fl->f; b != NULL; b = b->next) + { + if (b->type != requested_type) + { + /* The callers isn't interested in this filter type. */ + continue; + } + if (strcmp(b->name, requested_name) == 0) + { + /* The requested filter has been found. Abort search. */ + return b; + } + } + } + + /* No filter with the given name and type exists. */ + return NULL; + +} + + /********************************************************************* * * Function : pcrs_filter_response @@ -1543,14 +1603,12 @@ int is_untrusted_url(const struct client_state *csp) static char *pcrs_filter_response(struct client_state *csp) { int hits = 0; - int i; size_t size, prev_size; char *old = NULL; char *new = NULL; pcrs_job *job; - struct file_list *fl; struct re_filterfile_spec *b; struct list_entry *filtername; @@ -1572,39 +1630,19 @@ static char *pcrs_filter_response(struct client_state *csp) size = (size_t)(csp->iob->eod - csp->iob->cur); old = csp->iob->cur; - for (i = 0; i < MAX_AF_FILES; i++) - { - fl = csp->rlist[i]; - if ((NULL == fl) || (NULL == fl->f)) - { - /* - * Either there are no filter files - * left, or this filter file just - * contains no valid filters. - * - * Continue to be sure we don't miss - * valid filter files that are chained - * after empty or invalid ones. - */ - continue; - } /* * 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) + for (filtername = csp->action->multi[ACTION_MULTI_FILTER]->first; + filtername != NULL; filtername = filtername->next) { - if (b->type != FT_CONTENT_FILTER) + b = get_filter(csp, filtername->str, FT_CONTENT_FILTER); + if (b == NULL) { - /* Skip header filters */ continue; } - - for (filtername = csp->action->multi[ACTION_MULTI_FILTER]->first; - filtername ; filtername = filtername->next) - { - if (strcmp(b->name, filtername->str) == 0) { int current_hits = 0; /* Number of hits caused by this filter */ int job_number = 0; /* Which job we're currently executing */ @@ -1673,8 +1711,7 @@ static char *pcrs_filter_response(struct client_state *csp) hits += current_hits; } } - } - } + /* * If there were no hits, destroy our copy and let diff --git a/filters.h b/filters.h index b9b05690..ec1663f8 100644 --- a/filters.h +++ b/filters.h @@ -1,6 +1,6 @@ #ifndef FILTERS_H_INCLUDED #define FILTERS_H_INCLUDED -#define FILTERS_H_VERSION "$Id: filters.h,v 1.44 2013/11/06 16:27:37 fabiankeil Exp $" +#define FILTERS_H_VERSION "$Id: filters.h,v 1.45 2013/11/24 14:23:28 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.h,v $ @@ -78,6 +78,11 @@ extern void get_url_actions(struct client_state *csp, extern void apply_url_actions(struct current_action_spec *action, struct http_request *http, struct url_actions *b); + +extern struct re_filterfile_spec *get_filter(const struct client_state *csp, + const char *requested_name, + enum filter_type requested_type); + /* * Determining parent proxies */