From 2bcd3fa6d83fc9c6e96b9d3d8a2d309a18e2e18e Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 3 Jun 2009 16:44:41 +0000 Subject: [PATCH] Factor path_matches() out of url_match(). --- urlmatch.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/urlmatch.c b/urlmatch.c index 05ec84ac..b390e353 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,4 +1,4 @@ -const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.56 2009/06/03 16:43:50 fabiankeil Exp $"; +const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.57 2009/06/03 16:44:15 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/urlmatch.c,v $ @@ -1217,6 +1217,26 @@ static int host_matches(const struct http_request *http, } +/********************************************************************* + * + * Function : path_matches + * + * Description : Compares a path against a path pattern. + * + * Parameters : + * 1 : path = The path to match + * 2 : pattern = The URL pattern + * + * Returns : TRUE for yes, FALSE otherwise. + * + *********************************************************************/ +static int path_matches(const char *path, const struct url_spec *pattern) +{ + return ((NULL == pattern->preg) + || (0 == regexec(pattern->preg, path, 0, NULL, 0))); +} + + /********************************************************************* * * Function : url_match @@ -1233,9 +1253,6 @@ static int host_matches(const struct http_request *http, int url_match(const struct url_spec *pattern, const struct http_request *http) { - /* XXX: these should probably be functions. */ -#define PATH_MATCHES ((NULL == pattern->preg) || (0 == regexec(pattern->preg, http->path, 0, NULL, 0))) - if (pattern->tag_regex != NULL) { /* It's a tag pattern and shouldn't be matched against URLs */ @@ -1243,7 +1260,7 @@ int url_match(const struct url_spec *pattern, } return (port_matches(http->port, pattern->port_list) - && host_matches(http, pattern) && PATH_MATCHES); + && host_matches(http, pattern) && path_matches(http->path, pattern)); } -- 2.39.2