From 343e3cb94c2985078f3e2e0510a024ecfa58b87f Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Wed, 29 Apr 2015 17:31:22 +0000 Subject: SkypeWeb: TRouter support part 2. git-svn-id: http://svn.miranda-ng.org/main/trunk@13249 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/requests/trouter.h | 36 +++++++++++++++++++++++++++---- protocols/SkypeWeb/src/skype_proto.h | 1 + protocols/SkypeWeb/src/skype_trouter.cpp | 34 +++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/protocols/SkypeWeb/src/requests/trouter.h b/protocols/SkypeWeb/src/requests/trouter.h index dad1caabbf..30cd906992 100644 --- a/protocols/SkypeWeb/src/requests/trouter.h +++ b/protocols/SkypeWeb/src/requests/trouter.h @@ -49,6 +49,38 @@ public: //{"sr":"AUKRNgA8_eKV0Ibsx037Gbd8GVrsDg8zLQRt1pH8sCyIAile3gtoWmlq2x1yZ_VNZ3tf","issuer":"edf","sp":"connect","st":"1430236511619","se":"1430318082619","sig":"nYczCdlBENCxoAFLy7lPkGELVV1w5TcUnpSUE2G7GLA"} }; +class RegisterTrouterRequest : public HttpRequest +{ +public: + RegisterTrouterRequest(const char *token, const char *trouterUrl) : + HttpRequest(REQUEST_POST, "prod.registrar.skype.com/v2/registrations") + { + Headers + << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml") + << CHAR_VALUE("X-Skypetoken", token); + + CMStringA data; + data.AppendFormat("{\"clientDescription\":{\"aesKey\":\"\",\"languageId\":\"en-US\",\"platform\":\"SWX\",\"templateKey\":\"SkypeWeb_1.0\"},\"registrationId\":\"eafc0311-7bb4-4a93-4f32-7fce2496d724\",\"nodeId\":\"\",\"transports\":{\"TROUTER\":[{\"context\":\"\",\"path\":\"%s\",\"ttl\":3600}]}}", trouterUrl); + + Body << VALUE(data); + } +}; + +class HealthTrouterRequest : public HttpRequest +{ +public: + HealthTrouterRequest(const char *ccid) : + HttpRequest(REQUEST_POST, "go.trouter.io/v2/h") + { + Url + << CHAR_VALUE("ccid", ccid); + + Headers + << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml"); + + } +}; + class GetTrouterRequest : public HttpRequest { public: @@ -103,7 +135,3 @@ public: } }; -//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_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 14ee01efc8..85c7cfcbd7 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -149,6 +149,7 @@ private: void OnCreateTrouter(const NETLIBHTTPREQUEST *response); void OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response); void OnGetTrouter(const NETLIBHTTPREQUEST *response); + void OnHealth(const NETLIBHTTPREQUEST *response); void __cdecl CSkypeProto::TRouterThread(void*); // profile diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index 9ff87a16f8..b5970f8e75 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -27,11 +27,12 @@ void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response) ptrA connId(mir_t2a(ptrT(json_as_string(json_get(root, "connId"))))); ptrA instance(mir_t2a(ptrT(json_as_string(json_get(root, "instance"))))); ptrA socketio(mir_t2a(ptrT(json_as_string(json_get(root, "socketio"))))); - + ptrA url(mir_t2a(ptrT(json_as_string(json_get(root, "url"))))); setString("Trouter_ccid", ccid); setString("Trouter_connId", connId); setString("Trouter_instance", instance); setString("Trouter_socketio", socketio); + setString("Trouter_url", url); SendRequest(new CreateTrouterPoliciesRequest(TokenSecret, connId), &CSkypeProto::OnTrouterPoliciesCreated); } @@ -71,6 +72,21 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response) CMStringA szToken = data.Tokenize(":", iStart).Trim(); setString("Trouter_SessId", szToken); m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, 0, NULL); + SendRequest(new RegisterTrouterRequest(TokenSecret, ptrA(getStringA("Trouter_url")))); +} + +void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST *response) +{ + 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")); + + SendRequest(new GetTrouterRequest(socketIo, connId, st, se, sig, instance, ccid), &CSkypeProto::OnGetTrouter); } void CSkypeProto::TRouterThread(void*) @@ -104,12 +120,23 @@ void CSkypeProto::TRouterThread(void*) if (response->resultCode != 200) { - errors++; + SendRequest(new HealthTrouterRequest(ccid), &CSkypeProto::OnHealth); + break; } if (response->pData) { - + char *json = strstr(response->pData, "{"); + + if (json == NULL) continue; + + JSONROOT root(json); + ptrA szBody(mir_t2a(ptrT(json_as_string(json_get(root, "body"))))); + JSONNODE *headers = json_get(root, "headers"); + JSONROOT jsonBody(szBody); + ptrT displayname(json_as_string(json_get(jsonBody, "displayname"))); + ptrT uid(json_as_string(json_get(jsonBody, "conversationId"))); + ShowNotification(displayname, TranslateT("Incoming call")); } m_TrouterConnection = response->nlc; @@ -120,7 +147,6 @@ void CSkypeProto::TRouterThread(void*) if (!isTerminated) { debugLogA(__FUNCTION__": unexpected termination; switching protocol to offline"); - //SetStatus(ID_STATUS_OFFLINE); } m_hTrouterThread = NULL; m_TrouterConnection = NULL; -- cgit v1.2.3