X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=urlmatch.c;h=176fdd308f16b1914ea60a231066a573a127e77c;hb=aa944637f685eec775f215f7122d4693fb842cea;hp=96d8877cd484d15f11d20dd008b681d978ecc9d6;hpb=073ebc2e7fc82aad52174bf2a9ec354a3b382850;p=privoxy.git diff --git a/urlmatch.c b/urlmatch.c index 96d8877c..176fdd30 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,4 +1,4 @@ -const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.18 2007/07/30 16:42:21 fabiankeil Exp $"; +const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.19 2007/09/02 13:42:11 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/urlmatch.c,v $ @@ -33,6 +33,10 @@ const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.18 2007/07/30 16:42:21 fabianke * * Revisions : * $Log: urlmatch.c,v $ + * Revision 1.19 2007/09/02 13:42:11 fabiankeil + * - Allow port lists in url patterns. + * - Ditch unused url_spec member pathlen. + * * Revision 1.18 2007/07/30 16:42:21 fabiankeil * Move the method check into unknown_method() * and loop through the known methods instead @@ -166,10 +170,6 @@ const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.18 2007/07/30 16:42:21 fabianke #include "ssplit.h" #include "miscutil.h" #include "errlog.h" -/* - * XXX: only for match_portlist() which I will relocate soonish. - */ -#include "filters.h" const char urlmatch_h_rcs[] = URLMATCH_H_VERSION; @@ -1038,6 +1038,86 @@ int url_match(const struct url_spec *pattern, } +/********************************************************************* + * + * 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; + +} + + /* Local Variables: tab-width: 3