diff options
-rw-r--r-- | config.c | 29 |
1 files changed, 11 insertions, 18 deletions
@@ -20,9 +20,11 @@ void cleanup_config(config *conf) { } int check_port(void *ctx, void *ret, const keyword *key, keyword_val val) { + int *error = (int *)ctx; if (key->type == TYPE_STRING) { int port = strtol(val.str, NULL, 0); if (port > 0 || port <= 65535) { + *error = 0; return 0; } else { log(LOG_ERR, "Invalid port %d. (Valid port must be between 1, and 65535.)", port); @@ -30,10 +32,13 @@ int check_port(void *ctx, void *ret, const keyword *key, keyword_val val) { } else { log(LOG_ERR, "Keyword \"%s\" doesn't return a string.", key->key); } + *error = 1; return -1; } config *parse_config(const char *filename) { + int error = 0; + int type_error = 0; /* Size of the file, in bytes. */ long filesize = 0; /* Config settings. */ @@ -55,25 +60,13 @@ config *parse_config(const char *filename) { return NULL; } - while (*tmp != '\0') { - char *line = get_line(&tmp); - char *value; - char *name = strtok_r(line, "=", &value); - int error; - - /* Did we fail to parse the config option? */ - if (error = parse_keywords(config_keywords, name, value, cfg, NULL)) { - if (error == 5) { - cleanup_config(cfg); - free(line); - free(buf); - return NULL; - } else { - log(LOG_WARNING, "Failed to parse config option \"%s\". Error code: %i", name, error); - } + /* Did we fail to parse the config file? */ + if (error = parse_key_value_file(cfg, &type_error, config_keywords, buf, "=", NULL)) { + if (type_error || (error >= 3 && error != 6)) { + cleanup_config(cfg); + free(buf); + return NULL; } - - free(line); } free(buf); |