From: jongfoster Date: Tue, 22 Jan 2002 23:31:43 +0000 (+0000) Subject: Replacing strsav() with string_append() X-Git-Tag: v_2_9_11~18 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=2bd9da82bd20174e904cae1cce5f19cdfb14fa96 Replacing strsav() with string_append() --- diff --git a/loadcfg.c b/loadcfg.c index 3c3f923a..48b72a1a 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.28 2001/12/30 14:07:32 steudten Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.29 2002/01/17 21:02:30 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -35,6 +35,11 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.28 2001/12/30 14:07:32 steudten E * * Revisions : * $Log: loadcfg.c,v $ + * Revision 1.29 2002/01/17 21:02:30 jongfoster + * 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. + * * Revision 1.28 2001/12/30 14:07:32 steudten * - Add signal handling (unix) * - Add SIGHUP handler (unix) @@ -246,6 +251,7 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.28 2001/12/30 14:07:32 steudten E #include #include #include +#include #ifdef _WIN32 @@ -361,7 +367,7 @@ static struct file_list *current_configfile = NULL; #define hash_show_on_task_bar 215410365ul /* "show-on-task-bar" */ -static void savearg(char *c, char *o, struct configuration_spec * config); +static void savearg(char *command, char *argument, struct configuration_spec * config); /********************************************************************* * @@ -502,6 +508,7 @@ struct configuration_spec * load_config(void) config->multi_threaded = 1; config->hport = HADDR_PORT; config->buffer_limit = 4096 * 1024; + config->proxy_args = strdup(""); if ((configfp = fopen(configfile, "r")) == NULL) { @@ -614,7 +621,7 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for " "deny-access directive in configuration file."); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Wrong number of parameters for " "deny-access directive in configuration file.

\n"); continue; @@ -635,12 +642,12 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Invalid source IP for deny-access " "directive in configuration file: \"%s\"", vec[0]); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Invalid source IP for deny-access directive" " in configuration file: \""); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, vec[0]); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "\"

\n"); freez(cur_acl); continue; @@ -651,12 +658,12 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Invalid destination IP for deny-access " "directive in configuration file: \"%s\"", vec[0]); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Invalid destination IP for deny-access directive" " in configuration file: \""); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, vec[0]); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "\"

\n"); freez(cur_acl); continue; @@ -720,7 +727,7 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for forward " "directive in configuration file."); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Wrong number of parameters for " "forward directive in configuration file."); continue; @@ -742,7 +749,7 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward " "directive in configuration file."); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Bad URL specifier for " "forward directive in configuration file."); continue; @@ -783,7 +790,7 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for " "forward-socks4 directive in configuration file."); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Wrong number of parameters for " "forward-socks4 directive in configuration file."); continue; @@ -805,7 +812,7 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4 " "directive in configuration file."); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Bad URL specifier for " "forward-socks4 directive in configuration file."); continue; @@ -864,7 +871,7 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for " "forward-socks4a directive in configuration file."); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Wrong number of parameters for " "forward-socks4a directive in configuration file."); continue; @@ -886,7 +893,7 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Bad URL specifier for forward-socks4a " "directive in configuration file."); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Bad URL specifier for " "forward-socks4a directive in configuration file."); continue; @@ -979,7 +986,7 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Wrong number of parameters for " "permit-access directive in configuration file."); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Wrong number of parameters for " "permit-access directive in configuration file.

\n"); @@ -1001,12 +1008,12 @@ struct configuration_spec * load_config(void) { log_error(LOG_LEVEL_ERROR, "Invalid source IP for permit-access " "directive in configuration file: \"%s\"", vec[0]); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Invalid source IP for permit-access directive" " in configuration file: \""); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, vec[0]); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "\"

\n"); freez(cur_acl); continue; @@ -1018,12 +1025,12 @@ struct configuration_spec * load_config(void) log_error(LOG_LEVEL_ERROR, "Invalid destination IP for " "permit-access directive in configuration file: \"%s\"", vec[0]); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "
\nWARNING: Invalid destination IP for permit-access directive" " in configuration file: \""); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, vec[0]); - config->proxy_args = strsav( config->proxy_args, + string_append(&config->proxy_args, "\"

\n"); freez(cur_acl); continue; @@ -1240,9 +1247,9 @@ struct configuration_spec * load_config(void) /* log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in " "configuration file: \"%s\"", hash_string( cmd ), buf); */ - config->proxy_args = strsav( config->proxy_args, "
\nWARNING: unrecognized directive : "); - config->proxy_args = strsav( config->proxy_args, buf); - config->proxy_args = strsav( config->proxy_args, "

\n"); + string_append(&config->proxy_args, "
\nWARNING: unrecognized directive : "); + string_append(&config->proxy_args, buf); + string_append(&config->proxy_args, "

\n"); continue; /****************************************************************************/ @@ -1251,6 +1258,11 @@ struct configuration_spec * load_config(void) fclose(configfp); + if (NULL == config->proxy_args) + { + log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args"); + } + init_error_log(Argv[0], config->logfile, config->debug); if (config->actions_file) @@ -1392,54 +1404,69 @@ struct configuration_spec * load_config(void) * Function : savearg * * Description : Called from `load_config'. It saves each non-empty - * and non-comment line from config into a list. This - * list is used to create the show-proxy-args page. + * and non-comment line from config into + * config->proxy_args. This is used to create the + * show-proxy-args page. On error, frees + * config->proxy_args and sets it to NULL * * Parameters : - * 1 : c = config setting that was found - * 2 : o = the setting's argument (if any) + * 1 : command = config setting that was found + * 2 : argument = the setting's argument (if any) * * Returns : N/A * *********************************************************************/ -static void savearg(char *c, char *o, struct configuration_spec * config) +static void savearg(char *command, char *argument, struct configuration_spec * config) { - char buf[BUFFER_SIZE]; + char * buf; + char * s; + + assert(command); + assert(*command); + assert(argument); - *buf = '\0'; + buf = strdup(""); - if ( ( NULL != c ) && ( '\0' != *c ) ) + s = html_encode(command); + if (NULL == s) { - if ((c = html_encode(c))) - { - sprintf(buf, "%s ", c, c); - } - freez(c); + freez(buf); + freez(config->proxy_args); + return; } - if ( ( NULL != o ) && ( '\0' != *o ) ) + string_append(&buf, ""); + string_join (&buf, s); + string_append(&buf, " "); + + if ( (NULL != argument) && ('\0' != *argument) ) { - if ((o = html_encode(o))) + s = html_encode(argument); + if (NULL == s) { - if (strncmpic(o, "http://", 7) == 0) - { - strcat(buf, ""); - strcat(buf, o); - strcat(buf, ""); - } - else - { - strcat(buf, o); - } + freez(buf); + freez(config->proxy_args); + return; } - freez(o); - } - strcat(buf, "
\n"); + if (strncmpic(argument, "http://", 7) == 0) + { + string_append(&buf, ""); + string_join (&buf, s); + string_append(&buf, ""); + } + else + { + string_join (&buf, s); + } + } - config->proxy_args = strsav(config->proxy_args, buf); + string_append(&buf, "
\n"); + string_join(&config->proxy_args, buf); }