X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=urlmatch.c;h=80a184242b36beb1be832378cd7b6f3958d52e27;hb=0fe7da14ad7c02749aac3c7defb4a639008c6462;hp=bff7ffcf5b124d25c39dbb229d46d2e738501921;hpb=144740dd36d5dff1422cf24654bbc5082e5f051b;p=privoxy.git diff --git a/urlmatch.c b/urlmatch.c index bff7ffcf..80a18424 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,4 +1,4 @@ -const char urlmatch_rcs[] = "$Id: urlmatch.c JGF $"; +const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.8 2002/04/03 23:32:47 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/urlmatch.c,v $ @@ -7,7 +7,7 @@ const char urlmatch_rcs[] = "$Id: urlmatch.c JGF $"; * patterns. * * Copyright : Written by and Copyright (C) 2001 the SourceForge - * IJBSWA team. http://ijbswa.sourceforge.net + * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written * by and Copyright (C) 1997 Anonymous Coders and @@ -33,6 +33,45 @@ const char urlmatch_rcs[] = "$Id: urlmatch.c JGF $"; * * Revisions : * $Log: urlmatch.c,v $ + * Revision 1.8 2002/04/03 23:32:47 jongfoster + * Fixing memory leak on error + * + * Revision 1.7 2002/03/26 22:29:55 swa + * we have a new homepage! + * + * Revision 1.6 2002/03/24 13:25:43 swa + * name change related issues + * + * Revision 1.5 2002/03/13 00:27:05 jongfoster + * Killing warnings + * + * Revision 1.4 2002/03/07 03:46:17 oes + * Fixed compiler warnings + * + * Revision 1.3 2002/03/03 14:51:11 oes + * Fixed CLF logging: Added ocmd member for client's request to struct http_request + * + * Revision 1.2 2002/01/21 00:14:09 jongfoster + * Correcting comment style + * Fixing an uninitialized memory bug in create_url_spec() + * + * Revision 1.1 2002/01/17 20:53:46 jongfoster + * Moving all our URL and URL pattern parsing code to the same file - it + * was scattered around in filters.c, loaders.c and parsers.c. + * + * Providing a single, simple url_match(pattern,url) function - rather than + * the 3-line match routine which was repeated all over the place. + * + * Renaming free_url to free_url_spec, since it frees a struct url_spec. + * + * Providing parse_http_url() so that URLs can be parsed without faking a + * HTTP request line for parse_http_request() or repeating the parsing + * code (both of which were techniques that were actually in use). + * + * Standardizing that struct http_request is used to represent a URL, and + * struct url_spec is used to represent a URL pattern. (Before, URLs were + * represented as seperate variables and a partially-filled-in url_spec). + * * *********************************************************************/ @@ -92,6 +131,7 @@ void free_http_request(struct http_request *http) assert(http); freez(http->cmd); + freez(http->ocmd); freez(http->gpc); freez(http->host); freez(http->url); @@ -274,7 +314,7 @@ jb_err parse_http_url(const char * url, */ { char *vec[BUFFER_SIZE]; - int size; + size_t size; char *p; http->dbuffer = strdup(http->host); @@ -295,8 +335,10 @@ jb_err parse_http_url(const char * url, if (http->dcount <= 0) { - // Error: More than SZ(vec) components in domain - // or: no components in domain + /* + * Error: More than SZ(vec) components in domain + * or: no components in domain + */ free_http_request(http); return JB_ERR_PARSE; } @@ -550,8 +592,8 @@ static int domain_match(const struct url_spec *pattern, const struct http_reques * When finished, free with unload_url(). * * Parameters : - * 1 : url = Target url_spec to be filled in. Must be - * zeroed out before the call (e.g. using zalloc). + * 1 : url = Target url_spec to be filled in. Will be + * zeroed before use. * 2 : buf = Source pattern, null terminated. NOTE: The * contents of this buffer are destroyed by this * function. If this function succeeds, the @@ -572,13 +614,16 @@ jb_err create_url_spec(struct url_spec * url, const char * buf) assert(url); assert(buf); + /* Zero memory */ + memset(url, '\0', sizeof(*url)); + /* save a copy of the orignal specification */ if ((url->spec = strdup(buf)) == NULL) { return JB_ERR_MEMORY; } - if ((p = strchr(buf, '/'))) + if ((p = strchr(buf, '/')) != NULL) { if (NULL == (url->path = strdup(p))) { @@ -593,7 +638,6 @@ jb_err create_url_spec(struct url_spec * url, const char * buf) url->path = NULL; url->pathlen = 0; } -#ifdef REGEX if (url->path) { int errcode; @@ -626,12 +670,12 @@ jb_err create_url_spec(struct url_spec * url, const char * buf) freez(url->spec); freez(url->path); + regfree(url->preg); freez(url->preg); return JB_ERR_PARSE; } } -#endif if ((p = strchr(buf, ':')) == NULL) { url->port = 0; @@ -645,7 +689,7 @@ jb_err create_url_spec(struct url_spec * url, const char * buf) if (buf[0] != '\0') { char *v[150]; - int size; + size_t size; /* Parse domain part */ if (buf[strlen(buf) - 1] == '.') @@ -664,9 +708,8 @@ jb_err create_url_spec(struct url_spec * url, const char * buf) { freez(url->spec); freez(url->path); -#ifdef REGEX + regfree(url->preg); freez(url->preg); -#endif /* def REGEX */ return JB_ERR_MEMORY; } @@ -683,9 +726,8 @@ jb_err create_url_spec(struct url_spec * url, const char * buf) { freez(url->spec); freez(url->path); -#ifdef REGEX + regfree(url->preg); freez(url->preg); -#endif /* def REGEX */ freez(url->dbuffer); url->dcount = 0; return JB_ERR_MEMORY; @@ -701,9 +743,8 @@ jb_err create_url_spec(struct url_spec * url, const char * buf) { freez(url->spec); freez(url->path); -#ifdef REGEX + regfree(url->preg); freez(url->preg); -#endif /* def REGEX */ freez(url->dbuffer); url->dcount = 0; return JB_ERR_MEMORY; @@ -739,14 +780,11 @@ void free_url_spec(struct url_spec *url) freez(url->dbuffer); freez(url->dvec); freez(url->path); -#ifdef REGEX if (url->preg) { regfree(url->preg); freez(url->preg); } -#endif - } @@ -769,11 +807,7 @@ int url_match(const struct url_spec *pattern, return ((pattern->port == 0) || (pattern->port == url->port)) && ((pattern->dbuffer == NULL) || (domain_match(pattern, url) == 0)) && ((pattern->path == NULL) || -#ifdef REGEX (regexec(pattern->preg, url->path, 0, NULL, 0) == 0) -#else - (strncmp(pattern->path, url->path, pattern->pathlen) == 0) -#endif ); }