It's used for url matching, not for filtering.
-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 $
*
* 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.
*
#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
#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 $
*
* 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.
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
-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 $
*
* 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
#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;
}
+/*********************************************************************
+ *
+ * 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
#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 $
*
* 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().
*
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 */