aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-07-08 14:42:03 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-07-08 14:42:03 +0100
commit470fe5ae7ddba65078d9d456dc0068ccb8b9905b (patch)
tree79ae5f998a5cb078fa860e2cba65513d199ca48c /src/lua
parent213c8ef3232ceada4e70fba6e3c4e72362cb5f15 (diff)
downloadrspamd-470fe5ae7ddba65078d9d456dc0068ccb8b9905b.tar.gz
rspamd-470fe5ae7ddba65078d9d456dc0068ccb8b9905b.zip
[Minor] Push dynamic symbol weight
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index dc41d4ab7..61aac63f2 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -2642,7 +2642,7 @@ struct rspamd_url_query_to_inject_cbd {
static gboolean
inject_url_query_callback(struct rspamd_url *url, gsize start_offset,
- gsize end_offset, gpointer ud)
+ gsize end_offset, gpointer ud)
{
struct rspamd_url_query_to_inject_cbd *cbd =
(struct rspamd_url_query_to_inject_cbd *) ud;
@@ -2661,7 +2661,7 @@ inject_url_query_callback(struct rspamd_url *url, gsize start_offset,
static void
inject_url_query(struct rspamd_task *task, struct rspamd_url *url,
- GPtrArray *part_urls)
+ GPtrArray *part_urls)
{
if (url->querylen > 0) {
struct rspamd_url_query_to_inject_cbd cbd;
@@ -2692,11 +2692,11 @@ lua_task_inject_url(lua_State *L)
if (lua_isuserdata(L, 3)) {
/* We also have a mime part there */
mpart = *((struct rspamd_mime_part **)
- rspamd_lua_check_udata_maybe(L, 3, rspamd_mimepart_classname));
+ rspamd_lua_check_udata_maybe(L, 3, rspamd_mimepart_classname));
}
if (task && task->message && url && url->url) {
if (rspamd_url_set_add_or_increase(MESSAGE_FIELD(task, urls), url->url, false)) {
- if(mpart && mpart->urls) {
+ if (mpart && mpart->urls) {
inject_url_query(task, url->url, mpart->urls);
}
}
@@ -4682,7 +4682,7 @@ lua_push_symbol_result(lua_State *L,
struct rspamd_symbol_option *opt;
struct rspamd_symbols_group *sym_group;
unsigned int i;
- int j = 1, table_fields_cnt = 4;
+ int j = 1, table_fields_cnt = 5;
if (!metric_res) {
metric_res = task->result;
@@ -4710,10 +4710,22 @@ lua_push_symbol_result(lua_State *L,
lua_pushstring(L, symbol);
lua_settable(L, -3);
}
+
lua_pushstring(L, "score");
lua_pushnumber(L, s->score);
lua_settable(L, -3);
+ /* Dynamic weight of the symbol */
+ if (s->sym->score != 0) {
+ lua_pushstring(L, "weight");
+ lua_pushnumber(L, s->score / s->sym->score);
+ }
+ else {
+ lua_pushstring(L, "weight");
+ lua_pushnumber(L, 0.0);
+ }
+ lua_settable(L, -3);
+
if (s->sym && s->sym->gr) {
lua_pushstring(L, "group");
lua_pushstring(L, s->sym->gr->name);