|
|
@@ -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); |