From 136628cf7ac5148ebdd8c8ecd25757c594d1bca8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 29 Jan 2013 17:05:30 +0000 Subject: MSN HTTP avatars, part I git-svn-id: http://svn.miranda-ng.org/main/trunk@3341 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/MSN/msn_10.vcxproj | 1 + protocols/MSN/msn_10.vcxproj.filters | 3 + protocols/MSN/msn_11.vcxproj | 1 + protocols/MSN/msn_11.vcxproj.filters | 3 + protocols/MSN/src/msn_avatar.cpp | 35 +++++++++ protocols/MSN/src/msn_commands.cpp | 51 ++++++------ protocols/MSN/src/msn_global.h | 19 ++++- protocols/MSN/src/msn_misc.cpp | 145 ++++++++++++++++------------------- protocols/MSN/src/msn_msgqueue.cpp | 44 +++++------ protocols/MSN/src/msn_p2ps.cpp | 4 +- protocols/MSN/src/msn_proto.cpp | 3 +- protocols/MSN/src/msn_proto.h | 6 +- protocols/MSN/src/msn_svcs.cpp | 60 +++++++-------- 13 files changed, 204 insertions(+), 171 deletions(-) create mode 100644 protocols/MSN/src/msn_avatar.cpp (limited to 'protocols') diff --git a/protocols/MSN/msn_10.vcxproj b/protocols/MSN/msn_10.vcxproj index a9bfd5e125..3956749665 100644 --- a/protocols/MSN/msn_10.vcxproj +++ b/protocols/MSN/msn_10.vcxproj @@ -206,6 +206,7 @@ NotUsing + Create diff --git a/protocols/MSN/msn_10.vcxproj.filters b/protocols/MSN/msn_10.vcxproj.filters index 739be1ce0b..ea6d433142 100644 --- a/protocols/MSN/msn_10.vcxproj.filters +++ b/protocols/MSN/msn_10.vcxproj.filters @@ -119,6 +119,9 @@ Source Files + + Source Files + diff --git a/protocols/MSN/msn_11.vcxproj b/protocols/MSN/msn_11.vcxproj index 87233b5a53..246f8e0a10 100644 --- a/protocols/MSN/msn_11.vcxproj +++ b/protocols/MSN/msn_11.vcxproj @@ -210,6 +210,7 @@ NotUsing + Create diff --git a/protocols/MSN/msn_11.vcxproj.filters b/protocols/MSN/msn_11.vcxproj.filters index 739be1ce0b..ea6d433142 100644 --- a/protocols/MSN/msn_11.vcxproj.filters +++ b/protocols/MSN/msn_11.vcxproj.filters @@ -119,6 +119,9 @@ Source Files + + Source Files + diff --git a/protocols/MSN/src/msn_avatar.cpp b/protocols/MSN/src/msn_avatar.cpp new file mode 100644 index 0000000000..2734b2a8a4 --- /dev/null +++ b/protocols/MSN/src/msn_avatar.cpp @@ -0,0 +1,35 @@ +/* +Plugin for Miranda NG for communicating with users of the MSN Messenger protocol. +Copyright (c) 2013 Miranda NG Team + +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 "msn_global.h" +#include "msn_proto.h" + +void CMsnProto::pushAvatarRequest(HANDLE hContact, LPCSTR pszUrl) +{ + SendBroadcast(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); + + if (pszUrl != NULL && *pszUrl != 0) { + mir_cslock lck(csAvatarQueue); + + for (int i=0; i < lsAvatarQueue.getCount(); i++) + if (lsAvatarQueue[i].hContact == hContact) + return; + + lsAvatarQueue.insert(new AvatarQueueEntry(hContact, pszUrl)); + } +} diff --git a/protocols/MSN/src/msn_commands.cpp b/protocols/MSN/src/msn_commands.cpp index 743094b0dc..430461f04f 100644 --- a/protocols/MSN/src/msn_commands.cpp +++ b/protocols/MSN/src/msn_commands.cpp @@ -1370,68 +1370,61 @@ LBL_InvalidCommand: setDword(hContact, "IdleTS", newStatus != ID_STATUS_IDLE ? 0 : time(NULL)); } - if (tArgs > 3 && tArgs <= 5 && cont) - { + if (tArgs > 3 && tArgs <= 5 && cont) { UrlDecode(data.cmdstring); char* end = NULL; cont->cap1 = strtoul(data.objid, &end, 10); cont->cap2 = end && *end == ':' ? strtoul(end + 1, NULL, 10) : 0; - if (lastStatus == ID_STATUS_OFFLINE) - { + if (lastStatus == ID_STATUS_OFFLINE) { DBVARIANT dbv; bool always = getString(hContact, "MirVer", &dbv) != 0; if (!always) MSN_FreeVariant(&dbv); sttSetMirVer(hContact, cont->cap1, always); } - if (/*(cont->cap1 & 0xf0000000) &&*/ data.cmdstring[0] && strcmp(data.cmdstring, "0")) + if (data.cmdstring[0] && strcmp(data.cmdstring, "0")) { - char* szAvatarHash = MSN_GetAvatarHash(data.cmdstring); - if (szAvatarHash == NULL) goto remove; + char *pszUrl, *pszAvatarHash = MSN_GetAvatarHash(data.cmdstring, &pszUrl); + if (pszAvatarHash == NULL) + goto remove; setString(hContact, "PictContext", data.cmdstring); - setString(hContact, "AvatarHash", szAvatarHash); + setString(hContact, "AvatarHash", pszAvatarHash); + if (pszUrl) + setString(hContact, "AvatarUrl", pszUrl); + else + deleteSetting(hContact, "AvatarUrl"); - if (hContact != NULL) - { + if (hContact != NULL) { char szSavedHash[64] = ""; getStaticString(hContact, "AvatarSavedHash", szSavedHash, sizeof(szSavedHash)); - if (stricmp(szSavedHash, szAvatarHash)) - { - SendBroadcast(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); - } - else - { + if (stricmp(szSavedHash, pszAvatarHash)) + pushAvatarRequest(hContact, pszUrl); + else { char szSavedContext[64]; int result = getStaticString(hContact, "PictSavedContext", szSavedContext, sizeof(szSavedContext)); if (result || strcmp(szSavedContext, data.cmdstring)) - SendBroadcast(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); + pushAvatarRequest(hContact, pszUrl); } - mir_free(szAvatarHash); } + mir_free(pszAvatarHash); + mir_free(pszUrl); } - else - { + else { remove: deleteSetting(hContact, "AvatarHash"); deleteSetting(hContact, "AvatarSavedHash"); + deleteSetting(hContact, "AvatarUrl"); deleteSetting(hContact, "PictContext"); deleteSetting(hContact, "PictSavedContext"); -// char tFileName[MAX_PATH]; -// MSN_GetAvatarFileName(hContact, tFileName, sizeof(tFileName)); -// remove(tFileName); - SendBroadcast(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); } } - else - { - if (lastStatus == ID_STATUS_OFFLINE) - deleteSetting(hContact, "MirVer"); - } + else if (lastStatus == ID_STATUS_OFFLINE) + deleteSetting(hContact, "MirVer"); break; } diff --git a/protocols/MSN/src/msn_global.h b/protocols/MSN/src/msn_global.h index 5b4bf32aef..d3349f219f 100644 --- a/protocols/MSN/src/msn_global.h +++ b/protocols/MSN/src/msn_global.h @@ -173,7 +173,7 @@ 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* MSN_GetAvatarHash(char* szContext, char** pszUrl = NULL); int MSN_GetImageFormat(void* buf, const TCHAR** ext); int MSN_GetImageFormat(const TCHAR* file); bool MSN_MsgWndExist(HANDLE hContact); @@ -602,6 +602,23 @@ struct MsgQueueEntry int flags; }; +///////////////////////////////////////////////////////////////////////////////////////// +// Avatars' queue + +struct AvatarQueueEntry +{ + HANDLE hContact; + char* pszUrl; + + __forceinline AvatarQueueEntry(HANDLE _contact, LPCSTR _url) : + hContact(_contact), + pszUrl( mir_strdup(_url)) + {} + + __forceinline ~AvatarQueueEntry() + { mir_free(pszUrl); + } +}; ///////////////////////////////////////////////////////////////////////////////////////// // User lists diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index 0695989eb9..511a24985f 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -150,16 +150,15 @@ void CMsnProto::InitCustomFolders(void) } -char* MSN_GetAvatarHash(char* szContext) +char* MSN_GetAvatarHash(char* szContext, char** pszUrl) { if (szContext == NULL) return NULL; - char* res = NULL; + char *res = NULL; ezxml_t xmli = ezxml_parse_str(NEWSTR_ALLOCA(szContext), strlen(szContext)); - const char* szAvatarHash = ezxml_attr(xmli, "SHA1D"); - if (szAvatarHash != NULL) - { + const char *szAvatarHash = ezxml_attr(xmli, "SHA1D"); + if (szAvatarHash != NULL) { BYTE szActHash[MIR_SHA1_HASH_SIZE+2] = {0}; const size_t len = strlen(szAvatarHash); @@ -167,6 +166,25 @@ char* MSN_GetAvatarHash(char* szContext) int decod = CallService(MS_NETLIB_BASE64DECODE, 0, LPARAM(&nlb)); if (decod != 0 && nlb.cbDecoded > 0) res = arrayToHex(szActHash, nlb.cbDecoded); + + if (pszUrl) { + const char *pszUrlAttr; + for (int i=0; ; i++) { + char szSetting[20]; + if (i == 0) + strcpy(szSetting, "Url"); + else + mir_snprintf(szSetting, sizeof(szSetting), "Url%d", i); + pszUrlAttr = ezxml_attr(xmli, "szSetting"); + if (pszUrlAttr == NULL) + break; + + if (pszUrlAttr[0] != 0) { + *pszUrl = mir_strdup(pszUrlAttr); + break; + } + } + } } ezxml_free(xmli); @@ -200,92 +218,74 @@ void CMsnProto::MSN_GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t c CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)pszDest); size_t tPathLen2 = tPathLen; - if (hContact != NULL) - { + if (hContact != NULL) { DBVARIANT dbv; - if (getString(hContact, "PictContext", &dbv) == 0) - { + if (getString(hContact, "PictContext", &dbv) == 0) { char* szAvatarHash = MSN_GetAvatarHash(dbv.pszVal); - if (szAvatarHash != NULL) - { + if (szAvatarHash != NULL) { TCHAR *sztAvatarHash = mir_a2t(szAvatarHash); tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s."), sztAvatarHash); mir_free(sztAvatarHash); mir_free(szAvatarHash); } - else - { + else { deleteSetting(hContact, "PictContext"); if (cbLen) pszDest[0] = 0; } MSN_FreeVariant(&dbv); } - else - { - if (cbLen) pszDest[0] = 0; - } + else if (cbLen) + pszDest[0] = 0; } - else - { + else { TCHAR *sztModuleName = mir_a2t(m_szModuleName); tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s avatar."), sztModuleName); mir_free(sztModuleName); } - if (ext == NULL) - { + if (ext == NULL) { mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("*")); bool found = false; _tfinddata_t c_file; long hFile = _tfindfirst(pszDest, &c_file); - if (hFile > -1L) - { + if (hFile > -1L) { do { - if (_tcsrchr(c_file.name, '.')) - { + if (_tcsrchr(c_file.name, '.')) { mir_sntprintf(pszDest + tPathLen2, cbLen - tPathLen2, _T("\\%s"), c_file.name); found = true; } - } while(_tfindnext(hFile, &c_file) == 0); + } + while(_tfindnext(hFile, &c_file) == 0); _findclose( hFile ); } if (!found) pszDest[0] = 0; } - else - mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext); + else mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext); } int MSN_GetImageFormat(void* buf, const TCHAR** ext) { - int res; - if (*(unsigned short*)buf == 0xd8ff) - { - res = PA_FORMAT_JPEG; + if (*(unsigned short*)buf == 0xd8ff) { *ext = _T("jpg"); + return PA_FORMAT_JPEG; } - else if (*(unsigned short*)buf == 0x4d42) - { - res = PA_FORMAT_BMP; + if (*(unsigned short*)buf == 0x4d42) { *ext = _T("bmp"); + return PA_FORMAT_BMP; } - else if (*(unsigned*)buf == 0x474e5089) - { - res = PA_FORMAT_PNG; + if (*(unsigned*)buf == 0x474e5089) { *ext = _T("png"); + return PA_FORMAT_PNG; } - else if (*(unsigned*)buf == 0x38464947) - { - res = PA_FORMAT_GIF; + if (*(unsigned*)buf == 0x38464947) { *ext = _T("gif"); + return PA_FORMAT_GIF; } - else - { - res = PA_FORMAT_UNKNOWN; - *ext = _T("unk"); - } - return res; + + *ext = _T("unk"); + return PA_FORMAT_UNKNOWN; } int MSN_GetImageFormat(const TCHAR* file) @@ -377,8 +377,7 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen MSN_GetAvatarFileName(NULL, szFileName, SIZEOF(szFileName), szExt); int fileId = _topen(szFileName, _O_CREAT | _O_TRUNC | _O_WRONLY | O_BINARY, _S_IREAD | _S_IWRITE); - if (fileId >= 0) - { + if (fileId >= 0) { _write(fileId, pData, (unsigned)cbLen); _close(fileId); @@ -392,8 +391,7 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen } mir_free(szAvatarHash); } - else - MSN_ShowError("Cannot set avatar. File '%s' could not be created/overwritten", szFileName); + else MSN_ShowError("Cannot set avatar. File '%s' could not be created/overwritten", szFileName); return fmt; } @@ -408,16 +406,14 @@ void CMsnProto::MSN_GetCustomSmileyFileName(HANDLE hContact, TCHAR* pszDest, si InitCustomFolders(); TCHAR* path = (TCHAR*)alloca(cbLen * sizeof(TCHAR)); - if (hCustomSmileyFolder == NULL || FoldersGetCustomPathT(hCustomSmileyFolder, path, (int)cbLen, _T(""))) - { + if (hCustomSmileyFolder == NULL || FoldersGetCustomPathT(hCustomSmileyFolder, path, (int)cbLen, _T(""))) { TCHAR *tmpPath = Utils_ReplaceVarsT(_T("%miranda_userdata%")); TCHAR *tszModuleName = mir_a2t(m_szModuleName); tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%s\\CustomSmiley"), tmpPath, tszModuleName); mir_free(tszModuleName); mir_free(tmpPath); } - else - { + else { _tcscpy(pszDest, path); tPathLen = _tcslen(pszDest); } @@ -435,8 +431,7 @@ void CMsnProto::MSN_GetCustomSmileyFileName(HANDLE hContact, TCHAR* pszDest, si tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), dbv.ptszVal); DBFreeVariant(&dbv); } - else - { + else { TCHAR *tszModuleName = mir_a2t(m_szModuleName); tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), tszModuleName); mir_free(tszModuleName); @@ -444,8 +439,7 @@ void CMsnProto::MSN_GetCustomSmileyFileName(HANDLE hContact, TCHAR* pszDest, si bool exist = _taccess(pszDest, 0) == 0; - if (type == 0) - { + if (type == 0) { if (!exist) pszDest[0] = 0; return; } @@ -482,20 +476,17 @@ void CMsnProto::MSN_GoOffline(void) MsgQueue_Clear(); clearCachedMsg(); - if (!Miranda_Terminated()) - { + if (!Miranda_Terminated()) { int msnOldStatus = m_iStatus; m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; SendBroadcast(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)msnOldStatus, ID_STATUS_OFFLINE); isIdle = false; int count = -1; - for (;;) - { + for (;;) { MsnContact *msc = Lists_GetNext(count); if (msc == NULL) break; - if (ID_STATUS_OFFLINE != getWord(msc->hContact, "Status", ID_STATUS_OFFLINE)) - { + if (ID_STATUS_OFFLINE != getWord(msc->hContact, "Status", ID_STATUS_OFFLINE)) { setWord(msc->hContact, "Status", ID_STATUS_OFFLINE); setDword(msc->hContact, "IdleTS", 0); } @@ -513,20 +504,17 @@ int ThreadData::sendMessage(int msgType, const char* email, int netId, const cha off = mir_snprintf(buf, sizeof(buf), "MIME-Version: 1.0\r\n"); - if ((parFlags & MSG_DISABLE_HDR) == 0) - { + if ((parFlags & MSG_DISABLE_HDR) == 0) { char tFontName[100], tFontStyle[3]; DWORD tFontColor; strcpy(tFontName, "Arial"); - if (proto->getByte("SendFontInfo", 1)) - { + if (proto->getByte("SendFontInfo", 1)) { char* p; DBVARIANT dbv; - if (!DBGetContactSettingString(NULL, "SRMsg", "Font0", &dbv)) - { + if (!DBGetContactSettingString(NULL, "SRMsg", "Font0", &dbv)) { for (p = dbv.pszVal; *p; p++) if (BYTE(*p) >= 128 || *p < 32) break; @@ -546,8 +534,7 @@ int ThreadData::sendMessage(int msgType, const char* email, int netId, const cha tFontColor = DBGetContactSettingDword(NULL, "SRMsg", "Font0Col", 0); } - else - { + else { tFontColor = 0; tFontStyle[0] = 0; } @@ -682,8 +669,7 @@ void CMsnProto::MSN_SendStatusMessage(const char* msg) size_t sz; char szMsg[2048]; - if (msnCurrentMedia.cbSize == 0) - { + if (msnCurrentMedia.cbSize == 0) { sz = mir_snprintf(szMsg, sizeof(szMsg), "%s%s" "", msgEnc, MyOptions.szMachineGuid); @@ -691,8 +677,7 @@ void CMsnProto::MSN_SendStatusMessage(const char* msg) else { char *szFormatEnc; - if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)) - { + if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)) { LISTENINGTOINFO lti = {0}; lti.cbSize = sizeof(lti); if (msnCurrentMedia.ptszTitle != NULL) lti.ptszTitle = _T("{0}"); @@ -746,8 +731,7 @@ void CMsnProto::MSN_SendStatusMessage(const char* msg) } mir_free(msgEnc); - if (msnPreviousUUX == NULL || strcmp(msnPreviousUUX, szMsg)) - { + if (msnPreviousUUX == NULL || strcmp(msnPreviousUUX, szMsg)) { replaceStr(msnPreviousUUX, szMsg); msnNsThread->sendPacket("UUX", "%d\r\n%s", sz, szMsg); mStatusMsgTS = clock(); @@ -768,8 +752,7 @@ int ThreadData::sendPacket(const char* cmd, const char* fmt,...) if (fmt == NULL) mir_snprintf(str, strsize, "%s", cmd); - else - { + else { thisTrid = InterlockedIncrement(&mTrid); if (fmt[0] == '\0') mir_snprintf(str, strsize, "%s %d", cmd, thisTrid); diff --git a/protocols/MSN/src/msn_msgqueue.cpp b/protocols/MSN/src/msn_msgqueue.cpp index eeafdfea2f..f897a70513 100644 --- a/protocols/MSN/src/msn_msgqueue.cpp +++ b/protocols/MSN/src/msn_msgqueue.cpp @@ -41,7 +41,7 @@ int CMsnProto::MsgQueue_Add(const char* wlid, int msgType, const char* msg, int EnterCriticalSection(&csMsgQueue); MsgQueueEntry* E = new MsgQueueEntry; - msgQueueList.insert(E); + lsMessageQueue.insert(E); int seq = msgQueueSeq++; @@ -70,9 +70,9 @@ const char* CMsnProto::MsgQueue_CheckContact(const char* wlid, time_t tsc) time_t ts = time(NULL); const char* ret = NULL; - for (int i=0; i < msgQueueList.getCount(); i++) + for (int i=0; i < lsMessageQueue.getCount(); i++) { - if (_stricmp(msgQueueList[i].wlid, wlid) == 0 && (tsc == 0 || (ts - msgQueueList[i].ts) < tsc)) + if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0 && (tsc == 0 || (ts - lsMessageQueue[i].ts) < tsc)) { ret = wlid; break; @@ -89,17 +89,17 @@ const char* CMsnProto::MsgQueue_GetNextRecipient(void) EnterCriticalSection(&csMsgQueue); const char* ret = NULL; - for (int i=0; i < msgQueueList.getCount(); i++) + for (int i=0; i < lsMessageQueue.getCount(); i++) { - MsgQueueEntry& E = msgQueueList[i]; + MsgQueueEntry& E = lsMessageQueue[i]; if (!E.allocatedToThread) { E.allocatedToThread = 1; ret = E.wlid; - while(++i < msgQueueList.getCount()) - if (_stricmp(msgQueueList[i].wlid, ret) == 0) - msgQueueList[i].allocatedToThread = 1; + while(++i < lsMessageQueue.getCount()) + if (_stricmp(lsMessageQueue[i].wlid, ret) == 0) + lsMessageQueue[i].allocatedToThread = 1; break; } @@ -115,15 +115,15 @@ bool CMsnProto::MsgQueue_GetNext(const char* wlid, MsgQueueEntry& retVal) int i; EnterCriticalSection(&csMsgQueue); - for(i=0; i < msgQueueList.getCount(); i++) - if (_stricmp(msgQueueList[i].wlid, wlid) == 0) + for(i=0; i < lsMessageQueue.getCount(); i++) + if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0) break; - bool res = i != msgQueueList.getCount(); + bool res = i != lsMessageQueue.getCount(); if (res) { - retVal = msgQueueList[i]; - msgQueueList.remove(i); + retVal = lsMessageQueue[i]; + lsMessageQueue.remove(i); } LeaveCriticalSection(&csMsgQueue); return res; @@ -134,8 +134,8 @@ int CMsnProto::MsgQueue_NumMsg(const char* wlid) int res = 0; EnterCriticalSection(&csMsgQueue); - for(int i=0; i < msgQueueList.getCount(); i++) - res += (_stricmp(msgQueueList[i].wlid, wlid) == 0); + for(int i=0; i < lsMessageQueue.getCount(); i++) + res += (_stricmp(lsMessageQueue[i].wlid, wlid) == 0); LeaveCriticalSection(&csMsgQueue); return res; @@ -149,9 +149,9 @@ void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg) if (wlid == NULL) { - for(i=0; i < msgQueueList.getCount(); i++) + for(i=0; i < lsMessageQueue.getCount(); i++) { - const MsgQueueEntry& E = msgQueueList[i]; + const MsgQueueEntry& E = lsMessageQueue[i]; if (E.msgSize == 0) { HANDLE hContact = MSN_HContactFromEmail(E.wlid); @@ -162,17 +162,17 @@ void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg) mir_free(E.wlid); if (E.cont) delete E.cont; } - msgQueueList.destroy(); + lsMessageQueue.destroy(); msgQueueSeq = 1; } else { - for(i=0; i < msgQueueList.getCount(); i++) + for(i=0; i < lsMessageQueue.getCount(); i++) { time_t ts = time(NULL); - const MsgQueueEntry& E = msgQueueList[i]; - if (_stricmp(msgQueueList[i].wlid, wlid) == 0 && (!msg || E.msgSize == 0)) + 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; @@ -180,7 +180,7 @@ void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg) mir_free(E.message); mir_free(E.wlid); if (E.cont) delete E.cont; - msgQueueList.remove(i); + lsMessageQueue.remove(i); if (msgfnd) { diff --git a/protocols/MSN/src/msn_p2ps.cpp b/protocols/MSN/src/msn_p2ps.cpp index a3b5965ac8..58edbc2d05 100644 --- a/protocols/MSN/src/msn_p2ps.cpp +++ b/protocols/MSN/src/msn_p2ps.cpp @@ -153,9 +153,7 @@ filetransfer* CMsnProto::p2p_getAvatarSession(HANDLE hContact) for (int i=0; i < sessionList.getCount(); i++) { filetransfer* FT = &sessionList[i]; - if (FT->std.hContact == hContact && !(FT->std.flags & PFTS_SENDING) && - FT->p2p_type == MSN_APPID_AVATAR) - { + if (FT->std.hContact == hContact && !(FT->std.flags & PFTS_SENDING) && FT->p2p_type == MSN_APPID_AVATAR) { result = FT; break; } diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index 1dcd243fb5..3a51666910 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -37,7 +37,8 @@ CMsnProto::CMsnProto(const char* aProtoName, const TCHAR* aUserName) : sttThreads(10, PtrKeySortT), sessionList(10, PtrKeySortT), dcList(10, PtrKeySortT), - msgQueueList(1), + lsMessageQueue(1), + lsAvatarQueue(1), msgCache(5, CompareId) { char path[MAX_PATH]; diff --git a/protocols/MSN/src/msn_proto.h b/protocols/MSN/src/msn_proto.h index c46c5f0665..ecf8c85b97 100644 --- a/protocols/MSN/src/msn_proto.h +++ b/protocols/MSN/src/msn_proto.h @@ -146,7 +146,10 @@ struct CMsnProto : public PROTO_INTERFACE, public MZeroedObject CRITICAL_SECTION csMsgQueue; int msgQueueSeq; - OBJLIST msgQueueList; + OBJLIST lsMessageQueue; + + CRITICAL_SECTION csAvatarQueue; + OBJLIST lsAvatarQueue; LONG sttChatID; @@ -202,6 +205,7 @@ struct CMsnProto : public PROTO_INTERFACE, public MZeroedObject void MSN_GoOffline(void); void MSN_GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext); + void pushAvatarRequest(HANDLE hContact, LPCSTR pszUrl); int MSN_SetMyAvatar(const TCHAR* szFname, void* pData, size_t cbLen); void MSN_GetCustomSmileyFileName(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const char* SmileyName, int Type); diff --git a/protocols/MSN/src/msn_svcs.cpp b/protocols/MSN/src/msn_svcs.cpp index 806be891dc..5a4ec5404a 100644 --- a/protocols/MSN/src/msn_svcs.cpp +++ b/protocols/MSN/src/msn_svcs.cpp @@ -65,8 +65,7 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam,LPARAM lParam) TCHAR filename[MAX_PATH]; MsnContact *cont = NULL; - if (AI->hContact) - { + if (AI->hContact) { cont = Lists_Get(AI->hContact); if (cont == NULL) return GAIR_NOAVATAR; @@ -74,43 +73,38 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam,LPARAM lParam) return GAIR_NOAVATAR; } - if (AI->hContact == NULL || _stricmp(cont->email, MyOptions.szEmail) == 0) - { + if (AI->hContact == NULL || _stricmp(cont->email, MyOptions.szEmail) == 0) { MSN_GetAvatarFileName(NULL, filename, SIZEOF(filename), NULL); AI->format = MSN_GetImageFormat(filename); - if (AI->format != PA_FORMAT_UNKNOWN) _tcscpy(AI->filename, filename); + if (AI->format != PA_FORMAT_UNKNOWN) + _tcscpy(AI->filename, filename); return AI->format == PA_FORMAT_UNKNOWN ? GAIR_NOAVATAR : GAIR_SUCCESS; } char *szContext; DBVARIANT dbv; - if (getString(AI->hContact, AI->hContact ? "PictContext" : "PictObject", &dbv) == 0) - { + if ( getString(AI->hContact, AI->hContact ? "PictContext" : "PictObject", &dbv) == 0) { szContext = (char*)NEWSTR_ALLOCA(dbv.pszVal); MSN_FreeVariant(&dbv); } - else - return GAIR_NOAVATAR; + else return GAIR_NOAVATAR; MSN_GetAvatarFileName(AI->hContact, filename, SIZEOF(filename), NULL); AI->format = MSN_GetImageFormat(filename); - if (AI->format != PA_FORMAT_UNKNOWN) - { + if (AI->format != PA_FORMAT_UNKNOWN) { bool needupdate = true; - if (getString(AI->hContact, "PictSavedContext", &dbv) == 0) - { + if (getString(AI->hContact, "PictSavedContext", &dbv) == 0) { needupdate = strcmp(dbv.pszVal, szContext) != 0; MSN_FreeVariant(&dbv); } - if (needupdate) - { + + if (needupdate) { setString(AI->hContact, "PictSavedContext", szContext); // Store also avatar hash char* szAvatarHash = MSN_GetAvatarHash(szContext); - if (szAvatarHash != NULL) - { + if (szAvatarHash != NULL) { setString(AI->hContact, "AvatarSavedHash", szAvatarHash); mir_free(szAvatarHash); } @@ -119,33 +113,33 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam,LPARAM lParam) return GAIR_SUCCESS; } - if ((wParam & GAIF_FORCE) != 0 && AI->hContact != NULL) - { + if ((wParam & GAIF_FORCE) != 0 && AI->hContact != NULL) { if (avsPresent < 0) avsPresent = ServiceExists(MS_AV_SETMYAVATAR) != 0; - if (!avsPresent) return GAIR_NOAVATAR; + if (!avsPresent) + return GAIR_NOAVATAR; WORD wStatus = getWord(AI->hContact, "Status", ID_STATUS_OFFLINE); - if (wStatus == ID_STATUS_OFFLINE) - { + if (wStatus == ID_STATUS_OFFLINE) { deleteSetting(AI->hContact, "AvatarHash"); PROTO_AVATAR_INFORMATIONT* fakeAI = new PROTO_AVATAR_INFORMATIONT; *fakeAI = *AI; ForkThread(&CMsnProto::sttFakeAvatarAck, fakeAI); } - else - { - if (p2p_getAvatarSession(AI->hContact) == NULL) - { - filetransfer* ft = new filetransfer(this); - ft->std.hContact = AI->hContact; - ft->p2p_object = mir_strdup(szContext); + else if ( !getString(AI->hContact, "AvatarUrl", &dbv)) { + pushAvatarRequest(AI->hContact, dbv.pszVal); + db_free(&dbv); + } + else if (p2p_getAvatarSession(AI->hContact) == NULL) { + filetransfer* ft = new filetransfer(this); + ft->std.hContact = AI->hContact; + ft->p2p_object = mir_strdup(szContext); - MSN_GetAvatarFileName(AI->hContact, filename, SIZEOF(filename), _T("unk")); - ft->std.tszCurrentFile = mir_tstrdup(filename); + MSN_GetAvatarFileName(AI->hContact, filename, SIZEOF(filename), _T("unk")); + ft->std.tszCurrentFile = mir_tstrdup(filename); - p2p_invite(MSN_APPID_AVATAR, ft, NULL); - } + p2p_invite(MSN_APPID_AVATAR, ft, NULL); } + return GAIR_WAITFOR; } return GAIR_NOAVATAR; -- cgit v1.2.3