From 0f73f1572a03e5bae2664c1b2bb2cd18a1e33fca Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 31 Mar 2015 21:33:48 +0000 Subject: SkypeWeb: - refactored status setting - refactored HttpRequest 3 git-svn-id: http://svn.miranda-ng.org/main/trunk@12579 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/http_request.h | 170 ++++++++---------------- protocols/SkypeWeb/src/requests/contacts.h | 20 +-- protocols/SkypeWeb/src/requests/endpoint.h | 9 +- protocols/SkypeWeb/src/requests/login.h | 8 +- protocols/SkypeWeb/src/requests/logout.h | 5 +- protocols/SkypeWeb/src/requests/messages.h | 8 +- protocols/SkypeWeb/src/requests/poll.h | 13 +- protocols/SkypeWeb/src/requests/profile.h | 4 +- protocols/SkypeWeb/src/requests/reg_info.h | 10 +- protocols/SkypeWeb/src/requests/status.h | 41 +----- protocols/SkypeWeb/src/requests/subscriptions.h | 12 +- protocols/SkypeWeb/src/skype_events.cpp | 11 +- protocols/SkypeWeb/src/skype_proto.cpp | 54 +++++++- protocols/SkypeWeb/src/skype_proto.h | 5 +- protocols/SkypeWeb/src/skype_status.cpp | 68 ---------- protocols/SkypeWeb/src/skype_utils.cpp | 20 +++ 16 files changed, 184 insertions(+), 274 deletions(-) (limited to 'protocols/SkypeWeb') diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h index a7d9eb8937..e39bdf3032 100644 --- a/protocols/SkypeWeb/src/http_request.h +++ b/protocols/SkypeWeb/src/http_request.h @@ -34,52 +34,56 @@ struct FORMAT_VALUE : public VALUE } }; -class HttpRequest : protected NETLIBHTTPREQUEST, public MZeroedObject +class HttpRequest : private NETLIBHTTPREQUEST, public MZeroedObject { +private: + va_list formatArgs; + CMStringA url; + protected: + enum HttpRequestUrlFormat { FORMAT }; + class HttpRequestUrl { friend HttpRequest; private: - CMStringA content; + HttpRequest &request; - void AppendSeparator() + HttpRequestUrl(HttpRequest &request, const char *url) : request(request) { - if (!content.IsEmpty()) - { - if (content.Find("?") == -1) - content.AppendChar('?'); - else - content.AppendChar('&'); - } + request.url = url; + request.szUrl = request.url.GetBuffer(); + } + + HttpRequestUrl(HttpRequest &request, const char *urlFormat, va_list args) : request(request) + { + request.url.AppendFormatV(urlFormat, args); + request.szUrl = request.url.GetBuffer(); } public: - HttpRequestUrl & operator<<(const VALUE ¶m) + HttpRequestUrl &operator<<(const VALUE ¶m) { - AppendSeparator(); - content.Append(param.szName); + request.AddUrlParameter(param.szName); return *this; } - HttpRequestUrl & operator<<(const INT_VALUE ¶m) + HttpRequestUrl &operator<<(const INT_VALUE ¶m) { - AppendSeparator(); - content.AppendFormat("%s=%i", param.szName, param.iValue); + request.AddUrlParameter("%s=%i", param.szName, param.iValue); return *this; } - HttpRequestUrl & operator<<(const CHAR_VALUE ¶m) + HttpRequestUrl &operator<<(const CHAR_VALUE ¶m) { - AppendSeparator(); - content.AppendFormat("%s=%s", param.szName, param.szValue); + request.AddUrlParameter("%s=%s", param.szName, param.szValue); return *this; } - char * ToString() + char *ToString() { - return content.GetBuffer(); + return request.url.GetBuffer(); } }; @@ -116,6 +120,12 @@ protected: Add(param.szName, param.szValue); return *this; } + + HttpRequestHeaders & operator<<(const FORMAT_VALUE ¶m) + { + Add(param.szName, param.szValue); + return *this; + } }; class HttpRequestBody @@ -168,17 +178,18 @@ protected: } }; - HttpRequest() : Headers(*this) + void AddUrlParameter(const char *fmt, ...) { - cbSize = sizeof(NETLIBHTTPREQUEST); - flags = NLHRF_HTTP11 | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; - } + va_list args; + va_start(args, fmt); + if (url.Find('?') == -1) + url += '?'; + else + url += '&'; + url.AppendFormatV(fmt, args); + va_end(args); - HttpRequest(int httpMethod, LPCSTR urlFormat, va_list args) - : Headers(*this) - { - requestType = httpMethod; - Url.content.AppendFormatV(urlFormat, args); + szUrl = url.GetBuffer(); } public: @@ -186,13 +197,21 @@ public: HttpRequestHeaders Headers; HttpRequestBody Body; - HttpRequest(int type, LPCSTR urlFormat, ...) - : Headers(*this) + HttpRequest(int type, LPCSTR url) + : Url(*this, url), Headers(*this) { - va_list args; - va_start(args, urlFormat); - this->HttpRequest::HttpRequest(type, urlFormat, args); - va_end(args); + cbSize = sizeof(NETLIBHTTPREQUEST); + flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; + requestType = type; + } + + HttpRequest(int type, HttpRequestUrlFormat format, LPCSTR urlFormat, ...) + : Url(*this, urlFormat, (va_start(formatArgs, urlFormat), formatArgs)), Headers(*this) + { + cbSize = sizeof(NETLIBHTTPREQUEST); + flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; + requestType = type; + va_end(formatArgs); } ~HttpRequest() @@ -203,14 +222,13 @@ public: mir_free(headers[i].szValue); } mir_free(headers); - //mir_free(pData); } NETLIBHTTPREQUEST * Send(HANDLE hConnection) { - if (Url.content.Find("://") == -1) - Url.content.Insert(0, flags & NLHRF_SSL ? "https://" : "http://"); - szUrl = Url.ToString(); + if (url.Find("://") == -1) + url.Insert(0, flags & NLHRF_SSL ? "https://" : "http://"); + szUrl = url.GetBuffer(); pData = Body.ToString(); dataLength = mir_strlen(pData); @@ -223,76 +241,4 @@ public: } }; -class HttpGetRequest : public HttpRequest -{ -public: - HttpGetRequest(LPCSTR urlFormat, ...) - { - va_list args; - va_start(args, urlFormat); - this->HttpRequest::HttpRequest(REQUEST_GET, urlFormat, args); - va_end(args); - } -}; - -class HttpPostRequest : public HttpRequest -{ -public: - HttpPostRequest(LPCSTR urlFormat, ...) - { - va_list args; - va_start(args, urlFormat); - this->HttpRequest::HttpRequest(REQUEST_POST, urlFormat, args); - va_end(args); - - //Headers << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); - } -}; - -class HttpsRequest : public HttpRequest -{ -protected: - HttpsRequest() : HttpRequest() - { - flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; - } - -public: - HttpsRequest(int type, LPCSTR urlFormat, ...) - { - va_list args; - va_start(args, urlFormat); - this->HttpRequest::HttpRequest(type, urlFormat, args); - va_end(args); - - flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; - } -}; - -class HttpsGetRequest : public HttpsRequest -{ -public: - HttpsGetRequest(LPCSTR urlFormat, ...) - { - va_list args; - va_start(args, urlFormat); - this->HttpRequest::HttpRequest(REQUEST_GET, urlFormat, args); - va_end(args); - } -}; - -class HttpsPostRequest : public HttpsRequest -{ -public: - HttpsPostRequest(LPCSTR urlFormat, ...) - { - va_list args; - va_start(args, urlFormat); - this->HttpRequest::HttpRequest(REQUEST_POST, urlFormat, args); - va_end(args); - - //Headers << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); - } -}; - #endif //_HTTP_REQUEST_H_ \ No newline at end of file diff --git a/protocols/SkypeWeb/src/requests/contacts.h b/protocols/SkypeWeb/src/requests/contacts.h index 55d35334ae..786f59e10d 100644 --- a/protocols/SkypeWeb/src/requests/contacts.h +++ b/protocols/SkypeWeb/src/requests/contacts.h @@ -1,11 +1,11 @@ #ifndef _SKYPE_REQUEST_CONTACTS_H_ #define _SKYPE_REQUEST_CONTACTS_H_ -class GetContactListRequest : public HttpsGetRequest +class GetContactListRequest : public HttpRequest { public: GetContactListRequest(const char *token, const char *skypename = "self") : - HttpsGetRequest("api.skype.com/users/%s/contacts", skypename) + HttpRequest(REQUEST_GET, FORMAT, "api.skype.com/users/%s/contacts", skypename) { Url << CHAR_VALUE("hideDetails", "true"); @@ -15,11 +15,11 @@ public: } }; -class GetContactsInfoRequest : public HttpsPostRequest +class GetContactsInfoRequest : public HttpRequest { public: GetContactsInfoRequest(const char *token, const LIST &skypenames, const char *skypename = "self") : - HttpsPostRequest("api.skype.com/users/%s/contacts/profiles", skypename) + HttpRequest(REQUEST_POST, FORMAT, "api.skype.com/users/%s/contacts/profiles", skypename) { Headers << CHAR_VALUE("X-Skypetoken", token) @@ -32,11 +32,11 @@ public: } }; -class GetContactsAuthRequest : public HttpsGetRequest +class GetContactsAuthRequest : public HttpRequest { public: GetContactsAuthRequest(const char *token, const char *skypename = "self") : - HttpsGetRequest("api.skype.com/users/%s/contacts/auth-request", skypename) + HttpRequest(REQUEST_GET, FORMAT, "api.skype.com/users/%s/contacts/auth-request", skypename) { Headers << CHAR_VALUE("X-Skypetoken", token) @@ -44,11 +44,11 @@ public: } }; -class AuthAcceptRequest : public HttpsGetRequest +class AuthAcceptRequest : public HttpRequest { public: AuthAcceptRequest(const char *token, const char *who, const char *skypename = "self") : - HttpsGetRequest("api.skype.com/users/%s/contacts/auth-request/%s/accept", skypename, who) + HttpRequest(REQUEST_GET, FORMAT, "api.skype.com/users/%s/contacts/auth-request/%s/accept", skypename, who) { Headers << CHAR_VALUE("X-Skypetoken", token) @@ -56,11 +56,11 @@ public: } }; -class AuthDeclineRequest : public HttpsGetRequest +class AuthDeclineRequest : public HttpRequest { public: AuthDeclineRequest(const char *token, const char *who, const char *skypename = "self") : - HttpsGetRequest("api.skype.com/users/%s/contacts/auth-request/%s/decline", skypename) + HttpRequest(REQUEST_GET, FORMAT, "api.skype.com/users/%s/contacts/auth-request/%s/decline", skypename) { Headers << CHAR_VALUE("X-Skypetoken", token) diff --git a/protocols/SkypeWeb/src/requests/endpoint.h b/protocols/SkypeWeb/src/requests/endpoint.h index bc3bdaff32..f6dd9c604c 100644 --- a/protocols/SkypeWeb/src/requests/endpoint.h +++ b/protocols/SkypeWeb/src/requests/endpoint.h @@ -1,19 +1,16 @@ #ifndef _SKYPE_REQUEST_ENDPOINT_H_ #define _SKYPE_REQUEST_ENDPOINT_H_ -class GetEndpointRequest : public HttpsRequest +class GetEndpointRequest : public HttpRequest { public: GetEndpointRequest(const char *regToken, const char *endpointID) : - HttpsRequest(REQUEST_PUT, "client-s.gateway.messenger.live.com/v1/users/ME/endpoints/%s/presenceDocs/messagingService", mir_urlEncode(endpointID)) + HttpRequest(REQUEST_PUT, FORMAT, "client-s.gateway.messenger.live.com/v1/users/ME/endpoints/%s/presenceDocs/messagingService", ptrA(mir_urlEncode(endpointID))) { - flags |= NLHRF_SSL; - CMStringA auth = "registrationToken="; - auth += regToken; Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << CHAR_VALUE("Expires", "0") - << CHAR_VALUE("RegistrationToken", auth) + << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8") << CHAR_VALUE("BehaviorOverride", "redirectAs404") << CHAR_VALUE("Referer", "https://web.skype.com/main") diff --git a/protocols/SkypeWeb/src/requests/login.h b/protocols/SkypeWeb/src/requests/login.h index c7924a842c..54af48f211 100644 --- a/protocols/SkypeWeb/src/requests/login.h +++ b/protocols/SkypeWeb/src/requests/login.h @@ -1,13 +1,14 @@ #ifndef _SKYPE_REQUEST_LOGIN_H_ #define _SKYPE_REQUEST_LOGIN_H_ -class LoginRequest : public HttpsPostRequest +class LoginRequest : public HttpRequest { public: LoginRequest() : - HttpsPostRequest("login.skype.com/login") + HttpRequest(REQUEST_POST, "login.skype.com/login") { //flags = NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; + Url << INT_VALUE("client_id", 578134) << CHAR_VALUE("redirect_uri", "https%3A%2F%2Fweb.skype.com"); @@ -18,9 +19,10 @@ public: } LoginRequest(const char *skypename, const char *password, const char *pie, const char *etm) : - HttpsPostRequest("login.skype.com/login") + HttpRequest(REQUEST_POST, "login.skype.com/login") { //flags = NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; + Url << INT_VALUE("client_id", 578134) << CHAR_VALUE("redirect_uri", "https%3A%2F%2Fweb.skype.com"); diff --git a/protocols/SkypeWeb/src/requests/logout.h b/protocols/SkypeWeb/src/requests/logout.h index 57caff2239..989a36776e 100644 --- a/protocols/SkypeWeb/src/requests/logout.h +++ b/protocols/SkypeWeb/src/requests/logout.h @@ -1,12 +1,11 @@ #ifndef _SKYPE_REQUEST_LOGOUT_H_ #define _SKYPE_REQUEST_LOGOUT_H_ -class LogoutRequest : public HttpsGetRequest +class LogoutRequest : public HttpRequest { public: - LogoutRequest() : HttpsGetRequest("login.skype.com/logout") + LogoutRequest() : HttpRequest(REQUEST_GET, "login.skype.com/logout") { - //flags = NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; Url << INT_VALUE("client_id", 578134) << CHAR_VALUE("redirect_uri", "https%3A%2F%2Fweb.skype.com&intsrc=client-_-webapp-_-production-_-go-signin"); diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h index a61441e10a..e86f54fce9 100644 --- a/protocols/SkypeWeb/src/requests/messages.h +++ b/protocols/SkypeWeb/src/requests/messages.h @@ -1,18 +1,16 @@ #ifndef _SKYPE_REQUEST_MESSAGES_H_ #define _SKYPE_REQUEST_MESSAGES_H_ -class SendMsgRequest : public HttpsPostRequest +class SendMsgRequest : public HttpRequest { public: SendMsgRequest(const char *regToken, const char *username, const char *message) : - HttpsPostRequest("client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:%s/messages", username) + HttpRequest(REQUEST_POST, FORMAT, "client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:%s/messages", username) { - CMStringA auth = "registrationToken="; - auth += regToken; Headers << CHAR_VALUE("Accept", "application / json, text / javascript") << CHAR_VALUE("Expires", "0") - << CHAR_VALUE("RegistrationToken", auth) + << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8") << CHAR_VALUE("BehaviorOverride", "redirectAs404") << CHAR_VALUE("Referer", "https://web.skype.com/main") diff --git a/protocols/SkypeWeb/src/requests/poll.h b/protocols/SkypeWeb/src/requests/poll.h index edec20dec7..48108ccdbc 100644 --- a/protocols/SkypeWeb/src/requests/poll.h +++ b/protocols/SkypeWeb/src/requests/poll.h @@ -1,22 +1,19 @@ #ifndef _SKYPE_POLL_H_ #define _SKYPE_POLL_H_ -class PollRequest : public HttpsPostRequest +class PollRequest : public HttpRequest { public: PollRequest(const char *regToken) : - HttpsPostRequest("client-s.gateway.messenger.live.com/v1/users/ME/endpoints/SELF/subscriptions/0/poll") + HttpRequest(REQUEST_POST, "client-s.gateway.messenger.live.com/v1/users/ME/endpoints/SELF/subscriptions/0/poll") { - timeout = 30 * 1000; - flags |= NLHRF_PERSISTENT; - CMStringA data; - CMStringA auth = "registrationToken="; - auth += regToken; + //timeout = 30 * 1000; + //flags |= NLHRF_PERSISTENT; Headers << CHAR_VALUE("Connection", "keep-alive") << CHAR_VALUE("Accept", "application/json, text/javascript") << CHAR_VALUE("Expires", "0") - << CHAR_VALUE("RegistrationToken", auth) + << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8") << CHAR_VALUE("BehaviorOverride", "redirectAs404") << CHAR_VALUE("Referer", "https://web.skype.com/main") diff --git a/protocols/SkypeWeb/src/requests/profile.h b/protocols/SkypeWeb/src/requests/profile.h index 579ac446b4..e7d7a4b682 100644 --- a/protocols/SkypeWeb/src/requests/profile.h +++ b/protocols/SkypeWeb/src/requests/profile.h @@ -1,11 +1,11 @@ #ifndef _SKYPE_REQUEST_PROFILE_H_ #define _SKYPE_REQUEST_PROFILE_H_ -class GetProfileRequest : public HttpsGetRequest +class GetProfileRequest : public HttpRequest { public: GetProfileRequest(const char *token, const char *skypename = "self") : - HttpsGetRequest("api.skype.com/users/%s/profile", skypename) + HttpRequest(REQUEST_GET, FORMAT, "api.skype.com/users/%s/profile", skypename) { Headers << CHAR_VALUE("X-Skypetoken", token) diff --git a/protocols/SkypeWeb/src/requests/reg_info.h b/protocols/SkypeWeb/src/requests/reg_info.h index 888ce987b0..47f649ec61 100644 --- a/protocols/SkypeWeb/src/requests/reg_info.h +++ b/protocols/SkypeWeb/src/requests/reg_info.h @@ -1,18 +1,16 @@ #ifndef _SKYPE_REQUEST_REGINFO_H_ #define _SKYPE_REQUEST_REGINFO_H_ -class GetRegInfoRequest : public HttpsPostRequest +class GetRegInfoRequest : public HttpRequest { public: GetRegInfoRequest(const char *token) : - HttpsPostRequest("client-s.gateway.messenger.live.com/v1/users/ME/endpoints") + HttpRequest(REQUEST_POST, "client-s.gateway.messenger.live.com/v1/users/ME/endpoints") { - CMStringA auth = "skypetoken="; - auth += token; - Headers + Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << CHAR_VALUE("Expires", "0") - << CHAR_VALUE("Authentication", auth) + << FORMAT_VALUE("Authentication", "skypetoken=%s", token) << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8") << CHAR_VALUE("Referer", "https://web.skype.com/main") << CHAR_VALUE("Origin", "https://web.skype.com") diff --git a/protocols/SkypeWeb/src/requests/status.h b/protocols/SkypeWeb/src/requests/status.h index 2f0f9f4f42..1fc30bac81 100644 --- a/protocols/SkypeWeb/src/requests/status.h +++ b/protocols/SkypeWeb/src/requests/status.h @@ -1,16 +1,16 @@ #ifndef _SKYPE_REQUEST_STATUS_H_ #define _SKYPE_REQUEST_STATUS_H_ -class SetStatusRequest : public HttpsRequest +class SetStatusRequest : public HttpRequest { public: - SetStatusRequest(const char *regToken, int status) : - HttpsRequest(REQUEST_PUT, "client-s.gateway.messenger.live.com/v1/users/ME/presenceDocs/messagingService") + SetStatusRequest(const char *regToken, const char *status) : + HttpRequest(REQUEST_PUT, "client-s.gateway.messenger.live.com/v1/users/ME/presenceDocs/messagingService") { CMStringA auth = "registrationToken="; auth += regToken; Headers - << CHAR_VALUE("Accept", "application / json, text / javascript") + << CHAR_VALUE("Accept", "application/json, text/javascript") << CHAR_VALUE("Expires", "0") << CHAR_VALUE("RegistrationToken", auth) << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8") @@ -19,38 +19,7 @@ public: << CHAR_VALUE("Origin", "https://web.skype.com") << CHAR_VALUE("Connection", "keep-alive"); - const char *data; - switch (status) - { - case ID_STATUS_ONLINE: - { - data = "{\"status\":\"Online\"}"; - break; - } - case ID_STATUS_AWAY: - { - data = "{\"status\":\"Away\"}"; - break; - } - case ID_STATUS_DND: - { - data = "{\"status\":\"Busy\"}"; - break; - } - case ID_STATUS_IDLE: - { - data = "{\"status\":\"Idle\"}"; - break; - } - case ID_STATUS_INVISIBLE: - { - data = "{\"status\":\"Hidden\"}"; - break; - } - default: - data = "{\"status\":\"Online\"}"; - } - Body << VALUE(data); + Body << FORMAT_VALUE("{\"status\":\"%s\"}", status); } }; diff --git a/protocols/SkypeWeb/src/requests/subscriptions.h b/protocols/SkypeWeb/src/requests/subscriptions.h index 609d5cfec3..624c7685a4 100644 --- a/protocols/SkypeWeb/src/requests/subscriptions.h +++ b/protocols/SkypeWeb/src/requests/subscriptions.h @@ -1,26 +1,24 @@ #ifndef _SKYPE_REQUEST_SUBSCIPTIONS_H_ #define _SKYPE_REQUEST_SUBSCIPTIONS_H_ -class SubscriptionsRequest : public HttpsPostRequest +class SubscriptionsRequest : public HttpRequest { public: SubscriptionsRequest(const char *regToken) : - HttpsPostRequest("client-s.gateway.messenger.live.com/v1/users/ME/endpoints/SELF/subscriptions") + HttpRequest(REQUEST_POST, "client-s.gateway.messenger.live.com/v1/users/ME/endpoints/SELF/subscriptions") { - CMStringA auth = "registrationToken="; - auth += regToken; Headers << CHAR_VALUE("Accept", "application/json, text/javascript") << CHAR_VALUE("Expires", "0") - << CHAR_VALUE("RegistrationToken", auth) + << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8") << CHAR_VALUE("BehaviorOverride", "redirectAs404") << CHAR_VALUE("Referer", "https://web.skype.com/main") << CHAR_VALUE("Origin", "https://web.skype.com") << CHAR_VALUE("Connection", "keep-alive"); - const char *data = "{\"channelType\":\"httpLongPoll\",\"template\":\"raw\",\"interestedResources\":[\"/v1/users/ME/conversations/ALL/properties\",\"/v1/users/ME/conversations/ALL/messages\",\"/v1/users/ME/contacts/ALL\",\"/v1/threads/ALL\"]}"; - Body << VALUE(data); + const char *data = "{\"channelType\":\"httpLongPoll\",\"template\":\"raw\",\"interestedResources\":[\"/v1/users/ME/conversations/ALL/properties\",\"/v1/users/ME/conversations/ALL/messages\",\"/v1/users/ME/contacts/ALL\",\"/v1/threads/ALL\"]}"; + Body << VALUE(data); } }; diff --git a/protocols/SkypeWeb/src/skype_events.cpp b/protocols/SkypeWeb/src/skype_events.cpp index fdc0dd246c..35f3746713 100644 --- a/protocols/SkypeWeb/src/skype_events.cpp +++ b/protocols/SkypeWeb/src/skype_events.cpp @@ -92,8 +92,6 @@ void CSkypeProto::OnLoginSecond(const NETLIBHTTPREQUEST *response) PushRequest(new GetRegInfoRequest(token.c_str()), &CSkypeProto::OnGetRegInfo); PushRequest(new GetProfileRequest(token.c_str()), &CSkypeProto::LoadProfile); PushRequest(new GetContactListRequest(token.c_str()), &CSkypeProto::LoadContactList); - - //ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus); } void CSkypeProto::OnGetRegInfo(const NETLIBHTTPREQUEST *response) @@ -123,12 +121,15 @@ void CSkypeProto::OnGetRegInfo(const NETLIBHTTPREQUEST *response) } PushRequest(new GetEndpointRequest(getStringA("registrationToken"), getStringA("endpointId"))); - SubscriptionsRequest *request = new SubscriptionsRequest(getStringA("registrationToken")); - request->Send(m_hNetlibUser); + SubscriptionsRequest *request = new SubscriptionsRequest(getStringA("registrationToken")); + request->Send(m_hNetlibUser); delete request; m_hPollingThread = ForkThreadEx(&CSkypeProto::PollingThread, 0, NULL); - PushRequest(new SetStatusRequest(getStringA("registrationToken"), ID_STATUS_ONLINE), &CSkypeProto::OnSetStatus); + + m_iStatus = m_iDesiredStatus; + ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus); + PushRequest(new SetStatusRequest(ptrA(getStringA("registrationToken")), MirandaToSkypeStatus(m_iStatus)), &CSkypeProto::OnSetStatus); } void CSkypeProto::OnSetStatus(const NETLIBHTTPREQUEST *response) diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index e5ef4991d6..6f0905c785 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -1,7 +1,7 @@ #include "common.h" CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) : - PROTO(protoName, userName), password(NULL) +PROTO(protoName, userName), password(NULL) { m_hProtoIcon = Icons[0].Handle; SetAllContactsStatus(ID_STATUS_OFFLINE); @@ -122,8 +122,60 @@ int CSkypeProto::SendUrl(MCONTACT, int, const char*) { return 0; } int CSkypeProto::SetApparentMode(MCONTACT, int) { return 0; } +int CSkypeProto::SetStatus(int iNewStatus) +{ + if (iNewStatus == m_iDesiredStatus) + { + return 0; + } + + debugLogA(__FUNCTION__ ": changing status from %i to %i", m_iStatus, iNewStatus); + + int old_status = m_iStatus; + m_iDesiredStatus = iNewStatus; + + if (iNewStatus == ID_STATUS_OFFLINE) + { + // logout + PushRequest(new LogoutRequest()); + requestQueue->Stop(); + if (!Miranda_Terminated()) + { + SetAllContactsStatus(ID_STATUS_OFFLINE); + } + m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; + } + else + { + if (old_status == ID_STATUS_CONNECTING) + { + return 0; + } + else if (old_status == ID_STATUS_OFFLINE && m_iStatus == ID_STATUS_OFFLINE) + { + // login + m_iStatus = ID_STATUS_CONNECTING; + + requestQueue->Start(); + PushRequest(new LoginRequest(), &CSkypeProto::OnLoginFirst); + } + else + { + // set status + m_iStatus = iNewStatus; + // it should be rewritten + //GetEndpointRequest *request = new GetEndpointRequest(getStringA("registrationToken"), getStringA("endpointId")); + //request->Send(m_hNetlibUser); + //delete request; + PushRequest(new SetStatusRequest(ptrA(getStringA("registrationToken")), MirandaToSkypeStatus(m_iStatus)), &CSkypeProto::OnSetStatus); + } + } + + ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); + return 0; +} HANDLE CSkypeProto::GetAwayMsg(MCONTACT) { return 0; } diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 1f35f810ff..f312fc38e5 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -172,10 +172,11 @@ private: int OnReceiveMessage(MCONTACT hContact, PROTORECVEVENT *pre); int OnSendMessage(MCONTACT hContact, int flags, const char *message); //polling - void __cdecl CSkypeProto::ParsePollData(JSONNODE *data); - void __cdecl CSkypeProto::PollingThread(void*); + void __cdecl ParsePollData(JSONNODE *data); + void __cdecl PollingThread(void*); void CSkypeProto::ProcessUserPresenceRes(JSONNODE *node); // utils + 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); diff --git a/protocols/SkypeWeb/src/skype_status.cpp b/protocols/SkypeWeb/src/skype_status.cpp index 5de3e6f683..054c90acd2 100644 --- a/protocols/SkypeWeb/src/skype_status.cpp +++ b/protocols/SkypeWeb/src/skype_status.cpp @@ -1,71 +1,3 @@ #include "common.h" -int CSkypeProto::SetStatus(int iNewStatus) -{ - if (iNewStatus == m_iDesiredStatus) - { - return 0; - } - - debugLogA(__FUNCTION__ ": changing status from %i to %i", m_iStatus, iNewStatus); - - int old_status = m_iStatus; - m_iDesiredStatus = iNewStatus; - switch (iNewStatus) - { - case ID_STATUS_OFFLINE: - isTerminated = true; - PushRequest(new LogoutRequest()); - requestQueue->Stop(); - if (!Miranda_Terminated()) - { - SetAllContactsStatus(ID_STATUS_OFFLINE); - } - - m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; - break; - - case ID_STATUS_INVISIBLE: - case ID_STATUS_AWAY: - case ID_STATUS_DND: - case ID_STATUS_IDLE: - { - GetEndpointRequest *request = new GetEndpointRequest(getStringA("registrationToken"), getStringA("endpointId")); - request->Send(m_hNetlibUser); - delete request; - PushRequest(new SetStatusRequest(ptrA(getStringA("registrationToken")), iNewStatus), &CSkypeProto::OnSetStatus); - break; - } - default: - if (old_status == ID_STATUS_CONNECTING) - return 0; - - if (m_iStatus == ID_STATUS_INVISIBLE || m_iStatus == ID_STATUS_AWAY || m_iStatus == ID_STATUS_DND || m_iStatus == ID_STATUS_IDLE) - { - GetEndpointRequest *request = new GetEndpointRequest(getStringA("registrationToken"), getStringA("endpointId")); - request->Send(m_hNetlibUser); - delete request; - PushRequest(new SetStatusRequest(ptrA(getStringA("registrationToken")), ID_STATUS_ONLINE), &CSkypeProto::OnSetStatus); - } - else if (old_status == ID_STATUS_OFFLINE && m_iStatus == ID_STATUS_OFFLINE) - { - // login - isTerminated = false; - m_iStatus = ID_STATUS_CONNECTING; - - requestQueue->Start(); - PushRequest(new LoginRequest(), &CSkypeProto::OnLoginFirst); - } - else - { - // set status - m_iStatus = iNewStatus; - } - break; - - } - ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); - return 0; -} - void CSkypeProto::SetServerStatus(int iNewStatus){ return; } \ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 92a7ba792d..0e32b56723 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -1,5 +1,25 @@ #include "common.h" +char *CSkypeProto::MirandaToSkypeStatus(int status) +{ + char *result = "Online"; + switch (status) + { + case ID_STATUS_AWAY: + return "Away"; + + case ID_STATUS_DND: + return "Busy"; + + case ID_STATUS_IDLE: + return "Idle"; + + case ID_STATUS_INVISIBLE: + return "Hidden"; + } + return "Online"; +} + void CSkypeProto::ShowNotification(const TCHAR *caption, const TCHAR *message, int flags, MCONTACT hContact) { if (Miranda_Terminated()) -- cgit v1.2.3