From 6895d635acb37ba42e53ba95ca3eee2ddbbef24d Mon Sep 17 00:00:00 2001
From: Tobias Weimer <wishmaster51@googlemail.com>
Date: Fri, 28 Nov 2014 21:19:14 +0000
Subject: Massive code cleanup and fixes for a lot of warnings reported in #837

git-svn-id: http://svn.miranda-ng.org/main/trunk@11136 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 protocols/JabberG/src/jabber_iqid_muc.cpp | 171 ++++++++++++++++--------------
 protocols/JabberG/src/jabber_opt.cpp      |   3 +-
 2 files changed, 95 insertions(+), 79 deletions(-)

(limited to 'protocols/JabberG')

diff --git a/protocols/JabberG/src/jabber_iqid_muc.cpp b/protocols/JabberG/src/jabber_iqid_muc.cpp
index 1e941ee9dc..91187d0715 100644
--- a/protocols/JabberG/src/jabber_iqid_muc.cpp
+++ b/protocols/JabberG/src/jabber_iqid_muc.cpp
@@ -37,22 +37,25 @@ void CJabberProto::SetMucConfig(HXML node, void *from)
 	}
 }
 
+// RECVED: room config form
+// ACTION: show the form
 void CJabberProto::OnIqResultGetMuc(HXML iqNode, CJabberIqInfo *pInfo)
 {
-	HXML queryNode, xNode;
-	const TCHAR *type, *from, *str;
-
-	// RECVED: room config form
-	// ACTION: show the form
 	debugLogA("<iq/> iqIdGetMuc");
-	if ((type = xmlGetAttrValue(iqNode, _T("type"))) == NULL) return;
-	if ((from = xmlGetAttrValue(iqNode, _T("from"))) == NULL) return;
+	LPCTSTR type = xmlGetAttrValue(iqNode, _T("type"));
+	if (type == NULL)
+		return;
+	LPCTSTR from = xmlGetAttrValue(iqNode, _T("from"));
+	if (from == NULL)
+		return;
 
 	if (!_tcscmp(type, _T("result"))) {
-		if ((queryNode = xmlGetChild(iqNode , "query")) != NULL) {
-			str = xmlGetAttrValue(queryNode, _T("xmlns"));
+		HXML queryNode = xmlGetChild(iqNode , _T("query"));
+		if (queryNode != NULL) {
+			LPCTSTR str = xmlGetAttrValue(queryNode, _T("xmlns"));
 			if (!lstrcmp(str, JABBER_FEAT_MUC_OWNER)) {
-				if ((xNode = xmlGetChild(queryNode , "x")) != NULL) {
+				HXML xNode = xmlGetChild(queryNode , _T("x"));
+				if (xNode != NULL) {
 					str = xmlGetAttrValue(xNode, _T("xmlns"));
 					if (!lstrcmp(str, JABBER_FEAT_DATA_FORMS))
 						//LaunchForm(xNode);
@@ -65,13 +68,6 @@ void CJabberProto::OnIqResultGetMuc(HXML iqNode, CJabberIqInfo *pInfo)
 
 static void sttFillJidList(HWND hwndDlg)
 {
-	JABBER_MUC_JIDLIST_INFO *jidListInfo;
-	HXML iqNode, queryNode;
-	const TCHAR *from, *jid, *reason, *nick;
-	LVITEM lvi;
-	HWND hwndList;
-	int count, i;
-
 	TCHAR *filter = NULL;
 	if (GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_FILTER), GWLP_USERDATA))
 	{
@@ -80,17 +76,18 @@ static void sttFillJidList(HWND hwndDlg)
 		GetDlgItemText(hwndDlg, IDC_FILTER, filter, filterLength);
 	}
 
-	jidListInfo = (JABBER_MUC_JIDLIST_INFO *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+	JABBER_MUC_JIDLIST_INFO *jidListInfo = (JABBER_MUC_JIDLIST_INFO *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
 	if (!jidListInfo)
 		return;
 
-	hwndList = GetDlgItem(hwndDlg, IDC_LIST);
+	HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST);
 	SendMessage(hwndList, WM_SETREDRAW, FALSE, 0);
 
-	count = ListView_GetItemCount(hwndList);
+	int count = ListView_GetItemCount(hwndList);
+	LVITEM lvi;
 	lvi.mask = LVIF_PARAM;
 	lvi.iSubItem = 0;
-	for (i=0; i<count; i++) {
+	for (int i=0; i<count; i++) {
 		lvi.iItem = i;
 		if (ListView_GetItem(hwndList, &lvi) == TRUE) {
 			if (lvi.lParam!=(LPARAM)(-1) && lvi.lParam!=(LPARAM)(NULL)) {
@@ -101,32 +98,38 @@ static void sttFillJidList(HWND hwndDlg)
 	ListView_DeleteAllItems(hwndList);
 
 	// Populate displayed list from iqNode
-	if ((iqNode = jidListInfo->iqNode) != NULL) {
-		if ((from = xmlGetAttrValue(iqNode, _T("from"))) != NULL) {
-			if ((queryNode = xmlGetChild(iqNode , "query")) != NULL) {
+	TCHAR tszItemText[ JABBER_MAX_JID_LEN + 256 ];
+	HXML iqNode = jidListInfo->iqNode;
+	if (iqNode != NULL) {
+		LPCTSTR from = xmlGetAttrValue(iqNode, _T("from"));
+		if (from != NULL) {
+			HXML queryNode = xmlGetChild(iqNode , _T("query"));
+			if (queryNode != NULL) {
 				lvi.mask = LVIF_TEXT | LVIF_PARAM;
 				lvi.iSubItem = 0;
 				lvi.iItem = 0;
-				for (i=0; ; i++) {
+				for (int i=0; ; i++) {
 					HXML itemNode = xmlGetChild(queryNode ,i);
 					if (!itemNode)
 						break;
 
-					if ((jid = xmlGetAttrValue(itemNode, _T("jid"))) != NULL) {
+					LPCTSTR jid = xmlGetAttrValue(itemNode, _T("jid"));
+					if (jid != NULL) {
 						lvi.pszText = (TCHAR*)jid;
 						if (jidListInfo->type == MUC_BANLIST) {
-							if ((reason = xmlGetText(xmlGetChild(itemNode , "reason"))) != NULL) {
-								TCHAR jidreason[ JABBER_MAX_JID_LEN + 256 ];
-								mir_sntprintf(jidreason, SIZEOF(jidreason), _T("%s (%s)") , jid, reason);
-								lvi.pszText = jidreason;
-						}	}
-
-						if (jidListInfo->type == MUC_VOICELIST || jidListInfo->type == MUC_MODERATORLIST) {
-							if ((nick = xmlGetAttrValue(itemNode, _T("nick"))) != NULL) {
-								TCHAR nickjid[ JABBER_MAX_JID_LEN + 256 ];
-								mir_sntprintf(nickjid, SIZEOF(nickjid), _T("%s (%s)") , nick, jid);
-								lvi.pszText = nickjid;
-						}	}
+							LPCTSTR reason = xmlGetText(xmlGetChild(itemNode , _T("reason")));
+							if (reason != NULL) {
+								mir_sntprintf(tszItemText, SIZEOF(tszItemText), _T("%s (%s)") , jid, reason);
+								lvi.pszText = tszItemText;
+							}
+						}
+						else if (jidListInfo->type == MUC_VOICELIST || jidListInfo->type == MUC_MODERATORLIST) {
+							LPCTSTR nick = xmlGetAttrValue(itemNode, _T("nick"));
+							if (nick != NULL) {
+								mir_sntprintf(tszItemText, SIZEOF(tszItemText), _T("%s (%s)") , nick, jid);
+								lvi.pszText = tszItemText;
+							}
+						}
 
 						if (filter && *filter && !JabberStrIStr(lvi.pszText, filter))
 							continue;
@@ -135,7 +138,11 @@ static void sttFillJidList(HWND hwndDlg)
 
 						ListView_InsertItem(hwndList, &lvi);
 						lvi.iItem++;
-	}	}	}	}	}
+					}
+				}
+			}
+		}
+	}
 
 	lvi.mask = LVIF_PARAM;
 	lvi.lParam = (LPARAM)(-1);
@@ -169,11 +176,10 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w
 		{
 			LVCOLUMN lvc;
 			RECT rc;
-			HWND hwndList;
 
 			TranslateDialogDefault(hwndDlg);
 
-			hwndList = GetDlgItem(hwndDlg, IDC_LIST);
+			HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST);
 			ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
 			GetClientRect(hwndList, &rc);
 			//rc.right -= GetSystemMetrics(SM_CXVSCROLL);
@@ -233,8 +239,6 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w
 	case WM_JABBER_REFRESH:
 		{
 			// lParam is (JABBER_MUC_JIDLIST_INFO *)
-			HXML iqNode, queryNode;
-			const TCHAR *from;
 			TCHAR title[256];
 
 			// Clear current GWL_USERDATA, if any
@@ -248,11 +252,13 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w
 			// Populate displayed list from iqNode
 			lstrcpyn(title, TranslateT("JID List"), SIZEOF(title));
 			if ((dat=(JABBER_MUC_JIDLIST_INFO *) lParam) != NULL) {
-				if ((iqNode = dat->iqNode) != NULL) {
-					if ((from = xmlGetAttrValue(iqNode, _T("from"))) != NULL) {
+				HXML iqNode = dat->iqNode;
+				if (iqNode != NULL) {
+					LPCTSTR from = xmlGetAttrValue(iqNode, _T("from"));
+					if (from != NULL) {
 						dat->roomJid = mir_tstrdup(from);
-
-						if ((queryNode = xmlGetChild(iqNode , "query")) != NULL) {
+						HXML queryNode = xmlGetChild(iqNode , _T("query"));
+						if (queryNode != NULL) {
 							TCHAR *localFrom = mir_tstrdup(from);
 							mir_sntprintf(title, SIZEOF(title), TranslateT("%s, %d items (%s)"),
 								(dat->type == MUC_VOICELIST) ? TranslateT("Voice List") :
@@ -263,7 +269,10 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w
 								(dat->type == MUC_OWNERLIST) ? TranslateT("Owner List") :
 								TranslateT("JID List"), xmlGetChildCount(queryNode), localFrom);
 							mir_free(localFrom);
-			}	}	}	}
+						}
+					}
+				}
+			}
 			SetWindowText(hwndDlg, title);
 
 			SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_FILTER), GWLP_USERDATA, 0);
@@ -285,10 +294,9 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w
 					case CDDS_SUBITEM|CDDS_ITEMPREPAINT:
 						{
 							RECT rc;
-							HICON hIcon;
-
 							ListView_GetSubItemRect(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, LVIR_LABEL, &rc);
 							if (nm->iSubItem == 1) {
+								HICON hIcon;
 								if (nm->nmcd.lItemlParam == (LPARAM)(-1))
 									hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ADDCONTACT), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
 								else
@@ -297,7 +305,10 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w
 								DestroyIcon(hIcon);
 								SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
 								return TRUE;
-				}	}	}	}
+							}
+						}
+					}
+				}
 				break;
 			case NM_CLICK:
 				{
@@ -376,16 +387,14 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w
 
 	case WM_CLOSE:
 		{
-			HWND hwndList;
-			int count, i;
 			LVITEM lvi;
 
 			// Free lParam of the displayed list items
-			hwndList = GetDlgItem(hwndDlg, IDC_LIST);
-			count = ListView_GetItemCount(hwndList);
+			HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST);
+			int count = ListView_GetItemCount(hwndList);
 			lvi.mask = LVIF_PARAM;
 			lvi.iSubItem = 0;
-			for (i=0; i<count; i++) {
+			for (int i=0; i<count; i++) {
 				lvi.iItem = i;
 				if (ListView_GetItem(hwndList, &lvi) == TRUE) {
 					if (lvi.lParam!=(LPARAM)(-1) && lvi.lParam!=(LPARAM)(NULL)) {
@@ -434,17 +443,24 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w
 
 static void CALLBACK JabberMucJidListCreateDialogApcProc(void* param)
 {
-	HXML iqNode, queryNode;
-	const TCHAR *from;
-	HWND *pHwndJidList;
 	JABBER_MUC_JIDLIST_INFO *jidListInfo = (JABBER_MUC_JIDLIST_INFO *)param;
+	if (jidListInfo == NULL)
+		return;
 
-	if (jidListInfo == NULL)                                     return;
-	if ((iqNode = jidListInfo->iqNode) == NULL)                 return;
-	if ((from = xmlGetAttrValue(iqNode, _T("from"))) == NULL)   return;
-	if ((queryNode = xmlGetChild(iqNode , "query")) == NULL)   return;
+	HXML iqNode = jidListInfo->iqNode;
+	if (iqNode == NULL)
+		return;
+
+	LPCTSTR from  = xmlGetAttrValue(iqNode, _T("from"));
+	if (from == NULL)
+		return;
+
+	HXML queryNode = xmlGetChild(iqNode , _T("query"));
+	if (queryNode == NULL)
+		return;
 
 	CJabberProto *ppro = jidListInfo->ppro;
+	HWND *pHwndJidList;
 	switch (jidListInfo->type) {
 	case MUC_VOICELIST:
 		pHwndJidList = &ppro->m_hwndMucVoiceList;
@@ -478,13 +494,13 @@ static void CALLBACK JabberMucJidListCreateDialogApcProc(void* param)
 
 void CJabberProto::OnIqResultMucGetJidList(HXML iqNode, JABBER_MUC_JIDLIST_TYPE listType)
 {
-	const TCHAR *type;
-	JABBER_MUC_JIDLIST_INFO *jidListInfo;
-
-	if ((type = xmlGetAttrValue(iqNode, _T("type"))) == NULL) return;
+	LPCTSTR type = xmlGetAttrValue(iqNode, _T("type"));
+	if (type == NULL)
+		return;
 
 	if (!lstrcmp(type, _T("result"))) {
-		if ((jidListInfo = new JABBER_MUC_JIDLIST_INFO) != NULL) {
+		JABBER_MUC_JIDLIST_INFO *jidListInfo = new JABBER_MUC_JIDLIST_INFO;
+		if (jidListInfo != NULL) {
 			jidListInfo->type = listType;
 			jidListInfo->ppro = this;
 			jidListInfo->roomJid = NULL;	// Set in the dialog procedure
@@ -492,39 +508,41 @@ void CJabberProto::OnIqResultMucGetJidList(HXML iqNode, JABBER_MUC_JIDLIST_TYPE
 				CallFunctionAsync(JabberMucJidListCreateDialogApcProc, jidListInfo);
 			else
 				mir_free(jidListInfo);
-}	}	}
+		}
+	}
+}
 
-void CJabberProto::OnIqResultMucGetVoiceList(HXML iqNode, CJabberIqInfo *pInfo)
+void CJabberProto::OnIqResultMucGetVoiceList(HXML iqNode, CJabberIqInfo *)
 {
 	debugLogA("<iq/> iqResultMucGetVoiceList");
 	OnIqResultMucGetJidList(iqNode, MUC_VOICELIST);
 }
 
-void CJabberProto::OnIqResultMucGetMemberList(HXML iqNode, CJabberIqInfo *pInfo)
+void CJabberProto::OnIqResultMucGetMemberList(HXML iqNode, CJabberIqInfo *)
 {
 	debugLogA("<iq/> iqResultMucGetMemberList");
 	OnIqResultMucGetJidList(iqNode, MUC_MEMBERLIST);
 }
 
-void CJabberProto::OnIqResultMucGetModeratorList(HXML iqNode, CJabberIqInfo *pInfo)
+void CJabberProto::OnIqResultMucGetModeratorList(HXML iqNode, CJabberIqInfo *)
 {
 	debugLogA("<iq/> iqResultMucGetModeratorList");
 	OnIqResultMucGetJidList(iqNode, MUC_MODERATORLIST);
 }
 
-void CJabberProto::OnIqResultMucGetBanList(HXML iqNode, CJabberIqInfo *pInfo)
+void CJabberProto::OnIqResultMucGetBanList(HXML iqNode, CJabberIqInfo *)
 {
 	debugLogA("<iq/> iqResultMucGetBanList");
 	OnIqResultMucGetJidList(iqNode, MUC_BANLIST);
 }
 
-void CJabberProto::OnIqResultMucGetAdminList(HXML iqNode, CJabberIqInfo *pInfo)
+void CJabberProto::OnIqResultMucGetAdminList(HXML iqNode, CJabberIqInfo *)
 {
 	debugLogA("<iq/> iqResultMucGetAdminList");
 	OnIqResultMucGetJidList(iqNode, MUC_ADMINLIST);
 }
 
-void CJabberProto::OnIqResultMucGetOwnerList(HXML iqNode, CJabberIqInfo *pInfo)
+void CJabberProto::OnIqResultMucGetOwnerList(HXML iqNode, CJabberIqInfo *)
 {
 	debugLogA("<iq/> iqResultMucGetOwnerList");
 	OnIqResultMucGetJidList(iqNode, MUC_OWNERLIST);
@@ -547,7 +565,6 @@ TCHAR* JABBER_MUC_JIDLIST_INFO::type2str() const
 		case MUC_BANLIST:       return TranslateT("Ban List");
 		case MUC_ADMINLIST:     return TranslateT("Admin List");
 		case MUC_OWNERLIST:     return TranslateT("Owner List");
+		default:                return TranslateT("JID List");
 	}
-
-	return TranslateT("JID List");
 }
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp
index ce8ea900d9..9b225a91e5 100644
--- a/protocols/JabberG/src/jabber_opt.cpp
+++ b/protocols/JabberG/src/jabber_opt.cpp
@@ -255,8 +255,7 @@ protected:
 			else
 				SetDlgItemText(m_hwnd, IDC_REG_STATUS, (TCHAR*)lParam);
 
-			if (wParam >= 0)
-				SendMessage(GetDlgItem(m_hwnd, IDC_PROGRESS_REG), PBM_SETPOS, wParam, 0);
+			SendMessage(GetDlgItem(m_hwnd, IDC_PROGRESS_REG), PBM_SETPOS, wParam, 0);
 			if (wParam >= 100)
 				m_btnOk.SetText(TranslateT("Close"));
 			else
-- 
cgit v1.2.3