syslog-ng source
correlation-context.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2013, 2015 Balabit
3  * Copyright (c) 1998-2013, 2015 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 #ifndef CORRELATION_CORRELATION_CONTEXT_H_INCLUDED
24 #define CORRELATION_CORRELATION_CONTEXT_H_INCLUDED
25 
26 #include "syslog-ng.h"
27 #include "correlation-key.h"
28 #include "timerwheel.h"
29 #include "logmsg/logmsg.h"
30 #include "template/templates.h"
31 
32 /* This class encapsulates a correlation context, keyed by CorrelationKey, type == PSK_RULE. */
33 typedef struct _CorrelationContext CorrelationContext;
35 {
36  /* key in the hashtable. */
38  /* timeout timer */
39  TWEntry *timer;
40  /* messages belonging to this context */
41  GPtrArray *messages;
42  gint ref_cnt;
43  void (*clear)(CorrelationContext *s);
44  void (*free_fn)(CorrelationContext *s);
45 };
46 
47 static inline LogMessage *
48 correlation_context_get_last_message(CorrelationContext *self)
49 {
50  g_assert(self->messages->len > 0);
51  return (LogMessage *) g_ptr_array_index(self->messages, self->messages->len - 1);
52 }
53 
54 static inline void
55 correlation_context_clear(CorrelationContext *self)
56 {
57  self->clear(self);
58 }
59 
60 void correlation_context_init(CorrelationContext *self, const CorrelationKey *key);
61 void correlation_context_clear_method(CorrelationContext *self);
62 void correlation_context_free_method(CorrelationContext *self);
63 void correlation_context_sort(CorrelationContext *self, LogTemplate *sort_key);
64 CorrelationContext *correlation_context_new(CorrelationKey *key);
65 CorrelationContext *correlation_context_ref(CorrelationContext *self);
66 void correlation_context_unref(CorrelationContext *self);
67 
68 
69 #endif
void correlation_context_init(CorrelationContext *self, const CorrelationKey *key)
Definition: correlation-context.c:81
void correlation_context_unref(CorrelationContext *self)
Definition: correlation-context.c:140
void correlation_context_sort(CorrelationContext *self, LogTemplate *sort_key)
Definition: correlation-context.c:72
void correlation_context_free_method(CorrelationContext *self)
Definition: correlation-context.c:109
CorrelationContext * correlation_context_new(CorrelationKey *key)
Definition: correlation-context.c:124
CorrelationContext * correlation_context_ref(CorrelationContext *self)
Definition: correlation-context.c:133
void correlation_context_clear_method(CorrelationContext *self)
Definition: correlation-context.c:99
#define self
Definition: rcptid.c:38
Definition: correlation-key.h:47
Definition: correlation-context.h:35
gint ref_cnt
Definition: correlation-context.h:42
GPtrArray * messages
Definition: correlation-context.h:41
TWEntry * timer
Definition: correlation-context.h:39
void(* free_fn)(CorrelationContext *s)
Definition: correlation-context.h:44
void(* clear)(CorrelationContext *s)
Definition: correlation-context.h:43
CorrelationKey key
Definition: correlation-context.h:37
struct tm key
Definition: cache.c:63