]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add option to show saved comments in configdump
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 17 Feb 2016 13:36:13 +0000 (13:36 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 17 Feb 2016 14:57:16 +0000 (14:57 +0000)
src/rspamadm/configdump.c

index c246509e3f8c03dc8f4f1bf9b73bc3b1a20410f3..b48009466d9134a0433870d54de3392d854dbf8e 100644 (file)
@@ -25,6 +25,7 @@
 static gboolean json = FALSE;
 static gboolean compact = FALSE;
 static gboolean show_help = FALSE;
+static gboolean show_comments = FALSE;
 static gchar *config = NULL;
 extern struct rspamd_main *rspamd_main;
 /* Defined in modules.c */
@@ -50,6 +51,8 @@ static GOptionEntry entries[] = {
                                "Config file to test",     NULL},
                {"show-help", 'h', 0, G_OPTION_ARG_NONE, &show_help,
                                "Show help as comments for each option", NULL },
+               {"show-comments", 's', 0, G_OPTION_ARG_NONE, &show_comments,
+                               "Show saved comments from the configuration file", NULL },
                {NULL,  0,   0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
 };
 
@@ -99,6 +102,12 @@ rspamadm_add_doc_elt (const ucl_object_t *obj, const ucl_object_t *doc_obj,
        const ucl_object_t *elt;
        ucl_object_t *nobj, *cur_comment;
 
+       if (ucl_object_lookup_len (comment_obj, (const char *)&obj,
+                       sizeof (void *))) {
+               /* Do not rewrite the existing comment */
+               return;
+       }
+
        if (doc_obj != NULL) {
                /* Create doc comment */
                nobj = ucl_object_fromstring_common ("/*", 0, 0);
@@ -178,7 +187,8 @@ rspamadm_gen_comments (const ucl_object_t *obj, const ucl_object_t *doc_obj,
 }
 
 static void
-rspamadm_dump_section_obj (const ucl_object_t *obj, const ucl_object_t *doc_obj)
+rspamadm_dump_section_obj (struct rspamd_config *cfg,
+               const ucl_object_t *obj, const ucl_object_t *doc_obj)
 {
        rspamd_fstring_t *output;
        ucl_object_t *comments = NULL;
@@ -186,9 +196,18 @@ rspamadm_dump_section_obj (const ucl_object_t *obj, const ucl_object_t *doc_obj)
        output = rspamd_fstring_new ();
 
        if (show_help) {
-               comments = ucl_object_typed_new (UCL_OBJECT);
+               if (show_comments) {
+                       comments = cfg->config_comments;
+               }
+               else {
+                       comments = ucl_object_typed_new (UCL_OBJECT);
+               }
+
                rspamadm_gen_comments (obj, doc_obj, comments);
        }
+       else if (show_comments) {
+               comments = cfg->config_comments;
+       }
 
        if (json) {
                rspamd_ucl_emit_fstring_comments (obj, UCL_EMIT_JSON, &output, comments);
@@ -277,7 +296,7 @@ rspamadm_configdump (gint argc, gchar **argv)
        if (ret) {
                /* Output configuration */
                if (argc == 1) {
-                       rspamadm_dump_section_obj (cfg->rcl_obj, cfg->doc_strings);
+                       rspamadm_dump_section_obj (cfg, cfg->rcl_obj, cfg->doc_strings);
                }
                else {
                        for (i = 1; i < argc; i ++) {
@@ -292,7 +311,7 @@ rspamadm_configdump (gint argc, gchar **argv)
                                                if (!json && !compact) {
                                                        rspamd_printf ("*** Section %s ***\n",  argv[i]);
                                                }
-                                               rspamadm_dump_section_obj (cur, doc_obj);
+                                               rspamadm_dump_section_obj (cfg, cur, doc_obj);
 
                                                if (!json && !compact) {
                                                        rspamd_printf ("*** End of section %s ***\n",  argv[i]);