syslog-ng source
evtlog.h
Go to the documentation of this file.
1 /*
2  * Event Logging API
3  * Copyright (c) 2003 BalaBit IT Ltd.
4  * All rights reserved.
5  * Author: Balazs Scheidler
6  *
7  * EventLog library public functions.
8  *
9  * $Id: evtlog.h,v 1.5 2004/08/20 19:53:52 bazsi Exp $
10  *
11  * Some of the ideas are based on the discussions on the log-analysis
12  * mailing list (http://www.loganalysis.org/).
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  * 3. Neither the name of BalaBit nor the names of its contributors
23  * may be used to endorse or promote products derived from this software
24  * without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY BALABIT AND CONTRIBUTORS `AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  */
39 
40 #ifndef __EVTLOG_H_INCLUDED
41 #define __EVTLOG_H_INCLUDED
42 
43 #ifndef _MSC_VER
44 # include <syslog.h>
45 #endif
46 #include <stdarg.h>
47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
51 #include <glib.h>
52 
53 #include "evtmaps.h"
54 
55 #define EVT_PRI_EMERG 0 /* system is unusable */
56 #define EVT_PRI_ALERT 1 /* action must be taken immediately */
57 #define EVT_PRI_CRIT 2 /* critical conditions */
58 #define EVT_PRI_ERR 3 /* error conditions */
59 #define EVT_PRI_WARNING 4 /* warning conditions */
60 #define EVT_PRI_NOTICE 5 /* normal but significant condition */
61 #define EVT_PRI_INFO 6 /* informational */
62 #define EVT_PRI_DEBUG 7 /* debug-level messages */
63 
64 #define EVT_FAC_KERN (0<<3) /* kernel messages */
65 #define EVT_FAC_USER (1<<3) /* random user-level messages */
66 #define EVT_FAC_MAIL (2<<3) /* mail system */
67 #define EVT_FAC_DAEMON (3<<3) /* system daemons */
68 #define EVT_FAC_AUTH (4<<3) /* security/authorization messages */
69 #define EVT_FAC_SYSLOG (5<<3) /* messages generated internally by syslogd */
70 #define EVT_FAC_LPR (6<<3) /* line printer subsystem */
71 #define EVT_FAC_NEWS (7<<3) /* network news subsystem */
72 #define EVT_FAC_UUCP (8<<3) /* UUCP subsystem */
73 #define EVT_FAC_CRON (9<<3) /* clock daemon */
74 #define EVT_FAC_AUTHPRIV (10<<3) /* security/authorization messages (private) */
75 #define EVT_FAC_FTP (11<<3) /* ftp daemon */
76 
77 /* other codes through 15 reserved for system use */
78 #define EVT_FAC_LOCAL0 (16<<3) /* reserved for local use */
79 #define EVT_FAC_LOCAL1 (17<<3) /* reserved for local use */
80 #define EVT_FAC_LOCAL2 (18<<3) /* reserved for local use */
81 #define EVT_FAC_LOCAL3 (19<<3) /* reserved for local use */
82 #define EVT_FAC_LOCAL4 (20<<3) /* reserved for local use */
83 #define EVT_FAC_LOCAL5 (21<<3) /* reserved for local use */
84 #define EVT_FAC_LOCAL6 (22<<3) /* reserved for local use */
85 #define EVT_FAC_LOCAL7 (23<<3) /* reserved for local use */
86 
87 /* EVTCONTEXT encapsulates logging specific parameters like the
88  * program name and facility to use */
89 typedef struct __evtcontext EVTCONTEXT;
90 
91 /* EVTREC is an event log record, contains a description and one or more
92  * name/value pairs */
93 typedef struct __evtrec EVTREC;
94 
95 /* EVTTAG is a name value pair, comprising an event record */
96 typedef struct __evttag EVTTAG;
97 
98 /* eventlog contexts */
99 
109 EVTCONTEXT *evt_ctx_init(const char *prog, int syslog_fac);
110 
117 void evt_ctx_free(EVTCONTEXT *ctx);
118 
122 int evt_ctx_tag_hook_add(EVTCONTEXT *ctx, int (*func)(EVTREC *e, void *user_ptr), void *user_ptr);
123 
124 /* event record manipulation */
125 EVTREC *evt_rec_init(EVTCONTEXT *ctx, int syslog_pri, const char *desc);
126 void evt_rec_add_tag(EVTREC *e, EVTTAG *tag);
127 void evt_rec_add_tagsv(EVTREC *e, va_list tags);
128 void evt_rec_add_tags(EVTREC *e, EVTTAG *first, ...);
129 int evt_rec_get_syslog_pri(EVTREC *e);
130 void evt_rec_free(EVTREC *e);
131 
132 
142 EVTTAG *evt_tag_str(const char *tag, const char *value);
143 EVTTAG *evt_tag_mem(const char *tag, const void *value, size_t len);
144 EVTTAG *evt_tag_int(const char *tag, int value);
145 EVTTAG *evt_tag_long(const char *tag, long long value);
146 EVTTAG *evt_tag_errno(const char *tag, int err);
147 EVTTAG *evt_tag_printf(const char *tag, const char *format, ...) G_GNUC_PRINTF(2, 3);
148 EVTTAG *evt_tag_inaddr(const char *tag, const struct in_addr *addr);
149 EVTTAG *evt_tag_inaddr6(const char *tag, const struct in6_addr *addr);
150 
160 char *evt_format(EVTREC *e);
161 
174 int evt_log(EVTREC *e);
175 
176 /* syslog wrapper */
177 void evt_openlog(const char *ident, int option, int facility);
178 void evt_closelog(void);
179 void evt_vsyslog(int pri, const char *format, va_list ap) G_GNUC_PRINTF(2, 0);
180 void evt_syslog(int pri, const char *format, ...) G_GNUC_PRINTF(2, 3);
181 
182 #ifdef EVENTLOG_SYSLOG_MACROS
183 
184 #define openlog evt_openlog
185 #define syslog evt_syslog
186 #define vsyslog evt_vsyslog
187 #define closelog evt_closelog
188 
189 #endif
190 
191 #endif
void evt_rec_free(EVTREC *e)
Definition: evtrec.c:133
void evt_vsyslog(int pri, const char *format, va_list ap) G_GNUC_PRINTF(2
EVTTAG EVTTAG * evt_tag_inaddr(const char *tag, const struct in_addr *addr)
Definition: evttags.c:141
EVTTAG * evt_tag_inaddr6(const char *tag, const struct in6_addr *addr)
Definition: evttags.c:154
void void evt_syslog(int pri, const char *format,...) G_GNUC_PRINTF(2
EVTCONTEXT * evt_ctx_init(const char *prog, int syslog_fac)
Definition: evtctx.c:107
EVTTAG * evt_tag_mem(const char *tag, const void *value, size_t len)
Definition: evttags.c:84
void evt_rec_add_tag(EVTREC *e, EVTTAG *tag)
Definition: evtrec.c:45
int evt_ctx_tag_hook_add(EVTCONTEXT *ctx, int(*func)(EVTREC *e, void *user_ptr), void *user_ptr)
Definition: evtctx.c:93
char * evt_format(EVTREC *e)
Definition: evtfmt.c:89
int evt_log(EVTREC *e)
Definition: evtout.c:84
int evt_rec_get_syslog_pri(EVTREC *e)
Definition: evtrec.c:83
EVTTAG * evt_tag_int(const char *tag, int value)
Definition: evttags.c:102
void evt_rec_add_tags(EVTREC *e, EVTTAG *first,...)
Definition: evtrec.c:72
EVTTAG * evt_tag_long(const char *tag, long long value)
Definition: evttags.c:111
void evt_ctx_free(EVTCONTEXT *ctx)
Definition: evtctx.c:138
void evt_rec_add_tagsv(EVTREC *e, va_list tags)
Definition: evtrec.c:59
EVTREC * evt_rec_init(EVTCONTEXT *ctx, int syslog_pri, const char *desc)
Definition: evtrec.c:103
void evt_closelog(void)
Definition: evtsyslog.c:59
EVTTAG * evt_tag_str(const char *tag, const char *value)
Definition: evttags.c:65
void evt_openlog(const char *ident, int option, int facility)
Definition: evtsyslog.c:48
EVTTAG * evt_tag_errno(const char *tag, int err)
Definition: evttags.c:120
EVTTAG * evt_tag_printf(const char *tag, const char *format,...) G_GNUC_PRINTF(2
Definition: evt_internals.h:77
Definition: evt_internals.h:97
Definition: evt_internals.h:107
GString * value
Definition: test_decode.c:28