aboutsummaryrefslogtreecommitdiffstats
path: root/src/settings.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-10-02 17:09:38 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-10-02 17:09:38 +0400
commitf3ad9c6f1e91c9912dbe730fdec350b5fc908672 (patch)
tree005e5568431db09becaa9b67a33dfc11f80bba7f /src/settings.c
parente6a1d22de250c10992b484635fd95a03f197f779 (diff)
downloadrspamd-f3ad9c6f1e91c9912dbe730fdec350b5fc908672.tar.gz
rspamd-f3ad9c6f1e91c9912dbe730fdec350b5fc908672.zip
* Retab, no functional changes
Diffstat (limited to 'src/settings.c')
-rw-r--r--src/settings.c98
1 files changed, 48 insertions, 50 deletions
diff --git a/src/settings.c b/src/settings.c
index 5ee37d4ed..a4dca10dd 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -30,16 +30,16 @@
#include "json/jansson.h"
struct json_buf {
- GHashTable *table;
- u_char *buf;
- u_char *pos;
- size_t buflen;
+ GHashTable *table;
+ u_char *buf;
+ u_char *pos;
+ size_t buflen;
};
static void
settings_free (gpointer data)
{
- struct rspamd_settings *s = data;
+ struct rspamd_settings *s = data;
if (s->statfile_alias) {
g_free (s->statfile_alias);
@@ -54,11 +54,11 @@ settings_free (gpointer data)
}
-u_char*
-json_read_cb (memory_pool_t *pool, u_char *chunk, size_t len, struct map_cb_data *data)
+u_char *
+json_read_cb (memory_pool_t * pool, u_char * chunk, size_t len, struct map_cb_data *data)
{
- struct json_buf *jb;
- size_t free, off;
+ struct json_buf *jb;
+ size_t free, off;
if (data->cur_data == NULL) {
jb = g_malloc (sizeof (struct json_buf));
@@ -89,22 +89,22 @@ json_read_cb (memory_pool_t *pool, u_char *chunk, size_t len, struct map_cb_data
memcpy (jb->pos, chunk, len);
jb->pos += len;
-
+
/* Say not to copy any part of this buffer */
return NULL;
}
void
-json_fin_cb (memory_pool_t *pool, struct map_cb_data *data)
-{
- struct json_buf *jb;
- int nelts, i;
- json_t *js, *cur_elt, *cur_nm, *it_val;
- json_error_t je;
- struct rspamd_settings *cur_settings;
- char *cur_name;
- void *json_it;
- double *score;
+json_fin_cb (memory_pool_t * pool, struct map_cb_data *data)
+{
+ struct json_buf *jb;
+ int nelts, i;
+ json_t *js, *cur_elt, *cur_nm, *it_val;
+ json_error_t je;
+ struct rspamd_settings *cur_settings;
+ char *cur_name;
+ void *json_it;
+ double *score;
if (data->prev_data) {
jb = data->prev_data;
@@ -146,7 +146,7 @@ json_fin_cb (memory_pool_t *pool, struct map_cb_data *data)
}
nelts = json_array_size (js);
- for (i = 0; i < nelts; i ++) {
+ for (i = 0; i < nelts; i++) {
cur_settings = g_malloc (sizeof (struct rspamd_settings));
cur_settings->metric_scores = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
cur_settings->factors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -179,10 +179,9 @@ json_fin_cb (memory_pool_t *pool, struct map_cb_data *data)
while (json_it) {
it_val = json_object_iter_value (json_it);
if (it_val && json_is_string (it_val)) {
- g_hash_table_insert (cur_settings->factors, g_strdup (json_object_iter_key (json_it)),
- g_strdup (json_string_value (it_val)));
+ g_hash_table_insert (cur_settings->factors, g_strdup (json_object_iter_key (json_it)), g_strdup (json_string_value (it_val)));
}
- json_it = json_object_iter_next(cur_nm, json_it);
+ json_it = json_object_iter_next (cur_nm, json_it);
}
}
/* Metrics object */
@@ -194,10 +193,9 @@ json_fin_cb (memory_pool_t *pool, struct map_cb_data *data)
if (it_val && json_is_number (it_val)) {
score = g_malloc (sizeof (double));
*score = json_number_value (it_val);
- g_hash_table_insert (cur_settings->metric_scores, g_strdup (json_object_iter_key (json_it)),
- score);
+ g_hash_table_insert (cur_settings->metric_scores, g_strdup (json_object_iter_key (json_it)), score);
}
- json_it = json_object_iter_next(cur_nm, json_it);
+ json_it = json_object_iter_next (cur_nm, json_it);
}
}
/* Want spam */
@@ -207,18 +205,18 @@ json_fin_cb (memory_pool_t *pool, struct map_cb_data *data)
cur_settings->want_spam = TRUE;
}
}
- g_hash_table_insert (((struct json_buf*)data->cur_data)->table, cur_name, cur_settings);
+ g_hash_table_insert (((struct json_buf *)data->cur_data)->table, cur_name, cur_settings);
}
json_decref (js);
}
gboolean
-read_settings (const char *path, struct config_file *cfg, GHashTable *table)
+read_settings (const char *path, struct config_file *cfg, GHashTable * table)
{
- struct json_buf *jb = g_malloc (sizeof (struct json_buf)), **pjb;
+ struct json_buf *jb = g_malloc (sizeof (struct json_buf)), **pjb;
pjb = g_malloc (sizeof (struct json_buf *));
-
+
jb->table = table;
jb->buf = NULL;
*pjb = jb;
@@ -227,7 +225,7 @@ read_settings (const char *path, struct config_file *cfg, GHashTable *table)
msg_err ("read_settings: cannot add map %s", path);
return FALSE;
}
-
+
return TRUE;
}
@@ -238,10 +236,10 @@ init_settings (struct config_file *cfg)
cfg->user_settings = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal, g_free, settings_free);
}
-static gboolean
+static gboolean
check_setting (struct worker_task *task, struct rspamd_settings **user_settings, struct rspamd_settings **domain_settings)
{
- char *field = NULL, *domain = NULL;
+ char *field = NULL, *domain = NULL;
if (task->deliver_to != NULL) {
/* First try to use deliver-to field */
@@ -267,9 +265,9 @@ check_setting (struct worker_task *task, struct rspamd_settings **user_settings,
}
}
if (domain != NULL) {
- domain ++;
+ domain++;
}
-
+
/* First try to search per-user settings */
if (field != NULL) {
*user_settings = g_hash_table_lookup (task->cfg->user_settings, field);
@@ -285,11 +283,11 @@ check_setting (struct worker_task *task, struct rspamd_settings **user_settings,
return FALSE;
}
-gboolean
-check_metric_settings (struct worker_task *task, struct metric *metric, double *score)
+gboolean
+check_metric_settings (struct worker_task * task, struct metric * metric, double *score)
{
- struct rspamd_settings *us, *ds;
- double *sc;
+ struct rspamd_settings *us, *ds;
+ double *sc;
if (check_setting (task, &us, &ds)) {
if (us != NULL) {
@@ -311,15 +309,15 @@ check_metric_settings (struct worker_task *task, struct metric *metric, double *
}
}
}
-
+
return FALSE;
}
-gboolean
-check_factor_settings (struct worker_task *task, const char *symbol, double *factor)
+gboolean
+check_factor_settings (struct worker_task * task, const char *symbol, double *factor)
{
- struct rspamd_settings *us, *ds;
- double *fc;
+ struct rspamd_settings *us, *ds;
+ double *fc;
if (check_setting (task, &us, &ds)) {
if (us != NULL) {
@@ -341,16 +339,16 @@ check_factor_settings (struct worker_task *task, const char *symbol, double *fac
}
}
}
-
+
return FALSE;
}
-gboolean
-check_want_spam (struct worker_task *task)
+gboolean
+check_want_spam (struct worker_task * task)
{
- struct rspamd_settings *us, *ds;
+ struct rspamd_settings *us, *ds;
if (check_setting (task, &us, &ds)) {
if (us != NULL) {
@@ -369,7 +367,7 @@ check_want_spam (struct worker_task *task)
}
}
}
-
+
return FALSE;
}