summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2016-11-29 20:14:10 +0300
committerGeorge Hazan <ghazan@miranda.im>2016-11-29 20:14:10 +0300
commit1f9fcfce83e81ff27d7c0ff80a5e85cdc89118c7 (patch)
tree812d8e2b475f9f68b865b126a422c18ebd44faa5 /protocols
parent30a6aec84f2a27a5ef5c8d438037817c2083014b (diff)
code cleaning
Diffstat (limited to 'protocols')
-rw-r--r--protocols/ICQCorp/src/corp.cpp84
-rw-r--r--protocols/ICQCorp/src/event.cpp77
-rw-r--r--protocols/ICQCorp/src/options.cpp90
-rw-r--r--protocols/ICQCorp/src/packet.cpp199
-rw-r--r--protocols/ICQCorp/src/protocol.cpp3748
-rw-r--r--protocols/ICQCorp/src/services.cpp45
-rw-r--r--protocols/ICQCorp/src/socket.cpp395
-rw-r--r--protocols/ICQCorp/src/transfer.cpp706
-rw-r--r--protocols/ICQCorp/src/user.cpp142
9 files changed, 2680 insertions, 2806 deletions
diff --git a/protocols/ICQCorp/src/corp.cpp b/protocols/ICQCorp/src/corp.cpp
index 8d57af8048..cd6388e59d 100644
--- a/protocols/ICQCorp/src/corp.cpp
+++ b/protocols/ICQCorp/src/corp.cpp
@@ -1,20 +1,20 @@
/*
- ICQ Corporate protocol plugin for Miranda IM.
- Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ ICQ Corporate protocol plugin for Miranda IM.
+ Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "corp.h"
@@ -42,17 +42,18 @@ PLUGININFOEX pluginInfo =
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD reason, LPVOID)
{
- hInstance = hModule;
- if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(hModule);
- return TRUE;
+ hInstance = hModule;
+ if (reason == DLL_PROCESS_ATTACH)
+ DisableThreadLibraryCalls(hModule);
+ return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
extern "C" __declspec(dllexport) int Unload()
{
- UnloadServices();
- return 0;
+ UnloadServices();
+ return 0;
}
///////////////////////////////////////////////////////////////////////////////
@@ -82,7 +83,7 @@ extern "C" __declspec(dllexport) int Load()
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
- return &pluginInfo;
+ return &pluginInfo;
}
///////////////////////////////////////////////////////////////////////////////
@@ -90,26 +91,25 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
#ifdef _DEBUG
void T(char *format, ...)
{
- char buffer[8196], bufferTime[64];
- va_list list;
- SYSTEMTIME t;
-
- va_start(list, format);
- vsprintf(buffer, format, list);
- va_end(list);
-
- GetLocalTime(&t);
- sprintf(bufferTime, "%.2d:%.2d:%.2d.%.3d ", t.wHour, t.wMinute, t.wSecond, t.wMilliseconds);
-
- static HANDLE hFile = INVALID_HANDLE_VALUE;
- DWORD result;
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- hFile = CreateFile("ICQ Corp.log", GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);
- SetFilePointer(hFile, 0, 0, FILE_END);
- }
- WriteFile(hFile, bufferTime, (DWORD)mir_strlen(bufferTime), &result, NULL);
+ char buffer[8196], bufferTime[64];
+ va_list list;
+ SYSTEMTIME t;
+
+ va_start(list, format);
+ vsprintf(buffer, format, list);
+ va_end(list);
+
+ GetLocalTime(&t);
+ sprintf(bufferTime, "%.2d:%.2d:%.2d.%.3d ", t.wHour, t.wMinute, t.wSecond, t.wMilliseconds);
+
+ static HANDLE hFile = INVALID_HANDLE_VALUE;
+ if (hFile == INVALID_HANDLE_VALUE) {
+ hFile = CreateFile("ICQ Corp.log", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);
+ SetFilePointer(hFile, 0, 0, FILE_END);
+ }
+
+ DWORD result;
+ WriteFile(hFile, bufferTime, (DWORD)mir_strlen(bufferTime), &result, NULL);
WriteFile(hFile, buffer, (DWORD)mir_strlen(buffer), &result, NULL);
}
#endif
diff --git a/protocols/ICQCorp/src/event.cpp b/protocols/ICQCorp/src/event.cpp
index 44a0a2bf56..70ccbedf3f 100644
--- a/protocols/ICQCorp/src/event.cpp
+++ b/protocols/ICQCorp/src/event.cpp
@@ -25,87 +25,90 @@ std::vector <ICQEvent *> icqEvents;
static void WINAPI eventTimerProc(HWND, UINT, UINT_PTR hTimer, DWORD)
{
- unsigned int i;
+ KillTimer(NULL, hTimer);
- KillTimer(NULL, hTimer);
- for (i=0; i<icqEvents.size(); i++) if (hTimer == icqEvents[i]->hTimer) icqEvents[i]->noAck();
+ for (size_t i = 0; i < icqEvents.size(); i++)
+ if (hTimer == icqEvents[i]->hTimer)
+ icqEvents[i]->noAck();
}
///////////////////////////////////////////////////////////////////////////////
-ICQEvent *getEvent(SOCKET hSocket, unsigned int sequence)
+ICQEvent* getEvent(SOCKET hSocket, unsigned int sequence)
{
- unsigned int i;
+ for (size_t i = 0; i < icqEvents.size(); i++)
+ if (icqEvents[i]->isEvent(hSocket, sequence))
+ return icqEvents[i];
- for (i=0; i<icqEvents.size(); i++) if (icqEvents[i]->isEvent(hSocket, sequence)) return icqEvents[i];
- return NULL;
+ return NULL;
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent::ICQEvent(unsigned short theCmd, unsigned short theSubCmd, unsigned int theSequence,
- unsigned int theUin, Socket *theSocket, Packet *thePacket, int theReply)
+ unsigned int theUin, Socket *theSocket, Packet *thePacket, int theReply)
{
- cmd = theCmd;
- subCmd = theSubCmd;
- sequence = theSequence;
- uin = theUin;
- socket = theSocket;
- packet = new Packet(thePacket);
- reply = theReply;
-
- hTimer = NULL;
- retries = 0;
+ cmd = theCmd;
+ subCmd = theSubCmd;
+ sequence = theSequence;
+ uin = theUin;
+ socket = theSocket;
+ packet = new Packet(thePacket);
+ reply = theReply;
+
+ hTimer = NULL;
+ retries = 0;
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent::~ICQEvent()
{
- stop();
- delete packet;
+ stop();
+ delete packet;
}
///////////////////////////////////////////////////////////////////////////////
bool ICQEvent::start()
{
- // send the packet
- if (!socket->sendPacket(*packet)) return false;
+ // send the packet
+ if (!socket->sendPacket(*packet))
+ return false;
- if (cmd != ICQ_CMDxTCP_START) hTimer = SetTimer(NULL, 0, MAX_WAIT_ACK, eventTimerProc);
- return true;
+ if (cmd != ICQ_CMDxTCP_START)
+ hTimer = SetTimer(NULL, 0, MAX_WAIT_ACK, eventTimerProc);
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
void ICQEvent::stop()
{
- if (hTimer)
- {
- KillTimer(NULL, hTimer);
- hTimer = NULL;
- }
+ if (hTimer) {
+ KillTimer(NULL, hTimer);
+ hTimer = NULL;
+ }
}
///////////////////////////////////////////////////////////////////////////////
bool ICQEvent::isEvent(SOCKET hSocket, unsigned long theSequence)
{
- return socket->handleVal == hSocket && sequence == theSequence;
+ return socket->handleVal == hSocket && sequence == theSequence;
}
///////////////////////////////////////////////////////////////////////////////
void ICQEvent::noAck()
{
- hTimer = NULL;
- if (socket->connected() && retries < MAX_SERVER_RETRIES && cmd != ICQ_CMDxTCP_START)
- {
- retries++;
- start();
- }
- else icq.doneEvent(false, socket->handleVal, sequence);
+ hTimer = NULL;
+ if (socket->connected() && retries < MAX_SERVER_RETRIES && cmd != ICQ_CMDxTCP_START)
+ {
+ retries++;
+ start();
+ }
+ else icq.doneEvent(false, socket->handleVal, sequence);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/ICQCorp/src/options.cpp b/protocols/ICQCorp/src/options.cpp
index 707d2c5b0d..7aa7a49ec1 100644
--- a/protocols/ICQCorp/src/options.cpp
+++ b/protocols/ICQCorp/src/options.cpp
@@ -23,66 +23,62 @@
static INT_PTR CALLBACK icqOptionsDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- DBVARIANT dbv;
- char str[128];
+ DBVARIANT dbv;
+ char str[128];
- switch (msg)
- {
- case WM_INITDIALOG:
- TranslateDialogDefault(hWnd);
- SetDlgItemInt(hWnd, IDC_OPT_UIN, db_get_dw(NULL, protoName, "UIN", 0), FALSE);
- if (!db_get(NULL, protoName, "Password", &dbv))
- {
- SetDlgItemText(hWnd, IDC_OPT_PASSWORD, dbv.pszVal);
- db_free(&dbv);
- }
- if(!db_get(NULL, protoName, "Server", &dbv))
- {
- SetDlgItemText(hWnd, IDC_OPT_SERVER, dbv.pszVal);
- db_free(&dbv);
- }
- SetDlgItemInt(hWnd, IDC_OPT_PORT, db_get_w(NULL, protoName, "Port", 4000), FALSE);
- ShowWindow(GetDlgItem(hWnd, IDC_OPT_RECONNECT), SW_HIDE);
- return TRUE;
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hWnd);
+ SetDlgItemInt(hWnd, IDC_OPT_UIN, db_get_dw(NULL, protoName, "UIN", 0), FALSE);
+ if (!db_get(NULL, protoName, "Password", &dbv)) {
+ SetDlgItemText(hWnd, IDC_OPT_PASSWORD, dbv.pszVal);
+ db_free(&dbv);
+ }
+ if (!db_get(NULL, protoName, "Server", &dbv)) {
+ SetDlgItemText(hWnd, IDC_OPT_SERVER, dbv.pszVal);
+ db_free(&dbv);
+ }
+ SetDlgItemInt(hWnd, IDC_OPT_PORT, db_get_w(NULL, protoName, "Port", 4000), FALSE);
+ ShowWindow(GetDlgItem(hWnd, IDC_OPT_RECONNECT), SW_HIDE);
+ return TRUE;
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_APPLY:
- db_set_dw(NULL, protoName, "UIN", (DWORD)GetDlgItemInt(hWnd, IDC_OPT_UIN, NULL, FALSE));
- GetDlgItemText(hWnd, IDC_OPT_PASSWORD, str, sizeof(str));
- db_set_s(NULL, protoName, "Password", str);
- GetDlgItemText(hWnd, IDC_OPT_SERVER, str, sizeof(str));
- db_set_s(NULL, protoName, "Server", str);
- db_set_w(NULL, protoName, "Port", (WORD)GetDlgItemInt(hWnd, IDC_OPT_PORT, NULL, FALSE));
- return TRUE;
- }
- break;
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_APPLY:
+ db_set_dw(NULL, protoName, "UIN", (DWORD)GetDlgItemInt(hWnd, IDC_OPT_UIN, NULL, FALSE));
+ GetDlgItemText(hWnd, IDC_OPT_PASSWORD, str, sizeof(str));
+ db_set_s(NULL, protoName, "Password", str);
+ GetDlgItemText(hWnd, IDC_OPT_SERVER, str, sizeof(str));
+ db_set_s(NULL, protoName, "Server", str);
+ db_set_w(NULL, protoName, "Port", (WORD)GetDlgItemInt(hWnd, IDC_OPT_PORT, NULL, FALSE));
+ return TRUE;
+ }
+ break;
- case WM_COMMAND:
- if ((LOWORD(wParam) == IDC_OPT_UIN || LOWORD(wParam) == IDC_OPT_PASSWORD || LOWORD(wParam) == IDC_OPT_SERVER || LOWORD(wParam) == IDC_OPT_PORT) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0;
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
- break;
- }
- return FALSE;
+ case WM_COMMAND:
+ if ((LOWORD(wParam) == IDC_OPT_UIN || LOWORD(wParam) == IDC_OPT_PASSWORD || LOWORD(wParam) == IDC_OPT_SERVER || LOWORD(wParam) == IDC_OPT_PORT) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0;
+ SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
+ break;
+ }
+ return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
int icqOptionsInitialise(WPARAM wParam, LPARAM)
{
- OPTIONSDIALOGPAGE odp = { 0 };
+ OPTIONSDIALOGPAGE odp = { 0 };
- odp.position = -800000000;
- odp.szTitle.a = protoName;
- odp.pfnDlgProc = icqOptionsDlgProc;
- odp.pszTemplate = MAKEINTRESOURCE(IDD_OPT_ICQCORP);
- odp.hInstance = hInstance;
+ odp.position = -800000000;
+ odp.szTitle.a = protoName;
+ odp.pfnDlgProc = icqOptionsDlgProc;
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_OPT_ICQCORP);
+ odp.hInstance = hInstance;
odp.szGroup.a = LPGEN("Network");
- odp.flags = ODPF_BOLDGROUPS;
+ odp.flags = ODPF_BOLDGROUPS;
Options_AddPage(wParam, &odp);
- return 0;
+ return 0;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/ICQCorp/src/packet.cpp b/protocols/ICQCorp/src/packet.cpp
index 45f753ef41..bce974f68a 100644
--- a/protocols/ICQCorp/src/packet.cpp
+++ b/protocols/ICQCorp/src/packet.cpp
@@ -23,86 +23,74 @@
Packet::Packet()
{
- maxSize = MAX_PACKET_SIZE;
- buff = new char[maxSize];
- nextData = buff;
- sizeVal = 0;
+ maxSize = MAX_PACKET_SIZE;
+ buff = new char[maxSize];
+ nextData = buff;
+ sizeVal = 0;
}
///////////////////////////////////////////////////////////////////////////////
Packet::Packet(Packet *packet)
{
- maxSize = packet->maxSize;
- buff = new char[maxSize];
- nextData = buff + (packet->nextData - packet->buff);
- sizeVal = packet->sizeVal;
- memcpy(buff, packet->buff, sizeVal);
+ maxSize = packet->maxSize;
+ buff = new char[maxSize];
+ nextData = buff + (packet->nextData - packet->buff);
+ sizeVal = packet->sizeVal;
+ memcpy(buff, packet->buff, sizeVal);
}
///////////////////////////////////////////////////////////////////////////////
-/*
-Packet::Packet(char *newBuff, unsigned long buffSize)
-{
- maxSize = MAX_PACKET_SIZE;
- if (buffSize > maxSize) buffSize = maxSize;
- buff = new char[maxSize];
- memcpy(buff, newBuff, buffSize);
- nextData = buff;
- sizeVal = buffSize;
-}
-///////////////////////////////////////////////////////////////////////////////
-*/
Packet::~Packet()
{
- delete [] buff;
+ delete[] buff;
}
///////////////////////////////////////////////////////////////////////////////
void Packet::clearPacket()
{
- nextData = buff;
- sizeVal = 0;
+ nextData = buff;
+ sizeVal = 0;
}
///////////////////////////////////////////////////////////////////////////////
void Packet::add(unsigned int s)
{
- nextData += s;
- sizeVal += s;
+ nextData += s;
+ sizeVal += s;
}
///////////////////////////////////////////////////////////////////////////////
Packet &Packet::operator << (unsigned int data)
{
- *(unsigned int*)nextData = data;
- sizeVal += sizeof(unsigned int);
- nextData += sizeof(unsigned int);
- return *this;
+ *(unsigned int*)nextData = data;
+ sizeVal += sizeof(unsigned int);
+ nextData += sizeof(unsigned int);
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
Packet &Packet::operator << (unsigned short data)
{
- *(unsigned short*)nextData = data;
- sizeVal += sizeof(unsigned short);
- nextData += sizeof(unsigned short);
- return *this;
+ *(unsigned short*)nextData = data;
+ sizeVal += sizeof(unsigned short);
+ nextData += sizeof(unsigned short);
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
Packet &Packet::operator << (unsigned char data)
{
- *(unsigned char*)nextData = data;
- sizeVal += sizeof(unsigned char);
- nextData += sizeof(unsigned char);
- return *this;
+ *(unsigned char*)nextData = data;
+ sizeVal += sizeof(unsigned char);
+ nextData += sizeof(unsigned char);
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
@@ -110,108 +98,103 @@ Packet &Packet::operator << (unsigned char data)
Packet &Packet::operator << (char *data)
{
unsigned int s = (unsigned int)mir_strlen(data) + 1;
- operator << ((unsigned short)s);
- memcpy(nextData, data, s);
- sizeVal += s;
- nextData += s;
- return *this;
+ operator << ((unsigned short)s);
+ memcpy(nextData, data, s);
+ sizeVal += s;
+ nextData += s;
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
Packet &Packet::operator << (Packet *packet)
{
- unsigned int s = packet->dataSize();
- memcpy(nextData, packet->nextData, s);
- sizeVal += s;
- nextData += s;
- return *this;
+ unsigned int s = packet->dataSize();
+ memcpy(nextData, packet->nextData, s);
+ sizeVal += s;
+ nextData += s;
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
Packet &Packet::operator >> (unsigned int &in)
{
- if (nextData+sizeof(unsigned int) > buff+sizeVal) in = 0;
- else
- {
- in = *(unsigned int*)nextData;
- nextData += sizeof(unsigned int);
- }
- return *this;
+ if (nextData + sizeof(unsigned int) > buff + sizeVal) in = 0;
+ else {
+ in = *(unsigned int*)nextData;
+ nextData += sizeof(unsigned int);
+ }
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
-Packet &Packet::operator >> (unsigned short &in)
+Packet& Packet::operator >> (unsigned short &in)
{
- if (nextData+sizeof(unsigned short) > buff+sizeVal) in = 0;
- else
- {
- in = *(unsigned short*)nextData;
- nextData += sizeof(unsigned short);
- }
- return *this;
+ if (nextData + sizeof(unsigned short) > buff + sizeVal) in = 0;
+ else {
+ in = *(unsigned short*)nextData;
+ nextData += sizeof(unsigned short);
+ }
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
-Packet &Packet::operator >> (unsigned char &in)
+Packet& Packet::operator >> (unsigned char &in)
{
- if (nextData+sizeof(unsigned char) > buff+sizeVal) in = 0;
- else
- {
- in = *(unsigned char*)nextData;
- nextData += sizeof(unsigned char);
- }
- return *this;
+ if (nextData + sizeof(unsigned char) > buff + sizeVal) in = 0;
+ else {
+ in = *(unsigned char*)nextData;
+ nextData += sizeof(unsigned char);
+ }
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
-Packet &Packet::operator >> (char *&in)
+Packet& Packet::operator >> (char *&in)
{
- unsigned short s;
-
- operator >> (s);
- if (nextData+s > buff+sizeVal) in = 0;
- else
- {
- if (in == NULL) in = new char[s];
- memcpy(in, nextData, s);
- nextData += s;
- }
- return *this;
+ unsigned short s;
+
+ operator >> (s);
+ if (nextData + s > buff + sizeVal) in = 0;
+ else {
+ if (in == NULL) in = new char[s];
+ memcpy(in, nextData, s);
+ nextData += s;
+ }
+ return *this;
}
///////////////////////////////////////////////////////////////////////////////
-char *Packet::print()
+char* Packet::print()
{
- unsigned int i;
- static char p[8196];
- char *pPos = p;
-
- for (i=0; i<sizeVal; i++)
- {
- if (i % 16 == 0)
- {
- sprintf(pPos, " 0x%04X: %65c\n\0", i, ' ');
- pPos += 11;
- }
-
- sprintf(pPos, "%02X ", (unsigned char)buff[i]);
- if ((unsigned char)buff[i] > ' ') pPos[48 - (i % 16)*2 + 1] = buff[i];
-
- pPos += 3;
- if ((i+1) % 16 == 0)
- {
- pPos[0] = ' ';
- pPos += 18;
- }
- }
- if (sizeVal % 16 != 0) pPos[0] = ' ';
- return p;
+ unsigned int i;
+ static char p[8196];
+ char *pPos = p;
+
+ for (i = 0; i<sizeVal; i++) {
+ if (i % 16 == 0) {
+ sprintf(pPos, " 0x%04X: %65c\n\0", i, ' ');
+ pPos += 11;
+ }
+
+ sprintf(pPos, "%02X ", (unsigned char)buff[i]);
+ if ((unsigned char)buff[i] > ' ')
+ pPos[48 - (i % 16) * 2 + 1] = buff[i];
+
+ pPos += 3;
+ if ((i + 1) % 16 == 0) {
+ pPos[0] = ' ';
+ pPos += 18;
+ }
+ }
+ if (sizeVal % 16 != 0)
+ pPos[0] = ' ';
+ return p;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/ICQCorp/src/protocol.cpp b/protocols/ICQCorp/src/protocol.cpp
index 5b112d6e83..4193dc2091 100644
--- a/protocols/ICQCorp/src/protocol.cpp
+++ b/protocols/ICQCorp/src/protocol.cpp
@@ -1,21 +1,21 @@
/*
- ICQ Corporate protocol plugin for Miranda IM.
- Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ ICQ Corporate protocol plugin for Miranda IM.
+ Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include "corp.h"
@@ -25,127 +25,110 @@ ICQ icq;
unsigned short toIcqStatus(unsigned short status)
{
-/*
- unsigned short icqStatus[] = { ICQ_STATUS_OFFLINE, ICQ_STATUS_ONLINE, ICQ_STATUS_AWAY, ICQ_STATUS_DND,
- ICQ_STATUS_NA, ICQ_STATUS_OCCUPIED, ICQ_STATUS_FREEFORCHAT, ICQ_STATUS_PRIVATE };
-
- return icqStatus[status - ID_STATUS_OFFLINE];
-*/
- switch (status)
- {
- case ID_STATUS_OFFLINE: return ICQ_STATUS_OFFLINE;
- case ID_STATUS_ONLINE: return ICQ_STATUS_ONLINE;
- case ID_STATUS_AWAY: return ICQ_STATUS_AWAY;
- case ID_STATUS_DND: return ICQ_STATUS_DND;
- case ID_STATUS_NA: return ICQ_STATUS_NA;
- case ID_STATUS_OCCUPIED: return ICQ_STATUS_OCCUPIED;
- case ID_STATUS_FREECHAT: return ICQ_STATUS_FREECHAT;
- case ID_STATUS_INVISIBLE: return ICQ_STATUS_PRIVATE;
- }
- return ICQ_STATUS_ONLINE;
+ switch (status) {
+ case ID_STATUS_OFFLINE: return ICQ_STATUS_OFFLINE;
+ case ID_STATUS_ONLINE: return ICQ_STATUS_ONLINE;
+ case ID_STATUS_AWAY: return ICQ_STATUS_AWAY;
+ case ID_STATUS_DND: return ICQ_STATUS_DND;
+ case ID_STATUS_NA: return ICQ_STATUS_NA;
+ case ID_STATUS_OCCUPIED: return ICQ_STATUS_OCCUPIED;
+ case ID_STATUS_FREECHAT: return ICQ_STATUS_FREECHAT;
+ case ID_STATUS_INVISIBLE: return ICQ_STATUS_PRIVATE;
+ }
+ return ICQ_STATUS_ONLINE;
}
///////////////////////////////////////////////////////////////////////////////
unsigned short toIdStatus(unsigned short status)
{
- switch (status)
- {
- case ICQ_STATUS_OFFLINE: return ID_STATUS_OFFLINE;
- case ICQ_STATUS_ONLINE: return ID_STATUS_ONLINE;
- case ICQ_STATUS_AWAY: return ID_STATUS_AWAY;
- case ICQ_STATUS_DND: return ID_STATUS_DND;
- case ICQ_STATUS_NA: return ID_STATUS_NA;
- case ICQ_STATUS_OCCUPIED: return ID_STATUS_OCCUPIED;
- case ICQ_STATUS_FREECHAT: return ID_STATUS_FREECHAT;
- case ICQ_STATUS_PRIVATE: return ID_STATUS_INVISIBLE;
- }
- return ID_STATUS_ONLINE;
+ switch (status) {
+ case ICQ_STATUS_OFFLINE: return ID_STATUS_OFFLINE;
+ case ICQ_STATUS_ONLINE: return ID_STATUS_ONLINE;
+ case ICQ_STATUS_AWAY: return ID_STATUS_AWAY;
+ case ICQ_STATUS_DND: return ID_STATUS_DND;
+ case ICQ_STATUS_NA: return ID_STATUS_NA;
+ case ICQ_STATUS_OCCUPIED: return ID_STATUS_OCCUPIED;
+ case ICQ_STATUS_FREECHAT: return ID_STATUS_FREECHAT;
+ case ICQ_STATUS_PRIVATE: return ID_STATUS_INVISIBLE;
+ }
+ return ID_STATUS_ONLINE;
}
///////////////////////////////////////////////////////////////////////////////
LRESULT WINAPI messageWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- SOCKET hSocket = (SOCKET)wParam;
- unsigned short netEvents = LOWORD(lParam);
- unsigned long result;
-
- switch (msg)
- {
- case WM_NETEVENT_SERVER:
- if (hSocket == icq.udpSocket.handleVal)
- {
- if (netEvents & FD_READ) icq.recvUDP(0);
- break;
- }
- break;
-
- case WM_NETEVENT_CONNECTION:
- if (hSocket == icq.tcpSocket.handleVal)
- {
- if (netEvents & FD_ACCEPT) icq.recvNewTCP(0);
- break;
- }
- break;
-
- case WM_NETEVENT_USER:
- if (netEvents & FD_READ)
- {
- ioctlsocket(hSocket, FIONREAD, &result);
- if (result > 0) icq.recvTCP(hSocket);
- }
- if (netEvents & FD_CLOSE)
- {
- unsigned int i;
- for (i=0; i<icqUsers.size(); i++)
- {
- if (hSocket == icqUsers[i]->socket.handleVal)
- {
- T("[tcp] user %d is aborted connection\n", icqUsers[i]->uin);
- icqUsers[i]->socket.closeConnection();
- break;
- }
- }
- }
- break;
-
- case WM_NETEVENT_TRANSFER:
- if (netEvents & FD_READ)
- {
- ioctlsocket(hSocket, FIONREAD, &result);
- if (result > 0) icq.recvTransferTCP(hSocket);
- }
- if (netEvents & FD_CLOSE)
- {
- unsigned int i;
- for (i=0; i<icqTransfers.size(); i++)
- {
- if (hSocket == icqTransfers[i]->socket.handleVal)
- {
- T("[tcp] user %d is aborted file connection\n", icqTransfers[i]->uin);
- ProtoBroadcastAck(protoName, icqTransfers[i]->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, icqTransfers[i], 0);
- delete icqTransfers[i];
- icqTransfers[i] = icqTransfers[icqTransfers.size() - 1];
- icqTransfers.pop_back();
- break;
- }
- }
- }
- break;
-
- default:
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
-
- return 0;
+ SOCKET hSocket = (SOCKET)wParam;
+ unsigned short netEvents = LOWORD(lParam);
+ unsigned long result;
+
+ switch (msg) {
+ case WM_NETEVENT_SERVER:
+ if (hSocket == icq.udpSocket.handleVal) {
+ if (netEvents & FD_READ)
+ icq.recvUDP(0);
+ break;
+ }
+ break;
+
+ case WM_NETEVENT_CONNECTION:
+ if (hSocket == icq.tcpSocket.handleVal) {
+ if (netEvents & FD_ACCEPT)
+ icq.recvNewTCP(0);
+ break;
+ }
+ break;
+
+ case WM_NETEVENT_USER:
+ if (netEvents & FD_READ) {
+ ioctlsocket(hSocket, FIONREAD, &result);
+ if (result > 0) icq.recvTCP(hSocket);
+ }
+ if (netEvents & FD_CLOSE) {
+ unsigned int i;
+ for (i = 0; i < icqUsers.size(); i++) {
+ if (hSocket == icqUsers[i]->socket.handleVal) {
+ T("[tcp] user %d is aborted connection\n", icqUsers[i]->uin);
+ icqUsers[i]->socket.closeConnection();
+ break;
+ }
+ }
+ }
+ break;
+
+ case WM_NETEVENT_TRANSFER:
+ if (netEvents & FD_READ) {
+ ioctlsocket(hSocket, FIONREAD, &result);
+ if (result > 0)
+ icq.recvTransferTCP(hSocket);
+ }
+ if (netEvents & FD_CLOSE) {
+ for (size_t i = 0; i < icqTransfers.size(); i++) {
+ if (hSocket == icqTransfers[i]->socket.handleVal) {
+ T("[tcp] user %d is aborted file connection\n", icqTransfers[i]->uin);
+ ProtoBroadcastAck(protoName, icqTransfers[i]->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, icqTransfers[i], 0);
+ delete icqTransfers[i];
+ icqTransfers[i] = icqTransfers[icqTransfers.size() - 1];
+ icqTransfers.pop_back();
+ break;
+ }
+ }
+ }
+ break;
+
+ default:
+ return DefWindowProc(hWnd, msg, wParam, lParam);
+ }
+
+ return 0;
}
///////////////////////////////////////////////////////////////////////////////
void WINAPI pingTimerProc(HWND, UINT, UINT_PTR, DWORD)
{
- icq.ping();
+ icq.ping();
}
///////////////////////////////////////////////////////////////////////////////
@@ -154,9 +137,9 @@ void WINAPI pingTimerProc(HWND, UINT, UINT_PTR, DWORD)
//
///////////////////////////////////////////////////////////////////////////////
-ICQ::ICQ() :
- tcpSocket(WM_NETEVENT_CONNECTION),
- udpSocket(WM_NETEVENT_SERVER)
+ICQ::ICQ()
+ : tcpSocket(WM_NETEVENT_CONNECTION),
+ udpSocket(WM_NETEVENT_SERVER)
{
}
@@ -164,1134 +147,1111 @@ ICQ::ICQ() :
bool ICQ::load()
{
- WSADATA data;
+ WSADATA data;
- if (WSAStartup(MAKEWORD(2,2), &data))
- {
- MessageBox(NULL, Translate("ICQ Corporate plugin used only WinSock v2.2 or later."), protoName, MB_ICONWARNING|MB_OK);
- return false;
- }
+ if (WSAStartup(MAKEWORD(2, 2), &data)) {
+ MessageBox(NULL, Translate("ICQ Corporate plugin used only WinSock v2.2 or later."), protoName, MB_ICONWARNING | MB_OK);
+ return false;
+ }
- statusVal = ID_STATUS_OFFLINE;
- searchSequenceVal = 0;
- tcpSequenceVal = 0xFFFFFFFE;
+ statusVal = ID_STATUS_OFFLINE;
+ searchSequenceVal = 0;
+ tcpSequenceVal = 0xFFFFFFFE;
- awayMessage = new char[1];
- awayMessage[0] = 0;
+ awayMessage = new char[1];
+ awayMessage[0] = 0;
- WNDCLASS wc = { 0, messageWndProc, 0, 0, hInstance, NULL, NULL, NULL, NULL, protoName };
- if (!RegisterClass(&wc)) return false;
+ WNDCLASS wc = { 0, messageWndProc, 0, 0, hInstance, NULL, NULL, NULL, NULL, protoName };
+ if (!RegisterClass(&wc)) return false;
- hWnd = CreateWindowEx(0, protoName, NULL, 0, 0, 0, 0, 0, (unsigned short)GetVersion() >= 5 ? HWND_MESSAGE : 0, NULL, hInstance, NULL);
- if (hWnd == NULL) return false;
+ hWnd = CreateWindowEx(0, protoName, NULL, 0, 0, 0, 0, 0, (unsigned short)GetVersion() >= 5 ? HWND_MESSAGE : 0, NULL, hInstance, NULL);
+ if (hWnd == NULL) return false;
- return true;
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::unload()
{
- if (statusVal != ID_STATUS_OFFLINE) logoff(false);
+ if (statusVal != ID_STATUS_OFFLINE) logoff(false);
- KillTimer(NULL, pingTimer);
- pingTimer = NULL;
+ KillTimer(NULL, pingTimer);
+ pingTimer = NULL;
- delete [] awayMessage;
+ delete[] awayMessage;
- WSACleanup();
+ WSACleanup();
- DestroyWindow(hWnd);
- UnregisterClass(protoName, hInstance);
+ DestroyWindow(hWnd);
+ UnregisterClass(protoName, hInstance);
}
///////////////////////////////////////////////////////////////////////////////
bool ICQ::logon(unsigned short logonStatus)
{
- DBVARIANT dbv;
- char str[128];
-
- if(!db_get(NULL, protoName, "Server", &dbv))
- {
- lstrcpy(str, dbv.pszVal);
- db_free(&dbv);
- }
- else
- {
- MessageBox(NULL, Translate("You need specify ICQ Corporate login server."), protoName, MB_ICONWARNING|MB_OK);
- return false;
- }
-
- if (!tcpSocket.connected() && !tcpSocket.startServer()) return false;
- if (!udpSocket.connected())
- {
- if (!udpSocket.setDestination(str, db_get_w(NULL, protoName, "Port", 4000))) return false;
- udpSocket.openConnection();
- }
-
- if (pingTimer == NULL) pingTimer = SetTimer(NULL, 0, PING_FREQUENCY, pingTimerProc);
-
- updateContactList();
-
- uin = db_get_dw(NULL, protoName, "UIN", 0);
- if (!db_get(NULL, protoName, "Password", &dbv))
- {
- lstrcpy(str, dbv.pszVal);
- db_free(&dbv);
- }
-
-
- timeStampLastMessage = 0;
- sequenceVal = 1;
-
- Packet loginPacket;
- loginPacket << ICQ_VERSION
- << ICQ_CMDxSND_LOGON
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << tcpSocket.localPortVal
- << str
- << (unsigned short)0x7A
- << (unsigned short)0x02
-// << LOCALHOST
- << udpSocket.localIPVal
- << (unsigned char)0x04
- << (unsigned int)toIcqStatus(logonStatus)
- << (unsigned int)0x02
- << (unsigned int)0x00
- << (unsigned short)0x13
- << (unsigned short)0x7A;
-
- T("[udp] requesting logon (%d)...\n", sequenceVal);
- sendICQ(udpSocket, loginPacket, ICQ_CMDxSND_LOGON, sequenceVal);
-
- desiredStatus = logonStatus;
- statusVal = ID_STATUS_CONNECTING;
- ProtoBroadcastAck(protoName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, statusVal);
-
- return true;
+ DBVARIANT dbv;
+ char str[128];
+
+ if (!db_get(NULL, protoName, "Server", &dbv)) {
+ lstrcpy(str, dbv.pszVal);
+ db_free(&dbv);
+ }
+ else {
+ MessageBox(NULL, Translate("You need specify ICQ Corporate login server."), protoName, MB_ICONWARNING | MB_OK);
+ return false;
+ }
+
+ if (!tcpSocket.connected() && !tcpSocket.startServer())
+ return false;
+
+ if (!udpSocket.connected()) {
+ if (!udpSocket.setDestination(str, db_get_w(NULL, protoName, "Port", 4000)))
+ return false;
+ udpSocket.openConnection();
+ }
+
+ if (pingTimer == NULL)
+ pingTimer = SetTimer(NULL, 0, PING_FREQUENCY, pingTimerProc);
+
+ updateContactList();
+
+ uin = db_get_dw(NULL, protoName, "UIN", 0);
+ if (!db_get(NULL, protoName, "Password", &dbv)) {
+ lstrcpy(str, dbv.pszVal);
+ db_free(&dbv);
+ }
+
+
+ timeStampLastMessage = 0;
+ sequenceVal = 1;
+
+ Packet loginPacket;
+ loginPacket << ICQ_VERSION
+ << ICQ_CMDxSND_LOGON
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << tcpSocket.localPortVal
+ << str
+ << (unsigned short)0x7A
+ << (unsigned short)0x02
+ // << LOCALHOST
+ << udpSocket.localIPVal
+ << (unsigned char)0x04
+ << (unsigned int)toIcqStatus(logonStatus)
+ << (unsigned int)0x02
+ << (unsigned int)0x00
+ << (unsigned short)0x13
+ << (unsigned short)0x7A;
+
+ T("[udp] requesting logon (%d)...\n", sequenceVal);
+ sendICQ(udpSocket, loginPacket, ICQ_CMDxSND_LOGON, sequenceVal);
+
+ desiredStatus = logonStatus;
+ statusVal = ID_STATUS_CONNECTING;
+ ProtoBroadcastAck(protoName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, statusVal);
+
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::logoff(bool reconnect)
{
- unsigned int i;
-
- // if not connected then don't both logging off
- if (udpSocket.connected())
- {
- Packet logoffPacket;
- logoffPacket << ICQ_VERSION
- << ICQ_CMDxSND_LOGOFF
- << (unsigned int)0x00
- << uin
- << (unsigned int)0x00
- << "B_USER_DISCONNECTED"
- << (unsigned short)0x0005;
-
- T("[udp] logging off.\n");
- udpSocket.sendPacket(logoffPacket);
-// udpSocket.closeConnection();
-
- // close all open events
- for (i=0; i<icqEvents.size(); i++) delete icqEvents[i];
- icqEvents.clear();
- }
-
- statusVal = ID_STATUS_OFFLINE;
-
- if (reconnect) logon(desiredStatus);
- else
- {
- udpSocket.closeConnection();
- tcpSocket.closeConnection();
-
- updateContactList();
- ProtoBroadcastAck(protoName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_ONLINE, statusVal);
- }
+ unsigned int i;
+
+ // if not connected then don't both logging off
+ if (udpSocket.connected()) {
+ Packet logoffPacket;
+ logoffPacket << ICQ_VERSION
+ << ICQ_CMDxSND_LOGOFF
+ << (unsigned int)0x00
+ << uin
+ << (unsigned int)0x00
+ << "B_USER_DISCONNECTED"
+ << (unsigned short)0x0005;
+
+ T("[udp] logging off.\n");
+ udpSocket.sendPacket(logoffPacket);
+ // udpSocket.closeConnection();
+
+ // close all open events
+ for (i = 0; i < icqEvents.size(); i++) delete icqEvents[i];
+ icqEvents.clear();
+ }
+
+ statusVal = ID_STATUS_OFFLINE;
+
+ if (reconnect) logon(desiredStatus);
+ else {
+ udpSocket.closeConnection();
+ tcpSocket.closeConnection();
+
+ updateContactList();
+ ProtoBroadcastAck(protoName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_ONLINE, statusVal);
+ }
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::ping()
{
- if (statusVal > ID_STATUS_OFFLINE)
- {
- Packet pingPacket;
- pingPacket << ICQ_VERSION
- << ICQ_CMDxSND_PING
- << sequenceVal
- << (unsigned short)0x00
- << uin
- << (unsigned int)0x00;
-
- T("[udp] keep alive (%d)\n", sequenceVal);
- sendICQ(udpSocket, pingPacket, ICQ_CMDxSND_PING, sequenceVal);
- }
-
- if (statusVal == ID_STATUS_OFFLINE && desiredStatus != ID_STATUS_OFFLINE) logoff(true);
+ if (statusVal > ID_STATUS_OFFLINE) {
+ Packet pingPacket;
+ pingPacket << ICQ_VERSION
+ << ICQ_CMDxSND_PING
+ << sequenceVal
+ << (unsigned short)0x00
+ << uin
+ << (unsigned int)0x00;
+
+ T("[udp] keep alive (%d)\n", sequenceVal);
+ sendICQ(udpSocket, pingPacket, ICQ_CMDxSND_PING, sequenceVal);
+ }
+
+ if (statusVal == ID_STATUS_OFFLINE && desiredStatus != ID_STATUS_OFFLINE) logoff(true);
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent *ICQ::sendICQ(Socket &socket, Packet &packet, unsigned short cmd, unsigned long sequence,
- unsigned long uin, unsigned short subCmd, int reply)
+ unsigned long uin, unsigned short subCmd, int reply)
{
- ICQEvent *result;
+ ICQEvent *result;
- if (!socket.connected()) return NULL;
+ if (!socket.connected())
+ return NULL;
- if (cmd != ICQ_CMDxTCP_START) sequenceVal++;
+ if (cmd != ICQ_CMDxTCP_START)
+ sequenceVal++;
- icqEvents.push_back(result = new ICQEvent(cmd, subCmd, sequence, uin, &socket, &packet, reply));
- if (!result->start())
- {
- cancelEvent(result);
- return NULL;
- }
- return result;
+ icqEvents.push_back(result = new ICQEvent(cmd, subCmd, sequence, uin, &socket, &packet, reply));
+ if (!result->start()) {
+ cancelEvent(result);
+ return NULL;
+ }
+ return result;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::doneEvent(bool gotAck, int hSocket, int sequence)
{
- unsigned int i;
- ICQEvent *e;
-
- for (i=0; i<icqEvents.size(); i++)
- {
- e = icqEvents[i];
- if (e->isEvent(hSocket, sequence)) break;
- }
- if (i == icqEvents.size()) return;
-
- e->stop();
- if (!gotAck || e->reply == 0)
- {
- icqEvents[i] = icqEvents[icqEvents.size() - 1];
- icqEvents.pop_back();
- }
-
- if (!gotAck) T("[ ] sending failed (%d)\n", sequence);
-
- switch (e->cmd)
- {
- case ICQ_CMDxTCP_START:
- doneUserFcn(gotAck, e);
- break;
- case ICQ_CMDxSND_THRUxSERVER:
- doneUserFcn(gotAck, e);
- break;
- case ICQ_CMDxSND_USERxGETxINFO:
- //emit doneUserInfo(true, e->uin);
- break;
- case ICQ_CMDxSND_SETxSTATUS:
- if (gotAck)
- {
- int oldStatus = statusVal;
- statusVal = desiredStatus;
- ProtoBroadcastAck(protoName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, statusVal);
- }
- break;
- case ICQ_CMDxSND_PING:
- //if (!gotAck) emit doneOwnerFcn(false, cmd);
- break;
- case ICQ_CMDxSND_USERxADD:
- //if (!gotAck) emit doneOwnerFcn(false, cmd);
- break;
- case ICQ_CMDxSND_AUTHORIZE:
- //emit doneOwnerFcn(gotAck, cmd);
- break;
- case ICQ_CMDxSND_LOGON:
- if (!gotAck)
- {
- logoff(false);
- //emit doneOwnerFcn(false, cmd);
- }
- break;
- case ICQ_CMDxSND_USERxLIST:
- //if (!gotAck) emit doneOwnerFcn(false, cmd);
- break;
- case ICQ_CMDxSND_VISxLIST:
- //if (!gotAck) emit doneOwnerFcn(false, cmd);
- break;
- case ICQ_CMDxSND_SYSxMSGxREQ:
- //if (!gotAck) emit doneOwnerFcn(false, cmd);
- break;
- case ICQ_CMDxSND_SYSxMSGxDONExACK:
- //if (!gotAck) emit doneOwnerFcn(false, cmd);
- break;
- }
-
- if (!gotAck && e->cmd != ICQ_CMDxTCP_START && e->cmd != ICQ_CMDxSND_LOGON) logoff(true);
-
-
- if (!gotAck || e->reply == 0) delete e;
-
- else e->reply--;
+ unsigned int i;
+ ICQEvent *e;
+ for (i = 0; i < icqEvents.size(); i++) {
+ e = icqEvents[i];
+ if (e->isEvent(hSocket, sequence))
+ break;
+ }
+ if (i == icqEvents.size())
+ return;
+
+ e->stop();
+ if (!gotAck || e->reply == 0) {
+ icqEvents[i] = icqEvents[icqEvents.size() - 1];
+ icqEvents.pop_back();
+ }
+
+ if (!gotAck) T("[ ] sending failed (%d)\n", sequence);
+
+ switch (e->cmd) {
+ case ICQ_CMDxTCP_START:
+ doneUserFcn(gotAck, e);
+ break;
+ case ICQ_CMDxSND_THRUxSERVER:
+ doneUserFcn(gotAck, e);
+ break;
+ case ICQ_CMDxSND_USERxGETxINFO:
+ //emit doneUserInfo(true, e->uin);
+ break;
+ case ICQ_CMDxSND_SETxSTATUS:
+ if (gotAck) {
+ int oldStatus = statusVal;
+ statusVal = desiredStatus;
+ ProtoBroadcastAck(protoName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, statusVal);
+ }
+ break;
+ case ICQ_CMDxSND_PING:
+ //if (!gotAck) emit doneOwnerFcn(false, cmd);
+ break;
+ case ICQ_CMDxSND_USERxADD:
+ //if (!gotAck) emit doneOwnerFcn(false, cmd);
+ break;
+ case ICQ_CMDxSND_AUTHORIZE:
+ //emit doneOwnerFcn(gotAck, cmd);
+ break;
+ case ICQ_CMDxSND_LOGON:
+ if (!gotAck)
+ {
+ logoff(false);
+ //emit doneOwnerFcn(false, cmd);
+ }
+ break;
+ case ICQ_CMDxSND_USERxLIST:
+ //if (!gotAck) emit doneOwnerFcn(false, cmd);
+ break;
+ case ICQ_CMDxSND_VISxLIST:
+ //if (!gotAck) emit doneOwnerFcn(false, cmd);
+ break;
+ case ICQ_CMDxSND_SYSxMSGxREQ:
+ //if (!gotAck) emit doneOwnerFcn(false, cmd);
+ break;
+ case ICQ_CMDxSND_SYSxMSGxDONExACK:
+ //if (!gotAck) emit doneOwnerFcn(false, cmd);
+ break;
+ }
+
+ if (!gotAck && e->cmd != ICQ_CMDxTCP_START && e->cmd != ICQ_CMDxSND_LOGON)
+ logoff(true);
+
+ if (!gotAck || e->reply == 0)
+ delete e;
+ else
+ e->reply--;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::cancelEvent(ICQEvent *&e)
{
- unsigned int i;
+ unsigned int i;
- for (i=0; i<icqEvents.size(); i++) if (icqEvents[i] == e) break;
- if (i == icqEvents.size()) return;
+ for (i = 0; i < icqEvents.size(); i++) if (icqEvents[i] == e)
+ break;
+ if (i == icqEvents.size())
+ return;
- e->stop();
+ e->stop();
- icqEvents[i] = icqEvents[icqEvents.size() - 1];
- icqEvents.pop_back();
+ icqEvents[i] = icqEvents[icqEvents.size() - 1];
+ icqEvents.pop_back();
- delete e;
- e = NULL;
+ delete e;
+ e = NULL;
}
///////////////////////////////////////////////////////////////////////////////
unsigned short ICQ::processUdpPacket(Packet &packet)
{
- unsigned short version, command, newCommand, theSequence, theSequence1, searchSequence, junkShort;
- unsigned int checkUin, userIP, realIP, junkl, newStatus, userPort, timedataStamp;
- unsigned char junkChar;
- char *message = NULL;
- ICQUser *u;
- ICQEvent *e;
-
- // read in the standard UDP header info
- packet >> version
- >> command
- >> theSequence
- >> theSequence1
- >> checkUin
- >> junkl;
-
- if (version != ICQ_VERSION)
- {
- T("[udp] bad version number %d\n", version);
- return 0xFFFF;
- }
-/* on offline multi packet field checkUin not equal uin :(
-
- if (checkUin != uin)
- {
- T("[udp] bad uin number %d\n", checkUin);
- return 0xFFFF;
- }
-*/
- switch (command)
- {
- case ICQ_CMDxRCV_LOGIN_ERR:
- T("[udp] error loging to server.\n");
- ackUDP(theSequence);
-
- packet >> message;
-
- T("%s\n", message);
- MessageBox(NULL, message, protoName, MB_ICONERROR|MB_OK);
- delete [] message;
- break;
-
- case ICQ_CMDxRCV_USERxONLINE: // initial user status packet
- packet >> checkUin;
-
- T("[udp] user %d is online\n", checkUin);
- ackUDP(theSequence);
-
- if ((u = getUserByUIN(checkUin, false)) == NULL) break;
-
- packet >> userIP
- >> userPort
- >> realIP
- >> junkChar
- >> newStatus;
-
- u->socket.closeConnection();
- u->socket.setDestination(userIP, userPort);
- u->setStatus(toIdStatus(newStatus));
- u->setInfo("IP", (unsigned int)ntohl(userIP));
- u->setInfo("Port", (unsigned short)userPort);
- u->setInfo("RealIP", (unsigned int)ntohl(realIP));
- break;
-
- case ICQ_CMDxRCV_USERxOFFLINE: // user just went offline packet
- packet >> checkUin;
-
- T("[udp] user %d is offline\n", checkUin);
- ackUDP(theSequence);
-
- if ((u = getUserByUIN(checkUin, false)) == NULL) break;
-
- u->setStatus(ID_STATUS_OFFLINE);
- u->socket.closeConnection();
- break;
-
- case ICQ_CMDxRCV_USERxBASICxINFO:
- case ICQ_CMDxRCV_USERxINFO:
- case ICQ_CMDxRCV_USERxWORKxINFO:
- case ICQ_CMDxRCV_USERxWORKxPAGE:
- case ICQ_CMDxRCV_USERxHOMExINFO:
- case ICQ_CMDxRCV_USERxHOMExPAGE:
- T("[udp] user information packet (%d)\n", theSequence);
- ackUDP(theSequence);
-
- if ((e = getEvent(udpSocket.handleVal, theSequence1)) == NULL) break;
- checkUin = e->uin;
- if ((u = getUserByUIN(checkUin, false)) == NULL) break;
-
- char *buffer;
- buffer = new char[1024];
-
- switch (command)
- {
- case ICQ_CMDxRCV_USERxBASICxINFO:
- case ICQ_CMDxRCV_USERxINFO:
- packet >> buffer;
- u->setInfo("Nick", buffer);
- packet >> buffer;
- u->setInfo("FirstName", buffer);
- packet >> buffer;
- u->setInfo("LastName", buffer);
- packet >> buffer;
- u->setInfo("e-mail", buffer);
- break;
-
- case ICQ_CMDxRCV_USERxWORKxINFO:
- packet >> buffer;
- u->setInfo("CompanyStreet", buffer);
- packet >> buffer;
- u->setInfo("CompanyCity", buffer);
- packet >> buffer;
- u->setInfo("CompanyState", buffer);
- packet >> junkShort;
- u->setInfo("CompanyCountry", junkShort);
- packet >> buffer;
- u->setInfo("Company", buffer);
- packet >> buffer;
- u->setInfo("CompanyPosition", buffer);
- packet >> junkl;
- packet >> buffer;
- u->setInfo("CompanyPhone", buffer);
- packet >> buffer;
- u->setInfo("CompanyFax", buffer);
- packet >> buffer;
- packet >> junkl;
- if (junkl && junkl != 0xFFFFFFFF) _itoa(junkl, buffer, 10);
- else buffer[0] = 0;
- u->setInfo("CompanyZIP", buffer);
- break;
-
- case ICQ_CMDxRCV_USERxWORKxPAGE:
- packet >> buffer;
- u->setInfo("CompanyHomepage", buffer);
- break;
-
- case ICQ_CMDxRCV_USERxHOMExINFO:
- packet >> buffer;
- u->setInfo("Street", buffer);
- packet >> buffer;
- u->setInfo("City", buffer);
- packet >> buffer;
- u->setInfo("State", buffer);
- packet >> junkShort;
- u->setInfo("Country", junkShort);
- packet >> buffer;
- u->setInfo("Phone", buffer);
- packet >> buffer;
- u->setInfo("Fax", buffer);
- packet >> buffer;
- u->setInfo("Cellular", buffer);
- packet >> junkl;
- if (junkl && junkl != 0xFFFFFFFF) _itoa(junkl, buffer, 10);
- else buffer[0] = 0;
- u->setInfo("ZIP", buffer);
- packet >> junkChar;
- if (junkChar == 1) junkChar = 'F';
- if (junkChar == 2) junkChar = 'M';
- u->setInfo("Gender", junkChar);
- packet >> junkShort;
- u->setInfo("Age", (unsigned char)junkShort);
- packet >> junkChar;
- u->setInfo("BirthDay", junkChar);
- packet >> junkChar;
- u->setInfo("BirthMonth", junkChar);
- packet >> junkShort;
- u->setInfo("BirthYear", junkShort);
- break;
-
- case ICQ_CMDxRCV_USERxHOMExPAGE:
- packet >> buffer;
- u->setInfo("Homepage", buffer);
- break;
- }
+ unsigned short version, command, newCommand, theSequence, theSequence1, searchSequence, junkShort;
+ unsigned int checkUin, userIP, realIP, junkl, newStatus, userPort, timedataStamp;
+ unsigned char junkChar;
+ char *message = NULL;
+ ICQUser *u;
+ ICQEvent *e;
+
+ // read in the standard UDP header info
+ packet >> version
+ >> command
+ >> theSequence
+ >> theSequence1
+ >> checkUin
+ >> junkl;
+
+ if (version != ICQ_VERSION) {
+ T("[udp] bad version number %d\n", version);
+ return 0xFFFF;
+ }
+
+ switch (command) {
+ case ICQ_CMDxRCV_LOGIN_ERR:
+ T("[udp] error loging to server.\n");
+ ackUDP(theSequence);
+
+ packet >> message;
+
+ T("%s\n", message);
+ MessageBox(NULL, message, protoName, MB_ICONERROR | MB_OK);
+ delete[] message;
+ break;
+
+ case ICQ_CMDxRCV_USERxONLINE: // initial user status packet
+ packet >> checkUin;
+
+ T("[udp] user %d is online\n", checkUin);
+ ackUDP(theSequence);
+
+ if ((u = getUserByUIN(checkUin, false)) == NULL) break;
+
+ packet >> userIP
+ >> userPort
+ >> realIP
+ >> junkChar
+ >> newStatus;
+
+ u->socket.closeConnection();
+ u->socket.setDestination(userIP, userPort);
+ u->setStatus(toIdStatus(newStatus));
+ u->setInfo("IP", (unsigned int)ntohl(userIP));
+ u->setInfo("Port", (unsigned short)userPort);
+ u->setInfo("RealIP", (unsigned int)ntohl(realIP));
+ break;
+
+ case ICQ_CMDxRCV_USERxOFFLINE: // user just went offline packet
+ packet >> checkUin;
+
+ T("[udp] user %d is offline\n", checkUin);
+ ackUDP(theSequence);
+
+ if ((u = getUserByUIN(checkUin, false)) == NULL) break;
+
+ u->setStatus(ID_STATUS_OFFLINE);
+ u->socket.closeConnection();
+ break;
+
+ case ICQ_CMDxRCV_USERxBASICxINFO:
+ case ICQ_CMDxRCV_USERxINFO:
+ case ICQ_CMDxRCV_USERxWORKxINFO:
+ case ICQ_CMDxRCV_USERxWORKxPAGE:
+ case ICQ_CMDxRCV_USERxHOMExINFO:
+ case ICQ_CMDxRCV_USERxHOMExPAGE:
+ T("[udp] user information packet (%d)\n", theSequence);
+ ackUDP(theSequence);
+
+ if ((e = getEvent(udpSocket.handleVal, theSequence1)) == NULL) break;
+ checkUin = e->uin;
+ if ((u = getUserByUIN(checkUin, false)) == NULL) break;
+
+ char *buffer;
+ buffer = new char[1024];
+
+ switch (command) {
+ case ICQ_CMDxRCV_USERxBASICxINFO:
+ case ICQ_CMDxRCV_USERxINFO:
+ packet >> buffer;
+ u->setInfo("Nick", buffer);
+ packet >> buffer;
+ u->setInfo("FirstName", buffer);
+ packet >> buffer;
+ u->setInfo("LastName", buffer);
+ packet >> buffer;
+ u->setInfo("e-mail", buffer);
+ break;
+
+ case ICQ_CMDxRCV_USERxWORKxINFO:
+ packet >> buffer;
+ u->setInfo("CompanyStreet", buffer);
+ packet >> buffer;
+ u->setInfo("CompanyCity", buffer);
+ packet >> buffer;
+ u->setInfo("CompanyState", buffer);
+ packet >> junkShort;
+ u->setInfo("CompanyCountry", junkShort);
+ packet >> buffer;
+ u->setInfo("Company", buffer);
+ packet >> buffer;
+ u->setInfo("CompanyPosition", buffer);
+ packet >> junkl;
+ packet >> buffer;
+ u->setInfo("CompanyPhone", buffer);
+ packet >> buffer;
+ u->setInfo("CompanyFax", buffer);
+ packet >> buffer;
+ packet >> junkl;
+ if (junkl && junkl != 0xFFFFFFFF) _itoa(junkl, buffer, 10);
+ else buffer[0] = 0;
+ u->setInfo("CompanyZIP", buffer);
+ break;
+
+ case ICQ_CMDxRCV_USERxWORKxPAGE:
+ packet >> buffer;
+ u->setInfo("CompanyHomepage", buffer);
+ break;
+
+ case ICQ_CMDxRCV_USERxHOMExINFO:
+ packet >> buffer;
+ u->setInfo("Street", buffer);
+ packet >> buffer;
+ u->setInfo("City", buffer);
+ packet >> buffer;
+ u->setInfo("State", buffer);
+ packet >> junkShort;
+ u->setInfo("Country", junkShort);
+ packet >> buffer;
+ u->setInfo("Phone", buffer);
+ packet >> buffer;
+ u->setInfo("Fax", buffer);
+ packet >> buffer;
+ u->setInfo("Cellular", buffer);
+ packet >> junkl;
+ if (junkl && junkl != 0xFFFFFFFF) _itoa(junkl, buffer, 10);
+ else buffer[0] = 0;
+ u->setInfo("ZIP", buffer);
+ packet >> junkChar;
+ if (junkChar == 1) junkChar = 'F';
+ if (junkChar == 2) junkChar = 'M';
+ u->setInfo("Gender", junkChar);
+ packet >> junkShort;
+ u->setInfo("Age", (unsigned char)junkShort);
+ packet >> junkChar;
+ u->setInfo("BirthDay", junkChar);
+ packet >> junkChar;
+ u->setInfo("BirthMonth", junkChar);
+ packet >> junkShort;
+ u->setInfo("BirthYear", junkShort);
+ break;
+
+ case ICQ_CMDxRCV_USERxHOMExPAGE:
+ packet >> buffer;
+ u->setInfo("Homepage", buffer);
+ break;
+ }
if (e->reply == 0) ProtoBroadcastAck(protoName, u->hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, 0, 0);
- doneEvent(true, udpSocket.handleVal, theSequence1);
- delete [] buffer;
- break;
+ doneEvent(true, udpSocket.handleVal, theSequence1);
+ delete[] buffer;
+ break;
- case ICQ_CMDxRCV_USERxINVALIDxUIN: // not a good uin
- T("[udp] invalid uin\n");
- ackUDP(theSequence);
+ case ICQ_CMDxRCV_USERxINVALIDxUIN: // not a good uin
+ T("[udp] invalid uin\n");
+ ackUDP(theSequence);
- if ((e = getEvent(udpSocket.handleVal, theSequence1)) == NULL) break;
+ if ((e = getEvent(udpSocket.handleVal, theSequence1)) == NULL) break;
- checkUin = e->uin;
- T("invalid uin: %d\n", checkUin);
-/*
- delete icqEvents[i2];
- icqEvents[i2] = icqEvents[icqEvents.size() - 1];
- icqEvents.pop_back();
-*/
- break;
-
- case ICQ_CMDxRCV_USERxSTATUS: // user changed status packet
- packet >> checkUin;
-
- T("[udp] user %d changed status\n", checkUin);
- ackUDP(theSequence);
-
- packet >> newStatus;
+ checkUin = e->uin;
+ T("invalid uin: %d\n", checkUin);
+ break;
- if ((u = getUserByUIN(checkUin, false)) == NULL) break;
- u->setStatus(toIdStatus(newStatus));
- break;
-
- case ICQ_CMDxRCV_USERxLISTxDONE: // end of user list
- T("[udp] end of user list.\n");
- ackUDP(theSequence);
- break;
-
- case ICQ_CMDxRCV_SEARCHxFOUND: // user found in search
- T("[udp] search found user\n");
- ackUDP(theSequence);
-
- char *alias, *firstName, *lastName, *email;
- unsigned char auth;
-
- alias = NULL;
- firstName = NULL;
- lastName = NULL;
- email = NULL;
- packet >> checkUin >> alias >> firstName >> lastName >> email >> auth;
- {
- ICQSEARCHRESULT psr = { 0 };
- psr.hdr.cbSize = sizeof(psr);
- psr.hdr.nick.a = alias;
- psr.hdr.firstName.a = firstName;
- psr.hdr.lastName.a = lastName;
- psr.hdr.email.a = email;
- psr.uin = checkUin;
- psr.auth = auth;
- ProtoBroadcastAck(protoName, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
- }
-
- delete [] alias;
- delete [] firstName;
- delete [] lastName;
- delete [] email;
- break;
-
- case ICQ_CMDxRCV_SEARCHxDONE:
- T("[udp] search finished.\n");
- ackUDP(theSequence);
-
- packet >> searchSequence;
- searchSequence = theSequence1;
-
- ProtoBroadcastAck(protoName, NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
- break;
-
- case ICQ_CMDxRCV_SYSxMSGxOFFLINE: // offline system message, now have to check the sub-command
- T("[udp] offline system message\n");
- ackUDP(theSequence);
-
- packet >> checkUin
- >> timedataStamp
- >> newCommand;
-
- timeStampLastMessage = timedataStamp;
- timedataStamp = TimeZone_ToLocal(timedataStamp);
-
- processSystemMessage(packet, checkUin, newCommand, timedataStamp);
- break;
-
- case ICQ_CMDxRCV_SYSxMSGxONLINE: // online system message, now have to check the sub-command
- T("[udp] online system message\n");
- ackUDP(theSequence);
-
- packet >> checkUin
- >> newCommand;
-
- processSystemMessage(packet, checkUin, newCommand, time(NULL));
- break;
-
- case ICQ_CMDxRCV_SYSxMSGxDONE: // end of system messages
- T("[udp] end of system messages.\n");
- ackUDP(theSequence);
-
- if (timeStampLastMessage)
- {
- ackSYS(timeStampLastMessage);
- timeStampLastMessage = 0;
- }
- break;
-
- case ICQ_CMDxRCV_BROADCASTxMULTI:
- T("[udp] broadcast multi-packet (%d)\n", theSequence);
- ackUDP(theSequence);
-
- unsigned int i;
- unsigned char j, frameNo, frameSize;
- bool found;
-
- packet >> frameNo
- >> frameSize;
-
- icqEvents.push_back(new ICQEvent(ICQ_CMDxRCV_BROADCASTxMULTI, (unsigned short)frameNo, theSequence1, 0, &udpSocket, &packet, 0));
-
- {
- Packet multiPacket;
-
- for (j=0; j<frameSize; j++)
- {
- found = false;
- for (i=0; i<icqEvents.size(); i++)
- {
- e = icqEvents[i];
- if (e->cmd == ICQ_CMDxRCV_BROADCASTxMULTI && e->subCmd == j && e->isEvent(udpSocket.handleVal, theSequence1))
- {
- multiPacket << e->packet;
- found = true;
- break;
- }
- }
- if (!found) break;
- }
-
- if (j == frameSize)
- {
- for (i=0; i<icqEvents.size(); i++)
- {
- e = icqEvents[i];
- if (e->cmd == ICQ_CMDxRCV_BROADCASTxMULTI && e->isEvent(udpSocket.handleVal, theSequence1))
- {
- icqEvents[i] = icqEvents[icqEvents.size() - 1];
- icqEvents.pop_back();
-
- delete e;
- }
- }
-
- multiPacket.reset();
- processUdpPacket(multiPacket);
- }
- }
- break;
-
- case ICQ_CMDxRCV_BROADCASTxOFFLINE:
- T("[udp] offline broadcast message (%d)\n", theSequence);
- ackUDP(theSequence);
-
- packet >> checkUin
- >> timedataStamp
- >> newCommand;
-
- db_set_dw(NULL, protoName, "LastBroadcastTime", timedataStamp);
- timedataStamp = TimeZone_ToLocal(timedataStamp);
-
- processSystemMessage(packet, checkUin, newCommand, timedataStamp);
- break;
-
- case ICQ_CMDxRCV_BROADCASTxONLINE:
- T("[udp] online broadcast message (%d)\n", theSequence);
- ackUDP(theSequence);
-
- packet >> checkUin
- >> newCommand;
-
- processSystemMessage(packet, checkUin, newCommand, time(NULL));
- break;
-
- case ICQ_CMDxRCV_BROADCASTxDONE:
- T("[udp] end of broadcast messages.\n");
- ackUDP(theSequence);
- break;
-
- case ICQ_CMDxRCV_SETxOFFLINE: // we got put offline by mirabilis for some reason
- T("[udp] kicked offline.\n");
- logoff(true);
- break;
-
- case ICQ_CMDxRCV_ACK: // icq acknowledgement
- T("[udp] received ack (%d)\n", theSequence);
- doneEvent(true, udpSocket.handleVal, theSequence);
- break;
-
- case ICQ_CMDxRCV_ERROR: // icq says go away
- T("[udp] server says bugger off.\n");
- logoff(true);
- break;
-
- case ICQ_CMDxRCV_HELLO: // hello packet from mirabilis received on logon
- T("[udp] received hello.\n");
- ackUDP(theSequence);
-
- int oldStatus;
-
- requestSystemMsg();
- requestBroadcastMsg();
-
-// pingTimer.start(PING_FREQUENCY * 1000);
- oldStatus = statusVal;
- statusVal = desiredStatus;
- ProtoBroadcastAck(protoName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, statusVal);
-
- updateContactList();
-// sendVisibleList();
-// sendInvisibleList();
- break;
-
- case ICQ_CMDxRCV_WRONGxPASSWD: // incorrect password sent in logon
- T("[udp] incorrect password.\n");
- ProtoBroadcastAck(protoName, NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD);
- MessageBox(NULL, Translate("Your ICQ Corp number and password combination was rejected by the ICQ Corporate server. Please go to Options -> Network -> ICQCorp and try again."), protoName, MB_ICONERROR|MB_OK);
- break;
-
- case ICQ_CMDxRCV_BUSY: // server too busy to respond
- T("[udp] server busy, try again in a few minutes.\n");
- break;
-
- default: // what the heck is this packet?
- T("[udp] unknown packet:\n%s", packet.print());
- ackUDP(theSequence);
- break;
- }
-
- return command;
-}
+ case ICQ_CMDxRCV_USERxSTATUS: // user changed status packet
+ packet >> checkUin;
-///////////////////////////////////////////////////////////////////////////////
+ T("[udp] user %d changed status\n", checkUin);
+ ackUDP(theSequence);
-void ICQ::processSystemMessage(Packet &packet, unsigned long checkUin, unsigned short newCommand, time_t timeSent)
-{
- char *message/*, *sysMsg*/;
- ICQUser *u;
- unsigned int i, /*j,*/ messageLen;
+ packet >> newStatus;
- u = getUserByUIN(checkUin);
+ if ((u = getUserByUIN(checkUin, false)) == NULL) break;
+ u->setStatus(toIdStatus(newStatus));
+ break;
- message = NULL;
- packet >> message;
+ case ICQ_CMDxRCV_USERxLISTxDONE: // end of user list
+ T("[udp] end of user list.\n");
+ ackUDP(theSequence);
+ break;
- switch (newCommand)
- {
- case ICQ_CMDxRCV_SYSxMSG:
- T("message through server from %d\n", checkUin);
- addMessage(u, message, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxTCP_MSG, 0, timeSent);
- break;
+ case ICQ_CMDxRCV_SEARCHxFOUND: // user found in search
+ T("[udp] search found user\n");
+ ackUDP(theSequence);
- case ICQ_CMDxRCV_SYSxURL:
- T("url through server from %d\n", checkUin);
- addUrl(u, message, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxTCP_URL, 0, timeSent);
- break;
+ char *alias, *firstName, *lastName, *email;
+ unsigned char auth;
- case ICQ_CMDxRCV_SYSxBROADCAST:
- T("broadcast message from %d\n", checkUin);
+ alias = NULL;
+ firstName = NULL;
+ lastName = NULL;
+ email = NULL;
+ packet >> checkUin >> alias >> firstName >> lastName >> email >> auth;
+ {
+ ICQSEARCHRESULT psr = { 0 };
+ psr.hdr.cbSize = sizeof(psr);
+ psr.hdr.nick.a = alias;
+ psr.hdr.firstName.a = firstName;
+ psr.hdr.lastName.a = lastName;
+ psr.hdr.email.a = email;
+ psr.uin = checkUin;
+ psr.auth = auth;
+ ProtoBroadcastAck(protoName, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
+ }
- messageLen = (unsigned int)mir_strlen(message);
- for (i=0; i<messageLen; i++) if (message[i] == (char)0xFE) message[i] = '\n';
+ delete[] alias;
+ delete[] firstName;
+ delete[] lastName;
+ delete[] email;
+ break;
- addMessage(u, message, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxTCP_MSG, 0, timeSent);
- break;
-/*
- case ICQ_CMDxRCV_SYSxAUTHxREQ: // system message: authorisation request
- // 02 00 04 01 08 00 8F 76 20 00 06 00 41 00 41 70 6F 74 68 65 6F 73 69 73
- // FE 47 72 61 68 61 6D FE 52 6F 66 66 FE 67 72 6F 66 66 40 75 77 61 74 65
- // 72 6C 6F 6F 2E 63 61 FE 31 FE 50 6C 65 61 73 65 20 61 75 74 68 6F 72 69
- // 7A 65 20 6D 65 2E 00
- T("authorization request from %ld.\n", checkUin);
- packet >> messageLen;
- message = new char[messageLen + 1];
- for (i=0; i<=messageLen; i++)
- {
- packet >> message[i];
- if (message[i] == (char)0xFE) message[i] = '\n';
- }
-
- sysMsg = new char[messageLen + 128];
- sprintf(sysMsg, "(%s) Authorization request from %ld:\n%s", sm.timeRec(), checkUin, message);
- icqOwner.addMessage(sysMsg, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxRCV_SMxREQxAUTH, 0, timeSent);
- sprintf(sysMsg, "Authorization request from %ld:\n%s", checkUin, message);
- addToSystemMessageHistory(sysMsg);
- playSound(soundSysMsg);
- delete sysMsg;
- delete message;
- break;
-
- case ICQ_CMDxRCV_SYSxAUTHxGRANTED: // system message: authorization granted
-
- outputWindow->wprintf(" (%s) Authorization granted from %ld.", sm.timeRec(), checkUin);
- packet >> messageLen;
- message = new char[messageLen + 1];
- for (i = 0; i <= messageLen; i++)
- {
- packet >> message[i];
- if (message[i] == (char)0xFE) message[i] = '\n';
- }
-
- sysMsg = new char[messageLen + 128];
- sprintf(sysMsg, "(%s) Authorization granted from %ld:\n%s", sm.timeRec(), checkUin, message);
- icqOwner.addMessage(sysMsg, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxRCV_SMxREQxAUTH, 0, timeSent);
- sprintf(sysMsg, "Authorization granted from %ld:\n%s", checkUin, message);
- addToSystemMessageHistory(sysMsg);
- playSound(soundSysMsg);
-
- delete sysMsg;
- delete message;
- break;
-*/
-/*
- case ICQ_CMDxRCV_SYSxADDED: // system message: added to a contact list
- outputWindow->wprintf(" %C(%s) user %C%ld%C added you to their contact list.", COLOR_RECEIVE, sm.timeRec(), COLOR_DATA, checkUin, COLOR_RECEIVE);
- sysMsg = new char[128];
- sprintf(sysMsg, "(%s) User %ld added you to their contact list.", sm.timeRec(), checkUin);
- icqOwner.addMessage(sysMsg, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxRCV_SMxADDED, 0, timeSent);
- sprintf(sysMsg, "User %ld added you to their contact list.", checkUin);
- addToSystemMessageHistory(sysMsg);
- delete sysMsg;
- playSound(soundSysMsg);
-*/
- /* there is a bunch of info about the given user in the packet but the read routine to get
- at it is totally broken right now
- int infoLen, j;
- packet >> infoLen;
-
- // declare all the strings we will need for reading in the user data
- char *userInfo, *aliasField, *firstNameField, *lastNameField, *emailField;
- userInfo = new char[infoLen];
- aliasField = new char[infoLen];
- firstNameField = new char[infoLen];
- lastNameField = new char[infoLen];
- emailField = new char[infoLen];
-
- // read in the user data from the packet
- for (i = 0; i < infoLen; i++) packet >> userInfo[i];
-
- // parse the user info string for the four fields
- i = j = 0;
- do { aliasField[j] = userInfo[i]; i++; j++;} while (userInfo[i] != (char)0xFE);
- aliasField[j] = '\0'; j = 0;
- do { firstNameField[j] = userInfo[i]; i++; j++;} while (userInfo[i] != (char)0xFE);
- firstNameField[j] = '\0'; j = 0;
- do { lastNameField[j] = userInfo[i]; i++; j++;} while (userInfo[i] != (char)0xFE);
- lastNameField[j] = '\0'; j = 0;
- do { emailField[j] = userInfo[i]; i++; j++;} while (i < infoLen);
- emailField[j] = '\0';
-
- *outputWindow << " " << aliasField << " (" << firstNameField << " " << lastNameField << "), " << emailField << ".";
-
- delete userInfo; delete aliasField; delete firstNameField; delete lastNameField; delete emailField;
- break;
- */
-
- default:
- T("[udp] unknown system packet:\n%s", packet.print());
- break;
- }
-
- delete [] message;
+ case ICQ_CMDxRCV_SEARCHxDONE:
+ T("[udp] search finished.\n");
+ ackUDP(theSequence);
+
+ packet >> searchSequence;
+ searchSequence = theSequence1;
+
+ ProtoBroadcastAck(protoName, NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ break;
+
+ case ICQ_CMDxRCV_SYSxMSGxOFFLINE: // offline system message, now have to check the sub-command
+ T("[udp] offline system message\n");
+ ackUDP(theSequence);
+
+ packet >> checkUin
+ >> timedataStamp
+ >> newCommand;
+
+ timeStampLastMessage = timedataStamp;
+ timedataStamp = TimeZone_ToLocal(timedataStamp);
+
+ processSystemMessage(packet, checkUin, newCommand, timedataStamp);
+ break;
+
+ case ICQ_CMDxRCV_SYSxMSGxONLINE: // online system message, now have to check the sub-command
+ T("[udp] online system message\n");
+ ackUDP(theSequence);
+
+ packet >> checkUin
+ >> newCommand;
+
+ processSystemMessage(packet, checkUin, newCommand, time(NULL));
+ break;
+
+ case ICQ_CMDxRCV_SYSxMSGxDONE: // end of system messages
+ T("[udp] end of system messages.\n");
+ ackUDP(theSequence);
+
+ if (timeStampLastMessage)
+ {
+ ackSYS(timeStampLastMessage);
+ timeStampLastMessage = 0;
+ }
+ break;
+
+ case ICQ_CMDxRCV_BROADCASTxMULTI:
+ T("[udp] broadcast multi-packet (%d)\n", theSequence);
+ ackUDP(theSequence);
+
+ unsigned int i;
+ unsigned char j, frameNo, frameSize;
+ bool found;
+
+ packet >> frameNo
+ >> frameSize;
+
+ icqEvents.push_back(new ICQEvent(ICQ_CMDxRCV_BROADCASTxMULTI, (unsigned short)frameNo, theSequence1, 0, &udpSocket, &packet, 0));
+
+ {
+ Packet multiPacket;
+
+ for (j = 0; j < frameSize; j++) {
+ found = false;
+ for (i = 0; i < icqEvents.size(); i++) {
+ e = icqEvents[i];
+ if (e->cmd == ICQ_CMDxRCV_BROADCASTxMULTI && e->subCmd == j && e->isEvent(udpSocket.handleVal, theSequence1)) {
+ multiPacket << e->packet;
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ break;
+ }
+
+ if (j == frameSize) {
+ for (i = 0; i < icqEvents.size(); i++) {
+ e = icqEvents[i];
+ if (e->cmd == ICQ_CMDxRCV_BROADCASTxMULTI && e->isEvent(udpSocket.handleVal, theSequence1)) {
+ icqEvents[i] = icqEvents[icqEvents.size() - 1];
+ icqEvents.pop_back();
+
+ delete e;
+ }
+ }
+
+ multiPacket.reset();
+ processUdpPacket(multiPacket);
+ }
+ }
+ break;
+
+ case ICQ_CMDxRCV_BROADCASTxOFFLINE:
+ T("[udp] offline broadcast message (%d)\n", theSequence);
+ ackUDP(theSequence);
+
+ packet >> checkUin
+ >> timedataStamp
+ >> newCommand;
+
+ db_set_dw(NULL, protoName, "LastBroadcastTime", timedataStamp);
+ timedataStamp = TimeZone_ToLocal(timedataStamp);
+
+ processSystemMessage(packet, checkUin, newCommand, timedataStamp);
+ break;
+
+ case ICQ_CMDxRCV_BROADCASTxONLINE:
+ T("[udp] online broadcast message (%d)\n", theSequence);
+ ackUDP(theSequence);
+
+ packet >> checkUin
+ >> newCommand;
+
+ processSystemMessage(packet, checkUin, newCommand, time(NULL));
+ break;
+
+ case ICQ_CMDxRCV_BROADCASTxDONE:
+ T("[udp] end of broadcast messages.\n");
+ ackUDP(theSequence);
+ break;
+
+ case ICQ_CMDxRCV_SETxOFFLINE: // we got put offline by mirabilis for some reason
+ T("[udp] kicked offline.\n");
+ logoff(true);
+ break;
+
+ case ICQ_CMDxRCV_ACK: // icq acknowledgement
+ T("[udp] received ack (%d)\n", theSequence);
+ doneEvent(true, udpSocket.handleVal, theSequence);
+ break;
+
+ case ICQ_CMDxRCV_ERROR: // icq says go away
+ T("[udp] server says bugger off.\n");
+ logoff(true);
+ break;
+
+ case ICQ_CMDxRCV_HELLO: // hello packet from mirabilis received on logon
+ T("[udp] received hello.\n");
+ ackUDP(theSequence);
+
+ int oldStatus;
+
+ requestSystemMsg();
+ requestBroadcastMsg();
+
+ // pingTimer.start(PING_FREQUENCY * 1000);
+ oldStatus = statusVal;
+ statusVal = desiredStatus;
+ ProtoBroadcastAck(protoName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, statusVal);
+
+ updateContactList();
+ // sendVisibleList();
+ // sendInvisibleList();
+ break;
+
+ case ICQ_CMDxRCV_WRONGxPASSWD: // incorrect password sent in logon
+ T("[udp] incorrect password.\n");
+ ProtoBroadcastAck(protoName, NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD);
+ MessageBox(NULL, Translate("Your ICQ Corp number and password combination was rejected by the ICQ Corporate server. Please go to Options -> Network -> ICQCorp and try again."), protoName, MB_ICONERROR | MB_OK);
+ break;
+
+ case ICQ_CMDxRCV_BUSY: // server too busy to respond
+ T("[udp] server busy, try again in a few minutes.\n");
+ break;
+
+ default: // what the heck is this packet?
+ T("[udp] unknown packet:\n%s", packet.print());
+ ackUDP(theSequence);
+ break;
+ }
+
+ return command;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+void ICQ::processSystemMessage(Packet &packet, unsigned long checkUin, unsigned short newCommand, time_t timeSent)
+{
+ char *message/*, *sysMsg*/;
+ ICQUser *u;
+ unsigned int i, /*j,*/ messageLen;
+
+ u = getUserByUIN(checkUin);
+
+ message = NULL;
+ packet >> message;
+
+ switch (newCommand) {
+ case ICQ_CMDxRCV_SYSxMSG:
+ T("message through server from %d\n", checkUin);
+ addMessage(u, message, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxTCP_MSG, 0, timeSent);
+ break;
+
+ case ICQ_CMDxRCV_SYSxURL:
+ T("url through server from %d\n", checkUin);
+ addUrl(u, message, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxTCP_URL, 0, timeSent);
+ break;
+
+ case ICQ_CMDxRCV_SYSxBROADCAST:
+ T("broadcast message from %d\n", checkUin);
+
+ messageLen = (unsigned int)mir_strlen(message);
+ for (i = 0; i < messageLen; i++) if (message[i] == (char)0xFE) message[i] = '\n';
+
+ addMessage(u, message, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxTCP_MSG, 0, timeSent);
+ break;
+ /*
+ case ICQ_CMDxRCV_SYSxAUTHxREQ: // system message: authorisation request
+ // 02 00 04 01 08 00 8F 76 20 00 06 00 41 00 41 70 6F 74 68 65 6F 73 69 73
+ // FE 47 72 61 68 61 6D FE 52 6F 66 66 FE 67 72 6F 66 66 40 75 77 61 74 65
+ // 72 6C 6F 6F 2E 63 61 FE 31 FE 50 6C 65 61 73 65 20 61 75 74 68 6F 72 69
+ // 7A 65 20 6D 65 2E 00
+ T("authorization request from %ld.\n", checkUin);
+ packet >> messageLen;
+ message = new char[messageLen + 1];
+ for (i=0; i<=messageLen; i++)
+ {
+ packet >> message[i];
+ if (message[i] == (char)0xFE) message[i] = '\n';
+ }
+
+ sysMsg = new char[messageLen + 128];
+ sprintf(sysMsg, "(%s) Authorization request from %ld:\n%s", sm.timeRec(), checkUin, message);
+ icqOwner.addMessage(sysMsg, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxRCV_SMxREQxAUTH, 0, timeSent);
+ sprintf(sysMsg, "Authorization request from %ld:\n%s", checkUin, message);
+ addToSystemMessageHistory(sysMsg);
+ playSound(soundSysMsg);
+ delete sysMsg;
+ delete message;
+ break;
+
+ case ICQ_CMDxRCV_SYSxAUTHxGRANTED: // system message: authorization granted
+
+ outputWindow->wprintf(" (%s) Authorization granted from %ld.", sm.timeRec(), checkUin);
+ packet >> messageLen;
+ message = new char[messageLen + 1];
+ for (i = 0; i <= messageLen; i++)
+ {
+ packet >> message[i];
+ if (message[i] == (char)0xFE) message[i] = '\n';
+ }
+
+ sysMsg = new char[messageLen + 128];
+ sprintf(sysMsg, "(%s) Authorization granted from %ld:\n%s", sm.timeRec(), checkUin, message);
+ icqOwner.addMessage(sysMsg, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxRCV_SMxREQxAUTH, 0, timeSent);
+ sprintf(sysMsg, "Authorization granted from %ld:\n%s", checkUin, message);
+ addToSystemMessageHistory(sysMsg);
+ playSound(soundSysMsg);
+
+ delete sysMsg;
+ delete message;
+ break;
+ */
+ /*
+ case ICQ_CMDxRCV_SYSxADDED: // system message: added to a contact list
+ outputWindow->wprintf(" %C(%s) user %C%ld%C added you to their contact list.", COLOR_RECEIVE, sm.timeRec(), COLOR_DATA, checkUin, COLOR_RECEIVE);
+ sysMsg = new char[128];
+ sprintf(sysMsg, "(%s) User %ld added you to their contact list.", sm.timeRec(), checkUin);
+ icqOwner.addMessage(sysMsg, ICQ_CMDxRCV_SYSxMSGxONLINE, ICQ_CMDxRCV_SMxADDED, 0, timeSent);
+ sprintf(sysMsg, "User %ld added you to their contact list.", checkUin);
+ addToSystemMessageHistory(sysMsg);
+ delete sysMsg;
+ playSound(soundSysMsg);
+ */
+ /* there is a bunch of info about the given user in the packet but the read routine to get
+ at it is totally broken right now
+ int infoLen, j;
+ packet >> infoLen;
+
+ // declare all the strings we will need for reading in the user data
+ char *userInfo, *aliasField, *firstNameField, *lastNameField, *emailField;
+ userInfo = new char[infoLen];
+ aliasField = new char[infoLen];
+ firstNameField = new char[infoLen];
+ lastNameField = new char[infoLen];
+ emailField = new char[infoLen];
+
+ // read in the user data from the packet
+ for (i = 0; i < infoLen; i++) packet >> userInfo[i];
+
+ // parse the user info string for the four fields
+ i = j = 0;
+ do { aliasField[j] = userInfo[i]; i++; j++;} while (userInfo[i] != (char)0xFE);
+ aliasField[j] = '\0'; j = 0;
+ do { firstNameField[j] = userInfo[i]; i++; j++;} while (userInfo[i] != (char)0xFE);
+ firstNameField[j] = '\0'; j = 0;
+ do { lastNameField[j] = userInfo[i]; i++; j++;} while (userInfo[i] != (char)0xFE);
+ lastNameField[j] = '\0'; j = 0;
+ do { emailField[j] = userInfo[i]; i++; j++;} while (i < infoLen);
+ emailField[j] = '\0';
+
+ *outputWindow << " " << aliasField << " (" << firstNameField << " " << lastNameField << "), " << emailField << ".";
+
+ delete userInfo; delete aliasField; delete firstNameField; delete lastNameField; delete emailField;
+ break;
+ */
+
+ default:
+ T("[udp] unknown system packet:\n%s", packet.print());
+ break;
+ }
+
+ delete[] message;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::ackUDP(unsigned short theSequence)
{
- Packet packet;
- packet << ICQ_VERSION
- << ICQ_CMDxSND_ACK
- << theSequence
- << (unsigned short)0x00
- << uin
- << (unsigned int)0x00;
-
- T("[udp] sending ack (%d)\n", theSequence);
- udpSocket.sendPacket(packet);
+ Packet packet;
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_ACK
+ << theSequence
+ << (unsigned short)0x00
+ << uin
+ << (unsigned int)0x00;
+
+ T("[udp] sending ack (%d)\n", theSequence);
+ udpSocket.sendPacket(packet);
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::ackSYS(unsigned int timeStamp)
{
- Packet packet;
- packet << ICQ_VERSION
- << ICQ_CMDxSND_SYSxMSGxDONExACK
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << timeStamp;
-
- T("[udp] sending system message ack (%d)\n", sequenceVal);
- sendICQ(udpSocket, packet, ICQ_CMDxSND_SYSxMSGxDONExACK, sequenceVal);
+ Packet packet;
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_SYSxMSGxDONExACK
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << timeStamp;
+
+ T("[udp] sending system message ack (%d)\n", sequenceVal);
+ sendICQ(udpSocket, packet, ICQ_CMDxSND_SYSxMSGxDONExACK, sequenceVal);
}
///////////////////////////////////////////////////////////////////////////////
ICQUser *ICQ::getUserByUIN(unsigned long uin, bool allowAdd)
{
- unsigned long i;
- ICQUser *u;
-
- for (i=0; i<icqUsers.size(); i++)
- {
- u = icqUsers[i];
- if (u->uin == uin) return u;
- }
-
- if (allowAdd)
- {
- T("unknown user %d, adding them to your list\n", uin);
- return addUser(uin, false);
- }
-
- T("ICQ sent unknown user %d\n", uin);
- return NULL;
+ unsigned long i;
+ ICQUser *u;
+
+ for (i = 0; i < icqUsers.size(); i++)
+ {
+ u = icqUsers[i];
+ if (u->uin == uin) return u;
+ }
+
+ if (allowAdd)
+ {
+ T("unknown user %d, adding them to your list\n", uin);
+ return addUser(uin, false);
+ }
+
+ T("ICQ sent unknown user %d\n", uin);
+ return NULL;
}
///////////////////////////////////////////////////////////////////////////////
ICQUser *ICQ::getUserByContact(MCONTACT hContact)
{
- unsigned long i;
- ICQUser *u;
+ unsigned long i;
+ ICQUser *u;
-// uin = db_get_dw(ccs->hContact, protoName, "UIN", 0);
+ // uin = db_get_dw(ccs->hContact, protoName, "UIN", 0);
- for (i=0; i<icqUsers.size(); i++)
- {
- u = icqUsers[i];
- if (u->hContact == hContact) return u;
- }
- return NULL;
+ for (i = 0; i < icqUsers.size(); i++)
+ {
+ u = icqUsers[i];
+ if (u->hContact == hContact) return u;
+ }
+ return NULL;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::requestSystemMsg()
{
- // request offline system messages
- // 02 00 4C 04 02 00 50 A5 82 00
-
- Packet packet;
- packet << ICQ_VERSION
- << ICQ_CMDxSND_SYSxMSGxREQ
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00;
-
- T("[udp] sending offline system messages request (%d)...\n", sequenceVal);
- sendICQ(udpSocket, packet, ICQ_CMDxSND_SYSxMSGxREQ, sequenceVal);
+ // request offline system messages
+ // 02 00 4C 04 02 00 50 A5 82 00
+
+ Packet packet;
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_SYSxMSGxREQ
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00;
+
+ T("[udp] sending offline system messages request (%d)...\n", sequenceVal);
+ sendICQ(udpSocket, packet, ICQ_CMDxSND_SYSxMSGxREQ, sequenceVal);
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::requestBroadcastMsg()
{
- unsigned int timeStamp = db_get_dw(NULL, protoName, "LastBroadcastTime", 0);
-
- Packet packet;
- packet << ICQ_VERSION
- << ICQ_CMDxSND_BROADCASTxREQ
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << timeStamp
- << (unsigned int)0x00;
-
- T("[udp] sending offline broadcast messages request (%d)...\n", sequenceVal);
- sendICQ(udpSocket, packet, ICQ_CMDxSND_SYSxMSGxREQ, sequenceVal);
+ unsigned int timeStamp = db_get_dw(NULL, protoName, "LastBroadcastTime", 0);
+
+ Packet packet;
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_BROADCASTxREQ
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << timeStamp
+ << (unsigned int)0x00;
+
+ T("[udp] sending offline broadcast messages request (%d)...\n", sequenceVal);
+ sendICQ(udpSocket, packet, ICQ_CMDxSND_SYSxMSGxREQ, sequenceVal);
}
///////////////////////////////////////////////////////////////////////////////
bool ICQ::setStatus(unsigned short newStatus)
{
- if (!udpSocket.connected()) return false;
-
- Packet packet;
- packet << ICQ_VERSION
- << ICQ_CMDxSND_SETxSTATUS
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << toIcqStatus(newStatus);
-
- T("[udp] sending set status packet (%d)\n", sequenceVal);
- sendICQ(udpSocket, packet, ICQ_CMDxSND_SETxSTATUS, sequenceVal);
-
- desiredStatus = newStatus;
- return true;
+ if (!udpSocket.connected())
+ return false;
+
+ Packet packet;
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_SETxSTATUS
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << toIcqStatus(newStatus);
+
+ T("[udp] sending set status packet (%d)\n", sequenceVal);
+ sendICQ(udpSocket, packet, ICQ_CMDxSND_SETxSTATUS, sequenceVal);
+
+ desiredStatus = newStatus;
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::updateContactList()
{
- char *proto;
- unsigned int i;
- int userCount;
- //HANDLE hContact;
- ICQUser *u;
-
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- proto = GetContactProto(hContact);
- if (proto && !mir_strcmp(proto, protoName))
- {
- if ((u = getUserByContact(hContact)) == NULL)
- {
- u = new ICQUser();
- u->hContact = hContact;
- u->uin = db_get_dw(hContact, protoName, "UIN", 0);
- icqUsers.push_back(u);
- }
- if (statusVal <= ID_STATUS_OFFLINE) u->setStatus(ID_STATUS_OFFLINE);
- else u->statusVal = db_get_w(hContact, protoName, "Status", ID_STATUS_OFFLINE);
- }
- }
-
- if (statusVal <= ID_STATUS_OFFLINE) return;
-
-
- // create user info packet
- Packet userPacket;
- for (i=0; i<icqUsers.size(); )
- {
+ char *proto;
+ unsigned int i;
+ int userCount;
+ //HANDLE hContact;
+ ICQUser *u;
+
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ proto = GetContactProto(hContact);
+ if (proto && !mir_strcmp(proto, protoName)) {
+ if ((u = getUserByContact(hContact)) == NULL) {
+ u = new ICQUser();
+ u->hContact = hContact;
+ u->uin = db_get_dw(hContact, protoName, "UIN", 0);
+ icqUsers.push_back(u);
+ }
+ if (statusVal <= ID_STATUS_OFFLINE)
+ u->setStatus(ID_STATUS_OFFLINE);
+ else
+ u->statusVal = db_get_w(hContact, protoName, "Status", ID_STATUS_OFFLINE);
+ }
+ }
+
+ if (statusVal <= ID_STATUS_OFFLINE)
+ return;
+
+ // create user info packet
+ Packet userPacket;
+ for (i = 0; i < icqUsers.size();)
+ {
userCount = (unsigned int)icqUsers.size() - i;
- if (userCount > 100) userCount = 100;
-
- userPacket.clearPacket();
- userPacket << ICQ_VERSION
- << ICQ_CMDxSND_USERxLIST
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << (unsigned char)userCount;
-
- for (; userCount>0; userCount--) userPacket << icqUsers[i++]->uin;
-
- // send user info packet
- T("[udp] sending contact list (%d)...\n", sequenceVal);
- sendICQ(udpSocket, userPacket, ICQ_CMDxSND_USERxLIST, sequenceVal);
- }
+ if (userCount > 100) userCount = 100;
+
+ userPacket.clearPacket();
+ userPacket << ICQ_VERSION
+ << ICQ_CMDxSND_USERxLIST
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << (unsigned char)userCount;
+
+ for (; userCount > 0; userCount--) userPacket << icqUsers[i++]->uin;
+
+ // send user info packet
+ T("[udp] sending contact list (%d)...\n", sequenceVal);
+ sendICQ(udpSocket, userPacket, ICQ_CMDxSND_USERxLIST, sequenceVal);
+ }
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::sendVisibleList()
{
-/*
- unsigned int i, numUsers = 0;
- ICQUser *u;
-
- if (statusVal != ID_STATUS_INVISIBLE) return;
-
- Packet userPacket;
- userPacket << ICQ_VERSION
- << ICQ_CMDxSND_VISxLIST
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00;
-
- for (i=0; i<icqUsers.size(); i++)
- {
- u = icqUsers[i];
- if (u->statusVal != ID_STATUS_OFFLINE && db_get_w(u->hContact, protoName, "ApparentMode", 0) == ID_STATUS_ONLINE)
- numUsers++;
- }
-
- if (numUsers == 0) return;
- userPacket << (char)numUsers;
-
- for (i=0; i<icqUsers.size(); i++)
- {
- u = icqUsers[i];
- if (u->statusVal != ID_STATUS_OFFLINE && db_get_w(u->hContact, protoName, "ApparentMode", 0) == ID_STATUS_ONLINE)
- userPacket << icqUsers[i]->uin;
- }
-
- T("[udp] sending visible list (%d)\n", sequenceVal);
- sendICQ(udpSocket, userPacket, ICQ_CMDxSND_VISxLIST, sequenceVal);
-*/
+ /*
+ unsigned int i, numUsers = 0;
+ ICQUser *u;
+
+ if (statusVal != ID_STATUS_INVISIBLE) return;
+
+ Packet userPacket;
+ userPacket << ICQ_VERSION
+ << ICQ_CMDxSND_VISxLIST
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00;
+
+ for (i=0; i<icqUsers.size(); i++)
+ {
+ u = icqUsers[i];
+ if (u->statusVal != ID_STATUS_OFFLINE && db_get_w(u->hContact, protoName, "ApparentMode", 0) == ID_STATUS_ONLINE)
+ numUsers++;
+ }
+
+ if (numUsers == 0) return;
+ userPacket << (char)numUsers;
+
+ for (i=0; i<icqUsers.size(); i++)
+ {
+ u = icqUsers[i];
+ if (u->statusVal != ID_STATUS_OFFLINE && db_get_w(u->hContact, protoName, "ApparentMode", 0) == ID_STATUS_ONLINE)
+ userPacket << icqUsers[i]->uin;
+ }
+
+ T("[udp] sending visible list (%d)\n", sequenceVal);
+ sendICQ(udpSocket, userPacket, ICQ_CMDxSND_VISxLIST, sequenceVal);
+ */
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::sendInvisibleList()
{
-/*
- unsigned int i, numUsers = 0;
-
- Packet userPacket;
- userPacket << ICQ_VERSION
- << ICQ_CMDxSND_INVISxLIST
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00;
-
- for (i=0; i<icqUsers.size(); i++)
- {
- if (db_get_w(icqUsers[i]->hContact, protoName, "ApparentMode", 0) == ID_STATUS_OFFLINE)
- numUsers++;
- }
-
- if (numUsers == 0) return;
- userPacket << (char)numUsers;
-
- for (i=0; i<icqUsers.size(); i++)
- {
- if (db_get_w(icqUsers[i]->hContact, protoName, "ApparentMode", 0) == ID_STATUS_OFFLINE)
- userPacket << icqUsers[i]->uin;
- }
-
- T("[udp] sending invisible list (%d)\n", sequenceVal);
- sendICQ(udpSocket, userPacket, ICQ_CMDxSND_INVISxLIST, sequenceVal);
-*/
+ /*
+ unsigned int i, numUsers = 0;
+
+ Packet userPacket;
+ userPacket << ICQ_VERSION
+ << ICQ_CMDxSND_INVISxLIST
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00;
+
+ for (i=0; i<icqUsers.size(); i++)
+ {
+ if (db_get_w(icqUsers[i]->hContact, protoName, "ApparentMode", 0) == ID_STATUS_OFFLINE)
+ numUsers++;
+ }
+
+ if (numUsers == 0) return;
+ userPacket << (char)numUsers;
+
+ for (i=0; i<icqUsers.size(); i++)
+ {
+ if (db_get_w(icqUsers[i]->hContact, protoName, "ApparentMode", 0) == ID_STATUS_OFFLINE)
+ userPacket << icqUsers[i]->uin;
+ }
+
+ T("[udp] sending invisible list (%d)\n", sequenceVal);
+ sendICQ(udpSocket, userPacket, ICQ_CMDxSND_INVISxLIST, sequenceVal);
+ */
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::updateUserList(ICQUser *u, char list, char add)
{
-/*
- Packet userPacket;
- userPacket << ICQ_VERSION
- << ICQ_CMDxSND_UPDATExLIST
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << u->uin
- << list
- << add;
-
- T("[udp] update user list (%d)\n", sequenceVal);
- sendICQ(udpSocket, userPacket, ICQ_CMDxSND_UPDATExLIST, sequenceVal);
-*/
+ /*
+ Packet userPacket;
+ userPacket << ICQ_VERSION
+ << ICQ_CMDxSND_UPDATExLIST
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << u->uin
+ << list
+ << add;
+
+ T("[udp] update user list (%d)\n", sequenceVal);
+ sendICQ(udpSocket, userPacket, ICQ_CMDxSND_UPDATExLIST, sequenceVal);
+ */
}
///////////////////////////////////////////////////////////////////////////////
@@ -1301,13 +1261,10 @@ ICQUser *ICQ::addUser(unsigned int uin, bool persistent)
unsigned int i;
ICQUser *u;
- for (i=0; i<icqUsers.size(); i++)
- {
+ for (i = 0; i < icqUsers.size(); i++) {
u = icqUsers[i];
- if (u->uin == uin)
- {
- if (persistent)
- {
+ if (u->uin == uin) {
+ if (persistent) {
db_unset(u->hContact, "CList", "NotOnList");
db_unset(u->hContact, "CList", "Hidden");
}
@@ -1323,9 +1280,9 @@ ICQUser *ICQ::addUser(unsigned int uin, bool persistent)
Proto_AddToContact(u->hContact, protoName);
u->setInfo("UIN", uin);
- if (persistent) getUserInfo(u, true);
- else
- {
+ if (persistent)
+ getUserInfo(u, true);
+ else {
db_set_b(u->hContact, "CList", "NotOnList", 1);
db_set_b(u->hContact, "CList", "Hidden", 1);
}
@@ -1338,998 +1295,943 @@ ICQUser *ICQ::addUser(unsigned int uin, bool persistent)
void ICQ::addNewUser(ICQUser *u)
{
-/*
- // update the users info from the server
- if (statusVal != ICQ_STATUS_OFFLINE)
- {
- Packet packet; // alert server to new user
-
- packet << ICQ_VERSION
- << ICQ_CMDxSND_USERxADD
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << u->uin;
-
- T("[udp] alerting server to new user (%d)...\n", sequenceVal);
- sendICQ(udpSocket, packet, ICQ_CMDxSND_USERxADD, sequenceVal);
-
-// getUserInfo(u);
- }
-*/
- updateContactList();
+ /*
+ // update the users info from the server
+ if (statusVal != ICQ_STATUS_OFFLINE)
+ {
+ Packet packet; // alert server to new user
+
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_USERxADD
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << u->uin;
+
+ T("[udp] alerting server to new user (%d)...\n", sequenceVal);
+ sendICQ(udpSocket, packet, ICQ_CMDxSND_USERxADD, sequenceVal);
+
+ // getUserInfo(u);
+ }
+ */
+ updateContactList();
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::removeUser(ICQUser *u)
{
- unsigned int i;
+ unsigned int i;
- for (i=0; i<icqUsers.size(); i++) if (icqUsers[i] == u) break;
- if (i == icqUsers.size()) return;
+ for (i = 0; i < icqUsers.size(); i++) if (icqUsers[i] == u) break;
+ if (i == icqUsers.size()) return;
- icqUsers[i] = icqUsers[icqUsers.size() - 1];
- icqUsers.pop_back();
+ icqUsers[i] = icqUsers[icqUsers.size() - 1];
+ icqUsers.pop_back();
- delete u;
+ delete u;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::startSearch(unsigned char skrit, unsigned char smode, char *sstring, unsigned int s)
{
- Packet packet;
- packet << ICQ_VERSION
- << ICQ_CMDxSND_SEARCHxSTART
- << sequenceVal
- << (unsigned short)s
-// << (unsigned short)(icqOwner.sequence1())
- << uin
- << (unsigned int)0x00
- << (unsigned char)0xFF
- << skrit
- << (unsigned char)0x00
- << smode
- << sstring;
-
- T("[udp] starting search for user (%d)...\n", s);
- sendICQ(udpSocket, packet, ICQ_CMDxSND_SEARCHxSTART, sequenceVal);
+ Packet packet;
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_SEARCHxSTART
+ << sequenceVal
+ << (unsigned short)s
+ // << (unsigned short)(icqOwner.sequence1())
+ << uin
+ << (unsigned int)0x00
+ << (unsigned char)0xFF
+ << skrit
+ << (unsigned char)0x00
+ << smode
+ << sstring;
+
+ T("[udp] starting search for user (%d)...\n", s);
+ sendICQ(udpSocket, packet, ICQ_CMDxSND_SEARCHxSTART, sequenceVal);
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent *ICQ::send(ICQUser *u, unsigned short cmd, char *cmdStr, char *m)
{
- ICQEvent *result;
+ ICQEvent *result;
- if (u->statusVal > ID_STATUS_OFFLINE && (result = sendTCP(u, cmd, cmdStr, m)) != NULL) return result;
- else return sendUDP(u, cmd, cmdStr, m);
+ if (u->statusVal > ID_STATUS_OFFLINE && (result = sendTCP(u, cmd, cmdStr, m)) != NULL) return result;
+ else return sendUDP(u, cmd, cmdStr, m);
}
///////////////////////////////////////////////////////////////////////////////
bool ICQ::openConnection(TCPSocket &socket)
{
- T("[tcp] connecting to %s on port %d...\n", inet_ntoa(*(in_addr*)&socket.remoteIPVal), socket.remotePortVal);
- socket.openConnection();
-
- if (!socket.connected())
- {
- T("[tcp] connect failed\n");
- return false;
- }
-
- T("[tcp] connection successful\n");
-
- Packet packet;
-// packet << ICQ_CMDxTCP_HANDSHAKE3
- packet << (unsigned char)0xFF
- << (unsigned int)0x02
- << (unsigned int)0x00
-// << (unsigned long)tcpSocket.localPortVal
- << uin
- << socket.localIPVal
- << socket.localIPVal
- << (unsigned char)0x04
- << (unsigned int)0x00;
-// << (unsigned long)tcpSocket.localPortVal;
-
- T("[tcp] sending handshake\n");
- if (!socket.sendPacket(packet))
- {
- T("[tcp] send failed\n");
- return false;
- }
-
- T("[tcp] setup completed\n");
- return true;
+ T("[tcp] connecting to %s on port %d...\n", inet_ntoa(*(in_addr*)&socket.remoteIPVal), socket.remotePortVal);
+ socket.openConnection();
+
+ if (!socket.connected())
+ {
+ T("[tcp] connect failed\n");
+ return false;
+ }
+
+ T("[tcp] connection successful\n");
+
+ Packet packet;
+ // packet << ICQ_CMDxTCP_HANDSHAKE3
+ packet << (unsigned char)0xFF
+ << (unsigned int)0x02
+ << (unsigned int)0x00
+ // << (unsigned long)tcpSocket.localPortVal
+ << uin
+ << socket.localIPVal
+ << socket.localIPVal
+ << (unsigned char)0x04
+ << (unsigned int)0x00;
+ // << (unsigned long)tcpSocket.localPortVal;
+
+ T("[tcp] sending handshake\n");
+ if (!socket.sendPacket(packet)) {
+ T("[tcp] send failed\n");
+ return false;
+ }
+
+ T("[tcp] setup completed\n");
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent *ICQ::sendTCP(ICQUser *u, unsigned short cmd, char *cmdStr, char *m)
{
- if (!u->socket.connected() && !openConnection(u->socket))
- return NULL;
-
- unsigned int status;
- if (accept)
- {
- switch (statusVal)
- {
- case ID_STATUS_ONLINE: status = 0x00100000; break;
- case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
- case ID_STATUS_AWAY: status = 0x01100000; break;
- case ID_STATUS_NA: status = 0x00100000; break;
- case ID_STATUS_DND: status = 0x00100000; break;
- case ID_STATUS_OCCUPIED: status = 0x02100000; break;
- case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
- default: status = 0x00100000; break;
- }
- }
- else status = 0x00000001;
-
- Packet packet;
- packet << uin
- << (unsigned short)0x02 // ICQ_VERSION
- << ICQ_CMDxTCP_START // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
- << (unsigned short)0x00
- << uin
- << cmd
- << m
- << udpSocket.localIPVal
- << udpSocket.localIPVal
- << tcpSocket.localPortVal
- << (unsigned char)0x04
- << status
- << tcpSequenceVal--;
-
- T("[tcp] sending %s (%d)\n", cmdStr, tcpSequenceVal + 1);
- return sendICQ(u->socket, packet, ICQ_CMDxTCP_START, tcpSequenceVal + 1, u->uin, cmd);
+ if (!u->socket.connected() && !openConnection(u->socket))
+ return NULL;
+
+ unsigned int status;
+ switch (statusVal) {
+ case ID_STATUS_ONLINE: status = 0x00100000; break;
+ case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
+ case ID_STATUS_AWAY: status = 0x01100000; break;
+ case ID_STATUS_NA: status = 0x00100000; break;
+ case ID_STATUS_DND: status = 0x00100000; break;
+ case ID_STATUS_OCCUPIED: status = 0x02100000; break;
+ case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
+ default: status = 0x00100000; break;
+ }
+
+ Packet packet;
+ packet << uin
+ << (unsigned short)0x02 // ICQ_VERSION
+ << ICQ_CMDxTCP_START // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
+ << (unsigned short)0x00
+ << uin
+ << cmd
+ << m
+ << udpSocket.localIPVal
+ << udpSocket.localIPVal
+ << tcpSocket.localPortVal
+ << (unsigned char)0x04
+ << status
+ << tcpSequenceVal--;
+
+ T("[tcp] sending %s (%d)\n", cmdStr, tcpSequenceVal + 1);
+ return sendICQ(u->socket, packet, ICQ_CMDxTCP_START, tcpSequenceVal + 1, u->uin, cmd);
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent *ICQ::sendUDP(ICQUser *u, unsigned short cmd, char *cmdStr, char *m)
{
- Packet packet;
- packet << ICQ_VERSION
- << ICQ_CMDxSND_THRUxSERVER
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << u->uin
- << cmd
- << m;
-
-/* write for offline multi packet, but not work - little architecturial trouble:
- one big packet must divided on several little packets and Miranda use returned ONE event for control process sending,
- but not several events
-
- if (packet.size() > 450)
- {
- unsigned int i, j = 0;
- unsigned char c, frameNo, frameSize;
-
- packet.reset();
-
- frameSize = (packet.size()+449) / 450;
- for (frameNo=0; frameNo<frameSize; frameNo++)
- {
- Packet frame;
- frame << ICQ_VERSION
- << ICQ_CMDxSND_MULTI
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << frameSize
- << frameNo;
-
- for (i=0; i<450 && j<packet.size(); i++, j++)
- {
- packet >> c;
- frame << c;
- }
-
- T("[udp] sending %s through server, part %d of %d (%d)\n", cmdStr, frameNo, frameSize, sequenceVal);
- sendICQ(udpSocket, packet, ICQ_CMDxSND_THRUxSERVER, sequenceVal, u->uin, cmd);
- }
- }
- else
-*/
- {
- T("[udp] sending %s through server (%d)\n", cmdStr, sequenceVal);
- return sendICQ(udpSocket, packet, ICQ_CMDxSND_THRUxSERVER, sequenceVal, u->uin, cmd);
- }
+ Packet packet;
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_THRUxSERVER
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << u->uin
+ << cmd
+ << m;
+
+ /* write for offline multi packet, but not work - little architecturial trouble:
+ one big packet must divided on several little packets and Miranda use returned ONE event for control process sending,
+ but not several events
+
+ if (packet.size() > 450)
+ {
+ unsigned int i, j = 0;
+ unsigned char c, frameNo, frameSize;
+
+ packet.reset();
+
+ frameSize = (packet.size()+449) / 450;
+ for (frameNo=0; frameNo<frameSize; frameNo++)
+ {
+ Packet frame;
+ frame << ICQ_VERSION
+ << ICQ_CMDxSND_MULTI
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << frameSize
+ << frameNo;
+
+ for (i=0; i<450 && j<packet.size(); i++, j++)
+ {
+ packet >> c;
+ frame << c;
+ }
+
+ T("[udp] sending %s through server, part %d of %d (%d)\n", cmdStr, frameNo, frameSize, sequenceVal);
+ sendICQ(udpSocket, packet, ICQ_CMDxSND_THRUxSERVER, sequenceVal, u->uin, cmd);
+ }
+ }
+ else
+ */
+ {
+ T("[udp] sending %s through server (%d)\n", cmdStr, sequenceVal);
+ return sendICQ(udpSocket, packet, ICQ_CMDxSND_THRUxSERVER, sequenceVal, u->uin, cmd);
+ }
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent *ICQ::sendMessage(ICQUser *u, char *m)
{
- return send(u, ICQ_CMDxTCP_MSG, "message", m);
+ return send(u, ICQ_CMDxTCP_MSG, "message", m);
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent *ICQ::sendUrl(ICQUser *u, char *url)
{
- unsigned int nameLen, descriptionLen;
- char *m, *description;
- ICQEvent *result;
+ unsigned int nameLen, descriptionLen;
+ char *m, *description;
+ ICQEvent *result;
nameLen = (unsigned int)mir_strlen(url);
- description = (char*)url + nameLen + 1;
+ description = (char*)url + nameLen + 1;
descriptionLen = (unsigned int)mir_strlen(description);
- m = new char[nameLen + descriptionLen + 2];
- mir_strcpy(m, description);
- mir_strcpy(m + descriptionLen + 1, url);
- m[descriptionLen] = (char)0xFE;
+ m = new char[nameLen + descriptionLen + 2];
+ mir_strcpy(m, description);
+ mir_strcpy(m + descriptionLen + 1, url);
+ m[descriptionLen] = (char)0xFE;
- result = send(u, ICQ_CMDxTCP_URL, "url", m);
- delete [] m;
+ result = send(u, ICQ_CMDxTCP_URL, "url", m);
+ delete[] m;
- return result;
+ return result;
}
///////////////////////////////////////////////////////////////////////////////
ICQEvent *ICQ::sendReadAwayMsg(ICQUser *u)
{
- unsigned short cmd;
-
- switch (u->statusVal)
- {
- case ID_STATUS_AWAY: cmd = ICQ_CMDxTCP_READxAWAYxMSG; break;
- case ID_STATUS_DND: cmd = ICQ_CMDxTCP_READxDNDxMSG; break;
- case ID_STATUS_NA: cmd = ICQ_CMDxTCP_READxNAxMSG; break;
- case ID_STATUS_OCCUPIED: cmd = ICQ_CMDxTCP_READxOCCUPIEDxMSG; break;
- case ID_STATUS_FREECHAT: cmd = ICQ_CMDxTCP_READxFREECHATxMSG; break;
- default: return NULL;
- }
-
- return sendTCP(u, cmd, "away message request", "");
+ unsigned short cmd;
+
+ switch (u->statusVal) {
+ case ID_STATUS_AWAY: cmd = ICQ_CMDxTCP_READxAWAYxMSG; break;
+ case ID_STATUS_DND: cmd = ICQ_CMDxTCP_READxDNDxMSG; break;
+ case ID_STATUS_NA: cmd = ICQ_CMDxTCP_READxNAxMSG; break;
+ case ID_STATUS_OCCUPIED: cmd = ICQ_CMDxTCP_READxOCCUPIEDxMSG; break;
+ case ID_STATUS_FREECHAT: cmd = ICQ_CMDxTCP_READxFREECHATxMSG; break;
+ default: return NULL;
+ }
+
+ return sendTCP(u, cmd, "away message request", "");
}
///////////////////////////////////////////////////////////////////////////////
ICQTransfer *ICQ::sendFile(ICQUser *u, char *description, char *filename, unsigned int size, char **files)
{
- if (!u->socket.connected() && !openConnection(u->socket)) return NULL;
+ if (!u->socket.connected() && !openConnection(u->socket))
+ return NULL;
- unsigned int i;
+ unsigned int i;
- ICQTransfer *transfer = new ICQTransfer(u, tcpSequenceVal);
+ ICQTransfer *transfer = new ICQTransfer(u, tcpSequenceVal);
- for (i=0; files[i]; i++);
- transfer->files = new char*[i + 1];
- for (i=0; files[i]; i++) transfer->files[i] = _strdup(files[i]);
- transfer->files[i] = 0;
+ for (i = 0; files[i]; i++);
+ transfer->files = new char*[i + 1];
+ for (i = 0; files[i]; i++) transfer->files[i] = _strdup(files[i]);
+ transfer->files[i] = 0;
- transfer->description = _strdup(description);
- transfer->count = i;
- transfer->totalSize = size;
+ transfer->description = _strdup(description);
+ transfer->count = i;
+ transfer->totalSize = size;
- transfer->path = _strdup(transfer->files[0]);
+ transfer->path = _strdup(transfer->files[0]);
char *s = strrchr(transfer->path, '\\');
- if (s != NULL) *s = 0;
-
- icqTransfers.push_back(transfer);
- transfer->ack(ACKRESULT_SENTREQUEST);
-
-
- unsigned short cmd = ICQ_CMDxTCP_FILE;
- char *m = description;
-
- unsigned int status;
- if (accept)
- {
- switch (statusVal)
- {
- case ID_STATUS_ONLINE: status = 0x00100000; break;
- case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
- case ID_STATUS_AWAY: status = 0x01100000; break;
- case ID_STATUS_NA: status = 0x00100000; break;
- case ID_STATUS_DND: status = 0x00100000; break;
- case ID_STATUS_OCCUPIED: status = 0x02100000; break;
- case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
- default: status = 0x00100000; break;
- }
- }
- else status = 0x00000001;
-
- Packet packet;
- packet << uin
- << (unsigned short)0x02 // ICQ_VERSION
- << ICQ_CMDxTCP_START // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
- << (unsigned short)0x00
- << uin
- << cmd
- << m
- << udpSocket.localIPVal
- << udpSocket.localIPVal
- << tcpSocket.localPortVal
- << (unsigned char)0x04
- << status;
-
-
- packet << (unsigned int)0x00
- << filename
- << size
- << (unsigned int)0x00;
-
- packet << tcpSequenceVal--;
-
- T("[tcp] sending file request (%d)\n", tcpSequenceVal + 1);
- sendICQ(u->socket, packet, ICQ_CMDxTCP_START, tcpSequenceVal + 1, u->uin, cmd);
- return transfer;
+ if (s != NULL)
+ *s = 0;
+
+ icqTransfers.push_back(transfer);
+ transfer->ack(ACKRESULT_SENTREQUEST);
+
+ unsigned short cmd = ICQ_CMDxTCP_FILE;
+ char *m = description;
+
+ unsigned int status;
+ switch (statusVal) {
+ case ID_STATUS_ONLINE: status = 0x00100000; break;
+ case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
+ case ID_STATUS_AWAY: status = 0x01100000; break;
+ case ID_STATUS_NA: status = 0x00100000; break;
+ case ID_STATUS_DND: status = 0x00100000; break;
+ case ID_STATUS_OCCUPIED: status = 0x02100000; break;
+ case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
+ default: status = 0x00100000; break;
+ }
+
+ Packet packet;
+ packet << uin
+ << (unsigned short)0x02 // ICQ_VERSION
+ << ICQ_CMDxTCP_START // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
+ << (unsigned short)0x00
+ << uin
+ << cmd
+ << m
+ << udpSocket.localIPVal
+ << udpSocket.localIPVal
+ << tcpSocket.localPortVal
+ << (unsigned char)0x04
+ << status;
+
+
+ packet << (unsigned int)0x00
+ << filename
+ << size
+ << (unsigned int)0x00;
+
+ packet << tcpSequenceVal--;
+
+ T("[tcp] sending file request (%d)\n", tcpSequenceVal + 1);
+ sendICQ(u->socket, packet, ICQ_CMDxTCP_START, tcpSequenceVal + 1, u->uin, cmd);
+ return transfer;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::acceptFile(ICQUser *u, unsigned long hTransfer, char *path)
{
- unsigned int theSequence = hTransfer;
- unsigned short cmd = ICQ_CMDxTCP_FILE;
- char m[1] = { 0 };
-
- unsigned long status;
- if (accept)
- {
- switch (statusVal)
- {
- case ID_STATUS_ONLINE: status = 0x00100000; break;
- case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
- case ID_STATUS_AWAY: status = 0x01100000; break;
- case ID_STATUS_NA: status = 0x00100000; break;
- case ID_STATUS_DND: status = 0x00100000; break;
- case ID_STATUS_OCCUPIED: status = 0x02100000; break;
- case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
- default: status = 0x00100000; break;
- }
- }
- else status = 0x00000001;
-
- Packet packet;
- packet << uin
- << (unsigned short)0x02 // ICQ_VERSION
- << ICQ_CMDxTCP_ACK // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
- << (unsigned short)0x00
- << uin
- << cmd
- << m
- << udpSocket.localIPVal
- << udpSocket.localIPVal
- << tcpSocket.localPortVal
- << (unsigned char)0x04
-// << status;
- << (unsigned int)0x00;
-
- packet << (unsigned int)htons(tcpSocket.localPortVal)
- << m
- << (unsigned int)0x00
- << tcpSocket.localPortVal;
-
- packet << theSequence;
-
- T("[tcp] sending accept file ack (%d)\n", theSequence);
- u->socket.sendPacket(packet);
+ unsigned int theSequence = hTransfer;
+ unsigned short cmd = ICQ_CMDxTCP_FILE;
+ char m[1] = { 0 };
+
+ unsigned long status;
+ switch (statusVal) {
+ case ID_STATUS_ONLINE: status = 0x00100000; break;
+ case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
+ case ID_STATUS_AWAY: status = 0x01100000; break;
+ case ID_STATUS_NA: status = 0x00100000; break;
+ case ID_STATUS_DND: status = 0x00100000; break;
+ case ID_STATUS_OCCUPIED: status = 0x02100000; break;
+ case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
+ default: status = 0x00100000; break;
+ }
+
+ Packet packet;
+ packet << uin
+ << (unsigned short)0x02 // ICQ_VERSION
+ << ICQ_CMDxTCP_ACK // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
+ << (unsigned short)0x00
+ << uin
+ << cmd
+ << m
+ << udpSocket.localIPVal
+ << udpSocket.localIPVal
+ << tcpSocket.localPortVal
+ << (unsigned char)0x04
+ << (unsigned int)0x00;
+
+ packet << (unsigned int)htons(tcpSocket.localPortVal)
+ << m
+ << (unsigned int)0x00
+ << tcpSocket.localPortVal;
+
+ packet << theSequence;
+
+ T("[tcp] sending accept file ack (%d)\n", theSequence);
+ u->socket.sendPacket(packet);
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::refuseFile(ICQUser *u, unsigned long hTransfer, char *reason)
{
- unsigned int theSequence = hTransfer;
- unsigned short cmd = ICQ_CMDxTCP_FILE;
- char m[1] = { 0 };
-
- unsigned int status;
- if (accept)
- {
- switch (statusVal)
- {
- case ID_STATUS_ONLINE: status = 0x00100000; break;
- case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
- case ID_STATUS_AWAY: status = 0x01100000; break;
- case ID_STATUS_NA: status = 0x00100000; break;
- case ID_STATUS_DND: status = 0x00100000; break;
- case ID_STATUS_OCCUPIED: status = 0x02100000; break;
- case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
- default: status = 0x00100000; break;
- }
- }
- else status = 0x00000001;
-
- Packet packet;
- packet << uin
- << (unsigned short)0x02 // ICQ_VERSION
- << ICQ_CMDxTCP_ACK // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
- << (unsigned short)0x00
- << uin
- << cmd
- << reason
- << udpSocket.localIPVal
- << udpSocket.localIPVal
- << tcpSocket.localPortVal
- << (unsigned char)0x04
-// << status;
- << (unsigned int)0x00000001;
-
- packet << (unsigned int)0x00
- << m
- << (unsigned int)0x00
- << (unsigned int)0x00;
-
- packet << theSequence;
-
- T("[tcp] sending refuse file ack (%d)\n", theSequence);
- u->socket.sendPacket(packet);
+ unsigned int theSequence = hTransfer;
+ unsigned short cmd = ICQ_CMDxTCP_FILE;
+ char m[1] = { 0 };
+
+ unsigned int status;
+ switch (statusVal) {
+ case ID_STATUS_ONLINE: status = 0x00100000; break;
+ case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
+ case ID_STATUS_AWAY: status = 0x01100000; break;
+ case ID_STATUS_NA: status = 0x00100000; break;
+ case ID_STATUS_DND: status = 0x00100000; break;
+ case ID_STATUS_OCCUPIED: status = 0x02100000; break;
+ case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
+ default: status = 0x00100000; break;
+ }
+
+ Packet packet;
+ packet << uin
+ << (unsigned short)0x02 // ICQ_VERSION
+ << ICQ_CMDxTCP_ACK // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
+ << (unsigned short)0x00
+ << uin
+ << cmd
+ << reason
+ << udpSocket.localIPVal
+ << udpSocket.localIPVal
+ << tcpSocket.localPortVal
+ << (unsigned char)0x04
+ << (unsigned int)0x00000001;
+
+ packet << (unsigned int)0x00
+ << m
+ << (unsigned int)0x00
+ << (unsigned int)0x00;
+
+ packet << theSequence;
+
+ T("[tcp] sending refuse file ack (%d)\n", theSequence);
+ u->socket.sendPacket(packet);
}
///////////////////////////////////////////////////////////////////////////////
bool ICQ::getUserInfo(ICQUser *u, bool basicInfo)
{
- unsigned short cmd = basicInfo ? ICQ_CMDxSND_USERxGETxBASICxINFO : ICQ_CMDxSND_USERxGETxINFO;
-
- Packet request;
- request << ICQ_VERSION
- << cmd
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << u->uin;
-
- T("[udp] sending user %s info request (%d)...\n", basicInfo ? "basic" : "details", sequenceVal);
- sendICQ(udpSocket, request, cmd, sequenceVal, u->uin, 0, basicInfo ? 1 : 5);
- return true;
+ unsigned short cmd = basicInfo ? ICQ_CMDxSND_USERxGETxBASICxINFO : ICQ_CMDxSND_USERxGETxINFO;
+
+ Packet request;
+ request << ICQ_VERSION
+ << cmd
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << u->uin;
+
+ T("[udp] sending user %s info request (%d)...\n", basicInfo ? "basic" : "details", sequenceVal);
+ sendICQ(udpSocket, request, cmd, sequenceVal, u->uin, 0, basicInfo ? 1 : 5);
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::authorize(unsigned int uinToAuthorize)
{
- Packet packet;
- packet << ICQ_VERSION
- << ICQ_CMDxSND_AUTHORIZE
- << sequenceVal
- << sequenceVal
- << uin
- << (unsigned int)0x00
- << uinToAuthorize
- << (unsigned int)0x00010008 // who knows, seems to be constant
- << (unsigned char)0x00;
-
- T("[udp] sending authorization (%d)\n", sequenceVal);
- sendICQ(udpSocket, packet, ICQ_CMDxSND_AUTHORIZE, sequenceVal);
+ Packet packet;
+ packet << ICQ_VERSION
+ << ICQ_CMDxSND_AUTHORIZE
+ << sequenceVal
+ << sequenceVal
+ << uin
+ << (unsigned int)0x00
+ << uinToAuthorize
+ << (unsigned int)0x00010008 // who knows, seems to be constant
+ << (unsigned char)0x00;
+
+ T("[udp] sending authorization (%d)\n", sequenceVal);
+ sendICQ(udpSocket, packet, ICQ_CMDxSND_AUTHORIZE, sequenceVal);
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::processTcpPacket(Packet &packet, unsigned int hSocket)
{
- unsigned int i, checkUin, senderIp, localIp, userStatus, senderPort, junkLong, thePort, theTCPSequence = 0;
- unsigned short version, command, junkShort, newCommand, /*messageLen,*/ cicqVersion;
- unsigned char cicqChar, junkChar;
- char *message = NULL;
- ICQUser *u;
- static unsigned int chatUin, chatSequence;
-
- packet >> checkUin
- >> version
- >> command // so far either message stuff or message ack
- >> junkShort // 00 00 to fill in the MSB of the command long int which is read in as a short
- >> checkUin
- >> newCommand // if a message then what type, message/chat/read away message/...
- >> message
- >> senderIp
- >> localIp
- >> senderPort
- >> junkChar
- >> userStatus;
-
- u = getUserByUIN(checkUin);
- switch(command)
- {
- case ICQ_CMDxTCP_START: // incoming tcp packet containing one of many possible things
- switch(newCommand) // do a switch on what it could be
- {
- case ICQ_CMDxTCP_MSG: // straight message from a user
- T("[tcp] message from %d.\n", checkUin);
-
- packet >> theTCPSequence;
-
- ackTCP(packet, u, newCommand, theTCPSequence);
- addMessage(u, message, ICQ_CMDxTCP_START, ICQ_CMDxTCP_MSG, theTCPSequence, time(NULL));
- break;
-
- case ICQ_CMDxTCP_CHAT:
- T("[tcp] chat request from %d.\n", checkUin);
-
- packet >> junkLong
- >> junkLong
- >> junkShort
- >> junkChar
- >> theTCPSequence
- >> cicqChar
- >> cicqVersion;
-/*
- char *chatReq;
- chatReq = new char[messageLen + 32];
- sprintf(chatReq, "Chat request:\n %s", message);
-// u->addMessage(chatReq, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CHAT, theTCPSequence, 0, (cicqChar == 'C'), cicqVersion);
- delete chatReq;
-*/
- break;
-
- case ICQ_CMDxTCP_URL: // url sent
- T("[tcp] url from %d.\n", checkUin);
-
- packet >> theTCPSequence;
-
- ackTCP(packet, u, newCommand, theTCPSequence);
- addUrl(u, message, ICQ_CMDxTCP_START, ICQ_CMDxTCP_URL, theTCPSequence, time(NULL));
- break;
-
- case ICQ_CMDxTCP_FILE:
- unsigned int size;
- char *fileName;
-
- fileName = NULL;
- packet >> junkLong
- >> fileName
- >> size
- >> junkLong
- >> theTCPSequence;
-
- T("[tcp] file transfer request from %d (%d)\n", checkUin, theTCPSequence);
-
- addFileReq(u, message, fileName, size, ICQ_CMDxTCP_START, ICQ_CMDxTCP_FILE, theTCPSequence, time(NULL));
- delete [] fileName;
- break;
-
- case ICQ_CMDxTCP_READxAWAYxMSG: // read away message
- case ICQ_CMDxTCP_READxOCCUPIEDxMSG:
- case ICQ_CMDxTCP_READxNAxMSG:
- case ICQ_CMDxTCP_READxDNDxMSG:
- case ICQ_CMDxTCP_READxFREECHATxMSG:
- T("[tcp] %d requested read of away message.\n", checkUin);
-
- packet >> theTCPSequence;
- ackTCP(packet, u, newCommand, theTCPSequence);
- break;
- }
- break;
-
- case ICQ_CMDxTCP_ACK: // message received packet
- switch (newCommand)
- {
- case ICQ_CMDxTCP_MSG:
- packet >> theTCPSequence;
- break;
+ unsigned int i, checkUin, senderIp, localIp, userStatus, senderPort, junkLong, thePort, theTCPSequence = 0;
+ unsigned short version, command, junkShort, newCommand, /*messageLen,*/ cicqVersion;
+ unsigned char cicqChar, junkChar;
+ char *message = NULL;
+ ICQUser *u;
+ static unsigned int chatUin, chatSequence;
+
+ packet >> checkUin
+ >> version
+ >> command // so far either message stuff or message ack
+ >> junkShort // 00 00 to fill in the MSB of the command long int which is read in as a short
+ >> checkUin
+ >> newCommand // if a message then what type, message/chat/read away message/...
+ >> message
+ >> senderIp
+ >> localIp
+ >> senderPort
+ >> junkChar
+ >> userStatus;
+
+ u = getUserByUIN(checkUin);
+ switch (command) {
+ case ICQ_CMDxTCP_START: // incoming tcp packet containing one of many possible things
+ switch (newCommand) { // do a switch on what it could be
+ case ICQ_CMDxTCP_MSG: // straight message from a user
+ T("[tcp] message from %d.\n", checkUin);
+
+ packet >> theTCPSequence;
+
+ ackTCP(packet, u, newCommand, theTCPSequence);
+ addMessage(u, message, ICQ_CMDxTCP_START, ICQ_CMDxTCP_MSG, theTCPSequence, time(NULL));
+ break;
case ICQ_CMDxTCP_CHAT:
- packet >> junkShort
- >> junkChar
- >> junkLong // port backwards
- >> thePort // port to connect to for chat
- >> theTCPSequence;
-
- if (chatSequence != theTCPSequence || chatUin != checkUin) // only if this is the first chat ack packet
- { // do we do anything
- chatSequence = theTCPSequence;
- chatUin = checkUin;
-// emit eventResult(u, ICQ_CMDxTCP_CHAT, userStatus == 0x0000 ? true : false, thePort);
- }
- break;
+ T("[tcp] chat request from %d.\n", checkUin);
+
+ packet >> junkLong
+ >> junkLong
+ >> junkShort
+ >> junkChar
+ >> theTCPSequence
+ >> cicqChar
+ >> cicqVersion;
+ break;
+
+ case ICQ_CMDxTCP_URL: // url sent
+ T("[tcp] url from %d.\n", checkUin);
+
+ packet >> theTCPSequence;
+
+ ackTCP(packet, u, newCommand, theTCPSequence);
+ addUrl(u, message, ICQ_CMDxTCP_START, ICQ_CMDxTCP_URL, theTCPSequence, time(NULL));
+ break;
+
+ case ICQ_CMDxTCP_FILE:
+ unsigned int size;
+ char *fileName;
+
+ fileName = NULL;
+ packet >> junkLong
+ >> fileName
+ >> size
+ >> junkLong
+ >> theTCPSequence;
+
+ T("[tcp] file transfer request from %d (%d)\n", checkUin, theTCPSequence);
+
+ addFileReq(u, message, fileName, size, ICQ_CMDxTCP_START, ICQ_CMDxTCP_FILE, theTCPSequence, time(NULL));
+ delete[] fileName;
+ break;
+
+ case ICQ_CMDxTCP_READxAWAYxMSG: // read away message
+ case ICQ_CMDxTCP_READxOCCUPIEDxMSG:
+ case ICQ_CMDxTCP_READxNAxMSG:
+ case ICQ_CMDxTCP_READxDNDxMSG:
+ case ICQ_CMDxTCP_READxFREECHATxMSG:
+ T("[tcp] %d requested read of away message.\n", checkUin);
+
+ packet >> theTCPSequence;
+ ackTCP(packet, u, newCommand, theTCPSequence);
+ break;
+ }
+ break;
+
+ case ICQ_CMDxTCP_ACK: // message received packet
+ switch (newCommand)
+ {
+ case ICQ_CMDxTCP_MSG:
+ packet >> theTCPSequence;
+ break;
+
+ case ICQ_CMDxTCP_CHAT:
+ packet >> junkShort
+ >> junkChar
+ >> junkLong // port backwards
+ >> thePort // port to connect to for chat
+ >> theTCPSequence;
+
+ if (chatSequence != theTCPSequence || chatUin != checkUin) { // only if this is the first chat ack packet
+ chatSequence = theTCPSequence;
+ chatUin = checkUin;
+ // emit eventResult(u, ICQ_CMDxTCP_CHAT, userStatus == 0x0000 ? true : false, thePort);
+ }
+ break;
case ICQ_CMDxTCP_URL:
- packet >> theTCPSequence;
- break;
+ packet >> theTCPSequence;
+ break;
+
+ case ICQ_CMDxTCP_FILE:
+ packet >> junkLong
+ >> junkShort
+ >> junkChar
+ >> junkLong
+ >> thePort
+ >> theTCPSequence;
+
+ T("[tcp] file transfer ack from %d (%d)\n", u->uin, theTCPSequence);
+
+ ICQTransfer *t;
+ for (i = 0; i < icqTransfers.size(); i++) {
+ t = icqTransfers[i];
+ if (t->uin == checkUin && !t->socket.connected()) {
+ if (userStatus != 0) {
+ T("[tcp] file transfer denied by %d\n", checkUin);
+ ProtoBroadcastAck(protoName, t->hContact, ACKTYPE_FILE, ACKRESULT_DENIED, t, 0);
+ delete t;
+ icqTransfers[i] = icqTransfers[icqTransfers.size() - 1];
+ icqTransfers.pop_back();
+ break;
+ }
+
+ if (!t->socket.setDestination(u->socket.remoteIPVal, thePort)) {
+ T("[tcp] can't set destination\n");
+ break;
+ }
+ t->ack(ACKRESULT_CONNECTING);
+ if (openConnection(t->socket)) {
+ t->ack(ACKRESULT_CONNECTED);
+ t->sendPacket0x00();
+ }
+ break;
+ }
+ }
+ break;
+
+ case ICQ_CMDxTCP_READxAWAYxMSG:
+ case ICQ_CMDxTCP_READxOCCUPIEDxMSG:
+ case ICQ_CMDxTCP_READxNAxMSG:
+ case ICQ_CMDxTCP_READxDNDxMSG:
+ case ICQ_CMDxTCP_READxFREECHATxMSG:
+ packet >> theTCPSequence;
+ addAwayMsg(u, message, ICQ_CMDxTCP_START, ICQ_CMDxTCP_READxAWAYxMSG, theTCPSequence, time(NULL));
+ break;
+ }
+
+ // output the away message if there is one (ie if user status is not online)
+ if (userStatus == 0x0000)
+ T("[tcp] ack from %d (%d).\n", u->uin, theTCPSequence);
+ else if (userStatus == 0x0001)
+ T("[tcp] refusal from %d (%d): %s\n", u->uin, theTCPSequence, message);
+ else {
+ // u->setAwayMessage(message);
+ T("[tcp] ack from %d (%d).\n", u->uin, theTCPSequence);
+ // T("[tcp] ack from %d (%ld): %s\n", u->uin, theTCPSequence, message);
+ }
+
+ doneEvent(true, hSocket, theTCPSequence);
+ break;
+
+ case ICQ_CMDxTCP_CANCEL:
+ switch (newCommand) {
+ case ICQ_CMDxTCP_CHAT:
+ T("[tcp] chat request from %d (%d) cancelled.\n", checkUin, theTCPSequence);
+ // u->addMessage(chatReq, ICQ_CMDxTCP_CANCEL, ICQ_CMDxTCP_CHAT, 0);
+ break;
case ICQ_CMDxTCP_FILE:
- packet >> junkLong
- >> junkShort
- >> junkChar
- >> junkLong
- >> thePort
- >> theTCPSequence;
-
- T("[tcp] file transfer ack from %d (%d)\n", u->uin, theTCPSequence);
-
- ICQTransfer *t;
- for (i=0; i<icqTransfers.size(); i++)
- {
- t = icqTransfers[i];
- if (t->uin == checkUin && !t->socket.connected())
- {
- if (userStatus != 0)
- {
- T("[tcp] file transfer denied by %d\n", checkUin);
- ProtoBroadcastAck(protoName, t->hContact, ACKTYPE_FILE, ACKRESULT_DENIED, t, 0);
- delete t;
- icqTransfers[i] = icqTransfers[icqTransfers.size() - 1];
- icqTransfers.pop_back();
- break;
- }
-
- if (!t->socket.setDestination(u->socket.remoteIPVal, thePort))
- {
- T("[tcp] can't set destination\n");
- break;
- }
- t->ack(ACKRESULT_CONNECTING);
- if (openConnection(t->socket))
- {
- t->ack(ACKRESULT_CONNECTED);
- t->sendPacket0x00();
- }
- break;
- }
- }
- break;
-
- case ICQ_CMDxTCP_READxAWAYxMSG:
- case ICQ_CMDxTCP_READxOCCUPIEDxMSG:
- case ICQ_CMDxTCP_READxNAxMSG:
- case ICQ_CMDxTCP_READxDNDxMSG:
- case ICQ_CMDxTCP_READxFREECHATxMSG:
- packet >> theTCPSequence;
- addAwayMsg(u, message, ICQ_CMDxTCP_START, ICQ_CMDxTCP_READxAWAYxMSG, theTCPSequence, time(NULL));
- break;
- }
-
- // output the away message if there is one (ie if user status is not online)
- if (userStatus == 0x0000) T("[tcp] ack from %d (%d).\n", u->uin, theTCPSequence);
- else if (userStatus == 0x0001)
- {
- T("[tcp] refusal from %d (%d): %s\n", u->uin, theTCPSequence, message);
- }
- else
- {
-// u->setAwayMessage(message);
- T("[tcp] ack from %d (%d).\n", u->uin, theTCPSequence);
-// T("[tcp] ack from %d (%ld): %s\n", u->uin, theTCPSequence, message);
- }
-
- doneEvent(true, hSocket, theTCPSequence);
- break;
-
- case ICQ_CMDxTCP_CANCEL:
- switch (newCommand)
- {
- case ICQ_CMDxTCP_CHAT:
- T("[tcp] chat request from %d (%d) cancelled.\n", checkUin, theTCPSequence);
-// u->addMessage(chatReq, ICQ_CMDxTCP_CANCEL, ICQ_CMDxTCP_CHAT, 0);
- break;
-
- case ICQ_CMDxTCP_FILE:
- T("[tcp] file transfer request from %d (%d) cancelled.\n", u->uin, theTCPSequence);
-// u->addMessage(fileReq, ICQ_CMDxTCP_CANCEL, ICQ_CMDxTCP_FILE, 0);
- break;
- }
- break;
-
- default:
- T("[tcp] unknown packet:\n%s", packet.print());
- packet.reset();
- }
- delete [] message;
+ T("[tcp] file transfer request from %d (%d) cancelled.\n", u->uin, theTCPSequence);
+ // u->addMessage(fileReq, ICQ_CMDxTCP_CANCEL, ICQ_CMDxTCP_FILE, 0);
+ break;
+ }
+ break;
+
+ default:
+ T("[tcp] unknown packet:\n%s", packet.print());
+ packet.reset();
+ }
+ delete[] message;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::ackTCP(Packet &packet, ICQUser *u, unsigned short newCommand, unsigned int theSequence)
{
- unsigned int status;
-
- switch (statusVal)
- {
- case ID_STATUS_ONLINE: status = 0x00100000; break;
- case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
- case ID_STATUS_AWAY: status = 0x01100000; break;
- case ID_STATUS_NA: status = 0x00100000; break;
- case ID_STATUS_DND: status = 0x00100000; break;
- case ID_STATUS_OCCUPIED: status = 0x02100000; break;
- case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
- default: status = 0x00100000; break;
- }
-
- packet.clearPacket();
- packet << uin
- << (unsigned short)0x02
- << (unsigned short)ICQ_CMDxTCP_ACK // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
- << (unsigned short)0x00
- << uin
- << newCommand
- << awayMessage
- << u->socket.localIPVal
- << u->socket.localIPVal
- << u->socket.localPortVal
- << (unsigned char)0x04
- << status
- << theSequence;
-
- T("[tcp] sending ack (%d)\n", theSequence);
- u->socket.sendPacket(packet);
+ unsigned int status;
+
+ switch (statusVal) {
+ case ID_STATUS_ONLINE: status = 0x00100000; break;
+ case ID_STATUS_FREECHAT: status = 0x00000000; break; // ??
+ case ID_STATUS_AWAY: status = 0x01100000; break;
+ case ID_STATUS_NA: status = 0x00100000; break;
+ case ID_STATUS_DND: status = 0x00100000; break;
+ case ID_STATUS_OCCUPIED: status = 0x02100000; break;
+ case ID_STATUS_INVISIBLE: status = 0x00900000; break; // ??
+ default: status = 0x00100000; break;
+ }
+
+ packet.clearPacket();
+ packet << uin
+ << (unsigned short)0x02
+ << (unsigned short)ICQ_CMDxTCP_ACK // ICQ_CMDxTCP_ACK, ICQ_CMDxTCP_START, ICQ_CMDxTCP_CANCEL
+ << (unsigned short)0x00
+ << uin
+ << newCommand
+ << awayMessage
+ << u->socket.localIPVal
+ << u->socket.localIPVal
+ << u->socket.localPortVal
+ << (unsigned char)0x04
+ << status
+ << theSequence;
+
+ T("[tcp] sending ack (%d)\n", theSequence);
+ u->socket.sendPacket(packet);
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::recvUDP(int)
{
- Packet packet;
+ Packet packet;
- // mirabilis contacts us using udp on this server
- if (udpSocket.receivePacket(packet)) processUdpPacket(packet);
+ // mirabilis contacts us using udp on this server
+ if (udpSocket.receivePacket(packet)) processUdpPacket(packet);
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::recvNewTCP(int)
{
- ICQUser *u;
- Packet handshake;
-
- // our tcp incoming server
- TCPSocket newSocket(0);
- tcpSocket.receiveConnection(newSocket);
- newSocket.receivePacket(handshake);
-
- unsigned int ulJunk, newUin, localHost;
- unsigned short command, usJunk;
- unsigned char ucJunk;
-
- handshake >> command;
-
- if (command != ICQ_CMDxTCP_HANDSHAKE && command != ICQ_CMDxTCP_HANDSHAKE2 && command != ICQ_CMDxTCP_HANDSHAKE3)
- {
- T("[tcp] garbage packet:\n%s", handshake.print());
- handshake.reset();
- }
- else
- {
- handshake >> ulJunk
- >> usJunk
- >> ucJunk
- >> newUin
- >> localHost
- >> localHost
- >> ulJunk
- >> ucJunk;
-
- u = getUserByUIN(newUin);
- if (!u->socket.connected())
- {
- T("[tcp] connection from uin %d.\n", newUin);
- u->socket.transferConnectionFrom(newSocket);
- }
- else
- {
- unsigned int i;
- ICQTransfer *t;
-
- T("[tcp] file direct connection from uin %d.\n", newUin);
- for (i=0; i<icqTransfers.size(); i++)
- {
- t = icqTransfers[i];
- if (t->uin == newUin && !t->socket.connected()) t->socket.transferConnectionFrom(newSocket);
- }
- }
- }
+ ICQUser *u;
+ Packet handshake;
+
+ // our tcp incoming server
+ TCPSocket newSocket(0);
+ tcpSocket.receiveConnection(newSocket);
+ newSocket.receivePacket(handshake);
+
+ unsigned int ulJunk, newUin, localHost;
+ unsigned short command, usJunk;
+ unsigned char ucJunk;
+
+ handshake >> command;
+
+ if (command != ICQ_CMDxTCP_HANDSHAKE && command != ICQ_CMDxTCP_HANDSHAKE2 && command != ICQ_CMDxTCP_HANDSHAKE3) {
+ T("[tcp] garbage packet:\n%s", handshake.print());
+ handshake.reset();
+ }
+ else {
+ handshake >> ulJunk
+ >> usJunk
+ >> ucJunk
+ >> newUin
+ >> localHost
+ >> localHost
+ >> ulJunk
+ >> ucJunk;
+
+ u = getUserByUIN(newUin);
+ if (!u->socket.connected()) {
+ T("[tcp] connection from uin %d.\n", newUin);
+ u->socket.transferConnectionFrom(newSocket);
+ }
+ else {
+ unsigned int i;
+ ICQTransfer *t;
+
+ T("[tcp] file direct connection from uin %d.\n", newUin);
+ for (i = 0; i < icqTransfers.size(); i++) {
+ t = icqTransfers[i];
+ if (t->uin == newUin && !t->socket.connected())
+ t->socket.transferConnectionFrom(newSocket);
+ }
+ }
+ }
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::recvTCP(SOCKET hSocket)
{
- unsigned int i;
- Packet packet;
- ICQUser *u;
-
- for(i=0; i<icqUsers.size(); i++)
- {
- u = icqUsers[i];
- if (u->socket.handleVal == hSocket)
- {
- if (!u->socket.receivePacket(packet))
- {
- T("[tcp] connection to %d lost.\n", u->uin);
- return;
- }
- processTcpPacket(packet, hSocket);
- return;
- }
- }
+ for (size_t i = 0; i < icqUsers.size(); i++) {
+ ICQUser *u = icqUsers[i];
+ if (u->socket.handleVal == hSocket) {
+ Packet packet;
+ if (!u->socket.receivePacket(packet)) {
+ T("[tcp] connection to %d lost.\n", u->uin);
+ return;
+ }
+ processTcpPacket(packet, hSocket);
+ return;
+ }
+ }
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::recvTransferTCP(SOCKET hSocket)
{
- unsigned int i;
- Packet packet;
- ICQTransfer *transfer;
-
- for(i=0; i<icqTransfers.size(); i++)
- {
- transfer = icqTransfers[i];
- if (transfer->socket.handleVal == hSocket)
- {
- if (!transfer->socket.receivePacket(packet))
- {
-// T("[tcp] connection to %d lost.\n", s->uin);
- return;
- }
- transfer->processTcpPacket(packet);
- return;
- }
- }
+ for (size_t i = 0; i < icqTransfers.size(); i++) {
+ ICQTransfer *transfer = icqTransfers[i];
+ if (transfer->socket.handleVal == hSocket) {
+ Packet packet;
+ if (!transfer->socket.receivePacket(packet)) {
+ // T("[tcp] connection to %d lost.\n", s->uin);
+ return;
+ }
+ transfer->processTcpPacket(packet);
+ return;
+ }
+ }
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::addMessage(ICQUser *u, char *m, unsigned short theCmd, unsigned short theSubCmd, unsigned long theSequence, time_t t)
{
- CCSDATA ccs;
- PROTORECVEVENT pre;
-
- T("message: %s\n", m);
-
- ccs.hContact = u->hContact;
- ccs.szProtoService = PSR_MESSAGE;
- ccs.wParam = 0;
- ccs.lParam = (LPARAM)&pre;
- pre.flags = 0;
- pre.timestamp = t;
- pre.szMessage = (char*)m;
- pre.lParam = 0;
- Proto_ChainRecv(0, &ccs);
+ T("message: %s\n", m);
+
+ PROTORECVEVENT pre;
+ pre.flags = 0;
+ pre.timestamp = t;
+ pre.szMessage = (char*)m;
+ pre.lParam = 0;
+
+ CCSDATA ccs;
+ ccs.hContact = u->hContact;
+ ccs.szProtoService = PSR_MESSAGE;
+ ccs.wParam = 0;
+ ccs.lParam = (LPARAM)&pre;
+ Proto_ChainRecv(0, &ccs);
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::addUrl(ICQUser *u, char *m, unsigned short theCmd, unsigned short theSubCmd, unsigned long theSequence, time_t t)
{
- unsigned int i, messageLen;
- char *url;
- CCSDATA ccs;
- PROTORECVEVENT pre;
-
- messageLen = (int)mir_strlen(m);
- for (i=0; i<messageLen; i++) if (m[i] == (char)0xFE) m[i] = 0;
-
- url = new char[messageLen + 1];
- lstrcpy(url, m + mir_strlen(m) + 1);
- lstrcpy(url + mir_strlen(url) + 1, m);
-
- ccs.hContact = u->hContact;
- ccs.szProtoService = PSR_URL;
- ccs.wParam = 0;
- ccs.lParam = (LPARAM)&pre;
- pre.flags = 0;
- pre.timestamp = t;
- pre.szMessage = url;
- pre.lParam = 0;
- Proto_ChainRecv(0, &ccs);
-
- delete [] url;
+ unsigned int i, messageLen;
+ char *url;
+
+ messageLen = (int)mir_strlen(m);
+ for (i = 0; i < messageLen; i++)
+ if (m[i] == (char)0xFE)
+ m[i] = 0;
+
+ url = new char[messageLen + 1];
+ lstrcpy(url, m + mir_strlen(m) + 1);
+ lstrcpy(url + mir_strlen(url) + 1, m);
+
+ PROTORECVEVENT pre;
+ pre.flags = 0;
+ pre.timestamp = t;
+ pre.szMessage = url;
+ pre.lParam = 0;
+
+ CCSDATA ccs;
+ ccs.hContact = u->hContact;
+ ccs.szProtoService = PSR_URL;
+ ccs.wParam = 0;
+ ccs.lParam = (LPARAM)&pre;
+ Proto_ChainRecv(0, &ccs);
+
+ delete[] url;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::addAwayMsg(ICQUser *u, char *m, unsigned short theCmd, unsigned short theSubCmd, unsigned long theSequence, time_t t)
{
- CCSDATA ccs;
- PROTORECVEVENT pre;
-
- T("away msg: %s\n", m);
-
- ccs.hContact = u->hContact;
- ccs.szProtoService = PSR_AWAYMSG;
- ccs.wParam = u->statusVal;
- ccs.lParam = (LPARAM)&pre;
- pre.flags = 0;
- pre.timestamp = t;
- pre.szMessage = (char*)m;
- pre.lParam = theSequence;
- Proto_ChainRecv(0, &ccs);
+ T("away msg: %s\n", m);
+
+ PROTORECVEVENT pre;
+ pre.flags = 0;
+ pre.timestamp = t;
+ pre.szMessage = (char*)m;
+ pre.lParam = theSequence;
+
+ CCSDATA ccs;
+ ccs.hContact = u->hContact;
+ ccs.szProtoService = PSR_AWAYMSG;
+ ccs.wParam = u->statusVal;
+ ccs.lParam = (LPARAM)&pre;
+ Proto_ChainRecv(0, &ccs);
}
///////////////////////////////////////////////////////////////////////////////
/*
void ICQ::addAdded(ICQUser *u, char *m, unsigned short theCmd, unsigned short theSubCmd, unsigned long theSequence, time_t t)
{
- DBEVENTINFO dbei;
- PBYTE pCurBlob;
-
- //blob is: uin(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ)
- ZeroMemory(&dbei, sizeof(dbei));
- dbei.cbSize=sizeof(dbei);
- dbei.szModule="ICQ";
- dbei.timestamp=TimestampLocalToGMT(YMDHMSToTime(year,month,day,hour,minute,0));
- dbei.flags=0;
- dbei.eventType=EVENTTYPE_ADDED;
- dbei.cbBlob=sizeof(DWORD)+mir_strlen(nick)+mir_strlen(first)+mir_strlen(last)+mir_strlen(email)+4;
- pCurBlob=dbei.pBlob=(PBYTE)malloc(dbei.cbBlob);
- CopyMemory(pCurBlob,&uin,sizeof(DWORD)); pCurBlob+=sizeof(DWORD);
- CopyMemory(pCurBlob,nick,mir_strlen(nick)+1); pCurBlob+=mir_strlen(nick)+1;
- CopyMemory(pCurBlob,first,mir_strlen(first)+1); pCurBlob+=mir_strlen(first)+1;
- CopyMemory(pCurBlob,last,mir_strlen(last)+1); pCurBlob+=mir_strlen(last)+1;
- CopyMemory(pCurBlob,email,mir_strlen(email)+1); pCurBlob+=mir_strlen(email)+1;
- CallService(MS_DB_EVENT_ADD,(WPARAM)(HANDLE)NULL,(LPARAM)&dbei);
+ DBEVENTINFO dbei;
+ PBYTE pCurBlob;
+
+ //blob is: uin(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ)
+ ZeroMemory(&dbei, sizeof(dbei));
+ dbei.cbSize=sizeof(dbei);
+ dbei.szModule="ICQ";
+ dbei.timestamp=TimestampLocalToGMT(YMDHMSToTime(year,month,day,hour,minute,0));
+ dbei.flags=0;
+ dbei.eventType=EVENTTYPE_ADDED;
+ dbei.cbBlob=sizeof(DWORD)+mir_strlen(nick)+mir_strlen(first)+mir_strlen(last)+mir_strlen(email)+4;
+ pCurBlob=dbei.pBlob=(PBYTE)malloc(dbei.cbBlob);
+ CopyMemory(pCurBlob,&uin,sizeof(DWORD)); pCurBlob+=sizeof(DWORD);
+ CopyMemory(pCurBlob,nick,mir_strlen(nick)+1); pCurBlob+=mir_strlen(nick)+1;
+ CopyMemory(pCurBlob,first,mir_strlen(first)+1); pCurBlob+=mir_strlen(first)+1;
+ CopyMemory(pCurBlob,last,mir_strlen(last)+1); pCurBlob+=mir_strlen(last)+1;
+ CopyMemory(pCurBlob,email,mir_strlen(email)+1); pCurBlob+=mir_strlen(email)+1;
+ CallService(MS_DB_EVENT_ADD,(WPARAM)(HANDLE)NULL,(LPARAM)&dbei);
}
*/
///////////////////////////////////////////////////////////////////////////////
void ICQ::addFileReq(ICQUser *u, char *m, char *filename, unsigned long size, unsigned short theCmd, unsigned short theSubCmd, unsigned long theSequence, time_t t)
{
- CCSDATA ccs;
- PROTORECVEVENT pre;
- char *szBlob;
-/*
- filetransfer *ft;
-
- // Initialize a filetransfer struct
- ft = new filetransfer;
- memset(ft, 0, sizeof(filetransfer));
- ft->status = 0;
- ft->wCookie = wCookie;
- ft->szFilename = _strdup(fileName);
- ft->szDescription = _strdup(m);
- ft->dwUin = u->uin;
- ft->fileId = -1;
- ft->dwTotalSize = size;
- ft->nVersion = nVersion;
- ft->TS1 = dwID1;
- ft->TS2 = dwID2;
-*/
- ICQTransfer *transfer = new ICQTransfer(u, theSequence);
- transfer->description = _strdup(m);
- transfer->totalSize = size;
-
- icqTransfers.push_back(transfer);
-
-
-
- // Send chain event
- szBlob = new char[sizeof(DWORD) + mir_strlen(filename) + mir_strlen(m) + 2];
-
- *(PDWORD)szBlob = (UINT_PTR)transfer;
- mir_strcpy(szBlob + sizeof(DWORD), filename);
- mir_strcpy(szBlob + sizeof(DWORD) + mir_strlen(filename) + 1, m);
-
- ccs.hContact = u->hContact;
- ccs.szProtoService = PSR_FILE;
- ccs.wParam = 0;
- ccs.lParam = (LPARAM)&pre;
- pre.flags = 0;
- pre.timestamp = t;
- pre.szMessage = szBlob;
- pre.lParam = theSequence;
- Proto_ChainRecv(0, &ccs);
-
- delete [] szBlob;
-
+ char *szBlob;
+ /*
+ filetransfer *ft;
+
+ // Initialize a filetransfer struct
+ ft = new filetransfer;
+ memset(ft, 0, sizeof(filetransfer));
+ ft->status = 0;
+ ft->wCookie = wCookie;
+ ft->szFilename = _strdup(fileName);
+ ft->szDescription = _strdup(m);
+ ft->dwUin = u->uin;
+ ft->fileId = -1;
+ ft->dwTotalSize = size;
+ ft->nVersion = nVersion;
+ ft->TS1 = dwID1;
+ ft->TS2 = dwID2;
+ */
+ ICQTransfer *transfer = new ICQTransfer(u, theSequence);
+ transfer->description = _strdup(m);
+ transfer->totalSize = size;
+
+ icqTransfers.push_back(transfer);
+
+
+
+ // Send chain event
+ szBlob = new char[sizeof(DWORD) + mir_strlen(filename) + mir_strlen(m) + 2];
+
+ *(PDWORD)szBlob = (UINT_PTR)transfer;
+ mir_strcpy(szBlob + sizeof(DWORD), filename);
+ mir_strcpy(szBlob + sizeof(DWORD) + mir_strlen(filename) + 1, m);
+
+ PROTORECVEVENT pre;
+ pre.flags = 0;
+ pre.timestamp = t;
+ pre.szMessage = szBlob;
+ pre.lParam = theSequence;
+
+ CCSDATA ccs;
+ ccs.hContact = u->hContact;
+ ccs.szProtoService = PSR_FILE;
+ ccs.wParam = 0;
+ ccs.lParam = (LPARAM)&pre;
+ Proto_ChainRecv(0, &ccs);
+
+ delete[] szBlob;
}
///////////////////////////////////////////////////////////////////////////////
void ICQ::doneUserFcn(bool ack, ICQEvent *icqEvent)
{
- unsigned int type = 0;
+ unsigned int type = 0;
- if (icqEvent->subCmd == ICQ_CMDxTCP_MSG) type = ACKTYPE_MESSAGE;
- if (icqEvent->subCmd == ICQ_CMDxTCP_URL) type = ACKTYPE_URL;
+ if (icqEvent->subCmd == ICQ_CMDxTCP_MSG)
+ type = ACKTYPE_MESSAGE;
+ if (icqEvent->subCmd == ICQ_CMDxTCP_URL)
+ type = ACKTYPE_URL;
- ProtoBroadcastAck(protoName, getUserByUIN(icqEvent->uin)->hContact, type, ack ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)icqEvent->sequence, 0);
+ ProtoBroadcastAck(protoName, getUserByUIN(icqEvent->uin)->hContact, type, ack ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)icqEvent->sequence, 0);
}
-
-///////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/ICQCorp/src/services.cpp b/protocols/ICQCorp/src/services.cpp
index db8aa0e0c4..1d84255ed6 100644
--- a/protocols/ICQCorp/src/services.cpp
+++ b/protocols/ICQCorp/src/services.cpp
@@ -72,16 +72,21 @@ static INT_PTR icqSetStatus(WPARAM wParam, LPARAM)
T("[ ] set status\n");
// on change status to online set away msg not calling
- if (desiredStatus == ID_STATUS_ONLINE) icq.awayMessage[0] = 0;
+ if (desiredStatus == ID_STATUS_ONLINE)
+ icq.awayMessage[0] = 0;
- if (icq.desiredStatus == desiredStatus) return 0;
+ if (icq.desiredStatus == desiredStatus)
+ return 0;
+
if (desiredStatus == ID_STATUS_OFFLINE) {
icq.desiredStatus = desiredStatus;
icq.logoff(false);
}
else {
- if (icq.statusVal == ID_STATUS_OFFLINE) icq.logon(desiredStatus);
- else icq.setStatus(desiredStatus);
+ if (icq.statusVal == ID_STATUS_OFFLINE)
+ icq.logon(desiredStatus);
+ else
+ icq.setStatus(desiredStatus);
}
return 0;
}
@@ -144,21 +149,23 @@ static INT_PTR icqAddToList(WPARAM wParam, LPARAM lParam)
bool persistent = (wParam & PALF_TEMPORARY) == 0;
T("[ ] add user to list\n");
- if (isr->hdr.cbSize != sizeof(ICQSEARCHRESULT) || isr->uin == icq.uin) return NULL;
- return (int)icq.addUser(isr->uin, persistent)->hContact;
+
+ if (isr->hdr.cbSize != sizeof(ICQSEARCHRESULT) || isr->uin == icq.uin)
+ return NULL;
+
+ return icq.addUser(isr->uin, persistent)->hContact;
}
///////////////////////////////////////////////////////////////////////////////
static INT_PTR icqGetInfo(WPARAM, LPARAM lParam)
{
- CCSDATA *ccs = (CCSDATA *)lParam;
- ICQUser *u;
-
T("[ ] get user info\n");
- u = icq.getUserByContact(ccs->hContact);
- if (u == NULL || icq.statusVal <= ID_STATUS_OFFLINE) return 1;
+ CCSDATA *ccs = (CCSDATA *)lParam;
+ ICQUser *u = icq.getUserByContact(ccs->hContact);
+ if (u == NULL || icq.statusVal <= ID_STATUS_OFFLINE)
+ return 1;
icq.getUserInfo(u, ccs->wParam & SGIF_MINIMAL);
return 0;
@@ -168,17 +175,15 @@ static INT_PTR icqGetInfo(WPARAM, LPARAM lParam)
static INT_PTR icqSendMessage(WPARAM, LPARAM lParam)
{
- CCSDATA *ccs = (CCSDATA *)lParam;
- ICQUser *u;
- ICQEvent *icqEvent;
-
T("[ ] send message\n");
- u = icq.getUserByContact(ccs->hContact);
+ CCSDATA *ccs = (CCSDATA *)lParam;
+ ICQUser *u = icq.getUserByContact(ccs->hContact);
// uin = db_get_dw(ccs->hContact, ICQCORP_PROTONAME, "UIN", 0);
- if (u == NULL || icq.statusVal <= ID_STATUS_OFFLINE) return 0;
+ if (u == NULL || icq.statusVal <= ID_STATUS_OFFLINE)
+ return 0;
- icqEvent = icq.sendMessage(u, ptrA(mir_utf8decodeA((char*)ccs->lParam)));
+ ICQEvent *icqEvent = icq.sendMessage(u, ptrA(mir_utf8decodeA((char*)ccs->lParam)));
return icqEvent ? icqEvent->sequence : 0;
}
@@ -186,14 +191,14 @@ static INT_PTR icqSendMessage(WPARAM, LPARAM lParam)
static INT_PTR icqRecvMessage(WPARAM, LPARAM lParam)
{
- DBEVENTINFO dbei;
CCSDATA *ccs = (CCSDATA*)lParam;
PROTORECVEVENT *pre = (PROTORECVEVENT*)ccs->lParam;
T("[ ] recieve message\n");
db_unset(ccs->hContact, "CList", "Hidden");
- ZeroMemory(&dbei, sizeof(dbei));
+
+ DBEVENTINFO dbei = { 0 };
dbei.cbSize = sizeof(dbei);
dbei.szModule = protoName;
dbei.timestamp = pre->timestamp;
diff --git a/protocols/ICQCorp/src/socket.cpp b/protocols/ICQCorp/src/socket.cpp
index b3516f2069..eae8642411 100644
--- a/protocols/ICQCorp/src/socket.cpp
+++ b/protocols/ICQCorp/src/socket.cpp
@@ -20,181 +20,179 @@
#include "corp.h"
///////////////////////////////////////////////////////////////////////////////
-//
// Socket
-//
///////////////////////////////////////////////////////////////////////////////
Socket::Socket()
{
- handleVal = INVALID_SOCKET;
- remoteIPVal = 0;
- remotePortVal = 0;
- localIPVal = 0;
- localPortVal = 0;
- messageVal = 0;
+ handleVal = INVALID_SOCKET;
+ remoteIPVal = 0;
+ remotePortVal = 0;
+ localIPVal = 0;
+ localPortVal = 0;
+ messageVal = 0;
}
///////////////////////////////////////////////////////////////////////////////
Socket::~Socket()
{
- if (connected()) closeConnection();
+ if (connected()) closeConnection();
}
///////////////////////////////////////////////////////////////////////////////
bool Socket::connected()
{
- return handleVal != INVALID_SOCKET;
+ return handleVal != INVALID_SOCKET;
};
///////////////////////////////////////////////////////////////////////////////
bool Socket::completed(int result)
{
- if (result != SOCKET_ERROR || WSAGetLastError() != WSAEWOULDBLOCK) return true;
+ if (result != SOCKET_ERROR || WSAGetLastError() != WSAEWOULDBLOCK)
+ return true;
- Sleep(1);
- return false;
+ Sleep(1);
+ return false;
};
///////////////////////////////////////////////////////////////////////////////
void Socket::openSocket()
{
- if (connected()) WSAAsyncSelect(handleVal, icq.hWnd, messageVal, FD_READ|FD_ACCEPT|FD_CONNECT|FD_CLOSE);
+ if (connected())
+ WSAAsyncSelect(handleVal, icq.hWnd, messageVal, FD_READ | FD_ACCEPT | FD_CONNECT | FD_CLOSE);
}
///////////////////////////////////////////////////////////////////////////////
void Socket::closeSocket()
{
- if (connected()) WSAAsyncSelect(handleVal, icq.hWnd, 0, 0);
+ if (connected())
+ WSAAsyncSelect(handleVal, icq.hWnd, 0, 0);
}
///////////////////////////////////////////////////////////////////////////////
bool Socket::setDestination(unsigned long rIp, unsigned short rPort)
{
- char localName[128];
-
- if (rIp == 0) return false;
- gethostname(localName, 128);
- localIPVal = lookup(localName);
-
- // set up remote connection
- remoteIPVal = rIp;
- remotePortVal = rPort;
- remote.sin_port = htons(rPort);
- remote.sin_addr.s_addr = rIp;
- return true;
+ if (rIp == 0)
+ return false;
+
+ char localName[128];
+ gethostname(localName, 128);
+ localIPVal = lookup(localName);
+
+ // set up remote connection
+ remoteIPVal = rIp;
+ remotePortVal = rPort;
+ remote.sin_port = htons(rPort);
+ remote.sin_addr.s_addr = rIp;
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
bool Socket::setDestination(char *rHost, unsigned short rPort)
{
- return setDestination(lookup(rHost), rPort);
+ return setDestination(lookup(rHost), rPort);
};
///////////////////////////////////////////////////////////////////////////////
unsigned long Socket::lookup(char *h)
{
- unsigned long ina;
- struct hostent *host;
-
- // check if the hostname is in dot and number notation
- ina = inet_addr(h);
- if (ina != INADDR_NONE) return ina;
-
- // try and resolve hostname
- if ((host = gethostbyname(h)) == NULL) return 0; // Couldn't resolve hostname/ip
-
- // return the ip
- return *((unsigned long *)host->h_addr);
+ // check if the hostname is in dot and number notation
+ unsigned long ina = inet_addr(h);
+ if (ina != INADDR_NONE)
+ return ina;
+
+ // try and resolve hostname
+ struct hostent *host = gethostbyname(h);
+ if (host == NULL) // Couldn't resolve hostname/ip
+ return 0;
+
+ // return the ip
+ return *((unsigned long *)host->h_addr);
}
///////////////////////////////////////////////////////////////////////////////
bool Socket::openConnection(int Type)
-{
- struct sockaddr_in local;
-
- handleVal = socket(AF_INET, Type, 0);
- if (handleVal == INVALID_SOCKET) return false;
+{
+ handleVal = socket(AF_INET, Type, 0);
+ if (handleVal == INVALID_SOCKET)
+ return false;
- memset(&local.sin_zero, 0, 8);
- local.sin_family = AF_INET;
- local.sin_port = htons(localPortVal);
- local.sin_addr.s_addr = htonl(INADDR_ANY);
-// local.sin_addr.s_addr = htonl(localIPVal);
+ struct sockaddr_in local;
+ memset(&local.sin_zero, 0, 8);
+ local.sin_family = AF_INET;
+ local.sin_port = htons(localPortVal);
+ local.sin_addr.s_addr = htonl(INADDR_ANY);
+ // local.sin_addr.s_addr = htonl(localIPVal);
- memset(&remote.sin_zero, 0, 8);
- remote.sin_family = AF_INET;
+ memset(&remote.sin_zero, 0, 8);
+ remote.sin_family = AF_INET;
- bind(handleVal, (sockaddr*)&local, sizeof(sockaddr));
+ bind(handleVal, (sockaddr*)&local, sizeof(sockaddr));
- int sizeofSockaddr = sizeof(sockaddr);
- getsockname(handleVal, (sockaddr*)&local, &sizeofSockaddr);
- localPortVal = ntohs(local.sin_port);
- if (local.sin_addr.s_addr) localIPVal = ntohl(local.sin_addr.s_addr);
+ int sizeofSockaddr = sizeof(sockaddr);
+ getsockname(handleVal, (sockaddr*)&local, &sizeofSockaddr);
+ localPortVal = ntohs(local.sin_port);
+ if (local.sin_addr.s_addr)
+ localIPVal = ntohl(local.sin_addr.s_addr);
- return true;
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
void Socket::closeConnection()
{
- if (connected())
- {
- closeSocket();
- shutdown(handleVal, SD_BOTH);
- closesocket(handleVal);
- handleVal = INVALID_SOCKET;
- }
+ if (connected()) {
+ closeSocket();
+ shutdown(handleVal, SD_BOTH);
+ closesocket(handleVal);
+ handleVal = INVALID_SOCKET;
+ }
}
///////////////////////////////////////////////////////////////////////////////
bool Socket::sendBuffer(char *buffer, unsigned int bufferSize)
{
- int result;
-
- while (bufferSize > 0)
- {
- while (! completed(result = send(handleVal, buffer, bufferSize, 0)));
- if (result <= 0)
- {
- closeConnection();
- return false;
- }
- buffer += result;
- bufferSize -= result;
- }
- return true;
+ int result;
+
+ while (bufferSize > 0) {
+ while (!completed(result = send(handleVal, buffer, bufferSize, 0)));
+ if (result <= 0) {
+ closeConnection();
+ return false;
+ }
+ buffer += result;
+ bufferSize -= result;
+ }
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
bool Socket::receiveBuffer(char *buffer, unsigned int bufferSize)
{
- int result;
-
- while (bufferSize > 0)
- {
- while (! completed(result = recv(handleVal, buffer, bufferSize, 0)));
- if (result <= 0)
- {
- closeConnection();
- return false;
- }
- buffer += result;
- bufferSize -= result;
- }
- return true;
+ int result;
+
+ while (bufferSize > 0) {
+ while (!completed(result = recv(handleVal, buffer, bufferSize, 0)));
+ if (result <= 0) {
+ closeConnection();
+ return false;
+ }
+ buffer += result;
+ bufferSize -= result;
+ }
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
@@ -205,123 +203,127 @@ bool Socket::receiveBuffer(char *buffer, unsigned int bufferSize)
TCPSocket::TCPSocket(unsigned int msg)
{
- messageVal = msg;
+ messageVal = msg;
}
///////////////////////////////////////////////////////////////////////////////
bool TCPSocket::openConnection()
{
- int result;
-
- if (remoteIPVal == 0) return false;
- if (! Socket::openConnection(SOCK_STREAM)) return false;
-
- result = connect(handleVal, (sockaddr*)&remote, sizeof(sockaddr));
- if (result == SOCKET_ERROR)
- {
- closeConnection();
- return false;
- }
- openSocket();
- return true;
+ if (remoteIPVal == 0)
+ return false;
+ if (!Socket::openConnection(SOCK_STREAM))
+ return false;
+
+ int result = connect(handleVal, (sockaddr*)&remote, sizeof(sockaddr));
+ if (result == SOCKET_ERROR) {
+ closeConnection();
+ return false;
+ }
+ openSocket();
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
void TCPSocket::receiveConnection(TCPSocket &newSocket)
{
- int sizeofSockaddr = sizeof(sockaddr);
- newSocket.handleVal = accept(handleVal, (sockaddr*)&remote, &sizeofSockaddr);
- newSocket.openSocket();
+ int sizeofSockaddr = sizeof(sockaddr);
+ newSocket.handleVal = accept(handleVal, (sockaddr*)&remote, &sizeofSockaddr);
+ newSocket.openSocket();
- sizeofSockaddr = sizeof(sockaddr);
- getpeername(newSocket.handleVal, (sockaddr*)&newSocket.remote, &sizeofSockaddr);
+ sizeofSockaddr = sizeof(sockaddr);
+ getpeername(newSocket.handleVal, (sockaddr*)&newSocket.remote, &sizeofSockaddr);
- newSocket.remoteIPVal = newSocket.remote.sin_addr.s_addr;
- newSocket.remotePortVal = ntohs(newSocket.remote.sin_port);
+ newSocket.remoteIPVal = newSocket.remote.sin_addr.s_addr;
+ newSocket.remotePortVal = ntohs(newSocket.remote.sin_port);
- newSocket.localIPVal = localIPVal;
- newSocket.localPortVal = localPortVal;
+ newSocket.localIPVal = localIPVal;
+ newSocket.localPortVal = localPortVal;
}
///////////////////////////////////////////////////////////////////////////////
bool TCPSocket::startServer()
{
- if (! Socket::openConnection(SOCK_STREAM)) return false;
- listen(handleVal, 10);
- openSocket();
- return true;
-}
+ if (!Socket::openConnection(SOCK_STREAM)) return false;
+ listen(handleVal, 10);
+ openSocket();
+ return true;
+}
///////////////////////////////////////////////////////////////////////////////
void TCPSocket::transferConnectionFrom(TCPSocket &from)
{
- handleVal = from.handleVal;
- remoteIPVal = from.remoteIPVal;
- remotePortVal = from.remotePortVal;
- localIPVal = from.localIPVal;
- localPortVal = from.localPortVal;
-
- from.closeSocket();
- from.handleVal = INVALID_SOCKET;
- openSocket();
+ handleVal = from.handleVal;
+ remoteIPVal = from.remoteIPVal;
+ remotePortVal = from.remotePortVal;
+ localIPVal = from.localIPVal;
+ localPortVal = from.localPortVal;
+
+ from.closeSocket();
+ from.handleVal = INVALID_SOCKET;
+ openSocket();
}
///////////////////////////////////////////////////////////////////////////////
bool TCPSocket::sendPacket(Packet &p)
{
- return sendPacket(p, true);
+ return sendPacket(p, true);
}
///////////////////////////////////////////////////////////////////////////////
bool TCPSocket::receivePacket(Packet &p)
{
- return receivePacket(p, true);
+ return receivePacket(p, true);
}
///////////////////////////////////////////////////////////////////////////////
bool TCPSocket::sendPacket(Packet &p, bool sendSize)
{
- if (! connected()) return false;
- if (sendSize)
- {
- char pSize[2];
-
- pSize[0] = (p.sizeVal) & 0xFF;
- pSize[1] = (p.sizeVal >> 8) & 0xFF;
-
- if (! sendBuffer(pSize, 2)) return false;
- }
- return sendBuffer(p.buff, p.sizeVal);
+ if (!connected())
+ return false;
+
+ if (sendSize) {
+ char pSize[2];
+
+ pSize[0] = (p.sizeVal) & 0xFF;
+ pSize[1] = (p.sizeVal >> 8) & 0xFF;
+
+ if (!sendBuffer(pSize, 2))
+ return false;
+ }
+ return sendBuffer(p.buff, p.sizeVal);
}
///////////////////////////////////////////////////////////////////////////////
bool TCPSocket::receivePacket(Packet &p, bool recvSize)
{
- unsigned short sizeVal;
-
- if (! connected()) return false;
- WSAAsyncSelect(handleVal, icq.hWnd, messageVal, FD_ACCEPT|FD_CONNECT|FD_CLOSE);
-
- p.clearPacket();
- if (recvSize)
- {
- if (!receiveBuffer((char*)&sizeVal, 2) || sizeVal > p.maxSize) return false;
- }
- else sizeVal = 1;
-
- if (! receiveBuffer(p.buff, sizeVal)) return false;
- p.sizeVal = sizeVal;
-
- WSAAsyncSelect(handleVal, icq.hWnd, messageVal, FD_READ|FD_ACCEPT|FD_CONNECT|FD_CLOSE);
- return true;
+ if (!connected())
+ return false;
+
+ WSAAsyncSelect(handleVal, icq.hWnd, messageVal, FD_ACCEPT | FD_CONNECT | FD_CLOSE);
+
+ p.clearPacket();
+
+ unsigned short sizeVal;
+ if (recvSize) {
+ if (!receiveBuffer((char*)&sizeVal, 2) || sizeVal > p.maxSize)
+ return false;
+ }
+ else sizeVal = 1;
+
+ if (!receiveBuffer(p.buff, sizeVal))
+ return false;
+
+ p.sizeVal = sizeVal;
+ WSAAsyncSelect(handleVal, icq.hWnd, messageVal, FD_READ | FD_ACCEPT | FD_CONNECT | FD_CLOSE);
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
@@ -332,68 +334,71 @@ bool TCPSocket::receivePacket(Packet &p, bool recvSize)
UDPSocket::UDPSocket(unsigned int msg)
{
- messageVal = msg;
+ messageVal = msg;
}
///////////////////////////////////////////////////////////////////////////////
bool UDPSocket::openConnection()
-{
- if (remoteIPVal == 0) return false;
- if (! Socket::openConnection(SOCK_DGRAM)) return false;
- openSocket();
- return true;
+{
+ if (remoteIPVal == 0)
+ return false;
+ if (!Socket::openConnection(SOCK_DGRAM))
+ return false;
+
+ openSocket();
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
bool UDPSocket::startServer()
{
- if (! Socket::openConnection(SOCK_DGRAM)) return false;
- openSocket();
- return true;
-}
+ if (!Socket::openConnection(SOCK_DGRAM))
+ return false;
+
+ openSocket();
+ return true;
+}
///////////////////////////////////////////////////////////////////////////////
bool UDPSocket::sendPacket(Packet &p)
{
- if (! connected()) return false;
+ if (!connected())
+ return false;
- unsigned int bytesSent = 0;
- bytesSent = sendto(handleVal, p.buff, p.sizeVal, 0, (sockaddr*)&remote, sizeof(sockaddr));
+ unsigned int bytesSent = 0;
+ bytesSent = sendto(handleVal, p.buff, p.sizeVal, 0, (sockaddr*)&remote, sizeof(sockaddr));
- // if unable to send anything
- if (bytesSent != p.sizeVal)
- {
- closeConnection();
- return false;
- }
+ // if unable to send anything
+ if (bytesSent != p.sizeVal) {
+ closeConnection();
+ return false;
+ }
- return true;
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
bool UDPSocket::receivePacket(Packet &p)
{
- if (! connected()) return false;
+ if (!connected())
+ return false;
- int sizeofSockaddr = sizeof(sockaddr);
- p.clearPacket();
- p.sizeVal = recvfrom(handleVal, p.buff, p.maxSize, 0, (sockaddr*)&remote, &sizeofSockaddr);
+ int sizeofSockaddr = sizeof(sockaddr);
+ p.clearPacket();
+ p.sizeVal = recvfrom(handleVal, p.buff, p.maxSize, 0, (sockaddr*)&remote, &sizeofSockaddr);
- // it didn't manage to receive anything, there was an error, close the socket and return false
- if (int(p.sizeVal) <= 0)
- {
- closeConnection();
- return false;
- }
+ // it didn't manage to receive anything, there was an error, close the socket and return false
+ if (int(p.sizeVal) <= 0) {
+ closeConnection();
+ return false;
+ }
- // make sure the size won't overflow the buffer
- if (p.sizeVal > p.maxSize) p.sizeVal = p.maxSize - sizeof(unsigned long);
+ // make sure the size won't overflow the buffer
+ if (p.sizeVal > p.maxSize) p.sizeVal = p.maxSize - sizeof(unsigned long);
- return true;
+ return true;
}
-
-///////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/ICQCorp/src/transfer.cpp b/protocols/ICQCorp/src/transfer.cpp
index 4f1f039dfa..a6c6b992e6 100644
--- a/protocols/ICQCorp/src/transfer.cpp
+++ b/protocols/ICQCorp/src/transfer.cpp
@@ -1,21 +1,21 @@
/*
- ICQ Corporate protocol plugin for Miranda IM.
- Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>
+ ICQ Corporate protocol plugin for Miranda IM.
+ Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include "corp.h"
@@ -25,481 +25,457 @@ std::vector <ICQTransfer *> icqTransfers;
void WINAPI transferTimerProc(HWND, UINT, UINT_PTR hTimer, DWORD)
{
- unsigned int i;
+ KillTimer(NULL, hTimer);
- KillTimer(NULL, hTimer);
- for (i=0; i<icqTransfers.size(); i++) if (hTimer == icqTransfers[i]->hTimer) icqTransfers[i]->process();
+ for (size_t i = 0; i < icqTransfers.size(); i++)
+ if (hTimer == icqTransfers[i]->hTimer)
+ icqTransfers[i]->process();
}
///////////////////////////////////////////////////////////////////////////////
ICQTransfer::ICQTransfer(ICQUser *u, unsigned int theSequence) :
- socket(WM_NETEVENT_TRANSFER)
+ socket(WM_NETEVENT_TRANSFER)
{
- uin = u->uin;
- hContact = u->hContact;
- sequence = theSequence;
- files = NULL;
- description = NULL;
- path = NULL;
- sending = 0;
- speed = 100;
- count = 0;
- current = -1;
- fileName = NULL;
- fileSize = 0;
- fileProgress = 0;
- totalSize = 0;
- totalProgress = 0;
- lastNotify = 0;
- hTimer = NULL;
- hFile = INVALID_HANDLE_VALUE;
+ uin = u->uin;
+ hContact = u->hContact;
+ sequence = theSequence;
+ files = NULL;
+ description = NULL;
+ path = NULL;
+ sending = 0;
+ speed = 100;
+ count = 0;
+ current = -1;
+ fileName = NULL;
+ fileSize = 0;
+ fileProgress = 0;
+ totalSize = 0;
+ totalProgress = 0;
+ lastNotify = 0;
+ hTimer = NULL;
+ hFile = INVALID_HANDLE_VALUE;
}
///////////////////////////////////////////////////////////////////////////////
ICQTransfer::~ICQTransfer()
{
- closeFile();
+ closeFile();
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::processTcpPacket(Packet &packet)
{
- unsigned int /*i,*/ status, junkLong;
- //unsigned short junkShort;
- unsigned char cmd/*, junkChar*/;
- char *name = NULL, *directoryName = NULL;
-
- packet >> cmd;
- switch (cmd)
- {
- case 0x00:
- T("[tcp] recieve initialising file transfer\n");
- packet >> junkLong
- >> count
- >> totalSize
- >> speed
- >> name;
-
- files = new char*[count + 1];
- ZeroMemory(files, (count+1)*sizeof(char*));
-
- ack(ACKRESULT_INITIALISING);
- sendPacket0x01();
- break;
-
- case 0x01:
- T("[tcp] ack initialising\n");
- packet >> speed
- >> name;
-
- ack(ACKRESULT_INITIALISING);
- sendPacket0x02();
- break;
-
- case 0x02:
- T("[tcp] recieve next file\n");
- packet >> directory
- >> files[++current]
- >> directoryName
- >> fileSize
- >> fileDate
- >> speed;
-
- if (directoryName[0])
- {
- char *fullName = new char[mir_strlen(directoryName) + mir_strlen(files[current]) + 2];
- sprintf(fullName, "%s\\%s", directoryName, files[current]);
- delete [] files[current];
- files[current] = fullName;
- }
-
- if (directory) createDirectory();
- else openFile();
- ack(ACKRESULT_NEXTFILE);
-
- if (fileProgress) ack(ACKRESULT_FILERESUME);
- else sendPacket0x03();
- break;
-
- case 0x03:
- T("[tcp] ack next file\n");
- packet >> fileProgress
- >> status
- >> speed;
-
- totalProgress += fileProgress;
- setFilePosition();
- ack(ACKRESULT_NEXTFILE);
-
- if (status != 0)
- {
- totalProgress += fileSize - fileProgress;
- fileProgress = fileSize;
- closeFile();
- ack(ACKRESULT_DATA);
- }
-
- process();
- break;
-
- case 0x04:
- T("[tcp] recieve stop file\n");
- packet >> junkLong;
-
- totalProgress += fileSize - fileProgress;
- fileProgress = fileSize;
- closeFile();
- ack(ACKRESULT_DATA);
- break;
-
- case 0x05:
- T("[tcp] recieve new speed\n");
- packet >> speed;
- break;
-
- case 0x06:
- unsigned long result;
-
- WriteFile(hFile, packet.data(), packet.dataSize(), &result, NULL);
-
- fileProgress += result;
- totalProgress += result;
-
- if (fileProgress >= fileSize) closeFile();
- ack(ACKRESULT_DATA);
- break;
-
- default:
- T("[tcp] unknown packet:\n%s", packet.print());
- packet.reset();
- }
-
- delete [] directoryName;
- delete [] name;
+ unsigned int /*i,*/ status, junkLong;
+ unsigned char cmd/*, junkChar*/;
+ char *name = NULL, *directoryName = NULL;
+
+ packet >> cmd;
+ switch (cmd) {
+ case 0x00:
+ T("[tcp] recieve initialising file transfer\n");
+ packet >> junkLong
+ >> count
+ >> totalSize
+ >> speed
+ >> name;
+
+ files = new char*[count + 1];
+ ZeroMemory(files, (count + 1)*sizeof(char*));
+
+ ack(ACKRESULT_INITIALISING);
+ sendPacket0x01();
+ break;
+
+ case 0x01:
+ T("[tcp] ack initialising\n");
+ packet >> speed
+ >> name;
+
+ ack(ACKRESULT_INITIALISING);
+ sendPacket0x02();
+ break;
+
+ case 0x02:
+ T("[tcp] recieve next file\n");
+ packet >> directory
+ >> files[++current]
+ >> directoryName
+ >> fileSize
+ >> fileDate
+ >> speed;
+
+ if (directoryName[0]) {
+ char *fullName = new char[mir_strlen(directoryName) + mir_strlen(files[current]) + 2];
+ sprintf(fullName, "%s\\%s", directoryName, files[current]);
+ delete[] files[current];
+ files[current] = fullName;
+ }
+
+ if (directory) createDirectory();
+ else openFile();
+ ack(ACKRESULT_NEXTFILE);
+
+ if (fileProgress) ack(ACKRESULT_FILERESUME);
+ else sendPacket0x03();
+ break;
+
+ case 0x03:
+ T("[tcp] ack next file\n");
+ packet >> fileProgress
+ >> status
+ >> speed;
+
+ totalProgress += fileProgress;
+ setFilePosition();
+ ack(ACKRESULT_NEXTFILE);
+
+ if (status != 0) {
+ totalProgress += fileSize - fileProgress;
+ fileProgress = fileSize;
+ closeFile();
+ ack(ACKRESULT_DATA);
+ }
+
+ process();
+ break;
+
+ case 0x04:
+ T("[tcp] recieve stop file\n");
+ packet >> junkLong;
+
+ totalProgress += fileSize - fileProgress;
+ fileProgress = fileSize;
+ closeFile();
+ ack(ACKRESULT_DATA);
+ break;
+
+ case 0x05:
+ T("[tcp] recieve new speed\n");
+ packet >> speed;
+ break;
+
+ case 0x06:
+ unsigned long result;
+
+ WriteFile(hFile, packet.data(), packet.dataSize(), &result, NULL);
+
+ fileProgress += result;
+ totalProgress += result;
+
+ if (fileProgress >= fileSize) closeFile();
+ ack(ACKRESULT_DATA);
+ break;
+
+ default:
+ T("[tcp] unknown packet:\n%s", packet.print());
+ packet.reset();
+ }
+
+ delete[] directoryName;
+ delete[] name;
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::sendPacket0x00()
{
- char nick[1] = { 0 };
+ char nick[1] = { 0 };
- sending = true;
+ sending = true;
- Packet packet;
- packet << (unsigned char)0x00
- << (unsigned int)0x00
- << count
- << totalSize
- << speed
- << nick;
+ Packet packet;
+ packet << (unsigned char)0x00
+ << (unsigned int)0x00
+ << count
+ << totalSize
+ << speed
+ << nick;
- T("[tcp] send packet 0x00\n");
- socket.sendPacket(packet);
+ T("[tcp] send packet 0x00\n");
+ socket.sendPacket(packet);
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::sendPacket0x01()
{
- char nick[1] = { 0 };
+ char nick[1] = { 0 };
- Packet packet;
- packet << (unsigned char)0x01
- << speed
- << nick;
+ Packet packet;
+ packet << (unsigned char)0x01
+ << speed
+ << nick;
- T("[tcp] send packet 0x01\n");
- socket.sendPacket(packet);
+ T("[tcp] send packet 0x01\n");
+ socket.sendPacket(packet);
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::sendPacket0x02()
{
- char *directoryName, *p;
-
- current++;
- openFile();
-
- directoryName = _strdup(fileName);
- p = strrchr(directoryName, '\\');
- p[0] = 0;
- p[1] = 0;
-
- Packet packet;
- packet << (unsigned char)0x02
- << directory
- << (strrchr(fileName, '\\') + 1)
- << (directoryName + mir_strlen(path) + 1)
- << fileSize
- << fileDate
- << speed;
-
- T("[tcp] send packet 0x02\n");
- socket.sendPacket(packet);
- ack(ACKRESULT_NEXTFILE);
-
- free(directoryName);
+ current++;
+ openFile();
+
+ char *directoryName = _strdup(fileName);
+ char *p = strrchr(directoryName, '\\');
+ p[0] = 0;
+ p[1] = 0;
+
+ Packet packet;
+ packet << (unsigned char)0x02
+ << directory
+ << (strrchr(fileName, '\\') + 1)
+ << (directoryName + mir_strlen(path) + 1)
+ << fileSize
+ << fileDate
+ << speed;
+
+ T("[tcp] send packet 0x02\n");
+ socket.sendPacket(packet);
+ ack(ACKRESULT_NEXTFILE);
+
+ free(directoryName);
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::sendPacket0x03()
{
- Packet packet;
- packet << (unsigned char)0x03
- << fileProgress
- << (unsigned int)0x00
- << speed;
+ Packet packet;
+ packet << (unsigned char)0x03
+ << fileProgress
+ << (unsigned int)0x00
+ << speed;
- setFilePosition();
+ setFilePosition();
- T("[tcp] send packet 0x03\n");
- socket.sendPacket(packet);
+ T("[tcp] send packet 0x03\n");
+ socket.sendPacket(packet);
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::sendPacket0x04()
{
- T("[tcp] send packet 0x04\n");
-/*
- icq_PacketAppend8(p, 0x04);
- icq_PacketAppend32(p, filenum);
-*/
+ T("[tcp] send packet 0x04\n");
+ // icq_PacketAppend8(p, 0x04);
+ // icq_PacketAppend32(p, filenum);
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::sendPacket0x05()
{
- T("[tcp] send packet 0x05\n");
-/*
- icq_PacketAppend8(p, 0x05);
- icq_PacketAppend32(p, speed);
-*/
+ T("[tcp] send packet 0x05\n");
+ // icq_PacketAppend8(p, 0x05);
+ // icq_PacketAppend32(p, speed);
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::sendPacket0x06()
{
- unsigned long result;
+ Packet packet;
+ packet << (unsigned char)0x06;
- Packet packet;
- packet << (unsigned char)0x06;
+ unsigned long result;
+ ReadFile(hFile, packet.data(), 2048, &result, NULL);
+ if (result == 0)
+ return;
- ReadFile(hFile, packet.data(), 2048, &result, NULL);
- if (result == 0) return;
- packet.add(result);
+ packet.add(result);
-// T("[tcp] send packet 0x06\n");
- socket.sendPacket(packet);
+ socket.sendPacket(packet);
- fileProgress += result;
- totalProgress += result;
+ fileProgress += result;
+ totalProgress += result;
- if (fileProgress >= fileSize) closeFile();
+ if (fileProgress >= fileSize)
+ closeFile();
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::ack(unsigned int result)
{
- PROTOFILETRANSFERSTATUS fts;
-
- if (result == ACKRESULT_DATA && GetTickCount() < lastNotify+250 && fileProgress < fileSize) return;
+ if (result == ACKRESULT_DATA && GetTickCount() < lastNotify + 250 && fileProgress < fileSize)
+ return;
- fts.cbSize = sizeof(fts);
- fts.hContact = hContact;
- //fts.sending = sending;
+ PROTOFILETRANSFERSTATUS fts;
+ fts.cbSize = sizeof(fts);
+ fts.hContact = hContact;
fts.pszFiles = files;
- fts.totalFiles = count;
- fts.currentFileNumber = current;
- fts.totalBytes = totalSize;
- fts.totalProgress = totalProgress;
- fts.szWorkingDir = path;
- fts.szCurrentFile = fileName;
- fts.currentFileSize = fileSize;
- fts.currentFileProgress = fileProgress;
- fts.currentFileTime = TimeZone_ToLocal(fileDate);
-/*
- switch (session->status)
- {
- case FILE_STATUS_LISTENING: result = ACKRESULT_SENTREQUEST; break;
- case FILE_STATUS_CONNECTED: result = ACKRESULT_CONNECTED; break;
- case FILE_STATUS_CONNECTING: result = ACKRESULT_CONNECTING; break;
- case FILE_STATUS_INITIALIZING: result = ACKRESULT_INITIALISING; break;
- case FILE_STATUS_NEXT_FILE: result = ACKRESULT_NEXTFILE; break;
- case FILE_STATUS_SENDING:
- case FILE_STATUS_RECEIVING: result=ACKRESULT_DATA; break;
- }
-*/
- ProtoBroadcastAck(protoName, hContact, ACKTYPE_FILE, result, this, (LPARAM)&fts);
- lastNotify = GetTickCount();
-
- if (result == ACKRESULT_DATA && current >= count-1 && fileProgress >= fileSize)
- {
- ProtoBroadcastAck(protoName, hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, this, 0);
- socket.closeConnection();
-
- unsigned int i;
- for (i=0; i<icqTransfers.size(); i++)
- {
- if (icqTransfers[i] == this)
- {
- delete icqTransfers[i];
- icqTransfers[i] = icqTransfers[icqTransfers.size() - 1];
- icqTransfers.pop_back();
- break;
- }
- }
- }
+ fts.totalFiles = count;
+ fts.currentFileNumber = current;
+ fts.totalBytes = totalSize;
+ fts.totalProgress = totalProgress;
+ fts.szWorkingDir = path;
+ fts.szCurrentFile = fileName;
+ fts.currentFileSize = fileSize;
+ fts.currentFileProgress = fileProgress;
+ fts.currentFileTime = TimeZone_ToLocal(fileDate);
+
+ ProtoBroadcastAck(protoName, hContact, ACKTYPE_FILE, result, this, (LPARAM)&fts);
+ lastNotify = GetTickCount();
+
+ if (result == ACKRESULT_DATA && current >= count - 1 && fileProgress >= fileSize) {
+ ProtoBroadcastAck(protoName, hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, this, 0);
+ socket.closeConnection();
+
+ unsigned int i;
+ for (i = 0; i < icqTransfers.size(); i++) {
+ if (icqTransfers[i] == this) {
+ delete icqTransfers[i];
+ icqTransfers[i] = icqTransfers[icqTransfers.size() - 1];
+ icqTransfers.pop_back();
+ break;
+ }
+ }
+ }
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::process()
{
- unsigned int /*i, */startTime;
+ unsigned int /*i, */startTime;
- hTimer = NULL;
- if (current >= count) return;
+ hTimer = NULL;
+ if (current >= count)
+ return;
- startTime = GetTickCount();
- while (fileProgress < fileSize && GetTickCount() < startTime+100) sendPacket0x06();
- ack(ACKRESULT_DATA);
+ startTime = GetTickCount();
+ while (fileProgress < fileSize && GetTickCount() < startTime + 100)
+ sendPacket0x06();
+ ack(ACKRESULT_DATA);
- if (fileProgress < fileSize) hTimer = SetTimer(NULL, 0, 1, transferTimerProc);
- else if (current < count-1) sendPacket0x02();
+ if (fileProgress < fileSize)
+ hTimer = SetTimer(NULL, 0, 1, transferTimerProc);
+ else if (current < count - 1)
+ sendPacket0x02();
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::resume(int action, const char *newName)
{
- switch (action)
- {
- case FILERESUME_OVERWRITE:
- T("[ ] overwrite existing file\n");
- fileProgress = 0;
- break;
-
- case FILERESUME_RESUME:
- T("[ ] file resume\n");
- break;
-
- case FILERESUME_RENAME:
- T("[ ] rename file\n");
- delete [] fileName;
- fileName = new char[mir_strlen(newName) + 1];
- mir_strcpy(fileName, newName);
- files[current] = fileName;
-
- openFile();
- fileProgress = 0;
- break;
-
- case FILERESUME_SKIP:
- T("[ ] skip file\n");
- fileProgress = fileSize;
- break;
+ switch (action) {
+ case FILERESUME_OVERWRITE:
+ T("[ ] overwrite existing file\n");
+ fileProgress = 0;
+ break;
+
+ case FILERESUME_RESUME:
+ T("[ ] file resume\n");
+ break;
+
+ case FILERESUME_RENAME:
+ T("[ ] rename file\n");
+ delete[] fileName;
+ fileName = new char[mir_strlen(newName) + 1];
+ mir_strcpy(fileName, newName);
+ files[current] = fileName;
+
+ openFile();
+ fileProgress = 0;
+ break;
+
+ case FILERESUME_SKIP:
+ T("[ ] skip file\n");
+ fileProgress = fileSize;
+ break;
}
- totalProgress += fileProgress;
+ totalProgress += fileProgress;
- sendPacket0x03();
- ack(ACKRESULT_NEXTFILE);
+ sendPacket0x03();
+ ack(ACKRESULT_NEXTFILE);
- if (fileProgress) ack(ACKRESULT_DATA);
+ if (fileProgress)
+ ack(ACKRESULT_DATA);
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::openFile()
{
- HANDLE hFind;
- WIN32_FIND_DATA findData;
- __int64 fileTime;
-
- if (hFile != INVALID_HANDLE_VALUE) closeFile();
- if (path) SetCurrentDirectory(path);
-
- fileName = files[current];
-
- hFind = FindFirstFile(fileName, &findData);
- if (hFind != INVALID_HANDLE_VALUE)
- {
- FindClose(hFind);
- if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- {
- T("open directory %s\n", fileName);
- directory = 1;
- fileProgress = 0;
- fileSize = 0;
- fileDate = *(__int64*)(&findData.ftLastWriteTime) / 10000000 - 11644473600i64;
- return;
- }
- }
- directory = 0;
-
- hFile = CreateFile(fileName, sending ? GENERIC_READ : GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- {
- char msg[2048];
-
- T("can't open file %s\n", fileName);
- sprintf(msg, "%s\n%s", sending ? Translate("Your file transfer has been aborted because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it.") : Translate("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."), fileName);
- MessageBox(NULL, msg, Translate(protoName), MB_ICONWARNING|MB_OK);
- return;
- }
-
- if (sending)
- {
- fileProgress = 0;
- fileSize = GetFileSize(hFile, NULL);
-
- GetFileTime(hFile, NULL, NULL, (LPFILETIME)&fileTime);
- fileDate = fileTime / 10000000 - 11644473600i64;
- }
- else
- {
- fileProgress = GetFileSize(hFile, NULL);
-
- fileTime = (11644473600i64 + (__int64)fileDate) * 10000000;
- SetFileTime(hFile, NULL, NULL, (LPFILETIME)&fileTime);
- }
+ if (hFile != INVALID_HANDLE_VALUE)
+ closeFile();
+ if (path)
+ SetCurrentDirectory(path);
+
+ fileName = files[current];
+
+ WIN32_FIND_DATA findData;
+ HANDLE hFind = FindFirstFile(fileName, &findData);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ FindClose(hFind);
+ if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ T("open directory %s\n", fileName);
+ directory = 1;
+ fileProgress = 0;
+ fileSize = 0;
+ fileDate = *(__int64*)(&findData.ftLastWriteTime) / 10000000 - 11644473600i64;
+ return;
+ }
+ }
+ directory = 0;
+
+ hFile = CreateFile(fileName, sending ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
+ if (hFile == INVALID_HANDLE_VALUE) {
+ char msg[2048];
+
+ T("can't open file %s\n", fileName);
+ sprintf(msg, "%s\n%s", sending ? Translate("Your file transfer has been aborted because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it.") : Translate("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."), fileName);
+ MessageBox(NULL, msg, Translate(protoName), MB_ICONWARNING | MB_OK);
+ return;
+ }
+
+ __int64 fileTime;
+ if (sending) {
+ fileProgress = 0;
+ fileSize = GetFileSize(hFile, NULL);
+
+ GetFileTime(hFile, NULL, NULL, (LPFILETIME)&fileTime);
+ fileDate = fileTime / 10000000 - 11644473600i64;
+ }
+ else {
+ fileProgress = GetFileSize(hFile, NULL);
+
+ fileTime = (11644473600i64 + (__int64)fileDate) * 10000000;
+ SetFileTime(hFile, NULL, NULL, (LPFILETIME)&fileTime);
+ }
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::closeFile()
{
- CloseHandle(hFile);
- hFile = INVALID_HANDLE_VALUE;
+ CloseHandle(hFile);
+ hFile = INVALID_HANDLE_VALUE;
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::setFilePosition()
{
- if (hFile != INVALID_HANDLE_VALUE) SetFilePointer(hFile, fileProgress, NULL, FILE_BEGIN);
+ if (hFile != INVALID_HANDLE_VALUE)
+ SetFilePointer(hFile, fileProgress, NULL, FILE_BEGIN);
}
///////////////////////////////////////////////////////////////////////////////
void ICQTransfer::createDirectory()
{
- if (path) SetCurrentDirectory(path);
+ if (path)
+ SetCurrentDirectory(path);
- fileName = files[current];
- CreateDirectory(fileName, NULL);
+ fileName = files[current];
+ CreateDirectory(fileName, NULL);
- fileProgress = 0;
+ fileProgress = 0;
}
-
-///////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/ICQCorp/src/user.cpp b/protocols/ICQCorp/src/user.cpp
index b1d68e0032..c66eec6539 100644
--- a/protocols/ICQCorp/src/user.cpp
+++ b/protocols/ICQCorp/src/user.cpp
@@ -1,21 +1,21 @@
/*
- ICQ Corporate protocol plugin for Miranda IM.
- Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>
+ ICQ Corporate protocol plugin for Miranda IM.
+ Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include "corp.h"
@@ -24,7 +24,7 @@ std::vector <ICQUser *> icqUsers;
///////////////////////////////////////////////////////////////////////////////
ICQUser::ICQUser() :
- socket(WM_NETEVENT_USER)
+ socket(WM_NETEVENT_USER)
{
}
@@ -32,108 +32,114 @@ ICQUser::ICQUser() :
void ICQUser::setStatus(unsigned short newStatus)
{
- if (statusVal == newStatus) return;
+ if (statusVal == newStatus)
+ return;
- statusVal = newStatus;
- db_set_w(hContact, protoName, "Status", newStatus);
+ statusVal = newStatus;
+ db_set_w(hContact, protoName, "Status", newStatus);
}
///////////////////////////////////////////////////////////////////////////////
void ICQUser::setInfo(char *name, unsigned int data)
{
- if (data && data != 0xFFFFFFFF) db_set_dw(hContact, protoName, name, data);
- else db_unset(hContact, protoName, name);
+ if (data && data != 0xFFFFFFFF)
+ db_set_dw(hContact, protoName, name, data);
+ else
+ db_unset(hContact, protoName, name);
}
///////////////////////////////////////////////////////////////////////////////
void ICQUser::setInfo(char *name, unsigned short data)
{
- if (data && data != 0xFFFF) db_set_w(hContact, protoName, name, data);
- else db_unset(hContact, protoName, name);
+ if (data && data != 0xFFFF)
+ db_set_w(hContact, protoName, name, data);
+ else
+ db_unset(hContact, protoName, name);
}
///////////////////////////////////////////////////////////////////////////////
void ICQUser::setInfo(char *name, unsigned char data)
{
- if (data && data != 0xFF) db_set_b(hContact, protoName, name, data);
- else db_unset(hContact, protoName, name);
+ if (data && data != 0xFF)
+ db_set_b(hContact, protoName, name, data);
+ else
+ db_unset(hContact, protoName, name);
}
///////////////////////////////////////////////////////////////////////////////
void ICQUser::setInfo(char *name, char *data)
{
- if (data[0]) db_set_s(hContact, protoName, name, data);
- else db_unset(hContact, protoName, name);
+ if (data[0])
+ db_set_s(hContact, protoName, name, data);
+ else
+ db_unset(hContact, protoName, name);
}
///////////////////////////////////////////////////////////////////////////////
-static char *iptoa(unsigned int ip)
+static char* iptoa(unsigned int ip)
{
- struct in_addr addr;
-
- addr.S_un.S_addr = htonl(ip);
- return inet_ntoa(addr);
+ struct in_addr addr;
+ addr.S_un.S_addr = htonl(ip);
+ return inet_ntoa(addr);
}
///////////////////////////////////////////////////////////////////////////////
static void setTextValue(HWND hWnd, int id, char *value)
{
- bool unspecified = value == NULL;
+ bool unspecified = value == NULL;
- EnableWindow(GetDlgItem(hWnd, id), !unspecified);
- SetDlgItemText(hWnd, id, unspecified ? Translate("<not specified>") : value);
+ EnableWindow(GetDlgItem(hWnd, id), !unspecified);
+ SetDlgItemText(hWnd, id, unspecified ? Translate("<not specified>") : value);
}
///////////////////////////////////////////////////////////////////////////////
static INT_PTR CALLBACK icqUserInfoDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- LPNMHDR hdr;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- TranslateDialogDefault(hWnd);
- return TRUE;
-
- case WM_NOTIFY:
- hdr = (LPNMHDR)lParam;
- if (hdr->idFrom == 0 && hdr->code == PSN_INFOCHANGED)
- {
- char buffer[64];
- unsigned long ip, port;
+ LPNMHDR hdr;
+
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hWnd);
+ return TRUE;
+
+ case WM_NOTIFY:
+ hdr = (LPNMHDR)lParam;
+ if (hdr->idFrom == 0 && hdr->code == PSN_INFOCHANGED) {
+ char buffer[64];
+ unsigned long ip, port;
MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
- _itoa(db_get_dw(hContact, protoName, "UIN", 0), buffer, 10);
- setTextValue(hWnd, IDC_INFO_UIN, buffer);
+ _itoa(db_get_dw(hContact, protoName, "UIN", 0), buffer, 10);
+ setTextValue(hWnd, IDC_INFO_UIN, buffer);
- ip = db_get_dw(hContact, protoName, "IP", 0);
- setTextValue(hWnd, IDC_INFO_IP, ip ? iptoa(ip) : NULL);
+ ip = db_get_dw(hContact, protoName, "IP", 0);
+ setTextValue(hWnd, IDC_INFO_IP, ip ? iptoa(ip) : NULL);
- ip = db_get_dw(hContact, protoName, "RealIP", 0);
- setTextValue(hWnd, IDC_INFO_REALIP, ip ? iptoa(ip) : NULL);
+ ip = db_get_dw(hContact, protoName, "RealIP", 0);
+ setTextValue(hWnd, IDC_INFO_REALIP, ip ? iptoa(ip) : NULL);
- port = db_get_w(hContact, protoName, "Port", 0);
- _itoa(port, buffer, 10);
- setTextValue(hWnd, IDC_INFO_PORT, port ? buffer : NULL);
+ port = db_get_w(hContact, protoName, "Port", 0);
+ _itoa(port, buffer, 10);
+ setTextValue(hWnd, IDC_INFO_PORT, port ? buffer : NULL);
- setTextValue(hWnd, IDC_INFO_VERSION, NULL);
- setTextValue(hWnd, IDC_INFO_MIRVER, NULL);
- setTextValue(hWnd, IDC_INFO_PING, NULL);
- }
- break;
+ setTextValue(hWnd, IDC_INFO_VERSION, NULL);
+ setTextValue(hWnd, IDC_INFO_MIRVER, NULL);
+ setTextValue(hWnd, IDC_INFO_PING, NULL);
+ }
+ break;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDCANCEL) SendMessage(GetParent(hWnd), msg, wParam, lParam);
- break;
- }
- return FALSE;
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDCANCEL) SendMessage(GetParent(hWnd), msg, wParam, lParam);
+ break;
+ }
+ return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
@@ -153,5 +159,3 @@ int icqUserInfoInitialise(WPARAM wParam, LPARAM lParam)
UserInfo_AddPage(wParam, &odp);
return 0;
}
-
-///////////////////////////////////////////////////////////////////////////////