aboutsummaryrefslogtreecommitdiffstats
path: root/src/rspamadm/stat_convert.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-07-26 10:49:23 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-07-26 10:49:23 +0100
commit537a7180a0d5132c11636c4fd8b1450cd99d352c (patch)
treefb9f8c84955a411bdffbd6371ea32f2716fb3687 /src/rspamadm/stat_convert.c
parent5fd7a90fdaa33f52c59bdb0ca84451e5c1e22365 (diff)
downloadrspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.tar.gz
rspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.zip
[Rework] Use clang-format to unify formatting in all sources
No meaningful changes.
Diffstat (limited to 'src/rspamadm/stat_convert.c')
-rw-r--r--src/rspamadm/stat_convert.c266
1 files changed, 131 insertions, 135 deletions
diff --git a/src/rspamadm/stat_convert.c b/src/rspamadm/stat_convert.c
index 38ce30a4d..ba2c4efb9 100644
--- a/src/rspamadm/stat_convert.c
+++ b/src/rspamadm/stat_convert.c
@@ -37,69 +37,67 @@ static gchar *redis_db = NULL;
static gchar *redis_password = NULL;
static gboolean reset_previous = FALSE;
-static void rspamadm_statconvert (gint argc, gchar **argv,
- const struct rspamadm_command *cmd);
-static const char *rspamadm_statconvert_help (gboolean full_help,
- const struct rspamadm_command *cmd);
+static void rspamadm_statconvert(gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_statconvert_help(gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command statconvert_command = {
- .name = "statconvert",
- .flags = 0,
- .help = rspamadm_statconvert_help,
- .run = rspamadm_statconvert,
- .lua_subrs = NULL,
+ .name = "statconvert",
+ .flags = 0,
+ .help = rspamadm_statconvert_help,
+ .run = rspamadm_statconvert,
+ .lua_subrs = NULL,
};
static GOptionEntry entries[] = {
- {"config", 'c', 0, G_OPTION_ARG_FILENAME, &config_file,
- "Config file to read data from", NULL},
- {"reset", 'r', 0, G_OPTION_ARG_NONE, &reset_previous,
- "Reset previous data instead of appending values", NULL},
- {"expire", 'e', 0, G_OPTION_ARG_DOUBLE, &expire,
- "Set expiration in seconds (can be fractional)", NULL},
-
- {"symbol-spam", 0, 0, G_OPTION_ARG_STRING, &symbol_spam,
- "Symbol for spam (e.g. BAYES_SPAM)", NULL},
- {"symbol-ham", 0, 0, G_OPTION_ARG_STRING, &symbol_ham,
- "Symbol for ham (e.g. BAYES_HAM)", NULL},
- {"spam-db", 0, 0, G_OPTION_ARG_STRING, &spam_db,
- "Input spam file (sqlite3)", NULL},
- {"ham-db", 0, 0, G_OPTION_ARG_STRING, &ham_db,
- "Input ham file (sqlite3)", NULL},
- {"cache", 0, 0, G_OPTION_ARG_FILENAME, &cache_db,
- "Input learn cache", NULL},
- {"redis-host", 'h', 0, G_OPTION_ARG_STRING, &redis_host,
- "Output redis ip (in format ip:port)", NULL},
- {"redis-password", 'p', 0, G_OPTION_ARG_STRING, &redis_password,
- "Password to connect to redis", NULL},
- {"redis-db", 'd', 0, G_OPTION_ARG_STRING, &redis_db,
- "Redis database (should be numeric)", NULL},
- {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
-};
+ {"config", 'c', 0, G_OPTION_ARG_FILENAME, &config_file,
+ "Config file to read data from", NULL},
+ {"reset", 'r', 0, G_OPTION_ARG_NONE, &reset_previous,
+ "Reset previous data instead of appending values", NULL},
+ {"expire", 'e', 0, G_OPTION_ARG_DOUBLE, &expire,
+ "Set expiration in seconds (can be fractional)", NULL},
+
+ {"symbol-spam", 0, 0, G_OPTION_ARG_STRING, &symbol_spam,
+ "Symbol for spam (e.g. BAYES_SPAM)", NULL},
+ {"symbol-ham", 0, 0, G_OPTION_ARG_STRING, &symbol_ham,
+ "Symbol for ham (e.g. BAYES_HAM)", NULL},
+ {"spam-db", 0, 0, G_OPTION_ARG_STRING, &spam_db,
+ "Input spam file (sqlite3)", NULL},
+ {"ham-db", 0, 0, G_OPTION_ARG_STRING, &ham_db,
+ "Input ham file (sqlite3)", NULL},
+ {"cache", 0, 0, G_OPTION_ARG_FILENAME, &cache_db,
+ "Input learn cache", NULL},
+ {"redis-host", 'h', 0, G_OPTION_ARG_STRING, &redis_host,
+ "Output redis ip (in format ip:port)", NULL},
+ {"redis-password", 'p', 0, G_OPTION_ARG_STRING, &redis_password,
+ "Password to connect to redis", NULL},
+ {"redis-db", 'd', 0, G_OPTION_ARG_STRING, &redis_db,
+ "Redis database (should be numeric)", NULL},
+ {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
static const char *
-rspamadm_statconvert_help (gboolean full_help, const struct rspamadm_command *cmd)
+rspamadm_statconvert_help(gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
if (full_help) {
help_str = "Convert statistics from sqlite3 to redis\n\n"
- "Usage: rspamadm statconvert -c /etc/rspamd.conf [-r]\n"
- "Where options are:\n\n"
- "-c: config file to read data from\n"
- "-r: reset previous data instead of increasing values\n"
- "-e: set expire to that amount of seconds\n"
- "** Or specify options directly **\n"
- "--redis-host: output redis ip (in format ip:port)\n"
- "--redis-db: output redis database\n"
- "--redis-password: redis password\n"
- "--cache: sqlite3 file for learn cache\n"
- "--spam-db: sqlite3 input file for spam data\n"
- "--ham-db: sqlite3 input file for ham data\n"
- "--symbol-spam: symbol in redis for spam (e.g. BAYES_SPAM)\n"
- "--symbol-ham: symbol in redis for ham (e.g. BAYES_HAM)\n"
- ;
+ "Usage: rspamadm statconvert -c /etc/rspamd.conf [-r]\n"
+ "Where options are:\n\n"
+ "-c: config file to read data from\n"
+ "-r: reset previous data instead of increasing values\n"
+ "-e: set expire to that amount of seconds\n"
+ "** Or specify options directly **\n"
+ "--redis-host: output redis ip (in format ip:port)\n"
+ "--redis-db: output redis database\n"
+ "--redis-password: redis password\n"
+ "--cache: sqlite3 file for learn cache\n"
+ "--spam-db: sqlite3 input file for spam data\n"
+ "--ham-db: sqlite3 input file for ham data\n"
+ "--symbol-spam: symbol in redis for spam (e.g. BAYES_SPAM)\n"
+ "--symbol-ham: symbol in redis for ham (e.g. BAYES_HAM)\n";
}
else {
help_str = "Convert statistics from sqlite3 to redis";
@@ -109,47 +107,45 @@ rspamadm_statconvert_help (gboolean full_help, const struct rspamadm_command *cm
}
static void
-rspamadm_statconvert (gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_statconvert(gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
ucl_object_t *obj;
- context = g_option_context_new (
- "statconvert - converts statistics from sqlite3 to redis");
- 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);
- g_option_context_set_ignore_unknown_options (context, TRUE);
-
- if (!g_option_context_parse (context, &argc, &argv, &error)) {
- rspamd_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(
+ "statconvert - converts statistics from sqlite3 to redis");
+ 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);
+ g_option_context_set_ignore_unknown_options(context, TRUE);
+
+ if (!g_option_context_parse(context, &argc, &argv, &error)) {
+ rspamd_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_file) {
/* Load config file, assuming that it has all information required */
struct ucl_parser *parser;
- parser = ucl_parser_new (0);
- rspamd_ucl_add_conf_variables (parser, ucl_vars);
+ parser = ucl_parser_new(0);
+ rspamd_ucl_add_conf_variables(parser, ucl_vars);
- if (!ucl_parser_add_file (parser, config_file)) {
- msg_err ("ucl parser error: %s", ucl_parser_get_error (parser));
- ucl_parser_free (parser);
+ if (!ucl_parser_add_file(parser, config_file)) {
+ msg_err("ucl parser error: %s", ucl_parser_get_error(parser));
+ ucl_parser_free(parser);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
- obj = ucl_parser_get_object (parser);
- ucl_parser_free (parser);
+ obj = ucl_parser_get_object(parser);
+ ucl_parser_free(parser);
}
else {
/* We need to get all information from the command line */
@@ -157,101 +153,101 @@ rspamadm_statconvert (gint argc, gchar **argv, const struct rspamadm_command *cm
/* Check arguments sanity */
if (spam_db == NULL) {
- msg_err ("No spam-db specified");
- exit (EXIT_FAILURE);
+ msg_err("No spam-db specified");
+ exit(EXIT_FAILURE);
}
if (ham_db == NULL) {
- msg_err ("No ham-db specified");
- exit (EXIT_FAILURE);
+ msg_err("No ham-db specified");
+ exit(EXIT_FAILURE);
}
if (redis_host == NULL) {
- msg_err ("No redis-host specified");
- exit (EXIT_FAILURE);
+ msg_err("No redis-host specified");
+ exit(EXIT_FAILURE);
}
if (symbol_ham == NULL) {
- msg_err ("No symbol-ham specified");
- exit (EXIT_FAILURE);
+ msg_err("No symbol-ham specified");
+ exit(EXIT_FAILURE);
}
if (symbol_spam == NULL) {
- msg_err ("No symbol-spam specified");
- exit (EXIT_FAILURE);
+ msg_err("No symbol-spam specified");
+ exit(EXIT_FAILURE);
}
- obj = ucl_object_typed_new (UCL_OBJECT);
+ obj = ucl_object_typed_new(UCL_OBJECT);
- classifier = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (obj, classifier, "classifier", 0, false);
+ classifier = ucl_object_typed_new(UCL_OBJECT);
+ ucl_object_insert_key(obj, classifier, "classifier", 0, false);
/* Now we need to create "bayes" key in it */
- tmp = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (classifier, tmp, "bayes", 0, false);
+ tmp = ucl_object_typed_new(UCL_OBJECT);
+ ucl_object_insert_key(classifier, tmp, "bayes", 0, false);
classifier = tmp;
- ucl_object_insert_key (classifier, ucl_object_fromstring ("sqlite3"),
- "backend", 0, false);
+ ucl_object_insert_key(classifier, ucl_object_fromstring("sqlite3"),
+ "backend", 0, false);
if (cache_db != NULL) {
ucl_object_t *cache;
- cache = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (cache, ucl_object_fromstring ("sqlite3"),
- "type", 0, false);
- ucl_object_insert_key (cache, ucl_object_fromstring (cache_db),
- "file", 0, false);
+ cache = ucl_object_typed_new(UCL_OBJECT);
+ ucl_object_insert_key(cache, ucl_object_fromstring("sqlite3"),
+ "type", 0, false);
+ ucl_object_insert_key(cache, ucl_object_fromstring(cache_db),
+ "file", 0, false);
- ucl_object_insert_key (classifier, cache, "cache", 0, false);
+ ucl_object_insert_key(classifier, cache, "cache", 0, false);
}
- statfile_ham = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (statfile_ham, ucl_object_fromstring (symbol_ham),
- "symbol", 0, false);
- ucl_object_insert_key (statfile_ham, ucl_object_frombool (false),
- "spam", 0, false);
- ucl_object_insert_key (statfile_ham, ucl_object_fromstring (ham_db),
- "db", 0, false);
-
- statfile_spam = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (statfile_spam, ucl_object_fromstring (symbol_spam),
- "symbol", 0, false);
- ucl_object_insert_key (statfile_spam, ucl_object_frombool (true),
- "spam", 0, false);
- ucl_object_insert_key (statfile_spam, ucl_object_fromstring (spam_db),
- "db", 0, false);
-
- DL_APPEND (statfile_ham, statfile_spam);
- ucl_object_insert_key (classifier, statfile_ham,
- "statfile", 0, false);
+ statfile_ham = ucl_object_typed_new(UCL_OBJECT);
+ ucl_object_insert_key(statfile_ham, ucl_object_fromstring(symbol_ham),
+ "symbol", 0, false);
+ ucl_object_insert_key(statfile_ham, ucl_object_frombool(false),
+ "spam", 0, false);
+ ucl_object_insert_key(statfile_ham, ucl_object_fromstring(ham_db),
+ "db", 0, false);
+
+ statfile_spam = ucl_object_typed_new(UCL_OBJECT);
+ ucl_object_insert_key(statfile_spam, ucl_object_fromstring(symbol_spam),
+ "symbol", 0, false);
+ ucl_object_insert_key(statfile_spam, ucl_object_frombool(true),
+ "spam", 0, false);
+ ucl_object_insert_key(statfile_spam, ucl_object_fromstring(spam_db),
+ "db", 0, false);
+
+ DL_APPEND(statfile_ham, statfile_spam);
+ ucl_object_insert_key(classifier, statfile_ham,
+ "statfile", 0, false);
/* Deal with redis */
- redis = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (obj, redis, "redis", 0, false);
+ redis = ucl_object_typed_new(UCL_OBJECT);
+ ucl_object_insert_key(obj, redis, "redis", 0, false);
- ucl_object_insert_key (redis, ucl_object_fromstring (redis_host),
- "servers", 0, false);
+ ucl_object_insert_key(redis, ucl_object_fromstring(redis_host),
+ "servers", 0, false);
if (redis_db) {
- ucl_object_insert_key (redis, ucl_object_fromstring (redis_db),
- "dbname", 0, false);
+ ucl_object_insert_key(redis, ucl_object_fromstring(redis_db),
+ "dbname", 0, false);
}
if (redis_password) {
- ucl_object_insert_key (redis, ucl_object_fromstring (redis_password),
- "password", 0, false);
+ ucl_object_insert_key(redis, ucl_object_fromstring(redis_password),
+ "password", 0, false);
}
}
- ucl_object_insert_key (obj, ucl_object_frombool (reset_previous),
- "reset_previous", 0, false);
+ ucl_object_insert_key(obj, ucl_object_frombool(reset_previous),
+ "reset_previous", 0, false);
if (expire != 0) {
- ucl_object_insert_key (obj, ucl_object_fromdouble (expire),
- "expire", 0, false);
+ ucl_object_insert_key(obj, ucl_object_fromdouble(expire),
+ "expire", 0, false);
}
- rspamadm_execute_lua_ucl_subr (argc,
- argv,
- obj,
- "stat_convert",
- TRUE);
+ rspamadm_execute_lua_ucl_subr(argc,
+ argv,
+ obj,
+ "stat_convert",
+ TRUE);
- ucl_object_unref (obj);
+ ucl_object_unref(obj);
}