Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / ep / ep_syslog.c @ master

History | View | Annotate | Download (3.76 KB)

1
/* vim: set ai sw=8 sts=8 ts=8 : */
2

    
3
/***********************************************************************
4
**  ----- BEGIN LICENSE BLOCK -----
5
**        LIBEP: Enhanced Portability Library (Reduced Edition)
6
**
7
**        Copyright (c) 2008-2019, Eric P. Allman.  All rights reserved.
8
**        Copyright (c) 2015-2019, Regents of the University of California.
9
**        All rights reserved.
10
**
11
**        Permission is hereby granted, without written agreement and without
12
**        license or royalty fees, to use, copy, modify, and distribute this
13
**        software and its documentation for any purpose, provided that the above
14
**        copyright notice and the following two paragraphs appear in all copies
15
**        of this software.
16
**
17
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
18
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
19
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
20
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
**
22
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
23
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
25
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
26
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27
**        OR MODIFICATIONS.
28
**  ----- END LICENSE BLOCK -----
29
***********************************************************************/
30

    
31
#include <ep.h>
32
#include <ep_syslog.h>
33

    
34
#include <strings.h>
35

    
36
struct code
37
{
38
        const char        *c_name;
39
        const int        c_val;
40
};
41

    
42
static struct code        PriNames[] =
43
{
44
        { "alert",        LOG_ALERT        },
45
        { "crit",        LOG_CRIT        },
46
        { "debug",        LOG_DEBUG        },
47
        { "emerg",        LOG_EMERG        },
48
        { "err",        LOG_ERR                },
49
        { "error",        LOG_ERR                },                /* DEPRECATED */
50
        { "info",        LOG_INFO        },
51
        { "notice",        LOG_NOTICE        },
52
        { "panic",        LOG_EMERG        },                /* DEPRECATED */
53
        { "warn",        LOG_WARNING        },                /* DEPRECATED */
54
        { "warning",        LOG_WARNING        },
55
        { NULL,                -1                }
56
};
57

    
58
struct code     FacNames[] =
59
{
60
        { "auth",        LOG_AUTH        },
61
#ifdef LOG_AUTHPRIV
62
        { "authpriv",        LOG_AUTHPRIV        },
63
#endif
64
#ifdef LOG_CONSOLE
65
        { "console",        LOG_CONSOLE        },
66
#endif
67
        { "cron",        LOG_CRON        },
68
        { "daemon",        LOG_DAEMON        },
69
#ifdef LOG_FTP
70
        { "ftp",        LOG_FTP                },
71
#endif
72
#ifdef LOG_INSTALL
73
        { "install",        LOG_INSTALL        },                // MacOS
74
#endif
75
        { "kern",        LOG_KERN        },
76
#ifdef LOG_LAUNCHD
77
        { "launchd",        LOG_LAUNCHD        },                // MacOS
78
#endif
79
        { "lpr",        LOG_LPR                },
80
        { "mail",        LOG_MAIL        },
81
#ifdef LOG_NETINFO
82
        { "netinfo",        LOG_NETINFO        },                // MacOS
83
#endif
84
        { "news",        LOG_NEWS        },
85
#ifdef LOG_NTP
86
        { "ntp",        LOG_NTP                },
87
#endif
88
#ifdef LOG_RAS
89
        { "ras",        LOG_RAS                },                // MacOS
90
#endif
91
#ifdef LOG_REMOTEAUTH
92
        { "remoteauth",        LOG_REMOTEAUTH        },                // MacOS
93
#endif
94
        { "security",        LOG_AUTH        },                /* DEPRECATED */
95
        { "syslog",        LOG_SYSLOG        },
96
        { "user",        LOG_USER        },
97
        { "uucp",        LOG_UUCP        },
98
        { "local0",        LOG_LOCAL0        },
99
        { "local1",        LOG_LOCAL1        },
100
        { "local2",        LOG_LOCAL2        },
101
        { "local3",        LOG_LOCAL3        },
102
        { "local4",        LOG_LOCAL4        },
103
        { "local5",        LOG_LOCAL5        },
104
        { "local6",        LOG_LOCAL6        },
105
        { "local7",        LOG_LOCAL7        },
106
        { NULL,                -1                }
107
};
108

    
109

    
110
/*
111
**  EP_SYSLOG_PRI_FROM_NAME --- translate string name to log priority
112
*/
113

    
114
int
115
ep_syslog_pri_from_name(const char *name)
116
{
117
        struct code *c;
118

    
119
        for (c = PriNames; c->c_name != NULL; c++)
120
        {
121
                if (strcasecmp(c->c_name, name) == 0)
122
                        return c->c_val;
123
        }
124
        return -1;
125
}
126

    
127

    
128

    
129
const char *
130
ep_syslog_name_from_pri(int pri)
131
{
132
        struct code *c;
133

    
134
        for (c = PriNames; c->c_name != NULL; c++)
135
        {
136
                if (c->c_val == pri)
137
                        return c->c_name;
138
        }
139
        return "unknown";
140
}
141

    
142

    
143

    
144
int
145
ep_syslog_fac_from_name(const char *name)
146
{
147
        struct code *c;
148

    
149
        for (c = FacNames; c->c_name != NULL; c++)
150
        {
151
                if (strcasecmp(c->c_name, name) == 0)
152
                        return c->c_val;
153
        }
154
        return -1;
155
}
156

    
157

    
158

    
159
const char *
160
ep_syslog_name_from_fac(int fac)
161
{
162
        struct code *c;
163

    
164
        for (c = FacNames; c->c_name != NULL; c++)
165
        {
166
                if (c->c_val == fac)
167
                        return c->c_name;
168
        }
169
        return "unknown";
170
}