From 6d1be23988e8d1c91d96876f2e14601901ae9e0f Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan.bosch@open-xchange.com> Date: Mon, 12 Oct 2020 20:34:27 +0200 Subject: [PATCH] lib-sieve: plugins: include: Reformat cmd-global.c. --- src/lib-sieve/plugins/include/cmd-global.c | 189 +++++++++++---------- 1 file changed, 100 insertions(+), 89 deletions(-) diff --git a/src/lib-sieve/plugins/include/cmd-global.c b/src/lib-sieve/plugins/include/cmd-global.c index 0ef37eb35..01862c058 100644 --- a/src/lib-sieve/plugins/include/cmd-global.c +++ b/src/lib-sieve/plugins/include/cmd-global.c @@ -22,20 +22,21 @@ * Commands */ -static bool cmd_global_validate - (struct sieve_validator *valdtr, struct sieve_command *cmd); -static bool cmd_global_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); +static bool +cmd_global_validate(struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool +cmd_global_generate(const struct sieve_codegen_env *cgenv, + struct sieve_command *cmd); const struct sieve_command_def cmd_global = { - .identifier = "global", - .type = SCT_COMMAND, + .identifier = "global", + .type = SCT_COMMAND, .positional_args = 1, .subtests = 0, .block_allowed = FALSE, .block_required = FALSE, - .validate = cmd_global_validate, - .generate = cmd_global_generate, + .validate = cmd_global_validate, + .generate = cmd_global_generate, }; /* DEPRICATED: @@ -77,10 +78,10 @@ const struct sieve_command_def cmd_export = { * Operations */ -static bool opc_global_dump - (const struct sieve_dumptime_env *denv, sieve_size_t *address); -static int opc_global_execute - (const struct sieve_runtime_env *renv, sieve_size_t *address); +static bool +opc_global_dump(const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int +opc_global_execute(const struct sieve_runtime_env *renv, sieve_size_t *address); /* Global operation */ @@ -89,38 +90,38 @@ const struct sieve_operation_def global_operation = { .ext_def = &include_extension, .code = EXT_INCLUDE_OPERATION_GLOBAL, .dump = opc_global_dump, - .execute = opc_global_execute + .execute = opc_global_execute, }; /* * Validation */ -static inline struct sieve_argument *_create_variable_argument -(struct sieve_command *cmd, struct sieve_variable *var) +static inline struct sieve_argument * +_create_variable_argument(struct sieve_command *cmd, + struct sieve_variable *var) { - struct sieve_argument *argument = sieve_argument_create - (cmd->ast_node->ast, NULL, cmd->ext, 0); - - argument->data = (void *) var; + struct sieve_argument *argument = + sieve_argument_create(cmd->ast_node->ast, NULL, cmd->ext, 0); + argument->data = (void *)var; return argument; } -static bool cmd_global_validate -(struct sieve_validator *valdtr, struct sieve_command *cmd) +static bool +cmd_global_validate(struct sieve_validator *valdtr, struct sieve_command *cmd) { const struct sieve_extension *this_ext = cmd->ext; struct sieve_ast_argument *arg = cmd->first_positional; struct sieve_command *prev = sieve_command_prev(cmd); /* DEPRECATED: Check valid command placement */ - if ( !sieve_command_is(cmd, cmd_global) ) { - if ( !sieve_command_is_toplevel(cmd) || - ( !sieve_command_is_first(cmd) && prev != NULL && - !sieve_command_is(prev, cmd_require) && - !sieve_command_is(prev, cmd_import) && - !sieve_command_is(prev, cmd_export) ) ) { + if (!sieve_command_is(cmd, cmd_global)) { + if (!sieve_command_is_toplevel(cmd) || + (!sieve_command_is_first(cmd) && prev != NULL && + !sieve_command_is(prev, cmd_require) && + !sieve_command_is(prev, cmd_import) && + !sieve_command_is(prev, cmd_export))) { sieve_command_validate_error(valdtr, cmd, "the DEPRECATED %s command can only be placed at top level " "at the beginning of the file after any require or " @@ -131,44 +132,48 @@ static bool cmd_global_validate } /* Check for use of variables extension */ - if ( !ext_include_validator_have_variables(this_ext, valdtr) ) { - sieve_command_validate_error(valdtr, cmd, + if (!ext_include_validator_have_variables(this_ext, valdtr)) { + sieve_command_validate_error( + valdtr, cmd, "%s command requires that variables extension is active", sieve_command_identifier(cmd)); return FALSE; } /* Register global variable */ - if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { + if (sieve_ast_argument_type(arg) == SAAT_STRING) { /* Single string */ const char *identifier = sieve_ast_argument_strc(arg); struct sieve_variable *var; - if ( (var=ext_include_variable_import_global - (valdtr, cmd, identifier)) == NULL ) + var = ext_include_variable_import_global(valdtr, cmd, + identifier); + if (var == NULL) return FALSE; arg->argument = _create_variable_argument(cmd, var); - - } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { + } else if (sieve_ast_argument_type(arg) == SAAT_STRING_LIST) { /* String list */ - struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg); + struct sieve_ast_argument *stritem = + sieve_ast_strlist_first(arg); - while ( stritem != NULL ) { - const char *identifier = sieve_ast_argument_strc(stritem); + while (stritem != NULL) { + const char *identifier = + sieve_ast_argument_strc(stritem); struct sieve_variable *var; - if ( (var=ext_include_variable_import_global - (valdtr, cmd, identifier)) == NULL ) + var = ext_include_variable_import_global(valdtr, cmd, + identifier); + if (var == NULL) return FALSE; stritem->argument = _create_variable_argument(cmd, var); - stritem = sieve_ast_strlist_next(stritem); } } else { /* Something else */ - sieve_argument_validate_error(valdtr, arg, + sieve_argument_validate_error( + valdtr, arg, "the %s command accepts a single string or string list argument, " "but %s was found", sieve_command_identifier(cmd), sieve_ast_argument_name(arg)); @@ -176,15 +181,17 @@ static bool cmd_global_validate } /* Join global commands with predecessors if possible */ - if ( sieve_commands_equal(prev, cmd) ) { + if (sieve_commands_equal(prev, cmd)) { /* Join this command's string list with the previous one */ - prev->first_positional = sieve_ast_stringlist_join - (prev->first_positional, cmd->first_positional); - - if ( prev->first_positional == NULL ) { - /* Not going to happen unless MAXINT stringlist items are specified */ - sieve_command_validate_error(valdtr, cmd, - "compiler reached AST limit (script too complex)"); + prev->first_positional = sieve_ast_stringlist_join( + prev->first_positional, cmd->first_positional); + + if (prev->first_positional == NULL) { + /* Not going to happen unless MAXINT stringlist items + are specified */ + sieve_command_validate_error( + valdtr, cmd, "compiler reached AST limit " + "(script too complex)"); return FALSE; } @@ -199,39 +206,40 @@ static bool cmd_global_validate * Code generation */ -static bool cmd_global_generate -(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +static bool +cmd_global_generate(const struct sieve_codegen_env *cgenv, + struct sieve_command *cmd) { struct sieve_ast_argument *arg = cmd->first_positional; sieve_operation_emit(cgenv->sblock, cmd->ext, &global_operation); - if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { + if (sieve_ast_argument_type(arg) == SAAT_STRING) { /* Single string */ - struct sieve_variable *var = (struct sieve_variable *) arg->argument->data; + struct sieve_variable *var = + (struct sieve_variable *)arg->argument->data; (void)sieve_binary_emit_unsigned(cgenv->sblock, 1); (void)sieve_binary_emit_unsigned(cgenv->sblock, var->index); - - } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { + } else if (sieve_ast_argument_type(arg) == SAAT_STRING_LIST) { /* String list */ - struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg); - - (void)sieve_binary_emit_unsigned - (cgenv->sblock, sieve_ast_strlist_count(arg)); + struct sieve_ast_argument *stritem = + sieve_ast_strlist_first(arg); - while ( stritem != NULL ) { - struct sieve_variable *var = - (struct sieve_variable *) stritem->argument->data; + (void)sieve_binary_emit_unsigned(cgenv->sblock, + sieve_ast_strlist_count(arg)); - (void)sieve_binary_emit_unsigned(cgenv->sblock, var->index); + while (stritem != NULL) { + struct sieve_variable *var = (struct sieve_variable *) + stritem->argument->data; + (void)sieve_binary_emit_unsigned(cgenv->sblock, + var->index); stritem = sieve_ast_strlist_next(stritem); } } else { i_unreached(); } - return TRUE; } @@ -239,8 +247,8 @@ static bool cmd_global_generate * Code dump */ -static bool opc_global_dump -(const struct sieve_dumptime_env *denv, sieve_size_t *address) +static bool +opc_global_dump(const struct sieve_dumptime_env *denv, sieve_size_t *address) { const struct sieve_extension *this_ext = denv->oprtn->ext; unsigned int count, i, var_count; @@ -248,7 +256,7 @@ static bool opc_global_dump struct sieve_variable_scope *global_scope; struct sieve_variable * const *vars; - if ( !sieve_binary_read_unsigned(denv->sblock, address, &count) ) + if (!sieve_binary_read_unsigned(denv->sblock, address, &count)) return FALSE; sieve_code_dumpf(denv, "GLOBAL (count: %u):", count); @@ -259,15 +267,17 @@ static bool opc_global_dump sieve_code_descend(denv); - for ( i = 0; i < count; i++ ) { + for (i = 0; i < count; i++) { unsigned int index; sieve_code_mark(denv); - if ( !sieve_binary_read_unsigned(denv->sblock, address, &index) || - index >= var_count ) + if (!sieve_binary_read_unsigned(denv->sblock, address, + &index) || + index >= var_count) return FALSE; - sieve_code_dumpf(denv, "%d: VAR[%d]: '%s'", i, index, vars[index]->identifier); + sieve_code_dumpf(denv, "%d: VAR[%d]: '%s'", + i, index, vars[index]->identifier); } return TRUE; @@ -277,8 +287,8 @@ static bool opc_global_dump * Execution */ -static int opc_global_execute -(const struct sieve_runtime_env *renv, sieve_size_t *address) +static int +opc_global_execute(const struct sieve_runtime_env *renv, sieve_size_t *address) { const struct sieve_extension *this_ext = renv->oprtn->ext; struct sieve_variable_scope_binary *global_vars; @@ -287,35 +297,38 @@ static int opc_global_execute struct sieve_variable * const *vars; unsigned int var_count, count, i; - if ( !sieve_binary_read_unsigned(renv->sblock, address, &count) ) { - sieve_runtime_trace_error(renv, - "global: count operand invalid"); + if (!sieve_binary_read_unsigned(renv->sblock, address, &count)) { + sieve_runtime_trace_error( + renv, "global: count operand invalid"); return SIEVE_EXEC_BIN_CORRUPT; } global_vars = ext_include_binary_get_global_scope(this_ext, renv->sbin); global_scope = sieve_variable_scope_binary_get(global_vars); vars = sieve_variable_scope_get_variables(global_scope, &var_count); - storage = ext_include_interpreter_get_global_variables - (this_ext, renv->interp); + storage = ext_include_interpreter_get_global_variables(this_ext, + renv->interp); - for ( i = 0; i < count; i++ ) { + for (i = 0; i < count; i++) { unsigned int index; - if ( !sieve_binary_read_unsigned(renv->sblock, address, &index) ) { - sieve_runtime_trace_error(renv, - "global: variable index operand invalid"); + if (!sieve_binary_read_unsigned(renv->sblock, address, + &index)) { + sieve_runtime_trace_error( + renv, "global: variable index operand invalid"); return SIEVE_EXEC_BIN_CORRUPT; } - if ( index >= var_count ) { - sieve_runtime_trace_error(renv, - "global: variable index %u is invalid in global storage (> %u)", - index, var_count); + if (index >= var_count) { + sieve_runtime_trace_error( + renv, "global: " + "variable index %u is invalid in global storage " + "(> %u)", index, var_count); return SIEVE_EXEC_BIN_CORRUPT; } - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + sieve_runtime_trace( + renv, SIEVE_TRLVL_COMMANDS, "global: exporting variable '%s' [gvid: %u, vid: %u]", vars[index]->identifier, i, index); @@ -325,5 +338,3 @@ static int opc_global_execute return SIEVE_EXEC_OK; } - - -- GitLab