diff options
Diffstat (limited to 'src/rspamadm/configdump.c')
-rw-r--r-- | src/rspamadm/configdump.c | 503 |
1 files changed, 250 insertions, 253 deletions
diff --git a/src/rspamadm/configdump.c b/src/rspamadm/configdump.c index 7ec009636..23e02db58 100644 --- a/src/rspamadm/configdump.c +++ b/src/rspamadm/configdump.c @@ -36,54 +36,53 @@ extern struct rspamd_main *rspamd_main; extern module_t *modules[]; extern worker_t *workers[]; -static void rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *); -static const char *rspamadm_configdump_help (gboolean full_help, const struct rspamadm_command *); +static void rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *); +static const char *rspamadm_configdump_help(gboolean full_help, const struct rspamadm_command *); struct rspamadm_command configdump_command = { - .name = "configdump", - .flags = 0, - .help = rspamadm_configdump_help, - .run = rspamadm_configdump, - .lua_subrs = NULL, + .name = "configdump", + .flags = 0, + .help = rspamadm_configdump_help, + .run = rspamadm_configdump, + .lua_subrs = NULL, }; static GOptionEntry entries[] = { - {"json", 'j', 0, G_OPTION_ARG_NONE, &json, - "Json output (pretty formatted)", NULL}, - {"compact", 'C', 0, G_OPTION_ARG_NONE, &compact, - "Compacted json output", NULL}, - {"config", 'c', 0, G_OPTION_ARG_STRING, &config, - "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 }, - {"modules-state", 'm', 0, G_OPTION_ARG_NONE, &modules_state, - "Show modules state only", NULL}, - {"groups", 'g', 0, G_OPTION_ARG_NONE, &symbol_groups_only, - "Show symbols groups only", NULL}, - {"symbol-details", 'd', 0, G_OPTION_ARG_NONE, &symbol_full_details, - "Show full symbol details only", NULL}, - {"skip-template", 'T', 0, G_OPTION_ARG_NONE, &skip_template, - "Do not apply Jinja templates", NULL}, - {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} -}; + {"json", 'j', 0, G_OPTION_ARG_NONE, &json, + "Json output (pretty formatted)", NULL}, + {"compact", 'C', 0, G_OPTION_ARG_NONE, &compact, + "Compacted json output", NULL}, + {"config", 'c', 0, G_OPTION_ARG_STRING, &config, + "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}, + {"modules-state", 'm', 0, G_OPTION_ARG_NONE, &modules_state, + "Show modules state only", NULL}, + {"groups", 'g', 0, G_OPTION_ARG_NONE, &symbol_groups_only, + "Show symbols groups only", NULL}, + {"symbol-details", 'd', 0, G_OPTION_ARG_NONE, &symbol_full_details, + "Show full symbol details only", NULL}, + {"skip-template", 'T', 0, G_OPTION_ARG_NONE, &skip_template, + "Do not apply Jinja templates", NULL}, + {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}}; static const char * -rspamadm_configdump_help (gboolean full_help, const struct rspamadm_command *cmd) +rspamadm_configdump_help(gboolean full_help, const struct rspamadm_command *cmd) { const char *help_str; if (full_help) { help_str = "Perform configuration file dump\n\n" - "Usage: rspamadm configdump [-c <config_name> [-j --compact -m] [<path1> [<path2> ...]]]\n" - "Where options are:\n\n" - "-j: output plain json\n" - "--compact: output compacted json\n" - "-c: config file to test\n" - "-m: show state of modules only\n" - "-h: show help for dumped options\n" - "--help: shows available options and commands"; + "Usage: rspamadm configdump [-c <config_name> [-j --compact -m] [<path1> [<path2> ...]]]\n" + "Where options are:\n\n" + "-j: output plain json\n" + "--compact: output compacted json\n" + "-c: config file to test\n" + "-m: show state of modules only\n" + "-h: show help for dumped options\n" + "--help: shows available options and commands"; } else { help_str = "Perform configuration file dump"; @@ -93,74 +92,74 @@ rspamadm_configdump_help (gboolean full_help, const struct rspamadm_command *cmd } static void -config_logger (rspamd_mempool_t *pool, gpointer ud) +config_logger(rspamd_mempool_t *pool, gpointer ud) { } static void -rspamadm_add_doc_elt (const ucl_object_t *obj, const ucl_object_t *doc_obj, - ucl_object_t *comment_obj) +rspamadm_add_doc_elt(const ucl_object_t *obj, const ucl_object_t *doc_obj, + ucl_object_t *comment_obj) { - rspamd_fstring_t *comment = rspamd_fstring_new (); + rspamd_fstring_t *comment = rspamd_fstring_new(); const ucl_object_t *elt; ucl_object_t *nobj, *cur_comment; - if (ucl_object_lookup_len (comment_obj, (const char *)&obj, - sizeof (void *))) { - rspamd_fstring_free (comment); + if (ucl_object_lookup_len(comment_obj, (const char *) &obj, + sizeof(void *))) { + rspamd_fstring_free(comment); /* Do not rewrite the existing comment */ return; } if (doc_obj != NULL) { /* Create doc comment */ - nobj = ucl_object_fromstring_common ("/*", 0, 0); + nobj = ucl_object_fromstring_common("/*", 0, 0); } else { - rspamd_fstring_free (comment); + rspamd_fstring_free(comment); return; } /* We create comments as a list of parts */ - elt = ucl_object_lookup (doc_obj, "data"); + elt = ucl_object_lookup(doc_obj, "data"); if (elt) { - rspamd_printf_fstring (&comment, " * %s", ucl_object_tostring (elt)); - cur_comment = ucl_object_fromstring_common (comment->str, comment->len, 0); - rspamd_fstring_erase (comment, 0, comment->len); - DL_APPEND (nobj, cur_comment); + rspamd_printf_fstring(&comment, " * %s", ucl_object_tostring(elt)); + cur_comment = ucl_object_fromstring_common(comment->str, comment->len, 0); + rspamd_fstring_erase(comment, 0, comment->len); + DL_APPEND(nobj, cur_comment); } - elt = ucl_object_lookup (doc_obj, "type"); + elt = ucl_object_lookup(doc_obj, "type"); if (elt) { - rspamd_printf_fstring (&comment, " * Type: %s", ucl_object_tostring (elt)); - cur_comment = ucl_object_fromstring_common (comment->str, comment->len, 0); - rspamd_fstring_erase (comment, 0, comment->len); - DL_APPEND (nobj, cur_comment); + rspamd_printf_fstring(&comment, " * Type: %s", ucl_object_tostring(elt)); + cur_comment = ucl_object_fromstring_common(comment->str, comment->len, 0); + rspamd_fstring_erase(comment, 0, comment->len); + DL_APPEND(nobj, cur_comment); } - elt = ucl_object_lookup (doc_obj, "required"); + elt = ucl_object_lookup(doc_obj, "required"); if (elt) { - rspamd_printf_fstring (&comment, " * Required: %s", - ucl_object_toboolean (elt) ? "true" : "false"); - cur_comment = ucl_object_fromstring_common (comment->str, comment->len, 0); - rspamd_fstring_erase (comment, 0, comment->len); - DL_APPEND (nobj, cur_comment); + rspamd_printf_fstring(&comment, " * Required: %s", + ucl_object_toboolean(elt) ? "true" : "false"); + cur_comment = ucl_object_fromstring_common(comment->str, comment->len, 0); + rspamd_fstring_erase(comment, 0, comment->len); + DL_APPEND(nobj, cur_comment); } - cur_comment = ucl_object_fromstring (" */"); - DL_APPEND (nobj, cur_comment); - rspamd_fstring_free (comment); + cur_comment = ucl_object_fromstring(" */"); + DL_APPEND(nobj, cur_comment); + rspamd_fstring_free(comment); - ucl_object_insert_key (comment_obj, ucl_object_ref (nobj), - (const char *)&obj, - sizeof (void *), true); + ucl_object_insert_key(comment_obj, ucl_object_ref(nobj), + (const char *) &obj, + sizeof(void *), true); - ucl_object_unref (nobj); + ucl_object_unref(nobj); } static void -rspamadm_gen_comments (const ucl_object_t *obj, const ucl_object_t *doc_obj, - ucl_object_t *comments) +rspamadm_gen_comments(const ucl_object_t *obj, const ucl_object_t *doc_obj, + ucl_object_t *comments) { const ucl_object_t *cur_obj, *cur_doc, *cur_elt; ucl_object_iter_t it = NULL; @@ -170,19 +169,20 @@ rspamadm_gen_comments (const ucl_object_t *obj, const ucl_object_t *doc_obj, } if (obj->keylen > 0) { - rspamadm_add_doc_elt (obj, doc_obj, comments); + rspamadm_add_doc_elt(obj, doc_obj, comments); } - if (ucl_object_type (obj) == UCL_OBJECT) { - while ((cur_obj = ucl_object_iterate (obj, &it, true))) { - cur_doc = ucl_object_lookup_len (doc_obj, cur_obj->key, - cur_obj->keylen); + if (ucl_object_type(obj) == UCL_OBJECT) { + while ((cur_obj = ucl_object_iterate(obj, &it, true))) { + cur_doc = ucl_object_lookup_len(doc_obj, cur_obj->key, + cur_obj->keylen); if (cur_doc != NULL) { - LL_FOREACH (cur_obj, cur_elt) { - if (ucl_object_lookup_len (comments, (const char *)&cur_elt, - sizeof (void *)) == NULL) { - rspamadm_gen_comments (cur_elt, cur_doc, comments); + LL_FOREACH(cur_obj, cur_elt) + { + if (ucl_object_lookup_len(comments, (const char *) &cur_elt, + sizeof(void *)) == NULL) { + rspamadm_gen_comments(cur_elt, cur_doc, comments); } } } @@ -191,51 +191,50 @@ rspamadm_gen_comments (const ucl_object_t *obj, const ucl_object_t *doc_obj, } static void -rspamadm_dump_section_obj (struct rspamd_config *cfg, - 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; - output = rspamd_fstring_new (); + output = rspamd_fstring_new(); if (show_help) { if (show_comments) { comments = cfg->config_comments; } else { - comments = ucl_object_typed_new (UCL_OBJECT); + 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) { - rspamd_ucl_emit_fstring_comments (obj, UCL_EMIT_JSON, &output, comments); + rspamd_ucl_emit_fstring_comments(obj, UCL_EMIT_JSON, &output, comments); } else if (compact) { - rspamd_ucl_emit_fstring_comments (obj, UCL_EMIT_JSON_COMPACT, &output, - comments); + rspamd_ucl_emit_fstring_comments(obj, UCL_EMIT_JSON_COMPACT, &output, + comments); } else { - rspamd_ucl_emit_fstring_comments (obj, UCL_EMIT_CONFIG, &output, - comments); + rspamd_ucl_emit_fstring_comments(obj, UCL_EMIT_CONFIG, &output, + comments); } - rspamd_printf ("%V", output); - rspamd_fstring_free (output); + rspamd_printf("%V", output); + rspamd_fstring_free(output); if (comments != NULL) { - ucl_object_unref (comments); + ucl_object_unref(comments); } } -__attribute__((noreturn)) -static void -rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd) +__attribute__((noreturn)) static void +rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *cmd) { GOptionContext *context; GError *error = NULL; @@ -246,37 +245,35 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd worker_t **pworker; gint i; - context = g_option_context_new ( - "configdump - dumps Rspamd configuration"); - g_option_context_set_summary (context, - "Summary:\n Rspamd administration utility version " - RVERSION - "\n Release id: " - RID); - g_option_context_add_main_entries (context, entries, NULL); - - if (!g_option_context_parse (context, &argc, &argv, &error)) { - fprintf (stderr, "option parsing failed: %s\n", error->message); - g_error_free (error); - g_option_context_free (context); - exit (EXIT_FAILURE); + context = g_option_context_new( + "configdump - dumps Rspamd configuration"); + g_option_context_set_summary(context, + "Summary:\n Rspamd administration utility version " RVERSION + "\n Release id: " RID); + g_option_context_add_main_entries(context, entries, NULL); + + if (!g_option_context_parse(context, &argc, &argv, &error)) { + fprintf(stderr, "option parsing failed: %s\n", error->message); + g_error_free(error); + g_option_context_free(context); + exit(EXIT_FAILURE); } - g_option_context_free (context); + g_option_context_free(context); if (config == NULL) { - if ((confdir = g_hash_table_lookup (ucl_vars, "CONFDIR")) == NULL) { + if ((confdir = g_hash_table_lookup(ucl_vars, "CONFDIR")) == NULL) { confdir = RSPAMD_CONFDIR; } - config = g_strdup_printf ("%s%c%s", confdir, G_DIR_SEPARATOR, - "rspamd.conf"); + config = g_strdup_printf("%s%c%s", confdir, G_DIR_SEPARATOR, + "rspamd.conf"); } pworker = &workers[0]; while (*pworker) { /* Init string quarks */ - (void) g_quark_from_static_string ((*pworker)->name); + (void) g_quark_from_static_string((*pworker)->name); pworker++; } @@ -284,28 +281,28 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd cfg->compiled_workers = workers; cfg->cfg_name = config; - if (!rspamd_config_read (cfg, cfg->cfg_name, config_logger, rspamd_main, - ucl_vars, skip_template, lua_env)) { + if (!rspamd_config_read(cfg, cfg->cfg_name, config_logger, rspamd_main, + ucl_vars, skip_template, lua_env)) { ret = FALSE; } else { /* Do post-load actions */ - rspamd_lua_post_load_config (cfg); + rspamd_lua_post_load_config(cfg); - (void)rspamd_init_filters (rspamd_main->cfg, false, false); - rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE); + (void) rspamd_init_filters(rspamd_main->cfg, false, false); + rspamd_config_post_load(cfg, RSPAMD_CONFIG_INIT_SYMCACHE); } if (ret) { if (modules_state) { - rspamadm_execute_lua_ucl_subr (argc, - argv, - cfg->rcl_obj, - "plugins_stats", - FALSE); + rspamadm_execute_lua_ucl_subr(argc, + argv, + cfg->rcl_obj, + "plugins_stats", + FALSE); - exit (EXIT_SUCCESS); + exit(EXIT_SUCCESS); } if (symbol_full_details) { @@ -313,77 +310,78 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd * Create object from symbols groups and output it using the * specified format */ - ucl_object_t *out = ucl_object_typed_new (UCL_OBJECT); + ucl_object_t *out = ucl_object_typed_new(UCL_OBJECT); GHashTableIter it; gpointer sk, sv; - g_hash_table_iter_init (&it, cfg->symbols); - ucl_object_t *sym_ucl = ucl_object_typed_new (UCL_OBJECT); + g_hash_table_iter_init(&it, cfg->symbols); + ucl_object_t *sym_ucl = ucl_object_typed_new(UCL_OBJECT); const ucl_object_t *all_symbols_ucl = ucl_object_lookup(cfg->rcl_obj, "symbols"); - while (g_hash_table_iter_next (&it, &sk, &sv)) { - const gchar *sym_name = (const gchar *)sk; - struct rspamd_symbol *s = (struct rspamd_symbol *)sv; - ucl_object_t *this_sym_ucl = ucl_object_typed_new (UCL_OBJECT); + while (g_hash_table_iter_next(&it, &sk, &sv)) { + const gchar *sym_name = (const gchar *) sk; + struct rspamd_symbol *s = (struct rspamd_symbol *) sv; + ucl_object_t *this_sym_ucl = ucl_object_typed_new(UCL_OBJECT); - ucl_object_insert_key (this_sym_ucl, - ucl_object_fromdouble (s->score), - "score", strlen ("score"), - false); + ucl_object_insert_key(this_sym_ucl, + ucl_object_fromdouble(s->score), + "score", strlen("score"), + false); - ucl_object_insert_key (this_sym_ucl, - ucl_object_fromstring (s->description), - "description", strlen ("description"), false); + ucl_object_insert_key(this_sym_ucl, + ucl_object_fromstring(s->description), + "description", strlen("description"), false); rspamd_symcache_get_symbol_details(cfg->cache, sym_name, this_sym_ucl); - ucl_object_insert_key (this_sym_ucl, - ucl_object_frombool (!!(s->flags & RSPAMD_SYMBOL_FLAG_DISABLED)), - "disabled", strlen ("disabled"), - false); + ucl_object_insert_key(this_sym_ucl, + ucl_object_frombool(!!(s->flags & RSPAMD_SYMBOL_FLAG_DISABLED)), + "disabled", strlen("disabled"), + false); if (s->nshots == 1) { - ucl_object_insert_key (this_sym_ucl, - ucl_object_frombool (true), - "one_shot", strlen ("one_shot"), - false); + ucl_object_insert_key(this_sym_ucl, + ucl_object_frombool(true), + "one_shot", strlen("one_shot"), + false); } else { - ucl_object_insert_key (this_sym_ucl, - ucl_object_frombool (false), - "one_shot", strlen ("one_shot"), - false); + ucl_object_insert_key(this_sym_ucl, + ucl_object_frombool(false), + "one_shot", strlen("one_shot"), + false); } if (s->gr != NULL) { struct rspamd_symbols_group *gr = s->gr; const char *gr_name = gr->name; if (strcmp(gr_name, "ungrouped") != 0) { - ucl_object_insert_key (this_sym_ucl, - ucl_object_fromstring (gr_name), - "group", strlen("group"), - false); + ucl_object_insert_key(this_sym_ucl, + ucl_object_fromstring(gr_name), + "group", strlen("group"), + false); } if (s->groups) { - ucl_object_t *add_groups = ucl_object_typed_new (UCL_ARRAY); + ucl_object_t *add_groups = ucl_object_typed_new(UCL_ARRAY); guint j; struct rspamd_symbols_group *add_gr; bool has_extra_groups = false; - PTR_ARRAY_FOREACH (s->groups, j, add_gr) { - if (add_gr->name && strcmp (add_gr->name, gr_name) != 0) { - ucl_array_append (add_groups, - ucl_object_fromstring (add_gr->name)); + PTR_ARRAY_FOREACH(s->groups, j, add_gr) + { + if (add_gr->name && strcmp(add_gr->name, gr_name) != 0) { + ucl_array_append(add_groups, + ucl_object_fromstring(add_gr->name)); has_extra_groups = true; } } if (has_extra_groups == true) { - ucl_object_insert_key (this_sym_ucl, - add_groups, - "groups", strlen ("groups"), - false); + ucl_object_insert_key(this_sym_ucl, + add_groups, + "groups", strlen("groups"), + false); } } } @@ -391,11 +389,10 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd const ucl_object_t *loaded_symbol_ucl = ucl_object_lookup(all_symbols_ucl, sym_name); if (loaded_symbol_ucl) { ucl_object_iter_t it = NULL; - while ((cur = ucl_iterate_object (loaded_symbol_ucl, &it, true)) != NULL) - { + while ((cur = ucl_iterate_object(loaded_symbol_ucl, &it, true)) != NULL) { const char *key = ucl_object_key(cur); /* If this key isn't something we have direct in the symbol item, grab the key/value */ - if ((strcmp(key, "score") != 0 ) && + if ((strcmp(key, "score") != 0) && (strcmp(key, "description") != 0) && (strcmp(key, "disabled") != 0) && (strcmp(key, "condition") != 0) && @@ -403,22 +400,20 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd (strcmp(key, "any_shot") != 0) && (strcmp(key, "nshots") != 0) && (strcmp(key, "one_param") != 0) && - (strcmp(key, "priority") != 0)) - { - ucl_object_insert_key(this_sym_ucl, (ucl_object_t *)cur, key, strlen(key), false); + (strcmp(key, "priority") != 0)) { + ucl_object_insert_key(this_sym_ucl, (ucl_object_t *) cur, key, strlen(key), false); } } } - ucl_object_insert_key (sym_ucl, this_sym_ucl, sym_name, - strlen (sym_name), true); - + ucl_object_insert_key(sym_ucl, this_sym_ucl, sym_name, + strlen(sym_name), true); } - ucl_object_insert_key (out, sym_ucl, "symbols", - strlen ("symbols"), true); + ucl_object_insert_key(out, sym_ucl, "symbols", + strlen("symbols"), true); - rspamadm_dump_section_obj (cfg, out, NULL); - exit (EXIT_SUCCESS); + rspamadm_dump_section_obj(cfg, out, NULL); + exit(EXIT_SUCCESS); } if (symbol_groups_only) { @@ -426,127 +421,129 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd * Create object from symbols groups and output it using the * specified format */ - ucl_object_t *out = ucl_object_typed_new (UCL_OBJECT); + ucl_object_t *out = ucl_object_typed_new(UCL_OBJECT); GHashTableIter it; gpointer k, v; - g_hash_table_iter_init (&it, cfg->groups); - - while (g_hash_table_iter_next (&it, &k, &v)) { - const gchar *gr_name = (const gchar *)k; - struct rspamd_symbols_group *gr = (struct rspamd_symbols_group *)v; - ucl_object_t *gr_ucl = ucl_object_typed_new (UCL_OBJECT); - - ucl_object_insert_key (gr_ucl, - ucl_object_frombool (!!(gr->flags & RSPAMD_SYMBOL_GROUP_PUBLIC)), - "public", strlen ("public"), false); - ucl_object_insert_key (gr_ucl, - ucl_object_frombool (!!(gr->flags & RSPAMD_SYMBOL_GROUP_DISABLED)), - "disabled", strlen ("disabled"), false); - ucl_object_insert_key (gr_ucl, - ucl_object_frombool (!!(gr->flags & RSPAMD_SYMBOL_GROUP_ONE_SHOT)), - "one_shot", strlen ("one_shot"), false); - ucl_object_insert_key (gr_ucl, - ucl_object_fromdouble (gr->max_score), - "max_score", strlen ("max_score"), false); - ucl_object_insert_key (gr_ucl, - ucl_object_fromstring (gr->description), - "description", strlen ("description"), false); + g_hash_table_iter_init(&it, cfg->groups); + + while (g_hash_table_iter_next(&it, &k, &v)) { + const gchar *gr_name = (const gchar *) k; + struct rspamd_symbols_group *gr = (struct rspamd_symbols_group *) v; + ucl_object_t *gr_ucl = ucl_object_typed_new(UCL_OBJECT); + + ucl_object_insert_key(gr_ucl, + ucl_object_frombool(!!(gr->flags & RSPAMD_SYMBOL_GROUP_PUBLIC)), + "public", strlen("public"), false); + ucl_object_insert_key(gr_ucl, + ucl_object_frombool(!!(gr->flags & RSPAMD_SYMBOL_GROUP_DISABLED)), + "disabled", strlen("disabled"), false); + ucl_object_insert_key(gr_ucl, + ucl_object_frombool(!!(gr->flags & RSPAMD_SYMBOL_GROUP_ONE_SHOT)), + "one_shot", strlen("one_shot"), false); + ucl_object_insert_key(gr_ucl, + ucl_object_fromdouble(gr->max_score), + "max_score", strlen("max_score"), false); + ucl_object_insert_key(gr_ucl, + ucl_object_fromstring(gr->description), + "description", strlen("description"), false); if (gr->symbols) { GHashTableIter sit; gpointer sk, sv; - g_hash_table_iter_init (&sit, gr->symbols); - ucl_object_t *sym_ucl = ucl_object_typed_new (UCL_OBJECT); + g_hash_table_iter_init(&sit, gr->symbols); + ucl_object_t *sym_ucl = ucl_object_typed_new(UCL_OBJECT); - while (g_hash_table_iter_next (&sit, &sk, &sv)) { + while (g_hash_table_iter_next(&sit, &sk, &sv)) { const gchar *sym_name = (const gchar *) sk; - struct rspamd_symbol *s = (struct rspamd_symbol *)sv; - ucl_object_t *spec_sym = ucl_object_typed_new (UCL_OBJECT); - - ucl_object_insert_key (spec_sym, - ucl_object_fromdouble (s->score), - "score", strlen ("score"), - false); - ucl_object_insert_key (spec_sym, - ucl_object_fromstring (s->description), - "description", strlen ("description"), false); - ucl_object_insert_key (spec_sym, - ucl_object_frombool (!!(s->flags & RSPAMD_SYMBOL_FLAG_DISABLED)), - "disabled", strlen ("disabled"), - false); + struct rspamd_symbol *s = (struct rspamd_symbol *) sv; + ucl_object_t *spec_sym = ucl_object_typed_new(UCL_OBJECT); + + ucl_object_insert_key(spec_sym, + ucl_object_fromdouble(s->score), + "score", strlen("score"), + false); + ucl_object_insert_key(spec_sym, + ucl_object_fromstring(s->description), + "description", strlen("description"), false); + ucl_object_insert_key(spec_sym, + ucl_object_frombool(!!(s->flags & RSPAMD_SYMBOL_FLAG_DISABLED)), + "disabled", strlen("disabled"), + false); if (s->nshots == 1) { - ucl_object_insert_key (spec_sym, - ucl_object_frombool (true), - "one_shot", strlen ("one_shot"), - false); + ucl_object_insert_key(spec_sym, + ucl_object_frombool(true), + "one_shot", strlen("one_shot"), + false); } else { - ucl_object_insert_key (spec_sym, - ucl_object_frombool (false), - "one_shot", strlen ("one_shot"), - false); + ucl_object_insert_key(spec_sym, + ucl_object_frombool(false), + "one_shot", strlen("one_shot"), + false); } - ucl_object_t *add_groups = ucl_object_typed_new (UCL_ARRAY); + ucl_object_t *add_groups = ucl_object_typed_new(UCL_ARRAY); guint j; struct rspamd_symbols_group *add_gr; - PTR_ARRAY_FOREACH (s->groups, j, add_gr) { - if (add_gr->name && strcmp (add_gr->name, gr_name) != 0) { - ucl_array_append (add_groups, - ucl_object_fromstring (add_gr->name)); + PTR_ARRAY_FOREACH(s->groups, j, add_gr) + { + if (add_gr->name && strcmp(add_gr->name, gr_name) != 0) { + ucl_array_append(add_groups, + ucl_object_fromstring(add_gr->name)); } } - ucl_object_insert_key (spec_sym, - add_groups, - "extra_groups", strlen ("extra_groups"), - false); + ucl_object_insert_key(spec_sym, + add_groups, + "extra_groups", strlen("extra_groups"), + false); - ucl_object_insert_key (sym_ucl, spec_sym, sym_name, - strlen (sym_name), true); + ucl_object_insert_key(sym_ucl, spec_sym, sym_name, + strlen(sym_name), true); } - ucl_object_insert_key (gr_ucl, sym_ucl, "symbols", - strlen ("symbols"), false); + ucl_object_insert_key(gr_ucl, sym_ucl, "symbols", + strlen("symbols"), false); } - ucl_object_insert_key (out, gr_ucl, gr_name, strlen (gr_name), - true); + ucl_object_insert_key(out, gr_ucl, gr_name, strlen(gr_name), + true); } - rspamadm_dump_section_obj (cfg, out, NULL); + rspamadm_dump_section_obj(cfg, out, NULL); - exit (EXIT_SUCCESS); + exit(EXIT_SUCCESS); } /* Output configuration */ if (argc == 1) { - rspamadm_dump_section_obj (cfg, cfg->rcl_obj, cfg->doc_strings); + rspamadm_dump_section_obj(cfg, cfg->rcl_obj, cfg->doc_strings); } else { - for (i = 1; i < argc; i ++) { - obj = ucl_object_lookup_path (cfg->rcl_obj, argv[i]); - doc_obj = ucl_object_lookup_path (cfg->doc_strings, argv[i]); + for (i = 1; i < argc; i++) { + obj = ucl_object_lookup_path(cfg->rcl_obj, argv[i]); + doc_obj = ucl_object_lookup_path(cfg->doc_strings, argv[i]); if (!obj) { - rspamd_printf ("Section %s NOT FOUND\n", argv[i]); + rspamd_printf("Section %s NOT FOUND\n", argv[i]); } else { - LL_FOREACH (obj, cur) { + LL_FOREACH(obj, cur) + { if (!json && !compact) { - rspamd_printf ("*** Section %s ***\n", argv[i]); + rspamd_printf("*** Section %s ***\n", argv[i]); } - rspamadm_dump_section_obj (cfg, cur, doc_obj); + rspamadm_dump_section_obj(cfg, cur, doc_obj); if (!json && !compact) { - rspamd_printf ("\n*** End of section %s ***\n", argv[i]); + rspamd_printf("\n*** End of section %s ***\n", argv[i]); } else { - rspamd_printf ("\n"); + rspamd_printf("\n"); } } } @@ -554,5 +551,5 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd } } - exit (ret ? EXIT_SUCCESS : EXIT_FAILURE); + exit(ret ? EXIT_SUCCESS : EXIT_FAILURE); } |