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);
/* 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));
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;
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);
}
}