From 8a59f88f48312eb877347a233b0a6ec11c9ab550 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 16 Nov 2014 18:15:16 +0000 Subject: MSN protocol's death-scream git-svn-id: http://svn.miranda-ng.org/main/trunk@10998 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/MSN/src/msn.cpp | 2 +- protocols/MSN/src/msn_auth.cpp | 122 ++--- protocols/MSN/src/msn_avatar.cpp | 8 +- protocols/MSN/src/msn_chat.cpp | 330 ++++++------- protocols/MSN/src/msn_contact.cpp | 110 ++--- protocols/MSN/src/msn_errors.cpp | 15 +- protocols/MSN/src/msn_ftold.cpp | 256 +++++----- protocols/MSN/src/msn_global.h | 6 +- protocols/MSN/src/msn_http.cpp | 32 +- protocols/MSN/src/msn_libstr.cpp | 31 +- protocols/MSN/src/msn_links.cpp | 46 +- protocols/MSN/src/msn_lists.cpp | 97 ++-- protocols/MSN/src/msn_mail.cpp | 96 ++-- protocols/MSN/src/msn_menu.cpp | 81 ++-- protocols/MSN/src/msn_mime.cpp | 242 +++++----- protocols/MSN/src/msn_misc.cpp | 109 ++--- protocols/MSN/src/msn_msgqueue.cpp | 33 +- protocols/MSN/src/msn_msgsplit.cpp | 22 +- protocols/MSN/src/msn_natdetect.cpp | 170 +++---- protocols/MSN/src/msn_opts.cpp | 120 +++-- protocols/MSN/src/msn_p2p.cpp | 875 +++++++++++++--------------------- protocols/MSN/src/msn_p2ps.cpp | 59 +-- protocols/MSN/src/msn_proto.cpp | 41 +- protocols/MSN/src/msn_soapab.cpp | 657 +++++++++---------------- protocols/MSN/src/msn_soapstore.cpp | 149 ++---- protocols/MSN/src/msn_srv.cpp | 59 +-- protocols/MSN/src/msn_ssl.cpp | 39 +- protocols/MSN/src/msn_std.cpp | 27 +- protocols/MSN/src/msn_svcs.cpp | 161 +++---- protocols/MSN/src/msn_switchboard.cpp | 2 +- protocols/MSN/src/msn_threads.cpp | 313 +++++------- protocols/MSN/src/msn_ws.cpp | 52 +- protocols/MSN/src/version.h | 2 +- 33 files changed, 1744 insertions(+), 2620 deletions(-) (limited to 'protocols') diff --git a/protocols/MSN/src/msn.cpp b/protocols/MSN/src/msn.cpp index 21e199fb77..1dc588393d 100644 --- a/protocols/MSN/src/msn.cpp +++ b/protocols/MSN/src/msn.cpp @@ -70,7 +70,7 @@ OBJLIST g_Instances(1, sttCompareProtocols); ///////////////////////////////////////////////////////////////////////////////////////// // Main DLL function -extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,LPVOID lpvReserved) +extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { if (fdwReason == DLL_PROCESS_ATTACH) { hInst = hinstDLL; diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp index 9474b71dfc..d0b2830664 100644 --- a/protocols/MSN/src/msn_auth.cpp +++ b/protocols/MSN/src/msn_auth.cpp @@ -52,8 +52,8 @@ static const char authPacket[] = "%s" "" "" - "%s" - "%s" + "%S" + "%S" "" "" "" @@ -136,24 +136,14 @@ int CMsnProto::MSN_GetPassportAuth(void) char szPassword[100]; db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword)); szPassword[16] = 0; - char* szEncPassword = HtmlEncode(szPassword); time_t ts = time(NULL); TCHAR szTs1[64], szTs2[64]; - tmi.printTimeStamp(UTC_TIME_HANDLE, ts, _T("I"), szTs1, SIZEOF(szTs1), 0); tmi.printTimeStamp(UTC_TIME_HANDLE, ts + 20 * 60, _T("I"), szTs2, SIZEOF(szTs2), 0); - char *szTs1A = mir_t2a(szTs1), *szTs2A = mir_t2a(szTs2); - - const size_t len = sizeof(authPacket) + 2048; - char* szAuthInfo = (char*)alloca(len); - mir_snprintf(szAuthInfo, len, authPacket, int(ts), MyOptions.szEmail, szEncPassword, szTs1A, szTs2A); - - mir_free(szTs2A); - mir_free(szTs1A); - mir_free(szEncPassword); + CMStringA szAuthInfo(FORMAT, authPacket, int(ts), MyOptions.szEmail, ptrA(HtmlEncode(szPassword)), szTs1, szTs2); char* szPassportHost = (char*)mir_alloc(256); if (db_get_static(NULL, m_szModuleName, "MsnPassportHost", szPassportHost, 256)) @@ -162,47 +152,41 @@ int CMsnProto::MSN_GetPassportAuth(void) bool defaultUrlAllow = strcmp(szPassportHost, defaultPassportUrl) != 0; char *tResult = NULL; - while (retVal == -1) - { + while (retVal == -1) { unsigned status; tResult = getSslResult(&szPassportHost, szAuthInfo, NULL, status); - if (tResult == NULL) - { - if (defaultUrlAllow) - { + if (tResult == NULL) { + if (defaultUrlAllow) { strcpy(szPassportHost, defaultPassportUrl); defaultUrlAllow = false; continue; } - else - { + else { retVal = 4; break; } } - switch (status) - { - case 200: + switch (status) { + case 200: + const char *errurl; { - const char *errurl = NULL; + errurl = NULL; ezxml_t xml = ezxml_parse_str(tResult, strlen(tResult)); ezxml_t tokr = ezxml_get(xml, "S:Body", 0, "wst:RequestSecurityTokenResponseCollection", 0, "wst:RequestSecurityTokenResponse", -1); - while (tokr != NULL) - { + while (tokr != NULL) { ezxml_t toks = ezxml_get(tokr, "wst:RequestedSecurityToken", 0, "wsse:BinarySecurityToken", -1); const char* addr = ezxml_txt(ezxml_get(tokr, "wsp:AppliesTo", 0, "wsa:EndpointReference", 0, "wsa:Address", -1)); - if (strcmp(addr, "http://Passport.NET/tb") == 0) - { + if (strcmp(addr, "http://Passport.NET/tb") == 0) { ezxml_t node = ezxml_get(tokr, "wst:RequestedSecurityToken", 0, "EncryptedData", -1); free(hotAuthToken); hotAuthToken = ezxml_toxml(node, 0); @@ -210,73 +194,60 @@ int CMsnProto::MSN_GetPassportAuth(void) node = ezxml_get(tokr, "wst:RequestedProofToken", 0, "wst:BinarySecret", -1); replaceStr(hotSecretToken, ezxml_txt(node)); } - else if (strcmp(addr, "messengerclear.live.com") == 0) - { + else if (strcmp(addr, "messengerclear.live.com") == 0) { ezxml_t node = ezxml_get(tokr, "wst:RequestedProofToken", 0, "wst:BinarySecret", -1); - if (toks) - { + if (toks) { replaceStr(authStrToken, ezxml_txt(toks)); replaceStr(authSecretToken, ezxml_txt(node)); retVal = 0; } - else - { + else { errurl = ezxml_txt(ezxml_get(tokr, "S:Fault", 0, "psf:pp", 0, "psf:flowurl", -1)); } } - else if (strcmp(addr, "messenger.msn.com") == 0 && toks) - { + else if (strcmp(addr, "messenger.msn.com") == 0 && toks) { const char* tok = ezxml_txt(toks); char* ch = (char*)strchr(tok, '&'); *ch = 0; - replaceStr(tAuthToken, tok+2); - replaceStr(pAuthToken, ch+3); + replaceStr(tAuthToken, tok + 2); + replaceStr(pAuthToken, ch + 3); *ch = '&'; } - else if (strcmp(addr, "contacts.msn.com") == 0 && toks) - { + else if (strcmp(addr, "contacts.msn.com") == 0 && toks) { replaceStr(authContactToken, ezxml_txt(toks)); } - else if (strcmp(addr, "messengersecure.live.com") == 0 && toks) - { + else if (strcmp(addr, "messengersecure.live.com") == 0 && toks) { replaceStr(oimSendToken, ezxml_txt(toks)); } - else if (strcmp(addr, "storage.msn.com") == 0 && toks) - { + else if (strcmp(addr, "storage.msn.com") == 0 && toks) { replaceStr(authStorageToken, ezxml_txt(toks)); } tokr = ezxml_next(tokr); } - if (retVal != 0) - { - if (errurl) - { + if (retVal != 0) { + if (errurl) { debugLogA("Starting URL: '%s'", errurl); CallService(MS_UTILS_OPENURL, 1, (LPARAM)errurl); } ezxml_t tokf = ezxml_get(xml, "S:Body", 0, "S:Fault", 0, "S:Detail", -1); ezxml_t tokrdr = ezxml_child(tokf, "psf:redirectUrl"); - if (tokrdr != NULL) - { + if (tokrdr != NULL) { strcpy(szPassportHost, ezxml_txt(tokrdr)); debugLogA("Redirected to '%s'", szPassportHost); } - else - { + else { const char* szFault = ezxml_txt(ezxml_get(tokf, "psf:error", 0, "psf:value", -1)); retVal = strcmp(szFault, "0x80048821") == 0 ? 3 : (tokf ? 5 : 7); - if (retVal != 3 && defaultUrlAllow) - { + if (retVal != 3 && defaultUrlAllow) { strcpy(szPassportHost, defaultPassportUrl); defaultUrlAllow = false; retVal = -1; } - else if (retVal != 3 && retVal != 7) - { + else if (retVal != 3 && retVal != 7) { char err[512]; mir_snprintf(err, sizeof(err), "Unknown Authentication error: %s", szFault); MSN_ShowError(err); @@ -285,26 +256,23 @@ int CMsnProto::MSN_GetPassportAuth(void) } ezxml_free(xml); - break; } - default: - if (defaultUrlAllow) - { - strcpy(szPassportHost, defaultPassportUrl); - defaultUrlAllow = false; - } - else - retVal = 6; + break; + + default: + if (defaultUrlAllow) { + strcpy(szPassportHost, defaultPassportUrl); + defaultUrlAllow = false; + } + else + retVal = 6; } mir_free(tResult); } - if (retVal != 0) - { - if (!Miranda_Terminated()) - { - switch (retVal) - { + if (retVal != 0) { + if (!Miranda_Terminated()) { + switch (retVal) { case 3: MSN_ShowError("Your username or password is incorrect"); ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD); @@ -382,7 +350,7 @@ static unsigned char* PKCS5_Padding(char* in, size_t &len) unsigned char* res = (unsigned char*)mir_alloc(nlen); memcpy(res, in, len); - const unsigned char pad = 8 - (len & 7); + const unsigned char pad = 8 - (len & 7); memset(res + len, pad, pad); len = nlen; @@ -395,8 +363,8 @@ char* CMsnProto::GenerateLoginBlob(char* challenge) unsigned key1len; BYTE *key1 = (BYTE*)mir_base64_decode(authSecretToken, &key1len); - BYTE key2[MIR_SHA1_HASH_SIZE+4]; - BYTE key3[MIR_SHA1_HASH_SIZE+4]; + BYTE key2[MIR_SHA1_HASH_SIZE + 4]; + BYTE key3[MIR_SHA1_HASH_SIZE + 4]; static const unsigned char encdata1[] = "WS-SecureConversationSESSION KEY HASH"; static const unsigned char encdata2[] = "WS-SecureConversationSESSION KEY ENCRYPTION"; @@ -407,7 +375,7 @@ char* CMsnProto::GenerateLoginBlob(char* challenge) size_t chllen = strlen(challenge); BYTE hash[MIR_SHA1_HASH_SIZE]; - mir_hmac_sha1(hash, key2, MIR_SHA1_HASH_SIZE+4, (BYTE*)challenge, chllen); + mir_hmac_sha1(hash, key2, MIR_SHA1_HASH_SIZE + 4, (BYTE*)challenge, chllen); unsigned char* newchl = PKCS5_Padding(challenge, chllen); @@ -455,7 +423,7 @@ CMStringA CMsnProto::HotmailLogin(const char* url) memcpy(data1, encdata, sizeof(encdata) - 1); memcpy(data1 + sizeof(encdata) - 1, nonce, sizeof(nonce)); - unsigned char key2[MIR_SHA1_HASH_SIZE+4]; + unsigned char key2[MIR_SHA1_HASH_SIZE + 4]; derive_key(key2, key1, key1len, data1, data1len); CMStringA result; diff --git a/protocols/MSN/src/msn_avatar.cpp b/protocols/MSN/src/msn_avatar.cpp index ba3b0da6ce..50c7430e83 100644 --- a/protocols/MSN/src/msn_avatar.cpp +++ b/protocols/MSN/src/msn_avatar.cpp @@ -39,7 +39,7 @@ void CMsnProto::pushAvatarRequest(MCONTACT hContact, LPCSTR pszUrl) if (pszUrl != NULL && *pszUrl != 0) { mir_cslock lck(csAvatarQueue); - for (int i=0; i < lsAvatarQueue.getCount(); i++) + for (int i = 0; i < lsAvatarQueue.getCount(); i++) if (lsAvatarQueue[i]->hContact == hContact) return; @@ -96,11 +96,11 @@ LBL_Error: void __cdecl CMsnProto::MSN_AvatarsThread(void*) { - while(true) { + while (true) { if (WaitForSingleObject(hevAvatarQueue, INFINITE) != WAIT_OBJECT_0) break; - if ( Miranda_Terminated()) + if (Miranda_Terminated()) break; AvatarQueueEntry *p = NULL; @@ -115,7 +115,7 @@ void __cdecl CMsnProto::MSN_AvatarsThread(void*) if (p == NULL) continue; - if ( !loadHttpAvatar(p)) + if (!loadHttpAvatar(p)) ProtoBroadcastAck(p->hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, 0, 0); delete p; } diff --git a/protocols/MSN/src/msn_chat.cpp b/protocols/MSN/src/msn_chat.cpp index 04b17072d5..fb90187f21 100644 --- a/protocols/MSN/src/msn_chat.cpp +++ b/protocols/MSN/src/msn_chat.cpp @@ -28,7 +28,7 @@ along with this program. If not, see . MCONTACT CMsnProto::MSN_GetChatInernalHandle(MCONTACT hContact) { MCONTACT result = hContact; - if ( isChatRoom(hContact)) { + if (isChatRoom(hContact)) { DBVARIANT dbv; if (getString(hContact, "ChatRoomID", &dbv) == 0) { result = (MCONTACT)(-atol(dbv.pszVal)); @@ -96,8 +96,7 @@ void CMsnProto::MSN_ChatStart(ThreadData* info) gce.time = time(NULL); gce.bIsMe = FALSE; - for (int j=0; j < info->mJoinedContactsWLID.getCount(); j++) - { + for (int j = 0; j < info->mJoinedContactsWLID.getCount(); j++) { MCONTACT hContact = MSN_HContactFromEmail(info->mJoinedContactsWLID[j]); TCHAR *wlid = mir_a2t(info->mJoinedContactsWLID[j]); @@ -120,10 +119,8 @@ void CMsnProto::MSN_KillChatSession(const TCHAR* id) static void ChatInviteUser(ThreadData* info, const char* email) { - if (info->mJoinedContactsWLID.getCount()) - { - for (int j=0; j < info->mJoinedContactsWLID.getCount(); j++) - { + if (info->mJoinedContactsWLID.getCount()) { + for (int j = 0; j < info->mJoinedContactsWLID.getCount(); j++) { if (_stricmp(info->mJoinedContactsWLID[j], email) == 0) return; } @@ -138,27 +135,21 @@ static void ChatInviteSend(HANDLE hItem, HWND hwndList, STRLIST &str, CMsnProto if (hItem == NULL) hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0); - while (hItem) - { - if (IsHContactGroup(hItem)) - { + while (hItem) { + if (IsHContactGroup(hItem)) { HANDLE hItemT = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_CHILD, (LPARAM)hItem); if (hItemT) ChatInviteSend(hItemT, hwndList, str, ppro); } - else - { + else { int chk = SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0); - if (chk) - { - if (IsHContactInfo(hItem)) - { + if (chk) { + if (IsHContactInfo(hItem)) { TCHAR buf[128] = _T(""); SendMessage(hwndList, CLM_GETITEMTEXT, (WPARAM)hItem, (LPARAM)buf); if (buf[0]) str.insert(mir_t2a(buf)); } - else - { + else { MsnContact *msc = ppro->Lists_Get((MCONTACT)hItem); if (msc) str.insertn(msc->email); } @@ -180,8 +171,7 @@ static void ChatPrepare(MCONTACT hItem, HWND hwndList, CMsnProto* ppro) if (hItem == NULL) hItem = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0); - while (hItem) - { + while (hItem) { MCONTACT hItemN = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXT, (LPARAM)hItem); if (IsHContactGroup(hItem)) { @@ -193,22 +183,21 @@ static void ChatPrepare(MCONTACT hItem, HWND hwndList, CMsnProto* ppro) ChatValidateContact(hItem, hwndList, ppro); hItem = hItemN; - } + } } INT_PTR CALLBACK DlgInviteToChat(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { InviteChatParam *param = (InviteChatParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) - { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); param = (InviteChatParam*)lParam; -// WindowSetIcon(hwndDlg, "msn"); + // WindowSetIcon(hwndDlg, "msn"); break; case WM_CLOSE: @@ -216,89 +205,78 @@ INT_PTR CALLBACK DlgInviteToChat(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l break; case WM_NCDESTROY: -// WindowFreeIcon(hwndDlg); + // WindowFreeIcon(hwndDlg); delete param; break; case WM_NOTIFY: - { - NMCLISTCONTROL* nmc = (NMCLISTCONTROL*)lParam; - if (nmc->hdr.idFrom == IDC_CCLIST) + NMCLISTCONTROL* nmc; { - switch (nmc->hdr.code) - { - case CLN_NEWCONTACT: - if (param && (nmc->flags & (CLNF_ISGROUP | CLNF_ISINFO)) == 0) - ChatValidateContact((MCONTACT)nmc->hItem, nmc->hdr.hwndFrom, param->ppro); - break; - - case CLN_LISTREBUILT: - if (param) - ChatPrepare(NULL, nmc->hdr.hwndFrom, param->ppro); - break; + nmc = (NMCLISTCONTROL*)lParam; + if (nmc->hdr.idFrom == IDC_CCLIST) { + switch (nmc->hdr.code) { + case CLN_NEWCONTACT: + if (param && (nmc->flags & (CLNF_ISGROUP | CLNF_ISINFO)) == 0) + ChatValidateContact((MCONTACT)nmc->hItem, nmc->hdr.hwndFrom, param->ppro); + break; + + case CLN_LISTREBUILT: + if (param) + ChatPrepare(NULL, nmc->hdr.hwndFrom, param->ppro); + break; + } } } - } - break; + break; case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDC_ADDSCR: - if (param->ppro->msnLoggedIn) - { - TCHAR email[MSN_MAX_EMAIL_LEN]; - GetDlgItemText(hwndDlg, IDC_EDITSCR, email, SIZEOF(email)); + switch (LOWORD(wParam)) { + case IDC_ADDSCR: + if (param->ppro->msnLoggedIn) { + TCHAR email[MSN_MAX_EMAIL_LEN]; + GetDlgItemText(hwndDlg, IDC_EDITSCR, email, SIZEOF(email)); + + CLCINFOITEM cii = { 0 }; + cii.cbSize = sizeof(cii); + cii.flags = CLCIIF_CHECKBOX | CLCIIF_BELOWCONTACTS; + cii.pszText = _tcslwr(email); + + HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CCLIST, CLM_ADDINFOITEM, 0, (LPARAM)&cii); + SendDlgItemMessage(hwndDlg, IDC_CCLIST, CLM_SETCHECKMARK, (LPARAM)hItem, 1); + } + break; - CLCINFOITEM cii = {0}; - cii.cbSize = sizeof(cii); - cii.flags = CLCIIF_CHECKBOX | CLCIIF_BELOWCONTACTS; - cii.pszText = _tcslwr(email); + case IDCANCEL: + EndDialog(hwndDlg, IDCANCEL); + break; - HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CCLIST, CLM_ADDINFOITEM, 0, (LPARAM)&cii); - SendDlgItemMessage(hwndDlg, IDC_CCLIST, CLM_SETCHECKMARK, (LPARAM)hItem, 1); - } - break; - - case IDOK: - { - char tEmail[MSN_MAX_EMAIL_LEN] = ""; - ThreadData *info = NULL; - if (param->id) - info = param->ppro->MSN_GetThreadByChatId(param->id); - else if (param->hContact) - { - if (!param->ppro->MSN_IsMeByContact(param->hContact, tEmail)) - info = param->ppro->MSN_GetThreadByContact(tEmail); - } - - HWND hwndList = GetDlgItem(hwndDlg, IDC_CCLIST); - STRLIST *cont = new STRLIST; - ChatInviteSend(NULL, hwndList, *cont, param->ppro); - - if (info) - { - for (int i = 0; i < cont->getCount(); ++i) - ChatInviteUser(info, (*cont)[i]); - delete cont; - } - else - { - if (tEmail[0]) cont->insertn(tEmail); - param->ppro->MsgQueue_Add("chat", 'X', NULL, 0, NULL, 0, cont); - if (param->ppro->msnLoggedIn) - param->ppro->msnNsThread->sendPacket("XFR", "SB"); - } - } + case IDOK: + char tEmail[MSN_MAX_EMAIL_LEN]; tEmail[0] = 0; + ThreadData *info = NULL; + if (param->id) + info = param->ppro->MSN_GetThreadByChatId(param->id); + else if (param->hContact) { + if (!param->ppro->MSN_IsMeByContact(param->hContact, tEmail)) + info = param->ppro->MSN_GetThreadByContact(tEmail); + } - EndDialog(hwndDlg, IDOK); - break; + HWND hwndList = GetDlgItem(hwndDlg, IDC_CCLIST); + STRLIST *cont = new STRLIST; + ChatInviteSend(NULL, hwndList, *cont, param->ppro); - case IDCANCEL: - EndDialog(hwndDlg, IDCANCEL); - break; + if (info) { + for (int i = 0; i < cont->getCount(); ++i) + ChatInviteUser(info, (*cont)[i]); + delete cont; } + else { + if (tEmail[0]) cont->insertn(tEmail); + param->ppro->MsgQueue_Add("chat", 'X', NULL, 0, NULL, 0, cont); + if (param->ppro->msnLoggedIn) + param->ppro->msnNsThread->sendPacket("XFR", "SB"); + } + + EndDialog(hwndDlg, IDOK); } break; } @@ -313,109 +291,101 @@ int CMsnProto::MSN_GCEventHook(WPARAM, LPARAM lParam) if (_stricmp(gch->pDest->pszModule, m_szModuleName)) return 0; - switch (gch->pDest->iType) - { - case GC_SESSION_TERMINATE: + switch (gch->pDest->iType) { + case GC_SESSION_TERMINATE: { - ThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID); + ThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID); if (thread != NULL) thread->sendTerminate(); - break; } + break; - case GC_USER_MESSAGE: - if (gch->ptszText && gch->ptszText[0]) - { - ThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID); - if (thread) - { - TCHAR* pszMsg = UnEscapeChatTags(NEWTSTR_ALLOCA(gch->ptszText)); - rtrimt(pszMsg); // remove the ending linebreak - thread->sendMessage('N', NULL, NETID_MSN, UTF8(pszMsg), 0); - - DBVARIANT dbv; - int bError = getTString("Nick", &dbv); - - GCDEST gcd = { m_szModuleName, gch->pDest->ptszID, GC_EVENT_MESSAGE }; - GCEVENT gce = { sizeof(gce), &gcd }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = bError ? _T("") : dbv.ptszVal; - gce.ptszUID = mir_a2t(MyOptions.szEmail); - gce.time = time(NULL); - gce.ptszText = gch->ptszText; - gce.bIsMe = TRUE; - CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); - - mir_free((void*)gce.ptszUID); - if (!bError) - db_free(&dbv); - } + case GC_USER_MESSAGE: + if (gch->ptszText && gch->ptszText[0]) { + ThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID); + if (thread) { + TCHAR* pszMsg = UnEscapeChatTags(NEWTSTR_ALLOCA(gch->ptszText)); + rtrimt(pszMsg); // remove the ending linebreak + thread->sendMessage('N', NULL, NETID_MSN, UTF8(pszMsg), 0); + + DBVARIANT dbv; + int bError = getTString("Nick", &dbv); + + GCDEST gcd = { m_szModuleName, gch->pDest->ptszID, GC_EVENT_MESSAGE }; + GCEVENT gce = { sizeof(gce), &gcd }; + gce.dwFlags = GCEF_ADDTOLOG; + gce.ptszNick = bError ? _T("") : dbv.ptszVal; + gce.ptszUID = mir_a2t(MyOptions.szEmail); + gce.time = time(NULL); + gce.ptszText = gch->ptszText; + gce.bIsMe = TRUE; + CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); + + mir_free((void*)gce.ptszUID); + if (!bError) + db_free(&dbv); } - break; + } + break; + + case GC_USER_CHANMGR: + DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, + LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this))); + break; + + case GC_USER_PRIVMESS: + { + char *email = mir_t2a(gch->ptszUID); + MCONTACT hContact = MSN_HContactFromEmail(email); + CallService(MS_MSG_SENDMESSAGE, hContact, 0); + mir_free(email); + break; + } - case GC_USER_CHANMGR: + case GC_USER_LOGMENU: + switch (gch->dwData) { + case 10: DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this))); break; - case GC_USER_PRIVMESS: - { - char *email = mir_t2a(gch->ptszUID); - MCONTACT hContact = MSN_HContactFromEmail(email); - CallService(MS_MSG_SENDMESSAGE, hContact, 0); - mir_free(email); + case 20: + MSN_KillChatSession(gch->pDest->ptszID); break; } + break; - case GC_USER_LOGMENU: - switch(gch->dwData) - { - case 10: - DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, - LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this))); - break; - - case 20: - MSN_KillChatSession(gch->pDest->ptszID); - break; - } - break; - - case GC_USER_NICKLISTMENU: - { - char *email = mir_t2a(gch->ptszUID); - MCONTACT hContact = MSN_HContactFromEmail(email); - mir_free(email); + case GC_USER_NICKLISTMENU: + MCONTACT hContact = MSN_HContactFromEmail(_T2A(gch->ptszUID)); - switch(gch->dwData) - { - case 10: - CallService(MS_USERINFO_SHOWDIALOG, hContact, 0); - break; + switch (gch->dwData) { + case 10: + CallService(MS_USERINFO_SHOWDIALOG, hContact, 0); + break; - case 20: - CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact, 0); - break; + case 20: + CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact, 0); + break; - case 110: - MSN_KillChatSession(gch->pDest->ptszID); - break; - } + case 110: + MSN_KillChatSession(gch->pDest->ptszID); break; } -/* haven't implemented in chat.dll - case GC_USER_TYPNOTIFY: - { + break; + + /* haven't implemented in chat.dll + case GC_USER_TYPNOTIFY: + { int chatID = atoi(p); ThreadData* thread = MSN_GetThreadByContact((HANDLE)-chatID); for (int j=0; j < thread->mJoinedCount; j++) { - if ((long)thread->mJoinedContacts[j] > 0) - CallService(MS_PROTO_SELFISTYPING, (WPARAM) thread->mJoinedContacts[j], (LPARAM) PROTOTYPE_SELFTYPING_ON); + if ((long)thread->mJoinedContacts[j] > 0) + CallService(MS_PROTO_SELFISTYPING, (WPARAM) thread->mJoinedContacts[j], (LPARAM) PROTOTYPE_SELFTYPING_ON); } break; - } -*/ + } + */ } return 0; @@ -423,12 +393,11 @@ int CMsnProto::MSN_GCEventHook(WPARAM, LPARAM lParam) int CMsnProto::MSN_GCMenuHook(WPARAM, LPARAM lParam) { - GCMENUITEMS *gcmi= (GCMENUITEMS*) lParam; + GCMENUITEMS *gcmi = (GCMENUITEMS*)lParam; 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[] = { { LPGENT("&Invite user..."), 10, MENU_ITEM, FALSE }, @@ -437,11 +406,9 @@ int CMsnProto::MSN_GCMenuHook(WPARAM, LPARAM lParam) gcmi->nItems = SIZEOF(Items); gcmi->Item = (gc_item*)Items; } - else if (gcmi->Type == MENU_ON_NICKLIST) - { - char* email = mir_t2a(gcmi->pszUID); - if (!_stricmp(MyOptions.szEmail, email)) - { + else if (gcmi->Type == MENU_ON_NICKLIST) { + char *email = mir_t2a(gcmi->pszUID); + if (!_stricmp(MyOptions.szEmail, email)) { static const struct gc_item Items[] = { { LPGENT("User &details"), 10, MENU_ITEM, FALSE }, @@ -452,8 +419,7 @@ int CMsnProto::MSN_GCMenuHook(WPARAM, LPARAM lParam) gcmi->nItems = SIZEOF(Items); gcmi->Item = (gc_item*)Items; } - else - { + else { static const struct gc_item Items[] = { { LPGENT("User &details"), 10, MENU_ITEM, FALSE }, diff --git a/protocols/MSN/src/msn_contact.cpp b/protocols/MSN/src/msn_contact.cpp index fc3bef21a1..06f5abe7e5 100644 --- a/protocols/MSN/src/msn_contact.cpp +++ b/protocols/MSN/src/msn_contact.cpp @@ -27,11 +27,12 @@ MCONTACT CMsnProto::MSN_HContactFromEmail(const char* wlid, const char* msnNick, { MCONTACT hContact = NULL; - char* szEmail; + char *szEmail; parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); MsnContact *msc = Lists_Get(szEmail); - if (msc && msc->hContact) hContact = msc->hContact; + if (msc && msc->hContact) + hContact = msc->hContact; if (hContact == NULL && addIfNeeded) { hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); @@ -53,16 +54,13 @@ void CMsnProto::MSN_SetContactDb(MCONTACT hContact, const char *szEmail) MsnContact *cont = Lists_Get(szEmail); const int listId = cont->list; - if (listId & LIST_FL) - { - if (db_get_b(hContact, "CList", "NotOnList", 0) == 1) - { + if (listId & LIST_FL) { + if (db_get_b(hContact, "CList", "NotOnList", 0) == 1) { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } - if (listId & (LIST_BL | LIST_AL)) - { + if (listId & (LIST_BL | LIST_AL)) { WORD tApparentMode = getWord(hContact, "ApparentMode", 0); if ((listId & LIST_BL) && tApparentMode == 0) setWord(hContact, "ApparentMode", ID_STATUS_OFFLINE); @@ -70,8 +68,7 @@ void CMsnProto::MSN_SetContactDb(MCONTACT hContact, const char *szEmail) delSetting(hContact, "ApparentMode"); } - if (cont->netId == NETID_MOB) - { + if (cont->netId == NETID_MOB) { setWord(hContact, "Status", ID_STATUS_ONTHEPHONE); setString(hContact, "MirVer", "SMS"); } @@ -80,7 +77,6 @@ void CMsnProto::MSN_SetContactDb(MCONTACT hContact, const char *szEmail) setByte(hContact, "LocalList", 1); else delSetting(hContact, "LocalList"); - } @@ -89,21 +85,18 @@ void CMsnProto::AddDelUserContList(const char* email, const int list, const int char buf[512]; size_t sz; - if (list < LIST_RL) - { + if (list < LIST_RL) { const char* dom = strchr(email, '@'); - if (dom == NULL) - { + if (dom == NULL) { sz = mir_snprintf(buf, sizeof(buf), "", email, list); } - else - { + else { *(char*)dom = 0; sz = mir_snprintf(buf, sizeof(buf), "", - dom+1, email, list, netId); + dom + 1, email, list, netId); *(char*)dom = '@'; } msnNsThread->sendPacket(del ? "RML" : "ADL", "%d\r\n%s", sz, buf); @@ -121,33 +114,29 @@ void CMsnProto::AddDelUserContList(const char* email, const int list, const int bool CMsnProto::MSN_AddUser(MCONTACT hContact, const char* email, int netId, int flags, const char *msg) { - bool needRemove = (flags & LIST_REMOVE) != 0; - bool leaveHotmail = (flags & LIST_REMOVENH) == LIST_REMOVENH; + bool needRemove = (flags & LIST_REMOVE) != 0; + bool leaveHotmail = (flags & LIST_REMOVENH) == LIST_REMOVENH; flags &= 0xFF; if (needRemove != Lists_IsInList(flags, email)) return true; - bool res = false; - if (flags == LIST_FL) - { - if (needRemove) - { - if (hContact == NULL) - { + if (flags == LIST_FL) { + if (needRemove) { + if (hContact == NULL) { hContact = MSN_HContactFromEmail(email); - if (hContact == NULL) return false; + if (hContact == NULL) + return false; } char id[MSN_GUID_LEN]; - if (!db_get_static(hContact, m_szModuleName, "ID", id, sizeof(id))) - { + if (!db_get_static(hContact, m_szModuleName, "ID", id, sizeof(id))) { int netId = Lists_GetNetId(email); if (leaveHotmail) res = MSN_ABAddRemoveContact(id, netId, false); else - res = MSN_ABAddDelContactGroup(id , NULL, "ABContactDelete"); + res = MSN_ABAddDelContactGroup(id, NULL, "ABContactDelete"); if (res) AddDelUserContList(email, flags, netId, true); delSetting(hContact, "GroupID"); @@ -155,37 +144,29 @@ bool CMsnProto::MSN_AddUser(MCONTACT hContact, const char* email, int netId, int MSN_RemoveEmptyGroups(); } } - else - { - DBVARIANT dbv = {0}; + else { + DBVARIANT dbv = { 0 }; if (!strcmp(email, MyOptions.szEmail)) getStringUtf("Nick", &dbv); unsigned res1 = MSN_ABContactAdd(email, dbv.pszVal, netId, msg, false); - if (netId == NETID_MSN && res1 == 2) - { + if (netId == NETID_MSN && res1 == 2) { netId = NETID_LCS; res = MSN_ABContactAdd(email, dbv.pszVal, netId, msg, false) == 0; } - else if (netId == NETID_MSN && res1 == 3) - { + else if (netId == NETID_MSN && res1 == 3) { char szContactID[100]; hContact = MSN_HContactFromEmail(email); - if (db_get_static(hContact, m_szModuleName, "ID", szContactID, sizeof(szContactID)) == 0) - { + if (db_get_static(hContact, m_szModuleName, "ID", szContactID, sizeof(szContactID)) == 0) { MSN_ABAddRemoveContact(szContactID, netId, true); res = true; } } + else res = (res1 == 0); - else - res = (res1 == 0); - - if (res) - { + if (res) { DBVARIANT dbv; - if (!db_get_utf(hContact, "CList", "Group", &dbv)) - { + if (!db_get_utf(hContact, "CList", "Group", &dbv)) { MSN_MoveContactToGroup(hContact, dbv.pszVal); db_free(&dbv); } @@ -197,36 +178,30 @@ bool CMsnProto::MSN_AddUser(MCONTACT hContact, const char* email, int netId, int MSN_SharingFindMembership(true); AddDelUserContList(email, flags, netId, false); } - else - { - if (netId == 1 && strstr(email, "@yahoo.com") != 0) - MSN_FindYahooUser(email); - } + else if (netId == 1 && strstr(email, "@yahoo.com") != 0) + MSN_FindYahooUser(email); + db_free(&dbv); } } - else if (flags == LIST_LL) - { + else if (flags == LIST_LL) { if (needRemove) Lists_Remove(LIST_LL, email); else Lists_Add(LIST_LL, NETID_MSN, email); } - else - { - if (netId == 0) netId = Lists_GetNetId(email); + else { + if (netId == 0) + netId = Lists_GetNetId(email); res = MSN_SharingAddDelMember(email, flags, netId, needRemove ? "DeleteMember" : "AddMember"); -// if (res || (flags & LIST_RL)) - AddDelUserContList(email, flags, netId, needRemove); - if ((flags & LIST_BL) && !needRemove) - { - ThreadData* thread = MSN_GetThreadByContact(email, SERVER_SWITCHBOARD); + AddDelUserContList(email, flags, netId, needRemove); + if ((flags & LIST_BL) && !needRemove) { + ThreadData* thread = MSN_GetThreadByContact(email, SERVER_SWITCHBOARD); if (thread) thread->sendTerminate(); } + if ((flags & LIST_PL) && needRemove) - { MSN_AddUser(hContact, email, netId, LIST_RL); - } } return res; } @@ -234,14 +209,13 @@ bool CMsnProto::MSN_AddUser(MCONTACT hContact, const char* email, int netId, int void CMsnProto::MSN_FindYahooUser(const char* email) { - const char* dom = strchr(email, '@'); - if (dom) - { + const char *dom = strchr(email, '@'); + if (dom) { char buf[512]; size_t sz; *(char*)dom = '\0'; - sz = mir_snprintf(buf, sizeof(buf), "", dom+1, email); + sz = mir_snprintf(buf, sizeof(buf), "", dom + 1, email); *(char*)dom = '@'; msnNsThread->sendPacket("FQY", "%d\r\n%s", sz, buf); } diff --git a/protocols/MSN/src/msn_errors.cpp b/protocols/MSN/src/msn_errors.cpp index 177122d4e0..6ced78f708 100644 --- a/protocols/MSN/src/msn_errors.cpp +++ b/protocols/MSN/src/msn_errors.cpp @@ -30,7 +30,7 @@ int CMsnProto::MSN_HandleErrors(ThreadData* info, char* cmdString) debugLogA("Server error:%s", cmdString); - switch(errorCode) { + switch (errorCode) { case ERR_INTERNAL_SERVER: MSN_ShowError("MSN Services are temporarily unavailable, please try to connect later"); ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NOSERVER); @@ -56,15 +56,15 @@ int CMsnProto::MSN_HandleErrors(ThreadData* info, char* cmdString) case ERR_CONTACT_LIST_FAILED: case ERR_LIST_UNAVAILABLE: - char* tWords[3]; - if (sttDivideWords(cmdString, 3, tWords) == 3) - HReadBuffer(info, 0).surelyRead(atol(tWords[2])); - return 0; + char* tWords[3]; + if (sttDivideWords(cmdString, 3, tWords) == 3) + HReadBuffer(info, 0).surelyRead(atol(tWords[2])); + return 0; case ERR_NOT_ONLINE: if (info->mInitialContactWLID) ProtoBroadcastAck(MSN_HContactFromEmail(info->mInitialContactWLID), ACKTYPE_MESSAGE, ACKRESULT_FAILED, - (HANDLE)999999, (LPARAM)Translate("User not online")); + (HANDLE)999999, (LPARAM)Translate("User not online")); else MSN_ShowError("User not online"); @@ -75,8 +75,7 @@ int CMsnProto::MSN_HandleErrors(ThreadData* info, char* cmdString) return 0; case ERR_AUTHENTICATION_FAILED: - if (info->mType != SERVER_SWITCHBOARD) - { + if (info->mType != SERVER_SWITCHBOARD) { MSN_ShowError("Your username or password is incorrect"); ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD); } diff --git a/protocols/MSN/src/msn_ftold.cpp b/protocols/MSN/src/msn_ftold.cpp index db1ba3de66..20284d152a 100644 --- a/protocols/MSN/src/msn_ftold.cpp +++ b/protocols/MSN/src/msn_ftold.cpp @@ -23,14 +23,12 @@ along with this program. If not, see . #include "msn_global.h" #include "msn_proto.h" - void CMsnProto::msnftp_sendAcceptReject(filetransfer *ft, bool acc) { ThreadData* thread = MSN_GetThreadByContact(ft->p2p_dest); if (thread == NULL) return; - if (acc) - { + if (acc) { thread->sendPacket("MSG", "U %d\r\nMIME-Version: 1.0\r\n" "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" @@ -38,17 +36,16 @@ void CMsnProto::msnftp_sendAcceptReject(filetransfer *ft, bool acc) "Invitation-Cookie: %s\r\n" "Launch-Application: FALSE\r\n" "Request-Data: IP-Address:\r\n\r\n", - 172+4+strlen(ft->szInvcookie), ft->szInvcookie); + 172 + 4 + strlen(ft->szInvcookie), ft->szInvcookie); } - else - { + else { thread->sendPacket("MSG", "U %d\r\nMIME-Version: 1.0\r\n" "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" "Invitation-Command: CANCEL\r\n" "Invitation-Cookie: %s\r\n" "Cancel-Code: REJECT\r\n\r\n", - 172-33+4+strlen(ft->szInvcookie), ft->szInvcookie); + 172 - 33 + 4 + strlen(ft->szInvcookie), ft->szInvcookie); } } @@ -65,8 +62,8 @@ void CMsnProto::msnftp_invite(filetransfer *ft) else pszFiles = *ft->std.ptszFiles; - char msg[1024]; - mir_snprintf(msg, SIZEOF(msg), + char msg[1024]; + mir_snprintf(msg, SIZEOF(msg), "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" "Application-Name: File Transfer\r\n" "Application-GUID: {5D3E02AB-6190-11d3-BBBB-00C04F795683}\r\n" @@ -92,36 +89,31 @@ int CMsnProto::MSN_HandleMSNFTP(ThreadData *info, char *cmdString) filetransfer* ft = info->mMsnFtp; if (cmdString[3]) - params = cmdString+4; + params = cmdString + 4; - switch((*(PDWORD)cmdString&0x00FFFFFF)|0x20000000) - { - case ' EYB': //********* BYE - { - ft->complete(); - return 1; - } - case ' LIF': //********* FIL - { - char filesize[30]; - if (sscanf(params, "%s", filesize) < 1) - goto LBL_InvalidCommand; + switch ((*(PDWORD)cmdString & 0x00FFFFFF) | 0x20000000) { + case ' EYB': //********* BYE + ft->complete(); + return 1; - info->mCaller = 1; - info->send("TFR\r\n", 5); - break; - } - case ' RFT': //********* TFR + case ' LIF': //********* FIL + char filesize[30]; + if (sscanf(params, "%s", filesize) < 1) + goto LBL_InvalidCommand; + + info->mCaller = 1; + info->send("TFR\r\n", 5); + break; + + case ' RFT': //********* TFR { - char* sendpacket = (char*)alloca(2048); + char *sendpacket = (char*)alloca(2048); filetransfer* ft = info->mMsnFtp; info->mCaller = 3; - while (ft->std.currentFileProgress < ft->std.currentFileSize) - { - if (ft->bCanceled) - { + while (ft->std.currentFileProgress < ft->std.currentFileSize) { + if (ft->bCanceled) { sendpacket[0] = 0x01; sendpacket[1] = 0x00; sendpacket[2] = 0x00; @@ -138,7 +130,7 @@ int CMsnProto::MSN_HandleMSNFTP(ThreadData *info, char *cmdString) sendpacket[wPlace++] = (char)((packetLen & 0xff00) >> 8); _read(ft->fileId, &sendpacket[wPlace], packetLen); - info->send(&sendpacket[0], packetLen+3); + info->send(&sendpacket[0], packetLen + 3); ft->std.totalProgress += packetLen; ft->std.currentFileProgress += packetLen; @@ -147,107 +139,94 @@ int CMsnProto::MSN_HandleMSNFTP(ThreadData *info, char *cmdString) } ft->complete(); - break; } - case ' RSU': //********* USR - { - char email[130],authcookie[14]; - if (sscanf(params,"%129s %13s",email,authcookie) < 2) - { - debugLogA("Invalid USR OK command, ignoring"); - break; - } + break; - char tCommand[30]; - mir_snprintf(tCommand, sizeof(tCommand), "FIL %i\r\n", info->mMsnFtp->std.totalBytes); - info->send(tCommand, strlen(tCommand)); + case ' RSU': //********* USR + char email[130], authcookie[14]; + if (sscanf(params, "%129s %13s", email, authcookie) < 2) { + debugLogA("Invalid USR OK command, ignoring"); break; } - case ' REV': //********* VER - { - char protocol1[7]; - if (sscanf(params, "%6s", protocol1) < 1) - { + + char tCommand[30]; + mir_snprintf(tCommand, sizeof(tCommand), "FIL %i\r\n", info->mMsnFtp->std.totalBytes); + info->send(tCommand, strlen(tCommand)); + break; + + case ' REV': //********* VER + char protocol1[7]; + if (sscanf(params, "%6s", protocol1) < 1) { LBL_InvalidCommand: - debugLogA("Invalid %.3s command, ignoring", cmdString); - break; - } + debugLogA("Invalid %.3s command, ignoring", cmdString); + break; + } - if (strcmp(protocol1, "MSNFTP") != 0) - { - int tempInt; - int tFieldCount = sscanf(params, "%d %6s", &tempInt, protocol1); - if (tFieldCount != 2 || strcmp(protocol1, "MSNFTP") != 0) - { - debugLogA("Another side requested the unknown protocol (%s), closing thread", params); - return 1; - } - } - - if (info->mCaller == 0) //receive - { - char tCommand[MSN_MAX_EMAIL_LEN + 50]; - mir_snprintf(tCommand, sizeof(tCommand), "USR %s %s\r\n", MyOptions.szEmail, info->mCookie); - info->send(tCommand, strlen(tCommand)); + if (strcmp(protocol1, "MSNFTP") != 0) { + int tempInt; + int tFieldCount = sscanf(params, "%d %6s", &tempInt, protocol1); + if (tFieldCount != 2 || strcmp(protocol1, "MSNFTP") != 0) { + debugLogA("Another side requested the unknown protocol (%s), closing thread", params); + return 1; } - else if (info->mCaller == 2) //send - { - static const char sttCommand[] = "VER MSNFTP\r\n"; - info->send(sttCommand, strlen(sttCommand)); - } - break; } - default: // receiving file - { - HReadBuffer tBuf(info, int(cmdString - info->mData)); - - for (;;) - { - if (ft->bCanceled) - { info->send("CCL\r\n", 5); - ft->close(); - return 1; - } - BYTE* p = tBuf.surelyRead(3); - if (p == NULL) - { + if (info->mCaller == 0) { //receive + char tCommand[MSN_MAX_EMAIL_LEN + 50]; + mir_snprintf(tCommand, sizeof(tCommand), "USR %s %s\r\n", MyOptions.szEmail, info->mCookie); + info->send(tCommand, strlen(tCommand)); + } + else if (info->mCaller == 2) { //send + static const char sttCommand[] = "VER MSNFTP\r\n"; + info->send(sttCommand, strlen(sttCommand)); + } + break; + + default: // receiving file + HReadBuffer tBuf(info, int(cmdString - info->mData)); + + for (;;) { + if (ft->bCanceled) { + info->send("CCL\r\n", 5); + ft->close(); + return 1; + } + + BYTE* p = tBuf.surelyRead(3); + if (p == NULL) { LBL_Error: - ft->close(); - MSN_ShowError("file transfer is canceled by remote host"); - return 1; - } + ft->close(); + MSN_ShowError("file transfer is canceled by remote host"); + return 1; + } - BYTE tIsTransitionFinished = *p++; - WORD dataLen = *p++; - dataLen |= (*p++ << 8); + BYTE tIsTransitionFinished = *p++; + WORD dataLen = *p++; + dataLen |= (*p++ << 8); - if (tIsTransitionFinished) - { + if (tIsTransitionFinished) { LBL_Success: - static const char sttCommand[] = "BYE 16777989\r\n"; - info->send(sttCommand, strlen(sttCommand)); - return 1; - } + static const char sttCommand[] = "BYE 16777989\r\n"; + info->send(sttCommand, strlen(sttCommand)); + return 1; + } - p = tBuf.surelyRead(dataLen); - if (p == NULL) - goto LBL_Error; + p = tBuf.surelyRead(dataLen); + if (p == NULL) + goto LBL_Error; - _write(ft->fileId, p, dataLen); - ft->std.totalProgress += dataLen; - ft->std.currentFileProgress += dataLen; + _write(ft->fileId, p, dataLen); + ft->std.totalProgress += dataLen; + ft->std.currentFileProgress += dataLen; - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); + ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); - if (ft->std.currentFileProgress == ft->std.totalBytes) - { - ft->complete(); - goto LBL_Success; - } - } - } - } + if (ft->std.currentFileProgress == ft->std.totalBytes) { + ft->complete(); + goto LBL_Success; + } + } + } return 0; } @@ -261,8 +240,7 @@ void __cdecl CMsnProto::msnftp_sendFileThread(void* arg) debugLogA("Waiting for an incoming connection to '%s'...", info->mServer); - switch(WaitForSingleObject(info->hWaitEvent, 60000)) - { + switch (WaitForSingleObject(info->hWaitEvent, 60000)) { case WAIT_TIMEOUT: case WAIT_FAILED: debugLogA("Incoming connection timed out, closing file transfer"); @@ -271,25 +249,22 @@ void __cdecl CMsnProto::msnftp_sendFileThread(void* arg) info->mBytesInData = 0; - for (;;) - { - int recvResult = info->recv(info->mData+info->mBytesInData, 1000 - info->mBytesInData); + for (;;) { + int recvResult = info->recv(info->mData + info->mBytesInData, 1000 - info->mBytesInData); if (recvResult == SOCKET_ERROR || !recvResult) break; info->mBytesInData += recvResult; //pull off each line for parsing - if (info->mCaller == 3 && info->mType == SERVER_FILETRANS) - { + if (info->mCaller == 3 && info->mType == SERVER_FILETRANS) { if (MSN_HandleMSNFTP(info, info->mData)) break; } else // info->mType!=SERVER_FILETRANS - { - for (;;) - { - char* peol = strchr(info->mData,'\r'); + { + for (;;) { + char* peol = strchr(info->mData, '\r'); if (peol == NULL) break; @@ -308,23 +283,21 @@ void __cdecl CMsnProto::msnftp_sendFileThread(void* arg) debugLogA("RECV:%s", msg); - if (!isalnum(msg[0]) || !isalnum(msg[1]) || !isalnum(msg[2]) || (msg[3] && msg[3]!=' ')) - { + if (!isalnum(msg[0]) || !isalnum(msg[1]) || !isalnum(msg[2]) || (msg[3] && msg[3] != ' ')) { debugLogA("Invalid command name"); continue; } if (MSN_HandleMSNFTP(info, msg)) break; - } - } + } + } - if (info->mBytesInData == sizeof(info->mData)) - { + if (info->mBytesInData == sizeof(info->mData)) { debugLogA("sizeof(data) is too small: the longest line won't fit"); break; - } - } + } + } debugLogA("Closing file transfer thread"); } @@ -334,12 +307,11 @@ void CMsnProto::msnftp_startFileSend(ThreadData* info, const char* Invcommand, c if (_stricmp(Invcommand, "ACCEPT")) return; - NETLIBBIND nlb = {0}; + NETLIBBIND nlb = { 0 }; HANDLE sb = NULL; filetransfer* ft = info->mMsnFtp; info->mMsnFtp = NULL; - if (ft != NULL && MyConnection.extIP) - { + if (ft != NULL && MyConnection.extIP) { nlb.cbSize = sizeof(nlb); nlb.pfnNewConnectionV2 = MSN_ConnectionProc; nlb.pExtra = this; @@ -380,8 +352,7 @@ void CMsnProto::msnftp_startFileSend(ThreadData* info, const char* Invcommand, c info->sendPacket("MSG", "N %d\r\n%s", nBytes, command); - if (sb) - { + if (sb) { ThreadData* newThread = new ThreadData; newThread->mType = SERVER_FILETRANS; newThread->mCaller = 2; @@ -390,6 +361,5 @@ void CMsnProto::msnftp_startFileSend(ThreadData* info, const char* Invcommand, c newThread->mIncomingPort = nlb.wPort; newThread->startThread(&CMsnProto::msnftp_sendFileThread, this); } - else - delete ft; + else delete ft; } diff --git a/protocols/MSN/src/msn_global.h b/protocols/MSN/src/msn_global.h index 439617d14d..5eb3ebba1b 100644 --- a/protocols/MSN/src/msn_global.h +++ b/protocols/MSN/src/msn_global.h @@ -771,9 +771,9 @@ struct TWinErrorCode const char msnProtChallenge[] = "C1BX{V4W}Q3*10SM"; const char msnProductID[] = "PROD0120PW!CCV9@"; -const char msnAppID[] = "F6D2794D-501F-443A-ADBE-8F1490FF30FD"; -const char msnStoreAppId[] = "Skype"; -const char msnProductVer[] = "6.21.0.104"; +const char msnAppID[] = "484AAC02-7F59-41B7-9601-772045DCC569"; +const char msnStoreAppId[] = "Windows Live Messenger 2012"; +const char msnProductVer[] = "16.4.3528"; const char msnProtID[] = "MSNP18"; extern HINSTANCE hInst; diff --git a/protocols/MSN/src/msn_http.cpp b/protocols/MSN/src/msn_http.cpp index ae2f18cdf2..7077c66838 100644 --- a/protocols/MSN/src/msn_http.cpp +++ b/protocols/MSN/src/msn_http.cpp @@ -25,7 +25,7 @@ along with this program. If not, see . static ThreadData* FindThreadConn(HANDLE hConn) { - ThreadData* res = NULL; + ThreadData *res = NULL; for (int i = 0; i < g_Instances.getCount() && res == NULL; ++i) res = g_Instances[i].MSN_GetThreadByConnection(hConn); @@ -38,7 +38,7 @@ static ThreadData* FindThreadConn(HANDLE hConn) int msn_httpGatewayInit(HANDLE hConn, NETLIBOPENCONNECTION* nloc, NETLIBHTTPREQUEST* nlhr) { - NETLIBHTTPPROXYINFO nlhpi = {0}; + NETLIBHTTPPROXYINFO nlhpi = { 0 }; nlhpi.cbSize = sizeof(nlhpi); nlhpi.szHttpGetUrl = NULL; nlhpi.szHttpPostUrl = "messenger.hotmail.com"; @@ -54,9 +54,8 @@ int msn_httpGatewayInit(HANDLE hConn, NETLIBOPENCONNECTION* nloc, NETLIBHTTPREQU int msn_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags, MIRANDASERVICE pfnNetlibSend) { - ThreadData* T = FindThreadConn(hConn); - if (T != NULL) - { + ThreadData *T = FindThreadConn(hConn); + if (T != NULL) { if (T->sessionClosed) return SOCKET_ERROR; @@ -76,18 +75,17 @@ PBYTE msn_httpGatewayUnwrapRecv(NETLIBHTTPREQUEST* nlhr, PBYTE buf, int len, int { *outBufLen = len; - ThreadData* T = FindThreadConn(nlhr->nlc); - if (T == NULL) return buf; + ThreadData *T = FindThreadConn(nlhr->nlc); + if (T == NULL) + return buf; bool isSessionClosed = true; bool isMsnPacket = false; - if (nlhr->resultCode == 200) - { + if (nlhr->resultCode == 200) { char *xMsgr = NULL, *xHost = NULL; - for (int i=0; i < nlhr->headersCount; i++) - { + for (int i = 0; i < nlhr->headersCount; i++) { NETLIBHTTPHEADER& tHeader = nlhr->headers[i]; if (_stricmp(tHeader.szName, "X-MSN-Messenger") == 0) xMsgr = tHeader.szValue; @@ -96,8 +94,7 @@ PBYTE msn_httpGatewayUnwrapRecv(NETLIBHTTPREQUEST* nlhr, PBYTE buf, int len, int } - if (xMsgr) - { + if (xMsgr) { isMsnPacket = true; if (strstr(xMsgr, "Session=close") == 0) @@ -109,20 +106,17 @@ PBYTE msn_httpGatewayUnwrapRecv(NETLIBHTTPREQUEST* nlhr, PBYTE buf, int len, int } T->sessionClosed |= isSessionClosed; - if (isSessionClosed && buf == NULL) - { + if (isSessionClosed && buf == NULL) { *outBufLen = 0; buf = (PBYTE)mir_alloc(1); *buf = 0; } - else if (buf == NULL && len == 0) - { + else if (buf == NULL && len == 0) { *outBufLen = 1; buf = (PBYTE)mir_alloc(1); *buf = 0; } - else if (!isMsnPacket) - { + else if (!isMsnPacket) { *outBufLen = 0; *buf = 0; } diff --git a/protocols/MSN/src/msn_libstr.cpp b/protocols/MSN/src/msn_libstr.cpp index 48296b36fb..127328230e 100644 --- a/protocols/MSN/src/msn_libstr.cpp +++ b/protocols/MSN/src/msn_libstr.cpp @@ -40,7 +40,7 @@ void overrideStr(TCHAR*& dest, const TCHAR* src, bool unicode, const TCHAR* def) else if (def != NULL) dest = mir_tstrdup(def); } - + char* arrayToHex(BYTE* data, size_t datasz) { char *res = (char*)mir_alloc(2 * datasz + 1); @@ -48,7 +48,7 @@ char* arrayToHex(BYTE* data, size_t datasz) return res; } -bool txtParseParam (const char* szData, const char* presearch, const char* start, const char* finish, char* param, const int size) +bool txtParseParam(const char* szData, const char* presearch, const char* start, const char* finish, char* param, const int size) { const char *cp, *cp1; int len; @@ -69,7 +69,7 @@ bool txtParseParam (const char* szData, const char* presearch, const char* start if (finish) { cp1 = strstr(cp, finish); if (cp1 == NULL) return FALSE; - while (*(cp1-1) == ' ' && cp1 > cp) --cp1; + while (*(cp1 - 1) == ' ' && cp1 > cp) --cp1; } else cp1 = strchr(cp, '\0'); @@ -108,9 +108,9 @@ void parseWLID(char* wlid, char** net, char** email, char** inst) static int SingleHexToDecimal(char c) { - if (c >= '0' && c <= '9') return c-'0'; - if (c >= 'a' && c <= 'f') return c-'a'+10; - if (c >= 'A' && c <= 'F') return c-'A'+10; + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; return -1; } @@ -121,7 +121,7 @@ template void UrlDecode(chartype* str) { chartype* s = str, *d = str; - while(*s) { + while (*s) { if (*s == '%') { int digit1 = SingleHexToDecimal(s[1]); if (digit1 != -1) { @@ -147,12 +147,12 @@ void HtmlDecode(char *str) char* p, *q; for (p = q = str; *p != '\0'; p++, q++) { if (*p == '&') { - if (!strncmp(p, "&", 5)) { *q = '&'; p += 4; } + if (!strncmp(p, "&", 5)) { *q = '&'; p += 4; } else if (!strncmp(p, "'", 6)) { *q = '\''; p += 5; } else if (!strncmp(p, ">", 4)) { *q = '>'; p += 3; } else if (!strncmp(p, "<", 4)) { *q = '<'; p += 3; } else if (!strncmp(p, """, 6)) { *q = '"'; p += 5; } - else { *q = *p; } + else { *q = *p; } } else *q = *p; } @@ -167,7 +167,7 @@ char* HtmlEncode(const char *str) if (str == NULL) return NULL; - for (c=0,p=(char*)str; *p!='\0'; p++) { + for (c = 0, p = (char*)str; *p != '\0'; p++) { switch (*p) { case '&': c += 5; break; case '\'': c += 6; break; @@ -178,8 +178,8 @@ char* HtmlEncode(const char *str) } } - if ((s=(char*)mir_alloc(c+1)) != NULL) { - for (p=(char*)str,q=s; *p!='\0'; p++) { + if ((s = (char*)mir_alloc(c + 1)) != NULL) { + for (p = (char*)str, q = s; *p != '\0'; p++) { switch (*p) { case '&': strcpy(q, "&"); q += 5; break; case '\'': strcpy(q, "'"); q += 6; break; @@ -206,8 +206,8 @@ void stripBBCode(char* src) while (*ps != 0) { if (!tag && *ps == '[') { char ch = ps[1]; - if (ch == '/') ch = ps[2]; - tag = ch == 'b' || ch == 'u' || ch == 'i' || ch == 'c' || ch == 'a' || ch == 's'; + if (ch == '/') ch = ps[2]; + tag = ch == 'b' || ch == 'u' || ch == 'i' || ch == 'c' || ch == 'a' || ch == 's'; } if (!tag) *(pd++) = *ps; else tag = *ps != ']'; @@ -252,9 +252,10 @@ void stripColorCode(char* src) } else if (ps[3] == '#') { ps += 4; - for (int i=0; i<6; ++i) + for (int i = 0; i < 6; ++i) { if (isxdigit(*ps)) ++ps; else break; + } continue; } break; diff --git a/protocols/MSN/src/msn_links.cpp b/protocols/MSN/src/msn_links.cpp index 4c3adb0a1b..8c735d050c 100644 --- a/protocols/MSN/src/msn_links.cpp +++ b/protocols/MSN/src/msn_links.cpp @@ -30,23 +30,19 @@ static HANDLE hServiceParseLink; static MCONTACT GetContact(TCHAR *arg, TCHAR **pemail, CMsnProto *proto) { TCHAR* email = NULL; - do - { + do { TCHAR *tok = _tcschr(arg, '&'); /* next token */ if (tok != NULL) *tok++ = '\0'; - if (_tcsnicmp(arg, _T("contact="), 8) == 0) - { + if (_tcsnicmp(arg, _T("contact="), 8) == 0) { arg += 8; UrlDecode(arg); email = arg; } arg = tok; - } - while(arg != NULL); + } while (arg != NULL); - if (email == NULL || email[0] == '\0') - { + if (email == NULL || email[0] == '\0') { if (pemail) *pemail = NULL; return NULL; } @@ -60,7 +56,7 @@ static MCONTACT GetContact(TCHAR *arg, TCHAR **pemail, CMsnProto *proto) send message: msnim:chat?contact=netpassport@emailaddress.com voice chat: msnim:voice?contact=netpassport@emailaddress.com video chat: msnim:video?contact=netpassport@emailaddress.com -*/ + */ static INT_PTR ServiceParseMsnimLink(WPARAM, LPARAM lParam) { @@ -79,10 +75,8 @@ static INT_PTR ServiceParseMsnimLink(WPARAM, LPARAM lParam) if (g_Instances.getCount() == 0) return 0; CMsnProto *proto = &g_Instances[0]; - for (int i = 0; i < g_Instances.getCount(); ++i) - { - if (g_Instances[i].m_iStatus > ID_STATUS_OFFLINE) - { + for (int i = 0; i < g_Instances.getCount(); ++i) { + if (g_Instances[i].m_iStatus > ID_STATUS_OFFLINE) { proto = &g_Instances[i]; break; } @@ -91,8 +85,7 @@ static INT_PTR ServiceParseMsnimLink(WPARAM, LPARAM lParam) /* add a contact to the list */ - if(_tcsnicmp(arg, _T("add?"), 4) == 0) - { + if (_tcsnicmp(arg, _T("add?"), 4) == 0) { arg += 4; TCHAR *email; @@ -100,14 +93,13 @@ static INT_PTR ServiceParseMsnimLink(WPARAM, LPARAM lParam) if (email == NULL) return 1; /* does not yet check if email is current user */ - if (hContact == NULL) - { + if (hContact == NULL) { PROTOSEARCHRESULT psr = { sizeof(psr) }; psr.flags = PSR_TCHAR; psr.nick = email; psr.email = email; - ADDCONTACTSTRUCT acs = {0}; + ADDCONTACTSTRUCT acs = { 0 }; acs.handleType = HANDLE_SEARCHRESULT; acs.szProto = proto->m_szModuleName; acs.psr = &psr; @@ -117,38 +109,32 @@ static INT_PTR ServiceParseMsnimLink(WPARAM, LPARAM lParam) } /* send a message to a contact */ /* "voice" and "video" not yet implemented, perform same action as "chat" */ - else if(_tcsnicmp(arg, _T("chat?"), 5) == 0) - { + else if (_tcsnicmp(arg, _T("chat?"), 5) == 0) { arg += 5; MCONTACT hContact = GetContact(arg, NULL, proto); - if (hContact != NULL) - { + if (hContact != NULL) { CallService(MS_MSG_SENDMESSAGE, hContact, 0); return 0; } } - else if(_tcsnicmp(arg, _T("voice?"), 6) == 0) - { + else if (_tcsnicmp(arg, _T("voice?"), 6) == 0) { arg += 6; MCONTACT hContact = GetContact(arg, NULL, proto); - if (hContact != NULL) - { + if (hContact != NULL) { CallService(MS_MSG_SENDMESSAGE, hContact, 0); return 0; } } - else if(_tcsnicmp(arg, _T("video?"), 6) == 0) - { + else if (_tcsnicmp(arg, _T("video?"), 6) == 0) { arg += 6; MCONTACT hContact = GetContact(arg, NULL, proto); - if (hContact != NULL) - { + if (hContact != NULL) { CallService(MS_MSG_SENDMESSAGE, hContact, 0); return 0; } diff --git a/protocols/MSN/src/msn_lists.cpp b/protocols/MSN/src/msn_lists.cpp index 57a227a22f..bd9fa308e8 100644 --- a/protocols/MSN/src/msn_lists.cpp +++ b/protocols/MSN/src/msn_lists.cpp @@ -39,11 +39,12 @@ bool CMsnProto::Lists_IsInList(int list, const char* email) { mir_cslock lck(csLists); - MsnContact* p = contList.find((MsnContact*)&email); - bool res = p != NULL; - if (res && list != -1) - res &= ((p->list & list) == list); - return res; + MsnContact *p = contList.find((MsnContact*)&email); + if (p == NULL) + return false; + if (list == -1) + return true; + return (p->list & list) == list; } MsnContact* CMsnProto::Lists_Get(const char* email) @@ -73,43 +74,40 @@ MsnPlace* CMsnProto::Lists_GetPlace(const char* wlid) if (szInst == NULL) szInst = (char*)sttVoidUid; - MsnPlace* pl = NULL; MsnContact* p = contList.find((MsnContact*)&szEmail); - if (p) - pl = p->places.find((MsnPlace*)&szInst); + if (p == NULL) + return NULL; - return pl; + return p->places.find((MsnPlace*)&szInst); } MsnPlace* CMsnProto::Lists_AddPlace(const char* email, const char* id, unsigned cap1, unsigned cap2) { mir_cslock lck(csLists); - MsnPlace* pl = NULL; - MsnContact* p = contList.find((MsnContact*)&email); - if (p) { - pl = p->places.find((MsnPlace*)&id); - if (!pl) { - pl = new MsnPlace; - - pl->id = mir_strdup(id); - pl->cap1 = cap1; - pl->cap2 = cap2; - pl->p2pMsgId = 0; - pl->p2pPktNum = 0; - p->places.insert(pl); - } + MsnContact *p = contList.find((MsnContact*)&email); + if (p == NULL) + return NULL; + + MsnPlace *pl = p->places.find((MsnPlace*)&id); + if (pl == NULL) { + pl = new MsnPlace; + pl->id = mir_strdup(id); + pl->cap1 = cap1; + pl->cap2 = cap2; + pl->p2pMsgId = 0; + pl->p2pPktNum = 0; + p->places.insert(pl); } return pl; } -MsnContact* CMsnProto::Lists_GetNext(int& i) +MsnContact* CMsnProto::Lists_GetNext(int &i) { - MsnContact* p = NULL; - mir_cslock lck(csLists); + MsnContact *p = NULL; while (p == NULL && ++i < contList.getCount()) if (contList[i].hContact) p = &contList[i]; @@ -121,7 +119,7 @@ int CMsnProto::Lists_GetMask(const char* email) { mir_cslock lck(csLists); - MsnContact* p = contList.find((MsnContact*)&email); + MsnContact *p = contList.find((MsnContact*)&email); return p ? p->list : 0; } @@ -131,14 +129,14 @@ int CMsnProto::Lists_GetNetId(const char* email) mir_cslock lck(csLists); - MsnContact* p = contList.find((MsnContact*)&email); + MsnContact *p = contList.find((MsnContact*)&email); return p ? p->netId : NETID_UNKNOWN; } unsigned CMsnProto::p2p_getMsgId(const char* wlid, int inc) { mir_cslock lck(csLists); - MsnPlace* p = Lists_GetPlace(wlid); + MsnPlace *p = Lists_GetPlace(wlid); unsigned res = p && p->p2pMsgId ? p->p2pMsgId : MSN_GenRandom(); if (p) @@ -151,7 +149,7 @@ unsigned CMsnProto::p2p_getPktNum(const char* wlid) { mir_cslock lck(csLists); - MsnPlace* p = Lists_GetPlace(wlid); + MsnPlace *p = Lists_GetPlace(wlid); return p ? p->p2pPktNum++ : 0; } @@ -489,6 +487,7 @@ static void SaveSettings(MCONTACT hItem, HWND hwndList, CMsnProto* proto) INT_PTR CALLBACK DlgProcMsnServLists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CMsnProto *proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + NMCLISTCONTROL *nmc; switch (msg) { case WM_INITDIALOG: @@ -531,37 +530,25 @@ INT_PTR CALLBACK DlgProcMsnServLists(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR } return TRUE; -// case WM_SETFOCUS: -// SetFocus(GetDlgItem(hwndDlg ,IDC_LIST)); -// break; - case WM_COMMAND: - if (LOWORD(wParam) == IDC_LISTREFRESH) - { + if (LOWORD(wParam) == IDC_LISTREFRESH) { HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST); SendMessage(hwndList, CLM_AUTOREBUILD, 0, 0); - CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); EnableWindow(hwndList, proto->msnLoggedIn); } break; case WM_NOTIFY: - { - CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - NMCLISTCONTROL* nmc = (NMCLISTCONTROL*)lParam; - if (nmc->hdr.idFrom == 0 && nmc->hdr.code == (unsigned)PSN_APPLY) - { + nmc = (NMCLISTCONTROL*)lParam; + if (nmc->hdr.idFrom == 0 && nmc->hdr.code == (unsigned)PSN_APPLY) { HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST); SaveSettings(NULL, hwndList, proto); SendMessage(hwndList, CLM_AUTOREBUILD, 0, 0); EnableWindow(hwndList, proto->msnLoggedIn); } - else if (nmc->hdr.idFrom == IDC_LIST) - { - switch (nmc->hdr.code) - { + else if (nmc->hdr.idFrom == IDC_LIST) { + switch (nmc->hdr.code) { case CLN_NEWCONTACT: if ((nmc->flags & (CLNF_ISGROUP | CLNF_ISINFO)) == 0) SetContactIcons((MCONTACT)nmc->hItem, nmc->hdr.hwndFrom, proto); @@ -573,18 +560,13 @@ INT_PTR CALLBACK DlgProcMsnServLists(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR break; case NM_CLICK: - HANDLE hItem; - DWORD hitFlags; - int iImage; - // Make sure we have an extra column, also we can't change RL list if (nmc->iColumn == -1 || nmc->iColumn == 4) break; // Find clicked item - hItem = (HANDLE)SendMessage(nmc->hdr.hwndFrom, CLM_HITTEST, (WPARAM)&hitFlags, MAKELPARAM(nmc->pt.x,nmc->pt.y)); - - // Nothing was clicked + DWORD hitFlags; + HANDLE hItem = (HANDLE)SendMessage(nmc->hdr.hwndFrom, CLM_HITTEST, (WPARAM)&hitFlags, MAKELPARAM(nmc->pt.x, nmc->pt.y)); if (hItem == NULL || !(IsHContactContact(hItem) || IsHContactInfo(hItem))) break; @@ -593,7 +575,7 @@ INT_PTR CALLBACK DlgProcMsnServLists(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR break; // Get image in clicked column (0=none, 1=LL, 2=FL, 3=AL, 4=BL, 5=RL) - iImage = SendMessage(nmc->hdr.hwndFrom, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(nmc->iColumn, 0)); + int iImage = SendMessage(nmc->hdr.hwndFrom, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(nmc->iColumn, 0)); iImage = iImage ? 0 : nmc->iColumn + 1; SendMessage(nmc->hdr.hwndFrom, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(nmc->iColumn, iImage)); @@ -606,11 +588,10 @@ INT_PTR CALLBACK DlgProcMsnServLists(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR break; } } - } - break; + break; case WM_DESTROY: - HIMAGELIST hIml=(HIMAGELIST)SendDlgItemMessage(hwndDlg,IDC_LIST,CLM_GETEXTRAIMAGELIST,0,0); + HIMAGELIST hIml = (HIMAGELIST)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETEXTRAIMAGELIST, 0, 0); ImageList_Destroy(hIml); ReleaseIconEx("list_fl"); ReleaseIconEx("list_al"); diff --git a/protocols/MSN/src/msn_mail.cpp b/protocols/MSN/src/msn_mail.cpp index 407375bf17..80f45f1211 100644 --- a/protocols/MSN/src/msn_mail.cpp +++ b/protocols/MSN/src/msn_mail.cpp @@ -28,8 +28,8 @@ static const char mailReqHdr[] = ezxml_t CMsnProto::oimRecvHdr(const char* service, ezxml_t& tbdy, char*& httphdr) { ezxml_t xmlp = ezxml_new("soap:Envelope"); - ezxml_set_attr(xmlp, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - ezxml_set_attr(xmlp, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); + ezxml_set_attr(xmlp, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + ezxml_set_attr(xmlp, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); ezxml_set_attr(xmlp, "xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/"); ezxml_t hdr = ezxml_add_child(xmlp, "soap:Header", 0); @@ -72,9 +72,8 @@ void CMsnProto::getOIMs(ezxml_t xmli) ezxml_t xmldel = oimRecvHdr("DeleteMessages", delmsg, delReqHdr); ezxml_t delmids = ezxml_add_child(delmsg, "messageIds", 0); - while (toki != NULL) - { - const char* szId = ezxml_txt(ezxml_child(toki, "I")); + while (toki != NULL) { + const char* szId = ezxml_txt(ezxml_child(toki, "I")); const char* szEmail = ezxml_txt(ezxml_child(toki, "E")); ezxml_set_txt(reqmid, szId); @@ -88,8 +87,7 @@ void CMsnProto::getOIMs(ezxml_t xmli) free(szData); mir_free(url); - if (tResult != NULL && status == 200) - { + if (tResult != NULL && status == 200) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); ezxml_t body = getSoapResponse(xmlm, "GetMessage"); @@ -98,15 +96,13 @@ void CMsnProto::getOIMs(ezxml_t xmli) time_t evtm = time(NULL); const char* arrTime = mailInfo["X-OriginalArrivalTime"]; - if (arrTime != NULL) - { + if (arrTime != NULL) { char szTime[32], *p; txtParseParam(arrTime, "FILETIME", "[", "]", szTime, sizeof(szTime)); unsigned filetimeLo = strtoul(szTime, &p, 16); - if (*p == ':') - { - unsigned __int64 filetime = strtoul(p+1, &p, 16); + if (*p == ':') { + unsigned __int64 filetime = strtoul(p + 1, &p, 16); filetime <<= 32; filetime |= filetimeLo; filetime /= 10000000; @@ -119,11 +115,11 @@ void CMsnProto::getOIMs(ezxml_t xmli) } } - PROTORECVEVENT pre = {0}; + PROTORECVEVENT pre = { 0 }; pre.szMessage = mailInfo.decodeMailBody((char*)mailbody); pre.flags = PREF_UTF /*+ ((isRtl) ? PREF_RTL : 0)*/; pre.timestamp = evtm; - ProtoChainRecvMsg( MSN_HContactFromEmail(szEmail), &pre); + ProtoChainRecvMsg(MSN_HContactFromEmail(szEmail), &pre); mir_free(pre.szMessage); ezxml_t delmid = ezxml_add_child(delmids, "messageId", 0); @@ -137,8 +133,7 @@ void CMsnProto::getOIMs(ezxml_t xmli) ezxml_free(xmlreq); mir_free(getReqHdr); - if (ezxml_child(delmids, "messageId") != NULL) - { + if (ezxml_child(delmids, "messageId") != NULL) { char* szData = ezxml_toxml(xmldel, true); unsigned status; @@ -173,8 +168,7 @@ void CMsnProto::getMetaData(void) free(szData); mir_free(getReqHdr); - if (tResult != NULL && status == 200) - { + if (tResult != NULL && status == 200) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); ezxml_t xmli = ezxml_get(xmlm, "s:Body", 0, "GetMetadataResponse", 0, "MD", -1); if (!xmli) @@ -189,12 +183,10 @@ void CMsnProto::getMetaData(void) void CMsnProto::processMailData(char* mailData) { - if (strcmp(mailData, "too-large") == 0) - { + if (strcmp(mailData, "too-large") == 0) { getMetaData(); } - else - { + else { ezxml_t xmli = ezxml_parse_str(mailData, strlen(mailData)); ezxml_t toke = ezxml_child(xmli, "E"); @@ -239,8 +231,7 @@ void CMsnProto::sttNotificationMessage(char* msgBody, bool isInitial) if (FoldersUnread != NULL) mUnreadJunkEmails = atol(FoldersUnread); - if (MsgDelta != NULL) - { + if (MsgDelta != NULL) { int iDelta = atol(MsgDelta); if (SrcFolder && strcmp(SrcFolder, "ACTIVE") == 0) mUnreadMessages -= iDelta; @@ -255,10 +246,8 @@ void CMsnProto::sttNotificationMessage(char* msgBody, bool isInitial) if (mUnreadMessages < 0) mUnreadMessages = 0; } - if (From != NULL && Subject != NULL && Fromaddr != NULL) - { - if (DestFolder != NULL && SrcFolder == NULL) - { + if (From != NULL && Subject != NULL && Fromaddr != NULL) { + if (DestFolder != NULL && SrcFolder == NULL) { mUnreadMessages += strcmp(DestFolder, "ACTIVE") == 0; mUnreadJunkEmails += strcmp(DestFolder, "HM_BuLkMail_") == 0; } @@ -279,8 +268,7 @@ void CMsnProto::sttNotificationMessage(char* msgBody, bool isInitial) mir_free(mimeSubjectW); ShowPopup = true; } - else - { + else { const char* MailData = tFileInfo["Mail-Data"]; if (MailData != NULL) processMailData((char*)MailData); @@ -294,18 +282,16 @@ void CMsnProto::sttNotificationMessage(char* msgBody, bool isInitial) ShowPopup &= mUnreadMessages != 0 || (mUnreadJunkEmails != 0 && !getByte("DisableHotmailJunk", 0)); MCONTACT hContact = MSN_HContactFromEmail(MyOptions.szEmail); - if (hContact) - { - CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM) 1); + if (hContact) { + CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM)1); displayEmailCount(hContact); - if (ShowPopup && !getByte("DisableHotmailTray", 1)) - { - CLISTEVENT cle = {0}; + if (ShowPopup && !getByte("DisableHotmailTray", 1)) { + CLISTEVENT cle = { 0 }; cle.cbSize = sizeof(cle); cle.hContact = hContact; - cle.hDbEvent = (HANDLE) 1; + cle.hDbEvent = (HANDLE)1; cle.flags = CLEF_URGENT | CLEF_TCHAR; cle.hIcon = LoadSkinnedIcon(SKINICON_OTHER_SENDEMAIL); cle.ptszTooltip = tBuffer2; @@ -320,13 +306,11 @@ void CMsnProto::sttNotificationMessage(char* msgBody, bool isInitial) ProtoBroadcastAck(NULL, ACKTYPE_EMAIL, ACKRESULT_STATUS, NULL, 0); // Disable to notify receiving hotmail - if (ShowPopup && !getByte("DisableHotmail", 0)) - { + if (ShowPopup && !getByte("DisableHotmail", 0)) { SkinPlaySound(mailsoundname); const char *msgurl = tFileInfo["Message-URL"]; - if (msgurl) - { + if (msgurl) { const char *p = strchr(msgurl, '&'); if (p) *(char*)p = 0; p = strstr(msgurl, "getmsg"); if (p) msgurl = p; } @@ -345,26 +329,21 @@ void CMsnProto::sttNotificationMessage(char* msgBody, bool isInitial) return; char mailerpath[MAX_PATH]; - if (!db_get_static(NULL, m_szModuleName, "MailerPath", mailerpath, sizeof(mailerpath))) - { - if (mailerpath[0]) - { + if (!db_get_static(NULL, m_szModuleName, "MailerPath", mailerpath, sizeof(mailerpath))) { + if (mailerpath[0]) { char* tParams = NULL; char* tCmd = mailerpath; - if (*tCmd == '\"') - { + if (*tCmd == '\"') { ++tCmd; char* tEndPtr = strchr(tCmd, '\"'); - if (tEndPtr != NULL) - { + if (tEndPtr != NULL) { *tEndPtr = 0; - tParams = tEndPtr+1; + tParams = tEndPtr + 1; } } - if (tParams == NULL) - { + if (tParams == NULL) { tParams = strchr(tCmd, ' '); tParams = tParams ? tParams + 1 : strchr(tCmd, '\0'); } @@ -383,8 +362,7 @@ static void TruncUtf8(char *str, size_t sz) if (sz > len) sz = len; size_t cntl = 0, cnt = 0; - for (;;) - { + for (;;) { unsigned char p = (unsigned char)str[cnt]; if (p >= 0xE0) cnt += 3; @@ -405,12 +383,10 @@ void CMsnProto::displayEmailCount(MCONTACT hContact) TCHAR* name = GetContactNameT(hContact); if (name == NULL) return; - TCHAR* ch = name-1; - do - { - ch = _tcschr(ch+1, '['); - } - while (ch && !_istdigit(ch[1])); + TCHAR* ch = name - 1; + do { + ch = _tcschr(ch + 1, '['); + } while (ch && !_istdigit(ch[1])); if (ch) *ch = 0; rtrimt(name); diff --git a/protocols/MSN/src/msn_menu.cpp b/protocols/MSN/src/msn_menu.cpp index 84ef664f0f..f4193b4d92 100644 --- a/protocols/MSN/src/msn_menu.cpp +++ b/protocols/MSN/src/msn_menu.cpp @@ -50,7 +50,7 @@ INT_PTR CMsnProto::MsnBlockCommand(WPARAM hContact, LPARAM) INT_PTR CMsnProto::MsnGotoInbox(WPARAM, LPARAM) { MCONTACT hContact = MSN_HContactFromEmail(MyOptions.szEmail); - if (hContact) CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM) 1); + if (hContact) CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM)1); MsnInvokeMyURL(true, "http://mail.live.com?rru=inbox"); return 0; @@ -121,7 +121,7 @@ INT_PTR CMsnProto::MsnInviteCommand(WPARAM, LPARAM) int CMsnProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM) { - if ( !MSN_IsMyContact(hContact)) + if (!MSN_IsMyContact(hContact)) return 0; char szEmail[MSN_MAX_EMAIL_LEN]; @@ -196,61 +196,58 @@ INT_PTR CMsnProto::MsnSendNetMeeting(WPARAM wParam, LPARAM) static INT_PTR CALLBACK DlgProcSetNickname(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch (msg) + switch (msg) { + case WM_INITDIALOG: { - case WM_INITDIALOG: - { - TranslateDialogDefault(hwndDlg); + TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - CMsnProto* proto = (CMsnProto*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + CMsnProto* proto = (CMsnProto*)lParam; - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx("main", true)); - SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconEx("main")); - SendMessage(GetDlgItem(hwndDlg, IDC_NICKNAME), EM_LIMITTEXT, 129, 0); + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx("main", true)); + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconEx("main")); + SendMessage(GetDlgItem(hwndDlg, IDC_NICKNAME), EM_LIMITTEXT, 129, 0); - DBVARIANT dbv; - if (!proto->getTString("Nick", &dbv)) { - SetDlgItemText(hwndDlg, IDC_NICKNAME, dbv.ptszVal); - db_free(&dbv); - } - return TRUE; + DBVARIANT dbv; + if (!proto->getTString("Nick", &dbv)) { + SetDlgItemText(hwndDlg, IDC_NICKNAME, dbv.ptszVal); + db_free(&dbv); } - case WM_COMMAND: - switch(wParam) - { - case IDOK: - { - CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (proto->msnLoggedIn) - { - TCHAR str[130]; - GetDlgItemText(hwndDlg, IDC_NICKNAME, str, SIZEOF(str)); - proto->MSN_SendNickname(str); - } - } - - case IDCANCEL: - DestroyWindow(hwndDlg); - break; + return TRUE; + } + case WM_COMMAND: + switch (wParam) { + case IDOK: + { + CMsnProto *proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + if (proto->msnLoggedIn) { + TCHAR str[130]; + GetDlgItemText(hwndDlg, IDC_NICKNAME, str, SIZEOF(str)); + proto->MSN_SendNickname(str); } - break; + } - case WM_CLOSE: + case IDCANCEL: DestroyWindow(hwndDlg); break; + } + break; - case WM_DESTROY: - ReleaseIconEx("main"); - ReleaseIconEx("main", true); - break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + + case WM_DESTROY: + ReleaseIconEx("main"); + ReleaseIconEx("main", true); + break; } return FALSE; } INT_PTR CMsnProto::SetNicknameUI(WPARAM, LPARAM) { - HWND hwndSetNickname = CreateDialogParam (hInst, MAKEINTRESOURCE(IDD_SETNICKNAME), + HWND hwndSetNickname = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SETNICKNAME), NULL, DlgProcSetNickname, (LPARAM)this); SetForegroundWindow(hwndSetNickname); @@ -339,7 +336,7 @@ void CMsnProto::MSN_EnableMenuItems(bool bEnable) if (!bEnable) mi.flags |= CMIF_GRAYED; - for (int i=0; i < SIZEOF(menuItemsMain); i++) + for (int i = 0; i < SIZEOF(menuItemsMain); i++) if (menuItemsMain[i] != NULL) Menu_ModifyItem(menuItemsMain[i], &mi); diff --git a/protocols/MSN/src/msn_mime.cpp b/protocols/MSN/src/msn_mime.cpp index 6f9d15d587..9a60356ab1 100644 --- a/protocols/MSN/src/msn_mime.cpp +++ b/protocols/MSN/src/msn_mime.cpp @@ -47,8 +47,7 @@ MimeHeaders::~MimeHeaders() void MimeHeaders::clear(void) { - for (unsigned i=0; i < mCount; i++) - { + for (unsigned i = 0; i < mCount; i++) { MimeHeader& H = mVals[i]; if (H.flags & 1) mir_free((void*)H.name); if (H.flags & 2) mir_free((void*)H.value); @@ -58,8 +57,7 @@ void MimeHeaders::clear(void) unsigned MimeHeaders::allocSlot(void) { - if (++mCount >= mAllocCount) - { + if (++mCount >= mAllocCount) { mAllocCount += 10; mVals = (MimeHeader*)mir_realloc(mVals, sizeof(MimeHeader) * mAllocCount); } @@ -115,19 +113,16 @@ char* MimeHeaders::flipStr(const char* src, size_t len, char* dest) { if (len == -1) len = strlen(src); - if (src == dest) - { + if (src == dest) { const unsigned b = (unsigned)len-- / 2; - for (unsigned i = 0; i < b; i++) - { + for (unsigned i = 0; i < b; i++) { const char c = dest[i]; dest[i] = dest[len - i]; dest[len - i] = c; } ++len; } - else - { + else { for (unsigned i = 0; i < len; i++) dest[i] = src[len - 1 - i]; dest[len] = 0; @@ -142,8 +137,7 @@ char* MimeHeaders::flipStr(const char* src, size_t len, char* dest) size_t MimeHeaders::getLength(void) { size_t iResult = 0; - for (unsigned i=0; i < mCount; i++) - { + for (unsigned i = 0; i < mCount; i++) { MimeHeader& H = mVals[i]; iResult += strlen(H.name) + strlen(H.value) + 4; } @@ -153,11 +147,9 @@ size_t MimeHeaders::getLength(void) char* MimeHeaders::writeToBuffer(char* dest) { - for (unsigned i=0; i < mCount; i++) - { + for (unsigned i = 0; i < mCount; i++) { MimeHeader& H = mVals[i]; - if (H.flags & 4) - { + if (H.flags & 4) { dest = flipStr(H.name, -1, dest); *(dest++) = ':'; @@ -173,8 +165,7 @@ char* MimeHeaders::writeToBuffer(char* dest) dest += sprintf(dest, "%s: %s\r\n", H.name, H.value); //!!!!!!!!!!!! } - if (mCount) - { + if (mCount) { *(dest++) = '\r'; *(dest++) = '\n'; *dest = 0; @@ -190,22 +181,20 @@ char* MimeHeaders::readFromBuffer(char* src) { clear(); - while (*src) - { + while (*src) { char* peol = strchr(src, '\n'); if (peol == NULL) return strchr(src, 0); else if (peol == src) return src + 1; - else if (peol == (src + 1) && *src == '\r') + else if (peol == (src + 1) && *src == '\r') return src + 2; *peol = 0; char* delim = strchr(src, ':'); - if (delim) - { + if (delim) { *delim = 0; MimeHeader& H = mVals[allocSlot()]; @@ -224,8 +213,7 @@ char* MimeHeaders::readFromBuffer(char* src) const char* MimeHeaders::find(const char* szFieldName) { size_t i; - for (i = 0; i < mCount; i++) - { + for (i = 0; i < mCount; i++) { MimeHeader& MH = mVals[i]; if (_stricmp(MH.name, szFieldName) == 0) return MH.value; @@ -235,11 +223,9 @@ const char* MimeHeaders::find(const char* szFieldName) char* szFieldNameR = (char*)alloca(len + 1); flipStr(szFieldName, len, szFieldNameR); - for (i = 0; i < mCount; i++) - { + for (i = 0; i < mCount; i++) { MimeHeader& MH = mVals[i]; - if (_stricmp(MH.name, szFieldNameR) == 0 && (MH.flags & 3) == 0) - { + if (_stricmp(MH.name, szFieldNameR) == 0 && (MH.flags & 3) == 0) { strcpy((char*)MH.name, szFieldNameR); flipStr(MH.value, -1, (char*)MH.value); return MH.value; @@ -255,54 +241,54 @@ static const struct _tag_cpltbl const char* mimecp; } cptbl[] = { - { 37, "IBM037" }, // IBM EBCDIC US-Canada - { 437, "IBM437" }, // OEM United States - { 500, "IBM500" }, // IBM EBCDIC International - { 708, "ASMO-708" }, // Arabic (ASMO 708) - { 720, "DOS-720" }, // Arabic (Transparent ASMO); Arabic (DOS) - { 737, "ibm737" }, // OEM Greek (formerly 437G); Greek (DOS) - { 775, "ibm775" }, // OEM Baltic; Baltic (DOS) - { 850, "ibm850" }, // OEM Multilingual Latin 1; Western European (DOS) - { 852, "ibm852" }, // OEM Latin 2; Central European (DOS) - { 855, "IBM855" }, // OEM Cyrillic (primarily Russian) - { 857, "ibm857" }, // OEM Turkish; Turkish (DOS) - { 858, "IBM00858" }, // OEM Multilingual Latin 1 + Euro symbol - { 860, "IBM860" }, // OEM Portuguese; Portuguese (DOS) - { 861, "ibm861" }, // OEM Icelandic; Icelandic (DOS) - { 862, "DOS-862" }, // OEM Hebrew; Hebrew (DOS) - { 863, "IBM863" }, // OEM French Canadian; French Canadian (DOS) - { 864, "IBM864" }, // OEM Arabic; Arabic (864) - { 865, "IBM865" }, // OEM Nordic; Nordic (DOS) - { 866, "cp866" }, // OEM Russian; Cyrillic (DOS) - { 869, "ibm869" }, // OEM Modern Greek; Greek, Modern (DOS) - { 870, "IBM870" }, // IBM EBCDIC Multilingual/ROECE (Latin 2); IBM EBCDIC Multilingual Latin 2 - { 874, "windows-874" }, // ANSI/OEM Thai (same as 28605, ISO 8859-15); Thai (Windows) - { 875, "cp875" }, // IBM EBCDIC Greek Modern - { 932, "shift_jis" }, // ANSI/OEM Japanese; Japanese (Shift-JIS) - { 936, "gb2312" }, // ANSI/OEM Simplified Chinese (PRC, Singapore); Chinese Simplified (GB2312) - { 949, "ks_c_5601-1987" }, // ANSI/OEM Korean (Unified Hangul Code) - { 950, "big5" }, // ANSI/OEM Traditional Chinese (Taiwan; Hong Kong SAR, PRC); Chinese Traditional (Big5) - { 1026, "IBM1026" }, // IBM EBCDIC Turkish (Latin 5) - { 1047, "IBM01047" }, // IBM EBCDIC Latin 1/Open System - { 1140, "IBM01140" }, // IBM EBCDIC US-Canada (037 + Euro symbol); IBM EBCDIC (US-Canada-Euro) - { 1141, "IBM01141" }, // IBM EBCDIC Germany (20273 + Euro symbol); IBM EBCDIC (Germany-Euro) - { 1142, "IBM01142" }, // IBM EBCDIC Denmark-Norway (20277 + Euro symbol); IBM EBCDIC (Denmark-Norway-Euro) - { 1143, "IBM01143" }, // IBM EBCDIC Finland-Sweden (20278 + Euro symbol); IBM EBCDIC (Finland-Sweden-Euro) - { 1144, "IBM01144" }, // IBM EBCDIC Italy (20280 + Euro symbol); IBM EBCDIC (Italy-Euro) - { 1145, "IBM01145" }, // IBM EBCDIC Latin America-Spain (20284 + Euro symbol); IBM EBCDIC (Spain-Euro) - { 1146, "IBM01146" }, // IBM EBCDIC United Kingdom (20285 + Euro symbol); IBM EBCDIC (UK-Euro) - { 1147, "IBM01147" }, // IBM EBCDIC France (20297 + Euro symbol); IBM EBCDIC (France-Euro) - { 1148, "IBM01148" }, // IBM EBCDIC International (500 + Euro symbol); IBM EBCDIC (International-Euro) - { 1149, "IBM01149" }, // IBM EBCDIC Icelandic (20871 + Euro symbol); IBM EBCDIC (Icelandic-Euro) - { 1250, "windows-1250" }, // ANSI Central European; Central European (Windows) - { 1251, "windows-1251" }, // ANSI Cyrillic; Cyrillic (Windows) - { 1252, "windows-1252" }, // ANSI Latin 1; Western European (Windows) - { 1253, "windows-1253" }, // ANSI Greek; Greek (Windows) - { 1254, "windows-1254" }, // ANSI Turkish; Turkish (Windows) - { 1255, "windows-1255" }, // ANSI Hebrew; Hebrew (Windows) - { 1256, "windows-1256" }, // ANSI Arabic; Arabic (Windows) - { 1257, "windows-1257" }, // ANSI Baltic; Baltic (Windows) - { 1258, "windows-1258" }, // ANSI/OEM Vietnamese; Vietnamese (Windows) + { 37, "IBM037" }, // IBM EBCDIC US-Canada + { 437, "IBM437" }, // OEM United States + { 500, "IBM500" }, // IBM EBCDIC International + { 708, "ASMO-708" }, // Arabic (ASMO 708) + { 720, "DOS-720" }, // Arabic (Transparent ASMO); Arabic (DOS) + { 737, "ibm737" }, // OEM Greek (formerly 437G); Greek (DOS) + { 775, "ibm775" }, // OEM Baltic; Baltic (DOS) + { 850, "ibm850" }, // OEM Multilingual Latin 1; Western European (DOS) + { 852, "ibm852" }, // OEM Latin 2; Central European (DOS) + { 855, "IBM855" }, // OEM Cyrillic (primarily Russian) + { 857, "ibm857" }, // OEM Turkish; Turkish (DOS) + { 858, "IBM00858" }, // OEM Multilingual Latin 1 + Euro symbol + { 860, "IBM860" }, // OEM Portuguese; Portuguese (DOS) + { 861, "ibm861" }, // OEM Icelandic; Icelandic (DOS) + { 862, "DOS-862" }, // OEM Hebrew; Hebrew (DOS) + { 863, "IBM863" }, // OEM French Canadian; French Canadian (DOS) + { 864, "IBM864" }, // OEM Arabic; Arabic (864) + { 865, "IBM865" }, // OEM Nordic; Nordic (DOS) + { 866, "cp866" }, // OEM Russian; Cyrillic (DOS) + { 869, "ibm869" }, // OEM Modern Greek; Greek, Modern (DOS) + { 870, "IBM870" }, // IBM EBCDIC Multilingual/ROECE (Latin 2); IBM EBCDIC Multilingual Latin 2 + { 874, "windows-874" }, // ANSI/OEM Thai (same as 28605, ISO 8859-15); Thai (Windows) + { 875, "cp875" }, // IBM EBCDIC Greek Modern + { 932, "shift_jis" }, // ANSI/OEM Japanese; Japanese (Shift-JIS) + { 936, "gb2312" }, // ANSI/OEM Simplified Chinese (PRC, Singapore); Chinese Simplified (GB2312) + { 949, "ks_c_5601-1987" }, // ANSI/OEM Korean (Unified Hangul Code) + { 950, "big5" }, // ANSI/OEM Traditional Chinese (Taiwan; Hong Kong SAR, PRC); Chinese Traditional (Big5) + { 1026, "IBM1026" }, // IBM EBCDIC Turkish (Latin 5) + { 1047, "IBM01047" }, // IBM EBCDIC Latin 1/Open System + { 1140, "IBM01140" }, // IBM EBCDIC US-Canada (037 + Euro symbol); IBM EBCDIC (US-Canada-Euro) + { 1141, "IBM01141" }, // IBM EBCDIC Germany (20273 + Euro symbol); IBM EBCDIC (Germany-Euro) + { 1142, "IBM01142" }, // IBM EBCDIC Denmark-Norway (20277 + Euro symbol); IBM EBCDIC (Denmark-Norway-Euro) + { 1143, "IBM01143" }, // IBM EBCDIC Finland-Sweden (20278 + Euro symbol); IBM EBCDIC (Finland-Sweden-Euro) + { 1144, "IBM01144" }, // IBM EBCDIC Italy (20280 + Euro symbol); IBM EBCDIC (Italy-Euro) + { 1145, "IBM01145" }, // IBM EBCDIC Latin America-Spain (20284 + Euro symbol); IBM EBCDIC (Spain-Euro) + { 1146, "IBM01146" }, // IBM EBCDIC United Kingdom (20285 + Euro symbol); IBM EBCDIC (UK-Euro) + { 1147, "IBM01147" }, // IBM EBCDIC France (20297 + Euro symbol); IBM EBCDIC (France-Euro) + { 1148, "IBM01148" }, // IBM EBCDIC International (500 + Euro symbol); IBM EBCDIC (International-Euro) + { 1149, "IBM01149" }, // IBM EBCDIC Icelandic (20871 + Euro symbol); IBM EBCDIC (Icelandic-Euro) + { 1250, "windows-1250" }, // ANSI Central European; Central European (Windows) + { 1251, "windows-1251" }, // ANSI Cyrillic; Cyrillic (Windows) + { 1252, "windows-1252" }, // ANSI Latin 1; Western European (Windows) + { 1253, "windows-1253" }, // ANSI Greek; Greek (Windows) + { 1254, "windows-1254" }, // ANSI Turkish; Turkish (Windows) + { 1255, "windows-1255" }, // ANSI Hebrew; Hebrew (Windows) + { 1256, "windows-1256" }, // ANSI Arabic; Arabic (Windows) + { 1257, "windows-1257" }, // ANSI Baltic; Baltic (Windows) + { 1258, "windows-1258" }, // ANSI/OEM Vietnamese; Vietnamese (Windows) { 20127, "us-ascii" }, // US-ASCII (7-bit) { 20273, "IBM273" }, // IBM EBCDIC Germany { 20277, "IBM277" }, // IBM EBCDIC Denmark-Norway @@ -353,10 +339,8 @@ static const struct _tag_cpltbl static unsigned FindCP(const char* mimecp) { unsigned cp = CP_ACP; - for (unsigned i = 0; i < SIZEOF(cptbl); ++i) - { - if (_stricmp(mimecp, cptbl[i].mimecp) == 0) - { + for (unsigned i = 0; i < SIZEOF(cptbl); ++i) { + if (_stricmp(mimecp, cptbl[i].mimecp) == 0) { cp = cptbl[i].cp; break; } @@ -367,9 +351,9 @@ static unsigned FindCP(const char* mimecp) static int SingleHexToDecimal(char c) { - if (c >= '0' && c <= '9') return c-'0'; - if (c >= 'a' && c <= 'f') return c-'a'+10; - if (c >= 'A' && c <= 'F') return c-'A'+10; + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; return -1; } @@ -377,32 +361,28 @@ static void PQDecode(char* str) { char* s = str, *d = str; - while(*s) - { - switch (*s) + while (*s) { + switch (*s) { + case '=': { - case '=': - { - int digit1 = SingleHexToDecimal(s[1]); - if (digit1 != -1) - { - int digit2 = SingleHexToDecimal(s[2]); - if (digit2 != -1) - { - s += 3; - *d++ = (char)((digit1 << 4) | digit2); - } + int digit1 = SingleHexToDecimal(s[1]); + if (digit1 != -1) { + int digit2 = SingleHexToDecimal(s[2]); + if (digit2 != -1) { + s += 3; + *d++ = (char)((digit1 << 4) | digit2); } - break; } + break; + } - case '_': - *d++ = ' '; ++s; - break; + case '_': + *d++ = ' '; ++s; + break; - default: - *d++ = *s++; - break; + default: + *d++ = *s++; + break; } } *d = 0; @@ -428,8 +408,7 @@ wchar_t* MimeHeaders::decode(const char* val) wchar_t* resp = res; char *p = tbuf; - while (*p) - { + while (*p) { char *cp = strstr(p, "=?"); if (cp == NULL) break; *cp = 0; @@ -450,30 +429,27 @@ wchar_t* MimeHeaders::decode(const char* val) if (pe == NULL) break; *pe = 0; - switch (*enc) + switch (*enc) { + case 'b': + case 'B': { - case 'b': - case 'B': - { - char* dec = (char*)mir_base64_decode(fld, 0); - strcpy(fld, dec); - mir_free(dec); - break; - } + char* dec = (char*)mir_base64_decode(fld, 0); + strcpy(fld, dec); + mir_free(dec); + break; + } - case 'q': - case 'Q': - PQDecode(fld); - break; + case 'q': + case 'Q': + PQDecode(fld); + break; } - if (_stricmp(cp, "UTF-8") == 0) - { + if (_stricmp(cp, "UTF-8") == 0) { sz = utf8toutf16(fld, resp); ssz -= sz; resp += sz; } - else - { + else { int sz = MultiByteToWideChar(FindCP(cp), 0, fld, -1, resp, (int)ssz); if (sz == 0) sz = MultiByteToWideChar(CP_ACP, 0, fld, -1, resp, (int)ssz); @@ -492,19 +468,16 @@ char* MimeHeaders::decodeMailBody(char* msgBody) { char* res; const char *val = find("Content-Transfer-Encoding"); - if (val && _stricmp(val, "base64") == 0) - { + if (val && _stricmp(val, "base64") == 0) { char *src = msgBody, *dst = msgBody; - while (*src != 0) - { + while (*src != 0) { if (isspace(*src)) ++src; else *(dst++) = *(src++); } *dst = 0; res = (char*)mir_base64_decode(msgBody, 0); } - else - { + else { res = mir_strdup(msgBody); if (val && _stricmp(val, "quoted-printable") == 0) PQDecode(res); @@ -516,8 +489,7 @@ char* MimeHeaders::decodeMailBody(char* msgBody) int sttDivideWords(char* parBuffer, int parMinItems, char** parDest) { int i; - for (i=0; i < parMinItems; i++) - { + for (i = 0; i < parMinItems; i++) { parDest[i] = parBuffer; size_t tWordLen = strcspn(parBuffer, " \t"); @@ -525,12 +497,12 @@ int sttDivideWords(char* parBuffer, int parMinItems, char** parDest) return i; parBuffer += tWordLen; - if (*parBuffer != '\0') - { + if (*parBuffer != '\0') { size_t tSpaceLen = strspn(parBuffer, " \t"); memset(parBuffer, 0, tSpaceLen); parBuffer += tSpaceLen; - } } + } + } return i; } diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index d370429c57..f7cf5cd6b4 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -30,8 +30,7 @@ along with this program. If not, see . const char* CMsnProto::MirandaStatusToMSN(int status) { - switch(status) - { + switch (status) { case ID_STATUS_OFFLINE: return "FLN"; case ID_STATUS_ONTHEPHONE: case ID_STATUS_OUTTOLUNCH: @@ -42,12 +41,12 @@ const char* CMsnProto::MirandaStatusToMSN(int status) case ID_STATUS_INVISIBLE: return "HDN"; case ID_STATUS_IDLE: return "IDL"; default: return "NLN"; -} } + } +} WORD CMsnProto::MSNStatusToMiranda(const char *status) { - switch((*(PDWORD)status&0x00FFFFFF) | 0x20000000) - { + switch ((*(PDWORD)status & 0x00FFFFFF) | 0x20000000) { case ' LDI': return ID_STATUS_IDLE; case ' NLN': return ID_STATUS_ONLINE; case ' NHP': @@ -75,7 +74,7 @@ char** CMsnProto::GetStatusMsgLoc(int status) ID_STATUS_OUTTOLUNCH, }; - for (int i=0; i < MSN_NUM_MODES; i++) + for (int i = 0; i < MSN_NUM_MODES; i++) if (modes[i] == status) return &msnModeMsgs[i]; return NULL; @@ -139,7 +138,7 @@ char* MSN_GetAvatarHash(char* szContext, char** pszUrl) if (szContext == NULL) return NULL; - char *res = NULL; + char *res = NULL; ezxml_t xmli = ezxml_parse_str(NEWSTR_ALLOCA(szContext), strlen(szContext)); const char *szAvatarHash = ezxml_attr(xmli, "SHA1D"); @@ -151,7 +150,7 @@ char* MSN_GetAvatarHash(char* szContext, char** pszUrl) if (pszUrl) { const char *pszUrlAttr; - for (int i=0; ; i++) { + for (int i = 0;; i++) { char szSetting[20]; if (i == 0) strcpy(szSetting, "Url"); @@ -221,9 +220,8 @@ void CMsnProto::MSN_GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t mir_sntprintf(pszDest + tPathLen2, cbLen - tPathLen2, _T("\\%s"), c_file.name); found = true; } - } - while(_tfindnext(hFile, &c_file) == 0); - _findclose( hFile ); + } while (_tfindnext(hFile, &c_file) == 0); + _findclose(hFile); } if (!found) pszDest[0] = 0; @@ -245,7 +243,7 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen) mir_sha1_append(&sha1ctx, (BYTE*)pData, (int)cbLen); mir_sha1_finish(&sha1ctx, sha1d); - ptrA szSha1d( mir_base64_encode((PBYTE)sha1d, sizeof(sha1d))); + ptrA szSha1d(mir_base64_encode((PBYTE)sha1d, sizeof(sha1d))); mir_sha1_init(&sha1ctx); ezxml_t xmlp = ezxml_new("msnobj"); @@ -278,7 +276,7 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen) mir_sha1_finish(&sha1ctx, sha1c); - ptrA szSha1c( mir_base64_encode((PBYTE)sha1c, sizeof(sha1c))); + ptrA szSha1c(mir_base64_encode((PBYTE)sha1c, sizeof(sha1c))); // ezxml_set_attr(xmlp, "SHA1C", szSha1c); @@ -340,11 +338,9 @@ void CMsnProto::MSN_GetCustomSmileyFileName(MCONTACT hContact, TCHAR* pszDest, s tPathLen = _tcslen(pszDest); } - if (hContact != NULL) - { - DBVARIANT dbv = {0}; - if (getTString(hContact, "e-mail", &dbv)) - { + if (hContact != NULL) { + DBVARIANT dbv = { 0 }; + if (getTString(hContact, "e-mail", &dbv)) { dbv.type = DBVT_ASCIIZ; dbv.ptszVal = (TCHAR*)mir_alloc(11); _ui64tot((UINT_PTR)hContact, dbv.ptszVal, 10); @@ -471,10 +467,10 @@ int ThreadData::sendMessage(int msgType, const char* email, int netId, const cha int seq; if (netId == NETID_YAHOO || netId == NETID_MOB || (parFlags & MSG_OFFLINE)) seq = sendPacket("UUM", "%s %d %c %d\r\n%s%s", email, netId, msgType, - strlen(parMsg)+off, buf, parMsg); + strlen(parMsg) + off, buf, parMsg); else seq = sendPacket("MSG", "%c %d\r\n%s%s", msgType, - strlen(parMsg)+off, buf, parMsg); + strlen(parMsg) + off, buf, parMsg); return seq; } @@ -525,7 +521,7 @@ int ThreadData::sendRawMessage(int msgType, const char* data, int datLen) // Typing notifications support -void CMsnProto::MSN_SendTyping(ThreadData* info, const char* email, int netId ) +void CMsnProto::MSN_SendTyping(ThreadData* info, const char* email, int netId) { char tCommand[1024]; mir_snprintf(tCommand, sizeof(tCommand), @@ -597,7 +593,7 @@ void CMsnProto::MSN_SendStatusMessage(const char* msg) else { char *szFormatEnc; if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)) { - LISTENINGTOINFO lti = {0}; + LISTENINGTOINFO lti = { 0 }; lti.cbSize = sizeof(lti); if (msnCurrentMedia.ptszTitle != NULL) lti.ptszTitle = _T("{0}"); if (msnCurrentMedia.ptszArtist != NULL) lti.ptszArtist = _T("{1}"); @@ -609,7 +605,7 @@ void CMsnProto::MSN_SendStatusMessage(const char* msg) if (msnCurrentMedia.ptszPlayer != NULL) lti.ptszPlayer = _T("{7}"); if (msnCurrentMedia.ptszType != NULL) lti.ptszType = _T("{8}"); - TCHAR *tmp = (TCHAR *)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM) _T("%title% - %artist%"), (LPARAM) <i); + TCHAR *tmp = (TCHAR *)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)_T("%title% - %artist%"), (LPARAM)<i); szFormatEnc = HtmlEncodeUTF8T(tmp); mir_free(tmp); } @@ -657,7 +653,7 @@ void CMsnProto::MSN_SendStatusMessage(const char* msg) ///////////////////////////////////////////////////////////////////////////////////////// // MSN_SendPacket - sends a packet accordingly to the MSN protocol -int ThreadData::sendPacket(const char* cmd, const char* fmt,...) +int ThreadData::sendPacket(const char* cmd, const char* fmt, ...) { if (this == NULL) return 0; @@ -677,16 +673,16 @@ int ThreadData::sendPacket(const char* cmd, const char* fmt,...) va_start(vararg, fmt); int paramStart = mir_snprintf(str, strsize, "%s %d ", cmd, thisTrid); - while (mir_vsnprintf(str+paramStart, strsize-paramStart-3, fmt, vararg) == -1) + while (mir_vsnprintf(str + paramStart, strsize - paramStart - 3, fmt, vararg) == -1) str = (char*)mir_realloc(str, strsize += 512); - str[strsize-3] = 0; + str[strsize - 3] = 0; va_end(vararg); } } if (strchr(str, '\r') == NULL) - strcat(str,"\r\n"); + strcat(str, "\r\n"); int result = send(str, strlen(str)); mir_free(str); @@ -709,7 +705,7 @@ void CMsnProto::MSN_SetServerStatus(int newStatus) const char* szStatusName = MirandaStatusToMSN(newStatus); if (newStatus != ID_STATUS_OFFLINE) { - DBVARIANT msnObject = {0}; + DBVARIANT msnObject = { 0 }; if (ServiceExists(MS_AV_SETMYAVATAR)) getString("PictObject", &msnObject); @@ -724,7 +720,7 @@ void CMsnProto::MSN_SetServerStatus(int newStatus) if (m_iStatus < ID_STATUS_ONLINE) { int sz = mir_snprintf(szMsg, sizeof(szMsg), "%u:%u", myFlags, myFlagsEx); - msnNsThread->sendPacket( "UUX", "%d\r\n%s", sz, szMsg ); + msnNsThread->sendPacket("UUX", "%d\r\n%s", sz, szMsg); msnNsThread->sendPacket("BLP", msnOtherContactsBlocked ? "BL" : "AL"); @@ -738,13 +734,13 @@ void CMsnProto::MSN_SetServerStatus(int newStatus) char *szPlace; DBVARIANT dbv; - if (!getStringUtf("Place", &dbv)) + if (!getStringUtf("Place", &dbv)) szPlace = dbv.pszVal; else { TCHAR buf[128] = _T("Miranda"); DWORD buflen = SIZEOF(buf); GetComputerName(buf, &buflen); - szPlace = mir_utf8encodeT(buf); + szPlace = mir_utf8encodeT(buf); } int sz = mir_snprintf(szMsg, sizeof(szMsg), @@ -835,7 +831,7 @@ LRESULT CALLBACK NullWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara if (tData != NULL) { if (tData->flags & MSN_HOTMAIL_POPUP) { MCONTACT hContact = tData->proto->MSN_HContactFromEmail(tData->proto->MyOptions.szEmail, NULL); - if (hContact) CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM) 1); + if (hContact) CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM)1); if (tData->flags & MSN_ALLOW_ENTER) tData->proto->MsnInvokeMyURL(true, tData->url); } @@ -849,7 +845,7 @@ LRESULT CALLBACK NullWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara if (tData != NULL && tData->flags & MSN_HOTMAIL_POPUP) { MCONTACT hContact = tData->proto->MSN_HContactFromEmail(tData->proto->MyOptions.szEmail, NULL); if (hContact) - CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM) 1); + CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM)1); } PUDeletePopup(hWnd); break; @@ -883,14 +879,14 @@ void CMsnProto::InitPopups(void) ppc.pszName = name; ppc.colorBack = RGB(173, 206, 247); - ppc.colorText = GetSysColor(COLOR_WINDOWTEXT); + ppc.colorText = GetSysColor(COLOR_WINDOWTEXT); ppc.iSeconds = 3; mir_sntprintf(desc, SIZEOF(desc), _T("%s/%s"), m_tszUserName, TranslateT("Hotmail")); mir_snprintf(name, SIZEOF(name), "%s_%s", m_szModuleName, "Hotmail"); hPopupHotmail = Popup_RegisterClass(&ppc); ppc.colorBack = RGB(173, 206, 247); - ppc.colorText = GetSysColor(COLOR_WINDOWTEXT); + ppc.colorText = GetSysColor(COLOR_WINDOWTEXT); ppc.iSeconds = 3; mir_sntprintf(desc, SIZEOF(desc), _T("%s/%s"), m_tszUserName, TranslateT("Notify")); mir_snprintf(name, SIZEOF(name), "%s_%s", m_szModuleName, "Notify"); @@ -990,15 +986,13 @@ filetransfer::~filetransfer(void) WaitForSingleObject(hLockHandle, 2000); CloseHandle(hLockHandle); - if (fileId != -1) - { + if (fileId != -1) { _close(fileId); if (p2p_appID != MSN_APPID_FILE && !(std.flags & PFTS_SENDING)) proto->p2p_pictureTransferFailed(this); } - if (!bCompleted && p2p_appID == MSN_APPID_FILE) - { + if (!bCompleted && p2p_appID == MSN_APPID_FILE) { std.ptszFiles = NULL; std.totalFiles = 0; proto->ProtoBroadcastAck(std.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, this, 0); @@ -1011,9 +1005,8 @@ filetransfer::~filetransfer(void) mir_free(std.tszCurrentFile); mir_free(std.tszWorkingDir); - if (std.ptszFiles != NULL) - { - for (int i=0; std.ptszFiles[i]; i++) + if (std.ptszFiles != NULL) { + for (int i = 0; std.ptszFiles[i]; i++) mir_free(std.ptszFiles[i]); mir_free(std.ptszFiles); } @@ -1049,15 +1042,13 @@ int filetransfer::create(void) int filetransfer::openNext(void) { - if (fileId != -1) - { + if (fileId != -1) { close(); ++std.currentFileNumber; ++cf; } - while (std.ptszFiles && std.ptszFiles[cf]) - { + while (std.ptszFiles && std.ptszFiles[cf]) { struct _stati64 statbuf; if (_tstati64(std.ptszFiles[cf], &statbuf) == 0 && (statbuf.st_mode & _S_IFDIR) == 0) break; @@ -1065,13 +1056,11 @@ int filetransfer::openNext(void) ++cf; } - if (std.ptszFiles && std.ptszFiles[cf]) - { + if (std.ptszFiles && std.ptszFiles[cf]) { bCompleted = false; replaceStrT(std.tszCurrentFile, std.ptszFiles[cf]); fileId = _topen(std.tszCurrentFile, _O_BINARY | _O_RDONLY, _S_IREAD); - if (fileId != -1) - { + if (fileId != -1) { std.currentFileSize = _filelengthi64(fileId); std.currentFileProgress = 0; @@ -1149,7 +1138,7 @@ void directconnection::xNonceToBin(UUID* nonce) size_t len = strlen(xNonce); char *p = (char*)alloca(len); strcpy(p, xNonce + 1); - p[len-2] = 0; + p[len - 2] = 0; UuidFromStringA((BYTE*)p, nonce); } @@ -1184,12 +1173,12 @@ char* TWinErrorCode::getText() *mErrorText = (char)tolower(*mErrorText); - if (mErrorText[tBytes-1] == '\n') + if (mErrorText[tBytes - 1] == '\n') mErrorText[--tBytes] = 0; - if (mErrorText[tBytes-1] == '\r') + if (mErrorText[tBytes - 1] == '\r') mErrorText[--tBytes] = 0; - if (mErrorText[tBytes-1] == '.') - mErrorText[tBytes-1] = 0; + if (mErrorText[tBytes - 1] == '.') + mErrorText[tBytes - 1] = 0; return mErrorText; } @@ -1216,7 +1205,7 @@ bool MSN_MsgWndExist(MCONTACT hContact) { MessageWindowInputData msgWinInData = { sizeof(MessageWindowInputData), hContact, MSG_WINDOW_UFLAG_MSG_BOTH }; - MessageWindowData msgWinData = {0}; + MessageWindowData msgWinData = { 0 }; msgWinData.cbSize = sizeof(MessageWindowData); bool res = CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&msgWinInData, (LPARAM)&msgWinData) != 0; @@ -1244,16 +1233,16 @@ void MSN_MakeDigest(const char* chl, char* dgst) memcpy(md5hashOr, md5hash, sizeof(md5hash)); size_t i; - for (i=0; i < 4; i++) + for (i = 0; i < 4; i++) md5hash[i] &= 0x7FFFFFFF; char chlString[128]; mir_snprintf(chlString, sizeof(chlString), "%s%s00000000", chl, msnProductID); - chlString[(strlen(chl)+strlen(msnProductID)+7) & 0xF8] = 0; + chlString[(strlen(chl) + strlen(msnProductID) + 7) & 0xF8] = 0; - LONGLONG high=0, low=0; + LONGLONG high = 0, low = 0; int* chlStringArray = (int*)chlString; - for (i=0; i < strlen(chlString) / 4; i += 2) { + for (i = 0; i < strlen(chlString) / 4; i += 2) { LONGLONG temp = chlStringArray[i]; temp = (0x0E79A9C1 * temp) % 0x7FFFFFFF; diff --git a/protocols/MSN/src/msn_msgqueue.cpp b/protocols/MSN/src/msn_msgqueue.cpp index c11887c53d..3edfa0cbbf 100644 --- a/protocols/MSN/src/msn_msgqueue.cpp +++ b/protocols/MSN/src/msn_msgqueue.cpp @@ -68,7 +68,7 @@ const char* CMsnProto::MsgQueue_CheckContact(const char* wlid, time_t tsc) mir_cslock lck(csMsgQueue); - for (int i=0; i < lsMessageQueue.getCount(); i++) + for (int i = 0; i < lsMessageQueue.getCount(); i++) if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0 && (tsc == 0 || (ts - lsMessageQueue[i].ts) < tsc)) return wlid; @@ -80,15 +80,13 @@ const char* CMsnProto::MsgQueue_GetNextRecipient(void) { mir_cslock lck(csMsgQueue); - for (int i=0; i < lsMessageQueue.getCount(); i++) - { + for (int i = 0; i < lsMessageQueue.getCount(); i++) { MsgQueueEntry& E = lsMessageQueue[i]; - if (!E.allocatedToThread) - { + if (!E.allocatedToThread) { E.allocatedToThread = 1; const char *ret = E.wlid; - while(++i < lsMessageQueue.getCount()) + while (++i < lsMessageQueue.getCount()) if (_stricmp(lsMessageQueue[i].wlid, ret) == 0) lsMessageQueue[i].allocatedToThread = 1; @@ -110,8 +108,7 @@ bool CMsnProto::MsgQueue_GetNext(const char* wlid, MsgQueueEntry& retVal) break; bool res = i != lsMessageQueue.getCount(); - if (res) - { + if (res) { retVal = lsMessageQueue[i]; lsMessageQueue.remove(i); } @@ -124,7 +121,7 @@ int CMsnProto::MsgQueue_NumMsg(const char* wlid) int res = 0; mir_cslock lck(csMsgQueue); - for(int i=0; i < lsMessageQueue.getCount(); i++) + for (int i = 0; i < lsMessageQueue.getCount(); i++) res += (_stricmp(lsMessageQueue[i].wlid, wlid) == 0); return res; @@ -135,13 +132,10 @@ void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg) int i; mir_cslockfull lck(csMsgQueue); - if (wlid == NULL) - { - for(i=0; i < lsMessageQueue.getCount(); i++) - { + if (wlid == NULL) { + for (i = 0; i < lsMessageQueue.getCount(); i++) { const MsgQueueEntry& E = lsMessageQueue[i]; - if (E.msgSize == 0) - { + if (E.msgSize == 0) { MCONTACT hContact = MSN_HContactFromEmail(E.wlid); ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)E.seq, (LPARAM)Translate("Message delivery failed")); @@ -154,14 +148,11 @@ void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg) msgQueueSeq = 1; } - else - { - for(i=0; i < lsMessageQueue.getCount(); i++) - { + else { + for (i = 0; i < lsMessageQueue.getCount(); i++) { time_t ts = time(NULL); const MsgQueueEntry& E = lsMessageQueue[i]; - if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0 && (!msg || E.msgSize == 0)) - { + if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0 && (!msg || E.msgSize == 0)) { bool msgfnd = E.msgSize == 0 && E.ts < ts; int seq = E.seq; diff --git a/protocols/MSN/src/msn_msgsplit.cpp b/protocols/MSN/src/msn_msgsplit.cpp index ab0e3bb11d..5f887a8585 100644 --- a/protocols/MSN/src/msn_msgsplit.cpp +++ b/protocols/MSN/src/msn_msgsplit.cpp @@ -21,7 +21,6 @@ along with this program. If not, see . #include "msn_global.h" #include "msn_proto.h" - chunkedmsg::chunkedmsg(const char* tid, const size_t totsz, const bool tbychunk) : size(totsz), recvsz(0), bychunk(tbychunk) { @@ -37,19 +36,16 @@ chunkedmsg::~chunkedmsg() void chunkedmsg::add(const char* tmsg, size_t offset, size_t portion) { - if (bychunk) - { + if (bychunk) { size_t oldsz = recvsz; recvsz += portion; - msg = (char*)mir_realloc(msg, recvsz + 1); - memcpy( msg + oldsz, tmsg, portion ); + msg = (char*)mir_realloc(msg, recvsz + 1); + memcpy(msg + oldsz, tmsg, portion); --size; } - else - { + else { size_t newsz = offset + portion; - if (newsz > size) - { + if (newsz > size) { portion = size - offset; newsz = size; } @@ -61,8 +57,7 @@ void chunkedmsg::add(const char* tmsg, size_t offset, size_t portion) bool chunkedmsg::get(char*& tmsg, size_t& tsize) { bool alldata = bychunk ? size == 0 : recvsz == size; - if (alldata) - { + if (alldata) { msg[recvsz] = 0; tmsg = msg; tsize = recvsz; @@ -74,11 +69,10 @@ bool chunkedmsg::get(char*& tmsg, size_t& tsize) int CMsnProto::addCachedMsg(const char* id, const char* msg, const size_t offset, - const size_t portion, const size_t totsz, const bool bychunk) + const size_t portion, const size_t totsz, const bool bychunk) { int idx = msgCache.getIndex((chunkedmsg*)&id); - if (idx == -1) - { + if (idx == -1) { msgCache.insert(new chunkedmsg(id, totsz, bychunk)); idx = msgCache.getIndex((chunkedmsg*)&id); } diff --git a/protocols/MSN/src/msn_natdetect.cpp b/protocols/MSN/src/msn_natdetect.cpp index c6569ff817..76bcf7a081 100644 --- a/protocols/MSN/src/msn_natdetect.cpp +++ b/protocols/MSN/src/msn_natdetect.cpp @@ -71,11 +71,10 @@ static void DiscardExtraPackets(SOCKET s) { Sleep(3000); - static const TIMEVAL tv = {0, 0}; + static const TIMEVAL tv = { 0, 0 }; unsigned buf; - for (;;) - { + for (;;) { if (Miranda_Terminated()) break; fd_set fd; @@ -95,8 +94,7 @@ void CMsnProto::MSNatDetect(void) unsigned i; PHOSTENT host = gethostbyname("echo.edge.messenger.live.com"); - if (host == NULL) - { + if (host == NULL) { debugLogA("P2PNAT could not find echo server \"echo.edge.messenger.live.com\""); return; } @@ -104,7 +102,7 @@ void CMsnProto::MSNatDetect(void) SOCKADDR_IN addr; addr.sin_family = AF_INET; addr.sin_port = _htons(7001); - addr.sin_addr = *( PIN_ADDR )host->h_addr_list[0]; + addr.sin_addr = *(PIN_ADDR)host->h_addr_list[0]; debugLogA("P2PNAT Detected echo server IP %d.%d.%d.%d", addr.sin_addr.S_un.S_un_b.s_b1, addr.sin_addr.S_un.S_un_b.s_b2, @@ -138,11 +136,10 @@ void CMsnProto::MSNatDetect(void) pkt.clientPort = 0x3141; pkt.clientIP = 0x31413141; - UDPProbePkt rpkt = {0}; + UDPProbePkt rpkt = { 0 }; // NAT detection - for (i=0; i<4; ++i) - { + for (i = 0; i < 4; ++i) { if (Miranda_Terminated()) break; // Send echo request to server 1 @@ -152,25 +149,22 @@ void CMsnProto::MSNatDetect(void) fd_set fd; FD_ZERO(&fd); FD_SET(s1, &fd); - TIMEVAL tv = {0, 200000 * (1 << i) }; + TIMEVAL tv = { 0, 200000 * (1 << i) }; - if (select(1, &fd, NULL, NULL, &tv) == 1) - { + if (select(1, &fd, NULL, NULL, &tv) == 1) { debugLogA("P2PNAT Request 1 attempt %d response", i); recv(s1, (char*)&rpkt, sizeof(rpkt), 0); pkt2 = rpkt; DecryptEchoPacket(rpkt); break; } - else - debugLogA("P2PNAT Request 1 attempt %d timeout", i); + else debugLogA("P2PNAT Request 1 attempt %d timeout", i); } closesocket(s); // Server did not respond - if (i >= 4) - { + if (i >= 4) { MyConnection.udpConType = conFirewall; closesocket(s1); return; @@ -179,8 +173,7 @@ void CMsnProto::MSNatDetect(void) MyConnection.extIP = rpkt.clientIP; // Check if NAT not found - if (MyConnection.extIP == MyConnection.intIP) - { + if (MyConnection.extIP == MyConnection.intIP) { if (msnExternalIP != NULL && inet_addr(msnExternalIP) != MyConnection.extIP) MyConnection.udpConType = conISALike; else @@ -191,14 +184,13 @@ void CMsnProto::MSNatDetect(void) } // Detect UPnP NAT - NETLIBBIND nlb = {0}; + NETLIBBIND nlb = { 0 }; nlb.cbSize = sizeof(nlb); nlb.pfnNewConnectionV2 = MSN_ConnectionProc; nlb.pExtra = this; - HANDLE sb = (HANDLE) CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlb); - if ( sb != NULL ) - { + HANDLE sb = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlb); + if (sb != NULL) { MyConnection.upnpNAT = htonl(nlb.dwExternalIP) == MyConnection.extIP; Sleep(100); Netlib_CloseHandle(sb); @@ -207,13 +199,12 @@ void CMsnProto::MSNatDetect(void) DiscardExtraPackets(s1); // Start IP Restricted NAT detection - UDPProbePkt rpkt2 = {0}; + UDPProbePkt rpkt2 = { 0 }; pkt2.serviceCode = 3; SOCKADDR_IN addr2 = addr; addr2.sin_addr.S_un.S_addr = rpkt.testIP; addr2.sin_port = rpkt.discardPort; - for (i=0; i<4; ++i) - { + for (i = 0; i < 4; ++i) { if (Miranda_Terminated()) break; debugLogA("P2PNAT Request 2 attempt %d sent", i); @@ -225,10 +216,9 @@ void CMsnProto::MSNatDetect(void) fd_set fd; FD_ZERO(&fd); FD_SET(s1, &fd); - TIMEVAL tv = {0, 200000 * (1 << i) }; + TIMEVAL tv = { 0, 200000 * (1 << i) }; - if (select(1, &fd, NULL, NULL, &tv) == 1) - { + if (select(1, &fd, NULL, NULL, &tv) == 1) { debugLogA("P2PNAT Request 2 attempt %d response", i); recv(s1, (char*)&rpkt2, sizeof(rpkt2), 0); DecryptEchoPacket(rpkt2); @@ -240,8 +230,7 @@ void CMsnProto::MSNatDetect(void) // Response recieved so it's an IP Restricted NAT (Restricted Cone NAT) // (MSN does not detect Full Cone NAT and consider it as IP Restricted NAT) - if (i < 4) - { + if (i < 4) { MyConnection.udpConType = conIPRestrictNAT; closesocket(s1); return; @@ -251,8 +240,7 @@ void CMsnProto::MSNatDetect(void) // Symmetric NAT detection addr2.sin_port = rpkt.testPort; - for (i=0; i<4; ++i) - { + for (i = 0; i < 4; ++i) { if (Miranda_Terminated()) break; debugLogA("P2PNAT Request 3 attempt %d sent", i); @@ -262,10 +250,9 @@ void CMsnProto::MSNatDetect(void) fd_set fd; FD_ZERO(&fd); FD_SET(s1, &fd); - TIMEVAL tv = {1 << i, 0 }; + TIMEVAL tv = { 1 << i, 0 }; - if ( select(1, &fd, NULL, NULL, &tv) == 1 ) - { + if (select(1, &fd, NULL, NULL, &tv) == 1) { debugLogA("P2PNAT Request 3 attempt %d response", i); recv(s1, (char*)&rpkt2, sizeof(rpkt2), 0); DecryptEchoPacket(rpkt2); @@ -274,11 +261,10 @@ void CMsnProto::MSNatDetect(void) else debugLogA("P2PNAT Request 3 attempt %d timeout", i); } - if (i < 4) - { + if (i < 4) { // If ports different it's symmetric NAT MyConnection.udpConType = rpkt.clientPort == rpkt2.clientPort ? - conPortRestrictNAT : conSymmetricNAT; +conPortRestrictNAT : conSymmetricNAT; } closesocket(s1); } @@ -302,7 +288,7 @@ static bool IsIcfEnabled(void) // Create an instance of the firewall settings manager. hr = CoCreateInstance(CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, - IID_INetFwMgr, (void**)&fwMgr ); + IID_INetFwMgr, (void**)&fwMgr); if (FAILED(hr)) goto error; // Retrieve the local firewall policy. @@ -334,8 +320,7 @@ static bool IsIcfEnabled(void) // Attempt to retrieve the authorized application. hr = fwApps->Item(fwBstrProcessImageFileName, &fwApp); - if (SUCCEEDED(hr)) - { + if (SUCCEEDED(hr)) { // Find out if the authorized application is enabled. fwApp->get_Enabled(&fwEnabled); fwEnabled = ~fwEnabled; @@ -366,8 +351,7 @@ error: return fwEnabled != VARIANT_FALSE; } - -void CMsnProto::MSNConnDetectThread( void* ) +void CMsnProto::MSNConnDetectThread(void*) { char parBuf[512] = ""; @@ -377,59 +361,53 @@ void CMsnProto::MSNConnDetectThread( void* ) bool portsMapped = getByte("NLSpecifyIncomingPorts", 0) != 0; unsigned gethst = getByte("AutoGetHost", 1); - switch (gethst) - { - case 0: - debugLogA("P2PNAT User overwrote IP connection is guessed by user settings only"); - - // User specified host by himself so check if it matches MSN information - // if it does, move to connection type autodetection, - // if it does not, guess connection type from available info - db_get_static(NULL, m_szModuleName, "YourHost", parBuf, sizeof(parBuf)); - if (msnExternalIP == NULL || strcmp(msnExternalIP, parBuf) != 0) - { - MyConnection.extIP = inet_addr(parBuf); - if (MyConnection.extIP == INADDR_NONE) - { - PHOSTENT myhost = gethostbyname(parBuf); - if (myhost != NULL) - MyConnection.extIP = ((PIN_ADDR)myhost->h_addr)->S_un.S_addr; - else - setByte("AutoGetHost", 1); - } - if (MyConnection.extIP != INADDR_NONE) - { - MyConnection.intIP = MyConnection.extIP; - MyConnection.udpConType = MyConnection.extIP ? (ConEnum)portsMapped : conUnknown; - MyConnection.CalculateWeight(); - return; - } - else - MyConnection.extIP = 0; - } - break; - - case 1: - if (msnExternalIP != NULL) - MyConnection.extIP = inet_addr(msnExternalIP); - else - { - gethostname(parBuf, sizeof(parBuf)); + switch (gethst) { + case 0: + debugLogA("P2PNAT User overwrote IP connection is guessed by user settings only"); + + // User specified host by himself so check if it matches MSN information + // if it does, move to connection type autodetection, + // if it does not, guess connection type from available info + db_get_static(NULL, m_szModuleName, "YourHost", parBuf, sizeof(parBuf)); + if (msnExternalIP == NULL || strcmp(msnExternalIP, parBuf) != 0) { + MyConnection.extIP = inet_addr(parBuf); + if (MyConnection.extIP == INADDR_NONE) { PHOSTENT myhost = gethostbyname(parBuf); if (myhost != NULL) MyConnection.extIP = ((PIN_ADDR)myhost->h_addr)->S_un.S_addr; + else + setByte("AutoGetHost", 1); } - MyConnection.intIP = MyConnection.extIP; - break; + if (MyConnection.extIP != INADDR_NONE) { + MyConnection.intIP = MyConnection.extIP; + MyConnection.udpConType = MyConnection.extIP ? (ConEnum)portsMapped : conUnknown; + MyConnection.CalculateWeight(); + return; + } + else + MyConnection.extIP = 0; + } + break; + + case 1: + if (msnExternalIP != NULL) + MyConnection.extIP = inet_addr(msnExternalIP); + else { + gethostname(parBuf, sizeof(parBuf)); + PHOSTENT myhost = gethostbyname(parBuf); + if (myhost != NULL) + MyConnection.extIP = ((PIN_ADDR)myhost->h_addr)->S_un.S_addr; + } + MyConnection.intIP = MyConnection.extIP; + break; - case 2: - MyConnection.udpConType = conUnknown; - MyConnection.CalculateWeight(); - return; + case 2: + MyConnection.udpConType = conUnknown; + MyConnection.CalculateWeight(); + return; } - if (getByte( "NLSpecifyOutgoingPorts", 0)) - { + if (getByte("NLSpecifyOutgoingPorts", 0)) { // User specified outgoing ports so the connection must be firewalled // do not autodetect and guess connection type from available info MyConnection.intIP = MyConnection.extIP; @@ -442,11 +420,9 @@ void CMsnProto::MSNConnDetectThread( void* ) MSNatDetect(); // If user mapped incoming ports consider direct connection - if (portsMapped) - { + if (portsMapped) { debugLogA("P2PNAT User manually mapped ports for incoming connection"); - switch(MyConnection.udpConType) - { + switch (MyConnection.udpConType) { case conUnknown: case conFirewall: case conISALike: @@ -468,20 +444,16 @@ void CMsnProto::MSNConnDetectThread( void* ) MyConnection.CalculateWeight(); } - void MyConnectionType::SetUdpCon(const char* str) { - for (unsigned i=0; imsnLoggedIn && proto->getByte("MobileEnabled", 0) && proto->getByte("MobileAllowed", 0)); - CheckDlgButton(hwndDlg, IDC_MOBILESEND, proto->getByte("MobileAllowed", 0)); - CheckDlgButton(hwndDlg, IDC_SENDFONTINFO, proto->getByte("SendFontInfo", 1)); - CheckDlgButton(hwndDlg, IDC_MANAGEGROUPS, proto->getByte("ManageServer", 1)); + CheckDlgButton(hwndDlg, IDC_MOBILESEND, proto->getByte("MobileAllowed", 0)); + CheckDlgButton(hwndDlg, IDC_SENDFONTINFO, proto->getByte("SendFontInfo", 1)); + CheckDlgButton(hwndDlg, IDC_MANAGEGROUPS, proto->getByte("ManageServer", 1)); int tValue = proto->getByte("RunMailerOnHotmail", 0); CheckDlgButton(hwndDlg, IDC_RUN_APP_ON_HOTMAIL, tValue); @@ -133,15 +133,15 @@ static INT_PTR CALLBACK DlgProcMsnOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP } if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) { - switch(LOWORD(wParam)) { - case IDC_HANDLE: case IDC_PASSWORD: case IDC_HANDLE2: - case IDC_GATEWAYSERVER: case IDC_YOURHOST: case IDC_DIRECTSERVER: + switch (LOWORD(wParam)) { + case IDC_HANDLE: case IDC_PASSWORD: case IDC_HANDLE2: + case IDC_GATEWAYSERVER: case IDC_YOURHOST: case IDC_DIRECTSERVER: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } if (HIWORD(wParam) == BN_CLICKED) { - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDC_SENDFONTINFO: case IDC_DISABLE_ANOTHER_CONTACTS: case IDC_MOBILESEND: @@ -152,8 +152,7 @@ static INT_PTR CALLBACK DlgProcMsnOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP if (IsDlgButtonChecked(hwndDlg, IDC_MANAGEGROUPS)) { if (IDYES == MessageBox(hwndDlg, TranslateT("Server groups import may change your contact list layout after next login. Do you want to upload your groups to the server?"), - TranslateT("MSN Protocol"), MB_YESNOCANCEL)) - { + TranslateT("MSN Protocol"), MB_YESNOCANCEL)) { CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); proto->MSN_UploadServerGroups(NULL); } @@ -171,32 +170,30 @@ static INT_PTR CALLBACK DlgProcMsnOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP break; case IDC_ENTER_MAILER_APP: + char szFile[MAX_PATH + 2]; { HWND tEditField = GetDlgItem(hwndDlg, IDC_MAILER_APP); - char szFile[MAX_PATH + 2]; GetWindowTextA(tEditField, szFile, sizeof(szFile)); size_t tSelectLen = 0; if (szFile[0] == '\"') { - char* p = strchr(szFile+1, '\"'); + char* p = strchr(szFile + 1, '\"'); if (p != NULL) { *p = '\0'; - memmove(szFile, szFile+1, strlen(szFile)); + memmove(szFile, szFile + 1, strlen(szFile)); tSelectLen += 2; goto LBL_Continue; } } - { - char* p = strchr(szFile, ' '); - if (p != NULL) *p = '\0'; - } + char* p = strchr(szFile, ' '); + if (p != NULL) *p = '\0'; LBL_Continue: tSelectLen += strlen(szFile); - OPENFILENAMEA ofn = {0}; + OPENFILENAMEA ofn = { 0 }; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwndDlg; ofn.nMaxFile = sizeof(szFile); @@ -249,7 +246,7 @@ LBL_Continue: } GetDlgItemText(hwndDlg, IDC_HANDLE2, screenStr, SIZEOF(screenStr)); - if (!proto->getTString("Nick", &dbv)) { + if (!proto->getTString("Nick", &dbv)) { if (_tcscmp(dbv.ptszVal, screenStr)) proto->MSN_SendNickname(screenStr); db_free(&dbv); @@ -270,17 +267,17 @@ LBL_Continue: break; } - proto->setByte("SendFontInfo", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SENDFONTINFO)); + proto->setByte("SendFontInfo", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SENDFONTINFO)); proto->setByte("RunMailerOnHotmail", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_RUN_APP_ON_HOTMAIL)); - proto->setByte("ManageServer", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_MANAGEGROUPS)); + proto->setByte("ManageServer", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_MANAGEGROUPS)); GetDlgItemText(hwndDlg, IDC_MAILER_APP, screenStr, SIZEOF(screenStr)); proto->setTString("MailerPath", screenStr); if (reconnectRequired && proto->msnLoggedIn) MessageBox(hwndDlg, - TranslateT("The changes you have made require you to reconnect to the MSN Messenger network before they take effect"), - TranslateT("MSN Options"), MB_OK); + TranslateT("The changes you have made require you to reconnect to the MSN Messenger network before they take effect"), + TranslateT("MSN Options"), MB_OK); proto->LoadOptions(); return TRUE; @@ -309,15 +306,15 @@ static INT_PTR CALLBACK DlgProcMsnConnOpts(HWND hwndDlg, UINT msg, WPARAM wParam SetDlgItemTextA(hwndDlg, IDC_DIRECTSERVER, dbv.pszVal); db_free(&dbv); } - else SetDlgItemTextA(hwndDlg, IDC_DIRECTSERVER, MSN_DEFAULT_LOGIN_SERVER); + else SetDlgItemTextA(hwndDlg, IDC_DIRECTSERVER, MSN_DEFAULT_LOGIN_SERVER); if (!proto->getString("GatewayServer", &dbv)) { SetDlgItemTextA(hwndDlg, IDC_GATEWAYSERVER, dbv.pszVal); db_free(&dbv); } - else SetDlgItemTextA(hwndDlg, IDC_GATEWAYSERVER, MSN_DEFAULT_GATEWAY); + else SetDlgItemTextA(hwndDlg, IDC_GATEWAYSERVER, MSN_DEFAULT_GATEWAY); - CheckDlgButton(hwndDlg, IDC_SLOWSEND, proto->getByte("SlowSend", 0)); + CheckDlgButton(hwndDlg, IDC_SLOWSEND, proto->getByte("SlowSend", 0)); SendDlgItemMessage(hwndDlg, IDC_HOSTOPT, CB_ADDSTRING, 0, (LPARAM)TranslateT("Automatically obtain host/port")); SendDlgItemMessage(hwndDlg, IDC_HOSTOPT, CB_ADDSTRING, 0, (LPARAM)TranslateT("Manually specify host/port")); @@ -353,7 +350,7 @@ static INT_PTR CALLBACK DlgProcMsnConnOpts(HWND hwndDlg, UINT msg, WPARAM wParam } if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDC_DIRECTSERVER: case IDC_GATEWAYSERVER: case IDC_YOURHOST: @@ -367,7 +364,7 @@ static INT_PTR CALLBACK DlgProcMsnConnOpts(HWND hwndDlg, UINT msg, WPARAM wParam } if (HIWORD(wParam) == BN_CLICKED) { - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDC_SLOWSEND: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; @@ -394,13 +391,12 @@ static INT_PTR CALLBACK DlgProcMsnConnOpts(HWND hwndDlg, UINT msg, WPARAM wParam else proto->delSetting("GatewayServer"); - proto->setByte("SlowSend", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SLOWSEND )); + proto->setByte("SlowSend", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SLOWSEND)); if (proto->getByte("SlowSend", FALSE)) { if (db_get_dw(NULL, "SRMsg", "MessageTimeout", 60000) < 60000 || - db_get_dw(NULL, "SRMM", "MessageTimeout", 60000) < 60000) - { + db_get_dw(NULL, "SRMM", "MessageTimeout", 60000) < 60000) { MessageBox(NULL, TranslateT("MSN Protocol requires message timeout to be not less then 60 sec. Correct the timeout value."), - TranslateT("MSN Protocol"), MB_OK|MB_ICONINFORMATION); + TranslateT("MSN Protocol"), MB_OK | MB_ICONINFORMATION); } } @@ -438,7 +434,7 @@ static INT_PTR CALLBACK DlgProcHotmailPopupOpts(HWND hwndDlg, UINT msg, WPARAM w static bool bEnabled; CMsnProto* proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); bEnabled = false; @@ -446,11 +442,11 @@ static INT_PTR CALLBACK DlgProcHotmailPopupOpts(HWND hwndDlg, UINT msg, WPARAM w SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); proto = (CMsnProto*)lParam; CheckDlgButton(hwndDlg, IDC_DISABLEHOTMAILPOPUP, proto->getByte("DisableHotmail", 0)); - CheckDlgButton(hwndDlg, IDC_DISABLEHOTMAILTRAY, proto->getByte("DisableHotmailTray", 1)); - CheckDlgButton(hwndDlg, IDC_DISABLEHOTMAILCL, proto->getByte("DisableHotmailCL", 0)); - CheckDlgButton(hwndDlg, IDC_DISABLEHOTJUNK, proto->getByte("DisableHotmailJunk", 0)); - CheckDlgButton(hwndDlg, IDC_NOTIFY_ENDSESSION, proto->getByte("EnableSessionPopup", 0)); - CheckDlgButton(hwndDlg, IDC_NOTIFY_FIRSTMSG, proto->getByte("EnableDeliveryPopup", 0)); + CheckDlgButton(hwndDlg, IDC_DISABLEHOTMAILTRAY, proto->getByte("DisableHotmailTray", 1)); + CheckDlgButton(hwndDlg, IDC_DISABLEHOTMAILCL, proto->getByte("DisableHotmailCL", 0)); + CheckDlgButton(hwndDlg, IDC_DISABLEHOTJUNK, proto->getByte("DisableHotmailJunk", 0)); + CheckDlgButton(hwndDlg, IDC_NOTIFY_ENDSESSION, proto->getByte("EnableSessionPopup", 0)); + CheckDlgButton(hwndDlg, IDC_NOTIFY_FIRSTMSG, proto->getByte("EnableDeliveryPopup", 0)); CheckDlgButton(hwndDlg, IDC_ERRORS_USING_POPUPS, proto->getByte("ShowErrorsAsPopups", 0)); bEnabled = true; @@ -472,13 +468,13 @@ static INT_PTR CALLBACK DlgProcHotmailPopupOpts(HWND hwndDlg, UINT msg, WPARAM w break; case WM_NOTIFY: //Here we have pressed either the OK or the APPLY button. - switch(((LPNMHDR)lParam)->idFrom) { + switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_RESET: proto->LoadOptions(); return TRUE; - + case PSN_APPLY: proto->MyOptions.ShowErrorsAsPopups = IsDlgButtonChecked(hwndDlg, IDC_ERRORS_USING_POPUPS) != 0; proto->setByte("ShowErrorsAsPopups", proto->MyOptions.ShowErrorsAsPopups); @@ -486,7 +482,7 @@ static INT_PTR CALLBACK DlgProcHotmailPopupOpts(HWND hwndDlg, UINT msg, WPARAM w proto->setByte("DisableHotmail", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_DISABLEHOTMAILPOPUP)); proto->setByte("DisableHotmailCL", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_DISABLEHOTMAILCL)); proto->setByte("DisableHotmailTray", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_DISABLEHOTMAILTRAY)); - proto->setByte("DisableHotmailJunk",(BYTE)IsDlgButtonChecked(hwndDlg, IDC_DISABLEHOTJUNK)); + proto->setByte("DisableHotmailJunk", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_DISABLEHOTJUNK)); proto->setByte("EnableDeliveryPopup", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_NOTIFY_FIRSTMSG)); proto->setByte("EnableSessionPopup", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_NOTIFY_ENDSESSION)); @@ -505,14 +501,13 @@ static INT_PTR CALLBACK DlgProcHotmailPopupOpts(HWND hwndDlg, UINT msg, WPARAM w static INT_PTR CALLBACK DlgProcAccMgrUI(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); { - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - CMsnProto* proto = (CMsnProto*)lParam; + CMsnProto* proto = (CMsnProto*)lParam; SetDlgItemTextA(hwndDlg, IDC_HANDLE, proto->MyOptions.szEmail); char tBuffer[MAX_PATH]; @@ -537,7 +532,7 @@ static INT_PTR CALLBACK DlgProcAccMgrUI(HWND hwndDlg, UINT msg, WPARAM wParam, L } if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) { - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDC_HANDLE: case IDC_PASSWORD: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); @@ -583,7 +578,7 @@ static INT_PTR CALLBACK DlgProcAccMgrUI(HWND hwndDlg, UINT msg, WPARAM wParam, L INT_PTR CALLBACK DlgDeleteContactUI(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); @@ -619,33 +614,33 @@ INT_PTR CALLBACK DlgDeleteContactUI(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA ///////////////////////////////////////////////////////////////////////////////////////// // Initialize options pages -int CMsnProto::OnOptionsInit(WPARAM wParam,LPARAM lParam) +int CMsnProto::OnOptionsInit(WPARAM wParam, LPARAM lParam) { OPTIONSDIALOGPAGE odp = { sizeof(odp) }; - odp.position = -790000000; - odp.hInstance = hInst; + odp.position = -790000000; + odp.hInstance = hInst; odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MSN); - odp.ptszTitle = m_tszUserName; - odp.ptszGroup = LPGENT("Network"); - odp.ptszTab = LPGENT("Account"); - odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE; - odp.pfnDlgProc = DlgProcMsnOpts; + odp.ptszTitle = m_tszUserName; + odp.ptszGroup = LPGENT("Network"); + odp.ptszTab = LPGENT("Account"); + odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE; + odp.pfnDlgProc = DlgProcMsnOpts; odp.dwInitParam = (LPARAM)this; Options_AddPage(wParam, &odp); - odp.ptszTab = LPGENT("Connection"); + odp.ptszTab = LPGENT("Connection"); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MSN_CONN); - odp.pfnDlgProc = DlgProcMsnConnOpts; + odp.pfnDlgProc = DlgProcMsnConnOpts; Options_AddPage(wParam, &odp); - odp.ptszTab = LPGENT("Server list"); + odp.ptszTab = LPGENT("Server list"); odp.pszTemplate = MAKEINTRESOURCEA(IDD_LISTSMGR); - odp.pfnDlgProc = DlgProcMsnServLists; + odp.pfnDlgProc = DlgProcMsnServLists; Options_AddPage(wParam, &odp); - odp.ptszTab = LPGENT("Notifications"); + odp.ptszTab = LPGENT("Notifications"); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_NOTIFY); - odp.pfnDlgProc = DlgProcHotmailPopupOpts; + odp.pfnDlgProc = DlgProcHotmailPopupOpts; Options_AddPage(wParam, &odp); return 0; @@ -653,11 +648,10 @@ int CMsnProto::OnOptionsInit(WPARAM wParam,LPARAM lParam) INT_PTR CMsnProto::SvcCreateAccMgrUI(WPARAM wParam, LPARAM lParam) { - return (INT_PTR)CreateDialogParam (hInst, MAKEINTRESOURCE(IDD_ACCMGRUI), + return (INT_PTR)CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ACCMGRUI), (HWND)lParam, DlgProcAccMgrUI, (LPARAM)this); } - ///////////////////////////////////////////////////////////////////////////////////////// // Load resident option values into memory diff --git a/protocols/MSN/src/msn_p2p.cpp b/protocols/MSN/src/msn_p2p.cpp index 28001e66cc..ffe25feeb1 100644 --- a/protocols/MSN/src/msn_p2p.cpp +++ b/protocols/MSN/src/msn_p2p.cpp @@ -84,13 +84,12 @@ bool CMsnProto::p2p_createListener(filetransfer* ft, directconnection *dc, MimeH { if (MyConnection.extIP == 0) return false; - NETLIBBIND nlb = {0}; + NETLIBBIND nlb = { 0 }; nlb.cbSize = sizeof(nlb); nlb.pfnNewConnectionV2 = MSN_ConnectionProc; nlb.pExtra = this; - HANDLE sb = (HANDLE) CallService(MS_NETLIB_BINDPORT, (WPARAM) m_hNetlibUser, (LPARAM)&nlb); - if (sb == NULL) - { + HANDLE sb = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlb); + if (sb == NULL) { debugLogA("Unable to bind the port for incoming transfers"); return false; } @@ -100,7 +99,7 @@ bool CMsnProto::p2p_createListener(filetransfer* ft, directconnection *dc, MimeH newThread->mCaller = 3; newThread->mIncomingBoundPort = sb; newThread->mIncomingPort = nlb.wPort; - strncpy(newThread->mCookie, dc->callId , sizeof(newThread->mCookie)); + strncpy(newThread->mCookie, dc->callId, sizeof(newThread->mCookie)); newThread->mInitialContactWLID = mir_strdup(ft->p2p_dest); newThread->startThread(&CMsnProto::p2p_filePassiveThread, this); @@ -113,15 +112,12 @@ bool CMsnProto::p2p_createListener(filetransfer* ft, directconnection *dc, MimeH int i4 = 0, i6 = 0; NETLIBIPLIST* ihaddr = (NETLIBIPLIST*)CallService(MS_NETLIB_GETMYIP, 1, 0); - for (unsigned i = 0; i < ihaddr->cbNum; ++i) - { - if (strchr(ihaddr->szIp[i], ':')) - { + for (unsigned i = 0; i < ihaddr->cbNum; ++i) { + if (strchr(ihaddr->szIp[i], ':')) { if (i6++ != 0) strcat(szIpv6, " "); strcat(szIpv6, ihaddr->szIp[i]); } - else - { + else { if (i4++ != 0) strcat(szIpv4, " "); ipInt |= (strcmp(ihaddr->szIp[i], szExtIp) == 0); strcat(szIpv4, ihaddr->szIp[i]); @@ -139,15 +135,13 @@ bool CMsnProto::p2p_createListener(filetransfer* ft, directconnection *dc, MimeH bool bUbnCall = !ft->p2p_sessionid; - if (!ipInt) - { + if (!ipInt) { chdrs.addString("IPv4External-Addrs", mir_strdup(MyConnection.GetMyExtIPStr()), bUbnCall ? 6 : 2); chdrs.addLong("IPv4External-Port", nlb.wExPort, bUbnCall ? 4 : 0); } chdrs.addString("IPv4Internal-Addrs", mir_strdup(szIpv4), bUbnCall ? 6 : 2); chdrs.addLong("IPv4Internal-Port", nlb.wPort, bUbnCall ? 4 : 0); - if (szIpv6[0]) - { + if (szIpv6[0]) { chdrs.addString("IPv6-Addrs", mir_strdup(szIpv6), 2); chdrs.addLong("IPv6-Port", nlb.wPort); } @@ -167,12 +161,11 @@ bool p2p_IsDlFileOk(filetransfer* ft) bool res = false; int fileId = _topen(ft->std.tszCurrentFile, O_RDONLY | _O_BINARY, _S_IREAD); - if (fileId != -1) - { + if (fileId != -1) { BYTE buf[4096]; int bytes; - while((bytes = _read(fileId, buf, sizeof(buf))) > 0) + while ((bytes = _read(fileId, buf, sizeof(buf))) > 0) mir_sha1_append(&sha1ctx, buf, bytes); _close(fileId); @@ -196,18 +189,17 @@ bool p2p_IsDlFileOk(filetransfer* ft) void CMsnProto::p2p_pictureTransferFailed(filetransfer* ft) { - switch(ft->p2p_type) - { + switch (ft->p2p_type) { case MSN_APPID_AVATAR: case MSN_APPID_AVATAR2: - { - PROTO_AVATAR_INFORMATIONT AI = {0}; - AI.cbSize = sizeof(AI); - AI.hContact = ft->std.hContact; - delSetting(ft->std.hContact, "AvatarHash"); - ProtoBroadcastAck(AI.hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, &AI, 0); - } - break; + { + PROTO_AVATAR_INFORMATIONT AI = { 0 }; + AI.cbSize = sizeof(AI); + AI.hContact = ft->std.hContact; + delSetting(ft->std.hContact, "AvatarHash"); + ProtoBroadcastAck(AI.hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, &AI, 0); + } + break; } _tremove(ft->std.tszCurrentFile); } @@ -216,8 +208,7 @@ void CMsnProto::p2p_savePicture2disk(filetransfer* ft) { ft->close(); - if (p2p_IsDlFileOk(ft)) - { + if (p2p_IsDlFileOk(ft)) { int fileId = _topen(ft->std.tszCurrentFile, O_RDONLY | _O_BINARY, _S_IREAD); if (fileId == -1) { p2p_pictureTransferFailed(ft); @@ -237,51 +228,50 @@ void CMsnProto::p2p_savePicture2disk(filetransfer* ft) return; } - switch(ft->p2p_type) - { + switch (ft->p2p_type) { case MSN_APPID_AVATAR: case MSN_APPID_AVATAR2: - { - PROTO_AVATAR_INFORMATIONT AI = {0}; - AI.cbSize = sizeof(AI); - AI.format = format; - AI.hContact = ft->std.hContact; - MSN_GetAvatarFileName(AI.hContact, AI.filename, SIZEOF(AI.filename), ext); - - _trename(ft->std.tszCurrentFile, AI.filename); - - // Store also avatar hash - char *szAvatarHash = MSN_GetAvatarHash(ft->p2p_object); - setString(ft->std.hContact, "AvatarSavedHash", szAvatarHash); - mir_free(szAvatarHash); - - setString(ft->std.hContact, "PictSavedContext", ft->p2p_object); - ProtoBroadcastAck(AI.hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &AI, 0); - - char *filename = mir_utf8encodeT(AI.filename); - debugLogA("Avatar for contact %08x saved to file '%s'", AI.hContact, filename); - mir_free(filename); - } - break; + { + PROTO_AVATAR_INFORMATIONT AI = { 0 }; + AI.cbSize = sizeof(AI); + AI.format = format; + AI.hContact = ft->std.hContact; + MSN_GetAvatarFileName(AI.hContact, AI.filename, SIZEOF(AI.filename), ext); + + _trename(ft->std.tszCurrentFile, AI.filename); + + // Store also avatar hash + char *szAvatarHash = MSN_GetAvatarHash(ft->p2p_object); + setString(ft->std.hContact, "AvatarSavedHash", szAvatarHash); + mir_free(szAvatarHash); + + setString(ft->std.hContact, "PictSavedContext", ft->p2p_object); + ProtoBroadcastAck(AI.hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &AI, 0); + + char *filename = mir_utf8encodeT(AI.filename); + debugLogA("Avatar for contact %08x saved to file '%s'", AI.hContact, filename); + mir_free(filename); + } + break; case MSN_APPID_CUSTOMSMILEY: case MSN_APPID_CUSTOMANIMATEDSMILEY: - { - SMADD_CONT cont; - cont.cbSize = sizeof(SMADD_CONT); - cont.hContact = ft->std.hContact; - cont.type = 1; + { + SMADD_CONT cont; + cont.cbSize = sizeof(SMADD_CONT); + cont.hContact = ft->std.hContact; + cont.type = 1; - TCHAR* pathcpy = mir_tstrdup(ft->std.tszCurrentFile); - _tcscpy(_tcsrchr(pathcpy, '.') + 1, ext); - _trename(ft->std.tszCurrentFile, pathcpy); + TCHAR* pathcpy = mir_tstrdup(ft->std.tszCurrentFile); + _tcscpy(_tcsrchr(pathcpy, '.') + 1, ext); + _trename(ft->std.tszCurrentFile, pathcpy); - cont.path = pathcpy; + cont.path = pathcpy; - CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); - mir_free(pathcpy); - } - break; + CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); + mir_free(pathcpy); + } + break; } } } @@ -294,8 +284,7 @@ static const char sttVoidSession[] = "ACHTUNG!!! an attempt made to send a messa void CMsnProto::p2p_sendMsg(const char *wlid, unsigned appId, P2PB_Header& hdrdata, char* msgbody, size_t msgsz) { ThreadData* info = MSN_GetP2PThreadByContact(wlid); - if (info == NULL) - { + if (info == NULL) { bool isOffline; info = MSN_StartSB(wlid, isOffline); } @@ -313,12 +302,11 @@ void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, unsigned fportion = msgType == 1 ? 1352 : 1202; if (hdrdata.isV2Hdr()) fportion += 4; - char* buf = (char*) alloca(sizeof(sttP2PheaderV2)+ MSN_MAX_EMAIL_LEN + + char* buf = (char*)alloca(sizeof(sttP2PheaderV2) + MSN_MAX_EMAIL_LEN + 120 + fportion); size_t offset = 0; - do - { + do { size_t portion = msgsz - offset; if (portion > fportion) portion = fportion; @@ -328,48 +316,39 @@ void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, p += msgType == 1 ? sizeof(unsigned) : sprintf(p, hdrdata.isV2Hdr() ? sttP2PheaderV2 : sttP2Pheader, wlid, MyOptions.szEmail, MyOptions.szMachineGuidP2P); //!!!!!!!!!!! - if (hdrdata.isV2Hdr()) - { + if (hdrdata.isV2Hdr()) { P2PV2_Header *ph = (P2PV2_Header*)&hdrdata; - if (offset == 0) - { - if (!info || !info->mBridgeInit) - { - if (info && ph->mSessionID) - { + if (offset == 0) { + if (!info || !info->mBridgeInit) { + if (info && ph->mSessionID) { P2PV2_Header tHdr; tHdr.mID = ph->mID; p2p_sendMsg(info, wlid, 0, tHdr, NULL, 0); } - else - { + else { ph->mOpCode |= ph->mAckUniqueID && msgType != 1 ? 1 : 3; ph->mCap = p2pV2Caps; if (info) info->mBridgeInit = true; } } } - else - { + else { ph->mOpCode = 0; ph->mCap = NULL; } } - if (msgsz) - { - if (hdrdata.isV2Hdr()) - { + if (msgsz) { + if (hdrdata.isV2Hdr()) { P2PV2_Header *ph = (P2PV2_Header*)&hdrdata; ph->mPacketLen = (unsigned)portion; ph->mRemSize = msgsz - offset - portion; - ph->mTFCode = offset ? ph->mTFCode & 0xfe : ph->mTFCode | 0x01; + ph->mTFCode = offset ? ph->mTFCode & 0xfe : ph->mTFCode | 0x01; if (offset == 0) ph->mPacketNum = p2p_getPktNum(wlid); } - else - { + else { P2P_Header *ph = (P2P_Header*)&hdrdata; ph->mPacketLen = (unsigned)portion; ph->mOffset = offset; @@ -385,15 +364,13 @@ void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, memcpy(p, msgbody + offset, portion); p += portion; // add message footer - if (msgType != 1) - { + if (msgType != 1) { *(unsigned*)p = _htonl(appId); p += 4; } char* szEmail; - switch (msgType) - { + switch (msgType) { case 0: parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); MsgQueue_Add(szEmail, 'D', buf, p - buf); @@ -409,8 +386,7 @@ void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, break; } offset += portion; - } - while (offset < msgsz); + } while (offset < msgsz); } @@ -418,8 +394,7 @@ void CMsnProto::p2p_sendAck(const char *wlid, P2PB_Header* hdr) { if (hdr == NULL) return; - if (!hdr->isV2Hdr()) - { + if (!hdr->isV2Hdr()) { P2P_Header *hdrdata = (P2P_Header*)hdr; P2P_Header tHdr; @@ -431,8 +406,7 @@ void CMsnProto::p2p_sendAck(const char *wlid, P2PB_Header* hdr) p2p_sendMsg(wlid, 0, tHdr, NULL, 0); } - else - { + else { P2PV2_Header *hdrdata = (P2PV2_Header*)hdr; P2PV2_Header tHdr; @@ -448,8 +422,7 @@ void CMsnProto::p2p_sendAck(const char *wlid, P2PB_Header* hdr) void CMsnProto::p2p_sendAbortSession(filetransfer* ft) { - if (ft == NULL) - { + if (ft == NULL) { debugLogA(sttVoidSession); return; } @@ -462,13 +435,11 @@ void CMsnProto::p2p_sendAbortSession(filetransfer* ft) tHdr.mAckSessionID = ft->p2p_sendmsgid; tHdr.mID = p2p_getMsgId(ft->p2p_dest, 1); - if (ft->std.flags & PFTS_SENDING) - { + if (ft->std.flags & PFTS_SENDING) { tHdr.mFlags = 0x40; tHdr.mAckSessionID = tHdr.mID - 2; } - else - { + else { tHdr.mAckUniqueID = 0x8200000f; tHdr.mFlags = 0x80; tHdr.mAckDataSize = ft->std.currentFileSize; @@ -480,8 +451,7 @@ void CMsnProto::p2p_sendAbortSession(filetransfer* ft) void CMsnProto::p2p_sendRedirect(filetransfer* ft) { - if (ft == NULL) - { + if (ft == NULL) { debugLogA(sttVoidSession); return; } @@ -508,8 +478,7 @@ void CMsnProto::p2p_sendRedirect(filetransfer* ft) void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders, MimeHeaders &pContent, const char *wlid) { - if (ft == NULL) - { + if (ft == NULL) { debugLogA(sttVoidSession); return; } @@ -522,35 +491,31 @@ void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders, char* buf = (char*)alloca(pHeaders.getLength() + cbContLen + 512); char* p = buf; - switch (iKind) - { - case -3: p += sprintf(p, "ACK MSNMSGR:%s MSNSLP/1.0", wlid); break; //!!!!!!!!!!!!!!!!!! - case -2: p += sprintf(p, "INVITE MSNMSGR:%s MSNSLP/1.0", wlid); break; //!!!!!!!!!!!!!!!!!! - case -1: p += sprintf(p, "BYE MSNMSGR:%s MSNSLP/1.0", wlid); break; //!!!!!!!!!!!!!!!!!! - case 200: p += sprintf(p, "MSNSLP/1.0 200 OK"); break; //!!!!!!!!!!!!!!!!!! - case 481: p += sprintf(p, "MSNSLP/1.0 481 No Such Call"); break; //!!!!!!!!!!!!!!!!!! - case 500: p += sprintf(p, "MSNSLP/1.0 500 Internal Error"); break; //!!!!!!!!!!!!!!!!!! - case 603: p += sprintf(p, "MSNSLP/1.0 603 DECLINE"); break; //!!!!!!!!!!!!!!!!!! - case 1603: p += sprintf(p, "MSNSLP/1.0 603 Decline"); break; //!!!!!!!!!!!!!!!!!! - default: return; - } - - if (iKind < 0) - { + switch (iKind) { + case -3: p += sprintf(p, "ACK MSNMSGR:%s MSNSLP/1.0", wlid); break; //!!!!!!!!!!!!!!!!!! + case -2: p += sprintf(p, "INVITE MSNMSGR:%s MSNSLP/1.0", wlid); break; //!!!!!!!!!!!!!!!!!! + case -1: p += sprintf(p, "BYE MSNMSGR:%s MSNSLP/1.0", wlid); break; //!!!!!!!!!!!!!!!!!! + case 200: p += sprintf(p, "MSNSLP/1.0 200 OK"); break; //!!!!!!!!!!!!!!!!!! + case 481: p += sprintf(p, "MSNSLP/1.0 481 No Such Call"); break; //!!!!!!!!!!!!!!!!!! + case 500: p += sprintf(p, "MSNSLP/1.0 500 Internal Error"); break; //!!!!!!!!!!!!!!!!!! + case 603: p += sprintf(p, "MSNSLP/1.0 603 DECLINE"); break; //!!!!!!!!!!!!!!!!!! + case 1603: p += sprintf(p, "MSNSLP/1.0 603 Decline"); break; //!!!!!!!!!!!!!!!!!! + default: return; + } + + if (iKind < 0) { mir_free(ft->p2p_branch); ft->p2p_branch = getNewUuid(); } - if (ft->p2p_isV2) - { + if (ft->p2p_isV2) { p += sprintf(p, "\r\nTo: \r\n" "From: \r\n" "Via: MSNSLP/1.0/TLP ;branch=%s\r\n", wlid, MyOptions.szEmail, MyOptions.szMachineGuidP2P, ft->p2p_branch); //!!!!!!!!!!!!!!!!!! } - else - { + else { p += sprintf(p, "\r\nTo: \r\n" "From: \r\n" @@ -565,26 +530,22 @@ void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders, if (!(myFlags & cap_SupportsP2PBootstrap) || ft->p2p_sessionid || MSN_GetThreadByContact(wlid, SERVER_P2P_DIRECT) || status == ID_STATUS_OFFLINE || status == ID_STATUS_INVISIBLE || - m_iStatus == ID_STATUS_INVISIBLE) - { - if (!ft->p2p_isV2) - { + m_iStatus == ID_STATUS_INVISIBLE) { + if (!ft->p2p_isV2) { P2P_Header tHdr; tHdr.mAckSessionID = ft->p2p_acksessid; p2p_sendMsg(wlid, 0, tHdr, buf, p - buf + 1); ft->p2p_waitack = true; - switch (iKind) - { + switch (iKind) { case -1: case 500: case 603: - ft->p2p_byemsgid = tHdr.mID; + ft->p2p_byemsgid = tHdr.mID; break; } } - else - { + else { P2PV2_Header tHdr; tHdr.mTFCode = 0x01; @@ -602,8 +563,7 @@ void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders, void CMsnProto::p2p_sendBye(filetransfer* ft) { - if (ft == NULL) - { + if (ft == NULL) { debugLogA(sttVoidSession); return; } @@ -629,8 +589,7 @@ void CMsnProto::p2p_sendCancel(filetransfer* ft) void CMsnProto::p2p_sendNoCall(filetransfer* ft) { - if (ft == NULL) - { + if (ft == NULL) { debugLogA(sttVoidSession); return; } @@ -653,8 +612,7 @@ void CMsnProto::p2p_sendNoCall(filetransfer* ft) void CMsnProto::p2p_sendStatus(filetransfer* ft, long lStatus) { - if (ft == NULL) - { + if (ft == NULL) { debugLogA(sttVoidSession); return; } @@ -667,8 +625,7 @@ void CMsnProto::p2p_sendStatus(filetransfer* ft, long lStatus) MimeHeaders chdrs(2); chdrs.addULong("SessionID", ft->p2p_sessionid); - if (lStatus != 1603) - { + if (lStatus != 1603) { tHeaders.addString("Content-Type", "application/x-msnmsgr-sessionreqbody"); chdrs.addString("SChannelState", "0"); @@ -683,15 +640,13 @@ void CMsnProto::p2p_sendAvatarInit(filetransfer* ft) { unsigned body = 0; - if (ft->p2p_isV2) - { + if (ft->p2p_isV2) { P2PV2_Header tHdr; tHdr.mSessionID = ft->p2p_sessionid; tHdr.mTFCode = 0x01; p2p_sendMsg(ft->p2p_dest, ft->p2p_appID, tHdr, (char*)&body, sizeof(body)); } - else - { + else { P2P_Header tHdr; tHdr.mSessionID = ft->p2p_sessionid; tHdr.mAckSessionID = ft->p2p_acksessid; @@ -706,7 +661,7 @@ void CMsnProto::p2p_sendAvatarInit(filetransfer* ft) ///////////////////////////////////////////////////////////////////////////////////////// // p2p_connectTo - connects to a remote P2P server -static const char p2p_greeting[8] = { 4, 0, 0, 0, 'f', 'o', 'o', 0 }; +static const char p2p_greeting[8] = { 4, 0, 0, 0, 'f', 'o', 'o', 0 }; static void sttSendPacket(ThreadData* T, void* hdr, unsigned len) { @@ -716,15 +671,14 @@ static void sttSendPacket(ThreadData* T, void* hdr, unsigned len) bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc) { - NETLIBOPENCONNECTION tConn = {0}; + NETLIBOPENCONNECTION tConn = { 0 }; tConn.cbSize = sizeof(tConn); tConn.szHost = info->mServer; tConn.flags = NLOCF_V2; tConn.timeout = 5; char* tPortDelim = strrchr(info->mServer, ':'); - if (tPortDelim != NULL) - { + if (tPortDelim != NULL) { *tPortDelim = '\0'; tConn.wPort = (WORD)atol(tPortDelim + 1); } @@ -732,8 +686,7 @@ bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc) debugLogA("Connecting to %s:%d", tConn.szHost, tConn.wPort); info->s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&tConn); - if (info->s == NULL) - { + if (info->s == NULL) { TWinErrorCode err; debugLogA("Connection Failed (%d): %s", err.mErrorCode, err.getText()); return false; @@ -743,8 +696,7 @@ bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc) bool isV2 = strchr(info->mInitialContactWLID, ';') != NULL; P2P_Header reply; - if (!isV2) - { + if (!isV2) { reply.mFlags = 0x100; if (dc->useHashedNonce) @@ -762,8 +714,7 @@ bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc) long cbPacketLen; HReadBuffer buf(info, 0); BYTE* p; - if ((p = buf.surelyRead(4)) == NULL) - { + if ((p = buf.surelyRead(4)) == NULL) { debugLogA("Error reading data, closing filetransfer"); return false; } @@ -774,12 +725,10 @@ bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc) bool cookieMatch; - if (!isV2) - { + if (!isV2) { P2P_Header cookie((char*)p); - if (dc->useHashedNonce) - { + if (dc->useHashedNonce) { char* hnonce = dc->calcHashedNonce((UUID*)&cookie.mAckSessionID); cookieMatch = strcmp(hnonce, dc->xNonce) == 0; mir_free(hnonce); @@ -787,15 +736,13 @@ bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc) else cookieMatch = memcmp(&cookie.mAckSessionID, &reply.mAckSessionID, sizeof(UUID)) == 0; } - else - { + else { char* hnonce = dc->calcHashedNonce((UUID*)p); cookieMatch = strcmp(hnonce, dc->xNonce) == 0; mir_free(hnonce); } - if (!cookieMatch) - { + if (!cookieMatch) { debugLogA("Invalid cookie received, exiting"); return false; } @@ -808,8 +755,7 @@ bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc) bool CMsnProto::p2p_listen(ThreadData* info, directconnection *dc) { - switch(WaitForSingleObject(info->hWaitEvent, 10000)) - { + switch (WaitForSingleObject(info->hWaitEvent, 10000)) { case WAIT_TIMEOUT: case WAIT_FAILED: debugLogA("Incoming connection timed out, closing file transfer"); @@ -825,14 +771,12 @@ LBL_Error: if ((p = buf.surelyRead(8)) == NULL) goto LBL_Error; - if (memcmp(p, p2p_greeting, 8) != 0) - { + if (memcmp(p, p2p_greeting, 8) != 0) { debugLogA("Invalid input data, exiting"); return false; } - if ((p = buf.surelyRead(4)) == NULL) - { + if ((p = buf.surelyRead(4)) == NULL) { debugLogA("Error reading data, closing filetransfer"); return false; } @@ -844,12 +788,10 @@ LBL_Error: bool cookieMatch; bool isV2 = strchr(info->mInitialContactWLID, ';') != NULL; - if (!isV2) - { + if (!isV2) { P2P_Header cookie((char*)p); - if (dc->useHashedNonce) - { + if (dc->useHashedNonce) { char* hnonce = dc->calcHashedNonce((UUID*)&cookie.mAckSessionID); cookieMatch = strcmp(hnonce, dc->xNonce) == 0; mir_free(hnonce); @@ -858,8 +800,7 @@ LBL_Error: else cookieMatch = memcmp(&cookie.mAckSessionID, dc->mNonce, sizeof(UUID)) == 0; - if (!cookieMatch) - { + if (!cookieMatch) { debugLogA("Invalid cookie received, exiting"); return false; } @@ -868,14 +809,12 @@ LBL_Error: cookie.createMsg(buf, info->mInitialContactWLID, this); sttSendPacket(info, buf, sizeof(buf)); } - else - { + else { char* hnonce = dc->calcHashedNonce((UUID*)p); cookieMatch = strcmp(hnonce, dc->xNonce) == 0; mir_free(hnonce); - if (!cookieMatch) - { + if (!cookieMatch) { debugLogA("Invalid cookie received, exiting"); goto LBL_Error; } @@ -905,8 +844,7 @@ LONG CMsnProto::p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2) else p += sizeof(unsigned); - if (!isV2) - { + if (!isV2) { // Fill P2P header P2P_Header H; @@ -920,8 +858,7 @@ LONG CMsnProto::p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2) p = H.createMsg(p, ft->p2p_dest, this); } - else - { + else { P2PV2_Header H; H.mSessionID = ft->p2p_sessionid; @@ -944,8 +881,7 @@ LONG CMsnProto::p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2) if (T->mType == SERVER_P2P_DIRECT) trid = T->send(databuf, p - databuf); - else - { + else { // Define packet footer for server transfer *(unsigned*)p = _htonl(ft->p2p_appID); p += sizeof(unsigned); @@ -953,12 +889,10 @@ LONG CMsnProto::p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2) trid = T->sendRawMessage('D', (char *)databuf, p - databuf); } - if (trid != 0) - { + if (trid != 0) { ft->std.totalProgress += portion; ft->std.currentFileProgress += portion; - if (ft->p2p_appID == MSN_APPID_FILE && clock() >= ft->nNotify) - { + if (ft->p2p_appID == MSN_APPID_FILE && clock() >= ft->nNotify) { ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); ft->nNotify = clock() + 500; } @@ -985,8 +919,7 @@ void __cdecl CMsnProto::p2p_sendFeedThread(void* arg) debugLogA("File send thread started"); - switch(WaitForSingleObject(info->hWaitEvent, 6000)) - { + switch (WaitForSingleObject(info->hWaitEvent, 6000)) { case WAIT_FAILED: debugLogA("File send wait failed"); return; @@ -999,14 +932,12 @@ void __cdecl CMsnProto::p2p_sendFeedThread(void* arg) filetransfer *ft = p2p_getSessionByCallID(info->mCookie, info->mJoinedIdentContactsWLID.getCount() ? info->mJoinedIdentContactsWLID[0] : info->mJoinedContactsWLID[0]); - if (ft != NULL && WaitForSingleObject(ft->hLockHandle, 2000) == WAIT_OBJECT_0) - { + if (ft != NULL && WaitForSingleObject(ft->hLockHandle, 2000) == WAIT_OBJECT_0) { hLockHandle = ft->hLockHandle; if (isV2) ft->p2p_sendmsgid = p2p_getPktNum(ft->p2p_dest); - else - { + else { if (ft->p2p_sendmsgid == 0) ft->p2p_sendmsgid = p2p_getMsgId(ft->p2p_dest, 1); } @@ -1022,18 +953,15 @@ void __cdecl CMsnProto::p2p_sendFeedThread(void* arg) bool fault = false; while (WaitForSingleObject(hLockHandle, 2000) == WAIT_OBJECT_0 && - ft->std.currentFileProgress < ft->std.currentFileSize && !ft->bCanceled) - { + ft->std.currentFileProgress < ft->std.currentFileSize && !ft->bCanceled) { if (ft->tType != lastType) T = MSN_GetThreadByContact(ft->p2p_dest, ft->tType); if (ft->bCanceled) break; bool cfault = (T == NULL || p2p_sendPortion(ft, T, isV2) == 0); - if (cfault) - { - if (fault) - { + if (cfault) { + if (fault) { debugLogA("File send failed"); break; } @@ -1052,10 +980,8 @@ void __cdecl CMsnProto::p2p_sendFeedThread(void* arg) if (ft->p2p_appID == MSN_APPID_FILE) ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); - if (isV2) - { - if (!ft->bCanceled) - { + if (isV2) { + if (!ft->bCanceled) { ft->bCompleted = true; p2p_sendBye(ft); } @@ -1068,8 +994,7 @@ void __cdecl CMsnProto::p2p_sendFeedThread(void* arg) void CMsnProto::p2p_sendFeedStart(filetransfer* ft) { - if (ft->std.flags & PFTS_SENDING) - { + if (ft->std.flags & PFTS_SENDING) { ThreadData* newThread = new ThreadData; newThread->mType = SERVER_FILETRANS; strcpy(newThread->mCookie, ft->p2p_callID); @@ -1098,8 +1023,7 @@ void CMsnProto::p2p_sendRecvFileDirectly(ThreadData* info) bool isV2 = strchr(wlid, ';') != NULL; - for (;;) - { + for (;;) { long len = state ? cbPacketLen : 4; BYTE* p = buf.surelyRead(len); @@ -1132,12 +1056,10 @@ void __cdecl CMsnProto::p2p_fileActiveThread(void* arg) debugLogA("p2p_fileActiveThread() started: connecting to '%s'", info->mServer); directconnection *dc = p2p_getDCByCallID(info->mCookie, info->mInitialContactWLID); - if (dc) - { + if (dc) { if (p2p_connectTo(info, dc)) p2p_sendRecvFileDirectly(info); - else - { + else { mir_free(info->mInitialContactWLID); info->mInitialContactWLID = NULL; } @@ -1156,12 +1078,10 @@ void __cdecl CMsnProto::p2p_filePassiveThread(void* arg) debugLogA("p2p_filePassiveThread() started: listening"); directconnection *dc = p2p_getDCByCallID(info->mCookie, info->mInitialContactWLID); - if (dc) - { + if (dc) { if (p2p_listen(info, dc)) p2p_sendRecvFileDirectly(info); - else - { + else { mir_free(info->mInitialContactWLID); info->mInitialContactWLID = NULL; } @@ -1183,7 +1103,7 @@ void CMsnProto::p2p_InitFileTransfer( return; const char *szCallID = tFileInfo["Call-ID"], - *szBranch = tFileInfo["Via"]; + *szBranch = tFileInfo["Via"]; if (szBranch != NULL) { szBranch = strstr(szBranch, "branch="); @@ -1196,12 +1116,11 @@ void CMsnProto::p2p_InitFileTransfer( } const char *szSessionID = tFileInfo2["SessionID"], - *szEufGuid = tFileInfo2["EUF-GUID"], - *szContext = tFileInfo2["Context"], - *szAppId = tFileInfo2["AppID"]; + *szEufGuid = tFileInfo2["EUF-GUID"], + *szContext = tFileInfo2["Context"], + *szAppId = tFileInfo2["AppID"]; - if (szSessionID == NULL || szAppId == NULL || szEufGuid == NULL) - { + if (szSessionID == NULL || szAppId == NULL || szEufGuid == NULL) { debugLogA("Ignoring invalid invitation: SessionID='%s', AppID=%s, Branch='%s',Context='%s'", szSessionID, szAppId, szEufGuid, szContext); return; @@ -1229,30 +1148,26 @@ void CMsnProto::p2p_InitFileTransfer( p2p_registerSession(ft); - switch (dwAppID) - { + switch (dwAppID) { case MSN_APPID_AVATAR: case MSN_APPID_AVATAR2: if (!_stricmp(szEufGuid, "{A4268EEC-FEC5-49E5-95C3-F126696BDBF6}")) { DBVARIANT dbv; bool pictmatch = !getString("PictObject", &dbv); - if (pictmatch) - { + if (pictmatch) { UrlDecode(dbv.pszVal); ezxml_t xmlcon = ezxml_parse_str((char*)szContext, strlen(szContext)); ezxml_t xmldb = ezxml_parse_str(dbv.pszVal, strlen(dbv.pszVal)); const char *szCtBuf = ezxml_attr(xmlcon, "SHA1C"); - if (szCtBuf) - { - const char *szPtBuf = ezxml_attr(xmldb, "SHA1C"); + if (szCtBuf) { + const char *szPtBuf = ezxml_attr(xmldb, "SHA1C"); pictmatch = szPtBuf && strcmp(szCtBuf, szPtBuf) == 0; } - else - { + else { const char *szCtBuf = ezxml_attr(xmlcon, "SHA1D"); - const char *szPtBuf = ezxml_attr(xmldb, "SHA1D"); + const char *szPtBuf = ezxml_attr(xmldb, "SHA1D"); pictmatch = szCtBuf && szPtBuf && strcmp(szCtBuf, szPtBuf) == 0; } @@ -1260,23 +1175,20 @@ void CMsnProto::p2p_InitFileTransfer( ezxml_free(xmldb); db_free(&dbv); } - if (pictmatch) - { + if (pictmatch) { TCHAR szFileName[MAX_PATH]; MSN_GetAvatarFileName(NULL, szFileName, SIZEOF(szFileName), NULL); ft->fileId = _topen(szFileName, O_RDONLY | _O_BINARY, _S_IREAD); - if (ft->fileId == -1) - { + if (ft->fileId == -1) { p2p_sendStatus(ft, 603); MSN_ShowError("Your avatar not set correctly. Avatar should be set in View/Change My Details | Avatar"); debugLogA("Unable to open avatar file '%s', error %d", szFileName, errno); p2p_unregisterSession(ft); } - else - { + else { mir_free(ft->std.tszCurrentFile); ft->std.tszCurrentFile = mir_tstrdup(szFileName); -// debugLogA("My avatar file opened for %s as %08p::%d", szEmail, ft, ft->fileId); + // debugLogA("My avatar file opened for %s as %08p::%d", szEmail, ft, ft->fileId); ft->std.totalBytes = ft->std.currentFileSize = _filelengthi64(ft->fileId); ft->std.flags |= PFTS_SENDING; @@ -1284,15 +1196,13 @@ void CMsnProto::p2p_InitFileTransfer( p2p_sendStatus(ft, 200); p2p_sendFeedStart(ft); - if (ft->p2p_isV2) - { + if (ft->p2p_isV2) { p2p_sendAvatarInit(ft); MSN_StartP2PTransferByContact(ft->p2p_dest); } } } - else - { + else { p2p_sendStatus(ft, 603); debugLogA("Requested avatar does not match current avatar"); p2p_unregisterSession(ft); @@ -1301,13 +1211,10 @@ void CMsnProto::p2p_InitFileTransfer( break; case MSN_APPID_FILE: - if (!_stricmp(szEufGuid, "{5D3E02AB-6190-11D3-BBBB-00C04F795683}")) - { + if (!_stricmp(szEufGuid, "{5D3E02AB-6190-11D3-BBBB-00C04F795683}")) { wchar_t* wszFileName = ((HFileContext*)szContext)->wszFileName; - for (wchar_t* p = wszFileName; *p != 0; p++) - { - switch(*p) - { + for (wchar_t* p = wszFileName; *p != 0; p++) { + switch (*p) { case ':': case '?': case '/': case '\\': case '*': *p = '_'; } @@ -1322,7 +1229,7 @@ void CMsnProto::p2p_InitFileTransfer( TCHAR tComment[40]; mir_sntprintf(tComment, SIZEOF(tComment), TranslateT("%I64u bytes"), ft->std.currentFileSize); - PROTORECVFILET pre = {0}; + PROTORECVFILET pre = { 0 }; pre.flags = PREF_TCHAR; pre.fileCount = 1; pre.timestamp = time(NULL); @@ -1349,9 +1256,9 @@ void CMsnProto::p2p_InitFileTransfer( break; case MSN_APPID_MEDIA_SHARING: -// MSN_ShowPopup(ft->std.hContact, -// TranslateT("Contact tried to share media with us (not currently supported)"), -// MSN_ALLOW_MSGBOX | MSN_SHOW_ERROR); + // MSN_ShowPopup(ft->std.hContact, + // TranslateT("Contact tried to share media with us (not currently supported)"), + // MSN_ALLOW_MSGBOX | MSN_SHOW_ERROR); p2p_sendStatus(ft, 603); p2p_unregisterSession(ft); break; @@ -1368,36 +1275,32 @@ void CMsnProto::p2p_InitFileTransfer( void CMsnProto::p2p_InitDirectTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid) { - const char *szCallID = tFileInfo["Call-ID"], - *szBranch = tFileInfo["Via"], - *szConnType = tFileInfo2["Conn-Type"], - *szUPnPNat = tFileInfo2["UPnPNat"], - *szNetID = tFileInfo2["NetID"], - *szICF = tFileInfo2["ICF"], - *szHashedNonce = tFileInfo2["Hashed-Nonce"]; - - if (szBranch != NULL) - { + const char *szCallID = tFileInfo["Call-ID"], + *szBranch = tFileInfo["Via"], + *szConnType = tFileInfo2["Conn-Type"], + *szUPnPNat = tFileInfo2["UPnPNat"], + *szNetID = tFileInfo2["NetID"], + *szICF = tFileInfo2["ICF"], + *szHashedNonce = tFileInfo2["Hashed-Nonce"]; + + if (szBranch != NULL) { szBranch = strstr(szBranch, "branch="); if (szBranch != NULL) szBranch += 7; } - if (szCallID == NULL || szBranch == NULL) - { + if (szCallID == NULL || szBranch == NULL) { debugLogA("Ignoring invalid invitation: CallID='%s', Branch='%s'", szCallID, szBranch); return; } - if (szConnType == NULL || szUPnPNat == NULL || szICF == NULL || szNetID == NULL) - { + if (szConnType == NULL || szUPnPNat == NULL || szICF == NULL || szNetID == NULL) { debugLogA("Ignoring invalid invitation: ConnType='%s', UPnPNat='%s', ICF='%s', NetID='%s'", szConnType, szUPnPNat, szICF, szNetID); return; } filetransfer ftl(this), *ft = p2p_getSessionByCallID(szCallID, wlid); - if (!ft || !ft->p2p_sessionid) - { + if (!ft || !ft->p2p_sessionid) { ft = &ftl; replaceStr(ft->p2p_dest, wlid); replaceStr(ft->p2p_callID, szCallID); @@ -1405,27 +1308,24 @@ void CMsnProto::p2p_InitDirectTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFil ft->p2p_isV2 = strchr(wlid, ';') != NULL; ft->std.hContact = MSN_HContactFromEmail(wlid); } - else - { + else { replaceStr(ft->p2p_callID, szCallID); replaceStr(ft->p2p_branch, szBranch); ft->p2p_acksessid = MSN_GenRandom(); -/* - if (p2p_isAvatarOnly(ft->std.hContact)) - { - p2p_sendStatus(ft, 1603); - return; - } - else - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0); -*/ + /* + if (p2p_isAvatarOnly(ft->std.hContact)) + { + p2p_sendStatus(ft, 1603); + return; + } + else + ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0); + */ } directconnection *dc = p2p_getDCByCallID(szCallID, wlid); - if (dc) - { - if (MSN_GetThreadByContact(wlid, SERVER_P2P_DIRECT)) - { + if (dc) { + if (MSN_GetThreadByContact(wlid, SERVER_P2P_DIRECT)) { p2p_sendStatus(ft, 1603); p2p_unregisterDC(dc); return; @@ -1444,7 +1344,7 @@ void CMsnProto::p2p_InitDirectTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFil tResult.addString("Call-ID", szCallID); tResult.addLong("Max-Forwards", 0); - MyConnectionType conType = {0}; + MyConnectionType conType = { 0 }; conType.extIP = atol(szNetID); conType.SetUdpCon(szConnType); @@ -1459,8 +1359,7 @@ void CMsnProto::p2p_InitDirectTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFil if (conType.weight <= MyConnection.weight) listen = p2p_createListener(ft, dc, chdrs); - if (!listen) - { + if (!listen) { chdrs.addString("Bridge", "TCPv1"); chdrs.addBool("Listening", false); @@ -1486,14 +1385,12 @@ void CMsnProto::p2p_startConnect(const char* wlid, const char* szCallID, const c if (port == NULL) return; char *pPortTokBeg = (char*)port; - for (;;) - { + for (;;) { char *pPortTokEnd = strchr(pPortTokBeg, ' '); if (pPortTokEnd != NULL) *pPortTokEnd = 0; char *pAddrTokBeg = (char*)addr; - for (;;) - { + for (;;) { char *pAddrTokEnd = strchr(pAddrTokBeg, ' '); if (pAddrTokEnd != NULL) *pAddrTokEnd = 0; @@ -1522,26 +1419,24 @@ void CMsnProto::p2p_startConnect(const char* wlid, const char* szCallID, const c void CMsnProto::p2p_InitDirectTransfer2(MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid) { - const char *szCallID = tFileInfo["Call-ID"], - *szInternalAddress = tFileInfo2["IPv4Internal-Addrs"], - *szInternalPort = tFileInfo2["IPv4Internal-Port"], - *szExternalAddress = tFileInfo2["IPv4External-Addrs"], - *szExternalPort = tFileInfo2["IPv4External-Port"], - *szNonce = tFileInfo2["Nonce"], - *szHashedNonce = tFileInfo2["Hashed-Nonce"], - *szListening = tFileInfo2["Listening"], - *szV6Address = tFileInfo2["IPv6-Addrs"], - *szV6Port = tFileInfo2["IPv6-Port" ]; - - if ((szNonce == NULL && szHashedNonce == NULL) || szListening == NULL) - { + const char *szCallID = tFileInfo["Call-ID"], + *szInternalAddress = tFileInfo2["IPv4Internal-Addrs"], + *szInternalPort = tFileInfo2["IPv4Internal-Port"], + *szExternalAddress = tFileInfo2["IPv4External-Addrs"], + *szExternalPort = tFileInfo2["IPv4External-Port"], + *szNonce = tFileInfo2["Nonce"], + *szHashedNonce = tFileInfo2["Hashed-Nonce"], + *szListening = tFileInfo2["Listening"], + *szV6Address = tFileInfo2["IPv6-Addrs"], + *szV6Port = tFileInfo2["IPv6-Port"]; + + if ((szNonce == NULL && szHashedNonce == NULL) || szListening == NULL) { debugLogA("Ignoring invalid invitation: Listening='%s', Nonce=%s", szListening, szNonce); return; } directconnection* dc = p2p_getDCByCallID(szCallID, wlid); - if (dc == NULL) - { + if (dc == NULL) { dc = new directconnection(szCallID, wlid); p2p_registerDC(dc); } @@ -1549,8 +1444,7 @@ void CMsnProto::p2p_InitDirectTransfer2(MimeHeaders& tFileInfo, MimeHeaders& tFi dc->useHashedNonce = szHashedNonce != NULL; replaceStr(dc->xNonce, szHashedNonce ? szHashedNonce : szNonce); - if (!strcmp(szListening, "true") && strcmp(dc->xNonce, sttVoidUid)) - { + if (!strcmp(szListening, "true") && strcmp(dc->xNonce, sttVoidUid)) { p2p_startConnect(wlid, szCallID, szV6Address, szV6Port, true); p2p_startConnect(wlid, szCallID, szInternalAddress, szInternalPort, false); p2p_startConnect(wlid, szCallID, szExternalAddress, szExternalPort, false); @@ -1571,8 +1465,7 @@ void CMsnProto::p2p_AcceptTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFileInf filetransfer ftl(this), *ft = p2p_getSessionByCallID(szCallID, wlid); - if (!ft || !ft->p2p_sessionid) - { + if (!ft || !ft->p2p_sessionid) { ft = &ftl; replaceStr(ft->p2p_branch, szBranch); replaceStr(ft->p2p_callID, szCallID); @@ -1580,17 +1473,14 @@ void CMsnProto::p2p_AcceptTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFileInf ft->p2p_isV2 = strchr(wlid, ';') != NULL; ft->std.hContact = MSN_HContactFromEmail(wlid); } - else - { - if (!(ft->std.flags & PFTS_SENDING)) - { + else { + if (!(ft->std.flags & PFTS_SENDING)) { replaceStr(ft->p2p_branch, szBranch); replaceStr(ft->p2p_callID, szCallID); } } - if (szCallID == NULL || szBranch == NULL || szOldContentType == NULL) - { + if (szCallID == NULL || szBranch == NULL || szOldContentType == NULL) { debugLogA("Ignoring invalid invitation: CallID='%s', szBranch='%s'", szCallID, szBranch); LBL_Close: p2p_sendStatus(ft, 500); @@ -1604,24 +1494,20 @@ LBL_Close: MimeHeaders chdrs(12); - if (!strcmp(szOldContentType, "application/x-msnmsgr-sessionreqbody")) - { - if (ft == &ftl) - { + if (!strcmp(szOldContentType, "application/x-msnmsgr-sessionreqbody")) { + if (ft == &ftl) { p2p_sendCancel(ft); return; } - if (!ft->bAccepted) - { + if (!ft->bAccepted) { replaceStr(ft->p2p_dest, wlid); ft->bAccepted = true; } else return; - if (ft->p2p_type != MSN_APPID_FILE) - { + if (ft->p2p_type != MSN_APPID_FILE) { if (ft->fileId == -1) ft->create(); return; } @@ -1629,8 +1515,7 @@ LBL_Close: p2p_sendFeedStart(ft); ThreadData* T = MSN_GetP2PThreadByContact(ft->p2p_dest); - if (T != NULL && T->mType == SERVER_P2P_DIRECT) - { + if (T != NULL && T->mType == SERVER_P2P_DIRECT) { MSN_StartP2PTransferByContact(ft->p2p_dest); return; } @@ -1651,20 +1536,18 @@ LBL_Close: chdrs.addString("IPv6-global", GetGlobalIp(), 2); chdrs.addString("Hashed-Nonce", dc->mNonceToHash(), 2); } - else if (!strcmp(szOldContentType, "application/x-msnmsgr-transrespbody")) - { - const char *szListening = tFileInfo2["Listening"], - *szNonce = tFileInfo2["Nonce"], - *szHashedNonce = tFileInfo2["Hashed-Nonce"], - *szExternalAddress = tFileInfo2["IPv4External-Addrs"], - *szExternalPort = tFileInfo2["IPv4External-Port" ], - *szInternalAddress = tFileInfo2["IPv4Internal-Addrs"], - *szInternalPort = tFileInfo2["IPv4Internal-Port" ], - *szV6Address = tFileInfo2["IPv6-Addrs"], - *szV6Port = tFileInfo2["IPv6-Port" ]; - - if ((szNonce == NULL && szHashedNonce == NULL) || szListening == NULL) - { + else if (!strcmp(szOldContentType, "application/x-msnmsgr-transrespbody")) { + const char *szListening = tFileInfo2["Listening"], + *szNonce = tFileInfo2["Nonce"], + *szHashedNonce = tFileInfo2["Hashed-Nonce"], + *szExternalAddress = tFileInfo2["IPv4External-Addrs"], + *szExternalPort = tFileInfo2["IPv4External-Port"], + *szInternalAddress = tFileInfo2["IPv4Internal-Addrs"], + *szInternalPort = tFileInfo2["IPv4Internal-Port"], + *szV6Address = tFileInfo2["IPv6-Addrs"], + *szV6Port = tFileInfo2["IPv6-Port"]; + + if ((szNonce == NULL && szHashedNonce == NULL) || szListening == NULL) { debugLogA("Invalid data packet, exiting..."); goto LBL_Close; } @@ -1681,8 +1564,7 @@ LBL_Close: replaceStr(dc->xNonce, szHashedNonce ? szHashedNonce : szNonce); // another side reported that it will be a server. - if (!strcmp(szListening, "true") && (szNonce == NULL || strcmp(szNonce, sttVoidUid))) - { + if (!strcmp(szListening, "true") && (szNonce == NULL || strcmp(szNonce, sttVoidUid))) { p2p_startConnect(ft->p2p_dest, szCallID, szV6Address, szV6Port, true); p2p_startConnect(ft->p2p_dest, szCallID, szInternalAddress, szInternalPort, false); p2p_startConnect(ft->p2p_dest, szCallID, szExternalAddress, szExternalPort, false); @@ -1690,8 +1572,7 @@ LBL_Close: } // no, send a file via server - if (!p2p_createListener(ft, dc, chdrs)) - { + if (!p2p_createListener(ft, dc, chdrs)) { p2p_unregisterDC(dc); if (ft != &ftl) MSN_StartP2PTransferByContact(ft->p2p_dest); @@ -1702,14 +1583,12 @@ LBL_Close: tResult.addString("Content-Type", "application/x-msnmsgr-transrespbody"); } - else if (!strcmp(szOldContentType, "application/x-msnmsgr-transreqbody")) - { + else if (!strcmp(szOldContentType, "application/x-msnmsgr-transreqbody")) { const char *szHashedNonce = tFileInfo2["Hashed-Nonce"]; - const char *szNonce = tFileInfo2["Nonce"]; + const char *szNonce = tFileInfo2["Nonce"]; directconnection* dc = p2p_getDCByCallID(szCallID, wlid); - if (dc == NULL) - { + if (dc == NULL) { dc = new directconnection(szCallID, wlid); p2p_registerDC(dc); } @@ -1718,8 +1597,7 @@ LBL_Close: replaceStr(dc->xNonce, szHashedNonce ? szHashedNonce : szNonce); // no, send a file via server - if (!p2p_createListener(ft, dc, chdrs)) - { + if (!p2p_createListener(ft, dc, chdrs)) { p2p_unregisterDC(dc); MSN_StartP2PTransferByContact(ft->p2p_dest); return; @@ -1758,27 +1636,24 @@ void CMsnProto::p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdr char* peol = strstr(msgbody, "\r\n"); if (peol != NULL) - msgbody = peol+2; + msgbody = peol + 2; MimeHeaders tFileInfo, tFileInfo2; msgbody = tFileInfo.readFromBuffer(msgbody); msgbody = tFileInfo2.readFromBuffer(msgbody); const char* szContentType = tFileInfo["Content-Type"]; - if (szContentType == NULL) - { + if (szContentType == NULL) { debugLogA("Invalid or missing Content-Type field, exiting"); return; } - if (hdrdata && !hdrdata->isV2Hdr()) - { + if (hdrdata && !hdrdata->isV2Hdr()) { if (iMsgType == 2 || (iMsgType == 1 && !strcmp(szContentType, "application/x-msnmsgr-transreqbody"))) p2p_getMsgId(wlid, 1); } - switch(iMsgType) - { + switch (iMsgType) { case 1: if (!strcmp(szContentType, "application/x-msnmsgr-sessionreqbody")) p2p_InitFileTransfer(info, tFileInfo, tFileInfo2, wlid); @@ -1793,18 +1668,14 @@ void CMsnProto::p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdr break; case 3: - if (!strcmp(szContentType, "application/x-msnmsgr-sessionclosebody")) - { + if (!strcmp(szContentType, "application/x-msnmsgr-sessionclosebody")) { filetransfer* ft = p2p_getSessionByCallID(tFileInfo["Call-ID"], wlid); - if (ft != NULL) - { - if (ft->std.currentFileProgress < ft->std.currentFileSize) - { + if (ft != NULL) { + if (ft->std.currentFileProgress < ft->std.currentFileSize) { ft->bCanceled = true; p2p_sendAbortSession(ft); } - else - { + else { if (!(ft->std.flags & PFTS_SENDING)) ft->bCompleted = true; } @@ -1815,41 +1686,38 @@ void CMsnProto::p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdr break; case 4: - { - const char* szCallID = tFileInfo["Call-ID"]; + { + const char* szCallID = tFileInfo["Call-ID"]; -// application/x-msnmsgr-session-failure-respbody + // application/x-msnmsgr-session-failure-respbody - directconnection *dc = p2p_getDCByCallID(szCallID, wlid); - if (dc != NULL) - { - p2p_unregisterDC(dc); - break; - } + directconnection *dc = p2p_getDCByCallID(szCallID, wlid); + if (dc != NULL) { + p2p_unregisterDC(dc); + break; + } - filetransfer* ft = p2p_getSessionByCallID(szCallID, wlid); - if (ft == NULL) - break; + filetransfer* ft = p2p_getSessionByCallID(szCallID, wlid); + if (ft == NULL) + break; - ft->close(); - if (!(ft->std.flags & PFTS_SENDING)) _tremove(ft->std.tszCurrentFile); + ft->close(); + if (!(ft->std.flags & PFTS_SENDING)) _tremove(ft->std.tszCurrentFile); - p2p_unregisterSession(ft); - } - break; + p2p_unregisterSession(ft); + } + break; case 5: - if (!strcmp(szContentType, "application/x-msnmsgr-turnsetup")) - { -// tFileInfo2["ServerAddress"]; -// tFileInfo2["SessionUsername"]; -// tFileInfo2["SessionPassword"]; + if (!strcmp(szContentType, "application/x-msnmsgr-turnsetup")) { + // tFileInfo2["ServerAddress"]; + // tFileInfo2["SessionUsername"]; + // tFileInfo2["SessionPassword"]; } - else if (!strcmp(szContentType, "application/x-msnmsgr-transudpswitch")) - { -// tFileInfo2["IPv6AddrsAndPorts"]; -// tFileInfo2["IPv4ExternalAddrsAndPorts"]; -// tFileInfo2["IPv4InternalAddrsAndPorts"]; + else if (!strcmp(szContentType, "application/x-msnmsgr-transudpswitch")) { + // tFileInfo2["IPv6AddrsAndPorts"]; + // tFileInfo2["IPv4ExternalAddrsAndPorts"]; + // tFileInfo2["IPv4InternalAddrsAndPorts"]; } break; } @@ -1858,46 +1726,39 @@ void CMsnProto::p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdr ///////////////////////////////////////////////////////////////////////////////////////// // p2p_processMsg - processes all MSN P2P incoming messages -void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* wlid) +void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* wlid) { P2PV2_Header hdrdata; char *msg = hdrdata.parseMsg(msgbody); hdrdata.logHeader(this); - if (hdrdata.mSessionID == 0) - { - if (hdrdata.mPacketLen == 0) - { + if (hdrdata.mSessionID == 0) { + if (hdrdata.mPacketLen == 0) { if (hdrdata.mOpCode & 0x02) p2p_sendAck(wlid, &hdrdata); return; } - if (hdrdata.mRemSize || hdrdata.mTFCode == 0) - { + if (hdrdata.mRemSize || hdrdata.mTFCode == 0) { char msgid[128]; mir_snprintf(msgid, sizeof(msgid), "%s_%08x", wlid, hdrdata.mPacketNum); int idx; - if (hdrdata.mTFCode == 0x01) - { + if (hdrdata.mTFCode == 0x01) { const size_t portion = hdrdata.mPacketLen + (msg - msgbody); const size_t len = portion + hdrdata.mRemSize; idx = addCachedMsg(msgid, msgbody, 0, portion, len, false); } - else - { + else { size_t len = hdrdata.mPacketLen + hdrdata.mRemSize; size_t offset = getCachedMsgSize(msgid); if (offset >= len) offset -= len; idx = addCachedMsg(msgid, msg, offset, hdrdata.mPacketLen, len, false); } - if (hdrdata.mRemSize == 0) - { + if (hdrdata.mRemSize == 0) { size_t newsize; - if (getCachedMsg(idx, msgbody, newsize)) - { + if (getCachedMsg(idx, msgbody, newsize)) { unsigned id = hdrdata.mID; msg = hdrdata.parseMsg(msgbody); hdrdata.mID = id; @@ -1913,8 +1774,7 @@ void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* w clearCachedMsg(idx); } } - else - { + else { if (hdrdata.mOpCode & 0x02) p2p_sendAck(wlid, &hdrdata); @@ -1932,15 +1792,13 @@ void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* w ft->ts = time(NULL); - if (hdrdata.mTFCode >= 4 && hdrdata.mTFCode <= 7) - { + if (hdrdata.mTFCode >= 4 && hdrdata.mTFCode <= 7) { _write(ft->fileId, msg, hdrdata.mPacketLen); ft->std.totalProgress += hdrdata.mPacketLen; ft->std.currentFileProgress += hdrdata.mPacketLen; - if (ft->p2p_appID == MSN_APPID_FILE && clock() >= ft->nNotify) - { + if (ft->p2p_appID == MSN_APPID_FILE && clock() >= ft->nNotify) { ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); ft->nNotify = clock() + 500; @@ -1948,15 +1806,12 @@ void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* w debugLogA("Transferred %I64u bytes remaining %I64u", ft->std.currentFileProgress, hdrdata.mRemSize); } - if (hdrdata.mRemSize == 0) - { - if (ft->p2p_appID == MSN_APPID_FILE) - { + if (hdrdata.mRemSize == 0) { + if (ft->p2p_appID == MSN_APPID_FILE) { ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); ft->complete(); } - else - { + else { p2p_savePicture2disk(ft); if (!ft->p2p_isV2) p2p_sendBye(ft); } @@ -1964,21 +1819,19 @@ void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* w } } -void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wlid) +void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wlid) { P2P_Header hdrdata; msgbody = hdrdata.parseMsg(msgbody); hdrdata.logHeader(this); //---- if we got a message - if (LOWORD(hdrdata.mFlags) == 0 && hdrdata.mSessionID == 0) - { + if (LOWORD(hdrdata.mFlags) == 0 && hdrdata.mSessionID == 0) { // MsnContact *cont = Lists_Get(wlid); // if (cont && cont->places.getCount()) // return; - if (hdrdata.mPacketLen < hdrdata.mTotalSize) - { + if (hdrdata.mPacketLen < hdrdata.mTotalSize) { char msgid[128]; mir_snprintf(msgid, sizeof(msgid), "%s_%08x", wlid, hdrdata.mID); int idx = addCachedMsg(msgid, msgbody, (size_t)hdrdata.mOffset, hdrdata.mPacketLen, @@ -1986,20 +1839,17 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli char* newbody; size_t newsize; - if (getCachedMsg(idx, newbody, newsize)) - { + if (getCachedMsg(idx, newbody, newsize)) { p2p_sendAck(wlid, &hdrdata); p2p_processSIP(info, newbody, &hdrdata, wlid); mir_free(newbody); } - else - { + else { if (hdrdata.mOffset + hdrdata.mPacketLen >= hdrdata.mTotalSize) clearCachedMsg(idx); } } - else - { + else { p2p_sendAck(wlid, &hdrdata); p2p_processSIP(info, msgbody, &hdrdata, wlid); } @@ -2016,12 +1866,10 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli ft->ts = time(NULL); //---- receiving redirect ----------- - if (hdrdata.mFlags == 0x01) - { - if (WaitForSingleObject(ft->hLockHandle, INFINITE) == WAIT_OBJECT_0) - { + if (hdrdata.mFlags == 0x01) { + if (WaitForSingleObject(ft->hLockHandle, INFINITE) == WAIT_OBJECT_0) { __int64 dp = (__int64)(ft->std.currentFileProgress - hdrdata.mAckDataSize); - ft->std.totalProgress -= dp ; + ft->std.totalProgress -= dp; ft->std.currentFileProgress -= dp; _lseeki64(ft->fileId, ft->std.currentFileProgress, SEEK_SET); ft->tType = info->mType; @@ -2030,28 +1878,23 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli } //---- receiving ack ----------- - if (hdrdata.mFlags == 0x02) - { + if (hdrdata.mFlags == 0x02) { ft->p2p_waitack = false; - if (hdrdata.mAckSessionID == ft->p2p_sendmsgid) - { - if (ft->p2p_appID == MSN_APPID_FILE) - { + if (hdrdata.mAckSessionID == ft->p2p_sendmsgid) { + if (ft->p2p_appID == MSN_APPID_FILE) { ft->bCompleted = true; p2p_sendBye(ft); } return; } - if (hdrdata.mAckSessionID == ft->p2p_byemsgid) - { + if (hdrdata.mAckSessionID == ft->p2p_byemsgid) { p2p_sessionComplete(ft); return; } - switch(ft->p2p_ackID) - { + switch (ft->p2p_ackID) { case 1000: //---- send Data Preparation Message p2p_sendAvatarInit(ft); @@ -2067,12 +1910,10 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli return; } - if (LOWORD(hdrdata.mFlags) == 0) - { + if (LOWORD(hdrdata.mFlags) == 0) { //---- accept the data preparation message ------ // const unsigned* pLongs = (unsigned*)msgbody; - if (hdrdata.mPacketLen == 4 && hdrdata.mTotalSize == 4) - { + if (hdrdata.mPacketLen == 4 && hdrdata.mTotalSize == 4) { p2p_sendAck(ft->p2p_dest, &hdrdata); return; } @@ -2081,13 +1922,11 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli } //---- receiving data ----------- - if (LOWORD(hdrdata.mFlags) == 0x20 || LOWORD(hdrdata.mFlags) == 0x30) - { + if (LOWORD(hdrdata.mFlags) == 0x20 || LOWORD(hdrdata.mFlags) == 0x30) { if (hdrdata.mOffset + hdrdata.mPacketLen > hdrdata.mTotalSize) hdrdata.mPacketLen = DWORD(hdrdata.mTotalSize - hdrdata.mOffset); - if (ft->tTypeReq == 0 || ft->tTypeReq == info->mType) - { + if (ft->tTypeReq == 0 || ft->tTypeReq == info->mType) { ft->tType = info->mType; ft->p2p_sendmsgid = hdrdata.mID; } @@ -2095,10 +1934,8 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli __int64 dsz = ft->std.currentFileSize - hdrdata.mOffset; if (dsz > hdrdata.mPacketLen) dsz = hdrdata.mPacketLen; - if (ft->tType == info->mType) - { - if (dsz > 0 && ft->fileId >= 0) - { + if (ft->tType == info->mType) { + if (dsz > 0 && ft->fileId >= 0) { if (ft->lstFilePtr != hdrdata.mOffset) _lseeki64(ft->fileId, hdrdata.mOffset, SEEK_SET); _write(ft->fileId, msgbody, (unsigned int)dsz); @@ -2106,13 +1943,11 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli ft->lstFilePtr = hdrdata.mOffset + dsz; __int64 dp = ft->lstFilePtr - ft->std.currentFileProgress; - if (dp > 0) - { + if (dp > 0) { ft->std.totalProgress += dp; ft->std.currentFileProgress += dp; - if (ft->p2p_appID == MSN_APPID_FILE && clock() >= ft->nNotify) - { + if (ft->p2p_appID == MSN_APPID_FILE && clock() >= ft->nNotify) { ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); ft->nNotify = clock() + 500; } @@ -2122,18 +1957,15 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli debugLogA("Transferred %I64u bytes out of %I64u", ft->std.currentFileProgress, hdrdata.mTotalSize); } - if (ft->std.currentFileProgress >= hdrdata.mTotalSize) - { + if (ft->std.currentFileProgress >= hdrdata.mTotalSize) { ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); p2p_sendAck(ft->p2p_dest, &hdrdata); - if (ft->p2p_appID == MSN_APPID_FILE) - { + if (ft->p2p_appID == MSN_APPID_FILE) { ft->ts = time(NULL); ft->p2p_waitack = true; ft->complete(); } - else - { + else { p2p_savePicture2disk(ft); p2p_sendBye(ft); } @@ -2141,8 +1973,7 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli } } - if (hdrdata.mFlags == 0x40 || hdrdata.mFlags == 0x80) - { + if (hdrdata.mFlags == 0x40 || hdrdata.mFlags == 0x80) { p2p_sendAbortSession(ft); p2p_unregisterSession(ft); } @@ -2154,8 +1985,7 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wli void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) { const char* szAppID; - switch(iAppID) - { + switch (iAppID) { case MSN_APPID_FILE: szAppID = "{5D3E02AB-6190-11D3-BBBB-00C04F795683}"; break; case MSN_APPID_AVATAR: szAppID = "{A4268EEC-FEC5-49E5-95C3-F126696BDBF6}"; break; case MSN_APPID_CUSTOMSMILEY: szAppID = "{A4268EEC-FEC5-49E5-95C3-F126696BDBF6}"; break; @@ -2171,8 +2001,7 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) MsnContact* cont = Lists_Get(ft->std.hContact); if (cont == NULL) return; - if (ft->p2p_dest == NULL) - { + if (ft->p2p_dest == NULL) { ft->p2p_isV2 = (cont->cap2 & capex_SupportsPeerToPeerV2) != 0 || (cont->cap1 >> 28) >= 10; ft->p2p_dest = mir_strdup(wlid ? wlid : cont->email); } @@ -2180,21 +2009,18 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) char* pContext = NULL; size_t cbContext = 0; - switch (iAppID) - { + switch (iAppID) { case MSN_APPID_FILE: + cbContext = sizeof(HFileContext); + pContext = (char*)malloc(cbContext); { - cbContext = sizeof(HFileContext); - pContext = (char*)malloc(cbContext); HFileContext* ctx = (HFileContext*)pContext; memset(pContext, 0, cbContext); - if (ft->p2p_isV2) - { + if (ft->p2p_isV2) { cbContext -= 64; ctx->ver = 2; } - else - { + else { ctx->ver = 3; ctx->id = 0xffffffff; } @@ -2219,8 +2045,7 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) default: ft->p2p_appID = MSN_APPID_AVATAR2; - if (ft->p2p_object == NULL) - { + if (ft->p2p_object == NULL) { delete ft; return; } @@ -2254,7 +2079,7 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) ezxml_set_attr(xmlr, "SHA1C", p); pContext = ezxml_toxml(xmlr, false); - cbContext = strlen(pContext)+1; + cbContext = strlen(pContext) + 1; ezxml_free(xmlr); ezxml_free(xmlo); @@ -2263,18 +2088,14 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) } bool sessionExist = p2p_sessionRegistered(ft); - if (!sessionExist) - { + if (!sessionExist) { p2p_registerSession(ft); unsigned short status = getWord(ft->std.hContact, "Status", ID_STATUS_OFFLINE); if ((myFlags & 0x4000000) && cont->places.getCount() <= 1 && - status != ID_STATUS_OFFLINE && status != ID_STATUS_INVISIBLE && m_iStatus != ID_STATUS_INVISIBLE) - { - if (ft->p2p_isV2) - { - if (cont->places.getCount() && cont->places[0].cap1 & cap_SupportsP2PBootstrap) - { + status != ID_STATUS_OFFLINE && status != ID_STATUS_INVISIBLE && m_iStatus != ID_STATUS_INVISIBLE) { + if (ft->p2p_isV2) { + if (cont->places.getCount() && cont->places[0].cap1 & cap_SupportsP2PBootstrap) { char wlid[128]; mir_snprintf(wlid, SIZEOF(wlid), strcmp(cont->places[0].id, sttVoidUid) ? "%s;%s" : "%s", @@ -2289,11 +2110,9 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) return; } } - else - { + else { const char *wlid = cont->email; - if (cont->cap1 & cap_SupportsP2PBootstrap) - { + if (cont->cap1 & cap_SupportsP2PBootstrap) { if (!MSN_GetThreadByContact(wlid, SERVER_P2P_DIRECT)) p2p_inviteDc(ft, wlid); else @@ -2309,7 +2128,7 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) if (!ft->bAccepted) ft->p2p_sessionid = MSN_GenRandom(); - ptrA szContextEnc( mir_base64_encode((PBYTE)pContext, (unsigned)cbContext)); + ptrA szContextEnc(mir_base64_encode((PBYTE)pContext, (unsigned)cbContext)); int cbContextEnc = lstrlenA(szContextEnc); MimeHeaders chdrs(10); @@ -2327,10 +2146,8 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) if (iAppID != MSN_APPID_FILE) ft->p2p_waitack = true; - if (ft->p2p_isV2 && ft->std.currentFileNumber == 0) - { - for (int i = 0; i < cont->places.getCount(); ++i) - { + if (ft->p2p_isV2 && ft->std.currentFileNumber == 0) { + for (int i = 0; i < cont->places.getCount(); ++i) { char wlid[128]; mir_snprintf(wlid, SIZEOF(wlid), strcmp(cont->places[i].id, sttVoidUid) ? "%s;%s" : "%s", @@ -2339,8 +2156,7 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) p2p_sendSlp(-2, ft, tResult, chdrs, wlid); } } - else - p2p_sendSlp(-2, ft, tResult, chdrs, wlid); + else p2p_sendSlp(-2, ft, tResult, chdrs, wlid); free(pContext); } @@ -2372,6 +2188,7 @@ void CMsnProto::p2p_inviteDc(filetransfer* ft, const char *wlid) p2p_sendSlp(-2, ft, tResult, chdrs, wlid); } + /* void CMsnProto::p2p_sendSessionAck(filetransfer* ft) { @@ -2392,25 +2209,22 @@ void CMsnProto::p2p_sendSessionAck(filetransfer* ft) p2p_sendSlp(-3, ft, tResult, chdrs); } */ + void CMsnProto::p2p_sessionComplete(filetransfer* ft) { if (ft->p2p_appID != MSN_APPID_FILE) p2p_unregisterSession(ft); - else if (ft->std.flags & PFTS_SENDING) - { - if (ft->openNext() == -1) - { + else if (ft->std.flags & PFTS_SENDING) { + if (ft->openNext() == -1) { bool success = ft->std.currentFileNumber >= ft->std.totalFiles && ft->bCompleted; ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, success ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, ft, 0); } - else - { + else { ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0); p2p_invite(ft->p2p_appID, ft, NULL); } } - else - { + else { ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ft->bCompleted ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, ft, 0); p2p_unregisterSession(ft); } @@ -2425,10 +2239,8 @@ char* P2PV2_Header::parseMsg(char *buf) char* buf1 = buf + hdrLen1; - for (char *tlvp = buf + 8; tlvp < buf1 && *tlvp; tlvp += 2 + tlvp[1]) - { - switch (*tlvp) - { + for (char *tlvp = buf + 8; tlvp < buf1 && *tlvp; tlvp += 2 + tlvp[1]) { + switch (*tlvp) { case 1: mCap = tlvp; break; @@ -2449,10 +2261,8 @@ char* P2PV2_Header::parseMsg(char *buf) char* buf2 = buf1 + hdrLen2; - for (char *tlvp1 = buf1 + 8; tlvp1 < buf2 && *tlvp1; tlvp1 += 2 + tlvp1[1]) - { - switch (*tlvp1) - { + for (char *tlvp1 = buf1 + 8; tlvp1 < buf2 && *tlvp1; tlvp1 += 2 + tlvp1[1]) { + switch (*tlvp1) { case 1: mRemSize = _htonl64(*(unsigned __int64*)(tlvp1 + 2)); break; @@ -2484,17 +2294,15 @@ char* P2PV2_Header::createMsg(char *buf, const char* wlid, CMsnProto *ppro) char *buf1 = buf + 8; - if (mAckUniqueID) - { + if (mAckUniqueID) { *(unsigned char*)buf1 = 2; *(unsigned char*)(buf1 + 1) = 4; *(unsigned*)(buf1 + 2) = _htonl(mAckUniqueID); buf1 += 6; } - if (mCap) - { + if (mCap) { unsigned len = 2 + mCap[1]; - memcpy(buf1, mCap, len); + memcpy(buf1, mCap, len); buf1 += len; } @@ -2507,8 +2315,7 @@ char* P2PV2_Header::createMsg(char *buf, const char* wlid, CMsnProto *ppro) *(unsigned short*)(buf1 + 2) = _htons(mPacketNum); *(unsigned*)(buf1 + 4) = _htonl(mSessionID); - if (mRemSize) - { + if (mRemSize) { *(unsigned char*)(buf1 + 8) = 1; *(unsigned char*)(buf1 + 9) = 8; *(unsigned __int64*)(buf1 + 10) = _htonl64(mRemSize); diff --git a/protocols/MSN/src/msn_p2ps.cpp b/protocols/MSN/src/msn_p2ps.cpp index 07d8f80d5a..372dbc9132 100644 --- a/protocols/MSN/src/msn_p2ps.cpp +++ b/protocols/MSN/src/msn_p2ps.cpp @@ -51,7 +51,7 @@ filetransfer* CMsnProto::p2p_getSessionByID(unsigned id) mir_cslock lck(sessionLock); - for (int i=0; i < sessionList.getCount(); i++) { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; if (FT->p2p_sessionid == id) return FT; @@ -67,8 +67,7 @@ filetransfer* CMsnProto::p2p_getSessionByUniqueID(unsigned id) mir_cslock lck(sessionLock); - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; if (FT->p2p_acksessid == id) return FT; @@ -91,8 +90,7 @@ filetransfer* CMsnProto::p2p_getThreadSession(MCONTACT hContact, TInfoType mType { mir_cslock lck(sessionLock); - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; if (FT->std.hContact == hContact && FT->tType == mType) return FT; @@ -105,11 +103,9 @@ void CMsnProto::p2p_clearThreadSessions(MCONTACT hContact, TInfoType mType) { mir_cslock lck(sessionLock); - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* ft = &sessionList[i]; - if (ft->std.hContact == hContact && ft->tType == mType) - { + if (ft->std.hContact == hContact && ft->tType == mType) { ft->bCanceled = true; ft->tType = SERVER_NOTIFICATION; p2p_sendCancel(ft); @@ -121,8 +117,7 @@ filetransfer* CMsnProto::p2p_getAvatarSession(MCONTACT hContact) { mir_cslock lck(sessionLock); - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; if (FT->std.hContact == hContact && !(FT->std.flags & PFTS_SENDING) && FT->p2p_type == MSN_APPID_AVATAR) return FT; @@ -136,8 +131,7 @@ bool CMsnProto::p2p_isAvatarOnly(MCONTACT hContact) mir_cslock lck(sessionLock); bool result = true; - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; result &= FT->std.hContact != hContact || FT->p2p_type != MSN_APPID_FILE; } @@ -150,13 +144,11 @@ void CMsnProto::p2p_clearDormantSessions(void) mir_cslockfull lck(sessionLock); time_t ts = time(NULL); - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; if (!FT->p2p_sessionid && !MSN_GetUnconnectedThread(FT->p2p_dest, SERVER_P2P_DIRECT)) p2p_invite(FT->p2p_type, FT, NULL); - else if (FT->p2p_waitack && (ts - FT->ts) > 120) - { + else if (FT->p2p_waitack && (ts - FT->ts) > 120) { FT->bCanceled = true; p2p_sendCancel(FT); lck.unlock(); @@ -172,20 +164,16 @@ void CMsnProto::p2p_redirectSessions(const char *wlid) mir_cslock lck(sessionLock); ThreadData* T = MSN_GetP2PThreadByContact(wlid); - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; if (_stricmp(FT->p2p_dest, wlid) == 0 && FT->std.currentFileProgress < FT->std.currentFileSize && - (T == NULL || (FT->tType != T->mType && FT->tType != 0))) - { - if (FT->p2p_isV2) - { + (T == NULL || (FT->tType != T->mType && FT->tType != 0))) { + if (FT->p2p_isV2) { if ((FT->std.flags & PFTS_SENDING) && T) FT->tType = T->mType; } - else - { + else { if (!(FT->std.flags & PFTS_SENDING)) p2p_sendRedirect(FT); } @@ -200,11 +188,9 @@ void CMsnProto::p2p_startSessions(const char* wlid) char* szEmail; parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; - if (!FT->bAccepted && !_stricmp(FT->p2p_dest, szEmail)) - { + if (!FT->bAccepted && !_stricmp(FT->p2p_dest, szEmail)) { if (FT->p2p_appID == MSN_APPID_FILE && (FT->std.flags & PFTS_SENDING)) p2p_invite(FT->p2p_type, FT, wlid); else if (FT->p2p_appID != MSN_APPID_FILE && !(FT->std.flags & PFTS_SENDING)) @@ -217,8 +203,7 @@ void CMsnProto::p2p_cancelAllSessions(void) { mir_cslock lck(sessionLock); - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { sessionList[i].bCanceled = true; p2p_sendCancel(&sessionList[i]); } @@ -232,13 +217,10 @@ filetransfer* CMsnProto::p2p_getSessionByCallID(const char* CallID, const char* mir_cslock lck(sessionLock); char* szEmail = NULL; - for (int i=0; i < sessionList.getCount(); i++) - { + for (int i = 0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; - if (FT->p2p_callID && !_stricmp(FT->p2p_callID, CallID)) - { - if (_stricmp(FT->p2p_dest, wlid)) - { + if (FT->p2p_callID && !_stricmp(FT->p2p_callID, CallID)) { + if (_stricmp(FT->p2p_dest, wlid)) { if (!szEmail) parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); if (_stricmp(FT->p2p_dest, szEmail)) @@ -271,8 +253,7 @@ directconnection* CMsnProto::p2p_getDCByCallID(const char* CallID, const char* w mir_cslock lck(sessionLock); - for (int i=0; i < dcList.getCount(); i++) - { + for (int i = 0; i < dcList.getCount(); i++) { directconnection* DC = &dcList[i]; if (DC->callId != NULL && !strcmp(DC->callId, CallID) && !strcmp(DC->wlid, wlid)) return DC; diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index f289313ee6..afd93523dd 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -402,18 +402,18 @@ void __cdecl CMsnProto::MsnSearchAckThread(void* arg) case 0: case 2: case 3: - { - PROTOSEARCHRESULT isr = { 0 }; - isr.cbSize = sizeof(isr); - isr.flags = PSR_TCHAR; - isr.id = (TCHAR*)emailT; - isr.nick = (TCHAR*)emailT; - isr.email = (TCHAR*)emailT; - - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, arg, (LPARAM)&isr); - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, arg, 0); - } - break; + { + PROTOSEARCHRESULT isr = { 0 }; + isr.cbSize = sizeof(isr); + isr.flags = PSR_TCHAR; + isr.id = (TCHAR*)emailT; + isr.nick = (TCHAR*)emailT; + isr.email = (TCHAR*)emailT; + + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, arg, (LPARAM)&isr); + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, arg, 0); + } + break; case 1: if (strstr(email, "@yahoo.com") == NULL) @@ -1017,16 +1017,15 @@ int __cdecl CMsnProto::UserIsTyping(MCONTACT hContact, int type) case NETID_UNKNOWN: case NETID_MSN: case NETID_LCS: + bool isOffline; { - bool isOffline; ThreadData* thread = MSN_StartSB(tEmail, isOffline); - if (thread == NULL) { - if (isOffline) return 0; + if (isOffline) + return 0; MsgQueue_Add(tEmail, 2571, NULL, 0, NULL, typing); } - else - MSN_StartStopTyping(thread, typing); + else MSN_StartStopTyping(thread, typing); } break; @@ -1081,11 +1080,9 @@ int __cdecl CMsnProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM l break; case EV_PROTO_ONERASE: - { - char szDbsettings[64]; - mir_snprintf(szDbsettings, sizeof(szDbsettings), "%s_HTTPS", m_szModuleName); - CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbsettings); - } + char szDbsettings[64]; + mir_snprintf(szDbsettings, sizeof(szDbsettings), "%s_HTTPS", m_szModuleName); + CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbsettings); break; case EV_PROTO_ONRENAME: diff --git a/protocols/MSN/src/msn_soapab.cpp b/protocols/MSN/src/msn_soapab.cpp index 7545a1d7d7..a3871d4c37 100644 --- a/protocols/MSN/src/msn_soapab.cpp +++ b/protocols/MSN/src/msn_soapab.cpp @@ -21,16 +21,14 @@ along with this program. If not, see . #include "msn_global.h" #include "msn_proto.h" -static const char abReqHdr[] = - "SOAPAction: http://www.msn.com/webservices/AddressBook/%s\r\n"; - +static const char abReqHdr[] = "SOAPAction: http://www.msn.com/webservices/AddressBook/%s\r\n"; ezxml_t CMsnProto::abSoapHdr(const char* service, const char* scenario, ezxml_t& tbdy, char*& httphdr) { ezxml_t xmlp = ezxml_new("soap:Envelope"); ezxml_set_attr(xmlp, "xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/"); - ezxml_set_attr(xmlp, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - ezxml_set_attr(xmlp, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); + ezxml_set_attr(xmlp, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + ezxml_set_attr(xmlp, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); ezxml_set_attr(xmlp, "xmlns:soapenc", "http://schemas.xmlsoap.org/soap/encoding/"); ezxml_t hdr = ezxml_add_child(xmlp, "soap:Header", 0); @@ -44,8 +42,7 @@ ezxml_t CMsnProto::abSoapHdr(const char* service, const char* scenario, ezxml_t& ezxml_set_txt(node, scenario); char *cacheKey = strstr(service, "Member") ? sharingCacheKey : abCacheKey; - if (cacheKey) - { + if (cacheKey) { node = ezxml_add_child(apphdr, "CacheKey", 0); ezxml_set_txt(node, cacheKey); } @@ -62,8 +59,7 @@ ezxml_t CMsnProto::abSoapHdr(const char* service, const char* scenario, ezxml_t& tbdy = ezxml_add_child(bdy, service, 0); ezxml_set_attr(tbdy, "xmlns", "http://www.msn.com/webservices/AddressBook"); - if (strstr(service, "Member") == NULL && strcmp(service, "ABAdd") != 0 && strcmp(service, "ABFindContactsPaged")) - { + if (strstr(service, "Member") == NULL && strcmp(service, "ABAdd") != 0 && strcmp(service, "ABFindContactsPaged")) { ezxml_t node = ezxml_add_child(tbdy, "abId", 0); ezxml_set_txt(node, "00000000-0000-0000-0000-000000000000"); } @@ -107,14 +103,12 @@ void CMsnProto::UpdateABHost(const char* service, const char* url) delSetting(hostname); } -void CMsnProto::UpdateABCacheKey(ezxml_t bdy, bool isSharing) +void CMsnProto::UpdateABCacheKey(ezxml_t bdy, bool isSharing) { ezxml_t hdr = ezxml_get(bdy, "soap:Header", 0, "ServiceHeader", -1); bool changed = strcmp(ezxml_txt(ezxml_child(hdr, "CacheKeyChanged")), "true") == 0; if (changed) - { replaceStr(isSharing ? sharingCacheKey : abCacheKey, ezxml_txt(ezxml_child(hdr, "CacheKey"))); - } } char* CMsnProto::GetABHost(const char* service, bool isSharing) @@ -123,8 +117,7 @@ char* CMsnProto::GetABHost(const char* service, bool isSharing) mir_snprintf(hostname, sizeof(hostname), "ABHost-%s", service); char* host = (char*)mir_alloc(256); - if (db_get_static(NULL, m_szModuleName, hostname, host, 256)) - { + if (db_get_static(NULL, m_szModuleName, hostname, host, 256)) { mir_snprintf(host, 256, "https://byrdr.omega.contacts.msn.com/abservice/%s.asmx", isSharing ? "SharingService" : "abservice"); } @@ -132,52 +125,6 @@ char* CMsnProto::GetABHost(const char* service, bool isSharing) return host; } -/* -ezxml_t CMsnProto::PerformSoapReq(const char *service, bool isSharing, char *szData, const char* hdrs, unsigned& status) -{ - unsigned status = 0; - char *abUrl = NULL, *tResult = NULL; - - for (int k = 4; --k;) - { - mir_free(abUrl); - abUrl = GetABHost(service, true); - tResult = getSslResult(&abUrl, szData, hdrs, status); - if (tResult == NULL) UpdateABHost(service, NULL); - else break; - } - - mir_free(reqHdr); - free(szData); - - if (tResult != NULL) - { - UpdateABHost(service, abUrl); - ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); - if (!xmlm || !ezxml_child(xmlm, "soap:Body")) - { - mir_free(tResult); - ezxml_free(xmlm); - UpdateABHost("service", NULL); - PerformSoapReq(service, isSharing, szData, hdrs, status); - } - else if (status == 500) - { - const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (!szErr[0]) - { - mir_free(tResult); - ezxml_free(xmlm); - UpdateABHost("service", NULL); - PerformSoapReq(service, isSharing, szData, hdrs, status); - } - } - } - mir_free(abUrl); -} -*/ - - bool CMsnProto::MSN_ABAdd(bool allowRecurse) { char* reqHdr; @@ -199,8 +146,7 @@ bool CMsnProto::MSN_ABAdd(bool allowRecurse) unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("ABAdd", false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -211,16 +157,13 @@ bool CMsnProto::MSN_ABAdd(bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost("ABAdd", abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_ABAdd(false) ? 200 : 500; } @@ -245,26 +188,24 @@ bool CMsnProto::MSN_SharingFindMembership(bool deltas, bool allowRecurse) ezxml_t tps = ezxml_add_child(svcflt, "Types", 0); ezxml_t node = ezxml_add_child(tps, "ServiceType", 0); ezxml_set_txt(node, "Messenger"); -/* - node = ezxml_add_child(tps, "ServiceType", 0); - ezxml_set_txt(node, "Invitation"); - node = ezxml_add_child(tps, "ServiceType", 0); - ezxml_set_txt(node, "SocialNetwork"); - node = ezxml_add_child(tps, "ServiceType", 0); - ezxml_set_txt(node, "Space"); - node = ezxml_add_child(tps, "ServiceType", 0); - ezxml_set_txt(node, "Profile"); - node = ezxml_add_child(tps, "ServiceType", 0); - ezxml_set_txt(node, "Folder"); - node = ezxml_add_child(tps, "ServiceType", 0); - ezxml_set_txt(node, "OfficeLiveWebNotification"); -*/ + /* + node = ezxml_add_child(tps, "ServiceType", 0); + ezxml_set_txt(node, "Invitation"); + node = ezxml_add_child(tps, "ServiceType", 0); + ezxml_set_txt(node, "SocialNetwork"); + node = ezxml_add_child(tps, "ServiceType", 0); + ezxml_set_txt(node, "Space"); + node = ezxml_add_child(tps, "ServiceType", 0); + ezxml_set_txt(node, "Profile"); + node = ezxml_add_child(tps, "ServiceType", 0); + ezxml_set_txt(node, "Folder"); + node = ezxml_add_child(tps, "ServiceType", 0); + ezxml_set_txt(node, "OfficeLiveWebNotification"); + */ const char *szLastChange = NULL; - if (deltas) - { + if (deltas) { DBVARIANT dbv; - if (!getString("SharingLastChange", &dbv) && dbv.pszVal[0]) - { + if (!getString("SharingLastChange", &dbv) && dbv.pszVal[0]) { szLastChange = NEWSTR_ALLOCA(dbv.pszVal); db_free(&dbv); } @@ -285,8 +226,7 @@ bool CMsnProto::MSN_SharingFindMembership(bool deltas, bool allowRecurse) unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("FindMembership", true); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -297,31 +237,26 @@ bool CMsnProto::MSN_SharingFindMembership(bool deltas, bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); - if (status == 200) - { + if (status == 200) { UpdateABCacheKey(xmlm, true); ezxml_t body = getSoapResponse(xmlm, "FindMembership"); ezxml_t svcs = ezxml_get(body, "Services", 0, "Service", -1); UpdateABHost("FindMembership", body ? abUrl : NULL); - while (svcs != NULL) - { + while (svcs != NULL) { const char* szType = ezxml_txt(ezxml_get(svcs, "Info", 0, "Handle", 0, "Type", -1)); if (_stricmp(szType, "Messenger") == 0) break; svcs = ezxml_next(svcs); } const char* szLastChange = ezxml_txt(ezxml_child(svcs, "LastChange")); - if (szLastChange[0]) setString("SharingLastChange", szLastChange); - - ezxml_t mems = ezxml_get(svcs, "Memberships", 0, "Membership", -1); + if (szLastChange[0]) + setString("SharingLastChange", szLastChange); - while (mems != NULL) - { + for (ezxml_t mems = ezxml_get(svcs, "Memberships", 0, "Membership", -1); mems != NULL; mems = ezxml_next(mems)) { const char* szRole = ezxml_txt(ezxml_child(mems, "MemberRole")); int lstId = 0; @@ -330,77 +265,65 @@ bool CMsnProto::MSN_SharingFindMembership(bool deltas, bool allowRecurse) else if (strcmp(szRole, "Reverse") == 0) lstId = LIST_RL; else if (strcmp(szRole, "Pending") == 0) lstId = LIST_PL; - ezxml_t memb = ezxml_get(mems, "Members", 0, "Member", -1); - while (memb != NULL) - { + for (ezxml_t memb = ezxml_get(mems, "Members", 0, "Member", -1); memb != NULL; memb = ezxml_next(memb)) { bool deleted = strcmp(ezxml_txt(ezxml_child(memb, "Deleted")), "true") == 0; - const char* szType = ezxml_txt(ezxml_child(memb, "Type")); - if (strcmp(szType, "Passport") == 0) - { - const char* szInvite = NULL; - const char* szEmail = ezxml_txt(ezxml_child(memb, "PassportName")); - const char* szNick = ezxml_txt(ezxml_child(memb, "DisplayName")); if (!szNick[0]) szNick = NULL; + const char *szType = ezxml_txt(ezxml_child(memb, "Type")); + const char *szInvite = NULL, *szEmail = NULL, *szNick = NULL; + int netId; + + if (strcmp(szType, "Passport") == 0) { + netId = NETID_MSN; + szEmail = ezxml_txt(ezxml_child(memb, "PassportName")); + szNick = ezxml_txt(ezxml_child(memb, "DisplayName")); if (!szNick[0]) szNick = NULL; ezxml_t anot = ezxml_get(memb, "Annotations", 0, "Annotation", -1); - while (anot != NULL) - { + while (anot != NULL) { if (strcmp(ezxml_txt(ezxml_child(anot, "Name")), "MSN.IM.InviteMessage") == 0) - { szInvite = ezxml_txt(ezxml_child(anot, "Value")); - } + anot = ezxml_next(anot); } - if (!deleted) Lists_Add(lstId, NETID_MSN, szEmail, NULL, szNick, szInvite); else Lists_Remove(lstId, szEmail); } - else if (strcmp(szType, "Phone") == 0) - { - const char* szEmail = ezxml_txt(ezxml_child(memb, "PhoneNumber")); + else if (strcmp(szType, "Phone") == 0) { + netId = NETID_MOB; char email[128]; - mir_snprintf(email, sizeof(email), "tel:%s", szEmail); - if (!deleted) Lists_Add(lstId, NETID_MOB, email); else Lists_Remove(lstId, szEmail); + mir_snprintf(email, sizeof(email), "tel:%s", ezxml_txt(ezxml_child(memb, "PhoneNumber"))); + szEmail = email; } - else if (strcmp(szType, "Email") == 0) - { - const char* szInvite = NULL; - const char* szEmail = ezxml_txt(ezxml_child(memb, "Email")); - const char* szNick = ezxml_txt(ezxml_child(memb, "DisplayName")); if (!szNick[0]) szNick = NULL; - int netId = strstr(szEmail, "@yahoo.com") ? NETID_YAHOO : NETID_LCS; + else if (strcmp(szType, "Email") == 0) { + szEmail = ezxml_txt(ezxml_child(memb, "Email")); + szNick = ezxml_txt(ezxml_child(memb, "DisplayName")); if (!szNick[0]) szNick = NULL; + netId = strstr(szEmail, "@yahoo.com") ? NETID_YAHOO : NETID_LCS; ezxml_t anot = ezxml_get(memb, "Annotations", 0, "Annotation", -1); - while (anot != NULL) - { + while (anot != NULL) { if (strcmp(ezxml_txt(ezxml_child(anot, "Name")), "MSN.IM.BuddyType") == 0) - { netId = atol(ezxml_txt(ezxml_child(anot, "Value"))); - } else if (strcmp(ezxml_txt(ezxml_child(anot, "Name")), "MSN.IM.InviteMessage") == 0) - { szInvite = ezxml_txt(ezxml_child(anot, "Value")); - } + anot = ezxml_next(anot); } - - if (!deleted) Lists_Add(lstId, netId, szEmail, NULL, szNick, szInvite); else Lists_Remove(lstId, szEmail); } - memb = ezxml_next(memb); + else continue; + + if (!deleted) + Lists_Add(lstId, netId, szEmail, NULL, szNick, szInvite); + else + Lists_Remove(lstId, szEmail); } - mems = ezxml_next(mems); } } - else if (status == 500) - { + else if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "ABDoesNotExist") == 0) - { + if (strcmp(szErr, "ABDoesNotExist") == 0) { MSN_ABAdd(); status = 200; } - else if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + else if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_SharingFindMembership(deltas, false) ? 200 : 500; } } - else - UpdateABHost("FindMembership", NULL); + else UpdateABHost("FindMembership", NULL); ezxml_free(xmlm); } @@ -430,33 +353,31 @@ bool CMsnProto::MSN_SharingAddDelMember(const char* szEmail, const int listId, c node = ezxml_add_child(svchnd, "Type", 0); ezxml_set_txt(node, "Messenger"); node = ezxml_add_child(svchnd, "ForeignId", 0); -// ezxml_set_txt(node, ""); const char* szMemberName = ""; const char* szTypeName = ""; const char* szAccIdName = ""; - switch (netId) - { - case 1: - szMemberName = "PassportMember"; - szTypeName = "Passport"; - szAccIdName = "PassportName"; - break; - - case 4: - szMemberName = "PhoneMember"; - szTypeName = "Phone"; - szAccIdName = "PhoneNumber"; - szEmail = strchr(szEmail, ':') + 1; - break; - - case 2: - case 32: - szMemberName = "EmailMember"; - szTypeName = "Email"; - szAccIdName = "Email"; - break; + switch (netId) { + case 1: + szMemberName = "PassportMember"; + szTypeName = "Passport"; + szAccIdName = "PassportName"; + break; + + case 4: + szMemberName = "PhoneMember"; + szTypeName = "Phone"; + szAccIdName = "PhoneNumber"; + szEmail = strchr(szEmail, ':') + 1; + break; + + case 2: + case 32: + szMemberName = "EmailMember"; + szTypeName = "Email"; + szAccIdName = "Email"; + break; } ezxml_t memb = ezxml_add_child(tbdy, "memberships", 0); @@ -465,8 +386,8 @@ bool CMsnProto::MSN_SharingAddDelMember(const char* szEmail, const int listId, c ezxml_set_txt(node, szRole); memb = ezxml_add_child(memb, "Members", 0); memb = ezxml_add_child(memb, "Member", 0); - ezxml_set_attr(memb, "xsi:type", szMemberName); - ezxml_set_attr(memb, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + ezxml_set_attr(memb, "xsi:type", szMemberName); + ezxml_set_attr(memb, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); node = ezxml_add_child(memb, "Type", 0); ezxml_set_txt(node, szTypeName); node = ezxml_add_child(memb, "State", 0); @@ -475,8 +396,7 @@ bool CMsnProto::MSN_SharingAddDelMember(const char* szEmail, const int listId, c ezxml_set_txt(node, szEmail); char buf[64]; - if ((netId == NETID_LCS || netId == NETID_YAHOO) && strcmp(szMethod, "DeleteMember") != 0) - { + if ((netId == NETID_LCS || netId == NETID_YAHOO) && strcmp(szMethod, "DeleteMember") != 0) { node = ezxml_add_child(memb, "Annotations", 0); ezxml_t anot = ezxml_add_child(node, "Annotation", 0); node = ezxml_add_child(anot, "Name", 0); @@ -494,8 +414,7 @@ bool CMsnProto::MSN_SharingAddDelMember(const char* szEmail, const int listId, c unsigned status; char *abUrl = NULL, *tResult; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost(szMethod, true); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -506,16 +425,13 @@ bool CMsnProto::MSN_SharingAddDelMember(const char* szEmail, const int listId, c mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost(szMethod, abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, true); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_SharingAddDelMember(szEmail, listId, netId, szMethod, false) ? 200 : 500; } @@ -550,7 +466,7 @@ bool CMsnProto::MSN_SharingMyProfile(bool allowRecurse) memb = ezxml_add_child(memb, "Members", 0); memb = ezxml_add_child(memb, "Member", 0); ezxml_set_attr(memb, "xsi:type", "RoleMember"); - ezxml_set_attr(memb, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + ezxml_set_attr(memb, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); node = ezxml_add_child(memb, "Type", 0); ezxml_set_txt(node, "Role"); node = ezxml_add_child(memb, "State", 0); @@ -578,8 +494,7 @@ bool CMsnProto::MSN_SharingMyProfile(bool allowRecurse) unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("AddMember", true); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -591,11 +506,9 @@ bool CMsnProto::MSN_SharingMyProfile(bool allowRecurse) free(szData); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); MSN_SharingMyProfile(false); } @@ -612,7 +525,7 @@ bool CMsnProto::MSN_SharingMyProfile(bool allowRecurse) void CMsnProto::SetAbParam(MCONTACT hContact, const char *name, const char *par) { if (*par) setStringUtf(hContact, name, (char*)par); -// else delSetting(hContact, "FirstName"); + // else delSetting(hContact, "FirstName"); } // "ABFindAll", "ABFindByContacts", "ABFindContactsPaged" @@ -624,22 +537,18 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas const char *szLastChange = NULL; - if (deltas) - { + if (deltas) { DBVARIANT dbv; - if (!getString("ABFullLastChange", &dbv) && dbv.pszVal[0]) - { + if (!getString("ABFullLastChange", &dbv) && dbv.pszVal[0]) { szLastChange = NEWSTR_ALLOCA(dbv.pszVal); db_free(&dbv); } deltas &= (szLastChange != NULL); } const char *szDynLastChange = NULL; - if (deltas) - { + if (deltas) { DBVARIANT dbv; - if (!getString("ABFullDynLastChange", &dbv) && dbv.pszVal[0]) - { + if (!getString("ABFullDynLastChange", &dbv) && dbv.pszVal[0]) { szDynLastChange = NEWSTR_ALLOCA(dbv.pszVal); db_free(&dbv); } @@ -647,24 +556,21 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas } const char *szGroups, *szContacts, *szLastChangeStr; - if (strcmp(szMethod, "ABFindContactsPaged")) - { + if (strcmp(szMethod, "ABFindContactsPaged")) { ezxml_t node = ezxml_add_child(tbdy, "abView", 0); ezxml_set_txt(node, "Full"); node = ezxml_add_child(tbdy, "deltasOnly", 0); ezxml_set_txt(node, deltas ? "true" : "false"); node = ezxml_add_child(tbdy, "dynamicItemView", 0); ezxml_set_txt(node, "Gleam"); - if (deltas) - { + if (deltas) { node = ezxml_add_child(tbdy, "lastChange", 0); ezxml_set_txt(node, szLastChange); node = ezxml_add_child(tbdy, "dynamicItemLastChange", 0); ezxml_set_txt(node, szDynLastChange); } - if (szGuid) - { + if (szGuid) { node = ezxml_add_child(tbdy, "contactIds", 0); node = ezxml_add_child(node, "guid", 0); ezxml_set_txt(node, szGuid); @@ -673,8 +579,7 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas szContacts = "contacts"; szLastChangeStr = "LastChange"; } - else - { + else { ezxml_t node = ezxml_add_child(tbdy, "abView", 0); ezxml_set_txt(node, "MessengerClient8"); node = ezxml_add_child(tbdy, "extendedContent", 0); @@ -683,12 +588,11 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas node = ezxml_add_child(filt, "DeltasOnly", 0); ezxml_set_txt(node, deltas ? "true" : "false"); - if (deltas) - { + if (deltas) { node = ezxml_add_child(filt, "LastChanged", 0); ezxml_set_txt(node, szLastChange); } - node = ezxml_add_child(filt, "ContactFilter", 0); + node = ezxml_add_child(filt, "ContactFilter", 0); node = ezxml_add_child(node, "IncludeHiddenContacts", 0); ezxml_set_txt(node, "true"); @@ -697,14 +601,13 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas szLastChangeStr = "lastChange"; } - char* szData = ezxml_toxml(xmlp, true); + char *szData = ezxml_toxml(xmlp, true); ezxml_free(xmlp); unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost(szMethod, false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -715,34 +618,31 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 200) - { + if (status == 200) { ezxml_t body = getSoapResponse(xmlm, szMethod); UpdateABHost(szMethod, body ? abUrl : NULL); ezxml_t ab = ezxml_child(body, "Ab"); - if (strcmp(szMethod, "ABFindByContacts")) - { + if (strcmp(szMethod, "ABFindByContacts")) { const char* szLastChange = ezxml_txt(ezxml_child(ab, szLastChangeStr)); - if (szLastChange[0]) setString("ABFullLastChange", szLastChange); + if (szLastChange[0]) + setString("ABFullLastChange", szLastChange); szLastChange = ezxml_txt(ezxml_child(ab, "DynamicItemLastChanged")); - if (szLastChange[0]) setString("ABFullDynLastChange", szLastChange); + if (szLastChange[0]) + setString("ABFullDynLastChange", szLastChange); } ezxml_t abinf = ezxml_child(ab, "abInfo"); - mir_snprintf(mycid, sizeof(mycid), "%s", ezxml_txt(ezxml_child(abinf, "OwnerCID"))); + mir_snprintf(mycid, sizeof(mycid), "%s", ezxml_txt(ezxml_child(abinf, "OwnerCID"))); mir_snprintf(mypuid, sizeof(mycid), "%s", ezxml_txt(ezxml_child(abinf, "ownerPuid"))); - if (MyOptions.ManageServer) - { + if (MyOptions.ManageServer) { ezxml_t grp = ezxml_get(body, szGroups, 0, "Group", -1); - while (grp != NULL) - { + while (grp != NULL) { const char* szGrpId = ezxml_txt(ezxml_child(grp, "groupId")); const char* szGrpName = ezxml_txt(ezxml_get(grp, "groupInfo", 0, "name", -1)); MSN_AddGroup(szGrpName, szGrpId, true); @@ -751,15 +651,13 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas } } - for (ezxml_t cont = ezxml_get(body, szContacts, 0, "Contact", -1); cont != NULL; cont = ezxml_next(cont)) - { + for (ezxml_t cont = ezxml_get(body, szContacts, 0, "Contact", -1); cont != NULL; cont = ezxml_next(cont)) { const char* szContId = ezxml_txt(ezxml_child(cont, "contactId")); ezxml_t contInf = ezxml_child(cont, "contactInfo"); const char* szType = ezxml_txt(ezxml_child(contInf, "contactType")); - if (strcmp(szType, "Me") != 0) - { + if (strcmp(szType, "Me") != 0) { char email[128]; const char* szEmail = ezxml_txt(ezxml_child(contInf, "passportName")); @@ -768,14 +666,11 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas int netId = NETID_UNKNOWN; if (strcmp(szMsgUsr, "true") == 0) netId = NETID_MSN; - if (szEmail[0] == '\0') - { + if (szEmail[0] == '\0') { ezxml_t eml = ezxml_get(contInf, "emails", 0, "ContactEmail", -1); - while (eml != NULL) - { + while (eml != NULL) { szMsgUsr = ezxml_txt(ezxml_child(eml, "isMessengerEnabled")); - if (strcmp(szMsgUsr, "true") == 0) - { + if (strcmp(szMsgUsr, "true") == 0) { szEmail = ezxml_txt(ezxml_child(eml, "email")); const char* szCntType = ezxml_txt(ezxml_child(eml, "contactEmailType")); if (strcmp(szCntType, "Messenger2") == 0) @@ -787,14 +682,11 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas eml = ezxml_next(eml); } - if (netId == NETID_UNKNOWN) - { + if (netId == NETID_UNKNOWN) { ezxml_t phn = ezxml_get(contInf, "phones", 0, "ContactPhone", -1); - while (phn != NULL) - { + while (phn != NULL) { szMsgUsr = ezxml_txt(ezxml_child(phn, "isMessengerEnabled")); - if (strcmp(szMsgUsr, "true") == 0) - { + if (strcmp(szMsgUsr, "true") == 0) { szEmail = ezxml_txt(ezxml_child(phn, "number")); mir_snprintf(email, sizeof(email), "tel:%s", szEmail); szEmail = email; @@ -806,22 +698,16 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas } } - if (netId == NETID_UNKNOWN || szEmail[0] == 0) continue; + if (netId == NETID_UNKNOWN || szEmail[0] == 0) + continue; Lists_Add(LIST_FL, netId, szEmail); - const char *szTmp; - // Depricated in WLM 8.1 - // const char* szNick = ezxml_txt(ezxml_child(contInf, "displayName")); - // if (*szNick == '\0') szNick = szEmail; MCONTACT hContact = MSN_HContactFromEmail(szEmail, szEmail, true, false); - // setStringUtf(hContact, "Nick", (char*)szNick); - if (MyOptions.ManageServer) - { + if (MyOptions.ManageServer) { ezxml_t grpid = ezxml_child(contInf, "groupIds"); - if (!deltas || grpid) - { + if (!deltas || grpid) { ezxml_t grps = ezxml_child(grpid, "guid"); MSN_SyncContactToServerGroup(hContact, szContId, grps); } @@ -829,16 +715,13 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas const char* szNick = NULL; ezxml_t anot = ezxml_get(contInf, "annotations", 0, "Annotation", -1); - while (anot != NULL) - { - if (strcmp(ezxml_txt(ezxml_child(anot, "Name")), "AB.NickName") == 0) - { + while (anot != NULL) { + if (strcmp(ezxml_txt(ezxml_child(anot, "Name")), "AB.NickName") == 0) { szNick = ezxml_txt(ezxml_child(anot, "Value")); db_set_utf(hContact, "CList", "MyHandle", szNick); } - if (strcmp(ezxml_txt(ezxml_child(anot, "Name")), "AB.JobTitle") == 0) - { - szTmp = ezxml_txt(ezxml_child(anot, "Value")); + if (strcmp(ezxml_txt(ezxml_child(anot, "Name")), "AB.JobTitle") == 0) { + const char *szTmp = ezxml_txt(ezxml_child(anot, "Value")); SetAbParam(hContact, "CompanyPosition", szTmp); } anot = ezxml_next(anot); @@ -848,8 +731,7 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas setString(hContact, "ID", szContId); - switch (netId) - { + switch (netId) { case NETID_YAHOO: setString(hContact, "Transport", "YAHOO"); break; @@ -862,10 +744,10 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas delSetting(hContact, "Transport"); } - szTmp = ezxml_txt(ezxml_child(contInf, "CID")); + const char *szTmp = ezxml_txt(ezxml_child(contInf, "CID")); SetAbParam(hContact, "CID", szTmp); - szTmp = ezxml_txt(ezxml_child(contInf, "IsNotMobileVisible")); + szTmp = ezxml_txt(ezxml_child(contInf, "IsNotMobileVisible")); setByte(hContact, "MobileAllowed", strcmp(szTmp, "true") != 0); szTmp = ezxml_txt(ezxml_child(contInf, "isMobileIMEnabled")); @@ -879,26 +761,18 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas szTmp = ezxml_txt(ezxml_child(contInf, "birthdate")); char *szPtr; - if (strtol(szTmp, &szPtr, 10) > 1) - { + if (strtol(szTmp, &szPtr, 10) > 1) { setWord(hContact, "BirthYear", (WORD)strtol(szTmp, &szPtr, 10)); - setByte(hContact, "BirthMonth", (BYTE)strtol(szPtr+1, &szPtr, 10)); - setByte(hContact, "BirthDay", (BYTE)strtol(szPtr+1, &szPtr, 10)); - } - else - { - // delSetting(hContact, "BirthYear"); - // delSetting(hContact, "BirthMonth"); - // delSetting(hContact, "BirthDay"); + setByte(hContact, "BirthMonth", (BYTE)strtol(szPtr + 1, &szPtr, 10)); + setByte(hContact, "BirthDay", (BYTE)strtol(szPtr + 1, &szPtr, 10)); } szTmp = ezxml_txt(ezxml_child(contInf, "comment")); - if (*szTmp) db_set_s(hContact, "UserInfo", "MyNotes", szTmp); - // else db_unset(hContact, "UserInfo", "MyNotes"); + if (*szTmp) + db_set_s(hContact, "UserInfo", "MyNotes", szTmp); ezxml_t loc = ezxml_get(contInf, "locations", 0, "ContactLocation", -1); - while (loc != NULL) - { + while (loc != NULL) { const char* szCntType = ezxml_txt(ezxml_child(loc, "contactLocationType")); int locid = -1; @@ -907,8 +781,7 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas else if (strcmp(szCntType, "ContactLocationBusiness") == 0) locid = 1; - if (locid >= 0) - { + if (locid >= 0) { szTmp = ezxml_txt(ezxml_child(loc, "name")); SetAbParam(hContact, "Company", szTmp); szTmp = ezxml_txt(ezxml_child(loc, "street")); @@ -926,25 +799,16 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas } ezxml_t web = ezxml_get(contInf, "webSites", 0, "ContactWebSite", -1); - while (web != NULL) - { + while (web != NULL) { const char* szCntType = ezxml_txt(ezxml_child(web, "contactWebSiteType")); - if (strcmp(szCntType, "ContactWebSiteBusiness") == 0) - { + if (strcmp(szCntType, "ContactWebSiteBusiness") == 0) { szTmp = ezxml_txt(ezxml_child(web, "webURL")); SetAbParam(hContact, "CompanyHomepage", szTmp); } web = ezxml_next(web); } } - else - { - // This depricated in WLM 8.1 - // if (!getByte("NeverUpdateNickname", 0)) - // { - // const char* szNick = ezxml_txt(ezxml_child(contInf, "displayName")); - // setStringUtf(NULL, "Nick", (char*)szNick); - // } + else { const char *szTmp; szTmp = ezxml_txt(ezxml_child(contInf, "isMobileIMEnabled")); @@ -960,8 +824,7 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas setStringUtf(NULL, "LastName", szTmp); ezxml_t anot = ezxml_get(contInf, "annotations", 0, "Annotation", -1); - while (anot != NULL) - { + while (anot != NULL) { if (strcmp(ezxml_txt(ezxml_child(anot, "Name")), "MSN.IM.BLP") == 0) msnOtherContactsBlocked = !atol(ezxml_txt(ezxml_child(anot, "Value"))); @@ -969,25 +832,21 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas } } } - if (!msnLoggedIn && msnNsThread) - { + if (!msnLoggedIn && msnNsThread) { char *szCircleTicket = ezxml_txt(ezxml_get(body, "CircleResult", 0, "CircleTicket", -1)); - ptrA szCircleTicketEnc( mir_base64_encode((PBYTE)szCircleTicket, (unsigned)strlen(szCircleTicket))); + ptrA szCircleTicketEnc(mir_base64_encode((PBYTE)szCircleTicket, (unsigned)strlen(szCircleTicket))); if (szCircleTicketEnc) msnNsThread->sendPacket("USR", "SHA A %s", szCircleTicketEnc); } } - else if (status == 500) - { + else if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_ABFind(szMethod, szGuid, deltas, false) ? 200 : 500; } - else if (strcmp(szErr, "FullSyncRequired") == 0 && deltas) - { + else if (strcmp(szErr, "FullSyncRequired") == 0 && deltas) { status = MSN_ABFind(szMethod, szGuid, false, false) ? 200 : 500; } } @@ -1010,16 +869,14 @@ bool CMsnProto::MSN_ABAddDelContactGroup(const char* szCntId, const char* szGrpI ezxml_t tbdy, node; ezxml_t xmlp = abSoapHdr(szMethod, "Timer", tbdy, reqHdr); - if (szGrpId != NULL) - { + if (szGrpId != NULL) { node = ezxml_add_child(tbdy, "groupFilter", 0); node = ezxml_add_child(node, "groupIds", 0); node = ezxml_add_child(node, "guid", 0); ezxml_set_txt(node, szGrpId); } - if (szCntId != NULL) - { + if (szCntId != NULL) { node = ezxml_add_child(tbdy, "contacts", 0); node = ezxml_add_child(node, "Contact", 0); node = ezxml_add_child(node, "contactId", 0); @@ -1032,8 +889,7 @@ bool CMsnProto::MSN_ABAddDelContactGroup(const char* szCntId, const char* szGrpI unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost(szMethod, false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -1044,16 +900,13 @@ bool CMsnProto::MSN_ABAddDelContactGroup(const char* szCntId, const char* szGrpI mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost(szMethod, abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_ABAddDelContactGroup(szCntId, szGrpId, szMethod, false) ? 200 : 500; } @@ -1097,8 +950,7 @@ void CMsnProto::MSN_ABAddGroup(const char* szGrpName, bool allowRecurse) unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("ABGroupAdd", false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -1109,22 +961,18 @@ void CMsnProto::MSN_ABAddGroup(const char* szGrpName, bool allowRecurse) free(szData); mir_free(reqHdr); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost("ABGroupAdd", abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 200) - { + if (status == 200) { ezxml_t body = getSoapResponse(xmlm, "ABGroupAdd"); const char* szGrpId = ezxml_txt(ezxml_child(body, "guid")); MSN_AddGroup(szGrpName, szGrpId, false); } - else if (status == 500) - { + else if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); MSN_ABAddGroup(szGrpName, false); } @@ -1159,8 +1007,7 @@ void CMsnProto::MSN_ABRenameGroup(const char* szGrpName, const char* szGrpId, bo unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("ABGroupUpdate", false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -1171,16 +1018,13 @@ void CMsnProto::MSN_ABRenameGroup(const char* szGrpName, const char* szGrpId, bo mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost("ABGroupUpdate", abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); MSN_ABRenameGroup(szGrpName, szGrpId, false); } @@ -1195,7 +1039,7 @@ void CMsnProto::MSN_ABRenameGroup(const char* szGrpName, const char* szGrpId, bo bool CMsnProto::MSN_ABAddRemoveContact(const char* szCntId, int netId, bool add, bool allowRecurse) { char* reqHdr; - ezxml_t tbdy; + ezxml_t tbdy, contp; ezxml_t xmlp = abSoapHdr("ABContactUpdate", "Timer", tbdy, reqHdr); ezxml_t node = ezxml_add_child(tbdy, "contacts", 0); @@ -1206,8 +1050,7 @@ bool CMsnProto::MSN_ABAddRemoveContact(const char* szCntId, int netId, bool add, ezxml_set_txt(node, szCntId); ezxml_t conti = ezxml_add_child(cont, "contactInfo", 0); - switch (netId) - { + switch (netId) { case NETID_MSN: node = ezxml_add_child(conti, "isMessengerUser", 0); ezxml_set_txt(node, add ? "true" : "false"); @@ -1217,33 +1060,29 @@ bool CMsnProto::MSN_ABAddRemoveContact(const char* szCntId, int netId, bool add, case NETID_LCS: case NETID_YAHOO: - { - ezxml_t contp = ezxml_add_child(conti, "emails", 0); - contp = ezxml_add_child(contp, "ContactEmail", 0); - node = ezxml_add_child(contp, "contactEmailType", 0); - ezxml_set_txt(node, netId == NETID_YAHOO ? "Messenger2" : "Messenger3"); - node = ezxml_add_child(contp, "isMessengerEnabled", 0); - ezxml_set_txt(node, add ? "true" : "false"); - node = ezxml_add_child(contp, "propertiesChanged", 0); - ezxml_set_txt(node, "IsMessengerEnabled"); - node = ezxml_add_child(cont, "propertiesChanged", 0); - ezxml_set_txt(node, "ContactEmail"); - } + contp = ezxml_add_child(conti, "emails", 0); + contp = ezxml_add_child(contp, "ContactEmail", 0); + node = ezxml_add_child(contp, "contactEmailType", 0); + ezxml_set_txt(node, netId == NETID_YAHOO ? "Messenger2" : "Messenger3"); + node = ezxml_add_child(contp, "isMessengerEnabled", 0); + ezxml_set_txt(node, add ? "true" : "false"); + node = ezxml_add_child(contp, "propertiesChanged", 0); + ezxml_set_txt(node, "IsMessengerEnabled"); + node = ezxml_add_child(cont, "propertiesChanged", 0); + ezxml_set_txt(node, "ContactEmail"); break; case NETID_MOB: - { - ezxml_t contp = ezxml_add_child(conti, "phones", 0); - contp = ezxml_add_child(contp, "ContactPhone", 0); - node = ezxml_add_child(contp, "contactPhoneType", 0); - ezxml_set_txt(node, "ContactPhoneMobile"); - node = ezxml_add_child(contp, "isMessengerEnabled", 0); - ezxml_set_txt(node, add ? "true" : "false"); - node = ezxml_add_child(contp, "propertiesChanged", 0); - ezxml_set_txt(node, "IsMessengerEnabled"); - node = ezxml_add_child(cont, "propertiesChanged", 0); - ezxml_set_txt(node, "ContactPhone"); - } + contp = ezxml_add_child(conti, "phones", 0); + contp = ezxml_add_child(contp, "ContactPhone", 0); + node = ezxml_add_child(contp, "contactPhoneType", 0); + ezxml_set_txt(node, "ContactPhoneMobile"); + node = ezxml_add_child(contp, "isMessengerEnabled", 0); + ezxml_set_txt(node, add ? "true" : "false"); + node = ezxml_add_child(contp, "propertiesChanged", 0); + ezxml_set_txt(node, "IsMessengerEnabled"); + node = ezxml_add_child(cont, "propertiesChanged", 0); + ezxml_set_txt(node, "ContactPhone"); break; } @@ -1253,8 +1092,7 @@ bool CMsnProto::MSN_ABAddRemoveContact(const char* szCntId, int netId, bool add, unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("ABContactUpdate", false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -1265,16 +1103,13 @@ bool CMsnProto::MSN_ABAddRemoveContact(const char* szCntId, int netId, bool add, mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost("ABContactUpdate", abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); if (MSN_ABAddRemoveContact(szCntId, netId, add, false)) status = 200; @@ -1300,13 +1135,11 @@ bool CMsnProto::MSN_ABUpdateProperty(const char* szCntId, const char* propName, ezxml_set_attr(cont, "xmlns", "http://www.msn.com/webservices/AddressBook"); ezxml_t conti = ezxml_add_child(cont, "contactInfo", 0); - if (szCntId == NULL) - { + if (szCntId == NULL) { node = ezxml_add_child(conti, "contactType", 0); ezxml_set_txt(node, "Me"); } - else - { + else { node = ezxml_add_child(cont, "contactId", 0); ezxml_set_txt(node, szCntId); } @@ -1325,8 +1158,7 @@ bool CMsnProto::MSN_ABUpdateProperty(const char* szCntId, const char* propName, unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("ABContactUpdate", false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -1337,16 +1169,13 @@ bool CMsnProto::MSN_ABUpdateProperty(const char* szCntId, const char* propName, mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost("ABContactUpdate", abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); if (MSN_ABUpdateProperty(szCntId, propName, propValue, false)) status = 200; @@ -1360,7 +1189,6 @@ bool CMsnProto::MSN_ABUpdateProperty(const char* szCntId, const char* propName, return status == 200; } - void CMsnProto::MSN_ABUpdateAttr(const char* szCntId, const char* szAttr, const char* szValue, bool allowRecurse) { char* reqHdr; @@ -1371,13 +1199,11 @@ void CMsnProto::MSN_ABUpdateAttr(const char* szCntId, const char* szAttr, const ezxml_t cont = ezxml_add_child(node, "Contact", 0); ezxml_set_attr(cont, "xmlns", "http://www.msn.com/webservices/AddressBook"); ezxml_t conti = ezxml_add_child(cont, "contactInfo", 0); - if (szCntId == NULL) - { + if (szCntId == NULL) { node = ezxml_add_child(conti, "contactType", 0); ezxml_set_txt(node, "Me"); } - else - { + else { node = ezxml_add_child(cont, "contactId", 0); ezxml_set_txt(node, szCntId); } @@ -1397,8 +1223,7 @@ void CMsnProto::MSN_ABUpdateAttr(const char* szCntId, const char* szAttr, const unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("ABContactUpdate", false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -1409,16 +1234,13 @@ void CMsnProto::MSN_ABUpdateAttr(const char* szCntId, const char* szAttr, const mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost("ABContactUpdate", abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); MSN_ABUpdateAttr(szCntId, szAttr, szValue, false); } @@ -1454,8 +1276,7 @@ unsigned CMsnProto::MSN_ABContactAdd(const char* szEmail, const char* szNick, in const char* szEmailNP = strchr(szEmail, ':'); if (szEmailNP != NULL) netId = NETID_MOB; - switch (netId) - { + switch (netId) { case NETID_MSN: node = ezxml_add_child(conti, "contactType", 0); ezxml_set_txt(node, "LivePending"); @@ -1464,8 +1285,7 @@ unsigned CMsnProto::MSN_ABContactAdd(const char* szEmail, const char* szNick, in node = ezxml_add_child(conti, "isMessengerUser", 0); ezxml_set_txt(node, "true"); - if (szInvite) - { + if (szInvite) { node = ezxml_add_child(conti, "MessengerMemberInfo", 0); node = ezxml_add_child(node, "PendingAnnotations", 0); ezxml_t anot = ezxml_add_child(node, "Annotation", 0); @@ -1502,14 +1322,13 @@ unsigned CMsnProto::MSN_ABContactAdd(const char* szEmail, const char* szNick, in node = ezxml_add_child(contp, "isMessengerEnabled", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(contp, "Capability", 0); - ezxml_set_txt(node, netId == NETID_YAHOO ? "32" : "2"); + ezxml_set_txt(node, netId == NETID_YAHOO ? "32" : "2"); node = ezxml_add_child(contp, "propertiesChanged", 0); ezxml_set_txt(node, "Email IsMessengerEnabled Capability"); break; } - if (szNick != NULL) - { + if (szNick != NULL) { node = ezxml_add_child(conti, "annotations", 0); ezxml_t annt = ezxml_add_child(node, "Annotation", 0); node = ezxml_add_child(annt, "Name", 0); @@ -1528,8 +1347,7 @@ unsigned CMsnProto::MSN_ABContactAdd(const char* szEmail, const char* szNick, in unsigned status = 0; char *abUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("ABContactAdd", false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -1540,28 +1358,24 @@ unsigned CMsnProto::MSN_ABContactAdd(const char* szEmail, const char* szNick, in mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 200) - { + if (status == 200) { ezxml_t body = getSoapResponse(xmlm, "ABContactAdd"); const char* szContId = ezxml_txt(ezxml_child(body, "guid")); if (search) - MSN_ABAddDelContactGroup(szContId , NULL, "ABContactDelete"); - else - { + MSN_ABAddDelContactGroup(szContId, NULL, "ABContactDelete"); + else { MSN_ABAddRemoveContact(szContId, NETID_MSN, true); MCONTACT hContact = MSN_HContactFromEmail(szEmail, szNick ? szNick : szEmail, true, false); setString(hContact, "ID", szContId); } status = 0; } - else if (status == 500) - { + else if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); if (strcmp(szErr, "InvalidPassportUser") == 0) @@ -1572,37 +1386,29 @@ unsigned CMsnProto::MSN_ABContactAdd(const char* szEmail, const char* szNick, in status = 2; else if (strcmp(szErr, "BadEmailArgument") == 0) status = 4; - else if (strcmp(szErr, "ContactAlreadyExists") == 0) - { + else if (strcmp(szErr, "ContactAlreadyExists") == 0) { status = 3; ezxml_t node = getSoapFault(xmlm, false); node = ezxml_get(node, "detail", 0, "additionalDetails", 0, "conflictObjectId", -1); const char* szContId = ezxml_txt(node); - if (search) - { - if (retry) - { - MSN_ABAddDelContactGroup(szContId , NULL, "ABContactDelete"); + if (search) { + if (retry) { + MSN_ABAddDelContactGroup(szContId, NULL, "ABContactDelete"); status = 0; } } - else - { + else { MCONTACT hContact = MSN_HContactFromEmail(szEmail, szNick ? szNick : szEmail, true, false); setString(hContact, "ID", szContId); } } - else if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + else if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_ABContactAdd(szEmail, szNick, netId, NULL, search, retry, false); } - else - { - status = MSN_ABContactAdd(szEmail, szNick, netId, NULL, search, false); - } + else status = MSN_ABContactAdd(szEmail, szNick, netId, NULL, search, false); } ezxml_free(xmlm); } @@ -1612,7 +1418,6 @@ unsigned CMsnProto::MSN_ABContactAdd(const char* szEmail, const char* szNick, in return status; } - void CMsnProto::MSN_ABUpdateDynamicItem(bool allowRecurse) { char* reqHdr; @@ -1662,7 +1467,7 @@ void CMsnProto::MSN_ABUpdateDynamicItem(bool allowRecurse) char tmstr[32]; mir_snprintf(tmstr, sizeof(tmstr), "%04u-%02u-%02uT%02u:%02u:%02uZ", - tmst->tm_year + 1900, tmst->tm_mon+1, tmst->tm_mday, + tmst->tm_year + 1900, tmst->tm_mon + 1, tmst->tm_mday, tmst->tm_hour, tmst->tm_min, tmst->tm_sec); ezxml_set_txt(node, tmstr); @@ -1680,8 +1485,7 @@ void CMsnProto::MSN_ABUpdateDynamicItem(bool allowRecurse) unsigned status; char *abUrl = NULL, *tResult; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(abUrl); abUrl = GetABHost("UpdateDynamicItem", false); tResult = getSslResult(&abUrl, szData, reqHdr, status); @@ -1692,16 +1496,13 @@ void CMsnProto::MSN_ABUpdateDynamicItem(bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateABHost("UpdateDynamicItem", abUrl); ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateABCacheKey(xmlm, false); - if (status == 500) - { + if (status == 500) { const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); MSN_ABUpdateDynamicItem(false); } diff --git a/protocols/MSN/src/msn_soapstore.cpp b/protocols/MSN/src/msn_soapstore.cpp index 0edbe6b9b0..89d8bfe5b1 100644 --- a/protocols/MSN/src/msn_soapstore.cpp +++ b/protocols/MSN/src/msn_soapstore.cpp @@ -28,14 +28,13 @@ ezxml_t CMsnProto::storeSoapHdr(const char* service, const char* scenario, ezxml { ezxml_t xmlp = ezxml_new("soap:Envelope"); ezxml_set_attr(xmlp, "xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/"); - ezxml_set_attr(xmlp, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - ezxml_set_attr(xmlp, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); + ezxml_set_attr(xmlp, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + ezxml_set_attr(xmlp, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); ezxml_set_attr(xmlp, "xmlns:soapenc", "http://schemas.xmlsoap.org/soap/encoding/"); ezxml_t hdr = ezxml_add_child(xmlp, "soap:Header", 0); - if (storageCacheKey) - { + if (storageCacheKey) { ezxml_t cachehdr = ezxml_add_child(hdr, "AffinityCacheHeader", 0); ezxml_set_attr(cachehdr, "xmlns", "http://www.msn.com/webservices/storage/2008"); ezxml_t node = ezxml_add_child(cachehdr, "CacheKey", 0); @@ -122,10 +121,8 @@ bool CMsnProto::MSN_StoreCreateProfile(bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL) - { - if (status == 200) - { + if (tResult != NULL) { + if (status == 200) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); UpdateStoreCacheKey(xmlm); ezxml_t body = getSoapResponse(xmlm, "CreateProfile"); @@ -135,12 +132,10 @@ bool CMsnProto::MSN_StoreCreateProfile(bool allowRecurse) ezxml_free(xmlm); } - else if (status == 500) - { + else if (status == 500) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_StoreCreateProfile(false) ? 200 : 500; } @@ -178,12 +173,10 @@ bool CMsnProto::MSN_StoreShareItem(const char* id, bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL && status == 500) - { + if (tResult != NULL && status == 500) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_StoreCreateProfile(false) ? 200 : 500; } @@ -246,8 +239,7 @@ bool CMsnProto::MSN_StoreGetProfile(bool allowRecurse) unsigned status = 0; char *storeUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(storeUrl); storeUrl = GetStoreHost("GetProfile"); tResult = getSslResult(&storeUrl, szData, reqHdr, status); @@ -258,10 +250,8 @@ bool CMsnProto::MSN_StoreGetProfile(bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL) - { - if (status == 200) - { + if (tResult != NULL) { + if (status == 200) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); ezxml_t body = getSoapResponse(xmlm, "GetProfile"); @@ -270,14 +260,12 @@ bool CMsnProto::MSN_StoreGetProfile(bool allowRecurse) mir_snprintf(proresid, sizeof(proresid), "%s", ezxml_txt(ezxml_child(body, "ResourceID"))); ezxml_t expr = ezxml_child(body, "ExpressionProfile"); - if (expr == NULL) - { + if (expr == NULL) { MSN_StoreShareItem(proresid); MSN_SharingMyProfile(); if (allowRecurse) MSN_StoreGetProfile(false); } - else - { + else { const char* szNick = ezxml_txt(ezxml_child(expr, "DisplayName")); setStringUtf(NULL, "Nick", (char*)szNick); @@ -290,11 +278,9 @@ bool CMsnProto::MSN_StoreGetProfile(bool allowRecurse) mir_snprintf(photoid, sizeof(photoid), "%s", ezxml_txt(ezxml_child(photo, "ResourceID"))); ezxml_t docstr = ezxml_get(photo, "DocumentStreams", 0, "DocumentStream", -1); - while (docstr) - { + while (docstr) { const char *docname = ezxml_txt(ezxml_child(docstr, "DocumentStreamName")); - if (!strcmp(docname, "UserTileStatic")) - { + if (!strcmp(docname, "UserTileStatic")) { getMyAvatarFile(ezxml_txt(ezxml_child(docstr, "PreAuthURL")), _T("miranda_avatar.tmp")); break; } @@ -303,17 +289,14 @@ bool CMsnProto::MSN_StoreGetProfile(bool allowRecurse) } ezxml_free(xmlm); } - else if (status == 500 && allowRecurse) - { + else if (status == 500 && allowRecurse) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0) - { + if (strcmp(szErr, "PassportAuthFail") == 0) { MSN_GetPassportAuth(); MSN_StoreGetProfile(false); } - else - { + else { MSN_StoreCreateProfile(); if (MSN_StoreGetProfile(false)) status = 200; } @@ -342,13 +325,11 @@ bool CMsnProto::MSN_StoreUpdateProfile(const char* szNick, const char* szStatus, ezxml_t expro = ezxml_add_child(pro, "ExpressionProfile", 0); node = ezxml_add_child(expro, "FreeText", 0); ezxml_set_txt(node, "Update"); - if (szNick) - { + if (szNick) { node = ezxml_add_child(expro, "DisplayName", 0); ezxml_set_txt(node, szNick); } - if (szStatus) - { + if (szStatus) { node = ezxml_add_child(expro, "PersonalStatus", 0); ezxml_set_txt(node, szStatus); } @@ -362,8 +343,7 @@ bool CMsnProto::MSN_StoreUpdateProfile(const char* szNick, const char* szStatus, unsigned status = 0; char *storeUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(storeUrl); storeUrl = GetStoreHost("UpdateProfile"); tResult = getSslResult(&storeUrl, szData, reqHdr, status); @@ -374,20 +354,16 @@ bool CMsnProto::MSN_StoreUpdateProfile(const char* szNick, const char* szStatus, mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateStoreHost("UpdateProfile", storeUrl); - if (status == 200) - { + if (status == 200) { replaceStr(msnLastStatusMsg, szStatus); MSN_ABUpdateDynamicItem(); } - else if (status == 500 && allowRecurse) - { + else if (status == 500 && allowRecurse) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0) - { + if (strcmp(szErr, "PassportAuthFail") == 0) { MSN_GetPassportAuth(); status = MSN_StoreUpdateProfile(szNick, szStatus, lock, false) ? 200 : 500; } @@ -428,8 +404,7 @@ bool CMsnProto::MSN_StoreCreateRelationships(bool allowRecurse) unsigned status = 0; char *storeUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(storeUrl); storeUrl = GetStoreHost("CreateRelationships"); tResult = getSslResult(&storeUrl, szData, reqHdr, status); @@ -440,16 +415,13 @@ bool CMsnProto::MSN_StoreCreateRelationships(bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateStoreHost("CreateRelationships", storeUrl); - if (status == 500) - { + if (status == 500) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_StoreCreateRelationships(false) ? 200 : 500; } @@ -473,8 +445,7 @@ bool CMsnProto::MSN_StoreDeleteRelationships(bool tile, bool allowRecurse) ezxml_t srch = ezxml_add_child(tbdy, "sourceHandle", 0); ezxml_t node; - if (tile) - { + if (tile) { node = ezxml_add_child(srch, "RelationshipName", 0); ezxml_set_txt(node, "/UserTiles"); @@ -484,8 +455,7 @@ bool CMsnProto::MSN_StoreDeleteRelationships(bool tile, bool allowRecurse) node = ezxml_add_child(alias, "NameSpace", 0); ezxml_set_txt(node, "MyCidStuff"); } - else - { + else { node = ezxml_add_child(srch, "ResourceID", 0); ezxml_set_txt(node, expresid); } @@ -502,8 +472,7 @@ bool CMsnProto::MSN_StoreDeleteRelationships(bool tile, bool allowRecurse) unsigned status = 0; char *storeUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(storeUrl); storeUrl = GetStoreHost("DeleteRelationships"); tResult = getSslResult(&storeUrl, szData, reqHdr, status); @@ -514,15 +483,12 @@ bool CMsnProto::MSN_StoreDeleteRelationships(bool tile, bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateStoreHost("DeleteRelationships", storeUrl); - if (status == 500) - { + if (status == 500) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_StoreDeleteRelationships(tile, false) ? 200 : 500; } @@ -583,8 +549,7 @@ bool CMsnProto::MSN_StoreCreateDocument(const TCHAR *sztName, const char *szMime unsigned status = 0; char *storeUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(storeUrl); storeUrl = GetStoreHost("CreateDocument"); tResult = getSslResult(&storeUrl, szData, reqHdr, status); @@ -595,22 +560,18 @@ bool CMsnProto::MSN_StoreCreateDocument(const TCHAR *sztName, const char *szMime mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateStoreHost("CreateDocument", storeUrl); - if (status == 200) - { + if (status == 200) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); ezxml_t bdy = getSoapResponse(xmlm, "CreateDocument"); mir_snprintf(photoid, sizeof(photoid), "%s", ezxml_txt(bdy)); ezxml_free(xmlm); } - else if (status == 500) - { + else if (status == 500) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_StoreCreateDocument(sztName, szMimeType, szPicData, false) ? 200 : 500; } @@ -660,8 +621,7 @@ bool CMsnProto::MSN_StoreUpdateDocument(const TCHAR *sztName, const char *szMime unsigned status = 0; char *storeUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(storeUrl); storeUrl = GetStoreHost("UpdateDocument"); tResult = getSslResult(&storeUrl, szData, reqHdr, status); @@ -672,20 +632,16 @@ bool CMsnProto::MSN_StoreUpdateDocument(const TCHAR *sztName, const char *szMime mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateStoreHost("UpdateDocument", storeUrl); - if (status == 500 && allowRecurse) - { + if (status == 500 && allowRecurse) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0) - { + if (strcmp(szErr, "PassportAuthFail") == 0) { MSN_GetPassportAuth(); status = MSN_StoreUpdateDocument(sztName, szMimeType, szPicData, false) ? 200 : 500; } - else if (szErr[0]) - { + else if (szErr[0]) { MSN_StoreDeleteRelationships(true); MSN_StoreDeleteRelationships(false); @@ -702,7 +658,6 @@ bool CMsnProto::MSN_StoreUpdateDocument(const TCHAR *sztName, const char *szMime return status == 200; } - bool CMsnProto::MSN_StoreFindDocuments(bool allowRecurse) { char* reqHdr; @@ -746,8 +701,7 @@ bool CMsnProto::MSN_StoreFindDocuments(bool allowRecurse) unsigned status = 0; char *storeUrl = NULL, *tResult = NULL; - for (int k = 4; --k;) - { + for (int k = 4; --k;) { mir_free(storeUrl); storeUrl = GetStoreHost("FindDocuments"); tResult = getSslResult(&storeUrl, szData, reqHdr, status); @@ -758,15 +712,12 @@ bool CMsnProto::MSN_StoreFindDocuments(bool allowRecurse) mir_free(reqHdr); free(szData); - if (tResult != NULL) - { + if (tResult != NULL) { UpdateStoreHost("FindDocuments", storeUrl); - if (status == 500) - { + if (status == 500) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); - if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) - { + if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse) { MSN_GetPassportAuth(); status = MSN_StoreFindDocuments(false) ? 200 : 500; } diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp index 57eee9f381..fab6bb59a2 100644 --- a/protocols/MSN/src/msn_srv.cpp +++ b/protocols/MSN/src/msn_srv.cpp @@ -23,7 +23,6 @@ along with this program. If not, see . #include "msn_global.h" #include "msn_proto.h" - ///////////////////////////////////////////////////////////////////////////////////////// // MSN_AddGroup - adds new server group to the list @@ -39,7 +38,7 @@ void CMsnProto::MSN_AddGroup(const char* grpName, const char *grpId, bool init) grpList.insert(p); if (init) - Clist_CreateGroup(0, ptrT( mir_utf8decodeT(grpName))); + Clist_CreateGroup(0, ptrT(mir_utf8decodeT(grpName))); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -48,8 +47,7 @@ void CMsnProto::MSN_AddGroup(const char* grpName, const char *grpId, bool init) void CMsnProto::MSN_DeleteGroup(const char* pId) { int i = grpList.getIndex((ServerGroupItem*)&pId); - if (i > -1) - { + if (i > -1) { ServerGroupItem* p = grpList[i]; mir_free(p->id); mir_free(p->name); @@ -68,14 +66,12 @@ void CMsnProto::MSN_DeleteServerGroup(LPCSTR szId) MSN_ABAddDelContactGroup(NULL, szId, "ABGroupDelete"); int count = -1; - for (;;) - { + for (;;) { MsnContact *msc = Lists_GetNext(count); if (msc == NULL) break; char szGroupID[100]; - if (!db_get_static(msc->hContact, m_szModuleName, "GroupID", szGroupID, sizeof(szGroupID))) - { + if (!db_get_static(msc->hContact, m_szModuleName, "GroupID", szGroupID, sizeof(szGroupID))) { if (strcmp(szGroupID, szId) == 0) delSetting(msc->hContact, "GroupID"); } @@ -88,7 +84,7 @@ void CMsnProto::MSN_DeleteServerGroup(LPCSTR szId) void CMsnProto::MSN_FreeGroups(void) { - for (int i=0; i < grpList.getCount(); i++) { + for (int i = 0; i < grpList.getCount(); i++) { ServerGroupItem* p = grpList[i]; mir_free(p->id); mir_free(p->name); @@ -111,8 +107,7 @@ LPCSTR CMsnProto::MSN_GetGroupById(const char* pId) LPCSTR CMsnProto::MSN_GetGroupByName(const char* pName) { - for (int i=0; i < grpList.getCount(); i++) - { + for (int i = 0; i < grpList.getCount(); i++) { const ServerGroupItem* p = grpList[i]; if (strcmp(p->name, pName) == 0) return p->id; @@ -183,22 +178,19 @@ void CMsnProto::MSN_RemoveEmptyGroups(void) unsigned *cCount = (unsigned*)mir_calloc(grpList.getCount() * sizeof(unsigned)); int count = -1; - for (;;) - { + for (;;) { MsnContact *msc = Lists_GetNext(count); if (msc == NULL) break; char szGroupID[100]; - if (!db_get_static(msc->hContact, m_szModuleName, "GroupID", szGroupID, sizeof(szGroupID))) - { + if (!db_get_static(msc->hContact, m_szModuleName, "GroupID", szGroupID, sizeof(szGroupID))) { const char *pId = szGroupID; int i = grpList.getIndex((ServerGroupItem*)&pId); if (i > -1) ++cCount[i]; } } - for (int i=grpList.getCount(); i--;) - { + for (int i = grpList.getCount(); i--;) { if (cCount[i] == 0) MSN_DeleteServerGroup(grpList[i]->id); } mir_free(cCount); @@ -222,18 +214,15 @@ void CMsnProto::MSN_UploadServerGroups(char* group) if (!MyOptions.ManageServer) return; int count = -1; - for (;;) - { + for (;;) { MsnContact *msc = Lists_GetNext(count); if (msc == NULL) break; DBVARIANT dbv; - if (!db_get_utf(msc->hContact, "CList", "Group", &dbv)) - { + if (!db_get_utf(msc->hContact, "CList", "Group", &dbv)) { char szGroupID[100]; if (group == NULL || (strcmp(group, dbv.pszVal) == 0 && - db_get_static(msc->hContact, m_szModuleName, "GroupID", szGroupID, sizeof(szGroupID)) != 0)) - { + db_get_static(msc->hContact, m_szModuleName, "GroupID", szGroupID, sizeof(szGroupID)) != 0)) { MSN_MoveContactToGroup(msc->hContact, dbv.pszVal); } db_free(&dbv); @@ -259,9 +248,8 @@ void CMsnProto::MSN_SyncContactToServerGroup(MCONTACT hContact, const char* szCo } const char* szGrpIdF = NULL; - while(cgrp != NULL) - { - const char* szGrpId = ezxml_txt(cgrp); + while (cgrp != NULL) { + const char* szGrpId = ezxml_txt(cgrp); cgrp = ezxml_next(cgrp); const char* szGrpNameById = MSN_GetGroupById(szGrpId); @@ -273,15 +261,13 @@ void CMsnProto::MSN_SyncContactToServerGroup(MCONTACT hContact, const char* szCo MSN_ABAddDelContactGroup(szContId, szGrpId, "ABGroupContactDelete"); } - if (szGrpIdF != NULL) - { + if (szGrpIdF != NULL) { setString(hContact, "GroupID", szGrpIdF); const char* szGrpNameById = MSN_GetGroupById(szGrpIdF); if (strcmp(szGrpNameById, szGrpName)) db_set_utf(hContact, "CList", "Group", szGrpNameById); } - else - { + else { if (szGrpName[0]) db_unset(hContact, "CList", "Group"); delSetting(hContact, "GroupID"); @@ -340,8 +326,7 @@ void CMsnProto::msn_storeAvatarThread(void* arg) MSN_ABUpdateDynamicItem(); - if (dat) - { + if (dat) { mir_free(dat->szName); mir_free(dat->data); mir_free(dat); @@ -356,8 +341,7 @@ void CMsnProto::msn_storeProfileThread(void* param) DBVARIANT dbv; char *szNick = NULL; bool needFree = false; - if (!getStringUtf("Nick", &dbv)) - { + if (!getStringUtf("Nick", &dbv)) { szNick = dbv.pszVal[0] ? dbv.pszVal : NULL; needFree = true; } @@ -365,14 +349,9 @@ void CMsnProto::msn_storeProfileThread(void* param) char** msgptr = GetStatusMsgLoc(m_iStatus); char *szStatus = msgptr ? *msgptr : NULL; - if (param || (msnLastStatusMsg != szStatus && - (msnLastStatusMsg && szStatus && strcmp(msnLastStatusMsg, szStatus)))) - { - + if (param || (msnLastStatusMsg != szStatus && (msnLastStatusMsg && szStatus && strcmp(msnLastStatusMsg, szStatus)))) if (MSN_StoreUpdateProfile(szNick, szStatus, false)) MSN_ABUpdateDynamicItem(); - // MSN_ABUpdateNick(nickname, NULL); - } if (needFree) db_free(&dbv); } diff --git a/protocols/MSN/src/msn_ssl.cpp b/protocols/MSN/src/msn_ssl.cpp index 42b324655c..b4f0402e4b 100644 --- a/protocols/MSN/src/msn_ssl.cpp +++ b/protocols/MSN/src/msn_ssl.cpp @@ -28,7 +28,7 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char mHttpsTS = clock(); char* result = NULL; - NETLIBHTTPREQUEST nlhr = {0}; + NETLIBHTTPREQUEST nlhr = { 0 }; // initialize the netlib request nlhr.cbSize = sizeof(nlhr); @@ -44,28 +44,26 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char #endif nlhr.headersCount = 4; - nlhr.headers=(NETLIBHTTPHEADER*)alloca(sizeof(NETLIBHTTPHEADER) * (nlhr.headersCount + 5)); - nlhr.headers[0].szName = "User-Agent"; + nlhr.headers = (NETLIBHTTPHEADER*)alloca(sizeof(NETLIBHTTPHEADER) * (nlhr.headersCount + 5)); + nlhr.headers[0].szName = "User-Agent"; nlhr.headers[0].szValue = (char*)MSN_USER_AGENT; - nlhr.headers[1].szName = "Accept"; + nlhr.headers[1].szName = "Accept"; nlhr.headers[1].szValue = "text/*"; - nlhr.headers[2].szName = "Content-Type"; + nlhr.headers[2].szName = "Content-Type"; nlhr.headers[2].szValue = "text/xml; charset=utf-8"; - nlhr.headers[3].szName = "Cache-Control"; + nlhr.headers[3].szName = "Cache-Control"; nlhr.headers[3].szValue = "no-cache"; - if (hdrs) - { + if (hdrs) { unsigned count = 0; char* hdrprs = NEWSTR_ALLOCA(hdrs); - for (;;) - { + for (;;) { char* fnd = strchr(hdrprs, ':'); if (fnd == NULL) break; *fnd = 0; fnd += 2; - nlhr.headers[nlhr.headersCount].szName = hdrprs; + nlhr.headers[nlhr.headersCount].szName = hdrprs; nlhr.headers[nlhr.headersCount].szValue = fnd; fnd = strchr(fnd, '\r'); @@ -78,15 +76,13 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char // download the page NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, - (WPARAM)hNetlibUserHttps,(LPARAM)&nlhr); + (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); - if (nlhrReply) - { + if (nlhrReply) { hHttpsConnection = nlhrReply->nlc; status = nlhrReply->resultCode; - if (nlhrReply->szUrl) - { + if (nlhrReply->szUrl) { mir_free(*parUrl); *parUrl = nlhrReply->szUrl; nlhrReply->szUrl = NULL; @@ -109,7 +105,7 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char bool CMsnProto::getMyAvatarFile(char *url, TCHAR *fname) { - NETLIBHTTPREQUEST nlhr = {0}; + NETLIBHTTPREQUEST nlhr = { 0 }; bool result = true; // initialize the netlib request @@ -119,16 +115,15 @@ bool CMsnProto::getMyAvatarFile(char *url, TCHAR *fname) nlhr.szUrl = url; nlhr.headersCount = 1; - nlhr.headers=(NETLIBHTTPHEADER*)alloca(sizeof(NETLIBHTTPHEADER) * nlhr.headersCount); - nlhr.headers[0].szName = "User-Agent"; + nlhr.headers = (NETLIBHTTPHEADER*)alloca(sizeof(NETLIBHTTPHEADER) * nlhr.headersCount); + nlhr.headers[0].szName = "User-Agent"; nlhr.headers[0].szValue = (char*)MSN_USER_AGENT; // download the page NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, - (WPARAM)hNetlibUserHttps,(LPARAM)&nlhr); + (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); - if (nlhrReply) - { + if (nlhrReply) { if (nlhrReply->resultCode == 200 && nlhrReply->dataLength) MSN_SetMyAvatar(fname, nlhrReply->pData, nlhrReply->dataLength); else diff --git a/protocols/MSN/src/msn_std.cpp b/protocols/MSN/src/msn_std.cpp index b6e2163e4d..c0dfa87833 100644 --- a/protocols/MSN/src/msn_std.cpp +++ b/protocols/MSN/src/msn_std.cpp @@ -27,15 +27,18 @@ along with this program. If not, see . // Standard functions int CMsnProto::getStringUtf(MCONTACT hContact, const char* name, DBVARIANT* result) -{ return db_get_utf(hContact, m_szModuleName, name, result); +{ + return db_get_utf(hContact, m_szModuleName, name, result); } int CMsnProto::getStringUtf(const char* name, DBVARIANT* result) -{ return db_get_utf(NULL, m_szModuleName, name, result); +{ + return db_get_utf(NULL, m_szModuleName, name, result); } void CMsnProto::setStringUtf(MCONTACT hContact, const char* name, const char* value) -{ db_set_utf(hContact, m_szModuleName, name, value); +{ + db_set_utf(hContact, m_szModuleName, name, value); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -44,17 +47,15 @@ TCHAR* CMsnProto::GetContactNameT(MCONTACT hContact) { if (hContact) return (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, WPARAM(hContact), GCDNF_TCHAR); + + CONTACTINFO ci = { 0 }; + ci.cbSize = sizeof(ci); + ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; + ci.szProto = m_szModuleName; + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) + return (TCHAR*)ci.pszVal; else - { - CONTACTINFO ci = {0}; - ci.cbSize = sizeof(ci); - ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; - ci.szProto = m_szModuleName; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) - return (TCHAR*)ci.pszVal; - else - return _T("Me"); - } + return _T("Me"); } unsigned MSN_GenRandom(void) diff --git a/protocols/MSN/src/msn_svcs.cpp b/protocols/MSN/src/msn_svcs.cpp index 9c6c61b915..62d433b4b0 100644 --- a/protocols/MSN/src/msn_svcs.cpp +++ b/protocols/MSN/src/msn_svcs.cpp @@ -28,7 +28,7 @@ extern int avsPresent; ///////////////////////////////////////////////////////////////////////////////////////// // GetMyAwayMsg - obtain the current away message -INT_PTR CMsnProto::GetMyAwayMsg(WPARAM wParam,LPARAM lParam) +INT_PTR CMsnProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam) { char** msgptr = GetStatusMsgLoc(wParam ? wParam : m_iStatus); if (msgptr == NULL) return 0; @@ -61,9 +61,9 @@ void CMsnProto::sttFakeAvatarAck(void* arg) ProtoBroadcastAck(((PROTO_AVATAR_INFORMATIONT*)arg)->hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, arg, 0); } -INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam,LPARAM lParam) +INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) { - PROTO_AVATAR_INFORMATIONT* AI = (PROTO_AVATAR_INFORMATIONT*)lParam; + PROTO_AVATAR_INFORMATIONT *AI = (PROTO_AVATAR_INFORMATIONT*)lParam; TCHAR filename[MAX_PATH]; MsnContact *cont = NULL; @@ -85,7 +85,7 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam,LPARAM lParam) char *szContext; DBVARIANT dbv; - if ( getString(AI->hContact, AI->hContact ? "PictContext" : "PictObject", &dbv) == 0) { + if (getString(AI->hContact, AI->hContact ? "PictContext" : "PictObject", &dbv) == 0) { szContext = (char*)NEWSTR_ALLOCA(dbv.pszVal); db_free(&dbv); } @@ -127,7 +127,7 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam,LPARAM lParam) *fakeAI = *AI; ForkThread(&CMsnProto::sttFakeAvatarAck, fakeAI); } - else if ( !getString(AI->hContact, "AvatarUrl", &dbv)) { + else if (!getString(AI->hContact, "AvatarUrl", &dbv)) { pushAvatarRequest(AI->hContact, dbv.pszVal); db_free(&dbv); } @@ -154,8 +154,7 @@ INT_PTR CMsnProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) { int res = 0; - switch (wParam) - { + switch (wParam) { case AF_MAXSIZE: ((POINT*)lParam)->x = 96; ((POINT*)lParam)->y = 96; @@ -188,14 +187,12 @@ INT_PTR CMsnProto::SetAvatar(WPARAM wParam, LPARAM lParam) MSN_GetAvatarFileName(NULL, tFileName, SIZEOF(tFileName), NULL); _tremove(tFileName); - if (szFileName == NULL) - { + if (szFileName == NULL) { delSetting("PictObject"); delSetting("AvatarHash"); ForkThread(&CMsnProto::msn_storeAvatarThread, NULL); } - else - { + else { int fileId = _topen(szFileName, _O_RDONLY | _O_BINARY, _S_IREAD); if (fileId < 0) return 1; @@ -261,21 +258,19 @@ INT_PTR CMsnProto::SendNudge(WPARAM hContact, LPARAM lParam) case NETID_MSN: case NETID_LCS: - { - bool isOffline; - ThreadData* thread = MSN_StartSB(tEmail, isOffline); - if (thread == NULL) - { - if (isOffline) return 0; - MsgQueue_Add(tEmail, 'N', nudgemsg, -1); - } - else - { - int tNnetId = netId == NETID_UNKNOWN ? NETID_MSN : netId; - thread->sendMessage('N', tEmail, tNnetId, nudgemsg, MSG_DISABLE_HDR); - } + { + bool isOffline; + ThreadData* thread = MSN_StartSB(tEmail, isOffline); + if (thread == NULL) { + if (isOffline) return 0; + MsgQueue_Add(tEmail, 'N', nudgemsg, -1); } - break; + else { + int tNnetId = netId == NETID_UNKNOWN ? NETID_MSN : netId; + thread->sendMessage('N', tEmail, tNnetId, nudgemsg, MSG_DISABLE_HDR); + } + } + break; case NETID_YAHOO: msnNsThread->sendMessage('3', tEmail, netId, nudgemsg, MSG_DISABLE_HDR); @@ -330,8 +325,7 @@ INT_PTR CMsnProto::SetCurrentMedia(WPARAM wParam, LPARAM lParam) // Copy new info LISTENINGTOINFO *cm = (LISTENINGTOINFO *)lParam; - if (cm != NULL && cm->cbSize == sizeof(LISTENINGTOINFO) && (cm->ptszArtist != NULL || cm->ptszTitle != NULL)) - { + if (cm != NULL && cm->cbSize == sizeof(LISTENINGTOINFO) && (cm->ptszArtist != NULL || cm->ptszTitle != NULL)) { bool unicode = (cm->dwFlags & LTI_UNICODE) != 0; msnCurrentMedia.cbSize = sizeof(msnCurrentMedia); // Marks that there is info set @@ -351,16 +345,14 @@ INT_PTR CMsnProto::SetCurrentMedia(WPARAM wParam, LPARAM lParam) // Set user text if (msnCurrentMedia.cbSize == 0) delSetting("ListeningTo"); - else - { + else { TCHAR *text; if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)) - text = (TCHAR *) CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM) _T("%title% - %artist%"), (LPARAM) &msnCurrentMedia); - else - { - text = (TCHAR *) mir_alloc(128 * sizeof(TCHAR)); + text = (TCHAR *)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)_T("%title% - %artist%"), (LPARAM)&msnCurrentMedia); + else { + text = (TCHAR *)mir_alloc(128 * sizeof(TCHAR)); mir_sntprintf(text, 128, _T("%s - %s"), (msnCurrentMedia.ptszTitle ? msnCurrentMedia.ptszTitle : _T("")), - (msnCurrentMedia.ptszArtist ? msnCurrentMedia.ptszArtist : _T(""))); + (msnCurrentMedia.ptszArtist ? msnCurrentMedia.ptszArtist : _T(""))); } setTString("ListeningTo", text); mir_free(text); @@ -381,7 +373,7 @@ int CMsnProto::OnContactDeleted(WPARAM hContact, LPARAM lParam) if (!msnLoggedIn) //should never happen for MSN contacts return 0; - if ( isChatRoom(hContact)) { + if (isChatRoom(hContact)) { DBVARIANT dbv; if (!getTString(hContact, "ChatRoomID", &dbv)) { MSN_KillChatSession(dbv.ptszVal); @@ -391,24 +383,22 @@ int CMsnProto::OnContactDeleted(WPARAM hContact, LPARAM lParam) else { char szEmail[MSN_MAX_EMAIL_LEN]; if (MSN_IsMeByContact(hContact, szEmail)) - CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM) 1); + CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM)1); - if (szEmail[0]) - { + if (szEmail[0]) { debugLogA("Deleted Handler Email"); - if (Lists_IsInList(LIST_FL, szEmail)) - { + if (Lists_IsInList(LIST_FL, szEmail)) { DeleteParam param = { this, hContact }; DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DELETECONTACT), NULL, DlgDeleteContactUI, (LPARAM)¶m); - MsnContact* msc = Lists_Get(szEmail); - if (msc) msc->hContact = NULL; + MsnContact *msc = Lists_Get(szEmail); + if (msc) + msc->hContact = NULL; } + if (Lists_IsInList(LIST_LL, szEmail)) - { MSN_AddUser(hContact, szEmail, 0, LIST_LL | LIST_REMOVE); - } } } @@ -422,27 +412,21 @@ int CMsnProto::OnGroupChange(WPARAM hContact, LPARAM lParam) const CLISTGROUPCHANGE* grpchg = (CLISTGROUPCHANGE*)lParam; - if (hContact == NULL) - { - if (grpchg->pszNewName == NULL && grpchg->pszOldName != NULL) - { + if (hContact == NULL) { + if (grpchg->pszNewName == NULL && grpchg->pszOldName != NULL) { LPCSTR szId = MSN_GetGroupByName(UTF8(grpchg->pszOldName)); - if (szId != NULL) MSN_DeleteServerGroup(szId); + if (szId != NULL) + MSN_DeleteServerGroup(szId); } - else if (grpchg->pszNewName != NULL && grpchg->pszOldName != NULL) - { + else if (grpchg->pszNewName != NULL && grpchg->pszOldName != NULL) { LPCSTR szId = MSN_GetGroupByName(UTF8(grpchg->pszOldName)); - if (szId != NULL) MSN_RenameServerGroup(szId, UTF8(grpchg->pszNewName)); + if (szId != NULL) + MSN_RenameServerGroup(szId, UTF8(grpchg->pszNewName)); } } - else - { + else { if (MSN_IsMyContact(hContact)) - { - char* szNewName = grpchg->pszNewName ? mir_utf8encodeT(grpchg->pszNewName) : NULL; - MSN_MoveContactToGroup(hContact, szNewName); - mir_free(szNewName); - } + MSN_MoveContactToGroup(hContact, ptrA(mir_utf8encodeT(grpchg->pszNewName))); } return 0; } @@ -458,57 +442,48 @@ int CMsnProto::OnDbSettingChanged(WPARAM hContact, LPARAM lParam) if (!msnLoggedIn) return 0; - if (hContact == NULL) - { + if (hContact == NULL) { if (MyOptions.SlowSend && strcmp(cws->szSetting, "MessageTimeout") == 0 && - (strcmp(cws->szModule, "SRMM") == 0 || strcmp(cws->szModule, "SRMsg") == 0)) - { + (strcmp(cws->szModule, "SRMM") == 0 || strcmp(cws->szModule, "SRMsg") == 0)) { if (cws->value.dVal < 60000) MessageBox(NULL, TranslateT("MSN requires message send timeout in your Message window plugin to be not less then 60 sec. Please correct the timeout value."), - TranslateT("MSN Protocol"), MB_OK|MB_ICONINFORMATION); + TranslateT("MSN Protocol"), MB_OK | MB_ICONINFORMATION); } return 0; } - if (!strcmp(cws->szSetting, "ApparentMode")) - { + if (!strcmp(cws->szSetting, "ApparentMode")) { char tEmail[MSN_MAX_EMAIL_LEN]; - if (!db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail))) - { + if (!db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail))) { bool isBlocked = Lists_IsInList(LIST_BL, tEmail); - if (isBlocked && (cws->value.type == DBVT_DELETED || cws->value.wVal == 0)) - { + if (isBlocked && (cws->value.type == DBVT_DELETED || cws->value.wVal == 0)) { MSN_AddUser(hContact, tEmail, 0, LIST_BL + LIST_REMOVE); MSN_AddUser(hContact, tEmail, 0, LIST_AL); } - else if (!isBlocked && cws->value.wVal == ID_STATUS_OFFLINE) - { + else if (!isBlocked && cws->value.wVal == ID_STATUS_OFFLINE) { MSN_AddUser(hContact, tEmail, 0, LIST_AL + LIST_REMOVE); MSN_AddUser(hContact, tEmail, 0, LIST_BL); } } } - if (!strcmp(cws->szSetting, "MyHandle") && !strcmp(cws->szModule, "CList")) - { + if (!strcmp(cws->szSetting, "MyHandle") && !strcmp(cws->szModule, "CList")) { bool isMe = MSN_IsMeByContact(hContact); - if (!isMe || !nickChg) - { + if (!isMe || !nickChg) { char szContactID[100]; - if (!db_get_static(hContact, m_szModuleName, "ID", szContactID, sizeof(szContactID))) - { - if (cws->value.type != DBVT_DELETED) - { + if (!db_get_static(hContact, m_szModuleName, "ID", szContactID, sizeof(szContactID))) { + if (cws->value.type != DBVT_DELETED) { if (cws->value.type == DBVT_UTF8) MSN_ABUpdateNick(cws->value.pszVal, szContactID); else MSN_ABUpdateNick(UTF8(cws->value.pszVal), szContactID); } - else - MSN_ABUpdateNick(NULL, szContactID); + else MSN_ABUpdateNick(NULL, szContactID); } - if (isMe) displayEmailCount(hContact); + + if (isMe) + displayEmailCount(hContact); } } return 0; @@ -525,13 +500,11 @@ int CMsnProto::OnIdleChanged(WPARAM wParam, LPARAM lParam) bool bIdle = (lParam & IDF_ISIDLE) != 0; bool bPrivacy = (lParam & IDF_PRIVACY) != 0; - if (isIdle && !bIdle) - { + if (isIdle && !bIdle) { isIdle = false; MSN_SetServerStatus(m_iDesiredStatus); } - else if (!isIdle && bIdle && !bPrivacy && m_iDesiredStatus != ID_STATUS_AWAY) - { + else if (!isIdle && bIdle && !bPrivacy && m_iDesiredStatus != ID_STATUS_AWAY) { isIdle = true; MSN_SetServerStatus(ID_STATUS_IDLE); } @@ -544,10 +517,9 @@ int CMsnProto::OnIdleChanged(WPARAM wParam, LPARAM lParam) int CMsnProto::OnWindowEvent(WPARAM wParam, LPARAM lParam) { - MessageWindowEventData* msgEvData = (MessageWindowEventData*)lParam; + MessageWindowEventData* msgEvData = (MessageWindowEventData*)lParam; - if (msgEvData->uType == MSG_WINDOW_EVT_OPENING) - { + if (msgEvData->uType == MSG_WINDOW_EVT_OPENING) { if (m_iStatus == ID_STATUS_OFFLINE || m_iStatus == ID_STATUS_INVISIBLE) return 0; @@ -576,22 +548,17 @@ int CMsnProto::OnWindowEvent(WPARAM wParam, LPARAM lParam) int CMsnProto::OnWindowPopup(WPARAM wParam, LPARAM lParam) { MessageWindowPopupData *mwpd = (MessageWindowPopupData *)lParam; - if (!MSN_IsMyContact(mwpd->hContact) || isChatRoom(mwpd->hContact)) return 0; - switch (mwpd->uType) - { + switch (mwpd->uType) { case MSG_WINDOWPOPUP_SHOWING: AppendMenu(mwpd->hMenu, MF_STRING, 13465, TranslateT("Convert to Chat")); break; case MSG_WINDOWPOPUP_SELECTED: if (mwpd->selection == 13465) - { - DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, - LPARAM(new InviteChatParam(NULL, mwpd->hContact, this))); - } + DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, LPARAM(new InviteChatParam(NULL, mwpd->hContact, this))); break; } diff --git a/protocols/MSN/src/msn_switchboard.cpp b/protocols/MSN/src/msn_switchboard.cpp index 4ff32a7938..d8967f66c0 100644 --- a/protocols/MSN/src/msn_switchboard.cpp +++ b/protocols/MSN/src/msn_switchboard.cpp @@ -25,7 +25,7 @@ along with this program. If not, see . int ThreadData::contactJoined(const char* email) { - for (int i=0; i < mJoinedContactsWLID.getCount(); i++) + for (int i = 0; i < mJoinedContactsWLID.getCount(); i++) if (_stricmp(mJoinedContactsWLID[i], email) == 0) return mJoinedContactsWLID.getCount(); diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp index e643bce91b..fdaeb929b9 100644 --- a/protocols/MSN/src/msn_threads.cpp +++ b/protocols/MSN/src/msn_threads.cpp @@ -34,40 +34,35 @@ void __cdecl CMsnProto::msn_keepAliveThread(void*) msnPingTimeout = 45; - while (keepFlag) - { - switch (WaitForSingleObject(hKeepAliveThreadEvt, msnPingTimeout * 1000)) - { - case WAIT_TIMEOUT: - keepFlag = msnNsThread != NULL; - if (usingGateway) - msnPingTimeout = 45; - else - { - msnPingTimeout = 20; - keepFlag = keepFlag && msnNsThread->send("PNG\r\n", 5); - } - p2p_clearDormantSessions(); - if (hHttpsConnection && (clock() - mHttpsTS) > 60 * CLOCKS_PER_SEC) - { - HANDLE hConn = hHttpsConnection; - hHttpsConnection = NULL; - Netlib_CloseHandle(hConn); - } - if (mStatusMsgTS && (clock() - mStatusMsgTS) > 60 * CLOCKS_PER_SEC) - { - mStatusMsgTS = 0; - ForkThread(&CMsnProto::msn_storeProfileThread, NULL); - } - break; + while (keepFlag) { + switch (WaitForSingleObject(hKeepAliveThreadEvt, msnPingTimeout * 1000)) { + case WAIT_TIMEOUT: + keepFlag = msnNsThread != NULL; + if (usingGateway) + msnPingTimeout = 45; + else { + msnPingTimeout = 20; + keepFlag = keepFlag && msnNsThread->send("PNG\r\n", 5); + } + p2p_clearDormantSessions(); + if (hHttpsConnection && (clock() - mHttpsTS) > 60 * CLOCKS_PER_SEC) { + HANDLE hConn = hHttpsConnection; + hHttpsConnection = NULL; + Netlib_CloseHandle(hConn); + } + if (mStatusMsgTS && (clock() - mStatusMsgTS) > 60 * CLOCKS_PER_SEC) { + mStatusMsgTS = 0; + ForkThread(&CMsnProto::msn_storeProfileThread, NULL); + } + break; - case WAIT_OBJECT_0: - keepFlag = msnPingTimeout > 0; - break; + case WAIT_OBJECT_0: + keepFlag = msnPingTimeout > 0; + break; - default: - keepFlag = false; - break; + default: + keepFlag = false; + break; } } @@ -81,16 +76,22 @@ void __cdecl CMsnProto::msn_keepAliveThread(void*) void __cdecl CMsnProto::MSNServerThread(void* arg) { ThreadData* info = (ThreadData*)arg; - if (info->mIsMainThread) isConnectSuccess = false; - char* tPortDelim = strrchr(info->mServer, ':'); - if (tPortDelim != NULL) - *tPortDelim = '\0'; - - if (usingGateway) + int tPortNumber = -1; { + char* tPortDelim = strrchr(info->mServer, ':'); + if (tPortDelim != NULL) { + *tPortDelim = '\0'; + if ((tPortNumber = atoi(tPortDelim + 1)) == 0) + tPortNumber = -1; + else if (usingGateway && !(tPortNumber == 80 || tPortNumber == 443)) + usingGateway = false; + } + } + + if (usingGateway) { if (info->mServer[0] == 0) strcpy(info->mServer, MSN_DEFAULT_LOGIN_SERVER); else if (info->mIsMainThread) @@ -98,57 +99,47 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) if (info->gatewayType) strcpy(info->mGatewayIP, info->mServer); - else - { + else { if (info->mGatewayIP[0] == 0 && db_get_static(NULL, m_szModuleName, "GatewayServer", info->mGatewayIP, sizeof(info->mGatewayIP))) strcpy(info->mGatewayIP, MSN_DEFAULT_GATEWAY); } } - else - { + else { if (info->mServer[0] == 0 && db_get_static(NULL, m_szModuleName, "DirectServer", info->mServer, sizeof(info->mServer))) strcpy(info->mServer, MSN_DEFAULT_LOGIN_SERVER); } NETLIBOPENCONNECTION tConn = { 0 }; - tConn.cbSize = sizeof(tConn); - tConn.flags = NLOCF_V2; + tConn.cbSize = sizeof(tConn); + tConn.flags = NLOCF_V2; tConn.timeout = 5; - if (usingGateway) - { - tConn.flags |= NLOCF_HTTPGATEWAY; - tConn.szHost = info->mGatewayIP; - tConn.wPort = MSN_DEFAULT_GATEWAY_PORT; + if (usingGateway) { + tConn.flags |= NLOCF_HTTPGATEWAY; + tConn.szHost = info->mGatewayIP; + tConn.wPort = MSN_DEFAULT_GATEWAY_PORT; } - else - { - tConn.szHost = info->mServer; - tConn.wPort = MSN_DEFAULT_PORT; - if (tPortDelim != NULL) - { - int tPortNumber = atoi(tPortDelim + 1); - if (tPortNumber) - tConn.wPort = (WORD)tPortNumber; - } + else { + tConn.szHost = info->mServer; + tConn.wPort = MSN_DEFAULT_PORT; } + if (tPortNumber != -1) + tConn.wPort = (WORD)tPortNumber; debugLogA("Thread started: server='%s:%d', type=%d", tConn.szHost, tConn.wPort, info->mType); info->s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&tConn); - if (info->s == NULL) - { + if (info->s == NULL) { debugLogA("Connection Failed (%d) server='%s:%d'", WSAGetLastError(), tConn.szHost, tConn.wPort); - switch (info->mType) - { - case SERVER_NOTIFICATION: - goto LBL_Exit; - break; + switch (info->mType) { + case SERVER_NOTIFICATION: + goto LBL_Exit; + break; - case SERVER_SWITCHBOARD: - if (info->mCaller) msnNsThread->sendPacket("XFR", "SB"); - break; + case SERVER_SWITCHBOARD: + if (info->mCaller) msnNsThread->sendPacket("XFR", "SB"); + break; } return; } @@ -158,61 +149,51 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) debugLogA("Connected with handle=%08X", info->s); - if (info->mType == SERVER_NOTIFICATION) - { + if (info->mType == SERVER_NOTIFICATION) { info->sendPacket("VER", "MSNP18 MSNP17 CVR0"); } - else if (info->mType == SERVER_SWITCHBOARD) - { + else if (info->mType == SERVER_SWITCHBOARD) { info->sendPacket(info->mCaller ? "USR" : "ANS", "%s;%s %s", MyOptions.szEmail, MyOptions.szMachineGuid, info->mCookie); } - else if (info->mType == SERVER_FILETRANS && info->mCaller == 0) - { + else if (info->mType == SERVER_FILETRANS && info->mCaller == 0) { info->send("VER MSNFTP\r\n", 12); } - if (info->mIsMainThread) - { + if (info->mIsMainThread) { msnNsThread = info; } debugLogA("Entering main recv loop"); info->mBytesInData = 0; - for (;;) - { + for (;;) { int recvResult = info->recv(info->mData + info->mBytesInData, sizeof(info->mData) - info->mBytesInData); - if (recvResult == SOCKET_ERROR) - { + if (recvResult == SOCKET_ERROR) { debugLogA("Connection %08p [%08X] was abortively closed", info->s, GetCurrentThreadId()); break; } - if (!recvResult) - { + if (!recvResult) { debugLogA("Connection %08p [%08X] was gracefully closed", info->s, GetCurrentThreadId()); break; } info->mBytesInData += recvResult; - if (info->mCaller == 1 && info->mType == SERVER_FILETRANS) - { + if (info->mCaller == 1 && info->mType == SERVER_FILETRANS) { if (MSN_HandleMSNFTP(info, info->mData)) break; } - else - { - for (;;) - { + else { + for (;;) { char* peol = strchr(info->mData, '\r'); if (peol == NULL) break; - if (info->mBytesInData < peol-info->mData + 2) + if (info->mBytesInData < peol - info->mData + 2) break; //wait for full line end char msg[sizeof(info->mData)]; - memcpy(msg, info->mData, peol-info->mData); msg[peol-info->mData] = 0; + memcpy(msg, info->mData, peol - info->mData); msg[peol - info->mData] = 0; if (*++peol != '\n') debugLogA("Dodgy line ending to command: ignoring"); @@ -223,22 +204,19 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) memmove(info->mData, peol, info->mBytesInData); debugLogA("RECV: %s", msg); - if (!isalnum(msg[0]) || !isalnum(msg[1]) || !isalnum(msg[2]) || (msg[3] && msg[3] != ' ')) - { + if (!isalnum(msg[0]) || !isalnum(msg[1]) || !isalnum(msg[2]) || (msg[3] && msg[3] != ' ')) { debugLogA("Invalid command name"); continue; } - if (info->mType != SERVER_FILETRANS) - { + if (info->mType != SERVER_FILETRANS) { int handlerResult; if (isdigit(msg[0]) && isdigit(msg[1]) && isdigit(msg[2])) //all error messages handlerResult = MSN_HandleErrors(info, msg); else handlerResult = MSN_HandleCommands(info, msg); - if (handlerResult) - { + if (handlerResult) { if (info->sessionClosed) goto LBL_Exit; info->sendTerminate(); } @@ -249,18 +227,15 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) } } - if (info->mBytesInData == sizeof(info->mData)) - { + if (info->mBytesInData == sizeof(info->mData)) { debugLogA("sizeof(data) is too small: the longest line won't fit"); break; } } LBL_Exit: - if (info->mIsMainThread) - { - if (!isConnectSuccess && !usingGateway && m_iDesiredStatus != ID_STATUS_OFFLINE) - { + if (info->mIsMainThread) { + if (!isConnectSuccess && !usingGateway && m_iDesiredStatus != ID_STATUS_OFFLINE) { msnNsThread = NULL; usingGateway = true; @@ -270,24 +245,20 @@ LBL_Exit: newThread->startThread(&CMsnProto::MSNServerThread, this); } - else - { - if (hKeepAliveThreadEvt) - { + else { + if (hKeepAliveThreadEvt) { msnPingTimeout *= -1; SetEvent(hKeepAliveThreadEvt); } if (info->s == NULL) ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK); - else - { + else { p2p_cancelAllSessions(); MSN_CloseConnections(); } - if (hHttpsConnection) - { + if (hHttpsConnection) { Netlib_CloseHandle(hHttpsConnection); hHttpsConnection = NULL; } @@ -304,19 +275,16 @@ void CMsnProto::MSN_CloseConnections(void) { mir_cslockfull lck(csThreads); - NETLIBSELECTEX nls = {0}; + NETLIBSELECTEX nls = { 0 }; nls.cbSize = sizeof(nls); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; - switch (T->mType) - { - case SERVER_NOTIFICATION : - case SERVER_SWITCHBOARD : - if (T->s != NULL && !T->sessionClosed && !T->termPending) - { + switch (T->mType) { + case SERVER_NOTIFICATION: + case SERVER_SWITCHBOARD: + if (T->s != NULL && !T->sessionClosed && !T->termPending) { nls.hReadConns[0] = T->s; int res = CallService(MS_NETLIB_SELECTEX, 0, (LPARAM)&nls); if (res >= 0 || nls.hReadStatus[0] == 0) @@ -324,7 +292,7 @@ void CMsnProto::MSN_CloseConnections(void) } break; - case SERVER_P2P_DIRECT : + case SERVER_P2P_DIRECT: CallService(MS_NETLIB_SHUTDOWN, (WPARAM)T->s, 0); break; } @@ -346,10 +314,8 @@ ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type) { mir_cslock lck(csThreads); - if (type == SERVER_P2P_DIRECT) - { - for (int i=0; i < sttThreads.getCount(); i++) - { + if (type == SERVER_P2P_DIRECT) { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->mType != SERVER_P2P_DIRECT || !T->mJoinedIdentContactsWLID.getCount() || T->s == NULL) continue; @@ -362,8 +328,7 @@ ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type) char *szEmail = NULL; parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->mType != type || !T->mJoinedContactsWLID.getCount() || T->mInitialContactWLID || T->s == NULL) continue; @@ -379,8 +344,7 @@ ThreadData* CMsnProto::MSN_GetThreadByChatId(const TCHAR* chatId) { mir_cslock lck(csThreads); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (_tcsicmp(T->mChatID, chatId) == 0) @@ -394,8 +358,7 @@ ThreadData* CMsnProto::MSN_GetThreadByTimer(UINT timerId) { mir_cslock lck(csThreads); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->mType == SERVER_SWITCHBOARD && T->mTimerId == timerId) return T; @@ -408,8 +371,7 @@ ThreadData* CMsnProto::MSN_GetP2PThreadByContact(const char *wlid) { mir_cslock lck(csThreads); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->mType != SERVER_P2P_DIRECT || !T->mJoinedIdentContactsWLID.getCount()) continue; @@ -422,12 +384,10 @@ ThreadData* CMsnProto::MSN_GetP2PThreadByContact(const char *wlid) parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); ThreadData *result = NULL; - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->mJoinedContactsWLID.getCount() && !T->mInitialContactWLID && - _stricmp(T->mJoinedContactsWLID[0], szEmail) == 0) - { + _stricmp(T->mJoinedContactsWLID[0], szEmail) == 0) { if (T->mType == SERVER_P2P_DIRECT) return T; @@ -444,14 +404,12 @@ void CMsnProto::MSN_StartP2PTransferByContact(const char* wlid) { mir_cslock lck(csThreads); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; - if (T->mType == SERVER_FILETRANS && T->hWaitEvent != INVALID_HANDLE_VALUE) - { + if (T->mType == SERVER_FILETRANS && T->hWaitEvent != INVALID_HANDLE_VALUE) { if ((T->mInitialContactWLID && !_stricmp(T->mInitialContactWLID, wlid)) || - (T->mJoinedContactsWLID.getCount() && !_stricmp(T->mJoinedContactsWLID[0], wlid)) || - (T->mJoinedIdentContactsWLID.getCount() && !_stricmp(T->mJoinedIdentContactsWLID[0], wlid))) + (T->mJoinedContactsWLID.getCount() && !_stricmp(T->mJoinedContactsWLID[0], wlid)) || + (T->mJoinedIdentContactsWLID.getCount() && !_stricmp(T->mJoinedIdentContactsWLID[0], wlid))) ReleaseSemaphore(T->hWaitEvent, 1, NULL); } } @@ -462,8 +420,7 @@ ThreadData* CMsnProto::MSN_GetOtherContactThread(ThreadData* thread) { mir_cslock lck(csThreads); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->mJoinedContactsWLID.getCount() == 0 || T->s == NULL) continue; @@ -484,10 +441,9 @@ ThreadData* CMsnProto::MSN_GetUnconnectedThread(const char* wlid, TInfoType type if (type == SERVER_SWITCHBOARD && strchr(wlid, ';')) parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; - if (T->mType == type && T->mInitialContactWLID && _stricmp(T->mInitialContactWLID, szEmail) == 0) + if (T->mType == type && T->mInitialContactWLID && _stricmp(T->mInitialContactWLID, szEmail) == 0) return T; } @@ -499,12 +455,10 @@ ThreadData* CMsnProto::MSN_StartSB(const char* wlid, bool& isOffline) { isOffline = false; ThreadData* thread = MSN_GetThreadByContact(wlid); - if (thread == NULL) - { + if (thread == NULL) { MCONTACT hContact = MSN_HContactFromEmail(wlid); WORD wStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE); - if (wStatus != ID_STATUS_OFFLINE) - { + if (wStatus != ID_STATUS_OFFLINE) { if (MSN_GetUnconnectedThread(wlid) == NULL && MsgQueue_CheckContact(wlid, 5) == NULL) msnNsThread->sendPacket("XFR", "SB"); } @@ -520,8 +474,7 @@ int CMsnProto::MSN_GetActiveThreads(ThreadData** parResult) int tCount = 0; mir_cslock lck(csThreads); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->mType == SERVER_SWITCHBOARD && T->mJoinedContactsWLID.getCount() != 0 && T->mJoinedContactsWLID.getCount()) parResult[tCount++] = T; @@ -534,8 +487,7 @@ ThreadData* CMsnProto::MSN_GetThreadByConnection(HANDLE s) { mir_cslock lck(csThreads); - for (int i = 0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->s == s) return T; @@ -548,8 +500,7 @@ ThreadData* CMsnProto::MSN_GetThreadByPort(WORD wPort) { mir_cslock lck(csThreads); - for (int i=0; i < sttThreads.getCount(); i++) - { + for (int i = 0; i < sttThreads.getCount(); i++) { ThreadData* T = &sttThreads[i]; if (T->mIncomingPort == wPort) return T; @@ -563,7 +514,7 @@ ThreadData* CMsnProto::MSN_GetThreadByPort(WORD wPort) ThreadData::ThreadData() { - memset(&mInitialContactWLID, 0, sizeof(ThreadData) - 2*sizeof(STRLIST)); + memset(&mInitialContactWLID, 0, sizeof(ThreadData) - 2 * sizeof(STRLIST)); mGatewayTimeout = 2; resetTimeout(); hWaitEvent = CreateSemaphore(NULL, 0, MSN_PACKETS_COMBINE, NULL); @@ -573,19 +524,16 @@ ThreadData::~ThreadData() { int i; - if (s != NULL) - { + if (s != NULL) { proto->debugLogA("Closing connection handle %08X", s); Netlib_CloseHandle(s); } - if (mIncomingBoundPort != NULL) - { + if (mIncomingBoundPort != NULL) { Netlib_CloseHandle(mIncomingBoundPort); } - if (mMsnFtp != NULL) - { + if (mMsnFtp != NULL) { delete mMsnFtp; mMsnFtp = NULL; } @@ -596,10 +544,8 @@ ThreadData::~ThreadData() if (mTimerId != 0) KillTimer(NULL, mTimerId); - if (mType == SERVER_SWITCHBOARD) - { - for (i=0; iMSN_HContactFromEmail(wlid); int temp_status = proto->getWord(hContact, "Status", ID_STATUS_OFFLINE); @@ -617,10 +563,9 @@ ThreadData::~ThreadData() if (proto && mType == SERVER_P2P_DIRECT) proto->p2p_clearDormantSessions(); - if (wlid != NULL && mType == SERVER_SWITCHBOARD && - proto->MSN_GetThreadByContact(wlid) == NULL && - proto->MSN_GetUnconnectedThread(wlid) == NULL) - { + if (wlid != NULL && mType == SERVER_SWITCHBOARD && + proto->MSN_GetThreadByContact(wlid) == NULL && + proto->MSN_GetUnconnectedThread(wlid) == NULL) { proto->MsgQueue_Clear(wlid, true); } } @@ -632,7 +577,7 @@ void ThreadData::applyGatewayData(HANDLE hConn, bool isPoll) proto->debugLogA("applying '%s' to %08X [%08X]", szHttpPostUrl, this, GetCurrentThreadId()); - NETLIBHTTPPROXYINFO nlhpi = {0}; + NETLIBHTTPPROXYINFO nlhpi = { 0 }; nlhpi.cbSize = sizeof(nlhpi); nlhpi.flags = NLHPIF_HTTP11; nlhpi.szHttpGetUrl = NULL; @@ -645,15 +590,13 @@ void ThreadData::getGatewayUrl(char* dest, int destlen, bool isPoll) { static const char openFmtStr[] = "http://%s/gateway/gateway.dll?Action=open&Server=%s&IP=%s"; static const char pollFmtStr[] = "http://%s/gateway/gateway.dll?Action=poll&SessionID=%s"; - static const char cmdFmtStr[] = "http://%s/gateway/gateway.dll?SessionID=%s"; + static const char cmdFmtStr[] = "http://%s/gateway/gateway.dll?SessionID=%s"; - if (mSessionID[0] == 0) - { + if (mSessionID[0] == 0) { const char* svr = mType == SERVER_NOTIFICATION ? "NS" : "SB"; mir_snprintf(dest, destlen, openFmtStr, mGatewayIP, svr, mServer); } - else - mir_snprintf(dest, destlen, isPoll ? pollFmtStr : cmdFmtStr, mGatewayIP, mSessionID); + else mir_snprintf(dest, destlen, isPoll ? pollFmtStr : cmdFmtStr, mGatewayIP, mSessionID); } void ThreadData::processSessionData(const char* xMsgr, const char* xHost) @@ -726,8 +669,7 @@ HReadBuffer::HReadBuffer(ThreadData* T, int iStart) HReadBuffer::~HReadBuffer() { - if (totalDataSize > startOffset) - { + if (totalDataSize > startOffset) { memmove(buffer, buffer + startOffset, (totalDataSize -= startOffset)); owner->mBytesInData = (int)totalDataSize; } @@ -738,8 +680,7 @@ BYTE* HReadBuffer::surelyRead(size_t parBytes) { const size_t bufferSize = sizeof(owner->mData); - if ((startOffset + parBytes) > bufferSize) - { + if ((startOffset + parBytes) > bufferSize) { if (totalDataSize > startOffset) memmove(buffer, buffer + startOffset, (totalDataSize -= startOffset)); else @@ -747,15 +688,13 @@ BYTE* HReadBuffer::surelyRead(size_t parBytes) startOffset = 0; - if (parBytes > bufferSize) - { + if (parBytes > bufferSize) { owner->proto->debugLogA("HReadBuffer::surelyRead: not enough memory, %d %d %d", parBytes, bufferSize, startOffset); return NULL; } } - while ((startOffset + parBytes) > totalDataSize) - { + while ((startOffset + parBytes) > totalDataSize) { int recvResult = owner->recv((char*)buffer + totalDataSize, bufferSize - totalDataSize); if (recvResult <= 0) diff --git a/protocols/MSN/src/msn_ws.cpp b/protocols/MSN/src/msn_ws.cpp index 22a4cbc0aa..3bea4b60eb 100644 --- a/protocols/MSN/src/msn_ws.cpp +++ b/protocols/MSN/src/msn_ws.cpp @@ -23,7 +23,6 @@ along with this program. If not, see . #include "msn_global.h" #include "msn_proto.h" - //======================================================================================= int ThreadData::send(const char data[], size_t datalen) @@ -32,15 +31,13 @@ int ThreadData::send(const char data[], size_t datalen) resetTimeout(); - if (proto->usingGateway && !(mType == SERVER_FILETRANS || mType == SERVER_P2P_DIRECT)) - { + if (proto->usingGateway && !(mType == SERVER_FILETRANS || mType == SERVER_P2P_DIRECT)) { mGatewayTimeout = 2; CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); } int rlen = CallService(MS_NETLIB_SEND, (WPARAM)s, (LPARAM)&nlb); - if (rlen == SOCKET_ERROR) - { + if (rlen == SOCKET_ERROR) { // should really also check if sendlen is the same as datalen proto->debugLogA("Send failed: %d", WSAGetLastError()); return FALSE; @@ -61,23 +58,19 @@ bool ThreadData::isTimeout(void) if (mWaitPeriod >= clock()) return false; - if (mIsMainThread) - { + if (mIsMainThread) { res = !proto->usingGateway; } - else if (mJoinedContactsWLID.getCount() <= 1 || mChatID[0] == 0) - { + else if (mJoinedContactsWLID.getCount() <= 1 || mChatID[0] == 0) { MCONTACT hContact = getContactHandle(); if (mJoinedContactsWLID.getCount() == 0 || termPending) res = true; else if (proto->p2p_getThreadSession(hContact, mType) != NULL) res = false; - else if (mType == SERVER_SWITCHBOARD) - { + else if (mType == SERVER_SWITCHBOARD) { res = MSN_MsgWndExist(hContact); - if (res) - { + if (res) { WORD status = proto->getWord(hContact, "Status", ID_STATUS_OFFLINE); if ((status == ID_STATUS_OFFLINE || status == ID_STATUS_INVISIBLE || proto->m_iStatus == ID_STATUS_INVISIBLE)) res = false; @@ -87,15 +80,13 @@ bool ThreadData::isTimeout(void) res = true; } - if (res) - { + if (res) { bool sbsess = mType == SERVER_SWITCHBOARD; proto->debugLogA("Dropping the idle %s due to inactivity", sbsess ? "switchboard" : "p2p"); if (!sbsess || termPending) return true; - if (proto->getByte("EnableSessionPopup", 0)) - { + if (proto->getByte("EnableSessionPopup", 0)) { MCONTACT hContact = NULL; if (mJoinedContactsWLID.getCount()) hContact = proto->MSN_HContactFromEmail(mJoinedContactsWLID[0]); @@ -119,24 +110,20 @@ int ThreadData::recv(char* data, size_t datalen) { NETLIBBUFFER nlb = { data, (int)datalen, 0 }; - if (!proto->usingGateway) - { + if (!proto->usingGateway) { resetTimeout(); NETLIBSELECT nls = { 0 }; nls.cbSize = sizeof(nls); nls.dwTimeout = 1000; nls.hReadConns[0] = s; - for (;;) - { + for (;;) { int ret = CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls); - if (ret < 0) - { + if (ret < 0) { proto->debugLogA("Connection abortively closed, error %d", WSAGetLastError()); return ret; } - else if (ret == 0) - { + else if (ret == 0) { if (isTimeout()) return 0; } else @@ -146,30 +133,25 @@ int ThreadData::recv(char* data, size_t datalen) LBL_RecvAgain: int ret = CallService(MS_NETLIB_RECV, (WPARAM)s, (LPARAM)&nlb); - if (ret == 0) - { + if (ret == 0) { proto->debugLogA("Connection closed gracefully"); return 0; } - if (ret < 0) - { + if (ret < 0) { proto->debugLogA("Connection abortively closed, error %d", WSAGetLastError()); return ret; } - if (proto->usingGateway) - { - if (ret == 1 && *data == 0) - { + if (proto->usingGateway) { + if (ret == 1 && *data == 0) { if (sessionClosed || isTimeout()) return 0; if ((mGatewayTimeout += 2) > 20) mGatewayTimeout = 20; CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); goto LBL_RecvAgain; } - else - { + else { resetTimeout(); mGatewayTimeout = 1; CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); diff --git a/protocols/MSN/src/version.h b/protocols/MSN/src/version.h index f3f5952fe3..11fefe7035 100644 --- a/protocols/MSN/src/version.h +++ b/protocols/MSN/src/version.h @@ -21,7 +21,7 @@ along with this program. If not, see . #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 #define __RELEASE_NUM 1 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include -- cgit v1.2.3