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)
56 typedef void (*tpStatusChangedCb)(int status, void * data);
57 typedef void (*tpStatChangedCb)(const LOADSTAT & stat, void * data);
58 typedef void (*tpCallBackInfoFn)(const string & message, int infoType, int showTime, int sendTime, void * data);
59 typedef void (*tpCallBackErrorFn)(const string & message, int netError, void * data);
60 typedef void (*tpCallBackDirNameFn)(const vector<string> & dirName, void * data);
62 //---------------------------------------------------------------------------
66 friend unsigned long WINAPI RunW(void * data);
68 friend void * RunL(void * data);
72 IA_CLIENT_PROT(const string & sn, uint16_t p, uint16_t localPort = 0);
77 void GetStat(LOADSTAT * ls);
79 void SetServer(const string & sn, unsigned short port);
80 void SetLogin(const string & login);
81 void SetPassword(const string & password);
82 void SetEnabledDirs(const bool * selectedDirs);
84 void SetStatusChangedCb(tpStatusChangedCb p, void * data);
85 void SetStatChangedCb(tpStatChangedCb p, void * data);
86 void SetInfoCb(tpCallBackInfoFn p, void * data);
87 void SetErrorCb(tpCallBackErrorFn p, void * data);
88 void SetDirNameCb(tpCallBackDirNameFn p, void * data);
92 int GetAuthorized() const { return phase == 3 || phase == 4; };
93 int GetPhase() const { return phase; };
94 int GetStatus() const;
95 int GetReconnect() const { return reconnect; };
96 void SetReconnect(int r) { reconnect = r; };
97 char GetProtoVer() const { return proxyMode ? IA_PROTO_PROXY_VER : IA_PROTO_VER; };
98 void GetMessageText(string * text) const { *text = messageText; };
99 void GetInfoText(string * text) const { *text = infoText; };
100 int GetStrError(string * error) const;
102 void SetProxyMode(bool on) { proxyMode = on; };
103 bool GetProxyMode() const { return proxyMode; };
105 void SetIP(uint32_t ip) { IA_CLIENT_PROT::ip = ip; };
106 uint32_t GetIP() const { return ip; };
112 bool GetNonstop() const { return nonstop; };
114 int DeterminatePacketType(const char * buffer);
116 int Process_CONN_SYN_ACK_8(const char * buffer);
117 int Process_ALIVE_SYN_8(const char * buffer);
118 int Process_DISCONN_SYN_ACK_8(const char * buffer);
119 int Process_FIN_8(const char * buffer);
120 int Process_INFO_8(const char * buffer);
121 int Process_ERROR(const char * buffer);
123 int Prepare_CONN_SYN_8(char * buffer);
124 int Prepare_CONN_ACK_8(char * buffer);
125 int Prepare_ALIVE_ACK_8(char * buffer);
126 int Prepare_DISCONN_SYN_8(char * buffer);
127 int Prepare_DISCONN_ACK_8(char * buffer);
129 void FillHdr8(char * buffer, unsigned long ip);
130 int Send(char * buffer, int len);
131 int Recv(char * buffer, int len);
139 mutable string strError;
140 mutable int codeError;
145 BLOWFISH_CTX ctxPass;
148 bool selectedDirs[DIR_NUM];
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 map<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 //---------------------------------------------------------------------------