2 ** This program is free software; you can redistribute it and/or modify
3 ** it under the terms of the GNU General Public License as published by
4 ** the Free Software Foundation; either version 1, or (at your option)
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 ** GNU General Public License for more details.
12 ** You should have received a copy of the GNU General Public License
13 ** along with this program; if not, write to the Free Software
14 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Date: 2010/03/15 12:57:24 $
24 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
26 //---------------------------------------------------------------------------
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
43 #include "stg/blowfish.h"
44 #include "stg/ia_packets.h"
46 #define IA_BIND_ERROR (1)
47 #define IA_SERVER_ERROR (2)
48 #define IA_FCNTL_ERROR (3)
49 #define IA_GETHOSTBYNAME_ERROR (4)
51 #define IA_PROTO_VER (8)
52 #define IA_PROTO_PROXY_VER (101)
54 typedef void (*tpStatusChangedCb)(int status, void * data);
55 typedef void (*tpStatChangedCb)(const LOADSTAT & stat, void * data);
56 typedef void (*tpCallBackInfoFn)(const std::string & message, int infoType, int showTime, int sendTime, void * data);
57 typedef void (*tpCallBackErrorFn)(const std::string & message, int netError, void * data);
58 typedef void (*tpCallBackDirNameFn)(const std::vector<std::string> & dirName, void * data);
60 //---------------------------------------------------------------------------
64 friend unsigned long WINAPI RunW(void * data);
66 friend void * RunL(void * data);
70 IA_CLIENT_PROT(const std::string & sn, uint16_t p, const std::string & localName = "", uint16_t localPort = 0);
75 void GetStat(LOADSTAT * ls);
77 void SetServer(const std::string & sn, unsigned short port);
78 void SetLogin(const std::string & login);
79 void SetPassword(const std::string & password);
80 void SetEnabledDirs(const bool * selectedDirs);
82 void SetStatusChangedCb(tpStatusChangedCb p, void * data);
83 void SetStatChangedCb(tpStatChangedCb p, void * data);
84 void SetInfoCb(tpCallBackInfoFn p, void * data);
85 void SetErrorCb(tpCallBackErrorFn p, void * data);
86 void SetDirNameCb(tpCallBackDirNameFn p, void * data);
90 int GetAuthorized() const { return phase == 3 || phase == 4; };
91 int GetPhase() const { return phase; };
92 int GetStatus() const;
93 int GetReconnect() const { return reconnect; };
94 void SetReconnect(int r) { reconnect = r; };
95 char GetProtoVer() const { return proxyMode ? IA_PROTO_PROXY_VER : IA_PROTO_VER; };
96 void GetMessageText(std::string * text) const { *text = messageText; };
97 void GetInfoText(std::string * text) const { *text = infoText; };
98 int GetStrError(std::string * error) const;
100 void SetProxyMode(bool on) { proxyMode = on; };
101 bool GetProxyMode() const { return proxyMode; };
103 void SetIP(uint32_t ip) { IA_CLIENT_PROT::ip = ip; };
104 uint32_t GetIP() const { return ip; };
110 bool GetNonstop() const { return nonstop; };
112 int DeterminatePacketType(const char * buffer);
114 int Process_CONN_SYN_ACK_8(const char * buffer);
115 int Process_ALIVE_SYN_8(const char * buffer);
116 int Process_DISCONN_SYN_ACK_8(const char * buffer);
117 int Process_FIN_8(const char * buffer);
118 int Process_INFO_8(const char * buffer);
119 int Process_ERROR(const char * buffer);
121 int Prepare_CONN_SYN_8(char * buffer);
122 int Prepare_CONN_ACK_8(char * buffer);
123 int Prepare_ALIVE_ACK_8(char * buffer);
124 int Prepare_DISCONN_SYN_8(char * buffer);
125 int Prepare_DISCONN_ACK_8(char * buffer);
127 void FillHdr8(char * buffer, unsigned long ip);
128 int Send(char * buffer, int len);
129 int Recv(char * buffer, int len);
135 std::string messageText;
136 std::string infoText;
137 mutable std::string strError;
138 mutable int codeError;
143 BLOWFISH_CTX ctxPass;
146 bool selectedDirs[DIR_NUM];
148 std::string password;
157 std::string serverName;
160 std::string localName;
164 struct sockaddr_in servAddr;
174 tpStatusChangedCb pStatusChangedCb;
175 tpStatChangedCb pStatChangedCb;
176 tpCallBackInfoFn pInfoCb;
177 tpCallBackErrorFn pErrorCb;
178 tpCallBackDirNameFn pDirNameCb;
180 void * statusChangedCbData;
181 void * statChangedCbData;
184 void * dirNameCbData;
186 std::map<std::string, int> packetTypes;
188 CONN_SYN_8 * connSyn8;
189 CONN_SYN_ACK_8 * connSynAck8;
190 CONN_ACK_8 * connAck8;
191 ALIVE_SYN_8 * aliveSyn8;
192 ALIVE_ACK_8 * aliveAck8;
193 DISCONN_SYN_8 * disconnSyn8;
194 DISCONN_SYN_ACK_8 * disconnSynAck8;
195 DISCONN_ACK_8 * disconnAck8;
198 //---------------------------------------------------------------------------
200 unsigned long WINAPI RunW(void *);
205 //---------------------------------------------------------------------------