syslog-ng source
transport-aux-data.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 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 #ifndef TRANSPORT_TRANSPORT_AUX_DATA_H_INCLUDED
24 #define TRANSPORT_TRANSPORT_AUX_DATA_H_INCLUDED
25 
26 #include "gsockaddr.h"
27 #include <string.h>
28 
29 typedef struct _LogTransportAuxData
30 {
33  struct timespec timestamp;
34  gint proto;
35  gchar data[1536];
36  gsize end_ptr;
38 
39 static inline void
40 log_transport_aux_data_init(LogTransportAuxData *self)
41 {
42  if (self)
43  {
44  self->peer_addr = NULL;
45  self->local_addr = NULL;
46  self->end_ptr = 0;
47  self->data[0] = 0;
48  self->timestamp.tv_sec = 0;
49  self->timestamp.tv_nsec = 0;
50  self->proto = 0;
51  }
52 }
53 
54 static inline void
55 log_transport_aux_data_destroy(LogTransportAuxData *self)
56 {
57  if (self)
58  {
59  g_sockaddr_unref(self->peer_addr);
60  g_sockaddr_unref(self->local_addr);
61  }
62 }
63 
64 static inline void
65 log_transport_aux_data_reinit(LogTransportAuxData *self)
66 {
67  log_transport_aux_data_destroy(self);
68  log_transport_aux_data_init(self);
69 }
70 
71 static inline void
72 log_transport_aux_data_copy(LogTransportAuxData *dst, LogTransportAuxData *src)
73 {
74  gsize data_to_copy = sizeof(*src) - sizeof(src->data) + src->end_ptr;
75 
76  if (dst)
77  {
78  memcpy(dst, src, data_to_copy);
81  }
82 }
83 
84 static inline void
85 log_transport_aux_data_move(LogTransportAuxData *dst, LogTransportAuxData *src)
86 {
87  gsize data_to_copy = sizeof(*src) - sizeof(src->data) + src->end_ptr;
88 
89  if (dst)
90  memcpy(dst, src, data_to_copy);
91  log_transport_aux_data_init(src);
92 }
93 
94 static inline void
95 log_transport_aux_data_set_peer_addr_ref(LogTransportAuxData *self, GSockAddr *peer_addr)
96 {
97  if (self)
98  {
99  if (self->peer_addr)
100  g_sockaddr_unref(self->peer_addr);
101  self->peer_addr = peer_addr;
102  }
103 }
104 
105 static inline void
106 log_transport_aux_data_set_local_addr_ref(LogTransportAuxData *self, GSockAddr *local_addr)
107 {
108  if (self)
109  {
110  if (self->local_addr)
111  g_sockaddr_unref(self->local_addr);
112  self->local_addr = local_addr;
113  }
114 }
115 
116 static inline void
117 log_transport_aux_data_set_timestamp(LogTransportAuxData *self, const struct timespec *timestamp)
118 {
119  if (self)
120  self->timestamp = *timestamp;
121 }
122 
123 void log_transport_aux_data_add_nv_pair(LogTransportAuxData *self, const gchar *name, const gchar *value);
124 void log_transport_aux_data_foreach(LogTransportAuxData *self, void (*func)(const gchar *, const gchar *, gsize,
125  gpointer), gpointer user_data);
126 
127 #endif
const gchar * name
Definition: debugger.c:265
GSockAddr * g_sockaddr_ref(GSockAddr *a)
Definition: gsockaddr.c:168
void g_sockaddr_unref(GSockAddr *a)
Definition: gsockaddr.c:188
#define self
Definition: rcptid.c:38
Definition: gsockaddr.h:46
Definition: transport-aux-data.h:30
GSockAddr * local_addr
Definition: transport-aux-data.h:32
GSockAddr * peer_addr
Definition: transport-aux-data.h:31
gsize end_ptr
Definition: transport-aux-data.h:36
gchar data[1536]
Definition: transport-aux-data.h:35
gint proto
Definition: transport-aux-data.h:34
GString * value
Definition: test_decode.c:28
void log_transport_aux_data_foreach(LogTransportAuxData *self, void(*func)(const gchar *, const gchar *, gsize, gpointer), gpointer user_data)
Definition: transport-aux-data.c:60
void log_transport_aux_data_add_nv_pair(LogTransportAuxData *self, const gchar *name, const gchar *value)
Definition: transport-aux-data.c:29