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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS), Gergely Nagy
  • Date: 2011-10-11 14:30:48 UTC
  • mfrom: (1.3.7)
  • Revision ID: package-import@ubuntu.com-20111011143048-r1iljux9xbvj3lwh
Tags: 3.3.1.dfsg-1
* New upstream release with important fixes from upstream git tree with
  non-free manpages removed.
* Drop syslog-ng.conf(5) (closes: #496521).
* syslog-ng(8) is generated, and does not mention -Q anymore
  (closes: #616069).
* Supports CAP_SYSLOG on recent kernels (closes: #630172).
* Does not use g_timeout_add_seconds anymore (closes: #609154).

[ Gergely Nagy <algernon@madhouse-project.org> ]
* Update debian/copyright to DEP-5 format.
* Simplified the logrotate file by merging identical entries.
* Include local configuration files from /etc/syslog-ng/conf.d/ (Closes:
  #609050).
* Update syslog-ng.conf to be fully 3.3 compliant.
* Compress both source and binaries (except the syslog-ng meta
  package) with xz, instead of gzip.
* Use dpkg triggers to restart syslog-ng when appropriate.
* Include DFSG-free manual pages for all binaries.
* Build with Hardening enabled.
* Mention syslog(3) in /etc/default/syslog-ng, instead of
  <linux/kernel.h> (Closes: #608605)
* Support 'status' in the init script.
  Patch from Peter Eisentraut <petere@debian.org> (Closes: #644458)
* Build-Depend on libevtlog-dev (>= 0.2.12-5~) for correct shlibs.
* Use [linux-any] in Build-Depends instead of hardcoded links.
  (Closes: #634715)
* Use $SYSLOGNG_OPTS in the init script when reloading syslog-ng.
  (Closes: #589081)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include "filter-expr-parser.h"
5
5
#include "cfg.h"
6
6
 
 
7
#include <stdlib.h>
 
8
#include <errno.h>
 
9
#include <string.h>
 
10
 
7
11
static void
8
 
tf_echo(LogMessage *msg, gint argc, GString *argv[], GString *result)
 
12
append_args(gint argc, GString *argv[], GString *result)
9
13
{
10
14
  gint i;
11
15
 
17
21
    }
18
22
}
19
23
 
 
24
static void
 
25
tf_echo(LogMessage *msg, gint argc, GString *argv[], GString *result)
 
26
{
 
27
  append_args(argc, argv, result);
 
28
}
 
29
 
20
30
TEMPLATE_FUNCTION_SIMPLE(tf_echo);
21
31
 
22
32
typedef struct _TFCondState
32
42
  gint i;
33
43
 
34
44
  if (args->filter)
35
 
    filter_expr_free(args->filter);
 
45
    filter_expr_unref(args->filter);
36
46
  for (i = 0; i < args->argc; i++)
37
47
    {
38
48
      if (args->argv[i])
53
63
  args = g_malloc0(sizeof(TFCondState) + (argc - 1) * sizeof(LogTemplate *));
54
64
  args->argc = argc - 1;
55
65
  lexer = cfg_lexer_new_buffer(argv[0], strlen(argv[0]));
56
 
  if (!cfg_run_parser(parent->cfg, lexer, &filter_expr_parser, (gpointer *) &args->filter))
 
66
  if (!cfg_run_parser(parent->cfg, lexer, &filter_expr_parser, (gpointer *) &args->filter, NULL))
57
67
    {
58
68
      g_set_error(error, LOG_TEMPLATE_ERROR, LOG_TEMPLATE_ERROR_COMPILE, "Error parsing conditional filter expression");
59
69
      goto error;
60
70
    }
61
71
  for (i = 1; i < argc; i++)
62
72
    {
63
 
      args->argv[i - 1] = log_template_new(parent->cfg, NULL, argv[i]);
 
73
      args->argv[i - 1] = log_template_new(parent->cfg, NULL);
64
74
      log_template_set_escape(args->argv[i - 1], TRUE);
65
 
      if (!log_template_compile(args->argv[i - 1], error))
 
75
      if (!log_template_compile(args->argv[i - 1], argv[i], error))
66
76
        goto error;
67
77
    }
68
78
  *state = args;
75
85
}
76
86
 
77
87
void
78
 
tf_cond_eval(LogTemplateFunction *self, gpointer state, GPtrArray *arg_bufs, LogMessage **messages, gint num_messages, LogTemplateOptions *opts, gint tz, gint seq_num)
 
88
tf_cond_eval(LogTemplateFunction *self, gpointer state, GPtrArray *arg_bufs, LogMessage **messages, gint num_messages, LogTemplateOptions *opts, gint tz, gint seq_num, const gchar *context_id)
79
89
{
80
90
  return;
81
91
}
94
104
 
95
105
 
96
106
void
97
 
tf_grep_call(LogTemplateFunction *self, gpointer state, GPtrArray *arg_bufs, LogMessage **messages, gint num_messages, LogTemplateOptions *opts, gint tz, gint seq_num, GString *result)
 
107
tf_grep_call(LogTemplateFunction *self, gpointer state, GPtrArray *arg_bufs, LogMessage **messages, gint num_messages, LogTemplateOptions *opts, gint tz, gint seq_num, const gchar *context_id, GString *result)
98
108
{
99
109
  gint i, msg_ndx;
100
110
  gboolean first = TRUE;
110
120
            {
111
121
              if (!first)
112
122
                g_string_append_c(result, ',');
113
 
              log_template_append_format(args->argv[i], msg, opts, tz, seq_num, result);
 
123
              log_template_append_format(args->argv[i], msg, opts, tz, seq_num, context_id, result);
114
124
              first = FALSE;
115
125
            }
116
126
        }
133
143
TEMPLATE_FUNCTION(tf_grep, tf_grep_prepare, tf_cond_eval, tf_grep_call, NULL);
134
144
 
135
145
void
136
 
tf_if_call(LogTemplateFunction *self, gpointer state, GPtrArray *arg_bufs, LogMessage **messages, gint num_messages, LogTemplateOptions *opts, gint tz, gint seq_num, GString *result)
 
146
tf_if_call(LogTemplateFunction *self, gpointer state, GPtrArray *arg_bufs, LogMessage **messages, gint num_messages, LogTemplateOptions *opts, gint tz, gint seq_num, const gchar *context_id, GString *result)
137
147
{
138
148
  TFCondState *args = (TFCondState *) state;
139
149
  LogMessage *msg;
142
152
  msg = messages[num_messages - 1];
143
153
  if (filter_expr_eval(args->filter, msg))
144
154
    {
145
 
      log_template_append_format(args->argv[0], msg, opts, tz, seq_num, result);
 
155
      log_template_append_format(args->argv[0], msg, opts, tz, seq_num, context_id, result);
146
156
    }
147
157
  else
148
158
    {
149
 
      log_template_append_format(args->argv[1], msg, opts, tz, seq_num, result);
 
159
      log_template_append_format(args->argv[1], msg, opts, tz, seq_num, context_id, result);
150
160
    }
151
161
}
152
162
 
153
163
TEMPLATE_FUNCTION(tf_if, tf_if_prepare, tf_cond_eval, tf_if_call, NULL);
154
164
 
155
165
 
156
 
static Plugin builtin_tmpl_func_plugins[] =
 
166
void
 
167
tf_indent_multi_line(LogMessage *msg, gint argc, GString *argv[], GString *text)
 
168
{
 
169
  gchar *p, *new_line;
 
170
 
 
171
  /* append the message text(s) to the template string */
 
172
  append_args(argc, argv, text);
 
173
 
 
174
  /* look up the \n-s and insert a \t after them */
 
175
  p = text->str;
 
176
  new_line = memchr(p, '\n', text->len);
 
177
  while(new_line)
 
178
    {
 
179
      if (*(gchar *)(new_line + 1) != '\t')
 
180
        {
 
181
          g_string_insert_c(text, new_line - p + 1, '\t');
 
182
        }
 
183
      new_line = memchr(new_line + 1, '\n', p + text->len - new_line);
 
184
    }
 
185
}
 
186
 
 
187
TEMPLATE_FUNCTION_SIMPLE(tf_indent_multi_line);
 
188
 
 
189
static Plugin basicfuncs_plugins[] =
157
190
{
158
191
  TEMPLATE_FUNCTION_PLUGIN(tf_echo, "echo"),
159
192
  TEMPLATE_FUNCTION_PLUGIN(tf_grep, "grep"),
160
193
  TEMPLATE_FUNCTION_PLUGIN(tf_if, "if"),
 
194
  TEMPLATE_FUNCTION_PLUGIN(tf_indent_multi_line, "indent-multi-line"),
161
195
};
162
196
 
163
197
gboolean
164
198
basicfuncs_module_init(GlobalConfig *cfg, CfgArgs *args)
165
199
{
166
 
  plugin_register(cfg, builtin_tmpl_func_plugins, G_N_ELEMENTS(builtin_tmpl_func_plugins));
 
200
  plugin_register(cfg, basicfuncs_plugins, G_N_ELEMENTS(basicfuncs_plugins));
167
201
  return TRUE;
168
202
}
 
203
 
 
204
const ModuleInfo module_info =
 
205
{
 
206
  .canonical_name = "basicfuncs",
 
207
  .version = VERSION,
 
208
  .description = "The basicfuncs module provides various template functions for syslog-ng.",
 
209
  .core_revision = SOURCE_REVISION,
 
210
  .plugins = basicfuncs_plugins,
 
211
  .plugins_len = G_N_ELEMENTS(basicfuncs_plugins),
 
212
};