diff --git a/src/lib-sieve/plugins/include/ext-include-binary.c b/src/lib-sieve/plugins/include/ext-include-binary.c index 11c1faaf8a5cb7f0b9d682f12fb21e12866d35aa..ce72b342576818ad7d28711fe76463269a508218 100644 --- a/src/lib-sieve/plugins/include/ext-include-binary.c +++ b/src/lib-sieve/plugins/include/ext-include-binary.c @@ -24,18 +24,20 @@ * Forward declarations */ -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); -static bool ext_include_binary_up_to_date - (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); +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); +static bool +ext_include_binary_up_to_date(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); /* * Binary include extension @@ -46,7 +48,7 @@ const struct sieve_binary_extension include_binary_ext = { .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 + .binary_up_to_date = ext_include_binary_up_to_date, }; /* @@ -66,8 +68,9 @@ struct ext_include_binary_context { bool outdated:1; }; -static struct ext_include_binary_context *ext_include_binary_create_context -(const struct sieve_extension *this_ext, struct sieve_binary *sbin) +static struct ext_include_binary_context * +ext_include_binary_create_context(const struct sieve_extension *this_ext, + struct sieve_binary *sbin) { pool_t pool = sieve_binary_pool(sbin); @@ -76,29 +79,30 @@ static struct ext_include_binary_context *ext_include_binary_create_context ctx->binary = sbin; hash_table_create(&ctx->included_scripts, pool, 0, - sieve_script_hash, sieve_script_cmp); + sieve_script_hash, sieve_script_cmp); p_array_init(&ctx->include_index, pool, 128); sieve_binary_extension_set(sbin, this_ext, &include_binary_ext, ctx); - return ctx; } -struct ext_include_binary_context *ext_include_binary_get_context -(const struct sieve_extension *this_ext, struct sieve_binary *sbin) +struct ext_include_binary_context * +ext_include_binary_get_context(const struct sieve_extension *this_ext, + struct sieve_binary *sbin) { - struct ext_include_binary_context *ctx = (struct ext_include_binary_context *) + struct ext_include_binary_context *ctx = + (struct ext_include_binary_context *) sieve_binary_extension_get_context(sbin, this_ext); - if ( ctx == NULL ) + if (ctx == NULL) ctx = ext_include_binary_create_context(this_ext, sbin); return ctx; } -struct ext_include_binary_context *ext_include_binary_init -(const struct sieve_extension *this_ext, struct sieve_binary *sbin, - struct sieve_ast *ast) +struct ext_include_binary_context * +ext_include_binary_init(const struct sieve_extension *this_ext, + struct sieve_binary *sbin, struct sieve_ast *ast) { struct ext_include_ast_context *ast_ctx = ext_include_get_ast_context(this_ext, ast); @@ -108,13 +112,13 @@ struct ext_include_binary_context *ext_include_binary_init ctx = ext_include_binary_get_context(this_ext, sbin); /* Create dependency block */ - if ( ctx->dependency_block == 0 ) + if (ctx->dependency_block == 0) ctx->dependency_block = sieve_binary_extension_create_block(sbin, this_ext); - if ( ctx->global_vars == NULL ) { - ctx->global_vars = - sieve_variable_scope_binary_create(ast_ctx->global_vars); + if (ctx->global_vars == NULL) { + ctx->global_vars = sieve_variable_scope_binary_create( + ast_ctx->global_vars); sieve_variable_scope_binary_ref(ctx->global_vars); } @@ -125,10 +129,12 @@ struct ext_include_binary_context *ext_include_binary_init * Script inclusion */ -struct ext_include_script_info *ext_include_binary_script_include -(struct ext_include_binary_context *binctx, - enum ext_include_script_location location, enum ext_include_flags flags, - struct sieve_script *script, struct sieve_binary_block *inc_block) +struct ext_include_script_info * +ext_include_binary_script_include(struct ext_include_binary_context *binctx, + enum ext_include_script_location location, + enum ext_include_flags flags, + struct sieve_script *script, + struct sieve_binary_block *inc_block) { pool_t pool = sieve_binary_pool(binctx->binary); struct ext_include_script_info *incscript; @@ -149,8 +155,9 @@ struct ext_include_script_info *ext_include_binary_script_include return incscript; } -struct ext_include_script_info *ext_include_binary_script_get_include_info -(struct ext_include_binary_context *binctx, struct sieve_script *script) +struct ext_include_script_info * +ext_include_binary_script_get_include_info( + struct ext_include_binary_context *binctx, struct sieve_script *script) { struct ext_include_script_info *incscript = hash_table_lookup(binctx->included_scripts, script); @@ -158,28 +165,29 @@ struct ext_include_script_info *ext_include_binary_script_get_include_info return incscript; } -const struct ext_include_script_info *ext_include_binary_script_get_included -(struct ext_include_binary_context *binctx, unsigned int include_id) +const struct ext_include_script_info * +ext_include_binary_script_get_included( + struct ext_include_binary_context *binctx, unsigned int include_id) { - if ( include_id > 0 && - (include_id - 1) < array_count(&binctx->include_index) ) { + if (include_id > 0 && + (include_id - 1) < array_count(&binctx->include_index) ) { struct ext_include_script_info *const *sinfo = array_idx(&binctx->include_index, include_id - 1); return *sinfo; } - return NULL; } -const struct ext_include_script_info *ext_include_binary_script_get -(struct ext_include_binary_context *binctx, struct sieve_script *script) +const struct ext_include_script_info * +ext_include_binary_script_get(struct ext_include_binary_context *binctx, + struct sieve_script *script) { return hash_table_lookup(binctx->included_scripts, script); } -unsigned int ext_include_binary_script_get_count -(struct ext_include_binary_context *binctx) +unsigned int +ext_include_binary_script_get_count(struct ext_include_binary_context *binctx) { return array_count(&binctx->include_index); } @@ -188,8 +196,9 @@ unsigned int ext_include_binary_script_get_count * Variables */ -struct sieve_variable_scope_binary *ext_include_binary_get_global_scope -(const struct sieve_extension *this_ext, struct sieve_binary *sbin) +struct sieve_variable_scope_binary * +ext_include_binary_get_global_scope(const struct sieve_extension *this_ext, + struct sieve_binary *sbin) { struct ext_include_binary_context *binctx = ext_include_binary_get_context(this_ext, sbin); @@ -201,13 +210,13 @@ struct sieve_variable_scope_binary *ext_include_binary_get_global_scope * Binary extension */ -static bool ext_include_binary_pre_save -(const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_binary *sbin ATTR_UNUSED, void *context, - enum sieve_error *error_r) +static bool +ext_include_binary_pre_save(const struct sieve_extension *ext ATTR_UNUSED, + 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; + (struct ext_include_binary_context *)context; struct ext_include_script_info *const *scripts; struct sieve_binary_block *sblock = binctx->dependency_block; unsigned int script_count, i; @@ -219,34 +228,37 @@ static bool ext_include_binary_pre_save sieve_binary_emit_unsigned(sblock, script_count); - for ( i = 0; i < script_count; i++ ) { + for (i = 0; i < script_count; i++) { struct ext_include_script_info *incscript = scripts[i]; - if ( incscript->block != NULL ) { - sieve_binary_emit_unsigned - (sblock, sieve_binary_block_get_id(incscript->block)); + if (incscript->block != NULL) { + sieve_binary_emit_unsigned( + sblock, + sieve_binary_block_get_id(incscript->block)); } else { sieve_binary_emit_unsigned(sblock, 0); } sieve_binary_emit_byte(sblock, incscript->location); - sieve_binary_emit_cstring(sblock, sieve_script_name(incscript->script)); + sieve_binary_emit_cstring( + sblock, sieve_script_name(incscript->script)); sieve_binary_emit_byte(sblock, incscript->flags); sieve_script_binary_write_metadata(incscript->script, sblock); } - result = ext_include_variables_save(sblock, binctx->global_vars, error_r); - + result = ext_include_variables_save(sblock, binctx->global_vars, + error_r); return result; } -static bool ext_include_binary_open -(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context) +static bool +ext_include_binary_open(const struct sieve_extension *ext, + struct sieve_binary *sbin, void *context) { struct sieve_instance *svinst = ext->svinst; struct ext_include_context *ext_ctx = (struct ext_include_context *)ext->context; struct ext_include_binary_context *binctx = - (struct ext_include_binary_context *) context; + (struct ext_include_binary_context *)context; struct sieve_binary_block *sblock; unsigned int depcount, i, block_id; sieve_size_t offset; @@ -262,24 +274,26 @@ static bool ext_include_binary_open offset = 0; - if ( !sieve_binary_read_unsigned(sblock, &offset, &depcount) ) { + if (!sieve_binary_read_unsigned(sblock, &offset, &depcount)) { e_error(svinst->event, "include: failed to read include count " - "for dependency block %d of binary %s", block_id, - sieve_binary_path(sbin)); + "for dependency block %d of binary %s", + block_id, sieve_binary_path(sbin)); return FALSE; } /* Check include limit */ - if ( depcount > ext_ctx->max_includes ) { + if (depcount > ext_ctx->max_includes) { e_error(svinst->event, - "include: binary %s includes too many scripts (%u > %u)", - sieve_binary_path(sbin), depcount, ext_ctx->max_includes); + "include: binary %s includes too many scripts " + "(%u > %u)", + sieve_binary_path(sbin), depcount, + ext_ctx->max_includes); return FALSE; } /* Read dependencies */ - for ( i = 0; i < depcount; i++ ) { + for (i = 0; i < depcount; i++) { unsigned int inc_block_id; struct sieve_binary_block *inc_block = NULL; unsigned int location, flags; @@ -289,11 +303,11 @@ static bool ext_include_binary_open enum sieve_error error; int ret; - if ( - !sieve_binary_read_unsigned(sblock, &offset, &inc_block_id) || - !sieve_binary_read_byte(sblock, &offset, &location) || - !sieve_binary_read_string(sblock, &offset, &script_name) || - !sieve_binary_read_byte(sblock, &offset, &flags) ) { + if (!sieve_binary_read_unsigned(sblock, &offset, + &inc_block_id) || + !sieve_binary_read_byte(sblock, &offset, &location) || + !sieve_binary_read_string(sblock, &offset, &script_name) || + !sieve_binary_read_byte(sblock, &offset, &flags)) { /* Binary is corrupt, recompile */ e_error(svinst->event, "include: failed to read included script " @@ -302,8 +316,9 @@ static bool ext_include_binary_open return FALSE; } - if ( inc_block_id != 0 && - (inc_block=sieve_binary_block_get(sbin, inc_block_id)) == NULL ) { + if (inc_block_id != 0 && + (inc_block=sieve_binary_block_get( + sbin, inc_block_id)) == NULL) { e_error(svinst->event, "include: failed to find block %d for included script " "from dependency block %d of binary %s", @@ -312,7 +327,7 @@ static bool ext_include_binary_open return FALSE; } - if ( location >= EXT_INCLUDE_LOCATION_INVALID ) { + if (location >= EXT_INCLUDE_LOCATION_INVALID) { /* Binary is corrupt, recompile */ e_error(svinst->event, "include: dependency block %d of binary %s " @@ -322,30 +337,31 @@ static bool ext_include_binary_open } /* Can we find the script dependency ? */ - storage = ext_include_get_script_storage - (ext, location, str_c(script_name), &error); - if ( storage == NULL ) { + storage = ext_include_get_script_storage(ext, location, + str_c(script_name), + &error); + if (storage == NULL) { /* No, recompile */ // FIXME: handle ':optional' in this case return FALSE; } /* Can we open the script dependency ? */ - script = sieve_storage_get_script - (storage, str_c(script_name), &error); - if ( script == NULL ) { + script = sieve_storage_get_script(storage, str_c(script_name), + &error); + if (script == NULL) { /* No, recompile */ return FALSE; } - if ( sieve_script_open(script, &error) < 0 ) { - if ( error != SIEVE_ERROR_NOT_FOUND ) { + if (sieve_script_open(script, &error) < 0) { + if (error != SIEVE_ERROR_NOT_FOUND) { /* No, recompile */ return FALSE; } - if ( (flags & EXT_INCLUDE_FLAG_OPTIONAL) == 0 ) { + if ((flags & EXT_INCLUDE_FLAG_OPTIONAL) == 0) { /* Not supposed to be missing, recompile */ - if ( svinst->debug ) { + if (svinst->debug) { e_debug(svinst->event, "include: " "script '%s' included in binary %s is missing, " "so recompile", @@ -356,21 +372,23 @@ static bool ext_include_binary_open } } else if (inc_block == NULL) { - /* Script exists, but it is missing from the binary, recompile no matter - * what. - */ - if ( svinst->debug ) { + /* Script exists, but it is missing from the binary, + recompile no matter what. */ + if (svinst->debug) { e_debug(svinst->event, "include: " - "script '%s' is missing in binary %s, but is now available, " - "so recompile", str_c(script_name), sieve_binary_path(sbin)); + "script '%s' is missing in binary %s, " + "but is now available, so recompile", + str_c(script_name), + sieve_binary_path(sbin)); } sieve_script_unref(&script); return FALSE; } /* Can we read script metadata ? */ - if ( (ret=sieve_script_binary_read_metadata - (script, sblock, &offset)) < 0 ) { + ret = sieve_script_binary_read_metadata(script, sblock, + &offset); + if (ret < 0) { /* Binary is corrupt, recompile */ e_error(svinst->event, "include: " "dependency block %d of binary %s " @@ -381,53 +399,52 @@ static bool ext_include_binary_open return FALSE; } - if ( ret == 0 ) + if (ret == 0) binctx->outdated = TRUE; - (void)ext_include_binary_script_include - (binctx, location, flags, script, inc_block); - + (void)ext_include_binary_script_include(binctx, location, flags, + script, inc_block); sieve_script_unref(&script); } - if ( !ext_include_variables_load - (ext, sblock, &offset, &binctx->global_vars) ) + if (!ext_include_variables_load(ext, sblock, &offset, + &binctx->global_vars)) return FALSE; - return TRUE; } -static bool ext_include_binary_up_to_date -(const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_binary *sbin ATTR_UNUSED, void *context, - enum sieve_compile_flags cpflags ATTR_UNUSED) +static bool +ext_include_binary_up_to_date(const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_binary *sbin ATTR_UNUSED, + void *context, + enum sieve_compile_flags cpflags ATTR_UNUSED) { struct ext_include_binary_context *binctx = - (struct ext_include_binary_context *) context; + (struct ext_include_binary_context *)context; return !binctx->outdated; } -static void ext_include_binary_free -(const struct sieve_extension *ext ATTR_UNUSED, - struct sieve_binary *sbin ATTR_UNUSED, void *context) +static void +ext_include_binary_free(const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_binary *sbin ATTR_UNUSED, void *context) { struct ext_include_binary_context *binctx = - (struct ext_include_binary_context *) context; + (struct ext_include_binary_context *)context; struct hash_iterate_context *hctx; struct sieve_script *script; struct ext_include_script_info *incscript; /* Release references to all included script objects */ hctx = hash_table_iterate_init(binctx->included_scripts); - while ( hash_table_iterate - (hctx, binctx->included_scripts, &script, &incscript) ) + while (hash_table_iterate(hctx, binctx->included_scripts, + &script, &incscript)) sieve_script_unref(&incscript->script); hash_table_iterate_deinit(&hctx); hash_table_destroy(&binctx->included_scripts); - if ( binctx->global_vars != NULL ) + if (binctx->global_vars != NULL) sieve_variable_scope_binary_unref(&binctx->global_vars); } @@ -435,8 +452,8 @@ static void ext_include_binary_free * Dumping the binary */ -bool ext_include_binary_dump -(const struct sieve_extension *ext, struct sieve_dumptime_env *denv) +bool ext_include_binary_dump(const struct sieve_extension *ext, + struct sieve_dumptime_env *denv) { struct sieve_binary *sbin = denv->sbin; struct ext_include_binary_context *binctx = @@ -445,29 +462,32 @@ bool ext_include_binary_dump struct sieve_script *script; struct ext_include_script_info *incscript; - if ( !ext_include_variables_dump(denv, binctx->global_vars) ) + if (!ext_include_variables_dump(denv, binctx->global_vars)) return FALSE; hctx = hash_table_iterate_init(binctx->included_scripts); - while ( hash_table_iterate - (hctx, binctx->included_scripts, &script, &incscript) ) { - - if ( incscript->block == NULL ) { - sieve_binary_dump_sectionf(denv, "Included %s script '%s' (MISSING)", - ext_include_script_location_name(incscript->location), + while (hash_table_iterate(hctx, binctx->included_scripts, + &script, &incscript)) { + if (incscript->block == NULL) { + sieve_binary_dump_sectionf( + denv, "Included %s script '%s' (MISSING)", + ext_include_script_location_name( + incscript->location), sieve_script_name(incscript->script)); - } else { - unsigned int block_id = sieve_binary_block_get_id(incscript->block); + unsigned int block_id = + sieve_binary_block_get_id(incscript->block); - sieve_binary_dump_sectionf(denv, "Included %s script '%s' (block: %d)", - ext_include_script_location_name(incscript->location), + sieve_binary_dump_sectionf( + denv, "Included %s script '%s' (block: %d)", + ext_include_script_location_name( + incscript->location), sieve_script_name(incscript->script), block_id); denv->sblock = incscript->block; denv->cdumper = sieve_code_dumper_create(denv); - if ( denv->cdumper == NULL ) + if (denv->cdumper == NULL) return FALSE; sieve_code_dumper_run(denv->cdumper); @@ -475,24 +495,20 @@ bool ext_include_binary_dump } } hash_table_iterate_deinit(&hctx); - return TRUE; } -bool ext_include_code_dump -(const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, - sieve_size_t *address ATTR_UNUSED) +bool ext_include_code_dump(const struct sieve_extension *ext, + const struct sieve_dumptime_env *denv, + sieve_size_t *address ATTR_UNUSED) { struct sieve_binary *sbin = denv->sbin; struct ext_include_binary_context *binctx = ext_include_binary_get_context(ext, sbin); struct ext_include_context *ectx = ext_include_get_context(ext); - sieve_ext_variables_dump_set_scope - (ectx->var_ext, denv, ext, - sieve_variable_scope_binary_get(binctx->global_vars)); - + sieve_ext_variables_dump_set_scope( + ectx->var_ext, denv, ext, + sieve_variable_scope_binary_get(binctx->global_vars)); return TRUE; } - -