From 5b6f2daa070dff9998af4259daa3926cb70bb817 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 24 Nov 2013 17:27:34 +0000 Subject: - custom UrlEncode replaced with the core function; - fix for opening Hotmail Inbox in a browser; - end of strange buffers; - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@6976 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/MSN/src/msn_auth.cpp | 30 ++++++++------------------- protocols/MSN/src/msn_commands.cpp | 8 ++------ protocols/MSN/src/msn_global.h | 3 +-- protocols/MSN/src/msn_libstr.cpp | 29 -------------------------- protocols/MSN/src/msn_menu.cpp | 8 +------- protocols/MSN/src/msn_misc.cpp | 42 +++++++++++--------------------------- protocols/MSN/src/msn_proto.h | 8 ++++---- protocols/MSN/src/msn_srv.cpp | 6 +----- 8 files changed, 30 insertions(+), 104 deletions(-) (limited to 'protocols') diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp index e69972e28a..172c74cab9 100644 --- a/protocols/MSN/src/msn_auth.cpp +++ b/protocols/MSN/src/msn_auth.cpp @@ -439,7 +439,7 @@ char* CMsnProto::GenerateLoginBlob(char* challenge) } -char* CMsnProto::HotmailLogin(const char* url) +CMStringA CMsnProto::HotmailLogin(const char* url) { unsigned char nonce[24]; CallService(MS_UTILS_GETRANDOM, sizeof(nonce), (LPARAM)nonce); @@ -458,29 +458,17 @@ char* CMsnProto::HotmailLogin(const char* url) unsigned char key2[MIR_SHA1_HASH_SIZE+4]; derive_key(key2, key1, key1len, data1, data1len); - const size_t xmlenclen = 3 * strlen(hotAuthToken) + 1; - char* xmlenc = (char*)alloca(xmlenclen); - UrlEncode(hotAuthToken, xmlenc, xmlenclen); + CMStringA result; + result.Format("%s&da=%s&nonce=", url, ptrA(mir_urlEncode(hotAuthToken))); - ptrA noncenc( mir_base64_encode(nonce, sizeof(nonce))); - size_t noncenclen = lstrlenA(noncenc); - - const size_t fnpstlen = strlen(xmlenc) + strlen(url) + 3*noncenclen + 100; - char* fnpst = (char*)mir_alloc(fnpstlen); - - size_t sz = mir_snprintf(fnpst, fnpstlen, "%s&da=%s&nonce=", url, xmlenc); - - UrlEncode(noncenc, fnpst + sz, fnpstlen - sz); - sz = strlen(fnpst); + ptrA noncenc(mir_base64_encode(nonce, sizeof(nonce))); + result.Append(ptrA(mir_urlEncode(noncenc))); BYTE hash[MIR_SHA1_HASH_SIZE]; - mir_hmac_sha1(hash, key2, sizeof(key2), (BYTE*)fnpst, sz); - - noncenc = mir_base64_encode(hash, sizeof(hash)); - - sz += mir_snprintf(fnpst + sz, fnpstlen - sz, "&hash="); - UrlEncode(noncenc, fnpst + sz, fnpstlen - sz); - return fnpst; + mir_hmac_sha1(hash, key2, sizeof(key2), (BYTE*)result.GetString(), result.GetLength()); + ptrA szHash(mir_base64_encode(hash, sizeof(hash))); + result.AppendFormat("&hash=%s", ptrA(mir_urlEncode(szHash))); + return result; } void CMsnProto::FreeAuthTokens(void) diff --git a/protocols/MSN/src/msn_commands.cpp b/protocols/MSN/src/msn_commands.cpp index a7e5774f43..4821dd4c67 100644 --- a/protocols/MSN/src/msn_commands.cpp +++ b/protocols/MSN/src/msn_commands.cpp @@ -303,20 +303,16 @@ void CMsnProto::sttCustomSmiley(const char* msgBody, char* email, char* nick, in size_t slen = strlen(lastsml); ptrA buf( mir_base64_encode((PBYTE)lastsml, (unsigned)slen)); + ptrA smileyName(mir_urlEncode(buf)); int rlen = lstrlenA(buf); - char* smileyName = (char*)mir_alloc(rlen*3); - UrlEncode(buf, smileyName, rlen*3); - TCHAR path[MAX_PATH]; MSN_GetCustomSmileyFileName(hContact, path, SIZEOF(path), smileyName, iSmileyType); ft->std.tszCurrentFile = mir_tstrdup(path); - mir_free(smileyName); if (p2p_IsDlFileOk(ft)) delete ft; - else - { + else { debugLogA("Custom Smiley p2p invite for object : %s", ft->p2p_object); p2p_invite(iSmileyType, ft, email); Sleep(3000); diff --git a/protocols/MSN/src/msn_global.h b/protocols/MSN/src/msn_global.h index 1011df19f1..4e5314b22a 100644 --- a/protocols/MSN/src/msn_global.h +++ b/protocols/MSN/src/msn_global.h @@ -63,6 +63,7 @@ along with this program. If not, see . #include #include #include +#include #include "m_proto_listeningto.h" #include "m_folders.h" @@ -163,8 +164,6 @@ char* GetGlobalIp(void); template void UrlDecode(chartype* str); -void UrlEncode(const char* src, char* dest, size_t cbDest); - void __cdecl MSN_ConnectionProc(HANDLE hNewConnection, DWORD dwRemoteIP, void*); char* MSN_GetAvatarHash(char* szContext, char** pszUrl = NULL); diff --git a/protocols/MSN/src/msn_libstr.cpp b/protocols/MSN/src/msn_libstr.cpp index 8067341faa..7a9c07a2b2 100644 --- a/protocols/MSN/src/msn_libstr.cpp +++ b/protocols/MSN/src/msn_libstr.cpp @@ -229,35 +229,6 @@ char* HtmlEncode(const char* str) } ///////////////////////////////////////////////////////////////////////////////////////// -// UrlEncode - converts printable characters into URL chars like %20 - -void UrlEncode(const char* src, char* dest, size_t cbDest) -{ - unsigned char* d = (unsigned char*)dest; - size_t i = 0; - - for (const unsigned char* s = (unsigned char*)src; *s; s++) - { - if ((*s <= '/' && *s != '.' && *s != '-') || - (*s >= ':' && *s <= '?') || - (*s >= '[' && *s <= '`' && *s != '_')) - { - if (i + 4 >= cbDest) break; - - *d++ = '%'; - _itoa(*s, (char*)d, 16); - d += 2; - i += 3; - } - else - { - if (++i >= cbDest) break; - *d++ = *s; - } } - - *d = '\0'; -} - void stripBBCode(char* src) { diff --git a/protocols/MSN/src/msn_menu.cpp b/protocols/MSN/src/msn_menu.cpp index b6760000cb..405c5da7dc 100644 --- a/protocols/MSN/src/msn_menu.cpp +++ b/protocols/MSN/src/msn_menu.cpp @@ -67,13 +67,7 @@ INT_PTR CMsnProto::MsnSendHotmail(WPARAM wParam, LPARAM) if (MSN_IsMeByContact(hContact, szEmail)) MsnGotoInbox(0, 0); else if (msnLoggedIn) - { - char szEmailEnc[MSN_MAX_EMAIL_LEN*3], szUrl[256]; - - UrlEncode(szEmail, szEmailEnc, sizeof(szEmailEnc)); - mir_snprintf(szUrl, sizeof(szUrl), "http://mail.live.com?rru=compose?to=%s", szEmailEnc); - MsnInvokeMyURL(true, szUrl); - } + MsnInvokeMyURL(true, CMStringA().Format("http://mail.live.com?rru=compose?to=%s", ptrA(mir_urlEncode(szEmail)))); return 0; } diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index 8a515d7ffa..e9ced7454b 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -285,9 +285,7 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen) char* szBuffer = ezxml_toxml(xmlp, false); ezxml_free(xmlp); mir_free(szFname); - - char szEncodedBuffer[2000]; - UrlEncode(szBuffer, szEncodedBuffer, sizeof(szEncodedBuffer)); + ptrA szEncodedBuffer(mir_urlEncode(szBuffer)); free(szBuffer); const TCHAR *szExt; @@ -309,8 +307,7 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen) char szAvatarHashdOld[41] = ""; getStaticString(NULL, "AvatarHash", szAvatarHashdOld, sizeof(szAvatarHashdOld)); char *szAvatarHash = arrayToHex(sha1d, sizeof(sha1d)); - if (strcmp(szAvatarHashdOld, szAvatarHash)) - { + if (strcmp(szAvatarHashdOld, szAvatarHash)) { setString("PictObject", szEncodedBuffer); setString("AvatarHash", szAvatarHash); } @@ -445,7 +442,7 @@ int ThreadData::sendMessage(int msgType, const char* email, int netId, const cha break; if (*p == 0) { - UrlEncode(dbv.pszVal, tFontName, sizeof(tFontName)); + strncpy_s(tFontName, sizeof(tFontName), ptrA(mir_urlEncode(dbv.pszVal)), _TRUNCATE); db_free(&dbv); } } @@ -777,14 +774,15 @@ void CMsnProto::MSN_SetServerStatus(int newStatus) ///////////////////////////////////////////////////////////////////////////////////////// // 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"; + void CMsnProto::MsnInvokeMyURL(bool ismail, const char* url) { char* hippy = NULL; if (!url) url = ismail ? "http://mail.live.com?rru=inbox" : "http://profile.live.com"; - 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"; const char *postdata = ismail ? postdataM : postdataS; char passport[256]; @@ -796,30 +794,14 @@ void CMsnProto::MsnInvokeMyURL(bool ismail, const char* url) if (p) *p = 0; - char ruenc[256]; - UrlEncode(url, ruenc, sizeof(ruenc)); - - const size_t fnpstlen = strlen(postdata) + strlen(ruenc) + 30; - char* fnpst = (char*)alloca(fnpstlen); + CMStringA post = HotmailLogin(CMStringA().Format(postdata, (unsigned)time(NULL), ptrA(mir_urlEncode(url)))); + if (!post.IsEmpty()) { + CMStringA hippy(passport); + hippy.AppendFormat("/ppsecure/sha1auth.srf?lc=%d&token=%s", itoa(langpref, passport, 10), ptrA(mir_urlEncode(post))); - mir_snprintf(fnpst, fnpstlen, postdata, time(NULL), ruenc); - - char* post = HotmailLogin(fnpst); - if (post) { - size_t hipsz = strlen(passport) + 3*strlen(post) + 70; - hippy = (char*)alloca(hipsz); - - strcpy(hippy, passport); - strcat(hippy, "\\ppsecure\\sha1auth.srf?lc="); - strcat(hippy, itoa(langpref, passport, 10)); - strcat(hippy, "&token="); - size_t hiplen = strlen(hippy); - UrlEncode(post, hippy+hiplen, hipsz-hiplen); - mir_free(post); + debugLogA("Starting URL: '%s'", hippy);//why are we doin' this even though "hippy" might be "null"? + CallService(MS_UTILS_OPENURL, 1, (LPARAM)(LPCSTR)hippy); } - - debugLogA("Starting URL: '%s'", hippy); - CallService(MS_UTILS_OPENURL, 1, (LPARAM)hippy); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/MSN/src/msn_proto.h b/protocols/MSN/src/msn_proto.h index aaaee49351..48c41d0fec 100644 --- a/protocols/MSN/src/msn_proto.h +++ b/protocols/MSN/src/msn_proto.h @@ -474,10 +474,10 @@ struct CMsnProto : public PROTO ///////////////////////////////////////////////////////////////////////////////////////// // MSN Authentication - int MSN_GetPassportAuth(void); - char* GenerateLoginBlob(char* challenge); - char* HotmailLogin(const char* url); - void FreeAuthTokens(void); + int MSN_GetPassportAuth(void); + char* GenerateLoginBlob(char* challenge); + CMStringA HotmailLogin(const char* url); + void FreeAuthTokens(void); ///////////////////////////////////////////////////////////////////////////////////////// // MSN avatars support diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp index 1fcdb0eba2..10b0d5a5dc 100644 --- a/protocols/MSN/src/msn_srv.cpp +++ b/protocols/MSN/src/msn_srv.cpp @@ -324,11 +324,7 @@ void CMsnProto::MSN_SendNicknameUtf(const char* nickname) void CMsnProto::MSN_SetNicknameUtf(const char* nickname) { - const size_t urlNickSz = strlen(nickname) * 3 + 1; - char* urlNick = (char*)alloca(urlNickSz); - - UrlEncode(nickname, urlNick, urlNickSz); - msnNsThread->sendPacket("PRP", "MFN %s", urlNick); + msnNsThread->sendPacket("PRP", "MFN %s", ptrA(mir_urlEncode(nickname))); } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3