From b2b7fe083115822966eed20b28a07b2fb9de84dd Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 3 Jul 2011 10:36:08 +0200 Subject: Handle all libconfuse parse errors. --- lib/conf.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'lib/conf.c') diff --git a/lib/conf.c b/lib/conf.c index e3d5522..9b8e77c 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -37,10 +37,12 @@ } #endif +/* FIXME: Leaking memory in error cases? */ int rs_context_read_config(struct rs_context *ctx, const char *config_file) { cfg_t *cfg, *cfg_realm, *cfg_server; + int err = 0; int i, j; const char *s; struct rs_config *config = NULL; @@ -74,9 +76,22 @@ rs_context_read_config(struct rs_context *ctx, const char *config_file) cfg = cfg_init (opts, CFGF_NONE); if (cfg == NULL) return rs_err_ctx_push (ctx, RSE_CONFIG, "unable to initialize libconfuse"); - if (cfg_parse (cfg, config_file) == CFG_PARSE_ERROR) - return rs_err_ctx_push (ctx, RSE_CONFIG, "%s: invalid configuration file", - config_file); + err = cfg_parse (cfg, config_file); + switch (err) + { + case CFG_SUCCESS: + break; + case CFG_FILE_ERROR: + return rs_err_ctx_push (ctx, RSE_CONFIG, + "%s: unable to open configuration file", + config_file); + case CFG_PARSE_ERROR: + return rs_err_ctx_push (ctx, RSE_CONFIG, "%s: invalid configuration file", + config_file); + default: + return rs_err_ctx_push (ctx, RSE_CONFIG, "%s: unknown parse error", + config_file); + } config = rs_calloc (ctx, 1, sizeof (*config)); if (config == NULL) -- cgit v1.1