Commit 6efafc3f 6efafc3f28d24b6e31052263d1c8f154049e9f65 by Sergey Poznyakoff

sieve: more improvements to the argument/tag runtime access API

* include/mailutils/sieve.h (mu_sieve_handler_t): Change signature:
remove args and tags arguments, they are contained in struct
mu_sieve_machine now.
(mu_sieve_get_comparator)
(mu_sieve_relcmpn_t): Change signature.
(mu_sieve_tag_lookup,mu_sieve_tag_lookup_untyped): Remove
(mu_sieve_get_tag,mu_sieve_get_tag_untyped): New protos.
(mu_sieve_value_get_optional): Replace by
mu_sieve_get_arg_optional.
(mu_sieve_value_get_untyped): Replace by
mu_sieve_get_arg_untyped.
(mu_sieve_value_get): Replace by
mu_sieve_get_arg.
All uses changed.
* libmu_sieve/sieve-priv.h (mu_sieve_machine): New members:
arg_list and tag_list
* libmu_sieve/runtime.c (instr_run): Set up identifier, arg_list,
and tag_list in mu_sieve_machine_t before calling the handler.
Reset them afterward.
* libmu_sieve/util.c (mu_sieve_value_get_optional): Replace by
mu_sieve_get_arg_optional.
(mu_sieve_value_get_untyped): Replace by
mu_sieve_get_arg_untyped.
(mu_sieve_value_get): Replace by
mu_sieve_get_arg.
(mu_sieve_tag_lookup): Replace by mu_sieve_get_tag
(mu_sieve_tag_lookup_untyped): Replace by
mu_sieve_get_tag_untyped
1 parent 1528dfde
......@@ -78,7 +78,7 @@ _count_items (void *item, void *data)
/* Handler for the numaddr test */
static int
numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
numaddr_test (mu_sieve_machine_t mach)
{
mu_sieve_value_t *h;
struct val_ctr vc;
......@@ -86,9 +86,9 @@ numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
/* Retrieve required arguments: */
/* First argument: list of header names */
h = mu_sieve_value_get_untyped (mach, args, 0);
h = mu_sieve_get_arg_untyped (mach, 0);
/* Second argument: Limit on the number of addresses */
mu_sieve_value_get (mach, args, 1, SVT_NUMBER, &vc.limit);
mu_sieve_get_arg (mach, 1, SVT_NUMBER, &vc.limit);
/* Fill in the val_ctr structure */
mu_message_get_header (mu_sieve_get_message (mach), &vc.hdr);
......@@ -99,7 +99,7 @@ numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
/* Here rc >= 1 iff the counted number of addresses is greater or equal
to vc.limit. If `:under' tag was given we reverse the return value */
if (mu_sieve_tag_lookup (mach, tags, "under", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "under", SVT_VOID, NULL))
rc = !rc;
return rc;
......
gint @ fd86bf7d
Subproject commit 42f4712085b40173eaea58e14b1a579291a6fe3a
Subproject commit fd86bf7d44b0c970771830692ae7491447ebe8b1
......
......@@ -33,8 +33,7 @@ extern "C" {
typedef struct mu_sieve_machine *mu_sieve_machine_t;
typedef int (*mu_sieve_handler_t) (mu_sieve_machine_t mach,
mu_list_t args, mu_list_t tags);
typedef int (*mu_sieve_handler_t) (mu_sieve_machine_t mach);
typedef void (*mu_sieve_action_log_t) (mu_sieve_machine_t mach,
const char *action,
const char *fmt, va_list ap);
......@@ -175,19 +174,16 @@ mu_sieve_comparator_t mu_sieve_comparator_lookup (mu_sieve_machine_t mach,
const char *name,
int matchtype);
mu_sieve_comparator_t mu_sieve_get_comparator (mu_sieve_machine_t mach,
mu_list_t tags);
mu_sieve_comparator_t mu_sieve_get_comparator (mu_sieve_machine_t mach);
int mu_sieve_str_to_relcmp (const char *str, mu_sieve_relcmp_t *test,
mu_sieve_relcmpn_t *stest);
mu_sieve_relcmp_t mu_sieve_get_relcmp (mu_sieve_machine_t mach,
mu_list_t tags);
mu_sieve_relcmp_t mu_sieve_get_relcmp (mu_sieve_machine_t mach);
void mu_sieve_require (mu_sieve_machine_t mach, mu_list_t slist);
int mu_sieve_tag_lookup (mu_sieve_machine_t mach,
mu_list_t taglist, char *name,
int mu_sieve_get_tag (mu_sieve_machine_t mach, char *name,
mu_sieve_data_type type, void *ret);
int mu_sieve_tag_lookup_untyped (mu_sieve_machine_t mach, mu_list_t taglist,
int mu_sieve_get_tag_untyped (mu_sieve_machine_t mach,
char *name, mu_sieve_value_t **ret);
int mu_sieve_load_ext (mu_sieve_machine_t mach, const char *name);
......@@ -198,14 +194,11 @@ int mu_sieve_match_part_checker (mu_sieve_machine_t mach,
const char *name, mu_list_t tags,
mu_list_t args);
/* Operations on value lists */
mu_sieve_value_t *mu_sieve_value_get_optional (mu_sieve_machine_t mach,
mu_list_t vlist,
mu_sieve_value_t *mu_sieve_get_arg_optional (mu_sieve_machine_t mach,
size_t index);
mu_sieve_value_t *mu_sieve_value_get_untyped (mu_sieve_machine_t mach,
mu_list_t vlist,
mu_sieve_value_t *mu_sieve_get_arg_untyped (mu_sieve_machine_t mach,
size_t index);
int mu_sieve_value_get (mu_sieve_machine_t mach, mu_list_t vlist,
size_t index,
int mu_sieve_get_arg (mu_sieve_machine_t mach, size_t index,
mu_sieve_data_type type, void *ret);
int mu_sieve_vlist_do (mu_sieve_value_t *val, mu_list_action_t ac,
void *data);
......
......@@ -47,7 +47,7 @@ sieve_mark_deleted (mu_message_t msg, int deleted)
static int
sieve_action_stop (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_action_stop (mu_sieve_machine_t mach)
{
mu_sieve_log_action (mach, "STOP", NULL);
mach->pc = 0;
......@@ -55,7 +55,7 @@ sieve_action_stop (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
}
static int
sieve_action_keep (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_action_keep (mu_sieve_machine_t mach)
{
mu_sieve_log_action (mach, "KEEP", NULL);
if (mu_sieve_is_dry_run (mach))
......@@ -65,7 +65,7 @@ sieve_action_keep (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
}
static int
sieve_action_discard (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_action_discard (mu_sieve_machine_t mach)
{
mu_sieve_log_action (mach, "DISCARD", _("marking as deleted"));
if (mu_sieve_is_dry_run (mach))
......@@ -75,16 +75,16 @@ sieve_action_discard (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
}
static int
sieve_action_fileinto (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_action_fileinto (mu_sieve_machine_t mach)
{
int rc;
int mbflags = 0;
char *filename;
char *perms;
mu_sieve_value_get (mach, args, 0, SVT_STRING, &filename);
mu_sieve_get_arg (mach, 0, SVT_STRING, &filename);
if (mu_sieve_tag_lookup (mach, tags, "permissions", SVT_STRING, &perms))
if (mu_sieve_get_tag (mach, "permissions", SVT_STRING, &perms))
{
const char *p;
......@@ -281,7 +281,7 @@ build_mime (mu_mime_t *pmime, mu_message_t msg, const char *text)
}
static int
sieve_action_reject (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_action_reject (mu_sieve_machine_t mach)
{
mu_mime_t mime = NULL;
mu_mailer_t mailer = mu_sieve_get_mailer (mach);
......@@ -292,7 +292,7 @@ sieve_action_reject (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_header_t hdr;
char *text;
mu_sieve_value_get (mach, args, 0, SVT_STRING, &text);
mu_sieve_get_arg (mach, 0, SVT_STRING, &text);
mu_sieve_log_action (mach, "REJECT", NULL);
if (mu_sieve_is_dry_run (mach))
return 0;
......@@ -398,7 +398,7 @@ check_redirect_loop (mu_message_t msg)
}
static int
sieve_action_redirect (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_action_redirect (mu_sieve_machine_t mach)
{
mu_message_t msg, newmsg = NULL;
mu_address_t addr = NULL, from = NULL;
......@@ -408,7 +408,7 @@ sieve_action_redirect (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_mailer_t mailer = mu_sieve_get_mailer (mach);
char *addrstr;
mu_sieve_value_get (mach, args, 0, SVT_STRING, &addrstr);
mu_sieve_get_arg (mach, 0, SVT_STRING, &addrstr);
rc = mu_address_create (&addr, addrstr);
if (rc)
......
......@@ -127,11 +127,11 @@ _find_comparator (void *item, void *data)
}
mu_sieve_comparator_t
mu_sieve_get_comparator (mu_sieve_machine_t mach, mu_list_t tags)
mu_sieve_get_comparator (mu_sieve_machine_t mach)
{
mu_sieve_comparator_t comp = NULL;
mu_list_foreach (tags, _find_comparator, &comp);
mu_list_foreach (mach->tag_list, _find_comparator, &comp);
return comp ? comp : mu_sieve_comparator_lookup (mach,
"i;ascii-casemap",
MU_SIEVE_MATCH_IS);
......
......@@ -31,7 +31,7 @@
/* Syntax: addheader [:last] <field-name: string> <value: string>
*/
int
sieve_addheader (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_addheader (mu_sieve_machine_t mach)
{
const char *field_name;
const char *field_value;
......@@ -39,8 +39,8 @@ sieve_addheader (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_header_t hdr;
int rc;
mu_sieve_value_get (mach, args, 0, SVT_STRING, &field_name);
mu_sieve_value_get (mach, args, 1, SVT_STRING, &field_value);
mu_sieve_get_arg (mach, 0, SVT_STRING, &field_name);
mu_sieve_get_arg (mach, 1, SVT_STRING, &field_value);
mu_sieve_log_action (mach, "ADDHEADER", "%s: %s", field_name, field_value);
......@@ -58,7 +58,7 @@ sieve_addheader (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_sieve_abort (mach);
}
rc = (mu_sieve_tag_lookup (mach, tags, "last", SVT_VOID, NULL) ?
rc = (mu_sieve_get_tag (mach, "last", SVT_VOID, NULL) ?
mu_header_append : mu_header_prepend) (hdr, field_name, field_value);
if (rc)
{
......@@ -77,7 +77,7 @@ sieve_addheader (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
[<value-patterns: string-list>]
*/
int
sieve_deleteheader (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_deleteheader (mu_sieve_machine_t mach)
{
mu_sieve_value_t *val;
const char *field_name;
......@@ -89,8 +89,8 @@ sieve_deleteheader (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_iterator_t itr;
size_t i, idx = 0;
mu_sieve_value_get (mach, args, 0, SVT_STRING, &field_name);
val = mu_sieve_value_get_optional (mach, args, 1);
mu_sieve_get_arg (mach, 0, SVT_STRING, &field_name);
val = mu_sieve_get_arg_optional (mach, 1);
if (!val)
{
field_pattern = NULL;
......@@ -142,14 +142,14 @@ sieve_deleteheader (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
}
mu_header_get_iterator (hdr, &itr);
if (mu_sieve_tag_lookup (mach, tags, "last", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "last", SVT_VOID, NULL))
{
int backwards = 1;
mu_iterator_ctl (itr, mu_itrctl_set_direction, &backwards);
}
comp = mu_sieve_get_comparator (mach, tags);
comp = mu_sieve_get_comparator (mach);
mu_sieve_tag_lookup (mach, tags, "index", SVT_NUMBER, &idx);
mu_sieve_get_tag (mach, "index", SVT_NUMBER, &idx);
for (i = 0, mu_iterator_first (itr); !mu_iterator_is_done (itr);
mu_iterator_next (itr))
......
......@@ -145,22 +145,22 @@ list_retrieve_header (void *item, void *data, int idx, char **pval)
*/
static int
list_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
list_test (mu_sieve_machine_t mach)
{
mu_sieve_value_t *h, *v;
mu_sieve_comparator_t comp = mu_sieve_get_comparator (mach, tags);
mu_sieve_comparator_t comp = mu_sieve_get_comparator (mach);
struct header_closure clos;
int result;
memset (&clos, 0, sizeof clos);
if (!mu_sieve_tag_lookup (mach, tags, "delim", SVT_STRING, &clos.delim))
if (!mu_sieve_get_tag (mach, "delim", SVT_STRING, &clos.delim))
clos.delim = ",";
h = mu_sieve_value_get_untyped (mach, args, 0);
v = mu_sieve_value_get_untyped (mach, args, 1);
h = mu_sieve_get_arg_untyped (mach, 0);
v = mu_sieve_get_arg_untyped (mach, 1);
mu_message_get_header (mu_sieve_get_message (mach), &clos.header);
result = mu_sieve_vlist_compare (h, v, comp,
mu_sieve_get_relcmp (mach, tags),
mu_sieve_get_relcmp (mach),
list_retrieve_header,
&clos, NULL) > 0;
cleanup (&clos);
......
......@@ -74,7 +74,7 @@
#include <stdlib.h>
static int
moderator_filter_message (mu_sieve_machine_t mach, mu_list_t tags,
moderator_filter_message (mu_sieve_machine_t mach,
mu_message_t msg, int *pdiscard)
{
int rc;
......@@ -82,7 +82,7 @@ moderator_filter_message (mu_sieve_machine_t mach, mu_list_t tags,
mu_attribute_t attr;
char *arg;
if (mu_sieve_tag_lookup (mach, tags, "source", SVT_STRING, &arg))
if (mu_sieve_get_tag (mach, "source", SVT_STRING, &arg))
{
rc = mu_sieve_machine_inherit (mach, &newmach);
if (rc)
......@@ -101,7 +101,7 @@ moderator_filter_message (mu_sieve_machine_t mach, mu_list_t tags,
if (rc)
mu_sieve_error (mach, _("cannot compile source `%s'"), arg);
}
else if (mu_sieve_tag_lookup (mach, tags, "program", SVT_STRING, &arg))
else if (mu_sieve_get_tag (mach, "program", SVT_STRING, &arg))
{
struct mu_locus locus;
......@@ -265,7 +265,7 @@ moderator_message_get_part (mu_sieve_machine_t mach,
}
static int
moderator_action (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
moderator_action (mu_sieve_machine_t mach)
{
mu_message_t msg, orig;
int rc;
......@@ -294,7 +294,7 @@ moderator_action (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if ((rc = moderator_message_get_part (mach, msg, 2, &orig)))
mu_sieve_abort (mach);
rc = moderator_filter_message (mach, tags, orig, &discard);
rc = moderator_filter_message (mach, orig, &discard);
mu_message_unref (orig);
if (rc)
mu_sieve_abort (mach);
......@@ -311,13 +311,13 @@ moderator_action (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_sieve_abort (mach);
}
mu_sieve_tag_lookup (mach, tags, "address", SVT_STRING, &from);
mu_sieve_get_tag (mach, "address", SVT_STRING, &from);
if (moderator_discard_message (mach, request, from))
discard = 0;
else
{
if (!mu_sieve_tag_lookup (mach, tags, "keep", SVT_VOID, NULL))
if (!mu_sieve_get_tag (mach, "keep", SVT_VOID, NULL))
{
mu_attribute_t attr = 0;
......
......@@ -82,7 +82,7 @@
#define PIPE_ALL (PIPE_ENVELOPE | PIPE_HEADERS | PIPE_BODY)
int
sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test)
sieve_pipe (mu_sieve_machine_t mach, int test)
{
int retval = 0;
int rc, result;
......@@ -94,7 +94,7 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test)
const char *error_arg = NULL;
int pipe_mask = 0;
mu_sieve_value_get (mach, args, 0, SVT_STRING, &cmd);
mu_sieve_get_arg (mach, 0, SVT_STRING, &cmd);
if (mu_sieve_is_dry_run (mach))
return 0;
......@@ -102,11 +102,11 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test)
msg = mu_sieve_get_message (mach);
mu_message_get_envelope (msg, &env);
if (mu_sieve_tag_lookup (mach, tags, "envelope", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "envelope", SVT_VOID, NULL))
pipe_mask |= PIPE_ENVELOPE;
if (mu_sieve_tag_lookup (mach, tags, "header", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "header", SVT_VOID, NULL))
pipe_mask |= PIPE_HEADERS;
if (mu_sieve_tag_lookup (mach, tags, "body", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "body", SVT_VOID, NULL))
pipe_mask |= PIPE_BODY;
if (pipe_mask == 0)
pipe_mask = PIPE_ALL;
......@@ -194,7 +194,7 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test)
mu_sieve_abort (mach);
}
if (mu_sieve_tag_lookup (mach, tags, "exit", SVT_NUMBER, &n))
if (mu_sieve_get_tag (mach, "exit", SVT_NUMBER, &n))
code = n;
if (result == 0)
retval = code == 0;
......@@ -204,7 +204,7 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test)
{
int signo = WTERMSIG (status);
size_t n;
if (mu_sieve_tag_lookup (mach, tags, "signal", SVT_NUMBER, &n))
if (mu_sieve_get_tag (mach, "signal", SVT_NUMBER, &n))
retval = signo == n;
else
{
......@@ -228,16 +228,16 @@ sieve_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags, int test)
}
int
sieve_action_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_action_pipe (mu_sieve_machine_t mach)
{
mu_sieve_log_action (mach, "PIPE", NULL);
return sieve_pipe (mach, args, tags, 0);
return sieve_pipe (mach, 0);
}
int
sieve_test_pipe (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_test_pipe (mu_sieve_machine_t mach)
{
return sieve_pipe (mach, args, tags, 1);
return sieve_pipe (mach, 1);
}
......
......@@ -353,7 +353,7 @@ get_real_message_size (mu_message_t msg, size_t *psize)
*/
static int
spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
spamd_test (mu_sieve_machine_t mach)
{
char *buffer = NULL;
size_t size;
......@@ -381,12 +381,12 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
mu_sieve_abort (mach);
}
if (!mu_sieve_tag_lookup (mach, tags, "host", SVT_STRING, &host))
if (!mu_sieve_get_tag (mach, "host", SVT_STRING, &host))
host = "127.0.0.1";
if (mu_sieve_tag_lookup (mach, tags, "port", SVT_NUMBER, &num))
if (mu_sieve_get_tag (mach, "port", SVT_NUMBER, &num))
result = spamd_connect_tcp (mach, &stream, host, num);
else if (mu_sieve_tag_lookup (mach, tags, "socket", SVT_STRING, &str))
else if (mu_sieve_get_tag (mach, "socket", SVT_STRING, &str))
result = spamd_connect_socket (mach, &stream, str);
else
result = spamd_connect_tcp (mach, &stream, host, DEFAULT_SPAMD_PORT);
......@@ -421,7 +421,7 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
spamd_send_command (stream, "SYMBOLS SPAMC/1.2");
spamd_send_command (stream, "Content-length: %lu", (u_long) size);
if (mu_sieve_tag_lookup (mach, tags, "user", SVT_STRING, &str))
if (mu_sieve_get_tag (mach, "user", SVT_STRING, &str))
spamd_send_command (stream, "User: %s", str);
else
{
......@@ -464,12 +464,12 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if (!result)
{
if (mu_sieve_tag_lookup (mach, tags, "over", SVT_STRING, &str))
if (mu_sieve_get_tag (mach, "over", SVT_STRING, &str))
{
decode_float (&limit, str, 3, NULL);
result = score >= limit;
}
else if (mu_sieve_tag_lookup (mach, tags, "under", SVT_STRING, &str))
else if (mu_sieve_get_tag (mach, "under", SVT_STRING, &str))
{
decode_float (&limit, str, 3, NULL);
result = score <= limit;
......
......@@ -48,7 +48,7 @@
/* Handler for the timestamp test */
static int
timestamp_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
timestamp_test (mu_sieve_machine_t mach)
{
char const *hname;
char const *date;
......@@ -60,9 +60,9 @@ timestamp_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
/* Retrieve required arguments: */
/* First argument: header name */
mu_sieve_value_get (mach, args, 0, SVT_STRING, &hname);
mu_sieve_get_arg (mach, 0, SVT_STRING, &hname);
/* Second argument: date displacement */
mu_sieve_value_get (mach, args, 1, SVT_STRING, &date);
mu_sieve_get_arg (mach, 1, SVT_STRING, &date);
if (mu_parse_date (date, &tlimit, &now))
{
......@@ -93,7 +93,7 @@ timestamp_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
rc = tval > tlimit;
if (mu_sieve_tag_lookup (mach, tags, "before", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "before", SVT_VOID, NULL))
rc = !rc;
return rc;
......
......@@ -51,7 +51,7 @@
is the message text.
*/
static int
build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
build_mime (mu_sieve_machine_t mach, mu_mime_t *pmime,
mu_message_t msg, const char *text)
{
mu_mime_t mime = NULL;
......@@ -78,7 +78,7 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
return 1;
}
if (mu_sieve_tag_lookup (mach, tags, "mime", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "mime", SVT_VOID, NULL))
{
mu_stream_t fstr;
rc = mu_filter_create (&fstr, input, "base64",
......@@ -227,7 +227,7 @@ regex_comparator (void *item, void *data)
/* Decide whether EMAIL address should not be responded to.
*/
static int
noreply_address_p (mu_sieve_machine_t mach, mu_list_t tags, char *email)
noreply_address_p (mu_sieve_machine_t mach, char *email)
{
int i, rc = 0;
mu_sieve_value_t *arg;
......@@ -249,7 +249,7 @@ noreply_address_p (mu_sieve_machine_t mach, mu_list_t tags, char *email)
for (i = 0; rc == 0 && noreply_sender[i]; i++)
rc = regex_comparator (noreply_sender[i], &rd);
if (!rc && mu_sieve_tag_lookup_untyped (mach, tags, "noreply", &arg))
if (!rc && mu_sieve_get_tag_untyped (mach, "noreply", &arg))
rc = mu_sieve_vlist_do (arg, regex_comparator, &rd);
return rc;
......@@ -337,7 +337,7 @@ test_and_update_prop (mu_property_t prop, const char *from,
be answered, 0 if it should not, and throw exception if an error
occurs. */
static int
check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
check_db (mu_sieve_machine_t mach, char *from)
{
mu_property_t prop;
char *file;
......@@ -348,7 +348,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
const char *dbfile = "~/.vacation";
size_t n;
if (mu_sieve_tag_lookup (mach, tags, "days", SVT_NUMBER, &n))
if (mu_sieve_get_tag (mach, "days", SVT_NUMBER, &n))
{
days = n;
if (days > DAYS_MAX)
......@@ -357,7 +357,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
else
days = DAYS_DEFAULT;
mu_sieve_tag_lookup (mach, tags, "database", SVT_STRING, &dbfile);
mu_sieve_get_tag (mach, "database", SVT_STRING, &dbfile);
file = mu_tilde_expansion (dbfile, MU_HIERARCHY_DELIMITER, NULL);
if (!file)
......@@ -429,12 +429,12 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
"reply_prefix" tag.
*/
static void
re_subject (mu_sieve_machine_t mach, mu_list_t tags, char **psubject)
re_subject (mu_sieve_machine_t mach, char **psubject)
{
char *subject;
char *prefix = "Re";
mu_sieve_tag_lookup (mach, tags, "reply_prefix", SVT_STRING, &prefix);
mu_sieve_get_tag (mach, "reply_prefix", SVT_STRING, &prefix);
subject = malloc (strlen (*psubject) + strlen (prefix) + 3);
if (!subject)
......@@ -459,7 +459,7 @@ re_subject (mu_sieve_machine_t mach, mu_list_t tags, char **psubject)
Otherwise, reply_prefix is prepended to it. */
static void
vacation_subject (mu_sieve_machine_t mach, mu_list_t tags,
vacation_subject (mu_sieve_machine_t mach,
mu_message_t msg, mu_header_t newhdr)
{
char *value;
......@@ -467,7 +467,7 @@ vacation_subject (mu_sieve_machine_t mach, mu_list_t tags,
int subject_allocated = 0;
mu_header_t hdr;
if (mu_sieve_tag_lookup (mach, tags, "subject", SVT_STRING, &subject))
if (mu_sieve_get_tag (mach, "subject", SVT_STRING, &subject))
/* nothing */;
else if (mu_message_get_header (msg, &hdr) == 0
&& mu_header_aget_value_unfold (hdr, MU_HEADER_SUBJECT,
......@@ -488,7 +488,7 @@ vacation_subject (mu_sieve_machine_t mach, mu_list_t tags,
subject = p;
}
if (mu_sieve_tag_lookup (mach, tags, "reply_regex", SVT_STRING, &p))
if (mu_sieve_get_tag (mach, "reply_regex", SVT_STRING, &p))
{
char *err = NULL;
......@@ -504,7 +504,7 @@ vacation_subject (mu_sieve_machine_t mach, mu_list_t tags,
}
if (mu_unre_subject (subject, NULL))
re_subject (mach, tags, &subject);
re_subject (mach, &subject);
free (value);
}
......@@ -601,7 +601,7 @@ add_header (void *item, void *data)
/* Generate and send the reply message */
static int
vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
vacation_reply (mu_sieve_machine_t mach, mu_message_t msg,
char const *text, char const *to, char const *from)
{
mu_mime_t mime = NULL;
......@@ -613,7 +613,7 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
int rc;
mu_sieve_value_t *val;
if (mu_sieve_tag_lookup (mach, tags, "file", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "file", SVT_VOID, NULL))
{
mu_stream_t instr;
......@@ -628,7 +628,7 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
return -1;
}
if (mu_sieve_tag_lookup (mach, tags, "rfc2822", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "rfc2822", SVT_VOID, NULL))
{
rc = mu_stream_to_message (instr, &newmsg);
mu_stream_unref (instr);
......@@ -684,7 +684,7 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
return -1;
}
if (build_mime (mach, tags, &mime, msg, (char const *) trans[0]))
if (build_mime (mach, &mime, msg, (char const *) trans[0]))
{
mu_stream_unref (text_stream);
return -1;
......@@ -696,7 +696,7 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
}
else
{
if (build_mime (mach, tags, &mime, msg, text))
if (build_mime (mach, &mime, msg, text))
return -1;
mu_mime_get_message (mime, &newmsg);
mu_message_unref (newmsg);
......@@ -716,7 +716,7 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
{
mu_header_set_value (newhdr, MU_HEADER_TO, to, 0);
if (mu_sieve_tag_lookup_untyped (mach, tags, "header", &val))
if (mu_sieve_get_tag_untyped (mach, "header", &val))
{
struct header_closure hc;
hc.mach = mach;
......@@ -724,7 +724,7 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
mu_sieve_vlist_do (val, add_header, &hc);
}
vacation_subject (mach, tags, msg, newhdr);
vacation_subject (mach, msg, newhdr);
if (from)
{
......@@ -763,7 +763,7 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
}
int
sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_action_vacation (mu_sieve_machine_t mach)
{
int rc;
char *text, *from = NULL;
......@@ -775,12 +775,12 @@ sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if (diag (mach))
return 0;
mu_sieve_value_get (mach, args, 0, SVT_STRING, &text);
mu_sieve_get_arg (mach, 0, SVT_STRING, &text);
msg = mu_sieve_get_message (mach);
mu_message_get_header (msg, &hdr);
if (mu_sieve_tag_lookup (mach, tags, "sender", SVT_STRING, &from))
if (mu_sieve_get_tag (mach, "sender", SVT_STRING, &from))
{
/* Debugging hook: :sender sets fake reply address */
from = strdup (from);
......@@ -803,12 +803,12 @@ sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
my_address = mu_get_user_email (NULL);
if (mu_sieve_tag_lookup (mach, tags, "always_reply", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "always_reply", SVT_VOID, NULL))
return_address = my_address;
else
{
mu_sieve_value_t *val = NULL;
mu_sieve_tag_lookup_untyped (mach, tags, "aliases", &val);
mu_sieve_get_tag_untyped (mach, "aliases", &val);
if (match_addresses (hdr, my_address, val, &return_address) == 0)
{
free (my_address);
......@@ -816,19 +816,19 @@ sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
}
}
if (noreply_address_p (mach, tags, from)
if (noreply_address_p (mach, from)
|| bulk_precedence_p (hdr)
|| check_db (mach, tags, from))
|| check_db (mach, from))
{
free (from);
free (my_address);
return 0;
}
mu_sieve_tag_lookup (mach, tags, "return_address", SVT_STRING,
mu_sieve_get_tag (mach, "return_address", SVT_STRING,
&return_address);
rc = vacation_reply (mach, tags, msg, text, from, return_address);
rc = vacation_reply (mach, msg, text, from, return_address);
free (from);
free (my_address);
if (rc == -1)
......
......@@ -81,12 +81,12 @@ mu_sieve_str_to_relcmp (const char *str,
}
mu_sieve_relcmp_t
mu_sieve_get_relcmp (mu_sieve_machine_t mach, mu_list_t tags)
mu_sieve_get_relcmp (mu_sieve_machine_t mach)
{
char *str;
mu_sieve_relcmp_t test = NULL;
if (mu_sieve_tag_lookup (mach, tags, "value", SVT_STRING, &str) == 0)
if (mu_sieve_get_tag (mach, "value", SVT_STRING, &str) == 0)
return op_ne;
mu_sieve_str_to_relcmp (str, &test, NULL);
return test;
......
......@@ -59,39 +59,38 @@ _mu_i_sv_instr_line (mu_sieve_machine_t mach)
static int
instr_run (mu_sieve_machine_t mach, char const *what)
{
mu_sieve_handler_t han = SIEVE_ARG (mach, 0, handler);
mu_list_t arg_list = SIEVE_ARG (mach, 1, list);
mu_list_t tag_list = SIEVE_ARG (mach, 2, list);
int rc = 0;
mu_sieve_handler_t han = SIEVE_ARG (mach, 0, handler);
mach->arg_list = SIEVE_ARG (mach, 1, list);
mach->tag_list = SIEVE_ARG (mach, 2, list);
mach->identifier = SIEVE_ARG (mach, 3, string);
SIEVE_ADJUST(mach, 4);
SIEVE_ADJUST (mach, 4);
if (INSTR_DEBUG (mach))
mu_i_sv_debug_command (mach, mach->pc - 1,
what, tag_list, arg_list);
mu_i_sv_debug_command (mach, mach->pc - 1, what);
else
mu_i_sv_trace (mach, what, tag_list, arg_list);
mu_i_sv_trace (mach, what);
if (!INSTR_DISASS(mach))
rc = han (mach, arg_list, tag_list);
if (!INSTR_DISASS (mach))
rc = han (mach);
mach->arg_list = NULL;
mach->tag_list = NULL;
mach->identifier = NULL;
return rc;
}
void
_mu_i_sv_instr_action (mu_sieve_machine_t mach)
{
mach->identifier = SIEVE_ARG (mach, 3, string);
mach->action_count++;
instr_run (mach, "ACTION");
mach->identifier = NULL;
}
void
_mu_i_sv_instr_test (mu_sieve_machine_t mach)
{
mach->identifier = SIEVE_ARG (mach, 3, string);
mach->reg = instr_run (mach, "TEST");
mach->identifier = NULL;
}
void
......
......@@ -83,9 +83,13 @@ struct mu_sieve_machine
long reg; /* Numeric register */
mu_list_t stack; /* Runtime stack */
/* Call environment */
const char *identifier; /* Name of action or test being executed */
mu_list_t arg_list; /* Positional arguments */
mu_list_t tag_list; /* Tagged arguments */
int dry_run; /* Dry-run mode */
jmp_buf errbuf; /* Target location for non-local exits */
const char *identifier; /* Name of action or test being executed */
mu_mailbox_t mailbox; /* Mailbox to operate upon */
size_t msgno; /* Current message number */
......@@ -195,12 +199,9 @@ void mu_i_sv_error (mu_sieve_machine_t mach);
void mu_i_sv_debug (mu_sieve_machine_t mach, size_t pc, const char *fmt, ...)
MU_PRINTFLIKE(3,4);
void mu_i_sv_debug_command (mu_sieve_machine_t mach,
size_t pc,
char const *what,
mu_list_t taglist, mu_list_t arglist);
void mu_i_sv_trace (mu_sieve_machine_t mach, const char *what,
mu_list_t taglist, mu_list_t arglist);
void mu_i_sv_debug_command (mu_sieve_machine_t mach, size_t pc,
char const *what);
void mu_i_sv_trace (mu_sieve_machine_t mach, const char *what);
void mu_i_sv_argf (mu_stream_t str, mu_list_t list);
void mu_i_sv_valf (mu_stream_t str, mu_sieve_value_t *val);
......
......@@ -64,19 +64,18 @@ struct address_closure
};
static int
do_count (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags,
size_t count, int retval)
do_count (mu_sieve_machine_t mach, size_t count, int retval)
{
char *relcmp;
if (mu_sieve_tag_lookup (mach, tags, "count", SVT_STRING, &relcmp))
if (mu_sieve_get_tag (mach, "count", SVT_STRING, &relcmp))
{
size_t limit;
char *str;
mu_list_t list;
mu_sieve_relcmpn_t stest;
mu_sieve_value_get (mach, args, 1, SVT_STRING_LIST, &list);
mu_sieve_get_arg (mach, 1, SVT_STRING_LIST, &list);
mu_list_get (list, 0, (void **) &str);
limit = strtoul (str, &str, 10);
......@@ -110,27 +109,28 @@ retrieve_address (void *item, void *data, int idx, char **pval)
}
int
sieve_test_address (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_test_address (mu_sieve_machine_t mach)
{
mu_sieve_value_t *h, *v;
mu_header_t header = NULL;
mu_sieve_comparator_t comp = mu_sieve_get_comparator (mach, tags);
mu_sieve_relcmp_t test = mu_sieve_get_relcmp (mach, tags);
mu_sieve_comparator_t comp = mu_sieve_get_comparator (mach);
mu_sieve_relcmp_t test = mu_sieve_get_relcmp (mach);
struct address_closure clos;
int rc;
size_t count;
h = mu_sieve_value_get_untyped (mach, args, 0);
v = mu_sieve_value_get_untyped (mach, args, 1);
h = mu_sieve_get_arg_untyped (mach, 0);
v = mu_sieve_get_arg_untyped (mach, 1);
mu_message_get_header (mu_sieve_get_message (mach), &header);
clos.data = header;
clos.aget = sieve_get_address_part (tags);
clos.aget = sieve_get_address_part (mach->tag_list);
clos.addr = NULL;
rc = mu_sieve_vlist_compare (h, v, comp, test, retrieve_address, &clos, &count);
rc = mu_sieve_vlist_compare (h, v, comp, test, retrieve_address, &clos,
&count);
mu_address_destroy (&clos.addr);
return do_count (mach, args, tags, count, rc);
return do_count (mach, count, rc);
}
struct header_closure
......@@ -164,18 +164,18 @@ retrieve_header (void *item, void *data, int idx, char **pval)
}
int
sieve_test_header (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_test_header (mu_sieve_machine_t mach)
{
mu_sieve_value_t *h, *v;
mu_sieve_comparator_t comp = mu_sieve_get_comparator (mach, tags);
mu_sieve_relcmp_t test = mu_sieve_get_relcmp (mach, tags);
mu_sieve_comparator_t comp = mu_sieve_get_comparator (mach);
mu_sieve_relcmp_t test = mu_sieve_get_relcmp (mach);
size_t count, mcount = 0;
struct header_closure clos;
h = mu_sieve_value_get_untyped (mach, args, 0);
v = mu_sieve_value_get_untyped (mach, args, 1);
h = mu_sieve_get_arg_untyped (mach, 0);
v = mu_sieve_get_arg_untyped (mach, 1);
if (mu_sieve_tag_lookup (mach, tags, "mime", SVT_VOID, NULL))
if (mu_sieve_get_tag (mach, "mime", SVT_VOID, NULL))
{
int ismime = 0;
......@@ -204,7 +204,7 @@ sieve_test_header (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
&count))
return 1;
return do_count (mach, args, tags, count + mcount, 0);
return do_count (mach, count + mcount, 0);
}
int
......@@ -235,39 +235,39 @@ retrieve_envelope (void *item, void *data, int idx, char **pval)
}
int
sieve_test_envelope (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_test_envelope (mu_sieve_machine_t mach)
{
mu_sieve_value_t *h, *v;
mu_sieve_comparator_t comp = mu_sieve_get_comparator (mach, tags);
mu_sieve_relcmp_t test = mu_sieve_get_relcmp (mach, tags);
mu_sieve_comparator_t comp = mu_sieve_get_comparator (mach);
mu_sieve_relcmp_t test = mu_sieve_get_relcmp (mach);
struct address_closure clos;
int rc;
size_t count;
h = mu_sieve_value_get_untyped (mach, args, 0);
v = mu_sieve_value_get_untyped (mach, args, 1);
h = mu_sieve_get_arg_untyped (mach, 0);
v = mu_sieve_get_arg_untyped (mach, 1);
mu_message_get_envelope (mu_sieve_get_message (mach),
(mu_envelope_t*)&clos.data);
clos.aget = sieve_get_address_part (tags);
clos.aget = sieve_get_address_part (mach->tag_list);
clos.addr = NULL;
rc = mu_sieve_vlist_compare (h, v, comp, test, retrieve_envelope, &clos,
&count);
mu_address_destroy (&clos.addr);
return do_count (mach, args, tags, count, rc);
return do_count (mach, count, rc);
}
int
sieve_test_size (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_test_size (mu_sieve_machine_t mach)
{
int rc = 1;
mu_sieve_runtime_tag_t *tag = NULL;
size_t size;
size_t arg;
mu_sieve_value_get (mach, args, 0, SVT_NUMBER, &arg);
mu_sieve_get_arg (mach, 0, SVT_NUMBER, &arg);
mu_message_size (mu_sieve_get_message (mach), &size);
mu_list_get (tags, 0, (void **)&tag);
mu_list_get (mach->tag_list, 0, (void **)&tag);
if (!tag)
rc = size == arg;
else if (strcmp (tag->tag, "over") == 0)
......@@ -288,13 +288,13 @@ _test_exists (void *item, void *data)
}
int
sieve_test_exists (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
sieve_test_exists (mu_sieve_machine_t mach)
{
mu_header_t header = NULL;
mu_sieve_value_t *val;
mu_message_get_header (mu_sieve_get_message (mach), &header);
val = mu_sieve_value_get_untyped (mach, args, 0);
val = mu_sieve_get_arg_untyped (mach, 0);
return mu_sieve_vlist_do (val, _test_exists, header) == 0;
}
......
......@@ -177,11 +177,10 @@ mu_sieve_value_create (mu_sieve_data_type type, void *data)
}
mu_sieve_value_t *
mu_sieve_value_get_untyped (mu_sieve_machine_t mach, mu_list_t vlist,
size_t index)
mu_sieve_get_arg_untyped (mu_sieve_machine_t mach, size_t index)
{
mu_sieve_value_t *val = NULL;
int rc = mu_list_get (vlist, index, (void **)&val);
int rc = mu_list_get (mach->arg_list, index, (void **)&val);
if (rc)
{
mu_sieve_error (mach, _("can't get argument %zu: %s"),
......@@ -192,11 +191,10 @@ mu_sieve_value_get_untyped (mu_sieve_machine_t mach, mu_list_t vlist,
}
mu_sieve_value_t *
mu_sieve_value_get_optional (mu_sieve_machine_t mach, mu_list_t vlist,
size_t index)
mu_sieve_get_arg_optional (mu_sieve_machine_t mach, size_t index)
{
mu_sieve_value_t *val = NULL;
int rc = mu_list_get (vlist, index, (void **)&val);
int rc = mu_list_get (mach->arg_list, index, (void **)&val);
if (rc == MU_ERR_NOENT)
return NULL;
else if (rc)
......@@ -209,11 +207,10 @@ mu_sieve_value_get_optional (mu_sieve_machine_t mach, mu_list_t vlist,
}
int
mu_sieve_value_get (mu_sieve_machine_t mach, mu_list_t vlist,
size_t index,
mu_sieve_get_arg (mu_sieve_machine_t mach, size_t index,
mu_sieve_data_type type, void *ret)
{
mu_sieve_value_t *val = mu_sieve_value_get_untyped (mach, vlist, index);
mu_sieve_value_t *val = mu_sieve_get_arg_untyped (mach, index);
if (val->type != type)
{
mu_sieve_error (mach,
......@@ -325,8 +322,7 @@ mu_i_sv_debug (mu_sieve_machine_t mach, size_t pc, const char *fmt, ...)
void
mu_i_sv_debug_command (mu_sieve_machine_t mach,
size_t pc,
char const *what,
mu_list_t taglist, mu_list_t arglist)
char const *what)
{
if (mach->state_flags & MU_SV_SAVED_DBG_STATE)
{
......@@ -344,14 +340,13 @@ mu_i_sv_debug_command (mu_sieve_machine_t mach,
}
mu_stream_printf (mach->dbgstream, "%4zu: %s: %s",
pc, what, mach->identifier);
mu_i_sv_tagf (mach->dbgstream, taglist);
mu_i_sv_argf (mach->dbgstream, arglist);
mu_i_sv_tagf (mach->dbgstream, mach->tag_list);
mu_i_sv_argf (mach->dbgstream, mach->arg_list);
mu_stream_write (mach->dbgstream, "\n", 1, NULL);
}
void
mu_i_sv_trace (mu_sieve_machine_t mach, const char *what,
mu_list_t taglist, mu_list_t arglist)
mu_i_sv_trace (mu_sieve_machine_t mach, const char *what)
{
if (!mu_debug_level_p (mu_sieve_debug_handle, MU_DEBUG_TRACE4))
return;
......@@ -365,8 +360,8 @@ mu_i_sv_trace (mu_sieve_machine_t mach, const char *what,
mach->locus.mu_line);
mu_stream_printf (mach->errstream, "%zu: %s %s", mach->msgno, what,
mach->identifier);
mu_i_sv_tagf (mach->errstream, taglist);
mu_i_sv_argf (mach->errstream, arglist);
mu_i_sv_tagf (mach->errstream, mach->tag_list);
mu_i_sv_argf (mach->errstream, mach->arg_list);
mu_stream_printf (mach->errstream, "\n");
}
......@@ -401,13 +396,13 @@ tag_finder (void *item, void *data)
}
int
mu_sieve_tag_lookup_untyped (mu_sieve_machine_t mach, mu_list_t taglist,
mu_sieve_get_tag_untyped (mu_sieve_machine_t mach,
char *name, mu_sieve_value_t **ret)
{
mu_sieve_runtime_tag_t t;
t.tag = name;
if (taglist && mu_list_foreach (taglist, tag_finder, &t))
if (mach->tag_list && mu_list_foreach (mach->tag_list, tag_finder, &t))
{
if (ret)
*ret = t.arg;
......@@ -417,12 +412,12 @@ mu_sieve_tag_lookup_untyped (mu_sieve_machine_t mach, mu_list_t taglist,
}
int
mu_sieve_tag_lookup (mu_sieve_machine_t mach, mu_list_t taglist,
mu_sieve_get_tag (mu_sieve_machine_t mach,
char *name, mu_sieve_data_type type,
void *ret)
{
mu_sieve_value_t *val;
int found = mu_sieve_tag_lookup_untyped (mach, taglist, name, &val);
int found = mu_sieve_get_tag_untyped (mach, name, &val);
if (found)
{
......