From 25fb34c76a42858dc732250b769bb08324d3a996 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 28 Oct 2012 19:35:19 +0000 Subject: - fixed some issues in own info loading - fixed avatar services git-svn-id: http://svn.miranda-ng.org/main/trunk@2105 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Skype/docs/todo_list.txt | 2 +- protocols/Skype/src/skype.h | 5 +- protocols/Skype/src/skype_contacts.cpp | 2 +- protocols/Skype/src/skype_profile.cpp | 25 ++++++++-- protocols/Skype/src/skype_proto.cpp | 5 ++ protocols/Skype/src/skype_proto.h | 14 +++--- protocols/Skype/src/skype_services.cpp | 91 ++++++++++++---------------------- protocols/Skype/src/skype_utils.cpp | 46 ++++++++++++----- 8 files changed, 106 insertions(+), 84 deletions(-) diff --git a/protocols/Skype/docs/todo_list.txt b/protocols/Skype/docs/todo_list.txt index 4412a2f97f..e23997e629 100644 --- a/protocols/Skype/docs/todo_list.txt +++ b/protocols/Skype/docs/todo_list.txt @@ -2,7 +2,7 @@ Bugs: - don't send auth request Features: -- own info(profile) +- add avatar loading to skype server - multiuser chat - voice - video diff --git a/protocols/Skype/src/skype.h b/protocols/Skype/src/skype.h index 08dfd5dd8c..398a3ad2b8 100644 --- a/protocols/Skype/src/skype.h +++ b/protocols/Skype/src/skype.h @@ -41,6 +41,9 @@ //#pragma warning(pop) #include +#include +#include + #include #include @@ -58,7 +61,7 @@ extern "C" #define SKYPE_PASSWORD_LIMIT 128 #define SKYPE_SETTINGS_NAME "Name" #define SKYPE_SETTINGS_STATUS "Status" -#define SKYPE_SETTINGS_LOGIN "SkypeLogin" +#define SKYPE_SETTINGS_LOGIN "sid" #define SKYPE_SETTINGS_PASSWORD "Password" #define SKYPE_SEARCH_BYSID 1001 diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp index 26e3ea530c..a83ee412da 100644 --- a/protocols/Skype/src/skype_contacts.cpp +++ b/protocols/Skype/src/skype_contacts.cpp @@ -76,9 +76,9 @@ void CSkypeProto::UpdateContactBirthday(HANDLE hContact, CContact::Ref contact) uint data; contact->GetPropBirthday(data); TCHAR date[9]; - _itot_s(data, date, 10); if (data > 0) { + _itot_s(data, date, 10); INT day, month, year; _stscanf(date, _T("%04d%02d%02d"), &year, &month, &day); this->SetSettingByte(hContact, "BirthDay", day); diff --git a/protocols/Skype/src/skype_profile.cpp b/protocols/Skype/src/skype_profile.cpp index 884a145358..a0e72d1f37 100644 --- a/protocols/Skype/src/skype_profile.cpp +++ b/protocols/Skype/src/skype_profile.cpp @@ -8,11 +8,28 @@ void CSkypeProto::UpdateOwnAvatar() if (newTS > oldTS) { SEBinary data; - //this->account->GetPropAvatarImage(data); + this->account->GetPropAvatarImage(data); - //if (data.size() > 0) + if (data.size() > 0) { - // todo: add own avatar loading'n'registration + wchar_t *path = this->GetContactAvatarFilePath(this->GetSettingString("sid")); + FILE* fp = _wfopen(path, L"wb"); + if (fp) + { + fwrite(data.data(), sizeof(char), data.size(), fp); + fclose(fp); + + this->SetSettingDword("AvatarTS", newTS); + + PROTO_AVATAR_INFORMATIONW pai = {0}; + pai.cbSize = sizeof(pai); + pai.format = PA_FORMAT_JPEG; + pai.hContact = NULL; + wcscpy(pai.filename, path); + + this->SendBroadcast(ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0); + } + delete path; } } } @@ -22,9 +39,9 @@ void CSkypeProto::UpdateOwnBirthday() uint data; this->account->GetPropBirthday(data); TCHAR date[9]; - _itot_s(data, date, 10); if (data > 0) { + _itot_s(data, date, 10); INT day, month, year; _stscanf(date, _T("%04d%02d%02d"), &year, &month, &day); this->SetSettingByte("BirthDay", day); diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp index d66a054e96..7a46169cb0 100644 --- a/protocols/Skype/src/skype_proto.cpp +++ b/protocols/Skype/src/skype_proto.cpp @@ -18,6 +18,11 @@ CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) this->SetAllContactStatus(ID_STATUS_OFFLINE); this->CreateService(PS_CREATEACCMGRUI, &CSkypeProto::OnAccountManagerInit); + // 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->InitNetLib(); } diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index aee81b58c7..e4514f1668 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -199,8 +199,10 @@ protected: // utils static void FakeAsync(void*); - wchar_t* GetOwnAvatarFilePath(); - wchar_t* GetContactAvatarFilePath(wchar_t* skypeName); + static int DetectAvatarFormatBuffer(const char *pBuffer); + static int DetectAvatarFormat(const wchar_t *path); + + wchar_t* GetContactAvatarFilePath(HANDLE hContact = 0); int SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason); @@ -232,10 +234,10 @@ protected: // services static LIST serviceList; - int GetAvatarInfo(WPARAM, LPARAM); - int GetAvatarCaps(WPARAM, LPARAM); - int GetMyAvatar(WPARAM, LPARAM); - int SetMyAvatar(WPARAM, LPARAM); + int __cdecl GetAvatarInfo(WPARAM, LPARAM); + int __cdecl GetAvatarCaps(WPARAM, LPARAM); + int __cdecl GetMyAvatar(WPARAM, LPARAM); + int __cdecl SetMyAvatar(WPARAM, LPARAM); // icons static _tag_iconList iconList[]; diff --git a/protocols/Skype/src/skype_services.cpp b/protocols/Skype/src/skype_services.cpp index a06f64dd0d..c9b140b4d0 100644 --- a/protocols/Skype/src/skype_services.cpp +++ b/protocols/Skype/src/skype_services.cpp @@ -8,7 +8,7 @@ void CSkypeProto::InitServiceList() ::CreateServiceFunction("Skype/MenuChoose", CSkypeProto::MenuChooseService)); } -int CSkypeProto::GetAvatarInfo(WPARAM, LPARAM lParam) +int __cdecl CSkypeProto::GetAvatarInfo(WPARAM, LPARAM lParam) { PROTO_AVATAR_INFORMATIONW *pai = (PROTO_AVATAR_INFORMATIONW*)lParam; @@ -32,7 +32,7 @@ int CSkypeProto::GetAvatarInfo(WPARAM, LPARAM lParam) return GAIR_NOAVATAR; } -int CSkypeProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) +int __cdecl CSkypeProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) { switch (wParam) { @@ -76,11 +76,11 @@ int CSkypeProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) return 0; } -int CSkypeProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) +int __cdecl CSkypeProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) { if (!wParam) return -2; - wchar_t *path = this->GetOwnAvatarFilePath(); + wchar_t *path = this->GetContactAvatarFilePath(); if (path && !_waccess(path, 0)) { ::wcsncpy((wchar_t *)wParam, path, (int)lParam); @@ -92,64 +92,39 @@ int CSkypeProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) return -1; } -int CSkypeProto::SetMyAvatar(WPARAM, LPARAM lParam) +int __cdecl CSkypeProto::SetMyAvatar(WPARAM, LPARAM lParam) { wchar_t *path = (wchar_t *)lParam; int iRet = -1; - //if (path) - //{ // set file for avatar - // int dwPaFormat = DetectAvatarFormat(tszFile); - // if (dwPaFormat != PA_FORMAT_XML) - // { - // // if it should be image, check if it is valid - // HBITMAP avt = (HBITMAP)CallService(MS_UTILS_LOADBITMAPT, 0, (WPARAM)tszFile); - // if (!avt) return iRet; - // DeleteObject(avt); - // } - - // TCHAR tszMyFile[MAX_PATH+1]; - // GetFullAvatarFileName(0, NULL, dwPaFormat, tszMyFile, MAX_PATH); - // // if not in our storage, copy - // if (lstrcmp(tszFile, tszMyFile) && !CopyFile(tszFile, tszMyFile, FALSE)) - // { - // NetLog_Server("Failed to copy our avatar to local storage."); - // return iRet; - // } - - // BYTE *hash = calcMD5HashOfFile(tszMyFile); - // if (hash) - // { - // BYTE* ihash = (BYTE*)_alloca(0x14); - // // upload hash to server - // ihash[0] = 0; //unknown - // ihash[1] = dwPaFormat == PA_FORMAT_XML ? AVATAR_HASH_FLASH : AVATAR_HASH_STATIC; //hash type - // ihash[2] = 1; //hash status - // ihash[3] = 0x10; //hash len - // memcpy(ihash+4, hash, 0x10); - // updateServAvatarHash(ihash, 0x14); - - // if (setSettingBlob(NULL, "AvatarHash", ihash, 0x14)) - // { - // NetLog_Server("Failed to save avatar hash."); - // } - - // TCHAR tmp[MAX_PATH]; - // CallService(MS_UTILS_PATHTORELATIVET, (WPARAM)tszMyFile, (LPARAM)tmp); - // setSettingStringT(NULL, "AvatarFile", tmp); - - // iRet = 0; - - // SAFE_FREE((void**)&hash); - // } - //} - //else - //{ // delete user avatar - // deleteSetting(NULL, "AvatarFile"); - // setSettingBlob(NULL, "AvatarHash", hashEmptyAvatar, 9); - // updateServAvatarHash(hashEmptyAvatar, 9); // set blank avatar - // iRet = 0; - //} + 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(); + if (::wcscmp(path, avatarPath) && !::CopyFile(path, avatarPath, FALSE)) + { + this->Log("Failed to copy our avatar to local storage."); + return iRet; + } + + // todo: add avatar loading to skype server + + this->SetSettingDword("AvatarTS", time(NULL)); + iRet = 0; + } + else + { + // todo: avatar deletig + this->DeleteSetting("AvatarTS"); + iRet = 0; + } return iRet; } \ No newline at end of file diff --git a/protocols/Skype/src/skype_utils.cpp b/protocols/Skype/src/skype_utils.cpp index a7b397b826..f4fbc8486e 100644 --- a/protocols/Skype/src/skype_utils.cpp +++ b/protocols/Skype/src/skype_utils.cpp @@ -231,22 +231,40 @@ void CSkypeProto::FakeAsync(void *param) ::mir_free(param); } -wchar_t* CSkypeProto::GetOwnAvatarFilePath() +int CSkypeProto::DetectAvatarFormatBuffer(const char *pBuffer) { - /*DBVARIANT dbvFile = {DBVT_DELETED}; + if (!strncmp(pBuffer, "%PNG", 4)) + return PA_FORMAT_PNG; - if (!getSettingStringT(NULL, "AvatarFile", &dbvFile)) - { - TCHAR tmp[MAX_PATH * 2]; - CallService(MS_UTILS_PATHTOABSOLUTET, (WPARAM)dbvFile.ptszVal, (LPARAM)tmp); - ICQFreeVariant(&dbvFile); + if (!strncmp(pBuffer, "GIF8", 4)) + return PA_FORMAT_GIF; + + if (!_strnicmp(pBuffer, "GetSettingString("sid"); + ::wcscat(path, sid); + ::wcscat(path, L".jpg"); + ::mir_free(sid); return path; } -- cgit v1.2.3