commit 42a8b2d: [Minor] Cleanup various stuff
Vsevolod Stakhov
vsevolod at highsecure.ru
Thu Apr 11 17:21:07 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-04-11 14:48:09 +0100
URL: https://github.com/rspamd/rspamd/commit/42a8b2da0117555109c35a9b6e44e73d605a0bd6
[Minor] Cleanup various stuff
---
src/libserver/rspamd_symcache.h | 38 ++++++++--------
src/libserver/task.h | 98 ++++++++++++++++++++---------------------
src/libserver/url.h | 58 ++++++++++++------------
src/lua/lua_common.h | 2 +-
src/lua/lua_task.c | 34 +++++++++++++-
5 files changed, 131 insertions(+), 99 deletions(-)
diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h
index 0228e4f5a..afdda7e79 100644
--- a/src/libserver/rspamd_symcache.h
+++ b/src/libserver/rspamd_symcache.h
@@ -32,25 +32,25 @@ typedef void (*symbol_func_t)(struct rspamd_task *task,
gpointer user_data);
enum rspamd_symbol_type {
- SYMBOL_TYPE_NORMAL = (1 << 0),
- SYMBOL_TYPE_VIRTUAL = (1 << 1),
- SYMBOL_TYPE_CALLBACK = (1 << 2),
- SYMBOL_TYPE_GHOST = (1 << 3),
- SYMBOL_TYPE_SKIPPED = (1 << 4),
- SYMBOL_TYPE_COMPOSITE = (1 << 5),
- SYMBOL_TYPE_CLASSIFIER = (1 << 6),
- SYMBOL_TYPE_FINE = (1 << 7),
- SYMBOL_TYPE_EMPTY = (1 << 8), /* Allow execution on empty tasks */
- SYMBOL_TYPE_PREFILTER = (1 << 9),
- SYMBOL_TYPE_POSTFILTER = (1 << 10),
- SYMBOL_TYPE_NOSTAT = (1 << 11), /* Skip as statistical symbol */
- SYMBOL_TYPE_IDEMPOTENT = (1 << 12), /* Symbol cannot change metric */
- SYMBOL_TYPE_SQUEEZED = (1 << 13), /* Symbol is squeezed inside Lua */
- SYMBOL_TYPE_TRIVIAL = (1 << 14), /* Symbol is trivial */
- SYMBOL_TYPE_MIME_ONLY = (1 << 15), /* Symbol is mime only */
- SYMBOL_TYPE_EXPLICIT_DISABLE = (1 << 16), /* Symbol should be disabled explicitly only */
- SYMBOL_TYPE_IGNORE_PASSTHROUGH = (1 << 17), /* Symbol ignores passthrough result */
- SYMBOL_TYPE_USE_CORO = (1 << 18), /* Symbol uses lua coroutines */
+ SYMBOL_TYPE_NORMAL = (1u << 0u),
+ SYMBOL_TYPE_VIRTUAL = (1u << 1u),
+ SYMBOL_TYPE_CALLBACK = (1u << 2u),
+ SYMBOL_TYPE_GHOST = (1u << 3u),
+ SYMBOL_TYPE_SKIPPED = (1u << 4u),
+ SYMBOL_TYPE_COMPOSITE = (1u << 5u),
+ SYMBOL_TYPE_CLASSIFIER = (1u << 6u),
+ SYMBOL_TYPE_FINE = (1u << 7u),
+ SYMBOL_TYPE_EMPTY = (1u << 8u), /* Allow execution on empty tasks */
+ SYMBOL_TYPE_PREFILTER = (1u << 9u),
+ SYMBOL_TYPE_POSTFILTER = (1u << 10u),
+ SYMBOL_TYPE_NOSTAT = (1u << 11u), /* Skip as statistical symbol */
+ SYMBOL_TYPE_IDEMPOTENT = (1u << 12u), /* Symbol cannot change metric */
+ SYMBOL_TYPE_SQUEEZED = (1u << 13u), /* Symbol is squeezed inside Lua */
+ SYMBOL_TYPE_TRIVIAL = (1u << 14u), /* Symbol is trivial */
+ SYMBOL_TYPE_MIME_ONLY = (1u << 15u), /* Symbol is mime only */
+ SYMBOL_TYPE_EXPLICIT_DISABLE = (1u << 16u), /* Symbol should be disabled explicitly only */
+ SYMBOL_TYPE_IGNORE_PASSTHROUGH = (1u << 17u), /* Symbol ignores passthrough result */
+ SYMBOL_TYPE_USE_CORO = (1u << 18u), /* Symbol uses lua coroutines */
};
/**
diff --git a/src/libserver/task.h b/src/libserver/task.h
index b97f91eb4..763866987 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -37,24 +37,24 @@ enum rspamd_command {
};
enum rspamd_task_stage {
- RSPAMD_TASK_STAGE_CONNECT = (1 << 0),
- RSPAMD_TASK_STAGE_ENVELOPE = (1 << 1),
- RSPAMD_TASK_STAGE_READ_MESSAGE = (1 << 2),
- RSPAMD_TASK_STAGE_PRE_FILTERS = (1 << 3),
- RSPAMD_TASK_STAGE_PROCESS_MESSAGE = (1 << 4),
- RSPAMD_TASK_STAGE_FILTERS = (1 << 5),
- RSPAMD_TASK_STAGE_CLASSIFIERS_PRE = (1 << 6),
- RSPAMD_TASK_STAGE_CLASSIFIERS = (1 << 7),
- RSPAMD_TASK_STAGE_CLASSIFIERS_POST = (1 << 8),
- RSPAMD_TASK_STAGE_COMPOSITES = (1 << 9),
- RSPAMD_TASK_STAGE_POST_FILTERS = (1 << 10),
- RSPAMD_TASK_STAGE_LEARN_PRE = (1 << 11),
- RSPAMD_TASK_STAGE_LEARN = (1 << 12),
- RSPAMD_TASK_STAGE_LEARN_POST = (1 << 13),
- RSPAMD_TASK_STAGE_COMPOSITES_POST = (1 << 14),
- RSPAMD_TASK_STAGE_IDEMPOTENT = (1 << 15),
- RSPAMD_TASK_STAGE_DONE = (1 << 16),
- RSPAMD_TASK_STAGE_REPLIED = (1 << 17)
+ RSPAMD_TASK_STAGE_CONNECT = (1u << 0u),
+ RSPAMD_TASK_STAGE_ENVELOPE = (1u << 1u),
+ RSPAMD_TASK_STAGE_READ_MESSAGE = (1u << 2u),
+ RSPAMD_TASK_STAGE_PRE_FILTERS = (1u << 3u),
+ RSPAMD_TASK_STAGE_PROCESS_MESSAGE = (1u << 4u),
+ RSPAMD_TASK_STAGE_FILTERS = (1u << 5u),
+ RSPAMD_TASK_STAGE_CLASSIFIERS_PRE = (1u << 6u),
+ RSPAMD_TASK_STAGE_CLASSIFIERS = (1u << 7u),
+ RSPAMD_TASK_STAGE_CLASSIFIERS_POST = (1u << 8u),
+ RSPAMD_TASK_STAGE_COMPOSITES = (1u << 9u),
+ RSPAMD_TASK_STAGE_POST_FILTERS = (1u << 10u),
+ RSPAMD_TASK_STAGE_LEARN_PRE = (1u << 11u),
+ RSPAMD_TASK_STAGE_LEARN = (1u << 12u),
+ RSPAMD_TASK_STAGE_LEARN_POST = (1u << 13u),
+ RSPAMD_TASK_STAGE_COMPOSITES_POST = (1u << 14u),
+ RSPAMD_TASK_STAGE_IDEMPOTENT = (1u << 15u),
+ RSPAMD_TASK_STAGE_DONE = (1u << 16u),
+ RSPAMD_TASK_STAGE_REPLIED = (1u << 17u)
};
#define RSPAMD_TASK_PROCESS_ALL (RSPAMD_TASK_STAGE_CONNECT | \
@@ -86,37 +86,37 @@ enum rspamd_task_stage {
RSPAMD_TASK_STAGE_LEARN_POST | \
RSPAMD_TASK_STAGE_DONE)
-#define RSPAMD_TASK_FLAG_MIME (1 << 0)
-#define RSPAMD_TASK_FLAG_JSON (1 << 1)
-#define RSPAMD_TASK_FLAG_SKIP_PROCESS (1 << 2)
-#define RSPAMD_TASK_FLAG_SKIP (1 << 3)
-#define RSPAMD_TASK_FLAG_EXT_URLS (1 << 4)
-#define RSPAMD_TASK_FLAG_SPAMC (1 << 5)
-#define RSPAMD_TASK_FLAG_PASS_ALL (1 << 6)
-#define RSPAMD_TASK_FLAG_NO_LOG (1 << 7)
-#define RSPAMD_TASK_FLAG_NO_IP (1 << 8)
-#define RSPAMD_TASK_FLAG_HAS_CONTROL (1 << 9)
-#define RSPAMD_TASK_FLAG_PROCESSING (1 << 10)
-#define RSPAMD_TASK_FLAG_GTUBE (1 << 11)
-#define RSPAMD_TASK_FLAG_FILE (1 << 12)
-#define RSPAMD_TASK_FLAG_NO_STAT (1 << 13)
-#define RSPAMD_TASK_FLAG_UNLEARN (1 << 14)
-#define RSPAMD_TASK_FLAG_ALREADY_LEARNED (1 << 15)
-#define RSPAMD_TASK_FLAG_LEARN_SPAM (1 << 16)
-#define RSPAMD_TASK_FLAG_LEARN_HAM (1 << 17)
-#define RSPAMD_TASK_FLAG_LEARN_AUTO (1 << 18)
-#define RSPAMD_TASK_FLAG_BROKEN_HEADERS (1 << 19)
-#define RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS (1 << 20)
-#define RSPAMD_TASK_FLAG_HAS_HAM_TOKENS (1 << 21)
-#define RSPAMD_TASK_FLAG_EMPTY (1 << 22)
-#define RSPAMD_TASK_FLAG_LOCAL_CLIENT (1 << 23)
-#define RSPAMD_TASK_FLAG_COMPRESSED (1 << 24)
-#define RSPAMD_TASK_FLAG_PROFILE (1 << 25)
-#define RSPAMD_TASK_FLAG_GREYLISTED (1 << 26)
-#define RSPAMD_TASK_FLAG_OWN_POOL (1 << 27)
-#define RSPAMD_TASK_FLAG_MILTER (1 << 28)
-#define RSPAMD_TASK_FLAG_SSL (1 << 29)
-#define RSPAMD_TASK_FLAG_BAD_UNICODE (1 << 30)
+#define RSPAMD_TASK_FLAG_MIME (1u << 0u)
+#define RSPAMD_TASK_FLAG_JSON (1u << 1u)
+#define RSPAMD_TASK_FLAG_SKIP_PROCESS (1u << 2u)
+#define RSPAMD_TASK_FLAG_SKIP (1u << 3u)
+#define RSPAMD_TASK_FLAG_EXT_URLS (1u << 4u)
+#define RSPAMD_TASK_FLAG_SPAMC (1u << 5u)
+#define RSPAMD_TASK_FLAG_PASS_ALL (1u << 6u)
+#define RSPAMD_TASK_FLAG_NO_LOG (1u << 7u)
+#define RSPAMD_TASK_FLAG_NO_IP (1u << 8u)
+#define RSPAMD_TASK_FLAG_HAS_CONTROL (1u << 9u)
+#define RSPAMD_TASK_FLAG_PROCESSING (1u << 10u)
+#define RSPAMD_TASK_FLAG_GTUBE (1u << 11u)
+#define RSPAMD_TASK_FLAG_FILE (1u << 12u)
+#define RSPAMD_TASK_FLAG_NO_STAT (1u << 13u)
+#define RSPAMD_TASK_FLAG_UNLEARN (1u << 14u)
+#define RSPAMD_TASK_FLAG_ALREADY_LEARNED (1u << 15u)
+#define RSPAMD_TASK_FLAG_LEARN_SPAM (1u << 16u)
+#define RSPAMD_TASK_FLAG_LEARN_HAM (1u << 17u)
+#define RSPAMD_TASK_FLAG_LEARN_AUTO (1u << 18u)
+#define RSPAMD_TASK_FLAG_BROKEN_HEADERS (1u << 19u)
+#define RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS (1u << 20u)
+#define RSPAMD_TASK_FLAG_HAS_HAM_TOKENS (1u << 21u)
+#define RSPAMD_TASK_FLAG_EMPTY (1u << 22u)
+#define RSPAMD_TASK_FLAG_LOCAL_CLIENT (1u << 23u)
+#define RSPAMD_TASK_FLAG_COMPRESSED (1u << 24u)
+#define RSPAMD_TASK_FLAG_PROFILE (1u << 25u)
+#define RSPAMD_TASK_FLAG_GREYLISTED (1u << 26u)
+#define RSPAMD_TASK_FLAG_OWN_POOL (1u << 27u)
+#define RSPAMD_TASK_FLAG_MILTER (1u << 28u)
+#define RSPAMD_TASK_FLAG_SSL (1u << 29u)
+#define RSPAMD_TASK_FLAG_BAD_UNICODE (1u << 30u)
#define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP))
#define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON))
diff --git a/src/libserver/url.h b/src/libserver/url.h
index 2243534dc..e724d44ff 100644
--- a/src/libserver/url.h
+++ b/src/libserver/url.h
@@ -10,25 +10,25 @@ struct rspamd_task;
struct rspamd_mime_text_part;
enum rspamd_url_flags {
- RSPAMD_URL_FLAG_PHISHED = 1 << 0,
- RSPAMD_URL_FLAG_NUMERIC = 1 << 1,
- RSPAMD_URL_FLAG_OBSCURED = 1 << 2,
- RSPAMD_URL_FLAG_REDIRECTED = 1 << 3,
- RSPAMD_URL_FLAG_HTML_DISPLAYED = 1 << 4,
- RSPAMD_URL_FLAG_FROM_TEXT = 1 << 5,
- RSPAMD_URL_FLAG_SUBJECT = 1 << 6,
- RSPAMD_URL_FLAG_HOSTENCODED = 1 << 7,
- RSPAMD_URL_FLAG_SCHEMAENCODED = 1 << 8,
- RSPAMD_URL_FLAG_PATHENCODED = 1 << 9,
- RSPAMD_URL_FLAG_QUERYENCODED = 1 << 10,
- RSPAMD_URL_FLAG_MISSINGSLASHES = 1 << 11,
- RSPAMD_URL_FLAG_IDN = 1 << 12,
- RSPAMD_URL_FLAG_HAS_PORT = 1 << 13,
- RSPAMD_URL_FLAG_HAS_USER = 1 << 14,
- RSPAMD_URL_FLAG_SCHEMALESS = 1 << 15,
- RSPAMD_URL_FLAG_UNNORMALISED = 1 << 16,
- RSPAMD_URL_FLAG_ZW_SPACES = 1 << 17,
- RSPAMD_URL_FLAG_DISPLAY_URL = 1 << 18,
+ RSPAMD_URL_FLAG_PHISHED = 1u << 0u,
+ RSPAMD_URL_FLAG_NUMERIC = 1u << 1u,
+ RSPAMD_URL_FLAG_OBSCURED = 1u << 2u,
+ RSPAMD_URL_FLAG_REDIRECTED = 1u << 3u,
+ RSPAMD_URL_FLAG_HTML_DISPLAYED = 1u << 4u,
+ RSPAMD_URL_FLAG_FROM_TEXT = 1u << 5u,
+ RSPAMD_URL_FLAG_SUBJECT = 1u << 6u,
+ RSPAMD_URL_FLAG_HOSTENCODED = 1u << 7u,
+ RSPAMD_URL_FLAG_SCHEMAENCODED = 1u << 8u,
+ RSPAMD_URL_FLAG_PATHENCODED = 1u << 9u,
+ RSPAMD_URL_FLAG_QUERYENCODED = 1u << 10u,
+ RSPAMD_URL_FLAG_MISSINGSLASHES = 1u << 11u,
+ RSPAMD_URL_FLAG_IDN = 1u << 12u,
+ RSPAMD_URL_FLAG_HAS_PORT = 1u << 13u,
+ RSPAMD_URL_FLAG_HAS_USER = 1u << 14u,
+ RSPAMD_URL_FLAG_SCHEMALESS = 1u << 15u,
+ RSPAMD_URL_FLAG_UNNORMALISED = 1u << 16u,
+ RSPAMD_URL_FLAG_ZW_SPACES = 1u << 17u,
+ RSPAMD_URL_FLAG_DISPLAY_URL = 1u << 18u,
};
struct rspamd_url_tag {
@@ -81,19 +81,19 @@ enum uri_errno {
};
enum rspamd_url_protocol {
- PROTOCOL_FILE = 1u << 0,
- PROTOCOL_FTP = 1u << 1,
- PROTOCOL_HTTP = 1u << 2,
- PROTOCOL_HTTPS = 1u << 3,
- PROTOCOL_MAILTO = 1u << 4,
- PROTOCOL_TELEPHONE = 1u << 5,
- PROTOCOL_UNKNOWN = 1u << 31,
+ PROTOCOL_FILE = 1u << 0u,
+ PROTOCOL_FTP = 1u << 1u,
+ PROTOCOL_HTTP = 1u << 2u,
+ PROTOCOL_HTTPS = 1u << 3u,
+ PROTOCOL_MAILTO = 1u << 4u,
+ PROTOCOL_TELEPHONE = 1u << 5u,
+ PROTOCOL_UNKNOWN = 1u << 31u,
};
enum rspamd_url_parse_flags {
- RSPAMD_URL_PARSE_TEXT = 0,
- RSPAMD_URL_PARSE_HREF = (1u << 0),
- RSPAMD_URL_PARSE_CHECK = (1 << 1),
+ RSPAMD_URL_PARSE_TEXT = 0u,
+ RSPAMD_URL_PARSE_HREF = (1u << 0u),
+ RSPAMD_URL_PARSE_CHECK = (1u << 1u),
};
enum rspamd_url_find_type {
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index ca0d0c591..2aaf670a4 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -486,7 +486,7 @@ extern ucl_object_t *lua_traces;
func_obj->value.iv ++; \
} while(0)
#else
-#define LUA_TRACE_POINT
+#define LUA_TRACE_POINT do {} while(0)
#endif
#endif /* WITH_LUA */
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index d809c6ab1..d647c4a1d 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -99,6 +99,11 @@ LUA_FUNCTION_DEF (task, get_mempool);
* @return {rspamd_session} session object
*/
LUA_FUNCTION_DEF (task, get_session);
+/***
+ * @method task:set_session(session)
+ * Sets new async session for a task
+ */
+LUA_FUNCTION_DEF (task, set_session);
/***
* @method task:get_ev_base()
* Return asynchronous event base for using in callbacks and resolver.
@@ -1026,6 +1031,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_cfg),
LUA_INTERFACE_DEF (task, get_mempool),
LUA_INTERFACE_DEF (task, get_session),
+ LUA_INTERFACE_DEF (task, set_session),
LUA_INTERFACE_DEF (task, get_ev_base),
LUA_INTERFACE_DEF (task, get_worker),
LUA_INTERFACE_DEF (task, insert_result),
@@ -1514,6 +1520,7 @@ lua_task_create (lua_State * L)
LUA_TRACE_POINT;
struct rspamd_task *task = NULL, **ptask;
struct rspamd_config *cfg = NULL;
+ struct event_base *ev_base = NULL;
if (lua_type (L, 1) == LUA_TUSERDATA) {
gpointer p;
@@ -1524,7 +1531,16 @@ lua_task_create (lua_State * L)
}
}
- task = rspamd_task_new (NULL, cfg, NULL, NULL, NULL);
+ if (lua_type (L, 2) == LUA_TUSERDATA) {
+ gpointer p;
+ p = rspamd_lua_check_udata_maybe (L, 2, "rspamd{ev_base}");
+
+ if (p) {
+ ev_base = *(struct event_base **)p;
+ }
+ }
+
+ task = rspamd_task_new (NULL, cfg, NULL, NULL, ev_base);
task->flags |= RSPAMD_TASK_FLAG_EMPTY;
ptask = lua_newuserdata (L, sizeof (*ptask));
@@ -1571,6 +1587,22 @@ lua_task_get_session (lua_State * L)
return 1;
}
+static int
+lua_task_set_session (lua_State * L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_async_session *session = lua_check_session (L, 2);
+ struct rspamd_task *task = lua_check_task (L, 1);
+
+ if (task != NULL && session != NULL) {
+ task->s = session;
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+ return 1;
+}
+
static int
lua_task_get_ev_base (lua_State * L)
{
More information about the Commits
mailing list