From 1ea84dc56d95ceaf85c036127c5045eba0ad50ee Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 13 Aug 2015 17:08:34 +0000 Subject: massive name conflict resolution git-svn-id: http://svn.miranda-ng.org/main/trunk@14941 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/AimOscar/src/aim.cpp | 7 +- protocols/AimOscar/src/avatars.cpp | 89 +- protocols/AimOscar/src/away.cpp | 46 +- protocols/AimOscar/src/chat.cpp | 227 ++-- protocols/AimOscar/src/client.cpp | 1235 +++++++++++---------- protocols/AimOscar/src/connection.cpp | 427 ++++---- protocols/AimOscar/src/conv.cpp | 979 ++++++++--------- protocols/AimOscar/src/defines.h | 6 +- protocols/AimOscar/src/direct_connect.cpp | 37 +- protocols/AimOscar/src/error.cpp | 28 +- protocols/AimOscar/src/file.cpp | 226 ++-- protocols/AimOscar/src/flap.cpp | 36 +- protocols/AimOscar/src/links.cpp | 63 +- protocols/AimOscar/src/proto.cpp | 277 +++-- protocols/AimOscar/src/proto.h | 105 +- protocols/AimOscar/src/proxy.cpp | 10 +- protocols/AimOscar/src/server.cpp | 1665 ++++++++++++----------------- protocols/AimOscar/src/services.cpp | 227 ++-- protocols/AimOscar/src/snac.h | 14 +- protocols/AimOscar/src/theme.cpp | 28 +- protocols/AimOscar/src/thread.cpp | 42 +- protocols/AimOscar/src/ui.cpp | 109 +- protocols/AimOscar/src/utility.cpp | 308 +++--- 23 files changed, 2749 insertions(+), 3442 deletions(-) (limited to 'protocols') diff --git a/protocols/AimOscar/src/aim.cpp b/protocols/AimOscar/src/aim.cpp index 2355754267..6d595ae8e9 100644 --- a/protocols/AimOscar/src/aim.cpp +++ b/protocols/AimOscar/src/aim.cpp @@ -16,6 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" char AIM_CAP_MIRANDA[16] = "MirandaA"; @@ -37,7 +38,7 @@ OBJLIST g_Instances(1, sttCompareProtocols); ///////////////////////////////////////////////////////////////////////////////////////// // Dll entry point -BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD /*fdwReason*/,LPVOID /*lpvReserved*/) +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD /*fdwReason*/, LPVOID /*lpvReserved*/) { hInstance = hinstDLL; return TRUE; @@ -71,7 +72,7 @@ extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD m ///////////////////////////////////////////////////////////////////////////////////////// // Interface information -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_PROTOCOL, MIID_LAST}; +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; //////////////////////////////////////////////////////////////////////////////////////// // OnModulesLoaded - finalizes plugin's configuration on load @@ -111,7 +112,7 @@ extern "C" int __declspec(dllexport) Load(void) pd.type = PROTOTYPE_PROTOCOL; pd.fnInit = protoInit; pd.fnUninit = protoUninit; - Proto_RegisterModule( & pd); + Proto_RegisterModule(&pd); InitIcons(); InitExtraIcons(); diff --git a/protocols/AimOscar/src/avatars.cpp b/protocols/AimOscar/src/avatars.cpp index 298a11f899..0b21052483 100644 --- a/protocols/AimOscar/src/avatars.cpp +++ b/protocols/AimOscar/src/avatars.cpp @@ -16,6 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" void __cdecl CAimProto::avatar_request_thread(void* param) @@ -25,8 +26,7 @@ void __cdecl CAimProto::avatar_request_thread(void* param) char *sn = getStringA(hContact, AIM_KEY_SN); debugLogA("Starting avatar request thread for %s)", sn); - if (wait_conn(hAvatarConn, hAvatarEvent, 0x10)) - { + if (wait_conn(m_hAvatarConn, m_hAvatarEvent, 0x10)) { char *hash_str = getStringA(hContact, AIM_KEY_AH); if (!hash_str) { mir_free(sn); @@ -35,10 +35,10 @@ void __cdecl CAimProto::avatar_request_thread(void* param) char type = getByte(hContact, AIM_KEY_AHT, 1); size_t len = (mir_strlen(hash_str) + 1) / 2; - char* hash = (char*)alloca(len); + char *hash = (char*)alloca(len); string_to_bytes(hash_str, hash); debugLogA("Requesting an Avatar: %s (Hash: %s)", sn, hash_str); - aim_request_avatar(hAvatarConn, avatar_seqno, sn, type, hash, (unsigned short)len); + aim_request_avatar(m_hAvatarConn, m_avatar_seqno, sn, type, hash, (unsigned short)len); mir_free(hash_str); } @@ -50,42 +50,35 @@ void __cdecl CAimProto::avatar_upload_thread(void* param) { avatar_up_req* req = (avatar_up_req*)param; - if (wait_conn(hAvatarConn, hAvatarEvent, 0x10)) - { - if (req->size2) - { - aim_upload_avatar(hAvatarConn, avatar_seqno, 1, req->data2, req->size2); - aim_upload_avatar(hAvatarConn, avatar_seqno, 12, req->data1, req->size1); + if (wait_conn(m_hAvatarConn, m_hAvatarEvent, 0x10)) { + if (req->size2) { + aim_upload_avatar(m_hAvatarConn, m_avatar_seqno, 1, req->data2, req->size2); + aim_upload_avatar(m_hAvatarConn, m_avatar_seqno, 12, req->data1, req->size1); } - else - aim_upload_avatar(hAvatarConn, avatar_seqno, 1, req->data1, req->size1); + else aim_upload_avatar(m_hAvatarConn, m_avatar_seqno, 1, req->data1, req->size1); } delete req; } void CAimProto::avatar_request_handler(MCONTACT hContact, char* hash, unsigned char type)//checks to see if the avatar needs requested { - if (hContact == NULL) - { - hash = hash_lg ? hash_lg : hash_sm; - type = hash_lg ? 12 : 1; + if (hContact == NULL) { + hash = m_hash_lg ? m_hash_lg : m_hash_sm; + type = m_hash_lg ? 12 : 1; } - char* saved_hash = getStringA(hContact, AIM_KEY_AH); + char *saved_hash = getStringA(hContact, AIM_KEY_AH); if (hash && _stricmp(hash, "0201d20472") && _stricmp(hash, "2b00003341")) //gaim default icon fix- we don't want their blank icon displaying. { - if (mir_strcmp(saved_hash, hash)) - { + if (mir_strcmp(saved_hash, hash)) { setByte(hContact, AIM_KEY_AHT, type); setString(hContact, AIM_KEY_AH, hash); ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); } } - else - { - if (saved_hash) - { + else { + if (saved_hash) { delSetting(hContact, AIM_KEY_AHT); delSetting(hContact, AIM_KEY_AH); @@ -106,7 +99,7 @@ void CAimProto::avatar_retrieval_handler(const char* sn, const char* /*hash*/, c ai.format = ProtoGetBufferFormat(data, &type); get_avatar_filename(ai.hContact, ai.filename, _countof(ai.filename), type); - int fileId = _topen(ai.filename, _O_CREAT | _O_TRUNC | _O_WRONLY | O_BINARY, _S_IREAD | _S_IWRITE); + int fileId = _topen(ai.filename, _O_CREAT | _O_TRUNC | _O_WRONLY | O_BINARY, _S_IREAD | _S_IWRITE); if (fileId >= 0) { _write(fileId, data, data_len); _close(fileId); @@ -125,7 +118,7 @@ void CAimProto::avatar_retrieval_handler(const char* sn, const char* /*hash*/, c int CAimProto::get_avatar_filename(MCONTACT hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext) { - int tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST( _T("%miranda_avatarcache%")), m_szModuleName); + int tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName); if (ext && _taccess(pszDest, 0)) CreateDirectoryTreeT(pszDest); @@ -138,28 +131,24 @@ int CAimProto::get_avatar_filename(MCONTACT hContact, TCHAR* pszDest, size_t cbL db_free(&dbv); bool found = false; - if (ext == NULL) - { + if (ext == NULL) { mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T(".*")); _tfinddata_t c_file; long hFile = _tfindfirst(pszDest, &c_file); - if (hFile > -1L) - { + if (hFile > -1L) { do { - if (_tcsrchr(c_file.name, '.')) - { + if (_tcsrchr(c_file.name, '.')) { mir_sntprintf(pszDest + tPathLen2, cbLen - tPathLen2, _T("\\%s"), c_file.name); found = true; } } while (_tfindnext(hFile, &c_file) == 0); - _findclose( hFile ); + _findclose(hFile); } if (!found) pszDest[0] = 0; } - else - { + else { mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext); found = _taccess(pszDest, 0) == 0; } @@ -173,8 +162,7 @@ bool get_avatar_hash(const TCHAR* file, char* hash, char** data, unsigned short if (fileId == -1) return false; long lAvatar = _filelength(fileId); - if (lAvatar <= 0) - { + if (lAvatar <= 0) { _close(fileId); return false; } @@ -183,8 +171,7 @@ bool get_avatar_hash(const TCHAR* file, char* hash, char** data, unsigned short int res = _read(fileId, pResult, lAvatar); _close(fileId); - if (res <= 0) - { + if (res <= 0) { mir_free(pResult); return false; } @@ -194,8 +181,7 @@ bool get_avatar_hash(const TCHAR* file, char* hash, char** data, unsigned short mir_md5_append(&state, (unsigned char*)pResult, lAvatar); mir_md5_finish(&state, (unsigned char*)hash); - if (data) - { + if (data) { *data = pResult; size = (unsigned short)lAvatar; } @@ -208,29 +194,28 @@ bool get_avatar_hash(const TCHAR* file, char* hash, char** data, unsigned short void rescale_image(char *data, unsigned short size, char *&data1, unsigned short &size1) { FI_INTERFACE *fei = NULL; - CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM) &fei); + CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fei); if (fei == NULL) return; - FIMEMORY *hmem = fei->FI_OpenMemory((BYTE *)data, size); - FREE_IMAGE_FORMAT fif = fei->FI_GetFileTypeFromMemory(hmem, 0); - FIBITMAP *dib = fei->FI_LoadFromMemory(fif, hmem, 0); - fei->FI_CloseMemory(hmem); + FIMEMORY *hmem = fei->FI_OpenMemory((BYTE *)data, size); + FREE_IMAGE_FORMAT fif = fei->FI_GetFileTypeFromMemory(hmem, 0); + FIBITMAP *dib = fei->FI_LoadFromMemory(fif, hmem, 0); + fei->FI_CloseMemory(hmem); - if (fei->FI_GetWidth(dib) > 64) - { + if (fei->FI_GetWidth(dib) > 64) { FIBITMAP *dib1 = fei->FI_Rescale(dib, 64, 64, FILTER_BSPLINE); - FIMEMORY *hmem = fei->FI_OpenMemory(NULL, 0); - fei->FI_SaveToMemory(fif, dib1, hmem, 0); + FIMEMORY *hmem2 = fei->FI_OpenMemory(NULL, 0); + fei->FI_SaveToMemory(fif, dib1, hmem2, 0); BYTE *data2; DWORD size2; - fei->FI_AcquireMemory(hmem, &data2, &size2); + fei->FI_AcquireMemory(hmem2, &data2, &size2); data1 = (char*)mir_alloc(size2); memcpy(data1, data2, size2); size1 = size2; - fei->FI_CloseMemory(hmem); + fei->FI_CloseMemory(hmem2); fei->FI_Unload(dib1); } fei->FI_Unload(dib); -} \ No newline at end of file +} diff --git a/protocols/AimOscar/src/away.cpp b/protocols/AimOscar/src/away.cpp index ec8fdbb4fa..057e55a1b3 100644 --- a/protocols/AimOscar/src/away.cpp +++ b/protocols/AimOscar/src/away.cpp @@ -16,25 +16,27 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" +static const int modes[] = +{ + ID_STATUS_ONLINE, + ID_STATUS_AWAY, + ID_STATUS_DND, + ID_STATUS_NA, + ID_STATUS_OCCUPIED, + ID_STATUS_FREECHAT, + ID_STATUS_INVISIBLE, + ID_STATUS_ONTHEPHONE, + ID_STATUS_OUTTOLUNCH, +}; + char** CAimProto::get_status_msg_loc(int status) { - static const int modes[] = - { - ID_STATUS_ONLINE, - ID_STATUS_AWAY, - ID_STATUS_DND, - ID_STATUS_NA, - ID_STATUS_OCCUPIED, - ID_STATUS_FREECHAT, - ID_STATUS_INVISIBLE, - ID_STATUS_ONTHEPHONE, - ID_STATUS_OUTTOLUNCH, - }; - - for (int i=0; i<9; i++) - if (modes[i] == status) return &modeMsgs[i]; + for (int i = 0; i < _countof(modes); i++) + if (modes[i] == status) + return &m_modeMsgs[i]; return NULL; } @@ -42,10 +44,9 @@ char** CAimProto::get_status_msg_loc(int status) int CAimProto::aim_set_away(HANDLE hServerConn, unsigned short &seqno, const char *amsg, bool set)//user info { unsigned short offset = 0; - char* html_msg = NULL; + char *html_msg = NULL; size_t msg_size = 0; - if (set) - { + if (set) { if (!amsg) return -1; setDword(AIM_KEY_LA, (DWORD)time(NULL)); html_msg = html_encode(amsg && amsg[0] ? amsg : DEFAULT_AWAY_MSG); @@ -56,10 +57,10 @@ int CAimProto::aim_set_away(HANDLE hServerConn, unsigned short &seqno, const cha const char *charset = str.isUnicode() ? AIM_MSG_TYPE_UNICODE : AIM_MSG_TYPE; const unsigned short charset_len = (unsigned short)mir_strlen(charset); - const char* msg = str.getBuf(); + const char *msg = str.getBuf(); const unsigned short msg_len = str.getSize(); - char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 3 + charset_len + msg_len + 1); + char *buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 3 + charset_len + msg_len + 1); aim_writesnac(0x02, 0x04, offset, buf); aim_writetlv(0x03, charset_len, charset, offset, buf); @@ -84,9 +85,9 @@ int CAimProto::aim_set_statusmsg(HANDLE hServerConn, unsigned short &seqno, cons size_t msg_size = mir_strlen(msg); unsigned short msgoffset = 0; - char* msgbuf = (char*)alloca(10 + msg_size); + char *msgbuf = (char*)alloca(10 + msg_size); if (msg_size) { - char* msgb = (char*)alloca(4 + msg_size); + char *msgb = (char*)alloca(4 + msg_size); msgb[0] = (unsigned char)(msg_size >> 8); msgb[1] = (unsigned char)(msg_size & 0xff); memcpy(&msgb[2], msg, msg_size); @@ -117,4 +118,3 @@ int CAimProto::aim_query_away_message(HANDLE hServerConn, unsigned short &seqno, int res = aim_sendflap(hServerConn, 0x02, offset, buf, seqno) == 0; return res; } - diff --git a/protocols/AimOscar/src/chat.cpp b/protocols/AimOscar/src/chat.cpp index 9d43570ab6..3bf8adab9f 100644 --- a/protocols/AimOscar/src/chat.cpp +++ b/protocols/AimOscar/src/chat.cpp @@ -15,9 +15,10 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" -static const COLORREF crCols[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; +static const COLORREF crCols[16] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }; void CAimProto::chat_register(void) { @@ -30,12 +31,12 @@ void CAimProto::chat_register(void) CallServiceSync(MS_GC_REGISTER, 0, (LPARAM)&gcr); HookProtoEvent(ME_GC_EVENT, &CAimProto::OnGCEvent); - HookProtoEvent(ME_GC_BUILDMENU, &CAimProto::OnGCMenuHook ); + HookProtoEvent(ME_GC_BUILDMENU, &CAimProto::OnGCMenuHook); } void CAimProto::chat_start(const char* id, unsigned short exchange) { - TCHAR* idt = mir_a2t(id); + TCHAR *idt = mir_a2t(id); GCSESSION gcw = { sizeof(gcw) }; gcw.iType = GCW_CHATROOM; @@ -55,8 +56,8 @@ void CAimProto::chat_start(const char* id, unsigned short exchange) gcd.iType = GC_EVENT_CONTROL; CallServiceSync(MS_GC_EVENT, SESSION_INITDONE, (LPARAM)&gce); - CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce); - CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce); + CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce); + CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce); setWord(find_chat_contact(id), "Exchange", exchange); @@ -65,11 +66,11 @@ void CAimProto::chat_start(const char* id, unsigned short exchange) void CAimProto::chat_event(const char* id, const char* sn, int evt, const TCHAR* msg) { - TCHAR* idt = mir_a2t(id); - TCHAR* snt = mir_a2t(sn); + TCHAR *idt = mir_a2t(id); + TCHAR *snt = mir_a2t(sn); MCONTACT hContact = contact_from_sn(sn); - TCHAR* nick = hContact ? (TCHAR*)pcli->pfnGetContactDisplayName( + TCHAR *nick = hContact ? (TCHAR*)pcli->pfnGetContactDisplayName( WPARAM(hContact), 0) : snt; GCDEST gcd = { m_szModuleName, idt, evt }; @@ -78,7 +79,7 @@ void CAimProto::chat_event(const char* id, const char* sn, int evt, const TCHAR* gce.pDest = &gcd; gce.ptszNick = nick; gce.ptszUID = snt; - gce.bIsMe = _stricmp(sn, username) == 0; + gce.bIsMe = _stricmp(sn, m_username) == 0; gce.ptszStatus = gce.bIsMe ? TranslateT("Me") : TranslateT("Others"); gce.ptszText = msg; gce.time = time(NULL); @@ -90,7 +91,7 @@ void CAimProto::chat_event(const char* id, const char* sn, int evt, const TCHAR* void CAimProto::chat_leave(const char* id) { - TCHAR* idt = mir_a2t(id); + TCHAR *idt = mir_a2t(id); GCDEST gcd = { m_szModuleName, idt, GC_EVENT_CONTROL }; GCEVENT gce = { sizeof(gce), &gcd }; @@ -102,97 +103,93 @@ void CAimProto::chat_leave(const char* id) } -int CAimProto::OnGCEvent(WPARAM, LPARAM lParam) +int CAimProto::OnGCEvent(WPARAM, LPARAM lParam) { - GCHOOK *gch = (GCHOOK*) lParam; + GCHOOK *gch = (GCHOOK*)lParam; if (!gch) return 1; if (mir_strcmp(gch->pDest->pszModule, m_szModuleName)) return 0; - char* id = mir_t2a(gch->pDest->ptszID); + char *id = mir_t2a(gch->pDest->ptszID); chat_list_item* item = find_chat_by_id(id); if (item == NULL) return 0; - switch (gch->pDest->iType) - { - case GC_SESSION_TERMINATE: - aim_sendflap(item->hconn,0x04,0,NULL,item->seqno); - Netlib_Shutdown(item->hconn); - break; + switch (gch->pDest->iType) { + case GC_SESSION_TERMINATE: + aim_sendflap(item->hconn, 0x04, 0, NULL, item->seqno); + Netlib_Shutdown(item->hconn); + break; - case GC_USER_MESSAGE: - if (gch->ptszText && mir_tstrlen(gch->ptszText)) - aim_chat_send_message(item->hconn, item->seqno, T2Utf(gch->ptszText)); - break; + case GC_USER_MESSAGE: + if (gch->ptszText && mir_tstrlen(gch->ptszText)) + aim_chat_send_message(item->hconn, item->seqno, T2Utf(gch->ptszText)); + break; + + case GC_USER_CHANMGR: + DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, invite_to_chat_dialog, + LPARAM(new invite_chat_param(item->id, this))); + break; + + case GC_USER_PRIVMESS: + { + char* sn = mir_t2a(gch->ptszUID); + MCONTACT hContact = contact_from_sn(sn); + mir_free(sn); + CallService(MS_MSG_SENDMESSAGE, hContact, 0); + } + break; - case GC_USER_CHANMGR: - DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, invite_to_chat_dialog, + case GC_USER_LOGMENU: + switch (gch->dwData) { + case 10: + DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, invite_to_chat_dialog, LPARAM(new invite_chat_param(item->id, this))); break; - case GC_USER_PRIVMESS: - { - char* sn = mir_t2a(gch->ptszUID); - MCONTACT hContact = contact_from_sn(sn); - mir_free(sn); - CallService(MS_MSG_SENDMESSAGE, hContact, 0); - } + case 20: + chat_leave(id); break; + } + break; + + case GC_USER_NICKLISTMENU: + { + char *sn = mir_t2a(gch->ptszUID); + MCONTACT hContact = contact_from_sn(sn); + mir_free(sn); - case GC_USER_LOGMENU: - switch(gch->dwData) - { + switch (gch->dwData) { case 10: - DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, invite_to_chat_dialog, - LPARAM(new invite_chat_param(item->id, this))); + CallService(MS_USERINFO_SHOWDIALOG, hContact, 0); break; case 20: + CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact, 0); + break; + + case 110: chat_leave(id); break; } - break; - - case GC_USER_NICKLISTMENU: - { - char *sn = mir_t2a(gch->ptszUID); - MCONTACT hContact = contact_from_sn(sn); - mir_free(sn); - - switch (gch->dwData) - { - case 10: - CallService(MS_USERINFO_SHOWDIALOG, hContact, 0); - break; - - case 20: - CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact, 0); - break; - - case 110: - chat_leave(id); - break; - } - } - break; + } + break; - case GC_USER_TYPNOTIFY: - break; + case GC_USER_TYPNOTIFY: + break; } mir_free(id); return 0; } -int CAimProto::OnGCMenuHook(WPARAM, LPARAM lParam) +int CAimProto::OnGCMenuHook(WPARAM, LPARAM lParam) { - GCMENUITEMS *gcmi= (GCMENUITEMS*)lParam; + GCMENUITEMS *gcmi = (GCMENUITEMS*)lParam; - if ( gcmi == NULL || _stricmp(gcmi->pszModule, m_szModuleName )) return 0; + if (gcmi == NULL || _stricmp(gcmi->pszModule, m_szModuleName)) return 0; - if ( gcmi->Type == MENU_ON_LOG ) - { + if (gcmi->Type == MENU_ON_LOG) { static const struct gc_item Items[] = { { TranslateT("&Invite user..."), 10, MENU_ITEM, FALSE }, { TranslateT("&Leave chat session"), 20, MENU_ITEM, FALSE } @@ -200,11 +197,9 @@ int CAimProto::OnGCMenuHook(WPARAM, LPARAM lParam) gcmi->nItems = _countof(Items); gcmi->Item = (gc_item*)Items; } - else if ( gcmi->Type == MENU_ON_NICKLIST ) - { + else if (gcmi->Type == MENU_ON_NICKLIST) { char* sn = mir_t2a(gcmi->pszUID); - if ( !mir_strcmp(username, sn)) - { + if (!mir_strcmp(m_username, sn)) { static const struct gc_item Items[] = { { TranslateT("User &details"), 10, MENU_ITEM, FALSE }, { TranslateT("User &history"), 20, MENU_ITEM, FALSE }, @@ -221,7 +216,7 @@ int CAimProto::OnGCMenuHook(WPARAM, LPARAM lParam) }; gcmi->nItems = _countof(Items); gcmi->Item = (gc_item*)Items; - } + } mir_free(sn); } @@ -229,69 +224,51 @@ int CAimProto::OnGCMenuHook(WPARAM, LPARAM lParam) } -void __cdecl CAimProto::chatnav_request_thread( void* param ) +void __cdecl CAimProto::chatnav_request_thread(void* param) { - chatnav_param* par = (chatnav_param*)param; + chatnav_param *par = (chatnav_param*)param; - if (wait_conn(hChatNavConn, hChatNavEvent, 0x0d)) - { + if (wait_conn(m_hChatNavConn, m_hChatNavEvent, 0x0d)) { if (par->isroom) - aim_chatnav_create(hChatNavConn, chatnav_seqno, par->id, par->exchange); + aim_chatnav_create(m_hChatNavConn, m_chatnav_seqno, par->id, par->exchange); else - aim_chatnav_room_info(hChatNavConn, chatnav_seqno, par->id, par->exchange, par->instance); + aim_chatnav_room_info(m_hChatNavConn, m_chatnav_seqno, par->id, par->exchange, par->instance); } delete par; } chat_list_item* CAimProto::find_chat_by_cid(unsigned short cid) { - chat_list_item* item = NULL; - for(int i=0; i. */ + #include "stdafx.h" -int CAimProto::aim_send_connection_packet(HANDLE hServerConn,unsigned short &seqno,char *buf) +int CAimProto::aim_send_connection_packet(HANDLE hServerConn, unsigned short &seqno, char *buf) { - return aim_sendflap(hServerConn,0x01,4,buf,seqno); + return aim_sendflap(hServerConn, 0x01, 4, buf, seqno); } -int CAimProto::aim_authkey_request(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_authkey_request(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE*3+mir_strlen(username)); - aim_writesnac(0x17,0x06,offset,buf); - aim_writetlv(0x01,(unsigned short)mir_strlen(username),username,offset,buf); - aim_writetlv(0x4B,0,0,offset,buf); - aim_writetlv(0x5A,0,0,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char *buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 3 + mir_strlen(m_username)); + aim_writesnac(0x17, 0x06, offset, buf); + aim_writetlv(0x01, (unsigned short)mir_strlen(m_username), m_username, offset, buf); + aim_writetlv(0x4B, 0, 0, offset, buf); + aim_writetlv(0x5A, 0, 0, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_auth_request(HANDLE hServerConn,unsigned short &seqno,const char* key,const char* language, - const char* country, const char* username, const char* password) +int CAimProto::aim_auth_request(HANDLE hServerConn, unsigned short &seqno, const char* key, const char* language, + const char* country, const char* username, const char* password) { - unsigned short offset=0; + unsigned short offset = 0; BYTE pass_hash[16]; BYTE auth_hash[16]; mir_md5_state_t state; - + mir_md5_init(&state); - mir_md5_append(&state,(const BYTE *)password, (int)mir_strlen(password)); - mir_md5_finish(&state,pass_hash); + mir_md5_append(&state, (const BYTE *)password, (int)mir_strlen(password)); + mir_md5_finish(&state, pass_hash); mir_md5_init(&state); - mir_md5_append(&state,(BYTE*)key, (int)mir_strlen(key)); - mir_md5_append(&state,(BYTE*)pass_hash,MD5_HASH_LENGTH); - mir_md5_append(&state,(BYTE*)AIM_MD5_STRING, sizeof(AIM_MD5_STRING)-1); - mir_md5_finish(&state,auth_hash); + mir_md5_append(&state, (BYTE*)key, (int)mir_strlen(key)); + mir_md5_append(&state, (BYTE*)pass_hash, MD5_HASH_LENGTH); + mir_md5_append(&state, (BYTE*)AIM_MD5_STRING, sizeof(AIM_MD5_STRING) - 1); + mir_md5_finish(&state, auth_hash); char client_id[64], mirver[64]; CallService(MS_SYSTEM_GETVERSIONTEXT, sizeof(mirver), (LPARAM)mirver); int client_id_len = mir_snprintf(client_id, _countof(client_id), "Miranda AIM, version %s", mirver); - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE*14+MD5_HASH_LENGTH+mir_strlen(username)+client_id_len+30+mir_strlen(language)+mir_strlen(country)); - - aim_writesnac(0x17,0x02,offset,buf); - aim_writetlv(0x01,(unsigned short)mir_strlen(username),username,offset,buf); - aim_writetlv(0x25,MD5_HASH_LENGTH,(char*)auth_hash,offset,buf); - aim_writetlv(0x4C,0,0,offset,buf);//signifies new password hash instead of old method - aim_writetlv(0x03,(unsigned short)client_id_len,client_id,offset,buf); - aim_writetlvshort(0x17,AIM_CLIENT_MAJOR_VERSION,offset,buf); - aim_writetlvshort(0x18,AIM_CLIENT_MINOR_VERSION,offset,buf); - aim_writetlvshort(0x19,AIM_CLIENT_LESSER_VERSION,offset,buf); - aim_writetlvshort(0x1A,AIM_CLIENT_BUILD_NUMBER,offset,buf); - aim_writetlvshort(0x16,AIM_CLIENT_ID_NUMBER,offset,buf); - aim_writetlvlong(0x14,AIM_CLIENT_DISTRIBUTION_NUMBER,offset,buf); - aim_writetlv(0x0F,(unsigned short)mir_strlen(language),language,offset,buf); - aim_writetlv(0x0E,(unsigned short)mir_strlen(country),country,offset,buf); - aim_writetlvchar(0x4A,getByte(AIM_KEY_FSC, 0) ? 3 : 1,offset,buf); -// aim_writetlvchar(0x94,0,offset,buf); + char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 14 + MD5_HASH_LENGTH + mir_strlen(username) + client_id_len + 30 + mir_strlen(language) + mir_strlen(country)); + + aim_writesnac(0x17, 0x02, offset, buf); + aim_writetlv(0x01, (unsigned short)mir_strlen(username), username, offset, buf); + aim_writetlv(0x25, MD5_HASH_LENGTH, (char*)auth_hash, offset, buf); + aim_writetlv(0x4C, 0, 0, offset, buf);//signifies new password hash instead of old method + aim_writetlv(0x03, (unsigned short)client_id_len, client_id, offset, buf); + aim_writetlvshort(0x17, AIM_CLIENT_MAJOR_VERSION, offset, buf); + aim_writetlvshort(0x18, AIM_CLIENT_MINOR_VERSION, offset, buf); + aim_writetlvshort(0x19, AIM_CLIENT_LESSER_VERSION, offset, buf); + aim_writetlvshort(0x1A, AIM_CLIENT_BUILD_NUMBER, offset, buf); + aim_writetlvshort(0x16, AIM_CLIENT_ID_NUMBER, offset, buf); + aim_writetlvlong(0x14, AIM_CLIENT_DISTRIBUTION_NUMBER, offset, buf); + aim_writetlv(0x0F, (unsigned short)mir_strlen(language), language, offset, buf); + aim_writetlv(0x0E, (unsigned short)mir_strlen(country), country, offset, buf); + aim_writetlvchar(0x4A, getByte(AIM_KEY_FSC, 0) ? 3 : 1, offset, buf); + // aim_writetlvchar(0x94,0,offset,buf); if (!getByte(AIM_KEY_DSSL, 0)) - aim_writetlv(0x8c,0,NULL,offset,buf); // Request SSL connection - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writetlv(0x8c, 0, NULL, offset, buf); // Request SSL connection + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_send_cookie(HANDLE hServerConn,unsigned short &seqno,int cookie_size,char * cookie) +int CAimProto::aim_send_cookie(HANDLE hServerConn, unsigned short &seqno, int cookie_size, char * cookie) { - unsigned short offset=0; - char* buf=(char*)alloca(TLV_HEADER_SIZE*2+cookie_size); - aim_writelong(0x01,offset,buf);//protocol version number - aim_writetlv(0x06,(unsigned short)cookie_size,cookie,offset,buf); - return aim_sendflap(hServerConn,0x01,offset,buf,seqno); + unsigned short offset = 0; + char* buf = (char*)alloca(TLV_HEADER_SIZE * 2 + cookie_size); + aim_writelong(0x01, offset, buf);//protocol version number + aim_writetlv(0x06, (unsigned short)cookie_size, cookie, offset, buf); + return aim_sendflap(hServerConn, 0x01, offset, buf, seqno); } -int CAimProto::aim_send_service_request(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_send_service_request(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*12]; - aim_writesnac(0x01,0x17,offset,buf); - aim_writefamily(AIM_SERVICE_GENERIC,offset,buf); - aim_writefamily(AIM_SERVICE_SSI,offset,buf); - aim_writefamily(AIM_SERVICE_LOCATION,offset,buf); - aim_writefamily(AIM_SERVICE_BUDDYLIST,offset,buf); - aim_writefamily(AIM_SERVICE_MESSAGING,offset,buf); - aim_writefamily(AIM_SERVICE_ICQ,offset,buf); - aim_writefamily(AIM_SERVICE_INVITATION,offset,buf); - aim_writefamily(AIM_SERVICE_POPUP,offset,buf); - aim_writefamily(AIM_SERVICE_BOS,offset,buf); - aim_writefamily(AIM_SERVICE_USERLOOKUP,offset,buf); - aim_writefamily(AIM_SERVICE_STATS,offset,buf); - aim_writefamily(AIM_SERVICE_UNKNOWN,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 12]; + aim_writesnac(0x01, 0x17, offset, buf); + aim_writefamily(AIM_SERVICE_GENERIC, offset, buf); + aim_writefamily(AIM_SERVICE_SSI, offset, buf); + aim_writefamily(AIM_SERVICE_LOCATION, offset, buf); + aim_writefamily(AIM_SERVICE_BUDDYLIST, offset, buf); + aim_writefamily(AIM_SERVICE_MESSAGING, offset, buf); + aim_writefamily(AIM_SERVICE_ICQ, offset, buf); + aim_writefamily(AIM_SERVICE_INVITATION, offset, buf); + aim_writefamily(AIM_SERVICE_POPUP, offset, buf); + aim_writefamily(AIM_SERVICE_BOS, offset, buf); + aim_writefamily(AIM_SERVICE_USERLOOKUP, offset, buf); + aim_writefamily(AIM_SERVICE_STATS, offset, buf); + aim_writefamily(AIM_SERVICE_UNKNOWN, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_new_service_request(HANDLE hServerConn,unsigned short &seqno,unsigned short service) +int CAimProto::aim_new_service_request(HANDLE hServerConn, unsigned short &seqno, unsigned short service) { - unsigned short offset=0; - char buf[SNAC_SIZE+2+TLV_HEADER_SIZE]; - aim_writesnac(0x01,0x04,offset,buf); - aim_writeshort(service,offset,buf); + unsigned short offset = 0; + char buf[SNAC_SIZE + 2 + TLV_HEADER_SIZE]; + aim_writesnac(0x01, 0x04, offset, buf); + aim_writeshort(service, offset, buf); if (!getByte(AIM_KEY_DSSL, 0)) - aim_writetlv(0x8c,0,NULL,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writetlv(0x8c, 0, NULL, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_request_rates(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_request_rates(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; + unsigned short offset = 0; char buf[SNAC_SIZE]; - aim_writesnac(0x01,0x06,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writesnac(0x01, 0x06, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_accept_rates(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_accept_rates(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE*2]; - aim_writesnac(0x01,0x08,offset,buf); - aim_writegeneric(10,AIM_SERVICE_RATES,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE * 2]; + aim_writesnac(0x01, 0x08, offset, buf); + aim_writegeneric(10, AIM_SERVICE_RATES, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_request_icbm(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_request_icbm(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; + unsigned short offset = 0; char buf[SNAC_SIZE]; - aim_writesnac(0x04,0x04,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writesnac(0x04, 0x04, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_set_icbm(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_set_icbm(HANDLE hServerConn, unsigned short &seqno) { - const unsigned icbm_flags = ICBM_CHANNEL_MSGS_ALLOWED | ICBM_MISSED_CALLS_ENABLED | + const unsigned icbm_flags = ICBM_CHANNEL_MSGS_ALLOWED | ICBM_MISSED_CALLS_ENABLED | ICBM_EVENTS_ALLOWED | ICBM_SMS_SUPPORTED | ICBM_OFFLINE_MSGS_ALLOWED; -// const unsigned icbm_flags = 0x3db; + // const unsigned icbm_flags = 0x3db; - unsigned short offset=0; - char buf[SNAC_SIZE+16]; - aim_writesnac(0x04,0x02,offset,buf); - aim_writeshort(0,offset,buf); //channel - aim_writelong(icbm_flags,offset,buf); //flags - aim_writeshort(0x1f40,offset,buf); //max snac size 8000 - aim_writeshort(0x03e7,offset,buf); //max sender warning level 999 (0-1000) WinAim default - aim_writeshort(0x03e7,offset,buf); //max receiver warning level 999 (0-1000) WinAim default - aim_writelong(0,offset,buf); //min message interval, ms 0 - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + 16]; + aim_writesnac(0x04, 0x02, offset, buf); + aim_writeshort(0, offset, buf); //channel + aim_writelong(icbm_flags, offset, buf); //flags + aim_writeshort(0x1f40, offset, buf); //max snac size 8000 + aim_writeshort(0x03e7, offset, buf); //max sender warning level 999 (0-1000) WinAim default + aim_writeshort(0x03e7, offset, buf); //max receiver warning level 999 (0-1000) WinAim default + aim_writelong(0, offset, buf); //min message interval, ms 0 + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_request_offline_msgs(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_request_offline_msgs(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; + unsigned short offset = 0; char buf[SNAC_SIZE]; - aim_writesnac(0x04,0x10,offset,buf); // Subtype for offline messages 0x10 - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writesnac(0x04, 0x10, offset, buf); // Subtype for offline messages 0x10 + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_request_list(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_request_list(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; + unsigned short offset = 0; char buf[SNAC_SIZE]; - aim_writesnac(0x13,0x04,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writesnac(0x13, 0x04, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_activate_list(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_activate_list(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; + unsigned short offset = 0; char buf[SNAC_SIZE]; - aim_writesnac(0x13,0x07,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writesnac(0x13, 0x07, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } /* @@ -202,35 +203,35 @@ int CAimProto::aim_request_rights(HANDLE hServerConn,unsigned short &seqno) return aim_sendflap(hServerConn,0x02,offset,buf,seqno); } */ -int CAimProto::aim_set_caps(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_set_caps(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - int i=1; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*3+AIM_CAPS_LENGTH*50+sizeof(AIM_MSG_TYPE)]; - char temp[AIM_CAPS_LENGTH*20]; - memcpy(temp,AIM_CAP_SHORT_CAPS,AIM_CAPS_LENGTH); - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_HOST_STATUS_TEXT_AWARE,AIM_CAPS_LENGTH); - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_SMART_CAPS,AIM_CAPS_LENGTH); - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_FILE_TRANSFER,AIM_CAPS_LENGTH); -// memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_HAS_MICROPHONE,AIM_CAPS_LENGTH); -// memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_RTCAUDIO,AIM_CAPS_LENGTH); -// memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_HAS_CAMERA,AIM_CAPS_LENGTH); -// memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_RTCVIDEO,AIM_CAPS_LENGTH); - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_BUDDY_ICON,AIM_CAPS_LENGTH); - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_CHAT,AIM_CAPS_LENGTH); - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_SUPPORT_ICQ,AIM_CAPS_LENGTH); -// memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_ICQ_SERVER_RELAY,AIM_CAPS_LENGTH); - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_UTF8,AIM_CAPS_LENGTH); - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_MIRANDA,AIM_CAPS_LENGTH); + unsigned short offset = 0; + int i = 1; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 3 + AIM_CAPS_LENGTH * 50 + sizeof(AIM_MSG_TYPE)]; + char temp[AIM_CAPS_LENGTH * 20]; + memcpy(temp, AIM_CAP_SHORT_CAPS, AIM_CAPS_LENGTH); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_HOST_STATUS_TEXT_AWARE, AIM_CAPS_LENGTH); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_SMART_CAPS, AIM_CAPS_LENGTH); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_FILE_TRANSFER, AIM_CAPS_LENGTH); + // memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_HAS_MICROPHONE,AIM_CAPS_LENGTH); + // memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_RTCAUDIO,AIM_CAPS_LENGTH); + // memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_HAS_CAMERA,AIM_CAPS_LENGTH); + // memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_RTCVIDEO,AIM_CAPS_LENGTH); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_BUDDY_ICON, AIM_CAPS_LENGTH); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_CHAT, AIM_CAPS_LENGTH); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_SUPPORT_ICQ, AIM_CAPS_LENGTH); + // memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_ICQ_SERVER_RELAY,AIM_CAPS_LENGTH); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_UTF8, AIM_CAPS_LENGTH); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_MIRANDA, AIM_CAPS_LENGTH); if (getByte(AIM_KEY_HF, 0)) - memcpy(&temp[AIM_CAPS_LENGTH*i++],AIM_CAP_HIPTOP,AIM_CAPS_LENGTH); - aim_writesnac(0x02,0x04,offset,buf); - aim_writetlv(0x05,(unsigned short)(AIM_CAPS_LENGTH*i),temp,offset,buf); + memcpy(&temp[AIM_CAPS_LENGTH*i++], AIM_CAP_HIPTOP, AIM_CAPS_LENGTH); + aim_writesnac(0x02, 0x04, offset, buf); + aim_writetlv(0x05, (unsigned short)(AIM_CAPS_LENGTH*i), temp, offset, buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_set_profile(HANDLE hServerConn,unsigned short &seqno, char* amsg)//user info +int CAimProto::aim_set_profile(HANDLE hServerConn, unsigned short &seqno, char* amsg)//user info { aimString str(amsg); const char *charset = str.isUnicode() ? AIM_MSG_TYPE_UNICODE : AIM_MSG_TYPE; @@ -239,338 +240,330 @@ int CAimProto::aim_set_profile(HANDLE hServerConn,unsigned short &seqno, char* a const char* msg = str.getBuf(); const unsigned short msg_len = str.getSize(); - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE*3+1+charset_len+msg_len); - unsigned short offset=0; + char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 3 + 1 + charset_len + msg_len); + unsigned short offset = 0; - aim_writesnac(0x02,0x04,offset,buf); - aim_writetlvchar(0x0c,1,offset,buf); - aim_writetlv(0x01,charset_len,charset,offset,buf); - aim_writetlv(0x02,msg_len,msg,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writesnac(0x02, 0x04, offset, buf); + aim_writetlvchar(0x0c, 1, offset, buf); + aim_writetlv(0x01, charset_len, charset, offset, buf); + aim_writetlv(0x02, msg_len, msg, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_client_ready(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_client_ready(HANDLE hServerConn, unsigned short &seqno) { unsigned short offset = 0; - NETLIBCONNINFO connInfo = { sizeof(connInfo) }; + NETLIBCONNINFO connInfo = { sizeof(connInfo) }; CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hServerConn, (LPARAM)&connInfo); - - internal_ip = connInfo.dwIpv4; - - char buf[SNAC_SIZE+TLV_HEADER_SIZE*22]; - aim_writesnac(0x01,0x02,offset,buf); - aim_writefamily(AIM_SERVICE_GENERIC,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_SSI,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_LOCATION,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_BUDDYLIST,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_MESSAGING,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_ICQ,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_INVITATION,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); + + m_internal_ip = connInfo.dwIpv4; + + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 22]; + aim_writesnac(0x01, 0x02, offset, buf); + aim_writefamily(AIM_SERVICE_GENERIC, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_SSI, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_LOCATION, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_BUDDYLIST, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_MESSAGING, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_ICQ, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_INVITATION, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); //removed extra generic server - aim_writefamily(AIM_SERVICE_POPUP,offset,buf); - aim_writegeneric(4,"\x01\x04\0\x01",offset,buf);//different version number like trillian 3.1 - aim_writefamily(AIM_SERVICE_BOS,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_USERLOOKUP,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_STATS,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writefamily(AIM_SERVICE_POPUP, offset, buf); + aim_writegeneric(4, "\x01\x04\0\x01", offset, buf);//different version number like trillian 3.1 + aim_writefamily(AIM_SERVICE_BOS, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_USERLOOKUP, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_STATS, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_mail_ready(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_mail_ready(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*4]; - aim_writesnac(0x01,0x02,offset,buf); - aim_writefamily(AIM_SERVICE_GENERIC,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_MAIL,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 4]; + aim_writesnac(0x01, 0x02, offset, buf); + aim_writefamily(AIM_SERVICE_GENERIC, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_MAIL, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_avatar_ready(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_avatar_ready(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*4]; - aim_writesnac(0x01,0x02,offset,buf); - aim_writefamily(AIM_SERVICE_GENERIC,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_AVATAR,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 4]; + aim_writesnac(0x01, 0x02, offset, buf); + aim_writefamily(AIM_SERVICE_GENERIC, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_AVATAR, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_chatnav_ready(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_chatnav_ready(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*4]; - aim_writesnac(0x01,0x02,offset,buf); - aim_writefamily(AIM_SERVICE_GENERIC,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_CHATNAV,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 4]; + aim_writesnac(0x01, 0x02, offset, buf); + aim_writefamily(AIM_SERVICE_GENERIC, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_CHATNAV, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_chat_ready(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_chat_ready(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*4]; - aim_writesnac(0x01,0x02,offset,buf); - aim_writefamily(AIM_SERVICE_GENERIC,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_CHAT,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 4]; + aim_writesnac(0x01, 0x02, offset, buf); + aim_writefamily(AIM_SERVICE_GENERIC, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_CHAT, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_send_message(HANDLE hServerConn,unsigned short &seqno,const char* sn,char* amsg,bool auto_response, bool blast) -{ +int CAimProto::aim_send_message(HANDLE hServerConn, unsigned short &seqno, const char* sn, char* amsg, bool auto_response, bool blast) +{ aimString str(amsg); const char* msg = str.getBuf(); const unsigned short msg_len = str.getSize(); - unsigned short tlv_offset=0; - char* tlv_buf=(char*)alloca(5+msg_len+8); + unsigned short tlv_offset = 0; + char* tlv_buf = (char*)alloca(5 + msg_len + 8); char icbm_cookie[8]; Utils_GetRandom(icbm_cookie, sizeof(icbm_cookie)); - - aim_writegeneric(5,"\x05\x01\x00\x01\x01",tlv_offset,tlv_buf); // icbm im capabilities - aim_writeshort(0x0101,tlv_offset,tlv_buf); // icbm im text tag - aim_writeshort(msg_len+4,tlv_offset,tlv_buf); // icbm im text tag length - aim_writeshort(str.isUnicode()?2:0,tlv_offset,tlv_buf); // character set - aim_writeshort(0,tlv_offset,tlv_buf); // language - - aim_writegeneric(msg_len,msg,tlv_offset,tlv_buf); // message text - - unsigned short offset=0; - unsigned short sn_length=(unsigned short)mir_strlen(sn); - char* buf= (char*)alloca(SNAC_SIZE+8+3+sn_length+TLV_HEADER_SIZE*3+tlv_offset); - - aim_writesnac(0x04,0x06,offset,buf,get_random()); - aim_writegeneric(8,icbm_cookie,offset,buf); // icbm cookie - aim_writeshort(0x01,offset,buf); // channel - aim_writechar((unsigned char)sn_length,offset,buf); // screen name len - aim_writegeneric(sn_length,sn,offset,buf); // screen name - - aim_writetlv(0x02,tlv_offset,tlv_buf,offset,buf); - - if (!blast) - { + + aim_writegeneric(5, "\x05\x01\x00\x01\x01", tlv_offset, tlv_buf); // icbm im capabilities + aim_writeshort(0x0101, tlv_offset, tlv_buf); // icbm im text tag + aim_writeshort(msg_len + 4, tlv_offset, tlv_buf); // icbm im text tag length + aim_writeshort(str.isUnicode() ? 2 : 0, tlv_offset, tlv_buf); // character set + aim_writeshort(0, tlv_offset, tlv_buf); // language + + aim_writegeneric(msg_len, msg, tlv_offset, tlv_buf); // message text + + unsigned short offset = 0; + unsigned short sn_length = (unsigned short)mir_strlen(sn); + char* buf = (char*)alloca(SNAC_SIZE + 8 + 3 + sn_length + TLV_HEADER_SIZE * 3 + tlv_offset); + + aim_writesnac(0x04, 0x06, offset, buf, get_random()); + aim_writegeneric(8, icbm_cookie, offset, buf); // icbm cookie + aim_writeshort(0x01, offset, buf); // channel + aim_writechar((unsigned char)sn_length, offset, buf); // screen name len + aim_writegeneric(sn_length, sn, offset, buf); // screen name + + aim_writetlv(0x02, tlv_offset, tlv_buf, offset, buf); + + if (!blast) { if (auto_response) - aim_writetlv(0x04,0,0,offset,buf); // auto-response message - else - { - aim_writetlv(0x03,0,0,offset,buf); // message ack request - aim_writetlv(0x06,0,0,offset,buf); // offline message storage + aim_writetlv(0x04, 0, 0, offset, buf); // auto-response message + else { + aim_writetlv(0x03, 0, 0, offset, buf); // message ack request + aim_writetlv(0x06, 0, 0, offset, buf); // offline message storage } } - return aim_sendflap(hServerConn,0x02,offset,buf,seqno) ? 0 : *(int*)icbm_cookie & 0x7fffffff; + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno) ? 0 : *(int*)icbm_cookie & 0x7fffffff; } -int CAimProto::aim_query_profile(HANDLE hServerConn,unsigned short &seqno,char* sn) +int CAimProto::aim_query_profile(HANDLE hServerConn, unsigned short &seqno, char* sn) { - unsigned short offset=0; - unsigned short sn_length=(unsigned short)mir_strlen(sn); - char* buf=(char*)alloca(SNAC_SIZE+5+sn_length); - aim_writesnac(0x02,0x15,offset,buf); - aim_writelong(0x01,offset,buf); - aim_writechar((unsigned char)sn_length,offset,buf); - aim_writegeneric(sn_length,sn,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno)==0; + unsigned short offset = 0; + unsigned short sn_length = (unsigned short)mir_strlen(sn); + char* buf = (char*)alloca(SNAC_SIZE + 5 + sn_length); + aim_writesnac(0x02, 0x15, offset, buf); + aim_writelong(0x01, offset, buf); + aim_writechar((unsigned char)sn_length, offset, buf); + aim_writegeneric(sn_length, sn, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno) == 0; } int CAimProto::aim_delete_contact(HANDLE hServerConn, unsigned short &seqno, char* sn, unsigned short item_id, - unsigned short group_id, unsigned short list, bool nil) + unsigned short group_id, unsigned short list, bool nil) { - unsigned short offset=0; - unsigned short sn_length=(unsigned short)mir_strlen(sn); - char* buf=(char*)alloca(SNAC_SIZE+sn_length+10); - aim_writesnac(0x13,0x0a,offset,buf, get_random()); // SSI Delete - aim_writeshort(sn_length,offset,buf); // screen name length - aim_writegeneric(sn_length,sn,offset,buf); // screen name - aim_writeshort(group_id,offset,buf); // group id - aim_writeshort(item_id,offset,buf); // buddy id - aim_writeshort(list,offset,buf); // buddy type - aim_writeshort(nil?4:0,offset,buf); // length of extra data - if (nil) aim_writetlv(0x6a,0,NULL,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + unsigned short sn_length = (unsigned short)mir_strlen(sn); + char* buf = (char*)alloca(SNAC_SIZE + sn_length + 10); + aim_writesnac(0x13, 0x0a, offset, buf, get_random()); // SSI Delete + aim_writeshort(sn_length, offset, buf); // screen name length + aim_writegeneric(sn_length, sn, offset, buf); // screen name + aim_writeshort(group_id, offset, buf); // group id + aim_writeshort(item_id, offset, buf); // buddy id + aim_writeshort(list, offset, buf); // buddy type + aim_writeshort(nil ? 4 : 0, offset, buf); // length of extra data + if (nil) aim_writetlv(0x6a, 0, NULL, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_add_contact(HANDLE hServerConn, unsigned short &seqno, const char* sn, unsigned short item_id, - unsigned short group_id, unsigned short list, char* nick, char* note) + unsigned short group_id, unsigned short list, char* nick, char* note) { - unsigned short offset=0; - unsigned short sn_length=(unsigned short)mir_strlen(sn); + unsigned short offset = 0; + unsigned short sn_length = (unsigned short)mir_strlen(sn); unsigned short nick_length = (unsigned short)mir_strlen(nick); unsigned short note_length = (unsigned short)mir_strlen(note); unsigned short tlv_len = nick || note ? TLV_HEADER_SIZE * 2 + nick_length + note_length : 0; - char* buf=(char*)alloca(SNAC_SIZE + sn_length + 10 + tlv_len); - aim_writesnac(0x13,0x08,offset,buf, get_random()); // SSI Add - aim_writeshort(sn_length,offset,buf); // screen name length - aim_writegeneric(sn_length,sn,offset,buf); // screen name - aim_writeshort(group_id,offset,buf); // group id - aim_writeshort(item_id,offset,buf); // buddy id - aim_writeshort(list,offset, buf); // buddy type - aim_writeshort(tlv_len,offset,buf); // length of extra data - - if (nick || note) - { - aim_writetlv(0x13c,note_length,note,offset,buf); - aim_writetlv(0x131,nick_length,nick,offset,buf); + char* buf = (char*)alloca(SNAC_SIZE + sn_length + 10 + tlv_len); + aim_writesnac(0x13, 0x08, offset, buf, get_random()); // SSI Add + aim_writeshort(sn_length, offset, buf); // screen name length + aim_writegeneric(sn_length, sn, offset, buf); // screen name + aim_writeshort(group_id, offset, buf); // group id + aim_writeshort(item_id, offset, buf); // buddy id + aim_writeshort(list, offset, buf); // buddy type + aim_writeshort(tlv_len, offset, buf); // length of extra data + + if (nick || note) { + aim_writetlv(0x13c, note_length, note, offset, buf); + aim_writetlv(0x131, nick_length, nick, offset, buf); } return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_mod_group(HANDLE hServerConn, unsigned short &seqno, const char* name, unsigned short group_id, - char* members, unsigned short members_length) + char* members, unsigned short members_length) { - unsigned short offset=0; - unsigned short name_length=(unsigned short)mir_strlen(name); - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE+name_length+members_length+10); - aim_writesnac(0x13,0x09,offset,buf, get_random()); // SSI Edit - aim_writeshort(name_length,offset,buf); // group name length - aim_writegeneric(name_length,name,offset,buf); // group name - aim_writeshort(group_id,offset,buf); // group id - aim_writeshort(0,offset,buf); // buddy id - aim_writeshort(1,offset,buf); // buddy type: Group - aim_writeshort(TLV_HEADER_SIZE+members_length,offset,buf); // length of extra data - aim_writetlv(0xc8,members_length,members,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + unsigned short name_length = (unsigned short)mir_strlen(name); + char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE + name_length + members_length + 10); + aim_writesnac(0x13, 0x09, offset, buf, get_random()); // SSI Edit + aim_writeshort(name_length, offset, buf); // group name length + aim_writegeneric(name_length, name, offset, buf); // group name + aim_writeshort(group_id, offset, buf); // group id + aim_writeshort(0, offset, buf); // buddy id + aim_writeshort(1, offset, buf); // buddy type: Group + aim_writeshort(TLV_HEADER_SIZE + members_length, offset, buf); // length of extra data + aim_writetlv(0xc8, members_length, members, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_mod_buddy(HANDLE hServerConn, unsigned short &seqno, const char* sn, - unsigned short buddy_id, unsigned short group_id, - char* nick, char* note) +int CAimProto::aim_mod_buddy(HANDLE hServerConn, unsigned short &seqno, const char* sn, + unsigned short buddy_id, unsigned short group_id, + char* nick, char* note) { - unsigned short offset=0; + unsigned short offset = 0; unsigned short sn_length = (unsigned short)mir_strlen(sn); unsigned short nick_length = (unsigned short)mir_strlen(nick); unsigned short note_length = (unsigned short)mir_strlen(note); unsigned short tlv_len = TLV_HEADER_SIZE * 2 + nick_length + note_length; - - char* buf=(char*)alloca(SNAC_SIZE+sn_length+10+tlv_len); - aim_writesnac(0x13,0x09,offset,buf, get_random()); // SSI Edit - aim_writeshort(sn_length,offset,buf); // screen name length - aim_writegeneric(sn_length,sn,offset,buf); // screen name - aim_writeshort(buddy_id,offset,buf); // buddy id - aim_writeshort(group_id,offset,buf); // group id - aim_writeshort(0,offset,buf); // buddy type: Buddy - aim_writeshort(tlv_len,offset,buf); // length of extra data - - aim_writetlv(0x13c,note_length,note,offset,buf); - aim_writetlv(0x131,nick_length,nick,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + + char* buf = (char*)alloca(SNAC_SIZE + sn_length + 10 + tlv_len); + aim_writesnac(0x13, 0x09, offset, buf, get_random()); // SSI Edit + aim_writeshort(sn_length, offset, buf); // screen name length + aim_writegeneric(sn_length, sn, offset, buf); // screen name + aim_writeshort(buddy_id, offset, buf); // buddy id + aim_writeshort(group_id, offset, buf); // group id + aim_writeshort(0, offset, buf); // buddy type: Buddy + aim_writeshort(tlv_len, offset, buf); // length of extra data + + aim_writetlv(0x13c, note_length, note, offset, buf); + aim_writetlv(0x131, nick_length, nick, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_set_pd_info(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*3+20]; + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 3 + 20]; unsigned short req = 0x09; - if (pd_info_id == 0) - { - pd_info_id = get_random(); + if (m_pd_info_id == 0) { + m_pd_info_id = get_random(); req = 0x08; } - aim_writesnac(0x13,req,offset,buf, get_random()); // SSI Edit/Add - aim_writeshort(0,offset,buf); // name length - aim_writeshort(0,offset,buf); // group id (root) - aim_writeshort(pd_info_id,offset,buf); // buddy id - aim_writeshort(0x4,offset,buf); // pd info id - aim_writeshort(0x15,offset,buf); // size - aim_writetlvchar(0xca,pd_mode,offset,buf); // pd mode - aim_writetlvlong(0xcb,0xffffffff,offset,buf); // pd mask - aim_writetlvlong(0xcc,pd_flags,offset,buf); // pd flags - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + aim_writesnac(0x13, req, offset, buf, get_random()); // SSI Edit/Add + aim_writeshort(0, offset, buf); // name length + aim_writeshort(0, offset, buf); // group id (root) + aim_writeshort(m_pd_info_id, offset, buf); // buddy id + aim_writeshort(0x4, offset, buf); // pd info id + aim_writeshort(0x15, offset, buf); // size + aim_writetlvchar(0xca, m_pd_mode, offset, buf); // pd mode + aim_writetlvlong(0xcb, 0xffffffff, offset, buf); // pd mask + aim_writetlvlong(0xcc, m_pd_flags, offset, buf); // pd flags + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_ssi_update_preferences(HANDLE hServerConn, unsigned short &seqno) { unsigned short offset = 0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*4+100]; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 4 + 100]; unsigned short req = 0x09; - if (pref1_id == 0) - { - pref1_id = get_random(); + if (m_pref1_id == 0) { + m_pref1_id = get_random(); req = 0x08; } - aim_writesnac(0x13,req,offset,buf, get_random()); // SSI Edit/Add - aim_writeshort(0,offset,buf); // group name length - aim_writeshort(0,offset,buf); // group id (root) - aim_writeshort(pref1_id,offset,buf); // buddy id - aim_writeshort(5,offset,buf); // buddy type: Presence + aim_writesnac(0x13, req, offset, buf, get_random()); // SSI Edit/Add + aim_writeshort(0, offset, buf); // group name length + aim_writeshort(0, offset, buf); // group id (root) + aim_writeshort(m_pref1_id, offset, buf); // buddy id + aim_writeshort(5, offset, buf); // buddy type: Presence unsigned short tlv_len = TLV_HEADER_SIZE * 2 + 8; - if (pref2_len) tlv_len += TLV_HEADER_SIZE + pref2_len; - if (pref2_set_len) tlv_len += TLV_HEADER_SIZE + pref2_set_len; - - aim_writeshort(tlv_len,offset,buf); // length of extra data - aim_writetlvlong(0xc9,pref1_flags,offset,buf); // Update Buddy preferences 1 - aim_writetlvlong(0xd6,pref1_set_flags,offset,buf); // Update Buddy preferences 1 - if (pref2_len) - aim_writetlv(0xd7,pref2_len,pref2_flags,offset,buf); // Update Buddy preferences 2 - if (pref2_set_len) - aim_writetlv(0xd8,pref2_set_len,pref2_set_flags,offset,buf);// Update Buddy preferences 2 - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + if (m_pref2_len) tlv_len += TLV_HEADER_SIZE + m_pref2_len; + if (m_pref2_set_len) tlv_len += TLV_HEADER_SIZE + m_pref2_set_len; + + aim_writeshort(tlv_len, offset, buf); // length of extra data + aim_writetlvlong(0xc9, m_pref1_flags, offset, buf); // Update Buddy preferences 1 + aim_writetlvlong(0xd6, m_pref1_set_flags, offset, buf); // Update Buddy preferences 1 + if (m_pref2_len) + aim_writetlv(0xd7, m_pref2_len, m_pref2_flags, offset, buf); // Update Buddy preferences 2 + if (m_pref2_set_len) + aim_writetlv(0xd8, m_pref2_set_len, m_pref2_set_flags, offset, buf); // Update Buddy preferences 2 + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_ssi_update(HANDLE hServerConn, unsigned short &seqno, bool start) { - unsigned short offset=0; + unsigned short offset = 0; char buf[SNAC_SIZE]; - aim_writesnac(0x13,start?0x11:0x12,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno)==0; + aim_writesnac(0x13, start ? 0x11 : 0x12, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno) == 0; } -int CAimProto::aim_keepalive(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_keepalive(HANDLE hServerConn, unsigned short &seqno) { - return aim_sendflap(hServerConn,0x05,4,"\x0\x0\x0\xEE",seqno); + return aim_sendflap(hServerConn, 0x05, 4, "\x0\x0\x0\xEE", seqno); } // used when requesting a regular file transfer int CAimProto::aim_send_file(HANDLE hServerConn, unsigned short &seqno, - unsigned long ip, unsigned short port, - bool force_proxy, file_transfer *ft) -{ + unsigned long ip, unsigned short port, + bool force_proxy, file_transfer *ft) +{ char msg_frag[2048]; - unsigned short frag_offset=0; + unsigned short frag_offset = 0; - aim_writeshort(0,frag_offset,msg_frag); // request type - aim_writegeneric(8,ft->icbm_cookie,frag_offset,msg_frag); // icbm cookie + aim_writeshort(0, frag_offset, msg_frag); // request type + aim_writegeneric(8, ft->icbm_cookie, frag_offset, msg_frag); // icbm cookie aim_writegeneric(AIM_CAPS_LENGTH, AIM_CAP_FILE_TRANSFER, - frag_offset, msg_frag); // uuid - aim_writetlvshort(0x0a,++ft->req_num,frag_offset,msg_frag); // request number -// aim_writetlvshort(0x12,2,frag_offset,msg_frag); // max protocol version + frag_offset, msg_frag); // uuid + aim_writetlvshort(0x0a, ++ft->req_num, frag_offset, msg_frag); // request number + + aim_writetlvlong(0x02, ip, frag_offset, msg_frag); // ip + aim_writetlvlong(0x16, ~ip, frag_offset, msg_frag); // ip check - aim_writetlvlong(0x02,ip,frag_offset,msg_frag); // ip - aim_writetlvlong(0x16,~ip,frag_offset,msg_frag); // ip check + aim_writetlvshort(0x05, port, frag_offset, msg_frag); // port + aim_writetlvshort(0x17, ~port, frag_offset, msg_frag); // port ip check - aim_writetlvshort(0x05,port,frag_offset,msg_frag); // port - aim_writetlvshort(0x17,~port,frag_offset,msg_frag); // port ip check - if (force_proxy) - aim_writetlv(0x10,0,0,frag_offset,msg_frag); // request proxy transfer + aim_writetlv(0x10, 0, 0, frag_offset, msg_frag); // request proxy transfer else - aim_writetlvlong(0x03,internal_ip,frag_offset,msg_frag); // ip + aim_writetlvlong(0x03, m_internal_ip, frag_offset, msg_frag); // ip - if (ft->req_num == 1) - { - if (ft->message) - { + if (ft->req_num == 1) { + if (ft->message) { aimString dscr(ft->message); const char* charset = dscr.isUnicode() ? "unicode-2-0" : "us-ascii"; @@ -579,12 +572,12 @@ int CAimProto::aim_send_file(HANDLE hServerConn, unsigned short &seqno, const char* desc_msg = dscr.getBuf(); const unsigned short desc_len = dscr.getSize(); - aim_writetlv(0x0e,2,"en",frag_offset,msg_frag); // language used by the data - aim_writetlv(0x0d,charset_len,charset,frag_offset,msg_frag);// charset used by the data - aim_writetlv(0x0c,desc_len,desc_msg,frag_offset,msg_frag); // invitaion text + aim_writetlv(0x0e, 2, "en", frag_offset, msg_frag); // language used by the data + aim_writetlv(0x0d, charset_len, charset, frag_offset, msg_frag);// charset used by the data + aim_writetlv(0x0c, desc_len, desc_msg, frag_offset, msg_frag); // invitaion text } - aim_writetlv(0x0f,0,0,frag_offset,msg_frag); // request host check + aim_writetlv(0x0f, 0, 0, frag_offset, msg_frag); // request host check const char* fname = get_fname(ft->file); const unsigned short fnlen = (unsigned short)mir_strlen(fname); @@ -592,263 +585,261 @@ int CAimProto::aim_send_file(HANDLE hServerConn, unsigned short &seqno, char* fblock = (char*)alloca(9 + fnlen); *(unsigned short*)&fblock[0] = _htons(ft->pfts.totalFiles > 1 ? 2 : 1); // single file transfer *(unsigned short*)&fblock[2] = _htons(ft->pfts.totalFiles); // number of files - *(unsigned long*) &fblock[4] = _htonl(ft->pfts.totalBytes); // total bytes in files + *(unsigned long*)&fblock[4] = _htonl(ft->pfts.totalBytes); // total bytes in files memcpy(&fblock[8], fname, fnlen + 1); const char* enc = is_utf(fname) ? "utf-8" : "us-ascii"; - aim_writetlv(0x2711,9+fnlen,fblock,frag_offset,msg_frag); // extra data, file names, size - aim_writetlv(0x2712,8,enc,frag_offset,msg_frag); // character set used by data + aim_writetlv(0x2711, 9 + fnlen, fblock, frag_offset, msg_frag); // extra data, file names, size + aim_writetlv(0x2712, 8, enc, frag_offset, msg_frag); // character set used by data // aim_writetlvlong64(0x2713,ft->pfts.totalBytes,frag_offset,msg_frag); // file length debugLogA("Attempting to Send a file to a buddy."); } - else - { - aim_writetlvshort(0x14,0x0a,frag_offset,msg_frag); // Counter proposal reason + else { + aim_writetlvshort(0x14, 0x0a, frag_offset, msg_frag); // Counter proposal reason } - unsigned short offset=0; - unsigned short sn_length=(unsigned short)mir_strlen(ft->sn); - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE*2+12+frag_offset+sn_length); - aim_writesnac(0x04,0x06,offset,buf); // msg to host - aim_writegeneric(8,ft->icbm_cookie,offset,buf); // icbm cookie - aim_writeshort(2,offset,buf); // icbm channel - aim_writechar((unsigned char)sn_length,offset,buf); // screen name length - aim_writegeneric(sn_length,ft->sn,offset,buf); // screen name - aim_writetlv(0x05,frag_offset,msg_frag,offset,buf); // icbm tags - aim_writetlv(0x03,0,0,offset,buf); // request ack + unsigned short offset = 0; + unsigned short sn_length = (unsigned short)mir_strlen(ft->sn); + char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 2 + 12 + frag_offset + sn_length); + aim_writesnac(0x04, 0x06, offset, buf); // msg to host + aim_writegeneric(8, ft->icbm_cookie, offset, buf); // icbm cookie + aim_writeshort(2, offset, buf); // icbm channel + aim_writechar((unsigned char)sn_length, offset, buf); // screen name length + aim_writegeneric(sn_length, ft->sn, offset, buf); // screen name + aim_writetlv(0x05, frag_offset, msg_frag, offset, buf); // icbm tags + aim_writetlv(0x03, 0, 0, offset, buf); // request ack char cip[20]; long_ip_to_char_ip(ip, cip); debugLogA("IP for Buddy to connect to: %s:%u", cip, port); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno)==0; + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno) == 0; } -int CAimProto::aim_file_ad(HANDLE hServerConn,unsigned short &seqno,char* sn, char* icbm_cookie, bool deny, unsigned short) -{ - unsigned short frag_offset=0; - char msg_frag[10+AIM_CAPS_LENGTH+TLV_HEADER_SIZE*2+6]; - aim_writeshort(deny ? 1 : 2,frag_offset,msg_frag); // icbm accept / deny - aim_writegeneric(8,icbm_cookie,frag_offset,msg_frag); // icbm cookie +int CAimProto::aim_file_ad(HANDLE hServerConn, unsigned short &seqno, char* sn, char* icbm_cookie, bool deny, unsigned short) +{ + unsigned short frag_offset = 0; + char msg_frag[10 + AIM_CAPS_LENGTH + TLV_HEADER_SIZE * 2 + 6]; + aim_writeshort(deny ? 1 : 2, frag_offset, msg_frag); // icbm accept / deny + aim_writegeneric(8, icbm_cookie, frag_offset, msg_frag); // icbm cookie aim_writegeneric(AIM_CAPS_LENGTH, - AIM_CAP_FILE_TRANSFER,frag_offset,msg_frag); // uuid + AIM_CAP_FILE_TRANSFER, frag_offset, msg_frag); // uuid // if (max_ver > 1) // aim_writetlvshort(0x12,2,frag_offset,msg_frag); // max protocol version - unsigned short sn_length=(unsigned short)mir_strlen(sn); - unsigned short offset=0; - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE+21+frag_offset+sn_length); - aim_writesnac(0x04,0x06,offset,buf); // msg to host - aim_writegeneric(8,icbm_cookie,offset,buf); // icbm cookie - aim_writeshort(2,offset,buf); // icbm channel - aim_writechar((unsigned char)sn_length,offset,buf); // screen name length - aim_writegeneric(sn_length,sn,offset,buf); // screen name - aim_writetlv(0x05,frag_offset,msg_frag,offset,buf); // icbm tags + unsigned short sn_length = (unsigned short)mir_strlen(sn); + unsigned short offset = 0; + char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE + 21 + frag_offset + sn_length); + aim_writesnac(0x04, 0x06, offset, buf); // msg to host + aim_writegeneric(8, icbm_cookie, offset, buf); // icbm cookie + aim_writeshort(2, offset, buf); // icbm channel + aim_writechar((unsigned char)sn_length, offset, buf); // screen name length + aim_writegeneric(sn_length, sn, offset, buf); // screen name + aim_writetlv(0x05, frag_offset, msg_frag, offset, buf); // icbm tags debugLogA("%s a file transfer.", deny ? "Denying" : "Accepting"); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno)==0; + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno) == 0; } -int CAimProto::aim_typing_notification(HANDLE hServerConn,unsigned short &seqno,char* sn,unsigned short type) +int CAimProto::aim_typing_notification(HANDLE hServerConn, unsigned short &seqno, char* sn, unsigned short type) { - unsigned short offset=0; - unsigned short sn_length=(unsigned short)mir_strlen(sn); - char* buf= (char*)alloca(SNAC_SIZE+sn_length+13); - aim_writesnac(0x04,0x14,offset,buf); - aim_writegeneric(8,"\0\0\0\0\0\0\0\0",offset,buf); // icbm cookie - aim_writeshort(1,offset,buf); // icbm channel - aim_writechar((unsigned char)sn_length,offset,buf); // screen name length - aim_writegeneric(sn_length,sn,offset,buf); // screen name - aim_writeshort(type,offset,buf); // typing event - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + unsigned short sn_length = (unsigned short)mir_strlen(sn); + char* buf = (char*)alloca(SNAC_SIZE + sn_length + 13); + aim_writesnac(0x04, 0x14, offset, buf); + aim_writegeneric(8, "\0\0\0\0\0\0\0\0", offset, buf); // icbm cookie + aim_writeshort(1, offset, buf); // icbm channel + aim_writechar((unsigned char)sn_length, offset, buf); // screen name length + aim_writegeneric(sn_length, sn, offset, buf); // screen name + aim_writeshort(type, offset, buf); // typing event + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_set_idle(HANDLE hServerConn,unsigned short &seqno,unsigned long seconds) +int CAimProto::aim_set_idle(HANDLE hServerConn, unsigned short &seqno, unsigned long seconds) { - unsigned short offset=0; - char buf[SNAC_SIZE+4]; - aim_writesnac(0x01,0x11,offset,buf); - aim_writelong(seconds,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + 4]; + aim_writesnac(0x01, 0x11, offset, buf); + aim_writelong(seconds, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_request_mail(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_request_mail(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+34]; - aim_writesnac(0x18,0x06,offset,buf); + unsigned short offset = 0; + char buf[SNAC_SIZE + 34]; + aim_writesnac(0x18, 0x06, offset, buf); aim_writegeneric(34, "\x00\x02" "\xb3\x80\x9a\xd8\x0d\xba\x11\xd5\x9f\x8a\x00\x60\xb0\xee\x06\x31" "\x5d\x5e\x17\x08\x55\xaa\x11\xd3\xb1\x43\x00\x60\xb0\xfb\x1e\xcb", - offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_activate_mail(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_activate_mail(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+17]; - aim_writesnac(0x18,0x16,offset,buf); - aim_writegeneric(17,"\x02\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00",offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + 17]; + aim_writesnac(0x18, 0x16, offset, buf); + aim_writegeneric(17, "\x02\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00", offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_request_avatar(HANDLE hServerConn,unsigned short &seqno, const char* sn, unsigned short bart_type, const char* hash, unsigned short hash_size) +int CAimProto::aim_request_avatar(HANDLE hServerConn, unsigned short &seqno, const char* sn, unsigned short bart_type, const char* hash, unsigned short hash_size) { - unsigned short offset=0; - unsigned char sn_length=(unsigned char)mir_strlen(sn); - char* buf= (char*)alloca(SNAC_SIZE+sn_length+hash_size+12); - aim_writesnac(0x10,0x06,offset,buf); - aim_writechar(sn_length,offset,buf); // screen name length - aim_writegeneric(sn_length,sn,offset,buf); // screen name - aim_writechar(1,offset,buf); // number of BART ID - aim_writebartid(bart_type,0,hash_size,hash,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + unsigned char sn_length = (unsigned char)mir_strlen(sn); + char* buf = (char*)alloca(SNAC_SIZE + sn_length + hash_size + 12); + aim_writesnac(0x10, 0x06, offset, buf); + aim_writechar(sn_length, offset, buf); // screen name length + aim_writegeneric(sn_length, sn, offset, buf); // screen name + aim_writechar(1, offset, buf); // number of BART ID + aim_writebartid(bart_type, 0, hash_size, hash, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_set_avatar_hash(HANDLE hServerConn, unsigned short &seqno, char flags, unsigned short bart_type, unsigned short &id, char size, const char* hash) { - unsigned short offset=0; - + unsigned short offset = 0; + char bart_type_txt[8]; ultoa(bart_type, bart_type_txt, 10); unsigned short bart_type_len = (unsigned short)mir_strlen(bart_type_txt); unsigned short req = 0x09; - if (id == 0) - { + if (id == 0) { id = get_random(); req = 0x08; } char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 2 + 20 + size + bart_type_len); - aim_writesnac(0x13,req,offset,buf, get_random()); // SSI Edit/Add - aim_writeshort(bart_type_len,offset,buf); // name length - aim_writegeneric(bart_type_len,bart_type_txt,offset,buf); // name - aim_writeshort(0,offset,buf); // group id - aim_writeshort(id,offset,buf); // buddy id - aim_writeshort(0x14,offset,buf); // buddy type: Buddy Icon - aim_writeshort(2+size+TLV_HEADER_SIZE,offset,buf); // length of extra data - - char* buf2 = (char*)alloca(2+size); + aim_writesnac(0x13, req, offset, buf, get_random()); // SSI Edit/Add + aim_writeshort(bart_type_len, offset, buf); // name length + aim_writegeneric(bart_type_len, bart_type_txt, offset, buf); // name + aim_writeshort(0, offset, buf); // group id + aim_writeshort(id, offset, buf); // buddy id + aim_writeshort(0x14, offset, buf); // buddy type: Buddy Icon + aim_writeshort(2 + size + TLV_HEADER_SIZE, offset, buf); // length of extra data + + char* buf2 = (char*)alloca(2 + size); buf2[0] = flags; buf2[1] = (char)size; memcpy(&buf2[2], hash, size); - aim_writetlv(0xd5, 2+size, buf2, offset, buf); // BART + aim_writetlv(0xd5, 2 + size, buf2, offset, buf); // BART - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_delete_avatar_hash(HANDLE hServerConn, unsigned short &seqno, char /*flags*/, unsigned short bart_type, unsigned short & id) { - unsigned short offset=0; + unsigned short offset = 0; if (id == 0) return -1; id = 0; - + char bart_type_txt[8]; ultoa(bart_type, bart_type_txt, 10); unsigned short bart_type_len = (unsigned short)mir_strlen(bart_type_txt); char* buf = (char*)alloca(SNAC_SIZE + 20 + bart_type_len); - aim_writesnac(0x13,0x0a,offset,buf, get_random()); // SSI Delete - aim_writeshort(bart_type_len,offset,buf); // name length - aim_writegeneric(bart_type_len,bart_type_txt,offset,buf); // name - aim_writeshort(0,offset,buf); // group id - aim_writeshort(id,offset,buf); // buddy id - aim_writeshort(0x14,offset,buf); // buddy type: Buddy Icon - aim_writeshort(0,offset,buf); // length of extra data + aim_writesnac(0x13, 0x0a, offset, buf, get_random()); // SSI Delete + aim_writeshort(bart_type_len, offset, buf); // name length + aim_writegeneric(bart_type_len, bart_type_txt, offset, buf); // name + aim_writeshort(0, offset, buf); // group id + aim_writeshort(id, offset, buf); // buddy id + aim_writeshort(0x14, offset, buf); // buddy type: Buddy Icon + aim_writeshort(0, offset, buf); // length of extra data - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_upload_avatar(HANDLE hServerConn, unsigned short &seqno, unsigned short bart_type, const char* avatar, unsigned short avatar_size) { - unsigned short offset=0; - char* buf=(char*)alloca(SNAC_SIZE+22+avatar_size); - aim_writesnac(0x10,0x02,offset,buf); - aim_writeshort(bart_type,offset,buf); // BART id - aim_writeshort(avatar_size,offset,buf); - aim_writegeneric(avatar_size,avatar,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char* buf = (char*)alloca(SNAC_SIZE + 22 + avatar_size); + aim_writesnac(0x10, 0x02, offset, buf); + aim_writeshort(bart_type, offset, buf); // BART id + aim_writeshort(avatar_size, offset, buf); + aim_writegeneric(avatar_size, avatar, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_search_by_email(HANDLE hServerConn,unsigned short &seqno, const char* email) +int CAimProto::aim_search_by_email(HANDLE hServerConn, unsigned short &seqno, const char* email) { - unsigned short offset=0; - char em_length=(char)mir_strlen(email); - char* buf= (char*)alloca(SNAC_SIZE+em_length); - aim_writesnac(0x0a,0x02,offset,buf); // Email search - aim_writegeneric(em_length,email,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char em_length = (char)mir_strlen(email); + char* buf = (char*)alloca(SNAC_SIZE + em_length); + aim_writesnac(0x0a, 0x02, offset, buf); // Email search + aim_writegeneric(em_length, email, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_chatnav_request_limits(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_chatnav_request_limits(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; + unsigned short offset = 0; char buf[SNAC_SIZE]; - aim_writesnac(0x0d,0x02,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno) ? -1 : 0; + aim_writesnac(0x0d, 0x02, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno) ? -1 : 0; } -int CAimProto::aim_chatnav_create(HANDLE hServerConn,unsigned short &seqno, char* room, unsigned short exchage) +int CAimProto::aim_chatnav_create(HANDLE hServerConn, unsigned short &seqno, char* room, unsigned short exchage) { //* Join Pseudo Room (Get's the info we need for the real connection) unsigned short room_len = (unsigned short)mir_strlen(room); - unsigned short offset=0; - char* buf=(char*)alloca(SNAC_SIZE+10+room_len+26); - aim_writesnac(0x0d,0x08,offset,buf); - aim_writeshort(exchage,offset,buf); // Exchange - aim_writechar(6,offset,buf); // Command Length - aim_writegeneric(6,"create",offset,buf); // Command - aim_writeshort(0xffff,offset,buf); // Last Instance - aim_writechar(1,offset,buf); // Detail - aim_writeshort(3,offset,buf); // Number of TLVs - aim_writetlv(0xd3,room_len,room,offset,buf); // Room Name - aim_writetlv(0xd6,8,"us-ascii",offset,buf); // Character Set - aim_writetlv(0xd7,2,"en",offset,buf); // Language Encoding + unsigned short offset = 0; + char* buf = (char*)alloca(SNAC_SIZE + 10 + room_len + 26); + aim_writesnac(0x0d, 0x08, offset, buf); + aim_writeshort(exchage, offset, buf); // Exchange + aim_writechar(6, offset, buf); // Command Length + aim_writegeneric(6, "create", offset, buf); // Command + aim_writeshort(0xffff, offset, buf); // Last Instance + aim_writechar(1, offset, buf); // Detail + aim_writeshort(3, offset, buf); // Number of TLVs + aim_writetlv(0xd3, room_len, room, offset, buf); // Room Name + aim_writetlv(0xd6, 8, "us-ascii", offset, buf); // Character Set + aim_writetlv(0xd7, 2, "en", offset, buf); // Language Encoding - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_chatnav_room_info(HANDLE hServerConn,unsigned short &seqno, char* chat_cookie, unsigned short exchange, unsigned short instance) -{ - unsigned short offset=0; - unsigned short chat_cookie_len = (unsigned short)mir_strlen(chat_cookie); - char* buf=(char*)alloca(SNAC_SIZE+7+chat_cookie_len); - aim_writesnac(0x0d,0x04,offset,buf); - aim_writeshort(exchange,offset,buf); // Exchange - aim_writechar((unsigned char)chat_cookie_len,offset,buf); // Chat Cookie Length - aim_writegeneric(chat_cookie_len,chat_cookie,offset,buf); // Chat Cookie - aim_writeshort(instance,offset,buf); // Last Instance - aim_writechar(1,offset,buf); // Detail - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); -} +int CAimProto::aim_chatnav_room_info(HANDLE hServerConn, unsigned short &seqno, char* chat_cookie, unsigned short exchange, unsigned short instance) +{ + unsigned short offset = 0; + unsigned short chat_cookie_len = (unsigned short)mir_strlen(chat_cookie); + char* buf = (char*)alloca(SNAC_SIZE + 7 + chat_cookie_len); + aim_writesnac(0x0d, 0x04, offset, buf); + aim_writeshort(exchange, offset, buf); // Exchange + aim_writechar((unsigned char)chat_cookie_len, offset, buf); // Chat Cookie Length + aim_writegeneric(chat_cookie_len, chat_cookie, offset, buf); // Chat Cookie + aim_writeshort(instance, offset, buf); // Last Instance + aim_writechar(1, offset, buf); // Detail + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); +} -int CAimProto::aim_chat_join_room(HANDLE hServerConn,unsigned short &seqno, char* chat_cookie, - unsigned short exchange, unsigned short instance, unsigned short id) +int CAimProto::aim_chat_join_room(HANDLE hServerConn, unsigned short &seqno, char* chat_cookie, + unsigned short exchange, unsigned short instance, unsigned short id) { - unsigned short offset=0; + unsigned short offset = 0; unsigned short cookie_len = (unsigned short)mir_strlen(chat_cookie); - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE*2+cookie_len+8); - aim_writesnac(0x01,0x04,offset,buf,id); - aim_writeshort(0x0e,offset,buf); // Service request for Chat + char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 2 + cookie_len + 8); + aim_writesnac(0x01, 0x04, offset, buf, id); + aim_writeshort(0x0e, offset, buf); // Service request for Chat - aim_writeshort(0x01,offset,buf); // Tag - aim_writeshort(cookie_len+5,offset,buf); // Length - aim_writeshort(exchange,offset,buf); // Value - Exchange - aim_writechar((unsigned char)cookie_len,offset,buf); // Value - Cookie Length - aim_writegeneric(cookie_len,chat_cookie,offset,buf); // Value - Cookie - aim_writeshort(instance,offset,buf); // Value - Instance + aim_writeshort(0x01, offset, buf); // Tag + aim_writeshort(cookie_len + 5, offset, buf); // Length + aim_writeshort(exchange, offset, buf); // Value - Exchange + aim_writechar((unsigned char)cookie_len, offset, buf); // Value - Cookie Length + aim_writegeneric(cookie_len, chat_cookie, offset, buf); // Value - Cookie + aim_writeshort(instance, offset, buf); // Value - Instance if (!getByte(AIM_KEY_DSSL, 0)) - aim_writetlv(0x8c,0,NULL,offset,buf); // Request SSL connection + aim_writetlv(0x8c, 0, NULL, offset, buf); // Request SSL connection - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } int CAimProto::aim_chat_send_message(HANDLE hServerConn, unsigned short &seqno, char *amsg) @@ -861,133 +852,133 @@ int CAimProto::aim_chat_send_message(HANDLE hServerConn, unsigned short &seqno, const char* msg = str.getBuf(); const unsigned short msg_len = str.getSize(); - unsigned short tlv_offset=0; - char* tlv_buf=(char*)alloca(TLV_HEADER_SIZE*4+chrset_len+msg_len+20); - aim_writetlv(0x04,13,"text/x-aolrtf",tlv_offset,tlv_buf); // Format - aim_writetlv(0x02,chrset_len,charset,tlv_offset,tlv_buf); // Character Set - aim_writetlv(0x03,2,"en",tlv_offset,tlv_buf); // Language Encoding - aim_writetlv(0x01,msg_len,msg,tlv_offset,tlv_buf); // Message + unsigned short tlv_offset = 0; + char* tlv_buf = (char*)alloca(TLV_HEADER_SIZE * 4 + chrset_len + msg_len + 20); + aim_writetlv(0x04, 13, "text/x-aolrtf", tlv_offset, tlv_buf); // Format + aim_writetlv(0x02, chrset_len, charset, tlv_offset, tlv_buf); // Character Set + aim_writetlv(0x03, 2, "en", tlv_offset, tlv_buf); // Language Encoding + aim_writetlv(0x01, msg_len, msg, tlv_offset, tlv_buf); // Message - unsigned short offset=0; - char* buf=(char*)alloca(SNAC_SIZE+8+2+TLV_HEADER_SIZE*3+tlv_offset); - aim_writesnac(0x0e,0x05,offset,buf); - aim_writegeneric(8,"\0\0\0\0\0\0\0\0",offset,buf); // Message Cookie (can be random) - aim_writeshort(0x03,offset,buf); // Message Channel (Always 3 for chat) - aim_writetlv(0x01,0,NULL,offset,buf); // Public/Whisper flag - aim_writetlv(0x06,0,NULL,offset,buf); // Enable Reflection flag - aim_writetlv(0x05,tlv_offset,tlv_buf,offset,buf); // Message Information TLV + unsigned short offset = 0; + char* buf = (char*)alloca(SNAC_SIZE + 8 + 2 + TLV_HEADER_SIZE * 3 + tlv_offset); + aim_writesnac(0x0e, 0x05, offset, buf); + aim_writegeneric(8, "\0\0\0\0\0\0\0\0", offset, buf); // Message Cookie (can be random) + aim_writeshort(0x03, offset, buf); // Message Channel (Always 3 for chat) + aim_writetlv(0x01, 0, NULL, offset, buf); // Public/Whisper flag + aim_writetlv(0x06, 0, NULL, offset, buf); // Enable Reflection flag + aim_writetlv(0x05, tlv_offset, tlv_buf, offset, buf); // Message Information TLV - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_chat_invite(HANDLE hServerConn,unsigned short &seqno, char* chat_cookie, unsigned short exchange, unsigned short instance, char* sn, char* msg) +int CAimProto::aim_chat_invite(HANDLE hServerConn, unsigned short &seqno, char* chat_cookie, unsigned short exchange, unsigned short instance, char* sn, char* msg) { - unsigned short offset=0; + unsigned short offset = 0; unsigned short chat_cookie_len = (unsigned short)mir_strlen(chat_cookie); unsigned short sn_len = (unsigned short)mir_strlen(sn); unsigned short msg_len = (unsigned short)mir_strlen(msg); - char* buf=(char*)alloca(SNAC_SIZE+64+chat_cookie_len+sn_len+msg_len); - aim_writesnac(0x04,0x06,offset,buf); - aim_writegeneric(8,"\0\0\0\0\0\0\0\0",offset,buf); // ICBM Cookie - aim_writeshort(2,offset,buf); // ICBM Channel - aim_writechar((unsigned char)sn_len,offset,buf); // Screen Name Length - aim_writegeneric(sn_len,sn,offset,buf); // Screen Name - - aim_writeshort(0x05,offset,buf); // Rendezvous Message Data TLV - aim_writeshort(49+msg_len+chat_cookie_len,offset,buf); // TLV size - - aim_writeshort(0,offset,buf); // Message Type (0) - Request - aim_writegeneric(8,"\0\0\0\0\0\0\0\0",offset,buf); // ICBM Cookie (same as above) - aim_writegeneric(16,AIM_CAP_CHAT,offset,buf); // Capability - - aim_writetlvshort(0x0a,1,offset,buf); // Sequence Number TLV - aim_writetlv(0x0f,0,NULL,offset,buf); // Request Host Caps Check TLV - aim_writetlv(0x0c,msg_len,msg,offset,buf); // Invitation Message TLV - - aim_writeshort(0x2711,offset,buf); // Capability TLV - aim_writeshort(chat_cookie_len+5,offset,buf); // Length - aim_writeshort(exchange,offset,buf); // Value - Exchange - aim_writechar((unsigned char)chat_cookie_len,offset,buf); // Value - Cookie Length - aim_writegeneric(chat_cookie_len,chat_cookie,offset,buf); // Value - Cookie - aim_writeshort(instance,offset,buf); // Value - Instance + char* buf = (char*)alloca(SNAC_SIZE + 64 + chat_cookie_len + sn_len + msg_len); + aim_writesnac(0x04, 0x06, offset, buf); + aim_writegeneric(8, "\0\0\0\0\0\0\0\0", offset, buf); // ICBM Cookie + aim_writeshort(2, offset, buf); // ICBM Channel + aim_writechar((unsigned char)sn_len, offset, buf); // Screen Name Length + aim_writegeneric(sn_len, sn, offset, buf); // Screen Name + + aim_writeshort(0x05, offset, buf); // Rendezvous Message Data TLV + aim_writeshort(49 + msg_len + chat_cookie_len, offset, buf); // TLV size + + aim_writeshort(0, offset, buf); // Message Type (0) - Request + aim_writegeneric(8, "\0\0\0\0\0\0\0\0", offset, buf); // ICBM Cookie (same as above) + aim_writegeneric(16, AIM_CAP_CHAT, offset, buf); // Capability + + aim_writetlvshort(0x0a, 1, offset, buf); // Sequence Number TLV + aim_writetlv(0x0f, 0, NULL, offset, buf); // Request Host Caps Check TLV + aim_writetlv(0x0c, msg_len, msg, offset, buf); // Invitation Message TLV + + aim_writeshort(0x2711, offset, buf); // Capability TLV + aim_writeshort(chat_cookie_len + 5, offset, buf); // Length + aim_writeshort(exchange, offset, buf); // Value - Exchange + aim_writechar((unsigned char)chat_cookie_len, offset, buf); // Value - Cookie Length + aim_writegeneric(chat_cookie_len, chat_cookie, offset, buf); // Value - Cookie + aim_writeshort(instance, offset, buf); // Value - Instance - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_chat_deny(HANDLE hServerConn,unsigned short &seqno,char* sn,char* icbm_cookie) -{ - unsigned short offset=0; - unsigned short sn_length=(unsigned short)mir_strlen(sn); - char* buf=(char*)alloca(SNAC_SIZE+20+sn_length); - aim_writesnac(0x04,0x0b,offset,buf); - aim_writegeneric(8,icbm_cookie,offset,buf); // ICBM Cookie - aim_writeshort(2,offset,buf); // Channel - aim_writechar((unsigned char)sn_length,offset,buf); // Screen Name length - aim_writegeneric(sn_length,sn,offset,buf); // Screen Name - aim_writeshort(3,offset,buf); // Error code - aim_writeshort(2,offset,buf); // Error code - aim_writeshort(1,offset,buf); // Error code - return aim_sendflap(hServerConn,0x02,offset,buf,seqno)==0; +int CAimProto::aim_chat_deny(HANDLE hServerConn, unsigned short &seqno, char* sn, char* icbm_cookie) +{ + unsigned short offset = 0; + unsigned short sn_length = (unsigned short)mir_strlen(sn); + char* buf = (char*)alloca(SNAC_SIZE + 20 + sn_length); + aim_writesnac(0x04, 0x0b, offset, buf); + aim_writegeneric(8, icbm_cookie, offset, buf); // ICBM Cookie + aim_writeshort(2, offset, buf); // Channel + aim_writechar((unsigned char)sn_length, offset, buf); // Screen Name length + aim_writegeneric(sn_length, sn, offset, buf); // Screen Name + aim_writeshort(3, offset, buf); // Error code + aim_writeshort(2, offset, buf); // Error code + aim_writeshort(1, offset, buf); // Error code + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno) == 0; } -int CAimProto::aim_admin_ready(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_admin_ready(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE*4]; - aim_writesnac(0x01,0x02,offset,buf); - aim_writefamily(AIM_SERVICE_GENERIC,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - aim_writefamily(AIM_SERVICE_ADMIN,offset,buf); - aim_writegeneric(4,AIM_TOOL_VERSION,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE * 4]; + aim_writesnac(0x01, 0x02, offset, buf); + aim_writefamily(AIM_SERVICE_GENERIC, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + aim_writefamily(AIM_SERVICE_ADMIN, offset, buf); + aim_writegeneric(4, AIM_TOOL_VERSION, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_admin_format_name(HANDLE hServerConn,unsigned short &seqno, const char* sn) +int CAimProto::aim_admin_format_name(HANDLE hServerConn, unsigned short &seqno, const char* sn) { - unsigned short offset=0; + unsigned short offset = 0; unsigned short sn_len = (unsigned short)mir_strlen(sn); - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE+sn_len); - aim_writesnac(0x07,0x04,offset,buf); - aim_writetlv(0x01,sn_len,sn,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE + sn_len); + aim_writesnac(0x07, 0x04, offset, buf); + aim_writetlv(0x01, sn_len, sn, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_admin_change_email(HANDLE hServerConn,unsigned short &seqno, const char* email) +int CAimProto::aim_admin_change_email(HANDLE hServerConn, unsigned short &seqno, const char* email) { - unsigned short offset=0; + unsigned short offset = 0; unsigned short email_len = (unsigned short)mir_strlen(email); - char* buf=(char*)alloca(SNAC_SIZE+TLV_HEADER_SIZE+email_len); - aim_writesnac(0x07,0x04,offset,buf); - aim_writetlv(0x11,email_len,email,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE + email_len); + aim_writesnac(0x07, 0x04, offset, buf); + aim_writetlv(0x11, email_len, email, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_admin_change_password(HANDLE hServerConn,unsigned short &seqno, const char* cur_pw, const char* new_pw) +int CAimProto::aim_admin_change_password(HANDLE hServerConn, unsigned short &seqno, const char* cur_pw, const char* new_pw) { - unsigned short offset=0; + unsigned short offset = 0; unsigned short cur_pw_len = (unsigned short)mir_strlen(cur_pw); unsigned short new_pw_len = (unsigned short)mir_strlen(new_pw); - char* buf=(char*)alloca(SNAC_SIZE+2*TLV_HEADER_SIZE+cur_pw_len+new_pw_len); - aim_writesnac(0x07,0x04,offset,buf); - aim_writetlv(0x02,new_pw_len,new_pw,offset,buf); - aim_writetlv(0x12,cur_pw_len,cur_pw,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + char* buf = (char*)alloca(SNAC_SIZE + 2 * TLV_HEADER_SIZE + cur_pw_len + new_pw_len); + aim_writesnac(0x07, 0x04, offset, buf); + aim_writetlv(0x02, new_pw_len, new_pw, offset, buf); + aim_writetlv(0x12, cur_pw_len, cur_pw, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_admin_request_info(HANDLE hServerConn,unsigned short &seqno, const unsigned short &type) +int CAimProto::aim_admin_request_info(HANDLE hServerConn, unsigned short &seqno, const unsigned short &type) { // types: 0x01 - nickname, 0x11 - email info, 0x13 - registration status - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE]; - aim_writesnac(0x07,0x02,offset,buf); - aim_writetlv(type,0,NULL,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE]; + aim_writesnac(0x07, 0x02, offset, buf); + aim_writetlv(type, 0, NULL, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } -int CAimProto::aim_admin_account_confirm(HANDLE hServerConn,unsigned short &seqno) +int CAimProto::aim_admin_account_confirm(HANDLE hServerConn, unsigned short &seqno) { - unsigned short offset=0; - char buf[SNAC_SIZE+TLV_HEADER_SIZE]; - aim_writesnac(0x07,0x06,offset,buf); - return aim_sendflap(hServerConn,0x02,offset,buf,seqno); + unsigned short offset = 0; + char buf[SNAC_SIZE + TLV_HEADER_SIZE]; + aim_writesnac(0x07, 0x06, offset, buf); + return aim_sendflap(hServerConn, 0x02, offset, buf, seqno); } diff --git a/protocols/AimOscar/src/connection.cpp b/protocols/AimOscar/src/connection.cpp index 1961da1dbc..0a09c6d86c 100644 --- a/protocols/AimOscar/src/connection.cpp +++ b/protocols/AimOscar/src/connection.cpp @@ -16,6 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" HANDLE CAimProto::aim_connect(const char* server, unsigned short port, bool use_ssl, const char* host) @@ -27,9 +28,9 @@ HANDLE CAimProto::aim_connect(const char* server, unsigned short port, bool use_ ncon.timeout = 6; ncon.flags = NLOCF_V2; debugLogA("%s:%u", server, port); - HANDLE con = (HANDLE) CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&ncon); + HANDLE con = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&ncon); if (con && use_ssl) { - NETLIBSSL ssl = {0}; + NETLIBSSL ssl = { 0 }; ssl.cbSize = sizeof(ssl); ssl.host = host; if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)con, (LPARAM)&ssl)) { @@ -41,14 +42,14 @@ HANDLE CAimProto::aim_connect(const char* server, unsigned short port, bool use_ } HANDLE CAimProto::aim_peer_connect(const char* ip, unsigned short port) -{ +{ NETLIBOPENCONNECTION ncon = { 0 }; ncon.cbSize = sizeof(ncon); ncon.flags = NLOCF_V2; ncon.szHost = ip; ncon.wPort = port; ncon.timeout = 3; - return (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibPeer, (LPARAM)&ncon); + return (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibPeer, (LPARAM)&ncon); } HANDLE CAimProto::aim_peer_connect(unsigned long ip, unsigned short port) @@ -64,15 +65,15 @@ void CAimProto::aim_connection_authorization(void) if (m_iDesiredStatus != ID_STATUS_OFFLINE) { char *password = getStringA(AIM_KEY_PW); if (password != NULL) { - mir_free(username); - username = getStringA(AIM_KEY_SN); - if (username != NULL) { - HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hServerConn, 2048 * 4); - NETLIBPACKETRECVER packetRecv = {0}; + mir_free(m_username); + m_username = getStringA(AIM_KEY_SN); + if (m_username != NULL) { + HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hServerConn, 2048 * 4); + NETLIBPACKETRECVER packetRecv = { 0 }; packetRecv.cbSize = sizeof(packetRecv); packetRecv.dwTimeout = 5000; for (;;) { - int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM) hServerPacketRecver, (LPARAM) & packetRecv); + int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)& packetRecv); if (recvResult == 0) { debugLogA("Connection Closed: No Error? during Connection Authorization"); break; @@ -82,24 +83,24 @@ void CAimProto::aim_connection_authorization(void) break; } else { - unsigned short flap_length=0; - for (;packetRecv.bytesUsed0) - { - unsigned short flap_length=0; - for (;packetRecv.bytesUsed 0) { + unsigned short flap_length = 0; + for (; packetRecv.bytesUsed < packetRecv.bytesAvailable; packetRecv.bytesUsed = flap_length) { if (!packetRecv.buffer) break; - FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed],packetRecv.bytesAvailable-packetRecv.bytesUsed); + FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed], packetRecv.bytesAvailable - packetRecv.bytesUsed); if (!flap.len()) break; - flap_length+=FLAP_SIZE+flap.len(); - if (flap.cmp(0x01)) - { - aim_send_cookie(hServerConn,seqno,COOKIE_LENGTH,COOKIE);//cookie challenge + flap_length += FLAP_SIZE + flap.len(); + if (flap.cmp(0x01)) { + aim_send_cookie(m_hServerConn, m_seqno, COOKIE_LENGTH, COOKIE);//cookie challenge mir_free(COOKIE); - COOKIE=NULL; - COOKIE_LENGTH=0; + COOKIE = NULL; + COOKIE_LENGTH = 0; } - else if (flap.cmp(0x02)) - { - SNAC snac(flap.val(),flap.snaclen()); - if (snac.cmp(0x0001)) - { - snac_supported_families(snac,hServerConn,seqno); - snac_supported_family_versions(snac,hServerConn,seqno); - snac_rate_limitations(snac,hServerConn,seqno); + else if (flap.cmp(0x02)) { + SNAC snac(flap.val(), flap.snaclen()); + if (snac.cmp(0x0001)) { + snac_supported_families(snac, m_hServerConn, m_seqno); + snac_supported_family_versions(snac, m_hServerConn, m_seqno); + snac_rate_limitations(snac, m_hServerConn, m_seqno); snac_service_redirect(snac); snac_self_info(snac); snac_error(snac); } - else if (snac.cmp(0x0002)) - { + else if (snac.cmp(0x0002)) { snac_received_info(snac); snac_error(snac); } - else if (snac.cmp(0x0003)) - { + else if (snac.cmp(0x0003)) { snac_user_online(snac); snac_user_offline(snac); snac_error(snac); } - else if (snac.cmp(0x0004)) - { - snac_icbm_limitations(snac,hServerConn,seqno); + else if (snac.cmp(0x0004)) { + snac_icbm_limitations(snac, m_hServerConn, m_seqno); snac_message_accepted(snac); - snac_received_message(snac,hServerConn,seqno); + snac_received_message(snac, m_hServerConn, m_seqno); snac_typing_notification(snac); snac_error(snac); snac_file_decline(snac); } - else if (snac.cmp(0x000A)) - { + else if (snac.cmp(0x000A)) { snac_email_search_results(snac); - /* + /* If there's no match (error 0x14), AIM will pop up a message. Since it's annoying and there's no other errors that'll get generated, I just assume leave this commented out. It's here @@ -228,15 +215,13 @@ void __cdecl CAimProto::aim_protocol_negotiation( void* ) */ //snac_error(snac); } - else if (snac.cmp(0x0013)) - { - snac_contact_list(snac,hServerConn,seqno); + else if (snac.cmp(0x0013)) { + snac_contact_list(snac, m_hServerConn, m_seqno); snac_list_modification_ack(snac); snac_error(snac); } } - else if (flap.cmp(0x04)) - { + else if (flap.cmp(0x04)) { ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_OTHERLOCATION); debugLogA("Connection Negotiation Thread Ending: Flap 0x04"); goto exit; @@ -246,67 +231,57 @@ void __cdecl CAimProto::aim_protocol_negotiation( void* ) } exit: - if (m_iStatus!=ID_STATUS_OFFLINE) broadcast_status(ID_STATUS_OFFLINE); - Netlib_CloseHandle(hServerPacketRecver); hServerPacketRecver=NULL; - Netlib_CloseHandle(hServerConn); hServerConn=NULL; + if (m_iStatus != ID_STATUS_OFFLINE) broadcast_status(ID_STATUS_OFFLINE); + Netlib_CloseHandle(hServerPacketRecver); hServerPacketRecver = NULL; + Netlib_CloseHandle(m_hServerConn); m_hServerConn = NULL; debugLogA("Connection Negotiation Thread Ending: End of Thread"); offline_contacts(); } -void __cdecl CAimProto::aim_mail_negotiation( void* ) +void __cdecl CAimProto::aim_mail_negotiation(void*) { - HANDLE hServerPacketRecver = (HANDLE) CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hMailConn, 2048 * 8); + HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hMailConn, 2048 * 8); - NETLIBPACKETRECVER packetRecv = {0}; + NETLIBPACKETRECVER packetRecv = { 0 }; packetRecv.cbSize = sizeof(packetRecv); - packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER*1000; - while(m_iStatus!=ID_STATUS_OFFLINE) - { + packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER * 1000; + while (m_iStatus != ID_STATUS_OFFLINE) { int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv); - if (recvResult == 0) - { + if (recvResult == 0) { break; } - if (recvResult == SOCKET_ERROR) - { - if (WSAGetLastError() == ERROR_TIMEOUT) - { - if (aim_keepalive(hMailConn, mail_seqno) < 0) + if (recvResult == SOCKET_ERROR) { + if (WSAGetLastError() == ERROR_TIMEOUT) { + if (aim_keepalive(m_hMailConn, m_mail_seqno) < 0) break; } else break; } - if (recvResult>0) - { - unsigned short flap_length=0; - for (;packetRecv.bytesUsed 0) { + unsigned short flap_length = 0; + for (; packetRecv.bytesUsed < packetRecv.bytesAvailable; packetRecv.bytesUsed = flap_length) { if (!packetRecv.buffer) break; - FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed],packetRecv.bytesAvailable-packetRecv.bytesUsed); + FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed], packetRecv.bytesAvailable - packetRecv.bytesUsed); if (!flap.len()) break; - flap_length+=FLAP_SIZE+flap.len(); - if (flap.cmp(0x01)) - { - aim_send_cookie(hMailConn,mail_seqno,MAIL_COOKIE_LENGTH,MAIL_COOKIE);//cookie challenge + flap_length += FLAP_SIZE + flap.len(); + if (flap.cmp(0x01)) { + aim_send_cookie(m_hMailConn, m_mail_seqno, MAIL_COOKIE_LENGTH, MAIL_COOKIE);//cookie challenge mir_free(MAIL_COOKIE); - MAIL_COOKIE=NULL; - MAIL_COOKIE_LENGTH=0; + MAIL_COOKIE = NULL; + MAIL_COOKIE_LENGTH = 0; } - else if (flap.cmp(0x02)) - { - SNAC snac(flap.val(),flap.snaclen()); - if (snac.cmp(0x0001)) - { - snac_supported_families(snac,hMailConn,mail_seqno); - snac_supported_family_versions(snac,hMailConn,mail_seqno); - snac_mail_rate_limitations(snac,hMailConn,mail_seqno); + else if (flap.cmp(0x02)) { + SNAC snac(flap.val(), flap.snaclen()); + if (snac.cmp(0x0001)) { + snac_supported_families(snac, m_hMailConn, m_mail_seqno); + snac_supported_family_versions(snac, m_hMailConn, m_mail_seqno); + snac_mail_rate_limitations(snac, m_hMailConn, m_mail_seqno); snac_error(snac); } - else if (snac.cmp(0x0018)) - { + else if (snac.cmp(0x0018)) { snac_mail_response(snac); } } @@ -319,56 +294,49 @@ void __cdecl CAimProto::aim_mail_negotiation( void* ) exit: debugLogA("Mail Server Connection has ended"); Netlib_CloseHandle(hServerPacketRecver); - Netlib_CloseHandle(hMailConn); - hMailConn=NULL; + Netlib_CloseHandle(m_hMailConn); + m_hMailConn = NULL; } -void __cdecl CAimProto::aim_avatar_negotiation( void* ) +void __cdecl CAimProto::aim_avatar_negotiation(void*) { - HANDLE hServerPacketRecver = (HANDLE) CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hAvatarConn, 2048 * 8); + HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hAvatarConn, 2048 * 8); - NETLIBPACKETRECVER packetRecv = {0}; + NETLIBPACKETRECVER packetRecv = { 0 }; packetRecv.cbSize = sizeof(packetRecv); packetRecv.dwTimeout = 300000;//5 minutes connected - for (;;) - { - int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM) hServerPacketRecver, (LPARAM) & packetRecv); + for (;;) { + int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)& packetRecv); if (recvResult == 0) break; if (recvResult == SOCKET_ERROR) break; - if (recvResult > 0) - { - unsigned short flap_length=0; - for (; packetRecv.bytesUsed < packetRecv.bytesAvailable; packetRecv.bytesUsed = flap_length) - { + if (recvResult > 0) { + unsigned short flap_length = 0; + for (; packetRecv.bytesUsed < packetRecv.bytesAvailable; packetRecv.bytesUsed = flap_length) { if (!packetRecv.buffer) break; - FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed],packetRecv.bytesAvailable-packetRecv.bytesUsed); + FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed], packetRecv.bytesAvailable - packetRecv.bytesUsed); if (!flap.len()) break; flap_length += FLAP_SIZE + flap.len(); - if (flap.cmp(0x01)) - { - aim_send_cookie(hAvatarConn, avatar_seqno, AVATAR_COOKIE_LENGTH, AVATAR_COOKIE);//cookie challenge + if (flap.cmp(0x01)) { + aim_send_cookie(m_hAvatarConn, m_avatar_seqno, AVATAR_COOKIE_LENGTH, AVATAR_COOKIE); // cookie challenge mir_free(AVATAR_COOKIE); AVATAR_COOKIE = NULL; AVATAR_COOKIE_LENGTH = 0; } - else if (flap.cmp(0x02)) - { + else if (flap.cmp(0x02)) { SNAC snac(flap.val(), flap.snaclen()); - if (snac.cmp(0x0001)) - { - snac_supported_families(snac, hAvatarConn, avatar_seqno); - snac_supported_family_versions(snac, hAvatarConn, avatar_seqno); - snac_avatar_rate_limitations(snac, hAvatarConn, avatar_seqno); + if (snac.cmp(0x0001)) { + snac_supported_families(snac, m_hAvatarConn, m_avatar_seqno); + snac_supported_family_versions(snac, m_hAvatarConn, m_avatar_seqno); + snac_avatar_rate_limitations(snac, m_hAvatarConn, m_avatar_seqno); snac_error(snac); } - if (snac.cmp(0x0010)) - { + if (snac.cmp(0x0010)) { snac_retrieve_avatar(snac); snac_upload_reply_avatar(snac); } @@ -381,73 +349,64 @@ void __cdecl CAimProto::aim_avatar_negotiation( void* ) exit: Netlib_CloseHandle(hServerPacketRecver); - Netlib_CloseHandle(hAvatarConn); - hAvatarConn=NULL; - ResetEvent(hAvatarEvent); + Netlib_CloseHandle(m_hAvatarConn); + m_hAvatarConn = NULL; + ResetEvent(m_hAvatarEvent); debugLogA("Avatar Server Connection has ended"); } -void __cdecl CAimProto::aim_chatnav_negotiation( void* ) +void __cdecl CAimProto::aim_chatnav_negotiation(void*) { unsigned idle_chat = 0; - HANDLE hServerPacketRecver = (HANDLE) CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hChatNavConn, 2048 * 8); + HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hChatNavConn, 2048 * 8); - NETLIBPACKETRECVER packetRecv = {0}; + NETLIBPACKETRECVER packetRecv = { 0 }; packetRecv.cbSize = sizeof(packetRecv); - packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER*1000; - for (;;) - { - int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM) hServerPacketRecver, (LPARAM)&packetRecv); + packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER * 1000; + for (;;) { + int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv); if (recvResult == 0) break; - if (recvResult == SOCKET_ERROR) - { - if (WSAGetLastError() == ERROR_TIMEOUT) - { - if (chat_rooms.getCount()) + if (recvResult == SOCKET_ERROR) { + if (WSAGetLastError() == ERROR_TIMEOUT) { + if (m_chat_rooms.getCount()) idle_chat = 0; else if (++idle_chat >= 6) break; - if (aim_keepalive(hChatNavConn, chatnav_seqno) < 0) + if (aim_keepalive(m_hChatNavConn, m_chatnav_seqno) < 0) break; } else break; } - if (recvResult>0) - { - unsigned short flap_length=0; - for (;packetRecv.bytesUsed 0) { + unsigned short flap_length = 0; + for (; packetRecv.bytesUsed < packetRecv.bytesAvailable; packetRecv.bytesUsed = flap_length) { if (!packetRecv.buffer) break; - FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed],packetRecv.bytesAvailable-packetRecv.bytesUsed); + FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed], packetRecv.bytesAvailable - packetRecv.bytesUsed); if (!flap.len()) break; - flap_length+=FLAP_SIZE+flap.len(); - if (flap.cmp(0x01)) - { - aim_send_cookie(hChatNavConn,chatnav_seqno,CHATNAV_COOKIE_LENGTH,CHATNAV_COOKIE);//cookie challenge + flap_length += FLAP_SIZE + flap.len(); + if (flap.cmp(0x01)) { + aim_send_cookie(m_hChatNavConn, m_chatnav_seqno, CHATNAV_COOKIE_LENGTH, CHATNAV_COOKIE);//cookie challenge mir_free(CHATNAV_COOKIE); - CHATNAV_COOKIE=NULL; - CHATNAV_COOKIE_LENGTH=0; + CHATNAV_COOKIE = NULL; + CHATNAV_COOKIE_LENGTH = 0; } - else if (flap.cmp(0x02)) - { - SNAC snac(flap.val(),flap.snaclen()); - if (snac.cmp(0x0001)) - { - snac_supported_families(snac,hChatNavConn,chatnav_seqno); - snac_supported_family_versions(snac,hChatNavConn,chatnav_seqno); - snac_chatnav_rate_limitations(snac,hChatNavConn,chatnav_seqno); + else if (flap.cmp(0x02)) { + SNAC snac(flap.val(), flap.snaclen()); + if (snac.cmp(0x0001)) { + snac_supported_families(snac, m_hChatNavConn, m_chatnav_seqno); + snac_supported_family_versions(snac, m_hChatNavConn, m_chatnav_seqno); + snac_chatnav_rate_limitations(snac, m_hChatNavConn, m_chatnav_seqno); snac_error(snac); } - if (snac.cmp(0x000D)) - { - snac_chatnav_info_response(snac,hChatNavConn,chatnav_seqno); + if (snac.cmp(0x000D)) { + snac_chatnav_info_response(snac, m_hChatNavConn, m_chatnav_seqno); snac_error(snac); } } @@ -459,30 +418,27 @@ void __cdecl CAimProto::aim_chatnav_negotiation( void* ) exit: Netlib_CloseHandle(hServerPacketRecver); - Netlib_CloseHandle(hChatNavConn); - hChatNavConn=NULL; - ResetEvent(hChatNavEvent); + Netlib_CloseHandle(m_hChatNavConn); + m_hChatNavConn = NULL; + ResetEvent(m_hChatNavEvent); debugLogA("Chat Navigation Server Connection has ended"); } -void __cdecl CAimProto::aim_chat_negotiation( void* param ) +void __cdecl CAimProto::aim_chat_negotiation(void* param) { chat_list_item *item = (chat_list_item*)param; HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)item->hconn, 2048 * 8); - NETLIBPACKETRECVER packetRecv = {0}; + NETLIBPACKETRECVER packetRecv = { 0 }; packetRecv.cbSize = sizeof(packetRecv); - packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER*1000; - for (;;) - { + packetRecv.dwTimeout = DEFAULT_KEEPALIVE_TIMER * 1000; + for (;;) { int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv); if (recvResult == 0) break; - if (recvResult == SOCKET_ERROR) - { - if (WSAGetLastError() == ERROR_TIMEOUT) - { + if (recvResult == SOCKET_ERROR) { + if (WSAGetLastError() == ERROR_TIMEOUT) { if (aim_keepalive(item->hconn, item->seqno) < 0) break; } @@ -490,37 +446,31 @@ void __cdecl CAimProto::aim_chat_negotiation( void* param ) break; } - if (recvResult>0) - { - unsigned short flap_length=0; - for (;packetRecv.bytesUsed 0) { + unsigned short flap_length = 0; + for (; packetRecv.bytesUsed < packetRecv.bytesAvailable; packetRecv.bytesUsed = flap_length) { if (!packetRecv.buffer) break; - FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed],packetRecv.bytesAvailable-packetRecv.bytesUsed); + FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed], packetRecv.bytesAvailable - packetRecv.bytesUsed); if (!flap.len()) break; - flap_length+=FLAP_SIZE+flap.len(); - if (flap.cmp(0x01)) - { - aim_send_cookie(item->hconn,item->seqno,item->CHAT_COOKIE_LENGTH,item->CHAT_COOKIE);//cookie challenge + flap_length += FLAP_SIZE + flap.len(); + if (flap.cmp(0x01)) { + aim_send_cookie(item->hconn, item->seqno, item->CHAT_COOKIE_LENGTH, item->CHAT_COOKIE);//cookie challenge mir_free(item->CHAT_COOKIE); - item->CHAT_COOKIE=NULL; - item->CHAT_COOKIE_LENGTH=0; + item->CHAT_COOKIE = NULL; + item->CHAT_COOKIE_LENGTH = 0; } - else if (flap.cmp(0x02)) - { - SNAC snac(flap.val(),flap.snaclen()); - if (snac.cmp(0x0001)) - { - snac_supported_families(snac,item->hconn,item->seqno); - snac_supported_family_versions(snac,item->hconn,item->seqno); - snac_chat_rate_limitations(snac,item->hconn,item->seqno); + else if (flap.cmp(0x02)) { + SNAC snac(flap.val(), flap.snaclen()); + if (snac.cmp(0x0001)) { + snac_supported_families(snac, item->hconn, item->seqno); + snac_supported_family_versions(snac, item->hconn, item->seqno); + snac_chat_rate_limitations(snac, item->hconn, item->seqno); snac_error(snac); } - if (snac.cmp(0x000E)) - { + if (snac.cmp(0x000E)) { snac_chat_received_message(snac, item); snac_chat_joined_left_users(snac, item); snac_error(snac); @@ -540,52 +490,45 @@ exit: debugLogA("Chat Server Connection has ended"); } -void __cdecl CAimProto::aim_admin_negotiation( void* ) +void __cdecl CAimProto::aim_admin_negotiation(void*) { - HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hAdminConn, 2048 * 8); + HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)m_hAdminConn, 2048 * 8); - NETLIBPACKETRECVER packetRecv = {0}; + NETLIBPACKETRECVER packetRecv = { 0 }; packetRecv.cbSize = sizeof(packetRecv); packetRecv.dwTimeout = 300000;//5 minutes connected - for (;;) - { - int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM) hServerPacketRecver, (LPARAM) & packetRecv); + for (;;) { + int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)& packetRecv); if (recvResult == 0) break; if (recvResult == SOCKET_ERROR) break; - if (recvResult>0) - { - unsigned short flap_length=0; - for (;packetRecv.bytesUsed 0) { + unsigned short flap_length = 0; + for (; packetRecv.bytesUsed < packetRecv.bytesAvailable; packetRecv.bytesUsed = flap_length) { if (!packetRecv.buffer) break; - FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed],packetRecv.bytesAvailable-packetRecv.bytesUsed); + FLAP flap((char*)&packetRecv.buffer[packetRecv.bytesUsed], packetRecv.bytesAvailable - packetRecv.bytesUsed); if (!flap.len()) break; - flap_length+=FLAP_SIZE+flap.len(); - if (flap.cmp(0x01)) - { - aim_send_cookie(hAdminConn,admin_seqno,ADMIN_COOKIE_LENGTH,ADMIN_COOKIE);//cookie challenge + flap_length += FLAP_SIZE + flap.len(); + if (flap.cmp(0x01)) { + aim_send_cookie(m_hAdminConn, m_admin_seqno, ADMIN_COOKIE_LENGTH, ADMIN_COOKIE);//cookie challenge mir_free(ADMIN_COOKIE); - ADMIN_COOKIE=NULL; - ADMIN_COOKIE_LENGTH=0; + ADMIN_COOKIE = NULL; + ADMIN_COOKIE_LENGTH = 0; } - else if (flap.cmp(0x02)) - { - SNAC snac(flap.val(),flap.snaclen()); - if (snac.cmp(0x0001)) - { - snac_supported_families(snac,hAdminConn,admin_seqno); - snac_supported_family_versions(snac,hAdminConn,admin_seqno); - snac_admin_rate_limitations(snac,hAdminConn,admin_seqno); + else if (flap.cmp(0x02)) { + SNAC snac(flap.val(), flap.snaclen()); + if (snac.cmp(0x0001)) { + snac_supported_families(snac, m_hAdminConn, m_admin_seqno); + snac_supported_family_versions(snac, m_hAdminConn, m_admin_seqno); + snac_admin_rate_limitations(snac, m_hAdminConn, m_admin_seqno); snac_error(snac); } - if (snac.cmp(0x0007)) - { + if (snac.cmp(0x0007)) { snac_admin_account_infomod(snac); snac_admin_account_confirm(snac); snac_error(snac); @@ -599,8 +542,8 @@ void __cdecl CAimProto::aim_admin_negotiation( void* ) exit: Netlib_CloseHandle(hServerPacketRecver); - Netlib_CloseHandle(hAdminConn); - hAdminConn=NULL; - ResetEvent(hAdminEvent); + Netlib_CloseHandle(m_hAdminConn); + m_hAdminConn = NULL; + ResetEvent(m_hAdminEvent); debugLogA("Admin Server Connection has ended"); } diff --git a/protocols/AimOscar/src/conv.cpp b/protocols/AimOscar/src/conv.cpp index 7f6d6f1a3e..f114c52311 100644 --- a/protocols/AimOscar/src/conv.cpp +++ b/protocols/AimOscar/src/conv.cpp @@ -16,11 +16,12 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" #pragma warning( disable: 4706 ) -char* process_status_msg (const char *str, const char* sn) +char* process_status_msg(const char *str, const char* sn) { const char *src = str; size_t size = mir_strlen(src) + 1; @@ -28,18 +29,15 @@ char* process_status_msg (const char *str, const char* sn) char* dest = res; size_t len = mir_strlen(sn); - for (; *src; ++src) - { - if (src[0] == '\n' && (src == str || src[-1] != '\r')) - { + for (; *src; ++src) { + if (src[0] == '\n' && (src == str || src[-1] != '\r')) { int off = dest - res; res = (char*)mir_realloc(res, ++size); dest = res + off; *(dest++) = '\r'; *(dest++) = *src; } - else if (src[0] == '%' && src[1] == 'n') - { + else if (src[0] == '%' && src[1] == 'n') { int off = dest - res; res = (char*)mir_realloc(res, size + len); dest = res + off; @@ -48,26 +46,23 @@ char* process_status_msg (const char *str, const char* sn) dest += len; ++src; } - else if (src[0] == '%' && src[1] == 'd') - { + else if (src[0] == '%' && src[1] == 'd') { int off = dest - res; res = (char*)mir_realloc(res, size + 20); dest = res + off; size += 20; - dest += GetDateFormatA(LOCALE_USER_DEFAULT, 0, NULL, NULL, dest, 20)-1; + dest += GetDateFormatA(LOCALE_USER_DEFAULT, 0, NULL, NULL, dest, 20) - 1; ++src; } - else if (src[0] == '%' && src[1] == 't') - { + else if (src[0] == '%' && src[1] == 't') { int off = dest - res; res = (char*)mir_realloc(res, size + 20); dest = res + off; size += 20; - dest += GetTimeFormatA(LOCALE_USER_DEFAULT, 0, NULL, NULL, dest, 20)-1; + dest += GetTimeFormatA(LOCALE_USER_DEFAULT, 0, NULL, NULL, dest, 20) - 1; ++src; } - else - *(dest++) = *src; + else *(dest++) = *src; } *dest = '\0'; return res; @@ -77,28 +72,22 @@ char* process_status_msg (const char *str, const char* sn) void html_decode(char* str) { char *p, *q; -// char *rstr = (char*)mir_alloc(mir_strlen(str)*2); if (str == NULL) return; - for ( p=q=str; *p!='\0'; p++,q++ ) - { - if ( *p == '&' ) - { - if ( !strnicmp( p, "&", 5 )) { *q = '&'; p += 4; } - else if ( !strnicmp( p, "'", 6 )) { *q = '\''; p += 5; } - else if ( !strnicmp( p, ">", 4 )) { *q = '>'; p += 3; } - else if ( !strnicmp( p, "<", 4 )) { *q = '<'; p += 3; } - else if ( !strnicmp( p, """, 6 )) { *q = '"'; p += 5; } - else if ( *(p+1) == '#' ) - { - char* s = strchr(p, ';'); - if (s) - { - wchar_t t[2] = { (wchar_t)atoi(p+2), 0 }; + for (p = q = str; *p != '\0'; p++, q++) { + if (*p == '&') { + if (!strnicmp(p, "&", 5)) { *q = '&'; p += 4; } + else if (!strnicmp(p, "'", 6)) { *q = '\''; p += 5; } + else if (!strnicmp(p, ">", 4)) { *q = '>'; p += 3; } + else if (!strnicmp(p, "<", 4)) { *q = '<'; p += 3; } + else if (!strnicmp(p, """, 6)) { *q = '"'; p += 5; } + else if (*(p + 1) == '#') { + char *s = strchr(p, ';'); + if (s) { + wchar_t t[2] = { (wchar_t)atoi(p + 2), 0 }; char *t1 = mir_utf8encodeW(t); - if (t1 && *t1) - { + if (t1 && *t1) { mir_strcpy(q, t1); q += mir_strlen(t1) - 1; } @@ -106,47 +95,24 @@ void html_decode(char* str) p = s; } else - *q = *p; + *q = *p; } - else { *q = *p; } - } - else if ( *p == '<' ) - { - if ( !strnicmp( p, "

", 3 )) { mir_strcpy(q, "\r\n\r\n"); q += 3; p += 2; } - else if ( !strnicmp( p, "

", 4 )) { mir_strcpy(q, "\r\n\r\n"); q += 3; p += 3; } - else if ( !strnicmp( p, "
", 4 )) { mir_strcpy(q, "\r\n"); ++q; p += 3; } - else if ( !strnicmp( p, "
", 6 )) { mir_strcpy(q, "\r\n"); ++q; p += 5; } - else if ( !strnicmp( p, "
", 4 )) { mir_strcpy(q, "\r\n"); ++q; p += 3; } - else if ( !strnicmp( p, "
", 6 )) { mir_strcpy(q, "\r\n"); ++q; p += 5; } -/* - else if ( !strnicmp( p, "", 3 )) { mir_strcpy(q, "[b]"); q += 2; p += 2; } - else if ( !strnicmp( p, "", 4 )) { mir_strcpy(q, "[/b]"); q += 3; p += 3; } - else if ( !strnicmp( p, "", 3 )) { mir_strcpy(q, "[u]"); q += 2; p += 2; } - else if ( !strnicmp( p, "", 4 )) { mir_strcpy(q, "[/u]"); q += 3; p += 3; } - else if ( !strnicmp( p, "", 3 )) { mir_strcpy(q, "[i]"); q += 2; p += 2; } - else if ( !strnicmp( p, "", 4 )) { mir_strcpy(q, "[/i]"); q += 3; p += 3; } - else if ( !strnicmp( p, "", 3 )) { mir_strcpy(q, "[s]"); q += 2; p += 2; } - else if ( !strnicmp( p, "", 4 )) { mir_strcpy(q, "[/s]"); q += 3; p += 3; } - else if ( !strnicmp( p, "'); - - mir_strcpy(q, "[url"); q += 4; p += 7; - while (*p != '>' && *p) *(q++) = *(p++); - *q = ']'; --p; - } -*/ - else { + else { *q = *p; } + } + else if (*p == '<') { + if (!strnicmp(p, "

", 3)) { mir_strcpy(q, "\r\n\r\n"); q += 3; p += 2; } + else if (!strnicmp(p, "

", 4)) { mir_strcpy(q, "\r\n\r\n"); q += 3; p += 3; } + else if (!strnicmp(p, "
", 4)) { mir_strcpy(q, "\r\n"); ++q; p += 3; } + else if (!strnicmp(p, "
", 6)) { mir_strcpy(q, "\r\n"); ++q; p += 5; } + else if (!strnicmp(p, "
", 4)) { mir_strcpy(q, "\r\n"); ++q; p += 3; } + else if (!strnicmp(p, "
", 6)) { mir_strcpy(q, "\r\n"); ++q; p += 5; } + else { char *l = strchr(p, '>'); - if (l) { p = l; --q; } else *q = *p; + if (l) { p = l; --q; } + else *q = *p; } } - else - *q = *p; + else *q = *p; } *q = '\0'; } @@ -154,39 +120,34 @@ void html_decode(char* str) char* html_encode(const char* str) { - char* s, *q; + char *s, *q; const char *p; int c; if (str == NULL) return NULL; - for ( c=0, p=str; *p!='\0'; p++ ) - { - switch ( *p ) - { - case '&' : c += 5; break; + for (c = 0, p = str; *p != '\0'; p++) { + switch (*p) { + case '&': c += 5; break; case '\'': c += 6; break; - case '>' : c += 4; break; - case '<' : c += 4; break; - case '"' : c += 6; break; + case '>': c += 4; break; + case '<': c += 4; break; + case '"': c += 6; break; case '\n': c += 4; break; default: c++; break; } } - s = (char*)mir_alloc(c + 27); + s = (char*)mir_alloc(c + 27); mir_strcpy(s, ""); - for ( p=str,q=s+12; *p!='\0'; p++ ) - { - switch ( *p ) - { - case '&' : memcpy( q, "&", 5 ); q += 5; break; -// case '\'': memcpy( q, "'", 6 ); q += 6; break; - case '>' : memcpy( q, ">", 4 ); q += 4; break; - case '<' : memcpy( q, "<", 4 ); q += 4; break; - case '"' : memcpy( q, """, 6 ); q += 6; break; + for (p = str, q = s + 12; *p != '\0'; p++) { + switch (*p) { + case '&': memcpy(q, "&", 5); q += 5; break; + case '>': memcpy(q, ">", 4); q += 4; break; + case '<': memcpy(q, "<", 4); q += 4; break; + case '"': memcpy(q, """, 6); q += 6; break; case '\r': break; - case '\n': memcpy( q, "
", 4 ); q += 4; break; + case '\n': memcpy(q, "
", 4); q += 4; break; default: *q = *p; ++q; break; } } @@ -201,283 +162,226 @@ char* html_to_bbcodes(char *src) char *ptrl; char *rptr; char* dest = mir_strdup(src); - while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) - { + while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; - *(ptr+1) = 'b'; - *(ptr+2) = ']'; - if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) - { + *(ptr + 1) = 'b'; + *(ptr + 2) = ']'; + if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; - *(ptr+2) = 'b'; - *(ptr+3) = ']'; + *(ptr + 2) = 'b'; + *(ptr + 3) = ']'; } - else - { - dest=(char*)mir_realloc(dest,mir_strlen(dest)+6); - memcpy(&dest[mir_strlen(dest)],"[/b]",5); + else { + dest = (char*)mir_realloc(dest, mir_strlen(dest) + 6); + memcpy(&dest[mir_strlen(dest)], "[/b]", 5); } } - while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) - { - *ptr = '['; - *(ptr+1) = 'i'; - *(ptr+2) = ']'; - if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) - { + while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { + *ptr = '['; + *(ptr + 1) = 'i'; + *(ptr + 2) = ']'; + if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; - *(ptr+2) = 'i'; - *(ptr+3) = ']'; + *(ptr + 2) = 'i'; + *(ptr + 3) = ']'; } - else - { - dest=(char*)mir_realloc(dest,mir_strlen(dest)+6); - memcpy(&dest[mir_strlen(dest)],"[/i]",5); + else { + dest = (char*)mir_realloc(dest, mir_strlen(dest) + 6); + memcpy(&dest[mir_strlen(dest)], "[/i]", 5); } } - while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) - { + while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; - *(ptr+1) = 'u'; - *(ptr+2) = ']'; - if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) - { + *(ptr + 1) = 'u'; + *(ptr + 2) = ']'; + if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; - *(ptr+2) = 'u'; - *(ptr+3) = ']'; + *(ptr + 2) = 'u'; + *(ptr + 3) = ']'; } - else - { - dest=(char*)mir_realloc(dest,mir_strlen(dest)+6); - memcpy(&dest[mir_strlen(dest)],"[/u]",5); + else { + dest = (char*)mir_realloc(dest, mir_strlen(dest) + 6); + memcpy(&dest[mir_strlen(dest)], "[/u]", 5); } } - while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) - { + while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; - *(ptr+1) = 's'; - *(ptr+2) = ']'; - if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) - { + *(ptr + 1) = 's'; + *(ptr + 2) = ']'; + if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; - *(ptr+2) = 's'; - *(ptr+3) = ']'; + *(ptr + 2) = 's'; + *(ptr + 3) = ']'; } - else - { - dest=(char*)mir_realloc(dest,mir_strlen(dest)+6); - memcpy(&dest[mir_strlen(dest)],"[/s]",5); + else { + dest = (char*)mir_realloc(dest, mir_strlen(dest) + 6); + memcpy(&dest[mir_strlen(dest)], "[/s]", 5); } } rptr = dest; - while (ptr = strstr(rptr,"
"))) - { - ptr-=1; - memmove(ptr, ptr+1, mir_strlen(ptr+1) + 1); - *(ptr)=']'; - ptrl-=1; - char* s1 = strstr(ptrl,""))) { + ptr -= 1; + memmove(ptr, ptr + 1, mir_strlen(ptr + 1) + 1); + *(ptr) = ']'; + ptrl -= 1; + char* s1 = strstr(ptrl, ""))) - { - ptr-=1; - memmove(ptr, ptr+1, mir_strlen(ptr+1) + 1); - *(ptr)=']'; - ptrl-=1; - char* s1 = strstr(ptrl,""))) { + ptr -= 1; + memmove(ptr, ptr + 1, mir_strlen(ptr + 1) + 1); + *(ptr) = ']'; + ptrl -= 1; + char* s1 = strstr(ptrl, ""))) - { - memmove(ptrl+7,ptr,mir_strlen(ptr)+1); - *(ptrl+7)=']'; - ptr=ptrl+7; - char* s1 = strstr(ptr,""))) { + memmove(ptrl + 7, ptr, mir_strlen(ptr) + 1); + *(ptrl + 7) = ']'; + ptr = ptrl + 7; + char* s1 = strstr(ptr, ""))) - { - memmove(ptrl+7,ptr,mir_strlen(ptr)+1); - *(ptrl+7)=']'; - ptr=ptrl+7; - char* s1 = strstr(ptr,""))) { + memmove(ptrl + 7, ptr, mir_strlen(ptr) + 1); + *(ptrl + 7) = ']'; + ptr = ptrl + 7; + char* s1 = strstr(ptr, ""))) - { - *(ptr)=']'; - if ((ptrl = strstr(ptr, ""))) { + *(ptr) = ']'; + if ((ptrl = strstr(ptr, "",7); - memmove(ptr+7,ptr+8,mir_strlen(ptr+8)+1); + while ((ptr = strstr(rptr, "[color="))) { + int addr = ptr - rptr; + dest = (char*)mir_realloc(dest, mir_strlen(dest) + 8); + rptr = dest; + ptr = rptr + addr; + memmove(ptr + 5, ptr, mir_strlen(ptr) + 1); + memcpy(ptr, "", 7); + memmove(ptr + 7, ptr + 8, mir_strlen(ptr + 8) + 1); } } else rptr++; } - while ((ptr = strstr(rptr, "[url="))) - { - int addr=ptr-rptr; - dest=(char*)mir_realloc(dest,mir_strlen(dest)+8); - rptr=dest; - ptr=rptr+addr; - memmove(ptr+3, ptr, mir_strlen(ptr)+1); - memcpy(ptr,"",4); - memmove(ptr+4,ptr+6,mir_strlen(ptr+6)+1); + while ((ptr = strstr(rptr, "[url="))) { + int addr = ptr - rptr; + dest = (char*)mir_realloc(dest, mir_strlen(dest) + 8); + rptr = dest; + ptr = rptr + addr; + memmove(ptr + 3, ptr, mir_strlen(ptr) + 1); + memcpy(ptr, "", 4); + memmove(ptr + 4, ptr + 6, mir_strlen(ptr + 6) + 1); } } else @@ -580,19 +470,18 @@ char* bbcodes_to_html(const char *src) void strip_tag(char* begin, char* end) { - memmove(begin,end+1,mir_strlen(end+1)+1); + memmove(begin, end + 1, mir_strlen(end + 1) + 1); } //strip a tag within a string char* strip_tag_within(char* begin, char* end) { - while(char* sub_begin=strchr(begin,'<')) - { - if (sub_begin'); - strip_tag(sub_begin,sub_end); - end=end-(sub_end-sub_begin)-1; + char *sub_end = strchr(begin, '>'); + strip_tag(sub_begin, sub_end); + end = end - (sub_end - sub_begin) - 1; } else break; @@ -600,177 +489,156 @@ char* strip_tag_within(char* begin, char* end) return end; } -char* rtf_to_html(HWND hwndDlg,int DlgItem) +char* rtf_to_html(HWND hwndDlg, int DlgItem) { - char* buf=(char*)mir_alloc(4024); - size_t pos=0; - int start=0; - int end=1; - BOOL Bold=false; - BOOL Italic=false; - BOOL Underline=false; - char Face[32]=""; - COLORREF Color=0; - COLORREF BackColor=0; - int Size=0; + char* buf = (char*)mir_alloc(4024); + size_t pos = 0; + int start = 0; + int end = 1; + BOOL Bold = false; + BOOL Italic = false; + BOOL Underline = false; + char Face[32] = ""; + COLORREF Color = 0; + COLORREF BackColor = 0; + int Size = 0; GETTEXTLENGTHEX tl; - tl.flags=GTL_DEFAULT; - tl.codepage=CP_ACP; + tl.flags = GTL_DEFAULT; + tl.codepage = CP_ACP; int oldstart = 0, oldend = 0; SendDlgItemMessage(hwndDlg, DlgItem, EM_GETSEL, (WPARAM)&oldstart, (LPARAM)&oldend); - int length=SendDlgItemMessage(hwndDlg, DlgItem, EM_GETTEXTLENGTHEX,(WPARAM)&tl,0); - while(start"); - pos+=3; + if (Bold != isBold) { + Bold = isBold; + if (isBold) { + mir_strcpy(&buf[pos], ""); + pos += 3; } - else - { - if (start!=0) - { - mir_strcpy(&buf[pos],""); - pos+=4; + else { + if (start != 0) { + mir_strcpy(&buf[pos], ""); + pos += 4; } } } - if (Italic!=isItalic) - { - Italic=isItalic; - if (isItalic) - { - mir_strcpy(&buf[pos],""); - pos+=3; + if (Italic != isItalic) { + Italic = isItalic; + if (isItalic) { + mir_strcpy(&buf[pos], ""); + pos += 3; } - else - { - if (start!=0) - { - mir_strcpy(&buf[pos],""); - pos+=4; + else { + if (start != 0) { + mir_strcpy(&buf[pos], ""); + pos += 4; } } } - if (Underline!=isUnderline) - { - Underline=isUnderline; - if (isUnderline) - { - mir_strcpy(&buf[pos],""); - pos+=3; + if (Underline != isUnderline) { + Underline = isUnderline; + if (isUnderline) { + mir_strcpy(&buf[pos], ""); + pos += 3; } - else - { - if (start!=0) - { - mir_strcpy(&buf[pos],""); - pos+=4; + else { + if (start != 0) { + mir_strcpy(&buf[pos], ""); + pos += 4; } } } - if (Size != isSize || Color != isColor || BackColor != isBackColor || mir_strcmp(Face, cfOld.szFaceName)) - { - Size=isSize; - Color=isColor; - BackColor=isBackColor; - mir_strcpy(Face,cfOld.szFaceName); - if (start!=0) - { - mir_strcpy(&buf[pos],""); - pos+=7; + if (Size != isSize || Color != isColor || BackColor != isBackColor || mir_strcmp(Face, cfOld.szFaceName)) { + Size = isSize; + Color = isColor; + BackColor = isBackColor; + mir_strcpy(Face, cfOld.szFaceName); + if (start != 0) { + mir_strcpy(&buf[pos], ""); + pos += 7; } - mir_strcpy(&buf[pos],">8),chBackColor,16); - size_t len=mir_strlen(chBackColor); - if (len<6) - { - memmove(chBackColor+(6-len),chBackColor,len+1); - for(int i=0;i<6;i++) - chBackColor[i]='0'; + _itoa((_htonl(BackColor) >> 8), chBackColor, 16); + size_t len = mir_strlen(chBackColor); + if (len < 6) { + memmove(chBackColor + (6 - len), chBackColor, len + 1); + for (int i = 0; i < 6; i++) + chBackColor[i] = '0'; } - mir_strcpy(&buf[pos],chBackColor); - pos+=6; + mir_strcpy(&buf[pos], chBackColor); + pos += 6; } - if (!(cfOld.dwEffects & CFE_AUTOCOLOR)) - { - mir_strcpy(&buf[pos]," color=#"); - pos+=8; + if (!(cfOld.dwEffects & CFE_AUTOCOLOR)) { + mir_strcpy(&buf[pos], " color=#"); + pos += 8; char chColor[7]; - _itoa((_htonl(Color)>>8),chColor,16); - size_t len=mir_strlen(chColor); - if (len<6) - { - memmove(chColor+(6-len),chColor,len+1); - for(int i=0;i<6;i++) - chColor[i]='0'; + _itoa((_htonl(Color) >> 8), chColor, 16); + size_t len = mir_strlen(chColor); + if (len < 6) { + memmove(chColor + (6 - len), chColor, len + 1); + for (int i = 0; i < 6; i++) + chColor[i] = '0'; } - mir_strcpy(&buf[pos],chColor); - pos+=6; + mir_strcpy(&buf[pos], chColor); + pos += 6; } - mir_strcpy(&buf[pos]," size="); - pos+=6; + mir_strcpy(&buf[pos], " size="); + pos += 6; char chSize[2]; - _itoa(Size,chSize,10); - mir_strcpy(&buf[pos],chSize); + _itoa(Size, chSize, 10); + mir_strcpy(&buf[pos], chSize); pos++; - mir_strcpy(&buf[pos],">"); + mir_strcpy(&buf[pos], ">"); pos++; } - if (text[0]=='\r') - { - mir_strcpy(&buf[pos],"
"); - pos+=4; + if (text[0] == '\r') { + mir_strcpy(&buf[pos], "
"); + pos += 4; } - else - { + else { T2Utf txt(text); mir_strcpy(&buf[pos], txt); pos += mir_strlen(txt); @@ -778,75 +646,68 @@ char* rtf_to_html(HWND hwndDlg,int DlgItem) start++; end++; } - if (Bold) - { - mir_strcpy(&buf[pos],""); - pos+=4; + if (Bold) { + mir_strcpy(&buf[pos], ""); + pos += 4; } - if (Italic) - { - mir_strcpy(&buf[pos],""); - pos+=4; + if (Italic) { + mir_strcpy(&buf[pos], ""); + pos += 4; } - if (Underline) - { - mir_strcpy(&buf[pos],""); - pos+=4; + if (Underline) { + mir_strcpy(&buf[pos], ""); + pos += 4; } - mir_strcpy(&buf[pos],""); - pos+=7; + mir_strcpy(&buf[pos], ""); + pos += 7; SendDlgItemMessage(hwndDlg, DlgItem, EM_SETSEL, oldstart, oldend); return buf; } -void wcs_htons(wchar_t * ch) +void wcs_htons(wchar_t *ch) { if (ch == NULL) return; - for(size_t i=0;i>4; - _itoa(bit,store,16); - memcpy(&string[i*2],store,1); - bit=(bytes[i]&0x0F); - _itoa(bit,store,16); - memcpy(&string[i*2+1],store,1); - } - string[num_bytes*2]='\0'; + unsigned char bit = (bytes[i] & 0xF0) >> 4; + _itoa(bit, store, 16); + memcpy(&string[i * 2], store, 1); + bit = (bytes[i] & 0x0F); + _itoa(bit, store, 16); + memcpy(&string[i * 2 + 1], store, 1); + } + string[num_bytes * 2] = '\0'; return string; } -void string_to_bytes(char* string, char* bytes) +void string_to_bytes(char *string, char *bytes) { char sbyte[3]; - sbyte[2]='\0'; - size_t length=mir_strlen(string); - for (size_t i=0; i. */ + #include "stdafx.h" void __cdecl CAimProto::aim_dc_helper(void* param) //only called when we are initiating a direct connection with someone else { - file_transfer *ft = (file_transfer*)param; + file_transfer *ft = (file_transfer*)param; ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, ft, 0); - NETLIBPACKETRECVER packetRecv = {0}; + NETLIBPACKETRECVER packetRecv = { 0 }; packetRecv.cbSize = sizeof(packetRecv); packetRecv.dwTimeout = 350000; - HANDLE hServerPacketRecver = (HANDLE) CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)ft->hConn, 2048 * 4); + HANDLE hServerPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)ft->hConn, 2048 * 4); int result; if (ft->sending)//we are sending result = sending_file(ft, hServerPacketRecver, packetRecv); - else + else result = receiving_file(ft, hServerPacketRecver, packetRecv); Netlib_CloseHandle(hServerPacketRecver); @@ -41,17 +42,12 @@ void __cdecl CAimProto::aim_dc_helper(void* param) //only called when we are ini ft->hConn = NULL; if (result == 0) - { ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ft, 0); - } - else - { - if (!ft->requester && result == 1 && !Miranda_Terminated()) - { + else { + if (!ft->requester && result == 1 && !Miranda_Terminated()) { ft->accepted = false; HANDLE hConn = aim_peer_connect(AIM_PROXY_SERVER, get_default_port()); - if (hConn) - { + if (hConn) { debugLogA("Connected to proxy ip because we want to use a proxy for the file transfer."); ft->requester = true; ft->hConn = hConn; @@ -59,30 +55,27 @@ void __cdecl CAimProto::aim_dc_helper(void* param) //only called when we are ini return; } } - aim_file_ad(hServerConn, seqno, ft->sn, ft->icbm_cookie, true, 0); + aim_file_ad(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie, true, 0); ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); } - ft_list.remove_by_ft(ft); + m_ft_list.remove_by_ft(ft); } void aim_direct_connection_initiated(HANDLE hNewConnection, DWORD, void* extra)//for receiving stuff via dc { - CAimProto* ppro = (CAimProto*)extra; - file_transfer *ft; + CAimProto *ppro = (CAimProto*)extra; - NETLIBCONNINFO connInfo = { sizeof(connInfo) }; + NETLIBCONNINFO connInfo = { sizeof(connInfo) }; CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hNewConnection, (LPARAM)&connInfo); ppro->debugLogA("Buddy connected: %s", connInfo.szIpPort); // okay someone connected to us or we initiated the connection- we need to figure out who they are and if they belong - ft = ppro->ft_list.find_by_port(connInfo.wPort); - if (ft) - { + file_transfer *ft = ppro->m_ft_list.find_by_port(connInfo.wPort); + if (ft) { ft->hConn = hNewConnection; ppro->aim_dc_helper(ft); } - else - Netlib_CloseHandle(hNewConnection); + else Netlib_CloseHandle(hNewConnection); } diff --git a/protocols/AimOscar/src/error.cpp b/protocols/AimOscar/src/error.cpp index f9ecf33108..885d13deb0 100644 --- a/protocols/AimOscar/src/error.cpp +++ b/protocols/AimOscar/src/error.cpp @@ -16,12 +16,12 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" void CAimProto::login_error(unsigned short error) { - switch(error) - { + switch (error) { case 0x0004: ShowPopup(LPGEN("Invalid Screen Name or password."), ERROR_POPUP); break; @@ -42,8 +42,7 @@ void CAimProto::login_error(unsigned short error) void CAimProto::get_error(unsigned short error) { - switch(error) - { + switch (error) { case 0x01: ShowPopup(LPGEN("Invalid SNAC header."), ERROR_POPUP); break; @@ -144,8 +143,7 @@ void CAimProto::get_error(unsigned short error) void CAimProto::admin_error(unsigned short error) { - switch(error) - { + switch (error) { case 0x01: ShowPopup(LPGEN("Check your Screen Name."), ERROR_POPUP); break; @@ -249,39 +247,39 @@ void CAimProto::admin_error(unsigned short error) case 0x1a: ShowPopup(LPGEN("Bad Database status."), ERROR_POPUP); break; - + case 0x1b: ShowPopup(LPGEN("Migration Cancel."), ERROR_POPUP); break; - + case 0x1c: ShowPopup(LPGEN("Internal Error."), ERROR_POPUP); break; - + case 0x1d: ShowPopup(LPGEN("There is already a Pending Request for this Screen Name."), ERROR_POPUP); break; - + case 0x1e: ShowPopup(LPGEN("Not DT status."), ERROR_POPUP); break; - + case 0x1f: ShowPopup(LPGEN("Outstanding Confirmation."), ERROR_POPUP); break; - + case 0x20: ShowPopup(LPGEN("No Email Address."), ERROR_POPUP); break; - + case 0x21: ShowPopup(LPGEN("Over Limit."), ERROR_POPUP); break; - + case 0x22: ShowPopup(LPGEN("Email Host Fail."), ERROR_POPUP); break; - + case 0x23: ShowPopup(LPGEN("DNS Fail."), ERROR_POPUP); break; diff --git a/protocols/AimOscar/src/file.cpp b/protocols/AimOscar/src/file.cpp index 19efeee646..33bcbf0afe 100644 --- a/protocols/AimOscar/src/file.cpp +++ b/protocols/AimOscar/src/file.cpp @@ -16,10 +16,13 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" #pragma pack(push, 1) -struct oft2//oscar file transfer 2 class- See On_Sending_Files_via_OSCAR.pdf + +// oscar file transfer 2 class- See On_Sending_Files_via_OSCAR.pdf +struct oft2 { char protocol_version[4];//4 unsigned short length;//6 @@ -64,24 +67,24 @@ bool send_init_oft2(file_transfer *ft, char* file) memset(oft, 0, len); memcpy(oft->protocol_version, "OFT2", 4); - oft->length = _htons(len); - oft->type = 0x0101; - oft->total_files = _htons(ft->pfts.totalFiles); - oft->num_files_left = _htons(ft->pfts.totalFiles - ft->pfts.currentFileNumber); - oft->total_parts = _htons(1); - oft->parts_left = _htons(1); - oft->total_size = _htonl(ft->pfts.totalBytes); - oft->size = _htonl(ft->pfts.currentFileSize); - oft->mod_time = _htonl(ft->pfts.currentFileTime); - oft->checksum = _htonl(aim_oft_checksum_file(ft->pfts.tszCurrentFile)); - oft->recv_RFchecksum = 0x0000FFFF; - oft->RFchecksum = 0x0000FFFF; - oft->recv_checksum = 0x0000FFFF; + oft->length = _htons(len); + oft->type = 0x0101; + oft->total_files = _htons(ft->pfts.totalFiles); + oft->num_files_left = _htons(ft->pfts.totalFiles - ft->pfts.currentFileNumber); + oft->total_parts = _htons(1); + oft->parts_left = _htons(1); + oft->total_size = _htonl(ft->pfts.totalBytes); + oft->size = _htonl(ft->pfts.currentFileSize); + oft->mod_time = _htonl(ft->pfts.currentFileTime); + oft->checksum = _htonl(aim_oft_checksum_file(ft->pfts.tszCurrentFile)); + oft->recv_RFchecksum = 0x0000FFFF; + oft->RFchecksum = 0x0000FFFF; + oft->recv_checksum = 0x0000FFFF; memcpy(oft->idstring, "Cool FileXfer", 13); - oft->flags = 0x20; + oft->flags = 0x20; oft->list_name_offset = 0x1c; oft->list_size_offset = 0x11; - oft->encoding = _htons(astr.isUnicode() ? 2 : 0); + oft->encoding = _htons(astr.isUnicode() ? 2 : 0); memcpy(oft->filename, astr.getBuf(), astr.getTermSize()); if (!ft->requester || ft->pfts.currentFileNumber) @@ -103,12 +106,11 @@ bool setup_next_file_send(file_transfer *ft) { TCHAR *file; struct _stati64 statbuf; - for (;;) - { + for (;;) { file = ft->pfts.ptszFiles[ft->cf]; if (file == NULL) return false; - if (_tstati64(file, &statbuf) == 0 && (statbuf.st_mode & _S_IFDIR) == 0) + if (_tstati64(file, &statbuf) == 0 && (statbuf.st_mode & _S_IFDIR) == 0) break; ++ft->cf; @@ -121,12 +123,10 @@ bool setup_next_file_send(file_transfer *ft) char* fnamea; T2Utf fname(file); - if (ft->pfts.totalFiles > 1 && ft->file[0]) - { + if (ft->pfts.totalFiles > 1 && ft->file[0]) { size_t dlen = mir_strlen(ft->file); - if (strncmp(fname, ft->file, dlen) == 0 && fname[dlen] == '\\') - { - fnamea = &fname[dlen+1]; + if (strncmp(fname, ft->file, dlen) == 0 && fname[dlen] == '\\') { + fnamea = &fname[dlen + 1]; for (char *p = fnamea; *p; ++p) if (*p == '\\') *p = 1; @@ -151,26 +151,22 @@ int CAimProto::sending_file(file_transfer *ft, HANDLE hServerPacketRecver, NETLI debugLogA("Sent file information to buddy."); //start listen for packets stuff - for (;;) - { + for (;;) { int recvResult = packetRecv.bytesAvailable - packetRecv.bytesUsed; if (recvResult <= 0) recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv); - if (recvResult == 0) - { + if (recvResult == 0) { debugLogA("P2P: File transfer connection Error: 0"); break; } - if (recvResult == SOCKET_ERROR) - { + if (recvResult == SOCKET_ERROR) { failed_conn = true; debugLogA("P2P: File transfer connection Error: -1"); break; } - if (recvResult > 0) - { + if (recvResult > 0) { if (recvResult < 0x100) continue; - + oft2* recv_ft = (oft2*)&packetRecv.buffer[packetRecv.bytesUsed]; unsigned short pkt_len = _htons(recv_ft->length); @@ -178,28 +174,25 @@ int CAimProto::sending_file(file_transfer *ft, HANDLE hServerPacketRecver, NETLI packetRecv.bytesUsed += pkt_len; unsigned short type = _htons(recv_ft->type); - if (type == 0x0202 || type == 0x0207) - { + if (type == 0x0202 || type == 0x0207) { debugLogA("P2P: Buddy Accepts our file transfer."); int fid = _topen(ft->pfts.tszCurrentFile, _O_RDONLY | _O_BINARY, _S_IREAD); - if (fid < 0) - { + if (fid < 0) { report_file_error(ft->pfts.tszCurrentFile); return 2; } if (ft->pfts.currentFileProgress) _lseeki64(fid, ft->pfts.currentFileProgress, SEEK_SET); - NETLIBSELECT tSelect = {0}; + NETLIBSELECT tSelect = { 0 }; tSelect.cbSize = sizeof(tSelect); tSelect.hReadConns[0] = ft->hConn; ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->pfts); clock_t lNotify = clock(); - for (;;) - { + for (;;) { char buffer[4096]; int bytes = _read(fid, buffer, sizeof(buffer)); if (bytes <= 0) break; @@ -207,9 +200,8 @@ int CAimProto::sending_file(file_transfer *ft, HANDLE hServerPacketRecver, NETLI if (Netlib_Send(ft->hConn, buffer, bytes, MSG_NODUMP) <= 0) break; ft->pfts.currentFileProgress += bytes; ft->pfts.totalProgress += bytes; - - if (clock() >= lNotify) - { + + if (clock() >= lNotify) { ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->pfts); if (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&tSelect)) break; @@ -220,40 +212,33 @@ int CAimProto::sending_file(file_transfer *ft, HANDLE hServerPacketRecver, NETLI debugLogA("P2P: Finished sending file bytes."); _close(fid); } - else if (type == 0x0204) - { + else if (type == 0x0204) { // Handle file skip case - if (ft->pfts.currentFileProgress == 0) - { + if (ft->pfts.currentFileProgress == 0) { ft->pfts.totalProgress += ft->pfts.currentFileSize; } debugLogA("P2P: Buddy says they got the file successfully"); - if ((ft->pfts.currentFileNumber + 1) < ft->pfts.totalFiles) - { + if ((ft->pfts.currentFileNumber + 1) < ft->pfts.totalFiles) { ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0); ++ft->pfts.currentFileNumber; ++ft->cf; - if (!setup_next_file_send(ft)) - { + if (!setup_next_file_send(ft)) { report_file_error(ft->pfts.tszCurrentFile); return 2; } } - else - { + else { failed = _htonl(recv_ft->recv_bytes) != ft->pfts.currentFileSize; break; } } - else if (type == 0x0205) - { + else if (type == 0x0205) { recv_ft = (oft2*)packetRecv.buffer; recv_ft->type = _htons(0x0106); - + ft->pfts.currentFileProgress = _htonl(recv_ft->recv_bytes); - if (aim_oft_checksum_file(ft->pfts.tszCurrentFile, ft->pfts.currentFileProgress) != _htonl(recv_ft->recv_checksum)) - { + if (aim_oft_checksum_file(ft->pfts.tszCurrentFile, ft->pfts.currentFileProgress) != _htonl(recv_ft->recv_checksum)) { ft->pfts.currentFileProgress = 0; recv_ft->recv_bytes = 0; } @@ -284,28 +269,23 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET ft->pfts.tszWorkingDir = mir_utf8decodeT(ft->file); //start listen for packets stuff - for (;;) - { + for (;;) { int recvResult = packetRecv.bytesAvailable - packetRecv.bytesUsed; if (recvResult <= 0) recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hServerPacketRecver, (LPARAM)&packetRecv); - if (recvResult == 0) - { + if (recvResult == 0) { debugLogA("P2P: File transfer connection Error: 0"); break; } - if (recvResult == SOCKET_ERROR) - { + if (recvResult == SOCKET_ERROR) { failed_conn = true; debugLogA("P2P: File transfer connection Error: -1"); break; } - if (recvResult > 0) - { - if (!accepted_file) - { + if (recvResult > 0) { + if (!accepted_file) { if (recvResult < 0x100) continue; - + oft2* recv_ft = (oft2*)&packetRecv.buffer[packetRecv.bytesUsed]; unsigned short pkt_len = _htons(recv_ft->length); @@ -313,8 +293,7 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET packetRecv.bytesUsed += pkt_len; unsigned short type = _htons(recv_ft->type); - if (type == 0x0101) - { + if (type == 0x0101) { debugLogA("P2P: Buddy Ready to begin transfer."); oft = (oft2*)mir_realloc(oft, pkt_len); memcpy(oft, recv_ft, pkt_len); @@ -331,15 +310,13 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET enc = _htons(recv_ft->encoding); TCHAR *name; - if (enc == 2) - { + if (enc == 2) { wchar_t* wbuf = (wchar_t*)buf; wcs_htons(wbuf); for (wchar_t *p = wbuf; *p; ++p) { if (*p == 1) *p = '\\'; } name = mir_u2t(wbuf); } - else - { + else { for (char *p = buf; *p; ++p) { if (*p == 1) *p = '\\'; } name = mir_a2t(buf); } @@ -356,8 +333,7 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET if (ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, ft, (LPARAM)&ft->pfts)) WaitForSingleObject(ft->hResumeEvent, INFINITE); - if (ft->pfts.tszCurrentFile) - { + if (ft->pfts.tszCurrentFile) { TCHAR* dir = get_dir(ft->pfts.tszCurrentFile); CreateDirectoryTreeT(dir); mir_free(dir); @@ -367,22 +343,19 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET const int flag = ft->pfts.currentFileProgress ? 0 : _O_TRUNC; fid = _topen(ft->pfts.tszCurrentFile, _O_CREAT | _O_WRONLY | _O_BINARY | flag, _S_IREAD | _S_IWRITE); - if (fid < 0) - { + if (fid < 0) { report_file_error(fname); break; } accepted_file = ft->pfts.currentFileProgress == 0; - if (ft->pfts.currentFileProgress) - { + if (ft->pfts.currentFileProgress) { bool the_same; oft->recv_bytes = _htonl(ft->pfts.currentFileProgress); oft->recv_checksum = _htonl(aim_oft_checksum_file(ft->pfts.tszCurrentFile)); the_same = oft->size == oft->recv_bytes && oft->checksum == oft->recv_checksum; - if (the_same) - { + if (the_same) { ft->pfts.totalProgress += ft->pfts.currentFileProgress; oft->type = _htons(0x0204); _close(fid); @@ -393,8 +366,7 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET } } } - else - { + else { oft->type = _htons(0x0204); ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0); @@ -405,14 +377,12 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET if (Netlib_Send(ft->hConn, (char*)oft, pkt_len, 0) == SOCKET_ERROR) break; - if (ft->pfts.currentFileNumber >= ft->pfts.totalFiles && _htons(oft->type) == 0x0204) - { + if (ft->pfts.currentFileNumber >= ft->pfts.totalFiles && _htons(oft->type) == 0x0204) { failed = false; break; } } - else if (type == 0x0106) - { + else if (type == 0x0106) { oft = (oft2*)mir_realloc(oft, pkt_len); memcpy(oft, recv_ft, pkt_len); @@ -426,31 +396,26 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET if (Netlib_Send(ft->hConn, (char*)oft, pkt_len, 0) == SOCKET_ERROR) break; } - else - break; + else break; } - else - { + else { packetRecv.bytesUsed = packetRecv.bytesAvailable; _write(fid, packetRecv.buffer, packetRecv.bytesAvailable); ft->pfts.currentFileProgress += packetRecv.bytesAvailable; - ft->pfts.totalProgress += packetRecv.bytesAvailable; + ft->pfts.totalProgress += packetRecv.bytesAvailable; ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->pfts); - if (ft->pfts.currentFileSize == ft->pfts.currentFileProgress) - { + if (ft->pfts.currentFileSize == ft->pfts.currentFileProgress) { oft->type = _htons(0x0204); oft->recv_bytes = _htonl(ft->pfts.currentFileProgress); oft->recv_checksum = _htonl(aim_oft_checksum_file(ft->pfts.tszCurrentFile)); debugLogA("P2P: We got the file successfully"); Netlib_Send(ft->hConn, (char*)oft, _htons(oft->length), 0); - if (_htons(oft->num_files_left) == 1) - { + if (_htons(oft->num_files_left) == 1) { failed = false; break; } - else - { + else { accepted_file = false; _close(fid); @@ -472,20 +437,18 @@ int CAimProto::receiving_file(file_transfer *ft, HANDLE hServerPacketRecver, NET void CAimProto::shutdown_file_transfers(void) { - for(int i=0; i(10) {}; +ft_list_type::ft_list_type() : OBJLIST (10) {}; file_transfer* ft_list_type::find_by_cookie(char* cookie, MCONTACT hContact) { - for (int i = 0; i < getCount(); ++i) - { + for (int i = 0; i < getCount(); ++i) { file_transfer *ft = items[i]; if (ft->hContact == hContact && memcmp(ft->icbm_cookie, cookie, 8) == 0) return ft; @@ -495,10 +458,9 @@ file_transfer* ft_list_type::find_by_cookie(char* cookie, MCONTACT hContact) file_transfer* ft_list_type::find_by_port(unsigned short port) { - for (int i = getCount(); i--; ) - { + for (int i = getCount(); i--; ) { file_transfer *ft = items[i]; - if (ft->requester && ft->local_port == port) + if (ft->requester && ft->local_port == port) return ft; } return NULL; @@ -508,18 +470,16 @@ file_transfer* ft_list_type::find_by_port(unsigned short port) bool ft_list_type::find_by_ft(file_transfer *ft) { for (int i = 0; i < getCount(); ++i) - { - if (items[i] == ft) return true; - } + if (items[i] == ft) + return true; + return false; } void ft_list_type::remove_by_ft(file_transfer *ft) { - for (int i = 0; i < getCount(); ++i) - { - if (items[i] == ft) - { + for (int i = 0; i < getCount(); ++i) { + if (items[i] == ft) { remove(i); break; } @@ -527,8 +487,8 @@ void ft_list_type::remove_by_ft(file_transfer *ft) } file_transfer::file_transfer(MCONTACT hCont, char* nick, char* cookie) -{ - memset(this, 0, sizeof(*this)); +{ + memset(this, 0, sizeof(*this)); pfts.cbSize = sizeof(pfts); pfts.flags = PFTS_TCHAR; @@ -541,23 +501,22 @@ file_transfer::file_transfer(MCONTACT hCont, char* nick, char* cookie) memcpy(icbm_cookie, cookie, 8); else Utils_GetRandom(icbm_cookie, 8); - + hResumeEvent = CreateEvent(NULL, FALSE, FALSE, NULL); } -file_transfer::~file_transfer() -{ +file_transfer::~file_transfer() +{ stop_listen(); - mir_free(file); - mir_free(message); - mir_free(sn); + mir_free(file); + mir_free(message); + mir_free(sn); mir_free(pfts.tszWorkingDir); if (!sending) mir_free(pfts.tszCurrentFile); - if (success && pfts.ptszFiles) - { + if (success && pfts.ptszFiles) { for (int i = 0; pfts.ptszFiles[i]; i++) mir_free(pfts.ptszFiles[i]); @@ -566,22 +525,21 @@ file_transfer::~file_transfer() CloseHandle(hResumeEvent); } -void file_transfer::listen(CAimProto* ppro) -{ +void file_transfer::listen(CAimProto* ppro) +{ if (hDirectBoundPort) return; - NETLIBBIND nlb = {0}; + NETLIBBIND nlb = { 0 }; nlb.cbSize = sizeof(nlb); nlb.pfnNewConnectionV2 = aim_direct_connection_initiated; nlb.pExtra = ppro; - hDirectBoundPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)ppro->hNetlibPeer, (LPARAM)&nlb); + hDirectBoundPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)ppro->m_hNetlibPeer, (LPARAM)&nlb); local_port = hDirectBoundPort ? nlb.wPort : 0; } -void file_transfer::stop_listen(void) -{ - if (hDirectBoundPort) - { +void file_transfer::stop_listen(void) +{ + if (hDirectBoundPort) { Netlib_CloseHandle(hDirectBoundPort); hDirectBoundPort = NULL; local_port = 0; diff --git a/protocols/AimOscar/src/flap.cpp b/protocols/AimOscar/src/flap.cpp index 96b164fa9c..960034d8a0 100644 --- a/protocols/AimOscar/src/flap.cpp +++ b/protocols/AimOscar/src/flap.cpp @@ -18,23 +18,17 @@ along with this program. If not, see . */ #include "stdafx.h" -FLAP::FLAP(char* buf,int num_bytes) +FLAP::FLAP(char* buf, int num_bytes) { - if (FLAP_SIZE>num_bytes) - { - length_=0; - } - else - { - length_=_htons((*(unsigned short*)&buf[4])); - if (FLAP_SIZE+length_>num_bytes) - { - length_=0; - } - else - { - type_=buf[1]; - value_=&buf[FLAP_SIZE]; + if (FLAP_SIZE > num_bytes) + length_ = 0; + else { + length_ = _htons((*(unsigned short*)&buf[4])); + if (FLAP_SIZE + length_ > num_bytes) + length_ = 0; + else { + type_ = buf[1]; + value_ = &buf[FLAP_SIZE]; } } } @@ -42,17 +36,17 @@ unsigned short FLAP::len() { return length_; } + unsigned short FLAP::snaclen() { - return length_-10; + return length_ - 10; } + int FLAP::cmp(unsigned short type) { - if (type_==type) - return 1; - else - return 0; + return (type_ == type); } + char* FLAP::val() { return value_; diff --git a/protocols/AimOscar/src/links.cpp b/protocols/AimOscar/src/links.cpp index ee4709ac0c..ea187bfbe6 100644 --- a/protocols/AimOscar/src/links.cpp +++ b/protocols/AimOscar/src/links.cpp @@ -22,7 +22,6 @@ static HANDLE hServiceParseLink; extern OBJLIST g_Instances; - static int SingleHexToDecimal(TCHAR c) { if (c >= '0' && c <= '9') return c - '0'; @@ -35,21 +34,17 @@ static TCHAR* url_decode(TCHAR* str) { TCHAR* s = str, *d = str; - while(*s) - { - if (*s == '%') - { + while (*s) { + if (*s == '%') { int digit1 = SingleHexToDecimal(s[1]); - if (digit1 != -1) - { + if (digit1 != -1) { int digit2 = SingleHexToDecimal(s[2]); - if (digit2 != -1) - { + if (digit2 != -1) { s += 3; *d++ = (TCHAR)((digit1 << 4) | digit2); continue; - } - } + } + } } *d++ = *s++; } @@ -58,7 +53,7 @@ static TCHAR* url_decode(TCHAR* str) return str; } -static INT_PTR ServiceParseAimLink(WPARAM,LPARAM lParam) +static INT_PTR ServiceParseAimLink(WPARAM, LPARAM lParam) { if (lParam == 0) return 1; /* sanity check */ @@ -75,10 +70,8 @@ static INT_PTR ServiceParseAimLink(WPARAM,LPARAM lParam) if (g_Instances.getCount() == 0) return 0; CAimProto *proto = &g_Instances[0]; - for (int i = 0; i < g_Instances.getCount(); ++i) - { - if (g_Instances[i].m_iStatus != ID_STATUS_OFFLINE && !IsStatusConnecting(g_Instances[i].m_iStatus)) - { + for (int i = 0; i < g_Instances.getCount(); ++i) { + if (g_Instances[i].m_iStatus != ID_STATUS_OFFLINE && !IsStatusConnecting(g_Instances[i].m_iStatus)) { proto = &g_Instances[i]; break; } @@ -91,13 +84,11 @@ static INT_PTR ServiceParseAimLink(WPARAM,LPARAM lParam) open chatroom: aim:gochat?roomname=ROOM&exchange=NUM */ /* add a contact to the list */ - if (!_tcsnicmp(arg, _T("addbuddy?"), 9)) - { - TCHAR *tok, *tok2; + if (!_tcsnicmp(arg, _T("addbuddy?"), 9)) { + TCHAR *tok, *tok2; char *sn = NULL, *group = NULL; - - for (tok = arg + 8; tok != NULL; tok = tok2) - { + + for (tok = arg + 8; tok != NULL; tok = tok2) { tok2 = _tcschr(++tok, '&'); /* first token */ if (tok2) *tok2 = 0; if (!_tcsnicmp(tok, _T("screenname="), 11) && *(tok + 11) != 0) @@ -105,8 +96,7 @@ static INT_PTR ServiceParseAimLink(WPARAM,LPARAM lParam) if (!_tcsnicmp(tok, _T("groupname="), 10) && *(tok + 10) != 0) group = mir_utf8encodeT(url_decode(tok + 10)); /* group is currently ignored */ } - if (sn == NULL) - { + if (sn == NULL) { mir_free(group); return 1; } @@ -121,15 +111,13 @@ static INT_PTR ServiceParseAimLink(WPARAM,LPARAM lParam) return 0; } /* send a message to a contact */ - else if (!_tcsnicmp(arg, _T("goim?"), 5)) - { + else if (!_tcsnicmp(arg, _T("goim?"), 5)) { TCHAR *tok, *tok2, *msg = NULL; char *sn = NULL; - for (tok = arg + 4; tok != NULL; tok = tok2) - { + for (tok = arg + 4; tok != NULL; tok = tok2) { tok2 = _tcschr(++tok, '&'); /* first token */ - if (tok2) *tok2=0; + if (tok2) *tok2 = 0; if (!_tcsnicmp(tok, _T("screenname="), 11) && *(tok + 11) != 0) sn = mir_t2a(url_decode(tok + 11)); if (!_tcsnicmp(tok, _T("message="), 8) && *(tok + 8) != 0) @@ -144,35 +132,32 @@ static INT_PTR ServiceParseAimLink(WPARAM,LPARAM lParam) mir_free(sn); return 0; } + /* open a chatroom */ - else if (!_tcsnicmp(arg, _T("gochat?"), 7)) - { + else if (!_tcsnicmp(arg, _T("gochat?"), 7)) { TCHAR *tok, *tok2; char *rm = NULL; int exchange = 0; - for (tok = arg + 6; tok != NULL; tok = tok2) - { + for (tok = arg + 6; tok != NULL; tok = tok2) { tok2 = _tcschr(++tok, '&'); /* first token */ if (tok2) *tok2 = 0; - if (!_tcsnicmp(tok, _T("roomname="), 9) && *(tok + 9) != 0) - { + if (!_tcsnicmp(tok, _T("roomname="), 9) && *(tok + 9) != 0) { rm = mir_t2a(url_decode(tok + 9)); for (char *ch = rm; *ch; ++ch) if (*ch == '+') *ch = ' '; } if (!_tcsnicmp(tok, _T("exchange="), 9)) - exchange = _ttoi(tok + 9); + exchange = _ttoi(tok + 9); } - if (rm == NULL || exchange <= 0) - { + if (rm == NULL || exchange <= 0) { mir_free(rm); return 1; } chatnav_param* par = new chatnav_param(rm, (unsigned short)exchange); proto->ForkThread(&CAimProto::chatnav_request_thread, par); - + mir_free(rm); return 0; } diff --git a/protocols/AimOscar/src/proto.cpp b/protocols/AimOscar/src/proto.cpp index 4dc782f75a..869c081787 100644 --- a/protocols/AimOscar/src/proto.cpp +++ b/protocols/AimOscar/src/proto.cpp @@ -19,42 +19,42 @@ along with this program. If not, see . CAimProto::CAimProto(const char* aProtoName, const TCHAR* aUserName) : PROTO(aProtoName, aUserName), - chat_rooms(5) + m_chat_rooms(5) { debugLogA("Setting protocol/module name to '%s'", m_szModuleName); //create some events - hAvatarEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - hChatNavEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - hAdminEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + m_hAvatarEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + m_hChatNavEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + m_hAdminEvent = CreateEvent(NULL, TRUE, FALSE, NULL); CreateProtoService(PS_CREATEACCMGRUI, &CAimProto::SvcCreateAccMgrUI); - CreateProtoService(PS_GETMYAWAYMSG, &CAimProto::GetMyAwayMsg); + CreateProtoService(PS_GETMYAWAYMSG, &CAimProto::GetMyAwayMsg); CreateProtoService(PS_GETAVATARINFO, &CAimProto::GetAvatarInfo); - CreateProtoService(PS_GETMYAVATAR, &CAimProto::GetAvatar); - CreateProtoService(PS_SETMYAVATAR, &CAimProto::SetAvatar); - CreateProtoService(PS_GETAVATARCAPS, &CAimProto::GetAvatarCaps); + CreateProtoService(PS_GETMYAVATAR, &CAimProto::GetAvatar); + CreateProtoService(PS_SETMYAVATAR, &CAimProto::SetAvatar); + CreateProtoService(PS_GETAVATARCAPS, &CAimProto::GetAvatarCaps); - CreateProtoService(PS_JOINCHAT, &CAimProto::OnJoinChat); - CreateProtoService(PS_LEAVECHAT, &CAimProto::OnLeaveChat); + CreateProtoService(PS_JOINCHAT, &CAimProto::OnJoinChat); + CreateProtoService(PS_LEAVECHAT, &CAimProto::OnLeaveChat); HookProtoEvent(ME_CLIST_PREBUILDCONTACTMENU, &CAimProto::OnPreBuildContactMenu); - HookProtoEvent(ME_CLIST_GROUPCHANGE, &CAimProto::OnGroupChange); - HookProtoEvent(ME_OPT_INITIALISE, &CAimProto::OnOptionsInit); + HookProtoEvent(ME_CLIST_GROUPCHANGE, &CAimProto::OnGroupChange); + HookProtoEvent(ME_OPT_INITIALISE, &CAimProto::OnOptionsInit); offline_contacts(); TCHAR descr[MAX_PATH]; - NETLIBUSER nlu = {0}; + NETLIBUSER nlu = { 0 }; nlu.cbSize = sizeof(nlu); nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR; nlu.szSettingsModule = m_szModuleName; mir_sntprintf(descr, TranslateT("%s server connection"), m_tszUserName); nlu.ptszDescriptiveName = descr; - m_hNetlibUser = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); + m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); char szP2P[128]; mir_snprintf(szP2P, _countof(szP2P), "%sP2P", m_szModuleName); @@ -62,41 +62,41 @@ CAimProto::CAimProto(const char* aProtoName, const TCHAR* aUserName) : mir_sntprintf(descr, TranslateT("%s Client-to-client connection"), m_tszUserName); nlu.szSettingsModule = szP2P; nlu.minIncomingPorts = 1; - hNetlibPeer = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); + m_hNetlibPeer = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); } CAimProto::~CAimProto() { - if (hServerConn) - Netlib_CloseHandle(hServerConn); - if (hAvatarConn && hAvatarConn != (HANDLE)1) - Netlib_CloseHandle(hAvatarConn); - if (hChatNavConn && hChatNavConn != (HANDLE)1) - Netlib_CloseHandle(hChatNavConn); - if (hAdminConn && hAdminConn != (HANDLE)1) - Netlib_CloseHandle(hAdminConn); + if (m_hServerConn) + Netlib_CloseHandle(m_hServerConn); + if (m_hAvatarConn && m_hAvatarConn != (HANDLE)1) + Netlib_CloseHandle(m_hAvatarConn); + if (m_hChatNavConn && m_hChatNavConn != (HANDLE)1) + Netlib_CloseHandle(m_hChatNavConn); + if (m_hAdminConn && m_hAdminConn != (HANDLE)1) + Netlib_CloseHandle(m_hAdminConn); close_chat_conn(); Netlib_CloseHandle(m_hNetlibUser); - Netlib_CloseHandle(hNetlibPeer); + Netlib_CloseHandle(m_hNetlibPeer); - CloseHandle(hAvatarEvent); - CloseHandle(hChatNavEvent); - CloseHandle(hAdminEvent); + CloseHandle(m_hAvatarEvent); + CloseHandle(m_hChatNavEvent); + CloseHandle(m_hAdminEvent); - for (int i=0; i<9; ++i) - mir_free(modeMsgs[i]); + for (int i = 0; i < 9; ++i) + mir_free(m_modeMsgs[i]); - mir_free(pref2_flags); - mir_free(pref2_set_flags); + mir_free(m_pref2_flags); + mir_free(m_pref2_set_flags); mir_free(COOKIE); mir_free(MAIL_COOKIE); mir_free(AVATAR_COOKIE); mir_free(CHATNAV_COOKIE); mir_free(ADMIN_COOKIE); - mir_free(username); + mir_free(m_username); } //////////////////////////////////////////////////////////////////////////////////////// @@ -119,7 +119,9 @@ int CAimProto::OnModulesLoaded(WPARAM, LPARAM) MCONTACT CAimProto::AddToList(int flags, PROTOSEARCHRESULT* psr) { - if (state != 1) return 0; + if (m_state != 1) + return 0; + TCHAR *id = psr->id.t ? psr->id.t : psr->nick.t; char *sn = psr->flags & PSR_UNICODE ? mir_u2a((wchar_t*)id) : mir_strdup((char*)id); MCONTACT hContact = contact_from_sn(sn, true, (flags & PALF_TEMPORARY) != 0); @@ -133,12 +135,11 @@ MCONTACT CAimProto::AddToList(int flags, PROTOSEARCHRESULT* psr) int __cdecl CAimProto::AuthRequest(MCONTACT hContact, const TCHAR*) { //Not a real authrequest- only used b/c we don't know the group until now. - if (state != 1) + if (m_state != 1) return 1; DBVARIANT dbv; - if (!db_get_utf(hContact, MOD_KEY_CL, OTH_KEY_GP, &dbv) && dbv.pszVal[0]) - { + if (!db_get_utf(hContact, MOD_KEY_CL, OTH_KEY_GP, &dbv) && dbv.pszVal[0]) { add_contact_to_group(hContact, dbv.pszVal); db_free(&dbv); } @@ -150,15 +151,13 @@ int __cdecl CAimProto::AuthRequest(MCONTACT hContact, const TCHAR*) //////////////////////////////////////////////////////////////////////////////////////// // FileAllow - starts a file transfer -HANDLE __cdecl CAimProto::FileAllow(MCONTACT, HANDLE hTransfer, const TCHAR* szPath) +HANDLE __cdecl CAimProto::FileAllow(MCONTACT, HANDLE hTransfer, const TCHAR *szPath) { file_transfer *ft = (file_transfer*)hTransfer; - if (ft && ft_list.find_by_ft(ft)) - { + if (ft && m_ft_list.find_by_ft(ft)) { char *path = mir_utf8encodeT(szPath); - if (ft->pfts.totalFiles > 1 && ft->file[0]) - { + if (ft->pfts.totalFiles > 1 && ft->file[0]) { size_t path_len = mir_strlen(path); size_t len = mir_strlen(ft->file) + 2; @@ -181,19 +180,18 @@ HANDLE __cdecl CAimProto::FileAllow(MCONTACT, HANDLE hTransfer, const TCHAR* szP int __cdecl CAimProto::FileCancel(MCONTACT, HANDLE hTransfer) { file_transfer *ft = (file_transfer*)hTransfer; - if (!ft_list.find_by_ft(ft)) return 0; + if (!m_ft_list.find_by_ft(ft)) + return 0; debugLogA("We are cancelling a file transfer."); - aim_chat_deny(hServerConn, seqno, ft->sn, ft->icbm_cookie); + aim_chat_deny(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie); - if (ft->hConn) - { + if (ft->hConn) { Netlib_Shutdown(ft->hConn); SetEvent(ft->hResumeEvent); } - else - ft_list.remove_by_ft(ft); + else m_ft_list.remove_by_ft(ft); return 0; } @@ -204,11 +202,12 @@ int __cdecl CAimProto::FileCancel(MCONTACT, HANDLE hTransfer) int __cdecl CAimProto::FileDeny(MCONTACT, HANDLE hTransfer, const TCHAR* /*szReason*/) { file_transfer *ft = (file_transfer*)hTransfer; - if (!ft_list.find_by_ft(ft)) return 0; + if (!m_ft_list.find_by_ft(ft)) + return 0; debugLogA("We are denying a file transfer."); - aim_chat_deny(hServerConn, seqno, ft->sn, ft->icbm_cookie); + aim_chat_deny(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie); return 0; } @@ -218,7 +217,8 @@ int __cdecl CAimProto::FileDeny(MCONTACT, HANDLE hTransfer, const TCHAR* /*szRea int __cdecl CAimProto::FileResume(HANDLE hTransfer, int* action, const TCHAR** szFilename) { file_transfer *ft = (file_transfer*)hTransfer; - if (!ft_list.find_by_ft(ft)) return 0; + if (!m_ft_list.find_by_ft(ft)) + return 0; switch (*action) { case FILERESUME_RESUME: @@ -244,7 +244,7 @@ int __cdecl CAimProto::FileResume(HANDLE hTransfer, int* action, const TCHAR** s break; default: - aim_file_ad(hServerConn, seqno, ft->sn, ft->icbm_cookie, true, ft->max_ver); + aim_file_ad(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie, true, ft->max_ver); break; } SetEvent(ft->hResumeEvent); @@ -262,18 +262,18 @@ DWORD_PTR __cdecl CAimProto::GetCaps(int type, MCONTACT) return PF1_IM | PF1_MODEMSG | PF1_BASICSEARCH | PF1_SEARCHBYEMAIL | PF1_FILE; case PFLAGNUM_2: -#ifdef ALLOW_BUSY + #ifdef ALLOW_BUSY return PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_ONTHEPHONE | PF2_LIGHTDND; -#else + #else return PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_ONTHEPHONE; -#endif + #endif case PFLAGNUM_3: -#ifdef ALLOW_BUSY + #ifdef ALLOW_BUSY return PF2_ONLINE | PF2_SHORTAWAY | PF2_INVISIBLE | PF2_LIGHTDND; -#else + #else return PF2_ONLINE | PF2_SHORTAWAY | PF2_INVISIBLE; -#endif + #endif case PFLAGNUM_4: return PF4_SUPPORTTYPING | PF4_FORCEAUTH | PF4_NOCUSTOMAUTH | PF4_FORCEADDED | @@ -289,7 +289,7 @@ DWORD_PTR __cdecl CAimProto::GetCaps(int type, MCONTACT) return (DWORD_PTR) "Screen Name"; case PFLAG_UNIQUEIDSETTING: - return (DWORD_PTR) AIM_KEY_SN; + return (DWORD_PTR)AIM_KEY_SN; } return 0; } @@ -297,31 +297,27 @@ DWORD_PTR __cdecl CAimProto::GetCaps(int type, MCONTACT) //////////////////////////////////////////////////////////////////////////////////////// // SearchBasic - searches the contact by JID -void __cdecl CAimProto::basic_search_ack_success(void* p) +void __cdecl CAimProto::basic_search_ack_success(void *p) { char *sn = normalize_name((char*)p); - if (sn) // normalize it - { + if (sn) { // normalize it if (mir_strlen(sn) > 32) - { - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE) 1, 0); - } - else - { - PROTOSEARCHRESULT psr = {0}; + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); + else { + PROTOSEARCHRESULT psr = { 0 }; psr.cbSize = sizeof(psr); psr.id.t = (TCHAR*)sn; - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE) 1, (LPARAM) & psr); - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE) 1, 0); + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)& psr); + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); } } mir_free(sn); mir_free(p); } -HANDLE __cdecl CAimProto::SearchBasic(const TCHAR* szId) +HANDLE __cdecl CAimProto::SearchBasic(const TCHAR *szId) { - if (state != 1) + if (m_state != 1) return 0; //duplicating the parameter so that it isn't deleted before it's needed- e.g. this function ends before it's used @@ -332,14 +328,14 @@ HANDLE __cdecl CAimProto::SearchBasic(const TCHAR* szId) //////////////////////////////////////////////////////////////////////////////////////// // SearchByEmail - searches the contact by its e-mail -HANDLE __cdecl CAimProto::SearchByEmail(const TCHAR* email) +HANDLE __cdecl CAimProto::SearchByEmail(const TCHAR *email) { // Maximum email size should really be 320, but the char string is limited to 255. - if (state != 1 || email == NULL || mir_tstrlen(email) >= 254) + if (m_state != 1 || email == NULL || mir_tstrlen(email) >= 254) return NULL; - char* szEmail = mir_t2a(email); - aim_search_by_email(hServerConn, seqno, szEmail); + char *szEmail = mir_t2a(email); + aim_search_by_email(m_hServerConn, m_seqno, szEmail); mir_free(szEmail); return (HANDLE)1; } @@ -347,12 +343,11 @@ HANDLE __cdecl CAimProto::SearchByEmail(const TCHAR* email) //////////////////////////////////////////////////////////////////////////////////////// // RecvMsg -int __cdecl CAimProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre) +int __cdecl CAimProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) { char *omsg = pre->szMessage; char *bbuf = NULL; - if (getByte(AIM_KEY_FI, 1)) - { + if (getByte(AIM_KEY_FI, 1)) { debugLogA("Converting from html to bbcodes then stripping leftover html."); pre->szMessage = bbuf = html_to_bbcodes(pre->szMessage); } @@ -360,9 +355,9 @@ int __cdecl CAimProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre) html_decode(pre->szMessage); INT_PTR res = Proto_RecvMessage(hContact, pre); - mir_free(bbuf); + mir_free(bbuf); pre->szMessage = omsg; - return ( int )res; + return (int)res; } //////////////////////////////////////////////////////////////////////////////////////// @@ -370,36 +365,30 @@ int __cdecl CAimProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre) HANDLE __cdecl CAimProto::SendFile(MCONTACT hContact, const TCHAR* szDescription, TCHAR** ppszFiles) { - if (state != 1) return 0; + if (m_state != 1) + return 0; - if (hContact && szDescription && ppszFiles) - { + if (hContact && szDescription && ppszFiles) { DBVARIANT dbv; - if (!getString(hContact, AIM_KEY_SN, &dbv)) - { + if (!getString(hContact, AIM_KEY_SN, &dbv)) { file_transfer *ft = new file_transfer(hContact, dbv.pszVal, NULL); bool isDir = false; int count = 0; - while (ppszFiles[count] != NULL) - { + while (ppszFiles[count] != NULL) { struct _stati64 statbuf; - if (_tstati64(ppszFiles[count++], &statbuf) == 0) - { - if (statbuf.st_mode & _S_IFDIR) - { + if (_tstati64(ppszFiles[count++], &statbuf) == 0) { + if (statbuf.st_mode & _S_IFDIR) { if (ft->pfts.totalFiles == 0) isDir = true; } - else - { + else { ft->pfts.totalBytes += statbuf.st_size; ++ft->pfts.totalFiles; } } } - if (ft->pfts.totalFiles == 0) - { + if (ft->pfts.totalFiles == 0) { delete ft; return NULL; } @@ -413,21 +402,18 @@ HANDLE __cdecl CAimProto::SendFile(MCONTACT hContact, const TCHAR* szDescription ft->me_force_proxy = getByte(AIM_KEY_FP, 0) != 0; ft->requester = true; - ft_list.insert(ft); + m_ft_list.insert(ft); - if (ft->me_force_proxy) - { + if (ft->me_force_proxy) { debugLogA("We are forcing a proxy file transfer."); ForkThread(&CAimProto::accept_file_thread, ft); } - else - { + else { ft->listen(this); - aim_send_file(hServerConn, seqno, detected_ip, ft->local_port, false, ft); + aim_send_file(m_hServerConn, m_seqno, m_detected_ip, ft->local_port, false, ft); } db_free(&dbv); - return ft; } } @@ -453,10 +439,10 @@ void __cdecl CAimProto::msg_ack_success(void* param) int __cdecl CAimProto::SendMsg(MCONTACT hContact, int, const char* pszSrc) { - if (pszSrc == NULL) return 0; + if (pszSrc == NULL) + return 0; - if (state != 1) - { + if (m_state != 1) { msg_ack_param *msg_ack = (msg_ack_param*)mir_calloc(sizeof(msg_ack_param)); msg_ack->hContact = hContact; msg_ack->msg = "Message cannot be sent, when protocol offline"; @@ -464,8 +450,7 @@ int __cdecl CAimProto::SendMsg(MCONTACT hContact, int, const char* pszSrc) } char *sn = getStringA(hContact, AIM_KEY_SN); - if (sn == NULL) - { + if (sn == NULL) { msg_ack_param *msg_ack = (msg_ack_param*)mir_calloc(sizeof(msg_ack_param)); msg_ack->hContact = hContact; msg_ack->msg = "Screen Name for the contact not available"; @@ -473,21 +458,19 @@ int __cdecl CAimProto::SendMsg(MCONTACT hContact, int, const char* pszSrc) } char *smsg = html_encode(pszSrc), *msg; - if (getByte(AIM_KEY_FO, 1)) - { + if (getByte(AIM_KEY_FO, 1)) { msg = bbcodes_to_html(smsg); mir_free(smsg); } else msg = smsg; bool blast = getBool(hContact, AIM_KEY_BLS, false); - int res = aim_send_message(hServerConn, seqno, sn, msg, false, blast); + int res = aim_send_message(m_hServerConn, m_seqno, sn, msg, false, blast); mir_free(msg); mir_free(sn); - if (!res || blast || 0 == getByte(AIM_KEY_DC, 1)) - { + if (!res || blast || 0 == getByte(AIM_KEY_DC, 1)) { msg_ack_param *msg_ack = (msg_ack_param*)mir_alloc(sizeof(msg_ack_param)); msg_ack->hContact = hContact; msg_ack->msg = NULL; @@ -504,8 +487,7 @@ int __cdecl CAimProto::SendMsg(MCONTACT hContact, int, const char* pszSrc) int __cdecl CAimProto::SetStatus(int iNewStatus) { - switch (iNewStatus) - { + switch (iNewStatus) { case ID_STATUS_FREECHAT: iNewStatus = ID_STATUS_ONLINE; break; @@ -513,10 +495,10 @@ int __cdecl CAimProto::SetStatus(int iNewStatus) case ID_STATUS_DND: case ID_STATUS_OCCUPIED: case ID_STATUS_ONTHEPHONE: -#ifdef ALLOW_BUSY + #ifdef ALLOW_BUSY iNewStatus = ID_STATUS_OCCUPIED; break; -#endif + #endif case ID_STATUS_OUTTOLUNCH: case ID_STATUS_NA: @@ -527,39 +509,35 @@ int __cdecl CAimProto::SetStatus(int iNewStatus) if (iNewStatus == m_iStatus) return 0; - if (iNewStatus == ID_STATUS_OFFLINE) - { + if (iNewStatus == ID_STATUS_OFFLINE) { broadcast_status(ID_STATUS_OFFLINE); return 0; } m_iDesiredStatus = iNewStatus; - if (m_iStatus == ID_STATUS_OFFLINE) - { + if (m_iStatus == ID_STATUS_OFFLINE) { broadcast_status(ID_STATUS_CONNECTING); ForkThread(&CAimProto::start_connection, (void*)iNewStatus); } - else if (m_iStatus > ID_STATUS_OFFLINE) - { - switch(iNewStatus) - { + else if (m_iStatus > ID_STATUS_OFFLINE) { + switch (iNewStatus) { case ID_STATUS_ONLINE: - aim_set_status(hServerConn, seqno, AIM_STATUS_ONLINE); + aim_set_status(m_hServerConn, m_seqno, AIM_STATUS_ONLINE); broadcast_status(ID_STATUS_ONLINE); break; case ID_STATUS_INVISIBLE: - aim_set_status(hServerConn, seqno, AIM_STATUS_INVISIBLE); + aim_set_status(m_hServerConn, m_seqno, AIM_STATUS_INVISIBLE); broadcast_status(ID_STATUS_INVISIBLE); break; case ID_STATUS_OCCUPIED: - aim_set_status(hServerConn, seqno, AIM_STATUS_BUSY | AIM_STATUS_AWAY); + aim_set_status(m_hServerConn, m_seqno, AIM_STATUS_BUSY | AIM_STATUS_AWAY); broadcast_status(ID_STATUS_OCCUPIED); break; case ID_STATUS_AWAY: - aim_set_status(hServerConn, seqno, AIM_STATUS_AWAY); + aim_set_status(m_hServerConn, m_seqno, AIM_STATUS_AWAY); broadcast_status(ID_STATUS_AWAY); break; } @@ -586,7 +564,7 @@ void __cdecl CAimProto::get_online_msg_thread(void* arg) HANDLE __cdecl CAimProto::GetAwayMsg(MCONTACT hContact) { - if (state != 1) + if (m_state != 1) return 0; int status = getWord(hContact, AIM_KEY_ST, ID_STATUS_OFFLINE); @@ -617,14 +595,13 @@ int __cdecl CAimProto::RecvAwayMsg(MCONTACT hContact, int, PROTORECVEVENT* pre) int __cdecl CAimProto::SetAwayMsg(int status, const TCHAR* msg) { - char** msgptr = get_status_msg_loc(status); + char **msgptr = get_status_msg_loc(status); if (msgptr == NULL) return 1; - char* nmsg = mir_utf8encodeT(msg); + char *nmsg = mir_utf8encodeT(msg); mir_free(*msgptr); *msgptr = nmsg; - switch (status) - { + switch (status) { case ID_STATUS_FREECHAT: status = ID_STATUS_ONLINE; break; @@ -632,10 +609,10 @@ int __cdecl CAimProto::SetAwayMsg(int status, const TCHAR* msg) case ID_STATUS_DND: case ID_STATUS_OCCUPIED: case ID_STATUS_ONTHEPHONE: -#ifdef ALLOW_BUSY + #ifdef ALLOW_BUSY status = ID_STATUS_OCCUPIED; break; -#endif + #endif case ID_STATUS_OUTTOLUNCH: case ID_STATUS_NA: @@ -643,15 +620,13 @@ int __cdecl CAimProto::SetAwayMsg(int status, const TCHAR* msg) break; } - if (state == 1 && status == m_iStatus) - { - if (!mir_strcmp(last_status_msg, nmsg)) + if (m_state == 1 && status == m_iStatus) { + if (!mir_strcmp(m_last_status_msg, nmsg)) return 0; - mir_free(last_status_msg); - last_status_msg = mir_strdup(nmsg); - aim_set_statusmsg(hServerConn, seqno, nmsg); - aim_set_away(hServerConn, seqno, nmsg, + replaceStr(m_last_status_msg, nmsg); + aim_set_statusmsg(m_hServerConn, m_seqno, nmsg); + aim_set_away(m_hServerConn, m_seqno, nmsg, status == ID_STATUS_AWAY || status == ID_STATUS_OCCUPIED); } return 0; @@ -662,18 +637,18 @@ int __cdecl CAimProto::SetAwayMsg(int status, const TCHAR* msg) int __cdecl CAimProto::UserIsTyping(MCONTACT hContact, int type) { - if (state != 1) return 0; + if (m_state != 1) + return 0; if (getWord(hContact, AIM_KEY_ST, ID_STATUS_OFFLINE) == ID_STATUS_ONTHEPHONE) return 0; DBVARIANT dbv; - if (!getBool(hContact, AIM_KEY_BLS, false) && !getString(hContact, AIM_KEY_SN, &dbv)) - { + if (!getBool(hContact, AIM_KEY_BLS, false) && !getString(hContact, AIM_KEY_SN, &dbv)) { if (type == PROTOTYPE_SELFTYPING_ON) - aim_typing_notification(hServerConn, seqno, dbv.pszVal, 0x0002); + aim_typing_notification(m_hServerConn, m_seqno, dbv.pszVal, 0x0002); else if (type == PROTOTYPE_SELFTYPING_OFF) - aim_typing_notification(hServerConn, seqno, dbv.pszVal, 0x0000); + aim_typing_notification(m_hServerConn, m_seqno, dbv.pszVal, 0x0000); db_free(&dbv); } return 0; @@ -696,11 +671,9 @@ int __cdecl CAimProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM l return OnOptionsInit(wParam, lParam); case EV_PROTO_ONERASE: - { - char szDbsettings[64]; - mir_snprintf(szDbsettings, _countof(szDbsettings), "%sP2P", m_szModuleName); - CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbsettings); - } + char szDbsettings[64]; + mir_snprintf(szDbsettings, _countof(szDbsettings), "%sP2P", m_szModuleName); + CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbsettings); break; case EV_PROTO_ONCONTACTDELETED: diff --git a/protocols/AimOscar/src/proto.h b/protocols/AimOscar/src/proto.h index ea4688b1ef..10e49759a5 100644 --- a/protocols/AimOscar/src/proto.h +++ b/protocols/AimOscar/src/proto.h @@ -108,89 +108,88 @@ struct CAimProto : public PROTO char* ADMIN_COOKIE; int ADMIN_COOKIE_LENGTH; - char *username; - unsigned short seqno;//main connection sequence number - int state;//m_iStatus of the connection; e.g. whether connected or not - unsigned short port; + char *m_username; + unsigned short m_seqno;//main connection sequence number + int m_state;//m_iStatus of the connection; e.g. whether connected or not + unsigned short m_port; //Some bools to keep track of different things - bool request_HTML_profile; - bool request_away_message; - bool extra_icons_loaded; - bool idle; - bool instantidle; - bool list_received; + bool m_request_HTML_profile; + bool m_request_away_message; + bool m_extra_icons_loaded; + bool m_idle; + bool m_instantidle; + bool m_list_received; //Some main connection stuff - HANDLE hServerConn;//handle to the main connection + HANDLE m_hServerConn; // handle to the main connection - unsigned long internal_ip; // our ip - unsigned long detected_ip; // our ip - unsigned short local_port; // our port + unsigned long m_internal_ip; // our ip + unsigned long m_detected_ip; // our ip + unsigned short m_local_port; // our port //Peer connection stuff - HANDLE hNetlibPeer;//handle to the peer netlib - HANDLE hDirectBoundPort;//direct connection listening port + HANDLE m_hNetlibPeer;//handle to the peer netlib + HANDLE m_hDirectBoundPort;//direct connection listening port //Handles for the context menu items - HGENMENU hHTMLAwayContextMenuItem; - HGENMENU hAddToServerListContextMenuItem; - HGENMENU hBlockContextMenuItem; - HGENMENU hMainMenu[3]; + HGENMENU m_hHTMLAwayContextMenuItem; + HGENMENU m_hAddToServerListContextMenuItem; + HGENMENU m_hBlockContextMenuItem; + HGENMENU m_hMainMenu[3]; //Some mail connection stuff - HANDLE hMailConn; - unsigned short mail_seqno; + HANDLE m_hMailConn; + unsigned short m_mail_seqno; //avatar connection stuff - unsigned short avatar_seqno; - unsigned short avatar_id_sm; - unsigned short avatar_id_lg; - HANDLE hAvatarConn; - HANDLE hAvatarEvent; + unsigned short m_avatar_seqno; + unsigned short m_avatar_id_sm; + unsigned short m_avatar_id_lg; + HANDLE m_hAvatarConn; + HANDLE m_hAvatarEvent; - ft_list_type ft_list; + ft_list_type m_ft_list; //chatnav connection stuff - unsigned short chatnav_seqno; - HANDLE hChatNavConn; - HANDLE hChatNavEvent; + unsigned short m_chatnav_seqno; + HANDLE m_hChatNavConn; + HANDLE m_hChatNavEvent; char MAX_ROOMS; - OBJLIST chat_rooms; + OBJLIST m_chat_rooms; //admin connection stuff - unsigned short admin_seqno; - HANDLE hAdminConn; - HANDLE hAdminEvent; + unsigned short m_admin_seqno; + HANDLE m_hAdminConn; + HANDLE m_hAdminEvent; // privacy settings - unsigned long pd_flags; - unsigned short pd_info_id; - char pd_mode; + unsigned long m_pd_flags; + unsigned short m_pd_info_id; + char m_pd_mode; // prefernces - unsigned short pref1_id; - unsigned long pref1_flags; - unsigned long pref1_set_flags; - unsigned long pref2_len; - unsigned long pref2_set_len; - char *pref2_flags; - char *pref2_set_flags; - - BdList allow_list; - BdList block_list; - - BdList group_list; + unsigned short m_pref1_id; + unsigned long m_pref1_flags; + unsigned long m_pref1_set_flags; + unsigned long m_pref2_len; + unsigned long m_pref2_set_len; + char *m_pref2_flags; + char *m_pref2_set_flags; + + BdList m_allow_list; + BdList m_block_list; + BdList m_group_list; //away message retrieval stuff - char *modeMsgs[9]; - char *last_status_msg; + char *m_modeMsgs[9]; + char *m_last_status_msg; ////////////////////////////////////////////////////////////////////////////////////// // avatars.cpp - char *hash_sm, *hash_lg; + char *m_hash_sm, *m_hash_lg; void __cdecl avatar_request_thread( void* param ); void __cdecl avatar_upload_thread( void* param ); diff --git a/protocols/AimOscar/src/proxy.cpp b/protocols/AimOscar/src/proxy.cpp index 3ed34d54af..35076518ae 100644 --- a/protocols/AimOscar/src/proxy.cpp +++ b/protocols/AimOscar/src/proxy.cpp @@ -24,12 +24,12 @@ void __cdecl CAimProto::aim_proxy_helper(void* param) if (ft->requester) { - if (proxy_initialize_send(ft->hConn, username, ft->icbm_cookie)) + if (proxy_initialize_send(ft->hConn, m_username, ft->icbm_cookie)) return;//error } else { - if (proxy_initialize_recv(ft->hConn, username, ft->icbm_cookie, ft->port)) + if (proxy_initialize_recv(ft->hConn, m_username, ft->icbm_cookie, ft->port)) return;//error } @@ -89,14 +89,14 @@ void __cdecl CAimProto::aim_proxy_helper(void* param) unsigned short port = _htons(*(unsigned short*)&packetRecv.buffer[12]); unsigned long ip = _htonl(*(unsigned long*)&packetRecv.buffer[14]); - aim_send_file(hServerConn, seqno, ip, port, true, ft); + aim_send_file(m_hServerConn, m_seqno, ip, port, true, ft); debugLogA("Stage %d Proxy ft and we are not the sender.", ft->req_num); } else if (type == 0x0005) { if (!ft->requester) { - aim_file_ad(hServerConn, seqno, ft->sn, ft->icbm_cookie, false, ft->max_ver); + aim_file_ad(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie, false, ft->max_ver); ft->accepted = true; } @@ -131,7 +131,7 @@ void __cdecl CAimProto::aim_proxy_helper(void* param) Netlib_CloseHandle(hServerPacketRecver); Netlib_CloseHandle(ft->hConn); - ft_list.remove_by_ft(ft); + m_ft_list.remove_by_ft(ft); } diff --git a/protocols/AimOscar/src/server.cpp b/protocols/AimOscar/src/server.cpp index 15d9e4babe..a69a768d25 100644 --- a/protocols/AimOscar/src/server.cpp +++ b/protocols/AimOscar/src/server.cpp @@ -16,13 +16,14 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" -void CAimProto::snac_md5_authkey(SNAC &snac,HANDLE hServerConn,unsigned short &seqno, const char* username, const char* password)//family 0x0017 +void CAimProto::snac_md5_authkey(SNAC &snac, HANDLE hServerConn, unsigned short &seqno, const char* username, const char* password)//family 0x0017 { if (snac.subcmp(0x0007))//md5 authkey string { - unsigned short length=snac.ushort(); + unsigned short length = snac.ushort(); char* authkey = snac.part(2, length); aim_auth_request(hServerConn, seqno, authkey, AIM_LANGUAGE, AIM_COUNTRY, username, password); mir_free(authkey); @@ -32,31 +33,27 @@ void CAimProto::snac_md5_authkey(SNAC &snac,HANDLE hServerConn,unsigned short &s int CAimProto::snac_authorization_reply(SNAC &snac)//family 0x0017 { int res = 0; - - if (snac.subcmp(0x0003)) - { + + if (snac.subcmp(0x0003)) { char* server = NULL; int address = 0; unsigned short port; unsigned char use_ssl = 0; - while (address < snac.len()) - { + while (address < snac.len()) { TLV tlv(snac.val(address)); if (tlv.cmp(0x0005)) server = tlv.dup(); - else if (tlv.cmp(0x0006)) - { - Netlib_CloseHandle(hServerConn); + else if (tlv.cmp(0x0006)) { + Netlib_CloseHandle(m_hServerConn); if (server == NULL) return 3; char* delim = strchr(server, ':'); port = delim ? (unsigned short)atoi(delim + 1) : get_default_port(); if (delim) *delim = 0; - hServerConn = aim_connect(server, port, use_ssl != 0, "bos.oscar.aol.com"); - if (hServerConn) - { + m_hServerConn = aim_connect(server, port, use_ssl != 0, "bos.oscar.aol.com"); + if (m_hServerConn) { mir_free(COOKIE); COOKIE_LENGTH = tlv.len(); COOKIE = tlv.dup(); @@ -67,138 +64,125 @@ int CAimProto::snac_authorization_reply(SNAC &snac)//family 0x0017 res = 3; break; } - else if (tlv.cmp(0x0008)) - { + else if (tlv.cmp(0x0008)) { login_error(tlv.ushort()); res = 2; break; } - else if (tlv.cmp(0x0011)) - { + else if (tlv.cmp(0x0011)) { char* email = tlv.dup(); setString(AIM_KEY_EM, email); mir_free(email); } - else if (tlv.cmp(0x008e)) - { + else if (tlv.cmp(0x008e)) { use_ssl = tlv.ubyte(); } address += tlv.len() + 4; } mir_free(server); - } + } return res; } -void CAimProto::snac_supported_families(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0001 +void CAimProto::snac_supported_families(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0001 { if (snac.subcmp(0x0003))//server supported service list { - aim_send_service_request(hServerConn,seqno); + aim_send_service_request(hServerConn, seqno); } } -void CAimProto::snac_supported_family_versions(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0001 +void CAimProto::snac_supported_family_versions(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0001 { if (snac.subcmp(0x0018))//service list okayed { - aim_request_rates(hServerConn,seqno);//request some rate crap + aim_request_rates(hServerConn, seqno);//request some rate crap } } -void CAimProto::snac_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_request_icbm(hServerConn,seqno); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_request_icbm(hServerConn, seqno); } } -void CAimProto::snac_mail_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_mail_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_request_mail(hServerConn,seqno); - aim_activate_mail(hServerConn,seqno); - aim_mail_ready(hServerConn,seqno); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_request_mail(hServerConn, seqno); + aim_activate_mail(hServerConn, seqno); + aim_mail_ready(hServerConn, seqno); } } -void CAimProto::snac_avatar_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_avatar_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_avatar_ready(hServerConn,seqno); - SetEvent(hAvatarEvent); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_avatar_ready(hServerConn, seqno); + SetEvent(m_hAvatarEvent); } } -void CAimProto::snac_chatnav_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_chatnav_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_chatnav_request_limits(hChatNavConn,chatnav_seqno); // Get the max number of rooms we're allowed in. + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_chatnav_request_limits(m_hChatNavConn, m_chatnav_seqno); // Get the max number of rooms we're allowed in. } } -void CAimProto::snac_chat_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_chat_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_chat_ready(hServerConn,seqno); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_chat_ready(hServerConn, seqno); } } -void CAimProto::snac_icbm_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0004 +void CAimProto::snac_icbm_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0004 { - if (snac.subcmp(0x0005)) - { - switch (m_iDesiredStatus) - { + if (snac.subcmp(0x0005)) { + switch (m_iDesiredStatus) { case ID_STATUS_ONLINE: broadcast_status(ID_STATUS_ONLINE); - aim_set_status(hServerConn,seqno,AIM_STATUS_ONLINE); + aim_set_status(hServerConn, seqno, AIM_STATUS_ONLINE); break; case ID_STATUS_INVISIBLE: broadcast_status(ID_STATUS_INVISIBLE); - aim_set_status(hServerConn,seqno,AIM_STATUS_INVISIBLE); + aim_set_status(hServerConn, seqno, AIM_STATUS_INVISIBLE); break; case ID_STATUS_OCCUPIED: broadcast_status(ID_STATUS_OCCUPIED); - aim_set_status(hServerConn,seqno,AIM_STATUS_BUSY|AIM_STATUS_AWAY); + aim_set_status(hServerConn, seqno, AIM_STATUS_BUSY | AIM_STATUS_AWAY); break; case ID_STATUS_AWAY: broadcast_status(ID_STATUS_AWAY); - aim_set_status(hServerConn,seqno,AIM_STATUS_AWAY); + aim_set_status(hServerConn, seqno, AIM_STATUS_AWAY); break; } char** msgptr = get_status_msg_loc(m_iDesiredStatus); - mir_free(last_status_msg); - last_status_msg = msgptr ? mir_strdup(*msgptr) : NULL; - aim_set_statusmsg(hServerConn, seqno, last_status_msg); + replaceStr(m_last_status_msg, msgptr ? *msgptr: NULL); + aim_set_statusmsg(hServerConn, seqno, m_last_status_msg); if (m_iDesiredStatus == ID_STATUS_AWAY) - aim_set_away(hServerConn, seqno, last_status_msg, true); + aim_set_away(hServerConn, seqno, m_last_status_msg, true); - if (getByte(AIM_KEY_II,0)) - { + if (getByte(AIM_KEY_II, 0)) { unsigned long time = getDword(AIM_KEY_IIT, 0); - aim_set_idle(hServerConn,seqno,time*60); - instantidle=1; + aim_set_idle(hServerConn, seqno, time * 60); + m_instantidle = 1; } - aim_request_list(hServerConn,seqno); + aim_request_list(hServerConn, seqno); } } void CAimProto::snac_self_info(SNAC &snac)//family 0x0001 { - if (snac.subcmp(0x000f)) - { + if (snac.subcmp(0x000f)) { int offset = snac.flags() & 0x8000 ? snac.ushort(0) + 2 : 0; unsigned char sn_len = snac.ubyte(offset++); @@ -208,14 +192,12 @@ void CAimProto::snac_self_info(SNAC &snac)//family 0x0001 int tlv_count = snac.ushort(offset); offset += 2; - for (int i = 0; i < tlv_count; i++) - { + for (int i = 0; i < tlv_count; i++) { TLV tlv(snac.val(offset)); offset += TLV_HEADER_SIZE + tlv.len(); - if (tlv.cmp(0x000a)) - { - detected_ip = tlv.ulong(); + if (tlv.cmp(0x000a)) { + m_detected_ip = tlv.ulong(); } } mir_free(sn); @@ -224,8 +206,7 @@ void CAimProto::snac_self_info(SNAC &snac)//family 0x0001 void CAimProto::snac_user_online(SNAC &snac)//family 0x0003 { - if (snac.subcmp(0x000b)) - { + if (snac.subcmp(0x000b)) { char client[100] = ""; bool hiptop_user = false; bool bot_user = false; @@ -244,53 +225,48 @@ void CAimProto::snac_user_online(SNAC &snac)//family 0x0003 int tlv_count = snac.ushort(offset); offset += 2; - for (int i = 0; i < tlv_count; i++) - { + for (int i = 0; i < tlv_count; i++) { TLV tlv(snac.val(offset)); offset += TLV_HEADER_SIZE; - if (tlv.cmp(0x0001))//user m_iStatus - { + if (tlv.cmp(0x0001)) { // user m_iStatus unsigned short status = tlv.ushort(); int unconfirmed = status & 0x0001; - int admin_aol = status & 0x0002; - int aol = status & 0x0004; + int admin_aol = status & 0x0002; + int aol = status & 0x0004; //int nonfree = status & 0x0008; //int aim = status & 0x0010; - int away = status & 0x0020; - int icq = status & 0x0040; - int wireless = status & 0x0080; - int bot = status & 0x0400; + int away = status & 0x0020; + int icq = status & 0x0040; + int wireless = status & 0x0080; + int bot = status & 0x0400; setString(hContact, AIM_KEY_NK, sn); if (icq) setString(hContact, "Transport", "ICQ"); else - delSetting(hContact, "Transport" ); + delSetting(hContact, "Transport"); if (admin_aol) setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_ADMIN); else if (aol) - setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_AOL); + setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_AOL); else if (icq) - setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_ICQ); + setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_ICQ); else if (unconfirmed) setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_UNCONFIRMED); else setByte(hContact, AIM_KEY_AC, ACCOUNT_TYPE_CONFIRMED); - if (bot) - { - mir_strcpy(client,CLIENT_BOT); - bot_user=1; + if (bot) { + mir_strcpy(client, CLIENT_BOT); + bot_user = 1; } - if (wireless) - { - mir_strcpy(client,CLIENT_SMS); - wireless_user=1; + if (wireless) { + mir_strcpy(client, CLIENT_SMS); + wireless_user = 1; } - else if (away) - { - away_user=1; + else if (away) { + away_user = 1; } setDword(hContact, AIM_KEY_IT, 0);//erase idle time setDword(hContact, AIM_KEY_OT, 0);//erase online time @@ -299,241 +275,215 @@ void CAimProto::snac_user_online(SNAC &snac)//family 0x0003 { status_type = tlv.ulong() & 0x00000FFF; } - else if (tlv.cmp(0x000d)) - { + else if (tlv.cmp(0x000d)) { caps_included = true; - for(int i = 0; i 2) - { - unsigned short len = tlv.ushort(i + 4); - if (len) - { + if ((flags & 4) && datalen > 2) { + unsigned short len = tlv.ushort(k + 4); + if (len) { msg_exist = true; - char* msg = tlv.part(i + 6, len); + char* msg = tlv.part(k + 6, len); char* msg_s = process_status_msg(msg, sn); db_set_utf(hContact, MOD_KEY_CL, OTH_KEY_SM, msg_s); @@ -546,32 +496,28 @@ void CAimProto::snac_user_online(SNAC &snac)//family 0x0003 } break; } - i += 4 + datalen; + k += 4 + datalen; } if (!msg_exist) db_unset(hContact, MOD_KEY_CL, OTH_KEY_SM); } } - else if (tlv.cmp(0x0004))//idle tlv - { - if (hContact) - { + else if (tlv.cmp(0x0004)) { //idle tlv + if (hContact) { time_t current_time; time(¤t_time); setDword(hContact, AIM_KEY_IT, ((DWORD)current_time) - tlv.ushort() * 60); } } - else if (tlv.cmp(0x0003))//online time tlv - { + else if (tlv.cmp(0x0003)) { // online time tlv if (hContact) setDword(hContact, AIM_KEY_OT, tlv.ulong()); } - else if (tlv.cmp(0x0005))//member since - { - if (hContact) - setDword(hContact, AIM_KEY_MS, tlv.ulong()); - } + else if (tlv.cmp(0x0005)) { // member since + if (hContact) + setDword(hContact, AIM_KEY_MS, tlv.ulong()); + } offset += tlv.len(); } @@ -617,10 +563,10 @@ void CAimProto::snac_user_offline(SNAC &snac)//family 0x0003 { if (snac.subcmp(0x000c)) { unsigned char buddy_length = snac.ubyte(); - char* buddy=snac.part(1,buddy_length); - MCONTACT hContact=contact_from_sn(buddy, true); + char* buddy = snac.part(1, buddy_length); + MCONTACT hContact = contact_from_sn(buddy, true); if (hContact) - offline_contact(hContact,0); + offline_contact(hContact, 0); mir_free(buddy); } } @@ -633,12 +579,12 @@ void CAimProto::snac_error(SNAC &snac)//family 0x0003 or 0x0004 void CAimProto::process_ssi_list(SNAC &snac, int &offset) { unsigned short name_length = snac.ushort(offset); - char* name = snac.part(offset+2, name_length); - unsigned short group_id = snac.ushort(offset+ 2 +name_length); - unsigned short item_id = snac.ushort(offset+4+name_length); - unsigned short type = snac.ushort(offset+6+name_length); - unsigned short tlv_size = snac.ushort(offset+8+name_length); - const int tlv_base = offset + name_length + 10; + char* name = snac.part(offset + 2, name_length); + unsigned short group_id = snac.ushort(offset + 2 + name_length); + unsigned short item_id = snac.ushort(offset + 4 + name_length); + unsigned short type = snac.ushort(offset + 6 + name_length); + unsigned short tlv_size = snac.ushort(offset + 8 + name_length); + const int tlv_base = offset + name_length + 10; switch (type) { case 0x0000: //buddy record @@ -654,7 +600,7 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) } } if (i == 1 && getByte(AIM_KEY_MG, 1)) { - const char* group = group_list.find_name(group_id); + const char* group = m_group_list.find_name(group_id); if (group) { bool ok = false; DBVARIANT dbv; @@ -694,36 +640,36 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) if (!nickfound && getDword(AIM_KEY_LV, 0) >= 0x80500) db_unset(hContact, MOD_KEY_CL, "MyHandle"); } - } + } break; case 0x0001: //group record if (group_id) { - group_list.add(name, group_id); + m_group_list.add(name, group_id); if (getByte(AIM_KEY_MG, 1)) create_group(name); } break; case 0x0002: //permit record - allow_list.add(name, item_id); + m_allow_list.add(name, item_id); break; case 0x0003: //deny record - block_list.add(name, item_id); + m_block_list.add(name, item_id); break; case 0x0004: //privacy record if (group_id == 0) { - pd_info_id = item_id; + m_pd_info_id = item_id; for (int tlv_offset = 0; tlv_offset < tlv_size;) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00ca)) - pd_mode = tlv.ubyte(); + m_pd_mode = tlv.ubyte(); else if (tlv.cmp(0x00cc)) - pd_flags = tlv.ulong(); + m_pd_flags = tlv.ulong(); tlv_offset += TLV_HEADER_SIZE + tlv.len(); } @@ -732,24 +678,24 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) case 0x0005: //prefernces record if (group_id == 0) { - pref1_id = item_id; + m_pref1_id = item_id; for (int tlv_offset = 0; tlv_offset < tlv_size;) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00c9)) - pref1_flags = tlv.ulong(); + m_pref1_flags = tlv.ulong(); else if (tlv.cmp(0x00d6)) - pref1_set_flags = tlv.ulong(); + m_pref1_set_flags = tlv.ulong(); else if (tlv.cmp(0x00d7)) { - mir_free(pref2_flags); - pref2_flags = tlv.dup(); - pref2_len = tlv.len(); + mir_free(m_pref2_flags); + m_pref2_flags = tlv.dup(); + m_pref2_len = tlv.len(); } else if (tlv.cmp(0x00d8)) { - mir_free(pref2_set_flags); - pref2_set_flags = tlv.dup(); - pref2_set_len = tlv.len(); + mir_free(m_pref2_set_flags); + m_pref2_set_flags = tlv.dup(); + m_pref2_set_len = tlv.len(); } tlv_offset += TLV_HEADER_SIZE + tlv.len(); @@ -760,27 +706,27 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) case 0x0014: //avatar record if (!mir_strcmp(name, "1") || !mir_strcmp(name, "12")) { if (name_length == 1) - avatar_id_sm = item_id; + m_avatar_id_sm = item_id; else - avatar_id_lg = item_id; + m_avatar_id_lg = item_id; for (int tlv_offset = 0; tlv_offset < tlv_size;) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00d5) && tlv.len() > 2) { if (name_length == 1) { - mir_free(hash_sm); - hash_sm = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); + mir_free(m_hash_sm); + m_hash_sm = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); } else { - mir_free(hash_lg); - hash_lg = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); + mir_free(m_hash_lg); + m_hash_lg = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); } } tlv_offset += TLV_HEADER_SIZE + tlv.len(); } - if (list_received) + if (m_list_received) avatar_request_handler(NULL, NULL, 0); } break; @@ -813,26 +759,22 @@ void CAimProto::process_ssi_list(SNAC &snac, int &offset) void CAimProto::modify_ssi_list(SNAC &snac, int &offset) { unsigned short name_length = snac.ushort(offset); - char* name = snac.part(offset+2, name_length); - unsigned short group_id = snac.ushort(offset+ 2 +name_length); - unsigned short item_id = snac.ushort(offset+4+name_length); - unsigned short type = snac.ushort(offset+6+name_length); - unsigned short tlv_size = snac.ushort(offset+8+name_length); - const int tlv_base = offset + name_length + 10; - - switch (type) - { + char* name = snac.part(offset + 2, name_length); + unsigned short group_id = snac.ushort(offset + 2 + name_length); + unsigned short item_id = snac.ushort(offset + 4 + name_length); + unsigned short type = snac.ushort(offset + 6 + name_length); + unsigned short tlv_size = snac.ushort(offset + 8 + name_length); + const int tlv_base = offset + name_length + 10; + + switch (type) { case 0x0000: //buddy record { MCONTACT hContact = contact_from_sn(name, true); - if (hContact) - { - for (int tlv_offset = 0; tlv_offset < tlv_size; ) - { + if (hContact) { + for (int tlv_offset = 0; tlv_offset < tlv_size; ) { TLV tlv(snac.val(tlv_base + tlv_offset)); - if (tlv.cmp(0x0131) && tlv.len()) - { + if (tlv.cmp(0x0131) && tlv.len()) { char* nick = tlv.dup(); if (nick) db_set_utf(hContact, MOD_KEY_CL, "MyHandle", nick); @@ -848,18 +790,16 @@ void CAimProto::modify_ssi_list(SNAC &snac, int &offset) } case 0x0004: //privacy record - if (group_id == 0) - { - pd_info_id = item_id; + if (group_id == 0) { + m_pd_info_id = item_id; - for (int tlv_offset = 0; tlv_offset < tlv_size; ) - { + for (int tlv_offset = 0; tlv_offset < tlv_size; ) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00ca)) - pd_mode = tlv.ubyte(); + m_pd_mode = tlv.ubyte(); else if (tlv.cmp(0x00cc)) - pd_flags = tlv.ulong(); + m_pd_flags = tlv.ulong(); tlv_offset += TLV_HEADER_SIZE + tlv.len(); } @@ -867,29 +807,25 @@ void CAimProto::modify_ssi_list(SNAC &snac, int &offset) break; case 0x0005: //prefernces record - if (group_id == 0) - { - pref1_id = item_id; + if (group_id == 0) { + m_pref1_id = item_id; - for (int tlv_offset = 0; tlv_offset < tlv_size; ) - { + for (int tlv_offset = 0; tlv_offset < tlv_size; ) { TLV tlv(snac.val(tlv_base + tlv_offset)); if (tlv.cmp(0x00c9)) - pref1_flags = tlv.ulong(); + m_pref1_flags = tlv.ulong(); else if (tlv.cmp(0x00d6)) - pref1_set_flags = tlv.ulong(); - else if (tlv.cmp(0x00d7)) - { - mir_free(pref2_flags); - pref2_flags = tlv.dup(); - pref2_len = tlv.len(); + m_pref1_set_flags = tlv.ulong(); + else if (tlv.cmp(0x00d7)) { + mir_free(m_pref2_flags); + m_pref2_flags = tlv.dup(); + m_pref2_len = tlv.len(); } - else if (tlv.cmp(0x00d8)) - { - mir_free(pref2_set_flags); - pref2_set_flags = tlv.dup(); - pref2_set_len = tlv.len(); + else if (tlv.cmp(0x00d8)) { + mir_free(m_pref2_set_flags); + m_pref2_set_flags = tlv.dup(); + m_pref2_set_len = tlv.len(); } tlv_offset += TLV_HEADER_SIZE + tlv.len(); @@ -898,29 +834,24 @@ void CAimProto::modify_ssi_list(SNAC &snac, int &offset) break; case 0x0014: //avatar record - if (!mir_strcmp(name, "1") || !mir_strcmp(name, "12")) - { + if (!mir_strcmp(name, "1") || !mir_strcmp(name, "12")) { if (name_length == 1) - avatar_id_sm = item_id; + m_avatar_id_sm = item_id; else - avatar_id_lg = item_id; + m_avatar_id_lg = item_id; - for (int tlv_offset = 0; tlv_offset < tlv_size; ) - { - TLV tlv(snac.val( tlv_base + tlv_offset)); + for (int tlv_offset = 0; tlv_offset < tlv_size; ) { + TLV tlv(snac.val(tlv_base + tlv_offset)); - if (tlv.cmp(0x00d5) && tlv.len() > 2) - { -// unsigned char type = tlv.ubyte(0); - if (name_length == 1) - { - mir_free(hash_sm); - hash_sm = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); + if (tlv.cmp(0x00d5) && tlv.len() > 2) { + // unsigned char type = tlv.ubyte(0); + if (name_length == 1) { + mir_free(m_hash_sm); + m_hash_sm = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); } - else - { - mir_free(hash_lg); - hash_lg = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); + else { + mir_free(m_hash_lg); + m_hash_lg = bytes_to_string(tlv.val() + 2, tlv.ubyte(1)); } } tlv_offset += TLV_HEADER_SIZE + tlv.len(); @@ -937,23 +868,21 @@ void CAimProto::delete_ssi_list(SNAC &snac, int &offset) { int i; - unsigned short name_length=snac.ushort(offset); - char* name=snac.part(offset+2,name_length); - unsigned short group_id=snac.ushort(offset+2+name_length); - unsigned short item_id=snac.ushort(offset+4+name_length); - unsigned short type=snac.ushort(offset+6+name_length); + unsigned short name_length = snac.ushort(offset); + char* name = snac.part(offset + 2, name_length); + unsigned short group_id = snac.ushort(offset + 2 + name_length); + unsigned short item_id = snac.ushort(offset + 4 + name_length); + unsigned short type = snac.ushort(offset + 6 + name_length); MCONTACT hContact = contact_from_sn(name); switch (type) { case 0x0000: //buddy record - for(i=1;;++i) - { + for (i = 1;; ++i) { unsigned short item_id_st = getBuddyId(hContact, i); if (item_id_st == 0) break; - if (item_id == item_id_st) - { + if (item_id == item_id_st) { deleteBuddyId(hContact, i); deleteGroupId(hContact, i); --i; @@ -964,60 +893,55 @@ void CAimProto::delete_ssi_list(SNAC &snac, int &offset) break; case 0x0001: //group record - group_list.remove_by_id(group_id); + m_group_list.remove_by_id(group_id); break; case 0x0014: //avatar record - if (mir_strcmp(name, "1")) - { - avatar_id_sm = 0; - mir_free(hash_sm); - hash_sm = NULL; + if (mir_strcmp(name, "1")) { + m_avatar_id_sm = 0; + mir_free(m_hash_sm); + m_hash_sm = NULL; } - else if (!mir_strcmp(name, "12")) - { - avatar_id_lg = 0; - mir_free(hash_lg); - hash_lg = NULL; + else if (!mir_strcmp(name, "12")) { + m_avatar_id_lg = 0; + mir_free(m_hash_lg); + m_hash_lg = NULL; } avatar_request_handler(NULL, NULL, 0); break; } - mir_free(name) ; + mir_free(name); } -void CAimProto::snac_contact_list(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0013 +void CAimProto::snac_contact_list(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0013 { - if (snac.subcmp(0x0006)) //contact list - { + if (snac.subcmp(0x0006)) { //contact list debugLogA("Contact List Received"); -// unsigned char ver = snac.ubyte(); + // unsigned char ver = snac.ubyte(); int num_obj = snac.ushort(1); - int offset=3; - for (int i=0; ihContact = hContact; msg_ack->id = *(int*)icbm_cookie & 0x7fffffff; @@ -1070,60 +988,56 @@ void CAimProto::snac_message_accepted(SNAC &snac)//family 0x004 mir_free(icbm_cookie); } } -void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)//family 0x0004 +void CAimProto::snac_received_message(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)//family 0x0004 { - if (snac.subcmp(0x0007)) - { - unsigned short channel = snac.ushort(8); + if (snac.subcmp(0x0007)) { + unsigned short channel = snac.ushort(8); unsigned char sn_length = snac.ubyte(10); - char* sn = snac.part(11,sn_length); + char *sn = snac.part(11, sn_length); MCONTACT hContact = contact_from_sn(sn, true, true), hMsgContact = NULL; - int offset=15+sn_length; + int offset = 15 + sn_length; - char* msg_buf=NULL; + char *msg_buf = NULL; unsigned long offline_timestamp = 0; bool is_offline = false; //file transfer stuff - char* icbm_cookie = NULL; - char* filename = NULL; - unsigned __int64 file_size=0; - bool auto_response=false; - bool force_proxy=false; - bool descr_included=false; - bool utf_fname=false; - bool unicode_descr=false; - short rdz_msg_type=-1; - unsigned short request_num=0; - unsigned long local_ip=0, verified_ip=0, proxy_ip=0; + char *icbm_cookie = NULL; + char *filename = NULL; + unsigned __int64 file_size = 0; + bool auto_response = false; + bool force_proxy = false; + bool descr_included = false; + bool utf_fname = false; + bool unicode_descr = false; + short rdz_msg_type = -1; + unsigned short request_num = 0; + unsigned long local_ip = 0, verified_ip = 0, proxy_ip = 0; unsigned short port = 0; unsigned short max_ver = 0; unsigned short num_files = 0; //end file transfer stuff - unsigned short tlv_head_num=snac.ushort(offset-2); - for (int i=0;i=snac.len()) break; + if (offset >= snac.len()) break; } - - while (offset < snac.len()) - { + + while (offset < snac.len()) { TLV tlv(snac.val(offset)); offset += TLV_HEADER_SIZE; - if (tlv.cmp(0x0004)&&!tlv.len())//auto response flag + if (tlv.cmp(0x0004) && !tlv.len())//auto response flag auto_response = 1; - if (tlv.cmp(0x0002)) //msg - { - unsigned short caps_length=tlv.ushort(2); - unsigned short msg_length=tlv.ushort(6+caps_length)-4; - unsigned short encoding=tlv.ushort(8+caps_length); - char* buf = tlv.part(12+caps_length,msg_length); + if (tlv.cmp(0x0002)) { // msg + unsigned short caps_length = tlv.ushort(2); + unsigned short msg_length = tlv.ushort(6 + caps_length) - 4; + unsigned short encoding = tlv.ushort(8 + caps_length); + char *buf = tlv.part(12 + caps_length, msg_length); if (hContact) { wchar_t* wbuf; hMsgContact = hContact; @@ -1156,39 +1070,39 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho if (channel == 2 && tlv.cmp(0x0005)) { //recv rendervous packet rdz_msg_type = snac.ushort(offset); - icbm_cookie = snac.part(offset+2,8); - if (cap_cmp(snac.val(offset+10), AIM_CAP_FILE_TRANSFER) == 0) { + icbm_cookie = snac.part(offset + 2, 8); + if (cap_cmp(snac.val(offset + 10), AIM_CAP_FILE_TRANSFER) == 0) { for (int i = 26; i < tlv.len(); ) { - TLV tlv(snac.val(offset+i)); - if (tlv.cmp(0x000A)) - request_num=tlv.ushort();//for file transfer - else if (tlv.cmp(0x0002))//proxy ip - proxy_ip = tlv.ulong(); - else if (tlv.cmp(0x0003))//client ip - local_ip = tlv.ulong(); - else if (tlv.cmp(0x0004))//verified ip - verified_ip = tlv.ulong(); - else if (tlv.cmp(0x0005)) - port=tlv.ushort(); - else if (tlv.cmp(0x0010)) - force_proxy=1; - else if (tlv.cmp(0x0012)) - max_ver = tlv.ushort(); - else if (tlv.cmp(0x2711)) { - num_files = tlv.ushort(2); - file_size = tlv.ulong(4); - filename = tlv.part(8, tlv.len()-8); + TLV tlv2(snac.val(offset + i)); + if (tlv2.cmp(0x000A)) + request_num = tlv2.ushort();//for file transfer + else if (tlv2.cmp(0x0002))//proxy ip + proxy_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0003))//client ip + local_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0004))//verified ip + verified_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0005)) + port = tlv2.ushort(); + else if (tlv2.cmp(0x0010)) + force_proxy = 1; + else if (tlv2.cmp(0x0012)) + max_ver = tlv2.ushort(); + else if (tlv2.cmp(0x2711)) { + num_files = tlv2.ushort(2); + file_size = tlv2.ulong(4); + filename = tlv2.part(8, tlv2.len() - 8); } - else if (tlv.cmp(0x2712)) { - char* enc = tlv.dup(); + else if (tlv2.cmp(0x2712)) { + char *enc = tlv2.dup(); utf_fname = mir_strcmp(enc, "utf-8") == 0; mir_free(enc); } - else if (tlv.cmp(0x2713)) { - file_size = tlv.u64(); + else if (tlv2.cmp(0x2713)) { + file_size = tlv2.u64(); } - else if (tlv.cmp(0x000c)) { - msg_buf = unicode_descr ? tlv.dupw() : tlv.dup(); + else if (tlv2.cmp(0x000c)) { + msg_buf = unicode_descr ? tlv2.dupw() : tlv2.dup(); html_decode(msg_buf); descr_included = true; if (strstr(msg_buf, "")) { @@ -1202,46 +1116,46 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho else descr_included = false; } } - else if (tlv.cmp(0x000d)) { - char* enc = tlv.dup(); + else if (tlv2.cmp(0x000d)) { + char* enc = tlv2.dup(); unicode_descr = mir_strcmp(enc, "unicode-2-0") == 0; mir_free(enc); } - i += TLV_HEADER_SIZE + tlv.len(); + i += TLV_HEADER_SIZE + tlv2.len(); } } - else if (cap_cmp(snac.val(offset+10), AIM_CAP_RTCAUDIO) == 0 || cap_cmp(snac.val(offset+10), AIM_CAP_RTCVIDEO) == 0) { + else if (cap_cmp(snac.val(offset + 10), AIM_CAP_RTCAUDIO) == 0 || cap_cmp(snac.val(offset + 10), AIM_CAP_RTCVIDEO) == 0) { for (int i = 26; i < tlv.len(); ) { - TLV tlv(snac.val(offset+i)); - if (tlv.cmp(0x000A)) - request_num=tlv.ushort();//for file transfer - else if (tlv.cmp(0x0002))//proxy ip - proxy_ip = tlv.ulong(); - else if (tlv.cmp(0x0003))//client ip - local_ip = tlv.ulong(); - else if (tlv.cmp(0x0004))//verified ip - verified_ip = tlv.ulong(); - else if (tlv.cmp(0x0005)) - port=tlv.ushort(); + TLV tlv2(snac.val(offset + i)); + if (tlv2.cmp(0x000A)) + request_num = tlv2.ushort();//for file transfer + else if (tlv2.cmp(0x0002))//proxy ip + proxy_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0003))//client ip + local_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0004))//verified ip + verified_ip = tlv2.ulong(); + else if (tlv2.cmp(0x0005)) + port = tlv2.ushort(); } channel = 0; break; } - else if (cap_cmp(snac.val(offset+10), AIM_CAP_CHAT) == 0) { //it's a chat invite request - for(int i=26; i < tlv.len();) { - TLV tlv(snac.val(offset+i)); - if (tlv.cmp(0x000c)) //optional message - msg_buf = tlv.dup(); - else if (tlv.cmp(0x2711)) { //room information - int cookie_len=tlv.ubyte(2); - chatnav_param* par = - new chatnav_param(tlv.part(3,cookie_len), tlv.ushort(), tlv.ushort(3+cookie_len), - msg_buf, sn, icbm_cookie); + else if (cap_cmp(snac.val(offset + 10), AIM_CAP_CHAT) == 0) { //it's a chat invite request + for (int i = 26; i < tlv.len();) { + TLV tlv2(snac.val(offset + i)); + if (tlv2.cmp(0x000c)) //optional message + msg_buf = tlv2.dup(); + else if (tlv2.cmp(0x2711)) { //room information + int cookie_len = tlv2.ubyte(2); + chatnav_param* par = + new chatnav_param(tlv2.part(3, cookie_len), tlv2.ushort(), tlv2.ushort(3 + cookie_len), + msg_buf, sn, icbm_cookie); invite_chat_req_param* chat_rq = new invite_chat_req_param(par, this, msg_buf, sn, icbm_cookie); CallFunctionAsync(chat_request_cb, chat_rq); } - i+=TLV_HEADER_SIZE+tlv.len(); + i += TLV_HEADER_SIZE + tlv2.len(); } } else { @@ -1251,7 +1165,7 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho } if (channel == 6 && tlv.cmp(0x0005))//audio/video tunnel - msg_buf = tlv.dup(); + msg_buf = tlv.dup(); if (tlv.cmp(0x0006))//Offline message flag is_offline = true; @@ -1281,13 +1195,11 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho ProtoChainRecvMsg(hMsgContact, &pre); } - if (m_iStatus==ID_STATUS_AWAY && !auto_response && !getByte(AIM_KEY_DM,0)) - { + if (m_iStatus == ID_STATUS_AWAY && !auto_response && !getByte(AIM_KEY_DM, 0)) { unsigned long msg_time = getDword(hContact, AIM_KEY_LM, 0); unsigned long away_time = getDword(AIM_KEY_LA, 0); char** msgptr = get_status_msg_loc(m_iStatus); - if (away_time > msg_time && *msgptr) - { + if (away_time > msg_time && *msgptr) { char* s_msg = process_status_msg(*msgptr, sn); T2Utf away(TranslateT("[Auto-Response]:")); @@ -1310,10 +1222,8 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho setDword(hContact, AIM_KEY_LM, (DWORD)time(NULL)); } } - else if (channel == 2) // File Transfer - { - if (rdz_msg_type == 0 && request_num == 1) //buddy wants to send us a file - { + else if (channel == 2) { // File Transfer + if (rdz_msg_type == 0 && request_num == 1) { // buddy wants to send us a file debugLogA("Buddy Wants to Send us a file. Request 1"); debugLogA(force_proxy ? "Forcing a Proxy File transfer." : "Not forcing Proxy File transfer."); @@ -1329,11 +1239,11 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho ft->req_num = request_num; ft->file = mir_strdup(filename); - + ft->pfts.totalBytes = file_size; ft->pfts.totalFiles = num_files; - ft_list.insert(ft); + m_ft_list.insert(ft); if (!descr_included) msg_buf = NULL; @@ -1356,14 +1266,12 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho debugLogA("Verified IP: %s:%u", long_ip_to_char_ip(verified_ip, cip), port); debugLogA("Proxy IP: %s:%u", long_ip_to_char_ip(proxy_ip, cip), port); } - else if (rdz_msg_type == 0) - { + else if (rdz_msg_type == 0) { debugLogA("We are sending a file. Buddy wants us to connect to them. Request %d", request_num); debugLogA(force_proxy ? "Forcing a Proxy File transfer." : "Not forcing Proxy File transfer."); - file_transfer* ft = ft_list.find_by_cookie(icbm_cookie, hContact); - if (ft) - { + file_transfer* ft = m_ft_list.find_by_cookie(icbm_cookie, hContact); + if (ft) { ft->hContact = hContact; ft->me_force_proxy |= (request_num > 2); @@ -1383,31 +1291,26 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho ForkThread(&CAimProto::accept_file_thread, ft); } - else - { + else { debugLogA("Unknown File transfer, thus denied."); aim_file_ad(hServerConn, seqno, sn, icbm_cookie, true, 0); } } - else if (rdz_msg_type == 1)//buddy cancelled or denied file transfer - { + else if (rdz_msg_type == 1) { // buddy cancelled or denied file transfer debugLogA("File transfer cancelled or denied."); - file_transfer* ft = ft_list.find_by_cookie(icbm_cookie, hContact); + file_transfer *ft = m_ft_list.find_by_cookie(icbm_cookie, hContact); ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_DENIED, ft, 0); - ft_list.remove_by_ft(ft); + m_ft_list.remove_by_ft(ft); } - else if (rdz_msg_type == 2)//buddy accepts our file transfer request - { + else if (rdz_msg_type == 2) { // buddy accepts our file transfer request debugLogA("File transfer accepted"); - file_transfer* ft = ft_list.find_by_cookie(icbm_cookie, hContact); - if (ft) - { - ft->accepted = true; + file_transfer *ft = m_ft_list.find_by_cookie(icbm_cookie, hContact); + if (ft) { + ft->accepted = true; ft->max_ver = max_ver; } - else - aim_file_ad(hServerConn, seqno, sn, icbm_cookie, true, 0); + else aim_file_ad(hServerConn, seqno, sn, icbm_cookie, true, 0); } } else if (channel == 6) // Audio/Video call @@ -1425,15 +1328,12 @@ void CAimProto::snac_received_message(SNAC &snac,HANDLE hServerConn,unsigned sho void CAimProto::snac_file_decline(SNAC &snac)//family 0x0004 { - if (snac.subcmp(0x000b)) - { + if (snac.subcmp(0x000b)) { char *icbm_cookie = snac.part(0, 8); int channel = snac.ushort(8); - if (channel == 0x01) - { + if (channel == 0x01) { int sn_len = snac.ubyte(10); - char* sn = snac.part(11, sn_len); -// int reason = snac.ushort(11 + sn_len); + char *sn = snac.part(11, sn_len); MCONTACT hContact = contact_from_sn(sn); msg_ack_param *msg_ack = (msg_ack_param*)mir_alloc(sizeof(msg_ack_param)); @@ -1443,24 +1343,23 @@ void CAimProto::snac_file_decline(SNAC &snac)//family 0x0004 msg_ack->success = false; ForkThread(&CAimProto::msg_ack_success, msg_ack); } - if (channel == 0x02) - { + + if (channel == 0x02) { int sn_len = snac.ubyte(10); - char* sn = snac.part(11, sn_len); + char *sn = snac.part(11, sn_len); int reason = snac.ushort(11 + sn_len); - if (reason == 0x03) - { + if (reason == 0x03) { int error = snac.ushort(13 + sn_len); - if (error == 0x02) - { + if (error == 0x02) { debugLogA("File Transfer declied"); MCONTACT hContact = contact_from_sn(sn); - file_transfer *ft = ft_list.find_by_cookie(icbm_cookie, hContact); - if (ft) - { + file_transfer *ft = m_ft_list.find_by_cookie(icbm_cookie, hContact); + if (ft) { ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_DENIED, ft, 0); - if (ft->hConn) Netlib_Shutdown(ft->hConn); - else ft_list.remove_by_ft(ft); + if (ft->hConn) + Netlib_Shutdown(ft->hConn); + else + m_ft_list.remove_by_ft(ft); } } } @@ -1471,8 +1370,7 @@ void CAimProto::snac_file_decline(SNAC &snac)//family 0x0004 } void CAimProto::snac_received_info(SNAC &snac)//family 0x0002 { - if (snac.subcmp(0x0006)) - { + if (snac.subcmp(0x0006)) { unsigned short offset = 0; int i = 0; bool away_message_received = false; @@ -1486,38 +1384,32 @@ void CAimProto::snac_received_info(SNAC &snac)//family 0x0002 unsigned short tlv_count = snac.ushort(3 + sn_length); offset = 5 + sn_length; MCONTACT hContact = contact_from_sn(sn, true, true); - - while (offset < snac.len()) - { + + while (offset < snac.len()) { TLV tlv(snac.val(offset)); - if (++i > tlv_count) - { - if (tlv.cmp(0x0001))//profile encoding - { - char* enc = tlv.dup(); + if (++i > tlv_count) { + if (tlv.cmp(0x0001)) { //profile encoding + char *enc = tlv.dup(); profile_unicode = strstr(enc, "unicode-2-0") != NULL; profile_utf = strstr(enc, "utf-8") != NULL; mir_free(enc); } - else if (tlv.cmp(0x0002))//profile message string - { - char* msg = profile_unicode ? tlv.dupw() : tlv.dup(); + else if (tlv.cmp(0x0002)) { //profile message string + char *msg = profile_unicode ? tlv.dupw() : tlv.dup(); profile_received = true; write_profile(sn, msg, profile_unicode | profile_utf); mir_free(msg); } - else if (tlv.cmp(0x0003))//away message encoding - { - char* enc = tlv.dup(); + else if (tlv.cmp(0x0003)) { //away message encoding + char *enc = tlv.dup(); away_message_unicode = strstr(enc, "unicode-2-0") != NULL; away_message_utf = strstr(enc, "utf-8") != NULL; mir_free(enc); } - else if (tlv.cmp(0x0004))//away message string - { - char* msg = away_message_unicode ? tlv.dupw() : tlv.dup(); + else if (tlv.cmp(0x0004)) { // away message string + char *msg = away_message_unicode ? tlv.dupw() : tlv.dup(); away_message_received = true; write_away_message(sn, msg, away_message_unicode | away_message_utf); @@ -1526,56 +1418,49 @@ void CAimProto::snac_received_info(SNAC &snac)//family 0x0002 } offset += TLV_HEADER_SIZE + tlv.len(); } - if (hContact) - { - if (getWord(hContact,AIM_KEY_ST,ID_STATUS_OFFLINE) == ID_STATUS_AWAY) - { - if (!away_message_received && request_away_message) - write_away_message(sn,Translate("No information has been provided by the server."),false); - request_away_message = 0; - } - if (!profile_received&&request_HTML_profile) - write_profile(sn,"No Profile",false); - request_HTML_profile=0; + if (hContact) { + if (getWord(hContact, AIM_KEY_ST, ID_STATUS_OFFLINE) == ID_STATUS_AWAY) { + if (!away_message_received && m_request_away_message) + write_away_message(sn, Translate("No information has been provided by the server."), false); + m_request_away_message = 0; + } + if (!profile_received && m_request_HTML_profile) + write_profile(sn, "No Profile", false); + m_request_HTML_profile = 0; } mir_free(sn); } } void CAimProto::snac_typing_notification(SNAC &snac)//family 0x004 { - if (snac.subcmp(0x0014)) - { - unsigned char sn_length=snac.ubyte(10); - char* sn=snac.part(11,sn_length); - MCONTACT hContact=contact_from_sn(sn); - if (hContact) - { - unsigned short type=snac.ushort(11+sn_length); - if (type==0x0000)//typing finished - CallService(MS_PROTO_CONTACTISTYPING,hContact,(WPARAM)PROTOTYPE_CONTACTTYPING_OFF); - else if (type==0x0001)//typed - CallService(MS_PROTO_CONTACTISTYPING,hContact,PROTOTYPE_CONTACTTYPING_INFINITE); - else if (type==0x0002)//typing - CallService(MS_PROTO_CONTACTISTYPING,hContact,(LPARAM)60); + if (snac.subcmp(0x0014)) { + unsigned char sn_length = snac.ubyte(10); + char *sn = snac.part(11, sn_length); + MCONTACT hContact = contact_from_sn(sn); + if (hContact) { + unsigned short type = snac.ushort(11 + sn_length); + if (type == 0x0000)//typing finished + CallService(MS_PROTO_CONTACTISTYPING, hContact, (WPARAM)PROTOTYPE_CONTACTTYPING_OFF); + else if (type == 0x0001)//typed + CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_INFINITE); + else if (type == 0x0002)//typing + CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)60); } mir_free(sn); } } void CAimProto::snac_list_modification_ack(SNAC &snac)//family 0x0013 { - if (snac.subcmp(0x000e)) - { + if (snac.subcmp(0x000e)) { unsigned short id = snac.id(); TLV tlv(snac.val(2)); unsigned short code = snac.ushort(6 + tlv.len()); -// ssi_queue.execute(this, code == 0); - switch (id) - { + + switch (id) { case 0x000a: - switch (code) - { + switch (code) { case 0x0000: -// ShowPopup(LPGEN("Successfully removed buddy from list."), ERROR_POPUP); + // ShowPopup(LPGEN("Successfully removed buddy from list."), ERROR_POPUP); break; case 0x0002: @@ -1591,10 +1476,9 @@ void CAimProto::snac_list_modification_ack(SNAC &snac)//family 0x0013 break; case 0x0008: - switch (code) - { + switch (code) { case 0x0000: -// ShowPopup("Successfully added buddy to list.", ERROR_POPUP); + // ShowPopup("Successfully added buddy to list.", ERROR_POPUP); break; case 0x0003: @@ -1626,11 +1510,9 @@ void CAimProto::snac_list_modification_ack(SNAC &snac)//family 0x0013 break; case 0x0009: - switch (code) - { + switch (code) { case 0x0000: case 0x000e: -// ShowPopup(LPGEN("Successfully modified group."), ERROR_POPUP); break; case 0x0002: @@ -1650,112 +1532,88 @@ void CAimProto::snac_list_modification_ack(SNAC &snac)//family 0x0013 void CAimProto::snac_service_redirect(SNAC &snac)//family 0x0001 { - if (snac.subcmp(0x0005)) - { - char* server=NULL; - char* local_cookie=NULL; - char* host=NULL; - int local_cookie_length=0; - unsigned short family=0; - unsigned char use_ssl=0; - - int offset=2; // skip number of bytes in family version tlv - while (offset < snac.len()) - { + if (snac.subcmp(0x0005)) { + char* server = NULL; + char* local_cookie = NULL; + char* host = NULL; + int local_cookie_length = 0; + unsigned short family = 0; + unsigned char use_ssl = 0; + + int offset = 2; // skip number of bytes in family version tlv + while (offset < snac.len()) { TLV tlv(snac.val(offset)); - if (tlv.cmp(0x000d)) - { - family=tlv.ushort(); + if (tlv.cmp(0x000d)) { + family = tlv.ushort(); } - else if (tlv.cmp(0x0005)) - { - server=tlv.dup(); + else if (tlv.cmp(0x0005)) { + server = tlv.dup(); } - else if (tlv.cmp(0x0006)) - { - local_cookie=tlv.dup(); - local_cookie_length=tlv.len(); + else if (tlv.cmp(0x0006)) { + local_cookie = tlv.dup(); + local_cookie_length = tlv.len(); } - else if (tlv.cmp(0x008d)) - { - host=tlv.dup(); + else if (tlv.cmp(0x008d)) { + host = tlv.dup(); } - else if (tlv.cmp(0x008e)) - { - use_ssl=tlv.ubyte(); + else if (tlv.cmp(0x008e)) { + use_ssl = tlv.ubyte(); } - offset+=TLV_HEADER_SIZE+tlv.len(); + offset += TLV_HEADER_SIZE + tlv.len(); } - if (family == 0x0018) - { - hMailConn = aim_connect(server, get_default_port(), false/*use_ssl != 0*/, host); - if (hMailConn) - { + if (family == 0x0018) { + m_hMailConn = aim_connect(server, get_default_port(), false/*use_ssl != 0*/, host); + if (m_hMailConn) { debugLogA("Successfully Connected to the Mail Server."); - MAIL_COOKIE=local_cookie; - MAIL_COOKIE_LENGTH=local_cookie_length; - ForkThread( &CAimProto::aim_mail_negotiation, 0 ); + MAIL_COOKIE = local_cookie; + MAIL_COOKIE_LENGTH = local_cookie_length; + ForkThread(&CAimProto::aim_mail_negotiation, 0); } - else - debugLogA("Failed to connect to the Mail Server."); + else debugLogA("Failed to connect to the Mail Server."); } - else if (family == 0x0010) - { - hAvatarConn = aim_connect(server, get_default_port(), false/*use_ssl != 0*/); - if (hAvatarConn) - { + else if (family == 0x0010) { + m_hAvatarConn = aim_connect(server, get_default_port(), false/*use_ssl != 0*/); + if (m_hAvatarConn) { debugLogA("Successfully Connected to the Avatar Server."); AVATAR_COOKIE = local_cookie; AVATAR_COOKIE_LENGTH = local_cookie_length; - ForkThread( &CAimProto::aim_avatar_negotiation, 0 ); + ForkThread(&CAimProto::aim_avatar_negotiation, 0); } - else - debugLogA("Failed to connect to the Avatar Server."); + else debugLogA("Failed to connect to the Avatar Server."); } - else if (family == 0x000D) - { - hChatNavConn = aim_connect(server, get_default_port(), use_ssl != 0, host); - if (hChatNavConn) - { + else if (family == 0x000D) { + m_hChatNavConn = aim_connect(server, get_default_port(), use_ssl != 0, host); + if (m_hChatNavConn) { debugLogA("Successfully Connected to the Chat Navigation Server."); CHATNAV_COOKIE = local_cookie; CHATNAV_COOKIE_LENGTH = local_cookie_length; - ForkThread( &CAimProto::aim_chatnav_negotiation, 0 ); + ForkThread(&CAimProto::aim_chatnav_negotiation, 0); } - else - debugLogA("Failed to connect to the Chat Navigation Server."); - + else debugLogA("Failed to connect to the Chat Navigation Server."); } - else if (family == 0x000E) - { + else if (family == 0x000E) { chat_list_item* item = find_chat_by_cid(snac.idh()); - if (item) - { + if (item) { item->hconn = aim_connect(server, get_default_port(), use_ssl != 0, host); - if (item->hconn) - { + if (item->hconn) { debugLogA("Successfully Connected to the Chat Server."); chat_start(item->id, item->exchange); item->CHAT_COOKIE = local_cookie; item->CHAT_COOKIE_LENGTH = local_cookie_length; - ForkThread( &CAimProto::aim_chat_negotiation, item ); + ForkThread(&CAimProto::aim_chat_negotiation, item); } - else - debugLogA("Failed to connect to the Chat Server."); + else debugLogA("Failed to connect to the Chat Server."); } } - else if (family == 0x0007) - { - hAdminConn = aim_connect(server, get_default_port(), false /*use_ssl != 0*/); - if (hAdminConn) - { + else if (family == 0x0007) { + m_hAdminConn = aim_connect(server, get_default_port(), false /*use_ssl != 0*/); + if (m_hAdminConn) { debugLogA("Successfully Connected to the Admin Server."); ADMIN_COOKIE = local_cookie; ADMIN_COOKIE_LENGTH = local_cookie_length; - ForkThread( &CAimProto::aim_admin_negotiation, 0 ); + ForkThread(&CAimProto::aim_admin_negotiation, 0); } - else - debugLogA("Failed to connect to the Admin Server."); + else debugLogA("Failed to connect to the Admin Server."); } mir_free(server); mir_free(host); @@ -1764,8 +1622,7 @@ void CAimProto::snac_service_redirect(SNAC &snac)//family 0x0001 void CAimProto::snac_mail_response(SNAC &snac)//family 0x0018 { - if (snac.subcmp(0x0007)) - { + if (snac.subcmp(0x0007)) { char* sn = NULL; time_t time = 0; unsigned short num_msgs = 0; @@ -1776,45 +1633,36 @@ void CAimProto::snac_mail_response(SNAC &snac)//family 0x0018 int position = 26; int num_tlvs = snac.ushort(24); - for (int i = 0; i < num_tlvs; i++) - { + for (int i = 0; i < num_tlvs; i++) { TLV tlv(snac.val(position)); - if (tlv.cmp(0x0009)) - { + if (tlv.cmp(0x0009)) { sn = tlv.dup(); } - else if (tlv.cmp(0x001d)) - { + else if (tlv.cmp(0x001d)) { time = tlv.ulong(); } - else if (tlv.cmp(0x0080)) - { + else if (tlv.cmp(0x0080)) { num_msgs = tlv.ushort(); } - else if (tlv.cmp(0x0081)) - { + else if (tlv.cmp(0x0081)) { new_mail = tlv.ubyte(); } - else if (tlv.cmp(0x0084)) - { + else if (tlv.cmp(0x0084)) { flags = tlv.ushort(); } - else if (tlv.cmp(0x0007)) - { + else if (tlv.cmp(0x0007)) { url = tlv.dup(); } - else if (tlv.cmp(0x0082)) - { + else if (tlv.cmp(0x0082)) { address = tlv.dup(); } position += TLV_HEADER_SIZE + tlv.len(); } - if (new_mail && num_msgs) - { + if (new_mail && num_msgs) { TCHAR msg[1024]; int len = mir_sntprintf(msg, _countof(msg), _T("%S@%S (%d)\r\n%s "), sn, address, num_msgs, - TranslateT("You've got mail! Checked at")) ; + TranslateT("You've got mail! Checked at")); SYSTEMTIME stLocal; GetLocalTime(&stLocal); @@ -1827,22 +1675,22 @@ void CAimProto::snac_mail_response(SNAC &snac)//family 0x0018 mir_free(url); } } + void CAimProto::snac_retrieve_avatar(SNAC &snac)//family 0x0010 { - if (snac.subcmp(0x0007)) - { + if (snac.subcmp(0x0007)) { int sn_len = snac.ubyte(0); char* sn = snac.part(1, sn_len); int parse_off = sn_len + 4; parse_off += snac.ubyte(parse_off); - int hash_size=snac.ubyte(5+parse_off); - char* hash_string=bytes_to_string(snac.val(6+parse_off), hash_size); - parse_off += hash_size + 6; + int hash_size = snac.ubyte(5 + parse_off); + char* hash_string = bytes_to_string(snac.val(6 + parse_off), hash_size); + parse_off += hash_size + 6; - int icon_length=snac.ushort(parse_off); - char* icon_data=snac.val(parse_off+2); + int icon_length = snac.ushort(parse_off); + char* icon_data = snac.val(parse_off + 2); avatar_retrieval_handler(sn, hash_string, icon_data, icon_length); @@ -1852,12 +1700,10 @@ void CAimProto::snac_retrieve_avatar(SNAC &snac)//family 0x0010 } void CAimProto::snac_upload_reply_avatar(SNAC &snac)//family 0x0010 { - if (snac.subcmp(0x0003)) - { + if (snac.subcmp(0x0003)) { int code = snac.ubyte(0); - switch (code) - { - case 0: + switch (code) { + case 0: break; case 3: ShowPopup(LPGEN("Error uploading avatar. (Too small)"), ERROR_POPUP); @@ -1879,54 +1725,47 @@ void CAimProto::snac_upload_reply_avatar(SNAC &snac)//family 0x0010 } void CAimProto::snac_email_search_results(SNAC &snac)//family 0x000A { - if (snac.subcmp(0x0003)) // Found some buddies - { - PROTOSEARCHRESULT psr = {0}; + if (snac.subcmp(0x0003)) { // Found some buddies + PROTOSEARCHRESULT psr = { 0 }; psr.cbSize = sizeof(psr); - unsigned short offset=0; - while(offsetcid); + aim_chat_join_room(m_hServerConn, m_seqno, cookie, exchange, instance, item->cid); } mir_free(name); @@ -1992,148 +1808,89 @@ void CAimProto::snac_chatnav_info_response(SNAC &snac,HANDLE hServerConn,unsigne } } } -void CAimProto::snac_chat_joined_left_users(SNAC &snac,chat_list_item* item)//family 0x000E -{ // Handles both joining and leaving users. - if (snac.subcmp(0x0003) || snac.subcmp(0x0004)) - { +void CAimProto::snac_chat_joined_left_users(SNAC &snac, chat_list_item* item)//family 0x000E +{ + // Handles both joining and leaving users. + if (snac.subcmp(0x0003) || snac.subcmp(0x0004)) { int offset = 0; - while (offset < snac.len()) - { + while (offset < snac.len()) { int sn_len = snac.ubyte(offset); - char* sn = snac.part(offset+1, sn_len); // Most important part (screenname) + char* sn = snac.part(offset + 1, sn_len); // Most important part (screenname) chat_event(item->id, sn, snac.subcmp(0x0003) ? GC_EVENT_JOIN : GC_EVENT_PART); mir_free(sn); -// int warning = snac.ushort(offset+1+sn_len); - int num_tlv = snac.ushort(offset+3+sn_len); - offset += 5+sn_len; // We're looking at any remaining TLVs -/* - unsigned short user_class = 0; - unsigned long idle_time = 0; - unsigned long signon_time = 0; - unsigned long creation_time = 0; // Server uptime? -*/ - for (int i = 0; i < num_tlv; i++) // Loop through all the TLVs - { + int num_tlv = snac.ushort(offset + 3 + sn_len); + offset += 5 + sn_len; // We're looking at any remaining TLVs + + for (int i = 0; i < num_tlv; i++) { // Loop through all the TLVs TLV tlv(snac.val(offset)); -/* - if (tlv.cmp(0x0001)) - user_class = tlv.ushort(); - else if (tlv.cmp(0x0003)) - signon_time = tlv.ulong(); - else if (tlv.cmp(0x0005)) - creation_time = tlv.ulong(); - else if (tlv.cmp(0x000F)) - idle_time = tlv.ulong(); -*/ offset += TLV_HEADER_SIZE + tlv.len(); } } - } + } } -void CAimProto::snac_chat_received_message(SNAC &snac,chat_list_item* item)//family 0x000E +void CAimProto::snac_chat_received_message(SNAC &snac, chat_list_item* item)//family 0x000E { - if (snac.subcmp(0x0006)) - { + if (snac.subcmp(0x0006)) { TCHAR* message = NULL; char* sn = NULL; -// unsigned long cookie = snac.ulong(0); -// unsigned short channel = snac.ushort(8); + // unsigned long cookie = snac.ulong(0); + // unsigned short channel = snac.ushort(8); int tlv_offset = 10; - while (tlv_offset < snac.len()) - { + while (tlv_offset < snac.len()) { TLV tlv(snac.val(tlv_offset)); - if (tlv.cmp(0x0003)) // Sender information - { + if (tlv.cmp(0x0003)) { // Sender information int sn_len = tlv.ubyte(0); sn = tlv.part(1, sn_len); - /* - unsigned short warning = tlv.ushort(1+sn_len); - int num_tlv = tlv.ushort(3+sn_len); - - int offset = 19 + sn_len; - - unsigned short user_class = 0; - unsigned long idle_time = 0; - unsigned long signon_time = 0; - unsigned long creation_time = 0; //Server uptime? - - for (int i = 0; i < num_tlv; i++) // Loop through all the TLVs - { - TLV info_tlv(tlv.val() + offset); - - // TLV List - if (info_tlv.cmp(0x0001)) - user_class = info_tlv.ushort(); - else if (info_tlv.cmp(0x0003)) - signon_time = info_tlv.ulong(); - else if (info_tlv.cmp(0x0005)) - creation_time = info_tlv.ulong(); - else if (info_tlv.cmp(0x000F)) - idle_time = info_tlv.ulong(); - - offset += TLV_HEADER_SIZE + info_tlv.len(); - } - */ } - else if (tlv.cmp(0x0001)) // Public/Whisper flag + else if (tlv.cmp(0x0001)) // Public/Whisper flag { } - else if (tlv.cmp(0x0005)) // Message information - { + else if (tlv.cmp(0x0005)) { // Message information bool uni = false; bool utf = false; -// char* language = NULL; int offset = 0; - while (offset < tlv.len()) - { + while (offset < tlv.len()) { TLV msg_tlv(tlv.val() + offset); - + // TLV List - if (msg_tlv.cmp(0x0001)) - { - if (uni) - { + if (msg_tlv.cmp(0x0001)) { + if (uni) { char* msg = msg_tlv.dupw(); html_decode(msg); - message = mir_utf8decodeT(msg); + message = mir_utf8decodeT(msg); mir_free(msg); } - else if (utf) - { + else if (utf) { char* msg = msg_tlv.dup(); html_decode(msg); message = mir_utf8decodeT(msg); mir_free(msg); } - else - { + else { char* msg = msg_tlv.dup(); html_decode(msg); message = mir_a2t(msg); mir_free(msg); } } - else if (msg_tlv.cmp(0x0002)) - { + else if (msg_tlv.cmp(0x0002)) { char* enc = msg_tlv.dup(); uni = strstr(enc, "unicode-2-0") != NULL; utf = strstr(enc, "utf-8") != NULL; mir_free(enc); } -// else if (msg_tlv.cmp(0x0003)) -// language = msg_tlv.dup(); offset += TLV_HEADER_SIZE + msg_tlv.len(); } } - + tlv_offset += TLV_HEADER_SIZE + tlv.len(); } @@ -2144,76 +1901,63 @@ void CAimProto::snac_chat_received_message(SNAC &snac,chat_list_item* item)//fam } } -void CAimProto::snac_admin_rate_limitations(SNAC &snac,HANDLE hServerConn,unsigned short &seqno)// family 0x0001 +void CAimProto::snac_admin_rate_limitations(SNAC &snac, HANDLE hServerConn, unsigned short &seqno)// family 0x0001 { - if (snac.subcmp(0x0007)) - { - aim_accept_rates(hServerConn,seqno); - aim_admin_ready(hServerConn,seqno); - SetEvent(hAdminEvent); + if (snac.subcmp(0x0007)) { + aim_accept_rates(hServerConn, seqno); + aim_admin_ready(hServerConn, seqno); + SetEvent(m_hAdminEvent); } } -void CAimProto::snac_admin_account_infomod(SNAC &snac)//family 0x0007 +void CAimProto::snac_admin_account_infomod(SNAC &snac) //family 0x0007 { - if (snac.subcmp(0x0003) || snac.subcmp(0x0005)) // Handles info response and modification response - { + if (snac.subcmp(0x0003) || snac.subcmp(0x0005)) { // Handles info response and modification response bool err = false; bool req_email = false; - unsigned short perms = 0; - unsigned short num_tlv = 0; - - perms = snac.ushort(); // Permissions - num_tlv = snac.ushort(2); // Number of TLVs - char* sn = NULL; // Screen Name - char* email = NULL; // Email address - //unsigned short status = 0; // Account status + WORD num_tlv = snac.ushort(2); // Number of TLVs + + char *sn = NULL; // Screen Name + char *email = NULL; // Email address unsigned short offset = 0; for (int i = 0; i < num_tlv; i++) // Loop through all the TLVs { - TLV tlv(snac.val(4+offset)); - + TLV tlv(snac.val(4 + offset)); + // TLV List if (tlv.cmp(0x0001)) sn = tlv.dup(); - if (tlv.cmp(0x0011)) - { + + if (tlv.cmp(0x0011)) { req_email = true; email = tlv.dup(); } - //if (tlv.cmp(0x0013)) - // status = tlv.ushort(); - if (tlv.cmp(0x0008)) // Handles any problems when requesting/changing information - { + + if (tlv.cmp(0x0008)) { // Handles any problems when requesting/changing information err = true; admin_error(tlv.ushort()); } - //if (tlv.cmp(0x0004)) - //error description offset += TLV_HEADER_SIZE + tlv.len(); } - if (snac.subcmp(0x0003) && !err) // Requested info - { + if (snac.subcmp(0x0003) && !err) { // Requested info // Display messages if (email) - setString(AIM_KEY_EM,email); // Save our email for future reference. + setString(AIM_KEY_EM, email); // Save our email for future reference. if (sn) - setString(AIM_KEY_SN,sn); // Update the database to reflect the formatted name. - ProtoBroadcastAck( NULL, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0 ); - + setString(AIM_KEY_SN, sn); // Update the database to reflect the formatted name. + ProtoBroadcastAck(NULL, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0); + } - else if (snac.subcmp(0x0005) && !err) // Changed info - { + else if (snac.subcmp(0x0005) && !err) { // Changed info // Display messages if (email && req_email) // We requested to change the email ShowPopup(LPGEN("A confirmation message has been sent to the new email address. Please follow its instructions."), 0); - else if (sn) - { - setString(AIM_KEY_SN,sn); // Update the database to reflect the formatted name. + else if (sn) { + setString(AIM_KEY_SN, sn); // Update the database to reflect the formatted name. //ShowPopup("Your Screen Name has been successfully formatted.", 0); } } @@ -2224,14 +1968,12 @@ void CAimProto::snac_admin_account_infomod(SNAC &snac)//family 0x0007 void CAimProto::snac_admin_account_confirm(SNAC &snac)//family 0x0007 { - if (snac.subcmp(0x0007)) - { + if (snac.subcmp(0x0007)) { unsigned short status = 0; status = snac.ushort(); - switch (status) - { + switch (status) { case 0: ShowPopup(LPGEN("A confirmation message has been sent to your email address. Please follow its instructions."), 0); break; @@ -2248,34 +1990,5 @@ void CAimProto::snac_admin_account_confirm(SNAC &snac)//family 0x0007 ShowPopup(LPGEN("Can't start the confirmation procedure."), 0); break; } - - //TLV tlv(snac.val(2)); - //if (tlv.cmp(0x0004)) - //error description } } - - -/*void CAimProto::snac_delete_contact(SNAC &snac, char* buf)//family 0x0013 -{ - if (snac.subcmp(0x000a)) - { - char sn[33]; - int sn_length=buf[SNAC_SIZE*2]; - MCONTACT hContact; - memset(sn, 0, sizeof(sn)); - memcpy(sn,&buf[SNAC_SIZE*2+1],sn_length); - hContact=find_contact(sn); - if (hContact) - { - unsigned short* type=(unsigned short*)&buf[SNAC_SIZE*2+1+sn_length]; - *type=htons(*type); - if (*type==0x0000)//typing finished - CallService(MS_PROTO_CONTACTISTYPING,hContact,(WPARAM)PROTOTYPE_CONTACTTYPING_OFF); - else if (*type==0x0001)//typed - CallService(MS_PROTO_CONTACTISTYPING,hContact,PROTOTYPE_CONTACTTYPING_INFINITE); - else if (*type==0x0002)//typing - CallService(MS_PROTO_CONTACTISTYPING,hContact,(LPARAM)60); - } - } -}*/ diff --git a/protocols/AimOscar/src/services.cpp b/protocols/AimOscar/src/services.cpp index cfa55973a1..27fe595f9a 100644 --- a/protocols/AimOscar/src/services.cpp +++ b/protocols/AimOscar/src/services.cpp @@ -18,7 +18,7 @@ along with this program. If not, see . */ #include "stdafx.h" -INT_PTR CAimProto::GetMyAwayMsg(WPARAM wParam,LPARAM lParam) +INT_PTR CAimProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam) { char** msgptr = get_status_msg_loc(wParam ? wParam : m_iStatus); if (msgptr == NULL) return 0; @@ -28,21 +28,19 @@ INT_PTR CAimProto::GetMyAwayMsg(WPARAM wParam,LPARAM lParam) int CAimProto::OnIdleChanged(WPARAM, LPARAM lParam) { - if (state != 1) - { - idle=0; + if (m_state != 1) { + m_idle = 0; return 0; } - if (instantidle) //ignore- we are instant idling at the moment + if (m_instantidle) //ignore- we are instant idling at the moment return 0; bool bIdle = (lParam & IDF_ISIDLE) != 0; bool bPrivacy = (lParam & IDF_PRIVACY) != 0; - if (bPrivacy && idle) - { - aim_set_idle(hServerConn,seqno,0); + if (bPrivacy && m_idle) { + aim_set_idle(m_hServerConn, m_seqno, 0); return 0; } @@ -54,31 +52,29 @@ int CAimProto::OnIdleChanged(WPARAM, LPARAM lParam) MIRANDA_IDLE_INFO mii = { sizeof(mii) }; CallService(MS_IDLE_GETIDLEINFO, 0, (LPARAM)&mii); - idle = 1; - aim_set_idle(hServerConn,seqno,mii.idleTime * 60); + m_idle = 1; + aim_set_idle(m_hServerConn, m_seqno, mii.idleTime * 60); } - else aim_set_idle(hServerConn,seqno,0); + else aim_set_idle(m_hServerConn, m_seqno, 0); return 0; } int CAimProto::OnWindowEvent(WPARAM, LPARAM lParam) { - MessageWindowEventData* msgEvData = (MessageWindowEventData*)lParam; + MessageWindowEventData* msgEvData = (MessageWindowEventData*)lParam; - if (msgEvData->uType == MSG_WINDOW_EVT_CLOSE) - { - if (state != 1 || !is_my_contact(msgEvData->hContact)) + if (msgEvData->uType == MSG_WINDOW_EVT_CLOSE) { + if (m_state != 1 || !is_my_contact(msgEvData->hContact)) return 0; if (getWord(msgEvData->hContact, AIM_KEY_ST, ID_STATUS_OFFLINE) == ID_STATUS_ONTHEPHONE) return 0; DBVARIANT dbv; - if (!getBool(msgEvData->hContact, AIM_KEY_BLS, false) && !getString(msgEvData->hContact, AIM_KEY_SN, &dbv)) - { + if (!getBool(msgEvData->hContact, AIM_KEY_BLS, false) && !getString(msgEvData->hContact, AIM_KEY_SN, &dbv)) { if (_stricmp(dbv.pszVal, SYSTEM_BUDDY)) - aim_typing_notification(hServerConn, seqno, dbv.pszVal, 0x000f); + aim_typing_notification(m_hServerConn, m_seqno, dbv.pszVal, 0x000f); db_free(&dbv); } } @@ -87,13 +83,13 @@ int CAimProto::OnWindowEvent(WPARAM, LPARAM lParam) INT_PTR CAimProto::GetProfile(WPARAM wParam, LPARAM) { - if (state != 1) + if (m_state != 1) return 0; DBVARIANT dbv; if (!getString(wParam, AIM_KEY_SN, &dbv)) { - request_HTML_profile = 1; - aim_query_profile(hServerConn, seqno, dbv.pszVal); + m_request_HTML_profile = 1; + aim_query_profile(m_hServerConn, m_seqno, dbv.pszVal); db_free(&dbv); } return 0; @@ -101,14 +97,13 @@ INT_PTR CAimProto::GetProfile(WPARAM wParam, LPARAM) INT_PTR CAimProto::GetHTMLAwayMsg(WPARAM wParam, LPARAM) { - if (state != 1) + if (m_state != 1) return 0; DBVARIANT dbv; - if (!getString(wParam, AIM_KEY_SN, &dbv)) - { - request_away_message = 1; - aim_query_away_message(hServerConn, seqno, dbv.pszVal); + if (!getString(wParam, AIM_KEY_SN, &dbv)) { + m_request_away_message = 1; + aim_query_away_message(m_hServerConn, m_seqno, dbv.pszVal); } return 0; } @@ -117,15 +112,11 @@ int CAimProto::OnDbSettingChanged(WPARAM hContact, LPARAM lParam) { DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam; - if (mir_strcmp(cws->szModule, MOD_KEY_CL) == 0 && state == 1 && hContact) - { - if (mir_strcmp(cws->szSetting, AIM_KEY_NL) == 0) - { - if (cws->value.type == DBVT_DELETED) - { + if (mir_strcmp(cws->szModule, MOD_KEY_CL) == 0 && m_state == 1 && hContact) { + if (mir_strcmp(cws->szSetting, AIM_KEY_NL) == 0) { + if (cws->value.type == DBVT_DELETED) { DBVARIANT dbv; - if (!db_get_utf(hContact, MOD_KEY_CL, OTH_KEY_GP, &dbv) && dbv.pszVal[0]) - { + if (!db_get_utf(hContact, MOD_KEY_CL, OTH_KEY_GP, &dbv) && dbv.pszVal[0]) { add_contact_to_group(hContact, dbv.pszVal); db_free(&dbv); } @@ -133,11 +124,9 @@ int CAimProto::OnDbSettingChanged(WPARAM hContact, LPARAM lParam) add_contact_to_group(hContact, AIM_DEFAULT_GROUP); } } - else if (mir_strcmp(cws->szSetting, "MyHandle") == 0) - { - char* name; - switch (cws->value.type) - { + else if (mir_strcmp(cws->szSetting, "MyHandle") == 0) { + char *name; + switch (cws->value.type) { case DBVT_DELETED: set_local_nick(hContact, NULL, NULL); break; @@ -166,28 +155,26 @@ int CAimProto::OnDbSettingChanged(WPARAM hContact, LPARAM lParam) int CAimProto::OnContactDeleted(WPARAM hContact, LPARAM) { - if (state != 1) return 0; + if (m_state != 1) + return 0; if (db_get_b(hContact, MOD_KEY_CL, AIM_KEY_NL, 0)) return 0; DBVARIANT dbv; - if (!getString(hContact, AIM_KEY_SN, &dbv)) - { - for(int i=1;;++i) - { + if (!getString(hContact, AIM_KEY_SN, &dbv)) { + for (int i = 1;; ++i) { unsigned short item_id = getBuddyId(hContact, i); - if (item_id == 0) break; + if (item_id == 0) break; unsigned short group_id = getGroupId(hContact, i); - if (group_id) - { + if (group_id) { bool is_not_in_list = getBool(hContact, AIM_KEY_NIL, false); - aim_ssi_update(hServerConn, seqno, true); - aim_delete_contact(hServerConn, seqno, dbv.pszVal, item_id, group_id, 0, is_not_in_list); - char* group = group_list.find_name(group_id); + aim_ssi_update(m_hServerConn, m_seqno, true); + aim_delete_contact(m_hServerConn, m_seqno, dbv.pszVal, item_id, group_id, 0, is_not_in_list); + char *group = m_group_list.find_name(group_id); update_server_group(group, group_id); - aim_ssi_update(hServerConn, seqno, false); + aim_ssi_update(m_hServerConn, m_seqno, false); } } db_free(&dbv); @@ -196,24 +183,25 @@ int CAimProto::OnContactDeleted(WPARAM hContact, LPARAM) } -int CAimProto::OnGroupChange(WPARAM hContact,LPARAM lParam) +int CAimProto::OnGroupChange(WPARAM hContact, LPARAM lParam) { - if (state != 1 || !getByte(AIM_KEY_MG, 1)) return 0; + if (m_state != 1 || !getByte(AIM_KEY_MG, 1)) + return 0; - CLISTGROUPCHANGE* grpchg = (CLISTGROUPCHANGE*)lParam; + CLISTGROUPCHANGE *grpchg = (CLISTGROUPCHANGE*)lParam; if (hContact == NULL) { if (grpchg->pszNewName == NULL && grpchg->pszOldName != NULL) { T2Utf szOldName(grpchg->pszOldName); - unsigned short group_id = group_list.find_id(szOldName); + unsigned short group_id = m_group_list.find_id(szOldName); if (group_id) { - aim_delete_contact(hServerConn, seqno, szOldName, 0, group_id, 1, false); - group_list.remove_by_id(group_id); + aim_delete_contact(m_hServerConn, m_seqno, szOldName, 0, group_id, 1, false); + m_group_list.remove_by_id(group_id); update_server_group("", 0); } } else if (grpchg->pszNewName != NULL && grpchg->pszOldName != NULL) { - unsigned short group_id = group_list.find_id(T2Utf(grpchg->pszOldName)); + unsigned short group_id = m_group_list.find_id(T2Utf(grpchg->pszOldName)); if (group_id) update_server_group(T2Utf(grpchg->pszNewName), group_id); } @@ -231,7 +219,8 @@ int CAimProto::OnGroupChange(WPARAM hContact,LPARAM lParam) INT_PTR CAimProto::AddToServerList(WPARAM hContact, LPARAM) { - if (state != 1) return 0; + if (m_state != 1) + return 0; DBVARIANT dbv; if (!db_get_utf(hContact, MOD_KEY_CL, OTH_KEY_GP, &dbv) && dbv.pszVal[0]) { @@ -244,7 +233,7 @@ INT_PTR CAimProto::AddToServerList(WPARAM hContact, LPARAM) INT_PTR CAimProto::BlockBuddy(WPARAM hContact, LPARAM) { - if (state != 1) + if (m_state != 1) return 0; unsigned short item_id; @@ -252,36 +241,36 @@ INT_PTR CAimProto::BlockBuddy(WPARAM hContact, LPARAM) if (getString(hContact, AIM_KEY_SN, &dbv)) return 0; - switch(pd_mode) { + switch (m_pd_mode) { case 1: - pd_mode = 4; - aim_set_pd_info(hServerConn, seqno); + m_pd_mode = 4; + aim_set_pd_info(m_hServerConn, m_seqno); case 4: - item_id = block_list.find_id(dbv.pszVal); + item_id = m_block_list.find_id(dbv.pszVal); if (item_id != 0) { - block_list.remove_by_id(item_id); - aim_delete_contact(hServerConn, seqno, dbv.pszVal, item_id, 0, 3, false); + m_block_list.remove_by_id(item_id); + aim_delete_contact(m_hServerConn, m_seqno, dbv.pszVal, item_id, 0, 3, false); } else { - item_id = block_list.add(dbv.pszVal); - aim_add_contact(hServerConn, seqno, dbv.pszVal, item_id, 0, 3, false); + item_id = m_block_list.add(dbv.pszVal); + aim_add_contact(m_hServerConn, m_seqno, dbv.pszVal, item_id, 0, 3, false); } break; case 2: - pd_mode = 3; - aim_set_pd_info(hServerConn, seqno); + m_pd_mode = 3; + aim_set_pd_info(m_hServerConn, m_seqno); case 3: - item_id = allow_list.find_id(dbv.pszVal); + item_id = m_allow_list.find_id(dbv.pszVal); if (item_id != 0) { - allow_list.remove_by_id(item_id); - aim_delete_contact(hServerConn, seqno, dbv.pszVal, item_id, 0, 2, false); + m_allow_list.remove_by_id(item_id); + aim_delete_contact(m_hServerConn, m_seqno, dbv.pszVal, item_id, 0, 2, false); } else { - item_id = allow_list.add(dbv.pszVal); - aim_add_contact(hServerConn, seqno, dbv.pszVal, item_id, 0, 2); + item_id = m_allow_list.add(dbv.pszVal); + aim_add_contact(m_hServerConn, m_seqno, dbv.pszVal, item_id, 0, 2); } break; } @@ -290,7 +279,7 @@ INT_PTR CAimProto::BlockBuddy(WPARAM hContact, LPARAM) return 0; } - INT_PTR CAimProto::JoinChatUI(WPARAM, LPARAM) +INT_PTR CAimProto::JoinChatUI(WPARAM, LPARAM) { DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHAT), NULL, join_chat_dialog, LPARAM(this)); return 0; @@ -298,11 +287,11 @@ INT_PTR CAimProto::BlockBuddy(WPARAM hContact, LPARAM) INT_PTR CAimProto::OnJoinChat(WPARAM hContact, LPARAM) { - if (state != 1) return 0; + if (m_state != 1) + return 0; DBVARIANT dbv; - if (!getString(hContact, "ChatRoomID", &dbv)) - { + if (!getString(hContact, "ChatRoomID", &dbv)) { chatnav_param* par = new chatnav_param(dbv.pszVal, getWord(hContact, "Exchange", 4)); ForkThread(&CAimProto::chatnav_request_thread, par); db_free(&dbv); @@ -312,13 +301,13 @@ INT_PTR CAimProto::OnJoinChat(WPARAM hContact, LPARAM) INT_PTR CAimProto::OnLeaveChat(WPARAM wParam, LPARAM) { - if (state != 1) return 0; + if (m_state != 1) + return 0; MCONTACT hContact = wParam; DBVARIANT dbv; - if (!getString(hContact, "ChatRoomID", &dbv)) - { + if (!getString(hContact, "ChatRoomID", &dbv)) { chat_leave(dbv.pszVal); db_free(&dbv); } @@ -339,17 +328,17 @@ INT_PTR CAimProto::ManageAccount(WPARAM, LPARAM) INT_PTR CAimProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) { - PROTO_AVATAR_INFORMATION* pai = (PROTO_AVATAR_INFORMATION*)lParam; - + PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION*)lParam; + pai->filename[0] = 0; pai->format = PA_FORMAT_UNKNOWN; - if (getByte(AIM_KEY_DA, 0)) return GAIR_NOAVATAR; + if (getByte(AIM_KEY_DA, 0)) + return GAIR_NOAVATAR; - switch (get_avatar_filename(pai->hContact, pai->filename, _countof(pai->filename), NULL)) - { + switch (get_avatar_filename(pai->hContact, pai->filename, _countof(pai->filename), NULL)) { case GAIR_SUCCESS: - if (!(wParam & GAIF_FORCE) || state != 1 ) + if (!(wParam & GAIF_FORCE) || m_state != 1) return GAIR_SUCCESS; case GAIR_WAITFOR: @@ -360,8 +349,7 @@ INT_PTR CAimProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) return GAIR_NOAVATAR; } - if (state == 1) - { + if (m_state == 1) { ForkThread(&CAimProto::avatar_request_thread, (void*)pai->hContact); return GAIR_WAITFOR; } @@ -420,56 +408,52 @@ INT_PTR CAimProto::GetAvatar(WPARAM wParam, LPARAM lParam) INT_PTR CAimProto::SetAvatar(WPARAM, LPARAM lParam) { - TCHAR* szFileName = (TCHAR*)lParam; + TCHAR *szFileName = (TCHAR*)lParam; - if (state != 1) return 1; + if (m_state != 1) + return 1; - if (szFileName == NULL) - { - aim_ssi_update(hServerConn, seqno, true); - aim_delete_avatar_hash(hServerConn, seqno, 1, 1, avatar_id_sm); - aim_delete_avatar_hash(hServerConn, seqno, 1, 12, avatar_id_lg); - aim_ssi_update(hServerConn, seqno, false); + if (szFileName == NULL) { + aim_ssi_update(m_hServerConn, m_seqno, true); + aim_delete_avatar_hash(m_hServerConn, m_seqno, 1, 1, m_avatar_id_sm); + aim_delete_avatar_hash(m_hServerConn, m_seqno, 1, 12, m_avatar_id_lg); + aim_ssi_update(m_hServerConn, m_seqno, false); avatar_request_handler(NULL, NULL, 0); } - else - { + else { char hash[16], hash1[16], *data, *data1 = NULL; unsigned short size, size1 = 0; - if (!get_avatar_hash(szFileName, hash, &data, size)) - { + if (!get_avatar_hash(szFileName, hash, &data, size)) { mir_free(hash); return 1; } rescale_image(data, size, data1, size1); - if (size1) - { + if (size1) { mir_md5_state_t state; mir_md5_init(&state); mir_md5_append(&state, (unsigned char*)data1, size1); mir_md5_finish(&state, (unsigned char*)hash1); - mir_free(hash_lg); hash_lg = bytes_to_string(hash, sizeof(hash)); - mir_free(hash_sm); hash_sm = bytes_to_string(hash1, sizeof(hash1)); + mir_free(m_hash_lg); m_hash_lg = bytes_to_string(hash, sizeof(hash)); + mir_free(m_hash_sm); m_hash_sm = bytes_to_string(hash1, sizeof(hash1)); - aim_ssi_update(hServerConn, seqno, true); - aim_set_avatar_hash(hServerConn, seqno, 1, 1, avatar_id_sm, 16, hash1); - aim_set_avatar_hash(hServerConn, seqno, 1, 12, avatar_id_lg, 16, hash); - aim_ssi_update(hServerConn, seqno, false); + aim_ssi_update(m_hServerConn, m_seqno, true); + aim_set_avatar_hash(m_hServerConn, m_seqno, 1, 1, m_avatar_id_sm, 16, hash1); + aim_set_avatar_hash(m_hServerConn, m_seqno, 1, 12, m_avatar_id_lg, 16, hash); + aim_ssi_update(m_hServerConn, m_seqno, false); } - else - { - mir_free(hash_lg); hash_lg = NULL; - mir_free(hash_sm); hash_sm = bytes_to_string(hash, sizeof(hash1)); - - aim_ssi_update(hServerConn, seqno, true); - aim_set_avatar_hash(hServerConn, seqno, 1, 1, avatar_id_sm, 16, hash); - aim_delete_avatar_hash(hServerConn, seqno, 1, 12, avatar_id_lg); - aim_ssi_update(hServerConn, seqno, false); + else { + mir_free(m_hash_lg); m_hash_lg = NULL; + mir_free(m_hash_sm); m_hash_sm = bytes_to_string(hash, sizeof(hash1)); + + aim_ssi_update(m_hServerConn, m_seqno, true); + aim_set_avatar_hash(m_hServerConn, m_seqno, 1, 1, m_avatar_id_sm, 16, hash); + aim_delete_avatar_hash(m_hServerConn, m_seqno, 1, 12, m_avatar_id_lg); + aim_ssi_update(m_hServerConn, m_seqno, false); } avatar_request_handler(NULL, NULL, 0); @@ -481,12 +465,11 @@ INT_PTR CAimProto::SetAvatar(WPARAM, LPARAM lParam) TCHAR *ext = _tcsrchr(szFileName, '.'); get_avatar_filename(NULL, tFileName, _countof(tFileName), ext); int fileId = _topen(tFileName, _O_CREAT | _O_TRUNC | _O_WRONLY | O_BINARY, _S_IREAD | _S_IWRITE); - if (fileId < 0) - { + if (fileId < 0) { char errmsg[512]; mir_snprintf(errmsg, _countof(errmsg), "Cannot store avatar. File '%s' could not be created/overwritten", tFileName); ShowPopup(errmsg, ERROR_POPUP); - return 1; + return 1; } _write(fileId, data, size); _close(fileId); diff --git a/protocols/AimOscar/src/snac.h b/protocols/AimOscar/src/snac.h index 8c184dfa3e..5c97462f22 100644 --- a/protocols/AimOscar/src/snac.h +++ b/protocols/AimOscar/src/snac.h @@ -23,23 +23,23 @@ along with this program. If not, see . class SNAC { -private: unsigned short service_; unsigned short subgroup_; unsigned short length_; unsigned short flags_; unsigned short idh_; unsigned short id_; - char* value_; + char *value_; + public: - SNAC(char* buf, unsigned short length); + SNAC(char *buf, unsigned short length); int cmp(unsigned short service); int subcmp(unsigned short subgroup); - unsigned short ushort(int pos=0); - unsigned long ulong(int pos=0); - unsigned char ubyte(int pos=0); + unsigned short ushort(int pos = 0); + unsigned long ulong(int pos = 0); + unsigned char ubyte(int pos = 0); char* part(int pos, int length); - char* val(int pos=0) { return &value_[pos]; } + char* val(int pos = 0) { return &value_[pos]; } unsigned short len(void) { return length_; } unsigned short flags(void) { return flags_; } unsigned short id(void) { return id_; } diff --git a/protocols/AimOscar/src/theme.cpp b/protocols/AimOscar/src/theme.cpp index cbcd33e7e4..200c6f90cf 100644 --- a/protocols/AimOscar/src/theme.cpp +++ b/protocols/AimOscar/src/theme.cpp @@ -176,32 +176,32 @@ int CAimProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM) bool bIsChatRoom = isChatRoom(hContact); //see if we should add the html away message context menu items - Menu_ShowItem(hHTMLAwayContextMenuItem, getWord(hContact, AIM_KEY_ST, ID_STATUS_OFFLINE) == ID_STATUS_AWAY && !bIsChatRoom); - Menu_ShowItem(hAddToServerListContextMenuItem, !getBuddyId(hContact, 1) && state != 0 && !bIsChatRoom); + Menu_ShowItem(m_hHTMLAwayContextMenuItem, getWord(hContact, AIM_KEY_ST, ID_STATUS_OFFLINE) == ID_STATUS_AWAY && !bIsChatRoom); + Menu_ShowItem(m_hAddToServerListContextMenuItem, !getBuddyId(hContact, 1) && m_state != 0 && !bIsChatRoom); ptrA id(getStringA(hContact, AIM_KEY_SN)); if (id == NULL) return 0; - switch (pd_mode) { + switch (m_pd_mode) { case 1: - Menu_ModifyItem(hBlockContextMenuItem, LPGENT("&Block")); + Menu_ModifyItem(m_hBlockContextMenuItem, LPGENT("&Block")); break; case 2: - Menu_ModifyItem(hBlockContextMenuItem, LPGENT("&Unblock")); + Menu_ModifyItem(m_hBlockContextMenuItem, LPGENT("&Unblock")); break; case 3: - Menu_ModifyItem(hBlockContextMenuItem, allow_list.find_id(id) ? LPGENT("&Block") : LPGENT("&Unblock")); + Menu_ModifyItem(m_hBlockContextMenuItem, m_allow_list.find_id(id) ? LPGENT("&Block") : LPGENT("&Unblock")); break; case 4: - Menu_ModifyItem(hBlockContextMenuItem, block_list.find_id(id) ? LPGENT("&Unblock") : LPGENT("&Block")); + Menu_ModifyItem(m_hBlockContextMenuItem, m_block_list.find_id(id) ? LPGENT("&Unblock") : LPGENT("&Block")); break; default: - Menu_ShowItem(hBlockContextMenuItem, false); + Menu_ShowItem(m_hBlockContextMenuItem, false); break; } return 0; @@ -217,21 +217,21 @@ void CAimProto::InitMainMenus(void) mi.position = 201001; mi.hIcolibItem = GetIconHandle("aim"); mi.name.a = LPGEN("Manage Account"); - hMainMenu[0] = Menu_AddProtoMenuItem(&mi, m_szModuleName); + m_hMainMenu[0] = Menu_AddProtoMenuItem(&mi, m_szModuleName); mi.pszService = "/InstantIdle"; CreateProtoService(mi.pszService, &CAimProto::InstantIdle); mi.position = 201002; mi.hIcolibItem = GetIconHandle("idle"); mi.name.a = LPGEN("Instant Idle"); - hMainMenu[1] = Menu_AddProtoMenuItem(&mi, m_szModuleName); + m_hMainMenu[1] = Menu_AddProtoMenuItem(&mi, m_szModuleName); mi.pszService = "/JoinChatRoom"; CreateProtoService(mi.pszService, &CAimProto::JoinChatUI); mi.position = 201003; mi.hIcolibItem = GetIconHandle("aol"); mi.name.a = LPGEN( "Join Chat Room" ); - hMainMenu[2] = Menu_AddProtoMenuItem(&mi, m_szModuleName); + m_hMainMenu[2] = Menu_AddProtoMenuItem(&mi, m_szModuleName); } void CAimProto::InitContactMenus(void) @@ -244,7 +244,7 @@ void CAimProto::InitContactMenus(void) mi.hIcolibItem = GetIconHandle("away"); mi.name.a = LPGEN("Read &HTML Away Message"); mi.flags = CMIF_NOTOFFLINE | CMIF_HIDDEN; - hHTMLAwayContextMenuItem = Menu_AddContactMenuItem(&mi, m_szModuleName); + m_hHTMLAwayContextMenuItem = Menu_AddContactMenuItem(&mi, m_szModuleName); CreateProtoService("/GetProfile", &CAimProto::GetProfile); mi.pszService = "/GetProfile"; @@ -260,7 +260,7 @@ void CAimProto::InitContactMenus(void) mi.hIcolibItem = GetIconHandle("add"); mi.name.a = LPGEN("Add To Server List"); mi.flags = CMIF_NOTONLINE | CMIF_HIDDEN; - hAddToServerListContextMenuItem = Menu_AddContactMenuItem(&mi, m_szModuleName); + m_hAddToServerListContextMenuItem = Menu_AddContactMenuItem(&mi, m_szModuleName); CreateProtoService("/BlockCommand", &CAimProto::BlockBuddy); mi.pszService = "/BlockCommand"; @@ -268,5 +268,5 @@ void CAimProto::InitContactMenus(void) mi.hIcolibItem = GetIconHandle("block"); mi.name.a = LPGEN("&Block"); mi.flags = CMIF_HIDDEN; - hBlockContextMenuItem = Menu_AddContactMenuItem(&mi, m_szModuleName); + m_hBlockContextMenuItem = Menu_AddContactMenuItem(&mi, m_szModuleName); } diff --git a/protocols/AimOscar/src/thread.cpp b/protocols/AimOscar/src/thread.cpp index 8c03fab0a0..35685f24ce 100644 --- a/protocols/AimOscar/src/thread.cpp +++ b/protocols/AimOscar/src/thread.cpp @@ -16,18 +16,18 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include "stdafx.h" void __cdecl CAimProto::accept_file_thread(void* param)//buddy sending file { - file_transfer *ft = (file_transfer*)param; + file_transfer *ft = (file_transfer*)param; HANDLE hConn = NULL; if (ft->peer_force_proxy) //peer is forcing proxy { hConn = aim_peer_connect(ft->proxy_ip, get_default_port()); - if (hConn) - { + if (hConn) { debugLogA("Connected to proxy ip that buddy specified."); ft->hConn = hConn; ForkThread(&CAimProto::aim_proxy_helper, ft); @@ -37,8 +37,7 @@ void __cdecl CAimProto::accept_file_thread(void* param)//buddy sending file else if (ft->me_force_proxy) //we are forcing proxy { hConn = aim_peer_connect(AIM_PROXY_SERVER, get_default_port()); - if (hConn) - { + if (hConn) { debugLogA("Connected to proxy ip because we want to use a proxy for the file transfer."); ft->requester = true; ft->hConn = hConn; @@ -46,47 +45,40 @@ void __cdecl CAimProto::accept_file_thread(void* param)//buddy sending file ft->stop_listen(); } } - else - { - bool verif = ft->verified_ip != detected_ip; + else { + bool verif = ft->verified_ip != m_detected_ip; hConn = aim_peer_connect(verif ? ft->verified_ip : ft->local_ip, ft->port); - if (hConn) - { - debugLogA("Connected to buddy over P2P port via %s ip.", verif ? "verified": "local"); + if (hConn) { + debugLogA("Connected to buddy over P2P port via %s ip.", verif ? "verified" : "local"); ft->accepted = true; ft->hConn = hConn; - aim_file_ad(hServerConn, seqno, ft->sn, ft->icbm_cookie, false, ft->max_ver); + aim_file_ad(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie, false, ft->max_ver); ForkThread(&CAimProto::aim_dc_helper, ft); ft->stop_listen(); } - else if (ft->sending) - { + else if (ft->sending) { hConn = aim_peer_connect(AIM_PROXY_SERVER, get_default_port()); - if (hConn) - { + if (hConn) { ft->hConn = hConn; ft->requester = true; ForkThread(&CAimProto::aim_proxy_helper, ft); ft->stop_listen(); } } - else - { + else { debugLogA("Failed to connect to buddy- asking buddy to connect to us."); ft->listen(this); ft->requester = true; - aim_send_file(hServerConn, seqno, detected_ip, ft->local_port, false, ft); + aim_send_file(m_hServerConn, m_seqno, m_detected_ip, ft->local_port, false, ft); return; } } - if (hConn == NULL) - { + if (hConn == NULL) { if (ft->req_num) - { - aim_file_ad(hServerConn, seqno, ft->sn, ft->icbm_cookie, true, 0); - } + aim_file_ad(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie, true, 0); + ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); - ft_list.remove_by_ft(ft); + m_ft_list.remove_by_ft(ft); } } diff --git a/protocols/AimOscar/src/ui.cpp b/protocols/AimOscar/src/ui.cpp index db98a0006a..4802fe3bd2 100644 --- a/protocols/AimOscar/src/ui.cpp +++ b/protocols/AimOscar/src/ui.cpp @@ -389,8 +389,8 @@ static INT_PTR CALLBACK userinfo_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, L { char* buf = rtf_to_html(hwndDlg, IDC_PROFILE); db_set_utf(NULL, ppro->m_szModuleName, AIM_KEY_PR, buf); - if (ppro->state == 1) - ppro->aim_set_profile(ppro->hServerConn, ppro->seqno, buf);//also see set caps for profile setting + if (ppro->m_state == 1) + ppro->aim_set_profile(ppro->m_hServerConn, ppro->m_seqno, buf);//also see set caps for profile setting mir_free(buf); EnableWindow(GetDlgItem(hwndDlg, IDC_SETPROFILE), FALSE); @@ -606,10 +606,9 @@ INT_PTR CALLBACK admin_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar ppro = (CAimProto*)((LPPSHNOTIFY)lParam)->lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)ppro); - if (ppro->wait_conn(ppro->hAdminConn, ppro->hAdminEvent, 0x07)) // Make a connection - { - ppro->aim_admin_request_info(ppro->hAdminConn, ppro->admin_seqno, 0x01); // Get our screenname - ppro->aim_admin_request_info(ppro->hAdminConn, ppro->admin_seqno, 0x11); // Get our email + if (ppro->wait_conn(ppro->m_hAdminConn, ppro->m_hAdminEvent, 0x07)) { // Make a connection + ppro->aim_admin_request_info(ppro->m_hAdminConn, ppro->m_admin_seqno, 0x01); // Get our screenname + ppro->aim_admin_request_info(ppro->m_hAdminConn, ppro->m_admin_seqno, 0x11); // Get our email } case PSN_INFOCHANGED: @@ -627,14 +626,14 @@ INT_PTR CALLBACK admin_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar case WM_COMMAND: if (LOWORD(wParam) == IDC_SAVECHANGES) { - if (!ppro->wait_conn(ppro->hAdminConn, ppro->hAdminEvent, 0x07)) // Make a connection + if (!ppro->wait_conn(ppro->m_hAdminConn, ppro->m_hAdminEvent, 0x07)) // Make a connection break; char name[64]; GetDlgItemTextA(hwndDlg, IDC_FNAME, name, _countof(name)); if (mir_strlen(trim_str(name)) > 0 && !ppro->getString(AIM_KEY_SN, &dbv)) { if (mir_strcmp(name, dbv.pszVal)) - ppro->aim_admin_format_name(ppro->hAdminConn, ppro->admin_seqno, name); + ppro->aim_admin_format_name(ppro->m_hAdminConn, ppro->m_admin_seqno, name); db_free(&dbv); } @@ -643,7 +642,7 @@ INT_PTR CALLBACK admin_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar if (mir_strlen(trim_str(email)) > 1 && !ppro->getString(AIM_KEY_EM, &dbv)) // Must be greater than 1 or a SNAC error is thrown. { if (mir_strcmp(email, dbv.pszVal)) - ppro->aim_admin_change_email(ppro->hAdminConn, ppro->admin_seqno, email); + ppro->aim_admin_change_email(ppro->m_hAdminConn, ppro->m_admin_seqno, email); db_free(&dbv); } @@ -658,7 +657,7 @@ INT_PTR CALLBACK admin_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar // Let's allow the client to type (two) new passwords incase they make a mistake so we // can handle any input error locally. if (mir_strcmp(npw1, npw2) == 0) { - ppro->aim_admin_change_password(ppro->hAdminConn, ppro->admin_seqno, cpw, npw1); + ppro->aim_admin_change_password(ppro->m_hAdminConn, ppro->m_admin_seqno, cpw, npw1); } else { SetDlgItemTextA(hwndDlg, IDC_CPW, ""); @@ -670,8 +669,8 @@ INT_PTR CALLBACK admin_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar } else if (LOWORD(wParam) == IDC_CONFIRM) // Confirmation { - if (ppro->wait_conn(ppro->hAdminConn, ppro->hAdminEvent, 0x07)) // Make a connection - ppro->aim_admin_account_confirm(ppro->hAdminConn, ppro->admin_seqno); + if (ppro->wait_conn(ppro->m_hAdminConn, ppro->m_hAdminEvent, 0x07)) // Make a connection + ppro->aim_admin_account_confirm(ppro->m_hAdminConn, ppro->m_admin_seqno); } break; } @@ -945,15 +944,15 @@ static INT_PTR CALLBACK privacy_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LP SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); ppro = (CAimProto*)lParam; - CheckRadioButton(hwndDlg, IDC_ALLOWALL, IDC_BLOCKBELOW, btns[ppro->pd_mode - 1]); + CheckRadioButton(hwndDlg, IDC_ALLOWALL, IDC_BLOCKBELOW, btns[ppro->m_pd_mode - 1]); - for (i = 0; i < ppro->allow_list.getCount(); ++i) - SendDlgItemMessageA(hwndDlg, IDC_ALLOWLIST, LB_ADDSTRING, 0, (LPARAM)ppro->allow_list[i].name); + for (i = 0; i < ppro->m_allow_list.getCount(); ++i) + SendDlgItemMessageA(hwndDlg, IDC_ALLOWLIST, LB_ADDSTRING, 0, (LPARAM)ppro->m_allow_list[i].name); - for (i = 0; i < ppro->block_list.getCount(); ++i) - SendDlgItemMessageA(hwndDlg, IDC_BLOCKLIST, LB_ADDSTRING, 0, (LPARAM)ppro->block_list[i].name); + for (i = 0; i < ppro->m_block_list.getCount(); ++i) + SendDlgItemMessageA(hwndDlg, IDC_BLOCKLIST, LB_ADDSTRING, 0, (LPARAM)ppro->m_block_list[i].name); - CheckDlgButton(hwndDlg, IDC_SIS, (ppro->pref1_flags & 0x400) ? BST_CHECKED : BST_CHECKED); + CheckDlgButton(hwndDlg, IDC_SIS, (ppro->m_pref1_flags & 0x400) ? BST_CHECKED : BST_CHECKED); break; case WM_COMMAND: @@ -981,56 +980,56 @@ static INT_PTR CALLBACK privacy_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LP case WM_NOTIFY: if (((LPNMHDR)lParam)->code == PSN_APPLY) { - ppro->aim_ssi_update(ppro->hServerConn, ppro->seqno, true); + ppro->aim_ssi_update(ppro->m_hServerConn, ppro->m_seqno, true); for (i = 0; i < 5; ++i) { - if (IsDlgButtonChecked(hwndDlg, btns[i]) && ppro->pd_mode != i + 1) { - ppro->pd_mode = (char)(i + 1); - ppro->pd_flags = 1; - ppro->aim_set_pd_info(ppro->hServerConn, ppro->seqno); + if (IsDlgButtonChecked(hwndDlg, btns[i]) && ppro->m_pd_mode != i + 1) { + ppro->m_pd_mode = (char)(i + 1); + ppro->m_pd_flags = 1; + ppro->aim_set_pd_info(ppro->m_hServerConn, ppro->m_seqno); break; } } - for (i = 0; i < ppro->block_list.getCount(); ++i) { - BdListItem& pd = ppro->block_list[i]; + for (i = 0; i < ppro->m_block_list.getCount(); ++i) { + BdListItem& pd = ppro->m_block_list[i]; if (SendDlgItemMessageA(hwndDlg, IDC_BLOCKLIST, LB_FINDSTRING, (WPARAM)-1, (LPARAM)pd.name) == LB_ERR) { - ppro->aim_delete_contact(ppro->hServerConn, ppro->seqno, pd.name, pd.item_id, 0, 3, false); - ppro->block_list.remove(i--); + ppro->aim_delete_contact(ppro->m_hServerConn, ppro->m_seqno, pd.name, pd.item_id, 0, 3, false); + ppro->m_block_list.remove(i--); } } i = SendDlgItemMessage(hwndDlg, IDC_BLOCKLIST, LB_GETCOUNT, 0, 0); for (; i--;) { char nick[80]; SendDlgItemMessageA(hwndDlg, IDC_BLOCKLIST, LB_GETTEXT, i, (LPARAM)nick); - if (ppro->block_list.find_id(nick) == 0) { - unsigned short id = ppro->block_list.add(nick); - ppro->aim_add_contact(ppro->hServerConn, ppro->seqno, nick, id, 0, 3); + if (ppro->m_block_list.find_id(nick) == 0) { + unsigned short id = ppro->m_block_list.add(nick); + ppro->aim_add_contact(ppro->m_hServerConn, ppro->m_seqno, nick, id, 0, 3); } } - for (i = 0; i < ppro->allow_list.getCount(); ++i) { - BdListItem& pd = ppro->allow_list[i]; + for (i = 0; i < ppro->m_allow_list.getCount(); ++i) { + BdListItem& pd = ppro->m_allow_list[i]; if (SendDlgItemMessageA(hwndDlg, IDC_ALLOWLIST, LB_FINDSTRING, (WPARAM)-1, (LPARAM)pd.name) == LB_ERR) { - ppro->aim_delete_contact(ppro->hServerConn, ppro->seqno, pd.name, pd.item_id, 0, 2, false); - ppro->allow_list.remove(i--); + ppro->aim_delete_contact(ppro->m_hServerConn, ppro->m_seqno, pd.name, pd.item_id, 0, 2, false); + ppro->m_allow_list.remove(i--); } } i = SendDlgItemMessage(hwndDlg, IDC_ALLOWLIST, LB_GETCOUNT, 0, 0); for (; i--;) { char nick[80]; SendDlgItemMessageA(hwndDlg, IDC_ALLOWLIST, LB_GETTEXT, i, (LPARAM)nick); - if (ppro->allow_list.find_id(nick) == 0) { - unsigned short id = ppro->allow_list.add(nick); - ppro->aim_add_contact(ppro->hServerConn, ppro->seqno, nick, id, 0, 2); + if (ppro->m_allow_list.find_id(nick) == 0) { + unsigned short id = ppro->m_allow_list.add(nick); + ppro->aim_add_contact(ppro->m_hServerConn, ppro->m_seqno, nick, id, 0, 2); } } unsigned mask = (IsDlgButtonChecked(hwndDlg, IDC_SIS) == BST_CHECKED) << 10; - if ((ppro->pref1_flags & 0x400) ^ mask) { - ppro->pref1_flags = (ppro->pref1_flags & ~0x400) | mask; - ppro->aim_ssi_update_preferences(ppro->hServerConn, ppro->seqno); + if ((ppro->m_pref1_flags & 0x400) ^ mask) { + ppro->m_pref1_flags = (ppro->m_pref1_flags & ~0x400) | mask; + ppro->aim_ssi_update_preferences(ppro->m_hServerConn, ppro->m_seqno); } - ppro->aim_ssi_update(ppro->hServerConn, ppro->seqno, false); + ppro->aim_ssi_update(ppro->m_hServerConn, ppro->m_seqno, false); } break; } @@ -1168,16 +1167,16 @@ INT_PTR CALLBACK instant_idle_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR switch (LOWORD(wParam)) { case IDOK: //Instant Idle - if (ppro->state == 1) { - ppro->aim_set_idle(ppro->hServerConn, ppro->seqno, hours * 60 * 60 + minutes * 60); - ppro->instantidle = 1; + if (ppro->m_state == 1) { + ppro->aim_set_idle(ppro->m_hServerConn, ppro->m_seqno, hours * 60 * 60 + minutes * 60); + ppro->m_instantidle = 1; } EndDialog(hwndDlg, IDOK); break; case IDCANCEL: - ppro->aim_set_idle(ppro->hServerConn, ppro->seqno, 0); - ppro->instantidle = 0; + ppro->aim_set_idle(ppro->m_hServerConn, ppro->m_seqno, 0); + ppro->m_instantidle = 0; EndDialog(hwndDlg, IDCANCEL); break; } @@ -1217,7 +1216,7 @@ INT_PTR CALLBACK join_chat_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM case IDOK: char room[128]; GetDlgItemTextA(hwndDlg, IDC_ROOM, room, _countof(room)); - if (ppro->state == 1 && room[0] != 0) { + if (ppro->m_state == 1 && room[0] != 0) { chatnav_param* par = new chatnav_param(room, 4); ppro->ForkThread(&CAimProto::chatnav_request_thread, par); } @@ -1254,15 +1253,15 @@ static void clist_chat_invite_send(MCONTACT hItem, HWND hwndList, chat_list_item TCHAR buf[128] = _T(""); SendMessage(hwndList, CLM_GETITEMTEXT, (WPARAM)hItem, (LPARAM)buf); - char* sn = mir_t2a(buf); - ppro->aim_chat_invite(ppro->hServerConn, ppro->seqno, + char *sn = mir_t2a(buf); + ppro->aim_chat_invite(ppro->m_hServerConn, ppro->m_seqno, item->cookie, item->exchange, item->instance, sn, msg); mir_free(sn); } else { DBVARIANT dbv; if (!ppro->getString(hItem, AIM_KEY_SN, &dbv)) { - ppro->aim_chat_invite(ppro->hServerConn, ppro->seqno, + ppro->aim_chat_invite(ppro->m_hServerConn, ppro->m_seqno, item->cookie, item->exchange, item->instance, dbv.pszVal, msg); db_free(&dbv); } @@ -1347,7 +1346,7 @@ INT_PTR CALLBACK invite_to_chat_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LP { switch (LOWORD(wParam)) { case IDC_ADDSCR: - if (param->ppro->state == 1) { + if (param->ppro->m_state == 1) { TCHAR sn[64]; GetDlgItemText(hwndDlg, IDC_EDITSCR, sn, _countof(sn)); @@ -1365,11 +1364,11 @@ INT_PTR CALLBACK invite_to_chat_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LP { chat_list_item* item = param->ppro->find_chat_by_id(param->id); if (item) { - char msg[1024]; - GetDlgItemTextA(hwndDlg, IDC_MSG, msg, _countof(msg)); + char buf[1024]; + GetDlgItemTextA(hwndDlg, IDC_MSG, buf, _countof(buf)); HWND hwndList = GetDlgItem(hwndDlg, IDC_CCLIST); - clist_chat_invite_send(NULL, hwndList, item, param->ppro, msg); + clist_chat_invite_send(NULL, hwndList, item, param->ppro, buf); } EndDialog(hwndDlg, IDOK); } @@ -1423,7 +1422,7 @@ INT_PTR CALLBACK chat_request_dialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR break; case IDCANCEL: - param->ppro->aim_chat_deny(param->ppro->hServerConn, param->ppro->seqno, param->name, param->icbm_cookie); + param->ppro->aim_chat_deny(param->ppro->m_hServerConn, param->ppro->m_seqno, param->name, param->icbm_cookie); delete param->cnp; EndDialog(hwndDlg, IDCANCEL); break; diff --git a/protocols/AimOscar/src/utility.cpp b/protocols/AimOscar/src/utility.cpp index d66e920b56..0a774fbf5b 100644 --- a/protocols/AimOscar/src/utility.cpp +++ b/protocols/AimOscar/src/utility.cpp @@ -21,88 +21,79 @@ along with this program. If not, see . void CAimProto::broadcast_status(int status) { - debugLogA("Broadcast Status: %d",status); + debugLogA("Broadcast Status: %d", status); int old_status = m_iStatus; m_iStatus = status; - if (m_iStatus == ID_STATUS_OFFLINE) - { + if (m_iStatus == ID_STATUS_OFFLINE) { shutdown_file_transfers(); shutdown_chat_conn(); - if (hServerConn) - { - aim_sendflap(hServerConn,0x04,0,NULL,seqno); - Netlib_Shutdown(hServerConn); + if (m_hServerConn) { + aim_sendflap(m_hServerConn, 0x04, 0, NULL, m_seqno); + Netlib_Shutdown(m_hServerConn); } - if (hMailConn && hMailConn != (HANDLE)1) - { - aim_sendflap(hMailConn,0x04,0,NULL,mail_seqno); - Netlib_Shutdown(hMailConn); + if (m_hMailConn && m_hMailConn != (HANDLE)1) { + aim_sendflap(m_hMailConn, 0x04, 0, NULL, m_mail_seqno); + Netlib_Shutdown(m_hMailConn); } - else if (hMailConn == (HANDLE)1) - hMailConn = NULL; + else if (m_hMailConn == (HANDLE)1) + m_hMailConn = NULL; - if (hAvatarConn && hAvatarConn != (HANDLE)1) - { - aim_sendflap(hAvatarConn,0x04,0,NULL,avatar_seqno); - Netlib_Shutdown(hAvatarConn); + if (m_hAvatarConn && m_hAvatarConn != (HANDLE)1) { + aim_sendflap(m_hAvatarConn, 0x04, 0, NULL, m_avatar_seqno); + Netlib_Shutdown(m_hAvatarConn); } - else if (hAvatarConn == (HANDLE)1) - hAvatarConn = NULL; + else if (m_hAvatarConn == (HANDLE)1) + m_hAvatarConn = NULL; - if (hChatNavConn && hChatNavConn != (HANDLE)1) - { - aim_sendflap(hChatNavConn,0x04,0,NULL,chatnav_seqno); - Netlib_Shutdown(hChatNavConn); + if (m_hChatNavConn && m_hChatNavConn != (HANDLE)1) { + aim_sendflap(m_hChatNavConn, 0x04, 0, NULL, m_chatnav_seqno); + Netlib_Shutdown(m_hChatNavConn); } - else if (hChatNavConn == (HANDLE)1) - hChatNavConn = NULL; + else if (m_hChatNavConn == (HANDLE)1) + m_hChatNavConn = NULL; - idle = false; - instantidle = false; - list_received = false; - state = 0; + m_idle = false; + m_instantidle = false; + m_list_received = false; + m_state = 0; m_iDesiredStatus = ID_STATUS_OFFLINE; - mir_free(last_status_msg); last_status_msg = NULL; - - avatar_id_lg = 0; - avatar_id_sm = 0; - mir_free(hash_lg); hash_lg = NULL; - mir_free(hash_sm); hash_sm = NULL; - - pd_flags = 0; - pd_info_id = 0; - pd_mode = 0; - - seqno = 0; - mail_seqno = 0; - avatar_seqno = 0; - chatnav_seqno = 0; - admin_seqno = 0; - + replaceStr(m_last_status_msg, NULL); + + m_avatar_id_lg = 0; + m_avatar_id_sm = 0; + replaceStr(m_hash_lg, NULL); + replaceStr(m_hash_sm, NULL); + + m_pd_flags = 0; + m_pd_info_id = 0; + m_pd_mode = 0; + + m_seqno = 0; + m_mail_seqno = 0; + m_avatar_seqno = 0; + m_chatnav_seqno = 0; + m_admin_seqno = 0; } - ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); + ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); } void CAimProto::start_connection(void*) { - if (m_iStatus<=ID_STATUS_OFFLINE) - { + if (m_iStatus <= ID_STATUS_OFFLINE) { offline_contacts(); DBVARIANT dbv; if (!getString(AIM_KEY_SN, &dbv)) db_free(&dbv); - else - { + else { ShowPopup(LPGEN("Please, enter a username in the options dialog."), 0); broadcast_status(ID_STATUS_OFFLINE); return; } if (!getString(AIM_KEY_PW, &dbv)) db_free(&dbv); - else - { + else { ShowPopup(LPGEN("Please, enter a password in the options dialog."), 0); broadcast_status(ID_STATUS_OFFLINE); return; @@ -113,39 +104,39 @@ void CAimProto::start_connection(void*) char* login_url = getStringA(AIM_KEY_HN); if (login_url == NULL) login_url = mir_strdup(use_ssl ? AIM_DEFAULT_SERVER : AIM_DEFAULT_SERVER_NS); - hServerConn = aim_connect(login_url, get_default_port(), use_ssl, login_url); + m_hServerConn = aim_connect(login_url, get_default_port(), use_ssl, login_url); mir_free(login_url); - pref1_flags = 0x77ffff; - pref1_set_flags = 0x77ffff; - mir_free(pref2_flags); pref2_flags = NULL; pref2_len = 0; - mir_free(pref2_set_flags); pref2_set_flags = NULL; pref2_set_len = 0; + m_pref1_flags = 0x77ffff; + m_pref1_set_flags = 0x77ffff; + mir_free(m_pref2_flags); m_pref2_flags = NULL; m_pref2_len = 0; + mir_free(m_pref2_set_flags); m_pref2_set_flags = NULL; m_pref2_set_len = 0; - if (hServerConn) + if (m_hServerConn) aim_connection_authorization(); - else + else broadcast_status(ID_STATUS_OFFLINE); } } bool CAimProto::wait_conn(HANDLE& hConn, HANDLE& hEvent, unsigned short service) { - if (m_iStatus == ID_STATUS_OFFLINE) + if (m_iStatus == ID_STATUS_OFFLINE) return false; { mir_cslock lck(connMutex); - if (hConn == NULL && hServerConn) { + if (hConn == NULL && m_hServerConn) { debugLogA("Starting Connection."); hConn = (HANDLE)1; //set so no additional service request attempts are made while aim is still processing the request - aim_new_service_request(hServerConn, seqno, service);//general service connection! + aim_new_service_request(m_hServerConn, m_seqno, service);//general service connection! } } if (WaitForSingleObjectEx(hEvent, 10000, TRUE) != WAIT_OBJECT_0) return false; - if (Miranda_Terminated() || m_iStatus == ID_STATUS_OFFLINE) + if (Miranda_Terminated() || m_iStatus == ID_STATUS_OFFLINE) return false; return true; @@ -168,10 +159,10 @@ MCONTACT CAimProto::find_chat_contact(const char* room) for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { DBVARIANT dbv; if (!getString(hContact, "ChatRoomID", &dbv)) { - bool found = !mir_strcmp(room, dbv.pszVal); + bool found = !mir_strcmp(room, dbv.pszVal); db_free(&dbv); if (found) - return hContact; + return hContact; } } return NULL; @@ -179,15 +170,15 @@ MCONTACT CAimProto::find_chat_contact(const char* room) MCONTACT CAimProto::contact_from_sn(const char* sn, bool addIfNeeded, bool temporary) { - ptrA norm_sn( normalize_name(sn)); + ptrA norm_sn(normalize_name(sn)); for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { DBVARIANT dbv; if (!getString(hContact, AIM_KEY_SN, &dbv)) { - bool found = !mir_strcmp(norm_sn, dbv.pszVal); + bool found = !mir_strcmp(norm_sn, dbv.pszVal); db_free(&dbv); if (found) - return hContact; + return hContact; } } @@ -197,7 +188,7 @@ MCONTACT CAimProto::contact_from_sn(const char* sn, bool addIfNeeded, bool tempo if (Proto_AddToContact(hContact, m_szModuleName) == 0) { setString(hContact, AIM_KEY_SN, norm_sn); setString(hContact, AIM_KEY_NK, sn); - debugLogA("Adding contact %s to client side list.",norm_sn); + debugLogA("Adding contact %s to client side list.", norm_sn); if (temporary) db_set_b(hContact, "CList", "NotOnList", 1); return hContact; @@ -216,16 +207,15 @@ void CAimProto::update_server_group(const char* group, unsigned short group_id) if (group_id) user_id_array = get_members_of_group(group_id, user_id_array_size); - else - { - user_id_array_size = (unsigned short)group_list.getCount(); + else { + user_id_array_size = (unsigned short)m_group_list.getCount(); user_id_array = (unsigned short*)mir_alloc(user_id_array_size * sizeof(unsigned short)); - for (unsigned short i=0; iitem_id == id) goto retry; return id; @@ -461,8 +443,7 @@ retry: unsigned short BdList::find_id(const char* name) { - for (int i=0; iname, name) == 0) return items[i]->item_id; } @@ -471,8 +452,7 @@ unsigned short BdList::find_id(const char* name) char* BdList::find_name(unsigned short id) { - for (int i=0; iitem_id == id) return items[i]->name; } @@ -481,10 +461,8 @@ char* BdList::find_name(unsigned short id) void BdList::remove_by_id(unsigned short id) { - for (int i=0; iitem_id == id) - { + for (int i = 0; i < count; ++i) { + if (items[i]->item_id == id) { remove(i); break; } @@ -495,42 +473,42 @@ void BdList::remove_by_id(unsigned short id) unsigned short CAimProto::getBuddyId(MCONTACT hContact, int i) { - char item[sizeof(AIM_KEY_BI)+10]; + char item[sizeof(AIM_KEY_BI) + 10]; mir_snprintf(item, _countof(item), AIM_KEY_BI"%d", i); return getWord(hContact, item, 0); } void CAimProto::setBuddyId(MCONTACT hContact, int i, unsigned short id) { - char item[sizeof(AIM_KEY_BI)+10]; + char item[sizeof(AIM_KEY_BI) + 10]; mir_snprintf(item, _countof(item), AIM_KEY_BI"%d", i); setWord(hContact, item, id); } int CAimProto::deleteBuddyId(MCONTACT hContact, int i) { - char item[sizeof(AIM_KEY_BI)+10]; + char item[sizeof(AIM_KEY_BI) + 10]; mir_snprintf(item, _countof(item), AIM_KEY_BI"%d", i); return delSetting(hContact, item); } unsigned short CAimProto::getGroupId(MCONTACT hContact, int i) { - char item[sizeof(AIM_KEY_GI)+10]; + char item[sizeof(AIM_KEY_GI) + 10]; mir_snprintf(item, _countof(item), AIM_KEY_GI"%d", i); return getWord(hContact, item, 0); } void CAimProto::setGroupId(MCONTACT hContact, int i, unsigned short id) { - char item[sizeof(AIM_KEY_GI)+10]; + char item[sizeof(AIM_KEY_GI) + 10]; mir_snprintf(item, _countof(item), AIM_KEY_GI"%d", i); setWord(hContact, item, id); } int CAimProto::deleteGroupId(MCONTACT hContact, int i) { - char item[sizeof(AIM_KEY_GI)+10]; + char item[sizeof(AIM_KEY_GI) + 10]; mir_snprintf(item, _countof(item), AIM_KEY_GI"%d", i); return delSetting(hContact, item); } @@ -550,8 +528,7 @@ int CAimProto::open_contact_file(const char*, const TCHAR* file, const char*, TC mir_sntprintf(path + pos, MAX_PATH - pos, _T("\\%s"), file); int fid = _topen(path, _O_CREAT | _O_RDWR | _O_BINARY, _S_IREAD); - if (fid < 0) - { + if (fid < 0) { TCHAR errmsg[512]; mir_sntprintf(errmsg, _countof(errmsg), TranslateT("Failed to open file: %s %s"), path, __tcserror(NULL)); ShowPopup((char*)errmsg, ERROR_POPUP | TCHAR_POPUP); @@ -563,10 +540,9 @@ void CAimProto::write_away_message(const char* sn, const char* msg, bool utf) { TCHAR* path; int fid = open_contact_file(sn, _T("away.html"), "wb", path, 1); - if (fid >= 0) - { + if (fid >= 0) { if (utf) _write(fid, "\xEF\xBB\xBF", 3); - char* s_msg=process_status_msg(msg, sn); + char* s_msg = process_status_msg(msg, sn); _write(fid, "

", 4); _write(fid, sn, (unsigned)mir_strlen(sn)); _write(fid, "'s Away Message:

", 21); @@ -576,16 +552,15 @@ void CAimProto::write_away_message(const char* sn, const char* msg, bool utf) mir_free(path); mir_free(s_msg); } -} +} void CAimProto::write_profile(const char* sn, const char* msg, bool utf) { TCHAR* path; - int fid = open_contact_file(sn, _T("profile.html"),"wb", path, 1); - if (fid >= 0) - { + int fid = open_contact_file(sn, _T("profile.html"), "wb", path, 1); + if (fid >= 0) { if (utf) _write(fid, "\xEF\xBB\xBF", 3); - char* s_msg=process_status_msg(msg, sn); + char* s_msg = process_status_msg(msg, sn); _write(fid, "

", 4); _write(fid, sn, (unsigned)mir_strlen(sn)); _write(fid, "'s Profile:

", 16); @@ -601,8 +576,7 @@ unsigned long aim_oft_checksum_chunk(unsigned long dwChecksum, const unsigned ch { unsigned long checksum = (dwChecksum >> 16) & 0xffff; - for (int i = 0; i < len; i++) - { + for (int i = 0; i < len; i++) { unsigned val = buffer[i]; if ((i & 1) == 0) @@ -616,16 +590,14 @@ unsigned long aim_oft_checksum_chunk(unsigned long dwChecksum, const unsigned ch return checksum << 16; } -unsigned int aim_oft_checksum_file(TCHAR *filename, unsigned __int64 size) +unsigned int aim_oft_checksum_file(TCHAR *filename, unsigned __int64 size) { unsigned long checksum = 0xffff0000; int fid = _topen(filename, _O_RDONLY | _O_BINARY, _S_IREAD); - if (fid >= 0) - { + if (fid >= 0) { unsigned __int64 sz = _filelengthi64(fid); - if (size > sz) size = sz; - while (size) - { + if (size > sz) size = sz; + while (size) { unsigned char buffer[8912]; int bytes = (int)min(size, sizeof(buffer)); bytes = _read(fid, buffer, bytes); @@ -642,8 +614,7 @@ char* long_ip_to_char_ip(unsigned long host, char* ip) host = _htonl(host); unsigned char* bytes = (unsigned char*)&host; size_t buf_loc = 0; - for(int i=0; i<4; i++) - { + for (int i = 0; i < 4; i++) { char store[16]; _itoa(bytes[i], store, 10); size_t len = mir_strlen(store); @@ -659,10 +630,9 @@ char* long_ip_to_char_ip(unsigned long host, char* ip) unsigned long char_ip_to_long_ip(char* ip) { - unsigned char chost[4] = {0}; + unsigned char chost[4] = { 0 }; char *c = ip; - for(int i=0; i<4; ++i) - { + for (int i = 0; i < 4; ++i) { chost[i] = (unsigned char)atoi(c); c = strchr(c, '.'); if (c) ++c; -- cgit v1.2.3