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 #include "instant_ack_tracker.h"
26 #include "bookmark.h"
27 #include "syslog-ng.h"
28
29 typedef struct _InstantAckRecord
30 {
31 AckRecord super;
32 void *padding;
33 /* bookmark contains a binary container which has to be aligned */
34 } InstantAckRecord;
35
36 typedef struct _InstantAckTrackerBookmarkless
37 {
38 AckTracker super;
39
40 InstantAckRecord ack_record_storage;
41 } InstantAckTrackerBookmarkless;
42
43 static Bookmark *
_request_bookmark(AckTracker * s)44 _request_bookmark(AckTracker *s)
45 {
46 InstantAckTrackerBookmarkless *self = (InstantAckTrackerBookmarkless *)s;
47 return &(self->ack_record_storage.super.bookmark);
48 }
49
50 static void
_track_msg(AckTracker * s,LogMessage * msg)51 _track_msg(AckTracker *s, LogMessage *msg)
52 {
53 InstantAckTrackerBookmarkless *self = (InstantAckTrackerBookmarkless *)s;
54 log_pipe_ref((LogPipe *)self->super.source);
55 msg->ack_record = (AckRecord *)(&self->ack_record_storage);
56 }
57
58 static void
_manage_msg_ack(AckTracker * s,LogMessage * msg,AckType ack_type)59 _manage_msg_ack(AckTracker *s, LogMessage *msg, AckType ack_type)
60 {
61 InstantAckTrackerBookmarkless *self = (InstantAckTrackerBookmarkless *)s;
62
63 log_source_flow_control_adjust(self->super.source, 1);
64
65 if (ack_type == AT_SUSPENDED)
66 log_source_flow_control_suspend(self->super.source);
67
68 log_msg_unref(msg);
69 log_pipe_unref((LogPipe *)self->super.source);
70 }
71
72 static void
_free(AckTracker * s)73 _free(AckTracker *s)
74 {
75 InstantAckTrackerBookmarkless *self = (InstantAckTrackerBookmarkless *)s;
76
77 g_free(self);
78 }
79
80 static void
_setup_callbacks(InstantAckTrackerBookmarkless * self)81 _setup_callbacks(InstantAckTrackerBookmarkless *self)
82 {
83 self->super.request_bookmark = _request_bookmark;
84 self->super.track_msg = _track_msg;
85 self->super.manage_msg_ack = _manage_msg_ack;
86 self->super.free_fn = _free;
87 }
88
89 static void
_init_instance(InstantAckTrackerBookmarkless * self,LogSource * source)90 _init_instance(InstantAckTrackerBookmarkless *self, LogSource *source)
91 {
92 self->super.source = source;
93 source->ack_tracker = (AckTracker *)self;
94 self->ack_record_storage.super.tracker = (AckTracker *)self;
95 _setup_callbacks(self);
96 }
97
98 AckTracker *
instant_ack_tracker_bookmarkless_new(LogSource * source)99 instant_ack_tracker_bookmarkless_new(LogSource *source)
100 {
101 InstantAckTrackerBookmarkless *self = (InstantAckTrackerBookmarkless *)g_new0(InstantAckTrackerBookmarkless, 1);
102
103 _init_instance(self, source);
104
105 return (AckTracker *)self;
106 }
107