/src/pigeonhole/src/lib-sieve/plugins/vnd.dovecot/environment/ext-vnd-environment.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | /* Extension vnd.dovecot.environment |
4 | | * --------------------------------- |
5 | | * |
6 | | * Authors: Stephan Bosch |
7 | | * Specification: vendor-defined; |
8 | | * spec-bosch-sieve-dovecot-environment |
9 | | * Implementation: preliminary |
10 | | * Status: experimental |
11 | | * |
12 | | */ |
13 | | |
14 | | #include "lib.h" |
15 | | #include "array.h" |
16 | | #include "settings.h" |
17 | | |
18 | | #include "sieve-extensions.h" |
19 | | #include "sieve-commands.h" |
20 | | #include "sieve-comparators.h" |
21 | | #include "sieve-match-types.h" |
22 | | #include "sieve-address-parts.h" |
23 | | |
24 | | #include "sieve-validator.h" |
25 | | #include "sieve-generator.h" |
26 | | #include "sieve-binary.h" |
27 | | #include "sieve-interpreter.h" |
28 | | #include "sieve-dump.h" |
29 | | |
30 | | #include "sieve-ext-variables.h" |
31 | | |
32 | | #include "ext-vnd-environment-common.h" |
33 | | |
34 | | /* |
35 | | * Extension |
36 | | */ |
37 | | |
38 | | static int |
39 | | ext_vnd_environment_load(const struct sieve_extension *ext, void **context_r); |
40 | | static void |
41 | | ext_vnd_environment_unload(const struct sieve_extension *ext); |
42 | | static bool |
43 | | ext_vnd_environment_validator_load(const struct sieve_extension *ext, |
44 | | struct sieve_validator *valdtr); |
45 | | static bool |
46 | | ext_vnd_environment_interpreter_load(const struct sieve_extension *ext, |
47 | | const struct sieve_runtime_env *renv, |
48 | | sieve_size_t *address); |
49 | | |
50 | | const struct sieve_extension_def vnd_environment_extension = { |
51 | | .name = "vnd.dovecot.environment", |
52 | | .load = ext_vnd_environment_load, |
53 | | .unload = ext_vnd_environment_unload, |
54 | | .validator_load = ext_vnd_environment_validator_load, |
55 | | .interpreter_load = ext_vnd_environment_interpreter_load, |
56 | | SIEVE_EXT_DEFINE_OPERAND(environment_namespace_operand), |
57 | | }; |
58 | | |
59 | | static int |
60 | | ext_vnd_environment_load(const struct sieve_extension *ext, void **context_r) |
61 | 0 | { |
62 | 0 | const struct sieve_extension *ext_env; |
63 | 0 | const struct sieve_extension *ext_var; |
64 | 0 | struct sieve_instance *svinst = ext->svinst; |
65 | 0 | struct ext_vnd_environment_context *extctx; |
66 | 0 | const struct ext_vnd_environment_settings *set; |
67 | 0 | const char *error; |
68 | |
|
69 | 0 | if (sieve_ext_environment_require_extension(ext->svinst, &ext_env) < 0) |
70 | 0 | return -1; |
71 | 0 | if (sieve_ext_variables_get_extension(ext->svinst, &ext_var) < 0) |
72 | 0 | return -1; |
73 | | |
74 | 0 | if (settings_get(svinst->event, |
75 | 0 | &ext_vnd_environment_setting_parser_info, 0, |
76 | 0 | &set, &error) < 0) { |
77 | 0 | e_error(svinst->event, "%s", error); |
78 | 0 | return -1; |
79 | 0 | } |
80 | | |
81 | 0 | extctx = i_new(struct ext_vnd_environment_context, 1); |
82 | 0 | extctx->set = set; |
83 | 0 | extctx->env_ext = ext_env; |
84 | 0 | extctx->var_ext = ext_var; |
85 | |
|
86 | 0 | *context_r = extctx; |
87 | 0 | return 0; |
88 | 0 | } |
89 | | |
90 | | static void ext_vnd_environment_unload(const struct sieve_extension *ext) |
91 | 0 | { |
92 | 0 | struct ext_vnd_environment_context *extctx = ext->context; |
93 | |
|
94 | 0 | if (extctx == NULL) |
95 | 0 | return; |
96 | 0 | settings_free(extctx->set); |
97 | 0 | i_free(extctx); |
98 | 0 | } |
99 | | |
100 | | /* |
101 | | * Validator |
102 | | */ |
103 | | |
104 | | static bool |
105 | | ext_vnd_environment_validator_load(const struct sieve_extension *ext, |
106 | | struct sieve_validator *valdtr) |
107 | 0 | { |
108 | 0 | const struct sieve_extension *env_ext; |
109 | | |
110 | | /* Load environment extension implicitly */ |
111 | |
|
112 | 0 | env_ext = sieve_validator_extension_load_implicit( |
113 | 0 | valdtr, environment_extension.name); |
114 | 0 | if (env_ext == NULL) |
115 | 0 | return FALSE; |
116 | | |
117 | 0 | ext_environment_variables_init(ext, valdtr); |
118 | 0 | return TRUE; |
119 | 0 | } |
120 | | |
121 | | /* |
122 | | * Interpreter |
123 | | */ |
124 | | |
125 | | static bool |
126 | | ext_vnd_environment_interpreter_load(const struct sieve_extension *ext, |
127 | | const struct sieve_runtime_env *renv, |
128 | | sieve_size_t *address ATTR_UNUSED) |
129 | 0 | { |
130 | 0 | ext_vnd_environment_items_register(ext, renv); |
131 | 0 | return TRUE; |
132 | 0 | } |