From: jongfoster Date: Thu, 17 Jan 2002 21:03:08 +0000 (+0000) Subject: Moving all our URL and URL pattern parsing code to urlmatch.c. X-Git-Tag: v_2_9_11~37 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=e9da57995f3b86155d0dd2abadace8b96dbc1d0d Moving all our URL and URL pattern parsing code to urlmatch.c. Renaming free_url to free_url_spec, since it frees a struct url_spec. --- diff --git a/loadcfg.c b/loadcfg.c index 9d39f442..3c3f923a 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.27 2001/11/07 00:02:13 steudten Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.28 2001/12/30 14:07:32 steudten Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -35,6 +35,14 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.27 2001/11/07 00:02:13 steudten E * * Revisions : * $Log: loadcfg.c,v $ + * Revision 1.28 2001/12/30 14:07:32 steudten + * - Add signal handling (unix) + * - Add SIGHUP handler (unix) + * - Add creation of pidfile (unix) + * - Add action 'top' in rc file (RH) + * - Add entry 'SIGNALS' to manpage + * - Add exit message to logfile (unix) + * * Revision 1.27 2001/11/07 00:02:13 steudten * Add line number in error output for lineparsing for * actionsfile and configfile. @@ -272,6 +280,7 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.27 2001/11/07 00:02:13 steudten E #include "errlog.h" #include "ssplit.h" #include "encode.h" +#include "urlmatch.h" const char loadcfg_h_rcs[] = LOADCFG_H_VERSION; @@ -385,7 +394,7 @@ void unload_configfile (void * data) while (cur_fwd != NULL) { struct forward_spec * next_fwd = cur_fwd->next; - free_url(cur_fwd->url); + free_url_spec(cur_fwd->url); freez(cur_fwd->gateway_host); freez(cur_fwd->forward_host); diff --git a/loaders.c b/loaders.c index 0dd8ebb2..2ec1ffed 100644 --- a/loaders.c +++ b/loaders.c @@ -1,4 +1,4 @@ -const char loaders_rcs[] = "$Id: loaders.c,v 1.33 2001/11/13 00:16:38 jongfoster Exp $"; +const char loaders_rcs[] = "$Id: loaders.c,v 1.34 2001/12/30 14:07:32 steudten Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $ @@ -35,6 +35,14 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.33 2001/11/13 00:16:38 jongfoster * * Revisions : * $Log: loaders.c,v $ + * Revision 1.34 2001/12/30 14:07:32 steudten + * - Add signal handling (unix) + * - Add SIGHUP handler (unix) + * - Add creation of pidfile (unix) + * - Add action 'top' in rc file (RH) + * - Add entry 'SIGNALS' to manpage + * - Add exit message to logfile (unix) + * * Revision 1.33 2001/11/13 00:16:38 jongfoster * Replacing references to malloc.h with the standard stdlib.h * (See ANSI or K&R 2nd Ed) @@ -223,6 +231,7 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.33 2001/11/13 00:16:38 jongfoster #include "miscutil.h" #include "errlog.h" #include "actions.h" +#include "urlmatch.h" const char loaders_h_rcs[] = LOADERS_H_VERSION; @@ -363,174 +372,6 @@ void sweep(void) } -/********************************************************************* - * - * Function : create_url_spec - * - * Description : Creates a "url_spec" structure from a string. - * 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). - * 2 : buf = Source pattern, null terminated. NOTE: The - * contents of this buffer are destroyed by this - * function. If this function succeeds, the - * buffer is copied to url->spec. If this - * function fails, the contents of the buffer - * are lost forever. - * - * Returns : JB_ERR_OK - Success - * JB_ERR_MEMORY - Out of memory - * JB_ERR_PARSE - Cannot parse regex (Detailed message - * written to system log) - * - *********************************************************************/ -jb_err create_url_spec(struct url_spec * url, char * buf) -{ - char *p; - struct url_spec tmp_url[1]; - - assert(url); - assert(buf); - - /* save a copy of the orignal specification */ - if ((url->spec = strdup(buf)) == NULL) - { - return JB_ERR_MEMORY; - } - - if ((p = strchr(buf, '/'))) - { - if (NULL == (url->path = strdup(p))) - { - freez(url->spec); - return JB_ERR_MEMORY; - } - url->pathlen = strlen(url->path); - *p = '\0'; - } - else - { - url->path = NULL; - url->pathlen = 0; - } -#ifdef REGEX - if (url->path) - { - int errcode; - char rebuf[BUFFER_SIZE]; - - if (NULL == (url->preg = zalloc(sizeof(*url->preg)))) - { - freez(url->spec); - freez(url->path); - return JB_ERR_MEMORY; - } - - sprintf(rebuf, "^(%s)", url->path); - - errcode = regcomp(url->preg, rebuf, - (REG_EXTENDED|REG_NOSUB|REG_ICASE)); - if (errcode) - { - size_t errlen = regerror(errcode, - url->preg, rebuf, sizeof(rebuf)); - - if (errlen > (sizeof(rebuf) - (size_t)1)) - { - errlen = sizeof(rebuf) - (size_t)1; - } - rebuf[errlen] = '\0'; - - log_error(LOG_LEVEL_ERROR, "error compiling %s: %s", - url->spec, rebuf); - - freez(url->spec); - freez(url->path); - freez(url->preg); - - return JB_ERR_PARSE; - } - } -#endif - if ((p = strchr(buf, ':')) == NULL) - { - url->port = 0; - } - else - { - *p++ = '\0'; - url->port = atoi(p); - } - - if ((url->domain = strdup(buf)) == NULL) - { - freez(url->spec); - freez(url->path); -#ifdef REGEX - freez(url->preg); -#endif /* def REGEX */ - return JB_ERR_MEMORY; - } - - /* split domain into components */ - - *tmp_url = dsplit(url->domain); - if (tmp_url->dbuf == NULL) - { - freez(url->spec); - freez(url->path); - freez(url->domain); -#ifdef REGEX - freez(url->preg); -#endif /* def REGEX */ - return JB_ERR_MEMORY; - } - - url->dbuf = tmp_url->dbuf; - url->dcnt = tmp_url->dcnt; - url->dvec = tmp_url->dvec; - url->unanchored = tmp_url->unanchored; - - return JB_ERR_OK; - -} - - -/********************************************************************* - * - * Function : free_url - * - * Description : Called from the "unloaders". Freez the url - * structure elements. - * - * Parameters : - * 1 : url = pointer to a url_spec structure. - * - * Returns : N/A - * - *********************************************************************/ -void free_url(struct url_spec *url) -{ - if (url == NULL) return; - - freez(url->spec); - freez(url->domain); - freez(url->dbuf); - freez(url->dvec); - freez(url->path); -#ifdef REGEX - if (url->preg) - { - regfree(url->preg); - freez(url->preg); - } -#endif - -} - - /********************************************************************* * * Function : check_file_changed @@ -719,7 +560,7 @@ static void unload_trustfile(void *f) unload_trustfile(b->next); /* Stack is cheap, isn't it? */ - free_url(b->url); + free_url_spec(b->url); freez(b); @@ -831,6 +672,7 @@ int load_trustfile(struct client_state *csp) if (trusted) { *tl++ = b->url; + /* FIXME BUFFER OVERFLOW if >=64 entries */ } } diff --git a/loaders.h b/loaders.h index b231bd1b..6dcc0df9 100644 --- a/loaders.h +++ b/loaders.h @@ -1,6 +1,6 @@ #ifndef LOADERS_H_INCLUDED #define LOADERS_H_INCLUDED -#define LOADERS_H_VERSION "$Id: loaders.h,v 1.12 2001/11/07 00:02:13 steudten Exp $" +#define LOADERS_H_VERSION "$Id: loaders.h,v 1.13 2001/12/30 14:07:32 steudten Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.h,v $ @@ -37,6 +37,14 @@ * * Revisions : * $Log: loaders.h,v $ + * Revision 1.13 2001/12/30 14:07:32 steudten + * - Add signal handling (unix) + * - Add SIGHUP handler (unix) + * - Add creation of pidfile (unix) + * - Add action 'top' in rc file (RH) + * - Add entry 'SIGNALS' to manpage + * - Add exit message to logfile (unix) + * * Revision 1.12 2001/11/07 00:02:13 steudten * Add line number in error output for lineparsing for * actionsfile and configfile. @@ -145,9 +153,6 @@ extern int load_trustfile(struct client_state *csp); -extern jb_err create_url_spec(struct url_spec * url, char * buf); -extern void free_url(struct url_spec *url); - extern void add_loader(int (*loader)(struct client_state *), struct configuration_spec * config); extern int run_loader(struct client_state *csp);