1 /* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17
18 #ifndef AUDIT_HANDLER_INCLUDED
19 #define AUDIT_HANDLER_INCLUDED
20
21 #include <my_global.h>
22
23 #include "logger.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 typedef struct audit_handler_struct audit_handler_t;
30 typedef struct audit_handler_file_config_struct audit_handler_file_config_t;
31 typedef struct audit_handler_syslog_config_struct audit_handler_syslog_config_t;
32 typedef struct audit_handler_buffered_struct audit_handler_buffered_t;
33 typedef void * audit_handler_data_t;
34
35
36 typedef enum { OPT_ROTATE_ON_SIZE, OPT_ROTATIONS } audit_handler_option_t;
37
38 struct audit_handler_struct
39 {
40 int (*write)(audit_handler_t *, const char *, size_t);
41 int (*flush)(audit_handler_t *);
42 int (*close)(audit_handler_t *);
43 void (*set_option)(audit_handler_t *, audit_handler_option_t, void *);
44 audit_handler_data_t data;
45 };
46
47 struct audit_handler_file_config_struct
48 {
49 const char *name;
50 size_t rotate_on_size;
51 size_t rotations;
52 my_bool sync_on_write;
53 my_bool use_buffer;
54 size_t buffer_size;
55 my_bool can_drop_data;
56 logger_prolog_func_t header;
57 logger_epilog_func_t footer;
58 };
59
60 struct audit_handler_syslog_config_struct
61 {
62 const char *ident;
63 int facility;
64 int priority;
65 logger_prolog_func_t header;
66 logger_epilog_func_t footer;
67 };
68
69 static inline
audit_handler_write(audit_handler_t * handler,const char * buf,size_t len)70 int audit_handler_write(audit_handler_t *handler, const char *buf, size_t len)
71 {
72 if (handler != NULL && handler->write != NULL)
73 {
74 return handler->write(handler, buf, len);
75 }
76 return len;
77 }
78
79 static inline
audit_handler_flush(audit_handler_t * handler)80 int audit_handler_flush(audit_handler_t *handler)
81 {
82 if (handler != NULL && handler->flush != NULL)
83 {
84 return handler->flush(handler);
85 }
86 return 0;
87 }
88
89 static inline
audit_handler_close(audit_handler_t * handler)90 int audit_handler_close(audit_handler_t *handler)
91 {
92 if (handler != NULL && handler->close != NULL)
93 {
94 return handler->close(handler);
95 }
96 return 0;
97 }
98
99 static inline
audit_handler_set_option(audit_handler_t * handler,audit_handler_option_t opt,void * val)100 void audit_handler_set_option(audit_handler_t *handler,
101 audit_handler_option_t opt, void *val)
102 {
103 if (handler != NULL && handler->set_option != NULL)
104 {
105 handler->set_option(handler, opt, val);
106 }
107 }
108
109 audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts);
110 audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif
117