aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-09-28 14:30:13 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-09-28 14:30:13 +0100
commit388c08c712c8279a52ad82caa213191352639ca9 (patch)
tree9f12bba4be9b9772044928949c920175fa89d072 /src/lua
parent61dbbe0eca5291b1329393a5fe1903fde415a243 (diff)
downloadrspamd-388c08c712c8279a52ad82caa213191352639ca9.tar.gz
rspamd-388c08c712c8279a52ad82caa213191352639ca9.zip
[Feature] Stop using of GLists for headers, improve performance
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_common.h2
-rw-r--r--src/lua/lua_mimepart.c13
-rw-r--r--src/lua/lua_task.c44
3 files changed, 23 insertions, 36 deletions
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 1fefdc2cb..249ca9b90 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -192,7 +192,7 @@ struct rspamd_lua_text * lua_check_text (lua_State * L, gint pos);
* Push specific header to lua
*/
gint rspamd_lua_push_header (lua_State * L,
- GHashTable *hdrs,
+ GPtrArray *hdrs,
const gchar *name,
gboolean strong,
gboolean full,
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index d519cccbe..a2b6cc49c 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -668,19 +668,22 @@ lua_mimepart_get_filename (lua_State * L)
static gint
lua_mimepart_get_header_common (lua_State *L, gboolean full, gboolean raw)
{
- gboolean strong = FALSE;
struct rspamd_mime_part *part = lua_check_mimepart (L);
const gchar *name;
+ GPtrArray *ar;
name = luaL_checkstring (L, 2);
if (name && part) {
- if (lua_gettop (L) == 3) {
- strong = lua_toboolean (L, 3);
- }
- return rspamd_lua_push_header (L, part->raw_headers, name, strong, full, raw);
+
+ ar = rspamd_message_get_header_from_hash (part->raw_headers, NULL,
+ name, FALSE);
+
+ return rspamd_lua_push_header (L, ar, name, FALSE, full, raw);
}
+
lua_pushnil (L);
+
return 1;
}
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 8c6a3473c..db10abe01 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1361,57 +1361,40 @@ lua_task_set_request_header (lua_State *L)
gint
rspamd_lua_push_header (lua_State * L,
- GHashTable *hdrs,
+ GPtrArray *ar,
const gchar *name,
gboolean strong,
gboolean full,
gboolean raw)
{
- struct raw_header *rh, *cur;
- gint i = 1;
+ struct raw_header *rh;
+ guint i;
const gchar *val;
- rh = g_hash_table_lookup (hdrs, name);
-
- if (rh == NULL) {
+ if (ar == NULL || ar->len == 0) {
lua_pushnil (L);
return 1;
}
if (full) {
- i = 0;
- LL_FOREACH (rh, cur) {
- i ++;
- }
-
- lua_createtable (L, i, 0);
+ lua_createtable (L, ar->len, 0);
}
- i = 1;
-
- while (rh) {
- if (rh->name == NULL) {
- rh = rh->next;
- continue;
- }
- /* Check case sensivity */
- if (strong) {
- if (strcmp (rh->name, name) != 0) {
- rh = rh->next;
- continue;
- }
- }
+ PTR_ARRAY_FOREACH (ar, i, rh) {
if (full) {
/* Create new associated table for a header */
lua_createtable (L, 0, 6);
rspamd_lua_table_set (L, "name", rh->name);
+
if (rh->value) {
rspamd_lua_table_set (L, "value", rh->value);
}
+
if (rh->decoded) {
rspamd_lua_table_set (L, "decoded", rh->value);
}
+
lua_pushstring (L, "tab_separated");
lua_pushboolean (L, rh->tab_separated);
lua_settable (L, -3);
@@ -1419,9 +1402,7 @@ rspamd_lua_push_header (lua_State * L,
lua_pushboolean (L, rh->empty_separator);
lua_settable (L, -3);
rspamd_lua_table_set (L, "separator", rh->separator);
- lua_rawseti (L, -2, i++);
- /* Process next element */
- rh = rh->next;
+ lua_rawseti (L, -2, i + 1);
}
else {
if (!raw) {
@@ -1451,6 +1432,7 @@ lua_task_get_header_common (lua_State *L, gboolean full, gboolean raw)
gboolean strong = FALSE;
struct rspamd_task *task = lua_check_task (L, 1);
const gchar *name;
+ GPtrArray *ar;
name = luaL_checkstring (L, 2);
@@ -1459,7 +1441,9 @@ lua_task_get_header_common (lua_State *L, gboolean full, gboolean raw)
strong = lua_toboolean (L, 3);
}
- return rspamd_lua_push_header (L, task->raw_headers, name,
+ ar = rspamd_message_get_header_array (task, name, strong);
+
+ return rspamd_lua_push_header (L, ar, name,
strong, full, raw);
}
else {