]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Store settings id directly
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Jun 2019 12:40:37 +0000 (13:40 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Jun 2019 15:15:28 +0000 (16:15 +0100)
src/libserver/mempool_vars_internal.h
src/libserver/protocol.c
src/libserver/task.h
src/lua/lua_task.c

index ad2958ab4e2745c4d451540a6cf6d882e7eeccbf..c062d44d475ce1c3bc5ef6232c24c3800e215e32 100644 (file)
@@ -21,7 +21,6 @@
 #define RSPAMD_MEMPOOL_AVG_WORDS_LEN "avg_words_len"
 #define RSPAMD_MEMPOOL_SHORT_WORDS_CNT "short_words_cnt"
 #define RSPAMD_MEMPOOL_HEADERS_HASH "headers_hash"
-#define RSPAMD_MEMPOOL_SETTINGS_HASH "settings_hash"
 #define RSPAMD_MEMPOOL_MTA_TAG "MTA-Tag"
 #define RSPAMD_MEMPOOL_MTA_NAME "MTA-Name"
 #define RSPAMD_MEMPOOL_SPF_DOMAIN "spf_domain"
index 34eaabe89376198894163a798d2ed1f75a29acd1..3574b94d2f77048638b858f3b627f506bce8aaec 100644 (file)
@@ -406,16 +406,12 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                                }
                                IF_HEADER (SETTINGS_ID_HEADER) {
                                        guint64 h;
-                                       guint32 *hp;
 
                                        msg_debug_protocol ("read settings-id header, value: %V", hv);
                                        h = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
-                                                       hv_tok->begin, hv_tok->len, 0xdeadbabe);
-                                       hp = rspamd_mempool_alloc (task->task_pool, sizeof (*hp));
-                                       memcpy (hp, &h, sizeof (*hp));
-                                       rspamd_mempool_set_variable (task->task_pool,
-                                                       RSPAMD_MEMPOOL_SETTINGS_HASH,
-                                                       hp, NULL);
+                                                       hv_tok->begin, hv_tok->len, 0x0);
+                                       /* Take the lower part of hash as LE number */
+                                       task->settings_id = (guint32)GUINT64_TO_LE (h);
                                }
                                break;
                        case 'u':
@@ -1628,8 +1624,7 @@ rspamd_protocol_write_log_pipe (struct rspamd_task *task)
                                        ls = g_malloc0 (sz);
 
                                        /* Handle settings id */
-                                       sid = rspamd_mempool_get_variable (task->task_pool,
-                                                       "settings_hash");
+                                       sid = task->settings_id;
 
                                        if (sid) {
                                                ls->settings_id = *sid;
index 763866987c502b2375fc49493545e4161d06feea..079e388df9ec06da95eab42b57581443c8b5bd30 100644 (file)
@@ -136,7 +136,6 @@ enum rspamd_newlines_type;
  */
 struct rspamd_task {
        struct rspamd_worker *worker;                                   /**< pointer to worker object                                           */
-       guint processed_stages;                                                 /**< bits of stages that are processed                          */
        enum rspamd_command cmd;                                                /**< command                                                                            */
        gint sock;                                                                              /**< socket descriptor                                                          */
        guint32 flags;                                                                  /**< Bit flags                                                                          */
@@ -206,6 +205,8 @@ struct rspamd_task {
 
        gpointer checkpoint;                                                    /**< Opaque checkpoint data                                                     */
        ucl_object_t *settings;                                                 /**< Settings applied to task                                           */
+       guint32 processed_stages;                                                       /**< bits of stages that are processed                  */
+       guint32 settings_id;                                                    /**< hashed settings id                                                         */
 
        const gchar *classifier;                                                /**< Classifier to learn (if needed)                            */
        struct rspamd_lang_detector *lang_det;                  /**< Languages detector                                                         */
index c1b50484dcb091b13c98f7eaf9e0ea5cb4bb59d5..3218a958f5f43623de9464294a439d85e52c4ecc 100644 (file)
@@ -4869,14 +4869,11 @@ lua_task_get_settings_id (lua_State *L)
 {
        LUA_TRACE_POINT;
        struct rspamd_task *task = lua_check_task (L, 1);
-       guint32 *hp;
 
        if (task != NULL) {
-               hp = rspamd_mempool_get_variable (task->task_pool,
-                               RSPAMD_MEMPOOL_SETTINGS_HASH);
 
-               if (hp) {
-                       lua_pushnumber (L, *hp);
+               if (task->settings_id) {
+                       lua_pushnumber (L, task->settings_id);
                }
                else {
                        lua_pushnil (L);