summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-12-30 20:25:07 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-12-30 20:25:07 +0300
commit69a81a736bfbb2a215a6c56ad83977d5753b2c6d (patch)
tree4be65a73a127037c1c2f02371d7e752fff5d3871 /protocols
parentf6e89cd758c1df231b478c4f530af6216f991858 (diff)
ICQ10:
- fixes #1699 (after password change Miranda cannot login to ICQ until restart); - code cleaning
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Icq10/src/http.cpp2
-rw-r--r--protocols/Icq10/src/main.cpp2
-rw-r--r--protocols/Icq10/src/options.cpp12
-rw-r--r--protocols/Icq10/src/proto.cpp10
-rw-r--r--protocols/Icq10/src/server.cpp24
-rw-r--r--protocols/Icq10/src/stdafx.h6
-rw-r--r--protocols/Icq10/src/utils.cpp4
7 files changed, 39 insertions, 21 deletions
diff --git a/protocols/Icq10/src/http.cpp b/protocols/Icq10/src/http.cpp
index 0d66a3ae71..5590ddc596 100644
--- a/protocols/Icq10/src/http.cpp
+++ b/protocols/Icq10/src/http.cpp
@@ -141,7 +141,7 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq)
if (r.error() == 40201) { // robust token expired
CMStringA oldToken = m_szRToken;
m_szRToken.Empty();
- delSetting("RToken");
+ delSetting(DB_KEY_RTOKEN);
// if token refresh succeeded, replace it in the query and push request back
if (RefreshRobustToken()) {
diff --git a/protocols/Icq10/src/main.cpp b/protocols/Icq10/src/main.cpp
index ae2c297a62..6259a91a72 100644
--- a/protocols/Icq10/src/main.cpp
+++ b/protocols/Icq10/src/main.cpp
@@ -39,7 +39,7 @@ static PLUGININFOEX pluginInfoEx = {
CMPlugin::CMPlugin() :
ACCPROTOPLUGIN<CIcqProto>(MODULENAME, pluginInfoEx)
{
- SetUniqueId("UIN");
+ SetUniqueId(DB_KEY_UIN);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Icq10/src/options.cpp b/protocols/Icq10/src/options.cpp
index e4d09dcc12..2d0445f1a8 100644
--- a/protocols/Icq10/src/options.cpp
+++ b/protocols/Icq10/src/options.cpp
@@ -24,6 +24,7 @@ class CIcqOptionsDlg : public CProtoDlgBase<CIcqProto>
{
CCtrlEdit edtUin, edtPassword;
CCtrlCheck chkSlowSend;
+ CMStringW wszOldPass;
public:
CIcqOptionsDlg(CIcqProto *ppro, int iDlgID, bool bFullDlg) :
@@ -37,6 +38,17 @@ public:
if (bFullDlg)
CreateLink(chkSlowSend, ppro->m_bSlowSend);
+
+ wszOldPass = ppro->m_szPassword;
+ }
+
+ bool OnApply() override
+ {
+ if (wszOldPass != ptrW(edtPassword.GetText())) {
+ m_proto->delSetting(DB_KEY_ATOKEN);
+ m_proto->delSetting(DB_KEY_SESSIONKEY);
+ }
+ return true;
}
};
diff --git a/protocols/Icq10/src/proto.cpp b/protocols/Icq10/src/proto.cpp
index 6509759872..6d26bfdd40 100644
--- a/protocols/Icq10/src/proto.cpp
+++ b/protocols/Icq10/src/proto.cpp
@@ -39,7 +39,7 @@ CIcqProto::CIcqProto(const char* aProtoName, const wchar_t* aUserName) :
m_arOwnIds(1),
m_arCache(20, NumericKeySortT),
m_evRequestsQueue(CreateEvent(nullptr, FALSE, FALSE, nullptr)),
- m_dwUin(this, "UIN", 0),
+ m_dwUin(this, DB_KEY_UIN, 0),
m_szPassword(this, "Password"),
m_bSlowSend(this, "SlowSend", false)
{
@@ -83,7 +83,7 @@ void CIcqProto::OnShutdown()
void CIcqProto::OnContactDeleted(MCONTACT hContact)
{
- DWORD dwUin = getDword(hContact, "UIN");
+ DWORD dwUin = getDword(hContact, DB_KEY_UIN);
m_arCache.remove(FindContactByUIN(dwUin));
auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/removeBuddy");
@@ -150,7 +150,7 @@ 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)
- << INT_PARAM("buddy", getDword(hContact, "UIN")) << CHAR_PARAM("group", "General") << INT_PARAM("preAuthorized", 1);
+ << INT_PARAM("buddy", getDword(hContact, DB_KEY_UIN)) << CHAR_PARAM("group", "General") << INT_PARAM("preAuthorized", 1);
pReq->flags |= NLHRF_NODUMPSEND;
pReq->pUserInfo = (void*)hContact;
Push(pReq);
@@ -279,7 +279,7 @@ void __cdecl CIcqProto::SendAckThread(void *p)
int CIcqProto::SendMsg(MCONTACT hContact, int, const char *pszSrc)
{
- DWORD dwUin = getDword(hContact, "UIN");
+ DWORD dwUin = getDword(hContact, DB_KEY_UIN);
if (dwUin == 0)
return 0;
@@ -379,7 +379,7 @@ 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")
- << INT_PARAM("t", getDword(hContact, "UIN")) << CHAR_PARAM("r", pReq->m_reqId)
+ << INT_PARAM("t", getDword(hContact, DB_KEY_UIN)) << CHAR_PARAM("r", pReq->m_reqId)
<< CHAR_PARAM("typingStatus", (type == PROTOTYPE_SELFTYPING_ON) ? "typing" : "typed");
Push(pReq);
return 0;
diff --git a/protocols/Icq10/src/server.cpp b/protocols/Icq10/src/server.cpp
index 4b2fea9689..05b6b6cf31 100644
--- a/protocols/Icq10/src/server.cpp
+++ b/protocols/Icq10/src/server.cpp
@@ -52,10 +52,10 @@ void CIcqProto::CheckPassword()
char mirVer[100];
Miranda_GetVersionText(mirVer, _countof(mirVer));
- m_szAToken = getMStringA("AToken");
- m_szRToken = getMStringA("RToken");
- m_iRClientId = getDword("RClientID");
- m_szSessionKey = getMStringA("SessionKey");
+ m_szAToken = getMStringA(DB_KEY_ATOKEN);
+ m_szRToken = getMStringA(DB_KEY_RTOKEN);
+ m_iRClientId = getDword(DB_KEY_RCLIENTID);
+ m_szSessionKey = getMStringA(DB_KEY_SESSIONKEY);
if (m_szAToken.IsEmpty() || m_szSessionKey.IsEmpty()) {
auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_POST, "https://api.login.icq.net/auth/clientLogin", &CIcqProto::OnCheckPassword);
pReq << CHAR_PARAM("clientName", "Miranda NG") << CHAR_PARAM("clientVersion", mirVer) << CHAR_PARAM("devId", ICQ_APP_ID)
@@ -162,7 +162,7 @@ bool CIcqProto::RefreshRobustToken()
if (result.error() == 20000) {
const JSONNode &results = result.results();
m_szRToken = results["authToken"].as_mstring();
- setString("RToken", m_szRToken);
+ setString(DB_KEY_RTOKEN, m_szRToken);
// now add this token
auto *add = new AsyncHttpRequest(CONN_RAPI, REQUEST_POST, ICQ_ROBUST_SERVER, &CIcqProto::OnAddClient);
@@ -186,7 +186,7 @@ void CIcqProto::RetrieveUserInfo(MCONTACT hContact)
auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/presence/get", &CIcqProto::OnGetUserInfo);
pReq->flags |= NLHRF_NODUMPSEND;
pReq->pUserInfo = (void*)hContact;
- pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << INT_PARAM("mdir", 1) << INT_PARAM("t", getDword(hContact, "UIN"));
+ pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << INT_PARAM("mdir", 1) << INT_PARAM("t", getDword(hContact, DB_KEY_UIN));
Push(pReq);
}
@@ -276,7 +276,7 @@ void CIcqProto::OnAddBuddy(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq)
JsonReply root(pReply);
if (root.error() == 200) {
- RetrieveUserInfo(getDword(hContact, "UIN"));
+ RetrieveUserInfo(getDword(hContact, DB_KEY_UIN));
db_unset(hContact, "CList", "NotOnList");
}
}
@@ -293,7 +293,7 @@ void CIcqProto::OnAddClient(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq)
const JSONNode &results = reply.results();
m_iRClientId = results["clientId"].as_int();
- setDword("RClientID", m_iRClientId);
+ setDword(DB_KEY_RCLIENTID, m_iRClientId);
*pRet = true;
}
@@ -317,7 +317,7 @@ void CIcqProto::OnCheckPassword(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*)
JSONNode &data = root.data();
m_szAToken = data["token"]["a"].as_mstring();
m_szAToken = ptrA(mir_urlDecode(m_szAToken));
- setString("AToken", m_szAToken);
+ setString(DB_KEY_ATOKEN, m_szAToken);
CMStringA szSessionSecret = data["sessionSecret"].as_mstring();
CMStringA szPassTemp = m_szPassword;
@@ -326,7 +326,7 @@ void CIcqProto::OnCheckPassword(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*)
BYTE hashOut[MIR_SHA256_HASH_SIZE];
HMAC(EVP_sha256(), szPassTemp, szPassTemp.GetLength(), (BYTE*)szSessionSecret.c_str(), szSessionSecret.GetLength(), hashOut, &len);
m_szSessionKey = ptrA(mir_base64_encode(hashOut, sizeof(hashOut)));
- setString("SessionKey", m_szSessionKey);
+ setString(DB_KEY_SESSIONKEY, m_szSessionKey);
CMStringA szUin = data["loginId"].as_mstring();
if (szUin)
@@ -361,8 +361,8 @@ void CIcqProto::OnStartSession(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*)
case 401:
if (root.detail() == 1002) { // session expired
- delSetting("AToken");
- delSetting("SessionKey");
+ delSetting(DB_KEY_ATOKEN);
+ delSetting(DB_KEY_SESSIONKEY);
CheckPassword();
}
else ConnectionFailed(LOGINERR_WRONGPASSWORD);
diff --git a/protocols/Icq10/src/stdafx.h b/protocols/Icq10/src/stdafx.h
index 44f75d1099..7eda1521d8 100644
--- a/protocols/Icq10/src/stdafx.h
+++ b/protocols/Icq10/src/stdafx.h
@@ -78,6 +78,12 @@
#define MODULENAME "ICQ"
+#define DB_KEY_UIN "UIN"
+#define DB_KEY_ATOKEN "AToken"
+#define DB_KEY_RTOKEN "RToken"
+#define DB_KEY_RCLIENTID "RClientID"
+#define DB_KEY_SESSIONKEY "SessionKey"
+
#include "http.h"
#include "proto.h"
diff --git a/protocols/Icq10/src/utils.cpp b/protocols/Icq10/src/utils.cpp
index 49c9ad0d03..f745387742 100644
--- a/protocols/Icq10/src/utils.cpp
+++ b/protocols/Icq10/src/utils.cpp
@@ -24,7 +24,7 @@ void CIcqProto::InitContactCache()
{
mir_cslock l(m_csCache);
for (auto &it : AccContacts())
- m_arCache.insert(new IcqCacheItem(getDword(it, "UIN"), it));
+ m_arCache.insert(new IcqCacheItem(getDword(it, DB_KEY_UIN), it));
}
IcqCacheItem* CIcqProto::FindContactByUIN(DWORD dwUin)
@@ -41,7 +41,7 @@ MCONTACT CIcqProto::CreateContact(DWORD dwUin, bool bTemporary)
MCONTACT hContact = db_add_contact();
Proto_AddToContact(hContact, m_szModuleName);
- setDword(hContact, "UIN", dwUin);
+ setDword(hContact, DB_KEY_UIN, dwUin);
pCache = new IcqCacheItem(dwUin, hContact);
{
mir_cslock l(m_csCache);