static int cmd_test_config_set_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { string_t *setting; string_t *value; int ret; /* * Read operands */ /* Setting */ if ( (ret=sieve_opr_string_read(renv, address, "setting", &setting)) <= 0 ) return ret; /* Value */ if ( (ret=sieve_opr_string_read(renv, address, "value", &value)) <= 0 ) return ret; /* * Perform operation */ if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite: test_config_set command"); sieve_runtime_trace_descend(renv); sieve_runtime_trace(renv, 0, "set config `%s' = `%s'", str_c(setting), str_c(value)); } testsuite_setting_set(str_c(setting), str_c(value)); return SIEVE_EXEC_OK; }
static int cmd_error_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { string_t *message; int ret; /* * Read operands */ /* Read message */ if ( (ret=sieve_opr_string_read(renv, address, "message", &message)) <= 0 ) return ret; /* * Perform operation */ sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "error \"%s\"", str_sanitize(str_c(message), 80)); sieve_runtime_error(renv, NULL, "%s", str_c(message)); return SIEVE_EXEC_FAILURE; }
static int cmd_test_set_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { struct testsuite_object tobj; string_t *value; int member_id; int ret; if ( !testsuite_object_read_member (renv->sblock, address, &tobj, &member_id) ) { sieve_runtime_trace_error(renv, "invalid testsuite object member"); return SIEVE_EXEC_BIN_CORRUPT; } if ( (ret=sieve_opr_string_read(renv, address, "string", &value)) <= 0 ) return ret; if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite: test_set command"); sieve_runtime_trace_descend(renv); sieve_runtime_trace(renv, 0, "set test parameter '%s' = \"%s\"", testsuite_object_member_name(&tobj, member_id), str_c(value)); } if ( tobj.def == NULL || tobj.def->set_member == NULL ) { sieve_runtime_trace_error(renv, "unimplemented testsuite object"); return SIEVE_EXEC_FAILURE; } tobj.def->set_member(renv, member_id, value); return SIEVE_EXEC_OK; }
int sieve_extprogram_command_read_operands (const struct sieve_runtime_env *renv, sieve_size_t *address, string_t **pname_r, struct sieve_stringlist **args_list_r) { string_t *arg; int ret; /* * Read fixed operands */ if ( (ret=sieve_opr_string_read (renv, address, "program-name", pname_r)) <= 0 ) return ret; if ( (ret=sieve_opr_stringlist_read_ex (renv, address, "arguments", TRUE, args_list_r)) <= 0 ) return ret; /* * Check operands */ arg = NULL; while ( *args_list_r != NULL && (ret=sieve_stringlist_next_item(*args_list_r, &arg)) > 0 ) { if ( !sieve_extprogram_arg_is_valid(arg) ) { sieve_runtime_error(renv, NULL, "specified :args item `%s' is invalid", str_sanitize(str_c(arg), 128)); return SIEVE_EXEC_FAILURE; } } if ( ret < 0 ) { sieve_runtime_trace_error(renv, "invalid args-list item"); return SIEVE_EXEC_BIN_CORRUPT; } return SIEVE_EXEC_OK; }
static int cmd_test_imap_metadata_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { const struct sieve_operation *oprtn = renv->oprtn; int opt_code = 0; string_t *mailbox = NULL, *annotation = NULL, *value = NULL; int ret; /* * Read operands */ /* Optional operands */ for (;;) { int opt; if ( (opt=sieve_opr_optional_read(renv, address, &opt_code)) < 0 ) return SIEVE_EXEC_BIN_CORRUPT; if ( opt == 0 ) break; switch ( opt_code ) { case OPT_MAILBOX: ret = sieve_opr_string_read(renv, address, "mailbox", &mailbox); break; default: sieve_runtime_trace_error(renv, "unknown optional operand"); ret = SIEVE_EXEC_BIN_CORRUPT; } if ( ret <= 0 ) return ret; } /* Fixed operands */ if ( (ret=sieve_opr_string_read (renv, address, "annotation", &annotation)) <= 0 ) return ret; if ( (ret=sieve_opr_string_read (renv, address, "value", &value)) <= 0 ) return ret; /* * Perform operation */ if ( sieve_operation_is(oprtn, test_imap_metadata_set_operation) ) { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite/test_imap_metadata_set command"); sieve_runtime_trace_descend(renv); if (mailbox == NULL) { sieve_runtime_trace(renv, 0, "set server annotation `%s'", str_c(annotation)); } else { sieve_runtime_trace(renv, 0, "set annotation `%s' for mailbox `%s'", str_c(annotation), str_c(mailbox)); } } if (testsuite_mailstore_set_imap_metadata (( mailbox == NULL ? NULL : str_c(mailbox) ), str_c(annotation), str_c(value)) < 0) return SIEVE_EXEC_FAILURE; } return SIEVE_EXEC_OK; }
static int cmd_test_binary_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { const struct sieve_operation *oprtn = renv->oprtn; string_t *binary_name = NULL; int ret; /* * Read operands */ /* Binary Name */ if ( (ret=sieve_opr_string_read(renv, address, "binary-name", &binary_name)) <= 0 ) return ret; /* * Perform operation */ if ( sieve_operation_is(oprtn, test_binary_load_operation) ) { struct sieve_binary *sbin = testsuite_binary_load(str_c(binary_name)); if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite: test_binary_load command"); sieve_runtime_trace_descend(renv); sieve_runtime_trace(renv, 0, "load binary `%s'", str_c(binary_name)); } if ( sbin != NULL ) { testsuite_script_set_binary(sbin); sieve_binary_unref(&sbin); } else { sieve_sys_error(testsuite_sieve_instance, "failed to load binary %s", str_c(binary_name)); return SIEVE_EXEC_FAILURE; } } else if ( sieve_operation_is(oprtn, test_binary_save_operation) ) { struct sieve_binary *sbin = testsuite_script_get_binary(); if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite: test_binary_save command"); sieve_runtime_trace_descend(renv); sieve_runtime_trace(renv, 0, "save binary `%s'", str_c(binary_name)); } if ( sbin != NULL ) testsuite_binary_save(sbin, str_c(binary_name)); else { sieve_sys_error(testsuite_sieve_instance, "no compiled binary to save as %s", str_c(binary_name)); return SIEVE_EXEC_FAILURE; } } else { i_unreached(); } return SIEVE_EXEC_OK; }
static int cmd_test_config_reload_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { const struct sieve_extension *ext; int opt_code = 0; string_t *extension = NULL; int ret; /* * Read operands */ /* Optional operands */ for (;;) { int opt; if ( (opt=sieve_opr_optional_read(renv, address, &opt_code)) < 0 ) return SIEVE_EXEC_BIN_CORRUPT; if ( opt == 0 ) break; switch ( opt_code ) { case OPT_EXTENSION: ret = sieve_opr_string_read(renv, address, "extension", &extension); break; default: sieve_runtime_trace_error(renv, "unknown optional operand"); ret = SIEVE_EXEC_BIN_CORRUPT; } if ( ret <= 0 ) return ret; } /* * Perform operation */ if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "testsuite: test_config_reload command"); sieve_runtime_trace_descend(renv); } if ( extension == NULL ) { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "reload configuration for sieve engine"); } sieve_settings_load(renv->svinst); } else { if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { sieve_runtime_trace(renv, 0, "reload configuration for extension `%s'", str_c(extension)); } ext = sieve_extension_get_by_name(renv->svinst, str_c(extension)); if ( ext == NULL ) { testsuite_test_failf("test_config_reload: " "unknown extension '%s'", str_c(extension)); return SIEVE_EXEC_OK; } sieve_extension_reload(ext); } return SIEVE_EXEC_OK; }
static int cmd_report_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { struct act_report_data *act; string_t *fbtype, *message, *to_address; const char *norm_address, *feedback_type, *error; int opt_code = 0, ret = 0; bool headers_only = FALSE; pool_t pool; /* * Read operands */ /* Optional operands */ for (;;) { int opt; if ( (opt=sieve_opr_optional_read(renv, address, &opt_code)) < 0 ) return SIEVE_EXEC_BIN_CORRUPT; if ( opt == 0 ) break; switch ( opt_code ) { case OPT_HEADERS_ONLY: headers_only = TRUE; break; default: sieve_runtime_trace_error(renv, "unknown optional operand"); return SIEVE_EXEC_BIN_CORRUPT; } } /* Fixed operands */ if ( (ret=sieve_opr_string_read (renv, address, "feedback-type", &fbtype)) <= 0 ) return ret; if ( (ret=sieve_opr_string_read (renv, address, "message", &message)) <= 0 ) return ret; if ( (ret=sieve_opr_string_read (renv, address, "address", &to_address)) <= 0 ) return ret; /* * Perform operation */ /* Verify and trim feedback type */ feedback_type = ext_vnd_report_parse_feedback_type(str_c(fbtype)); if ( feedback_type == NULL ) { sieve_runtime_error(renv, NULL, "specified report feedback type `%s' is invalid", str_sanitize(str_c(fbtype), 256)); return SIEVE_EXEC_FAILURE; } /* Verify and normalize the address to 'local_part@domain' */ norm_address = sieve_address_normalize(to_address, &error); if ( norm_address == NULL ) { sieve_runtime_error(renv, NULL, "specified report address `%s' is invalid: %s", str_sanitize(str_c(to_address), 256), error); return SIEVE_EXEC_FAILURE; } /* Trace */ if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_ACTIONS) ) { sieve_runtime_trace(renv, 0, "report action"); sieve_runtime_trace_descend(renv); sieve_runtime_trace(renv, 0, "report incoming message as `%s' to address `%s'", str_sanitize(str_c(fbtype), 32), str_sanitize(norm_address, 80)); } /* Add report action to the result */ pool = sieve_result_pool(renv->result); act = p_new(pool, struct act_report_data, 1); act->headers_only = headers_only; act->feedback_type = p_strdup(pool, feedback_type); act->message = p_strdup(pool, str_c(message)); act->to_address = p_strdup(pool, norm_address); if ( sieve_result_add_action(renv, NULL, &act_report, NULL, (void *) act, 0, TRUE) < 0 ) return SIEVE_EXEC_FAILURE; return SIEVE_EXEC_OK; }