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);
134 int phaseTime; // Âðåìÿ âõîäà â ôàçó
135 string messageText; // Ñîîáùåíèå îá îøèáêå
137 mutable string strError;
138 mutable int codeError;
143 BLOWFISH_CTX ctxPass;
146 bool selectedDirs[DIR_NUM];
157 string serverName; // Èìÿ ñåðâåðà
158 uint16_t port; // Ïîðò ñåðâåðà
159 uint32_t ip; // Proxy IP
162 struct sockaddr_in localAddrS; // Íàø àäðåñ
163 struct sockaddr_in localAddrR; // Íàø àäðåñ
164 struct sockaddr_in servAddr; // àäðåñ ñåðâåðà
169 int protNum; // ×èñëî, êîòîðîå ó÷àñòâóåò â îáìåíå ñîîáùåíèÿìèa
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;
199 //---------------------------------------------------------------------------
201 unsigned long WINAPI RunW(void *);
206 //---------------------------------------------------------------------------