1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*
ELAPI
Module implements high level API for logging events
Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <dlfcn.h>
#include "elapi_debug.h"
#include "elapi_dispatcher.h"
#include "elapi_collection.h"
#include "elapi_sink.h"
const char event_name[] = "event";
/* Pointer to default global dispatcher */
struct dispatcher_handle *global_dispatcher = (struct dispatcher_handle *)(NULL);
/* Function to open audit using default routing functions */
/* If appname is NULL - uses module name */
int open_audit(const char *appname, char **desired_sinks)
{
int error;
DEBUG_STRING("open_audit","Entry");
error = create_audit_dispatcher(&global_dispatcher,appname,desired_sinks,NULL,NULL);
DEBUG_NUMBER("open_audit Exit:",error);
return error;
}
/* Function to open audit using custom routing function */
int open_audit_with_router(const char *appname,
char **desired_sinks,
event_router_fn desired_router,
void *custom_data)
{
int error;
DEBUG_STRING("open_audit_with_router","Entry");
error = create_audit_dispatcher(&global_dispatcher,appname,desired_sinks,desired_router,custom_data);
DEBUG_NUMBER("open_audit_with_router Exit:",error);
return error;
}
/* Get dispatcher if you want to add sink to a default deispatcher or do some advaced operations */
struct dispatcher_handle *get_dispatcher(void)
{
DEBUG_STRING("get_dispatcher was called.","Returning default dispatcher.");
return global_dispatcher;
}
/* Close audit */
void close_audit(void)
{
DEBUG_STRING("close_audit","Entry");
destroy_audit_dispatcher(global_dispatcher);
DEBUG_STRING("close_audit","Exit");
}
/* Creates collection with the timestamp already prepopulated */
int create_event(struct collection_item **event,char *name)
{
int error;
char *nm;
DEBUG_STRING("create_event","Entry");
if(name == NULL) nm = event_name;
else nm = name;
/* Construct collection and add timestamp */
if(((error = create_collection(event,nm)) != 0) ||
((error = set_timestamp(*event,NULL,NULL)) !=0 )) {
DEBUG_NUMBER("Failed to create event:",error);
return error;
}
DEBUG_STRING("create_event Exit:","");
return EOK;
}
/* Log event */
void log_event(char *format_string,struct collection_item *event)
{
DEBUG_STRING("log_event","Entry");
log_audit_event(global_dispatcher, event, format_string);
DEBUG_STRING("log_event","Entry");
}
|