diff options
author | Felix Fietkau <nbd@openwrt.org> | 2012-12-30 21:56:11 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2012-12-30 21:56:23 +0100 |
commit | 5ddf71b3638788f8d1dd1d312ec79acfac7f3e74 (patch) | |
tree | e9cb2ceba83eac4478633f616277d161cf0ee0b9 /main.c | |
parent | 9767b5af1c379608a7502e7820867af7090e9ee2 (diff) |
add config parser
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -40,6 +40,64 @@ static int run_server(void) return 0; } +static void uh_config_parse(void) +{ + const char *path = conf.file; + FILE *c; + char line[512]; + char *col1; + char *col2; + char *eol; + + if (!path) + path = "/etc/httpd.conf"; + + c = fopen(path, "r"); + if (!c) + return; + + memset(line, 0, sizeof(line)); + + while (fgets(line, sizeof(line) - 1, c)) { + if ((line[0] == '/') && (strchr(line, ':') != NULL)) { + if (!(col1 = strchr(line, ':')) || (*col1++ = 0) || + !(col2 = strchr(col1, ':')) || (*col2++ = 0) || + !(eol = strchr(col2, '\n')) || (*eol++ = 0)) + continue; + + uh_auth_add(line, col1, col2); + } else if (!strncmp(line, "I:", 2)) { + if (!(col1 = strchr(line, ':')) || (*col1++ = 0) || + !(eol = strchr(col1, '\n')) || (*eol++ = 0)) + continue; + + uh_index_add(strdup(col1)); + } else if (!strncmp(line, "E404:", 5)) { + if (!(col1 = strchr(line, ':')) || (*col1++ = 0) || + !(eol = strchr(col1, '\n')) || (*eol++ = 0)) + continue; + + conf.error_handler = strdup(col1); + } +#ifdef HAVE_CGI + else if ((line[0] == '*') && (strchr(line, ':') != NULL)) { + if (!(col1 = strchr(line, '*')) || (*col1++ = 0) || + !(col2 = strchr(col1, ':')) || (*col2++ = 0) || + !(eol = strchr(col2, '\n')) || (*eol++ = 0)) + continue; + + if (!uh_interpreter_add(col1, col2)) + fprintf(stderr, + "Unable to add interpreter %s for extension %s: " + "Out of memory\n", col2, col1 + ); + } +#endif + } + + fclose(c); +} + static void add_listener_arg(char *arg, bool tls) { char *host = NULL; @@ -102,5 +160,7 @@ int main(int argc, char **argv) } } + uh_config_parse(); + return run_server(); } |