summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2013-04-13 19:59:11 +0000
committerAlexander Lantsev <aunsane@gmail.com>2013-04-13 19:59:11 +0000
commit51b5164fd6c0ea0de58e4398e515dd73a0e12620 (patch)
tree94bed44c33f9c186f0110feadb56c1403ddf59cd /protocols
parent241aed20d47fe5e443370cd6224b5b2e844348d3 (diff)
- fix some own avatar get/set bugs
git-svn-id: http://svn.miranda-ng.org/main/trunk@4449 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Skype/src/skype_menus.cpp2
-rw-r--r--protocols/Skype/src/skype_profile.cpp30
-rw-r--r--protocols/Skype/src/skype_proto.cpp14
-rw-r--r--protocols/Skype/src/skype_proto.h4
-rw-r--r--protocols/Skype/src/skype_services.cpp39
-rw-r--r--protocols/Skype/src/skype_utils.cpp11
6 files changed, 62 insertions, 38 deletions
diff --git a/protocols/Skype/src/skype_menus.cpp b/protocols/Skype/src/skype_menus.cpp
index c9d6468427..ae01acf95a 100644
--- a/protocols/Skype/src/skype_menus.cpp
+++ b/protocols/Skype/src/skype_menus.cpp
@@ -206,7 +206,7 @@ void CSkypeProto::OnInitStatusMenu()
// Invite Command
strcpy(tDest, "/InviteCommand");
- this->CreateService(tDest, &CSkypeProto::InviteCommand);
+ this->CreateServiceObj(tDest, &CSkypeProto::InviteCommand);
mi.ptszName = LPGENT("Invite to conference");
mi.position = 200001;
mi.icolibItem = CSkypeProto::GetIconHandle("confInvite");
diff --git a/protocols/Skype/src/skype_profile.cpp b/protocols/Skype/src/skype_profile.cpp
index c7ecd37e5d..ea35f7e482 100644
--- a/protocols/Skype/src/skype_profile.cpp
+++ b/protocols/Skype/src/skype_profile.cpp
@@ -11,7 +11,7 @@ void CSkypeProto::UpdateProfileAvatar(SEObject *obj, HANDLE hContact)
//if ((newTS > oldTS) || (!newTS && data.size() > 0 && _waccess(path, 0) == -1) || (newTS && _waccess(path, 0) == -1)) //hack for avatars without timestamp
bool hasNewAvatar = newTS > oldTS;
bool isAvatarEmpty = data.size() == 0;
- bool isAvatarFileExists = ::PathFileExists(path);
+ bool isAvatarFileExists = ::PathFileExists(path) > 0;
if ( !isAvatarEmpty)
{
if (hasNewAvatar || !isAvatarFileExists)
@@ -24,13 +24,24 @@ void CSkypeProto::UpdateProfileAvatar(SEObject *obj, HANDLE hContact)
this->SetSettingDword("AvatarTS", newTS);
- PROTO_AVATAR_INFORMATIONW pai = {0};
- pai.cbSize = sizeof(pai);
- pai.format = PA_FORMAT_JPEG;
- pai.hContact = hContact;
- ::wcscpy(pai.filename, path);
-
- this->SendBroadcast(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
+ if (hContact)
+ {
+ PROTO_AVATAR_INFORMATIONW pai = {0};
+ pai.cbSize = sizeof(pai);
+ pai.format = PA_FORMAT_JPEG;
+ pai.hContact = hContact;
+ ::wcscpy(pai.filename, path);
+
+ this->SendBroadcast(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
+ }
+ else
+ {
+ ::mir_md5_byte_t digest[16];
+ ::mir_md5_hash((BYTE*)data.data(), data.size(), digest);
+ ::db_set_blob(hContact, this->m_szModuleName, "AvatarHash", digest, 16);
+
+ ::CallService(MS_AV_SETMYAVATART, (WPARAM)m_szModuleName, (LPARAM)path);
+ }
}
}
}
@@ -288,10 +299,11 @@ void CSkypeProto::UpdateProfileTimezone(SEObject *obj, HANDLE hContact)
void CSkypeProto::UpdateProfile(SEObject *obj, HANDLE hContact)
{
+ this->UpdateProfileAvatar(obj, hContact);
+
uint newTS = obj->GetUintProp(/* *::P_PROFILE_TIMESTAMP */ 19);
if (newTS > this->GetSettingDword("ProfileTS"))
{
- this->UpdateProfileAvatar(obj, hContact);
this->UpdateProfileAboutText(obj, hContact);
this->UpdateProfileBirthday(obj, hContact);
this->UpdateProfileCity(obj, hContact);
diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp
index 3fc58b3cc2..c418556ef4 100644
--- a/protocols/Skype/src/skype_proto.cpp
+++ b/protocols/Skype/src/skype_proto.cpp
@@ -13,15 +13,15 @@ CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) : fileTra
this->signin_lock = CreateMutex(0, false, 0);
this->SetAllContactStatus(ID_STATUS_OFFLINE);
- this->CreateService(PS_CREATEACCMGRUI, &CSkypeProto::OnAccountManagerInit);
+ this->CreateServiceObj(PS_CREATEACCMGRUI, &CSkypeProto::OnAccountManagerInit);
// Chat API
- this->CreateService(PS_JOINCHAT, &CSkypeProto::OnJoinChat);
- this->CreateService(PS_LEAVECHAT, &CSkypeProto::OnLeaveChat);
+ this->CreateServiceObj(PS_JOINCHAT, &CSkypeProto::OnJoinChat);
+ this->CreateServiceObj(PS_LEAVECHAT, &CSkypeProto::OnLeaveChat);
// Avatar API
- this->CreateService(PS_GETAVATARINFOT, &CSkypeProto::GetAvatarInfo);
- this->CreateService(PS_GETAVATARCAPS, &CSkypeProto::GetAvatarCaps);
- this->CreateService(PS_GETMYAVATART, &CSkypeProto::GetMyAvatar);
- this->CreateService(PS_SETMYAVATART, &CSkypeProto::SetMyAvatar);
+ this->CreateServiceObj(PS_GETAVATARINFOT, &CSkypeProto::GetAvatarInfo);
+ this->CreateServiceObj(PS_GETAVATARCAPS, &CSkypeProto::GetAvatarCaps);
+ this->CreateServiceObj(PS_GETMYAVATART, &CSkypeProto::GetMyAvatar);
+ this->CreateServiceObj(PS_SETMYAVATART, &CSkypeProto::SetMyAvatar);
}
CSkypeProto::~CSkypeProto()
diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h
index 7ac8b89ff0..b1f37b3147 100644
--- a/protocols/Skype/src/skype_proto.h
+++ b/protocols/Skype/src/skype_proto.h
@@ -438,8 +438,8 @@ protected:
static LIST<CSkypeProto> instanceList;
static int CompareProtos(const CSkypeProto *p1, const CSkypeProto *p2);
- void CreateService(const char* szService, SkypeServiceFunc serviceProc);
- void CreateServiceParam(const char* szService, SkypeServiceFunc serviceProc, LPARAM lParam);
+ void CreateServiceObj(const char* szService, SkypeServiceFunc serviceProc);
+ void CreateServiceObjParam(const char* szService, SkypeServiceFunc serviceProc, LPARAM lParam);
HANDLE CreateEvent(const char* szService);
void HookEvent(const char*, SkypeEventFunc);
diff --git a/protocols/Skype/src/skype_services.cpp b/protocols/Skype/src/skype_services.cpp
index 3b03b13807..509b3e422e 100644
--- a/protocols/Skype/src/skype_services.cpp
+++ b/protocols/Skype/src/skype_services.cpp
@@ -80,14 +80,13 @@ INT_PTR __cdecl CSkypeProto::GetMyAvatar(WPARAM wParam, LPARAM lParam)
if (!wParam) return -2;
wchar_t *path = this->GetContactAvatarFilePath(NULL);
- if (path && !_waccess(path, 0))
+ if (path && ::PathFileExists(path))
{
::wcsncpy((wchar_t *)wParam, path, (int)lParam);
delete path;
return 0;
}
- delete path;
return -1;
}
@@ -98,14 +97,6 @@ INT_PTR __cdecl CSkypeProto::SetMyAvatar(WPARAM, LPARAM lParam)
if (path)
{
- /*int dwPaFormat = CSkypeProto::DetectAvatarFormat(path);
- if (dwPaFormat != PA_FORMAT_XML)
- {
- HBITMAP avt = (HBITMAP)::CallService(MS_UTILS_LOADBITMAPT, 0, (WPARAM)path);
- if (!avt) return iRet;
- ::DeleteObject(avt);
- }*/
-
wchar_t *avatarPath = this->GetContactAvatarFilePath(NULL);
if (::wcscmp(path, avatarPath) && !::CopyFile(path, avatarPath, FALSE))
{
@@ -115,18 +106,34 @@ INT_PTR __cdecl CSkypeProto::SetMyAvatar(WPARAM, LPARAM lParam)
int len;
char *buffer;
- FILE* fp = _wfopen(avatarPath, L"rb");
+ FILE* fp = ::_wfopen(avatarPath, L"rb");
if (!fp)
{
this->Log(L"Failed to read avatar in local storage.");
return iRet;
}
- fseek(fp, 0, SEEK_END);
- len = ftell(fp);
- fseek(fp, 0, SEEK_SET);
+ ::fseek(fp, 0, SEEK_END);
+ len = ::ftell(fp);
+ ::fseek(fp, 0, SEEK_SET);
buffer = new char[len + 1];
- fread(buffer, len, 1, fp);
- fclose(fp);
+ ::fread(buffer, len, 1, fp);
+ ::fclose(fp);
+
+ ::mir_md5_byte_t digest[16];
+ ::mir_md5_hash((BYTE*)buffer, len, digest);
+
+ DBVARIANT dbv;
+ ::db_get(NULL, this->m_szModuleName, "AvatarHash", &dbv);
+ if (dbv.type == DBVT_BLOB && dbv.pbVal && dbv.cpbVal == 16)
+ {
+ if (::memcmp(digest, dbv.pbVal, 16) == 0)
+ {
+ ::db_free(&dbv);
+ delete [] buffer;
+ return 0;
+ }
+ }
+ ::db_free(&dbv);
int fbl;
SEBinary avatar(buffer, len);
diff --git a/protocols/Skype/src/skype_utils.cpp b/protocols/Skype/src/skype_utils.cpp
index 03ddc08302..acc1ef33c5 100644
--- a/protocols/Skype/src/skype_utils.cpp
+++ b/protocols/Skype/src/skype_utils.cpp
@@ -344,7 +344,7 @@ wchar_t* CSkypeProto::GetContactAvatarFilePath(HANDLE hContact)
{
wchar_t *tmpPath = ::Utils_ReplaceVarsT(L"%miranda_avatarcache%");
::mir_sntprintf(path, MAX_PATH, _T("%s\\%S"), tmpPath, this->m_szModuleName);
- mir_free(tmpPath);
+ ::mir_free(tmpPath);
}
DWORD dwAttributes = GetFileAttributes(path);
@@ -356,6 +356,11 @@ wchar_t* CSkypeProto::GetContactAvatarFilePath(HANDLE hContact)
::mir_sntprintf(path, MAX_PATH, _T("%s\\%s.jpg"), path, sid);
else if (sid != NULL)
::mir_sntprintf(path, MAX_PATH, _T("%s\\%s avatar.jpg"), path, sid);
+ else
+ {
+ delete path;
+ return NULL;
+ }
return path;
}
@@ -365,7 +370,7 @@ int CSkypeProto::CompareProtos(const CSkypeProto *p1, const CSkypeProto *p2)
return wcscmp(p1->m_tszUserName, p2->m_tszUserName);
}
-void CSkypeProto::CreateService(const char* szService, SkypeServiceFunc serviceProc)
+void CSkypeProto::CreateServiceObj(const char* szService, SkypeServiceFunc serviceProc)
{
char moduleName[MAXMODULELABELLENGTH];
@@ -373,7 +378,7 @@ void CSkypeProto::CreateService(const char* szService, SkypeServiceFunc serviceP
::CreateServiceFunctionObj(moduleName, (MIRANDASERVICEOBJ)*(void**)&serviceProc, this);
}
-void CSkypeProto::CreateServiceParam(const char* szService, SkypeServiceFunc serviceProc, LPARAM lParam)
+void CSkypeProto::CreateServiceObjParam(const char* szService, SkypeServiceFunc serviceProc, LPARAM lParam)
{
char moduleName[MAXMODULELABELLENGTH];