From 79e46207a78f216b054ece49994e7b260c4e4511 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 20 Jan 2014 14:49:26 +0000 Subject: ICQ: Miranda identifies itself as v.11, allowing pure utf8 packets exchange git-svn-id: http://svn.miranda-ng.org/main/trunk@7790 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/IcqOscarJ/src/chan_04close.cpp | 59 +- protocols/IcqOscarJ/src/directpackets.cpp | 2 +- protocols/IcqOscarJ/src/fam_04message.cpp | 2 +- protocols/IcqOscarJ/src/icq_clients.cpp | 4 +- protocols/IcqOscarJ/src/icq_constants.h | 2 +- protocols/IcqOscarJ/src/icq_direct.cpp | 10 +- protocols/IcqOscarJ/src/icq_proto.cpp | 1003 ++++++++++++----------------- protocols/IcqOscarJ/src/icq_proto.h | 2 +- protocols/IcqOscarJ/src/icq_xtraz.cpp | 210 +++--- protocols/IcqOscarJ/src/stdpackets.cpp | 218 +++---- protocols/IcqOscarJ/src/utilities.cpp | 523 ++++++--------- protocols/IcqOscarJ/src/utilities.h | 4 +- protocols/IcqOscarJ/src/version.h | 6 +- 13 files changed, 814 insertions(+), 1231 deletions(-) (limited to 'protocols/IcqOscarJ') diff --git a/protocols/IcqOscarJ/src/chan_04close.cpp b/protocols/IcqOscarJ/src/chan_04close.cpp index 0eb714feae..873df06cab 100644 --- a/protocols/IcqOscarJ/src/chan_04close.cpp +++ b/protocols/IcqOscarJ/src/chan_04close.cpp @@ -41,10 +41,8 @@ void CIcqProto::handleCloseChannel(BYTE *buf, WORD datalen, serverthread_info *i if (info->isMigrating) handleMigration(info); - if ((!info->bLoggedIn || info->isMigrating) && info->newServerReady) - { - if (!connectNewServer(info)) - { // Connecting failed + if ((!info->bLoggedIn || info->isMigrating) && info->newServerReady) { + if (!connectNewServer(info)) { // Connecting failed if (info->isMigrating) icq_LogUsingErrorCode(LOG_ERROR, GetLastError(), LPGEN("Unable to connect to migrated ICQ communication server")); else @@ -59,12 +57,10 @@ void CIcqProto::handleCloseChannel(BYTE *buf, WORD datalen, serverthread_info *i return; } - if (chain = readIntoTLVChain(&buf, datalen, 0)) - { + if (chain = readIntoTLVChain(&buf, datalen, 0)) { // TLV 9 errors (runtime errors?) WORD wError = chain->getWord(0x09, 1); - if (wError) - { + if (wError) { SetCurrentStatus(ID_STATUS_OFFLINE); handleRuntimeError(wError); @@ -83,8 +79,7 @@ void CIcqProto::handleLoginReply(BYTE *buf, WORD datalen, serverthread_info *inf icq_sendCloseConnection(); // imitate icq5 behaviour - if (!(chain = readIntoTLVChain(&buf, datalen, 0))) - { + if (!(chain = readIntoTLVChain(&buf, datalen, 0))) { debugLogA("Error: Missing chain on close channel"); NetLib_CloseConnection(&hServerConn, TRUE); return; // Invalid data @@ -92,13 +87,11 @@ void CIcqProto::handleLoginReply(BYTE *buf, WORD datalen, serverthread_info *inf // TLV 8 errors (signon errors?) WORD wError = chain->getWord(0x08, 1); - if (wError) - { + if (wError) { handleSignonError(wError); // we return only if the server did not gave us cookie (possible to connect with soft error) - if (!chain->getLength(0x06, 1)) - { + if (!chain->getLength(0x06, 1)) { disposeChain(&chain); SetCurrentStatus(ID_STATUS_OFFLINE); icq_serverDisconnect(FALSE); @@ -116,8 +109,7 @@ void CIcqProto::handleLoginReply(BYTE *buf, WORD datalen, serverthread_info *inf // We dont need this anymore disposeChain(&chain); - if (!info->newServer || !info->cookieData) - { + if (!info->newServer || !info->cookieData) { icq_LogMessage(LOG_FATAL, LPGEN("You could not sign on because the server returned invalid data. Try again.")); SAFE_FREE(&info->newServer); @@ -144,42 +136,34 @@ int CIcqProto::connectNewServer(serverthread_info *info) WORD wServerPort = info->wServerPort; // prepare default port parseServerAddress(info->newServer, &wServerPort); - NETLIBOPENCONNECTION nloc = {0}; + NETLIBOPENCONNECTION nloc = { 0 }; nloc.flags = 0; nloc.szHost = info->newServer; nloc.wPort = wServerPort; - if (!m_bGatewayMode) - { + if (!m_bGatewayMode) { NetLib_SafeCloseHandle(&info->hPacketRecver); NetLib_CloseConnection(&hServerConn, TRUE); debugLogA("Closed connection to login server"); hServerConn = NetLib_OpenConnection(m_hNetlibUser, NULL, &nloc); - if (hServerConn && info->newServerSSL) - { /* Start SSL session if requested */ + if (hServerConn && info->newServerSSL) /* Start SSL session if requested */ if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hServerConn, 0)) NetLib_CloseConnection(&hServerConn, FALSE); - } - if (hServerConn) - { + if (hServerConn) { /* Time to recreate the packet receiver */ info->hPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hServerConn, 0x2400); if (!info->hPacketRecver) - { debugLogA("Error: Failed to create packet receiver."); - } - else // we need to reset receiving structs - { + else { // we need to reset receiving structs info->bReinitRecver = 1; res = 1; } } } - else - { // TODO: We should really do some checks here + else { // TODO: We should really do some checks here debugLogA("Walking in Gateway to %s", info->newServer); // TODO: This REQUIRES more work (most probably some kind of mid-netlib module) icq_httpGatewayWalkTo(hServerConn, &nloc); @@ -199,8 +183,7 @@ void CIcqProto::handleMigration(serverthread_info *info) { // Check the data that was saved when the migration was announced debugLogA("Migrating to %s", info->newServer); - if (!info->newServer || !info->cookieData) - { + if (!info->newServer || !info->cookieData) { icq_LogMessage(LOG_FATAL, LPGEN("You have been disconnected from the ICQ network because the current server shut down.")); SAFE_FREE(&info->newServer); @@ -297,15 +280,11 @@ void CIcqProto::handleSignonError(WORD wError) void CIcqProto::handleRuntimeError(WORD wError) { - switch (wError) - { - + switch (wError) { case 0x01: - { - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_OTHERLOCATION); - icq_LogMessage(LOG_FATAL, LPGEN("You have been disconnected from the ICQ network because you logged on from another location using the same ICQ number.")); - break; - } + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_OTHERLOCATION); + icq_LogMessage(LOG_FATAL, LPGEN("You have been disconnected from the ICQ network because you logged on from another location using the same ICQ number.")); + break; default: icq_LogFatalParam(LPGEN("Unknown runtime error: 0x%02x"), wError); diff --git a/protocols/IcqOscarJ/src/directpackets.cpp b/protocols/IcqOscarJ/src/directpackets.cpp index cf9f698500..d4eb61dbc2 100644 --- a/protocols/IcqOscarJ/src/directpackets.cpp +++ b/protocols/IcqOscarJ/src/directpackets.cpp @@ -81,7 +81,7 @@ DWORD CIcqProto::icq_sendGetAwayMsgDirect(HANDLE hContact, int type) DWORD dwCookie; cookie_message_data *pCookieData; - if (getWord(hContact, "Version", 0) == 9) + if (getWord(hContact, "Version", 0) >= 9) return 0; // v9 DC protocol does not support this message pCookieData = CreateMessageCookie(MTYPE_AUTOAWAY, (BYTE)type); diff --git a/protocols/IcqOscarJ/src/fam_04message.cpp b/protocols/IcqOscarJ/src/fam_04message.cpp index 996f991394..ed84dad0dc 100644 --- a/protocols/IcqOscarJ/src/fam_04message.cpp +++ b/protocols/IcqOscarJ/src/fam_04message.cpp @@ -1637,7 +1637,7 @@ void CIcqProto::handleStatusMsgReply(const char *szPrefix, HANDLE hContact, DWOR // it is probably UTF-8 status reply PROTORECVEVENT pre = {0}; - if (wVersion == 9 || (nMsgFlags & MTF_PLUGIN) && wVersion == 10) + if (wVersion >= 9) if (UTF8_IsValid(szMsg)) pre.flags |= PREF_UTF; diff --git a/protocols/IcqOscarJ/src/icq_clients.cpp b/protocols/IcqOscarJ/src/icq_clients.cpp index c834dd285c..c836b16e3c 100644 --- a/protocols/IcqOscarJ/src/icq_clients.cpp +++ b/protocols/IcqOscarJ/src/icq_clients.cpp @@ -681,7 +681,7 @@ const char* CIcqProto::detectUserClient(HANDLE hContact, int nIsICQ, WORD wUserC else if (szClient == NULL) { // ZA mangled the version, OMG! if (wVersion == 8 && CheckContactCapabilities(hContact, CAPF_XTRAZ) && (MatchCapability(caps, wLen, &capIMSecKey1, 6) || MatchCapability(caps, wLen, &capIMSecKey2, 6))) - wVersion = 9; + wVersion = ICQ_VERSION; // try to determine 2001-2003 versions if (wVersion == 8 && (MatchCapability(caps, wLen, &capComm20012) || CheckContactCapabilities(hContact, CAPF_SRV_RELAY))) { @@ -733,7 +733,7 @@ const char* CIcqProto::detectUserClient(HANDLE hContact, int nIsICQ, WORD wUserC szClient = "imo.im"; //https://imo.im/ - Web IM } // try to determine lite versions - else if (wVersion == 9) { + else if (wVersion >= 9) { if (CheckContactCapabilities(hContact, CAPF_XTRAZ)) { *bClientId = CLID_GENERIC; if (CheckContactCapabilities(hContact, CAPF_OSCAR_FILE)) { diff --git a/protocols/IcqOscarJ/src/icq_constants.h b/protocols/IcqOscarJ/src/icq_constants.h index 5095b781fa..85c0a90665 100644 --- a/protocols/IcqOscarJ/src/icq_constants.h +++ b/protocols/IcqOscarJ/src/icq_constants.h @@ -621,7 +621,7 @@ // Internal Constants #define ICQ_PROTOCOL_NAME LPGEN("ICQ") #define ICQ_PLUG_VERSION PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM) -#define ICQ_VERSION 8 // Protocol version +#define ICQ_VERSION 11 // Protocol version #define DC_TYPE DC_NORMAL // Used for DC settings #define MAX_CONTACTSSEND 15 #define MAX_MESSAGESNACSIZE 8000 diff --git a/protocols/IcqOscarJ/src/icq_direct.cpp b/protocols/IcqOscarJ/src/icq_direct.cpp index 075f07122c..69a610f1b4 100644 --- a/protocols/IcqOscarJ/src/icq_direct.cpp +++ b/protocols/IcqOscarJ/src/icq_direct.cpp @@ -824,23 +824,15 @@ void EncryptDirectPacket(directconnect* dc, icq_packet* p) unsigned long hex; unsigned long size = p->wLen - 1; - if (dc->wVersion < 4) return; // no encryption necessary. - - switch (dc->wVersion) - { + switch (dc->wVersion) { case 4: case 5: offset = 6; break; - case 6: - case 7: - case 8: - case 9: - case 10: default: offset = 0; } diff --git a/protocols/IcqOscarJ/src/icq_proto.cpp b/protocols/IcqOscarJ/src/icq_proto.cpp index 9525e9c16d..e23420b326 100644 --- a/protocols/IcqOscarJ/src/icq_proto.cpp +++ b/protocols/IcqOscarJ/src/icq_proto.cpp @@ -43,20 +43,20 @@ static int CompareConns(const directconnect* p1, const directconnect* p2) return (p1 == p2) ? 0 : 1; } -static int CompareCookies( const icq_cookie_info* p1, const icq_cookie_info* p2 ) +static int CompareCookies(const icq_cookie_info* p1, const icq_cookie_info* p2) { - if ( p1->dwCookie < p2->dwCookie ) + if (p1->dwCookie < p2->dwCookie) return -1; - return ( p1->dwCookie == p2->dwCookie ) ? 0 : 1; + return (p1->dwCookie == p2->dwCookie) ? 0 : 1; } -static int CompareFT( const filetransfer* p1, const filetransfer* p2 ) +static int CompareFT(const filetransfer* p1, const filetransfer* p2) { - if ( p1->dwCookie < p2->dwCookie ) + if (p1->dwCookie < p2->dwCookie) return -1; - return ( p1->dwCookie == p2->dwCookie ) ? 0 : 1; + return (p1->dwCookie == p2->dwCookie) ? 0 : 1; } static int CompareContactsCache(const icq_contacts_cache *p1, const icq_contacts_cache *p2) @@ -70,15 +70,15 @@ static int CompareContactsCache(const icq_contacts_cache *p1, const icq_contacts return stricmpnull(p1->szUid, p2->szUid); } -CIcqProto::CIcqProto( const char* aProtoName, const TCHAR* aUserName ) : - PROTO(aProtoName, aUserName), - cookies(10, CompareCookies), - directConns(10, CompareConns), - expectedFileRecvs(10, CompareFT), - contactsCache(10, CompareContactsCache), - cheekySearchId(-1) +CIcqProto::CIcqProto(const char* aProtoName, const TCHAR* aUserName) : +PROTO(aProtoName, aUserName), +cookies(10, CompareCookies), +directConns(10, CompareConns), +expectedFileRecvs(10, CompareFT), +contactsCache(10, CompareContactsCache), +cheekySearchId(-1) { - debugLogA( "Setting protocol/module name to '%s'", m_szModuleName ); + debugLogA("Setting protocol/module name to '%s'", m_szModuleName); oftMutex = new icq_critical_section(); @@ -122,7 +122,7 @@ CIcqProto::CIcqProto( const char* aProtoName, const TCHAR* aUserName ) : db_set_resident(m_szModuleName, DBSETTING_STATUS_MOOD); // Setup services - CreateProtoService(PS_CREATEACCMGRUI, &CIcqProto::OnCreateAccMgrUI ); + CreateProtoService(PS_CREATEACCMGRUI, &CIcqProto::OnCreateAccMgrUI); CreateProtoService(MS_ICQ_SENDSMS, &CIcqProto::SendSms); CreateProtoService(PS_SET_NICKNAME, &CIcqProto::SetNickName); @@ -172,7 +172,7 @@ CIcqProto::CIcqProto( const char* aProtoName, const TCHAR* aUserName ) : HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &CIcqProto::OnPreBuildStatusMenu); // Register netlib users - NETLIBUSER nlu = {0}; + NETLIBUSER nlu = { 0 }; TCHAR szBuffer[MAX_PATH + 64]; mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s server connection"), m_tszUserName); nlu.cbSize = sizeof(nlu); @@ -197,7 +197,7 @@ CIcqProto::CIcqProto( const char* aProtoName, const TCHAR* aUserName ) : m_hDirectNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); // Register custom database events - DBEVENTTYPEDESCR eventType = {0}; + DBEVENTTYPEDESCR eventType = { 0 }; eventType.cbSize = DBEVENTTYPEDESCR_SIZE; eventType.eventType = ICQEVENTTYPE_MISSEDMESSAGE; eventType.module = m_szModuleName; @@ -267,12 +267,12 @@ CIcqProto::~CIcqProto() //////////////////////////////////////////////////////////////////////////////////////// // OnModulesLoadedEx - performs hook registration -int CIcqProto::OnModulesLoaded( WPARAM wParam, LPARAM lParam ) +int CIcqProto::OnModulesLoaded(WPARAM wParam, LPARAM lParam) { char pszP2PName[MAX_PATH]; char pszGroupsName[MAX_PATH]; char pszSrvGroupsName[MAX_PATH]; - char* modules[5] = {0,0,0,0,0}; + char* modules[5] = { 0, 0, 0, 0, 0 }; mir_snprintf(pszP2PName, SIZEOF(pszP2PName), "%sP2P", m_szModuleName); mir_snprintf(pszGroupsName, SIZEOF(pszGroupsName), "%sGroups", m_szModuleName); @@ -281,7 +281,7 @@ int CIcqProto::OnModulesLoaded( WPARAM wParam, LPARAM lParam ) modules[1] = pszP2PName; modules[2] = pszGroupsName; modules[3] = pszSrvGroupsName; - CallService("DBEditorpp/RegisterModule",(WPARAM)modules,(LPARAM)4); + CallService("DBEditorpp/RegisterModule", (WPARAM)modules, (LPARAM)4); HookProtoEvent(ME_OPT_INITIALISE, &CIcqProto::OnOptionsInit); HookProtoEvent(ME_USERINFO_INITIALISE, &CIcqProto::OnUserInfoInit); @@ -292,8 +292,7 @@ int CIcqProto::OnModulesLoaded( WPARAM wParam, LPARAM lParam ) InitXStatusItems(FALSE); HANDLE hContact = FindFirstContact(); - while (hContact != NULL) - { + while (hContact != NULL) { DWORD bXStatus = getContactXStatus(hContact); if (bXStatus > 0) setContactExtraIcon(hContact, bXStatus); @@ -304,7 +303,7 @@ int CIcqProto::OnModulesLoaded( WPARAM wParam, LPARAM lParam ) return 0; } -int CIcqProto::OnPreShutdown(WPARAM wParam,LPARAM lParam) +int CIcqProto::OnPreShutdown(WPARAM wParam, LPARAM lParam) { // signal info update thread to stop icq_InfoUpdateCleanup(); @@ -317,17 +316,14 @@ int CIcqProto::OnPreShutdown(WPARAM wParam,LPARAM lParam) //////////////////////////////////////////////////////////////////////////////////////// // PS_AddToList - adds a contact to the contact list -HANDLE CIcqProto::AddToList( int flags, PROTOSEARCHRESULT* psr ) +HANDLE CIcqProto::AddToList(int flags, PROTOSEARCHRESULT* psr) { - if (psr) - { - if (psr->cbSize == sizeof(ICQSEARCHRESULT)) - { + if (psr) { + if (psr->cbSize == sizeof(ICQSEARCHRESULT)) { ICQSEARCHRESULT *isr = (ICQSEARCHRESULT*)psr; if (isr->uin) return AddToListByUIN(isr->uin, flags); - else - { // aim contact + else { // aim contact char szUid[MAX_PATH]; if (isr->hdr.flags & PSR_UNICODE) @@ -339,8 +335,7 @@ HANDLE CIcqProto::AddToList( int flags, PROTOSEARCHRESULT* psr ) return AddToListByUID(szUid, flags); } } - else - { + else { char szUid[MAX_PATH]; if (psr->flags & PSR_UNICODE) @@ -359,10 +354,10 @@ HANDLE CIcqProto::AddToList( int flags, PROTOSEARCHRESULT* psr ) return 0; // Failure } -HANDLE __cdecl CIcqProto::AddToListByEvent( int flags, int iContact, HANDLE hDbEvent ) +HANDLE __cdecl CIcqProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent) { DWORD uin = 0; - uid_str uid = {0}; + uid_str uid = { 0 }; DBEVENTINFO dbei = { sizeof(dbei) }; if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == -1) @@ -377,28 +372,26 @@ HANDLE __cdecl CIcqProto::AddToListByEvent( int flags, int iContact, HANDLE hDbE if (strcmpnull(dbei.szModule, m_szModuleName)) return 0; // this event is not ours - switch(dbei.eventType) { + switch (dbei.eventType) { case EVENTTYPE_CONTACTS: - { - char *pbOffset = (char*)dbei.pBlob; - char *pbEnd = pbOffset + dbei.cbBlob; - for (int i = 0; i <= iContact; i++) { - pbOffset += strlennull(pbOffset) + 1; // Nick - if (pbOffset >= pbEnd) break; - if (i == iContact) - { // we found the contact, get uid - if (IsStringUIN((char*)pbOffset)) - uin = atoi((char*)pbOffset); - else - { - uin = 0; - strcpy(uid, (char*)pbOffset); - } - } - pbOffset += strlennull(pbOffset) + 1; // Uin - if (pbOffset >= pbEnd) break; - } - } + { + char *pbOffset = (char*)dbei.pBlob; + char *pbEnd = pbOffset + dbei.cbBlob; + for (int i = 0; i <= iContact; i++) { + pbOffset += strlennull(pbOffset) + 1; // Nick + if (pbOffset >= pbEnd) break; + if (i == iContact) { // we found the contact, get uid + if (IsStringUIN((char*)pbOffset)) + uin = atoi((char*)pbOffset); + else { + uin = 0; + strcpy(uid, (char*)pbOffset); + } + } + pbOffset += strlennull(pbOffset) + 1; // Uin + if (pbOffset >= pbEnd) break; + } + } break; case EVENTTYPE_AUTHREQUEST: @@ -424,11 +417,10 @@ HANDLE __cdecl CIcqProto::AddToListByEvent( int flags, int iContact, HANDLE hDbE //////////////////////////////////////////////////////////////////////////////////////// // PS_AuthAllow - processes the successful authorization -int CIcqProto::Authorize( HANDLE hDbEvent ) +int CIcqProto::Authorize(HANDLE hDbEvent) { - if (icqOnline() && hDbEvent) - { - HANDLE hContact = HContactFromAuthEvent( hDbEvent ); + if (icqOnline() && hDbEvent) { + HANDLE hContact = HContactFromAuthEvent(hDbEvent); if (hContact == INVALID_HANDLE_VALUE) return 1; @@ -451,10 +443,9 @@ int CIcqProto::Authorize( HANDLE hDbEvent ) //////////////////////////////////////////////////////////////////////////////////////// // PS_AuthDeny - handles the unsuccessful authorization -int CIcqProto::AuthDeny( HANDLE hDbEvent, const TCHAR* szReason ) +int CIcqProto::AuthDeny(HANDLE hDbEvent, const TCHAR* szReason) { - if (icqOnline() && hDbEvent) - { + if (icqOnline() && hDbEvent) { HANDLE hContact = HContactFromAuthEvent(hDbEvent); if (hContact == INVALID_HANDLE_VALUE) return 1; @@ -479,30 +470,28 @@ int CIcqProto::AuthDeny( HANDLE hDbEvent, const TCHAR* szReason ) //////////////////////////////////////////////////////////////////////////////////////// // PSR_AUTH -int __cdecl CIcqProto::AuthRecv( HANDLE hContact, PROTORECVEVENT* pre ) +int __cdecl CIcqProto::AuthRecv(HANDLE hContact, PROTORECVEVENT* pre) { - setContactHidden( hContact, 0 ); - ICQAddRecvEvent( NULL, EVENTTYPE_AUTHREQUEST, pre, pre->lParam, (PBYTE)pre->szMessage, 0 ); + setContactHidden(hContact, 0); + ICQAddRecvEvent(NULL, EVENTTYPE_AUTHREQUEST, pre, pre->lParam, (PBYTE)pre->szMessage, 0); return 0; } //////////////////////////////////////////////////////////////////////////////////////// // PSS_AUTHREQUEST -int __cdecl CIcqProto::AuthRequest( HANDLE hContact, const TCHAR* szMessage ) +int __cdecl CIcqProto::AuthRequest(HANDLE hContact, const TCHAR* szMessage) { - if ( !icqOnline()) + if (!icqOnline()) return 1; - if (hContact) - { + if (hContact) { DWORD dwUin; uid_str szUid; if (getContactUid(hContact, &dwUin, &szUid)) return 1; // Invalid contact - if (dwUin) - { + if (dwUin) { char *utf = tchar_to_utf8(szMessage); icq_sendAuthReqServ(dwUin, szUid, utf); SAFE_FREE(&utf); @@ -517,7 +506,7 @@ int __cdecl CIcqProto::AuthRequest( HANDLE hContact, const TCHAR* szMessage ) //////////////////////////////////////////////////////////////////////////////////////// // ChangeInfo -HANDLE __cdecl CIcqProto::ChangeInfo( int iInfoType, void* pInfoData ) +HANDLE __cdecl CIcqProto::ChangeInfo(int iInfoType, void* pInfoData) { return NULL; } @@ -526,7 +515,7 @@ HANDLE __cdecl CIcqProto::ChangeInfo( int iInfoType, void* pInfoData ) //////////////////////////////////////////////////////////////////////////////////////// // PS_FileAllow - starts a file transfer -HANDLE __cdecl CIcqProto::FileAllow( HANDLE hContact, HANDLE hTransfer, const TCHAR* szPath ) +HANDLE __cdecl CIcqProto::FileAllow(HANDLE hContact, HANDLE hTransfer, const TCHAR* szPath) { DWORD dwUin; uid_str szUid; @@ -534,15 +523,13 @@ HANDLE __cdecl CIcqProto::FileAllow( HANDLE hContact, HANDLE hTransfer, const TC if (getContactUid(hContact, &dwUin, &szUid)) return 0; // Invalid contact - if (icqOnline() && hContact && szPath && hTransfer) - { // approve old fashioned file transfer + if (icqOnline() && hContact && szPath && hTransfer) { // approve old fashioned file transfer basic_filetransfer *ft = (basic_filetransfer *)hTransfer; if (!IsValidFileTransfer(ft)) return 0; // Invalid transfer - if (dwUin && ft->ft_magic == FT_MAGIC_ICQ) - { + if (dwUin && ft->ft_magic == FT_MAGIC_ICQ) { filetransfer *ft = (filetransfer *)hTransfer; ft->szSavePath = tchar_to_utf8(szPath); @@ -559,8 +546,7 @@ HANDLE __cdecl CIcqProto::FileAllow( HANDLE hContact, HANDLE hTransfer, const TC return hTransfer; // Success } - else if (ft->ft_magic == FT_MAGIC_OSCAR) - { // approve oscar file transfer + else if (ft->ft_magic == FT_MAGIC_OSCAR) { // approve oscar file transfer return oftFileAllow(hContact, hTransfer, szPath); } } @@ -572,28 +558,25 @@ HANDLE __cdecl CIcqProto::FileAllow( HANDLE hContact, HANDLE hTransfer, const TC //////////////////////////////////////////////////////////////////////////////////////// // PS_FileCancel - cancels a file transfer -int __cdecl CIcqProto::FileCancel( HANDLE hContact, HANDLE hTransfer ) +int __cdecl CIcqProto::FileCancel(HANDLE hContact, HANDLE hTransfer) { DWORD dwUin; uid_str szUid; - if ( getContactUid(hContact, &dwUin, &szUid)) + if (getContactUid(hContact, &dwUin, &szUid)) return 1; // Invalid contact - if (hContact && hTransfer) - { + if (hContact && hTransfer) { basic_filetransfer *ft = (basic_filetransfer *)hTransfer; if (!IsValidFileTransfer(ft)) return 1; // Invalid transfer - if (dwUin && ft->ft_magic == FT_MAGIC_ICQ) - { // cancel old fashioned file transfer + if (dwUin && ft->ft_magic == FT_MAGIC_ICQ) { // cancel old fashioned file transfer filetransfer * ft = (filetransfer*)hTransfer; icq_CancelFileTransfer(hContact, ft); return 0; // Success } - else if (ft->ft_magic == FT_MAGIC_OSCAR) - { // cancel oscar file transfer + else if (ft->ft_magic == FT_MAGIC_OSCAR) { // cancel oscar file transfer return oftFileCancel(hContact, hTransfer); } } @@ -605,7 +588,7 @@ int __cdecl CIcqProto::FileCancel( HANDLE hContact, HANDLE hTransfer ) //////////////////////////////////////////////////////////////////////////////////////// // PS_FileDeny - denies a file transfer -int __cdecl CIcqProto::FileDeny( HANDLE hContact, HANDLE hTransfer, const TCHAR* szReason ) +int __cdecl CIcqProto::FileDeny(HANDLE hContact, HANDLE hTransfer, const TCHAR* szReason) { int nReturnValue = 1; DWORD dwUin; @@ -615,13 +598,11 @@ int __cdecl CIcqProto::FileDeny( HANDLE hContact, HANDLE hTransfer, const TCHAR* if (getContactUid(hContact, &dwUin, &szUid)) return 1; // Invalid contact - if (icqOnline() && hTransfer && hContact) - { + if (icqOnline() && hTransfer && hContact) { if (!IsValidFileTransfer(hTransfer)) return 1; // Invalid transfer - if (dwUin && ft->ft_magic == FT_MAGIC_ICQ) - { // deny old fashioned file transfer + if (dwUin && ft->ft_magic == FT_MAGIC_ICQ) { // deny old fashioned file transfer filetransfer *ft = (filetransfer*)hTransfer; char *szReasonUtf = tchar_to_utf8(szReason); // Was request received thru DC and have we a open DC, send through that @@ -633,8 +614,7 @@ int __cdecl CIcqProto::FileDeny( HANDLE hContact, HANDLE hTransfer, const TCHAR* nReturnValue = 0; // Success } - else if (ft->ft_magic == FT_MAGIC_OSCAR) - { // deny oscar file transfer + else if (ft->ft_magic == FT_MAGIC_OSCAR) { // deny oscar file transfer return oftFileDeny(hContact, hTransfer, szReason); } } @@ -648,23 +628,20 @@ int __cdecl CIcqProto::FileDeny( HANDLE hContact, HANDLE hTransfer, const TCHAR* //////////////////////////////////////////////////////////////////////////////////////// // PS_FileResume - processes file renaming etc -int __cdecl CIcqProto::FileResume( HANDLE hTransfer, int* action, const TCHAR** szFilename ) +int __cdecl CIcqProto::FileResume(HANDLE hTransfer, int* action, const TCHAR** szFilename) { - if (icqOnline() && hTransfer) - { + if (icqOnline() && hTransfer) { basic_filetransfer *ft = (basic_filetransfer *)hTransfer; if (!IsValidFileTransfer(ft)) return 1; // Invalid transfer - if (ft->ft_magic == FT_MAGIC_ICQ) - { + if (ft->ft_magic == FT_MAGIC_ICQ) { char *szFileNameUtf = tchar_to_utf8(*szFilename); icq_sendFileResume((filetransfer *)hTransfer, *action, szFileNameUtf); SAFE_FREE(&szFileNameUtf); } - else if (ft->ft_magic == FT_MAGIC_OSCAR) - { + else if (ft->ft_magic == FT_MAGIC_OSCAR) { oftFileResume((oscar_filetransfer *)hTransfer, *action, *szFilename); } else @@ -680,11 +657,11 @@ int __cdecl CIcqProto::FileResume( HANDLE hTransfer, int* action, const TCHAR** //////////////////////////////////////////////////////////////////////////////////////// // GetCaps - return protocol capabilities bits -DWORD_PTR __cdecl CIcqProto::GetCaps( int type, HANDLE hContact ) +DWORD_PTR __cdecl CIcqProto::GetCaps(int type, HANDLE hContact) { DWORD_PTR nReturn = 0; - switch ( type ) { + switch (type) { case PFLAGNUM_1: nReturn = PF1_IM | PF1_URL | PF1_AUTHREQ | PF1_BASICSEARCH | PF1_ADDSEARCHRES | @@ -733,19 +710,16 @@ DWORD_PTR __cdecl CIcqProto::GetCaps( int type, HANDLE hContact ) break; case PFLAG_MAXCONTACTSPERPACKET: - if ( hContact ) - { // determine per contact + if (hContact) { // determine per contact BYTE bClientId = getByte(hContact, "ClientID", CLID_GENERIC); - if (bClientId == CLID_MIRANDA) - { + if (bClientId == CLID_MIRANDA) { if (CheckContactCapabilities(hContact, CAPF_CONTACTS) && getContactStatus(hContact) != ID_STATUS_OFFLINE) nReturn = 0x100; // limited only by packet size else nReturn = MAX_CONTACTSSEND; } - else if (bClientId == CLID_ICQ6) - { + else if (bClientId == CLID_ICQ6) { if (CheckContactCapabilities(hContact, CAPF_CONTACTS)) nReturn = 1; // crapy ICQ6 cannot handle multiple contacts in the transfer else @@ -759,7 +733,7 @@ DWORD_PTR __cdecl CIcqProto::GetCaps( int type, HANDLE hContact ) break; case PFLAG_MAXLENOFMESSAGE: - nReturn = MAX_MESSAGESNACSIZE-102; + nReturn = MAX_MESSAGESNACSIZE - 102; } return nReturn; @@ -770,8 +744,7 @@ DWORD_PTR __cdecl CIcqProto::GetCaps( int type, HANDLE hContact ) int __cdecl CIcqProto::GetInfo(HANDLE hContact, int infoType) { - if (icqOnline()) - { + if (icqOnline()) { DWORD dwUin; uid_str szUid; @@ -793,19 +766,17 @@ int __cdecl CIcqProto::GetInfo(HANDLE hContact, int infoType) //////////////////////////////////////////////////////////////////////////////////////// // SearchBasic - searches the contact by UID -void CIcqProto::CheekySearchThread( void* ) +void CIcqProto::CheekySearchThread(void*) { char szUin[UINMAXLEN]; - ICQSEARCHRESULT isr = {0}; + ICQSEARCHRESULT isr = { 0 }; isr.hdr.cbSize = sizeof(isr); - if (cheekySearchUin) - { + if (cheekySearchUin) { _itoa(cheekySearchUin, szUin, 10); isr.hdr.id = (FNAMECHAR*)szUin; } - else - { + else { isr.hdr.id = (FNAMECHAR*)cheekySearchUid; } isr.uin = cheekySearchUin; @@ -816,7 +787,7 @@ void CIcqProto::CheekySearchThread( void* ) } -HANDLE __cdecl CIcqProto::SearchBasic( const PROTOCHAR *pszSearch ) +HANDLE __cdecl CIcqProto::SearchBasic(const PROTOCHAR *pszSearch) { if (strlennull(pszSearch) == 0) return 0; @@ -825,23 +796,17 @@ HANDLE __cdecl CIcqProto::SearchBasic( const PROTOCHAR *pszSearch ) int nHandle = 0; int i, j; - if (!m_bAimEnabled) - { - for (i=j=0; (i=0x30) && (pszSearch[i]<=0x39)) - { + if (!m_bAimEnabled) { + for (i = j = 0; (i < strlennull(pszSearch)) && (j < 255); i++) { // we take only numbers + if ((pszSearch[i] >= 0x30) && (pszSearch[i] <= 0x39)) { pszUIN[j] = pszSearch[i]; j++; } } } - else - { - for (i=j=0; (i= 0x80) continue; pszUIN[j] = pszSearch[i]; j++; @@ -850,8 +815,7 @@ HANDLE __cdecl CIcqProto::SearchBasic( const PROTOCHAR *pszSearch ) } pszUIN[j] = 0; - if (strlennull(pszUIN)) - { + if (strlennull(pszUIN)) { DWORD dwUin; if (IsStringUIN(pszUIN)) dwUin = atoi(pszUIN); @@ -859,16 +823,14 @@ HANDLE __cdecl CIcqProto::SearchBasic( const PROTOCHAR *pszSearch ) dwUin = 0; // Cheeky instant UIN search - if (!dwUin || GetKeyState(VK_CONTROL)&0x8000) - { + if (!dwUin || GetKeyState(VK_CONTROL) & 0x8000) { cheekySearchId = GenerateCookie(0); cheekySearchUin = dwUin; cheekySearchUid = null_strdup(pszUIN); ForkThread(&CIcqProto::CheekySearchThread, 0); // The caller needs to get this return value before the results nHandle = cheekySearchId; } - else if (icqOnline()) - { + else if (icqOnline()) { nHandle = SearchByUin(dwUin); } @@ -883,10 +845,9 @@ HANDLE __cdecl CIcqProto::SearchBasic( const PROTOCHAR *pszSearch ) //////////////////////////////////////////////////////////////////////////////////////// // SearchByEmail - searches the contact by its e-mail -HANDLE __cdecl CIcqProto::SearchByEmail( const PROTOCHAR *email ) +HANDLE __cdecl CIcqProto::SearchByEmail(const PROTOCHAR *email) { - if (email && icqOnline() && strlennull(email) > 0) - { + if (email && icqOnline() && strlennull(email) > 0) { DWORD dwSearchId, dwSecId; char *szEmail = tchar_to_ansi(email); @@ -900,9 +861,9 @@ HANDLE __cdecl CIcqProto::SearchByEmail( const PROTOCHAR *email ) SAFE_FREE(&szEmail); if (dwSearchId) - return ( HANDLE )dwSearchId; + return (HANDLE)dwSearchId; else - return ( HANDLE )dwSecId; + return (HANDLE)dwSecId; } return 0; // Failure @@ -913,10 +874,8 @@ HANDLE __cdecl CIcqProto::SearchByEmail( const PROTOCHAR *email ) HANDLE __cdecl CIcqProto::SearchByName(const PROTOCHAR *nick, const PROTOCHAR *firstName, const PROTOCHAR *lastName) { - if (icqOnline()) - { - if (nick || firstName || lastName) - { + if (icqOnline()) { + if (nick || firstName || lastName) { char *nickUtf = tchar_to_utf8(nick); char *firstNameUtf = tchar_to_utf8(firstName); char *lastNameUtf = tchar_to_utf8(lastName); @@ -936,7 +895,7 @@ HANDLE __cdecl CIcqProto::SearchByName(const PROTOCHAR *nick, const PROTOCHAR *f } -HWND __cdecl CIcqProto::CreateExtendedSearchUI( HWND parent ) +HWND __cdecl CIcqProto::CreateExtendedSearchUI(HWND parent) { if (parent && hInst) return CreateDialog(hInst, MAKEINTRESOURCE(IDD_ICQADVANCEDSEARCH), parent, AdvancedSearchDlgProc); @@ -944,18 +903,16 @@ HWND __cdecl CIcqProto::CreateExtendedSearchUI( HWND parent ) return NULL; // Failure } -HWND __cdecl CIcqProto::SearchAdvanced( HWND hwndDlg ) +HWND __cdecl CIcqProto::SearchAdvanced(HWND hwndDlg) { - if (icqOnline() && IsWindow(hwndDlg)) - { + if (icqOnline() && IsWindow(hwndDlg)) { int nDataLen; BYTE* bySearchData; - if (bySearchData = createAdvancedSearchStructure(hwndDlg, &nDataLen)) - { + if (bySearchData = createAdvancedSearchStructure(hwndDlg, &nDataLen)) { int result = icq_sendAdvancedSearchServ(bySearchData, nDataLen); SAFE_FREE((void**)&bySearchData); - return ( HWND )result; // Success + return (HWND)result; // Success } } @@ -966,7 +923,7 @@ HWND __cdecl CIcqProto::SearchAdvanced( HWND hwndDlg ) //////////////////////////////////////////////////////////////////////////////////////// // RecvContacts -int __cdecl CIcqProto::RecvContacts( HANDLE hContact, PROTORECVEVENT* pre ) +int __cdecl CIcqProto::RecvContacts(HANDLE hContact, PROTORECVEVENT* pre) { ICQSEARCHRESULT **isrList = (ICQSEARCHRESULT**)pre->szMessage; int i; @@ -976,8 +933,7 @@ int __cdecl CIcqProto::RecvContacts( HANDLE hContact, PROTORECVEVENT* pre ) if (pre->flags & PREF_UTF || pre->flags & PREF_UNICODE) flags |= DBEF_UTF; - for (i = 0; i < pre->lParam; i++) - { + for (i = 0; i < pre->lParam; i++) { if (pre->flags & PREF_UNICODE) cbBlob += get_utf8_size((WCHAR*)isrList[i]->hdr.nick) + 2; else @@ -990,21 +946,18 @@ int __cdecl CIcqProto::RecvContacts( HANDLE hContact, PROTORECVEVENT* pre ) cbBlob += strlennull((char*)isrList[i]->hdr.id); } PBYTE pBlob = (PBYTE)_alloca(cbBlob), pCurBlob; - for (i = 0, pCurBlob = pBlob; i < pre->lParam; i++) - { + for (i = 0, pCurBlob = pBlob; i < pre->lParam; i++) { if (pre->flags & PREF_UNICODE) make_utf8_string_static((WCHAR*)isrList[i]->hdr.nick, (char*)pCurBlob, cbBlob - (pCurBlob - pBlob)); else strcpy((char*)pCurBlob, (char*)isrList[i]->hdr.nick); pCurBlob += strlennull((char*)pCurBlob) + 1; - if (isrList[i]->uin) - { + if (isrList[i]->uin) { char szUin[UINMAXLEN]; _itoa(isrList[i]->uin, szUin, 10); strcpy((char*)pCurBlob, szUin); } - else - { // aim contact + else { // aim contact if (pre->flags & PREF_UNICODE) unicode_to_ansi_static((WCHAR*)isrList[i]->hdr.id, (char*)pCurBlob, cbBlob - (pCurBlob - pBlob)); else @@ -1021,7 +974,7 @@ int __cdecl CIcqProto::RecvContacts( HANDLE hContact, PROTORECVEVENT* pre ) //////////////////////////////////////////////////////////////////////////////////////// // RecvFile -int __cdecl CIcqProto::RecvFile( HANDLE hContact, PROTORECVFILET* evt ) +int __cdecl CIcqProto::RecvFile(HANDLE hContact, PROTORECVFILET* evt) { return Proto_RecvFile(hContact, evt); } @@ -1030,7 +983,7 @@ int __cdecl CIcqProto::RecvFile( HANDLE hContact, PROTORECVFILET* evt ) //////////////////////////////////////////////////////////////////////////////////////// // RecvMsg -int __cdecl CIcqProto::RecvMsg( HANDLE hContact, PROTORECVEVENT* pre ) +int __cdecl CIcqProto::RecvMsg(HANDLE hContact, PROTORECVEVENT* pre) { DWORD cbBlob; DWORD flags = 0; @@ -1040,7 +993,7 @@ int __cdecl CIcqProto::RecvMsg( HANDLE hContact, PROTORECVEVENT* pre ) if ((pre->flags & PREF_UTF) && !IsUSASCII(pre->szMessage, strlennull(pre->szMessage))) flags |= DBEF_UTF; // process unicode ucs-2 messages - if ((pre->flags & PREF_UNICODE) && !IsUnicodeAscii((WCHAR*)(pre->szMessage+cbBlob), strlennull((WCHAR*)(pre->szMessage+cbBlob)))) + if ((pre->flags & PREF_UNICODE) && !IsUnicodeAscii((WCHAR*)(pre->szMessage + cbBlob), strlennull((WCHAR*)(pre->szMessage + cbBlob)))) cbBlob *= (sizeof(WCHAR)+1); ICQAddRecvEvent(hContact, EVENTTYPE_MESSAGE, pre, cbBlob, (PBYTE)pre->szMessage, flags); @@ -1056,7 +1009,7 @@ int __cdecl CIcqProto::RecvMsg( HANDLE hContact, PROTORECVEVENT* pre ) //////////////////////////////////////////////////////////////////////////////////////// // RecvUrl -int __cdecl CIcqProto::RecvUrl( HANDLE hContact, PROTORECVEVENT* ) +int __cdecl CIcqProto::RecvUrl(HANDLE hContact, PROTORECVEVENT*) { return 1; } @@ -1065,37 +1018,31 @@ int __cdecl CIcqProto::RecvUrl( HANDLE hContact, PROTORECVEVENT* ) //////////////////////////////////////////////////////////////////////////////////////// // SendContacts -int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, HANDLE* hContactsList ) +int __cdecl CIcqProto::SendContacts(HANDLE hContact, int flags, int nContacts, HANDLE* hContactsList) { - if (hContact && hContactsList) - { + if (hContact && hContactsList) { int i; DWORD dwUin; uid_str szUid; WORD wRecipientStatus; DWORD dwCookie; - if (getContactUid(hContact, &dwUin, &szUid)) - { // Invalid contact + if (getContactUid(hContact, &dwUin, &szUid)) { // Invalid contact return ReportGenericSendError(hContact, ACKTYPE_CONTACTS, "The receiver has an invalid user ID."); } wRecipientStatus = getContactStatus(hContact); // Failures - if (!icqOnline()) - { + if (!icqOnline()) { dwCookie = ReportGenericSendError(hContact, ACKTYPE_CONTACTS, "You cannot send messages when you are offline."); } - else if (!hContactsList || (nContacts < 1) || (nContacts > MAX_CONTACTSSEND)) - { + else if (!hContactsList || (nContacts < 1) || (nContacts > MAX_CONTACTSSEND)) { dwCookie = ReportGenericSendError(hContact, ACKTYPE_CONTACTS, "Bad data (internal error #1)"); } // OK - else - { - if (CheckContactCapabilities(hContact, CAPF_CONTACTS) && wRecipientStatus != ID_STATUS_OFFLINE) - { // Use the new format if possible + else { + if (CheckContactCapabilities(hContact, CAPF_CONTACTS) && wRecipientStatus != ID_STATUS_OFFLINE) { // Use the new format if possible int nDataLen, nNamesLen; struct icq_contactsend_s* contacts = NULL; @@ -1106,22 +1053,20 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, ZeroMemory(contacts, sizeof(struct icq_contactsend_s)*nContacts); { nDataLen = 0; nNamesLen = 0; - for (i = 0; i < nContacts; i++) - { + for (i = 0; i < nContacts; i++) { uid_str szContactUid; if (!IsICQContact(hContactsList[i])) break; // Abort if a non icq contact is found if (getContactUid(hContactsList[i], &contacts[i].uin, &szContactUid)) break; // Abort if invalid contact - contacts[i].uid = contacts[i].uin?NULL:null_strdup(szContactUid); + contacts[i].uid = contacts[i].uin ? NULL : null_strdup(szContactUid); contacts[i].szNick = NickFromHandleUtf(hContactsList[i]); nDataLen += getUIDLen(contacts[i].uin, contacts[i].uid) + 4; nNamesLen += strlennull(contacts[i].szNick) + 8; } - if (i == nContacts) - { + if (i == nContacts) { icq_packet mData, mNames; #ifdef _DEBUG @@ -1150,8 +1095,7 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, // all contacts in one group packWord(&mData, (WORD)nContacts); packWord(&mNames, (WORD)nContacts); - for (i = 0; i < nContacts; i++) - { + for (i = 0; i < nContacts; i++) { uid_str szContactUid; WORD wLen; @@ -1172,15 +1116,13 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, } // Cleanup temporary list - for(i = 0; i < nContacts; i++) - { + for (i = 0; i < nContacts; i++) { SAFE_FREE(&contacts[i].szNick); SAFE_FREE(&contacts[i].uid); } // Rate check - if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) - { // rate is too high, the message will not go thru... + if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) { // rate is too high, the message will not go thru... SAFE_FREE((void**)&mData.pData); SAFE_FREE((void**)&mNames.pData); @@ -1197,8 +1139,7 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, dwCookie = icq_SendChannel2Contacts(dwUin, szUid, hContact, (char*)mData.pData, mData.wPlace, (char*)mNames.pData, mNames.wPlace, pCookieData); // This will stop the message dialog from waiting for the real message delivery ack - if (pCookieData->nAckType == ACKTYPE_NONE) - { + if (pCookieData->nAckType == ACKTYPE_NONE) { SendProtoAck(hContact, dwCookie, ACKRESULT_SUCCESS, ACKTYPE_CONTACTS, NULL); // We need to free this here since we will never see the real ack // The actual cookie value will still have to be returned to the message dialog though @@ -1208,20 +1149,17 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, SAFE_FREE((void**)&mData.pData); SAFE_FREE((void**)&mNames.pData); } - else - { + else { dwCookie = ReportGenericSendError(hContact, ACKTYPE_CONTACTS, "Bad data (internal error #2)"); } - for(i = 0; i < nContacts; i++) - { + for (i = 0; i < nContacts; i++) { SAFE_FREE(&contacts[i].szNick); SAFE_FREE(&contacts[i].uid); } } } - else if (dwUin) - { // old format is only understood by ICQ clients + else if (dwUin) { // old format is only understood by ICQ clients int nBodyLength; char szContactUin[UINMAXLEN]; char szCount[17]; @@ -1236,21 +1174,19 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, ZeroMemory(contacts, sizeof(struct icq_contactsend_s)*nContacts); { nBodyLength = 0; - for (i = 0; i < nContacts; i++) - { + for (i = 0; i < nContacts; i++) { if (!IsICQContact(hContactsList[i])) break; // Abort if a non icq contact is found if (getContactUid(hContactsList[i], &contacts[i].uin, &szContactUid)) break; // Abort if invalid contact - contacts[i].uid = contacts[i].uin?NULL:null_strdup(szContactUid); + contacts[i].uid = contacts[i].uin ? NULL : null_strdup(szContactUid); contacts[i].szNick = NickFromHandle(hContactsList[i]); // Compute this contact's length nBodyLength += getUIDLen(contacts[i].uin, contacts[i].uid) + 1; nBodyLength += strlennull(contacts[i].szNick) + 1; } - if (i == nContacts) - { + if (i == nContacts) { char* pBody; char* pBuffer; @@ -1266,10 +1202,8 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, null_strcpy(pBuffer, szCount, nBodyLength - 1); pBuffer += strlennull(pBuffer); *pBuffer++ = (char)0xFE; - for (i = 0; i < nContacts; i++) - { - if (contacts[i].uin) - { + for (i = 0; i < nContacts; i++) { + if (contacts[i].uin) { _itoa(contacts[i].uin, szContactUin, 10); strcpy(pBuffer, szContactUin); } @@ -1282,8 +1216,7 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, *pBuffer++ = (char)0xFE; } - for (i = 0; i < nContacts; i++) - { // release memory + for (i = 0; i < nContacts; i++) { // release memory SAFE_FREE(&contacts[i].szNick); SAFE_FREE(&contacts[i].uid); } @@ -1291,12 +1224,10 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, // Set up the ack type cookie_message_data *pCookieData = CreateMessageCookieData(MTYPE_CONTACTS, hContact, dwUin, TRUE); - if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) - { + if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) { int iRes = icq_SendDirectMessage(hContact, pBody, nBodyLength, 1, pCookieData, NULL); - if (iRes) - { + if (iRes) { SAFE_FREE((void**)&pBody); return iRes; // we succeded, return @@ -1304,21 +1235,20 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, } // Rate check - if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) - { // rate is too high, the message will not go thru... + if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) { // rate is too high, the message will not go thru... SAFE_FREE((void**)&pCookieData); SAFE_FREE((void**)&pBody); return ReportGenericSendError(hContact, ACKTYPE_CONTACTS, "The message could not be delivered. You are sending too fast. Wait a while and try again."); } // Select channel and send -/* - if (!CheckContactCapabilities(hContact, CAPF_SRV_RELAY) || wRecipientStatus == ID_STATUS_OFFLINE) - { - dwCookie = icq_SendChannel4Message(dwUin, hContact, MTYPE_CONTACTS, (WORD)nBodyLength, pBody, pCookieData); - } - else -*/ + /* + if (!CheckContactCapabilities(hContact, CAPF_SRV_RELAY) || wRecipientStatus == ID_STATUS_OFFLINE) + { + dwCookie = icq_SendChannel4Message(dwUin, hContact, MTYPE_CONTACTS, (WORD)nBodyLength, pBody, pCookieData); + } + else + */ { WORD wPriority; @@ -1331,8 +1261,7 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, } // This will stop the message dialog from waiting for the real message delivery ack - if (pCookieData->nAckType == ACKTYPE_NONE) - { + if (pCookieData->nAckType == ACKTYPE_NONE) { SendProtoAck(hContact, dwCookie, ACKRESULT_SUCCESS, ACKTYPE_CONTACTS, NULL); // We need to free this here since we will never see the real ack // The actual cookie value will still have to be returned to the message dialog though @@ -1340,14 +1269,12 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, } SAFE_FREE((void**)&pBody); } - else - { + else { dwCookie = ReportGenericSendError(hContact, ACKTYPE_CONTACTS, "Bad data (internal error #2)"); } } } - else - { + else { dwCookie = ReportGenericSendError(hContact, ACKTYPE_CONTACTS, "The reciever does not support receiving of contacts."); } } @@ -1362,44 +1289,39 @@ int __cdecl CIcqProto::SendContacts( HANDLE hContact, int flags, int nContacts, //////////////////////////////////////////////////////////////////////////////////////// // SendFile - sends a file -HANDLE __cdecl CIcqProto::SendFile( HANDLE hContact, const TCHAR* szDescription, TCHAR** ppszFiles ) +HANDLE __cdecl CIcqProto::SendFile(HANDLE hContact, const TCHAR* szDescription, TCHAR** ppszFiles) { - if ( !icqOnline()) + if (!icqOnline()) return 0; - if (hContact && szDescription && ppszFiles) - { + if (hContact && szDescription && ppszFiles) { DWORD dwUin; uid_str szUid; if (getContactUid(hContact, &dwUin, &szUid)) return 0; // Invalid contact - if (getContactStatus(hContact) != ID_STATUS_OFFLINE) - { + if (getContactStatus(hContact) != ID_STATUS_OFFLINE) { if (CheckContactCapabilities(hContact, CAPF_OSCAR_FILE)) return oftInitTransfer(hContact, dwUin, szUid, (LPCTSTR*)ppszFiles, szDescription); - if (dwUin) - { + if (dwUin) { WORD wClientVersion = getWord(hContact, "Version", 7); if (wClientVersion < 7) debugLogA("IcqSendFile() can't send to version %u", wClientVersion); - else - { + else { int i; filetransfer* ft; struct _stat statbuf; // Initialize filetransfer struct - ft = CreateFileTransfer(hContact, dwUin, (wClientVersion == 7) ? 7: 8); + ft = CreateFileTransfer(hContact, dwUin, (wClientVersion == 7) ? 7 : 8); for (ft->dwFileCount = 0; ppszFiles[ft->dwFileCount]; ft->dwFileCount++); - ft->pszFiles = (char **)SAFE_MALLOC(sizeof(char *) * ft->dwFileCount); + ft->pszFiles = (char **)SAFE_MALLOC(sizeof(char *)* ft->dwFileCount); ft->dwTotalSize = 0; - for (i = 0; i < (int)ft->dwFileCount; i++) - { + for (i = 0; i < (int)ft->dwFileCount; i++) { ft->pszFiles[i] = (ppszFiles[i]) ? tchar_to_utf8(ppszFiles[i]) : NULL; if (_tstat(ppszFiles[i], &statbuf)) @@ -1423,36 +1345,30 @@ HANDLE __cdecl CIcqProto::SendFile( HANDLE hContact, const TCHAR* szDescription, debugLogA("Init file send"); - if (ft->dwFileCount == 1) - { + if (ft->dwFileCount == 1) { pszFiles = strchr(ft->pszFiles[0], '\\'); if (pszFiles) pszFiles++; else pszFiles = ft->pszFiles[0]; } - else - { + else { mir_snprintf(szFiles, SIZEOF(szFiles), ICQTranslateUtfStatic("%d Files", tmp, SIZEOF(tmp)), ft->dwFileCount); pszFiles = szFiles; } // Send packet { - if (ft->nVersion == 7) - { - if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) - { + if (ft->nVersion == 7) { + if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) { int iRes = icq_sendFileSendDirectv7(ft, pszFiles); if (iRes) return ft; // Success } debugLogA("Sending v%u file transfer request through server", 7); icq_sendFileSendServv7(ft, pszFiles); } - else - { - if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) - { + else { + if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) { int iRes = icq_sendFileSendDirectv8(ft, pszFiles); if (iRes) return ft; // Success } @@ -1475,99 +1391,90 @@ HANDLE __cdecl CIcqProto::SendFile( HANDLE hContact, const TCHAR* szDescription, //////////////////////////////////////////////////////////////////////////////////////// // PS_SendMessage - sends a message -int __cdecl CIcqProto::SendMsg( HANDLE hContact, int flags, const char* pszSrc ) +int __cdecl CIcqProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc) { - if (hContact && pszSrc) - { - DWORD dwCookie; - char* puszText = NULL; - int bNeedFreeU = 0; - cookie_message_data *pCookieData = NULL; + if (hContact == NULL || pszSrc == NULL) + return NULL; - // Invalid contact - DWORD dwUin; - uid_str szUID; - if (getContactUid(hContact, &dwUin, &szUID)) - return ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The receiver has an invalid user ID."); + DWORD dwCookie; + char* puszText = NULL; + int bNeedFreeU = 0; + cookie_message_data *pCookieData = NULL; - if (flags & PREF_UNICODE) - { - puszText = make_utf8_string((WCHAR*)(pszSrc + strlennull(pszSrc) + 1)); // get the UTF-16 part - bNeedFreeU = 1; - } - else if (flags & PREF_UTF) - puszText = (char*)pszSrc; - else - { - puszText = (char*)ansi_to_utf8(pszSrc); - bNeedFreeU = 1; - } + // Invalid contact + DWORD dwUin; + uid_str szUID; + if (getContactUid(hContact, &dwUin, &szUID)) + return ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The receiver has an invalid user ID."); - WORD wRecipientStatus = getContactStatus(hContact); + if (flags & PREF_UNICODE) { + puszText = make_utf8_string((WCHAR*)(pszSrc + strlennull(pszSrc) + 1)); // get the UTF-16 part + bNeedFreeU = 1; + } + else if (flags & PREF_UTF) + puszText = (char*)pszSrc; + else { + puszText = (char*)ansi_to_utf8(pszSrc); + bNeedFreeU = 1; + } - BOOL plain_ascii = IsUSASCII(puszText, strlennull(puszText)); + WORD wRecipientStatus = getContactStatus(hContact); - BOOL oldAnsi = plain_ascii || !m_bUtfEnabled || - (!(flags & (PREF_UTF | PREF_UNICODE)) && m_bUtfEnabled == 1) || - !CheckContactCapabilities(hContact, CAPF_UTF) || - !getByte(hContact, "UnicodeSend", 1); + BOOL plain_ascii = IsUSASCII(puszText, strlennull(puszText)); - if (m_bTempVisListEnabled && m_iStatus == ID_STATUS_INVISIBLE) - makeContactTemporaryVisible(hContact); // make us temporarily visible to contact + BOOL oldAnsi = plain_ascii || !m_bUtfEnabled || + (!(flags & (PREF_UTF | PREF_UNICODE)) && m_bUtfEnabled == 1) || + !CheckContactCapabilities(hContact, CAPF_UTF) || + !getByte(hContact, "UnicodeSend", 1); - // Failure scenarios - if (!icqOnline()) - { - dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "You cannot send messages when you are offline."); - } - else if ((wRecipientStatus == ID_STATUS_OFFLINE) && (strlennull(puszText) > 4096)) - { - dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "Messages to offline contacts must be shorter than 4096 characters."); - } - // Looks OK - else - { + if (m_bTempVisListEnabled && m_iStatus == ID_STATUS_INVISIBLE) + makeContactTemporaryVisible(hContact); // make us temporarily visible to contact + + // Failure scenarios + if (!icqOnline()) { + dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "You cannot send messages when you are offline."); + } + else if ((wRecipientStatus == ID_STATUS_OFFLINE) && (strlennull(puszText) > 4096)) { + dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "Messages to offline contacts must be shorter than 4096 characters."); + } + // Looks OK + else { #ifdef _DEBUG - debugLogA("Send %smessage - Message cap is %u", puszText ? "unicode " : "", CheckContactCapabilities(hContact, CAPF_SRV_RELAY)); - debugLogA("Send %smessage - Contact status is %u", puszText ? "unicode " : "", wRecipientStatus); + debugLogA("Send %smessage - Message cap is %u", puszText ? "unicode " : "", CheckContactCapabilities(hContact, CAPF_SRV_RELAY)); + debugLogA("Send %smessage - Contact status is %u", puszText ? "unicode " : "", wRecipientStatus); #endif - if (dwUin && m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) - { // send thru direct - char *dc_msg = puszText; - char *dc_cap = plain_ascii ? NULL : CAP_UTF8MSGS; - char *szUserAnsi = NULL; - - if (!plain_ascii && oldAnsi) - { - szUserAnsi = ConvertMsgToUserSpecificAnsi(hContact, puszText); - if (szUserAnsi) - { - dc_msg = szUserAnsi; - dc_cap = NULL; - } + if (dwUin && m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) { // send thru direct + char *dc_msg = puszText; + char *dc_cap = plain_ascii ? NULL : CAP_UTF8MSGS; + char *szUserAnsi = NULL; + + if (!plain_ascii && oldAnsi) { + szUserAnsi = ConvertMsgToUserSpecificAnsi(hContact, puszText); + if (szUserAnsi) { + dc_msg = szUserAnsi; + dc_cap = NULL; } + } - // Set up the ack type - pCookieData = CreateMessageCookieData(MTYPE_PLAIN, hContact, dwUin, TRUE); - pCookieData->nAckType = ACKTYPE_CLIENT; - dwCookie = icq_SendDirectMessage(hContact, dc_msg, strlennull(dc_msg), 1, pCookieData, dc_cap); + // Set up the ack type + pCookieData = CreateMessageCookieData(MTYPE_PLAIN, hContact, dwUin, TRUE); + pCookieData->nAckType = ACKTYPE_CLIENT; + dwCookie = icq_SendDirectMessage(hContact, dc_msg, strlennull(dc_msg), 1, pCookieData, dc_cap); - SAFE_FREE(&szUserAnsi); - if (dwCookie) - { // free the buffers if alloced - if (bNeedFreeU) SAFE_FREE(&puszText); + SAFE_FREE(&szUserAnsi); + if (dwCookie) { // free the buffers if alloced + if (bNeedFreeU) SAFE_FREE(&puszText); - return dwCookie; // we succeded, return - } - // on failure, fallback to send thru server + return dwCookie; // we succeded, return } + // on failure, fallback to send thru server + } - if (!dwUin || !CheckContactCapabilities(hContact, CAPF_SRV_RELAY) || - wRecipientStatus == ID_STATUS_OFFLINE || wRecipientStatus == ID_STATUS_INVISIBLE || - getByte(hContact, "OnlyServerAcks", getByte("OnlyServerAcks", DEFAULT_ONLYSERVERACKS)) || - !getByte(hContact, "SlowSend", getByte("SlowSend", DEFAULT_SLOWSEND))) - { - /// TODO: add support for RTL & user customizable font + if (!dwUin || !CheckContactCapabilities(hContact, CAPF_SRV_RELAY) || + wRecipientStatus == ID_STATUS_OFFLINE || wRecipientStatus == ID_STATUS_INVISIBLE || + getByte(hContact, "OnlyServerAcks", getByte("OnlyServerAcks", DEFAULT_ONLYSERVERACKS)) || + !getByte(hContact, "SlowSend", getByte("SlowSend", DEFAULT_SLOWSEND))) { + /// TODO: add support for RTL & user customizable font { char *mng = MangleXml(puszText, strlennull(puszText)); int len = strlennull(mng); @@ -1580,208 +1487,166 @@ int __cdecl CIcqProto::SendMsg( HANDLE hContact, int flags, const char* pszSrc ) bNeedFreeU = 1; } - WCHAR *pwszText = plain_ascii ? NULL : make_unicode_string(puszText); - if ((plain_ascii ? strlennull(puszText) : strlennull(pwszText) * sizeof(WCHAR)) > MAX_MESSAGESNACSIZE) - { // max length check // TLV(2) is currently limited to 0xA00 bytes in online mode - // only limit to not get disconnected, all other will be handled by error 0x0A - dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The message could not be delivered, it is too long."); - - // free the buffers if alloced - SAFE_FREE((void**)&pwszText); - if (bNeedFreeU) SAFE_FREE(&puszText); + WCHAR *pwszText = plain_ascii ? NULL : make_unicode_string(puszText); + if ((plain_ascii ? strlennull(puszText) : strlennull(pwszText) * sizeof(WCHAR)) > MAX_MESSAGESNACSIZE) { // max length check // TLV(2) is currently limited to 0xA00 bytes in online mode + // only limit to not get disconnected, all other will be handled by error 0x0A + dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The message could not be delivered, it is too long."); - return dwCookie; - } - // Rate check - if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) - { // rate is too high, the message will not go thru... - dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The message could not be delivered. You are sending too fast. Wait a while and try again."); - - // free the buffers if alloced - SAFE_FREE((void**)&pwszText); - if (bNeedFreeU) SAFE_FREE(&puszText); - - return dwCookie; - } + // free the buffers if alloced + SAFE_FREE((void**)&pwszText); + if (bNeedFreeU) SAFE_FREE(&puszText); - pCookieData = CreateMessageCookieData(MTYPE_PLAIN, hContact, dwUin, FALSE); + return dwCookie; + } + // Rate check + if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) { // rate is too high, the message will not go thru... + dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The message could not be delivered. You are sending too fast. Wait a while and try again."); - if (plain_ascii) - dwCookie = icq_SendChannel1Message(dwUin, szUID, hContact, puszText, pCookieData); - else - dwCookie = icq_SendChannel1MessageW(dwUin, szUID, hContact, pwszText, pCookieData); - // free the unicode message + // free the buffers if alloced SAFE_FREE((void**)&pwszText); + if (bNeedFreeU) SAFE_FREE(&puszText); + + return dwCookie; } - else - { - WORD wPriority; - char *srv_msg = puszText; - char *srv_cap = plain_ascii ? NULL : CAP_UTF8MSGS; - char *szUserAnsi = NULL; + pCookieData = CreateMessageCookieData(MTYPE_PLAIN, hContact, dwUin, FALSE); - if (!plain_ascii && oldAnsi) - { - szUserAnsi = ConvertMsgToUserSpecificAnsi(hContact, puszText); - if (szUserAnsi) - { - srv_msg = szUserAnsi; - srv_cap = NULL; - } + if (plain_ascii) + dwCookie = icq_SendChannel1Message(dwUin, szUID, hContact, puszText, pCookieData); + else + dwCookie = icq_SendChannel1MessageW(dwUin, szUID, hContact, pwszText, pCookieData); + // free the unicode message + SAFE_FREE((void**)&pwszText); + } + else { + WORD wPriority; + + char *srv_msg = puszText; + char *srv_cap = plain_ascii ? NULL : CAP_UTF8MSGS; + char *szUserAnsi = NULL; + + if (!plain_ascii && oldAnsi) { + szUserAnsi = ConvertMsgToUserSpecificAnsi(hContact, puszText); + if (szUserAnsi) { + srv_msg = szUserAnsi; + srv_cap = NULL; } + } - if (wRecipientStatus == ID_STATUS_ONLINE || wRecipientStatus == ID_STATUS_FREECHAT) - wPriority = 0x0001; - else - wPriority = 0x0021; - - if (strlennull(srv_msg) + (!oldAnsi ? 144 : 102) > MAX_MESSAGESNACSIZE) - { // max length check - dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The message could not be delivered, it is too long."); - - SAFE_FREE(&szUserAnsi); - // free the buffers if alloced - if (bNeedFreeU) SAFE_FREE(&puszText); + if (wRecipientStatus == ID_STATUS_ONLINE || wRecipientStatus == ID_STATUS_FREECHAT) + wPriority = 0x0001; + else + wPriority = 0x0021; - return dwCookie; - } - // Rate check - if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) - { // rate is too high, the message will not go thru... - dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The message could not be delivered. You are sending too fast. Wait a while and try again."); + if (strlennull(srv_msg) + (!oldAnsi ? 144 : 102) > MAX_MESSAGESNACSIZE) { // max length check + dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The message could not be delivered, it is too long."); - SAFE_FREE(&szUserAnsi); - // free the buffers if alloced - if (bNeedFreeU) SAFE_FREE(&puszText); + SAFE_FREE(&szUserAnsi); + // free the buffers if alloced + if (bNeedFreeU) SAFE_FREE(&puszText); - return dwCookie; - } + return dwCookie; + } + // Rate check + if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) { // rate is too high, the message will not go thru... + dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "The message could not be delivered. You are sending too fast. Wait a while and try again."); - pCookieData = CreateMessageCookieData(MTYPE_PLAIN, hContact, dwUin, TRUE); - dwCookie = icq_SendChannel2Message(dwUin, hContact, srv_msg, strlennull(srv_msg), wPriority, pCookieData, srv_cap); SAFE_FREE(&szUserAnsi); - } + // free the buffers if alloced + if (bNeedFreeU) SAFE_FREE(&puszText); - // This will stop the message dialog from waiting for the real message delivery ack - if (pCookieData && pCookieData->nAckType == ACKTYPE_NONE) - { - SendProtoAck(hContact, dwCookie, ACKRESULT_SUCCESS, ACKTYPE_MESSAGE, NULL); - // We need to free this here since we will never see the real ack - // The actual cookie value will still have to be returned to the message dialog though - ReleaseCookie(dwCookie); + return dwCookie; } + + pCookieData = CreateMessageCookieData(MTYPE_PLAIN, hContact, dwUin, TRUE); + dwCookie = icq_SendChannel2Message(dwUin, hContact, srv_msg, strlennull(srv_msg), wPriority, pCookieData, srv_cap); + SAFE_FREE(&szUserAnsi); } - // free the buffers if alloced - if (bNeedFreeU) SAFE_FREE(&puszText); - return dwCookie; // Success + // This will stop the message dialog from waiting for the real message delivery ack + if (pCookieData && pCookieData->nAckType == ACKTYPE_NONE) { + SendProtoAck(hContact, dwCookie, ACKRESULT_SUCCESS, ACKTYPE_MESSAGE, NULL); + // We need to free this here since we will never see the real ack + // The actual cookie value will still have to be returned to the message dialog though + ReleaseCookie(dwCookie); + } } + // free the buffers if alloced + if (bNeedFreeU) SAFE_FREE(&puszText); - return 0; // Failure + return dwCookie; // Success } //////////////////////////////////////////////////////////////////////////////////////// // SendUrl -int __cdecl CIcqProto::SendUrl( HANDLE hContact, int flags, const char* url ) +int __cdecl CIcqProto::SendUrl(HANDLE hContact, int flags, const char* url) { - if (hContact && url) - { - DWORD dwCookie; - WORD wRecipientStatus; - DWORD dwUin; - - if (getContactUid(hContact, &dwUin, NULL)) - { // Invalid contact - return ReportGenericSendError(hContact, ACKTYPE_URL, "The receiver has an invalid user ID."); - } - - wRecipientStatus = getContactStatus(hContact); - - // Failure - if (!icqOnline()) - { - dwCookie = ReportGenericSendError(hContact, ACKTYPE_URL, "You cannot send messages when you are offline."); - } - // Looks OK - else - { - char* szDesc; - char* szBody; - int nBodyLen; - int nDescLen; - int nUrlLen; + if (hContact == NULL || url == NULL) + return 0; + DWORD dwUin; + if (getContactUid(hContact, &dwUin, NULL)) // Invalid contact + return ReportGenericSendError(hContact, ACKTYPE_URL, "The receiver has an invalid user ID."); - // Set up the ack type - cookie_message_data *pCookieData = CreateMessageCookieData(MTYPE_URL, hContact, dwUin, TRUE); - - // Format the body - nUrlLen = strlennull(url); - szDesc = (char *)url + nUrlLen + 1; - nDescLen = strlennull(szDesc); - nBodyLen = nUrlLen + nDescLen + 2; - szBody = (char *)_alloca(nBodyLen); - strcpy(szBody, szDesc); - szBody[nDescLen] = (char)0xFE; // Separator - strcpy(szBody + nDescLen + 1, url); - - if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) - { - int iRes = icq_SendDirectMessage(hContact, szBody, nBodyLen, 1, pCookieData, NULL); - if (iRes) return iRes; // we succeded, return - } + WORD wRecipientStatus = getContactStatus(hContact); - // Rate check - if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) - { // rate is too high, the message will not go thru... - SAFE_FREE((void**)&pCookieData); + // Failure + if (!icqOnline()) { + ReportGenericSendError(hContact, ACKTYPE_URL, "You cannot send messages when you are offline."); + return 0; + } - return ReportGenericSendError(hContact, ACKTYPE_URL, "The message could not be delivered. You are sending too fast. Wait a while and try again."); - } - // Select channel and send -/* - if (!CheckContactCapabilities(hContact, CAPF_SRV_RELAY) || - wRecipientStatus == ID_STATUS_OFFLINE) - { - dwCookie = icq_SendChannel4Message(dwUin, hContact, MTYPE_URL, - (WORD)nBodyLen, szBody, pCookieData); - } - else -*/ - { - WORD wPriority; + // Set up the ack type + cookie_message_data *pCookieData = CreateMessageCookieData(MTYPE_URL, hContact, dwUin, TRUE); + + // Format the body + int nUrlLen = strlennull(url); + char *szDesc = (char *)url + nUrlLen + 1; + int nDescLen = strlennull(szDesc); + int nBodyLen = nUrlLen + nDescLen + 2; + char *szBody = (char *)_alloca(nBodyLen); + strcpy(szBody, szDesc); + szBody[nDescLen] = (char)0xFE; // Separator + strcpy(szBody + nDescLen + 1, url); + + if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) { + int iRes = icq_SendDirectMessage(hContact, szBody, nBodyLen, 1, pCookieData, NULL); + if (iRes) + return iRes; // we succeded, return + } - if (wRecipientStatus == ID_STATUS_ONLINE || wRecipientStatus == ID_STATUS_FREECHAT) - wPriority = 0x0001; - else - wPriority = 0x0021; + // Rate check + if (IsServerOverRate(ICQ_MSG_FAMILY, ICQ_MSG_SRV_SEND, RML_LIMIT)) { // rate is too high, the message will not go thru... + SAFE_FREE((void**)&pCookieData); + return ReportGenericSendError(hContact, ACKTYPE_URL, "The message could not be delivered. You are sending too fast. Wait a while and try again."); + } - dwCookie = icq_SendChannel2Message(dwUin, hContact, szBody, nBodyLen, wPriority, pCookieData, NULL); - } + // Select channel and send + WORD wPriority; + if (wRecipientStatus == ID_STATUS_ONLINE || wRecipientStatus == ID_STATUS_FREECHAT) + wPriority = 0x0001; + else + wPriority = 0x0021; - // This will stop the message dialog from waiting for the real message delivery ack - if (pCookieData->nAckType == ACKTYPE_NONE) - { - SendProtoAck(hContact, dwCookie, ACKRESULT_SUCCESS, ACKTYPE_URL, NULL); - // We need to free this here since we will never see the real ack - // The actual cookie value will still have to be returned to the message dialog though - ReleaseCookie(dwCookie); - } - } + DWORD dwCookie = icq_SendChannel2Message(dwUin, hContact, szBody, nBodyLen, wPriority, pCookieData, NULL); - return dwCookie; // Success + // This will stop the message dialog from waiting for the real message delivery ack + if (pCookieData->nAckType == ACKTYPE_NONE) { + SendProtoAck(hContact, dwCookie, ACKRESULT_SUCCESS, ACKTYPE_URL, NULL); + // We need to free this here since we will never see the real ack + // The actual cookie value will still have to be returned to the message dialog though + ReleaseCookie(dwCookie); } - return 0; // Failure + return dwCookie; // Success } //////////////////////////////////////////////////////////////////////////////////////// // PS_SetApparentMode - sets the visibility status -int __cdecl CIcqProto::SetApparentMode( HANDLE hContact, int mode ) +int __cdecl CIcqProto::SetApparentMode(HANDLE hContact, int mode) { DWORD uin; uid_str uid; @@ -1789,38 +1654,31 @@ int __cdecl CIcqProto::SetApparentMode( HANDLE hContact, int mode ) if (getContactUid(hContact, &uin, &uid)) return 1; // Invalid contact - if (hContact) - { + if (hContact) { // Only 3 modes are supported - if (mode == 0 || mode == ID_STATUS_ONLINE || mode == ID_STATUS_OFFLINE) - { + if (mode == 0 || mode == ID_STATUS_ONLINE || mode == ID_STATUS_OFFLINE) { int oldMode = getWord(hContact, "ApparentMode", 0); // Don't send redundant updates - if (mode != oldMode) - { + if (mode != oldMode) { setWord(hContact, "ApparentMode", (WORD)mode); // Not being online is only an error when in SS mode. This is not handled // yet so we just ignore this for now. - if (icqOnline()) - { - if (oldMode != 0) - { // Remove from old list - if (oldMode == ID_STATUS_OFFLINE && getWord(hContact, DBSETTING_SERVLIST_IGNORE, 0)) - { // Need to remove Ignore item as well + if (icqOnline()) { + if (oldMode != 0) { // Remove from old list + if (oldMode == ID_STATUS_OFFLINE && getWord(hContact, DBSETTING_SERVLIST_IGNORE, 0)) { // Need to remove Ignore item as well icq_removeServerPrivacyItem(hContact, uin, uid, getWord(hContact, DBSETTING_SERVLIST_IGNORE, 0), SSI_ITEM_IGNORE); setWord(hContact, DBSETTING_SERVLIST_IGNORE, 0); } - icq_sendChangeVisInvis(hContact, uin, uid, oldMode==ID_STATUS_OFFLINE, 0); + icq_sendChangeVisInvis(hContact, uin, uid, oldMode == ID_STATUS_OFFLINE, 0); } - if (mode != 0) - { // Add to new list - if (mode==ID_STATUS_OFFLINE && getWord(hContact, DBSETTING_SERVLIST_IGNORE, 0)) + if (mode != 0) { // Add to new list + if (mode == ID_STATUS_OFFLINE && getWord(hContact, DBSETTING_SERVLIST_IGNORE, 0)) return 0; // Success: offline by ignore item - icq_sendChangeVisInvis(hContact, uin, uid, mode==ID_STATUS_OFFLINE, 1); + icq_sendChangeVisInvis(hContact, uin, uid, mode == ID_STATUS_OFFLINE, 1); } } @@ -1845,8 +1703,7 @@ char* CIcqProto::PrepareStatusNote(int nStatus) if (bXStatus) szStatusNote = getSettingStringUtf(NULL, DBSETTING_XSTATUS_MSG, ""); - if (!szStatusNote || !szStatusNote[0]) - { // get standard status message (no custom status defined) + if (!szStatusNote || !szStatusNote[0]) { // get standard status message (no custom status defined) icq_lock l(m_modeMsgsMutex); char **pszStatusNote = MirandaStatusToAwayMsg(nStatus); @@ -1884,10 +1741,8 @@ int __cdecl CIcqProto::SetStatus(int iNewStatus) setXStatusEx(0, 0); // New status is OFFLINE - if (nNewStatus == ID_STATUS_OFFLINE) - { // for quick logoff - if (icqOnline()) - { // set offline status note (otherwise the old will remain) + if (nNewStatus == ID_STATUS_OFFLINE) { // for quick logoff + if (icqOnline()) { // set offline status note (otherwise the old will remain) char *szOfflineNote = PrepareStatusNote(nNewStatus); SetStatusNote(szOfflineNote, 0, FALSE); SAFE_FREE(&szOfflineNote); @@ -1895,8 +1750,7 @@ int __cdecl CIcqProto::SetStatus(int iNewStatus) m_iDesiredStatus = nNewStatus; - if (hServerConn) - { // Connected, Send disconnect packet + if (hServerConn) { // Connected, Send disconnect packet icq_sendCloseConnection(); icq_serverDisconnect(FALSE); @@ -1906,40 +1760,36 @@ int __cdecl CIcqProto::SetStatus(int iNewStatus) debugLogA("Logged off."); } } - else - { + else { switch (m_iStatus) { - // We are offline and need to connect + // We are offline and need to connect case ID_STATUS_OFFLINE: - { - // Update user connection settings - UpdateGlobalSettings(); - - // Read UIN from database - m_dwLocalUIN = getContactUin(NULL); - if (m_dwLocalUIN == 0) - { - SetCurrentStatus(ID_STATUS_OFFLINE); - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID); - icq_LogMessage(LOG_FATAL, LPGEN("You have not entered an ICQ number.\nConfigure this in Options->Network->ICQ and try again.")); - return 0; - } + // Update user connection settings + UpdateGlobalSettings(); + + // Read UIN from database + m_dwLocalUIN = getContactUin(NULL); + if (m_dwLocalUIN == 0) { + SetCurrentStatus(ID_STATUS_OFFLINE); + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID); + icq_LogMessage(LOG_FATAL, LPGEN("You have not entered an ICQ number.\nConfigure this in Options->Network->ICQ and try again.")); + return 0; + } - // Set status to 'Connecting' - m_iDesiredStatus = nNewStatus; - SetCurrentStatus(ID_STATUS_CONNECTING); + // Set status to 'Connecting' + m_iDesiredStatus = nNewStatus; + SetCurrentStatus(ID_STATUS_CONNECTING); - // Read password from database + // Read password from database + { char *pszPwd = GetUserPassword(FALSE); - if (pszPwd) icq_login(pszPwd); else RequestPassword(); - - break; } + break; // We are connecting... We only need to change the going online status case ID_STATUS_CONNECTING: @@ -1957,22 +1807,19 @@ int __cdecl CIcqProto::SetStatus(int iNewStatus) // will only change User Details Directory SetStatusNote(szStatusNote, 6000, FALSE); - if (m_iStatus == ID_STATUS_INVISIBLE) - { + if (m_iStatus == ID_STATUS_INVISIBLE) { if (m_bSsiEnabled) updateServVisibilityCode(3); icq_setstatus(MirandaStatusToIcq(m_iStatus), szStatusNote); } - else - { + else { icq_setstatus(MirandaStatusToIcq(m_iStatus), szStatusNote); if (m_bSsiEnabled) updateServVisibilityCode(4); } SAFE_FREE(&szStatusNote); - if (m_bAimEnabled) - { + if (m_bAimEnabled) { icq_lock l(m_modeMsgsMutex); char ** pszStatusNote = MirandaStatusToAwayMsg(m_iStatus); @@ -1998,7 +1845,7 @@ struct status_message_thread_data HANDLE hProcess; }; -void __cdecl CIcqProto::GetAwayMsgThread( void *pStatusData ) +void __cdecl CIcqProto::GetAwayMsgThread(void *pStatusData) { status_message_thread_data *pThreadData = (status_message_thread_data*)pStatusData; if (pThreadData) { @@ -2019,20 +1866,17 @@ void __cdecl CIcqProto::GetAwayMsgThread( void *pStatusData ) //////////////////////////////////////////////////////////////////////////////////////// // PS_GetAwayMsg - returns a contact's away message -HANDLE __cdecl CIcqProto::GetAwayMsg( HANDLE hContact ) +HANDLE __cdecl CIcqProto::GetAwayMsg(HANDLE hContact) { DWORD dwUin; uid_str szUID; - if (getContactUid(hContact, &dwUin, &szUID)) return 0; // Invalid contact - if (!dwUin || !CheckContactCapabilities(hContact, CAPF_STATUS_MESSAGES)) - { // No individual status messages, check if the contact has Status Note, if yes give it + if (!dwUin || !CheckContactCapabilities(hContact, CAPF_STATUS_MESSAGES)) { // No individual status messages, check if the contact has Status Note, if yes give it char *szStatusNote = getSettingStringUtf(hContact, DBSETTING_STATUS_NOTE, NULL); - if (strlennull(szStatusNote) > 0) - { // Give Status Note + if (strlennull(szStatusNote) > 0) { // Give Status Note status_message_thread_data *pThreadData = (status_message_thread_data*)SAFE_MALLOC(sizeof(status_message_thread_data)); pThreadData->hContact = hContact; @@ -2050,12 +1894,10 @@ HANDLE __cdecl CIcqProto::GetAwayMsg( HANDLE hContact ) WORD wStatus = getContactStatus(hContact); - if (dwUin) - { + if (dwUin) { int wMessageType = 0; - switch(wStatus) - { + switch (wStatus) { case ID_STATUS_ONLINE: if (CheckContactCapabilities(hContact, CAPF_STATUS_MESSAGES)) wMessageType = MTYPE_AUTOONLINE; @@ -2080,28 +1922,22 @@ HANDLE __cdecl CIcqProto::GetAwayMsg( HANDLE hContact ) case ID_STATUS_FREECHAT: wMessageType = MTYPE_AUTOFFC; break; - - default: - break; } - if (wMessageType) - { - if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) - { + if (wMessageType) { + if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) { int iRes = icq_sendGetAwayMsgDirect(hContact, wMessageType); if (iRes) return (HANDLE)iRes; // we succeded, return } + + WORD wVer = getWord(hContact, "Version", 0) <= 8 ? 8 : ICQ_VERSION; if (CheckContactCapabilities(hContact, CAPF_STATUS_MESSAGES)) - return (HANDLE)icq_sendGetAwayMsgServExt(hContact, dwUin, szUID, wMessageType, - (WORD)(getWord(hContact, "Version", 0)==9?9:ICQ_VERSION)); // Success - else - return (HANDLE)icq_sendGetAwayMsgServ(hContact, dwUin, wMessageType, - (WORD)(getWord(hContact, "Version", 0)==9?9:ICQ_VERSION)); // Success + return (HANDLE)icq_sendGetAwayMsgServExt(hContact, dwUin, szUID, wMessageType, wVer); + + return (HANDLE)icq_sendGetAwayMsgServ(hContact, dwUin, wMessageType, wVer); } } - else - { // AIM contact + else { // AIM contact if (wStatus == ID_STATUS_AWAY) return (HANDLE)icq_sendGetAimAwayMsgServ(hContact, szUID, MTYPE_AUTOAWAY); } @@ -2113,7 +1949,7 @@ HANDLE __cdecl CIcqProto::GetAwayMsg( HANDLE hContact ) //////////////////////////////////////////////////////////////////////////////////////// // PSR_AWAYMSG - processes received status mode message -int __cdecl CIcqProto::RecvAwayMsg( HANDLE hContact, int statusMode, PROTORECVEVENT* evt ) +int __cdecl CIcqProto::RecvAwayMsg(HANDLE hContact, int statusMode, PROTORECVEVENT* evt) { if (evt->flags & PREF_UTF) { setStatusMsgVar(hContact, evt->szMessage, false); @@ -2144,8 +1980,7 @@ int __cdecl CIcqProto::SetAwayMsg(int status, const TCHAR* msg) // Prepare UTF-8 status message char *szNewUtf = tchar_to_utf8(msg); - if (strcmpnull(szNewUtf, *ppszMsg)) - { + if (strcmpnull(szNewUtf, *ppszMsg)) { // Free old message SAFE_FREE(ppszMsg); @@ -2153,8 +1988,7 @@ int __cdecl CIcqProto::SetAwayMsg(int status, const TCHAR* msg) *ppszMsg = szNewUtf; szNewUtf = NULL; - if ((m_iStatus == status) && icqOnline()) - { // update current status note + if ((m_iStatus == status) && icqOnline()) { // update current status note char *szNote = *ppszMsg ? *ppszMsg : ""; BYTE bXStatus = getContactXStatus(NULL); @@ -2185,15 +2019,13 @@ INT_PTR CIcqProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam) int nMsgLen = strlennull(*ppszMsg) + 1; - if (lParam & SGMA_UNICODE) - { + if (lParam & SGMA_UNICODE) { WCHAR *szMsg = (WCHAR*)_alloca(nMsgLen * sizeof(WCHAR)); make_unicode_string_static(*ppszMsg, szMsg, nMsgLen); return (INT_PTR)mir_wstrdup(szMsg); } - else - { // convert to ansi + else { // convert to ansi char *szMsg = (char*)_alloca(nMsgLen); if (utf8_decode_static(*ppszMsg, szMsg, nMsgLen)) @@ -2207,12 +2039,10 @@ INT_PTR CIcqProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam) ///////////////////////////////////////////////////////////////////////////////////////// // PS_UserIsTyping - sends a UTN notification -int __cdecl CIcqProto::UserIsTyping( HANDLE hContact, int type ) +int __cdecl CIcqProto::UserIsTyping(HANDLE hContact, int type) { - if (hContact && icqOnline()) - { - if (CheckContactCapabilities(hContact, CAPF_TYPING)) - { + if (hContact && icqOnline()) { + if (CheckContactCapabilities(hContact, CAPF_TYPING)) { switch (type) { case PROTOTYPE_SELFTYPING_ON: sendTypingNotification(hContact, MTN_BEGUN); @@ -2234,7 +2064,7 @@ int __cdecl CIcqProto::UserIsTyping( HANDLE hContact, int type ) int __cdecl CIcqProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam) { - switch( eventType ) { + switch (eventType) { case EV_PROTO_ONLOAD: return OnModulesLoaded(0, 0); @@ -2247,15 +2077,14 @@ int __cdecl CIcqProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM l case EV_PROTO_ONERASE: { char szDbSetting[MAX_PATH]; - mir_snprintf(szDbSetting, sizeof(szDbSetting), "%sP2P", m_szModuleName); CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbSetting); mir_snprintf(szDbSetting, sizeof(szDbSetting), "%sSrvGroups", m_szModuleName); CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbSetting); mir_snprintf(szDbSetting, sizeof(szDbSetting), "%sGroups", m_szModuleName); CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbSetting); - break; } + break; case EV_PROTO_ONCONTACTDELETED: return ServListDbContactDeleted(wParam, lParam); diff --git a/protocols/IcqOscarJ/src/icq_proto.h b/protocols/IcqOscarJ/src/icq_proto.h index a3291a94e7..836eaafb51 100644 --- a/protocols/IcqOscarJ/src/icq_proto.h +++ b/protocols/IcqOscarJ/src/icq_proto.h @@ -922,7 +922,7 @@ struct CIcqProto : public PROTO char** MirandaStatusToAwayMsg(int nStatus); - BOOL validateStatusMessageRequest(HANDLE hContact, WORD byMessageType); + bool validateStatusMessageRequest(HANDLE hContact, WORD byMessageType); }; #endif diff --git a/protocols/IcqOscarJ/src/icq_xtraz.cpp b/protocols/IcqOscarJ/src/icq_xtraz.cpp index 115fe87984..58e8230804 100644 --- a/protocols/IcqOscarJ/src/icq_xtraz.cpp +++ b/protocols/IcqOscarJ/src/icq_xtraz.cpp @@ -27,8 +27,8 @@ // Internal Xtraz API // // ----------------------------------------------------------------------------- -#include "icqoscar.h" +#include "icqoscar.h" void CIcqProto::handleXtrazNotify(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD wCookie, char* szMsg, int nMsgLen, BOOL bThruDC) { @@ -39,8 +39,7 @@ void CIcqProto::handleXtrazNotify(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD w if (hContact) // user sent us xtraz, he supports it SetContactCapabilities(hContact, CAPF_XTRAZ); - if (szNotify && szQuery) - { // valid request + if (szNotify && szQuery) { // valid request char *szWork, *szEnd; int nNotifyLen, nQueryLen; @@ -60,27 +59,22 @@ void CIcqProto::handleXtrazNotify(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD w debugLogA("Query: %s", szQuery); debugLogA("Notify: %s", szNotify); #endif - if (szWork && szEnd) - { // this is our plugin + if (szWork && szEnd) { // this is our plugin szWork += 10; *szEnd = '\0'; - if (!stricmpnull(szWork, "srvMng") && strstrnull(szNotify, "AwayStat")) - { + if (!stricmpnull(szWork, "srvMng") && strstrnull(szNotify, "AwayStat")) { char *szSender = strstrnull(szNotify, ""); char *szEndSend = strstrnull(szNotify, ""); - if (szSender && szEndSend) - { + if (szSender && szEndSend) { szSender += 10; *szEndSend = '\0'; - if ((DWORD)atoi(szSender) == dwUin) - { - BYTE dwXId = m_bXStatusEnabled ? getContactXStatus(NULL) : 0; + if ((DWORD)atoi(szSender) == dwUin) { + BYTE dwXId = m_bXStatusEnabled ? getContactXStatus(NULL) : 0; - if (dwXId && validateStatusMessageRequest(hContact, MTYPE_SCRIPT_NOTIFY)) - { // apply privacy rules + if (dwXId && validateStatusMessageRequest(hContact, MTYPE_SCRIPT_NOTIFY)) { // apply privacy rules NotifyEventHooks(m_modeMsgsEvent, (WPARAM)MTYPE_SCRIPT_NOTIFY, (LPARAM)dwUin); char *tmp = getSettingStringUtf(NULL, DBSETTING_XSTATUS_NAME, ""); @@ -94,7 +88,7 @@ void CIcqProto::handleXtrazNotify(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD w int nResponseLen = 212 + strlennull(szXName) + strlennull(szXMsg) + UINMAXLEN + 2; char *szResponse = (char*)_alloca(nResponseLen + 1); // send response - mir_snprintf(szResponse, nResponseLen, + mir_snprintf(szResponse, nResponseLen, "" "cAwaySrv" "" @@ -108,50 +102,52 @@ void CIcqProto::handleXtrazNotify(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD w SAFE_FREE(&szXName); SAFE_FREE(&szXMsg); - struct rates_xstatus_response: public rates_queue_item { - protected: - virtual rates_queue_item* copyItem(rates_queue_item *aDest = NULL) { - rates_xstatus_response *pDest = (rates_xstatus_response*)aDest; - if (!pDest) - pDest = new rates_xstatus_response(ppro, wGroup); - - pDest->bThruDC = bThruDC; - pDest->dwMsgID1 = dwMsgID1; - pDest->dwMsgID2 = dwMsgID2; - pDest->wCookie = wCookie; - pDest->szResponse = null_strdup(szResponse); - - return rates_queue_item::copyItem(pDest); - }; - public: - rates_xstatus_response(CIcqProto *ppro, WORD wGroup): rates_queue_item(ppro, wGroup), szResponse(NULL) { }; - virtual ~rates_xstatus_response() { if (bCreated) SAFE_FREE(&szResponse); }; - - virtual void execute() { + struct rates_xstatus_response : public rates_queue_item { + protected: + virtual rates_queue_item* copyItem(rates_queue_item *aDest = NULL) + { + rates_xstatus_response *pDest = (rates_xstatus_response*)aDest; + if (!pDest) + pDest = new rates_xstatus_response(ppro, wGroup); + + pDest->bThruDC = bThruDC; + pDest->dwMsgID1 = dwMsgID1; + pDest->dwMsgID2 = dwMsgID2; + pDest->wCookie = wCookie; + pDest->szResponse = null_strdup(szResponse); + + return rates_queue_item::copyItem(pDest); + }; + public: + rates_xstatus_response(CIcqProto *ppro, WORD wGroup) : rates_queue_item(ppro, wGroup), szResponse(NULL) {}; + virtual ~rates_xstatus_response() { if (bCreated) SAFE_FREE(&szResponse); }; + + virtual void execute() + { ppro->SendXtrazNotifyResponse(dwUin, dwMsgID1, dwMsgID2, wCookie, szResponse, strlennull(szResponse), bThruDC); - }; - - BOOL bThruDC; - DWORD dwMsgID1; - DWORD dwMsgID2; - WORD wCookie; - char *szResponse; - }; - - m_ratesMutex->Enter(); - WORD wGroup = m_rates->getGroupFromSNAC(ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE); - m_ratesMutex->Leave(); - - rates_xstatus_response rr(this, wGroup); - rr.hContact = hContact; - rr.dwUin = dwUin; - rr.bThruDC = bThruDC; - rr.dwMsgID1 = dwMID; - rr.dwMsgID2 = dwMID2; - rr.wCookie = wCookie; - rr.szResponse = szResponse; - - handleRateItem(&rr, RQT_RESPONSE, 0, !bThruDC); + }; + + BOOL bThruDC; + DWORD dwMsgID1; + DWORD dwMsgID2; + WORD wCookie; + char *szResponse; + }; + + m_ratesMutex->Enter(); + WORD wGroup = m_rates->getGroupFromSNAC(ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE); + m_ratesMutex->Leave(); + + rates_xstatus_response rr(this, wGroup); + rr.hContact = hContact; + rr.dwUin = dwUin; + rr.bThruDC = bThruDC; + rr.dwMsgID1 = dwMID; + rr.dwMsgID2 = dwMID2; + rr.wCookie = wCookie; + rr.szResponse = szResponse; + + handleRateItem(&rr, RQT_RESPONSE, 0, !bThruDC); } else if (dwXId) debugLogA("Privacy: Ignoring XStatus request"); @@ -167,13 +163,13 @@ void CIcqProto::handleXtrazNotify(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD w else debugLogA("Error: Unknown plugin \"%s\" in Xtraz message", szWork); } - else + else debugLogA("Error: Missing PluginID in Xtraz message"); SAFE_FREE(&szNotify); SAFE_FREE(&szQuery); } - else + else debugLogA("Error: Invalid Xtraz Notify message"); } @@ -190,8 +186,7 @@ void CIcqProto::handleXtrazNotifyResponse(DWORD dwUin, HANDLE hContact, WORD wCo szRes = strstrnull(szMsg, ""); szEnd = strstrnull(szMsg, ""); - if (szRes && szEnd) - { // valid response + if (szRes && szEnd) { // valid response char *szNode, *szWork; szRes += 5; @@ -205,37 +200,32 @@ void CIcqProto::handleXtrazNotifyResponse(DWORD dwUin, HANDLE hContact, WORD wCo ProtoBroadcastAck(hContact, ICQACKTYPE_XTRAZNOTIFY_RESPONSE, ACKRESULT_SUCCESS, (HANDLE)wCookie, (LPARAM)szRes); -NextVal: + NextVal: szNode = strstrnull(szRes, ""); else szEnd = NULL; - if (szNode && szEnd) - { - *(szEnd-1) = '\0'; + if (szNode && szEnd) { + *(szEnd - 1) = '\0'; szNode += 13; //one more than the length of the string to skip ' or " too szWork = szEnd + 1; - if (!stricmpnull(szNode, "cAwaySrv")) - { + if (!stricmpnull(szNode, "cAwaySrv")) { int bChanged = FALSE; *szEnd = ' '; szNode = strstrnull(szWork, ""); szEnd = strstrnull(szWork, ""); - if (szNode && szEnd) - { + if (szNode && szEnd) { szNode += 7; *szEnd = '\0'; - if (atoi(szNode) != getContactXStatus(hContact)) - { // this is strange - but go on + if (atoi(szNode) != getContactXStatus(hContact)) { // this is strange - but go on debugLogA("Warning: XStatusIds do not match!"); } *szEnd = ' '; } szNode = strstrnull(szWork, ""); szEnd = strstrnull(szWork, ""); - if (szNode && szEnd) - { // we got XStatus title, save it + if (szNode && szEnd) { // we got XStatus title, save it char *szXName, *szOldXName; szNode += 7; *szEnd = '\0'; @@ -251,8 +241,7 @@ NextVal: } szNode = strstrnull(szWork, ""); szEnd = strstrnull(szWork, ""); - if (szNode && szEnd) - { // we got XStatus mode msg, save it + if (szNode && szEnd) { // we got XStatus mode msg, save it char *szXMsg, *szOldXMsg; szNode += 6; *szEnd = '\0'; @@ -267,12 +256,10 @@ NextVal: } ProtoBroadcastAck(hContact, ICQACKTYPE_XSTATUS_RESPONSE, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0); } - else - { + else { char *szSrvEnd = strstrnull(szEnd, ""); - if (szSrvEnd && strstrnull(szSrvEnd, ""); szEnd = strstrnull(szData, ""); - if (szPid && szEnd) - { + if (szPid && szEnd) { szPid += 5; - return DemangleXml(szPid, szEnd - szPid); } return NULL; @@ -309,21 +294,16 @@ static char* getXmlPidItem(const char* szData, int nLen) void CIcqProto::handleXtrazInvitation(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD wCookie, char* szMsg, int nMsgLen, BOOL bThruDC) { - HANDLE hContact; - char* szPluginID; - - hContact = HContactFromUIN(dwUin, NULL); + HANDLE hContact = HContactFromUIN(dwUin, NULL); if (hContact) // user sent us xtraz, he supports it SetContactCapabilities(hContact, CAPF_XTRAZ); - szPluginID = getXmlPidItem(szMsg, nMsgLen); - if (!strcmpnull(szPluginID, "ICQChatRecv")) - { // it is a invitation to multi-user chat - } - else - { + char *szPluginID = getXmlPidItem(szMsg, nMsgLen); + if (!strcmpnull(szPluginID, "ICQChatRecv")) // it is a invitation to multi-user chat + ; + else NetLog_Uni(bThruDC, "Error: Unknown plugin \"%s\" in Xtraz message", szPluginID); - } + SAFE_FREE(&szPluginID); } @@ -338,59 +318,50 @@ void CIcqProto::handleXtrazData(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD wCo SetContactCapabilities(hContact, CAPF_XTRAZ); szPluginID = getXmlPidItem(szMsg, nMsgLen); - if (!strcmpnull(szPluginID, "viewCard")) - { // it is a greeting card + if (!strcmpnull(szPluginID, "viewCard")) { // it is a greeting card char *szWork, *szEnd, *szUrl, *szNum; szWork = strstrnull(szMsg, ""); szEnd = strstrnull(szMsg, ""); - if (szWork && szEnd) - { + if (szWork && szEnd) { int nDataLen = szEnd - szWork; szUrl = (char*)_alloca(nDataLen); - memcpy(szUrl, szWork+5, nDataLen); + memcpy(szUrl, szWork + 5, nDataLen); szUrl[nDataLen - 5] = '\0'; - if (!_strnicmp(szUrl, "view_", 5)) - { + if (!_strnicmp(szUrl, "view_", 5)) { szNum = szUrl + 5; szWork = strstrnull(szUrl, ".html"); - if (szWork) - { + if (szWork) { strcpy(szWork, ".php"); - strcat(szWork, szWork+5); - } - while (szWork = strstrnull(szUrl, "&")) - { // unescape & code - strcpy(szWork+1, szWork+5); + strcat(szWork, szWork + 5); } + while (szWork = strstrnull(szUrl, "&")) // unescape & code + strcpy(szWork + 1, szWork + 5); + szWork = (char*)SAFE_MALLOC(nDataLen + MAX_PATH); ICQTranslateUtfStatic(LPGEN("Greeting card:"), szWork, MAX_PATH); strcat(szWork, "\r\nhttp://www.icq.com/friendship/pages/view_page_"); strcat(szWork, szNum); // Create message to notify user - PROTORECVEVENT pre = {0}; + PROTORECVEVENT pre = { 0 }; pre.timestamp = time(NULL); pre.szMessage = szWork; pre.flags = PREF_UTF; int bAdded; - ProtoChainRecvMsg( HContactFromUIN(dwUin, &bAdded), &pre); + ProtoChainRecvMsg(HContactFromUIN(dwUin, &bAdded), &pre); SAFE_FREE(&szWork); } - else - NetLog_Uni(bThruDC, "Error: Non-standard greeting card message"); + else NetLog_Uni(bThruDC, "Error: Non-standard greeting card message"); } - else - NetLog_Uni(bThruDC, "Error: Malformed greeting card message"); - } - else - { - NetLog_Uni(bThruDC, "Error: Unknown plugin \"%s\" in Xtraz message", szPluginID); + else NetLog_Uni(bThruDC, "Error: Malformed greeting card message"); } + else NetLog_Uni(bThruDC, "Error: Unknown plugin \"%s\" in Xtraz message", szPluginID); + SAFE_FREE(&szPluginID); } @@ -440,8 +411,7 @@ void CIcqProto::SendXtrazNotifyResponse(DWORD dwUin, DWORD dwMID, DWORD dwMID2, char *szBody = (char*)_alloca(nBodyLen); HANDLE hContact = HContactFromUIN(dwUin, NULL); - if (hContact != INVALID_HANDLE_VALUE && !CheckContactCapabilities(hContact, CAPF_XTRAZ)) - { + if (hContact != INVALID_HANDLE_VALUE && !CheckContactCapabilities(hContact, CAPF_XTRAZ)) { SAFE_FREE(&szResBody); return; // Contact does not support xtraz, do not send anything } diff --git a/protocols/IcqOscarJ/src/stdpackets.cpp b/protocols/IcqOscarJ/src/stdpackets.cpp index 4de31b3e9a..e1e573cc9f 100644 --- a/protocols/IcqOscarJ/src/stdpackets.cpp +++ b/protocols/IcqOscarJ/src/stdpackets.cpp @@ -52,7 +52,7 @@ static void packServMsgSendHeader(icq_packet *p, DWORD dwSequence, DWORD dwID1, static void packServIcqExtensionHeader(icq_packet *p, CIcqProto *ppro, WORD wLen, WORD wType, WORD wSeq, WORD wCmd = ICQ_META_CLI_REQUEST) { serverPacketInit(p, (WORD)(24 + wLen)); - packFNACHeader(p, ICQ_EXTENSIONS_FAMILY, ICQ_META_CLI_REQUEST, 0, wSeq | (wCmd<<0x10)); + packFNACHeader(p, ICQ_EXTENSIONS_FAMILY, ICQ_META_CLI_REQUEST, 0, wSeq | (wCmd << 0x10)); packWord(p, 0x01); // TLV type 1 packWord(p, (WORD)(10 + wLen)); // TLV len packLEWord(p, (WORD)(8 + wLen)); // Data chunk size (TLV.Length-2) @@ -128,11 +128,11 @@ static void packServDCInfo(icq_packet *p, CIcqProto* ppro, BOOL bEmpty) static void packServChannel2Header(icq_packet *p, CIcqProto* ppro, DWORD dwUin, WORD wLen, DWORD dwID1, DWORD dwID2, DWORD dwCookie, WORD wVersion, BYTE bMsgType, BYTE bMsgFlags, WORD wPriority, int isAck, int includeDcInfo, BYTE bRequestServerAck) { - packServMsgSendHeader(p, dwCookie, dwID1, dwID2, dwUin, NULL, 0x0002, (WORD)(wLen + 95 + (bRequestServerAck?4:0) + (includeDcInfo?14:0))); + packServMsgSendHeader(p, dwCookie, dwID1, dwID2, dwUin, NULL, 0x0002, (WORD)(wLen + 95 + (bRequestServerAck ? 4 : 0) + (includeDcInfo ? 14 : 0))); packWord(p, 0x05); // TLV type - packWord(p, (WORD)(wLen + 91 + (includeDcInfo?14:0))); /* TLV len */ - packWord(p, (WORD)(isAck ? 2: 0)); /* not aborting anything */ + packWord(p, (WORD)(wLen + 91 + (includeDcInfo ? 14 : 0))); /* TLV len */ + packWord(p, (WORD)(isAck ? 2 : 0)); /* not aborting anything */ packLEDWord(p, dwID1); // Msg ID part 1 packLEDWord(p, dwID2); // Msg ID part 2 packGUID(p, MCAP_SRV_RELAY_FMT); /* capability (4 dwords) */ @@ -151,7 +151,7 @@ static void packServChannel2Header(icq_packet *p, CIcqProto* ppro, DWORD dwUin, static void packServAdvancedReply(icq_packet *p, DWORD dwUin, const char *szUid, DWORD dwID1, DWORD dwID2, WORD wCookie, WORD wLen) { serverPacketInit(p, (WORD)(getUIDLen(dwUin, szUid) + 23 + wLen)); - packFNACHeader(p, ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE, 0, ICQ_MSG_RESPONSE<<0x10 | (wCookie & 0x7FFF)); + packFNACHeader(p, ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE, 0, ICQ_MSG_RESPONSE << 0x10 | (wCookie & 0x7FFF)); packLEDWord(p, dwID1); // Msg ID part 1 packLEDWord(p, dwID2); // Msg ID part 2 packWord(p, 0x02); // Channel @@ -238,12 +238,11 @@ void CIcqProto::icq_setidle(int bAllow) { icq_packet packet; - if (bAllow != m_bIdleAllow) - { + if (bAllow != m_bIdleAllow) { /* SNAC 1,11 */ serverPacketInit(&packet, 14); packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_SET_IDLE); - if (bAllow==1) + if (bAllow == 1) packDWord(&packet, 0x0000003C); else packDWord(&packet, 0x00000000); @@ -261,9 +260,8 @@ void CIcqProto::icq_setstatus(WORD wStatus, const char *szStatusNote) WORD wStatusMoodLen = 0, wStatusNoteLen = 0, wSessionDataLen = 0; char *szMoodData = NULL; - if (szStatusNote && strcmpnull(szCurrentStatusNote, szStatusNote)) - { // status note was changed, update now - DBVARIANT dbv = {DBVT_DELETED}; + if (szStatusNote && strcmpnull(szCurrentStatusNote, szStatusNote)) { // status note was changed, update now + DBVARIANT dbv = { DBVT_DELETED }; if (m_bMoodsEnabled && !getString(DBSETTING_STATUS_MOOD, &dbv)) szMoodData = null_strdup(dbv.pszVal); @@ -284,13 +282,11 @@ void CIcqProto::icq_setstatus(WORD wStatus, const char *szStatusNote) packWord(&packet, 0x04); // TLV length packWord(&packet, GetMyStatusFlags()); // Status flags packWord(&packet, wStatus); // Status - 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); @@ -394,7 +390,7 @@ DWORD CIcqProto::icq_SendChannel1MessageW(DWORD dwUin, char *szUID, HANDLE hCont packWord(&packet, 0x0002); // Message charset number, again copied from ICQ 2003b packWord(&packet, 0x0000); // Message charset subset ppText = pszText; // we must convert the widestring - for (i = 0; idwMsgID1, pCookieData->dwMsgID2, dwCookie, ICQ_VERSION, (BYTE)pCookieData->bMessageType, 0, - wPriority, 0, 0, (BYTE)((pCookieData->nAckType == ACKTYPE_SERVER)?1:0)); + packServChannel2Header(&packet, this, dwUin, (WORD)(nBodyLen + (szCap ? 53 : 11)), pCookieData->dwMsgID1, pCookieData->dwMsgID2, dwCookie, ICQ_VERSION, (BYTE)pCookieData->bMessageType, 0, + wPriority, 0, 0, (BYTE)((pCookieData->nAckType == ACKTYPE_SERVER) ? 1 : 0)); - packLEWord(&packet, (WORD)(nBodyLen+1)); // Length of message - packBuffer(&packet, (LPBYTE)szMessage, (WORD)(nBodyLen+1)); // Message + packLEWord(&packet, (WORD)(nBodyLen + 1)); // Length of message + packBuffer(&packet, (LPBYTE)szMessage, (WORD)(nBodyLen + 1)); // Message packMsgColorInfo(&packet); - if (szCap) - { + if (szCap) { packLEDWord(&packet, 0x00000026); // length of GUID packBuffer(&packet, (LPBYTE)szCap, 0x26); // UTF-8 GUID } @@ -447,7 +442,7 @@ DWORD CIcqProto::icq_SendChannel2Contacts(DWORD dwUin, char *szUid, HANDLE hCont WORD wPacketLength = wDataLen + wNamesLen + 0x12; // Pack the standard header - packServMsgSendHeader(&packet, dwCookie, pCookieData->dwMsgID1, pCookieData->dwMsgID2, dwUin, szUid, 2, (WORD)(wPacketLength + ((pCookieData->nAckType == ACKTYPE_SERVER)?0x22:0x1E))); + packServMsgSendHeader(&packet, dwCookie, pCookieData->dwMsgID1, pCookieData->dwMsgID2, dwUin, szUid, 2, (WORD)(wPacketLength + ((pCookieData->nAckType == ACKTYPE_SERVER) ? 0x22 : 0x1E))); packServTLV5HeaderBasic(&packet, wPacketLength, pCookieData->dwMsgID1, pCookieData->dwMsgID2, 0, MCAP_CONTACTS); @@ -457,8 +452,7 @@ DWORD CIcqProto::icq_SendChannel2Contacts(DWORD dwUin, char *szUid, HANDLE hCont packTLV(&packet, 0x2712, wNamesLen, (LPBYTE)pNames);// TLV: 0x2712 Extended Content (Contact NickNames) // Pack request ack TLV - if (pCookieData->nAckType == ACKTYPE_SERVER) - { + if (pCookieData->nAckType == ACKTYPE_SERVER) { packDWord(&packet, 0x00030000); // TLV(3) } @@ -493,8 +487,7 @@ DWORD CIcqProto::icq_SendChannel4Message(DWORD dwUin, HANDLE hContact, BYTE bMsg packMsgColorInfo(&packet); // Pack request ack TLV - if (pCookieData->nAckType == ACKTYPE_SERVER) - { + if (pCookieData->nAckType == ACKTYPE_SERVER) { packDWord(&packet, 0x00030000); // TLV(3) } @@ -511,8 +504,7 @@ void CIcqProto::sendOwnerInfoRequest(void) { icq_packet packet; - if (m_bLegacyFix) - { + if (m_bLegacyFix) { cookie_fam15_data *pCookieData = (cookie_fam15_data*)SAFE_MALLOC(sizeof(cookie_fam15_data)); pCookieData->bRequestType = REQUESTTYPE_OWNER; DWORD dwCookie = AllocateCookie(CKT_FAMILYSPECIAL, 0, NULL, (void*)pCookieData); @@ -521,8 +513,7 @@ void CIcqProto::sendOwnerInfoRequest(void) packLEWord(&packet, META_REQUEST_SELF_INFO); packLEDWord(&packet, m_dwLocalUIN); } - else - { + else { cookie_directory_data *pCookieData = (cookie_directory_data*)SAFE_MALLOC(sizeof(cookie_directory_data)); pCookieData->bRequestType = DIRECTORYREQUEST_INFOOWNER; @@ -569,12 +560,11 @@ DWORD CIcqProto::icq_sendGetInfoServ(HANDLE hContact, DWORD dwUin, int bManual) if (IsServerOverRate(ICQ_EXTENSIONS_FAMILY, ICQ_META_CLI_REQUEST, bManual ? RML_IDLE_10 : RML_IDLE_50)) return dwCookie; - DBVARIANT infoToken = {DBVT_DELETED}; + DBVARIANT infoToken = { DBVT_DELETED }; BYTE *pToken = NULL; WORD cbToken = 0; - if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &infoToken)) - { // retrieve user details using privacy token + if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &infoToken)) { // retrieve user details using privacy token cbToken = infoToken.cpbVal; pToken = (BYTE*)_alloca(cbToken); memcpy(pToken, infoToken.pbVal, cbToken); @@ -584,8 +574,7 @@ DWORD CIcqProto::icq_sendGetInfoServ(HANDLE hContact, DWORD dwUin, int bManual) cookie_directory_data *pCookieData = (cookie_directory_data*)SAFE_MALLOC(sizeof(cookie_directory_data)); - if (m_bLegacyFix) - { + if (m_bLegacyFix) { pCookieData->bRequestType = REQUESTTYPE_USERDETAILED; dwCookie = AllocateCookie(CKT_FAMILYSPECIAL, 0, hContact, (void*)pCookieData); @@ -721,12 +710,10 @@ void CIcqProto::icq_sendSetAimAwayMsgServ(const char *szMsg) DWORD dwCookie = GenerateCookie(ICQ_LOCATION_SET_USER_INFO); - if (wMsgLen) - { + if (wMsgLen) { if (wMsgLen > 0x1000) wMsgLen = 0x1000; // limit length - if (IsUSASCII(szMsg, wMsgLen)) - { + if (IsUSASCII(szMsg, wMsgLen)) { const char* fmt = "text/x-aolrtf; charset=\"us-ascii\""; const WORD fmtlen = (WORD)strlen(fmt); @@ -736,8 +723,7 @@ void CIcqProto::icq_sendSetAimAwayMsgServ(const char *szMsg) packTLV(&packet, 0x03, fmtlen, (LPBYTE)fmt); packTLV(&packet, 0x04, wMsgLen, (LPBYTE)szMsg); } - else - { + else { const char* fmt = "text/x-aolrtf; charset=\"unicode-2-0\""; const WORD fmtlen = (WORD)strlen(fmt); @@ -755,8 +741,7 @@ void CIcqProto::icq_sendSetAimAwayMsgServ(const char *szMsg) packTLV(&packet, 0x04, wMsgLen, (LPBYTE)szMsgW2); } } - else - { + else { serverPacketInit(&packet, 19); packFNACHeader(&packet, ICQ_LOCATION_FAMILY, ICQ_LOCATION_SET_USER_INFO, 0, dwCookie); packTLV(&packet, 0x0f, 1, (LPBYTE)"\x02"); @@ -816,7 +801,7 @@ void CIcqProto::icq_sendFileSendServv8(filetransfer* ft, const char *szFiles, in // 202 + UIN len + file description (no null) + file name (null included) // Packet size = Flap length + 4 - WORD wFlapLen = 178 + wDescrLen + wFilesLen + (nAckType == ACKTYPE_SERVER?4:0); + WORD wFlapLen = 178 + wDescrLen + wFilesLen + (nAckType == ACKTYPE_SERVER ? 4 : 0); packServMsgSendHeader(&packet, ft->dwCookie, ft->pMessage.dwMsgID1, ft->pMessage.dwMsgID2, ft->dwUin, NULL, 2, wFlapLen); // TLV(5) header @@ -876,7 +861,7 @@ void CIcqProto::icq_sendFileAcceptServv8(DWORD dwUin, DWORD TS1, DWORD TS2, DWOR // 202 + UIN len + file description (no null) + file name (null included) // Packet size = Flap length + 4 - WORD wFlapLen = 178 + wDescrLen + wFilesLen + (nAckType == ACKTYPE_SERVER?4:0); + WORD wFlapLen = 178 + wDescrLen + wFilesLen + (nAckType == ACKTYPE_SERVER ? 4 : 0); packServMsgSendHeader(&packet, dwCookie, TS1, TS2, dwUin, NULL, 2, wFlapLen); // TLV(5) header @@ -886,7 +871,7 @@ void CIcqProto::icq_sendFileAcceptServv8(DWORD dwUin, DWORD TS1, DWORD TS2, DWOR packServDCInfo(&packet, this, !accepted); // TLV(0x2711) header - packServTLV2711Header(&packet, (WORD)dwCookie, ICQ_VERSION, MTYPE_PLUGIN, 0, (WORD)(accepted ? 0:1), 0, 69 + wDescrLen + wFilesLen); + packServTLV2711Header(&packet, (WORD)dwCookie, ICQ_VERSION, MTYPE_PLUGIN, 0, (WORD)(accepted ? 0 : 1), 0, 69 + wDescrLen + wFilesLen); // packEmptyMsg(&packet); // Message (unused) @@ -906,8 +891,7 @@ void CIcqProto::icq_sendFileAcceptServv8(DWORD dwUin, DWORD TS1, DWORD TS2, DWOR SAFE_FREE(&szDescrAnsi); // Pack request server ack TLV - if (nAckType == ACKTYPE_SERVER) - { + if (nAckType == ACKTYPE_SERVER) { packDWord(&packet, 0x00030000); // TLV(3) } @@ -937,7 +921,7 @@ void CIcqProto::icq_sendFileAcceptServv7(DWORD dwUin, DWORD TS1, DWORD TS2, DWOR // 150 + UIN len + file description (with null) + file name (2 nulls) // Packet size = Flap length + 4 - WORD wFlapLen = 127 + wDescrLen + 1 + wFilesLen + (nAckType == ACKTYPE_SERVER?4:0); + WORD wFlapLen = 127 + wDescrLen + 1 + wFilesLen + (nAckType == ACKTYPE_SERVER ? 4 : 0); packServMsgSendHeader(&packet, dwCookie, TS1, TS2, dwUin, NULL, 2, wFlapLen); // TLV(5) header @@ -947,7 +931,7 @@ void CIcqProto::icq_sendFileAcceptServv7(DWORD dwUin, DWORD TS1, DWORD TS2, DWOR packServDCInfo(&packet, this, !accepted); // TLV(0x2711) header - packServTLV2711Header(&packet, (WORD)dwCookie, ICQ_VERSION, MTYPE_FILEREQ, 0, (WORD)(accepted ? 0:1), 0, 19 + wDescrLen + wFilesLen); + packServTLV2711Header(&packet, (WORD)dwCookie, ICQ_VERSION, MTYPE_FILEREQ, 0, (WORD)(accepted ? 0 : 1), 0, 19 + wDescrLen + wFilesLen); // packLEWord(&packet, (WORD)(wDescrLen + 1)); // Description packBuffer(&packet, (LPBYTE)szDescrAnsi, (WORD)(wDescrLen + 1)); @@ -963,8 +947,7 @@ void CIcqProto::icq_sendFileAcceptServv7(DWORD dwUin, DWORD TS1, DWORD TS2, DWOR SAFE_FREE(&szDescrAnsi); // Pack request server ack TLV - if (nAckType == ACKTYPE_SERVER) - { + if (nAckType == ACKTYPE_SERVER) { packDWord(&packet, 0x00030000); // TLV(3) } @@ -979,13 +962,11 @@ void CIcqProto::icq_sendFileAcceptServ(DWORD dwUin, filetransfer *ft, int nAckTy if (ft->bEmptyDesc) szDesc = ""; // keep empty if it originally was (Trillian workaround) - if (ft->nVersion >= 8) - { + if (ft->nVersion >= 8) { icq_sendFileAcceptServv8(dwUin, ft->pMessage.dwMsgID1, ft->pMessage.dwMsgID2, ft->dwCookie, ft->szFilename, szDesc, ft->dwTotalSize, wListenPort, TRUE, nAckType); debugLogA("Sent file accept v%u through server, port %u", 8, wListenPort); } - else - { + else { icq_sendFileAcceptServv7(dwUin, ft->pMessage.dwMsgID1, ft->pMessage.dwMsgID2, ft->dwCookie, ft->szFilename, szDesc, ft->dwTotalSize, wListenPort, TRUE, nAckType); debugLogA("Sent file accept v%u through server, port %u", 7, wListenPort); } @@ -994,13 +975,11 @@ void CIcqProto::icq_sendFileAcceptServ(DWORD dwUin, filetransfer *ft, int nAckTy void CIcqProto::icq_sendFileDenyServ(DWORD dwUin, filetransfer *ft, const char *szReason, int nAckType) { - if (ft->nVersion >= 8) - { + if (ft->nVersion >= 8) { icq_sendFileAcceptServv8(dwUin, ft->pMessage.dwMsgID1, ft->pMessage.dwMsgID2, ft->dwCookie, ft->szFilename, szReason, ft->dwTotalSize, wListenPort, FALSE, nAckType); debugLogA("Sent file deny v%u through server", 8); } - else - { + else { icq_sendFileAcceptServv7(dwUin, ft->pMessage.dwMsgID1, ft->pMessage.dwMsgID2, ft->dwCookie, ft->szFilename, szReason, ft->dwTotalSize, wListenPort, FALSE, nAckType); debugLogA("Sent file deny v%u through server", 7); } @@ -1011,24 +990,20 @@ void CIcqProto::icq_sendAwayMsgReplyServ(DWORD dwUin, DWORD dwMsgID1, DWORD dwMs { HANDLE hContact = HContactFromUIN(dwUin, NULL); - if (validateStatusMessageRequest(hContact, msgType)) - { + if (validateStatusMessageRequest(hContact, msgType)) { NotifyEventHooks(m_modeMsgsEvent, (WPARAM)msgType, (LPARAM)dwUin); icq_lock l(m_modeMsgsMutex); - if (szMsg && *szMsg) - { + if (szMsg && *szMsg) { char *pszMsg = NULL; WORD wReplyVersion = ICQ_VERSION; - if (wVersion == 9) - { + if (wVersion >= 9) { pszMsg = *szMsg; wReplyVersion = 9; } - else - { // only v9 protocol supports UTF-8 mode messagees + else { // only v9 protocol supports UTF-8 mode messagees WORD wMsgLen = strlennull(*szMsg) + 1; char *szAnsiMsg = (char*)_alloca(wMsgLen); @@ -1059,24 +1034,20 @@ void CIcqProto::icq_sendAwayMsgReplyServExt(DWORD dwUin, char *szUID, DWORD dwMs { HANDLE hContact = HContactFromUID(dwUin, szUID, NULL); - if (validateStatusMessageRequest(hContact, msgType)) - { + if (validateStatusMessageRequest(hContact, msgType)) { NotifyEventHooks(m_modeMsgsEvent, (WPARAM)msgType, (LPARAM)dwUin); icq_lock l(m_modeMsgsMutex); - if (szMsg && *szMsg) - { + if (szMsg && *szMsg) { char *pszMsg = NULL; WORD wReplyVersion = ICQ_VERSION; - if (wVersion == 9) - { + if (wVersion >= 9) pszMsg = *szMsg; - wReplyVersion = 9; - } - else - { // only v9 protocol supports UTF-8 mode messagees + else { // only v9 protocol supports UTF-8 mode messagees + wReplyVersion = 8; + WORD wMsgLen = strlennull(*szMsg) + 1; char *szAnsiMsg = (char*)_alloca(wMsgLen); @@ -1146,9 +1117,8 @@ DWORD CIcqProto::SearchByUin(DWORD dwUin) { WORD wInfoLen; icq_packet pBuffer; // I reuse the ICQ packet type as a generic buffer - // I should be ashamed! ;) - if (m_bLegacyFix) - { + // I should be ashamed! ;) + if (m_bLegacyFix) { // Calculate data size wInfoLen = 8; @@ -1185,11 +1155,10 @@ DWORD CIcqProto::SearchByUin(DWORD dwUin) DWORD CIcqProto::SearchByNames(const char *pszNick, const char *pszFirstName, const char *pszLastName, WORD wPage) { // use directory search like ICQ6 does WORD wInfoLen = 0; - WORD wNickLen,wFirstLen,wLastLen; + WORD wNickLen, wFirstLen, wLastLen; icq_packet pBuffer; // I reuse the ICQ packet type as a generic buffer - // I should be ashamed! ;) - if (m_bLegacyFix) - { + // I should be ashamed! ;) + if (m_bLegacyFix) { // Legacy protocol uses ANSI-string searches char* pszNickAnsi = NULL; @@ -1226,18 +1195,15 @@ DWORD CIcqProto::SearchByNames(const char *pszNick, const char *pszFirstName, co int pBufferPos = 0; // Pack the search details - if (wFirstLen > 0) - { + if (wFirstLen > 0) { packLETLVLNTS(&pBuffer.pData, &pBufferPos, pszFirstNameAnsi, TLV_FIRSTNAME); } - if (wLastLen > 0) - { + if (wLastLen > 0) { packLETLVLNTS(&pBuffer.pData, &pBufferPos, pszLastNameAnsi, TLV_LASTNAME); } - if (wNickLen > 0) - { + if (wNickLen > 0) { packLETLVLNTS(&pBuffer.pData, &pBufferPos, pszNickAnsi, TLV_NICKNAME); } @@ -1299,8 +1265,7 @@ DWORD CIcqProto::SearchByMail(const char* pszEmail) _ASSERTE(wEmailLen); - if (wEmailLen > 0) - { + if (wEmailLen > 0) { // Calculate data size wInfoLen = wEmailLen + 7; @@ -1328,8 +1293,7 @@ DWORD CIcqProto::sendDirectorySearchPacket(const BYTE *pSearchData, WORD wDataLe _ASSERTE(wDataLen >= 4); cookie_directory_data *pCookieData = (cookie_directory_data*)SAFE_MALLOC(sizeof(cookie_directory_data)); - if (pCookieData) - { + if (pCookieData) { pCookieData->bRequestType = DIRECTORYREQUEST_SEARCH; dwCookie = AllocateCookie(CKT_DIRECTORY_QUERY, 0, NULL, (void*)pCookieData); } @@ -1348,8 +1312,7 @@ DWORD CIcqProto::sendDirectorySearchPacket(const BYTE *pSearchData, WORD wDataLe packWord(&packet, wDataLen + (bOnlineUsersOnly ? 6 : 0)); packBuffer(&packet, pSearchData, wDataLen); - if (bOnlineUsersOnly) - { // Pack "Online users only" flag + if (bOnlineUsersOnly) { // Pack "Online users only" flag packTLVWord(&packet, 0x136, 1); } @@ -1376,7 +1339,7 @@ DWORD CIcqProto::sendTLVSearchPacket(BYTE bType, char* pSearchDataBuf, WORD wSea DWORD dwCookie = AllocateCookie(CKT_SEARCH, 0, 0, pCookie); // Pack headers - packServIcqExtensionHeader(&packet, this, (WORD)(wInfoLen + (wSearchType==META_SEARCH_GENERIC?7:2)), CLI_META_INFO_REQ, (WORD)dwCookie); + packServIcqExtensionHeader(&packet, this, (WORD)(wInfoLen + (wSearchType == META_SEARCH_GENERIC ? 7 : 2)), CLI_META_INFO_REQ, (WORD)dwCookie); // Pack search type packLEWord(&packet, wSearchType); @@ -1384,8 +1347,7 @@ DWORD CIcqProto::sendTLVSearchPacket(BYTE bType, char* pSearchDataBuf, WORD wSea // Pack search data packBuffer(&packet, (LPBYTE)pSearchDataBuf, wInfoLen); - if (wSearchType == META_SEARCH_GENERIC && bOnlineUsersOnly) - { // Pack "Online users only" flag - only for generic search + if (wSearchType == META_SEARCH_GENERIC && bOnlineUsersOnly) { // Pack "Online users only" flag - only for generic search BYTE bData = 1; packTLV(&packet, TLV_ONLINEONLY, 1, &bData); } @@ -1397,14 +1359,13 @@ DWORD CIcqProto::sendTLVSearchPacket(BYTE bType, char* pSearchDataBuf, WORD wSea } -DWORD CIcqProto::icq_sendAdvancedSearchServ(BYTE* fieldsBuffer,int bufferLen) +DWORD CIcqProto::icq_sendAdvancedSearchServ(BYTE* fieldsBuffer, int bufferLen) { icq_packet packet; DWORD dwCookie; cookie_search *pCookie = (cookie_search*)SAFE_MALLOC(sizeof(cookie_search)); - if (pCookie) - { + if (pCookie) { pCookie->bSearchType = SEARCHTYPE_DETAILS; dwCookie = AllocateCookie(CKT_SEARCH, 0, 0, pCookie); } @@ -1427,15 +1388,13 @@ DWORD CIcqProto::icq_searchAimByEmail(const char* pszEmail, DWORD dwSearchId) cookie_search* pCookie; WORD wEmailLen; - if (!FindCookie(dwSearchId, NULL, (void**)&pCookie)) - { + if (!FindCookie(dwSearchId, NULL, (void**)&pCookie)) { dwSearchId = 0; pCookie = (cookie_search*)SAFE_MALLOC(sizeof(cookie_search)); pCookie->bSearchType = SEARCHTYPE_EMAIL; } - if (pCookie) - { + if (pCookie) { pCookie->dwMainId = dwSearchId; pCookie->szObject = null_strdup(pszEmail); dwCookie = AllocateCookie(CKT_SEARCH, ICQ_LOOKUP_REQUEST, 0, pCookie); @@ -1507,8 +1466,7 @@ DWORD CIcqProto::icq_sendSMSServ(const char *szPhoneNumber, const char *szMsg) szMyNick = null_strdup((char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)(HANDLE)NULL, 0)); nBufferSize = 1 + strlennull(szMyNick) + strlennull(szPhoneNumber) + strlennull(szMsg) + sizeof("1252utf80000000000Yes"); - if (szBuffer = (char *)_alloca(nBufferSize)) - { + if (szBuffer = (char *)_alloca(nBufferSize)) { wBufferLen = mir_snprintf(szBuffer, nBufferSize, "" @@ -1555,8 +1513,7 @@ DWORD CIcqProto::icq_sendSMSServ(const char *szPhoneNumber, const char *szMsg) sendServPacket(&packet); } - else - { + else { dwCookie = 0; } @@ -1597,25 +1554,21 @@ void CIcqProto::icq_sendRemoveContact(DWORD dwUin, const char *szUid) void CIcqProto::icq_sendChangeVisInvis(HANDLE hContact, DWORD dwUin, char* szUID, int list, int add) { // TODO: This needs grouping & rate management // Tell server to change our server-side contact visbility list - if (m_bSsiEnabled) - { + if (m_bSsiEnabled) { WORD wContactId; char* szSetting; WORD wType; - if (list == 0) - { + if (list == 0) { wType = SSI_ITEM_PERMIT; szSetting = DBSETTING_SERVLIST_PERMIT; } - else - { + else { wType = SSI_ITEM_DENY; szSetting = DBSETTING_SERVLIST_DENY; } - if (add) - { + if (add) { // check if we should make the changes, this is 2nd level check if (getWord(hContact, szSetting, 0) != 0) return; @@ -1627,13 +1580,11 @@ void CIcqProto::icq_sendChangeVisInvis(HANDLE hContact, DWORD dwUin, char* szUID setWord(hContact, szSetting, wContactId); } - else - { + else { // Remove wContactId = getWord(hContact, szSetting, 0); - if (wContactId) - { + if (wContactId) { icq_removeServerPrivacyItem(hContact, dwUin, szUID, wContactId, wType); delSetting(hContact, szSetting); @@ -1852,7 +1803,7 @@ void CIcqProto::icq_sendReverseFailed(directconnect* dc, DWORD dwMsgID1, DWORD d int nUinLen = getUINLen(dc->dwRemoteUin); serverPacketInit(&packet, (WORD)(nUinLen + 74)); - packFNACHeader(&packet, ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE, 0, ICQ_MSG_RESPONSE<<0x10 | (dwCookie & 0x7FFF)); + packFNACHeader(&packet, ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE, 0, ICQ_MSG_RESPONSE << 0x10 | (dwCookie & 0x7FFF)); packLEDWord(&packet, dwMsgID1); // Msg ID part 1 packLEDWord(&packet, dwMsgID2); // Msg ID part 2 packWord(&packet, 0x02); @@ -1874,7 +1825,7 @@ void CIcqProto::oft_sendFileRequest(DWORD dwUin, char *szUid, oscar_filetransfer { icq_packet packet; - size_t size = strlennull(ft->szDescription)+strlennull(pszFiles) + 160; + size_t size = strlennull(ft->szDescription) + strlennull(pszFiles) + 160; char *szCoolStr = (char *)_alloca(size); mir_snprintf(szCoolStr, size, "%s%I64u1%s", pszFiles, ft->qwTotalSize, ft->szDescription); szCoolStr = MangleXml(szCoolStr, strlennull(szCoolStr)); @@ -1890,25 +1841,21 @@ void CIcqProto::oft_sendFileRequest(DWORD dwUin, char *szUid, oscar_filetransfer packTLV(&packet, 0x0D, 5, (LPBYTE)"utf-8"); // Charset packTLV(&packet, 0x0C, (WORD)strlennull(szCoolStr), (LPBYTE)szCoolStr); // User message (CoolData XML) SAFE_FREE(&szCoolStr); - if (ft->bUseProxy) - { + if (ft->bUseProxy) { packTLVDWord(&packet, 0x02, ft->dwProxyIP); // Proxy IP packTLVDWord(&packet, 0x16, ft->dwProxyIP ^ 0x0FFFFFFFF); // Proxy IP check } - else - { + else { packTLVDWord(&packet, 0x02, dwLocalInternalIP); packTLVDWord(&packet, 0x16, dwLocalInternalIP ^ 0x0FFFFFFFF); } packTLVDWord(&packet, 0x03, dwLocalInternalIP); // Client IP - if (ft->bUseProxy) - { + if (ft->bUseProxy) { packTLVWord(&packet, 0x05, ft->wRemotePort); packTLVWord(&packet, 0x17, (WORD)(ft->wRemotePort ^ 0x0FFFF)); packDWord(&packet, 0x00100000); // Proxy flag } - else - { + else { oscar_listener *pListener = (oscar_listener*)ft->listener; packTLVWord(&packet, 0x05, pListener->wPort); @@ -1964,8 +1911,7 @@ void CIcqProto::oft_sendFileResponse(DWORD dwUin, char *szUid, oscar_filetransfe void CIcqProto::oft_sendFileDeny(DWORD dwUin, char *szUid, oscar_filetransfer *ft) { - if (dwUin) - { // ICQ clients uses special deny file transfer + if (dwUin) { // ICQ clients uses special deny file transfer oft_sendFileResponse(dwUin, szUid, ft, 0x01); } else diff --git a/protocols/IcqOscarJ/src/utilities.cpp b/protocols/IcqOscarJ/src/utilities.cpp index de9d020fd6..a3e8064992 100644 --- a/protocols/IcqOscarJ/src/utilities.cpp +++ b/protocols/IcqOscarJ/src/utilities.cpp @@ -218,53 +218,52 @@ char* MirandaStatusToStringUtf(int mirandaStatus) char** CIcqProto::MirandaStatusToAwayMsg(int nStatus) { switch (nStatus) { + case ID_STATUS_ONLINE: + return &m_modeMsgs.szOnline; -case ID_STATUS_ONLINE: - return &m_modeMsgs.szOnline; + case ID_STATUS_AWAY: + return &m_modeMsgs.szAway; -case ID_STATUS_AWAY: - return &m_modeMsgs.szAway; + case ID_STATUS_NA: + return &m_modeMsgs.szNa; -case ID_STATUS_NA: - return &m_modeMsgs.szNa; - -case ID_STATUS_OCCUPIED: - return &m_modeMsgs.szOccupied; + case ID_STATUS_OCCUPIED: + return &m_modeMsgs.szOccupied; -case ID_STATUS_DND: - return &m_modeMsgs.szDnd; + case ID_STATUS_DND: + return &m_modeMsgs.szDnd; -case ID_STATUS_FREECHAT: - return &m_modeMsgs.szFfc; + case ID_STATUS_FREECHAT: + return &m_modeMsgs.szFfc; -default: - return NULL; + default: + return NULL; } } int AwayMsgTypeToStatus(int nMsgType) { switch (nMsgType) { -case MTYPE_AUTOONLINE: - return ID_STATUS_ONLINE; + case MTYPE_AUTOONLINE: + return ID_STATUS_ONLINE; -case MTYPE_AUTOAWAY: - return ID_STATUS_AWAY; + case MTYPE_AUTOAWAY: + return ID_STATUS_AWAY; -case MTYPE_AUTOBUSY: - return ID_STATUS_OCCUPIED; + case MTYPE_AUTOBUSY: + return ID_STATUS_OCCUPIED; -case MTYPE_AUTONA: - return ID_STATUS_NA; + case MTYPE_AUTONA: + return ID_STATUS_NA; -case MTYPE_AUTODND: - return ID_STATUS_DND; + case MTYPE_AUTODND: + return ID_STATUS_DND; -case MTYPE_AUTOFFC: - return ID_STATUS_FREECHAT; + case MTYPE_AUTOFFC: + return ID_STATUS_FREECHAT; -default: - return ID_STATUS_OFFLINE; + default: + return ID_STATUS_OFFLINE; } } @@ -273,16 +272,14 @@ void SetGatewayIndex(HANDLE hConn, DWORD dwIndex) { icq_lock l(gatewayMutex); - for (int i = 0; i < gatewayCount; i++) - { - if (hConn == gateways[i].hConn) - { + for (int i = 0; i < gatewayCount; i++) { + if (hConn == gateways[i].hConn) { gateways[i].dwIndex = dwIndex; return; } } - gateways = (gateway_index *)SAFE_REALLOC(gateways, sizeof(gateway_index) * (gatewayCount + 1)); + gateways = (gateway_index *)SAFE_REALLOC(gateways, sizeof(gateway_index)* (gatewayCount + 1)); gateways[gatewayCount].hConn = hConn; gateways[gatewayCount].dwIndex = dwIndex; gatewayCount++; @@ -293,8 +290,7 @@ DWORD GetGatewayIndex(HANDLE hConn) { icq_lock l(gatewayMutex); - for (int i = 0; i < gatewayCount; i++) - { + for (int i = 0; i < gatewayCount; i++) { if (hConn == gateways[i].hConn) return gateways[i].dwIndex; } @@ -307,13 +303,11 @@ void FreeGatewayIndex(HANDLE hConn) { icq_lock l(gatewayMutex); - for (int i = 0; i < gatewayCount; i++) - { - if (hConn == gateways[i].hConn) - { + for (int i = 0; i < gatewayCount; i++) { + if (hConn == gateways[i].hConn) { gatewayCount--; - memmove(&gateways[i], &gateways[i+1], sizeof(gateway_index) * (gatewayCount - i)); - gateways = (gateway_index*)SAFE_REALLOC(gateways, sizeof(gateway_index) * gatewayCount); + memmove(&gateways[i], &gateways[i + 1], sizeof(gateway_index)* (gatewayCount - i)); + gateways = (gateway_index*)SAFE_REALLOC(gateways, sizeof(gateway_index)* gatewayCount); // Gateway found, exit loop break; @@ -326,7 +320,7 @@ void CIcqProto::AddToSpammerList(DWORD dwUIN) { icq_lock l(gatewayMutex); - spammerList = (DWORD *)SAFE_REALLOC(spammerList, sizeof(DWORD) * (spammerListCount + 1)); + spammerList = (DWORD *)SAFE_REALLOC(spammerList, sizeof(DWORD)* (spammerListCount + 1)); spammerList[spammerListCount] = dwUIN; spammerListCount++; } @@ -337,10 +331,8 @@ BOOL CIcqProto::IsOnSpammerList(DWORD dwUIN) icq_lock l(gatewayMutex); for (int i = 0; i < spammerListCount; i++) - { if (dwUIN == spammerList[i]) return TRUE; - } return FALSE; } @@ -382,8 +374,7 @@ void CIcqProto::InitContactsCache() HANDLE hContact = FindFirstContact(); - while (hContact) - { + while (hContact) { DWORD dwUin; uid_str szUid; @@ -400,8 +391,7 @@ void CIcqProto::UninitContactsCache(void) contactsCacheMutex->Enter(); // cleanup the cache - for (int i = 0; i < contactsCache.getCount(); i++) - { + for (int i = 0; i < contactsCache.getCount(); i++) { icq_contacts_cache *cache_item = contactsCache[i]; SAFE_FREE((void**)&cache_item->szUid); @@ -425,12 +415,10 @@ void CIcqProto::DeleteFromContactsCache(HANDLE hContact) { icq_lock l(contactsCacheMutex); - for (int i = 0; i < contactsCache.getCount(); i++) - { + for (int i = 0; i < contactsCache.getCount(); i++) { icq_contacts_cache *cache_item = contactsCache[i]; - if (cache_item->hContact == hContact) - { + if (cache_item->hContact == hContact) { #ifdef _DEBUG debugLogA("Removing contact from cache: %u%s%s, position: %u", cache_item->dwUin, cache_item->dwUin ? "" : " - ", cache_item->dwUin ? "" : cache_item->szUid, i); #endif @@ -446,7 +434,7 @@ void CIcqProto::DeleteFromContactsCache(HANDLE hContact) HANDLE CIcqProto::HandleFromCacheByUid(DWORD dwUin, const char *szUid) { - icq_contacts_cache cache_item = {NULL, dwUin, szUid}; + icq_contacts_cache cache_item = { NULL, dwUin, szUid }; icq_lock l(contactsCacheMutex); // find in list @@ -466,13 +454,11 @@ HANDLE CIcqProto::HContactFromUIN(DWORD dwUin, int *Added) if (hContact) return hContact; hContact = FindFirstContact(); - while (hContact) - { + while (hContact) { DWORD dwContactUin; dwContactUin = getContactUin(hContact); - if (dwContactUin == dwUin) - { + if (dwContactUin == dwUin) { AddToContactsCache(hContact, dwUin, NULL); return hContact; } @@ -481,17 +467,14 @@ HANDLE CIcqProto::HContactFromUIN(DWORD dwUin, int *Added) } //not present: add - if (Added) - { + if (Added) { hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); - if (!hContact) - { + if (!hContact) { debugLogA("Failed to create ICQ contact %u", dwUin); return INVALID_HANDLE_VALUE; } - if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)m_szModuleName) != 0) - { + if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)m_szModuleName) != 0) { // For some reason we failed to register the protocol to this contact CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); debugLogA("Failed to register ICQ contact %u", dwUin); @@ -500,8 +483,7 @@ HANDLE CIcqProto::HContactFromUIN(DWORD dwUin, int *Added) setDword(hContact, UNIQUEIDSETTING, dwUin); - if (!bIsSyncingCL) - { + if (!bIsSyncingCL) { db_set_b(hContact, "CList", "NotOnList", 1); setContactHidden(hContact, 1); @@ -539,17 +521,13 @@ HANDLE CIcqProto::HContactFromUID(DWORD dwUin, const char *szUid, int *Added) if (hContact) return hContact; hContact = FindFirstContact(); - while (hContact) - { + while (hContact) { DWORD dwContactUin; uid_str szContactUid; - if (!getContactUid(hContact, &dwContactUin, &szContactUid)) - { - if (!dwContactUin && !stricmpnull(szContactUid, szUid)) - { - if (strcmpnull(szContactUid, szUid)) - { // fix case in SN + if (!getContactUid(hContact, &dwContactUin, &szContactUid)) { + if (!dwContactUin && !stricmpnull(szContactUid, szUid)) { + if (strcmpnull(szContactUid, szUid)) { // fix case in SN setString(hContact, UNIQUEIDSETTING, szUid); } return hContact; @@ -559,15 +537,13 @@ HANDLE CIcqProto::HContactFromUID(DWORD dwUin, const char *szUid, int *Added) } //not present: add - if (Added) - { + if (Added) { hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)m_szModuleName); setString(hContact, UNIQUEIDSETTING, szUid); - if (!bIsSyncingCL) - { + if (!bIsSyncingCL) { db_set_b(hContact, "CList", "NotOnList", 1); setContactHidden(hContact, 1); @@ -591,7 +567,7 @@ HANDLE CIcqProto::HContactFromAuthEvent(HANDLE hEvent) DBEVENTINFO dbei = { sizeof(dbei) }; DWORD body[3]; - dbei.cbBlob = sizeof(DWORD)*2; + dbei.cbBlob = sizeof(DWORD)* 2; dbei.pBlob = (PBYTE)&body; if (db_event_get(hEvent, &dbei)) @@ -706,8 +682,7 @@ char* __fastcall null_strcpy(char *dest, const char *src, size_t maxlen) if (!dest) return NULL; - if (src && src[0]) - { + if (src && src[0]) { strncpy(dest, src, maxlen); dest[maxlen] = '\0'; } @@ -723,8 +698,7 @@ WCHAR* __fastcall null_strcpy(WCHAR *dest, const WCHAR *src, size_t maxlen) if (!dest) return NULL; - if (src && src[0]) - { + if (src && src[0]) { wcsncpy(dest, src, maxlen); dest[maxlen] = '\0'; } @@ -739,7 +713,7 @@ int __fastcall null_strcut(char *string, int maxlen) { // limit the string to max length (null & utf-8 strings ready) int len = (int)strlennull(string); - if (len < maxlen) + if (len < maxlen) return len; len = maxlen; @@ -760,8 +734,7 @@ void parseServerAddress(char* szServer, WORD* wPort) int i = 0; while (szServer[i] && szServer[i] != ':') i++; - if (szServer[i] == ':') - { // port included + if (szServer[i] == ':') { // port included *wPort = atoi(&szServer[i + 1]); } // otherwise do not change port @@ -770,37 +743,31 @@ void parseServerAddress(char* szServer, WORD* wPort) char *DemangleXml(const char *string, int len) { - char *szWork = (char*)SAFE_MALLOC(len+1), *szChar = szWork; + char *szWork = (char*)SAFE_MALLOC(len + 1), *szChar = szWork; int i; - for (i=0; i') l += 4; else if (string[i]=='&') l += 5; else if (string[i]=='"') l += 6; else l++; + for (i = 0; i < len; i++) { + if (string[i] == '<' || string[i] == '>') l += 4; else if (string[i] == '&') l += 5; else if (string[i] == '"') l += 6; else l++; } szChar = szWork = (char*)SAFE_MALLOC(l + 1); - for (i = 0; i') - { + else if (string[i] == '>') { *(DWORD*)szChar = ';tg&'; szChar += 4; } - else if (string[i]=='&') - { + else if (string[i] == '&') { *(DWORD*)szChar = 'pma&'; szChar += 4; *szChar = ';'; szChar++; } - else if (string[i]=='"') - { + else if (string[i] == '"') { *(DWORD*)szChar = 'ouq&'; szChar += 4; *(WORD*)szChar = ';t'; szChar += 2; } - else - { + else { *szChar = string[i]; szChar++; } @@ -860,16 +820,13 @@ char *MangleXml(const char *string, int len) char *EliminateHtml(const char *string, int len) { char *tmp = (char*)SAFE_MALLOC(len + 1); - int i,j; + int i, j; BOOL tag = FALSE; char *res; - for (i=0,j=0;i", 4) || !_strnicmp(string + i, "
", 5))) - { // insert newline + for (i = 0, j = 0; i < len; i++) { + if (!tag && string[i] == '<') { + if ((i + 4 <= len) && (!_strnicmp(string + i, "
", 4) || !_strnicmp(string + i, "
", 5))) { // insert newline tmp[j] = '\r'; j++; tmp[j] = '\n'; @@ -877,12 +834,10 @@ char *EliminateHtml(const char *string, int len) } tag = TRUE; } - else if (tag && string[i] == '>') - { + else if (tag && string[i] == '>') { tag = FALSE; } - else if (!tag) - { + else if (!tag) { tmp[j] = string[i]; j++; } @@ -897,29 +852,24 @@ char *EliminateHtml(const char *string, int len) char *ApplyEncoding(const char *string, const char *pszEncoding) { // decode encoding to Utf-8 - if (string && pszEncoding) - { // we do only encodings known to icq5.1 // TODO: check if this is enough - if (!_strnicmp(pszEncoding, "utf-8", 5)) - { // it is utf-8 encoded + if (string && pszEncoding) { // we do only encodings known to icq5.1 // TODO: check if this is enough + if (!_strnicmp(pszEncoding, "utf-8", 5)) { // it is utf-8 encoded return null_strdup(string); } - if (!_strnicmp(pszEncoding, "unicode-2-0", 11)) - { // it is UCS-2 encoded + if (!_strnicmp(pszEncoding, "unicode-2-0", 11)) { // it is UCS-2 encoded int wLen = strlennull((WCHAR*)string) + 1; - WCHAR *szStr = (WCHAR*)_alloca(wLen*2); + WCHAR *szStr = (WCHAR*)_alloca(wLen * 2); BYTE *tmp = (BYTE*)string; - unpackWideString(&tmp, szStr, (WORD)(wLen*2)); + unpackWideString(&tmp, szStr, (WORD)(wLen * 2)); return make_utf8_string(szStr); } - if (!_strnicmp(pszEncoding, "iso-8859-1", 10)) - { // we use "Latin I" instead - it does the job + if (!_strnicmp(pszEncoding, "iso-8859-1", 10)) { // we use "Latin I" instead - it does the job return ansi_to_utf8_codepage(string, 1252); } } - if (string) - { // consider it CP_ACP + if (string) { // consider it CP_ACP return ansi_to_utf8(string); } @@ -938,8 +888,7 @@ void CIcqProto::ResetSettingsOnListReload() HANDLE hContact = FindFirstContact(); - while (hContact) - { + while (hContact) { // All these values will be restored during the serv-list receive setWord(hContact, DBSETTING_SERVLIST_ID, 0); setWord(hContact, DBSETTING_SERVLIST_GROUP, 0); @@ -963,8 +912,7 @@ void CIcqProto::ResetSettingsOnConnect() HANDLE hContact = FindFirstContact(); - while (hContact) - { + while (hContact) { setDword(hContact, "LogonTS", 0); setDword(hContact, "IdleTS", 0); setDword(hContact, "TickTS", 0); @@ -985,13 +933,11 @@ void CIcqProto::ResetSettingsOnLoad() HANDLE hContact = FindFirstContact(); - while (hContact) - { + while (hContact) { setDword(hContact, "LogonTS", 0); setDword(hContact, "IdleTS", 0); setDword(hContact, "TickTS", 0); - if (getContactStatus(hContact) != ID_STATUS_OFFLINE) - { + if (getContactStatus(hContact) != ID_STATUS_OFFLINE) { setWord(hContact, "Status", ID_STATUS_OFFLINE); delSetting(hContact, DBSETTING_XSTATUS_ID); @@ -1006,18 +952,16 @@ void CIcqProto::ResetSettingsOnLoad() int RandRange(int nLow, int nHigh) { - return nLow + (int)((nHigh-nLow+1)*rand()/(RAND_MAX+1.0)); + return nLow + (int)((nHigh - nLow + 1)*rand() / (RAND_MAX + 1.0)); } -BOOL IsStringUIN(const char *pszString) +bool IsStringUIN(const char *pszString) { - int i; int nLen = strlennull(pszString); - if (nLen > 0 && pszString[0] != '0') - { - for (i=0; i 0 && pszString[0] != '0') { + for (int i = 0; i < nLen; i++) if ((pszString[i] < '0') || (pszString[i] > '9')) return FALSE; @@ -1052,7 +996,7 @@ void CIcqProto::SendProtoAck(HANDLE hContact, DWORD dwCookie, int nAckResult, in pArgs->nAckType = nAckType; pArgs->pszMessage = (LPARAM)null_strdup(pszMessage); - ForkThread((MyThreadFunc)&CIcqProto::ProtocolAckThread, pArgs ); + ForkThread((MyThreadFunc)&CIcqProto::ProtocolAckThread, pArgs); } void CIcqProto::SetCurrentStatus(int nStatus) @@ -1066,18 +1010,15 @@ void CIcqProto::SetCurrentStatus(int nStatus) int CIcqProto::IsMetaInfoChanged(HANDLE hContact) { - DBVARIANT infoToken = {DBVT_DELETED}; + DBVARIANT infoToken = { DBVT_DELETED }; int res = 0; - if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &infoToken)) - { // contact does have info from directory, check if it is not outdated + if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &infoToken)) { // contact does have info from directory, check if it is not outdated double dInfoTime = 0; double dInfoSaved = 0; - if ((dInfoTime = getSettingDouble(hContact, DBSETTING_METAINFO_TIME, 0)) > 0) - { - if ((dInfoSaved = getSettingDouble(hContact, DBSETTING_METAINFO_SAVED, 0)) > 0) - { + if ((dInfoTime = getSettingDouble(hContact, DBSETTING_METAINFO_TIME, 0)) > 0) { + if ((dInfoSaved = getSettingDouble(hContact, DBSETTING_METAINFO_SAVED, 0)) > 0) { if (dInfoSaved < dInfoTime) res = 2; // directory info outdated } @@ -1087,15 +1028,12 @@ int CIcqProto::IsMetaInfoChanged(HANDLE hContact) db_free(&infoToken); } - else - { // it cannot be detected if user info was not changed, so use a generic threshold - DBVARIANT infoSaved = {DBVT_DELETED}; + else { // it cannot be detected if user info was not changed, so use a generic threshold + DBVARIANT infoSaved = { DBVT_DELETED }; DWORD dwInfoTime = 0; - if (!getSetting(hContact, DBSETTING_METAINFO_SAVED, &infoSaved)) - { - if (infoSaved.type == DBVT_BLOB && infoSaved.cpbVal == 8) - { + if (!getSetting(hContact, DBSETTING_METAINFO_SAVED, &infoSaved)) { + if (infoSaved.type == DBVT_BLOB && infoSaved.cpbVal == 8) { double dwTime = *(double*)infoSaved.pbVal; dwInfoTime = (dwTime - 25567) * 86400; @@ -1105,8 +1043,7 @@ int CIcqProto::IsMetaInfoChanged(HANDLE hContact) db_free(&infoSaved); - if ((time(NULL) - dwInfoTime) > 14*3600*24) - { + if ((time(NULL) - dwInfoTime) > 14 * 3600 * 24) { res = 3; // threshold exceeded } } @@ -1125,17 +1062,13 @@ void __cdecl CIcqProto::SetStatusNoteThread(void *pDelay) cookieMutex->Enter(); - if (icqOnline() && (setStatusNoteText || setStatusMoodData)) - { // send status note change packets, write status note to database - if (setStatusNoteText) - { // change status note in directory + if (icqOnline() && (setStatusNoteText || setStatusMoodData)) { // send status note change packets, write status note to database + if (setStatusNoteText) { // change status note in directory m_ratesMutex->Enter(); - if (m_rates) - { // rate management + if (m_rates) { // rate management WORD wGroup = m_rates->getGroupFromSNAC(ICQ_EXTENSIONS_FAMILY, ICQ_META_CLI_REQUEST); - while (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_LIMIT)) - { // we are over rate, need to wait before sending + while (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_LIMIT)) { // we are over rate, need to wait before sending int nDelay = m_rates->getDelayToLimitLevel(wGroup, RML_IDLE_10); m_ratesMutex->Leave(); @@ -1161,15 +1094,12 @@ void __cdecl CIcqProto::SetStatusNoteThread(void *pDelay) SAFE_FREE((void**)&pBuffer); } - if (setStatusNoteText || setStatusMoodData) - { // change status note and mood in session data + if (setStatusNoteText || setStatusMoodData) { // change status note and mood in session data m_ratesMutex->Enter(); - if (m_rates) - { // rate management + if (m_rates) { // rate management WORD wGroup = m_rates->getGroupFromSNAC(ICQ_SERVICE_FAMILY, ICQ_CLIENT_SET_STATUS); - while (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_LIMIT)) - { // we are over rate, need to wait before sending + while (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_LIMIT)) { // we are over rate, need to wait before sending int nDelay = m_rates->getDelayToLimitLevel(wGroup, RML_IDLE_10); m_ratesMutex->Leave(); @@ -1189,7 +1119,7 @@ void __cdecl CIcqProto::SetStatusNoteThread(void *pDelay) // check if the session data were not updated already char *szCurrentStatusNote = getSettingStringUtf(NULL, DBSETTING_STATUS_NOTE, NULL); char *szCurrentStatusMood = NULL; - DBVARIANT dbv = {DBVT_DELETED}; + DBVARIANT dbv = { DBVT_DELETED }; if (m_bMoodsEnabled && !getString(DBSETTING_STATUS_MOOD, &dbv)) szCurrentStatusMood = dbv.pszVal; @@ -1199,8 +1129,7 @@ void __cdecl CIcqProto::SetStatusNoteThread(void *pDelay) if (m_bMoodsEnabled && !setStatusMoodData && szCurrentStatusMood) setStatusMoodData = null_strdup(szCurrentStatusMood); - if (strcmpnull(szCurrentStatusNote, setStatusNoteText) || (m_bMoodsEnabled && strcmpnull(szCurrentStatusMood, setStatusMoodData))) - { + if (strcmpnull(szCurrentStatusNote, setStatusNoteText) || (m_bMoodsEnabled && strcmpnull(szCurrentStatusMood, setStatusMoodData))) { db_set_utf(NULL, m_szModuleName, DBSETTING_STATUS_NOTE, setStatusNoteText); if (m_bMoodsEnabled) setString(DBSETTING_STATUS_MOOD, setStatusMoodData); @@ -1216,8 +1145,7 @@ void __cdecl CIcqProto::SetStatusNoteThread(void *pDelay) packWord(&packet, 0x1D); // TLV 1D packWord(&packet, wDataLen); // 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)setStatusNoteText, wStatusNoteLen); @@ -1254,12 +1182,10 @@ int CIcqProto::SetStatusNote(const char *szStatusNote, DWORD dwDelay, int bForce // reuse generic critical section (used for cookies list and object variables locks) icq_lock l(cookieMutex); - if (!setStatusNoteText && (!m_bMoodsEnabled || !setStatusMoodData)) - { // check if the status note was changed and if yes, create thread to change it + if (!setStatusNoteText && (!m_bMoodsEnabled || !setStatusMoodData)) { // check if the status note was changed and if yes, create thread to change it char *szCurrentStatusNote = getSettingStringUtf(NULL, DBSETTING_STATUS_NOTE, NULL); - if (strcmpnull(szCurrentStatusNote, szStatusNote)) - { // status note was changed + if (strcmpnull(szCurrentStatusNote, szStatusNote)) { // status note was changed // create thread to change status note on existing server connection setStatusNoteText = null_strdup(szStatusNote); @@ -1272,8 +1198,7 @@ int CIcqProto::SetStatusNote(const char *szStatusNote, DWORD dwDelay, int bForce } SAFE_FREE(&szCurrentStatusNote); } - else - { // only alter status note object with new status note, keep the thread waiting for execution + else { // only alter status note object with new status note, keep the thread waiting for execution SAFE_FREE(&setStatusNoteText); setStatusNoteText = null_strdup(szStatusNote); @@ -1293,16 +1218,14 @@ int CIcqProto::SetStatusMood(const char *szMoodData, DWORD dwDelay) // reuse generic critical section (used for cookies list and object variables locks) icq_lock l(cookieMutex); - if (!setStatusNoteText && !setStatusMoodData) - { // check if the status mood was changed and if yes, create thread to change it + if (!setStatusNoteText && !setStatusMoodData) { // check if the status mood was changed and if yes, create thread to change it char *szCurrentStatusMood = NULL; - DBVARIANT dbv = {DBVT_DELETED}; + DBVARIANT dbv = { DBVT_DELETED }; if (!getString(DBSETTING_STATUS_MOOD, &dbv)) szCurrentStatusMood = dbv.pszVal; - if (strcmpnull(szCurrentStatusMood, szMoodData)) - { // status mood was changed + if (strcmpnull(szCurrentStatusMood, szMoodData)) { // status mood was changed // create thread to change status mood on existing server connection setStatusMoodData = null_strdup(szMoodData); if (dwDelay) @@ -1314,8 +1237,7 @@ int CIcqProto::SetStatusMood(const char *szMoodData, DWORD dwDelay) } db_free(&dbv); } - else - { // only alter status mood object with new status mood, keep the thread waiting for execution + else { // only alter status mood object with new status mood, keep the thread waiting for execution SAFE_FREE(&setStatusMoodData); setStatusMoodData = null_strdup(szMoodData); @@ -1330,23 +1252,20 @@ void CIcqProto::writeDbInfoSettingTLVStringUtf(HANDLE hContact, const char *szSe { oscar_tlv *pTLV = chain->getTLV(wTlv, 1); - if (pTLV && pTLV->wLen > 0) - { - char *str = (char*)_alloca(pTLV->wLen + 1); + if (pTLV && pTLV->wLen > 0) { + char *str = (char*)_alloca(pTLV->wLen + 1); memcpy(str, pTLV->pData, pTLV->wLen); str[pTLV->wLen] = '\0'; db_set_utf(hContact, m_szModuleName, szSetting, str); } - else - delSetting(hContact, szSetting); + else delSetting(hContact, szSetting); } void CIcqProto::writeDbInfoSettingTLVWord(HANDLE hContact, const char *szSetting, oscar_tlv_chain *chain, WORD wTlv) { int num = chain->getNumber(wTlv, 1); - if (num > 0) setWord(hContact, szSetting, num); else @@ -1368,7 +1287,6 @@ void CIcqProto::writeDbInfoSettingTLVByte(HANDLE hContact, const char *szSetting void CIcqProto::writeDbInfoSettingTLVDouble(HANDLE hContact, const char *szSetting, oscar_tlv_chain *chain, WORD wTlv) { double num = chain->getDouble(wTlv, 1); - if (num > 0) setSettingDouble(hContact, szSetting, num); else @@ -1379,24 +1297,20 @@ void CIcqProto::writeDbInfoSettingTLVDate(HANDLE hContact, const char* szSetting { double time = chain->getDouble(wTlv, 1); - if (time > 0) - { // date is stored as double with unit equal to a day, incrementing since 1/1/1900 0:00 GMT - SYSTEMTIME sTime = {0}; - if (VariantTimeToSystemTime(time + 2, &sTime)) - { + if (time > 0) { // date is stored as double with unit equal to a day, incrementing since 1/1/1900 0:00 GMT + SYSTEMTIME sTime = { 0 }; + if (VariantTimeToSystemTime(time + 2, &sTime)) { setWord(hContact, szSettingYear, sTime.wYear); setByte(hContact, szSettingMonth, (BYTE)sTime.wMonth); setByte(hContact, szSettingDay, (BYTE)sTime.wDay); } - else - { + else { delSetting(hContact, szSettingYear); delSetting(hContact, szSettingMonth); delSetting(hContact, szSettingDay); } } - else - { + else { delSetting(hContact, szSettingYear); delSetting(hContact, szSettingMonth); delSetting(hContact, szSettingDay); @@ -1417,38 +1331,30 @@ void CIcqProto::writeDbInfoSettingTLVBlob(HANDLE hContact, const char *szSetting BOOL CIcqProto::writeDbInfoSettingString(HANDLE hContact, const char* szSetting, char** buf, WORD* pwLength) { - WORD wLen; - if (*pwLength < 2) return FALSE; + WORD wLen; unpackLEWord((LPBYTE*)buf, &wLen); *pwLength -= 2; if (*pwLength < wLen) return FALSE; - if ((wLen > 0) && (**buf) && ((*buf)[wLen-1]==0)) // Make sure we have a proper string - { + if ((wLen > 0) && (**buf) && ((*buf)[wLen - 1] == 0)) { // Make sure we have a proper string WORD wCp = getWord(hContact, "InfoCodePage", getWord(hContact, "InfoCP", CP_ACP)); - - if (wCp != CP_ACP) - { + if (wCp != CP_ACP) { char *szUtf = ansi_to_utf8_codepage(*buf, wCp); - if (szUtf) - { + if (szUtf) { db_set_utf(hContact, m_szModuleName, szSetting, szUtf); SAFE_FREE((void**)&szUtf); } - else - setString(hContact, szSetting, *buf); + else setString(hContact, szSetting, *buf); } - else - setString(hContact, szSetting, *buf); + else setString(hContact, szSetting, *buf); } - else - delSetting(hContact, szSetting); + else delSetting(hContact, szSetting); *buf += wLen; *pwLength -= wLen; @@ -1458,12 +1364,10 @@ BOOL CIcqProto::writeDbInfoSettingString(HANDLE hContact, const char* szSetting, BOOL CIcqProto::writeDbInfoSettingWord(HANDLE hContact, const char *szSetting, char **buf, WORD* pwLength) { - WORD wVal; - - if (*pwLength < 2) return FALSE; + WORD wVal; unpackLEWord((LPBYTE*)buf, &wVal); *pwLength -= 2; @@ -1477,17 +1381,15 @@ BOOL CIcqProto::writeDbInfoSettingWord(HANDLE hContact, const char *szSetting, c BOOL CIcqProto::writeDbInfoSettingWordWithTable(HANDLE hContact, const char *szSetting, const FieldNamesItem *table, char **buf, WORD* pwLength) { - WORD wVal; - char sbuf[MAX_PATH]; - char *text; - if (*pwLength < 2) return FALSE; + WORD wVal; unpackLEWord((LPBYTE*)buf, &wVal); *pwLength -= 2; - text = LookupFieldNameUtf(table, wVal, sbuf, MAX_PATH); + char sbuf[MAX_PATH]; + char *text = LookupFieldNameUtf(table, wVal, sbuf, MAX_PATH); if (text) db_set_utf(hContact, m_szModuleName, szSetting, text); else @@ -1498,11 +1400,10 @@ BOOL CIcqProto::writeDbInfoSettingWordWithTable(HANDLE hContact, const char *szS BOOL CIcqProto::writeDbInfoSettingByte(HANDLE hContact, const char *pszSetting, char **buf, WORD* pwLength) { - BYTE byVal; - if (*pwLength < 1) return FALSE; + BYTE byVal; unpackByte((LPBYTE*)buf, &byVal); *pwLength -= 1; @@ -1516,17 +1417,15 @@ BOOL CIcqProto::writeDbInfoSettingByte(HANDLE hContact, const char *pszSetting, BOOL CIcqProto::writeDbInfoSettingByteWithTable(HANDLE hContact, const char *szSetting, const FieldNamesItem *table, char **buf, WORD* pwLength) { - BYTE byVal; - char sbuf[MAX_PATH]; - char *text; - if (*pwLength < 1) return FALSE; + BYTE byVal; unpackByte((LPBYTE*)buf, &byVal); *pwLength -= 1; - text = LookupFieldNameUtf(table, byVal, sbuf, MAX_PATH); + char sbuf[MAX_PATH]; + char *text = LookupFieldNameUtf(table, byVal, sbuf, MAX_PATH); if (text) db_set_utf(hContact, m_szModuleName, szSetting, text); else @@ -1539,45 +1438,41 @@ char* time2text(time_t time) { tm *local = localtime(&time); - if (local) - { + if (local) { char *str = asctime(local); str[24] = '\0'; // remove new line return str; } - else - return ""; + + return ""; } -BOOL CIcqProto::validateStatusMessageRequest(HANDLE hContact, WORD byMessageType) +bool CIcqProto::validateStatusMessageRequest(HANDLE hContact, WORD byMessageType) { // Privacy control - if (getByte("StatusMsgReplyCList", 0)) - { + if (getByte("StatusMsgReplyCList", 0)) { // Don't send statusmessage to unknown contacts if (hContact == INVALID_HANDLE_VALUE) - return FALSE; + return false; // Don't send statusmessage to temporary contacts or hidden contacts if (db_get_b(hContact, "CList", "NotOnList", 0) || db_get_b(hContact, "CList", "Hidden", 0)) - return FALSE; + return false; // Don't send statusmessage to invisible contacts - if (getByte("StatusMsgReplyVisible", 0)) - { + if (getByte("StatusMsgReplyVisible", 0)) { WORD wStatus = getContactStatus(hContact); if (wStatus == ID_STATUS_OFFLINE) - return FALSE; + return false; } } // Dont send messages to people you are hiding from if (hContact != INVALID_HANDLE_VALUE && - getWord(hContact, "ApparentMode", 0) == ID_STATUS_OFFLINE) - { - return FALSE; + getWord(hContact, "ApparentMode", 0) == ID_STATUS_OFFLINE) { + return false; } // Dont respond to request for other statuses than your current one @@ -1586,29 +1481,25 @@ BOOL CIcqProto::validateStatusMessageRequest(HANDLE hContact, WORD byMessageType (byMessageType == MTYPE_AUTOBUSY && m_iStatus != ID_STATUS_OCCUPIED) || (byMessageType == MTYPE_AUTONA && m_iStatus != ID_STATUS_NA) || (byMessageType == MTYPE_AUTODND && m_iStatus != ID_STATUS_DND) || - (byMessageType == MTYPE_AUTOFFC && m_iStatus != ID_STATUS_FREECHAT)) - { - return FALSE; + (byMessageType == MTYPE_AUTOFFC && m_iStatus != ID_STATUS_FREECHAT)) { + return false; } - if (hContact != INVALID_HANDLE_VALUE && m_iStatus==ID_STATUS_INVISIBLE && - getWord(hContact, "ApparentMode", 0) != ID_STATUS_ONLINE) - { - if (!getByte(hContact, "TemporaryVisible", 0)) - { // Allow request to temporary visible contacts - return FALSE; + if (hContact != INVALID_HANDLE_VALUE && m_iStatus == ID_STATUS_INVISIBLE && + getWord(hContact, "ApparentMode", 0) != ID_STATUS_ONLINE) { + if (!getByte(hContact, "TemporaryVisible", 0)) { // Allow request to temporary visible contacts + return false; } } // All OK! - return TRUE; + return true; } void __fastcall SAFE_DELETE(MZeroedObject **p) { - if (*p) - { + if (*p) { delete *p; *p = NULL; } @@ -1617,8 +1508,7 @@ void __fastcall SAFE_DELETE(MZeroedObject **p) void __fastcall SAFE_DELETE(lockable_struct **p) { - if (*p) - { + if (*p) { (*p)->_Release(); *p = NULL; } @@ -1627,8 +1517,7 @@ void __fastcall SAFE_DELETE(lockable_struct **p) void __fastcall SAFE_FREE(void** p) { - if (*p) - { + if (*p) { free(*p); *p = NULL; } @@ -1639,10 +1528,8 @@ void* __fastcall SAFE_MALLOC(size_t size) { void* p = NULL; - if (size) - { + if (size) { p = malloc(size); - if (p) ZeroMemory(p, size); } @@ -1653,11 +1540,9 @@ void* __fastcall SAFE_MALLOC(size_t size) void* __fastcall SAFE_REALLOC(void* p, size_t size) { if (p) - { return realloc(p, size); - } - else - return SAFE_MALLOC(size); + + return SAFE_MALLOC(size); } @@ -1667,7 +1552,8 @@ DWORD ICQWaitForSingleObject(HANDLE hObject, DWORD dwMilliseconds, int bWaitAlwa do { // will get WAIT_IO_COMPLETION for QueueUserAPC(), ignore it unless terminating dwResult = WaitForSingleObjectEx(hObject, dwMilliseconds, TRUE); - } while (dwResult == WAIT_IO_COMPLETION && (bWaitAlways || !Miranda_Terminated())); + } + while (dwResult == WAIT_IO_COMPLETION && (bWaitAlways || !Miranda_Terminated())); return dwResult; } @@ -1675,7 +1561,7 @@ DWORD ICQWaitForSingleObject(HANDLE hObject, DWORD dwMilliseconds, int bWaitAlwa HANDLE NetLib_OpenConnection(HANDLE hUser, const char* szIdent, NETLIBOPENCONNECTION* nloc) { - Netlib_Logf(hUser, "%sConnecting to %s:%u", szIdent?szIdent:"", nloc->szHost, nloc->wPort); + Netlib_Logf(hUser, "%sConnecting to %s:%u", szIdent ? szIdent : "", nloc->szHost, nloc->wPort); nloc->cbSize = sizeof(NETLIBOPENCONNECTION); nloc->flags |= NLOCF_V2; @@ -1686,9 +1572,8 @@ HANDLE NetLib_OpenConnection(HANDLE hUser, const char* szIdent, NETLIBOPENCONNEC HANDLE CIcqProto::NetLib_BindPort(NETLIBNEWCONNECTIONPROC_V2 pFunc, void* lParam, WORD* pwPort, DWORD* pdwIntIP) { - NETLIBBIND nlb = {0}; - - nlb.cbSize = sizeof(NETLIBBIND); + NETLIBBIND nlb = { 0 }; + nlb.cbSize = sizeof(NETLIBBIND); nlb.pfnNewConnectionV2 = pFunc; nlb.pExtra = lParam; SetLastError(ERROR_INVALID_PARAMETER); // this must be here - NetLib does not set any error :(( @@ -1704,8 +1589,7 @@ HANDLE CIcqProto::NetLib_BindPort(NETLIBNEWCONNECTIONPROC_V2 pFunc, void* lParam void NetLib_CloseConnection(HANDLE *hConnection, int bServerConn) { - if (*hConnection) - { + if (*hConnection) { NetLib_SafeCloseHandle(hConnection); if (bServerConn) @@ -1716,49 +1600,41 @@ void NetLib_CloseConnection(HANDLE *hConnection, int bServerConn) void NetLib_SafeCloseHandle(HANDLE *hConnection) { - if (*hConnection) - { + if (*hConnection) { Netlib_CloseHandle(*hConnection); *hConnection = NULL; } } -int CIcqProto::NetLog_Direct(const char *fmt,...) +int CIcqProto::NetLog_Direct(const char *fmt, ...) { - va_list va; char szText[1024]; - va_start(va,fmt); - mir_vsnprintf(szText,sizeof(szText),fmt,va); + va_list va; + va_start(va, fmt); + mir_vsnprintf(szText, sizeof(szText), fmt, va); va_end(va); - return CallService(MS_NETLIB_LOG,(WPARAM)m_hDirectNetlibUser,(LPARAM)szText); + return CallService(MS_NETLIB_LOG, (WPARAM)m_hDirectNetlibUser, (LPARAM)szText); } -int CIcqProto::NetLog_Uni(BOOL bDC, const char *fmt,...) +int CIcqProto::NetLog_Uni(BOOL bDC, const char *fmt, ...) { - va_list va; char szText[1024]; - HANDLE hNetlib; - - va_start(va,fmt); - mir_vsnprintf(szText,sizeof(szText),fmt,va); + va_list va; + va_start(va, fmt); + mir_vsnprintf(szText, sizeof(szText), fmt, va); va_end(va); - if (bDC) - hNetlib = m_hDirectNetlibUser; - else - hNetlib = m_hNetlibUser; - - return CallService(MS_NETLIB_LOG,(WPARAM)hNetlib,(LPARAM)szText); + HANDLE hNetlib = (bDC) ? m_hDirectNetlibUser : m_hNetlibUser; + return CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)szText); } char* __fastcall ICQTranslateUtf(const char *src) { // this takes UTF-8 strings only!!! char *szRes = NULL; - if (!strlennull(src)) - { // for the case of empty strings + if (!strlennull(src)) { // for the case of empty strings return null_strdup(src); } @@ -1774,8 +1650,7 @@ char* __fastcall ICQTranslateUtf(const char *src) char* __fastcall ICQTranslateUtfStatic(const char *src, char *buf, size_t bufsize) { // this takes UTF-8 strings only!!! - if (strlennull(src)) - { // we can use unicode translate (0.5+) + if (strlennull(src)) { // we can use unicode translate (0.5+) WCHAR *usrc = make_unicode_string(src); make_utf8_string_static(TranslateW(usrc), buf, bufsize); @@ -1803,8 +1678,7 @@ char* CIcqProto::GetUserPassword(BOOL bAlways) if (m_szPassword[0] != '\0' && (m_bRememberPwd || bAlways)) return m_szPassword; - if (GetUserStoredPassword(m_szPassword, sizeof(m_szPassword))) - { + if (GetUserStoredPassword(m_szPassword, sizeof(m_szPassword))) { m_bRememberPwd = TRUE; return m_szPassword; @@ -1823,8 +1697,7 @@ WORD CIcqProto::GetMyStatusFlags() wFlags |= STATUS_WEBAWARE; // DC setting bit flag - switch (getByte("DCType", 0)) - { + switch (getByte("DCType", 0)) { case 0: break; @@ -1908,18 +1781,15 @@ int MakeDirUtf(const char *dir) int size = strlennull(dir) + 2; TCHAR *szDir = (TCHAR*)_alloca(size * sizeof(TCHAR)); - if (utf8_to_tchar_static(dir, szDir, size)) - { // _tmkdir can created only one dir at once + if (utf8_to_tchar_static(dir, szDir, size)) { // _tmkdir can created only one dir at once wRes = _tmkdir(szDir); // check if dir not already existed - return success if yes if (wRes == -1 && errno == 17 /* EEXIST */) wRes = 0; - else if (wRes && errno == 2 /* ENOENT */) - { // failed, try one directory less first + else if (wRes && errno == 2 /* ENOENT */) { // failed, try one directory less first char *szLast = (char*)strrchr(dir, '\\'); if (!szLast) szLast = (char*)strrchr(dir, '/'); - if (szLast) - { + if (szLast) { char cOld = *szLast; *szLast = '\0'; @@ -1949,9 +1819,8 @@ int OpenFileUtf(const char *filename, int oflag, int pmode) WCHAR *GetWindowTextUcs(HWND hWnd) { - WCHAR *utext; int nLen = GetWindowTextLengthW(hWnd); - utext = (WCHAR*)SAFE_MALLOC((nLen+2)*sizeof(WCHAR)); + WCHAR *utext = (WCHAR*)SAFE_MALLOC((nLen + 2)*sizeof(WCHAR)); GetWindowTextW(hWnd, utext, nLen + 1); return utext; } @@ -2047,7 +1916,7 @@ char* CIcqProto::ConvertMsgToUserSpecificAnsi(HANDLE hContact, const char* szMsg // just broadcast generic send error with dummy cookie and return that cookie DWORD CIcqProto::ReportGenericSendError(HANDLE hContact, int nType, const char* szErrorMsg) -{ +{ DWORD dwCookie = GenerateCookie(0); SendProtoAck(hContact, dwCookie, ACKRESULT_FAILED, nType, Translate(szErrorMsg)); return dwCookie; diff --git a/protocols/IcqOscarJ/src/utilities.h b/protocols/IcqOscarJ/src/utilities.h index 336c0e8a8a..25387d7ef3 100644 --- a/protocols/IcqOscarJ/src/utilities.h +++ b/protocols/IcqOscarJ/src/utilities.h @@ -91,12 +91,10 @@ char *ApplyEncoding(const char *string, const char *pszEncoding); int RandRange(int nLow, int nHigh); -BOOL IsStringUIN(const char *pszString); +bool IsStringUIN(const char *pszString); char* time2text(time_t time); -BOOL validateStatusMessageRequest(HANDLE hContact, WORD byMessageType); - void __fastcall SAFE_FREE(void** p); void* __fastcall SAFE_MALLOC(size_t size); void* __fastcall SAFE_REALLOC(void* p, size_t size); diff --git a/protocols/IcqOscarJ/src/version.h b/protocols/IcqOscarJ/src/version.h index cb045b18bb..f49017ee7f 100644 --- a/protocols/IcqOscarJ/src/version.h +++ b/protocols/IcqOscarJ/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 -#define __RELEASE_NUM 0 -#define __BUILD_NUM 1 +#define __RELEASE_NUM 1 +#define __BUILD_NUM 0 #define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM #define __TOSTRING(x) #x @@ -12,4 +12,4 @@ #define __AUTHOR "Joe Kucera, Bio, Martin \xd6" "berg, Richard Hughes, Jon Keating, etc." #define __AUTHOREMAIL "jokusoftware@miranda-im.org" #define __AUTHORWEB "http://miranda-ng.org/p/ICQ/" -#define __COPYRIGHT "(C) 2000-2010 M.\xd6" "berg, R.Hughes, J.Keating, Bio, Angeli-Ka, G.Hazan, J.Kucera" +#define __COPYRIGHT "(ñ) 2000-2010 M.\xd6" "berg, R.Hughes, J.Keating, Bio, Angeli-Ka, G.Hazan, J.Kucera" -- cgit v1.2.3