2018-10-28 12:33:36 +01:00
|
|
|
/* SPDX-License-Identifier: ISC */
|
2018-10-28 12:10:07 +01:00
|
|
|
#include "syslogd.h"
|
|
|
|
|
2018-10-28 13:29:42 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2018-10-28 23:54:11 +01:00
|
|
|
static const char *levels[] = {
|
|
|
|
"emergency",
|
|
|
|
"alert",
|
|
|
|
"critical",
|
|
|
|
"error",
|
|
|
|
"warning",
|
|
|
|
"notice",
|
|
|
|
"info",
|
|
|
|
"debug",
|
2018-10-28 12:10:07 +01:00
|
|
|
};
|
|
|
|
|
2018-10-28 23:54:11 +01:00
|
|
|
static const char *facilities[] = {
|
|
|
|
"kernel",
|
|
|
|
"user",
|
|
|
|
"mail",
|
|
|
|
"daemon",
|
|
|
|
"auth",
|
|
|
|
"syslog",
|
|
|
|
"lpr",
|
|
|
|
"news",
|
|
|
|
"uucp",
|
|
|
|
"clock",
|
|
|
|
"authpriv",
|
|
|
|
"ftp",
|
|
|
|
"ntp",
|
|
|
|
"audit",
|
|
|
|
"alert",
|
|
|
|
"cron",
|
|
|
|
"local0",
|
|
|
|
"local1",
|
|
|
|
"local2",
|
|
|
|
"local3",
|
|
|
|
"local4",
|
|
|
|
"local5",
|
|
|
|
"local6",
|
|
|
|
"local7",
|
2018-10-28 12:10:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *level_id_to_string(int level)
|
|
|
|
{
|
2018-10-28 23:54:11 +01:00
|
|
|
return (level < 0 || level > 7) ? NULL : levels[level];
|
2018-10-28 12:10:07 +01:00
|
|
|
}
|
|
|
|
|
2018-10-28 13:29:42 +01:00
|
|
|
const char *facility_id_to_string(int id)
|
|
|
|
{
|
2018-10-28 23:54:11 +01:00
|
|
|
return (id < 0 || id > 23) ? NULL : facilities[id];
|
2018-10-28 13:29:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int level_id_from_string(const char *level)
|
|
|
|
{
|
2018-10-28 23:54:11 +01:00
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < sizeof(levels) / sizeof(levels[0]); ++i) {
|
|
|
|
if (strcmp(level, levels[i]) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2018-10-28 13:29:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int facility_id_from_string(const char *fac)
|
2018-10-28 12:10:07 +01:00
|
|
|
{
|
2018-10-28 23:54:11 +01:00
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < sizeof(facilities) / sizeof(facilities[0]); ++i) {
|
|
|
|
if (strcmp(fac, facilities[i]) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2018-10-28 12:10:07 +01:00
|
|
|
}
|