aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_ip.c6
-rw-r--r--src/lua/lua_regexp.c2
-rw-r--r--src/lua/lua_task.c25
-rw-r--r--src/lua/lua_url.c2
-rw-r--r--src/lua/lua_util.c8
5 files changed, 26 insertions, 17 deletions
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c
index 97f75ddda..0ebbf2003 100644
--- a/src/lua/lua_ip.c
+++ b/src/lua/lua_ip.c
@@ -223,8 +223,8 @@ lua_ip_to_table (lua_State *L)
guint8 *ptr;
if (ip != NULL && ip->addr) {
- lua_newtable (L);
ptr = rspamd_inet_address_get_hash_key (ip->addr, &max);
+ lua_createtable (L, max, 0);
for (i = 1; i <= max; i++, ptr++) {
lua_pushnumber (L, *ptr);
@@ -248,9 +248,9 @@ lua_ip_str_octets (lua_State *L)
char numbuf[8];
if (ip != NULL && ip->addr) {
- lua_newtable (L);
af = rspamd_inet_address_get_af (ip->addr);
ptr = rspamd_inet_address_get_hash_key (ip->addr, &max);
+ lua_createtable (L, max * 2, 0);
for (i = 1; i <= max; i++, ptr++) {
if (af == AF_INET) {
@@ -288,9 +288,9 @@ lua_ip_inversed_str_octets (lua_State *L)
gint af;
if (ip != NULL && ip->addr) {
- lua_newtable (L);
ptr = rspamd_inet_address_get_hash_key (ip->addr, &max);
af = rspamd_inet_address_get_af (ip->addr);
+ lua_createtable (L, max * 2, 0);
ptr += max - 1;
for (i = 1; i <= max; i++, ptr--) {
diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c
index e92c8530b..80b752172 100644
--- a/src/lua/lua_regexp.c
+++ b/src/lua/lua_regexp.c
@@ -419,7 +419,7 @@ lua_regexp_search (lua_State *L)
captures)) {
if (capture) {
- lua_newtable (L);
+ lua_createtable (L, captures->len, 0);
for (capn = 0; capn < captures->len; capn ++) {
cap = &g_array_index (captures, struct rspamd_re_capture,
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 8da6d3f16..4706d69a0 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1116,13 +1116,20 @@ lua_task_get_urls (lua_State * L)
struct rspamd_task *task = lua_check_task (L, 1);
struct lua_tree_cb_data cb;
gboolean need_emails = FALSE;
+ gsize sz;
if (task) {
if (lua_gettop (L) >= 2) {
need_emails = lua_toboolean (L, 2);
}
- lua_newtable (L);
+ sz = g_hash_table_size (task->urls);
+
+ if (need_emails) {
+ sz += g_hash_table_size (task->emails);
+ }
+
+ lua_createtable (L, sz, 0);
cb.i = 1;
cb.L = L;
g_hash_table_foreach (task->urls, lua_tree_url_callback, &cb);
@@ -1222,7 +1229,7 @@ lua_task_get_emails (lua_State * L)
struct lua_tree_cb_data cb;
if (task) {
- lua_newtable (L);
+ lua_createtable (L, g_hash_table_size (task->emails), 0);
cb.i = 1;
cb.L = L;
g_hash_table_foreach (task->emails, lua_tree_url_callback, &cb);
@@ -1242,7 +1249,7 @@ lua_task_get_text_parts (lua_State * L)
struct rspamd_mime_text_part *part, **ppart;
if (task != NULL) {
- lua_newtable (L);
+ lua_createtable (L, task->text_parts->len, 0);
for (i = 0; i < task->text_parts->len; i ++) {
part = g_ptr_array_index (task->text_parts, i);
@@ -1268,7 +1275,7 @@ lua_task_get_parts (lua_State * L)
struct rspamd_mime_part *part, **ppart;
if (task != NULL) {
- lua_newtable (L);
+ lua_createtable (L, task->parts->len, 0);
for (i = 0; i < task->parts->len; i ++) {
part = g_ptr_array_index (task->parts, i);
@@ -2218,7 +2225,7 @@ lua_task_get_archives (lua_State *L)
struct rspamd_archive **parch;
if (task) {
- lua_newtable (L);
+ lua_createtable (L, task->parts->len, 0);
for (i = 0; i < task->parts->len; i ++) {
part = g_ptr_array_index (task->parts, i);
@@ -2276,11 +2283,13 @@ lua_push_symbol_result (lua_State *L,
opt = s->options;
lua_pushstring (L, "options");
lua_newtable (L);
+
while (opt) {
lua_pushstring (L, opt->data);
lua_rawseti (L, -2, j++);
opt = g_list_next (opt);
}
+
lua_settable (L, -3);
}
@@ -2589,7 +2598,7 @@ lua_task_get_timeval (lua_State *L)
struct rspamd_task *task = lua_check_task (L, 1);
if (task != NULL) {
- lua_newtable (L);
+ lua_createtable (L, 0, 2);
lua_pushstring (L, "tv_sec");
lua_pushnumber (L, (lua_Number)task->tv.tv_sec);
lua_settable (L, -3);
@@ -2720,7 +2729,7 @@ lua_task_get_flags (lua_State *L)
guint flags, bit, i;
if (task) {
- lua_newtable (L);
+ lua_createtable (L, 8, 0);
flags = task->flags;
@@ -3088,7 +3097,7 @@ lua_task_get_metric_score (lua_State *L)
if (task && metric_name) {
if ((metric_res =
g_hash_table_lookup (task->results, metric_name)) != NULL) {
- lua_newtable (L);
+ lua_createtable (L, 2, 0);
lua_pushnumber (L, metric_res->score);
rs = rspamd_task_get_required_score (task, metric_res);
lua_rawseti (L, -2, 1);
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index ad77fcde2..2fd34664b 100644
--- a/src/lua/lua_url.c
+++ b/src/lua/lua_url.c
@@ -376,7 +376,7 @@ lua_url_to_table (lua_State *L)
if (url != NULL) {
u = url->url;
- lua_newtable (L);
+ lua_createtable (L, 0, 12);
lua_pushstring (L, "url");
lua_pushlstring (L, u->string, u->urllen);
lua_settable (L, -3);
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index b3c30ab29..9c37bc861 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -873,7 +873,7 @@ lua_util_tokenize_text (lua_State *L)
lua_pushnil (L);
}
else {
- lua_newtable (L);
+ lua_createtable (L, res->len, 0);
for (i = 0; i < res->len; i ++) {
w = &g_array_index (res, rspamd_ftok_t, i);
@@ -992,12 +992,12 @@ lua_util_parse_addr (lua_State *L)
}
else {
cnt = internet_address_list_length (ia);
- lua_newtable (L);
+ lua_createtable (L, cnt, 0);
for (i = 0; i < cnt; i ++) {
addr = internet_address_list_get_address (ia, i);
- lua_newtable (L);
+ lua_createtable (L, 0, 2);
lua_pushstring (L, "name");
lua_pushstring (L, internet_address_get_name (addr));
lua_settable (L, -3);
@@ -1147,7 +1147,7 @@ lua_util_glob (lua_State *L)
}
}
- lua_newtable (L);
+ lua_createtable (L, gl.gl_pathc, 0);
/* Push results */
for (i = 0; i < (gint)gl.gl_pathc; i ++) {
lua_pushstring (L, gl.gl_pathv[i]);