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