//---------------------------------------------------------------------------
+#ifdef WIN32
+#include <winsock2.h>
+#include <windows.h>
+#include <winbase.h>
+#include <winnt.h>
+#else
+#include <fcntl.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <csignal>
+#endif
+
#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"
+#include "stg/ia.h"
#define IA_NONE (0)
#define IA_CONNECT (1)
//---------------------------------------------------------------------------
#ifndef WIN32
#include <sys/time.h>
+void Sleep(int ms)
+{
+long long res = ms * 1000000;
+struct timespec ts = {res / 1000000000, res % 1000000000};
+nanosleep(&ts, NULL);
+}
+//---------------------------------------------------------------------------
void * RunL(void * data)
{
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data;
static int a = 0;
if (a == 0)
{
- usleep(50000);
+ Sleep(50);
a = 1;
}
return NULL;
}
//---------------------------------------------------------------------------
-void Sleep(int ms)
-{
-usleep(ms * 1000);
-}
-//---------------------------------------------------------------------------
long GetTickCount()
{
struct timeval tv;
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));
+ EncodeString(buffer + db + i * 8, buffer + db + i * 8, &ctxHdr);
}
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));
+ EncodeString(buffer + db, buffer + db, &ctxPass);
db += 8;
}
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));
+ DecodeString(buffer + i * 8, buffer + i * 8, &ctxPass);
}
return 0;
{
connSyn8 = (CONN_SYN_8*)buffer;
+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);
+
#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;
{
connSyn8->dirs |= (selectedDirs[i] << i);
}
-return connSyn8->len;
+return sizeof(CONN_SYN_8);
}
//---------------------------------------------------------------------------
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);
rnd++;
connAck8->rnd = rnd;
-return connAck8->len;
+#ifdef ARCH_BE
+SwapBytes(connAck8->len);
+SwapBytes(connAck8->rnd);
+#endif
+
+return sizeof(CONN_ACK_8);
}
//---------------------------------------------------------------------------
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;
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;
+
+#ifdef ARCH_BE
+SwapBytes(aliveAck8->len);
+SwapBytes(aliveAck8->rnd);
+#endif
+
+return sizeof(ALIVE_ACK_8);
}
//---------------------------------------------------------------------------
int IA_CLIENT_PROT::Prepare_DISCONN_SYN_8(char * buffer)
{
disconnSyn8 = (DISCONN_SYN_8*)buffer;
+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);
+
#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;
+return sizeof(DISCONN_SYN_8);
}
//---------------------------------------------------------------------------
int IA_CLIENT_PROT::Prepare_DISCONN_ACK_8(char * buffer)
{
disconnAck8 = (DISCONN_ACK_8*)buffer;
+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;
+
#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;
+return Min8(sizeof(DISCONN_ACK_8));
}
//---------------------------------------------------------------------------
void IA_CLIENT_PROT::SetStatusChangedCb(tpStatusChangedCb p, void * data)