1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/*
* Copyright (c) 2002-2013 Balabit
* Copyright (c) 1998-2013 Balázs Scheidler
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#include "filter/filter-pri.h"
#include "syslog-names.h"
#include "logmsg/logmsg.h"
typedef struct _FilterPri
{
FilterExprNode super;
guint32 valid;
} FilterPri;
static gboolean
filter_facility_eval(FilterExprNode *s, LogMessage **msgs, gint num_msg, LogTemplateEvalOptions *options)
{
FilterPri *self = (FilterPri *) s;
LogMessage *msg = msgs[num_msg - 1];
guint32 fac_num = (msg->pri & SYSLOG_FACMASK) >> 3;
gboolean res;
if (G_UNLIKELY(self->valid & 0x80000000))
{
/* exact number specified */
res = ((self->valid & ~0x80000000) == fac_num);
}
else
{
res = !!(self->valid & (1 << fac_num));
}
msg_trace("facility() evaluation started",
evt_tag_int("fac", fac_num),
evt_tag_printf("valid_fac", "%08x", self->valid),
evt_tag_msg_reference(msg));
return res ^ s->comp;
}
FilterExprNode *
filter_facility_new(guint32 facilities)
{
FilterPri *self = g_new0(FilterPri, 1);
filter_expr_node_init_instance(&self->super);
self->super.eval = filter_facility_eval;
self->valid = facilities;
self->super.type = "facility";
return &self->super;
}
static gboolean
filter_severity_eval(FilterExprNode *s, LogMessage **msgs, gint num_msg, LogTemplateEvalOptions *options)
{
FilterPri *self = (FilterPri *) s;
LogMessage *msg = msgs[num_msg - 1];
guint32 pri = msg->pri & SYSLOG_PRIMASK;
gboolean res;
res = !!((1 << pri) & self->valid);
msg_trace("severity() evaluation started",
evt_tag_int("pri", pri),
evt_tag_printf("valid_pri", "%08x", self->valid),
evt_tag_msg_reference(msg));
return res ^ s->comp;
}
FilterExprNode *
filter_severity_new(guint32 levels)
{
FilterPri *self = g_new0(FilterPri, 1);
filter_expr_node_init_instance(&self->super);
self->super.eval = filter_severity_eval;
self->valid = levels;
self->super.type = "severity";
return &self->super;
}
|