summaryrefslogtreecommitdiff
path: root/protocols/IcqOscarJ/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/IcqOscarJ/src')
-rw-r--r--protocols/IcqOscarJ/src/chan_01login.cpp33
-rw-r--r--protocols/IcqOscarJ/src/chan_04close.cpp21
-rw-r--r--protocols/IcqOscarJ/src/chan_05ping.cpp56
-rw-r--r--protocols/IcqOscarJ/src/fam_01service.cpp392
-rw-r--r--protocols/IcqOscarJ/src/icq_proto.h3
-rw-r--r--protocols/IcqOscarJ/src/icq_server.cpp2
-rw-r--r--protocols/IcqOscarJ/src/icq_server.h19
7 files changed, 216 insertions, 310 deletions
diff --git a/protocols/IcqOscarJ/src/chan_01login.cpp b/protocols/IcqOscarJ/src/chan_01login.cpp
index a0e1222aa4..fdd905258d 100644
--- a/protocols/IcqOscarJ/src/chan_01login.cpp
+++ b/protocols/IcqOscarJ/src/chan_01login.cpp
@@ -33,13 +33,8 @@ void CIcqProto::handleLoginChannel(BYTE *buf, WORD datalen, serverthread_info *i
#endif
// isLoginServer is "1" if we just received SRV_HELLO
- if (info->isLoginServer)
- {
- if (m_bSecureLogin)
- {
- char szUin[UINMAXLEN];
- WORD wUinLen;
-
+ if (info->isLoginServer) {
+ if (m_bSecureLogin) {
#ifdef _DEBUG
debugLogA("Sending %s to %s", "CLI_HELLO", "login server");
#endif
@@ -49,35 +44,32 @@ void CIcqProto::handleLoginChannel(BYTE *buf, WORD datalen, serverthread_info *i
packTLVDWord(&packet, 0x8003, 0x00100000); // unknown
sendServPacket(&packet); // greet login server
- wUinLen = strlennull(strUID(m_dwLocalUIN, szUin));
+ char szUin[UINMAXLEN];
+ WORD wUinLen = strlennull(strUID(m_dwLocalUIN, szUin));
+
#ifdef _DEBUG
debugLogA("Sending %s to %s", "ICQ_SIGNON_AUTH_REQUEST", "login server");
#endif
-
serverPacketInit(&packet, (WORD)(14 + wUinLen));
packFNACHeader(&packet, ICQ_AUTHORIZATION_FAMILY, ICQ_SIGNON_AUTH_REQUEST, 0, 0);
packTLV(&packet, 0x0001, wUinLen, (LPBYTE)szUin);
sendServPacket(&packet); // request login digest
}
- else
- {
+ else {
sendClientAuth((char*)info->szAuthKey, info->wAuthKeyLen, FALSE);
#ifdef _DEBUG
debugLogA("Sent CLI_IDENT to %s", "login server");
#endif
}
- info->isLoginServer = 0;
- if (info->cookieDataLen)
- {
+ info->isLoginServer = false;
+ if (info->cookieDataLen) {
SAFE_FREE((void**)&info->cookieData);
info->cookieDataLen = 0;
}
}
- else
- {
- if (info->cookieDataLen)
- {
+ else {
+ if (info->cookieDataLen) {
wLocalSequence = generate_flap_sequence();
serverCookieInit(&packet, info->cookieData, (WORD)info->cookieDataLen);
@@ -90,10 +82,7 @@ void CIcqProto::handleLoginChannel(BYTE *buf, WORD datalen, serverthread_info *i
SAFE_FREE((void**)&info->cookieData);
info->cookieDataLen = 0;
}
- else
- {
- // We need a cookie to identify us to the communication server
+ else // We need a cookie to identify us to the communication server
debugLogA("Error: Connected to %s without a cookie!", "communication server");
- }
}
}
diff --git a/protocols/IcqOscarJ/src/chan_04close.cpp b/protocols/IcqOscarJ/src/chan_04close.cpp
index b5a1e6388f..d7f6548f82 100644
--- a/protocols/IcqOscarJ/src/chan_04close.cpp
+++ b/protocols/IcqOscarJ/src/chan_04close.cpp
@@ -29,13 +29,13 @@ void CIcqProto::handleCloseChannel(BYTE *buf, WORD datalen, serverthread_info *i
oscar_tlv_chain *chain = NULL;
// Parse server reply, prepare reconnection
- if (!info->bLoggedIn && datalen && !info->newServerReady)
+ if (!info->bLoggedIn && datalen && !info->isNewServerReady)
handleLoginReply(buf, datalen, info);
if (info->isMigrating)
handleMigration(info);
- if ((!info->bLoggedIn || info->isMigrating) && info->newServerReady) {
+ if ((!info->bLoggedIn || info->isMigrating) && info->isNewServerReady) {
if (!connectNewServer(info)) { // Connecting failed
if (info->isMigrating)
icq_LogUsingErrorCode(LOG_ERROR, GetLastError(), LPGEN("Unable to connect to migrated ICQ communication server"));
@@ -44,9 +44,9 @@ void CIcqProto::handleCloseChannel(BYTE *buf, WORD datalen, serverthread_info *i
SetCurrentStatus(ID_STATUS_OFFLINE);
- info->isMigrating = 0;
+ info->isMigrating = false;
}
- info->newServerReady = 0;
+ info->isNewServerReady = false;
return;
}
@@ -65,7 +65,6 @@ void CIcqProto::handleCloseChannel(BYTE *buf, WORD datalen, serverthread_info *i
NetLib_CloseConnection(&hServerConn, TRUE);
}
-
void CIcqProto::handleLoginReply(BYTE *buf, WORD datalen, serverthread_info *info)
{
oscar_tlv_chain *chain = NULL;
@@ -114,12 +113,9 @@ void CIcqProto::handleLoginReply(BYTE *buf, WORD datalen, serverthread_info *inf
}
debugLogA("Authenticated.");
- info->newServerReady = 1;
-
- return;
+ info->isNewServerReady = true;
}
-
int CIcqProto::connectNewServer(serverthread_info *info)
{
int res = 0;
@@ -150,7 +146,7 @@ int CIcqProto::connectNewServer(serverthread_info *info)
if (!info->hPacketRecver)
debugLogA("Error: Failed to create packet receiver.");
else { // we need to reset receiving structs
- info->bReinitRecver = 1;
+ info->bReinitRecver = true;
res = 1;
}
}
@@ -170,7 +166,6 @@ int CIcqProto::connectNewServer(serverthread_info *info)
return res;
}
-
void CIcqProto::handleMigration(serverthread_info *info)
{
// Check the data that was saved when the migration was announced
@@ -180,8 +175,7 @@ void CIcqProto::handleMigration(serverthread_info *info)
SAFE_FREE(&info->newServer);
SAFE_FREE((void**)&info->cookieData);
- info->newServerReady = 0;
- info->isMigrating = 0;
+ info->isNewServerReady = info->isMigrating = false;
}
}
@@ -269,7 +263,6 @@ void CIcqProto::handleSignonError(WORD wError)
}
}
-
void CIcqProto::handleRuntimeError(WORD wError)
{
switch (wError) {
diff --git a/protocols/IcqOscarJ/src/chan_05ping.cpp b/protocols/IcqOscarJ/src/chan_05ping.cpp
index 62c3377ada..5fe2aaf9a7 100644
--- a/protocols/IcqOscarJ/src/chan_05ping.cpp
+++ b/protocols/IcqOscarJ/src/chan_05ping.cpp
@@ -29,50 +29,30 @@ void CIcqProto::handlePingChannel(BYTE *buf, WORD datalen)
debugLogA("Warning: Ignoring server packet on PING channel");
}
-void __cdecl CIcqProto::KeepAliveThread(void *arg)
+void CIcqProto::StartKeepAlive(serverthread_info *info)
{
- serverthread_info *info = (serverthread_info*)arg;
- icq_packet packet;
- DWORD dwInterval = getDword("KeepAliveInterval", KEEPALIVE_INTERVAL);
-
- debugLogA("Keep alive thread starting.");
-
- info->hKeepAliveEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
-
- for (;;) {
- DWORD dwWait = ICQWaitForSingleObject(info->hKeepAliveEvent, dwInterval);
- if (serverThreadHandle == NULL) // connection lost, end
- break;
+ if (getByte("KeepAlive", DEFAULT_KEEPALIVE_ENABLED))
+ info->iKeepalive = getDword("KeepAliveInterval", KEEPALIVE_INTERVAL);
+ else
+ info->iKeepalive = -1;
+}
- // Possible shutdown in progress
- if (dwWait == WAIT_IO_COMPLETION)
- break;
+void CIcqProto::StopKeepAlive(serverthread_info *info)
+{
+ info->iKeepalive = -1;
+}
- if (dwWait == WAIT_TIMEOUT) {
+void CIcqProto::CheckKeepAlive(serverthread_info *info)
+{
+ if (info->iKeepalive != -1) {
+ if (info->iKeepalive == 0) {
// Send a keep alive packet to server
- packet.wLen = 0;
+ icq_packet packet = { 0 };
write_flap(&packet, ICQ_PING_CHAN);
sendServPacket(&packet);
+
+ StartKeepAlive(info);
}
+ else info->iKeepalive--;
}
-
- debugLogA("Keep alive thread ended.");
-
- CloseHandle(info->hKeepAliveEvent);
- info->hKeepAliveEvent = NULL;
-}
-
-void CIcqProto::StartKeepAlive(serverthread_info *info)
-{
- if (info->hKeepAliveEvent) // start only once
- return;
-
- if (getByte("KeepAlive", DEFAULT_KEEPALIVE_ENABLED))
- ForkThread(&CIcqProto::KeepAliveThread, info);
-}
-
-void CIcqProto::StopKeepAlive(serverthread_info *info)
-{
- if (info->hKeepAliveEvent)
- SetEvent(info->hKeepAliveEvent);
}
diff --git a/protocols/IcqOscarJ/src/fam_01service.cpp b/protocols/IcqOscarJ/src/fam_01service.cpp
index 148bfecf83..ab75bab78c 100644
--- a/protocols/IcqOscarJ/src/fam_01service.cpp
+++ b/protocols/IcqOscarJ/src/fam_01service.cpp
@@ -223,13 +223,12 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
break;
case ICQ_SERVER_MIGRATIONREQ:
- {
#ifdef _DEBUG
- debugLogA("Server migration requested (Flags: %u)", pSnacHeader->wFlags);
+ debugLogA("Server migration requested (Flags: %u)", pSnacHeader->wFlags);
#endif
- pBuffer += 2; // Unknown, seen: 0
- wBufferLength -= 2;
-
+ pBuffer += 2; // Unknown, seen: 0
+ wBufferLength -= 2;
+ {
oscar_tlv_chain *chain = readIntoTLVChain(&pBuffer, wBufferLength, 0);
if (info->cookieDataLen > 0)
@@ -242,13 +241,12 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
disposeChain(&chain);
- if (!info->newServer || !info->cookieData)
- {
+ if (!info->newServer || !info->cookieData) {
icq_LogMessage(LOG_FATAL, LPGEN("A server migration has failed because the server returned invalid data. You must reconnect manually."));
SAFE_FREE(&info->newServer);
SAFE_FREE((void**)&info->cookieData);
info->cookieDataLen = 0;
- info->newServerReady = 0;
+ info->isNewServerReady = false;
return;
}
@@ -257,28 +255,23 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
m_iDesiredStatus = m_iStatus;
SetCurrentStatus(ID_STATUS_CONNECTING); // revert to connecting state
- info->newServerReady = 1;
- info->isMigrating = 1;
+ info->isNewServerReady = info->isMigrating = true;
}
break;
case ICQ_SERVER_NAME_INFO: // This is the reply to CLI_REQINFO
- {
- BYTE bUinLen;
- oscar_tlv_chain *chain;
-
#ifdef _DEBUG
- debugLogA("Received self info");
+ debugLogA("Received self info");
#endif
+ {
+ BYTE bUinLen;
unpackByte(&pBuffer, &bUinLen);
pBuffer += bUinLen;
pBuffer += 4; /* warning level & user class */
wBufferLength -= 5 + bUinLen;
- if (pSnacHeader->dwRef == ICQ_CLIENT_REQINFO<<0x10)
- { // This is during the login sequence
- DWORD dwValue;
-
+ // This is during the login sequence
+ if (pSnacHeader->dwRef == ICQ_CLIENT_REQINFO << 0x10) {
// TLV(x01) User type?
// TLV(x0C) Empty CLI2CLI Direct connection info
// TLV(x0A) External IP
@@ -289,10 +282,10 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
// TLV(x1E) Unknown: empty.
// TLV(x05) Member of ICQ since.
// TLV(x14) Unknown
- chain = readIntoTLVChain(&pBuffer, wBufferLength, 0);
+ oscar_tlv_chain *chain = readIntoTLVChain(&pBuffer, wBufferLength, 0);
// Save external IP
- dwValue = chain->getDWord(0x0A, 1);
+ DWORD dwValue = chain->getDWord(0x0A, 1);
setDword("IP", dwValue);
// Save member since timestamp
@@ -313,11 +306,8 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
break;
case ICQ_SERVER_RATE_CHANGE:
-
- if (wBufferLength >= 2)
- {
- WORD wStatus;
- WORD wClass;
+ if (wBufferLength >= 2) {
+ WORD wStatus, wClass;
DWORD dwLevel;
// We now have global rate management, although controlled are only some
// areas. This should not arrive in most cases. If it does, update our
@@ -331,16 +321,15 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
m_rates->updateLevel(wClass, dwLevel);
m_ratesMutex->Leave();
- if (wStatus == 2 || wStatus == 3)
- { // this is only the simplest solution, needs rate management to every section
+ if (wStatus == 2 || wStatus == 3) {
+ // this is only the simplest solution, needs rate management to every section
ProtoBroadcastAck(NULL, ICQACKTYPE_RATEWARNING, ACKRESULT_STATUS, (HANDLE)wClass, wStatus);
if (wStatus == 2)
debugLogA("Rates #%u: Alert", wClass);
else
debugLogA("Rates #%u: Limit", wClass);
}
- else if (wStatus == 4)
- {
+ else if (wStatus == 4) {
ProtoBroadcastAck(NULL, ICQACKTYPE_RATEWARNING, ACKRESULT_STATUS, (HANDLE)wClass, wStatus);
debugLogA("Rates #%u: Clear", wClass);
}
@@ -353,16 +342,14 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
oscar_tlv_chain *pChain = NULL;
cookie_family_request *pCookieData;
- if (!(pChain = readIntoTLVChain(&pBuffer, wBufferLength, 0)))
- {
+ if (!(pChain = readIntoTLVChain(&pBuffer, wBufferLength, 0))) {
debugLogA("Received Broken Redirect Service SNAC(1,5).");
break;
}
- WORD wFamily = pChain->getWord(0x0D, 1);
// pick request data
- if ((!FindCookie(pSnacHeader->dwRef, NULL, (void**)&pCookieData)) || (pCookieData->wFamily != wFamily))
- {
+ WORD wFamily = pChain->getWord(0x0D, 1);
+ if ((!FindCookie(pSnacHeader->dwRef, NULL, (void**)&pCookieData)) || (pCookieData->wFamily != wFamily)) {
disposeChain(&pChain);
debugLogA("Received unexpected SNAC(1,5), skipping.");
break;
@@ -370,148 +357,130 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
FreeCookie(pSnacHeader->dwRef);
- { // new family entry point received
- char *pServer = pChain->getString(0x05, 1);
- BYTE bServerSSL = pChain->getNumber(0x8E, 1);
- char *pCookie = pChain->getString(0x06, 1);
- WORD wCookieLen = pChain->getLength(0x06, 1);
+ // new family entry point received
+ char *pServer = pChain->getString(0x05, 1);
+ BYTE bServerSSL = pChain->getNumber(0x8E, 1);
+ char *pCookie = pChain->getString(0x06, 1);
+ WORD wCookieLen = pChain->getLength(0x06, 1);
- if (!pServer || !pCookie)
- {
- debugLogA("Server returned invalid data, family unavailable.");
+ if (!pServer || !pCookie) {
+ debugLogA("Server returned invalid data, family unavailable.");
- SAFE_FREE(&pServer);
- SAFE_FREE(&pCookie);
- SAFE_FREE((void**)&pCookieData);
- disposeChain(&pChain);
- break;
- }
+ SAFE_FREE(&pServer);
+ SAFE_FREE(&pCookie);
+ SAFE_FREE((void**)&pCookieData);
+ disposeChain(&pChain);
+ break;
+ }
- // Get new family server ip and port
- WORD wPort = info->wServerPort; // get default port
- parseServerAddress(pServer, &wPort);
+ // Get new family server ip and port
+ WORD wPort = info->wServerPort; // get default port
+ parseServerAddress(pServer, &wPort);
- // establish connection
- NETLIBOPENCONNECTION nloc = {0};
- if (m_bGatewayMode)
- nloc.flags |= NLOCF_HTTPGATEWAY;
- nloc.szHost = pServer;
- nloc.wPort = wPort;
+ // establish connection
+ NETLIBOPENCONNECTION nloc = { 0 };
+ if (m_bGatewayMode)
+ nloc.flags |= NLOCF_HTTPGATEWAY;
+ nloc.szHost = pServer;
+ nloc.wPort = wPort;
- HANDLE hConnection = NetLib_OpenConnection(m_hNetlibUser, wFamily == ICQ_AVATAR_FAMILY ? "Avatar " : NULL, &nloc);
+ HANDLE hConnection = NetLib_OpenConnection(m_hNetlibUser, wFamily == ICQ_AVATAR_FAMILY ? "Avatar " : NULL, &nloc);
- if (hConnection == NULL)
- {
- debugLogA("Unable to connect to ICQ new family server.");
- } // we want the handler to be called even if the connecting failed
- else if (bServerSSL)
- { /* Start SSL session if requested */
+ if (hConnection == NULL)
+ debugLogA("Unable to connect to ICQ new family server.");
+ // we want the handler to be called even if the connecting failed
+ else if (bServerSSL) { /* Start SSL session if requested */
#ifdef _DEBUG
- debugLogA("(%d) Starting SSL negotiation", CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0));
+ debugLogA("(%d) Starting SSL negotiation", CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0));
#endif
- if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hConnection, 0))
- {
- debugLogA("Unable to connect to ICQ new family server, SSL could not be negotiated");
- NetLib_CloseConnection(&hConnection, FALSE);
- }
+ if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hConnection, 0)) {
+ debugLogA("Unable to connect to ICQ new family server, SSL could not be negotiated");
+ NetLib_CloseConnection(&hConnection, FALSE);
}
-
- (this->*pCookieData->familyHandler)(hConnection, pCookie, wCookieLen);
-
- // Free allocated memory
- // NOTE: "cookie" will get freed when we have connected to the avatar server.
- disposeChain(&pChain);
- SAFE_FREE(&pServer);
- SAFE_FREE((void**)&pCookieData);
}
+ (this->*pCookieData->familyHandler)(hConnection, pCookie, wCookieLen);
+
+ // Free allocated memory
+ // NOTE: "cookie" will get freed when we have connected to the avatar server.
+ disposeChain(&pChain);
+ SAFE_FREE(&pServer);
+ SAFE_FREE((void**)&pCookieData);
break;
}
case ICQ_SERVER_EXTSTATUS: // our session data
- {
#ifdef _DEBUG
- debugLogA("Received owner session data.");
+ debugLogA("Received owner session data.");
#endif
- while (wBufferLength > 4)
- { // loop thru all items
- WORD itemType = pBuffer[0] * 0x10 | pBuffer[1];
- BYTE itemFlags = pBuffer[2];
- BYTE itemLen = pBuffer[3];
+ while (wBufferLength > 4) { // loop thru all items
+ WORD itemType = pBuffer[0] * 0x10 | pBuffer[1];
+ BYTE itemFlags = pBuffer[2];
+ BYTE itemLen = pBuffer[3];
- if (itemType == AVATAR_HASH_PHOTO) /// TODO: handle photo item
- { // skip photo item
+ if (itemType == AVATAR_HASH_PHOTO) { /// TODO: handle photo item
+ // skip photo item
#ifdef _DEBUG
- debugLogA("Photo item recognized");
+ debugLogA("Photo item recognized");
#endif
- }
- else if ((itemType == AVATAR_HASH_STATIC || itemType == AVATAR_HASH_FLASH) && (itemLen >= 0x10))
- {
+ }
+ else if ((itemType == AVATAR_HASH_STATIC || itemType == AVATAR_HASH_FLASH) && (itemLen >= 0x10)) {
#ifdef _DEBUG
- debugLogA("Avatar item recognized");
-#endif
- if (m_bAvatarsEnabled && !info->bMyAvatarInited) // signal the server after login
- { // this refreshes avatar state - it used to work automatically, but now it does not
- if (getByte("ForceOurAvatar", 0))
- { // keep our avatar
- TCHAR *file = GetOwnAvatarFileName();
- SetMyAvatar(0, (LPARAM)file);
- SAFE_FREE(&file);
- }
- else // only change avatar hash to the same one
- {
- BYTE hash[0x14];
-
- memcpy(hash, pBuffer, 0x14);
- hash[2] = 1; // update image status
- updateServAvatarHash(hash, 0x14);
- }
- info->bMyAvatarInited = TRUE;
- break;
- }
- // process owner avatar hash changed notification
- handleAvatarOwnerHash(itemType, itemFlags, pBuffer, itemLen + 4);
- }
- else if (itemType == 0x02)
- {
+ debugLogA("Avatar item recognized");
+#endif
+ if (m_bAvatarsEnabled && !info->bMyAvatarInited) { // signal the server after login
+ // this refreshes avatar state - it used to work automatically, but now it does not
+ if (getByte("ForceOurAvatar", 0)) { // keep our avatar
+ TCHAR *file = GetOwnAvatarFileName();
+ SetMyAvatar(0, (LPARAM)file);
+ SAFE_FREE(&file);
+ }
+ else { // only change avatar hash to the same one
+ BYTE hash[0x14];
+ memcpy(hash, pBuffer, 0x14);
+ hash[2] = 1; // update image status
+ updateServAvatarHash(hash, 0x14);
+ }
+ info->bMyAvatarInited = true;
+ break;
+ }
+ // process owner avatar hash changed notification
+ handleAvatarOwnerHash(itemType, itemFlags, pBuffer, itemLen + 4);
+ }
+ else if (itemType == 0x02) {
#ifdef _DEBUG
- debugLogA("Status message item recognized");
+ debugLogA("Status message item recognized");
#endif
- }
- else if (itemType == 0x0E)
- {
+ }
+ else if (itemType == 0x0E) {
#ifdef _DEBUG
- debugLogA("Status mood item recognized");
-#endif
- }
-
- // move to next item
- if (wBufferLength >= itemLen + 4)
- {
- wBufferLength -= itemLen + 4;
- pBuffer += itemLen + 4;
- }
- else
- {
- pBuffer += wBufferLength;
- wBufferLength = 0;
- }
+ debugLogA("Status mood item recognized");
+#endif
+ }
+
+ // move to next item
+ if (wBufferLength >= itemLen + 4) {
+ wBufferLength -= itemLen + 4;
+ pBuffer += itemLen + 4;
+ }
+ else {
+ pBuffer += wBufferLength;
+ wBufferLength = 0;
}
- break;
}
+ break;
- case ICQ_ERROR:
- { // Something went wrong, probably the request for avatar family failed
+ case ICQ_ERROR: // Something went wrong, probably the request for avatar family failed
+ {
WORD wError;
-
if (wBufferLength >= 2)
unpackWord(&pBuffer, &wError);
- else
+ else
wError = 0;
LogFamilyError(ICQ_SERVICE_FAMILY, wError);
- break;
}
+ break;
// Stuff we don't care about
case ICQ_SERVER_MOTD:
@@ -523,22 +492,21 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header
default:
debugLogA("Warning: Ignoring SNAC(x%02x,x%02x) - Unknown SNAC (Flags: %u, Ref: %u)", ICQ_SERVICE_FAMILY, pSnacHeader->wSubtype, pSnacHeader->wFlags, pSnacHeader->dwRef);
break;
-
}
}
char* CIcqProto::buildUinList(int subtype, WORD wMaxLen, MCONTACT *hContactResume)
{
- char* szList;
MCONTACT hContact;
WORD wCurrentLen = 0;
DWORD dwUIN;
uid_str szUID;
- char szLen[2];
int add;
- szList = (char*)SAFE_MALLOC(CallService(MS_DB_CONTACT_GETCOUNT, 0, 0) * UINMAXLEN);
+ char *szList = (char*)SAFE_MALLOC(CallService(MS_DB_CONTACT_GETCOUNT, 0, 0) * UINMAXLEN);
+
+ char szLen[2];
szLen[1] = '\0';
if (*hContactResume)
@@ -546,15 +514,11 @@ char* CIcqProto::buildUinList(int subtype, WORD wMaxLen, MCONTACT *hContactResum
else
hContact = db_find_first(m_szModuleName);
- while (hContact != NULL)
- {
- if (!getContactUid(hContact, &dwUIN, &szUID))
- {
+ while (hContact != NULL) {
+ if (!getContactUid(hContact, &dwUIN, &szUID)) {
szLen[0] = strlennull(strUID(dwUIN, szUID));
- switch (subtype)
- {
-
+ switch (subtype) {
case BUL_VISIBLE:
add = ID_STATUS_ONLINE == getWord(hContact, "ApparentMode", 0);
break;
@@ -587,11 +551,9 @@ char* CIcqProto::buildUinList(int subtype, WORD wMaxLen, MCONTACT *hContactResum
break;
}
- if (add)
- {
+ if (add) {
wCurrentLen += szLen[0] + 1;
- if (wCurrentLen > wMaxLen)
- {
+ if (wCurrentLen > wMaxLen) {
*hContactResume = hContact;
return szList;
}
@@ -608,21 +570,17 @@ char* CIcqProto::buildUinList(int subtype, WORD wMaxLen, MCONTACT *hContactResum
return szList;
}
-
void CIcqProto::sendEntireListServ(WORD wFamily, WORD wSubtype, int listType)
{
MCONTACT hResumeContact = NULL;
- do
- { // server doesn't seem to be able to cope with packets larger than 8k
+ do { // server doesn't seem to be able to cope with packets larger than 8k
// send only about 100contacts per packet
char *szList = buildUinList(listType, 0x3E8, &hResumeContact);
- int nListLen = strlennull(szList);
- if (nListLen)
- {
+ int nListLen = strlennull(szList);
+ if (nListLen) {
icq_packet packet;
-
serverPacketInit(&packet, (WORD)(nListLen + 10));
packFNACHeader(&packet, wFamily, wSubtype);
packBuffer(&packet, (LPBYTE)szList, (WORD)nListLen);
@@ -631,21 +589,21 @@ void CIcqProto::sendEntireListServ(WORD wFamily, WORD wSubtype, int listType)
SAFE_FREE((void**)&szList);
}
- while (hResumeContact);
+ while (hResumeContact);
}
static void packShortCapability(icq_packet *packet, WORD wCapability)
-{ // pack standard capability
+{
+ // pack standard capability
DWORD dwQ1 = 0x09460000 | wCapability;
- packDWord(packet, dwQ1);
+ packDWord(packet, dwQ1);
packDWord(packet, 0x4c7f11d1);
packDWord(packet, 0x82224445);
packDWord(packet, 0x53540000);
}
-
// CLI_SETUSERINFO
void CIcqProto::setUserInfo()
{
@@ -685,7 +643,7 @@ void CIcqProto::setUserInfo()
//MIM/PackName
bool bHasPackName = false;
DBVARIANT dbv;
- if ( !db_get_s(NULL, "ICQCaps", "PackName", &dbv )) {
+ if (!db_get_s(NULL, "ICQCaps", "PackName", &dbv)) {
//MIM/PackName
bHasPackName = true;
wAdditionalData += 16;
@@ -699,62 +657,55 @@ void CIcqProto::setUserInfo()
packWord(&packet, (WORD)(48 + wAdditionalData));
#ifdef DBG_CAPMTN
- {
- packDWord(&packet, 0x563FC809); // CAP_TYPING
- packDWord(&packet, 0x0B6F41BD);
- packDWord(&packet, 0x9F794226);
- packDWord(&packet, 0x09DFA2F3);
- }
+ packDWord(&packet, 0x563FC809); // CAP_TYPING
+ packDWord(&packet, 0x0B6F41BD);
+ packDWord(&packet, 0x9F794226);
+ packDWord(&packet, 0x09DFA2F3);
#endif
- {
- packShortCapability(&packet, 0x1349); // AIM_CAPS_ICQSERVERRELAY
- }
+
+ packShortCapability(&packet, 0x1349); // AIM_CAPS_ICQSERVERRELAY
+
+ // Broadcasts the capability to receive UTF8 encoded messages
if (m_bUtfEnabled)
- {
packShortCapability(&packet, 0x134E); // CAP_UTF8MSGS
- } // Broadcasts the capability to receive UTF8 encoded messages
+
#ifdef DBG_NEWCAPS
- {
- packShortCapability(&packet, 0x0000); // CAP_SHORTCAPS
- } // Tells server we understand to new format of caps
+ // Tells server we understand to new format of caps
+ packShortCapability(&packet, 0x0000); // CAP_SHORTCAPS
#endif
+
#ifdef DBG_CAPXTRAZ
- {
- packDWord(&packet, 0x1a093c6c); // CAP_XTRAZ
- packDWord(&packet, 0xd7fd4ec5); // Broadcasts the capability to handle
- packDWord(&packet, 0x9d51a647); // Xtraz
- packDWord(&packet, 0x4e34f5a0);
- }
+ packDWord(&packet, 0x1a093c6c); // CAP_XTRAZ
+ packDWord(&packet, 0xd7fd4ec5); // Broadcasts the capability to handle
+ packDWord(&packet, 0x9d51a647); // Xtraz
+ packDWord(&packet, 0x4e34f5a0);
#endif
+
if (m_bAvatarsEnabled)
- {
packShortCapability(&packet, 0x134C); // CAP_DEVILS
- }
+
#ifdef DBG_OSCARFT
- {
- packShortCapability(&packet, 0x1343); // CAP_AIM_FILE
- } // Broadcasts the capability to receive Oscar File Transfers
+ // Broadcasts the capability to receive Oscar File Transfers
+ packShortCapability(&packet, 0x1343); // CAP_AIM_FILE
#endif
+
+ // Tells the server we can speak to AIM
if (m_bAimEnabled)
- {
packShortCapability(&packet, 0x134D); // CAP_AIM_COMPATIBLE
- } // Tells the server we can speak to AIM
+
#ifdef DBG_AIMCONTACTSEND
- {
- packShortCapability(&packet, 0x134B); // CAP_SENDBUDDYLIST
- }
+ packShortCapability(&packet, 0x134B); // CAP_SENDBUDDYLIST
#endif
+
if (m_bXStatusEnabled && bXStatus != 0)
- {
- packBuffer(&packet, capXStatus[bXStatus-1], BINARY_CAP_SIZE);
- }
+ packBuffer(&packet, capXStatus[bXStatus - 1], BINARY_CAP_SIZE);
packShortCapability(&packet, 0x1344); // CAP_ICQDIRECT
#ifdef DBG_CAPHTML
packShortCapability(&packet, 0x0002); // CAP_HTMLMSGS
#endif
-
+
packDWord(&packet, 0x4D697261); // Miranda Signature
packDWord(&packet, 0x6E64614E);
@@ -766,16 +717,14 @@ void CIcqProto::setUserInfo()
packWord(&packet, v[3]);
//MIM/PackName
- if ( bHasPackName ) {
+ if (bHasPackName) {
packBuffer(&packet, (BYTE*)dbv.pszVal, 0x10);
db_free(&dbv);
}
- if(!CustomCapList.empty())
- {
- for(std::list<ICQ_CUSTOMCAP*>::iterator it = CustomCapList.begin(), end = CustomCapList.end(); it != end; ++it)
+ if (!CustomCapList.empty())
+ for (std::list<ICQ_CUSTOMCAP*>::iterator it = CustomCapList.begin(), end = CustomCapList.end(); it != end; ++it)
packBuffer(&packet, (BYTE*)(*it)->caps, 0x10);
- }
sendServPacket(&packet);
}
@@ -783,16 +732,13 @@ void CIcqProto::setUserInfo()
void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info)
{
- icq_packet packet;
-
setUserInfo();
/* SNAC 3,4: Tell server who's on our list (deprecated) */
- /* SNAC 3,15: Try to add unauthorised contacts to temporary list */
+ /* SNAC 3,15: Try to add unauthorised contacts to temporary list */
sendEntireListServ(ICQ_BUDDY_FAMILY, ICQ_USER_ADDTOTEMPLIST, BUL_ALLCONTACTS);
- if (m_iDesiredStatus == ID_STATUS_INVISIBLE)
- {
+ if (m_iDesiredStatus == ID_STATUS_INVISIBLE) {
/* Tell server who's on our visible list (deprecated) */
if (!m_bSsiEnabled)
sendEntireListServ(ICQ_BOS_FAMILY, ICQ_CLI_ADDVISIBLE, BUL_VISIBLE);
@@ -800,8 +746,7 @@ void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info)
updateServVisibilityCode(3);
}
- if (m_iDesiredStatus != ID_STATUS_INVISIBLE)
- {
+ if (m_iDesiredStatus != ID_STATUS_INVISIBLE) {
/* Tell server who's on our invisible list (deprecated) */
if (!m_bSsiEnabled)
sendEntireListServ(ICQ_BOS_FAMILY, ICQ_CLI_ADDINVISIBLE, BUL_INVISIBLE);
@@ -810,6 +755,7 @@ void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info)
}
// SNAC 1,1E: Set status
+ icq_packet packet;
{
DWORD dwDirectCookie = rand() ^ (rand() << 16);
@@ -822,8 +768,8 @@ void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info)
char szMoodData[32];
// prepare mood id
- if (m_bMoodsEnabled && bXStatus && moodXStatus[bXStatus-1] != -1)
- mir_snprintf(szMoodData, SIZEOF(szMoodData), "icqmood%d", moodXStatus[bXStatus-1]);
+ if (m_bMoodsEnabled && bXStatus && moodXStatus[bXStatus - 1] != -1)
+ mir_snprintf(szMoodData, SIZEOF(szMoodData), "icqmood%d", moodXStatus[bXStatus - 1]);
else
szMoodData[0] = '\0';
@@ -857,13 +803,11 @@ void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info)
packWord(&packet, 0x0000); // Unknown
packTLVWord(&packet, 0x001F, 0x0000);
- if (wSessionDataLen)
- { // Pack session data
+ if (wSessionDataLen) { // Pack session data
packWord(&packet, 0x1D); // TLV 1D
packWord(&packet, wSessionDataLen); // TLV length
packWord(&packet, 0x02); // Item Type
- if (wStatusNoteLen)
- {
+ if (wStatusNoteLen) {
packWord(&packet, 0x400 | (WORD)(wStatusNoteLen + 4)); // Flags + Item Length
packWord(&packet, wStatusNoteLen); // Text Length
packBuffer(&packet, (LPBYTE)szStatusNote, wStatusNoteLen);
@@ -928,7 +872,7 @@ void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info)
debugLogA(" *** Yeehah, login sequence complete");
// login sequence is complete enter logged-in mode
- info->bLoggedIn = 1;
+ info->bLoggedIn = true;
m_bConnectionLost = false;
// enable auto info-update routine
@@ -966,7 +910,7 @@ void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info)
// Set last xstatus
updateServerCustomStatus(TRUE);
}
- info->isMigrating = 0;
+ info->isMigrating = false;
if (m_bAimEnabled) {
char **szAwayMsg = NULL;
diff --git a/protocols/IcqOscarJ/src/icq_proto.h b/protocols/IcqOscarJ/src/icq_proto.h
index a3fb7b44f9..5c8a254f31 100644
--- a/protocols/IcqOscarJ/src/icq_proto.h
+++ b/protocols/IcqOscarJ/src/icq_proto.h
@@ -219,10 +219,9 @@ struct CIcqProto : public PROTO<CIcqProto>
//----| chan_05ping.cpp |-------------------------------------------------------------
void handlePingChannel(BYTE *buf, WORD wLen);
- void __cdecl KeepAliveThread(void *arg);
-
void StartKeepAlive(serverthread_info *info);
void StopKeepAlive(serverthread_info *info);
+ void CheckKeepAlive(serverthread_info *info);
//----| cookies.cpp |-----------------------------------------------------------------
icq_critical_section *cookieMutex; // we want this in avatar thread, used as queue lock
diff --git a/protocols/IcqOscarJ/src/icq_server.cpp b/protocols/IcqOscarJ/src/icq_server.cpp
index ca86fa0eca..6a1aadeab3 100644
--- a/protocols/IcqOscarJ/src/icq_server.cpp
+++ b/protocols/IcqOscarJ/src/icq_server.cpp
@@ -125,6 +125,8 @@ void __cdecl CIcqProto::ServerThread(serverthread_start_info *infoParam)
if (dwError == ERROR_TIMEOUT) {
if (m_iDesiredStatus == ID_STATUS_OFFLINE)
break;
+
+ CheckKeepAlive(&info);
continue;
}
if (dwError == WSAESHUTDOWN) // ok, we're going offline
diff --git a/protocols/IcqOscarJ/src/icq_server.h b/protocols/IcqOscarJ/src/icq_server.h
index 2559ced355..9d04b0d805 100644
--- a/protocols/IcqOscarJ/src/icq_server.h
+++ b/protocols/IcqOscarJ/src/icq_server.h
@@ -20,13 +20,12 @@
// 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.
-//
// -----------------------------------------------------------------------------
// DESCRIPTION:
//
// Declarations for server thread
-//
// -----------------------------------------------------------------------------
+
#ifndef __ICQ_SERVER_H
#define __ICQ_SERVER_H
@@ -39,9 +38,6 @@ struct serverthread_start_info
struct serverthread_info
{
- struct CIcqProto *ppro;
- int bLoggedIn;
- int isLoginServer;
BYTE szAuthKey[20];
WORD wAuthKeyLen;
WORD wServerPort;
@@ -49,14 +45,17 @@ struct serverthread_info
BYTE *cookieData;
int cookieDataLen;
int newServerSSL;
- int newServerReady;
- int isMigrating;
- int bReinitRecver;
- int bMyAvatarInited;
+ int iKeepalive;
+
+ bool isLoginServer;
+ bool isMigrating;
+ bool isNewServerReady;
+ bool bLoggedIn;
+ bool bReinitRecver;
+ bool bMyAvatarInited;
HANDLE hPacketRecver;
HANDLE hDirectBoundPort;
- HANDLE hKeepAliveEvent;
};
#endif /* __ICQ_SERVER_H */