dovecot-2.0-pigeonhole: include extension: implemented proper co...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Sun Sep 11 11:52:04 EEST 2011
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/ce825c9671a6
changeset: 1524:ce825c9671a6
user: Stephan Bosch <stephan at rename-it.nl>
date: Sun Sep 11 10:51:40 2011 +0200
description:
include extension: implemented proper configuration handling
Configuration is now only read once at extension initialization.
diffstat:
src/lib-sieve/plugins/include/ext-include-common.c | 116 ++++++++--
src/lib-sieve/plugins/include/ext-include-common.h | 9 +
src/lib-sieve/plugins/include/ext-include.c | 33 ---
src/testsuite/testsuite.c | 21 +-
tests/extensions/include/errors/included/action-fileinto.sieve | 3 -
tests/extensions/include/errors/included/action-reject.sieve | 3 -
tests/extensions/include/errors/included/circular-one.sieve | 5 -
tests/extensions/include/errors/included/circular-three-2.sieve | 3 -
tests/extensions/include/errors/included/circular-three-3.sieve | 3 -
tests/extensions/include/errors/included/circular-three.sieve | 7 -
tests/extensions/include/errors/included/circular-two-2.sieve | 3 -
tests/extensions/include/errors/included/circular-two.sieve | 7 -
tests/extensions/include/execute/included/actions-fileinto1.sieve | 3 -
tests/extensions/include/execute/included/actions-fileinto2.sieve | 4 -
tests/extensions/include/execute/included/actions-fileinto3.sieve | 3 -
tests/extensions/include/included/action-fileinto.sieve | 3 +
tests/extensions/include/included/action-reject.sieve | 3 +
tests/extensions/include/included/actions-fileinto1.sieve | 3 +
tests/extensions/include/included/actions-fileinto2.sieve | 4 +
tests/extensions/include/included/actions-fileinto3.sieve | 3 +
tests/extensions/include/included/circular-one.sieve | 5 +
tests/extensions/include/included/circular-three-2.sieve | 3 +
tests/extensions/include/included/circular-three-3.sieve | 3 +
tests/extensions/include/included/circular-three.sieve | 7 +
tests/extensions/include/included/circular-two-2.sieve | 3 +
tests/extensions/include/included/circular-two.sieve | 7 +
26 files changed, 152 insertions(+), 115 deletions(-)
diffs (truncated from 453 to 300 lines):
diff -r 6d0da356f0fd -r ce825c9671a6 src/lib-sieve/plugins/include/ext-include-common.c
--- a/src/lib-sieve/plugins/include/ext-include-common.c Sun Sep 11 00:41:04 2011 +0200
+++ b/src/lib-sieve/plugins/include/ext-include-common.c Sun Sep 11 10:51:40 2011 +0200
@@ -65,6 +65,74 @@
bool returned;
};
+/*
+ * Extension configuration
+ */
+
+/* Extension hooks */
+
+bool ext_include_load
+(const struct sieve_extension *ext, void **context)
+{
+ struct sieve_instance *svinst = ext->svinst;
+ struct ext_include_context *ctx;
+ const char *global_dir, *personal_dir, *home;
+
+ if ( *context != NULL ) {
+ ext_include_unload(ext);
+ }
+
+ /* Get directory for :global scripts */
+ global_dir = sieve_setting_get(svinst, "sieve_global_dir");
+
+ if ( global_dir == NULL && svinst->debug ) {
+ sieve_sys_debug(svinst, "include: sieve_global_dir is not set; "
+ "it is currently not possible to include `:global' scripts.");
+ }
+
+ /* Get directory for :personal scripts */
+ personal_dir = sieve_setting_get(svinst, "sieve_dir");
+
+ home = sieve_environment_get_homedir(svinst);
+
+ if ( personal_dir == NULL ) {
+ if ( home == NULL ) {
+ if ( svinst->debug ) {
+ sieve_sys_debug(svinst, "include: sieve_dir is not set "
+ "and no home directory is set for the default `~/sieve'; "
+ "it is currently not possible to include `:personal' scripts.");
+ }
+ } else {
+ personal_dir = "~/sieve";
+ }
+ }
+
+ if ( home != NULL )
+ personal_dir = home_expand_tilde(personal_dir, home);
+
+ ctx = i_new(struct ext_include_context, 1);
+ ctx->personal_dir = i_strdup(personal_dir);
+ ctx->global_dir = i_strdup(global_dir);
+
+ /* Extension dependencies */
+ ctx->var_ext = sieve_ext_variables_get_extension(ext->svinst);
+
+ *context = (void *)ctx;
+
+ return TRUE;
+}
+
+void ext_include_unload
+(const struct sieve_extension *ext)
+{
+ struct ext_include_context *ctx =
+ (struct ext_include_context *) ext->context;
+
+ i_free(ctx->personal_dir);
+ i_free(ctx->global_dir);
+ i_free(ctx);
+}
+
/*
* Script access
*/
@@ -74,42 +142,36 @@
const char *script_name)
{
struct sieve_instance *svinst = ext->svinst;
- const char *home = NULL, *sieve_dir = NULL;
+ struct ext_include_context *ctx =
+ (struct ext_include_context *) ext->context;
+ const char *sieve_dir;
switch ( location ) {
case EXT_INCLUDE_LOCATION_PERSONAL:
- sieve_dir = sieve_setting_get(svinst, "sieve_dir");
- home = sieve_environment_get_homedir(svinst);
-
- if ( sieve_dir == NULL ) {
- if ( home == NULL ) {
- sieve_sys_error(svinst,
- "include: sieve_dir and home not set for :personal script include "
- "(wanted script '%s')", str_sanitize(script_name, 80));
- return NULL;
- }
-
- sieve_dir = "~/sieve";
- }
-
- if ( home != NULL )
- sieve_dir = home_expand_tilde(sieve_dir, home);
-
- break;
- case EXT_INCLUDE_LOCATION_GLOBAL:
- sieve_dir = sieve_setting_get(svinst, "sieve_global_dir");
-
- if (sieve_dir == NULL) {
- sieve_sys_error(svinst,
- "include: sieve_global_dir not set for :global script include "
- "(wanted script '%s')", str_sanitize(script_name, 80));
+ if ( ctx->personal_dir == NULL ) {
+ sieve_sys_error(svinst, "include: sieve_dir is unconfigured; "
+ "include of `:personal' script `%s' is therefore not possible",
+ str_sanitize(script_name, 80));
return NULL;
}
+ sieve_dir = ctx->personal_dir;
+ break;
+
+ case EXT_INCLUDE_LOCATION_GLOBAL:
+
+ if ( ctx->global_dir == NULL ) {
+ sieve_sys_error(svinst, "include: sieve_global_dir is unconfigured; "
+ "include of `:global' script `%s' is therefore not possible",
+ str_sanitize(script_name, 80));
+ return NULL;
+ }
+
+ sieve_dir = ctx->global_dir;
break;
default:
- break;
+ i_unreached();
}
return sieve_dir;
diff -r 6d0da356f0fd -r ce825c9671a6 src/lib-sieve/plugins/include/ext-include-common.h
--- a/src/lib-sieve/plugins/include/ext-include-common.h Sun Sep 11 00:41:04 2011 +0200
+++ b/src/lib-sieve/plugins/include/ext-include-common.h Sun Sep 11 10:51:40 2011 +0200
@@ -52,6 +52,11 @@
extern const struct sieve_extension_def include_extension;
extern const struct sieve_binary_extension include_binary_ext;
+bool ext_include_load
+ (const struct sieve_extension *ext, void **context);
+void ext_include_unload
+ (const struct sieve_extension *ext);
+
/*
* Commands
*/
@@ -95,6 +100,10 @@
struct ext_include_context {
/* Extension dependencies */
const struct sieve_extension *var_ext;
+
+ /* Configuration */
+ char *global_dir;
+ char *personal_dir;
};
static inline struct ext_include_context *ext_include_get_context
diff -r 6d0da356f0fd -r ce825c9671a6 src/lib-sieve/plugins/include/ext-include.c
--- a/src/lib-sieve/plugins/include/ext-include.c Sun Sep 11 00:41:04 2011 +0200
+++ b/src/lib-sieve/plugins/include/ext-include.c Sun Sep 11 10:51:40 2011 +0200
@@ -50,10 +50,6 @@
/* Forward declaration */
-static bool ext_include_load
- (const struct sieve_extension *ext, void **context);
-static void ext_include_unload
- (const struct sieve_extension *ext);
static bool ext_include_validator_load
(const struct sieve_extension *ext, struct sieve_validator *validator);
static bool ext_include_generator_load
@@ -80,35 +76,6 @@
SIEVE_EXT_DEFINE_NO_OPERANDS
};
-/* Extension hooks */
-
-static bool ext_include_load
-(const struct sieve_extension *ext, void **context)
-{
- struct ext_include_context *ctx;
-
- if ( *context != NULL ) {
- ctx = (struct ext_include_context *) ext->context;
- } else {
- ctx = i_new(struct ext_include_context, 1);
- }
-
- /* Extension dependencies */
- ctx->var_ext = sieve_ext_variables_get_extension(ext->svinst);
-
- *context = ctx;
-
- return TRUE;
-}
-
-static void ext_include_unload
-(const struct sieve_extension *ext)
-{
- struct ext_include_context *ctx = (struct ext_include_context *) ext->context;
-
- i_free(ctx);
-}
-
static bool ext_include_validator_load
(const struct sieve_extension *ext, struct sieve_validator *valdtr)
{
diff -r 6d0da356f0fd -r ce825c9671a6 src/testsuite/testsuite.c
--- a/src/testsuite/testsuite.c Sun Sep 11 00:41:04 2011 +0200
+++ b/src/testsuite/testsuite.c Sun Sep 11 10:51:40 2011 +0200
@@ -49,7 +49,7 @@
static void print_help(void)
{
printf(
-"Usage: testsuite [-E] [-d <dump-filename>]\n"
+"Usage: testsuite [-D] [-E] [-d <dump-filename>]\n"
" [-t <trace-filename>] [-T <trace-option>]\n"
" [-P <plugin>] [-x <extensions>]\n"
" <scriptfile>\n"
@@ -91,7 +91,7 @@
int ret, c;
sieve_tool = sieve_tool_init
- ("testsuite", &argc, &argv, "d:t:T:EP:", TRUE);
+ ("testsuite", &argc, &argv, "d:t:T:EDP:", TRUE);
/* Parse arguments */
scriptfile = dumpfile = tracefile = NULL;
@@ -136,16 +136,10 @@
/* Initialize mail user */
sieve_tool_set_homedir(sieve_tool, t_abspath(""));
- /* Finish tool initialization */
- svinst = sieve_tool_init_finish(sieve_tool, FALSE);
-
- testsuite_init(svinst, log_stdout);
+ /* Initialize settings environment */
testsuite_settings_init();
- printf("Test case: %s:\n\n", scriptfile);
-
- /* Initialize environment */
-
+ /* Currently needed for include (FIXME) */
sieve_dir = strrchr(scriptfile, '/');
if ( sieve_dir == NULL )
sieve_dir= "./";
@@ -153,12 +147,17 @@
sieve_dir = t_strdup_until(scriptfile, sieve_dir+1);
}
- /* Currently needed for include (FIXME) */
testsuite_setting_set
("sieve_dir", t_strconcat(sieve_dir, "included", NULL));
testsuite_setting_set
("sieve_global_dir", t_strconcat(sieve_dir, "included-global", NULL));
+ /* Finish testsuite initialization */
+ svinst = sieve_tool_init_finish(sieve_tool, FALSE);
+ testsuite_init(svinst, log_stdout);
+
+ printf("Test case: %s:\n\n", scriptfile);
+
/* Compile sieve script */
if ( (sbin = sieve_compile
(svinst, scriptfile, NULL, testsuite_log_main_ehandler, NULL)) != NULL ) {
diff -r 6d0da356f0fd -r ce825c9671a6 tests/extensions/include/errors/included/action-fileinto.sieve
--- a/tests/extensions/include/errors/included/action-fileinto.sieve Sun Sep 11 00:41:04 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-require "fileinto";
-
-fileinto "frop";
diff -r 6d0da356f0fd -r ce825c9671a6 tests/extensions/include/errors/included/action-reject.sieve
--- a/tests/extensions/include/errors/included/action-reject.sieve Sun Sep 11 00:41:04 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-require "reject";
-
-reject "Ik heb geen zin in die rommel.";
diff -r 6d0da356f0fd -r ce825c9671a6 tests/extensions/include/errors/included/circular-one.sieve
--- a/tests/extensions/include/errors/included/circular-one.sieve Sun Sep 11 00:41:04 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-require "include";
-
-keep;
-
-include "circular-one.sieve";
More information about the dovecot-cvs
mailing list