From: oes Date: Wed, 10 Oct 2001 16:44:16 +0000 (+0000) Subject: Added match_portlist function X-Git-Tag: v_2_9_10~144 X-Git-Url: http://www.privoxy.org/gitweb/templates.html?a=commitdiff_plain;h=0a8f2d177dc9487fa974dad9755d5cbda3fbbf67;p=privoxy.git Added match_portlist function --- diff --git a/filters.c b/filters.c index 9b456040..e30a24c8 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.34 2001/09/20 15:49:36 steudten Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.35 2001/10/07 15:41:23 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -38,6 +38,18 @@ const char filters_rcs[] = "$Id: filters.c,v 1.34 2001/09/20 15:49:36 steudten E * * Revisions : * $Log: filters.c,v $ + * Revision 1.35 2001/10/07 15:41:23 oes + * Replaced 6 boolean members of csp with one bitmap (csp->flags) + * + * New function remove_chunked_transfer_coding that strips chunked + * transfer coding to plain and is called by pcrs_filter_response + * and gif_deanimate_response if neccessary + * + * Improved handling of zero-change re_filter runs + * + * pcrs_filter_response and gif_deanimate_response now remove + * chunked transfer codeing before processing the body. + * * Revision 1.34 2001/09/20 15:49:36 steudten * * Fix BUG: Change int size to size_t size in pcrs_filter_response(). @@ -466,6 +478,86 @@ int acl_addr(char *aspec, struct access_control_addr *aca) #endif /* def FEATURE_ACL */ +/********************************************************************* + * + * Function : match_portlist + * + * Description : Check if a given number is covered by a comma + * separated list of numbers and ranges (a,b-c,d,..) + * + * Parameters : + * 1 : portlist = String with list + * 2 : port = port to check + * + * Returns : 0 => no match + * 1 => match + * + *********************************************************************/ +int match_portlist(const char *portlist, int port) +{ + char *min, *max, *next, *portlist_copy; + + min = next = portlist_copy = strdup(portlist); + + /* + * Zero-terminate first item and remember offset for next + */ + if (NULL != (next = strchr(portlist_copy, (int) ','))) + { + *next++ = '\0'; + } + + /* + * Loop through all items, checking for match + */ + while(min) + { + if (NULL == (max = strchr(min, (int) '-'))) + { + /* + * No dash, check for equality + */ + if (port == atoi(min)) + { + free(portlist_copy); + return(1); + } + } + else + { + /* + * This is a range, so check if between min and max, + * or, if max was omitted, between min and 65K + */ + *max++ = '\0'; + if(port >= atoi(min) && port <= (atoi(max) ? atoi(max) : 65535)) + { + free(portlist_copy); + return(1); + } + + } + + /* + * Jump to next item + */ + min = next; + + /* + * Zero-terminate next item and remember offset for n+1 + */ + if ((NULL != next) && (NULL != (next = strchr(next, (int) ',')))) + { + *next++ = '\0'; + } + } + + free(portlist_copy); + return 0; + +} + + /********************************************************************* * * Function : block_url diff --git a/filters.h b/filters.h index c4dfd124..5661ee33 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.13 2001/07/30 22:08:36 jongfoster Exp $" +#define FILTERS_H_VERSION "$Id: filters.h,v 1.14 2001/10/07 15:41:40 oes Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.h,v $ @@ -40,6 +40,9 @@ * * Revisions : * $Log: filters.h,v $ + * Revision 1.14 2001/10/07 15:41:40 oes + * Added prototype for remove_chunked_transfer_coding + * * Revision 1.13 2001/07/30 22:08:36 jongfoster * Tidying up #defines: * - All feature #defines are now of the form FEATURE_xxx @@ -198,6 +201,7 @@ struct url_spec; extern int block_acl(struct access_control_addr *dst, struct client_state *csp); extern int acl_addr(char *aspec, struct access_control_addr *aca); #endif /* def FEATURE_ACL */ +extern int match_portlist(const char *portlist, int port); /* * Interceptors