dovecot-1.2-sieve: Reworked error handler implementation and cle...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Sun Jan 10 03:39:28 EET 2010
details: http://hg.rename-it.nl/dovecot-1.2-sieve/rev/9da9817a0e05
changeset: 1194:9da9817a0e05
user: Stephan Bosch <stephan at rename-it.nl>
date: Sun Jan 10 02:11:11 2010 +0100
description:
Reworked error handler implementation and cleaned up enotify extension implementation.
diffstat:
configure.in | 1 +
src/lib-sieve/plugins/enotify/Makefile.am | 12 +-
src/lib-sieve/plugins/enotify/cmd-notify.c | 73 +-
src/lib-sieve/plugins/enotify/ext-enotify-common.c | 340 ++++---
src/lib-sieve/plugins/enotify/ext-enotify-common.h | 25 +-
src/lib-sieve/plugins/enotify/ext-enotify.c | 2 +-
src/lib-sieve/plugins/enotify/mailto/Makefile.am | 18 +
src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c | 582 +++++++++++++
src/lib-sieve/plugins/enotify/mailto/uri-mailto.c | 612 ++++++++++++++
src/lib-sieve/plugins/enotify/mailto/uri-mailto.h | 45 +
src/lib-sieve/plugins/enotify/ntfy-mailto.c | 1104 -------------------------
src/lib-sieve/plugins/enotify/sieve-ext-enotify.h | 97 +-
src/lib-sieve/sieve-actions.h | 2 +
src/lib-sieve/sieve-error-private.h | 88 +-
src/lib-sieve/sieve-error.c | 236 +++++-
src/lib-sieve/sieve-error.h | 12 +
src/lib-sieve/sieve-result.c | 153 +--
src/lib-sieve/sieve-result.h | 23 +-
18 files changed, 1927 insertions(+), 1498 deletions(-)
diffs (truncated from 4016 to 300 lines):
diff -r 219a6f0d6bf6 -r 9da9817a0e05 configure.in
--- a/configure.in Fri Jan 08 12:18:20 2010 +0100
+++ b/configure.in Sun Jan 10 02:11:11 2010 +0100
@@ -126,6 +126,7 @@
src/lib-sieve/plugins/body/Makefile
src/lib-sieve/plugins/variables/Makefile
src/lib-sieve/plugins/enotify/Makefile
+src/lib-sieve/plugins/enotify/mailto/Makefile
src/lib-sieve/plugins/notify/Makefile
src/lib-sieve/plugins/environment/Makefile
src/lib-sieve/plugins/mailbox/Makefile
diff -r 219a6f0d6bf6 -r 9da9817a0e05 src/lib-sieve/plugins/enotify/Makefile.am
--- a/src/lib-sieve/plugins/enotify/Makefile.am Fri Jan 08 12:18:20 2010 +0100
+++ b/src/lib-sieve/plugins/enotify/Makefile.am Sun Jan 10 02:11:11 2010 +0100
@@ -1,3 +1,5 @@
+SUBDIRS = mailto
+
noinst_LTLIBRARIES = libsieve_ext_enotify.la
AM_CPPFLAGS = \
@@ -19,15 +21,19 @@
vmodf-encodeurl.c
notify_methods = \
- ntfy-mailto.c
+ ./mailto/libsieve_ext_enotify_mailto.la
+libsieve_ext_enotify_la_DEPENDENCIES = \
+ $(notify_methods)
+libsieve_ext_enotify_la_LIBADD = \
+ $(notify_methods)
+
libsieve_ext_enotify_la_SOURCES = \
ext-enotify.c \
ext-enotify-common.c \
$(commands) \
$(tests) \
- $(var_modifiers) \
- $(notify_methods)
+ $(var_modifiers)
public_headers = \
sieve-ext-enotify.h
diff -r 219a6f0d6bf6 -r 9da9817a0e05 src/lib-sieve/plugins/enotify/cmd-notify.c
--- a/src/lib-sieve/plugins/enotify/cmd-notify.c Fri Jan 08 12:18:20 2010 +0100
+++ b/src/lib-sieve/plugins/enotify/cmd-notify.c Sun Jan 10 02:11:11 2010 +0100
@@ -4,6 +4,7 @@
#include "lib.h"
#include "sieve-common.h"
+#include "sieve-error.h"
#include "sieve-code.h"
#include "sieve-extensions.h"
#include "sieve-commands.h"
@@ -523,7 +524,9 @@
const struct sieve_action *act_other ATTR_UNUSED)
{
const struct sieve_enotify_action *nact1, *nact2;
- struct sieve_enotify_log nlog;
+ const struct sieve_enotify_method_def *nmth_def;
+ struct sieve_enotify_env nenv;
+ bool result = TRUE;
if ( act->context == NULL || act_other->context == NULL )
return 0;
@@ -531,15 +534,24 @@
nact1 = (const struct sieve_enotify_action *) act->context;
nact2 = (const struct sieve_enotify_action *) act_other->context;
- if ( nact1->method == NULL || nact1->method->action_check_duplicates == NULL )
+ if ( nact1->method == NULL || nact1->method->def == NULL )
return 0;
- memset(&nlog, 0, sizeof(nlog));
- nlog.location = act->location;
- nlog.ehandler = sieve_result_get_error_handler(renv->result);
+ nmth_def = nact1->method->def;
+ if ( nmth_def->action_check_duplicates == NULL )
+ return 0;
- return nact1->method->action_check_duplicates
- (&nlog, nact1->method_context, nact2->method_context, act_other->location);
+ memset(&nenv, sizeof(nenv), 0);
+ nenv.method = nact1->method;
+ nenv.ehandler = sieve_prefix_ehandler_create
+ (sieve_result_get_error_handler(renv->result), act->location, "notify");
+
+ result = nmth_def->action_check_duplicates
+ (&nenv, nact1->method_context, nact2->method_context, act_other->location);
+
+ sieve_error_handler_unref(&nenv.ehandler);
+
+ return result;
}
/* Result printing */
@@ -550,17 +562,22 @@
{
const struct sieve_enotify_action *act =
(const struct sieve_enotify_action *) action->context;
+ const struct sieve_enotify_method *method;
- sieve_result_action_printf
- ( rpenv, "send notification with method '%s:':", act->method->identifier);
-
- if ( act->method->action_print != NULL ) {
- struct sieve_enotify_print_env penv;
+ method = act->method;
- memset(&penv, 0, sizeof(penv));
- penv.result_penv = rpenv;
+ if ( method->def != NULL ) {
+ sieve_result_action_printf
+ ( rpenv, "send notification with method '%s:':", method->def->identifier);
- act->method->action_print(&penv, act);
+ if ( method->def->action_print != NULL ) {
+ struct sieve_enotify_print_env penv;
+
+ memset(&penv, 0, sizeof(penv));
+ penv.result_penv = rpenv;
+
+ method->def->action_print(&penv, act);
+ }
}
}
@@ -572,21 +589,25 @@
{
const struct sieve_enotify_action *act =
(const struct sieve_enotify_action *) action->context;
+ const struct sieve_enotify_method *method = act->method;
struct sieve_enotify_exec_env nenv;
- struct sieve_enotify_log nlog;
-
- memset(&nlog, 0, sizeof(nlog));
- nlog.aenv = aenv;
+ bool result = TRUE;
- nenv.scriptenv = aenv->scriptenv;
- nenv.msgdata = aenv->msgdata;
- nenv.msgctx = aenv->msgctx;
- nenv.notify_log = &nlog;
+ if ( method->def != NULL && method->def->action_execute != NULL ) {
+ /* Compose log structure */
+ memset(&nenv, sizeof(nenv), 0);
+ nenv.method = method;
+ nenv.scriptenv = aenv->scriptenv;
+ nenv.msgdata = aenv->msgdata;
+ nenv.msgctx = aenv->msgctx;
- if ( act->method->action_execute != NULL )
- return act->method->action_execute(&nenv, act);
+ nenv.ehandler = sieve_prefix_ehandler_create
+ (aenv->ehandler, action->location, "notify action");
+
+ result = method->def->action_execute(&nenv, act);
+ }
- return TRUE;
+ return result;
}
diff -r 219a6f0d6bf6 -r 9da9817a0e05 src/lib-sieve/plugins/enotify/ext-enotify-common.c
--- a/src/lib-sieve/plugins/enotify/ext-enotify-common.c Fri Jan 08 12:18:20 2010 +0100
+++ b/src/lib-sieve/plugins/enotify/ext-enotify-common.c Sun Jan 10 02:11:11 2010 +0100
@@ -52,29 +52,56 @@
};
/*
+ * Core notification methods
+ */
+
+extern const struct sieve_enotify_method_def mailto_notify;
+
+/*
* Notify method registry
*/
-static void ext_enotify_method_register
-(struct ext_enotify_context *ectx, const struct sieve_enotify_method *method)
+static const struct sieve_enotify_method *ext_enotify_method_register
+(struct sieve_instance *svinst, struct ext_enotify_context *ectx,
+ const struct sieve_enotify_method_def *nmth_def)
{
- array_append(&ectx->notify_methods, &method, 1);
+ struct sieve_enotify_method *nmth;
+
+ nmth = array_append_space(&ectx->notify_methods);
+ nmth->def = nmth_def;
+ nmth->svinst = svinst;
+
+ if ( nmth_def->load != NULL )
+ nmth_def->load(nmth, &nmth->context);
+
+ return nmth;
}
-void ext_enotify_methods_init(struct ext_enotify_context *ectx)
+void ext_enotify_methods_init
+(struct sieve_instance *svinst, struct ext_enotify_context *ectx)
{
p_array_init(&ectx->notify_methods, default_pool, 4);
- ext_enotify_method_register(ectx, &mailto_notify);
+ ext_enotify_method_register(svinst, ectx, &mailto_notify);
}
void ext_enotify_methods_deinit(struct ext_enotify_context *ectx)
{
+ const struct sieve_enotify_method *methods;
+ unsigned int meth_count, i;
+
+ methods = array_get(&ectx->notify_methods, &meth_count);
+ for ( i = 0; i < meth_count; i++ ) {
+ if ( methods[i].def != NULL && methods[i].def->unload != NULL )
+ methods[i].def->unload(&methods[i]);
+ }
+
array_free(&ectx->notify_methods);
}
-void sieve_enotify_method_register
-(struct sieve_instance *svinst, const struct sieve_enotify_method *method)
+const struct sieve_enotify_method *sieve_enotify_method_register
+(struct sieve_instance *svinst,
+ const struct sieve_enotify_method_def *nmth_def)
{
const struct sieve_extension *ntfy_ext =
sieve_extension_get_by_name(svinst, "enotify");
@@ -83,8 +110,10 @@
struct ext_enotify_context *ectx =
(struct ext_enotify_context *) ntfy_ext->context;
- ext_enotify_method_register(ectx, method);
+ return ext_enotify_method_register(svinst, ectx, nmth_def);
}
+
+ return NULL;
}
const struct sieve_enotify_method *ext_enotify_method_find
@@ -93,13 +122,15 @@
struct ext_enotify_context *ectx =
(struct ext_enotify_context *) ntfy_ext->context;
unsigned int meth_count, i;
- const struct sieve_enotify_method *const *methods;
+ const struct sieve_enotify_method *methods;
methods = array_get(&ectx->notify_methods, &meth_count);
for ( i = 0; i < meth_count; i++ ) {
- if ( strcasecmp(methods[i]->identifier, identifier) == 0 ) {
- return methods[i];
+ if ( methods[i].def == NULL ) continue;
+
+ if ( strcasecmp(methods[i].def->identifier, identifier) == 0 ) {
+ return &methods[i];
}
}
@@ -112,17 +143,17 @@
struct ext_enotify_context *ectx =
(struct ext_enotify_context *) ntfy_ext->context;
unsigned int meth_count, i;
- const struct sieve_enotify_method *const *methods;
+ const struct sieve_enotify_method *methods;
string_t *result = t_str_new(128);
methods = array_get(&ectx->notify_methods, &meth_count);
if ( meth_count > 0 ) {
- str_append(result, methods[0]->identifier);
+ str_append(result, methods[0].def->identifier);
for ( i = 1; i < meth_count; i++ ) {
str_append_c(result, ' ');
- str_append(result, methods[i]->identifier);
+ str_append(result, methods[i].def->identifier);
}
return str_c(result);
@@ -173,7 +204,7 @@
}
static bool ext_enotify_option_parse
-(struct sieve_enotify_log *nlog, const char *option, bool name_only,
+(struct sieve_enotify_env *nenv, const char *option, bool name_only,
const char **opt_name_r, const char **opt_value_r)
{
const char *p = option;
@@ -194,7 +225,7 @@
/* Explicitly report empty option as such */
if ( *p == '\0' ) {
- sieve_enotify_error(nlog, "empty option specified");
+ sieve_enotify_error(nenv, "empty option specified");
return FALSE;
}
More information about the dovecot-cvs
mailing list