syslog-ng source
driver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2012 Balabit
3  * Copyright (c) 1998-2012 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 DRIVER_H_INCLUDED
26 #define DRIVER_H_INCLUDED
27 
28 #include "syslog-ng.h"
29 #include "logpipe.h"
30 #include "logqueue.h"
31 #include "cfg.h"
33 
34 /*
35  * Drivers overview
36  * ================
37  *
38  * In syslog-ng nomenclature a driver is either responsible for handling
39  * incoming messages (also known as source driver), or to send them out to
40  * another party (also known as the destination driver). Source drivers are
41  * created in "source" statements and destination drivers are similarly
42  * created in "destination" statements.
43  *
44  * Drivers are derived from LogPipes, in essence they use the same "queue"
45  * method to forward messages further down the processing pipeline.
46  *
47  * Driver plugins
48  * ==============
49  *
50  * It is possible to change the behaviour of a driver somewhat by adding
51  * "plugins" to drivers. These plugins basically get a chance to override
52  * LogDriver virtual methods, change their semantics and possibly rely on
53  * the original behaviour too. This way, functionalities that are present
54  * in all destination drivers can easily be shared, without having to recode
55  * the same stuff multiple times.
56  *
57  * Driver plugins are activated with the "attach" virtual method, which in
58  * turn may redirect any of the LogDriver virtual methods to themselves.
59  * They can even have a "user_data" pointer, so that they can locate their
60  * associated state.
61  *
62  * Multiple plugins can hook into the same method, by saving the original
63  * address & original user_data value.
64  *
65  */
66 
67 /* direction agnostic driver class: LogDriver, see specialized source & destination drivers below */
68 
69 typedef struct _LogDriver LogDriver;
70 typedef struct _LogDriverPlugin LogDriverPlugin;
71 
73 {
74  SignalSlotConnector *signal_connector;
75  const gchar *name;
76  /* this function is called when the plugin is attached to a LogDriver
77  * instance. It should do whatever it is necessary to extend the
78  * functionality of the driver specified (e.g. hook into various
79  * methods).
80  */
81 
82  gboolean (*attach)(LogDriverPlugin *s, LogDriver *d);
83  void (*detach)(LogDriverPlugin *s, LogDriver *d);
84  void (*free_fn)(LogDriverPlugin *s);
85 };
86 
87 static inline gboolean
88 log_driver_plugin_attach(LogDriverPlugin *self, LogDriver *d)
89 {
90  return self->attach(self, d);
91 }
92 
93 static inline void
94 log_driver_plugin_detach(LogDriverPlugin *self, LogDriver *d)
95 {
96  if (self->detach)
97  self->detach(self, d);
98 }
99 
100 static inline void
101 log_driver_plugin_free(LogDriverPlugin *self)
102 {
103  self->free_fn(self);
104 }
105 
106 void log_driver_plugin_init_instance(LogDriverPlugin *self, const gchar *name);
107 void log_driver_plugin_free_method(LogDriverPlugin *self);
108 
110 {
111  LogPipe super;
112 
113  gboolean optional;
114  gchar *group;
115  gchar *id;
116 
117  SignalSlotConnector *signal_slot_connector;
118 
119  GList *plugins;
120 
122 
123 };
124 
125 gboolean log_driver_add_plugin(LogDriver *self, LogDriverPlugin *plugin);
126 void log_driver_append(LogDriver *self, LogDriver *next);
127 LogDriverPlugin *log_driver_lookup_plugin(LogDriver *self, const gchar *name);
128 
129 #define log_driver_get_plugin(self, T, name) \
130  ({ \
131  T *plugin = (T *) log_driver_lookup_plugin(self, name); \
132  g_assert(plugin != NULL); \
133  plugin; \
134  })
135 
136 /* methods registered to the init/deinit virtual functions */
137 gboolean log_driver_init_method(LogPipe *s);
138 gboolean log_driver_deinit_method(LogPipe *s);
139 
140 
141 /* source driver class: LogSourceDriver */
142 
143 typedef struct _LogSrcDriver LogSrcDriver;
144 
146 {
147  LogDriver super;
148  gint group_len;
150 };
151 
152 gboolean log_src_driver_init_method(LogPipe *s);
153 gboolean log_src_driver_deinit_method(LogPipe *s);
154 void log_src_driver_queue_method(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options);
155 void log_src_driver_init_instance(LogSrcDriver *self, GlobalConfig *cfg);
156 void log_src_driver_free(LogPipe *s);
157 
158 /* destination driver class: LogDestDriver */
159 
160 typedef struct _LogDestDriver LogDestDriver;
161 
163 {
164  LogDriver super;
165 
166  LogQueue *(*acquire_queue)(LogDestDriver *s, const gchar *persist_name, gint stats_level,
167  StatsClusterKeyBuilder *driver_sck_builder,
168  StatsClusterKeyBuilder *queue_sck_builder);
169  void (*release_queue)(LogDestDriver *s, LogQueue *q);
170 
171  /* queues managed by this LogDestDriver, all constructed queues come
172  * here and are automatically saved into cfg_persist & persist_state. */
173  GList *queues;
174 
176  gint throttle;
178 };
179 
180 /* returns a reference */
181 static inline LogQueue *
182 log_dest_driver_acquire_queue(LogDestDriver *self, const gchar *persist_name, gint stats_level,
183  StatsClusterKeyBuilder *driver_sck_builder,
184  StatsClusterKeyBuilder *queue_sck_builder)
185 {
186  LogQueue *q;
187 
188  q = self->acquire_queue(self, persist_name, stats_level, driver_sck_builder, queue_sck_builder);
189  if (q)
190  {
191  self->queues = g_list_prepend(self->queues, q);
192  }
193  return q;
194 }
195 
196 /* consumes the reference in @q */
197 static inline void
198 log_dest_driver_release_queue(LogDestDriver *self, LogQueue *q)
199 {
200  if (q)
201  {
202  self->queues = g_list_remove(self->queues, q);
203 
204  /* this drops the reference passed by the caller */
205  self->release_queue(self, q);
206  /* this drops the reference stored on the list */
207  log_queue_unref(q);
208  }
209 }
210 
211 gboolean log_dest_driver_init_method(LogPipe *s);
212 gboolean log_dest_driver_deinit_method(LogPipe *s);
213 void log_dest_driver_queue_method(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options);
214 
215 void log_dest_driver_init_instance(LogDestDriver *self, GlobalConfig *cfg);
216 void log_dest_driver_free(LogPipe *s);
217 
218 
219 #endif
const gchar * name
Definition: debugger.c:265
LogDriverPlugin * log_driver_lookup_plugin(LogDriver *self, const gchar *name)
Definition: driver.c:68
gboolean log_src_driver_init_method(LogPipe *s)
Definition: driver.c:192
gboolean log_driver_deinit_method(LogPipe *s)
Definition: driver.c:114
void log_dest_driver_init_instance(LogDestDriver *self, GlobalConfig *cfg)
Definition: driver.c:426
gboolean log_driver_init_method(LogPipe *s)
Definition: driver.c:108
void log_driver_append(LogDriver *self, LogDriver *next)
void log_driver_plugin_free_method(LogDriverPlugin *self)
Definition: driver.c:36
void log_driver_plugin_init_instance(LogDriverPlugin *self, const gchar *name)
Definition: driver.c:42
void log_src_driver_free(LogPipe *s)
Definition: driver.c:259
void log_src_driver_init_instance(LogSrcDriver *self, GlobalConfig *cfg)
Definition: driver.c:248
gboolean log_src_driver_deinit_method(LogPipe *s)
Definition: driver.c:218
void log_src_driver_queue_method(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options)
Definition: driver.c:231
void log_dest_driver_free(LogPipe *s)
Definition: driver.c:440
gboolean log_driver_add_plugin(LogDriver *self, LogDriverPlugin *plugin)
Definition: driver.c:52
gboolean log_dest_driver_deinit_method(LogPipe *s)
Definition: driver.c:412
gboolean log_dest_driver_init_method(LogPipe *s)
Definition: driver.c:366
void log_dest_driver_queue_method(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options)
Definition: driver.c:327
#define self
Definition: rcptid.c:38
Definition: stats-counter.h:67
Definition: driver.h:163
gint log_fifo_size
Definition: driver.h:175
gint throttle
Definition: driver.h:176
GList * queues
Definition: driver.h:173
LogDriver super
Definition: driver.h:164
StatsCounterItem * queued_global_messages
Definition: driver.h:177
void(* release_queue)(LogDestDriver *s, LogQueue *q)
Definition: driver.h:169
Definition: driver.h:73
gboolean(* attach)(LogDriverPlugin *s, LogDriver *d)
Definition: driver.h:82
SignalSlotConnector * signal_connector
Definition: driver.h:74
void(* detach)(LogDriverPlugin *s, LogDriver *d)
Definition: driver.h:83
void(* free_fn)(LogDriverPlugin *s)
Definition: driver.h:84
const gchar * name
Definition: driver.h:75
Definition: driver.h:110
LogPipe super
Definition: driver.h:111
GList * plugins
Definition: driver.h:119
gchar * id
Definition: driver.h:115
SignalSlotConnector * signal_slot_connector
Definition: driver.h:117
gchar * group
Definition: driver.h:114
StatsCounterItem * processed_group_messages
Definition: driver.h:121
gboolean optional
Definition: driver.h:113
Definition: driver.h:146
StatsCounterItem * received_global_messages
Definition: driver.h:149
gint group_len
Definition: driver.h:148
LogDriver super
Definition: driver.h:147
GlobalConfig * cfg
Definition: test_batched_ack_tracker.c:34
LogMessage * msg
Definition: test_rename.c:35
LogPathOptions path_options
Definition: test_wildcard_file_reader.c:62