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

« back to all changes in this revision

Viewing changes to sieve/src/testsuite/cmd-test-binary.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short, Scott Kitterman
  • Date: 2010-06-22 10:33:51 UTC
  • mfrom: (1.13.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100622103351-ifbmnklp8kxrhb30
Tags: 1:1.2.12-0ubuntu1
* New upstream release:
  - deliver: Don't crash when a message with Auto-submitted: header gets
   rejected.
  - lib-storage: Fixed header searches to work correctly when there are
    multiple headers with same name.
  - dict client: Disconnect from dict server after 1 second of idling.
  - dict: If process crashed, it wasn't automatically restarted
  - dict file: If dict file's group permissions equal world permissions,
    don't try to change its gid.
  - maildir: Fixed a memory leak when copying with hardlinks.
  - maildir: Expunging last messages may have assert-crashed if their
    filenames had just changed.
 * Update sieve patch to 0.1.17
 * debian/dovecot-common.postinst: Add warning about expired certificate.
   (Debian Bug: #576455)
 * Silence lintian warnings.

 [Scott Kitterman]
 * Rename dovecot-postfix to mail-stack-delivery 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.*

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
/*
18
18
 * Test_binary command
19
19
 *
20
 
 * Syntax:
 
20
 * Syntax:   
21
21
 *   test_binary ( :load / :save ) <mailbox: string>
22
22
 */
23
23
 
29
29
static bool cmd_test_binary_generate
30
30
        (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
31
31
 
32
 
const struct sieve_command_def cmd_test_binary = {
33
 
        "test_binary",
34
 
        SCT_COMMAND,
 
32
const struct sieve_command_def cmd_test_binary = { 
 
33
        "test_binary", 
 
34
        SCT_COMMAND, 
35
35
        1, 0, FALSE, FALSE,
36
 
        cmd_test_binary_registered,
 
36
        cmd_test_binary_registered, 
37
37
        NULL,
38
 
        cmd_test_binary_validate,
39
 
        cmd_test_binary_generate,
40
 
        NULL
 
38
        cmd_test_binary_validate, 
 
39
        cmd_test_binary_generate, 
 
40
        NULL 
41
41
};
42
42
 
43
 
/*
 
43
/* 
44
44
 * Operations
45
 
 */
 
45
 */ 
46
46
 
47
47
static bool cmd_test_binary_operation_dump
48
48
        (const struct sieve_dumptime_env *denv, sieve_size_t *address);
49
49
static int cmd_test_binary_operation_execute
50
50
        (const struct sieve_runtime_env *renv, sieve_size_t *address);
51
 
 
 
51
 
52
52
/* test_binary_create operation */
53
53
 
54
 
const struct sieve_operation_def test_binary_load_operation = {
 
54
const struct sieve_operation_def test_binary_load_operation = { 
55
55
        "TEST_BINARY_LOAD",
56
 
        &testsuite_extension,
 
56
        &testsuite_extension, 
57
57
        TESTSUITE_OPERATION_TEST_BINARY_LOAD,
58
 
        cmd_test_binary_operation_dump,
59
 
        cmd_test_binary_operation_execute
 
58
        cmd_test_binary_operation_dump, 
 
59
        cmd_test_binary_operation_execute 
60
60
};
61
61
 
62
62
/* test_binary_delete operation */
63
63
 
64
 
const struct sieve_operation_def test_binary_save_operation = {
 
64
const struct sieve_operation_def test_binary_save_operation = { 
65
65
        "TEST_BINARY_SAVE",
66
 
        &testsuite_extension,
 
66
        &testsuite_extension, 
67
67
        TESTSUITE_OPERATION_TEST_BINARY_SAVE,
68
 
        cmd_test_binary_operation_dump,
69
 
        cmd_test_binary_operation_execute
 
68
        cmd_test_binary_operation_dump, 
 
69
        cmd_test_binary_operation_execute 
70
70
};
71
71
 
72
72
/*
73
73
 * Compiler context data
74
74
 */
75
 
 
 
75
 
76
76
enum test_binary_operation {
77
 
        BINARY_OP_LOAD,
 
77
        BINARY_OP_LOAD, 
78
78
        BINARY_OP_SAVE,
79
79
        BINARY_OP_LAST
80
80
};
89
89
        const char *folder;
90
90
};
91
91
 
92
 
/*
93
 
 * Command tags
 
92
/* 
 
93
 * Command tags 
94
94
 */
95
 
 
 
95
 
96
96
static bool cmd_test_binary_validate_tag
97
 
        (struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
 
97
        (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
98
98
                struct sieve_command *cmd);
99
99
 
100
 
static const struct sieve_argument_def test_binary_load_tag = {
101
 
        "load",
102
 
        NULL,
 
100
static const struct sieve_argument_def test_binary_load_tag = { 
 
101
        "load", 
 
102
        NULL, 
103
103
        cmd_test_binary_validate_tag,
104
104
        NULL, NULL, NULL,
105
105
};
106
106
 
107
 
static const struct sieve_argument_def test_binary_save_tag = {
108
 
        "save",
 
107
static const struct sieve_argument_def test_binary_save_tag = { 
 
108
        "save", 
109
109
        NULL,
110
110
        cmd_test_binary_validate_tag,
111
 
        NULL, NULL, NULL,
 
111
        NULL, NULL, NULL, 
112
112
};
113
113
 
114
114
static bool cmd_test_binary_registered
115
 
(struct sieve_validator *valdtr, const struct sieve_extension *ext,
116
 
        struct sieve_command_registration *cmd_reg)
 
115
(struct sieve_validator *valdtr, const struct sieve_extension *ext, 
 
116
        struct sieve_command_registration *cmd_reg) 
117
117
{
118
118
        /* Register our tags */
119
 
        sieve_validator_register_tag(valdtr, cmd_reg, ext, &test_binary_load_tag, 0);
120
 
        sieve_validator_register_tag(valdtr, cmd_reg, ext, &test_binary_save_tag, 0);
 
119
        sieve_validator_register_tag(valdtr, cmd_reg, ext, &test_binary_load_tag, 0);   
 
120
        sieve_validator_register_tag(valdtr, cmd_reg, ext, &test_binary_save_tag, 0);   
121
121
 
122
122
        return TRUE;
123
123
}
124
124
 
125
125
static bool cmd_test_binary_validate_tag
126
 
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
 
126
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
127
127
        struct sieve_command *cmd)
128
128
{
129
 
        struct cmd_test_binary_context_data *ctx_data =
130
 
                (struct cmd_test_binary_context_data *) cmd->data;
131
 
 
 
129
        struct cmd_test_binary_context_data *ctx_data = 
 
130
                (struct cmd_test_binary_context_data *) cmd->data;      
 
131
        
132
132
        if ( ctx_data != NULL ) {
133
133
                sieve_argument_validate_error
134
134
                        (valdtr, *arg, "exactly one of the ':load' or ':save' tags must be "
135
135
                                "specified for the test_binary command, but more were found");
136
 
                return NULL;
 
136
                return NULL;            
137
137
        }
138
 
 
 
138
        
139
139
        ctx_data = p_new
140
140
                (sieve_command_pool(cmd), struct cmd_test_binary_context_data, 1);
141
141
        cmd->data = ctx_data;
142
 
 
143
 
        if ( sieve_argument_is(*arg, test_binary_load_tag) )
 
142
        
 
143
        if ( sieve_argument_is(*arg, test_binary_load_tag) ) 
144
144
                ctx_data->binary_op = BINARY_OP_LOAD;
145
145
        else
146
146
                ctx_data->binary_op = BINARY_OP_SAVE;
151
151
        return TRUE;
152
152
}
153
153
 
154
 
/*
155
 
 * Validation
 
154
/* 
 
155
 * Validation 
156
156
 */
157
157
 
158
158
static bool cmd_test_binary_validate
159
 
(struct sieve_validator *valdtr, struct sieve_command *cmd)
160
 
{
 
159
(struct sieve_validator *valdtr, struct sieve_command *cmd) 
 
160
{       
161
161
        struct sieve_ast_argument *arg = cmd->first_positional;
162
 
 
 
162
        
163
163
        if ( cmd->data == NULL ) {
164
 
                sieve_command_validate_error(valdtr, cmd,
 
164
                sieve_command_validate_error(valdtr, cmd, 
165
165
                        "the test_binary command requires either the :load or the :save tag "
166
166
                        "to be specified");
167
 
                return FALSE;
 
167
                return FALSE;           
168
168
        }
169
 
 
 
169
                
170
170
        if ( !sieve_validate_positional_argument
171
171
                (valdtr, cmd, arg, "binary-name", 1, SAAT_STRING) ) {
172
172
                return FALSE;
173
173
        }
174
 
 
 
174
        
175
175
        return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE);
176
176
}
177
177
 
178
 
/*
179
 
 * Code generation
 
178
/* 
 
179
 * Code generation 
180
180
 */
181
181
 
182
182
static bool cmd_test_binary_generate
183
183
(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
184
184
{
185
185
        struct cmd_test_binary_context_data *ctx_data =
186
 
                (struct cmd_test_binary_context_data *) cmd->data;
 
186
                (struct cmd_test_binary_context_data *) cmd->data; 
187
187
 
188
188
        i_assert( ctx_data->binary_op < BINARY_OP_LAST );
189
 
 
 
189
        
190
190
        /* Emit operation */
191
 
        sieve_operation_emit(cgenv->sbin, cmd->ext,
 
191
        sieve_operation_emit(cgenv->sbin, cmd->ext, 
192
192
                test_binary_operations[ctx_data->binary_op]);
193
 
 
 
193
                
194
194
        /* Generate arguments */
195
195
        if ( !sieve_generate_arguments(cgenv, cmd, NULL) )
196
196
                return FALSE;
198
198
        return TRUE;
199
199
}
200
200
 
201
 
/*
 
201
/* 
202
202
 * Code dump
203
203
 */
204
 
 
 
204
 
205
205
static bool cmd_test_binary_operation_dump
206
206
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
207
207
{
208
208
        const struct sieve_operation *op = &denv->oprtn;
209
209
 
210
210
        sieve_code_dumpf(denv, "%s:", sieve_operation_mnemonic(op));
211
 
 
 
211
        
212
212
        sieve_code_descend(denv);
213
 
 
 
213
        
214
214
        return sieve_opr_string_dump(denv, address, "binary-name");
215
215
}
216
216
 
218
218
/*
219
219
 * Intepretation
220
220
 */
221
 
 
 
221
 
222
222
static int cmd_test_binary_operation_execute
223
223
(const struct sieve_runtime_env *renv, sieve_size_t *address)
224
224
{
225
225
        const struct sieve_operation *op = &renv->oprtn;
226
226
        string_t *binary_name = NULL;
227
227
 
228
 
        /*
229
 
         * Read operands
 
228
        /* 
 
229
         * Read operands 
230
230
         */
231
231
 
232
232
        /* Binary Name */
239
239
        /*
240
240
         * Perform operation
241
241
         */
242
 
 
 
242
                
243
243
        sieve_runtime_trace
244
244
                (renv, "%s %s:", sieve_operation_mnemonic(op), str_c(binary_name));
245
245
 
258
258
        } else if ( sieve_operation_is(op, test_binary_save_operation) ) {
259
259
                struct sieve_binary *sbin = testsuite_script_get_binary();
260
260
 
261
 
                if ( sbin != NULL )
 
261
                if ( sbin != NULL ) 
262
262
                        testsuite_binary_save(sbin, str_c(binary_name));
263
263
                else {
264
264
                        sieve_sys_error("no compiled binary to save as %s", str_c(binary_name));