From 849a1fc933b56cc5cfe62fe9affbad23b557086a Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 21 Nov 2014 19:03:31 +0200 Subject: [PATCH 01/16] Removed some unused stuff from build script. --- projects/libs/build | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/projects/libs/build b/projects/libs/build index 228e1df2..a85ad133 100755 --- a/projects/libs/build +++ b/projects/libs/build @@ -30,9 +30,6 @@ sys=`uname -s` release=`uname -r | cut -b1` BUILD_DIR=`pwd` CONFFILE="../../Makefile.conf" -VAR_DIR="./inst/var/stargazer" -MIN_XMLRPCC_VERSION="1.06.27" -XMLRPC_FEATURES="c++2 abyss-server" if [ "$1" = "debug" ] @@ -55,7 +52,6 @@ if [ "$sys" = "Linux" ] then OS=linux release="" - ETC_DIR="./inst/linux/etc/stargazer" MAKE="make" fi @@ -68,14 +64,12 @@ then 7) OS=bsd7;; *) OS=bsd7;; esac - ETC_DIR="./inst/freebsd/etc/stargazer" MAKE="gmake" fi if [ "$sys" = "Darwin" ] then OS=darwin - ETC_DIR="./inst/freebsd/etc/stargazer" MAKE="gmake" fi @@ -191,7 +185,7 @@ 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 +$CXX $CXXFLAGS $LDFLAGS build_check.c -lfbclient -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_FBCLIENT=no @@ -223,44 +217,24 @@ printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE -printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE -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 -printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE -printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE -printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE -printf "CHECK_PCAP=$CHECK_PCAP\n" >> $CONFFILE -printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE -printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE printf "DEFS=$DEFS\n" >> $CONFFILE -printf "NFQ_LIBS=$NFQ_LIBS\n" >> $CONFFILE printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do printf "$lib " >> $CONFFILE done printf "\n" >> $CONFFILE -printf "PLUGINS=" >> $CONFFILE -for plugin in $PLUGINS -do - printf "$plugin " >> $CONFFILE -done -printf "\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 "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 -printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE -printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE - -mkdir -p modules if [ "$1" != "debug" ] then -- 2.44.2 From 25f2c3fa03f0729e4f06fbabbb380f4e2ec25e7d Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 23 Nov 2014 22:51:20 +0200 Subject: [PATCH 02/16] Fixed crash on problems with loading plugins. --- projects/stargazer/plugin_runner.cpp | 40 +++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/projects/stargazer/plugin_runner.cpp b/projects/stargazer/plugin_runner.cpp index bcf68bee..eaf51058 100644 --- a/projects/stargazer/plugin_runner.cpp +++ b/projects/stargazer/plugin_runner.cpp @@ -86,35 +86,45 @@ PLUGIN & PLUGIN_RUNNER::Load(const MODULE_SETTINGS & ms, { if (pluginFileName.empty()) { - errorStr = "Empty plugin file name."; - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + const std::string msg = "Empty plugin file name."; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); + } + +if (access(pluginFileName.c_str(), R_OK)) + { + const std::string msg = "Plugin file '" + pluginFileName + "' is missing or inaccessible."; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } libHandle = dlopen(pluginFileName.c_str(), RTLD_NOW); if (!libHandle) { - errorStr = "Error loading plugin '" + pluginFileName + "': '" + dlerror() + "'"; - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + std::string msg = "Error loading plugin '" + pluginFileName + "'"; + const char* error = dlerror(); + if (error) + msg = msg + ": '" + error + "'"; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } PLUGIN * (*GetPlugin)(); GetPlugin = (PLUGIN * (*)())dlsym(libHandle, "GetPlugin"); if (!GetPlugin) { - errorStr = "Plugin '" + pluginFileName + "' does not have GetPlugin() function. " + dlerror(); - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + const std::string msg = "Plugin '" + pluginFileName + "' does not have GetPlugin() function. "; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } PLUGIN * plugin = GetPlugin(); if (!plugin) { - errorStr = "Failed to create an instance of plugin '" + pluginFileName + "'."; - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + const std::string msg = "Failed to create an instance of plugin '" + pluginFileName + "'."; + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } plugin->SetSettings(ms); @@ -129,9 +139,9 @@ plugin->SetStgSettings(&settings); if (plugin->ParseSettings()) { - errorStr = "Plugin '" + pluginFileName + "' is unable to parse settings. " + plugin->GetStrError(); - printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", errorStr.c_str()); - throw Error(errorStr); + const std::string msg = "Plugin '" + pluginFileName + "' is unable to parse settings. " + plugin->GetStrError(); + printfd(__FILE__, "PLUGIN_RUNNER::Load() - %s\n", msg.c_str()); + throw Error(msg); } return *plugin; -- 2.44.2 From 5eadb33222ea8b0ab94bc8499a9caf2b02f5eb7b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 7 Dec 2014 13:53:13 +0200 Subject: [PATCH 03/16] Settings object is now allocated on stack, no need to delete it. --- projects/stargazer/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 3db3b266..73786c4e 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -66,7 +66,7 @@ namespace std::set executers; void StartTimer(); -int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings); +int StartScriptExecuter(char * procName, int msgKey, int * msgID); int ForkAndWait(const std::string & confDir); void KillExecuters(); @@ -89,9 +89,9 @@ else } //----------------------------------------------------------------------------- #if defined(LINUX) || defined(DARWIN) -int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings) +int StartScriptExecuter(char * procName, int msgKey, int * msgID) #else -int StartScriptExecuter(char *, int msgKey, int * msgID, SETTINGS_IMPL * settings) +int StartScriptExecuter(char *, int msgKey, int * msgID) #endif { STG_LOGGER & WriteServLog = GetStgLogger(); @@ -132,7 +132,6 @@ switch (pid) return -1; case 0: - delete settings; #if defined(LINUX) || defined(DARWIN) Executer(*msgID, pid, procName); #else @@ -251,7 +250,7 @@ WriteServLog("Stg v. %s", SERVER_VERSION); for (size_t i = 0; i < settings.GetExecutersNum(); i++) { - int ret = StartScriptExecuter(argv[0], settings.GetExecMsgKey(), &msgID, &settings); + int ret = StartScriptExecuter(argv[0], settings.GetExecMsgKey(), &msgID); if (ret < 0) { STG_LOGGER & WriteServLog = GetStgLogger(); -- 2.44.2 From ed64e4a39e36592994411edfaba20e62de5f456d Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 21:27:20 +0200 Subject: [PATCH 04/16] Changed version. --- include/stg/version.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/stg/version.h b/include/stg/version.h index 3698b59d..20538a7f 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.409" #endif -- 2.44.2 From b91e9676639abcb81181f036923c44d4a71c251a Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 21:43:52 +0200 Subject: [PATCH 05/16] Added ToLower/ToUpper. --- stglibs/common.lib/common.cpp | 12 ++++++++++++ stglibs/common.lib/include/stg/common.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 1068cfa1..8c3eb1a5 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -820,6 +820,18 @@ std::string & Trim(std::string & val) return TrimR(TrimL(val)); } //--------------------------------------------------------------------------- +std::string ToLower(std::string value) +{ + std::transform(value.begin(), value.end(), value.begin(), ::tolower); + return value; +} +//--------------------------------------------------------------------------- +std::string ToUpper(std::string value) +{ + std::transform(value.begin(), value.end(), value.begin(), ::toupper); + return value; +} +//--------------------------------------------------------------------------- #ifdef WIN32 static int is_leap(unsigned y) { diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index fe3b3af2..e2eb0d58 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -97,6 +97,9 @@ std::string & TrimL(std::string & val); std::string & TrimR(std::string & val); std::string & Trim(std::string & val); +std::string ToLower(std::string value); +std::string ToUpper(std::string value); + template C Split(const std::string & value, char delim, F conv) { -- 2.44.2 From 5d5457b414d2dd5ee77d2a17427e2c03d30ac176 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 21:44:39 +0200 Subject: [PATCH 06/16] Added missing include. --- include/stg/admin_conf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/stg/admin_conf.h b/include/stg/admin_conf.h index 28ceab66..f88ab0c8 100644 --- a/include/stg/admin_conf.h +++ b/include/stg/admin_conf.h @@ -7,6 +7,8 @@ #ifndef ADMIN_CONF_H #define ADMIN_CONF_H +#include "stg/resetable.h" + #include #include "os_int.h" -- 2.44.2 From 8bda633ffa7e6620b338829d69ab75445ff76605 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 21:51:12 +0200 Subject: [PATCH 07/16] More convenient logger. --- stglibs/logger.lib/include/stg/logger.h | 3 ++ stglibs/logger.lib/logger.cpp | 57 ++++++++++++++----------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/stglibs/logger.lib/include/stg/logger.h b/stglibs/logger.lib/include/stg/logger.h index c55801ac..115d1fb3 100644 --- a/stglibs/logger.lib/include/stg/logger.h +++ b/stglibs/logger.lib/include/stg/logger.h @@ -30,6 +30,7 @@ public: ~STG_LOGGER(); void SetLogFileName(const std::string & fn); void operator()(const char * fmt, ...) const; + void operator()(const std::string & line) const { LogString(line.c_str()); } private: STG_LOGGER(); @@ -37,6 +38,7 @@ private: STG_LOGGER & operator=(const STG_LOGGER & rvalue); const char * LogDate(time_t t) const; + void LogString(const char * str) const; std::string fileName; mutable pthread_mutex_t mutex; @@ -49,6 +51,7 @@ friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::strin public: PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs); void operator()(const char * fmt, ...) const; + void operator()(const std::string & line) const; private: PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn); diff --git a/stglibs/logger.lib/logger.cpp b/stglibs/logger.lib/logger.cpp index 14c09591..6289618e 100644 --- a/stglibs/logger.lib/logger.cpp +++ b/stglibs/logger.lib/logger.cpp @@ -43,10 +43,33 @@ va_start(vl, fmt); vsnprintf(buff, sizeof(buff), fmt, vl); va_end(vl); -FILE * f; +LogString(buff); +} +//----------------------------------------------------------------------------- +const char * STG_LOGGER::LogDate(time_t t) const +{ +static char s[32]; +if (t == 0) + t = time(NULL); + +struct tm * tt = localtime(&t); + +snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d", + tt->tm_year + 1900, + tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1, + tt->tm_mday < 10 ? "0" : "", tt->tm_mday, + tt->tm_hour < 10 ? "0" : "", tt->tm_hour, + tt->tm_min < 10 ? "0" : "", tt->tm_min, + tt->tm_sec < 10 ? "0" : "", tt->tm_sec); + +return s; +} +//----------------------------------------------------------------------------- +void STG_LOGGER::LogString(const char * str) const +{ if (!fileName.empty()) { - f = fopen(fileName.c_str(), "at"); + FILE * f = fopen(fileName.c_str(), "at"); if (f) { #ifdef STG_TIME @@ -55,44 +78,25 @@ if (!fileName.empty()) fprintf(f, "%s", LogDate(time(NULL))); #endif fprintf(f, " -- "); - fprintf(f, "%s", buff); + fprintf(f, "%s", str); fprintf(f, "\n"); fclose(f); } else { openlog("stg", LOG_NDELAY, LOG_USER); - syslog(LOG_CRIT, "%s", buff); + syslog(LOG_CRIT, "%s", str); closelog(); } } else { openlog("stg", LOG_NDELAY, LOG_USER); - syslog(LOG_CRIT, "%s", buff); + syslog(LOG_CRIT, "%s", str); closelog(); } } //----------------------------------------------------------------------------- -const char * STG_LOGGER::LogDate(time_t t) const -{ -static char s[32]; -if (t == 0) - t = time(NULL); - -struct tm * tt = localtime(&t); - -snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d", - tt->tm_year + 1900, - tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1, - tt->tm_mday < 10 ? "0" : "", tt->tm_mday, - tt->tm_hour < 10 ? "0" : "", tt->tm_hour, - tt->tm_min < 10 ? "0" : "", tt->tm_min, - tt->tm_sec < 10 ? "0" : "", tt->tm_sec); - -return s; -} -//----------------------------------------------------------------------------- PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn) : STG_LOGGER(), pluginName(pn) @@ -119,6 +123,11 @@ va_end(vl); STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff); } //----------------------------------------------------------------------------- +void PLUGIN_LOGGER::operator()(const std::string & line) const +{ +STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), line.c_str()); +} +//----------------------------------------------------------------------------- PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName) { return PLUGIN_LOGGER(logger, pluginName); -- 2.44.2 From 1cb8c64f1717769b51cbf4c737d95030c920ac99 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 22:05:30 +0200 Subject: [PATCH 08/16] Added missing include. --- stglibs/common.lib/common.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 8c3eb1a5..d91c1795 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -47,6 +47,8 @@ #include +#include + #include #include #include -- 2.44.2 From 57de0355b9a289dc3a2f219f0ea32145bdd7e69b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 22:06:16 +0200 Subject: [PATCH 09/16] Use common case-conversion functions. --- .../stargazer/plugins/store/firebird/firebird_store.cpp | 7 +------ .../plugins/store/postgresql/postgresql_store.cpp | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.cpp b/projects/stargazer/plugins/store/firebird/firebird_store.cpp index 3c4f32ad..81160114 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 { @@ -81,9 +78,7 @@ 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); + s = ToLower(i->param); if (s == "server") db_server = *(i->value.begin()); diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index 3a1d7272..80431c0d 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -40,7 +40,6 @@ #include #include -#include #include @@ -97,8 +96,7 @@ 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()); + s = ToLower(i->param); if (s == "server") { server = *(i->value.begin()); -- 2.44.2 From 554a2f77f485f55c8c62ae9d854a2198b2c0f98f Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 22:07:04 +0200 Subject: [PATCH 10/16] Added handy encoding functions. --- stglibs/common.lib/include/stg/common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index e2eb0d58..ddc69def 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -66,6 +66,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); +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); -- 2.44.2 From e982ee10a3a88a2cb6f623a3f12b1b428df9879c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 22:08:00 +0200 Subject: [PATCH 11/16] Fixed compilation issues. --- projects/stargazer/plugins/Makefile.in | 4 ++-- projects/stargazer/plugins/configuration/sgconfig/Makefile | 1 - .../stargazer/plugins/configuration/sgconfig/configproto.cpp | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/projects/stargazer/plugins/Makefile.in b/projects/stargazer/plugins/Makefile.in index dd1e124a..efb5d984 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 diff --git a/projects/stargazer/plugins/configuration/sgconfig/Makefile b/projects/stargazer/plugins/configuration/sgconfig/Makefile index 40a5c534..2e5c8c60 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/Makefile +++ b/projects/stargazer/plugins/configuration/sgconfig/Makefile @@ -15,7 +15,6 @@ SRCS = ./stgconfig.cpp \ ./parser_users.cpp \ ./parser_message.cpp \ ./parser_auth_by.cpp \ - ./parser_user_info.cpp \ ./parser_server_info.cpp LIBS += -lexpat \ diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index d1d25026..567c537a 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -19,6 +19,7 @@ * Author : Maxim Mamontov */ +#include "configproto.h" #include "conn.h" @@ -27,7 +28,6 @@ #include "parser_tariffs.h" #include "parser_users.h" #include "parser_message.h" -#include "parser_user_info.h" #include "parser_auth_by.h" #include "stg/common.h" @@ -230,8 +230,6 @@ void CONFIGPROTO::RegisterParsers() SP::SEND_MESSAGE::FACTORY::Register(m_registry, *m_users); SP::AUTH_BY::FACTORY::Register(m_registry, *m_users); - - SP::USER_INFO::FACTORY::Register(m_registry, *m_users); } int CONFIGPROTO::MaxFD() const -- 2.44.2 From e3e39cff57129ed71935bd0016e16bc134742872 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Jan 2015 22:13:18 +0200 Subject: [PATCH 12/16] Some fixes in USER_IMPL. --- projects/stargazer/user_impl.cpp | 9 +++++++-- projects/stargazer/user_impl.h | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index e832c669..36930576 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -77,7 +77,8 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, const STORE * st, const TARIFFS * t, const ADMIN * a, - const USERS * u) + const USERS * u, + const SERVICES & svcs) : users(u), property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), @@ -93,6 +94,7 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, store(st), tariffs(t), tariff(NULL), + m_services(svcs), settings(s), authorizedModificationTime(0), deleted(false), @@ -145,7 +147,8 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, const STORE * st, const TARIFFS * t, const ADMIN * a, - const USERS * u) + const USERS * u, + const SERVICES & svcs) : users(u), property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), @@ -161,6 +164,7 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, store(st), tariffs(t), tariff(NULL), + m_services(svcs), settings(s), authorizedModificationTime(0), deleted(false), @@ -249,6 +253,7 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u) store(u.store), tariffs(u.tariffs), tariff(u.tariff), + m_services(u.m_services), traffStat(u.traffStat), traffStatSaved(u.traffStatSaved), settings(u.settings), diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index 30b6aa78..77887514 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -125,13 +125,15 @@ public: const STORE * store, const TARIFFS * tariffs, const ADMIN * sysAdmin, - const USERS * u); + const USERS * u, + const SERVICES & svcs); #else USER_IMPL(const SETTINGS_IMPL * settings, const STORE * store, const TARIFFS * tariffs, const ADMIN * sysAdmin, - const USERS * u); + const USERS * u, + const SERVICES & svcs); #endif USER_IMPL(const USER_IMPL & u); virtual ~USER_IMPL(); @@ -269,6 +271,8 @@ private: const TARIFFS * tariffs; const TARIFF * tariff; + const SERVICES & m_services; + TRAFF_STAT traffStat; std::pair traffStatSaved; -- 2.44.2 From 90f4f13ef5d9a90a06e1ba9243f18c3b98977655 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 18 Jan 2015 19:34:21 +0200 Subject: [PATCH 13/16] Removed unused functions. --- stglibs/srvconf.lib/include/stg/netunit.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stglibs/srvconf.lib/include/stg/netunit.h b/stglibs/srvconf.lib/include/stg/netunit.h index e288df86..cfc120f8 100644 --- a/stglibs/srvconf.lib/include/stg/netunit.h +++ b/stglibs/srvconf.lib/include/stg/netunit.h @@ -107,10 +107,6 @@ private: int TxData(char * data); int RxDataAnswer(); - void Encrypt(char * d, const char * s, BLOWFISH_CTX *ctx); - void EnDecryptInit(const char * passwd, int passwdLen, BLOWFISH_CTX *ctx); - void Decrypt(char * d, const char * s, BLOWFISH_CTX *ctx); - std::string server; short unsigned port; std::string login; -- 2.44.2 From 45043ba8ae9d21f69209fcb74f1715d97e4fc409 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 18 Jan 2015 19:40:38 +0200 Subject: [PATCH 14/16] Removed some unused stuff from netunit.cpp. --- stglibs/srvconf.lib/netunit.cpp | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index 596f766f..936ebc60 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -58,31 +58,6 @@ NETTRANSACT::NETTRANSACT() dataRxCallBack(NULL) { } -//----------------------------------------------------------------------------- -void NETTRANSACT::EnDecryptInit(const char * passwd, int, BLOWFISH_CTX *ctx) -{ -unsigned char * keyL = NULL; - -keyL = new unsigned char[PASSWD_LEN]; - -memset(keyL, 0, PASSWD_LEN); - -strncpy((char *)keyL, passwd, PASSWD_LEN); - -Blowfish_Init(ctx, keyL, PASSWD_LEN); - -delete[] keyL; -} -//----------------------------------------------------------------------------- -void NETTRANSACT::Encrypt(char * d, const char * s, BLOWFISH_CTX *ctx) -{ -EncodeString(d, s, ctx); -} -//--------------------------------------------------------------------------- -void NETTRANSACT::Decrypt(char * d, const char * s, BLOWFISH_CTX *ctx) -{ -DecodeString(d, s, ctx); -} //--------------------------------------------------------------------------- int NETTRANSACT::Connect() { @@ -370,12 +345,12 @@ if (strlen(data)%ENC_MSG_LEN) l++; BLOWFISH_CTX ctx; -InitContext(password.c_str(), PASSWD_LEN, &ctx); +InitContext(passwd, PASSWD_LEN, &ctx); for (int j = 0; j < l; j++) { strncpy(buff, &data[j*ENC_MSG_LEN], ENC_MSG_LEN); - Encrypt(buffS, buff, &ctx); + EncryptBlock(buffS, buff, &ctx); send(outerSocket, buffS, ENC_MSG_LEN, 0); } @@ -390,7 +365,7 @@ char bufferS[ENC_MSG_LEN]; char buffer[ENC_MSG_LEN + 1]; BLOWFISH_CTX ctx; -EnDecryptInit(password.c_str(), PASSWD_LEN, &ctx); +InitContext(password.c_str(), PASSWD_LEN, &ctx); while (1) { @@ -405,7 +380,7 @@ while (1) if (n == ENC_MSG_LEN) { n = 0; - Decrypt(buffer, bufferS, &ctx); + DecryptBlock(buffer, bufferS, &ctx); buffer[ENC_MSG_LEN] = 0; answerList.push_back(buffer); -- 2.44.2 From e2a55a9e10716abc07c3d160bf1539423c216efd Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 18 Jan 2015 20:01:15 +0200 Subject: [PATCH 15/16] Fixed compilation of srvconf lib. --- stglibs/srvconf.lib/include/stg/netunit.h | 1 - stglibs/srvconf.lib/netunit.cpp | 44 +++-------------------- 2 files changed, 4 insertions(+), 41 deletions(-) diff --git a/stglibs/srvconf.lib/include/stg/netunit.h b/stglibs/srvconf.lib/include/stg/netunit.h index cfc120f8..664eee63 100644 --- a/stglibs/srvconf.lib/include/stg/netunit.h +++ b/stglibs/srvconf.lib/include/stg/netunit.h @@ -104,7 +104,6 @@ private: int RxLoginSAnswer(); int TxData(const char * text); - int TxData(char * data); int RxDataAnswer(); std::string server; diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index 936ebc60..df0af7f2 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -262,13 +262,11 @@ else int NETTRANSACT::TxLoginS() { char loginZ[ADM_LOGIN_LEN]; -char ct[ENC_MSG_LEN]; -int ret; memset(loginZ, 0, ADM_LOGIN_LEN); BLOWFISH_CTX ctx; InitContext(password.c_str(), PASSWD_LEN, &ctx); -EncryptString(loginZ, login.c_str(), std::min(login.length() + 1, ADM_LOGIN_LEN), &ctx); +EncryptString(loginZ, login.c_str(), std::min(login.length() + 1, ADM_LOGIN_LEN), &ctx); if (send(outerSocket, loginZ, ADM_LOGIN_LEN, 0) <= 0) { errorMsg = SEND_LOGIN_ERROR; @@ -310,18 +308,11 @@ else //--------------------------------------------------------------------------- int NETTRANSACT::TxData(const char * text) { -char textZ[ENC_MSG_LEN]; -char ct[ENC_MSG_LEN]; -int ret; -int j; - -int n = strlen(text) / ENC_MSG_LEN; -int r = strlen(text) % ENC_MSG_LEN; - BLOWFISH_CTX ctx; InitContext(password.c_str(), PASSWD_LEN, &ctx); -char buffer[text.length() + 9]; -EncryptString(buffer, text.c_str(), text.length() + 1, &ctx); +size_t length = strlen(text); +char buffer[length + 9]; +EncryptString(buffer, text, length, &ctx); if (send(outerSocket, buffer, sizeof(buffer), 0) <= 0) { errorMsg = SEND_DATA_ERROR; @@ -330,33 +321,6 @@ if (send(outerSocket, buffer, sizeof(buffer), 0) <= 0) return st_ok; } //--------------------------------------------------------------------------- -int NETTRANSACT::TxData(char * data) -{ -char buff[ENC_MSG_LEN]; -char buffS[ENC_MSG_LEN]; -char passwd[ADM_PASSWD_LEN]; - -memset(passwd, 0, ADM_PASSWD_LEN); -strncpy(passwd, password.c_str(), ADM_PASSWD_LEN); -memset(buff, 0, ENC_MSG_LEN); - -int l = strlen(data)/ENC_MSG_LEN; -if (strlen(data)%ENC_MSG_LEN) - l++; - -BLOWFISH_CTX ctx; -InitContext(passwd, PASSWD_LEN, &ctx); - -for (int j = 0; j < l; j++) - { - strncpy(buff, &data[j*ENC_MSG_LEN], ENC_MSG_LEN); - EncryptBlock(buffS, buff, &ctx); - send(outerSocket, buffS, ENC_MSG_LEN, 0); - } - -return 0; -} -//--------------------------------------------------------------------------- int NETTRANSACT::RxDataAnswer() { int n = 0; -- 2.44.2 From 38ae57da63d8faa84bc639b15774567c49fedf40 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 18 Jan 2015 20:01:57 +0200 Subject: [PATCH 16/16] Fixed compilation of sgconf. --- projects/sgconf/common_sg.cpp | 26 ++++---- projects/sgconf/main.cpp | 118 +++++++++++++++++----------------- 2 files changed, 71 insertions(+), 73 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index bf2ac622..27f0b9f9 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -335,13 +335,13 @@ if (ud->login == "") return; } -if (!req->cash.res_empty()) +if (!req->cash.empty()) cout << "cash=" << ud->cash << endl; -if (!req->credit.res_empty()) +if (!req->credit.empty()) cout << "credit=" << ud->credit << endl; -if (!req->creditExpire.res_empty()) +if (!req->creditExpire.empty()) { char buf[32]; struct tm brokenTime; @@ -361,32 +361,32 @@ if (!req->creditExpire.res_empty()) cout << "creditExpire=" << buf << endl; } -if (!req->down.res_empty()) +if (!req->down.empty()) cout << "down=" << ud->down << endl; -if (!req->passive.res_empty()) +if (!req->passive.empty()) cout << "passive=" << ud->passive << endl; -if (!req->disableDetailStat.res_empty()) +if (!req->disableDetailStat.empty()) cout << "disableDetailStat=" << ud->disableDetailStat << endl; -if (!req->alwaysOnline.res_empty()) +if (!req->alwaysOnline.empty()) cout << "alwaysOnline=" << ud->alwaysOnline << endl; -if (!req->prepaidTraff.res_empty()) +if (!req->prepaidTraff.empty()) cout << "prepaidTraff=" << ud->prepaidTraff << endl; for (int i = 0; i < DIR_NUM; i++) { - if (!req->u[i].res_empty()) + if (!req->u[i].empty()) cout << "u" << i << "=" << ud->stat.mu[i] << endl; - if (!req->d[i].res_empty()) + if (!req->d[i].empty()) cout << "d" << i << "=" << ud->stat.md[i] << endl; } for (int i = 0; i < USERDATA_NUM; i++) { - if (!req->ud[i].res_empty()) + if (!req->ud[i].empty()) { string str; ConvertFromKOI8(ud->userData[i], &str); @@ -408,7 +408,7 @@ StringReqParams strReqParams[] = }; for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++) { - if (!strReqParams[i].reqParam.res_empty()) + if (!strReqParams[i].reqParam.empty()) { string str; ConvertFromKOI8(*strReqParams[i].value, &str); @@ -425,8 +425,6 @@ abcbd = (AuthByCbData *)d; bool * result = abcbd->result; -REQUEST * req = (REQUEST *)abcbd->data; - for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) cout << *it << "\n"; cout << endl; diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 2c02be27..18e36835 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -401,10 +401,10 @@ memset(str, 0, strLen); r[0] = 0; -if (!req->usrMsg.res_empty()) +if (!req->usrMsg.empty()) { string msg; - Encode12str(msg, req->usrMsg); + Encode12str(msg, req->usrMsg.data()); sprintf(str, "", req->login.const_data().c_str(), msg.c_str()); //sprintf(str, "\n", req->login, msg); strcat(r, str); @@ -430,72 +430,72 @@ if (req->createUser) strcat(r, "\n"); sprintf(str, "\n", req->login.const_data().c_str()); strcat(r, str); -if (!req->credit.res_empty()) +if (!req->credit.empty()) { sprintf(str, "\n", req->credit.const_data()); strcat(r, str); } -if (!req->creditExpire.res_empty()) +if (!req->creditExpire.empty()) { sprintf(str, "\n", req->creditExpire.const_data()); strcat(r, str); } -if (!req->prepaidTraff.res_empty()) +if (!req->prepaidTraff.empty()) { sprintf(str, "\n", req->prepaidTraff.const_data()); strcat(r, str); } -if (!req->cash.res_empty()) +if (!req->cash.empty()) { string msg; - Encode12str(msg, req->message); + Encode12str(msg, req->message.data()); sprintf(str, "\n", req->cash.const_data(), msg.c_str()); strcat(r, str); } -if (!req->setCash.res_empty()) +if (!req->setCash.empty()) { string msg; - Encode12str(msg, req->message); + Encode12str(msg, req->message.data()); sprintf(str, "\n", req->setCash.const_data(), msg.c_str()); strcat(r, str); } -if (!req->usrPasswd.res_empty()) +if (!req->usrPasswd.empty()) { sprintf(str, "\n", req->usrPasswd.const_data().c_str()); strcat(r, str); } -if (!req->down.res_empty()) +if (!req->down.empty()) { sprintf(str, "\n", req->down.const_data()); strcat(r, str); } -if (!req->passive.res_empty()) +if (!req->passive.empty()) { sprintf(str, "\n", req->passive.const_data()); strcat(r, str); } -if (!req->disableDetailStat.res_empty()) +if (!req->disableDetailStat.empty()) { sprintf(str, "\n", req->disableDetailStat.const_data()); strcat(r, str); } -if (!req->alwaysOnline.res_empty()) +if (!req->alwaysOnline.empty()) { sprintf(str, "\n", req->alwaysOnline.const_data()); strcat(r, str); } // IP-address of user -if (!req->ips.res_empty()) +if (!req->ips.empty()) { sprintf(str, "\n", req->ips.const_data().c_str()); strcat(r, str); @@ -505,7 +505,7 @@ int uPresent = false; int dPresent = false; for (int i = 0; i < DIR_NUM; i++) { - if (!req->u[i].res_empty()) + if (!req->u[i].empty()) { if (!uPresent && !dPresent) { @@ -520,7 +520,7 @@ for (int i = 0; i < DIR_NUM; i++) sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str()); strcat(r, str); } - if (!req->d[i].res_empty()) + if (!req->d[i].empty()) { if (!uPresent && !dPresent) { @@ -542,7 +542,7 @@ if (uPresent || dPresent) //printf("%s\n", r); -if (!req->tariff.res_empty()) +if (!req->tariff.empty()) { switch (req->chgTariff) { @@ -562,60 +562,60 @@ if (!req->tariff.res_empty()) } -if (!req->note.res_empty()) +if (!req->note.empty()) { string note; - Encode12str(note, req->note); + Encode12str(note, req->note.data()); sprintf(str, "", note.c_str()); strcat(r, str); } -if (!req->name.res_empty()) +if (!req->name.empty()) { string name; - Encode12str(name, req->name); + Encode12str(name, req->name.data()); sprintf(str, "", name.c_str()); strcat(r, str); } -if (!req->address.res_empty()) +if (!req->address.empty()) { string address; - Encode12str(address, req->address); + Encode12str(address, req->address.data()); sprintf(str, "
", address.c_str()); strcat(r, str); } -if (!req->email.res_empty()) +if (!req->email.empty()) { string email; - Encode12str(email, req->email); + Encode12str(email, req->email.data()); sprintf(str, "", email.c_str()); strcat(r, str); } -if (!req->phone.res_empty()) +if (!req->phone.empty()) { string phone; - Encode12str(phone, req->phone); + Encode12str(phone, req->phone.data()); sprintf(str, "", phone.c_str()); strcat(r, str); } -if (!req->group.res_empty()) +if (!req->group.empty()) { string group; - Encode12str(group, req->group); + Encode12str(group, req->group.data()); sprintf(str, "", group.c_str()); strcat(r, str); } for (int i = 0; i < USERDATA_NUM; i++) { - if (!req->ud[i].res_empty()) + if (!req->ud[i].empty()) { string ud; - Encode12str(ud, req->ud[i]); + Encode12str(ud, req->ud[i].data()); sprintf(str, "", i, ud.c_str()); strcat(r, str); } @@ -629,27 +629,27 @@ int CheckParameters(REQUEST * req) int u = false; int d = false; int ud = false; -int a = !req->admLogin.res_empty() - && !req->admPasswd.res_empty() - && !req->server.res_empty() - && !req->port.res_empty() - && !req->login.res_empty(); - -int b = !req->cash.res_empty() - || !req->setCash.res_empty() - || !req->credit.res_empty() - || !req->prepaidTraff.res_empty() - || !req->tariff.res_empty() - || !req->usrMsg.res_empty() - || !req->usrPasswd.res_empty() - - || !req->note.res_empty() - || !req->name.res_empty() - || !req->address.res_empty() - || !req->email.res_empty() - || !req->phone.res_empty() - || !req->group.res_empty() - || !req->ips.res_empty() // IP-address of user +int a = !req->admLogin.empty() + && !req->admPasswd.empty() + && !req->server.empty() + && !req->port.empty() + && !req->login.empty(); + +int b = !req->cash.empty() + || !req->setCash.empty() + || !req->credit.empty() + || !req->prepaidTraff.empty() + || !req->tariff.empty() + || !req->usrMsg.empty() + || !req->usrPasswd.empty() + + || !req->note.empty() + || !req->name.empty() + || !req->address.empty() + || !req->email.empty() + || !req->phone.empty() + || !req->group.empty() + || !req->ips.empty() // IP-address of user || !req->createUser || !req->deleteUser; @@ -657,7 +657,7 @@ int b = !req->cash.res_empty() for (int i = 0; i < DIR_NUM; i++) { - if (req->u[i].res_empty()) + if (req->u[i].empty()) { u = true; break; @@ -666,7 +666,7 @@ for (int i = 0; i < DIR_NUM; i++) for (int i = 0; i < DIR_NUM; i++) { - if (req->d[i].res_empty()) + if (req->d[i].empty()) { d = true; break; @@ -675,7 +675,7 @@ for (int i = 0; i < DIR_NUM; i++) for (int i = 0; i < DIR_NUM; i++) { - if (req->ud[i].res_empty()) + if (req->ud[i].empty()) { ud = true; break; @@ -879,9 +879,9 @@ if (missedOptionArg || !CheckParametersGet(&req)) } if (req.authBy) - return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req); + return ProcessAuthBy(req.server.data(), req.port.data(), req.admLogin.data(), req.admPasswd.data(), req.login.data(), &req); else - return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req); + return ProcessGetUser(req.server.data(), req.port.data(), req.admLogin.data(), req.admPasswd.data(), req.login.data(), &req); } //----------------------------------------------------------------------------- int mainSet(int argc, char **argv) @@ -1103,7 +1103,7 @@ char rstr[rLen]; memset(rstr, 0, rLen); CreateRequestSet(&req, rstr); -return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr, NULL, isMessage); +return ProcessSetUser(req.server.data(), req.port.data(), req.admLogin.data(), req.admPasswd.data(), rstr, NULL, isMessage); } //----------------------------------------------------------------------------- int main(int argc, char **argv) -- 2.44.2