/src/pigeonhole/src/lib-sieve/cmd-stop.c
Line | Count | Source |
1 | | /* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file |
2 | | */ |
3 | | |
4 | | #include "sieve-common.h" |
5 | | #include "sieve-commands.h" |
6 | | #include "sieve-code.h" |
7 | | #include "sieve-generator.h" |
8 | | #include "sieve-interpreter.h" |
9 | | |
10 | | /* |
11 | | * Stop command |
12 | | * |
13 | | * Syntax |
14 | | * stop |
15 | | */ |
16 | | |
17 | | static bool cmd_stop_generate |
18 | | (const struct sieve_codegen_env *cgenv, |
19 | | struct sieve_command *ctx ATTR_UNUSED); |
20 | | static bool cmd_stop_validate |
21 | | (struct sieve_validator *valdtr, struct sieve_command *cmd); |
22 | | |
23 | | const struct sieve_command_def cmd_stop = { |
24 | | .identifier = "stop", |
25 | | .type = SCT_COMMAND, |
26 | | .positional_args = 0, |
27 | | .subtests = 0, |
28 | | .block_allowed = FALSE, |
29 | | .block_required = FALSE, |
30 | | .validate = cmd_stop_validate, |
31 | | .generate = cmd_stop_generate |
32 | | }; |
33 | | |
34 | | /* |
35 | | * Stop operation |
36 | | */ |
37 | | |
38 | | static int opc_stop_execute |
39 | | (const struct sieve_runtime_env *renv, sieve_size_t *address); |
40 | | |
41 | | const struct sieve_operation_def cmd_stop_operation = { |
42 | | .mnemonic = "STOP", |
43 | | .code = SIEVE_OPERATION_STOP, |
44 | | .execute = opc_stop_execute |
45 | | }; |
46 | | |
47 | | /* |
48 | | * Command validation |
49 | | */ |
50 | | |
51 | | static bool cmd_stop_validate |
52 | | (struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) |
53 | 0 | { |
54 | 0 | sieve_command_exit_block_unconditionally(cmd); |
55 | |
|
56 | 0 | return TRUE; |
57 | 0 | } |
58 | | |
59 | | /* |
60 | | * Code generation |
61 | | */ |
62 | | |
63 | | static bool cmd_stop_generate |
64 | | (const struct sieve_codegen_env *cgenv, |
65 | | struct sieve_command *cmd ATTR_UNUSED) |
66 | 0 | { |
67 | 0 | sieve_operation_emit(cgenv->sblock, NULL, &cmd_stop_operation); |
68 | |
|
69 | 0 | return TRUE; |
70 | 0 | } |
71 | | |
72 | | /* |
73 | | * Code execution |
74 | | */ |
75 | | |
76 | | static int opc_stop_execute |
77 | | (const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) |
78 | 0 | { |
79 | 0 | sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, |
80 | 0 | "stop command; end all script execution"); |
81 | |
|
82 | 0 | sieve_interpreter_interrupt(renv->interp); |
83 | |
|
84 | 0 | return SIEVE_EXEC_OK; |
85 | 0 | } |
86 | | |