Commit 05df35d0 05df35d07a46f70e7d09a4da39fdd2d7a7d58ed0 by Sergey Poznyakoff

sieve: simplify action logging API

* include/mailutils/sieve.h (mu_sieve_action_log_t): Change proto.
* lib/sieve.c (_sieve_action_log): Rewrite.
* libmu_sieve/util.c (mu_sieve_log_action): Rewrite.
* python/libmu_py/sieve.c (_sieve_action_printer): Rewrite.
* sieve/sieve.c (_sieve_action_log): Rewrite.
1 parent a4c1a0e8
......@@ -35,9 +35,7 @@ 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 void (*mu_sieve_action_log_t) (void *data,
mu_stream_t stream,
size_t msgno, mu_message_t msg,
typedef void (*mu_sieve_action_log_t) (mu_sieve_machine_t mach,
const char *action,
const char *fmt, va_list ap);
......
......@@ -28,15 +28,17 @@ struct sieve_log_data
};
static void
_sieve_action_log (void *data,
mu_stream_t stream, size_t msgno,
mu_message_t msg,
_sieve_action_log (mu_sieve_machine_t mach,
const char *action, const char *fmt, va_list ap)
{
struct sieve_log_data *ldat = data;
struct sieve_log_data *ldat = mu_sieve_get_data (mach);
int pfx = 0;
mu_stream_t stream;
mu_message_t msg = mu_sieve_get_message (mach);
mu_sieve_get_diag_stream (mach, &stream);
mu_stream_printf (stream, "\033s<%d>", MU_LOG_NOTICE);
if (ldat)
{
if (ldat->user)
......@@ -70,6 +72,7 @@ _sieve_action_log (void *data,
mu_stream_vprintf (stream, fmt, ap);
}
mu_stream_printf (stream, "\n");
mu_stream_unref (stream);
}
static int
......
......@@ -344,16 +344,11 @@ mu_sieve_log_action (mu_sieve_machine_t mach, const char *action,
if (!mach->logger)
return;
mu_stream_ioctl (mach->errstream, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &mach->locus);
va_start (ap, fmt);
mu_stream_printf (mach->errstream, "\033s<%d>", MU_LOG_INFO);
if (mach->locus.mu_file)
mu_stream_printf (mach->errstream, "\033O<%d>\033f<%u>%s\033l<%u>",
MU_LOGMODE_LOCUS,
(unsigned) strlen (mach->locus.mu_file),
mach->locus.mu_file,
mach->locus.mu_line);
mach->logger (mach->data, mach->errstream, mach->msgno, mach->msg,
action, fmt, ap);
mach->logger (mach, action, fmt, ap);
va_end (ap);
}
......
......@@ -236,8 +236,7 @@ api_sieve_message (PyObject *self, PyObject *args)
}
static void
_sieve_action_printer (void *data, mu_stream_t stream,
size_t msgno, mu_message_t msg,
_sieve_action_printer (mu_sieve_machine_t mach,
const char *action, const char *fmt, va_list ap)
{
PyObject *py_args;
......@@ -258,10 +257,12 @@ _sieve_action_printer (void *data, mu_stream_t stream,
PyStream *py_stm = PyStream_NEW ();
if (py_stm)
{
py_stm->stm = stream;
mu_stream_ref (stream);
size_t msgno;
py_msg->msg = msg;
mu_sieve_get_diag_stream (mach, &py_stm->stm);
msgno = mu_sieve_get_message_num (mach);
py_msg->msg = mu_sieve_get_message (mach);
Py_INCREF (py_msg);
PyDict_SetItemString (py_dict, "msgno",
......@@ -272,7 +273,7 @@ _sieve_action_printer (void *data, mu_stream_t stream,
if (mu_vasnprintf (&buf, &buflen, fmt, ap))
{
mu_stream_unref (stream);
mu_stream_destroy (&py_stm->stm);
return;
}
PyDict_SetItemString (py_dict, "text",
......@@ -282,7 +283,7 @@ _sieve_action_printer (void *data, mu_stream_t stream,
py_args = PyTuple_New (1);
if (py_args)
{
struct _mu_py_sieve_logger *s = data;
struct _mu_py_sieve_logger *s = mu_sieve_get_data (mach);
PyObject *py_fnc = s->py_action_printer;
Py_INCREF (py_dict);
......
......@@ -264,12 +264,15 @@ Compatibility debug flags:\n\
};
static void
_sieve_action_log (void *unused,
mu_stream_t stream, size_t msgno,
mu_message_t msg,
_sieve_action_log (mu_sieve_machine_t mach,
const char *action, const char *fmt, va_list ap)
{
size_t uid = 0;
mu_message_t msg;
mu_stream_t stream;
mu_sieve_get_diag_stream (mach, &stream);
msg = mu_sieve_get_message (mach);
mu_message_get_uid (msg, &uid);
mu_stream_printf (stream, "\033s<%d>\033%c<%d>", MU_LOG_NOTICE,
......@@ -283,6 +286,8 @@ _sieve_action_log (void *unused,
mu_stream_vprintf (stream, fmt, ap);
}
mu_stream_printf (stream, "\n");
mu_stream_unref (stream);
}
static int
......