1 /*
2  * Copyright (c) 2002-2014 Balabit
3  * Copyright (c) 2014 Laszlo Budai
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 ACK_TRACKER_H_INCLUDED
26 #define ACK_TRACKER_H_INCLUDED
27 
28 #include "syslog-ng.h"
29 #include "logsource.h"
30 #include "ack_tracker_types.h"
31 #include "bookmark.h"
32 
33 struct _AckTracker
34 {
35   LogSource *source;
36   Bookmark *(*request_bookmark)(AckTracker *self);
37   void (*track_msg)(AckTracker *self, LogMessage *msg);
38   void (*manage_msg_ack)(AckTracker *self, LogMessage *msg, AckType ack_type);
39   void (*free_fn)(AckTracker *self);
40   void (*disable_bookmark_saving)(AckTracker *self);
41   gboolean (*init)(AckTracker *self);
42   void (*deinit)(AckTracker *self);
43 };
44 
45 struct _AckRecord
46 {
47   AckTracker *tracker;
48   Bookmark bookmark;
49 };
50 
51 static inline void
ack_tracker_free(AckTracker * self)52 ack_tracker_free(AckTracker *self)
53 {
54   if (self && self->free_fn)
55     {
56       self->free_fn(self);
57     }
58 }
59 
60 static inline Bookmark *
ack_tracker_request_bookmark(AckTracker * self)61 ack_tracker_request_bookmark(AckTracker *self)
62 {
63   return self->request_bookmark(self);
64 }
65 
66 static inline void
ack_tracker_track_msg(AckTracker * self,LogMessage * msg)67 ack_tracker_track_msg(AckTracker *self, LogMessage *msg)
68 {
69   self->track_msg(self, msg);
70 }
71 
72 static inline void
ack_tracker_manage_msg_ack(AckTracker * self,LogMessage * msg,AckType ack_type)73 ack_tracker_manage_msg_ack(AckTracker *self, LogMessage *msg, AckType ack_type)
74 {
75   self->manage_msg_ack(self, msg, ack_type);
76 }
77 
78 static inline void
ack_tracker_disable_bookmark_saving(AckTracker * self)79 ack_tracker_disable_bookmark_saving(AckTracker *self)
80 {
81   if (self->disable_bookmark_saving)
82     {
83       self->disable_bookmark_saving(self);
84     }
85 }
86 
87 static inline gboolean
ack_tracker_init(AckTracker * self)88 ack_tracker_init(AckTracker *self)
89 {
90   if (self && self->init)
91     return self->init(self);
92 
93   return TRUE;
94 }
95 
96 static inline void
ack_tracker_deinit(AckTracker * self)97 ack_tracker_deinit(AckTracker *self)
98 {
99   if (self && self->deinit)
100     self->deinit(self);
101 }
102 
103 #endif
104