|
|
|
@ -131,7 +131,9 @@ static void conf_parsestr(char *str, char **key, char **expr, char **value)
|
|
|
|
|
|
|
|
|
|
int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
{
|
|
|
|
|
// printf("%s %d\n", confname, inclevel);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr,"BF-DEBUG: Parsing config file: %s %d\n", confname, inclevel);
|
|
|
|
|
#endif
|
|
|
|
|
FILE *fp = NULL;
|
|
|
|
|
char tmp[BF_MAXCFGLINE + 1];
|
|
|
|
|
int rc, maxrc = 0;
|
|
|
|
@ -156,8 +158,10 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
{
|
|
|
|
|
if( i != (int)bforce_config[i].real_key )
|
|
|
|
|
{
|
|
|
|
|
log("invalid config table: found %d instead of %d",
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr,"BF-DEBUG: invalid config table: found %d instead of %d",
|
|
|
|
|
bforce_config[i].real_key, i);
|
|
|
|
|
#endif
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -165,12 +169,15 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
|
|
|
|
|
if( (fp = file_open(confname,"r")) == NULL )
|
|
|
|
|
{
|
|
|
|
|
logerr("can't open config file \"%s\"", confname);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr,"BF-DEBUG: can't open config file \"%s\"", confname);
|
|
|
|
|
#endif
|
|
|
|
|
return(PROC_RC_IGNORE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEB((D_CONFIG, "readconfig: start reading config \"%s\"", confname));
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr,"BF-DEBUG: start reading config \"%s\"", confname);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
while( fgets(tmp, sizeof(tmp), fp) )
|
|
|
|
|
{
|
|
|
|
|
++line;
|
|
|
|
@ -180,15 +187,20 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
{
|
|
|
|
|
if( isifexpr )
|
|
|
|
|
{
|
|
|
|
|
log("warning: automatically close expression at empty line %d", line);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr,"BF-DEBUG: warning: automatically close expression at empty line %d", line);
|
|
|
|
|
#endif
|
|
|
|
|
if( ifexpr ) { free(ifexpr); ifexpr = NULL; }
|
|
|
|
|
isifexpr = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !isappend )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr,"BF-DEBUG: warning: appending empty or comment line %d", line);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
log("warning: appending empty or comment line %d", line);
|
|
|
|
|
isappend = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -230,9 +242,10 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
p_value = NULL;
|
|
|
|
|
|
|
|
|
|
conf_parsestr(fullstr ? fullstr : tmp, &p_key, &p_expr, &p_value);
|
|
|
|
|
|
|
|
|
|
DEB((D_CONFIG, "conf_readconf: [%d] key \"%s\" expr \"%s\" value \"%s\"",
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: conf_readconf: [%d] key \"%s\" expr \"%s\" value \"%s\"",
|
|
|
|
|
line, p_key, p_expr, p_value));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if( p_value )
|
|
|
|
|
{
|
|
|
|
@ -256,18 +269,24 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
{
|
|
|
|
|
if( value == NULL || expr )
|
|
|
|
|
{
|
|
|
|
|
log("incorrect usage of `%s' directive", p_key);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: incorrect usage of `%s' directive", p_key);
|
|
|
|
|
#endif
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
else if( inclevel < MAXINCLUDELEVEL )
|
|
|
|
|
{
|
|
|
|
|
DEB((D_CONFIG, "conf_readconf: process inlude file \"%s\"", value));
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: conf_readconf: process inlude file \"%s\"", value);
|
|
|
|
|
#endif
|
|
|
|
|
rc = conf_readconf(value, inclevel + 1);
|
|
|
|
|
if( rc ) rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DEB((D_CONFIG, "conf_readconf: too deep include"));
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: conf_readconf: too deep include"));
|
|
|
|
|
#endif
|
|
|
|
|
log("including level too deep");
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
@ -276,7 +295,9 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
{
|
|
|
|
|
if( value || isifexpr )
|
|
|
|
|
{
|
|
|
|
|
log("incorrect usage of `%s' directive", p_key);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: incorrect usage of `%s' directive", p_key);
|
|
|
|
|
#endif
|
|
|
|
|
rc = PROC_RC_ABORT;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -292,7 +313,9 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
{
|
|
|
|
|
if( value || expr || !isifexpr )
|
|
|
|
|
{
|
|
|
|
|
log("incorrect usage of `%s' directive", p_key);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: incorrect usage of `%s' directive", p_key);
|
|
|
|
|
#endif
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -301,69 +324,12 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
isifexpr = FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* else if( strcasecmp(p_key+1, "logfile") == 0 )
|
|
|
|
|
{
|
|
|
|
|
if( value == NULL || expr )
|
|
|
|
|
{
|
|
|
|
|
log("incorrect usage of `%s' directive", p_key);
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if( log_reopen(value, NULL, NULL) )
|
|
|
|
|
{
|
|
|
|
|
log("can't continue without logging");
|
|
|
|
|
rc = PROC_RC_ABORT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if( strcasecmp(p_key+1, "debugfile") == 0 )
|
|
|
|
|
{
|
|
|
|
|
if( value == NULL || expr )
|
|
|
|
|
{
|
|
|
|
|
log("incorrect usage of `%s' directive", p_key);
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
{
|
|
|
|
|
if( debug_isopened() ) debug_close();
|
|
|
|
|
debug_setfilename(value);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
{
|
|
|
|
|
log("incorrect directive `%s': no debug code", p_key);
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else if( strcasecmp(p_key+1, "debuglevel") == 0 )
|
|
|
|
|
{
|
|
|
|
|
if( value == NULL || expr )
|
|
|
|
|
{
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
{
|
|
|
|
|
unsigned long newlevel = 0L;
|
|
|
|
|
|
|
|
|
|
if( debug_parsestring(value, &newlevel) )
|
|
|
|
|
{
|
|
|
|
|
rc = PROC_RC_WARN;
|
|
|
|
|
}
|
|
|
|
|
debug_setlevel(newlevel, 1);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
{
|
|
|
|
|
log("incorrect directive `%s': no debug code", p_key);
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log("unknown directive `%s'", p_key);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, ("BF-DEBUG: unknown directive `%s'", p_key);
|
|
|
|
|
#endif
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -371,7 +337,9 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
{
|
|
|
|
|
if( isifexpr && expr )
|
|
|
|
|
{
|
|
|
|
|
log("can't use expressions inside $ifexpr block");
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: can't use expressions inside $ifexpr block");
|
|
|
|
|
#endif
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
else if( isifexpr )
|
|
|
|
@ -385,7 +353,9 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log("incorrect config string");
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: incorrect config string");
|
|
|
|
|
#endif
|
|
|
|
|
rc = PROC_RC_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -400,13 +370,19 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
case PROC_RC_OK:
|
|
|
|
|
break;
|
|
|
|
|
case PROC_RC_WARN:
|
|
|
|
|
log("warning in config \"%s\" line %d", confname, line);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: warning in config \"%s\" line %d", confname, line);
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
case PROC_RC_IGNORE:
|
|
|
|
|
log("ignore line %d in config \"%s\"", line, confname);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: ignore line %d in config \"%s\"", line, confname);
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
case PROC_RC_ABORT:
|
|
|
|
|
log("fatal error in config \"%s\" in line %d", confname, line);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: fatal error in config \"%s\" in line %d", confname, line);
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT_MSG();
|
|
|
|
@ -418,20 +394,29 @@ int conf_readconf(const char *confname, int inclevel)
|
|
|
|
|
file_close(fp);
|
|
|
|
|
|
|
|
|
|
if( isifexpr )
|
|
|
|
|
{ maxrc = 1; log("unterminated directive `#ifexp'"); }
|
|
|
|
|
{
|
|
|
|
|
maxrc = 1;
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: unterminated directive `#ifexp'");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( fullstr )
|
|
|
|
|
free(fullstr);
|
|
|
|
|
if( ifexpr )
|
|
|
|
|
free(ifexpr);
|
|
|
|
|
|
|
|
|
|
DEB((D_CONFIG, "readconfig: exit with maxrc = %d", maxrc));
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: readconfig: exit with maxrc = %d", maxrc);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* update subsystems */
|
|
|
|
|
if (inclevel==0) { // end of main config
|
|
|
|
|
if( log_reopen(log_getfilename(LOG_FILE_SESSION), NULL, NULL) )
|
|
|
|
|
{
|
|
|
|
|
log("can't continue without logging");
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf(stderr, "BF-DEBUG: can't continue without logging");
|
|
|
|
|
#endif
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|