diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
commit | dcc721a95bef6f0d8e6d8775b8efe33e5aecd562 (patch) | |
tree | 66a2774cd0ee294d019efd71d2544c70f42b2842 /contrib/mmdarwin | |
parent | Initial commit. (diff) | |
download | rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.tar.xz rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.zip |
Adding upstream version 8.2402.0.upstream/8.2402.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | contrib/mmdarwin/Makefile.am | 8 | ||||
-rw-r--r-- | contrib/mmdarwin/Makefile.in | 797 | ||||
-rw-r--r-- | contrib/mmdarwin/mmdarwin.c | 953 | ||||
-rw-r--r-- | contrib/mmdarwin/protocol.h | 70 |
4 files changed, 1828 insertions, 0 deletions
diff --git a/contrib/mmdarwin/Makefile.am b/contrib/mmdarwin/Makefile.am new file mode 100644 index 0000000..4b88691 --- /dev/null +++ b/contrib/mmdarwin/Makefile.am @@ -0,0 +1,8 @@ +pkglib_LTLIBRARIES = mmdarwin.la + +mmdarwin_la_SOURCES = mmdarwin.c protocol.h +mmdarwin_la_CPPFLAGS = $(RSRT_CFLAGS) $(PTHREADS_CFLAGS) +mmdarwin_la_LDFLAGS = -module -avoid-version +mmdarwin_la_LIBADD = + +EXTRA_DIST = diff --git a/contrib/mmdarwin/Makefile.in b/contrib/mmdarwin/Makefile.in new file mode 100644 index 0000000..60812d4 --- /dev/null +++ b/contrib/mmdarwin/Makefile.in @@ -0,0 +1,797 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = contrib/mmdarwin +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_check_define.m4 \ + $(top_srcdir)/m4/atomic_operations.m4 \ + $(top_srcdir)/m4/atomic_operations_64bit.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(pkglibdir)" +LTLIBRARIES = $(pkglib_LTLIBRARIES) +mmdarwin_la_DEPENDENCIES = +am_mmdarwin_la_OBJECTS = mmdarwin_la-mmdarwin.lo +mmdarwin_la_OBJECTS = $(am_mmdarwin_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +mmdarwin_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(mmdarwin_la_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/mmdarwin_la-mmdarwin.Plo +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(mmdarwin_la_SOURCES) +DIST_SOURCES = $(mmdarwin_la_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +APU_CFLAGS = @APU_CFLAGS@ +APU_LIBS = @APU_LIBS@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CIVETWEB_LIBS = @CIVETWEB_LIBS@ +CONF_FILE_PATH = @CONF_FILE_PATH@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CURL_CFLAGS = @CURL_CFLAGS@ +CURL_LIBS = @CURL_LIBS@ +CYGPATH_W = @CYGPATH_W@ +CZMQ_CFLAGS = @CZMQ_CFLAGS@ +CZMQ_LIBS = @CZMQ_LIBS@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DL_LIBS = @DL_LIBS@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FAUP_LIBS = @FAUP_LIBS@ +FGREP = @FGREP@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ +GNUTLS_LIBS = @GNUTLS_LIBS@ +GREP = @GREP@ +GSS_LIBS = @GSS_LIBS@ +GT_KSI_LS12_CFLAGS = @GT_KSI_LS12_CFLAGS@ +GT_KSI_LS12_LIBS = @GT_KSI_LS12_LIBS@ +HASH_XXHASH_LIBS = @HASH_XXHASH_LIBS@ +HIREDIS_CFLAGS = @HIREDIS_CFLAGS@ +HIREDIS_LIBS = @HIREDIS_LIBS@ +IMUDP_LIBS = @IMUDP_LIBS@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +IP = @IP@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBCAPNG_CFLAGS = @LIBCAPNG_CFLAGS@ +LIBCAPNG_LIBS = @LIBCAPNG_LIBS@ +LIBCAPNG_PRESENT_CFLAGS = @LIBCAPNG_PRESENT_CFLAGS@ +LIBCAPNG_PRESENT_LIBS = @LIBCAPNG_PRESENT_LIBS@ +LIBDBI_CFLAGS = @LIBDBI_CFLAGS@ +LIBDBI_LIBS = @LIBDBI_LIBS@ +LIBESTR_CFLAGS = @LIBESTR_CFLAGS@ +LIBESTR_LIBS = @LIBESTR_LIBS@ +LIBEVENT_CFLAGS = @LIBEVENT_CFLAGS@ +LIBEVENT_LIBS = @LIBEVENT_LIBS@ +LIBFASTJSON_CFLAGS = @LIBFASTJSON_CFLAGS@ +LIBFASTJSON_LIBS = @LIBFASTJSON_LIBS@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBLOGGING_CFLAGS = @LIBLOGGING_CFLAGS@ +LIBLOGGING_LIBS = @LIBLOGGING_LIBS@ +LIBLOGGING_STDLOG_CFLAGS = @LIBLOGGING_STDLOG_CFLAGS@ +LIBLOGGING_STDLOG_LIBS = @LIBLOGGING_STDLOG_LIBS@ +LIBLOGNORM_CFLAGS = @LIBLOGNORM_CFLAGS@ +LIBLOGNORM_LIBS = @LIBLOGNORM_LIBS@ +LIBLZ4_CFLAGS = @LIBLZ4_CFLAGS@ +LIBLZ4_LIBS = @LIBLZ4_LIBS@ +LIBM = @LIBM@ +LIBMONGOC_CFLAGS = @LIBMONGOC_CFLAGS@ +LIBMONGOC_LIBS = @LIBMONGOC_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBRDKAFKA_CFLAGS = @LIBRDKAFKA_CFLAGS@ +LIBRDKAFKA_LIBS = @LIBRDKAFKA_LIBS@ +LIBS = @LIBS@ +LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ +LIBSYSTEMD_JOURNAL_CFLAGS = @LIBSYSTEMD_JOURNAL_CFLAGS@ +LIBSYSTEMD_JOURNAL_LIBS = @LIBSYSTEMD_JOURNAL_LIBS@ +LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ +LIBTOOL = @LIBTOOL@ +LIBUUID_CFLAGS = @LIBUUID_CFLAGS@ +LIBUUID_LIBS = @LIBUUID_LIBS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MYSQL_CFLAGS = @MYSQL_CFLAGS@ +MYSQL_CONFIG = @MYSQL_CONFIG@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OPENSSL_CFLAGS = @OPENSSL_CFLAGS@ +OPENSSL_LIBS = @OPENSSL_LIBS@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PGSQL_CFLAGS = @PGSQL_CFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PG_CONFIG = @PG_CONFIG@ +PID_FILE_PATH = @PID_FILE_PATH@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PROTON_CFLAGS = @PROTON_CFLAGS@ +PROTON_LIBS = @PROTON_LIBS@ +PROTON_PROACTOR_CFLAGS = @PROTON_PROACTOR_CFLAGS@ +PROTON_PROACTOR_LIBS = @PROTON_PROACTOR_LIBS@ +PTHREADS_CFLAGS = @PTHREADS_CFLAGS@ +PTHREADS_LIBS = @PTHREADS_LIBS@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +RABBITMQ_CFLAGS = @RABBITMQ_CFLAGS@ +RABBITMQ_LIBS = @RABBITMQ_LIBS@ +RANLIB = @RANLIB@ +READLINK = @READLINK@ +REDIS = @REDIS@ +RELP_CFLAGS = @RELP_CFLAGS@ +RELP_LIBS = @RELP_LIBS@ +RSRT_CFLAGS = @RSRT_CFLAGS@ +RSRT_CFLAGS1 = @RSRT_CFLAGS1@ +RSRT_LIBS = @RSRT_LIBS@ +RSRT_LIBS1 = @RSRT_LIBS1@ +RST2MAN = @RST2MAN@ +RT_LIBS = @RT_LIBS@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SNMP_CFLAGS = @SNMP_CFLAGS@ +SNMP_LIBS = @SNMP_LIBS@ +SOL_LIBS = @SOL_LIBS@ +STRIP = @STRIP@ +TCL_BIN_DIR = @TCL_BIN_DIR@ +TCL_INCLUDE_SPEC = @TCL_INCLUDE_SPEC@ +TCL_LIB_FILE = @TCL_LIB_FILE@ +TCL_LIB_FLAG = @TCL_LIB_FLAG@ +TCL_LIB_SPEC = @TCL_LIB_SPEC@ +TCL_PATCH_LEVEL = @TCL_PATCH_LEVEL@ +TCL_SRC_DIR = @TCL_SRC_DIR@ +TCL_STUB_LIB_FILE = @TCL_STUB_LIB_FILE@ +TCL_STUB_LIB_FLAG = @TCL_STUB_LIB_FLAG@ +TCL_STUB_LIB_SPEC = @TCL_STUB_LIB_SPEC@ +TCL_VERSION = @TCL_VERSION@ +UDPSPOOF_CFLAGS = @UDPSPOOF_CFLAGS@ +UDPSPOOF_LIBS = @UDPSPOOF_LIBS@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +WARN_CFLAGS = @WARN_CFLAGS@ +WARN_LDFLAGS = @WARN_LDFLAGS@ +WARN_SCANNERFLAGS = @WARN_SCANNERFLAGS@ +WGET = @WGET@ +YACC = @YACC@ +YACC_FOUND = @YACC_FOUND@ +YFLAGS = @YFLAGS@ +ZLIB_CFLAGS = @ZLIB_CFLAGS@ +ZLIB_LIBS = @ZLIB_LIBS@ +ZSTD_CFLAGS = @ZSTD_CFLAGS@ +ZSTD_LIBS = @ZSTD_LIBS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +moddirs = @moddirs@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +pkglib_LTLIBRARIES = mmdarwin.la +mmdarwin_la_SOURCES = mmdarwin.c protocol.h +mmdarwin_la_CPPFLAGS = $(RSRT_CFLAGS) $(PTHREADS_CFLAGS) +mmdarwin_la_LDFLAGS = -module -avoid-version +mmdarwin_la_LIBADD = +EXTRA_DIST = +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu contrib/mmdarwin/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu contrib/mmdarwin/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkglibdir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pkglibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pkglibdir)"; \ + } + +uninstall-pkglibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pkglibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pkglibdir)/$$f"; \ + done + +clean-pkglibLTLIBRARIES: + -test -z "$(pkglib_LTLIBRARIES)" || rm -f $(pkglib_LTLIBRARIES) + @list='$(pkglib_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +mmdarwin.la: $(mmdarwin_la_OBJECTS) $(mmdarwin_la_DEPENDENCIES) $(EXTRA_mmdarwin_la_DEPENDENCIES) + $(AM_V_CCLD)$(mmdarwin_la_LINK) -rpath $(pkglibdir) $(mmdarwin_la_OBJECTS) $(mmdarwin_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmdarwin_la-mmdarwin.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mmdarwin_la-mmdarwin.lo: mmdarwin.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmdarwin_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmdarwin_la-mmdarwin.lo -MD -MP -MF $(DEPDIR)/mmdarwin_la-mmdarwin.Tpo -c -o mmdarwin_la-mmdarwin.lo `test -f 'mmdarwin.c' || echo '$(srcdir)/'`mmdarwin.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmdarwin_la-mmdarwin.Tpo $(DEPDIR)/mmdarwin_la-mmdarwin.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmdarwin.c' object='mmdarwin_la-mmdarwin.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmdarwin_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmdarwin_la-mmdarwin.lo `test -f 'mmdarwin.c' || echo '$(srcdir)/'`mmdarwin.c + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(pkglibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-pkglibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/mmdarwin_la-mmdarwin.Plo + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-pkglibLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/mmdarwin_la-mmdarwin.Plo + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-pkglibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libtool clean-pkglibLTLIBRARIES \ + cscopelist-am ctags ctags-am distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-pkglibLTLIBRARIES install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am uninstall-pkglibLTLIBRARIES + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/contrib/mmdarwin/mmdarwin.c b/contrib/mmdarwin/mmdarwin.c new file mode 100644 index 0000000..e36dbde --- /dev/null +++ b/contrib/mmdarwin/mmdarwin.c @@ -0,0 +1,953 @@ +/* Copyright 2019 Advens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "config.h" +#include "rsyslog.h" +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <signal.h> +#include <errno.h> +#include <unistd.h> +#include <stdint.h> +#include <pthread.h> +#include "conf.h" +#include "syslogd-types.h" +#include "srUtils.h" +#include "template.h" +#include "module-template.h" +#include "errmsg.h" +#include "parserif.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/un.h> +#include <sys/socket.h> +#include <uuid/uuid.h> +#include <json.h> + +#include "protocol.h" /* custom file written for Darwin */ + +#define JSON_DEFAULT_CONTAINER "!mmdarwin" +#define JSON_DARWIN_ID "darwin_id" +#define INVLD_SOCK -1 +#define INITIAL_BUFFER_SIZE 32 +#define BUFFER_DEFAULT_MAX_SIZE 65536 + +MODULE_TYPE_OUTPUT +MODULE_TYPE_NOKEEP +MODULE_CNFNAME("mmdarwin") + +DEFobjCurrIf(glbl) +DEF_OMOD_STATIC_DATA + +typedef struct dyn_buffer_t +{ + char *buffer; + size_t bufferAllocSize; + size_t bufferMsgSize; + size_t bufferMaxSize; +} dyn_buffer; + +/* config variables */ +typedef struct _instanceData +{ + char *pUUIDKey; /* the key to the UUID generated by an mmdarwin instance */ + char *pCertitudeKey; /* the key name to save in the enriched log + line the certitude obtained from Darwin */ + uchar *pSockName; /* the socket path of the filter which will be used by + Darwin */ + unsigned long long int filterCode; /* the filter code associated to the filter which will be used + by Darwin */ + enum darwin_filter_response_type response; /* the type of response for Darwin: no / back / darwin / both */ + struct + { + int nmemb; + char **name; + char **varname; + } fieldList; /* our keys (fields) to be extracted from the JSON-parsed log line */ + unsigned int socketMaxUse; + sbool sendPartial; +} instanceData; + +typedef struct wrkrInstanceData +{ + instanceData *pData; + int sock; /* the socket of the filter which will be used by Darwin */ + struct sockaddr_un addr; /* the sockaddr_un used to connect to the Darwin filter */ + uint8_t pktSentSocket; + dyn_buffer darwinBody; /* the body object used (and reused) to hold data to send to Darwin */ + dyn_buffer fieldBuffer; +} wrkrInstanceData_t; + +struct modConfData_s +{ + /* our overall config object */ + rsconf_t *pConf; + const char *container; +}; + +/* modConf ptr to use for the current load process */ +static modConfData_t *loadModConf = NULL; +/* modConf ptr to use for the current exec process */ +static modConfData_t *runModConf = NULL; + +/* module-global parameters */ +static struct cnfparamdescr modpdescr[] = { + {"container", eCmdHdlrGetWord, 0}, +}; +static struct cnfparamblk modpblk = + {CNFPARAMBLK_VERSION, + sizeof(modpdescr) / sizeof(struct cnfparamdescr), + modpdescr}; + +/* tables for interfacing with the v6 config system + * action (instance) parameters */ +static struct cnfparamdescr actpdescr[] = { + {"key", eCmdHdlrGetWord, CNFPARAM_REQUIRED}, + {"socketpath", eCmdHdlrGetWord, CNFPARAM_REQUIRED}, + {"fields", eCmdHdlrArray, CNFPARAM_REQUIRED}, + {"filtercode", eCmdHdlrGetWord, 0}, /* optional parameter */ + {"response", eCmdHdlrGetWord, 0}, /* optional parameter */ + {"send_partial", eCmdHdlrBinary, 0}, /* optional parameter */ + {"socket_max_use", eCmdHdlrNonNegInt, 0}, /* optional parameter - will disappear in future updates */ +}; +static struct cnfparamblk actpblk = { + CNFPARAMBLK_VERSION, + sizeof(actpdescr) / sizeof(struct cnfparamdescr), + actpdescr}; + +/* custom functions */ +#define min(a, b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) + +static rsRetVal openSocket(wrkrInstanceData_t *pWrkrData); +static rsRetVal closeSocket(wrkrInstanceData_t *pWrkrData); +static rsRetVal doTryResume(wrkrInstanceData_t *pWrkrData); + +static rsRetVal sendMsg(wrkrInstanceData_t *pWrkrData, void *msg, size_t len); +static rsRetVal receiveMsg(wrkrInstanceData_t *pWrkrData, void *response, size_t len); + +const char* get_uuid_object(smsg_t *const pMsg); +int get_field(smsg_t *const pMsg, const char *pFieldName, char **ppRetString); +int expand_buffer(dyn_buffer *pBody, size_t new_size); +int add_field_to_body(dyn_buffer *pBody, const char *field, size_t size); +int start_new_line(dyn_buffer *pBody); +int end_body(dyn_buffer *pBody); + +/* open socket to remote system + */ +static rsRetVal openSocket(wrkrInstanceData_t *pWrkrData) +{ + DEFiRet; + assert(pWrkrData->sock == INVLD_SOCK); + + if ((pWrkrData->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) + { + char errStr[1024]; + int eno = errno; + DBGPRINTF("mmdarwin::openSocket:: error %d creating AF_UNIX/SOCK_STREAM: %s.\n", + eno, rs_strerror_r(eno, errStr, sizeof(errStr))); + pWrkrData->sock = INVLD_SOCK; + ABORT_FINALIZE(RS_RET_NO_SOCKET); + } + + memset(&pWrkrData->addr, 0, sizeof(struct sockaddr_un)); + pWrkrData->addr.sun_family = AF_UNIX; + strncpy(pWrkrData->addr.sun_path, (char *)pWrkrData->pData->pSockName, sizeof(pWrkrData->addr.sun_path) - 1); + + DBGPRINTF("mmdarwin::openSocket:: connecting to Darwin...\n"); + + if (connect(pWrkrData->sock, (struct sockaddr *)&pWrkrData->addr, sizeof(struct sockaddr_un)) == -1) + { + LogError(errno, RS_RET_NO_SOCKET, "mmdarwin::openSocket:: error connecting to Darwin " + "via socket '%s'", + pWrkrData->pData->pSockName); + + pWrkrData->sock = INVLD_SOCK; + ABORT_FINALIZE(RS_RET_NO_SOCKET); + } + + DBGPRINTF("mmdarwin::openSocket:: connected !\n"); +finalize_it: + if (iRet != RS_RET_OK) + { + closeSocket(pWrkrData); + } + RETiRet; +} + +/* close socket to remote system + */ +static rsRetVal closeSocket(wrkrInstanceData_t *pWrkrData) +{ + DEFiRet; + if (pWrkrData->sock != INVLD_SOCK) + { + if (close(pWrkrData->sock) != 0) + { + char errStr[1024]; + int eno = errno; + DBGPRINTF("mmdarwin::closeSocket:: error %d closing the socket: %s.\n", + eno, rs_strerror_r(eno, errStr, sizeof(errStr))); + } + pWrkrData->sock = INVLD_SOCK; + } + RETiRet; +} + +/* try to resume connection if it is not ready + */ +static rsRetVal doTryResume(wrkrInstanceData_t *pWrkrData) +{ + DEFiRet; + + DBGPRINTF("mmdarwin::doTryResume:: trying to resume\n"); + closeSocket(pWrkrData); + iRet = openSocket(pWrkrData); + + if (iRet != RS_RET_OK) + { + iRet = RS_RET_SUSPENDED; + } + + RETiRet; +} + +/* send a message via TCP + * inspired by rgehards, 2007-12-20 + */ +static rsRetVal sendMsg(wrkrInstanceData_t *pWrkrData, void *msg, size_t len) +{ + DEFiRet; + + DBGPRINTF("mmdarwin::sendMsg:: sending message to Darwin...\n"); + + if (pWrkrData->sock == INVLD_SOCK) + { + CHKiRet(doTryResume(pWrkrData)); + } + + if (pWrkrData->sock != INVLD_SOCK) + { + if (send(pWrkrData->sock, msg, len, 0) == -1) + { + char errStr[1024]; + DBGPRINTF("mmdarwin::sendData:: error while sending data: error[%d] -> %s\n", + errno, rs_strerror_r(errno, errStr, sizeof(errStr))); + iRet = RS_RET_SUSPENDED; + } + } + +finalize_it: + RETiRet; +} + +/* receive a message via TCP + * inspired by rgehards, 2007-12-20 + */ +static rsRetVal receiveMsg(wrkrInstanceData_t *pWrkrData, void *response, size_t len) +{ + DEFiRet; + + DBGPRINTF("mmdarwin::receiveMsg:: receiving message from Darwin...\n"); + + if (pWrkrData->sock == INVLD_SOCK) + { + CHKiRet(doTryResume(pWrkrData)); + } + + if (pWrkrData->sock != INVLD_SOCK) + { + if (recv(pWrkrData->sock, response, len, MSG_WAITALL) <= 0) + { + char errStr[1024]; + DBGPRINTF("mmdarwin::receiveMsg:: error while receiving data: error[%d] -> %s\n", + errno, rs_strerror_r(errno, errStr, sizeof(errStr))); + iRet = RS_RET_NONE; + } + } + +finalize_it: + RETiRet; +} + +/** + * Get the string corresponding to a field supposedly present in the provided message + * + * params: + * - pMsg: a pointer to the rsyslog message where the field should be + * - pFieldName: a nul-terminated pointer to string representing the name of the field to search for + * - ppRetString: the pointer to contain the potential return string + * + * return: 1 if a string was put in ppRetString, 0 otherwise + * + * note: the string placed in ppRetString should be freed by the caller + */ +int get_field(smsg_t *const pMsg, const char *pFieldName, char **ppRetString) +{ + DBGPRINTF("mmdarwin::get_field:: getting key '%s' in msg\n", pFieldName); + struct json_object *pJson = NULL; + char *pFieldString = NULL; + int retVal = 0; + + msgPropDescr_t propDesc; + msgPropDescrFill(&propDesc, (uchar *)pFieldName, strlen(pFieldName)); + msgGetJSONPropJSONorString(pMsg, &propDesc, &pJson, (uchar **)&pFieldString); + + if (pFieldString) + { + *ppRetString = pFieldString; + DBGPRINTF("mmdarwin::get_field:: got string\n"); + retVal = 1; + } + else if (pJson) + { + pFieldString = (char *)json_object_get_string(pJson); + if (pFieldString) + { + *ppRetString = strdup(pFieldString); + retVal = 1; + DBGPRINTF("mmdarwin::get_field:: got string from json\n"); + json_object_put(pJson); + } + } + + msgPropDescrDestruct(&propDesc); + return retVal; +} + +/** + * expands the buffer object in the dyn_buffer object + * + * params: + * - pBody: a pointer to the concerned structure to expand + * - new_size: the new size to give to the underlying buffer + * + * return: 0 if the expansion was successful, -1 otherwise + */ +int expand_buffer(dyn_buffer *pBody, size_t new_size) +{ + /* return error if new_size tries to exceed max defined size */ + if (new_size > pBody->bufferMaxSize) + return -1; + while (pBody->bufferAllocSize < new_size) + pBody->bufferAllocSize += INITIAL_BUFFER_SIZE; + + DBGPRINTF("mmdarwin::expand_buffer:: expanding buffer to %zu\n", pBody->bufferAllocSize); + + char *tmp = realloc(pBody->buffer, pBody->bufferAllocSize * sizeof(char)); + + if (!tmp) + { + DBGPRINTF("mmdarwin::expand_buffer:: could not resize buffer\n"); + return -1; + } + + pBody->buffer = tmp; + return 0; +} + +/** + * adds a field to the dyn_buffer buffer + * + * params: + * - pBody: the pointer on the dyn_buffer structure + * - field: the potentially not null-terminated string to add as a field to the dyn_buffer + * - size: the size of the string (without the '\0' character) + * + * return: 0 if the field was indeed added to the dyn_buffer, -1 otherwise + */ +int add_field_to_body(dyn_buffer *pBody, const char *field, size_t size) +{ + /* get required additional size for field, quotes, colon, and \0 + and potentially also for the beginning of the message structure */ + int beginning = (pBody->bufferMsgSize == 0) ? 2 : 0; + size_t requiredBodySize = pBody->bufferMsgSize + size + 4 + beginning; + + /* resize body buffer if necessary */ + if (requiredBodySize > pBody->bufferAllocSize) + { + if (expand_buffer(pBody, requiredBodySize) != 0) + { + return -1; + } + } + + /* add message structure beginning if current message is empty */ + if (!pBody->bufferMsgSize) + { + pBody->buffer[0] = '['; + pBody->buffer[1] = '['; + pBody->bufferMsgSize += 2; + } + + /* add field with quotes and colon */ + pBody->buffer[pBody->bufferMsgSize++] = '\"'; + memcpy((void *)&pBody->buffer[pBody->bufferMsgSize], (const void *)field, size); + pBody->bufferMsgSize += size; + pBody->buffer[pBody->bufferMsgSize++] = '\"'; + pBody->buffer[pBody->bufferMsgSize++] = ','; + + return 0; +} + +/** + * small helper function to start a new input line (used for bulk-calls) in the dyn_buffer. + * will close current line with a ']' and start the next with a '['. + * will also remove leading ',' in fields list. + * + * params: + * - pBody: the pointer on the dyn_buffer on which to start a new input line + * + * return: 0 if successful, -1 otherwise + */ +int start_new_line(dyn_buffer *pBody) +{ + /* don't if the message is empty */ + if (!pBody->bufferMsgSize) + { + return -1; + } + + DBGPRINTF("mmdarwin::start_new_line:: starting new line entry in body\n"); + + if (pBody->bufferAllocSize < pBody->bufferMsgSize + 2) + { + if (expand_buffer(pBody, pBody->bufferAllocSize + 2) != 0) + { + return -1; + } + } + + pBody->buffer[pBody->bufferMsgSize - 1] = ']'; + pBody->buffer[pBody->bufferMsgSize++] = ','; + pBody->buffer[pBody->bufferMsgSize++] = '['; + return 0; +} + +/** + * small helper function to close the dyn_buffer structure. + * will close the line list with two ']' and will remove the leading ',' in the fields list + * + * params: + * - pBody: the pointer on the dyn_buffer on which to start a new input line + * + * return: 0 if successful, -1 otherwise + */ +int end_body(dyn_buffer *pBody) +{ + /* don't if the message is empty */ + if (!pBody->bufferMsgSize) + { + return -1; + } + + DBGPRINTF("mmdarwin::end_body:: finishing body structure\n"); + + if (pBody->bufferAllocSize < pBody->bufferMsgSize + 2) + { + if (expand_buffer(pBody, pBody->bufferAllocSize + 2) != 0) + { + return -1; + } + } + + pBody->buffer[pBody->bufferMsgSize - 1] = ']'; + pBody->buffer[pBody->bufferMsgSize++] = ']'; + pBody->buffer[pBody->bufferMsgSize++] = '\0'; + return 0; +} + +/** + * Get the potential existing uuid put by previous mmdarwin call in a json + * + * params: + * - pJson: the pointer on the json + * + * return: a valid json_object pointer if found, NULL otherwise + */ +const char* get_uuid_object(smsg_t *const pMsg) { + struct json_object *mmdarwin_object = NULL; + const char *result = NULL, *key = NULL; + + msgPropDescr_t propDesc; + msgPropDescrFill(&propDesc, (uchar *)runModConf->container, strlen(runModConf->container)); + msgGetJSONPropJSON(pMsg, &propDesc, &mmdarwin_object); + + if(mmdarwin_object) { + struct json_object_iterator it = json_object_iter_begin(mmdarwin_object); + struct json_object_iterator itEnd = json_object_iter_end(mmdarwin_object); + + while(!json_object_iter_equal(&it, &itEnd)) { + key = json_object_iter_peek_name(&it); + + if(!strcmp(key, JSON_DARWIN_ID)) { + // should always be a (non-empty) null-terminated string, safe to use with strdup() + result = strdup(json_object_get_string(json_object_iter_peek_value(&it))); + break; + } + + json_object_iter_next(&it); + } + json_object_put(mmdarwin_object); + } + + msgPropDescrDestruct(&propDesc); + return result; +} + +BEGINbeginCnfLoad +CODESTARTbeginCnfLoad + loadModConf = pModConf; +pModConf->pConf = pConf; +ENDbeginCnfLoad + +BEGINendCnfLoad +CODESTARTendCnfLoad +ENDendCnfLoad + +BEGINcheckCnf +CODESTARTcheckCnf +ENDcheckCnf + +BEGINactivateCnf +CODESTARTactivateCnf + runModConf = pModConf; +ENDactivateCnf + +BEGINfreeCnf +CODESTARTfreeCnf + free((void *)pModConf->container); +ENDfreeCnf + +BEGINdbgPrintInstInfo +CODESTARTdbgPrintInstInfo + DBGPRINTF("%s\n", pData->pSockName); +ENDdbgPrintInstInfo + +BEGINcreateInstance +CODESTARTcreateInstance +ENDcreateInstance + +BEGINcreateWrkrInstance +CODESTARTcreateWrkrInstance + pWrkrData->pktSentSocket = 0; + pWrkrData->darwinBody.bufferAllocSize = 0; + pWrkrData->darwinBody.bufferMaxSize = BUFFER_DEFAULT_MAX_SIZE; + pWrkrData->darwinBody.bufferMsgSize = 0; + pWrkrData->sock = INVLD_SOCK; +ENDcreateWrkrInstance + +BEGINisCompatibleWithFeature +CODESTARTisCompatibleWithFeature +ENDisCompatibleWithFeature + +BEGINfreeInstance +CODESTARTfreeInstance + if (pData->fieldList.name != NULL) + { + for (int i = 0; i < pData->fieldList.nmemb; ++i) + { + free(pData->fieldList.name[i]); + free(pData->fieldList.varname[i]); + } + free(pData->fieldList.name); + free(pData->fieldList.varname); + } + free(pData->pUUIDKey); + free(pData->pCertitudeKey); + free(pData->pSockName); +ENDfreeInstance + +BEGINfreeWrkrInstance +CODESTARTfreeWrkrInstance + closeSocket(pWrkrData); + free(pWrkrData->darwinBody.buffer); +ENDfreeWrkrInstance + +BEGINsetModCnf +struct cnfparamvals *pvals = NULL; +int i; +CODESTARTsetModCnf + loadModConf->container = NULL; + pvals = nvlstGetParams(lst, &modpblk, NULL); + if (pvals == NULL) + { + LogError(0, RS_RET_MISSING_CNFPARAMS, + "mmdarwin: error processing module config parameters missing [module(...)]"); + ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS); + } + if (Debug) + { + DBGPRINTF("mmdarwin::setModCnf:: module (global) param blk for mmdarwin:\n"); + cnfparamsPrint(&modpblk, pvals); + } + + for (i = 0; i < modpblk.nParams; ++i) + { + if (!pvals[i].bUsed) + continue; + if (!strcmp(modpblk.descr[i].name, "container")) + { + loadModConf->container = es_str2cstr(pvals[i].val.d.estr, NULL); + if(loadModConf->container[0] != '!' && loadModConf->container[0] != '.') { + LogError(0, RS_RET_INVALID_PARAMS, "mmdarwin: container should either" + " begin with '!' or '.'\n"); + ABORT_FINALIZE(RS_RET_INVALID_PARAMS); + } + } + else + { + DBGPRINTF("mmdarwin::setModCnf:: program error, non-handled " + "param '%s'\n", + modpblk.descr[i].name); + } + } + + if (loadModConf->container == NULL) + { + CHKmalloc(loadModConf->container = strdup(JSON_DEFAULT_CONTAINER)); + } + +finalize_it : + if (pvals != NULL) + cnfparamvalsDestruct(pvals, &modpblk); +ENDsetModCnf + +static inline void setInstParamDefaults(instanceData *pData) +{ + DBGPRINTF("mmdarwin::setInstParamDefaults::\n"); + pData->pUUIDKey = NULL; + pData->pCertitudeKey = NULL; + pData->pSockName = NULL; + pData->fieldList.nmemb = 0; + pData->filterCode = DARWIN_FILTER_CODE_NO; + pData->response = DARWIN_RESPONSE_SEND_NO; + pData->socketMaxUse = 0; + pData->sendPartial = 0; +} + +BEGINnewActInst + struct cnfparamvals *pvals; + int i; +CODESTARTnewActInst + DBGPRINTF("mmdarwin::newActInst::\n"); + if ((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL) + { + ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS); + } + + CODE_STD_STRING_REQUESTnewActInst(1) + CHKiRet(OMSRsetEntry(*ppOMSR, 0, NULL, OMSR_TPL_AS_MSG)); + CHKiRet(createInstance(&pData)); + setInstParamDefaults(pData); + + for (i = 0; i < actpblk.nParams; ++i) + { + if (!pvals[i].bUsed) + continue; + + if (!strcmp(actpblk.descr[i].name, "key")) + { + char *key = es_str2cstr(pvals[i].val.d.estr, NULL); + char vnamebuf[1024]; + snprintf(vnamebuf, sizeof(vnamebuf), "%s!%s", loadModConf->container, key); + CHKmalloc(pData->pCertitudeKey = strdup(vnamebuf)); + free(key); + DBGPRINTF("mmdarwin::newActInst:: certitudeKey is %s\n", pData->pCertitudeKey); + } + else if (!strcmp(actpblk.descr[i].name, "socketpath")) + { + pData->pSockName = (uchar *)es_str2cstr(pvals[i].val.d.estr, NULL); + DBGPRINTF("mmdarwin::newActInst:: sockName is %s\n", pData->pSockName); + } + else if (!strcmp(actpblk.descr[i].name, "socket_max_use")) + { + pData->socketMaxUse = (uint32_t)pvals[i].val.d.n; + DBGPRINTF("mmdarwin::newActInst:: socketMaxUse is %d\n", pData->socketMaxUse); + } + else if (!strcmp(actpblk.descr[i].name, "send_partial")) + { + pData->sendPartial = (sbool)pvals[i].val.d.n; + if (pData->sendPartial) + { + DBGPRINTF("mmdarwin::newActInst:: sending bodies even if fields are missing\n"); + } + else + { + DBGPRINTF("mmdarwin::newActInst:: only sending complete bodies\n"); + } + } + else if (!strcmp(actpblk.descr[i].name, "response")) + { + char *response = es_str2cstr(pvals[i].val.d.estr, NULL); + + if (!strcmp(response, "no")) + { + pData->response = DARWIN_RESPONSE_SEND_NO; + DBGPRINTF("mmdarwin::newActInst:: response type is 'no'\n"); + } + else if (!strcmp(response, "back")) + { + pData->response = DARWIN_RESPONSE_SEND_BACK; + DBGPRINTF("mmdarwin::newActInst:: response type is 'back'\n"); + } + else if (!strcmp(response, "darwin")) + { + pData->response = DARWIN_RESPONSE_SEND_DARWIN; + DBGPRINTF("mmdarwin::newActInst:: response type is 'darwin'\n"); + } + else if (!strcmp(response, "both")) + { + pData->response = DARWIN_RESPONSE_SEND_BOTH; + DBGPRINTF("mmdarwin::newActInst:: response type is 'both'\n"); + } + else + { + DBGPRINTF( + "mmdarwin::newActInst:: invalid 'response' value: %s. 'No response' set.\n", + response); + + pData->response = DARWIN_RESPONSE_SEND_NO; + DBGPRINTF("mmdarwin::newActInst:: response type is 'no'\n"); + } + + free(response); + } + else if (!strcmp(actpblk.descr[i].name, "filtercode")) + { + char *filterCode = es_str2cstr(pvals[i].val.d.estr, NULL); + pData->filterCode = strtoull(filterCode, NULL, 16); + free(filterCode); + } + else if (!strcmp(actpblk.descr[i].name, "fields")) + { + pData->fieldList.nmemb = pvals[i].val.d.ar->nmemb; + CHKmalloc(pData->fieldList.name = calloc(pData->fieldList.nmemb, sizeof(char *))); + CHKmalloc(pData->fieldList.varname = calloc(pData->fieldList.nmemb, sizeof(char *))); + + for (int j = 0; j < pData->fieldList.nmemb; ++j) + { + char *const param = es_str2cstr(pvals[i].val.d.ar->arr[j], NULL); + char *varname = NULL; + char *name; + if (*param == ':') + { + char *b = strchr(param + 1, ':'); + if (b == NULL) + { + parser_errmsg( + "mmdarwin::newActInst:: missing closing colon: '%s'", param); + ABORT_FINALIZE(RS_RET_ERR); + } + + *b = '\0'; /* split name & varname */ + varname = param + 1; + name = b + 1; + } + else + { + name = param; + } + CHKmalloc(pData->fieldList.name[j] = strdup(name)); + char vnamebuf[1024]; + snprintf(vnamebuf, sizeof(vnamebuf), + "%s!%s", loadModConf->container, + (varname == NULL) ? name : varname); + CHKmalloc(pData->fieldList.varname[j] = strdup(vnamebuf)); + free(param); + DBGPRINTF("mmdarwin::newActInst:: will look for field %s\n", pData->fieldList.name[j]); + } + } + else + { + DBGPRINTF( + "mmdarwin::newActInst:: program error, non-handled param '%s'\n", actpblk.descr[i].name); + } + } + + // reserve space for 'container!key\0' + size_t sizeKey = strlen(loadModConf->container) + strlen(JSON_DARWIN_ID) + 2; + pData->pUUIDKey = malloc(sizeKey); + snprintf(pData->pUUIDKey, sizeKey, "%s!%s", loadModConf->container, JSON_DARWIN_ID); + DBGPRINTF("mmdarwin:: uuid key is %s\n", pData->pUUIDKey); + +CODE_STD_FINALIZERnewActInst + cnfparamvalsDestruct(pvals, &actpblk); +ENDnewActInst + +BEGINtryResume +CODESTARTtryResume + iRet = doTryResume(pWrkrData); +ENDtryResume + +BEGINdoAction_NoStrings + smsg_t **ppMsg = (smsg_t **)pMsgData; /* the raw data */ + smsg_t *pMsg = ppMsg[0]; /* the raw log line */ + instanceData *pData = pWrkrData->pData; /* the parameters given for the plugin */ + char *pFieldValue = NULL; /* ponter to the found field value */ + int fieldsNum = 0; /* number of fields retrieved */ + +CODESTARTdoAction + DBGPRINTF("mmdarwin::doAction:: beggining action\n"); + pWrkrData->darwinBody.bufferMsgSize = 0; + fieldsNum = 0; + + for (int i = 0; i < pData->fieldList.nmemb; i++) + { + DBGPRINTF("mmdarwin::doAction:: processing field '%s'\n", pData->fieldList.name[i]); + pFieldValue = NULL; + + /* case 1: static field. We simply forward it to Darwin */ + if (pData->fieldList.name[i][0] != '!' && pData->fieldList.name[i][0] != '.') + { + pFieldValue = strdup(pData->fieldList.name[i]); + } + /* case 2: dynamic field. We retrieve its value from the JSON logline and forward it to + * Darwin */ + else + { + if (!get_field(pMsg, pData->fieldList.name[i], &pFieldValue)) + { + DBGPRINTF("mmdarwin::doAction:: \ +could not extract field '%s' from message\n", pData->fieldList.name[i]); + continue; + } + } + + DBGPRINTF( + "mmdarwin::doAction:: got value of field '%s': '%s'\n", pData->fieldList.name[i], pFieldValue); + + if (add_field_to_body(&(pWrkrData->darwinBody), pFieldValue, strlen(pFieldValue)) != 0) + { + DBGPRINTF("mmdarwin::doAction:: could not add field to body, aborting\n"); + free(pFieldValue); + ABORT_FINALIZE(RS_RET_ERR); + } + + fieldsNum++; + free(pFieldValue); + } + + if (fieldsNum) + { + if (!pData->sendPartial && fieldsNum != pData->fieldList.nmemb) + { + DBGPRINTF("mmdarwin::doAction:: not all fields could be retrieved, not sending partial message." + " (if you wish to send partial messages anyway, set 'send_partial' to 'on' in instance parameters)\n"); + FINALIZE; + } + if (end_body(&(pWrkrData->darwinBody)) != 0) + ABORT_FINALIZE(RS_RET_ERR); + } + else + { + DBGPRINTF("mmdarwin::doAction:: no fields retrieved, finalizing\n"); + FINALIZE; + } + + DBGPRINTF("mmdarwin::doAction:: body to send: '%s'\n", pWrkrData->darwinBody.buffer); + + if (pData->socketMaxUse) + { + /* need to rotate socket connections */ + if (!pWrkrData->pktSentSocket) + { + DBGPRINTF("mmdarwin::doAction:: opening a new connection\n"); + CHKiRet(doTryResume(pWrkrData)); + } + pWrkrData->pktSentSocket = (pWrkrData->pktSentSocket + 1) % pData->socketMaxUse; + } + + /* the Darwin header to be sent to the filter */ + darwin_filter_packet_t header = { + .type = DARWIN_PACKET_OTHER, + .response = pData->response, + .filter_code = pData->filterCode, + .body_size = pWrkrData->darwinBody.bufferMsgSize}; + + const char *uuid = get_uuid_object(pMsg); + if(uuid) { + DBGPRINTF("mmdarwin: using existing UUID = %s\n", uuid); + if(uuid_parse(uuid, header.evt_id)) + LogError(0, RS_RET_ERR, "mmdarwin:: failed to parse existing UUID: %s\n", uuid); + free((void*)uuid); + } + else { + uuid_generate(header.evt_id); + char uuidStr[40]; + uuid_unparse(header.evt_id, uuidStr); + DBGPRINTF("mmdarwin: generated new UUID = %s\n", uuidStr); + msgAddJSON(pMsg, (uchar *)pData->pUUIDKey, json_object_new_string(uuidStr), 0, 0); + } + + DBGPRINTF("mmdarwin::doAction:: sending header to Darwin\n"); + CHKiRet(sendMsg(pWrkrData, &header, sizeof(darwin_filter_packet_t))); + + DBGPRINTF("mmdarwin::doAction:: sending body to Darwin\n"); + CHKiRet(sendMsg(pWrkrData, (void *)(pWrkrData->darwinBody.buffer), pWrkrData->darwinBody.bufferMsgSize)); + + /* there is no need to wait for a response that will never come */ + if (pData->response == DARWIN_RESPONSE_SEND_NO || pData->response == DARWIN_RESPONSE_SEND_DARWIN) + { + DBGPRINTF("mmdarwin::doAction:: no response will be sent back " + "(darwin response type is set to 'no' or 'darwin')\n"); + goto finalize_it; + } + + darwin_filter_packet_t response; + memset(&response, 0, sizeof(response)); + DBGPRINTF("mmdarwin::doAction:: receiving from Darwin\n"); + CHKiRet(receiveMsg(pWrkrData, &response, sizeof(response))); + + unsigned int certitude = response.certitude_list[0]; + DBGPRINTF("mmdarwin::doAction:: end of the transaction, certitude is %d\n", certitude); + + msgAddJSON(pMsg, (uchar *)pData->pCertitudeKey, json_object_new_int(certitude), 0, 0); + +finalize_it : + DBGPRINTF("mmdarwin::doAction:: finished processing log line\n"); + +ENDdoAction + +NO_LEGACY_CONF_parseSelectorAct + +BEGINmodExit +CODESTARTmodExit + objRelease(glbl, CORE_COMPONENT); +ENDmodExit + +BEGINqueryEtryPt +CODESTARTqueryEtryPt +CODEqueryEtryPt_STD_OMOD_QUERIES +CODEqueryEtryPt_STD_OMOD8_QUERIES +CODEqueryEtryPt_STD_CONF2_setModCnf_QUERIES +CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES +CODEqueryEtryPt_STD_CONF2_QUERIES +ENDqueryEtryPt + +BEGINmodInit() +CODESTARTmodInit + /* we only support the current interface specification */ + *ipIFVersProvided = CURR_MOD_IF_VERSION; +CODEmodInit_QueryRegCFSLineHdlr + DBGPRINTF("mmdarwin::modInit:: module compiled with rsyslog version %s.\n", VERSION); + CHKiRet(objUse(glbl, CORE_COMPONENT)); +ENDmodInit diff --git a/contrib/mmdarwin/protocol.h b/contrib/mmdarwin/protocol.h new file mode 100644 index 0000000..fce211f --- /dev/null +++ b/contrib/mmdarwin/protocol.h @@ -0,0 +1,70 @@ +/* Copyright 2019 Advens + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef DARWIN_PROTOCOL_H +#define DARWIN_PROTOCOL_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include <stddef.h> +#include <netinet/in.h> + +#define DARWIN_FILTER_CODE_NO 0x00000000 +// the default certitude list size, which is 1, to allow FMAs (see flexible array members on C99) for both C and C++ +// code +#define DEFAULT_CERTITUDE_LIST_SIZE 1 + + /// Represent the receiver of the results. + /// + /// \enum darwin_response_type + enum darwin_filter_response_type + { + DARWIN_RESPONSE_SEND_NO = 0, //!< Don't send results to anybody. + DARWIN_RESPONSE_SEND_BACK, //!< Send results back to caller. + DARWIN_RESPONSE_SEND_DARWIN, //!< Send results to the next filter. + DARWIN_RESPONSE_SEND_BOTH, //!< Send results to both caller and the next filter. + }; + + /// Represent the type of information sent. + /// + /// \enum darwin_packet_type + enum darwin_packet_type + { + DARWIN_PACKET_OTHER = 0, //!< Information sent by something else. + DARWIN_PACKET_FILTER, //!< Information sent by another filter. + }; + + /// First packet to be sent to a filter. + /// + /// \struct darwin_filter_packet_t + typedef struct + { + enum darwin_packet_type type; //!< The type of information sent. + enum darwin_filter_response_type response; //!< Whom the response will be sent to. + long filter_code; //!< The unique identifier code of a filter. + size_t body_size; //!< The complete size of the the parameters to be sent + unsigned char evt_id[16]; //!< An array containing the event ID + size_t certitude_size; //!< The size of the list containing the certitudes. + unsigned int certitude_list[DEFAULT_CERTITUDE_LIST_SIZE]; + //!< The scores or the certitudes of the module. May be used to pass other info in specific cases. + } darwin_filter_packet_t; + +#ifdef __cplusplus +}; +#endif + +#endif /* !DARWIN_PROTOCOL_H */ |