Browse Source

Add option to show saved comments in configdump

tags/1.2.0
Vsevolod Stakhov 8 years ago
parent
commit
3d8ee7b019
1 changed files with 23 additions and 4 deletions
  1. 23
    4
      src/rspamadm/configdump.c

+ 23
- 4
src/rspamadm/configdump.c View File

static gboolean json = FALSE; static gboolean json = FALSE;
static gboolean compact = FALSE; static gboolean compact = FALSE;
static gboolean show_help = FALSE; static gboolean show_help = FALSE;
static gboolean show_comments = FALSE;
static gchar *config = NULL; static gchar *config = NULL;
extern struct rspamd_main *rspamd_main; extern struct rspamd_main *rspamd_main;
/* Defined in modules.c */ /* Defined in modules.c */
"Config file to test", NULL}, "Config file to test", NULL},
{"show-help", 'h', 0, G_OPTION_ARG_NONE, &show_help, {"show-help", 'h', 0, G_OPTION_ARG_NONE, &show_help,
"Show help as comments for each option", NULL }, "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} {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
}; };


const ucl_object_t *elt; const ucl_object_t *elt;
ucl_object_t *nobj, *cur_comment; 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) { if (doc_obj != NULL) {
/* Create doc comment */ /* Create doc comment */
nobj = ucl_object_fromstring_common ("/*", 0, 0); nobj = ucl_object_fromstring_common ("/*", 0, 0);
} }


static void 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; rspamd_fstring_t *output;
ucl_object_t *comments = NULL; ucl_object_t *comments = NULL;
output = rspamd_fstring_new (); output = rspamd_fstring_new ();


if (show_help) { 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); rspamadm_gen_comments (obj, doc_obj, comments);
} }
else if (show_comments) {
comments = cfg->config_comments;
}


if (json) { if (json) {
rspamd_ucl_emit_fstring_comments (obj, UCL_EMIT_JSON, &output, comments); rspamd_ucl_emit_fstring_comments (obj, UCL_EMIT_JSON, &output, comments);
if (ret) { if (ret) {
/* Output configuration */ /* Output configuration */
if (argc == 1) { 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 { else {
for (i = 1; i < argc; i ++) { for (i = 1; i < argc; i ++) {
if (!json && !compact) { if (!json && !compact) {
rspamd_printf ("*** Section %s ***\n", argv[i]); 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) { if (!json && !compact) {
rspamd_printf ("*** End of section %s ***\n", argv[i]); rspamd_printf ("*** End of section %s ***\n", argv[i]);

Loading…
Cancel
Save