Revamp debugging/tracing support
* bootstrap.conf (mu_sieve_debug, mu_sieve_trace): Remove. * include/mailutils/sieve.h (mu_sieve_debug): Remove. * examples/numaddr.c: Remove calls to mu_sieve_trace. * libmu_sieve/extensions/list.c: Likewise. * libmu_sieve/extensions/moderator.c: Likewise. * libmu_sieve/extensions/pipe.c: Likewise. * libmu_sieve/extensions/spamd.c: Likewise. * libmu_sieve/extensions/timestamp.c: Likewise. * libmu_sieve/extensions/vacation.c: Likewise. * libmu_sieve/tests.c: Likewise. * libmu_sieve/runtime.c: Use new debugging/tracing functions. * libmu_sieve/sieve-priv.h (mu_i_sv_debug, mu_i_sv_trace) (mu_i_sv_debug_command) (mu_i_sv_argf, mu_i_sv_valf): New prototypes. * libmu_sieve/sieve.y (mu_i_sv_valf, mu_i_sv_argf): New functions. * libmu_sieve/util.c (mu_sieve_debug): Remove. (mu_i_sv_print_value_list): Remove. (mu_i_sv_print_tag_list): Remove. (mu_sieve_trace): Remove. (mu_i_sv_tagf): New function. (mu_i_sv_debug): New function. (mu_i_sv_trace): New function. (mu_i_sv_debug_command): New function.
Showing
14 changed files
with
134 additions
and
203 deletions
... | @@ -47,7 +47,6 @@ XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\ | ... | @@ -47,7 +47,6 @@ XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\ |
47 | --flag=mu_debug_print:3:c-format\\\ | 47 | --flag=mu_debug_print:3:c-format\\\ |
48 | --flag=mu_debug_printf:3:c-format\\\ | 48 | --flag=mu_debug_printf:3:c-format\\\ |
49 | --flag=mu_sieve_error:2:c-format\\\ | 49 | --flag=mu_sieve_error:2:c-format\\\ |
50 | --flag=mu_sieve_debug:2:c-format\\\ | ||
51 | --flag=mu_sieve_log_action:3:c-format\\\ | 50 | --flag=mu_sieve_log_action:3:c-format\\\ |
52 | --flag=mu_nntp_writeline:2:c-format\\\ | 51 | --flag=mu_nntp_writeline:2:c-format\\\ |
53 | --flag=mu_pop3_writeline:2:c-format\\\ | 52 | --flag=mu_pop3_writeline:2:c-format\\\ | ... | ... |
... | @@ -84,8 +84,6 @@ numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -84,8 +84,6 @@ numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
84 | struct val_ctr vc; | 84 | struct val_ctr vc; |
85 | int rc; | 85 | int rc; |
86 | 86 | ||
87 | mu_sieve_trace (mach, "NUMADDR"); | ||
88 | |||
89 | /* Retrieve required arguments: */ | 87 | /* Retrieve required arguments: */ |
90 | /* First argument: list of header names */ | 88 | /* First argument: list of header names */ |
91 | h = mu_sieve_value_get (args, 0); | 89 | h = mu_sieve_value_get (args, 0); | ... | ... |
... | @@ -251,8 +251,6 @@ int mu_sieve_get_message_sender (mu_message_t msg, char **ptext); | ... | @@ -251,8 +251,6 @@ int mu_sieve_get_message_sender (mu_message_t msg, char **ptext); |
251 | 251 | ||
252 | void mu_sieve_error (mu_sieve_machine_t mach, const char *fmt, ...) | 252 | void mu_sieve_error (mu_sieve_machine_t mach, const char *fmt, ...) |
253 | MU_PRINTFLIKE(2,3); | 253 | MU_PRINTFLIKE(2,3); |
254 | void mu_sieve_debug (mu_sieve_machine_t mach, const char *fmt, ...) | ||
255 | MU_PRINTFLIKE(2,3); | ||
256 | void mu_sieve_log_action (mu_sieve_machine_t mach, const char *action, | 254 | void mu_sieve_log_action (mu_sieve_machine_t mach, const char *action, |
257 | const char *fmt, ...) | 255 | const char *fmt, ...) |
258 | MU_PRINTFLIKE(3,4); | 256 | MU_PRINTFLIKE(3,4); | ... | ... |
... | @@ -152,8 +152,6 @@ list_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -152,8 +152,6 @@ list_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
152 | struct header_closure clos; | 152 | struct header_closure clos; |
153 | int result; | 153 | int result; |
154 | 154 | ||
155 | mu_sieve_trace (mach, "LIST"); | ||
156 | |||
157 | memset (&clos, 0, sizeof clos); | 155 | memset (&clos, 0, sizeof clos); |
158 | if (mu_sieve_tag_lookup (tags, "delim", &arg)) | 156 | if (mu_sieve_tag_lookup (tags, "delim", &arg)) |
159 | clos.delim = arg->v.string; | 157 | clos.delim = arg->v.string; | ... | ... |
... | @@ -273,9 +273,6 @@ moderator_action (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -273,9 +273,6 @@ moderator_action (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
273 | int discard = 0; | 273 | int discard = 0; |
274 | int ismime; | 274 | int ismime; |
275 | 275 | ||
276 | mu_sieve_trace (mach, "moderator_test %lu", | ||
277 | (unsigned long) mu_sieve_get_message_num (mach)); | ||
278 | |||
279 | msg = mu_sieve_get_message (mach); | 276 | msg = mu_sieve_get_message (mach); |
280 | mu_message_is_multipart (msg, &ismime); | 277 | mu_message_is_multipart (msg, &ismime); |
281 | 278 | ... | ... |
... | @@ -105,8 +105,6 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test) | ... | @@ -105,8 +105,6 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test) |
105 | } | 105 | } |
106 | cmd = val->v.string; | 106 | cmd = val->v.string; |
107 | 107 | ||
108 | mu_sieve_trace (mach, test ? "PIPE (test)" : "PIPE (action)"); | ||
109 | |||
110 | if (mu_sieve_is_dry_run (mach)) | 108 | if (mu_sieve_is_dry_run (mach)) |
111 | return 0; | 109 | return 0; |
112 | 110 | ... | ... |
... | @@ -368,9 +368,6 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -368,9 +368,6 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
368 | mu_header_t hdr; | 368 | mu_header_t hdr; |
369 | mu_debug_handle_t lev = 0; | 369 | mu_debug_handle_t lev = 0; |
370 | 370 | ||
371 | mu_sieve_trace (mach, "spamd_test %lu", | ||
372 | (unsigned long) mu_sieve_get_message_num (mach)); | ||
373 | |||
374 | if (mu_sieve_is_dry_run (mach)) | 371 | if (mu_sieve_is_dry_run (mach)) |
375 | return 0; | 372 | return 0; |
376 | 373 | ... | ... |
... | @@ -57,8 +57,6 @@ timestamp_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -57,8 +57,6 @@ timestamp_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
57 | time_t tlimit, tval; | 57 | time_t tlimit, tval; |
58 | int rc; | 58 | int rc; |
59 | 59 | ||
60 | mu_sieve_trace (mach, "TIMESTAMP"); | ||
61 | |||
62 | /* Retrieve required arguments: */ | 60 | /* Retrieve required arguments: */ |
63 | /* First argument: header name */ | 61 | /* First argument: header name */ |
64 | h = mu_sieve_value_get (args, 0); | 62 | h = mu_sieve_value_get (args, 0); | ... | ... |
... | @@ -136,8 +136,6 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, | ... | @@ -136,8 +136,6 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, |
136 | static int | 136 | static int |
137 | diag (mu_sieve_machine_t mach) | 137 | diag (mu_sieve_machine_t mach) |
138 | { | 138 | { |
139 | mu_sieve_trace (mach, "VACATION"); | ||
140 | |||
141 | mu_sieve_log_action (mach, "VACATION", NULL); | 139 | mu_sieve_log_action (mach, "VACATION", NULL); |
142 | return mu_sieve_is_dry_run (mach); | 140 | return mu_sieve_is_dry_run (mach); |
143 | } | 141 | } | ... | ... |
... | @@ -36,7 +36,7 @@ void | ... | @@ -36,7 +36,7 @@ void |
36 | _mu_i_sv_instr_nop (mu_sieve_machine_t mach) | 36 | _mu_i_sv_instr_nop (mu_sieve_machine_t mach) |
37 | { | 37 | { |
38 | if (INSTR_DEBUG (mach)) | 38 | if (INSTR_DEBUG (mach)) |
39 | mu_sieve_debug (mach, "%4lu: NOP", (unsigned long) (mach->pc - 1)); | 39 | mu_i_sv_debug (mach, mach->pc - 1, "NOP"); |
40 | } | 40 | } |
41 | 41 | ||
42 | void | 42 | void |
... | @@ -47,9 +47,7 @@ _mu_i_sv_instr_source (mu_sieve_machine_t mach) | ... | @@ -47,9 +47,7 @@ _mu_i_sv_instr_source (mu_sieve_machine_t mach) |
47 | MU_IOCTL_LOGSTREAM_SET_LOCUS, | 47 | MU_IOCTL_LOGSTREAM_SET_LOCUS, |
48 | &mach->locus); | 48 | &mach->locus); |
49 | if (INSTR_DEBUG (mach)) | 49 | if (INSTR_DEBUG (mach)) |
50 | mu_sieve_debug (mach, "%4lu: SOURCE %s", | 50 | mu_i_sv_debug (mach, mach->pc - 1, "SOURCE %s", mach->locus.mu_file); |
51 | (unsigned long) (mach->pc - 1), | ||
52 | mach->locus.mu_file); | ||
53 | SIEVE_ADJUST (mach, 1); | 51 | SIEVE_ADJUST (mach, 1); |
54 | } | 52 | } |
55 | 53 | ||
... | @@ -61,14 +59,13 @@ _mu_i_sv_instr_line (mu_sieve_machine_t mach) | ... | @@ -61,14 +59,13 @@ _mu_i_sv_instr_line (mu_sieve_machine_t mach) |
61 | MU_IOCTL_LOGSTREAM_SET_LOCUS, | 59 | MU_IOCTL_LOGSTREAM_SET_LOCUS, |
62 | &mach->locus); | 60 | &mach->locus); |
63 | if (INSTR_DEBUG (mach)) | 61 | if (INSTR_DEBUG (mach)) |
64 | mu_sieve_debug (mach, "%4lu: LINE %u", | 62 | mu_i_sv_debug (mach, mach->pc - 1, "LINE %u", |
65 | (unsigned long) (mach->pc - 1), | 63 | mach->locus.mu_line); |
66 | mach->locus.mu_line); | ||
67 | SIEVE_ADJUST (mach, 1); | 64 | SIEVE_ADJUST (mach, 1); |
68 | } | 65 | } |
69 | 66 | ||
70 | static int | 67 | static int |
71 | instr_run (mu_sieve_machine_t mach) | 68 | instr_run (mu_sieve_machine_t mach, char const *what) |
72 | { | 69 | { |
73 | mu_sieve_handler_t han = SIEVE_ARG (mach, 0, handler); | 70 | mu_sieve_handler_t han = SIEVE_ARG (mach, 0, handler); |
74 | mu_list_t arg_list = SIEVE_ARG (mach, 1, list); | 71 | mu_list_t arg_list = SIEVE_ARG (mach, 1, list); |
... | @@ -78,15 +75,11 @@ instr_run (mu_sieve_machine_t mach) | ... | @@ -78,15 +75,11 @@ instr_run (mu_sieve_machine_t mach) |
78 | SIEVE_ADJUST(mach, 4); | 75 | SIEVE_ADJUST(mach, 4); |
79 | 76 | ||
80 | if (INSTR_DEBUG (mach)) | 77 | if (INSTR_DEBUG (mach)) |
81 | { | 78 | mu_i_sv_debug_command (mach, mach->pc - 1, |
82 | mu_stream_printf (mach->errstream, | 79 | what, tag_list, arg_list); |
83 | "\033s<%d>Arguments: ", MU_LOG_DEBUG); | 80 | else |
84 | mu_i_sv_print_value_list (arg_list, mach->errstream); | 81 | mu_i_sv_trace (mach, what, tag_list, arg_list); |
85 | mu_stream_printf (mach->errstream, "\n\033s<%d>Tags: ", MU_LOG_DEBUG); | 82 | |
86 | mu_i_sv_print_tag_list (tag_list, mach->errstream); | ||
87 | mu_stream_printf (mach->errstream, "\n"); | ||
88 | } | ||
89 | |||
90 | if (!INSTR_DISASS(mach)) | 83 | if (!INSTR_DISASS(mach)) |
91 | rc = han (mach, arg_list, tag_list); | 84 | rc = han (mach, arg_list, tag_list); |
92 | return rc; | 85 | return rc; |
... | @@ -96,12 +89,8 @@ void | ... | @@ -96,12 +89,8 @@ void |
96 | _mu_i_sv_instr_action (mu_sieve_machine_t mach) | 89 | _mu_i_sv_instr_action (mu_sieve_machine_t mach) |
97 | { | 90 | { |
98 | mach->identifier = SIEVE_ARG (mach, 3, string); | 91 | mach->identifier = SIEVE_ARG (mach, 3, string); |
99 | if (INSTR_DEBUG (mach)) | ||
100 | mu_sieve_debug (mach, "%4lu: ACTION: %s", | ||
101 | (unsigned long) (mach->pc - 1), | ||
102 | mach->identifier); | ||
103 | mach->action_count++; | 92 | mach->action_count++; |
104 | instr_run (mach); | 93 | instr_run (mach, "action"); |
105 | mach->identifier = NULL; | 94 | mach->identifier = NULL; |
106 | } | 95 | } |
107 | 96 | ||
... | @@ -109,11 +98,7 @@ void | ... | @@ -109,11 +98,7 @@ void |
109 | _mu_i_sv_instr_test (mu_sieve_machine_t mach) | 98 | _mu_i_sv_instr_test (mu_sieve_machine_t mach) |
110 | { | 99 | { |
111 | mach->identifier = SIEVE_ARG (mach, 3, string); | 100 | mach->identifier = SIEVE_ARG (mach, 3, string); |
112 | if (INSTR_DEBUG (mach)) | 101 | mach->reg = instr_run (mach, "test"); |
113 | mu_sieve_debug (mach, "%4lu: TEST: %s", | ||
114 | (unsigned long) (mach->pc - 1), | ||
115 | mach->identifier); | ||
116 | mach->reg = instr_run (mach); | ||
117 | mach->identifier = NULL; | 102 | mach->identifier = NULL; |
118 | } | 103 | } |
119 | 104 | ||
... | @@ -122,7 +107,7 @@ _mu_i_sv_instr_push (mu_sieve_machine_t mach) | ... | @@ -122,7 +107,7 @@ _mu_i_sv_instr_push (mu_sieve_machine_t mach) |
122 | { | 107 | { |
123 | if (INSTR_DEBUG (mach)) | 108 | if (INSTR_DEBUG (mach)) |
124 | { | 109 | { |
125 | mu_sieve_debug (mach, "%4lu: PUSH", (unsigned long)(mach->pc - 1)); | 110 | mu_i_sv_debug (mach, mach->pc - 1, "PUSH"); |
126 | if (INSTR_DISASS (mach)) | 111 | if (INSTR_DISASS (mach)) |
127 | return; | 112 | return; |
128 | } | 113 | } |
... | @@ -140,7 +125,7 @@ _mu_i_sv_instr_pop (mu_sieve_machine_t mach) | ... | @@ -140,7 +125,7 @@ _mu_i_sv_instr_pop (mu_sieve_machine_t mach) |
140 | { | 125 | { |
141 | if (INSTR_DEBUG (mach)) | 126 | if (INSTR_DEBUG (mach)) |
142 | { | 127 | { |
143 | mu_sieve_debug (mach, "%4lu: POP", (unsigned long)(mach->pc - 1)); | 128 | mu_i_sv_debug (mach, mach->pc - 1, "POP"); |
144 | if (INSTR_DISASS (mach)) | 129 | if (INSTR_DISASS (mach)) |
145 | return; | 130 | return; |
146 | } | 131 | } |
... | @@ -158,7 +143,7 @@ _mu_i_sv_instr_not (mu_sieve_machine_t mach) | ... | @@ -158,7 +143,7 @@ _mu_i_sv_instr_not (mu_sieve_machine_t mach) |
158 | { | 143 | { |
159 | if (INSTR_DEBUG (mach)) | 144 | if (INSTR_DEBUG (mach)) |
160 | { | 145 | { |
161 | mu_sieve_debug (mach, "%4lu: NOT", (unsigned long)(mach->pc - 1)); | 146 | mu_i_sv_debug (mach, mach->pc - 1, "NOT"); |
162 | if (INSTR_DISASS (mach)) | 147 | if (INSTR_DISASS (mach)) |
163 | return; | 148 | return; |
164 | } | 149 | } |
... | @@ -173,9 +158,8 @@ _mu_i_sv_instr_branch (mu_sieve_machine_t mach) | ... | @@ -173,9 +158,8 @@ _mu_i_sv_instr_branch (mu_sieve_machine_t mach) |
173 | SIEVE_ADJUST (mach, 1); | 158 | SIEVE_ADJUST (mach, 1); |
174 | if (INSTR_DEBUG (mach)) | 159 | if (INSTR_DEBUG (mach)) |
175 | { | 160 | { |
176 | mu_sieve_debug (mach, "%4lu: BRANCH %lu", | 161 | mu_i_sv_debug (mach, mach->pc - 2, "BRANCH %lu", |
177 | (unsigned long)(mach->pc-2), | 162 | (unsigned long)(mach->pc + num)); |
178 | (unsigned long)(mach->pc + num)); | ||
179 | if (INSTR_DISASS (mach)) | 163 | if (INSTR_DISASS (mach)) |
180 | return; | 164 | return; |
181 | } | 165 | } |
... | @@ -191,9 +175,8 @@ _mu_i_sv_instr_brz (mu_sieve_machine_t mach) | ... | @@ -191,9 +175,8 @@ _mu_i_sv_instr_brz (mu_sieve_machine_t mach) |
191 | 175 | ||
192 | if (INSTR_DEBUG (mach)) | 176 | if (INSTR_DEBUG (mach)) |
193 | { | 177 | { |
194 | mu_sieve_debug (mach, "%4lu: BRZ %lu", | 178 | mu_i_sv_debug (mach, mach->pc - 2, "BRZ %lu", |
195 | (unsigned long)(mach->pc-2), | 179 | (unsigned long)(mach->pc + num)); |
196 | (unsigned long)(mach->pc + num)); | ||
197 | if (INSTR_DISASS (mach)) | 180 | if (INSTR_DISASS (mach)) |
198 | return; | 181 | return; |
199 | } | 182 | } |
... | @@ -210,9 +193,8 @@ _mu_i_sv_instr_brnz (mu_sieve_machine_t mach) | ... | @@ -210,9 +193,8 @@ _mu_i_sv_instr_brnz (mu_sieve_machine_t mach) |
210 | 193 | ||
211 | if (INSTR_DEBUG (mach)) | 194 | if (INSTR_DEBUG (mach)) |
212 | { | 195 | { |
213 | mu_sieve_debug (mach, "%4lu: BRNZ %lu", | 196 | mu_i_sv_debug (mach, mach->pc - 2, "BRNZ %lu", |
214 | (unsigned long)(mach->pc-2), | 197 | (unsigned long)(mach->pc + num)); |
215 | (unsigned long)(mach->pc + num)); | ||
216 | if (INSTR_DISASS (mach)) | 198 | if (INSTR_DISASS (mach)) |
217 | return; | 199 | return; |
218 | } | 200 | } |
... | @@ -299,7 +281,7 @@ sieve_run (mu_sieve_machine_t mach) | ... | @@ -299,7 +281,7 @@ sieve_run (mu_sieve_machine_t mach) |
299 | mu_sieve_log_action (mach, "IMPLICIT KEEP", NULL); | 281 | mu_sieve_log_action (mach, "IMPLICIT KEEP", NULL); |
300 | 282 | ||
301 | if (INSTR_DEBUG (mach)) | 283 | if (INSTR_DEBUG (mach)) |
302 | mu_sieve_debug (mach, "%4lu: STOP", (unsigned long) mach->pc); | 284 | mu_i_sv_debug (mach, mach->pc, "STOP"); |
303 | 285 | ||
304 | return 0; | 286 | return 0; |
305 | } | 287 | } | ... | ... |
... | @@ -180,3 +180,15 @@ void mu_i_sv_print_tag_list (mu_list_t list, mu_stream_t str); | ... | @@ -180,3 +180,15 @@ void mu_i_sv_print_tag_list (mu_list_t list, mu_stream_t str); |
180 | 180 | ||
181 | void mu_i_sv_error (mu_sieve_machine_t mach); | 181 | void mu_i_sv_error (mu_sieve_machine_t mach); |
182 | 182 | ||
183 | void mu_i_sv_debug (mu_sieve_machine_t mach, size_t pc, const char *fmt, ...) | ||
184 | MU_PRINTFLIKE(3,4); | ||
185 | void mu_i_sv_debug_command (mu_sieve_machine_t mach, | ||
186 | size_t pc, | ||
187 | char const *what, | ||
188 | mu_list_t taglist, mu_list_t arglist); | ||
189 | void mu_i_sv_trace (mu_sieve_machine_t mach, const char *what, | ||
190 | mu_list_t taglist, mu_list_t arglist); | ||
191 | |||
192 | void mu_i_sv_argf (mu_stream_t str, mu_list_t list); | ||
193 | void mu_i_sv_valf (mu_stream_t str, mu_sieve_value_t *val); | ||
194 | ... | ... |
... | @@ -502,12 +502,9 @@ string_dumper (void *item, void *data) | ... | @@ -502,12 +502,9 @@ string_dumper (void *item, void *data) |
502 | return 0; | 502 | return 0; |
503 | } | 503 | } |
504 | 504 | ||
505 | static int | 505 | void |
506 | dump_val (void *item, void *data) | 506 | mu_i_sv_valf (mu_stream_t str, mu_sieve_value_t *val) |
507 | { | 507 | { |
508 | mu_sieve_value_t *val = item; | ||
509 | mu_stream_t str = data; | ||
510 | |||
511 | mu_stream_printf (str, " "); | 508 | mu_stream_printf (str, " "); |
512 | switch (val->type) | 509 | switch (val->type) |
513 | { | 510 | { |
... | @@ -544,7 +541,7 @@ dump_val (void *item, void *data) | ... | @@ -544,7 +541,7 @@ dump_val (void *item, void *data) |
544 | 541 | ||
545 | case SVT_VALUE_LIST: | 542 | case SVT_VALUE_LIST: |
546 | mu_stream_printf (str, "["); | 543 | mu_stream_printf (str, "["); |
547 | mu_list_foreach (val->v.list, dump_val, str); | 544 | mu_i_sv_argf (str, val->v.list); |
548 | mu_stream_printf (str, "]"); | 545 | mu_stream_printf (str, "]"); |
549 | break; | 546 | break; |
550 | 547 | ||
... | @@ -555,9 +552,23 @@ dump_val (void *item, void *data) | ... | @@ -555,9 +552,23 @@ dump_val (void *item, void *data) |
555 | default: | 552 | default: |
556 | abort (); | 553 | abort (); |
557 | } | 554 | } |
558 | return 0; | ||
559 | } | 555 | } |
560 | 556 | ||
557 | static int | ||
558 | dump_val (void *item, void *data) | ||
559 | { | ||
560 | mu_sieve_value_t *val = item; | ||
561 | mu_stream_t str = data; | ||
562 | mu_i_sv_valf (str, val); | ||
563 | return 0; | ||
564 | } | ||
565 | |||
566 | void | ||
567 | mu_i_sv_argf (mu_stream_t str, mu_list_t list) | ||
568 | { | ||
569 | mu_list_foreach (list, dump_val, str); | ||
570 | } | ||
571 | |||
561 | static void | 572 | static void |
562 | dump_node_command (mu_stream_t str, struct mu_sieve_node *node, unsigned level) | 573 | dump_node_command (mu_stream_t str, struct mu_sieve_node *node, unsigned level) |
563 | { | 574 | { | ... | ... |
... | @@ -119,8 +119,6 @@ sieve_test_address (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -119,8 +119,6 @@ sieve_test_address (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
119 | int rc; | 119 | int rc; |
120 | size_t count; | 120 | size_t count; |
121 | 121 | ||
122 | mu_sieve_trace (mach, "ADDRESS"); | ||
123 | |||
124 | h = mu_sieve_value_get (args, 0); | 122 | h = mu_sieve_value_get (args, 0); |
125 | if (!h) | 123 | if (!h) |
126 | { | 124 | { |
... | @@ -182,8 +180,6 @@ sieve_test_header (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -182,8 +180,6 @@ sieve_test_header (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
182 | size_t count, mcount = 0; | 180 | size_t count, mcount = 0; |
183 | struct header_closure clos; | 181 | struct header_closure clos; |
184 | 182 | ||
185 | mu_sieve_trace (mach, "HEADER"); | ||
186 | |||
187 | h = mu_sieve_value_get (args, 0); | 183 | h = mu_sieve_value_get (args, 0); |
188 | if (!h) | 184 | if (!h) |
189 | { | 185 | { |
... | @@ -265,8 +261,6 @@ sieve_test_envelope (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -265,8 +261,6 @@ sieve_test_envelope (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
265 | int rc; | 261 | int rc; |
266 | size_t count; | 262 | size_t count; |
267 | 263 | ||
268 | mu_sieve_trace (mach, "ENVELOPE"); | ||
269 | |||
270 | h = mu_sieve_value_get (args, 0); | 264 | h = mu_sieve_value_get (args, 0); |
271 | if (!h) | 265 | if (!h) |
272 | { | 266 | { |
... | @@ -331,8 +325,6 @@ sieve_test_exists (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) | ... | @@ -331,8 +325,6 @@ sieve_test_exists (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) |
331 | mu_header_t header = NULL; | 325 | mu_header_t header = NULL; |
332 | mu_sieve_value_t *val; | 326 | mu_sieve_value_t *val; |
333 | 327 | ||
334 | mu_sieve_trace (mach, "EXISTS"); | ||
335 | |||
336 | mu_message_get_header (mu_sieve_get_message (mach), &header); | 328 | mu_message_get_header (mu_sieve_get_message (mach), &header); |
337 | val = mu_sieve_value_get (args, 0); | 329 | val = mu_sieve_value_get (args, 0); |
338 | if (!val) | 330 | if (!val) | ... | ... |
... | @@ -210,67 +210,7 @@ mu_sieve_arg_error (mu_sieve_machine_t mach, int n) | ... | @@ -210,67 +210,7 @@ mu_sieve_arg_error (mu_sieve_machine_t mach, int n) |
210 | { | 210 | { |
211 | mu_sieve_error (mach, _("cannot retrieve argument %d"), n); | 211 | mu_sieve_error (mach, _("cannot retrieve argument %d"), n); |
212 | } | 212 | } |
213 | 213 | ||
214 | void | ||
215 | mu_sieve_debug (mu_sieve_machine_t mach, const char *fmt, ...) | ||
216 | { | ||
217 | va_list ap; | ||
218 | |||
219 | va_start (ap, fmt); | ||
220 | mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_DEBUG); | ||
221 | if (mach->locus.mu_file) | ||
222 | mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>", | ||
223 | MU_LOGMODE_LOCUS, | ||
224 | (unsigned) strlen (mach->locus.mu_file), | ||
225 | mach->locus.mu_file, | ||
226 | mach->locus.mu_line); | ||
227 | mu_stream_vprintf (mach->errstream, fmt, ap); | ||
228 | mu_stream_write (mach->errstream, "\n", 1, NULL); | ||
229 | va_end (ap); | ||
230 | } | ||
231 | |||
232 | void | ||
233 | mu_sieve_trace (mu_sieve_machine_t mach, const char *fmt, ...) | ||
234 | { | ||
235 | va_list ap; | ||
236 | |||
237 | if (!mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE4)) | ||
238 | return; | ||
239 | |||
240 | va_start (ap, fmt); | ||
241 | mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_DEBUG); | ||
242 | if (mach->locus.mu_file) | ||
243 | mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>", | ||
244 | MU_LOGMODE_LOCUS, | ||
245 | (unsigned) strlen (mach->locus.mu_file), | ||
246 | mach->locus.mu_file, | ||
247 | mach->locus.mu_line); | ||
248 | mu_stream_vprintf (mach->errstream, fmt, ap); | ||
249 | mu_stream_write (mach->errstream, "\n", 1, NULL); | ||
250 | va_end (ap); | ||
251 | } | ||
252 | |||
253 | void | ||
254 | mu_sieve_log_action (mu_sieve_machine_t mach, const char *action, | ||
255 | const char *fmt, ...) | ||
256 | { | ||
257 | va_list ap; | ||
258 | |||
259 | if (!mach->logger) | ||
260 | return; | ||
261 | va_start (ap, fmt); | ||
262 | mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_INFO); | ||
263 | if (mach->locus.mu_file) | ||
264 | mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>", | ||
265 | MU_LOGMODE_LOCUS, | ||
266 | (unsigned) strlen (mach->locus.mu_file), | ||
267 | mach->locus.mu_file, | ||
268 | mach->locus.mu_line); | ||
269 | mach->logger (mach->data, mach->errstream, mach->msgno, mach->msg, | ||
270 | action, fmt, ap); | ||
271 | va_end (ap); | ||
272 | } | ||
273 | |||
274 | const char * | 214 | const char * |
275 | mu_sieve_type_str (mu_sieve_data_type type) | 215 | mu_sieve_type_str (mu_sieve_data_type type) |
276 | { | 216 | { |
... | @@ -303,95 +243,106 @@ mu_sieve_type_str (mu_sieve_data_type type) | ... | @@ -303,95 +243,106 @@ mu_sieve_type_str (mu_sieve_data_type type) |
303 | 243 | ||
304 | return "unknown"; | 244 | return "unknown"; |
305 | } | 245 | } |
306 | 246 | ||
307 | static int | 247 | static int |
308 | string_printer (void *item, void *data) | 248 | tag_printer (void *item, void *data) |
309 | { | 249 | { |
310 | char *s = item; | 250 | mu_sieve_runtime_tag_t *val = item; |
311 | mu_stream_t str = data; | 251 | mu_stream_t str = data; |
312 | 252 | ||
313 | mu_stream_printf (str, "\"%s\" ", s); | 253 | mu_stream_printf (str, " :%s", val->tag); |
254 | if (val->arg) | ||
255 | mu_i_sv_valf (str, val->arg); | ||
314 | return 0; | 256 | return 0; |
315 | } | 257 | } |
316 | 258 | ||
317 | static void sieve_print_value (mu_sieve_value_t *, mu_stream_t str); | 259 | void |
318 | 260 | mu_i_sv_tagf (mu_stream_t str, mu_list_t taglist) | |
319 | static int | ||
320 | value_printer (void *item, void *data) | ||
321 | { | 261 | { |
322 | mu_sieve_value_t *val = item; | 262 | mu_list_foreach (taglist, tag_printer, str); |
323 | mu_stream_t str = data; | ||
324 | |||
325 | sieve_print_value (val, str); | ||
326 | mu_stream_printf (str, " "); | ||
327 | return 0; | ||
328 | } | 263 | } |
329 | 264 | ||
330 | static void | 265 | void |
331 | sieve_print_value (mu_sieve_value_t *val, mu_stream_t str) | 266 | mu_i_sv_debug (mu_sieve_machine_t mach, size_t pc, const char *fmt, ...) |
332 | { | 267 | { |
333 | mu_stream_printf (str, "%s(", mu_sieve_type_str (val->type)); | 268 | va_list ap; |
334 | switch (val->type) | ||
335 | { | ||
336 | case SVT_VOID: | ||
337 | break; | ||
338 | |||
339 | case SVT_NUMBER: | ||
340 | mu_stream_printf (str, "%lu", (unsigned long) val->v.number); | ||
341 | break; | ||
342 | |||
343 | case SVT_TAG: | ||
344 | case SVT_IDENT: | ||
345 | case SVT_STRING: | ||
346 | mu_stream_printf (str, "%s", val->v.string); | ||
347 | break; | ||
348 | |||
349 | case SVT_STRING_LIST: | ||
350 | mu_list_foreach (val->v.list, string_printer, str); | ||
351 | break; | ||
352 | |||
353 | case SVT_VALUE_LIST: | ||
354 | mu_list_foreach (val->v.list, value_printer, str); | ||
355 | 269 | ||
356 | case SVT_POINTER: | 270 | va_start (ap, fmt); |
357 | mu_stream_printf (str, "%p", val->v.ptr); | 271 | mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_DEBUG); |
358 | } | 272 | if (mach->locus.mu_file) |
359 | mu_stream_printf (str, ")"); | 273 | mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>", |
360 | } | 274 | MU_LOGMODE_LOCUS, |
275 | (unsigned) strlen (mach->locus.mu_file), | ||
276 | mach->locus.mu_file, | ||
277 | mach->locus.mu_line); | ||
278 | mu_stream_printf (mach->errstream, "%4zu: ", pc); | ||
279 | mu_stream_vprintf (mach->errstream, fmt, ap); | ||
280 | mu_stream_write (mach->errstream, "\n", 1, NULL); | ||
281 | va_end (ap); | ||
282 | } | ||
361 | 283 | ||
362 | void | 284 | void |
363 | mu_i_sv_print_value_list (mu_list_t list, mu_stream_t str) | 285 | mu_i_sv_debug_command (mu_sieve_machine_t mach, |
286 | size_t pc, | ||
287 | char const *what, | ||
288 | mu_list_t taglist, mu_list_t arglist) | ||
364 | { | 289 | { |
365 | mu_sieve_value_t val; | 290 | mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_DEBUG); |
366 | 291 | if (mach->locus.mu_file) | |
367 | val.type = SVT_VALUE_LIST; | 292 | mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>", |
368 | val.v.list = list; | 293 | MU_LOGMODE_LOCUS, |
369 | sieve_print_value (&val, str); | 294 | (unsigned) strlen (mach->locus.mu_file), |
295 | mach->locus.mu_file, | ||
296 | mach->locus.mu_line); | ||
297 | mu_stream_printf (mach->errstream, "%4zu: %s: %s", | ||
298 | pc, what, mach->identifier); | ||
299 | mu_i_sv_tagf (mach->errstream, taglist); | ||
300 | mu_i_sv_argf (mach->errstream, arglist); | ||
301 | mu_stream_write (mach->errstream, "\n", 1, NULL); | ||
370 | } | 302 | } |
371 | 303 | ||
372 | static int | 304 | void |
373 | tag_printer (void *item, void *data) | 305 | mu_i_sv_trace (mu_sieve_machine_t mach, const char *what, |
306 | mu_list_t taglist, mu_list_t arglist) | ||
374 | { | 307 | { |
375 | mu_sieve_runtime_tag_t *val = item; | 308 | if (!mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE4)) |
376 | mu_stream_t str = data; | 309 | return; |
377 | 310 | ||
378 | mu_stream_printf (str, "%s", val->tag); | 311 | mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_DEBUG); |
379 | if (val->arg) | 312 | if (mach->locus.mu_file) |
380 | { | 313 | mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>", |
381 | mu_stream_printf (str, "("); | 314 | MU_LOGMODE_LOCUS, |
382 | sieve_print_value (val->arg, str); | 315 | (unsigned) strlen (mach->locus.mu_file), |
383 | mu_stream_printf (str, ")"); | 316 | mach->locus.mu_file, |
384 | } | 317 | mach->locus.mu_line); |
385 | mu_stream_printf (str, " "); | 318 | mu_stream_printf (mach->errstream, "%zu: %s %s", mach->msgno, what, |
386 | return 0; | 319 | mach->identifier); |
320 | mu_i_sv_tagf (mach->errstream, taglist); | ||
321 | mu_i_sv_argf (mach->errstream, arglist); | ||
322 | mu_stream_printf (mach->errstream, "\n"); | ||
387 | } | 323 | } |
388 | 324 | ||
389 | void | 325 | void |
390 | mu_i_sv_print_tag_list (mu_list_t list, mu_stream_t str) | 326 | mu_sieve_log_action (mu_sieve_machine_t mach, const char *action, |
327 | const char *fmt, ...) | ||
391 | { | 328 | { |
392 | mu_list_foreach (list, tag_printer, str); | 329 | va_list ap; |
330 | |||
331 | if (!mach->logger) | ||
332 | return; | ||
333 | va_start (ap, fmt); | ||
334 | mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_INFO); | ||
335 | if (mach->locus.mu_file) | ||
336 | mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>", | ||
337 | MU_LOGMODE_LOCUS, | ||
338 | (unsigned) strlen (mach->locus.mu_file), | ||
339 | mach->locus.mu_file, | ||
340 | mach->locus.mu_line); | ||
341 | mach->logger (mach->data, mach->errstream, mach->msgno, mach->msg, | ||
342 | action, fmt, ap); | ||
343 | va_end (ap); | ||
393 | } | 344 | } |
394 | 345 | ||
395 | static int | 346 | static int |
396 | tag_finder (void *item, void *data) | 347 | tag_finder (void *item, void *data) |
397 | { | 348 | { |
... | @@ -437,7 +388,8 @@ mu_sieve_vlist_do (mu_sieve_value_t *val, mu_list_action_t ac, void *data) | ... | @@ -437,7 +388,8 @@ mu_sieve_vlist_do (mu_sieve_value_t *val, mu_list_action_t ac, void *data) |
437 | } | 388 | } |
438 | } | 389 | } |
439 | 390 | ||
440 | struct comp_data { | 391 | struct comp_data |
392 | { | ||
441 | mu_sieve_value_t *val; | 393 | mu_sieve_value_t *val; |
442 | mu_sieve_comparator_t comp; | 394 | mu_sieve_comparator_t comp; |
443 | mu_sieve_relcmp_t test; | 395 | mu_sieve_relcmp_t test; |
... | @@ -446,7 +398,8 @@ struct comp_data { | ... | @@ -446,7 +398,8 @@ struct comp_data { |
446 | size_t count; | 398 | size_t count; |
447 | }; | 399 | }; |
448 | 400 | ||
449 | struct comp_data2 { | 401 | struct comp_data2 |
402 | { | ||
450 | char *sample; | 403 | char *sample; |
451 | mu_sieve_comparator_t comp; | 404 | mu_sieve_comparator_t comp; |
452 | mu_sieve_relcmp_t test; | 405 | mu_sieve_relcmp_t test; | ... | ... |
-
Please register or sign in to post a comment