Ver código fonte

Fix headers operation in lua_task.

tags/1.0.5
Vsevolod Stakhov 8 anos atrás
pai
commit
05e5995e15
1 arquivos alterados com 12 adições e 8 exclusões
  1. 12
    8
      src/lua/lua_task.c

+ 12
- 8
src/lua/lua_task.c Ver arquivo

static gint static gint
lua_task_get_request_header (lua_State *L) 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); struct rspamd_task *task = lua_check_task (L, 1);
const gchar *s; const gchar *s;
struct rspamd_lua_text *t; struct rspamd_lua_text *t;
s = luaL_checklstring (L, 2, &len); s = luaL_checklstring (L, 2, &len);


if (s) { if (s) {
srch.str = (gchar *)s;
srch.begin = (gchar *)s;
srch.len = len; srch.len = len;


hdr = g_hash_table_lookup (task->request_headers, &srch); hdr = g_hash_table_lookup (task->request_headers, &srch);
if (hdr) { if (hdr) {
t = lua_newuserdata (L, sizeof (*t)); t = lua_newuserdata (L, sizeof (*t));
rspamd_lua_setclass (L, "rspamd{text}", -1); rspamd_lua_setclass (L, "rspamd{text}", -1);
t->start = hdr->str;
t->start = hdr->begin;
t->len = hdr->len; t->len = hdr->len;
t->own = FALSE; t->own = FALSE;


{ {
struct rspamd_task *task = lua_check_task (L, 1); struct rspamd_task *task = lua_check_task (L, 1);
const gchar *s, *v = NULL; const gchar *s, *v = NULL;
rspamd_fstring_t *buf;
struct rspamd_lua_text *t; struct rspamd_lua_text *t;
GString *hdr, srch, *new_name;
rspamd_ftok_t *hdr, srch, *new_name;
gsize len, vlen; gsize len, vlen;


s = luaL_checklstring (L, 2, &len); s = luaL_checklstring (L, 2, &len);
} }


if (v != NULL) { if (v != NULL) {
srch.str = (gchar *)s;
srch.begin = (gchar *)s;
srch.len = len; srch.len = len;


hdr = g_hash_table_lookup (task->request_headers, &srch); hdr = g_hash_table_lookup (task->request_headers, &srch);


if (hdr) {
if (!hdr) {
new_name = &srch; new_name = &srch;
} }
else { else {
/* Not found, need to allocate */ /* 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 */ /* This does not destroy key if it exists */
g_hash_table_insert (task->request_headers, new_name, hdr); g_hash_table_insert (task->request_headers, new_name, hdr);

Carregando…
Cancelar
Salvar