From 2c54d6e129aa0810010d1a2c004e63057b80fbf8 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Wed, 4 Nov 2015 22:42:01 +0000 Subject: MSN: - minor cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@15686 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/MSN/src/msn.cpp | 14 ------- protocols/MSN/src/msn_auth.cpp | 78 ++++++++++++++++++-------------------- protocols/MSN/src/msn_commands.cpp | 15 ++++---- protocols/MSN/src/msn_menu.cpp | 25 ++---------- protocols/MSN/src/msn_misc.cpp | 63 +++++++----------------------- protocols/MSN/src/msn_proto.cpp | 63 ++++++------------------------ protocols/MSN/src/msn_ssl.cpp | 7 ++-- protocols/MSN/src/msn_threads.cpp | 18 ++++----- protocols/MSN/src/stdafx.h | 26 ++++++++----- 9 files changed, 98 insertions(+), 211 deletions(-) (limited to 'protocols/MSN') diff --git a/protocols/MSN/src/msn.cpp b/protocols/MSN/src/msn.cpp index 909ed04d9c..3e0c3f2005 100644 --- a/protocols/MSN/src/msn.cpp +++ b/protocols/MSN/src/msn.cpp @@ -58,7 +58,6 @@ static const PLUGININFOEX pluginInfo = int MSN_GCEventHook(WPARAM wParam, LPARAM lParam); int MSN_GCMenuHook(WPARAM wParam, LPARAM lParam); -///////////////////////////////////////////////////////////////////////////// // Protocol instances static int sttCompareProtocols(const CMsnProto *p1, const CMsnProto *p2) { @@ -67,9 +66,7 @@ static int sttCompareProtocols(const CMsnProto *p1, const CMsnProto *p2) OBJLIST g_Instances(1, sttCompareProtocols); -///////////////////////////////////////////////////////////////////////////////////////// // Main DLL function - extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID) { if (fdwReason == DLL_PROCESS_ATTACH) { @@ -79,9 +76,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID) return TRUE; } -///////////////////////////////////////////////////////////////////////////////////////// // OnModulesLoaded - finalizes plugin's configuration on load - static int OnModulesLoaded(WPARAM, LPARAM) { avsPresent = ServiceExists(MS_AV_SETMYAVATART) != 0; @@ -104,10 +99,7 @@ static int msnProtoUninit(CMsnProto* ppro) return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// // Performs a primary set of actions upon plugin loading - extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); @@ -128,9 +120,7 @@ extern "C" int __declspec(dllexport) Load(void) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // Unload a plugin - extern "C" int __declspec(dllexport) Unload(void) { MSN_RemoveContactMenus(); @@ -138,15 +128,11 @@ extern "C" int __declspec(dllexport) Unload(void) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MirandaPluginInfoEx - returns an information about a plugin - extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD) { return &pluginInfo; } -///////////////////////////////////////////////////////////////////////////////////////// // MirandaInterfaces - returns the protocol interface to the core - extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp index 0f8ba306e9..e08b456ef9 100644 --- a/protocols/MSN/src/msn_auth.cpp +++ b/protocols/MSN/src/msn_auth.cpp @@ -257,7 +257,6 @@ SkypeToken::SkypeToken(const char *pszTokenName): bool SkypeToken::Refresh(bool bForce) { NETLIBHTTPREQUEST nlhr = { 0 }; - NETLIBHTTPREQUEST *nlhrReply; NETLIBHTTPHEADER headers[1]; char szPOST[2048], szToken[1024]; bool bRet = false; @@ -276,11 +275,11 @@ bool SkypeToken::Refresh(bool bForce) if (m_proto->MyOptions.netId == NETID_SKYPE) { BYTE digest[16]; - int cbPasswd; char szPassword[100]={0}; - cbPasswd=mir_snprintf(szPassword, sizeof(szPassword), "%s\nskyper\n", m_proto->MyOptions.szEmail); - db_get_static(NULL, m_proto->m_szModuleName, "Password", szPassword+cbPasswd, sizeof(szPassword)-cbPasswd-1); + 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"; @@ -294,7 +293,7 @@ bool SkypeToken::Refresh(bool bForce) } m_proto->mHttpsTS = clock(); - nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_proto->hNetlibUserHttps, (LPARAM)&nlhr); + NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_proto->hNetlibUserHttps, (LPARAM)&nlhr); m_proto->mHttpsTS = clock(); if (nlhrReply) { @@ -334,10 +333,7 @@ const char *SkypeToken::XSkypetoken() } return NULL; } - -///////////////////////////////////////////////////////////////////////////////////////// // Performs the MSN Passport login via TLS - int CMsnProto::MSN_GetPassportAuth(void) { int retVal = -1; @@ -349,7 +345,9 @@ int CMsnProto::MSN_GetPassportAuth(void) } char szPassword[100]; - db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword)); + if (db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword))) + return 0; + szPassword[16] = 0; time_t ts = time(NULL); @@ -518,10 +516,8 @@ int CMsnProto::MSN_GetPassportAuth(void) static void derive_key(BYTE* der, unsigned char* key, size_t keylen, unsigned char* data, size_t datalen) { - BYTE hash1[MIR_SHA1_HASH_SIZE]; - BYTE hash2[MIR_SHA1_HASH_SIZE]; - BYTE hash3[MIR_SHA1_HASH_SIZE]; - BYTE hash4[MIR_SHA1_HASH_SIZE]; + BYTE hash1[MIR_SHA1_HASH_SIZE], hash2[MIR_SHA1_HASH_SIZE], + hash3[MIR_SHA1_HASH_SIZE], hash4[MIR_SHA1_HASH_SIZE]; const size_t buflen = MIR_SHA1_HASH_SIZE + datalen; BYTE* buf = (BYTE*)alloca(buflen); @@ -583,8 +579,7 @@ char* CMsnProto::GenerateLoginBlob(char* challenge) unsigned key1len; mir_ptr key1((BYTE*)mir_base64_decode(authSecretToken, &key1len)); - BYTE key2[MIR_SHA1_HASH_SIZE + 4]; - BYTE key3[MIR_SHA1_HASH_SIZE + 4]; + BYTE key2[MIR_SHA1_HASH_SIZE + 4], key3[MIR_SHA1_HASH_SIZE + 4]; static const unsigned char encdata1[] = "WS-SecureConversationSESSION KEY HASH"; static const unsigned char encdata2[] = "WS-SecureConversationSESSION KEY ENCRYPTION"; @@ -672,11 +667,8 @@ int CMsnProto::MSN_SkypeAuth(const char *pszNonce, char *pszUIC) pfnSkyLogin_PerformLogin SkyLogin_PerformLogin; pfnSkyLogin_CreateUICString SkyLogin_CreateUICString; - HMODULE hLibSkylogin; - - if ((hLibSkylogin = LoadLibraryA("Plugins\\skylogin.dll"))) { - SkyLogin hLogin; - char szPassword[100]; + HMODULE hLibSkylogin = LoadLibrary(_T("Plugins\\skylogin.dll")); + if (hLibSkylogin) { // load function pointers if (!LOAD_FN(SkyLogin_Init) || @@ -690,16 +682,21 @@ int CMsnProto::MSN_SkypeAuth(const char *pszNonce, char *pszUIC) } // Perform login - if (hLogin = SkyLogin_Init()) { - db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword)); - if (SkyLogin_LoadCredentials(hLogin, MyOptions.szEmail) || - SkyLogin_PerformLogin(hLogin, MyOptions.szEmail, szPassword)) - { - if (SkyLogin_CreateUICString(hLogin, pszNonce, pszUIC)) - iRet = 1; - } else iRet = 0; - SkyLogin_Exit(hLogin); - } else iRet = -3; + SkyLogin hLogin = SkyLogin_Init(); + if (hLogin) { + char szPassword[100]; + if (!db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword))) { + if (SkyLogin_LoadCredentials(hLogin, MyOptions.szEmail) || + SkyLogin_PerformLogin(hLogin, MyOptions.szEmail, szPassword)) + { + if (SkyLogin_CreateUICString(hLogin, pszNonce, pszUIC)) + iRet = 1; + } + else iRet = 0; + SkyLogin_Exit(hLogin); + } + else iRet = -3; + } FreeLibrary(hLibSkylogin); } return iRet; @@ -721,11 +718,8 @@ int CMsnProto::LoginSkypeOAuth(const char *pRefreshToken) pfnSkyLogin_GetCredentialsUIC SkyLogin_GetCredentialsUIC; pfnSkyLogin_GetUser SkyLogin_GetUser; - HMODULE hLibSkylogin; - - if ((hLibSkylogin = LoadLibraryA("Plugins\\skylogin.dll"))) { - SkyLogin hLogin; - + HMODULE hLibSkylogin = LoadLibrary(_T("Plugins\\skylogin.dll")); + if (hLibSkylogin) { // load function pointers if (!LOAD_FN(SkyLogin_Init) || !LOAD_FN(SkyLogin_Exit) || @@ -739,7 +733,8 @@ int CMsnProto::LoginSkypeOAuth(const char *pRefreshToken) } // Perform login - if (hLogin = SkyLogin_Init()) { + SkyLogin hLogin = SkyLogin_Init(); + if (hLogin) { char szLoginToken[1024]; if (RefreshOAuth(pRefreshToken, "service::login.skype.com::MBI_SSL", szLoginToken) && SkyLogin_PerformLoginOAuth(hLogin, szLoginToken)) @@ -796,7 +791,6 @@ static int CopyCookies(NETLIBHTTPREQUEST *nlhrReply, NETLIBHTTPHEADER *hdr) bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService, char *pszAccessToken, char *pszOutRefreshToken, time_t *ptExpires) { NETLIBHTTPREQUEST nlhr = { 0 }; - NETLIBHTTPREQUEST *nlhrReply; NETLIBHTTPHEADER headers[3]; bool bRet = false; CMStringA post; @@ -825,7 +819,7 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService // Query mHttpsTS = clock(); - nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); + NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); mHttpsTS = clock(); if (nlhrReply) { hHttpsConnection = nlhrReply->nlc; @@ -857,7 +851,7 @@ void CMsnProto::LoadAuthTokensDB(void) authSkypeComToken.Load(); authMethod = getDword("authMethod", 0); - bPassportAuth = getByte("PassportAuth", true); + bPassportAuth = getBool("PassportAuth", true); if (getString("authUser", &dbv) == 0) { replaceStr(authUser, dbv.pszVal); db_free(&dbv); @@ -1044,7 +1038,8 @@ bool CMsnProto::parseLoginPage(char *pszHTML, NETLIBHTTPREQUEST *nlhr, CMStringA /* Create POST data */ char szPassword[100]; - db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword)); + if (db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword))) + return false; szPassword[16] = 0; post->Format("PPFT=%s&login=%s&passwd=%s", ptrA(mir_urlEncode(pPPFT)), ptrA(mir_urlEncode(MyOptions.szEmail)), ptrA(mir_urlEncode(szPassword))); @@ -1123,7 +1118,6 @@ int CMsnProto::MSN_AuthOAuth(void) { int retVal = -1; NETLIBHTTPREQUEST nlhr = { 0 }; - NETLIBHTTPREQUEST *nlhrReply; NETLIBHTTPHEADER headers[3]; if (bAskingForAuth) return 0; @@ -1147,7 +1141,7 @@ int CMsnProto::MSN_AuthOAuth(void) // Get oauth20 login data nlhr.szUrl = AUTH_URL; mHttpsTS = clock(); - nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); + NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); mHttpsTS = clock(); if (nlhrReply) { diff --git a/protocols/MSN/src/msn_commands.cpp b/protocols/MSN/src/msn_commands.cpp index 5959277e2a..275ed84328 100644 --- a/protocols/MSN/src/msn_commands.cpp +++ b/protocols/MSN/src/msn_commands.cpp @@ -642,14 +642,15 @@ void CMsnProto::MSN_ProcessNLN(const char *userStatus, const char *wlid, char *u if (hContact != NULL) { char szSavedHash[64] = ""; - db_get_static(hContact, m_szModuleName, "AvatarSavedHash", szSavedHash, sizeof(szSavedHash)); - if (mir_strcmpi(szSavedHash, pszAvatarHash)) - pushAvatarRequest(hContact, pszUrl); - else { - char szSavedContext[64]; - int result = db_get_static(hContact, m_szModuleName, "PictSavedContext", szSavedContext, sizeof(szSavedContext)); - if (result || mir_strcmp(szSavedContext, cmdstring)) + if (!db_get_static(hContact, m_szModuleName, "AvatarSavedHash", szSavedHash, sizeof(szSavedHash))) { + if (mir_strcmpi(szSavedHash, pszAvatarHash)) pushAvatarRequest(hContact, pszUrl); + else { + char szSavedContext[64]; + int result = db_get_static(hContact, m_szModuleName, "PictSavedContext", szSavedContext, sizeof(szSavedContext)); + if (result || mir_strcmp(szSavedContext, cmdstring)) + pushAvatarRequest(hContact, pszUrl); + } } } mir_free(pszAvatarHash); diff --git a/protocols/MSN/src/msn_menu.cpp b/protocols/MSN/src/msn_menu.cpp index caeeef4fd5..08a9414ebc 100644 --- a/protocols/MSN/src/msn_menu.cpp +++ b/protocols/MSN/src/msn_menu.cpp @@ -27,15 +27,14 @@ static HGENMENU hBlockMenuItem, hLiveSpaceMenuItem, hNetmeetingMenuItem, hChatIn HANDLE hNetMeeting, hBlockCom, hSendHotMail, hInviteChat, hViewProfile; -///////////////////////////////////////////////////////////////////////////////////////// // Block command callback function - INT_PTR CMsnProto::MsnBlockCommand(WPARAM hContact, LPARAM) { if (msnLoggedIn) { char tEmail[MSN_MAX_EMAIL_LEN]; - if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail))) - db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail)); + if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail)) + && db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail))) + return 0; if (Lists_IsInList(LIST_BL, tEmail)) delSetting(hContact, "ApparentMode"); @@ -45,9 +44,7 @@ INT_PTR CMsnProto::MsnBlockCommand(WPARAM hContact, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnGotoInbox - goes to the Inbox folder at the live.com - INT_PTR CMsnProto::MsnGotoInbox(WPARAM, LPARAM) { MCONTACT hContact = MSN_HContactFromEmail(MyOptions.szEmail); @@ -68,18 +65,14 @@ INT_PTR CMsnProto::MsnSendHotmail(WPARAM hContact, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnSetupAlerts - goes to the alerts section at the live.com - INT_PTR CMsnProto::MsnSetupAlerts(WPARAM, LPARAM) { MsnInvokeMyURL(false, "http://alerts.live.com"); return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnViewProfile - view a contact's profile - INT_PTR CMsnProto::MsnViewProfile(WPARAM hContact, LPARAM) { char buf[64], *cid; @@ -98,18 +91,14 @@ INT_PTR CMsnProto::MsnViewProfile(WPARAM hContact, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnEditProfile - goes to the Profile section at the live.com - INT_PTR CMsnProto::MsnEditProfile(WPARAM, LPARAM) { MsnViewProfile(0, 0); return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnInviteCommand - invite command callback function - INT_PTR CMsnProto::MsnInviteCommand(WPARAM, LPARAM) { DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, @@ -117,9 +106,7 @@ INT_PTR CMsnProto::MsnInviteCommand(WPARAM, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnRebuildContactMenu - gray or ungray the block menus according to contact's status - int CMsnProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM) { if (!MSN_IsMyContact(hContact)) @@ -156,9 +143,7 @@ int CMsnProto::OnContactDoubleClicked(WPARAM hContact, LPARAM) } #ifdef OBSOLETE -///////////////////////////////////////////////////////////////////////////////////////// // MsnSendNetMeeting - Netmeeting callback function - INT_PTR CMsnProto::MsnSendNetMeeting(WPARAM wParam, LPARAM) { if (!msnLoggedIn) return 0; @@ -197,9 +182,7 @@ static INT_PTR MsnMenuSendNetMeeting(WPARAM wParam, LPARAM lParam) 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) { @@ -263,9 +246,7 @@ INT_PTR CMsnProto::SetNicknameUI(WPARAM, LPARAM) } #endif -////////////////////////////////////////////////////////////////////////////////////// // Menus initialization - void CMsnProto::MsnInitMainMenu(void) { CMenuItem mi; diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index a1cb7bfa0f..964584e354 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -25,9 +25,7 @@ along with this program. If not, see . #include "version.h" -///////////////////////////////////////////////////////////////////////////////////////// // MirandaStatusToMSN - status helper functions - const char* CMsnProto::MirandaStatusToMSN(int status) { switch (status) { @@ -80,9 +78,7 @@ char** CMsnProto::GetStatusMsgLoc(int status) return NULL; } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_AddAuthRequest - adds the authorization event to the database - void CMsnProto::MSN_AddAuthRequest(const char *email, const char *nick, const char *reason) { //blob is: UIN=0(DWORD), hContact(DWORD), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), email(ASCIIZ), ""(ASCIIZ) @@ -171,9 +167,7 @@ char* MSN_GetAvatarHash(char* szContext, char** pszUrl) return res; } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_GetAvatarFileName - gets a file name for an contact's avatar - void CMsnProto::MSN_GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext) { size_t tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName); @@ -301,22 +295,21 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen) _close(fileId); char szAvatarHashdOld[41] = ""; - db_get_static(NULL, m_szModuleName, "AvatarHash", szAvatarHashdOld, sizeof(szAvatarHashdOld)); - char *szAvatarHash = arrayToHex(sha1d, sizeof(sha1d)); - if (mir_strcmp(szAvatarHashdOld, szAvatarHash)) { - setString("PictObject", szEncodedBuffer); - setString("AvatarHash", szAvatarHash); + if (!db_get_static(NULL, m_szModuleName, "AvatarHash", szAvatarHashdOld, sizeof(szAvatarHashdOld))) { + char *szAvatarHash = arrayToHex(sha1d, sizeof(sha1d)); + if (mir_strcmp(szAvatarHashdOld, szAvatarHash)) { + setString("PictObject", szEncodedBuffer); + setString("AvatarHash", szAvatarHash); + } + mir_free(szAvatarHash); } - mir_free(szAvatarHash); } else MSN_ShowError("Cannot set avatar. File '%s' could not be created/overwritten", szFileName); return fmt; } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_GetCustomSmileyFileName - gets a file name for an contact's custom smiley - void CMsnProto::MSN_GetCustomSmileyFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen, const char* SmileyName, int type) { size_t tPathLen; @@ -340,7 +333,7 @@ void CMsnProto::MSN_GetCustomSmileyFileName(MCONTACT hContact, TCHAR* pszDest, s DBVARIANT dbv = { 0 }; if (getTString(hContact, "e-mail", &dbv)) { dbv.type = DBVT_ASCIIZ; - dbv.ptszVal = (TCHAR*)mir_alloc(11); + dbv.ptszVal = (TCHAR*)mir_alloc(11*sizeof(TCHAR)); _ui64tot((UINT_PTR)hContact, dbv.ptszVal, 10); } @@ -369,9 +362,7 @@ void CMsnProto::MSN_GetCustomSmileyFileName(MCONTACT hContact, TCHAR* pszDest, s mir_free(sztSmileyName); } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_GoOffline - performs several actions when a server goes offline - void CMsnProto::MSN_GoOffline(void) { if (m_iStatus == ID_STATUS_OFFLINE) return; @@ -422,13 +413,10 @@ void CMsnProto::MSN_GoOffline(void) } } } - -///////////////////////////////////////////////////////////////////////////////////////// -// MSN_SendMessage - formats and sends a MSG packet through the server - #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 { @@ -558,9 +546,7 @@ void ThreadData::sendTerminate(void) } } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_SendRawPacket - sends a packet accordingly to the MSN protocol - int ThreadData::sendRawMessage(int msgType, const char* data, int datLen) { if (data == NULL) @@ -582,7 +568,6 @@ int ThreadData::sendRawMessage(int msgType, const char* data, int datLen) } // Typing notifications support - void CMsnProto::MSN_SendTyping(ThreadData* info, const char* email, int netId, bool bTyping) { char tCommand[1024]; @@ -601,10 +586,6 @@ void CMsnProto::MSN_StartStopTyping(GCThreadData* info, bool start) MSN_SendTyping(msnNsThread, info->szEmail, info->netId, start); } - -///////////////////////////////////////////////////////////////////////////////////////// -// MSN_SendStatusMessage - notify a server about the status message change - // Helper to process texts static char * HtmlEncodeUTF8T(const TCHAR *src) { @@ -617,6 +598,7 @@ static char * HtmlEncodeUTF8T(const TCHAR *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 { @@ -698,9 +680,7 @@ void CMsnProto::MSN_SendStatusMessage(const char*) #endif } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_SendPacket - sends a packet accordingly to the MSN protocol - int ThreadData::sendPacket(const char* cmd, const char* fmt, ...) { if (this == NULL) return 0; @@ -769,10 +749,7 @@ int ThreadData::sendPacketPayload(const char* cmd, const char *param, const char return (result > 0) ? thisTrid : -1; } - -///////////////////////////////////////////////////////////////////////////////////////// // MSN_SetServerStatus - changes plugins status at the server - void CMsnProto::MSN_SetServerStatus(int newStatus) { debugLogA("Setting MSN server status %d, logged in = %d", newStatus, msnLoggedIn); @@ -889,9 +866,7 @@ void CMsnProto::MSN_SetServerStatus(int newStatus) #endif } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_FetchRecentMessages - fetches missed offline messages - void CMsnProto::MSN_FetchRecentMessages(time_t since) { if (!since) { @@ -917,13 +892,10 @@ void CMsnProto::MSN_FetchRecentMessages(time_t since) ((unsigned __int64)since)*1000); } - -///////////////////////////////////////////////////////////////////////////////////////// -// Display Hotmail Inbox thread - static const char postdataM[] = "ct=%u&bver=7&wa=wsignin1.0&ru=%s&pl=MBI"; static const char postdataS[] = "ct=%u&bver=7&id=73625&ru=%s&js=yes&pl=%%3Fid%%3D73625"; +// Display Hotmail Inbox thread void CMsnProto::MsnInvokeMyURL(bool ismail, const char* url) { if (!url) @@ -950,9 +922,7 @@ void CMsnProto::MsnInvokeMyURL(bool ismail, const char* url) } } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_ShowError - shows an error - void CMsnProto::MSN_ShowError(const char* msgtext, ...) { TCHAR tBuffer[4096]; @@ -989,9 +959,8 @@ void RemovePopupData(PopupData *tData) { CallService(MS_CLIST_REMOVEEVENT, hContact, 1); } } -///////////////////////////////////////////////////////////////////////////////////////// -// Popup plugin window proc +// Popup plugin window proc LRESULT CALLBACK NullWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { PopupData *tData = (PopupData*)PUGetPluginData(hWnd); @@ -1020,9 +989,7 @@ LRESULT CALLBACK NullWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara return DefWindowProc(hWnd, msg, wParam, lParam); } -///////////////////////////////////////////////////////////////////////////////////////// // InitPopups - popup plugin support - void CMsnProto::InitPopups(void) { TCHAR desc[256]; @@ -1059,12 +1026,10 @@ void CMsnProto::InitPopups(void) hPopupError = Popup_RegisterClass(&ppc); } -///////////////////////////////////////////////////////////////////////////////////////// // MSN_ShowPopup - popup plugin support - -void CALLBACK sttMainThreadCallback(PVOID dwParam) +void CALLBACK sttMainThreadCallback(void *param) { - PopupData* pud = (PopupData*)dwParam; + PopupData* pud = (PopupData*)param; bool iserr = (pud->flags & MSN_SHOW_ERROR) != 0; if ((iserr && !pud->proto->MyOptions.ShowErrorsAsPopups) || !ServiceExists(MS_POPUP_ADDPOPUPCLASS)) { diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index 9d1f2b5a31..29724809a4 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -219,9 +219,7 @@ int CMsnProto::OnModulesLoaded(WPARAM, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // OnPreShutdown - prepare a global Miranda shutdown - int CMsnProto::OnPreShutdown(WPARAM, LPARAM) { g_bTerminated = true; @@ -233,9 +231,7 @@ int CMsnProto::OnPreShutdown(WPARAM, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnAddToList - adds contact to the server list - MCONTACT CMsnProto::AddToListByEmail(const char *email, const char *nick, DWORD flags) { MCONTACT hContact = MSN_HContactFromEmail(email, nick, true, flags & PALF_TEMPORARY); @@ -297,9 +293,7 @@ int CMsnProto::AuthRecv(MCONTACT, PROTORECVEVENT* pre) return 0; } -//////////////////////////////////////////////////////////////////////////////////////// // PSS_AUTHREQUEST - int __cdecl CMsnProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage) { if (msnLoggedIn) { @@ -322,9 +316,7 @@ int __cdecl CMsnProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage) return 1; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnAuthAllow - called after successful authorization - int CMsnProto::Authorize(MEVENT hDbEvent) { if (!msnLoggedIn) @@ -360,9 +352,7 @@ int CMsnProto::Authorize(MEVENT hDbEvent) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnAuthDeny - called after unsuccessful authorization - int CMsnProto::AuthDeny(MEVENT hDbEvent, const TCHAR*) { if (!msnLoggedIn) @@ -404,9 +394,7 @@ int CMsnProto::AuthDeny(MEVENT hDbEvent, const TCHAR*) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnBasicSearch - search contacts by e-mail - void __cdecl CMsnProto::MsnSearchAckThread(void* arg) { const TCHAR* emailT = (TCHAR*)arg; @@ -474,9 +462,6 @@ HANDLE __cdecl CMsnProto::SearchByEmail(const TCHAR* email) return SearchBasic(email); } -///////////////////////////////////////////////////////////////////////////////////////// -// MsnFileAllow - starts the file transfer - // stolen from netlibhttp.cpp static void MyNetlibConnFromUrl(const char* szUrl, NETLIBOPENCONNECTION &nloc) { @@ -588,6 +573,7 @@ void __cdecl CMsnProto::MsnFileAckThread(void* arg) } } +// MsnFileAllow - starts the file transfer HANDLE __cdecl CMsnProto::FileAllow(MCONTACT, HANDLE hTransfer, const TCHAR* szPath) { filetransfer* ft = (filetransfer*)hTransfer; @@ -613,9 +599,7 @@ HANDLE __cdecl CMsnProto::FileAllow(MCONTACT, HANDLE hTransfer, const TCHAR* szP return ft; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnFileCancel - cancels the active file transfer - int __cdecl CMsnProto::FileCancel(MCONTACT, HANDLE hTransfer) { filetransfer* ft = (filetransfer*)hTransfer; @@ -648,9 +632,7 @@ int __cdecl CMsnProto::FileCancel(MCONTACT, HANDLE hTransfer) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnFileDeny - rejects the file transfer request - int __cdecl CMsnProto::FileDeny(MCONTACT, HANDLE hTransfer, const TCHAR* /*szReason*/) { filetransfer* ft = (filetransfer*)hTransfer; @@ -678,9 +660,7 @@ int __cdecl CMsnProto::FileDeny(MCONTACT, HANDLE hTransfer, const TCHAR* /*szRea return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnFileResume - renames a file - int __cdecl CMsnProto::FileResume(HANDLE hTransfer, int* action, const TCHAR** szFilename) { filetransfer* ft = (filetransfer*)hTransfer; @@ -743,15 +723,13 @@ int __cdecl CMsnProto::FileResume(HANDLE hTransfer, int* action, const TCHAR** s return 0; } -///////////////////////////////////////////////////////////////////////////////////////// -// MsnGetAwayMsg - reads the current status message for a user - typedef struct AwayMsgInfo_tag { INT_PTR id; MCONTACT hContact; } AwayMsgInfo; +// MsnGetAwayMsg - reads the current status message for a user void __cdecl CMsnProto::MsnGetAwayMsgThread(void* arg) { Sleep(150); @@ -777,9 +755,7 @@ HANDLE __cdecl CMsnProto::GetAwayMsg(MCONTACT hContact) return (HANDLE)inf->id; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnGetCaps - obtain the protocol capabilities - DWORD_PTR __cdecl CMsnProto::GetCaps(int type, MCONTACT) { switch (type) { @@ -816,17 +792,16 @@ DWORD_PTR __cdecl CMsnProto::GetCaps(int type, MCONTACT) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnRecvMessage - creates a database event from the message been received - int __cdecl CMsnProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre) { char tEmail[MSN_MAX_EMAIL_LEN]; - if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail))) - db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail)); + if (!db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail)) + || !db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail))) { + if (Lists_IsInList(LIST_FL, tEmail) && db_get_b(hContact, "MetaContacts", "IsSubcontact", 0) == 0) + db_unset(hContact, "CList", "Hidden"); + } - if (Lists_IsInList(LIST_FL, tEmail) && db_get_b(hContact, "MetaContacts", "IsSubcontact", 0) == 0) - db_unset(hContact, "CList", "Hidden"); return Proto_RecvMessage(hContact, pre); } @@ -835,8 +810,9 @@ int CMsnProto::GetInfo(MCONTACT hContact, int) { if (MyOptions.netId == NETID_SKYPE) { char tEmail[MSN_MAX_EMAIL_LEN]; - if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail))) - db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail)); + if (db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail)) + && db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail))) + return 0; MSN_SKYABGetProfile(tEmail); return 1; @@ -844,10 +820,7 @@ int CMsnProto::GetInfo(MCONTACT hContact, int) return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// // MsnRecvContacts - creates a database event from the contacts received - int CMsnProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT* pre) { PROTOSEARCHRESULT **isrList = (PROTOSEARCHRESULT**)pre->szMessage; @@ -875,9 +848,7 @@ int CMsnProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT* pre) #ifdef OBSOLETE -///////////////////////////////////////////////////////////////////////////////////////// // MsnSendFile - initiates a file transfer - HANDLE __cdecl CMsnProto::SendFile(MCONTACT hContact, const TCHAR*, TCHAR** ppszFiles) { if (!msnLoggedIn) @@ -923,9 +894,6 @@ HANDLE __cdecl CMsnProto::SendFile(MCONTACT hContact, const TCHAR*, TCHAR** ppsz } #endif -///////////////////////////////////////////////////////////////////////////////////////// -// MsnSendMessage - sends the message to a server - struct TFakeAckParams { inline TFakeAckParams(MCONTACT p2, long p3, const char* p4, CMsnProto *p5, int p6=ACKTYPE_MESSAGE) : @@ -955,6 +923,7 @@ void CMsnProto::MsnFakeAck(void* arg) delete tParam; } +// MsnSendMessage - sends the message to a server int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) { const char *errMsg = NULL; @@ -1052,7 +1021,6 @@ int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) return seq; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnSendContacts - sends contacts to a certain user int __cdecl CMsnProto::SendContacts(MCONTACT hContact, int, int nContacts, MCONTACT *hContactsList) { @@ -1077,10 +1045,7 @@ int __cdecl CMsnProto::SendContacts(MCONTACT hContact, int, int nContacts, MCONT return seq; } - -///////////////////////////////////////////////////////////////////////////////////////// // MsnSetAwayMsg - sets the current status message for a user - int __cdecl CMsnProto::SetAwayMsg(int status, const TCHAR* msg) { char** msgptr = GetStatusMsgLoc(status); @@ -1109,9 +1074,7 @@ int __cdecl CMsnProto::SetAwayMsg(int status, const TCHAR* msg) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnSetStatus - set the plugin's connection status - int __cdecl CMsnProto::SetStatus(int iNewStatus) { if (m_iDesiredStatus == iNewStatus) return 0; @@ -1162,9 +1125,7 @@ int __cdecl CMsnProto::SetStatus(int iNewStatus) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnUserIsTyping - notify another contact that we're typing a message - int __cdecl CMsnProto::UserIsTyping(MCONTACT hContact, int type) { if (!msnLoggedIn) return 0; @@ -1206,9 +1167,7 @@ int __cdecl CMsnProto::UserIsTyping(MCONTACT hContact, int type) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// // MsnSetApparentMode - controls contact visibility - int __cdecl CMsnProto::SetApparentMode(MCONTACT hContact, int mode) { if (mode && mode != ID_STATUS_OFFLINE) diff --git a/protocols/MSN/src/msn_ssl.cpp b/protocols/MSN/src/msn_ssl.cpp index 20964a1b23..f39e17a709 100644 --- a/protocols/MSN/src/msn_ssl.cpp +++ b/protocols/MSN/src/msn_ssl.cpp @@ -67,6 +67,7 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char nlhr.headers[nlhr.headersCount].szValue = fnd; fnd = strchr(fnd, '\r'); + if (fnd == NULL) break; *fnd = 0; hdrprs = fnd + 2; ++nlhr.headersCount; @@ -75,8 +76,7 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char } // download the page - NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, - (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); + NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); if (nlhrReply) { hHttpsConnection = nlhrReply->nlc; @@ -120,8 +120,7 @@ bool CMsnProto::getMyAvatarFile(char *url, TCHAR *fname) nlhr.headers[0].szValue = (char*)MSN_USER_AGENT; // download the page - NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, - (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); + NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUserHttps, (LPARAM)&nlhr); if (nlhrReply) { if (nlhrReply->resultCode == 200 && nlhrReply->dataLength) diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp index 8e92e2e72e..e2851c4220 100644 --- a/protocols/MSN/src/msn_threads.cpp +++ b/protocols/MSN/src/msn_threads.cpp @@ -23,9 +23,7 @@ along with this program. If not, see . #include "stdafx.h" #include "msn_proto.h" -///////////////////////////////////////////////////////////////////////////////////////// // Keep-alive thread for the main connection - void __cdecl CMsnProto::msn_keepAliveThread(void*) { bool keepFlag = true; @@ -89,8 +87,6 @@ void __cdecl CMsnProto::msn_refreshOAuthThread(void *param) MSN_SendATH((ThreadData*)param); } } -///////////////////////////////////////////////////////////////////////////////////////// -// MSN server thread - read and process commands from a server static bool ReallocInfoBuffer(ThreadData *info, size_t mDataSize) { @@ -104,6 +100,7 @@ static bool ReallocInfoBuffer(ThreadData *info, size_t mDataSize) return true; } +// MSN server thread - read and process commands from a server void __cdecl CMsnProto::MSNServerThread(void* arg) { ThreadData* info = (ThreadData*)arg; @@ -544,14 +541,15 @@ ThreadData* CMsnProto::MSN_GetThreadByPort(WORD wPort) ///////////////////////////////////////////////////////////////////////////////////////// // class ThreadData members - -ThreadData::ThreadData() +ThreadData::ThreadData() : mDataSize(8192), mGatewayTimeout(2), mFunc(0), mIncomingBoundPort(0), mIncomingPort(0), + mIsMainThread(false), sessionClosed(false), mBridgeInit(false), gatewayType(false), termPending(false), firstMsgRecv(false), + mTrid(0), mBytesInData(0), mMsnFtp(0), mCaller(0), mTimerId(0), proto(0), s(0) { memset(&mInitialContactWLID, 0, sizeof(ThreadData) - 2 * sizeof(STRLIST)); - mGatewayTimeout = 2; + resetTimeout(); hWaitEvent = CreateSemaphore(NULL, 0, MSN_PACKETS_COMBINE, NULL); - mData = (char*)mir_calloc((mDataSize=8192)+1); + mData = (char*)mir_calloc(mDataSize + 1); } ThreadData::~ThreadData() @@ -754,9 +752,7 @@ BYTE* HReadBuffer::surelyRead(size_t parBytes) ///////////////////////////////////////////////////////////////////////////////////////// // class GCThreadData members - -GCThreadData::GCThreadData() : -mJoinedContacts(10, PtrKeySortT) +GCThreadData::GCThreadData() : mJoinedContacts(10, PtrKeySortT), mMe(0), netId(0) { memset(&mCreator, 0, sizeof(GCThreadData) - sizeof(mJoinedContacts)); } diff --git a/protocols/MSN/src/stdafx.h b/protocols/MSN/src/stdafx.h index 78de164fec..0bece806b7 100644 --- a/protocols/MSN/src/stdafx.h +++ b/protocols/MSN/src/stdafx.h @@ -680,7 +680,6 @@ struct MsgQueueEntry ///////////////////////////////////////////////////////////////////////////////////////// // Avatars' queue - struct AvatarQueueEntry { MCONTACT hContact; @@ -763,7 +762,9 @@ struct MsnPlace unsigned p2pMsgId; unsigned short p2pPktNum; - ~MsnPlace() { mir_free(id); } + ~MsnPlace() { + mir_free(id); + } }; struct MsnContact @@ -780,8 +781,16 @@ struct MsnContact OBJLIST places; - MsnContact() : places(1, CompareId) {} - ~MsnContact() { mir_free(email); mir_free(nick); mir_free(invite); } + MsnContact() : email(0), invite(0), nick(0), + hContact(0), list(0), netId(0), p2pMsgId(0), + cap1(0), cap2(0), places(1, CompareId) { + } + + ~MsnContact() { + mir_free(email); + mir_free(nick); + mir_free(invite); + } }; #define cap_OnlineViaMobile 0x00000001 @@ -882,9 +891,7 @@ struct MsnContact #define LIST_REMOVE 0x0100 #define LIST_REMOVENH 0x0300 -///////////////////////////////////////////////////////////////////////////////////////// // MSN plugin options - typedef struct _tag_MYOPTIONS { bool EnableSounds; @@ -900,9 +907,7 @@ typedef struct _tag_MYOPTIONS } MYOPTIONS; -///////////////////////////////////////////////////////////////////////////////////////// // Windows error class - struct TWinErrorCode { WINAPI TWinErrorCode(); @@ -1029,8 +1034,9 @@ struct InviteChatParam InviteChatParam(const TCHAR* id, MCONTACT hContact, CMsnProto* ppro) : id(mir_tstrdup(id)), hContact(hContact), ppro(ppro) {} - ~InviteChatParam() - { mir_free(id); } + ~InviteChatParam() { + mir_free(id); + } }; INT_PTR CALLBACK DlgInviteToChat(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); \ No newline at end of file -- cgit v1.2.3