summaryrefslogtreecommitdiff
path: root/protocols/ICQ-WIM
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-01 19:29:26 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-01 19:29:26 +0300
commit128341ef85a0f9daef7dce3653adf1011f3e6e06 (patch)
tree479b9ab1af161a2e8289f31eb5e874a6c35ddcdc /protocols/ICQ-WIM
parent70b77d0c25f8138e30d78d3af7966711cff3b375 (diff)
ICQ-WIM: code cleaning & optimization
Diffstat (limited to 'protocols/ICQ-WIM')
-rw-r--r--protocols/ICQ-WIM/src/groupchats.cpp11
-rw-r--r--protocols/ICQ-WIM/src/http.cpp9
-rw-r--r--protocols/ICQ-WIM/src/ignore.cpp14
-rw-r--r--protocols/ICQ-WIM/src/poll.cpp2
-rw-r--r--protocols/ICQ-WIM/src/proto.cpp27
-rw-r--r--protocols/ICQ-WIM/src/proto.h11
-rw-r--r--protocols/ICQ-WIM/src/server.cpp26
7 files changed, 48 insertions, 52 deletions
diff --git a/protocols/ICQ-WIM/src/groupchats.cpp b/protocols/ICQ-WIM/src/groupchats.cpp
index 5f5854b6b6..84a293684c 100644
--- a/protocols/ICQ-WIM/src/groupchats.cpp
+++ b/protocols/ICQ-WIM/src/groupchats.cpp
@@ -151,9 +151,8 @@ public:
}
}
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/mchat/AddChat");
- pReq << CHAR_PARAM("f", "json") << WCHAR_PARAM("chat_id", m_si->ptszID) << CHAR_PARAM("aimsid", m_proto->m_aimsid) << CHAR_PARAM("r", pReq->m_reqId) << WCHAR_PARAM("members", szMembers);
- m_proto->Push(pReq);
+ m_proto->Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/mchat/AddChat")
+ << AIMSID(m_proto) << WCHAR_PARAM("chat_id", m_si->ptszID) << WCHAR_PARAM("members", szMembers));
return true;
}
};
@@ -168,10 +167,8 @@ void CIcqProto::InviteUserToChat(SESSION_INFO *si)
void CIcqProto::LeaveDestroyChat(SESSION_INFO *si)
{
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/hideChat");
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << WCHAR_PARAM("buddy", si->ptszID)
- << CHAR_PARAM("r", pReq->m_reqId) << INT64_PARAM("lastMsgId", getId(si->hContact, DB_KEY_LASTMSGID));
- Push(pReq);
+ Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/hideChat")
+ << AIMSID(this) << WCHAR_PARAM("buddy", si->ptszID) << INT64_PARAM("lastMsgId", getId(si->hContact, DB_KEY_LASTMSGID)));
Chat_Terminate(si->pszModule, si->ptszID, true);
}
diff --git a/protocols/ICQ-WIM/src/http.cpp b/protocols/ICQ-WIM/src/http.cpp
index e31cc46fe8..47929fbc69 100644
--- a/protocols/ICQ-WIM/src/http.cpp
+++ b/protocols/ICQ-WIM/src/http.cpp
@@ -234,6 +234,15 @@ void CIcqProto::Push(MHttpRequest *p)
/////////////////////////////////////////////////////////////////////////////////////////
+AsyncHttpRequest* operator<<(AsyncHttpRequest *pReq, const AIMSID &param)
+{
+ pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", param.m_ppro->m_aimsid) << CHAR_PARAM("r", pReq->m_reqId);
+ pReq->flags |= NLHRF_NODUMPSEND;
+ return pReq;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
JsonReply::JsonReply(NETLIBHTTPREQUEST *pReply)
{
if (pReply == nullptr) {
diff --git a/protocols/ICQ-WIM/src/ignore.cpp b/protocols/ICQ-WIM/src/ignore.cpp
index 435cd5b417..63bcc48d72 100644
--- a/protocols/ICQ-WIM/src/ignore.cpp
+++ b/protocols/ICQ-WIM/src/ignore.cpp
@@ -52,9 +52,8 @@ public:
m_list.InsertColumn(0, &lvc);
auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/preference/getPermitDeny", &CIcqProto::OnRefreshEditIgnore);
- pReq->flags |= NLHRF_NODUMPHEADERS;
+ pReq << AIMSID(m_proto);
pReq->pUserInfo = this;
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_proto->m_aimsid) << CHAR_PARAM("r", pReq->m_reqId);
m_proto->ExecuteRequest(pReq);
Utils_RestoreWindowPosition(m_hwnd, 0, m_proto->m_szModuleName, "editIgnore_");
@@ -166,10 +165,7 @@ INT_PTR CIcqProto::EditIgnoreList(WPARAM, LPARAM)
void CIcqProto::GetPermitDeny()
{
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/preference/getPermitDeny", &CIcqProto::OnGetPermitDeny);
- pReq->flags |= NLHRF_NODUMPHEADERS;
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId);
- Push(pReq);
+ Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/preference/getPermitDeny", &CIcqProto::OnGetPermitDeny) << AIMSID(this));
}
void CIcqProto::OnGetPermitDeny(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*)
@@ -209,8 +205,6 @@ void CIcqProto::ProcessPermissions(const JSONNode &ev)
void CIcqProto::SetPermitDeny(const CMStringW &userId, bool bAllow)
{
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/preference/setPermitDeny");
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId)
- << WCHAR_PARAM((bAllow) ? "pdIgnoreRemove" : "pdIgnore", userId);
- Push(pReq);
+ Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/preference/setPermitDeny")
+ << AIMSID(this) << WCHAR_PARAM((bAllow) ? "pdIgnoreRemove" : "pdIgnore", userId));
}
diff --git a/protocols/ICQ-WIM/src/poll.cpp b/protocols/ICQ-WIM/src/poll.cpp
index 6cd4575e13..db994cd0cf 100644
--- a/protocols/ICQ-WIM/src/poll.cpp
+++ b/protocols/ICQ-WIM/src/poll.cpp
@@ -281,7 +281,7 @@ void __cdecl CIcqProto::PollThread(void*)
debugLogA("Polling thread started");
m_bFirstBos = true;
- while (m_bOnline) {
+ while (m_bOnline && !m_fetchBaseURL.IsEmpty()) {
CMStringA szUrl = m_fetchBaseURL;
if (m_bFirstBos)
szUrl.Append("&first=1");
diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp
index 8b6fe3b126..1d01af5dc4 100644
--- a/protocols/ICQ-WIM/src/proto.cpp
+++ b/protocols/ICQ-WIM/src/proto.cpp
@@ -139,11 +139,8 @@ void CIcqProto::OnContactDeleted(MCONTACT hContact)
if (!isChatRoom(hContact))
m_arCache.remove(FindContactByUIN(szId));
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/removeBuddy");
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << WCHAR_PARAM("buddy", szId)
- << CHAR_PARAM("r", pReq->m_reqId) << INT_PARAM("allGroups", 1);
- pReq->flags |= NLHRF_NODUMPSEND;
- Push(pReq);
+ Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/removeBuddy")
+ << AIMSID(this) << WCHAR_PARAM("buddy", szId) << INT_PARAM("allGroups", 1));
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -269,8 +266,7 @@ int CIcqProto::OnGroupChange(WPARAM hContact, LPARAM lParam)
CLISTGROUPCHANGE *pParam = (CLISTGROUPCHANGE*)lParam;
if (hContact == 0) { // whole group is changed
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/");
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId);
+ auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/") << AIMSID(this);
if (pParam->pszOldName == nullptr) {
pReq->m_szUrl += "addGroup";
pReq << WCHAR_PARAM("group", pParam->pszNewName);
@@ -315,9 +311,7 @@ MCONTACT CIcqProto::AddToList(int, PROTOSEARCHRESULT *psr)
int CIcqProto::AuthRequest(MCONTACT hContact, const wchar_t* szMessage)
{
auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_POST, ICQ_API_SERVER "/buddylist/addBuddy", &CIcqProto::OnAddBuddy);
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId) << WCHAR_PARAM("authorizationMsg", szMessage)
- << WCHAR_PARAM("buddy", GetUserId(hContact)) << CHAR_PARAM("group", "General") << INT_PARAM("preAuthorized", 1);
- pReq->flags |= NLHRF_NODUMPSEND;
+ pReq << AIMSID(this) << WCHAR_PARAM("authorizationMsg", szMessage) << WCHAR_PARAM("buddy", GetUserId(hContact)) << CHAR_PARAM("group", "General") << INT_PARAM("preAuthorized", 1);
pReq->hContact = hContact;
Push(pReq);
return 0;
@@ -436,9 +430,8 @@ int CIcqProto::SendMsg(MCONTACT hContact, int, const char *pszSrc)
m_arOwnIds.insert(pOwn);
}
- pReq << CHAR_PARAM("a", m_szAToken) << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("f", "json") << CHAR_PARAM("k", ICQ_APP_ID)
- << CHAR_PARAM("mentions", "") << CHAR_PARAM("message", pszSrc) << CHAR_PARAM("offlineIM", "true") << CHAR_PARAM("r", pReq->m_reqId)
- << CHAR_PARAM("t", szUserid) << INT_PARAM("ts", time(0));
+ pReq << AIMSID(this) << CHAR_PARAM("a", m_szAToken) << CHAR_PARAM("k", ICQ_APP_ID) << CHAR_PARAM("mentions", "")
+ << CHAR_PARAM("message", pszSrc) << CHAR_PARAM("offlineIM", "true") << CHAR_PARAM("t", szUserid) << INT_PARAM("ts", time(0));
Push(pReq);
return id;
}
@@ -523,12 +516,8 @@ int CIcqProto::SetAwayMsg(int, const wchar_t*)
int CIcqProto::UserIsTyping(MCONTACT hContact, int type)
{
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/im/setTyping");
- pReq->flags |= NLHRF_NODUMPSEND;
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("f", "json")
- << WCHAR_PARAM("t", GetUserId(hContact)) << CHAR_PARAM("r", pReq->m_reqId)
- << CHAR_PARAM("typingStatus", (type == PROTOTYPE_SELFTYPING_ON) ? "typing" : "typed");
- Push(pReq);
+ Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/im/setTyping")
+ << AIMSID(this) << WCHAR_PARAM("t", GetUserId(hContact)) << CHAR_PARAM("typingStatus", (type == PROTOTYPE_SELFTYPING_ON) ? "typing" : "typed"));
return 0;
}
diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h
index 8dfa81a8cc..4dd0801e7b 100644
--- a/protocols/ICQ-WIM/src/proto.h
+++ b/protocols/ICQ-WIM/src/proto.h
@@ -53,6 +53,15 @@
typedef CProtoDlgBase<CIcqProto> CIcqDlgBase;
+struct AIMSID
+{
+ AIMSID(CIcqProto *_ppro) :
+ m_ppro(_ppro)
+ {}
+
+ CIcqProto *m_ppro;
+};
+
enum ChatMenuItems
{
IDM_INVITE = 10, IDM_LEAVE
@@ -148,6 +157,8 @@ class CIcqProto : public PROTO<CIcqProto>
friend class CGroupchatInviteDlg;
friend class CEditIgnoreListDlg;
+ friend AsyncHttpRequest* operator <<(AsyncHttpRequest*, const AIMSID&);
+
bool m_bOnline, m_bTerminated, m_bFirstBos;
MCONTACT CheckOwnMessage(const CMStringA &reqId, const CMStringA &msgId, bool bRemove);
void CheckPassword(void);
diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp
index a960bb1d95..ce82808092 100644
--- a/protocols/ICQ-WIM/src/server.cpp
+++ b/protocols/ICQ-WIM/src/server.cpp
@@ -155,10 +155,8 @@ void CIcqProto::ConnectionFailed(int iReason, int iErrorCode)
void CIcqProto::MoveContactToGroup(MCONTACT hContact, const wchar_t *pwszGroup, const wchar_t *pwszNewGroup)
{
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/moveBuddy");
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId)
- << WCHAR_PARAM("buddy", GetUserId(hContact)) << WCHAR_PARAM("group", pwszGroup) << WCHAR_PARAM("newGroup", pwszNewGroup);
- Push(pReq);
+ Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/moveBuddy")
+ << AIMSID(this) << WCHAR_PARAM("buddy", GetUserId(hContact)) << WCHAR_PARAM("group", pwszGroup) << WCHAR_PARAM("newGroup", pwszNewGroup));
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -459,9 +457,8 @@ void CIcqProto::RetrieveUserInfo(MCONTACT hContact)
AsyncHttpRequest* CIcqProto::UserInfoRequest(MCONTACT hContact)
{
auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/presence/get", &CIcqProto::OnGetUserInfo);
- pReq->flags |= NLHRF_NODUMPSEND;
pReq->hContact = hContact;
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << INT_PARAM("mdir", 1) << INT_PARAM("capabilities", 1);
+ pReq << AIMSID(this) << INT_PARAM("mdir", 1) << INT_PARAM("capabilities", 1);
return pReq;
}
@@ -496,7 +493,7 @@ void CIcqProto::SetServerStatus(int iStatus)
int invisible = 0;
switch (iStatus) {
- case ID_STATUS_OFFLINE: szStatus = "offline"; break;
+ case ID_STATUS_OFFLINE: szStatus = "offline"; break;
case ID_STATUS_NA: szStatus = "occupied"; break;
case ID_STATUS_AWAY:
case ID_STATUS_DND: szStatus = "away"; break;
@@ -504,11 +501,11 @@ void CIcqProto::SetServerStatus(int iStatus)
invisible = 1;
}
- auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/presence/setState");
- pReq->flags |= NLHRF_NODUMPSEND;
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId)
- << CHAR_PARAM("view", szStatus) << INT_PARAM("invisible", invisible);
- Push(pReq);
+ Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/presence/setState")
+ << AIMSID(this) << CHAR_PARAM("view", szStatus) << INT_PARAM("invisible", invisible));
+
+ if (iStatus == ID_STATUS_OFFLINE)
+ Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/aim/endSession") << AIMSID(this));
int iOldStatus = m_iStatus; m_iStatus = iStatus;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus);
@@ -683,9 +680,8 @@ void CIcqProto::OnFileContinue(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pOld
m_arOwnIds.insert(pOwn);
}
- pReq << CHAR_PARAM("a", m_szAToken) << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("f", "json") << CHAR_PARAM("k", ICQ_APP_ID)
- << CHAR_PARAM("mentions", "") << WCHAR_PARAM("message", wszUrl) << CHAR_PARAM("offlineIM", "true") << WCHAR_PARAM("parts", wszParts)
- << CHAR_PARAM("r", pReq->m_reqId) << WCHAR_PARAM("t", GetUserId(pTransfer->pfts.hContact)) << INT_PARAM("ts", time(0));
+ pReq << AIMSID(this) << CHAR_PARAM("a", m_szAToken) << CHAR_PARAM("k", ICQ_APP_ID) << CHAR_PARAM("mentions", "") << WCHAR_PARAM("message", wszUrl)
+ << CHAR_PARAM("offlineIM", "true") << WCHAR_PARAM("parts", wszParts) << WCHAR_PARAM("t", GetUserId(pTransfer->pfts.hContact)) << INT_PARAM("ts", time(0));
Push(pReq);
}
else ProtoBroadcastAck(pTransfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, pTransfer);