test_template_compile: create get_template_function_ops()

This new function makes it easier to describe LTE_FUNC elements.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
templates.c: extract log_template_prepare_function_call()

In order to make log_template_add_func_elem() easier to read (and to prepare
a new feature there), extract log_template_prepare_function_call()
that sets up the template function invocation given the implementing
plugin.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
templates.c: extract log_template_lookup_and_setup_function_call()

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
messages: add msg_warning_once() macro

This patch implements msg_warning_once() macro, that causes the warning
to be printed once per syslog-ng execution. This pattern is being
used at a number of places in syslog-ng, but so far has been open-coded
at all sites. This macro makes it possible to refactor all such sites,
reducing the code considerably.

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
global: use msg_warning_once() instead of open coding the same

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
cfg: display warning about duplicate configuration elements only once

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
afmongodb: remove exclamation from warning messages

All other warning call sites use WARNING: and not WARNING!, do the same in
the mongo driver too.

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
dbparser: only display the change in inject-mode() once per startup

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
cfg-tree: increase buffer for formatting the location in debug messages

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
cfg-tree: add log_expr_node_location_tag() function

This new function formats a "location" tag to be emitted as a name-value
pair associated with an internal message. This makes it trivial
to add this information to internal messages.

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
logpipe: add log_pipe_location_tag() function

This function formats a "location" tag to be emitted as a name-value
pair of internal messages.

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
global: use log_pipe_location_tag() and log_expr_node_location_tag()

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
system-source: parse @cim marked messages by json-parser automatically

This allows any local applications to submit JSON formatted messages
through the syslog() API, which will automatically be parsed. A ".cim."
prefix will be added to the fields extracted.

The same values can be reconstructed using a value-pairs expression,
something like:

  $(format-json --key .cim.* --shift 5)

Signed-off-by: Balazs Scheidler <bazsi@balabit.com>
cfg-grammar: make it possible to create templates without braces

In a number of cases this syntax:

template foo {
    template("template text");
};

Has a lot of boilerplate. In case template-escape() option is not needed
(which is less-and-less needed and could probably be deprecated),
this syntax is just enough:

template foo "template text";

This plays nicely with the new feature that template functions can be defined in
configuration files with a similar syntax.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
plugin: add free_fn to Plugin instances

Traditionally Plugin instances are allocated as global variables, which
didn't need free operation. This patch allows allocating Plugin instances
dynamically, which in turn requires a free_fn.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
templates: add free_fn method to LogTemplateFunction

Just like with Plugins, LogTemplateFunctions couldn't really be subclassed,
as we basically assumed those are defined in a statically allocated struct.
With the upcoming support for user-defined template functions, we do need
to allocate these on the heap, thus a free operation is needed too.

This patch adds this free_fn, which should both free any dynamic data inside
the struct _and_ the struct itself.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
templates: don't allocate state if size_of_state is zero

The upcoming user template functions code does not have a state, and we
don't want to implement boilerplate free_state calls.  Make state optional
by specifying size_of_state as zero.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
templates: add implementation for user-defined template functions

This patch adds a new API, user_template_function_register() that allows
registering a LogTemplate instance as a template function, dynamically.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-grammar: add template-function support

This patch completes the support for user defined template functions. With
this patch you can define template functions in your configuration the same
way you would define a template.

template-function foobar "this is a template function running on $HOST";

destination d_file {
	file("something.log" template("$(foobar)\n"));
};

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
scl: add $(format-cim) template function

This patch adds a template function $(format-cim) into an SCL module
that implements Common Information Model (aka cim) formatting, as
used by Kibana (and Splunk).

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>