(struct dlua_passdb_module *)_module;
const char *error;
- if (dlua_script_create_file(module->file, &module->script, &error) < 0 ||
+ if (dlua_script_create_file(module->file, &module->script, auth_event, &error) < 0 ||
auth_lua_script_init(module->script, &error) < 0)
i_fatal("passdb-lua: initialization failed: %s", error);
module->has_password_verify =
test_begin("auth db lua passdb_verify");
- test_assert(dlua_script_create_string(luascript, &script, &error) == 0);
+ test_assert(dlua_script_create_string(luascript, &script, NULL, &error) == 0);
test_assert(auth_lua_script_init(script, &error) == 0);
if (script != NULL) {
test_assert(auth_lua_call_password_verify(script, req, "password", &error) == 1);
test_begin("auth db lua passdb_lookup");
- test_assert(dlua_script_create_string(luascript, &script, &error) == 0);
+ test_assert(dlua_script_create_string(luascript, &script, NULL, &error) == 0);
test_assert(auth_lua_script_init(script, &error) == 0);
if (script != NULL) {
test_assert(auth_lua_call_passdb_lookup(script, req, &scheme, &pass, &error) == 1);
(struct dlua_userdb_module *)_module;
const char *error;
- if (dlua_script_create_file(module->file, &module->script, &error) < 0 ||
+ if (dlua_script_create_file(module->file, &module->script, auth_event, &error) < 0 ||
auth_lua_script_init(module->script, &error) < 0)
i_fatal("userdb-lua: initialization failed: %s", error);
}
lua_State *L;
+ struct event *event;
const char *filename;
struct istream *in;
ssize_t last_read;
} v;
};
+extern struct event_category event_category_lua;
+
/* Get dlua_script from lua_State */
struct dlua_script *dlua_script_from_state(lua_State *L);
#define LUA_SCRIPT_INIT_FN "script_init"
#define LUA_SCRIPT_DEINIT_FN "script_deinit"
+struct event_category event_category_lua = {
+ .name = "lua",
+};
+
static struct dlua_script *dlua_scripts = NULL;
static const char *dlua_errstr(int err)
return ret;
}
-static struct dlua_script *dlua_create_script(const char *name)
+static struct dlua_script *dlua_create_script(const char *name,
+ struct event *event_parent)
{
pool_t pool = pool_allocfree_create(t_strdup_printf("lua script %s", name));
struct dlua_script *script = p_new(pool, struct dlua_script, 1);
i_assert(script->L != NULL);
script->ref = 1;
luaL_openlibs(script->L);
+ script->event = event_create(event_parent);
+ event_add_category(script->event, &event_category_lua);
return script;
}
return -1;
}
+ event_add_str(script->event, "script", script->filename);
DLLIST_PREPEND(&dlua_scripts, script);
*script_r = script;
}
int dlua_script_create_string(const char *str, struct dlua_script **script_r,
- const char **error_r)
+ struct event *event_parent, const char **error_r)
{
struct dlua_script *script;
int err;
return 0;
}
- script = dlua_create_script(fn);
+ script = dlua_create_script(fn, event_parent);
if ((err = luaL_loadstring(script->L, str)) != 0) {
*error_r = t_strdup_printf("lua_load(<string>) failed: %s",
dlua_errstr(err));
}
int dlua_script_create_file(const char *file, struct dlua_script **script_r,
- const char **error_r)
+ struct event *event_parent, const char **error_r)
{
struct dlua_script *script;
int err;
return -1;
}
- script = dlua_create_script(file);
+ script = dlua_create_script(file, event_parent);
if ((err = luaL_loadfile(script->L, file)) != 0) {
*error_r = t_strdup_printf("lua_load(%s) failed: %s",
file, dlua_errstr(err));
}
int dlua_script_create_stream(struct istream *is, struct dlua_script **script_r,
- const char **error_r)
+ struct event *event_parent, const char **error_r)
{
struct dlua_script *script;
const char *filename = i_stream_get_name(is);
return 0;
}
- script = dlua_create_script(filename);
+ script = dlua_create_script(filename, event_parent);
script->in = is;
script->filename = p_strdup(script->pool, filename);
if ((err = lua_load(script->L, dlua_reader, script, filename, 0)) < 0) {
/* remove from list */
DLLIST_REMOVE(&dlua_scripts, script);
+ event_unref(&script->event);
/* then just release memory */
pool_unref(&script->pool);
}
/* Parse and load a lua script. Will reuse an existing script
if found. */
int dlua_script_create_string(const char *str, struct dlua_script **script_r,
- const char **error_r);
+ struct event *event_parent, const char **error_r);
int dlua_script_create_file(const char *file, struct dlua_script **script_r,
- const char **error_r);
+ struct event *event_parent, const char **error_r);
/* Remember to set script name using i_stream_set_name */
int dlua_script_create_stream(struct istream *is, struct dlua_script **script_r,
- const char **error_r);
+ struct event *event_parent, const char **error_r);
/* run dlua_script_init function */
int dlua_script_init(struct dlua_script *script, const char **error_r);
test_begin("lua script");
- test_assert(dlua_script_create_string(luascript, &script, &error) == 0);
+ test_assert(dlua_script_create_string(luascript, &script, NULL, &error) == 0);
dlua_dovecot_register(script);
test_assert(dlua_script_init(script, &error) == 0);
test_assert(dlua_script_has_function(script, "lua_function"));
if (script_fn == NULL)
return;
- if (dlua_script_create_file(script_fn, &script, &error) < 0) {
+ if (dlua_script_create_file(script_fn, &script, user->event, &error) < 0) {
user->error = p_strdup_printf(user->pool, "dlua_script_create_file(%s) failed: %s",
script_fn, error);
return;
push_notification_driver_debug(DLUA_LOG_LABEL, user, "Loading %s", file);
- if (dlua_script_create_file(file, &ctx->script, error_r) < 0) {
+ if (dlua_script_create_file(file, &ctx->script, NULL, error_r) < 0) {
/* there is a T_POP after this, which will break errors */
*error_r = p_strdup(pool, *error_r);
return -1;