From 63055c7d28e3f878ae9ab6b1edbdb1025083fa77 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Wed, 29 Apr 2015 15:46:09 +0000 Subject: SkypeWeb: TRouter support part 1. git-svn-id: http://svn.miranda-ng.org/main/trunk@13244 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/common.h | 2 ++ protocols/SkypeWeb/src/requests/trouter.h | 33 +++++++++++++++-- protocols/SkypeWeb/src/skype_polling.cpp | 2 -- protocols/SkypeWeb/src/skype_proto.h | 4 +-- protocols/SkypeWeb/src/skype_trouter.cpp | 59 ++++++++++++++++++++++++++++--- 5 files changed, 90 insertions(+), 10 deletions(-) (limited to 'protocols') diff --git a/protocols/SkypeWeb/src/common.h b/protocols/SkypeWeb/src/common.h index 820bfc029c..62b8891ada 100644 --- a/protocols/SkypeWeb/src/common.h +++ b/protocols/SkypeWeb/src/common.h @@ -101,6 +101,8 @@ enum SKYPE_LOGIN_ERROR #define SKYPE_SETTINGS_PASSWORD "Password" #define SKYPE_SETTINGS_GROUP "DefaultGroup" +#define POLLING_ERRORS_LIMIT 3 + #define SKYPE_DB_EVENT_TYPE_ACTION 10001 #endif //_COMMON_H_ \ No newline at end of file diff --git a/protocols/SkypeWeb/src/requests/trouter.h b/protocols/SkypeWeb/src/requests/trouter.h index 193c4310ce..dad1caabbf 100644 --- a/protocols/SkypeWeb/src/requests/trouter.h +++ b/protocols/SkypeWeb/src/requests/trouter.h @@ -67,7 +67,7 @@ public: << CHAR_VALUE("v", "v2") << INT_VALUE("p", 443) << CHAR_VALUE("ccid", ccid) - << CHAR_VALUE("tc", "%7B%22cv%22:%222014.8.26%22,%22hr%22:%22%22,%22ua%22:%22SWX%22,%22v%22:%221.2.273%22%7D")//ptrA(mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))) + << CHAR_VALUE("tc", ptrA(mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))) << INT_VALUE("t", time(NULL)*1000); Headers @@ -75,6 +75,35 @@ public: } }; -//GET https://193-149-88-131.drip.trouter.io/socket.io/1/websocket/3725b0e4-a8b6-49c9-9cf1-6bef4672fe7a?sr=AUKRNgA8_eKV0Ibsx037Gbd8GVrsDg8zLQRt1pH8sCyIAile3gtoWmlq2x1yZ_VNZ3tf&issuer=edf&sp=connect&st=1430236511619&se=1430318082619&sig=nYczCdlBENCxoAFLy7lPkGELVV1w5TcUnpSUE2G7GLA&r=193.149.88.131&v=v2&p=443&ccid=huzHTfsZt3wZ&dom=web.skype.com&tc=%7B%22cv%22:%222014.8.26%22,%22hr%22:%22%22,%22ua%22:%22SWX%22,%22v%22:%221.2.273%22%7D HTTP/1.1 +class TrouterPollRequest : public HttpRequest +{ +public: + TrouterPollRequest(const char *socketio, const char *sr, const char *st, const char *se, const char *sig, + const char *instance, const char *ccid, const char *sessId) : + HttpRequest(REQUEST_GET, FORMAT, "%ssocket.io/1/xhr-polling/%s", socketio, sessId) + { + timeout = INFINITE; + flags |= NLHRF_PERSISTENT; + Url + << CHAR_VALUE("sr", sr) + << CHAR_VALUE("issuer", "edf") + << CHAR_VALUE("sp", "connect") + << CHAR_VALUE("st", st) + << CHAR_VALUE("se", se) + << CHAR_VALUE("sig", sig) + << CHAR_VALUE("r", instance) + << CHAR_VALUE("v", "v2") + << INT_VALUE("p", 443) + << CHAR_VALUE("ccid", ccid) + << CHAR_VALUE("tc", ptrA(mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))) + << INT_VALUE("t", time(NULL)*1000); + + Headers + << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml"); + } +}; + +//https://193-149-88-55.drip.trouter.io/socket.io/1/xhr-polling/18a1cfae-225a-4b87-83a9-031547c4dd2a?sr=ACSsBADYbV964VzQTW9TMJz0WbnjqF_oEqWsUWgFUnTOeNL-_X3unXd0TusIZ3tvNxvB&issuer=edf&sp=connect&st=1430320100020&se=1430402662020&sig=SV9dpQcUPzRbDHsFSNn338VRvdyCTcYo1CvFZBGhBIA&r=193.149.88.55&v=v2&p=443&ccid=XNBNb1MwnPRZ&dom=web.skype.com&tc=%7B%22cv%22:%222014.8.26%22,%22hr%22:%22%22,%22ua%22:%22SWX%22,%22v%22:%221.2.273%22%7D&t=1430320585701 + //is websocket // diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index caa14eaa0c..0c42d62d1c 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -16,8 +16,6 @@ along with this program. If not, see . */ #include "common.h" -#define POLLING_ERRORS_LIMIT 3 - void CSkypeProto::ParsePollData(JSONNODE *data) { debugLogA("CSkypeProto::ParsePollData"); diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index f64e8579e7..14ee01efc8 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -84,7 +84,7 @@ private: RequestQueue *requestQueue; bool isTerminated; std::map cookies; - HANDLE m_pollingConnection, m_hPollingThread, m_hTrouterThread; + HANDLE m_pollingConnection, m_hPollingThread, m_hTrouterThread, m_TrouterConnection; static std::map languages; static INT_PTR CALLBACK PasswordEditorProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -149,7 +149,7 @@ private: void OnCreateTrouter(const NETLIBHTTPREQUEST *response); void OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response); void OnGetTrouter(const NETLIBHTTPREQUEST *response); - void CSkypeProto::TRouterThread(void*); + void __cdecl CSkypeProto::TRouterThread(void*); // profile void UpdateProfileFirstName (JSONNODE *root, MCONTACT hContact = NULL); diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index a9071bf780..fd5133e79f 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -25,13 +25,11 @@ void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response) ptrA ccid(mir_t2a(ptrT(json_as_string(json_get(root, "ccid"))))); ptrA connId(mir_t2a(ptrT(json_as_string(json_get(root, "connId"))))); - ptrA id(mir_t2a(ptrT(json_as_string(json_get(root, "cid"))))); ptrA instance(mir_t2a(ptrT(json_as_string(json_get(root, "instance"))))); ptrA socketio(mir_t2a(ptrT(json_as_string(json_get(root, "socketio"))))); setString("Trouter_ccid", ccid); setString("Trouter_connId", connId); - setString("Trouter_id", id); setString("Trouter_instance", instance); setString("Trouter_socketio", socketio); @@ -48,6 +46,9 @@ void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response) ptrA st(mir_t2a(ptrT(json_as_string(json_get(root, "st"))))); ptrA se(mir_t2a(ptrT(json_as_string(json_get(root, "se"))))); ptrA sig(mir_t2a(ptrT(json_as_string(json_get(root, "sig"))))); + setString("Trouter_st", st); + setString("Trouter_se", se); + setString("Trouter_sig", sig); SendRequest(new GetTrouterRequest ( @@ -56,7 +57,7 @@ void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response) st, se, sig, getStringA("Trouter_instance"), getStringA("Trouter_ccid") - )); + ), &CSkypeProto::OnGetTrouter); } @@ -69,9 +70,59 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response) int iStart = 0; CMStringA szToken = data.Tokenize(":", iStart).Trim(); setString("Trouter_SessId", szToken); + m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, 0, NULL); } void CSkypeProto::TRouterThread(void*) { - + debugLogA(__FUNCTION__": entering"); + + int errors = 0; + isTerminated = false; + + ptrA socketIo(getStringA("Trouter_socketio")); + ptrA connId(getStringA("Trouter_connId")); + ptrA st(getStringA("Trouter_st")); + ptrA se(getStringA("Trouter_se")); + ptrA instance(getStringA("Trouter_instance")); + ptrA ccid(getStringA("Trouter_ccid")); + ptrA sessId(getStringA("Trouter_SessId")); + ptrA sig(getStringA("Trouter_sig")); + + while (!isTerminated && errors < POLLING_ERRORS_LIMIT) + { + TrouterPollRequest *request = new TrouterPollRequest(socketIo, connId, st, se, sig, instance, ccid, sessId) ; + request->nlc = m_TrouterConnection; + NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser); + + if (response == NULL) + { + errors++; + delete request; + continue; + } + + if (response->resultCode != 200) + { + errors++; + } + + if (response->pData) + { + + } + + m_TrouterConnection = response->nlc; + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); + delete request; + } + + if (!isTerminated) + { + debugLogA(__FUNCTION__": unexpected termination; switching protocol to offline"); + SetStatus(ID_STATUS_OFFLINE); + } + m_hPollingThread = NULL; + m_pollingConnection = NULL; + debugLogA(__FUNCTION__": leaving"); } \ No newline at end of file -- cgit v1.2.3