Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 13 commits
  • 27 files changed
  • 0 comments
  • 1 contributor
Aug 12, 2012
Balazs Scheidler bazsi ivykis: updated to latest commit in ivykis-0.30 branch
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
1850cd9
Balazs Scheidler bazsi tfuuid: rename to cryptofuncs
Some further crypto related functions are to be added to syslog-ng, I'd
like to avoid the profileration of modules just for single functions.

Thus "cryptofuncs" is born, a place for stuff that depeeds on OpenSSL.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
58e9f31
Balazs Scheidler bazsi $(hash): New template function to calculate the hash of its inputs
This patch adds a family of new template functions called
$(hash), $(md5), $(md4), $(sha1), $(sha256), $(sha512)

These can be used to calculate the cryptographic hash of its arguments.

As it uses the SHA1() function from OpenSSL, it is only available if syslog-ng
is compiled using --enable-ssl.

One use case for it can be when you'd like to anonymize sensitive parts of the
log message (eg. the user name) you parsed out using patterndb before storing
or forwarding it for further analysis but would like to retain the ability to
correlate messages along this value. Beware though that such simple anonymization
can be broken if there's enough data available, see

    http://arxiv.org/pdf/cs/0610105v2.pdf for references and examples.

Another use-case is to generate quasi-unique-ids for data, using the
--length option that truncates the length of the hash to a shorter form.
In real life the chances of the collision is slim, but still makes it
possible to use a shorter id, than in most cases is unique, especially
when constrained to a time period, which is often the case for logs.

Syntax:
  $(<method> [opts] $arg1 $arg2 $arg3...)

Options:
  --length N, -l N    Truncate the hash to the first N characters

The generic name "hash" refers to md5. Arguments are concatenated w/o the
use of additional characters.

Thanks for the original idea to Martin Grauel.

Signed-off-by: Peter Gyongyosi <gyp@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
e7538a5
Balazs Scheidler bazsi cryptofuncs: refactor hash related tests to a separate unit test program
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
89fab67
Balazs Scheidler bazsi msg_parse_lib: rearranged includes
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
3df8c3c
Aug 13, 2012
Balazs Scheidler bazsi value-pairs: clarified some error messages
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cc866a8
Balazs Scheidler bazsi libtest: added assert_template_format_with_context() function
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
0f3c04f
Balazs Scheidler bazsi tfjson: added skeleton unit tests 30ef046
Balazs Scheidler bazsi test_template: remove cryptofuncs unit tests
As they were moved to a separate test program in an earlier commit.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
36c00a9
Balazs Scheidler bazsi basicfuncs: unit tests moved to a separate program
Continuing the refactor to independent unit tests, this patch moves stuff
from test_template to modules/basicfuncs/tests using the new
template_lib.c in libtest.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
7745887
Balazs Scheidler bazsi test_template_speed: indent output so that unit test runs are more re…
…adable

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
8644c76
Balazs Scheidler bazsi test_template: refactor to use testutils
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
ba8a1bc
Aug 14, 2012
Balazs Scheidler bazsi fixed invalid declarations for bison generated yyparse() functions
The new bison finally declares the yyparse() function in its header, which
revealed a couple of invalid declarations in a couple of parsers.

This patch fixes that.

Reported-By: Conrad Hoffmann <ch@bitfehler.net>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cb62deb

Showing 27 changed files with 704 additions and 423 deletions. Show diff stats Hide diff stats

  1. +4 1 configure.in
  2. +1 1  lib/filter-expr-parser.c
  3. +1 1  lib/ivykis
  4. +1 1  lib/parser-expr-parser.c
  5. +1 1  lib/rewrite-expr-parser.c
  6. +3 3 lib/value-pairs.c
  7. +2 0  libtest/Makefile.am
  8. +3 3 libtest/msg_parse_lib.h
  9. +112 0 libtest/template_lib.c
  10. +17 0 libtest/template_lib.h
  11. +1 1  modules/Makefile.am
  12. +1 1  modules/afsmtp/afsmtp-parser.c
  13. +1 1  modules/afuser/afuser-parser.c
  14. +2 0  modules/basicfuncs/Makefile.am
  15. +6 0 modules/basicfuncs/tests/Makefile.am
  16. +99 0 modules/basicfuncs/tests/test_basicfuncs.c
  17. +10 0 modules/cryptofuncs/Makefile.am
  18. +176 0 modules/cryptofuncs/cryptofuncs.c
  19. +6 0 modules/cryptofuncs/tests/Makefile.am
  20. +39 0 modules/cryptofuncs/tests/test_cryptofuncs.c
  21. +2 0  modules/tfjson/Makefile.am
  22. +6 0 modules/tfjson/tests/Makefile.am
  23. +24 0 modules/tfjson/tests/test_json.c
  24. +0 9 modules/tfuuid/Makefile.am
  25. +0 57 modules/tfuuid/tfuuid.c
  26. +185 342 tests/unit/test_template.c
  27. +1 1  tests/unit/test_template_speed.c
5 configure.in
@@ -1187,8 +1187,11 @@ AC_OUTPUT(dist.conf
1187 1187 modules/syslogformat/Makefile
1188 1188 modules/pacctformat/Makefile
1189 1189 modules/basicfuncs/Makefile
  1190 + modules/basicfuncs/tests/Makefile
  1191 + modules/cryptofuncs/Makefile
  1192 + modules/cryptofuncs/tests/Makefile
1190 1193 modules/tfjson/Makefile
1191   - modules/tfuuid/Makefile
  1194 + modules/tfjson/tests/Makefile
1192 1195 modules/jsonparser/Makefile
1193 1196 scripts/Makefile
1194 1197 scripts/update-patterndb
2  lib/filter-expr-parser.c
@@ -27,7 +27,7 @@
27 27 #include "filter-expr-grammar.h"
28 28
29 29 extern int filter_expr_debug;
30   -int filter_expr_parse(CfgLexer *lexer, FilterExprNode **node);
  30 +int filter_expr_parse(CfgLexer *lexer, FilterExprNode **node, gpointer arg);
31 31
32 32 static CfgLexerKeyword filter_expr_keywords[] = {
33 33 { "or", KW_OR },
2  lib/ivykis
... ... @@ -1 +1 @@
1   -Subproject commit 73c0c27a19755f700b268081a5a59acdd04b421e
  1 +Subproject commit 526937a9116ed9fc816b4bb086aa11c4ded44aac
2  lib/parser-expr-parser.c
@@ -26,7 +26,7 @@
26 26 #include "parser-expr-grammar.h"
27 27
28 28 extern int parser_expr_debug;
29   -int parser_expr_parse(CfgLexer *lexer, LogExprNode **node);
  29 +int parser_expr_parse(CfgLexer *lexer, LogExprNode **node, gpointer arg);
30 30
31 31 static CfgLexerKeyword parser_expr_keywords[] = {
32 32 { "file", KW_FILE },
2  lib/rewrite-expr-parser.c
@@ -27,7 +27,7 @@
27 27 #include "rewrite-expr-grammar.h"
28 28
29 29 extern int rewrite_expr_debug;
30   -int rewrite_expr_parse(CfgLexer *lexer, LogExprNode **node);
  30 +int rewrite_expr_parse(CfgLexer *lexer, LogExprNode **node, gpointer arg);
31 31
32 32 static CfgLexerKeyword rewrite_expr_keywords[] = {
33 33 { "set", KW_SET, 0x0300 },
6 lib/value-pairs.c
@@ -476,7 +476,7 @@ vp_cmdline_parse_scope(const gchar *option_name, const gchar *value,
476 476 if (!value_pairs_add_scope (vp, value))
477 477 {
478 478 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
479   - "Unknon value-pairs scope, scope=%s", value);
  479 + "Error parsing value-pairs: unknown scope %s", value);
480 480 return FALSE;
481 481 }
482 482 return TRUE;
@@ -520,7 +520,7 @@ vp_cmdline_parse_pair (const gchar *option_name, const gchar *value,
520 520 if (!g_strstr_len (value, strlen (value), "="))
521 521 {
522 522 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
523   - "Error parsing value-pairs' key=value pair");
  523 + "Error parsing value-pairs: expected an equal sign in key=value pair");
524 524 return FALSE;
525 525 }
526 526
@@ -573,7 +573,7 @@ vp_cmdline_parse_rekey_replace (const gchar *option_name, const gchar *value,
573 573 if (!g_strstr_len (value, strlen (value), "="))
574 574 {
575 575 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
576   - "Error parsing value-pairs' rekey replace construct");
  576 + "Error parsing value-pairs: rekey replace construct should be in the format string=replacement");
577 577 return FALSE;
578 578 }
579 579
2  libtest/Makefile.am
@@ -10,5 +10,7 @@ libsyslog_ng_test_a_SOURCES = \
10 10 testutils.h \
11 11 msg_parse_lib.c \
12 12 msg_parse_lib.h \
  13 + template_lib.c \
  14 + template_lib.h \
13 15 mock-transport.c \
14 16 mock-transport.h
6 libtest/msg_parse_lib.h
... ... @@ -1,12 +1,12 @@
  1 +#ifndef MSG_PARSE_LIB_H_INCLUDED
  2 +#define MSG_PARSE_LIB_H_INCLUDED
  3 +
1 4 #include "testutils.h"
2 5
3 6 #include "cfg.h"
4 7 #include "plugin.h"
5 8 #include "logmsg.h"
6 9
7   -#ifndef MSG_PARSE_LIB_H_INCLUDED
8   -#define MSG_PARSE_LIB_H_INCLUDED
9   -
10 10 MsgFormatOptions parse_options;
11 11
12 12 void init_and_load_syslogformat_module();
112 libtest/template_lib.c
... ... @@ -0,0 +1,112 @@
  1 +#include "template_lib.h"
  2 +#include "msg_parse_lib.h"
  3 +
  4 +void
  5 +init_template_tests(void)
  6 +{
  7 + init_and_load_syslogformat_module();
  8 +}
  9 +
  10 +void
  11 +deinit_template_tests(void)
  12 +{
  13 + deinit_syslogformat_module();
  14 +}
  15 +
  16 +LogMessage *
  17 +create_sample_message(void)
  18 +{
  19 + LogMessage *msg;
  20 + char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]:árvíztűrőtükörfúrógép";
  21 + GSockAddr *saddr;
  22 +
  23 + saddr = g_sockaddr_inet_new("10.11.12.13", 1010);
  24 + msg = log_msg_new(msg_str, strlen(msg_str), saddr, &parse_options);
  25 + g_sockaddr_unref(saddr);
  26 + log_msg_set_value(msg, log_msg_get_value_handle("APP.VALUE"), "value", -1);
  27 + log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP1"), " value", -1);
  28 + log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP2"), "value ", -1);
  29 + log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP3"), " value ", -1);
  30 + log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP4"), "value", -1);
  31 + log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP5"), "", -1);
  32 + log_msg_set_match(msg, 0, "whole-match", -1);
  33 + log_msg_set_match(msg, 1, "first-match", -1);
  34 + log_msg_set_tag_by_name(msg, "alma");
  35 + log_msg_set_tag_by_name(msg, "korte");
  36 + log_msg_clear_tag_by_name(msg, "narancs");
  37 + log_msg_set_tag_by_name(msg, "citrom");
  38 +
  39 + /* fix some externally or automatically defined values */
  40 + log_msg_set_value(msg, LM_V_HOST_FROM, "kismacska", -1);
  41 + msg->timestamps[LM_TS_RECVD].tv_sec = 1139684315;
  42 + msg->timestamps[LM_TS_RECVD].tv_usec = 639000;
  43 + msg->timestamps[LM_TS_RECVD].zone_offset = get_local_timezone_ofs(1139684315);
  44 +
  45 + return msg;
  46 +}
  47 +
  48 +LogTemplate *
  49 +compile_template(const gchar *template)
  50 +{
  51 + LogTemplate *templ = log_template_new(configuration, NULL);
  52 + gboolean success;
  53 + GError *error = NULL;
  54 +
  55 + success = log_template_compile(templ, template, &error);
  56 + assert_true(success, "template expected to compile cleanly, but it didn't, template=%s, error=%s", template, error ? error->message : "(none)");
  57 + g_clear_error(&error);
  58 +
  59 + return templ;
  60 +}
  61 +
  62 +void
  63 +assert_template_format(const gchar *template, const gchar *expected)
  64 +{
  65 + LogMessage *msg;
  66 + LogTemplate *templ;
  67 + GString *res = g_string_sized_new(128);
  68 + const gchar *context_id = "test-context-id";
  69 +
  70 + msg = create_sample_message();
  71 +
  72 + templ = compile_template(template);
  73 + log_template_format(templ, msg, NULL, LTZ_LOCAL, 999, context_id, res);
  74 + assert_string(res->str, expected, "template test failed, template=%s", template);
  75 + log_template_unref(templ);
  76 + g_string_free(res, TRUE);
  77 + log_msg_unref(msg);
  78 +}
  79 +
  80 +void
  81 +assert_template_format_with_context(const gchar *template, const gchar *expected)
  82 +{
  83 + LogMessage *msg;
  84 + LogTemplate *templ;
  85 + GString *res = g_string_sized_new(128);
  86 + const gchar *context_id = "test-context-id";
  87 + LogMessage *context[2];
  88 +
  89 + msg = create_sample_message();
  90 + context[0] = context[1] = msg;
  91 +
  92 + templ = compile_template(template);
  93 +
  94 + log_template_format_with_context(templ, context, 2, NULL, LTZ_LOCAL, 999, context_id, res);
  95 + assert_string(res->str, expected, "context template test failed, template=%s", template);
  96 + log_template_unref(templ);
  97 + g_string_free(res, TRUE);
  98 + log_msg_unref(msg);
  99 +}
  100 +
  101 +void
  102 +assert_template_failure(const gchar *template, const gchar *expected_error)
  103 +{
  104 + LogTemplate *templ;
  105 + GError *error = NULL;
  106 +
  107 + templ = log_template_new(configuration, NULL);
  108 + assert_false(log_template_compile(templ, template, &error), "compilation failure expected to template, but success was returned, template=%s, expected_error=%s\n", template, expected_error);
  109 + assert_true(strstr(error->message, expected_error) != NULL, "FAIL: compilation error doesn't match, error=%s, expected_error=%s\n", error->message, expected_error);
  110 + g_clear_error(&error);
  111 + log_template_unref(templ);
  112 +}
17 libtest/template_lib.h
... ... @@ -0,0 +1,17 @@
  1 +#ifndef LIBTEST_TEMPLATE_LIB_H_INCLUDED
  2 +#define LIBTEST_TEMPLATE_LIB_H_INCLUDED 1
  3 +
  4 +#include "testutils.h"
  5 +#include "templates.h"
  6 +
  7 +void assert_template_format(const gchar *template, const gchar *expected);
  8 +void assert_template_format_with_context(const gchar *template, const gchar *expected);
  9 +void assert_template_failure(const gchar *template, const gchar *expected_failure);
  10 +
  11 +LogMessage *create_sample_message(void);
  12 +LogTemplate *compile_template(const gchar *template);
  13 +void init_template_tests(void);
  14 +void deinit_template_tests(void);
  15 +
  16 +
  17 +#endif
2  modules/Makefile.am
... ... @@ -1 +1 @@
1   -SUBDIRS = afsocket afsql afstreams affile afprog afuser afmongodb afsmtp csvparser confgen syslogformat pacctformat basicfuncs dbparser tfjson tfuuid jsonparser
  1 +SUBDIRS = afsocket afsql afstreams affile afprog afuser afmongodb afsmtp csvparser confgen syslogformat pacctformat basicfuncs cryptofuncs dbparser tfjson jsonparser
2  modules/afsmtp/afsmtp-parser.c
@@ -26,7 +26,7 @@
26 26 #include "afsmtp-grammar.h"
27 27
28 28 extern int afsmtp_debug;
29   -int afsmtp_parse(CfgLexer *lexer, LogDriver **instance);
  29 +int afsmtp_parse(CfgLexer *lexer, LogDriver **instance, gpointer arg);
30 30
31 31 static CfgLexerKeyword afsmtp_keywords[] = {
32 32 { "smtp", KW_SMTP },
2  modules/afuser/afuser-parser.c
@@ -27,7 +27,7 @@
27 27
28 28 extern int afuser_debug;
29 29
30   -int afuser_parse(CfgLexer *lexer, LogDriver **instance, gpointer);
  30 +int afuser_parse(CfgLexer *lexer, LogDriver **instance, gpointer arg);
31 31
32 32 static CfgLexerKeyword afuser_keywords[] = {
33 33 { "usertty", KW_USERTTY },
2  modules/basicfuncs/Makefile.am
... ... @@ -1,3 +1,5 @@
  1 +SUBDIRS = tests
  2 +
1 3 moduledir = @moduledir@
2 4 AM_CPPFLAGS = -I$(top_srcdir)/lib -I../../lib
3 5 export top_srcdir
6 modules/basicfuncs/tests/Makefile.am
... ... @@ -0,0 +1,6 @@
  1 +AM_CFLAGS = -I$(top_srcdir)/lib -I../../../lib -I$(top_srcdir)/libtest -I../../../libtest -I$(top_srcdir)/modules/basicfuncs -I..
  2 +AM_LDFLAGS = -dlpreopen ../../syslogformat/libsyslogformat.la -dlpreopen ../libbasicfuncs.la
  3 +LDADD = $(top_builddir)/lib/libsyslog-ng.la $(top_builddir)/libtest/libsyslog-ng-test.a @TOOL_DEPS_LIBS@
  4 +
  5 +check_PROGRAMS = test_basicfuncs
  6 +TESTS = $(check_PROGRAMS)
99 modules/basicfuncs/tests/test_basicfuncs.c
... ... @@ -0,0 +1,99 @@
  1 +#include "template_lib.h"
  2 +#include "apphook.h"
  3 +#include "plugin.h"
  4 +
  5 +void
  6 +test_cond_funcs(void)
  7 +{
  8 + assert_template_format_with_context("$(grep 'facility(local3)' $PID)", "23323,23323");
  9 + assert_template_format_with_context("$(grep -m 1 'facility(local3)' $PID)", "23323");
  10 + assert_template_format_with_context("$(grep 'facility(local3)' $PID $PROGRAM)", "23323,syslog-ng,23323,syslog-ng");
  11 + assert_template_format_with_context("$(grep 'facility(local4)' $PID)", "");
  12 + assert_template_format_with_context("$(grep ('$FACILITY' == 'local4') $PID)", "");
  13 + assert_template_format_with_context("$(grep ('$FACILITY(' == 'local3(') $PID)", "23323,23323");
  14 + assert_template_format_with_context("$(grep ('$FACILITY(' == 'local4)') $PID)", "");
  15 + assert_template_format_with_context("$(grep \\'$FACILITY\\'\\ ==\\ \\'local4\\' $PID)", "");
  16 +
  17 + assert_template_format_with_context("$(if 'facility(local4)' alma korte)", "korte");
  18 + assert_template_format_with_context("$(if 'facility(local3)' alma korte)", "alma");
  19 +
  20 + assert_template_format_with_context("$(if '\"$FACILITY\" lt \"local3\"' alma korte)", "korte");
  21 + assert_template_format_with_context("$(if '\"$FACILITY\" le \"local3\"' alma korte)", "alma");
  22 + assert_template_format_with_context("$(if '\"$FACILITY\" eq \"local3\"' alma korte)", "alma");
  23 + assert_template_format_with_context("$(if '\"$FACILITY\" ne \"local3\"' alma korte)", "korte");
  24 + assert_template_format_with_context("$(if '\"$FACILITY\" gt \"local3\"' alma korte)", "korte");
  25 + assert_template_format_with_context("$(if '\"$FACILITY\" ge \"local3\"' alma korte)", "alma");
  26 +
  27 + assert_template_format_with_context("$(if '\"$FACILITY_NUM\" < \"19\"' alma korte)", "korte");
  28 + assert_template_format_with_context("$(if '\"$FACILITY_NUM\" <= \"19\"' alma korte)", "alma");
  29 + assert_template_format_with_context("$(if '\"$FACILITY_NUM\" == \"19\"' alma korte)", "alma");
  30 + assert_template_format_with_context("$(if '\"$FACILITY_NUM\" != \"19\"' alma korte)", "korte");
  31 + assert_template_format_with_context("$(if '\"$FACILITY_NUM\" > \"19\"' alma korte)", "korte");
  32 + assert_template_format_with_context("$(if '\"$FACILITY_NUM\" >= \"19\"' alma korte)", "alma");
  33 + assert_template_format_with_context("$(if '\"$FACILITY_NUM\" >= \"19\" and \"kicsi\" == \"nagy\"' alma korte)", "korte");
  34 + assert_template_format_with_context("$(if '\"$FACILITY_NUM\" >= \"19\" or \"kicsi\" == \"nagy\"' alma korte)", "alma");
  35 +
  36 + assert_template_format_with_context("$(grep 'facility(local3)' $PID)@0", "23323");
  37 + assert_template_format_with_context("$(grep 'facility(local3)' $PID)@1", "23323");
  38 + assert_template_format_with_context("$(grep 'facility(local3)' $PID)@2", "");
  39 +}
  40 +
  41 +void
  42 +test_str_funcs(void)
  43 +{
  44 + assert_template_format("$(ipv4-to-int $SOURCEIP)", "168496141");
  45 +
  46 + assert_template_format("$(length $HOST $PID)", "5 5");
  47 + assert_template_format("$(length $HOST)", "5");
  48 + assert_template_format("$(length)", "");
  49 +
  50 + assert_template_format("$(substr $HOST 1 3)", "zor");
  51 + assert_template_format("$(substr $HOST 1)", "zorp");
  52 + assert_template_format("$(substr $HOST -1)", "p");
  53 + assert_template_format("$(substr $HOST -2 1)", "r");
  54 +
  55 + assert_template_format("$(strip ${APP.STRIP1})", "value");
  56 + assert_template_format("$(strip ${APP.STRIP2})", "value");
  57 + assert_template_format("$(strip ${APP.STRIP3})", "value");
  58 + assert_template_format("$(strip ${APP.STRIP4})", "value");
  59 + assert_template_format("$(strip ${APP.STRIP5})", "");
  60 +
  61 + assert_template_format("$(strip ${APP.STRIP1} ${APP.STRIP2} ${APP.STRIP3} ${APP.STRIP4} ${APP.STRIP5})", "value value value value ");
  62 +
  63 + assert_template_format("$(sanitize alma/bela)", "alma_bela");
  64 + assert_template_format("$(sanitize -r @ alma/bela)", "alma@bela");
  65 + assert_template_format("$(sanitize -i @ alma@bela)", "alma_bela");
  66 + assert_template_format("$(sanitize -i '@/l ' alma@/bela)", "a_ma__be_a");
  67 + assert_template_format("$(sanitize alma\x1b_bela)", "alma__bela");
  68 + assert_template_format("$(sanitize -C alma\x1b_bela)", "alma\x1b_bela");
  69 +
  70 + assert_template_format("$(sanitize $HOST $PROGRAM)", "bzorp/syslog-ng");
  71 +}
  72 +
  73 +void
  74 +test_numeric_funcs(void)
  75 +{
  76 + assert_template_format("$(+ $FACILITY_NUM 1)", "20");
  77 + assert_template_format("$(+ -1 -1)", "-2");
  78 + assert_template_format("$(- $FACILITY_NUM 1)", "18");
  79 + assert_template_format("$(- $FACILITY_NUM 20)", "-1");
  80 + assert_template_format("$(* $FACILITY_NUM 2)", "38");
  81 + assert_template_format("$(/ $FACILITY_NUM 2)", "9");
  82 + assert_template_format("$(% $FACILITY_NUM 3)", "1");
  83 + assert_template_format("$(/ $FACILITY_NUM 0)", "NaN");
  84 + assert_template_format("$(% $FACILITY_NUM 0)", "NaN");
  85 + assert_template_format("$(+ foo bar)", "NaN");
  86 +}
  87 +
  88 +int
  89 +main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
  90 +{
  91 + app_startup();
  92 + init_template_tests();
  93 + plugin_load_module("basicfuncs", configuration, NULL);
  94 +
  95 + test_cond_funcs();
  96 +
  97 + deinit_template_tests();
  98 + app_shutdown();
  99 +}
10 modules/cryptofuncs/Makefile.am
... ... @@ -0,0 +1,10 @@
  1 +SUBDIRS = tests
  2 +moduledir = @moduledir@
  3 +export top_srcdir
  4 +
  5 +AM_CPPFLAGS = -I$(top_srcdir)/lib -I../../lib
  6 +module_LTLIBRARIES = libcryptofuncs.la
  7 +
  8 +libcryptofuncs_la_SOURCES = cryptofuncs.c
  9 +libcryptofuncs_la_LIBADD = $(MODULE_DEPS_LIBS) ../../lib/libsyslog-ng-crypto.la $(OPENSSL_LIBS)
  10 +libcryptofuncs_la_LDFLAGS = $(MODULE_LDFLAGS) $(OPENSSL_CFLAGS)
176 modules/cryptofuncs/cryptofuncs.c
... ... @@ -0,0 +1,176 @@
  1 +/*
  2 + * Copyright (c) 2012 BalaBit IT Ltd, Budapest, Hungary
  3 + * Copyright (c) 2012 Gergely Nagy <algernon@balabit.hu>,
  4 + * Peter Gyongyosi <gyp@balabit.hu>
  5 + *
  6 + * This program is free software; you can redistribute it and/or modify it
  7 + * under the terms of the GNU General Public License version 2 as published
  8 + * by the Free Software Foundation, or (at your option) any later version.
  9 + *
  10 + * This library is distributed in the hope that it will be useful,
  11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13 + * Lesser General Public License for more details.
  14 + *
  15 + * You should have received a copy of the GNU Lesser General Public
  16 + * License along with this library; if not, write to the Free Software
  17 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18 + */
  19 +
  20 +#include "plugin.h"
  21 +#include "templates.h"
  22 +#include "cfg.h"
  23 +#include "uuid.h"
  24 +#include "misc.h"
  25 +#include "config.h"
  26 +
  27 +#if ENABLE_SSL
  28 +#include <openssl/evp.h>
  29 +#endif
  30 +
  31 +static void
  32 +tf_uuid(LogMessage *msg, gint argc, GString *argv[], GString *result)
  33 +{
  34 + char uuid_str[37];
  35 +
  36 + uuid_gen_random(uuid_str, sizeof(uuid_str));
  37 + g_string_append (result, uuid_str);
  38 +}
  39 +
  40 +TEMPLATE_FUNCTION_SIMPLE(tf_uuid);
  41 +
  42 +#if ENABLE_SSL
  43 +/*
  44 + * $($hash_method [opts] $arg1 $arg2 $arg3...)
  45 + *
  46 + * Returns the hash of the argument, using the specified hashing
  47 + * method. Note that the values of the arguments are simply concatenated
  48 + * when calculating the hash.
  49 + *
  50 + * Options:
  51 + * --length N, -l N Truncate the hash to the first N characters
  52 + */
  53 +typedef struct _TFHashState
  54 +{
  55 + TFSimpleFuncState super;
  56 + gint length;
  57 + const EVP_MD *md;
  58 +} TFHashState;
  59 +
  60 +static gboolean
  61 +tf_hash_prepare(LogTemplateFunction *self, gpointer s, LogTemplate *parent, gint argc, gchar *argv[], GError **error)
  62 +{
  63 + TFHashState *state = (TFHashState *) s;
  64 + GOptionContext *ctx;
  65 + gint length = 0;
  66 + const EVP_MD *md;
  67 + GOptionEntry hash_options[] = {
  68 + { "length", 'l', 0, G_OPTION_ARG_INT, &length, NULL, NULL },
  69 + { NULL }
  70 + };
  71 +
  72 + ctx = g_option_context_new("hash");
  73 + g_option_context_add_main_entries(ctx, hash_options, NULL);
  74 +
  75 + if (!g_option_context_parse(ctx, &argc, &argv, error))
  76 + {
  77 + g_option_context_free(ctx);
  78 + return FALSE;
  79 + }
  80 + g_option_context_free(ctx);
  81 +
  82 + if (argc < 2)
  83 + {
  84 + g_set_error(error, LOG_TEMPLATE_ERROR, LOG_TEMPLATE_ERROR_COMPILE, "$(hash) parsing failed, invalid number of arguments");
  85 + return FALSE;
  86 + }
  87 +
  88 + if (!tf_simple_func_prepare(self, state, parent, argc, argv, error))
  89 + {
  90 + g_free(state);
  91 + return FALSE;
  92 + }
  93 + state->length = length;
  94 + md = EVP_get_digestbyname(strcmp(argv[0], "hash") == 0 ? "md5" : argv[0]);
  95 + if (!md)
  96 + {
  97 + g_set_error(error, LOG_TEMPLATE_ERROR, LOG_TEMPLATE_ERROR_COMPILE, "$(hash) parsing failed, unknown digest type");
  98 + return FALSE;
  99 + }
  100 + state->md = md;
  101 + if (state->length == 0)
  102 + state->length = md->md_size * 2;
  103 + return TRUE;
  104 +}
  105 +
  106 +static void
  107 +tf_hash_call(LogTemplateFunction *self, gpointer s, const LogTemplateInvokeArgs *args, GString *result)
  108 +{
  109 + TFHashState *state = (TFHashState *) s;
  110 + GString **argv;
  111 + gint argc;
  112 + gint i;
  113 + EVP_MD_CTX mdctx;
  114 + guchar hash[EVP_MAX_MD_SIZE];
  115 + gchar hash_str[EVP_MAX_MD_SIZE * 2 + 1];
  116 + guint md_len;
  117 +
  118 + argv = (GString **) args->bufs->pdata;
  119 + argc = args->bufs->len;
  120 +
  121 + EVP_MD_CTX_init(&mdctx);
  122 + EVP_DigestInit_ex(&mdctx, state->md, NULL);
  123 +
  124 + for (i = 0; i < argc; i++)
  125 + {
  126 + EVP_DigestUpdate(&mdctx, argv[i]->str, argv[i]->len);
  127 + }
  128 + EVP_DigestFinal_ex(&mdctx, hash, &md_len);
  129 + EVP_MD_CTX_cleanup(&mdctx);
  130 +
  131 + // we fetch the entire hash in a hex format otherwise we cannot truncate at
  132 + // odd character numbers
  133 + format_hex_string(hash, md_len, hash_str, sizeof(hash_str));
  134 + if (state->length == 0)
  135 + {
  136 + g_string_append(result, hash_str);
  137 + }
  138 + else
  139 + {
  140 + g_string_append_len(result, hash_str, MIN(sizeof(hash_str), state->length));
  141 + }
  142 +}
  143 +
  144 +TEMPLATE_FUNCTION(TFHashState, tf_hash, tf_hash_prepare, tf_simple_func_eval, tf_hash_call, tf_simple_func_free_state, NULL);
  145 +
  146 +#endif
  147 +
  148 +static Plugin cryptofuncs_plugins[] =
  149 +{
  150 + TEMPLATE_FUNCTION_PLUGIN(tf_uuid, "uuid"),
  151 +#if ENABLE_SSL
  152 + TEMPLATE_FUNCTION_PLUGIN(tf_hash, "hash"),
  153 + TEMPLATE_FUNCTION_PLUGIN(tf_hash, "sha1"),
  154 + TEMPLATE_FUNCTION_PLUGIN(tf_hash, "sha256"),
  155 + TEMPLATE_FUNCTION_PLUGIN(tf_hash, "sha512"),
  156 + TEMPLATE_FUNCTION_PLUGIN(tf_hash, "md4"),
  157 + TEMPLATE_FUNCTION_PLUGIN(tf_hash, "md5"),
  158 +#endif
  159 +};
  160 +
  161 +gboolean
  162 +cryptofuncs_module_init(GlobalConfig *cfg, CfgArgs *args)
  163 +{
  164 + plugin_register(cfg, cryptofuncs_plugins, G_N_ELEMENTS(cryptofuncs_plugins));
  165 + return TRUE;
  166 +}
  167 +
  168 +const ModuleInfo module_info =
  169 +{
  170 + .canonical_name = "cryptofuncs",
  171 + .version = VERSION,
  172 + .description = "The cryptofuncs module provides cryptographic template functions.",
  173 + .core_revision = SOURCE_REVISION,
  174 + .plugins = cryptofuncs_plugins,
  175 + .plugins_len = G_N_ELEMENTS(cryptofuncs_plugins),
  176 +};
6 modules/cryptofuncs/tests/Makefile.am
... ... @@ -0,0 +1,6 @@
  1 +AM_CFLAGS = -I$(top_srcdir)/lib -I../../../lib -I$(top_srcdir)/libtest -I../../../libtest -I$(top_srcdir)/modules/cryptofuncs -I..
  2 +AM_LDFLAGS = -dlpreopen ../../syslogformat/libsyslogformat.la -dlpreopen ../libcryptofuncs.la
  3 +LDADD = $(top_builddir)/lib/libsyslog-ng.la $(top_builddir)/libtest/libsyslog-ng-test.a @TOOL_DEPS_LIBS@
  4 +
  5 +check_PROGRAMS = test_cryptofuncs
  6 +TESTS = $(check_PROGRAMS)
39 modules/cryptofuncs/tests/test_cryptofuncs.c
... ... @@ -0,0 +1,39 @@
  1 +#include "template_lib.h"
  2 +#include "apphook.h"
  3 +#include "plugin.h"
  4 +
  5 +void
  6 +test_hash(void)
  7 +{
  8 +#if ENABLE_SSL
  9 + assert_template_format("$(sha1 foo)", "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33");
  10 + assert_template_format("$(sha1 bar)", "62cdb7020ff920e5aa642c3d4066950dd1f01f4d");
  11 + assert_template_format("$(md5 foo)", "acbd18db4cc2f85cedef654fccc4a4d8");
  12 + assert_template_format("$(hash foo)", "acbd18db4cc2f85cedef654fccc4a4d8");
  13 + assert_template_format("$(md4 foo)", "0ac6700c491d70fb8650940b1ca1e4b2");
  14 + assert_template_format("$(sha256 foo)", "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae");
  15 + assert_template_format("$(sha512 foo)", "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7");
  16 + assert_template_failure("$(sha1)", "$(hash) parsing failed, invalid number of arguments");
  17 + assert_template_format("$(sha1 --length 5 foo)", "0beec");
  18 + assert_template_format("$(sha1 -l 5 foo)", "0beec");
  19 + assert_template_failure("$(sha1 --length 5)", "$(hash) parsing failed, invalid number of arguments");
  20 + assert_template_failure("$(sha1 --length invalid_length_specification foo)", "Cannot parse integer value 'invalid_length_specification' for --length");
  21 + assert_template_format("$(sha1 --length 99999 foo)", "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33");
  22 + assert_template_format("$(sha1 foo bar)", "8843d7f92416211de9ebb963ff4ce28125932878");
  23 + assert_template_format("$(sha1 \"foo bar\")", "3773dea65156909838fa6c22825cafe090ff8030");
  24 + assert_template_format("$(md5 $(sha1 foo) bar)", "196894290a831b2d2755c8de22619a97");
  25 +#endif
  26 +}
  27 +
  28 +int
  29 +main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
  30 +{
  31 + app_startup();
  32 + init_template_tests();
  33 + plugin_load_module("cryptofuncs", configuration, NULL);
  34 +
  35 + test_hash();
  36 +
  37 + deinit_template_tests();
  38 + app_shutdown();
  39 +}
2  modules/tfjson/Makefile.am
... ... @@ -1,3 +1,5 @@
  1 +SUBDIRS = tests
  2 +
1 3 moduledir = @moduledir@
2 4 export top_srcdir
3 5
6 modules/tfjson/tests/Makefile.am
... ... @@ -0,0 +1,6 @@
  1 +AM_CFLAGS = -I$(top_srcdir)/lib -I../../../lib -I$(top_srcdir)/libtest -I../../../libtest -I$(top_srcdir)/modules/tfjson -I..
  2 +AM_LDFLAGS = -dlpreopen ../../syslogformat/libsyslogformat.la -dlpreopen ../libtfjson.la
  3 +LDADD = $(top_builddir)/lib/libsyslog-ng.la $(top_builddir)/libtest/libsyslog-ng-test.a @TOOL_DEPS_LIBS@
  4 +
  5 +check_PROGRAMS = test_json
  6 +TESTS = $(check_PROGRAMS)
24 modules/tfjson/tests/test_json.c
... ... @@ -0,0 +1,24 @@
  1 +#include "template_lib.h"
  2 +#include "apphook.h"
  3 +#include "plugin.h"
  4 +
  5 +void
  6 +test_format_json(void)
  7 +{
  8 + assert_template_format("$(format-json MSG=$MSG)", "{\"MSG\":\"árvíztűrőtükörfúrógép\"}");
  9 + assert_template_format_with_context("$(format-json MSG=$MSG)", "{\"MSG\":\"árvíztűrőtükörfúrógép\"}{\"MSG\":\"árvíztűrőtükörfúrógép\"}");
  10 + assert_template_format("$(format-json --scope rfc3164)", "{\"DATE\":\"Feb 11 19:58:35\",\"FACILITY\":\"local3\",\"HOST\":\"bzorp\",\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"PID\":\"23323\",\"PRIORITY\":\"err\",\"PROGRAM\":\"syslog-ng\"}");
  11 +}
  12 +
  13 +int
  14 +main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
  15 +{
  16 + app_startup();
  17 + init_template_tests();
  18 + plugin_load_module("tfjson", configuration, NULL);
  19 +
  20 + test_format_json();
  21 +
  22 + deinit_template_tests();
  23 + app_shutdown();
  24 +}
9 modules/tfuuid/Makefile.am
... ... @@ -1,9 +0,0 @@
1   -moduledir = @moduledir@
2   -export top_srcdir
3   -
4   -AM_CPPFLAGS = -I$(top_srcdir)/lib -I../../lib
5   -module_LTLIBRARIES = libtfuuid.la
6   -
7   -libtfuuid_la_SOURCES = tfuuid.c
8   -libtfuuid_la_LIBADD = $(MODULE_DEPS_LIBS) ../../lib/libsyslog-ng-crypto.la
9   -libtfuuid_la_LDFLAGS = $(MODULE_LDFLAGS)
57 modules/tfuuid/tfuuid.c
... ... @@ -1,57 +0,0 @@
1   -/*
2   - * Copyright (c) 2012 BalaBit IT Ltd, Budapest, Hungary
3   - * Copyright (c) 2012 Gergely Nagy <algernon@balabit.hu>
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 library 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 GNU
12   - * Lesser General Public License for more details.
13   - *
14   - * You should have received a copy of the GNU Lesser General Public
15   - * License along with this library; if not, write to the Free Software
16   - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17   - */
18   -
19   -#include "plugin.h"
20   -#include "templates.h"
21   -#include "cfg.h"
22   -#include "uuid.h"
23   -
24   -#include "config.h"
25   -
26   -static void
27   -tf_uuid(LogMessage *msg, gint argc, GString *argv[], GString *result)
28   -{
29   - char uuid_str[37];
30   -
31   - uuid_gen_random(uuid_str, sizeof(uuid_str));
32   - g_string_append (result, uuid_str);
33   -}
34   -
35   -TEMPLATE_FUNCTION_SIMPLE(tf_uuid);
36   -
37   -static Plugin tfuuid_plugins[] =
38   - {
39   - TEMPLATE_FUNCTION_PLUGIN(tf_uuid, "uuid"),
40   - };
41   -
42   -gboolean
43   -tfuuid_module_init(GlobalConfig *cfg, CfgArgs *args)
44   -{
45   - plugin_register(cfg, tfuuid_plugins, G_N_ELEMENTS(tfuuid_plugins));
46   - return TRUE;
47   -}
48   -
49   -const ModuleInfo module_info =
50   -{
51   - .canonical_name = "tfuuid",
52   - .version = VERSION,
53   - .description = "The tfuuid module provides a template function to generate UUIDs.",
54   - .core_revision = SOURCE_REVISION,
55   - .plugins = tfuuid_plugins,
56   - .plugins_len = G_N_ELEMENTS(tfuuid_plugins),
57   -};
527 tests/unit/test_template.c
... ... @@ -1,3 +1,5 @@
  1 +#include "template_lib.h"
  2 +
1 3 #include "syslog-ng.h"
2 4 #include "logmsg.h"
3 5 #include "templates.h"
@@ -12,67 +14,6 @@
12 14 #include <stdio.h>
13 15 #include <string.h>
14 16
15   -gboolean success = TRUE;
16   -gboolean verbose = FALSE;
17   -MsgFormatOptions parse_options;
18   -
19   -void
20   -testcase(LogMessage *msg, gchar *template, gchar *expected)
21   -{
22   - LogTemplate *templ;
23   - GString *res = g_string_sized_new(128);
24   - GError *error = NULL;
25   - LogMessage *context[2] = { msg, msg };
26   - const gchar *context_id = "test-context-id";
27   -
28   - templ = log_template_new(configuration, "dummy");
29   - if (!log_template_compile(templ, template, &error))
30   - {
31   - fprintf(stderr, "FAIL: error compiling template, template=%s, error=%s\n", template, error->message);
32   - g_clear_error(&error);
33   - success = FALSE;
34   - goto error;
35   - }
36   - log_template_format_with_context(templ, context, 2, NULL, LTZ_LOCAL, 999, context_id, res);
37   -
38   - if (strcmp(res->str, expected) != 0)
39   - {
40   - fprintf(stderr, "FAIL: template test failed, template=%s, [%s] <=> [%s]\n", template, res->str, expected);
41   - success = FALSE;
42   - }
43   - else if (verbose)
44   - {
45   - fprintf(stderr, "PASS: template test success, template=%s => %s\n", template, expected);
46   - }
47   - error:
48   - log_template_unref(templ);
49   - g_string_free(res, TRUE);
50   -}
51   -
52   -void
53   -testcase_failure(gchar *template, const gchar *expected_error)
54   -{
55   - LogTemplate *templ;
56   - GError *error = NULL;
57   -
58   - templ = log_template_new(configuration, NULL);
59   - if (log_template_compile(templ, template, &error))
60   - {
61   - fprintf(stderr, "FAIL: compilation failure expected to template, but success was returned, template=%s, expected_error=%s\n", template, expected_error);
62   - success = FALSE;
63   - goto error;
64   - }
65   - if (strstr(error->message, expected_error) == NULL)
66   - {
67   - fprintf(stderr, "FAIL: compilation error doesn't match, error=%s, expected_error=%s\n", error->message, expected_error);
68   - success = FALSE;
69   - goto error;
70   - }
71   - g_clear_error(&error);
72   - error:
73   - log_template_unref(templ);
74   -}
75   -
76 17 GCond *thread_ping;
77 18 GMutex *thread_lock;
78 19 gboolean thread_start;
@@ -96,34 +37,26 @@ format_template_thread(gpointer s)
96 37 for (i = 0; i < 10000; i++)
97 38 {
98 39 log_template_format(templ, msg, NULL, LTZ_SEND, 5555, NULL, result);
99   - if (strcmp(result->str, expected) != 0)
100   - {
101   - fprintf(stderr, "FAIL: multi-threaded formatting yielded invalid result (iteration: %d): %s, expected=%s\n", i, result->str, expected);
102   - success = FALSE;
103   - break;
104   - }
  40 + assert_string(result->str, expected, "multi-threaded formatting yielded invalid result (iteration: %d)", i);
105 41 }
106 42 g_string_free(result, TRUE);
107 43 return NULL;
108 44 }
109 45
110   -void
111   -testcase_multi_thread(LogMessage *msg, gchar *template, const gchar *expected)
  46 +static void
  47 +assert_template_format_multi_thread(const gchar *template, const gchar *expected)
112 48 {
113 49 LogTemplate *templ;
114   - gpointer args[] = { msg, NULL, (gpointer) expected };
115   - GError *error = NULL;
  50 + LogMessage *msg;
  51 + gpointer args[3];
116 52 GThread *threads[16];
117 53 gint i;
118 54
119   - templ = log_template_new(configuration, NULL);
120   - if (!log_template_compile(templ, template, &error))
121   - {
122   - fprintf(stderr, "FAIL: error compiling template, template=%s, error=%s\n", template, error->message);
123   - success = FALSE;
124   - g_clear_error(&error);
125   - goto error;
126   - }
  55 + msg = create_sample_message();
  56 + templ = compile_template(template);
  57 + args[0] = msg;
  58 + args[1] = templ;
  59 + args[2] = (gpointer) expected;
127 60
128 61 thread_start = FALSE;
129 62 thread_ping = g_cond_new();
@@ -144,294 +77,204 @@ testcase_multi_thread(LogMessage *msg, gchar *template, const gchar *expected)
144 77 }
145 78 g_cond_free(thread_ping);
146 79 g_mutex_free(thread_lock);
147   -
148   - error:
149   - ;
  80 + log_template_unref(templ);
  81 + log_msg_unref(msg);
150 82 }
151 83
152   -int
153   -main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
  84 +static void
  85 +test_macros(void)
154 86 {
155   - LogMessage *msg;
156   - char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]:árvíztűrőtükörfúrógép";
157   - GSockAddr *saddr;
158   -
159   - if (argc > 1)
160   - verbose = TRUE;
161   -
162   - app_startup();
163   -
164   - configuration = cfg_new(0x0302);
165   - plugin_load_module("syslogformat", configuration, NULL);
166   - plugin_load_module("basicfuncs", configuration, NULL);
167   - msg_format_options_defaults(&parse_options);
168   - msg_format_options_init(&parse_options, configuration);
169   - configuration->template_options.frac_digits = 3;
170   - configuration->template_options.time_zone_info[LTZ_LOCAL] = time_zone_info_new(NULL);
171   -
172   -
173   - putenv("TZ=MET-1METDST");
174   - tzset();
175   -
176   - saddr = g_sockaddr_inet_new("10.11.12.13", 1010);
177   - msg = log_msg_new(msg_str, strlen(msg_str), saddr, &parse_options);
178   - log_msg_set_value(msg, log_msg_get_value_handle("APP.VALUE"), "value", -1);
179   - log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP1"), " value", -1);
180   - log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP2"), "value ", -1);
181   - log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP3"), " value ", -1);
182   - log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP4"), "value", -1);
183   - log_msg_set_value(msg, log_msg_get_value_handle("APP.STRIP5"), "", -1);
184   - log_msg_set_match(msg, 0, "whole-match", -1);
185   - log_msg_set_match(msg, 1, "first-match", -1);
186   - log_msg_set_tag_by_name(msg, "alma");
187   - log_msg_set_tag_by_name(msg, "korte");
188   - log_msg_clear_tag_by_name(msg, "narancs");
189   - log_msg_set_tag_by_name(msg, "citrom");
190   -
191   - /* fix some externally or automatically defined values */
192   - log_msg_set_value(msg, LM_V_HOST_FROM, "kismacska", -1);
193   - msg->timestamps[LM_TS_RECVD].tv_sec = 1139684315;
194   - msg->timestamps[LM_TS_RECVD].tv_usec = 639000;
195   - msg->timestamps[LM_TS_RECVD].zone_offset = get_local_timezone_ofs(1139684315);
196   -
197 87 /* pri 3, fac 19 == local3 */
198 88
199   - testcase(msg, "$FACILITY", "local3");
200   - testcase(msg, "$FACILITY_NUM", "19");
201   - testcase(msg, "$PRIORITY", "err");
202   - testcase(msg, "$LEVEL", "err");
203   - testcase(msg, "$LEVEL_NUM", "3");
204   - testcase(msg, "$TAG", "9b");
205   - testcase(msg, "$TAGS", "alma,korte,citrom");
206   - testcase(msg, "$PRI", "155");
207   - testcase(msg, "$DATE", "Feb 11 10:34:56.000");
208   - testcase(msg, "$FULLDATE", "2006 Feb 11 10:34:56.000");
209   - testcase(msg, "$ISODATE", "2006-02-11T10:34:56.000+01:00");
210   - testcase(msg, "$STAMP", "Feb 11 10:34:56.000");
211   - testcase(msg, "$YEAR", "2006");
212   - testcase(msg, "$YEAR_DAY", "042");
213   - testcase(msg, "$MONTH", "02");
214   - testcase(msg, "$MONTH_WEEK", "1");
215   - testcase(msg, "$MONTH_ABBREV", "Feb");
216   - testcase(msg, "$MONTH_NAME", "February");
217   - testcase(msg, "$DAY", "11");
218   - testcase(msg, "$HOUR", "10");
219   - testcase(msg, "$MIN", "34");
220   - testcase(msg, "$SEC", "56");
221   - testcase(msg, "$WEEKDAY", "Sat");
222   - testcase(msg, "$WEEK_DAY", "7");
223   - testcase(msg, "$WEEK_DAY_NAME", "Saturday");
224   - testcase(msg, "$WEEK_DAY_ABBREV", "Sat");
225   - testcase(msg, "$WEEK", "06");
226   - testcase(msg, "$UNIXTIME", "1139650496.000");
227   - testcase(msg, "$TZOFFSET", "+01:00");
228   - testcase(msg, "$TZ", "+01:00");
229   - testcase(msg, "$R_DATE", "Feb 11 19:58:35.639");
230   - testcase(msg, "$R_FULLDATE", "2006 Feb 11 19:58:35.639");
231   - testcase(msg, "$R_ISODATE", "2006-02-11T19:58:35.639+01:00");
232   - testcase(msg, "$R_STAMP", "Feb 11 19:58:35.639");
233   - testcase(msg, "$R_YEAR", "2006");
234   - testcase(msg, "$R_YEAR_DAY", "042");
235   - testcase(msg, "$R_MONTH", "02");
236   - testcase(msg, "$R_MONTH_WEEK", "1");
237   - testcase(msg, "$R_MONTH_ABBREV", "Feb");
238   - testcase(msg, "$R_MONTH_NAME", "February");
239   - testcase(msg, "$R_DAY", "11");
240   - testcase(msg, "$R_HOUR", "19");
241   - testcase(msg, "$R_MIN", "58");
242   - testcase(msg, "$R_SEC", "35");
243   - testcase(msg, "$R_WEEKDAY", "Sat");
244   - testcase(msg, "$R_WEEK_DAY", "7");
245   - testcase(msg, "$R_WEEK_DAY_NAME", "Saturday");
246   - testcase(msg, "$R_WEEK_DAY_ABBREV", "Sat");
247   - testcase(msg, "$R_WEEK", "06");
248   - testcase(msg, "$R_UNIXTIME", "1139684315.639");
249   - testcase(msg, "$R_TZOFFSET", "+01:00");
250   - testcase(msg, "$R_TZ", "+01:00");
251   - testcase(msg, "$S_DATE", "Feb 11 10:34:56.000");
252   - testcase(msg, "$S_FULLDATE", "2006 Feb 11 10:34:56.000");
253   - testcase(msg, "$S_ISODATE", "2006-02-11T10:34:56.000+01:00");
254   - testcase(msg, "$S_STAMP", "Feb 11 10:34:56.000");
255   - testcase(msg, "$S_YEAR", "2006");
256   - testcase(msg, "$S_YEAR_DAY", "042");
257   - testcase(msg, "$S_MONTH", "02");
258   - testcase(msg, "$S_MONTH_WEEK", "1");
259   - testcase(msg, "$S_MONTH_ABBREV", "Feb");
260   - testcase(msg, "$S_MONTH_NAME", "February");
261   - testcase(msg, "$S_DAY", "11");
262   - testcase(msg, "$S_HOUR", "10");
263   - testcase(msg, "$S_MIN", "34");
264   - testcase(msg, "$S_SEC", "56");
265   - testcase(msg, "$S_WEEKDAY", "Sat");
266   - testcase(msg, "$S_WEEK_DAY", "7");
267   - testcase(msg, "$S_WEEK_DAY_NAME", "Saturday");
268   - testcase(msg, "$S_WEEK_DAY_ABBREV", "Sat");
269   - testcase(msg, "$S_WEEK", "06");
270   - testcase(msg, "$S_UNIXTIME", "1139650496.000");
271   - testcase(msg, "$S_TZOFFSET", "+01:00");
272   - testcase(msg, "$S_TZ", "+01:00");
273   - testcase(msg, "$HOST_FROM", "kismacska");
274   - testcase(msg, "$FULLHOST_FROM", "kismacska");
275   - testcase(msg, "$HOST", "bzorp");
276   - testcase(msg, "$FULLHOST", "bzorp");
277   - testcase(msg, "$PROGRAM", "syslog-ng");
278   - testcase(msg, "$PID", "23323");
279   - testcase(msg, "$MSGHDR", "syslog-ng[23323]:");
280   - testcase(msg, "$MSG", "árvíztűrőtükörfúrógép");
281   - testcase(msg, "$MESSAGE", "árvíztűrőtükörfúrógép");
282   - testcase(msg, "$SOURCEIP", "10.11.12.13");
283   - testcase(msg, "$PROGRAM/var/log/messages/$HOST/$HOST_FROM/$MONTH$DAY${QQQQQ}valami", "syslog-ng/var/log/messages/bzorp/kismacska/0211valami");
284   - testcase(msg, "${APP.VALUE}", "value");
285   - testcase(msg, "${APP.VALUE:-ures}", "value");
286   - testcase(msg, "${APP.VALUE2:-ures}", "ures");
287   - testcase(msg, "${1}", "first-match");
288   - testcase(msg, "$1", "first-match");
289   - testcase(msg, "$$$1$$", "$first-match$");
  89 + assert_template_format("$FACILITY", "local3");
  90 + assert_template_format("$FACILITY_NUM", "19");
  91 + assert_template_format("$PRIORITY", "err");
  92 + assert_template_format("$LEVEL", "err");
  93 + assert_template_format("$LEVEL_NUM", "3");
  94 + assert_template_format("$TAG", "9b");
  95 + assert_template_format("$TAGS", "alma,korte,citrom");
  96 + assert_template_format("$PRI", "155");
  97 + assert_template_format("$DATE", "Feb 11 10:34:56.000");
  98 + assert_template_format("$FULLDATE", "2006 Feb 11 10:34:56.000");
  99 + assert_template_format("$ISODATE", "2006-02-11T10:34:56.000+01:00");
  100 + assert_template_format("$STAMP", "Feb 11 10:34:56.000");
  101 + assert_template_format("$YEAR", "2006");
  102 + assert_template_format("$YEAR_DAY", "042");
  103 + assert_template_format("$MONTH", "02");
  104 + assert_template_format("$MONTH_WEEK", "1");
  105 + assert_template_format("$MONTH_ABBREV", "Feb");
  106 + assert_template_format("$MONTH_NAME", "February");
  107 + assert_template_format("$DAY", "11");
  108 + assert_template_format("$HOUR", "10");
  109 + assert_template_format("$MIN", "34");
  110 + assert_template_format("$SEC", "56");
  111 + assert_template_format("$WEEKDAY", "Sat");
  112 + assert_template_format("$WEEK_DAY", "7");
  113 + assert_template_format("$WEEK_DAY_NAME", "Saturday");
  114 + assert_template_format("$WEEK_DAY_ABBREV", "Sat");
  115 + assert_template_format("$WEEK", "06");
  116 + assert_template_format("$UNIXTIME", "1139650496.000");
  117 + assert_template_format("$TZOFFSET", "+01:00");
  118 + assert_template_format("$TZ", "+01:00");
  119 + assert_template_format("$R_DATE", "Feb 11 19:58:35.639");
  120 + assert_template_format("$R_FULLDATE", "2006 Feb 11 19:58:35.639");
  121 + assert_template_format("$R_ISODATE", "2006-02-11T19:58:35.639+01:00");
  122 + assert_template_format("$R_STAMP", "Feb 11 19:58:35.639");
  123 + assert_template_format("$R_YEAR", "2006");
  124 + assert_template_format("$R_YEAR_DAY", "042");
  125 + assert_template_format("$R_MONTH", "02");
  126 + assert_template_format("$R_MONTH_WEEK", "1");
  127 + assert_template_format("$R_MONTH_ABBREV", "Feb");
  128 + assert_template_format("$R_MONTH_NAME", "February");
  129 + assert_template_format("$R_DAY", "11");
  130 + assert_template_format("$R_HOUR", "19");
  131 + assert_template_format("$R_MIN", "58");
  132 + assert_template_format("$R_SEC", "35");
  133 + assert_template_format("$R_WEEKDAY", "Sat");
  134 + assert_template_format("$R_WEEK_DAY", "7");
  135 + assert_template_format("$R_WEEK_DAY_NAME", "Saturday");
  136 + assert_template_format("$R_WEEK_DAY_ABBREV", "Sat");
  137 + assert_template_format("$R_WEEK", "06");
  138 + assert_template_format("$R_UNIXTIME", "1139684315.639");
  139 + assert_template_format("$R_TZOFFSET", "+01:00");
  140 + assert_template_format("$R_TZ", "+01:00");
  141 + assert_template_format("$S_DATE", "Feb 11 10:34:56.000");
  142 + assert_template_format("$S_FULLDATE", "2006 Feb 11 10:34:56.000");
  143 + assert_template_format("$S_ISODATE", "2006-02-11T10:34:56.000+01:00");
  144 + assert_template_format("$S_STAMP", "Feb 11 10:34:56.000");
  145 + assert_template_format("$S_YEAR", "2006");
  146 + assert_template_format("$S_YEAR_DAY", "042");
  147 + assert_template_format("$S_MONTH", "02");
  148 + assert_template_format("$S_MONTH_WEEK", "1");
  149 + assert_template_format("$S_MONTH_ABBREV", "Feb");
  150 + assert_template_format("$S_MONTH_NAME", "February");
  151 + assert_template_format("$S_DAY", "11");
  152 + assert_template_format("$S_HOUR", "10");
  153 + assert_template_format("$S_MIN", "34");
  154 + assert_template_format("$S_SEC", "56");
  155 + assert_template_format("$S_WEEKDAY", "Sat");
  156 + assert_template_format("$S_WEEK_DAY", "7");
  157 + assert_template_format("$S_WEEK_DAY_NAME", "Saturday");
  158 + assert_template_format("$S_WEEK_DAY_ABBREV", "Sat");
  159 + assert_template_format("$S_WEEK", "06");
  160 + assert_template_format("$S_UNIXTIME", "1139650496.000");
  161 + assert_template_format("$S_TZOFFSET", "+01:00");
  162 + assert_template_format("$S_TZ", "+01:00");
  163 + assert_template_format("$HOST_FROM", "kismacska");
  164 + assert_template_format("$FULLHOST_FROM", "kismacska");
  165 + assert_template_format("$HOST", "bzorp");
  166 + assert_template_format("$FULLHOST", "bzorp");
  167 + assert_template_format("$PROGRAM", "syslog-ng");
  168 + assert_template_format("$PID", "23323");
  169 + assert_template_format("$MSGHDR", "syslog-ng[23323]:");
  170 + assert_template_format("$MSG", "árvíztűrőtükörfúrógép");
  171 + assert_template_format("$MESSAGE", "árvíztűrőtükörfúrógép");
  172 + assert_template_format("$SOURCEIP", "10.11.12.13");
  173 +
  174 + assert_template_format("$SEQNUM", "999");
  175 + assert_template_format("$CONTEXT_ID", "test-context-id");
  176 +}
290 177
291   - testcase(msg, "$SEQNUM", "999");
292   - testcase(msg, "$CONTEXT_ID", "test-context-id");
  178 +static void
  179 +test_nvpairs(void)
  180 +{
  181 + assert_template_format("$PROGRAM/var/log/messages/$HOST/$HOST_FROM/$MONTH$DAY${QQQQQ}valami", "syslog-ng/var/log/messages/bzorp/kismacska/0211valami");
  182 + assert_template_format("${APP.VALUE}", "value");
  183 + assert_template_format("${APP.VALUE:-ures}", "value");
  184 + assert_template_format("${APP.VALUE2:-ures}", "ures");
  185 + assert_template_format("${1}", "first-match");
  186 + assert_template_format("$1", "first-match");
  187 + assert_template_format("$$$1$$", "$first-match$");
  188 +}
293 189
  190 +static void
  191 +test_template_functions(void)
  192 +{
294 193 /* template functions */
295   - testcase(msg, "$(echo $HOST $PID)", "bzorp 23323");
296   - testcase(msg, "$(echo \"$(echo $HOST)\" $PID)", "bzorp 23323");
297   - testcase(msg, "$(echo \"$(echo '$(echo $HOST)')\" $PID)", "bzorp 23323");
298   - testcase(msg, "$(echo \"$(echo '$(echo $HOST)')\" $PID)", "bzorp 23323");
299   - testcase(msg, "$(echo '\"$(echo $(echo $HOST))\"' $PID)", "\"bzorp\" 23323");
300   - testcase(msg, "$(ipv4-to-int $SOURCEIP)", "168496141");
301   -
302   - testcase(msg, "$(length $HOST $PID)", "5 5");
303   - testcase(msg, "$(length $HOST)", "5");
304   - testcase(msg, "$(length)", "");
305   -
306   - testcase(msg, "$(grep 'facility(local3)' $PID)", "23323,23323");
307   - testcase(msg, "$(grep -m 1 'facility(local3)' $PID)", "23323");
308   - testcase(msg, "$(grep 'facility(local3)' $PID $PROGRAM)", "23323,syslog-ng,23323,syslog-ng");
309   - testcase(msg, "$(grep 'facility(local4)' $PID)", "");
310   - testcase(msg, "$(grep ('$FACILITY' == 'local4') $PID)", "");
311   - testcase(msg, "$(grep ('$FACILITY(' == 'local3(') $PID)", "23323,23323");
312   - testcase(msg, "$(grep ('$FACILITY(' == 'local4)') $PID)", "");
313   - testcase(msg, "$(grep \\'$FACILITY\\'\\ ==\\ \\'local4\\' $PID)", "");
314   - testcase(msg, "$(if 'facility(local4)' alma korte)", "korte");
315   - testcase(msg, "$(if 'facility(local3)' alma korte)", "alma");
316   -
317   - testcase(msg, "$(if '\"$FACILITY\" lt \"local3\"' alma korte)", "korte");
318   - testcase(msg, "$(if '\"$FACILITY\" le \"local3\"' alma korte)", "alma");
319   - testcase(msg, "$(if '\"$FACILITY\" eq \"local3\"' alma korte)", "alma");
320   - testcase(msg, "$(if '\"$FACILITY\" ne \"local3\"' alma korte)", "korte");
321   - testcase(msg, "$(if '\"$FACILITY\" gt \"local3\"' alma korte)", "korte");
322   - testcase(msg, "$(if '\"$FACILITY\" ge \"local3\"' alma korte)", "alma");
323   -
324   - testcase(msg, "$(if '\"$FACILITY_NUM\" < \"19\"' alma korte)", "korte");
325   - testcase(msg, "$(if '\"$FACILITY_NUM\" <= \"19\"' alma korte)", "alma");
326   - testcase(msg, "$(if '\"$FACILITY_NUM\" == \"19\"' alma korte)", "alma");
327   - testcase(msg, "$(if '\"$FACILITY_NUM\" != \"19\"' alma korte)", "korte");
328   - testcase(msg, "$(if '\"$FACILITY_NUM\" > \"19\"' alma korte)", "korte");
329   - testcase(msg, "$(if '\"$FACILITY_NUM\" >= \"19\"' alma korte)", "alma");
330   - testcase(msg, "$(if '\"$FACILITY_NUM\" >= \"19\" and \"kicsi\" == \"nagy\"' alma korte)", "korte");
331   - testcase(msg, "$(if '\"$FACILITY_NUM\" >= \"19\" or \"kicsi\" == \"nagy\"' alma korte)", "alma");
332   -
333   - testcase(msg, "$(substr $HOST 1 3)", "zor");
334   - testcase(msg, "$(substr $HOST 1)", "zorp");
335   - testcase(msg, "$(substr $HOST -1)", "p");
336   - testcase(msg, "$(substr $HOST -2 1)", "r");
337   -
338   - testcase(msg, "$(strip ${APP.STRIP1})", "value");
339   - testcase(msg, "$(strip ${APP.STRIP2})", "value");
340   - testcase(msg, "$(strip ${APP.STRIP3})", "value");
341   - testcase(msg, "$(strip ${APP.STRIP4})", "value");
342   - testcase(msg, "$(strip ${APP.STRIP5})", "");
343   -
344   - testcase(msg, "$(strip ${APP.STRIP1} ${APP.STRIP2} ${APP.STRIP3} ${APP.STRIP4} ${APP.STRIP5})", "value value value value ");
345   -
346   - testcase(msg, "$(sanitize alma/bela)", "alma_bela");
347   - testcase(msg, "$(sanitize -r @ alma/bela)", "alma@bela");
348   - testcase(msg, "$(sanitize -i @ alma@bela)", "alma_bela");
349   - testcase(msg, "$(sanitize -i '@/l ' alma@/bela)", "a_ma__be_a");
350   - testcase(msg, "$(sanitize alma\x1b_bela)", "alma__bela");
351   - testcase(msg, "$(sanitize -C alma\x1b_bela)", "alma\x1b_bela");
352   -
353   - testcase(msg, "$(sanitize $HOST $PROGRAM)", "bzorp/syslog-ng");
354   -
355   - testcase(msg, "$(+ $FACILITY_NUM 1)", "20");
356   - testcase(msg, "$(+ -1 -1)", "-2");
357   - testcase(msg, "$(- $FACILITY_NUM 1)", "18");
358   - testcase(msg, "$(- $FACILITY_NUM 20)", "-1");
359   - testcase(msg, "$(* $FACILITY_NUM 2)", "38");
360   - testcase(msg, "$(/ $FACILITY_NUM 2)", "9");
361   - testcase(msg, "$(% $FACILITY_NUM 3)", "1");
362   - testcase(msg, "$(/ $FACILITY_NUM 0)", "NaN");
363   - testcase(msg, "$(% $FACILITY_NUM 0)", "NaN");
364   - testcase(msg, "$(+ foo bar)", "NaN");
  194 + assert_template_format("$(echo $HOST $PID)", "bzorp 23323");
  195 + assert_template_format("$(echo \"$(echo $HOST)\" $PID)", "bzorp 23323");
  196 + assert_template_format("$(echo \"$(echo '$(echo $HOST)')\" $PID)", "bzorp 23323");
  197 + assert_template_format("$(echo \"$(echo '$(echo $HOST)')\" $PID)", "bzorp 23323");
  198 + assert_template_format("$(echo '\"$(echo $(echo $HOST))\"' $PID)", "\"bzorp\" 23323");
  199 +}
365 200
  201 +static void
  202 +test_message_refs(void)
  203 +{
366 204 /* message refs */
367   - testcase(msg, "$(echo ${HOST}@0 ${PID}@1)", "bzorp 23323");
368   - testcase(msg, "$(echo $HOST $PID)@0", "bzorp 23323");
369   -
370   - testcase(msg, "$(grep 'facility(local3)' $PID)@0", "23323");
371   - testcase(msg, "$(grep 'facility(local3)' $PID)@1", "23323");
372   - testcase(msg, "$(grep 'facility(local3)' $PID)@2", "");
373   -
374   - /* multi-threaded expansion */
375   -
376   - /* name-value pair */
377   - testcase_multi_thread(msg, "alma $HOST bela", "alma bzorp bela");
378   - testcase_multi_thread(msg, "kukac $DATE mukac", "kukac Feb 11 10:34:56.000 mukac");
379   - testcase_multi_thread(msg, "dani $(echo $HOST $DATE $(echo huha)) balint", "dani bzorp Feb 11 10:34:56.000 huha balint");
380   -
  205 + assert_template_format_with_context("$(echo ${HOST}@0 ${PID}@1)", "bzorp 23323");
  206 + assert_template_format_with_context("$(echo $HOST $PID)@0", "bzorp 23323");
  207 +}
381 208
  209 +static void
  210 +test_syntax_errors(void)
  211 +{
382 212 /* template syntax errors */
383   - testcase_failure("${unbalanced_brace", "'}' is missing");
384   - testcase(msg, "$unbalanced_brace}", "}");
385   - testcase(msg, "$}", "$}");
386   - testcase_failure("$(unbalanced_paren", "missing function name or inbalanced '('");
387   - testcase(msg, "$unbalanced_paren)", ")");
  213 + assert_template_failure("${unbalanced_brace", "'}' is missing");
  214 + assert_template_format("$unbalanced_brace}", "}");
  215 + assert_template_format("$}", "$}");
  216 + assert_template_failure("$(unbalanced_paren", "missing function name or inbalanced '('");
  217 + assert_template_format("$unbalanced_paren)", ")");
  218 +}
388 219
  220 +static void
  221 +test_compat(void)
  222 +{
  223 + gint old_version;
389 224
  225 + old_version = configuration->user_version;
  226 + /* old version for various macros */
390 227 configuration->user_version = 0x0201;
391   - testcase(msg, "$MSGHDR", "syslog-ng[23323]:");
392   - testcase(msg, "$MSG", "syslog-ng[23323]:árvíztűrőtükörfúrógép");
393   - testcase(msg, "$MSGONLY", "árvíztűrőtükörfúrógép");
394   - testcase(msg, "$MESSAGE", "syslog-ng[23323]:árvíztűrőtükörfúrógép");
395   -
396   - log_msg_unref(msg);
397 228
398   - configuration->user_version = 0x0302;
  229 + start_grabbing_messages();
  230 + assert_template_format("$MSGHDR", "syslog-ng[23323]:");
  231 + assert_grabbed_messages_contain("the default value for template-escape has changed to 'no' from syslog-ng 3.0", NULL);
  232 + reset_grabbed_messages();
  233 + assert_template_format("$MSG", "syslog-ng[23323]:árvíztűrőtükörfúrógép");
  234 + assert_grabbed_messages_contain("the meaning of the $MSG/$MESSAGE macros has changed from syslog-ng 3.0", NULL);
  235 + stop_grabbing_messages();
  236 + assert_template_format("$MSGONLY", "árvíztűrőtükörfúrógép");
  237 + assert_template_format("$MESSAGE", "syslog-ng[23323]:árvíztűrőtükörfúrógép");
  238 +
  239 + configuration->user_version = old_version;
  240 +}
399 241
400   - msg_str = "syslog-ng: árvíztűrőtükörfúrógép [pid test]";
401   - msg = log_msg_new(msg_str, strlen(msg_str), saddr, &parse_options);
  242 +static void
  243 +test_multi_thread(void)
  244 +{
  245 + /* name-value pair */
  246 + assert_template_format_multi_thread("alma $HOST bela", "alma bzorp bela");
  247 + assert_template_format_multi_thread("kukac $DATE mukac", "kukac Feb 11 10:34:56.000 mukac");
  248 + assert_template_format_multi_thread("dani $(echo $HOST $DATE $(echo huha)) balint", "dani bzorp Feb 11 10:34:56.000 huha balint");
  249 +}
402 250
403   - testcase(msg, "$PID", "");
404   - log_msg_unref(msg);
  251 +int
  252 +main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
  253 +{
  254 + app_startup();
405 255
406   - msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]:árvíztűrőtükörfúrógép";
  256 + init_template_tests();
  257 + plugin_load_module("basicfuncs", configuration, NULL);
  258 + configuration->template_options.frac_digits = 3;
  259 + configuration->template_options.time_zone_info[LTZ_LOCAL] = time_zone_info_new(NULL);
407 260
408   - parse_options.flags = LP_EXPECT_HOSTNAME;
409   - msg = log_msg_new(msg_str, strlen(msg_str), saddr, &parse_options);
410 261
411   - testcase(msg, "$LEGACY_MSGHDR", "");
412   - testcase(msg, "$MSGHDR", "syslog-ng[23323]: ");
413   - log_msg_unref(msg);
  262 + putenv("TZ=MET-1METDST");
  263 + tzset();
414 264
415   - msg_str = "<132>1 2006-10-29T01:59:59.156+01:00 mymachine evntslog 3535 ID47 [exampleSDID@0 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"][examplePriority@0 class=\"high\"] BOMAn application event log entry...";
416   - parse_options.flags = LP_SYSLOG_PROTOCOL;
417   - msg = log_msg_new(msg_str, strlen(msg_str), saddr, &parse_options);
  265 + test_macros();
  266 + test_nvpairs();
  267 + test_template_functions();
  268 + test_message_refs();
  269 + test_syntax_errors();
  270 + test_compat();
  271 + test_multi_thread();
418 272
419   - testcase(msg, "$PRI", "132");
420   - testcase(msg, "$HOST", "mymachine");
421   - testcase(msg, "$PROGRAM", "evntslog");
422   - testcase(msg, "$PID", "3535");
423   - testcase(msg, "$MSGID", "ID47");
424   - testcase(msg, "${.SDATA.exampleSDID@0.iut}", "3");
425   - testcase(msg, "${.SDATA.exampleSDID@0.eventSource}", "Application");
426   - testcase(msg, "${.SDATA.exampleSDID@0.eventID}", "1011");
427   - testcase(msg, "${.SDATA.examplePriority@0.class}", "high");
  273 + /* multi-threaded expansion */
428 274
429   - log_msg_unref(msg);
430 275
  276 + deinit_template_tests();
431 277 app_shutdown();
432   - g_sockaddr_unref(saddr);
433 278
434   - if (success)
435   - return 0;
436   - return 1;
  279 + return 0;
437 280 }
2  tests/unit/test_template_speed.c
@@ -68,7 +68,7 @@ testcase(const gchar *msg_str, gboolean syslog_proto, gchar *template)
68 68 log_template_format(templ, msg, NULL, LTZ_LOCAL, 0, NULL, res);
69 69 }
70 70 g_get_current_time(&end);
71   - printf("%-90.*s speed: %12.3f msg/sec\n", (int) strlen(template) - 1, template, i * 1e6 / g_time_val_diff(&end, &start));
  71 + printf(" %-90.*s speed: %12.3f msg/sec\n", (int) strlen(template) - 1, template, i * 1e6 / g_time_val_diff(&end, &start));
72 72
73 73 log_template_unref(templ);
74 74 g_string_free(res, TRUE);

No commit comments for this range

Something went wrong with that request. Please try again.