summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/SkypeWeb/src')
-rw-r--r--protocols/SkypeWeb/src/http_request.h277
-rw-r--r--protocols/SkypeWeb/src/request_queue.cpp89
-rw-r--r--protocols/SkypeWeb/src/request_queue.h69
-rw-r--r--protocols/SkypeWeb/src/requests/avatars.h22
-rw-r--r--protocols/SkypeWeb/src/requests/capabilities.h16
-rw-r--r--protocols/SkypeWeb/src/requests/chatrooms.h140
-rw-r--r--protocols/SkypeWeb/src/requests/contacts.h122
-rw-r--r--protocols/SkypeWeb/src/requests/endpoint.h27
-rw-r--r--protocols/SkypeWeb/src/requests/files.h42
-rw-r--r--protocols/SkypeWeb/src/requests/history.h62
-rw-r--r--protocols/SkypeWeb/src/requests/login.h14
-rw-r--r--protocols/SkypeWeb/src/requests/messages.h77
-rw-r--r--protocols/SkypeWeb/src/requests/mslogin.h97
-rw-r--r--protocols/SkypeWeb/src/requests/oauth.h45
-rw-r--r--protocols/SkypeWeb/src/requests/poll.h20
-rw-r--r--protocols/SkypeWeb/src/requests/profile.h15
-rw-r--r--protocols/SkypeWeb/src/requests/search.h19
-rw-r--r--protocols/SkypeWeb/src/requests/status.h43
-rw-r--r--protocols/SkypeWeb/src/requests/subscriptions.h36
-rw-r--r--protocols/SkypeWeb/src/requests/trouter.h126
-rw-r--r--protocols/SkypeWeb/src/skype_avatars.cpp10
-rw-r--r--protocols/SkypeWeb/src/skype_chatrooms.cpp18
-rw-r--r--protocols/SkypeWeb/src/skype_contacts.cpp20
-rw-r--r--protocols/SkypeWeb/src/skype_files.cpp13
-rw-r--r--protocols/SkypeWeb/src/skype_history_sync.cpp29
-rw-r--r--protocols/SkypeWeb/src/skype_login.cpp38
-rw-r--r--protocols/SkypeWeb/src/skype_messages.cpp36
-rw-r--r--protocols/SkypeWeb/src/skype_mslogin.cpp170
-rw-r--r--protocols/SkypeWeb/src/skype_oauth.cpp10
-rw-r--r--protocols/SkypeWeb/src/skype_polling.cpp12
-rw-r--r--protocols/SkypeWeb/src/skype_profile.cpp4
-rw-r--r--protocols/SkypeWeb/src/skype_proto.cpp58
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h136
-rw-r--r--protocols/SkypeWeb/src/skype_request.cpp59
-rw-r--r--protocols/SkypeWeb/src/skype_search.cpp14
-rw-r--r--protocols/SkypeWeb/src/skype_trouter.cpp44
-rw-r--r--protocols/SkypeWeb/src/skype_utils.cpp65
-rw-r--r--protocols/SkypeWeb/src/skype_utils.h4
-rw-r--r--protocols/SkypeWeb/src/stdafx.h60
-rw-r--r--protocols/SkypeWeb/src/version.h6
40 files changed, 681 insertions, 1483 deletions
diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h
deleted file mode 100644
index 70f6b62abf..0000000000
--- a/protocols/SkypeWeb/src/http_request.h
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
-Copyright (c) 2015-20 Miranda NG team (https://miranda-ng.org)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _HTTP_REQUEST_H_
-#define _HTTP_REQUEST_H_
-
-struct VALUE
-{
- LPCSTR szName;
- __forceinline VALUE(LPCSTR _name) : szName(_name) { }
-};
-
-struct INT_VALUE : public VALUE
-{
- int iValue;
- __forceinline INT_VALUE(LPCSTR _name, int _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;
- __forceinline CHAR_VALUE(LPCSTR _name, LPCSTR _value)
- : VALUE(_name), szValue(_value) { }
-};
-
-struct FORMAT_VALUE : public VALUE
-{
- CMStringA szValue;
- FORMAT_VALUE(LPCSTR _name, LPCSTR _valueFormat, ...)
- : VALUE(_name)
- {
- va_list args;
- va_start(args, _valueFormat);
- szValue.FormatV(_valueFormat, args);
- va_end(args);
- }
-};
-
-class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject, private MNonCopyable
-{
- va_list formatArgs;
- CMStringA url;
-
-protected:
- enum HttpRequestUrlFormat { FORMAT };
-
- class HttpRequestUrl : private MNonCopyable
- {
- friend HttpRequest;
-
- private:
- HttpRequest &request;
-
- HttpRequestUrl(HttpRequest &request, const char *url) : request(request)
- {
- 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 &param)
- {
- request.AddUrlParameter(param.szName);
- return *this;
- }
-
- HttpRequestUrl &operator<<(const INT_VALUE &param)
- {
- request.AddUrlParameter("%s=%i", param.szName, param.iValue);
- return *this;
- }
-
- HttpRequestUrl &operator<<(const LONG_VALUE &param)
- {
- request.AddUrlParameter("%s=%lld", param.szName, param.llValue);
- return *this;
- }
-
- HttpRequestUrl &operator<<(const CHAR_VALUE &param)
- {
- request.AddUrlParameter("%s=%s", param.szName, param.szValue);
- return *this;
- }
-
- char *ToString()
- {
- return request.url.GetBuffer();
- }
- };
-
- class HttpRequestHeaders : private MNonCopyable
- {
- HttpRequest &request;
-
- void Add(LPCSTR szName)
- {
- Add(szName, "");
- }
-
- void Add(LPCSTR szName, LPCSTR szValue)
- {
- request.headers = (NETLIBHTTPHEADER*)mir_realloc(
- request.headers, sizeof(NETLIBHTTPHEADER) * (request.headersCount + 1));
- request.headers[request.headersCount].szName = mir_strdup(szName);
- request.headers[request.headersCount].szValue = mir_strdup(szValue);
- request.headersCount++;
- }
-
- public:
- HttpRequestHeaders(HttpRequest &request) : request(request) { }
-
- HttpRequestHeaders& operator<<(const VALUE &param)
- {
- Add(param.szName);
- return *this;
- }
-
- HttpRequestHeaders& operator<<(const CHAR_VALUE &param)
- {
- Add(param.szName, param.szValue);
- return *this;
- }
-
- HttpRequestHeaders& operator<<(const FORMAT_VALUE &param)
- {
- Add(param.szName, param.szValue);
- return *this;
- }
- };
-
- class HttpRequestBody
- {
- private:
- CMStringA content;
-
- void AppendSeparator()
- {
- if (!content.IsEmpty())
- {
- content.AppendChar('&');
- }
- }
-
- public:
- HttpRequestBody() { }
-
- HttpRequestBody & operator<<(const VALUE &param)
- {
- AppendSeparator();
- content.Append(param.szName);
- return *this;
- }
-
- HttpRequestBody & operator<<(const INT_VALUE &param)
- {
- AppendSeparator();
- content.AppendFormat("%s=%i", param.szName, param.iValue);
- return *this;
- }
-
- HttpRequestBody & operator<<(const LONG_VALUE &param)
- {
- AppendSeparator();
- content.AppendFormat("%s=%lld", param.szName, param.llValue);
- return *this;
- }
-
- HttpRequestBody & operator<<(const CHAR_VALUE &param)
- {
- AppendSeparator();
- content.AppendFormat("%s=%s", param.szName, param.szValue);
- return *this;
- }
-
- HttpRequestBody & operator<<(const FORMAT_VALUE &param)
- {
- AppendSeparator();
- content.AppendFormat("%s=%s", param.szName, param.szValue.c_str());
- return *this;
- }
-
- char * ToString()
- {
- return content.GetBuffer();
- }
- };
-
- void AddUrlParameter(const char *fmt, ...)
- {
- va_list args;
- va_start(args, fmt);
- url += (url.Find('?') == -1) ? '?' : '&';
- url.AppendFormatV(fmt, args);
- va_end(args);
- szUrl = url.GetBuffer();
- }
-
-public:
- HttpRequestUrl Url;
- HttpRequestHeaders Headers;
- HttpRequestBody Body;
-
- HttpRequest(int type, LPCSTR url)
- : Url(*this, url), Headers(*this)
- {
- cbSize = sizeof(NETLIBHTTPREQUEST);
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_DUMPASTEXT;
- requestType = type;
- pData = NULL;
- }
-
- HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...)
- : Url(*this, urlFormat, (va_start(formatArgs, urlFormat), formatArgs)), Headers(*this)
- {
- cbSize = sizeof(NETLIBHTTPREQUEST);
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_DUMPASTEXT;
- requestType = type;
- va_end(formatArgs);
- pData = NULL;
- }
-
- virtual ~HttpRequest()
- {
- for (int i = 0; i < headersCount; i++)
- {
- mir_free(headers[i].szName);
- mir_free(headers[i].szValue);
- }
- mir_free(headers);
- }
-
- virtual NETLIBHTTPREQUEST* Send(HNETLIBUSER nlu)
- {
- if (url.Find("://") == -1)
- url.Insert(0, ((flags & NLHRF_SSL) ? "https://" : "http://"));
- szUrl = url.GetBuffer();
-
- if (!pData) {
- pData = Body.ToString();
- dataLength = (int)mir_strlen(pData);
- }
-
- Netlib_Logf(nlu, "Send request to %s", szUrl);
-
- return Netlib_HttpTransaction(nlu, this);
- }
-};
-
-#endif //_HTTP_REQUEST_H_ \ No newline at end of file
diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp
index f05701b6e3..45e58d92da 100644
--- a/protocols/SkypeWeb/src/request_queue.cpp
+++ b/protocols/SkypeWeb/src/request_queue.cpp
@@ -17,102 +17,81 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-RequestQueue::RequestQueue(HNETLIBUSER _nlu) :
- nlu(_nlu), requests(1)
+void CSkypeProto::StartQueue()
{
- isTerminated = true;
- hRequestQueueThread = nullptr;
-}
-
-RequestQueue::~RequestQueue()
-{
- if (hRequestQueueThread) {
- WaitForSingleObject(hRequestQueueThread, INFINITE);
- hRequestQueueThread = nullptr;
- }
-
- requests.destroy();
-}
-
-void RequestQueue::Start()
-{
- if (!isTerminated)
+ if (!m_isTerminated)
return;
- isTerminated = false;
- if (hRequestQueueThread == nullptr)
- hRequestQueueThread = mir_forkThread<RequestQueue>(&RequestQueue::WorkerThread, this);
+ m_isTerminated = false;
+ if (m_hRequestQueueThread == nullptr)
+ m_hRequestQueueThread = ForkThreadEx(&CSkypeProto::WorkerThread, 0, 0);
}
-void RequestQueue::Stop()
+void CSkypeProto::StopQueue()
{
- if (isTerminated)
+ if (m_isTerminated)
return;
- isTerminated = true;
- hRequestQueueEvent.Set();
+ m_isTerminated = true;
+ m_hRequestQueueEvent.Set();
}
-void RequestQueue::Push(HttpRequest *request, HttpResponseCallback response, void *arg)
+void CSkypeProto::PushRequest(AsyncHttpRequest *request)
{
- if (isTerminated)
+ if (m_isTerminated)
return;
-
- RequestQueueItem *item = new RequestQueueItem(request, response, arg);
{
- mir_cslock lock(requestQueueLock);
-
- requests.insert(item);
+ mir_cslock lock(m_requestQueueLock);
+ m_requests.insert(request);
}
- hRequestQueueEvent.Set();
+ m_hRequestQueueEvent.Set();
}
-void RequestQueue::Send(HttpRequest *request, HttpResponseCallback response, void *arg)
+void CSkypeProto::SendRequest(AsyncHttpRequest *request)
{
- RequestQueueItem *item = new RequestQueueItem(request, response, arg);
- mir_forkthreadowner(&RequestQueue::AsyncSendThread, this, item, nullptr);
+ mir_forkthreadowner(&CSkypeProto::AsyncSendThread, this, request, nullptr);
}
-void RequestQueue::Execute(RequestQueueItem *item)
+void CSkypeProto::Execute(AsyncHttpRequest *item)
{
- NLHR_PTR response(item->request->Send(nlu));
- if (item->responseCallback != nullptr)
- item->responseCallback(response, item->arg);
- requests.remove(item);
+ NLHR_PTR response(DoSend(item));
+ if (item->m_pFunc != nullptr)
+ (this->*item->m_pFunc)(response, item);
+ m_requests.remove(item);
delete item;
}
-unsigned RequestQueue::AsyncSendThread(void *owner, void *arg)
+unsigned CSkypeProto::AsyncSendThread(void *owner, void *arg)
{
- RequestQueue *that = (RequestQueue*)owner;
- RequestQueueItem *item = (RequestQueueItem*)arg;
+ CSkypeProto *that = (CSkypeProto*)owner;
+ AsyncHttpRequest *item = (AsyncHttpRequest*)arg;
that->Execute(item);
return 0;
}
-void RequestQueue::WorkerThread(RequestQueue *queue)
+void CSkypeProto::WorkerThread(void*)
{
while (true) {
- queue->hRequestQueueEvent.Wait();
- if (queue->isTerminated)
+ m_hRequestQueueEvent.Wait();
+ if (m_isTerminated)
break;
while (true) {
- RequestQueueItem *item = nullptr;
+ AsyncHttpRequest *item = nullptr;
{
- mir_cslock lock(queue->requestQueueLock);
+ mir_cslock lock(m_requestQueueLock);
- if (queue->requests.getCount() == 0)
+ if (m_requests.getCount() == 0)
break;
- item = queue->requests[0];
- queue->requests.remove(0);
+ item = m_requests[0];
+ m_requests.remove(0);
}
if (item != nullptr)
- queue->Execute(item);
+ Execute(item);
}
}
- queue->hRequestQueueThread = nullptr;
+ m_hRequestQueueThread = nullptr;
}
diff --git a/protocols/SkypeWeb/src/request_queue.h b/protocols/SkypeWeb/src/request_queue.h
deleted file mode 100644
index 0d49d9858c..0000000000
--- a/protocols/SkypeWeb/src/request_queue.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
-Copyright (c) 2015-20 Miranda NG team (https://miranda-ng.org)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _SKYPE_REQUEST_QUEUE_H_
-#define _SKYPE_REQUEST_QUEUE_H_
-
-typedef void(*HttpResponseCallback)(const NETLIBHTTPREQUEST *response, void *arg);
-
-struct RequestQueueItem
-{
- void *arg;
- HttpRequest *request;
- HttpResponseCallback responseCallback;
-
- RequestQueueItem(HttpRequest *request, void *arg) :
- arg(arg), request(request), responseCallback(NULL) { }
-
- RequestQueueItem(HttpRequest *request, HttpResponseCallback response, void *arg) :
- arg(arg), request(request), responseCallback(response) { }
-
- ~RequestQueueItem()
- {
- delete request;
- request = NULL;
- responseCallback = NULL;
- }
-};
-
-class RequestQueue
-{
- bool isTerminated;
- HNETLIBUSER nlu;
- mir_cs requestQueueLock;
- LIST<RequestQueueItem> requests;
- EventHandle hRequestQueueEvent;
- HANDLE hRequestQueueThread;
-
- void Execute(RequestQueueItem *item);
-
- static unsigned __cdecl AsyncSendThread(void*, void*);
- static void __cdecl WorkerThread(RequestQueue *queue);
-
-public:
- RequestQueue(HNETLIBUSER nlu);
- ~RequestQueue();
-
- void Start();
- void Stop();
-
- void Push(HttpRequest *request, HttpResponseCallback response = NULL, void *arg = NULL);
- void Send(HttpRequest *request, HttpResponseCallback response = NULL, void *arg = NULL);
-
-};
-
-#endif //_SKYPE_REQUEST_QUEUE_H_ \ No newline at end of file
diff --git a/protocols/SkypeWeb/src/requests/avatars.h b/protocols/SkypeWeb/src/requests/avatars.h
index c0dd5061af..918bbf37c4 100644
--- a/protocols/SkypeWeb/src/requests/avatars.h
+++ b/protocols/SkypeWeb/src/requests/avatars.h
@@ -18,26 +18,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_AVATAR_H_
#define _SKYPE_REQUEST_AVATAR_H_
-class GetAvatarRequest : public HttpRequest
+struct GetAvatarRequest : public AsyncHttpRequest
{
-public:
- GetAvatarRequest(const char *url) : HttpRequest(REQUEST_GET, url)
+ GetAvatarRequest(const char *url, MCONTACT hContact) :
+ AsyncHttpRequest(REQUEST_GET, url, &CSkypeProto::OnReceiveAvatar)
{
flags |= NLHRF_REDIRECT;
+ pUserInfo = (void *)hContact;
}
};
-class SetAvatarRequest : public HttpRequest
+struct SetAvatarRequest : public AsyncHttpRequest
{
-public:
SetAvatarRequest(const PBYTE data, size_t dataSize, const char *szMime, CSkypeProto *ppro) :
- HttpRequest(REQUEST_PUT, FORMAT, "api.skype.com/users/%s/profile/avatar", ppro->m_szSkypename.MakeLower().c_str())
+ AsyncHttpRequest(REQUEST_PUT, 0, &CSkypeProto::OnSentAvatar)
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Content-Type", szMime);
+ m_szUrl.Format("api.skype.com/users/%s/profile/avatar", ppro->m_szSkypename.MakeLower().c_str());
- pData = (char*)mir_alloc(dataSize);
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Content-Type", szMime);
+
+ pData = (char *)mir_alloc(dataSize);
memcpy(pData, data, dataSize);
dataLength = (int)dataSize;
}
@@ -48,5 +49,4 @@ public:
}
};
-
#endif //_SKYPE_REQUEST_AVATAR_H_
diff --git a/protocols/SkypeWeb/src/requests/capabilities.h b/protocols/SkypeWeb/src/requests/capabilities.h
index deab1354b1..ce53922869 100644
--- a/protocols/SkypeWeb/src/requests/capabilities.h
+++ b/protocols/SkypeWeb/src/requests/capabilities.h
@@ -18,16 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_CAPS_H_
#define _SKYPE_REQUEST_CAPS_H_
-class SendCapabilitiesRequest : public HttpRequest
+struct SendCapabilitiesRequest : public AsyncHttpRequest
{
-public:
SendCapabilitiesRequest(const char *hostname, CSkypeProto *ppro) :
- HttpRequest(REQUEST_PUT, FORMAT, "%s/v1/users/ME/endpoints/%s/presenceDocs/messagingService", ppro->m_szServer, mir_urlEncode(ppro->m_szId).c_str())
+ AsyncHttpRequest(REQUEST_PUT, 0, &CSkypeProto::OnCapabilitiesSended)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get());
+ m_szUrl.Format("/users/ME/endpoints/%s/presenceDocs/messagingService", mir_urlEncode(ppro->m_szId).c_str());
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
JSONNode privateInfo; privateInfo.set_name("privateInfo");
privateInfo << JSONNode("epname", hostname);
@@ -48,7 +48,7 @@ public:
<< privateInfo
<< publicInfo;
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
#endif //_SKYPE_REQUEST_CAPS_H_ \ No newline at end of file
diff --git a/protocols/SkypeWeb/src/requests/chatrooms.h b/protocols/SkypeWeb/src/requests/chatrooms.h
index 66549c74f4..e0dd27c739 100644
--- a/protocols/SkypeWeb/src/requests/chatrooms.h
+++ b/protocols/SkypeWeb/src/requests/chatrooms.h
@@ -18,56 +18,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_CHATS_H_
#define _SKYPE_REQUEST_CHATS_H_
-class LoadChatsRequest : public HttpRequest
+struct LoadChatsRequest : public AsyncHttpRequest
{
-public:
LoadChatsRequest(CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_GET, "/users/ME/conversations", &CSkypeProto::OnLoadChats)
{
- Url
- << INT_VALUE("startTime", 0)
- << INT_VALUE("pageSize", 100)
- << CHAR_VALUE("view", "msnp24Equivalent")
- << CHAR_VALUE("targetType", "Thread");
-
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8");
+ this << INT_PARAM("startTime", 0) << INT_PARAM("pageSize", 100)
+ << CHAR_PARAM("view", "msnp24Equivalent") << CHAR_PARAM("targetType", "Thread");
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddRegistrationToken(ppro);
+ AddHeader("Content-Type", "application/json; charset = UTF-8");
}
};
-class SendChatMessageRequest : public HttpRequest
+struct SendChatMessageRequest : public AsyncHttpRequest
{
-public:
SendChatMessageRequest(const char *to, time_t timestamp, const char *message, CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/19:%s/messages", ppro->m_szServer, to)
+ AsyncHttpRequest(REQUEST_POST)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ m_szUrl.Format("/users/ME/conversations/19:%s/messages", to);
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddRegistrationToken(ppro);
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+
JSONNode node;
node
<< JSONNode("clientmessageid", CMStringA(::FORMAT, "%llu000", (ULONGLONG)timestamp))
<< JSONNode("messagetype", "RichText")
<< JSONNode("contenttype", "text")
<< JSONNode("content", message);
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class SendChatActionRequest : public HttpRequest
+struct SendChatActionRequest : public AsyncHttpRequest
{
-public:
SendChatActionRequest(const char *to, time_t timestamp, const char *message, CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/19:%s/messages", ppro->m_szServer, to)
+ AsyncHttpRequest(REQUEST_POST)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ m_szUrl.Format("/users/ME/conversations/19:%s/messages", to);
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
JSONNode node(JSON_NODE);
node
@@ -76,23 +71,19 @@ public:
<< JSONNode("contenttype", "text")
<< JSONNode("content", message)
<< JSONNode("skypeemoteoffset", 4);
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class CreateChatroomRequest : public HttpRequest
+struct CreateChatroomRequest : public AsyncHttpRequest
{
-public:
CreateChatroomRequest(const LIST<char> &skypenames, CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/threads", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_POST, "/threads")
{
//{"members":[{"id":"8:user3","role":"User"},{"id":"8:user2","role":"User"},{"id":"8:user1","role":"Admin"}]}
-
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get());
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
JSONNode node;
JSONNode members(JSON_ARRAY); members.set_name("members");
@@ -106,73 +97,70 @@ public:
members << member;
}
node << members;
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class GetChatInfoRequest : public HttpRequest
+struct GetChatInfoRequest : public AsyncHttpRequest
{
-public:
- GetChatInfoRequest(const char *chatId, CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/v1/threads/%s%s", ppro->m_szServer, strstr(chatId, "19:") == chatId ? "" : "19:", chatId)
+ GetChatInfoRequest(const char *chatId, const CMStringW topic, CSkypeProto *ppro) :
+ AsyncHttpRequest(REQUEST_GET, 0, &CSkypeProto::OnGetChatInfo)
{
- Url << CHAR_VALUE("view", "msnp24Equivalent");
+ m_szUrl.Format("/threads/%s%s", ppro->m_szServer, strstr(chatId, "19:") == chatId ? "" : "19:", chatId);
+ pUserInfo = topic.Detach();
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get());
+ this << CHAR_PARAM("view", "msnp24Equivalent");
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
}
};
-class InviteUserToChatRequest : public HttpRequest
+struct InviteUserToChatRequest : public AsyncHttpRequest
{
-public:
InviteUserToChatRequest(const char *chatId, const char *skypename, const char* role, CSkypeProto *ppro) :
- HttpRequest(REQUEST_PUT, FORMAT, "%s/v1/threads/19:%s/members/8:%s", ppro->m_szServer, chatId, skypename)
+ AsyncHttpRequest(REQUEST_PUT)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get());
+ m_szUrl.Format("/threads/19:%s/members/8:%s", chatId, skypename);
- JSONNode node;
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
+ JSONNode node;
node << JSONNode("role", role);
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class KickUserRequest : public HttpRequest
+struct KickUserRequest : public AsyncHttpRequest
{
-public:
KickUserRequest(const char *chatId, const char *skypename, CSkypeProto *ppro) :
- HttpRequest(REQUEST_DELETE, FORMAT, "%s/v1/threads/19:%s/members/8:%s", ppro->m_szServer, chatId, skypename)
+ AsyncHttpRequest(REQUEST_DELETE)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get());
+ m_szUrl.Format("/threads/19:%s/members/8:%s", chatId, skypename);
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
}
};
-class SetChatPropertiesRequest : public HttpRequest
+struct SetChatPropertiesRequest : public AsyncHttpRequest
{
-public:
SetChatPropertiesRequest(const char *chatId, const char *propname, const char *value, CSkypeProto *ppro) :
- HttpRequest(REQUEST_PUT, FORMAT, "%s/v1/threads/19:%s/properties?name=%s", ppro->m_szServer, chatId, propname)
+ AsyncHttpRequest(REQUEST_PUT)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get());
+ m_szUrl.Format("/threads/19:%s/properties?name=%s", chatId, propname);
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
JSONNode node;
node << JSONNode(propname, value);
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
diff --git a/protocols/SkypeWeb/src/requests/contacts.h b/protocols/SkypeWeb/src/requests/contacts.h
index 430b51aa2f..57866eb18c 100644
--- a/protocols/SkypeWeb/src/requests/contacts.h
+++ b/protocols/SkypeWeb/src/requests/contacts.h
@@ -18,121 +18,113 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_CONTACTS_H_
#define _SKYPE_REQUEST_CONTACTS_H_
-class GetContactListRequest : public HttpRequest
+struct GetContactListRequest : public AsyncHttpRequest
{
-public:
GetContactListRequest(CSkypeProto *ppro, const char *filter) :
- HttpRequest(REQUEST_GET, FORMAT, "contacts.skype.com/contacts/v1/users/%s/contacts", ppro->m_szSkypename.MakeLower().GetBuffer())
+ AsyncHttpRequest(REQUEST_GET, 0, &CSkypeProto::LoadContactList)
{
+ m_szUrl.Format("contacts.skype.com/contacts/v1/users/%s/contacts", ppro->m_szSkypename.MakeLower().GetBuffer());
+
+ // ?filter=contacts[?(@.type="skype" or @.type="msn")]
if (filter != NULL)
- {
- Url
- << CHAR_VALUE ("filter", filter); //?filter=contacts[?(@.type="skype" or @.type="msn")]
- }
+ this << CHAR_PARAM("filter", filter);
- Headers
- << CHAR_VALUE("X-SkypeToken", ppro->m_szApiToken);
+ AddHeader("X-SkypeToken", ppro->m_szApiToken);
}
};
-class GetContactsAuthRequest : public HttpRequest
+struct GetContactsAuthRequest : public AsyncHttpRequest
{
-public:
GetContactsAuthRequest(CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, FORMAT, "contacts.skype.com/contacts/v2/users/SELF/invites")
+ AsyncHttpRequest(REQUEST_GET, "contacts.skype.com/contacts/v2/users/SELF/invites", &CSkypeProto::LoadContactsAuth)
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Accept", "application/json");
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
}
};
-class AddContactRequest : public HttpRequest
+struct AddContactRequest : public AsyncHttpRequest
{
-public:
AddContactRequest(CSkypeProto *ppro, const char *who, const char *greeting = "") :
- HttpRequest(REQUEST_PUT, "contacts.skype.com/contacts/v2/users/SELF/contacts")
+ AsyncHttpRequest(REQUEST_PUT, "contacts.skype.com/contacts/v2/users/SELF/contacts")
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Accept", "application/json")
- << CHAR_VALUE("Content-type", "application/x-www-form-urlencoded");
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
+ AddHeader("Content-type", "application/x-www-form-urlencoded");
JSONNode node;
- node
- << JSONNode("mri", CMStringA(::FORMAT, "8:", who).GetString())
+ node << JSONNode("mri", CMStringA(::FORMAT, "8:", who).GetString())
<< JSONNode("greeting", greeting);
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class DeleteContactRequest : public HttpRequest
+struct DeleteContactRequest : public AsyncHttpRequest
{
-public:
DeleteContactRequest(CSkypeProto *ppro, const char *who) :
- HttpRequest(REQUEST_DELETE, FORMAT, "contacts.skype.com/contacts/v2/users/SELF/contacts/8:%s", who)
+ AsyncHttpRequest(REQUEST_DELETE)
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Accept", "application/json")
- << CHAR_VALUE("Content-type", "application/x-www-form-urlencoded");
+ m_szUrl.Format("contacts.skype.com/contacts/v2/users/SELF/contacts/8:%s", who);
+
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
}
};
-class AuthAcceptRequest : public HttpRequest
+struct AuthAcceptRequest : public AsyncHttpRequest
{
-public:
AuthAcceptRequest(CSkypeProto *ppro, const char *who) :
- HttpRequest(REQUEST_PUT, FORMAT, "contacts.skype.com/contacts/v2/users/SELF/invites/8:%s/accept", who)
+ AsyncHttpRequest(REQUEST_PUT)
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Accept", "application/json");
+ m_szUrl.Format("contacts.skype.com/contacts/v2/users/SELF/invites/8:%s/accept", who);
+
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
}
};
-class AuthDeclineRequest : public HttpRequest
+struct AuthDeclineRequest : public AsyncHttpRequest
{
-public:
AuthDeclineRequest(CSkypeProto *ppro, const char *who) :
- HttpRequest(REQUEST_PUT, FORMAT, "contacts.skype.com/contacts/v2/users/SELF/invites/8:%s/decline", who)
+ AsyncHttpRequest(REQUEST_PUT)
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Accept", "application/json");
+ m_szUrl.Format("contacts.skype.com/contacts/v2/users/SELF/invites/8:%s/decline", who);
+
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
}
};
-class BlockContactRequest : public HttpRequest
+struct BlockContactRequest : public AsyncHttpRequest
{
-public:
- BlockContactRequest(CSkypeProto *ppro, const char *who) :
- HttpRequest(REQUEST_PUT, FORMAT, "contacts.skype.com/contacts/v2/users/SELF/contacts/blocklist/8:%s", who)
+ BlockContactRequest(CSkypeProto *ppro, MCONTACT hContact) :
+ AsyncHttpRequest(REQUEST_PUT, 0, &CSkypeProto::OnBlockContact)
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Accept", "application/json")
- << CHAR_VALUE("Content-type", "application/x-www-form-urlencoded");
+ m_szUrl.Format("contacts.skype.com/contacts/v2/users/SELF/contacts/blocklist/8:%s", ppro->getId(hContact).c_str());
+ m_szParam = "{\"report_abuse\":\"false\",\"ui_version\":\"skype.com\"}";
+ pUserInfo = (void *)hContact;
- Body << VALUE("{\"report_abuse\":\"false\",\"ui_version\":\"skype.com\"}");
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
+ AddHeader("Content-type", "application/x-www-form-urlencoded");
}
};
-class UnblockContactRequest : public HttpRequest
+struct UnblockContactRequest : public AsyncHttpRequest
{
-public:
- UnblockContactRequest(CSkypeProto *ppro, const char *who) :
- HttpRequest(REQUEST_DELETE, FORMAT, "contacts.skype.com/contacts/v2/users/SELF/contacts/blocklist/8:%s", who)
+ UnblockContactRequest(CSkypeProto *ppro, MCONTACT hContact) :
+ AsyncHttpRequest(REQUEST_DELETE, 0, &CSkypeProto::OnUnblockContact)
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Accept", "application/json")
- << CHAR_VALUE("Content-type", "application/x-www-form-urlencoded");
-
- Body
- << CHAR_VALUE("reporterIp", "123.123.123.123") //TODO: user ip address
- << CHAR_VALUE("uiVersion", g_szMirVer);
+ m_szUrl.Format("contacts.skype.com/contacts/v2/users/SELF/contacts/blocklist/8:%s", ppro->getId(hContact).c_str());
+ pUserInfo = (void *)hContact;
+
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
+ AddHeader("Content-type", "application/x-www-form-urlencoded");
+
+ this << CHAR_PARAM("reporterIp", "123.123.123.123") // TODO: user ip address
+ << CHAR_PARAM("uiVersion", g_szMirVer);
}
};
diff --git a/protocols/SkypeWeb/src/requests/endpoint.h b/protocols/SkypeWeb/src/requests/endpoint.h
index bf4e724cd7..07baa3c409 100644
--- a/protocols/SkypeWeb/src/requests/endpoint.h
+++ b/protocols/SkypeWeb/src/requests/endpoint.h
@@ -18,32 +18,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_ENDPOINT_H_
#define _SKYPE_REQUEST_ENDPOINT_H_
-class CreateEndpointRequest : public HttpRequest
+struct CreateEndpointRequest : public AsyncHttpRequest
{
-public:
CreateEndpointRequest(CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/endpoints", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_POST, "/users/ME/endpoints", &CSkypeProto::OnEndpointCreated)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << FORMAT_VALUE("Authentication", "skypetoken=%s", ppro->m_szApiToken.get());
+ m_szParam = "{}";
- Body << VALUE("{}");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddHeader("Authentication", CMStringA(FORMAT, "skypetoken=%s", ppro->m_szApiToken.get()));
}
};
-class DeleteEndpointRequest : public HttpRequest
+struct DeleteEndpointRequest : public AsyncHttpRequest
{
-public:
DeleteEndpointRequest(CSkypeProto *ppro) :
- HttpRequest(REQUEST_DELETE, FORMAT, "%s/v1/users/ME/endpoints/%s", ppro->m_szServer, mir_urlEncode(ppro->m_szId).c_str())
+ AsyncHttpRequest(REQUEST_DELETE)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get());
+ m_szUrl.Format("/users/ME/endpoints/%s", mir_urlEncode(ppro->m_szId).c_str());
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddRegistrationToken(ppro);
}
};
-
#endif //_SKYPE_REQUEST_ENDPOINT_H_
diff --git a/protocols/SkypeWeb/src/requests/files.h b/protocols/SkypeWeb/src/requests/files.h
index f7404474a2..11123e3f03 100644
--- a/protocols/SkypeWeb/src/requests/files.h
+++ b/protocols/SkypeWeb/src/requests/files.h
@@ -1,43 +1,47 @@
#pragma once
-class ASMObjectCreateRequest : public HttpRequest
+struct ASMObjectCreateRequest : public AsyncHttpRequest
{
-public:
- ASMObjectCreateRequest(CSkypeProto *ppro, const char *szContact, const char *szFileName) :
- HttpRequest(REQUEST_POST, "api.asm.skype.com/v1/objects")
+ ASMObjectCreateRequest(CSkypeProto *ppro, CFileUploadParam *fup) :
+ AsyncHttpRequest(REQUEST_POST, "api.asm.skype.com/v1/objects", &CSkypeProto::OnASMObjectCreated)
{
flags &= (~NLHRF_DUMPASTEXT);
- Headers
- << FORMAT_VALUE("Authorization", "skype_token %s", ppro->m_szApiToken.get())
- << CHAR_VALUE("Content-Type", "text/json")
- << CHAR_VALUE("X-Client-Version", "0/0.0.0.0");
+ pUserInfo = fup;
+
+ AddHeader("Authorization", CMStringA(FORMAT, "skype_token %s", ppro->m_szApiToken.get()));
+ AddHeader("Content-Type", "text/json");
+ AddHeader("X-Client-Version", "0/0.0.0.0");
+
+ CMStringA szContact(FORMAT, "%d:%s", ppro->isChatRoom(fup->hContact) ? 19 : 8, ppro->getId(fup->hContact).c_str());
+ T2Utf uszFileName(fup->tszFileName);
+ const char *szFileName = strrchr(uszFileName.get() + 1, '\\');
JSONNode node, jPermissions, jPermission(JSON_ARRAY);
jPermissions.set_name("permissions");
- jPermission.set_name(szContact);
+ jPermission.set_name(szContact.c_str());
jPermission << JSONNode("", "read");
jPermissions << jPermission;
node << JSONNode("type", "sharing/file") << JSONNode("filename", szFileName) << jPermissions;
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class ASMObjectUploadRequest : public HttpRequest
+struct ASMObjectUploadRequest : public AsyncHttpRequest
{
-public:
- ASMObjectUploadRequest(CSkypeProto *ppro, const char *szObject, const PBYTE data, const size_t size) :
- HttpRequest(REQUEST_PUT, FORMAT, "api.asm.skype.com/v1/objects/%s/content/original", szObject)
+ ASMObjectUploadRequest(CSkypeProto *ppro, const char *szObject, const PBYTE data, const size_t size, CFileUploadParam *fup) :
+ AsyncHttpRequest(REQUEST_PUT, 0, &CSkypeProto::OnASMObjectUploaded)
{
- Headers
- << FORMAT_VALUE("Authorization", "skype_token %s", ppro->m_szApiToken.get())
- << CHAR_VALUE("Content-Type", "application/octet-stream");
+ m_szUrl.Format("api.asm.skype.com/v1/objects/%s/content/original", szObject);
+ pUserInfo = fup;
+
+ AddHeader("Authorization", CMStringA(FORMAT, "skype_token %s", ppro->m_szApiToken.get()));
+ AddHeader("Content-Type", "application/octet-stream");
pData = (char*)mir_alloc(size);
memcpy(pData, data, size);
dataLength = (int)size;
-
}
+
~ASMObjectUploadRequest()
{
mir_free(pData);
diff --git a/protocols/SkypeWeb/src/requests/history.h b/protocols/SkypeWeb/src/requests/history.h
index fa6055b14b..ed65be8b2d 100644
--- a/protocols/SkypeWeb/src/requests/history.h
+++ b/protocols/SkypeWeb/src/requests/history.h
@@ -17,64 +17,52 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_HISTORY_H_
#define _SKYPE_REQUEST_HISTORY_H_
-class SyncHistoryFirstRequest : public HttpRequest
+struct SyncHistoryFirstRequest : public AsyncHttpRequest
{
-public:
SyncHistoryFirstRequest(int pageSize, CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_GET, "/users/ME/conversations", &CSkypeProto::OnSyncHistory)
{
- Url
- << INT_VALUE("startTime", 0)
- << INT_VALUE("pageSize", pageSize)
- << CHAR_VALUE("view", "msnp24Equivalent")
- << CHAR_VALUE("targetType", "Passport|Skype|Lync");
+ this << INT_PARAM("startTime", 0) << INT_PARAM("pageSize", pageSize)
+ << CHAR_PARAM("view", "msnp24Equivalent") << CHAR_PARAM("targetType", "Passport|Skype|Lync");
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset = UTF-8");
+ AddRegistrationToken(ppro);
}
SyncHistoryFirstRequest(const char *url, CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, url)
+ AsyncHttpRequest(REQUEST_GET, url, &CSkypeProto::OnSyncHistory)
{
-
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset = UTF-8");
+ AddRegistrationToken(ppro);
}
};
-class GetHistoryRequest : public HttpRequest
+struct GetHistoryRequest : public AsyncHttpRequest
{
-public:
GetHistoryRequest(const char *username, int pageSize, bool isChat, LONGLONG timestamp, CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations/%d:%s/messages", ppro->m_szServer, isChat ? 19 : 8, mir_urlEncode(username).c_str())
+ AsyncHttpRequest(REQUEST_GET, 0, &CSkypeProto::OnGetServerHistory)
{
- Url
- << LONG_VALUE("startTime", timestamp)
- << INT_VALUE("pageSize", pageSize)
- << CHAR_VALUE("view", "msnp24Equivalent")
- << CHAR_VALUE("targetType", "Passport|Skype|Lync|Thread");
+ m_szUrl.Format("/users/ME/conversations/%d:%s/messages", isChat ? 19 : 8, mir_urlEncode(username).c_str());
+
+ this << INT_PARAM("startTime", timestamp) << INT_PARAM("pageSize", pageSize)
+ << CHAR_PARAM("view", "msnp24Equivalent") << CHAR_PARAM("targetType", "Passport|Skype|Lync|Thread");
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset = UTF-8");
+ AddRegistrationToken(ppro);
}
};
-class GetHistoryOnUrlRequest : public HttpRequest
+struct GetHistoryOnUrlRequest : public AsyncHttpRequest
{
-public:
GetHistoryOnUrlRequest(const char *url, CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, url)
+ AsyncHttpRequest(REQUEST_GET, url, &CSkypeProto::OnGetServerHistory)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset = UTF-8");
+ AddRegistrationToken(ppro);
}
};
diff --git a/protocols/SkypeWeb/src/requests/login.h b/protocols/SkypeWeb/src/requests/login.h
index 18eec57aa6..bb5e5d00ad 100644
--- a/protocols/SkypeWeb/src/requests/login.h
+++ b/protocols/SkypeWeb/src/requests/login.h
@@ -18,11 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_LOGIN_H_
#define _SKYPE_REQUEST_LOGIN_H_
-class LoginOAuthRequest : public HttpRequest
+struct LoginOAuthRequest : public AsyncHttpRequest
{
-public:
LoginOAuthRequest(CMStringA username, const char *password) :
- HttpRequest(REQUEST_POST, "api.skype.com/login/skypetoken")
+ AsyncHttpRequest(REQUEST_POST, "api.skype.com/login/skypetoken", &CSkypeProto::OnLoginOAuth)
{
username.MakeLower();
CMStringA hashStr(::FORMAT, "%s\nskyper\n%s", username.c_str(), password);
@@ -30,11 +29,10 @@ public:
BYTE digest[16];
mir_md5_hash((const BYTE*)hashStr.GetString(), hashStr.GetLength(), digest);
- Body
- << CHAR_VALUE("scopes", "client")
- << CHAR_VALUE("clientVersion", mir_urlEncode("0/7.4.85.102/259/").c_str())
- << CHAR_VALUE("username", mir_urlEncode(username).c_str())
- << CHAR_VALUE("passwordHash", mir_urlEncode(ptrA(mir_base64_encode(digest, sizeof(digest)))).c_str());
+ this << CHAR_PARAM("scopes", "client")
+ << CHAR_PARAM("clientVersion", mir_urlEncode("0/7.4.85.102/259/").c_str())
+ << CHAR_PARAM("username", mir_urlEncode(username).c_str())
+ << CHAR_PARAM("passwordHash", mir_urlEncode(ptrA(mir_base64_encode(digest, sizeof(digest)))).c_str());
}
};
diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h
index 04cd3226c6..fdcb8d8ae6 100644
--- a/protocols/SkypeWeb/src/requests/messages.h
+++ b/protocols/SkypeWeb/src/requests/messages.h
@@ -18,38 +18,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_MESSAGES_H_
#define _SKYPE_REQUEST_MESSAGES_H_
-class SendMessageRequest : public HttpRequest
+struct SendMessageParam
+{
+ MCONTACT hContact;
+ DWORD hMessage;
+};
+
+struct SendMessageRequest : public AsyncHttpRequest
{
-public:
SendMessageRequest(const char *username, time_t timestamp, const char *message, CSkypeProto *ppro, const char *MessageType = nullptr) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", ppro->m_szServer, username)
+ AsyncHttpRequest(REQUEST_POST, 0, &CSkypeProto::OnMessageSent)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ m_szUrl.Format("/users/ME/conversations/8:%s/messages", username);
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
JSONNode node;
- node
- << JSONNode("clientmessageid", CMStringA(::FORMAT, "%llu", (ULONGLONG)timestamp))
+ node << JSONNode("clientmessageid", CMStringA(::FORMAT, "%llu", (ULONGLONG)timestamp))
<< JSONNode("messagetype", MessageType ? MessageType : "Text")
<< JSONNode("contenttype", "text")
<< JSONNode("content", message);
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class SendActionRequest : public HttpRequest
+struct SendActionRequest : public AsyncHttpRequest
{
-public:
SendActionRequest(const char *username, time_t timestamp, const char *message, CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", ppro->m_szServer, username)
+ AsyncHttpRequest(REQUEST_POST, 0, &CSkypeProto::OnMessageSent)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ m_szUrl.Format("/users/ME/conversations/8:%s/messages", username);
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
CMStringA content;
content.AppendFormat("%s %s", ppro->m_szSkypename.c_str(), message);
@@ -61,21 +65,20 @@ public:
<< JSONNode("contenttype", "text")
<< JSONNode("content", content)
<< JSONNode("skypeemoteoffset", ppro->m_szSkypename.GetLength() + 1);
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class SendTypingRequest : public HttpRequest
+struct SendTypingRequest : public AsyncHttpRequest
{
-public:
SendTypingRequest(const char *username, int iState, CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", ppro->m_szServer, mir_urlEncode(username).c_str())
+ AsyncHttpRequest(REQUEST_POST)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ m_szUrl.Format("/users/ME/conversations/8:%s/messages", mir_urlEncode(username).c_str());
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
const char *state = (iState == PROTOTYPE_SELFTYPING_ON) ? "Control/Typing" : "Control/ClearTyping";
@@ -85,28 +88,26 @@ public:
<< JSONNode("messagetype", state)
<< JSONNode("contenttype", "text")
<< JSONNode("content", "");
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class MarkMessageReadRequest : public HttpRequest
+struct MarkMessageReadRequest : public AsyncHttpRequest
{
-public:
MarkMessageReadRequest(const char *username, LONGLONG /*msgId*/, LONGLONG msgTimestamp, bool isChat, CSkypeProto *ppro) :
- HttpRequest(REQUEST_PUT, FORMAT, "%s/v1/users/ME/conversations/%d:%s/properties?name=consumptionhorizon", ppro->m_szServer, !isChat ? 8 : 19, username)
+ AsyncHttpRequest(REQUEST_PUT)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ m_szUrl.Format("/users/ME/conversations/%d:%s/properties?name=consumptionhorizon", !isChat ? 8 : 19, username);
+
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
//"lastReadMessageTimestamp;modificationTime;lastReadMessageId"
JSONNode node(JSON_NODE);
node << JSONNode("consumptionhorizon", CMStringA(::FORMAT, "%lld000;%lld000;%lld000", msgTimestamp, time(NULL), msgTimestamp));
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
diff --git a/protocols/SkypeWeb/src/requests/mslogin.h b/protocols/SkypeWeb/src/requests/mslogin.h
deleted file mode 100644
index 3f7930542b..0000000000
--- a/protocols/SkypeWeb/src/requests/mslogin.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
-Copyright (c) 2015-20 Miranda NG team (https://miranda-ng.org)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _SKYPE_REQUEST_LOGINMS_H_
-#define _SKYPE_REQUEST_LOGINMS_H_
-
-class LoginMSRequest : public HttpRequest
-{
-public:
- LoginMSRequest() :
- HttpRequest(REQUEST_GET, "login.skype.com/login/oauth/microsoft")
- {
- flags |= NLHRF_REDIRECT;
-
- Url
- << INT_VALUE ("client_id", 578134)
- << CHAR_VALUE ("redirect_uri", mir_urlEncode("https://web.skype.com"));
- }
- LoginMSRequest(const char *login, const char *password, const char *cookies_str, const char *ppft) :
- HttpRequest(REQUEST_POST, "login.live.com/ppsecure/post.srf")
- {
- Url
- << CHAR_VALUE ("wa", "wsignin1.0")
- << CHAR_VALUE ("wreply", "https%3A%2F%2Fsecure.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com");
-
- Headers
- << CHAR_VALUE ("Content-Type", "application/x-www-form-urlencoded")
- << CHAR_VALUE ("Cookie", cookies_str);
-
- Body
- << CHAR_VALUE ("login", mir_urlEncode(login))
- << CHAR_VALUE ("passwd", mir_urlEncode(password))
- << CHAR_VALUE ("PPFT", ppft);
- }
- LoginMSRequest(const char *t) :
- HttpRequest(REQUEST_POST, "login.skype.com/login/oauth")
- {
- Url
- << INT_VALUE ("client_id", 578134)
- << CHAR_VALUE ("redirect_uri", mir_urlEncode("https://web.skype.com"));
-
- Headers
- << CHAR_VALUE ("Content-Type", "application/x-www-form-urlencoded");
-
- Body
- << CHAR_VALUE ("t", mir_urlEncode(t))
- << INT_VALUE ("oauthPartner", 999)
- << INT_VALUE ("client_id", 578134)
- << CHAR_VALUE ("redirect_uri", mir_urlEncode("https://web.skype.com"));
- }
-
- LoginMSRequest(const char *t, int) :
- HttpRequest(REQUEST_POST, "secure.skype.com/login/oauth/proxy")
- {
- Url
- << INT_VALUE ("client_id", 578134)
- << CHAR_VALUE ("redirect_uri", mir_urlEncode("https://web.skype.com"));
-
- Headers
- << CHAR_VALUE ("Content-Type", "application/x-www-form-urlencoded");
-
- Body
- << CHAR_VALUE ("t", mir_urlEncode(t))
- << INT_VALUE ("oauthPartner", 999)
- << INT_VALUE ("client_id", 578134)
- << CHAR_VALUE ("redirect_uri", mir_urlEncode("https://web.skype.com"));
- }
-
- LoginMSRequest(const char *url, const char *login, const char *cookies_str, const char *ppft, const char *code) :
- HttpRequest(REQUEST_POST, url)
- {
- Headers
- << CHAR_VALUE ("Cookie", cookies_str);
- Body
- << CHAR_VALUE ("oct", code)
- << INT_VALUE ("AdTD", 1)
- << CHAR_VALUE ("login", mir_urlEncode(login))
- << INT_VALUE ("type", 19)
- << CHAR_VALUE ("PPFT", mir_urlEncode(ppft));
- }
-};
-
-#endif //_SKYPE_REQUEST_LOGINMS_H_
diff --git a/protocols/SkypeWeb/src/requests/oauth.h b/protocols/SkypeWeb/src/requests/oauth.h
index aef2e150c1..3f23ea50e3 100644
--- a/protocols/SkypeWeb/src/requests/oauth.h
+++ b/protocols/SkypeWeb/src/requests/oauth.h
@@ -18,50 +18,39 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_OAUTH_H_
#define _SKYPE_REQUEST_OAUTH_H_
-class OAuthRequest : public HttpRequest
+struct OAuthRequest : public AsyncHttpRequest
{
-public:
OAuthRequest() :
- HttpRequest(REQUEST_GET, "login.live.com/login.srf")
+ AsyncHttpRequest(REQUEST_GET, "login.live.com/login.srf", &CSkypeProto::OnOAuthStart)
{
flags |= NLHRF_REDIRECT;
- Url
- << CHAR_VALUE("wa", "wsignin1.0")
- << CHAR_VALUE("wp", "MBI_SSL")
- << CHAR_VALUE("wreply", "https%3A%2F%2Flw.skype.com%2Flogin%2Foauth%2Fproxy%3Fsite_name%3Dlw.skype.com")
- << CHAR_VALUE("cobrandid", "90010");
+ this << CHAR_PARAM("wa", "wsignin1.0") << CHAR_PARAM("wp", "MBI_SSL")
+ << CHAR_PARAM("wreply", "https://lw.skype.com/login/oauth/proxy?site_name=lw.skype.com")
+ << CHAR_PARAM("cobrandid", "90010");
}
OAuthRequest(const char *login, const char *password, const char *cookies, const char *ppft) :
- HttpRequest(REQUEST_POST, "login.live.com/ppsecure/post.srf")
+ AsyncHttpRequest(REQUEST_POST, "login.live.com/ppsecure/post.srf", &CSkypeProto::OnOAuthAuthorize)
{
- Url
- << CHAR_VALUE("wa", "wsignin1.0")
- << CHAR_VALUE("wp", "MBI_SSL")
- << CHAR_VALUE("wreply", "https%3A%2F%2Flw.skype.com%2Flogin%2Foauth%2Fproxy%3Fsite_name%3Dlw.skype.com")
- << CHAR_VALUE("cobrandid", "90010");
+ this << CHAR_PARAM("wa", "wsignin1.0") << CHAR_PARAM("wp", "MBI_SSL")
+ << CHAR_PARAM("wreply", "https://lw.skype.com/login/oauth/proxy?site_name=lw.skype.com")
+ << CHAR_PARAM("cobrandid", "90010");
+ m_szUrl.AppendFormat("?%s", m_szParam.c_str());
+ m_szParam.Empty();
- Headers
- << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded")
- << CHAR_VALUE("Cookie", cookies);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ AddHeader("Cookie", cookies);
- Body
- << CHAR_VALUE("login", mir_urlEncode(login))
- << CHAR_VALUE("passwd", mir_urlEncode(password))
- << CHAR_VALUE("PPFT", ppft);
+ this << CHAR_PARAM("login", login) << CHAR_PARAM("passwd", password) << CHAR_PARAM("PPFT", ppft);
}
OAuthRequest(const char *t) :
- HttpRequest(REQUEST_POST, "login.skype.com/login/microsoft")
+ AsyncHttpRequest(REQUEST_POST, "login.skype.com/login/microsoft", &CSkypeProto::OnOAuthEnd)
{
- Headers
- << CHAR_VALUE ("Content-Type", "application/x-www-form-urlencoded");
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
- Body
- << CHAR_VALUE ("t", mir_urlEncode(t))
- << CHAR_VALUE("site_name", "lw.skype.com")
- << INT_VALUE ("oauthPartner", 999);
+ this << CHAR_PARAM ("t", t) << CHAR_PARAM("site_name", "lw.skype.com") << INT_PARAM ("oauthPartner", 999);
}
};
diff --git a/protocols/SkypeWeb/src/requests/poll.h b/protocols/SkypeWeb/src/requests/poll.h
index 7293c07067..d74030dbd4 100644
--- a/protocols/SkypeWeb/src/requests/poll.h
+++ b/protocols/SkypeWeb/src/requests/poll.h
@@ -18,24 +18,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_POLL_H_
#define _SKYPE_POLL_H_
-class PollRequest : public HttpRequest
+struct PollRequest : public AsyncHttpRequest
{
-public:
PollRequest(CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/endpoints/SELF/subscriptions/0/poll", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_POST, "/users/ME/endpoints/SELF/subscriptions/0/poll")
{
timeout = 120000;
if (ppro->m_iPollingId != -1)
- Url << INT_VALUE("ackId", ppro->m_iPollingId);
+ this << INT_PARAM("ackId", ppro->m_iPollingId);
- Headers
- << CHAR_VALUE("Referer", "https://web.skype.com/main")
- << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("ClientInfo", "os=Windows; osVer=8.1; proc=Win32; lcid=en-us; deviceType=1; country=n/a; clientName=swx-skype.com; clientVer=908/1.85.0.29")
- << CHAR_VALUE("Accept", "application/json; ver=1.0")
- << CHAR_VALUE("Accept-Language", "en, C");
+ AddHeader("Referer", "https://web.skype.com/main");
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ AddHeader("ClientInfo", "os=Windows; osVer=8.1; proc=Win32; lcid=en-us; deviceType=1; country=n/a; clientName=swx-skype.com; clientVer=908/1.85.0.29");
+ AddHeader("Accept", "application/json; ver=1.0");
+ AddHeader("Accept-Language", "en, C");
+ AddRegistrationToken(ppro);
}
};
#endif //_SKYPE_POLL_H_ \ No newline at end of file
diff --git a/protocols/SkypeWeb/src/requests/profile.h b/protocols/SkypeWeb/src/requests/profile.h
index 13e5e50724..5f872b7fe8 100644
--- a/protocols/SkypeWeb/src/requests/profile.h
+++ b/protocols/SkypeWeb/src/requests/profile.h
@@ -18,15 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_PROFILE_H_
#define _SKYPE_REQUEST_PROFILE_H_
-class GetProfileRequest : public HttpRequest
+struct GetProfileRequest : public AsyncHttpRequest
{
-public:
- GetProfileRequest(CSkypeProto *ppro, const char *skypename = "self") :
- HttpRequest(REQUEST_GET, FORMAT, "api.skype.com/users/%s/profile", skypename)
+ GetProfileRequest(CSkypeProto *ppro, MCONTACT hContact) :
+ AsyncHttpRequest(REQUEST_GET, 0, &CSkypeProto::LoadProfile)
{
- Headers
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Accept", "application/json");
+ m_szUrl.Format("api.skype.com/users/%s/profile", (hContact == 0) ? "self" : ppro->getId(hContact).c_str());
+ pUserInfo = (void *)hContact;
+
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
}
};
diff --git a/protocols/SkypeWeb/src/requests/search.h b/protocols/SkypeWeb/src/requests/search.h
index 275c5df80f..3df9f2fda2 100644
--- a/protocols/SkypeWeb/src/requests/search.h
+++ b/protocols/SkypeWeb/src/requests/search.h
@@ -18,23 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_SEARCH_H_
#define _SKYPE_REQUEST_SEARCH_H_
-class GetSearchRequest : public HttpRequest
+struct GetSearchRequest : public AsyncHttpRequest
{
-public:
GetSearchRequest(const char *string, CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, "skypegraph.skype.com/search/v1.1/namesearch/swx/")
+ AsyncHttpRequest(REQUEST_GET, "skypegraph.skype.com/search/v1.1/namesearch/swx/", &CSkypeProto::OnSearch)
{
+ this << CHAR_PARAM("requestid", "skype.com-1.48.78-00000000-0000-0000-0000-000000000000")
+ << CHAR_PARAM("locale", "en-US") << CHAR_PARAM("searchstring", string);
- wchar_t locale[LOCALE_NAME_MAX_LENGTH] = L"en-US";
- //LCIDToLocaleName(Langpack_GetDefaultLocale(), locale, _countof(locale), 0); //FIXME: xp support
-
- Url
- << CHAR_VALUE("requestid", "skype.com-1.48.78-00000000-0000-0000-0000-000000000000")
- << CHAR_VALUE("locale", T2Utf(locale))
- << CHAR_VALUE("searchstring", string);
- Headers
- << CHAR_VALUE("Accept", "application/json")
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json");
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
}
};
diff --git a/protocols/SkypeWeb/src/requests/status.h b/protocols/SkypeWeb/src/requests/status.h
index 459b30471f..5b68b46ddd 100644
--- a/protocols/SkypeWeb/src/requests/status.h
+++ b/protocols/SkypeWeb/src/requests/status.h
@@ -18,54 +18,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_STATUS_H_
#define _SKYPE_REQUEST_STATUS_H_
-class GetStatusRequest : public HttpRequest
+struct GetStatusRequest : public AsyncHttpRequest
{
-public:
GetStatusRequest(CSkypeProto *ppro) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/contacts/ALL/presenceDocs/messagingService", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_GET, "/users/ME/contacts/ALL/presenceDocs/messagingService", &CSkypeProto::OnReceiveStatus)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
}
};
-class SetStatusRequest : public HttpRequest
+struct SetStatusRequest : public AsyncHttpRequest
{
-public:
SetStatusRequest(const char *status, CSkypeProto *ppro) :
- HttpRequest(REQUEST_PUT, FORMAT, "%s/v1/users/ME/presenceDocs/messagingService", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_PUT, "/users/ME/presenceDocs/messagingService", &CSkypeProto::OnStatusChanged)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
JSONNode node(JSON_NODE);
node << JSONNode("status", status);
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class SetStatusMsgRequest : public HttpRequest
+struct SetStatusMsgRequest : public AsyncHttpRequest
{
-public:
SetStatusMsgRequest(const char *status, CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, "api.skype.com/users/self/profile/partial")
+ AsyncHttpRequest(REQUEST_POST, "api.skype.com/users/self/profile/partial")
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken)
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
JSONNode node, payload;
payload.set_name("payload");
node << (payload << JSONNode("mood", status));
-
-
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
diff --git a/protocols/SkypeWeb/src/requests/subscriptions.h b/protocols/SkypeWeb/src/requests/subscriptions.h
index c10c572b38..610373f52b 100644
--- a/protocols/SkypeWeb/src/requests/subscriptions.h
+++ b/protocols/SkypeWeb/src/requests/subscriptions.h
@@ -18,58 +18,52 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_REQUEST_SUBSCIPTIONS_H_
#define _SKYPE_REQUEST_SUBSCIPTIONS_H_
-class CreateSubscriptionsRequest : public HttpRequest
+struct CreateSubscriptionsRequest : public AsyncHttpRequest
{
-public:
CreateSubscriptionsRequest(CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/endpoints/SELF/subscriptions", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_POST, "/users/ME/endpoints/SELF/subscriptions", &CSkypeProto::OnSubscriptionsCreated)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get())
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
JSONNode interestedResources(JSON_ARRAY); interestedResources.set_name("interestedResources");
- interestedResources
+ interestedResources
<< JSONNode("", "/v1/users/ME/conversations/ALL/properties")
<< JSONNode("", "/v1/users/ME/conversations/ALL/messages")
<< JSONNode("", "/v1/users/ME/contacts/ALL")
<< JSONNode("", "/v1/threads/ALL");
JSONNode node;
- node
+ node
<< JSONNode("channelType", "httpLongPoll")
<< JSONNode("template", "raw")
<< interestedResources;
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class CreateContactsSubscriptionRequest : public HttpRequest
+struct CreateContactsSubscriptionRequest : public AsyncHttpRequest
{
-public:
CreateContactsSubscriptionRequest(const LIST<char> &skypenames, CSkypeProto *ppro) :
- HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/contacts", ppro->m_szServer)
+ AsyncHttpRequest(REQUEST_POST, "/users/ME/contacts")
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", ppro->m_szToken.get());
-
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddRegistrationToken(ppro);
JSONNode node;
JSONNode contacts(JSON_ARRAY); contacts.set_name("contacts");
- for (auto &it : skypenames)
- {
+ for (auto &it : skypenames) {
JSONNode contact;
contact << JSONNode("id", CMStringA(::FORMAT, "8:%s", it));
contacts << contact;
}
node << contacts;
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
diff --git a/protocols/SkypeWeb/src/requests/trouter.h b/protocols/SkypeWeb/src/requests/trouter.h
index 85cfeea5f0..baeba2a861 100644
--- a/protocols/SkypeWeb/src/requests/trouter.h
+++ b/protocols/SkypeWeb/src/requests/trouter.h
@@ -17,53 +17,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
-class CreateTrouterRequest : public HttpRequest
+struct CreateTrouterRequest : public AsyncHttpRequest
{
-public:
CreateTrouterRequest() :
- HttpRequest(REQUEST_POST, "go.trouter.io/v2/a")
+ AsyncHttpRequest(REQUEST_POST, "go.trouter.io/v2/a", &CSkypeProto::OnCreateTrouter)
{
- Headers << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
+ AddHeader("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
}
};
-class CreateTrouterPoliciesRequest : public HttpRequest
+struct CreateTrouterPoliciesRequest : public AsyncHttpRequest
{
-public:
CreateTrouterPoliciesRequest(CSkypeProto *ppro, const char *sr) :
- HttpRequest(REQUEST_POST, FORMAT, "prod.tpc.skype.com/v1/policies")
+ AsyncHttpRequest(REQUEST_POST, "prod.tpc.skype.com/v1/policies", &CSkypeProto::OnTrouterPoliciesCreated)
{
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
- << CHAR_VALUE("X-Skypetoken", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json, text/javascript");
+ AddHeader("Content-Type", "application/json; charset=UTF-8");
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
JSONNode node;
node << JSONNode("sr", sr);
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class RegisterTrouterRequest : public HttpRequest
+struct RegisterTrouterRequest : public AsyncHttpRequest
{
-public:
RegisterTrouterRequest(CSkypeProto *ppro, const char *trouterUrl, const char *id) :
- HttpRequest(REQUEST_POST, "prod.registrar.skype.com/v2/registrations")
+ AsyncHttpRequest(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", ppro->m_szApiToken);
+ AddHeader("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
+ AddHeader("X-Skypetoken", ppro->m_szApiToken);
JSONNode clientDescription; clientDescription.set_name("clientDescription");
- clientDescription
+ clientDescription
<< JSONNode("aesKey", "")
<< JSONNode("languageId", "en-US")
<< JSONNode("platform", "SWX")
<< JSONNode("templateKey", "SkypeWeb_1.0");
JSONNode TRouter;
- TRouter
+ TRouter
<< JSONNode("context", "")
<< JSONNode("path", trouterUrl)
<< JSONNode("ttl", 3600);
@@ -75,82 +70,77 @@ public:
transports << TRouters;
JSONNode node;
- node
+ node
<< JSONNode("registrationId", id)
<< JSONNode("nodeId", "")
<< clientDescription
<< transports;
- Body << VALUE(node.write().c_str());
+ m_szParam = node.write().c_str();
}
};
-class HealthTrouterRequest : public HttpRequest
+struct HealthTrouterRequest : public AsyncHttpRequest
{
-public:
HealthTrouterRequest(const char *ccid) :
- HttpRequest(REQUEST_POST, "go.trouter.io/v2/h")
+ AsyncHttpRequest(REQUEST_POST, "go.trouter.io/v2/h", &CSkypeProto::OnHealth)
{
- Url
- << CHAR_VALUE("ccid", ccid);
+ this << CHAR_PARAM("ccid", ccid);
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
+ AddHeader("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
}
};
-class GetTrouterRequest : public HttpRequest
+struct GetTrouterRequest : public AsyncHttpRequest
{
-public:
GetTrouterRequest(const std::string &socketio, const std::string &sr, const std::string &st, const std::string &se, const std::string &sig,
const std::string &instance, const std::string &ccid) :
- HttpRequest(REQUEST_GET, FORMAT, "%ssocket.io/1/", socketio.c_str())
+ AsyncHttpRequest(REQUEST_GET, 0, &CSkypeProto::OnGetTrouter)
{
- Url
- << CHAR_VALUE("sr", sr.c_str())
- << CHAR_VALUE("issuer", "edf")
- << CHAR_VALUE("sp", "connect")
- << CHAR_VALUE("st", st.c_str())
- << CHAR_VALUE("se", se.c_str())
- << CHAR_VALUE("sig", sig.c_str())
- << CHAR_VALUE("r", instance.c_str())
- << CHAR_VALUE("v", "v2")
- << INT_VALUE("p", 443)
- << CHAR_VALUE("ccid", ccid.c_str())
- << CHAR_VALUE("tc", mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))
- << LONG_VALUE("t", time(NULL) * 1000);
-
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
+ m_szUrl.Format("%ssocket.io/1/", socketio.c_str());
+
+ this << CHAR_PARAM("sr", sr.c_str())
+ << CHAR_PARAM("issuer", "edf")
+ << CHAR_PARAM("sp", "connect")
+ << CHAR_PARAM("st", st.c_str())
+ << CHAR_PARAM("se", se.c_str())
+ << CHAR_PARAM("sig", sig.c_str())
+ << CHAR_PARAM("r", instance.c_str())
+ << CHAR_PARAM("v", "v2")
+ << INT_PARAM("p", 443)
+ << CHAR_PARAM("ccid", ccid.c_str())
+ << CHAR_PARAM("tc", mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))
+ << INT_PARAM("t", time(NULL) * 1000);
+
+ AddHeader("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
}
};
-class TrouterPollRequest : public HttpRequest
+struct TrouterPollRequest : public AsyncHttpRequest
{
-public:
TrouterPollRequest(const std::string &socketio, const std::string &sr, const std::string &st, const std::string &se, const std::string &sig,
const std::string &instance, const std::string &ccid, const std::string &sessId) :
- HttpRequest(REQUEST_GET, FORMAT, "%ssocket.io/1/xhr-polling/%s", socketio.c_str(), sessId.c_str())
+ AsyncHttpRequest(REQUEST_GET)
{
+ m_szUrl.Format("%ssocket.io/1/xhr-polling/%s", socketio.c_str(), sessId.c_str());
+
timeout = 60000;
flags |= NLHRF_PERSISTENT;
- Url
- << CHAR_VALUE("sr", sr.c_str())
- << CHAR_VALUE("issuer", "edf")
- << CHAR_VALUE("sp", "connect")
- << CHAR_VALUE("st", st.c_str())
- << CHAR_VALUE("se", se.c_str())
- << CHAR_VALUE("sig", sig.c_str())
- << CHAR_VALUE("r", instance.c_str())
- << CHAR_VALUE("v", "v2")
- << INT_VALUE("p", 443)
- << CHAR_VALUE("ccid", ccid.c_str())
- << CHAR_VALUE("tc", mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))
- << LONG_VALUE("t", time(NULL) * 1000);
-
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
+ this
+ << CHAR_PARAM("sr", sr.c_str())
+ << CHAR_PARAM("issuer", "edf")
+ << CHAR_PARAM("sp", "connect")
+ << CHAR_PARAM("st", st.c_str())
+ << CHAR_PARAM("se", se.c_str())
+ << CHAR_PARAM("sig", sig.c_str())
+ << CHAR_PARAM("r", instance.c_str())
+ << CHAR_PARAM("v", "v2")
+ << INT_PARAM("p", 443)
+ << CHAR_PARAM("ccid", ccid.c_str())
+ << CHAR_PARAM("tc", mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))
+ << INT_PARAM("t", time(NULL) * 1000);
+
+ AddHeader("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml");
}
};
-
diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp
index ad4e9646d8..0a59a52631 100644
--- a/protocols/SkypeWeb/src/skype_avatars.cpp
+++ b/protocols/SkypeWeb/src/skype_avatars.cpp
@@ -52,12 +52,12 @@ void CSkypeProto::ReloadAvatarInfo(MCONTACT hContact)
SvcGetAvatarInfo(0, (LPARAM)&ai);
}
-void CSkypeProto::OnReceiveAvatar(const NETLIBHTTPREQUEST *response, void *arg)
+void CSkypeProto::OnReceiveAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
if (response == nullptr || response->pData == nullptr)
return;
- MCONTACT hContact = (DWORD_PTR)arg;
+ MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
if (response->resultCode != 200)
return;
@@ -78,7 +78,7 @@ void CSkypeProto::OnReceiveAvatar(const NETLIBHTTPREQUEST *response, void *arg)
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai, 0);
}
-void CSkypeProto::OnSentAvatar(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnSentAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply root(response);
if (root.error())
@@ -103,7 +103,7 @@ INT_PTR CSkypeProto::SvcGetAvatarInfo(WPARAM, LPARAM lParam)
return GAIR_SUCCESS;
if (IsOnline()) {
- PushRequest(new GetAvatarRequest(szUrl), &CSkypeProto::OnReceiveAvatar, (void*)pai->hContact);
+ PushRequest(new GetAvatarRequest(szUrl, pai->hContact));
debugLogA("Requested to read an avatar from '%s'", szUrl.get());
return GAIR_WAITFOR;
}
@@ -174,7 +174,7 @@ INT_PTR CSkypeProto::SvcSetMyAvatar(WPARAM, LPARAM lParam)
if (data != NULL && fread(data, sizeof(BYTE), length, hFile) == length) {
const char *szMime = FreeImage_GetFIFMimeType(FreeImage_GetFIFFromFilenameU(path));
- PushRequest(new SetAvatarRequest(data, length, szMime, this), &CSkypeProto::OnSentAvatar);
+ PushRequest(new SetAvatarRequest(data, length, szMime, this));
fclose(hFile);
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp
index 1a6ed3b71c..ee770de407 100644
--- a/protocols/SkypeWeb/src/skype_chatrooms.cpp
+++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp
@@ -54,7 +54,7 @@ void CSkypeProto::StartChatRoom(const wchar_t *tid, const wchar_t *tname)
Chat_Control(m_szModuleName, tid, SESSION_ONLINE);
}
-void CSkypeProto::OnLoadChats(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnLoadChats(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -68,7 +68,7 @@ void CSkypeProto::OnLoadChats(const NETLIBHTTPREQUEST *response)
std::string syncState = metadata["syncState"].as_string();
if (totalCount >= 99 || conversations.size() >= 99)
- PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), this), &CSkypeProto::OnSyncHistory);
+ PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), this));
for (auto &conversation : conversations) {
if (!conversation["lastMessage"])
@@ -77,7 +77,7 @@ void CSkypeProto::OnLoadChats(const NETLIBHTTPREQUEST *response)
const JSONNode &id = conversation["id"];
const JSONNode &threadProperties = conversation["threadProperties"];
CMStringW topic(threadProperties["topic"].as_mstring());
- SendRequest(new GetChatInfoRequest(id.as_string().c_str(), this), &CSkypeProto::OnGetChatInfo, topic.Detach());
+ SendRequest(new GetChatInfoRequest(id.as_string().c_str(), topic, this));
}
}
@@ -243,12 +243,12 @@ void CSkypeProto::OnChatEvent(const JSONNode &node)
int nEmoteOffset = node["skypeemoteoffset"].as_int();
if (FindChatRoom(szConversationName) == NULL)
- SendRequest(new GetChatInfoRequest(szConversationName, this), &CSkypeProto::OnGetChatInfo, szTopic.Detach());
+ SendRequest(new GetChatInfoRequest(szConversationName, szTopic, this));
std::string messageType = node["messagetype"].as_string();
if (messageType == "Text" || messageType == "RichText") {
- ptrA szClearedContent(messageType == "RichText" ? RemoveHtml(strContent.c_str()) : mir_strdup(strContent.c_str()));
- AddMessageToChat(szConversationName, szFromSkypename, szClearedContent, nEmoteOffset != NULL, nEmoteOffset, timestamp);
+ std::string szClearedContent(messageType == "RichText" ? RemoveHtml(strContent) : strContent);
+ AddMessageToChat(szConversationName, szFromSkypename, szClearedContent.c_str(), nEmoteOffset != NULL, nEmoteOffset, timestamp);
}
else if (messageType == "ThreadActivity/AddMember") {
// <addmember><eventtime>1429186229164</eventtime><initiator>8:initiator</initiator><target>8:user</target></addmember>
@@ -359,9 +359,9 @@ void CSkypeProto::AddMessageToChat(const char *chat_id, const char *from, const
Chat_Event(&gce);
}
-void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p)
+void CSkypeProto::OnGetChatInfo(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
- ptrW topic((wchar_t*)p); // memory must be freed in any case
+ ptrW topic((wchar_t*)pRequest->pUserInfo); // memory must be freed in any case
JsonReply reply(response);
if (reply.error())
@@ -380,7 +380,7 @@ void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p)
std::string role = member["role"].as_string();
AddChatContact(chatId, username, username, role.c_str(), true);
}
- PushRequest(new GetHistoryRequest(chatId, 15, true, 0, this), &CSkypeProto::OnGetServerHistory);
+ PushRequest(new GetHistoryRequest(chatId, 15, true, 0, this));
}
void CSkypeProto::RenameChat(const char *chat_id, const char *name)
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp
index 5500ba5ba2..70e556aec3 100644
--- a/protocols/SkypeWeb/src/skype_contacts.cpp
+++ b/protocols/SkypeWeb/src/skype_contacts.cpp
@@ -90,7 +90,7 @@ MCONTACT CSkypeProto::AddContact(const char *skypename, bool isTemporary)
return hContact;
}
-void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::LoadContactsAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -127,7 +127,7 @@ void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response)
//[{"skypename":"echo123", "authorized" : true, "blocked" : false, ...},...]
// other properties is exists but empty
-void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::LoadContactList(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -178,7 +178,7 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response)
setWString(hContact, "LastName", last_name);
if (item["mood"])
- db_set_utf(hContact, "CList", "StatusMsg", ptrA(RemoveHtml(item["mood"].as_string().c_str())));
+ db_set_utf(hContact, "CList", "StatusMsg", RemoveHtml(item["mood"].as_string()).c_str());
SetAvatarUrl(hContact, avatar_url);
ReloadAvatarInfo(hContact);
@@ -199,7 +199,7 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response)
}
}
- PushRequest(new GetContactsAuthRequest(this), &CSkypeProto::LoadContactsAuth);
+ PushRequest(new GetContactsAuthRequest(this));
}
INT_PTR CSkypeProto::OnRequestAuth(WPARAM hContact, LPARAM)
@@ -232,29 +232,29 @@ INT_PTR CSkypeProto::BlockContact(WPARAM hContact, LPARAM)
if (!IsOnline()) return 1;
if (IDYES == MessageBox(NULL, TranslateT("Are you sure?"), TranslateT("Warning"), MB_YESNO | MB_ICONQUESTION))
- SendRequest(new BlockContactRequest(this, getId(hContact)), &CSkypeProto::OnBlockContact, (void *)hContact);
+ SendRequest(new BlockContactRequest(this, hContact));
return 0;
}
-void CSkypeProto::OnBlockContact(const NETLIBHTTPREQUEST *response, void *p)
+void CSkypeProto::OnBlockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
- MCONTACT hContact = (DWORD_PTR)p;
+ MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
if (response != nullptr)
Contact_Hide(hContact);
}
INT_PTR CSkypeProto::UnblockContact(WPARAM hContact, LPARAM)
{
- SendRequest(new UnblockContactRequest(this, getId(hContact)), &CSkypeProto::OnUnblockContact, (void *)hContact);
+ SendRequest(new UnblockContactRequest(this, hContact));
return 0;
}
-void CSkypeProto::OnUnblockContact(const NETLIBHTTPREQUEST *response, void *p)
+void CSkypeProto::OnUnblockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
if (response == nullptr)
return;
- MCONTACT hContact = (DWORD_PTR)p;
+ MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
Contact_Hide(hContact, false);
delSetting(hContact, "IsBlocked");
}
diff --git a/protocols/SkypeWeb/src/skype_files.cpp b/protocols/SkypeWeb/src/skype_files.cpp
index d74dd71fe6..158ba0c25e 100644
--- a/protocols/SkypeWeb/src/skype_files.cpp
+++ b/protocols/SkypeWeb/src/skype_files.cpp
@@ -25,13 +25,12 @@ void CSkypeProto::SendFileThread(void *p)
}
ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)fup);
- T2Utf uszFileName(fup->tszFileName);
- SendRequest(new ASMObjectCreateRequest(this, CMStringA(FORMAT, "%d:%s", isChatRoom(fup->hContact) ? 19 : 8, getId(fup->hContact).c_str()), strrchr((const char*)uszFileName + 1, '\\')), &CSkypeProto::OnASMObjectCreated, fup);
+ SendRequest(new ASMObjectCreateRequest(this, fup));
}
-void CSkypeProto::OnASMObjectCreated(const NETLIBHTTPREQUEST *response, void *arg)
+void CSkypeProto::OnASMObjectCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
- CFileUploadParam *fup = (CFileUploadParam*)arg;
+ auto *fup = (CFileUploadParam*)pRequest->pUserInfo;
if (response == nullptr || response->pData == nullptr) {
LBL_Error:
FILETRANSFER_FAILED(fup);
@@ -71,13 +70,13 @@ LBL_Error:
}
fup->size = lBytes;
ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)fup);
- SendRequest(new ASMObjectUploadRequest(this, strObjectId.c_str(), pData, lBytes), &CSkypeProto::OnASMObjectUploaded, fup);
+ SendRequest(new ASMObjectUploadRequest(this, strObjectId.c_str(), pData, lBytes, fup));
fclose(pFile);
}
-void CSkypeProto::OnASMObjectUploaded(const NETLIBHTTPREQUEST *response, void *arg)
+void CSkypeProto::OnASMObjectUploaded(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
- CFileUploadParam *fup = (CFileUploadParam*)arg;
+ auto *fup = (CFileUploadParam*)pRequest->pUserInfo;
if (response == nullptr) {
FILETRANSFER_FAILED(fup);
return;
diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp
index f17d988f26..20cdd9850a 100644
--- a/protocols/SkypeWeb/src/skype_history_sync.cpp
+++ b/protocols/SkypeWeb/src/skype_history_sync.cpp
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* HISTORY SYNC */
-void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -35,7 +35,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response)
bool markAllAsUnread = getBool("MarkMesUnread", true);
if (totalCount >= 99 || conversations.size() >= 99)
- PushRequest(new GetHistoryOnUrlRequest(syncState.c_str(), this), &CSkypeProto::OnGetServerHistory);
+ PushRequest(new GetHistoryOnUrlRequest(syncState.c_str(), this));
for (int i = (int)conversations.size(); i >= 0; i--) {
const JSONNode &message = conversations.at(i);
@@ -67,10 +67,10 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response)
if (strstr(conversationLink.c_str(), "/8:")) {
if (messageType == "Text" || messageType == "RichText") {
- ptrA szMessage(messageType == "RichText" ? RemoveHtml(content.c_str()) : mir_strdup(content.c_str()));
+ std::string szMessage(messageType == "RichText" ? RemoveHtml(content) : content);
MEVENT dbevent = GetMessageFromDb(szMessageId);
if (isEdited && dbevent != NULL)
- EditEvent(hContact, dbevent, szMessage, timestamp);
+ EditEvent(hContact, dbevent, szMessage.c_str(), timestamp);
else
AddDbEvent(emoteOffset == 0 ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION, hContact, timestamp, iFlags, &szMessage[emoteOffset], szMessageId);
}
@@ -95,21 +95,20 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response)
}
else if (conversationLink.find("/19:") != -1) {
CMStringA chatname(UrlToSkypename(conversationLink.c_str()));
- ptrA szMessage(messageType == "RichText" ? RemoveHtml(content.c_str()) : mir_strdup(content.c_str()));
- if (messageType == "Text" || messageType == "RichText") {
- AddMessageToChat(chatname, skypename, szMessage, emoteOffset != NULL, emoteOffset, timestamp, true);
- }
+ std::string szMessage(messageType == "RichText" ? RemoveHtml(content) : content);
+ if (messageType == "Text" || messageType == "RichText")
+ AddMessageToChat(chatname, skypename, szMessage.c_str(), emoteOffset != NULL, emoteOffset, timestamp, true);
}
}
}
INT_PTR CSkypeProto::GetContactHistory(WPARAM hContact, LPARAM)
{
- PushRequest(new GetHistoryRequest(getId(hContact), 100, false, 0, this), &CSkypeProto::OnGetServerHistory);
+ PushRequest(new GetHistoryRequest(getId(hContact), 100, false, 0, this));
return 0;
}
-void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnSyncHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -123,7 +122,7 @@ void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response)
std::string syncState = metadata["syncState"].as_string();
if (totalCount >= 99 || conversations.size() >= 99)
- PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), this), &CSkypeProto::OnSyncHistory);
+ PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), this));
for (auto &conversation : conversations) {
const JSONNode &lastMessage = conversation["lastMessage"];
@@ -135,11 +134,9 @@ void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response)
time_t composeTime(IsoToUnixTime(lastMessage["composetime"].as_string().c_str()));
MCONTACT hContact = FindContact(szSkypename);
- if (hContact != NULL) {
- if (getDword(hContact, "LastMsgTime", 0) < composeTime) {
- PushRequest(new GetHistoryRequest(szSkypename, 100, false, 0, this), &CSkypeProto::OnGetServerHistory);
- }
- }
+ if (hContact != NULL)
+ if (getDword(hContact, "LastMsgTime", 0) < composeTime)
+ PushRequest(new GetHistoryRequest(szSkypename, 100, false, 0, this));
}
}
}
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp
index 61420cc4ce..9918acc54a 100644
--- a/protocols/SkypeWeb/src/skype_login.cpp
+++ b/protocols/SkypeWeb/src/skype_login.cpp
@@ -21,7 +21,7 @@ void CSkypeProto::Login()
{
// login
m_iStatus = ID_STATUS_CONNECTING;
- requestQueue->Start();
+ StartQueue();
int tokenExpires(getDword("TokenExpiresIn", 0));
m_szSkypename = getMStringA(SKYPE_SETTINGS_ID);
@@ -36,10 +36,10 @@ void CSkypeProto::Login()
if ((tokenExpires - 1800) > time(0))
OnLoginSuccess();
- PushRequest(new OAuthRequest(), &CSkypeProto::OnOAuthStart);
+ PushRequest(new OAuthRequest());
}
-void CSkypeProto::OnLoginOAuth(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnLoginOAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (!IsStatusConnecting(m_iStatus)) return;
@@ -113,10 +113,10 @@ void CSkypeProto::OnLoginSuccess()
m_impl.m_heartBeat.StartSafe(600 * 1000);
- SendRequest(new CreateEndpointRequest(this), &CSkypeProto::OnEndpointCreated);
+ SendRequest(new CreateEndpointRequest(this));
}
-void CSkypeProto::OnEndpointCreated(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (!IsStatusConnecting(m_iStatus))
return;
@@ -142,7 +142,7 @@ void CSkypeProto::OnEndpointCreated(const NETLIBHTTPREQUEST *response)
if (!strstr(szStatus, "SkypeTokenExpired"))
delSetting("TokenSecret");
delSetting("TokenExpiresIn");
- SendRequest(new LoginOAuthRequest(m_szSkypename, pass_ptrA(getStringA(SKYPE_SETTINGS_PASSWORD))), &CSkypeProto::OnLoginOAuth);
+ SendRequest(new LoginOAuthRequest(m_szSkypename, pass_ptrA(getStringA(SKYPE_SETTINGS_PASSWORD))));
return;
case 400:
@@ -152,7 +152,7 @@ void CSkypeProto::OnEndpointCreated(const NETLIBHTTPREQUEST *response)
return;
default: // it should be rewritten
- SendRequest(new CreateEndpointRequest(this), &CSkypeProto::OnEndpointCreated);
+ SendRequest(new CreateEndpointRequest(this));
return;
}
@@ -188,10 +188,10 @@ void CSkypeProto::OnEndpointCreated(const NETLIBHTTPREQUEST *response)
RefreshStatuses();
- SendRequest(new CreateSubscriptionsRequest(this), &CSkypeProto::OnSubscriptionsCreated);
+ SendRequest(new CreateSubscriptionsRequest(this));
}
-void CSkypeProto::OnSubscriptionsCreated(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnSubscriptionsCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (!IsStatusConnecting(m_iStatus))
return;
@@ -220,12 +220,12 @@ void CSkypeProto::SendPresence(bool isLogin)
}
if (isLogin)
- SendRequest(new SendCapabilitiesRequest(epname, this), &CSkypeProto::OnCapabilitiesSended);
+ SendRequest(new SendCapabilitiesRequest(epname, this));
else
PushRequest(new SendCapabilitiesRequest(epname, this));
}
-void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnCapabilitiesSended(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (!IsStatusConnecting(m_iStatus))
return;
@@ -236,7 +236,7 @@ void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response)
return;
}
- SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), this), &CSkypeProto::OnStatusChanged);
+ SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), this));
LIST<char> skypenames(1);
for (auto &hContact : AccContacts())
@@ -249,22 +249,22 @@ void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response)
m_hPollingEvent.Set();
- SendRequest(new LoadChatsRequest(this), &CSkypeProto::OnLoadChats);
- SendRequest(new CreateTrouterRequest(), &CSkypeProto::OnCreateTrouter);
- PushRequest(new GetContactListRequest(this, nullptr), &CSkypeProto::LoadContactList);
- PushRequest(new GetAvatarRequest(ptrA(getStringA("AvatarUrl"))), &CSkypeProto::OnReceiveAvatar, NULL);
+ SendRequest(new LoadChatsRequest(this));
+ SendRequest(new CreateTrouterRequest());
+ PushRequest(new GetContactListRequest(this, nullptr));
+ PushRequest(new GetAvatarRequest(ptrA(getStringA("AvatarUrl")), 0));
if (m_opts.bAutoHistorySync)
- PushRequest(new SyncHistoryFirstRequest(100, this), &CSkypeProto::OnSyncHistory);
+ PushRequest(new SyncHistoryFirstRequest(100, this));
JSONNode root = JSONNode::parse(response->pData);
if (root)
setString("SelfEndpointName", UrlToSkypename(root["selfLink"].as_string().c_str()));
- PushRequest(new GetProfileRequest(this), &CSkypeProto::LoadProfile, nullptr);
+ PushRequest(new GetProfileRequest(this, 0));
}
-void CSkypeProto::OnStatusChanged(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnStatusChanged(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (response == nullptr || response->pData == nullptr) {
debugLogA(__FUNCTION__ ": failed to change status");
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp
index 166222998b..d5cd19f31d 100644
--- a/protocols/SkypeWeb/src/skype_messages.cpp
+++ b/protocols/SkypeWeb/src/skype_messages.cpp
@@ -19,12 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* MESSAGE SENDING */
-struct SendMessageParam
-{
- MCONTACT hContact;
- DWORD hMessage;
-};
-
// outcoming message flow
int CSkypeProto::OnSendMessage(MCONTACT hContact, int, const char *szMessage)
{
@@ -40,11 +34,13 @@ int CSkypeProto::OnSendMessage(MCONTACT hContact, int, const char *szMessage)
ptrA username(getStringA(hContact, "Skypename"));
+ AsyncHttpRequest *pReq;
if (strncmp(szMessage, "/me ", 4) == 0)
- SendRequest(new SendActionRequest(username, param->hMessage, &szMessage[4], this), &CSkypeProto::OnMessageSent, param);
+ pReq = new SendActionRequest(username, param->hMessage, &szMessage[4], this);
else
- SendRequest(new SendMessageRequest(username, param->hMessage, szMessage, this), &CSkypeProto::OnMessageSent, param);
-
+ pReq = new SendMessageRequest(username, param->hMessage, szMessage, this);
+ pReq->pUserInfo = param;
+ SendRequest(pReq);
{
mir_cslock lck(m_lckOutMessagesList);
m_OutMessages.insert((void*)param->hMessage);
@@ -52,9 +48,9 @@ int CSkypeProto::OnSendMessage(MCONTACT hContact, int, const char *szMessage)
return param->hMessage;
}
-void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
+void CSkypeProto::OnMessageSent(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
- SendMessageParam *param = (SendMessageParam*)arg;
+ auto *param = (SendMessageParam*)pRequest->pUserInfo;
MCONTACT hContact = param->hContact;
HANDLE hMessage = (HANDLE)param->hMessage;
delete param;
@@ -102,7 +98,7 @@ void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node)
std::string strMessageType = node["messagetype"].as_string();
std::string strContent = node["content"].as_string();
- ptrA szClearedContent(strMessageType == "RichText" ? RemoveHtml(strContent.c_str()) : mir_strdup(strContent.c_str()));
+ std::string szClearedContent(strMessageType == "RichText" ? RemoveHtml(strContent) : strContent);
bool bEdited = node["skypeeditedid"];
time_t timestamp = time(0); // fuck the server time, we need to place events in the order of our local time
@@ -125,26 +121,22 @@ void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node)
HANDLE hMessage = (HANDLE)atoi(szMessageId);
if (m_OutMessages.getIndex(hMessage) != -1) {
ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, hMessage, (LPARAM)szMessageId.c_str());
- {
- mir_cslock lck(m_lckOutMessagesList);
- m_OutMessages.remove(hMessage);
- }
- }
- else {
- AddDbEvent(nEmoteOffset == 0 ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION, hContact,
- timestamp, DBEF_UTF | DBEF_SENT, &szClearedContent[nEmoteOffset], szMessageId);
+
+ mir_cslock lck(m_lckOutMessagesList);
+ m_OutMessages.remove(hMessage);
}
+ else AddDbEvent(nEmoteOffset == 0 ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION, hContact, timestamp, DBEF_UTF | DBEF_SENT, &szClearedContent[nEmoteOffset], szMessageId);
}
else {
CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF);
MEVENT hDbEvent = GetMessageFromDb(szMessageId);
if (bEdited && hDbEvent != NULL)
- EditEvent(hContact, hDbEvent, szClearedContent, timestamp);
+ EditEvent(hContact, hDbEvent, szClearedContent.c_str(), timestamp);
else {
PROTORECVEVENT recv = {};
recv.timestamp = timestamp;
- recv.szMessage = mir_strdup(szClearedContent);
+ recv.szMessage = (char*)szClearedContent.c_str();
recv.lParam = nEmoteOffset;
recv.szMsgId = szMessageId;
ProtoChainRecvMsg(hContact, &recv);
diff --git a/protocols/SkypeWeb/src/skype_mslogin.cpp b/protocols/SkypeWeb/src/skype_mslogin.cpp
deleted file mode 100644
index fedaa74211..0000000000
--- a/protocols/SkypeWeb/src/skype_mslogin.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
-Copyright (c) 2015-20 Miranda NG team (https://miranda-ng.org)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#include "stdafx.h"
-
-void CSkypeProto::OnMSLoginFirst(const NETLIBHTTPREQUEST *response)
-{
- if (response == nullptr || response->pData == nullptr) {
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- std::regex regex;
- std::smatch match;
- std::map<std::string, std::string> scookies;
- std::string content = response->pData;
-
- regex = "<input.+?type=\"hidden\".+?name=\"PPFT\".+?id=\"i0327\".+?value=\"(.+?)\".*?/>";
-
- if (!std::regex_search(content, match, regex)) {
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
- std::string PPTF = match[1];
-
- for (int i = 0; i < response->headersCount; i++) {
- if (mir_strcmpi(response->headers[i].szName, "Set-Cookie"))
- continue;
-
- regex = "^(.+?)=(.+?);";
- content = response->headers[i].szValue;
- if (std::regex_search(content, match, regex))
- scookies[match[1]] = match[2];
- }
-
- CMStringA mscookies(FORMAT, "MSPRequ=%s;MSPOK=%s;CkTst=G%lld;", scookies["MSPRequ"].c_str(), scookies["MSPOK"].c_str(), time(NULL));
-
- SendRequest(new LoginMSRequest(ptrA(getStringA(SKYPE_SETTINGS_ID)), ptrA(getStringA(SKYPE_SETTINGS_PASSWORD)), mscookies.c_str(), PPTF.c_str()), &CSkypeProto::OnMSLoginSecond);
-}
-
-void CSkypeProto::OnMSLoginSecond(const NETLIBHTTPREQUEST *response)
-{
- if (response == nullptr || response->pData == nullptr) {
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- std::regex regex;
- std::smatch match;
- std::string content = response->pData;
- ptrA szContent(response->pData);
-
- regex = "<meta.+?name=\"PageID\".+?content=\"(.+?)\".*?/>";
- if (std::regex_search(content, match, regex)) {
- if (match[1] == "i5600") {
- CMStringA szCookies;
- for (int i = 0; i < response->headersCount; i++) {
- if (mir_strcmpi(response->headers[i].szName, "Set-Cookie"))
- continue;
-
- regex = "^(.+?)=(.+?);";
- content = response->headers[i].szValue;
- if (std::regex_search(content, match, regex))
- if (!std::string(match[2]).empty() && std::string(match[2]) != " ")
- szCookies.AppendFormat("%s=%s;", std::string(match[1]).c_str(), std::string(match[2]).c_str());
- }
-
- CMStringA url(GetStringChunk(szContent, "urlPost:'", "'"));
- CMStringA ppft(GetStringChunk(szContent, "sFT:'", "'"));
-
- ptrA code(mir_utf8encodeW(RunConfirmationCode()));
-
- SendRequest(new LoginMSRequest(url.c_str(), ptrA(getStringA(SKYPE_SETTINGS_ID)), szCookies.c_str(), ppft.c_str(), code), &CSkypeProto::OnMSLoginEnd);
- return;
- }
- }
-
- regex = "<input.+?type=\"hidden\".+?name=\"t\".+?id=\"t\".+?value=\"(.+?)\".*?>";
- if (!std::regex_search(content, match, regex)) {
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
- std::string t = match[1];
-
- SendRequest(new LoginMSRequest(t.c_str(), 0), &CSkypeProto::OnMSLoginThird);
-}
-
-void CSkypeProto::OnMSLoginThird(const NETLIBHTTPREQUEST *response)
-{
- if (response == nullptr || response->pData == nullptr) {
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- std::regex regex;
- std::smatch match;
- std::string content = response->pData;
-
- regex = "<input.+?type=\"hidden\".+?name=\"t\".+?value=\"(.+?)\".*?/>";
-
- if (!std::regex_search(content, match, regex)) {
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
- std::string t = match[1];
-
- SendRequest(new LoginMSRequest(t.c_str()), &CSkypeProto::OnMSLoginEnd);
-}
-
-void CSkypeProto::OnMSLoginEnd(const NETLIBHTTPREQUEST *response)
-{
- if (response == nullptr || response->pData == nullptr) {
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- std::regex regex;
- std::smatch match;
- std::string content = response->pData;
-
- regex = "<input.+?type=\"hidden\".+?name=\"skypetoken\".+?value=\"(.+?)\".*?/>";
- if (!std::regex_search(content, match, regex)) {
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
- std::string token = match[1];
- setString("TokenSecret", token.c_str());
- regex = "<input.+?type=\"hidden\".+?name=\"expires_in\".+?value=\"(.+?)\".*?/>";
-
- if (std::regex_search(content, match, regex)) {
- std::string expiresIn = match[1];
- int seconds = atoi(expiresIn.c_str());
- setDword("TokenExpiresIn", time(NULL) + seconds);
- }
-
- OnLoginSuccess();
-}
-
-CMStringW CSkypeProto::RunConfirmationCode()
-{
- CMStringW caption(FORMAT, L"[%s] %s", _A2T(m_szModuleName), TranslateT("Enter confirmation code"));
- ENTER_STRING pForm = {};
- pForm.type = ESF_PASSWORD;
- pForm.caption = caption;
- pForm.ptszInitVal = nullptr;
- pForm.szModuleName = m_szModuleName;
- return (!EnterString(&pForm)) ? CMStringW() : CMStringW(ptrW(pForm.ptszResult));
-}
diff --git a/protocols/SkypeWeb/src/skype_oauth.cpp b/protocols/SkypeWeb/src/skype_oauth.cpp
index d00fc7fa10..8a202bdf09 100644
--- a/protocols/SkypeWeb/src/skype_oauth.cpp
+++ b/protocols/SkypeWeb/src/skype_oauth.cpp
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-void CSkypeProto::OnOAuthStart(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnOAuthStart(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (response == nullptr || response->pData == nullptr) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
@@ -53,10 +53,10 @@ void CSkypeProto::OnOAuthStart(const NETLIBHTTPREQUEST *response)
ptrA password(getStringA(SKYPE_SETTINGS_PASSWORD));
CMStringA mscookies(FORMAT, "MSPRequ=%s;MSPOK=%s;CkTst=G%lld;", scookies["MSPRequ"].c_str(), scookies["MSPOK"].c_str(), time(NULL));
- PushRequest(new OAuthRequest(login, password, mscookies.c_str(), PPTF.c_str()), &CSkypeProto::OnOAuthAuthorize);
+ PushRequest(new OAuthRequest(login, password, mscookies.c_str(), PPTF.c_str()));
}
-void CSkypeProto::OnOAuthAuthorize(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (response == nullptr || response->pData == nullptr) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
@@ -75,10 +75,10 @@ void CSkypeProto::OnOAuthAuthorize(const NETLIBHTTPREQUEST *response)
}
std::string t = match[1];
- PushRequest(new OAuthRequest(t.c_str()), &CSkypeProto::OnOAuthEnd);
+ PushRequest(new OAuthRequest(t.c_str()));
}
-void CSkypeProto::OnOAuthEnd(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnOAuthEnd(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (response == nullptr || response->pData == nullptr) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp
index c86f90dcd1..a9e4c0c737 100644
--- a/protocols/SkypeWeb/src/skype_polling.cpp
+++ b/protocols/SkypeWeb/src/skype_polling.cpp
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-void CSkypeProto::PollingThread(void*)
+void CSkypeProto::PollingThread(void *)
{
debugLogA(__FUNCTION__ ": entering");
@@ -31,7 +31,7 @@ void CSkypeProto::PollingThread(void*)
while ((nErrors < POLLING_ERRORS_LIMIT) && m_iStatus != ID_STATUS_OFFLINE) {
std::unique_ptr<PollRequest> request(new PollRequest(this));
- NLHR_PTR response(request->Send(m_hNetlibUser));
+ NLHR_PTR response(DoSend(request.get()));
if (response == nullptr) {
nErrors++;
continue;
@@ -100,7 +100,7 @@ void CSkypeProto::ParsePollData(const char *szData)
void CSkypeProto::ProcessEndpointPresence(const JSONNode &node)
{
- debugLogA("CSkypeProto::ProcessEndpointPresenceRes");
+ debugLogA(__FUNCTION__);
std::string selfLink = node["selfLink"].as_string();
CMStringA skypename(UrlToSkypename(selfLink.c_str()));
@@ -163,7 +163,7 @@ void CSkypeProto::ProcessEndpointPresence(const JSONNode &node)
void CSkypeProto::ProcessUserPresence(const JSONNode &node)
{
- debugLogA("CSkypeProto::ProcessUserPresenceRes");
+ debugLogA(__FUNCTION__);
std::string selfLink = node["selfLink"].as_string();
std::string status = node["status"].as_string();
@@ -199,5 +199,5 @@ void CSkypeProto::ProcessNewMessage(const JSONNode &node)
OnChatEvent(node);
}
-void CSkypeProto::ProcessConversationUpdate(const JSONNode&) {}
-void CSkypeProto::ProcessThreadUpdate(const JSONNode&) {} \ No newline at end of file
+void CSkypeProto::ProcessConversationUpdate(const JSONNode &) {}
+void CSkypeProto::ProcessThreadUpdate(const JSONNode &) {}
diff --git a/protocols/SkypeWeb/src/skype_profile.cpp b/protocols/SkypeWeb/src/skype_profile.cpp
index adad8300e0..3751f5dc89 100644
--- a/protocols/SkypeWeb/src/skype_profile.cpp
+++ b/protocols/SkypeWeb/src/skype_profile.cpp
@@ -397,9 +397,9 @@ void CSkypeProto::UpdateProfileAvatar(const JSONNode &root, MCONTACT hContact)
}
//{"firstname":"Echo \/ Sound Test Service", "lastname" : null, "birthday" : null, "gender" : null, "country" : null, "city" : null, "language" : null, "homepage" : null, "about" : null, "province" : null, "jobtitle" : null, "emails" : [], "phoneMobile" : null, "phoneHome" : null, "phoneOffice" : null, "mood" : null, "richMood" : null, "avatarUrl" : null, "username" : "echo123"}
-void CSkypeProto::LoadProfile(const NETLIBHTTPREQUEST *response, void *arg)
+void CSkypeProto::LoadProfile(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
- MCONTACT hContact = (DWORD_PTR)arg;
+ MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
JsonReply reply(response);
if (reply.error()) {
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp
index 7faf918ee3..efa4383d7e 100644
--- a/protocols/SkypeWeb/src/skype_proto.cpp
+++ b/protocols/SkypeWeb/src/skype_proto.cpp
@@ -27,12 +27,11 @@ CSkypeProto::CSkypeProto(const char* protoName, const wchar_t* userName) :
m_TrouterConnection(nullptr),
m_opts(this),
m_impl(*this),
- m_szServer(mir_strdup(SKYPE_ENDPOINTS_HOST))
+ m_requests(1),
+ m_szServer(mir_strdup("azeus1-client-s.gateway.messenger.live.com"))
{
InitNetwork();
- requestQueue = new RequestQueue(m_hNetlibUser);
-
CreateProtoService(PS_CREATEACCMGRUI, &CSkypeProto::OnAccountManagerInit);
CreateProtoService(PS_GETAVATARINFO, &CSkypeProto::SvcGetAvatarInfo);
CreateProtoService(PS_GETAVATARCAPS, &CSkypeProto::SvcGetAvatarCaps);
@@ -61,8 +60,11 @@ CSkypeProto::CSkypeProto(const char* protoName, const wchar_t* userName) :
CSkypeProto::~CSkypeProto()
{
- requestQueue->Stop();
- delete requestQueue; requestQueue = nullptr;
+ StopQueue();
+ if (m_hRequestQueueThread) {
+ WaitForSingleObject(m_hRequestQueueThread, INFINITE);
+ m_hRequestQueueThread = nullptr;
+ }
UnInitNetwork();
UninitPopups();
@@ -93,7 +95,7 @@ void CSkypeProto::OnShutdown()
{
debugLogA(__FUNCTION__);
- requestQueue->Stop();
+ StopQueue();
m_bThreadsTerminated = true;
@@ -120,26 +122,34 @@ INT_PTR CSkypeProto::GetCaps(int type, MCONTACT)
int CSkypeProto::SetAwayMsg(int, const wchar_t *msg)
{
- PushRequest(new SetStatusMsgRequest(msg ? T2Utf(msg) : "", this));
+ if (IsOnline())
+ PushRequest(new SetStatusMsgRequest(msg ? T2Utf(msg) : "", this));
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CSkypeProto::OnReceiveAwayMsg(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+{
+ JsonReply reply(response);
+ if (reply.error())
+ return;
+
+ MCONTACT hContact = DWORD_PTR(pRequest->pUserInfo);
+ auto &root = reply.data();
+ if (JSONNode &mood = root["mood"]) {
+ CMStringW str = mood.as_mstring();
+ ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)str.c_str());
+ }
+ else {
+ ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ }
+}
+
HANDLE CSkypeProto::GetAwayMsg(MCONTACT hContact)
{
- PushRequest(new GetProfileRequest(this, getId(hContact)), [this, hContact](const NETLIBHTTPREQUEST *response) {
- JsonReply reply(response);
- if (reply.error())
- return;
-
- auto &root = reply.data();
- if (JSONNode &mood = root["mood"]) {
- CMStringW str = mood.as_mstring();
- this->ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)str.c_str());
- }
- else {
- this->ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, 0);
- }
- });
+ auto *pReq = new GetProfileRequest(this, hContact);
+ pReq->m_pFunc = &CSkypeProto::OnReceiveAwayMsg;
return (HANDLE)1;
}
@@ -219,7 +229,7 @@ int CSkypeProto::GetInfo(MCONTACT hContact, int)
if (isChatRoom(hContact))
return 1;
- PushRequest(new GetProfileRequest(this, getId(hContact)), &CSkypeProto::LoadProfile, (void*)hContact);
+ PushRequest(new GetProfileRequest(this, hContact));
return 0;
}
@@ -260,7 +270,7 @@ int CSkypeProto::SetStatus(int iNewStatus)
}
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
// logout
- requestQueue->Stop();
+ StopQueue();
CloseDialogs();
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, ID_STATUS_OFFLINE);
@@ -279,7 +289,7 @@ int CSkypeProto::SetStatus(int iNewStatus)
Login();
}
else {
- SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), this), &CSkypeProto::OnStatusChanged);
+ SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), this));
}
}
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index be5926d761..32d68de785 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -18,10 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SKYPE_PROTO_H_
#define _SKYPE_PROTO_H_
-typedef void(CSkypeProto::*SkypeResponseCallback)(const NETLIBHTTPREQUEST *response);
-typedef void(CSkypeProto::*SkypeResponseWithArgCallback)(const NETLIBHTTPREQUEST *response, void *arg);
-
-struct CSkypeProto : public PROTO < CSkypeProto >
+struct CSkypeProto : public PROTO <CSkypeProto>
{
friend CSkypeOptionsMain;
friend CSkypeGCCreateDlg;
@@ -112,9 +109,50 @@ public:
return getMStringA(hContact, SKYPE_SETTINGS_ID);
}
-private:
- class RequestQueue *requestQueue;
+ void OnReceiveAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnSentAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnSearch(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ // login
+ void OnLoginOAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnSubscriptionsCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnCapabilitiesSended(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnStatusChanged(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnReceiveStatus(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ // oauth
+ void OnOAuthStart(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnOAuthAuthorize(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnOAuthEnd(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ void OnCreateTrouter(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnTrouterPoliciesCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnGetTrouter(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnHealth(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ void OnASMObjectCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnASMObjectUploaded(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ void LoadContactsAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void LoadContactList(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ void OnBlockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnUnblockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ void OnMessageSent(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ void OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnSyncHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ void OnLoadChats(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnGetChatInfo(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnReceiveAwayMsg(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+ void LoadProfile(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+
+private:
bool m_bHistorySynced;
std::map<std::string, std::string> cookies;
@@ -162,27 +200,23 @@ private:
void UnInitNetwork();
void ShutdownConnections();
- void PushRequest(HttpRequest *request);
- void PushRequest(HttpRequest *request, SkypeResponseCallback response);
- void PushRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg);
+ bool m_isTerminated = true;
+ mir_cs m_requestQueueLock;
+ LIST<AsyncHttpRequest> m_requests;
+ EventHandle m_hRequestQueueEvent;
+ HANDLE m_hRequestQueueThread;
- template<typename F>
- void PushRequest(HttpRequest *request, F callback)
- {
- SkypeResponseDelegateBase *delegate = new SkypeResponseDelegateLambda<F>(this, callback);
- requestQueue->Push(request, SkypeHttpResponse, delegate);
- }
+ static unsigned __cdecl AsyncSendThread(void *, void *);
+ void __cdecl WorkerThread(void *);
- void SendRequest(HttpRequest *request);
- void SendRequest(HttpRequest *request, SkypeResponseCallback response);
- void SendRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg);
+ void StartQueue();
+ void StopQueue();
- template<typename F>
- void SendRequest(HttpRequest *request, F callback)
- {
- SkypeResponseDelegateBase *delegate = new SkypeResponseDelegateLambda<F>(this, response);
- requestQueue->Send(request, SkypeHttpResponse, delegate);
- }
+ NETLIBHTTPREQUEST* DoSend(AsyncHttpRequest *request);
+
+ void Execute(AsyncHttpRequest *request);
+ void PushRequest(AsyncHttpRequest *request);
+ void SendRequest(AsyncHttpRequest *request);
// menus
static HGENMENU ContactMenuItems[CMI_MAX];
@@ -192,32 +226,12 @@ private:
// options
int __cdecl OnOptionsInit(WPARAM wParam, LPARAM lParam);
- // oauth
- void OnOAuthStart(const NETLIBHTTPREQUEST *response);
- void OnOAuthAuthorize(const NETLIBHTTPREQUEST *response);
- void OnOAuthEnd(const NETLIBHTTPREQUEST *response);
-
// login
void Login();
- void OnMSLoginFirst(const NETLIBHTTPREQUEST *response);
- void OnMSLoginSecond(const NETLIBHTTPREQUEST *response);
- void OnMSLoginThird(const NETLIBHTTPREQUEST *response);
- void OnMSLoginEnd(const NETLIBHTTPREQUEST *response);
- void OnLoginOAuth(const NETLIBHTTPREQUEST *response);
void OnLoginSuccess();
- void OnEndpointCreated(const NETLIBHTTPREQUEST *response);
void SendPresence(bool isLogin = false);
- void OnSubscriptionsCreated(const NETLIBHTTPREQUEST *response);
- void OnCapabilitiesSended(const NETLIBHTTPREQUEST *response);
- void OnStatusChanged(const NETLIBHTTPREQUEST *response);
- void OnReceiveStatus(const NETLIBHTTPREQUEST *response);
-
- //TRouter
-
- void OnCreateTrouter(const NETLIBHTTPREQUEST *response);
- void OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response);
- void OnGetTrouter(const NETLIBHTTPREQUEST *response);
- void OnHealth(const NETLIBHTTPREQUEST *response);
+
+ // TRouter
void OnTrouterEvent(const JSONNode &body, const JSONNode &headers);
void __cdecl TRouterThread(void*);
@@ -240,12 +254,7 @@ private:
void UpdateProfileXStatusMessage(const JSONNode &root, MCONTACT hContact = NULL);
void UpdateProfileAvatar(const JSONNode &root, MCONTACT hContact = NULL);
- void LoadProfile(const NETLIBHTTPREQUEST *response, void *arg);
-
-
void __cdecl CSkypeProto::SendFileThread(void *p);
- void OnASMObjectCreated(const NETLIBHTTPREQUEST *response, void *arg);
- void OnASMObjectUploaded(const NETLIBHTTPREQUEST *response, void *arg);
// contacts
WORD GetContactStatus(MCONTACT hContact);
@@ -255,21 +264,11 @@ private:
void ReloadAvatarInfo(MCONTACT hContact);
void GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t cbLen);
- void OnReceiveAvatar(const NETLIBHTTPREQUEST *response, void *arg);
- void OnSentAvatar(const NETLIBHTTPREQUEST *response);
- void OnSearch(const NETLIBHTTPREQUEST *response);
-
MCONTACT FindContact(const char *skypename);
MCONTACT AddContact(const char *skypename, bool isTemporary = false);
MCONTACT GetContactFromAuthEvent(MEVENT hEvent);
- void LoadContactsAuth(const NETLIBHTTPREQUEST *response);
- void LoadContactList(const NETLIBHTTPREQUEST *response);
-
- void OnBlockContact(const NETLIBHTTPREQUEST *response, void *p);
- void OnUnblockContact(const NETLIBHTTPREQUEST *response, void *p);
-
// messages
std::map<ULONGLONG, HANDLE> m_mpOutMessagesIds;
@@ -278,7 +277,6 @@ private:
void EditEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, time_t edit_time);
int OnSendMessage(MCONTACT hContact, int flags, const char *message);
- void OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg);
int __cdecl OnPreCreateMessage(WPARAM, LPARAM lParam);
void MarkMessagesRead(MCONTACT hContact, MEVENT hDbEvent);
@@ -287,10 +285,6 @@ private:
void ProcessContactRecv(MCONTACT hContact, time_t timestamp, const char *szContent, const char *szMessageId);
- // sync
- void OnGetServerHistory(const NETLIBHTTPREQUEST *response);
- void OnSyncHistory(const NETLIBHTTPREQUEST *response);
-
// chats
void InitGroupChatModule();
@@ -302,8 +296,6 @@ private:
INT_PTR __cdecl OnLeaveChatRoom(WPARAM hContact, LPARAM);
void StartChatRoom(const wchar_t *tid, const wchar_t *tname);
- void OnLoadChats(const NETLIBHTTPREQUEST *response);
- void OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p);
void OnChatEvent(const JSONNode &node);
void OnSendChatMessage(const char *chat_id, const wchar_t *tszMessage);
@@ -348,7 +340,6 @@ private:
MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob);
static time_t IsoToUnixTime(const char *stamp);
- static char *RemoveHtml(const char *text);
static CMStringA GetStringChunk(const char *haystack, const char *start, const char *end);
static int SkypeToMirandaStatus(const char *status);
@@ -393,6 +384,13 @@ private:
}
};
+struct AsyncHttpRequest : public MTHttpRequest<CSkypeProto>
+{
+ AsyncHttpRequest(int type, LPCSTR url = nullptr, MTHttpRequestHandler pFunc = nullptr);
+
+ void AddRegistrationToken(CSkypeProto *ppro);
+};
+
struct CMPlugin : public ACCPROTOPLUGIN<CSkypeProto>
{
CMPlugin();
diff --git a/protocols/SkypeWeb/src/skype_request.cpp b/protocols/SkypeWeb/src/skype_request.cpp
deleted file mode 100644
index d4b00ed6d0..0000000000
--- a/protocols/SkypeWeb/src/skype_request.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
-Copyright (c) 2015-20 Miranda NG team (https://miranda-ng.org)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#include "stdafx.h"
-
-void SkypeHttpResponse(const NETLIBHTTPREQUEST *response, void *arg)
-{
- SkypeResponseDelegateBase *delegate = (SkypeResponseDelegateBase*)arg;
- delegate->Invoke(response);
- delete delegate;
-}
-
-void CSkypeProto::PushRequest(HttpRequest *request)
-{
- requestQueue->Push(request);
-}
-
-void CSkypeProto::PushRequest(HttpRequest *request, SkypeResponseCallback response)
-{
- SkypeResponseDelegateBase *delegate = new SkypeResponseDelegate(this, response);
- requestQueue->Push(request, SkypeHttpResponse, delegate);
-}
-
-void CSkypeProto::PushRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg)
-{
- SkypeResponseDelegateBase *delegate = new SkypeResponseDelegateWithArg(this, response, arg);
- requestQueue->Push(request, SkypeHttpResponse, delegate);
-}
-
-void CSkypeProto::SendRequest(HttpRequest *request)
-{
- requestQueue->Send(request, nullptr, nullptr);
-}
-
-void CSkypeProto::SendRequest(HttpRequest *request, SkypeResponseCallback response)
-{
- SkypeResponseDelegateBase *delegate = new SkypeResponseDelegate(this, response);
- requestQueue->Send(request, SkypeHttpResponse, delegate);
-}
-
-void CSkypeProto::SendRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg)
-{
- SkypeResponseDelegateBase *delegate = new SkypeResponseDelegateWithArg(this, response, arg);
- requestQueue->Send(request, SkypeHttpResponse, delegate);
-}
diff --git a/protocols/SkypeWeb/src/skype_search.cpp b/protocols/SkypeWeb/src/skype_search.cpp
index 2a738a6317..b361845bbc 100644
--- a/protocols/SkypeWeb/src/skype_search.cpp
+++ b/protocols/SkypeWeb/src/skype_search.cpp
@@ -17,23 +17,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-HANDLE CSkypeProto::SearchBasic(const wchar_t* id)
+HANDLE CSkypeProto::SearchBasic(const wchar_t *id)
{
ForkThread(&CSkypeProto::SearchBasicThread, (void *)id);
return (HANDLE)1;
}
-void CSkypeProto::SearchBasicThread(void* id)
+void CSkypeProto::SearchBasicThread(void *id)
{
debugLogA("CSkypeProto::OnSearchBasicThread");
if (IsOnline())
- SendRequest(new GetSearchRequest(mir_urlEncode(T2Utf((wchar_t*)id)), this), &CSkypeProto::OnSearch);
+ SendRequest(new GetSearchRequest(mir_urlEncode(T2Utf((wchar_t *)id)), this));
}
-void CSkypeProto::OnSearch(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnSearch(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
debugLogA(__FUNCTION__);
-
+
JsonReply reply(response);
if (reply.error()) {
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
@@ -50,8 +50,8 @@ void CSkypeProto::OnSearch(const NETLIBHTTPREQUEST *response)
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_UTF8;
- psr.id.a = const_cast<char*>(skypeId.c_str());
- psr.nick.a = const_cast<char*>(name.c_str());
+ psr.id.a = const_cast<char *>(skypeId.c_str());
+ psr.nick.a = const_cast<char *>(name.c_str());
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
}
diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp
index 79a4f12cf3..550ff54f2b 100644
--- a/protocols/SkypeWeb/src/skype_trouter.cpp
+++ b/protocols/SkypeWeb/src/skype_trouter.cpp
@@ -22,13 +22,13 @@ void CSkypeProto::ProcessTimer()
if (!IsOnline())
return;
- PushRequest(new GetContactListRequest(this, nullptr), &CSkypeProto::LoadContactList);
+ PushRequest(new GetContactListRequest(this, nullptr));
SendPresence(false);
RefreshStatuses();
}
-void CSkypeProto::OnReceiveStatus(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnReceiveStatus(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -61,20 +61,20 @@ void CSkypeProto::RefreshStatuses(void)
nRecs = 0;
}
- pReq->Url << CHAR_VALUE("cMri", "8:" + id);
+ pReq << CHAR_PARAM("cMri", "8:" + id);
nRecs++;
if (nRecs >= 10) {
- PushRequest(pReq, &CSkypeProto::OnReceiveStatus);
+ PushRequest(pReq);
pReq = nullptr;
}
}
if (pReq)
- PushRequest(pReq, &CSkypeProto::OnReceiveStatus);
+ PushRequest(pReq);
}
-void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnCreateTrouter(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error()) {
@@ -99,10 +99,10 @@ LBL_Error:
TRouter.socketIo = socketio.as_string();
TRouter.url = url.as_string();
- SendRequest(new CreateTrouterPoliciesRequest(this, TRouter.connId.c_str()), &CSkypeProto::OnTrouterPoliciesCreated);
+ SendRequest(new CreateTrouterPoliciesRequest(this, TRouter.connId.c_str()));
}
-void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnTrouterPoliciesCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error()) {
@@ -122,18 +122,10 @@ LBL_Error:
TRouter.st = st.as_string();
TRouter.se = se.as_string();
TRouter.sig = sig.as_string();
-
- SendRequest(new GetTrouterRequest(
- TRouter.socketIo,
- TRouter.connId,
- TRouter.st,
- TRouter.se,
- TRouter.sig,
- TRouter.instance,
- TRouter.ccid), &CSkypeProto::OnGetTrouter);
+ SendRequest(new GetTrouterRequest(TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid));
}
-void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response)
+void CSkypeProto::OnGetTrouter(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
if (response == nullptr || response->pData == nullptr) {
debugLogA("Failed to establish a TRouter connection.");
@@ -154,17 +146,9 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response)
}
}
-void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST*)
+void CSkypeProto::OnHealth(NETLIBHTTPREQUEST *, AsyncHttpRequest *)
{
- SendRequest(new GetTrouterRequest(
- TRouter.socketIo,
- TRouter.connId,
- TRouter.st,
- TRouter.se,
- TRouter.sig,
- TRouter.instance,
- TRouter.ccid),
- &CSkypeProto::OnGetTrouter);
+ SendRequest(new GetTrouterRequest(TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid));
}
void CSkypeProto::TRouterThread(void*)
@@ -182,7 +166,7 @@ void CSkypeProto::TRouterThread(void*)
while (errors < POLLING_ERRORS_LIMIT && m_iStatus > ID_STATUS_OFFLINE) {
request->nlc = m_TrouterConnection;
- NLHR_PTR response(request->Send(m_hNetlibUser));
+ NLHR_PTR response(DoSend(request));
if (response == NULL) {
m_TrouterConnection = nullptr;
@@ -207,7 +191,7 @@ void CSkypeProto::TRouterThread(void*)
else {
errors++;
- SendRequest(new HealthTrouterRequest(TRouter.ccid.c_str()), &CSkypeProto::OnHealth);
+ SendRequest(new HealthTrouterRequest(TRouter.ccid.c_str()));
m_hTrouterHealthEvent.Wait();
}
m_TrouterConnection = response->nlc;
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp
index cb27f1bab3..f99f8bf8ac 100644
--- a/protocols/SkypeWeb/src/skype_utils.cpp
+++ b/protocols/SkypeWeb/src/skype_utils.cpp
@@ -342,10 +342,9 @@ const HtmlEntity htmlEntities[] =
{ "zwnj", "\xE2\x80\x8C" }
};
-char *CSkypeProto::RemoveHtml(const char *text)
+std::string RemoveHtml(const std::string &data)
{
- std::string new_string = "";
- std::string data = text;
+ std::string new_string;
for (std::string::size_type i = 0; i < data.length(); i++) {
if (data.at(i) == '<') {
@@ -424,10 +423,10 @@ char *CSkypeProto::RemoveHtml(const char *text)
new_string += data.at(i);
}
- return mir_strdup(new_string.c_str());
+ return new_string;
}
-const char *CSkypeProto::MirandaToSkypeStatus(int status)
+const char* CSkypeProto::MirandaToSkypeStatus(int status)
{
switch (status) {
case ID_STATUS_AWAY:
@@ -558,16 +557,16 @@ INT_PTR CSkypeProto::ParseSkypeUriService(WPARAM, LPARAM lParam)
CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, NULL);
return 0;
}
-
+
if (!mir_wstrcmpi(szCommand, L"call")) {
MCONTACT hContact = AddContact(_T2A(szJid), true);
NotifyEventHooks(g_hCallEvent, (WPARAM)hContact, (LPARAM)0);
return 0;
}
-
- if (!mir_wstrcmpi(szCommand, L"userinfo"))
+
+ if (!mir_wstrcmpi(szCommand, L"userinfo"))
return 0;
-
+
if (!mir_wstrcmpi(szCommand, L"add")) {
MCONTACT hContact = FindContact(_T2A(szJid));
if (hContact == NULL) {
@@ -604,7 +603,53 @@ INT_PTR CSkypeProto::GlobalParseSkypeUriService(WPARAM wParam, LPARAM lParam)
/////////////////////////////////////////////////////////////////////////////////////////
-JsonReply::JsonReply(const NETLIBHTTPREQUEST *pReply)
+AsyncHttpRequest::AsyncHttpRequest(int type, LPCSTR url, MTHttpRequestHandler pFunc)
+{
+ if (url)
+ m_szUrl = url;
+ m_pFunc = pFunc;
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_DUMPASTEXT;
+ requestType = type;
+}
+
+void AsyncHttpRequest::AddRegistrationToken(CSkypeProto *ppro)
+{
+ AddHeader("RegistrationToken", CMStringA(FORMAT, "registrationToken=%s", ppro->m_szToken.get()));
+}
+
+NETLIBHTTPREQUEST* CSkypeProto::DoSend(AsyncHttpRequest *pReq)
+{
+ if (pReq->m_szUrl[0] == '/') {
+ pReq->m_szUrl.Insert(0, "/v1"); // current API version
+ pReq->m_szUrl.Insert(0, m_szServer);
+ }
+
+ if (pReq->m_szUrl.Find("://") == -1)
+ pReq->m_szUrl.Insert(0, ((pReq->flags & NLHRF_SSL) ? "https://" : "http://"));
+
+ if (!pReq->m_szParam.IsEmpty()) {
+ switch (pReq->requestType) {
+ case REQUEST_GET:
+ case REQUEST_DELETE:
+ pReq->m_szUrl.AppendChar('?');
+ pReq->m_szUrl.Append(pReq->m_szParam.c_str());
+ break;
+
+ default:
+ pReq->pData = pReq->m_szParam.Detach();
+ pReq->dataLength = (int)mir_strlen(pReq->pData);
+ }
+ }
+
+ pReq->szUrl = pReq->m_szUrl.GetBuffer();
+ debugLogA("Send request to %s", pReq->szUrl);
+
+ return Netlib_HttpTransaction(m_hNetlibUser, pReq);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+JsonReply::JsonReply(NETLIBHTTPREQUEST *pReply)
{
if (pReply == nullptr) {
m_errorCode = 500;
diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h
index 1340caf599..a79b17b1e5 100644
--- a/protocols/SkypeWeb/src/skype_utils.h
+++ b/protocols/SkypeWeb/src/skype_utils.h
@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _UTILS_H_
#define _UTILS_H_
+std::string RemoveHtml(const std::string &src);
+
class EventHandle
{
HANDLE _hEvent;
@@ -49,7 +51,7 @@ class JsonReply
int m_errorCode = 0;
public:
- JsonReply(const NETLIBHTTPREQUEST *response);
+ JsonReply(NETLIBHTTPREQUEST *response);
~JsonReply();
__forceinline JSONNode &data() const { return *m_root; }
diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h
index ebaff8d4bb..961e9824cc 100644
--- a/protocols/SkypeWeb/src/stdafx.h
+++ b/protocols/SkypeWeb/src/stdafx.h
@@ -61,8 +61,6 @@ struct CSkypeProto;
extern char g_szMirVer[];
extern HANDLE g_hCallEvent;
-#define SKYPE_ENDPOINTS_HOST "client-s.gateway.messenger.live.com"
-
struct TRInfo
{
std::string socketIo,
@@ -92,7 +90,6 @@ struct MessageId
#include "skype_trouter.h"
#include "skype_utils.h"
#include "skype_db.h"
-#include "http_request.h"
#include "skype_proto.h"
#include "requests/avatars.h"
@@ -104,7 +101,6 @@ struct MessageId
#include "requests/history.h"
#include "requests/login.h"
#include "requests/messages.h"
-#include "requests/mslogin.h"
#include "requests/oauth.h"
#include "requests/poll.h"
#include "requests/profile.h"
@@ -112,62 +108,6 @@ struct MessageId
#include "requests/status.h"
#include "requests/subscriptions.h"
#include "requests/trouter.h"
-#include "request_queue.h"
-
-void SkypeHttpResponse(const NETLIBHTTPREQUEST *response, void *arg);
-
-class SkypeResponseDelegateBase
-{
-protected:
- CSkypeProto *proto;
-public:
- SkypeResponseDelegateBase(CSkypeProto *ppro) : proto(ppro) {}
- virtual void Invoke(const NETLIBHTTPREQUEST *) = 0;
- virtual ~SkypeResponseDelegateBase(){};
-};
-
-class SkypeResponseDelegate : public SkypeResponseDelegateBase
-{
- SkypeResponseCallback pfnResponseCallback;
-public:
- SkypeResponseDelegate(CSkypeProto *ppro, SkypeResponseCallback callback) : SkypeResponseDelegateBase(ppro), pfnResponseCallback(callback) {}
-
- virtual void Invoke(const NETLIBHTTPREQUEST *response) override
- {
- (proto->*(pfnResponseCallback))(response);
- }
-};
-
-class SkypeResponseDelegateWithArg : public SkypeResponseDelegateBase
-{
- SkypeResponseWithArgCallback pfnResponseCallback;
- void *arg;
-public:
- SkypeResponseDelegateWithArg(CSkypeProto *ppro, SkypeResponseWithArgCallback callback, void *p) :
- SkypeResponseDelegateBase(ppro),
- pfnResponseCallback(callback),
- arg(p)
- {}
-
- virtual void Invoke(const NETLIBHTTPREQUEST *response) override
- {
- (proto->*(pfnResponseCallback))(response, arg);
- }
-};
-
-template <typename F>
-class SkypeResponseDelegateLambda : public SkypeResponseDelegateBase
-{
- F lCallback;
-public:
- SkypeResponseDelegateLambda(CSkypeProto *ppro, F &callback) : SkypeResponseDelegateBase(ppro), lCallback(callback) {}
-
- virtual void Invoke(const NETLIBHTTPREQUEST *response) override
- {
- lCallback(response);
- }
-};
-
#define MODULE "Skype"
diff --git a/protocols/SkypeWeb/src/version.h b/protocols/SkypeWeb/src/version.h
index c2fb3727df..18bb6ad8b9 100644
--- a/protocols/SkypeWeb/src/version.h
+++ b/protocols/SkypeWeb/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 12
-#define __RELEASE_NUM 3
-#define __BUILD_NUM 7
+#define __MINOR_VERSION 95
+#define __RELEASE_NUM 12
+#define __BUILD_NUM 1
#include <stdver.h>