/src/pigeonhole/src/lib-sieve/cmd-keep.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | #include "lib.h" |
4 | | |
5 | | #include "sieve-common.h" |
6 | | #include "sieve-commands.h" |
7 | | #include "sieve-code.h" |
8 | | #include "sieve-dump.h" |
9 | | #include "sieve-message.h" |
10 | | #include "sieve-actions.h" |
11 | | #include "sieve-validator.h" |
12 | | #include "sieve-generator.h" |
13 | | #include "sieve-interpreter.h" |
14 | | #include "sieve-result.h" |
15 | | |
16 | | /* |
17 | | * Keep command |
18 | | * |
19 | | * Syntax: |
20 | | * keep |
21 | | */ |
22 | | |
23 | | static bool |
24 | | cmd_keep_generate(const struct sieve_codegen_env *cgenv, |
25 | | struct sieve_command *cmd); |
26 | | |
27 | | const struct sieve_command_def cmd_keep = { |
28 | | .identifier = "keep", |
29 | | .type = SCT_COMMAND, |
30 | | .positional_args = 0, |
31 | | .subtests = 0, |
32 | | .block_allowed = FALSE, |
33 | | .block_required = FALSE, |
34 | | .generate = cmd_keep_generate |
35 | | }; |
36 | | |
37 | | /* |
38 | | * Keep operation |
39 | | */ |
40 | | |
41 | | static bool |
42 | | cmd_keep_operation_dump(const struct sieve_dumptime_env *denv, |
43 | | sieve_size_t *address); |
44 | | static int |
45 | | cmd_keep_operation_execute(const struct sieve_runtime_env *renv, |
46 | | sieve_size_t *address); |
47 | | |
48 | | const struct sieve_operation_def cmd_keep_operation = { |
49 | | .mnemonic = "KEEP", |
50 | | .code = SIEVE_OPERATION_KEEP, |
51 | | .dump = cmd_keep_operation_dump, |
52 | | .execute = cmd_keep_operation_execute |
53 | | }; |
54 | | |
55 | | /* |
56 | | * Code generation |
57 | | */ |
58 | | |
59 | | static bool |
60 | | cmd_keep_generate(const struct sieve_codegen_env *cgenv, |
61 | | struct sieve_command *cmd) |
62 | 0 | { |
63 | | /* Emit opcode */ |
64 | 0 | sieve_operation_emit(cgenv->sblock, NULL, &cmd_keep_operation); |
65 | | |
66 | | /* Generate arguments */ |
67 | 0 | return sieve_generate_arguments(cgenv, cmd, NULL); |
68 | 0 | } |
69 | | |
70 | | /* |
71 | | * Code dump |
72 | | */ |
73 | | |
74 | | static bool |
75 | | cmd_keep_operation_dump(const struct sieve_dumptime_env *denv, |
76 | | sieve_size_t *address) |
77 | 0 | { |
78 | 0 | sieve_code_dumpf(denv, "KEEP"); |
79 | 0 | sieve_code_descend(denv); |
80 | |
|
81 | 0 | return (sieve_action_opr_optional_dump(denv, address, NULL) == 0); |
82 | 0 | } |
83 | | |
84 | | /* |
85 | | * Interpretation |
86 | | */ |
87 | | |
88 | | static int |
89 | | cmd_keep_operation_execute(const struct sieve_runtime_env *renv, |
90 | | sieve_size_t *address) |
91 | 0 | { |
92 | 0 | struct sieve_side_effects_list *slist = NULL; |
93 | 0 | int ret = 0; |
94 | | |
95 | | /* |
96 | | * Read data |
97 | | */ |
98 | | |
99 | | /* Optional operands (side effects only) */ |
100 | 0 | if (sieve_action_opr_optional_read(renv, address, NULL, |
101 | 0 | &ret, &slist) != 0) |
102 | 0 | return ret; |
103 | | |
104 | | /* |
105 | | * Perform operation |
106 | | */ |
107 | | |
108 | 0 | sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, |
109 | 0 | "keep action; store message in default mailbox"); |
110 | | |
111 | | /* Add keep action to result. */ |
112 | 0 | if (sieve_result_add_keep(renv, slist) < 0) |
113 | 0 | return SIEVE_EXEC_FAILURE; |
114 | | |
115 | 0 | return SIEVE_EXEC_OK; |
116 | 0 | } |