From dda5cd20ebac6913f2857fbd9ecbe5a646bce7db Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Mon, 30 Aug 2010 02:18:54 +0200 Subject: [PATCH] Simplified runtime command script location querying. --- TODO | 5 +- src/lib-sieve/cmd-discard.c | 13 ++-- src/lib-sieve/cmd-keep.c | 12 ++-- src/lib-sieve/cmd-redirect.c | 12 ++-- src/lib-sieve/ext-fileinto.c | 14 ++-- src/lib-sieve/ext-reject.c | 10 +-- src/lib-sieve/plugins/enotify/cmd-notify.c | 13 ++-- .../plugins/enotify/ext-enotify-common.c | 72 +++++++++---------- .../plugins/enotify/ext-enotify-common.h | 6 +- .../enotify/tst-notify-method-capability.c | 2 +- .../plugins/enotify/tst-valid-notify-method.c | 2 +- src/lib-sieve/plugins/notify/cmd-notify.c | 23 ++---- src/lib-sieve/plugins/vacation/cmd-vacation.c | 14 ++-- src/lib-sieve/sieve-actions.c | 11 ++- src/lib-sieve/sieve-actions.h | 3 +- src/lib-sieve/sieve-interpreter.c | 59 ++++++++------- src/lib-sieve/sieve-interpreter.h | 20 +++--- src/lib-sieve/sieve-result.c | 19 +++-- src/lib-sieve/sieve-result.h | 12 ++-- src/sieve-tools/debug/cmd-debug-print.c | 17 +++-- src/testsuite/testsuite-result.c | 4 +- src/testsuite/testsuite-script.c | 4 +- 22 files changed, 154 insertions(+), 193 deletions(-) diff --git a/TODO b/TODO index eed9fa369..8b64eee5d 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ Current activities: +* Code cleanup: + - Review all FIXMEs * Improve error handling and logging - Avoid reporting user-caused errors to the master log. - Review logging and error handling; add more warning/info/debug messages @@ -7,9 +9,6 @@ Current activities: Next (in order of descending priority/precedence): -* Code cleanup: - - Review all FIXMEs - * ## MAKE A SECOND RELEASE (0.2.x) ## * Unfinished new extensions: diff --git a/src/lib-sieve/cmd-discard.c b/src/lib-sieve/cmd-discard.c index 91bfdb5cd..2ebad6bb6 100644 --- a/src/lib-sieve/cmd-discard.c +++ b/src/lib-sieve/cmd-discard.c @@ -102,19 +102,14 @@ static bool cmd_discard_operation_dump */ static int cmd_discard_operation_execute -(const struct sieve_runtime_env *renv ATTR_UNUSED, +(const struct sieve_runtime_env *renv ATTR_UNUSED, sieve_size_t *address ATTR_UNUSED) -{ - unsigned int source_line; - - /* Source line */ - source_line = sieve_runtime_get_command_location(renv); - - sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, +{ + sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "discard action; cancel implicit keep"); if ( sieve_result_add_action - (renv, NULL, &act_discard, NULL, source_line, NULL, 0) < 0 ) + (renv, NULL, &act_discard, NULL, NULL, 0) < 0 ) return SIEVE_EXEC_FAILURE; return SIEVE_EXEC_OK; diff --git a/src/lib-sieve/cmd-keep.c b/src/lib-sieve/cmd-keep.c index 7f734ce35..2187f5a11 100644 --- a/src/lib-sieve/cmd-keep.c +++ b/src/lib-sieve/cmd-keep.c @@ -82,18 +82,14 @@ static bool cmd_keep_operation_dump static int cmd_keep_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) -{ +{ struct sieve_side_effects_list *slist = NULL; - unsigned int source_line; int ret = 0; /* * Read data */ - /* Source line */ - source_line = sieve_runtime_get_command_location(renv); - /* Optional operands (side effects only) */ if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) return ret; @@ -104,12 +100,12 @@ static int cmd_keep_operation_execute sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "keep action; store message in default mailbox"); - + /* Add keep action to result. */ - if ( sieve_result_add_keep(renv, slist, source_line) < 0 ) + if ( sieve_result_add_keep(renv, slist) < 0 ) return SIEVE_EXEC_FAILURE; - + return SIEVE_EXEC_OK; } diff --git a/src/lib-sieve/cmd-redirect.c b/src/lib-sieve/cmd-redirect.c index 5701047c0..eb87a6875 100644 --- a/src/lib-sieve/cmd-redirect.c +++ b/src/lib-sieve/cmd-redirect.c @@ -193,7 +193,6 @@ static int cmd_redirect_operation_execute struct sieve_side_effects_list *slist = NULL; struct act_redirect_context *act; string_t *redirect; - unsigned int source_line; pool_t pool; int ret; @@ -201,9 +200,6 @@ static int cmd_redirect_operation_execute * Read data */ - /* Source line */ - source_line = sieve_runtime_get_command_location(renv); - /* Optional operands (side effects only) */ if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) return ret; @@ -225,18 +221,18 @@ static int cmd_redirect_operation_execute sieve_runtime_trace(renv, 0, "forward message to address `%s'", str_sanitize(str_c(redirect), 80)); } - + /* Add redirect action to the result */ pool = sieve_result_pool(renv->result); act = p_new(pool, struct act_redirect_context, 1); act->to_address = p_strdup(pool, str_c(redirect)); - + if ( sieve_result_add_action - (renv, NULL, &act_redirect, slist, source_line, (void *) act, + (renv, NULL, &act_redirect, slist, (void *) act, svinst->max_redirects) < 0 ) return SIEVE_EXEC_FAILURE; - + return SIEVE_EXEC_OK; } diff --git a/src/lib-sieve/ext-fileinto.c b/src/lib-sieve/ext-fileinto.c index 63a83f30e..ebaa4b2f8 100644 --- a/src/lib-sieve/ext-fileinto.c +++ b/src/lib-sieve/ext-fileinto.c @@ -155,16 +155,12 @@ static int ext_fileinto_operation_execute struct sieve_side_effects_list *slist = NULL; string_t *folder; const char *mailbox; - unsigned int source_line; int ret = 0; - + /* * Read operands */ - /* Source line */ - source_line = sieve_runtime_get_command_location(renv); - /* Optional operands (side effects only) */ if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) return ret; @@ -172,7 +168,7 @@ static int ext_fileinto_operation_execute /* Folder operand */ if ( (ret=sieve_opr_string_read(renv, address, "folder", &folder)) <= 0 ) return ret; - + /* * Perform operation */ @@ -185,10 +181,10 @@ static int ext_fileinto_operation_execute sieve_runtime_trace(renv, 0, "store message in mailbox `%s'", str_sanitize(mailbox, 80)); } - - /* Add action to result */ + + /* Add action to result */ if ( sieve_act_store_add_to_result - (renv, slist, str_c(folder), source_line) < 0 ) + (renv, slist, str_c(folder)) < 0 ) return SIEVE_EXEC_FAILURE; return SIEVE_EXEC_OK; diff --git a/src/lib-sieve/ext-reject.c b/src/lib-sieve/ext-reject.c index c4d5cf57c..514d3fb60 100644 --- a/src/lib-sieve/ext-reject.c +++ b/src/lib-sieve/ext-reject.c @@ -267,7 +267,6 @@ static int ext_reject_operation_execute struct sieve_side_effects_list *slist = NULL; struct act_reject_context *act; string_t *reason; - unsigned int source_line; pool_t pool; int ret; @@ -275,9 +274,6 @@ static int ext_reject_operation_execute * Read data */ - /* Source line */ - source_line = sieve_runtime_get_command_location(renv); - /* Optional operands (side effects only) */ if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 ) return ret; @@ -306,11 +302,11 @@ static int ext_reject_operation_execute act = p_new(pool, struct act_reject_context, 1); act->reason = p_strdup(pool, str_c(reason)); act->ereject = ( sieve_operation_is(oprtn, ereject_operation) ); - + if ( sieve_result_add_action - (renv, this_ext, &act_reject, slist, source_line, (void *) act, 0) < 0 ) + (renv, this_ext, &act_reject, slist, (void *) act, 0) < 0 ) return SIEVE_EXEC_FAILURE; - + return SIEVE_EXEC_OK; } diff --git a/src/lib-sieve/plugins/enotify/cmd-notify.c b/src/lib-sieve/plugins/enotify/cmd-notify.c index 523b5dfc2..15f924c84 100644 --- a/src/lib-sieve/plugins/enotify/cmd-notify.c +++ b/src/lib-sieve/plugins/enotify/cmd-notify.c @@ -405,17 +405,12 @@ static int cmd_notify_operation_execute struct sieve_stringlist *options = NULL; const struct sieve_enotify_method *method; string_t *method_uri, *message = NULL, *from = NULL; - unsigned int source_line; int ret; /* * Read operands */ - - /* Source line */ - source_line = sieve_runtime_get_command_location(renv); - /* Optional operands */ for (;;) { @@ -475,7 +470,7 @@ static int cmd_notify_operation_execute /* Check operands */ if ( (ret=ext_enotify_runtime_check_operands - (renv, source_line, method_uri, message, from, options, &method, + (renv, method_uri, message, from, options, &method, &method_context)) > 0 ) { /* Add notify action to the result */ @@ -489,14 +484,14 @@ static int cmd_notify_operation_execute act->message = p_strdup(pool, str_c(message)); if ( from != NULL ) act->from = p_strdup(pool, str_c(from)); - + if ( sieve_result_add_action - (renv, this_ext, &act_notify, slist, source_line, (void *) act, 0) < 0 ) + (renv, this_ext, &act_notify, slist, (void *) act, 0) < 0 ) return SIEVE_EXEC_FAILURE; return SIEVE_EXEC_OK; } - + return ret; } diff --git a/src/lib-sieve/plugins/enotify/ext-enotify-common.c b/src/lib-sieve/plugins/enotify/ext-enotify-common.c index 86b9d13fb..c4c420e31 100644 --- a/src/lib-sieve/plugins/enotify/ext-enotify-common.c +++ b/src/lib-sieve/plugins/enotify/ext-enotify-common.c @@ -472,33 +472,32 @@ bool ext_enotify_compile_check_arguments */ bool ext_enotify_runtime_method_validate -(const struct sieve_runtime_env *renv, unsigned int source_line, - string_t *method_uri) +(const struct sieve_runtime_env *renv, string_t *method_uri) { const struct sieve_extension *this_ext = renv->oprtn->ext; const struct sieve_enotify_method *method; const char *uri = str_c(method_uri); const char *scheme; bool result = TRUE; - + /* Get the method */ - + if ( (scheme=ext_enotify_uri_scheme_parse(&uri)) == NULL ) return FALSE; - + if ( (method=ext_enotify_method_find(this_ext, scheme)) == NULL ) return FALSE; - + /* Validate the provided URI */ - + if ( method->def != NULL && method->def->runtime_check_uri != NULL ) { - struct sieve_enotify_env nenv; - + struct sieve_enotify_env nenv; + memset(&nenv, 0, sizeof(nenv)); nenv.method = method; nenv.ehandler = sieve_prefix_ehandler_create - (sieve_interpreter_get_error_handler(renv->interp), - sieve_error_script_location(renv->script, source_line), + (sieve_interpreter_get_error_handler(renv->interp), + sieve_runtime_get_full_command_location(renv), "valid_notify_method test"); /* Use the method check function to validate the URI */ @@ -509,32 +508,30 @@ bool ext_enotify_runtime_method_validate return result; } - + static const struct sieve_enotify_method *ext_enotify_get_method -(const struct sieve_runtime_env *renv, unsigned int source_line, - string_t *method_uri, const char **uri_body_r) +(const struct sieve_runtime_env *renv, string_t *method_uri, + const char **uri_body_r) { const struct sieve_extension *this_ext = renv->oprtn->ext; const struct sieve_enotify_method *method; const char *uri = str_c(method_uri); const char *scheme; - + /* Parse part before ':' of the uri (the scheme) and use it to identify * notify method. */ if ( (scheme=ext_enotify_uri_scheme_parse(&uri)) == NULL ) { - sieve_runtime_error - (renv, sieve_error_script_location(renv->script, source_line), - "invalid scheme part for method URI '%s'", - str_sanitize(str_c(method_uri), 80)); + sieve_runtime_error(renv, NULL, + "invalid scheme part for method URI '%s'", + str_sanitize(str_c(method_uri), 80)); return NULL; } - + /* Find the notify method */ if ( (method=ext_enotify_method_find(this_ext, scheme)) == NULL ) { - sieve_runtime_error - (renv, sieve_error_script_location(renv->script, source_line), - "invalid notify method '%s'", scheme); + sieve_runtime_error(renv, NULL, + "invalid notify method '%s'", scheme); return NULL; } @@ -544,17 +541,17 @@ static const struct sieve_enotify_method *ext_enotify_get_method } const char *ext_enotify_runtime_get_method_capability -(const struct sieve_runtime_env *renv, unsigned int source_line, +(const struct sieve_runtime_env *renv, string_t *method_uri, const char *capability) { const struct sieve_enotify_method *method; const char *uri_body; const char *result = NULL; - + /* Get method */ - method = ext_enotify_get_method(renv, source_line, method_uri, &uri_body); + method = ext_enotify_get_method(renv, method_uri, &uri_body); if ( method == NULL ) return NULL; - + /* Get requested capability */ if ( method->def != NULL && method->def->runtime_get_method_capability != NULL ) { @@ -563,14 +560,13 @@ const char *ext_enotify_runtime_get_method_capability memset(&nenv, 0, sizeof(nenv)); nenv.method = method; nenv.ehandler = sieve_prefix_ehandler_create - (sieve_interpreter_get_error_handler(renv->interp), - sieve_error_script_location(renv->script, source_line), + (sieve_interpreter_get_error_handler(renv->interp), + sieve_runtime_get_full_command_location(renv), "notify_method_capability test"); - + /* Execute method function to acquire capability value */ result = method->def->runtime_get_method_capability (&nenv, str_c(method_uri), uri_body, capability); - sieve_error_handler_unref(&nenv.ehandler); } @@ -578,18 +574,18 @@ const char *ext_enotify_runtime_get_method_capability } int ext_enotify_runtime_check_operands -(const struct sieve_runtime_env *renv, unsigned int source_line, +(const struct sieve_runtime_env *renv, string_t *method_uri, string_t *message, string_t *from, struct sieve_stringlist *options, const struct sieve_enotify_method **method_r, void **method_context) { const struct sieve_enotify_method *method; const char *uri_body; - + /* Get method */ - method = ext_enotify_get_method(renv, source_line, method_uri, &uri_body); + method = ext_enotify_get_method(renv, method_uri, &uri_body); if ( method == NULL ) return SIEVE_EXEC_FAILURE; - + /* Check provided operands */ if ( method->def != NULL && method->def->runtime_check_operands != NULL ) { struct sieve_enotify_env nenv; @@ -598,15 +594,15 @@ int ext_enotify_runtime_check_operands memset(&nenv, 0, sizeof(nenv)); nenv.method = method; nenv.ehandler = sieve_prefix_ehandler_create - (sieve_interpreter_get_error_handler(renv->interp), - sieve_error_script_location(renv->script, source_line), + (sieve_interpreter_get_error_handler(renv->interp), + sieve_runtime_get_full_command_location(renv), "notify action"); /* Execute check function */ if ( method->def->runtime_check_operands (&nenv, str_c(method_uri), uri_body, message, from, sieve_result_pool(renv->result), method_context) ) { - + /* Check any provided options */ if ( options != NULL ) { string_t *option = NULL; diff --git a/src/lib-sieve/plugins/enotify/ext-enotify-common.h b/src/lib-sieve/plugins/enotify/ext-enotify-common.h index b10b5bdc5..3a67da541 100644 --- a/src/lib-sieve/plugins/enotify/ext-enotify-common.h +++ b/src/lib-sieve/plugins/enotify/ext-enotify-common.h @@ -102,15 +102,15 @@ bool ext_enotify_compile_check_arguments */ bool ext_enotify_runtime_method_validate - (const struct sieve_runtime_env *renv, unsigned int source_line, + (const struct sieve_runtime_env *renv, string_t *method_uri); const char *ext_enotify_runtime_get_method_capability - (const struct sieve_runtime_env *renv, unsigned int source_line, + (const struct sieve_runtime_env *renv, string_t *method_uri, const char *capability); int ext_enotify_runtime_check_operands - (const struct sieve_runtime_env *renv, unsigned int source_line, + (const struct sieve_runtime_env *renv, string_t *method_uri, string_t *message, string_t *from, struct sieve_stringlist *options, const struct sieve_enotify_method **method_r, void **method_context); diff --git a/src/lib-sieve/plugins/enotify/tst-notify-method-capability.c b/src/lib-sieve/plugins/enotify/tst-notify-method-capability.c index dc7c06bdd..644d40feb 100644 --- a/src/lib-sieve/plugins/enotify/tst-notify-method-capability.c +++ b/src/lib-sieve/plugins/enotify/tst-notify-method-capability.c @@ -213,7 +213,7 @@ static int tst_notifymc_operation_execute sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "notify_method_capability test"); cap_value = ext_enotify_runtime_get_method_capability - (renv, 0 /* FIXME */, notify_uri, str_c(notify_capability)); + (renv, notify_uri, str_c(notify_capability)); if ( cap_value != NULL ) { value_list = sieve_single_stringlist_create_cstr(renv, cap_value, TRUE); diff --git a/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c b/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c index acbdcfa07..1d6c8149d 100644 --- a/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c +++ b/src/lib-sieve/plugins/enotify/tst-valid-notify-method.c @@ -127,7 +127,7 @@ static int tst_vnotifym_operation_execute uri_item = NULL; while ( (ret=sieve_stringlist_next_item(notify_uris, &uri_item)) > 0 ) { - if ( !ext_enotify_runtime_method_validate(renv, 0 /* FIXME */, uri_item) ) { + if ( !ext_enotify_runtime_method_validate(renv, uri_item) ) { all_valid = FALSE; break; } diff --git a/src/lib-sieve/plugins/notify/cmd-notify.c b/src/lib-sieve/plugins/notify/cmd-notify.c index 1b0c42662..773cbbdd0 100644 --- a/src/lib-sieve/plugins/notify/cmd-notify.c +++ b/src/lib-sieve/plugins/notify/cmd-notify.c @@ -420,17 +420,12 @@ static int cmd_notify_operation_execute sieve_number_t importance = 1; struct sieve_stringlist *options = NULL; string_t *message = NULL, *id = NULL; - unsigned int source_line; int ret; /* * Read operands */ - - /* Source line */ - source_line = sieve_runtime_get_command_location(renv); - /* Optional operands */ for (;;) { @@ -523,16 +518,14 @@ static int cmd_notify_operation_execute /* Add only if unique */ if ( i != rcpt_count ) { - sieve_runtime_warning(renv, - sieve_error_script_location(renv->script, source_line), + sieve_runtime_warning(renv, NULL, "duplicate recipient '%s' specified in the :options argument of " "the deprecated notify command", str_sanitize(str_c(raw_address), 128)); } else if ( array_count(&act->recipients) >= EXT_NOTIFY_MAX_RECIPIENTS ) { - sieve_runtime_warning(renv, - sieve_error_script_location(renv->script, source_line), + sieve_runtime_warning(renv, NULL, "more than the maximum %u recipients are specified " "for the deprecated notify command; " "the rest is discarded", EXT_NOTIFY_MAX_RECIPIENTS); @@ -545,25 +538,23 @@ static int cmd_notify_operation_execute recipient.normalized = p_strdup(pool, addr_norm); array_append(&act->recipients, &recipient, 1); - } + } } else { - sieve_runtime_error(renv, - sieve_error_script_location(renv->script, source_line), + sieve_runtime_error(renv, NULL, "specified :options address '%s' is invalid for " "the deprecated notify command: %s", str_sanitize(str_c(raw_address), 128), error); return SIEVE_EXEC_FAILURE; } } - + if ( ret < 0 ) { sieve_runtime_trace_error(renv, "invalid options stringlist"); return SIEVE_EXEC_BIN_CORRUPT; } - + if ( sieve_result_add_action - (renv, this_ext, &act_notify_old, NULL, source_line, (void *) act, 0) - < 0 ) + (renv, this_ext, &act_notify_old, NULL, (void *) act, 0) < 0 ) return SIEVE_EXEC_FAILURE; } diff --git a/src/lib-sieve/plugins/vacation/cmd-vacation.c b/src/lib-sieve/plugins/vacation/cmd-vacation.c index 8fc057354..f4e570628 100644 --- a/src/lib-sieve/plugins/vacation/cmd-vacation.c +++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c @@ -544,18 +544,13 @@ static int ext_vacation_operation_execute bool mime = FALSE; struct sieve_stringlist *addresses = NULL; string_t *reason, *subject = NULL, *from = NULL, *handle = NULL; - unsigned int source_line; const char *from_normalized = NULL; int ret; /* * Read code */ - - /* Source line */ - source_line = sieve_runtime_get_command_location(renv); - /* Optional operands */ for (;;) { @@ -623,8 +618,7 @@ static int ext_vacation_operation_execute from_normalized = sieve_address_normalize(from, &error); if ( from_normalized == NULL) { - sieve_runtime_error(renv, - sieve_error_script_location(renv->script, source_line), + sieve_runtime_error(renv, NULL, "specified :from address '%s' is invalid for vacation action: %s", str_sanitize(str_c(from), 128), error); } @@ -679,7 +673,7 @@ static int ext_vacation_operation_execute } if ( sieve_result_add_action - (renv, this_ext, &act_vacation, slist, source_line, (void *) act, 0) < 0 ) + (renv, this_ext, &act_vacation, slist, (void *) act, 0) < 0 ) return SIEVE_EXEC_FAILURE; return SIEVE_EXEC_OK; @@ -693,11 +687,11 @@ static int ext_vacation_operation_execute static int act_vacation_check_duplicate (const struct sieve_runtime_env *renv ATTR_UNUSED, - const struct sieve_action *act, + const struct sieve_action *act, const struct sieve_action *act_other) { if ( !act_other->executed ) { - sieve_runtime_error(renv, act->location, + sieve_runtime_error(renv, act->location, "duplicate vacation action not allowed " "(previously triggered one was here: %s)", act_other->location); return -1; diff --git a/src/lib-sieve/sieve-actions.c b/src/lib-sieve/sieve-actions.c index 819ea1fa3..5896ab5e9 100644 --- a/src/lib-sieve/sieve-actions.c +++ b/src/lib-sieve/sieve-actions.c @@ -210,20 +210,19 @@ const struct sieve_action_def act_store = { /* API */ int sieve_act_store_add_to_result -(const struct sieve_runtime_env *renv, - struct sieve_side_effects_list *seffects, const char *mailbox, - unsigned int source_line) +(const struct sieve_runtime_env *renv, + struct sieve_side_effects_list *seffects, const char *mailbox) { pool_t pool; struct act_store_context *act; - + /* Add redirect action to the result */ pool = sieve_result_pool(renv->result); act = p_new(pool, struct act_store_context, 1); act->mailbox = p_strdup(pool, mailbox); - return sieve_result_add_action(renv, NULL, &act_store, seffects, - source_line, (void *) act, 0); + return sieve_result_add_action(renv, NULL, &act_store, seffects, + (void *) act, 0); } void sieve_act_store_add_flags diff --git a/src/lib-sieve/sieve-actions.h b/src/lib-sieve/sieve-actions.h index 543a31773..974fce8cf 100644 --- a/src/lib-sieve/sieve-actions.h +++ b/src/lib-sieve/sieve-actions.h @@ -232,8 +232,7 @@ struct act_store_transaction { int sieve_act_store_add_to_result (const struct sieve_runtime_env *renv, - struct sieve_side_effects_list *seffects, const char *folder, - unsigned int source_line); + struct sieve_side_effects_list *seffects, const char *folder); void sieve_act_store_add_flags (const struct sieve_action_exec_env *aenv, void *tr_context, diff --git a/src/lib-sieve/sieve-interpreter.c b/src/lib-sieve/sieve-interpreter.c index 9f1af6136..c9001e853 100644 --- a/src/lib-sieve/sieve-interpreter.c +++ b/src/lib-sieve/sieve-interpreter.c @@ -224,7 +224,7 @@ void sieve_interpreter_free(struct sieve_interpreter **interp) sieve_binary_debug_reader_deinit(&(*interp)->dreader); sieve_binary_unref(&(*interp)->runenv.sbin); sieve_error_handler_unref(&(*interp)->ehandler); - + pool_unref(&((*interp)->pool)); *interp = NULL; } @@ -267,54 +267,54 @@ void sieve_interpreter_set_result sieve_result_ref(result); } -/* - * Error handling - */ - -/* This is not particularly user friendly, so avoid using this +/* + * Error handling */ -const char *sieve_runtime_location(const struct sieve_runtime_env *renv) -{ - const char *op = sieve_operation_mnemonic(renv->oprtn); - return t_strdup_printf("%s: #%08llx: %s", sieve_script_name(renv->script), - (unsigned long long) renv->oprtn->address, op); -} void sieve_runtime_error -(const struct sieve_runtime_env *runenv, const char *location, +(const struct sieve_runtime_env *renv, const char *location, const char *fmt, ...) { va_list args; - + + if ( location == NULL ) + location = sieve_runtime_get_full_command_location(renv); + va_start(args, fmt); T_BEGIN { - sieve_verror(runenv->interp->ehandler, location, fmt, args); + sieve_verror(renv->interp->ehandler, location, fmt, args); } T_END; va_end(args); } void sieve_runtime_warning -(const struct sieve_runtime_env *runenv, const char *location, +(const struct sieve_runtime_env *renv, const char *location, const char *fmt, ...) -{ +{ va_list args; - + + if ( location == NULL ) + location = sieve_runtime_get_full_command_location(renv); + va_start(args, fmt); T_BEGIN { - sieve_vwarning(runenv->interp->ehandler, location, fmt, args); + sieve_vwarning(renv->interp->ehandler, location, fmt, args); } T_END; va_end(args); } void sieve_runtime_log -(const struct sieve_runtime_env *runenv, const char *location, +(const struct sieve_runtime_env *renv, const char *location, const char *fmt, ...) -{ +{ va_list args; - + + if ( location == NULL ) + location = sieve_runtime_get_full_command_location(renv); + va_start(args, fmt); T_BEGIN { - sieve_vinfo(runenv->interp->ehandler, location, fmt, args); + sieve_vinfo(renv->interp->ehandler, location, fmt, args); } T_END; va_end(args); } @@ -354,8 +354,15 @@ unsigned int sieve_runtime_get_command_location return interp->command_line; } -/* - * Extension support +const char *sieve_runtime_get_full_command_location +(const struct sieve_runtime_env *renv) +{ + return sieve_error_script_location + (renv->script, sieve_runtime_get_command_location(renv)); +} + +/* + * Extension support */ void sieve_interpreter_extension_register @@ -365,7 +372,7 @@ void sieve_interpreter_extension_register struct sieve_interpreter_extension_reg *reg; if ( ext->id < 0 ) return; - + reg = array_idx_modifiable(&interp->extensions, (unsigned int) ext->id); reg->intext = intext; reg->ext = ext; diff --git a/src/lib-sieve/sieve-interpreter.h b/src/lib-sieve/sieve-interpreter.h index bece38319..649ea759b 100644 --- a/src/lib-sieve/sieve-interpreter.h +++ b/src/lib-sieve/sieve-interpreter.h @@ -57,40 +57,40 @@ sieve_size_t sieve_interpreter_program_counter int sieve_interpreter_program_jump (struct sieve_interpreter *interp, bool jump); - + /* * Test results - */ - + */ + void sieve_interpreter_set_test_result (struct sieve_interpreter *interp, bool result); bool sieve_interpreter_get_test_result (struct sieve_interpreter *interp); - + /* * Source location */ unsigned int sieve_runtime_get_source_location (const struct sieve_runtime_env *renv, sieve_size_t code_address); + unsigned int sieve_runtime_get_command_location (const struct sieve_runtime_env *renv); +const char *sieve_runtime_get_full_command_location + (const struct sieve_runtime_env *renv); /* * Error handling */ -/* This is not particularly user-friendly, so avoid using this.. */ -const char *sieve_runtime_location(const struct sieve_runtime_env *runenv); - void sieve_runtime_error - (const struct sieve_runtime_env *runenv, const char *location, + (const struct sieve_runtime_env *renv, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_runtime_warning - (const struct sieve_runtime_env *runenv, const char *location, + (const struct sieve_runtime_env *renv, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); void sieve_runtime_log - (const struct sieve_runtime_env *runenv, const char *location, + (const struct sieve_runtime_env *renv, const char *location, const char *fmt, ...) ATTR_FORMAT(3, 4); /* diff --git a/src/lib-sieve/sieve-result.c b/src/lib-sieve/sieve-result.c index 5a7adf523..45e955300 100644 --- a/src/lib-sieve/sieve-result.c +++ b/src/lib-sieve/sieve-result.c @@ -414,9 +414,9 @@ static void sieve_result_action_detach static int _sieve_result_add_action (const struct sieve_runtime_env *renv, const struct sieve_extension *ext, - const struct sieve_action_def *act_def, - struct sieve_side_effects_list *seffects, unsigned int source_line, - void *context, unsigned int instance_limit, bool keep) + const struct sieve_action_def *act_def, + struct sieve_side_effects_list *seffects, + void *context, unsigned int instance_limit, bool keep) { int ret = 0; unsigned int instance_count = 0; @@ -424,10 +424,10 @@ static int _sieve_result_add_action struct sieve_result *result = renv->result; struct sieve_result_action *raction = NULL, *kaction = NULL; struct sieve_action action; - + action.def = act_def; action.ext = ext; - action.location = sieve_error_script_location(renv->script, source_line); + action.location = sieve_runtime_get_full_command_location(renv); action.context = context; action.executed = FALSE; @@ -621,20 +621,19 @@ static int _sieve_result_add_action int sieve_result_add_action (const struct sieve_runtime_env *renv, const struct sieve_extension *ext, const struct sieve_action_def *act_def, - struct sieve_side_effects_list *seffects, unsigned int source_line, + struct sieve_side_effects_list *seffects, void *context, unsigned int instance_limit) { return _sieve_result_add_action - (renv, ext, act_def, seffects, source_line, context, instance_limit, FALSE); + (renv, ext, act_def, seffects, context, instance_limit, FALSE); } int sieve_result_add_keep -(const struct sieve_runtime_env *renv, struct sieve_side_effects_list *seffects, - unsigned int source_line) +(const struct sieve_runtime_env *renv, struct sieve_side_effects_list *seffects) { return _sieve_result_add_action (renv, renv->result->keep_action.ext, renv->result->keep_action.def, - seffects, source_line, NULL, 0, TRUE); + seffects, NULL, 0, TRUE); } void sieve_result_set_keep_action diff --git a/src/lib-sieve/sieve-result.h b/src/lib-sieve/sieve-result.h index 65f4db81e..f5991379d 100644 --- a/src/lib-sieve/sieve-result.h +++ b/src/lib-sieve/sieve-result.h @@ -99,20 +99,20 @@ void sieve_result_log /* * Result composition */ - + void sieve_result_add_implicit_side_effect (struct sieve_result *result, const struct sieve_action_def *to_action, - bool to_keep, const struct sieve_extension *ext, + bool to_keep, const struct sieve_extension *ext, const struct sieve_side_effect_def *seffect, void *context); - + int sieve_result_add_action (const struct sieve_runtime_env *renv, const struct sieve_extension *ext, const struct sieve_action_def *act_def, - struct sieve_side_effects_list *seffects, unsigned int source_line, + struct sieve_side_effects_list *seffects, void *context, unsigned int instance_limit); int sieve_result_add_keep - (const struct sieve_runtime_env *renv, - struct sieve_side_effects_list *seffects, unsigned int source_line); + (const struct sieve_runtime_env *renv, + struct sieve_side_effects_list *seffects); void sieve_result_set_keep_action (struct sieve_result *result, const struct sieve_extension *ext, diff --git a/src/sieve-tools/debug/cmd-debug-print.c b/src/sieve-tools/debug/cmd-debug-print.c index 375b4c868..7ce461e1d 100644 --- a/src/sieve-tools/debug/cmd-debug-print.c +++ b/src/sieve-tools/debug/cmd-debug-print.c @@ -1,6 +1,9 @@ /* Copyright (c) 2002-2010 Pigeonhole authors, see the included COPYING file */ - + +#include "lib.h" +#include "str-sanitize.h" + #include "sieve-extensions.h" #include "sieve-commands.h" #include "sieve-code.h" @@ -108,20 +111,20 @@ static int cmd_debug_print_operation_execute /* * Read operands */ - + /* Read message */ if ( (ret=sieve_opr_string_read(renv, address, "message", &message)) <= 0 ) return ret; - + /* * Perform operation */ - sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "DEBUG_PRINT"); - - /* FIXME: give this proper source location */ - sieve_runtime_log(renv, "DEBUG", "%s", str_c(message)); + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "debug_print \"%s\"", + str_sanitize(str_c(message), 80)); + + sieve_runtime_log(renv, NULL, "DEBUG: %s", str_c(message)); return SIEVE_EXEC_OK; } diff --git a/src/testsuite/testsuite-result.c b/src/testsuite/testsuite-result.c index 3581d101d..0d3d72642 100644 --- a/src/testsuite/testsuite-result.c +++ b/src/testsuite/testsuite-result.c @@ -67,8 +67,8 @@ bool testsuite_result_execute(const struct sieve_runtime_env *renv) int ret; if ( _testsuite_result == NULL ) { - sieve_runtime_error(renv, sieve_error_script_location(renv->script,0), - "testsuite: no result evaluated yet"); + sieve_runtime_error(renv, NULL, + "testsuite: trying to execute result, but no result evaluated yet"); return FALSE; } diff --git a/src/testsuite/testsuite-script.c b/src/testsuite/testsuite-script.c index 2186c4862..c3b0fcadc 100644 --- a/src/testsuite/testsuite-script.c +++ b/src/testsuite/testsuite-script.c @@ -99,8 +99,8 @@ bool testsuite_script_run(const struct sieve_runtime_env *renv) int ret; if ( _testsuite_compiled_script == NULL ) { - sieve_runtime_error(renv, sieve_error_script_location(renv->script,0), - "testsuite: no script compiled yet"); + sieve_runtime_error(renv, NULL, + "testsuite: trying to run script, but no script compiled yet"); return FALSE; } -- GitLab