aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-12 14:44:35 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-12 14:44:35 +0000
commit85b3f42f215e5736d90a803835f506673538bbd0 (patch)
tree30ac8621fee86ad9dcb5f7950af157016e0bc3cf /src/libserver
parentd54124d738a0e30d2b3b9adb1966374935ff3f46 (diff)
downloadrspamd-85b3f42f215e5736d90a803835f506673538bbd0.tar.gz
rspamd-85b3f42f215e5736d90a803835f506673538bbd0.zip
Initial support for dynamic modules and workers
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/cfg_file.h2
-rw-r--r--src/libserver/cfg_utils.c93
-rw-r--r--src/libserver/worker_util.c29
3 files changed, 112 insertions, 12 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 7b49e4866..44e838dd6 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -341,6 +341,8 @@ struct rspamd_config {
GList *classify_headers; /**< list of headers using for statistics */
struct module_s **compiled_modules; /**< list of compiled C modules */
struct worker_s **compiled_workers; /**< list of compiled C modules */
+ GList *dynamic_modules; /**< list of dynamic C modules */
+ GList *dynamic_workers; /**< list of dynamic C modules */
struct rspamd_log_format *log_format; /**< parsed log format */
gchar *log_format_str; /**< raw log format string */
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 66a67fe13..bd2aac89b 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -1130,6 +1130,64 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data)
}
gboolean
+rspamd_check_module (struct rspamd_config *cfg, module_t *mod)
+{
+ gboolean ret = TRUE;
+
+ if (mod != NULL) {
+ if (mod->module_version != RSPAMD_CUR_MODULE_VERSION) {
+ msg_err_config ("module %s has incorrect version %xd (%xd expected)",
+ mod->name, mod->module_version, RSPAMD_CUR_MODULE_VERSION);
+ ret = FALSE;
+ }
+ if (ret && mod->rspamd_version != RSPAMD_VERSION_NUM) {
+ msg_err_config ("module %s has incorrect rspamd version %xd (%xd expected)",
+ mod->name, mod->rspamd_version, RSPAMD_VERSION_NUM);
+ ret = FALSE;
+ }
+ if (ret && strcmp (mod->rspamd_features, RSPAMD_FEATURES) != 0) {
+ msg_err_config ("module %s has incorrect rspamd features '%s' ('%s' expected)",
+ mod->name, mod->rspamd_features, RSPAMD_FEATURES);
+ ret = FALSE;
+ }
+ }
+ else {
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
+gboolean
+rspamd_check_worker (struct rspamd_config *cfg, worker_t *wrk)
+{
+ gboolean ret = TRUE;
+
+ if (wrk != NULL) {
+ if (wrk->worker_version != RSPAMD_CUR_WORKER_VERSION) {
+ msg_err_config ("worker %s has incorrect version %xd (%xd expected)",
+ wrk->name, wrk->worker_version, RSPAMD_CUR_WORKER_VERSION);
+ ret = FALSE;
+ }
+ if (ret && wrk->rspamd_version != RSPAMD_VERSION_NUM) {
+ msg_err_config ("worker %s has incorrect rspamd version %xd (%xd expected)",
+ wrk->name, wrk->rspamd_version, RSPAMD_VERSION_NUM);
+ ret = FALSE;
+ }
+ if (ret && strcmp (wrk->rspamd_features, RSPAMD_FEATURES) != 0) {
+ msg_err_config ("worker %s has incorrect rspamd features '%s' ('%s' expected)",
+ wrk->name, wrk->rspamd_features, RSPAMD_FEATURES);
+ ret = FALSE;
+ }
+ }
+ else {
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
+gboolean
rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
{
GList *cur;
@@ -1140,17 +1198,40 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
if (!reconfig) {
for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod ++) {
mod = *pmod;
- mod_ctx = g_slice_alloc0 (sizeof (struct module_ctx));
- if (mod->module_init_func (cfg, &mod_ctx) == 0) {
- g_hash_table_insert (cfg->c_modules,
- (gpointer) mod->name,
- mod_ctx);
- mod_ctx->mod = mod;
+ if (rspamd_check_module (cfg, mod)) {
+ mod_ctx = g_slice_alloc0 (sizeof (struct module_ctx));
+
+ if (mod->module_init_func (cfg, &mod_ctx) == 0) {
+ g_hash_table_insert (cfg->c_modules,
+ (gpointer) mod->name,
+ mod_ctx);
+ mod_ctx->mod = mod;
+ }
}
}
+
+ cur = g_list_first (cfg->dynamic_modules);
+
+ while (cur) {
+ mod = cur->data;
+
+ if (rspamd_check_module (cfg, mod)) {
+ mod_ctx = g_slice_alloc0 (sizeof (struct module_ctx));
+
+ if (mod->module_init_func (cfg, &mod_ctx) == 0) {
+ g_hash_table_insert (cfg->c_modules,
+ (gpointer) mod->name,
+ mod_ctx);
+ mod_ctx->mod = mod;
+ }
+ }
+
+ cur = g_list_next (cur);
+ }
}
+ /* Now check what's enabled */
cur = g_list_first (cfg->filters);
while (cur) {
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 8bda8d709..b18c36ec9 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -49,14 +49,31 @@
worker_t *
rspamd_get_worker_by_type (struct rspamd_config *cfg, GQuark type)
{
- worker_t **cur;
+ worker_t **pwrk, *wrk;
+ GList *cur;
- cur = cfg->compiled_workers;
- while (cur && *cur) {
- if (g_quark_from_string ((*cur)->name) == type) {
- return *cur;
+ pwrk = cfg->compiled_workers;
+ while (pwrk && *pwrk) {
+ if (rspamd_check_worker (cfg, *pwrk)) {
+ if (g_quark_from_string ((*pwrk)->name) == type) {
+ return *pwrk;
+ }
}
- cur++;
+
+ pwrk++;
+ }
+
+ cur = g_list_first (cfg->dynamic_workers);
+ while (cur) {
+ wrk = cur->data;
+
+ if (rspamd_check_worker (cfg, wrk)) {
+ if (g_quark_from_string (wrk->name) == type) {
+ return wrk;
+ }
+ }
+
+ cur = g_list_next (cur);
}
return NULL;