degesch: fix reading in the configuration
This commit is contained in:
parent
06857c6bbb
commit
23298f3a0e
51
degesch.c
51
degesch.c
@ -1935,6 +1935,29 @@ autofill_user_info (struct app_context *ctx, struct error **e)
|
|||||||
return true;
|
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
|
static bool
|
||||||
load_config (struct app_context *ctx, struct error **e)
|
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);
|
str_map_init (&map);
|
||||||
map.free = free;
|
map.free = free;
|
||||||
|
|
||||||
if (!read_config_file (&map, e))
|
bool success = read_config_file (&map, e) &&
|
||||||
return false;
|
unescape_config (&map, &ctx->config, e) &&
|
||||||
|
autofill_user_info (ctx, e);
|
||||||
struct str_map_iter iter;
|
str_map_free (&map);
|
||||||
str_map_iter_init (&iter, &map);
|
if (!success)
|
||||||
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))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!irc_get_boolean_from_config (ctx, "reconnect", &ctx->reconnect, e))
|
if (!irc_get_boolean_from_config (ctx, "reconnect", &ctx->reconnect, e))
|
||||||
|
Loading…
Reference in New Issue
Block a user