~ubuntu-branches/ubuntu/quantal/dovecot/quantal

« back to all changes in this revision

Viewing changes to sieve/src/lib-sieve/plugins/variables/ext-variables-operands.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-29 09:21:32 UTC
  • mfrom: (4.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20100629092132-q4pr5lfuvmjqou19
Tags: 1:1.2.12-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  + Add mail-stack-delivery as per server-maverick-mail-integration spec:
   - Update debian/rules
   - Convert existing package to a dummy package and add new binary in debian/control
   - Update maintainer scripts.
   - Move previously installed backups and config files to new package name
     space in preinst
   - Add new debian/mail-stack-delivery.prerm to handle downgrades
   - Rename debian/dovecot-postfix.* to debian/mail-stack-delivery.*
  + Use Snakeoil SSL certificates by default.
    - debian/control: Depend on ssl-cert.
    - debian/patches/ssl-cert-snakeoil.dpatch: Change default SSL cert paths to snakeoil.
    - debian/dovecot-common.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - Created debian/dovecot-common.ufw.profile.
    - debian/rules: install profile.
    - debian/control: suggest ufw.
  + debian/{control,rules}: enable PIE hardening.
  + debian/control: Update Vcs-* headers.
  + Add SMTP-AUTH support for Outlook (login auth mechanism) 
  + debian/dovecot-common.dirs: Added usr/share/doc/dovecot-common
  + debian/patches/fix-dovecot-config-parser.patch: Fix ordering of external config 
    files. (LP: #597818)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "ext-variables-dump.h"
25
25
#include "ext-variables-operands.h"
26
26
 
27
 
/* 
28
 
 * Variable operand 
 
27
/*
 
28
 * Variable operand
29
29
 */
30
30
 
31
31
static bool opr_variable_read_value
35
35
        (const struct sieve_dumptime_env *denv, const struct sieve_operand *operand,
36
36
                sieve_size_t *address, const char *field_name);
37
37
 
38
 
const struct sieve_opr_string_interface variable_interface = { 
 
38
const struct sieve_opr_string_interface variable_interface = {
39
39
        opr_variable_dump,
40
40
        opr_variable_read_value
41
41
};
42
 
                
43
 
const struct sieve_operand_def variable_operand = { 
44
 
        "variable", 
45
 
        &variables_extension, 
 
42
 
 
43
const struct sieve_operand_def variable_operand = {
 
44
        "variable",
 
45
        &variables_extension,
46
46
        EXT_VARIABLES_OPERAND_VARIABLE,
47
47
        &string_class,
48
48
        &variable_interface
49
49
};
50
50
 
51
51
void sieve_variables_opr_variable_emit
52
 
(struct sieve_binary *sbin, const struct sieve_extension *var_ext, 
53
 
        struct sieve_variable *var) 
 
52
(struct sieve_binary *sbin, const struct sieve_extension *var_ext,
 
53
        struct sieve_variable *var)
54
54
{
55
55
        if ( var->ext == NULL ) {
56
56
                /* Default variable storage */
58
58
                (void) sieve_binary_emit_byte(sbin, 0); /* Default */
59
59
                (void) sieve_binary_emit_unsigned(sbin, var->index);
60
60
                return;
61
 
        } 
 
61
        }
62
62
 
63
63
        (void) sieve_operand_emit(sbin, var_ext, &variable_operand);
64
64
        (void) sieve_binary_emit_extension(sbin, var->ext, 1); /* Extension */
67
67
 
68
68
static bool opr_variable_dump
69
69
(const struct sieve_dumptime_env *denv, const struct sieve_operand *operand,
70
 
        sieve_size_t *address, const char *field_name) 
 
70
        sieve_size_t *address, const char *field_name)
71
71
{
72
72
        const struct sieve_extension *this_ext = operand->ext;
73
73
        unsigned int index = 0;
77
77
 
78
78
        if ( !sieve_binary_read_extension(denv->sbin, address, &code, &ext) )
79
79
                return FALSE;
80
 
        
 
80
 
81
81
        if ( !sieve_binary_read_unsigned(denv->sbin, address, &index) )
82
82
                return FALSE;
83
 
                
 
83
 
84
84
        identifier = ext_variables_dump_get_identifier(this_ext, denv, ext, index);
85
85
        identifier = identifier == NULL ? "??" : identifier;
86
86
 
87
 
        if ( ext == NULL ) {            
88
 
                if ( field_name != NULL ) 
89
 
                        sieve_code_dumpf(denv, "%s: VAR ${%s} (%ld)", 
 
87
        if ( ext == NULL ) {
 
88
                if ( field_name != NULL )
 
89
                        sieve_code_dumpf(denv, "%s: VAR ${%s} (%ld)",
90
90
                                field_name, identifier, (long) index);
91
91
                else
92
 
                        sieve_code_dumpf(denv, "VAR ${%s} (%ld)", 
 
92
                        sieve_code_dumpf(denv, "VAR ${%s} (%ld)",
93
93
                                identifier, (long) index);
94
94
        } else {
95
 
                if ( field_name != NULL ) 
96
 
                        sieve_code_dumpf(denv, "%s: VAR [%s] ${%s} (%ld)", 
 
95
                if ( field_name != NULL )
 
96
                        sieve_code_dumpf(denv, "%s: VAR [%s] ${%s} (%ld)",
97
97
                                field_name, sieve_extension_name(ext), identifier, (long) index);
98
98
                else
99
 
                        sieve_code_dumpf(denv, "VAR [%s] ${%s} (%ld)", 
 
99
                        sieve_code_dumpf(denv, "VAR [%s] ${%s} (%ld)",
100
100
                                sieve_extension_name(ext), identifier, (long) index);
101
101
        }
102
102
        return TRUE;
105
105
static bool opr_variable_read_value
106
106
(const struct sieve_runtime_env *renv, const struct sieve_operand *operand,
107
107
        sieve_size_t *address, string_t **str)
108
 
 
108
{
109
109
        const struct sieve_extension *this_ext = operand->ext;
110
110
        const struct sieve_extension *ext;
111
111
        unsigned int code = 1; /* Initially set to offset value */
112
112
        struct sieve_variable_storage *storage;
113
113
        unsigned int index = 0;
114
 
        
 
114
 
115
115
        if ( !sieve_binary_read_extension(renv->sbin, address, &code, &ext) )
116
116
                return FALSE;
117
117
 
118
118
        storage = sieve_ext_variables_get_storage(this_ext, renv->interp, ext);
119
 
        if ( storage == NULL ) 
 
119
        if ( storage == NULL )
120
120
                return FALSE;
121
 
        
 
121
 
122
122
        if (sieve_binary_read_unsigned(renv->sbin, address, &index) ) {
123
 
                /* Parameter str can be NULL if we are requested to only skip and not 
 
123
                /* Parameter str can be NULL if we are requested to only skip and not
124
124
                 * actually read the argument.
125
125
                 */
126
126
                if ( str != NULL ) {
127
127
                        if ( !sieve_variable_get(storage, index, str) )
128
128
                                return FALSE;
129
 
                
 
129
 
130
130
                        if ( *str == NULL ) *str = t_str_new(0);
131
131
                }
132
132
                return TRUE;
133
133
        }
134
 
        
 
134
 
135
135
        return FALSE;
136
136
}
137
 
                
 
137
 
138
138
bool sieve_variable_operand_read_data
139
 
(const struct sieve_runtime_env *renv, const struct sieve_operand *operand, 
140
 
        sieve_size_t *address, struct sieve_variable_storage **storage, 
 
139
(const struct sieve_runtime_env *renv, const struct sieve_operand *operand,
 
140
        sieve_size_t *address, struct sieve_variable_storage **storage,
141
141
        unsigned int *var_index)
142
142
{
143
143
        const struct sieve_extension *ext;
150
150
 
151
151
        if ( !sieve_binary_read_extension(renv->sbin, address, &code, &ext) )
152
152
                return FALSE;
153
 
                
 
153
 
154
154
        *storage = sieve_ext_variables_get_storage(operand->ext, renv->interp, ext);
155
 
        if ( *storage == NULL ) 
 
155
        if ( *storage == NULL )
156
156
                return FALSE;
157
 
        
 
157
 
158
158
        if ( !sieve_binary_read_unsigned(renv->sbin, address, &idx) )
159
 
                return FALSE;           
 
159
                return FALSE;
160
160
 
161
161
        *var_index = idx;
162
162
        return TRUE;
163
163
}
164
164
 
165
165
bool sieve_variable_operand_read
166
 
(const struct sieve_runtime_env *renv, sieve_size_t *address, 
 
166
(const struct sieve_runtime_env *renv, sieve_size_t *address,
167
167
        struct sieve_variable_storage **storage, unsigned int *var_index)
168
168
{
169
169
        struct sieve_operand operand;
174
174
        return sieve_variable_operand_read_data
175
175
                (renv, &operand, address, storage, var_index);
176
176
}
177
 
        
178
 
/* 
179
 
 * Match value operand 
 
177
 
 
178
/*
 
179
 * Match value operand
180
180
 */
181
181
 
182
182
static bool opr_match_value_read
186
186
        (const struct sieve_dumptime_env *denv,  const struct sieve_operand *operand,
187
187
                sieve_size_t *address, const char *field_name);
188
188
 
189
 
const struct sieve_opr_string_interface match_value_interface = { 
 
189
const struct sieve_opr_string_interface match_value_interface = {
190
190
        opr_match_value_dump,
191
191
        opr_match_value_read
192
192
};
193
 
                
194
 
const struct sieve_operand_def match_value_operand = { 
195
 
        "match-value", 
196
 
        &variables_extension, 
 
193
 
 
194
const struct sieve_operand_def match_value_operand = {
 
195
        "match-value",
 
196
        &variables_extension,
197
197
        EXT_VARIABLES_OPERAND_MATCH_VALUE,
198
198
        &string_class,
199
199
        &match_value_interface
200
 
};      
 
200
};
201
201
 
202
202
void sieve_variables_opr_match_value_emit
203
 
(struct sieve_binary *sbin, const struct sieve_extension *var_ext, 
204
 
        unsigned int index) 
 
203
(struct sieve_binary *sbin, const struct sieve_extension *var_ext,
 
204
        unsigned int index)
205
205
{
206
206
        (void) sieve_operand_emit(sbin, var_ext, &match_value_operand);
207
207
        (void) sieve_binary_emit_unsigned(sbin, index);
210
210
static bool opr_match_value_dump
211
211
(const struct sieve_dumptime_env *denv,
212
212
        const struct sieve_operand *operand ATTR_UNUSED,
213
 
        sieve_size_t *address, const char *field_name) 
 
213
        sieve_size_t *address, const char *field_name)
214
214
{
215
215
        unsigned int index = 0;
216
 
        
 
216
 
217
217
        if (sieve_binary_read_unsigned(denv->sbin, address, &index) ) {
218
218
                if ( field_name != NULL )
219
219
                        sieve_code_dumpf
223
223
 
224
224
                return TRUE;
225
225
        }
226
 
        
 
226
 
227
227
        return FALSE;
228
228
}
229
229
 
230
230
static bool opr_match_value_read
231
 
(const struct sieve_runtime_env *renv, 
 
231
(const struct sieve_runtime_env *renv,
232
232
        const struct sieve_operand *operand ATTR_UNUSED,
233
233
        sieve_size_t *address, string_t **str)
234
 
 
234
{
235
235
        unsigned int index = 0;
236
 
                        
 
236
 
237
237
        if (sieve_binary_read_unsigned(renv->sbin, address, &index) ) {
238
 
                /* Parameter str can be NULL if we are requested to only skip and not 
 
238
                /* Parameter str can be NULL if we are requested to only skip and not
239
239
                 * actually read the argument.
240
240
                        */
241
241
                if ( str != NULL ) {
242
242
                        sieve_match_values_get(renv->interp, index, str);
243
 
                
244
 
                        if ( *str == NULL ) 
 
243
 
 
244
                        if ( *str == NULL )
245
245
                                *str = t_str_new(0);
246
 
                        else if ( str_len(*str) > EXT_VARIABLES_MAX_VARIABLE_SIZE ) 
 
246
                        else if ( str_len(*str) > EXT_VARIABLES_MAX_VARIABLE_SIZE )
247
247
                                str_truncate(*str, EXT_VARIABLES_MAX_VARIABLE_SIZE);
248
248
                }
249
249
                return TRUE;
250
250
        }
251
 
        
 
251
 
252
252
        return FALSE;
253
253
}