diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-07 13:25:49 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-07 13:25:49 +0100 |
commit | ee9def66ca6120fdaa9acc623b8c8e49b1b2ea93 (patch) | |
tree | 352737c37db34f0ff436808c1fb301b3cc5e4d5c | |
parent | 2a522e2a42bcb814e20b41206923f56e66b54c47 (diff) | |
download | rspamd-ee9def66ca6120fdaa9acc623b8c8e49b1b2ea93.tar.gz rspamd-ee9def66ca6120fdaa9acc623b8c8e49b1b2ea93.zip |
Fix lua_http.
-rw-r--r-- | src/libutil/map.c | 2 | ||||
-rw-r--r-- | src/lua/lua_http.c | 18 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/libutil/map.c b/src/libutil/map.c index cba82ba41..28faf13c4 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -111,7 +111,7 @@ write_http_request (struct http_callback_data *cbd) msg = rspamd_http_new_message (HTTP_REQUEST); - msg->url = g_string_new (cbd->data->path); + msg->url = rspamd_fstring_new_init (cbd->data->path, strlen (cbd->data->path)); if (cbd->data->last_checked != 0) { tm = gmtime (&cbd->data->last_checked); strftime (datebuf, sizeof (datebuf), "%a, %d %b %Y %H:%M:%S %Z", tm); diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index e87da02b1..bbea1ebce 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -168,7 +168,9 @@ lua_http_finish_handler (struct rspamd_http_connection *conn, /* Headers */ lua_newtable (cbd->L); LL_FOREACH (msg->headers, h) { - rspamd_lua_table_set (cbd->L, h->name->str, h->value->str); + lua_pushlstring (cbd->L, h->name->begin, h->name->len); + lua_pushlstring (cbd->L, h->value->begin, h->value->len); + lua_settable (cbd->L, -3); } if (lua_pcall (cbd->L, 4, 0, 0) != 0) { msg_info ("callback call failed: %s", lua_tostring (cbd->L, -1)); @@ -269,8 +271,9 @@ lua_http_push_headers (lua_State *L, struct rspamd_http_message *msg) static gint lua_http_request (lua_State *L) { - const gchar *url; + const gchar *url, *lua_body; gint cbref; + gsize bodylen; struct event_base *ev_base; struct rspamd_http_message *msg; struct lua_http_cbdata *cbd; @@ -403,17 +406,14 @@ lua_http_request (lua_State *L) lua_pushstring (L, "body"); lua_gettable (L, -2); if (lua_type (L, -1) == LUA_TSTRING) { - msg->body = g_string_new (lua_tostring (L, -1)); + lua_body = lua_tolstring (L, -1, &bodylen); + msg->body = rspamd_fstring_new_init (lua_body, bodylen); } else if (lua_type (L, -1) == LUA_TUSERDATA) { t = lua_check_text (L, -1); + /* TODO: think about zero-copy possibilities */ if (t) { - /* XXX: is it safe ? */ - msg->body = g_string_new (NULL); - msg->body->str = (gchar *)t->start; - msg->body->len = t->len; - /* It is not safe unless we set len to avoid body_buf to be freed */ - msg->body_buf.len = t->len; + msg->body = rspamd_fstring_new_init (t->start, t->len); } } |