2
* Copyright (c) 2002-2012 BalaBit IT Ltd, Budapest, Hungary
3
* Copyright (c) 1998-2012 Balázs Scheidler
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.
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.
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
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.
25
tf_num_parse(gint argc, GString *argv[],
26
const gchar *func_name, glong *n, glong *m)
30
msg_debug("Template function requires two arguments.",
31
evt_tag_str("function", func_name), NULL);
35
if (!parse_number_with_suffix(argv[0]->str, n))
37
msg_debug("Parsing failed, template function's first argument is not a number",
38
evt_tag_str("function", func_name),
39
evt_tag_str("arg1", argv[0]->str), NULL);
43
if (!parse_number_with_suffix(argv[1]->str, m))
45
msg_debug("Parsing failed, template function's first argument is not a number",
46
evt_tag_str("function", func_name),
47
evt_tag_str("arg1", argv[1]->str), NULL);
55
tf_num_plus(LogMessage *msg, gint argc, GString *argv[], GString *result)
59
if (!tf_num_parse(argc, argv, "+", &n, &m))
61
g_string_append_len(result, "NaN", 3);
65
format_int32_padded(result, 0, ' ', 10, n + m);
68
TEMPLATE_FUNCTION_SIMPLE(tf_num_plus);
71
tf_num_minus(LogMessage *msg, gint argc, GString *argv[], GString *result)
75
if (!tf_num_parse(argc, argv, "-", &n, &m))
77
g_string_append_len(result, "NaN", 3);
81
format_int32_padded(result, 0, ' ', 10, n - m);
84
TEMPLATE_FUNCTION_SIMPLE(tf_num_minus);
87
tf_num_multi(LogMessage *msg, gint argc, GString *argv[], GString *result)
91
if (!tf_num_parse(argc, argv, "*", &n, &m))
93
g_string_append_len(result, "NaN", 3);
97
format_int32_padded(result, 0, ' ', 10, n * m);
100
TEMPLATE_FUNCTION_SIMPLE(tf_num_multi);
103
tf_num_div(LogMessage *msg, gint argc, GString *argv[], GString *result)
107
if (!tf_num_parse(argc, argv, "/", &n, &m) || !m)
109
g_string_append_len(result, "NaN", 3);
113
format_int32_padded(result, 0, ' ', 10, n / m);
116
TEMPLATE_FUNCTION_SIMPLE(tf_num_div);
119
tf_num_mod(LogMessage *msg, gint argc, GString *argv[], GString *result)
123
if (!tf_num_parse(argc, argv, "%", &n, &m) || !m)
125
g_string_append_len(result, "NaN", 3);
129
format_uint32_padded(result, 0, ' ', 10, n % m);
132
TEMPLATE_FUNCTION_SIMPLE(tf_num_mod);