#define AUTH_H
#include "plugin.h"
-#include "stg_message.h"
+#include "message.h"
#include "noncopyable.h"
class AUTH : public PLUGIN {
--- /dev/null
+/*
+ * 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 <stg34@ua.fm>
+ */
+
+ /*
+ $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
--- /dev/null
+#ifndef STG_MESSAGES_H
+#define STG_MESSAGES_H
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.3 $
+ $Date: 2010/03/04 11:49:52 $
+ */
+
+#include <ctime>
+#include <string>
+
+#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
#include <cstring>
-#include "stg_const.h"
+#include "const.h"
#include "common.h"
#define IPv4 (2)
+++ /dev/null
-/*
- * 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 <stg34@ua.fm>
- */
-
- /*
- $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
+++ /dev/null
-#ifndef STG_MESSAGES_H
-#define STG_MESSAGES_H
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.3 $
- $Date: 2010/03/04 11:49:52 $
- */
-
-#include <ctime>
-#include <string>
-
-#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
#include "admin_conf.h"
#include "tariff_conf.h"
#include "module_settings.h"
-#include "stg_message.h"
+#include "message.h"
//-----------------------------------------------------------------------------
class STORE {
#include <vector>
#include "resetable.h"
-#include "stg_const.h"
+#include "const.h"
//-----------------------------------------------------------------------------
enum
#include "os_int.h"
#include "notifer.h"
-#include "stg_message.h"
+#include "message.h"
#include "tariff.h"
#include "user_traff.h"
#include <string>
#include <vector>
-#include "stg_const.h"
+#include "const.h"
#include "user_ips.h"
#include "resetable.h"
#include "os_int.h"
#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"
#include <iostream>
#include <vector>
-#include "stg_const.h"
+#include "const.h"
#include "os_int.h"
enum TRAFF_DIRECTION {TRAFF_UPLOAD, TRAFF_DOWNLOAD};
SRCS = ./main.cpp \
./settings_impl.cpp
-STGLIBS = -lstg_logger \
- -lstg_common \
+STGLIBS = -lstglogger \
+ -lstgcommon \
-ldotconfpp \
- -lstg_crypto
+ -lstgcrypto
LIBS += $(LIB_THREAD)
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
#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"
./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
SRCS = ./rlm_stg.cpp \
./stg_client.cpp
-STGLIBS = -lstg_common \
- -lstg_crypto
+STGLIBS = -lstgcommon \
+ -lstgcrypto
LIBS += $(LIB_THREAD)
./listener.cpp \
./pidfile.cpp
-STGLIBS = -lstg_logger \
- -lstg_common \
- -lstg_crypto \
- -lscript_executer \
- -lconffiles
+STGLIBS = -lstglogger \
+ -lstgcommon \
+ -lstgcrypto \
+ -lstgscriptexecuter \
+ -lstgconffiles
LIBS += $(LIB_THREAD)
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" ]
#include <algorithm>
#include "stg/script_executer.h"
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
#include "stg/common.h"
#include "listener.h"
#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
{
#include <set>
#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"
./settings_impl.cpp \
./web.cpp
-STGLIBS = -lconffiles \
- -lstg_crypto \
- -lstg_common \
- -lia_auth_c
+STGLIBS = -lstgconffiles \
+ -lstgcrypto \
+ -lstgcommon \
+ -lstgia
LIBS += $(LIB_THREAD)
STG_LIBS="crypto.lib
common.lib
conffiles.lib
- ia_auth_c.lib"
+ ia.lib"
if [ "$OS" = "linux" ]
then
#include <iostream>
#include <vector>
-#include "stg/ia_auth_c.h"
+#include "stg/ia.h"
#include "stg/common.h"
#include "web.h"
#include "settings_impl.h"
#include <string>
#include <list>
-#include "stg/stg_const.h"
+#include "stg/const.h"
#include "stg/ia_packets.h"
using namespace std;
SRCS = ./main.cpp \
./common_sg.cpp
-STGLIBS = -lconffiles \
- -lstg_common \
- -lstg_crypto \
- -lsrvconf
+STGLIBS = -lstgconffiles \
+ -lstgcommon \
+ -lstgcrypto \
+ -lstgsrvconf
LIBS += -lexpat \
$(LIB_THREAD)
#include <string>
#include "stg/resetable.h"
-#include "stg/stg_const.h"
+#include "stg/const.h"
#include "stg/os_int.h"
#define TARIFF_NOW (0)
SRCS = ./main.cpp \
./parser.cpp
-LIBS = -lconffiles \
- -lstg_crypto \
- -lstg_common \
- -lsrvconf
+LIBS = -lstgconffiles \
+ -lstgcrypto \
+ -lstgcommon \
+ -lstgsrvconf
LIBS += -lexpat \
$(LIB_THREAD)
#include "stg/resetable.h"
#include "stg/os_int.h"
-#include "stg/stg_const.h"
+#include "stg/const.h"
#ifndef ENODATA
#define ENODATA 61
./user_property.cpp \
./users_impl.cpp
-STGLIBS = -lstg_logger \
- -lstg_locker \
- -lstg_common \
- -lscript_executer \
+STGLIBS = -lstglogger \
+ -lstglocker \
+ -lstgcommon \
+ -lstgscriptexecuter \
-ldotconfpp
LIBS += -lexpat
#include <algorithm>
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
// Polymorphick action invocation
template <class ACTIVE_CLASS, typename DATA_TYPE>
#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:
#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"
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"
#include <cerrno>
#include <cstring>
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
#include "stg/common.h"
#include "eventloop.h"
#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"
SRCS = ./ao.cpp
-STGLIBS = -lstg_common
+STGLIBS = -lstgcommon
include ../../Makefile.in
SRCS = ./inetaccess.cpp
-STGLIBS = -lstg_common -lstg_crypto
+STGLIBS = -lstgcommon -lstgcrypto
include ../../Makefile.in
#include <algorithm>
#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"
#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();
./tcp.c \
./udp.c
-STGLIBS = -lstg_common
+STGLIBS = -lstgcommon
LIBS += $(LIB_THREAD)
SRCS = ./cap_nf.cpp
LIBS += $(LIB_THREAD)
-STGLIBS = -lstg_common
+STGLIBS = -lstgcommon
include ../../Makefile.in
SRCS = ./divert_cap.cpp
-STGLIBS = -lstg_common
+STGLIBS = -lstgcommon
LIBS += $(LIB_THREAD)
SRCS = ./ether_cap.cpp
-STGLIBS = -lstg_common
+STGLIBS = -lstgcommon
LIBS += $(LIB_THREAD)
SRCS = ./ether_cap.cpp
LIBS += $(LIB_THREAD)
-STGLIBS = -lstg_common
+STGLIBS = -lstgcommon
include ../../Makefile.in
./libipq.c
LIBS += $(LIB_THREAD)
-STGLIBS = -lstg_common
+STGLIBS = -lstgcommon
include ../../Makefile.in
LIBS += -liconv
endif
-STGLIBS = -lstg_common -lstg_logger
+STGLIBS = -lstgcommon -lstglogger
include ../../Makefile.in
-#include "stg/stg_message.h"
+#include "stg/message.h"
#include "stg/common.h"
#include "utils.h"
#include "messages_methods.h"
LIBS += -lexpat \
-lboost_thread-mt
-STGLIBS = -lstg_common -lstg_logger -lcrypto
+STGLIBS = -lstgcommon -lstglogger -lcrypto
include ../../Makefile.in
LIBS += -lexpat \
$(LIB_THREAD)
-STGLIBS = -lstg_common -lstg_logger -lstg_crypto
+STGLIBS = -lstgcommon -lstglogger -lstgcrypto
include ../../Makefile.in
#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"
#include <vector>
#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;
LIBS += -lexpat \
$(LIB_THREAD)
-STGLIBS = -lstg_common -lstg_logger
+STGLIBS = -lstgcommon -lstglogger
include ../../Makefile.in
#include "users.h"
#include "admins.h"
#include "tariffs.h"
-#include "stg_logger.h"
+#include "logger.h"
using namespace std;
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 {
SRCS = ./ping.cpp
-STGLIBS = -lstg_pinger -lstg_common
+STGLIBS = -lstgpinger -lstgcommon
include ../../Makefile.in
#include <algorithm>
#include "stg/user.h"
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
#include "stg/user_property.h"
#include "ping.h"
SRCS = ./radius.cpp
-STGLIBS = -lstg_common -lstg_crypto
+STGLIBS = -lstgcommon -lstgcrypto
include ../../Makefile.in
SRCS = ./rscript.cpp \
./nrmap_parser.cpp
-STGLIBS = -lstg_common -lstg_crypto
+STGLIBS = -lstgcommon -lstgcrypto
include ../../Makefile.in
#include <algorithm>
#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"
SRCS = ./userstat.cpp \
./datathread.cpp
-LIBS += -lstg_common \
- -lstg_crypto
+LIBS += -lstgcommon \
+ -lstgcrypto
include ../../Makefile.in
SRCS = ./file_store.cpp
-STGLIBS = -lconffiles -lstg_common -lstg_locker -lstg_crypto
+STGLIBS = -lstgconffiles -lstgcommon -lstglocker -lstgcrypto
include ../../Makefile.in
#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"
./firebird_store_users.cpp \
./firebird_store_utils.cpp
-STGLIBS = -libpp -lstg_common -lstg_locker -lstg_crypto
+STGLIBS = -libpp -lstgcommon -lstglocker -lstgcrypto
include ../../Makefile.in
#include <map>
#include "stg/store.h"
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
#include "stg/ibpp.h"
struct ToLower {
*
*/
-#include "stg/stg_const.h"
+#include "stg/const.h"
#include "firebird_store.h"
#include "stg/ibpp.h"
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)
./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)
#include <libpq-fe.h>
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
#include "stg/admin_conf.h"
#include "stg/blowfish.h"
#include "postgresql_store.h"
#include <libpq-fe.h>
#include "postgresql_store.h"
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetCorpsList(vector<string> * corpsList) const
#include <libpq-fe.h>
#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
#include <libpq-fe.h>
#include "postgresql_store.h"
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetServicesList(vector<string> * servicesList) const
#include <libpq-fe.h>
#include "postgresql_store.h"
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetTariffsList(vector<string> * tariffsList) const
#include <libpq-fe.h>
-#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"
#include <cerrno>
#include <string>
-#include "stg/stg_logger.h"
+#include "stg/logger.h"
#include "stg/dotconfpp.h"
#include "settings_impl.h"
#include "stg/settings.h"
#include "stg/common.h"
-#include "stg/stg_logger.h"
+#include "stg/logger.h"
#include "stg/module_settings.h"
//-----------------------------------------------------------------------------
#include <algorithm>
#include <vector>
-#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"
#include <cstdio> // fopen and similar
#include "stg/common.h"
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
#include "traffcounter_impl.h"
#include "stg_timer.h"
#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"
#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"
//-----------------------------------------------------------------------------
#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"
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
#include <string>
#include "stg/os_int.h"
-#include "stg/stg_const.h"
+#include "stg/const.h"
#define STAT_TIME_3 (1)
#define STAT_TIME_2 (2)
+++ /dev/null
-/*
- * $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 <time.h>
-
-char * stg_strptime(const char * a, const char * b, struct tm * tm)
-{
-return strptime(a, b, tm);
-}
-
--- /dev/null
+/*
+ * $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 <time.h>
+
+char * stg_strptime(const char * a, const char * b, struct tm * tm)
+{
+return strptime(a, b, tm);
+}
+
# $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
# $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 \
#include <cstring>
#include "blowfish.h"
-#include "stg/stg_const.h"
+#include "stg/const.h"
/*typedef struct _BCoptions
{
--- /dev/null
+###############################################################################
+# $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
--- /dev/null
+//---------------------------------------------------------------------------
+
+#include <vcl.h>
+#pragma hdrstop
+#define Library
+
+// To add a file to the library use the Project menu 'Add to Project'.
+
+
\ No newline at end of file
--- /dev/null
+<?xml version='1.0' encoding='utf-8' ?>
+<!-- C++Builder XML Project -->
+<PROJECT>
+ <MACROS>
+ <VERSION value="BCB.06.00"/>
+ <PROJECT value="..\..\lib\ia_auth_c.lib"/>
+ <OBJFILES value="ia_auth_c.obj"/>
+ <RESFILES value=""/>
+ <IDLFILES value=""/>
+ <IDLGENFILES value=""/>
+ <DEFFILE value=""/>
+ <RESDEPEN value="$(RESFILES)"/>
+ <LIBFILES value=""/>
+ <LIBRARIES value=""/>
+ <PACKAGES value=""/>
+ <PATHCPP value=".;"/>
+ <PATHPAS value=".;"/>
+ <PATHRC value=".;"/>
+ <PATHASM value=".;"/>
+ <LINKER value="TLib"/>
+ <USERDEFINES value="_DEBUG;WIN32"/>
+ <SYSDEFINES value="_RTLDLL;NO_STRICT"/>
+ <MAINSOURCE value="ia_auth_c.bpf"/>
+ <INCLUDEPATH value="$(BCB)\include;$(BCB)\include\vcl;..\..\include"/>
+ <LIBPATH value="$(BCB)\lib\obj;$(BCB)\lib"/>
+ <WARNINGS value="-w-par"/>
+ <LISTFILE value=""/>
+ <OTHERFILES value=""/>
+ </MACROS>
+ <OPTIONS>
+ <IDLCFLAGS value="-I$(BCB)\include -I$(BCB)\include\vcl -I..\..\include -src_suffix cpp
+ -D_DEBUG -DWIN32 -boa"/>
+ <CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c
+ -tW -tWM"/>
+ <PFLAGS value="-$YD -$W -$O- -$A8 -v -JPHNE -M"/>
+ <AFLAGS value="/mx /w2 /zd"/>
+ <LFLAGS value=""/>
+ <OTHERFILES value=""/>
+ </OPTIONS>
+ <LINKER>
+ <ALLOBJ value="$(OBJFILES)"/>
+ <ALLLIB value=""/>
+ <OTHERFILES value=""/>
+ </LINKER>
+ <FILELIST>
+ <FILE FILENAME="ia_auth_c.bpf" FORMNAME="" UNITNAME="ia_auth_c" CONTAINERID="BPF" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="packet.h" FORMNAME="" UNITNAME="packet.h" CONTAINERID="" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="ia_auth_c.h" FORMNAME="" UNITNAME="ia_auth_c.h" CONTAINERID="" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="ia_auth_c.cpp" FORMNAME="" UNITNAME="ia_auth_c.cpp" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
+ </FILELIST>
+ <BUILDTOOLS>
+ </BUILDTOOLS>
+
+ <IDEOPTIONS>
+[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
+ </IDEOPTIONS>
+</PROJECT>
\ No newline at end of file
--- /dev/null
+/*
+** 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 <stg34@stargazer.dp.ua>
+* Maxim Mamontov <faust@stargazer.dp.ua>
+* Andrey Rakhmanov <andrey_rakhmanov@yahoo.com> - bugfixes.
+*/
+
+//---------------------------------------------------------------------------
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cassert>
+
+#ifdef WIN32
+ #include <winsock2.h>
+ #include <windows.h>
+ #include <winbase.h>
+ #include <winnt.h>
+#else
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netdb.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+ #include <unistd.h>
+#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 <sys/time.h>
+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<string, int>::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<string> 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;
+}
+//---------------------------------------------------------------------------
--- /dev/null
+/*
+** 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 <stg34@stargazer.dp.ua>
+*/
+//---------------------------------------------------------------------------
+#ifndef IA_AUTH_C_H
+#define IA_AUTH_C_H
+
+#ifndef WIN32
+#include <netinet/in.h>
+#include <pthread.h>
+#else
+#include <winsock2.h>
+#endif
+
+#include <string>
+#include <vector>
+#include <map>
+
+#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<string> & 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<string, int> 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
+++ /dev/null
-###############################################################################
-# $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
+++ /dev/null
-//---------------------------------------------------------------------------
-
-#include <vcl.h>
-#pragma hdrstop
-#define Library
-
-// To add a file to the library use the Project menu 'Add to Project'.
-
-
\ No newline at end of file
+++ /dev/null
-<?xml version='1.0' encoding='utf-8' ?>
-<!-- C++Builder XML Project -->
-<PROJECT>
- <MACROS>
- <VERSION value="BCB.06.00"/>
- <PROJECT value="..\..\lib\ia_auth_c.lib"/>
- <OBJFILES value="ia_auth_c.obj"/>
- <RESFILES value=""/>
- <IDLFILES value=""/>
- <IDLGENFILES value=""/>
- <DEFFILE value=""/>
- <RESDEPEN value="$(RESFILES)"/>
- <LIBFILES value=""/>
- <LIBRARIES value=""/>
- <PACKAGES value=""/>
- <PATHCPP value=".;"/>
- <PATHPAS value=".;"/>
- <PATHRC value=".;"/>
- <PATHASM value=".;"/>
- <LINKER value="TLib"/>
- <USERDEFINES value="_DEBUG;WIN32"/>
- <SYSDEFINES value="_RTLDLL;NO_STRICT"/>
- <MAINSOURCE value="ia_auth_c.bpf"/>
- <INCLUDEPATH value="$(BCB)\include;$(BCB)\include\vcl;..\..\include"/>
- <LIBPATH value="$(BCB)\lib\obj;$(BCB)\lib"/>
- <WARNINGS value="-w-par"/>
- <LISTFILE value=""/>
- <OTHERFILES value=""/>
- </MACROS>
- <OPTIONS>
- <IDLCFLAGS value="-I$(BCB)\include -I$(BCB)\include\vcl -I..\..\include -src_suffix cpp
- -D_DEBUG -DWIN32 -boa"/>
- <CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c
- -tW -tWM"/>
- <PFLAGS value="-$YD -$W -$O- -$A8 -v -JPHNE -M"/>
- <AFLAGS value="/mx /w2 /zd"/>
- <LFLAGS value=""/>
- <OTHERFILES value=""/>
- </OPTIONS>
- <LINKER>
- <ALLOBJ value="$(OBJFILES)"/>
- <ALLLIB value=""/>
- <OTHERFILES value=""/>
- </LINKER>
- <FILELIST>
- <FILE FILENAME="ia_auth_c.bpf" FORMNAME="" UNITNAME="ia_auth_c" CONTAINERID="BPF" DESIGNCLASS="" LOCALCOMMAND=""/>
- <FILE FILENAME="packet.h" FORMNAME="" UNITNAME="packet.h" CONTAINERID="" DESIGNCLASS="" LOCALCOMMAND=""/>
- <FILE FILENAME="ia_auth_c.h" FORMNAME="" UNITNAME="ia_auth_c.h" CONTAINERID="" DESIGNCLASS="" LOCALCOMMAND=""/>
- <FILE FILENAME="ia_auth_c.cpp" FORMNAME="" UNITNAME="ia_auth_c.cpp" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
- </FILELIST>
- <BUILDTOOLS>
- </BUILDTOOLS>
-
- <IDEOPTIONS>
-[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
- </IDEOPTIONS>
-</PROJECT>
\ No newline at end of file
+++ /dev/null
-/*
-** 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 <stg34@stargazer.dp.ua>
-* Maxim Mamontov <faust@stargazer.dp.ua>
-* Andrey Rakhmanov <andrey_rakhmanov@yahoo.com> - bugfixes.
-*/
-
-//---------------------------------------------------------------------------
-
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <cassert>
-
-#ifdef WIN32
- #include <winsock2.h>
- #include <windows.h>
- #include <winbase.h>
- #include <winnt.h>
-#else
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
-#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 <sys/time.h>
-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<string, int>::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<string> 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;
-}
-//---------------------------------------------------------------------------
+++ /dev/null
-/*
-** 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 <stg34@stargazer.dp.ua>
-*/
-//---------------------------------------------------------------------------
-#ifndef IA_AUTH_C_H
-#define IA_AUTH_C_H
-
-#ifndef WIN32
-#include <netinet/in.h>
-#include <pthread.h>
-#else
-#include <winsock2.h>
-#endif
-
-#include <string>
-#include <vector>
-#include <map>
-
-#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<string> & 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<string, int> 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
--- /dev/null
+###############################################################################
+# $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
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+/*
+ $Revision: 1.2 $
+ $Date: 2007/11/30 08:57:49 $
+ $Author: nobunaga $
+*/
+
+
+
+#include <pthread.h>
+
+#include "locker.h"
+
+#ifdef DEBUG_LOCKER
+
+long long STG_LOCKER::id = 0;
+pthread_mutex_t STG_LOCKER::lockerMutex = PTHREAD_MUTEX_INITIALIZER;
+
+#endif
+
--- /dev/null
+/*
+ * 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 <stg34@stargazer.dp.ua>
+ */
+
+/*
+ $Revision: 1.5 $
+ $Date: 2010/03/04 11:57:11 $
+ $Author: faust $
+*/
+
+
+#ifndef STG_LOCKER_H
+#define STG_LOCKER_H
+
+#include <pthread.h>
+
+#ifdef DEBUG_LOCKER
+
+#include <iostream>
+#include <string>
+#include <pthread.h>
+
+#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
--- /dev/null
+###############################################################################
+# $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
--- /dev/null
+#include <stdio.h>
+#include <stdarg.h>
+#include <syslog.h>
+
+#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;
+}
+//-----------------------------------------------------------------------------
--- /dev/null
+#ifndef STG_LOGGER_H
+#define STG_LOGGER_H
+
+#include <pthread.h>
+
+#include <string>
+
+#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
# $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
test: all
g++ -c test.cpp
- g++ -o test test.o ./libstg_pinger.a -lpthread
+ g++ -o test test.o ./libstgpinger.a -lpthread
#include "pinger.h"
#include "stg/common.h"
-#include "stg/stg_locker.h"
+#include "stg/locker.h"
#ifdef STG_TIME
extern volatile time_t stgTime;
+++ /dev/null
-###############################################################################
-# $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
+++ /dev/null
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <cstring>
-#include <cerrno>
-#include <csignal>
-
-#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
- }
- }
-}
-//-----------------------------------------------------------------------------
-
-
+++ /dev/null
-#ifndef SCRIPT_EXECUTER_H
-#define SCRIPT_EXECUTER_H
-
-#include <string>
-
-int ScriptExec(const std::string & str);
-void Executer(int msgKey, int msgID, pid_t pid, char * procName);
-
-#endif //SCRIPT_EXECUTER_H
-
-
--- /dev/null
+###############################################################################
+# $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
--- /dev/null
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <cstring>
+#include <cerrno>
+#include <csignal>
+
+#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
+ }
+ }
+}
+//-----------------------------------------------------------------------------
+
+
--- /dev/null
+#ifndef SCRIPT_EXECUTER_H
+#define SCRIPT_EXECUTER_H
+
+#include <string>
+
+int ScriptExec(const std::string & str);
+void Executer(int msgKey, int msgID, pid_t pid, char * procName);
+
+#endif //SCRIPT_EXECUTER_H
+
+
# $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 \
#include <string>
#include "stg/common.h"
-#include "stg/stg_const.h"
+#include "stg/const.h"
#include "servconf.h"
using namespace std;
#include <string>
#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);
+++ /dev/null
-###############################################################################
-# $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
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.2 $
- $Date: 2007/11/30 08:57:49 $
- $Author: nobunaga $
-*/
-
-
-
-#include <pthread.h>
-
-#include "stg_locker.h"
-
-#ifdef DEBUG_LOCKER
-
-long long STG_LOCKER::id = 0;
-pthread_mutex_t STG_LOCKER::lockerMutex = PTHREAD_MUTEX_INITIALIZER;
-
-#endif
-
+++ /dev/null
-/*
- * 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 <stg34@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.5 $
- $Date: 2010/03/04 11:57:11 $
- $Author: faust $
-*/
-
-
-#ifndef STG_LOCKER_H
-#define STG_LOCKER_H
-
-#include <pthread.h>
-
-#ifdef DEBUG_LOCKER
-
-#include <iostream>
-#include <string>
-#include <pthread.h>
-
-#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
+++ /dev/null
-###############################################################################
-# $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
+++ /dev/null
-#include <stdio.h>
-#include <stdarg.h>
-#include <syslog.h>
-
-#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;
-}
-//-----------------------------------------------------------------------------
+++ /dev/null
-#ifndef STG_LOGGER_H
-#define STG_LOGGER_H
-
-#include <pthread.h>
-
-#include <string>
-
-#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
-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
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)
#include <cstring>
-#include "stg_const.h"
+#include "const.h"
#define IPv4 (2)