aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_config.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-01-29 15:03:21 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-01-29 15:03:21 +0000
commitc70985d47ed3635fe5bedda65e9178f04d84b94e (patch)
treeb634cda9b27a2f582018e5f5c5866a01f06ef08d /src/lua/lua_config.c
parent971025ceca5af31e11a1d079302365bb6f3d7f8c (diff)
downloadrspamd-c70985d47ed3635fe5bedda65e9178f04d84b94e.tar.gz
rspamd-c70985d47ed3635fe5bedda65e9178f04d84b94e.zip
[Rework] Allow to add userdata as symbols options
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r--src/lua/lua_config.c77
1 files changed, 60 insertions, 17 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 266dbd111..24487f1b5 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -1267,24 +1267,45 @@ lua_metric_symbol_callback (struct rspamd_task *task,
for (i = level + first_opt; i <= last_pos; i++) {
if (lua_type (L, i) == LUA_TSTRING) {
- const char *opt = lua_tostring (L, i);
+ gsize optlen;
+ const char *opt = lua_tolstring (L, i, &optlen);
- rspamd_task_add_result_option (task, s, opt);
+ rspamd_task_add_result_option (task, s, opt, optlen);
+ }
+ else if (lua_type (L, i) == LUA_TUSERDATA) {
+ struct rspamd_lua_text *t = lua_check_text (L, i);
+
+ if (t) {
+ rspamd_task_add_result_option (task, s, t->start,
+ t->len);
+ }
}
else if (lua_type (L, i) == LUA_TTABLE) {
- lua_pushvalue (L, i);
+ gsize objlen = rspamd_lua_table_size (L, i);
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
- const char *opt = lua_tostring (L, -1);
+ for (guint j = 1; j <= objlen; j ++) {
+ lua_rawgeti (L, i, j);
- rspamd_task_add_result_option (task, s, opt);
- }
+ if (lua_type (L, -1) == LUA_TSTRING) {
+ gsize optlen;
+ const char *opt = lua_tolstring (L, -1, &optlen);
- lua_pop (L, 1);
+ rspamd_task_add_result_option (task, s, opt, optlen);
+ }
+ else if (lua_type (L, -1) == LUA_TUSERDATA) {
+ struct rspamd_lua_text *t = lua_check_text (L, -1);
+
+ if (t) {
+ rspamd_task_add_result_option (task, s, t->start,
+ t->len);
+ }
+ }
+
+ lua_pop (L, 1);
+ }
}
}
}
-
}
lua_pop (L, nresults);
@@ -1403,20 +1424,42 @@ lua_metric_symbol_callback_return (struct thread_entry *thread_entry, int ret)
for (i = cd->stack_level + first_opt; i <= last_pos; i++) {
if (lua_type (L, i) == LUA_TSTRING) {
- const char *opt = lua_tostring (L, i);
+ gsize optlen;
+ const char *opt = lua_tolstring (L, i, &optlen);
+
+ rspamd_task_add_result_option (task, s, opt, optlen);
+ }
+ else if (lua_type (L, i) == LUA_TUSERDATA) {
+ struct rspamd_lua_text *t = lua_check_text (L, i);
- rspamd_task_add_result_option (task, s, opt);
+ if (t) {
+ rspamd_task_add_result_option (task, s, t->start,
+ t->len);
+ }
}
else if (lua_type (L, i) == LUA_TTABLE) {
- lua_pushvalue (L, i);
+ gsize objlen = rspamd_lua_table_size (L, i);
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
- const char *opt = lua_tostring (L, -1);
+ for (guint j = 1; j <= objlen; j ++) {
+ lua_rawgeti (L, i, j);
- rspamd_task_add_result_option (task, s, opt);
- }
+ if (lua_type (L, -1) == LUA_TSTRING) {
+ gsize optlen;
+ const char *opt = lua_tolstring (L, -1, &optlen);
+
+ rspamd_task_add_result_option (task, s, opt, optlen);
+ }
+ else if (lua_type (L, -1) == LUA_TUSERDATA) {
+ struct rspamd_lua_text *t = lua_check_text (L, -1);
+
+ if (t) {
+ rspamd_task_add_result_option (task, s, t->start,
+ t->len);
+ }
+ }
- lua_pop (L, 1);
+ lua_pop (L, 1);
+ }
}
}
}