From 3a790729df214dfb00d0d92f813819b23edb23fb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 21 Nov 2013 16:20:06 +0000 Subject: [PATCH] Allow dump of invalid xml to ucl format. --- src/cfg_utils.c | 29 +++++++++++++++++++---------- src/main.c | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/cfg_utils.c b/src/cfg_utils.c index 80faadbf3..1faaf08a7 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -774,10 +774,15 @@ read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar } close (fd); - ext = get_filename_extension (filename); - if (ext != NULL && strcmp (ext, "xml") == 0) { + if (convert_to != NULL) { is_xml = TRUE; } + else { + ext = get_filename_extension (filename); + if (ext != NULL && strcmp (ext, "xml") == 0) { + is_xml = TRUE; + } + } if (is_xml) { /* Prepare xml parser */ @@ -805,14 +810,6 @@ read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar return FALSE; } - top = rspamd_rcl_config_init (); - err = NULL; - - if (!rspamd_read_rcl_config (top, cfg, cfg->rcl_obj, &err)) { - msg_err ("rcl parse error: %s", err->message); - return FALSE; - } - if (is_xml && convert_to != NULL) { /* Convert XML config to UCL */ rcl = ucl_object_emit (cfg->rcl_obj, UCL_EMIT_CONFIG); @@ -824,11 +821,23 @@ read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar else if (write (fd, rcl, strlen (rcl)) == -1) { msg_err ("cannot write rcl %s: %s", convert_to, strerror (errno)); } + else { + msg_info ("dumped xml configuration %s to ucl configuration %s", + filename, convert_to); + } close (fd); free (rcl); } } + top = rspamd_rcl_config_init (); + err = NULL; + + if (!rspamd_read_rcl_config (top, cfg, cfg->rcl_obj, &err)) { + msg_err ("rcl parse error: %s", err->message); + return FALSE; + } + return TRUE; } diff --git a/src/main.c b/src/main.c index b96d37309..66eb5b6c7 100644 --- a/src/main.c +++ b/src/main.c @@ -1038,7 +1038,7 @@ main (gint argc, gchar **argv, gchar **env) rspamd_main->cfg->log_level = G_LOG_LEVEL_DEBUG; } else { - rspamd_main->cfg->log_level = G_LOG_LEVEL_CRITICAL; + rspamd_main->cfg->log_level = G_LOG_LEVEL_INFO; } type = g_quark_from_static_string ("main"); -- 2.39.5