]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Move some of mempool magic constants to a separate file
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 May 2017 14:38:27 +0000 (15:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 May 2017 14:38:48 +0000 (15:38 +0100)
src/libmime/message.c
src/libmime/mime_headers.c
src/libserver/mempool_vars_internal.h [new file with mode: 0644]
src/libserver/protocol.c

index 1d0783d9b7bf67cb1029de199c6aef6b5e2f22bd..1d61b9807c17073f8d9de7d0ddd49fca7090dd23 100644 (file)
@@ -24,6 +24,7 @@
 #include "smtp_parsers.h"
 #include "mime_parser.h"
 #include "mime_encoding.h"
+#include "libserver/mempool_vars_internal.h"
 
 #ifdef WITH_SNOWBALL
 #include "libstemmer.h"
@@ -291,26 +292,26 @@ rspamd_extract_words (struct rspamd_task *task,
                gdouble *avg_len_p, *short_len_p;
 
                avg_len_p = rspamd_mempool_get_variable (task->task_pool,
-                               "avg_words_len");
+                               RSPAMD_MEMPOOL_AVG_WORDS_LEN);
 
                if (avg_len_p == NULL) {
                        avg_len_p = rspamd_mempool_alloc (task->task_pool, sizeof (double));
                        *avg_len_p = total_len;
                        rspamd_mempool_set_variable (task->task_pool,
-                                       "avg_words_len", avg_len_p, NULL);
+                                       RSPAMD_MEMPOOL_AVG_WORDS_LEN, avg_len_p, NULL);
                }
                else {
                        *avg_len_p += total_len;
                }
 
                short_len_p = rspamd_mempool_get_variable (task->task_pool,
-                               "short_words_cnt");
+                               RSPAMD_MEMPOOL_SHORT_WORDS_CNT);
 
                if (short_len_p == NULL) {
                        short_len_p = rspamd_mempool_alloc (task->task_pool, sizeof (double));
                        *short_len_p = short_len;
                        rspamd_mempool_set_variable (task->task_pool,
-                                       "short_words_cnt", avg_len_p, NULL);
+                                       RSPAMD_MEMPOOL_SHORT_WORDS_CNT, avg_len_p, NULL);
                }
                else {
                        *short_len_p += short_len;
@@ -950,13 +951,15 @@ rspamd_message_parse (struct rspamd_task *task)
        }
 
        if (total_words > 0) {
-               var = rspamd_mempool_get_variable (task->task_pool, "avg_words_len");
+               var = rspamd_mempool_get_variable (task->task_pool,
+                               RSPAMD_MEMPOOL_AVG_WORDS_LEN);
 
                if (var) {
                        *var /= (double)total_words;
                }
 
-               var = rspamd_mempool_get_variable (task->task_pool, "short_words_cnt");
+               var = rspamd_mempool_get_variable (task->task_pool,
+                               RSPAMD_MEMPOOL_SHORT_WORDS_CNT);
 
                if (var) {
                        *var /= (double)total_words;
index b4203f0d47c656df578366b52ba82523717d36d8..ef05bfcb3a6c5d2c1360a53b926889934c64a54f 100644 (file)
@@ -17,6 +17,7 @@
 #include "mime_headers.h"
 #include "smtp_parsers.h"
 #include "mime_encoding.h"
+#include "libserver/mempool_vars_internal.h"
 
 static void
 rspamd_mime_header_check_special (struct rspamd_task *task,
@@ -444,7 +445,8 @@ rspamd_mime_headers_process (struct rspamd_task *task, GHashTable *target,
                hexout[sizeof (hout) * 2] = '\0';
                rspamd_encode_hex_buf (hout, sizeof (hout), hexout,
                                sizeof (hout) * 2 + 1);
-               rspamd_mempool_set_variable (task->task_pool, "headers_hash",
+               rspamd_mempool_set_variable (task->task_pool,
+                               RSPAMD_MEMPOOL_HEADERS_HASH,
                                hexout, NULL);
        }
 }
diff --git a/src/libserver/mempool_vars_internal.h b/src/libserver/mempool_vars_internal.h
new file mode 100644 (file)
index 0000000..d73d530
--- /dev/null
@@ -0,0 +1,29 @@
+/*-
+ * Copyright 2016 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RSPAMD_MEMPOOL_VARS_INTERNAL_H
+#define RSPAMD_MEMPOOL_VARS_INTERNAL_H
+
+/* Basic rspamd mempool variables names */
+#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_CACHED_REPLY "cached_reply"
+
+
+#endif
index 1c11832a2dfd0ff4cecc045ff294881c67de94fd..404e75ce4e06c39c6bf22e63fcb3ce1cb8e94c9a 100644 (file)
@@ -23,6 +23,7 @@
 #include "lua/lua_common.h"
 #include "unix-std.h"
 #include "protocol_internal.h"
+#include "libserver/mempool_vars_internal.h"
 #include <math.h>
 
 static GQuark
@@ -357,7 +358,8 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                                                        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, "settings_hash",
+                                       rspamd_mempool_set_variable (task->task_pool,
+                                                       RSPAMD_MEMPOOL_SETTINGS_HASH,
                                                        hp, NULL);
                                }
                                break;
@@ -424,7 +426,8 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                                IF_HEADER (MTA_TAG_HEADER) {
                                        gchar *mta_tag;
                                        mta_tag = rspamd_mempool_ftokdup (task->task_pool, hv_tok);
-                                       rspamd_mempool_set_variable (task->task_pool, "MTA-Tag",
+                                       rspamd_mempool_set_variable (task->task_pool,
+                                                       RSPAMD_MEMPOOL_MTA_TAG,
                                                        mta_tag, NULL);
                                        debug_task ("read MTA-Tag header, value: %s", mta_tag);
                                }
@@ -1068,7 +1071,7 @@ rspamd_protocol_write_ucl (struct rspamd_task *task,
        GString *dkim_sig;
        const ucl_object_t *rmilter_reply;
        struct rspamd_saved_protocol_reply *cached;
-       static const gchar *varname = "cached_reply";
+       static const gchar *varname = RSPAMD_MEMPOOL_CACHED_REPLY;
 
        /* Check for cached reply */
        cached = rspamd_mempool_get_variable (task->task_pool, varname);