diff options
author | George Hazan <george.hazan@gmail.com> | 2024-01-05 15:54:03 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-01-05 15:54:03 +0300 |
commit | 14c4e44a0a91e1ad701d4ae3c58185d25118e64e (patch) | |
tree | 50f36035466f355c74373e757bc00b6610ce6267 /protocols/SkypeWeb | |
parent | 94667140aeb3886d22e4c1301423fe99aaf3fba4 (diff) |
Netlib:
- NETLIBHTTPHEADER & NETLIBHTTPREQUEST obsoleted;
- NETLIBHTTPREQUEST divided into MHttpRequest & MHttpResponse;
- MHttpHeaders now manager headers both for MHttpRequest & MHttpResponse;
Diffstat (limited to 'protocols/SkypeWeb')
-rw-r--r-- | protocols/SkypeWeb/src/request_queue.cpp | 13 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/avatars.h | 12 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/files.h | 12 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_avatars.cpp | 12 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_chatrooms.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_contacts.cpp | 8 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_files.cpp | 8 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_history_sync.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_login.cpp | 30 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 6 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_oauth.cpp | 38 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_polling.cpp | 8 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_profile.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 56 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_search.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_trouter.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.h | 2 |
19 files changed, 104 insertions, 121 deletions
diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp index d6240e7cee..9dd5ecd71e 100644 --- a/protocols/SkypeWeb/src/request_queue.cpp +++ b/protocols/SkypeWeb/src/request_queue.cpp @@ -73,7 +73,7 @@ void CSkypeProto::PushRequest(AsyncHttpRequest *request) /////////////////////////////////////////////////////////////////////////////////////////
-NETLIBHTTPREQUEST* CSkypeProto::DoSend(AsyncHttpRequest *pReq)
+MHttpResponse* CSkypeProto::DoSend(AsyncHttpRequest *pReq)
{
if (pReq->m_host != HOST_OTHER)
pReq->m_szUrl.Insert(0, ((pReq->flags & NLHRF_SSL) ? "https://" : "http://"));
@@ -88,17 +88,12 @@ NETLIBHTTPREQUEST* CSkypeProto::DoSend(AsyncHttpRequest *pReq) case REQUEST_PUT:
case REQUEST_POST:
- if (Netlib_GetHeader(pReq, "Content-Type") == nullptr) {
+ if (!pReq->FindHeader("Content-Type")) {
if (pReq->m_szParam[0] == '[' || pReq->m_szParam[0] == '{')
pReq->AddHeader("Content-Type", "application/json; charset=UTF-8");
else
pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
}
- __fallthrough;
-
- default:
- pReq->pData = pReq->m_szParam.Detach();
- pReq->dataLength = (int)mir_strlen(pReq->pData);
}
}
@@ -126,8 +121,8 @@ NETLIBHTTPREQUEST* CSkypeProto::DoSend(AsyncHttpRequest *pReq) break;
}
- pReq->szUrl = pReq->m_szUrl.GetBuffer();
- debugLogA("Send request to %s", pReq->szUrl);
+ pReq->m_szUrl = pReq->m_szUrl.GetBuffer();
+ debugLogA("Send request to %s", pReq->m_szUrl.c_str());
return Netlib_HttpTransaction(m_hNetlibUser, pReq);
}
diff --git a/protocols/SkypeWeb/src/requests/avatars.h b/protocols/SkypeWeb/src/requests/avatars.h index cdf5ac7b6e..aeffbf8ab0 100644 --- a/protocols/SkypeWeb/src/requests/avatars.h +++ b/protocols/SkypeWeb/src/requests/avatars.h @@ -30,21 +30,15 @@ struct GetAvatarRequest : public AsyncHttpRequest struct SetAvatarRequest : public AsyncHttpRequest
{
- SetAvatarRequest(const uint8_t *data, size_t dataSize, const char *szMime, CSkypeProto *ppro) :
+ SetAvatarRequest(const uint8_t *data, int dataSize, const char *szMime, CSkypeProto *ppro) :
AsyncHttpRequest(REQUEST_PUT, HOST_API, 0, &CSkypeProto::OnSentAvatar)
{
m_szUrl.AppendFormat("/users/%s/profile/avatar", ppro->m_szSkypename.MakeLower().c_str());
AddHeader("Content-Type", szMime);
- pData = (char *)mir_alloc(dataSize);
- memcpy(pData, data, dataSize);
- dataLength = (int)dataSize;
- }
-
- ~SetAvatarRequest()
- {
- mir_free(pData);
+ m_szParam.Truncate(dataSize);
+ memcpy(m_szParam.GetBuffer(), data, dataSize);
}
};
diff --git a/protocols/SkypeWeb/src/requests/files.h b/protocols/SkypeWeb/src/requests/files.h index 72c47b4788..d47b3637f3 100644 --- a/protocols/SkypeWeb/src/requests/files.h +++ b/protocols/SkypeWeb/src/requests/files.h @@ -28,7 +28,7 @@ struct ASMObjectCreateRequest : public AsyncHttpRequest struct ASMObjectUploadRequest : public AsyncHttpRequest { - ASMObjectUploadRequest(CSkypeProto *ppro, const char *szObject, const uint8_t *data, const size_t size, CFileUploadParam *fup) : + ASMObjectUploadRequest(CSkypeProto *ppro, const char *szObject, const uint8_t *data, int size, CFileUploadParam *fup) : AsyncHttpRequest(REQUEST_PUT, HOST_OTHER, 0, &CSkypeProto::OnASMObjectUploaded) { m_szUrl.AppendFormat("https://api.asm.skype.com/v1/objects/%s/content/original", szObject); @@ -37,13 +37,7 @@ struct ASMObjectUploadRequest : public AsyncHttpRequest 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); + m_szParam.Truncate(size); + memcpy(m_szParam.GetBuffer(), data, size); } }; diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index 94d097c852..50c1207803 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -52,9 +52,9 @@ void CSkypeProto::ReloadAvatarInfo(MCONTACT hContact) SvcGetAvatarInfo(0, (LPARAM)&ai);
}
-void CSkypeProto::OnReceiveAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::OnReceiveAvatar(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
- if (response == nullptr || response->pData == nullptr)
+ if (response == nullptr || response->body.IsEmpty())
return;
MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
@@ -62,7 +62,7 @@ void CSkypeProto::OnReceiveAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest return;
PROTO_AVATAR_INFORMATION ai = { 0 };
- ai.format = ProtoGetBufferFormat(response->pData);
+ ai.format = ProtoGetBufferFormat(response->body);
setByte(hContact, "AvatarType", ai.format);
GetAvatarFileName(hContact, ai.filename, _countof(ai.filename));
@@ -72,13 +72,13 @@ void CSkypeProto::OnReceiveAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest return;
}
- fwrite(response->pData, 1, response->dataLength, out);
+ fwrite(response->body, 1, response->body.GetLength(), out);
fclose(out);
setByte(hContact, "NeedNewAvatar", 0);
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai, 0);
}
-void CSkypeProto::OnSentAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnSentAvatar(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply root(response);
if (root.error())
@@ -175,7 +175,7 @@ INT_PTR CSkypeProto::SvcSetMyAvatar(WPARAM, LPARAM lParam) if (data != NULL && fread(data, sizeof(uint8_t), length, hFile) == length) {
const char *szMime = FreeImage_GetFIFMimeType(FreeImage_GetFIFFromFilenameU(path));
- PushRequest(new SetAvatarRequest(data, length, szMime, this));
+ PushRequest(new SetAvatarRequest(data, (int)length, szMime, this));
fclose(hFile);
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index 2d1fc6c3b8..243257353e 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -51,7 +51,7 @@ SESSION_INFO* CSkypeProto::StartChatRoom(const wchar_t *tid, const wchar_t *tnam return si;
}
-void CSkypeProto::OnLoadChats(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnLoadChats(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -380,7 +380,7 @@ void CSkypeProto::AddMessageToChat(SESSION_INFO *si, const wchar_t *from, const Chat_Event(&gce);
}
-void CSkypeProto::OnGetChatInfo(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnGetChatInfo(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index c249c6e281..f5f83e6fa9 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -100,7 +100,7 @@ MCONTACT CSkypeProto::AddContact(const char *skypeId, const char *nick, bool isT return hContact;
}
-void CSkypeProto::LoadContactsAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::LoadContactsAuth(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -142,7 +142,7 @@ void CSkypeProto::LoadContactsAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest //[{"skypeId":"echo123", "authorized" : true, "blocked" : false, ...},...]
// other properties is exists but empty
-void CSkypeProto::LoadContactList(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::LoadContactList(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
@@ -255,7 +255,7 @@ INT_PTR CSkypeProto::BlockContact(WPARAM hContact, LPARAM) return 0;
}
-void CSkypeProto::OnBlockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::OnBlockContact(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
if (response != nullptr)
@@ -268,7 +268,7 @@ INT_PTR CSkypeProto::UnblockContact(WPARAM hContact, LPARAM) return 0;
}
-void CSkypeProto::OnUnblockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::OnUnblockContact(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
if (response == nullptr)
return;
diff --git a/protocols/SkypeWeb/src/skype_files.cpp b/protocols/SkypeWeb/src/skype_files.cpp index 358a337e90..9eaef8b665 100644 --- a/protocols/SkypeWeb/src/skype_files.cpp +++ b/protocols/SkypeWeb/src/skype_files.cpp @@ -28,10 +28,10 @@ void CSkypeProto::SendFileThread(void *p) PushRequest(new ASMObjectCreateRequest(this, fup));
}
-void CSkypeProto::OnASMObjectCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::OnASMObjectCreated(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
auto *fup = (CFileUploadParam*)pRequest->pUserInfo;
- if (response == nullptr || response->pData == nullptr) {
+ if (response == nullptr || response->body.IsEmpty()) {
LBL_Error:
FILETRANSFER_FAILED(fup);
return;
@@ -42,7 +42,7 @@ LBL_Error: goto LBL_Error;
}
- JSONNode node = JSONNode::parse((char*)response->pData);
+ JSONNode node = JSONNode::parse(response->body);
std::string strObjectId = node["id"].as_string();
if (strObjectId.empty()) {
debugLogA("Invalid server response (empty object id)");
@@ -74,7 +74,7 @@ LBL_Error: fclose(pFile);
}
-void CSkypeProto::OnASMObjectUploaded(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::OnASMObjectUploaded(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
auto *fup = (CFileUploadParam*)pRequest->pUserInfo;
if (response == nullptr) {
diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index b10897b0d3..7497d8f7a1 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(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
JsonReply reply(response);
if (reply.error())
@@ -140,7 +140,7 @@ INT_PTR CSkypeProto::GetContactHistory(WPARAM hContact, LPARAM) return 0;
}
-void CSkypeProto::OnSyncHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnSyncHistory(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 76977ab6cd..f9f2ecab57 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -66,18 +66,18 @@ void CSkypeProto::Login() PushRequest(new OAuthRequest());
}
-void CSkypeProto::OnLoginOAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnLoginOAuth(MHttpResponse *response, AsyncHttpRequest*)
{
if (!IsStatusConnecting(m_iStatus))
return;
- if (response == nullptr || response->pData == nullptr) {
+ if (response == nullptr || response->body.IsEmpty()) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
}
- JSONNode json = JSONNode::parse(response->pData);
+ JSONNode json = JSONNode::parse(response->body);
if (!json) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
@@ -148,7 +148,7 @@ void CSkypeProto::OnLoginSuccess() PushRequest(new CreateEndpointRequest(this));
}
-void CSkypeProto::OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnEndpointCreated(MHttpResponse *response, AsyncHttpRequest*)
{
if (IsStatusConnecting(m_iStatus))
m_iStatus++;
@@ -167,7 +167,7 @@ void CSkypeProto::OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpReques case 301:
case 302: // redirect to the closest data center
- if (auto *hdr = Netlib_GetHeader(response, "Location")) {
+ if (auto *hdr = response->FindHeader("Location")) {
CMStringA szUrl(hdr+8);
int iEnd = szUrl.Find('/');
g_plugin.szDefaultServer = (iEnd != -1) ? szUrl.Left(iEnd) : szUrl;
@@ -176,7 +176,7 @@ void CSkypeProto::OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpReques return;
case 401: // unauthorized
- if (auto *szStatus = Netlib_GetHeader(response, "StatusText"))
+ if (auto *szStatus = response->FindHeader("StatusText"))
if (strstr(szStatus, "SkypeTokenExpired"))
delSetting("TokenSecret");
delSetting("TokenExpiresIn");
@@ -191,7 +191,7 @@ void CSkypeProto::OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpReques }
// Succeeded, decode the answer
- if (auto *hdr = Netlib_GetHeader(response, "Set-RegistrationToken")) {
+ if (auto *hdr = response->FindHeader("Set-RegistrationToken")) {
CMStringA szValue = hdr;
int iStart = 0;
while (true) {
@@ -215,13 +215,13 @@ void CSkypeProto::OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpReques PushRequest(new CreateSubscriptionsRequest());
}
-void CSkypeProto::OnEndpointDeleted(NETLIBHTTPREQUEST *, AsyncHttpRequest *)
+void CSkypeProto::OnEndpointDeleted(MHttpResponse *, AsyncHttpRequest *)
{
m_szId = nullptr;
m_szToken = nullptr;
}
-void CSkypeProto::OnSubscriptionsCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnSubscriptionsCreated(MHttpResponse *response, AsyncHttpRequest*)
{
if (response == nullptr) {
debugLogA(__FUNCTION__ ": failed to create subscription");
@@ -249,9 +249,9 @@ void CSkypeProto::SendPresence() PushRequest(new SendCapabilitiesRequest(epname, this));
}
-void CSkypeProto::OnCapabilitiesSended(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest*)
{
- if (response == nullptr || response->pData == nullptr) {
+ if (response == nullptr || response->body.IsEmpty()) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
@@ -277,23 +277,23 @@ void CSkypeProto::OnCapabilitiesSended(NETLIBHTTPREQUEST *response, AsyncHttpReq if (bAutoHistorySync)
PushRequest(new SyncHistoryFirstRequest(100));
- JSONNode root = JSONNode::parse(response->pData);
+ JSONNode root = JSONNode::parse(response->body);
if (root)
setString("SelfEndpointName", UrlToSkypeId(root["selfLink"].as_string().c_str()));
PushRequest(new GetProfileRequest(this, 0));
}
-void CSkypeProto::OnStatusChanged(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnStatusChanged(MHttpResponse *response, AsyncHttpRequest*)
{
- if (response == nullptr || response->pData == nullptr) {
+ if (response == nullptr || response->body.IsEmpty()) {
debugLogA(__FUNCTION__ ": failed to change status");
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
}
- JSONNode json = JSONNode::parse(response->pData);
+ JSONNode json = JSONNode::parse(response->body);
if (!json) {
debugLogA(__FUNCTION__ ": failed to change status");
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 16d9b2cb03..6504224c21 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -45,7 +45,7 @@ int CSkypeProto::SendMsg(MCONTACT hContact, MEVENT, const char *szMessage) return param->hMessage;
}
-void CSkypeProto::OnMessageSent(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::OnMessageSent(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
auto *param = (SendMessageParam*)pRequest->pUserInfo;
MCONTACT hContact = param->hContact;
@@ -56,8 +56,8 @@ void CSkypeProto::OnMessageSent(NETLIBHTTPREQUEST *response, AsyncHttpRequest *p if (response->resultCode != 201) {
std::string strError = Translate("Unknown error!");
- if (response->pData != nullptr) {
- JSONNode jRoot = JSONNode::parse(response->pData);
+ if (!response->body.IsEmpty()) {
+ JSONNode jRoot = JSONNode::parse(response->body);
const JSONNode &jErr = jRoot["errorCode"];
if (jErr)
strError = jErr.as_string();
diff --git a/protocols/SkypeWeb/src/skype_oauth.cpp b/protocols/SkypeWeb/src/skype_oauth.cpp index 0a1f8908d3..d767496efa 100644 --- a/protocols/SkypeWeb/src/skype_oauth.cpp +++ b/protocols/SkypeWeb/src/skype_oauth.cpp @@ -28,9 +28,9 @@ static std::string sub(const std::string &str, const char *start, const char *en return (i2 == -1) ? "" : str.substr(i1, i2 - i1);
}
-void CSkypeProto::OnOAuthStart(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnOAuthStart(MHttpResponse *response, AsyncHttpRequest*)
{
- if (response == nullptr || response->pData == nullptr) {
+ if (response == nullptr || response->body.IsEmpty()) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
@@ -38,7 +38,7 @@ void CSkypeProto::OnOAuthStart(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) std::regex regex;
std::smatch match;
- std::string content = response->pData;
+ std::string content = response->body.c_str();
regex = "<input.+?type=\"hidden\".+?name=\"PPFT\".+?id=\"i0327\".+?value=\"(.+?)\".*?/>";
@@ -52,11 +52,11 @@ void CSkypeProto::OnOAuthStart(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) std::map<std::string, std::string> scookies;
regex = "^(.+?)=(.*?);";
- for (int i = 0; i < response->headersCount; i++) {
- if (mir_strcmpi(response->headers[i].szName, "Set-Cookie"))
+ for (auto &it : *response) {
+ if (mir_strcmpi(it->szName, "Set-Cookie"))
continue;
- content = response->headers[i].szValue;
+ content = it->szValue;
if (std::regex_search(content, match, regex))
scookies[match[1]] = match[2];
}
@@ -83,18 +83,18 @@ bool CSkypeProto::CheckOauth(const char *szResponse) return true;
}
-void CSkypeProto::OnOAuthConfirm(NETLIBHTTPREQUEST *response, AsyncHttpRequest *)
+void CSkypeProto::OnOAuthConfirm(MHttpResponse *response, AsyncHttpRequest *)
{
- if (response == nullptr || response->pData == nullptr) {
+ if (response == nullptr || response->body.IsEmpty()) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
}
- if (CheckOauth(response->pData))
+ if (CheckOauth(response->body))
return;
- std::string content = response->pData;
+ std::string content = response->body.c_str();
std::string PPFT = sub(content, "sFT:'", "'");
std::string opid = sub(content, "opid=", "&");
if (PPFT.empty() || opid.empty()) {
@@ -107,11 +107,11 @@ void CSkypeProto::OnOAuthConfirm(NETLIBHTTPREQUEST *response, AsyncHttpRequest * std::smatch match;
CMStringA mscookies;
- for (int i = 0; i < response->headersCount; i++) {
- if (mir_strcmpi(response->headers[i].szName, "Set-Cookie"))
+ for (auto &it : *response) {
+ if (mir_strcmpi(it->szName, "Set-Cookie"))
continue;
- content = response->headers[i].szValue;
+ content = it->szValue;
if (std::regex_search(content, match, regex))
mscookies.Append(match[1].str().c_str());
}
@@ -119,23 +119,23 @@ void CSkypeProto::OnOAuthConfirm(NETLIBHTTPREQUEST *response, AsyncHttpRequest * PushRequest(new OAuthRequest(mscookies.c_str(), PPFT.c_str(), opid.c_str()));
}
-void CSkypeProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnOAuthAuthorize(MHttpResponse *response, AsyncHttpRequest*)
{
- if (response == nullptr || response->pData == nullptr) {
+ if (response == nullptr || response->body.IsEmpty()) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
}
- if (!CheckOauth(response->pData)) {
+ if (!CheckOauth(response->body)) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
}
}
-void CSkypeProto::OnOAuthEnd(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnOAuthEnd(MHttpResponse *response, AsyncHttpRequest*)
{
- if (response == nullptr || response->pData == nullptr) {
+ if (response == nullptr || response->body.IsEmpty()) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
@@ -143,7 +143,7 @@ void CSkypeProto::OnOAuthEnd(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) std::regex regex;
std::smatch match;
- std::string content = response->pData;
+ std::string content = response->body;
regex = "<input.+?type=\"hidden\".+?name=\"skypetoken\".+?value=\"(.+?)\".*?/>";
if (!std::regex_search(content, match, regex)) {
diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index 0000de3b20..b850cffb23 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -39,14 +39,14 @@ void CSkypeProto::PollingThread(void *) if (response->resultCode == 200) {
nErrors = 0;
- if (response->pData)
- ParsePollData(response->pData);
+ if (!response->body.IsEmpty())
+ ParsePollData(response->body);
}
else {
nErrors++;
- if (response->pData) {
- JSONNode root = JSONNode::parse(response->pData);
+ if (!response->body.IsEmpty()) {
+ JSONNode root = JSONNode::parse(response->body);
const JSONNode &error = root["errorCode"];
if (error && error.as_int() == 729)
break;
diff --git a/protocols/SkypeWeb/src/skype_profile.cpp b/protocols/SkypeWeb/src/skype_profile.cpp index f8fbaa2fbe..16fda7b0c8 100644 --- a/protocols/SkypeWeb/src/skype_profile.cpp +++ b/protocols/SkypeWeb/src/skype_profile.cpp @@ -397,7 +397,7 @@ 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(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::LoadProfile(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 59ad914aaa..536744f36f 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -125,7 +125,7 @@ int CSkypeProto::SetAwayMsg(int, const wchar_t *msg) /////////////////////////////////////////////////////////////////////////////////////////
-void CSkypeProto::OnReceiveAwayMsg(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
+void CSkypeProto::OnReceiveAwayMsg(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
JsonReply reply(response);
if (reply.error())
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 5686aad69c..113e22b228 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -120,48 +120,48 @@ public: return getMStringA(hContact, SKYPE_SETTINGS_ID);
}
- void OnReceiveAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnSentAvatar(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnSearch(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnReceiveAvatar(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnSentAvatar(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnSearch(MHttpResponse *response, AsyncHttpRequest *pRequest);
// login
- void OnLoginOAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnSubscriptionsCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnCapabilitiesSended(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnReceiveStatus(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnStatusChanged(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnLoginOAuth(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnSubscriptionsCreated(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnReceiveStatus(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnStatusChanged(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnEndpointDeleted(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnEndpointCreated(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnEndpointDeleted(MHttpResponse *response, AsyncHttpRequest *pRequest);
// oauth
- void OnOAuthStart(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnOAuthConfirm(NETLIBHTTPREQUEST* response, AsyncHttpRequest* pRequest);
- void OnOAuthAuthorize(NETLIBHTTPREQUEST* response, AsyncHttpRequest* pRequest);
- void OnOAuthEnd(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnOAuthStart(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnOAuthConfirm(MHttpResponse* response, AsyncHttpRequest* pRequest);
+ void OnOAuthAuthorize(MHttpResponse* response, AsyncHttpRequest* pRequest);
+ void OnOAuthEnd(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void OnASMObjectCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnASMObjectUploaded(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnASMObjectCreated(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnASMObjectUploaded(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void LoadContactsAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void LoadContactList(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void LoadContactsAuth(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void LoadContactList(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void OnBlockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnUnblockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnBlockContact(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnUnblockContact(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void OnMessageSent(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnMessageSent(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnSyncHistory(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnSyncHistory(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void OnLoadChats(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnGetChatInfo(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
- void OnReceiveAwayMsg(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void OnLoadChats(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnGetChatInfo(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnReceiveAwayMsg(MHttpResponse *response, AsyncHttpRequest *pRequest);
void CheckConvert(void);
bool CheckOauth(const char *szResponse);
- void LoadProfile(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest);
+ void LoadProfile(MHttpResponse *response, AsyncHttpRequest *pRequest);
static INT_PTR __cdecl GlobalParseSkypeUriService(WPARAM, LPARAM lParam);
@@ -206,7 +206,7 @@ private: void StartQueue();
void StopQueue();
- NETLIBHTTPREQUEST* DoSend(AsyncHttpRequest *request);
+ MHttpResponse* DoSend(AsyncHttpRequest *request);
void Execute(AsyncHttpRequest *request);
void PushRequest(AsyncHttpRequest *request);
diff --git a/protocols/SkypeWeb/src/skype_search.cpp b/protocols/SkypeWeb/src/skype_search.cpp index 51a4952021..8dc34dc62c 100644 --- a/protocols/SkypeWeb/src/skype_search.cpp +++ b/protocols/SkypeWeb/src/skype_search.cpp @@ -30,7 +30,7 @@ void CSkypeProto::SearchBasicThread(void *id) PushRequest(new GetSearchRequest(T2Utf((wchar_t *)id)));
}
-void CSkypeProto::OnSearch(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnSearch(MHttpResponse *response, AsyncHttpRequest*)
{
debugLogA(__FUNCTION__);
diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index 65e38d4d41..567e449da1 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -26,7 +26,7 @@ void CSkypeProto::ProcessTimer() SendPresence();
}
-void CSkypeProto::OnReceiveStatus(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
+void CSkypeProto::OnReceiveStatus(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index acd02c6892..e2a751568c 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -653,7 +653,7 @@ INT_PTR CSkypeProto::GlobalParseSkypeUriService(WPARAM wParam, LPARAM lParam) /////////////////////////////////////////////////////////////////////////////////////////
-JsonReply::JsonReply(NETLIBHTTPREQUEST *pReply)
+JsonReply::JsonReply(MHttpResponse *pReply)
{
if (pReply == nullptr) {
m_errorCode = 500;
@@ -664,7 +664,7 @@ JsonReply::JsonReply(NETLIBHTTPREQUEST *pReply) if (m_errorCode != 200)
return;
- m_root = json_parse(pReply->pData);
+ m_root = json_parse(pReply->body);
if (m_root == nullptr) {
m_errorCode = 500;
return;
diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h index e8a1f05836..4162a8ec35 100644 --- a/protocols/SkypeWeb/src/skype_utils.h +++ b/protocols/SkypeWeb/src/skype_utils.h @@ -59,7 +59,7 @@ class JsonReply int m_errorCode = 0;
public:
- JsonReply(NETLIBHTTPREQUEST *response);
+ JsonReply(MHttpResponse *response);
~JsonReply();
__forceinline JSONNode &data() const { return *m_root; }
|