X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jcc.c;h=0970e0beb71255b7a1d77b9a9db2a336562b1a84;hp=6b17d1f4e8e198aeb533702bae872b8fb759f10d;hb=8e22cb9cdedac101a56a2f4e724aef21ef1a1cc4;hpb=692f5cb1598fd8e5645e42e5d32387ab0ae69a22 diff --git a/jcc.c b/jcc.c index 6b17d1f4..0970e0be 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.5 2001/05/22 18:46:04 oes Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.9 2001/05/26 00:28:36 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,22 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.5 2001/05/22 18:46:04 oes Exp $"; * * Revisions : * $Log: jcc.c,v $ + * Revision 1.9 2001/05/26 00:28:36 jongfoster + * Automatic reloading of config file. + * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32). + * Most of the global variables have been moved to a new + * struct configuration_spec, accessed through csp->config->globalname + * Most of the globals remaining are used by the Win32 GUI. + * + * Revision 1.8 2001/05/25 22:43:18 jongfoster + * Fixing minor memory leak and buffer overflow. + * + * Revision 1.7 2001/05/25 22:34:30 jongfoster + * Hard tabs->Spaces + * + * Revision 1.6 2001/05/23 00:13:58 joergs + * AmigaOS support fixed. + * * Revision 1.5 2001/05/22 18:46:04 oes * * - Enabled filtering banners by size rather than URL @@ -276,19 +292,19 @@ static void chat(struct client_state *csp) #ifdef FORCE_LOAD /* If this request contains the FORCE_PREFIX, - * better get rid of it now and set the force flag --oes + * better get rid of it now and set the force flag --oes */ - if(strstr(req, FORCE_PREFIX)) + if (strstr(req, FORCE_PREFIX)) { - strclean(req, FORCE_PREFIX); - log_error(LOG_LEVEL_FORCE, "Enforcing request \"%s\".\n", req); - csp->force = 1; - } + strclean(req, FORCE_PREFIX); + log_error(LOG_LEVEL_FORCE, "Enforcing request \"%s\".\n", req); + csp->force = 1; + } else { - csp->force = 0; - } + csp->force = 0; + } #endif /* def FORCE_LOAD */ parse_http_request(req, http, csp); @@ -410,8 +426,8 @@ static void chat(struct client_state *csp) destroy_list(csp->headers); - /* Check the request against all rules, unless - * we're toggled off or in force mode. + /* Check the request against all rules, unless + * we're toggled off or in force mode. */ if (IS_TOGGLED_ON @@ -422,7 +438,7 @@ static void chat(struct client_state *csp) IS_TRUSTED_URL (p = block_url(http, csp)) #ifdef FAST_REDIRECTS - || (fast_redirects && (p = redirect_url(http, csp))) + || (csp->config->fast_redirects && (p = redirect_url(http, csp))) #endif /* def FAST_REDIRECTS */ )) { @@ -434,24 +450,26 @@ static void chat(struct client_state *csp) #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) /* Block as image? */ - if ( (tinygif > 0) && block_imageurl(http, csp) ) + if ( (csp->config->tinygif > 0) && block_imageurl(http, csp) ) { /* Send "blocked" image */ log_error(LOG_LEVEL_GPC, "%s%s image crunch!", http->hostport, http->path); - if ((tinygif == 2) || strstr(http->path, "ijb-send-banner")) + if ((csp->config->tinygif == 2) || strstr(http->path, "ijb-send-banner")) { write_socket(csp->cfd, JBGIF, sizeof(JBGIF)-1); } - if (tinygif == 1) + else if (csp->config->tinygif == 1) { write_socket(csp->cfd, BLANKGIF, sizeof(BLANKGIF)-1); } - else if ((tinygif == 3) && (tinygifurl)) + else if ((csp->config->tinygif == 3) && (csp->config->tinygifurl)) { - p = (char *)malloc(strlen(HTTP_REDIRECT_TEMPLATE) + strlen(tinygifurl)); - sprintf(p, HTTP_REDIRECT_TEMPLATE, tinygifurl); + freez(p); + p = (char *)malloc(sizeof(HTTP_REDIRECT_TEMPLATE) + + strlen(csp->config->tinygifurl)); + sprintf(p, HTTP_REDIRECT_TEMPLATE, csp->config->tinygifurl); write_socket(csp->cfd, p, strlen(p)); } else @@ -963,22 +981,8 @@ int main(int argc, const char *argv[]) configfile = argv[1]; } - remove_all_loaders(); - memset( proxy_args, 0, sizeof( proxy_args ) ); files->next = NULL; - load_config( 0 ); - - /* - * Since load_config acts as a signal handler too, it returns - * its status in configret. Check it for an error in loading. - */ - if ( 0 != configret ) - { - /* load config failed! Exit with error. */ - return( 1 ); - } - #ifdef _WIN32 InitWin32(); #endif @@ -987,7 +991,6 @@ int main(int argc, const char *argv[]) #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, SIG_IGN); - signal(SIGHUP, load_config); #else /* ifdef _WIN32 */ # ifdef _WIN_CONSOLE @@ -1023,24 +1026,29 @@ static void listen_loop(void) { struct client_state *csp = NULL; int bfd; + struct configuration_spec * config; + + config = load_config(); log_error(LOG_LEVEL_CONNECT, "bind (%s, %d)", - haddr ? haddr : "INADDR_ANY", hport); + config->haddr ? config->haddr : "INADDR_ANY", config->hport); - bfd = bind_port(haddr, hport); - config_changed = 0; + bfd = bind_port(config->haddr, config->hport); if (bfd < 0) { log_error(LOG_LEVEL_FATAL, "can't bind %s:%d: %E " "- There may be another junkbuster or some other " "proxy running on port %d", - (NULL != haddr) ? haddr : "INADDR_ANY", hport, hport + (NULL != config->haddr) ? config->haddr : "INADDR_ANY", + config->hport, config->hport ); /* shouldn't get here */ return; } + config->need_bind = 0; + while (FOREVER) { @@ -1063,7 +1071,9 @@ static void listen_loop(void) csp->active = 1; csp->sfd = -1; - if ( config_changed ) + csp->config = config = load_config(); + + if ( config->need_bind ) { /* * Since we were listening to the "old port", we will not see @@ -1077,13 +1087,26 @@ static void listen_loop(void) * request. This should not be a so common of an operation * that this will hurt people's feelings. */ + close_socket(bfd); log_error(LOG_LEVEL_CONNECT, "bind (%s, %d)", - haddr ? haddr : "INADDR_ANY", hport); - bfd = bind_port(haddr, hport); + config->haddr ? config->haddr : "INADDR_ANY", config->hport); + bfd = bind_port(config->haddr, config->hport); - config_changed = 0; + if (bfd < 0) + { + log_error(LOG_LEVEL_FATAL, "can't bind %s:%d: %E " + "- There may be another junkbuster or some other " + "proxy running on port %d", + (NULL != config->haddr) ? config->haddr : "INADDR_ANY", + config->hport, config->hport + ); + /* shouldn't get here */ + return; + } + + config->need_bind = 0; } log_error(LOG_LEVEL_CONNECT, "accept connection ... "); @@ -1097,30 +1120,39 @@ static void listen_loop(void) { exit(1); } -#endif +#endif + freez(csp); continue; } else { log_error(LOG_LEVEL_CONNECT, "OK"); - } + } #if defined(TOGGLE) /* by haroon - most of credit to srt19170 */ csp->toggled_on = g_bToggleIJB; #endif - /* add it to the list of clients */ - csp->next = clients->next; - clients->next = csp; - if (run_loader(csp)) { log_error(LOG_LEVEL_FATAL, "a loader failed - must exit"); /* Never get here - LOG_LEVEL_FATAL causes program exit */ } - - if (multi_threaded) + + if (block_acl(NULL,csp)) + { + log_error(LOG_LEVEL_CONNECT, "Connection dropped due to ACL"); + close_socket(csp->cfd); + freez(csp); + continue; + } + + /* add it to the list of clients */ + csp->next = clients->next; + clients->next = csp; + + if (config->multi_threaded) { int child_id;