From 0fc0c03f8176b13f0596e90bb3832040cf46c9af Mon Sep 17 00:00:00 2001
From: George Hazan <ghazan@miranda.im>
Date: Fri, 26 Jun 2020 19:24:14 +0300
Subject: WM_JABBER_REGDLG_UPDATE - unused message removed

---
 protocols/JabberG/src/jabber_agent.cpp  | 58 +++++++++++++++++++++++----------
 protocols/JabberG/src/jabber_iqid.cpp   | 24 --------------
 protocols/JabberG/src/jabber_opt.cpp    | 35 ++++++++++----------
 protocols/JabberG/src/jabber_proto.cpp  |  2 +-
 protocols/JabberG/src/jabber_proto.h    | 13 +++++---
 protocols/JabberG/src/jabber_thread.cpp | 23 ++++++-------
 protocols/JabberG/src/stdafx.h          |  4 +--
 7 files changed, 82 insertions(+), 77 deletions(-)

(limited to 'protocols/JabberG')

diff --git a/protocols/JabberG/src/jabber_agent.cpp b/protocols/JabberG/src/jabber_agent.cpp
index de17dc3bab..7d7badaeec 100644
--- a/protocols/JabberG/src/jabber_agent.cpp
+++ b/protocols/JabberG/src/jabber_agent.cpp
@@ -43,7 +43,7 @@ public:
 
 	bool OnInitDialog() override
 	{
-		m_proto->m_hwndRegProgress = m_hwnd;
+		m_proto->m_pDlgReg = this;
 		SetWindowText(m_hwnd, TranslateT("Jabber Agent Registration"));
 		TranslateDialogDefault(m_hwnd);
 		return true;
@@ -51,27 +51,49 @@ public:
 
 	void OnDestroy() override
 	{
-		m_proto->m_hwndRegProgress = nullptr;
+		m_proto->m_pDlgReg = nullptr;
 	}
 
-	INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override
+	void Update(int progress, const wchar_t *pwszText)
 	{
-		if (msg == WM_JABBER_REGDLG_UPDATE) {
-			if ((wchar_t*)lParam == nullptr)
-				SetDlgItemText(m_hwnd, IDC_REG_STATUS, TranslateT("No message"));
-			else
-				SetDlgItemText(m_hwnd, IDC_REG_STATUS, (wchar_t*)lParam);
-
-			SendDlgItemMessage(m_hwnd, IDC_PROGRESS_REG, PBM_SETPOS, wParam, 0);
+		if (this == nullptr)
+			return;
 
-			if (wParam >= 100)
-				m_ok.SetText(TranslateT("OK"));
-		}
+		SetDlgItemText(m_hwnd, IDC_REG_STATUS, pwszText);
+		SendDlgItemMessage(m_hwnd, IDC_PROGRESS_REG, PBM_SETPOS, progress, 0);
 
-		return CJabberDlgBase::DlgProc(msg, wParam, lParam);
+		if (progress >= 100)
+			m_ok.SetText(TranslateT("OK"));
 	}
 };
 
+void CJabberProto::AgentShutdown()
+{
+	UI_SAFE_CLOSE(m_pDlgReg);
+}
+
+void CJabberProto::OnIqAgentRegister(const TiXmlElement *iqNode, CJabberIqInfo *)
+{
+	// RECVED: result of registration process
+	// ACTION: notify of successful agent registration
+	debugLogA("<iq/> iqIdSetRegister");
+
+	const char *type, *from;
+	if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return;
+	if ((from = XmlGetAttr(iqNode, "from")) == nullptr) return;
+
+	if (!mir_strcmp(type, "result")) {
+		MCONTACT hContact = HContactFromJID(from);
+		if (hContact != 0)
+			setByte(hContact, "IsTransport", true);
+
+		m_pDlgReg->Update(100, TranslateT("Registration successful"));
+	}
+	else if (!mir_strcmp(type, "error")) {
+		m_pDlgReg->Update(100, JabberErrorMsg(iqNode).c_str());
+	}
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////
 // Transport registration form
 
@@ -127,10 +149,9 @@ public:
 			return true;
 
 		HWND hwndFrame = GetDlgItem(m_hwnd, IDC_FRAME);
-		wchar_t *str2 = (wchar_t *)alloca(sizeof(wchar_t) * 128);
 		int id = 0;
 
-		XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultSetRegister, JABBER_IQ_TYPE_SET, from));
+		XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqAgentRegister, JABBER_IQ_TYPE_SET, from));
 		TiXmlElement *query = iq << XQUERY(JABBER_FEAT_REGISTER);
 
 		if (auto *xNode = XmlFirstChild(queryNode, "x")) {
@@ -153,8 +174,9 @@ public:
 						// do nothing, we will skip these
 					}
 					else {
-						GetDlgItemText(hwndFrame, id, str2, 128);
-						XmlAddChildA(query, pszName, T2Utf(str2).get());
+						wchar_t str[128];
+						GetDlgItemText(hwndFrame, id, str, _countof(str));
+						XmlAddChildA(query, pszName, T2Utf(str).get());
 						id++;
 					}
 				}
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp
index c6e0432206..39c695f69d 100755
--- a/protocols/JabberG/src/jabber_iqid.cpp
+++ b/protocols/JabberG/src/jabber_iqid.cpp
@@ -490,30 +490,6 @@ void CJabberProto::OnIqResultGetRegister(const TiXmlElement *iqNode, CJabberIqIn
 	}
 }
 
-void CJabberProto::OnIqResultSetRegister(const TiXmlElement *iqNode, CJabberIqInfo*)
-{
-	// RECVED: result of registration process
-	// ACTION: notify of successful agent registration
-	debugLogA("<iq/> iqIdSetRegister");
-
-	const char *type, *from;
-	if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return;
-	if ((from = XmlGetAttr(iqNode, "from")) == nullptr) return;
-
-	if (!mir_strcmp(type, "result")) {
-		MCONTACT hContact = HContactFromJID(from);
-		if (hContact != 0)
-			setByte(hContact, "IsTransport", true);
-
-		if (m_hwndRegProgress)
-			SendMessage(m_hwndRegProgress, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Registration successful"));
-	}
-	else if (!mir_strcmp(type, "error")) {
-		if (m_hwndRegProgress)
-			SendMessage(m_hwndRegProgress, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)JabberErrorMsg(iqNode).c_str());
-	}
-}
-
 /////////////////////////////////////////////////////////////////////////////////////////
 // JabberIqResultGetVcard - processes the server-side v-card
 
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp
index 4a273b5168..15cba2df5b 100755
--- a/protocols/JabberG/src/jabber_opt.cpp
+++ b/protocols/JabberG/src/jabber_opt.cpp
@@ -257,7 +257,7 @@ public:
 
 		ShowWindow(GetDlgItem(m_hwnd, IDC_PROGRESS_REG), SW_SHOW);
 
-		m_regInfo->reg_hwndDlg = m_hwnd;
+		m_regInfo->pDlg = this;
 		m_proto->ForkThread((CJabberProto::MyThreadFunc) & CJabberProto::ServerThread, m_regInfo);
 
 		m_btnOk.SetText(TranslateT("Cancel"));
@@ -265,28 +265,29 @@ public:
 		return false;
 	}
 
-	INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override
+	void OnDestroy() override
 	{
-		switch (msg) {
-		case WM_JABBER_REGDLG_UPDATE:	// wParam=progress (0-100), lparam=status string
-			if ((wchar_t*)lParam == nullptr)
-				SetDlgItemTextW(m_hwnd, IDC_REG_STATUS, TranslateT("No message"));
-			else
-				SetDlgItemTextW(m_hwnd, IDC_REG_STATUS, (wchar_t*)lParam);
-
-			SendDlgItemMessage(m_hwnd, IDC_PROGRESS_REG, PBM_SETPOS, wParam, 0);
-			if (wParam >= 100)
-				m_btnOk.SetText(TranslateT("Close"));
-			else
-				SetFocus(GetDlgItem(m_hwnd, IDC_PROGRESS_REG));
+		m_regInfo->pDlg = nullptr;
+	}
 
-			return TRUE;
-		}
+	void Update(int progress, const wchar_t *pwszText)
+	{
+		SetDlgItemTextW(m_hwnd, IDC_REG_STATUS, pwszText);
+		SendDlgItemMessageW(m_hwnd, IDC_PROGRESS_REG, PBM_SETPOS, progress, 0);
 
-		return CSuper::DlgProc(msg, wParam, lParam);
+		if (progress >= 100)
+			m_btnOk.SetText(TranslateT("Close"));
+		else
+			SetFocus(GetDlgItem(m_hwnd, IDC_PROGRESS_REG));
 	}
 };
 
+void JABBER_CONN_DATA::SetProgress(int progress, const wchar_t *pwszText)
+{
+	if (pDlg)
+		pDlg->Update(progress, pwszText);
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////
 // JabberOptDlgProc - main options dialog procedure
 
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index ad3626164f..b249df7ed9 100755
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -332,7 +332,6 @@ void CJabberProto::OnShutdown()
 	m_bShutdown = true;
 
 	UI_SAFE_CLOSE_HWND(m_hwndAgentRegInput);
-	UI_SAFE_CLOSE_HWND(m_hwndRegProgress);
 	UI_SAFE_CLOSE_HWND(m_hwndJabberChangePassword);
 	UI_SAFE_CLOSE_HWND(m_hwndJabberAddBookmark);
 	UI_SAFE_CLOSE_HWND(m_hwndPrivacyRule);
@@ -343,6 +342,7 @@ void CJabberProto::OnShutdown()
 	UI_SAFE_CLOSE(m_pDlgJabberJoinGroupchat);
 	UI_SAFE_CLOSE(m_pDlgNotes);
 
+	AgentShutdown();
 	MucShutdown();
 
 	m_iqManager.ExpireAll();
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index 8539ec23f6..bd0c06d54e 100755
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -252,7 +252,6 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
 	bool   m_bMamPrefsAvailable;
 
 	HWND   m_hwndAgentRegInput;
-	HWND   m_hwndRegProgress;
 	HWND   m_hwndJabberChangePassword;
 	HWND   m_hwndPrivacyRule;
 	HWND   m_hwndJabberAddBookmark;
@@ -360,13 +359,20 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
 
 	void       ContactMenuAdhocCommands(struct CJabberAdhocStartupParams *param);
 
+	//---- jabber_agent.c ----------------------------------------------------------------
+
+	class      CAgentRegProgressDlg *m_pDlgReg;
+
+	void       AgentShutdown();
+	void       OnIqAgentRegister(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
+
 	//---- jabber_archive.c --------------------------------------------------------------
 
 	void       EnableArchive(bool bEnable);
 	void       RetrieveMessageArchive(MCONTACT hContact, JABBER_LIST_ITEM *pItem);
 			    
-	void       OnIqResultGetCollection(const TiXmlElement *iqNode, CJabberIqInfo*);
-	void       OnIqResultGetCollectionList(const TiXmlElement *iqNode, CJabberIqInfo*);
+	void       OnIqResultGetCollection(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
+	void       OnIqResultGetCollectionList(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
 
 	//---- jabber_bookmarks.c ------------------------------------------------------------
 
@@ -550,7 +556,6 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
 	void       OnIqResultSetAuth(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
 	void       OnIqResultSetBookmarks(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
 	void       OnIqResultSetPassword(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
-	void       OnIqResultSetRegister(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
 	void       OnIqResultSetSearch(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
 	void       OnIqResultSetVcard(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
 	void       OnProcessLoginRq(ThreadData *info, DWORD rq);
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index da88826cee..586e670548 100755
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -328,7 +328,7 @@ LBL_FatalError:
 		// Multiple thread allowed, although not possible :)
 		// thinking again.. multiple thread should not be allowed
 		info.reg_done = false;
-		SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 25, (LPARAM)TranslateT("Connecting..."));
+		info.conn.SetProgress(25, TranslateT("Connecting..."));
 		iqIdRegGetReg = -1;
 		iqIdRegSetReg = -1;
 	}
@@ -337,7 +337,7 @@ LBL_FatalError:
 	if ((info.buffer = (char*)mir_alloc(jabberNetworkBufferSize + 1)) == nullptr) {	// +1 is for '\0' when debug logging this buffer
 		debugLogA("Cannot allocate network buffer, thread ended");
 		if (info.bIsReg)
-			SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Not enough memory"));
+			info.conn.SetProgress(100, TranslateT("Error: Not enough memory"));
 		else
 			ProtoBroadcastAck(0, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK);
 
@@ -361,7 +361,7 @@ LBL_FatalError:
 			if (m_ThreadInfo == &info)
 				ProtoBroadcastAck(0, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK);
 		}
-		else SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Cannot connect to the server"));
+		else info.conn.SetProgress(100, TranslateT("Error: Cannot connect to the server"));
 
 		debugLogA("Thread ended, connection failed");
 		goto LBL_FatalError;
@@ -375,7 +375,7 @@ LBL_FatalError:
 			if (!info.bIsReg)
 				ProtoBroadcastAck(0, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK);
 			else
-				SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Cannot connect to the server"));
+				info.conn.SetProgress(100, TranslateT("Error: Cannot connect to the server"));
 
 			info.close();
 			debugLogA("Thread ended, SSL connection failed");
@@ -533,7 +533,7 @@ recvRest:
 		}
 		else {
 			if (!info.reg_done)
-				SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Connection lost"));
+				info.conn.SetProgress(100, TranslateT("Error: Connection lost"));
 			g_pRegInfo = nullptr;
 		}
 	}
@@ -554,7 +554,7 @@ void CJabberProto::PerformRegistration(ThreadData *info)
 	iqIdRegGetReg = SerialNext();
 	info->send(XmlNodeIq("get", iqIdRegGetReg, nullptr) << XQUERY(JABBER_FEAT_REGISTER));
 
-	SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 50, (LPARAM)TranslateT("Requesting registration instruction..."));
+	info->conn.SetProgress(50, TranslateT("Requesting registration instruction..."));
 }
 
 void CJabberProto::PerformIqAuth(ThreadData *info)
@@ -1878,7 +1878,7 @@ void CJabberProto::OnProcessIq(const TiXmlElement *node)
 void CJabberProto::CancelRegConfig(CJabberFormDlg*, void*)
 {
 	if (g_pRegInfo)
-		SendMessage(g_pRegInfo->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Registration canceled"));
+		g_pRegInfo->conn.SetProgress(100, TranslateT("Registration canceled"));
 }
 
 void CJabberProto::SetRegConfig(CJabberFormDlg *pDlg, void *from)
@@ -1916,7 +1916,8 @@ void CJabberProto::OnProcessRegIq(const TiXmlElement *node, ThreadData *info)
 						g_pRegInfo = info;
 
 						auto *pDlg = new CJabberFormDlg(this, xNode, "Jabber register new user", &CJabberProto::SetRegConfig, mir_strdup(XmlGetAttr(node, "from")));
-						pDlg->SetParent(info->conn.reg_hwndDlg);
+						if (info->conn.pDlg)
+							pDlg->SetParent(((CDlgBase*)info->conn.pDlg)->GetHwnd());
 						pDlg->SetCancel(&CJabberProto::CancelRegConfig);
 						pDlg->Display();
 						return;
@@ -1936,18 +1937,18 @@ void CJabberProto::OnProcessRegIq(const TiXmlElement *node, ThreadData *info)
 			query << XCHILD("username", info->conn.username);
 			info->send(iq);
 
-			SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 75, (LPARAM)TranslateT("Sending registration information..."));
+			info->conn.SetProgress(75, TranslateT("Sending registration information..."));
 		}
 		// RECVED: result of the registration process
 		// ACTION: account registration successful
 		else if (id == iqIdRegSetReg) {
 			info->send("</stream:stream>");
-			SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Registration successful"));
+			info->conn.SetProgress(100, TranslateT("Registration successful"));
 			info->reg_done = true;
 		}
 	}
 	else if (!mir_strcmp(type, "error")) {
-		SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)JabberErrorMsg(node).c_str());
+		info->conn.SetProgress(100, JabberErrorMsg(node));
 		info->reg_done = true;
 		info->send("</stream:stream>");
 	}
diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h
index 37c1d863c4..f5f73f96ae 100755
--- a/protocols/JabberG/src/stdafx.h
+++ b/protocols/JabberG/src/stdafx.h
@@ -179,7 +179,6 @@ protected:
 #define JABBER_DB_EVENT_PRESENCE_ERROR           5
 
 // User-defined message
-#define WM_JABBER_REGDLG_UPDATE        (WM_PROTO_LAST + 100)
 #define WM_JABBER_AGENT_REFRESH        (WM_PROTO_LAST + 101)
 #define WM_JABBER_TRANSPORT_REFRESH    (WM_PROTO_LAST + 102)
 #define WM_JABBER_REGINPUT_ACTIVATE    (WM_PROTO_LAST + 103)
@@ -342,7 +341,8 @@ struct JABBER_CONN_DATA : public MZeroedObject
 	int  port;
 	BOOL useSSL;
 
-	HWND reg_hwndDlg;
+	class CJabberDlgRegister *pDlg;
+	void  SetProgress(int progress, const wchar_t *pwszText);
 };
 
 struct ThreadData
-- 
cgit v1.2.3