/src/pigeonhole/src/lib-sieve/plugins/enotify/ext-enotify.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | /* Extension enotify |
4 | | * ------------------ |
5 | | * |
6 | | * Authors: Stephan Bosch |
7 | | * Specification: RFC 5435 |
8 | | * Implementation: full |
9 | | * Status: testing |
10 | | * |
11 | | */ |
12 | | |
13 | | #include "sieve-common.h" |
14 | | |
15 | | #include "settings.h" |
16 | | |
17 | | #include "sieve-code.h" |
18 | | #include "sieve-extensions.h" |
19 | | #include "sieve-actions.h" |
20 | | #include "sieve-commands.h" |
21 | | #include "sieve-validator.h" |
22 | | #include "sieve-generator.h" |
23 | | #include "sieve-interpreter.h" |
24 | | #include "sieve-result.h" |
25 | | |
26 | | #include "sieve-ext-variables.h" |
27 | | |
28 | | #include "ext-enotify-common.h" |
29 | | |
30 | | /* |
31 | | * Operations |
32 | | */ |
33 | | |
34 | | const struct sieve_operation_def *ext_enotify_operations[] = { |
35 | | ¬ify_operation, |
36 | | &valid_notify_method_operation, |
37 | | ¬ify_method_capability_operation, |
38 | | }; |
39 | | |
40 | | /* |
41 | | * Extension |
42 | | */ |
43 | | |
44 | | static int |
45 | | ext_enotify_load(const struct sieve_extension *ext, void **context_r); |
46 | | static void ext_enotify_unload(const struct sieve_extension *ext); |
47 | | static bool |
48 | | ext_enotify_validator_load(const struct sieve_extension *ext, |
49 | | struct sieve_validator *valdtr); |
50 | | |
51 | | const struct sieve_extension_def enotify_extension = { |
52 | | .name = "enotify", |
53 | | .load = ext_enotify_load, |
54 | | .unload = ext_enotify_unload, |
55 | | .validator_load = ext_enotify_validator_load, |
56 | | SIEVE_EXT_DEFINE_OPERATIONS(ext_enotify_operations), |
57 | | SIEVE_EXT_DEFINE_OPERAND(encodeurl_operand), |
58 | | }; |
59 | | |
60 | | static int ext_enotify_load(const struct sieve_extension *ext, void **context_r) |
61 | 0 | { |
62 | 0 | struct sieve_instance *svinst = ext->svinst; |
63 | 0 | const struct sieve_extension *var_ext; |
64 | 0 | const struct ext_enotify_settings *set; |
65 | 0 | struct ext_enotify_context *extctx; |
66 | 0 | const char *error; |
67 | |
|
68 | 0 | if (sieve_ext_variables_get_extension(ext->svinst, &var_ext) < 0) |
69 | 0 | return -1; |
70 | | |
71 | 0 | if (settings_get(svinst->event, &ext_enotify_setting_parser_info, 0, |
72 | 0 | &set, &error) < 0) { |
73 | 0 | e_error(svinst->event, "%s", error); |
74 | 0 | return -1; |
75 | 0 | } |
76 | | |
77 | 0 | extctx = i_new(struct ext_enotify_context, 1); |
78 | 0 | extctx->var_ext = var_ext; |
79 | 0 | extctx->set = set; |
80 | |
|
81 | 0 | if (ext_enotify_methods_init(extctx, ext) < 0) { |
82 | 0 | settings_free(extctx->set); |
83 | 0 | i_free(extctx); |
84 | 0 | return -1; |
85 | 0 | } |
86 | | |
87 | 0 | sieve_extension_capabilities_register(ext, ¬ify_capabilities); |
88 | |
|
89 | 0 | *context_r = extctx; |
90 | 0 | return 0; |
91 | 0 | } |
92 | | |
93 | | static void ext_enotify_unload(const struct sieve_extension *ext) |
94 | 0 | { |
95 | 0 | struct ext_enotify_context *extctx = ext->context; |
96 | |
|
97 | 0 | if (extctx == NULL) |
98 | 0 | return; |
99 | | |
100 | 0 | ext_enotify_methods_deinit(extctx); |
101 | 0 | settings_free(extctx->set); |
102 | 0 | i_free(extctx); |
103 | 0 | } |
104 | | |
105 | | static bool |
106 | | ext_enotify_validator_load(const struct sieve_extension *ext, |
107 | | struct sieve_validator *valdtr) |
108 | 0 | { |
109 | 0 | struct ext_enotify_context *extctx = ext->context; |
110 | | |
111 | | /* Register new commands */ |
112 | 0 | sieve_validator_register_command(valdtr, ext, |
113 | 0 | ¬ify_command); |
114 | 0 | sieve_validator_register_command(valdtr, ext, |
115 | 0 | &valid_notify_method_test); |
116 | 0 | sieve_validator_register_command(valdtr, ext, |
117 | 0 | ¬ify_method_capability_test); |
118 | | |
119 | | /* Register new set modifier for variables extension */ |
120 | 0 | sieve_variables_modifier_register(extctx->var_ext, valdtr, ext, |
121 | 0 | &encodeurl_modifier); |
122 | |
|
123 | 0 | return TRUE; |
124 | 0 | } |