aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/roll_history.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-07-23 12:45:28 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-07-23 12:45:28 +0100
commite0483657ff6cf1adc828ccce457814d61fe90a0d (patch)
tree5183e4163f40b81b3e7d5f51488d360883782154 /src/libserver/roll_history.c
parent7962087e808fb824aa3af6d41d02abc92916ba1e (diff)
downloadrspamd-e0483657ff6cf1adc828ccce457814d61fe90a0d.tar.gz
rspamd-e0483657ff6cf1adc828ccce457814d61fe90a0d.zip
Unify code style.
Diffstat (limited to 'src/libserver/roll_history.c')
-rw-r--r--src/libserver/roll_history.c53
1 files changed, 31 insertions, 22 deletions
diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c
index 504f8ae3b..d9553fa93 100644
--- a/src/libserver/roll_history.c
+++ b/src/libserver/roll_history.c
@@ -33,10 +33,10 @@
* @param pool pool for shared memory
* @return new structure
*/
-struct roll_history*
+struct roll_history *
rspamd_roll_history_new (rspamd_mempool_t *pool)
{
- struct roll_history *new;
+ struct roll_history *new;
if (pool == NULL) {
return NULL;
@@ -57,9 +57,9 @@ struct history_metric_callback_data {
static void
roll_history_symbols_callback (gpointer key, gpointer value, void *user_data)
{
- struct history_metric_callback_data *cb = user_data;
- struct symbol *s = value;
- guint wr;
+ struct history_metric_callback_data *cb = user_data;
+ struct symbol *s = value;
+ guint wr;
if (cb->remain > 0) {
wr = rspamd_snprintf (cb->pos, cb->remain, "%s, ", s->name);
@@ -74,12 +74,13 @@ roll_history_symbols_callback (gpointer key, gpointer value, void *user_data)
* @param task task object
*/
void
-rspamd_roll_history_update (struct roll_history *history, struct rspamd_task *task)
+rspamd_roll_history_update (struct roll_history *history,
+ struct rspamd_task *task)
{
- gint row_num;
- struct roll_history_row *row;
- struct metric_result *metric_res;
- struct history_metric_callback_data cbdata;
+ gint row_num;
+ struct roll_history_row *row;
+ struct metric_result *metric_res;
+ struct history_metric_callback_data cbdata;
if (history->need_lock) {
/* Some process is getting history, so wait on a mutex */
@@ -108,10 +109,11 @@ rspamd_roll_history_update (struct roll_history *history, struct rspamd_task *ta
/* Add information from task to roll history */
memcpy (&row->from_addr, &task->from_addr, sizeof (row->from_addr));
- memcpy (&row->tv, &task->tv, sizeof (row->tv));
+ memcpy (&row->tv, &task->tv, sizeof (row->tv));
/* Strings */
- rspamd_strlcpy (row->message_id, task->message_id, sizeof (row->message_id));
+ rspamd_strlcpy (row->message_id, task->message_id,
+ sizeof (row->message_id));
if (task->user) {
rspamd_strlcpy (row->user, task->user, sizeof (row->message_id));
}
@@ -120,19 +122,23 @@ rspamd_roll_history_update (struct roll_history *history, struct rspamd_task *ta
}
/* Get default metric */
- metric_res = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+ metric_res = g_hash_table_lookup (task->results, DEFAULT_METRIC);
if (metric_res == NULL) {
row->symbols[0] = '\0';
row->action = METRIC_ACTION_NOACTION;
}
else {
row->score = metric_res->score;
- row->required_score = metric_res->metric->actions[METRIC_ACTION_REJECT].score;
+ row->required_score =
+ metric_res->metric->actions[METRIC_ACTION_REJECT].score;
row->action = check_metric_action (metric_res->score,
- metric_res->metric->actions[METRIC_ACTION_REJECT].score, metric_res->metric);
+ metric_res->metric->actions[METRIC_ACTION_REJECT].score,
+ metric_res->metric);
cbdata.pos = row->symbols;
cbdata.remain = sizeof (row->symbols);
- g_hash_table_foreach (metric_res->symbols, roll_history_symbols_callback, &cbdata);
+ g_hash_table_foreach (metric_res->symbols,
+ roll_history_symbols_callback,
+ &cbdata);
if (cbdata.remain > 0) {
/* Remove last whitespace and comma */
*cbdata.pos-- = '\0';
@@ -155,11 +161,12 @@ rspamd_roll_history_update (struct roll_history *history, struct rspamd_task *ta
gboolean
rspamd_roll_history_load (struct roll_history *history, const gchar *filename)
{
- gint fd;
- struct stat st;
+ gint fd;
+ struct stat st;
if (stat (filename, &st) == -1) {
- msg_info ("cannot load history from %s: %s", filename, strerror (errno));
+ msg_info ("cannot load history from %s: %s", filename,
+ strerror (errno));
return FALSE;
}
@@ -169,13 +176,15 @@ rspamd_roll_history_load (struct roll_history *history, const gchar *filename)
}
if ((fd = open (filename, O_RDONLY)) == -1) {
- msg_info ("cannot load history from %s: %s", filename, strerror (errno));
+ msg_info ("cannot load history from %s: %s", filename,
+ strerror (errno));
return FALSE;
}
if (read (fd, history->rows, sizeof (history->rows)) == -1) {
close (fd);
- msg_info ("cannot read history from %s: %s", filename, strerror (errno));
+ msg_info ("cannot read history from %s: %s", filename,
+ strerror (errno));
return FALSE;
}
@@ -193,7 +202,7 @@ rspamd_roll_history_load (struct roll_history *history, const gchar *filename)
gboolean
rspamd_roll_history_save (struct roll_history *history, const gchar *filename)
{
- gint fd;
+ gint fd;
if ((fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 00600)) == -1) {
msg_info ("cannot save history to %s: %s", filename, strerror (errno));