aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-13 17:46:50 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-13 17:46:50 +0100
commitd2a938d398d31fae55e709a4e219b5acfa5c7622 (patch)
tree616ee4dacde622e13ee26f4437febf9e5eae4661 /src/lua
parent444c70ff896dcd07f1569e394b528cf1f61dec54 (diff)
downloadrspamd-d2a938d398d31fae55e709a4e219b5acfa5c7622.tar.gz
rspamd-d2a938d398d31fae55e709a4e219b5acfa5c7622.zip
Rework parts and task structure:
- Now text_parts, parts and received are arrays - Pre-allocate arrays with some reasonable defaults - Use arrays instead of lists in plugins and checks - Remove unused fields from task structure - Rework mime_foreach callback function - Remove deprecated scan_milliseconds field
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c40
-rw-r--r--src/lua/lua_trie.c11
2 files changed, 21 insertions, 30 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index e40fe0197..90aea155d 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -886,23 +886,22 @@ lua_task_get_emails (lua_State * L)
static gint
lua_task_get_text_parts (lua_State * L)
{
- gint i = 1;
+ guint i;
struct rspamd_task *task = lua_check_task (L, 1);
- GList *cur;
struct mime_text_part *part, **ppart;
if (task != NULL) {
lua_newtable (L);
- cur = task->text_parts;
- while (cur) {
- part = cur->data;
+
+ for (i = 0; i < task->text_parts->len; i ++) {
+ part = g_ptr_array_index (task->text_parts, i);
ppart = lua_newuserdata (L, sizeof (struct mime_text_part *));
*ppart = part;
rspamd_lua_setclass (L, "rspamd{textpart}", -1);
/* Make it array */
- lua_rawseti (L, -2, i++);
- cur = g_list_next (cur);
+ lua_rawseti (L, -2, i + 1);
}
+
return 1;
}
lua_pushnil (L);
@@ -912,22 +911,20 @@ lua_task_get_text_parts (lua_State * L)
static gint
lua_task_get_parts (lua_State * L)
{
- gint i = 1;
+ guint i;
struct rspamd_task *task = lua_check_task (L, 1);
- GList *cur;
struct mime_part *part, **ppart;
if (task != NULL) {
lua_newtable (L);
- cur = task->parts;
- while (cur) {
- part = cur->data;
+
+ for (i = 0; i < task->parts->len; i ++) {
+ part = g_ptr_array_index (task->text_parts, i);
ppart = lua_newuserdata (L, sizeof (struct mime_part *));
*ppart = part;
rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
/* Make it array */
- lua_rawseti (L, -2, i++);
- cur = g_list_next (cur);
+ lua_rawseti (L, -2, i + 1);
}
return 1;
}
@@ -1153,23 +1150,23 @@ static gint
lua_task_get_received_headers (lua_State * L)
{
struct rspamd_task *task = lua_check_task (L, 1);
- GList *cur;
struct received_header *rh;
- gint i = 1;
+ guint i;
if (task) {
lua_newtable (L);
- cur = g_list_first (task->received);
- while (cur) {
- rh = cur->data;
+
+ for (i = 0; i < task->received->len; i ++) {
+ rh = g_ptr_array_index (task->received, i);
+
if (rh->is_error || G_UNLIKELY (
rh->from_ip == NULL &&
rh->real_ip == NULL &&
rh->real_hostname == NULL &&
rh->by_hostname == NULL)) {
- cur = g_list_next (cur);
continue;
}
+
lua_newtable (L);
rspamd_lua_table_set (L, "from_hostname", rh->from_hostname);
lua_pushstring (L, "from_ip");
@@ -1180,8 +1177,7 @@ lua_task_get_received_headers (lua_State * L)
rspamd_lua_ip_push_fromstring (L, rh->real_ip);
lua_settable (L, -3);
rspamd_lua_table_set (L, "by_hostname", rh->by_hostname);
- lua_rawseti (L, -2, i++);
- cur = g_list_next (cur);
+ lua_rawseti (L, -2, i + 1);
}
}
else {
diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c
index f1b9088db..bceda4502 100644
--- a/src/lua/lua_trie.c
+++ b/src/lua/lua_trie.c
@@ -260,17 +260,14 @@ lua_trie_search_mime (lua_State *L)
ac_trie_t *trie = lua_check_trie (L, 1);
struct rspamd_task *task = lua_check_task (L, 2);
struct mime_text_part *part;
- GList *cur;
const gchar *text;
gint state = 0;
- gsize len;
+ gsize len, i;
gboolean found = FALSE;
if (trie) {
- cur = task->text_parts;
-
- while (cur) {
- part = cur->data;
+ for (i = 0; i < task->text_parts->len; i ++) {
+ part = g_ptr_array_index (task->text_parts, i);
if (!IS_PART_EMPTY (part) && part->content != NULL) {
text = part->content->data;
@@ -280,8 +277,6 @@ lua_trie_search_mime (lua_State *L)
found = TRUE;
}
}
-
- cur = g_list_next (cur);
}
}