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 <netinet/in.h>
42 #include "ia_packets.h"
44 #define IA_BIND_ERROR (1)
45 #define IA_SERVER_ERROR (2)
46 #define IA_FCNTL_ERROR (3)
47 #define IA_GETHOSTBYNAME_ERROR (4)
49 #define IA_PROTO_VER (8)
50 #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 string & message, int infoType, int showTime, int sendTime, void * data);
57 typedef void (*tpCallBackErrorFn)(const string & message, int netError, void * data);
58 typedef void (*tpCallBackDirNameFn)(const vector<string> & dirName, void * data);
60 //---------------------------------------------------------------------------
64 friend unsigned long WINAPI RunW(void * data);
66 friend void * RunL(void * data);
70 IA_CLIENT_PROT(const string & sn, uint16_t p, uint16_t localPort = 0);
75 void GetStat(LOADSTAT * ls);
77 void SetServer(const string & sn, unsigned short port);
78 void SetLogin(const string & login);
79 void SetPassword(const 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(string * text) const { *text = messageText; };
97 void GetInfoText(string * text) const { *text = infoText; };
98 int GetStrError(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);
137 mutable string strError;
138 mutable int codeError;
143 BLOWFISH_CTX ctxPass;
146 bool selectedDirs[DIR_NUM];
162 struct sockaddr_in servAddr;
172 tpStatusChangedCb pStatusChangedCb;
173 tpStatChangedCb pStatChangedCb;
174 tpCallBackInfoFn pInfoCb;
175 tpCallBackErrorFn pErrorCb;
176 tpCallBackDirNameFn pDirNameCb;
178 void * statusChangedCbData;
179 void * statChangedCbData;
182 void * dirNameCbData;
184 map<string, int> packetTypes;
186 CONN_SYN_8 * connSyn8;
187 CONN_SYN_ACK_8 * connSynAck8;
188 CONN_ACK_8 * connAck8;
189 ALIVE_SYN_8 * aliveSyn8;
190 ALIVE_ACK_8 * aliveAck8;
191 DISCONN_SYN_8 * disconnSyn8;
192 DISCONN_SYN_ACK_8 * disconnSynAck8;
193 DISCONN_ACK_8 * disconnAck8;
197 //---------------------------------------------------------------------------
199 unsigned long WINAPI RunW(void *);
204 //---------------------------------------------------------------------------