syslog-ng source
transport-mapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2013 Balabit
3  * Copyright (c) 1998-2013 Balázs Scheidler
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 
24 #ifndef TRANSPORT_MAPPER_H_INCLUDED
25 #define TRANSPORT_MAPPER_H_INCLUDED
26 
27 #include "socket-options.h"
29 #include "gsockaddr.h"
30 
31 typedef struct _TransportMapper TransportMapper;
32 typedef gboolean (*TransportMapperAsyncInitCB)(gpointer arg);
33 
35 {
36  /* the transport() option as specified by the user */
37  gchar *transport;
38 
39  /* output parameters as determinted by TransportMapper */
41  /* SOCK_DGRAM or SOCK_STREAM or other SOCK_XXX values used by the socket() call */
42  gint sock_type;
43  /* protocol parameter for the socket() call, 0 for default or IPPROTO_XXX for specific transports */
44  gint sock_proto;
45 
46  const gchar *logproto;
47  /* the user visible summary of the transport, to be put into $TRANSPORT */
51 
52  gboolean (*apply_transport)(TransportMapper *self, GlobalConfig *cfg);
53  gboolean (*setup_stack)(TransportMapper *self, LogTransportStack *stack);
54  gboolean (*init)(TransportMapper *self);
55  gboolean (*async_init)(TransportMapper *self, TransportMapperAsyncInitCB func, gpointer arg);
56  void (*free_fn)(TransportMapper *self);
57 };
58 
59 void transport_mapper_set_transport(TransportMapper *self, const gchar *transport);
60 void transport_mapper_set_address_family(TransportMapper *self, gint address_family);
61 
62 gboolean transport_mapper_open_socket(TransportMapper *self,
63  SocketOptions *socket_options,
64  GSockAddr *bind_addr,
65  GSockAddr *peer_addr,
67  int *fd);
68 
69 gboolean transport_mapper_apply_transport_method(TransportMapper *self, GlobalConfig *cfg);
70 
71 void transport_mapper_init_instance(TransportMapper *self, const gchar *transport);
72 void transport_mapper_free(TransportMapper *self);
73 void transport_mapper_free_method(TransportMapper *self);
74 
75 static inline const gchar *
76 transport_mapper_get_transport(TransportMapper *self)
77 {
78  return self->transport;
79 }
80 
81 static inline const gchar *
82 transport_mapper_get_logproto(TransportMapper *self)
83 {
84  return self->logproto;
85 }
86 
87 static inline const gchar *
88 transport_mapper_get_transport_name(TransportMapper *self, gsize *len)
89 {
90  if (self->transport_name)
91  {
92  if (len)
93  *len = self->transport_name_len;
94  return self->transport_name;
95  }
96  return NULL;
97 }
98 
99 static inline gboolean
100 transport_mapper_apply_transport(TransportMapper *self, GlobalConfig *cfg)
101 {
102  gboolean result = self->apply_transport(self, cfg);
103 
104  if (result)
105  self->transport_name_len = self->transport_name ? strlen(self->transport_name) : 0;
106  return result;
107 }
108 
109 static inline gboolean
110 transport_mapper_setup_stack(TransportMapper *self, LogTransportStack *stack, gint fd)
111 {
112  stack->fd = fd;
113  return self->setup_stack(self, stack);
114 }
115 
116 static inline gboolean
117 transport_mapper_init(TransportMapper *self)
118 {
119  if (self->init)
120  return self->init(self);
121 
122  return TRUE;
123 }
124 
125 static inline gboolean
126 transport_mapper_async_init(TransportMapper *self, TransportMapperAsyncInitCB func, gpointer arg)
127 {
128  if (self->async_init)
129  {
130  return self->async_init(self, func, arg);
131  }
132 
133  return func(arg);
134 }
135 #endif
#define self
Definition: rcptid.c:38
AFSocketDirection
Definition: socket-options.h:29
Definition: gsockaddr.h:46
Definition: transport-mapper.h:35
gboolean(* async_init)(TransportMapper *self, TransportMapperAsyncInitCB func, gpointer arg)
Definition: transport-mapper.h:55
gboolean(* setup_stack)(TransportMapper *self, LogTransportStack *stack)
Definition: transport-mapper.h:53
gint address_family
Definition: transport-mapper.h:40
gchar * transport_name
Definition: transport-mapper.h:48
gchar * transport
Definition: transport-mapper.h:37
gboolean(* init)(TransportMapper *self)
Definition: transport-mapper.h:54
gsize transport_name_len
Definition: transport-mapper.h:49
gint sock_proto
Definition: transport-mapper.h:44
gint stats_source
Definition: transport-mapper.h:50
gboolean(* apply_transport)(TransportMapper *self, GlobalConfig *cfg)
Definition: transport-mapper.h:52
const gchar * logproto
Definition: transport-mapper.h:46
gint sock_type
Definition: transport-mapper.h:42
void(* free_fn)(TransportMapper *self)
Definition: transport-mapper.h:56
GlobalConfig * cfg
Definition: test_batched_ack_tracker.c:34
GString * result
Definition: test_lexer_block.c:34
gboolean transport_mapper_apply_transport_method(TransportMapper *self, GlobalConfig *cfg)
Definition: transport-mapper.c:96
void transport_mapper_set_address_family(TransportMapper *self, gint address_family)
Definition: transport-mapper.c:109
void transport_mapper_set_transport(TransportMapper *self, const gchar *transport)
Definition: transport-mapper.c:102
void transport_mapper_init_instance(TransportMapper *self, const gchar *transport)
Definition: transport-mapper.c:122
gboolean transport_mapper_open_socket(TransportMapper *self, SocketOptions *socket_options, GSockAddr *bind_addr, GSockAddr *peer_addr, AFSocketDirection dir, int *fd)
Definition: transport-mapper.c:52
void transport_mapper_free_method(TransportMapper *self)
Definition: transport-mapper.c:115
gboolean(* TransportMapperAsyncInitCB)(gpointer arg)
Definition: transport-mapper.h:32
void transport_mapper_free(TransportMapper *self)
Definition: transport-mapper.c:132