Skip to content

Commit

Permalink
mail-lua: Add deinit_pre function
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse committed Oct 3, 2018
1 parent 7c72577 commit cc7843b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/plugins/mail-lua/mail-lua-plugin.c
Expand Up @@ -11,6 +11,7 @@
#define MAIL_LUA_SCRIPT "mail_lua_script"
#define MAIL_LUA_USER_CREATED_FN "mail_user_created"
#define MAIL_LUA_USER_DEINIT_FN "mail_user_deinit"
#define MAIL_LUA_USER_DEINIT_PRE_FN "mail_user_deinit_pre"
#define MAIL_LUA_USER_CONTEXT(obj) \
MODULE_CONTEXT(obj, mail_lua_user_module)

Expand Down Expand Up @@ -57,6 +58,23 @@ static int mail_lua_call_hook(struct dlua_script *script,
return ret < 0 ? -1 : 1;
}

static void mail_lua_user_deinit_pre(struct mail_user *user)
{
struct mail_lua_user_context *luser = MAIL_LUA_USER_CONTEXT(user);
const char *error;
int ret;

if (luser == NULL)
return;

if ((ret = mail_lua_call_hook(luser->script, user, MAIL_LUA_USER_DEINIT_PRE_FN,
&error)) < 0) {
e_error(user->event, "mail-lua: %s", error);
}

luser->module_ctx.super.deinit_pre(user);
}

static void mail_lua_user_deinit(struct mail_user *user)
{
struct mail_lua_user_context *luser = MAIL_LUA_USER_CONTEXT(user);
Expand Down Expand Up @@ -116,6 +134,7 @@ static void mail_lua_user_created(struct mail_user *user)

luser = p_new(user->pool, struct mail_lua_user_context, 1);
luser->module_ctx.super = *v;
v->deinit_pre = mail_lua_user_deinit_pre;
v->deinit = mail_lua_user_deinit;
luser->script = script;
user->vlast = &luser->module_ctx.super;
Expand Down

0 comments on commit cc7843b

Please sign in to comment.