chiark / gitweb /
tree-wide: remove Lennart's copyright lines
[elogind.git] / src / basic / syslog-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <string.h>
4 #include <syslog.h>
5
6 #include "hexdecoct.h"
7 #include "macro.h"
8 #include "string-table.h"
9 #include "syslog-util.h"
10
11 #if 0 /// UNNEEDED by elogind
12 int syslog_parse_priority(const char **p, int *priority, bool with_facility) {
13         int a = 0, b = 0, c = 0;
14         int k;
15
16         assert(p);
17         assert(*p);
18         assert(priority);
19
20         if ((*p)[0] != '<')
21                 return 0;
22
23         if (!strchr(*p, '>'))
24                 return 0;
25
26         if ((*p)[2] == '>') {
27                 c = undecchar((*p)[1]);
28                 k = 3;
29         } else if ((*p)[3] == '>') {
30                 b = undecchar((*p)[1]);
31                 c = undecchar((*p)[2]);
32                 k = 4;
33         } else if ((*p)[4] == '>') {
34                 a = undecchar((*p)[1]);
35                 b = undecchar((*p)[2]);
36                 c = undecchar((*p)[3]);
37                 k = 5;
38         } else
39                 return 0;
40
41         if (a < 0 || b < 0 || c < 0 ||
42             (!with_facility && (a || b || c > 7)))
43                 return 0;
44
45         if (with_facility)
46                 *priority = a*100 + b*10 + c;
47         else
48                 *priority = (*priority & LOG_FACMASK) | c;
49
50         *p += k;
51         return 1;
52 }
53 #endif // 0
54
55 static const char *const log_facility_unshifted_table[LOG_NFACILITIES] = {
56         [LOG_FAC(LOG_KERN)] = "kern",
57         [LOG_FAC(LOG_USER)] = "user",
58         [LOG_FAC(LOG_MAIL)] = "mail",
59         [LOG_FAC(LOG_DAEMON)] = "daemon",
60         [LOG_FAC(LOG_AUTH)] = "auth",
61         [LOG_FAC(LOG_SYSLOG)] = "syslog",
62         [LOG_FAC(LOG_LPR)] = "lpr",
63         [LOG_FAC(LOG_NEWS)] = "news",
64         [LOG_FAC(LOG_UUCP)] = "uucp",
65         [LOG_FAC(LOG_CRON)] = "cron",
66         [LOG_FAC(LOG_AUTHPRIV)] = "authpriv",
67         [LOG_FAC(LOG_FTP)] = "ftp",
68         [LOG_FAC(LOG_LOCAL0)] = "local0",
69         [LOG_FAC(LOG_LOCAL1)] = "local1",
70         [LOG_FAC(LOG_LOCAL2)] = "local2",
71         [LOG_FAC(LOG_LOCAL3)] = "local3",
72         [LOG_FAC(LOG_LOCAL4)] = "local4",
73         [LOG_FAC(LOG_LOCAL5)] = "local5",
74         [LOG_FAC(LOG_LOCAL6)] = "local6",
75         [LOG_FAC(LOG_LOCAL7)] = "local7"
76 };
77
78 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int, LOG_FAC(~0));
79
80 #if 0 /// UNNEEDED by elogind
81 bool log_facility_unshifted_is_valid(int facility) {
82         return facility >= 0 && facility <= LOG_FAC(~0);
83 }
84 #endif // 0
85
86 static const char *const log_level_table[] = {
87         [LOG_EMERG] = "emerg",
88         [LOG_ALERT] = "alert",
89         [LOG_CRIT] = "crit",
90         [LOG_ERR] = "err",
91         [LOG_WARNING] = "warning",
92         [LOG_NOTICE] = "notice",
93         [LOG_INFO] = "info",
94         [LOG_DEBUG] = "debug"
95 };
96
97 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG);
98
99 #if 0 /// UNNEEDED by elogind
100 bool log_level_is_valid(int level) {
101         return level >= 0 && level <= LOG_DEBUG;
102 }
103 #endif // 0