~ubuntu-branches/ubuntu/wily/syslog-ng/wily-proposed

« back to all changes in this revision

Viewing changes to modules/basicfuncs/numeric-funcs.c

  • Committer: Package Import Robot
  • Author(s): Gergely Nagy, Gergely Nagy
  • Date: 2013-11-04 15:27:37 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131104152737-mqh6eqtna2xk97jq
Tags: 3.5.1-1
[ Gergely Nagy <algernon@madhouse-project.org> ]
* New upstream release.
  + Support auto-loading modules (Closes: #650814)
  + The SMTP module is available in syslog-ng-mod-smtp (Closes: #722746)
  + New modules: amqp, geoip, stomp, redis and smtp.
  + Multi-line input support (indented multiline and regexp-based)
  + Template type hinting for the MongoDB destination and $(format-json)
  + Support for unit suffixes in the configuration file
  + New filters, template functions and other miscellaneous changes
* New (team) maintainer, Laszlo Boszormenyi, Attila Szalay and myself
  added to Uploaders.
* Ship /var/lib/syslog-ng in the syslog-ng-core package, instead of
  creating it in the init script. Thanks Michael Biebl
  <biebl@debian.org> for the report & assistance. (Closes: #699942, #719910)
* Use dh-systemd for proper systemd-related maintainer scripts. Based on
  a patch by Michael Biebl <biebl@debian.org>. (Closes: #713982,
  #690067)
* Do not wait for syslog-ng to settle down during installation / update.
  This also fixes installing via debootstrap and a fake
  start-stop-daemon. (Closes: #714254)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2002-2012 BalaBit IT Ltd, Budapest, Hungary
 
3
 * Copyright (c) 1998-2012 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
 
 
24
static gboolean
 
25
tf_num_parse(gint argc, GString *argv[],
 
26
             const gchar *func_name, glong *n, glong *m)
 
27
{
 
28
  if (argc != 2)
 
29
    {
 
30
      msg_debug("Template function requires two arguments.",
 
31
                evt_tag_str("function", func_name), NULL);
 
32
      return FALSE;
 
33
    }
 
34
 
 
35
  if (!parse_number_with_suffix(argv[0]->str, n))
 
36
    {
 
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);
 
40
      return FALSE;
 
41
    }
 
42
 
 
43
  if (!parse_number_with_suffix(argv[1]->str, m))
 
44
    {
 
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);
 
48
      return FALSE;
 
49
    }
 
50
 
 
51
  return TRUE;
 
52
}
 
53
 
 
54
static void
 
55
tf_num_plus(LogMessage *msg, gint argc, GString *argv[], GString *result)
 
56
{
 
57
  glong n, m;
 
58
 
 
59
  if (!tf_num_parse(argc, argv, "+", &n, &m))
 
60
    {
 
61
      g_string_append_len(result, "NaN", 3);
 
62
      return;
 
63
    }
 
64
 
 
65
  format_int32_padded(result, 0, ' ', 10, n + m);
 
66
}
 
67
 
 
68
TEMPLATE_FUNCTION_SIMPLE(tf_num_plus);
 
69
 
 
70
static void
 
71
tf_num_minus(LogMessage *msg, gint argc, GString *argv[], GString *result)
 
72
{
 
73
  glong n, m;
 
74
 
 
75
  if (!tf_num_parse(argc, argv, "-", &n, &m))
 
76
    {
 
77
      g_string_append_len(result, "NaN", 3);
 
78
      return;
 
79
    }
 
80
 
 
81
  format_int32_padded(result, 0, ' ', 10, n - m);
 
82
}
 
83
 
 
84
TEMPLATE_FUNCTION_SIMPLE(tf_num_minus);
 
85
 
 
86
static void
 
87
tf_num_multi(LogMessage *msg, gint argc, GString *argv[], GString *result)
 
88
{
 
89
  glong n, m;
 
90
 
 
91
  if (!tf_num_parse(argc, argv, "*", &n, &m))
 
92
    {
 
93
      g_string_append_len(result, "NaN", 3);
 
94
      return;
 
95
    }
 
96
 
 
97
  format_int32_padded(result, 0, ' ', 10, n * m);
 
98
}
 
99
 
 
100
TEMPLATE_FUNCTION_SIMPLE(tf_num_multi);
 
101
 
 
102
static void
 
103
tf_num_div(LogMessage *msg, gint argc, GString *argv[], GString *result)
 
104
{
 
105
  glong n, m;
 
106
 
 
107
  if (!tf_num_parse(argc, argv, "/", &n, &m) || !m)
 
108
    {
 
109
      g_string_append_len(result, "NaN", 3);
 
110
      return;
 
111
    }
 
112
 
 
113
  format_int32_padded(result, 0, ' ', 10, n / m);
 
114
}
 
115
 
 
116
TEMPLATE_FUNCTION_SIMPLE(tf_num_div);
 
117
 
 
118
static void
 
119
tf_num_mod(LogMessage *msg, gint argc, GString *argv[], GString *result)
 
120
{
 
121
  glong n, m;
 
122
 
 
123
  if (!tf_num_parse(argc, argv, "%", &n, &m) || !m)
 
124
    {
 
125
      g_string_append_len(result, "NaN", 3);
 
126
      return;
 
127
    }
 
128
 
 
129
  format_uint32_padded(result, 0, ' ', 10, n % m);
 
130
}
 
131
 
 
132
TEMPLATE_FUNCTION_SIMPLE(tf_num_mod);