Commit 78148745 78148745b40a9c7308c30b049f313182eeb41b1b by Sergey Poznyakoff

*** empty log message ***

1 parent e5fc59d2
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20 #include <syslog.h>
21 #include <string.h>
22
23 struct kw_int
24 {
25 char *name;
26 int tok;
27 };
28
29 static int
30 syslog_to_n (struct kw_int *kw, char *str, int *pint)
31 {
32 int i;
33
34 if (strncasecmp (str, "LOG_", 4) == 0)
35 str += 4;
36
37 for (; kw->name; kw++)
38 if (strcasecmp (kw->name, str) == 0)
39 {
40 *pint = kw->tok;
41 return 0;
42 }
43 return 1;
44 }
45
46 static const char *
47 n_to_syslog (struct kw_int *kw, int n)
48 {
49 for (; kw->name; kw++)
50 if (kw->tok == n)
51 return kw->name;
52 return NULL;
53 }
54
55 static struct kw_int kw_facility[] = {
56 { "USER", LOG_USER },
57 { "DAEMON", LOG_DAEMON },
58 { "AUTH", LOG_AUTH },
59 { "AUTHPRIV",LOG_AUTHPRIV },
60 { "MAIL", LOG_MAIL },
61 { "CRON", LOG_CRON },
62 { "LOCAL0", LOG_LOCAL0 },
63 { "LOCAL1", LOG_LOCAL1 },
64 { "LOCAL2", LOG_LOCAL2 },
65 { "LOCAL3", LOG_LOCAL3 },
66 { "LOCAL4", LOG_LOCAL4 },
67 { "LOCAL5", LOG_LOCAL5 },
68 { "LOCAL6", LOG_LOCAL6 },
69 { "LOCAL7", LOG_LOCAL7 },
70 { NULL }
71 };
72
73 int
74 mu_string_to_syslog_facility (char *str, int *pfacility)
75 {
76 return syslog_to_n (kw_facility, str, pfacility);
77 }
78
79 const char *
80 mu_syslog_facility_to_string (int n)
81 {
82 return n_to_syslog (kw_facility, n);
83 }
84
85 static struct kw_int kw_prio[] = {
86 { "EMERG", LOG_EMERG },
87 { "ALERT", LOG_ALERT },
88 { "CRIT", LOG_CRIT },
89 { "ERR", LOG_ERR },
90 { "WARNING", LOG_WARNING },
91 { "NOTICE", LOG_NOTICE },
92 { "INFO", LOG_INFO },
93 { "DEBUG", LOG_DEBUG },
94 { NULL }
95 };
96
97 int
98 mu_string_to_syslog_priority (char *str, int *pprio)
99 {
100 return syslog_to_n (kw_prio, str, pprio);
101 }
102
103 const char *
104 mu_syslog_priority_to_string (int n)
105 {
106 return n_to_syslog (kw_prio, n);
107 }
108
109
110 int log_facility;