kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit c14f3031ff7cac76c40517b3a8e690759c6df05f
parent 2bdc9210a0f6ea957dc6d28593f4b6aeed581171
Author: Joris Vink <joris@coders.se>
Date:   Tue, 22 Apr 2014 13:15:19 +0200

Allow us to include config files with "include"

Diffstat:
src/config.c | 59+++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 41 insertions(+), 18 deletions(-)

diff --git a/src/config.c b/src/config.c @@ -26,6 +26,7 @@ /* XXX - This is becoming a clusterfuck. Fix it. */ +static int configure_include(char **); static int configure_bind(char **); static int configure_load(char **); static int configure_handler(char **); @@ -60,11 +61,13 @@ static int configure_authentication_value(char **); static int configure_authentication_validator(char **); static void domain_sslstart(void); +static void kore_parse_config_file(char *); static struct { const char *name; int (*configure)(char **); } config_names[] = { + { "include", configure_include }, { "bind", configure_bind }, { "load", configure_load }, { "static", configure_handler }, @@ -110,15 +113,39 @@ static struct kore_module_handle *current_handler = NULL; void kore_parse_config(void) { + if (config_file == NULL) + fatal("specify a configuration file with -c"); + + kore_parse_config_file(config_file); + + if (!kore_module_loaded()) + fatal("no site module was loaded"); + if (kore_cb_name != NULL && kore_cb == NULL) + fatal("no '%s' symbol found for kore_cb", kore_cb_name); + if (LIST_EMPTY(&listeners)) + fatal("no listeners defined"); + if (chroot_path == NULL) + fatal("missing a chroot path"); + if (runas_user == NULL) + fatal("missing a username to run as"); + if ((pw = getpwnam(runas_user)) == NULL) + fatal("user '%s' does not exist", runas_user); + + if (getuid() != 0 && skip_chroot == 0) + fatal("Cannot chroot(), use -n to skip it"); +} + +static void +kore_parse_config_file(char *fpath) +{ FILE *fp; int i, lineno; char buf[BUFSIZ], *p, *t, *argv[5]; - if (config_file == NULL) - fatal("specify a configuration file with -c"); + if ((fp = fopen(fpath, "r")) == NULL) + fatal("configuration given cannot be opened: %s", fpath); - if ((fp = fopen(config_file, "r")) == NULL) - fatal("configuration given cannot be opened: %s", config_file); + kore_debug("parsing configuration file '%s'", fpath); lineno = 1; while (fgets(buf, sizeof(buf), fp) != NULL) { @@ -172,22 +199,18 @@ kore_parse_config(void) } fclose(fp); +} - if (!kore_module_loaded()) - fatal("no site module was loaded"); - if (kore_cb_name != NULL && kore_cb == NULL) - fatal("no '%s' symbol found for kore_cb", kore_cb_name); - if (LIST_EMPTY(&listeners)) - fatal("no listeners defined"); - if (chroot_path == NULL) - fatal("missing a chroot path"); - if (runas_user == NULL) - fatal("missing a username to run as"); - if ((pw = getpwnam(runas_user)) == NULL) - fatal("user '%s' does not exist", runas_user); +static int +configure_include(char **argv) +{ + if (argv[1] == NULL) { + printf("No file given in include directive\n"); + return (KORE_RESULT_ERROR); + } - if (getuid() != 0 && skip_chroot == 0) - fatal("Cannot chroot(), use -n to skip it"); + kore_parse_config_file(argv[1]); + return (KORE_RESULT_OK); } static int