push-notification-driver-lua.c (dovecot-2.3.16) | : | push-notification-driver-lua.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 255 | skipping to change at line 255 | |||
str_append_c(fn, (*evname) - 'A' + 'a'); | str_append_c(fn, (*evname) - 'A' + 'a'); | |||
} else { | } else { | |||
str_append_c(fn, *evname); | str_append_c(fn, *evname); | |||
} | } | |||
} | } | |||
return str_c(fn); | return str_c(fn); | |||
} | } | |||
/* Pushes lua list of flags */ | /* Pushes lua list of flags */ | |||
static void dlua_pushflags(struct dlua_script *script, enum mail_flags flags) | static void dlua_push_flags(struct dlua_script *script, enum mail_flags flags) | |||
{ | { | |||
lua_newtable(script->L); | lua_newtable(script->L); | |||
int idx = 1; | int idx = 1; | |||
if ((flags & MAIL_ANSWERED) != 0) { | if ((flags & MAIL_ANSWERED) != 0) { | |||
lua_pushliteral(script->L, "\\Answered"); | lua_pushliteral(script->L, "\\Answered"); | |||
lua_rawseti(script->L, -2, idx++); | lua_rawseti(script->L, -2, idx++); | |||
} | } | |||
if ((flags & MAIL_FLAGGED) != 0) { | if ((flags & MAIL_FLAGGED) != 0) { | |||
lua_pushliteral(script->L, "\\Flagged"); | lua_pushliteral(script->L, "\\Flagged"); | |||
skipping to change at line 287 | skipping to change at line 287 | |||
lua_pushliteral(script->L, "\\Draft"); | lua_pushliteral(script->L, "\\Draft"); | |||
lua_rawseti(script->L, -2, idx++); | lua_rawseti(script->L, -2, idx++); | |||
} | } | |||
if ((flags & MAIL_RECENT) != 0) { | if ((flags & MAIL_RECENT) != 0) { | |||
lua_pushliteral(script->L, "\\Recent"); | lua_pushliteral(script->L, "\\Recent"); | |||
lua_rawseti(script->L, -2, idx++); | lua_rawseti(script->L, -2, idx++); | |||
} | } | |||
} | } | |||
static void | static void | |||
dlua_pushkeywords(struct dlua_script *script, const char *const *keywords, | dlua_push_keywords(struct dlua_script *script, const char *const *keywords, | |||
unsigned int count) | unsigned int count) | |||
{ | { | |||
lua_newtable(script->L); | lua_newtable(script->L); | |||
if (keywords == NULL) | if (keywords == NULL) | |||
return; | return; | |||
for (unsigned int idx = 0; idx < count; idx++) { | for (unsigned int idx = 0; idx < count; idx++) { | |||
lua_pushstring(script->L, keywords[idx]); | lua_pushstring(script->L, keywords[idx]); | |||
lua_rawseti(script->L, -2, idx+1); | lua_rawseti(script->L, -2, idx+1); | |||
} | } | |||
} | } | |||
static void | static void | |||
push_notification_lua_push_flagsclear( | push_notification_lua_push_flagsclear( | |||
const struct push_notification_txn_event *event, | const struct push_notification_txn_event *event, | |||
struct dlua_script *script) | struct dlua_script *script) | |||
{ | { | |||
/* Push cleared flags */ | /* Push cleared flags */ | |||
unsigned int size = 0; | unsigned int size = 0; | |||
struct push_notification_event_flagsclear_data *data = event->data; | struct push_notification_event_flagsclear_data *data = event->data; | |||
dlua_pushflags(script, data->flags_clear); | dlua_push_flags(script, data->flags_clear); | |||
lua_setfield(script->L, -2, "flags"); | lua_setfield(script->L, -2, "flags"); | |||
dlua_pushflags(script, data->flags_old); | dlua_push_flags(script, data->flags_old); | |||
lua_setfield(script->L, -2, "flags_old"); | lua_setfield(script->L, -2, "flags_old"); | |||
if (array_is_created(&data->keywords_clear)) { | if (array_is_created(&data->keywords_clear)) { | |||
const char *const *kw = array_get(&data->keywords_clear, &size); | const char *const *kw = array_get(&data->keywords_clear, &size); | |||
dlua_pushkeywords(script, kw, size); | dlua_push_keywords(script, kw, size); | |||
lua_setfield(script->L, -2, "keywords"); | lua_setfield(script->L, -2, "keywords"); | |||
} | } | |||
if (array_is_created(&data->keywords_old)) { | if (array_is_created(&data->keywords_old)) { | |||
const char *const *kw = array_get(&data->keywords_old, &size); | const char *const *kw = array_get(&data->keywords_old, &size); | |||
dlua_pushkeywords(script, kw, size); | dlua_push_keywords(script, kw, size); | |||
lua_setfield(script->L, -2, "keywords_old"); | lua_setfield(script->L, -2, "keywords_old"); | |||
} | } | |||
} | } | |||
static void | static void | |||
push_notification_lua_push_flagsset( | push_notification_lua_push_flagsset( | |||
const struct push_notification_txn_event *event, | const struct push_notification_txn_event *event, | |||
struct dlua_script *script) | struct dlua_script *script) | |||
{ | { | |||
/* push set flags */ | /* push set flags */ | |||
unsigned int size = 0; | unsigned int size = 0; | |||
struct push_notification_event_flagsset_data *data = event->data; | struct push_notification_event_flagsset_data *data = event->data; | |||
dlua_pushflags(script, data->flags_set); | dlua_push_flags(script, data->flags_set); | |||
lua_setfield(script->L, -2, "flags"); | lua_setfield(script->L, -2, "flags"); | |||
if (array_is_created(&data->keywords_set)) { | if (array_is_created(&data->keywords_set)) { | |||
const char *const *kw = array_get(&data->keywords_set, &size); | const char *const *kw = array_get(&data->keywords_set, &size); | |||
dlua_pushkeywords(script, kw, size); | dlua_push_keywords(script, kw, size); | |||
lua_setfield(script->L, -2, "keywords"); | lua_setfield(script->L, -2, "keywords"); | |||
} | } | |||
} | } | |||
static void | static void | |||
push_notification_lua_push_mailboxrename( | push_notification_lua_push_mailboxrename( | |||
const struct push_notification_txn_event *event, | const struct push_notification_txn_event *event, | |||
struct dlua_script *script) | struct dlua_script *script) | |||
{ | { | |||
struct push_notification_event_mailboxrename_data *data = event->data; | struct push_notification_event_mailboxrename_data *data = event->data; | |||
lua_pushstring(script->L, data->old_mbox); | lua_pushstring(script->L, data->old_mbox); | |||
lua_setfield(script->L, -2, "mailbox_old"); | lua_setfield(script->L, -2, "mailbox_old"); | |||
} | } | |||
#define push_notification_lua_pushstring(L, value) \ | #define push_notification_lua_push_string(L, value) \ | |||
lua_pushstring((L), (value) == NULL ? "" : (value)) | lua_pushstring((L), (value) == NULL ? "" : (value)) | |||
static void | static void | |||
push_notification_lua_push_message_ext( | push_notification_lua_push_message_ext( | |||
const struct push_notification_message_ext *ext, | const struct push_notification_message_ext *ext, | |||
struct dlua_script *script) | struct dlua_script *script) | |||
{ | { | |||
push_notification_lua_pushstring(script->L, ext->from_address); | push_notification_lua_push_string(script->L, ext->from_address); | |||
lua_setfield(script->L, -2, "from_address"); | lua_setfield(script->L, -2, "from_address"); | |||
push_notification_lua_pushstring(script->L, ext->from_display_name_utf8); | push_notification_lua_push_string(script->L, ext->from_display_name_utf8) ; | |||
lua_setfield(script->L, -2, "from_display_name"); | lua_setfield(script->L, -2, "from_display_name"); | |||
push_notification_lua_pushstring(script->L, ext->to_address); | push_notification_lua_push_string(script->L, ext->to_address); | |||
lua_setfield(script->L, -2, "to_address"); | lua_setfield(script->L, -2, "to_address"); | |||
push_notification_lua_pushstring(script->L, ext->to_display_name_utf8); | push_notification_lua_push_string(script->L, ext->to_display_name_utf8); | |||
lua_setfield(script->L, -2, "to_display_name"); | lua_setfield(script->L, -2, "to_display_name"); | |||
lua_pushstring(script->L, ext->subject_utf8); | lua_pushstring(script->L, ext->subject_utf8); | |||
lua_setfield(script->L, -2, "subject"); | lua_setfield(script->L, -2, "subject"); | |||
} | } | |||
static void | static void | |||
push_notification_lua_push_messageappend( | push_notification_lua_push_messageappend( | |||
const struct push_notification_txn_event *event, | const struct push_notification_txn_event *event, | |||
struct dlua_script *script) | struct dlua_script *script) | |||
{ | { | |||
struct push_notification_event_messageappend_data *data = event->data; | struct push_notification_event_messageappend_data *data = event->data; | |||
lua_pushnumber(script->L, data->date); | lua_pushnumber(script->L, data->date); | |||
lua_setfield(script->L, -2, "date"); | lua_setfield(script->L, -2, "date"); | |||
lua_pushnumber(script->L, data->date_tz); | lua_pushnumber(script->L, data->date_tz); | |||
lua_setfield(script->L, -2, "tz"); | lua_setfield(script->L, -2, "tz"); | |||
push_notification_lua_pushstring(script->L, data->from); | push_notification_lua_push_string(script->L, data->from); | |||
lua_setfield(script->L, -2, "from"); | lua_setfield(script->L, -2, "from"); | |||
push_notification_lua_pushstring(script->L, data->to); | push_notification_lua_push_string(script->L, data->to); | |||
lua_setfield(script->L, -2, "to"); | lua_setfield(script->L, -2, "to"); | |||
lua_pushstring(script->L, data->snippet); | lua_pushstring(script->L, data->snippet); | |||
lua_setfield(script->L, -2, "snippet"); | lua_setfield(script->L, -2, "snippet"); | |||
dlua_pushflags(script, data->flags); | dlua_push_flags(script, data->flags); | |||
lua_setfield(script->L, -2, "flags"); | lua_setfield(script->L, -2, "flags"); | |||
dlua_pushkeywords(script, data->keywords, | dlua_push_keywords(script, data->keywords, | |||
str_array_length(data->keywords)); | str_array_length(data->keywords)); | |||
lua_setfield(script->L, -2, "keywords"); | lua_setfield(script->L, -2, "keywords"); | |||
lua_pushstring(script->L, data->message_id); | lua_pushstring(script->L, data->message_id); | |||
lua_setfield(script->L, -2, "message_id"); | lua_setfield(script->L, -2, "message_id"); | |||
push_notification_lua_push_message_ext(&data->ext, script); | push_notification_lua_push_message_ext(&data->ext, script); | |||
} | } | |||
static void | static void | |||
skipping to change at line 426 | skipping to change at line 426 | |||
struct dlua_script *script) | struct dlua_script *script) | |||
{ | { | |||
struct push_notification_event_messagenew_data *data = event->data; | struct push_notification_event_messagenew_data *data = event->data; | |||
lua_pushnumber(script->L, data->date); | lua_pushnumber(script->L, data->date); | |||
lua_setfield(script->L, -2, "date"); | lua_setfield(script->L, -2, "date"); | |||
lua_pushnumber(script->L, data->date_tz); | lua_pushnumber(script->L, data->date_tz); | |||
lua_setfield(script->L, -2, "tz"); | lua_setfield(script->L, -2, "tz"); | |||
push_notification_lua_pushstring(script->L, data->from); | push_notification_lua_push_string(script->L, data->from); | |||
lua_setfield(script->L, -2, "from"); | lua_setfield(script->L, -2, "from"); | |||
push_notification_lua_pushstring(script->L, data->to); | push_notification_lua_push_string(script->L, data->to); | |||
lua_setfield(script->L, -2, "to"); | lua_setfield(script->L, -2, "to"); | |||
lua_pushstring(script->L, data->snippet); | lua_pushstring(script->L, data->snippet); | |||
lua_setfield(script->L, -2, "snippet"); | lua_setfield(script->L, -2, "snippet"); | |||
dlua_pushflags(script, data->flags); | dlua_push_flags(script, data->flags); | |||
lua_setfield(script->L, -2, "flags"); | lua_setfield(script->L, -2, "flags"); | |||
dlua_pushkeywords(script, data->keywords, | dlua_push_keywords(script, data->keywords, | |||
str_array_length(data->keywords)); | str_array_length(data->keywords)); | |||
lua_setfield(script->L, -2, "keywords"); | lua_setfield(script->L, -2, "keywords"); | |||
lua_pushstring(script->L, data->message_id); | lua_pushstring(script->L, data->message_id); | |||
lua_setfield(script->L, -2, "message_id"); | lua_setfield(script->L, -2, "message_id"); | |||
push_notification_lua_push_message_ext(&data->ext, script); | push_notification_lua_push_message_ext(&data->ext, script); | |||
} | } | |||
/* Events that need special treatment */ | /* Events that need special treatment */ | |||
skipping to change at line 477 | skipping to change at line 477 | |||
.event_name = "MessageAppend", | .event_name = "MessageAppend", | |||
.push = push_notification_lua_push_messageappend | .push = push_notification_lua_push_messageappend | |||
}, | }, | |||
{ | { | |||
.event_name = "MessageNew", | .event_name = "MessageNew", | |||
.push = push_notification_lua_push_messagenew | .push = push_notification_lua_push_messagenew | |||
}, | }, | |||
}; | }; | |||
static void | static void | |||
push_notification_driver_lua_pushevent( | push_notification_driver_lua_push_event( | |||
const struct push_notification_txn_event *event, | const struct push_notification_txn_event *event, | |||
struct dlua_push_notification_context *ctx) | struct dlua_push_notification_context *ctx) | |||
{ | { | |||
struct dlua_script *script = ctx->script; | struct dlua_script *script = ctx->script; | |||
const char *name = event->event->event->name; | const char *name = event->event->event->name; | |||
/* Create a table */ | /* Create a table */ | |||
lua_newtable(script->L); | lua_newtable(script->L); | |||
/* Event name */ | /* Event name */ | |||
skipping to change at line 516 | skipping to change at line 516 | |||
push_notification_driver_lua_to_fn(event->event->event->name); | push_notification_driver_lua_to_fn(event->event->event->name); | |||
struct event *e = event_create(ctx->event); | struct event *e = event_create(ctx->event); | |||
event_set_name(e, DLUA_CALL_FINISHED); | event_set_name(e, DLUA_CALL_FINISHED); | |||
event_add_str(e, "event_name", event->event->event->name); | event_add_str(e, "event_name", event->event->event->name); | |||
event_add_str(e, "function_name", fn); | event_add_str(e, "function_name", fn); | |||
/* Push context */ | /* Push context */ | |||
lua_rawgeti(ctx->script->L, LUA_REGISTRYINDEX, tctx->tx_ref); | lua_rawgeti(ctx->script->L, LUA_REGISTRYINDEX, tctx->tx_ref); | |||
/* Push event + common fields */ | /* Push event + common fields */ | |||
push_notification_driver_lua_pushevent(event, ctx); | push_notification_driver_lua_push_event(event, ctx); | |||
if (mbox != NULL) { | if (mbox != NULL) { | |||
lua_pushstring(ctx->script->L, mbox->mailbox); | lua_pushstring(ctx->script->L, mbox->mailbox); | |||
lua_setfield(ctx->script->L, -2, "mailbox"); | lua_setfield(ctx->script->L, -2, "mailbox"); | |||
e_debug(ctx->event, | e_debug(ctx->event, | |||
"Calling %s(ctx, event[name=%s,mailbox=%s])", | "Calling %s(ctx, event[name=%s,mailbox=%s])", | |||
fn, event->event->event->name, mbox->mailbox); | fn, event->event->event->name, mbox->mailbox); | |||
event_add_str(e, "mailbox", mbox->mailbox); | event_add_str(e, "mailbox", mbox->mailbox); | |||
} else if (msg != NULL) { | } else if (msg != NULL) { | |||
lua_pushstring(ctx->script->L, msg->mailbox); | lua_pushstring(ctx->script->L, msg->mailbox); | |||
End of changes. 23 change blocks. | ||||
23 lines changed or deleted | 23 lines changed or added |