aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-09 18:55:45 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-09 18:55:45 +0100
commit1321e13e3d5e717d78d30e7eebdb069a9ebea390 (patch)
tree4980cea6e7da701cb8d291959c4664ad9976d4ed
parentb5e2ec2942b303b8d95989b9e7f3cec5debe4f00 (diff)
downloadrspamd-1321e13e3d5e717d78d30e7eebdb069a9ebea390.tar.gz
rspamd-1321e13e3d5e717d78d30e7eebdb069a9ebea390.zip
[Rework] Adopt new maps code
Issue: #616
-rw-r--r--src/libserver/cfg_utils.c49
-rw-r--r--src/libserver/dynamic_cfg.c5
-rw-r--r--src/plugins/surbl.c30
3 files changed, 36 insertions, 48 deletions
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 8cc54c792..233051dcb 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -42,13 +42,11 @@ struct rspamd_ucl_map_cbdata {
struct rspamd_config *cfg;
GString *buf;
};
-static gchar * rspamd_ucl_read_cb (rspamd_mempool_t * pool,
- gchar * chunk,
+static gchar * rspamd_ucl_read_cb (gchar * chunk,
gint len,
struct map_cb_data *data,
gboolean final);
-static void rspamd_ucl_fin_cb (rspamd_mempool_t * pool,
- struct map_cb_data *data);
+static void rspamd_ucl_fin_cb (struct map_cb_data *data);
gboolean
rspamd_parse_bind_line (struct rspamd_config *cfg,
@@ -1135,8 +1133,7 @@ rspamd_config_check_statfiles (struct rspamd_classifier_config *cf)
}
static gchar *
-rspamd_ucl_read_cb (rspamd_mempool_t * pool,
- gchar * chunk,
+rspamd_ucl_read_cb (gchar * chunk,
gint len,
struct map_cb_data *data,
gboolean final)
@@ -1157,7 +1154,7 @@ rspamd_ucl_read_cb (rspamd_mempool_t * pool,
}
static void
-rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data)
+rspamd_ucl_fin_cb (struct map_cb_data *data)
{
struct rspamd_ucl_map_cbdata *cbdata = data->cur_data, *prev =
data->prev_data;
@@ -1181,33 +1178,25 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data)
}
checksum = XXH64 (cbdata->buf->str, cbdata->buf->len, 0);
- if (data->map->checksum != checksum) {
- /* New data available */
- parser = ucl_parser_new (0);
- if (!ucl_parser_add_chunk (parser, cbdata->buf->str,
+ /* New data available */
+ parser = ucl_parser_new (0);
+ if (!ucl_parser_add_chunk (parser, cbdata->buf->str,
cbdata->buf->len)) {
- msg_err_config ("cannot parse map %s: %s",
- data->map->uri,
+ msg_err_config ("cannot parse map %s: %s",
+ data->map->name,
ucl_parser_get_error (parser));
- ucl_parser_free (parser);
- }
- else {
- obj = ucl_parser_get_object (parser);
- ucl_parser_free (parser);
- it = NULL;
-
- while ((cur = ucl_object_iterate (obj, &it, true))) {
- ucl_object_replace_key (cbdata->cfg->rcl_obj, (ucl_object_t *)cur,
- cur->key, cur->keylen, false);
- }
- ucl_object_unref (obj);
- data->map->checksum = checksum;
- }
+ ucl_parser_free (parser);
}
else {
- msg_info_config ("do not reload map %s, checksum is the same: %d",
- data->map->uri,
- checksum);
+ obj = ucl_parser_get_object (parser);
+ ucl_parser_free (parser);
+ it = NULL;
+
+ while ((cur = ucl_object_iterate (obj, &it, true))) {
+ ucl_object_replace_key (cbdata->cfg->rcl_obj, (ucl_object_t *)cur,
+ cur->key, cur->keylen, false);
+ }
+ ucl_object_unref (obj);
}
}
diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c
index 3a76f20f9..d31418588 100644
--- a/src/libserver/dynamic_cfg.c
+++ b/src/libserver/dynamic_cfg.c
@@ -134,8 +134,7 @@ apply_dynamic_conf (const ucl_object_t *top, struct rspamd_config *cfg)
/* Callbacks for reading json dynamic rules */
static gchar *
-json_config_read_cb (rspamd_mempool_t * pool,
- gchar * chunk,
+json_config_read_cb (gchar * chunk,
gint len,
struct map_cb_data *data,
gboolean final)
@@ -167,7 +166,7 @@ json_config_read_cb (rspamd_mempool_t * pool,
}
static void
-json_config_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data)
+json_config_fin_cb (struct map_cb_data *data)
{
struct config_json_buf *jb;
ucl_object_t *top;
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index 4dda832b3..35383c829 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -80,7 +80,7 @@ module_t surbl_module = {
};
static void
-exception_insert (gpointer st, gconstpointer key, gpointer value)
+exception_insert (gpointer st, gconstpointer key, gconstpointer value)
{
GHashTable **t = st;
gint level = 0;
@@ -103,27 +103,27 @@ exception_insert (gpointer st, gconstpointer key, gpointer value)
val = g_malloc (sizeof (rspamd_ftok_t));
val->begin = key;
val->len = strlen (key);
+
if (t[level] == NULL) {
t[level] = g_hash_table_new_full (rspamd_ftok_icase_hash,
rspamd_ftok_icase_equal,
g_free,
- NULL);
+ g_free);
}
- g_hash_table_insert (t[level], val, value);
+
+ g_hash_table_insert (t[level], val, g_strdup (value));
}
static gchar *
-read_exceptions_list (rspamd_mempool_t * pool,
- gchar * chunk,
+read_exceptions_list (gchar * chunk,
gint len,
struct map_cb_data *data,
gboolean final)
{
if (data->cur_data == NULL) {
- data->cur_data = rspamd_mempool_alloc0 (pool,
- sizeof (GHashTable *) * MAX_LEVELS);
+ data->cur_data = g_malloc (sizeof (GHashTable *) * MAX_LEVELS);
}
- return rspamd_parse_kv_list (pool,
+ return rspamd_parse_kv_list (
chunk,
len,
data,
@@ -133,7 +133,7 @@ read_exceptions_list (rspamd_mempool_t * pool,
}
static void
-fin_exceptions_list (rspamd_mempool_t * pool, struct map_cb_data *data)
+fin_exceptions_list (struct map_cb_data *data)
{
GHashTable **t;
gint i;
@@ -145,11 +145,12 @@ fin_exceptions_list (rspamd_mempool_t * pool, struct map_cb_data *data)
g_hash_table_destroy (t[i]);
}
}
+ g_free (t);
}
}
static void
-redirector_insert (gpointer st, gconstpointer key, gpointer value)
+redirector_insert (gpointer st, gconstpointer key, gconstpointer value)
{
GHashTable *tld_hash = st;
const gchar *p = key, *begin = key;
@@ -200,8 +201,7 @@ redirector_item_free (gpointer p)
}
static gchar *
-read_redirectors_list (rspamd_mempool_t * pool,
- gchar * chunk,
+read_redirectors_list (gchar * chunk,
gint len,
struct map_cb_data *data,
gboolean final)
@@ -217,17 +217,17 @@ read_redirectors_list (rspamd_mempool_t * pool,
data->cur_data = tld_hash;
}
- return rspamd_parse_kv_list (pool,
+ return rspamd_parse_kv_list (
chunk,
len,
data,
- (insert_func) redirector_insert,
+ redirector_insert,
"",
final);
}
void
-fin_redirectors_list (rspamd_mempool_t * pool, struct map_cb_data *data)
+fin_redirectors_list (struct map_cb_data *data)
{
GHashTable *tld_hash;