/src/pigeonhole/src/lib-sieve/plugins/include/ext-include.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | /* Extension include |
4 | | * ----------------- |
5 | | * |
6 | | * Authors: Stephan Bosch |
7 | | * Specification: RFC 6609 |
8 | | * Implementation: full |
9 | | * Status: testing |
10 | | * |
11 | | */ |
12 | | |
13 | | /* FIXME: Current include implementation does not allow for parts of the script |
14 | | to be located in external binaries; all included scripts are recompiled and |
15 | | the resulting byte code is imported into the main binary in separate blocks. |
16 | | */ |
17 | | |
18 | | #include "lib.h" |
19 | | |
20 | | #include "sieve-common.h" |
21 | | |
22 | | #include "sieve-extensions.h" |
23 | | #include "sieve-validator.h" |
24 | | #include "sieve-generator.h" |
25 | | #include "sieve-interpreter.h" |
26 | | #include "sieve-binary.h" |
27 | | #include "sieve-dump.h" |
28 | | |
29 | | #include "sieve-ext-variables.h" |
30 | | |
31 | | #include "ext-include-common.h" |
32 | | #include "ext-include-binary.h" |
33 | | #include "ext-include-variables.h" |
34 | | |
35 | | /* |
36 | | * Operations |
37 | | */ |
38 | | |
39 | | static const struct sieve_operation_def *ext_include_operations[] = { |
40 | | &include_operation, |
41 | | &return_operation, |
42 | | &global_operation, |
43 | | }; |
44 | | |
45 | | /* |
46 | | * Extension |
47 | | */ |
48 | | |
49 | | /* Forward declaration */ |
50 | | |
51 | | static bool |
52 | | ext_include_validator_load(const struct sieve_extension *ext, |
53 | | struct sieve_validator *validator); |
54 | | static bool |
55 | | ext_include_generator_load(const struct sieve_extension *ext, |
56 | | const struct sieve_codegen_env *cgenv); |
57 | | static bool |
58 | | ext_include_interpreter_load(const struct sieve_extension *ext, |
59 | | const struct sieve_runtime_env *renv, |
60 | | sieve_size_t *address); |
61 | | static bool |
62 | | ext_include_binary_load(const struct sieve_extension *ext, |
63 | | struct sieve_binary *binary); |
64 | | |
65 | | /* Extension objects */ |
66 | | |
67 | | const struct sieve_extension_def include_extension = { |
68 | | .name = "include", |
69 | | .version = 2, |
70 | | |
71 | | .load = ext_include_load, |
72 | | .unload = ext_include_unload, |
73 | | .validator_load = ext_include_validator_load, |
74 | | .generator_load = ext_include_generator_load, |
75 | | .interpreter_load = ext_include_interpreter_load, |
76 | | .binary_load = ext_include_binary_load, |
77 | | .binary_dump = ext_include_binary_dump, |
78 | | .code_dump = ext_include_code_dump, |
79 | | |
80 | | SIEVE_EXT_DEFINE_OPERATIONS(ext_include_operations), |
81 | | }; |
82 | | |
83 | | static bool |
84 | | ext_include_validator_load(const struct sieve_extension *ext, |
85 | | struct sieve_validator *valdtr) |
86 | 0 | { |
87 | | /* Register new commands */ |
88 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_include); |
89 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_return); |
90 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_global); |
91 | | |
92 | | /* Initialize global variables namespace */ |
93 | 0 | ext_include_variables_global_namespace_init(ext, valdtr); |
94 | |
|
95 | 0 | return TRUE; |
96 | 0 | } |
97 | | |
98 | | static bool |
99 | | ext_include_generator_load(const struct sieve_extension *ext, |
100 | | const struct sieve_codegen_env *cgenv) |
101 | 0 | { |
102 | 0 | ext_include_register_generator_context(ext, cgenv); |
103 | |
|
104 | 0 | return TRUE; |
105 | 0 | } |
106 | | |
107 | | static bool |
108 | | ext_include_interpreter_load(const struct sieve_extension *ext, |
109 | | const struct sieve_runtime_env *renv, |
110 | | sieve_size_t *address ATTR_UNUSED) |
111 | 0 | { |
112 | 0 | ext_include_interpreter_context_init(ext, renv->interp); |
113 | |
|
114 | 0 | return TRUE; |
115 | 0 | } |
116 | | |
117 | | static bool |
118 | | ext_include_binary_load(const struct sieve_extension *ext, |
119 | | struct sieve_binary *sbin) |
120 | 0 | { |
121 | 0 | (void)ext_include_binary_get_context(ext, sbin); |
122 | |
|
123 | 0 | return TRUE; |
124 | 0 | } |