From: Maxim Mamontov Date: Fri, 23 Aug 2013 18:59:58 +0000 (+0300) Subject: Merge branch 'naffanya-dev' X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/e9cb0683c0b33d8458c1d9b2558bbeb5d101e680?hp=3b72948400d02d863025d3cde828b9dd22b8af8e Merge branch 'naffanya-dev' --- diff --git a/doc/xmlrpc/API-user.xml b/doc/xmlrpc/API-user.xml index fac4f2be..82f8e7ee 100644 --- a/doc/xmlrpc/API-user.xml +++ b/doc/xmlrpc/API-user.xml @@ -243,6 +243,7 @@ stargazer.set_user_cash, stargazer.chg_user_tariff stargazer.get_online_ips + stargazer.get_user_auth_by @@ -481,6 +482,7 @@ stargazer.set_user_cash, stargazer.chg_user_tariff stargazer.get_online_ips + stargazer.get_user_auth_by @@ -534,6 +536,7 @@ stargazer.set_user_cash, stargazer.chg_user_tariff stargazer.get_online_ips + stargazer.get_user_auth_by @@ -732,6 +735,7 @@ stargazer.set_user_cash, stargazer.chg_user_tariff stargazer.get_online_ips + stargazer.get_user_auth_by @@ -785,6 +789,7 @@ stargazer.set_user_cash, stargazer.chg_user_tariff stargazer.get_online_ips + stargazer.get_user_auth_by @@ -852,6 +857,7 @@ stargazer.set_user_cash, stargazer.chg_user_tariff stargazer.get_online_ips + stargazer.get_user_auth_by @@ -919,6 +925,7 @@ stargazer.add_user_cash, stargazer.chg_user_tariff stargazer.get_online_ips + stargazer.get_user_auth_by @@ -993,6 +1000,7 @@ stargazer.add_user_cash, stargazer.set_user_cash stargazer.get_online_ips + stargazer.get_user_auth_by @@ -1060,6 +1068,75 @@ stargazer.add_user_cash, stargazer.set_user_cash stargazer.chg_user_tariff + stargazer.get_user_auth_by + + + + + + stargazer.get_user_auth_by + + + stargazer.get_user_auth_by + Получение списка авторизаторов которыми авторизован пользователь + + + + + stargazer.get_user_auth_by + string cookie + string login + + + + + Description + Метод stargazer.get_user_auth_by позволяет получить список авторизаторов которыми в данный момент авторизован пользователь. + + + string cookie + + Авторизационный cookie. Для авторизации в системе используется метод stargazer.login + + + + string login + + Логин пользователя + + + + + Return Value + Возвращает структуру: + + + bool result + + Результат операции. true - успешно, false - неудача (неправильный или устаревший cookie). + + + + array of strings auths + + Список авторизаторов которыми авторизован пользователь. + + + + + + + See also + + stargazer.get_users, + stargazer.get_user, + stargazer.add_user, + stargazer.chg_user, + stargazer.del_user, + stargazer.add_user_cash, + stargazer.set_user_cash + stargazer.chg_user_tariff + stargazer.get_online_ips diff --git a/include/stg/os_int.h b/include/stg/os_int.h index cc017b84..00ab3fad 100644 --- a/include/stg/os_int.h +++ b/include/stg/os_int.h @@ -31,7 +31,7 @@ #include #endif -#ifdef FREE_BSD5 +#if defined(FREE_BSD5) || defined(DARWIN) #include #endif diff --git a/include/stg/user.h b/include/stg/user.h index 365c71ef..a8f61105 100644 --- a/include/stg/user.h +++ b/include/stg/user.h @@ -21,14 +21,16 @@ #ifndef USER_H #define USER_H -#include -#include - -#include "os_int.h" #include "notifer.h" #include "message.h" #include "tariff.h" #include "user_traff.h" +#include "os_int.h" + +#include +#include + +#include class USER_PROPERTIES; class AUTH; @@ -71,12 +73,12 @@ public: virtual bool GetConnected() const = 0; virtual time_t GetConnectedModificationTime() const = 0; + virtual const std::string & GetLastDisconnectReason() const = 0; virtual int GetAuthorized() const = 0; - /*virtual int Authorize(uint32_t ip, - uint32_t enabledDirs, - const AUTH * auth) = 0; - virtual void Unauthorize(const AUTH * auth) = 0;*/ + virtual time_t GetAuthorizedModificationTime() const = 0; + virtual bool IsAuthorizedBy(const AUTH * auth) const = 0; + virtual std::vector GetAuthorizers() const = 0; virtual int AddMessage(STG_MSG * msg) = 0; diff --git a/include/stg/user_ips.h b/include/stg/user_ips.h index e68190c5..e55f99fa 100644 --- a/include/stg/user_ips.h +++ b/include/stg/user_ips.h @@ -70,7 +70,8 @@ public: std::string GetIpStr() const; bool IsIPInIPS(uint32_t ip) const; bool OnlyOneIP() const; - int Count() const; + bool IsAnyIP() const; + size_t Count() const; void Add(const IP_MASK &im); void Erase(); @@ -129,9 +130,9 @@ return s.str(); } //----------------------------------------------------------------------------- inline -int USER_IPS::Count() const +size_t USER_IPS::Count() const { -return static_cast(ips.size()); +return ips.size(); } //----------------------------------------------------------------------------- inline @@ -172,6 +173,12 @@ return false; } //----------------------------------------------------------------------------- inline +bool USER_IPS::IsAnyIP() const +{ + return !ips.empty() && ips.front().ip == 0; +} +//----------------------------------------------------------------------------- +inline void USER_IPS::Add(const IP_MASK &im) { ips.push_back(im); diff --git a/include/stg/users.h b/include/stg/users.h index ed9af901..a1d5d295 100644 --- a/include/stg/users.h +++ b/include/stg/users.h @@ -32,6 +32,7 @@ class USERS { public: virtual ~USERS() {} virtual int FindByName(const std::string & login, USER_PTR * user) = 0; + virtual int FindByName(const std::string & login, CONST_USER_PTR * user) const = 0; virtual bool TariffInUse(const std::string & tariffName) const = 0; @@ -53,6 +54,7 @@ public: virtual int FindByIPIdx(uint32_t ip, USER_PTR * user) const = 0; virtual bool IsIPInIndex(uint32_t ip) const = 0; + virtual bool IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const = 0; virtual int OpenSearch() = 0; virtual int SearchNext(int handle, USER_PTR * u) = 0; diff --git a/projects/rlm_stg/build b/projects/rlm_stg/build index 91fe7d9d..6459cdb9 100755 --- a/projects/rlm_stg/build +++ b/projects/rlm_stg/build @@ -53,15 +53,15 @@ fi if [ "$OS" = "unknown" ] then - echo "#############################################################################" - echo "# Sorry, but rlm_stg currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #" - echo "#############################################################################" + printf "#############################################################################\n" + printf "# Sorry, but rlm_stg currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "#############################################################################\n" exit 1 fi -echo "#############################################################################" -echo " Building rlm_stg for $sys $release" -echo "#############################################################################" +printf "#############################################################################\n" +printf " Building rlm_stg for $sys $release\n" +printf "#############################################################################\n" STG_LIBS="crypto.lib common.lib" @@ -95,32 +95,32 @@ then CXX=g++ fi -echo -n "Checking CC... " +printf "Checking CC... " $CC --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CC not found" + printf "FAIL!\n" + printf "$CC not found\n" exit; fi -echo "found" -echo -n "Checking CXX... " +printf "found\n" +printf "Checking CXX... " $CXX --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CXX not found" + printf "FAIL!\n" + printf "$CXX not found\n" exit; fi -echo "found" +printf "found\n" -echo -n "Checking endianess... " -echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c +printf "Checking endianess... " +printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "Endianess checking failed" + printf "FAIL!\n" + printf "Endianess checking failed\n" exit; else ./fake @@ -129,39 +129,39 @@ else ARCH=le CXXFLAGS="$CXXFLAGS -DARCH_LE" CFLAGS="$CFLAGS -DARCH_LE" - echo "Little Endian" + printf "Little Endian\n" else ARCH=be CXXFLAGS="$CXXFLAGS -DARCH_BE" CFLAGS="$CFLAGS -DARCH_BE" - echo "Big Endian" + printf "Big Endian\n" fi fi rm -f fake -echo "OS=$OS" > $CONFFILE -echo "STG_TIME=yes" >> $CONFFILE -echo "DEBUG=$DEBUG" >> $CONFFILE -echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE -echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE -echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE -echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE -echo "ARCH=$ARCH" >> $CONFFILE -echo "DEFS=$DEFS" >> $CONFFILE -echo -n "STG_LIBS=" >> $CONFFILE +printf "OS=$OS\n" > $CONFFILE +printf "STG_TIME=yes\n" >> $CONFFILE +printf "DEBUG=$DEBUG\n" >> $CONFFILE +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 "ARCH=$ARCH\n" >> $CONFFILE +printf "DEFS=$DEFS\n" >> $CONFFILE +printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do - echo -n "$lib " >> $CONFFILE + printf "$lib " >> $CONFFILE done -echo "" >> $CONFFILE -echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE -echo "CFLAGS=$CFLAGS" >> $CONFFILE -echo "LDFLAGS=$LDFLAGS" >> $CONFFILE -echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE -echo "PREFIX=$PREFIX" >> $CONFFILE -echo "BIN_MODE=$BIN_MODE" >> $CONFFILE -echo "DATA_MODE=$DATA_MODE" >> $CONFFILE -echo "DIR_MODE=$DIR_MODE" >> $CONFFILE -echo "OWNER=$OWNER" >> $CONFFILE +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 $MAKE $MAKEOPTS diff --git a/projects/rscriptd/build b/projects/rscriptd/build index ea3914c7..c7aa090d 100755 --- a/projects/rscriptd/build +++ b/projects/rscriptd/build @@ -53,15 +53,15 @@ fi if [ "$OS" = "unknown" ] then - echo "#############################################################################" - echo "# Sorry, but rscriptd currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #" - echo "#############################################################################" + printf "#############################################################################\n" + printf "# Sorry, but rscriptd currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "#############################################################################\n" exit 1 fi -echo "#############################################################################" -echo " Building rscriptd for $sys $release" -echo "#############################################################################" +printf "#############################################################################\n" +printf " Building rscriptd for $sys $release\n" +printf "#############################################################################\n" STG_LIBS="logger.lib locker.lib @@ -100,32 +100,32 @@ then CXX=g++ fi -echo -n "Checking CC... " +printf "Checking CC... " $CC --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CC not found" + printf "FAIL!\n" + printf "$CC not found\n" exit; fi -echo "found" -echo -n "Checking CXX... " +printf "found\n" +printf "Checking CXX... " $CXX --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CXX not found" + printf "FAIL!\n" + printf "$CXX not found\n" exit; fi -echo "found" +printf "found\n" -echo -n "Checking endianess... " -echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c +printf "Checking endianess... " +printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "Endianess checking failed" + printf "FAIL!\n" + printf "Endianess checking failed\n" exit; else ./fake @@ -134,41 +134,41 @@ else ARCH=le CXXFLAGS="$CXXFLAGS -DARCH_LE" CFLAGS="$CFLAGS -DARCH_LE" - echo "Little Endian" + printf "Little Endian\n" else ARCH=be CXXFLAGS="$CXXFLAGS -DARCH_BE" CFLAGS="$CFLAGS -DARCH_BE" - echo "Big Endian" + printf "Big Endian\n" fi fi rm -f fake rm -f build_check.c -echo "OS=$OS" > $CONFFILE -echo "STG_TIME=yes" >> $CONFFILE -echo "DEBUG=$DEBUG" >> $CONFFILE -echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE -echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE -echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE -echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE -echo "ARCH=$ARCH" >> $CONFFILE -echo "DEFS=$DEFS" >> $CONFFILE -echo -n "STG_LIBS=" >> $CONFFILE +printf "OS=$OS\n" > $CONFFILE +printf "STG_TIME=yes\n" >> $CONFFILE +printf "DEBUG=$DEBUG\n" >> $CONFFILE +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 "ARCH=$ARCH\n" >> $CONFFILE +printf "DEFS=$DEFS\n" >> $CONFFILE +printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do - echo -n "$lib " >> $CONFFILE + printf "$lib " >> $CONFFILE done -echo "" >> $CONFFILE -echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE -echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE -echo "CFLAGS=$CFLAGS" >> $CONFFILE -echo "LDFLAGS=$LDFLAGS" >> $CONFFILE -echo "PREFIX=$PREFIX" >> $CONFFILE -echo "BIN_MODE=$BIN_MODE" >> $CONFFILE -echo "DATA_MODE=$DATA_MODE" >> $CONFFILE -echo "DIR_MODE=$DIR_MODE" >> $CONFFILE -echo "OWNER=$OWNER" >> $CONFFILE +printf "\n" >> $CONFFILE +printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE +printf "CFLAGS=$CFLAGS\n" >> $CONFFILE +printf "LDFLAGS=$LDFLAGS\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 diff --git a/projects/sgauth/build b/projects/sgauth/build index 8b79bc52..5ea022a2 100755 --- a/projects/sgauth/build +++ b/projects/sgauth/build @@ -53,15 +53,15 @@ fi if [ "$OS" = "unknown" ] then - echo "#############################################################################" - echo "# Sorry, but sgauth currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #" - echo "#############################################################################" + printf "#############################################################################\n" + printf "# Sorry, but sgauth currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "#############################################################################\n" exit 1 fi -echo "#############################################################################" -echo " Building sgauth for $sys $release" -echo "#############################################################################" +printf "#############################################################################\n" +printf " Building sgauth for $sys $release\n" +printf "#############################################################################\n" STG_LIBS="crypto.lib common.lib @@ -98,32 +98,32 @@ then CXX=g++ fi -echo -n "Checking CC... " +printf "Checking CC... " $CC --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CC not found" + printf "FAIL!\n" + printf "$CC not found\n" exit; fi -echo "found" -echo -n "Checking CXX... " +printf "found\n" +printf "Checking CXX... " $CXX --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CXX not found" + printf "FAIL!\n" + printf "$CXX not found\n" exit; fi -echo "found" +printf "found\n" -echo -n "Checking endianess... " -echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c +printf "Checking endianess... " +printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "Endianess checking failed" + printf "FAIL!\n" + printf "Endianess checking failed\n" exit; else ./fake @@ -132,40 +132,40 @@ else ARCH=le CXXFLAGS="$CXXFLAGS -DARCH_LE" CFLAGS="$CFLAGS -DARCH_LE" - echo "Little Endian" + printf "Little Endian\n" else ARCH=be CXXFLAGS="$CXXFLAGS -DARCH_BE" CFLAGS="$CFLAGS -DARCH_BE" - echo "Big Endian" + printf "Big Endian\n" fi fi rm -f fake rm -f build_check.c -echo "OS=$OS" > $CONFFILE -echo "STG_TIME=yes" >> $CONFFILE -echo "DEBUG=$DEBUG" >> $CONFFILE -echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE -echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE -echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE -echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE -echo "ARCH=$ARCH" >> $CONFFILE -echo "DEFS=$DEFS" >> $CONFFILE -echo -n "STG_LIBS=" >> $CONFFILE +printf "OS=$OS\n" > $CONFFILE +printf "STG_TIME=yes\n" >> $CONFFILE +printf "DEBUG=$DEBUG\n" >> $CONFFILE +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 "ARCH=$ARCH\n" >> $CONFFILE +printf "DEFS=$DEFS\n" >> $CONFFILE +printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do - echo -n "$lib " >> $CONFFILE + printf "$lib " >> $CONFFILE done -echo "" >> $CONFFILE -echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE -echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE -echo "CFLAGS=$CFLAGS" >> $CONFFILE -echo "LDFLAGS=$LDFLAGS" >> $CONFFILE -echo "PREFIX=$PREFIX" >> $CONFFILE -echo "BIN_MODE=$BIN_MODE" >> $CONFFILE -echo "DATA_MODE=$DATA_MODE" >> $CONFFILE -echo "DIR_MODE=$DIR_MODE" >> $CONFFILE -echo "OWNER=$OWNER" >> $CONFFILE +printf "\n" >> $CONFFILE +printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE +printf "CFLAGS=$CFLAGS\n" >> $CONFFILE +printf "LDFLAGS=$LDFLAGS\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 diff --git a/projects/sgauthstress/build b/projects/sgauthstress/build index 6f26a17e..2b145659 100755 --- a/projects/sgauthstress/build +++ b/projects/sgauthstress/build @@ -59,15 +59,15 @@ fi if [ "$OS" = "unknown" ] then - echo "################################################################################" - echo "# Sorry, but sgauthstress currently supported by Linux, FreeBSD 4.x-8.x #" - echo "################################################################################" + printf "################################################################################\n" + printf "# Sorry, but sgauthstress currently supported by Linux, FreeBSD 4.x-8.x #\n" + printf "################################################################################\n" exit 1 fi -echo "#############################################################################" -echo " Building sgauthstress for $sys $release" -echo "#############################################################################" +printf "#############################################################################\n" +printf " Building sgauthstress for $sys $release\n" +printf "#############################################################################\n" STG_LIBS="logger.lib locker.lib @@ -108,32 +108,32 @@ then CXX=g++ fi -echo -n "Checking CC... " +printf "Checking CC... " $CC --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CC not found" + printf "FAIL!\n" + printf "$CC not found\n" exit; fi -echo "found" -echo -n "Checking CXX... " +printf "found\n" +printf "Checking CXX... " $CXX --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CXX not found" + printf "FAIL!\n" + printf "$CXX not found\n" exit; fi -echo "found" +printf "found\n" -echo -n "Checking endianess... " -echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c +printf "Checking endianess... " +printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "Endianess checking failed" + printf "FAIL!\n" + printf "Endianess checking failed\n" exit; else ./fake @@ -142,103 +142,103 @@ else ARCH=le CXXFLAGS="$CXXFLAGS -DARCH_LE" CFLAGS="$CFLAGS -DARCH_LE" - echo "Little Endian" + printf "Little Endian\n" else ARCH=be CXXFLAGS="$CXXFLAGS -DARCH_BE" CFLAGS="$CFLAGS -DARCH_BE" - echo "Big Endian" + printf "Big Endian\n" fi fi rm -f fake rm -f build_check.c -echo -n "Checking for -lfbclient... " +printf "Checking for -lfbclient... " $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_FBCLIENT=no - echo "no" + printf "no\n" else CHECK_FBCLIENT=yes - echo "yes" + printf "yes\n" fi rm -f fake -echo -n "Checking for mysql_config... " +printf "Checking for mysql_config... " MYSQL_VERSION=`mysql_config --version 2> /dev/null` if [ $? != 0 ] then - echo "no"; - echo -n "Checking for -lmysqlclient... " + printf "no\n"; + printf "Checking for -lmysqlclient... " $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else CHECK_MYSQLCLIENT=yes - echo "yes" + printf "yes\n" fi rm -f fake else - echo "yes" - echo -n "Checking for mysql_config --cflags... " + printf "yes\n" + printf "Checking for mysql_config --cflags... " MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null` if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else - echo "[$MYSQL_CFLAGS]" - echo -n "Checking for mysql_config --libs_r... " + printf "[$MYSQL_CFLAGS]\n" + printf "Checking for mysql_config --libs_r... " MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null` if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else CHECK_MYSQLCLIENT=yes - echo "[$MYSQL_LDFLAGS]" + printf "[$MYSQL_LDFLAGS]\n" fi fi fi -echo -n "Checking for pg_config... " +printf "Checking for pg_config... " PG_VERSION=`pg_config --version 2> /dev/null` if [ $? != 0 ] then - echo "no"; - echo -n "Checking for -lpq... " + printf "no\n"; + printf "Checking for -lpq... " $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else CHECK_PQ=yes - echo "yes" + printf "yes\n" fi rm -f fake else - echo "yes"; - echo -n "Checking for pg_config --includedir... " + printf "yes\n"; + printf "Checking for pg_config --includedir... " PG_CFLAGS=`pg_config --includedir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else - echo "[$PG_CFLAGS]" - echo -n "Checking for pg_config --libdir... " + printf "[$PG_CFLAGS]\n" + printf "Checking for pg_config --libdir... " PG_LDFLAGS=`pg_config --libdir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else CHECK_PQ=yes - echo "[$PG_LDFLAGS]" + printf "[$PG_LDFLAGS]\n" fi fi fi @@ -265,36 +265,36 @@ then store/mysql" fi -echo "OS=$OS" > $CONFFILE -echo "STG_TIME=yes" >> $CONFFILE -echo "DEBUG=$DEBUG" >> $CONFFILE -echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE -echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE -echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE -echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE -echo "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules" >> $CONFFILE -echo "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins" >> $CONFFILE -echo "ARCH=$ARCH" >> $CONFFILE -echo "DEFS=$DEFS" >> $CONFFILE -echo -n "STG_LIBS=" >> $CONFFILE +printf "OS=$OS\n" > $CONFFILE +printf "STG_TIME=yes\n" >> $CONFFILE +printf "DEBUG=$DEBUG\n" >> $CONFFILE +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)/../stargazer/modules\n" >> $CONFFILE +printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE +printf "ARCH=$ARCH\n" >> $CONFFILE +printf "DEFS=$DEFS\n" >> $CONFFILE +printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do - echo -n "$lib " >> $CONFFILE + printf "$lib " >> $CONFFILE done -echo "" >> $CONFFILE -echo -n "PLUGINS=" >> $CONFFILE +printf "\n" >> $CONFFILE +printf "PLUGINS=" >> $CONFFILE for plugin in $PLUGINS do - echo -n "$plugin " >> $CONFFILE + printf "$plugin " >> $CONFFILE done -echo "" >> $CONFFILE -echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE -echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE -echo "CFLAGS=$CFLAGS" >> $CONFFILE -echo "LDFLAGS=$LDFLAGS" >> $CONFFILE -echo "PREFIX=$PREFIX" >> $CONFFILE -echo "BIN_MODE=$BIN_MODE" >> $CONFFILE -echo "DATA_MODE=$DATA_MODE" >> $CONFFILE -echo "DIR_MODE=$DIR_MODE" >> $CONFFILE -echo "OWNER=$OWNER" >> $CONFFILE +printf "\n" >> $CONFFILE +printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE +printf "CFLAGS=$CFLAGS\n" >> $CONFFILE +printf "LDFLAGS=$LDFLAGS\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 diff --git a/projects/sgconf/Makefile b/projects/sgconf/Makefile index 297d3e20..09699122 100644 --- a/projects/sgconf/Makefile +++ b/projects/sgconf/Makefile @@ -41,7 +41,11 @@ OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS)))) CXXFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS) CFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS) -LDFLAGS += -Wl,-E $(STGLIBS_LIBS) +LDFLAGS += $(STGLIBS_LIBS) + +ifneq ($(OS),darwin) +LDFLAGS += -Wl,-E +endif .PHONY: all clean distclean libs install uninstall install-bin install-data uninstall-bin uninstall-data all: libs $(PROG) ../../Makefile.conf diff --git a/projects/sgconf/build b/projects/sgconf/build index a8a675be..d7b72363 100755 --- a/projects/sgconf/build +++ b/projects/sgconf/build @@ -51,17 +51,24 @@ then MAKE="gmake" fi +if [ "$sys" = "Darwin" ] +then + OS=darwin + ETC_DIR="./inst/freebsd/etc/stargazer" + MAKE="gmake" +fi + if [ "$OS" = "unknown" ] then - echo "#############################################################################" - echo "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #" - echo "#############################################################################" + printf "#############################################################################\n" + printf "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "#############################################################################\n" exit 1 fi -echo "#############################################################################" -echo " Building sgconf for $sys $release" -echo "#############################################################################" +printf "#############################################################################\n" +printf " Building sgconf for $sys $release\n" +printf "#############################################################################\n" STG_LIBS="conffiles.lib crypto.lib @@ -77,12 +84,18 @@ else then DEFS="$DEFS -DFREE_BSD" else - DEFS="$DEFS -DFREE_BSD5" if [ "$OS" = "bsd7" ] then + DEFS="$DEFS -DFREE_BSD5" LIB_THREAD=-lpthread else - LIB_THREAD=-lc_r + if [ "$OS" == "darwin" ] + then + DEFS="$DEFS -DDARWIN" + LIB_THREAD=-lpthread + else + LIB_THREAD=-lc_r + fi fi fi fi @@ -97,32 +110,32 @@ then CXX=g++ fi -echo -n "Checking CC... " +printf "Checking CC... " $CC --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CC not found" + printf "FAIL!\n" + printf "$CC not found\n" exit; fi -echo "found" -echo -n "Checking CXX... " +printf "found\n" +printf "Checking CXX... " $CXX --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CXX not found" + printf "FAIL!\n" + printf "$CXX not found\n" exit; fi -echo "found" +printf "found\n" -echo -n "Checking endianess... " -echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c +printf "Checking endianess... " +printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "Endianess checking failed" + printf "FAIL!\n" + printf "Endianess checking failed\n" exit; else ./fake @@ -131,61 +144,61 @@ else ARCH=le CXXFLAGS="$CXXFLAGS -DARCH_LE" CFLAGS="$CFLAGS -DARCH_LE" - echo "Little Endian" + printf "Little Endian\n" else ARCH=be CXXFLAGS="$CXXFLAGS -DARCH_BE" CFLAGS="$CFLAGS -DARCH_BE" - echo "Big Endian" + printf "Big Endian\n" fi fi rm -f fake -echo -n "Checking for -lexpat... " -echo "int main() { return 0; }" > build_check.c +printf "Checking for -lexpat... " +printf "int main() { return 0; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_EXPAT=no - echo "no" + printf "no\n" else CHECK_EXPAT=yes - echo "yes" + printf "yes\n" fi rm -f fake rm -f build_check.c if [ "$CHECK_EXPAT" != "yes" ] then - echo "-lexpat not found!" + printf "-lexpat not found!\n" exit 1 fi -echo "OS=$OS" > $CONFFILE -echo "STG_TIME=yes" >> $CONFFILE -echo "DEBUG=$DEBUG" >> $CONFFILE -echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE -echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE -echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE -echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE -echo "ARCH=$ARCH" >> $CONFFILE -echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE -echo "DEFS=$DEFS" >> $CONFFILE -echo -n "STG_LIBS=" >> $CONFFILE +printf "OS=$OS\n" > $CONFFILE +printf "STG_TIME=yes\n" >> $CONFFILE +printf "DEBUG=$DEBUG\n" >> $CONFFILE +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 "ARCH=$ARCH\n" >> $CONFFILE +printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE +printf "DEFS=$DEFS\n" >> $CONFFILE +printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do - echo -n "$lib " >> $CONFFILE + printf "$lib " >> $CONFFILE done -echo "" >> $CONFFILE -echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE -echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE -echo "CFLAGS=$CFLAGS" >> $CONFFILE -echo "LDFLAGS=$LDFLAGS" >> $CONFFILE -echo "PREFIX=$PREFIX" >> $CONFFILE -echo "BIN_MODE=$BIN_MODE" >> $CONFFILE -echo "DATA_MODE=$DATA_MODE" >> $CONFFILE -echo "DIR_MODE=$DIR_MODE" >> $CONFFILE -echo "OWNER=$OWNER" >> $CONFFILE +printf "\n" >> $CONFFILE +printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE +printf "CFLAGS=$CFLAGS\n" >> $CONFFILE +printf "LDFLAGS=$LDFLAGS\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 diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index 3d015160..a54826df 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -25,21 +25,23 @@ */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "stg/common.h" #include "sg_error_codes.h" #include "common_sg.h" #include "version_sg.h" -using namespace std; +#include "stg/common.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include const int usageConf = 0; const int usageInfo = 1; @@ -47,18 +49,26 @@ const int usageInfo = 1; const int TO_KOI8 = 0; const int FROM_KOI8 = 1; //----------------------------------------------------------------------------- -struct GetUserCbData +struct ResultData +{ + bool result; + std::string reason; +}; +//----------------------------------------------------------------------------- +struct GetUserData { - void * data; - bool * result; + GetUserData(REQUEST & req, bool res) : request(req), result(res) {} + REQUEST & request; + bool result; + std::string reason; }; //--------------------------------------------------------------------------- struct HelpParams { - string setActionName; - string getActionName; - string valueName; - string valueParam; + std::string setActionName; + std::string getActionName; + std::string valueName; + std::string valueParam; }; //--------------------------------------------------------------------------- void Usage(int usageType) @@ -84,7 +94,7 @@ HelpParams hp[] = {"set credit expire", "get credit expire", "-E", ""}, {"set password", "get password", "-o", ""}, {"set prepaid traffic", "get prepaid traffic", "-e", ""}, - {"set IP-addresses", "get IP-addresses", "-I", "<*|ip_addr[,ip_addr...]>"}, + {"set IP-addresses", "get IP-addresses", "-I", "<*|ip_addr[,ip_addr...]>"}, {"set name", "get name", "-A", ""}, {"set note", "get note", "-N", ""}, {"set street address", "get street address", "-D", "
"}, @@ -122,6 +132,9 @@ printf("sgconf set -s -p -a -w -u -- printf("To get userdata<0...9> use:\n"); printf("sgconf get -s -p -a -w -u --ud0 [--ud1 ...]\n\n"); +printf("To get user's authorizers list use:\n"); +printf("sgconf get -s -p -a -w -u --authorized-by\n\n"); + printf("To send message use:\n"); printf("sgconf set -s -p -a -w -u -m \n\n"); @@ -164,7 +177,7 @@ short int ParseServerPort(const char * p) int port; if (str2x(p, port) != 0) { - printf("Incorresct server port %s\n", p); + printf("Incorrect server port %s\n", p); exit(NETWORK_ERR_CODE); } return (short)port; @@ -174,7 +187,7 @@ char * ParseAdminLogin(char * adm) { if (CheckLogin(adm)) { - printf("Incorresct admin login %s\n", adm); + printf("Incorrect admin login %s\n", adm); exit(PARAMETER_PARSING_ERR_CODE); } return adm; @@ -195,13 +208,13 @@ char * ParseUser(char * usr) { if (CheckLogin(usr)) { - printf("Incorresct user login %s\n", usr); + printf("Incorrect user login %s\n", usr); exit(PARAMETER_PARSING_ERR_CODE); } return usr; } //----------------------------------------------------------------------------- -void ConvertKOI8(const string & src, string * dst, int encType) +void ConvertKOI8(const std::string & src, std::string * dst, int encType) { iconv_t cd; char * ob = new char[src.size() * 2 + 1]; @@ -276,67 +289,75 @@ delete[] ob; delete[] ib; } //----------------------------------------------------------------------------- -void ConvertFromKOI8(const string & src, string * dst) +void ConvertFromKOI8(const std::string & src, std::string * dst) { ConvertKOI8(src, dst, FROM_KOI8); } //----------------------------------------------------------------------------- -void ConvertToKOI8(const string & src, string * dst) +void SendMessageCallback(bool result, const std::string & reason, void * d) { -ConvertKOI8(src, dst, TO_KOI8); +ResultData * data = static_cast(d); +data->result = result; +data->reason = reason; } //----------------------------------------------------------------------------- -int RecvSetUserAnswer(const char * ans, void * d) +void RecvSetUserAnswer(bool result, const std::string & reason, void * d) { -GetUserCbData * gucbd; -gucbd = (GetUserCbData *)d; - -bool * result = gucbd->result; +ResultData * data = static_cast(d); +data->result = result; +data->reason = reason; +} +//----------------------------------------------------------------------------- +void RecvAuthByData(bool result, const std::string & reason, + const PARSER_AUTH_BY::INFO & list, void * d) +{ +ResultData * data = static_cast(d); +data->result = result; +data->reason = reason; -//REQUEST * req = (REQUEST *)gucbd->data; +if (!result) + return; -//printf("ans=%s\n", ans); -if (strcasecmp("Ok", ans) == 0) - *result = true; -else - *result = false; +for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + std::cout << *it << "\n"; -return 0; +std::cout << std::endl; } //----------------------------------------------------------------------------- struct StringReqParams { - string name; - RESETABLE reqParam; - string * value; + std::string name; + RESETABLE reqParam; + const std::string * value; }; //----------------------------------------------------------------------------- -void RecvUserData(USERDATA * ud, void * d) +void GetUserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * d) { -GetUserCbData * gucbd; -gucbd = (GetUserCbData *)d; - -bool * result = gucbd->result; +GetUserData * data = static_cast(d); +data->result = false; +data->reason = reason; -REQUEST * req = (REQUEST *)gucbd->data; +if (!result) + return; -if (ud->login == "") +if (info.login == "") { - *result = false; + data->result = false; + data->reason = "Invalid login."; return; } -if (!req->cash.res_empty()) - cout << "cash=" << ud->cash << endl; +if (!data->request.cash.res_empty()) + cout << "cash = " << info.cash << endl; -if (!req->credit.res_empty()) - cout << "credit=" << ud->credit << endl; +if (!data->request.credit.res_empty()) + cout << "credit = " << info.credit << endl; -if (!req->creditExpire.res_empty()) +if (!data->request.creditExpire.res_empty()) { char buf[32]; struct tm brokenTime; - time_t tt = ud->creditExpire; + time_t tt = info.creditExpire; brokenTime.tm_wday = 0; brokenTime.tm_yday = 0; @@ -349,53 +370,61 @@ if (!req->creditExpire.res_empty()) strftime(buf, 32, "%Y-%m-%d", &brokenTime); - cout << "creditExpire=" << buf << endl; + cout << "creditExpire = " << buf << endl; } -if (!req->down.res_empty()) - cout << "down=" << ud->down << endl; +if (!data->request.down.res_empty()) + cout << "down = " << info.down << endl; -if (!req->passive.res_empty()) - cout << "passive=" << ud->passive << endl; +if (!data->request.passive.res_empty()) + cout << "passive = " << info.passive << endl; -if (!req->disableDetailStat.res_empty()) - cout << "disableDetailStat=" << ud->disableDetailStat << endl; +if (!data->request.disableDetailStat.res_empty()) + cout << "disableDetailStat = " << info.disableDetailStat << endl; -if (!req->alwaysOnline.res_empty()) - cout << "alwaysOnline=" << ud->alwaysOnline << endl; +if (!data->request.alwaysOnline.res_empty()) + cout << "alwaysOnline = " << info.alwaysOnline << endl; -if (!req->prepaidTraff.res_empty()) - cout << "prepaidTraff=" << ud->prepaidTraff << endl; +if (!data->request.prepaidTraff.res_empty()) + cout << "prepaidTraff = " << info.prepaidTraff << endl; for (int i = 0; i < DIR_NUM; i++) { - if (!req->u[i].res_empty()) - cout << "u" << i << "=" << ud->stat.mu[i] << endl; - if (!req->d[i].res_empty()) - cout << "d" << i << "=" << ud->stat.md[i] << endl; + if (!data->request.sessionUpload[i].res_empty()) + cout << "session upload for dir " << i << " = " << info.stat.su[i] << endl; + if (!data->request.sessionDownload[i].res_empty()) + cout << "session download for dir " << i << "=" << info.stat.sd[i] << endl; + } + +for (int i = 0; i < DIR_NUM; i++) + { + if (!data->request.monthUpload[i].res_empty()) + cout << "month upload for dir " << i << " = " << info.stat.mu[i] << endl; + if (!data->request.monthDownload[i].res_empty()) + cout << "month download for dir " << i << " = " << info.stat.md[i] << endl; } for (int i = 0; i < USERDATA_NUM; i++) { - if (!req->ud[i].res_empty()) + if (!data->request.userData[i].res_empty()) { - string str; - ConvertFromKOI8(ud->userData[i], &str); - cout << "userdata" << i << "=" << str << endl; + std::string str; + ConvertFromKOI8(info.userData[i], &str); + cout << "user data " << i << " = " << str << endl; } } StringReqParams strReqParams[] = { - {"note", req->note, &ud->note}, - {"name", req->name, &ud->name}, - {"address", req->address, &ud->address}, - {"email", req->email, &ud->email}, - {"phone", req->phone, &ud->phone}, - {"group", req->group, &ud->group}, - {"tariff", req->tariff, &ud->tariff}, - {"password", req->usrPasswd, &ud->password}, - {"ip", req->ips, &ud->ips} // IP-address of user + {"note", data->request.note, &info.note}, + {"name", data->request.name, &info.name}, + {"address", data->request.address, &info.address}, + {"email", data->request.email, &info.email}, + {"phone", data->request.phone, &info.phone}, + {"group", data->request.group, &info.group}, + {"tariff", data->request.tariff, &info.tariff}, + {"password", data->request.usrPasswd, &info.password}, + {"ip", data->request.ips, &info.ips} // IP-address of user }; for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++) { @@ -403,97 +432,133 @@ for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++) { string str; ConvertFromKOI8(*strReqParams[i].value, &str); - cout << strReqParams[i].name << "=" << str << endl; + cout << strReqParams[i].name << " = " << str << endl; } } -*result = true; +data->result = true; } //----------------------------------------------------------------------------- -int ProcessSetUser(const std::string &server, - int port, - const std::string &admLogin, - const std::string &admPasswd, - const std::string &str, - void * data, - bool isMessage) +bool ProcessSetUser(const std::string & server, + int port, + const std::string & admLogin, + const std::string & admPasswd, + const std::string & str) { SERVCONF sc; -bool result = false; - - -sc.SetServer(server.c_str()); // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ -sc.SetPort(port); // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ -sc.SetAdmLogin(admLogin.c_str()); // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉÎ É ÐÁÒÏÌØ ÁÄÍÉÎÁ +sc.SetServer(server.c_str()); +sc.SetPort(port); +sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); -// TODO Good variable name :) -GetUserCbData gucbd; - -gucbd.data = data; -gucbd.result = &result; +ResultData data; +sc.SetChgUserCallback(RecvSetUserAnswer, &data); +int res = sc.ChgUser(str.c_str()); -if (isMessage) +if (res == st_ok && data.result) { - sc.SetSendMessageCb(RecvSetUserAnswer, &gucbd); - sc.MsgUser(str.c_str()); + printf("Ok\n"); + return false; } + +printf("Error\n"); +if (res != st_ok) + printf("%s\n", sc.GetStrError().c_str()); else - { - sc.SetChgUserCb(RecvSetUserAnswer, &gucbd); - sc.ChgUser(str.c_str()); - } + printf("%s\n", data.reason.c_str()); +return true; +} +//----------------------------------------------------------------------------- +bool ProcessSendMessage(const std::string & server, uint16_t port, + const std::string & login, const std::string & password, + const std::string & requestString) +{ +SERVCONF sc; + +sc.SetServer(server.c_str()); +sc.SetPort(port); +sc.SetAdmLogin(login.c_str()); +sc.SetAdmPassword(password.c_str()); -if (result) +ResultData data; +sc.SetSendMessageCallback(SendMessageCallback, &data); +int res = sc.SendMessage(requestString.c_str()); + +if (res == st_ok && data.result) { printf("Ok\n"); - return 0; + return true; } + +printf("Error\n"); +if (res != st_ok) + printf("%s\n", sc.GetStrError().c_str()); else + printf("%s\n", data.reason.c_str()); +return false; +} +//----------------------------------------------------------------------------- +bool ProcessGetUser(const std::string &server, + int port, + const std::string &admLogin, + const std::string &admPasswd, + const std::string &login, + REQUEST & request) +{ +SERVCONF sc; + +sc.SetServer(server.c_str()); +sc.SetPort(port); +sc.SetAdmLogin(admLogin.c_str()); +sc.SetAdmPassword(admPasswd.c_str()); + +GetUserData data(request, false); + +sc.SetGetUserCallback(GetUserCallback, &data); +bool res = (sc.GetUser(login.c_str()) == st_ok); + +if (res && data.result) { - printf("Error\n"); - return -1; + printf("Ok\n"); + return true; } -return 0; +printf("Error\n"); +if (!res) + printf("%s\n", sc.GetStrError().c_str()); +else + printf("%s\n", data.reason.c_str()); +return false; } //----------------------------------------------------------------------------- -int ProcessGetUser(const std::string &server, +bool ProcessAuthBy(const std::string &server, int port, const std::string &admLogin, const std::string &admPasswd, - const std::string &login, - void * data) + const std::string &login) { SERVCONF sc; -bool result = false; - -sc.SetServer(server.c_str()); // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ -sc.SetPort(port); // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ -sc.SetAdmLogin(admLogin.c_str()); // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉÎ É ÐÁÒÏÌØ ÁÄÍÉÎÁ +sc.SetServer(server.c_str()); +sc.SetPort(port); +sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); -// TODO Good variable name :) -GetUserCbData gucbd; - -gucbd.data = data; -gucbd.result = &result; +ResultData data; +sc.SetAuthByCallback(RecvAuthByData, &data); +bool res = (sc.AuthBy(login.c_str()) == st_ok); -sc.SetGetUserDataRecvCb(RecvUserData, &gucbd); -sc.GetUser(login.c_str()); - -if (result) +if (res && data.result) { printf("Ok\n"); - return 0; - } -else - { - printf("Error\n"); - return -1; + return true; } -return 0; +printf("Error\n"); +if (!res) + printf("%s\n", sc.GetStrError().c_str()); +else + printf("%s\n", data.reason.c_str()); +return false; } //----------------------------------------------------------------------------- diff --git a/projects/sgconf/common_sg.h b/projects/sgconf/common_sg.h index a654748a..4bff0aa7 100644 --- a/projects/sgconf/common_sg.h +++ b/projects/sgconf/common_sg.h @@ -28,11 +28,11 @@ #ifndef COMMON_SG_H #define COMMON_SG_H -#include - #include "stg/servconf.h" #include "request.h" +#include + void UsageConf(); void UsageInfo(); @@ -45,20 +45,27 @@ int CheckLogin(const char * login); void ConvertFromKOI8(const std::string & src, std::string * dst); void ConvertToKOI8(const std::string & src, std::string * dst); -int ProcessGetUser(const std::string &server, - int port, - const std::string &admLogin, - const std::string &admPasswd, - const std::string &login, - void * data); +bool ProcessGetUser(const std::string & server, + int port, + const std::string & admLogin, + const std::string & admPasswd, + const std::string & login, + REQUEST & request); -int ProcessSetUser(const std::string &server, +bool ProcessAuthBy(const std::string & server, int port, - const std::string &admLogin, - const std::string &admPasswd, - const std::string &str, - void * data, - bool isMessage = false); + const std::string & admLogin, + const std::string & admPasswd, + const std::string & login); -#endif +bool ProcessSetUser(const std::string & server, + int port, + const std::string & admLogin, + const std::string & admPasswd, + const std::string & str); +bool ProcessSendMessage(const std::string & server, uint16_t port, + const std::string & login, const std::string & password, + const std::string & requestString); + +#endif diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 2aaacbc0..66f580f6 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -43,7 +43,35 @@ #include "common_sg.h" #include "sg_error_codes.h" -using namespace std; +namespace +{ + +template +struct ARRAY_TYPE; + +template +struct ARRAY_TYPE +{ +typedef T type; +}; + +template +struct ARRAY_TYPE +{ +typedef T type; +}; + +template +bool SetArrayItem(T & array, const char * index, const typename ARRAY_TYPE::type & value) +{ +size_t pos = 0; +if (str2x(index, pos)) + return false; +array[pos] = value; +return true; +} + +} // namespace anonymous time_t stgTime; @@ -66,37 +94,12 @@ struct option long_options_get[] = { {"passive", 0, 0, 'i'}, //passive {"disable-stat",0, 0, 'S'}, //disable detail stat {"always-online",0, 0, 'O'}, //always online -{"u0", 0, 0, 500}, //U0 -{"u1", 0, 0, 501}, //U1 -{"u2", 0, 0, 502}, //U2 -{"u3", 0, 0, 503}, //U3 -{"u4", 0, 0, 504}, //U4 -{"u5", 0, 0, 505}, //U5 -{"u6", 0, 0, 506}, //U6 -{"u7", 0, 0, 507}, //U7 -{"u8", 0, 0, 508}, //U8 -{"u9", 0, 0, 509}, //U9 -{"d0", 0, 0, 600}, //D0 -{"d1", 0, 0, 601}, //D1 -{"d2", 0, 0, 602}, //D2 -{"d3", 0, 0, 603}, //D3 -{"d4", 0, 0, 604}, //D4 -{"d5", 0, 0, 605}, //D5 -{"d6", 0, 0, 606}, //D6 -{"d7", 0, 0, 607}, //D7 -{"d8", 0, 0, 608}, //D8 -{"d9", 0, 0, 609}, //D9 - -{"ud0", 0, 0, 700}, //UserData0 -{"ud1", 0, 0, 701}, //UserData1 -{"ud2", 0, 0, 702}, //UserData2 -{"ud3", 0, 0, 703}, //UserData3 -{"ud4", 0, 0, 704}, //UserData4 -{"ud5", 0, 0, 705}, //UserData5 -{"ud6", 0, 0, 706}, //UserData6 -{"ud7", 0, 0, 707}, //UserData7 -{"ud8", 0, 0, 708}, //UserData8 -{"ud9", 0, 0, 709}, //UserData9 +{"session-upload", 1, 0, 500}, //SU0 +{"session-download", 1, 0, 501}, //SD0 +{"month-upload", 1, 0, 502}, //MU0 +{"month-download", 1, 0, 503}, //MD0 + +{"user-data", 1, 0, 700}, //UserData0 {"prepaid", 0, 0, 'e'}, //prepaid traff {"create", 0, 0, 'n'}, //create @@ -108,7 +111,8 @@ struct option long_options_get[] = { {"email", 0, 0, 'L'}, //emaiL {"phone", 0, 0, 'P'}, //phone {"group", 0, 0, 'G'}, //Group -{"ip", 0, 0, 'I'}, //IP-address of user +{"ip", 0, 0, 'I'}, //IP-address of user +{"authorized-by",0, 0, 800}, //always online {0, 0, 0, 0}}; @@ -128,37 +132,12 @@ struct option long_options_set[] = { {"passive", 1, 0, 'i'}, //passive {"disable-stat",1, 0, 'S'}, //disable detail stat {"always-online",1, 0, 'O'}, //always online -{"u0", 1, 0, 500}, //U0 -{"u1", 1, 0, 501}, //U1 -{"u2", 1, 0, 502}, //U2 -{"u3", 1, 0, 503}, //U3 -{"u4", 1, 0, 504}, //U4 -{"u5", 1, 0, 505}, //U5 -{"u6", 1, 0, 506}, //U6 -{"u7", 1, 0, 507}, //U7 -{"u8", 1, 0, 508}, //U8 -{"u9", 1, 0, 509}, //U9 -{"d0", 1, 0, 600}, //D0 -{"d1", 1, 0, 601}, //D1 -{"d2", 1, 0, 602}, //D2 -{"d3", 1, 0, 603}, //D3 -{"d4", 1, 0, 604}, //D4 -{"d5", 1, 0, 605}, //D5 -{"d6", 1, 0, 606}, //D6 -{"d7", 1, 0, 607}, //D7 -{"d8", 1, 0, 608}, //D8 -{"d9", 1, 0, 609}, //D9 - -{"ud0", 1, 0, 700}, //UserData -{"ud1", 1, 0, 701}, //UserData1 -{"ud2", 1, 0, 702}, //UserData2 -{"ud3", 1, 0, 703}, //UserData3 -{"ud4", 1, 0, 704}, //UserData4 -{"ud5", 1, 0, 705}, //UserData5 -{"ud6", 1, 0, 706}, //UserData6 -{"ud7", 1, 0, 707}, //UserData7 -{"ud8", 1, 0, 708}, //UserData8 -{"ud9", 1, 0, 709}, //UserData9 +{"session-upload", 1, 0, 500}, //U0 +{"session-download", 1, 0, 501}, //U1 +{"month-upload", 1, 0, 502}, //U2 +{"month-download", 1, 0, 503}, //U3 + +{"user-data", 1, 0, 700}, //UserData {"prepaid", 1, 0, 'e'}, //prepaid traff {"create", 1, 0, 'n'}, //create @@ -504,7 +483,36 @@ int uPresent = false; int dPresent = false; for (int i = 0; i < DIR_NUM; i++) { - if (!req->u[i].res_empty()) + if (!req->monthUpload[i].res_empty()) + { + if (!uPresent && !dPresent) + { + sprintf(str, "monthUpload[i].const_data(); + //sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data()); + sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str()); + strcat(r, str); + } + if (!req->monthDownload[i].res_empty()) + { + if (!uPresent && !dPresent) + { + sprintf(str, "monthDownload[i].const_data(); + sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str()); + strcat(r, str); + } + if (!req->sessionUpload[i].res_empty()) { if (!uPresent && !dPresent) { @@ -514,12 +522,12 @@ for (int i = 0; i < DIR_NUM; i++) } stringstream ss; - ss << req->u[i].const_data(); + ss << req->sessionUpload[i].const_data(); //sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data()); sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str()); strcat(r, str); } - if (!req->d[i].res_empty()) + if (!req->sessionDownload[i].res_empty()) { if (!uPresent && !dPresent) { @@ -529,7 +537,7 @@ for (int i = 0; i < DIR_NUM; i++) } stringstream ss; - ss << req->d[i].const_data(); + ss << req->sessionDownload[i].const_data(); sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str()); strcat(r, str); } @@ -611,10 +619,10 @@ if (!req->group.res_empty()) for (int i = 0; i < USERDATA_NUM; i++) { - if (!req->ud[i].res_empty()) + if (!req->userData[i].res_empty()) { string ud; - Encode12str(ud, req->ud[i]); + Encode12str(ud, req->userData[i]); sprintf(str, "", i, ud.c_str()); strcat(r, str); } @@ -625,16 +633,18 @@ strcat(r, "\n"); //----------------------------------------------------------------------------- int CheckParameters(REQUEST * req) { -int u = false; -int d = false; -int ud = false; -int a = !req->admLogin.res_empty() +bool su = false; +bool sd = false; +bool mu = false; +bool md = false; +bool ud = false; +bool 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() +bool b = !req->cash.res_empty() || !req->setCash.res_empty() || !req->credit.res_empty() || !req->prepaidTraff.res_empty() @@ -656,25 +666,43 @@ int b = !req->cash.res_empty() for (int i = 0; i < DIR_NUM; i++) { - if (req->u[i].res_empty()) + if (req->sessionUpload[i].res_empty()) { - u = true; + su = true; break; } } for (int i = 0; i < DIR_NUM; i++) { - if (req->d[i].res_empty()) + if (req->sessionDownload[i].res_empty()) { - d = true; + sd = true; break; } } for (int i = 0; i < DIR_NUM; i++) { - if (req->ud[i].res_empty()) + if (req->monthUpload[i].res_empty()) + { + mu = true; + break; + } + } + +for (int i = 0; i < DIR_NUM; i++) + { + if (req->monthDownload[i].res_empty()) + { + md = true; + break; + } + } + +for (int i = 0; i < DIR_NUM; i++) + { + if (req->userData[i].res_empty()) { ud = true; break; @@ -683,7 +711,7 @@ for (int i = 0; i < DIR_NUM; i++) //printf("a=%d, b=%d, u=%d, d=%d ud=%d\n", a, b, u, d, ud); -return a && (b || u || d || ud); +return a && (b || su || sd || mu || md || ud); } //----------------------------------------------------------------------------- int CheckParametersGet(REQUEST * req) @@ -696,7 +724,7 @@ int CheckParametersSet(REQUEST * req) return CheckParameters(req); } //----------------------------------------------------------------------------- -int mainGet(int argc, char **argv) +bool mainGet(int argc, char **argv) { int c; REQUEST req; @@ -791,10 +819,10 @@ while (1) case 'G': //Group req.group = " "; break; - - case 'I': //IP-address of user - req.ips = " "; - break; + + case 'I': //IP-address of user + req.ips = " "; + break; case 'S': //Detail stat status req.disableDetailStat = " "; @@ -805,50 +833,33 @@ while (1) break; case 500: //U + SetArrayItem(req.sessionUpload, optarg, 1); + //req.sessionUpload[optarg] = 1; + break; case 501: + SetArrayItem(req.sessionDownload, optarg, 1); + //req.sessionDownload[optarg] = 1; + break; case 502: + SetArrayItem(req.monthUpload, optarg, 1); + //req.monthUpload[optarg] = 1; + break; case 503: - case 504: - case 505: - case 506: - case 507: - case 508: - case 509: - //printf("U%d\n", c - 500); - req.u[c - 500] = 1; - break; - - case 600: //D - case 601: - case 602: - case 603: - case 604: - case 605: - case 606: - case 607: - case 608: - case 609: - //printf("D%d\n", c - 600); - req.d[c - 600] = 1; + SetArrayItem(req.monthDownload, optarg, 1); + //req.monthDownload[optarg] = 1; break; case 700: //UserData - case 701: - case 702: - case 703: - case 704: - case 705: - case 706: - case 707: - case 708: - case 709: - //printf("UD%d\n", c - 700); - req.ud[c - 700] = " "; + SetArrayItem(req.userData, optarg, std::string(" ")); + //req.userData[optarg] = " "; + break; + + case 800: + req.authBy = true; break; case '?': case ':': - //printf ("Unknown option \n"); missedOptionArg = true; break; @@ -873,10 +884,13 @@ if (missedOptionArg || !CheckParametersGet(&req)) exit(PARAMETER_PARSING_ERR_CODE); } -return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req); +if (req.authBy) + return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login); +else + return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, req); } //----------------------------------------------------------------------------- -int mainSet(int argc, char **argv) +bool mainSet(int argc, char **argv) { string str; @@ -1017,55 +1031,33 @@ while (1) break; case 500: //U + SetArrayItem(req.sessionUpload, optarg, ParseTraff(argv[optind++])); + //req.sessionUpload[optarg] = ParseTraff(argv[optind++]); + break; case 501: + SetArrayItem(req.sessionDownload, optarg, ParseTraff(argv[optind++])); + //req.sessionDownload[optarg] = ParseTraff(argv[optind++]); + break; case 502: + SetArrayItem(req.monthUpload, optarg, ParseTraff(argv[optind++])); + //req.monthUpload[optarg] = ParseTraff(argv[optind++]); + break; case 503: - case 504: - case 505: - case 506: - case 507: - case 508: - case 509: - //printf("U%d\n", c - 500); - req.u[c - 500] = ParseTraff(optarg); - break; - - case 600: //D - case 601: - case 602: - case 603: - case 604: - case 605: - case 606: - case 607: - case 608: - case 609: - //printf("D%d\n", c - 600); - req.d[c - 600] = ParseTraff(optarg); + SetArrayItem(req.monthDownload, optarg, ParseTraff(argv[optind++])); + //req.monthDownload[optarg] = ParseTraff(argv[optind++]); break; case 700: //UserData - case 701: - case 702: - case 703: - case 704: - case 705: - case 706: - case 707: - case 708: - case 709: - ParseAnyString(optarg, &str); - //printf("UD%d\n", c - 700); - req.ud[c - 700] = str; + ParseAnyString(argv[optind++], &str); + SetArrayItem(req.userData, optarg, str); + //req.userData[optarg] = str; break; case '?': - //printf("Missing option argument\n"); missedOptionArg = true; break; case ':': - //printf("Missing option argument\n"); missedOptionArg = true; break; @@ -1095,7 +1087,10 @@ char rstr[rLen]; memset(rstr, 0, rLen); CreateRequestSet(&req, rstr); -return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr, NULL, isMessage); +if (isMessage) + return ProcessSendMessage(req.server, req.port, req.admLogin, req.admPasswd, rstr); + +return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr); } //----------------------------------------------------------------------------- int main(int argc, char **argv) @@ -1114,7 +1109,9 @@ if (strcmp(argv[1], "get") == 0) else if (strcmp(argv[1], "set") == 0) { //printf("set\n"); - return mainSet(argc - 1, argv + 1); + if (mainSet(argc - 1, argv + 1) ) + return 0; + return -1; } else { diff --git a/projects/sgconf/request.h b/projects/sgconf/request.h index daddec1d..bca3c148 100644 --- a/projects/sgconf/request.h +++ b/projects/sgconf/request.h @@ -49,16 +49,19 @@ struct REQUEST REQUEST() : chgTariff(false), createUser(false), - deleteUser(false) + deleteUser(false), + authBy(false) { for (int i = 0; i < DIR_NUM; i++) { - u[i].reset(); - d[i].reset(); + sessionUpload[i].reset(); + sessionDownload[i].reset(); + monthUpload[i].reset(); + monthDownload[i].reset(); } for (int i = 0; i < USERDATA_NUM; i++) - ud[i].reset(); + userData[i].reset(); } RESETABLE server; @@ -75,6 +78,7 @@ RESETABLE setCash; string message; bool createUser; bool deleteUser; +bool authBy; RESETABLE usrMsg; RESETABLE credit; @@ -86,10 +90,13 @@ RESETABLE disableDetailStat; RESETABLE alwaysOnline; RESETABLE prepaidTraff; -RESETABLE u[DIR_NUM]; -RESETABLE d[DIR_NUM]; +RESETABLE sessionUpload[DIR_NUM]; +RESETABLE sessionDownload[DIR_NUM]; -RESETABLE ud[USERDATA_NUM]; +RESETABLE monthUpload[DIR_NUM]; +RESETABLE monthDownload[DIR_NUM]; + +RESETABLE userData[USERDATA_NUM]; RESETABLE note; RESETABLE name; diff --git a/projects/sgconf_xml/build b/projects/sgconf_xml/build index 6816a436..e9cfb40b 100755 --- a/projects/sgconf_xml/build +++ b/projects/sgconf_xml/build @@ -53,15 +53,15 @@ fi if [ "$OS" = "unknown" ] then - echo "#############################################################################" - echo "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #" - echo "#############################################################################" + printf "#############################################################################\n" + printf "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "#############################################################################\n" exit 1 fi -echo "#############################################################################" -echo " Building sgconf for $sys $release" -echo "#############################################################################" +printf "#############################################################################\n" +printf " Building sgconf for $sys $release\n" +printf "#############################################################################\n" STG_LIBS="conffiles.lib crypto.lib @@ -97,32 +97,32 @@ then CXX=g++ fi -echo -n "Checking CC... " +printf "Checking CC... " $CC --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CC not found" + printf "FAIL!\n" + printf "$CC not found\n" exit; fi -echo "found" -echo -n "Checking CXX... " +printf "found\n" +printf "Checking CXX... " $CXX --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CXX not found" + printf "FAIL!\n" + printf "$CXX not found\n" exit; fi -echo "found" +printf "found\n" -echo -n "Checking endianess... " -echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c +printf "Checking endianess... " +printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "Endianess checking failed" + printf "FAIL!\n" + printf "Endianess checking failed\n" exit; else ./fake @@ -131,61 +131,61 @@ else ARCH=le CXXFLAGS="$CXXFLAGS -DARCH_LE" CFLAGS="$CFLAGS -DARCH_LE" - echo "Little Endian" + printf "Little Endian\n" else ARCH=be CXXFLAGS="$CXXFLAGS -DARCH_BE" CFLAGS="$CFLAGS -DARCH_BE" - echo "Big Endian" + printf "Big Endian\n" fi fi rm -f fake -echo -n "Checking for -lexpat... " -echo "int main() { return 0; }" > build_check.c +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 if [ $? != 0 ] then CHECK_EXPAT=no - echo "no" + printf "no\n" else CHECK_EXPAT=yes - echo "yes" + printf "yes\n" fi rm -f fake rm -f build_check.c if [ "$CHECK_EXPAT" != "yes" ] then - echo "-lexpat not found!" + printf "-lexpat not found!\n" exit 1 fi -echo "OS=$OS" > $CONFFILE -echo "STG_TIME=yes" >> $CONFFILE -echo "DEBUG=$DEBUG" >> $CONFFILE -echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE -echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE -echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE -echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE -echo "ARCH=$ARCH" >> $CONFFILE -echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE -echo "DEFS=$DEFS" >> $CONFFILE -echo -n "STG_LIBS=" >> $CONFFILE +printf "OS=$OS\n" > $CONFFILE +printf "STG_TIME=yes\n" >> $CONFFILE +printf "DEBUG=$DEBUG\n" >> $CONFFILE +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 "ARCH=$ARCH\n" >> $CONFFILE +printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE +printf "DEFS=$DEFS\n" >> $CONFFILE +printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do - echo -n "$lib " >> $CONFFILE + printf "$lib " >> $CONFFILE done -echo "" >> $CONFFILE -echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE -echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE -echo "CFLAGS=$CFLAGS" >> $CONFFILE -echo "LDFLAGS=$LDFLAGS" >> $CONFFILE -echo "PREFIX=$PREFIX" >> $CONFFILE -echo "BIN_MODE=$BIN_MODE" >> $CONFFILE -echo "DATA_MODE=$DATA_MODE" >> $CONFFILE -echo "DIR_MODE=$DIR_MODE" >> $CONFFILE -echo "OWNER=$OWNER" >> $CONFFILE +printf "\n" >> $CONFFILE +printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE +printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE +printf "CFLAGS=$CFLAGS\n" >> $CONFFILE +printf "LDFLAGS=$LDFLAGS\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 diff --git a/projects/sgconv/build b/projects/sgconv/build index 5084bd0d..7e430be2 100755 --- a/projects/sgconv/build +++ b/projects/sgconv/build @@ -54,15 +54,15 @@ fi if [ "$OS" = "unknown" ] then - echo "#############################################################################" - echo "# Sorry, but sgconv currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #" - echo "#############################################################################" + printf "#############################################################################\n" + printf "# Sorry, but sgconv currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "#############################################################################\n" exit 1 fi -echo "#############################################################################" -echo " Building sgconv for $sys $release" -echo "#############################################################################" +printf "#############################################################################\n" +printf " Building sgconv for $sys $release\n" +printf "#############################################################################\n" STG_LIBS="logger.lib locker.lib @@ -103,32 +103,32 @@ then CXX=g++ fi -echo -n "Checking CC... " +printf "Checking CC... " $CC --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CC not found" + printf "FAIL!\n" + printf "$CC not found\n" exit; fi -echo "found" -echo -n "Checking CXX... " +printf "found\n" +printf "Checking CXX... " $CXX --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CXX not found" + printf "FAIL!\n" + printf "$CXX not found\n" exit; fi -echo "found" +printf "found\n" -echo -n "Checking endianess... " -echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c +printf "Checking endianess... " +printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c $CC $CFLAGS $LDFLAGS -L/usr/lib/mysql -L/usr/local/lib/mysql build_check.c -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "Endianess checking failed" + printf "FAIL!\n" + printf "Endianess checking failed\n" exit; else ./fake @@ -137,102 +137,102 @@ else ARCH=le CXXFLAGS="$CXXFLAGS -DARCH_LE" CFLAGS="$CFLAGS -DARCH_LE" - echo "Little Endian" + printf "Little Endian\n" else ARCH=be CXXFLAGS="$CXXFLAGS -DARCH_BE" CFLAGS="$CFLAGS -DARCH_BE" - echo "Big Endian" + printf "Big Endian\n" fi fi rm -f fake -echo -n "Checking for -lfbclient... " +printf "Checking for -lfbclient... " $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_FBCLIENT=no - echo "no" + printf "no\n" else CHECK_FBCLIENT=yes - echo "yes" + printf "yes\n" fi rm -f fake -echo -n "Checking for mysql_config... " +printf "Checking for mysql_config... " MYSQL_VERSION=`mysql_config --version 2> /dev/null` if [ $? != 0 ] then - echo "no"; - echo -n "Checking for -lmysqlclient... " + printf "no\n"; + printf "Checking for -lmysqlclient... " $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else CHECK_MYSQLCLIENT=yes - echo "yes" + printf "yes\n" fi rm -f fake else - echo "yes" - echo -n "Checking for mysql_config --cflags... " + printf "yes\n" + printf "Checking for mysql_config --cflags... " MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null` if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else - echo "[$MYSQL_CFLAGS]" - echo -n "Checking for mysql_config --libs_r... " + printf "[$MYSQL_CFLAGS]\n" + printf "Checking for mysql_config --libs_r... " MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null` if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else CHECK_MYSQLCLIENT=yes - echo "[$MYSQL_LDFLAGS]" + printf "[$MYSQL_LDFLAGS]\n" fi fi fi -echo -n "Checking for pg_config... " +printf "Checking for pg_config... " PG_VERSION=`pg_config --version 2> /dev/null` if [ $? != 0 ] then - echo "no"; - echo -n "Checking for -lpq... " + printf "no\n"; + printf "Checking for -lpq... " $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else CHECK_PQ=yes - echo "yes" + printf "yes\n" fi rm -f fake else - echo "yes"; - echo -n "Checking for pg_config --includedir... " + printf "yes\n"; + printf "Checking for pg_config --includedir... " PG_CFLAGS=`pg_config --includedir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else - echo "[$PG_CFLAGS]" - echo -n "Checking for pg_config --libdir... " + printf "[$PG_CFLAGS]\n" + printf "Checking for pg_config --libdir... " PG_LDFLAGS=`pg_config --libdir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else CHECK_PQ=yes - echo "[$PG_LDFLAGS]" + printf "[$PG_LDFLAGS]\n" fi fi fi @@ -259,40 +259,40 @@ then store/mysql" fi -echo "OS=$OS" > $CONFFILE -echo "STG_TIME=yes" >> $CONFFILE -echo "DEBUG=$DEBUG" >> $CONFFILE -echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE -echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE -echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE -echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE -echo "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules" >> $CONFFILE -echo "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins" >> $CONFFILE -echo "ARCH=$ARCH" >> $CONFFILE -echo "CHECK_FBCLIENT=$CHECK_FBCLIENT" >> $CONFFILE -echo "DEFS=$DEFS" >> $CONFFILE -echo -n "STG_LIBS=" >> $CONFFILE +printf "OS=$OS\n" > $CONFFILE +printf "STG_TIME=yes\n" >> $CONFFILE +printf "DEBUG=$DEBUG\n" >> $CONFFILE +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)/../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 +printf "DEFS=$DEFS\n" >> $CONFFILE +printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do - echo -n "$lib " >> $CONFFILE + printf "$lib " >> $CONFFILE done -echo "" >> $CONFFILE -echo -n "PLUGINS=" >> $CONFFILE +printf "\n" >> $CONFFILE +printf "PLUGINS=" >> $CONFFILE for plugin in $PLUGINS do - echo -n "$plugin " >> $CONFFILE + printf "$plugin " >> $CONFFILE done -echo "" >> $CONFFILE -echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE -echo "CFLAGS=$CFLAGS" >> $CONFFILE -echo "LDFLAGS=$LDFLAGS" >> $CONFFILE -echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE -echo "PREFIX=$PREFIX" >> $CONFFILE -echo "BIN_MODE=$BIN_MODE" >> $CONFFILE -echo "DATA_MODE=$DATA_MODE" >> $CONFFILE -echo "DIR_MODE=$DIR_MODE" >> $CONFFILE -echo "OWNER=$OWNER" >> $CONFFILE -echo "VAR_DIR=$VAR_DIR" >> $CONFFILE +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 mkdir -p ../stargazer/modules diff --git a/projects/stargazer/Makefile b/projects/stargazer/Makefile index 9dfc0b51..aa2b6f90 100644 --- a/projects/stargazer/Makefile +++ b/projects/stargazer/Makefile @@ -47,7 +47,12 @@ OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS)))) CXXFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS) CFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS) + +ifneq ($(OS),darwin) LDFLAGS += -Wl,-E $(STGLIBS_LIBS) +endif + +LDFLAGS += $(STGLIBS_LIBS) .PHONY: all clean distclean libs plugins install uninstall install-bin install-data all: libs plugins $(PROG) diff --git a/projects/stargazer/build b/projects/stargazer/build index a323148b..2061d538 100755 --- a/projects/stargazer/build +++ b/projects/stargazer/build @@ -72,17 +72,24 @@ then MAKE="gmake" fi +if [ "$sys" = "Darwin" ] +then + OS=darwin + ETC_DIR="./inst/freebsd/etc/stargazer" + MAKE="gmake" +fi + if [ "$OS" = "unknown" ] then - echo "#############################################################################" - echo "# Sorry, but stargazer currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #" - echo "#############################################################################" + printf "#############################################################################\n" + printf "# Sorry, but stargazer currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n" + printf "#############################################################################\n" exit 1 fi -echo "#############################################################################" -echo " Building STG 2.4 for $sys $release" -echo "#############################################################################" +printf "#############################################################################\n" +printf " Building STG 2.4 for $sys $release\n" +printf "#############################################################################\n" STG_LIBS="logger.lib locker.lib @@ -116,12 +123,18 @@ else DEFS="$DEFS -DFREE_BSD" LIB_THREAD=-lc_r else - DEFS="$DEFS -DFREE_BSD5" if [ "$OS" = "bsd7" ] then + DEFS="$DEFS -DFREE_BSD5" LIB_THREAD=-lpthread else - LIB_THREAD=-lc_r + if [ "$OS" == "darwin" ] + then + DEFS="$DEFS -DDARWIN" + LIB_THREAD=-lpthread + else + LIB_THREAD=-lc_r + fi fi fi PLUGINS="$PLUGINS @@ -139,32 +152,32 @@ then CXX=g++ fi -echo -n "Checking CC... " +printf "Checking CC... " $CC --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CC not found" + printf "FAIL!\n" + printf "$CC not found\n" exit; fi -echo "found" -echo -n "Checking CXX... " +printf "found\n" +printf "Checking CXX... " $CXX --version > /dev/null 2> /dev/null if [ $? != 0 ] then - echo "FAIL!" - echo "$CXX not found" + printf "FAIL!\n" + printf "$CXX not found\n" exit; fi -echo "found" +printf "found\n" -echo -n "Checking endianess... " -echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c +printf "Checking endianess... " +printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -o fake if [ $? != 0 ] then - echo "FAIL!" - echo "Endianess checking failed" + printf "FAIL!\n" + printf "Endianess checking failed\n" exit; else ./fake @@ -173,179 +186,179 @@ else ARCH=le CXXFLAGS="$CXXFLAGS -DARCH_LE" CFLAGS="$CFLAGS -DARCH_LE" - echo "Little Endian" + printf "Little Endian\n" else ARCH=be CXXFLAGS="$CXXFLAGS -DARCH_BE" CFLAGS="$CFLAGS -DARCH_BE" - echo "Big Endian" + printf "Big Endian\n" fi fi rm -f fake -echo -n "Checking for -lexpat... " -echo "int main() { return 0; }" > build_check.c +printf "Checking for -lexpat... " +printf "int main() { return 0; }\n" > build_check.c $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_EXPAT=no - echo "no" + printf "no\n" else CHECK_EXPAT=yes - echo "yes" + printf "yes\n" fi rm -f fake -echo -n "Checking for -lfbclient... " +printf "Checking for -lfbclient... " $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_FBCLIENT=no - echo "no" + printf "no\n" else CHECK_FBCLIENT=yes - echo "yes" + printf "yes\n" fi rm -f fake -echo -n "Checking for mysql_config... " +printf "Checking for mysql_config... " MYSQL_VERSION=`mysql_config --version 2> /dev/null` if [ $? != 0 ] then - echo "no"; - echo -n "Checking for -lmysqlclient... " + printf "no\n"; + printf "Checking for -lmysqlclient... " $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else CHECK_MYSQLCLIENT=yes - echo "yes" + printf "yes\n" fi rm -f fake else - echo "yes" - echo -n "Checking for mysql_config --cflags... " + printf "yes\n" + printf "Checking for mysql_config --cflags... " MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null` if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else - echo "[$MYSQL_CFLAGS]" - echo -n "Checking for mysql_config --libs_r... " + printf "[$MYSQL_CFLAGS]\n" + printf "Checking for mysql_config --libs_r... " MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null` if [ $? != 0 ] then CHECK_MYSQLCLIENT=no - echo "no" + printf "no\n" else CHECK_MYSQLCLIENT=yes - echo "[$MYSQL_LDFLAGS]" + printf "[$MYSQL_LDFLAGS]\n" fi fi fi -echo -n "Checking for pg_config... " +printf "Checking for pg_config... " PG_VERSION=`pg_config --version 2> /dev/null` if [ $? != 0 ] then - echo "no"; - echo -n "Checking for -lpq... " + printf "no\n"; + printf "Checking for -lpq... " $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else CHECK_PQ=yes - echo "yes" + printf "yes\n" fi rm -f fake else - echo "yes"; - echo -n "Checking for pg_config --includedir... " + printf "yes\n"; + printf "Checking for pg_config --includedir... " PG_CFLAGS=`pg_config --includedir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else - echo "[$PG_CFLAGS]" - echo -n "Checking for pg_config --libdir... " + printf "[$PG_CFLAGS]\n" + printf "Checking for pg_config --libdir... " PG_LDFLAGS=`pg_config --libdir 2> /dev/null` if [ $? != 0 ] then CHECK_PQ=no - echo "no" + printf "no\n" else CHECK_PQ=yes - echo "[$PG_LDFLAGS]" + printf "[$PG_LDFLAGS]\n" fi fi fi -echo -n "Checking for xmlrpc-c-config... " +printf "Checking for xmlrpc-c-config... " XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null` if [ $? != 0 ] then - echo "no"; - echo -n "Checking for -lxmlrpc... " + printf "no\n"; + printf "Checking for -lxmlrpc... " $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_XMLRPC=no - echo "no" + printf "no\n" else CHECK_XMLRPC=yes - echo "yes" + printf "yes\n" fi rm -f fake elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ] then - echo "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)"; + printf "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)\n"; CHECK_XMLRPC=no else - echo "yes (version $XMLRPCC_VERSION)"; - echo -n "Checking for xmlrpc-c-config --cflags... " + printf "yes (version $XMLRPCC_VERSION)\n"; + printf "Checking for xmlrpc-c-config --cflags... " XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null` if [ $? != 0 ] then CHECK_XMLRPC=no - echo "no" + printf "no\n" else - echo "[$XMLRPC_CFLAGS]" - echo -n "Checking for xmlrpc-c-config --libs... " + printf "[$XMLRPC_CFLAGS]\n" + printf "Checking for xmlrpc-c-config --libs... " XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null` if [ $? != 0 ] then CHECK_XMLRPC=no - echo "no" + printf "no\n" else CHECK_XMLRPC=yes - echo "[$XMLRPC_LDFLAGS]" + printf "[$XMLRPC_LDFLAGS]\n" fi fi fi if [ "$OS" = "linux" ] then - echo -n "Checking for linux/netfilter_ipv4/ip_queue.h... " - echo "#include " > build_check.c - echo "#include " >> build_check.c - echo "int main() { return 0; }" >> build_check.c + printf "Checking for linux/netfilter_ipv4/ip_queue.h... " + printf "#include \n" > build_check.c + printf "#include \n" >> build_check.c + printf "int main() { return 0; }\n" >> build_check.c $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null if [ $? != 0 ] then CHECK_IP_QUEUE_H=no - echo "no" + printf "no\n" else CHECK_IP_QUEUE_H=yes DEFS="$DEFS -DHAS_IP_QUEUE_H" PLUGINS="$PLUGINS capture/ipq_linux" - echo "yes" + printf "yes\n" fi rm -f fake fi @@ -354,7 +367,7 @@ rm -f build_check.c if [ "$CHECK_EXPAT" != "yes" ] then - echo "-lexpat not found!" + printf "-lexpat not found!\n" exit 1 fi @@ -384,45 +397,45 @@ then configuration/rpcconfig" fi -echo "OS=$OS" > $CONFFILE -echo "STG_TIME=yes" >> $CONFFILE -echo "DEBUG=$DEBUG" >> $CONFFILE -echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE -echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE -echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE -echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE -echo "DIR_MOD=\$(DIR_BUILD)/modules" >> $CONFFILE -echo "DIR_PLUGINS=\$(DIR_BUILD)/plugins" >> $CONFFILE -echo "ARCH=$ARCH" >> $CONFFILE -echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE -echo "CHECK_FBCLIENT=$CHECK_FBCLIENT" >> $CONFFILE -echo "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT" >> $CONFFILE -echo "CHECK_PQ=$CHECK_PQ" >> $CONFFILE -echo "CHECK_XMLRPC=$CHECK_XMLRPC" >> $CONFFILE -echo "DEFS=$DEFS" >> $CONFFILE -echo -n "STG_LIBS=" >> $CONFFILE +printf "OS=$OS\n" > $CONFFILE +printf "STG_TIME=yes\n" >> $CONFFILE +printf "DEBUG=$DEBUG\n" >> $CONFFILE +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 "DEFS=$DEFS\n" >> $CONFFILE +printf "STG_LIBS=" >> $CONFFILE for lib in $STG_LIBS do - echo -n "$lib " >> $CONFFILE + printf "$lib " >> $CONFFILE done -echo "" >> $CONFFILE -echo -n "PLUGINS=" >> $CONFFILE +printf "\n" >> $CONFFILE +printf "PLUGINS=" >> $CONFFILE for plugin in $PLUGINS do - echo -n "$plugin " >> $CONFFILE + printf "$plugin " >> $CONFFILE done -echo "" >> $CONFFILE -echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE -echo "CFLAGS=$CFLAGS" >> $CONFFILE -echo "LDFLAGS=$LDFLAGS" >> $CONFFILE -echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE -echo "PREFIX=$PREFIX" >> $CONFFILE -echo "BIN_MODE=$BIN_MODE" >> $CONFFILE -echo "DATA_MODE=$DATA_MODE" >> $CONFFILE -echo "DIR_MODE=$DIR_MODE" >> $CONFFILE -echo "OWNER=$OWNER" >> $CONFFILE -echo "VAR_DIR=$VAR_DIR" >> $CONFFILE -echo "ETC_DIR=$ETC_DIR" >> $CONFFILE +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 @@ -430,5 +443,5 @@ if [ "$1" != "debug" ] then $MAKE $MAKEOPTS else - echo -e "\n\n\nDebug build. Type $MAKE explicitly" + printf "\n\n\nDebug build. Type $MAKE explicitly\n" fi diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index b7bb91f5..7cc8eccc 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -106,7 +106,7 @@ else } } //----------------------------------------------------------------------------- -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings) #else int StartScriptExecuter(char *, int msgKey, int * msgID, SETTINGS_IMPL * settings) @@ -151,7 +151,7 @@ switch (executerPid) case 0: delete settings; -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) Executer(*msgID, executerPid, procName); #else Executer(*msgID, executerPid); @@ -160,7 +160,7 @@ switch (executerPid) default: if (executersPid.empty()) { -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) Executer(*msgID, executerPid, NULL); #else Executer(*msgID, executerPid); diff --git a/projects/stargazer/plugins/Makefile.in b/projects/stargazer/plugins/Makefile.in index 70954a2a..dd1e124a 100644 --- a/projects/stargazer/plugins/Makefile.in +++ b/projects/stargazer/plugins/Makefile.in @@ -9,18 +9,23 @@ OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS)))) LN = ln STGLIBS_INCS = $(addprefix -I ../../../../../stglibs/,$(addsuffix .lib/include,$(STGLIBS))) -STGLIBS_LIBS = $(addprefix -L ../../../../../stglibs/,$(addsuffix .lib,$(STGLIBS))) +STGLIBS_PATHS = $(addprefix -L ../../../../../stglibs/,$(addsuffix .lib,$(STGLIBS))) -LIBS += $(addprefix -lstg,$(STGLIBS)) +STGLIBS_LIBS = $(addprefix -lstg,$(STGLIBS)) CXXFLAGS += -fPIC $(STGLIBS_INCS) CFLAGS += -fPIC $(STGLIBS_INCS) + +ifneq ($(OS),darwin) LDFLAGS += -shared -Wl,-rpath,$(PREFIX)/usr/lib/stg +else +LDFLAGS += -dynamiclib -undefined suppress -flat_namespace -Wl,-rpath,$(PREFIX)/usr/lib/stg +endif all: $(PROG) $(PROG): $(OBJS) - $(CXX) $^ $(STGLIBS_LIBS) $(LIBS) $(LDFLAGS) -o $(PROG) + $(CXX) $^ $(STGLIBS_PATHS) $(STGLIBS_LIBS) $(LIBS) $(LDFLAGS) -o $(PROG) $(LN) -fs "`pwd`/$(PROG)" $(DIR_MOD)/$(PROG) clean: diff --git a/projects/stargazer/plugins/authorization/ao/Makefile b/projects/stargazer/plugins/authorization/ao/Makefile index 1a7697e3..0e356aa1 100644 --- a/projects/stargazer/plugins/authorization/ao/Makefile +++ b/projects/stargazer/plugins/authorization/ao/Makefile @@ -8,10 +8,10 @@ PROG = mod_auth_ao.so SRCS = ./ao.cpp -STGLIBS = common \ +STGLIBS = scriptexecuter \ logger \ locker \ - scriptexecuter + common include ../../Makefile.in diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp index 5177330e..72e7f73b 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp @@ -279,7 +279,7 @@ do if (bd->fd < 0) { errorStr = "Can't capture packets. Open bpf device for " + bd->iface + " error."; - logger("Cannot open device for interface '%s': %s", bd->iface, strerror(errno)); + logger("Cannot open device for interface '%s': %s", bd->iface.c_str(), strerror(errno)); printfd(__FILE__, "Cannot open BPF device\n"); return -1; } @@ -289,7 +289,7 @@ strncpy(ifr.ifr_name, bd->iface.c_str(), sizeof(ifr.ifr_name)); if (ioctl(bd->fd, BIOCSBLEN, (caddr_t)&l) < 0) { errorStr = bd->iface + " BIOCSBLEN " + std::string(strerror(errno)); - logger("ioctl (BIOCSBLEN) error for interface '%s': %s", db->iface, strerror(errno)); + logger("ioctl (BIOCSBLEN) error for interface '%s': %s", bd->iface.c_str(), strerror(errno)); printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str()); return -1; } @@ -297,7 +297,7 @@ if (ioctl(bd->fd, BIOCSBLEN, (caddr_t)&l) < 0) if (ioctl(bd->fd, BIOCSETIF, (caddr_t)&ifr) < 0) { errorStr = bd->iface + " BIOCSETIF " + std::string(strerror(errno)); - logger("ioctl (BIOCSETIF) error for interface '%s': %s", db->iface, strerror(errno)); + logger("ioctl (BIOCSETIF) error for interface '%s': %s", bd->iface.c_str(), strerror(errno)); printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str()); return -1; } @@ -305,7 +305,7 @@ if (ioctl(bd->fd, BIOCSETIF, (caddr_t)&ifr) < 0) if (ioctl(bd->fd, BIOCIMMEDIATE, &im) < 0) { errorStr = bd->iface + " BIOCIMMEDIATE " + std::string(strerror(errno)); - logger("ioctl (BIOCIMMEDIATE) error for interface '%s': %s", db->iface, strerror(errno)); + logger("ioctl (BIOCIMMEDIATE) error for interface '%s': %s", bd->iface.c_str(), strerror(errno)); printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str()); return -1; } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp index e84e9a0e..dca87fbe 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp @@ -473,5 +473,11 @@ xmlrpc_c::methodPtr const methodGetOnlinIPsPtr(new METHOD_GET_ONLINE_IPS( users )); rpcRegistry.addMethod("stargazer.get_online_ips", methodGetOnlinIPsPtr); + +xmlrpc_c::methodPtr const methodGetUserAuthByPtr(new METHOD_GET_USER_AUTH_BY( + this, + users + )); +rpcRegistry.addMethod("stargazer.get_user_auth_by", methodGetUserAuthByPtr); } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp index 665a04f4..89c41587 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp @@ -161,6 +161,18 @@ if ((it = structVal.find("ips")) != structVal.end()) { USER_IPS ips; ips = StrToIPS(xmlrpc_c::value_string(it->second)); + + for (size_t i = 0; i < ips.Count(); ++i) + { + CONST_USER_PTR user; + uint32_t ip = ips[i].ip; + if (users.IsIPInUse(ip, login, &user)) + { + printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str()); + return true; + } + } + if (!ptr->GetProperty().ips.Set(ips, admin, login, diff --git a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.h b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.h index 83f70b5c..4e1dd796 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.h +++ b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.h @@ -14,8 +14,9 @@ class TARIFFS; class USER_HELPER { public: - USER_HELPER(USER_PTR & p) - : ptr(p) + USER_HELPER(USER_PTR & p, USERS & us) + : ptr(p), + users(us) { } @@ -28,6 +29,7 @@ public: TARIFFS * tariffs); private: USER_PTR & ptr; + USERS & users; }; #endif diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp index 5b39cf1e..5adbf441 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp @@ -39,7 +39,7 @@ if (users->FindByName(login, &u)) return; } -USER_HELPER uhelper(u); +USER_HELPER uhelper(u, *users); if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd) { @@ -172,7 +172,7 @@ while (1) xmlrpc_c::value info; - USER_HELPER uhelper(u); + USER_HELPER uhelper(u, *users); uhelper.GetUserInfo(&info, hidePassword); @@ -216,7 +216,7 @@ if (users->FindByName(login, &u)) return; } -USER_HELPER uhelper(u); +USER_HELPER uhelper(u, *users); if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd) { @@ -509,3 +509,36 @@ ipm.mask = htonl(0xffFFffFF << (32 - ipm.mask)); return false; } + +void METHOD_GET_USER_AUTH_BY::execute(xmlrpc_c::paramList const & paramList, + xmlrpc_c::value * const retvalPtr) +{ +std::string cookie = paramList.getString(0); +std::string login = paramList.getString(1); +paramList.verifyEnd(2); + +std::map structVal; +ADMIN_INFO adminInfo; + +if (config->GetAdminInfo(cookie, &adminInfo)) + { + structVal["result"] = xmlrpc_c::value_boolean(false); + *retvalPtr = xmlrpc_c::value_struct(structVal); + return; + } + +USER_PTR u; + +if (users->FindByName(login, &u)) + { + structVal["result"] = xmlrpc_c::value_boolean(false); + *retvalPtr = xmlrpc_c::value_struct(structVal); + return; + } + +std::vector list(u->GetAuthorizers()); +std::vector authList; +for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + authList.push_back(xmlrpc_c::value_string(*it)); +*retvalPtr = xmlrpc_c::value_array(authList); +} diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.h b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.h index 413e9aaf..d1ec33a4 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.h +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.h @@ -229,4 +229,24 @@ private: bool ParseNet(const std::string & net, IP_MASK & ipm) const; }; +class METHOD_GET_USER_AUTH_BY : public xmlrpc_c::method { +public: + METHOD_GET_USER_AUTH_BY(RPC_CONFIG * c, + USERS * u) + : config(c), + users(u) + { + } + + void execute(xmlrpc_c::paramList const & paramList, + xmlrpc_c::value * const retvalP); + +private: + METHOD_GET_USER_AUTH_BY(const METHOD_GET_ONLINE_IPS & rvalue); + METHOD_GET_USER_AUTH_BY & operator=(const METHOD_GET_ONLINE_IPS & rvalue); + + RPC_CONFIG * config; + USERS * users; +}; + #endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/Makefile b/projects/stargazer/plugins/configuration/sgconfig/Makefile index b6f4938a..1b59f5cf 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/Makefile +++ b/projects/stargazer/plugins/configuration/sgconfig/Makefile @@ -11,7 +11,9 @@ SRCS = ./stgconfig.cpp \ ./configproto.cpp \ ./parser.cpp \ ./parser_tariff.cpp \ - ./parser_admin.cpp + ./parser_admin.cpp \ + ./parser_auth_by.cpp \ + ./parser_user_info.cpp LIBS += -lexpat \ $(LIB_THREAD) diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index 22facc61..ec3e3ee3 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -28,11 +28,10 @@ $Author: faust $ */ +#include "configproto.h" #include -#include "configproto.h" - //----------------------------------------------------------------------------- void ParseXMLStart(void *data, const char *el, const char **attr) { @@ -87,39 +86,15 @@ else } //----------------------------------------------------------------------------- CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l) - : answerList(), - requestList(), - adminIP(0), - adminLogin(), - adminPassword(), + : adminIP(0), port(0), - thrReciveSendConf(), nonstop(true), state(0), currAdmin(NULL), logger(l), listenSocket(-1), - parserGetServInfo(), - parserGetUsers(), - parserGetUser(), - parserChgUser(), - parserAddUser(), - parserDelUser(), - parserCheckUser(), - parserSendMessage(), - parserGetAdmins(), - parserAddAdmin(), - parserDelAdmin(), - parserChgAdmin(), - parserGetTariffs(), - parserAddTariff(), - parserDelTariff(), - parserChgTariff(), admins(NULL), - currParser(NULL), - dataParser(), - xmlParser(), - errorStr() + currParser(NULL) { dataParser.push_back(&parserGetServInfo); @@ -130,6 +105,8 @@ dataParser.push_back(&parserAddUser); dataParser.push_back(&parserDelUser); dataParser.push_back(&parserCheckUser); dataParser.push_back(&parserSendMessage); +dataParser.push_back(&parserAuthBy); +dataParser.push_back(&parserUserInfo); dataParser.push_back(&parserGetTariffs); dataParser.push_back(&parserAddTariff); @@ -210,51 +187,34 @@ while(nonstop) return 0; } //----------------------------------------------------------------------------- -void CONFIGPROTO::SetPort(uint16_t p) -{ -port = p; -} -//----------------------------------------------------------------------------- void CONFIGPROTO::SetAdmins(ADMINS * a) { admins = a; for (size_t i = 0; i < dataParser.size(); i++) - { dataParser[i]->SetAdmins(a); - } - } //----------------------------------------------------------------------------- void CONFIGPROTO::SetUsers(USERS * u) { for (size_t i = 0; i < dataParser.size(); i++) - { dataParser[i]->SetUsers(u); - } - } //----------------------------------------------------------------------------- void CONFIGPROTO::SetTariffs(TARIFFS * t) { for (size_t i = 0; i < dataParser.size(); i++) - { dataParser[i]->SetTariffs(t); - } } //----------------------------------------------------------------------------- void CONFIGPROTO::SetStore(STORE * s) { for (size_t i = 0; i < dataParser.size(); i++) - { dataParser[i]->SetStore(s); - } } //----------------------------------------------------------------------------- void CONFIGPROTO::SetStgSettings(const SETTINGS * s) { for (size_t i = 0; i < dataParser.size(); i++) - { dataParser[i]->SetStgSettings(s); - } } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.h b/projects/stargazer/plugins/configuration/sgconfig/configproto.h index b8b01f02..4adba097 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -28,12 +28,8 @@ #ifndef CONFIGPROTO_H #define CONFIGPROTO_H -#include -#include -#include - -#include -#include +#include "parser_auth_by.h" +#include "parser_user_info.h" #include "stg/users.h" #include "stg/admins.h" @@ -41,6 +37,13 @@ #include "stg/logger.h" #include "parser.h" +#include +#include + +#include +#include +#include + #define STG_HEADER "SG04" #define OK_HEADER "OKHD" #define ERR_HEADER "ERHD" @@ -55,7 +58,7 @@ public: CONFIGPROTO(PLUGIN_LOGGER & l); ~CONFIGPROTO(); - void SetPort(uint16_t port); + void SetPort(uint16_t p) { port = p; } void SetAdmins(ADMINS * a); void SetUsers(USERS * u); void SetTariffs(TARIFFS * t); @@ -107,6 +110,8 @@ private: PARSER_DEL_USER parserDelUser; PARSER_CHECK_USER parserCheckUser; PARSER_SEND_MESSAGE parserSendMessage; + PARSER_AUTH_BY parserAuthBy; + PARSER_USER_INFO parserUserInfo; PARSER_GET_ADMINS parserGetAdmins; PARSER_ADD_ADMIN parserAddAdmin; diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index 1f7757d2..7deab3d0 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -133,8 +133,7 @@ answerList->erase(answerList->begin(), answerList->end()); if (users->FindByName(login, &u)) { - s = ""; - answerList->push_back(s); + answerList->push_back(""); return; } @@ -286,6 +285,13 @@ answerList->push_back(s); strprintf(&s, "", u->GetProperty().creditExpire.Get()); answerList->push_back(s); +s = ""; +std::vector list(u->GetAuthorizers()); +for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + s += ""; +s += ""; +answerList->push_back(s); + strprintf(&s, ""); answerList->push_back(s); } @@ -1025,9 +1031,23 @@ if (check && alwaysOnline && !onlyOneIP) { printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n"); GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin->GetLogStr().c_str()); + res = -1; return -1; } +for (size_t i = 0; i < ucr->ips.const_data().Count(); ++i) + { + CONST_USER_PTR user; + uint32_t ip = ucr->ips.const_data().operator[](i).ip; + if (users->IsIPInUse(ip, login, &user)) + { + printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str()); + GetStgLogger()("%s trying to assign an IP %s to '%s' that is currently in use by '%s'", currAdmin->GetLogStr().c_str(), inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str()); + res = -1; + return -1; + } + } + if (!ucr->ips.res_empty()) if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store)) res = -1; @@ -1342,11 +1362,11 @@ switch (result) break; case res_params_error: printfd(__FILE__, "res_params_error\n"); - answerList->push_back(""); + answerList->push_back(""); break; case res_unknown: printfd(__FILE__, "res_unknown\n"); - answerList->push_back(""); + answerList->push_back(""); break; default: printfd(__FILE__, "res_default\n"); @@ -1400,30 +1420,17 @@ else answerList->push_back(""); } //----------------------------------------------------------------------------- -/*void PARSERDELUSER::CreateAnswer(char * mes) -{ -//answerList->clear(); -answerList->erase(answerList->begin(), answerList->end()); - -char str[255]; -sprintf(str, "", mes); -answerList->push_back(str); -}*/ -//----------------------------------------------------------------------------- // CHECK USER // //----------------------------------------------------------------------------- int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr) { -result = false; - if (strcasecmp(el, "CheckUser") == 0) { if (attr[0] == NULL || attr[1] == NULL || attr[2] == NULL || attr[3] == NULL) { - result = false; - CreateAnswer(); + CreateAnswer("Invalid parameters."); printfd(__FILE__, "PARSER_CHECK_USER - attr err\n"); return 0; } @@ -1431,22 +1438,19 @@ if (strcasecmp(el, "CheckUser") == 0) USER_PTR user; if (users->FindByName(attr[1], &user)) { - result = false; - CreateAnswer(); + CreateAnswer("User not found."); printfd(__FILE__, "PARSER_CHECK_USER - login err\n"); return 0; } if (strcmp(user->GetProperty().password.Get().c_str(), attr[3])) { - result = false; - CreateAnswer(); + CreateAnswer("Wrong password."); printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n"); return 0; } - result = true; - CreateAnswer(); + CreateAnswer(NULL); return 0; } return -1; @@ -1461,12 +1465,12 @@ if (strcasecmp(el, "CheckUser") == 0) return -1; } //----------------------------------------------------------------------------- -void PARSER_CHECK_USER::CreateAnswer() +void PARSER_CHECK_USER::CreateAnswer(const char * error) { -if (result) - answerList->push_back(""); +if (error) + answerList->push_back(std::string(""); else - answerList->push_back(""); + answerList->push_back(""); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.h b/projects/stargazer/plugins/configuration/sgconfig/parser.h index df3d7155..e76d8f4c 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.h @@ -7,10 +7,6 @@ #ifndef PARSER_H #define PARSER_H -#include -#include -#include - #include "stg/resetable.h" #include "stg/const.h" #include "stg/store.h" @@ -19,6 +15,10 @@ #include "stg/users.h" #include "stg/message.h" +#include +#include +#include + class TARIFFS; class SETTINGS; @@ -39,18 +39,18 @@ public: virtual ~BASE_PARSER() {} virtual int ParseStart(void *data, const char *el, const char **attr) = 0; virtual int ParseEnd(void *data, const char *el) = 0; - virtual void CreateAnswer() = 0; - virtual void SetAnswerList(std::list * ansList) { answerList = ansList; } - virtual void SetUsers(USERS * u) { users = u; } - virtual void SetAdmins(ADMINS * a) { admins = a; } - virtual void SetTariffs(TARIFFS * t) { tariffs = t; } - virtual void SetStore(STORE * s) { store = s; } - virtual void SetStgSettings(const SETTINGS * s) { settings = s; } + void SetAnswerList(std::list * ansList) { answerList = ansList; } + + void SetUsers(USERS * u) { users = u; } + void SetAdmins(ADMINS * a) { admins = a; } + void SetTariffs(TARIFFS * t) { tariffs = t; } + void SetStore(STORE * s) { store = s; } + void SetStgSettings(const SETTINGS * s) { settings = s; } - virtual void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; } - virtual std::string & GetStrError() { return strError; } - virtual void Reset() { answerList->clear(); depth = 0; } + void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; } + std::string & GetStrError() { return strError; } + void Reset() { answerList->clear(); depth = 0; } protected: BASE_PARSER(const BASE_PARSER & rvalue); @@ -71,6 +71,8 @@ class PARSER_GET_ADMINS: public BASE_PARSER { public: int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); + +private: void CreateAnswer(); }; //----------------------------------------------------------------------------- @@ -79,9 +81,11 @@ public: PARSER_ADD_ADMIN() : BASE_PARSER(), adminToAdd() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: std::string adminToAdd; + + void CreateAnswer(); }; //----------------------------------------------------------------------------- class PARSER_DEL_ADMIN: public BASE_PARSER { @@ -89,10 +93,12 @@ public: PARSER_DEL_ADMIN() : BASE_PARSER(), adminToDel() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: - int CheckAttr(const char **attr); std::string adminToDel; + + int CheckAttr(const char **attr); + void CreateAnswer(); }; //----------------------------------------------------------------------------- class PARSER_CHG_ADMIN: public BASE_PARSER { @@ -100,17 +106,21 @@ public: PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: RESETABLE login; RESETABLE password; RESETABLE privAsString; + + void CreateAnswer(); }; //----------------------------------------------------------------------------- class PARSER_GET_SERVER_INFO: public BASE_PARSER { public: int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); + +private: void CreateAnswer(); }; //----------------------------------------------------------------------------- @@ -120,9 +130,11 @@ public: ~PARSER_GET_USER() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: std::string login; + + void CreateAnswer(); }; //----------------------------------------------------------------------------- class PARSER_GET_USERS: public BASE_PARSER { @@ -130,16 +142,20 @@ public: PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: time_t lastUserUpdateTime; bool lastUpdateFound; + + void CreateAnswer(); }; //----------------------------------------------------------------------------- class PARSER_GET_TARIFFS: public BASE_PARSER { public: int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); + +private: void CreateAnswer(); }; //----------------------------------------------------------------------------- @@ -148,9 +164,11 @@ public: PARSER_ADD_TARIFF() : BASE_PARSER(), tariffToAdd() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: std::string tariffToAdd; + + void CreateAnswer(); }; //----------------------------------------------------------------------------- class PARSER_DEL_TARIFF: public BASE_PARSER { @@ -158,9 +176,11 @@ public: PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: std::string tariffToDel; + + void CreateAnswer(); }; //----------------------------------------------------------------------------- class PARSER_CHG_TARIFF: public BASE_PARSER { @@ -168,14 +188,15 @@ public: PARSER_CHG_TARIFF() : BASE_PARSER(), td() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: + TARIFF_DATA_RES td; + int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params); int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params); int CheckTariffData(); int AplayChanges(); - - TARIFF_DATA_RES td; + void CreateAnswer(); }; //-----------------------------------------------------------------------------/ class PARSER_ADD_USER: public BASE_PARSER { @@ -184,11 +205,13 @@ public: ~PARSER_ADD_USER() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); - void Reset(); + private: - int CheckUserData(); std::string login; + + int CheckUserData(); + void CreateAnswer(); + void Reset(); }; //----------------------------------------------------------------------------- class PARSER_CHG_USER: public BASE_PARSER { @@ -197,15 +220,8 @@ public: ~PARSER_CHG_USER(); int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); - void Reset(); -private: - PARSER_CHG_USER(const PARSER_CHG_USER & rvalue); - PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue); - - std::string EncChar2String(const char *); - int AplayChanges(); +private: USER_STAT_RES * usr; USER_CONF_RES * ucr; RESETABLE * upr; @@ -214,6 +230,14 @@ private: std::string login; bool cashMustBeAdded; int res; + + PARSER_CHG_USER(const PARSER_CHG_USER & rvalue); + PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue); + + std::string EncChar2String(const char *); + int AplayChanges(); + void CreateAnswer(); + void Reset(); }; //----------------------------------------------------------------------------- class PARSER_DEL_USER: public BASE_PARSER { @@ -221,24 +245,25 @@ public: PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); private: + int res; + USER * u; + PARSER_DEL_USER(const PARSER_DEL_USER & rvalue); PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue); - int res; - USER * u; + void CreateAnswer(); }; //----------------------------------------------------------------------------- class PARSER_CHECK_USER: public BASE_PARSER { public: - PARSER_CHECK_USER() : BASE_PARSER(), result(false) {} + PARSER_CHECK_USER() : BASE_PARSER() {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); + private: - bool result; + void CreateAnswer(const char * error); }; //----------------------------------------------------------------------------- class PARSER_SEND_MESSAGE: public BASE_PARSER { @@ -246,18 +271,19 @@ public: PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {} int ParseStart(void *data, const char *el, const char **attr); int ParseEnd(void *data, const char *el); - void CreateAnswer(); -private: - PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue); - PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue); - - int ParseLogins(const char * logins); +private: enum {res_ok, res_params_error, res_unknown}; std::vector logins; int result; STG_MSG msg; USER * u; + + PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue); + PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue); + + int ParseLogins(const char * logins); + void CreateAnswer(); }; //----------------------------------------------------------------------------- #endif //PARSER_H diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp new file mode 100644 index 00000000..54921571 --- /dev/null +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp @@ -0,0 +1,46 @@ +#include "parser_auth_by.h" + +int PARSER_AUTH_BY::ParseStart(void * /*data*/, const char *el, const char **attr) +{ +if (strcasecmp(el, "GetUserAuthBy") == 0) + { + if (attr[0] && attr[1]) + login = attr[1]; + else + { + login.erase(login.begin(), login.end()); + return -1; + } + return 0; + } +return -1; +} + +int PARSER_AUTH_BY::ParseEnd(void * /*data*/, const char *el) +{ +if (strcasecmp(el, "GetUserAuthBy") == 0) + { + CreateAnswer(); + return 0; + } +return -1; +} + +void PARSER_AUTH_BY::CreateAnswer() +{ +answerList->erase(answerList->begin(), answerList->end()); + +USER_PTR u; +if (users->FindByName(login, &u)) + { + answerList->push_back(""); + return; + } + +std::string s = ""; +std::vector list(u->GetAuthorizers()); +for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + s += ""; +s += ""; +answerList->push_back(s); +} diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h new file mode 100644 index 00000000..c34586c9 --- /dev/null +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h @@ -0,0 +1,18 @@ +#ifndef __STG_PARSER_AUTH_BY_H__ +#define __STG_PARSER_AUTH_BY_H__ + +#include + +#include "parser.h" + +class PARSER_AUTH_BY : public BASE_PARSER { +public: + int ParseStart(void *data, const char *el, const char **attr); + int ParseEnd(void *data, const char *el); + void CreateAnswer(); + +private: + std::string login; +}; + +#endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp new file mode 100644 index 00000000..72c3c6ec --- /dev/null +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp @@ -0,0 +1,70 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#include "parser_user_info.h" + +#include "stg/user.h" +#include "stg/common.h" + +#include // strcasecmp + +int PARSER_USER_INFO::ParseStart(void * /*data*/, const char *el, const char **attr) +{ +login.clear(); +if (strcasecmp(el, "GetUserInfo") != 0) + return -1; + +if (!attr[0] || !attr[1] || strcasecmp(attr[0], "login") != 0) + return -1; + +login = attr[1]; +return 0; +} + +int PARSER_USER_INFO::ParseEnd(void * /*data*/, const char *el) +{ +if (strcasecmp(el, "GetUserInfo") != 0) + return -1; + +CreateAnswer(); +return 0; +} + +void PARSER_USER_INFO::CreateAnswer() +{ +answerList->clear(); + +CONST_USER_PTR u; +if (users->FindByName(login, &u)) + { + answerList->push_back(""); + return; + } + +std::string s = "GetAuthorizedModificationTime()) + "\"" + + " lastDisconnectTime=\"" + x2str(u->GetConnectedModificationTime()) + "\"" + + " connected=\"" + (u->GetConnected() ? "true" : "false") + "\"" + + " lastDisconnectReason=\"" + u->GetLastDisconnectReason() + "\">"; +std::vector list(u->GetAuthorizers()); +for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + s += ""; +s += ""; +answerList->push_back(s); +} diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h new file mode 100644 index 00000000..ccd1d94e --- /dev/null +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef __STG_PARSER_USER_INFO_H__ +#define __STG_PARSER_USER_INFO_H__ + +#include "parser.h" + +#include + +class PARSER_USER_INFO : public BASE_PARSER { +public: + int ParseStart(void *data, const char *el, const char **attr); + int ParseEnd(void *data, const char *el); + +private: + std::string login; + + void CreateAnswer(); +}; + +#endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp index 9b448f6c..6ca2b3da 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp @@ -26,14 +26,15 @@ * *******************************************************************/ -#include // close +#include "configproto.h" + +#include "stg/blowfish.h" #include #include #include // snprintf -#include "stg/blowfish.h" -#include "configproto.h" +#include // close #ifndef ENODATA // FreeBSD 4.* - suxx @@ -147,13 +148,11 @@ while (nonstop) &outerAddrLen); if (!nonstop) - { break; - } if (outerSocket < 0) { - logger("accept error: %s", strerror(errno)); + logger("accept error: %s", strerror(errno)); printfd(__FILE__, "accept failed\n"); continue; } @@ -256,8 +255,8 @@ while (pos < stgHdrLen) ssize_t ret = recv(sock, &buf[pos], static_cast(stgHdrLen) - static_cast(pos), 0); if (ret <= 0) { - if (ret < 0) - logger("recv error: %s", strerror(errno)); + if (ret < 0) + logger("recv error: %s", strerror(errno)); state = confHdr; return -1; } @@ -319,7 +318,7 @@ while (pos < ADM_LOGIN_LEN) { if (ret <= 0) { // Error in network - logger("recv error: %s", strerror(errno)); + logger("recv error: %s", strerror(errno)); state = confHdr; return ENODATA; } @@ -370,7 +369,7 @@ while (pos < ADM_LOGIN_LEN) { // Network error printfd(__FILE__, "recv error: '%s'\n", strerror(errno)); - logger("recv error: %s", strerror(errno)); + logger("recv error: %s", strerror(errno)); state = confHdr; return ENODATA; } @@ -389,9 +388,7 @@ EnDecodeInit(currAdmin->GetPassword().c_str(), ADM_PASSWD_LEN, &ctx); char login[ADM_LOGIN_LEN + 1]; for (size_t i = 0; i < ADM_LOGIN_LEN / 8; i++) - { DecodeString(login + i * 8, loginS + i * 8, &ctx); - } if (currAdmin == admins->GetNoAdmin()) { @@ -456,7 +453,7 @@ while (1) if (ret < 0) { // Network error - logger("recv error: %s", strerror(errno)); + logger("recv error: %s", strerror(errno)); printfd(__FILE__, "recv error: '%s'\n", strerror(errno)); return -1; } @@ -514,11 +511,8 @@ while (li != answerList.end()) if (n % 8 == 0) { EncodeString(buffS, buff, &ctx); - int ret = static_cast(send(sock, buffS, 8, 0)); - if (ret < 0) - { + if (send(sock, buffS, 8, 0) < 0) return -1; - } } } k = 0;// new node diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index d5fab222..fb8cb57c 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -324,6 +324,9 @@ std::for_each(authorizedUsers.begin(), authorizedUsers.end(), UpdateRouter(*this)); +logger("%s reloaded successfully.", rsSettings.GetMapFileName().c_str()); +printfd(__FILE__, "REMOTE_SCRIPT::Reload() %s reloaded successfully.\n"); + return 0; } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 31b91bb3..09cb4636 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -278,6 +278,11 @@ if (Stop()) return -1; if (Start()) return -1; +if (!needReconnect) + { + printfd(__FILE__, "SMUX reconnected succesfully.\n"); + logger("Reconnected successfully."); + } return 0; } diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp index 8b21907e..e48fd0d8 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp @@ -337,7 +337,7 @@ try st->Execute(); st->Prepare("insert into tb_allowed_ip (fk_user, ip, mask) values (?, ?, ?)"); - for(i = 0; i < conf.ips.Count(); i++) + for(size_t i = 0; i < conf.ips.Count(); i++) { st->Set(1, uid); st->Set(2, (int32_t)conf.ips[i].ip); diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index dd2fbbab..5e2d8ae6 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -38,16 +38,15 @@ * */ -#include -#include -#include - -#include +#include "postgresql_store.h" #include "stg/module_settings.h" #include "stg/plugin_creator.h" -#include "postgresql_store_utils.h" -#include "postgresql_store.h" + +#include + +#include +#include namespace { @@ -93,37 +92,25 @@ pthread_mutex_destroy(&mutex); int POSTGRESQL_STORE::ParseSettings() { std::vector::iterator i; -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 (s == "server") - { + std::string param(ToLower(i->param)); + if (param == "server") server = *(i->value.begin()); - } - if (s == "database") - { + else if (param == "database") database = *(i->value.begin()); - } - if (s == "user") - { + else if (param == "user") user = *(i->value.begin()); - } - if (s == "password") - { + else if (param == "password") password = *(i->value.begin()); - } - if (s == "retries") - { + else if (param == "retries") if (str2x(*(i->value.begin()), 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_users.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp index 4cd64418..0722cc4c 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp @@ -1525,7 +1525,7 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) PQclear(result); -for (int i = 0; i < ips.Count(); ++i) +for (size_t i = 0; i < ips.Count(); ++i) { std::ostringstream query; query << "INSERT INTO tb_allowed_ip " diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp index f5dec89f..ef705053 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp @@ -26,14 +26,15 @@ * */ +#include "postgresql_store.h" + +#include "stg/common.h" + #include #include #include -#include "stg/common.h" -#include "postgresql_store.h" - extern volatile time_t stgTime; int POSTGRESQL_STORE::StartTransaction() const @@ -93,10 +94,10 @@ int error = 0; char * buf = new char[(value.length() << 1) + 1]; PQescapeStringConn(connection, - buf, - value.c_str(), - value.length(), - &error); + buf, + value.c_str(), + value.length(), + &error); if (error) { @@ -114,7 +115,6 @@ return 0; std::string POSTGRESQL_STORE::Int2TS(time_t ts) const { -char buf[32]; struct tm brokenTime; brokenTime.tm_wday = 0; @@ -123,6 +123,7 @@ brokenTime.tm_isdst = 0; gmtime_r(&ts, &brokenTime); +char buf[32]; strftime(buf, 32, "%Y-%m-%d %H:%M:%S", &brokenTime); return buf; @@ -160,8 +161,6 @@ if (year) else { time_t curTime = stgTime; - /*time(&curTime);*/ - localtime_r(&curTime, &brokenTime); } @@ -173,4 +172,3 @@ strftime(buf, 32, "%Y-%m-%d", &brokenTime); date = buf; } - diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h deleted file mode 100644 index 4ffa6ecf..00000000 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h +++ /dev/null @@ -1,11 +0,0 @@ -#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/traffcounter_impl.cpp b/projects/stargazer/traffcounter_impl.cpp index 17a786ff..fce47595 100644 --- a/projects/stargazer/traffcounter_impl.cpp +++ b/projects/stargazer/traffcounter_impl.cpp @@ -738,8 +738,8 @@ if (ReadRules(true)) FreeRules(); ReadRules(); -printfd(__FILE__, "TRAFFCOUNTER_IMPL::Reload() - Reload rules successfull.\n"); -WriteServLog("TRAFFCOUNTER: Reload rules successfull."); +printfd(__FILE__, "TRAFFCOUNTER_IMPL::Reload() - Reloaded rules successfully.\n"); +WriteServLog("TRAFFCOUNTER: Reloaded rules successfully."); return 0; } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 52731b7b..13cf0b77 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -32,12 +32,9 @@ #define _GNU_SOURCE #endif -#include -#include // access - -#include -#include -#include +#include "user_impl.h" +#include "settings_impl.h" +#include "stg_timer.h" #include "stg/users.h" #include "stg/common.h" @@ -45,9 +42,16 @@ #include "stg/tariff.h" #include "stg/tariffs.h" #include "stg/admin.h" -#include "user_impl.h" -#include "settings_impl.h" -#include "stg_timer.h" + +#include +#include + +#include +#include +#include + +#include +#include // access #ifdef USE_ABSTRACT_SETTINGS USER_IMPL::USER_IMPL(const SETTINGS * s, @@ -60,12 +64,9 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), lastScanMessages(0), - login(), id(0), __connected(0), connected(__connected), - enabledDirs(), - userIDGenerator(), __currIP(0), currIP(__currIP), lastIPForDisconnect(0), @@ -74,11 +75,8 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, store(st), tariffs(t), tariff(NULL), - traffStat(), - traffStatSaved(), settings(s), - authorizedBy(), - messages(), + authorizedModificationTime(0), deleted(false), lastWriteStat(0), lastWriteDetailedStat(0), @@ -116,14 +114,10 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, userdata7(property.userdata7), userdata8(property.userdata8), userdata9(property.userdata9), - sessionUpload(), - sessionDownload(), passiveNotifier(this), tariffNotifier(this), cashNotifier(this), - ipNotifier(this), - mutex(), - errorStr() + ipNotifier(this) { password = "*_EMPTY_PASSWORD_*"; tariffName = NO_TARIFF_NAME; @@ -153,12 +147,9 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), lastScanMessages(0), - login(), id(0), __connected(0), connected(__connected), - enabledDirs(), - userIDGenerator(), __currIP(0), currIP(__currIP), lastIPForDisconnect(0), @@ -167,11 +158,8 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, store(st), tariffs(t), tariff(NULL), - traffStat(), - traffStatSaved(), settings(s), - authorizedBy(), - messages(), + authorizedModificationTime(0), deleted(false), lastWriteStat(0), lastWriteDetailedStat(0), @@ -209,15 +197,11 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, userdata7(property.userdata7), userdata8(property.userdata8), userdata9(property.userdata9), - sessionUpload(), - sessionDownload(), passiveNotifier(this), disabledNotifier(this), tariffNotifier(this), cashNotifier(this), - ipNotifier(this), - mutex(), - errorStr() + ipNotifier(this) { password = "*_EMPTY_PASSWORD_*"; tariffName = NO_TARIFF_NAME; @@ -248,7 +232,6 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u) id(u.id), __connected(0), connected(__connected), - enabledDirs(), userIDGenerator(u.userIDGenerator), __currIP(u.__currIP), currIP(__currIP), @@ -261,7 +244,7 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u) traffStat(u.traffStat), traffStatSaved(u.traffStatSaved), settings(u.settings), - authorizedBy(), + authorizedModificationTime(u.authorizedModificationTime), messages(u.messages), deleted(u.deleted), lastWriteStat(u.lastWriteStat), @@ -306,9 +289,7 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u) disabledNotifier(this), tariffNotifier(this), cashNotifier(this), - ipNotifier(this), - mutex(), - errorStr() + ipNotifier(this) { if (&u == this) return; @@ -535,6 +516,8 @@ else } } +if (authorizedBy.empty()) + authorizedModificationTime = stgTime; authorizedBy.insert(auth); ScanMessage(); @@ -553,6 +536,7 @@ if (!authorizedBy.erase(auth)) if (authorizedBy.empty()) { + authorizedModificationTime = stgTime; lastIPForDisconnect = currIP; currIP = 0; // DelUser in traffcounter return; @@ -566,6 +550,13 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); return authorizedBy.find(auth) != authorizedBy.end(); } //----------------------------------------------------------------------------- +std::vector USER_IMPL::GetAuthorizers() const +{ + std::vector list; + std::transform(authorizedBy.begin(), authorizedBy.end(), std::back_inserter(list), std::mem_fun(&AUTH::GetVersion)); + return list; +} +//----------------------------------------------------------------------------- void USER_IMPL::Connect(bool fakeConnect) { /* @@ -641,6 +632,7 @@ if (!lastIPForDisconnect) if (!fakeDisconnect) { + lastDisconnectReason = reason; std::string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect"; if (access(scriptOnDisonnect.c_str(), X_OK) == 0) diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index d240f0c8..26ff58fc 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -27,14 +27,7 @@ #ifndef USER_IMPL_H #define USER_IMPL_H -#include -#include -#include -#include - #include "stg/user.h" -#include "stg/os_int.h" -#include "stg/const.h" #include "stg/user_stat.h" #include "stg/user_conf.h" #include "stg/user_ips.h" @@ -42,6 +35,15 @@ #include "stg/auth.h" #include "stg/message.h" #include "stg/noncopyable.h" +#include "stg/os_int.h" +#include "stg/const.h" + +#include +#include +#include +#include + +#include //----------------------------------------------------------------------------- class TARIFF; @@ -182,10 +184,13 @@ public: bool GetConnected() const { return connected; } time_t GetConnectedModificationTime() const { return connected.ModificationTime(); } + const std::string & GetLastDisconnectReason() const { return lastDisconnectReason; } int GetAuthorized() const { return static_cast(authorizedBy.size()); } + time_t GetAuthorizedModificationTime() const { return authorizedModificationTime; } int Authorize(uint32_t ip, uint32_t enabledDirs, const AUTH * auth); void Unauthorize(const AUTH * auth); bool IsAuthorizedBy(const AUTH * auth) const; + std::vector GetAuthorizers() const; int AddMessage(STG_MSG * msg); @@ -240,6 +245,7 @@ private: int id; bool __connected; USER_PROPERTY connected; + std::string lastDisconnectReason; bool enabledDirs[DIR_NUM]; @@ -268,6 +274,7 @@ private: #endif std::set authorizedBy; + time_t authorizedModificationTime; std::list messages; diff --git a/projects/stargazer/users_impl.cpp b/projects/stargazer/users_impl.cpp index 17d1e4f7..5b88e685 100644 --- a/projects/stargazer/users_impl.cpp +++ b/projects/stargazer/users_impl.cpp @@ -88,23 +88,39 @@ pthread_mutex_destroy(&mutex); //----------------------------------------------------------------------------- int USERS_IMPL::FindByNameNonLock(const std::string & login, user_iter * user) { -std::map::iterator iter; -iter = loginIndex.find(login); -if (iter != loginIndex.end()) - { - if (user) - *user = iter->second; - return 0; - } -return -1; +const std::map::const_iterator iter(loginIndex.find(login)); +if (iter == loginIndex.end()) + return -1; +if (user) + *user = iter->second; +return 0; +} +//----------------------------------------------------------------------------- +int USERS_IMPL::FindByNameNonLock(const std::string & login, const_user_iter * user) const +{ +const std::map::const_iterator iter(loginIndex.find(login)); +if (iter == loginIndex.end()) + return -1; +if (user) + *user = iter->second; +return 0; } //----------------------------------------------------------------------------- int USERS_IMPL::FindByName(const std::string & login, USER_PTR * user) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); user_iter u; -int res = FindByNameNonLock(login, &u); -if (res) +if (FindByNameNonLock(login, &u)) + return -1; +*user = &(*u); +return 0; +} +//----------------------------------------------------------------------------- +int USERS_IMPL::FindByName(const std::string & login, CONST_USER_PTR * user) const +{ +STG_LOCKER lock(&mutex, __FILE__, __LINE__); +const_user_iter u; +if (FindByNameNonLock(login, &u)) return -1; *user = &(*u); return 0; @@ -695,6 +711,26 @@ std::map::const_iterator it(ipIndex.find(ip)); return it != ipIndex.end(); } //----------------------------------------------------------------------------- +bool USERS_IMPL::IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const +{ +STG_LOCKER lock(&mutex, __FILE__, __LINE__); +std::list::const_iterator iter; +iter = users.begin(); +while (iter != users.end()) + { + if (iter->GetLogin() != login && + !iter->GetProperty().ips.Get().IsAnyIP() && + iter->GetProperty().ips.Get().IsIPInIPS(ip)) + { + if (user != NULL) + *user = &(*iter); + return true; + } + ++iter; + } +return false; +} +//----------------------------------------------------------------------------- void USERS_IMPL::AddNotifierUserAdd(NOTIFIER_BASE * n) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); diff --git a/projects/stargazer/users_impl.h b/projects/stargazer/users_impl.h index 69f3fbae..b9d2b22d 100644 --- a/projects/stargazer/users_impl.h +++ b/projects/stargazer/users_impl.h @@ -75,6 +75,7 @@ public: virtual ~USERS_IMPL(); int FindByName(const std::string & login, USER_PTR * user); + int FindByName(const std::string & login, CONST_USER_PTR * user) const; bool TariffInUse(const std::string & tariffName) const; @@ -103,6 +104,7 @@ public: int FindByIPIdx(uint32_t ip, USER_PTR * user) const; int FindByIPIdx(uint32_t ip, USER_IMPL ** user) const; bool IsIPInIndex(uint32_t ip) const; + bool IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const; int OpenSearch(); int SearchNext(int handler, USER_PTR * user); @@ -121,6 +123,7 @@ private: bool FindByIPIdx(uint32_t ip, user_iter & iter) const; int FindByNameNonLock(const std::string & login, user_iter * user); + int FindByNameNonLock(const std::string & login, const_user_iter * user) const; void RealDelUser(); void ProcessActions(); diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 787b813d..763df532 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -819,6 +819,22 @@ std::string & Trim(std::string & val) return TrimR(TrimL(val)); } //--------------------------------------------------------------------------- +std::string ToLower(const std::string & value) +{ + std::string res; + for (std::string::size_type pos = 0; pos < value.length(); ++pos) + res += tolower(value[pos]); + return res; +} +//--------------------------------------------------------------------------- +std::string ToUpper(const std::string & value) +{ + std::string res; + for (std::string::size_type pos = 0; pos < value.length(); ++pos) + res += toupper(value[pos]); + return res; +} +//--------------------------------------------------------------------------- #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 80d32aba..6c71289b 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -96,6 +96,9 @@ std::string & TrimL(std::string & val); std::string & TrimR(std::string & val); std::string & Trim(std::string & val); +std::string ToLower(const std::string & value); +std::string ToUpper(const std::string & value); + std::string IconvString(const std::string & source, const std::string & from, const std::string & to); int ParseInt(const std::string & str, int * val); @@ -112,7 +115,11 @@ int str2x(const std::string & str, varT & x); template const std::string & x2str(varT x, std::string & s); template +std::string x2str(varT x) { std::string s; return x2str(x, s); } +template const std::string & unsigned2str(varT x, std::string & s); +template +std::string unsigned2str(varT x) { std::string s; return unsigned2str(x, s); } //----------------------------------------------------------------------------- template @@ -148,7 +155,7 @@ int str2x(const std::string & str, varT & x) x += str[i] - '0'; } - x*= minus; + x *= minus; return 0; } diff --git a/stglibs/crypto.lib/include/stg/blowfish.h b/stglibs/crypto.lib/include/stg/blowfish.h index a8800d75..c9983340 100644 --- a/stglibs/crypto.lib/include/stg/blowfish.h +++ b/stglibs/crypto.lib/include/stg/blowfish.h @@ -13,7 +13,10 @@ #define MAXKEYBYTES 56 /* 448 bits */ #ifdef __cplusplus +#include // size_t extern "C" { +#else +#include // size_t #endif typedef struct { diff --git a/stglibs/pinger.lib/include/stg/pinger.h b/stglibs/pinger.lib/include/stg/pinger.h index b25f6847..91608dbb 100644 --- a/stglibs/pinger.lib/include/stg/pinger.h +++ b/stglibs/pinger.lib/include/stg/pinger.h @@ -18,7 +18,7 @@ #include #endif -#if defined (FREE_BSD) || defined (FREE_BSD5) +#if defined (FREE_BSD) || defined (FREE_BSD5) || defined(DARWIN) #include #include #include diff --git a/stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h b/stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h index 41b02a2f..947669c7 100644 --- a/stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h +++ b/stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h @@ -6,7 +6,7 @@ extern "C" { #endif int ScriptExec(const char * str); -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) void Executer(int msgID, pid_t pid, char * procName); #else void Executer(int msgID, pid_t pid); diff --git a/stglibs/scriptexecuter.lib/scriptexecuter.c b/stglibs/scriptexecuter.lib/scriptexecuter.c index bf45105a..728082ae 100644 --- a/stglibs/scriptexecuter.lib/scriptexecuter.c +++ b/stglibs/scriptexecuter.lib/scriptexecuter.c @@ -40,7 +40,7 @@ if (msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0) < 0) return 0; } //----------------------------------------------------------------------------- -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) void Executer(int msgID, pid_t pid, char * procName) #else void Executer(int msgID, pid_t pid) @@ -56,7 +56,7 @@ if (pid) return; nonstop = 1; -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) memset(procName, 0, strlen(procName)); strcpy(procName, "stg-exec"); #else diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index e3bfa762..aaf3e117 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -8,14 +8,21 @@ STGLIBS = -lstgcommon \ -lstgcrypto LIBS = -lexpat -SRCS = netunit.cpp \ - parser.cpp \ +SRCS = netunit.cpp \ + property_parsers.cpp \ + parser_auth_by.cpp \ + parser_server_info.cpp \ + parser_check_user.cpp \ + parser_get_user.cpp \ + parser_get_users.cpp \ + parser_chg_user.cpp \ + parser_send_message.cpp \ servconf.cpp INCS = servconf.h \ netunit.h LIB_INCS = -I ../common.lib/include \ - -I ../crypto.lib/include + -I ../crypto.lib/include include ../Makefile.in diff --git a/stglibs/srvconf.lib/include/stg/netunit.h b/stglibs/srvconf.lib/include/stg/netunit.h index e288df86..d40b4c6a 100644 --- a/stglibs/srvconf.lib/include/stg/netunit.h +++ b/stglibs/srvconf.lib/include/stg/netunit.h @@ -27,14 +27,14 @@ #ifndef NetUnitH #define NetUnitH -#include -#include -#include +#include "stg/blowfish.h" #include #include -#include "stg/blowfish.h" +#include +#include +#include #define STG_HEADER "SG04" #define OK_HEADER "OKHD" diff --git a/stglibs/srvconf.lib/include/stg/parser.h b/stglibs/srvconf.lib/include/stg/parser.h new file mode 100644 index 00000000..f8c3af0c --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser.h @@ -0,0 +1,33 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_H__ + +class PARSER +{ +public: + virtual ~PARSER() {} + virtual int ParseStart(const char *el, const char **attr) = 0; + virtual void ParseEnd(const char *el) = 0; +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/parser_auth_by.h b/stglibs/srvconf.lib/include/stg/parser_auth_by.h new file mode 100644 index 00000000..00c997d5 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_auth_by.h @@ -0,0 +1,48 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__ + +#include "parser.h" + +#include +#include + +class PARSER_AUTH_BY: public PARSER +{ +public: + typedef std::vector INFO; + typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + + PARSER_AUTH_BY(); + int ParseStart(const char *el, const char **attr); + void ParseEnd(const char *el); + void SetCallback(CALLBACK f, void * data); +private: + CALLBACK callback; + void * data; + int depth; + bool parsingAnswer; + INFO info; + std::string error; +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/parser_check_user.h b/stglibs/srvconf.lib/include/stg/parser_check_user.h new file mode 100644 index 00000000..e0bea221 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_check_user.h @@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__ + +#include "parser.h" + +#include + +class PARSER_CHECK_USER: public PARSER +{ +public: + typedef int (* CALLBACK)(bool result, const std::string & reason, void * data); + + PARSER_CHECK_USER(); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); +private: + CALLBACK callback; + void * data; + int depth; + + void ParseAnswer(const char * el, const char ** attr); +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/parser_chg_user.h b/stglibs/srvconf.lib/include/stg/parser_chg_user.h new file mode 100644 index 00000000..cc6e9f18 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_chg_user.h @@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__ + +#include "parser.h" + +#include + +class PARSER_CHG_USER: public PARSER +{ +public: + typedef void (* CALLBACK)(bool result, const std::string& reason, void * data); + + PARSER_CHG_USER(); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); +private: + CALLBACK callback; + void * data; + int depth; + + void ParseAnswer(const char * el, const char ** attr); +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/parser_get_user.h b/stglibs/srvconf.lib/include/stg/parser_get_user.h new file mode 100644 index 00000000..7f6faaad --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_get_user.h @@ -0,0 +1,95 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__ + +#include "parser.h" + +#include "property_parsers.h" + +#include "stg/os_int.h" +#include "stg/const.h" + +#include + +#include + +class PARSER_GET_USER: public PARSER +{ +public: + struct STAT + { + long long su[DIR_NUM]; + long long sd[DIR_NUM]; + long long mu[DIR_NUM]; + long long md[DIR_NUM]; + double freeMb; + }; + + struct INFO + { + std::string login; + std::string password; + double cash; + double credit; + time_t creditExpire; + double lastCash; + double prepaidTraff; + int down; + int passive; + int disableDetailStat; + int connected; + int alwaysOnline; + uint32_t ip; + std::string ips; + std::string tariff; + std::string group; + std::string note; + std::string email; + std::string name; + std::string address; + std::string phone; + STAT stat; + std::string userData[USERDATA_NUM]; + }; + + typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + + PARSER_GET_USER(); + virtual ~PARSER_GET_USER(); + int ParseStart(const char *el, const char **attr); + void ParseEnd(const char *el); + void SetCallback(CALLBACK f, void * data); +private: + PROPERTY_PARSERS propertyParsers; + CALLBACK callback; + void * data; + INFO info; + int depth; + bool parsingAnswer; + std::string error; + + void ParseUser(const char *el, const char **attr); + void ParseUserParams(const char *el, const char **attr); +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/parser_get_users.h b/stglibs/srvconf.lib/include/stg/parser_get_users.h new file mode 100644 index 00000000..35fcd126 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_get_users.h @@ -0,0 +1,57 @@ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__ + +#include "parser.h" + +#include "parser_get_user.h" + +#include + +class PARSER_GET_USERS: public PARSER +{ +public: + typedef std::vector INFO; + typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + + PARSER_GET_USERS(); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); +private: + CALLBACK callback; + void * data; + PARSER_GET_USER userParser; + INFO info; + int depth; + bool parsingAnswer; + std::string error; + + void AddUser(const PARSER_GET_USER::INFO & userInfo); + void SetError(const std::string & e) { error = e; } + + static void UserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * data); +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/parser_send_message.h b/stglibs/srvconf.lib/include/stg/parser_send_message.h new file mode 100644 index 00000000..9b3ca5ef --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_send_message.h @@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__ + +#include "parser.h" + +#include + +class PARSER_SEND_MESSAGE: public PARSER +{ +public: + typedef void (* CALLBACK)(bool result, const std::string& reason, void * data); + + PARSER_SEND_MESSAGE(); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); +private: + CALLBACK callback; + void * data; + int depth; + + void ParseAnswer(const char * el, const char ** attr); +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/parser_server_info.h b/stglibs/srvconf.lib/include/stg/parser_server_info.h new file mode 100644 index 00000000..ff31ae71 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_server_info.h @@ -0,0 +1,61 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ + +#include "parser.h" + +#include "property_parsers.h" +#include "stg/const.h" + +#include + +class PARSER_SERVER_INFO: public PARSER +{ +public: + struct INFO + { + std::string version; + int tariffNum; + int tariffType; + int usersNum; + std::string uname; + int dirNum; + std::string dirName[DIR_NUM]; + }; + typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + + PARSER_SERVER_INFO(); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); +private: + PROPERTY_PARSERS propertyParsers; + CALLBACK callback; + void * data; + int depth; + bool parsingAnswer; + INFO info; + std::string error; +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/property_parsers.h b/stglibs/srvconf.lib/include/stg/property_parsers.h new file mode 100644 index 00000000..d1e6a893 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/property_parsers.h @@ -0,0 +1,98 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__ +#define __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__ + +#include +#include + +#include "stg/common.h" + +class BASE_PROPERTY_PARSER +{ + public: + virtual ~BASE_PROPERTY_PARSER() {} + virtual bool Parse(const char ** attr) = 0; +}; + +template +class PROPERTY_PARSER : public BASE_PROPERTY_PARSER +{ + public: + typedef bool (* FUNC)(const char **, T &); + PROPERTY_PARSER(T & v, FUNC f) : value(v), func(f) {} + virtual bool Parse(const char ** attr) { return func(attr, value); } + private: + T & value; + FUNC func; +}; + +typedef std::map PROPERTY_PARSERS; + +bool CheckValue(const char ** attr); + +template +inline +bool GetValue(const char ** attr, T & value) +{ +if (CheckValue(attr)) + if (str2x(attr[1], value) < 0) + return false; +return true; +} + +template <> +inline +bool GetValue(const char ** attr, std::string & value) +{ +if (!CheckValue(attr)) + return false; +value = attr[1]; +return true; +} + +template <> +inline +bool GetValue(const char ** attr, double & value) +{ +if (CheckValue(attr)) + if (strtodouble2(attr[1], value)) + return false; +return true; +} + +bool GetEncodedValue(const char ** attr, std::string & value); + +bool GetIPValue(const char ** attr, uint32_t& value); + +template +void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER::FUNC & func = GetValue); + +template +inline +void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER::FUNC & func) +{ + parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER(value, func))); +} + +bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr); + +#endif diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index 67c2f248..b422f708 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -27,203 +27,36 @@ #ifndef SERVCONF_H #define SERVCONF_H -#include +#include "netunit.h" -#include -#include +#include "stg/parser_auth_by.h" +#include "stg/parser_server_info.h" +#include "stg/parser_check_user.h" +#include "stg/parser_get_user.h" +#include "stg/parser_get_users.h" +#include "stg/parser_chg_user.h" +#include "stg/parser_send_message.h" #include "stg/os_int.h" #include "stg/const.h" -#include "netunit.h" -void Start(void *data, const char *el, const char **attr); -void End(void *data, const char *el); +#include +#include +#include + +#include + +void Start(void * data, const char * el, const char ** attr); +void End(void * data, const char * el); #define MAX_ERR_STR_LEN (64) #define IP_STRING_LEN (255) -#define UNAME_LEN (256) -#define SERV_VER_LEN (64) -#define DIRNAME_LEN (16) -//----------------------------------------------------------------------------- -struct STAT -{ - long long su[DIR_NUM]; - long long sd[DIR_NUM]; - long long mu[DIR_NUM]; - long long md[DIR_NUM]; - double freeMb; -}; -//----------------------------------------------------------------------------- -struct SERVERINFO -{ - std::string version; - int tariffNum; - int tariffType; - int usersNum; - std::string uname; - int dirNum; - std::string dirName[DIR_NUM]; -}; -//----------------------------------------------------------------------------- -struct USERDATA -{ - std::string login; - std::string password; - double cash; - double credit; - time_t creditExpire; - double lastCash; - double prepaidTraff; - int down; - int passive; - int disableDetailStat; - int connected; - int alwaysOnline; - uint32_t ip; - std::string ips; - std::string tariff; - std::string iface; - std::string group; - std::string note; - std::string email; - std::string name; - std::string address; - std::string phone; - STAT stat; - std::string userData[USERDATA_NUM]; - - struct USERDATA * next; -}; -//----------------------------------------------------------------------------- -typedef void(*RecvUserDataCb_t)(USERDATA * ud, void * data); -typedef void(*RecvServerInfoDataCb_t)(SERVERINFO * si, void * data); -typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data); -typedef int(*RecvCheckUserCb_t)(const char * answer, void * data); -typedef int(*RecvSendMessageCb_t)(const char * answer, void * data); -//----------------------------------------------------------------------------- struct ADMINDATA { char login[ADM_LOGIN_LEN]; }; //----------------------------------------------------------------------------- -class PARSER -{ -public: - PARSER() {} - virtual ~PARSER() {} - virtual int ParseStart(const char *el, const char **attr) = 0; - virtual void ParseEnd(const char *el) = 0; -}; -//----------------------------------------------------------------------------- -class PARSER_CHG_USER: public PARSER -{ -public: - PARSER_CHG_USER(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); - void SetChgUserRecvCb(RecvChgUserCb_t, void * data); -private: - RecvChgUserCb_t RecvChgUserCb; - void * chgUserCbData; - int depth; - bool error; -}; -//----------------------------------------------------------------------------- -class PARSER_CHECK_USER: public PARSER -{ -public: - PARSER_CHECK_USER(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); - void SetCheckUserRecvCb(RecvCheckUserCb_t, void * data); -private: - RecvCheckUserCb_t RecvCheckUserCb; - void * checkUserCbData; - int depth; - bool error; -}; -//----------------------------------------------------------------------------- -class PARSER_GET_USERS: public PARSER -{ -public: - PARSER_GET_USERS(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseUsers(const char *el, const char **attr); - void ParseUser(const char *el, const char **attr); - void ParseUserParams(const char *el, const char **attr); - void ParseUserLoadStat(const char * el, const char ** attr); - void SetUserDataRecvCb(RecvUserDataCb_t, void * data); -private: - RecvUserDataCb_t RecvUserDataCb; - void * userDataCb; - USERDATA user; - int depth; - bool error; -}; -//----------------------------------------------------------------------------- -class PARSER_GET_USER: public PARSER -{ -public: - PARSER_GET_USER(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseUsers(const char *el, const char **attr); - void ParseUser(const char *el, const char **attr); - void ParseUserParams(const char *el, const char **attr); - void ParseUserLoadStat(const char * el, const char ** attr); - void SetUserDataRecvCb(RecvUserDataCb_t, void * data); -private: - RecvUserDataCb_t RecvUserDataCb; - void * userDataCb; - USERDATA user; - int depth; - bool error; -}; -//----------------------------------------------------------------------------- -class PARSER_GET_SERVER_INFO: public PARSER -{ -public: - PARSER_GET_SERVER_INFO(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseServerInfo(const char *el, const char **attr); - bool GetError(); - void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data); -private: - void ParseUname(const char ** attr); - void ParseServerVersion(const char ** attr); - void ParseUsersNum(const char ** attr); - void ParseTariffsNum(const char ** attr); - void ParseTariffType(const char ** attr); - void ParseDirNum(const char **attr); - void ParseDirName(const char **attr, int d); - - RecvServerInfoDataCb_t RecvServerInfoDataCb; - void * serverInfoDataCb; - int depth; - bool error; - SERVERINFO serverInfo; -}; -//----------------------------------------------------------------------------- -class PARSER_SEND_MESSAGE: public PARSER -{ -public: - PARSER_SEND_MESSAGE(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); - void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data); -private: - RecvSendMessageCb_t RecvSendMessageCb; - void * sendMessageCbData; - int depth; - bool error; -}; -//----------------------------------------------------------------------------- class SERVCONF { public: @@ -234,57 +67,43 @@ public: void SetAdmLogin(const char * login); void SetAdmPassword(const char * password); - void SetUserDataRecvCb(RecvUserDataCb_t, void * data); - void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data); - void SetChgUserCb(RecvChgUserCb_t, void * data); - void SetCheckUserCb(RecvCheckUserCb_t, void * data); - void SetGetUserDataRecvCb(RecvUserDataCb_t, void * data); - void SetSendMessageCb(RecvSendMessageCb_t, void * data); + void SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data); + void SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data); + void SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data); + void SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data); + void SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data); + void SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data); + void SetSendMessageCallback(PARSER_SEND_MESSAGE::CALLBACK f, void * data); int GetUsers(); int GetUser(const char * login); int ChgUser(const char * request); - // TODO: Remove this shit! - int MsgUser(const char * request); - int SendMessage(const char * login, const char * message, int prio); - int GetServerInfo(); + int AuthBy(const char * login); + int SendMessage(const char * request); + int ServerInfo(); int CheckUser(const char * login, const char * password); const std::string & GetStrError() const; - int GetError(); - int Start(const char *el, const char **attr); - void End(const char *el); + int Start(const char * el, const char ** attr); + void End(const char * el); private: PARSER * currParser; PARSER_GET_USERS parserGetUsers; PARSER_GET_USER parserGetUser; - PARSER_GET_SERVER_INFO parserServerInfo; + PARSER_AUTH_BY parserAuthBy; + PARSER_SERVER_INFO parserServerInfo; PARSER_CHG_USER parserChgUser; PARSER_CHECK_USER parserCheckUser; PARSER_SEND_MESSAGE parserSendMessage; NETTRANSACT nt; - int parseDepth; std::string errorMsg; - int error; XML_Parser parser; - RecvUserDataCb_t RecvUserDataCb; - RecvUserDataCb_t RecvGetUserDataCb; - RecvServerInfoDataCb_t RecvServerInfoDataCb; - RecvChgUserCb_t RecvChgUserCb; - RecvCheckUserCb_t RecvCheckUserCb; - RecvSendMessageCb_t RecvSendMessageCb; - - void * getUserDataDataCb; - void * getUsersDataDataCb; - void * getServerInfoDataCb; - void * chgUserDataCb; - void * checkUserDataCb; - void * sendMessageDataCb; + int Exec(const char * request); friend int AnsRecv(void * data, std::list * list); }; diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index 9a653d5b..aaba3df6 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -25,15 +25,17 @@ */ //--------------------------------------------------------------------------- -#include -#include -#include + +#include "stg/netunit.h" +#include "stg/common.h" #include +#include #include -#include "stg/netunit.h" -#include "stg/common.h" +#include +#include +#include //--------------------------------------------------------------------------- @@ -212,6 +214,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_HEADER), 0); if (ret <= 0) { + printf("Receive header answer error: '%s'\n", strerror(errno)); errorMsg = RECV_HEADER_ANSWER_ERROR; return st_recv_fail; } @@ -261,6 +264,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_LOGIN), 0); if (ret <= 0) { + printf("Receive login answer error: '%s'\n", strerror(errno)); errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -318,6 +322,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_LOGINS), 0); if (ret <= 0) { + printf("Receive secret login answer error: '%s'\n", strerror(errno)); errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -425,6 +430,7 @@ while (1) ret = recv(outerSocket, &bufferS[n++], 1, 0); if (ret <= 0) { + printf("Receive data error: '%s'\n", strerror(errno)); close(outerSocket); errorMsg = RECV_DATA_ANSWER_ERROR; return st_recv_fail; @@ -436,17 +442,18 @@ while (1) Decrypt(buffer, bufferS, &ctx); buffer[ENC_MSG_LEN] = 0; + printf("%s", buffer); + answerList.push_back(buffer); for (int j = 0; j < ENC_MSG_LEN; j++) { if (buffer[j] == 0) { + printf("\n"); if (RxCallBack) if (st_ok != RxCallBack(dataRxCallBack, &answerList)) - { return st_xml_parse_error; - } return st_ok; } } diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp deleted file mode 100644 index a87266eb..00000000 --- a/stglibs/srvconf.lib/parser.cpp +++ /dev/null @@ -1,955 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.18 $ - $Date: 2010/08/04 00:40:00 $ - $Author: faust $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "stg/common.h" -#include "stg/const.h" -#include "stg/servconf.h" - -using namespace std; - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_GET_USERS::PARSER_GET_USERS() - : RecvUserDataCb(NULL), - userDataCb(NULL), - user(), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_GET_USERS::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - ParseUsers(el, attr); - } - -if (depth == 2) - { - ParseUser(el, attr); - } - -if (depth == 3) - { - ParseUserParams(el, attr); - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_GET_USERS::ParseEnd(const char *) -{ -depth--; -if (depth == 1) - { - if (RecvUserDataCb) - { - RecvUserDataCb(&user, userDataCb); - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_USERS::ParseUsers(const char * el, const char ** attr) -{ -if (strcasecmp(el, "users") == 0) - { - if (*attr != NULL) - return; - return; - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_USERS::ParseUser(const char * el, const char ** attr) -{ -if (el && attr[0]) - { - if (strcasecmp(el, "user") != 0) - { - return; - } - - if (strcasecmp(attr[0], "login") != 0) - { - return; - } - user.login = attr[1]; - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_USERS::ParseUserParams(const char * el, const char ** attr) -{ -if (strcasecmp(el, "cash") == 0) - { - if (strtodouble2(attr[1], user.cash) < 0) - { - return; - } - } - -/*if (strcasecmp(el, "LastCash") == 0) - { - if (strtodouble2(attr[1], user.lastCash) < 0) - { - MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0); - return 0; - } - }*/ - -/*if (strcasecmp(el, "LastActivityTime") == 0) - { - if (strtol(attr[1], user.lastActivityTime) < 0) - { - MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0); - return 0; - } - }*/ - - -/*if (strcasecmp(el, "LastTimeCash") == 0) - { - if (strtol(attr[1], user.lastTimeCash) < 0) - { - MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0); - return 0; - } - }*/ - -/*if (strcasecmp(el, "CashExpire") == 0) - { - if (strtol(attr[1], user.cashExpire) < 0) - { - MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0); - return 0; - } - }*/ - -if (strcasecmp(el, "credit") == 0) - { - if (strtodouble2(attr[1], user.credit) < 0) - { - return; - } - } - -if (strcasecmp(el, "creditExpire") == 0) - { - if (str2x(attr[1], user.creditExpire) < 0) - { - return; - } - } - -/*if (strcasecmp(el, "freemb") == 0) - { - if (strtodouble2(attr[1], user.freeMb) < 0) - { - MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0); - return 0; - } - }*/ - -if (strcasecmp(el, "down") == 0) - { - if (str2x(attr[1], user.down) < 0) - { - return; - } - } - -if (strcasecmp(el, "passive") == 0) - { - if (str2x(attr[1], user.passive) < 0) - { - return; - } - } - -if (strcasecmp(el, "disableDetailStat") == 0) - { - if (str2x(attr[1], user.disableDetailStat) < 0) - { - return; - } - } - - -if (strcasecmp(el, "status") == 0) - { - if (str2x(attr[1], user.connected) < 0) - { - return; - } - } - -if (strcasecmp(el, "aonline") == 0) - { - if (str2x(attr[1], user.alwaysOnline) < 0) - { - return; - } - } - -if (strcasecmp(el, "currip") == 0) - { - user.ip = inet_addr(attr[1]); - } - -if (strcasecmp(el, "ip") == 0) - { - user.ips = attr[1]; - } - - -if (strcasecmp(el, "tariff") == 0) - { - //KOIToWin(user.tariff, *(attr+1), TARIFF_LEN); - user.tariff = attr[1]; - return; - } - -if (strcasecmp(el, "password") == 0) - { - user.password = *(attr+1); - return; - } - -if (strcasecmp(el, "iface") == 0) - { - user.iface = attr[1]; - return; - } - -/*if (strcasecmp(el, "name") == 0) - { - / *char nameEnc[REALNM_LEN * 2 + 1]; - char name[REALNM_LEN]; - strncpy(nameEnc, attr[1], REALNM_LEN * 2 + 1); - Decode21(name, nameEnc); - KOIToWin(user.realName, name, REALNM_LEN);* / - Decode21str(user.realName, attr[1]); - return; - }*/ - -if (strcasecmp(el, "address") == 0) - { - /*char addressEnc[ADDR_LEN * 2 + 1]; - char address[ADDR_LEN]; - strncpy(addressEnc, attr[1], ADDR_LEN * 2 + 1); - Decode21(address, addressEnc); - KOIToWin(user.address, address, ADDR_LEN);*/ - Decode21str(user.address, attr[1]); - return; - } - -if (strcasecmp(el, "phone") == 0) - { - /*char phoneEnc[PHONE_LEN * 2 + 1]; - char phone[PHONE_LEN]; - strncpy(phoneEnc, attr[1], PHONE_LEN * 2 + 1); - Decode21(phone, phoneEnc); - KOIToWin(user.phone, phone, PHONE_LEN);*/ - Decode21str(user.phone, attr[1]); - return; - } - -if (strcasecmp(el, "note") == 0) - { - /*char noteEnc[NOTE_LEN * 2 + 1]; - char note[NOTE_LEN]; - strncpy(noteEnc, attr[1], NOTE_LEN * 2 + 1);*/ - //KOIToWin(user.note, note, NOTE_LEN); - //user.note = note; - Decode21str(user.note, attr[1]); - return; - } - -if (strcasecmp(el, "email") == 0) - { - /*char emailEnc[EMAIL_LEN * 2 + 1]; - char email[EMAIL_LEN]; - strncpy(emailEnc, attr[1], EMAIL_LEN * 2 + 1); - Decode21(email, emailEnc); - //KOIToWin(user.email, email, EMAIL_LEN); - user.email = email;*/ - Decode21str(user.email, attr[1]); - return; - } - -if (strcasecmp(el, "group") == 0) - { - /*char groupEnc[GROUP_LEN * 2 + 1]; - char group[GROUP_LEN]; - strncpy(groupEnc, attr[1], GROUP_LEN * 2 + 1); - Decode21(group, groupEnc); - //KOIToWin(user.group, group, GROUP_LEN); - user.group = group;*/ - Decode21str(user.group, attr[1]); - return; - } - -if (strcasecmp(el, "traff") == 0) - { - ParseUserLoadStat(el, attr); - return; - } - -} -//----------------------------------------------------------------------------- -void PARSER_GET_USERS::ParseUserLoadStat(const char *, const char ** attr) -{ -int i = 0; -char dir[6]; -while (attr[i]) - { - for (int j = 0; j < DIR_NUM; j++) - { - sprintf(dir, "MU%d", j); - if (strcasecmp(dir, attr[i]) == 0) - { - str2x(attr[i+1], user.stat.mu[j]); - break; - } - } - for (int j = 0; j < DIR_NUM; j++) - { - sprintf(dir, "MD%d", j); - if (strcasecmp(dir, attr[i]) == 0) - { - str2x(attr[i+1], user.stat.md[j]); - break; - } - } - for (int j = 0; j < DIR_NUM; j++) - { - sprintf(dir, "SU%d", j); - if (strcasecmp(dir, attr[i]) == 0) - { - str2x(attr[i+1], user.stat.su[j]); - break; - } - } - for (int j = 0; j < DIR_NUM; j++) - { - sprintf(dir, "SD%d", j); - if (strcasecmp(dir, attr[i]) == 0) - { - str2x(attr[i+1], user.stat.sd[j]); - break; - } - } - i+=2; - } -return; -} -//----------------------------------------------------------------------------- -void PARSER_GET_USERS::SetUserDataRecvCb(RecvUserDataCb_t f, void * data) -{ -RecvUserDataCb = f; -userDataCb = data; -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_GET_USER::PARSER_GET_USER() - : RecvUserDataCb(NULL), - userDataCb(NULL), - user(), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_GET_USER::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - ParseUser(el, attr); - } - -if (depth == 2) - { - ParseUserParams(el, attr); - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_GET_USER::ParseEnd(const char *) -{ -depth--; -if (depth == 0) - { - if (RecvUserDataCb) - { - RecvUserDataCb(&user, userDataCb); - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_USER::ParseUser(const char * el, const char ** attr) -{ -if (strcasecmp(el, "user") == 0) - { - if (strcasecmp(attr[1], "error") == 0) - user.login = ""; - return; - } -} -//----------------------------------------------------------------------------- -struct ParsedStringParams -{ -string * param; -string paramName; -}; -//----------------------------------------------------------------------------- -struct ParsedDoubleParams -{ -double * param; -string paramName; -}; -//----------------------------------------------------------------------------- -void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr) -{ -//printf("PARSER_GET_USER::ParseUserParams el=%s attr[1]=%s\n", el, attr[1]); - -if (strcasecmp(el, "login") == 0) - { - user.login = attr[1]; - } - - -/*if (strcasecmp(el, "LastActivityTime") == 0) - { - if (strtol(attr[1], user.lastActivityTime) < 0) - { - MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0); - return 0; - } - } - - -if (strcasecmp(el, "LastTimeCash") == 0) - { - if (strtol(attr[1], user.lastTimeCash) < 0) - { - MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0); - return 0; - } - } - -if (strcasecmp(el, "CashExpire") == 0) - { - if (strtol(attr[1], user.cashExpire) < 0) - { - MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0); - return 0; - } - } -*/ - -if (strcasecmp(el, "down") == 0) - { - if (str2x(attr[1], user.down) < 0) - { - return; - } - } - -if (strcasecmp(el, "passive") == 0) - { - if (str2x(attr[1], user.passive) < 0) - { - return; - } - } - -if (strcasecmp(el, "disableDetailStat") == 0) - { - if (str2x(attr[1], user.disableDetailStat) < 0) - { - return; - } - } - - -if (strcasecmp(el, "status") == 0) - { - if (str2x(attr[1], user.connected) < 0) - { - return; - } - } - -if (strcasecmp(el, "aonline") == 0) - { - if (str2x(attr[1], user.alwaysOnline) < 0) - { - return; - } - } - -if (strcasecmp(el, "currip") == 0) - { - user.ip = inet_addr(attr[1]); - } - -if (strcasecmp(el, "creditExpire") == 0) - { - if (str2x(attr[1], user.creditExpire) < 0) - { - return; - } - } - -for (int i = 0; i < USERDATA_NUM; i++) - { - string num; - x2str(i, num); - string udName = "UserData" + num; - if (strcasecmp(el, udName.c_str()) == 0) - { - Decode21str(user.userData[i], attr[1]); - return; - } - } - -ParsedStringParams psp[] = -{ - {&user.ips, "ip"}, - {&user.tariff, "tariff"}, - {&user.password, "password"}, - {&user.iface, "iface"}, -}; - -for (unsigned i = 0; i < sizeof(psp)/sizeof(ParsedStringParams); i++) - { - if (strcasecmp(el, psp[i].paramName.c_str()) == 0) - { - *psp[i].param = attr[1]; - return; - } - } - -ParsedStringParams pspEnc[] = -{ - {&user.note, "note"}, - {&user.email, "email"}, - {&user.group, "group"}, - {&user.name, "name"}, - {&user.address, "address"}, - {&user.phone, "phone"} -}; - -for (unsigned i = 0; i < sizeof(pspEnc)/sizeof(ParsedStringParams); i++) - { - if (strcasecmp(el, pspEnc[i].paramName.c_str()) == 0) - { - Decode21str(*pspEnc[i].param, attr[1]); - return; - } - } - -ParsedDoubleParams pdp[] = -{ - {&user.cash, "cash"}, - {&user.credit, "credit"}, - {&user.lastCash, "lastCash"}, - {&user.prepaidTraff, "freemb"}, -}; - -for (unsigned i = 0; i < sizeof(pdp)/sizeof(ParsedDoubleParams); i++) - { - if (strcasecmp(el, pdp[i].paramName.c_str()) == 0) - { - strtodouble2(attr[1], *pdp[i].param); - return; - } - } - -if (strcasecmp(el, "traff") == 0) - { - ParseUserLoadStat(el, attr); - return; - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_USER::ParseUserLoadStat(const char *, const char ** attr) -{ -int i = 0; -char dir[6]; -while (attr[i]) - { - for (int j = 0; j < DIR_NUM; j++) - { - sprintf(dir, "MU%d", j); - if (strcasecmp(dir, attr[i]) == 0) - { - str2x(attr[i+1], user.stat.mu[j]); - break; - } - } - for (int j = 0; j < DIR_NUM; j++) - { - sprintf(dir, "MD%d", j); - if (strcasecmp(dir, attr[i]) == 0) - { - str2x(attr[i+1], user.stat.md[j]); - break; - } - } - for (int j = 0; j < DIR_NUM; j++) - { - sprintf(dir, "SU%d", j); - if (strcasecmp(dir, attr[i]) == 0) - { - str2x(attr[i+1], user.stat.su[j]); - break; - } - } - for (int j = 0; j < DIR_NUM; j++) - { - sprintf(dir, "SD%d", j); - if (strcasecmp(dir, attr[i]) == 0) - { - str2x(attr[i+1], user.stat.sd[j]); - break; - } - } - i+=2; - } -return; -} -//----------------------------------------------------------------------------- -void PARSER_GET_USER::SetUserDataRecvCb(RecvUserDataCb_t f, void * data) -{ -RecvUserDataCb = f; -userDataCb = data; -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_GET_SERVER_INFO::PARSER_GET_SERVER_INFO() - : RecvServerInfoDataCb(NULL), - serverInfoDataCb(NULL), - depth(0), - error(false), - serverInfo() -{ -} -//----------------------------------------------------------------------------- -int PARSER_GET_SERVER_INFO::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "ServerInfo") != 0) - { - //printf("%s\n", el); - } - } -else - { - if (depth == 2) - { - if (strcasecmp(el, "uname") == 0) - { - ParseUname(attr); - return 0; - } - if (strcasecmp(el, "version") == 0) - { - ParseServerVersion(attr); - return 0; - } - if (strcasecmp(el, "tariff") == 0) - { - ParseTariffType(attr); - return 0; - } - if (strcasecmp(el, "dir_num") == 0) - { - ParseDirNum(attr); - return 0; - } - if (strcasecmp(el, "users_num") == 0) - { - ParseUsersNum(attr); - return 0; - } - if (strcasecmp(el, "tariff_num") == 0) - { - ParseTariffsNum(attr); - return 0; - } - - for (int j = 0; j < DIR_NUM; j++) - { - char str[16]; - sprintf(str, "dir_name_%d", j); - if (strcasecmp(el, str) == 0) - { - ParseDirName(attr, j); - } - } - - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseEnd(const char *) -{ -depth--; -if (depth == 0) - { - RecvServerInfoDataCb(&serverInfo, serverInfoDataCb); - } -} -//----------------------------------------------------------------------------- -/*void PARSER_GET_SERVER_INFO::ParseServerInfo(const char * el, const char ** attr) - { - }*/ -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data) -{ -RecvServerInfoDataCb = f; -serverInfoDataCb = data; -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseUname(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - serverInfo.uname = attr[1]; -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseServerVersion(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - serverInfo.version = attr[1]; -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseUsersNum(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - { - if (str2x(attr[1], serverInfo.usersNum) < 0) - { - serverInfo.usersNum = -1; - return; - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseTariffsNum(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - { - if (str2x(attr[1], serverInfo.tariffNum) < 0) - { - serverInfo.tariffNum = -1; - return; - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseTariffType(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - { - if (str2x(attr[1], serverInfo.tariffType) < 0) - { - serverInfo.tariffType = -1; - return; - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseDirNum(const char **attr) -{ -if (strcasecmp(*attr, "value") == 0) - { - if (str2x(attr[1], serverInfo.dirNum) < 0) - { - serverInfo.dirNum = -1; - return; - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseDirName(const char **attr, int d) -{ -if (strcmp(attr[0], "value") == 0) - { - char str[2*DIRNAME_LEN + 1]; - Decode21(str, attr[1]); - serverInfo.dirName[d] = str; - } -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_CHG_USER::PARSER_CHG_USER() - : RecvChgUserCb(NULL), - chgUserCbData(NULL), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_CHG_USER::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "SetUser") == 0) - { - ParseAnswer(el, attr); - } - else if (strcasecmp(el, "DelUser") == 0) - { - ParseAnswer(el, attr); - } - else if (strcasecmp(el, "AddUser") == 0) - { - ParseAnswer(el, attr); - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::ParseEnd(const char *) -{ -depth--; -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::ParseAnswer(const char *, const char **attr) -{ -if (RecvChgUserCb) - { - RecvChgUserCb(attr[1], chgUserCbData); - } -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::SetChgUserRecvCb(RecvChgUserCb_t f, void * data) -{ -RecvChgUserCb = f; -chgUserCbData = data; -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_CHECK_USER::PARSER_CHECK_USER() - : RecvCheckUserCb(NULL), - checkUserCbData(NULL), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_CHECK_USER::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "CheckUser") == 0) - { - //printf("el=%s attr[0]=%s attr[1]=%s\n", el, attr[0], attr[1]); - ParseAnswer(el, attr); - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_CHECK_USER::ParseEnd(const char *) -{ -depth--; -} -//----------------------------------------------------------------------------- -void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr) -{ -if (RecvCheckUserCb) - { - RecvCheckUserCb(attr[1], checkUserCbData); - } -} -//----------------------------------------------------------------------------- -void PARSER_CHECK_USER::SetCheckUserRecvCb(RecvCheckUserCb_t f, void * data) -{ -RecvCheckUserCb = f; -checkUserCbData = data; -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() - : RecvSendMessageCb(NULL), - sendMessageCbData(NULL), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_SEND_MESSAGE::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "SendMessageResult") == 0) - { - ParseAnswer(el, attr); - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::ParseEnd(const char *) -{ -depth--; -} -//----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::ParseAnswer(const char *, const char **attr) -{ -if (RecvSendMessageCb) - RecvSendMessageCb(attr[1], sendMessageCbData); -} -//----------------------------------------------------------------------------- -void PARSER_SEND_MESSAGE::SetSendMessageRecvCb(RecvSendMessageCb_t f, void * data) -{ -RecvSendMessageCb = f; -sendMessageCbData = data; -} -//----------------------------------------------------------------------------- diff --git a/stglibs/srvconf.lib/parser_auth_by.cpp b/stglibs/srvconf.lib/parser_auth_by.cpp new file mode 100644 index 00000000..06981aae --- /dev/null +++ b/stglibs/srvconf.lib/parser_auth_by.cpp @@ -0,0 +1,85 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#include "stg/parser_auth_by.h" + +#include + +#include // strcasecmp + +PARSER_AUTH_BY::PARSER_AUTH_BY() + : callback(NULL), + data(NULL), + depth(0), + parsingAnswer(false) +{ +} +//----------------------------------------------------------------------------- +int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr) +{ +depth++; +if (depth == 1) + { + if (strcasecmp(el, "AuthorizedBy") == 0) + if (attr && attr[0] && attr[1]) + { + if (strcasecmp(attr[1], "error") == 0) + { + if (attr[2] && attr[3]) + error = attr[3]; + else + error = "User not found."; + } + else + parsingAnswer = true; + } + } +else + { + if (depth == 2) + { + if (parsingAnswer && strcasecmp(el, "Auth") == 0) + { + if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "name") == 0) + info.push_back(attr[1]); + return 0; + } + } + } +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_AUTH_BY::ParseEnd(const char * /*el*/) +{ +depth--; +if (depth == 0) + { + if (callback) + callback(error.empty(), error, info, data); + info.clear(); + error.clear(); + } +} +//----------------------------------------------------------------------------- +void PARSER_AUTH_BY::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/parser_check_user.cpp b/stglibs/srvconf.lib/parser_check_user.cpp new file mode 100644 index 00000000..eed03f30 --- /dev/null +++ b/stglibs/srvconf.lib/parser_check_user.cpp @@ -0,0 +1,63 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_check_user.h" + +#include + +#include + +PARSER_CHECK_USER::PARSER_CHECK_USER() + : callback(NULL), + data(NULL), + depth(0) +{ +} +//----------------------------------------------------------------------------- +int PARSER_CHECK_USER::ParseStart(const char * el, const char ** attr) +{ +depth++; +if (depth == 1) + if (strcasecmp(el, "CheckUser") == 0) + ParseAnswer(el, attr); +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_CHECK_USER::ParseEnd(const char *) +{ +depth--; +} +//----------------------------------------------------------------------------- +void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr) +{ +if (!callback) + return; +if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0) + callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data); +else + callback(false, "Invalid response.", data); +} +//----------------------------------------------------------------------------- +void PARSER_CHECK_USER::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/parser_chg_user.cpp b/stglibs/srvconf.lib/parser_chg_user.cpp new file mode 100644 index 00000000..53ce941d --- /dev/null +++ b/stglibs/srvconf.lib/parser_chg_user.cpp @@ -0,0 +1,69 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_chg_user.h" + +#include + +#include + +PARSER_CHG_USER::PARSER_CHG_USER() + : callback(NULL), + data(NULL), + depth(0) +{ +} +//----------------------------------------------------------------------------- +int PARSER_CHG_USER::ParseStart(const char *el, const char **attr) +{ +depth++; +if (depth == 1) + { + if (strcasecmp(el, "SetUser") == 0) + ParseAnswer(el, attr); + else if (strcasecmp(el, "DelUser") == 0) + ParseAnswer(el, attr); + else if (strcasecmp(el, "AddUser") == 0) + ParseAnswer(el, attr); + } +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::ParseEnd(const char *) +{ +depth--; +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::ParseAnswer(const char * /*el*/, const char ** attr) +{ +if (!callback) + return; +if (attr && attr[0] && attr[1]) + callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data); +else + callback(false, "Invalid response.", data); +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp new file mode 100644 index 00000000..a684a3f7 --- /dev/null +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -0,0 +1,150 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_get_user.h" + +#include "stg/common.h" + +#include +#include +#include + +#include + +template <> +bool GetValue(const char ** attr, PARSER_GET_USER::STAT & value) +{ +if (!attr) + return false; +std::map props; +for (size_t i = 0; i < DIR_NUM; ++i) + { + props.insert(std::pair("su" + x2str(i), &value.su[i])); + props.insert(std::pair("sd" + x2str(i), &value.sd[i])); + props.insert(std::pair("mu" + x2str(i), &value.mu[i])); + props.insert(std::pair("md" + x2str(i), &value.md[i])); + } +size_t pos = 0; +while (attr[pos]) + { + std::string name(ToLower(attr[pos++])); + std::map::iterator it(props.find(name)); + if (it != props.end()) + if (str2x(attr[pos++], *it->second) < 0) + return false; + } +return true; +} + +PARSER_GET_USER::PARSER_GET_USER() + : callback(NULL), + data(NULL), + depth(0), + parsingAnswer(false) +{ + AddParser(propertyParsers, "login", info.login); + AddParser(propertyParsers, "password", info.password); + AddParser(propertyParsers, "cash", info.cash); + AddParser(propertyParsers, "credit", info.credit); + AddParser(propertyParsers, "creditExpire", info.creditExpire); + AddParser(propertyParsers, "lastCash", info.lastCash); + AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff); + AddParser(propertyParsers, "down", info.down); + AddParser(propertyParsers, "passive", info.passive); + AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat); + AddParser(propertyParsers, "connected", info.connected); + AddParser(propertyParsers, "alwaysOnline", info.alwaysOnline); + AddParser(propertyParsers, "currIP", info.ip, GetIPValue); + AddParser(propertyParsers, "ip", info.ips); + AddParser(propertyParsers, "tariff", info.tariff); + AddParser(propertyParsers, "group", info.group, GetEncodedValue); + AddParser(propertyParsers, "note", info.note, GetEncodedValue); + AddParser(propertyParsers, "email", info.email, GetEncodedValue); + AddParser(propertyParsers, "name", info.name, GetEncodedValue); + AddParser(propertyParsers, "address", info.address, GetEncodedValue); + AddParser(propertyParsers, "phone", info.phone, GetEncodedValue); + AddParser(propertyParsers, "traff", info.stat); + + for (size_t i = 0; i < USERDATA_NUM; ++i) + AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue); +} +//----------------------------------------------------------------------------- +PARSER_GET_USER::~PARSER_GET_USER() +{ + PROPERTY_PARSERS::iterator it(propertyParsers.begin()); + while (it != propertyParsers.end()) + delete (it++)->second; +} +//----------------------------------------------------------------------------- +int PARSER_GET_USER::ParseStart(const char * el, const char ** attr) +{ +depth++; +if (depth == 1) + ParseUser(el, attr); + +if (depth == 2 && parsingAnswer) + ParseUserParams(el, attr); + +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_GET_USER::ParseEnd(const char * /*el*/) +{ +depth--; +if (depth == 0 && parsingAnswer) + { + if (callback) + callback(error.empty(), error, info, data); + error.clear(); + parsingAnswer = false; + } +} +//----------------------------------------------------------------------------- +void PARSER_GET_USER::ParseUser(const char * el, const char ** attr) +{ +if (strcasecmp(el, "user") == 0) + if (attr && attr[0] && attr[1]) + { + if (strcasecmp(attr[1], "error") == 0) + { + if (attr[2] && attr[3]) + error = attr[3]; + else + error = "User not found."; + } + else + parsingAnswer = true; + } + else + parsingAnswer = true; +} +//----------------------------------------------------------------------------- +void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr) +{ +if (!TryParse(propertyParsers, ToLower(el), attr)) + error = "Invalid parameter."; +} +//----------------------------------------------------------------------------- +void PARSER_GET_USER::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/parser_get_users.cpp b/stglibs/srvconf.lib/parser_get_users.cpp new file mode 100644 index 00000000..2f380c82 --- /dev/null +++ b/stglibs/srvconf.lib/parser_get_users.cpp @@ -0,0 +1,83 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_get_users.h" + +#include + +#include + +PARSER_GET_USERS::PARSER_GET_USERS() + : callback(NULL), + data(NULL), + depth(0), + parsingAnswer(false) +{ + userParser.SetCallback(&PARSER_GET_USERS::UserCallback, this); +} +//----------------------------------------------------------------------------- +int PARSER_GET_USERS::ParseStart(const char * el, const char ** attr) +{ +depth++; +if (depth == 1 && strcasecmp(el, "users") == 0) + parsingAnswer = true; + +if (depth > 1 && parsingAnswer) + userParser.ParseStart(el, attr); + +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_GET_USERS::ParseEnd(const char * el) +{ +depth--; +if (depth > 0 && parsingAnswer) + userParser.ParseEnd(el); + +if (depth == 0 && parsingAnswer) + { + if (callback) + callback(error.empty(), error, info, data); + error.clear(); + info.clear(); + parsingAnswer = false; + } +} +//----------------------------------------------------------------------------- +void PARSER_GET_USERS::AddUser(const PARSER_GET_USER::INFO & userInfo) +{ +info.push_back(userInfo); +} +//----------------------------------------------------------------------------- +void PARSER_GET_USERS::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} +//----------------------------------------------------------------------------- +void PARSER_GET_USERS::UserCallback(bool result, const std::string & error, const PARSER_GET_USER::INFO & info, void * data) +{ + PARSER_GET_USERS * parser = static_cast(data); + if (!result) + parser->SetError(error); + else + parser->AddUser(info); +} diff --git a/stglibs/srvconf.lib/parser_send_message.cpp b/stglibs/srvconf.lib/parser_send_message.cpp new file mode 100644 index 00000000..c1955fce --- /dev/null +++ b/stglibs/srvconf.lib/parser_send_message.cpp @@ -0,0 +1,63 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_send_message.h" + +#include + +#include + +PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() + : callback(NULL), + data(NULL), + depth(0) +{ +} +//----------------------------------------------------------------------------- +int PARSER_SEND_MESSAGE::ParseStart(const char * el, const char ** attr) +{ +depth++; +if (depth == 1) + if (strcasecmp(el, "SendMessageResult") == 0) + ParseAnswer(el, attr); +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_SEND_MESSAGE::ParseEnd(const char * /*el*/) +{ +depth--; +} +//----------------------------------------------------------------------------- +void PARSER_SEND_MESSAGE::ParseAnswer(const char * /*el*/, const char **attr) +{ +if (!callback) + return; +if (attr && attr[0] && attr[1]) + callback(strcasecmp(attr[1], "ok") == 0, attr[1], data); +else + callback(false, "Invalid response.", data); +} +//----------------------------------------------------------------------------- +void PARSER_SEND_MESSAGE::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/parser_server_info.cpp b/stglibs/srvconf.lib/parser_server_info.cpp new file mode 100644 index 00000000..645f6099 --- /dev/null +++ b/stglibs/srvconf.lib/parser_server_info.cpp @@ -0,0 +1,86 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_server_info.h" + +#include "stg/common.h" + +#include // sprintf +#include + +#include + +namespace +{ + +const size_t UNAME_LEN = 256; +const size_t SERV_VER_LEN = 64; +const size_t DIRNAME_LEN = 16; + +} + +PARSER_SERVER_INFO::PARSER_SERVER_INFO() + : callback(NULL), + data(NULL), + depth(0), + parsingAnswer(false) +{ + AddParser(propertyParsers, "uname", info.uname); + AddParser(propertyParsers, "version", info.version); + AddParser(propertyParsers, "tariff", info.tariffType); + AddParser(propertyParsers, "dir_num", info.dirNum); + AddParser(propertyParsers, "users_num", info.usersNum); + AddParser(propertyParsers, "tariff_num", info.tariffNum); + + for (size_t i = 0; i < DIR_NUM; i++) + AddParser(propertyParsers, "dir_name_" + x2str(i), info.dirName[i], GetEncodedValue); +} +//----------------------------------------------------------------------------- +int PARSER_SERVER_INFO::ParseStart(const char *el, const char **attr) +{ +depth++; +if (depth == 1) + if (strcasecmp(el, "ServerInfo") == 0) + parsingAnswer = true; +else + if (depth == 2 && parsingAnswer) + if (!TryParse(propertyParsers, ToLower(el), attr)) + error = "Invalid parameter."; +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_SERVER_INFO::ParseEnd(const char * /*el*/) +{ +depth--; +if (depth == 0 && parsingAnswer) + { + if (callback) + callback(error.empty(), error, info, data); + error.clear(); + parsingAnswer = false; + } +} +//----------------------------------------------------------------------------- +void PARSER_SERVER_INFO::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/property_parsers.cpp b/stglibs/srvconf.lib/property_parsers.cpp new file mode 100644 index 00000000..fcb9020a --- /dev/null +++ b/stglibs/srvconf.lib/property_parsers.cpp @@ -0,0 +1,55 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + +#include "stg/property_parsers.h" + +#include + +bool CheckValue(const char ** attr) +{ +return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0; +} + +bool GetEncodedValue(const char ** attr, std::string & value) +{ +if (!CheckValue(attr)) + return false; +Decode21str(value, attr[1]); +return true; +} + +bool GetIPValue(const char ** attr, uint32_t & value) +{ +if (!CheckValue(attr)) + return false; +std::string ip(attr[1]); +value = inet_strington(attr[1]); +if (value == 0 && ip != "0.0.0.0") + return false; +return true; +} + +bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr) +{ + PROPERTY_PARSERS::iterator it(parsers.find(name)); + if (it != parsers.end()) + return it->second->Parse(attr); + return true; // Assume that non-existing params are ok. +} diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index ab386cf7..f2498ef5 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -18,48 +18,33 @@ * Author : Boris Mikhailenko */ - /* - $Revision: 1.8 $ - $Date: 2010/08/04 00:40:38 $ - $Author: faust $ - */ - -#include -#include +#include "stg/servconf.h" #include "stg/common.h" -#include "stg/servconf.h" -using namespace std; +#include +#include //----------------------------------------------------------------------------- -int AnsRecv(void * data, list * list1) +int AnsRecv(void * data, std::list * list1) { -//NODE * node; -SERVCONF * sc; -char ans[ENC_MSG_LEN + 1]; -int len, done = 0; - -sc = (SERVCONF*)data; +SERVCONF * sc = static_cast(data); XML_ParserReset(sc->parser, NULL); XML_SetElementHandler(sc->parser, Start, End); XML_SetUserData(sc->parser, data); +char ans[ENC_MSG_LEN + 1]; +int len, done = 0; + //loop parsing -list::iterator node; +std::list::iterator node; node = list1->begin(); -if (node == list1->end()) - { - return st_ok; - } - while (node != list1->end()) { strncpy(ans, node->c_str(), ENC_MSG_LEN); ans[ENC_MSG_LEN] = 0; - //printf("---> %s\n", ans); len = strlen(ans); if (XML_Parse(sc->parser, ans, len, done) == XML_STATUS_ERROR) @@ -67,47 +52,32 @@ while (node != list1->end()) strprintf(&sc->errorMsg, "XML parse error at line %d: %s", static_cast(XML_GetCurrentLineNumber(sc->parser)), XML_ErrorString(XML_GetErrorCode(sc->parser))); + printf("%s\n", sc->errorMsg.c_str()); return st_xml_parse_error; } ++node; - } -return 0; +return st_ok; } //----------------------------------------------------------------------------- void Start(void *data, const char *el, const char **attr) { -SERVCONF * sc; -sc = (SERVCONF*)data; +SERVCONF * sc = static_cast(data); sc->Start(el, attr); } //----------------------------------------------------------------------------- -void End(void *data, const char *el) +void End(void * data, const char * el) { -SERVCONF * sc; -sc = (SERVCONF*)data; +SERVCONF * sc = static_cast(data); sc->End(el); } //----------------------------------------------------------------------------- SERVCONF::SERVCONF() - : currParser(NULL), - parseDepth(0), - error(0), - RecvUserDataCb(NULL), - RecvGetUserDataCb(NULL), - RecvServerInfoDataCb(NULL), - RecvChgUserCb(NULL), - RecvCheckUserCb(NULL), - RecvSendMessageCb(NULL), - getUserDataDataCb(NULL), - getUsersDataDataCb(NULL), - getServerInfoDataCb(NULL), - chgUserDataCb(NULL), - checkUserDataCb(NULL), - sendMessageDataCb(NULL) + : currParser(NULL) { parser = XML_ParserCreate(NULL); +nt.SetRxCallback(this, AnsRecv); } //----------------------------------------------------------------------------- void SERVCONF::SetServer(const char * server) @@ -134,262 +104,108 @@ int SERVCONF::GetUser(const char * l) { char request[255]; snprintf(request, 255, "", l); -int ret; currParser = &parserGetUser; -((PARSER_GET_USER*)currParser)->SetUserDataRecvCb(RecvGetUserDataCb, getUserDataDataCb); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- -int SERVCONF::GetUsers() +int SERVCONF::AuthBy(const char * l) { -char request[] = ""; -int ret; - -currParser = &parserGetUsers; -((PARSER_GET_USERS*)currParser)->SetUserDataRecvCb(RecvUserDataCb, getUsersDataDataCb); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); +char request[255]; +snprintf(request, 255, "", l); -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } +currParser = &parserAuthBy; -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- -int SERVCONF::SendMessage(const char * login, const char * message, int prio) +int SERVCONF::GetUsers() { -char request[1000]; -char msg[500]; -Encode12(msg, message, strlen(message)); -snprintf(request, 1000, "", login, prio, msg); -int ret; - -currParser = &parserSendMessage; -parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); +char request[] = ""; -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } +currParser = &parserGetUsers; -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- -int SERVCONF::GetServerInfo() +int SERVCONF::ServerInfo() { char request[] = ""; -int ret; currParser = &parserServerInfo; -((PARSER_GET_SERVER_INFO*)currParser)->SetServerInfoRecvCb(RecvServerInfoDataCb, getServerInfoDataCb); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::ChgUser(const char * request) { -int ret; - currParser = &parserChgUser; -((PARSER_CHG_USER*)currParser)->SetChgUserRecvCb(RecvChgUserCb, chgUserDataCb); -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- -// TODO: remove this shit! -//----------------------------------------------------------------------------- -int SERVCONF::MsgUser(const char * request) +int SERVCONF::SendMessage(const char * request) { -int ret; - currParser = &parserSendMessage; -parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::CheckUser(const char * login, const char * password) { char request[255]; snprintf(request, 255, "", login, password); -int ret; currParser = &parserCheckUser; -((PARSER_CHECK_USER*)currParser)->SetCheckUserRecvCb(RecvCheckUserCb, checkUserDataCb); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- -int SERVCONF::Start(const char *el, const char **attr) +int SERVCONF::Start(const char * el, const char ** attr) { currParser->ParseStart(el, attr); return 0; } //----------------------------------------------------------------------------- -void SERVCONF::End(const char *el) +void SERVCONF::End(const char * el) { currParser->ParseEnd(el); } //----------------------------------------------------------------------------- -void SERVCONF::SetUserDataRecvCb(RecvUserDataCb_t f, void * data) +void SERVCONF::SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data) +{ +parserGetUsers.SetCallback(f, data); +} +//----------------------------------------------------------------------------- +void SERVCONF::SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data) { -RecvUserDataCb = f; -getUsersDataDataCb = data; +parserGetUser.SetCallback(f, data); } //----------------------------------------------------------------------------- -void SERVCONF::SetGetUserDataRecvCb(RecvUserDataCb_t f, void * data) +void SERVCONF::SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data) { -RecvGetUserDataCb = f; //GET_USER -getUserDataDataCb = data; +parserAuthBy.SetCallback(f, data); } //----------------------------------------------------------------------------- -void SERVCONF::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data) +void SERVCONF::SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data) { -RecvServerInfoDataCb = f; -getServerInfoDataCb = data; +parserServerInfo.SetCallback(f, data); } //----------------------------------------------------------------------------- -void SERVCONF::SetChgUserCb(RecvChgUserCb_t f, void * data) +void SERVCONF::SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data) { -RecvChgUserCb = f; -chgUserDataCb = data; +parserChgUser.SetCallback(f, data); } //----------------------------------------------------------------------------- -void SERVCONF::SetCheckUserCb(RecvCheckUserCb_t f, void * data) +void SERVCONF::SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data) { -RecvCheckUserCb = f; -checkUserDataCb = data; +parserCheckUser.SetCallback(f, data); } //----------------------------------------------------------------------------- -void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data) +void SERVCONF::SetSendMessageCallback(PARSER_SEND_MESSAGE::CALLBACK f, void * data) { -RecvSendMessageCb = f; -sendMessageDataCb = data; +parserSendMessage.SetCallback(f, data); } //----------------------------------------------------------------------------- const std::string & SERVCONF::GetStrError() const @@ -397,10 +213,26 @@ const std::string & SERVCONF::GetStrError() const return errorMsg; } //----------------------------------------------------------------------------- -int SERVCONF::GetError() +int SERVCONF::Exec(const char * request) { -int e = error; -error = 0; -return e; +nt.Reset(); + +int ret = 0; +if ((ret = nt.Connect()) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } +if ((ret = nt.Transact(request)) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } +if ((ret = nt.Disconnect()) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } + +return st_ok; } -//-----------------------------------------------------------------------------