diff options
author | Michael Adam <obnox@samba.org> | 2009-11-08 23:41:21 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2009-11-14 12:13:10 +0100 |
commit | fba81e417422abb249efa6576b3e3af6e9b044ed (patch) | |
tree | acf1278a997165d66f5b0a3c6024c25fd2dc8496 /src | |
parent | a09dd9cd00f0752ff14b326d556073904f095ed7 (diff) | |
download | tinyproxy-fba81e417422abb249efa6576b3e3af6e9b044ed.tar.gz tinyproxy-fba81e417422abb249efa6576b3e3af6e9b044ed.zip |
conf: refactor loading of config file out into load_config_file()
and make config_compile and config_parse static to conf.c
Michael
Diffstat (limited to '')
-rw-r--r-- | src/conf.c | 29 | ||||
-rw-r--r-- | src/conf.h | 3 | ||||
-rw-r--r-- | src/main.c | 16 |
3 files changed, 30 insertions, 18 deletions
@@ -265,7 +265,7 @@ const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]); * * Returns 0 on success; negative upon failure. */ -int config_compile (void) +static int config_compile (void) { 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. */ -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 */ unsigned long lineno = 1; @@ -329,6 +329,31 @@ int config_parse (struct config_s *conf, FILE * f) 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 @@ -21,7 +21,6 @@ #ifndef TINYPROXY_CONF_H #define TINYPROXY_CONF_H -extern int config_compile (void); -extern int config_parse (struct config_s *conf, FILE * f); +extern int load_config_file (const char *config_fname, struct config_s *conf); #endif @@ -329,23 +329,11 @@ main (int argc, char **argv) log_message (LOG_INFO, "Initializing " PACKAGE " ..."); - /* Read in the settings from the config file */ - config_file = fopen (config.config_file, "r"); - if (!config_file) { - fprintf (stderr, - "%s: Could not open config file \"%s\".\n", - argv[0], config.config_file); - exit (EX_SOFTWARE); - } - - if (config_compile () || config_parse (&config, config_file)) { - fprintf (stderr, "Unable to parse config file. " - "Not starting.\n"); + ret = load_config_file(config.config_file, &config); + if (ret != 0) { exit (EX_SOFTWARE); } - fclose (config_file); - ret = setup_logging (); if (ret != 0) { exit (EX_SOFTWARE); |