From 346d6c8bba413fa13f31f8acfd808c23a4bbccae Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Mon, 27 Jul 2015 13:48:14 +0000 Subject: SkypeWeb: More fixes & optimizations git-svn-id: http://svn.miranda-ng.org/main/trunk@14738 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/http_request.h | 13 ++++++ protocols/SkypeWeb/src/requests/trouter.h | 4 +- protocols/SkypeWeb/src/skype_accounts.cpp | 2 +- protocols/SkypeWeb/src/skype_chatrooms.cpp | 10 ++--- protocols/SkypeWeb/src/skype_events.cpp | 40 +++++++++++------- protocols/SkypeWeb/src/skype_history_sync.cpp | 8 ++-- protocols/SkypeWeb/src/skype_login.cpp | 2 +- protocols/SkypeWeb/src/skype_messages.cpp | 6 +-- protocols/SkypeWeb/src/skype_poll_processing.cpp | 6 +-- protocols/SkypeWeb/src/skype_proto.h | 53 ++++++++++++++---------- protocols/SkypeWeb/src/skype_trouter.cpp | 10 ++--- protocols/SkypeWeb/src/skype_trouter.h | 1 + protocols/SkypeWeb/src/skype_utils.cpp | 19 ++++----- protocols/SkypeWeb/src/stdafx.h | 1 - 14 files changed, 103 insertions(+), 72 deletions(-) (limited to 'protocols/SkypeWeb') diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h index b939d9508d..e69355a300 100644 --- a/protocols/SkypeWeb/src/http_request.h +++ b/protocols/SkypeWeb/src/http_request.h @@ -31,6 +31,13 @@ struct INT_VALUE : public VALUE : VALUE(_name), iValue(_value) { } }; +struct LONG_VALUE : public VALUE +{ + LONGLONG llValue; + __forceinline LONG_VALUE(LPCSTR _name, LONGLONG _value) + : VALUE(_name), llValue(_value) { } +}; + struct CHAR_VALUE : public VALUE { LPCSTR szValue; @@ -95,6 +102,12 @@ protected: return *this; } + HttpRequestUrl &operator<<(const LONG_VALUE ¶m) + { + request.AddUrlParameter("%s=%lld", param.szName, param.llValue); + return *this; + } + HttpRequestUrl &operator<<(const CHAR_VALUE ¶m) { request.AddUrlParameter("%s=%s", param.szName, param.szValue); diff --git a/protocols/SkypeWeb/src/requests/trouter.h b/protocols/SkypeWeb/src/requests/trouter.h index 7a9a0ca684..6035324cf9 100644 --- a/protocols/SkypeWeb/src/requests/trouter.h +++ b/protocols/SkypeWeb/src/requests/trouter.h @@ -118,7 +118,7 @@ public: << INT_VALUE("p", 443) << CHAR_VALUE("ccid", ccid.c_str()) << CHAR_VALUE("tc", ptrA(mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))) - << INT_VALUE("t", time(NULL) * 1000); + << LONG_VALUE("t", time(NULL) * 1000); Headers << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml"); @@ -146,7 +146,7 @@ public: << INT_VALUE("p", 443) << CHAR_VALUE("ccid", ccid.c_str()) << CHAR_VALUE("tc", ptrA(mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))) - << INT_VALUE("t", time(NULL) * 1000); + << LONG_VALUE("t", time(NULL) * 1000); Headers << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml"); diff --git a/protocols/SkypeWeb/src/skype_accounts.cpp b/protocols/SkypeWeb/src/skype_accounts.cpp index c306668496..e80c56c004 100644 --- a/protocols/SkypeWeb/src/skype_accounts.cpp +++ b/protocols/SkypeWeb/src/skype_accounts.cpp @@ -17,7 +17,7 @@ along with this program. If not, see . #include "stdafx.h" -LIST Accounts(1, CSkypeProto::CompareAccounts); +LIST CSkypeProto::Accounts(1, CSkypeProto::CompareAccounts); int CSkypeProto::CompareAccounts(const CSkypeProto *p1, const CSkypeProto *p2) { diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index 839a1191d0..5dc7dc21a3 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -127,7 +127,7 @@ void CSkypeProto::OnLoadChats(const NETLIBHTTPREQUEST *response) std::string conversationLink = lastMessage["conversationLink"].as_string(); if (conversationLink.find("/19:") != -1) { - CMStringA skypename(ChatUrlToName(conversationLink.c_str())); + CMStringA skypename(UrlToSkypename(conversationLink.c_str())); CMString topic(threadProperties["topic"].as_mstring()); SendRequest(new GetChatInfoRequest(m_szRegToken, skypename, m_szServer), &CSkypeProto::OnGetChatInfo, topic.Detach()); } @@ -277,7 +277,7 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) //std::string skypeEditedId = node["skypeeditedid"].as_string(); std::string fromLink = node["from"].as_string(); - CMStringA from(ContactUrlToName(fromLink.c_str())); + CMStringA from(UrlToSkypename(fromLink.c_str())); time_t timestamp = IsoToUnixTime(node["composetime"].as_string().c_str()); @@ -285,7 +285,7 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) int emoteOffset = node["skypeemoteoffset"].as_int(); std::string conversationLink = node["conversationLink"].as_string(); - CMStringA chatname(ChatUrlToName(conversationLink.c_str())); + CMStringA chatname(UrlToSkypename(conversationLink.c_str())); CMString topic(node["threadtopic"].as_mstring()); if (FindChatRoom(chatname) == NULL) @@ -453,13 +453,13 @@ void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p) if (!properties["capabilities"] || properties["capabilities"].empty()) return; - CMStringA chatId(ChatUrlToName(root["messages"].as_string().c_str())); + CMStringA chatId(UrlToSkypename(root["messages"].as_string().c_str())); StartChatRoom(_A2T(chatId), topic); for (size_t i = 0; i < members.size(); i++) { const JSONNode &member = members.at(i); - CMStringA username(ContactUrlToName(member["userLink"].as_string().c_str())); + CMStringA username(UrlToSkypename(member["userLink"].as_string().c_str())); std::string role = member["role"].as_string(); if (!IsChatContact(_A2T(chatId), username)) AddChatContact(_A2T(chatId), username, username, _A2T(role.c_str()), true); diff --git a/protocols/SkypeWeb/src/skype_events.cpp b/protocols/SkypeWeb/src/skype_events.cpp index 8dc4be687e..a68c5e8186 100644 --- a/protocols/SkypeWeb/src/skype_events.cpp +++ b/protocols/SkypeWeb/src/skype_events.cpp @@ -137,7 +137,7 @@ INT_PTR CSkypeProto::GetEventText(WPARAM, LPARAM lParam) } case SKYPE_DB_EVENT_TYPE_UNKNOWN: { - pszText = mir_strdup(CMStringA(FORMAT, Translate("Unknown event, please send this text for developer: \"%s\""), (char*)pEvent->dbei->pBlob)); + pszText = mir_strdup(CMStringA(FORMAT, Translate("Unknown event, please send this text for developer: \"%s\""), mir_utf8decodeA((char*)pEvent->dbei->pBlob))); break; } default: @@ -146,14 +146,24 @@ INT_PTR CSkypeProto::GetEventText(WPARAM, LPARAM lParam) } } - - if (pEvent->datatype == DBVT_TCHAR) + switch(pEvent->datatype) { - TCHAR *pwszText = _A2T(pszText); - nRetVal = (INT_PTR)mir_tstrdup(pwszText); + case DBVT_TCHAR: + { + nRetVal = (INT_PTR)mir_tstrdup(_A2T(pszText)); + break; + } + case DBVT_ASCIIZ: + { + nRetVal = (INT_PTR)mir_strdup(pszText); + break; + } + case DBVT_UTF8: + { + nRetVal = (INT_PTR)mir_utf8encode(pszText); + break; + } } - else if (pEvent->datatype == DBVT_ASCIIZ) - nRetVal = (INT_PTR)mir_strdup(pszText); return nRetVal; } @@ -277,7 +287,7 @@ int CSkypeProto::ProcessSrmmEvent(WPARAM, LPARAM lParam) //Timers -mir_cs timerLock; +mir_cs CSkypeProto::timerLock; mir_cs CSkypeProto::accountsLock; void CSkypeProto::ProcessTimer() @@ -291,9 +301,9 @@ void CSkypeProto::ProcessTimer() } } -static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) +void CALLBACK CSkypeProto::TimerProc(HWND, UINT, UINT_PTR, DWORD) { - mir_cslock lck(CSkypeProto::accountsLock); + mir_cslock lck(accountsLock); for (int i = 0; i < Accounts.getCount(); i++) { Accounts[i]->ProcessTimer(); @@ -303,14 +313,14 @@ static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) void CSkypeProto::SkypeSetTimer(void*) { mir_cslock lck(timerLock); - if (!CSkypeProto::m_timer) - CSkypeProto::m_timer = SetTimer(NULL, 0, 600000, TimerProc); + if (!m_timer) + m_timer = SetTimer(NULL, 0, 600000, TimerProc); } void CSkypeProto::SkypeUnsetTimer(void*) { mir_cslock lck(timerLock); - if (CSkypeProto::m_timer && Accounts.getCount() == 0) - KillTimer(NULL, CSkypeProto::m_timer); - CSkypeProto::m_timer = 0; + if (m_timer && Accounts.getCount() == 0) + KillTimer(NULL, m_timer); + m_timer = 0; } \ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 1016bd3e1c..06fe888e0d 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -51,11 +51,11 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) std::string conversationLink = message["conversationLink"].as_string(); int emoteOffset = message["skypeemoteoffset"].as_int(); time_t timestamp = IsoToUnixTime(message["composetime"].as_string().c_str()); - CMStringA skypename(ContactUrlToName(from.c_str())); + CMStringA skypename(UrlToSkypename(from.c_str())); bool isEdited = message["skypeeditedid"]; - MCONTACT hContact = FindContact(ContactUrlToName(conversationLink.c_str())); + MCONTACT hContact = FindContact(UrlToSkypename(conversationLink.c_str())); if (timestamp > db_get_dw(hContact, m_szModuleName, "LastMsgTime", 0)) db_set_dw(hContact, m_szModuleName, "LastMsgTime", (DWORD)timestamp); @@ -100,7 +100,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) } else if (conversationLink.find("/19:") != -1) { - CMStringA chatname(ChatUrlToName(conversationLink.c_str())); + CMStringA chatname(UrlToSkypename(conversationLink.c_str())); if (!mir_strcmpi(messageType.c_str(), "Text") || !mir_strcmpi(messageType.c_str(), "RichText")) AddMessageToChat(_A2T(chatname), _A2T(skypename), content.c_str(), emoteOffset != NULL, emoteOffset, timestamp, true); } @@ -143,7 +143,7 @@ void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response) if (conversationLink.find("/8:") != -1) { - CMStringA skypename(ContactUrlToName(conversationLink.c_str())); + CMStringA skypename(UrlToSkypename(conversationLink.c_str())); MCONTACT hContact = FindContact(skypename); if (hContact == NULL) continue; diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index c4a5601aae..f4e259e753 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -267,7 +267,7 @@ void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response) JSONNode root = JSONNode::parse(response->pData); if (root) - setString("SelfEndpointName", SelfUrlToName(root["selfLink"].as_string().c_str())); + setString("SelfEndpointName", UrlToSkypename(root["selfLink"].as_string().c_str())); } void CSkypeProto::OnStatusChanged(const NETLIBHTTPREQUEST *response) diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index e6974fd2a3..c303e4cedd 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -22,7 +22,7 @@ along with this program. If not, see . // incoming message flow int CSkypeProto::OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset, bool isRead) { - CMStringA skypename(ContactUrlToName(url)); + CMStringA skypename(UrlToSkypename(url)); debugLogA("Incoming message from %s", skypename); MCONTACT hContact = AddContact(skypename, true); @@ -128,8 +128,8 @@ void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node) bool isEdited = node["skypeeditedid"]; time_t timestamp = getByte("UseLocalTime", 0) ? time(NULL) : IsoToUnixTime(node["composetime"].as_string().c_str()); - CMStringA skypename(ContactUrlToName(node["conversationLink"].as_string().c_str())); - CMStringA from(ContactUrlToName(node["from"].as_string().c_str())); + CMStringA skypename(UrlToSkypename(node["conversationLink"].as_string().c_str())); + CMStringA from(UrlToSkypename(node["from"].as_string().c_str())); std::string content = node["content"].as_string(); int emoteOffset = node["skypeemoteoffset"].as_int(); diff --git a/protocols/SkypeWeb/src/skype_poll_processing.cpp b/protocols/SkypeWeb/src/skype_poll_processing.cpp index 2f5d9e259e..b586e67eab 100644 --- a/protocols/SkypeWeb/src/skype_poll_processing.cpp +++ b/protocols/SkypeWeb/src/skype_poll_processing.cpp @@ -21,7 +21,7 @@ void CSkypeProto::ProcessEndpointPresenceRes(const JSONNode &node) { debugLogA("CSkypeProto::ProcessEndpointPresenceRes"); std::string selfLink = node["selfLink"].as_string(); - CMStringA skypename(ContactUrlToName(selfLink.c_str())); + CMStringA skypename(UrlToSkypename(selfLink.c_str())); if (skypename.IsEmpty()) return; @@ -111,11 +111,11 @@ void CSkypeProto::ProcessUserPresenceRes(const JSONNode &node) if (selfLink.find("/8:") != std::string::npos) { - skypename = ContactUrlToName(selfLink.c_str()); + skypename = UrlToSkypename(selfLink.c_str()); } else if (selfLink.find("/1:") != std::string::npos) { - skypename = SelfUrlToName(selfLink.c_str()); + skypename = UrlToSkypename(selfLink.c_str()); } if (!skypename.IsEmpty()) diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 876b51e655..d121b2c6a5 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -76,43 +76,53 @@ public: void __cdecl SearchBasicThread(void* id); //////////////////////////////////////////// - static UINT_PTR m_timer; - static int CompareAccounts(const CSkypeProto *p1, const CSkypeProto *p2); - void ProcessTimer(); static INT_PTR EventGetIcon(WPARAM wParam, LPARAM lParam); static INT_PTR GetEventText(WPARAM, LPARAM lParam); - static mir_cs accountsLock; private: + + static UINT_PTR m_timer, m_trouterTimer; + + //---Accounts + static LIST CSkypeProto::Accounts; + static int CompareAccounts(const CSkypeProto *p1, const CSkypeProto *p2); + //---/ + RequestQueue *requestQueue; bool isTerminated, - HistorySynced; + HistorySynced; std::map cookies; static std::map languages; HANDLE m_pollingConnection, - m_hPollingThread, - m_hTrouterThread, - m_TrouterConnection, - m_hTrouterEvent, - m_hCallHook; + m_hPollingThread, + m_hTrouterThread, + m_TrouterConnection, + m_hTrouterEvent, + m_hCallHook; TRInfo TRouter; LIST m_PopupClasses; - + + //dialogs LIST m_InviteDialogs; LIST m_GCCreateDialogs; + + //locks mir_cs m_InviteDialogsLock; mir_cs m_GCCreateDialogsLock; - // accounts + mir_cs messageSyncLock; + static mir_cs accountsLock; + static mir_cs timerLock; + ptrA m_szServer, - m_szRegToken, - m_szTokenSecret, - m_szEndpointId, - m_szSelfSkypeName; + m_szRegToken, + m_szTokenSecret, + m_szEndpointId, + m_szSelfSkypeName; static CSkypeProto* GetContactAccount(MCONTACT hContact); int __cdecl OnAccountLoaded(WPARAM, LPARAM); @@ -170,7 +180,7 @@ private: void OnCreateTrouter(const NETLIBHTTPREQUEST *response); void OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response); - void OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p); + void OnGetTrouter(const NETLIBHTTPREQUEST *response); void OnHealth(const NETLIBHTTPREQUEST *response); void OnTrouterEvent(const JSONNode &body, const JSONNode &headers); void __cdecl TRouterThread(void*); @@ -225,7 +235,6 @@ private: void OnUnblockContact(const NETLIBHTTPREQUEST *response, void *p); // messages - mir_cs messageSyncLock; MEVENT GetMessageFromDb(MCONTACT hContact, const char *messageId, LONGLONG timestamp = 0); MEVENT AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DWORD flags, const char *content, const char *uid); @@ -307,13 +316,15 @@ private: void SetSrmmReadStatus(MCONTACT hContact); - CMStringA ChatUrlToName(const char *url); - CMStringA ContactUrlToName(const char *url); - CMStringA SelfUrlToName(const char *url); + CMStringA UrlToSkypename(const char *url); CMStringA GetServerFromUrl(const char *url); + //---Timers void CALLBACK SkypeUnsetTimer(void*); void CALLBACK SkypeSetTimer(void*); + void ProcessTimer(); + static void CALLBACK CSkypeProto::TimerProc(HWND, UINT, UINT_PTR, DWORD); + //---/ time_t GetLastMessageTime(MCONTACT hContact); CMString RunConfirmationCode(); diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index ca4931d6e0..efc8ab8128 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -88,10 +88,10 @@ void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response) TRouter.se, TRouter.sig, TRouter.instance, - TRouter.ccid), &CSkypeProto::OnGetTrouter, NULL); + TRouter.ccid), &CSkypeProto::OnGetTrouter); } -void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p) +void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response) { if (response == NULL || response->pData == NULL) { @@ -99,8 +99,6 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p) return; } - bool isHealth = p != NULL; - CMStringA data(response->pData); int iStart = 0; CMStringA szToken = data.Tokenize(":", iStart).Trim(); @@ -110,7 +108,7 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p) else SetEvent(m_hTrouterEvent); - if (!isHealth) + if (time(NULL) - (TRouter.lastRegistrationTime - 120) <= 0) SendRequest(new RegisterTrouterRequest(m_szTokenSecret, TRouter.url.c_str(), TRouter.sessId.c_str())); } @@ -124,7 +122,7 @@ void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST*) TRouter.sig, TRouter.instance, TRouter.ccid), - &CSkypeProto::OnGetTrouter, (void *)1); + &CSkypeProto::OnGetTrouter); } void CSkypeProto::TRouterThread(void*) diff --git a/protocols/SkypeWeb/src/skype_trouter.h b/protocols/SkypeWeb/src/skype_trouter.h index 18442ab57c..fc1becacd5 100644 --- a/protocols/SkypeWeb/src/skype_trouter.h +++ b/protocols/SkypeWeb/src/skype_trouter.h @@ -12,6 +12,7 @@ struct TRInfo sessId, sig, url; + time_t lastRegistrationTime; }; #endif //_SKYPE_TROUTER_H_ \ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index cf0fcf7be5..39e8428b98 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -552,19 +552,18 @@ CMStringA CSkypeProto::GetStringChunk(const char *haystack, const char *start, c return CMStringA(sstart, send - sstart); } -CMStringA CSkypeProto::ContactUrlToName(const char *url) +CMStringA CSkypeProto::UrlToSkypename(const char *url) { - return ParseUrl(url, "/8:"); -} + CMStringA szResult; -CMStringA CSkypeProto::SelfUrlToName(const char *url) -{ - return ParseUrl(url, "/1:"); -} + if (strstr(url, "/1:")) + szResult = ParseUrl(url, "/1:"); + else if (strstr(url, "/8:")) + szResult = ParseUrl(url, "/8:"); + else if (strstr(url, "/19:")) + szResult = ParseUrl(url, "/19:"); -CMStringA CSkypeProto::ChatUrlToName(const char *url) -{ - return ParseUrl(url, "/19:"); + return szResult; } CMStringA CSkypeProto::GetServerFromUrl(const char *url) diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h index 6816b262e4..41137d5963 100644 --- a/protocols/SkypeWeb/src/stdafx.h +++ b/protocols/SkypeWeb/src/stdafx.h @@ -57,7 +57,6 @@ struct CSkypeProto; extern HINSTANCE g_hInstance; extern char g_szMirVer[]; -extern LIST Accounts; #define SKYPE_ENDPOINTS_HOST "client-s.gateway.messenger.live.com" -- cgit v1.2.3