]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add magic for all workers' contexts
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Apr 2016 15:07:14 +0000 (16:07 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Apr 2016 15:07:14 +0000 (16:07 +0100)
src/controller.c
src/fuzzy_storage.c
src/hs_helper.c
src/http_proxy.c
src/libserver/protocol.c
src/lua_worker.c
src/rspamd.h
src/smtp_proxy.c
src/worker.c

index 6aefe071976f72c906090722617f3f3015558200..f3e21730e355abc60261a5662ce83dbf90208a91 100644 (file)
@@ -99,6 +99,8 @@ const struct timeval rrd_update_time = {
                .tv_usec = 0
 };
 
+const guint64 rspamd_controller_ctx_magic = 0xf72697805e6941faULL;
+
 gpointer init_controller_worker (struct rspamd_config *cfg);
 void start_controller_worker (struct rspamd_worker *worker);
 
@@ -114,6 +116,7 @@ worker_t controller_worker = {
  * Worker's context
  */
 struct rspamd_controller_worker_ctx {
+       guint64 magic;
        guint32 timeout;
        struct timeval io_tv;
        /* DNS resolver */
@@ -2397,6 +2400,7 @@ init_controller_worker (struct rspamd_config *cfg)
 
        ctx = g_malloc0 (sizeof (struct rspamd_controller_worker_ctx));
 
+       ctx->magic = rspamd_controller_ctx_magic;
        ctx->timeout = DEFAULT_WORKER_IO_TIMEOUT;
 
        rspamd_rcl_register_worker_option (cfg,
index b37d6766cce3291fae4cb9b5eb8ed1f9fcb92fbd..4ab92cc9f14fa09b10553700cf024b016a9b1f89 100644 (file)
@@ -84,7 +84,10 @@ struct fuzzy_key_stat {
        rspamd_lru_hash_t *last_ips;
 };
 
+static const guint64 rspamd_fuzzy_storage_magic = 0x291a3253eb1b3ea5ULL;
+
 struct rspamd_fuzzy_storage_ctx {
+       guint64 magic;
        struct fuzzy_global_stat stat;
        char *hashfile;
        gdouble expire;
@@ -1204,6 +1207,7 @@ init_fuzzy (struct rspamd_config *cfg)
 
        ctx = g_malloc0 (sizeof (struct rspamd_fuzzy_storage_ctx));
 
+       ctx->magic = rspamd_fuzzy_storage_magic;
        ctx->sync_timeout = DEFAULT_SYNC_TIMEOUT;
        ctx->expire = DEFAULT_EXPIRE;
        ctx->keypair_cache_size = DEFAULT_KEYPAIR_CACHE_SIZE;
index 5885461aa62b0ca7285c215fb22fb1b2183c489d..1434f551af9401d53c9fb8a8681ee5c9f914af82 100644 (file)
@@ -39,11 +39,13 @@ worker_t hs_helper_worker = {
 
 static const gdouble default_max_time = 1.0;
 static const gdouble default_recompile_time = 60.0;
+static const guint64 rspamd_hs_helper_magic = 0x22d310157a2288a0ULL;
 
 /*
  * Worker's context
  */
 struct hs_helper_ctx {
+       guint64 magic;
        gchar *hs_dir;
        gboolean loaded;
        gdouble max_time;
@@ -62,6 +64,7 @@ init_hs_helper (struct rspamd_config *cfg)
        type = g_quark_try_string ("hs_helper");
        ctx = g_malloc0 (sizeof (*ctx));
 
+       ctx->magic = rspamd_hs_helper_magic;
        ctx->cfg = cfg;
        ctx->hs_dir = RSPAMD_DBDIR "/";
        ctx->max_time = default_max_time;
index 3ad821f9675d8338e26206f6d61f6ab59242193b..b61511d1c3cc7c18c4e2d4b0a4f3ecab528dbf91 100644 (file)
@@ -49,7 +49,10 @@ struct rspamd_http_upstream {
        struct rspamd_cryptobox_pubkey *key;
 };
 
+static const guint64 rspamd_http_proxy_magic = 0xcdeb4fd1fc351980ULL;
+
 struct http_proxy_ctx {
+       guint64 magic;
        gdouble timeout;
        struct timeval io_tv;
        struct rspamd_config *cfg;
@@ -188,6 +191,7 @@ init_http_proxy (struct rspamd_config *cfg)
        type = g_quark_try_string ("http_proxy");
 
        ctx = g_malloc0 (sizeof (struct http_proxy_ctx));
+       ctx->magic = rspamd_http_proxy_magic;
        ctx->timeout = 5.0;
        ctx->upstreams = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
        ctx->rotate_tm = DEFAULT_ROTATION_TIME;
index 609f7995bf9b680442b0640bc663e4e28e4ec7cc..0774df13ce91a80858aa14cca1a734c5e4e16c1f 100644 (file)
@@ -21,6 +21,7 @@
 #include "message.h"
 #include "utlist.h"
 #include "http.h"
+#include "worker_private.h"
 
 /* Max line size */
 #define OUTBUFSIZ BUFSIZ
index ea876cec5e26b18b0f109192f7b31529f78f5155..87f597e28fea1577e4c22c3fd6c93f450c232c06 100644 (file)
@@ -47,10 +47,12 @@ worker_t lua_worker = {
        RSPAMD_WORKER_VER       /* Version info */
 };
 
+static const guint64 rspamd_lua_ctx_magic = 0x8055e2652aacf96eULL;
 /*
  * Worker's context
  */
 struct rspamd_lua_worker_ctx {
+       guint64 magic;
        /* DNS resolver */
        struct rspamd_dns_resolver *resolver;
        /* Events base */
@@ -310,6 +312,7 @@ init_lua_worker (struct rspamd_config *cfg)
        type = g_quark_try_string ("lua");
 
        ctx = g_malloc0 (sizeof (struct rspamd_lua_worker_ctx));
+       ctx->magic = rspamd_lua_ctx_magic;
        ctx->params = g_hash_table_new_full (rspamd_str_hash,
                        rspamd_str_equal,
                        g_free,
index 90a4b376269b098672395b9a83a6129726724e04..286a929f8609fa412f543f6cb22641baeab1599c 100644 (file)
@@ -62,6 +62,11 @@ struct rspamd_worker {
        gpointer control_data;          /**< used by control protocol to handle commands        */
 };
 
+struct rspamd_abstract_worker_ctx {
+       guint64 magic;
+       char data[];
+};
+
 struct rspamd_worker_signal_handler;
 
 struct rspamd_worker_signal_cb {
index 3f9444b06341e143241999d4b74b28d7a7325f71..0202e3cfea68005f26fdab599a8c3fb812d440d4 100644 (file)
@@ -48,7 +48,10 @@ worker_t smtp_proxy_worker = {
        RSPAMD_WORKER_VER           /* Version info */
 };
 
+static guint64 rspamd_smtp_proxy_magic = 0xf3d849189c85f12dULL;
+
 struct smtp_proxy_ctx {
+       guint64 magic;
        struct upstream_list *upstreams;
        gchar *upstreams_str;
 
@@ -965,6 +968,7 @@ init_smtp_proxy (struct rspamd_config *cfg)
        type = g_quark_try_string ("smtp_proxy");
 
        ctx = g_malloc0 (sizeof (struct smtp_worker_ctx));
+       ctx->magic = rspamd_smtp_proxy_magic;
        ctx->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
 
        /* Set default values */
index a4ef7a81ab293f3197158b585857fa5428f6dd87..8056b3f0f9d3a491f524b55090139f59281a151e 100644 (file)
@@ -32,6 +32,7 @@
 #include "libstat/stat_api.h"
 #include "libserver/worker_util.h"
 #include "libserver/rspamd_control.h"
+#include "worker_private.h"
 #include "utlist.h"
 
 #include "lua/lua_common.h"
@@ -70,44 +71,6 @@ worker_t normal_worker = {
         G_STRFUNC, \
         __VA_ARGS__)
 
-struct rspamd_worker_log_pipe {
-       gint fd;
-       enum rspamd_log_pipe_type type;
-       struct rspamd_worker_log_pipe *prev, *next;
-};
-
-/*
- * Worker's context
- */
-struct rspamd_worker_ctx {
-       guint32 timeout;
-       struct timeval io_tv;
-       /* Detect whether this worker is mime worker    */
-       gboolean is_mime;
-       /* HTTP worker                                                                  */
-       gboolean is_http;
-       /* JSON output                                  */
-       gboolean is_json;
-       /* Allow learning throught worker                               */
-       gboolean allow_learn;
-       /* DNS resolver */
-       struct rspamd_dns_resolver *resolver;
-       /* Limit of tasks */
-       guint32 max_tasks;
-       /* Maximum time for task processing */
-       gdouble task_timeout;
-       /* Events base */
-       struct event_base *ev_base;
-       /* Encryption key */
-       struct rspamd_cryptobox_keypair *key;
-       /* Keys cache */
-       struct rspamd_keypair_cache *keys_cache;
-       /* Configuration */
-       struct rspamd_config *cfg;
-       /* Log pipe */
-       struct rspamd_worker_log_pipe *log_pipes;
-};
-
 /*
  * Reduce number of tasks proceeded
  */
@@ -436,6 +399,7 @@ init_worker (struct rspamd_config *cfg)
 
        ctx = g_malloc0 (sizeof (struct rspamd_worker_ctx));
 
+       ctx->magic = rspamd_worker_magic;
        ctx->is_mime = TRUE;
        ctx->timeout = DEFAULT_WORKER_IO_TIMEOUT;
        ctx->cfg = cfg;