summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-30 15:40:31 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-30 15:40:31 +0100
commit67761b737080a3e8f4a5ac8417258d6fcda05240 (patch)
tree2ed0a1a22d5c6593321af6d3e028db0a457b535f /src/plugins
parentd0a4d803ecfb7934ccd4e665e8b0919eaa2a8d3c (diff)
downloadrspamd-67761b737080a3e8f4a5ac8417258d6fcda05240.tar.gz
rspamd-67761b737080a3e8f4a5ac8417258d6fcda05240.zip
[Project] Implement fast module ctx lookup
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/chartable.c13
-rw-r--r--src/plugins/dkim_check.c13
-rw-r--r--src/plugins/fuzzy_check.c13
-rw-r--r--src/plugins/regexp.c37
-rw-r--r--src/plugins/spf.c28
-rw-r--r--src/plugins/surbl.c26
6 files changed, 70 insertions, 60 deletions
diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c
index c9df2269a..d07e7fc00 100644
--- a/src/plugins/chartable.c
+++ b/src/plugins/chartable.c
@@ -61,12 +61,13 @@ gint chartable_module_config (struct rspamd_config *cfg);
gint chartable_module_reconfig (struct rspamd_config *cfg);
module_t chartable_module = {
- "chartable",
- chartable_module_init,
- chartable_module_config,
- chartable_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "chartable",
+ chartable_module_init,
+ chartable_module_config,
+ chartable_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
struct chartable_ctx {
diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c
index 3993d7bc4..7d930b2b4 100644
--- a/src/plugins/dkim_check.c
+++ b/src/plugins/dkim_check.c
@@ -106,12 +106,13 @@ gint dkim_module_config (struct rspamd_config *cfg);
gint dkim_module_reconfig (struct rspamd_config *cfg);
module_t dkim_module = {
- "dkim",
- dkim_module_init,
- dkim_module_config,
- dkim_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "dkim",
+ dkim_module_init,
+ dkim_module_config,
+ dkim_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
static void
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index 7557d9bf7..1b0fa2844 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -188,12 +188,13 @@ static gint fuzzy_lua_learn_handler (lua_State *L);
static gint fuzzy_lua_unlearn_handler (lua_State *L);
module_t fuzzy_check_module = {
- "fuzzy_check",
- fuzzy_check_module_init,
- fuzzy_check_module_config,
- fuzzy_check_module_reconfig,
- fuzzy_attach_controller,
- RSPAMD_MODULE_VER
+ "fuzzy_check",
+ fuzzy_check_module_init,
+ fuzzy_check_module_config,
+ fuzzy_check_module_reconfig,
+ fuzzy_attach_controller,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
static void
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index 1ffa7d88b..915305aa3 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -39,8 +39,6 @@ struct regexp_ctx {
gsize max_size;
};
-static struct regexp_ctx *regexp_module_ctx = NULL;
-
static void process_regexp_item (struct rspamd_task *task, void *user_data);
@@ -50,14 +48,23 @@ gint regexp_module_config (struct rspamd_config *cfg);
gint regexp_module_reconfig (struct rspamd_config *cfg);
module_t regexp_module = {
- "regexp",
- regexp_module_init,
- regexp_module_config,
- regexp_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "regexp",
+ regexp_module_init,
+ regexp_module_config,
+ regexp_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
+
+static inline struct regexp_ctx *
+regexp_get_context (struct rspamd_config *cfg)
+{
+ return (struct regexp_ctx *)g_ptr_array_index (cfg->c_modules,
+ regexp_module.ctx_offset);
+}
+
/* Process regexp expression */
static gboolean
read_regexp_expression (rspamd_mempool_t * pool,
@@ -90,9 +97,10 @@ read_regexp_expression (rspamd_mempool_t * pool,
gint
regexp_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
- if (regexp_module_ctx == NULL) {
- regexp_module_ctx = g_malloc0 (sizeof (struct regexp_ctx));
- }
+ struct regexp_ctx *regexp_module_ctx;
+
+ regexp_module_ctx = rspamd_mempool_alloc0 (cfg->cfg_pool,
+ sizeof (*regexp_module_ctx));
*ctx = (struct module_ctx *)regexp_module_ctx;
@@ -122,6 +130,7 @@ regexp_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
gint
regexp_module_config (struct rspamd_config *cfg)
{
+ struct regexp_ctx *regexp_module_ctx = regexp_get_context (cfg);
struct regexp_module_item *cur_item = NULL;
const ucl_object_t *sec, *value, *elt;
ucl_object_iter_t it = NULL;
@@ -336,12 +345,6 @@ regexp_module_config (struct rspamd_config *cfg)
gint
regexp_module_reconfig (struct rspamd_config *cfg)
{
- struct module_ctx saved_ctx;
-
- saved_ctx = regexp_module_ctx->ctx;
- memset (regexp_module_ctx, 0, sizeof (*regexp_module_ctx));
- regexp_module_ctx->ctx = saved_ctx;
-
return regexp_module_config (cfg);
}
diff --git a/src/plugins/spf.c b/src/plugins/spf.c
index 683683a55..5ec5bfcfc 100644
--- a/src/plugins/spf.c
+++ b/src/plugins/spf.c
@@ -62,13 +62,6 @@ struct spf_ctx {
gboolean check_authed;
};
-static inline struct spf_ctx *
-spf_get_context (struct rspamd_config *cfg)
-{
- return (struct spf_ctx *)g_hash_table_lookup (cfg->c_modules, "spf");
-}
-
-
static void spf_symbol_callback (struct rspamd_task *task, void *unused);
/* Initialization */
@@ -77,14 +70,23 @@ gint spf_module_config (struct rspamd_config *cfg);
gint spf_module_reconfig (struct rspamd_config *cfg);
module_t spf_module = {
- "spf",
- spf_module_init,
- spf_module_config,
- spf_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "spf",
+ spf_module_init,
+ spf_module_config,
+ spf_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
+static inline struct spf_ctx *
+spf_get_context (struct rspamd_config *cfg)
+{
+ return (struct spf_ctx *)g_ptr_array_index (cfg->c_modules,
+ spf_module.ctx_offset);
+}
+
+
gint
spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index 07c6d06c1..d3ed6da74 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -159,26 +159,28 @@ surbl_error_quark (void)
return g_quark_from_static_string ("surbl-error-quark");
}
-static inline struct surbl_ctx *
-surbl_get_context (struct rspamd_config *cfg)
-{
- return (struct surbl_ctx *)g_hash_table_lookup (cfg->c_modules, "surbl");
-}
-
/* Initialization */
gint surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
gint surbl_module_config (struct rspamd_config *cfg);
gint surbl_module_reconfig (struct rspamd_config *cfg);
module_t surbl_module = {
- "surbl",
- surbl_module_init,
- surbl_module_config,
- surbl_module_reconfig,
- NULL,
- RSPAMD_MODULE_VER
+ "surbl",
+ surbl_module_init,
+ surbl_module_config,
+ surbl_module_reconfig,
+ NULL,
+ RSPAMD_MODULE_VER,
+ (guint)-1,
};
+static inline struct surbl_ctx *
+surbl_get_context (struct rspamd_config *cfg)
+{
+ return (struct surbl_ctx *)g_ptr_array_index (cfg->c_modules,
+ surbl_module.ctx_offset);
+}
+
static void
exceptions_free_value (gpointer v)
{