summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-09 19:32:32 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-09 19:32:39 +0300
commitdf6b0c988eb26339d4c7e4a1d0fe3b9717703c28 (patch)
tree5b4960edd6c9186e1fbc14f83f7f08a6a842f0a7 /protocols
parent303dd9297732fc943ed3e20ab37587f0c009dfe5 (diff)
more loop-related code cleaning
Diffstat (limited to 'protocols')
-rw-r--r--protocols/IRCG/src/output.cpp38
-rw-r--r--protocols/JabberG/src/jabber_opttree.cpp12
-rw-r--r--protocols/JabberG/src/jabber_search.cpp24
-rwxr-xr-xprotocols/JabberG/src/jabber_userinfo.cpp13
-rw-r--r--protocols/MSN/src/msn_chat.cpp6
-rw-r--r--protocols/MSN/src/msn_lists.cpp16
-rw-r--r--protocols/MSN/src/msn_skypeab.cpp30
-rw-r--r--protocols/MSN/src/msn_srv.cpp13
-rw-r--r--protocols/VKontakte/src/misc.cpp13
9 files changed, 54 insertions, 111 deletions
diff --git a/protocols/IRCG/src/output.cpp b/protocols/IRCG/src/output.cpp
index fe0c8b97f4..0e8bc3ff0b 100644
--- a/protocols/IRCG/src/output.cpp
+++ b/protocols/IRCG/src/output.cpp
@@ -21,39 +21,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-static CMStringW FormatOutput(const CIrcMessage* pmsg)
+static CMStringW FormatOutput(const CIrcMessage *pmsg)
{
CMStringW sMessage;
if (pmsg->m_bIncoming) { // Is it an incoming message?
if (pmsg->sCommand == L"WALLOPS" && pmsg->parameters.getCount() > 0) {
sMessage.Format(TranslateT("WallOps from %s: "), pmsg->prefix.sNick.c_str());
- for (int i = 0; i < pmsg->parameters.getCount(); i++) {
- sMessage += pmsg->parameters[i];
- if (i != pmsg->parameters.getCount() - 1)
- sMessage += L" ";
- }
+ for (auto &it : pmsg->parameters)
+ sMessage += *it + L" ";
goto THE_END;
}
if (pmsg->sCommand == L"INVITE" && pmsg->parameters.getCount() > 1) {
sMessage.Format(TranslateT("%s invites you to %s"), pmsg->prefix.sNick.c_str(), pmsg->parameters[1].c_str());
- for (int i = 2; i < pmsg->parameters.getCount(); i++) {
- sMessage += L": " + pmsg->parameters[i];
- if (i != pmsg->parameters.getCount() - 1)
- sMessage += L" ";
- }
+ for (int i = 2; i < pmsg->parameters.getCount(); i++)
+ sMessage += L": " + pmsg->parameters[i] + L" ";
goto THE_END;
}
int index = _wtoi(pmsg->sCommand.c_str());
if (index == 301 && pmsg->parameters.getCount() > 0) {
sMessage.Format(TranslateT("%s is away"), pmsg->parameters[1].c_str());
- for (int i = 2; i < pmsg->parameters.getCount(); i++) {
- sMessage += L": " + pmsg->parameters[i];
- if (i != pmsg->parameters.getCount() - 1)
- sMessage += L" ";
- }
+ for (int i = 2; i < pmsg->parameters.getCount(); i++)
+ sMessage += L": " + pmsg->parameters[i] + L" ";
goto THE_END;
}
@@ -62,11 +53,8 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg)
if (index == 303) { // ISON command
sMessage = TranslateT("These are online: ");
- for (int i = 1; i < pmsg->parameters.getCount(); i++) {
- sMessage += pmsg->parameters[i];
- if (i != pmsg->parameters.getCount() - 1)
- sMessage += L", ";
- }
+ for (int i = 1; i < pmsg->parameters.getCount(); i++)
+ sMessage += pmsg->parameters[i] + L", ";
goto THE_END;
}
@@ -88,11 +76,8 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg)
}
else {
sMessage.Format(TranslateT("Notice to %s: "), pmsg->parameters[0].c_str());
- for (int i = 1; i < pmsg->parameters.getCount(); i++) {
- sMessage += pmsg->parameters[i];
- if (i != pmsg->parameters.getCount() - 1)
- sMessage += L" ";
- }
+ for (int i = 1; i < pmsg->parameters.getCount(); i++)
+ sMessage += pmsg->parameters[i] + L" ";
}
goto THE_END;
}
@@ -116,6 +101,7 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg)
}
THE_END:
+ sMessage.TrimRight();
return sMessage;
}
diff --git a/protocols/JabberG/src/jabber_opttree.cpp b/protocols/JabberG/src/jabber_opttree.cpp
index 047decb2be..c9ad4ba465 100644
--- a/protocols/JabberG/src/jabber_opttree.cpp
+++ b/protocols/JabberG/src/jabber_opttree.cpp
@@ -175,10 +175,10 @@ void CCtrlTreeOpts::OnApply()
{
CCtrlTreeView::OnApply();
- for (int i = 0; i < m_options.getCount(); i++) {
+ for (auto &it : m_options) {
TVITEMEX tvi;
- GetItem(m_options[i]->m_hItem, &tvi);
- *m_options[i]->m_option = ((tvi.iImage == IMG_CHECK) || (tvi.iImage == IMG_RCHECK)) ? 1 : 0;
+ GetItem(it->m_hItem, &tvi);
+ *it->m_option = ((tvi.iImage == IMG_CHECK) || (tvi.iImage == IMG_RCHECK)) ? 1 : 0;
}
}
@@ -208,11 +208,11 @@ void CCtrlTreeOpts::ProcessItemClick(HTREEITEM hti)
break;
case IMG_NORCHECK:
- for (int i = 0; i < m_options.getCount(); i++) {
- if (m_options[i]->m_groupId == m_options[tvi.lParam]->m_groupId) {
+ for (auto &it : m_options) {
+ if (it->m_groupId == m_options[tvi.lParam]->m_groupId) {
TVITEMEX tvi_tmp;
tvi_tmp.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
- tvi_tmp.hItem = m_options[i]->m_hItem;
+ tvi_tmp.hItem = it->m_hItem;
tvi_tmp.iImage = tvi_tmp.iSelectedImage = IMG_NORCHECK;
SetItem(&tvi_tmp);
}
diff --git a/protocols/JabberG/src/jabber_search.cpp b/protocols/JabberG/src/jabber_search.cpp
index e325fad9fe..d0dfcfcbe3 100644
--- a/protocols/JabberG/src/jabber_search.cpp
+++ b/protocols/JabberG/src/jabber_search.cpp
@@ -209,12 +209,10 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M
{
LIST<wchar_t> ListOfNonEmptyFields(20, (LIST<wchar_t>::FTSortFunc)TCharKeyCmp);
LIST<wchar_t> ListOfFields(20);
- LIST<void>* plUsersInfo = (LIST<void>*)pvUsersInfo;
- int i, nUsersFound = plUsersInfo->getCount();
+ LIST<U_TCHAR_MAP> *plUsersInfo = (LIST<U_TCHAR_MAP>*)pvUsersInfo;
// lets fill the ListOfNonEmptyFields but in users order
- for (i = 0; i < nUsersFound; i++) {
- U_TCHAR_MAP* pmUserData = (U_TCHAR_MAP*)plUsersInfo->operator [](i);
+ for (auto &pmUserData : *plUsersInfo) {
int nUserFields = pmUserData->getCount();
for (int j = 0; j < nUserFields; j++) {
wchar_t *var = pmUserData->getKeyName(j);
@@ -225,7 +223,7 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M
// now fill the ListOfFields but order is from pmAllFields
int nAllCount = pmAllFields->getCount();
- for (i = 0; i < nAllCount; i++) {
+ for (int i = 0; i < nAllCount; i++) {
wchar_t *var = pmAllFields->getUnOrderedKeyName(i);
if (var && ListOfNonEmptyFields.getIndex(var) < 0)
continue;
@@ -241,7 +239,7 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M
Results.nFieldCount = nFieldCount;
/* Sending Columns Titles */
- for (i = 0; i < nFieldCount; i++) {
+ for (int i = 0; i < nFieldCount; i++) {
wchar_t *var = ListOfFields[i];
if (var)
Results.pszFields[i] = pmAllFields->operator [](var);
@@ -253,10 +251,9 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M
/* Sending Users Data */
Results.psr.cbSize = sizeof(Results.psr); // sending user data
- for (i = 0; i < nUsersFound; i++) {
+ for (auto &pmUserData : *plUsersInfo) {
wchar_t buff[200];
buff[0] = 0;
- U_TCHAR_MAP *pmUserData = (U_TCHAR_MAP *)plUsersInfo->operator [](i);
for (int j = 0; j < nFieldCount; j++) {
wchar_t *var = ListOfFields[j];
wchar_t *value = pmUserData->operator [](var);
@@ -554,14 +551,11 @@ static INT_PTR CALLBACK JabberSearchAdvancedDlgProc(HWND hwndDlg, UINT msg, WPAR
SetDlgItemTextA(hwndDlg, IDC_SERVER, szServerName);
SendDlgItemMessageA(hwndDlg, IDC_SERVER, CB_ADDSTRING, 0, (LPARAM)szServerName);
//TO DO: Add Transports here
- int i, transpCount = dat->ppro->m_lstTransports.getCount();
- for (i = 0; i < transpCount; i++) {
- wchar_t *szTransp = dat->ppro->m_lstTransports[i];
- if (szTransp)
- JabberSearchAddUrlToRecentCombo(hwndDlg, szTransp);
- }
+ for (auto &it : dat->ppro->m_lstTransports)
+ if (it != nullptr)
+ JabberSearchAddUrlToRecentCombo(hwndDlg, it);
- for (i = 0; i < 10; i++) {
+ for (int i = 0; i < 10; i++) {
char key[30];
mir_snprintf(key, "RecentlySearched_%d", i);
ptrW szValue(dat->ppro->getWStringA(key));
diff --git a/protocols/JabberG/src/jabber_userinfo.cpp b/protocols/JabberG/src/jabber_userinfo.cpp
index 610cab6a87..203c1022e2 100755
--- a/protocols/JabberG/src/jabber_userinfo.cpp
+++ b/protocols/JabberG/src/jabber_userinfo.cpp
@@ -292,15 +292,16 @@ static void sttFillResourceInfo(CJabberProto *ppro, HWND hwndTree, HTREEITEM hti
sttFillInfoLine(hwndTree, htiCaps, nullptr, nullptr, szDescription, sttInfoLineId(resource, INFOLINE_CAPS, i));
}
- for (int j = 0; j < ppro->m_lstJabberFeatCapPairsDynamic.getCount(); j++, i++)
- if (jcb & ppro->m_lstJabberFeatCapPairsDynamic[j]->jcbCap) {
+ for (auto &it : ppro->m_lstJabberFeatCapPairsDynamic) {
+ if (jcb & it->jcbCap) {
wchar_t szDescription[1024];
- if (ppro->m_lstJabberFeatCapPairsDynamic[j]->szDescription)
- mir_snwprintf(szDescription, L"%s (%s)", TranslateW(ppro->m_lstJabberFeatCapPairsDynamic[j]->szDescription), ppro->m_lstJabberFeatCapPairsDynamic[j]->szFeature);
+ if (it->szDescription)
+ mir_snwprintf(szDescription, L"%s (%s)", TranslateW(it->szDescription), it->szFeature);
else
- wcsncpy_s(szDescription, ppro->m_lstJabberFeatCapPairsDynamic[j]->szFeature, _TRUNCATE);
- sttFillInfoLine(hwndTree, htiCaps, nullptr, nullptr, szDescription, sttInfoLineId(resource, INFOLINE_CAPS, i));
+ wcsncpy_s(szDescription, it->szFeature, _TRUNCATE);
+ sttFillInfoLine(hwndTree, htiCaps, nullptr, nullptr, szDescription, sttInfoLineId(resource, INFOLINE_CAPS, i++));
}
+ }
}
// Software info
diff --git a/protocols/MSN/src/msn_chat.cpp b/protocols/MSN/src/msn_chat.cpp
index 2ed9979947..fe9b611941 100644
--- a/protocols/MSN/src/msn_chat.cpp
+++ b/protocols/MSN/src/msn_chat.cpp
@@ -152,9 +152,9 @@ void CMsnProto::MSN_Promoteuser(GCHOOK *gch, const char *pszRole)
const wchar_t *CMsnProto::MSN_GCGetRole(GCThreadData* thread, const char *pszWLID)
{
if (thread)
- for (int j = 0; j < thread->mJoinedContacts.getCount(); j++)
- if (!mir_strcmp(thread->mJoinedContacts[j]->WLID, pszWLID))
- return thread->mJoinedContacts[j]->role;
+ for (auto &it : thread->mJoinedContacts)
+ if (!mir_strcmp(it->WLID, pszWLID))
+ return it->role;
return nullptr;
}
diff --git a/protocols/MSN/src/msn_lists.cpp b/protocols/MSN/src/msn_lists.cpp
index 0953685dde..c103be86f3 100644
--- a/protocols/MSN/src/msn_lists.cpp
+++ b/protocols/MSN/src/msn_lists.cpp
@@ -297,21 +297,9 @@ void CMsnProto::MSN_CreateContList(void)
cxml.AppendFormat("<c n=\"%s\" t=\"%d\"><s l=\"%d\" n=\"PE\"/><s l=\"%d\" n=\"IM\"/><s l=\"%d\" n=\"SKP\"/><s l=\"%d\" n=\"PUB\"/></c>", C.email, C.netId, list, list, list, list);
used[j] = true;
}
- /* Seems to be unused in Skype and causing errors
- else if (dom != NULL && lastds != NULL && _stricmp(lastds, dom) == 0) {
- if (newdom) {
- cxml.AppendFormat("<d n=\"%s\">", lastds + 1);
- newdom = false;
- }
-
- *(char*)dom = 0;
- cxml.AppendFormat("<c n=\"%s\" t=\"%d\"><s n=\"IM\" l=\"%d\"/></c>", C.email, C.netId, C.list & ~(LIST_RL | LIST_LL));
- *(char*)dom = '@';
- used[j] = true;
- }
- */
}
- if (!newdom) cxml.Append(lastds ? "</d>" : "</skp>");
+ if (!newdom)
+ cxml.Append(lastds ? "</d>" : "</skp>");
}
}
diff --git a/protocols/MSN/src/msn_skypeab.cpp b/protocols/MSN/src/msn_skypeab.cpp
index c551866a78..571dcf63b3 100644
--- a/protocols/MSN/src/msn_skypeab.cpp
+++ b/protocols/MSN/src/msn_skypeab.cpp
@@ -405,33 +405,3 @@ bool CMsnProto::MSN_SKYABSearch(const char *keyWord, HANDLE hSearch)
else hHttpsConnection = nullptr;
return bRet;
}
-
-/*
-class GetContactsInfoRequest : public HttpRequest
-{
-public:
- GetContactsInfoRequest(const char *token, const LIST<char> &skypenames, const char *skypename = "self") :
- HttpRequest(REQUEST_POST, FORMAT, "api.skype.com/users/%s/contacts/profiles", skypename)
- {
- Headers
- << CHAR_VALUE("X-Skypetoken", token)
- << CHAR_VALUE("Accept", "application/json");
-
- for (int i = 0; i < skypenames.getCount(); i++)
- Body << CHAR_VALUE("contacts[]", skypenames[i]);
- }
-};
-
-class GetContactStatusRequest : public HttpRequest
-{
-public:
- GetContactStatusRequest(const char *regToken, const char *skypename, const char *server = SKYPE_ENDPOINTS_HOST) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/contacts/8:%s/presenceDocs/messagingService", server, skypename)
- {
- Headers
- << CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken);
- }
-};
-
-*/
diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp
index a3e5181f73..cc9ff30f2b 100644
--- a/protocols/MSN/src/msn_srv.cpp
+++ b/protocols/MSN/src/msn_srv.cpp
@@ -177,19 +177,22 @@ void CMsnProto::MSN_RemoveEmptyGroups(void)
int count = -1;
for (;;) {
MsnContact *msc = Lists_GetNext(count);
- if (msc == nullptr) break;
+ if (msc == nullptr)
+ break;
char szGroupID[100];
if (!db_get_static(msc->hContact, m_szModuleName, "GroupID", szGroupID, sizeof(szGroupID))) {
const char *pId = szGroupID;
int i = m_arGroups.getIndex((ServerGroupItem*)&pId);
- if (i > -1) ++cCount[i];
+ if (i > -1)
+ ++cCount[i];
}
}
- for (int i = m_arGroups.getCount(); i--;) {
- if (cCount[i] == 0) MSN_DeleteServerGroup(m_arGroups[i]->id);
- }
+ for (int i = m_arGroups.getCount(); i--;)
+ if (cCount[i] == 0)
+ MSN_DeleteServerGroup(m_arGroups[i]->id);
+
mir_free(cCount);
}
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index c8479c6911..551ac57da7 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -519,14 +519,15 @@ void CVkProto::GrabCookies(NETLIBHTTPREQUEST *nhr)
}
if (!szCookieName.IsEmpty() && !szDomain.IsEmpty()) {
- int k;
- for (k = 0; k < m_cookies.getCount(); k++) {
- if (m_cookies[k].m_name == szCookieName) {
- m_cookies[k].m_value = szCookieVal;
+ bool bFound = false;
+ for (auto &it : m_cookies)
+ if (it->m_name == szCookieName) {
+ bFound = true;
+ it->m_value = szCookieVal;
break;
}
- }
- if (k == m_cookies.getCount())
+
+ if (!bFound)
m_cookies.insert(new CVkCookie(szCookieName, szCookieVal, szDomain));
}
}