chiark / gitweb /
Prep v228: Substitute declaration masks (2/4)
[elogind.git] / src / basic / syslog-util.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <syslog.h>
23
24 #include "assert.h"
25 #include "hexdecoct.h"
26 #include "string-table.h"
27 #include "syslog-util.h"
28
29 /// UNNEEDED by elogind
30 #if 0
31 int syslog_parse_priority(const char **p, int *priority, bool with_facility) {
32         int a = 0, b = 0, c = 0;
33         int k;
34
35         assert(p);
36         assert(*p);
37         assert(priority);
38
39         if ((*p)[0] != '<')
40                 return 0;
41
42         if (!strchr(*p, '>'))
43                 return 0;
44
45         if ((*p)[2] == '>') {
46                 c = undecchar((*p)[1]);
47                 k = 3;
48         } else if ((*p)[3] == '>') {
49                 b = undecchar((*p)[1]);
50                 c = undecchar((*p)[2]);
51                 k = 4;
52         } else if ((*p)[4] == '>') {
53                 a = undecchar((*p)[1]);
54                 b = undecchar((*p)[2]);
55                 c = undecchar((*p)[3]);
56                 k = 5;
57         } else
58                 return 0;
59
60         if (a < 0 || b < 0 || c < 0 ||
61             (!with_facility && (a || b || c > 7)))
62                 return 0;
63
64         if (with_facility)
65                 *priority = a*100 + b*10 + c;
66         else
67                 *priority = (*priority & LOG_FACMASK) | c;
68
69         *p += k;
70         return 1;
71 }
72 #endif // 0
73
74 static const char *const log_facility_unshifted_table[LOG_NFACILITIES] = {
75         [LOG_FAC(LOG_KERN)] = "kern",
76         [LOG_FAC(LOG_USER)] = "user",
77         [LOG_FAC(LOG_MAIL)] = "mail",
78         [LOG_FAC(LOG_DAEMON)] = "daemon",
79         [LOG_FAC(LOG_AUTH)] = "auth",
80         [LOG_FAC(LOG_SYSLOG)] = "syslog",
81         [LOG_FAC(LOG_LPR)] = "lpr",
82         [LOG_FAC(LOG_NEWS)] = "news",
83         [LOG_FAC(LOG_UUCP)] = "uucp",
84         [LOG_FAC(LOG_CRON)] = "cron",
85         [LOG_FAC(LOG_AUTHPRIV)] = "authpriv",
86         [LOG_FAC(LOG_FTP)] = "ftp",
87         [LOG_FAC(LOG_LOCAL0)] = "local0",
88         [LOG_FAC(LOG_LOCAL1)] = "local1",
89         [LOG_FAC(LOG_LOCAL2)] = "local2",
90         [LOG_FAC(LOG_LOCAL3)] = "local3",
91         [LOG_FAC(LOG_LOCAL4)] = "local4",
92         [LOG_FAC(LOG_LOCAL5)] = "local5",
93         [LOG_FAC(LOG_LOCAL6)] = "local6",
94         [LOG_FAC(LOG_LOCAL7)] = "local7"
95 };
96
97 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int, LOG_FAC(~0));
98
99 /// UNNEEDED by elogind
100 #if 0
101 bool log_facility_unshifted_is_valid(int facility) {
102         return facility >= 0 && facility <= LOG_FAC(~0);
103 }
104 #endif // 0
105
106 static const char *const log_level_table[] = {
107         [LOG_EMERG] = "emerg",
108         [LOG_ALERT] = "alert",
109         [LOG_CRIT] = "crit",
110         [LOG_ERR] = "err",
111         [LOG_WARNING] = "warning",
112         [LOG_NOTICE] = "notice",
113         [LOG_INFO] = "info",
114         [LOG_DEBUG] = "debug"
115 };
116
117 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG);
118
119 /// UNNEEDED by elogind
120 #if 0
121 bool log_level_is_valid(int level) {
122         return level >= 0 && level <= LOG_DEBUG;
123 }
124 #endif // 0