From fff952e50f44761fa85ca90819ac97c47e77b553 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Tue, 14 Apr 2015 12:35:37 +0000 Subject: SkypeWeb: More improvements. git-svn-id: http://svn.miranda-ng.org/main/trunk@12802 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/SkypeWeb_10.vcxproj | 2 +- protocols/SkypeWeb/SkypeWeb_10.vcxproj.filters | 6 ++-- protocols/SkypeWeb/src/common.h | 1 + protocols/SkypeWeb/src/requests/contacts.h | 5 +-- protocols/SkypeWeb/src/requests/endpoint.h | 6 ++-- protocols/SkypeWeb/src/requests/messages.h | 23 +++--------- protocols/SkypeWeb/src/skype_accounts.cpp | 2 ++ protocols/SkypeWeb/src/skype_chatrooms.cpp | 1 - protocols/SkypeWeb/src/skype_contacts.cpp | 1 - protocols/SkypeWeb/src/skype_history_sync.cpp | 4 +-- protocols/SkypeWeb/src/skype_login.cpp | 5 +-- protocols/SkypeWeb/src/skype_messages.cpp | 9 +++++ protocols/SkypeWeb/src/skype_poll_processing.cpp | 2 -- protocols/SkypeWeb/src/skype_polling.cpp | 45 ++++++++++++++---------- protocols/SkypeWeb/src/skype_proto.cpp | 32 +++++++++++++---- protocols/SkypeWeb/src/skype_proto.h | 13 ++++--- protocols/SkypeWeb/src/skype_utils.cpp | 1 - 17 files changed, 88 insertions(+), 70 deletions(-) (limited to 'protocols') diff --git a/protocols/SkypeWeb/SkypeWeb_10.vcxproj b/protocols/SkypeWeb/SkypeWeb_10.vcxproj index 123ab79089..4ae49d6b50 100644 --- a/protocols/SkypeWeb/SkypeWeb_10.vcxproj +++ b/protocols/SkypeWeb/SkypeWeb_10.vcxproj @@ -204,12 +204,12 @@ + - diff --git a/protocols/SkypeWeb/SkypeWeb_10.vcxproj.filters b/protocols/SkypeWeb/SkypeWeb_10.vcxproj.filters index ac7dd70325..323e29558b 100644 --- a/protocols/SkypeWeb/SkypeWeb_10.vcxproj.filters +++ b/protocols/SkypeWeb/SkypeWeb_10.vcxproj.filters @@ -57,9 +57,6 @@ Header Files\requests - - Header Files\requests - Header Files\requests @@ -87,6 +84,9 @@ Header Files\requests + + Header Files\requests + diff --git a/protocols/SkypeWeb/src/common.h b/protocols/SkypeWeb/src/common.h index 83a0ba1bdd..96bf0fa36a 100644 --- a/protocols/SkypeWeb/src/common.h +++ b/protocols/SkypeWeb/src/common.h @@ -76,6 +76,7 @@ struct CSkypeProto; #include "requests\capabilities.h" #include "requests\subscriptions.h" #include "requests\messages.h" +#include "requests\history.h" #include "requests\poll.h" #include "requests\avatars.h" #include "requests\search.h" diff --git a/protocols/SkypeWeb/src/requests/contacts.h b/protocols/SkypeWeb/src/requests/contacts.h index ce16179d95..af39438ffd 100644 --- a/protocols/SkypeWeb/src/requests/contacts.h +++ b/protocols/SkypeWeb/src/requests/contacts.h @@ -100,9 +100,10 @@ public: { Headers << CHAR_VALUE("X-Skypetoken", token) - << CHAR_VALUE("Accept", "application/json"); + << CHAR_VALUE("Accept", "application/json") + << CHAR_VALUE("Content-type", "application/x-www-form-urlencoded"); CMStringA data; - data.AppendFormat("greeting=%s", mir_urlEncode(greeting)); + data.AppendFormat("greeting=%s", ptrA(mir_urlEncode(greeting))); Body << VALUE(data); } }; diff --git a/protocols/SkypeWeb/src/requests/endpoint.h b/protocols/SkypeWeb/src/requests/endpoint.h index 635820e0f0..428a727b5b 100644 --- a/protocols/SkypeWeb/src/requests/endpoint.h +++ b/protocols/SkypeWeb/src/requests/endpoint.h @@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef _SKYPE_REQUEST_REGINFO_H_ -#define _SKYPE_REQUEST_REGINFO_H_ +#ifndef _SKYPE_REQUEST_ENDPOINT_H_ +#define _SKYPE_REQUEST_ENDPOINT_H_ class CreateEndpointRequest : public HttpRequest { @@ -33,4 +33,4 @@ public: } }; -#endif //_SKYPE_REQUEST_STATUS_H_ +#endif //_SKYPE_REQUEST_ENDPOINT_H_ diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h index 1eb0115ae3..de6d044305 100644 --- a/protocols/SkypeWeb/src/requests/messages.h +++ b/protocols/SkypeWeb/src/requests/messages.h @@ -28,7 +28,6 @@ public: << CHAR_VALUE("Accept", "application/json, text/javascript") << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); - JSONNODE *node = json_new(5); json_push_back(node, json_new_i("clientmessageid", timestamp)); json_push_back(node, json_new_a("messagetype", "RichText")); @@ -79,7 +78,7 @@ public: Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) - << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); + << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); char *state = (iState == PROTOTYPE_SELFTYPING_ON) ? "Control/Typing" : "Control/ClearTyping"; @@ -96,11 +95,11 @@ public: } }; -class GetHistoryRequest : public HttpRequest +class MarkMessageReadRequest : public HttpRequest { public: - GetHistoryRequest(const char *regToken, const char *username, LONGLONG timestamp = 0, const char *server = SKYPE_ENDPOINTS_HOST) : - HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages?startTime=%d&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread", server, ptrA(mir_urlEncode(username)), timestamp) + MarkMessageReadRequest(const char *regToken, const char *username, LONGLONG msgId = 0, const char *server = SKYPE_ENDPOINTS_HOST) : + HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages/%lld", server, ptrA(mir_urlEncode(username)), msgId) { Headers << CHAR_VALUE("Accept", "application/json, text/javascript") @@ -108,18 +107,4 @@ public: << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); } }; - -class SyncHistoryFirstRequest : public HttpRequest -{ -public: - SyncHistoryFirstRequest(const char *regToken, const char *server = SKYPE_ENDPOINTS_HOST) : - HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations?startTime=0&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread", server) - { - Headers - << CHAR_VALUE("Accept", "application/json, text/javascript") - << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) - << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); - } -}; - #endif //_SKYPE_REQUEST_MESSAGES_H_ diff --git a/protocols/SkypeWeb/src/skype_accounts.cpp b/protocols/SkypeWeb/src/skype_accounts.cpp index 413e745565..7a83a93d78 100644 --- a/protocols/SkypeWeb/src/skype_accounts.cpp +++ b/protocols/SkypeWeb/src/skype_accounts.cpp @@ -51,6 +51,8 @@ int CSkypeProto::OnAccountLoaded(WPARAM, LPARAM) HookProtoEvent(ME_OPT_INITIALISE, &CSkypeProto::OnOptionsInit); HookProtoEvent(ME_MSG_PRECREATEEVENT, &CSkypeProto::OnPreCreateMessage); + HookProtoEvent(ME_DB_EVENT_MARKED_READ, &CSkypeProto::OnDbEventRead); + InitGroupChatModule(); return 0; diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index e3e835ddb1..c97d1e93de 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -201,5 +201,4 @@ void CSkypeProto::OnChatEvent(JSONNODE *node) { } - return; //chats not supported } \ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index 46107461af..9e7aa71902 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -54,7 +54,6 @@ MCONTACT CSkypeProto::GetContactFromAuthEvent(MEVENT hEvent) if (strcmp(dbei.szModule, m_szModuleName) != 0) return INVALID_CONTACT_ID; - return DbGetAuthEventContact(&dbei); } diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 08bb862b7a..7f5b8258b9 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -53,9 +53,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) if (isMe) flags |= DBEF_SENT; - MCONTACT hContact = IsMe(skypename) - ? FindContact(ptrA(ContactUrlToName(conversationLink))) - : FindContact(skypename); + MCONTACT hContact = FindContact(ptrA(ContactUrlToName(conversationLink))); ptrA message(RemoveHtml(content)); diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 9f2d4c43fb..2df0ff7ceb 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -17,10 +17,7 @@ along with this program. If not, see . #include "common.h" -int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM) -{ - return 0; -} +int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM) { return 0; } void CSkypeProto::OnLoginFirst(const NETLIBHTTPREQUEST *response) { diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 0fab2ce165..070cf94851 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -226,10 +226,13 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) ptrA messageType(mir_t2a(ptrT(json_as_string(json_get(node, "messagetype"))))); MCONTACT hContact = AddContact(skypename, true); + if (!mir_strcmpi(messageType, "Control/Typing")) CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_INFINITE); + else if (!mir_strcmpi(messageType, "Control/ClearTyping")) CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF); + else if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) { debugLogA(__FUNCTION__" timestamp = %d clientmsgid = %s", timestamp, clientMsgId); @@ -238,4 +241,10 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) else if (!mir_strcmpi(messageType, "Event/SkypeVideoMessage")) return; //not supported } +} + +int CSkypeProto::OnDbEventRead(WPARAM wParam, LPARAM lParam) +{ + debugLogA(__FUNCTION__); + return 0; } \ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_poll_processing.cpp b/protocols/SkypeWeb/src/skype_poll_processing.cpp index ae14cee480..878a593435 100644 --- a/protocols/SkypeWeb/src/skype_poll_processing.cpp +++ b/protocols/SkypeWeb/src/skype_poll_processing.cpp @@ -98,8 +98,6 @@ void CSkypeProto::ProcessNewMessageRes(JSONNODE *node) OnPrivateMessageEvent(node); else if (strstr(conversationLink, "/19:")) OnChatEvent(node); - - } void CSkypeProto::ProcessConversationUpdateRes(JSONNODE *node) diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index 1472a2364b..be69a83bdd 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -14,7 +14,6 @@ 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 . */ - #include "common.h" #define POLLING_ERRORS_LIMIT 3 @@ -30,26 +29,26 @@ void CSkypeProto::ParsePollData(JSONNODE *data) { JSONNODE *message = json_at(messages, i); JSONNODE *resType = json_get(message, "resourceType"); - TCHAR *resourceType = json_as_string(resType); + ptrA resourceType(mir_t2a(ptrT(json_as_string(resType)))); JSONNODE *resource = json_get(message, "resource"); - if (!mir_tstrcmpi(resourceType, L"NewMessage")) + if (!mir_strcmpi(resourceType, "NewMessage")) { ProcessNewMessageRes(resource); } - else if (!mir_tstrcmpi(resourceType, L"UserPresence")) + else if (!mir_strcmpi(resourceType, "UserPresence")) { ProcessUserPresenceRes(resource); } - else if (!mir_tstrcmpi(resourceType, L"EndpointPresence")) + else if (!mir_strcmpi(resourceType, "EndpointPresence")) { ProcessEndpointPresenceRes(resource); } - else if (!mir_tstrcmpi(resourceType, L"ConversationUpdate")) + else if (!mir_strcmpi(resourceType, "ConversationUpdate")) { ProcessConversationUpdateRes(resource); } - else if (!mir_tstrcmpi(resourceType, L"ThreadUpdate")) + else if (!mir_strcmpi(resourceType, "ThreadUpdate")) { ProcessThreadUpdateRes(resource); } @@ -72,21 +71,30 @@ void CSkypeProto::PollingThread(void*) request->nlc = m_pollingConnection; NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser); - if (response) + if (response == NULL) + { + errors++; + continue; + } + + if (response->resultCode != 200) { - if (response->pData) + errors++; + } + + if (response->pData) + { + JSONROOT root(response->pData); + JSONNODE *errorCode = json_get(root, "errorCode"); + if (errorCode != NULL) { - JSONROOT root(response->pData); - if (json_get(root, "errorCode") != NULL) - { - errors++; - continue; - } - ParsePollData(root); + errors++; + debugLogA(__FUNCTION__": polling error %s", ptrA(mir_t2a(ptrT(json_as_string(errorCode))))); } - m_pollingConnection = response->nlc; - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); + ParsePollData(root); } + m_pollingConnection = response->nlc; + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); delete request; } @@ -96,7 +104,6 @@ void CSkypeProto::PollingThread(void*) debugLogA(__FUNCTION__": unexpected termination; switching protocol to offline"); SetStatus(ID_STATUS_OFFLINE); } - m_hPollingThread = NULL; m_pollingConnection = NULL; debugLogA(__FUNCTION__": leaving"); diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index aa041f1019..1f363811ca 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -86,6 +86,7 @@ MCONTACT CSkypeProto::AddToList(int flags, PROTOSEARCHRESULT *psr) { debugLogA("CSkypeProto::AddToList"); + ptrA skypeName(mir_t2a(ptrT(psr->id))); if (skypeName == NULL) return NULL; @@ -101,7 +102,7 @@ int CSkypeProto::Authorize(MEVENT hDbEvent) MCONTACT hContact = GetContactFromAuthEvent(hDbEvent); if (hContact == INVALID_CONTACT_ID) return 1; - + ptrA token(getStringA("TokenSecret")); ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID)); PushRequest(new AuthAcceptRequest(token, skypename)); @@ -125,9 +126,22 @@ int CSkypeProto::AuthRecv(MCONTACT, PROTORECVEVENT* pre) return Proto_AuthRecv(m_szModuleName, pre); } +int CSkypeProto::AuthRequest(MCONTACT hContact, const PROTOCHAR *szMessage) +{ + if (hContact == INVALID_CONTACT_ID) + return 1; + + ptrA token(getStringA("TokenSecret")); + ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID)); + PushRequest(new AddContactRequest(token, skypename, ptrA(mir_t2a(szMessage)))); + return 0; +} + int CSkypeProto::GetInfo(MCONTACT hContact, int) { - PushRequest(new GetProfileRequest(ptrA(getStringA("TokenSecret")), ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID))), &CSkypeProto::LoadProfile); + PushRequest( + new GetProfileRequest(ptrA(getStringA("TokenSecret")), ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID))), + &CSkypeProto::LoadProfile); return 0; } @@ -205,10 +219,16 @@ int CSkypeProto::SetStatus(int iNewStatus) int CSkypeProto::UserIsTyping(MCONTACT hContact, int type) { - ptrA regToken(getStringA("registrationToken")); - ptrA username(getStringA(hContact, SKYPE_SETTINGS_ID)); - ptrA server(getStringA("Server")); - PushRequest(new SendTypingRequest(regToken, username, type, server)); + PushRequest + ( + new SendTypingRequest + ( + ptrA(getStringA("registrationToken")), + ptrA(getStringA(hContact, SKYPE_SETTINGS_ID)), + type, + ptrA(getStringA("Server")) + ) + ); return 0; } diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 3f7baea634..123e6a2b0c 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -38,7 +38,7 @@ public: virtual MCONTACT __cdecl AddToList(int flags, PROTOSEARCHRESULT* psr); virtual MCONTACT __cdecl AddToListByEvent(int flags, int iContact, MEVENT hDbEvent); - + virtual int __cdecl AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage); virtual int __cdecl Authorize(MEVENT hDbEvent); virtual int __cdecl AuthDeny(MEVENT hDbEvent, const PROTOCHAR* szReason); virtual int __cdecl AuthRecv(MCONTACT hContact, PROTORECVEVENT*); @@ -74,7 +74,7 @@ public: // events static int OnModulesLoaded(WPARAM, LPARAM); - + int __cdecl OnDbEventRead(WPARAM, LPARAM); //search void __cdecl SearchBasicThread(void* id); @@ -223,8 +223,8 @@ private: void OnChatEvent(JSONNODE *node); //polling - void ParsePollData(JSONNODE *data); void __cdecl PollingThread(void*); + void ParsePollData(JSONNODE *data); void ProcessEndpointPresenceRes(JSONNODE *node); void ProcessUserPresenceRes(JSONNODE *node); void ProcessNewMessageRes(JSONNODE *node); @@ -233,17 +233,20 @@ private: // utils bool IsOnline(); + bool IsMe(const char *skypeName); + MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob); time_t IsoToUnixTime(const TCHAR *stamp); char *RemoveHtml(const char *text); char *GetStringChunk(const char *haystack, size_t len, const char *start, const char *end); - bool IsMe(const char *skypeName); + int SkypeToMirandaStatus(const char *status); char *MirandaToSkypeStatus(int status); + static void ShowNotification(const TCHAR *message, int flags = 0, MCONTACT hContact = NULL); static void ShowNotification(const TCHAR *caption, const TCHAR *message, int flags = 0, MCONTACT hContact = NULL); - void SetServerStatus(int iNewStatus); static bool IsFileExists(std::tstring path); + char *ChatUrlToName(const char *url); char *ContactUrlToName(const char *url); char *SelfUrlToName(const char *url); diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index bf3fb13fd9..aa429017be 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -170,7 +170,6 @@ bool CSkypeProto::IsMe(const char *skypeName) ptrA SelfEndpointName(getStringA("SelfEndpointName")); if (!mir_strcmp(skypeName, mySkypeName) || !mir_strcmp(skypeName, SelfEndpointName)) return true; - return false; } -- cgit v1.2.3