From: Vsevolod Stakhov Date: Wed, 7 Oct 2015 15:38:12 +0000 (+0100) Subject: Fix headers operation in lua_task. X-Git-Tag: 1.0.5~66^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=05e5995e153e06943499b0b8bc09346cf3d302fe;p=rspamd.git Fix headers operation in lua_task. --- diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 4ef772a5c..3bc40efe4 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -963,7 +963,7 @@ lua_task_get_parts (lua_State * L) static gint lua_task_get_request_header (lua_State *L) { - GString *hdr, srch; + rspamd_ftok_t *hdr, srch; struct rspamd_task *task = lua_check_task (L, 1); const gchar *s; struct rspamd_lua_text *t; @@ -972,7 +972,7 @@ lua_task_get_request_header (lua_State *L) s = luaL_checklstring (L, 2, &len); if (s) { - srch.str = (gchar *)s; + srch.begin = (gchar *)s; srch.len = len; hdr = g_hash_table_lookup (task->request_headers, &srch); @@ -980,7 +980,7 @@ lua_task_get_request_header (lua_State *L) if (hdr) { t = lua_newuserdata (L, sizeof (*t)); rspamd_lua_setclass (L, "rspamd{text}", -1); - t->start = hdr->str; + t->start = hdr->begin; t->len = hdr->len; t->own = FALSE; @@ -997,8 +997,9 @@ lua_task_set_request_header (lua_State *L) { struct rspamd_task *task = lua_check_task (L, 1); const gchar *s, *v = NULL; + rspamd_fstring_t *buf; struct rspamd_lua_text *t; - GString *hdr, srch, *new_name; + rspamd_ftok_t *hdr, srch, *new_name; gsize len, vlen; s = luaL_checklstring (L, 2, &len); @@ -1017,19 +1018,22 @@ lua_task_set_request_header (lua_State *L) } if (v != NULL) { - srch.str = (gchar *)s; + srch.begin = (gchar *)s; srch.len = len; hdr = g_hash_table_lookup (task->request_headers, &srch); - if (hdr) { + if (!hdr) { new_name = &srch; } else { /* Not found, need to allocate */ - new_name = g_string_new_len (srch.str, srch.len); + buf = rspamd_fstring_new_init (srch.begin, srch.len); + new_name = rspamd_ftok_map (buf); } - hdr = g_string_new_len (v, vlen); + + buf = rspamd_fstring_new_init (v, vlen); + hdr = rspamd_ftok_map (buf); /* This does not destroy key if it exists */ g_hash_table_insert (task->request_headers, new_name, hdr);