From: Markus Valentin Date: Thu, 14 Mar 2024 12:51:55 +0000 (+0100) Subject: plugins/push-notification: push_notification_driver_lua_init() - Use dlua_script_crea... X-Git-Tag: 2.4.1~919 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2290f48813230c4d620b8465e06705f44ca3e3e9;p=thirdparty%2Fdovecot%2Fcore.git plugins/push-notification: push_notification_driver_lua_init() - Use dlua_script_create_auto() --- diff --git a/src/plugins/push-notification/push-notification-driver-lua.c b/src/plugins/push-notification/push-notification-driver-lua.c index 8d536da3a3..df8ef32858 100644 --- a/src/plugins/push-notification/push-notification-driver-lua.c +++ b/src/plugins/push-notification/push-notification-driver-lua.c @@ -36,8 +36,6 @@ #include "push-notification-event-messageread.h" #include "push-notification-event-messagetrash.h" -#define DLUA_LOG_USERENV_KEY "push_notification_lua_script_path" - #define DLUA_FN_BEGIN_TXN "dovecot_lua_notify_begin_txn" #define DLUA_FN_EVENT_PREFIX "dovecot_lua_notify_event" #define DLUA_FN_END_TXN "dovecot_lua_notify_end_txn" @@ -77,48 +75,20 @@ push_notification_driver_lua_init( void **context, const char **error_r) { struct dlua_push_notification_context *ctx; - const char *path; - - struct push_notification_lua_settings *lua_settings; - if (settings_get_filter(user->event, PUSH_NOTIFICATION_SETTINGS_FILTER_NAME, - name, &push_notification_lua_setting_parser_info, - 0, &lua_settings, error_r) < 0) - return -1; struct event *event = event_create(user->event); + char *filter_name = p_strdup_printf( + event_get_pool(event), "%s/%s", + PUSH_NOTIFICATION_SETTINGS_FILTER_NAME, + settings_section_escape(name)); + event_set_ptr(event, SETTINGS_EVENT_FILTER_NAME, filter_name); event_add_category(event, push_notification_get_event_category()); event_set_append_log_prefix(event, "lua: "); - if ((path = mail_user_plugin_getenv(user, DLUA_LOG_USERENV_KEY)) == NULL) - path = t_strdup(lua_settings->path); - - settings_free(lua_settings); - - if (path == NULL) { - struct dlua_script *script; - /* If there is a script loaded, use the same context */ - if (mail_lua_plugin_get_script(user, &script)) { - dlua_script_ref(script); - ctx = p_new( - pool, struct dlua_push_notification_context, 1); - ctx->script = script; - ctx->event = event; - *context = ctx; - return 0; - } - - event_unref(&event); - *error_r = "No path in config and no " - DLUA_LOG_USERENV_KEY " set"; - return -1; - } - ctx = p_new(pool, struct dlua_push_notification_context, 1); ctx->event = event; - e_debug(ctx->event, "Loading %s", path); - - if (dlua_script_create_file(path, &ctx->script, event, error_r) < 0) { + if (dlua_script_create_auto(event, &ctx->script, error_r) <= 0) { /* There is a T_POP after this, which will break errors */ event_unref(&event); *error_r = p_strdup(pool, *error_r); diff --git a/src/plugins/push-notification/push-notification-settings.c b/src/plugins/push-notification/push-notification-settings.c index bc5ce51fab..8ef361d517 100644 --- a/src/plugins/push-notification/push-notification-settings.c +++ b/src/plugins/push-notification/push-notification-settings.c @@ -15,35 +15,9 @@ #define PUSH_NOTIFICATION_DRIVER_OX_DEFAULT_CACHE_TTL_MSECS (60 * 1000) -static bool push_notification_lua_settings_check(void *, pool_t, const char **); static bool push_notification_settings_check(void *, pool_t, const char **); static bool push_notification_ox_settings_check(void *, pool_t, const char **); -#undef DEF -#define DEF(type, name) \ - SETTING_DEFINE_STRUCT_##type("push_notification_lua_"#name, name, struct push_notification_lua_settings) - -static const struct setting_define push_notification_lua_setting_defines[] = { - DEF(STR, path), - - SETTING_DEFINE_LIST_END, -}; - -static const struct push_notification_lua_settings push_notification_lua_default_settings = { - .path = "", -}; - -const struct setting_parser_info push_notification_lua_setting_parser_info = { - .name = "push_notification_lua", - - .defines = push_notification_lua_setting_defines, - .defaults = &push_notification_lua_default_settings, - - .struct_size = sizeof(struct push_notification_lua_settings), - .pool_offset1 = 1 + offsetof(struct push_notification_lua_settings, pool), - .check_func = push_notification_lua_settings_check, -}; - #undef DEF #define DEF(type, name) \ SETTING_DEFINE_STRUCT_##type("push_notification_ox_"#name, name, struct push_notification_ox_settings) @@ -109,21 +83,6 @@ const struct setting_parser_info push_notification_setting_parser_info = { }; /* */ -static bool -push_notification_lua_settings_check(void *_set, pool_t ATTR_UNUSED pool, - const char **error_r) -{ - struct push_notification_lua_settings *set = _set; - - if (set->path[0] != '\0' && access(set->path, F_OK) != 0) { - *error_r = t_strdup_printf( - "push_notification_lua_path: access(%s) failed: %m", - set->path); - return FALSE; - } - return TRUE; -} - static bool push_notification_settings_check(void *_set, pool_t pool ATTR_UNUSED, const char **error_r ATTR_UNUSED)