From adc541dedd58c94a1fbd7d571be10237ecf4ec38 Mon Sep 17 00:00:00 2001 From: laforge Date: Mon, 20 Nov 2000 19:36:25 +0000 Subject: mysql autoconf detection --- ulogd/Makefile.in | 10 +- ulogd/Rules.make.in | 13 +- ulogd/aclocal.m4 | 130 ++++++++++++++++++ ulogd/conffile/Makefile.in | 2 + ulogd/configure | 219 +++++++++++++++++++++-------- ulogd/configure.in | 78 ++++++++++- ulogd/doc/Makefile.in | 2 + ulogd/extensions/Makefile.in | 8 +- ulogd/extensions/ulogd_MYSQL.c | 298 ---------------------------------------- ulogd/libipulog.old/Makefile.in | 2 + ulogd/libipulog/Makefile.in | 2 + ulogd/mysql/Makefile.in | 26 ++++ ulogd/mysql/ulogd_MYSQL.c | 298 ++++++++++++++++++++++++++++++++++++++++ 13 files changed, 715 insertions(+), 373 deletions(-) create mode 100644 ulogd/aclocal.m4 delete mode 100644 ulogd/extensions/ulogd_MYSQL.c create mode 100644 ulogd/mysql/Makefile.in create mode 100644 ulogd/mysql/ulogd_MYSQL.c (limited to 'ulogd') diff --git a/ulogd/Makefile.in b/ulogd/Makefile.in index 54a8416..05570e7 100644 --- a/ulogd/Makefile.in +++ b/ulogd/Makefile.in @@ -5,9 +5,10 @@ CFLAGS+=-I@top_srcdir@/libipulog/include -I@top_srcdir@/conffile SUBDIRS=conffile libipulog extensions doc -prefix=@prefix@ -exec_prefix=@exec_prefix@ -sysconfdir=@sysconfdir@ +ifeq (x@MYSQLINCLUDES@,x) +else +SUBDIRS+=mysql +endif # Normally You should not need to change anything below @@ -29,8 +30,7 @@ distclean: clean rm -f Makefile config.cache config.log config.status Rules.make install: all - @INSTALL@ -m 755 -d @libdir@/ulogd - @INSTALL@ -m 644 extensions/*.so @libdir@/ulogd + @for d in $(SUBDIRS); do if ! make -C $$d $@; then exit 1; fi; done @INSTALL@ -m 755 ulogd @sbindir@/ulogd @INSTALL@ -m 600 ulogd.conf @sysconfdir@/ulogd.conf diff --git a/ulogd/Rules.make.in b/ulogd/Rules.make.in index 6c40d98..ac8e0c9 100644 --- a/ulogd/Rules.make.in +++ b/ulogd/Rules.make.in @@ -1,5 +1,11 @@ # +prefix=@prefix@ +exec_prefix=@exec_prefix@ +sysconfdir=@sysconfdir@ + +ULOGD_LIB_PATH=@libdir@/ulogd + CC=@CC@ CFLAGS=@CFLAGS@ @CPPFLAGS@ CFLAGS+=$(INCIPULOG) $(INCCONFFILE) @@ -19,6 +25,7 @@ LIBIPULOG=@top_srcdir@/libipulog ULOGD_SL:=BASE OPRINT PWSNIFF LOGEMU # mysql output support -ULOGD_SL+=MYSQL -MYSQL_CFLAGS= -MYSQL_LDFLAGS=-L/usr/lib/mysql -lmysqlclient +#ULOGD_SL+=MYSQL +MYSQL_CFLAGS=-I@MYSQLINCLUDES@ +MYSQL_LDFLAGS=@DATABASE_LIB_DIR@ @DATABASE_LIB@ + diff --git a/ulogd/aclocal.m4 b/ulogd/aclocal.m4 new file mode 100644 index 0000000..368464b --- /dev/null +++ b/ulogd/aclocal.m4 @@ -0,0 +1,130 @@ +dnl aclocal.m4 generated automatically by aclocal 1.4 + +dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +dnl aclocal.m4 generated automatically by aclocal 1.4 + +dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +# Do all the work for Automake. This macro actually does too much -- +# some checks are only needed if your package does certain things. +# But this isn't really a big deal. + +# serial 1 + +dnl Usage: +dnl AM_INIT_AUTOMAKE(package,version, [no-define]) + +AC_DEFUN(AM_INIT_AUTOMAKE, +[AC_REQUIRE([AC_PROG_INSTALL]) +PACKAGE=[$1] +AC_SUBST(PACKAGE) +VERSION=[$2] +AC_SUBST(VERSION) +dnl test to see if srcdir already configured +if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) +fi +ifelse([$3],, +AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) +AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])) +AC_REQUIRE([AM_SANITY_CHECK]) +AC_REQUIRE([AC_ARG_PROGRAM]) +dnl FIXME This is truly gross. +missing_dir=`cd $ac_aux_dir && pwd` +AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) +AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) +AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) +AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) +AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) +AC_REQUIRE([AC_PROG_MAKE_SET])]) + +# +# Check to make sure that the build environment is sane. +# + +AC_DEFUN(AM_SANITY_CHECK, +[AC_MSG_CHECKING([whether build environment is sane]) +# Just in case +sleep 1 +echo timestamp > conftestfile +# Do `set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` + if test "[$]*" = "X"; then + # -L didn't work. + set X `ls -t $srcdir/configure conftestfile` + fi + if test "[$]*" != "X $srcdir/configure conftestfile" \ + && test "[$]*" != "X conftestfile $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken +alias in your environment]) + fi + + test "[$]2" = conftestfile + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +rm -f conftest* +AC_MSG_RESULT(yes)]) + +dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY) +dnl The program must properly implement --version. +AC_DEFUN(AM_MISSING_PROG, +[AC_MSG_CHECKING(for working $2) +# Run test in a subshell; some versions of sh will print an error if +# an executable is not found, even if stderr is redirected. +# Redirect stdin to placate older versions of autoconf. Sigh. +if ($2 --version) < /dev/null > /dev/null 2>&1; then + $1=$2 + AC_MSG_RESULT(found) +else + $1="$3/missing $2" + AC_MSG_RESULT(missing) +fi +AC_SUBST($1)]) + + +# Define a conditional. + +AC_DEFUN(AM_CONDITIONAL, +[AC_SUBST($1_TRUE) +AC_SUBST($1_FALSE) +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi]) + diff --git a/ulogd/conffile/Makefile.in b/ulogd/conffile/Makefile.in index b91723e..746a46b 100644 --- a/ulogd/conffile/Makefile.in +++ b/ulogd/conffile/Makefile.in @@ -14,3 +14,5 @@ clean: distclean: rm -f Makefile + +install: all diff --git a/ulogd/configure b/ulogd/configure index 290272d..5238573 100755 --- a/ulogd/configure +++ b/ulogd/configure @@ -11,6 +11,8 @@ ac_help= ac_default_prefix=/usr/local # Any additions from configure.in: +ac_help="$ac_help +--with-mysql= use mysql backend in " # Initialize some variables set by options. # The variables have the same names as the options, with @@ -523,7 +525,7 @@ fi echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 -echo "configure:527: checking whether ${MAKE-make} sets \${MAKE}" >&5 +echo "configure:529: checking whether ${MAKE-make} sets \${MAKE}" >&5 set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -552,7 +554,7 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:556: checking for $ac_word" >&5 +echo "configure:558: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -582,7 +584,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:586: checking for $ac_word" >&5 +echo "configure:588: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -633,7 +635,7 @@ fi # Extract the first word of "cl", so it can be a program name with args. set dummy cl; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:637: checking for $ac_word" >&5 +echo "configure:639: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -665,7 +667,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:669: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:671: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -676,12 +678,12 @@ cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF -#line 680 "configure" +#line 682 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:685: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:687: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -707,12 +709,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:711: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:713: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:716: checking whether we are using GNU C" >&5 +echo "configure:718: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -721,7 +723,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:725: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:727: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -740,7 +742,7 @@ ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:744: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:746: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -802,7 +804,7 @@ ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:806: checking for a BSD compatible install" >&5 +echo "configure:808: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -856,7 +858,7 @@ test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6 -echo "configure:860: checking for dlopen in -ldl" >&5 +echo "configure:862: checking for dlopen in -ldl" >&5 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -864,7 +866,7 @@ else ac_save_LIBS="$LIBS" LIBS="-ldl $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:881: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -908,12 +910,12 @@ for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr that defines DIR""... $ac_c" 1>&6 -echo "configure:912: checking for $ac_hdr that defines DIR" >&5 +echo "configure:914: checking for $ac_hdr that defines DIR" >&5 if eval "test \"`echo '$''{'ac_cv_header_dirent_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include <$ac_hdr> @@ -921,7 +923,7 @@ int main() { DIR *dirp = 0; ; return 0; } EOF -if { (eval echo configure:925: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:927: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* eval "ac_cv_header_dirent_$ac_safe=yes" else @@ -946,7 +948,7 @@ done # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix. if test $ac_header_dirent = dirent.h; then echo $ac_n "checking for opendir in -ldir""... $ac_c" 1>&6 -echo "configure:950: checking for opendir in -ldir" >&5 +echo "configure:952: checking for opendir in -ldir" >&5 ac_lib_var=`echo dir'_'opendir | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -954,7 +956,7 @@ else ac_save_LIBS="$LIBS" LIBS="-ldir $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:971: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -987,7 +989,7 @@ fi else echo $ac_n "checking for opendir in -lx""... $ac_c" 1>&6 -echo "configure:991: checking for opendir in -lx" >&5 +echo "configure:993: checking for opendir in -lx" >&5 ac_lib_var=`echo x'_'opendir | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -995,7 +997,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lx $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1012: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1029,7 +1031,7 @@ fi fi echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1033: checking how to run the C preprocessor" >&5 +echo "configure:1035: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1044,13 +1046,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1054: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1056: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1061,13 +1063,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1071: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1073: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1078,13 +1080,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1088: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1090: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1109,12 +1111,12 @@ fi echo "$ac_t""$CPP" 1>&6 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1113: checking for ANSI C header files" >&5 +echo "configure:1115: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -1122,7 +1124,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1126: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1128: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1139,7 +1141,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1157,7 +1159,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1178,7 +1180,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1189,7 +1191,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1193: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1195: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else @@ -1216,17 +1218,17 @@ for ac_hdr in fcntl.h unistd.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1220: checking for $ac_hdr" >&5 +echo "configure:1222: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1230: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1232: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1254,12 +1256,12 @@ done echo $ac_n "checking for working const""... $ac_c" 1>&6 -echo "configure:1258: checking for working const" >&5 +echo "configure:1260: checking for working const" >&5 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1314: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_const=yes else @@ -1329,12 +1331,12 @@ EOF fi echo $ac_n "checking for size_t""... $ac_c" 1>&6 -echo "configure:1333: checking for size_t" >&5 +echo "configure:1335: checking for size_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #if STDC_HEADERS @@ -1362,12 +1364,12 @@ EOF fi echo $ac_n "checking whether struct tm is in sys/time.h or time.h""... $ac_c" 1>&6 -echo "configure:1366: checking whether struct tm is in sys/time.h or time.h" >&5 +echo "configure:1368: checking whether struct tm is in sys/time.h or time.h" >&5 if eval "test \"`echo '$''{'ac_cv_struct_tm'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -1375,7 +1377,7 @@ int main() { struct tm *tp; tp->tm_sec; ; return 0; } EOF -if { (eval echo configure:1379: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1381: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_struct_tm=time.h else @@ -1397,12 +1399,12 @@ fi echo $ac_n "checking for vprintf""... $ac_c" 1>&6 -echo "configure:1401: checking for vprintf" >&5 +echo "configure:1403: checking for vprintf" >&5 if eval "test \"`echo '$''{'ac_cv_func_vprintf'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1431: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_vprintf=yes" else @@ -1449,12 +1451,12 @@ fi if test "$ac_cv_func_vprintf" != yes; then echo $ac_n "checking for _doprnt""... $ac_c" 1>&6 -echo "configure:1453: checking for _doprnt" >&5 +echo "configure:1455: checking for _doprnt" >&5 if eval "test \"`echo '$''{'ac_cv_func__doprnt'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1483: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__doprnt=yes" else @@ -1504,12 +1506,12 @@ fi for ac_func in socket strerror do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1508: checking for $ac_func" >&5 +echo "configure:1510: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1538: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1557,6 +1559,95 @@ fi done +DATABASE_DIR="" +DATABASE_LIB="" +DATABASE_LIB_DIR="" + +DATABASE_DRIVERS="" + +# Check whether --with-mysql or --without-mysql was given. +if test "${with_mysql+set}" = set; then + withval="$with_mysql" + +if test $withval != yes +then + dir=$withval +else + dir="/usr/local" +fi +mysqldir="" +echo $ac_n "checking for MySQL files""... $ac_c" 1>&6 +echo "configure:1581: checking for MySQL files" >&5 +for d in $dir /usr /usr/local /usr/local/mysql /opt/mysql /opt/packages/mysql +do + if test -f $d/lib/mysql/libmysqlclient.a + then + echo "$ac_t""found mysql in $d" 1>&6 + mysqldir=$d + mysqldir_suffix=/mysql + break + fi + if test -f $d/lib/libmysqlclient.a + then + echo "$ac_t""found mysql in $d" 1>&6 + mysqldir=$d + mysqldir_suffix= + break + fi +done + +if test x$mysqldir = x +then + echo "configure: warning: MySQL backend not used" 1>&2 +else + cat >> confdefs.h <<\EOF +#define HAVE_MYSQL 1 +EOF + + MYSQLINCLUDES=${mysqldir}/include${mysqldir_suffix} + MYSQLLIBS=${mysqldir}/lib${mysqldir_suffix} + + DATABASE_DIR="${DATABASE_DIR} mysql" + + DATABASE_LIB="${DATABASE_LIB} -lmysqlclient " + DATABASE_LIB_DIR="${DATABASE_LIB_DIR} -L${MYSQLLIBS} " + + DATABASE_DRIVERS="${DATABASE_DRIVERS} ../mysql/mysql_driver.o " + + DB_DEF="${DB_DEF} -DHAVE_MYSQL " + + + + + if test -f $MYSQLLIBS/libmystrings.a + then + DATABASE_LIB="${DATABASE_LIB} -lmystrings " + else + MYSQLEXTRALIBS= + fi +fi + +fi + + + + + + + + + + + +if test x$mysqldir != x; then + HAVE_MYSQL_TRUE= + HAVE_MYSQL_FALSE='#' +else + HAVE_MYSQL_TRUE='#' + HAVE_MYSQL_FALSE= +fi + + trap '' 1 2 15 cat > confcache <<\EOF # This file is a shell script that caches the results of configure @@ -1670,7 +1761,7 @@ done ac_given_srcdir=$srcdir ac_given_INSTALL="$INSTALL" -trap 'rm -fr `echo "extensions/Makefile doc/Makefile conffile/Makefile libipulog/Makefile Makefile Rules.make" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 +trap 'rm -fr `echo "extensions/Makefile doc/Makefile conffile/Makefile libipulog/Makefile mysql/Makefile Makefile Rules.make" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then diff --git a/ulogd/configure.in b/ulogd/configure.in index e37c4b9..da22cd8 100644 --- a/ulogd/configure.in +++ b/ulogd/configure.in @@ -23,4 +23,80 @@ dnl Checks for library functions. AC_FUNC_VPRINTF AC_CHECK_FUNCS(socket strerror) -AC_OUTPUT(extensions/Makefile doc/Makefile conffile/Makefile libipulog/Makefile Makefile Rules.make) +DATABASE_DIR="" +DATABASE_LIB="" +DATABASE_LIB_DIR="" + +DATABASE_DRIVERS="" + +dnl +dnl test for MySQL +dnl +AC_ARG_WITH(mysql, + --with-mysql= use mysql backend in ,[ +if test $withval != yes +then + dir=$withval +else + dir="/usr/local" +fi +mysqldir="" +AC_MSG_CHECKING(for MySQL files) +for d in $dir /usr /usr/local /usr/local/mysql /opt/mysql /opt/packages/mysql +do + if test -f $d/lib/mysql/libmysqlclient.a + then + AC_MSG_RESULT(found mysql in $d) + mysqldir=$d + mysqldir_suffix=/mysql + break + fi + if test -f $d/lib/libmysqlclient.a + then + AC_MSG_RESULT(found mysql in $d) + mysqldir=$d + mysqldir_suffix= + break + fi +done + +if test x$mysqldir = x +then + AC_MSG_WARN(MySQL backend not used) +else + AC_DEFINE(HAVE_MYSQL) + MYSQLINCLUDES=${mysqldir}/include${mysqldir_suffix} + MYSQLLIBS=${mysqldir}/lib${mysqldir_suffix} + + DATABASE_DIR="${DATABASE_DIR} mysql" + + DATABASE_LIB="${DATABASE_LIB} -lmysqlclient " + DATABASE_LIB_DIR="${DATABASE_LIB_DIR} -L${MYSQLLIBS} " + + DATABASE_DRIVERS="${DATABASE_DRIVERS} ../mysql/mysql_driver.o " + + DB_DEF="${DB_DEF} -DHAVE_MYSQL " + + + AC_SUBST(MYSQLINCLUDES) + + if test -f $MYSQLLIBS/libmystrings.a + then + DATABASE_LIB="${DATABASE_LIB} -lmystrings " + else + MYSQLEXTRALIBS= + fi +fi +]) + +AC_SUBST(DATABASE_DIR) +AC_SUBST(DATABASE_LIB) +AC_SUBST(DATABASE_LIB_DIR) +AC_SUBST(DB_DEF) + +AC_SUBST(DATABASE_DRIVERS) + +AM_CONDITIONAL(HAVE_MYSQL, test x$mysqldir != x) + + +AC_OUTPUT(extensions/Makefile doc/Makefile conffile/Makefile libipulog/Makefile mysql/Makefile Makefile Rules.make) diff --git a/ulogd/doc/Makefile.in b/ulogd/doc/Makefile.in index 2c8fbca..fd7b711 100644 --- a/ulogd/doc/Makefile.in +++ b/ulogd/doc/Makefile.in @@ -44,3 +44,5 @@ clean: distclean: rm -f Makefile + +install: diff --git a/ulogd/extensions/Makefile.in b/ulogd/extensions/Makefile.in index bb185b1..5fe385a 100644 --- a/ulogd/extensions/Makefile.in +++ b/ulogd/extensions/Makefile.in @@ -17,12 +17,6 @@ $(SHARED_LIBS): %.so: %_sh.o %_sh.o: %.c $(CC) $(SH_CFLAGS) -o $@ -c $< -ulogd_MYSQL.so: ulogd_MYSQL_sh.o - ld -shared $(MYSQL_LDFLAGS) -o $@ $< - -ulogd_MYSQL_sh.o: ulogd_MYSQL.c - $(CC) $(MYSQL_CFLAGS) $(SH_CFLAGS) -o $@ -c $< - clean: rm -f $(SHARED_LIBS) *.o @@ -30,3 +24,5 @@ distclean: rm -f Makefile install: all + @INSTALL@ -m 755 -d $(ULOGD_LIB_PATH) + @INSTALL@ -m 644 *.so $(ULOGD_LIB_PATH) diff --git a/ulogd/extensions/ulogd_MYSQL.c b/ulogd/extensions/ulogd_MYSQL.c deleted file mode 100644 index 3777e26..0000000 --- a/ulogd/extensions/ulogd_MYSQL.c +++ /dev/null @@ -1,298 +0,0 @@ -/* ulogd_MYSQL.c, Version $Revision$ - * - * ulogd output plugin for logging to a MySQL database - * - * (C) 2000 by Harald Welte - * This software is distributed under the terms of GNU GPL - * - * $Id$ - * - **/ - -#include -#include -#include -#include -#include "ulogd.h" -#include "conffile.h" - -#ifdef DEBUG_MYSQL -#define DEBUGP(x, args...) fprintf(stderr, x, ## args) -#else -#define DEBUGP(x, args...) -#endif - -struct _field { - char name[ULOGD_MAX_KEYLEN]; - unsigned int id; - struct _field *next; -}; - -/* the database handle we are using */ -static MYSQL *dbh; - -/* a linked list of the fields the table has */ -static struct _field *fields; - -/* buffer for our insert statement */ -static char *stmt; - -/* pointer to the beginning of the "VALUES" part */ -static char *stmt_val; - -/* pointer to current inser position in statement */ -static char *stmt_ins; - -/* our configuration directives */ -static config_entry_t db_ce = { NULL, "mysqldb", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; - -static config_entry_t host_ce = { &db_ce, "mysqlhost", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; - -static config_entry_t user_ce = { &host_ce, "mysqluser", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; - -static config_entry_t pass_ce = { &user_ce, "mysqlpass", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; - -static config_entry_t table_ce = { &pass_ce, "mysqltable", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; - -/* is the given string a field in our table? */ -static int is_field(const char *name) -{ - struct _field *f; - - for (f = fields; f; f = f->next) { - if (!strcmp(f->name, name)) - return 1; - } - return 0; -} - -/* our main output function, called by ulogd */ -static int _mysql_output(ulog_iret_t *result) -{ - struct _field *f; - ulog_iret_t *res; - - stmt_ins = stmt_val; - - for (f = fields; f; f = f->next) { - res = keyh_getres(f->id); - - if (!res) { - ulogd_log(ULOGD_NOTICE, - "no result for %s ?!?\n", f->name); - } - - if (!res || !IS_VALID((*res))) { - /* no result, we have to fake something */ - sprintf(stmt_ins, "NULL,"); - stmt_ins = stmt + strlen(stmt); - continue; - } - - switch (res->type) { - case ULOGD_RET_INT8: - sprintf(stmt_ins, "%d,", res->value.i8); - break; - case ULOGD_RET_INT16: - sprintf(stmt_ins, "%d,", res->value.i16); - break; - case ULOGD_RET_INT32: - sprintf(stmt_ins, "%d,", res->value.i32); - break; - case ULOGD_RET_INT64: - sprintf(stmt_ins, "%ld,", res->value.i64); - break; - case ULOGD_RET_UINT8: - sprintf(stmt_ins, "%u,", res->value.ui8); - break; - case ULOGD_RET_UINT16: - sprintf(stmt_ins, "%u,", res->value.ui16); - break; - case ULOGD_RET_IPADDR: - case ULOGD_RET_UINT32: - sprintf(stmt_ins, "%u,", res->value.ui32); - break; - case ULOGD_RET_UINT64: - sprintf(stmt_ins, "%lu,", res->value.ui64); - break; - case ULOGD_RET_STRING: - *stmt_ins++ = '\''; - mysql_real_escape_string(dbh, stmt_ins, - res->value.ptr, strlen(res->value.ptr)); - stmt_ins = stmt + strlen(stmt); - sprintf(stmt_ins, "',"); - /* sprintf(stmt_ins, "'%s',", res->value.ptr); */ - break; - default: - ulogd_log(ULOGD_NOTICE, - "unknown type %d for %s\n", - res->type, res->key); - break; - } - stmt_ins = stmt + strlen(stmt); - } - *(stmt_ins - 1) = ')'; - DEBUGP("stmt=#%s#\n", stmt); - - /* now we have created our statement, insert it */ - - if(mysql_real_query(dbh, stmt, strlen(stmt))) { - ulogd_log(ULOGD_ERROR, "sql error during insert: %s\n", - mysql_error(dbh)); - return 1; - } - - return 0; -} - -#define MYSQL_INSERTTEMPL "insert into X (Y) values (Z)" -#define MYSQL_VALSIZE 100 - -/* create the static part of our insert statement */ -static int _mysql_createstmt(void) -{ - struct _field *f; - unsigned int size; - char buf[ULOGD_MAX_KEYLEN]; - char *underscore; - - if (stmt) { - ulogd_log(ULOGD_NOTICE, "createstmt called, but stmt" - " already existing\n"); - return 1; - } - - /* caclulate the size for the insert statement */ - size = strlen(MYSQL_INSERTTEMPL) + strlen(table_ce.u.string); - - for (f = fields; f; f = f->next) { - /* we need space for the key and a comma, as well as - * enough space for the values */ - size += strlen(f->name) + 1 + MYSQL_VALSIZE; - } - - ulogd_log(ULOGD_DEBUG, "allocating %u bytes for statement\n", size); - - stmt = (char *) malloc(size); - - if (!stmt) { - ulogd_log(ULOGD_ERROR, "OOM!\n"); - return 1; - } - - sprintf(stmt, "insert into %s (", table_ce.u.string); - stmt_val = stmt + strlen(stmt); - - for (f = fields; f; f = f->next) { - strncpy(buf, f->name, ULOGD_MAX_KEYLEN); - while (underscore = strchr(buf, '.')) - *underscore = '_'; - sprintf(stmt_val, "%s,", buf); - stmt_val = stmt + strlen(stmt); - } - *(stmt_val - 1) = ')'; - - sprintf(stmt_val, " values ("); - stmt_val = stmt + strlen(stmt); - - ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt); - - return 0; -} - -/* find out which columns the table has */ -static int _mysql_get_columns(const char *table) -{ - MYSQL_RES *result; - MYSQL_FIELD *field; - char buf[ULOGD_MAX_KEYLEN]; - char *underscore; - struct _field *f; - int id; - - if (!dbh) - return 1; - - result = mysql_list_fields(dbh, table, NULL); - if (!result) - return 1; - - while (field = mysql_fetch_field(result)) { - - /* replace all underscores with dots */ - strncpy(buf, field->name, ULOGD_MAX_KEYLEN); - while (underscore = strchr(buf, '_')) - *underscore = '.'; - - DEBUGP("field '%s' found: ", buf); - - if (!(id = keyh_getid(buf))) { - DEBUGP(" no keyid!\n"); - continue; - } - - DEBUGP("keyid %u\n", id); - - /* prepend it to the linked list */ - f = (struct _field *) malloc(sizeof *f); - if (!f) { - ulogd_log(ULOGD_ERROR, "OOM!\n"); - return 1; - } - strncpy(f->name, buf, ULOGD_MAX_KEYLEN); - f->id = id; - f->next = fields; - fields = f; - } - - mysql_free_result(result); - return 0; -} - -/* make connection and select database */ -static int _mysql_open_db(char *server, char *user, char *pass, char *db) -{ - dbh = mysql_connect(NULL, server, user, pass); - - if (!dbh) - return 1; - - mysql_select_db(dbh, db); - return 0; -} - -static ulog_output_t _mysql_plugin = { NULL, "mysql", &_mysql_output }; - -void _init(void) -{ - /* register our configfile options here */ - config_register_key(&table_ce); - - /* have the opts parsed */ - config_parse_file(0); - - if (_mysql_open_db(host_ce.u.string, user_ce.u.string, - pass_ce.u.string, db_ce.u.string)) { - ulogd_log(ULOGD_ERROR, "can't establish database connection\n"); - return; - } - - /* read the fieldnames to know which values to insert */ - if (_mysql_get_columns(table_ce.u.string)) { - ulogd_log(ULOGD_ERROR, "unable to get mysql columns\n"); - return; - } - _mysql_createstmt(); - register_output(&_mysql_plugin); - -} diff --git a/ulogd/libipulog.old/Makefile.in b/ulogd/libipulog.old/Makefile.in index a3b16cb..4686b20 100644 --- a/ulogd/libipulog.old/Makefile.in +++ b/ulogd/libipulog.old/Makefile.in @@ -17,3 +17,5 @@ clean: distclean: clean rm Makefile + +install: libipulog.a diff --git a/ulogd/libipulog/Makefile.in b/ulogd/libipulog/Makefile.in index a3b16cb..4686b20 100644 --- a/ulogd/libipulog/Makefile.in +++ b/ulogd/libipulog/Makefile.in @@ -17,3 +17,5 @@ clean: distclean: clean rm Makefile + +install: libipulog.a diff --git a/ulogd/mysql/Makefile.in b/ulogd/mysql/Makefile.in new file mode 100644 index 0000000..be8c98a --- /dev/null +++ b/ulogd/mysql/Makefile.in @@ -0,0 +1,26 @@ +# + +# Normally You should not need to change anything below +# +include @top_srcdir@/Rules.make + +CFLAGS+=-I@top_srcdir@ -I@top_srcdir@/libipulog/include -I@top_srcdir@/conffile +SH_CFLAGS:=$(CFLAGS) -fPIC + +SHARED_LIBS=ulogd_MYSQL.so + +all: $(SHARED_LIBS) + +$(SHARED_LIBS): %.so: %_sh.o + ld -shared $(MYSQL_LDFLAGS) -o $@ $< + +%_sh.o: %.c + $(CC) $(MYSQL_CFLAGS) $(SH_CFLAGS) -o $@ -c $< + +clean: + rm -f $(SHARED_LIBS) *.o + +distclean: + rm -f Makefile + +install: all diff --git a/ulogd/mysql/ulogd_MYSQL.c b/ulogd/mysql/ulogd_MYSQL.c new file mode 100644 index 0000000..24c1c46 --- /dev/null +++ b/ulogd/mysql/ulogd_MYSQL.c @@ -0,0 +1,298 @@ +/* ulogd_MYSQL.c, Version $Revision: 1.1 $ + * + * ulogd output plugin for logging to a MySQL database + * + * (C) 2000 by Harald Welte + * This software is distributed under the terms of GNU GPL + * + * $Id: ulogd_MYSQL.c,v 1.1 2000/11/20 11:43:22 laforge Exp $ + * + **/ + +#include +#include +#include +#include +#include "ulogd.h" +#include "conffile.h" + +#ifdef DEBUG_MYSQL +#define DEBUGP(x, args...) fprintf(stderr, x, ## args) +#else +#define DEBUGP(x, args...) +#endif + +struct _field { + char name[ULOGD_MAX_KEYLEN]; + unsigned int id; + struct _field *next; +}; + +/* the database handle we are using */ +static MYSQL *dbh; + +/* a linked list of the fields the table has */ +static struct _field *fields; + +/* buffer for our insert statement */ +static char *stmt; + +/* pointer to the beginning of the "VALUES" part */ +static char *stmt_val; + +/* pointer to current inser position in statement */ +static char *stmt_ins; + +/* our configuration directives */ +static config_entry_t db_ce = { NULL, "mysqldb", CONFIG_TYPE_STRING, + CONFIG_OPT_MANDATORY, 0, + { } }; + +static config_entry_t host_ce = { &db_ce, "mysqlhost", CONFIG_TYPE_STRING, + CONFIG_OPT_MANDATORY, 0, + { } }; + +static config_entry_t user_ce = { &host_ce, "mysqluser", CONFIG_TYPE_STRING, + CONFIG_OPT_MANDATORY, 0, + { } }; + +static config_entry_t pass_ce = { &user_ce, "mysqlpass", CONFIG_TYPE_STRING, + CONFIG_OPT_MANDATORY, 0, + { } }; + +static config_entry_t table_ce = { &pass_ce, "mysqltable", CONFIG_TYPE_STRING, + CONFIG_OPT_MANDATORY, 0, + { } }; + +/* is the given string a field in our table? */ +static int is_field(const char *name) +{ + struct _field *f; + + for (f = fields; f; f = f->next) { + if (!strcmp(f->name, name)) + return 1; + } + return 0; +} + +/* our main output function, called by ulogd */ +static int _mysql_output(ulog_iret_t *result) +{ + struct _field *f; + ulog_iret_t *res; + + stmt_ins = stmt_val; + + for (f = fields; f; f = f->next) { + res = keyh_getres(f->id); + + if (!res) { + ulogd_log(ULOGD_NOTICE, + "no result for %s ?!?\n", f->name); + } + + if (!res || !IS_VALID((*res))) { + /* no result, we have to fake something */ + sprintf(stmt_ins, "NULL,"); + stmt_ins = stmt + strlen(stmt); + continue; + } + + switch (res->type) { + case ULOGD_RET_INT8: + sprintf(stmt_ins, "%d,", res->value.i8); + break; + case ULOGD_RET_INT16: + sprintf(stmt_ins, "%d,", res->value.i16); + break; + case ULOGD_RET_INT32: + sprintf(stmt_ins, "%d,", res->value.i32); + break; + case ULOGD_RET_INT64: + sprintf(stmt_ins, "%ld,", res->value.i64); + break; + case ULOGD_RET_UINT8: + sprintf(stmt_ins, "%u,", res->value.ui8); + break; + case ULOGD_RET_UINT16: + sprintf(stmt_ins, "%u,", res->value.ui16); + break; + case ULOGD_RET_IPADDR: + case ULOGD_RET_UINT32: + sprintf(stmt_ins, "%u,", res->value.ui32); + break; + case ULOGD_RET_UINT64: + sprintf(stmt_ins, "%lu,", res->value.ui64); + break; + case ULOGD_RET_STRING: + *stmt_ins++ = '\''; + mysql_real_escape_string(dbh, stmt_ins, + res->value.ptr, strlen(res->value.ptr)); + stmt_ins = stmt + strlen(stmt); + sprintf(stmt_ins, "',"); + /* sprintf(stmt_ins, "'%s',", res->value.ptr); */ + break; + default: + ulogd_log(ULOGD_NOTICE, + "unknown type %d for %s\n", + res->type, res->key); + break; + } + stmt_ins = stmt + strlen(stmt); + } + *(stmt_ins - 1) = ')'; + DEBUGP("stmt=#%s#\n", stmt); + + /* now we have created our statement, insert it */ + + if(mysql_real_query(dbh, stmt, strlen(stmt))) { + ulogd_log(ULOGD_ERROR, "sql error during insert: %s\n", + mysql_error(dbh)); + return 1; + } + + return 0; +} + +#define MYSQL_INSERTTEMPL "insert into X (Y) values (Z)" +#define MYSQL_VALSIZE 100 + +/* create the static part of our insert statement */ +static int _mysql_createstmt(void) +{ + struct _field *f; + unsigned int size; + char buf[ULOGD_MAX_KEYLEN]; + char *underscore; + + if (stmt) { + ulogd_log(ULOGD_NOTICE, "createstmt called, but stmt" + " already existing\n"); + return 1; + } + + /* caclulate the size for the insert statement */ + size = strlen(MYSQL_INSERTTEMPL) + strlen(table_ce.u.string); + + for (f = fields; f; f = f->next) { + /* we need space for the key and a comma, as well as + * enough space for the values */ + size += strlen(f->name) + 1 + MYSQL_VALSIZE; + } + + ulogd_log(ULOGD_DEBUG, "allocating %u bytes for statement\n", size); + + stmt = (char *) malloc(size); + + if (!stmt) { + ulogd_log(ULOGD_ERROR, "OOM!\n"); + return 1; + } + + sprintf(stmt, "insert into %s (", table_ce.u.string); + stmt_val = stmt + strlen(stmt); + + for (f = fields; f; f = f->next) { + strncpy(buf, f->name, ULOGD_MAX_KEYLEN); + while (underscore = strchr(buf, '.')) + *underscore = '_'; + sprintf(stmt_val, "%s,", buf); + stmt_val = stmt + strlen(stmt); + } + *(stmt_val - 1) = ')'; + + sprintf(stmt_val, " values ("); + stmt_val = stmt + strlen(stmt); + + ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt); + + return 0; +} + +/* find out which columns the table has */ +static int _mysql_get_columns(const char *table) +{ + MYSQL_RES *result; + MYSQL_FIELD *field; + char buf[ULOGD_MAX_KEYLEN]; + char *underscore; + struct _field *f; + int id; + + if (!dbh) + return 1; + + result = mysql_list_fields(dbh, table, NULL); + if (!result) + return 1; + + while (field = mysql_fetch_field(result)) { + + /* replace all underscores with dots */ + strncpy(buf, field->name, ULOGD_MAX_KEYLEN); + while (underscore = strchr(buf, '_')) + *underscore = '.'; + + DEBUGP("field '%s' found: ", buf); + + if (!(id = keyh_getid(buf))) { + DEBUGP(" no keyid!\n"); + continue; + } + + DEBUGP("keyid %u\n", id); + + /* prepend it to the linked list */ + f = (struct _field *) malloc(sizeof *f); + if (!f) { + ulogd_log(ULOGD_ERROR, "OOM!\n"); + return 1; + } + strncpy(f->name, buf, ULOGD_MAX_KEYLEN); + f->id = id; + f->next = fields; + fields = f; + } + + mysql_free_result(result); + return 0; +} + +/* make connection and select database */ +static int _mysql_open_db(char *server, char *user, char *pass, char *db) +{ + dbh = mysql_connect(NULL, server, user, pass); + + if (!dbh) + return 1; + + mysql_select_db(dbh, db); + return 0; +} + +static ulog_output_t _mysql_plugin = { NULL, "mysql", &_mysql_output }; + +void _init(void) +{ + /* register our configfile options here */ + config_register_key(&table_ce); + + /* have the opts parsed */ + config_parse_file(0); + + if (_mysql_open_db(host_ce.u.string, user_ce.u.string, + pass_ce.u.string, db_ce.u.string)) { + ulogd_log(ULOGD_ERROR, "can't establish database connection\n"); + return; + } + + /* read the fieldnames to know which values to insert */ + if (_mysql_get_columns(table_ce.u.string)) { + ulogd_log(ULOGD_ERROR, "unable to get mysql columns\n"); + return; + } + _mysql_createstmt(); + register_output(&_mysql_plugin); + +} -- cgit v1.2.3