From 9a80a756aa3bee92b85e09466b234c4c26c744b4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 5 Jun 2017 14:14:54 +0300 Subject: MSN - fix for rare crash; - all pre-MSNP24 code removed --- protocols/MSN/src/msn_auth.cpp | 200 ++- protocols/MSN/src/msn_chat.cpp | 4 - protocols/MSN/src/msn_commands.cpp | 1297 +----------------- protocols/MSN/src/msn_contact.cpp | 46 - protocols/MSN/src/msn_errors.cpp | 6 +- protocols/MSN/src/msn_ftold.cpp | 369 ------ protocols/MSN/src/msn_lists.cpp | 24 +- protocols/MSN/src/msn_menu.cpp | 132 -- protocols/MSN/src/msn_misc.cpp | 228 +--- protocols/MSN/src/msn_msgqueue.cpp | 183 --- protocols/MSN/src/msn_natdetect.cpp | 471 ------- protocols/MSN/src/msn_opts.cpp | 33 - protocols/MSN/src/msn_p2p.cpp | 2328 --------------------------------- protocols/MSN/src/msn_p2ps.cpp | 275 ---- protocols/MSN/src/msn_proto.cpp | 217 +-- protocols/MSN/src/msn_proto.h | 159 +-- protocols/MSN/src/msn_srv.cpp | 11 - protocols/MSN/src/msn_svcs.cpp | 133 -- protocols/MSN/src/msn_switchboard.cpp | 26 - protocols/MSN/src/msn_threads.cpp | 329 +---- protocols/MSN/src/msn_ws.cpp | 60 +- protocols/MSN/src/stdafx.h | 100 +- protocols/MSN/src/version.h | 6 +- 23 files changed, 258 insertions(+), 6379 deletions(-) delete mode 100644 protocols/MSN/src/msn_ftold.cpp delete mode 100644 protocols/MSN/src/msn_msgqueue.cpp delete mode 100644 protocols/MSN/src/msn_natdetect.cpp delete mode 100644 protocols/MSN/src/msn_p2p.cpp delete mode 100644 protocols/MSN/src/msn_p2ps.cpp (limited to 'protocols/MSN') diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp index 1ef0c8c3bc..a805672f17 100644 --- a/protocols/MSN/src/msn_auth.cpp +++ b/protocols/MSN/src/msn_auth.cpp @@ -146,7 +146,7 @@ static const char authPacket[] = ///////////////////////////////////////////////////////////////////////////////////////// // Tokens, tokens, tokens..... -GenericToken::GenericToken(const char *pszTokenName): +GenericToken::GenericToken(const char *pszTokenName) : m_pszTokenName(pszTokenName), m_pszToken(NULL), m_tExpires(0), @@ -157,7 +157,6 @@ GenericToken::GenericToken(const char *pszTokenName): GenericToken::~GenericToken() { mir_free(m_pszToken); -// mir_free(m_pszRefreshToken); } bool GenericToken::Load() @@ -190,11 +189,11 @@ void GenericToken::Save() bool GenericToken::Expired(time_t t) { - return t+3600 >= m_tExpires; + return t + 3600 >= m_tExpires; } void GenericToken::SetToken(const char *pszToken, time_t tExpires) -{ +{ replaceStr(m_pszToken, pszToken); m_tExpires = tExpires; Save(); @@ -219,7 +218,7 @@ void GenericToken::Clear() m_proto->delSetting(szTokenName); } -OAuthToken::OAuthToken(const char *pszTokenName, const char *pszService, bool bPrependT): +OAuthToken::OAuthToken(const char *pszTokenName, const char *pszService, bool bPrependT) : GenericToken(pszTokenName), m_pszService(pszService), m_bPreprendT(bPrependT) @@ -244,7 +243,7 @@ bool OAuthToken::Refresh(bool bForce) return true; } -SkypeToken::SkypeToken(const char *pszTokenName): +SkypeToken::SkypeToken(const char *pszTokenName) : GenericToken(pszTokenName) { } @@ -267,16 +266,17 @@ bool SkypeToken::Refresh(bool bForce) CMStringA szPOST; if (m_proto->MyOptions.netId == NETID_SKYPE) { BYTE digest[16]; - char szPassword[100]={0}; + char szPassword[100] = { 0 }; - int cbPasswd=mir_snprintf(szPassword, sizeof(szPassword), "%s\nskyper\n", m_proto->MyOptions.szEmail); + int cbPasswd = mir_snprintf(szPassword, sizeof(szPassword), "%s\nskyper\n", m_proto->MyOptions.szEmail); if (db_get_static(NULL, m_proto->m_szModuleName, "Password", szPassword + cbPasswd, sizeof(szPassword) - cbPasswd - 1)) return false; mir_md5_hash((BYTE*)szPassword, mir_strlen(szPassword), digest); mir_base64_encodebuf(digest, sizeof(digest), szPassword, sizeof(szPassword)); nlhr.szUrl = "https://api.skype.com/login/skypetoken"; szPOST.Format("scopes=client&clientVersion=%s&username=%s&passwordHash=%s", msnProductVer, m_proto->MyOptions.szEmail, szPassword); - } else { + } + else { // Get skype_token nlhr.szUrl = "https://api.skype.com/rps/skypetoken"; szPOST.Format("scopes=client&clientVersion=%s&access_token=%s&partner=999", msnProductVer, m_proto->authSkypeComToken.Token()); @@ -290,7 +290,7 @@ bool SkypeToken::Refresh(bool bForce) m_proto->mHttpsTS = clock(); bool bRet = false; - if (nlhrReply) { + if (nlhrReply) { m_proto->hHttpsConnection = nlhrReply->nlc; if (nlhrReply->resultCode == 200 && nlhrReply->pData) { @@ -307,7 +307,8 @@ bool SkypeToken::Refresh(bool bForce) } } Netlib_FreeHttpRequest(nlhrReply); - } else m_proto->hHttpsConnection = NULL; + } + else m_proto->hHttpsConnection = NULL; return bRet; } @@ -316,7 +317,7 @@ const char* SkypeToken::XSkypetoken() Refresh(); if (m_pszToken) { char *pszRet = strchr(m_pszToken, ' '); - if (pszRet) return pszRet+1; + if (pszRet) return pszRet + 1; } return NULL; } @@ -401,7 +402,7 @@ int CMsnProto::MSN_GetPassportAuth(void) ezxml_t xml_expires = ezxml_get(tokr, "wst:Lifetime", 0, "wsu:Expires", -1); time_t expires; - expires = xml_expires?IsoToUnixTime(ezxml_txt(xml_expires)):time(NULL)+86400; + expires = xml_expires ? IsoToUnixTime(ezxml_txt(xml_expires)) : time(NULL) + 86400; if (mir_strcmp(addr, "http://Passport.NET/tb") == 0) { @@ -652,10 +653,10 @@ CMStringA CMsnProto::HotmailLogin(const char* url) } /* 1 - Login successful - 0 - Login failed - -1 - Loading Skylogin library failed - -2 - Functions cannot be loaded from Skylogin library - -3 - Initializing Skylogin library failed + 0 - Login failed + -1 - Loading Skylogin library failed + -2 - Functions cannot be loaded from Skylogin library + -3 - Initializing Skylogin library failed */ int CMsnProto::MSN_SkypeAuth(const char *pszNonce, char *pszUIC) { @@ -670,8 +671,7 @@ int CMsnProto::MSN_SkypeAuth(const char *pszNonce, char *pszUIC) SkyLogin_SetLogFunction(hLogin, debugLogSkyLoginA, this); if (!db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword))) { if (SkyLogin_LoadCredentials(hLogin, MyOptions.szEmail) || - SkyLogin_PerformLogin(hLogin, MyOptions.szEmail, szPassword)) - { + SkyLogin_PerformLogin(hLogin, MyOptions.szEmail, szPassword)) { if (SkyLogin_CreateUICString(hLogin, pszNonce, pszUIC)) iRet = 1; } @@ -684,7 +684,7 @@ int CMsnProto::MSN_SkypeAuth(const char *pszNonce, char *pszUIC) } /* 1 - Login successful - 0 - Login failed + 0 - Login failed */ int CMsnProto::LoginSkypeOAuth(const char *pRefreshToken) @@ -697,22 +697,21 @@ int CMsnProto::LoginSkypeOAuth(const char *pRefreshToken) CMStringA szLoginToken; SkyLogin_SetLogFunction(hLogin, debugLogSkyLoginA, this); if (RefreshOAuth(pRefreshToken, "service::login.skype.com::MBI_SSL", &szLoginToken, nullptr, nullptr) && - SkyLogin_PerformLoginOAuth(hLogin, szLoginToken)) - { + SkyLogin_PerformLoginOAuth(hLogin, szLoginToken)) { char szUIC[1024]; if (SkyLogin_GetCredentialsUIC(hLogin, szUIC)) { char *pszPartner; replaceStr(authUIC, szUIC); iRet = 1; - if (pszPartner = SkyLogin_GetUser(hLogin)) + if (pszPartner = SkyLogin_GetUser(hLogin)) setString("SkypePartner", pszPartner); } } else iRet = 0; SkyLogin_Exit(hLogin); - } + } return iRet; } @@ -729,10 +728,10 @@ static int CopyCookies(NETLIBHTTPREQUEST *nlhrReply, NETLIBHTTPHEADER *hdr) for (i = 0; i < nlhrReply->headersCount; i++) { if (mir_strcmpi(nlhrReply->headers[i].szName, "Set-Cookie")) continue; - if (p=strchr(nlhrReply->headers[i].szValue, ';')) *p=0; + if (p = strchr(nlhrReply->headers[i].szValue, ';')) *p = 0; if (hdr) { - if (*hdr->szValue) mir_strcat (hdr->szValue, "; "); - mir_strcat (hdr->szValue, nlhrReply->headers[i].szValue); + if (*hdr->szValue) mir_strcat(hdr->szValue, "; "); + mir_strcat(hdr->szValue, nlhrReply->headers[i].szValue); } else nSize += (int)mir_strlen(nlhrReply->headers[i].szValue) + 2; } @@ -740,7 +739,7 @@ static int CopyCookies(NETLIBHTTPREQUEST *nlhrReply, NETLIBHTTPHEADER *hdr) } /* - pszService: + pszService: service::login.skype.com::MBI_SSL - For LoginSkypeOAuth service::ssl.live.com::MBI_SSL - For ssl-compact-ticket service::contacts.msn.com::MBI_SSL - Contact SOAP service -> authContactToken @@ -772,7 +771,7 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService nlhr.headers[2].szName = "Cookie"; nlhr.headers[2].szValue = authCookies; post.Format("client_id=00000000480BC46C&scope=%s&grant_type=refresh_token&refresh_token=%s", ptrA(mir_urlEncode(pszService)), pszRefreshToken); - + nlhr.pData = (char*)(const char*)post; nlhr.dataLength = (int)mir_strlen(nlhr.pData); nlhr.szUrl = "https://login.live.com/oauth20_token.srf"; @@ -781,7 +780,7 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService mHttpsTS = clock(); NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(hNetlibUserHttps, &nlhr); mHttpsTS = clock(); - if (nlhrReply) { + if (nlhrReply) { hHttpsConnection = nlhrReply->nlc; if (nlhrReply->resultCode == 200 && nlhrReply->pData) { JSONROOT root(nlhrReply->pData); @@ -793,7 +792,7 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService if (pszAccessToken->IsEmpty()) bRet = false; } - + if (pszOutRefreshToken) { *pszOutRefreshToken = (*root)["refresh_token"].as_mstring(); if (pszOutRefreshToken->IsEmpty()) @@ -861,7 +860,8 @@ void CMsnProto::SaveAuthTokensDB(void) setString("authRefreshToken", authRefreshToken); } -typedef struct { +typedef struct +{ /* Internal */ IEEmbed *pEmbed; /* Input */ @@ -875,16 +875,15 @@ typedef struct { LRESULT CALLBACK AuthWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) - { - case WM_SIZE: + switch (uMsg) { + case WM_SIZE: { IEAUTH_PARAM *pAuth = (IEAUTH_PARAM*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (pAuth && pAuth->pEmbed) pAuth->pEmbed->ResizeBrowser(); return(0); } - case WM_CREATE: + case WM_CREATE: { IEAUTH_PARAM *pAuth = (IEAUTH_PARAM*)((LPCREATESTRUCT)lParam)->lpCreateParams; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pAuth); @@ -896,7 +895,7 @@ LRESULT CALLBACK AuthWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar return(0); } - case UM_DOCCOMPLETE: + case UM_DOCCOMPLETE: { if (!lParam) return 1; IEAUTH_PARAM *pAuth = (IEAUTH_PARAM*)GetWindowLongPtr(hwnd, GWLP_USERDATA); @@ -929,7 +928,7 @@ LRESULT CALLBACK AuthWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar (pAuth->pszCookies = (char*)mir_alloc(cbCookie))) { fpInternetGetCookieExA("https://login.live.com", NULL, pAuth->pszCookies, &cbCookie, INTERNET_COOKIE_HTTPONLY, NULL); } - else pAuth->pszCookies = mir_u2a(pAuth->pEmbed->getCookies()); + else pAuth->pszCookies = mir_u2a(pAuth->pEmbed->getCookies()); PostMessage(hwnd, WM_CLOSE, 0, 0); } else if (wcsstr((WCHAR*)lParam, L"res=cancel") || wcsstr((WCHAR*)lParam, L"access_denied")) { @@ -938,12 +937,12 @@ LRESULT CALLBACK AuthWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar return(0); } - case WM_CLOSE: - DestroyWindow(hwnd); - PostQuitMessage(0); - break; + case WM_CLOSE: + DestroyWindow(hwnd); + PostQuitMessage(0); + break; - case WM_DESTROY: + case WM_DESTROY: { IEAUTH_PARAM *pAuth = (IEAUTH_PARAM*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (pAuth && pAuth->pEmbed) delete pAuth->pEmbed; @@ -960,28 +959,27 @@ void __cdecl CMsnProto::msn_IEAuthThread(void *pParam) { HWND hWnd; MSG msg; - WNDCLASSEX wc={0}; - static const wchar_t *ClassName = L"SkypeLoginWindow"; - - CoInitialize(NULL); - - wc.cbSize = sizeof(WNDCLASSEX); - wc.cbWndExtra = sizeof(void*); - wc.hInstance = g_hInst; - wc.lpfnWndProc = AuthWindowProc; - wc.lpszClassName = ClassName; - RegisterClassEx(&wc); - - if ((hWnd = CreateWindowEx(0, ClassName, L"MSN Login", WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, - HWND_DESKTOP, NULL, g_hInst, pParam))) { - ShowWindow( hWnd, SW_SHOW ); - UpdateWindow( hWnd ); - - while( GetMessage(&msg, NULL, 0, 0) ) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); + WNDCLASSEX wc = { 0 }; + static const wchar_t *ClassName = L"SkypeLoginWindow"; + + CoInitialize(NULL); + + wc.cbSize = sizeof(WNDCLASSEX); + wc.cbWndExtra = sizeof(void*); + wc.hInstance = g_hInst; + wc.lpfnWndProc = AuthWindowProc; + wc.lpszClassName = ClassName; + RegisterClassEx(&wc); + + if ((hWnd = CreateWindowEx(0, ClassName, L"MSN Login", WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, + HWND_DESKTOP, NULL, g_hInst, pParam))) { + ShowWindow(hWnd, SW_SHOW); + UpdateWindow(hWnd); + + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); } } @@ -994,22 +992,23 @@ bool CMsnProto::parseLoginPage(char *pszHTML, NETLIBHTTPREQUEST *nlhr, CMStringA char *pPPFT, *pEnd; /* Get PPFT */ - if ((pPPFT = strstr(pszHTML, "name=\"PPFT\"")) && (pPPFT = strstr(pPPFT, "value=\"")) && (pEnd=strchr(pPPFT+7, '"'))) { - *pEnd=0; - pPPFT+=7; + if ((pPPFT = strstr(pszHTML, "name=\"PPFT\"")) && (pPPFT = strstr(pPPFT, "value=\"")) && (pEnd = strchr(pPPFT + 7, '"'))) { + *pEnd = 0; + pPPFT += 7; /* Get POST URL if available */ - if ((nlhr->szUrl = strstr(pszHTML, "urlPost:'")) && (pEnd=strchr(nlhr->szUrl+9, '\''))) { - *pEnd=0; + if ((nlhr->szUrl = strstr(pszHTML, "urlPost:'")) && (pEnd = strchr(nlhr->szUrl + 9, '\''))) { + *pEnd = 0; nlhr->szUrl += 9; - } else nlhr->szUrl = POST_URL; + } + else nlhr->szUrl = POST_URL; /* Create POST data */ char szPassword[100]; if (db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword))) return false; szPassword[99] = 0; - post->Format("PPFT=%s&login=%s&passwd=%s", ptrA(mir_urlEncode(pPPFT)), + post->Format("PPFT=%s&login=%s&passwd=%s", ptrA(mir_urlEncode(pPPFT)), ptrA(mir_urlEncode(MyOptions.szEmail)), ptrA(mir_urlEncode(szPassword))); /* Do the login and get the required tokens */ @@ -1026,54 +1025,54 @@ bool CMsnProto::parseLoginPage(char *pszHTML, NETLIBHTTPREQUEST *nlhr, CMStringA int CMsnProto::MSN_RefreshOAuthTokens(bool bJustCheck) { time_t t; - int i=authMethod==2?0:1, iRet; - OAuthToken *tokens[] = {&authStrToken, &authContactToken, &authStorageToken, &authSSLToken, &authSkypeComToken}; + int i = authMethod == 2 ? 0 : 1, iRet; + OAuthToken *tokens[] = { &authStrToken, &authContactToken, &authStorageToken, &authSSLToken, &authSkypeComToken }; time(&t); if (bJustCheck) { - for (;iExpired(t)) return 1; return 0; } - for (iRet=0;iExpired()) - iRet=tokens[i]->Refresh(true)?1:-1; + iRet = tokens[i]->Refresh(true) ? 1 : -1; } return iRet; } -void CMsnProto::MSN_SendATH(ThreadData* info) +void CMsnProto::MSN_SendATH(ThreadData *info) { - if (MyOptions.netId!=NETID_SKYPE) { + if (MyOptions.netId != NETID_SKYPE) { /* MSN account login */ - switch (authMethod) - { - case 1: + switch (authMethod) { + case 1: info->sendPacketPayload("ATH", "CON\\USER", "t=%s" "%s" - "%s%s\r\n", - (const char*)authSSLToken ? ptrA(HtmlEncode(authSSLToken)) : "", - authUIC, + "%s%s\r\n", + (const char*)authSSLToken ? ptrA(HtmlEncode(authSSLToken)) : "", + authUIC, GetMyUsername(NETID_MSN), GetMyUsername(NETID_SKYPE)); break; - case 2: + case 2: info->sendPacketPayload("ATH", "CON\\USER", "%s" "%s" "chatservice.live.com" - "\r\n", + "\r\n", (const char*)authStrToken ? ptrA(HtmlEncode(authStrToken)) : "", authUIC); break; } - } else { + } + else { info->sendPacketPayload("ATH", "CON\\USER", - "%s%s\r\n", + "%s%s\r\n", authUIC, MyOptions.szEmail); } } @@ -1112,7 +1111,7 @@ int CMsnProto::MSN_AuthOAuth(void) NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(hNetlibUserHttps, &nlhr); mHttpsTS = clock(); - if (nlhrReply) { + if (nlhrReply) { hHttpsConnection = nlhrReply->nlc; if (nlhrReply->resultCode == 200 && nlhrReply->pData) { @@ -1137,11 +1136,11 @@ int CMsnProto::MSN_AuthOAuth(void) NETLIBHTTPREQUEST *nlhrReply2 = Netlib_HttpTransaction(hNetlibUserHttps, &nlhr); mHttpsTS = clock(); if (nlhrReply2) { - char *pszURL=NULL, *pAccessToken, *pEnd; + char *pszURL = NULL, *pAccessToken, *pEnd; hHttpsConnection = nlhrReply2->nlc; bPassportAuth = true; - + if (nlhrReply2->resultCode == 302) { /* Extract access_token from Location can be found */ for (int i = 0; i < nlhrReply2->headersCount; i++) { @@ -1156,7 +1155,7 @@ int CMsnProto::MSN_AuthOAuth(void) * window in order to let user login there. May also be used for 2-factor auth */ if (nlhrReply2->resultCode == 200 && nlhrReply2->pData) { UINT uThreadId; - IEAUTH_PARAM param = {NULL, this, &nlhr, nlhrReply2, NULL, NULL}; + IEAUTH_PARAM param = { NULL, this, &nlhr, nlhrReply2, NULL, NULL }; bAskingForAuth = true; WaitForSingleObject(ForkThreadEx(&CMsnProto::msn_IEAuthThread, ¶m, &uThreadId), INFINITE); @@ -1273,11 +1272,12 @@ int CMsnProto::MSN_AuthOAuth(void) } else hHttpsConnection = NULL; - if (retVal<=0) authSkypeComToken.Clear(); else { + if (retVal <= 0) authSkypeComToken.Clear(); else { if (bPassportAuth) { // Fast authentication with just 1 SOAP call supported :) MSN_GetPassportAuth(); - } else { + } + else { // Slow authentication required by fetching multiple tokens, i.e. 2-factor auth :( if (authMethod == 2) authStrToken.Refresh(); authContactToken.Refresh(); @@ -1288,19 +1288,17 @@ int CMsnProto::MSN_AuthOAuth(void) return retVal; } -int CMsnProto::GetMyNetID(void) +int CMsnProto::GetMyNetID(void) { - return strchr(MyOptions.szEmail, '@')?NETID_MSN:NETID_SKYPE; + return strchr(MyOptions.szEmail, '@') ? NETID_MSN : NETID_SKYPE; } const char *CMsnProto::GetMyUsername(int netId) { static char szPartner[128]; - if (netId == NETID_SKYPE) - { - if (MyOptions.netId==NETID_MSN) - { + if (netId == NETID_SKYPE) { + if (MyOptions.netId == NETID_MSN) { if (db_get_static(NULL, m_szModuleName, "SkypePartner", szPartner, sizeof(szPartner)) == 0) return szPartner; } diff --git a/protocols/MSN/src/msn_chat.cpp b/protocols/MSN/src/msn_chat.cpp index e276f165a5..9653c829b4 100644 --- a/protocols/MSN/src/msn_chat.cpp +++ b/protocols/MSN/src/msn_chat.cpp @@ -421,10 +421,6 @@ INT_PTR CALLBACK DlgInviteToChat(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l GCThreadData *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; diff --git a/protocols/MSN/src/msn_commands.cpp b/protocols/MSN/src/msn_commands.cpp index bfbd1b0fe3..f8662107a3 100644 --- a/protocols/MSN/src/msn_commands.cpp +++ b/protocols/MSN/src/msn_commands.cpp @@ -23,55 +23,6 @@ along with this program. If not, see . #include "stdafx.h" #include "msn_proto.h" -#ifdef OBSOLETE -void CMsnProto::MSN_SetMirVer(MCONTACT hContact, DWORD dwValue, bool always) -{ - static const char* MirVerStr[] = - { - "MSN 4.x-5.x", - "MSN 6.0", - "MSN 6.1", - "MSN 6.2", - "MSN 7.0", - "MSN 7.5", - "WLM 8.0", - "WLM 8.1", - "WLM 8.5", - "WLM 9.0 Beta", - "WLM 2009", - "WLM 2011", - "WLM 2012", - "WLM Unknown", - }; - - LPCSTR szVersion; - - if (dwValue == 0) - szVersion = "Windows Phone"; - else if (dwValue & 0x1) - szVersion = "MSN Mobile"; - else if (dwValue & 0x200) - szVersion = "Webmessenger"; - else if (dwValue == 0x800800) - szVersion = "Yahoo"; - else if (dwValue == 0x800) - szVersion = "LCS"; - else if (dwValue == 0x50000000) - szVersion = "Miranda IM 0.5.x (MSN v.0.5.x)"; - else if (dwValue == 0x30000024) - szVersion = "Miranda IM 0.4.x (MSN v.0.4.x)"; - else if (always || getByte(hContact, "StdMirVer", 0)) { - unsigned wlmId = min(dwValue >> 28 & 0xff, _countof(MirVerStr) - 1); - szVersion = MirVerStr[wlmId]; - } - else - return; - - setString(hContact, "MirVer", szVersion); - setByte(hContact, "StdMirVer", 1); -} -#endif - void CMsnProto::MSN_SetMirVer(MCONTACT hContact, MsnPlace *place) { static const char* MirVerStr[] = @@ -416,31 +367,6 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para sttNotificationMessage(msgBody, true); else if (!_strnicmp(tContentType, "text/x-msmsgsoimnotification", 28)) sttNotificationMessage(msgBody, false); -#ifdef OBSOLETE - else if (!_strnicmp(tContentType, "text/x-msmsgsinvite", 19)) - MSN_InviteMessage(info, msgBody, email, nick); - else if (!_strnicmp(tContentType, "application/x-msnmsgrp2p", 24)) { - const char* dest = tHeader["P2P-Dest"]; - if (dest) { - char *szEmail, *szInst; - parseWLID(NEWSTR_ALLOCA(dest), NULL, &szEmail, &szInst); - - if (mir_strcmpi(szEmail, MyOptions.szEmail) == 0) { - const char* src = tHeader["P2P-Src"]; - if (src == NULL) src = email; - - if (szInst == NULL) - p2p_processMsg(info, msgBody, src); - else if (mir_strcmpi(szInst, MyOptions.szMachineGuidP2P) == 0) - p2p_processMsgV2(info, msgBody, src); - } - } - } - else if (!_strnicmp(tContentType, "text/x-mms-emoticon", 19)) - MSN_CustomSmiley(msgBody, email, nick, MSN_APPID_CUSTOMSMILEY); - else if (!_strnicmp(tContentType, "text/x-mms-animemoticon", 23)) - MSN_CustomSmiley(msgBody, email, nick, MSN_APPID_CUSTOMANIMATEDSMILEY); -#endif mir_free(mChatID); mir_free(newbody); @@ -742,132 +668,24 @@ void CMsnProto::MSN_ProcessStatusMessage(ezxml_t xmli, const char* wlid) unsigned cap2 = end && *end == ':' ? strtoul(end + 1, NULL, 10) : 0; Lists_AddPlace(szEmail, id, cap1, cap2); - } else if (!mir_strcmp(n, "PE")) { + } + else if (!mir_strcmp(n, "PE")) { MsnPlace *place = Lists_GetPlace(szEmail, ezxml_attr(endp, "epid")); - if (place) - { + if (place) { place->client = atoi(ezxml_txt(ezxml_child(endp, "TYP"))); mir_strncpy(place->szClientVer, ezxml_txt(ezxml_child(endp, "VER")), sizeof(place->szClientVer)); } } } - { - ptrW tszStatus(mir_utf8decodeW(szStatMsg)); - if (szInst) MSN_SetMirVer(hContact, Lists_GetPlace(szEmail, szInst)); - else { - MsnContact *cont = Lists_Get(hContact); - if (cont->places.getCount() > 0) MSN_SetMirVer(hContact, &cont->places[0]); - } - ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, NULL, tszStatus); - } - -#ifdef OBSOLETE - // Process current media info - const char* szCrntMda = ezxml_txt(ezxml_child(xmli, "CurrentMedia")); - if (!*szCrntMda) { - delSetting(hContact, "ListeningTo"); - return; - } - - // Get parts separeted by "\\0" - char *parts[16]; - unsigned pCount; - - char* p = (char*)szCrntMda; - for (pCount = 0; pCount < _countof(parts); ++pCount) { - parts[pCount] = p; - - char* p1 = strstr(p, "\\0"); - if (p1 == NULL) break; - - *p1 = '\0'; - p = p1 + 2; - } - - // Now let's mount the final string - if (pCount <= 4) { - delSetting(hContact, "ListeningTo"); - return; - } - - // Check if there is any info in the string - bool foundUsefullInfo = false; - for (unsigned i = 4; i < pCount; i++) { - if (parts[i][0] != '\0') { - foundUsefullInfo = true; - break; - } - } - if (!foundUsefullInfo) { - delSetting(hContact, "ListeningTo"); - return; - } - - if (!ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT) || - !ServiceExists(MS_LISTENINGTO_OVERRIDECONTACTOPTION) || - !CallService(MS_LISTENINGTO_OVERRIDECONTACTOPTION, 0, hContact)) - { - // User contact options - char *format = mir_strdup(parts[3]); - char *unknown = NULL; - if (ServiceExists(MS_LISTENINGTO_GETUNKNOWNTEXT)) - unknown = mir_utf8encodeW((wchar_t *)CallService(MS_LISTENINGTO_GETUNKNOWNTEXT, 0, 0)); - - for (unsigned i = 4; i < pCount; i++) { - char part[16]; - size_t lenPart = mir_snprintf(part, "{%d}", i - 4); - if (parts[i][0] == '\0' && unknown != NULL) - parts[i] = unknown; - size_t lenPartsI = mir_strlen(parts[i]); - for (p = strstr(format, part); p; p = strstr(p + lenPartsI, part)) { - if (lenPart < lenPartsI) { - int loc = p - format; - format = (char *)mir_realloc(format, mir_strlen(format) + (lenPartsI - lenPart) + 1); - p = format + loc; - } - memmove(p + lenPartsI, p + lenPart, mir_strlen(p + lenPart) + 1); - memmove(p, parts[i], lenPartsI); - } - } - - setStringUtf(hContact, "ListeningTo", format); - mir_free(unknown); - mir_free(format); - } + if (szInst) + MSN_SetMirVer(hContact, Lists_GetPlace(szEmail, szInst)); else { - // Use user options - LISTENINGTOINFO lti = { 0 }; - lti.cbSize = sizeof(LISTENINGTOINFO); - - lti.ptszTitle = mir_utf8decodeW(parts[4]); - if (pCount > 5) lti.ptszArtist = mir_utf8decodeW(parts[5]); - if (pCount > 6) lti.ptszAlbum = mir_utf8decodeW(parts[6]); - if (pCount > 7) lti.ptszTrack = mir_utf8decodeW(parts[7]); - if (pCount > 8) lti.ptszYear = mir_utf8decodeW(parts[8]); - if (pCount > 9) lti.ptszGenre = mir_utf8decodeW(parts[9]); - if (pCount > 10) lti.ptszLength = mir_utf8decodeW(parts[10]); - if (pCount > 11) lti.ptszPlayer = mir_utf8decodeW(parts[11]); - else lti.ptszPlayer = mir_utf8decodeW(parts[0]); - if (pCount > 12) lti.ptszType = mir_utf8decodeW(parts[12]); - else lti.ptszType = mir_utf8decodeW(parts[1]); - - wchar_t *cm = (wchar_t *)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)L"%title% - %artist%", (LPARAM)<i); - setWString(hContact, "ListeningTo", cm); - - mir_free(cm); - - mir_free(lti.ptszArtist); - mir_free(lti.ptszAlbum); - mir_free(lti.ptszTitle); - mir_free(lti.ptszTrack); - mir_free(lti.ptszYear); - mir_free(lti.ptszGenre); - mir_free(lti.ptszLength); - mir_free(lti.ptszPlayer); - mir_free(lti.ptszType); + MsnContact *cont = Lists_Get(hContact); + if (cont->places.getCount() > 0) + MSN_SetMirVer(hContact, &cont->places[0]); } -#endif + ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, NULL, ptrW(mir_utf8decodeW(szStatMsg))); } void CMsnProto::MSN_ProcessNotificationMessage(char* buf, size_t len) @@ -1055,11 +873,8 @@ LBL_InvalidCommand: MSN_SendATH(info); bSentBND = false; - if (!hKeepAliveThreadEvt) ForkThread(&CMsnProto::msn_keepAliveThread, NULL); -#ifdef OBSOLETE - /* FIXME: Currently disabled, as P2P maybe not working anymore in MSNP24? */ - ForkThread(&CMsnProto::MSNConnDetectThread, NULL); -#endif + if (!hKeepAliveThreadEvt) + ForkThread(&CMsnProto::msn_keepAliveThread, NULL); } break; @@ -1398,1093 +1213,3 @@ LBL_InvalidCommand: return 0; } - - -#ifdef OBSOLETE - -///////////////////////////////////////////////////////////////////////////////////////// -// Starts a file sending thread - -void MSN_ConnectionProc(HANDLE hNewConnection, DWORD /* dwRemoteIP */, void* extra) -{ - CMsnProto *proto = (CMsnProto*)extra; - - proto->debugLogA("File transfer connection accepted"); - - NETLIBCONNINFO connInfo = {}; - Netlib_GetConnectionInfo(hNewConnection, &connInfo); - - ThreadData* T = proto->MSN_GetThreadByPort(connInfo.wPort); - if (T != NULL && T->s == NULL) { - T->s = hNewConnection; - ReleaseSemaphore(T->hWaitEvent, 1, NULL); - } - else { - proto->debugLogA("There's no registered file transfers for incoming port #%u, connection closed", connInfo.wPort); - Netlib_CloseHandle(hNewConnection); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Processes various invitations - -void CMsnProto::MSN_InviteMessage(ThreadData* info, char* msgBody, char* email, char* nick) -{ - MimeHeaders tFileInfo; - tFileInfo.readFromBuffer(msgBody); - - const char* Appname = tFileInfo["Application-Name"]; - const char* AppGUID = tFileInfo["Application-GUID"]; - const char* Invcommand = tFileInfo["Invitation-Command"]; - const char* Invcookie = tFileInfo["Invitation-Cookie"]; - const char* Appfile = tFileInfo["Application-File"]; - const char* Appfilesize = tFileInfo["Application-FileSize"]; - const char* IPAddress = tFileInfo["IP-Address"]; - const char* IPAddressInt = tFileInfo["IP-Address-Internal"]; - const char* Port = tFileInfo["Port"]; - const char* PortXInt = tFileInfo["PortX-Internal"]; - const char* AuthCookie = tFileInfo["AuthCookie"]; - const char* SessionID = tFileInfo["Session-ID"]; - const char* SessionProtocol = tFileInfo["Session-Protocol"]; - // const char* Connectivity = tFileInfo["Connectivity"]; - - if (AppGUID != NULL) { - if (!mir_strcmp(AppGUID, "{02D3C01F-BF30-4825-A83A-DE7AF41648AA}")) { - MSN_ShowPopup(info->getContactHandle(), - TranslateT("Contact tried to open an audio conference (not currently supported)"), MSN_ALLOW_MSGBOX); - return; - } - } - - if (Invcommand && (mir_strcmp(Invcommand, "CANCEL") == 0)) { - delete info->mMsnFtp; - info->mMsnFtp = NULL; - } - - if (Appname != NULL && Appfile != NULL && Appfilesize != NULL) // receive first - { - filetransfer* ft = info->mMsnFtp = new filetransfer(this); - - ft->std.hContact = MSN_HContactFromEmail(email, nick, true, true); - mir_free(ft->std.tszCurrentFile); - ft->std.tszCurrentFile = mir_utf8decodeW(Appfile); - ft->std.totalBytes = ft->std.currentFileSize = _atoi64(Appfilesize); - ft->std.totalFiles = 1; - ft->szInvcookie = mir_strdup(Invcookie); - ft->p2p_dest = mir_strdup(email); - - wchar_t tComment[40]; - mir_snwprintf(tComment, TranslateT("%I64u bytes"), ft->std.currentFileSize); - - PROTORECVFILET pre = { 0 }; - pre.dwFlags = PRFF_UNICODE; - pre.fileCount = 1; - pre.timestamp = time(NULL); - pre.descr.w = tComment; - pre.files.w = &ft->std.tszCurrentFile; - pre.lParam = (LPARAM)ft; - ProtoChainRecvFile(ft->std.hContact, &pre); - return; - } - - // receive Second - if (IPAddress != NULL && Port != NULL && AuthCookie != NULL) { - ThreadData* newThread = new ThreadData; - - if (inet_addr(IPAddress) != MyConnection.extIP || !IPAddressInt) - mir_snprintf(newThread->mServer, "%s:%s", IPAddress, Port); - else - mir_snprintf(newThread->mServer, "%s:%u", IPAddressInt, atol(PortXInt) ^ 0x3141); - - newThread->mType = SERVER_FILETRANS; - - if (info->mMsnFtp == NULL) { - ThreadData* otherThread = MSN_GetOtherContactThread(info); - if (otherThread) { - info->mMsnFtp = otherThread->mMsnFtp; - otherThread->mMsnFtp = NULL; - } - } - - newThread->mMsnFtp = info->mMsnFtp; info->mMsnFtp = NULL; - mir_strcpy(newThread->mCookie, AuthCookie); - - newThread->startThread(&CMsnProto::MSNServerThread, this); - return; - } - - // send 1 - if (Invcommand != NULL && Invcookie != NULL && Port == NULL && AuthCookie == NULL && SessionID == NULL) { - msnftp_startFileSend(info, Invcommand, Invcookie); - return; - } - - // netmeeting send 1 - if (Appname == NULL && SessionID != NULL && SessionProtocol != NULL) { - if (!_stricmp(Invcommand, "ACCEPT")) { - ShellExecuteA(NULL, "open", "conf.exe", NULL, NULL, SW_SHOW); - Sleep(3000); - - info->sendPacketPayload("MSG", "N", - "MIME-Version: 1.0\r\n" - "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" - "Invitation-Command: ACCEPT\r\n" - "Invitation-Cookie: %s\r\n" - "Session-ID: {1A879604-D1B8-11D7-9066-0003FF431510}\r\n" - "Launch-Application: TRUE\r\n" - "IP-Address: %s\r\n\r\n", - Invcookie, MyConnection.GetMyExtIPStr()); - } - return; - } - - // netmeeting receive 1 - if (Appname != NULL && !_stricmp(Appname, "NetMeeting")) { - wchar_t text[512], *tszEmail = mir_a2u(email); - mir_snwprintf(text, TranslateT("Accept NetMeeting request from %s?"), tszEmail); - mir_free(tszEmail); - - if (MessageBox(NULL, text, TranslateT("MSN Protocol"), MB_YESNO | MB_ICONQUESTION) == IDYES) { - info->sendPacketPayload("MSG", "N", - "MIME-Version: 1.0\r\n" - "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" - "Invitation-Command: ACCEPT\r\n" - "Invitation-Cookie: %s\r\n" - "Session-ID: {A2ED5ACF-F784-4B47-A7D4-997CD8F643CC}\r\n" - "Session-Protocol: SM1\r\n" - "Launch-Application: TRUE\r\n" - "Request-Data: IP-Address:\r\n" - "IP-Address: %s\r\n\r\n", - Invcookie, MyConnection.GetMyExtIPStr()); - } - else { - info->sendPacketPayload("MSG", "N", - "MIME-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", - Invcookie); - } - return; - } - - if (IPAddress != NULL && Port == NULL && SessionID != NULL && SessionProtocol == NULL) { // netmeeting receive 2 - char ipaddr[256]; - mir_snprintf(ipaddr, "callto://%s", IPAddress); - ShellExecuteA(NULL, "open", ipaddr, NULL, NULL, SW_SHOW); - } -} - -void CMsnProto::MSN_ProcessRemove(char* buf, size_t len) -{ - ezxml_t xmli = ezxml_parse_str(buf, len); - ezxml_t dom = ezxml_child(xmli, "d"); - while (dom != NULL) { - const char* szDom = ezxml_attr(dom, "n"); - ezxml_t cont = ezxml_child(dom, "c"); - while (cont != NULL) { - const char* szCont = ezxml_attr(cont, "n"); - int listId = atol(ezxml_attr(cont, "l")); - - char szEmail[128]; - mir_snprintf(szEmail, "%s@%s", szCont, szDom); - Lists_Remove(listId, szEmail); - - MsnContact* msc = Lists_Get(szEmail); - if (msc == NULL || (msc->list & (LIST_RL | LIST_FL | LIST_LL)) == 0) { - if (msc->hContact && _stricmp(szEmail, MyOptions.szEmail)) { - db_delete_contact(msc->hContact); - msc->hContact = NULL; - } - } - - cont = ezxml_next(cont); - } - dom = ezxml_next(dom); - } - ezxml_free(xmli); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Processes custom smiley messages - -void CMsnProto::MSN_CustomSmiley(const char* msgBody, char* email, char* nick, int iSmileyType) -{ - MCONTACT hContact = MSN_HContactFromEmail(email, nick, true, true); - - char smileyList[500] = ""; - - const char *tok1 = msgBody, *tok2; - char *smlp = smileyList; - char lastsml[50]; - - unsigned iCount = 0; - bool parseSmiley = true; - - for (;;) { - tok2 = strchr(tok1, '\t'); - if (tok2 == NULL) break; - - size_t sz = tok2 - tok1; - if (parseSmiley) { - sz = min(sz, sizeof(lastsml)-1); - memcpy(lastsml, tok1, sz); - lastsml[sz] = 0; - - memcpy(smlp, tok1, sz); smlp += sz; - *(smlp++) = '\n'; *smlp = 0; - ++iCount; - } - else { - filetransfer* ft = new filetransfer(this); - ft->std.hContact = hContact; - - ft->p2p_object = (char*)mir_alloc(sz + 1); - memcpy(ft->p2p_object, tok1, sz); - ft->p2p_object[sz] = 0; - - size_t slen = mir_strlen(lastsml); - ptrA buf(mir_base64_encode((PBYTE)lastsml, (unsigned)slen)); - ptrA smileyName(mir_urlEncode(buf)); - - wchar_t path[MAX_PATH]; - MSN_GetCustomSmileyFileName(hContact, path, _countof(path), smileyName, iSmileyType); - ft->std.tszCurrentFile = mir_wstrdup(path); - - if (p2p_IsDlFileOk(ft)) - delete ft; - else { - debugLogA("Custom Smiley p2p invite for object : %s", ft->p2p_object); - p2p_invite(iSmileyType, ft, email); - Sleep(3000); - } - } - parseSmiley = !parseSmiley; - tok1 = tok2 + 1; - } -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Process user addition - -void CMsnProto::MSN_ProcessAdd(char* buf, size_t len) -{ - if (buf == NULL) return; - - ezxml_t xmli = ezxml_parse_str(buf, len); - ezxml_t dom = ezxml_child(xmli, "d"); - while (dom != NULL) { - const char* szDom = ezxml_attr(dom, "n"); - ezxml_t cont = ezxml_child(dom, "c"); - while (cont != NULL) { - const char* szCont = ezxml_attr(cont, "n"); - const char* szNick = ezxml_attr(cont, "f"); - int listId = atol(ezxml_attr(cont, "l")); - int netId = atol(ezxml_attr(cont, "t")); - - char szEmail[128]; - mir_snprintf(szEmail, "%s@%s", szCont, szDom); - - UrlDecode((char*)szNick); - - if (listId == LIST_FL) { - MCONTACT hContact = MSN_HContactFromEmail(szEmail, szNick, true, false); - MSN_SetContactDb(hContact, szEmail); - } - - if (listId == LIST_RL) - MSN_SharingFindMembership(true); - else - MSN_AddUser(NULL, szEmail, netId, listId); - - MsnContact* msc = Lists_Get(szEmail); - if (msc == NULL) { - Lists_Add(listId, netId, szEmail); - msc = Lists_Get(szEmail); - } - - if (listId == LIST_RL) { - if ((msc->list & (LIST_AL | LIST_BL)) == 0) { - MSN_AddAuthRequest(szEmail, szNick, msc->invite); - msc->netId = netId; - } - else MSN_AddUser(NULL, szEmail, netId, LIST_PL + LIST_REMOVE); - } - - cont = ezxml_next(cont); - } - dom = ezxml_next(dom); - } - ezxml_free(xmli); -} - -void CMsnProto::MSN_ProcessPage(char* buf, unsigned len) -{ - if (buf == NULL) return; - ezxml_t xmlnot = ezxml_parse_str(buf, len); - - ezxml_t xmlbdy = ezxml_get(xmlnot, "MSG", 0, "BODY", -1); - const char* szMsg = ezxml_txt(ezxml_child(xmlbdy, "TEXT")); - const char* szTel = ezxml_attr(ezxml_child(xmlnot, "FROM"), "name"); - - if (szTel && *szMsg) { - PROTORECVEVENT pre = { 0 }; - pre.szMessage = (char*)szMsg; - pre.flags = PREF_UTF /*+ ((isRtl) ? PREF_RTL : 0)*/; - pre.timestamp = time(NULL); - ProtoChainRecvMsg(MSN_HContactFromEmail(szTel, szTel, true, true), &pre); - } - ezxml_free(xmlnot); -} - - -void CMsnProto::MSN_InitSB(ThreadData* info, const char* szEmail) -{ - MsnContact *cont = Lists_Get(szEmail); - - if (cont->netId == NETID_MSN) - info->sendCaps(); - - bool typing = false; - - for (int i = 3; --i;) { - MsgQueueEntry E; - while (MsgQueue_GetNext(szEmail, E)) { - if (E.msgType == 'X') ; - else if (E.msgType == 2571) - typing = E.flags != 0; - else if (E.msgSize == 0) { - info->sendMessage(E.msgType, NULL, 1, E.message, E.flags); - ProtoBroadcastAck(cont->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)E.seq, 0); - } - else { - if (E.msgType == 'D' && !info->mBridgeInit) { //&& strchr(data.flags, ':')) { - info->mBridgeInit = true; - -// P2PV2_Header hdrdata(E.message); -// P2PV2_Header tHdr; -// tHdr.mID = hdrdata.mID; -// p2p_sendMsg(info, E.wlid, 0, tHdr, NULL, 0); - } - info->sendRawMessage(E.msgType, E.message, E.msgSize); - } - - mir_free(E.message); - mir_free(E.wlid); - - if (E.ft != NULL) - info->mMsnFtp = E.ft; - } - mir_free(info->mInitialContactWLID); info->mInitialContactWLID = NULL; - } - - if (typing) - MSN_StartStopTyping(info, true); - - if (getByte("EnableDeliveryPopup", 0)) - MSN_ShowPopup(cont->hContact, info->mCaller ? - TranslateT("Chat session established by my request") : - TranslateT("Chat session established by contact request"), 0); - - PROTO_AVATAR_INFORMATION ai = { 0 }; - ai.hContact = cont->hContact; - GetAvatarInfo(GAIF_FORCE, (LPARAM)&ai); -} - -int CMsnProto::MSN_HandleCommands(ThreadData* info, char* cmdString) -{ - char* params = ""; - int trid = -1; - - if (cmdString[3]) { - if (isdigit((BYTE)cmdString[4])) { - trid = strtol(cmdString + 4, ¶ms, 10); - switch (*params) { - case ' ': case '\0': case '\t': case '\n': - while (*params == ' ' || *params == '\t') - params++; - break; - - default: - params = cmdString + 4; - } - } - else params = cmdString + 4; - } - - switch((*(PDWORD)cmdString & 0x00FFFFFF) | 0x20000000) { - case ' KCA': //********* ACK: section 8.7 Instant Messages - ReleaseSemaphore(info->hWaitEvent, 1, NULL); - - if (info->mJoinedContactsWLID.getCount() > 0 && MyOptions.SlowSend) - ProtoBroadcastAck(info->getContactHandle(), ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)trid, 0); - break; - - case ' YQF': //********* FQY: Find Yahoo User - char* tWords[1]; - if (sttDivideWords(params, 1, tWords) != 1) - debugLogA("Invalid %.3s command, ignoring", cmdString); - else { - size_t len = atol(tWords[0]); - MSN_ProcessYFind((char*)HReadBuffer(info, 0).surelyRead(len), len); - } - break; - - case ' LDA': //********* ADL: Add to the list - { - char* tWords[1]; - if (sttDivideWords(params, 1, tWords) != 1) { -LBL_InvalidCommand: - debugLogA("Invalid %.3s command, ignoring", cmdString); - break; - } - - if (mir_strcmp(tWords[0], "OK") != 0) { - size_t len = atol(tWords[0]); - MSN_ProcessAdd((char*)HReadBuffer(info, 0).surelyRead(len), len); - } - } - break; - - case ' SBS': - break; - - case ' SNA': //********* ANS: section 8.4 Getting Invited to a Switchboard Session - break; - - case ' PRP': - break; - - case ' PLB': //********* BLP: section 7.6 List Retrieval And Property Management - break; - - case ' EYB': //********* BYE: section 8.5 Session Participant Changes - { - union { - char* tWords[2]; - // modified for chat, orginally param2 = junk - // param 2: quit due to idle = "1", normal quit = nothing - struct { char *userEmail, *isIdle; } data; - }; - - sttDivideWords(params, 2, tWords); - UrlDecode(data.userEmail); - - if (strchr(data.userEmail, ';')) { - if (info->mJoinedContactsWLID.getCount() == 1) - p2p_clearThreadSessions((MCONTACT)info->mJoinedContactsWLID[0], info->mType); - info->contactLeft(data.userEmail); - break; - } - - MCONTACT hContact = MSN_HContactFromEmail(data.userEmail); - - if (getByte("EnableSessionPopup", 0)) - MSN_ShowPopup(hContact, TranslateT("Contact left channel"), 0); - - // modified for chat - { - GCDEST gcd = { m_szModuleName, info->mChatID, GC_EVENT_QUIT }; - GCEVENT gce = { &gcd }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = GetContactNameT(hContact); - gce.ptszUID = mir_a2u(data.userEmail); - gce.time = time(NULL); - gce.bIsMe = FALSE; - Chat_Event(&gce); - mir_free((void*)gce.ptszUID); - } - - int personleft = info->contactLeft(data.userEmail); - - int temp_status = getWord(hContact, "Status", ID_STATUS_OFFLINE); - if (temp_status == ID_STATUS_INVISIBLE && MSN_GetThreadByContact(data.userEmail) == NULL) - setWord(hContact, "Status", ID_STATUS_OFFLINE); - - // see if the session is quit due to idleness - if (info->mChatID[0] && personleft == 1) { - if (!mir_strcmp(data.isIdle, "1")) { - GCDEST gcd = { m_szModuleName, info->mChatID, GC_EVENT_INFORMATION }; - GCEVENT gce = { &gcd }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.bIsMe = FALSE; - gce.time = time(NULL); - gce.ptszText = TranslateT("This conversation has been inactive, participants will be removed."); - Chat_Event(&gce); - gce.ptszText = TranslateT("To resume the conversation, please quit this session and start a new chat session."); - Chat_Event(&gce); - } - else { - if (!g_bTerminated && MessageBox(NULL, - TranslateT("There is only 1 person left in the chat, do you want to switch back to standard message window?"), - TranslateT("MSN Chat"), MB_YESNO | MB_ICONQUESTION) == IDYES) { - // kill chat dlg and open srmm dialog - MSN_KillChatSession(info->mChatID); - - // open up srmm dialog when quit while 1 person left - MCONTACT hContact = info->getContactHandle(); - if (hContact) CallServiceSync(MS_MSG_SENDMESSAGE, hContact, 0); - } - } - } - // this is not in chat session, quit the session when everyone left - else if (info->mJoinedContactsWLID.getCount() < 1) - return 1; - - } - break; - - case ' LAC': //********* CAL: section 8.3 Inviting Users to a Switchboard Session - break; - - case ' GHC': //********* CHG: section 7.7 Client States - { - int oldStatus = m_iStatus; - int newStatus = MSNStatusToMiranda(params); - if (oldStatus <= ID_STATUS_OFFLINE) { - isConnectSuccess = true; - int count = -1; - for (;;) { - MsnContact *msc = Lists_GetNext(count); - if (msc == NULL) break; - - if (msc->netId == NETID_MOB) - setWord(msc->hContact, "Status", ID_STATUS_ONTHEPHONE); - } - } - if (newStatus != ID_STATUS_IDLE) { - m_iStatus = newStatus; - ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, newStatus); - debugLogA("Status change acknowledged: %s", params); - MSN_RemoveEmptyGroups(); - } - if (newStatus == ID_STATUS_OFFLINE) return 1; - } - break; - case ' LHC': //********* CHL: Query from Server on MSNP7 - { - char* authChallengeInfo; - if (sttDivideWords(params, 1, &authChallengeInfo) != 1) - goto LBL_InvalidCommand; - - char dgst[64]; - MSN_MakeDigest(authChallengeInfo, dgst); - info->sendPacket("QRY", "%s 32\r\n%s", msnProductID, dgst); - } - break; - - case ' RVC': //********* CVR: MSNP8 - break; - - case ' NLF': //********* FLN: section 7.9 Notification Messages - { - union { - char* tWords[2]; - struct { char *userEmail, *netId; } data; - }; - - int tArgs = sttDivideWords(params, 2, tWords); - if (tArgs < 2) - goto LBL_InvalidCommand; - - MCONTACT hContact = MSN_HContactFromEmail(data.userEmail); - if (hContact != NULL) { - setWord(hContact, "Status", MSN_GetThreadByContact(data.userEmail) ? ID_STATUS_INVISIBLE : ID_STATUS_OFFLINE); - setDword(hContact, "IdleTS", 0); - ForkThread(&CMsnProto::MsgQueue_AllClearThread, mir_strdup(data.userEmail)); - } - } - break; - - case ' NLI': - case ' NLN': //********* ILN/NLN: section 7.9 Notification Messages - { - union { - char* tWords[5]; - struct { char *userStatus, *wlid, *userNick, *objid, *cmdstring; } data; - }; - - int tArgs = sttDivideWords(params, 5, tWords); - if (tArgs < 3) - goto LBL_InvalidCommand; - - if (data.cmdstring) UrlDecode(data.cmdstring); - MSN_ProcessNLN(data.userStatus, data.wlid, data.userNick, data.objid, data.cmdstring); - } - break; - case ' ORI': //******** IRO: section 8.4 Getting Invited to a Switchboard Session - { - union { - char* tWords[5]; - struct { char *strThisContact, *totalContacts, *userEmail, *userNick, *flags; } data; - }; - - int tNumTokens = sttDivideWords(params, 5, tWords); - if (tNumTokens < 4) - goto LBL_InvalidCommand; - - info->contactJoined(data.userEmail); - - if (!strchr(data.userEmail, ';')) { - UrlDecode(data.userNick); - MCONTACT hContact = MSN_HContactFromEmail(data.userEmail, data.userNick, true, true); - - if (tNumTokens == 5 && mir_strcmp(data.flags, "0:0")) { - MsnContact *cont = Lists_Get(data.userEmail); - if (cont) { - char* end = NULL; - cont->cap1 = strtoul(data.flags, &end, 10); - cont->cap2 = end && *end == ':' ? strtoul(end + 1, NULL, 10) : 0; - } - } - - int temp_status = getWord(hContact, "Status", ID_STATUS_OFFLINE); - if (temp_status == ID_STATUS_OFFLINE && Lists_IsInList(LIST_FL, data.userEmail)) - setWord(hContact, "Status", ID_STATUS_INVISIBLE); - - // only start the chat session after all the IRO messages has been recieved - if (info->mJoinedContactsWLID.getCount() > 1 && !mir_strcmp(data.strThisContact, data.totalContacts)) - MSN_ChatStart(info); - } - } - break;*/ - - case ' IOJ': //******** JOI: section 8.5 Session Participant Changes - { - union { - char* tWords[3]; - struct { char *userEmail, *userNick, *flags; } data; - }; - - int tNumTokens = sttDivideWords(params, 3, tWords); - if (tNumTokens < 2) - goto LBL_InvalidCommand; - - UrlDecode(data.userEmail); - - if (strchr(data.userEmail, ';')) { - info->contactJoined(data.userEmail); - break; - } - - if (_stricmp(MyOptions.szEmail, data.userEmail) == 0) { - if (!info->mCaller) { - if (info->mJoinedContactsWLID.getCount() == 1) { - MSN_InitSB(info, info->mJoinedContactsWLID[0]); - } - else { - info->sendCaps(); - if (info->mInitialContactWLID && MsgQueue_CheckContact(info->mInitialContactWLID)) - msnNsThread->sendPacket("XFR", "SB"); - mir_free(info->mInitialContactWLID); info->mInitialContactWLID = NULL; - } - break; - } - - const char* wlid; - do { - wlid = MsgQueue_GetNextRecipient(); - } - while (wlid != NULL && MSN_GetUnconnectedThread(wlid) != NULL); - - //can happen if both parties send first message at the same time - if (wlid == NULL) { - debugLogA("USR (SB) internal: thread created for no reason"); - return 1; - } - - if (mir_strcmp(wlid, "chat") == 0) { - MsgQueueEntry E; - MsgQueue_GetNext(wlid, E); - - for (int i = 0; i < E.cont->getCount(); ++i) - info->sendPacket("CAL", (*E.cont)[i]); - - MSN_ChatStart(info); - - delete E.cont; - mir_free(E.wlid); - break; - } - - char* szEmail; - parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - - info->mInitialContactWLID = mir_strdup(szEmail); - info->sendPacket("CAL", szEmail); - break; - } - - UrlDecode(data.userNick); - stripBBCode(data.userNick); - stripColorCode(data.userNick); - - MCONTACT hContact = MSN_HContactFromEmail(data.userEmail, data.userNick, true, true); - if (tNumTokens == 3) { - MsnContact *cont = Lists_Get(data.userEmail); - if (cont) { - char* end = NULL; - cont->cap1 = strtoul(data.flags, &end, 10); - cont->cap2 = end && *end == ':' ? strtoul(end + 1, NULL, 10) : 0; - } - } - - mir_utf8decode(data.userNick, NULL); - debugLogA("New contact in channel %s %s", data.userEmail, data.userNick); - - if (info->contactJoined(data.userEmail) <= 1) - MSN_InitSB(info, data.userEmail); - else { - bool chatCreated = info->mChatID[0] != 0; - - info->sendCaps(); - - if (chatCreated) { - GCDEST gcd = { m_szModuleName, info->mChatID, GC_EVENT_JOIN }; - GCEVENT gce = { &gcd }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = GetContactNameT(hContact); - gce.ptszUID = mir_a2u(data.userEmail); - gce.ptszStatus = TranslateT("Others"); - gce.time = time(NULL); - gce.bIsMe = FALSE; - Chat_Event(&gce); - mir_free((void*)gce.ptszUID); - } - else MSN_ChatStart(info); - } - } - break;*/ - - case ' GSM': //********* MSG: sections 8.7 Instant Messages, 8.8 Receiving an Instant Message - MSN_ReceiveMessage(info, cmdString, params); - break; - - case ' MBU': - MSN_ReceiveMessage(info, cmdString, params); - break; - - case ' KAN': //********* NAK: section 8.7 Instant Messages - if (info->mJoinedContactsWLID.getCount() > 0 && MyOptions.SlowSend) - ProtoBroadcastAck(info->getContactHandle(), - ACKTYPE_MESSAGE, ACKRESULT_FAILED, - (HANDLE)trid, (LPARAM)Translate("Message delivery failed")); - debugLogA("Message send failed (trid=%d)", trid); - break; - - case ' TON': //********* NOT: notification message - MSN_ProcessNotificationMessage((char*)HReadBuffer(info, 0).surelyRead(trid), trid); - break; - - case ' GPI': //********* IPG: mobile page - MSN_ProcessPage((char*)HReadBuffer(info, 0).surelyRead(trid), trid); - break; - - case ' FCG': //********* GCF: - HReadBuffer(info, 0).surelyRead(atol(params)); - break; - - case ' TUO': //********* OUT: sections 7.10 Connection Close, 8.6 Leaving a Switchboard Session - if (!_stricmp(params, "OTH")) { - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_OTHERLOCATION); - debugLogA("You have been disconnected from the MSN server because you logged on from another location using the same MSN passport."); - } - - if (!_stricmp(params, "MIG")) // ignore it - break; - - return 1; - - case ' YRQ': //********* QRY: - break; - - case ' GNQ': //********* QNG: reply to PNG - msnPingTimeout = trid; - if (info->mType == SERVER_NOTIFICATION && hKeepAliveThreadEvt != NULL) - SetEvent(hKeepAliveThreadEvt); - break; - - case ' LMR': //********* RML: Remove from the list - { - char* tWords[1]; - if (sttDivideWords(params, 1, tWords) != 1) - goto LBL_InvalidCommand; - - if (mir_strcmp(tWords[0], "OK") != 0) { - size_t len = atol(tWords[0]); - MSN_ProcessRemove((char*)HReadBuffer(info, 0).surelyRead(len), len); - } - } - break; - - case ' GNR': //********* RNG: section 8.4 Getting Invited to a Switchboard Session - //note: unusual message encoding: trid==sessionid - { - union { - char* tWords[8]; - struct { char *newServer, *security, *authChallengeInfo, *callerEmail, *callerNick, - *type, *srcUrl, *genGateway; } data; - }; - - if (sttDivideWords(params, 8, tWords) != 8) - goto LBL_InvalidCommand; - - UrlDecode(data.newServer); UrlDecode(data.callerEmail); - UrlDecode(data.callerNick); - stripBBCode(data.callerNick); - stripColorCode(data.callerNick); - - if (mir_strcmp(data.security, "CKI")) { - debugLogA("Unknown security package in RNG command: %s", data.security); - break; - } - - ThreadData* newThread = new ThreadData; - mir_strcpy(newThread->mServer, data.newServer); - newThread->gatewayType = atol(data.genGateway) != 0; - newThread->mType = SERVER_SWITCHBOARD; - newThread->mInitialContactWLID = mir_strdup(data.callerEmail); - MSN_HContactFromEmail(data.callerEmail, data.callerNick, true, true); - mir_snprintf(newThread->mCookie, "%s %d", data.authChallengeInfo, trid); - - ReleaseSemaphore(newThread->hWaitEvent, MSN_PACKETS_COMBINE, NULL); - - debugLogA("Opening caller's switchboard server '%s'...", data.newServer); - newThread->startThread(&CMsnProto::MSNServerThread, this); - } - break; - - case ' XBU': // UBX : MSNP11+ User Status Message - { - union { - char* tWords[2]; - struct { char *wlid, *datalen; } data; - }; - - if (sttDivideWords(params, 2, tWords) != 2) - goto LBL_InvalidCommand; - - int len = atol(data.datalen); - if (len < 0 || len > 4000) - goto LBL_InvalidCommand; - - ezxml_t xmli = ezxml_parse_str((char*)HReadBuffer(info, 0).surelyRead(len), len); - if (xmli) { - MSN_ProcessStatusMessage(xmli, data.wlid); - ezxml_free(xmli); - } - } - break; - - case ' NBU': // UBN : MSNP13+ File sharing, P2P Bootstrap, TURN setup. - { - union { - char* tWords[3]; - struct { char *email, *typeId, *datalen; } data; - }; - - if (sttDivideWords(params, 3, tWords) != 3) - goto LBL_InvalidCommand; - - int len = atol(data.datalen); - if (len < 0 || len > 4000) - goto LBL_InvalidCommand; - - HReadBuffer buf(info, 0); - char* msgBody = (char*)buf.surelyRead(len); - - char *szEmail = data.email; - if (strstr(data.email, sttVoidUid)) - parseWLID(NEWSTR_ALLOCA(data.email), NULL, &szEmail, NULL); - - switch (atol(data.typeId)) { - case 1: - // File sharing stuff - // sttProcessFileSharing(msgBody, len, hContact); - break; - - case 3: - // P2P Bootstrap - p2p_processSIP(info, msgBody, NULL, szEmail); - break; - - case 4: - case 8: - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_OTHERLOCATION); - debugLogA("You have been disconnected from the MSN server because you logged on from another location using the same MSN passport."); - break; - - case 6: - MSN_SharingFindMembership(true); - MSN_ABFind("ABFindContactsPaged", NULL, true); - break; - - case 10: - // TURN setup - p2p_processSIP(info, msgBody, NULL, szEmail); - break; - } - } - break; - - case ' NUU': // UUN : MSNP13+ File sharing, P2P Bootstrap, TURN setup. - break; - - case ' RSU': //********* USR: sections 7.3 Authentication, 8.2 Switchboard Connections and Authentication - if (info->mType == SERVER_SWITCHBOARD) { //(section 8.2) - union { - char* tWords[3]; - struct { char *status, *userHandle, *friendlyName; } data; - }; - - if (sttDivideWords(params, 3, tWords) != 3) - goto LBL_InvalidCommand; - - UrlDecode(data.userHandle); UrlDecode(data.friendlyName); - - if (mir_strcmp(data.status, "OK")) { - debugLogA("Unknown status to USR command (SB): '%s'", data.status); - break; - } - - info->sendPacket("CAL", MyOptions.szEmail); - } - else { //dispatch or notification server (section 7.3) - union { - char* tWords[4]; - struct { char *security, *sequence, *authChallengeInfo, *nonce; } data; - }; - - if (sttDivideWords(params, 4, tWords) != 4) - goto LBL_InvalidCommand; - - if (!mir_strcmp(data.security, "SSO")) { - if (MSN_GetPassportAuth()) { - m_iDesiredStatus = ID_STATUS_OFFLINE; - return 1; - } - - char* sec = GenerateLoginBlob(data.nonce); - info->sendPacket("USR", "SSO S %s %s %s", authStrToken ? authStrToken : "", sec, MyOptions.szMachineGuid); - mir_free(sec); - - ForkThread(&CMsnProto::msn_keepAliveThread, NULL); - ForkThread(&CMsnProto::MSNConnDetectThread, NULL); - } - else if (!mir_strcmp(data.security, "OK")) { - } - else { - debugLogA("Unknown security package '%s'", data.security); - - if (info->mType == SERVER_NOTIFICATION) - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPROTOCOL); - return 1; - } - } - break; - - case ' SFR': // RFS: Refresh Contact List - if (!MSN_RefreshContactList()) { - MSN_ShowError("Cannot retrieve contact list"); - return 1; - } - break; - - case ' XUU': // UUX: MSNP11 addition - { - char* tWords[1]; - if (sttDivideWords(params, _countof(tWords), tWords) != _countof(tWords)) - goto LBL_InvalidCommand; - - int len = atol(tWords[0]); - if (len < 0 || len > 4000) - goto LBL_InvalidCommand; - - HReadBuffer(info, 0).surelyRead(len); - } - break; - - case ' REV': //******** VER: section 7.1 Protocol Versioning - { - char* protocol1; - if (sttDivideWords(params, 1, &protocol1) != 1) - goto LBL_InvalidCommand; - - if (MyOptions.szEmail[0] == 0) { - MSN_ShowError("You must specify your e-mail in Options/Network/MSN"); - return 1; - } - - OSVERSIONINFOEX osvi = {0}; - osvi.dwOSVersionInfoSize = sizeof(osvi); - GetVersionEx((LPOSVERSIONINFO)&osvi); - - info->sendPacket("CVR","0x0409 %s %d.%d.%d i386 MSNMSGR %s msmsgs %s", - osvi.dwPlatformId >= 2 ? "winnt" : "win", osvi.dwMajorVersion, - osvi.dwMinorVersion, osvi.wServicePackMajor, - msnProductVer, MyOptions.szEmail); - - info->sendPacket("USR", "SSO I %s", MyOptions.szEmail); - } - break; - case ' RFX': //******** XFR: sections 7.4 Referral, 8.1 Referral to Switchboard - { - union { - char* tWords[7]; - struct { char *type, *newServer, *security, *authChallengeInfo, - *type2, *srcUrl, *genGateway; } data; - }; - - int numWords = sttDivideWords(params, 7, tWords); - if (numWords < 3) - goto LBL_InvalidCommand; - - if (!mir_strcmp(data.type, "NS")) { //notification server - UrlDecode(data.newServer); - ThreadData* newThread = new ThreadData; - mir_strcpy(newThread->mServer, data.newServer); - newThread->mType = SERVER_NOTIFICATION; - newThread->mTrid = info->mTrid; - newThread->mIsMainThread = true; - usingGateway |= (*data.security == 'G'); - info->mIsMainThread = false; - - debugLogA("Switching to notification server '%s'...", data.newServer); - newThread->startThread(&CMsnProto::MSNServerThread, this); - return 1; //kill the old thread - } - - if (!mir_strcmp(data.type, "SB")) { //switchboard server - UrlDecode(data.newServer); - - if (numWords < 4) - goto LBL_InvalidCommand; - - if (mir_strcmp(data.security, "CKI")) { - debugLogA("Unknown XFR SB security package '%s'", data.security); - break; - } - - ThreadData* newThread = new ThreadData; - mir_strcpy(newThread->mServer, data.newServer); - newThread->gatewayType = data.genGateway && atol(data.genGateway) != 0; - newThread->mType = SERVER_SWITCHBOARD; - newThread->mCaller = 1; - mir_strcpy(newThread->mCookie, data.authChallengeInfo); - - debugLogA("Opening switchboard server '%s'...", data.newServer); - newThread->startThread(&CMsnProto::MSNServerThread, this); - } - else debugLogA("Unknown referral server: %s", data.type); - } - break; - - default: - debugLogA("Unrecognised message: %s", cmdString); - break; - } - - return 0; -} -#endif \ No newline at end of file diff --git a/protocols/MSN/src/msn_contact.cpp b/protocols/MSN/src/msn_contact.cpp index 5e4aa5295d..6bd06b9d1c 100644 --- a/protocols/MSN/src/msn_contact.cpp +++ b/protocols/MSN/src/msn_contact.cpp @@ -108,28 +108,6 @@ void CMsnProto::MSN_SetContactDb(MCONTACT hContact, const char *szEmail) void CMsnProto::AddDelUserContList(const char* email, const int list, const int netId, const bool del) { -#ifdef OBSOLETE - char buf[512]; - size_t sz; - - if (list < LIST_RL) { - const char* dom = strchr(email, '@'); - if (dom == NULL) { - sz = mir_snprintf(buf, - "", - email, list); - } - else { - *(char*)dom = 0; - sz = mir_snprintf(buf, - "", - dom + 1, email, list, netId); - *(char*)dom = '@'; - } - msnNsThread->sendPacket(del ? "RML" : "ADL", "%d\r\n%s", sz, buf); - } -#endif - if (del) Lists_Remove(list, email); else @@ -220,10 +198,6 @@ bool CMsnProto::MSN_AddUser(MCONTACT hContact, const char* email, int netId, int MSN_SharingFindMembership(true); AddDelUserContList(email, flags, netId, false); } - #ifdef OBSOLETE - else if (netId == 1 && strstr(email, "@yahoo.com") != 0) - MSN_FindYahooUser(email); - #endif db_free(&dbv); } @@ -239,10 +213,6 @@ bool CMsnProto::MSN_AddUser(MCONTACT hContact, const char* email, int netId, int netId = Lists_GetNetId(email); res = MSN_SharingAddDelMember(email, flags, netId, needRemove ? "DeleteMember" : "AddMember"); 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); @@ -251,22 +221,6 @@ bool CMsnProto::MSN_AddUser(MCONTACT hContact, const char* email, int netId, int return res; } -#ifdef OBSOLETE -void CMsnProto::MSN_FindYahooUser(const char* email) -{ - const char *dom = strchr(email, '@'); - if (dom) { - char buf[512]; - size_t sz; - - *(char*)dom = '\0'; - sz = mir_snprintf(buf, "", dom + 1, email); - *(char*)dom = '@'; - msnNsThread->sendPacket("FQY", "%d\r\n%s", sz, buf); - } -} -#endif - bool CMsnProto::MSN_RefreshContactList(void) { Lists_Wipe(); diff --git a/protocols/MSN/src/msn_errors.cpp b/protocols/MSN/src/msn_errors.cpp index 0b4e16f06c..f1259425e5 100644 --- a/protocols/MSN/src/msn_errors.cpp +++ b/protocols/MSN/src/msn_errors.cpp @@ -106,10 +106,8 @@ int CMsnProto::MSN_HandleErrors(ThreadData* info, char* cmdString) return 0; case ERR_AUTHENTICATION_FAILED: - if (info->mType != SERVER_SWITCHBOARD) { - MSN_ShowError("Your username or password is incorrect"); - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD); - } + MSN_ShowError("Your username or password is incorrect"); + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD); return 1; default: diff --git a/protocols/MSN/src/msn_ftold.cpp b/protocols/MSN/src/msn_ftold.cpp deleted file mode 100644 index c6bc904b55..0000000000 --- a/protocols/MSN/src/msn_ftold.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* -Plugin of Miranda IM for communicating with users of the MSN Messenger protocol. - -Copyright (c) 2012-2017 Miranda NG Team -Copyright (c) 2006-2012 Boris Krasnovskiy. -Copyright (c) 2003-2005 George Hazan. -Copyright (c) 2002-2003 Richard Hughes (original version). - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdafx.h" -#include "msn_proto.h" -#ifdef OBSOLETE - -void CMsnProto::msnftp_sendAcceptReject(filetransfer *ft, bool acc) -{ - ThreadData* thread = MSN_GetThreadByContact(ft->p2p_dest); - if (thread == NULL) return; - - 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" - "Invitation-Command: ACCEPT\r\n" - "Invitation-Cookie: %s\r\n" - "Launch-Application: FALSE\r\n" - "Request-Data: IP-Address:\r\n\r\n", - 172 + 4 + mir_strlen(ft->szInvcookie), ft->szInvcookie); - } - 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 + mir_strlen(ft->szInvcookie), ft->szInvcookie); - } -} - -void CMsnProto::msnftp_invite(filetransfer *ft) -{ - bool isOffline; - ThreadData* thread = MSN_StartSB(ft->p2p_dest, isOffline); - if (isOffline) return; - if (thread != NULL) thread->mMsnFtp = ft; - - wchar_t* pszFiles = wcsrchr(ft->std.ptszFiles[0], '\\'); - if (pszFiles) - pszFiles++; - else - pszFiles = *ft->std.ptszFiles; - - char msg[1024]; - mir_snprintf(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" - "Invitation-Command: INVITE\r\n" - "Invitation-Cookie: %i\r\n" - "Application-File: %s\r\n" - "Application-FileSize: %I64u\r\n\r\n", - MSN_GenRandom(), UTF8(pszFiles), ft->std.currentFileSize); - - if (thread == NULL) - MsgQueue_Add(ft->p2p_dest, 'S', msg, -1, ft); - else - thread->sendMessage('S', NULL, NETID_MSN, msg, MSG_DISABLE_HDR); -} - - -///////////////////////////////////////////////////////////////////////////////////////// -// MSN File Transfer Protocol commands processing - -int CMsnProto::MSN_HandleMSNFTP(ThreadData *info, char *cmdString) -{ - char* params = ""; - filetransfer* ft = info->mMsnFtp; - - if (cmdString[3]) - 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; - - info->mCaller = 1; - info->send("TFR\r\n", 5); - break; - - case ' RFT': //********* TFR - { - char *sendpacket = (char*)alloca(2048); - filetransfer* ft = info->mMsnFtp; - - info->mCaller = 3; - - while (ft->std.currentFileProgress < ft->std.currentFileSize) { - if (ft->bCanceled) { - sendpacket[0] = 0x01; - sendpacket[1] = 0x00; - sendpacket[2] = 0x00; - info->send(sendpacket, 3); - return 0; - } - - int wPlace = 0; - sendpacket[wPlace++] = 0x00; - unsigned __int64 packetLen = ft->std.currentFileSize - ft->std.currentFileProgress; - if (packetLen > 2045) packetLen = 2045; - - sendpacket[wPlace++] = (char)(packetLen & 0x00ff); - sendpacket[wPlace++] = (char)((packetLen & 0xff00) >> 8); - _read(ft->fileId, &sendpacket[wPlace], packetLen); - - info->send(&sendpacket[0], packetLen + 3); - - ft->std.totalProgress += packetLen; - ft->std.currentFileProgress += packetLen; - - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); - } - - 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; - } - - char tCommand[30]; - size_t tCommandLen; - tCommandLen = mir_snprintf(tCommand, "FIL %i\r\n", info->mMsnFtp->std.totalBytes); - info->send(tCommand, tCommandLen); - break; - - case ' REV': //********* VER - char protocol1[7]; - if (sscanf(params, "%6s", protocol1) < 1) { -LBL_InvalidCommand: - debugLogA("Invalid %.3s command, ignoring", cmdString); - break; - } - - if (mir_strcmp(protocol1, "MSNFTP") != 0) { - int tempInt; - int tFieldCount = sscanf(params, "%d %6s", &tempInt, protocol1); - if (tFieldCount != 2 || mir_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]; - size_t tCommandLen; - tCommandLen = mir_snprintf(tCommand, "USR %s %s\r\n", MyOptions.szEmail, info->mCookie); - info->send(tCommand, tCommandLen); - } - else if (info->mCaller == 2) { //send - static const char sttCommand[] = "VER MSNFTP\r\n"; - info->send(sttCommand, mir_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; - } - - BYTE tIsTransitionFinished = *p++; - WORD dataLen = *p++; - dataLen |= (*p++ << 8); - - if (tIsTransitionFinished) { -LBL_Success: - static const char sttCommand[] = "BYE 16777989\r\n"; - info->send(sttCommand, mir_strlen(sttCommand)); - return 1; - } - - p = tBuf.surelyRead(dataLen); - if (p == NULL) - goto LBL_Error; - - _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); - - if (ft->std.currentFileProgress == ft->std.totalBytes) { - ft->complete(); - goto LBL_Success; - } - } - } - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// ft_startFileSend - sends a file using the old f/t protocol - -void __cdecl CMsnProto::msnftp_sendFileThread(void* arg) -{ - ThreadData* info = (ThreadData*)arg; - - debugLogA("Waiting for an incoming connection to '%s'...", info->mServer); - - switch (WaitForSingleObject(info->hWaitEvent, 60000)) { - case WAIT_TIMEOUT: - case WAIT_FAILED: - debugLogA("Incoming connection timed out, closing file transfer"); - return; - } - - info->mBytesInData = 0; - - 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 (MSN_HandleMSNFTP(info, info->mData)) - break; - } - else // info->mType!=SERVER_FILETRANS - { - for (;;) { - char* peol = strchr(info->mData, '\r'); - if (peol == NULL) - break; - - 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; - if (*++peol != '\n') - debugLogA("Dodgy line ending to command: ignoring"); - else - peol++; - - info->mBytesInData -= peol - info->mData; - memmove(info->mData, peol, info->mBytesInData); - - debugLogA("RECV:%s", msg); - - 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 == info->mDataSize) { - char *mData = (char*)mir_realloc(info->mData, (info->mDataSize*=2)+1); - if (mData) info->mData = mData; else { - debugLogA("sizeof(data) is too small: the longest line won't fit"); - break; - } - } - } - - debugLogA("Closing file transfer thread"); -} - -void CMsnProto::msnftp_startFileSend(ThreadData* info, const char* Invcommand, const char* Invcookie) -{ - if (_stricmp(Invcommand, "ACCEPT")) - return; - - NETLIBBIND nlb = { 0 }; - HANDLE sb = NULL; - - filetransfer* ft = info->mMsnFtp; info->mMsnFtp = NULL; - if (ft != NULL && MyConnection.extIP) { - nlb.cbSize = sizeof(nlb); - nlb.pfnNewConnectionV2 = MSN_ConnectionProc; - nlb.pExtra = this; - - sb = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlb); - if (sb == NULL) - debugLogA("Unable to bind the port for incoming transfers"); - } - - char hostname[256] = ""; - gethostname(hostname, sizeof(hostname)); - PHOSTENT he = gethostbyname(hostname); - - const PIN_ADDR addr = (PIN_ADDR)he->h_addr_list[0]; - if (addr) - mir_strcpy(hostname, inet_ntoa(*addr)); - else - hostname[0] = 0; - - info->sendPacketPayload("MSG", "N", - "MIME-Version: 1.0\r\n" - "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" - "Invitation-Command: %s\r\n" - "Invitation-Cookie: %s\r\n" - "IP-Address: %s\r\n" - "IP-Address-Internal: %s\r\n" - "Port: %i\r\n" - "PortX: %i\r\n" - "PortX-Internal: %i\r\n" - "AuthCookie: %i\r\n" - "Launch-Application: FALSE\r\n" - "Request-Data: IP-Address:\r\n\r\n", - sb && MyConnection.extIP ? "ACCEPT" : "CANCEL", - Invcookie, MyConnection.GetMyExtIPStr(), hostname, - nlb.wExPort, nlb.wExPort ^ 0x3141, nlb.wPort ^ 0x3141, - MSN_GenRandom()); - - if (sb) { - ThreadData* newThread = new ThreadData; - newThread->mType = SERVER_FILETRANS; - newThread->mCaller = 2; - newThread->mMsnFtp = ft; - newThread->mIncomingBoundPort = sb; - newThread->mIncomingPort = nlb.wPort; - newThread->startThread(&CMsnProto::msnftp_sendFileThread, this); - } - else delete ft; -} -#endif diff --git a/protocols/MSN/src/msn_lists.cpp b/protocols/MSN/src/msn_lists.cpp index c73bfbc9d6..b59df57808 100644 --- a/protocols/MSN/src/msn_lists.cpp +++ b/protocols/MSN/src/msn_lists.cpp @@ -24,6 +24,8 @@ along with this program. If not, see . #include "msn_proto.h" #include "m_smileyadd.h" +const char sttVoidUid[] = "{00000000-0000-0000-0000-000000000000}"; + void CMsnProto::Lists_Uninit(void) { Lists_Wipe(); @@ -140,28 +142,6 @@ int CMsnProto::Lists_GetNetId(const char* email) return p ? p->netId : NETID_UNKNOWN; } -#ifdef OBSOLETE -unsigned CMsnProto::p2p_getMsgId(const char* wlid, int inc) -{ - mir_cslock lck(m_csLists); - MsnPlace *p = Lists_GetPlace(wlid); - - unsigned res = p && p->p2pMsgId ? p->p2pMsgId : MSN_GenRandom(); - if (p) - p->p2pMsgId = res + inc; - - return res; -} - -unsigned CMsnProto::p2p_getPktNum(const char* wlid) -{ - mir_cslock lck(m_csLists); - - MsnPlace *p = Lists_GetPlace(wlid); - return p ? p->p2pPktNum++ : 0; -} -#endif - int CMsnProto::Lists_Add(int list, int netId, const char* email, MCONTACT hContact, const char* nick, const char* invite) { mir_cslock lck(m_csLists); diff --git a/protocols/MSN/src/msn_menu.cpp b/protocols/MSN/src/msn_menu.cpp index 30a6c28b25..9c37f90f5a 100644 --- a/protocols/MSN/src/msn_menu.cpp +++ b/protocols/MSN/src/msn_menu.cpp @@ -125,9 +125,6 @@ int CMsnProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM) Menu_ModifyItem(hOpenInboxMenuItem, isMe ? LPGENW("Open &Hotmail Inbox") : LPGENW("Send &Hotmail E-mail")); Menu_ShowItem(hOpenInboxMenuItem, emailEnabled); -#ifdef OBSOLETE - Menu_ShowItem(hNetmeetingMenuItem, !noChat); -#endif Menu_ShowItem(hChatInviteMenuItem, !noChat); } @@ -143,124 +140,12 @@ int CMsnProto::OnContactDoubleClicked(WPARAM hContact, LPARAM) return 0; } -#ifdef OBSOLETE -// MsnSendNetMeeting - Netmeeting callback function -INT_PTR CMsnProto::MsnSendNetMeeting(WPARAM wParam, LPARAM) -{ - if (!msnLoggedIn) return 0; - - MCONTACT hContact = MCONTACT(wParam); - - char szEmail[MSN_MAX_EMAIL_LEN]; - if (MSN_IsMeByContact(hContact, szEmail)) return 0; - - ThreadData* thread = MSN_GetThreadByContact(szEmail); - - if (thread == NULL) { - MessageBox(NULL, TranslateT("You must be talking to start Netmeeting"), TranslateT("MSN Protocol"), MB_OK | MB_ICONERROR); - return 0; - } - - char msg[1024]; - - mir_snprintf(msg, - "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" - "Application-Name: NetMeeting\r\n" - "Application-GUID: {44BBA842-CC51-11CF-AAFA-00AA00B6015C}\r\n" - "Session-Protocol: SM1\r\n" - "Invitation-Command: INVITE\r\n" - "Invitation-Cookie: %i\r\n" - "Session-ID: {1A879604-D1B8-11D7-9066-0003FF431510}\r\n\r\n", - MSN_GenRandom()); - - thread->sendMessage('N', NULL, 1, msg, MSG_DISABLE_HDR); - return 0; -} - -static INT_PTR MsnMenuSendNetMeeting(WPARAM wParam, LPARAM lParam) -{ - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); - return (ppro) ? ppro->MsnSendNetMeeting(wParam, lParam) : 0; -} - -// SetNicknameCommand - sets nick name -static INT_PTR CALLBACK DlgProcSetNickname(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) { - case WM_INITDIALOG: - { - TranslateDialogDefault(hwndDlg); - - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - CMsnProto* proto = (CMsnProto*)lParam; - - Window_SetIcon_IcoLib(hwndDlg, GetIconHandle("main")); - SendDlgItemMessage(hwndDlg, IDC_NICKNAME, EM_LIMITTEXT, 129, 0); - - DBVARIANT dbv; - if (!proto->getWString("Nick", &dbv)) { - SetDlgItemText(hwndDlg, IDC_NICKNAME, dbv.ptszVal); - db_free(&dbv); - } - return TRUE; - } - case WM_COMMAND: - switch (wParam) { - case IDOK: - { - CMsnProto *proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (proto->msnLoggedIn) { - wchar_t str[130]; - GetDlgItemText(hwndDlg, IDC_NICKNAME, str, _countof(str)); - proto->MSN_SendNickname(str); - } - } - - case IDCANCEL: - DestroyWindow(hwndDlg); - break; - } - 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(g_hInst, MAKEINTRESOURCE(IDD_SETNICKNAME), - NULL, DlgProcSetNickname, (LPARAM)this); - - SetForegroundWindow(hwndSetNickname); - SetFocus(hwndSetNickname); - ShowWindow(hwndSetNickname, SW_SHOW); - return 0; -} -#endif - // Menus initialization void CMsnProto::MsnInitMainMenu(void) { CMenuItem mi; mi.root = Menu_GetProtocolRoot(this); -#ifdef OBSOLETE - mi.pszService = MS_SET_NICKNAME_UI; - CreateProtoService(mi.pszService, &CMsnProto::SetNicknameUI); - mi.position = 201001; - mi.hIcolibItem = GetIconHandle(IDI_MSN); - mi.name.a = LPGEN("Set &Nickname"); - menuItemsMain[0] = Menu_AddProtoMenuItem(&mi, m_szModuleName); -#endif - mi.pszService = MSN_INVITE; CreateProtoService(mi.pszService, &CMsnProto::MsnInviteCommand); mi.position = 201002; @@ -342,9 +227,6 @@ static int MSN_OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam) else { Menu_ShowItem(hBlockMenuItem, false); Menu_ShowItem(hLiveSpaceMenuItem, false); -#ifdef OBSOLETE - Menu_ShowItem(hNetmeetingMenuItem, false); -#endif Menu_ShowItem(hChatInviteMenuItem, false); Menu_ShowItem(hOpenInboxMenuItem, false); } @@ -377,16 +259,6 @@ void MSN_InitContactMenu(void) mi.name.a = LPGEN("View &Profile"); hLiveSpaceMenuItem = Menu_AddContactMenuItem(&mi); -#ifdef OBSOLETE - mir_strcpy(tDest, MSN_NETMEETING); - hNetMeeting = CreateServiceFunction(servicefunction, MsnMenuSendNetMeeting); - mi.flags = CMIF_NOTOFFLINE; - mi.position = -500050002; - mi.hIcolibItem = GetIconHandle(IDI_NETMEETING); - mi.name.a = LPGEN("&Start Netmeeting"); - hNetmeetingMenuItem = Menu_AddContactMenuItem(&mi); -#endif - SET_UID(mi,0x25a007c0, 0x8dc7, 0x4284, 0x8a, 0x5e, 0x2, 0x83, 0x17, 0x5d, 0x52, 0xea); mir_strcpy(tDest, "/SendHotmail"); hSendHotMail = CreateServiceFunction(servicefunction, MsnMenuSendHotmail); @@ -403,10 +275,6 @@ void MSN_RemoveContactMenus(void) { Menu_RemoveItem(hBlockMenuItem); Menu_RemoveItem(hLiveSpaceMenuItem); -#ifdef OBSOLETE - Menu_RemoveItem(hNetmeetingMenuItem); - DestroyServiceFunction(hNetMeeting); -#endif Menu_RemoveItem(hChatInviteMenuItem); Menu_RemoveItem(hOpenInboxMenuItem); diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index c61f47c32a..044877456d 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -361,9 +361,7 @@ void CMsnProto::MSN_GoOffline(void) MSN_EnableMenuItems(false); MSN_FreeGroups(); -#ifdef OBSOLETE - MsgQueue_Clear(); -#endif + clearCachedMsg(); if (!g_bTerminated) { @@ -390,12 +388,9 @@ void CMsnProto::MSN_GoOffline(void) } } } -#ifdef OBSOLETE -int ThreadData::sendMessage(int msgType, const char* email, int netId, const char* parMsg, int parFlags) -#else + // MSN_SendMessage - formats and sends a MSG packet through the server int ThreadData::sendMessage(int, const char *email, int netId, const char *parMsg, int parFlags) -#endif { CMStringA buf; @@ -441,11 +436,6 @@ int ThreadData::sendMessage(int, const char *email, int netId, const char *parMs tFontColor = db_get_dw(NULL, "SRMsg", "Font0Col", 0); } else tFontStyle[0] = 0; - -#ifdef OBSOLETE - if (parFlags & MSG_OFFLINE) - off += mir_snprintf((buf + off), (_countof(buf) - off), "Dest-Agent: client\r\n"); -#endif } char *pszNick=proto->MyOptions.szEmail; @@ -491,33 +481,9 @@ int ThreadData::sendMessage(int, const char *email, int netId, const char *parMs netId == NETID_SKYPE?netId:proto->MyOptions.netId, proto->GetMyUsername(netId), proto->MyOptions.szMachineGuid, parMsg); -#ifdef OBSOLETE - if (netId == NETID_YAHOO || netId == NETID_MOB || (parFlags & MSG_OFFLINE)) - seq = sendPacket("UUM", "%s %d %c %d\r\n%s%s", email, netId, msgType, - mir_strlen(parMsg) + off, buf, parMsg); - else - seq = sendPacket("MSG", "%c %d\r\n%s%s", msgType, - mir_strlen(parMsg) + off, buf, parMsg); -#endif - return seq; } -#ifdef OBSOLETE -void ThreadData::sendCaps(void) -{ - char mversion[100], capMsg[1000]; - CallService(MS_SYSTEM_GETVERSIONTEXT, sizeof(mversion), (LPARAM)mversion); - - mir_snprintf(capMsg, - "Content-Type: text/x-clientcaps\r\n\r\n" - "Client-Name: Miranda NG %s (MSN v.%s)\r\n", - mversion, __VERSION_STRING_DOTS); - - sendMessage('U', NULL, 1, capMsg, MSG_DISABLE_HDR); -} -#endif - void ThreadData::sendTerminate(void) { if (!termPending) { @@ -575,89 +541,13 @@ static char * HtmlEncodeUTF8T(const wchar_t *src) return HtmlEncode(UTF8(src)); } -#ifdef OBSOLETE -void CMsnProto::MSN_SendStatusMessage(const char* msg) -#else // MSN_SendStatusMessage - notify a server about the status message change void CMsnProto::MSN_SendStatusMessage(const char*) -#endif { if (!msnLoggedIn) return; MSN_SetServerStatus(m_iDesiredStatus); - /* FIXME: Currently not implemented, should be set on status change anyway */ - -#ifdef OBSOLETE - char* msgEnc = HtmlEncode(msg ? msg : ""); - - size_t sz; - char szMsg[2048]; - if (msnCurrentMedia.cbSize == 0) { - sz = mir_snprintf(szMsg, "%s%s" - "", - msgEnc, MyOptions.szMachineGuid); - } - else { - char *szFormatEnc; - if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)) { - LISTENINGTOINFO lti = { 0 }; - lti.cbSize = sizeof(lti); - if (msnCurrentMedia.ptszTitle != NULL) lti.ptszTitle = L"{0}"; - if (msnCurrentMedia.ptszArtist != NULL) lti.ptszArtist = L"{1}"; - if (msnCurrentMedia.ptszAlbum != NULL) lti.ptszAlbum = L"{2}"; - if (msnCurrentMedia.ptszTrack != NULL) lti.ptszTrack = L"{3}"; - if (msnCurrentMedia.ptszYear != NULL) lti.ptszYear = L"{4}"; - if (msnCurrentMedia.ptszGenre != NULL) lti.ptszGenre = L"{5}"; - if (msnCurrentMedia.ptszLength != NULL) lti.ptszLength = L"{6}"; - if (msnCurrentMedia.ptszPlayer != NULL) lti.ptszPlayer = L"{7}"; - if (msnCurrentMedia.ptszType != NULL) lti.ptszType = L"{8}"; - - wchar_t *tmp = (wchar_t *)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)L"%title% - %artist%", (LPARAM)<i); - szFormatEnc = HtmlEncodeUTF8T(tmp); - mir_free(tmp); - } - else szFormatEnc = HtmlEncodeUTF8T(L"{0} - {1}"); - - char *szArtist = HtmlEncodeUTF8T(msnCurrentMedia.ptszArtist), - *szAlbum = HtmlEncodeUTF8T(msnCurrentMedia.ptszAlbum), - *szTitle = HtmlEncodeUTF8T(msnCurrentMedia.ptszTitle), - *szTrack = HtmlEncodeUTF8T(msnCurrentMedia.ptszTrack), - *szYear = HtmlEncodeUTF8T(msnCurrentMedia.ptszYear), - *szGenre = HtmlEncodeUTF8T(msnCurrentMedia.ptszGenre), - *szLength = HtmlEncodeUTF8T(msnCurrentMedia.ptszLength), - *szPlayer = HtmlEncodeUTF8T(msnCurrentMedia.ptszPlayer), - *szType = HtmlEncodeUTF8T(msnCurrentMedia.ptszType); - - sz = mir_snprintf(szMsg, _countof(szMsg), - "" - "%s" - "%s\\0%s\\01\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0\\0" - "%s" - "" - "", - msgEnc, szPlayer, szType, szFormatEnc, szTitle, szArtist, szAlbum, szTrack, szYear, szGenre, - szLength, szPlayer, szType, MyOptions.szMachineGuid); - - mir_free(szArtist); - mir_free(szAlbum); - mir_free(szTitle); - mir_free(szTrack); - mir_free(szYear); - mir_free(szGenre); - mir_free(szLength); - mir_free(szPlayer); - mir_free(szType); - mir_free(szFormatEnc); - } - mir_free(msgEnc); - - if (msnPreviousUUX == NULL || mir_strcmp(msnPreviousUUX, szMsg)) { - replaceStr(msnPreviousUUX, szMsg); - msnNsThread->sendPacket("UUX", "%d\r\n%s", sz, szMsg); - mStatusMsgTS = clock(); - } -#endif } // MSN_SendPacket - sends a packet accordingly to the MSN protocol @@ -746,22 +636,6 @@ void CMsnProto::MSN_SetServerStatus(int newStatus) unsigned myFlagsExEx = capexex_SupportsMissedConversations | capexex_SupportsShortCircuit; char szMsg[2048]; -#ifdef OBSOLETE - if (m_iStatus < ID_STATUS_ONLINE) { - int sz = mir_snprintf(szMsg, - "%u:%u", myFlags, myFlagsEx); - msnNsThread->sendPacket("UUX", "%d\r\n%s", sz, szMsg); - - msnNsThread->sendPacket("BLP", msnOtherContactsBlocked ? "BL" : "AL"); - - DBVARIANT dbv; - if (!getStringUtf("Nick", &dbv)) { - if (dbv.pszVal[0]) - MSN_SetNicknameUtf(dbv.pszVal); - db_free(&dbv); - } - } -#endif char *szPlace; DBVARIANT dbv; @@ -805,35 +679,9 @@ void CMsnProto::MSN_SetServerStatus(int newStatus) MyOptions.szMachineGuid, sz, szMsg); - - // TODO: Send, MSN_SendStatusMessage anpassen. -#ifdef OBSOLETE - int sz = mir_snprintf(szMsg, - "" - "%s" - "%s" - "1" - "%s" - "", - szPlace, newStatus == ID_STATUS_IDLE ? "true" : "false", szStatusName); - msnNsThread->sendPacket("UUX", "%d\r\n%s", sz, szMsg); -#endif mir_free(szPlace); - -#ifdef OBSOLETE - if (newStatus != ID_STATUS_IDLE) { - char** msgptr = GetStatusMsgLoc(newStatus); - if (msgptr != NULL) - MSN_SendStatusMessage(*msgptr); - } - - msnNsThread->sendPacket("CHG", "%s %u:%u %s", szStatusName, myFlags, myFlagsEx, msnObject.pszVal ? msnObject.pszVal : "0"); -#endif db_free(&msnObject); } -#ifdef OBSOLETE - else msnNsThread->sendPacket("CHG", szStatusName); -#endif } // MSN_FetchRecentMessages - fetches missed offline messages @@ -1083,13 +931,8 @@ filetransfer::~filetransfer(void) CloseHandle(hLockHandle); CloseHandle(hResumeEvt); - if (fileId != -1) { + if (fileId != -1) _close(fileId); -#ifdef OBSOLETE - if (tType != SERVER_HTTP && p2p_appID != MSN_APPID_FILE && !(std.flags & PFTS_SENDING)) - proto->p2p_pictureTransferFailed(this); -#endif - } if (!bCompleted && p2p_appID == MSN_APPID_FILE) { std.ptszFiles = NULL; @@ -1181,71 +1024,6 @@ int filetransfer::openNext(void) return fileId; } -#ifdef OBSOLETE -directconnection::directconnection(const char* CallID, const char* Wlid) -{ - memset(this, 0, sizeof(directconnection)); - - wlid = mir_strdup(Wlid); - callId = mir_strdup(CallID); - mNonce = (UUID*)mir_alloc(sizeof(UUID)); - UuidCreate(mNonce); - ts = time(NULL); -} - -directconnection::~directconnection() -{ - mir_free(wlid); - mir_free(callId); - mir_free(mNonce); - mir_free(xNonce); -} - - -char* directconnection::calcHashedNonce(UUID* nonce) -{ - mir_sha1_ctx sha1ctx; - BYTE sha[MIR_SHA1_HASH_SIZE]; - - mir_sha1_init(&sha1ctx); - mir_sha1_append(&sha1ctx, (BYTE*)nonce, sizeof(UUID)); - mir_sha1_finish(&sha1ctx, sha); - - char* p; - UuidToStringA((UUID*)&sha, (BYTE**)&p); - size_t len = mir_strlen(p) + 3; - char* result = (char*)mir_alloc(len); - mir_snprintf(result, len, "{%s}", p); - _strupr(result); - RpcStringFreeA((BYTE**)&p); - - return result; -} - -char* directconnection::mNonceToText(void) -{ - char* p; - UuidToStringA(mNonce, (BYTE**)&p); - size_t len = mir_strlen(p) + 3; - char* result = (char*)mir_alloc(len); - mir_snprintf(result, len, "{%s}", p); - _strupr(result); - RpcStringFreeA((BYTE**)&p); - - return result; -} - - -void directconnection::xNonceToBin(UUID* nonce) -{ - size_t len = mir_strlen(xNonce); - char *p = (char*)alloca(len); - mir_strcpy(p, xNonce + 1); - p[len - 2] = 0; - UuidFromStringA((BYTE*)p, nonce); -} -#endif - ///////////////////////////////////////////////////////////////////////////////////////// // TWinErrorCode class diff --git a/protocols/MSN/src/msn_msgqueue.cpp b/protocols/MSN/src/msn_msgqueue.cpp deleted file mode 100644 index 281a215544..0000000000 --- a/protocols/MSN/src/msn_msgqueue.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* -Plugin of Miranda IM for communicating with users of the MSN Messenger protocol. - -Copyright (c) 2012-2017 Miranda NG Team -Copyright (c) 2006-2012 Boris Krasnovskiy. -Copyright (c) 2003-2005 George Hazan. -Copyright (c) 2002-2003 Richard Hughes (original version). - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdafx.h" -#include "msn_proto.h" - -#ifdef OBSOLETE -//a few little functions to manage queuing send message requests until the -//connection is established - -void CMsnProto::MsgQueue_Init(void) -{ - msgQueueSeq = 1; -} - -void CMsnProto::MsgQueue_Uninit(void) -{ - MsgQueue_Clear(); -} - -int CMsnProto::MsgQueue_Add(const char* wlid, int msgType, const char* msg, int msgSize, filetransfer* ft, int flags, STRLIST *cnt) -{ - mir_cslock lck(csMsgQueue); - - MsgQueueEntry* E = new MsgQueueEntry; - lsMessageQueue.insert(E); - - int seq = msgQueueSeq++; - - E->wlid = mir_strdup(wlid); - E->msgSize = msgSize; - E->msgType = msgType; - if (msgSize <= 0) - E->message = mir_strdup(msg); - else - memcpy(E->message = (char*)mir_alloc(msgSize), msg, msgSize); - E->ft = ft; - E->cont = cnt; - E->seq = seq; - E->flags = flags; - E->allocatedToThread = 0; - E->ts = time(NULL); - return seq; -} - -// shall we create another session? -const char* CMsnProto::MsgQueue_CheckContact(const char* wlid, time_t tsc) -{ - time_t ts = time(NULL); - - mir_cslock lck(csMsgQueue); - - for (int i = 0; i < lsMessageQueue.getCount(); i++) - if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0 && (tsc == 0 || (ts - lsMessageQueue[i].ts) < tsc)) - return wlid; - - return NULL; -} - -//for threads to determine who they should connect to -const char* CMsnProto::MsgQueue_GetNextRecipient(void) -{ - mir_cslock lck(csMsgQueue); - - for (int i = 0; i < lsMessageQueue.getCount(); i++) { - MsgQueueEntry& E = lsMessageQueue[i]; - if (!E.allocatedToThread) { - E.allocatedToThread = 1; - - const char *ret = E.wlid; - while (++i < lsMessageQueue.getCount()) - if (_stricmp(lsMessageQueue[i].wlid, ret) == 0) - lsMessageQueue[i].allocatedToThread = 1; - - return ret; - } - } - - return NULL; -} - -//deletes from list. Must mir_free() return value -bool CMsnProto::MsgQueue_GetNext(const char* wlid, MsgQueueEntry& retVal) -{ - int i; - - mir_cslock lck(csMsgQueue); - for (i = 0; i < lsMessageQueue.getCount(); i++) - if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0) - break; - - bool res = i != lsMessageQueue.getCount(); - if (res) { - retVal = lsMessageQueue[i]; - lsMessageQueue.remove(i); - } - - return res; -} - -int CMsnProto::MsgQueue_NumMsg(const char* wlid) -{ - int res = 0; - mir_cslock lck(csMsgQueue); - - for (int i = 0; i < lsMessageQueue.getCount(); i++) - res += (_stricmp(lsMessageQueue[i].wlid, wlid) == 0); - - return res; -} - -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++) { - const MsgQueueEntry& E = lsMessageQueue[i]; - if (E.msgSize == 0) { - MCONTACT hContact = MSN_HContactFromEmail(E.wlid); - ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, - (HANDLE)E.seq, (LPARAM)Translate("Message delivery failed")); - } - mir_free(E.message); - mir_free(E.wlid); - if (E.cont) delete E.cont; - } - lsMessageQueue.destroy(); - - msgQueueSeq = 1; - } - 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)) { - bool msgfnd = E.msgSize == 0 && E.ts < ts; - int seq = E.seq; - - mir_free(E.message); - mir_free(E.wlid); - if (E.cont) delete E.cont; - lsMessageQueue.remove(i); - - if (msgfnd) { - lck.unlock(); - MCONTACT hContact = MSN_HContactFromEmail(wlid); - ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)seq, - (LPARAM)Translate("Message delivery failed")); - i = 0; - lck.lock(); - } - } - } - } -} - -void __cdecl CMsnProto::MsgQueue_AllClearThread(void* arg) -{ - MsgQueue_Clear((char*)arg); - mir_free(arg); -} -#endif diff --git a/protocols/MSN/src/msn_natdetect.cpp b/protocols/MSN/src/msn_natdetect.cpp deleted file mode 100644 index 35f518b51b..0000000000 --- a/protocols/MSN/src/msn_natdetect.cpp +++ /dev/null @@ -1,471 +0,0 @@ -/* -Plugin of Miranda IM for communicating with users of the MSN Messenger protocol. - -Copyright (c) 2012-2017 Miranda NG Team -Copyright (c) 2007-2012 Boris Krasnovskiy. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdafx.h" -#include "msn_proto.h" -#include -#ifdef OBSOLETE - -#ifndef CLSID_NetFwMgr -#define MDEF_CLSID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ - const CLSID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } - - MDEF_CLSID(CLSID_NetFwMgr, 0x304ce942, 0x6e39, 0x40d8, 0x94, 0x3a, 0xb9, 0x13, 0xc4, 0x0c, 0x9c, 0xd4); - MDEF_CLSID(IID_INetFwMgr, 0xf7898af5, 0xcac4, 0x4632, 0xa2, 0xec, 0xda ,0x06, 0xe5, 0x11, 0x1a, 0xf2); -#endif - - -MyConnectionType MyConnection; - -const char* conStr[] = -{ - "Unknown-Connect", - "Direct-Connect", - "Unknown-NAT", - "IP-Restrict-NAT", - "Port-Restrict-NAT", - "Symmetric-NAT", - "Firewall", - "ISALike" -}; - - -void CMsnProto::DecryptEchoPacket(UDPProbePkt& pkt) -{ - pkt.clientPort ^= 0x3141; - pkt.discardPort ^= 0x3141; - pkt.testPort ^= 0x3141; - pkt.clientIP ^= 0x31413141; - pkt.testIP ^= 0x31413141; - - - IN_ADDR addr; - debugLogA("Echo packet: version: 0x%x service code: 0x%x transaction ID: 0x%x", - pkt.version, pkt.serviceCode, pkt.trId); - addr.S_un.S_addr = pkt.clientIP; - debugLogA("Echo packet: client port: %u client addr: %s", - pkt.clientPort, inet_ntoa(addr)); - addr.S_un.S_addr = pkt.testIP; - debugLogA("Echo packet: discard port: %u test port: %u test addr: %s", - pkt.discardPort, pkt.testPort, inet_ntoa(addr)); -} - - -static void DiscardExtraPackets(SOCKET s) -{ - Sleep(3000); - - static const TIMEVAL tv = { 0, 0 }; - unsigned buf; - - for (;;) { - if (g_bTerminated) break; - - fd_set fd; - FD_ZERO(&fd); - FD_SET(s, &fd); - - if (select(1, &fd, NULL, NULL, &tv) == 1) - recv(s, (char*)&buf, sizeof(buf), 0); - else - break; - } -} - - -void CMsnProto::MSNatDetect(void) -{ - PHOSTENT host = gethostbyname("echo.edge.messenger.live.com"); - if (host == NULL) { - debugLogA("P2PNAT could not find echo server \"echo.edge.messenger.live.com\""); - return; - } - - SOCKADDR_IN addr; - addr.sin_family = AF_INET; - addr.sin_port = _htons(7001); - 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, - addr.sin_addr.S_un.S_un_b.s_b3, addr.sin_addr.S_un.S_un_b.s_b4); - - SOCKET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (connect(s, (SOCKADDR*)&addr, sizeof(addr)) == SOCKET_ERROR) { - debugLogA("P2PNAT could not connect to echo server \"echo.edge.messenger.live.com\""); - closesocket(s); - return; - } - - UDPProbePkt pkt = { 0 }, pkt2; - - // Detect My IP - pkt.version = 2; - pkt.serviceCode = 4; - send(s, (char*)&pkt, sizeof(pkt), 0); - - SOCKADDR_IN myaddr; - int szname = sizeof(myaddr); - getsockname(s, (SOCKADDR*)&myaddr, &szname); - - MyConnection.intIP = myaddr.sin_addr.S_un.S_addr; - debugLogA("P2PNAT Detected IP facing internet %d.%d.%d.%d", - myaddr.sin_addr.S_un.S_un_b.s_b1, myaddr.sin_addr.S_un.S_un_b.s_b2, - myaddr.sin_addr.S_un.S_un_b.s_b3, myaddr.sin_addr.S_un.S_un_b.s_b4); - - SOCKET s1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - - pkt.version = 2; - pkt.serviceCode = 1; - pkt.clientPort = 0x3141; - pkt.clientIP = 0x31413141; - - UDPProbePkt rpkt = { 0 }; - - // NAT detection - unsigned i; - for (i = 0; i < 4; ++i) { - if (g_bTerminated) break; - - // Send echo request to server 1 - debugLogA("P2PNAT Request 1 attempt %d sent", i); - sendto(s1, (char*)&pkt, sizeof(pkt), 0, (SOCKADDR*)&addr, sizeof(addr)); - - fd_set fd; - FD_ZERO(&fd); - FD_SET(s1, &fd); - TIMEVAL tv = { 0, 200000 * (1 << i) }; - - 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); - } - - closesocket(s); - - // Server did not respond - if (i >= 4) { - MyConnection.udpConType = conFirewall; - closesocket(s1); - return; - } - - MyConnection.extIP = rpkt.clientIP; - - // Check if NAT not found - if (MyConnection.extIP == MyConnection.intIP) { - if (msnExternalIP != NULL && inet_addr(msnExternalIP) != MyConnection.extIP) - MyConnection.udpConType = conISALike; - else - MyConnection.udpConType = conDirect; - - closesocket(s1); - return; - } - - // Detect UPnP NAT - 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) { - MyConnection.upnpNAT = htonl(nlb.dwExternalIP) == MyConnection.extIP; - Sleep(100); - Netlib_CloseHandle(sb); - } - - DiscardExtraPackets(s1); - - // Start IP Restricted NAT detection - 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) { - if (g_bTerminated) break; - - debugLogA("P2PNAT Request 2 attempt %d sent", i); - // Remove IP restriction for server 2 - sendto(s1, NULL, 0, 0, (SOCKADDR*)&addr2, sizeof(addr2)); - // Send echo request to server 1 for server 2 - sendto(s1, (char*)&pkt2, sizeof(pkt2), 0, (SOCKADDR*)&addr, sizeof(addr)); - - fd_set fd; - FD_ZERO(&fd); - FD_SET(s1, &fd); - TIMEVAL tv = { 0, 200000 * (1 << i) }; - - 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); - break; - } - else - debugLogA("P2PNAT Request 2 attempt %d timeout", i); - } - - // 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) { - MyConnection.udpConType = conIPRestrictNAT; - closesocket(s1); - return; - } - - DiscardExtraPackets(s1); - - // Symmetric NAT detection - addr2.sin_port = rpkt.testPort; - for (i = 0; i < 4; ++i) { - if (g_bTerminated) break; - - debugLogA("P2PNAT Request 3 attempt %d sent", i); - // Send echo request to server 1 - sendto(s1, (char*)&pkt, sizeof(pkt), 0, (SOCKADDR*)&addr2, sizeof(addr2)); - - fd_set fd; - FD_ZERO(&fd); - FD_SET(s1, &fd); - TIMEVAL tv = { 1 << i, 0 }; - - 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); - break; - } - else - debugLogA("P2PNAT Request 3 attempt %d timeout", i); - } - if (i < 4) { - // If ports different it's symmetric NAT - MyConnection.udpConType = rpkt.clientPort == rpkt2.clientPort ? -conPortRestrictNAT : conSymmetricNAT; - } - closesocket(s1); -} - - -static bool IsIcfEnabled(void) -{ - HRESULT hr; - VARIANT_BOOL fwEnabled = VARIANT_FALSE; - - INetFwProfile* fwProfile = NULL; - INetFwMgr* fwMgr = NULL; - INetFwPolicy* fwPolicy = NULL; - INetFwAuthorizedApplication* fwApp = NULL; - INetFwAuthorizedApplications* fwApps = NULL; - BSTR fwBstrProcessImageFileName = NULL; - wchar_t *wszFileName = NULL; - - hr = CoInitialize(NULL); - if (FAILED(hr)) return false; - - // Create an instance of the firewall settings manager. - hr = CoCreateInstance(CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, - IID_INetFwMgr, (void**)&fwMgr); - if (FAILED(hr)) goto error; - - // Retrieve the local firewall policy. - hr = fwMgr->get_LocalPolicy(&fwPolicy); - if (FAILED(hr)) goto error; - - // Retrieve the firewall profile currently in effect. - hr = fwPolicy->get_CurrentProfile(&fwProfile); - if (FAILED(hr)) goto error; - - // Get the current state of the firewall. - hr = fwProfile->get_FirewallEnabled(&fwEnabled); - if (FAILED(hr)) goto error; - - if (fwEnabled == VARIANT_FALSE) goto error; - - // Retrieve the authorized application collection. - hr = fwProfile->get_AuthorizedApplications(&fwApps); - if (FAILED(hr)) goto error; - - wchar_t szFileName[MAX_PATH]; - GetModuleFileName(NULL, szFileName, _countof(szFileName)); - - wszFileName = mir_wstrdup(szFileName); - - // Allocate a BSTR for the process image file name. - fwBstrProcessImageFileName = SysAllocString(wszFileName); - if (FAILED(hr)) goto error; - - // Attempt to retrieve the authorized application. - hr = fwApps->Item(fwBstrProcessImageFileName, &fwApp); - if (SUCCEEDED(hr)) { - // Find out if the authorized application is enabled. - fwApp->get_Enabled(&fwEnabled); - fwEnabled = ~fwEnabled; - } - -error: - // Free the BSTR. - SysFreeString(fwBstrProcessImageFileName); - mir_free(wszFileName); - - // Release the authorized application instance. - if (fwApp != NULL) fwApp->Release(); - - // Release the authorized application collection. - if (fwApps != NULL) fwApps->Release(); - - // Release the firewall profile. - if (fwProfile != NULL) fwProfile->Release(); - - // Release the local firewall policy. - if (fwPolicy != NULL) fwPolicy->Release(); - - // Release the firewall settings manager. - if (fwMgr != NULL) fwMgr->Release(); - - CoUninitialize(); - - return fwEnabled != VARIANT_FALSE; -} - -void CMsnProto::MSNConnDetectThread(void*) -{ - char parBuf[512] = ""; - - memset(&MyConnection, 0, sizeof(MyConnection)); - - MyConnection.icf = IsIcfEnabled(); - 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 || mir_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)); - 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; - } - - 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; - MyConnection.udpConType = (ConEnum)portsMapped; - MyConnection.upnpNAT = false; - MyConnection.CalculateWeight(); - return; - } - - MSNatDetect(); - - // If user mapped incoming ports consider direct connection - if (portsMapped) { - debugLogA("P2PNAT User manually mapped ports for incoming connection"); - switch (MyConnection.udpConType) { - case conUnknown: - case conFirewall: - case conISALike: - MyConnection.udpConType = conDirect; - break; - - case conUnknownNAT: - case conPortRestrictNAT: - case conIPRestrictNAT: - case conSymmetricNAT: - MyConnection.upnpNAT = true; - break; - } - } - - debugLogA("P2PNAT Connection %s found UPnP: %d ICF: %d", conStr[MyConnection.udpConType], - MyConnection.upnpNAT, MyConnection.icf); - - MyConnection.CalculateWeight(); -} - -void MyConnectionType::SetUdpCon(const char* str) -{ - for (unsigned i = 0; i < sizeof(conStr) / sizeof(char*); ++i) { - if (mir_strcmp(conStr[i], str) == 0) { - udpConType = (ConEnum)i; - break; - } - } -} - -void MyConnectionType::CalculateWeight(void) -{ - if (icf) weight = 0; - else if (udpConType == conDirect) weight = 6; - else if (udpConType >= conIPRestrictNAT && udpConType <= conSymmetricNAT) - weight = upnpNAT ? 5 : 2; - else if (udpConType == conUnknownNAT) - weight = upnpNAT ? 4 : 1; - else if (udpConType == conUnknown) weight = 1; - else if (udpConType == conFirewall) weight = 2; - else if (udpConType == conISALike) weight = 3; -} -#endif diff --git a/protocols/MSN/src/msn_opts.cpp b/protocols/MSN/src/msn_opts.cpp index e672669625..a78ba0f48d 100644 --- a/protocols/MSN/src/msn_opts.cpp +++ b/protocols/MSN/src/msn_opts.cpp @@ -248,30 +248,6 @@ LBL_Continue: proto->setString("Password", password); } -#ifdef OBSOLETE - GetDlgItemText(hwndDlg, IDC_HANDLE2, screenStr, _countof(screenStr)); - if (!proto->getWString("Nick", &dbv)) { - if (mir_wstrcmp(dbv.ptszVal, screenStr)) - proto->MSN_SendNickname(screenStr); - db_free(&dbv); - } - else proto->MSN_SendNickname(screenStr); - - BYTE mblsnd = IsDlgButtonChecked(hwndDlg, IDC_MOBILESEND) == BST_CHECKED; - if (mblsnd != proto->getByte("MobileAllowed", 0)) { - proto->msnNsThread->sendPacket("PRP", "MOB %c", mblsnd ? 'Y' : 'N'); - proto->MSN_SetServerStatus(proto->m_iStatus); - } - - unsigned tValue = IsDlgButtonChecked(hwndDlg, IDC_DISABLE_ANOTHER_CONTACTS); - if (tValue != proto->msnOtherContactsBlocked && proto->msnLoggedIn) { - proto->msnOtherContactsBlocked = tValue; - proto->msnNsThread->sendPacket("BLP", tValue ? "BL" : "AL"); - proto->MSN_ABUpdateAttr(NULL, "MSN.IM.BLP", tValue ? "0" : "1"); - break; - } -#endif - 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)); @@ -404,10 +380,6 @@ static INT_PTR CALLBACK DlgProcMsnConnOpts(HWND hwndDlg, UINT msg, WPARAM wParam } } -#ifdef OBSOLETE - unsigned gethst2 = proto->getByte("AutoGetHost", 1); - -#endif unsigned gethst = SendDlgItemMessage(hwndDlg, IDC_HOSTOPT, CB_GETCURSEL, 0, 0); if (gethst < 2) gethst = !gethst; proto->setByte("AutoGetHost", (BYTE)gethst); @@ -418,11 +390,6 @@ static INT_PTR CALLBACK DlgProcMsnConnOpts(HWND hwndDlg, UINT msg, WPARAM wParam } else proto->delSetting("YourHost"); -#ifdef OBSOLETE - if (gethst != gethst2) - proto->ForkThread(&CMsnProto::MSNConnDetectThread, NULL); -#endif - proto->LoadOptions(); return TRUE; } diff --git a/protocols/MSN/src/msn_p2p.cpp b/protocols/MSN/src/msn_p2p.cpp deleted file mode 100644 index 2c81a6ecc0..0000000000 --- a/protocols/MSN/src/msn_p2p.cpp +++ /dev/null @@ -1,2328 +0,0 @@ -/* -Plugin of Miranda IM for communicating with users of the MSN Messenger protocol. - -Copyright (c) 2012-2017 Miranda NG Team -Copyright (c) 2006-2012 Boris Krasnovskiy. -Copyright (c) 2003-2005 George Hazan. -Copyright (c) 2002-2003 Richard Hughes (original version). - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdafx.h" -#include "msn_proto.h" -#include "m_smileyadd.h" - -static const char sttP2Pheader[] = - "Content-Type: application/x-msnmsgrp2p\r\n" - "P2P-Dest: %s\r\n\r\n"; - -static const char sttP2PheaderV2[] = - "Content-Type: application/x-msnmsgrp2p\r\n" - "P2P-Dest: %s\r\n" - "P2P-Src: %s;%s\r\n\r\n"; - -const char sttVoidUid[] = "{00000000-0000-0000-0000-000000000000}"; -#ifdef OBSOLETE -static const char szUbnCall[] = "{F13B5C79-0126-458F-A29D-747C79C56530}"; - -static const char p2pV2Caps[] = { 0x01, 0x0C, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x0F, 0x01, 0x00, 0x00 }; - -void P2P_Header::logHeader(CMsnProto *ppro) -{ - ppro->debugLogA("--- Printing message header"); - ppro->debugLogA(" SessionID = %08X", mSessionID); - ppro->debugLogA(" MessageID = %08X", mID); -#ifndef __GNUC__ - ppro->debugLogA(" Offset of data = %I64u", mOffset); - ppro->debugLogA(" Total amount of data = %I64u", mTotalSize); -#else - ppro->debugLogA(" Offset of data = %llu", mOffset); - ppro->debugLogA(" Total amount of data = %llu", hdrdata->mTotalSize); -#endif - ppro->debugLogA(" Data in packet = %lu bytes", mPacketLen); - ppro->debugLogA(" Flags = %08X", mFlags); - ppro->debugLogA(" Acknowledged session ID: %08X", mAckSessionID); - ppro->debugLogA(" Acknowledged message ID: %08X", mAckUniqueID); -#ifndef __GNUC__ - ppro->debugLogA(" Acknowledged data size: %I64u", mAckDataSize); -#else - ppro->debugLogA(" Acknowledged data size: %llu", mAckDataSize); -#endif - ppro->debugLogA("------------------------"); -} - -void P2PV2_Header::logHeader(CMsnProto *ppro) -{ - ppro->debugLogA("--- Printing message header"); - ppro->debugLogA(" SessionID = %08X", mSessionID); - ppro->debugLogA(" MessageID = %08X", mID); -#ifndef __GNUC__ - ppro->debugLogA(" Remaining amount of data = %I64u", mRemSize); -#else - ppro->debugLogA(" Remaining amount of data = %llu", mTotalSize); -#endif - ppro->debugLogA(" Data in packet = %lu bytes", mPacketLen); - ppro->debugLogA(" Packet Number = %lu", mPacketNum); - ppro->debugLogA(" Operation Code = %08X", mOpCode); - ppro->debugLogA(" TF Code = %08X", mTFCode); - ppro->debugLogA(" Acknowledged message ID: %08X", mAckUniqueID); - ppro->debugLogA("------------------------"); -} - -bool CMsnProto::p2p_createListener(filetransfer* ft, directconnection *dc, MimeHeaders& chdrs) -{ - if (MyConnection.extIP == 0) return false; - - 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) { - debugLogA("Unable to bind the port for incoming transfers"); - return false; - } - - ThreadData* newThread = new ThreadData; - newThread->mType = SERVER_P2P_DIRECT; - newThread->mCaller = 3; - newThread->mIncomingBoundPort = sb; - newThread->mIncomingPort = nlb.wPort; - strncpy(newThread->mCookie, dc->callId, sizeof(newThread->mCookie)); - newThread->mInitialContactWLID = mir_strdup(ft->p2p_dest); - - newThread->startThread(&CMsnProto::p2p_filePassiveThread, this); - - char szIpv4[256] = ""; - char szIpv6[256] = ""; - const char *szExtIp = MyConnection.GetMyExtIPStr(); - - bool ipInt = false; - 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], ':')) { - if (i6++ != 0) mir_strcat(szIpv6, " "); - mir_strcat(szIpv6, ihaddr->szIp[i]); - } - else { - if (i4++ != 0) mir_strcat(szIpv4, " "); - ipInt |= (mir_strcmp(ihaddr->szIp[i], szExtIp) == 0); - mir_strcat(szIpv4, ihaddr->szIp[i]); - } - } - mir_free(ihaddr); - - chdrs.addString("Bridge", "TCPv1"); - chdrs.addBool("Listening", true); - - if (dc->useHashedNonce) - chdrs.addString("Hashed-Nonce", dc->mNonceToHash(), 2); - else - chdrs.addString("Nonce", dc->mNonceToText(), 2); - - bool bUbnCall = !ft->p2p_sessionid; - - 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]) { - chdrs.addString("IPv6-Addrs", mir_strdup(szIpv6), 2); - chdrs.addLong("IPv6-Port", nlb.wPort); - } - chdrs.addULong("SessionID", ft->p2p_sessionid); - chdrs.addString("SChannelState", "0"); - chdrs.addString("Capabilities-Flags", "1"); - - return true; -} - -bool p2p_IsDlFileOk(filetransfer* ft) -{ - mir_sha1_ctx sha1ctx; - BYTE sha[MIR_SHA1_HASH_SIZE]; - mir_sha1_init(&sha1ctx); - - bool res = false; - - int fileId = _wopen(ft->std.tszCurrentFile, O_RDONLY | _O_BINARY, _S_IREAD); - if (fileId != -1) { - BYTE buf[4096]; - int bytes; - - while ((bytes = _read(fileId, buf, sizeof(buf))) > 0) - mir_sha1_append(&sha1ctx, buf, bytes); - - _close(fileId); - mir_sha1_finish(&sha1ctx, sha); - - char *szSha = arrayToHex(sha, MIR_SHA1_HASH_SIZE); - char *szAvatarHash = MSN_GetAvatarHash(ft->p2p_object); - - res = szAvatarHash != NULL && _stricmp(szAvatarHash, szSha) == 0; - - mir_free(szSha); - mir_free(szAvatarHash); - } - return res; -} - - - -///////////////////////////////////////////////////////////////////////////////////////// -// sttSavePicture2disk - final handler for avatars downloading - -void CMsnProto::p2p_pictureTransferFailed(filetransfer* ft) -{ - switch (ft->p2p_type) { - case MSN_APPID_AVATAR: - case MSN_APPID_AVATAR2: - { - PROTO_AVATAR_INFORMATION ai = { 0 }; - ai.hContact = ft->std.hContact; - delSetting(ft->std.hContact, "AvatarHash"); - ProtoBroadcastAck(ai.hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, &ai, 0); - } - break; - } - _wremove(ft->std.tszCurrentFile); -} - -void CMsnProto::p2p_savePicture2disk(filetransfer* ft) -{ - ft->close(); - - if (p2p_IsDlFileOk(ft)) { - int fileId = _wopen(ft->std.tszCurrentFile, O_RDONLY | _O_BINARY, _S_IREAD); - if (fileId == -1) { - p2p_pictureTransferFailed(ft); - return; - } - - const wchar_t* ext; - int format; - BYTE buf[6]; - - int bytes = _read(fileId, buf, sizeof(buf)); - _close(fileId); - if (bytes > 4) - format = ProtoGetBufferFormat(buf, &ext); - else { - p2p_pictureTransferFailed(ft); - return; - } - - switch (ft->p2p_type) { - case MSN_APPID_AVATAR: - case MSN_APPID_AVATAR2: - { - PROTO_AVATAR_INFORMATION ai = { 0 }; - ai.format = format; - ai.hContact = ft->std.hContact; - MSN_GetAvatarFileName(ai.hContact, ai.filename, _countof(ai.filename), ext); - - _wrename(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); - - debugLogA("Avatar for contact %08x saved to file '%s'", ai.hContact, T2Utf(ai.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; - - wchar_t* pathcpy = mir_wstrdup(ft->std.tszCurrentFile); - mir_wstrcpy(wcsrchr(pathcpy, '.') + 1, ext); - _wrename(ft->std.tszCurrentFile, pathcpy); - - cont.path = pathcpy; - - CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); - mir_free(pathcpy); - } - break; - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_sendAck - sends MSN P2P acknowledgement to the received message - -static const char sttVoidSession[] = "ACHTUNG!!! an attempt made to send a message via the empty session"; - -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) { - bool isOffline; - info = MSN_StartSB(wlid, isOffline); - } - p2p_sendMsg(info, wlid, appId, hdrdata, msgbody, msgsz); -} - -void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, P2PB_Header& hdrdata, char* msgbody, size_t msgsz) -{ - unsigned msgType; - - if (info == NULL) msgType = 0; - else if (info->mType == SERVER_P2P_DIRECT) msgType = 1; - else msgType = 2; - - unsigned fportion = msgType == 1 ? 1352 : 1202; - if (hdrdata.isV2Hdr()) fportion += 4; - - char* buf = (char*)alloca(sizeof(sttP2PheaderV2) + MSN_MAX_EMAIL_LEN + - 120 + fportion); - - size_t offset = 0; - do { - size_t portion = msgsz - offset; - if (portion > fportion) portion = fportion; - - char* p = buf; - - // add message header - p += msgType == 1 ? sizeof(unsigned) : - sprintf(p, hdrdata.isV2Hdr() ? sttP2PheaderV2 : sttP2Pheader, wlid, MyOptions.szEmail, MyOptions.szMachineGuidP2P); //!!!!!!!!!!! - - if (hdrdata.isV2Hdr()) { - P2PV2_Header *ph = (P2PV2_Header*)&hdrdata; - 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 { - ph->mOpCode |= ph->mAckUniqueID && msgType != 1 ? 1 : 3; - ph->mCap = p2pV2Caps; - if (info) info->mBridgeInit = true; - } - } - } - else { - ph->mOpCode = 0; - ph->mCap = NULL; - } - } - - 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; - - if (offset == 0) - ph->mPacketNum = p2p_getPktNum(wlid); - } - else { - P2P_Header *ph = (P2P_Header*)&hdrdata; - ph->mPacketLen = (unsigned)portion; - ph->mOffset = offset; - ph->mTotalSize = msgsz; - } - } - - // add message body - p = hdrdata.createMsg(p, wlid, this); - hdrdata.logHeader(this); - - if (msgsz) - memcpy(p, msgbody + offset, portion); p += portion; - - // add message footer - if (msgType != 1) { - *(unsigned*)p = _htonl(appId); - p += 4; - } - - char* szEmail; - switch (msgType) { - case 0: - parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - MsgQueue_Add(szEmail, 'D', buf, p - buf); - break; - - case 1: - *(unsigned*)buf = (unsigned)(p - buf - sizeof(unsigned)); - info->send(buf, p - buf); - break; - - case 2: - info->sendRawMessage('D', buf, p - buf); - break; - } - offset += portion; - } while (offset < msgsz); -} - - -void CMsnProto::p2p_sendAck(const char *wlid, P2PB_Header* hdr) -{ - if (hdr == NULL) return; - - if (!hdr->isV2Hdr()) { - P2P_Header *hdrdata = (P2P_Header*)hdr; - P2P_Header tHdr; - - tHdr.mSessionID = hdrdata->mSessionID; - tHdr.mAckDataSize = hdrdata->mTotalSize; - tHdr.mFlags = 2; - tHdr.mAckSessionID = hdrdata->mID; - tHdr.mAckUniqueID = hdrdata->mAckSessionID; - - p2p_sendMsg(wlid, 0, tHdr, NULL, 0); - } - else { - P2PV2_Header *hdrdata = (P2PV2_Header*)hdr; - P2PV2_Header tHdr; - - tHdr.mAckUniqueID = hdrdata->mID; - - p2p_sendMsg(wlid, 0, tHdr, NULL, 0); - } -} - - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_sendEndSession - sends MSN P2P file transfer end packet - -void CMsnProto::p2p_sendAbortSession(filetransfer* ft) -{ - if (ft == NULL) { - debugLogA(sttVoidSession); - return; - } - - if (ft->p2p_isV2) return; - - P2P_Header tHdr; - - tHdr.mSessionID = ft->p2p_sessionid; - tHdr.mAckSessionID = ft->p2p_sendmsgid; - tHdr.mID = p2p_getMsgId(ft->p2p_dest, 1); - - if (ft->std.flags & PFTS_SENDING) { - tHdr.mFlags = 0x40; - tHdr.mAckSessionID = tHdr.mID - 2; - } - else { - tHdr.mAckUniqueID = 0x8200000f; - tHdr.mFlags = 0x80; - tHdr.mAckDataSize = ft->std.currentFileSize; - } - - p2p_sendMsg(ft->p2p_dest, 0, tHdr, NULL, 0); - ft->ts = time(NULL); -} - -void CMsnProto::p2p_sendRedirect(filetransfer* ft) -{ - if (ft == NULL) { - debugLogA(sttVoidSession); - return; - } - - if (ft->p2p_isV2) return; - - P2P_Header tHdr; - - tHdr.mSessionID = ft->p2p_sessionid; - tHdr.mFlags = 0x01; - tHdr.mAckSessionID = ft->p2p_sendmsgid; - tHdr.mAckDataSize = ft->std.currentFileProgress; - - p2p_sendMsg(ft->p2p_dest, 0, tHdr, NULL, 0); - - ft->tTypeReq = MSN_GetP2PThreadByContact(ft->p2p_dest) ? SERVER_P2P_DIRECT : SERVER_SWITCHBOARD; - ft->ts = time(NULL); - ft->p2p_waitack = true; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_sendSlp - send MSN P2P SLP packet - -void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders, - MimeHeaders &pContent, const char *wlid) -{ - if (ft == NULL) { - debugLogA(sttVoidSession); - return; - } - - if (wlid == NULL) wlid = ft->p2p_dest; - - size_t cbContLen = pContent.getLength(); - pHeaders.addULong("Content-Length", (unsigned)cbContLen + 1); - - 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) { - mir_free(ft->p2p_branch); - ft->p2p_branch = getNewUuid(); - } - - 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 { - p += sprintf(p, - "\r\nTo: \r\n" - "From: \r\n" - "Via: MSNSLP/1.0/TLP ;branch=%s\r\n", - wlid, MyOptions.szEmail, ft->p2p_branch); //!!!!!!!!!!!!!!!!!! - } - - p = pHeaders.writeToBuffer(p); - p = pContent.writeToBuffer(p); - - unsigned short status = getWord(ft->std.hContact, "Status", ID_STATUS_OFFLINE); - 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) { - P2P_Header tHdr; - tHdr.mAckSessionID = ft->p2p_acksessid; - - p2p_sendMsg(wlid, 0, tHdr, buf, p - buf + 1); - ft->p2p_waitack = true; - - switch (iKind) { - case -1: case 500: case 603: - ft->p2p_byemsgid = tHdr.mID; - break; - } - - } - else { - P2PV2_Header tHdr; - tHdr.mTFCode = 0x01; - - p2p_sendMsg(wlid, 0, tHdr, buf, p - buf + 1); - } - } - else - msnNsThread->sendPacket("UUN", "%s 3 %d\r\n%s", wlid, p - buf, buf); - - ft->ts = time(NULL); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_sendBye - closes P2P session - -void CMsnProto::p2p_sendBye(filetransfer* ft) -{ - if (ft == NULL) { - debugLogA(sttVoidSession); - return; - } - - MimeHeaders tHeaders(8); - tHeaders.addString("CSeq", "0 "); - tHeaders.addString("Call-ID", ft->p2p_callID); - tHeaders.addLong("Max-Forwards", 0); - tHeaders.addString("Content-Type", "application/x-msnmsgr-sessionclosebody"); - - MimeHeaders chdrs(2); - chdrs.addULong("SessionID", ft->p2p_sessionid); - chdrs.addString("SChannelState", "0"); - - p2p_sendSlp(-1, ft, tHeaders, chdrs); -} - -void CMsnProto::p2p_sendCancel(filetransfer* ft) -{ - p2p_sendBye(ft); - p2p_sendAbortSession(ft); -} - -void CMsnProto::p2p_sendNoCall(filetransfer* ft) -{ - if (ft == NULL) { - debugLogA(sttVoidSession); - return; - } - - MimeHeaders tHeaders(8); - tHeaders.addString("CSeq", "0 "); - tHeaders.addString("Call-ID", ft->p2p_callID); - tHeaders.addLong("Max-Forwards", 0); - tHeaders.addString("Content-Type", "application/x-msnmsgr-session-failure-respbody"); - - MimeHeaders chdrs(2); - chdrs.addULong("SessionID", ft->p2p_sessionid); - chdrs.addString("SChannelState", "0"); - - p2p_sendSlp(481, ft, tHeaders, chdrs); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_sendStatus - send MSN P2P status and its description - -void CMsnProto::p2p_sendStatus(filetransfer* ft, long lStatus) -{ - if (ft == NULL) { - debugLogA(sttVoidSession); - return; - } - - MimeHeaders tHeaders(8); - tHeaders.addString("CSeq", "1 "); - tHeaders.addString("Call-ID", ft->p2p_callID); - tHeaders.addLong("Max-Forwards", 0); - - MimeHeaders chdrs(2); - chdrs.addULong("SessionID", ft->p2p_sessionid); - - if (lStatus != 1603) { - tHeaders.addString("Content-Type", "application/x-msnmsgr-sessionreqbody"); - - chdrs.addString("SChannelState", "0"); - } - else - tHeaders.addString("Content-Type", "application/x-msnmsgr-transrespbody"); - - p2p_sendSlp(lStatus, ft, tHeaders, chdrs); -} - -void CMsnProto::p2p_sendAvatarInit(filetransfer* ft) -{ - unsigned body = 0; - - 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 { - P2P_Header tHdr; - tHdr.mSessionID = ft->p2p_sessionid; - tHdr.mAckSessionID = ft->p2p_acksessid; - p2p_sendMsg(ft->p2p_dest, ft->p2p_appID, tHdr, (char*)&body, sizeof(body)); - - ft->ts = time(NULL); - ft->p2p_waitack = true; - } -} - - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_connectTo - connects to a remote P2P server - -static const char p2p_greeting[8] = { 4, 0, 0, 0, 'f', 'o', 'o', 0 }; - -static void sttSendPacket(ThreadData* T, void* hdr, unsigned len) -{ - T->send((char*)&len, sizeof(unsigned)); - T->send((char*)hdr, len); -} - -bool CMsnProto::p2p_connectTo(ThreadData* info, directconnection *dc) -{ - 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) { - *tPortDelim = '\0'; - tConn.wPort = (WORD)atol(tPortDelim + 1); - } - - debugLogA("Connecting to %s:%d", tConn.szHost, tConn.wPort); - - info->s = (HANDLE)Netlib_OpenConnection(m_hNetlibUser, (LPARAM)&tConn); - if (info->s == NULL) { - TWinErrorCode err; - debugLogA("Connection Failed (%d): %s", err.mErrorCode, err.getText()); - return false; - } - info->send(p2p_greeting, sizeof(p2p_greeting)); - - bool isV2 = strchr(info->mInitialContactWLID, ';') != NULL; - - P2P_Header reply; - if (!isV2) { - reply.mFlags = 0x100; - - if (dc->useHashedNonce) - memcpy(&reply.mAckSessionID, dc->mNonce, sizeof(UUID)); - else - dc->xNonceToBin((UUID*)&reply.mAckSessionID); - - char buf[48]; - reply.createMsg(buf, info->mInitialContactWLID, this); - sttSendPacket(info, buf, sizeof(buf)); - } - else - sttSendPacket(info, dc->mNonce, sizeof(UUID)); - - long cbPacketLen; - HReadBuffer buf(info, 0); - BYTE* p; - if ((p = buf.surelyRead(4)) == NULL) { - debugLogA("Error reading data, closing filetransfer"); - return false; - } - - cbPacketLen = *(long*)p; - if ((p = buf.surelyRead(cbPacketLen)) == NULL) - return false; - - bool cookieMatch; - - if (!isV2) { - P2P_Header cookie((char*)p); - - if (dc->useHashedNonce) { - char* hnonce = dc->calcHashedNonce((UUID*)&cookie.mAckSessionID); - cookieMatch = mir_strcmp(hnonce, dc->xNonce) == 0; - mir_free(hnonce); - } - else - cookieMatch = memcmp(&cookie.mAckSessionID, &reply.mAckSessionID, sizeof(UUID)) == 0; - } - else { - char* hnonce = dc->calcHashedNonce((UUID*)p); - cookieMatch = mir_strcmp(hnonce, dc->xNonce) == 0; - mir_free(hnonce); - } - - if (!cookieMatch) { - debugLogA("Invalid cookie received, exiting"); - return false; - } - - return true; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_listen - acts like a local P2P server - -bool CMsnProto::p2p_listen(ThreadData* info, directconnection *dc) -{ - switch (WaitForSingleObject(info->hWaitEvent, 10000)) { - case WAIT_TIMEOUT: - case WAIT_FAILED: - debugLogA("Incoming connection timed out, closing file transfer"); - MSN_StartP2PTransferByContact(info->mInitialContactWLID); -LBL_Error: - debugLogA("File listen failed"); - return false; - } - - HReadBuffer buf(info, 0); - BYTE* p; - - if ((p = buf.surelyRead(8)) == NULL) - goto LBL_Error; - - if (memcmp(p, p2p_greeting, 8) != 0) { - debugLogA("Invalid input data, exiting"); - return false; - } - - if ((p = buf.surelyRead(4)) == NULL) { - debugLogA("Error reading data, closing filetransfer"); - return false; - } - - long cbPacketLen = *(long*)p; - if ((p = buf.surelyRead(cbPacketLen)) == NULL) - goto LBL_Error; - - bool cookieMatch; - bool isV2 = strchr(info->mInitialContactWLID, ';') != NULL; - - if (!isV2) { - P2P_Header cookie((char*)p); - - if (dc->useHashedNonce) { - char* hnonce = dc->calcHashedNonce((UUID*)&cookie.mAckSessionID); - cookieMatch = mir_strcmp(hnonce, dc->xNonce) == 0; - mir_free(hnonce); - memcpy(&cookie.mAckSessionID, dc->mNonce, sizeof(UUID)); - } - else - cookieMatch = memcmp(&cookie.mAckSessionID, dc->mNonce, sizeof(UUID)) == 0; - - if (!cookieMatch) { - debugLogA("Invalid cookie received, exiting"); - return false; - } - - char buf[48]; - cookie.createMsg(buf, info->mInitialContactWLID, this); - sttSendPacket(info, buf, sizeof(buf)); - } - else { - char* hnonce = dc->calcHashedNonce((UUID*)p); - cookieMatch = mir_strcmp(hnonce, dc->xNonce) == 0; - mir_free(hnonce); - - if (!cookieMatch) { - debugLogA("Invalid cookie received, exiting"); - goto LBL_Error; - } - - sttSendPacket(info, dc->mNonce, sizeof(UUID)); - } - - return true; -} - -LONG CMsnProto::p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2) -{ - LONG trid; - char databuf[1500], *p = databuf; - - // Compute the amount of data to send - unsigned fportion = T->mType == SERVER_P2P_DIRECT ? 1352 : 1202; - if (isV2) fportion += 4; - - const unsigned __int64 dt = ft->std.currentFileSize - ft->std.currentFileProgress; - const unsigned portion = dt > fportion ? fportion : dt; - - // Fill data size for direct transfer - - if (T->mType != SERVER_P2P_DIRECT) - p += sprintf(p, isV2 ? sttP2PheaderV2 : sttP2Pheader, ft->p2p_dest, MyOptions.szEmail, MyOptions.szMachineGuidP2P); //!!!!!!!!!!!!!!!!!! - else - p += sizeof(unsigned); - - if (!isV2) { - // Fill P2P header - P2P_Header H; - - H.mSessionID = ft->p2p_sessionid; - H.mID = ft->p2p_sendmsgid; - H.mFlags = ft->p2p_appID == MSN_APPID_FILE ? 0x01000030 : 0x20; - H.mTotalSize = ft->std.currentFileSize; - H.mOffset = ft->std.currentFileProgress; - H.mPacketLen = portion; - H.mAckSessionID = ft->p2p_acksessid; - - p = H.createMsg(p, ft->p2p_dest, this); - } - else { - P2PV2_Header H; - - H.mSessionID = ft->p2p_sessionid; - H.mTFCode = (ft->p2p_appID == MSN_APPID_FILE ? 6 : 4) | (ft->std.currentFileProgress ? 0 : 1); - H.mRemSize = ft->std.currentFileSize - ft->std.currentFileProgress - portion; - H.mPacketLen = portion; - H.mPacketNum = ft->p2p_sendmsgid; - - p = H.createMsg(p, ft->p2p_dest, this); - H.logHeader(this); - } - - if (T->mType == SERVER_P2P_DIRECT) - *(unsigned*)databuf = portion + (p - databuf) - (unsigned)sizeof(unsigned); - - // Fill data (payload) for transfer - if (ft->fileId == -1) return 0; - _read(ft->fileId, p, portion); - p += portion; - - if (T->mType == SERVER_P2P_DIRECT) - trid = T->send(databuf, p - databuf); - else { - // Define packet footer for server transfer - *(unsigned*)p = _htonl(ft->p2p_appID); - p += sizeof(unsigned); - - trid = T->sendRawMessage('D', (char *)databuf, p - databuf); - } - - if (trid != 0) { - ft->std.totalProgress += portion; - ft->std.currentFileProgress += portion; - 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; - } - } - else - debugLogA(" Error sending"); - ft->ts = time(NULL); - ft->p2p_waitack = true; - - return trid; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_sendFeedThread - sends a file via server - -void __cdecl CMsnProto::p2p_sendFeedThread(void* arg) -{ - ThreadData* info = (ThreadData*)arg; - - bool isV2 = strchr(info->mInitialContactWLID, ';') != NULL; - - info->contactJoined(info->mInitialContactWLID); - mir_free(info->mInitialContactWLID); info->mInitialContactWLID = NULL; - - debugLogA("File send thread started"); - - switch (WaitForSingleObject(info->hWaitEvent, 6000)) { - case WAIT_FAILED: - debugLogA("File send wait failed"); - return; - } - - HANDLE hLockHandle = NULL; - ThreadData* T = NULL; - TInfoType lastType = SERVER_NOTIFICATION; - - 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) { - hLockHandle = ft->hLockHandle; - - if (isV2) - ft->p2p_sendmsgid = p2p_getPktNum(ft->p2p_dest); - else { - if (ft->p2p_sendmsgid == 0) - ft->p2p_sendmsgid = p2p_getMsgId(ft->p2p_dest, 1); - } - - T = MSN_GetP2PThreadByContact(ft->p2p_dest); - if (T != NULL) - ft->tType = lastType = T->mType; - - ReleaseMutex(hLockHandle); - } - else - return; - - bool fault = false; - while (WaitForSingleObject(hLockHandle, 2000) == WAIT_OBJECT_0 && - 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) { - debugLogA("File send failed"); - break; - } - else - SleepEx(3000, TRUE); // Allow 3 sec for redirect request - } - fault = cfault; - - ReleaseMutex(hLockHandle); - - if (T != NULL && T->mType != SERVER_P2P_DIRECT) - WaitForSingleObject(T->hWaitEvent, 5000); - } - ReleaseMutex(hLockHandle); - - if (ft->p2p_appID == MSN_APPID_FILE) - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); - - if (isV2) { - if (!ft->bCanceled) { - ft->bCompleted = true; - p2p_sendBye(ft); - } - p2p_sessionComplete(ft); - } - - debugLogA("File send thread completed"); -} - - -void CMsnProto::p2p_sendFeedStart(filetransfer* ft) -{ - if (ft->std.flags & PFTS_SENDING) { - ThreadData* newThread = new ThreadData; - newThread->mType = SERVER_FILETRANS; - mir_strcpy(newThread->mCookie, ft->p2p_callID); - newThread->mInitialContactWLID = mir_strdup(ft->p2p_dest); - newThread->startThread(&CMsnProto::p2p_sendFeedThread, this); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_sendFileDirectly - sends a file via MSN P2P protocol - -void CMsnProto::p2p_sendRecvFileDirectly(ThreadData* info) -{ - long cbPacketLen = 0; - long state = 0; - - HReadBuffer buf(info, 0); - char *wlid = info->mInitialContactWLID; - - info->contactJoined(wlid); - info->mInitialContactWLID = NULL; - - MSN_StartP2PTransferByContact(wlid); - p2p_redirectSessions(wlid); - p2p_startSessions(wlid); - - bool isV2 = strchr(wlid, ';') != NULL; - - for (;;) { - long len = state ? cbPacketLen : 4; - - BYTE* p = buf.surelyRead(len); - - if (p == NULL) - break; - - if (state == 0) - cbPacketLen = *(long*)p; - else if (!isV2) - p2p_processMsg(info, (char*)p, wlid); - else - p2p_processMsgV2(info, (char*)p, wlid); - - state = (state + 1) % 2; - } - - info->contactLeft(wlid); - p2p_redirectSessions(wlid); - mir_free(wlid); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// bunch of thread functions to cover all variants of P2P file transfers - -void __cdecl CMsnProto::p2p_fileActiveThread(void* arg) -{ - ThreadData* info = (ThreadData*)arg; - - debugLogA("p2p_fileActiveThread() started: connecting to '%s'", info->mServer); - - directconnection *dc = p2p_getDCByCallID(info->mCookie, info->mInitialContactWLID); - if (dc) { - if (p2p_connectTo(info, dc)) - p2p_sendRecvFileDirectly(info); - else { - mir_free(info->mInitialContactWLID); - info->mInitialContactWLID = NULL; - } - - if (!MSN_GetThreadByContact(dc->wlid, SERVER_P2P_DIRECT) && !MSN_GetUnconnectedThread(dc->wlid, SERVER_P2P_DIRECT)) - p2p_unregisterDC(dc); - } - - debugLogA("p2p_fileActiveThread() completed: connecting to '%s'", info->mServer); -} - -void __cdecl CMsnProto::p2p_filePassiveThread(void* arg) -{ - ThreadData* info = (ThreadData*)arg; - - debugLogA("p2p_filePassiveThread() started: listening"); - - directconnection *dc = p2p_getDCByCallID(info->mCookie, info->mInitialContactWLID); - if (dc) { - if (p2p_listen(info, dc)) - p2p_sendRecvFileDirectly(info); - else { - mir_free(info->mInitialContactWLID); info->mInitialContactWLID = NULL; - } - - if (!MSN_GetThreadByContact(dc->wlid, SERVER_P2P_DIRECT) && !MSN_GetUnconnectedThread(dc->wlid, SERVER_P2P_DIRECT)) - p2p_unregisterDC(dc); - } - - debugLogA("p2p_filePassiveThread() completed"); -} - - -void CMsnProto::p2p_InitFileTransfer( - ThreadData* info, - MimeHeaders& tFileInfo, - MimeHeaders& tFileInfo2, - const char* wlid) -{ - if (info->mJoinedContactsWLID.getCount() == 0 && info->mJoinedIdentContactsWLID.getCount() == 0) - return; - - const char *szCallID = tFileInfo["Call-ID"], - *szBranch = tFileInfo["Via"]; - - if (szBranch != NULL) { - szBranch = strstr(szBranch, "branch="); - if (szBranch != NULL) - szBranch += 7; - } - if (szCallID == NULL || szBranch == NULL) { - debugLogA("Ignoring invalid invitation: CallID='%s', szBranch='%s'", szCallID, szBranch); - return; - } - - const char *szSessionID = tFileInfo2["SessionID"], - *szEufGuid = tFileInfo2["EUF-GUID"], - *szContext = tFileInfo2["Context"], - *szAppId = tFileInfo2["AppID"]; - - if (szSessionID == NULL || szAppId == NULL || szEufGuid == NULL) { - debugLogA("Ignoring invalid invitation: SessionID='%s', AppID=%s, Branch='%s',Context='%s'", - szSessionID, szAppId, szEufGuid, szContext); - return; - } - - unsigned dwAppID = strtoul(szAppId, NULL, 10); - unsigned dwSessionId = strtoul(szSessionID, NULL, 10); - - if (p2p_getSessionByID(dwSessionId)) - return; - - szContext = (char*)mir_base64_decode(szContext, 0); - - filetransfer* ft = new filetransfer(this); - ft->p2p_acksessid = MSN_GenRandom(); - ft->p2p_sessionid = dwSessionId; - ft->p2p_appID = dwAppID == MSN_APPID_AVATAR ? MSN_APPID_AVATAR2 : dwAppID; - ft->p2p_type = dwAppID; - ft->p2p_ackID = dwAppID == MSN_APPID_FILE ? 2000 : 1000; - replaceStr(ft->p2p_callID, szCallID); - replaceStr(ft->p2p_branch, szBranch); - ft->p2p_dest = mir_strdup(wlid); - ft->p2p_isV2 = strchr(wlid, ';') != NULL; - ft->std.hContact = MSN_HContactFromEmail(wlid); - - p2p_registerSession(ft); - - 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) { - UrlDecode(dbv.pszVal); - - ezxml_t xmlcon = ezxml_parse_str((char*)szContext, mir_strlen(szContext)); - ezxml_t xmldb = ezxml_parse_str(dbv.pszVal, mir_strlen(dbv.pszVal)); - - const char *szCtBuf = ezxml_attr(xmlcon, "SHA1C"); - if (szCtBuf) { - const char *szPtBuf = ezxml_attr(xmldb, "SHA1C"); - pictmatch = szPtBuf && mir_strcmp(szCtBuf, szPtBuf) == 0; - } - else { - const char *szCtBuf = ezxml_attr(xmlcon, "SHA1D"); - const char *szPtBuf = ezxml_attr(xmldb, "SHA1D"); - pictmatch = szCtBuf && szPtBuf && mir_strcmp(szCtBuf, szPtBuf) == 0; - } - - ezxml_free(xmlcon); - ezxml_free(xmldb); - db_free(&dbv); - } - if (pictmatch) { - wchar_t szFileName[MAX_PATH]; - MSN_GetAvatarFileName(NULL, szFileName, _countof(szFileName), NULL); - ft->fileId = _wopen(szFileName, O_RDONLY | _O_BINARY, _S_IREAD); - 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 { - mir_free(ft->std.tszCurrentFile); - ft->std.tszCurrentFile = mir_wstrdup(szFileName); - // 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; - - //---- send 200 OK Message - p2p_sendStatus(ft, 200); - p2p_sendFeedStart(ft); - - if (ft->p2p_isV2) { - p2p_sendAvatarInit(ft); - MSN_StartP2PTransferByContact(ft->p2p_dest); - } - } - } - else { - p2p_sendStatus(ft, 603); - debugLogA("Requested avatar does not match current avatar"); - p2p_unregisterSession(ft); - } - } - break; - - case MSN_APPID_FILE: - if (!_stricmp(szEufGuid, "{5D3E02AB-6190-11D3-BBBB-00C04F795683}")) { - wchar_t* wszFileName = ((HFileContext*)szContext)->wszFileName; - for (wchar_t* p = wszFileName; *p != 0; p++) { - switch (*p) { - case ':': case '?': case '/': case '\\': case '*': - *p = '_'; - } - } - - mir_free(ft->std.tszCurrentFile); - ft->std.tszCurrentFile = mir_wstrdup(wszFileName); - - ft->std.totalBytes = ft->std.currentFileSize = ((HFileContext*)szContext)->dwSize; - ft->std.totalFiles = 1; - - wchar_t tComment[40]; - mir_snwprintf(tComment, TranslateT("%I64u bytes"), ft->std.currentFileSize); - - PROTORECVFILET pre = { 0 }; - pre.dwFlags = PRFF_UNICODE; - pre.fileCount = 1; - pre.timestamp = time(NULL); - pre.descr.w = tComment; - pre.files.w = &ft->std.tszCurrentFile; - pre.lParam = (LPARAM)ft; - ProtoChainRecvFile(ft->std.hContact, &pre); - } - break; - - case MSN_APPID_WEBCAM: - if (!_stricmp(szEufGuid, "{4BD96FC0-AB17-4425-A14A-439185962DC8}")) { - MSN_ShowPopup(ft->std.hContact, - TranslateT("Contact tried to send its webcam data (not currently supported)"), - MSN_ALLOW_MSGBOX | MSN_SHOW_ERROR); - } - if (!_stricmp(szEufGuid, "{1C9AA97E-9C05-4583-A3BD-908A196F1E92}")) { - MSN_ShowPopup(ft->std.hContact, - TranslateT("Contact tried to view your webcam data (not currently supported)"), - MSN_ALLOW_MSGBOX | MSN_SHOW_ERROR); - } - p2p_sendStatus(ft, 603); - p2p_unregisterSession(ft); - 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); - p2p_sendStatus(ft, 603); - p2p_unregisterSession(ft); - break; - - default: - p2p_sendStatus(ft, 603); - p2p_unregisterSession(ft); - debugLogA("Invalid or unknown data transfer request (AppID/EUF-GUID: %ld/%s)", dwAppID, szEufGuid); - break; - } - - mir_free((void*)szContext); -} - -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) { - szBranch = strstr(szBranch, "branch="); - if (szBranch != NULL) - szBranch += 7; - } - 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) { - 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) { - ft = &ftl; - replaceStr(ft->p2p_dest, wlid); - replaceStr(ft->p2p_callID, szCallID); - replaceStr(ft->p2p_branch, szBranch); - ft->p2p_isV2 = strchr(wlid, ';') != NULL; - ft->std.hContact = MSN_HContactFromEmail(wlid); - } - 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); - */ - } - - directconnection *dc = p2p_getDCByCallID(szCallID, wlid); - if (dc) { - if (MSN_GetThreadByContact(wlid, SERVER_P2P_DIRECT)) { - p2p_sendStatus(ft, 1603); - p2p_unregisterDC(dc); - return; - } - p2p_unregisterDC(dc); - } - - dc = new directconnection(szCallID, wlid); - dc->useHashedNonce = szHashedNonce != NULL; - if (dc->useHashedNonce) - dc->xNonce = mir_strdup(szHashedNonce); - p2p_registerDC(dc); - - MimeHeaders tResult(8); - tResult.addString("CSeq", "1 "); - tResult.addString("Call-ID", szCallID); - tResult.addLong("Max-Forwards", 0); - - MyConnectionType conType = { 0 }; - - conType.extIP = atol(szNetID); - conType.SetUdpCon(szConnType); - conType.upnpNAT = mir_strcmp(szUPnPNat, "true") == 0; - conType.icf = mir_strcmp(szICF, "true") == 0; - conType.CalculateWeight(); - - MimeHeaders chdrs(12); - bool listen = false; - - debugLogA("Connection weight, his: %d mine: %d", conType.weight, MyConnection.weight); - if (conType.weight <= MyConnection.weight) - listen = p2p_createListener(ft, dc, chdrs); - - if (!listen) { - chdrs.addString("Bridge", "TCPv1"); - chdrs.addBool("Listening", false); - - if (dc->useHashedNonce) - chdrs.addString("Hashed-Nonce", dc->mNonceToHash(), 2); - else - chdrs.addString("Nonce", sttVoidUid); - - chdrs.addULong("SessionID", ft->p2p_sessionid); - chdrs.addString("SChannelState", "0"); - chdrs.addString("Capabilities-Flags", "1"); - } - - tResult.addString("Content-Type", "application/x-msnmsgr-transrespbody"); - - if (!ft->p2p_isV2) p2p_getMsgId(ft->p2p_dest, -1); - p2p_sendSlp(200, ft, tResult, chdrs); -} - - -void CMsnProto::p2p_startConnect(const char* wlid, const char* szCallID, const char* addr, const char* port, bool ipv6) -{ - if (port == NULL) return; - - char *pPortTokBeg = (char*)port; - for (;;) { - char *pPortTokEnd = strchr(pPortTokBeg, ' '); - if (pPortTokEnd != NULL) *pPortTokEnd = 0; - - char *pAddrTokBeg = (char*)addr; - for (;;) { - char *pAddrTokEnd = strchr(pAddrTokBeg, ' '); - if (pAddrTokEnd != NULL) *pAddrTokEnd = 0; - - ThreadData* newThread = new ThreadData; - - newThread->mType = SERVER_P2P_DIRECT; - newThread->mInitialContactWLID = mir_strdup(wlid); - strncpy_s(newThread->mCookie, szCallID, _TRUNCATE); - mir_snprintf(newThread->mServer, ipv6 ? "[%s]:%s" : "%s:%s", pAddrTokBeg, pPortTokBeg); - - newThread->startThread(&CMsnProto::p2p_fileActiveThread, this); - - if (pAddrTokEnd == NULL) break; - - *pAddrTokEnd = ' '; - pAddrTokBeg = pAddrTokEnd + 1; - } - - if (pPortTokEnd == NULL) break; - - *pPortTokEnd = ' '; - pPortTokBeg = pPortTokEnd + 1; - } -} - -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) { - debugLogA("Ignoring invalid invitation: Listening='%s', Nonce=%s", szListening, szNonce); - return; - } - - directconnection* dc = p2p_getDCByCallID(szCallID, wlid); - if (dc == NULL) { - dc = new directconnection(szCallID, wlid); - p2p_registerDC(dc); - } - - dc->useHashedNonce = szHashedNonce != NULL; - replaceStr(dc->xNonce, szHashedNonce ? szHashedNonce : szNonce); - - if (!mir_strcmp(szListening, "true") && mir_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); - } -} - -void CMsnProto::p2p_AcceptTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid) -{ - const char *szCallID = tFileInfo["Call-ID"]; - const char* szOldContentType = tFileInfo["Content-Type"]; - const char *szBranch = tFileInfo["Via"]; - - if (szBranch != NULL) { - szBranch = strstr(szBranch, "branch="); - if (szBranch != NULL) - szBranch += 7; - } - - filetransfer ftl(this), *ft = p2p_getSessionByCallID(szCallID, wlid); - - if (!ft || !ft->p2p_sessionid) { - ft = &ftl; - replaceStr(ft->p2p_branch, szBranch); - replaceStr(ft->p2p_callID, szCallID); - replaceStr(ft->p2p_dest, wlid); - ft->p2p_isV2 = strchr(wlid, ';') != NULL; - ft->std.hContact = MSN_HContactFromEmail(wlid); - } - else { - if (!(ft->std.flags & PFTS_SENDING)) { - replaceStr(ft->p2p_branch, szBranch); - replaceStr(ft->p2p_callID, szCallID); - } - } - - if (szCallID == NULL || szBranch == NULL || szOldContentType == NULL) { - debugLogA("Ignoring invalid invitation: CallID='%s', szBranch='%s'", szCallID, szBranch); -LBL_Close: - p2p_sendStatus(ft, 500); - return; - } - - MimeHeaders tResult(8); - tResult.addString("CSeq", "0 "); - tResult.addString("Call-ID", ft->p2p_callID); - tResult.addLong("Max-Forwards", 0); - - MimeHeaders chdrs(12); - - if (!mir_strcmp(szOldContentType, "application/x-msnmsgr-sessionreqbody")) { - if (ft == &ftl) { - p2p_sendCancel(ft); - return; - } - - if (!ft->bAccepted) { - replaceStr(ft->p2p_dest, wlid); - ft->bAccepted = true; - } - else - return; - - if (ft->p2p_type != MSN_APPID_FILE) { - if (ft->fileId == -1) ft->create(); - return; - } - - p2p_sendFeedStart(ft); - - ThreadData* T = MSN_GetP2PThreadByContact(ft->p2p_dest); - if (T != NULL && T->mType == SERVER_P2P_DIRECT) { - MSN_StartP2PTransferByContact(ft->p2p_dest); - return; - } - - if (usingGateway) - MSN_StartP2PTransferByContact(ft->p2p_dest); - - directconnection* dc = new directconnection(szCallID, wlid); - p2p_registerDC(dc); - - tResult.addString("Content-Type", "application/x-msnmsgr-transreqbody"); - - chdrs.addString("Bridges", "TCPv1"); - chdrs.addLong("NetID", MyConnection.extIP); - chdrs.addString("Conn-Type", MyConnection.GetMyUdpConStr()); - chdrs.addBool("UPnPNat", MyConnection.upnpNAT); - chdrs.addBool("ICF", MyConnection.icf); - chdrs.addString("IPv6-global", GetGlobalIp(), 2); - chdrs.addString("Hashed-Nonce", dc->mNonceToHash(), 2); - } - else if (!mir_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; - } - - directconnection* dc = p2p_getDCByCallID(szCallID, wlid); - if (dc == NULL) return; - - if (!dc->bAccepted) - dc->bAccepted = true; - else - return; - - dc->useHashedNonce = szHashedNonce != NULL; - replaceStr(dc->xNonce, szHashedNonce ? szHashedNonce : szNonce); - - // another side reported that it will be a server. - if (!mir_strcmp(szListening, "true") && (szNonce == NULL || mir_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); - return; - } - - // no, send a file via server - if (!p2p_createListener(ft, dc, chdrs)) { - p2p_unregisterDC(dc); - if (ft != &ftl) - MSN_StartP2PTransferByContact(ft->p2p_dest); - else - p2p_startSessions(ft->p2p_dest); - return; - } - - tResult.addString("Content-Type", "application/x-msnmsgr-transrespbody"); - } - else if (!mir_strcmp(szOldContentType, "application/x-msnmsgr-transreqbody")) { - const char *szHashedNonce = tFileInfo2["Hashed-Nonce"]; - const char *szNonce = tFileInfo2["Nonce"]; - - directconnection* dc = p2p_getDCByCallID(szCallID, wlid); - if (dc == NULL) { - dc = new directconnection(szCallID, wlid); - p2p_registerDC(dc); - } - - dc->useHashedNonce = szHashedNonce != NULL; - replaceStr(dc->xNonce, szHashedNonce ? szHashedNonce : szNonce); - - // no, send a file via server - if (!p2p_createListener(ft, dc, chdrs)) { - p2p_unregisterDC(dc); - MSN_StartP2PTransferByContact(ft->p2p_dest); - return; - } - - tResult.addString("Content-Type", "application/x-msnmsgr-transrespbody"); - } - else - return; - - if (!ft->p2p_isV2) p2p_getMsgId(ft->p2p_dest, -1); - p2p_sendSlp(-2, ft, tResult, chdrs); -} - - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_processSIP - processes all MSN SIP commands - -void CMsnProto::p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdrdata, const char* wlid) -{ - int iMsgType = 0; - if (!memcmp(msgbody, "INVITE MSNMSGR:", 15)) - iMsgType = 1; - else if (!memcmp(msgbody, "MSNSLP/1.0 200 ", 15)) - iMsgType = 2; - else if (!memcmp(msgbody, "BYE MSNMSGR:", 12)) - iMsgType = 3; - else if (!memcmp(msgbody, "MSNSLP/1.0 603 ", 15)) - iMsgType = 4; - else if (!memcmp(msgbody, "MSNSLP/1.0 481 ", 15)) - iMsgType = 4; - else if (!memcmp(msgbody, "MSNSLP/1.0 500 ", 15)) - iMsgType = 4; - else if (!memcmp(msgbody, "ACK MSNMSGR:", 12)) - iMsgType = 5; - - char* peol = strstr(msgbody, "\r\n"); - if (peol != NULL) - msgbody = peol + 2; - - MimeHeaders tFileInfo, tFileInfo2; - msgbody = tFileInfo.readFromBuffer(msgbody); - msgbody = tFileInfo2.readFromBuffer(msgbody); - - const char* szContentType = tFileInfo["Content-Type"]; - if (szContentType == NULL) { - debugLogA("Invalid or missing Content-Type field, exiting"); - return; - } - - if (hdrdata && !hdrdata->isV2Hdr()) { - if (iMsgType == 2 || (iMsgType == 1 && !mir_strcmp(szContentType, "application/x-msnmsgr-transreqbody"))) - p2p_getMsgId(wlid, 1); - } - - switch (iMsgType) { - case 1: - if (!mir_strcmp(szContentType, "application/x-msnmsgr-sessionreqbody")) - p2p_InitFileTransfer(info, tFileInfo, tFileInfo2, wlid); - else if (!mir_strcmp(szContentType, "application/x-msnmsgr-transreqbody")) - p2p_InitDirectTransfer(tFileInfo, tFileInfo2, wlid); - else if (!mir_strcmp(szContentType, "application/x-msnmsgr-transrespbody")) - p2p_InitDirectTransfer2(tFileInfo, tFileInfo2, wlid); - break; - - case 2: - p2p_AcceptTransfer(tFileInfo, tFileInfo2, wlid); - break; - - case 3: - if (!mir_strcmp(szContentType, "application/x-msnmsgr-sessionclosebody")) { - filetransfer* ft = p2p_getSessionByCallID(tFileInfo["Call-ID"], wlid); - if (ft != NULL) { - if (ft->std.currentFileProgress < ft->std.currentFileSize) { - ft->bCanceled = true; - p2p_sendAbortSession(ft); - } - else { - if (!(ft->std.flags & PFTS_SENDING)) - ft->bCompleted = true; - } - - p2p_sessionComplete(ft); - } - } - break; - - case 4: - { - const char* szCallID = tFileInfo["Call-ID"]; - - // application/x-msnmsgr-session-failure-respbody - - directconnection *dc = p2p_getDCByCallID(szCallID, wlid); - if (dc != NULL) { - p2p_unregisterDC(dc); - break; - } - - filetransfer* ft = p2p_getSessionByCallID(szCallID, wlid); - if (ft == NULL) - break; - - ft->close(); - if (!(ft->std.flags & PFTS_SENDING)) _wremove(ft->std.tszCurrentFile); - - p2p_unregisterSession(ft); - } - break; - - case 5: - if (!mir_strcmp(szContentType, "application/x-msnmsgr-turnsetup")) { - // tFileInfo2["ServerAddress"]; - // tFileInfo2["SessionUsername"]; - // tFileInfo2["SessionPassword"]; - } - else if (!mir_strcmp(szContentType, "application/x-msnmsgr-transudpswitch")) { - // tFileInfo2["IPv6AddrsAndPorts"]; - // tFileInfo2["IPv4ExternalAddrsAndPorts"]; - // tFileInfo2["IPv4InternalAddrsAndPorts"]; - } - break; - } -} - - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_processMsg - processes all MSN P2P incoming messages -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.mOpCode & 0x02) - p2p_sendAck(wlid, &hdrdata); - return; - } - - if (hdrdata.mRemSize || hdrdata.mTFCode == 0) { - char msgid[128]; - mir_snprintf(msgid, "%s_%08x", wlid, hdrdata.mPacketNum); - - int idx; - 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 { - 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) { - size_t newsize; - if (getCachedMsg(idx, msgbody, newsize)) { - unsigned id = hdrdata.mID; - msg = hdrdata.parseMsg(msgbody); - hdrdata.mID = id; - - if (hdrdata.mOpCode & 0x02) - p2p_sendAck(wlid, &hdrdata); - - if (hdrdata.mTFCode) - p2p_processSIP(info, msg, &hdrdata, wlid); - mir_free(msgbody); - } - else - clearCachedMsg(idx); - } - } - else { - if (hdrdata.mOpCode & 0x02) - p2p_sendAck(wlid, &hdrdata); - - p2p_processSIP(info, msg, &hdrdata, wlid); - } - - return; - } - - if (hdrdata.mOpCode & 0x02) - p2p_sendAck(wlid, &hdrdata); - - filetransfer* ft = p2p_getSessionByID(hdrdata.mSessionID); - if (ft == NULL) return; - - ft->ts = time(NULL); - - 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) { - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std); - ft->nNotify = clock() + 500; - - //---- send an ack: body was transferred correctly - debugLogA("Transferred %I64u bytes remaining %I64u", ft->std.currentFileProgress, hdrdata.mRemSize); - } - - 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 { - p2p_savePicture2disk(ft); - if (!ft->p2p_isV2) p2p_sendBye(ft); - } - } - } -} - -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) { - // MsnContact *cont = Lists_Get(wlid); - // if (cont && cont->places.getCount()) - // return; - - if (hdrdata.mPacketLen < hdrdata.mTotalSize) { - char msgid[128]; - mir_snprintf(msgid, "%s_%08x", wlid, hdrdata.mID); - int idx = addCachedMsg(msgid, msgbody, (size_t)hdrdata.mOffset, hdrdata.mPacketLen, - (size_t)hdrdata.mTotalSize, false); - - char* newbody; - size_t newsize; - if (getCachedMsg(idx, newbody, newsize)) { - p2p_sendAck(wlid, &hdrdata); - p2p_processSIP(info, newbody, &hdrdata, wlid); - mir_free(newbody); - } - else { - if (hdrdata.mOffset + hdrdata.mPacketLen >= hdrdata.mTotalSize) - clearCachedMsg(idx); - } - } - else { - p2p_sendAck(wlid, &hdrdata); - p2p_processSIP(info, msgbody, &hdrdata, wlid); - } - - return; - } - - filetransfer* ft = p2p_getSessionByID(hdrdata.mSessionID); - if (ft == NULL) - ft = p2p_getSessionByUniqueID(hdrdata.mAckUniqueID); - - if (ft == NULL) return; - - ft->ts = time(NULL); - - //---- receiving redirect ----------- - 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.currentFileProgress -= dp; - _lseeki64(ft->fileId, ft->std.currentFileProgress, SEEK_SET); - ft->tType = info->mType; - ReleaseMutex(ft->hLockHandle); - } - } - - //---- receiving ack ----------- - if (hdrdata.mFlags == 0x02) { - ft->p2p_waitack = false; - - 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) { - p2p_sessionComplete(ft); - return; - } - - switch (ft->p2p_ackID) { - case 1000: - //---- send Data Preparation Message - p2p_sendAvatarInit(ft); - break; - - case 1001: - //---- send Data Messages - MSN_StartP2PTransferByContact(ft->p2p_dest); - break; - } - - ft->p2p_ackID++; - return; - } - - if (LOWORD(hdrdata.mFlags) == 0) { - //---- accept the data preparation message ------ - // const unsigned* pLongs = (unsigned*)msgbody; - if (hdrdata.mPacketLen == 4 && hdrdata.mTotalSize == 4) { - p2p_sendAck(ft->p2p_dest, &hdrdata); - return; - } - else - hdrdata.mFlags = 0x20; - } - - //---- receiving data ----------- - 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) { - ft->tType = info->mType; - ft->p2p_sendmsgid = hdrdata.mID; - } - - __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->lstFilePtr != hdrdata.mOffset) - _lseeki64(ft->fileId, hdrdata.mOffset, SEEK_SET); - _write(ft->fileId, msgbody, (unsigned int)dsz); - - ft->lstFilePtr = hdrdata.mOffset + dsz; - - __int64 dp = ft->lstFilePtr - ft->std.currentFileProgress; - if (dp > 0) { - ft->std.totalProgress += dp; - ft->std.currentFileProgress += dp; - - 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; - } - } - - //---- send an ack: body was transferred correctly - debugLogA("Transferred %I64u bytes out of %I64u", 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) { - ft->ts = time(NULL); - ft->p2p_waitack = true; - ft->complete(); - } - else { - p2p_savePicture2disk(ft); - p2p_sendBye(ft); - } - } - } - } - - if (hdrdata.mFlags == 0x40 || hdrdata.mFlags == 0x80) { - p2p_sendAbortSession(ft); - p2p_unregisterSession(ft); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// -// p2p_invite - invite another side to transfer an avatar - -void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) -{ - const char* szAppID; - 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; - case MSN_APPID_CUSTOMANIMATEDSMILEY: szAppID = "{A4268EEC-FEC5-49E5-95C3-F126696BDBF6}"; break; - default: return; - } - - ft->p2p_type = iAppID; - ft->p2p_acksessid = MSN_GenRandom(); - mir_free(ft->p2p_callID); - ft->p2p_callID = getNewUuid(); - - MsnContact* cont = Lists_Get(ft->std.hContact); - if (cont == NULL) return; - - 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); - } - - char* pContext = NULL; - size_t cbContext = 0; - - switch (iAppID) { - case MSN_APPID_FILE: - cbContext = sizeof(HFileContext); - pContext = (char*)malloc(cbContext); - { - HFileContext* ctx = (HFileContext*)pContext; - memset(pContext, 0, cbContext); - if (ft->p2p_isV2) { - cbContext -= 64; - ctx->ver = 2; - } - else { - ctx->ver = 3; - ctx->id = 0xffffffff; - } - ctx->len = (unsigned)cbContext; - ctx->type = MSN_TYPEID_FTNOPREVIEW; - ctx->dwSize = ft->std.currentFileSize; - - wchar_t* pszFiles = wcsrchr(ft->std.tszCurrentFile, '\\'); - if (pszFiles) - pszFiles++; - else - pszFiles = ft->std.tszCurrentFile; - - wchar_t *fname = mir_wstrdup(pszFiles); - wcsncpy(ctx->wszFileName, fname, MAX_PATH); - mir_free(fname); - - ft->p2p_appID = MSN_APPID_FILE; - } - break; - - default: - ft->p2p_appID = MSN_APPID_AVATAR2; - - if (ft->p2p_object == NULL) { - delete ft; - return; - } - - ezxml_t xmlo = ezxml_parse_str(NEWSTR_ALLOCA(ft->p2p_object), mir_strlen(ft->p2p_object)); - ezxml_t xmlr = ezxml_new("msnobj"); - - const char* p; - p = ezxml_attr(xmlo, "Creator"); - if (p != NULL) - ezxml_set_attr(xmlr, "Creator", p); - p = ezxml_attr(xmlo, "Size"); - if (p != NULL) { - ezxml_set_attr(xmlr, "Size", p); - ft->std.totalBytes = ft->std.currentFileSize = _atoi64(p); - } - p = ezxml_attr(xmlo, "Type"); - if (p != NULL) - ezxml_set_attr(xmlr, "Type", p); - p = ezxml_attr(xmlo, "Location"); - if (p != NULL) - ezxml_set_attr(xmlr, "Location", p); - p = ezxml_attr(xmlo, "Friendly"); - if (p != NULL) - ezxml_set_attr(xmlr, "Friendly", p); - p = ezxml_attr(xmlo, "SHA1D"); - if (p != NULL) - ezxml_set_attr(xmlr, "SHA1D", p); - p = ezxml_attr(xmlo, "SHA1C"); - if (p != NULL) - ezxml_set_attr(xmlr, "SHA1C", p); - - pContext = ezxml_toxml(xmlr, false); - cbContext = mir_strlen(pContext) + 1; - - ezxml_free(xmlr); - ezxml_free(xmlo); - - break; - } - - bool sessionExist = p2p_sessionRegistered(ft); - 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) { - char wlid[128]; - mir_snprintf(wlid, - mir_strcmp(cont->places[0].id, sttVoidUid) ? "%s;%s" : "%s", - cont->email, cont->places[0].id); - - if (!MSN_GetThreadByContact(wlid, SERVER_P2P_DIRECT)) - p2p_inviteDc(ft, wlid); - else - p2p_invite(ft->p2p_type, ft, wlid); - - free(pContext); - return; - } - } - else { - const char *wlid = cont->email; - if (cont->cap1 & cap_SupportsP2PBootstrap) { - if (!MSN_GetThreadByContact(wlid, SERVER_P2P_DIRECT)) - p2p_inviteDc(ft, wlid); - else - p2p_invite(ft->p2p_type, ft, wlid); - - free(pContext); - return; - } - } - } - } - - if (!ft->bAccepted) - ft->p2p_sessionid = MSN_GenRandom(); - - ptrA szContextEnc(mir_base64_encode((PBYTE)pContext, (unsigned)cbContext)); - - MimeHeaders chdrs(10); - chdrs.addString("EUF-GUID", szAppID); - chdrs.addULong("SessionID", ft->p2p_sessionid); - chdrs.addULong("AppID", ft->p2p_appID); - chdrs.addString("Context", szContextEnc); - - MimeHeaders tResult(8); - tResult.addString("CSeq", "0 "); - tResult.addString("Call-ID", ft->p2p_callID); - tResult.addLong("Max-Forwards", 0); - tResult.addString("Content-Type", "application/x-msnmsgr-sessionreqbody"); - - 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) { - char wlid[128]; - mir_snprintf(wlid, - mir_strcmp(cont->places[i].id, sttVoidUid) ? "%s;%s" : "%s", - cont->email, cont->places[i].id); - - p2p_sendSlp(-2, ft, tResult, chdrs, wlid); - } - } - else p2p_sendSlp(-2, ft, tResult, chdrs, wlid); - - free(pContext); -} - - -void CMsnProto::p2p_inviteDc(filetransfer* ft, const char *wlid) -{ - directconnection* dc = new directconnection(szUbnCall, wlid); - p2p_registerDC(dc); - - MimeHeaders tResult(8); - tResult.addString("CSeq", "0 "); - tResult.addString("Call-ID", dc->callId); - tResult.addLong("Max-Forwards", 0); - tResult.addString("Content-Type", "application/x-msnmsgr-transreqbody"); - - MimeHeaders chdrs(12); - - chdrs.addString("Bridges", "TCPv1 SBBridge"); - chdrs.addLong("NetID", MyConnection.extIP); - chdrs.addString("Conn-Type", MyConnection.GetMyUdpConStr()); - chdrs.addBool("UPnPNat", MyConnection.upnpNAT); - chdrs.addBool("ICF", MyConnection.icf); - chdrs.addString("IPv6-global", GetGlobalIp(), 2); - chdrs.addString("Hashed-Nonce", dc->mNonceToHash(), 2); - chdrs.addString("SessionID", "0"); - chdrs.addString("SChannelState", "0"); - chdrs.addString("Capabilities-Flags", "1"); - - p2p_sendSlp(-2, ft, tResult, chdrs, wlid); -} - -/* -void CMsnProto::p2p_sendSessionAck(filetransfer* ft) -{ - MimeHeaders tResult(8); - tResult.addString("CSeq", "0 "); - tResult.addString("Call-ID", sttVoidUid); - tResult.addLong("Max-Forwards", 0); - tResult.addString("Content-Type", "application/x-msnmsgr-transdestaddrupdate"); - - MimeHeaders chdrs(8); - - chdrs.addString("IPv4ExternalAddrsAndPorts", mir_strdup(MyConnection.GetMyExtIPStr()), 6); - chdrs.addString("IPv4InternalAddrsAndPorts", mir_strdup(MyConnection.GetMyExtIPStr()), 6); - chdrs.addString("SessionID", "0"); - chdrs.addString("SChannelState", "0"); - chdrs.addString("Capabilities-Flags", "1"); - - 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) { - bool success = ft->std.currentFileNumber >= ft->std.totalFiles && ft->bCompleted; - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, success ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, ft, 0); - } - else { - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0); - p2p_invite(ft->p2p_appID, ft, NULL); - } - } - else { - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ft->bCompleted ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, ft, 0); - p2p_unregisterSession(ft); - } -} - -char* P2PV2_Header::parseMsg(char *buf) -{ - unsigned char hdrLen1 = *(unsigned char*)buf; - mOpCode = *(unsigned char*)(buf + 1); - mPacketLen = _htons(*(unsigned short*)(buf + 2)); - mID = _htonl(*(unsigned*)(buf + 4)); - - char* buf1 = buf + hdrLen1; - - for (char *tlvp = buf + 8; tlvp < buf1 && *tlvp; tlvp += 2 + tlvp[1]) { - switch (*tlvp) { - case 1: - mCap = tlvp; - break; - case 2: - mAckUniqueID = _htonl(*(unsigned*)(tlvp + 4)); - break; - case 3: - break; - } - } - - if (mPacketLen == 0) return buf + hdrLen1; - - unsigned char hdrLen2 = *(unsigned char*)buf1; - mTFCode = *(unsigned char*)(buf1 + 1); - mPacketNum = _htons(*(unsigned short*)(buf1 + 2)); - mSessionID = _htonl(*(unsigned*)(buf1 + 4)); - - char* buf2 = buf1 + hdrLen2; - - for (char *tlvp1 = buf1 + 8; tlvp1 < buf2 && *tlvp1; tlvp1 += 2 + tlvp1[1]) { - switch (*tlvp1) { - case 1: - mRemSize = _htonl64(*(unsigned __int64*)(tlvp1 + 2)); - break; - } - } - - mPacketLen -= hdrLen2; - return buf1 + hdrLen2; -} - -char* P2PV2_Header::createMsg(char *buf, const char* wlid, CMsnProto *ppro) -{ - unsigned char hdrLen1 = 8 + (mAckUniqueID ? 6 : 0) + (mCap ? 2 + mCap[1] : 0); - unsigned char comp = hdrLen1 & 3; - hdrLen1 += comp ? 4 - comp : 0; - - unsigned char hdrLen2 = mPacketLen ? (8 + (mRemSize ? 10 : 0)) : 0; - comp = hdrLen2 & 3; - hdrLen2 += comp ? 4 - comp : 0; - - mID = ppro->p2p_getMsgId(wlid, mPacketLen + hdrLen2); - - memset(buf, 0, hdrLen1 + hdrLen2); - - *(unsigned char*)(buf + 0) = hdrLen1; - *(unsigned char*)(buf + 1) = mOpCode; - *(unsigned short*)(buf + 2) = _htons(mPacketLen + hdrLen2); - *(unsigned*)(buf + 4) = _htonl(mID); - - char *buf1 = buf + 8; - - if (mAckUniqueID) { - *(unsigned char*)buf1 = 2; - *(unsigned char*)(buf1 + 1) = 4; - *(unsigned*)(buf1 + 2) = _htonl(mAckUniqueID); - buf1 += 6; - } - if (mCap) { - unsigned len = 2 + mCap[1]; - memcpy(buf1, mCap, len); - buf1 += len; - } - - buf1 = buf + hdrLen1; - - if (hdrLen2 == 0) return buf1; - - *(unsigned char*)(buf1 + 0) = hdrLen2; - *(unsigned char*)(buf1 + 1) = mTFCode; - *(unsigned short*)(buf1 + 2) = _htons(mPacketNum); - *(unsigned*)(buf1 + 4) = _htonl(mSessionID); - - if (mRemSize) { - *(unsigned char*)(buf1 + 8) = 1; - *(unsigned char*)(buf1 + 9) = 8; - *(unsigned __int64*)(buf1 + 10) = _htonl64(mRemSize); - } - - return buf1 + hdrLen2; -} - -char* P2P_Header::createMsg(char *buf, const char* wlid, CMsnProto *ppro) -{ - if (!mID) mID = ppro->p2p_getMsgId(wlid, 1); - memcpy(buf, &mSessionID, 48); - return buf + 48; -} -#endif \ No newline at end of file diff --git a/protocols/MSN/src/msn_p2ps.cpp b/protocols/MSN/src/msn_p2ps.cpp deleted file mode 100644 index a42526dac1..0000000000 --- a/protocols/MSN/src/msn_p2ps.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* -Plugin of Miranda IM for communicating with users of the MSN Messenger protocol. - -Copyright (c) 2012-2017 Miranda NG Team -Copyright (c) 2006-2012 Boris Krasnovskiy. -Copyright (c) 2003-2005 George Hazan. -Copyright (c) 2002-2003 Richard Hughes (original version). - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdafx.h" -#include "msn_proto.h" -#ifdef OBSOLETE - -///////////////////////////////////////////////////////////////////////////////////////// -// add file session to a list - -void CMsnProto::p2p_registerSession(filetransfer* ft) -{ - mir_cslock lck(m_csSessions); - m_arSessions.insert(ft); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// remove file session from a list - -void CMsnProto::p2p_unregisterSession(filetransfer* ft) -{ - mir_cslock lck(m_csSessions); - m_arSessions.remove(ft); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// get session by some parameter - -filetransfer* CMsnProto::p2p_getSessionByID(unsigned id) -{ - if (id == 0) - return NULL; - - mir_cslock lck(m_csSessions); - - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[i]; - if (FT->p2p_sessionid == id) - return FT; - } - - return NULL; -} - -filetransfer* CMsnProto::p2p_getSessionByUniqueID(unsigned id) -{ - if (id == 0) - return NULL; - - mir_cslock lck(m_csSessions); - - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[i]; - if (FT->p2p_acksessid == id) - return FT; - } - - return NULL; -} - - -bool CMsnProto::p2p_sessionRegistered(filetransfer* ft) -{ - if (ft != NULL && ft->p2p_appID == 0) - return true; - - mir_cslock lck(m_csSessions); - return m_arSessions.getIndex(ft) > -1; -} - -filetransfer* CMsnProto::p2p_getThreadSession(MCONTACT hContact, TInfoType mType) -{ - mir_cslock lck(m_csSessions); - - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[i]; - if (FT->std.hContact == hContact && FT->tType == mType) - return FT; - } - - return NULL; -} - -void CMsnProto::p2p_clearThreadSessions(MCONTACT hContact, TInfoType mType) -{ - mir_cslock lck(m_csSessions); - - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* ft = &m_arSessions[i]; - if (ft->std.hContact == hContact && ft->tType == mType) { - ft->bCanceled = true; - ft->tType = SERVER_NOTIFICATION; - p2p_sendCancel(ft); - } - } -} - -filetransfer* CMsnProto::p2p_getAvatarSession(MCONTACT hContact) -{ - mir_cslock lck(m_csSessions); - - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[i]; - if (FT->std.hContact == hContact && !(FT->std.flags & PFTS_SENDING) && FT->p2p_type == MSN_APPID_AVATAR) - return FT; - } - - return NULL; -} - -bool CMsnProto::p2p_isAvatarOnly(MCONTACT hContact) -{ - mir_cslock lck(m_csSessions); - - bool result = true; - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[i]; - result &= FT->std.hContact != hContact || FT->p2p_type != MSN_APPID_FILE; - } - - return result; -} - -void CMsnProto::p2p_clearDormantSessions(void) -{ - mir_cslockfull lck(m_csSessions); - - time_t ts = time(NULL); - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[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) { - FT->bCanceled = true; - p2p_sendCancel(FT); - lck.unlock(); - p2p_unregisterSession(FT); - lck.lock(); - i = 0; - } - } -} - -void CMsnProto::p2p_redirectSessions(const char *wlid) -{ - mir_cslock lck(m_csSessions); - - ThreadData* T = MSN_GetP2PThreadByContact(wlid); - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[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) { - if ((FT->std.flags & PFTS_SENDING) && T) - FT->tType = T->mType; - } - else { - if (!(FT->std.flags & PFTS_SENDING)) - p2p_sendRedirect(FT); - } - } - } -} - -void CMsnProto::p2p_startSessions(const char* wlid) -{ - mir_cslock lck(m_csSessions); - - char* szEmail; - parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[i]; - 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)) - p2p_invite(FT->p2p_type, FT, wlid); - } - } -} - -void CMsnProto::p2p_cancelAllSessions(void) -{ - mir_cslock lck(m_csSessions); - - for (int i = 0; i < m_arSessions.getCount(); i++) { - m_arSessions[i].bCanceled = true; - p2p_sendCancel(&m_arSessions[i]); - } -} - -filetransfer* CMsnProto::p2p_getSessionByCallID(const char* CallID, const char* wlid) -{ - if (CallID == NULL) - return NULL; - - mir_cslock lck(m_csSessions); - - char* szEmail = NULL; - for (int i = 0; i < m_arSessions.getCount(); i++) { - filetransfer* FT = &m_arSessions[i]; - 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)) - continue; - } - return FT; - } - } - - return NULL; -} - - -void CMsnProto::p2p_registerDC(directconnection* dc) -{ - mir_cslock lck(m_csSessions); - m_arDirect.insert(dc); -} - -void CMsnProto::p2p_unregisterDC(directconnection* dc) -{ - mir_cslock lck(m_csSessions); - m_arDirect.remove(dc); -} - -directconnection* CMsnProto::p2p_getDCByCallID(const char* CallID, const char* wlid) -{ - if (CallID == NULL) - return NULL; - - mir_cslock lck(m_csSessions); - - for (int i = 0; i < m_arDirect.getCount(); i++) { - directconnection* DC = &m_arDirect[i]; - if (DC->callId != NULL && !mir_strcmp(DC->callId, CallID) && !mir_strcmp(DC->wlid, wlid)) - return DC; - } - - return NULL; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// external functions - -void CMsnProto::P2pSessions_Uninit(void) -{ - mir_cslock lck(m_csSessions); - m_arSessions.destroy(); - m_arDirect.destroy(); -} -#endif diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index 44cd861286..57e190da30 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -24,9 +24,8 @@ along with this program. If not, see . static COLORREF crCols[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; int msn_httpGatewayInit(HNETLIBCONN hConn, NETLIBOPENCONNECTION *nloc, NETLIBHTTPREQUEST *nlhr); -int msn_httpGatewayBegin(HNETLIBCONN hConn, NETLIBOPENCONNECTION *nloc); int msn_httpGatewayWrapSend(HNETLIBCONN hConn, PBYTE buf, int len, int flags); -PBYTE msn_httpGatewayUnwrapRecv(NETLIBHTTPREQUEST *nlhr, PBYTE buf, int len, int *outBufLen, void *(*NetlibRealloc)(void*, size_t)); +PBYTE msn_httpGatewayUnwrapRecv(NETLIBHTTPREQUEST *nlhr, PBYTE buf, int len, int *outBufLen, void *(*)(void*, size_t)); static int CompareLists(const MsnContact *p1, const MsnContact *p2) { @@ -39,10 +38,6 @@ CMsnProto::CMsnProto(const char* aProtoName, const wchar_t* aUserName) : m_arGroups(10, CompareId), m_arThreads(10, PtrKeySortT), m_arGCThreads(10, PtrKeySortT), -#ifdef OBSOLETE - m_arSessions(10, PtrKeySortT), - m_arDirect(10, PtrKeySortT), -#endif lsMessageQueue(1), lsAvatarQueue(1), msgCache(5, CompareId), @@ -81,12 +76,6 @@ CMsnProto::CMsnProto(const char* aProtoName, const wchar_t* aUserName) : CreateProtoService(PS_GETAVATARCAPS, &CMsnProto::GetAvatarCaps); CreateProtoService(PS_SETMYNICKNAME, &CMsnProto::SetNickName); -#ifdef OBSOLETE - CreateProtoService(PS_GET_LISTENINGTO, &CMsnProto::GetCurrentMedia); - CreateProtoService(PS_SET_LISTENINGTO, &CMsnProto::SetCurrentMedia); - - MsgQueue_Init(); -#endif hMSNNudge = CreateProtoEvent("/Nudge"); CreateProtoService(PS_SEND_NUDGE, &CMsnProto::SendNudge); @@ -168,11 +157,6 @@ CMsnProto::~CMsnProto() Threads_Uninit(); AvatarQueue_Uninit(); Lists_Uninit(); -#ifdef OBSOLETE - DestroyHookableEvent(hMSNNudge); - P2pSessions_Uninit(); - MsgQueue_Uninit(); -#endif CachedMsg_Uninit(); Netlib_CloseHandle(m_hNetlibUser); @@ -416,12 +400,6 @@ void __cdecl CMsnProto::MsnSearchAckThread(void* arg) case 1: if (strstr(email, "@yahoo.com") == NULL) ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, arg, 0); - #ifdef OBSOLETE - else { - msnSearchId = arg; - MSN_FindYahooUser(email); - } - #endif break; default: @@ -487,17 +465,6 @@ void __cdecl CMsnProto::MsnFileAckThread(void* arg) ft->create(); -#ifdef OBSOLETE - if (ft->tType != SERVER_HTTP) { - if (ft->p2p_appID != 0) { - if (fcrt) - p2p_sendFeedStart(ft); - p2p_sendStatus(ft, fcrt ? 200 : 603); - } - else msnftp_sendAcceptReject(ft, fcrt); - } -#endif - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0); if (ft->tType == SERVER_HTTP) { @@ -564,11 +531,6 @@ HANDLE __cdecl CMsnProto::FileAllow(MCONTACT, HANDLE hTransfer, const wchar_t* s { filetransfer* ft = (filetransfer*)hTransfer; -#ifdef OBSOLETE - if (ft->tType != SERVER_HTTP && (!msnLoggedIn || !p2p_sessionRegistered(ft))) - return 0; -#endif - if ((ft->std.tszWorkingDir = mir_wstrdup(szPath)) == NULL) { wchar_t szCurrDir[MAX_PATH]; GetCurrentDirectory(_countof(szCurrDir), szCurrDir); @@ -590,31 +552,8 @@ int __cdecl CMsnProto::FileCancel(MCONTACT, HANDLE hTransfer) { filetransfer* ft = (filetransfer*)hTransfer; - if (ft->tType == SERVER_HTTP) ft->bCanceled = true; -#ifdef OBSOLETE - else { - if (!msnLoggedIn || !p2p_sessionRegistered(ft)) - return 0; - - if (!(ft->std.flags & PFTS_SENDING) && ft->fileId == -1) { - if (ft->p2p_appID != 0) - p2p_sendStatus(ft, 603); - else - msnftp_sendAcceptReject(ft, false); - } - else { - ft->bCanceled = true; - if (ft->p2p_appID != 0) { - p2p_sendCancel(ft); - if (!(ft->std.flags & PFTS_SENDING) && ft->p2p_isV2) - p2p_sessionComplete(ft); - } - } - - ft->std.ptszFiles = NULL; - ft->std.totalFiles = 0; - } -#endif + if (ft->tType == SERVER_HTTP) + ft->bCanceled = true; return 0; } @@ -622,26 +561,8 @@ int __cdecl CMsnProto::FileCancel(MCONTACT, HANDLE hTransfer) int __cdecl CMsnProto::FileDeny(MCONTACT, HANDLE hTransfer, const wchar_t* /*szReason*/) { filetransfer* ft = (filetransfer*)hTransfer; - - if (ft->tType == SERVER_HTTP) delete ft; -#ifdef OBSOLETE - else { - if (!msnLoggedIn || !p2p_sessionRegistered(ft)) - return 1; - - if (!(ft->std.flags & PFTS_SENDING) && ft->fileId == -1) { - if (ft->p2p_appID != 0) - p2p_sendStatus(ft, 603); - else - msnftp_sendAcceptReject(ft, false); - } - else { - ft->bCanceled = true; - if (ft->p2p_appID != 0) - p2p_sendCancel(ft); - } - } -#endif + if (ft->tType == SERVER_HTTP) + delete ft; return 0; } @@ -673,39 +594,6 @@ int __cdecl CMsnProto::FileResume(HANDLE hTransfer, int* action, const wchar_t** } SetEvent(ft->hResumeEvt); } -#ifdef OBSOLETE - else { - if (!msnLoggedIn || !p2p_sessionRegistered(ft)) - return 1; - - switch (*action) { - case FILERESUME_SKIP: - if (ft->p2p_appID != 0) - p2p_sendStatus(ft, 603); - else - msnftp_sendAcceptReject(ft, false); - break; - - case FILERESUME_RENAME: - replaceStrW(ft->std.tszCurrentFile, *szFilename); - - default: - bool fcrt = ft->create() != -1; - if (ft->p2p_appID != 0) { - if (fcrt) - p2p_sendFeedStart(ft); - - p2p_sendStatus(ft, fcrt ? 200 : 603); - } - else - msnftp_sendAcceptReject(ft, fcrt); - - ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0); - break; - } - } -#endif - return 0; } @@ -832,53 +720,7 @@ int CMsnProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT* pre) return 0; } - -#ifdef OBSOLETE -// MsnSendFile - initiates a file transfer -HANDLE __cdecl CMsnProto::SendFile(MCONTACT hContact, const wchar_t*, wchar_t** ppszFiles) -{ - if (!msnLoggedIn) - return 0; - - if (getWord(hContact, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) - return 0; - - MsnContact *cont = Lists_Get(hContact); - - if (!cont || _stricmp(cont->email, MyOptions.szEmail) == 0) return 0; - - if ((cont->cap1 & 0xf0000000) == 0 && cont->netId != NETID_MSN) return 0; - - filetransfer* sft = new filetransfer(this); - sft->std.ptszFiles = ppszFiles; - sft->std.hContact = hContact; - sft->std.flags |= PFTS_SENDING; - - int count = 0; - while (ppszFiles[count] != NULL) { - struct _stati64 statbuf; - if (_wstat64(ppszFiles[count++], &statbuf) == 0 && (statbuf.st_mode & _S_IFDIR) == 0) { - sft->std.totalBytes += statbuf.st_size; - ++sft->std.totalFiles; - } - } - - if (sft->openNext() == -1) { - delete sft; - return 0; - } - - if (cont->cap1 & 0xf0000000) - p2p_invite(MSN_APPID_FILE, sft, NULL); - else { - sft->p2p_dest = mir_strdup(cont->email); - msnftp_invite(sft); - } - - ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_SENTREQUEST, sft, 0); - return sft; -} -#endif +///////////////////////////////////////////////////////////////////////////////////////// struct TFakeAckParams { @@ -968,15 +810,9 @@ int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); } else { -#ifdef OBSOLETE - const char msgType = MyOptions.SlowSend ? 'A' : 'N'; - bool isOffline; - ThreadData *thread = MSN_StartSB(tEmail, isOffline); -#else - /* MSNP24 doesn't have a switchboard anymore */ + // MSNP24 doesn't have a switchboard anymore bool isOffline = true; ThreadData *thread = NULL; -#endif if (thread == NULL) { if (isOffline) { @@ -990,15 +826,6 @@ int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); } } -#ifdef OBSOLETE - else - seq = MsgQueue_Add(tEmail, msgType, msg, 0, 0, rtlFlag); - } - else { - seq = thread->sendMessage(msgType, tEmail, netId, msg, rtlFlag); - if (!MyOptions.SlowSend) - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this)); -#endif } } break; @@ -1087,11 +914,6 @@ int __cdecl CMsnProto::SetStatus(int iNewStatus) return 0; } -#ifdef OBSOLETE - m_arSessions.destroy(); - m_arDirect.destroy(); -#endif - usingGateway = false; int oldMode = m_iStatus; @@ -1120,33 +942,8 @@ int __cdecl CMsnProto::UserIsTyping(MCONTACT hContact, int type) if (MSN_IsMeByContact(hContact, tEmail)) return 0; bool typing = type == PROTOTYPE_SELFTYPING_ON; - int netId = Lists_GetNetId(tEmail); -#ifdef OBSOLETE - switch (netId) { - case NETID_UNKNOWN: - case NETID_MSN: - case NETID_LCS: - bool isOffline; - { - ThreadData* thread = MSN_StartSB(tEmail, isOffline); - if (thread == NULL) { - if (isOffline) - return 0; - MsgQueue_Add(tEmail, 2571, NULL, 0, NULL, typing); - } - else MSN_StartStopTyping(thread, typing); - } - break; - case NETID_YAHOO: - if (typing) MSN_SendTyping(msnNsThread, tEmail, netId); - break; - - default: - break; - } -#endif if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) MSN_SendTyping(msnNsThread, tEmail, netId, typing); diff --git a/protocols/MSN/src/msn_proto.h b/protocols/MSN/src/msn_proto.h index 3db4644cbd..d0576b7908 100644 --- a/protocols/MSN/src/msn_proto.h +++ b/protocols/MSN/src/msn_proto.h @@ -54,9 +54,6 @@ struct CMsnProto : public PROTO virtual int __cdecl RecvMsg(MCONTACT hContact, PROTORECVEVENT*); virtual int __cdecl RecvContacts(MCONTACT hContact, PROTORECVEVENT*); -#ifdef OBSOLETE - virtual HANDLE __cdecl SendFile(MCONTACT hContact, const wchar_t* szDescription, wchar_t** ppszFiles); -#endif virtual int __cdecl SendMsg(MCONTACT hContact, int flags, const char* msg); virtual int __cdecl SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT *hContactsList); @@ -74,15 +71,12 @@ struct CMsnProto : public PROTO INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM wParam, LPARAM lParam); INT_PTR __cdecl GetAvatarInfo(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl GetMyAwayMsg(WPARAM wParam,LPARAM lParam); + INT_PTR __cdecl GetMyAwayMsg(WPARAM wParam, LPARAM lParam); INT_PTR __cdecl GetAvatar(WPARAM wParam, LPARAM lParam); INT_PTR __cdecl SetAvatar(WPARAM wParam, LPARAM lParam); INT_PTR __cdecl GetAvatarCaps(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl GetCurrentMedia(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl SetCurrentMedia(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl SetNickName(WPARAM wParam, LPARAM lParam); INT_PTR __cdecl SendNudge(WPARAM wParam, LPARAM lParam); @@ -91,15 +85,15 @@ struct CMsnProto : public PROTO INT_PTR __cdecl OnLeaveChat(WPARAM wParam, LPARAM lParam); //====| Events |====================================================================== - int __cdecl OnContactDeleted(WPARAM wParam,LPARAM lParam); + int __cdecl OnContactDeleted(WPARAM wParam, LPARAM lParam); int __cdecl OnIdleChanged(WPARAM wParam, LPARAM lParam); int __cdecl OnGroupChange(WPARAM wParam, LPARAM lParam); int __cdecl OnModulesLoaded(WPARAM wParam, LPARAM lParam); - int __cdecl OnOptionsInit(WPARAM wParam,LPARAM lParam); - int __cdecl OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam); - int __cdecl OnPreShutdown(WPARAM wParam,LPARAM lParam); - int __cdecl OnContactDoubleClicked(WPARAM wParam,LPARAM lParam); - int __cdecl OnDbSettingChanged(WPARAM wParam,LPARAM lParam); + int __cdecl OnOptionsInit(WPARAM wParam, LPARAM lParam); + int __cdecl OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam); + int __cdecl OnPreShutdown(WPARAM wParam, LPARAM lParam); + int __cdecl OnContactDoubleClicked(WPARAM wParam, LPARAM lParam); + int __cdecl OnDbSettingChanged(WPARAM wParam, LPARAM lParam); int __cdecl OnWindowPopup(WPARAM wParam, LPARAM lParam); //====| Data |======================================================================== @@ -128,10 +122,6 @@ struct CMsnProto : public PROTO LIST m_arGCThreads; mir_cs m_csSessions; -#ifdef OBSOLETE - OBJLIST m_arSessions; - OBJLIST m_arDirect; -#endif mir_cs csMsgQueue; int msgQueueSeq; @@ -158,7 +148,7 @@ struct CMsnProto : public PROTO bool usingGateway; char* msnExternalIP; - char* msnRegistration; + char* msnRegistration; char* msnPreviousUUX; char* msnLastStatusMsg; @@ -203,26 +193,17 @@ struct CMsnProto : public PROTO void MSN_SetServerStatus(int newStatus); void MSN_FetchRecentMessages(time_t since = 0); void MSN_StartStopTyping(GCThreadData* info, bool start); - void MSN_SendTyping(ThreadData* info, const char* email, int netId, bool bTyping ); + void MSN_SendTyping(ThreadData* info, const char* email, int netId, bool bTyping); - void MSN_InitSB(ThreadData* info, const char* szEmail); void MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* params); int MSN_HandleCommands(ThreadData* info, char* cmdString); int MSN_HandleErrors(ThreadData* info, char* cmdString); void MSN_ProcessNotificationMessage(char* buf, size_t bufLen); void MSN_ProcessStatusMessage(ezxml_t xmli, const char* wlid); void MSN_ProcessNLN(const char *userStatus, const char *wlid, char *userNick, const char *objid, char *cmdstring); - void MSN_ProcessPage(char* buf, unsigned len); - void MSN_ProcessRemove(char* buf, size_t len); - void MSN_ProcessAdd(char* buf, size_t len); void MSN_ProcessYFind(char* buf, size_t len); - void MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli); - void MSN_CustomSmiley(const char* msgBody, char* email, char* nick, int iSmileyType); - void MSN_InviteMessage(ThreadData* info, char* msgBody, char* email, char* nick); -#ifdef OBSOLETE - void MSN_SetMirVer(MCONTACT hContact, DWORD dwValue, bool always); -#endif - void MSN_SetMirVer(MCONTACT hContact, MsnPlace *place); + void MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli); + void MSN_SetMirVer(MCONTACT hContact, MsnPlace *place); void LoadOptions(void); @@ -230,10 +211,6 @@ struct CMsnProto : public PROTO void MSN_ShowPopup(const wchar_t* nickname, const wchar_t* msg, int flags, const char* url); void MSN_ShowPopup(const MCONTACT hContact, const wchar_t* msg, int flags); void MSN_ShowError(const char* msgtext, ...); - -#ifdef OBSOLETE - void MSN_SetNicknameUtf(const char* nickname); -#endif void MSN_SendNicknameUtf(const char* nickname); typedef struct { wchar_t *szName; const char *szMimeType; unsigned char *data; size_t dataSize; } StoreAvatarData; @@ -263,8 +240,6 @@ struct CMsnProto : public PROTO INT_PTR __cdecl MsnSendHotmail(WPARAM wParam, LPARAM); INT_PTR __cdecl MsnEditProfile(WPARAM, LPARAM); INT_PTR __cdecl MsnInviteCommand(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl MsnSendNetMeeting(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl SetNicknameUI(WPARAM wParam, LPARAM lParam); INT_PTR __cdecl MsnViewProfile(WPARAM wParam, LPARAM lParam); INT_PTR __cdecl MsnSetupAlerts(WPARAM wParam, LPARAM lParam); @@ -284,8 +259,8 @@ struct CMsnProto : public PROTO void __cdecl MsnGetAwayMsgThread(void* arg); - void __cdecl p2p_sendFeedThread(void* arg ); - void __cdecl p2p_fileActiveThread(void* arg ); + void __cdecl p2p_sendFeedThread(void* arg); + void __cdecl p2p_fileActiveThread(void* arg); void __cdecl p2p_filePassiveThread(void* arg); void __cdecl MsgQueue_AllClearThread(void* arg); @@ -295,18 +270,9 @@ struct CMsnProto : public PROTO void Threads_Uninit(void); void MSN_CloseConnections(void); - int MSN_GetChatThreads(ThreadData** parResult); - int MSN_GetActiveThreads(ThreadData**); ThreadData* MSN_GetThreadByConnection(HANDLE hConn); - ThreadData* MSN_GetThreadByContact(const char* wlid, TInfoType type = SERVER_SWITCHBOARD); - GCThreadData*MSN_GetThreadByChatId(const wchar_t* chatId); - ThreadData* MSN_GetP2PThreadByContact(const char *wlid); - void MSN_StartP2PTransferByContact(const char* wlid); - ThreadData* MSN_GetThreadByPort(WORD wPort); - ThreadData* MSN_GetUnconnectedThread(const char* wlid, TInfoType type = SERVER_SWITCHBOARD); - ThreadData* MSN_GetOtherContactThread(ThreadData* thread); - - ThreadData* MSN_StartSB(const char* uid, bool& isOffline); + GCThreadData* MSN_GetThreadByChatId(const wchar_t* chatId); + void __cdecl ThreadStub(void* arg); ///////////////////////////////////////////////////////////////////////////////////////// @@ -327,90 +293,12 @@ struct CMsnProto : public PROTO OBJLIST msgCache; - int addCachedMsg(const char* id, const char* msg, const size_t offset, - const size_t portion, const size_t totsz, const bool bychunk); + int addCachedMsg(const char* id, const char* msg, const size_t offset, const size_t portion, const size_t totsz, const bool bychunk); size_t getCachedMsgSize(const char* id); - bool getCachedMsg(const int idx, char*& msg, size_t& size); - bool getCachedMsg(const char* id, char*& msg, size_t& size); - void clearCachedMsg(int idx = -1); - void CachedMsg_Uninit(void); - - ///////////////////////////////////////////////////////////////////////////////////////// - // MSN P2P session support - -#ifdef OBSOLETE - void p2p_clearDormantSessions(void); - void p2p_cancelAllSessions(void); - void p2p_redirectSessions(const char* wlid); - void p2p_startSessions(const char* wlid); - void p2p_clearThreadSessions(MCONTACT hContact, TInfoType mType); - - void p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid); - void p2p_inviteDc(filetransfer* ft, const char *wlid); - void p2p_processMsg(ThreadData* info, char* msgbody, const char* wlid); - void p2p_processMsgV2(ThreadData* info, char* msgbody, const char* wlid); - void p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdr, const char* wlid); - - void p2p_AcceptTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid); - void p2p_InitDirectTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid); - void p2p_InitDirectTransfer2(MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid); - void p2p_InitFileTransfer(ThreadData* info, MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid); - void p2p_pictureTransferFailed(filetransfer* ft); - void p2p_savePicture2disk(filetransfer* ft); - - bool p2p_createListener(filetransfer* ft, directconnection *dc, MimeHeaders& chdrs); - void p2p_startConnect(const char* wlid, const char* szCallID, const char* addr, const char* port, bool ipv6); - - void p2p_sendAbortSession(filetransfer* ft); - void p2p_sendAck(const char *wlid, P2PB_Header* hdrdata); - void p2p_sendAvatarInit(filetransfer* ft); - void p2p_sendBye(filetransfer* ft); - void p2p_sendCancel(filetransfer* ft); - void p2p_sendMsg(const char *wlid, unsigned appId, P2PB_Header& hdrdata, char* msgbody, size_t msgsz); - void p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId, P2PB_Header& hdrdata, char* msgbody, size_t msgsz); - void p2p_sendNoCall(filetransfer* ft); - void p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders, MimeHeaders &pContent, const char *wlid = NULL); - void p2p_sendRedirect(filetransfer* ft); - void p2p_sendStatus(filetransfer* ft, long lStatus); - - void p2p_sendFeedStart(filetransfer* ft); - LONG p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2); - void p2p_sendRecvFileDirectly(ThreadData* info); - bool p2p_connectTo(ThreadData* info, directconnection *dc); - bool p2p_listen(ThreadData* info, directconnection *dc); - - void p2p_registerSession(filetransfer* ft); - void p2p_unregisterSession(filetransfer* ft); - void p2p_sessionComplete(filetransfer* ft); - - void P2pSessions_Uninit(void); - - filetransfer* p2p_getAvatarSession(MCONTACT hContact); - filetransfer* p2p_getThreadSession(MCONTACT hContact, TInfoType mType); - filetransfer* p2p_getSessionByID(unsigned id); - filetransfer* p2p_getSessionByUniqueID(unsigned id); - filetransfer* p2p_getSessionByCallID(const char* CallID, const char* wlid); - - bool p2p_sessionRegistered(filetransfer* ft); - bool p2p_isAvatarOnly(MCONTACT hContact); - unsigned p2p_getMsgId(const char* wlid, int inc); - unsigned p2p_getPktNum(const char* wlid); - - void p2p_registerDC(directconnection* ft); - void p2p_unregisterDC(directconnection* dc); - directconnection* p2p_getDCByCallID(const char* CallID, const char* wlid); - - ///////////////////////////////////////////////////////////////////////////////////////// - // MSN MSNFTP file transfer - - void msnftp_invite(filetransfer *ft); - void msnftp_sendAcceptReject(filetransfer *ft, bool acc); - void msnftp_startFileSend(ThreadData* info, const char* Invcommand, const char* Invcookie); - - int MSN_HandleMSNFTP(ThreadData *info, char *cmdString); - - void __cdecl msnftp_sendFileThread(void* arg); -#endif + bool getCachedMsg(const int idx, char*& msg, size_t& size); + bool getCachedMsg(const char* id, char*& msg, size_t& size); + void clearCachedMsg(int idx = -1); + void CachedMsg_Uninit(void); ///////////////////////////////////////////////////////////////////////////////////////// // MSN Chat support @@ -455,11 +343,10 @@ struct CMsnProto : public PROTO void MSN_CreateContList(void); void MSN_CleanupLists(void); - void MSN_FindYahooUser(const char* email); bool MSN_RefreshContactList(void); bool MSN_IsMyContact(MCONTACT hContact); - bool MSN_IsMeByContact(MCONTACT hContact, char* szEmail = NULL); + bool MSN_IsMeByContact(MCONTACT hContact, char* szEmail = NULL); bool MSN_AddUser(MCONTACT hContact, const char* email, int netId, int flags, const char *msg = NULL); void MSN_AddAuthRequest(const char *email, const char *nick, const char *reason); void MSN_SetContactDb(MCONTACT hContact, const char *szEmail); @@ -560,13 +447,13 @@ struct CMsnProto : public PROTO bool MSN_ABAddRemoveContact(const char* szCntId, int netId, bool add, bool allowRecurse = true); unsigned MSN_ABContactAdd(const char* szEmail, const char* szNick, int netId, const char* szInvite, bool search, bool retry = false, bool allowRecurse = true); void MSN_ABUpdateDynamicItem(bool allowRecurse = true); - bool MSN_ABRefreshClist(unsigned int nTry=0); + bool MSN_ABRefreshClist(unsigned int nTry = 0); ezxml_t abSoapHdr(const char* service, const char* scenario, ezxml_t& tbdy, char*& httphdr); char* GetABHost(const char* service, bool isSharing); void SetAbParam(MCONTACT hContact, const char *name, const char *par); void UpdateABHost(const char* service, const char* url); - void UpdateABCacheKey(ezxml_t bdy, bool isSharing); + void UpdateABCacheKey(ezxml_t bdy, bool isSharing); ezxml_t getSoapResponse(ezxml_t bdy, const char* service); ezxml_t getSoapFault(ezxml_t bdy, bool err); diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp index 9f26f83ff9..db92c812bb 100644 --- a/protocols/MSN/src/msn_srv.cpp +++ b/protocols/MSN/src/msn_srv.cpp @@ -284,20 +284,9 @@ void CMsnProto::MSN_SendNicknameUtf(const char* nickname) else delSetting("Nick"); -#ifdef OBSOLETE - MSN_SetNicknameUtf(nickname[0] ? nickname : MyOptions.szEmail); -#endif - ForkThread(&CMsnProto::msn_storeProfileThread, (void*)1); } -#ifdef OBSOLETE -void CMsnProto::MSN_SetNicknameUtf(const char* nickname) -{ - msnNsThread->sendPacket("PRP", "MFN %s", ptrA(mir_urlEncode(nickname))); -} -#endif - ///////////////////////////////////////////////////////////////////////////////////////// // msn_storeAvatarThread - update our own avatar on the server diff --git a/protocols/MSN/src/msn_svcs.cpp b/protocols/MSN/src/msn_svcs.cpp index b0be81b0f1..aa745fa24a 100644 --- a/protocols/MSN/src/msn_svcs.cpp +++ b/protocols/MSN/src/msn_svcs.cpp @@ -133,19 +133,6 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) pushAvatarRequest(pai->hContact, dbv.pszVal); db_free(&dbv); } -#ifdef OBSOLETE - else if (p2p_getAvatarSession(pai->hContact) == NULL) { - filetransfer* ft = new filetransfer(this); - ft->std.hContact = pai->hContact; - ft->p2p_object = mir_strdup(szContext); - - MSN_GetAvatarFileName(pai->hContact, filename, _countof(filename), L"unk"); - ft->std.tszCurrentFile = mir_wstrdup(filename); - - p2p_invite(MSN_APPID_AVATAR, ft, NULL); - } -#endif - return GAIR_WAITFOR; } return GAIR_NOAVATAR; @@ -251,129 +238,9 @@ INT_PTR CMsnProto::SendNudge(WPARAM hContact, LPARAM) if (MSN_IsMeByContact(hContact, tEmail)) return 0; int netId = Lists_GetNetId(tEmail); - -#ifdef OBSOLETE - static const char nudgemsg[] = - "Content-Type: text/x-msnmsgr-datacast\r\n\r\n" - "ID: 1\r\n\r\n"; - - switch (netId) { - case NETID_UNKNOWN: - hContact = MSN_GetChatInernalHandle(hContact); - - 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); - } - } - break; - - case NETID_YAHOO: - msnNsThread->sendMessage('3', tEmail, netId, nudgemsg, MSG_DISABLE_HDR); - break; - - default: - break; - } -#else msnNsThread->sendMessage('3', tEmail, netId, "", MSG_NUDGE); -#endif - return 0; -} - -#ifdef OBSOLETE -///////////////////////////////////////////////////////////////////////////////////////// -// GetCurrentMedia - get current media - -INT_PTR CMsnProto::GetCurrentMedia(WPARAM, LPARAM lParam) -{ - LISTENINGTOINFO *cm = (LISTENINGTOINFO *)lParam; - - if (cm == NULL || cm->cbSize != sizeof(LISTENINGTOINFO)) - return -1; - - cm->ptszArtist = mir_wstrdup(msnCurrentMedia.ptszArtist); - cm->ptszAlbum = mir_wstrdup(msnCurrentMedia.ptszAlbum); - cm->ptszTitle = mir_wstrdup(msnCurrentMedia.ptszTitle); - cm->ptszTrack = mir_wstrdup(msnCurrentMedia.ptszTrack); - cm->ptszYear = mir_wstrdup(msnCurrentMedia.ptszYear); - cm->ptszGenre = mir_wstrdup(msnCurrentMedia.ptszGenre); - cm->ptszLength = mir_wstrdup(msnCurrentMedia.ptszLength); - cm->ptszPlayer = mir_wstrdup(msnCurrentMedia.ptszPlayer); - cm->ptszType = mir_wstrdup(msnCurrentMedia.ptszType); - cm->dwFlags = msnCurrentMedia.dwFlags; - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// SetCurrentMedia - set current media - -INT_PTR CMsnProto::SetCurrentMedia(WPARAM, LPARAM lParam) -{ - // Clear old info - mir_free(msnCurrentMedia.ptszArtist); - mir_free(msnCurrentMedia.ptszAlbum); - mir_free(msnCurrentMedia.ptszTitle); - mir_free(msnCurrentMedia.ptszTrack); - mir_free(msnCurrentMedia.ptszYear); - mir_free(msnCurrentMedia.ptszGenre); - mir_free(msnCurrentMedia.ptszLength); - mir_free(msnCurrentMedia.ptszPlayer); - mir_free(msnCurrentMedia.ptszType); - memset(&msnCurrentMedia, 0, sizeof(msnCurrentMedia)); - - // Copy new info - LISTENINGTOINFO *cm = (LISTENINGTOINFO *)lParam; - 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 - msnCurrentMedia.dwFlags = LTI_TCHAR; - - overrideStr(msnCurrentMedia.ptszType, cm->ptszType, unicode, L"Music"); - overrideStr(msnCurrentMedia.ptszArtist, cm->ptszArtist, unicode); - overrideStr(msnCurrentMedia.ptszAlbum, cm->ptszAlbum, unicode); - overrideStr(msnCurrentMedia.ptszTitle, cm->ptszTitle, unicode, L"No Title"); - overrideStr(msnCurrentMedia.ptszTrack, cm->ptszTrack, unicode); - overrideStr(msnCurrentMedia.ptszYear, cm->ptszYear, unicode); - overrideStr(msnCurrentMedia.ptszGenre, cm->ptszGenre, unicode); - overrideStr(msnCurrentMedia.ptszLength, cm->ptszLength, unicode); - overrideStr(msnCurrentMedia.ptszPlayer, cm->ptszPlayer, unicode); - } - - // Set user text - if (msnCurrentMedia.cbSize == 0) - delSetting("ListeningTo"); - else { - wchar_t *text; - if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)) - text = (wchar_t *)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)L"%title% - %artist%", (LPARAM)&msnCurrentMedia); - else { - text = (wchar_t *)mir_alloc(128 * sizeof(wchar_t)); - mir_snwprintf(text, 128, L"%s - %s", (msnCurrentMedia.ptszTitle ? msnCurrentMedia.ptszTitle : L""), - (msnCurrentMedia.ptszArtist ? msnCurrentMedia.ptszArtist : L"")); - } - setWString("ListeningTo", text); - mir_free(text); - } - - // Send it - char** msgptr = GetStatusMsgLoc(m_iDesiredStatus); - MSN_SendStatusMessage(msgptr ? *msgptr : NULL); - return 0; } -#endif ///////////////////////////////////////////////////////////////////////////////////////// // MsnContactDeleted - called when a contact is deleted from list diff --git a/protocols/MSN/src/msn_switchboard.cpp b/protocols/MSN/src/msn_switchboard.cpp index f6e6664edd..fec422f88f 100644 --- a/protocols/MSN/src/msn_switchboard.cpp +++ b/protocols/MSN/src/msn_switchboard.cpp @@ -22,32 +22,6 @@ along with this program. If not, see . #include "stdafx.h" #include "msn_proto.h" -#ifdef OBSOLETE - -int ThreadData::contactJoined(const char* email) -{ - for (int i = 0; i < mJoinedContactsWLID.getCount(); i++) - if (_stricmp(mJoinedContactsWLID[i], email) == 0) - return mJoinedContactsWLID.getCount(); - - if (strchr(email, ';')) - mJoinedIdentContactsWLID.insertn(email); - else - mJoinedContactsWLID.insertn(email); - - return mJoinedContactsWLID.getCount(); -} - -int ThreadData::contactLeft(const char* email) -{ - if (strchr(email, ';')) - mJoinedIdentContactsWLID.remove(email); - else - mJoinedContactsWLID.remove(email); - - return mJoinedContactsWLID.getCount(); -} -#endif MCONTACT ThreadData::getContactHandle(void) { diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp index a7a65ec54e..27a6a4d64a 100644 --- a/protocols/MSN/src/msn_threads.cpp +++ b/protocols/MSN/src/msn_threads.cpp @@ -42,23 +42,28 @@ void __cdecl CMsnProto::msn_keepAliveThread(void*) msnPingTimeout = 45; else { msnPingTimeout = 20; - keepFlag = keepFlag && (lastMsgId?msnNsThread->sendPacketPayload("PNG", "CON", "\bLast-Msg-Id: %I64u\r\n\r\n", lastMsgId): - (msnRegistration?msnNsThread->sendPacketPayload("PNG", "CON", "\b\r\n"): - msnNsThread->sendPacket("PNG", "CON 0"))); + + if (msnNsThread) { + if (lastMsgId) + keepFlag = msnNsThread->sendPacketPayload("PNG", "CON", "\bLast-Msg-Id: %I64u\r\n\r\n", lastMsgId); + else if (msnRegistration) + keepFlag = msnNsThread->sendPacketPayload("PNG", "CON", "\b\r\n"); + else + keepFlag = msnNsThread->sendPacket("PNG", "CON 0"); + } } -#ifdef OBSOLETE - p2p_clearDormantSessions(); -#endif + if (hHttpsConnection && (clock() - mHttpsTS) > 60 * CLOCKS_PER_SEC) { HNETLIBCONN hConn = hHttpsConnection; hHttpsConnection = NULL; Netlib_Shutdown(hConn); } + if (mStatusMsgTS && (clock() - mStatusMsgTS) > 60 * CLOCKS_PER_SEC) { mStatusMsgTS = 0; ForkThread(&CMsnProto::msn_storeProfileThread, NULL); } - if (MyOptions.netId!=NETID_SKYPE && MSN_RefreshOAuthTokens(true)) + if (keepFlag && MyOptions.netId != NETID_SKYPE && MSN_RefreshOAuthTokens(true)) ForkThread(&CMsnProto::msn_refreshOAuthThread, msnNsThread); break; @@ -94,13 +99,13 @@ void __cdecl CMsnProto::msn_refreshOAuthThread(void *param) static bool ReallocInfoBuffer(ThreadData *info, size_t mDataSize) { - char *mData = (char*)mir_realloc(info->mData, mDataSize+1); + char *mData = (char*)mir_realloc(info->mData, mDataSize + 1); if (mData == NULL) return false; info->mData = mData; info->mDataSize = mDataSize; - ZeroMemory(&mData[info->mBytesInData], info->mDataSize-info->mBytesInData+1); + ZeroMemory(&mData[info->mBytesInData], info->mDataSize - info->mBytesInData + 1); return true; } @@ -168,10 +173,6 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) case SERVER_NOTIFICATION: goto LBL_Exit; break; - - case SERVER_SWITCHBOARD: - if (info->mCaller) msnNsThread->sendPacket("XFR", "SB"); - break; } return; } @@ -181,19 +182,12 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) debugLogA("Connected with handle=%08X", info->s); - if (info->mType == SERVER_NOTIFICATION) + if (info->mType == SERVER_NOTIFICATION) info->sendPacketPayload("CNT", "CON", "%s%s%s2winnt5.2x86en-us\r\n", - *info->mState?"":"", *info->mState?info->mState:"", *info->mState?"":""); - 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) { - info->send("VER MSNFTP\r\n", 12); - } + *info->mState ? "" : "", *info->mState ? info->mState : "", *info->mState ? "" : ""); - if (info->mIsMainThread) { + if (info->mIsMainThread) msnNsThread = info; - } debugLogA("Entering main recv loop"); info->mBytesInData = 0; @@ -211,62 +205,46 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) info->mBytesInData += recvResult; -#ifdef OBSOLETE - if (info->mCaller == 1 && info->mType == SERVER_FILETRANS) { - if (MSN_HandleMSNFTP(info, info->mData)) + for (;;) { + char* peol = strchr(info->mData, '\r'); + if (peol == NULL) break; - } - else -#endif - { - for (;;) { - char* peol = strchr(info->mData, '\r'); - if (peol == NULL) - break; - - int msgLen = (int)(peol - info->mData); - if (info->mBytesInData < msgLen + 2) - break; //wait for full line end - - char msg[1024]; - strncpy_s(msg, info->mData, msgLen); - - if (*++peol != '\n') - debugLogA("Dodgy line ending to command: ignoring"); - else - peol++; - - info->mBytesInData -= peol - info->mData; - memmove(info->mData, peol, info->mBytesInData); - debugLogA("RECV: %s", msg); - - if (!isalnum(msg[0]) || !isalnum(msg[1]) || !isalnum(msg[2]) || (msg[3] && msg[3] != ' ')) { - debugLogA("Invalid command name"); - continue; - } - 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); + int msgLen = (int)(peol - info->mData); + if (info->mBytesInData < msgLen + 2) + break; //wait for full line end - if (handlerResult) { - if (info->sessionClosed) goto LBL_Exit; - info->sendTerminate(); - } - } -#ifdef OBSOLETE - else - if (MSN_HandleMSNFTP(info, msg)) - goto LBL_Exit; -#endif + char msg[1024]; + strncpy_s(msg, info->mData, msgLen); + + if (*++peol != '\n') + debugLogA("Dodgy line ending to command: ignoring"); + else + peol++; + + info->mBytesInData -= peol - info->mData; + memmove(info->mData, peol, info->mBytesInData); + debugLogA("RECV: %s", msg); + + if (!isalnum(msg[0]) || !isalnum(msg[1]) || !isalnum(msg[2]) || (msg[3] && msg[3] != ' ')) { + debugLogA("Invalid command name"); + continue; + } + + 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 (info->sessionClosed) goto LBL_Exit; + info->sendTerminate(); } } if (info->mBytesInData == info->mDataSize) { - if (!ReallocInfoBuffer(info, info->mDataSize*2)) { + if (!ReallocInfoBuffer(info, info->mDataSize * 2)) { debugLogA("sizeof(data) is too small: the longest line won't fit"); break; } @@ -294,12 +272,8 @@ LBL_Exit: if (info->s == NULL) ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK); - else { -#ifdef OBSOLETE - p2p_cancelAllSessions(); -#endif + else MSN_CloseConnections(); - } if (hHttpsConnection) { Netlib_CloseHandle(hHttpsConnection); @@ -325,7 +299,6 @@ void CMsnProto::MSN_CloseConnections(void) switch (T.mType) { case SERVER_NOTIFICATION: - case SERVER_SWITCHBOARD: if (T.s != NULL && !T.sessionClosed && !T.termPending) { nls.hReadConns[0] = T.s; int res = Netlib_SelectEx(&nls); @@ -333,10 +306,6 @@ void CMsnProto::MSN_CloseConnections(void) T.sendTerminate(); } break; - - case SERVER_P2P_DIRECT: - Netlib_Shutdown(T.s); - break; } } @@ -352,36 +321,6 @@ void CMsnProto::Threads_Uninit(void) m_arThreads.destroy(); } -ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type) -{ - mir_cslock lck(m_csThreads); - - if (type == SERVER_P2P_DIRECT) { - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - if (T.mType != SERVER_P2P_DIRECT || !T.mJoinedIdentContactsWLID.getCount() || T.s == NULL) - continue; - - if (_stricmp(T.mJoinedIdentContactsWLID[0], wlid) == 0) - return &T; - } - } - - char *szEmail = NULL; - parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - if (T.mType != type || !T.mJoinedContactsWLID.getCount() || T.mInitialContactWLID || T.s == NULL) - continue; - - if (_stricmp(T.mJoinedContactsWLID[0], szEmail) == 0 && T.mChatID[0] == 0) - return &T; - } - - return NULL; -} - GCThreadData* CMsnProto::MSN_GetThreadByChatId(const wchar_t* chatId) { if (mir_wstrlen(chatId) == 0) @@ -397,122 +336,6 @@ GCThreadData* CMsnProto::MSN_GetThreadByChatId(const wchar_t* chatId) return NULL; } -#ifdef OBSOLETE -ThreadData* CMsnProto::MSN_GetP2PThreadByContact(const char *wlid) -{ - mir_cslock lck(m_csThreads); - - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - if (T.mType != SERVER_P2P_DIRECT || !T.mJoinedIdentContactsWLID.getCount()) - continue; - - if (_stricmp(T.mJoinedIdentContactsWLID[0], wlid) == 0) - return &T; - } - - char *szEmail = NULL; - parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - - ThreadData *result = NULL; - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - if (T.mJoinedContactsWLID.getCount() && !T.mInitialContactWLID && - _stricmp(T.mJoinedContactsWLID[0], szEmail) == 0) { - if (T.mType == SERVER_P2P_DIRECT) - return &T; - - if (T.mType == SERVER_SWITCHBOARD) - result = &T; - } - } - - return result; -} - - -void CMsnProto::MSN_StartP2PTransferByContact(const char* wlid) -{ - mir_cslock lck(m_csThreads); - - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - 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))) - ReleaseSemaphore(T.hWaitEvent, 1, NULL); - } - } -} - -ThreadData* CMsnProto::MSN_GetOtherContactThread(ThreadData* thread) -{ - mir_cslock lck(m_csThreads); - - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - if (T.mJoinedContactsWLID.getCount() == 0 || T.s == NULL) - continue; - - if (&T != thread && _stricmp(T.mJoinedContactsWLID[0], thread->mJoinedContactsWLID[0]) == 0) - return &T; - } - - return NULL; -} - -ThreadData* CMsnProto::MSN_GetUnconnectedThread(const char* wlid, TInfoType type) -{ - mir_cslock lck(m_csThreads); - - char* szEmail = (char*)wlid; - - if (type == SERVER_SWITCHBOARD && strchr(wlid, ';')) - parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL); - - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - if (T.mType == type && T.mInitialContactWLID && _stricmp(T.mInitialContactWLID, szEmail) == 0) - return &T; - } - - return NULL; -} - - -ThreadData* CMsnProto::MSN_StartSB(const char* wlid, bool& isOffline) -{ - isOffline = false; - ThreadData *thread = MSN_GetThreadByContact(wlid); - if (thread == NULL) { - MCONTACT hContact = MSN_HContactFromEmail(wlid); - WORD wStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE); - if (wStatus != ID_STATUS_OFFLINE) { - if (MSN_GetUnconnectedThread(wlid) == NULL && MsgQueue_CheckContact(wlid, 5) == NULL) - msnNsThread->sendPacket("XFR", "SB"); - } - else isOffline = true; - } - return thread; -} - - -int CMsnProto::MSN_GetActiveThreads(ThreadData** parResult) -{ - int tCount = 0; - mir_cslock lck(m_csThreads); - - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - if (T.mType == SERVER_SWITCHBOARD && T.mJoinedContactsWLID.getCount() != 0 && T.mJoinedContactsWLID.getCount()) - parResult[tCount++] = &T; - } - - return tCount; -} -#endif - ThreadData* CMsnProto::MSN_GetThreadByConnection(HANDLE s) { mir_cslock lck(m_csThreads); @@ -526,21 +349,6 @@ ThreadData* CMsnProto::MSN_GetThreadByConnection(HANDLE s) return NULL; } -#ifdef OBSOLETE -ThreadData* CMsnProto::MSN_GetThreadByPort(WORD wPort) -{ - mir_cslock lck(m_csThreads); - - for (int i = 0; i < m_arThreads.getCount(); i++) { - ThreadData &T = m_arThreads[i]; - if (T.mIncomingPort == wPort) - return &T; - } - - return NULL; -} -#endif - ///////////////////////////////////////////////////////////////////////////////////////// // class ThreadData members @@ -550,7 +358,7 @@ ThreadData::ThreadData() mGatewayTimeout = 2; resetTimeout(); hWaitEvent = CreateSemaphore(NULL, 0, MSN_PACKETS_COMBINE, NULL); - mData = (char*)mir_calloc((mDataSize=8192)+1); + mData = (char*)mir_calloc((mDataSize = 8192) + 1); } ThreadData::~ThreadData() @@ -575,36 +383,10 @@ ThreadData::~ThreadData() if (mTimerId != 0) KillTimer(NULL, mTimerId); -#ifdef OBSOLETE - if (mType == SERVER_SWITCHBOARD) { - for (int i = 0; i < mJoinedContactsWLID.getCount(); ++i) { - const char* wlid = mJoinedContactsWLID[i]; - MCONTACT hContact = proto->MSN_HContactFromEmail(wlid); - int temp_status = proto->getWord(hContact, "Status", ID_STATUS_OFFLINE); - if (temp_status == ID_STATUS_INVISIBLE && proto->MSN_GetThreadByContact(wlid) == NULL) - proto->setWord(hContact, "Status", ID_STATUS_OFFLINE); - } - } -#endif - mJoinedContactsWLID.destroy(); mJoinedIdentContactsWLID.destroy(); mir_free(mInitialContactWLID); mInitialContactWLID = NULL; - -#ifdef OBSOLETE - const char* wlid = NEWSTR_ALLOCA(mInitialContactWLID); - - 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) { - proto->MsgQueue_Clear(wlid, true); - } -#endif - mir_free(mData); } @@ -727,7 +509,7 @@ BYTE* HReadBuffer::surelyRead(size_t parBytes) if (parBytes > owner->mDataSize) { size_t mDataSize = owner->mDataSize; - while (parBytes > mDataSize) mDataSize*=2; + while (parBytes > mDataSize) mDataSize *= 2; if (!ReallocInfoBuffer(owner, mDataSize)) { owner->proto->debugLogA("HReadBuffer::surelyRead: not enough memory, %d %d %d", parBytes, owner->mDataSize, startOffset); return NULL; @@ -736,7 +518,7 @@ BYTE* HReadBuffer::surelyRead(size_t parBytes) } } - while ((startOffset + parBytes) > totalDataSize) { + while ((startOffset + parBytes) > totalDataSize) { int recvResult = owner->recv((char*)buffer + totalDataSize, owner->mDataSize - totalDataSize); if (recvResult <= 0) @@ -754,7 +536,7 @@ BYTE* HReadBuffer::surelyRead(size_t parBytes) // class GCThreadData members GCThreadData::GCThreadData() : -mJoinedContacts(10, PtrKeySortT) + mJoinedContacts(10, PtrKeySortT) { memset(&mCreator, 0, sizeof(GCThreadData) - sizeof(mJoinedContacts)); } @@ -762,4 +544,3 @@ mJoinedContacts(10, PtrKeySortT) GCThreadData::~GCThreadData() { } - diff --git a/protocols/MSN/src/msn_ws.cpp b/protocols/MSN/src/msn_ws.cpp index c82c660e8f..87920c1723 100644 --- a/protocols/MSN/src/msn_ws.cpp +++ b/protocols/MSN/src/msn_ws.cpp @@ -29,7 +29,7 @@ int ThreadData::send(const char data[], size_t datalen) { resetTimeout(); - if (proto->usingGateway && !(mType == SERVER_FILETRANS || mType == SERVER_P2P_DIRECT)) { + if (proto->usingGateway) { mGatewayTimeout = 2; Netlib_SetPollingTimeout(s, mGatewayTimeout); } @@ -52,59 +52,21 @@ void ThreadData::resetTimeout(bool term) bool ThreadData::isTimeout(void) { - bool res = false; + if (mWaitPeriod >= clock()) + return false; - if (mWaitPeriod >= clock()) return false; - - if (mIsMainThread) { + bool res = false; + if (mIsMainThread) res = !proto->usingGateway; - } - else if (mJoinedContactsWLID.getCount() <= 1 || mChatID[0] == 0) { -#ifdef OBSOLETE - MCONTACT hContact = getContactHandle(); -#endif - if (mJoinedContactsWLID.getCount() == 0 || termPending) - res = true; -#ifdef OBSOLETE - else if (proto->p2p_getThreadSession(hContact, mType) != NULL) - res = false; - else if (mType == SERVER_SWITCHBOARD) { - res = MSN_MsgWndExist(hContact); - 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; - } - } -#endif - else - res = true; - } + else if (mJoinedContactsWLID.getCount() <= 1 || mChatID[0] == 0) + res = true; if (res) { - bool sbsess = mType == SERVER_SWITCHBOARD; - - proto->debugLogA("Dropping the idle %s due to inactivity", sbsess ? "switchboard" : "p2p"); - if (!sbsess || termPending) return true; - -#ifdef OBSOLETE - if (proto->getByte("EnableSessionPopup", 0)) { - MCONTACT hContact = NULL; - if (mJoinedContactsWLID.getCount()) - hContact = proto->MSN_HContactFromEmail(mJoinedContactsWLID[0]); - else if (mInitialContactWLID) - hContact = proto->MSN_HContactFromEmail(mInitialContactWLID); - - if (hContact) - proto->MSN_ShowPopup(hContact, TranslateT("Chat session dropped due to inactivity"), 0); - } - - sendTerminate(); - resetTimeout(true); -#endif + proto->debugLogA("Dropping the idle p2p due to inactivity"); + if (termPending) + return true; } - else - resetTimeout(); + else resetTimeout(); return false; } diff --git a/protocols/MSN/src/stdafx.h b/protocols/MSN/src/stdafx.h index 449d947bb3..37d0bae992 100644 --- a/protocols/MSN/src/stdafx.h +++ b/protocols/MSN/src/stdafx.h @@ -180,68 +180,63 @@ const char MSN_DEFAULT_LOGIN_SERVER[] = "s.gateway.messenger.live.com"; const char MSN_DEFAULT_GATEWAY[] = "geo.gateway.messenger.live.com"; const char MSN_USER_AGENT[] = NETLIB_USER_AGENT; -#define MSN_BLOCK "/BlockCommand" -#define MSN_INVITE "/InviteCommand" -#define MSN_NETMEETING "/NetMeeting" -#define MSN_VIEW_PROFILE "/ViewProfile" +#define MSN_BLOCK "/BlockCommand" +#define MSN_INVITE "/InviteCommand" +#define MSN_VIEW_PROFILE "/ViewProfile" -#define MS_GOTO_INBOX "/GotoInbox" -#define MS_EDIT_PROFILE "/EditProfile" -#define MS_EDIT_ALERTS "/EditAlerts" -#define MS_SET_NICKNAME_UI "/SetNicknameUI" - -extern const char sttVoidUid[]; +#define MS_GOTO_INBOX "/GotoInbox" +#define MS_EDIT_PROFILE "/EditProfile" +#define MS_EDIT_ALERTS "/EditAlerts" +#define MS_SET_NICKNAME_UI "/SetNicknameUI" ///////////////////////////////////////////////////////////////////////////////////////// // MSN plugin functions struct CMsnProto; -#define MSN_ALLOW_MSGBOX 1 -#define MSN_ALLOW_ENTER 2 -#define MSN_HOTMAIL_POPUP 4 -#define MSN_SHOW_ERROR 8 -#define MSN_ALERT_POPUP 16 +#define MSN_ALLOW_MSGBOX 1 +#define MSN_ALLOW_ENTER 2 +#define MSN_HOTMAIL_POPUP 4 +#define MSN_SHOW_ERROR 8 +#define MSN_ALERT_POPUP 16 -void HtmlDecode(char* str); -char* HtmlEncode(const char* str); -bool txtParseParam (const char* szData, const char* presearch, const char* start, const char* finish, char* param, const int size); -void stripBBCode(char* src); -void stripColorCode(char* src); -void stripHTML(char* str); -void parseWLID(char* wlid, char** net, char** email, char** inst); +void HtmlDecode(char* str); +char* HtmlEncode(const char* str); +bool txtParseParam (const char* szData, const char* presearch, const char* start, const char* finish, char* param, const int size); +void stripBBCode(char* src); +void stripColorCode(char* src); +void stripHTML(char* str); +void parseWLID(char* wlid, char** net, char** email, char** inst); -char* GetGlobalIp(void); +char* GetGlobalIp(void); template void UrlDecode(chartype* str); -void __cdecl MSN_ConnectionProc(HANDLE hNewConnection, DWORD dwRemoteIP, void*); - -char* MSN_GetAvatarHash(char* szContext, char** pszUrl = NULL); -bool MSN_MsgWndExist(MCONTACT hContact); +char* MSN_GetAvatarHash(char* szContext, char** pszUrl = NULL); +bool MSN_MsgWndExist(MCONTACT hContact); -#define MSN_SendNickname(a) MSN_SendNicknameUtf(UTF8(a)) +#define MSN_SendNickname(a) MSN_SendNicknameUtf(UTF8(a)) -unsigned MSN_GenRandom(void); +unsigned MSN_GenRandom(void); -void MSN_InitContactMenu(void); -void MSN_RemoveContactMenus(void); +void MSN_InitContactMenu(void); +void MSN_RemoveContactMenus(void); -HANDLE GetIconHandle(int iconId); -HICON LoadIconEx(const char* name, bool big = false); -void ReleaseIconEx(const char* name, bool big = false); +HANDLE GetIconHandle(int iconId); +HICON LoadIconEx(const char* name, bool big = false); +void ReleaseIconEx(const char* name, bool big = false); -void MsnInitIcons(void); +void MsnInitIcons(void); -int sttDivideWords(char* parBuffer, int parMinItems, char** parDest); +int sttDivideWords(char* parBuffer, int parMinItems, char** parDest); void MSN_MakeDigest(const char* chl, char* dgst); char* getNewUuid(void); -time_t IsoToUnixTime(const char *stamp); -time_t MsnTSToUnixtime(const char *pszTS); +time_t IsoToUnixTime(const char *stamp); +time_t MsnTSToUnixtime(const char *pszTS); wchar_t* EscapeChatTags(const wchar_t* pszText); -void overrideStr(wchar_t*& dest, const wchar_t* src, bool unicode, const wchar_t* def = NULL); +void overrideStr(wchar_t*& dest, const wchar_t* src, bool unicode, const wchar_t* def = NULL); char* arrayToHex(BYTE* data, size_t datasz); @@ -263,14 +258,14 @@ inline unsigned __int64 _htonl64(unsigned __int64 s) ///////////////////////////////////////////////////////////////////////////////////////// // Popup interface -typedef struct _tag_PopupData +struct PopupData { unsigned flags; char* url; wchar_t* title; wchar_t* text; CMsnProto* proto; -} PopupData; +}; struct STRLIST : public LIST { @@ -368,14 +363,9 @@ struct HReadBuffer enum TInfoType { SERVER_NOTIFICATION, - SERVER_SWITCHBOARD, - SERVER_FILETRANS, - SERVER_P2P_DIRECT, SERVER_HTTP }; - - struct filetransfer { filetransfer(CMsnProto* prt); @@ -570,13 +560,13 @@ struct ThreadData TInfoType mType; // thread type MsnThreadFunc mFunc; // thread entry point char mServer[80]; // server name - char mState[128]; // state on XFR + char mState[128]; // state on XFR HNETLIBCONN s; // NetLib connection for the thread HANDLE mIncomingBoundPort; // Netlib listen for the thread HANDLE hWaitEvent; WORD mIncomingPort; - wchar_t mChatID[10]; + wchar_t mChatID[10]; bool mIsMainThread; clock_t mWaitPeriod; @@ -603,7 +593,7 @@ struct ThreadData //----| internal data buffer |-------------------------------------------------------- int mBytesInData; // bytes available in data buffer - char *mData; // data buffer for connection + char *mData; // data buffer for connection size_t mDataSize; //----| methods |--------------------------------------------------------------------- @@ -619,18 +609,14 @@ struct ThreadData bool isTimeout(void); void sendTerminate(void); - void sendCaps(void); int sendMessage(int msgType, const char* email, int netId, const char* msg, int parFlags); int sendRawMessage(int msgType, const char* data, int datLen); int sendPacket(const char* cmd, const char* fmt, ...); - int sendPacketPayload(const char* cmd, const char *param, const char* fmt, ...); + int sendPacketPayload(const char* cmd, const char *param, const char* fmt, ...); - int contactJoined(const char* email); - int contactLeft(const char* email); MCONTACT getContactHandle(void); }; - ///////////////////////////////////////////////////////////////////////////////////////// // MSN P2P session support @@ -709,12 +695,10 @@ public: const char *Token(); __forceinline operator char*() const { return m_pszToken; } void SetToken(const char *pszToken, time_t tExpires); - //__forceinline const char *RefreshToken() { return m_pszRefreshToken; } protected: const char *m_pszTokenName; char *m_pszToken; - //char *m_pszRefreshToken; time_t m_tExpires; CMsnProto* m_proto; }; @@ -723,7 +707,7 @@ class OAuthToken : public GenericToken { public: OAuthToken(const char *pszTokenName, const char *pszService, bool bPreprendT = false); - bool Refresh(bool bForce = false); + virtual bool Refresh(bool bForce = false) override; private: const char *m_pszService; @@ -733,7 +717,7 @@ private: class SkypeToken : public GenericToken { public: SkypeToken(const char *pszTokenName); - bool Refresh(bool bForce = false); + virtual bool Refresh(bool bForce = false) override; const char *XSkypetoken(); }; diff --git a/protocols/MSN/src/version.h b/protocols/MSN/src/version.h index 597dbd6529..c4276023ca 100644 --- a/protocols/MSN/src/version.h +++ b/protocols/MSN/src/version.h @@ -19,9 +19,9 @@ along with this program. If not, see . */ #define __MAJOR_VERSION 0 -#define __MINOR_VERSION 12 -#define __RELEASE_NUM 1 -#define __BUILD_NUM 5 +#define __MINOR_VERSION 14 +#define __RELEASE_NUM 0 +#define __BUILD_NUM 1 #include -- cgit v1.2.3