43
43
struct sieve_binary_extension_reg {
44
44
/* The identifier of the extension within this binary */
47
47
/* Global extension object */
48
const struct sieve_extension *extension;
50
/* Extension to the binary; typically used to manage extension-specific blocks
48
const struct sieve_extension *extension;
50
/* Extension to the binary; typically used to manage extension-specific blocks
51
51
* in the binary and as a means to get a binary_free notification to release
52
* references held by extensions.
52
* references held by extensions.
54
const struct sieve_binary_extension *binext;
54
const struct sieve_binary_extension *binext;
56
56
/* Context data associated to the binary by this extension */
59
59
/* Main block for this extension */
60
60
unsigned int block_id;
83
83
struct sieve_instance *svinst;
85
85
struct sieve_script *script;
87
87
struct sieve_binary_file *file;
89
89
/* When the binary is loaded into memory or when it is being constructed by
90
90
* the generator, extensions can be associated to the binary. The extensions
91
* array is a sequential list of all linked extensions. The extension_index
92
* array is a mapping ext_id -> binary_extension. This is used to obtain the
93
* index code associated with an extension for this particular binary. The
91
* array is a sequential list of all linked extensions. The extension_index
92
* array is a mapping ext_id -> binary_extension. This is used to obtain the
93
* index code associated with an extension for this particular binary. The
94
94
* linked_extensions list all extensions linked to this binary object other
95
* than the preloaded language features implemented as 'extensions'.
97
* All arrays refer to the same extension registration objects. Upon loading
98
* a binary, the 'require'd extensions will sometimes need to associate
99
* context data to the binary object in memory. This is stored in these
95
* than the preloaded language features implemented as 'extensions'.
97
* All arrays refer to the same extension registration objects. Upon loading
98
* a binary, the 'require'd extensions will sometimes need to associate
99
* context data to the binary object in memory. This is stored in these
100
100
* registration objects as well.
102
ARRAY_DEFINE(extensions, struct sieve_binary_extension_reg *);
103
ARRAY_DEFINE(extension_index, struct sieve_binary_extension_reg *);
104
ARRAY_DEFINE(linked_extensions, struct sieve_binary_extension_reg *);
102
ARRAY(struct sieve_binary_extension_reg *) extensions;
103
ARRAY(struct sieve_binary_extension_reg *) extension_index;
104
ARRAY(struct sieve_binary_extension_reg *) linked_extensions;
106
106
/* Attributes of a loaded binary */
107
107
const char *path;
110
ARRAY_DEFINE(blocks, struct sieve_binary_block *);
110
ARRAY(struct sieve_binary_block *) blocks;
113
113
struct sieve_binary *sieve_binary_create
116
116
/* Blocks management */
118
118
static inline struct sieve_binary_block *sieve_binary_block_index
119
(struct sieve_binary *sbin, unsigned int id)
119
(struct sieve_binary *sbin, unsigned int id)
121
121
struct sieve_binary_block * const *sblock;
123
123
if ( id >= array_count(&sbin->blocks) )
126
126
sblock = array_idx(&sbin->blocks, id);
128
128
if ( *sblock == NULL ) {
158
158
ereg = p_new(sbin->pool, struct sieve_binary_extension_reg, 1);
159
159
ereg->index = index;
160
160
ereg->extension = ext;
162
162
array_idx_set(&sbin->extensions, (unsigned int) index, &ereg);
163
163
array_idx_set(&sbin->extension_index, (unsigned int) ext->id, &ereg);
168
static inline struct sieve_binary_extension_reg *sieve_binary_extension_get_reg
169
(struct sieve_binary *sbin, const struct sieve_extension *ext, bool create)
168
static inline struct sieve_binary_extension_reg *sieve_binary_extension_get_reg
169
(struct sieve_binary *sbin, const struct sieve_extension *ext, bool create)
171
171
struct sieve_binary_extension_reg *reg = NULL;
173
173
if ( ext->id >= 0 && ext->id < (int) array_count(&sbin->extension_index) ) {
174
struct sieve_binary_extension_reg * const *ereg =
174
struct sieve_binary_extension_reg * const *ereg =
175
175
array_idx(&sbin->extension_index, (unsigned int) ext->id);
187
187
static inline int sieve_binary_extension_register
188
(struct sieve_binary *sbin, const struct sieve_extension *ext,
189
struct sieve_binary_extension_reg **reg_r)
188
(struct sieve_binary *sbin, const struct sieve_extension *ext,
189
struct sieve_binary_extension_reg **reg_r)
191
191
struct sieve_binary_extension_reg *ereg;
193
193
if ( (ereg=sieve_binary_extension_get_reg(sbin, ext, FALSE)) == NULL ) {
194
194
ereg = sieve_binary_extension_create_reg(sbin, ext);
196
196
if ( ereg == NULL ) return -1;
198
198
array_append(&sbin->linked_extensions, &ereg, 1);