From: Maxim Mamontov Date: Fri, 8 Apr 2011 12:44:11 +0000 (+0300) Subject: Remove 'stg' prefixes from headers and add it to libraries X-Git-Tag: 2.407-rc3~24 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/90e389f6ec12e60a62c362296ffcf314feb5b03d Remove 'stg' prefixes from headers and add it to libraries --- diff --git a/include/stg/auth.h b/include/stg/auth.h index 8cdc3f2d..f597f6d1 100644 --- a/include/stg/auth.h +++ b/include/stg/auth.h @@ -27,7 +27,7 @@ #define AUTH_H #include "plugin.h" -#include "stg_message.h" +#include "message.h" #include "noncopyable.h" class AUTH : public PLUGIN { diff --git a/include/stg/const.h b/include/stg/const.h new file mode 100644 index 00000000..e882200d --- /dev/null +++ b/include/stg/const.h @@ -0,0 +1,87 @@ +/* + * 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: nobunaga $ + $Revision: 1.10 $ + $Date: 2008/01/11 17:33:50 $ + */ + + +#ifndef STG_CONST_H +#define STG_CONST_H + +#define DIR_NUM (10) +#define SYS_IFACE_LEN (9) +#define IFACE_LEN (255) +#define MAX_IP (5) +#define USERDATA_NUM (10) + +#define LOGIN_LEN (32) +#define PASSWD_LEN (32) +#define ADDR_LEN (255) +#define NOTE_LEN (255) +#define REALNM_LEN (255) +#define GROUP_LEN (255) +#define PHONE_LEN (255) +#define EMAIL_LEN (255) +#define USR_IFACE_LEN (255) +#define USER_DATA_LEN (255) +#define IP_STRING_LEN (255) + +#define ADM_LOGIN_LEN (32) +#define ADM_PASSWD_LEN (32) +#define TARIFF_NAME_LEN (32) +#define SERVER_NAME_LEN (255) + +#define DIR_NAME_LEN (16) + +#define MAX_MSG_LEN (235) +#define MAX_MSG_LEN_8 (1030) + +#define LOGCASH (1) +#define NOLOGCASH (0) + +#define USERNOCASH (0) +#define USERDISCONNECT (1) + +#define LOGEVENT_CONNECT (0) +#define LOGEVENT_DISCONNECT (1) +#define LOGEVENT_NEW_MONTH (2) +#define LOGEVENT_NO_CASH (3) +#define LOGEVENT_CONNECT_NO_CASH (4) +#define LOGEVENT_USER_DOWN (5) +#define LOGEVENT_DELETED (6) + +#define SET_TARIFF_NOW (0) +#define SET_TARIFF_DELAYED (1) +#define SET_TARIFF_RECALC (2) + +#define CASH_SET (0) +#define CASH_ADD (1) + +#define NO_TARIFF_NAME "*_NO_TARIFF_*" +#define NO_CORP_NAME "*_NO_CORP_*" + +#define mega (1024 * 1024) + +#define MONITOR_TIME_DELAY_SEC (60) + +#endif diff --git a/include/stg/message.h b/include/stg/message.h new file mode 100644 index 00000000..16fe566f --- /dev/null +++ b/include/stg/message.h @@ -0,0 +1,56 @@ +#ifndef STG_MESSAGES_H +#define STG_MESSAGES_H + +/* + * Author : Boris Mikhailenko + */ + + /* + $Revision: 1.3 $ + $Date: 2010/03/04 11:49:52 $ + */ + +#include +#include + +#include "os_int.h" + +//----------------------------------------------------------------------------- +struct STG_MSG_HDR +{ +STG_MSG_HDR() + : id(0), + ver(0), + type(0), + lastSendTime(0), + creationTime(0), + showTime(0), + repeat(0), + repeatPeriod(0) +{}; + +uint64_t id; +unsigned ver; +unsigned type; +unsigned lastSendTime; +unsigned creationTime; +unsigned showTime; +int repeat; +unsigned repeatPeriod; +}; +//----------------------------------------------------------------------------- +struct STG_MSG +{ +STG_MSG() {}; + +time_t GetNextSendTime() const +{ +return header.lastSendTime + header.repeat * 60; +}; + +STG_MSG_HDR header; +std::string text; +}; +//----------------------------------------------------------------------------- + +#endif diff --git a/include/stg/raw_ip_packet.h b/include/stg/raw_ip_packet.h index a1bdda71..bf8bc577 100644 --- a/include/stg/raw_ip_packet.h +++ b/include/stg/raw_ip_packet.h @@ -10,7 +10,7 @@ #include -#include "stg_const.h" +#include "const.h" #include "common.h" #define IPv4 (2) diff --git a/include/stg/stg_const.h b/include/stg/stg_const.h deleted file mode 100644 index e882200d..00000000 --- a/include/stg/stg_const.h +++ /dev/null @@ -1,87 +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 - */ - - /* - $Author: nobunaga $ - $Revision: 1.10 $ - $Date: 2008/01/11 17:33:50 $ - */ - - -#ifndef STG_CONST_H -#define STG_CONST_H - -#define DIR_NUM (10) -#define SYS_IFACE_LEN (9) -#define IFACE_LEN (255) -#define MAX_IP (5) -#define USERDATA_NUM (10) - -#define LOGIN_LEN (32) -#define PASSWD_LEN (32) -#define ADDR_LEN (255) -#define NOTE_LEN (255) -#define REALNM_LEN (255) -#define GROUP_LEN (255) -#define PHONE_LEN (255) -#define EMAIL_LEN (255) -#define USR_IFACE_LEN (255) -#define USER_DATA_LEN (255) -#define IP_STRING_LEN (255) - -#define ADM_LOGIN_LEN (32) -#define ADM_PASSWD_LEN (32) -#define TARIFF_NAME_LEN (32) -#define SERVER_NAME_LEN (255) - -#define DIR_NAME_LEN (16) - -#define MAX_MSG_LEN (235) -#define MAX_MSG_LEN_8 (1030) - -#define LOGCASH (1) -#define NOLOGCASH (0) - -#define USERNOCASH (0) -#define USERDISCONNECT (1) - -#define LOGEVENT_CONNECT (0) -#define LOGEVENT_DISCONNECT (1) -#define LOGEVENT_NEW_MONTH (2) -#define LOGEVENT_NO_CASH (3) -#define LOGEVENT_CONNECT_NO_CASH (4) -#define LOGEVENT_USER_DOWN (5) -#define LOGEVENT_DELETED (6) - -#define SET_TARIFF_NOW (0) -#define SET_TARIFF_DELAYED (1) -#define SET_TARIFF_RECALC (2) - -#define CASH_SET (0) -#define CASH_ADD (1) - -#define NO_TARIFF_NAME "*_NO_TARIFF_*" -#define NO_CORP_NAME "*_NO_CORP_*" - -#define mega (1024 * 1024) - -#define MONITOR_TIME_DELAY_SEC (60) - -#endif diff --git a/include/stg/stg_message.h b/include/stg/stg_message.h deleted file mode 100644 index 16fe566f..00000000 --- a/include/stg/stg_message.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef STG_MESSAGES_H -#define STG_MESSAGES_H - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.3 $ - $Date: 2010/03/04 11:49:52 $ - */ - -#include -#include - -#include "os_int.h" - -//----------------------------------------------------------------------------- -struct STG_MSG_HDR -{ -STG_MSG_HDR() - : id(0), - ver(0), - type(0), - lastSendTime(0), - creationTime(0), - showTime(0), - repeat(0), - repeatPeriod(0) -{}; - -uint64_t id; -unsigned ver; -unsigned type; -unsigned lastSendTime; -unsigned creationTime; -unsigned showTime; -int repeat; -unsigned repeatPeriod; -}; -//----------------------------------------------------------------------------- -struct STG_MSG -{ -STG_MSG() {}; - -time_t GetNextSendTime() const -{ -return header.lastSendTime + header.repeat * 60; -}; - -STG_MSG_HDR header; -std::string text; -}; -//----------------------------------------------------------------------------- - -#endif diff --git a/include/stg/store.h b/include/stg/store.h index f33a0653..0eaf6c3e 100644 --- a/include/stg/store.h +++ b/include/stg/store.h @@ -38,7 +38,7 @@ #include "admin_conf.h" #include "tariff_conf.h" #include "module_settings.h" -#include "stg_message.h" +#include "message.h" //----------------------------------------------------------------------------- class STORE { diff --git a/include/stg/tariff_conf.h b/include/stg/tariff_conf.h index 30f19815..31df4ec9 100644 --- a/include/stg/tariff_conf.h +++ b/include/stg/tariff_conf.h @@ -31,7 +31,7 @@ #include #include "resetable.h" -#include "stg_const.h" +#include "const.h" //----------------------------------------------------------------------------- enum diff --git a/include/stg/user.h b/include/stg/user.h index adf140de..51e8a76d 100644 --- a/include/stg/user.h +++ b/include/stg/user.h @@ -26,7 +26,7 @@ #include "os_int.h" #include "notifer.h" -#include "stg_message.h" +#include "message.h" #include "tariff.h" #include "user_traff.h" diff --git a/include/stg/user_conf.h b/include/stg/user_conf.h index 9a6efb23..70cb4fa7 100644 --- a/include/stg/user_conf.h +++ b/include/stg/user_conf.h @@ -9,7 +9,7 @@ #include #include -#include "stg_const.h" +#include "const.h" #include "user_ips.h" #include "resetable.h" #include "os_int.h" diff --git a/include/stg/user_property.h b/include/stg/user_property.h index 78e5675a..8b934167 100644 --- a/include/stg/user_property.h +++ b/include/stg/user_property.h @@ -18,8 +18,8 @@ $Author: faust $ #include "store.h" #include "admin.h" #include "notifer.h" -#include "stg_logger.h" -#include "stg_locker.h" +#include "logger.h" +#include "locker.h" #include "script_executer.h" #include "noncopyable.h" diff --git a/include/stg/user_traff.h b/include/stg/user_traff.h index fdefee0f..fa4cc7fd 100644 --- a/include/stg/user_traff.h +++ b/include/stg/user_traff.h @@ -30,7 +30,7 @@ #include #include -#include "stg_const.h" +#include "const.h" #include "os_int.h" enum TRAFF_DIRECTION {TRAFF_UPLOAD, TRAFF_DOWNLOAD}; diff --git a/projects/convertor/Makefile b/projects/convertor/Makefile index a143687c..569917d2 100644 --- a/projects/convertor/Makefile +++ b/projects/convertor/Makefile @@ -9,10 +9,10 @@ PROG = convertor SRCS = ./main.cpp \ ./settings_impl.cpp -STGLIBS = -lstg_logger \ - -lstg_common \ +STGLIBS = -lstglogger \ + -lstgcommon \ -ldotconfpp \ - -lstg_crypto + -lstgcrypto LIBS += $(LIB_THREAD) diff --git a/projects/convertor/build b/projects/convertor/build index 0ffb2b8b..07fb1e2f 100755 --- a/projects/convertor/build +++ b/projects/convertor/build @@ -52,8 +52,8 @@ echo "########################################################################## echo " Building convertor for $sys $release" echo "#############################################################################" -STG_LIBS="stg_logger.lib - stg_locker.lib +STG_LIBS="logger.lib + locker.lib crypto.lib common.lib conffiles.lib diff --git a/projects/convertor/main.cpp b/projects/convertor/main.cpp index f6491c7b..e0679d07 100644 --- a/projects/convertor/main.cpp +++ b/projects/convertor/main.cpp @@ -43,7 +43,7 @@ #include "stg/admin_conf.h" #include "stg/tariff_conf.h" #include "stg/settings.h" -#include "stg/stg_message.h" +#include "stg/message.h" #include "settings_impl.h" diff --git a/projects/make_tarball/mt.sh b/projects/make_tarball/mt.sh index 0ad2e6b1..bbfa45a1 100755 --- a/projects/make_tarball/mt.sh +++ b/projects/make_tarball/mt.sh @@ -19,8 +19,8 @@ arc_name=$src_dir.tar.gz ./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/common_settings.lib $src_dir ./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/conffiles.lib $src_dir ./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/crypto.lib $src_dir -./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/stg_logger.lib $src_dir -./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/stg_locker.lib $src_dir +./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/logger.lib $src_dir +./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/locker.lib $src_dir ./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/hostallow.lib $src_dir ./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/pinger.lib $src_dir ./get_from_cvs $cvs_user $cvs_pass $cvs_host /cvsroot/stglibs stglibs/dotconfpp.lib $src_dir diff --git a/projects/rlm_stg/Makefile b/projects/rlm_stg/Makefile index 20530c52..da1a5768 100644 --- a/projects/rlm_stg/Makefile +++ b/projects/rlm_stg/Makefile @@ -11,8 +11,8 @@ PROG = $(LIB_NAME).so SRCS = ./rlm_stg.cpp \ ./stg_client.cpp -STGLIBS = -lstg_common \ - -lstg_crypto +STGLIBS = -lstgcommon \ + -lstgcrypto LIBS += $(LIB_THREAD) diff --git a/projects/rscriptd/Makefile b/projects/rscriptd/Makefile index ff08de0d..2b6cbc1c 100644 --- a/projects/rscriptd/Makefile +++ b/projects/rscriptd/Makefile @@ -10,11 +10,11 @@ SRCS = ./main.cpp \ ./listener.cpp \ ./pidfile.cpp -STGLIBS = -lstg_logger \ - -lstg_common \ - -lstg_crypto \ - -lscript_executer \ - -lconffiles +STGLIBS = -lstglogger \ + -lstgcommon \ + -lstgcrypto \ + -lstgscriptexecuter \ + -lstgconffiles LIBS += $(LIB_THREAD) diff --git a/projects/rscriptd/build b/projects/rscriptd/build index 173e3afc..a91d70c8 100755 --- a/projects/rscriptd/build +++ b/projects/rscriptd/build @@ -65,11 +65,11 @@ echo "########################################################################## echo " Building rscriptd for $sys $release" echo "#############################################################################" -STG_LIBS="stg_logger.lib - stg_locker.lib +STG_LIBS="logger.lib + locker.lib crypto.lib common.lib - script_executer.lib + scriptexecuter.lib conffiles.lib" if [ "$OS" = "linux" ] diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index e6bd4d77..47adc93b 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -34,7 +34,7 @@ #include #include "stg/script_executer.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "stg/common.h" #include "listener.h" diff --git a/projects/rscriptd/listener.h b/projects/rscriptd/listener.h index 16c49219..1c88149a 100644 --- a/projects/rscriptd/listener.h +++ b/projects/rscriptd/listener.h @@ -29,7 +29,7 @@ #include "stg/os_int.h" #include "stg/blowfish.h" #include "stg/rs_packets.h" -#include "stg/stg_logger.h" +#include "stg/logger.h" struct UserData { diff --git a/projects/rscriptd/main.cpp b/projects/rscriptd/main.cpp index 2f5f0baa..714da320 100644 --- a/projects/rscriptd/main.cpp +++ b/projects/rscriptd/main.cpp @@ -39,8 +39,8 @@ #include #include "stg/common.h" -#include "stg/stg_logger.h" -#include "stg/script_executer.h" +#include "stg/logger.h" +#include "stg/scriptexecuter.h" #include "stg/conffiles.h" #include "stg/version.h" #include "listener.h" diff --git a/projects/sgauth/Makefile b/projects/sgauth/Makefile index e586695b..338e3500 100644 --- a/projects/sgauth/Makefile +++ b/projects/sgauth/Makefile @@ -10,10 +10,10 @@ SRCS = ./main.cpp \ ./settings_impl.cpp \ ./web.cpp -STGLIBS = -lconffiles \ - -lstg_crypto \ - -lstg_common \ - -lia_auth_c +STGLIBS = -lstgconffiles \ + -lstgcrypto \ + -lstgcommon \ + -lstgia LIBS += $(LIB_THREAD) diff --git a/projects/sgauth/build b/projects/sgauth/build index 29109a37..7155188b 100755 --- a/projects/sgauth/build +++ b/projects/sgauth/build @@ -68,7 +68,7 @@ echo "########################################################################## STG_LIBS="crypto.lib common.lib conffiles.lib - ia_auth_c.lib" + ia.lib" if [ "$OS" = "linux" ] then diff --git a/projects/sgauth/main.cpp b/projects/sgauth/main.cpp index c78f18ed..96c58203 100644 --- a/projects/sgauth/main.cpp +++ b/projects/sgauth/main.cpp @@ -35,7 +35,7 @@ #include #include -#include "stg/ia_auth_c.h" +#include "stg/ia.h" #include "stg/common.h" #include "web.h" #include "settings_impl.h" diff --git a/projects/sgauth/web.h b/projects/sgauth/web.h index a4dfcb48..aa2227ee 100644 --- a/projects/sgauth/web.h +++ b/projects/sgauth/web.h @@ -39,7 +39,7 @@ #include #include -#include "stg/stg_const.h" +#include "stg/const.h" #include "stg/ia_packets.h" using namespace std; diff --git a/projects/sgconf/Makefile b/projects/sgconf/Makefile index 4a051412..99135556 100644 --- a/projects/sgconf/Makefile +++ b/projects/sgconf/Makefile @@ -9,10 +9,10 @@ PROG = sgconf SRCS = ./main.cpp \ ./common_sg.cpp -STGLIBS = -lconffiles \ - -lstg_common \ - -lstg_crypto \ - -lsrvconf +STGLIBS = -lstgconffiles \ + -lstgcommon \ + -lstgcrypto \ + -lstgsrvconf LIBS += -lexpat \ $(LIB_THREAD) diff --git a/projects/sgconf/request.h b/projects/sgconf/request.h index c8098661..daddec1d 100644 --- a/projects/sgconf/request.h +++ b/projects/sgconf/request.h @@ -34,7 +34,7 @@ #include #include "stg/resetable.h" -#include "stg/stg_const.h" +#include "stg/const.h" #include "stg/os_int.h" #define TARIFF_NOW (0) diff --git a/projects/sgconf_xml/Makefile b/projects/sgconf_xml/Makefile index 33989ae2..752f05a5 100644 --- a/projects/sgconf_xml/Makefile +++ b/projects/sgconf_xml/Makefile @@ -9,10 +9,10 @@ PROG = sgconf_xml SRCS = ./main.cpp \ ./parser.cpp -LIBS = -lconffiles \ - -lstg_crypto \ - -lstg_common \ - -lsrvconf +LIBS = -lstgconffiles \ + -lstgcrypto \ + -lstgcommon \ + -lstgsrvconf LIBS += -lexpat \ $(LIB_THREAD) diff --git a/projects/sgconf_xml/request.h b/projects/sgconf_xml/request.h index bbd46325..004f89b0 100644 --- a/projects/sgconf_xml/request.h +++ b/projects/sgconf_xml/request.h @@ -34,7 +34,7 @@ #include "stg/resetable.h" #include "stg/os_int.h" -#include "stg/stg_const.h" +#include "stg/const.h" #ifndef ENODATA #define ENODATA 61 diff --git a/projects/stargazer/Makefile b/projects/stargazer/Makefile index beac6fc6..56a1ebf9 100644 --- a/projects/stargazer/Makefile +++ b/projects/stargazer/Makefile @@ -22,10 +22,10 @@ SRCS = ./admin_impl.cpp \ ./user_property.cpp \ ./users_impl.cpp -STGLIBS = -lstg_logger \ - -lstg_locker \ - -lstg_common \ - -lscript_executer \ +STGLIBS = -lstglogger \ + -lstglocker \ + -lstgcommon \ + -lstgscriptexecuter \ -ldotconfpp LIBS += -lexpat diff --git a/projects/stargazer/actions.inl.h b/projects/stargazer/actions.inl.h index 29dce606..d7874373 100644 --- a/projects/stargazer/actions.inl.h +++ b/projects/stargazer/actions.inl.h @@ -3,7 +3,7 @@ #include -#include "stg/stg_locker.h" +#include "stg/locker.h" // Polymorphick action invocation template diff --git a/projects/stargazer/admin_impl.h b/projects/stargazer/admin_impl.h index 69f38420..6d58336e 100644 --- a/projects/stargazer/admin_impl.h +++ b/projects/stargazer/admin_impl.h @@ -36,7 +36,7 @@ #include "stg/admin.h" #include "stg/os_int.h" #include "stg/admin_conf.h" -#include "stg/stg_logger.h" +#include "stg/logger.h" class ADMIN_IMPL : public ADMIN { public: diff --git a/projects/stargazer/admins_impl.h b/projects/stargazer/admins_impl.h index 9ca571e3..170f3a4f 100644 --- a/projects/stargazer/admins_impl.h +++ b/projects/stargazer/admins_impl.h @@ -38,7 +38,7 @@ #include "stg/admins.h" #include "stg/admin.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "stg/store.h" #include "stg/noncopyable.h" #include "admin_impl.h" diff --git a/projects/stargazer/build b/projects/stargazer/build index 36f2f733..1779160b 100755 --- a/projects/stargazer/build +++ b/projects/stargazer/build @@ -112,11 +112,11 @@ echo "########################################################################## echo " Building STG 2.4 for $sys $release" echo "#############################################################################" -STG_LIBS="stg_logger.lib - stg_locker.lib +STG_LIBS="logger.lib + locker.lib crypto.lib common.lib - script_executer.lib + scriptexecuter.lib conffiles.lib pinger.lib dotconfpp.lib" diff --git a/projects/stargazer/eventloop.cpp b/projects/stargazer/eventloop.cpp index 96c1ca4f..1d1a209d 100644 --- a/projects/stargazer/eventloop.cpp +++ b/projects/stargazer/eventloop.cpp @@ -1,7 +1,7 @@ #include #include -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "stg/common.h" #include "eventloop.h" diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 3ba9ccf3..46ea717d 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -43,7 +43,7 @@ #include "stg/user.h" #include "stg/common.h" #include "stg/plugin.h" -#include "stg/stg_logger.h" +#include "stg/logger.h" #include "stg/script_executer.h" #include "stg/conffiles.h" #include "stg/version.h" diff --git a/projects/stargazer/plugins/authorization/ao/Makefile b/projects/stargazer/plugins/authorization/ao/Makefile index a47cea23..a8651d64 100644 --- a/projects/stargazer/plugins/authorization/ao/Makefile +++ b/projects/stargazer/plugins/authorization/ao/Makefile @@ -8,7 +8,7 @@ PROG = mod_auth_ao.so SRCS = ./ao.cpp -STGLIBS = -lstg_common +STGLIBS = -lstgcommon include ../../Makefile.in diff --git a/projects/stargazer/plugins/authorization/inetaccess/Makefile b/projects/stargazer/plugins/authorization/inetaccess/Makefile index 62997715..15fd5287 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/Makefile +++ b/projects/stargazer/plugins/authorization/inetaccess/Makefile @@ -10,7 +10,7 @@ PROG = mod_auth_ia.so SRCS = ./inetaccess.cpp -STGLIBS = -lstg_common -lstg_crypto +STGLIBS = -lstgcommon -lstgcrypto include ../../Makefile.in diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index c58e8db1..8e44ed5e 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -40,7 +40,7 @@ #include #include "stg/common.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "stg/tariff.h" #include "stg/user_property.h" #include "stg/settings.h" diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index 707ed968..e16c0257 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -47,7 +47,7 @@ #include "stg/users.h" #include "stg/ia_packets.h" #include "stg/blowfish.h" -#include "stg/stg_logger.h" +#include "stg/logger.h" #include "stg/utime.h" extern "C" PLUGIN * GetPlugin(); diff --git a/projects/stargazer/plugins/capture/cap_debug/Makefile b/projects/stargazer/plugins/capture/cap_debug/Makefile index ade37382..916ae175 100644 --- a/projects/stargazer/plugins/capture/cap_debug/Makefile +++ b/projects/stargazer/plugins/capture/cap_debug/Makefile @@ -16,7 +16,7 @@ SRCS = ./debug_cap.cpp \ ./tcp.c \ ./udp.c -STGLIBS = -lstg_common +STGLIBS = -lstgcommon LIBS += $(LIB_THREAD) diff --git a/projects/stargazer/plugins/capture/cap_nf/Makefile b/projects/stargazer/plugins/capture/cap_nf/Makefile index 3eddb29e..b0f7713d 100644 --- a/projects/stargazer/plugins/capture/cap_nf/Makefile +++ b/projects/stargazer/plugins/capture/cap_nf/Makefile @@ -9,7 +9,7 @@ PROG = mod_cap_nf.so SRCS = ./cap_nf.cpp LIBS += $(LIB_THREAD) -STGLIBS = -lstg_common +STGLIBS = -lstgcommon include ../../Makefile.in diff --git a/projects/stargazer/plugins/capture/divert_freebsd/Makefile b/projects/stargazer/plugins/capture/divert_freebsd/Makefile index cd7824a7..2fbc97d6 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/Makefile +++ b/projects/stargazer/plugins/capture/divert_freebsd/Makefile @@ -8,7 +8,7 @@ PROG = mod_cap_divert.so SRCS = ./divert_cap.cpp -STGLIBS = -lstg_common +STGLIBS = -lstgcommon LIBS += $(LIB_THREAD) diff --git a/projects/stargazer/plugins/capture/ether_freebsd/Makefile b/projects/stargazer/plugins/capture/ether_freebsd/Makefile index 4ab0480c..f4b86e21 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/Makefile +++ b/projects/stargazer/plugins/capture/ether_freebsd/Makefile @@ -8,7 +8,7 @@ PROG = mod_cap_bpf.so SRCS = ./ether_cap.cpp -STGLIBS = -lstg_common +STGLIBS = -lstgcommon LIBS += $(LIB_THREAD) diff --git a/projects/stargazer/plugins/capture/ether_linux/Makefile b/projects/stargazer/plugins/capture/ether_linux/Makefile index f10886c6..4cd78a3c 100644 --- a/projects/stargazer/plugins/capture/ether_linux/Makefile +++ b/projects/stargazer/plugins/capture/ether_linux/Makefile @@ -9,7 +9,7 @@ PROG = mod_cap_ether.so SRCS = ./ether_cap.cpp LIBS += $(LIB_THREAD) -STGLIBS = -lstg_common +STGLIBS = -lstgcommon include ../../Makefile.in diff --git a/projects/stargazer/plugins/capture/ipq_linux/Makefile b/projects/stargazer/plugins/capture/ipq_linux/Makefile index 7cf92996..988cd948 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/Makefile +++ b/projects/stargazer/plugins/capture/ipq_linux/Makefile @@ -10,7 +10,7 @@ SRCS = ./ipq_cap.cpp \ ./libipq.c LIBS += $(LIB_THREAD) -STGLIBS = -lstg_common +STGLIBS = -lstgcommon include ../../Makefile.in diff --git a/projects/stargazer/plugins/configuration/rpcconfig/Makefile b/projects/stargazer/plugins/configuration/rpcconfig/Makefile index c2fb03d6..e0e09052 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/Makefile +++ b/projects/stargazer/plugins/configuration/rpcconfig/Makefile @@ -24,7 +24,7 @@ ifneq ($(OS),linux) LIBS += -liconv endif -STGLIBS = -lstg_common -lstg_logger +STGLIBS = -lstgcommon -lstglogger include ../../Makefile.in diff --git a/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp index 695da284..14319aa1 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp @@ -1,4 +1,4 @@ -#include "stg/stg_message.h" +#include "stg/message.h" #include "stg/common.h" #include "utils.h" #include "messages_methods.h" diff --git a/projects/stargazer/plugins/configuration/sgconfig-ng/Makefile b/projects/stargazer/plugins/configuration/sgconfig-ng/Makefile index 13bf5484..6d1a7a7b 100644 --- a/projects/stargazer/plugins/configuration/sgconfig-ng/Makefile +++ b/projects/stargazer/plugins/configuration/sgconfig-ng/Makefile @@ -18,6 +18,6 @@ SRCS = ./stgconfig.cpp \ LIBS += -lexpat \ -lboost_thread-mt -STGLIBS = -lstg_common -lstg_logger -lcrypto +STGLIBS = -lstgcommon -lstglogger -lcrypto include ../../Makefile.in diff --git a/projects/stargazer/plugins/configuration/sgconfig/Makefile b/projects/stargazer/plugins/configuration/sgconfig/Makefile index 8f065d16..f49ed018 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/Makefile +++ b/projects/stargazer/plugins/configuration/sgconfig/Makefile @@ -16,7 +16,7 @@ SRCS = ./stgconfig.cpp \ LIBS += -lexpat \ $(LIB_THREAD) -STGLIBS = -lstg_common -lstg_logger -lstg_crypto +STGLIBS = -lstgcommon -lstglogger -lstgcrypto include ../../Makefile.in diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.h b/projects/stargazer/plugins/configuration/sgconfig/configproto.h index 8c5aa3c5..efecd121 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -38,7 +38,7 @@ #include "stg/users.h" #include "stg/admins.h" #include "stg/tariffs.h" -#include "stg/stg_logger.h" +#include "stg/logger.h" #include "parser.h" #define STG_HEADER "SG04" diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.h b/projects/stargazer/plugins/configuration/sgconfig/parser.h index af85b710..da62dcb4 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.h @@ -12,12 +12,12 @@ #include #include "stg/resetable.h" -#include "stg/stg_const.h" +#include "stg/const.h" #include "stg/store.h" #include "stg/admins.h" #include "stg/admin.h" #include "stg/users.h" -#include "stg/stg_message.h" +#include "stg/message.h" class TARIFFS; class SETTINGS; diff --git a/projects/stargazer/plugins/configuration/sgconfig2/Makefile b/projects/stargazer/plugins/configuration/sgconfig2/Makefile index ab02cdff..290a616b 100644 --- a/projects/stargazer/plugins/configuration/sgconfig2/Makefile +++ b/projects/stargazer/plugins/configuration/sgconfig2/Makefile @@ -16,7 +16,7 @@ SRCS = ./stgconfig.cpp \ LIBS += -lexpat \ $(LIB_THREAD) -STGLIBS = -lstg_common -lstg_logger +STGLIBS = -lstgcommon -lstglogger include ../../Makefile.in diff --git a/projects/stargazer/plugins/configuration/sgconfig2/configproto.h b/projects/stargazer/plugins/configuration/sgconfig2/configproto.h index 7bdfb21f..5aea5499 100644 --- a/projects/stargazer/plugins/configuration/sgconfig2/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig2/configproto.h @@ -39,7 +39,7 @@ #include "users.h" #include "admins.h" #include "tariffs.h" -#include "stg_logger.h" +#include "logger.h" using namespace std; diff --git a/projects/stargazer/plugins/configuration/sgconfig2/parser.h b/projects/stargazer/plugins/configuration/sgconfig2/parser.h index 9e8a8bd9..7deac334 100644 --- a/projects/stargazer/plugins/configuration/sgconfig2/parser.h +++ b/projects/stargazer/plugins/configuration/sgconfig2/parser.h @@ -13,11 +13,11 @@ using namespace std; #include "resetable.h" -#include "stg_const.h" +#include "const.h" #include "store.h" #include "admins.h" #include "users.h" -#include "stg_message.h" +#include "message.h" //----------------------------------------------------------------------------- class BASE_PARSER { diff --git a/projects/stargazer/plugins/other/ping/Makefile b/projects/stargazer/plugins/other/ping/Makefile index 3e4d36d5..212bd288 100644 --- a/projects/stargazer/plugins/other/ping/Makefile +++ b/projects/stargazer/plugins/other/ping/Makefile @@ -10,7 +10,7 @@ PROG = mod_ping.so SRCS = ./ping.cpp -STGLIBS = -lstg_pinger -lstg_common +STGLIBS = -lstgpinger -lstgcommon include ../../Makefile.in diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index 5f87a99f..0fb5d30b 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -5,7 +5,7 @@ #include #include "stg/user.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "stg/user_property.h" #include "ping.h" diff --git a/projects/stargazer/plugins/other/radius/Makefile b/projects/stargazer/plugins/other/radius/Makefile index 68be7618..9735fb67 100644 --- a/projects/stargazer/plugins/other/radius/Makefile +++ b/projects/stargazer/plugins/other/radius/Makefile @@ -10,7 +10,7 @@ PROG = mod_radius.so SRCS = ./radius.cpp -STGLIBS = -lstg_common -lstg_crypto +STGLIBS = -lstgcommon -lstgcrypto include ../../Makefile.in diff --git a/projects/stargazer/plugins/other/rscript/Makefile b/projects/stargazer/plugins/other/rscript/Makefile index cad853c7..343d1150 100644 --- a/projects/stargazer/plugins/other/rscript/Makefile +++ b/projects/stargazer/plugins/other/rscript/Makefile @@ -11,7 +11,7 @@ PROG = mod_remote_script.so SRCS = ./rscript.cpp \ ./nrmap_parser.cpp -STGLIBS = -lstg_common -lstg_crypto +STGLIBS = -lstgcommon -lstgcrypto include ../../Makefile.in diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index df172364..12c00a40 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -32,7 +32,7 @@ #include #include "stg/common.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "stg/user_property.h" #include "rscript.h" #include "ur_functor.h" diff --git a/projects/stargazer/plugins/other/userstat/Makefile b/projects/stargazer/plugins/other/userstat/Makefile index 0046e2cf..ccc63727 100644 --- a/projects/stargazer/plugins/other/userstat/Makefile +++ b/projects/stargazer/plugins/other/userstat/Makefile @@ -23,8 +23,8 @@ PROG = mod_userstat.so SRCS = ./userstat.cpp \ ./datathread.cpp -LIBS += -lstg_common \ - -lstg_crypto +LIBS += -lstgcommon \ + -lstgcrypto include ../../Makefile.in diff --git a/projects/stargazer/plugins/store/files/Makefile b/projects/stargazer/plugins/store/files/Makefile index 3357a501..8bf5777a 100644 --- a/projects/stargazer/plugins/store/files/Makefile +++ b/projects/stargazer/plugins/store/files/Makefile @@ -8,7 +8,7 @@ PROG = mod_store_files.so SRCS = ./file_store.cpp -STGLIBS = -lconffiles -lstg_common -lstg_locker -lstg_crypto +STGLIBS = -lstgconffiles -lstgcommon -lstglocker -lstgcrypto include ../../Makefile.in diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index 555020b7..a0c3f915 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -47,10 +47,10 @@ #include "stg/user_ips.h" #include "stg/user_conf.h" #include "stg/user_stat.h" -#include "stg/stg_const.h" +#include "stg/const.h" #include "stg/blowfish.h" -#include "stg/stg_logger.h" -#include "stg/stg_locker.h" +#include "stg/logger.h" +#include "stg/locker.h" #include "file_store.h" #define DELETED_USERS_DIR "deleted_users" diff --git a/projects/stargazer/plugins/store/firebird/Makefile b/projects/stargazer/plugins/store/firebird/Makefile index 7304d4de..8b175fd9 100644 --- a/projects/stargazer/plugins/store/firebird/Makefile +++ b/projects/stargazer/plugins/store/firebird/Makefile @@ -17,7 +17,7 @@ SRCS = ./firebird_store.cpp \ ./firebird_store_users.cpp \ ./firebird_store_utils.cpp -STGLIBS = -libpp -lstg_common -lstg_locker -lstg_crypto +STGLIBS = -libpp -lstgcommon -lstglocker -lstgcrypto include ../../Makefile.in diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.h b/projects/stargazer/plugins/store/firebird/firebird_store.h index 73c2f19e..69815fe5 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.h +++ b/projects/stargazer/plugins/store/firebird/firebird_store.h @@ -35,7 +35,7 @@ #include #include "stg/store.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "stg/ibpp.h" struct ToLower { diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp index 5e959abd..a31ca3f8 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp @@ -26,7 +26,7 @@ * */ -#include "stg/stg_const.h" +#include "stg/const.h" #include "firebird_store.h" #include "stg/ibpp.h" diff --git a/projects/stargazer/plugins/store/mysql/Makefile b/projects/stargazer/plugins/store/mysql/Makefile index 0c01bd5a..81196222 100644 --- a/projects/stargazer/plugins/store/mysql/Makefile +++ b/projects/stargazer/plugins/store/mysql/Makefile @@ -8,7 +8,7 @@ PROG = mod_store_mysql.so SRCS = ./mysql_store.cpp -STGLIBS = -lstg_common -lstg_crypto +STGLIBS = -lstgcommon -lstgcrypto MYSQL_CFLAGS = $(shell mysql_config --cflags) MYSQL_LDFLAGS = $(shell mysql_config --libs_r) diff --git a/projects/stargazer/plugins/store/postgresql/Makefile b/projects/stargazer/plugins/store/postgresql/Makefile index 522058dd..fa6ebf0d 100644 --- a/projects/stargazer/plugins/store/postgresql/Makefile +++ b/projects/stargazer/plugins/store/postgresql/Makefile @@ -15,7 +15,7 @@ SRCS = ./postgresql_store.cpp \ ./postgresql_store_users.cpp \ ./postgresql_store_utils.cpp -STGLIBS = -lstg_common -lstg_crypto +STGLIBS = -lstgcommon -lstgcrypto PG_CFLAGS = $(shell pg_config --includedir) PG_LDFLAGS = $(shell pg_config --libdir) diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp index 9670ce83..5b27cb80 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp @@ -32,7 +32,7 @@ #include -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "stg/admin_conf.h" #include "stg/blowfish.h" #include "postgresql_store.h" diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp index 08848ea4..c358a4c5 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp @@ -33,7 +33,7 @@ #include #include "postgresql_store.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetCorpsList(vector * corpsList) const diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp index e4c87cdd..4260c3b4 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp @@ -34,8 +34,8 @@ #include #include "postgresql_store.h" -#include "stg/stg_locker.h" -#include "stg/stg_message.h" +#include "stg/locker.h" +#include "stg/message.h" //----------------------------------------------------------------------------- int POSTGRESQL_STORE::AddMessage(STG_MSG * msg, const string & login) const diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp index 82a999f7..b509c0f0 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp @@ -34,7 +34,7 @@ #include #include "postgresql_store.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetServicesList(vector * servicesList) const diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp index fc35f788..bb647563 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp @@ -33,7 +33,7 @@ #include #include "postgresql_store.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetTariffsList(vector * tariffsList) const diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp index c1c48e25..11c757f2 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp @@ -33,8 +33,8 @@ #include -#include "stg/stg_const.h" -#include "stg/stg_locker.h" +#include "stg/const.h" +#include "stg/locker.h" #include "../../../stg_timer.h" #include "postgresql_store.h" diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index 361993c9..e0eb4639 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -32,7 +32,7 @@ $Author: faust $ #include #include -#include "stg/stg_logger.h" +#include "stg/logger.h" #include "stg/dotconfpp.h" #include "settings_impl.h" diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index f7ded853..c7829b27 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -42,7 +42,7 @@ #include "stg/settings.h" #include "stg/common.h" -#include "stg/stg_logger.h" +#include "stg/logger.h" #include "stg/module_settings.h" //----------------------------------------------------------------------------- diff --git a/projects/stargazer/tariffs_impl.cpp b/projects/stargazer/tariffs_impl.cpp index c244cb69..61e3e12c 100644 --- a/projects/stargazer/tariffs_impl.cpp +++ b/projects/stargazer/tariffs_impl.cpp @@ -32,8 +32,8 @@ #include #include -#include "stg/stg_locker.h" -#include "stg/stg_logger.h" +#include "stg/locker.h" +#include "stg/logger.h" #include "stg/store.h" #include "stg/admin.h" #include "tariffs_impl.h" diff --git a/projects/stargazer/traffcounter_impl.cpp b/projects/stargazer/traffcounter_impl.cpp index 45ba883e..3f6eb0c0 100644 --- a/projects/stargazer/traffcounter_impl.cpp +++ b/projects/stargazer/traffcounter_impl.cpp @@ -39,7 +39,7 @@ #include // fopen and similar #include "stg/common.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" #include "traffcounter_impl.h" #include "stg_timer.h" diff --git a/projects/stargazer/traffcounter_impl.h b/projects/stargazer/traffcounter_impl.h index 27e7c03c..c30f6be4 100644 --- a/projects/stargazer/traffcounter_impl.h +++ b/projects/stargazer/traffcounter_impl.h @@ -37,7 +37,7 @@ #include "stg/traffcounter.h" #include "stg/os_int.h" -#include "stg/stg_logger.h" +#include "stg/logger.h" #include "stg/raw_ip_packet.h" #include "stg/users.h" #include "stg/noncopyable.h" diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index 935dcd0e..be28cc96 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -34,13 +34,13 @@ #include "stg/user.h" #include "stg/os_int.h" -#include "stg/stg_const.h" +#include "stg/const.h" #include "stg/user_stat.h" #include "stg/user_conf.h" #include "stg/user_ips.h" #include "stg/user_property.h" #include "stg/auth.h" -#include "stg/stg_message.h" +#include "stg/message.h" #include "stg/noncopyable.h" //----------------------------------------------------------------------------- diff --git a/projects/stargazer/users_impl.h b/projects/stargazer/users_impl.h index 37edef7a..f0b8ae25 100644 --- a/projects/stargazer/users_impl.h +++ b/projects/stargazer/users_impl.h @@ -41,7 +41,7 @@ $Author: faust $ #include "stg/users.h" #include "stg/user.h" #include "stg/tariffs.h" -#include "stg/stg_logger.h" +#include "stg/logger.h" #include "stg/notifer.h" #include "stg/noncopyable.h" #include "actions.h" diff --git a/stglibs/common.lib/Makefile b/stglibs/common.lib/Makefile index eb0959b7..3e52ad8d 100644 --- a/stglibs/common.lib/Makefile +++ b/stglibs/common.lib/Makefile @@ -4,11 +4,11 @@ include ../../Makefile.conf -LIB_NAME = stg_common +LIB_NAME = stgcommon PROG = lib$(LIB_NAME) SRCS = common.cpp \ - stg_strptime.cpp + strptime.cpp INCS = common.h diff --git a/stglibs/common.lib/common.h b/stglibs/common.lib/common.h index beba4508..3752822a 100644 --- a/stglibs/common.lib/common.h +++ b/stglibs/common.lib/common.h @@ -35,7 +35,7 @@ #include #include "stg/os_int.h" -#include "stg/stg_const.h" +#include "stg/const.h" #define STAT_TIME_3 (1) #define STAT_TIME_2 (2) diff --git a/stglibs/common.lib/stg_strptime.cpp b/stglibs/common.lib/stg_strptime.cpp deleted file mode 100644 index 0e1fde27..00000000 --- a/stglibs/common.lib/stg_strptime.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * $Revision: 1.1 $ - * $Date: 2007/05/17 08:25:58 $ - * - * This file contain a replacement of commonly used function strptime - * Under some OS's it appears only with _XOPEN_SOURCE definition - * - */ - -#define _XOPEN_SOURCE -#include - -char * stg_strptime(const char * a, const char * b, struct tm * tm) -{ -return strptime(a, b, tm); -} - diff --git a/stglibs/common.lib/strptime.cpp b/stglibs/common.lib/strptime.cpp new file mode 100644 index 00000000..0e1fde27 --- /dev/null +++ b/stglibs/common.lib/strptime.cpp @@ -0,0 +1,17 @@ +/* + * $Revision: 1.1 $ + * $Date: 2007/05/17 08:25:58 $ + * + * This file contain a replacement of commonly used function strptime + * Under some OS's it appears only with _XOPEN_SOURCE definition + * + */ + +#define _XOPEN_SOURCE +#include + +char * stg_strptime(const char * a, const char * b, struct tm * tm) +{ +return strptime(a, b, tm); +} + diff --git a/stglibs/conffiles.lib/Makefile b/stglibs/conffiles.lib/Makefile index 2cd4fb3d..28505b6f 100644 --- a/stglibs/conffiles.lib/Makefile +++ b/stglibs/conffiles.lib/Makefile @@ -2,7 +2,7 @@ # $Id: Makefile,v 1.4 2007/05/08 14:29:19 faust Exp $ ############################################################################### -LIB_NAME = conffiles +LIB_NAME = stgconffiles PROG = lib$(LIB_NAME) SRCS = conffiles.cpp diff --git a/stglibs/crypto.lib/Makefile b/stglibs/crypto.lib/Makefile index 6fe383ad..36ef7ee6 100644 --- a/stglibs/crypto.lib/Makefile +++ b/stglibs/crypto.lib/Makefile @@ -2,7 +2,7 @@ # $Id: Makefile,v 1.5 2009/10/09 07:15:48 nobunaga Exp $ ############################################################################### -LIB_NAME = stg_crypto +LIB_NAME = stgcrypto PROG = lib$(LIB_NAME) SRCS = ag_md5.cpp \ diff --git a/stglibs/crypto.lib/blowfish.cpp b/stglibs/crypto.lib/blowfish.cpp index e9d2bde4..ad482b79 100644 --- a/stglibs/crypto.lib/blowfish.cpp +++ b/stglibs/crypto.lib/blowfish.cpp @@ -8,7 +8,7 @@ #include #include "blowfish.h" -#include "stg/stg_const.h" +#include "stg/const.h" /*typedef struct _BCoptions { diff --git a/stglibs/ia.lib/Makefile b/stglibs/ia.lib/Makefile new file mode 100644 index 00000000..f6638bce --- /dev/null +++ b/stglibs/ia.lib/Makefile @@ -0,0 +1,16 @@ +############################################################################### +# $Id: Makefile,v 1.11 2010/08/18 07:47:03 faust Exp $ +############################################################################### + +LIB_NAME = stgia +PROG = lib$(LIB_NAME) + +SRCS = ia.cpp + +INCS = ia.h + +STGLIBS = -lstgcommon \ + -lstgcrypto +LIBS = $(LIB_THREAD) + +include ../Makefile.in diff --git a/stglibs/ia.lib/ia.bpf b/stglibs/ia.lib/ia.bpf new file mode 100644 index 00000000..e3c42ce0 --- /dev/null +++ b/stglibs/ia.lib/ia.bpf @@ -0,0 +1,9 @@ +//--------------------------------------------------------------------------- + +#include +#pragma hdrstop +#define Library + +// To add a file to the library use the Project menu 'Add to Project'. + + \ No newline at end of file diff --git a/stglibs/ia.lib/ia.bpr b/stglibs/ia.lib/ia.bpr new file mode 100644 index 00000000..c80bf51c --- /dev/null +++ b/stglibs/ia.lib/ia.bpr @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=1049 +CodePage=1251 + +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= + +[HistoryLists\hlIncludePath] +Count=2 +Item0=$(BCB)\include;$(BCB)\include\vcl;..\..\include +Item1=$(BCB)\include;$(BCB)\include\vcl + +[HistoryLists\hlLibraryPath] +Count=1 +Item0=$(BCB)\lib\obj;$(BCB)\lib + +[HistoryLists\hlDebugSourcePath] +Count=1 +Item0=$(BCB)\source\vcl + +[HistoryLists\hlConditionals] +Count=2 +Item0=_DEBUG;WIN32 +Item1=_DEBUG + +[HistoryLists\hlFinalOutputDir] +Count=1 +Item0=..\..\lib + +[Debugging] +DebugSourceDirs=$(BCB)\source\vcl + +[Parameters] +RunParams= +Launcher= +UseLauncher=0 +DebugCWD= +HostApplication= +RemoteHost= +RemotePath= +RemoteLauncher= +RemoteCWD= +RemoteDebug=0 + +[Compiler] +ShowInfoMsgs=0 +LinkDebugVcl=0 +LinkCGLIB=0 + +[CORBA] +AddServerUnit=1 +AddClientUnit=1 +PrecompiledHeaders=1 + + \ No newline at end of file diff --git a/stglibs/ia.lib/ia.cpp b/stglibs/ia.lib/ia.cpp new file mode 100644 index 00000000..f08c4614 --- /dev/null +++ b/stglibs/ia.lib/ia.cpp @@ -0,0 +1,840 @@ +/* +** 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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + $Author: faust $ + $Revision: 1.15 $ + $Date: 2010/04/16 11:28:03 $ +*/ + +/* +* Author : +* Boris Mikhailenko +* Maxim Mamontov +* Andrey Rakhmanov - bugfixes. +*/ + +//--------------------------------------------------------------------------- + +#include +#include +#include +#include + +#ifdef WIN32 + #include + #include + #include + #include +#else + #include + #include + #include + #include + #include + #include + #include +#endif + +#include "stg/common.h" +#include "ia.h" + +#define IA_NONE (0) +#define IA_CONNECT (1) +#define IA_DISCONNECT (2) + +#define IA_DEBUGPROTO 1 + +#define IA_ID "00100" +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +#ifndef WIN32 +#include +void * RunL(void * data) +{ + +IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data; +static int a = 0; + +if (a == 0) + { + usleep(50000); + a = 1; + } + +while (c->GetNonstop()) + { + c->Run(); + } +return NULL; +} +//--------------------------------------------------------------------------- +void Sleep(int ms) +{ +usleep(ms * 1000); +} +//--------------------------------------------------------------------------- +long GetTickCount() +{ +struct timeval tv; +gettimeofday(&tv, NULL); +return tv.tv_sec*1000 + tv.tv_usec/1000; +} +#else +//--------------------------------------------------------------------------- +unsigned long WINAPI RunW(void * data) +{ +IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data; +while (c->GetNonstop()) + c->Run(); +return 0; +} +//--------------------------------------------------------------------------- +#endif +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +IA_CLIENT_PROT::IA_CLIENT_PROT(const string & sn, unsigned short p, uint16_t localPort) + : action(IA_NONE), + phase(1), + phaseTime(0), + codeError(0), + nonstop(false), + isNetPrepared(false), + proxyMode(false), + serverName(sn), + port(p), + ip(0), + localPort(localPort), + firstConnect(true), + reconnect(0), + sockr(0), + protNum(0), + userTimeout(60), + aliveTimeout(5), + rnd(0), + pStatusChangedCb(NULL), + pStatChangedCb(NULL), + pInfoCb(NULL), + pErrorCb(NULL), + pDirNameCb(NULL), + statusChangedCbData(NULL), + statChangedCbData(NULL), + infoCbData(NULL), + errorCbData(NULL), + dirNameCbData(NULL), + connSyn8(NULL), + connSynAck8(NULL), + connAck8(NULL), + aliveSyn8(NULL), + aliveAck8(NULL), + disconnSyn8(NULL), + disconnSynAck8(NULL), + disconnAck8(NULL), + info(NULL) +{ +memset(&stat, 0, sizeof(stat)); + +#ifdef WIN32 +WSAStartup(MAKEWORD(2, 0), &wsaData); +#endif + +packetTypes["CONN_SYN"] = CONN_SYN_N; +packetTypes["CONN_SYN_ACK"] = CONN_SYN_ACK_N; +packetTypes["CONN_ACK"] = CONN_ACK_N; +packetTypes["ALIVE_SYN"] = ALIVE_SYN_N; +packetTypes["ALIVE_ACK"] = ALIVE_ACK_N; +packetTypes["DISCONN_SYN"] = DISCONN_SYN_N; +packetTypes["DISCONN_SYN_ACK"] = DISCONN_SYN_ACK_N; +packetTypes["DISCONN_ACK"] = DISCONN_ACK_N; +packetTypes["FIN"] = FIN_N; +packetTypes["ERR"] = ERROR_N; +packetTypes["INFO"] = INFO_N; +packetTypes["INFO_7"] = INFO_7_N; +packetTypes["INFO_8"] = INFO_8_N; + +unsigned char key[IA_PASSWD_LEN]; +memset(key, 0, IA_PASSWD_LEN); +strncpy((char *)key, "pr7Hhen", 8); +Blowfish_Init(&ctxHdr, key, IA_PASSWD_LEN); + +memset(key, 0, IA_PASSWD_LEN); +Blowfish_Init(&ctxPass, key, IA_PASSWD_LEN); + +for (size_t i = 0; i < DIR_NUM; ++i) + { + selectedDirs[i] = false; + } + +servAddr.sin_family = AF_INET; +servAddr.sin_port = htons(port); +servAddr.sin_addr.s_addr = ip; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::PrepareNet() +{ +struct hostent * phe; +unsigned long ip; + +ip = inet_addr(serverName.c_str()); +if (ip == INADDR_NONE) + { + phe = gethostbyname(serverName.c_str()); + if (phe) + { + ip = *((unsigned long*)phe->h_addr_list[0]); + } + else + { + strError = string("Unknown host ") + "\'" + serverName + "\'"; + codeError = IA_GETHOSTBYNAME_ERROR; + if (pErrorCb != NULL) + pErrorCb(strError, IA_GETHOSTBYNAME_ERROR, errorCbData); + } + } + +#ifndef WIN32 +close(sockr); +#else +closesocket(sockr); +#endif + +sockr = socket(AF_INET, SOCK_DGRAM, 0); + +struct sockaddr_in localAddrR; +localAddrR.sin_family = AF_INET; + +if (localPort) + localAddrR.sin_port = htons(localPort); +else + localAddrR.sin_port = htons(port); +localAddrR.sin_addr.s_addr = inet_addr("0.0.0.0"); + +servAddr.sin_family = AF_INET; +servAddr.sin_port = htons(port); +servAddr.sin_addr.s_addr = ip; + +int res = bind(sockr, (struct sockaddr*)&localAddrR, sizeof(localAddrR)); +if (res == -1) + { + strError = "bind error"; + codeError = IA_BIND_ERROR; + if (pErrorCb != NULL) + pErrorCb(strError, IA_BIND_ERROR, errorCbData); + return; + } + +#ifdef WIN32 +unsigned long arg = 1; +res = ioctlsocket(sockr, FIONBIO, &arg); +#else +if (0 != fcntl(sockr, F_SETFL, O_NONBLOCK)) + { + strError = "fcntl error"; + codeError = IA_FCNTL_ERROR; + if (pErrorCb != NULL) + pErrorCb(strError, IA_FCNTL_ERROR, errorCbData); + } +#endif + +} +//--------------------------------------------------------------------------- +IA_CLIENT_PROT::~IA_CLIENT_PROT() +{ +#ifndef WIN32 +close(sockr); +#else +closesocket(sockr); +WSACleanup(); +#endif +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::DeterminatePacketType(const char * buffer) +{ +map::iterator pi; +pi = packetTypes.find(buffer); +if (pi == packetTypes.end()) + { + return -1; + } +else + { + return pi->second; + } +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::FillHdr8(char * buffer, unsigned long) +{ +strncpy(buffer, IA_ID, 6); +buffer[IA_MAGIC_LEN] = 0; +buffer[IA_MAGIC_LEN + 1] = IA_PROTO_VER; +strncpy(buffer + sizeof(HDR_8), login.c_str(), IA_LOGIN_LEN); +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Send(char * buffer, int len) +{ +if (!isNetPrepared) + { + PrepareNet(); + isNetPrepared = true; + } + +int db = sizeof(HDR_8); +for (int i = 0; i < IA_LOGIN_LEN/8; i++) + { + Blowfish_Encrypt(&ctxHdr, (uint32_t*)(buffer + db + i*8), (uint32_t*)(buffer + db + i*8 + 4)); + } + +db += IA_LOGIN_LEN; +int encLen = (len - sizeof(HDR_8) - IA_LOGIN_LEN)/8; +for (int i = 0; i < encLen; i++) + { + Blowfish_Encrypt(&ctxPass, (uint32_t*)(buffer + db), (uint32_t*)(buffer + db + 4)); + db += 8; + } + +return sendto(sockr, buffer, len, 0, (struct sockaddr*)&servAddr, sizeof(servAddr)); +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Recv(char * buffer, int len) +{ +#ifdef WIN32 +int fromLen; +#else +socklen_t fromLen; +#endif + +struct sockaddr_in addr; +fromLen = sizeof(addr); +int res = recvfrom(sockr, buffer, len, 0, (struct sockaddr*)&addr, &fromLen); + +if (res == -1) + return res; + +if (strcmp(buffer + 4 + sizeof(HDR_8), "ERR")) + { + for (int i = 0; i < len/8; i++) + Blowfish_Decrypt(&ctxPass, (uint32_t*)(buffer + i*8), (uint32_t*)(buffer + i*8 + 4)); + } + +return 0; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::NetSend(int n) +{ +char buffer[2048]; +int msgLen; + +memset(buffer, 0, 2048); + +switch (n) + { + case CONN_SYN_N: + msgLen = Prepare_CONN_SYN_8(buffer); + break; + + case CONN_ACK_N: + msgLen = Prepare_CONN_ACK_8(buffer); + break; + + case ALIVE_ACK_N: + msgLen = Prepare_ALIVE_ACK_8(buffer); + break; + + case DISCONN_SYN_N: + msgLen = Prepare_DISCONN_SYN_8(buffer); + break; + + case DISCONN_ACK_N: + msgLen = Prepare_DISCONN_ACK_8(buffer); + break; + + default: + return -1; + } + +FillHdr8(buffer, 0); +Send(buffer, msgLen); + +return 0; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::NetRecv() +{ +char buffer[2048]; + +if (Recv(buffer, sizeof(buffer)) < 0) + return -1; + +char packetName[20]; +strncpy(packetName, buffer + 12, sizeof(packetName)); +packetName[sizeof(packetName) - 1] = 0; +int pn = DeterminatePacketType(buffer + 12); + +int ret; +switch (pn) + { + case CONN_SYN_ACK_N: + ret = Process_CONN_SYN_ACK_8(buffer); + break; + + case ALIVE_SYN_N: + ret = Process_ALIVE_SYN_8(buffer); + break; + + case DISCONN_SYN_ACK_N: + ret = Process_DISCONN_SYN_ACK_8(buffer); + break; + + case FIN_N: + ret = Process_FIN_8(buffer); + break; + + case INFO_8_N: + ret = Process_INFO_8(buffer); + break; + + case ERROR_N: + ret = Process_ERROR(buffer); + break; + + default: + ret = -1; + } +return ret; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::Start() +{ +nonstop = true; +#ifdef WIN32 +unsigned long pt; +CreateThread(NULL, 16384, RunW, this, 0, &pt); +#else +pthread_create(&thread, NULL, RunL, this); +#endif +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::Stop() +{ +nonstop = false; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::Run() +{ +NetRecv(); + +switch (phase) + { + case 1: + if (action == IA_CONNECT) + { + action = IA_NONE; + NetSend(CONN_SYN_N); + phase = 2; + phaseTime = GetTickCount(); + } + if (reconnect && !firstConnect) + { + action = IA_CONNECT; + } + break; + + case 2: + if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) + { + phase = 1; + phaseTime = GetTickCount(); + if (pStatusChangedCb != NULL) + pStatusChangedCb(0, statusChangedCbData); + } + + if (action == IA_DISCONNECT) + { + action = IA_NONE; + NetSend(DISCONN_SYN_N); + phase = 4; + phaseTime = GetTickCount(); + } + + break; + + case 3: + if ((int)(GetTickCount() - phaseTime)/1000 > userTimeout) + { + phase = 1; + phaseTime = GetTickCount(); + if (pStatusChangedCb != NULL) + pStatusChangedCb(0, statusChangedCbData); + firstConnect = false; + } + + if (action == IA_DISCONNECT) + { + action = IA_NONE; + NetSend(DISCONN_SYN_N); + phase = 4; + phaseTime = GetTickCount(); + } + + break; + + case 4: + if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) + { + phase=1; + phaseTime = GetTickCount(); + if (pStatusChangedCb != NULL) + pStatusChangedCb(0, statusChangedCbData); + } + + if (action == IA_CONNECT) + { + action = IA_NONE; + NetSend(CONN_SYN_N); + phase = 2; + phaseTime = GetTickCount(); + } + + break; + + case 5: + if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) + { + phase = 1; + phaseTime = GetTickCount(); + if (pStatusChangedCb != NULL) + pStatusChangedCb(0, statusChangedCbData); + } + + if (action == IA_CONNECT) + { + action = IA_NONE; + NetSend(CONN_SYN_N); + phase = 2; + phaseTime = GetTickCount(); + } + + break; + } +Sleep(20); +return; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::GetStat(LOADSTAT * ls) +{ +memcpy(ls, &stat, sizeof(stat)); +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetServer(const string & sn, unsigned short p) +{ +serverName = sn; +port = p; +PrepareNet(); +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetLogin(const string & l) +{ +login = l; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetPassword(const string & p) +{ +password = p; + +unsigned char keyL[IA_PASSWD_LEN]; +memset(keyL, 0, IA_PASSWD_LEN); +strncpy((char *)keyL, password.c_str(), IA_PASSWD_LEN); +Blowfish_Init(&ctxPass, keyL, IA_PASSWD_LEN); +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetEnabledDirs(const bool * selectedDirs) +{ +memcpy(IA_CLIENT_PROT::selectedDirs, selectedDirs, sizeof(bool) * DIR_NUM); +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Connect() +{ +action = IA_CONNECT; +return 0; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Disconnect() +{ +firstConnect = true; +action = IA_DISCONNECT; +return 0; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::GetStrError(string * error) const +{ +int ret = codeError; +*error = strError; +strError = ""; +codeError = 0; +return ret; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Process_CONN_SYN_ACK_8(const char * buffer) +{ +vector dirNames; +connSynAck8 = (CONN_SYN_ACK_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(connSynAck8->len); +SwapBytes(connSynAck8->rnd); +SwapBytes(connSynAck8->userTimeOut); +SwapBytes(connSynAck8->aliveDelay); +#endif + +rnd = connSynAck8->rnd; +userTimeout = connSynAck8->userTimeOut; +aliveTimeout = connSynAck8->aliveDelay; + +for (int i = 0; i < DIR_NUM; i++) + { + dirNames.push_back((const char*)connSynAck8->dirName[i]); + } + +if (pDirNameCb != NULL) + pDirNameCb(dirNames, dirNameCbData); + +NetSend(CONN_ACK_N); +phase = 3; +phaseTime = GetTickCount(); + +return CONN_SYN_ACK_N; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Process_ALIVE_SYN_8(const char * buffer) +{ +aliveSyn8 = (ALIVE_SYN_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(aliveSyn8->len); +SwapBytes(aliveSyn8->rnd); +SwapBytes(aliveSyn8->cash); +SwapBytes(aliveSyn8->status); +for (int i = 0; i < DIR_NUM; ++i) + { + SwapBytes(aliveSyn8->mu[i]); + SwapBytes(aliveSyn8->md[i]); + SwapBytes(aliveSyn8->su[i]); + SwapBytes(aliveSyn8->sd[i]); + } +#endif + +rnd = aliveSyn8->rnd; +memcpy(&stat, (char*)aliveSyn8->mu, sizeof(stat)); + +if (pStatChangedCb != NULL) + pStatChangedCb(stat, statChangedCbData); + +if (pStatusChangedCb != NULL) + pStatusChangedCb(1, statusChangedCbData); +NetSend(ALIVE_ACK_N); +phaseTime = GetTickCount(); + +return ALIVE_SYN_N; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Process_DISCONN_SYN_ACK_8(const char * buffer) +{ +disconnSynAck8 = (DISCONN_SYN_ACK_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(disconnSynAck8->len); +SwapBytes(disconnSynAck8->rnd); +#endif + +rnd = disconnSynAck8->rnd; + +NetSend(DISCONN_ACK_N); +phase = 5; +phaseTime = GetTickCount(); + +return DISCONN_SYN_ACK_N; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Process_FIN_8(const char *) +{ +phase = 1; +phaseTime = GetTickCount(); +if (pStatusChangedCb != NULL) + pStatusChangedCb(0, statusChangedCbData); + +return FIN_N; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Process_INFO_8(const char * buffer) +{ +info = (INFO_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(info->len); +SwapBytes(info->sendTime); +#endif + +if (pInfoCb != NULL) + pInfoCb((char*)info->text, info->infoType, info->showTime, info->sendTime, infoCbData); +return INFO_8_N; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Process_ERROR(const char * buffer) +{ +ERR_8 err; +memcpy(&err, buffer, sizeof(err)); + +#ifdef ARCH_BE +SwapBytes(err.len); +#endif + +KOIToWin((const char*)err.text, &messageText); +if (pErrorCb != NULL) + pErrorCb(messageText, IA_SERVER_ERROR, errorCbData); +phase = 1; +phaseTime = GetTickCount(); +codeError = IA_SERVER_ERROR; + +return ERROR_N; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Prepare_CONN_SYN_8(char * buffer) +{ +connSyn8 = (CONN_SYN_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(connSyn8->len); +#endif + +assert(sizeof(CONN_SYN_8) == Min8(sizeof(CONN_SYN_8)) && "CONN_SYN_8 is not aligned to 8 bytes"); + +connSyn8->len = sizeof(CONN_SYN_8); +strncpy((char*)connSyn8->type, "CONN_SYN", IA_MAX_TYPE_LEN); +strncpy((char*)connSyn8->login, login.c_str(), IA_LOGIN_LEN); +connSyn8->dirs = 0; +for (int i = 0; i < DIR_NUM; i++) + { + connSyn8->dirs |= (selectedDirs[i] << i); + } +return connSyn8->len; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Prepare_CONN_ACK_8(char * buffer) +{ +connAck8 = (CONN_ACK_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(connAck8->len); +SwapBytes(connAck8->rnd); +#endif + +assert(sizeof(CONN_ACK_8) == Min8(sizeof(CONN_ACK_8)) && "CONN_ACK_8 is not aligned to 8 bytes"); + +connAck8->len = sizeof(CONN_ACK_8); +strncpy((char*)connAck8->loginS, login.c_str(), IA_LOGIN_LEN); +strncpy((char*)connAck8->type, "CONN_ACK", IA_MAX_TYPE_LEN); +rnd++; +connAck8->rnd = rnd; + +return connAck8->len; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Prepare_ALIVE_ACK_8(char * buffer) +{ +aliveAck8 = (ALIVE_ACK_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(aliveAck8->len); +SwapBytes(aliveAck8->rnd); +#endif + +assert(Min8(sizeof(ALIVE_ACK_8)) == sizeof(ALIVE_ACK_8) && "ALIVE_ACK_8 is not aligned to 8 bytes"); + +aliveAck8 = (ALIVE_ACK_8*)buffer; +aliveAck8->len = sizeof(ALIVE_ACK_8); +strncpy((char*)aliveAck8->loginS, login.c_str(), IA_LOGIN_LEN); +strncpy((char*)aliveAck8->type, "ALIVE_ACK", IA_MAX_TYPE_LEN); +aliveAck8->rnd = ++rnd; +return aliveAck8->len; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Prepare_DISCONN_SYN_8(char * buffer) +{ +disconnSyn8 = (DISCONN_SYN_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(disconnSyn8->len); +#endif + +assert(Min8(sizeof(DISCONN_SYN_8)) == sizeof(DISCONN_SYN_8) && "DISCONN_SYN_8 is not aligned to 8 bytes"); + +disconnSyn8->len = sizeof(DISCONN_SYN_8); +strncpy((char*)disconnSyn8->loginS, login.c_str(), IA_LOGIN_LEN); +strncpy((char*)disconnSyn8->type, "DISCONN_SYN", IA_MAX_TYPE_LEN); +strncpy((char*)disconnSyn8->login, login.c_str(), IA_LOGIN_LEN); +return disconnSyn8->len; +} +//--------------------------------------------------------------------------- +int IA_CLIENT_PROT::Prepare_DISCONN_ACK_8(char * buffer) +{ +disconnAck8 = (DISCONN_ACK_8*)buffer; + +#ifdef ARCH_BE +SwapBytes(disconnAck8->len); +SwapBytes(disconnAck8->rnd); +#endif + +assert(Min8(sizeof(DISCONN_ACK_8)) == sizeof(DISCONN_ACK_8) && "DISCONN_ACK_8 is not aligned to 8 bytes"); + +disconnAck8->len = Min8(sizeof(DISCONN_ACK_8)); +disconnAck8->rnd = rnd + 1; +strncpy((char*)disconnAck8->loginS, login.c_str(), IA_LOGIN_LEN); +strncpy((char*)disconnAck8->type, "DISCONN_ACK", IA_MAX_TYPE_LEN); +return disconnAck8->len; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetStatusChangedCb(tpStatusChangedCb p, void * data) +{ +pStatusChangedCb = p; +statusChangedCbData = data; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetStatChangedCb(tpStatChangedCb p, void * data) +{ +pStatChangedCb = p; +statChangedCbData = data; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetInfoCb(tpCallBackInfoFn p, void * data) +{ +pInfoCb = p; +infoCbData = data; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetDirNameCb(tpCallBackDirNameFn p, void * data) +{ +pDirNameCb = p; +dirNameCbData = data; +} +//--------------------------------------------------------------------------- +void IA_CLIENT_PROT::SetErrorCb(tpCallBackErrorFn p, void * data) +{ +pErrorCb = p; +errorCbData = data; +} +//--------------------------------------------------------------------------- diff --git a/stglibs/ia.lib/ia.h b/stglibs/ia.lib/ia.h new file mode 100644 index 00000000..0a916f4c --- /dev/null +++ b/stglibs/ia.lib/ia.h @@ -0,0 +1,204 @@ +/* +** 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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + $Author: faust $ + $Revision: 1.10 $ + $Date: 2010/03/15 12:57:24 $ +*/ + +/* +* Author : Boris Mikhailenko +*/ +//--------------------------------------------------------------------------- +#ifndef IA_AUTH_C_H +#define IA_AUTH_C_H + +#ifndef WIN32 +#include +#include +#else +#include +#endif + +#include +#include +#include + +#include "stg/blowfish.h" +#include "stg/ia_packets.h" + +#define IA_BIND_ERROR (1) +#define IA_SERVER_ERROR (2) +#define IA_FCNTL_ERROR (3) +#define IA_GETHOSTBYNAME_ERROR (4) + +#define IA_PROTO_VER (8) +#define IA_PROTO_PROXY_VER (101) + +using namespace std; + +typedef void (*tpStatusChangedCb)(int status, void * data); +typedef void (*tpStatChangedCb)(const LOADSTAT & stat, void * data); +typedef void (*tpCallBackInfoFn)(const string & message, int infoType, int showTime, int sendTime, void * data); +typedef void (*tpCallBackErrorFn)(const string & message, int netError, void * data); +typedef void (*tpCallBackDirNameFn)(const vector & dirName, void * data); + +//--------------------------------------------------------------------------- +class IA_CLIENT_PROT +{ +#ifdef WIN32 +friend unsigned long WINAPI RunW(void * data); +#else +friend void * RunL(void * data); +#endif + +public: + IA_CLIENT_PROT(const string & sn, uint16_t p, uint16_t localPort = 0); + ~IA_CLIENT_PROT(); + + void Start(); + void Stop(); + void GetStat(LOADSTAT * ls); + + void SetServer(const string & sn, unsigned short port); + void SetLogin(const string & login); + void SetPassword(const string & password); + void SetEnabledDirs(const bool * selectedDirs); + + void SetStatusChangedCb(tpStatusChangedCb p, void * data); + void SetStatChangedCb(tpStatChangedCb p, void * data); + void SetInfoCb(tpCallBackInfoFn p, void * data); + void SetErrorCb(tpCallBackErrorFn p, void * data); + void SetDirNameCb(tpCallBackDirNameFn p, void * data); + + int Connect(); + int Disconnect(); + int GetAuthorized() const { return phase == 3 || phase == 4; }; + int GetPhase() const { return phase; }; + int GetStatus() const; + int GetReconnect() const { return reconnect; }; + void SetReconnect(int r) { reconnect = r; }; + char GetProtoVer() const { return proxyMode ? IA_PROTO_PROXY_VER : IA_PROTO_VER; }; + void GetMessageText(string * text) const { *text = messageText; }; + void GetInfoText(string * text) const { *text = infoText; }; + int GetStrError(string * error) const; + + void SetProxyMode(bool on) { proxyMode = on; }; + bool GetProxyMode() const { return proxyMode; }; + + void SetIP(uint32_t ip) { IA_CLIENT_PROT::ip = ip; }; + uint32_t GetIP() const { return ip; }; + +private: + void Run(); + int NetRecv(); + int NetSend(int n); + bool GetNonstop() const { return nonstop; }; + void PrepareNet(); + int DeterminatePacketType(const char * buffer); + + int Process_CONN_SYN_ACK_8(const char * buffer); + int Process_ALIVE_SYN_8(const char * buffer); + int Process_DISCONN_SYN_ACK_8(const char * buffer); + int Process_FIN_8(const char * buffer); + int Process_INFO_8(const char * buffer); + int Process_ERROR(const char * buffer); + + int Prepare_CONN_SYN_8(char * buffer); + int Prepare_CONN_ACK_8(char * buffer); + int Prepare_ALIVE_ACK_8(char * buffer); + int Prepare_DISCONN_SYN_8(char * buffer); + int Prepare_DISCONN_ACK_8(char * buffer); + + void FillHdr8(char * buffer, unsigned long ip); + int Send(char * buffer, int len); + int Recv(char * buffer, int len); + + LOADSTAT stat; + int action; + int phase; + int phaseTime; + string messageText; + string infoText; + mutable string strError; + mutable int codeError; + bool nonstop; + bool isNetPrepared; + bool proxyMode; + + BLOWFISH_CTX ctxPass; + BLOWFISH_CTX ctxHdr; + + bool selectedDirs[DIR_NUM]; + + string password; + string login; + + #ifdef WIN32 + WSADATA wsaData; + #else + pthread_t thread; + #endif + + string serverName; + uint16_t port; + uint32_t ip; + uint32_t localPort; + + struct sockaddr_in servAddr; + + bool firstConnect; + int reconnect; + int sockr; + int protNum; + int userTimeout; + int aliveTimeout; + unsigned int rnd; + + tpStatusChangedCb pStatusChangedCb; + tpStatChangedCb pStatChangedCb; + tpCallBackInfoFn pInfoCb; + tpCallBackErrorFn pErrorCb; + tpCallBackDirNameFn pDirNameCb; + + void * statusChangedCbData; + void * statChangedCbData; + void * infoCbData; + void * errorCbData; + void * dirNameCbData; + + map packetTypes; + + CONN_SYN_8 * connSyn8; + CONN_SYN_ACK_8 * connSynAck8; + CONN_ACK_8 * connAck8; + ALIVE_SYN_8 * aliveSyn8; + ALIVE_ACK_8 * aliveAck8; + DISCONN_SYN_8 * disconnSyn8; + DISCONN_SYN_ACK_8 * disconnSynAck8; + DISCONN_ACK_8 * disconnAck8; + INFO_8 * info; +}; +//--------------------------------------------------------------------------- +#ifdef WIN32 +unsigned long WINAPI RunW(void *); +#else +void * RunW(void *); +#endif + +//--------------------------------------------------------------------------- +#endif //IA_AUTH_C_H diff --git a/stglibs/ia_auth_c.lib/Makefile b/stglibs/ia_auth_c.lib/Makefile deleted file mode 100644 index fb49f948..00000000 --- a/stglibs/ia_auth_c.lib/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -############################################################################### -# $Id: Makefile,v 1.11 2010/08/18 07:47:03 faust Exp $ -############################################################################### - -LIB_NAME = ia_auth_c -PROG = lib$(LIB_NAME) - -SRCS = ia_auth_c.cpp - -INCS = ia_auth_c.h - -STGLIBS = -lstg_common \ - -lstg_crypto -LIBS = $(LIB_THREAD) - -include ../Makefile.in diff --git a/stglibs/ia_auth_c.lib/ia_auth_c.bpf b/stglibs/ia_auth_c.lib/ia_auth_c.bpf deleted file mode 100644 index e3c42ce0..00000000 --- a/stglibs/ia_auth_c.lib/ia_auth_c.bpf +++ /dev/null @@ -1,9 +0,0 @@ -//--------------------------------------------------------------------------- - -#include -#pragma hdrstop -#define Library - -// To add a file to the library use the Project menu 'Add to Project'. - - \ No newline at end of file diff --git a/stglibs/ia_auth_c.lib/ia_auth_c.bpr b/stglibs/ia_auth_c.lib/ia_auth_c.bpr deleted file mode 100644 index c80bf51c..00000000 --- a/stglibs/ia_auth_c.lib/ia_auth_c.bpr +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[Version Info] -IncludeVerInfo=0 -AutoIncBuild=0 -MajorVer=1 -MinorVer=0 -Release=0 -Build=0 -Debug=0 -PreRelease=0 -Special=0 -Private=0 -DLL=0 -Locale=1049 -CodePage=1251 - -[Version Info Keys] -CompanyName= -FileDescription= -FileVersion=1.0.0.0 -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion=1.0.0.0 -Comments= - -[HistoryLists\hlIncludePath] -Count=2 -Item0=$(BCB)\include;$(BCB)\include\vcl;..\..\include -Item1=$(BCB)\include;$(BCB)\include\vcl - -[HistoryLists\hlLibraryPath] -Count=1 -Item0=$(BCB)\lib\obj;$(BCB)\lib - -[HistoryLists\hlDebugSourcePath] -Count=1 -Item0=$(BCB)\source\vcl - -[HistoryLists\hlConditionals] -Count=2 -Item0=_DEBUG;WIN32 -Item1=_DEBUG - -[HistoryLists\hlFinalOutputDir] -Count=1 -Item0=..\..\lib - -[Debugging] -DebugSourceDirs=$(BCB)\source\vcl - -[Parameters] -RunParams= -Launcher= -UseLauncher=0 -DebugCWD= -HostApplication= -RemoteHost= -RemotePath= -RemoteLauncher= -RemoteCWD= -RemoteDebug=0 - -[Compiler] -ShowInfoMsgs=0 -LinkDebugVcl=0 -LinkCGLIB=0 - -[CORBA] -AddServerUnit=1 -AddClientUnit=1 -PrecompiledHeaders=1 - - \ No newline at end of file diff --git a/stglibs/ia_auth_c.lib/ia_auth_c.cpp b/stglibs/ia_auth_c.lib/ia_auth_c.cpp deleted file mode 100644 index 075a1913..00000000 --- a/stglibs/ia_auth_c.lib/ia_auth_c.cpp +++ /dev/null @@ -1,840 +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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -/* - $Author: faust $ - $Revision: 1.15 $ - $Date: 2010/04/16 11:28:03 $ -*/ - -/* -* Author : -* Boris Mikhailenko -* Maxim Mamontov -* Andrey Rakhmanov - bugfixes. -*/ - -//--------------------------------------------------------------------------- - -#include -#include -#include -#include - -#ifdef WIN32 - #include - #include - #include - #include -#else - #include - #include - #include - #include - #include - #include - #include -#endif - -#include "stg/common.h" -#include "ia_auth_c.h" - -#define IA_NONE (0) -#define IA_CONNECT (1) -#define IA_DISCONNECT (2) - -#define IA_DEBUGPROTO 1 - -#define IA_ID "00100" -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- -#ifndef WIN32 -#include -void * RunL(void * data) -{ - -IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data; -static int a = 0; - -if (a == 0) - { - usleep(50000); - a = 1; - } - -while (c->GetNonstop()) - { - c->Run(); - } -return NULL; -} -//--------------------------------------------------------------------------- -void Sleep(int ms) -{ -usleep(ms * 1000); -} -//--------------------------------------------------------------------------- -long GetTickCount() -{ -struct timeval tv; -gettimeofday(&tv, NULL); -return tv.tv_sec*1000 + tv.tv_usec/1000; -} -#else -//--------------------------------------------------------------------------- -unsigned long WINAPI RunW(void * data) -{ -IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data; -while (c->GetNonstop()) - c->Run(); -return 0; -} -//--------------------------------------------------------------------------- -#endif -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- -IA_CLIENT_PROT::IA_CLIENT_PROT(const string & sn, unsigned short p, uint16_t localPort) - : action(IA_NONE), - phase(1), - phaseTime(0), - codeError(0), - nonstop(false), - isNetPrepared(false), - proxyMode(false), - serverName(sn), - port(p), - ip(0), - localPort(localPort), - firstConnect(true), - reconnect(0), - sockr(0), - protNum(0), - userTimeout(60), - aliveTimeout(5), - rnd(0), - pStatusChangedCb(NULL), - pStatChangedCb(NULL), - pInfoCb(NULL), - pErrorCb(NULL), - pDirNameCb(NULL), - statusChangedCbData(NULL), - statChangedCbData(NULL), - infoCbData(NULL), - errorCbData(NULL), - dirNameCbData(NULL), - connSyn8(NULL), - connSynAck8(NULL), - connAck8(NULL), - aliveSyn8(NULL), - aliveAck8(NULL), - disconnSyn8(NULL), - disconnSynAck8(NULL), - disconnAck8(NULL), - info(NULL) -{ -memset(&stat, 0, sizeof(stat)); - -#ifdef WIN32 -WSAStartup(MAKEWORD(2, 0), &wsaData); -#endif - -packetTypes["CONN_SYN"] = CONN_SYN_N; -packetTypes["CONN_SYN_ACK"] = CONN_SYN_ACK_N; -packetTypes["CONN_ACK"] = CONN_ACK_N; -packetTypes["ALIVE_SYN"] = ALIVE_SYN_N; -packetTypes["ALIVE_ACK"] = ALIVE_ACK_N; -packetTypes["DISCONN_SYN"] = DISCONN_SYN_N; -packetTypes["DISCONN_SYN_ACK"] = DISCONN_SYN_ACK_N; -packetTypes["DISCONN_ACK"] = DISCONN_ACK_N; -packetTypes["FIN"] = FIN_N; -packetTypes["ERR"] = ERROR_N; -packetTypes["INFO"] = INFO_N; -packetTypes["INFO_7"] = INFO_7_N; -packetTypes["INFO_8"] = INFO_8_N; - -unsigned char key[IA_PASSWD_LEN]; -memset(key, 0, IA_PASSWD_LEN); -strncpy((char *)key, "pr7Hhen", 8); -Blowfish_Init(&ctxHdr, key, IA_PASSWD_LEN); - -memset(key, 0, IA_PASSWD_LEN); -Blowfish_Init(&ctxPass, key, IA_PASSWD_LEN); - -for (size_t i = 0; i < DIR_NUM; ++i) - { - selectedDirs[i] = false; - } - -servAddr.sin_family = AF_INET; -servAddr.sin_port = htons(port); -servAddr.sin_addr.s_addr = ip; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::PrepareNet() -{ -struct hostent * phe; -unsigned long ip; - -ip = inet_addr(serverName.c_str()); -if (ip == INADDR_NONE) - { - phe = gethostbyname(serverName.c_str()); - if (phe) - { - ip = *((unsigned long*)phe->h_addr_list[0]); - } - else - { - strError = string("Unknown host ") + "\'" + serverName + "\'"; - codeError = IA_GETHOSTBYNAME_ERROR; - if (pErrorCb != NULL) - pErrorCb(strError, IA_GETHOSTBYNAME_ERROR, errorCbData); - } - } - -#ifndef WIN32 -close(sockr); -#else -closesocket(sockr); -#endif - -sockr = socket(AF_INET, SOCK_DGRAM, 0); - -struct sockaddr_in localAddrR; -localAddrR.sin_family = AF_INET; - -if (localPort) - localAddrR.sin_port = htons(localPort); -else - localAddrR.sin_port = htons(port); -localAddrR.sin_addr.s_addr = inet_addr("0.0.0.0"); - -servAddr.sin_family = AF_INET; -servAddr.sin_port = htons(port); -servAddr.sin_addr.s_addr = ip; - -int res = bind(sockr, (struct sockaddr*)&localAddrR, sizeof(localAddrR)); -if (res == -1) - { - strError = "bind error"; - codeError = IA_BIND_ERROR; - if (pErrorCb != NULL) - pErrorCb(strError, IA_BIND_ERROR, errorCbData); - return; - } - -#ifdef WIN32 -unsigned long arg = 1; -res = ioctlsocket(sockr, FIONBIO, &arg); -#else -if (0 != fcntl(sockr, F_SETFL, O_NONBLOCK)) - { - strError = "fcntl error"; - codeError = IA_FCNTL_ERROR; - if (pErrorCb != NULL) - pErrorCb(strError, IA_FCNTL_ERROR, errorCbData); - } -#endif - -} -//--------------------------------------------------------------------------- -IA_CLIENT_PROT::~IA_CLIENT_PROT() -{ -#ifndef WIN32 -close(sockr); -#else -closesocket(sockr); -WSACleanup(); -#endif -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::DeterminatePacketType(const char * buffer) -{ -map::iterator pi; -pi = packetTypes.find(buffer); -if (pi == packetTypes.end()) - { - return -1; - } -else - { - return pi->second; - } -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::FillHdr8(char * buffer, unsigned long) -{ -strncpy(buffer, IA_ID, 6); -buffer[IA_MAGIC_LEN] = 0; -buffer[IA_MAGIC_LEN + 1] = IA_PROTO_VER; -strncpy(buffer + sizeof(HDR_8), login.c_str(), IA_LOGIN_LEN); -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Send(char * buffer, int len) -{ -if (!isNetPrepared) - { - PrepareNet(); - isNetPrepared = true; - } - -int db = sizeof(HDR_8); -for (int i = 0; i < IA_LOGIN_LEN/8; i++) - { - Blowfish_Encrypt(&ctxHdr, (uint32_t*)(buffer + db + i*8), (uint32_t*)(buffer + db + i*8 + 4)); - } - -db += IA_LOGIN_LEN; -int encLen = (len - sizeof(HDR_8) - IA_LOGIN_LEN)/8; -for (int i = 0; i < encLen; i++) - { - Blowfish_Encrypt(&ctxPass, (uint32_t*)(buffer + db), (uint32_t*)(buffer + db + 4)); - db += 8; - } - -return sendto(sockr, buffer, len, 0, (struct sockaddr*)&servAddr, sizeof(servAddr)); -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Recv(char * buffer, int len) -{ -#ifdef WIN32 -int fromLen; -#else -socklen_t fromLen; -#endif - -struct sockaddr_in addr; -fromLen = sizeof(addr); -int res = recvfrom(sockr, buffer, len, 0, (struct sockaddr*)&addr, &fromLen); - -if (res == -1) - return res; - -if (strcmp(buffer + 4 + sizeof(HDR_8), "ERR")) - { - for (int i = 0; i < len/8; i++) - Blowfish_Decrypt(&ctxPass, (uint32_t*)(buffer + i*8), (uint32_t*)(buffer + i*8 + 4)); - } - -return 0; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::NetSend(int n) -{ -char buffer[2048]; -int msgLen; - -memset(buffer, 0, 2048); - -switch (n) - { - case CONN_SYN_N: - msgLen = Prepare_CONN_SYN_8(buffer); - break; - - case CONN_ACK_N: - msgLen = Prepare_CONN_ACK_8(buffer); - break; - - case ALIVE_ACK_N: - msgLen = Prepare_ALIVE_ACK_8(buffer); - break; - - case DISCONN_SYN_N: - msgLen = Prepare_DISCONN_SYN_8(buffer); - break; - - case DISCONN_ACK_N: - msgLen = Prepare_DISCONN_ACK_8(buffer); - break; - - default: - return -1; - } - -FillHdr8(buffer, 0); -Send(buffer, msgLen); - -return 0; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::NetRecv() -{ -char buffer[2048]; - -if (Recv(buffer, sizeof(buffer)) < 0) - return -1; - -char packetName[20]; -strncpy(packetName, buffer + 12, sizeof(packetName)); -packetName[sizeof(packetName) - 1] = 0; -int pn = DeterminatePacketType(buffer + 12); - -int ret; -switch (pn) - { - case CONN_SYN_ACK_N: - ret = Process_CONN_SYN_ACK_8(buffer); - break; - - case ALIVE_SYN_N: - ret = Process_ALIVE_SYN_8(buffer); - break; - - case DISCONN_SYN_ACK_N: - ret = Process_DISCONN_SYN_ACK_8(buffer); - break; - - case FIN_N: - ret = Process_FIN_8(buffer); - break; - - case INFO_8_N: - ret = Process_INFO_8(buffer); - break; - - case ERROR_N: - ret = Process_ERROR(buffer); - break; - - default: - ret = -1; - } -return ret; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::Start() -{ -nonstop = true; -#ifdef WIN32 -unsigned long pt; -CreateThread(NULL, 16384, RunW, this, 0, &pt); -#else -pthread_create(&thread, NULL, RunL, this); -#endif -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::Stop() -{ -nonstop = false; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::Run() -{ -NetRecv(); - -switch (phase) - { - case 1: - if (action == IA_CONNECT) - { - action = IA_NONE; - NetSend(CONN_SYN_N); - phase = 2; - phaseTime = GetTickCount(); - } - if (reconnect && !firstConnect) - { - action = IA_CONNECT; - } - break; - - case 2: - if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) - { - phase = 1; - phaseTime = GetTickCount(); - if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); - } - - if (action == IA_DISCONNECT) - { - action = IA_NONE; - NetSend(DISCONN_SYN_N); - phase = 4; - phaseTime = GetTickCount(); - } - - break; - - case 3: - if ((int)(GetTickCount() - phaseTime)/1000 > userTimeout) - { - phase = 1; - phaseTime = GetTickCount(); - if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); - firstConnect = false; - } - - if (action == IA_DISCONNECT) - { - action = IA_NONE; - NetSend(DISCONN_SYN_N); - phase = 4; - phaseTime = GetTickCount(); - } - - break; - - case 4: - if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) - { - phase=1; - phaseTime = GetTickCount(); - if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); - } - - if (action == IA_CONNECT) - { - action = IA_NONE; - NetSend(CONN_SYN_N); - phase = 2; - phaseTime = GetTickCount(); - } - - break; - - case 5: - if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout) - { - phase = 1; - phaseTime = GetTickCount(); - if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); - } - - if (action == IA_CONNECT) - { - action = IA_NONE; - NetSend(CONN_SYN_N); - phase = 2; - phaseTime = GetTickCount(); - } - - break; - } -Sleep(20); -return; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::GetStat(LOADSTAT * ls) -{ -memcpy(ls, &stat, sizeof(stat)); -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetServer(const string & sn, unsigned short p) -{ -serverName = sn; -port = p; -PrepareNet(); -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetLogin(const string & l) -{ -login = l; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetPassword(const string & p) -{ -password = p; - -unsigned char keyL[IA_PASSWD_LEN]; -memset(keyL, 0, IA_PASSWD_LEN); -strncpy((char *)keyL, password.c_str(), IA_PASSWD_LEN); -Blowfish_Init(&ctxPass, keyL, IA_PASSWD_LEN); -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetEnabledDirs(const bool * selectedDirs) -{ -memcpy(IA_CLIENT_PROT::selectedDirs, selectedDirs, sizeof(bool) * DIR_NUM); -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Connect() -{ -action = IA_CONNECT; -return 0; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Disconnect() -{ -firstConnect = true; -action = IA_DISCONNECT; -return 0; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::GetStrError(string * error) const -{ -int ret = codeError; -*error = strError; -strError = ""; -codeError = 0; -return ret; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_CONN_SYN_ACK_8(const char * buffer) -{ -vector dirNames; -connSynAck8 = (CONN_SYN_ACK_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(connSynAck8->len); -SwapBytes(connSynAck8->rnd); -SwapBytes(connSynAck8->userTimeOut); -SwapBytes(connSynAck8->aliveDelay); -#endif - -rnd = connSynAck8->rnd; -userTimeout = connSynAck8->userTimeOut; -aliveTimeout = connSynAck8->aliveDelay; - -for (int i = 0; i < DIR_NUM; i++) - { - dirNames.push_back((const char*)connSynAck8->dirName[i]); - } - -if (pDirNameCb != NULL) - pDirNameCb(dirNames, dirNameCbData); - -NetSend(CONN_ACK_N); -phase = 3; -phaseTime = GetTickCount(); - -return CONN_SYN_ACK_N; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_ALIVE_SYN_8(const char * buffer) -{ -aliveSyn8 = (ALIVE_SYN_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(aliveSyn8->len); -SwapBytes(aliveSyn8->rnd); -SwapBytes(aliveSyn8->cash); -SwapBytes(aliveSyn8->status); -for (int i = 0; i < DIR_NUM; ++i) - { - SwapBytes(aliveSyn8->mu[i]); - SwapBytes(aliveSyn8->md[i]); - SwapBytes(aliveSyn8->su[i]); - SwapBytes(aliveSyn8->sd[i]); - } -#endif - -rnd = aliveSyn8->rnd; -memcpy(&stat, (char*)aliveSyn8->mu, sizeof(stat)); - -if (pStatChangedCb != NULL) - pStatChangedCb(stat, statChangedCbData); - -if (pStatusChangedCb != NULL) - pStatusChangedCb(1, statusChangedCbData); -NetSend(ALIVE_ACK_N); -phaseTime = GetTickCount(); - -return ALIVE_SYN_N; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_DISCONN_SYN_ACK_8(const char * buffer) -{ -disconnSynAck8 = (DISCONN_SYN_ACK_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(disconnSynAck8->len); -SwapBytes(disconnSynAck8->rnd); -#endif - -rnd = disconnSynAck8->rnd; - -NetSend(DISCONN_ACK_N); -phase = 5; -phaseTime = GetTickCount(); - -return DISCONN_SYN_ACK_N; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_FIN_8(const char *) -{ -phase = 1; -phaseTime = GetTickCount(); -if (pStatusChangedCb != NULL) - pStatusChangedCb(0, statusChangedCbData); - -return FIN_N; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_INFO_8(const char * buffer) -{ -info = (INFO_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(info->len); -SwapBytes(info->sendTime); -#endif - -if (pInfoCb != NULL) - pInfoCb((char*)info->text, info->infoType, info->showTime, info->sendTime, infoCbData); -return INFO_8_N; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Process_ERROR(const char * buffer) -{ -ERR_8 err; -memcpy(&err, buffer, sizeof(err)); - -#ifdef ARCH_BE -SwapBytes(err.len); -#endif - -KOIToWin((const char*)err.text, &messageText); -if (pErrorCb != NULL) - pErrorCb(messageText, IA_SERVER_ERROR, errorCbData); -phase = 1; -phaseTime = GetTickCount(); -codeError = IA_SERVER_ERROR; - -return ERROR_N; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_CONN_SYN_8(char * buffer) -{ -connSyn8 = (CONN_SYN_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(connSyn8->len); -#endif - -assert(sizeof(CONN_SYN_8) == Min8(sizeof(CONN_SYN_8)) && "CONN_SYN_8 is not aligned to 8 bytes"); - -connSyn8->len = sizeof(CONN_SYN_8); -strncpy((char*)connSyn8->type, "CONN_SYN", IA_MAX_TYPE_LEN); -strncpy((char*)connSyn8->login, login.c_str(), IA_LOGIN_LEN); -connSyn8->dirs = 0; -for (int i = 0; i < DIR_NUM; i++) - { - connSyn8->dirs |= (selectedDirs[i] << i); - } -return connSyn8->len; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_CONN_ACK_8(char * buffer) -{ -connAck8 = (CONN_ACK_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(connAck8->len); -SwapBytes(connAck8->rnd); -#endif - -assert(sizeof(CONN_ACK_8) == Min8(sizeof(CONN_ACK_8)) && "CONN_ACK_8 is not aligned to 8 bytes"); - -connAck8->len = sizeof(CONN_ACK_8); -strncpy((char*)connAck8->loginS, login.c_str(), IA_LOGIN_LEN); -strncpy((char*)connAck8->type, "CONN_ACK", IA_MAX_TYPE_LEN); -rnd++; -connAck8->rnd = rnd; - -return connAck8->len; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_ALIVE_ACK_8(char * buffer) -{ -aliveAck8 = (ALIVE_ACK_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(aliveAck8->len); -SwapBytes(aliveAck8->rnd); -#endif - -assert(Min8(sizeof(ALIVE_ACK_8)) == sizeof(ALIVE_ACK_8) && "ALIVE_ACK_8 is not aligned to 8 bytes"); - -aliveAck8 = (ALIVE_ACK_8*)buffer; -aliveAck8->len = sizeof(ALIVE_ACK_8); -strncpy((char*)aliveAck8->loginS, login.c_str(), IA_LOGIN_LEN); -strncpy((char*)aliveAck8->type, "ALIVE_ACK", IA_MAX_TYPE_LEN); -aliveAck8->rnd = ++rnd; -return aliveAck8->len; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_DISCONN_SYN_8(char * buffer) -{ -disconnSyn8 = (DISCONN_SYN_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(disconnSyn8->len); -#endif - -assert(Min8(sizeof(DISCONN_SYN_8)) == sizeof(DISCONN_SYN_8) && "DISCONN_SYN_8 is not aligned to 8 bytes"); - -disconnSyn8->len = sizeof(DISCONN_SYN_8); -strncpy((char*)disconnSyn8->loginS, login.c_str(), IA_LOGIN_LEN); -strncpy((char*)disconnSyn8->type, "DISCONN_SYN", IA_MAX_TYPE_LEN); -strncpy((char*)disconnSyn8->login, login.c_str(), IA_LOGIN_LEN); -return disconnSyn8->len; -} -//--------------------------------------------------------------------------- -int IA_CLIENT_PROT::Prepare_DISCONN_ACK_8(char * buffer) -{ -disconnAck8 = (DISCONN_ACK_8*)buffer; - -#ifdef ARCH_BE -SwapBytes(disconnAck8->len); -SwapBytes(disconnAck8->rnd); -#endif - -assert(Min8(sizeof(DISCONN_ACK_8)) == sizeof(DISCONN_ACK_8) && "DISCONN_ACK_8 is not aligned to 8 bytes"); - -disconnAck8->len = Min8(sizeof(DISCONN_ACK_8)); -disconnAck8->rnd = rnd + 1; -strncpy((char*)disconnAck8->loginS, login.c_str(), IA_LOGIN_LEN); -strncpy((char*)disconnAck8->type, "DISCONN_ACK", IA_MAX_TYPE_LEN); -return disconnAck8->len; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetStatusChangedCb(tpStatusChangedCb p, void * data) -{ -pStatusChangedCb = p; -statusChangedCbData = data; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetStatChangedCb(tpStatChangedCb p, void * data) -{ -pStatChangedCb = p; -statChangedCbData = data; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetInfoCb(tpCallBackInfoFn p, void * data) -{ -pInfoCb = p; -infoCbData = data; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetDirNameCb(tpCallBackDirNameFn p, void * data) -{ -pDirNameCb = p; -dirNameCbData = data; -} -//--------------------------------------------------------------------------- -void IA_CLIENT_PROT::SetErrorCb(tpCallBackErrorFn p, void * data) -{ -pErrorCb = p; -errorCbData = data; -} -//--------------------------------------------------------------------------- diff --git a/stglibs/ia_auth_c.lib/ia_auth_c.h b/stglibs/ia_auth_c.lib/ia_auth_c.h deleted file mode 100644 index 0a916f4c..00000000 --- a/stglibs/ia_auth_c.lib/ia_auth_c.h +++ /dev/null @@ -1,204 +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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -/* - $Author: faust $ - $Revision: 1.10 $ - $Date: 2010/03/15 12:57:24 $ -*/ - -/* -* Author : Boris Mikhailenko -*/ -//--------------------------------------------------------------------------- -#ifndef IA_AUTH_C_H -#define IA_AUTH_C_H - -#ifndef WIN32 -#include -#include -#else -#include -#endif - -#include -#include -#include - -#include "stg/blowfish.h" -#include "stg/ia_packets.h" - -#define IA_BIND_ERROR (1) -#define IA_SERVER_ERROR (2) -#define IA_FCNTL_ERROR (3) -#define IA_GETHOSTBYNAME_ERROR (4) - -#define IA_PROTO_VER (8) -#define IA_PROTO_PROXY_VER (101) - -using namespace std; - -typedef void (*tpStatusChangedCb)(int status, void * data); -typedef void (*tpStatChangedCb)(const LOADSTAT & stat, void * data); -typedef void (*tpCallBackInfoFn)(const string & message, int infoType, int showTime, int sendTime, void * data); -typedef void (*tpCallBackErrorFn)(const string & message, int netError, void * data); -typedef void (*tpCallBackDirNameFn)(const vector & dirName, void * data); - -//--------------------------------------------------------------------------- -class IA_CLIENT_PROT -{ -#ifdef WIN32 -friend unsigned long WINAPI RunW(void * data); -#else -friend void * RunL(void * data); -#endif - -public: - IA_CLIENT_PROT(const string & sn, uint16_t p, uint16_t localPort = 0); - ~IA_CLIENT_PROT(); - - void Start(); - void Stop(); - void GetStat(LOADSTAT * ls); - - void SetServer(const string & sn, unsigned short port); - void SetLogin(const string & login); - void SetPassword(const string & password); - void SetEnabledDirs(const bool * selectedDirs); - - void SetStatusChangedCb(tpStatusChangedCb p, void * data); - void SetStatChangedCb(tpStatChangedCb p, void * data); - void SetInfoCb(tpCallBackInfoFn p, void * data); - void SetErrorCb(tpCallBackErrorFn p, void * data); - void SetDirNameCb(tpCallBackDirNameFn p, void * data); - - int Connect(); - int Disconnect(); - int GetAuthorized() const { return phase == 3 || phase == 4; }; - int GetPhase() const { return phase; }; - int GetStatus() const; - int GetReconnect() const { return reconnect; }; - void SetReconnect(int r) { reconnect = r; }; - char GetProtoVer() const { return proxyMode ? IA_PROTO_PROXY_VER : IA_PROTO_VER; }; - void GetMessageText(string * text) const { *text = messageText; }; - void GetInfoText(string * text) const { *text = infoText; }; - int GetStrError(string * error) const; - - void SetProxyMode(bool on) { proxyMode = on; }; - bool GetProxyMode() const { return proxyMode; }; - - void SetIP(uint32_t ip) { IA_CLIENT_PROT::ip = ip; }; - uint32_t GetIP() const { return ip; }; - -private: - void Run(); - int NetRecv(); - int NetSend(int n); - bool GetNonstop() const { return nonstop; }; - void PrepareNet(); - int DeterminatePacketType(const char * buffer); - - int Process_CONN_SYN_ACK_8(const char * buffer); - int Process_ALIVE_SYN_8(const char * buffer); - int Process_DISCONN_SYN_ACK_8(const char * buffer); - int Process_FIN_8(const char * buffer); - int Process_INFO_8(const char * buffer); - int Process_ERROR(const char * buffer); - - int Prepare_CONN_SYN_8(char * buffer); - int Prepare_CONN_ACK_8(char * buffer); - int Prepare_ALIVE_ACK_8(char * buffer); - int Prepare_DISCONN_SYN_8(char * buffer); - int Prepare_DISCONN_ACK_8(char * buffer); - - void FillHdr8(char * buffer, unsigned long ip); - int Send(char * buffer, int len); - int Recv(char * buffer, int len); - - LOADSTAT stat; - int action; - int phase; - int phaseTime; - string messageText; - string infoText; - mutable string strError; - mutable int codeError; - bool nonstop; - bool isNetPrepared; - bool proxyMode; - - BLOWFISH_CTX ctxPass; - BLOWFISH_CTX ctxHdr; - - bool selectedDirs[DIR_NUM]; - - string password; - string login; - - #ifdef WIN32 - WSADATA wsaData; - #else - pthread_t thread; - #endif - - string serverName; - uint16_t port; - uint32_t ip; - uint32_t localPort; - - struct sockaddr_in servAddr; - - bool firstConnect; - int reconnect; - int sockr; - int protNum; - int userTimeout; - int aliveTimeout; - unsigned int rnd; - - tpStatusChangedCb pStatusChangedCb; - tpStatChangedCb pStatChangedCb; - tpCallBackInfoFn pInfoCb; - tpCallBackErrorFn pErrorCb; - tpCallBackDirNameFn pDirNameCb; - - void * statusChangedCbData; - void * statChangedCbData; - void * infoCbData; - void * errorCbData; - void * dirNameCbData; - - map packetTypes; - - CONN_SYN_8 * connSyn8; - CONN_SYN_ACK_8 * connSynAck8; - CONN_ACK_8 * connAck8; - ALIVE_SYN_8 * aliveSyn8; - ALIVE_ACK_8 * aliveAck8; - DISCONN_SYN_8 * disconnSyn8; - DISCONN_SYN_ACK_8 * disconnSynAck8; - DISCONN_ACK_8 * disconnAck8; - INFO_8 * info; -}; -//--------------------------------------------------------------------------- -#ifdef WIN32 -unsigned long WINAPI RunW(void *); -#else -void * RunW(void *); -#endif - -//--------------------------------------------------------------------------- -#endif //IA_AUTH_C_H diff --git a/stglibs/locker.lib/Makefile b/stglibs/locker.lib/Makefile new file mode 100644 index 00000000..c490ce69 --- /dev/null +++ b/stglibs/locker.lib/Makefile @@ -0,0 +1,14 @@ +############################################################################### +# $Id: Makefile,v 1.2 2008/12/04 17:11:55 faust Exp $ +############################################################################### + +LIB_NAME = stglocker +PROG = lib$(LIB_NAME) + +SRCS = locker.cpp + +INCS = locker.h + +LIBS = $(LIB_THREAD) + +include ../Makefile.in diff --git a/stglibs/locker.lib/locker.cpp b/stglibs/locker.lib/locker.cpp new file mode 100644 index 00000000..0d97fcb4 --- /dev/null +++ b/stglibs/locker.lib/locker.cpp @@ -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 : Boris Mikhailenko + */ + +/* + $Revision: 1.2 $ + $Date: 2007/11/30 08:57:49 $ + $Author: nobunaga $ +*/ + + + +#include + +#include "locker.h" + +#ifdef DEBUG_LOCKER + +long long STG_LOCKER::id = 0; +pthread_mutex_t STG_LOCKER::lockerMutex = PTHREAD_MUTEX_INITIALIZER; + +#endif + diff --git a/stglibs/locker.lib/locker.h b/stglibs/locker.lib/locker.h new file mode 100644 index 00000000..4621388e --- /dev/null +++ b/stglibs/locker.lib/locker.h @@ -0,0 +1,93 @@ +/* + * 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.5 $ + $Date: 2010/03/04 11:57:11 $ + $Author: faust $ +*/ + + +#ifndef STG_LOCKER_H +#define STG_LOCKER_H + +#include + +#ifdef DEBUG_LOCKER + +#include +#include +#include + +#endif + +#include "stg/noncopyable.h" +//----------------------------------------------------------------------------- +class STG_LOCKER : private NONCOPYABLE +{ +public: + #ifdef DEBUG_LOCKER + STG_LOCKER(pthread_mutex_t * m, const char * __file__, int __line__) + : mutex(m), + file(__file__), + line(__line__), + lockID(0) + #else + STG_LOCKER(pthread_mutex_t * m, const char *, int) + : mutex(m) + #endif + { + mutex = m; + #ifdef DEBUG_LOCKER + pthread_mutex_lock(&lockerMutex); + file = __file__; + line = __line__; + if (id == 0) + pthread_mutex_init(&lockerMutex, NULL); + + lockID = ++id; + std::cout << "Lock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; + pthread_mutex_unlock(&lockerMutex); + #endif + pthread_mutex_lock(mutex); + }; + + ~STG_LOCKER() + { + pthread_mutex_unlock(mutex); + #ifdef DEBUG_LOCKER + pthread_mutex_lock(&lockerMutex); + std::cout << "Unlock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; + pthread_mutex_unlock(&lockerMutex); + #endif + }; +private: + pthread_mutex_t * mutex; + #ifdef DEBUG_LOCKER + std::string file; + int line; + static pthread_mutex_t lockerMutex; + static long long id; + long long lockID; + #endif +}; +//----------------------------------------------------------------------------- + +#endif //STG_LOCKER_H diff --git a/stglibs/logger.lib/Makefile b/stglibs/logger.lib/Makefile new file mode 100644 index 00000000..95aca37e --- /dev/null +++ b/stglibs/logger.lib/Makefile @@ -0,0 +1,12 @@ +############################################################################### +# $Id: Makefile,v 1.3 2007/05/08 14:29:21 faust Exp $ +############################################################################### + +LIB_NAME = stglogger +PROG = lib$(LIB_NAME) + +SRCS = logger.cpp + +INCS = logger.h + +include ../Makefile.in diff --git a/stglibs/logger.lib/logger.cpp b/stglibs/logger.lib/logger.cpp new file mode 100644 index 00000000..18c9de7e --- /dev/null +++ b/stglibs/logger.lib/logger.cpp @@ -0,0 +1,94 @@ +#include +#include +#include + +#include "logger.h" + +#ifdef STG_TIME +extern const volatile time_t stgTime; +#endif +//----------------------------------------------------------------------------- +STG_LOGGER & GetStgLogger() +{ +static STG_LOGGER logger; +return logger; +} +//----------------------------------------------------------------------------- +STG_LOGGER::STG_LOGGER() + : fileName() +{ +pthread_mutex_init(&mutex, NULL); +} +//----------------------------------------------------------------------------- +STG_LOGGER::~STG_LOGGER() +{ +pthread_mutex_destroy(&mutex); +} +//----------------------------------------------------------------------------- +void STG_LOGGER::SetLogFileName(const std::string & fn) +{ +STG_LOGGER_LOCKER lock(&mutex); +fileName = fn; +} +//----------------------------------------------------------------------------- +void STG_LOGGER::operator()(const char * fmt, ...) +{ +STG_LOGGER_LOCKER lock(&mutex); + +char buff[2048]; + +va_list vl; +va_start(vl, fmt); +vsnprintf(buff, sizeof(buff), fmt, vl); +va_end(vl); + +FILE * f; +if (!fileName.empty()) + { + f = fopen(fileName.c_str(), "at"); + if (f) + { + #ifdef STG_TIME + fprintf(f, "%s", LogDate(stgTime)); + #else + fprintf(f, "%s", LogDate(time(NULL))); + #endif + fprintf(f, " -- "); + fprintf(f, "%s", buff); + fprintf(f, "\n"); + fclose(f); + } + else + { + openlog("stg", LOG_NDELAY, LOG_USER); + syslog(LOG_CRIT, "%s", buff); + closelog(); + } + } +else + { + openlog("stg", LOG_NDELAY, LOG_USER); + syslog(LOG_CRIT, "%s", buff); + closelog(); + } +} +//----------------------------------------------------------------------------- +const char * STG_LOGGER::LogDate(time_t t) +{ +static char s[32]; +if (t == 0) + t = time(NULL); + +struct tm * tt = localtime(&t); + +snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d", + tt->tm_year + 1900, + tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1, + tt->tm_mday < 10 ? "0" : "", tt->tm_mday, + tt->tm_hour < 10 ? "0" : "", tt->tm_hour, + tt->tm_min < 10 ? "0" : "", tt->tm_min, + tt->tm_sec < 10 ? "0" : "", tt->tm_sec); + +return s; +} +//----------------------------------------------------------------------------- diff --git a/stglibs/logger.lib/logger.h b/stglibs/logger.lib/logger.h new file mode 100644 index 00000000..f8375b06 --- /dev/null +++ b/stglibs/logger.lib/logger.h @@ -0,0 +1,42 @@ +#ifndef STG_LOGGER_H +#define STG_LOGGER_H + +#include + +#include + +#include "stg/noncopyable.h" + +const char * LogDate(time_t t); +//----------------------------------------------------------------------------- +class STG_LOGGER; +STG_LOGGER & GetStgLogger(); +//----------------------------------------------------------------------------- +class STG_LOGGER_LOCKER : private NONCOPYABLE +{ +public: + STG_LOGGER_LOCKER(pthread_mutex_t * m) : mutex(m) { pthread_mutex_lock(mutex); }; + ~STG_LOGGER_LOCKER() { pthread_mutex_unlock(mutex); }; +private: + pthread_mutex_t * mutex; +}; +//----------------------------------------------------------------------------- +class STG_LOGGER +{ +friend STG_LOGGER & GetStgLogger(); + +public: + ~STG_LOGGER(); + void SetLogFileName(const std::string & fn); + void operator()(const char * fmt, ...); + +private: + STG_LOGGER(); + const char * LogDate(time_t t); + + std::string fileName; + pthread_mutex_t mutex; +}; +//----------------------------------------------------------------------------- + +#endif //STG_LOGGER_H diff --git a/stglibs/pinger.lib/Makefile b/stglibs/pinger.lib/Makefile index 5f368b64..91f6322d 100644 --- a/stglibs/pinger.lib/Makefile +++ b/stglibs/pinger.lib/Makefile @@ -2,7 +2,7 @@ # $Id: Makefile,v 1.5 2008/12/04 17:13:14 faust Exp $ ############################################################################### -LIB_NAME = stg_pinger +LIB_NAME = stgpinger PROG = lib$(LIB_NAME) SRCS = pinger.cpp @@ -15,4 +15,4 @@ include ../Makefile.in test: all g++ -c test.cpp - g++ -o test test.o ./libstg_pinger.a -lpthread + g++ -o test test.o ./libstgpinger.a -lpthread diff --git a/stglibs/pinger.lib/pinger.cpp b/stglibs/pinger.lib/pinger.cpp index 68137d7c..216b5977 100644 --- a/stglibs/pinger.lib/pinger.cpp +++ b/stglibs/pinger.lib/pinger.cpp @@ -16,7 +16,7 @@ #include "pinger.h" #include "stg/common.h" -#include "stg/stg_locker.h" +#include "stg/locker.h" #ifdef STG_TIME extern volatile time_t stgTime; diff --git a/stglibs/script_executer.lib/Makefile b/stglibs/script_executer.lib/Makefile deleted file mode 100644 index 90691ab3..00000000 --- a/stglibs/script_executer.lib/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# $Id: Makefile,v 1.6 2010/01/21 13:02:12 faust Exp $ -############################################################################### - -LIB_NAME = script_executer -PROG = lib$(LIB_NAME) - -SRCS = script_executer.cpp - -INCS = script_executer.h - -include ../Makefile.in diff --git a/stglibs/script_executer.lib/script_executer.cpp b/stglibs/script_executer.lib/script_executer.cpp deleted file mode 100644 index 00ff0949..00000000 --- a/stglibs/script_executer.lib/script_executer.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "script_executer.h" - -using namespace std; - -#define MAX_SCRIPT_LEN (1100) - -static int msgid; -static bool nonstop; - -//----------------------------------------------------------------------------- -struct SCRIPT_DATA -{ - long mtype; - char script[MAX_SCRIPT_LEN]; -} sd; -//----------------------------------------------------------------------------- -static void CatchUSR1Executer(int) -{ -nonstop = false; -} -//----------------------------------------------------------------------------- -int ScriptExec(const string & str) -{ -if (str.length() >= MAX_SCRIPT_LEN) - return -1; - -int ret; -strncpy(sd.script, str.c_str(), MAX_SCRIPT_LEN); -sd.mtype = 1; -ret = msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0); -if (ret < 0) - { - return -1; - } -return 0; -} -//----------------------------------------------------------------------------- -#ifdef LINUX -void Executer(int, int msgID, pid_t pid, char * procName) -#else -void Executer(int, int msgID, pid_t pid, char *) -#endif -{ -msgid = msgID; -if (pid) - return; -nonstop = true; - -#ifdef LINUX -memset(procName, 0, strlen(procName)); -strcpy(procName, "stg-exec"); -#else -setproctitle("stg-exec"); -#endif - -struct sigaction newsa, oldsa; -sigset_t sigmask; - -sigemptyset(&sigmask); -sigaddset(&sigmask, SIGTERM); -newsa.sa_handler = SIG_IGN; -newsa.sa_mask = sigmask; -newsa.sa_flags = 0; -sigaction(SIGTERM, &newsa, &oldsa); - -sigemptyset(&sigmask); -sigaddset(&sigmask, SIGINT); -newsa.sa_handler = SIG_IGN; -newsa.sa_mask = sigmask; -newsa.sa_flags = 0; -sigaction(SIGINT, &newsa, &oldsa); - -sigemptyset(&sigmask); -sigaddset(&sigmask, SIGHUP); -newsa.sa_handler = SIG_IGN; -newsa.sa_mask = sigmask; -newsa.sa_flags = 0; -sigaction(SIGHUP, &newsa, &oldsa); - -sigemptyset(&sigmask); -sigaddset(&sigmask, SIGUSR1); -newsa.sa_handler = CatchUSR1Executer; -newsa.sa_mask = sigmask; -newsa.sa_flags = 0; -sigaction(SIGUSR1, &newsa, &oldsa); - -int ret; - -SCRIPT_DATA sd; - -while (nonstop) - { - sd.mtype = 1; - ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0); - - if (ret < 0) - { - usleep(20000); - continue; - } - int ret = system(sd.script); - if (ret == -1) - { - // Fork failed - } - } -} -//----------------------------------------------------------------------------- - - diff --git a/stglibs/script_executer.lib/script_executer.h b/stglibs/script_executer.lib/script_executer.h deleted file mode 100644 index 12ba0999..00000000 --- a/stglibs/script_executer.lib/script_executer.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef SCRIPT_EXECUTER_H -#define SCRIPT_EXECUTER_H - -#include - -int ScriptExec(const std::string & str); -void Executer(int msgKey, int msgID, pid_t pid, char * procName); - -#endif //SCRIPT_EXECUTER_H - - diff --git a/stglibs/scriptexecuter.lib/Makefile b/stglibs/scriptexecuter.lib/Makefile new file mode 100644 index 00000000..52f8259f --- /dev/null +++ b/stglibs/scriptexecuter.lib/Makefile @@ -0,0 +1,12 @@ +############################################################################### +# $Id: Makefile,v 1.6 2010/01/21 13:02:12 faust Exp $ +############################################################################### + +LIB_NAME = stgscriptexecuter +PROG = lib$(LIB_NAME) + +SRCS = scriptexecuter.cpp + +INCS = scriptexecuter.h + +include ../Makefile.in diff --git a/stglibs/scriptexecuter.lib/scriptexecuter.cpp b/stglibs/scriptexecuter.lib/scriptexecuter.cpp new file mode 100644 index 00000000..6e21a28f --- /dev/null +++ b/stglibs/scriptexecuter.lib/scriptexecuter.cpp @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "scriptexecuter.h" + +using namespace std; + +#define MAX_SCRIPT_LEN (1100) + +static int msgid; +static bool nonstop; + +//----------------------------------------------------------------------------- +struct SCRIPT_DATA +{ + long mtype; + char script[MAX_SCRIPT_LEN]; +} sd; +//----------------------------------------------------------------------------- +static void CatchUSR1Executer(int) +{ +nonstop = false; +} +//----------------------------------------------------------------------------- +int ScriptExec(const string & str) +{ +if (str.length() >= MAX_SCRIPT_LEN) + return -1; + +int ret; +strncpy(sd.script, str.c_str(), MAX_SCRIPT_LEN); +sd.mtype = 1; +ret = msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0); +if (ret < 0) + { + return -1; + } +return 0; +} +//----------------------------------------------------------------------------- +#ifdef LINUX +void Executer(int, int msgID, pid_t pid, char * procName) +#else +void Executer(int, int msgID, pid_t pid, char *) +#endif +{ +msgid = msgID; +if (pid) + return; +nonstop = true; + +#ifdef LINUX +memset(procName, 0, strlen(procName)); +strcpy(procName, "stg-exec"); +#else +setproctitle("stg-exec"); +#endif + +struct sigaction newsa, oldsa; +sigset_t sigmask; + +sigemptyset(&sigmask); +sigaddset(&sigmask, SIGTERM); +newsa.sa_handler = SIG_IGN; +newsa.sa_mask = sigmask; +newsa.sa_flags = 0; +sigaction(SIGTERM, &newsa, &oldsa); + +sigemptyset(&sigmask); +sigaddset(&sigmask, SIGINT); +newsa.sa_handler = SIG_IGN; +newsa.sa_mask = sigmask; +newsa.sa_flags = 0; +sigaction(SIGINT, &newsa, &oldsa); + +sigemptyset(&sigmask); +sigaddset(&sigmask, SIGHUP); +newsa.sa_handler = SIG_IGN; +newsa.sa_mask = sigmask; +newsa.sa_flags = 0; +sigaction(SIGHUP, &newsa, &oldsa); + +sigemptyset(&sigmask); +sigaddset(&sigmask, SIGUSR1); +newsa.sa_handler = CatchUSR1Executer; +newsa.sa_mask = sigmask; +newsa.sa_flags = 0; +sigaction(SIGUSR1, &newsa, &oldsa); + +int ret; + +SCRIPT_DATA sd; + +while (nonstop) + { + sd.mtype = 1; + ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0); + + if (ret < 0) + { + usleep(20000); + continue; + } + int ret = system(sd.script); + if (ret == -1) + { + // Fork failed + } + } +} +//----------------------------------------------------------------------------- + + diff --git a/stglibs/scriptexecuter.lib/scriptexecuter.h b/stglibs/scriptexecuter.lib/scriptexecuter.h new file mode 100644 index 00000000..12ba0999 --- /dev/null +++ b/stglibs/scriptexecuter.lib/scriptexecuter.h @@ -0,0 +1,11 @@ +#ifndef SCRIPT_EXECUTER_H +#define SCRIPT_EXECUTER_H + +#include + +int ScriptExec(const std::string & str); +void Executer(int msgKey, int msgID, pid_t pid, char * procName); + +#endif //SCRIPT_EXECUTER_H + + diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index 96ad48c2..f2f379d0 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -2,11 +2,11 @@ # $Id: Makefile,v 1.9 2010/08/18 07:47:03 faust Exp $ ############################################################################### -LIB_NAME = srvconf +LIB_NAME = stgsrvconf PROG = lib$(LIB_NAME) -STGLIBS = -lstg_common \ - -lstg_crypto +STGLIBS = -lstgcommon \ + -lstgcrypto LIBS = -lexpat SRCS = netunit.cpp \ diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp index d7c7568f..0038f03d 100644 --- a/stglibs/srvconf.lib/parser.cpp +++ b/stglibs/srvconf.lib/parser.cpp @@ -34,7 +34,7 @@ #include #include "stg/common.h" -#include "stg/stg_const.h" +#include "stg/const.h" #include "servconf.h" using namespace std; diff --git a/stglibs/srvconf.lib/servconf.h b/stglibs/srvconf.lib/servconf.h index a2a74081..67c2f248 100644 --- a/stglibs/srvconf.lib/servconf.h +++ b/stglibs/srvconf.lib/servconf.h @@ -33,7 +33,7 @@ #include #include "stg/os_int.h" -#include "stg/stg_const.h" +#include "stg/const.h" #include "netunit.h" void Start(void *data, const char *el, const char **attr); diff --git a/stglibs/stg_locker.lib/Makefile b/stglibs/stg_locker.lib/Makefile deleted file mode 100644 index 5f99d5c7..00000000 --- a/stglibs/stg_locker.lib/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################### -# $Id: Makefile,v 1.2 2008/12/04 17:11:55 faust Exp $ -############################################################################### - -LIB_NAME = stg_locker -PROG = lib$(LIB_NAME) - -SRCS = stg_locker.cpp - -INCS = stg_locker.h - -LIBS=$(LIB_THREAD) - -include ../Makefile.in diff --git a/stglibs/stg_locker.lib/stg_locker.cpp b/stglibs/stg_locker.lib/stg_locker.cpp deleted file mode 100644 index 0f4007cc..00000000 --- a/stglibs/stg_locker.lib/stg_locker.cpp +++ /dev/null @@ -1,39 +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.2 $ - $Date: 2007/11/30 08:57:49 $ - $Author: nobunaga $ -*/ - - - -#include - -#include "stg_locker.h" - -#ifdef DEBUG_LOCKER - -long long STG_LOCKER::id = 0; -pthread_mutex_t STG_LOCKER::lockerMutex = PTHREAD_MUTEX_INITIALIZER; - -#endif - diff --git a/stglibs/stg_locker.lib/stg_locker.h b/stglibs/stg_locker.lib/stg_locker.h deleted file mode 100644 index 4621388e..00000000 --- a/stglibs/stg_locker.lib/stg_locker.h +++ /dev/null @@ -1,93 +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.5 $ - $Date: 2010/03/04 11:57:11 $ - $Author: faust $ -*/ - - -#ifndef STG_LOCKER_H -#define STG_LOCKER_H - -#include - -#ifdef DEBUG_LOCKER - -#include -#include -#include - -#endif - -#include "stg/noncopyable.h" -//----------------------------------------------------------------------------- -class STG_LOCKER : private NONCOPYABLE -{ -public: - #ifdef DEBUG_LOCKER - STG_LOCKER(pthread_mutex_t * m, const char * __file__, int __line__) - : mutex(m), - file(__file__), - line(__line__), - lockID(0) - #else - STG_LOCKER(pthread_mutex_t * m, const char *, int) - : mutex(m) - #endif - { - mutex = m; - #ifdef DEBUG_LOCKER - pthread_mutex_lock(&lockerMutex); - file = __file__; - line = __line__; - if (id == 0) - pthread_mutex_init(&lockerMutex, NULL); - - lockID = ++id; - std::cout << "Lock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; - pthread_mutex_unlock(&lockerMutex); - #endif - pthread_mutex_lock(mutex); - }; - - ~STG_LOCKER() - { - pthread_mutex_unlock(mutex); - #ifdef DEBUG_LOCKER - pthread_mutex_lock(&lockerMutex); - std::cout << "Unlock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; - pthread_mutex_unlock(&lockerMutex); - #endif - }; -private: - pthread_mutex_t * mutex; - #ifdef DEBUG_LOCKER - std::string file; - int line; - static pthread_mutex_t lockerMutex; - static long long id; - long long lockID; - #endif -}; -//----------------------------------------------------------------------------- - -#endif //STG_LOCKER_H diff --git a/stglibs/stg_logger.lib/Makefile b/stglibs/stg_logger.lib/Makefile deleted file mode 100644 index e19b8928..00000000 --- a/stglibs/stg_logger.lib/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# $Id: Makefile,v 1.3 2007/05/08 14:29:21 faust Exp $ -############################################################################### - -LIB_NAME = stg_logger -PROG = lib$(LIB_NAME) - -SRCS = stg_logger.cpp - -INCS = stg_logger.h - -include ../Makefile.in diff --git a/stglibs/stg_logger.lib/stg_logger.cpp b/stglibs/stg_logger.lib/stg_logger.cpp deleted file mode 100644 index cb96e506..00000000 --- a/stglibs/stg_logger.lib/stg_logger.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include - -#include "stg_logger.h" - -#ifdef STG_TIME -extern const volatile time_t stgTime; -#endif -//----------------------------------------------------------------------------- -STG_LOGGER & GetStgLogger() -{ -static STG_LOGGER logger; -return logger; -} -//----------------------------------------------------------------------------- -STG_LOGGER::STG_LOGGER() - : fileName() -{ -pthread_mutex_init(&mutex, NULL); -} -//----------------------------------------------------------------------------- -STG_LOGGER::~STG_LOGGER() -{ -pthread_mutex_destroy(&mutex); -} -//----------------------------------------------------------------------------- -void STG_LOGGER::SetLogFileName(const std::string & fn) -{ -STG_LOGGER_LOCKER lock(&mutex); -fileName = fn; -} -//----------------------------------------------------------------------------- -void STG_LOGGER::operator()(const char * fmt, ...) -{ -STG_LOGGER_LOCKER lock(&mutex); - -char buff[2048]; - -va_list vl; -va_start(vl, fmt); -vsnprintf(buff, sizeof(buff), fmt, vl); -va_end(vl); - -FILE * f; -if (!fileName.empty()) - { - f = fopen(fileName.c_str(), "at"); - if (f) - { - #ifdef STG_TIME - fprintf(f, "%s", LogDate(stgTime)); - #else - fprintf(f, "%s", LogDate(time(NULL))); - #endif - fprintf(f, " -- "); - fprintf(f, "%s", buff); - fprintf(f, "\n"); - fclose(f); - } - else - { - openlog("stg", LOG_NDELAY, LOG_USER); - syslog(LOG_CRIT, "%s", buff); - closelog(); - } - } -else - { - openlog("stg", LOG_NDELAY, LOG_USER); - syslog(LOG_CRIT, "%s", buff); - closelog(); - } -} -//----------------------------------------------------------------------------- -const char * STG_LOGGER::LogDate(time_t t) -{ -static char s[32]; -if (t == 0) - t = time(NULL); - -struct tm * tt = localtime(&t); - -snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d", - tt->tm_year + 1900, - tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1, - tt->tm_mday < 10 ? "0" : "", tt->tm_mday, - tt->tm_hour < 10 ? "0" : "", tt->tm_hour, - tt->tm_min < 10 ? "0" : "", tt->tm_min, - tt->tm_sec < 10 ? "0" : "", tt->tm_sec); - -return s; -} -//----------------------------------------------------------------------------- diff --git a/stglibs/stg_logger.lib/stg_logger.h b/stglibs/stg_logger.lib/stg_logger.h deleted file mode 100644 index f8375b06..00000000 --- a/stglibs/stg_logger.lib/stg_logger.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef STG_LOGGER_H -#define STG_LOGGER_H - -#include - -#include - -#include "stg/noncopyable.h" - -const char * LogDate(time_t t); -//----------------------------------------------------------------------------- -class STG_LOGGER; -STG_LOGGER & GetStgLogger(); -//----------------------------------------------------------------------------- -class STG_LOGGER_LOCKER : private NONCOPYABLE -{ -public: - STG_LOGGER_LOCKER(pthread_mutex_t * m) : mutex(m) { pthread_mutex_lock(mutex); }; - ~STG_LOGGER_LOCKER() { pthread_mutex_unlock(mutex); }; -private: - pthread_mutex_t * mutex; -}; -//----------------------------------------------------------------------------- -class STG_LOGGER -{ -friend STG_LOGGER & GetStgLogger(); - -public: - ~STG_LOGGER(); - void SetLogFileName(const std::string & fn); - void operator()(const char * fmt, ...); - -private: - STG_LOGGER(); - const char * LogDate(time_t t); - - std::string fileName; - pthread_mutex_t mutex; -}; -//----------------------------------------------------------------------------- - -#endif //STG_LOGGER_H diff --git a/tests/Makefile b/tests/Makefile index ecb054ab..2364db74 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,4 +1,4 @@ -CXXFLAGS+=-g3 -Wall -W -Wextra -DLINUX -I../include -I../projects/stargazer -I../stglibs/conffiles.lib -I. +CXXFLAGS+=-g3 -Wall -W -Wextra -DLINUX -I../include -I../projects/stargazer -I../stglibs/stgconffiles.lib -I. LIBS=-lpthread PROG=tests @@ -6,9 +6,9 @@ SOURCES=main.cpp \ test_raw_ip.cpp \ test_admin_conf.cpp \ test_tariff.cpp \ - test_conffiles.cpp \ + test_stgconffiles.cpp \ ../projects/stargazer/tariff.cpp \ - ../stglibs/conffiles.lib/conffiles.cpp + ../stglibs/stgconffiles.lib/stgconffiles.cpp all: $(PROG) diff --git a/tests/raw_ip_packet_old.h b/tests/raw_ip_packet_old.h index 60af8ace..1fbfe5f3 100644 --- a/tests/raw_ip_packet_old.h +++ b/tests/raw_ip_packet_old.h @@ -6,7 +6,7 @@ #include -#include "stg_const.h" +#include "const.h" #define IPv4 (2)