1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
11 #include "hexdecoct.h"
13 #include "string-table.h"
14 #include "syslog-util.h"
16 int syslog_parse_priority(const char **p
, int *priority
, bool with_facility
) {
17 int a
= 0, b
= 0, c
= 0;
31 c
= undecchar((*p
)[1]);
33 } else if ((*p
)[3] == '>') {
34 b
= undecchar((*p
)[1]);
35 c
= undecchar((*p
)[2]);
37 } else if ((*p
)[4] == '>') {
38 a
= undecchar((*p
)[1]);
39 b
= undecchar((*p
)[2]);
40 c
= undecchar((*p
)[3]);
45 if (a
< 0 || b
< 0 || c
< 0 ||
46 (!with_facility
&& (a
|| b
|| c
> 7)))
50 *priority
= a
*100 + b
*10 + c
;
52 *priority
= (*priority
& LOG_FACMASK
) | c
;
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"
81 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted
, int, LOG_FAC(~0));
83 bool log_facility_unshifted_is_valid(int facility
) {
84 return facility
>= 0 && facility
<= LOG_FAC(~0);
87 static const char *const log_level_table
[] = {
88 [LOG_EMERG
] = "emerg",
89 [LOG_ALERT
] = "alert",
92 [LOG_WARNING
] = "warning",
93 [LOG_NOTICE
] = "notice",
98 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level
, int, LOG_DEBUG
);
100 bool log_level_is_valid(int level
) {
101 return level
>= 0 && level
<= LOG_DEBUG
;