summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/SkypeWeb/SkypeWeb.vcxproj1
-rw-r--r--protocols/SkypeWeb/SkypeWeb.vcxproj.filters3
-rw-r--r--protocols/SkypeWeb/src/requests/avatars.h45
-rw-r--r--protocols/SkypeWeb/src/skype_avatars.cpp188
-rw-r--r--protocols/SkypeWeb/src/skype_login.cpp2
-rw-r--r--protocols/SkypeWeb/src/skype_profile.cpp6
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h25
-rw-r--r--protocols/SkypeWeb/src/stdafx.h1
8 files changed, 132 insertions, 139 deletions
diff --git a/protocols/SkypeWeb/SkypeWeb.vcxproj b/protocols/SkypeWeb/SkypeWeb.vcxproj
index 9ad29de2f7..0e05b4afec 100644
--- a/protocols/SkypeWeb/SkypeWeb.vcxproj
+++ b/protocols/SkypeWeb/SkypeWeb.vcxproj
@@ -51,7 +51,6 @@
<ClCompile Include="src\stdafx.cxx">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
- <ClInclude Include="src\requests\avatars.h" />
<ClInclude Include="src\requests\capabilities.h" />
<ClInclude Include="src\requests\chatrooms.h" />
<ClInclude Include="src\requests\contacts.h" />
diff --git a/protocols/SkypeWeb/SkypeWeb.vcxproj.filters b/protocols/SkypeWeb/SkypeWeb.vcxproj.filters
index 506b60a8f5..e52040b257 100644
--- a/protocols/SkypeWeb/SkypeWeb.vcxproj.filters
+++ b/protocols/SkypeWeb/SkypeWeb.vcxproj.filters
@@ -78,9 +78,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\requests\avatars.h">
- <Filter>Header Files\Requests</Filter>
- </ClInclude>
<ClInclude Include="src\requests\capabilities.h">
<Filter>Header Files\Requests</Filter>
</ClInclude>
diff --git a/protocols/SkypeWeb/src/requests/avatars.h b/protocols/SkypeWeb/src/requests/avatars.h
deleted file mode 100644
index 6aff79ab87..0000000000
--- a/protocols/SkypeWeb/src/requests/avatars.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-Copyright (c) 2015-24 Miranda NG team (https://miranda-ng.org)
-
-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 version 2
-of the License.
-
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _SKYPE_REQUEST_AVATAR_H_
-#define _SKYPE_REQUEST_AVATAR_H_
-
-struct GetAvatarRequest : public AsyncHttpRequest
-{
- GetAvatarRequest(const char *url, MCONTACT hContact) :
- AsyncHttpRequest(REQUEST_GET, HOST_OTHER, url, &CSkypeProto::OnReceiveAvatar)
- {
- flags |= NLHRF_REDIRECT;
- pUserInfo = (void *)hContact;
- }
-};
-
-struct SetAvatarRequest : public AsyncHttpRequest
-{
- SetAvatarRequest(const uint8_t *data, int dataSize, const char *szMime, CSkypeProto *ppro) :
- AsyncHttpRequest(REQUEST_PUT, HOST_API, 0, &CSkypeProto::OnSentAvatar)
- {
- m_szUrl.AppendFormat("/users/%s/profile/avatar", ppro->m_szSkypename.MakeLower().c_str());
-
- AddHeader("Content-Type", szMime);
-
- m_szParam.Truncate(dataSize);
- memcpy(m_szParam.GetBuffer(), data, dataSize);
- }
-};
-
-#endif //_SKYPE_REQUEST_AVATAR_H_
diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp
index 63383e7fde..342e32c571 100644
--- a/protocols/SkypeWeb/src/skype_avatars.cpp
+++ b/protocols/SkypeWeb/src/skype_avatars.cpp
@@ -17,6 +17,58 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
+void CSkypeProto::GetAvatarFileName(MCONTACT hContact, wchar_t *pszDest, size_t cbLen)
+{
+ CMStringW wszPath(GetAvatarPath());
+ wszPath += '\\';
+
+ const wchar_t *szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_JPEG));
+ CMStringA username(getId(hContact));
+ username.Replace("live:", "__live_");
+ username.Replace("facebook:", "__facebook_");
+ wszPath.AppendFormat(L"%S%s", username.c_str(), szFileType);
+
+ wcsncpy_s(pszDest, cbLen, wszPath, _TRUNCATE);
+}
+
+void CSkypeProto::ReloadAvatarInfo(MCONTACT hContact)
+{
+ if (hContact == NULL) {
+ ReportSelfAvatarChanged();
+ return;
+ }
+
+ PROTO_AVATAR_INFORMATION ai = { 0 };
+ ai.hContact = hContact;
+ SvcGetAvatarInfo(0, (LPARAM)&ai);
+}
+
+void CSkypeProto::SetAvatarUrl(MCONTACT hContact, const CMStringW &tszUrl)
+{
+ ptrW oldUrl(getWStringA(hContact, "AvatarUrl"));
+ if (oldUrl != NULL)
+ if (tszUrl == oldUrl)
+ return;
+
+ if (tszUrl.IsEmpty()) {
+ delSetting(hContact, "AvatarUrl");
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, nullptr);
+ }
+ else {
+ setWString(hContact, "AvatarUrl", tszUrl);
+ setByte(hContact, "NeedNewAvatar", 1);
+
+ PROTO_AVATAR_INFORMATION ai = {};
+ ai.hContact = hContact;
+ GetAvatarFileName(ai.hContact, ai.filename, _countof(ai.filename));
+ ai.format = ProtoGetAvatarFormat(ai.filename);
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Avatar services for Miranda
+
INT_PTR CSkypeProto::SvcGetAvatarCaps(WPARAM wParam, LPARAM lParam)
{
switch (wParam) {
@@ -41,17 +93,48 @@ INT_PTR CSkypeProto::SvcGetAvatarCaps(WPARAM wParam, LPARAM lParam)
return 0;
}
-void CSkypeProto::ReloadAvatarInfo(MCONTACT hContact)
+INT_PTR CSkypeProto::SvcGetAvatarInfo(WPARAM, LPARAM lParam)
{
- if (hContact == NULL) {
- ReportSelfAvatarChanged();
- return;
- }
- PROTO_AVATAR_INFORMATION ai = { 0 };
- ai.hContact = hContact;
- SvcGetAvatarInfo(0, (LPARAM)&ai);
+ PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION *)lParam;
+
+ pai->format = getByte(pai->hContact, "AvatarType", PA_FORMAT_JPEG);
+
+ wchar_t tszFileName[MAX_PATH];
+ GetAvatarFileName(pai->hContact, tszFileName, _countof(tszFileName));
+ wcsncpy(pai->filename, tszFileName, _countof(pai->filename));
+
+ if (::_waccess(pai->filename, 0) == 0 && !getBool(pai->hContact, "NeedNewAvatar", 0))
+ return GAIR_SUCCESS;
+
+ if (IsOnline())
+ if (ReceiveAvatar(pai->hContact))
+ return GAIR_WAITFOR;
+
+ debugLogA("No avatar");
+ return GAIR_NOAVATAR;
}
+INT_PTR CSkypeProto::SvcGetMyAvatar(WPARAM wParam, LPARAM lParam)
+{
+ wchar_t path[MAX_PATH];
+ GetAvatarFileName(NULL, path, _countof(path));
+ wcsncpy((wchar_t *)wParam, path, (int)lParam);
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Avatars' receiving
+
+struct GetAvatarRequest : public AsyncHttpRequest
+{
+ GetAvatarRequest(const char *url, MCONTACT hContact) :
+ AsyncHttpRequest(REQUEST_GET, HOST_OTHER, url, &CSkypeProto::OnReceiveAvatar)
+ {
+ flags |= NLHRF_REDIRECT;
+ pUserInfo = (void *)hContact;
+ }
+};
+
void CSkypeProto::OnReceiveAvatar(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
if (response == nullptr || response->body.IsEmpty())
@@ -78,82 +161,39 @@ void CSkypeProto::OnReceiveAvatar(MHttpResponse *response, AsyncHttpRequest *pRe
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai, 0);
}
-void CSkypeProto::OnSentAvatar(MHttpResponse *response, AsyncHttpRequest*)
-{
- JsonReply root(response);
- if (root.error())
- return;
-}
-
-INT_PTR CSkypeProto::SvcGetAvatarInfo(WPARAM, LPARAM lParam)
+bool CSkypeProto::ReceiveAvatar(MCONTACT hContact)
{
- PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION*)lParam;
+ ptrA szUrl(getStringA(hContact, "AvatarUrl"));
+ if (!mir_strlen(szUrl))
+ return false;
- ptrA szUrl(getStringA(pai->hContact, "AvatarUrl"));
- if (szUrl == NULL)
- return GAIR_NOAVATAR;
-
- pai->format = getByte(pai->hContact, "AvatarType", PA_FORMAT_JPEG);
-
- wchar_t tszFileName[MAX_PATH];
- GetAvatarFileName(pai->hContact, tszFileName, _countof(tszFileName));
- wcsncpy(pai->filename, tszFileName, _countof(pai->filename));
-
- if (::_waccess(pai->filename, 0) == 0 && !getBool(pai->hContact, "NeedNewAvatar", 0))
- return GAIR_SUCCESS;
-
- if (IsOnline()) {
- PushRequest(new GetAvatarRequest(szUrl, pai->hContact));
- debugLogA("Requested to read an avatar from '%s'", szUrl.get());
- return GAIR_WAITFOR;
- }
-
- debugLogA("No avatar");
- return GAIR_NOAVATAR;
+ PushRequest(new GetAvatarRequest(szUrl, hContact));
+ debugLogA("Requested to read an avatar from '%s'", szUrl.get());
+ return true;
}
-INT_PTR CSkypeProto::SvcGetMyAvatar(WPARAM wParam, LPARAM lParam)
-{
- wchar_t path[MAX_PATH];
- GetAvatarFileName(NULL, path, _countof(path));
- wcsncpy((wchar_t*)wParam, path, (int)lParam);
- return 0;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Setting my own avatar
-void CSkypeProto::GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t cbLen)
+struct SetAvatarRequest : public AsyncHttpRequest
{
- CMStringW wszPath(GetAvatarPath());
- wszPath += '\\';
+ SetAvatarRequest(const uint8_t *data, int dataSize, const char *szMime, CSkypeProto *ppro) :
+ AsyncHttpRequest(REQUEST_PUT, HOST_API, 0, &CSkypeProto::OnSentAvatar)
+ {
+ m_szUrl.AppendFormat("/users/%s/profile/avatar", ppro->m_szSkypename.MakeLower().c_str());
- const wchar_t* szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_JPEG));
- CMStringA username(getId(hContact));
- username.Replace("live:", "__live_");
- username.Replace("facebook:", "__facebook_");
- wszPath.AppendFormat(L"%S%s", username.c_str(), szFileType);
+ AddHeader("Content-Type", szMime);
- wcsncpy_s(pszDest, cbLen, wszPath, _TRUNCATE);
-}
+ m_szParam.Truncate(dataSize);
+ memcpy(m_szParam.GetBuffer(), data, dataSize);
+ }
+};
-void CSkypeProto::SetAvatarUrl(MCONTACT hContact, const CMStringW &tszUrl)
+void CSkypeProto::OnSentAvatar(MHttpResponse *response, AsyncHttpRequest*)
{
- ptrW oldUrl(getWStringA(hContact, "AvatarUrl"));
- if (oldUrl != NULL)
- if (tszUrl == oldUrl)
- return;
-
- if (tszUrl.IsEmpty()) {
- delSetting(hContact, "AvatarUrl");
- ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, nullptr);
- }
- else {
- setWString(hContact, "AvatarUrl", tszUrl);
- setByte(hContact, "NeedNewAvatar", 1);
- PROTO_AVATAR_INFORMATION ai = { 0 };
- ai.hContact = hContact;
- GetAvatarFileName(ai.hContact, ai.filename, _countof(ai.filename));
- ai.format = ProtoGetAvatarFormat(ai.filename);
- ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai);
- }
+ JsonReply root(response);
+ if (root.error())
+ return;
}
INT_PTR CSkypeProto::SvcSetMyAvatar(WPARAM, LPARAM lParam)
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp
index 406f484278..9c13f39804 100644
--- a/protocols/SkypeWeb/src/skype_login.cpp
+++ b/protocols/SkypeWeb/src/skype_login.cpp
@@ -277,8 +277,8 @@ void CSkypeProto::OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest
FreeList(skypenames);
skypenames.destroy();
+ ReceiveAvatar(0);
PushRequest(new GetContactListRequest());
- PushRequest(new GetAvatarRequest(ptrA(getStringA("AvatarUrl")), 0));
PushRequest(new SyncConversations());
JSONNode root = JSONNode::parse(response->body);
diff --git a/protocols/SkypeWeb/src/skype_profile.cpp b/protocols/SkypeWeb/src/skype_profile.cpp
index 6aba685c73..2b5dc0eced 100644
--- a/protocols/SkypeWeb/src/skype_profile.cpp
+++ b/protocols/SkypeWeb/src/skype_profile.cpp
@@ -94,9 +94,9 @@ void CSkypeProto::UpdateProfileEmails(const JSONNode &root, MCONTACT hContact)
void CSkypeProto::UpdateProfileAvatar(const JSONNode &root, MCONTACT hContact)
{
- CMStringW province = root["avatarUrl"].as_mstring();
- if (!province.IsEmpty() && province != "null") {
- SetAvatarUrl(hContact, province);
+ CMStringW szUrl = root["avatarUrl"].as_mstring();
+ if (!szUrl.IsEmpty() && szUrl != "null") {
+ SetAvatarUrl(hContact, szUrl);
ReloadAvatarInfo(hContact);
}
}
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index ab24cf192b..af1915eb6f 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -129,8 +129,6 @@ public:
return getMStringA(hContact, SKYPE_SETTINGS_ID);
}
- void OnReceiveAvatar(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void OnSentAvatar(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnSearch(MHttpResponse *response, AsyncHttpRequest *pRequest);
// login
@@ -157,6 +155,9 @@ public:
void OnBlockContact(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnUnblockContact(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnReceiveAvatar(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnSentAvatar(MHttpResponse *response, AsyncHttpRequest *pRequest);
+
void OnMessageSent(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest *pRequest);
@@ -189,11 +190,6 @@ private:
HANDLE m_hPollingThread;
HNETLIBCONN m_hPollingConn;
- INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM);
- INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM);
- INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM);
- INT_PTR __cdecl SvcSetMyAvatar(WPARAM, LPARAM);
-
// requests
bool m_isTerminated = true;
mir_cs m_requestQueueLock;
@@ -211,6 +207,17 @@ private:
void Execute(AsyncHttpRequest *request);
void PushRequest(AsyncHttpRequest *request);
+ // avatars
+ void SetAvatarUrl(MCONTACT hContact, const CMStringW &tszUrl);
+ bool ReceiveAvatar(MCONTACT hContact);
+ void ReloadAvatarInfo(MCONTACT hContact);
+ void GetAvatarFileName(MCONTACT hContact, wchar_t *pszDest, size_t cbLen);
+
+ INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcSetMyAvatar(WPARAM, LPARAM);
+
// menus
static HGENMENU ContactMenuItems[CMI_MAX];
int OnPrebuildContactMenu(WPARAM hContact, LPARAM);
@@ -236,10 +243,6 @@ private:
uint16_t GetContactStatus(MCONTACT hContact);
void SetContactStatus(MCONTACT hContact, uint16_t status);
- void SetAvatarUrl(MCONTACT hContact, const CMStringW &tszUrl);
- void ReloadAvatarInfo(MCONTACT hContact);
- void GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t cbLen);
-
MCONTACT FindContact(const char *skypeId);
MCONTACT FindContact(const wchar_t *skypeId);
diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h
index 73d40365ba..645dfd4bb2 100644
--- a/protocols/SkypeWeb/src/stdafx.h
+++ b/protocols/SkypeWeb/src/stdafx.h
@@ -112,7 +112,6 @@ struct AsyncHttpRequest : public MTHttpRequest<CSkypeProto>
void AddAuthentication(CSkypeProto *ppro);
};
-#include "requests/avatars.h"
#include "requests/capabilities.h"
#include "requests/chatrooms.h"
#include "requests/contacts.h"