diff options
author | George Hazan <george.hazan@gmail.com> | 2024-06-10 16:10:19 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-06-10 16:10:19 +0300 |
commit | ff17d13ff535d20c1a1cf6226fefd29e07f40cdd (patch) | |
tree | 6f391f13820f5aa8f0e48414c69e6556b31005b1 | |
parent | a464482917c94761738949c2b5f6b16e7ab34798 (diff) |
SkypeWeb: contacts' URL unification
-rw-r--r-- | protocols/SkypeWeb/src/request_queue.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/contacts.h | 20 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_avatars.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_contacts.cpp | 89 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_login.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 13 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.cpp | 28 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.h | 2 |
9 files changed, 90 insertions, 74 deletions
diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp index 6742bacaaf..7332ac6644 100644 --- a/protocols/SkypeWeb/src/request_queue.cpp +++ b/protocols/SkypeWeb/src/request_queue.cpp @@ -22,7 +22,7 @@ AsyncHttpRequest::AsyncHttpRequest(int type, SkypeHost host, LPCSTR url, MTHttpR {
switch (host) {
case HOST_API: m_szUrl = "api.skype.com"; break;
- case HOST_CONTACTS: m_szUrl = "contacts.skype.com"; break;
+ case HOST_CONTACTS: m_szUrl = "contacts.skype.com/contacts/v2"; break;
case HOST_GRAPH: m_szUrl = "skypegraph.skype.com"; break;
case HOST_LOGIN: m_szUrl = "login.skype.com"; break;
case HOST_DEFAULT:
diff --git a/protocols/SkypeWeb/src/requests/contacts.h b/protocols/SkypeWeb/src/requests/contacts.h index f5ba5eec08..43371d15e9 100644 --- a/protocols/SkypeWeb/src/requests/contacts.h +++ b/protocols/SkypeWeb/src/requests/contacts.h @@ -23,7 +23,7 @@ struct GetContactListRequest : public AsyncHttpRequest GetContactListRequest(CSkypeProto *ppro, const char *filter) :
AsyncHttpRequest(REQUEST_GET, HOST_CONTACTS, 0, &CSkypeProto::LoadContactList)
{
- m_szUrl.AppendFormat("/contacts/v1/users/%s/contacts", ppro->m_szSkypename.MakeLower().GetBuffer());
+ m_szUrl.AppendFormat("/users/%s/contacts", ppro->m_szSkypename.MakeLower().GetBuffer());
// ?filter=contacts[?(@.type="skype" or @.type="msn")]
if (filter != NULL)
@@ -34,7 +34,7 @@ struct GetContactListRequest : public AsyncHttpRequest struct GetContactsAuthRequest : public AsyncHttpRequest
{
GetContactsAuthRequest() :
- AsyncHttpRequest(REQUEST_GET, HOST_CONTACTS, "/contacts/v2/users/SELF/invites", &CSkypeProto::LoadContactsAuth)
+ AsyncHttpRequest(REQUEST_GET, HOST_CONTACTS, "/users/SELF/invites", &CSkypeProto::LoadContactsAuth)
{
AddHeader("Accept", "application/json");
}
@@ -43,7 +43,7 @@ struct GetContactsAuthRequest : public AsyncHttpRequest struct AddContactRequest : public AsyncHttpRequest
{
AddContactRequest(const char *who, const char *greeting = "") :
- AsyncHttpRequest(REQUEST_PUT, HOST_CONTACTS, "/contacts/v2/users/SELF/contacts")
+ AsyncHttpRequest(REQUEST_PUT, HOST_CONTACTS, "/users/SELF/contacts")
{
AddHeader("Accept", "application/json");
@@ -56,7 +56,7 @@ struct AddContactRequest : public AsyncHttpRequest struct DeleteContactRequest : public AsyncHttpRequest
{
DeleteContactRequest(const char *who) :
- AsyncHttpRequest(REQUEST_DELETE, HOST_CONTACTS, "/contacts/v2/users/SELF/contacts/" + mir_urlEncode(who))
+ AsyncHttpRequest(REQUEST_DELETE, HOST_CONTACTS, "/users/SELF/contacts/" + mir_urlEncode(who))
{
AddHeader("Accept", "application/json");
}
@@ -64,10 +64,10 @@ struct DeleteContactRequest : public AsyncHttpRequest struct AuthAcceptRequest : public AsyncHttpRequest
{
- AuthAcceptRequest(const char *who) :
+ AuthAcceptRequest(CSkypeProto *ppro, const char *who) :
AsyncHttpRequest(REQUEST_PUT, HOST_CONTACTS)
{
- m_szUrl.AppendFormat("/contacts/v2/users/SELF/invites/%s/accept", who);
+ m_szUrl.AppendFormat("/users/%s/invites/%s/accept", ppro->m_szOwnSkypeId.get(), who);
AddHeader("Accept", "application/json");
}
@@ -75,10 +75,10 @@ struct AuthAcceptRequest : public AsyncHttpRequest struct AuthDeclineRequest : public AsyncHttpRequest
{
- AuthDeclineRequest(const char *who) :
+ AuthDeclineRequest(CSkypeProto *ppro, const char *who) :
AsyncHttpRequest(REQUEST_PUT, HOST_CONTACTS)
{
- m_szUrl.AppendFormat("/contacts/v2/users/SELF/invites/%s/decline", who);
+ m_szUrl.AppendFormat("/users/%s/invites/%s/decline", ppro->m_szOwnSkypeId.get(), who);
AddHeader("Accept", "application/json");
}
@@ -89,7 +89,7 @@ struct BlockContactRequest : public AsyncHttpRequest BlockContactRequest(CSkypeProto *ppro, MCONTACT hContact) :
AsyncHttpRequest(REQUEST_PUT, HOST_CONTACTS, 0, &CSkypeProto::OnBlockContact)
{
- m_szUrl.AppendFormat("/contacts/v2/users/SELF/contacts/blocklist/%s", ppro->getId(hContact).c_str());
+ m_szUrl.AppendFormat("/users/SELF/contacts/blocklist/%s", ppro->getId(hContact).c_str());
m_szParam = "{\"report_abuse\":\"false\",\"ui_version\":\"skype.com\"}";
pUserInfo = (void *)hContact;
@@ -102,7 +102,7 @@ struct UnblockContactRequest : public AsyncHttpRequest UnblockContactRequest(CSkypeProto *ppro, MCONTACT hContact) :
AsyncHttpRequest(REQUEST_DELETE, HOST_CONTACTS, 0, &CSkypeProto::OnUnblockContact)
{
- m_szUrl.AppendFormat("/contacts/v2/users/SELF/contacts/blocklist/%s", ppro->getId(hContact).c_str());
+ m_szUrl.AppendFormat("/users/SELF/contacts/blocklist/%s", ppro->getId(hContact).c_str());
pUserInfo = (void *)hContact;
AddHeader("Accept", "application/json");
diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index 596e379a46..63383e7fde 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -134,7 +134,7 @@ void CSkypeProto::GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t wcsncpy_s(pszDest, cbLen, wszPath, _TRUNCATE);
}
-void CSkypeProto::SetAvatarUrl(MCONTACT hContact, CMStringW &tszUrl)
+void CSkypeProto::SetAvatarUrl(MCONTACT hContact, const CMStringW &tszUrl)
{
ptrW oldUrl(getWStringA(hContact, "AvatarUrl"));
if (oldUrl != NULL)
@@ -146,7 +146,7 @@ void CSkypeProto::SetAvatarUrl(MCONTACT hContact, CMStringW &tszUrl) ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, nullptr);
}
else {
- setWString(hContact, "AvatarUrl", tszUrl.GetBuffer());
+ setWString(hContact, "AvatarUrl", tszUrl);
setByte(hContact, "NeedNewAvatar", 1);
PROTO_AVATAR_INFORMATION ai = { 0 };
ai.hContact = hContact;
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index ef4e27ae24..bacd557e41 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -138,73 +138,64 @@ void CSkypeProto::LoadContactsAuth(MHttpResponse *response, AsyncHttpRequest*) }
}
-//[{"skypeId":"echo123", "authorized" : true, "blocked" : false, ...},...]
-// other properties is exists but empty
-
void CSkypeProto::LoadContactList(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
return;
- bool loadAll = getBool("LoadAllContacts", false);
-
auto &root = reply.data();
for (auto &item : root["contacts"]) {
const JSONNode &name = item["name"];
- std::string skypeId = item["person_id"].as_string();
- CMStringW avatar_url = item["avatar_url"].as_mstring();
- std::string type = item["type"].as_string();
+ CMStringA szSkypeId = item["person_id"].as_mstring();
+ if (!IsPossibleUserType(szSkypeId))
+ continue;
- if (type == "skype" || loadAll) {
- MCONTACT hContact = AddContact(skypeId.c_str(), nullptr);
+ MCONTACT hContact = AddContact(szSkypeId, nullptr);
- std::string displayName = item["display_name"].as_string();
- if (!displayName.empty())
- setUString(hContact, "Nick", displayName.c_str());
+ std::string displayName = item["display_name"].as_string();
+ if (!displayName.empty())
+ setUString(hContact, "Nick", displayName.c_str());
- if (item["authorized"].as_bool()) {
- delSetting(hContact, "Auth");
- delSetting(hContact, "Grant");
- }
- else setByte(hContact, "Grant", 1);
-
- if (item["blocked"].as_bool())
- setByte(hContact, "IsBlocked", 1);
- else
- delSetting(hContact, "IsBlocked");
-
- ptrW wszGroup(Clist_GetGroup(hContact));
- if (wszGroup == nullptr) {
- if (wstrCListGroup) {
- Clist_GroupCreate(0, wstrCListGroup);
- Clist_SetGroup(hContact, wstrCListGroup);
- }
- }
+ if (item["authorized"].as_bool()) {
+ delSetting(hContact, "Auth");
+ delSetting(hContact, "Grant");
+ }
+ else setByte(hContact, "Grant", 1);
+
+ if (item["blocked"].as_bool())
+ setByte(hContact, "IsBlocked", 1);
+ else
+ delSetting(hContact, "IsBlocked");
- setString(hContact, "Type", type.c_str());
+ ptrW wszGroup(Clist_GetGroup(hContact));
+ if (wszGroup == nullptr) {
+ if (wstrCListGroup) {
+ Clist_GroupCreate(0, wstrCListGroup);
+ Clist_SetGroup(hContact, wstrCListGroup);
+ }
+ }
- SetString(hContact, "FirstName", name["first"]);
- SetString(hContact, "LastName", name["surname"]);
+ SetString(hContact, "FirstName", name["first"]);
+ SetString(hContact, "LastName", name["surname"]);
- if (item["mood"])
- db_set_ws(hContact, "CList", "StatusMsg", RemoveHtml(item["mood"].as_mstring()));
+ if (item["mood"])
+ db_set_ws(hContact, "CList", "StatusMsg", RemoveHtml(item["mood"].as_mstring()));
- SetAvatarUrl(hContact, avatar_url);
- ReloadAvatarInfo(hContact);
+ SetAvatarUrl(hContact, item["avatar_url"].as_mstring());
+ ReloadAvatarInfo(hContact);
- for (auto &phone : item["phones"]) {
- CMStringW number = phone["number"].as_mstring();
+ for (auto &phone : item["phones"]) {
+ CMStringW number = phone["number"].as_mstring();
- switch (phone["type"].as_int()) {
- case 0:
- setWString(hContact, "Phone", number);
- break;
- case 2:
- setWString(hContact, "Cellular", number);
- break;
- }
+ switch (phone["type"].as_int()) {
+ case 0:
+ setWString(hContact, "Phone", number);
+ break;
+ case 2:
+ setWString(hContact, "Cellular", number);
+ break;
}
}
}
@@ -226,7 +217,7 @@ INT_PTR CSkypeProto::OnGrantAuth(WPARAM hContact, LPARAM) if (hContact == INVALID_CONTACT_ID)
return 1;
- PushRequest(new AuthAcceptRequest(getId(hContact)));
+ PushRequest(new AuthAcceptRequest(this, getId(hContact)));
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 8b331563d0..13b90025b3 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -279,7 +279,7 @@ void CSkypeProto::OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest JSONNode root = JSONNode::parse(response->body);
if (root)
- setString("SelfEndpointName", UrlToSkypeId(root["selfLink"].as_string().c_str()));
+ m_szOwnSkypeId = UrlToSkypeId(root["selfLink"].as_string().c_str()).Detach();
PushRequest(new GetProfileRequest(this, 0));
}
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 3e77308bbf..4b9ae8b421 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -187,7 +187,7 @@ int CSkypeProto::Authorize(MEVENT hDbEvent) if (hContact == INVALID_CONTACT_ID)
return 1;
- PushRequest(new AuthAcceptRequest(getId(hContact)));
+ PushRequest(new AuthAcceptRequest(this, getId(hContact)));
return 0;
}
@@ -197,7 +197,7 @@ int CSkypeProto::AuthDeny(MEVENT hDbEvent, const wchar_t*) if (hContact == INVALID_CONTACT_ID)
return 1;
- PushRequest(new AuthDeclineRequest(getId(hContact)));
+ PushRequest(new AuthDeclineRequest(this, getId(hContact)));
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index ac92faff72..a5973d5c34 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -113,7 +113,7 @@ public: // other data
int m_iPollingId;
- ptrA m_szApiToken, m_szToken, m_szId;
+ ptrA m_szApiToken, m_szToken, m_szId, m_szOwnSkypeId;
CMStringA m_szSkypename, m_szMyname;
__forceinline CMStringA getId(MCONTACT hContact) {
@@ -239,7 +239,7 @@ private: uint16_t GetContactStatus(MCONTACT hContact);
void SetContactStatus(MCONTACT hContact, uint16_t status);
- void SetAvatarUrl(MCONTACT hContact, CMStringW &tszUrl);
+ void SetAvatarUrl(MCONTACT hContact, const CMStringW &tszUrl);
void ReloadAvatarInfo(MCONTACT hContact);
void GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t cbLen);
@@ -311,13 +311,8 @@ private: { return (m_iStatus > ID_STATUS_OFFLINE);
}
- __forceinline bool IsMe(const wchar_t *str)
- { return (!mir_wstrcmpi(str, Utf2T(m_szMyname)) || !mir_wstrcmp(str, getMStringW("SelfEndpointName")));
- }
-
- __forceinline bool IsMe(const char *str)
- { return (!mir_strcmpi(str, m_szMyname) || !mir_strcmp(str, ptrA(getUStringA("SelfEndpointName"))));
- }
+ bool IsMe(const wchar_t *str);
+ bool IsMe(const char *str);
static time_t IsoToUnixTime(const std::string &stamp);
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 36128db115..e3af5b6c74 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -427,6 +427,8 @@ CMStringW RemoveHtml(const CMStringW &data) return new_string;
}
+//////////////////////////////////////////////////////////////////////////////////////////
+
const char* CSkypeProto::MirandaToSkypeStatus(int status)
{
switch (status) {
@@ -461,6 +463,20 @@ int CSkypeProto::SkypeToMirandaStatus(const char *status) return ID_STATUS_OFFLINE;
}
+//////////////////////////////////////////////////////////////////////////////////////////
+
+bool CSkypeProto::IsMe(const wchar_t *str)
+{
+ return (!mir_wstrcmpi(str, Utf2T(m_szMyname)) || !mir_wstrcmp(str, Utf2T(m_szOwnSkypeId)));
+}
+
+bool CSkypeProto::IsMe(const char *str)
+{
+ return (!mir_strcmpi(str, m_szMyname) || !mir_strcmp(str, m_szOwnSkypeId));
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
bool CSkypeProto::IsFileExists(std::wstring path)
{
return _waccess(path.c_str(), 0) == 0;
@@ -526,6 +542,18 @@ CMStringW ParseUrl(const wchar_t *url, const wchar_t *token) static int possibleTypes[] = { 1, 2, 8, 19 };
+bool IsPossibleUserType(const char *pszUserId)
+{
+ int iType = atoi(pszUserId);
+
+ // we don't process 28 and other shit
+ for (auto &it : possibleTypes)
+ if (it == iType)
+ return true;
+
+ return false;
+}
+
CMStringA UrlToSkypeId(const char *url, int *pUserType)
{
int userType = -1;
diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h index 538feb0dea..5acdb1b856 100644 --- a/protocols/SkypeWeb/src/skype_utils.h +++ b/protocols/SkypeWeb/src/skype_utils.h @@ -25,6 +25,8 @@ const wchar_t* GetSkypeNick(const wchar_t *szSkypeId); CMStringA ParseUrl(const char *url, const char *token);
+bool IsPossibleUserType(const char *pszUserId);
+
CMStringA UrlToSkypeId(const char *url, int *pUserType = nullptr);
CMStringW UrlToSkypeId(const wchar_t *url, int *pUserType = nullptr);
|