diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-13 17:46:50 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-13 17:46:50 +0100 |
commit | d2a938d398d31fae55e709a4e219b5acfa5c7622 (patch) | |
tree | 616ee4dacde622e13ee26f4437febf9e5eae4661 /src/lua/lua_task.c | |
parent | 444c70ff896dcd07f1569e394b528cf1f61dec54 (diff) | |
download | rspamd-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/lua_task.c')
-rw-r--r-- | src/lua/lua_task.c | 40 |
1 files changed, 18 insertions, 22 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 { |