-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 $
*
* 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)
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
+#include <assert.h>
#ifdef _WIN32
#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);
/*********************************************************************
*
config->multi_threaded = 1;
config->hport = HADDR_PORT;
config->buffer_limit = 4096 * 1024;
+ config->proxy_args = strdup("");
if ((configfp = fopen(configfile, "r")) == NULL)
{
{
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,
"<br>\nWARNING: Wrong number of parameters for "
"deny-access directive in configuration file.<br><br>\n");
continue;
{
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,
"<br>\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,
"\"<br><br>\n");
freez(cur_acl);
continue;
{
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,
"<br>\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,
"\"<br><br>\n");
freez(cur_acl);
continue;
{
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,
"<br>\nWARNING: Wrong number of parameters for "
"forward directive in configuration file.");
continue;
{
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,
"<br>\nWARNING: Bad URL specifier for "
"forward directive in configuration file.");
continue;
{
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,
"<br>\nWARNING: Wrong number of parameters for "
"forward-socks4 directive in configuration file.");
continue;
{
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,
"<br>\nWARNING: Bad URL specifier for "
"forward-socks4 directive in configuration file.");
continue;
{
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,
"<br>\nWARNING: Wrong number of parameters for "
"forward-socks4a directive in configuration file.");
continue;
{
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,
"<br>\nWARNING: Bad URL specifier for "
"forward-socks4a directive in configuration file.");
continue;
{
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,
"<br>\nWARNING: Wrong number of parameters for "
"permit-access directive in configuration file.<br><br>\n");
{
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,
"<br>\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,
"\"<br><br>\n");
freez(cur_acl);
continue;
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,
"<br>\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,
"\"<br><br>\n");
freez(cur_acl);
continue;
/* log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%luul) in "
"configuration file: \"%s\"", hash_string( cmd ), buf);
*/
- config->proxy_args = strsav( config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
- config->proxy_args = strsav( config->proxy_args, buf);
- config->proxy_args = strsav( config->proxy_args, "<br><br>\n");
+ string_append(&config->proxy_args, "<br>\nWARNING: unrecognized directive : ");
+ string_append(&config->proxy_args, buf);
+ string_append(&config->proxy_args, "<br><br>\n");
continue;
/****************************************************************************/
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)
* 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, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
- }
- freez(c);
+ freez(buf);
+ freez(config->proxy_args);
+ return;
}
- if ( ( NULL != o ) && ( '\0' != *o ) )
+ string_append(&buf, "<a href=\"" REDIRECT_URL "option#");
+ string_append(&buf, s);
+ string_append(&buf, "\">");
+ string_join (&buf, s);
+ string_append(&buf, "</a> ");
+
+ 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, "<a href=\"");
- strcat(buf, o);
- strcat(buf, "\">");
- strcat(buf, o);
- strcat(buf, "</a>");
- }
- else
- {
- strcat(buf, o);
- }
+ freez(buf);
+ freez(config->proxy_args);
+ return;
}
- freez(o);
- }
- strcat(buf, "<br>\n");
+ if (strncmpic(argument, "http://", 7) == 0)
+ {
+ string_append(&buf, "<a href=\"");
+ string_append(&buf, s);
+ string_append(&buf, "\">");
+ string_join (&buf, s);
+ string_append(&buf, "</a>");
+ }
+ else
+ {
+ string_join (&buf, s);
+ }
+ }
- config->proxy_args = strsav(config->proxy_args, buf);
+ string_append(&buf, "<br>\n");
+ string_join(&config->proxy_args, buf);
}