dovecot-2.2-pigeonhole: lib-sieve: Added post_save hook to binar...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Wed Dec 25 22:51:30 EET 2013
details: http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/2a8bb622f17e
changeset: 1828:2a8bb622f17e
user: Stephan Bosch <stephan at rename-it.nl>
date: Wed Dec 25 21:42:05 2013 +0100
description:
lib-sieve: Added post_save hook to binary object.
diffstat:
src/lib-sieve/plugins/ihave/ext-ihave-binary.c | 26 +++++----
src/lib-sieve/plugins/include/ext-include-binary.c | 32 +++++++-----
src/lib-sieve/plugins/include/ext-include-variables.c | 3 +-
src/lib-sieve/plugins/include/ext-include-variables.h | 3 +-
src/lib-sieve/sieve-binary-file.c | 46 ++++++++++++++----
src/lib-sieve/sieve-binary.h | 7 ++-
6 files changed, 75 insertions(+), 42 deletions(-)
diffs (246 lines):
diff -r cafc7f640c97 -r 2a8bb622f17e src/lib-sieve/plugins/ihave/ext-ihave-binary.c
--- a/src/lib-sieve/plugins/ihave/ext-ihave-binary.c Wed Dec 25 21:40:19 2013 +0100
+++ b/src/lib-sieve/plugins/ihave/ext-ihave-binary.c Wed Dec 25 21:42:05 2013 +0100
@@ -20,24 +20,25 @@
* Forward declarations
*/
-static bool ext_ihave_binary_save
- (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
+static bool ext_ihave_binary_pre_save
+ (const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context, enum sieve_error *error_r);
static bool ext_ihave_binary_open
- (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
+ (const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context);
static bool ext_ihave_binary_up_to_date
- (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context,
- enum sieve_compile_flags cpflags);
+ (const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context, enum sieve_compile_flags cpflags);
/*
* Binary include extension
*/
const struct sieve_binary_extension ihave_binary_ext = {
- &ihave_extension,
- ext_ihave_binary_save,
- ext_ihave_binary_open,
- NULL,
- ext_ihave_binary_up_to_date
+ .extension = &ihave_extension,
+ .binary_pre_save = ext_ihave_binary_pre_save,
+ .binary_open = ext_ihave_binary_open,
+ .binary_up_to_date = ext_ihave_binary_up_to_date
};
/*
@@ -112,8 +113,9 @@
* Binary extension
*/
-static bool ext_ihave_binary_save
-(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context)
+static bool ext_ihave_binary_pre_save
+(const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context, enum sieve_error *error_r)
{
struct ext_ihave_binary_context *binctx =
(struct ext_ihave_binary_context *) context;
diff -r cafc7f640c97 -r 2a8bb622f17e src/lib-sieve/plugins/include/ext-include-binary.c
--- a/src/lib-sieve/plugins/include/ext-include-binary.c Wed Dec 25 21:40:19 2013 +0100
+++ b/src/lib-sieve/plugins/include/ext-include-binary.c Wed Dec 25 21:42:05 2013 +0100
@@ -23,26 +23,29 @@
* Forward declarations
*/
-static bool ext_include_binary_save
- (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
+static bool ext_include_binary_pre_save
+ (const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context, enum sieve_error *error_r);
static bool ext_include_binary_open
- (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
+ (const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context);
static bool ext_include_binary_up_to_date
- (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context,
- enum sieve_compile_flags cpflags);
+ (const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context, enum sieve_compile_flags cpflags);
static void ext_include_binary_free
- (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
+ (const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context);
/*
* Binary include extension
*/
const struct sieve_binary_extension include_binary_ext = {
- &include_extension,
- ext_include_binary_save,
- ext_include_binary_open,
- ext_include_binary_free,
- ext_include_binary_up_to_date
+ .extension = &include_extension,
+ .binary_pre_save = ext_include_binary_pre_save,
+ .binary_open = ext_include_binary_open,
+ .binary_free = ext_include_binary_free,
+ .binary_up_to_date = ext_include_binary_up_to_date
};
/*
@@ -202,9 +205,10 @@
* Binary extension
*/
-static bool ext_include_binary_save
+static bool ext_include_binary_pre_save
(const struct sieve_extension *ext ATTR_UNUSED,
- struct sieve_binary *sbin ATTR_UNUSED, void *context)
+ struct sieve_binary *sbin ATTR_UNUSED, void *context,
+ enum sieve_error *error_r)
{
struct ext_include_binary_context *binctx =
(struct ext_include_binary_context *) context;
@@ -234,7 +238,7 @@
sieve_script_binary_write_metadata(incscript->script, sblock);
}
- result = ext_include_variables_save(sblock, binctx->global_vars);
+ result = ext_include_variables_save(sblock, binctx->global_vars, error_r);
return result;
}
diff -r cafc7f640c97 -r 2a8bb622f17e src/lib-sieve/plugins/include/ext-include-variables.c
--- a/src/lib-sieve/plugins/include/ext-include-variables.c Wed Dec 25 21:40:19 2013 +0100
+++ b/src/lib-sieve/plugins/include/ext-include-variables.c Wed Dec 25 21:42:05 2013 +0100
@@ -80,7 +80,8 @@
bool ext_include_variables_save
(struct sieve_binary_block *sblock,
- struct sieve_variable_scope_binary *global_vars)
+ struct sieve_variable_scope_binary *global_vars,
+ enum sieve_error *error_r ATTR_UNUSED)
{
struct sieve_variable_scope *global_scope =
sieve_variable_scope_binary_get(global_vars);
diff -r cafc7f640c97 -r 2a8bb622f17e src/lib-sieve/plugins/include/ext-include-variables.h
--- a/src/lib-sieve/plugins/include/ext-include-variables.h Wed Dec 25 21:40:19 2013 +0100
+++ b/src/lib-sieve/plugins/include/ext-include-variables.h Wed Dec 25 21:42:05 2013 +0100
@@ -24,7 +24,8 @@
bool ext_include_variables_save
(struct sieve_binary_block *sblock,
- struct sieve_variable_scope_binary *global_vars);
+ struct sieve_variable_scope_binary *global_vars,
+ enum sieve_error *error_r);
bool ext_include_variables_load
(const struct sieve_extension *this_ext, struct sieve_binary_block *sblock,
sieve_size_t *offset, struct sieve_variable_scope_binary **global_vars_r);
diff -r cafc7f640c97 -r 2a8bb622f17e src/lib-sieve/sieve-binary-file.c
--- a/src/lib-sieve/sieve-binary-file.c Wed Dec 25 21:40:19 2013 +0100
+++ b/src/lib-sieve/sieve-binary-file.c Wed Dec 25 21:42:05 2013 +0100
@@ -198,23 +198,12 @@
(struct sieve_binary *sbin, struct ostream *stream)
{
struct sieve_binary_header header;
- struct sieve_binary_extension_reg *const *regs;
struct sieve_binary_block *ext_block;
unsigned int ext_count, blk_count, i;
uoff_t block_index;
blk_count = sieve_binary_block_count(sbin);
- /* Signal all extensions to finish generating their blocks */
-
- regs = array_get(&sbin->extensions, &ext_count);
- for ( i = 0; i < ext_count; i++ ) {
- const struct sieve_binary_extension *binext = regs[i]->binext;
-
- if ( binext != NULL && binext->binary_save != NULL )
- binext->binary_save(regs[i]->extension, sbin, regs[i]->context);
- }
-
/* Create header */
header.magic = SIEVE_BINARY_MAGIC;
@@ -277,6 +266,8 @@
int result, fd;
string_t *temp_path;
struct ostream *stream;
+ struct sieve_binary_extension_reg *const *regs;
+ unsigned int ext_count, i;
if ( error_r != NULL )
*error_r = SIEVE_ERROR_NONE;
@@ -312,6 +303,18 @@
return -1;
}
+ /* Signal all extensions that we're about to save the binary */
+ regs = array_get(&sbin->extensions, &ext_count);
+ for ( i = 0; i < ext_count; i++ ) {
+ const struct sieve_binary_extension *binext = regs[i]->binext;
+
+ if ( binext != NULL && binext->binary_pre_save != NULL &&
+ !binext->binary_pre_save
+ (regs[i]->extension, sbin, regs[i]->context, error_r)) {
+ return -1;
+ }
+ }
+
/* Save binary */
result = 1;
stream = o_stream_create_fd(fd, 0, FALSE);
@@ -353,9 +356,28 @@
str_c(temp_path));
}
} else {
- if ( sbin->path == NULL ) {
+ if ( sbin->path == NULL )
sbin->path = p_strdup(sbin->pool, path);
+
+ /* Signal all extensions that we successfully saved the binary */
+ regs = array_get(&sbin->extensions, &ext_count);
+ for ( i = 0; i < ext_count; i++ ) {
+ const struct sieve_binary_extension *binext = regs[i]->binext;
+
+ if ( binext != NULL && binext->binary_post_save != NULL &&
+ !binext->binary_post_save
+ (regs[i]->extension, sbin, regs[i]->context, error_r)) {
+ result = -1;
+ break;
+ }
}
+
+ if ( result < 0 && unlink(path) < 0 && errno != ENOENT ) {
+ sieve_sys_error(sbin->svinst,
+ "binary save: failed to clean up after error: "
+ "unlink(%s) failed: %m", path);
+ }
+ sbin->path = NULL;
}
return result;
diff -r cafc7f640c97 -r 2a8bb622f17e src/lib-sieve/sieve-binary.h
--- a/src/lib-sieve/sieve-binary.h Wed Dec 25 21:40:19 2013 +0100
+++ b/src/lib-sieve/sieve-binary.h Wed Dec 25 21:42:05 2013 +0100
@@ -111,9 +111,12 @@
struct sieve_binary_extension {
const struct sieve_extension_def *extension;
- bool (*binary_save)
+ bool (*binary_pre_save)
(const struct sieve_extension *ext, struct sieve_binary *sbin,
- void *context);
+ void *context, enum sieve_error *error_r);
+ bool (*binary_post_save)
+ (const struct sieve_extension *ext, struct sieve_binary *sbin,
+ void *context, enum sieve_error *error_r);
bool (*binary_open)
(const struct sieve_extension *ext, struct sieve_binary *sbin,
void *context);
More information about the dovecot-cvs
mailing list