Commit 7acfd2d8 7acfd2d86d9629f8510e4badd16d1098fe6df4b4 by Sergey Poznyakoff

Remove deprecated interfaces.

* include/mailutils/error.h (mu_error_pfn_t, mu_default_error_printer)
(mu_syslog_error_printer): Remove deprecated interfaces.
* libmailutils/diag/muerror.c: Likewise.
* libmailutils/stream/logstream.c (_log_write): Send
MU_IOCTL_LOGSTREAM_SET_SEVERITY to the transport stream.
* libmailutils/stream/syslogstream.c (_syslog_ctl): Translate
MU severity to syslog priority level and vice versa.
* mu/logger.c (mutool_logger): Bugfix.
1 parent 2613d48d
......@@ -28,15 +28,9 @@
extern "C" {
#endif
typedef int (*mu_error_pfn_t) (const char *fmt, va_list ap);
extern int mu_verror (const char *fmt, va_list ap);
extern int mu_error (const char *fmt, ...) MU_PRINTFLIKE(1,2);
extern void mu_error_set_print (mu_error_pfn_t) __attribute__((deprecated));
int mu_default_error_printer (const char *fmt, va_list ap);
int mu_syslog_error_printer (const char *fmt, va_list ap);
#ifdef __cplusplus
}
#endif
......
......@@ -46,71 +46,6 @@ mu_error (const char *fmt, ...)
return 0;
}
/* Compatibility layer */
int
mu_default_error_printer (const char *fmt, va_list ap)
{
if (mu_program_name)
fprintf (stderr, "%s: ", mu_program_name);
vfprintf (stderr, fmt, ap);
fputc ('\n', stderr);
return 0;
}
int
mu_syslog_error_printer (const char *fmt, va_list ap)
{
#ifdef HAVE_VSYSLOG
vsyslog (LOG_CRIT, fmt, ap);
#else
char buf[128];
vsnprintf (buf, sizeof buf, fmt, ap);
syslog (LOG_CRIT, "%s", buf);
#endif
return 0;
}
static void
compat_error_printer0 (mu_error_pfn_t pfn, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
pfn (fmt, ap);
va_end (ap);
}
static int
compat_error_printer (void *data, mu_log_level_t level, const char *buf)
{
if (!data)
mu_diag_stderr_printer (NULL, level, buf);
else
{
int len = strlen (buf);
if (len > 0 && buf[len-1] == '\n')
len--;
compat_error_printer0 (data, "%-.*s", len, buf);
}
return 0;
}
void
mu_error_set_print (mu_error_pfn_t pfn)
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, compat_error_printer, NULL);
mu_debug_set_data (debug, pfn, NULL, NULL);
#if 0
{
static int warned;
if (!warned)
{
warned = 1;
mu_diag_output ("this program uses mu_error_set_print, which is deprecated");
}
#endif
}
......
......@@ -159,6 +159,8 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size,
if (severity >= _mu_severity_num)
severity = MU_LOG_EMERG;
mu_stream_ioctl (sp->transport, MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
if (logmode & MU_LOGMODE_LOCUS)
{
if (fname)
......
......@@ -21,6 +21,7 @@
#include <syslog.h>
#include <errno.h>
#include <string.h>
#include <mailutils/errno.h>
#include <mailutils/stream.h>
#include <mailutils/sys/syslogstream.h>
......@@ -39,23 +40,44 @@ _syslog_stream_write (struct _mu_stream *stream, const char *buf,
return 0;
}
static int sev2prio[] = {
LOG_DEBUG,
LOG_INFO,
LOG_NOTICE,
LOG_WARNING,
LOG_ERR,
LOG_CRIT,
LOG_ALERT,
LOG_EMERG
};
static int
_syslog_ctl (struct _mu_stream *str, int op, void *arg)
{
struct _mu_syslog_stream *sp = (struct _mu_syslog_stream *)str;
unsigned n;
switch (op)
{
case MU_IOCTL_LOGSTREAM_GET_SEVERITY:
if (!arg)
return EINVAL;
*(int*)arg = sp->prio;
break;
for (n = 0; n < MU_ARRAY_SIZE (sev2prio); n++)
if (sev2prio[n] == sp->prio)
{
*(int*)arg = n;
break;
}
return MU_ERR_FAILURE;
case MU_IOCTL_LOGSTREAM_SET_SEVERITY:
if (!arg)
return EINVAL;
sp->prio = *(int*)arg;
n = *(unsigned*)arg;
if (n < MU_ARRAY_SIZE (sev2prio))
sp->prio = sev2prio[n];
else
return EINVAL;
break;
default:
......
......@@ -184,6 +184,7 @@ mutool_logger (int argc, char **argv)
mu_stream_write (logger, argv[i], strlen (argv[i]), NULL);
}
mu_stream_write (logger, "\n", 1, NULL);
return 0;
}
else if (!input_file || strcmp (input_file, "-") == 0)
{
......