1
/* Copyright (c) 2002-2009 Dovecot Sieve authors, see the included COPYING file
4
#include "sieve-common.h"
5
#include "sieve-script.h"
6
#include "sieve-commands.h"
7
#include "sieve-validator.h"
8
#include "sieve-generator.h"
9
#include "sieve-interpreter.h"
10
#include "sieve-code.h"
11
#include "sieve-binary.h"
12
#include "sieve-dump.h"
15
#include "testsuite-common.h"
16
#include "testsuite-script.h"
17
#include "testsuite-result.h"
20
* Test_script_run command
26
static bool tst_test_script_run_registered
27
(struct sieve_validator *validator, struct sieve_command_registration *cmd_reg);
28
static bool tst_test_script_run_generate
29
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
31
const struct sieve_command tst_test_script_run = {
35
tst_test_script_run_registered,
37
tst_test_script_run_generate,
45
static bool tst_test_script_run_operation_dump
46
(const struct sieve_operation *op,
47
const struct sieve_dumptime_env *denv, sieve_size_t *address);
48
static int tst_test_script_run_operation_execute
49
(const struct sieve_operation *op,
50
const struct sieve_runtime_env *renv, sieve_size_t *address);
52
const struct sieve_operation test_script_run_operation = {
55
TESTSUITE_OPERATION_TEST_SCRIPT_RUN,
56
tst_test_script_run_operation_dump,
57
tst_test_script_run_operation_execute
64
/* Codes for optional arguments */
66
enum cmd_vacation_optional {
73
static const struct sieve_argument append_result_tag = {
75
NULL, NULL, NULL, NULL, NULL
78
static bool tst_test_script_run_registered
79
(struct sieve_validator *validator, struct sieve_command_registration *cmd_reg)
81
sieve_validator_register_tag
82
(validator, cmd_reg, &append_result_tag, OPT_APPEND_RESULT);
92
static bool tst_test_script_run_generate
93
(const struct sieve_codegen_env *cgenv,
94
struct sieve_command_context *tst)
96
sieve_operation_emit_code(cgenv->sbin, &test_script_run_operation);
98
return sieve_generate_arguments(cgenv, tst, NULL);
105
static bool tst_test_script_run_operation_dump
106
(const struct sieve_operation *op ATTR_UNUSED,
107
const struct sieve_dumptime_env *denv, sieve_size_t *address)
111
sieve_code_dumpf(denv, "TEST_SCRIPT_RUN");
112
sieve_code_descend(denv);
114
/* Dump optional operands */
115
if ( sieve_operand_optional_present(denv->sbin, address) ) {
116
while ( opt_code != 0 ) {
117
sieve_code_mark(denv);
119
if ( !sieve_operand_optional_read(denv->sbin, address, &opt_code) )
122
switch ( opt_code ) {
125
case OPT_APPEND_RESULT:
126
sieve_code_dumpf(denv, "append_result");
143
static int tst_test_script_run_operation_execute
144
(const struct sieve_operation *op ATTR_UNUSED,
145
const struct sieve_runtime_env *renv,
146
sieve_size_t *address ATTR_UNUSED)
148
bool append_result = FALSE;
156
/* Optional operands */
157
if ( sieve_operand_optional_present(renv->sbin, address) ) {
158
while ( opt_code != 0 ) {
159
if ( !sieve_operand_optional_read(renv->sbin, address, &opt_code) ) {
160
sieve_runtime_trace_error(renv, "invalid optional operand");
161
return SIEVE_EXEC_BIN_CORRUPT;
164
switch ( opt_code ) {
167
case OPT_APPEND_RESULT:
168
append_result = TRUE;
171
sieve_runtime_trace_error(renv,
172
"unknown optional operand");
173
return SIEVE_EXEC_BIN_CORRUPT;
182
/* Reset result object */
183
if ( !append_result )
184
testsuite_result_reset(renv);
187
result = testsuite_script_run(renv);
189
/* Indicate test status */
190
sieve_interpreter_set_test_result(renv->interp, result);
192
return SIEVE_EXEC_OK;