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 12:10:07 +01:00
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
int id;
|
|
|
|
} enum_map_t;
|
|
|
|
|
|
|
|
static const enum_map_t levels[] = {
|
|
|
|
{ "emergency", 0 },
|
|
|
|
{ "alert", 1 },
|
|
|
|
{ "critical", 2 },
|
|
|
|
{ "error", 3 },
|
|
|
|
{ "warning", 4 },
|
|
|
|
{ "notice", 5 },
|
|
|
|
{ "info", 6 },
|
|
|
|
{ "debug", 7 },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const enum_map_t facilities[] = {
|
|
|
|
{ "kernel", 0 },
|
|
|
|
{ "user", 1 },
|
|
|
|
{ "mail", 2 },
|
|
|
|
{ "daemon", 3 },
|
|
|
|
{ "auth", 4 },
|
|
|
|
{ "syslog", 5 },
|
|
|
|
{ "lpr", 6 },
|
|
|
|
{ "news", 7 },
|
|
|
|
{ "uucp", 8 },
|
|
|
|
{ "clock", 9 },
|
|
|
|
{ "authpriv", 10 },
|
|
|
|
{ "ftp", 11 },
|
|
|
|
{ "ntp", 12 },
|
|
|
|
{ "audit", 13 },
|
|
|
|
{ "alert", 14 },
|
|
|
|
{ "cron", 15 },
|
|
|
|
{ "local0", 16 },
|
|
|
|
{ "local1", 17 },
|
|
|
|
{ "local2", 18 },
|
|
|
|
{ "local3", 19 },
|
|
|
|
{ "local4", 20 },
|
|
|
|
{ "local5", 21 },
|
|
|
|
{ "local6", 22 },
|
|
|
|
{ "local7", 23 },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *enum_to_name(const enum_map_t *map, int id)
|
|
|
|
{
|
|
|
|
while (map->name != NULL && map->id != id)
|
|
|
|
++map;
|
|
|
|
|
|
|
|
return map->name;
|
|
|
|
}
|
|
|
|
|
2018-10-28 13:29:42 +01:00
|
|
|
static int enum_by_name(const enum_map_t *map, const char *name)
|
|
|
|
{
|
|
|
|
while (map->name != NULL && strcmp(map->name, name) != 0)
|
|
|
|
++map;
|
|
|
|
|
|
|
|
return map->name == NULL ? -1 : map->id;
|
|
|
|
}
|
|
|
|
|
2018-10-28 12:10:07 +01:00
|
|
|
const char *level_id_to_string(int level)
|
|
|
|
{
|
|
|
|
return enum_to_name(levels, level);
|
|
|
|
}
|
|
|
|
|
2018-10-28 13:29:42 +01:00
|
|
|
const char *facility_id_to_string(int id)
|
|
|
|
{
|
|
|
|
return enum_to_name(facilities, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int level_id_from_string(const char *level)
|
|
|
|
{
|
|
|
|
return enum_by_name(levels, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
int facility_id_from_string(const char *fac)
|
2018-10-28 12:10:07 +01:00
|
|
|
{
|
2018-10-28 13:29:42 +01:00
|
|
|
return enum_by_name(facilities, fac);
|
2018-10-28 12:10:07 +01:00
|
|
|
}
|