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 @@ ...@@ -28,15 +28,9 @@
28 extern "C" { 28 extern "C" {
29 #endif 29 #endif
30 30
31 typedef int (*mu_error_pfn_t) (const char *fmt, va_list ap);
32
33 extern int mu_verror (const char *fmt, va_list ap); 31 extern int mu_verror (const char *fmt, va_list ap);
34 extern int mu_error (const char *fmt, ...) MU_PRINTFLIKE(1,2); 32 extern int mu_error (const char *fmt, ...) MU_PRINTFLIKE(1,2);
35 extern void mu_error_set_print (mu_error_pfn_t) __attribute__((deprecated));
36 33
37 int mu_default_error_printer (const char *fmt, va_list ap);
38 int mu_syslog_error_printer (const char *fmt, va_list ap);
39
40 #ifdef __cplusplus 34 #ifdef __cplusplus
41 } 35 }
42 #endif 36 #endif
......
...@@ -46,71 +46,6 @@ mu_error (const char *fmt, ...) ...@@ -46,71 +46,6 @@ mu_error (const char *fmt, ...)
46 return 0; 46 return 0;
47 } 47 }
48 48
49
50 /* Compatibility layer */
51 int
52 mu_default_error_printer (const char *fmt, va_list ap)
53 {
54 if (mu_program_name)
55 fprintf (stderr, "%s: ", mu_program_name);
56 vfprintf (stderr, fmt, ap);
57 fputc ('\n', stderr);
58 return 0;
59 }
60
61 int
62 mu_syslog_error_printer (const char *fmt, va_list ap)
63 {
64 #ifdef HAVE_VSYSLOG
65 vsyslog (LOG_CRIT, fmt, ap);
66 #else
67 char buf[128];
68 vsnprintf (buf, sizeof buf, fmt, ap);
69 syslog (LOG_CRIT, "%s", buf);
70 #endif
71 return 0;
72 }
73
74 static void
75 compat_error_printer0 (mu_error_pfn_t pfn, const char *fmt, ...)
76 {
77 va_list ap;
78 va_start (ap, fmt);
79 pfn (fmt, ap);
80 va_end (ap);
81 }
82
83 static int
84 compat_error_printer (void *data, mu_log_level_t level, const char *buf)
85 {
86 if (!data)
87 mu_diag_stderr_printer (NULL, level, buf);
88 else
89 {
90 int len = strlen (buf);
91 if (len > 0 && buf[len-1] == '\n')
92 len--;
93 compat_error_printer0 (data, "%-.*s", len, buf);
94 }
95 return 0;
96 }
97 49
98 void
99 mu_error_set_print (mu_error_pfn_t pfn)
100 {
101 mu_debug_t debug;
102 mu_diag_get_debug (&debug);
103 mu_debug_set_print (debug, compat_error_printer, NULL);
104 mu_debug_set_data (debug, pfn, NULL, NULL);
105 #if 0
106 {
107 static int warned;
108 if (!warned)
109 {
110 warned = 1;
111 mu_diag_output ("this program uses mu_error_set_print, which is deprecated");
112 }
113 #endif
114 }
115 50
116 51
......
...@@ -159,6 +159,8 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, ...@@ -159,6 +159,8 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size,
159 if (severity >= _mu_severity_num) 159 if (severity >= _mu_severity_num)
160 severity = MU_LOG_EMERG; 160 severity = MU_LOG_EMERG;
161 161
162 mu_stream_ioctl (sp->transport, MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
163
162 if (logmode & MU_LOGMODE_LOCUS) 164 if (logmode & MU_LOGMODE_LOCUS)
163 { 165 {
164 if (fname) 166 if (fname)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
21 #include <syslog.h> 21 #include <syslog.h>
22 #include <errno.h> 22 #include <errno.h>
23 #include <string.h> 23 #include <string.h>
24 #include <mailutils/errno.h>
24 #include <mailutils/stream.h> 25 #include <mailutils/stream.h>
25 #include <mailutils/sys/syslogstream.h> 26 #include <mailutils/sys/syslogstream.h>
26 27
...@@ -39,23 +40,44 @@ _syslog_stream_write (struct _mu_stream *stream, const char *buf, ...@@ -39,23 +40,44 @@ _syslog_stream_write (struct _mu_stream *stream, const char *buf,
39 return 0; 40 return 0;
40 } 41 }
41 42
43 static int sev2prio[] = {
44 LOG_DEBUG,
45 LOG_INFO,
46 LOG_NOTICE,
47 LOG_WARNING,
48 LOG_ERR,
49 LOG_CRIT,
50 LOG_ALERT,
51 LOG_EMERG
52 };
53
42 static int 54 static int
43 _syslog_ctl (struct _mu_stream *str, int op, void *arg) 55 _syslog_ctl (struct _mu_stream *str, int op, void *arg)
44 { 56 {
45 struct _mu_syslog_stream *sp = (struct _mu_syslog_stream *)str; 57 struct _mu_syslog_stream *sp = (struct _mu_syslog_stream *)str;
46 58 unsigned n;
59
47 switch (op) 60 switch (op)
48 { 61 {
49 case MU_IOCTL_LOGSTREAM_GET_SEVERITY: 62 case MU_IOCTL_LOGSTREAM_GET_SEVERITY:
50 if (!arg) 63 if (!arg)
51 return EINVAL; 64 return EINVAL;
52 *(int*)arg = sp->prio; 65 for (n = 0; n < MU_ARRAY_SIZE (sev2prio); n++)
53 break; 66 if (sev2prio[n] == sp->prio)
67 {
68 *(int*)arg = n;
69 break;
70 }
71 return MU_ERR_FAILURE;
54 72
55 case MU_IOCTL_LOGSTREAM_SET_SEVERITY: 73 case MU_IOCTL_LOGSTREAM_SET_SEVERITY:
56 if (!arg) 74 if (!arg)
57 return EINVAL; 75 return EINVAL;
58 sp->prio = *(int*)arg; 76 n = *(unsigned*)arg;
77 if (n < MU_ARRAY_SIZE (sev2prio))
78 sp->prio = sev2prio[n];
79 else
80 return EINVAL;
59 break; 81 break;
60 82
61 default: 83 default:
......
...@@ -184,6 +184,7 @@ mutool_logger (int argc, char **argv) ...@@ -184,6 +184,7 @@ mutool_logger (int argc, char **argv)
184 mu_stream_write (logger, argv[i], strlen (argv[i]), NULL); 184 mu_stream_write (logger, argv[i], strlen (argv[i]), NULL);
185 } 185 }
186 mu_stream_write (logger, "\n", 1, NULL); 186 mu_stream_write (logger, "\n", 1, NULL);
187 return 0;
187 } 188 }
188 else if (!input_file || strcmp (input_file, "-") == 0) 189 else if (!input_file || strcmp (input_file, "-") == 0)
189 { 190 {
......