X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=loaders.c;h=7843fc4cf7e1cee48654de7db3c47a2f351ac8b0;hb=d5f83d256499a62f6cbcf49e8078af22f7fc2249;hp=b200b90228a43d64b12bf3607bc96c1c1f3c2a1f;hpb=28b7a0e2c74ce13c5e3fb72a44da1fa5f8ba6e38;p=privoxy.git diff --git a/loaders.c b/loaders.c index b200b902..7843fc4c 100644 --- a/loaders.c +++ b/loaders.c @@ -1,4 +1,4 @@ -const char loaders_rcs[] = "$Id: loaders.c,v 1.25 2001/09/13 22:44:03 jongfoster Exp $"; +const char loaders_rcs[] = "$Id: loaders.c,v 1.28 2001/10/07 15:40:39 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $ @@ -35,6 +35,17 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.25 2001/09/13 22:44:03 jongfoster * * Revisions : * $Log: loaders.c,v $ + * Revision 1.28 2001/10/07 15:40:39 oes + * Replaced 6 boolean members of csp with one bitmap (csp->flags) + * + * Revision 1.27 2001/09/22 16:36:59 jongfoster + * Removing unused parameter fs from read_config_line() + * + * Revision 1.26 2001/09/22 14:05:22 jongfoster + * Bugfix: Multiple escaped "#" characters in a configuration + * file are now permitted. + * Also removing 3 unused headers. + * * Revision 1.25 2001/09/13 22:44:03 jongfoster * Adding {} to an if statement * @@ -176,6 +187,7 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.25 2001/09/13 22:44:03 jongfoster #include #include #include +#include #ifndef _WIN32 #include @@ -253,7 +265,7 @@ void sweep(void) for (csp = clients; csp && (ncsp = csp->next) ; csp = csp->next) { - if (ncsp->active) + if (ncsp->flags & CSP_FLAG_ACTIVE) { /* mark this client's files as active */ @@ -289,7 +301,7 @@ void sweep(void) * follow it */ { - while( !ncsp->active ) + while (!(ncsp->flags & CSP_FLAG_ACTIVE)) { csp->next = ncsp->next; @@ -309,10 +321,10 @@ void sweep(void) destroy_list(ncsp->cookie_list); free_current_action(ncsp->action); - + #ifdef FEATURE_STATISTICS urls_read++; - if (ncsp->rejected) + if (ncsp->flags & CSP_FLAG_REJECTED) { urls_rejected++; } @@ -361,24 +373,24 @@ void sweep(void) * function fails, the contents of the buffer * are lost forever. * - * Returns : 0 => Ok, everything else is an error. + * Returns : JB_ERR_OK - Success + * JB_ERR_MEMORY - Out of memory + * JB_ERR_PARSE - Cannot parse regex (Detailed message + * written to system log) * *********************************************************************/ -int create_url_spec(struct url_spec * url, char * buf) +jb_err create_url_spec(struct url_spec * url, char * buf) { char *p; struct url_spec tmp_url[1]; - /* paranoia - should never happen. */ - if ((url == NULL) || (buf == NULL)) - { - return 1; - } + assert(url); + assert(buf); /* save a copy of the orignal specification */ if ((url->spec = strdup(buf)) == NULL) { - return 1; + return JB_ERR_MEMORY; } if ((p = strchr(buf, '/'))) @@ -386,7 +398,7 @@ int create_url_spec(struct url_spec * url, char * buf) if (NULL == (url->path = strdup(p))) { freez(url->spec); - return 1; + return JB_ERR_MEMORY; } url->pathlen = strlen(url->path); *p = '\0'; @@ -406,7 +418,7 @@ int create_url_spec(struct url_spec * url, char * buf) { freez(url->spec); freez(url->path); - return 1; + return JB_ERR_MEMORY; } sprintf(rebuf, "^(%s)", url->path); @@ -416,18 +428,22 @@ int create_url_spec(struct url_spec * url, char * buf) if (errcode) { size_t errlen = regerror(errcode, - url->preg, buf, sizeof(buf)); + url->preg, rebuf, sizeof(rebuf)); - buf[errlen] = '\0'; + 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, buf); + url->spec, rebuf); freez(url->spec); freez(url->path); freez(url->preg); - return 1; + return JB_ERR_PARSE; } } #endif @@ -448,18 +464,29 @@ int create_url_spec(struct url_spec * url, char * buf) #ifdef REGEX freez(url->preg); #endif /* def REGEX */ - return 1; + 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 0; /* OK */ + return JB_ERR_OK; } @@ -577,20 +604,17 @@ int check_file_changed(const struct file_list * current, * Description : Read a single non-empty line from a file and return * it. Trims comments, leading and trailing whitespace * and respects escaping of newline and comment char. - * Also writes the file to fs->proxy_args. * * Parameters : * 1 : buf = Buffer to use. * 2 : buflen = Size of buffer in bytes. * 3 : fp = File to read from - * 4 : fs = File will be written to fs->proxy_args. May - * be NULL to disable this feature. * * Returns : NULL on EOF or error * Otherwise, returns buf. * *********************************************************************/ -char *read_config_line(char *buf, int buflen, FILE *fp, struct file_list *fs) +char *read_config_line(char *buf, int buflen, FILE *fp) { char *p; char *src; @@ -746,7 +770,7 @@ int load_trustfile(struct client_state *csp) tl = csp->config->trust_list; - while (read_config_line(buf, sizeof(buf), fp, fs) != NULL) + while (read_config_line(buf, sizeof(buf), fp) != NULL) { trusted = 0; reject = 1; @@ -913,7 +937,7 @@ int load_re_filterfile(struct client_state *csp) } /* Read line by line */ - while (read_config_line(buf, sizeof(buf), fp, fs) != NULL) + while (read_config_line(buf, sizeof(buf), fp) != NULL) { enlist( bl->patterns, buf );