From b4dd099c32035cff7407b70ae042996a3c30ca9e Mon Sep 17 00:00:00 2001
From: Laszlo Varady <laszlo.varady@balabit.com>
Date: Mon, 26 Sep 2016 20:13:53 +0000
Subject: [PATCH] modules: support syslog-ng 3.8

Fixes #157

Signed-off-by: Laszlo Varady <laszlo.varady@balabit.com>
---
 modules/basicfuncs-plus/basic-funcs-plus.c     |  2 +-
 modules/getent/tfgetent.c                      |  4 +--
 modules/kafka/kafka.c                          | 24 ++++++++------
 modules/lua/lua-dest.c                         | 31 +++++++++--------
 modules/lua/lua-dest.h                         |  2 +-
 modules/lua/lua-grammar.ym                     |  4 +--
 modules/lua/lua-msg.c                          |  2 +-
 modules/lua/lua-msg.h                          |  2 +-
 modules/lua/lua-plugin.c                       |  2 +-
 modules/monitor-source/monitor-source-plugin.c |  2 +-
 modules/monitor-source/monitor-source.c        |  2 ++
 modules/perl/perl-dest.c                       | 46 +++++++++++++++-----------
 modules/perl/perl-dest.h                       |  2 +-
 modules/perl/perl-grammar.ym                   |  4 +--
 modules/perl/perl-plugin.c                     |  2 +-
 modules/rss/rss.c                              |  2 +-
 modules/trigger-source/trigger-source-plugin.c |  2 +-
 modules/trigger-source/trigger-source.c        |  2 ++
 modules/zmq/zmq-destination.c                  | 18 ++++++----
 modules/zmq/zmq-plugin.c                       |  3 +-
 20 files changed, 90 insertions(+), 68 deletions(-)

diff --git a/modules/basicfuncs-plus/basic-funcs-plus.c b/modules/basicfuncs-plus/basic-funcs-plus.c
index 865bab9..85df42d 100644
--- a/modules/basicfuncs-plus/basic-funcs-plus.c
+++ b/modules/basicfuncs-plus/basic-funcs-plus.c
@@ -55,7 +55,7 @@ basicfuncs_plus_module_init(GlobalConfig *cfg, CfgArgs *args)
 const ModuleInfo module_info =
 {
   .canonical_name = "basicfuncs-plus",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The basicfuncs-plus module provides some additional template functions for syslog-ng.",
   .core_revision = VERSION_CURRENT_VER_ONLY,
   .plugins = basicfuncs_plus_plugins,
diff --git a/modules/getent/tfgetent.c b/modules/getent/tfgetent.c
index 3e92e84..2aec853 100644
--- a/modules/getent/tfgetent.c
+++ b/modules/getent/tfgetent.c
@@ -21,7 +21,7 @@
  */
 
 #include <syslog-ng.h>
-#include <logmsg.h>
+#include <logmsg/logmsg.h>
 #include <plugin.h>
 #include <plugin-types.h>
 #include <cfg.h>
@@ -182,7 +182,7 @@ getent_plugin_module_init(GlobalConfig *cfg, CfgArgs *args)
 const ModuleInfo module_info =
 {
   .canonical_name = "getent-plugin",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The getent module provides getent template functions for syslog-ng.",
   .core_revision = VERSION_CURRENT_VER_ONLY,
   .plugins = getent_plugins,
diff --git a/modules/kafka/kafka.c b/modules/kafka/kafka.c
index c6a9cb3..7462584 100644
--- a/modules/kafka/kafka.c
+++ b/modules/kafka/kafka.c
@@ -30,12 +30,12 @@
 #include "kafka-parser.h"
 #include "plugin.h"
 #include "messages.h"
-#include "misc.h"
 #include "stats/stats.h"
 #include "logqueue.h"
 #include "driver.h"
 #include "plugin-types.h"
 #include "logthrdestdrv.h"
+#include "seqnum.h"
 
 /*
  * This module draws from the redis module and provides an Apache Kafka
@@ -276,19 +276,23 @@ kafka_dd_format_stats_instance(LogThrDestDriver *d)
   KafkaDriver *self = (KafkaDriver *)d;
   static gchar persist_name[1024];
 
-  g_snprintf(persist_name, sizeof(persist_name),
-             "kafka,%s", self->topic_name);
+  if (d->super.super.super.persist_name)
+    g_snprintf(persist_name, sizeof(persist_name), "kafka,%s", d->super.super.super.persist_name);
+  else
+    g_snprintf(persist_name, sizeof(persist_name), "kafka,%s", self->topic_name);
   return persist_name;
 }
 
-static gchar *
-kafka_dd_format_persist_name(LogThrDestDriver *d)
+static const gchar *
+kafka_dd_format_persist_name(const LogPipe *d)
 {
-  KafkaDriver *self = (KafkaDriver *)d;
+  const KafkaDriver *self = (const KafkaDriver *)d;
   static gchar persist_name[1024];
 
-  g_snprintf(persist_name, sizeof(persist_name),
-             "kafka(%s)", self->topic_name);
+  if (d->persist_name)
+    g_snprintf(persist_name, sizeof(persist_name), "kafka.%s", d->persist_name);
+  else
+    g_snprintf(persist_name, sizeof(persist_name), "kafka(%s)", self->topic_name);
   return persist_name;
 }
 
@@ -500,13 +504,13 @@ kafka_dd_new(GlobalConfig *cfg)
   log_threaded_dest_driver_init_instance(&self->super, cfg);
   self->super.super.super.super.init = kafka_dd_init;
   self->super.super.super.super.free_fn = kafka_dd_free;
+  self->super.super.super.super.generate_persist_name = kafka_dd_format_persist_name;
 
   self->super.worker.thread_init = kafka_worker_thread_init;
   self->super.worker.thread_deinit = kafka_worker_thread_deinit;
   self->super.worker.insert = kafka_worker_insert;
 
   self->super.format.stats_instance = kafka_dd_format_stats_instance;
-  self->super.format.persist_name = kafka_dd_format_persist_name;
   self->super.stats_source = SCS_KAFKA;
 
   self->flags = KAFKA_FLAG_NONE;
@@ -538,7 +542,7 @@ kafka_module_init(GlobalConfig *cfg, CfgArgs *args)
 const ModuleInfo module_info =
 {
   .canonical_name = "kafka",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The afkafka module provides Kafka destination support for syslog-ng.",
   .core_revision = VERSION_CURRENT_VER_ONLY,
   .plugins = &kafka_plugin,
diff --git a/modules/lua/lua-dest.c b/modules/lua/lua-dest.c
index 1c8b6a1..acf0719 100644
--- a/modules/lua/lua-dest.c
+++ b/modules/lua/lua-dest.c
@@ -118,7 +118,7 @@ lua_cast_and_push_value_to_stack(lua_State *state, const gchar *name, TypeHint t
 };
 
 static gboolean
-lua_dd_add_parameter_to_table(const gchar *name, TypeHint type, const gchar *value, gpointer user_data)
+lua_dd_add_parameter_to_table(const gchar *name, TypeHint type, const gchar *value, gsize value_len, gpointer user_data)
 {
   lua_State *state = (lua_State *) user_data;
 
@@ -492,17 +492,20 @@ lua_dd_add_global_constant_with_type_hint(LogDriver *d, const char *name, const
 };
 
 static gchar *
-lua_dd_format_string_instance(LogThrDestDriver *d, char* name, size_t name_len)
+lua_dd_format_string_instance(const LogPipe *d, char* persist_name, size_t persist_name_len)
 {
   LuaDestDriver *self = (LuaDestDriver *)d;
 
-  g_snprintf(name, name_len,
-             "python,%s,%s,%s,%s",
-             self->filename,
-             self->init_func_name,
-             self->queue_func_name,
-             self->deinit_func_name);
-  return name;
+  if (d->persist_name)
+    g_snprintf(persist_name, persist_name_len, "lua.%s", d->persist_name);
+  else
+    g_snprintf(persist_name, persist_name_len,
+               "lua(%s,%s,%s,%s)",
+               self->filename,
+               self->init_func_name,
+               self->queue_func_name,
+               self->deinit_func_name);
+  return persist_name;
 };
 
 static gchar *
@@ -510,11 +513,11 @@ lua_dd_format_stats_instance(LogThrDestDriver *d)
 {
   static gchar stats_name[1024];
 
-  return lua_dd_format_string_instance(d, stats_name, sizeof(stats_name));
+  return lua_dd_format_string_instance((LogPipe *) d, stats_name, sizeof(stats_name));
 }
 
-static gchar *
-lua_dd_format_persist_name(LogThrDestDriver *d)
+static const gchar *
+lua_dd_format_persist_name(const LogPipe *d)
 {
   static gchar persist_name[1024];
 
@@ -527,7 +530,7 @@ lua_dd_set_params(LogDriver *d, ValuePairs *vp)
   LuaDestDriver *self = (LuaDestDriver *) d;
 
   if (self->params)
-    value_pairs_free(self->params);
+    value_pairs_unref(self->params);
   self->params = vp;
 }
 
@@ -543,12 +546,12 @@ lua_dd_new(GlobalConfig *cfg)
   self->super.super.super.super.init = lua_dd_init;
   self->super.super.super.super.deinit = lua_dd_deinit;
   self->super.super.super.super.free_fn = lua_dd_free;
+  self->super.super.super.super.generate_persist_name = lua_dd_format_persist_name;
 
   self->super.worker.insert = lua_dd_queue;
   self->super.worker.disconnect = NULL;
 
   self->super.format.stats_instance = lua_dd_format_stats_instance;
-  self->super.format.persist_name = lua_dd_format_persist_name;
   self->super.stats_source = SCS_LUA;
 
   return &self->super.super.super;
diff --git a/modules/lua/lua-dest.h b/modules/lua/lua-dest.h
index e4665a2..3ecf3cd 100644
--- a/modules/lua/lua-dest.h
+++ b/modules/lua/lua-dest.h
@@ -27,7 +27,7 @@
 
 #include "driver.h"
 #include "logwriter.h"
-#include "value-pairs.h"
+#include "value-pairs/value-pairs.h"
 #include "logthrdestdrv.h"
 #include <lua.h>
 
diff --git a/modules/lua/lua-grammar.ym b/modules/lua/lua-grammar.ym
index 42d2f22..8c3a992 100644
--- a/modules/lua/lua-grammar.ym
+++ b/modules/lua/lua-grammar.ym
@@ -26,8 +26,8 @@
 
 #include "lua-parser.h"
 #include "lua-dest.h"
-#include "value-pairs.h"
-#include "vptransform.h"
+#include "value-pairs/value-pairs.h"
+#include "value-pairs/transforms.h"
 
 }
 
diff --git a/modules/lua/lua-msg.c b/modules/lua/lua-msg.c
index 347ac2c..908abb4 100644
--- a/modules/lua/lua-msg.c
+++ b/modules/lua/lua-msg.c
@@ -25,7 +25,7 @@
 
 #include "lua-msg.h"
 #include "lua-utils.h"
-#include "logmsg.h"
+#include "logmsg/logmsg.h"
 #include "messages.h"
 #include <lauxlib.h>
 #include <lualib.h>
diff --git a/modules/lua/lua-msg.h b/modules/lua/lua-msg.h
index 900fba7..4b05ac1 100644
--- a/modules/lua/lua-msg.h
+++ b/modules/lua/lua-msg.h
@@ -21,7 +21,7 @@
  *
  */
 
-#include "logmsg.h"
+#include "logmsg/logmsg.h"
 #include <lua.h>
 
 #ifndef _LUA_MSG_H
diff --git a/modules/lua/lua-plugin.c b/modules/lua/lua-plugin.c
index a41f96f..6efb258 100644
--- a/modules/lua/lua-plugin.c
+++ b/modules/lua/lua-plugin.c
@@ -46,7 +46,7 @@ lua_module_init(GlobalConfig *cfg, CfgArgs *args G_GNUC_UNUSED)
 const ModuleInfo module_info =
 {
   .canonical_name = "lua",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The lua module provides lua scripted destination support for syslog-ng.",
   .core_revision = VERSION_CURRENT_VER_ONLY,
   .plugins = &lua_plugin,
diff --git a/modules/monitor-source/monitor-source-plugin.c b/modules/monitor-source/monitor-source-plugin.c
index e147985..a53d115 100644
--- a/modules/monitor-source/monitor-source-plugin.c
+++ b/modules/monitor-source/monitor-source-plugin.c
@@ -47,7 +47,7 @@ monitor_module_init(GlobalConfig *cfg, CfgArgs *args G_GNUC_UNUSED)
 const ModuleInfo module_info =
 {
   .canonical_name = "monitor",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The monitor module provides stuff.",
   .core_revision = VERSION_CURRENT_VER_ONLY,
   .plugins = &monitor_plugin,
diff --git a/modules/monitor-source/monitor-source.c b/modules/monitor-source/monitor-source.c
index 713d719..3c54e00 100644
--- a/modules/monitor-source/monitor-source.c
+++ b/modules/monitor-source/monitor-source.c
@@ -31,6 +31,8 @@
 #include "logsource.h"
 #include "mainloop.h"
 
+#include <iv.h>
+
 #define LUA_COMPAT_MODULE
 
 typedef struct
diff --git a/modules/perl/perl-dest.c b/modules/perl/perl-dest.c
index 6c3c3be..334303b 100644
--- a/modules/perl/perl-dest.c
+++ b/modules/perl/perl-dest.c
@@ -24,7 +24,7 @@
 #include "perl-dest.h"
 #include "logthrdestdrv.h"
 #include "stats/stats.h"
-#include "misc.h"
+#include "seqnum.h"
 
 #include <EXTERN.h>
 #include <perl.h>
@@ -93,7 +93,7 @@ perl_dd_set_value_pairs(LogDriver *d, ValuePairs *vp)
   PerlDestDriver *self = (PerlDestDriver *)d;
 
   if (self->vp)
-    value_pairs_free(self->vp);
+    value_pairs_unref(self->vp);
   self->vp = vp;
 }
 
@@ -113,27 +113,33 @@ perl_dd_format_stats_instance(LogThrDestDriver *d)
   PerlDestDriver *self = (PerlDestDriver *)d;
   static gchar persist_name[1024];
 
-  g_snprintf(persist_name, sizeof(persist_name),
-             "perl,%s,%s,%s,%s",
-             self->filename,
-             self->init_func_name,
-             self->queue_func_name,
-             self->deinit_func_name);
+  if (d->super.super.super.persist_name)
+    g_snprintf(persist_name, sizeof(persist_name), "perl,%s", d->super.super.super.persist_name);
+  else
+    g_snprintf(persist_name, sizeof(persist_name),
+               "perl,%s,%s,%s,%s",
+               self->filename,
+               self->init_func_name,
+               self->queue_func_name,
+               self->deinit_func_name);
   return persist_name;
 }
 
-static gchar *
-perl_dd_format_persist_name(LogThrDestDriver *d)
+static const gchar *
+perl_dd_format_persist_name(const LogPipe *d)
 {
-  PerlDestDriver *self = (PerlDestDriver *)d;
+  const PerlDestDriver *self = (const PerlDestDriver *)d;
   static gchar persist_name[1024];
 
-  g_snprintf(persist_name, sizeof(persist_name),
-             "perl(%s,%s,%s,%s)",
-             self->filename,
-             self->init_func_name,
-             self->queue_func_name,
-             self->deinit_func_name);
+  if (d->persist_name)
+    g_snprintf(persist_name, sizeof(persist_name), "perl.%s", d->persist_name);
+  else
+    g_snprintf(persist_name, sizeof(persist_name),
+               "perl(%s,%s,%s,%s)",
+               self->filename,
+               self->init_func_name,
+               self->queue_func_name,
+               self->deinit_func_name);
   return persist_name;
 }
 
@@ -206,7 +212,7 @@ xs_init(pTHX)
 
 static gboolean
 perl_worker_vp_add_one(const gchar *name,
-                       TypeHint type, const gchar *value,
+                       TypeHint type, const gchar *value, gsize value_len,
                        gpointer user_data)
 {
   PerlInterpreter *my_perl = (PerlInterpreter *)((gpointer *)user_data)[0];
@@ -402,7 +408,7 @@ perl_dd_free(LogPipe *d)
   g_free(self->deinit_func_name);
 
   if (self->vp)
-    value_pairs_free(self->vp);
+    value_pairs_unref(self->vp);
 
   log_threaded_dest_driver_free(d);
 }
@@ -416,6 +422,7 @@ perl_dd_new(GlobalConfig *cfg)
 
   self->super.super.super.super.init = perl_worker_init;
   self->super.super.super.super.free_fn = perl_dd_free;
+  self->super.super.super.super.generate_persist_name = perl_dd_format_persist_name;
 
   self->super.worker.thread_init = _perl_thread_init;
   self->super.worker.thread_deinit = _perl_thread_deinit;
@@ -423,7 +430,6 @@ perl_dd_new(GlobalConfig *cfg)
   self->super.worker.insert = perl_worker_eval;
 
   self->super.format.stats_instance = perl_dd_format_stats_instance;
-  self->super.format.persist_name = perl_dd_format_persist_name;
   self->super.stats_source = SCS_PERL;
 
   init_sequence_number(&self->seq_num);
diff --git a/modules/perl/perl-dest.h b/modules/perl/perl-dest.h
index 8ff2918..c92e181 100644
--- a/modules/perl/perl-dest.h
+++ b/modules/perl/perl-dest.h
@@ -26,7 +26,7 @@
 
 #include "driver.h"
 #include "logwriter.h"
-#include "value-pairs.h"
+#include "value-pairs/value-pairs.h"
 
 LogDriver *perl_dd_new(GlobalConfig *cfg);
 void perl_dd_set_init_func(LogDriver *d, gchar *init_func_name);
diff --git a/modules/perl/perl-grammar.ym b/modules/perl/perl-grammar.ym
index cf4dc32..1b083cd 100644
--- a/modules/perl/perl-grammar.ym
+++ b/modules/perl/perl-grammar.ym
@@ -25,8 +25,8 @@
 
 #include "perl-parser.h"
 #include "perl-dest.h"
-#include "value-pairs.h"
-#include "vptransform.h"
+#include "value-pairs/value-pairs.h"
+#include "value-pairs/transforms.h"
 
 }
 
diff --git a/modules/perl/perl-plugin.c b/modules/perl/perl-plugin.c
index 3a25a12..882f2ce 100644
--- a/modules/perl/perl-plugin.c
+++ b/modules/perl/perl-plugin.c
@@ -55,7 +55,7 @@ perl_module_init(GlobalConfig *cfg, CfgArgs *args G_GNUC_UNUSED)
 const ModuleInfo module_info =
 {
   .canonical_name = "perl",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The perl module provides Perl scripted destination support for syslog-ng.",
   .core_revision = VERSION_CURRENT_VER_ONLY,
   .plugins = &perl_plugin,
diff --git a/modules/rss/rss.c b/modules/rss/rss.c
index 4c415e3..e1405d2 100644
--- a/modules/rss/rss.c
+++ b/modules/rss/rss.c
@@ -342,7 +342,7 @@ rss_module_init (GlobalConfig * cfg, CfgArgs * args)
 
 const ModuleInfo module_info = {
   .canonical_name = "rss",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The rss module is a destination driver to offer logs in RSS feed.",
   .core_revision = VERSION_CURRENT_VER_ONLY,
   .plugins = &rss_plugin,
diff --git a/modules/trigger-source/trigger-source-plugin.c b/modules/trigger-source/trigger-source-plugin.c
index dacdd22..4a69cc2 100644
--- a/modules/trigger-source/trigger-source-plugin.c
+++ b/modules/trigger-source/trigger-source-plugin.c
@@ -46,7 +46,7 @@ trigger_module_init(GlobalConfig *cfg, CfgArgs *args G_GNUC_UNUSED)
 const ModuleInfo module_info =
 {
   .canonical_name = "trigger",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The trigger module provides stuff.",
   .core_revision = VERSION_CURRENT_VER_ONLY,
   .plugins = &trigger_plugin,
diff --git a/modules/trigger-source/trigger-source.c b/modules/trigger-source/trigger-source.c
index e02ed9e..a06606a 100644
--- a/modules/trigger-source/trigger-source.c
+++ b/modules/trigger-source/trigger-source.c
@@ -27,6 +27,8 @@
 #include "logsource.h"
 #include "mainloop.h"
 
+#include <iv.h>
+
 typedef struct
 {
   gint trigger_freq;
diff --git a/modules/zmq/zmq-destination.c b/modules/zmq/zmq-destination.c
index 421300f..b34f1a5 100644
--- a/modules/zmq/zmq-destination.c
+++ b/modules/zmq/zmq-destination.c
@@ -24,7 +24,7 @@
 #include <zmq.h>
 
 #include "zmq-module.h"
-#include "misc.h"
+#include "seqnum.h"
 
 #ifndef SCS_ZMQ
 #define SCS_ZMQ 0
@@ -87,16 +87,22 @@ zmq_dd_format_stats_instance(LogThrDestDriver *d)
 {
   static gchar persist_name[1024];
 
-  g_snprintf(persist_name, sizeof(persist_name), "zmq()");
+  if (d->super.super.super.persist_name)
+    g_snprintf(persist_name, sizeof(persist_name), "zmq,%s", d->super.super.super.persist_name);
+  else
+    g_snprintf(persist_name, sizeof(persist_name), "zmq");
   return persist_name;
 }
 
-static gchar *
-zmq_dd_format_persist_name(LogThrDestDriver *d)
+static const gchar *
+zmq_dd_format_persist_name(const LogPipe *d)
 {
   static gchar persist_name[1024];
 
-  g_snprintf(persist_name, sizeof(persist_name), "zmq()");
+  if (d->persist_name)
+    g_snprintf(persist_name, sizeof(persist_name), "zmq.%s", d->persist_name);
+  else
+    g_snprintf(persist_name, sizeof(persist_name), "zmq()");
   return persist_name;
 }
 
@@ -216,13 +222,13 @@ zmq_dd_new(GlobalConfig *cfg)
   log_threaded_dest_driver_init_instance(&self->super, cfg);
   self->super.super.super.super.init = zmq_dd_init;
   self->super.super.super.super.free_fn = zmq_dd_free;
+  self->super.super.super.super.generate_persist_name = zmq_dd_format_persist_name;
 
   self->super.worker.thread_init = zmq_worker_thread_init;
   self->super.worker.disconnect = zmq_dd_disconnect;
   self->super.worker.insert = zmq_worker_insert;
 
   self->super.format.stats_instance = zmq_dd_format_stats_instance;
-  self->super.format.persist_name = zmq_dd_format_persist_name;
   self->super.stats_source = SCS_ZMQ;
 
   zmq_dd_set_port((LogDriver *) self, 5556);
diff --git a/modules/zmq/zmq-plugin.c b/modules/zmq/zmq-plugin.c
index e5c6913..d866e92 100644
--- a/modules/zmq/zmq-plugin.c
+++ b/modules/zmq/zmq-plugin.c
@@ -26,7 +26,6 @@
 #include "zmq-parser.h"
 #include "plugin.h"
 #include "messages.h"
-#include "misc.h"
 #include "stats/stats.h"
 #include "logqueue.h"
 #include "driver.h"
@@ -58,7 +57,7 @@ zmq_module_init(GlobalConfig *cfg, CfgArgs *args)
 const ModuleInfo module_info =
 {
   .canonical_name = "zmq",
-  .version = VERSION,
+  .version = SYSLOG_NG_VERSION,
   .description = "The zmq module provides ZeroMQ destination support for syslog-ng.",
   .core_revision = "Dummy Revision",
   .plugins = zmq_plugins,
