summaryrefslogtreecommitdiffstats
path: root/dispatcher/elapi_dispatcher.h
blob: c7a582ec27247811d9a7647b3a1c9669e098ada7 (plain)
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
/*
    ELAPI

    Header file for the dispatcher interface.

    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/>.
*/

#ifndef ELAPI_DISPATCHER_H
#define ELAPI_DISPATCHER_H

#include "elapi_collection.h"
#include "elapi_sink.h"

/* Status values returned by the routing function */
#define ELAPI_DISPATCHER_SKIP   0
#define ELAPI_DISPATCHER_DONE   1
#define ELAPI_DISPATCHER_NEXT   2
#define ELAPI_DISPATCHER_ERROR  3


/* Actions that can be taken against a sink */
#define ELAPI_SINK_ACTION_ADD       0   /* Add a new sink */
#define ELAPI_SINK_ACTION_DELETE    1   /* Delete a sink */
#define ELAPI_SINK_ACTION_DISABLE   2   /* Disable a sink */
#define ELAPI_SINK_ACTION_PULSE     3   /* Disable a sink temporarily for one call */
#define ELAPI_SINK_ACTION_ENABLE    4   /* Enable sink */


/* Event routing function */
typedef int (*event_router_fn)(char *sink, 
                                char *previous_sink, 
                                int previous_status, 
                                struct collection_item *event,
                                struct sink_descriptor *sink_data,
                                void *custom_data, 
                                int *error); 

struct dispatcher_handle {
    char **sinks;
    char *appname;
    event_router_fn router;
    struct collection_item *sink_list;
    int sink_counter;
    void *custom_data;
};

/* Function to create a dispatcher */
int create_audit_dispatcher(struct dispatcher_handle **dispatcher, /* Handle of the dispatcher will be stored in this variable */
                            const char *appname,                   /* Application name. Passed to the sinks to do initialization */
                            char **desired_sinks,                  /* List of names of the sinks to use. If NULL the default will be used */ 
                            event_router_fn desired_router,        /* The rounting function. If NULL the default will be used */ 
                            void *custom_data);                    /* Custom data that can be used in the router function. */


/* Function to clean memory associated with the audit dispatcher */
void destroy_audit_dispatcher(struct dispatcher_handle *dispatcher);

/* Function to log an event */
void log_audit_event(struct dispatcher_handle *dispatcher, struct collection_item *event);

/* Advanced functions */
/* Managing the sink collection */
int alter_audit_dispatcher(struct dispatcher_handle *dispatcher, /* Dispatcher */
                           char *sink,                           /* Sink to change */
                           int action);                          /* Action to perform for sink */

/* This function is exposed in case you are providing your own routing callback */   
int log_event_to_sink(struct sink_descriptor *sink_data,
                      struct collection_item *event,
                      void *custom_data);


#endif