/src/pigeonhole/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | /* Extensions spamtest, spamtestplus and virustest |
4 | | * ----------------------------------------------- |
5 | | * |
6 | | * Authors: Stephan Bosch |
7 | | * Specification: RFC 5235 |
8 | | * Implementation: full |
9 | | * Status: testing |
10 | | * |
11 | | */ |
12 | | |
13 | | #include "lib.h" |
14 | | #include "array.h" |
15 | | |
16 | | #include "sieve-common.h" |
17 | | |
18 | | #include "sieve-extensions.h" |
19 | | #include "sieve-commands.h" |
20 | | |
21 | | #include "sieve-validator.h" |
22 | | |
23 | | #include "ext-spamvirustest-common.h" |
24 | | |
25 | | /* |
26 | | * Extensions |
27 | | */ |
28 | | |
29 | | /* Spamtest */ |
30 | | |
31 | | static bool |
32 | | ext_spamvirustest_validator_load(const struct sieve_extension *ext, |
33 | | struct sieve_validator *validator); |
34 | | |
35 | | const struct sieve_extension_def spamtest_extension = { |
36 | | .name = "spamtest", |
37 | | .load = ext_spamvirustest_load, |
38 | | .unload = ext_spamvirustest_unload, |
39 | | .validator_load = ext_spamvirustest_validator_load, |
40 | | SIEVE_EXT_DEFINE_OPERATION(spamtest_operation), |
41 | | }; |
42 | | |
43 | | const struct sieve_extension_def spamtestplus_extension = { |
44 | | .name = "spamtestplus", |
45 | | .load = ext_spamvirustest_load, |
46 | | .unload = ext_spamvirustest_unload, |
47 | | .validator_load = ext_spamvirustest_validator_load, |
48 | | SIEVE_EXT_DEFINE_OPERATION(spamtest_operation), |
49 | | }; |
50 | | |
51 | | const struct sieve_extension_def virustest_extension = { |
52 | | .name = "virustest", |
53 | | .load = ext_spamvirustest_load, |
54 | | .unload = ext_spamvirustest_unload, |
55 | | .validator_load = ext_spamvirustest_validator_load, |
56 | | SIEVE_EXT_DEFINE_OPERATION(virustest_operation), |
57 | | }; |
58 | | |
59 | | /* |
60 | | * Implementation |
61 | | */ |
62 | | |
63 | | static bool |
64 | | ext_spamtest_validator_check_conflict(const struct sieve_extension *ext, |
65 | | struct sieve_validator *valdtr, |
66 | | void *context, |
67 | | struct sieve_ast_argument *require_arg, |
68 | | const struct sieve_extension *ext_other, |
69 | | bool required); |
70 | | |
71 | | const struct sieve_validator_extension spamtest_validator_extension = { |
72 | | .ext = &spamtest_extension, |
73 | | .check_conflict = ext_spamtest_validator_check_conflict, |
74 | | }; |
75 | | |
76 | | static bool |
77 | | ext_spamvirustest_validator_load(const struct sieve_extension *ext, |
78 | | struct sieve_validator *valdtr) |
79 | 0 | { |
80 | | /* Register new test */ |
81 | |
|
82 | 0 | if (sieve_extension_is(ext, virustest_extension)) { |
83 | 0 | sieve_validator_register_command(valdtr, ext, &virustest_test); |
84 | 0 | } else { |
85 | 0 | if (sieve_extension_is(ext, spamtest_extension)) { |
86 | | /* Register validator extension to warn for duplicate */ |
87 | 0 | sieve_validator_extension_register( |
88 | 0 | valdtr, ext, &spamtest_validator_extension, |
89 | 0 | NULL); |
90 | 0 | } |
91 | |
|
92 | 0 | sieve_validator_register_command(valdtr, ext, &spamtest_test); |
93 | 0 | } |
94 | 0 | return TRUE; |
95 | 0 | } |
96 | | |
97 | | static bool |
98 | | ext_spamtest_validator_check_conflict( |
99 | | const struct sieve_extension *ext ATTR_UNUSED, |
100 | | struct sieve_validator *valdtr, void *context ATTR_UNUSED, |
101 | | struct sieve_ast_argument *require_arg, |
102 | | const struct sieve_extension *ext_other, bool required ATTR_UNUSED) |
103 | 0 | { |
104 | 0 | if (sieve_extension_name_is(ext_other, "spamtestplus")) { |
105 | 0 | sieve_argument_validate_warning( |
106 | 0 | valdtr, require_arg, |
107 | 0 | "the spamtest and spamtestplus extensions should " |
108 | 0 | "not be specified at the same time"); |
109 | 0 | } |
110 | 0 | return TRUE; |
111 | 0 | } |