conf: refactor loading of config file out into load_config_file()
and make config_compile and config_parse static to conf.c Michael
This commit is contained in:
parent
a09dd9cd00
commit
fba81e4174
29
src/conf.c
29
src/conf.c
@ -265,7 +265,7 @@ const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
|
|||||||
*
|
*
|
||||||
* Returns 0 on success; negative upon failure.
|
* Returns 0 on success; negative upon failure.
|
||||||
*/
|
*/
|
||||||
int config_compile (void)
|
static int config_compile (void)
|
||||||
{
|
{
|
||||||
unsigned int i, r;
|
unsigned int i, r;
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ static int check_match (struct config_s *conf, const char *line)
|
|||||||
/*
|
/*
|
||||||
* Parse the previously opened configuration stream.
|
* Parse the previously opened configuration stream.
|
||||||
*/
|
*/
|
||||||
int config_parse (struct config_s *conf, FILE * f)
|
static int config_parse (struct config_s *conf, FILE * f)
|
||||||
{
|
{
|
||||||
char buffer[1024]; /* 1KB lines should be plenty */
|
char buffer[1024]; /* 1KB lines should be plenty */
|
||||||
unsigned long lineno = 1;
|
unsigned long lineno = 1;
|
||||||
@ -329,6 +329,31 @@ int config_parse (struct config_s *conf, FILE * f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the settings from a config file.
|
||||||
|
*/
|
||||||
|
int load_config_file (const char *config_fname, struct config_s *conf)
|
||||||
|
{
|
||||||
|
FILE *config_file;
|
||||||
|
|
||||||
|
config_file = fopen (config_fname, "r");
|
||||||
|
if (!config_file) {
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s: Could not open config file \"%s\".\n",
|
||||||
|
PACKAGE, config_fname);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config_compile () || config_parse (&config, config_file)) {
|
||||||
|
fprintf (stderr, "Unable to parse config file. "
|
||||||
|
"Not starting.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose (config_file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* The following are basic data extraction building blocks that can
|
* The following are basic data extraction building blocks that can
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#ifndef TINYPROXY_CONF_H
|
#ifndef TINYPROXY_CONF_H
|
||||||
#define TINYPROXY_CONF_H
|
#define TINYPROXY_CONF_H
|
||||||
|
|
||||||
extern int config_compile (void);
|
extern int load_config_file (const char *config_fname, struct config_s *conf);
|
||||||
extern int config_parse (struct config_s *conf, FILE * f);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
16
src/main.c
16
src/main.c
@ -329,23 +329,11 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
|
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
|
||||||
|
|
||||||
/* Read in the settings from the config file */
|
ret = load_config_file(config.config_file, &config);
|
||||||
config_file = fopen (config.config_file, "r");
|
if (ret != 0) {
|
||||||
if (!config_file) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Could not open config file \"%s\".\n",
|
|
||||||
argv[0], config.config_file);
|
|
||||||
exit (EX_SOFTWARE);
|
exit (EX_SOFTWARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_compile () || config_parse (&config, config_file)) {
|
|
||||||
fprintf (stderr, "Unable to parse config file. "
|
|
||||||
"Not starting.\n");
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose (config_file);
|
|
||||||
|
|
||||||
ret = setup_logging ();
|
ret = setup_logging ();
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
exit (EX_SOFTWARE);
|
exit (EX_SOFTWARE);
|
||||||
|
Loading…
Reference in New Issue
Block a user