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