From e10b140e837860410ab2b97562b0d919beea4df0 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sun, 2 Sep 2007 15:31:20 +0000 Subject: [PATCH] Move match_portlist() from filter.c to urlmatch.c. It's used for url matching, not for filtering. --- filters.c | 85 +++------------------------------------------------ filters.h | 6 ++-- urlmatch.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++--- urlmatch.h | 7 ++++- 4 files changed, 99 insertions(+), 89 deletions(-) diff --git a/filters.c b/filters.c index 221da6de..d56bf1fe 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.89 2007/08/05 13:42:23 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.90 2007/09/02 12:44:17 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -40,6 +40,9 @@ const char filters_rcs[] = "$Id: filters.c,v 1.89 2007/08/05 13:42:23 fabiankeil * * Revisions : * $Log: filters.c,v $ + * Revision 1.90 2007/09/02 12:44:17 fabiankeil + * Remove newline at the end of a log_error() message. + * * Revision 1.89 2007/08/05 13:42:23 fabiankeil * #1763173 from Stefan Huehner: declare some more functions static. * @@ -771,86 +774,6 @@ int acl_addr(const 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 dd729cf0..3e50f290 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.26 2007/03/13 11:28:43 fabiankeil Exp $" +#define FILTERS_H_VERSION "$Id: filters.h,v 1.27 2007/04/30 15:02:18 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.h,v $ @@ -39,6 +39,9 @@ * * Revisions : * $Log: filters.h,v $ + * Revision 1.27 2007/04/30 15:02:18 fabiankeil + * Introduce dynamic pcrs jobs that can resolve variables. + * * Revision 1.26 2007/03/13 11:28:43 fabiankeil * - Fix port handling in acl_addr() and use a temporary acl spec * copy so error messages don't contain a truncated version. @@ -254,7 +257,6 @@ struct url_spec; extern int block_acl(struct access_control_addr *dst, struct client_state *csp); extern int acl_addr(const char *aspec, struct access_control_addr *aca); #endif /* def FEATURE_ACL */ -extern int match_portlist(const char *portlist, int port); /* * Interceptors 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 diff --git a/urlmatch.h b/urlmatch.h index 0056407f..71e2633e 100644 --- a/urlmatch.h +++ b/urlmatch.h @@ -1,6 +1,6 @@ #ifndef URLMATCH_H_INCLUDED #define URLMATCH_H_INCLUDED -#define URLMATCH_H_VERSION "$Id: urlmatch.h,v 1.6 2006/12/06 19:12:43 fabiankeil Exp $" +#define URLMATCH_H_VERSION "$Id: urlmatch.h,v 1.7 2007/01/06 14:24:38 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/urlmatch.h,v $ @@ -35,6 +35,10 @@ * * Revisions : * $Log: urlmatch.h,v $ + * Revision 1.7 2007/01/06 14:24:38 fabiankeil + * Mark *csp as immutable for parse_http_url() + * and url_match(). + * * Revision 1.6 2006/12/06 19:12:43 fabiankeil * Added prototype for init_domain_components(). * @@ -89,6 +93,7 @@ extern int url_match(const struct url_spec *pattern, extern jb_err create_url_spec(struct url_spec * url, const char * buf); extern void free_url_spec(struct url_spec *url); +extern int match_portlist(const char *portlist, int port); /* Revision control strings from this header and associated .c file */ -- 2.39.2