From 980332313bffde590173f76fd006837e0c8f3bed Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Tue, 19 Jul 2016 19:50:21 +0300 Subject: [PATCH] stg-2.409 pre-merge. --- include/stg/admin_conf.h | 10 +- include/stg/plugin.h | 2 +- include/stg/resetable.h | 5 + include/stg/tariff.h | 9 ++ include/stg/tariff_conf.h | 35 +++-- include/stg/user_conf.h | 5 +- include/stg/user_ips.h | 2 +- include/stg/version.h | 7 +- projects/libs/build | 80 ++++++++--- projects/rlm_stg/Makefile | 24 ++-- projects/rlm_stg/build | 14 ++ projects/rscriptd/Makefile | 22 +-- projects/rscriptd/build | 26 +++- projects/sgauth/Makefile | 14 +- projects/sgauth/build | 26 +++- projects/sgauthstress/Makefile | 9 +- projects/sgauthstress/build | 128 ++++++++++++++---- projects/sgconf/Makefile | 6 +- projects/sgconf/README.txt | 4 + projects/sgconf/build | 26 +++- projects/sgconf_xml/Makefile | 11 +- projects/sgconf_xml/build | 43 ++++-- projects/sgconf_xml/main.cpp | 16 +-- projects/sgconv/Makefile | 18 +-- projects/sgconv/build | 86 ++++++++++-- projects/stargazer/Makefile | 10 +- projects/stargazer/build | 125 +++++++++++++---- projects/stargazer/main.cpp | 17 ++- projects/stargazer/plugin_mgr.cpp | 56 +++++--- projects/stargazer/plugin_mgr.h | 3 +- projects/stargazer/plugin_runner.cpp | 6 +- projects/stargazer/plugin_runner.h | 5 +- projects/stargazer/plugins/Makefile.in | 10 +- .../stargazer/plugins/authorization/ao/ao.cpp | 9 +- .../stargazer/plugins/authorization/ao/ao.h | 2 +- .../authorization/inetaccess/inetaccess.cpp | 30 ++-- .../authorization/inetaccess/inetaccess.h | 2 +- .../plugins/authorization/stress/stress.h | 2 +- .../plugins/capture/cap_debug/debug_cap.h | 2 +- .../plugins/capture/cap_nf/cap_nf.cpp | 8 +- .../stargazer/plugins/capture/cap_nf/cap_nf.h | 2 +- .../capture/divert_freebsd/divert_cap.cpp | 9 +- .../capture/divert_freebsd/divert_cap.h | 2 +- .../capture/ether_freebsd/ether_cap.cpp | 8 +- .../plugins/capture/ether_freebsd/ether_cap.h | 2 +- .../plugins/capture/ether_linux/ether_cap.cpp | 4 +- .../plugins/capture/ether_linux/ether_cap.h | 2 +- .../plugins/capture/ipq_linux/ipq_cap.cpp | 3 - .../plugins/capture/ipq_linux/ipq_cap.h | 2 +- .../plugins/capture/nfqueue/Makefile | 2 +- .../plugins/capture/nfqueue/nfqueue.cpp | 8 +- .../plugins/capture/nfqueue/nfqueue.h | 2 +- .../plugins/capture/pcap/pcap_cap.cpp | 4 +- .../stargazer/plugins/capture/pcap/pcap_cap.h | 2 +- .../plugins/configuration/rpcconfig/Makefile | 11 +- .../configuration/rpcconfig/rpcconfig.cpp | 16 +-- .../configuration/rpcconfig/rpcconfig.h | 2 +- .../configuration/sgconfig/configproto.h | 2 +- .../plugins/configuration/sgconfig/conn.cpp | 30 ++-- .../plugins/configuration/sgconfig/conn.h | 8 ++ .../configuration/sgconfig/dumphelpers.h | 85 ++++++++++++ .../plugins/configuration/sgconfig/parser.cpp | 1 - .../plugins/configuration/sgconfig/parser.h | 6 +- .../configuration/sgconfig/parser_message.cpp | 1 - .../sgconfig/parser_server_info.cpp | 4 +- .../configuration/sgconfig/parser_tariffs.cpp | 16 ++- .../configuration/sgconfig/parser_users.cpp | 25 ++-- .../configuration/sgconfig/stgconfig.cpp | 4 +- .../configuration/sgconfig/stgconfig.h | 2 +- .../stargazer/plugins/other/ping/ping.cpp | 13 +- projects/stargazer/plugins/other/ping/ping.h | 2 +- .../stargazer/plugins/other/radius/radius.h | 2 +- .../plugins/other/rscript/rscript.cpp | 19 +-- .../stargazer/plugins/other/rscript/rscript.h | 2 +- .../stargazer/plugins/other/smux/smux.cpp | 11 +- projects/stargazer/plugins/other/smux/smux.h | 2 +- .../plugins/store/files/file_store.cpp | 12 +- .../stargazer/plugins/store/firebird/Makefile | 3 - .../plugins/store/firebird/firebird_store.cpp | 33 ++--- .../plugins/store/firebird/firebird_store.h | 9 ++ .../store/firebird/firebird_store_tariffs.cpp | 8 +- .../store/firebird/firebird_store_users.cpp | 12 +- .../stargazer/plugins/store/mysql/Makefile | 3 - .../plugins/store/mysql/mysql_store.cpp | 20 +-- .../plugins/store/postgresql/Makefile | 7 +- .../store/postgresql/postgresql_store.cpp | 44 +++--- .../store/postgresql/postgresql_store_utils.h | 11 ++ projects/stargazer/settings_impl.cpp | 38 +++++- projects/stargazer/settings_impl.h | 2 + projects/stargazer/user_impl.cpp | 2 + projects/stargazer/users_impl.cpp | 11 +- stglibs/Makefile.in | 6 +- stglibs/common.lib/Makefile | 4 +- stglibs/common.lib/common.cpp | 17 +-- stglibs/common.lib/include/stg/common.h | 4 +- stglibs/dotconfpp.lib/dotconfpp.cpp | 6 +- stglibs/logger.lib/include/stg/logger.h | 13 +- stglibs/logger.lib/logger.cpp | 18 +-- tests/test_crypto.cpp | 36 +++++ 99 files changed, 1031 insertions(+), 519 deletions(-) create mode 100644 projects/stargazer/plugins/configuration/sgconfig/dumphelpers.h create mode 100644 projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h diff --git a/include/stg/admin_conf.h b/include/stg/admin_conf.h index 7fbf4440..6e073d6f 100644 --- a/include/stg/admin_conf.h +++ b/include/stg/admin_conf.h @@ -7,11 +7,12 @@ #ifndef ADMIN_CONF_H #define ADMIN_CONF_H -#include "os_int.h" -#include "resetable.h" +#include "stg/resetable.h" #include +#include "os_int.h" + #define ADM_LOGIN_LEN (32) #define ADM_PASSWD_LEN (32) //----------------------------------------------------------------------------- @@ -79,11 +80,6 @@ struct ADMIN_CONF struct ADMIN_CONF_RES { ADMIN_CONF_RES() {} - ADMIN_CONF_RES(const ADMIN_CONF & conf) - : priv(conf.priv), - login(conf.login), - password(conf.password) - {} ADMIN_CONF_RES(const ADMIN_CONF_RES & rhs) : priv(rhs.priv), login(rhs.login), diff --git a/include/stg/plugin.h b/include/stg/plugin.h index 114ffc8b..2deabcc3 100644 --- a/include/stg/plugin.h +++ b/include/stg/plugin.h @@ -59,7 +59,7 @@ public: virtual int Start() = 0; virtual int Stop() = 0; - virtual int Reload() = 0; + virtual int Reload(const MODULE_SETTINGS &) = 0; virtual bool IsRunning() = 0; virtual const std::string & GetStrError() const = 0; virtual std::string GetVersion() const = 0; diff --git a/include/stg/resetable.h b/include/stg/resetable.h index 8a6ad27c..a451b357 100644 --- a/include/stg/resetable.h +++ b/include/stg/resetable.h @@ -50,6 +50,11 @@ public: is_set = true; } } + void maybeSet(value_type& dest) const + { + if (is_set) + dest = value; + } private: value_type value; diff --git a/include/stg/tariff.h b/include/stg/tariff.h index 1b6413b3..5d01cba0 100644 --- a/include/stg/tariff.h +++ b/include/stg/tariff.h @@ -41,6 +41,7 @@ public: static std::string TraffTypeToString(TRAFF_TYPE type); static TRAFF_TYPE StringToTraffType(const std::string& value); + static TRAFF_TYPE IntToTraffType(int value); virtual ~TARIFF() {} virtual double GetPriceWithTraffType(uint64_t up, @@ -117,4 +118,12 @@ std::istream & operator>>(std::istream & stream, TARIFF::TRAFF_TYPE & traffType) return stream; } +inline +TARIFF::TRAFF_TYPE TARIFF::IntToTraffType(int value) +{ + if (value < 0 || value > TRAFF_MAX) + return TRAFF_UP_DOWN; + return static_cast(value); +} + #endif diff --git a/include/stg/tariff_conf.h b/include/stg/tariff_conf.h index ae40c128..fe94b6e5 100644 --- a/include/stg/tariff_conf.h +++ b/include/stg/tariff_conf.h @@ -98,18 +98,17 @@ struct DIRPRICE_DATA_RES DIRPRICE_DATA GetData() const { DIRPRICE_DATA dd; - dd.hDay = hDay.data(); - dd.hNight = hNight.data(); - dd.mDay = mDay.data(); - dd.mNight = mNight.data(); - dd.noDiscount = noDiscount.data(); - dd.priceDayA = priceDayA.data(); - dd.priceDayB = priceDayB.data(); - - dd.priceNightA = priceNightA.data(); - dd.priceNightB = priceNightB.data(); - dd.singlePrice = singlePrice.data(); - dd.threshold = threshold.data(); + hDay.maybeSet(dd.hDay); + hNight.maybeSet(dd.hNight); + mDay.maybeSet(dd.mDay); + mNight.maybeSet(dd.mNight); + noDiscount.maybeSet(dd.noDiscount); + priceDayA.maybeSet(dd.priceDayA); + priceDayB.maybeSet(dd.priceDayB); + priceNightA.maybeSet(dd.priceNightA); + priceNightB.maybeSet(dd.priceNightB); + singlePrice.maybeSet(dd.singlePrice); + threshold.maybeSet(dd.threshold); return dd; } @@ -194,12 +193,12 @@ struct TARIFF_CONF_RES TARIFF_CONF GetData() const { TARIFF_CONF tc; - tc.fee = fee.data(); - tc.free = free.data(); - tc.name = name.data(); - tc.passiveCost = passiveCost.data(); - tc.traffType = traffType.data(); - tc.period = period.data(); + fee.maybeSet(tc.fee); + free.maybeSet(tc.free); + name.maybeSet(tc.name); + passiveCost.maybeSet(tc.passiveCost); + traffType.maybeSet(tc.traffType); + period.maybeSet(tc.period); return tc; } diff --git a/include/stg/user_conf.h b/include/stg/user_conf.h index d0415c42..a16b3929 100644 --- a/include/stg/user_conf.h +++ b/include/stg/user_conf.h @@ -51,9 +51,8 @@ struct USER_CONF struct USER_CONF_RES { USER_CONF_RES() - { - } - + : userdata(USERDATA_NUM) + {} USER_CONF_RES & operator=(const USER_CONF & uc) { userdata.resize(USERDATA_NUM); diff --git a/include/stg/user_ips.h b/include/stg/user_ips.h index e55f99fa..52e5df77 100644 --- a/include/stg/user_ips.h +++ b/include/stg/user_ips.h @@ -166,7 +166,7 @@ return false; inline bool USER_IPS::OnlyOneIP() const { -if (ips.size() == 1 && ips.front().mask == 32) +if (ips.size() == 1 && ips.front().mask == 32 && ips.front().ip != 0) return true; return false; diff --git a/include/stg/version.h b/include/stg/version.h index 3698b59d..fb41a227 100644 --- a/include/stg/version.h +++ b/include/stg/version.h @@ -18,15 +18,10 @@ * Author : Maxim Mamontiv */ - /* - $Revision: 1.6 $ - $Date: 2010/11/08 10:13:18 $ - */ - #ifndef __VERSION_H__ #define __VERSION_H__ // Stargazer version -#define SERVER_VERSION "2.409-alpha" +#define SERVER_VERSION "2.5" #endif diff --git a/projects/libs/build b/projects/libs/build index a85ad133..bc615505 100755 --- a/projects/libs/build +++ b/projects/libs/build @@ -1,10 +1,5 @@ #!/bin/sh -# $Revision: 1.57 $ -# $Author: faust $ -# $Date: 2010/05/09 12:39:01 $ -###################################################### - # Installation path prefix #PREFIX="" @@ -27,7 +22,8 @@ OWNER=root OS=unknown sys=`uname -s` -release=`uname -r | cut -b1` +release=`uname -r` +major=`printf "%s" "$release" | cut -d. -f1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" @@ -51,13 +47,12 @@ LDFLAGS="$LDFLAGS -L/usr/local/lib" if [ "$sys" = "Linux" ] then OS=linux - release="" MAKE="make" fi if [ "$sys" = "FreeBSD" ] then - case $release in + case $major in 4) OS=bsd;; 5) OS=bsd5;; 6) OS=bsd5;; @@ -76,13 +71,13 @@ fi if [ "$OS" = "unknown" ] then printf "#############################################################################\n" - printf "# Sorry, but stargazer currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "# Sorry, but we currently support Linux, FreeBSD and Darwin. #\n" printf "#############################################################################\n" exit 1 fi printf "#############################################################################\n" -printf " Building STG 2.4 for $sys $release\n" +printf " Building STG 2.4 libs for $sys $release\n" printf "#############################################################################\n" STG_LIBS="logger.lib @@ -100,6 +95,7 @@ if [ "$OS" = "linux" ] then DEFS="$DEFS -DLINUX" else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -111,6 +107,7 @@ else if [ "$OS" == "darwin" ] then DEFS="$DEFS -DDARWIN" + LIBICONV="" fi fi fi @@ -172,7 +169,7 @@ rm -f fake printf "Checking for -lexpat... " printf "#include \nint main() { return 0; }\n" > build_check.c -$CXX $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null +$CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_EXPAT=no @@ -183,18 +180,59 @@ else fi rm -f fake -printf "Checking for -lfbclient... " -printf "int main() { return 0; }\n" > build_check.c -$CXX $CXXFLAGS $LDFLAGS build_check.c -lfbclient -o fake > /dev/null 2> /dev/null +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - CHECK_FBCLIENT=no + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + +printf "Checking for fb_config... " +FB_VERSION=`fb_config --version 2> /dev/null` +if [ "$?" != "0" ] +then printf "no\n" + printf "Checking for -lfbclient... " + printf "int main() { return 0; }\n" > build_check.c + $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null + if [ $? != 0 ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + FB_CFLAGS="" + FB_LDFLAGS="-lfbclient" + CHECK_FBCLIENT=yes + printf "yes\n" + fi + rm -f fake else - CHECK_FBCLIENT=yes printf "yes\n" + printf "Checking for fb_config --cflags... " + FB_CFLAGS=`fb_config --cflags` + if [ "$?" != "0" ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + printf "[$FB_CFLAGS]\n" + printf "Checking for fb_config --libs " + FB_LDFLAGS=`fb_config --libs` + if [ "$?" != "0" ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + CHECK_FBCLIENT=yes + printf "[$FB_LDFLAGS]\n" + fi + fi fi -rm -f fake rm -f build_check.c @@ -220,6 +258,11 @@ printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE printf "ARCH=$ARCH\n" >> $CONFFILE printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE +if [ "$CHECK_FBCLIENT" = "yes" ] +then + printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE + printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE +fi printf "DEFS=$DEFS\n" >> $CONFFILE printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS @@ -227,9 +270,12 @@ do printf "$lib " >> $CONFFILE done printf "\n" >> $CONFFILE +printf "CC=$CC\n" >> $CONFFILE +printf "CXX=$CXX\n" >> $CONFFILE printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE diff --git a/projects/rlm_stg/Makefile b/projects/rlm_stg/Makefile index 3d410483..05c43d95 100644 --- a/projects/rlm_stg/Makefile +++ b/projects/rlm_stg/Makefile @@ -13,19 +13,18 @@ SRCS = ./rlm_stg.c \ ./stg_client.cpp STGLIBS = crypto \ - common - + common + STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS))) STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS))) -LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) +LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) $(LIBICONV) ifeq ($(OS),linux) LIBS += -ldl else LIBS += -lintl \ - -lc \ - -liconv + -lc endif SEARCH_DIRS = -I ../../include @@ -59,16 +58,21 @@ install: install-bin install-bin: ifeq ($(DEBUG), yes) ifeq ($(OS), linux) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/lib/freeradius/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib/freeradius + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/lib/freeradius/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/lib/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/lib/$(PROG) endif else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/freeradius/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib/freeradius + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/freeradius/$(PROG) ifeq ($(OS), linux) - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/freeradius/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib/freeradius + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/freeradius/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/$(PROG) endif endif $(MAKE) -C $(DIR_LIBSRC) install diff --git a/projects/rlm_stg/build b/projects/rlm_stg/build index 433cd04f..179d5261 100755 --- a/projects/rlm_stg/build +++ b/projects/rlm_stg/build @@ -68,6 +68,7 @@ then DEFS="$DEFS -DLINUX" LIB_THREAD=-lpthread else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -137,6 +138,18 @@ else fi rm -f fake +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null +if [ $? != 0 ] +then + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + printf "OS=$OS\n" > $CONFFILE printf "STG_TIME=yes\n" >> $CONFFILE printf "DEBUG=$DEBUG\n" >> $CONFFILE @@ -156,6 +169,7 @@ printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE diff --git a/projects/rscriptd/Makefile b/projects/rscriptd/Makefile index 4c960db7..98b2f5e4 100644 --- a/projects/rscriptd/Makefile +++ b/projects/rscriptd/Makefile @@ -19,11 +19,7 @@ STGLIBS = scriptexecuter \ STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS))) STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS))) -LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) - -ifneq ($(OS),linux) -LIBS += -liconv -endif +LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) $(LIBICONV) SEARCH_DIRS = -I ../../include @@ -62,9 +58,11 @@ install: install-bin install-data install-bin: ifeq ($(DEBUG), yes) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/sbin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/sbin/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG) endif $(MAKE) -C $(DIR_LIBSRC) install @@ -73,11 +71,13 @@ install-data: mkdir -m $(DIR_MODE) -p $(PREFIX)/etc/rscriptd install -m $(DATA_MODE) -o $(OWNER) ./rscriptd.conf $(PREFIX)/etc/rscriptd/rscriptd.conf ifeq ($(OS), linux) - install -D -m $(BIN_MODE) -o $(OWNER) ../stargazer/inst/linux/etc/stargazer/OnConnect $(PREFIX)/etc/rscriptd/ - install -D -m $(BIN_MODE) -o $(OWNER) ../stargazer/inst/linux/etc/stargazer/OnDisconnect $(PREFIX)/etc/rscriptd/ + mkdir -m $(DIR_MODE) -p $(PREFIX)/etc/rscriptd + install -m $(BIN_MODE) -o $(OWNER) ../stargazer/inst/linux/etc/stargazer/OnConnect $(PREFIX)/etc/rscriptd/ + install -m $(BIN_MODE) -o $(OWNER) ../stargazer/inst/linux/etc/stargazer/OnDisconnect $(PREFIX)/etc/rscriptd/ else - install -D -m $(BIN_MODE) -o $(OWNER) ../stargazer/inst/freebsd/etc/stargazer/OnConnect $(PREFIX)/etc/rscriptd/ - install -D -m $(BIN_MODE) -o $(OWNER) ../stargazer/inst/freebsd/etc/stargazer/OnDisconnect $(PREFIX)/etc/rscriptd/ + mkdir -m $(DIR_MODE) -p $(PREFIX)/etc/rscriptd + install -m $(BIN_MODE) -o $(OWNER) ../stargazer/inst/freebsd/etc/stargazer/OnConnect $(PREFIX)/etc/rscriptd/ + install -m $(BIN_MODE) -o $(OWNER) ../stargazer/inst/freebsd/etc/stargazer/OnDisconnect $(PREFIX)/etc/rscriptd/ endif uninstall: uninstall-bin uninstall-data diff --git a/projects/rscriptd/build b/projects/rscriptd/build index 3b73000d..a2926ed0 100755 --- a/projects/rscriptd/build +++ b/projects/rscriptd/build @@ -7,7 +7,8 @@ OS=unknown sys=`uname -s` -release=`uname -r | cut -b1` +release=`uname -r` +major=`printf "%s" "$release" | cut -d. -f1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" PREFIX="/" @@ -35,13 +36,12 @@ LDFLAGS="$LDFLAGS -L/usr/local/lib" if [ "$sys" = "Linux" ] then OS=linux - release="" MAKE="make" fi if [ "$sys" = "FreeBSD" ] then - case $release in + case $major in 4) OS=bsd;; 5) OS=bsd5;; 6) OS=bsd5;; @@ -61,7 +61,7 @@ fi if [ "$OS" = "unknown" ] then printf "#############################################################################\n" - printf "# Sorry, but rscriptd currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "# Sorry, but rscriptd is currently supported by Linux, FreeBSD and Darwin. #\n" printf "#############################################################################\n" exit 1 fi @@ -81,6 +81,7 @@ then DEFS="$DEFS -DLINUX" LIB_THREAD=-lpthread else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -94,6 +95,7 @@ else then DEFS="$DEFS -DDARWIN" LIB_THREAD=-lpthread + LIBICONV="" else LIB_THREAD=-lc_r fi @@ -154,6 +156,19 @@ else fi fi rm -f fake + +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null +if [ $? != 0 ] +then + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + rm -f build_check.c printf "OS=$OS\n" > $CONFFILE @@ -172,9 +187,12 @@ do done printf "\n" >> $CONFFILE printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CC=$CC\n" >> $CONFFILE +printf "CXX=$CXX\n" >> $CONFFILE printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE diff --git a/projects/sgauth/Makefile b/projects/sgauth/Makefile index ef649119..d6c844e0 100644 --- a/projects/sgauth/Makefile +++ b/projects/sgauth/Makefile @@ -18,12 +18,12 @@ STGLIBS = conffiles \ STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS))) STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS))) -LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) +LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) $(LIBICONV) -ifneq ($(OS),linux) +ifeq ($(OS),linux) +else LIBS += -lintl \ - -lc \ - -liconv + -lc endif SEARCH_DIRS = -I ../../include @@ -59,9 +59,11 @@ install: install-bin install-data install-bin: ifeq ($(DEBUG), yes) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/sbin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/sbin/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG) endif $(MAKE) -C $(DIR_LIBSRC) install diff --git a/projects/sgauth/build b/projects/sgauth/build index e7c4be9b..cef1da1d 100755 --- a/projects/sgauth/build +++ b/projects/sgauth/build @@ -7,7 +7,8 @@ OS=unknown sys=`uname -s` -release=`uname -r | cut -b1` +release=`uname -r` +major=`printf "%s" "$release" | cut -d. -f1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" PREFIX="/" @@ -35,13 +36,12 @@ LDFLAGS="$LDFLAGS -L/usr/local/lib" if [ "$sys" = "Linux" ] then OS=linux - release="" MAKE="make" fi if [ "$sys" = "FreeBSD" ] then - case $release in + case $major in 4) OS=bsd;; 5) OS=bsd5;; 6) OS=bsd5;; @@ -64,7 +64,7 @@ fi if [ "$OS" = "unknown" ] then printf "#############################################################################\n" - printf "# Sorry, but sgauth currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "# Sorry, but sgauth is currently supported by Linux, FreeBSD and Darwin. #\n" printf "#############################################################################\n" exit 1 fi @@ -83,6 +83,7 @@ then DEFS="$DEFS -DLINUX" LIB_THREAD=-lpthread else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -96,6 +97,7 @@ else then DEFS="$DEFS -DDARWIN" LIB_THREAD=-lpthread + LIBICONV="" else LIB_THREAD=-lc_r fi @@ -156,6 +158,19 @@ else fi fi rm -f fake + +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null +if [ $? != 0 ] +then + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + rm -f build_check.c printf "OS=$OS\n" > $CONFFILE @@ -174,9 +189,12 @@ do done printf "\n" >> $CONFFILE printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CC=$CC\n" >> $CONFFILE +printf "CXX=$CXX\n" >> $CONFFILE printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE diff --git a/projects/sgauthstress/Makefile b/projects/sgauthstress/Makefile index f88e59c6..74c09b62 100644 --- a/projects/sgauthstress/Makefile +++ b/projects/sgauthstress/Makefile @@ -9,20 +9,19 @@ SRCS = main.cpp \ proto.cpp STGLIBS = dotconfpp \ - crypto \ - common + crypto \ + common STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS))) STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS))) -LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) +LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) $(LIBICONV) ifeq ($(OS),linux) LIBS += -ldl else LIBS += -lintl \ - -lc \ - -liconv + -lc endif SEARCH_DIRS = -I ../../include diff --git a/projects/sgauthstress/build b/projects/sgauthstress/build index 29b10675..dae35b74 100755 --- a/projects/sgauthstress/build +++ b/projects/sgauthstress/build @@ -7,7 +7,8 @@ OS=unknown sys=`uname -s` -release=`uname -r | cut -b1` +release=`uname -r` +major=`printf "%s" "$release" | cut -d. -f1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" PREFIX="/" @@ -16,22 +17,16 @@ DATA_MODE=0644 DIR_MODE=0755 OWNER=root -if [ -z $1 ] +if [ "$1" = "debug" ] then - MAKEOPTS="-j1" - DEBUG="no" + DEFS="$DEFS -DDEBUG" + MAKEOPTS="$MAKEOPTS -j1" + CFLAGS="$CFLAGS -ggdb3 -W -Wall -Wextra" + CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall -Wextra" + DEBUG="yes" else - if [ "$1" = "debug" ] - then - DEFS="-DDEBUG" - MAKEOPTS="-j1" - CFLAGS="$CFLAGS -ggdb3 -W -Wall" - CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall" - DEBUG="yes" - else - MAKEOPTS="-j1" - DEBUG="no" - fi + DEFS="$DEFS -DNDEBUG" + DEBUG="no" fi CFLAGS="$CFLAGS -I/usr/local/include" @@ -41,28 +36,35 @@ LDFLAGS="$LDFLAGS -L/usr/local/lib" if [ "$sys" = "Linux" ] then OS=linux - release="" MAKE="make" fi if [ "$sys" = "FreeBSD" ] then - case $release in + case $major in 4) OS=bsd;; 5) OS=bsd5;; 6) OS=bsd5;; 7) OS=bsd7;; - 8) OS=bsd7;; - 9) OS=bsd7;; - *) OS=unknown;; + *) OS=bsd7;; esac MAKE="gmake" fi +if [ "$sys" = "Darwin" ] +then + OS=darwin + ETC_DIR="./inst/freebsd/etc/stargazer" + MAKE="gmake" + CFLAGS="$CFLAGS -I/opt/local/include" + CXXFLAGS="$CFLAGS -I/opt/local/include" + LDFLAGS="$LDFLAGS -L/opt/local/lib" +fi + if [ "$OS" = "unknown" ] then printf "################################################################################\n" - printf "# Sorry, but sgauthstress currently supported by Linux, FreeBSD 4.x-8.x #\n" + printf "# Sorry, but sgauthstress is currently supported by Linux, FreeBSD and Darwin. #\n" printf "################################################################################\n" exit 1 fi @@ -73,7 +75,7 @@ printf "######################################################################## STG_LIBS="logger.lib crypto.lib - common.lib + common.lib conffiles.lib dotconfpp.lib" @@ -84,6 +86,7 @@ then DEFS="$DEFS -DLINUX" LIB_THREAD=-lpthread else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -152,19 +155,62 @@ else fi fi rm -f fake -rm -f build_check.c -printf "Checking for -lfbclient... " -$CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - CHECK_FBCLIENT=no + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + +rm -f build_check.c + +printf "Checking for fb_config... " +FB_VERSION=`fb_config --version 2> /dev/null` +if [ "$?" != "0" ] +then printf "no\n" + printf "Checking for -lfbclient... " + printf "int main() { return 0; }\n" > build_check.c + $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null + if [ $? != 0 ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + FB_CFLAGS="" + FB_LDFLAGS="-lfbclient" + CHECK_FBCLIENT=yes + printf "yes\n" + fi + rm -f fake else - CHECK_FBCLIENT=yes printf "yes\n" + printf "Checking for fb_config --cflags... " + FB_CFLAGS=`fb_config --cflags` + if [ "$?" != "0" ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + printf "[$FB_CFLAGS]\n" + printf "Checking for fb_config --libs " + FB_LDFLAGS=`fb_config --libs` + if [ "$?" != "0" ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + CHECK_FBCLIENT=yes + printf "[$FB_LDFLAGS]\n" + fi + fi fi -rm -f fake printf "Checking for mysql_config... " MYSQL_VERSION=`mysql_config --version 2> /dev/null` @@ -206,6 +252,7 @@ else fi printf "Checking for pg_config... " +printf "#include \nint main() { return 0; }\n" > build_check.c PG_VERSION=`pg_config --version 2> /dev/null` if [ $? != 0 ] then @@ -224,7 +271,7 @@ then else printf "yes\n"; printf "Checking for pg_config --includedir... " - PG_CFLAGS=`pg_config --includedir 2> /dev/null` + PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no @@ -232,7 +279,7 @@ else else printf "[$PG_CFLAGS]\n" printf "Checking for pg_config --libdir... " - PG_LDFLAGS=`pg_config --libdir 2> /dev/null` + PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no @@ -276,6 +323,24 @@ printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE printf "ARCH=$ARCH\n" >> $CONFFILE +printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE +if [ "$CHECK_FBCLIENT" = "yes" ] +then + printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE + printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE +fi +printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE +if [ "$CHECK_MYSQLCLIENT" = "yes" ] +then + printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE + printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE +fi +printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE +if [ "$CHECK_PQ" = "yes" ] +then + printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE + printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE +fi printf "DEFS=$DEFS\n" >> $CONFFILE printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS @@ -290,9 +355,12 @@ do done printf "\n" >> $CONFFILE printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CC=$CC\n" >> $CONFFILE +printf "CXX=$CXX\n" >> $CONFFILE printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE diff --git a/projects/sgconf/Makefile b/projects/sgconf/Makefile index 803035df..3a64cb61 100644 --- a/projects/sgconf/Makefile +++ b/projects/sgconf/Makefile @@ -75,9 +75,11 @@ install: install-bin install-bin: ifeq ($(DEBUG), yes) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/bin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/sbin/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/bin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG) endif $(MAKE) -C $(DIR_LIBSRC) install diff --git a/projects/sgconf/README.txt b/projects/sgconf/README.txt index e69de29b..bb2db5b9 100644 --- a/projects/sgconf/README.txt +++ b/projects/sgconf/README.txt @@ -0,0 +1,4 @@ +Compiling: +> ./build + + diff --git a/projects/sgconf/build b/projects/sgconf/build index 91be2728..e2eb835b 100755 --- a/projects/sgconf/build +++ b/projects/sgconf/build @@ -7,7 +7,8 @@ OS=unknown sys=`uname -s` -release=`uname -r | cut -b1` +release=`uname -r` +major=`printf "%s" "$release" | cut -d. -f1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" PREFIX="/" @@ -35,13 +36,12 @@ LDFLAGS="$LDFLAGS -L/usr/local/lib" if [ "$sys" = "Linux" ] then OS=linux - release="" MAKE="make" fi if [ "$sys" = "FreeBSD" ] then - case $release in + case $major in 4) OS=bsd;; 5) OS=bsd5;; 6) OS=bsd5;; @@ -61,7 +61,7 @@ fi if [ "$OS" = "unknown" ] then printf "#############################################################################\n" - printf "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "# Sorry, but sgconf is currently supported by Linux, FreeBSD and Darwin. #\n" printf "#############################################################################\n" exit 1 fi @@ -80,6 +80,7 @@ then DEFS="$DEFS -DLINUX" LIB_THREAD=-lpthread else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -93,6 +94,7 @@ else then DEFS="$DEFS -DDARWIN" LIB_THREAD=-lpthread + LIBICONV="" else LIB_THREAD=-lc_r fi @@ -166,6 +168,19 @@ else printf "yes\n" fi rm -f fake + +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null +if [ $? != 0 ] +then + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + rm -f build_check.c if [ "$CHECK_EXPAT" != "yes" ] @@ -191,9 +206,12 @@ do done printf "\n" >> $CONFFILE printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CC=$CC\n" >> $CONFFILE +printf "CXX=$CXX\n" >> $CONFFILE printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE diff --git a/projects/sgconf_xml/Makefile b/projects/sgconf_xml/Makefile index b953bb52..a7058b89 100644 --- a/projects/sgconf_xml/Makefile +++ b/projects/sgconf_xml/Makefile @@ -17,12 +17,11 @@ STGLIBS = conffiles \ STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS))) STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS))) -LIBS += $(addprefix -lstg,$(STGLIBS)) -lexpat $(LIB_THREAD) +LIBS += $(addprefix -lstg,$(STGLIBS)) -lexpat $(LIB_THREAD) $(LIBICONV) ifeq ($(OS),linux) else -LIBS += -lc \ - -liconv +LIBS += -lc endif SEARCH_DIRS = -I ../../include @@ -67,9 +66,11 @@ install: install-bin install-data install-bin: ifeq ($(DEBUG), yes) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/bin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/sbin/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/bin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG) endif $(MAKE) -C $(DIR_LIBSRC) install diff --git a/projects/sgconf_xml/build b/projects/sgconf_xml/build index 689cc262..a1084554 100755 --- a/projects/sgconf_xml/build +++ b/projects/sgconf_xml/build @@ -7,7 +7,8 @@ OS=unknown sys=`uname -s` -release=`uname -r | cut -b1` +release=`uname -r` +major=`printf "%s" "$release" | cut -d. -f1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" PREFIX="/" @@ -35,13 +36,12 @@ LDFLAGS="$LDFLAGS -L/usr/local/lib" if [ "$sys" = "Linux" ] then OS=linux - release="" MAKE="make" fi if [ "$sys" = "FreeBSD" ] then - case $release in + case $major in 4) OS=bsd;; 5) OS=bsd5;; 6) OS=bsd5;; @@ -51,16 +51,22 @@ then MAKE="gmake" fi +if [ "$sys" = "Darwin" ] +then + OS=darwin + MAKE="gmake" +fi + if [ "$OS" = "unknown" ] then printf "#############################################################################\n" - printf "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "# Sorry, but sgconf_xml is currently supported by Linux, FreeBSD and Darwin.#\n" printf "#############################################################################\n" exit 1 fi printf "#############################################################################\n" -printf " Building sgconf for $sys $release\n" +printf " Building sgconf_xml for $sys $release\n" printf "#############################################################################\n" STG_LIBS="conffiles.lib @@ -73,6 +79,7 @@ then DEFS="$DEFS -DLINUX" LIB_THREAD=-lpthread else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -143,7 +150,7 @@ rm -f fake printf "Checking for -lexpat... " printf "int main() { return 0; }\n" > build_check.c -$CC $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null +$CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_EXPAT=no @@ -153,6 +160,19 @@ else printf "yes\n" fi rm -f fake + +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null +if [ $? != 0 ] +then + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + rm -f build_check.c if [ "$CHECK_EXPAT" != "yes" ] @@ -178,14 +198,21 @@ do done printf "\n" >> $CONFFILE printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CC=$CC\n" >> $CONFFILE +printf "CXX=$CXX\n" >> $CONFFILE printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE printf "OWNER=$OWNER\n" >> $CONFFILE -$MAKE $MAKEOPTS - +if [ "$1" != "debug" ] +then + $MAKE $MAKEOPTS +else + printf "\n\n\nDebug build. Type $MAKE explicitly\n" +fi diff --git a/projects/sgconf_xml/main.cpp b/projects/sgconf_xml/main.cpp index 03a63a9a..2d897573 100644 --- a/projects/sgconf_xml/main.cpp +++ b/projects/sgconf_xml/main.cpp @@ -108,7 +108,7 @@ void CreateRequest(REQUEST * req, char * r) char str[10024]; r[0] = 0; -if (!req->strReq.res_empty()) +if (!req->strReq.empty()) { sprintf(str, "%s", req->strReq.const_data().c_str()); strcat(r, str); @@ -140,7 +140,7 @@ char str[2048]; NETTRANSACT nt; nt.SetServer(r->server.const_data().c_str()); -nt.SetServerPort(r->port); +nt.SetServerPort(r->port.const_data()); nt.SetLogin(r->admLogin.const_data().c_str()); nt.SetPassword(r->admPasswd.const_data().c_str()); nt.SetRxCallback(NULL, ParseReply); @@ -169,13 +169,13 @@ return 0; //----------------------------------------------------------------------------- int CheckParameters(REQUEST * req) { -int a = !req->admLogin.res_empty() - && !req->admPasswd.res_empty() - && !req->server.res_empty() - && !req->port.res_empty(); +int a = !req->admLogin.empty() + && !req->admPasswd.empty() + && !req->server.empty() + && !req->port.empty(); -int b = !req->fileReq.res_empty() - || !req->strReq.res_empty(); +int b = !req->fileReq.empty() + || !req->strReq.empty(); return a && b; } diff --git a/projects/sgconv/Makefile b/projects/sgconv/Makefile index ceea22b7..b463f175 100644 --- a/projects/sgconv/Makefile +++ b/projects/sgconv/Makefile @@ -10,20 +10,20 @@ SRCS = ./main.cpp \ ./settings_impl.cpp STGLIBS = dotconfpp \ - conffiles \ - logger \ - crypto \ + conffiles \ + logger \ + crypto \ common STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS))) STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS))) -LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) +LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) $(LIBICONV) ifeq ($(OS),linux) LIBS += -ldl else -LIBS += -lc -liconv +LIBS += -lc endif SEARCH_DIRS = -I ../../include @@ -45,7 +45,7 @@ all: libs plugins $(PROG) ../../Makefile.conf libs: $(MAKE) -C $(DIR_LIBSRC) -plugins: libs +plugins: libs $(MAKE) -C $(DIR_PLUGINS) $(PROG): $(OBJS) @@ -67,9 +67,11 @@ install: install-bin install-bin: ifeq ($(DEBUG), yes) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/bin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/bin + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/bin/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/bin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/bin + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/bin/$(PROG) endif $(MAKE) -C $(DIR_PLUGINS) install diff --git a/projects/sgconv/build b/projects/sgconv/build index 5ceb4013..1bc23718 100755 --- a/projects/sgconv/build +++ b/projects/sgconv/build @@ -7,7 +7,8 @@ OS=unknown sys=`uname -s` -release=`uname -r | cut -b1` +release=`uname -r` +major=`printf "%s" "$release" | cut -d. -f1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" PREFIX="/" @@ -36,13 +37,12 @@ LDFLAGS="$LDFLAGS -L/usr/local/lib" if [ "$sys" = "Linux" ] then OS=linux - release="" MAKE="make" fi if [ "$sys" = "FreeBSD" ] then - case $release in + case $major in 4) OS=bsd;; 5) OS=bsd5;; 6) OS=bsd5;; @@ -62,7 +62,7 @@ fi if [ "$OS" = "unknown" ] then printf "#############################################################################\n" - printf "# Sorry, but sgconv currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "# Sorry, but sgconv is currently supported by Linux, FreeBSD and Darwin. #\n" printf "#############################################################################\n" exit 1 fi @@ -85,6 +85,7 @@ then DEFS="$DEFS -DLINUX" LIB_THREAD=-lpthread else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -99,6 +100,7 @@ else then DEFS="$DEFS -DDARWIN" LIB_THREAD=-lpthread + LIBICONV="" else LIB_THREAD=-lc_r fi @@ -160,17 +162,59 @@ else fi rm -f fake -printf "Checking for -lfbclient... " -$CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - CHECK_FBCLIENT=no + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + +printf "Checking for fb_config... " +FB_VERSION=`fb_config --version 2> /dev/null` +if [ "$?" != "0" ] +then printf "no\n" + printf "Checking for -lfbclient... " + printf "int main() { return 0; }\n" > build_check.c + $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null + if [ $? != 0 ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + FB_CFLAGS="" + FB_LDFLAGS="-lfbclient" + CHECK_FBCLIENT=yes + printf "yes\n" + fi + rm -f fake else - CHECK_FBCLIENT=yes printf "yes\n" + printf "Checking for fb_config --cflags... " + FB_CFLAGS=`fb_config --cflags` + if [ "$?" != "0" ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + printf "[$FB_CFLAGS]\n" + printf "Checking for fb_config --libs " + FB_LDFLAGS=`fb_config --libs` + if [ "$?" != "0" ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + CHECK_FBCLIENT=yes + printf "[$FB_LDFLAGS]\n" + fi + fi fi -rm -f fake printf "Checking for mysql_config... " printf "#include \nint main() { return 0; }\n" > build_check.c @@ -232,7 +276,7 @@ then else printf "yes\n"; printf "Checking for pg_config --includedir... " - PG_CFLAGS=`pg_config --includedir 2> /dev/null` + PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no @@ -240,7 +284,7 @@ else else printf "[$PG_CFLAGS]\n" printf "Checking for pg_config --libdir... " - PG_LDFLAGS=`pg_config --libdir 2> /dev/null` + PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no @@ -285,6 +329,23 @@ printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE printf "ARCH=$ARCH\n" >> $CONFFILE printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE +if [ "$CHECK_FBCLIENT" = "yes" ] +then + printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE + printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE +fi +printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE +if [ "$CHECK_MYSQLCLIENT" = "yes" ] +then + printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE + printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE +fi +printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE +if [ "$CHECK_PQ" = "yes" ] +then + printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE + printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE +fi printf "DEFS=$DEFS\n" >> $CONFFILE printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS @@ -298,10 +359,13 @@ do printf "$plugin " >> $CONFFILE done printf "\n" >> $CONFFILE +printf "CC=$CC\n" >> $CONFFILE +printf "CXX=$CXX\n" >> $CONFFILE printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE diff --git a/projects/stargazer/Makefile b/projects/stargazer/Makefile index e210dc2f..e127d4f8 100644 --- a/projects/stargazer/Makefile +++ b/projects/stargazer/Makefile @@ -33,12 +33,12 @@ STGLIBS = scriptexecuter \ STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS))) STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS))) -LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) +LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD) $(LIBICONV) ifeq ($(OS),linux) LIBS += -ldl else -LIBS += -lc -liconv +LIBS += -lc endif SEARCH_DIRS = -I ../../include @@ -83,9 +83,11 @@ install: install-bin install-data install-bin: $(PROG) ifeq ($(DEBUG), yes) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/sbin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/sbin/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/sbin + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/sbin/$(PROG) endif $(MAKE) -C $(DIR_INCLUDE) install $(MAKE) -C $(DIR_LIBSRC) install diff --git a/projects/stargazer/build b/projects/stargazer/build index 48da041a..638ed3ef 100755 --- a/projects/stargazer/build +++ b/projects/stargazer/build @@ -27,7 +27,8 @@ OWNER=root OS=unknown sys=`uname -s` -release=`uname -r | cut -b1` +release=`uname -r` +major=`printf "%s" "$release" | cut -d. -f1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" VAR_DIR="./inst/var/stargazer" @@ -54,14 +55,13 @@ LDFLAGS="$LDFLAGS -L/usr/local/lib" if [ "$sys" = "Linux" ] then OS=linux - release="" ETC_DIR="./inst/linux/etc/stargazer" MAKE="make" fi if [ "$sys" = "FreeBSD" ] then - case $release in + case $major in 4) OS=bsd;; 5) OS=bsd5;; 6) OS=bsd5;; @@ -82,7 +82,7 @@ fi if [ "$OS" = "unknown" ] then printf "#############################################################################\n" - printf "# Sorry, but stargazer currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "# Sorry, but stargazer is currently supported by Linux, FreeBSD and Darwin. #\n" printf "#############################################################################\n" exit 1 fi @@ -117,6 +117,7 @@ then capture/ether_linux" LIB_THREAD=-lpthread else + LIBICONV="-liconv" if [ "$OS" = "bsd" ] then DEFS="$DEFS -DFREE_BSD" @@ -131,6 +132,7 @@ else then DEFS="$DEFS -DDARWIN" LIB_THREAD=-lpthread + LIBICONV="" else LIB_THREAD=-lc_r fi @@ -197,7 +199,7 @@ rm -f fake printf "Checking for -lexpat... " printf "#include \nint main() { return 0; }\n" > build_check.c -$CXX $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null +$CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_EXPAT=no @@ -208,18 +210,60 @@ else fi rm -f fake -printf "Checking for -lfbclient... " -printf "int main() { return 0; }\n" > build_check.c -$CXX $CXXFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null +printf "Checking for iconv 2nd argument... " +printf "#include \nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c +$CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - CHECK_FBCLIENT=no + printf "non-const\n" +else + DEFS="$DEFS -DCONST_ICONV" + printf "const\n" +fi +rm -f fake + +printf "Checking for fb_config... " +FB_VERSION=`fb_config --version 2> /dev/null` +if [ "$?" != "0" ] +then printf "no\n" + printf "Checking for -lfbclient... " + printf "int main() { return 0; }\n" > build_check.c + $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null + if [ $? != 0 ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + FB_CFLAGS="" + FB_LDFLAGS="-lfbclient" + CHECK_FBCLIENT=yes + printf "yes\n" + fi + rm -f fake else - CHECK_FBCLIENT=yes printf "yes\n" + printf "Checking for fb_config --cflags... " + FB_CFLAGS=`fb_config --cflags` + if [ "$?" != "0" ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + printf "[$FB_CFLAGS]\n" + printf "Checking for fb_config --libs " + FB_LDFLAGS=`fb_config --libs` + if [ "$?" != "0" ] + then + CHECK_FBCLIENT=no + printf "no\n" + else + CHECK_FBCLIENT=yes + printf "[$FB_LDFLAGS]\n" + fi + fi fi -rm -f fake + printf "Checking for mysql_config... " printf "#include \nint main() { return 0; }\n" > build_check.c @@ -228,13 +272,15 @@ if [ $? != 0 ] then printf "no\n"; printf "Checking for -lmysqlclient... " - $CXX $CXXFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null + $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_MYSQLCLIENT=no printf "no\n" else CHECK_MYSQLCLIENT=yes + MYSQL_CFLAGS="" + MYSQL_LDFLAGS="-lmysqlclient_r" printf "yes\n" fi rm -f fake @@ -268,7 +314,7 @@ if [ $? != 0 ] then printf "no\n"; printf "Checking for -lpq... " - $CXX $CXXFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null + $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_PQ=no @@ -281,7 +327,7 @@ then else printf "yes\n"; printf "Checking for pg_config --includedir... " - PG_CFLAGS=`pg_config --includedir 2> /dev/null` + PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no @@ -289,7 +335,7 @@ else else printf "[$PG_CFLAGS]\n" printf "Checking for pg_config --libdir... " - PG_LDFLAGS=`pg_config --libdir 2> /dev/null` + PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no @@ -308,7 +354,7 @@ if [ $? != 0 ] then printf "no\n"; printf "Checking for -lxmlrpc... " - $CXX $CXXFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null + $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_XMLRPC=no @@ -347,7 +393,7 @@ fi printf "Checking for -lpcap... " printf "#include \nint main() { return 0; }\n" > build_check.c -$CXX $CXXFLAGS $LDFLAGS build_check.c -lpcap -o fake > /dev/null 2> /dev/null +$CC $CFLAGS $LDFLAGS build_check.c -lpcap -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_PCAP=no @@ -359,27 +405,29 @@ fi rm -f fake printf "Checking for -lnfnetlink... " -printf "#include \nint main() { return 0; }\n" > build_check.c -$CXX $CXXFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null +printf "#include \n#include \n#include \nint main() { return 0; }\n" > build_check.c +$CC $CFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_NFNETLINK=no printf "no\n" else CHECK_NFNETLINK=yes + NETLINK_LDFLAGS="-lnfnetlink" printf "yes\n" fi rm -f fake printf "Checking for -lnetfilter_queue... " -printf "#include \nint main() { return 0; }\n" > build_check.c -$CXX $CXXFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null +printf "#include \n#include \nint main() { return 0; }\n" > build_check.c +$CC $CFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_NFQ=no printf "no\n" else CHECK_NFQ=yes + NFQ_LDFLAGS="-lnetfilter_queue" printf "yes\n" fi rm -f fake @@ -390,7 +438,7 @@ then printf "#include \n" > build_check.c printf "#include \n" >> build_check.c printf "int main() { return 0; }\n" >> build_check.c - $CXX $CXXFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null + $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_IP_QUEUE_H=no @@ -449,7 +497,6 @@ if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ] then PLUGINS="$PLUGINS capture/nfqueue" - NFQ_LIBS="-lnfnetlink -lnetfilter_queue" fi printf "OS=$OS\n" > $CONFFILE @@ -464,14 +511,41 @@ printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE printf "ARCH=$ARCH\n" >> $CONFFILE printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE +if [ "$CHECK_FBCLIENT" = "yes" ] +then + printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE + printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE +fi printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE +if [ "$CHECK_MYSQLCLIENT" = "yes" ] +then + printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE + printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE +fi printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE +if [ "$CHECK_PQ" = "yes" ] +then + printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE + printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE +fi printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE +if [ "$CHECK_XMLRPC" = "yes" ] +then + printf "XMLRPC_CFLAGS=$XMLRPC_CFLAGS\n" >> $CONFFILE + printf "XMLRPC_LDFLAGS=$XMLRPC_LDFLAGS\n" >> $CONFFILE +fi printf "CHECK_PCAP=$CHECK_PCAP\n" >> $CONFFILE printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE +if [ "$CHECK_NFNETLINK" = "yes" ] +then + printf "NETLINK_LDFLAGS=$NETLINK_LDFLAGS\n" >> $CONFFILE +fi printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE +if [ "$CHECK_NFQ" = "yes" ] +then + printf "NFQ_LDFLAGS=$NFQ_LDFLAGS\n" >> $CONFFILE +fi printf "DEFS=$DEFS\n" >> $CONFFILE -printf "NFQ_LIBS=$NFQ_LIBS\n" >> $CONFFILE printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do @@ -484,10 +558,13 @@ do printf "$plugin " >> $CONFFILE done printf "\n" >> $CONFFILE +printf "CC=$CC\n" >> $CONFFILE +printf "CXX=$CXX\n" >> $CONFFILE printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE printf "CFLAGS=$CFLAGS\n" >> $CONFFILE printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "LIBICONV=$LIBICONV\n" >> $CONFFILE printf "PREFIX=$PREFIX\n" >> $CONFFILE printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 73786c4e..702bfb86 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -266,6 +266,11 @@ for (size_t i = 0; i < settings.GetExecutersNum(); i++) PIDFile pidFile(settings.GetPIDFileName()); +struct sigaction sa; +memset(&sa, 0, sizeof(sa)); +sa.sa_handler = SIG_DFL; +sigaction(SIGHUP, &sa, NULL); // Apparently FreeBSD ignores SIGHUP by default when launched from rc.d at bot time. + sigset_t signalSet; sigfillset(&signalSet); pthread_sigmask(SIG_BLOCK, &signalSet, NULL); @@ -338,8 +343,16 @@ while (running) switch (sig) { case SIGHUP: + { + SETTINGS_IMPL newSettings(settings); + if (newSettings.ReadSettings()) + WriteServLog("ReadSettings error. %s", newSettings.GetStrError().c_str()); + else + settings = newSettings; + WriteServLog.SetLogFileName(settings.GetLogFileName()); traffCnt.Reload(); - manager.reload(); + manager.reload(settings); + } break; case SIGTERM: running = false; @@ -363,6 +376,8 @@ while (running) WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); +manager.stop(); + if (loop.Stop()) WriteServLog("Event loop not stopped."); diff --git a/projects/stargazer/plugin_mgr.cpp b/projects/stargazer/plugin_mgr.cpp index 5346db8b..85215c7b 100644 --- a/projects/stargazer/plugin_mgr.cpp +++ b/projects/stargazer/plugin_mgr.cpp @@ -59,12 +59,13 @@ PluginManager::PluginManager(const SETTINGS_IMPL& settings, const std::vector & modSettings(settings.GetModulesSettings()); for (size_t i = 0; i < modSettings.size(); i++) { - std::string modulePath = basePath + "/mod_" + modSettings[i].moduleName + ".so"; + std::string moduleName = modSettings[i].moduleName; + std::string modulePath = basePath + "/mod_" + moduleName + ".so"; printfd(__FILE__, "Module: %s\n", modulePath.c_str()); try { m_modules.push_back( - new PLUGIN_RUNNER(modulePath, modSettings[i], admins, tariffs, + new PLUGIN_RUNNER(modulePath, moduleName, modSettings[i], admins, tariffs, users, services, corporations, traffcounter, store, settings) ); @@ -96,17 +97,49 @@ PluginManager::PluginManager(const SETTINGS_IMPL& settings, } PluginManager::~PluginManager() +{ + stop(); + for (size_t i = 0; i < m_modules.size(); ++i) + delete m_modules[i]; +} + +void PluginManager::reload(const SETTINGS_IMPL& settings) +{ + const std::vector & modSettings(settings.GetModulesSettings()); + for (size_t i = 0; i < m_modules.size(); ++i) + { + for (size_t j = 0; j < modSettings.size(); j++) + { + if (modSettings[j].moduleName == m_modules[i]->GetName()) + { + PLUGIN & plugin = m_modules[i]->GetPlugin(); + if (m_modules[i]->Reload(modSettings[j])) + { + m_log("Error reloading module '%s': '%s'", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + printfd(__FILE__, "Error reloading module '%s': '%s'\n", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + } + break; + } + } + } +} + +void PluginManager::stop() { std::sort(m_modules.begin(), m_modules.end(), StopModCmp); for (size_t i = 0; i < m_modules.size(); ++i) { + if (!m_modules[i]->IsRunning()) + continue; PLUGIN & plugin = m_modules[i]->GetPlugin(); if (m_modules[i]->Stop()) { m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(), plugin.GetStrError().c_str()); printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); + plugin.GetStrError().c_str()); } else { @@ -114,21 +147,4 @@ PluginManager::~PluginManager() printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str()); } } - for (size_t i = 0; i < m_modules.size(); ++i) - delete m_modules[i]; -} - -void PluginManager::reload() -{ - for (size_t i = 0; i < m_modules.size(); ++i) - { - PLUGIN & plugin = m_modules[i]->GetPlugin(); - if (m_modules[i]->Reload()) - { - m_log("Error reloading module '%s': '%s'", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - printfd(__FILE__, "Error reloading module '%s': '%s'\n", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - } - } } diff --git a/projects/stargazer/plugin_mgr.h b/projects/stargazer/plugin_mgr.h index 79b6cae9..a37052d5 100644 --- a/projects/stargazer/plugin_mgr.h +++ b/projects/stargazer/plugin_mgr.h @@ -48,7 +48,8 @@ class PluginManager USERS_IMPL& users, TRAFFCOUNTER_IMPL& traffcounter); ~PluginManager(); - void reload(); + void reload(const SETTINGS_IMPL& settings); + void stop(); private: std::vector m_modules; diff --git a/projects/stargazer/plugin_runner.cpp b/projects/stargazer/plugin_runner.cpp index eaf51058..e57a421e 100644 --- a/projects/stargazer/plugin_runner.cpp +++ b/projects/stargazer/plugin_runner.cpp @@ -28,6 +28,7 @@ //----------------------------------------------------------------------------- PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & fileName, + const std::string & name, const MODULE_SETTINGS & ms, ADMINS & admins, TARIFFS & tariffs, @@ -38,6 +39,7 @@ PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & fileName, STORE & store, const SETTINGS & settings) : pluginFileName(fileName), + pluginName(name), libHandle(NULL), m_plugin(Load(ms, admins, tariffs, users, services, corporations, traffcounter, store, settings)) @@ -67,9 +69,9 @@ errorStr = m_plugin.GetStrError(); return res; } //----------------------------------------------------------------------------- -int PLUGIN_RUNNER::Reload() +int PLUGIN_RUNNER::Reload(const MODULE_SETTINGS & ms) { -int res = m_plugin.Reload(); +int res = m_plugin.Reload(ms); errorStr = m_plugin.GetStrError(); return res; } diff --git a/projects/stargazer/plugin_runner.h b/projects/stargazer/plugin_runner.h index 1402d2ef..2d0c22c4 100644 --- a/projects/stargazer/plugin_runner.h +++ b/projects/stargazer/plugin_runner.h @@ -46,6 +46,7 @@ public: }; PLUGIN_RUNNER(const std::string & pluginFileName, + const std::string & pluginName, const MODULE_SETTINGS & ms, ADMINS & admins, TARIFFS & tariffs, @@ -59,13 +60,14 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); int Restart(); bool IsRunning() { return m_plugin.IsRunning(); } const std::string & GetStrError() const { return errorStr; } PLUGIN & GetPlugin() { return m_plugin; } const std::string & GetFileName() const { return pluginFileName; } + const std::string & GetName() const { return pluginName; } uint16_t GetStartPosition() const { return m_plugin.GetStartPosition(); } uint16_t GetStopPosition() const { return m_plugin.GetStopPosition(); } @@ -85,6 +87,7 @@ private: const SETTINGS & settings); std::string pluginFileName; + std::string pluginName; void * libHandle; PLUGIN & m_plugin; diff --git a/projects/stargazer/plugins/Makefile.in b/projects/stargazer/plugins/Makefile.in index dd1e124a..36aebbef 100644 --- a/projects/stargazer/plugins/Makefile.in +++ b/projects/stargazer/plugins/Makefile.in @@ -13,8 +13,8 @@ STGLIBS_PATHS = $(addprefix -L ../../../../../stglibs/,$(addsuffix .lib,$(STGLIB STGLIBS_LIBS = $(addprefix -lstg,$(STGLIBS)) -CXXFLAGS += -fPIC $(STGLIBS_INCS) -CFLAGS += -fPIC $(STGLIBS_INCS) +CXXFLAGS += -fPIC $(DEFS) $(SEARCH_DIRS) $(STGLIBS_INCS) +CFLAGS += -fPIC $(DEFS) $(SEARCH_DIRS) $(STGLIBS_INCS) ifneq ($(OS),darwin) LDFLAGS += -shared -Wl,-rpath,$(PREFIX)/usr/lib/stg @@ -25,7 +25,7 @@ endif all: $(PROG) $(PROG): $(OBJS) - $(CXX) $^ $(STGLIBS_PATHS) $(STGLIBS_LIBS) $(LIBS) $(LDFLAGS) -o $(PROG) + $(CXX) $^ $(LDFLAGS) $(STGLIBS_PATHS) $(STGLIBS_LIBS) $(LIBS) -o $(PROG) $(LN) -fs "`pwd`/$(PROG)" $(DIR_MOD)/$(PROG) clean: @@ -34,9 +34,9 @@ clean: install: $(PROG) mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib/stg ifeq ($(DEBUG), yes) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/lib/stg/$(PROG) + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/lib/stg/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/stg/$(PROG) + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/stg/$(PROG) endif uninstall: diff --git a/projects/stargazer/plugins/authorization/ao/ao.cpp b/projects/stargazer/plugins/authorization/ao/ao.cpp index 100e0557..5acea091 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.cpp +++ b/projects/stargazer/plugins/authorization/ao/ao.cpp @@ -70,15 +70,8 @@ return "Always Online authorizator v.1.0"; } //----------------------------------------------------------------------------- AUTH_AO::AUTH_AO() - : errorStr(), - users(NULL), - usersList(), + : users(NULL), isRunning(false), - settings(), - BeforeChgAONotifierList(), - AfterChgAONotifierList(), - BeforeChgIPNotifierList(), - AfterChgIPNotifierList(), onAddUserNotifier(*this), onDelUserNotifier(*this), logger(GetPluginLogger(GetStgLogger(), "auth_ao")) diff --git a/projects/stargazer/plugins/authorization/ao/ao.h b/projects/stargazer/plugins/authorization/ao/ao.h index d8b6dc88..9ed7ffcf 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.h +++ b/projects/stargazer/plugins/authorization/ao/ao.h @@ -89,7 +89,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS &) {} int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 9c8ae1af..99e0a091 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -86,7 +86,7 @@ std::vector::const_iterator pvi; /////////////////////////// pv.param = "Port"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@ -102,7 +102,7 @@ port = static_cast(p); /////////////////////////// pv.param = "UserDelay"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserDelay\' not found."; printfd(__FILE__, "Parameter 'UserDelay' not found\n"); @@ -118,7 +118,7 @@ if (ParseIntInRange(pvi->value[0], 5, 600, &userDelay)) /////////////////////////// pv.param = "UserTimeout"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserTimeout\' not found."; printfd(__FILE__, "Parameter 'UserTimeout' not found\n"); @@ -134,7 +134,7 @@ if (ParseIntInRange(pvi->value[0], 15, 1200, &userTimeout)) /////////////////////////// pv.param = "LogProtocolErrors"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) logProtocolErrors = false; else if (ParseYesNo(pvi->value[0], &logProtocolErrors)) { @@ -147,7 +147,7 @@ std::string freeMbType; int n = 0; pv.param = "FreeMb"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'FreeMb\' not found."; printfd(__FILE__, "Parameter 'FreeMb' not found\n"); @@ -188,15 +188,13 @@ return 0; #ifdef IA_PHASE_DEBUG IA_PHASE::IA_PHASE() : phase(1), - phaseTime(), flog(NULL) { gettimeofday(&phaseTime, NULL); } #else IA_PHASE::IA_PHASE() - : phase(1), - phaseTime() + : phase(1) { gettimeofday(&phaseTime, NULL); } @@ -526,6 +524,22 @@ if (ret) return ret; } //----------------------------------------------------------------------------- +int AUTH_IA::Reload(const MODULE_SETTINGS & ms) +{ +AUTH_IA_SETTINGS newIaSettings; +if (newIaSettings.ParseSettings(ms)) + { + printfd(__FILE__, "AUTH_IA::Reload() - Failed to reload InetAccess.\n"); + logger("AUTH_IA: Cannot reload InetAccess. Errors found."); + return -1; + } + +printfd(__FILE__, "AUTH_IA::Reload() - Reloaded InetAccess successfully.\n"); +logger("AUTH_IA: Reloaded InetAccess successfully."); +iaSettings = newIaSettings; +return 0; +} +//----------------------------------------------------------------------------- int AUTH_IA::PrepareNet() { struct sockaddr_in listenAddr; diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index 5e454124..2b527076 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -247,7 +247,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return isRunningRunTimeouter || isRunningRun; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/authorization/stress/stress.h b/projects/stargazer/plugins/authorization/stress/stress.h index 83ab3231..6ead8f33 100644 --- a/projects/stargazer/plugins/authorization/stress/stress.h +++ b/projects/stargazer/plugins/authorization/stress/stress.h @@ -93,7 +93,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning(); void SetSettings(const MODULE_SETTINGS & s); int ParseSettings(); diff --git a/projects/stargazer/plugins/capture/cap_debug/debug_cap.h b/projects/stargazer/plugins/capture/cap_debug/debug_cap.h index 6bea457f..8b1ccb92 100644 --- a/projects/stargazer/plugins/capture/cap_debug/debug_cap.h +++ b/projects/stargazer/plugins/capture/cap_debug/debug_cap.h @@ -69,7 +69,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } int ParseSettings() { return 0; } bool IsRunning(); const std::string & GetStrError() const; diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp index 8c4fdc2d..ce42d911 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp @@ -59,9 +59,6 @@ return cnc.GetPlugin(); NF_CAP::NF_CAP() : traffCnt(NULL), - settings(), - tidTCP(), - tidUDP(), runningTCP(false), runningUDP(false), stoppedTCP(true), @@ -70,7 +67,6 @@ NF_CAP::NF_CAP() portU(0), sockTCP(-1), sockUDP(-1), - errorStr(), logger(GetPluginLogger(GetStgLogger(), "cap_nf")) { } @@ -84,7 +80,7 @@ int NF_CAP::ParseSettings() std::vector::iterator it; for (it = settings.moduleParams.begin(); it != settings.moduleParams.end(); ++it) { - if (it->param == "TCPPort") + if (it->param == "TCPPort" && !it->value.empty()) { if (str2x(it->value[0], portT)) { @@ -94,7 +90,7 @@ for (it = settings.moduleParams.begin(); it != settings.moduleParams.end(); ++it } continue; } - if (it->param == "UDPPort") + if (it->param == "UDPPort" && !it->value.empty()) { if (str2x(it->value[0], portU)) { diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h index bcb8b743..7d24403b 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h @@ -99,7 +99,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return runningTCP || runningUDP; } const std::string & GetStrError() const { return errorStr; } std::string GetVersion() const { return VERSION; } diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 400709bd..aebca059 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -84,11 +84,8 @@ return "cap_divert v.1.0"; } //----------------------------------------------------------------------------- DIVERT_CAP::DIVERT_CAP() - : settings(), - port(0), + : port(0), disableForwarding(false), - errorStr(), - thread(), nonstop(false), isRunning(false), traffCnt(NULL), @@ -290,7 +287,7 @@ std::vector::const_iterator pvi; pv.param = "Port"; pvi = std::find(settings.moduleParams.begin(), settings.moduleParams.end(), pv); -if (pvi == settings.moduleParams.end()) +if (pvi == settings.moduleParams.end() || pvi->value.empty()) { p = 15701; } @@ -306,7 +303,7 @@ port = p; bool d = false; pv.param = "DisableForwarding"; pvi = std::find(settings.moduleParams.begin(), settings.moduleParams.end(), pv); -if (pvi == settings.moduleParams.end()) +if (pvi == settings.moduleParams.end() || pvi->value.empty()) { disableForwarding = false; } diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h index b34f832e..d8f4d6f8 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h @@ -51,7 +51,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp index 254fd3f9..36159fed 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp @@ -121,15 +121,9 @@ return "cap_bpf v.1.0"; } //----------------------------------------------------------------------------- BPF_CAP::BPF_CAP() - : capSettings(), - errorStr(), - bpfData(), - polld(), - thread(), - nonstop(false), + : nonstop(false), isRunning(false), capSock(-1), - settings(), traffCnt(NULL), logger(GetPluginLogger(GetStgLogger(), "cap_bpf")) { diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h index 76785ed2..b9150b8d 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h @@ -98,7 +98,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp index fd83c485..cc64bc18 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp @@ -78,9 +78,7 @@ return "cap_ether v.1.2"; } //----------------------------------------------------------------------------- ETHER_CAP::ETHER_CAP() - : errorStr(), - thread(), - nonstop(false), + : nonstop(false), isRunning(false), capSock(-1), traffCnt(NULL), diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h index 8dfb6c04..5bb938fe 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h @@ -52,7 +52,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp index 45ca9b1f..18696ec2 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp @@ -63,13 +63,10 @@ return "cap_ipq v.1.2"; //----------------------------------------------------------------------------- IPQ_CAP::IPQ_CAP() : ipq_h(NULL), - errorStr(), - thread(), nonstop(false), isRunning(false), capSock(-1), traffCnt(NULL), - buf(), logger(GetPluginLogger(GetStgLogger(), "cap_ipq")) { memset(buf, 0, BUFSIZE); diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h index 39ed5766..b7f76b05 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h @@ -47,7 +47,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } int ParseSettings() { return 0; } diff --git a/projects/stargazer/plugins/capture/nfqueue/Makefile b/projects/stargazer/plugins/capture/nfqueue/Makefile index a9f4a803..05a87af6 100644 --- a/projects/stargazer/plugins/capture/nfqueue/Makefile +++ b/projects/stargazer/plugins/capture/nfqueue/Makefile @@ -4,7 +4,7 @@ PROG = mod_cap_nfqueue.so SRCS = ./nfqueue.cpp -LIBS += $(NFQ_LIBS) $(LIB_THREAD) +LIBS += $(NFQ_LDFLAGS) $(NETLINK_LDFLAGS) $(LIB_THREAD) STGLIBS = common \ logger diff --git a/projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp b/projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp index 68f7270c..0c14c10f 100644 --- a/projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp +++ b/projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp @@ -93,9 +93,7 @@ return "cap_nfqueue v.1.0"; } //----------------------------------------------------------------------------- NFQ_CAP::NFQ_CAP() - : errorStr(), - thread(), - nonstop(false), + : nonstop(false), isRunning(false), queueNumber(0), nfqHandle(NULL), @@ -108,8 +106,8 @@ NFQ_CAP::NFQ_CAP() int NFQ_CAP::ParseSettings() { for (size_t i = 0; i < settings.moduleParams.size(); i++) - if (settings.moduleParams[i].param == "queueNumber") - if (str2x(settings.moduleParams[i].param, queueNumber) < 0) + if (settings.moduleParams[i].param == "queueNumber" && !settings.moduleParams[i].value.empty()) + if (str2x(settings.moduleParams[i].value[0], queueNumber) < 0) { errorStr = "Queue number should be a number. Got: '" + settings.moduleParams[i].param + "'"; logger(errorStr); diff --git a/projects/stargazer/plugins/capture/nfqueue/nfqueue.h b/projects/stargazer/plugins/capture/nfqueue/nfqueue.h index 87124784..27198073 100644 --- a/projects/stargazer/plugins/capture/nfqueue/nfqueue.h +++ b/projects/stargazer/plugins/capture/nfqueue/nfqueue.h @@ -51,7 +51,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/capture/pcap/pcap_cap.cpp b/projects/stargazer/plugins/capture/pcap/pcap_cap.cpp index 5e3e874d..d085df66 100644 --- a/projects/stargazer/plugins/capture/pcap/pcap_cap.cpp +++ b/projects/stargazer/plugins/capture/pcap/pcap_cap.cpp @@ -63,9 +63,7 @@ return "pcap_cap v.1.0"; } //----------------------------------------------------------------------------- PCAP_CAP::PCAP_CAP() - : errorStr(), - thread(), - nonstop(false), + : nonstop(false), isRunning(false), traffCnt(NULL), logger(GetPluginLogger(GetStgLogger(), "pcap_cap")) diff --git a/projects/stargazer/plugins/capture/pcap/pcap_cap.h b/projects/stargazer/plugins/capture/pcap/pcap_cap.h index bf050c17..3bdfd55e 100644 --- a/projects/stargazer/plugins/capture/pcap/pcap_cap.h +++ b/projects/stargazer/plugins/capture/pcap/pcap_cap.h @@ -65,7 +65,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/Makefile b/projects/stargazer/plugins/configuration/rpcconfig/Makefile index cbbe79c6..c647f752 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/Makefile +++ b/projects/stargazer/plugins/configuration/rpcconfig/Makefile @@ -15,14 +15,9 @@ SRCS = ./rpcconfig.cpp \ ./admins_methods.cpp \ ./messages_methods.cpp -XMLRPC_C_LIBS = $(shell xmlrpc-c-config c++2 abyss-server --libs) - -LIBS += $(XMLRPC_C_LIBS) \ - $(LIB_THREAD) - -ifneq ($(OS),linux) -LIBS += -liconv -endif +LIBS += $(XMLRPC_LDFLAGS) \ + $(LIB_THREAD) \ + $(LIBICONV) STGLIBS = common \ logger \ diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp index dca87fbe..3b28ddd8 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp @@ -33,8 +33,7 @@ PLUGIN_CREATOR rpcc; extern "C" PLUGIN * GetPlugin(); RPC_CONFIG_SETTINGS::RPC_CONFIG_SETTINGS() - : errorStr(), - port(0), + : port(0), cookieTimeout(0) { } @@ -45,7 +44,7 @@ PARAM_VALUE pv; pv.param = "Port"; std::vector::const_iterator pvi; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@ -62,7 +61,7 @@ port = static_cast(p); pv.param = "CookieTimeout"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { cookieTimeout = 1800; // 30 * 60 } @@ -85,22 +84,15 @@ return rpcc.GetPlugin(); } RPC_CONFIG::RPC_CONFIG() - : errorStr(), - rpcConfigSettings(), - users(NULL), + : users(NULL), admins(NULL), tariffs(NULL), store(NULL), - settings(), fd(-1), - rpcRegistry(), rpcServer(NULL), running(false), stopped(true), - tid(), - cookies(), dayFee(0), - dirNames(), logger(GetPluginLogger(GetStgLogger(), "conf_rpc")) { } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h index 72a14f21..ce295818 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h @@ -70,7 +70,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return running && !stopped; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.h b/projects/stargazer/plugins/configuration/sgconfig/configproto.h index e18ae82e..c464e95e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -61,9 +61,9 @@ public: void SetAdmins(ADMINS * admins) { m_admins = admins; } void SetTariffs(TARIFFS * tariffs) { m_tariffs = tariffs; } void SetUsers(USERS * users) { m_users = users; } + void SetStore(STORE * store) { m_store = store; } void SetServices(SERVICES * services) { m_services = services; } void SetCorporations(CORPORATIONS * corporations) { m_corporations = corporations; } - void SetStore(STORE * store) { m_store = store; } int Prepare(); int Stop(); diff --git a/projects/stargazer/plugins/configuration/sgconfig/conn.cpp b/projects/stargazer/plugins/configuration/sgconfig/conn.cpp index 8bba49be..c792125e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.cpp @@ -60,7 +60,12 @@ Conn::Conn(const BASE_PARSER::REGISTRY & registry, m_bufferSize(sizeof(m_header)), m_stream(NULL), m_logger(logger), +#ifdef DUMPCRYPTO + m_dataState(false, *this), + m_dumper(endpoint()) +#else m_dataState(false, *this) +#endif { if (m_xmlParser == NULL) throw Error("Failed to create XML parser."); @@ -84,16 +89,20 @@ bool Conn::Read() if (res < 0) { m_state = ERROR; - Log(__FILE__, "Failed to read data from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Reason: '" + strerror(errno) + "'"); + Log(__FILE__, "Failed to read data from " + endpoint() + ". Reason: '" + strerror(errno) + "'"); return false; } if (res == 0 && m_state != DATA) // EOF is ok for data. { m_state = ERROR; - Log(__FILE__, "Failed to read data from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Unexpected EOF."); + Log(__FILE__, "Failed to read data from " + endpoint() + ". Unexpected EOF."); return false; } +#ifdef DUMPCRYPTO + m_dumper.write(m_buffer, res); +#endif m_bufferSize -= res; + m_buffer = static_cast(m_buffer) + res; return HandleBuffer(res); } @@ -103,7 +112,7 @@ bool Conn::WriteAnswer(const void* buffer, size_t size) if (res < 0) { m_state = ERROR; - Log(__FILE__, "Failed to write data to " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Reason: '" + strerror(errno) + "'."); + Log(__FILE__, "Failed to write data to " + endpoint() + ". Reason: '" + strerror(errno) + "'."); return false; } return true; @@ -140,7 +149,7 @@ bool Conn::HandleHeader() { if (strncmp(m_header, STG_HEADER, sizeof(m_header)) != 0) { - Log(__FILE__, "Received invalid header from " + inet_ntostring(IP()) + ":" + x2str(Port()) + "."); + Log(__FILE__, "Received invalid header from " + endpoint() + "."); WriteAnswer(ERR_HEADER, sizeof(ERR_HEADER) - 1); // Without \0 m_state = ERROR; return false; @@ -156,7 +165,7 @@ bool Conn::HandleLogin() if (m_admins.Find(m_login, &m_admin)) // ADMINS::Find returns true on error. { std::string login(m_login, strnlen(m_login, sizeof(m_login))); - Log(__FILE__, "Received invalid login '" + ToPrintable(login) + "' from " + inet_ntostring(IP()) + ":" + x2str(Port()) + "."); + Log(__FILE__, "Received invalid login '" + ToPrintable(login) + "' from " + endpoint() + "."); WriteAnswer(ERR_LOGIN, sizeof(ERR_LOGIN) - 1); // Without \0 m_state = ERROR; return false; @@ -177,7 +186,7 @@ bool Conn::HandleCryptoLogin() if (strncmp(m_login, login, sizeof(login)) != 0) { - Log(__FILE__, "Attempt to connect with wrong password from " + m_admin->GetLogin() + "@" + inet_ntostring(IP()) + ":" + x2str(Port()) + "."); + Log(__FILE__, "Attempt to connect with wrong password from " + m_admin->GetLogin() + "@" + endpoint() + "."); WriteAnswer(ERR_LOGINS, sizeof(ERR_LOGINS) - 1); // Without \0 m_state = ERROR; return false; @@ -192,7 +201,8 @@ bool Conn::HandleCryptoLogin() bool Conn::HandleData(size_t size) { - m_stream->Put(m_buffer, size, size == 0 || memchr(m_buffer, 0, size) != NULL); + m_stream->Put(m_data, size, size == 0 || memchr(m_data, 0, size) != NULL); + m_buffer = m_data; return m_stream->IsOk(); } @@ -208,7 +218,7 @@ bool Conn::DataCallback(const void * block, size_t size, void * data) if (XML_Parse(state.conn.m_xmlParser, xml, length, state.final) == XML_STATUS_ERROR) { - state.conn.Log(__FILE__, "Received invalid XML from " + state.conn.m_admin->GetLogin() + "@" + inet_ntostring(state.conn.IP()) + ":" + x2str(state.conn.Port()) + "."); + state.conn.Log(__FILE__, "Received invalid XML from " + state.conn.m_admin->GetLogin() + "@" + state.conn.endpoint() + "."); printfd(__FILE__, "XML parse error at line %d, %d: %s. Is final: %d\n", static_cast(XML_GetCurrentLineNumber(state.conn.m_xmlParser)), static_cast(XML_GetCurrentColumnNumber(state.conn.m_xmlParser)), @@ -222,7 +232,7 @@ bool Conn::DataCallback(const void * block, size_t size, void * data) { if (!state.conn.WriteResponse()) { - state.conn.Log(__FILE__, "Failed to write response to " + state.conn.m_admin->GetLogin() + "@" + inet_ntostring(state.conn.IP()) + ":" + x2str(state.conn.Port()) + "."); + state.conn.Log(__FILE__, "Failed to write response to " + state.conn.m_admin->GetLogin() + "@" + state.conn.endpoint() + "."); state.conn.m_state = ERROR; return false; } @@ -242,7 +252,7 @@ void Conn::ParseXMLStart(void * data, const char * el, const char ** attr) if (conn.m_parser == NULL) { - conn.Log(__FILE__, "Received unknown command '" + std::string(el) + "' from " + conn.m_admin->GetLogin() + "@" + inet_ntostring(conn.IP()) + ":" + x2str(conn.Port()) + "."); + conn.Log(__FILE__, "Received unknown command '" + std::string(el) + "' from " + conn.m_admin->GetLogin() + "@" + conn.endpoint() + "."); conn.m_state = ERROR; return; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/conn.h b/projects/stargazer/plugins/configuration/sgconfig/conn.h index fae0c4b2..c67c972e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.h +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.h @@ -23,6 +23,8 @@ #include "parser.h" +#include "dumphelpers.h" + #include "stg/os_int.h" #include "stg/const.h" @@ -63,6 +65,8 @@ class Conn uint32_t IP() const { return *(uint32_t *)(&m_addr.sin_addr); } uint16_t Port() const { return ntohs(m_addr.sin_port); } + std::string endpoint() const { return inet_ntostring(IP()) + ":" + x2str(Port()); } + bool Read(); bool IsOk() const { return m_state != ERROR; } @@ -127,6 +131,10 @@ class Conn Conn & conn; } m_dataState; +#ifdef DUMPCRYPTO + Dumper m_dumper; +#endif + static bool DataCallback(const void * block, size_t size, void * data); static void ParseXMLStart(void * data, const char * el, const char ** attr); static void ParseXMLEnd(void * data, const char * el); diff --git a/projects/stargazer/plugins/configuration/sgconfig/dumphelpers.h b/projects/stargazer/plugins/configuration/sgconfig/dumphelpers.h new file mode 100644 index 00000000..cc02d14d --- /dev/null +++ b/projects/stargazer/plugins/configuration/sgconfig/dumphelpers.h @@ -0,0 +1,85 @@ +#ifndef __STG_DUMP_HELPERS_H__ +#define __STG_DUMP_HELPERS_H__ + +#include "stg/common.h" + +#include +#include +#include +#include + +#include +#include + +namespace STG +{ + +class Dumper +{ + public: + explicit Dumper(const std::string& tag) + : m_stream(getName(tag).c_str()) + { + } + ~Dumper() {} + + void write(const void* data, size_t size) + { + writePrefix(); + m_stream << " "; + writeHEX(data, size); + } + + private: + std::ofstream m_stream; + + tm getTime() const + { + time_t now = time(NULL); + tm localTime; + localtime_r(&now, &localTime); + return localTime; + } + + std::string getName(const std::string& tag) const + { + tm localTime = getTime(); + + std::ostringstream res; + res << tag + << "-" << (localTime.tm_year + 1900) << twoDigit(localTime.tm_mon + 1) << twoDigit(localTime.tm_mday) + << "-" << twoDigit(localTime.tm_hour) << twoDigit(localTime.tm_min) << twoDigit(localTime.tm_sec) + << ".data"; + + return res.str(); + } + + void writePrefix() + { + tm localTime = getTime(); + m_stream << "[" << (localTime.tm_year + 1900) << "-" << twoDigit(localTime.tm_mon + 1) << "-" << twoDigit(localTime.tm_mday) + << " " << twoDigit(localTime.tm_hour) << ":" << twoDigit(localTime.tm_min) << ":" << twoDigit(localTime.tm_sec) + << "]"; + } + + void writeHEX(const void* data, size_t size) + { + m_stream << "(" << std::setw(4) << std::setfill(' ') << size << ") "; + const unsigned char* pos = static_cast(data); + for (size_t i = 0; i < size; ++i) + m_stream << std::hex << std::setw(2) << std::setfill('0') << static_cast(*pos++); + m_stream << std::dec << "\n"; + } + + std::string twoDigit(int value) const + { + std::string res = x2str(value); + if (res.length() < 2) + res = "0" + res; + return res; + } +}; + +} // namespace Caster + +#endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index e52eb3fa..03717981 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -40,7 +40,6 @@ int BASE_PARSER::End(void *, const char * el) if (strcasecmp(el, m_tag.c_str()) != 0) return -1; CreateAnswer(); - m_done = true; } --m_depth; diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.h b/projects/stargazer/plugins/configuration/sgconfig/parser.h index 4e4b9417..af77158d 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.h @@ -38,8 +38,7 @@ class BASE_PARSER BASE_PARSER(const ADMIN & admin, const std::string & t) : m_currAdmin(admin), m_depth(0), - m_tag(t), - m_done(false) + m_tag(t) {} virtual ~BASE_PARSER() {} virtual int Start(void * data, const char * el, const char ** attr); @@ -50,8 +49,6 @@ class BASE_PARSER std::string GetOpenTag() const { return "<" + m_tag + ">"; } std::string GetCloseTag() const { return ""; } - bool IsDone() const { return m_done; } - protected: BASE_PARSER(const BASE_PARSER & rvalue); BASE_PARSER & operator=(const BASE_PARSER & rvalue); @@ -60,7 +57,6 @@ class BASE_PARSER size_t m_depth; std::string m_answer; std::string m_tag; - bool m_done; private: virtual void CreateAnswer() = 0; diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp index 2279aae6..06489a42 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp @@ -102,7 +102,6 @@ int SEND_MESSAGE::End(void *, const char *el) m_result = res_ok; } CreateAnswer(); - m_done = true; return 0; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp index 1873b9bb..75be7537 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp @@ -46,7 +46,7 @@ void GET_SERVER_INFO::CreateAnswer() utsn.machine + " " + utsn.nodename; - m_answer = GetOpenTag() + "" + + m_answer = std::string("" + "" + "" + "" + @@ -57,5 +57,5 @@ void GET_SERVER_INFO::CreateAnswer() for (size_t i = 0; i< DIR_NUM; i++) m_answer += ""; - m_answer += GetCloseTag(); + m_answer += ""; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp index cc32b6fc..0607db6f 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp @@ -56,6 +56,16 @@ std::string AOS2String(const A & array, size_t size, const F C::* field, F multi return res; } +template +bool str2res(const std::string& source, RESETABLE& dest, T divisor) +{ + T value = 0; + if (str2x(source, value)) + return false; + dest = value / divisor; + return true; +} + template bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE C::* field, F divisor) { @@ -64,15 +74,13 @@ bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE std::string::size_type pos = 0; while (index < size && (pos = source.find('/', from)) != std::string::npos) { - if (str2x(source.substr(from, pos - from), (array[index].*field).data())) + if (!str2res(source.substr(from, pos - from), array[index].*field, divisor)) return false; - (array[index].*field).data() /= divisor; from = pos + 1; ++index; } - if (str2x(source.substr(from), (array[index].*field).data())) + if (str2res(source.substr(from), array[index].*field, divisor)) return false; - (array[index].*field).data() /= divisor; return true; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp index 67e2c699..2e9d7087 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp @@ -52,9 +52,9 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ std::string answer; if (loginInStart) - answer += ""; + answer += ""; else - answer += ""; + answer += ""; answer += ""; @@ -126,8 +126,8 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ answer += ""; answer += " lastTime) for (size_t j = 0; j < DIR_NUM; j++) answer += " MU" + x2str(j) + "=\"" + x2str(upload[j]) + "\""; @@ -574,8 +574,8 @@ int CHG_USER::ApplyChanges() if (!u->GetProperty().realName.Set(m_ucr.realName.const_data(), &m_currAdmin, m_login, &m_store)) return -1; - if (!m_usr.cash.empty()) + { if (m_cashMustBeAdded) { if (!u->GetProperty().cash.Set(m_usr.cash.const_data() + u->GetProperty().cash, @@ -584,11 +584,13 @@ int CHG_USER::ApplyChanges() &m_store, m_cashMsg)) return -1; - else - if (!u->GetProperty().cash.Set(m_usr.cash.const_data(), &m_currAdmin, m_login, &m_store, m_cashMsg)) - return -1; } - + else + { + if (!u->GetProperty().cash.Set(m_usr.cash.const_data(), &m_currAdmin, m_login, &m_store, m_cashMsg)) + return -1; + } + } if (!m_ucr.tariffName.empty()) { @@ -682,8 +684,6 @@ int DEL_USER::End(void *, const char *el) if (!res) m_users.Del(u->GetLogin(), &m_currAdmin); - m_done = true; - return 0; } return -1; @@ -733,10 +733,7 @@ int CHECK_USER::Start(void *, const char *el, const char **attr) int CHECK_USER::End(void *, const char *el) { if (strcasecmp(el, m_tag.c_str()) == 0) - { - m_done = true; return 0; - } return -1; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp index ca2dd440..73f58145 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp @@ -42,7 +42,7 @@ bool STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) /////////////////////////// pv.param = "Port"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end()) + if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' is not found."; printfd(__FILE__, "%s\n", errorStr.c_str()); @@ -59,7 +59,7 @@ bool STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) pv.param = "BindAddress"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi != s.moduleParams.end()) + if (pvi != s.moduleParams.end() && !pvi->value.empty()) m_bindAddress = pvi->value[0]; return true; diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h index 8902766a..bf4f6195 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h @@ -62,7 +62,7 @@ class STG_CONFIG : public PLUGIN int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index c65a5cba..bec692fa 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -50,7 +50,7 @@ std::vector::const_iterator pvi; pv.param = "PingDelay"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'PingDelay\' not found."; printfd(__FILE__, "Parameter 'PingDelay' not found\n"); @@ -67,18 +67,9 @@ return 0; } //----------------------------------------------------------------------------- PING::PING() - : errorStr(), - pingSettings(), - settings(), - users(NULL), - usersList(), - thread(), - mutex(), + : users(NULL), nonstop(false), isRunning(false), - pinger(), - ChgCurrIPNotifierList(), - ChgIPNotifierList(), onAddUserNotifier(*this), onDelUserNotifier(*this), logger(GetPluginLogger(GetStgLogger(), "ping")) diff --git a/projects/stargazer/plugins/other/ping/ping.h b/projects/stargazer/plugins/other/ping/ping.h index 29e4974e..cfab1e55 100644 --- a/projects/stargazer/plugins/other/ping/ping.h +++ b/projects/stargazer/plugins/other/ping/ping.h @@ -112,7 +112,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning(); const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 8f5ba2a4..0f1c95fc 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -98,7 +98,7 @@ public: int Start(); int Stop(); - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 00114df4..4433dafd 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -73,12 +73,7 @@ return rsc.GetPlugin(); //----------------------------------------------------------------------------- RS::SETTINGS::SETTINGS() : sendPeriod(0), - port(0), - errorStr(), - netRouters(), - userParams(), - password(), - subnetFile() + port(0) { } //----------------------------------------------------------------------------- @@ -91,7 +86,7 @@ netRouters.clear(); /////////////////////////// pv.param = "Port"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@ -107,7 +102,7 @@ port = static_cast(p); /////////////////////////// pv.param = "SendPeriod"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'SendPeriod\' not found."; printfd(__FILE__, "Parameter 'SendPeriod' not found\n"); @@ -123,7 +118,7 @@ if (ParseIntInRange(pvi->value[0], 5, 600, &sendPeriod)) /////////////////////////// pv.param = "UserParams"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'UserParams\' not found."; printfd(__FILE__, "Parameter 'UserParams' not found\n"); @@ -133,7 +128,7 @@ userParams = pvi->value; /////////////////////////// pv.param = "Password"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Password\' not found."; printfd(__FILE__, "Parameter 'Password' not found\n"); @@ -143,7 +138,7 @@ password = pvi->value[0]; /////////////////////////// pv.param = "SubnetFile"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'SubnetFile\' not found."; printfd(__FILE__, "Parameter 'SubnetFile' not found\n"); @@ -301,7 +296,7 @@ if (isRunning) return 0; } //----------------------------------------------------------------------------- -int REMOTE_SCRIPT::Reload() +int REMOTE_SCRIPT::Reload(const MODULE_SETTINGS & /*ms*/) { NRMapParser nrMapParser; diff --git a/projects/stargazer/plugins/other/rscript/rscript.h b/projects/stargazer/plugins/other/rscript/rscript.h index e0412fb0..0de1ea2e 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.h +++ b/projects/stargazer/plugins/other/rscript/rscript.h @@ -185,7 +185,7 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 09cb4636..4586807c 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -24,9 +24,6 @@ namespace { PLUGIN_CREATOR smc; -bool SPrefixLess(const Sensors::value_type & a, - const Sensors::value_type & b); - bool SPrefixLess(const Sensors::value_type & a, const Sensors::value_type & b) { @@ -57,7 +54,7 @@ int p; pv.param = "Port"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Port\' not found."; printfd(__FILE__, "Parameter 'Port' not found\n"); @@ -73,7 +70,7 @@ port = static_cast(p); pv.param = "Password"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Password\' not found."; printfd(__FILE__, "Parameter 'Password' not found\n"); @@ -86,7 +83,7 @@ else pv.param = "Server"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'Server\' not found."; printfd(__FILE__, "Parameter 'Server' not found\n"); @@ -272,7 +269,7 @@ printfd(__FILE__, "SMUX::Stop() - After\n"); return 0; } -int SMUX::Reload() +int SMUX::Reload(const MODULE_SETTINGS & /*ms*/) { if (Stop()) return -1; diff --git a/projects/stargazer/plugins/other/smux/smux.h b/projects/stargazer/plugins/other/smux/smux.h index e379ea7f..3b217eb7 100644 --- a/projects/stargazer/plugins/other/smux/smux.h +++ b/projects/stargazer/plugins/other/smux/smux.h @@ -116,7 +116,7 @@ public: int Start(); int Stop(); - int Reload(); + int Reload(const MODULE_SETTINGS & ms); bool IsRunning() { return running && !stopped; } const std::string & GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index c09ac21f..96add48f 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -110,7 +110,7 @@ PARAM_VALUE pv; pv.param = owner; std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); -if (pvi == moduleParams.end()) +if (pvi == moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'" + owner + "\' not found."; printfd(__FILE__, "%s\n", errorStr.c_str()); @@ -131,7 +131,7 @@ PARAM_VALUE pv; pv.param = group; std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); -if (pvi == moduleParams.end()) +if (pvi == moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'" + group + "\' not found."; printfd(__FILE__, "%s\n", errorStr.c_str()); @@ -169,7 +169,7 @@ PARAM_VALUE pv; pv.param = modeStr; std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); -if (pvi == moduleParams.end()) +if (pvi == moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'" + modeStr + "\' not found."; printfd(__FILE__, "%s\n", errorStr.c_str()); @@ -211,7 +211,7 @@ std::vector::const_iterator pvi; PARAM_VALUE pv; pv.param = "RemoveBak"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { removeBak = true; } @@ -226,7 +226,7 @@ else pv.param = "ReadBak"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { readBak = false; } @@ -241,7 +241,7 @@ else pv.param = "WorkDir"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'WorkDir\' not found."; printfd(__FILE__, "Parameter 'WorkDir' not found\n"); diff --git a/projects/stargazer/plugins/store/firebird/Makefile b/projects/stargazer/plugins/store/firebird/Makefile index a6fb9ccd..cbe8156b 100644 --- a/projects/stargazer/plugins/store/firebird/Makefile +++ b/projects/stargazer/plugins/store/firebird/Makefile @@ -22,9 +22,6 @@ STGLIBS = ibpp \ logger \ crypto -FB_CFLAGS = $(shell fb_config --cflags) -FB_LDFLAGS = $(shell fb_config --libs) - CXXFLAGS += $(FB_CFLAGS) LDFLAGS += $(FB_LDFLAGS) diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.cpp b/projects/stargazer/plugins/store/firebird/firebird_store.cpp index 3c4f32ad..f9a2f78e 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store.cpp @@ -33,9 +33,6 @@ #include #include -#include - -#include namespace { @@ -53,14 +50,10 @@ return frsc.GetPlugin(); //----------------------------------------------------------------------------- FIREBIRD_STORE::FIREBIRD_STORE() : version("firebird_store v.1.4"), - strError(), db_server("localhost"), db_database("/var/stg/stargazer.fdb"), db_user("stg"), db_password("123456"), - settings(), - db(), - mutex(), til(IBPP::ilConcurrency), tlr(IBPP::lrWait), schemaVersion(0), @@ -81,41 +74,41 @@ std::string s; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { - s = i->param; - - std::transform(s.begin(), s.end(), s.begin(), ::tolower); + if (i->value.empty()) + continue; + s = ToLower(i->param); if (s == "server") - db_server = *(i->value.begin()); + db_server = i->value.front(); if (s == "database") - db_database = *(i->value.begin()); + db_database = i->value.front(); if (s == "user") - db_user = *(i->value.begin()); + db_user = i->value.front(); if (s == "password") - db_password = *(i->value.begin()); + db_password = i->value.front(); // Advanced settings block if (s == "isolationLevel") { - if (*(i->value.begin()) == "Concurrency") + if (i->value.front() == "Concurrency") til = IBPP::ilConcurrency; - else if (*(i->value.begin()) == "DirtyRead") + else if (i->value.front() == "DirtyRead") til = IBPP::ilReadDirty; - else if (*(i->value.begin()) == "ReadCommitted") + else if (i->value.front() == "ReadCommitted") til = IBPP::ilReadCommitted; - else if (*(i->value.begin()) == "Consistency") + else if (i->value.front() == "Consistency") til = IBPP::ilConsistency; } if (s == "lockResolution") { - if (*(i->value.begin()) == "Wait") + if (i->value.front() == "Wait") tlr = IBPP::lrWait; - else if (*(i->value.begin()) == "NoWait") + else if (i->value.front() == "NoWait") tlr = IBPP::lrNoWait; } } diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.h b/projects/stargazer/plugins/store/firebird/firebird_store.h index 688f0e88..d9c6af24 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.h +++ b/projects/stargazer/plugins/store/firebird/firebird_store.h @@ -136,4 +136,13 @@ time_t ts2time_t(const IBPP::Timestamp & ts); void time_t2ts(time_t t, IBPP::Timestamp * ts); void ym2date(int year, int month, IBPP::Date * date); +template +inline +T Get(IBPP::Statement st, size_t pos) +{ + T value; + st->Get(pos, value); + return value; +} + #endif //FIREBIRD_STORE_H diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp index f757d055..5e61cabb 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp @@ -275,13 +275,9 @@ try st->Get(3, td->tariffConf.fee); st->Get(4, td->tariffConf.free); st->Get(5, td->tariffConf.passiveCost); - st->Get(6, td->tariffConf.traffType); + td->tariffConf.traffType = TARIFF::IntToTraffType(Get(st, 6)); if (schemaVersion > 0) - { - std::string period; - st->Get(7, period); - td->tariffConf.period = TARIFF::StringToPeriod(period); - } + td->tariffConf.period = TARIFF::StringToPeriod(Get(st, 7)); st->Close(); st->Prepare("select * from tb_tariffs_params where fk_tariff = ?"); st->Set(1, id); diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp index 8c214fbf..fbeacae5 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp @@ -127,9 +127,9 @@ return SaveStat(stat, login); } //----------------------------------------------------------------------------- int FIREBIRD_STORE::SaveStat(const USER_STAT & stat, - const std::string & login, - int year, - int month) const + const std::string & login, + int year, + int month) const { IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr); IBPP::Statement st = IBPP::StatementFactory(db, tr); @@ -147,7 +147,7 @@ try tr->Rollback(); return -1; } - st->Get(1, uid); + int32_t uid = Get(st, 1); st->Close(); st->Prepare("select first 1 pk_stat from tb_stats where fk_user = ? order by stats_date desc"); st->Set(1, uid); @@ -302,7 +302,7 @@ try st->Prepare("insert into tb_users_services (fk_user, fk_service) \ values (?, (select pk_service from tb_services \ where name = ?))"); - for(std::vector::const_iterator it = conf.service.begin(); it != conf.service.end(); ++it) + for(std::vector::const_iterator it = conf.services.begin(); it != conf.services.end(); ++it) { st->Set(1, uid); st->Set(2, *it); @@ -516,7 +516,7 @@ try { std::string name; st->Get(1, name); - conf->service.push_back(name); + conf->services.push_back(name); } // User data diff --git a/projects/stargazer/plugins/store/mysql/Makefile b/projects/stargazer/plugins/store/mysql/Makefile index 25a29798..d676c81a 100644 --- a/projects/stargazer/plugins/store/mysql/Makefile +++ b/projects/stargazer/plugins/store/mysql/Makefile @@ -12,9 +12,6 @@ STGLIBS = common \ crypto \ logger -MYSQL_CFLAGS = $(shell mysql_config --cflags) -MYSQL_LDFLAGS = $(shell mysql_config --libs_r) - CXXFLAGS += $(MYSQL_CFLAGS) LIBS += $(MYSQL_LDFLAGS) diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.cpp b/projects/stargazer/plugins/store/mysql/mysql_store.cpp index 1e4c235d..6b16a99d 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@ -111,28 +111,23 @@ return msc.GetPlugin(); } //----------------------------------------------------------------------------- MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS() - : settings(NULL), - errorStr(), - dbUser(), - dbPass(), - dbName(), - dbHost() + : settings(NULL) { } //----------------------------------------------------------------------------- -int MYSQL_STORE_SETTINGS::ParseParam(const std::vector & moduleParams, - const std::string & name, std::string & result) +int MYSQL_STORE_SETTINGS::ParseParam(const std::vector & moduleParams, + const std::string & name, std::string & result) { PARAM_VALUE pv; pv.param = name; std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); -if (pvi == moduleParams.end()) +if (pvi == moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'" + name + "\' not found."; return -1; } - + result = pvi->value[0]; return 0; @@ -159,10 +154,7 @@ return 0; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- MYSQL_STORE::MYSQL_STORE() - : errorStr(), - version("mysql_store v.0.67"), - storeSettings(), - settings(), + : version("mysql_store v.0.67"), schemaVersion(0), logger(GetPluginLogger(GetStgLogger(), "store_mysql")) { diff --git a/projects/stargazer/plugins/store/postgresql/Makefile b/projects/stargazer/plugins/store/postgresql/Makefile index ef090f17..b59fbbfa 100644 --- a/projects/stargazer/plugins/store/postgresql/Makefile +++ b/projects/stargazer/plugins/store/postgresql/Makefile @@ -19,11 +19,8 @@ STGLIBS = common \ crypto \ logger -PG_CFLAGS = $(shell pg_config --includedir) -PG_LDFLAGS = $(shell pg_config --libdir) - -CXXFLAGS += -I $(PG_CFLAGS) -LDFLAGS += -L $(PG_LDFLAGS) +CXXFLAGS += $(PG_CFLAGS) +LDFLAGS += $(PG_LDFLAGS) LIBS += -lpq diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index 37ff6dbd..a9836911 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -40,14 +40,17 @@ #include "postgresql_store.h" +#include "postgresql_store_utils.h" +#include "postgresql_store.h" + #include "stg/module_settings.h" #include "stg/plugin_creator.h" -#include - #include #include +#include + namespace { PLUGIN_CREATOR pgsc; @@ -64,14 +67,11 @@ return pgsc.GetPlugin(); //----------------------------------------------------------------------------- POSTGRESQL_STORE::POSTGRESQL_STORE() : versionString("postgresql_store v.1.3"), - strError(), server("localhost"), database("stargazer"), user("stg"), password("123456"), clientEncoding("KOI8"), - settings(), - mutex(), version(0), retries(3), connection(NULL), @@ -95,22 +95,34 @@ std::vector::iterator i; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { - std::string param(ToLower(i->param)); - if (param == "server") - server = *(i->value.begin()); - else if (param == "database") - database = *(i->value.begin()); - else if (param == "user") - user = *(i->value.begin()); - else if (param == "password") - password = *(i->value.begin()); - else if (param == "retries") - if (str2x(*(i->value.begin()), retries)) + if (i->value.empty()) + continue; + std::string s = ToLower(i->param); + if (s == "server") + { + server = i->value.front(); + } + if (s == "database") + { + database = i->value.front(); + } + if (s == "user") + { + user = i->value.front(); + } + if (s == "password") + { + password = i->value.front(); + } + if (s == "retries") + { + if (str2x(i->value.front(), retries)) { strError = "Invalid 'retries' value"; printfd(__FILE__, "POSTGRESQL_STORE::ParseSettings(): '%s'\n", strError.c_str()); return -1; } + } } clientEncoding = "KOI8"; diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h new file mode 100644 index 00000000..4ffa6ecf --- /dev/null +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h @@ -0,0 +1,11 @@ +#ifndef POSTGRESQL_UTILS_STORE_H +#define POSTGRESQL_UTILS_STORE_H + +#include + +struct ToLower : public std::unary_function +{ +char operator() (char c) const { return static_cast(std::tolower(c)); } +}; + +#endif diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index 35a259af..fa7402ed 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -68,9 +68,7 @@ SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd) } //----------------------------------------------------------------------------- SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) - : SETTINGS(), - strError(), - modulesPath(rval.modulesPath), + : modulesPath(rval.modulesPath), dirName(rval.dirName), confDir(rval.confDir), scriptsDir(rval.scriptsDir), @@ -101,6 +99,40 @@ SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) { } //----------------------------------------------------------------------------- +SETTINGS_IMPL & SETTINGS_IMPL::operator=(const SETTINGS_IMPL & rhs) +{ + modulesPath = rhs.modulesPath; + dirName = rhs.dirName; + confDir = rhs.confDir; + scriptsDir = rhs.scriptsDir; + rules = rhs.rules; + logFile = rhs.logFile; + pidFile = rhs.pidFile; + monitorDir = rhs.monitorDir; + scriptParams = rhs.scriptParams; + monitoring = rhs.monitoring; + detailStatWritePeriod = rhs.detailStatWritePeriod; + statWritePeriod = rhs.statWritePeriod; + stgExecMsgKey = rhs.stgExecMsgKey; + executersNum = rhs.executersNum; + fullFee = rhs.fullFee; + dayFee = rhs.dayFee; + dayResetTraff = rhs.dayResetTraff; + spreadFee = rhs.spreadFee; + freeMbAllowInet = rhs.freeMbAllowInet; + dayFeeIsLastDay = rhs.dayFeeIsLastDay; + stopOnError = rhs.stopOnError; + writeFreeMbTraffCost = rhs.writeFreeMbTraffCost; + showFeeInCash = rhs.showFeeInCash; + messageTimeout = rhs.messageTimeout; + feeChargeType = rhs.feeChargeType; + reconnectOnTariffChange = rhs.reconnectOnTariffChange; + + modulesSettings = rhs.modulesSettings; + storeModuleSettings = rhs.storeModuleSettings; + return *this; +} +//----------------------------------------------------------------------------- int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector * params) { const DOTCONFDocumentNode * childNode; diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index b01e0fd1..ec8c9cb1 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -61,6 +61,8 @@ public: SETTINGS_IMPL(const std::string &); SETTINGS_IMPL(const SETTINGS_IMPL &); virtual ~SETTINGS_IMPL() {} + SETTINGS_IMPL & operator=(const SETTINGS_IMPL &); + int Reload() { return ReadSettings(); } int ReadSettings(); diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index f7162730..11f4385b 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -557,6 +557,8 @@ if (authorizedBy.empty()) lastDisconnectReason = reason; lastIPForDisconnect = currIP; currIP = 0; // DelUser in traffcounter + if (connected) + Disconnect(false, "not authorized"); return; } } diff --git a/projects/stargazer/users_impl.cpp b/projects/stargazer/users_impl.cpp index 60a36335..9985615f 100644 --- a/projects/stargazer/users_impl.cpp +++ b/projects/stargazer/users_impl.cpp @@ -319,6 +319,7 @@ STG_LOCKER lock(&mutex); if (FindByNameNonLock(login, &iter)) { WriteServLog("Attempt to unauthorize non-existant user '%s'", login.c_str()); + printfd(__FILE__, "Attempt to unauthorize non-existant user '%s'", login.c_str()); return false; } @@ -438,15 +439,7 @@ while (us->nonstop) stgUsleep(100000); } //while (us->nonstop) -user_iter ui = us->users.begin(); -while (ui != us->users.end()) - { - us->DelUserFromIndexes(ui); - ++ui; - } - -std::list::iterator iter; -iter = us->usersToDelete.begin(); +std::list::iterator iter(us->usersToDelete.begin()); while (iter != us->usersToDelete.end()) { iter->delTime -= 2 * userDeleteDelayTime; diff --git a/stglibs/Makefile.in b/stglibs/Makefile.in index b5d1195c..11dfcfb1 100644 --- a/stglibs/Makefile.in +++ b/stglibs/Makefile.in @@ -36,9 +36,11 @@ clean: install: $(PROG) ifeq ($(DEBUG), yes) - install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/lib/stg/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib/stg + install -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/lib/stg/$(PROG) else - install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/stg/$(PROG) + mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/lib/stg + install -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/lib/stg/$(PROG) endif mkdir -m $(DIR_MODE) -p $(PREFIX)/usr/include/stg install -m $(DATA_MODE) -o $(OWNER) $(addprefix include/stg/,$(INCS)) $(PREFIX)/usr/include/stg/ diff --git a/stglibs/common.lib/Makefile b/stglibs/common.lib/Makefile index 0ef14dea..1f662c25 100644 --- a/stglibs/common.lib/Makefile +++ b/stglibs/common.lib/Makefile @@ -11,8 +11,6 @@ SRCS = common.cpp \ INCS = common.h -ifneq ($(OS),linux) -LIBS += -liconv -endif +LIBS += $(LIBICONV) include ../Makefile.in diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index d0ff074c..76a1b421 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -48,6 +48,7 @@ #include #include + #include #include #include @@ -344,20 +345,6 @@ for (size_t i = 0; i < src.length() / 2; i++) } } //--------------------------------------------------------------------------- -std::string Encode12str(const std::string & src) -{ -std::string res; -Encode12str(res, src); -return res; -} -//--------------------------------------------------------------------------- -std::string Decode21str(const std::string & src) -{ -std::string res; -Decode21str(res, src); -return res; -} -//--------------------------------------------------------------------------- void Encode12(char * dst, const char * src, size_t srcLen) { for (size_t i = 0; i <= srcLen; i++) @@ -934,7 +921,7 @@ strncpy(inBuf, source.c_str(), source.length()); inBuf[source.length()] = 0; -#if defined(FREE_BSD) || defined(FREE_BSD5) || defined(WIN32) +#if defined(CONST_ICONV) const char * srcPos = inBuf; #else char * srcPos = inBuf; diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index 90bd639d..623d82d0 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -65,8 +65,8 @@ void Decode21(char * dst, const char * src); void Encode12str(std::string & dst, const std::string & src); void Decode21str(std::string & dst, const std::string & src); -std::string Encode12str(const std::string & src); -std::string Decode21str(const std::string & src); +inline std::string Encode12str(const std::string & src) { std::string dst; Encode12str(dst, src); return dst; } +inline std::string Decode21str(const std::string & src) { std::string dst; Decode21str(dst, src); return dst; } int ParseIPString(const char * str, uint32_t * ips, int maxIP); void KOIToWin(const char * s1, char * s2, int l); diff --git a/stglibs/dotconfpp.lib/dotconfpp.cpp b/stglibs/dotconfpp.lib/dotconfpp.cpp index caf5a590..8f766f01 100644 --- a/stglibs/dotconfpp.lib/dotconfpp.cpp +++ b/stglibs/dotconfpp.lib/dotconfpp.cpp @@ -336,7 +336,7 @@ int DOTCONFDocument::setContent(const char * _fileName) char realpathBuf[PATH_MAX]; if(realpath(_fileName, realpathBuf) == NULL){ - error(0, _fileName, "realpath('%s') failed: %s", _fileName, strerror(errno)); + error(0, _fileName, "%s", strerror(errno)); return -1; } @@ -514,9 +514,9 @@ void DOTCONFDocument::error(int lineNum, const char * fileName, const char * fmt char * buf = (char*)mempool->alloc(len); if(lineNum) - (void) snprintf(buf, len, "DOTCONF++: file '%s', line %d: %s\n", fileName, lineNum, msg); + (void) snprintf(buf, len, "File '%s', line %d: %s\n", fileName, lineNum, msg); else - (void) snprintf(buf, len, "DOTCONF++: file '%s': %s\n", fileName, msg); + (void) snprintf(buf, len, "File '%s': %s\n", fileName, msg); if (errorCallback) { errorCallback(errorCallbackData, buf); diff --git a/stglibs/logger.lib/include/stg/logger.h b/stglibs/logger.lib/include/stg/logger.h index 115d1fb3..e8d625a0 100644 --- a/stglibs/logger.lib/include/stg/logger.h +++ b/stglibs/logger.lib/include/stg/logger.h @@ -44,18 +44,19 @@ private: mutable pthread_mutex_t mutex; }; //----------------------------------------------------------------------------- -class PLUGIN_LOGGER : private STG_LOGGER +class PLUGIN_LOGGER { -friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName); +friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER& logger, const std::string& pluginName); public: - PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs); - void operator()(const char * fmt, ...) const; - void operator()(const std::string & line) const; + PLUGIN_LOGGER(const PLUGIN_LOGGER& rhs) : m_parent(rhs.m_parent), m_pluginName(rhs.m_pluginName) {} + void operator()(const char* fmt, ...) const; + void operator()(const std::string& line) const; private: PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn); - std::string pluginName; + const STG_LOGGER& m_parent; + std::string m_pluginName; }; PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName); diff --git a/stglibs/logger.lib/logger.cpp b/stglibs/logger.lib/logger.cpp index 6289618e..4a455257 100644 --- a/stglibs/logger.lib/logger.cpp +++ b/stglibs/logger.lib/logger.cpp @@ -97,18 +97,10 @@ else } } //----------------------------------------------------------------------------- -PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn) - : STG_LOGGER(), - pluginName(pn) +PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER& logger, const std::string& pn) + : m_parent(logger), + m_pluginName(pn) { - SetLogFileName(logger.fileName); -} -//----------------------------------------------------------------------------- -PLUGIN_LOGGER::PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs) - : STG_LOGGER(), - pluginName(rhs.pluginName) -{ - SetLogFileName(fileName); } //----------------------------------------------------------------------------- void PLUGIN_LOGGER::operator()(const char * fmt, ...) const @@ -120,12 +112,12 @@ va_start(vl, fmt); vsnprintf(buff, sizeof(buff), fmt, vl); va_end(vl); -STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff); +m_parent("[%s] %s", m_pluginName.c_str(), buff); } //----------------------------------------------------------------------------- void PLUGIN_LOGGER::operator()(const std::string & line) const { -STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), line.c_str()); +m_parent("[%s] %s", m_pluginName.c_str(), line.c_str()); } //----------------------------------------------------------------------------- PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName) diff --git a/tests/test_crypto.cpp b/tests/test_crypto.cpp index f95ecdb0..8db8ab72 100644 --- a/tests/test_crypto.cpp +++ b/tests/test_crypto.cpp @@ -431,4 +431,40 @@ namespace tut ensure_equals("DecryptString(EncryptString(longTest)) == longTest", source, std::string(longTest)); } + template<> + template<> + void testobject::test<8>() + { + set_test_name("Check old string encryption"); + + BLOWFISH_CTX ctx; + InitContext("123456", 7, &ctx); + const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39, + 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb, + 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb, + 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb}; + char res[32]; + DecryptString(res, source, 32, &ctx); + + ensure_equals("DecryptString(...) == 'admin'", std::string(res), "admin"); + } + + template<> + template<> + void testobject::test<9>() + { + set_test_name("Check new string encryption"); + + BLOWFISH_CTX ctx; + InitContext("123456", 7, &ctx); + const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + char res[32]; + DecryptString(res, source, 32, &ctx); + + ensure_equals("DecryptString(...) == 'admin'", std::string(res), "admin"); + } + } -- 2.44.2