text_part->utf_raw_content->len);
if (lua_pcall (L, 1, 1, err_idx) != 0) {
- GString *tb;
-
- tb = lua_touserdata (L, -1);
- msg_err_task ("cannot call lua lua_ical.ical_txt_values: %s", tb->str);
- g_string_free (tb, TRUE);
+ msg_err_task ("cannot call lua lua_ical.ical_txt_values: %s",
+ lua_tostring (L, -1));
lua_settop (L, err_idx - 1);
return FALSE;
}
else if (mime_atom->type == MIME_ATOM_LOCAL_LUA_FUNCTION) {
gint err_idx;
- GString *tb;
L = task->cfg->lua_state;
lua_pushcfunction (L, &rspamd_lua_traceback);
rspamd_lua_task_push (L, task);
if (lua_pcall (L, 1, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_info_task ("lua call to local function for atom '%s' failed: %v",
+ msg_info_task ("lua call to local function for atom '%s' failed: %s",
mime_atom->str,
- tb);
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ lua_tostring (L, -1));
}
else {
if (lua_type (L, -1) == LUA_TBOOLEAN) {
ucl_object_tostring (obj));
gchar *cur_dir, *lua_dir, *lua_file, *tmp1, *tmp2;
lua_State *L = cfg->lua_state;
- GString *tb;
gint err_idx;
tmp1 = g_strdup (lua_src);
/* Now do it */
if (lua_pcall (L, 0, 0, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"cannot init lua file %s: %s",
lua_src,
- tb->str);
- g_string_free (tb, TRUE);
- lua_pop (L, 2);
+ lua_tostring (L, -1));
+ lua_settop (L, 0);
if (chdir (cur_dir) == -1) {
msg_err_config ("cannot chdir to %s: %s", cur_dir,
const gchar *lua_script;
gsize slen;
gint err_idx, ref_idx;
- GString *tb = NULL;
lua_script = ucl_object_tolstring (cur, &slen);
L = cfg->lua_state;
/* Now do it */
if (lua_pcall (L, 0, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"cannot init lua condition script: %s",
- tb->str);
- g_string_free (tb, TRUE);
+ lua_tostring (L, -1));
lua_settop (L, 0);
return FALSE;
{
lua_State *L = cfg->lua_state;
gint err_idx, ret;
- GString *tb;
gchar str[PATH_MAX];
static const char *transform_script = "lua_cfg_transform";
ucl_object_push_lua (L, cfg->rcl_obj, true);
if ((ret = lua_pcall (L, 1, 2, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err ("call to rspamadm lua script failed (%d): %v", ret, tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
-
+ msg_err ("call to rspamadm lua script failed (%d): %v", ret,
+ lua_tostring (L, -1));
lua_settop (L, 0);
return;
lua_pushboolean (L, false);
if (lua_pcall (L, 3, 1, err_idx) != 0) {
- GString *tb;
-
- tb = lua_touserdata (L, -1);
- msg_err_config ("cannot call lua jinja_template script: %s", tb->str);
- g_string_free (tb, TRUE);
+ msg_err_config ("cannot call lua jinja_template script: %s",
+ lua_tostring (L, -1));
lua_settop (L, err_idx - 1);
return false;
rspamd_lua_setclass (L, "rspamd{config}", -1);
if (lua_pcall (L, 1, 0, err_idx) != 0) {
- GString *tb;
-
- tb = lua_touserdata (L, -1);
msg_err_config ("cannot call lua init_debug_logging script: %s",
- tb->str);
- g_string_free (tb, TRUE);
+ lua_tostring (L, -1));
lua_settop (L, err_idx - 1);
return FALSE;
if (rspamd_lua_require_function (cfg->lua_state, "lua_squeeze_rules",
"squeeze_init")) {
if (lua_pcall (L, 0, 0, err_idx) != 0) {
- GString *tb = lua_touserdata (L, -1);
- msg_err_config ("call to squeeze_init script failed: %v", tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ msg_err_config ("call to squeeze_init script failed: %s",
+ lua_tostring (L, -1));
}
}
khiter_t k;
lua_State *L;
gint err_idx, ret;
- GString *tb;
struct rspamd_task **ptask;
gboolean result = FALSE;
struct rspamd_re_cache *cache = rt->cache;
rspamd_lua_setclass (L, "rspamd{task}", -1);
if ((ret = lua_pcall (L, 1, 1, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_task ("call to selector %s "
- "failed (%d): %v", name, ret, tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ "failed (%d): %s", name, ret,
+ lua_tostring (L, -1));
}
else {
gsize slen;
struct rspamd_statfile_config *stcf;
lua_State *L = NULL;
struct rspamd_task **ptask;
- GString *tb;
const gchar *rcpt = NULL;
gint err_idx;
rspamd_lua_setclass (L, "rspamd{task}", -1);
if (lua_pcall (L, 1, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err_task ("call to user extraction script failed: %v", tb);
- g_string_free (tb, TRUE);
+ msg_err_task ("call to user extraction script failed: %s",
+ lua_tostring (L, -1));
}
else {
rcpt = rspamd_mempool_strdup (task->task_pool, lua_tostring (L, -1));
}
/* Result + error function */
- lua_pop (L, 2);
+ lua_settop (L, err_idx - 1);
}
if (rcpt) {
const gchar *user = NULL;
struct rspamd_task **ptask;
lua_State *L = db->L;
- GString *tb;
if (db->cbref_user == -1) {
user = rspamd_task_get_principal_recipient (task);
rspamd_lua_setclass (L, "rspamd{task}", -1);
if (lua_pcall (L, 1, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err_task ("call to user extraction script failed: %v", tb);
- g_string_free (tb, TRUE);
+ msg_err_task ("call to user extraction script failed: %s",
+ lua_tostring (L, -1));
}
else {
user = rspamd_mempool_strdup (task->task_pool, lua_tostring (L, -1));
}
/* Result + error function */
- lua_pop (L, 2);
+ lua_settop (L, err_idx - 1);
}
struct rspamd_mime_text_part *tp;
struct rspamd_task **ptask;
lua_State *L = db->L;
- GString *tb;
if (db->cbref_language == -1) {
for (i = 0; i < task->text_parts->len; i++) {
rspamd_lua_setclass (L, "rspamd{task}", -1);
if (lua_pcall (L, 1, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err_task ("call to language extraction script failed: %v", tb);
- g_string_free (tb, TRUE);
+ msg_err_task ("call to language extraction script failed: %s",
+ lua_tostring (L, -1));
}
else {
language = rspamd_mempool_strdup (task->task_pool,
}
/* Result + error function */
- lua_pop (L, 2);
+ lua_settop (L, err_idx - 1);
}
else {
/* Call this function to obtain closure */
gint err_idx, ret;
- GString *tb;
struct rspamd_config **pcfg;
lua_pushcfunction (L, &rspamd_lua_traceback);
rspamd_lua_setclass (L, "rspamd{config}", -1);
if ((ret = lua_pcall (L, 1, 1, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_config ("call to gen_stat_tokens lua "
- "script failed (%d): %v", ret, tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ "script failed (%d): %s", ret,
+ lua_tostring (L, -1));
}
else {
if (lua_type (L, -1) != LUA_TFUNCTION) {
if (st_ctx->lua_stat_tokens_ref != -1) {
gint err_idx, ret;
- GString *tb;
struct rspamd_task **ptask;
lua_pushcfunction (L, &rspamd_lua_traceback);
rspamd_lua_setclass (L, "rspamd{task}", -1);
if ((ret = lua_pcall (L, 1, 1, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_task ("call to stat_tokens lua "
- "script failed (%d): %v", ret, tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ "script failed (%d): %s", ret, lua_tostring (L, -1));
}
else {
if (lua_type (L, -1) != LUA_TTABLE) {
struct rspamd_metric_result *mres = NULL;
struct rspamd_task **ptask;
lua_State *L;
- GString *tb;
guint i;
gint err_idx;
gboolean ret = FALSE;
rspamd_lua_setclass (L, "rspamd{task}", -1);
if (lua_pcall (L, 1, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_task ("call to autolearn script failed: "
- "%v", tb);
- g_string_free (tb, TRUE);
+ "%s", lua_tostring (L, -1));
}
else {
lua_ret = lua_tostring (L, -1);
}
if (ret && lua_pcall (L, 0, 1, err_idx) != 0) {
- GString *tb = lua_touserdata (L, -1);
g_set_error (err, g_quark_from_static_string ("lua_env"), errno,
"cannot init lua file %s: %s",
fname,
- tb->str);
- g_string_free (tb, TRUE);
-
+ lua_tostring (L, -1));
ret = FALSE;
}
GList *cur;
struct script_module *module;
lua_State *L = cfg->lua_state;
- GString *tb;
gint err_idx;
cur = g_list_first (cfg->script_modules);
lua_setglobal (L, "rspamd_config");
if (lua_pcall (L, 0, 0, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err_config ("init of %s failed: %v",
+ msg_err_config ("init of %s failed: %s",
module->path,
- tb);
-
- g_string_free (tb, TRUE);
- lua_pop (L, 2); /* Result and error function */
+ lua_tostring (L, -1));
+ lua_settop (L, err_idx - 1);
rspamd_plugins_table_push_elt (L, "disabled_failed",
module->name);
}
static void
-rspamd_lua_traceback_string (lua_State *L, GString *s)
+rspamd_lua_traceback_string (lua_State *L, luaL_Buffer *buf)
{
- gint i = 1;
+ gint i = 1, r;
lua_Debug d;
+ gchar tmp[256];
while (lua_getstack (L, i++, &d)) {
lua_getinfo (L, "nSl", &d);
- g_string_append_printf (s, " [%d]:{%s:%d - %s [%s]};",
+ r = rspamd_snprintf (tmp, sizeof (tmp), " [%d]:{%s:%d - %s [%s]};",
i - 1, d.short_src, d.currentline,
(d.name ? d.name : "<unknown>"), d.what);
+ luaL_addlstring (buf, tmp, r);
}
}
gint
rspamd_lua_traceback (lua_State *L)
{
+ luaL_Buffer b;
- GString *tb;
-
- tb = rspamd_lua_get_traceback_string (L);
-
- lua_pushlightuserdata (L, tb);
+ luaL_buffinit (L, &b);
+ rspamd_lua_get_traceback_string (L, &b);
+ luaL_pushresult (&b);
return 1;
}
-GString *
-rspamd_lua_get_traceback_string (lua_State *L)
+void
+rspamd_lua_get_traceback_string (lua_State *L, luaL_Buffer *buf)
{
- GString *tb;
const gchar *msg = lua_tostring (L, -1);
- tb = g_string_sized_new (100);
- g_string_append_printf (tb, "%s; trace:", msg);
-
- rspamd_lua_traceback_string (L, tb);
-
- return tb;
+ luaL_addstring (buf, msg);
+ luaL_addstring (buf, "; trace:");
+ rspamd_lua_traceback_string (L, buf);
}
guint
gboolean fatal)
{
void *p = lua_touserdata (L, pos);
- GString *err_msg;
guint i, top = lua_gettop (L);
if (p == NULL) {
actual_classname = lua_typename (L, lua_type (L, pos));
}
- err_msg = g_string_sized_new (100);
- rspamd_printf_gstring (err_msg, "expected %s at position %d, but userdata has "
- "%s metatable; trace: ",
+ luaL_Buffer buf;
+ gchar tmp[512];
+ gint r;
+
+ luaL_buffinit (L, &buf);
+ r = rspamd_snprintf (tmp, sizeof (tmp),
+ "expected %s at position %d, but userdata has "
+ "%s metatable; trace: ",
classname, pos, actual_classname);
- rspamd_lua_traceback_string (L, err_msg);
- rspamd_printf_gstring (err_msg, " stack(%d): ", top);
+ luaL_addlstring (&buf, tmp, r);
+ rspamd_lua_traceback_string (L, &buf);
+ r = rspamd_snprintf (tmp, sizeof (tmp), " stack(%d): ", top);
+ luaL_addlstring (&buf, tmp, r);
for (i = 1; i <= MIN (top, 10); i ++) {
if (lua_type (L, i) == LUA_TUSERDATA) {
clsname = lua_typename (L, lua_type (L, i));
}
- rspamd_printf_gstring (err_msg, "[%d: ud=%s] ", i,
+ r = rspamd_snprintf (tmp, sizeof (tmp), "[%d: ud=%s] ", i,
clsname);
+ luaL_addlstring (&buf, tmp, r);
}
else {
- rspamd_printf_gstring (err_msg, "[%d: %s] ", i,
+ r = rspamd_snprintf (tmp, sizeof (tmp), "[%d: %s] ", i,
lua_typename (L, lua_type (L, i)));
+ luaL_addlstring (&buf, tmp, r);
}
}
- msg_err ("lua type error: %v", err_msg);
- g_string_free (err_msg, TRUE);
+ luaL_pushresult (&buf);
+ msg_err ("lua type error: %s", lua_tostring (L, -1));
}
lua_settop (L, top);
lua_pushboolean (L, false); /* no_fallback */
if (lua_pcall (L, 3, 1, err_idx) != 0) {
- GString *tb;
-
- tb = lua_touserdata (L, -1);
- msg_err_config ("cannot call lua try_load_redis_servers script: %s", tb->str);
- g_string_free (tb, TRUE);
+ msg_err_config ("cannot call lua try_load_redis_servers script: %s",
+ lua_tostring (L, -1));
lua_settop (L, 0);
return FALSE;
* @param L
* @return
*/
-GString *
-rspamd_lua_get_traceback_string (lua_State *L);
+void rspamd_lua_get_traceback_string (lua_State *L, luaL_Buffer *buf);
/**
* Returns size of table at position `tbl_pos`
struct rspamd_task **ptask;
gint level = lua_gettop (cd->L), nresults, err_idx, ret;
lua_State *L = cd->L;
- GString *tb;
struct rspamd_symbol_result *s;
cd->item = item;
*ptask = task;
if ((ret = lua_pcall (L, 1, LUA_MULTRET, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err_task ("call to (%s) failed (%d): %v", cd->symbol, ret, tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- lua_pop (L, 1);
- }
+ msg_err_task ("call to (%s) failed (%d): %s", cd->symbol, ret,
+ lua_tostring (L, -1));
+ lua_settop (L, err_idx); /* Not -1 here, as err_func is popped below */
}
else {
nresults = lua_gettop (L) - level;
/* Now call for squeeze function */
if (lua_pcall (L, 2, 1, err_idx) != 0) {
- GString *tb = lua_touserdata (L, -1);
- msg_err_config ("call to squeeze_virtual failed: %v", tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ msg_err_config ("call to squeeze_virtual failed: %s",
+ lua_tostring (L, -1));
}
ret = lua_tonumber (L, -1);
/* Now call for squeeze function */
if (lua_pcall (L, 3, 1, err_idx) != 0) {
- GString *tb = lua_touserdata (L, -1);
- msg_err_config ("call to squeeze_rule failed: %v", tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ msg_err_config ("call to squeeze_rule failed: %s",
+ lua_tostring (L, -1));
}
ret = lua_tonumber (L, -1);
lua_pushstring (L, parent);
if (lua_pcall (L, 2, 1, err_idx) != 0) {
- GString *tb = lua_touserdata (L, -1);
- msg_err_config ("call to squeeze_dependency script failed: %v", tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ msg_err_config ("call to squeeze_dependency script failed: %s",
+ lua_tostring (L, -1));
}
else {
ret = lua_toboolean (L, -1);
struct rspamd_lua_include_trace_cbdata *cbdata =
(struct rspamd_lua_include_trace_cbdata *)user_data;
gint err_idx;
- GString *tb;
lua_State *L;
L = cbdata->L;
}
if (lua_pcall (L, 4, 0, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err ("lua call to local include trace failed: %v", tb);
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ msg_err ("lua call to local include trace failed: %s", lua_tostring (L, -1));
}
lua_settop (L, err_idx - 1);
}
else {
gint err_idx, ret;
- GString *tb;
struct rspamd_config **pcfg;
lua_pushcfunction (L, &rspamd_lua_traceback);
lua_pushstring (L, delimiter);
if ((ret = lua_pcall (L, 3, 1, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_config ("call to create_selector_closure lua "
- "script failed (%d): %v", ret, tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ "script failed (%d): %s", ret,
+ lua_tostring (L, -1));
}
else {
if (lua_type (L, -1) != LUA_TFUNCTION) {
struct lua_callback_state cbs;
rspamd_mempool_t *pool;
gint err_idx;
- GString *tb = NULL;
pool = cd->pool;
lua_thread_pool_prepare_callback (cd->resolver->cfg->lua_thread_pool, &cbs);
}
if (lua_pcall (L, 7, 0, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
-
- if (tb) {
- msg_err_pool_check ("call to dns callback failed: %s", tb->str);
- g_string_free (tb, TRUE);
- }
+ msg_err_pool_check ("call to dns callback failed: %s",
+ lua_tostring (L, -1));
}
lua_settop (L, err_idx - 1);
}
if (lua_pcall (pd->L, nargs, 1, err_idx) != 0) {
- GString *tb = lua_touserdata (pd->L, -1);
- msg_info ("expression process callback failed: %s", tb->str);
- g_string_free (tb, TRUE);
+ msg_info ("expression process callback failed: %s", lua_tostring (pd->L, -1));
}
else {
ret = lua_tonumber (pd->L, -1);
rspamd_lua_push_full_word (L, tok);
if (lua_pcall (L, 1, 0, err_idx) != 0) {
- GString *tb = lua_touserdata (L, -1);
msg_err_task ("cannot call callback function for lookup words: %s",
- tb->str);
- g_string_free (tb, TRUE);
+ lua_tostring (L, -1));
}
lua_settop (L, err_idx - 1);
{
gint ret;
struct lua_thread_pool *pool;
- GString *tb;
struct rspamd_task *task;
msg_debug_lua_threads ("%s: lua_resume_thread_internal_full", loc);
else {
pool = thread_entry->cfg->lua_thread_pool;
}
+
if (ret == 0) {
if (thread_entry->finish_callback) {
thread_entry->finish_callback (thread_entry, ret);
lua_thread_pool_return_full (pool, thread_entry, loc);
}
else {
- tb = rspamd_lua_get_traceback_string (thread_entry->lua_state);
- if (tb && thread_entry->error_callback) {
- thread_entry->error_callback (thread_entry, ret, tb->str);
+ rspamd_lua_traceback (thread_entry->lua_state);
+ if (thread_entry->error_callback) {
+ thread_entry->error_callback (thread_entry, ret,
+ lua_tostring (thread_entry->lua_state, -1));
}
else if (thread_entry->task) {
task = thread_entry->task;
- msg_err_task ("lua call failed (%d): %v", ret, tb);
+ msg_err_task ("lua call failed (%d): %s", ret,
+ lua_tostring (thread_entry->lua_state, -1));
}
else {
- msg_err ("lua call failed (%d): %v", ret, tb);
+ msg_err ("lua call failed (%d): %s", ret,
+ lua_tostring (thread_entry->lua_state, -1));
}
- if (tb) {
- g_string_free (tb, TRUE);
- }
/*
* Maybe there is a way to recover here.
* For now, just remove faulty thread
lua_pushinteger (L, cur_errors);
if (lua_pcall (L, 3, 0, err_idx) != 0) {
- GString *tb = lua_touserdata (L, -1);
- msg_err ("cannot call watch function for upstream: %s", tb->str);
- g_string_free (tb, TRUE);
+ msg_err ("cannot call watch function for upstream: %s", lua_tostring (L, -1));
lua_settop (L, 0);
return;
struct rspamd_lua_process_cbdata *cbdata)
{
gint err_idx, r;
- GString *tb;
guint64 wlen = 0;
const gchar *ret;
gsize retlen;
lua_rawgeti (L, LUA_REGISTRYINDEX, cbdata->func_cbref);
if (lua_pcall (L, 0, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err ("call to subprocess failed: %v", tb);
+ const gchar *s = lua_tostring (L, -1);
+ gsize slen = strlen (s);
+
+ msg_err ("call to subprocess failed: %s", s);
/* Indicate error */
- wlen = (1ULL << 63) + tb->len;
+ wlen = (1ULL << 63u) + slen;
r = write (cbdata->sp[1], &wlen, sizeof (wlen));
if (r == -1) {
msg_err ("write failed: %s", strerror (errno));
}
- r = write (cbdata->sp[1], tb->str, tb->len);
+ r = write (cbdata->sp[1], s, slen);
if (r == -1) {
msg_err ("write failed: %s", strerror (errno));
}
- g_string_free (tb, TRUE);
-
- lua_pop (L, 1);
}
else {
ret = lua_tolstring (L, -1, &retlen);
}
}
- lua_pop (L, 1); /* Error function */
+ lua_settop (L, err_idx - 1);
}
static void
const gchar *data, gsize datalen)
{
gint err_idx;
- GString *tb;
lua_pushcfunction (L, &rspamd_lua_traceback);
err_idx = lua_gettop (L);
}
if (lua_pcall (L, 2, 0, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err ("call to subprocess callback script failed: %v", tb);
- lua_pop (L, 1);
+ msg_err ("call to on_complete script failed: %s",
+ lua_tostring (L, -1));
}
- lua_pop (L, 1); /* Error function */
+ lua_settop (L, err_idx - 1);
}
static gboolean
gint err_idx;
gint64 arc_idx = 0;
gsize len;
- GString *tb, *hdr;
+ GString *hdr;
GList *sigs = NULL;
GError *err = NULL;
const gchar *selector = NULL, *domain = NULL, *key = NULL, *key_type = NULL,
rspamd_lua_setclass (L, "rspamd{task}", -1);
if (lua_pcall (L, 1, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err_task ("call to user extraction script failed: %v", tb);
- g_string_free (tb, TRUE);
+ msg_err_task ("call to user extraction script failed: %s",
+ lua_tostring (L, -1));
}
else {
if (lua_istable (L, -1)) {
* Process rule in Lua
*/
gint err_idx, ret;
- GString *tb;
lua_State *L = (lua_State *)cfg->lua_state;
lua_pushcfunction (L, &rspamd_lua_traceback);
ucl_object_push_lua (L, obj, true);
if ((ret = lua_pcall (L, 1, 1, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_config ("call to process_rule lua "
- "script failed (%d): %v", ret, tb);
+ "script failed (%d): %s", ret, lua_tostring (L, -1));
- if (tb) {
- g_string_free (tb, TRUE);
- }
rule->lua_id = -1;
}
else {
if (fuzzy_module_ctx->cleanup_rules_ref != -1) {
/* Sync lua_fuzzy rules */
gint err_idx, ret;
- GString *tb;
lua_State *L = (lua_State *)cfg->lua_state;
lua_pushcfunction (L, &rspamd_lua_traceback);
lua_rawgeti (L, LUA_REGISTRYINDEX, fuzzy_module_ctx->cleanup_rules_ref);
if ((ret = lua_pcall (L, 0, 0, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_config ("call to cleanup_rules lua "
- "script failed (%d): %v", ret, tb);
-
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ "script failed (%d): %s", ret, lua_tostring (L, -1));
}
luaL_unref (cfg->lua_state, LUA_REGISTRYINDEX,
{
if (rule->lua_id != -1 && rule->ctx->check_mime_part_ref != -1) {
gint err_idx, ret;
- GString *tb;
lua_State *L = (lua_State *)task->cfg->lua_state;
struct rspamd_task **ptask;
struct rspamd_mime_part **ppart;
lua_pushnumber (L, rule->lua_id);
if ((ret = lua_pcall (L, 3, 2, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_task ("call to check_mime_part lua "
- "script failed (%d): %v", ret, tb);
+ "script failed (%d): %s", ret, lua_tostring (L, -1));
- if (tb) {
- g_string_free (tb, TRUE);
- }
ret = FALSE;
}
else {
guint i;
GError **err;
GPtrArray *commands;
- GString *tb;
lua_State *L;
gint r, *saved, rules = 0, err_idx;
struct fuzzy_ctx *fuzzy_module_ctx;
rspamd_lua_setclass (L, "rspamd{task}", -1);
if (lua_pcall (L, 1, LUA_MULTRET, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err_task ("call to user extraction script failed: %v", tb);
- g_string_free (tb, TRUE);
+ msg_err_task ("call to fuzzy learn condition failed: %s",
+ lua_tostring (L, -1));
}
else {
if (lua_gettop (L) > err_idx + 1) {
if (loaded) {
if (lua_pcall (L, 0, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err_config ("call failed: %v\n", tb);
- g_string_free (tb, TRUE);
+ msg_err_config ("call failed: %s\n", lua_tostring (L, -1));
}
else if (lua_isfunction (L, -1)) {
new_suffix->url_process_cbref = luaL_ref (L,
const gchar *lua_script;
gsize slen;
gint err_idx, ref_idx;
- GString *tb = NULL;
gboolean has_ref = FALSE;
g_assert (obj != NULL);
/* Now do it */
if (lua_pcall (L, 0, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
g_set_error (err,
rspamd_proxy_quark (),
EINVAL,
"cannot init lua parser script: %s",
- tb->str);
- g_string_free (tb, TRUE);
+ lua_tostring (L, -1));
lua_settop (L, 0);
return FALSE;
const gchar *lua_script;
gsize slen;
gint err_idx, ref_idx;
- GString *tb = NULL;
struct stat st;
ctx = pd->user_struct;
/* Now do it */
if (lua_pcall (L, 0, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
g_set_error (err,
rspamd_proxy_quark (),
EINVAL,
"cannot init lua parser script: %s",
- tb->str);
- g_string_free (tb, TRUE);
+ lua_tostring (L, -1));
lua_settop (L, 0);
goto err;
const gchar *in, gsize inlen)
{
struct ucl_parser *parser;
- GString *tb = NULL;
gint err_idx;
if (inlen == 0 || in == NULL) {
lua_pushlstring (L, in, inlen);
if (lua_pcall (L, 1, 1, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_session (
"cannot run lua parser script: %s",
- tb->str);
- g_string_free (tb, TRUE);
+ lua_tostring (L, -1));
lua_settop (L, 0);
return FALSE;
static void
proxy_call_cmp_script (struct rspamd_proxy_session *session, gint cbref)
{
- GString *tb = NULL;
gint err_idx;
guint i;
struct rspamd_proxy_backend_connection *conn;
}
if (lua_pcall (L, 1, 0, err_idx) != 0) {
- tb = lua_touserdata (L, -1);
msg_err_session (
"cannot run lua compare script: %s",
- tb->str);
- g_string_free (tb, TRUE);
+ lua_tostring (L, -1));
}
lua_settop (L, 0);