From 23298f3a0e2426b758de3ad472abc8487ccb37f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C5=99emysl=20Janouch?=
Date: Wed, 15 Apr 2015 15:49:33 +0200
Subject: [PATCH] degesch: fix reading in the configuration
---
degesch.c | 51 ++++++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/degesch.c b/degesch.c
index 3733339..358e592 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1935,6 +1935,29 @@ autofill_user_info (struct app_context *ctx, struct error **e)
return true;
}
+static bool
+unescape_config (struct str_map *input, struct str_map *output, struct error **e)
+{
+ struct error *error = NULL;
+ struct str_map_iter iter;
+ str_map_iter_init (&iter, input);
+ while (str_map_iter_next (&iter))
+ {
+ struct str value;
+ str_init (&value);
+ if (!unescape_string (iter.link->data, &value, &error))
+ {
+ error_set (e, "error reading configuration: %s: %s",
+ iter.link->key, error->message);
+ error_free (error);
+ return false;
+ }
+
+ str_map_set (output, iter.link->key, str_steal (&value));
+ }
+ return true;
+}
+
static bool
load_config (struct app_context *ctx, struct error **e)
{
@@ -1945,29 +1968,11 @@ load_config (struct app_context *ctx, struct error **e)
str_map_init (&map);
map.free = free;
- if (!read_config_file (&map, e))
- return false;
-
- struct str_map_iter iter;
- str_map_iter_init (&iter, &map);
- while (str_map_iter_next (&iter))
- {
- struct error *e = NULL;
- struct str value;
- str_init (&value);
- if (!unescape_string (iter.link->data, &value, &e))
- {
- // FIXME: use the "e" argument, don't print it
- print_error ("error reading configuration: %s: %s",
- iter.link->key, e->message);
- error_free (e);
- exit (EXIT_FAILURE);
- }
-
- str_map_set (&ctx->config, iter.link->key, str_steal (&value));
- }
-
- if (!autofill_user_info (ctx, e))
+ bool success = read_config_file (&map, e) &&
+ unescape_config (&map, &ctx->config, e) &&
+ autofill_user_info (ctx, e);
+ str_map_free (&map);
+ if (!success)
return false;
if (!irc_get_boolean_from_config (ctx, "reconnect", &ctx->reconnect, e))