1 /*
2  * Copyright (c) 2002-2011 Balabit
3  * Copyright (c) 1998-2011 Balázs Scheidler
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 
25 #ifndef __SYSLOG_NAMES_H_INCLUDED
26 #define __SYSLOG_NAMES_H_INCLUDED
27 
28 #include "syslog-ng.h"
29 
30 #define LOG_FACMASK 0x03f8  /* mask to extract facility part */
31 /* facility of pri */
32 #define LOG_FAC(p)  (((p) & LOG_FACMASK) >> 3)
33 #ifndef LOG_PRIMASK
34 #define LOG_PRIMASK 0x07  /* mask to extract priority part (internal) */
35 #endif
36 /* extract priority */
37 #define LOG_PRI(p)  ((p) & LOG_PRIMASK)
38 
39 #define SEVERITY_CODE(n)    ((n) & 7)
40 #define FACILITY_CODE(n) ((n) << 3)
41 
42 struct sl_name
43 {
44   const char *name;
45   int value;
46 };
47 
48 extern struct sl_name sl_severities[];
49 extern struct sl_name sl_facilities[];
50 
51 /* returns an index where this name is found */
52 int syslog_name_lookup_id_by_name(const char *name, struct sl_name names[]);
53 int syslog_name_lookup_value_by_name(const char *name, struct sl_name names[]);
54 const char *syslog_name_lookup_name_by_value(int value, struct sl_name names[]);
55 
56 guint32 syslog_make_range(guint32 r1, guint32 r2);
57 
58 static inline guint32
syslog_name_lookup_severity_by_name(const gchar * name)59 syslog_name_lookup_severity_by_name(const gchar *name)
60 {
61   return syslog_name_lookup_value_by_name(name, sl_severities);
62 }
63 
64 static inline guint32
syslog_name_lookup_facility_by_name(const gchar * name)65 syslog_name_lookup_facility_by_name(const gchar *name)
66 {
67   return syslog_name_lookup_value_by_name(name, sl_facilities);
68 }
69 
70 static inline const gchar *
syslog_name_lookup_severity_by_value(int value)71 syslog_name_lookup_severity_by_value(int value)
72 {
73   return syslog_name_lookup_name_by_value(value, sl_severities);
74 }
75 
76 static inline const gchar *
syslog_name_lookup_facility_by_value(int value)77 syslog_name_lookup_facility_by_value(int value)
78 {
79   return syslog_name_lookup_name_by_value(value, sl_facilities);
80 }
81 
82 #endif
83