diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-16 20:01:14 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-16 20:01:14 +0300 |
commit | 39390b02dbd5aa7eb21a83773fa561b39f8828bc (patch) | |
tree | 7982eda1257f7466b5663c2865fdb7804c397257 /protocols | |
parent | 5046973a41e412afd06d6a78a3b9bce226e3cf50 (diff) |
always hated these long expressions: contact_iter makes them much shorter
Diffstat (limited to 'protocols')
50 files changed, 95 insertions, 145 deletions
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 0b450a9fda..7014e6e51d 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -69,7 +69,7 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : Clist_GroupCreate(0, m_wszDefaultGroup); // Fill users list - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { CDiscordUser *pNew = new CDiscordUser(getId(hContact, DB_KEY_ID)); pNew->hContact = hContact; pNew->channelId = getId(hContact, DB_KEY_CHANNELID); diff --git a/protocols/EmLanProto/src/mlan.cpp b/protocols/EmLanProto/src/mlan.cpp index 6cd8255697..aedb605b13 100644 --- a/protocols/EmLanProto/src/mlan.cpp +++ b/protocols/EmLanProto/src/mlan.cpp @@ -111,7 +111,7 @@ void CMLan::SetMirandaStatus(u_int status) void CMLan::SetAllOffline() { - for (MCONTACT hContact = db_find_first(PROTONAME); hContact; hContact = db_find_next(hContact, PROTONAME)) { + for (auto &hContact : contact_iter(PROTONAME)) { db_set_w(hContact, PROTONAME, "Status", ID_STATUS_OFFLINE); db_unset(hContact, PROTONAME, "IP"); } @@ -205,7 +205,7 @@ void CMLan::SendPacketExt(TPacket& pak, u_long addr) MCONTACT CMLan::FindContact(in_addr addr, const char* nick, bool add_to_list, bool make_permanent, bool make_visible, u_int status) { - for (MCONTACT res = db_find_first(PROTONAME); res; res = db_find_next(res, PROTONAME)) { + for (auto &res : contact_iter(PROTONAME)) { u_long caddr = db_get_dw(res, PROTONAME, "ipaddr", -1); if (caddr == addr.S_un.S_addr) { if (make_permanent) diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index 266818d1af..565f434872 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -500,7 +500,7 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc) void FacebookProto::JoinChatrooms() { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!isChatRoom(hContact)) continue; diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index be4c056871..889b042fa3 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -90,7 +90,7 @@ MCONTACT FacebookProto::ChatIDToHContact(const std::string &chat_id) } // Go through all local contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!IsMyContact(hContact, true)) continue; @@ -122,7 +122,7 @@ MCONTACT FacebookProto::ContactIDToHContact(const std::string &user_id) } // Go through all local contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) continue; @@ -150,7 +150,7 @@ std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id) } // Go through all local contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (!IsMyContact(hContact)) continue; diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 4455126c61..a30cdbbf6c 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -50,7 +50,7 @@ void FacebookProto::ProcessFriendList(void*) ParseFriends(&resp.data, &friends, loadAllContacts); // Check and update old contacts - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (isChatRoom(hContact)) continue; diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index 266ff97786..f34163ad81 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -1373,7 +1373,7 @@ void GaduProto::setalloffline() debugLogA("setalloffline(): started. Setting buddies offline");
setWord(GG_KEY_STATUS, ID_STATUS_OFFLINE);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
setWord(hContact, GG_KEY_STATUS, ID_STATUS_OFFLINE);
// Clear IP and port settings
delSetting(hContact, GG_KEY_CLIENTIP);
@@ -1437,7 +1437,7 @@ void GaduProto::notifyall() debugLogA("notifyall(): Subscribing notification to all users");
// Readup count
int count = 0;
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ for (auto &hContact : acc_contact_iter())
count++;
// Readup list
@@ -1454,7 +1454,7 @@ void GaduProto::notifyall() char *types = (char*)calloc(sizeof(char), count);
int cc = 0;
- for (hContact = db_find_first(m_szModuleName); hContact && cc < count; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (uins[cc] = getDword(hContact, GG_KEY_UIN, 0)) {
if ((getWord(hContact, GG_KEY_APPARENT, (WORD)ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) ||
db_get_b(hContact, "CList", "NotOnList", 0))
@@ -1490,7 +1490,7 @@ MCONTACT GaduProto::getcontact(uin_t uin, int create, int inlist, wchar_t *szNic debugLogA("getcontact(): uin=%d create=%d inlist=%d", uin, create, inlist);
#endif
// Look for contact in DB
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if ((uin_t)getDword(hContact, GG_KEY_UIN, 0) == uin && !isChatRoom(hContact)) {
if (inlist) {
db_unset(hContact, "CList", "NotOnList");
diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp index 2126cfdb53..7e6d7a823f 100644 --- a/protocols/Gadu-Gadu/src/groupchat.cpp +++ b/protocols/Gadu-Gadu/src/groupchat.cpp @@ -407,7 +407,7 @@ static void gg_gc_resetclistopts(HWND hwndList) static int gg_gc_countcheckmarks(HWND hwndList)
{
int count = 0;
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0);
if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0))
++count;
@@ -459,7 +459,7 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa // Create new participiants table
uin_t* participants = (uin_t*)calloc(count, sizeof(uin_t));
gg->debugLogA("gg_gc_openconfdlg(): WM_COMMAND IDOK Opening new conference for %d contacts.", count);
- for (MCONTACT hContact = db_find_first(); hContact && i < count; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0);
if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support
@@ -508,7 +508,7 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa break;
// Delete non-gg contacts
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
MCONTACT hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0);
if (hItem) {
MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support
diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index 23c621ead5..ae8c96764f 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -25,7 +25,7 @@ char *gg_makecontacts(GaduProto *gg, int cr) string_t s = string_init(nullptr);
// Readup contacts
- for (MCONTACT hContact = db_find_first(gg->m_szModuleName); hContact; hContact = db_find_next(hContact, gg->m_szModuleName)) {
+ for (auto &hContact : gg->acc_contact_iter()) {
if (gg->isChatRoom(hContact))
continue;
diff --git a/protocols/ICQCorp/src/protocol.cpp b/protocols/ICQCorp/src/protocol.cpp index 57f683a63b..41cdc81cd3 100644 --- a/protocols/ICQCorp/src/protocol.cpp +++ b/protocols/ICQCorp/src/protocol.cpp @@ -1111,7 +1111,7 @@ void ICQ::updateContactList() //HANDLE hContact;
ICQUser *u;
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
proto = GetContactProto(hContact);
if (proto && !mir_strcmp(proto, protoName)) {
if ((u = getUserByContact(hContact)) == nullptr) {
diff --git a/protocols/IRCG/src/clist.cpp b/protocols/IRCG/src/clist.cpp index 8409c501e7..b09b9b9248 100644 --- a/protocols/IRCG/src/clist.cpp +++ b/protocols/IRCG/src/clist.cpp @@ -140,7 +140,7 @@ bool CIrcProto::CList_SetAllOffline(BYTE ChatsToo) DisconnectAllDCCSessions(false);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (isChatRoom(hContact))
continue;
@@ -168,7 +168,7 @@ MCONTACT CIrcProto::CList_FindContact(CONTACT *user) wchar_t* lowercasename = mir_wstrdup(user->name);
CharLower(lowercasename);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (isChatRoom(hContact))
continue;
diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp index 05ca521f17..8ba7681450 100644 --- a/protocols/IRCG/src/commandmonitor.cpp +++ b/protocols/IRCG/src/commandmonitor.cpp @@ -141,7 +141,7 @@ VOID CALLBACK OnlineNotifTimerProc(HWND, UINT, UINT_PTR idEvent, DWORD) if (name.IsEmpty() && name2.IsEmpty()) {
DBVARIANT dbv;
- for (MCONTACT hContact = db_find_first(ppro->m_szModuleName); hContact; hContact = db_find_next(hContact, ppro->m_szModuleName)) {
+ for (auto &hContact : ppro->acc_contact_iter()) {
if (ppro->isChatRoom(hContact))
continue;
diff --git a/protocols/IcqOscarJ/src/icq_infoupdate.cpp b/protocols/IcqOscarJ/src/icq_infoupdate.cpp index 8ebdcbd7bf..b4f443aa2c 100644 --- a/protocols/IcqOscarJ/src/icq_infoupdate.cpp +++ b/protocols/IcqOscarJ/src/icq_infoupdate.cpp @@ -126,7 +126,7 @@ void CIcqProto::icq_RescanInfoUpdate() bInfoUpdateEnabled = 0; // freeze thread
// Queue all outdated users
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ for (auto &hContact : acc_contact_iter())
if (IsMetaInfoChanged(hContact)) // Queue user
if (!icq_QueueUser(hContact)) { // The queue is full, pause queuing contacts
bInfoPendingUsers = 1;
diff --git a/protocols/IcqOscarJ/src/icq_proto.cpp b/protocols/IcqOscarJ/src/icq_proto.cpp index 25ba07ecd5..21b99bdd01 100644 --- a/protocols/IcqOscarJ/src/icq_proto.cpp +++ b/protocols/IcqOscarJ/src/icq_proto.cpp @@ -259,7 +259,7 @@ int CIcqProto::OnModulesLoaded(WPARAM, LPARAM) ModuleLoad(0, 0);
InitXStatusItems(FALSE);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
DWORD bXStatus = getContactXStatus(hContact);
if (bXStatus > 0)
setContactExtraIcon(hContact, bXStatus);
diff --git a/protocols/IcqOscarJ/src/icq_server.cpp b/protocols/IcqOscarJ/src/icq_server.cpp index 00c7f46806..b71737b5c6 100644 --- a/protocols/IcqOscarJ/src/icq_server.cpp +++ b/protocols/IcqOscarJ/src/icq_server.cpp @@ -178,7 +178,7 @@ void __cdecl CIcqProto::ServerThread(serverthread_start_info *infoParam) StopAvatarThread();
// Offline all contacts
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (getContactStatus(hContact) == ID_STATUS_OFFLINE)
continue;
diff --git a/protocols/IcqOscarJ/src/icq_servlist.cpp b/protocols/IcqOscarJ/src/icq_servlist.cpp index 54602dd8f5..b61fee4701 100644 --- a/protocols/IcqOscarJ/src/icq_servlist.cpp +++ b/protocols/IcqOscarJ/src/icq_servlist.cpp @@ -858,9 +858,7 @@ void CIcqProto::LoadServerIDs() nGroups = nServerIDListCount - nStart;
- MCONTACT hContact = db_find_first(m_szModuleName);
-
- while (hContact) { // search all our contacts, reserve their server IDs
+ for (auto &hContact : acc_contact_iter()) {
if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_ID, 0)) {
ReserveServerID(wSrvID, SSIT_ITEM, 0);
nContacts++;
@@ -877,8 +875,6 @@ void CIcqProto::LoadServerIDs() ReserveServerID(wSrvID, SSIT_ITEM, 0);
nIgnores++;
}
-
- hContact = db_find_next(hContact, m_szModuleName);
}
l.unlock();
@@ -1201,9 +1197,7 @@ void* CIcqProto::collectBuddyGroup(WORD wGroupID, int *count) MCONTACT hContact;
WORD wItemID;
- hContact = db_find_first(m_szModuleName);
-
- while (hContact) { // search all contacts
+ for (auto &hContact : acc_contact_iter()) {
if (wGroupID == getWord(hContact, DBSETTING_SERVLIST_GROUP, 0)) { // add only buddys from specified group
wItemID = getWord(hContact, DBSETTING_SERVLIST_ID, 0);
@@ -1214,8 +1208,6 @@ void* CIcqProto::collectBuddyGroup(WORD wGroupID, int *count) if (!count) break;
}
}
-
- hContact = db_find_next(hContact, m_szModuleName);
}
if (count)
@@ -1231,8 +1223,7 @@ void* CIcqProto::collectGroups(int *count) int i;
WORD wGroupID;
- MCONTACT hContact = db_find_first(m_szModuleName);
- while (hContact) { // search all contacts
+ for (auto &hContact : acc_contact_iter()) {
if (wGroupID = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0)) { // add only valid IDs
for (i = 0; i < cnt; i++) // check for already added ids
if (buf[i] == wGroupID)
@@ -1244,8 +1235,6 @@ void* CIcqProto::collectGroups(int *count) buf[i] = wGroupID;
}
}
-
- hContact = db_find_next(hContact, m_szModuleName);
}
*count = cnt << 1;
diff --git a/protocols/IcqOscarJ/src/icq_uploadui.cpp b/protocols/IcqOscarJ/src/icq_uploadui.cpp index b841f1eade..5991d7cfcc 100644 --- a/protocols/IcqOscarJ/src/icq_uploadui.cpp +++ b/protocols/IcqOscarJ/src/icq_uploadui.cpp @@ -52,8 +52,7 @@ static void UpdateAllContactsCheckmark(HWND hwndList, CIcqProto* ppro, HANDLE ph {
int check = 1;
- MCONTACT hContact = db_find_first(ppro->m_szModuleName);
- while (hContact) {
+ for (auto &hContact : ppro->acc_contact_iter()) {
HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0);
if (hItem) {
if (!SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { // if any of our contacts is unchecked, uncheck all contacts as well
@@ -61,7 +60,6 @@ static void UpdateAllContactsCheckmark(HWND hwndList, CIcqProto* ppro, HANDLE ph break;
}
}
- hContact = db_find_next(hContact, ppro->m_szModuleName);
}
SendMessage(hwndList, CLM_SETCHECKMARK, (WPARAM)phItemAll, check);
@@ -74,8 +72,7 @@ static int UpdateCheckmarks(HWND hwndList, CIcqProto* ppro, HANDLE phItemAll) int bAll = 1;
bListInit = 1; // lock CLC events
- MCONTACT hContact = db_find_first(ppro->m_szModuleName);
- while (hContact) {
+ for (auto &hContact : ppro->acc_contact_iter()) {
HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0);
if (hItem) {
if (ppro->getWord(hContact, DBSETTING_SERVLIST_ID, 0))
@@ -83,7 +80,6 @@ static int UpdateCheckmarks(HWND hwndList, CIcqProto* ppro, HANDLE phItemAll) else
bAll = 0;
}
- hContact = db_find_next(hContact, ppro->m_szModuleName);
}
// Update the "All contacts" checkmark
@@ -97,7 +93,7 @@ static int UpdateCheckmarks(HWND hwndList, CIcqProto* ppro, HANDLE phItemAll) static void DeleteOtherContactsFromControl(HWND hCtrl, CIcqProto* ppro)
{
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
HANDLE hItem = (HANDLE)SendMessage(hCtrl, CLM_FINDCONTACT, hContact, 0);
if (hItem)
if (!ppro->IsICQContact(hContact))
@@ -835,12 +831,10 @@ static INT_PTR CALLBACK DlgProcUploadList(HWND hwndDlg, UINT message, WPARAM wPa if (nm->flags&CLNF_ISINFO) {
int check = SendMessage(hClist, CLM_GETCHECKMARK, (WPARAM)hItemAll, 0);
- hContact = db_find_first(ppro->m_szModuleName);
- while (hContact) {
+ for (auto &hContact : ppro->acc_contact_iter()) {
HANDLE hItem = (HANDLE)SendMessage(hClist, CLM_FINDCONTACT, hContact, 0);
if (hItem)
SendMessage(hClist, CLM_SETCHECKMARK, (WPARAM)hItem, check);
- hContact = db_find_next(hContact, ppro->m_szModuleName);
}
}
else UpdateAllContactsCheckmark(hClist, ppro, hItemAll);
diff --git a/protocols/IcqOscarJ/src/utilities.cpp b/protocols/IcqOscarJ/src/utilities.cpp index e7af9c8a33..ceaa122129 100644 --- a/protocols/IcqOscarJ/src/utilities.cpp +++ b/protocols/IcqOscarJ/src/utilities.cpp @@ -355,15 +355,11 @@ void CIcqProto::InitContactsCache() // build cache
mir_cslock l(contactsCacheMutex);
- MCONTACT hContact = db_find_first(m_szModuleName);
-
- while (hContact) {
+ for (auto &hContact : acc_contact_iter()) {
DWORD dwUin;
uid_str szUid;
if (!getContactUid(hContact, &dwUin, &szUid))
AddToContactsCache(hContact, dwUin, szUid);
-
- hContact = db_find_next(hContact, m_szModuleName);
}
}
@@ -421,17 +417,12 @@ MCONTACT CIcqProto::HContactFromUIN(DWORD dwUin, int *Added) if (hContact)
return hContact;
- hContact = db_find_first(m_szModuleName);
- while (hContact) {
- DWORD dwContactUin;
-
- dwContactUin = getContactUin(hContact);
+ for (auto &hContact : acc_contact_iter()) {
+ DWORD dwContactUin = getContactUin(hContact);
if (dwContactUin == dwUin) {
AddToContactsCache(hContact, dwUin, nullptr);
return hContact;
}
-
- hContact = db_find_next(hContact, m_szModuleName);
}
// not present: add
@@ -489,8 +480,7 @@ MCONTACT CIcqProto::HContactFromUID(DWORD dwUin, const char *szUid, int *Added) if (hContact)
return hContact;
- hContact = db_find_first(m_szModuleName);
- while (hContact) {
+ for (auto &hContact : acc_contact_iter()) {
DWORD dwContactUin;
uid_str szContactUid;
if (!getContactUid(hContact, &dwContactUin, &szContactUid)) {
@@ -501,7 +491,6 @@ MCONTACT CIcqProto::HContactFromUID(DWORD dwUin, const char *szUid, int *Added) return hContact;
}
}
- hContact = db_find_next(hContact, m_szModuleName);
}
//not present: add
@@ -811,9 +800,7 @@ void CIcqProto::ResetSettingsOnListReload() setWord("SrvRecordCount", 0);
delSetting(DBSETTING_SERVLIST_UNHANDLED);
- MCONTACT hContact = db_find_first(m_szModuleName);
-
- while (hContact) {
+ for (auto &hContact : acc_contact_iter()) {
// All these values will be restored during the serv-list receive
setWord(hContact, DBSETTING_SERVLIST_ID, 0);
setWord(hContact, DBSETTING_SERVLIST_GROUP, 0);
@@ -822,8 +809,6 @@ void CIcqProto::ResetSettingsOnListReload() delSetting(hContact, DBSETTING_SERVLIST_IGNORE);
setByte(hContact, "Auth", 0);
delSetting(hContact, DBSETTING_SERVLIST_DATA);
-
- hContact = db_find_next(hContact, m_szModuleName);
}
FlushSrvGroupsCache();
@@ -835,9 +820,7 @@ void CIcqProto::ResetSettingsOnConnect() setByte("SrvVisibility", 0);
setDword("IdleTS", 0);
- MCONTACT hContact = db_find_first(m_szModuleName);
-
- while (hContact) {
+ for (auto &hContact : acc_contact_iter()) {
setDword(hContact, "LogonTS", 0);
setDword(hContact, "IdleTS", 0);
setDword(hContact, "TickTS", 0);
@@ -846,8 +829,6 @@ void CIcqProto::ResetSettingsOnConnect() // All these values will be restored during the login
if (getContactStatus(hContact) != ID_STATUS_OFFLINE)
setWord(hContact, "Status", ID_STATUS_OFFLINE);
-
- hContact = db_find_next(hContact, m_szModuleName);
}
}
@@ -856,9 +837,7 @@ void CIcqProto::ResetSettingsOnLoad() setDword("IdleTS", 0);
setDword("LogonTS", 0);
- MCONTACT hContact = db_find_first(m_szModuleName);
-
- while (hContact) {
+ for (auto &hContact : acc_contact_iter()) {
setDword(hContact, "LogonTS", 0);
setDword(hContact, "IdleTS", 0);
setDword(hContact, "TickTS", 0);
@@ -870,8 +849,6 @@ void CIcqProto::ResetSettingsOnLoad() delSetting(hContact, DBSETTING_XSTATUS_MSG);
}
setByte(hContact, "DCStatus", 0);
-
- hContact = db_find_next(hContact, m_szModuleName);
}
}
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index a2eeaf620f..c81f133583 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -654,7 +654,7 @@ class CGroupchatInviteDlg : public CJabberDlgBase void FilterList(CCtrlClc *)
{
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
char *proto = GetContactProto(hContact);
if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact))
if (HANDLE hItem = m_clc.FindContact(hContact))
@@ -763,7 +763,7 @@ public: HWND hwndList = GetDlgItem(m_hwnd, IDC_CLIST);
// invite users from roster
- for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
+ for (auto &hContact : m_proto->acc_contact_iter()) {
if (m_proto->isChatRoom(hContact))
continue;
diff --git a/protocols/JabberG/src/jabber_icolib.cpp b/protocols/JabberG/src/jabber_icolib.cpp index 5eb0a99b24..503937a5d0 100644 --- a/protocols/JabberG/src/jabber_icolib.cpp +++ b/protocols/JabberG/src/jabber_icolib.cpp @@ -444,7 +444,7 @@ BOOL CJabberProto::DBCheckIsTransportedContact(const wchar_t *jid, MCONTACT hCon void CJabberProto::CheckAllContactsAreTransported()
{
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
ptrW jid(getWStringA(hContact, "jid"));
if (jid)
DBCheckIsTransportedContact(jid, hContact);
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index 94ba7846e8..51beefb3dc 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -89,7 +89,7 @@ void JABBER_RESOURCE_STATUS::Release() void CJabberProto::ListInit(void)
{
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (isChatRoom(hContact)) {
ptrW jid(getWStringA(hContact, "ChatRoomID"));
if (jid != nullptr)
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index 94ba4caf28..54ee815d48 100755 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -1021,7 +1021,7 @@ void CJabberProto::_RosterHandleGetRequest(HXML node, CJabberIqInfo*) }
// now it is require to process whole contact list to add not in roster contacts
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
ptrW tszJid(getWStringA(hContact, "jid"));
if (tszJid == nullptr)
continue;
diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp index 4e37896abd..32ee36c4dc 100644 --- a/protocols/JabberG/src/jabber_privacy.cpp +++ b/protocols/JabberG/src/jabber_privacy.cpp @@ -422,7 +422,7 @@ public: SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0);
{
- for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
+ for (auto &hContact : m_proto->acc_contact_iter()) {
ptrW jid( m_proto->getWStringA(hContact, "jid"));
if (jid != nullptr)
SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_ADDSTRING, 0, jid);
@@ -1304,7 +1304,7 @@ void CJabberDlgPrivacyLists::CListResetOptions(HWND) void CJabberDlgPrivacyLists::CListFilter(HWND)
{
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
char *proto = GetContactProto(hContact);
if (!proto || mir_strcmp(proto, m_proto->m_szModuleName))
if (HANDLE hItem = m_clcClist.FindContact(hContact))
@@ -1361,7 +1361,7 @@ void CJabberDlgPrivacyLists::CListApplyList(HWND hwndList, CPrivacyList *pList) CListResetIcons(hwndList, hItem, bHideIcons);
}
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
HANDLE hItem = m_clcClist.FindContact(hContact);
if (hItem)
CListResetIcons(hwndList, hItem, bHideIcons);
@@ -1459,7 +1459,7 @@ void CJabberDlgPrivacyLists::CListBuildList(HWND hwndList, CPrivacyList *pList) pList->AddRule(Jid, szJid, FALSE, dwOrder++, dwPackets);
}
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
hItem = m_clcClist.FindContact(hContact);
ptrW jid( m_proto->getWStringA(hContact, "jid"));
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index eedaec74af..e75eb2fdfa 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -301,7 +301,7 @@ int CJabberProto::OnModulesLoadedEx(WPARAM, LPARAM) CheckAllContactsAreTransported();
// Set all contacts to offline
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
SetContactOfflineStatus(hContact);
if (getByte(hContact, "IsTransport", 0)) {
diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp index e0201f51ff..5343ea2312 100644 --- a/protocols/JabberG/src/jabber_rc.cpp +++ b/protocols/JabberG/src/jabber_rc.cpp @@ -464,7 +464,7 @@ int CJabberProto::AdhocOptionsHandler(HXML, CJabberIqInfo *pInfo, CJabberAdhocSe int CJabberProto::RcGetUnreadEventsCount()
{
int nEventsSent = 0;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
ptrW jid( getWStringA(hContact, "jid"));
if (jid == nullptr) continue;
@@ -550,7 +550,7 @@ int CJabberProto::AdhocForwardHandler(HXML, CJabberIqInfo *pInfo, CJabberAdhocSe m_bRcMarkMessagesAsRead = bRemoveCListEvents ? 1 : 0;
int nEventsSent = 0;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
ptrW tszJid( getWStringA(hContact, "jid"));
if (tszJid == nullptr)
continue;
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index a8b2b49bd4..dbadaa861f 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -521,7 +521,7 @@ recvRest: // Set all contacts to offline
debugLogA("1");
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ for (auto &hContact : acc_contact_iter())
SetContactOfflineStatus(hContact);
debugLogA("2");
diff --git a/protocols/MRA/src/MraProto.cpp b/protocols/MRA/src/MraProto.cpp index 03cd7f2336..2dd3b590a7 100644 --- a/protocols/MRA/src/MraProto.cpp +++ b/protocols/MRA/src/MraProto.cpp @@ -90,7 +90,7 @@ int CMraProto::OnModulesLoaded(WPARAM, LPARAM) HookProtoEvent(ME_CLIST_GROUPCHANGE, &CMraProto::OnGroupChanged);
// всех в offline // тк unsaved values сохран¤ютс¤ их нужно инициализировать
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact != NULL; hContact = db_find_next(hContact, m_szModuleName))
+ for (auto &hContact : acc_contact_iter())
SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID | SCBIF_GROUP_ID | SCBIF_SERVER_FLAG | SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, nullptr, nullptr, nullptr);
// unsaved values
@@ -462,7 +462,7 @@ int CMraProto::SetStatus(int iNewStatus) // всех в offline, только если мы бывали подключены
if (dwOldStatusMode > ID_STATUS_OFFLINE)
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ for (auto &hContact : acc_contact_iter())
SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID | SCBIF_GROUP_ID | SCBIF_SERVER_FLAG | SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, nullptr, nullptr, nullptr);
if (m_hConnection != nullptr)
diff --git a/protocols/MRA/src/Mra_functions.cpp b/protocols/MRA/src/Mra_functions.cpp index da0902c387..7355eb65b8 100644 --- a/protocols/MRA/src/Mra_functions.cpp +++ b/protocols/MRA/src/Mra_functions.cpp @@ -510,7 +510,7 @@ MCONTACT CMraProto::MraHContactFromEmail(const CMStringA &szEmail, BOOL bAddIfNe //check not already on list
CMStringA szEMailLocal;
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (mraGetStringA(hContact, "e-mail", szEMailLocal))
if (szEMailLocal == szEmail) {
if (bTemporary == FALSE)
diff --git a/protocols/MRA/src/Mra_menus.cpp b/protocols/MRA/src/Mra_menus.cpp index 6d26c956bb..431e42dcea 100644 --- a/protocols/MRA/src/Mra_menus.cpp +++ b/protocols/MRA/src/Mra_menus.cpp @@ -31,7 +31,7 @@ INT_PTR CMraProto::MraUpdateAllUsersInfo(WPARAM, LPARAM) return 0;
if (MessageBox(nullptr, TranslateT("Are you sure?"), TranslateT(MRA_UPD_ALL_USERS_INFO_STR), MB_YESNO | MB_ICONQUESTION) == IDYES) {
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
CMStringA szEmail;
if (mraGetStringA(hContact, "e-mail", szEmail))
MraWPRequestByEMail(hContact, ACKTYPE_GETINFO, szEmail);
@@ -43,7 +43,7 @@ INT_PTR CMraProto::MraUpdateAllUsersInfo(WPARAM, LPARAM) INT_PTR CMraProto::MraCheckUpdatesUsersAvt(WPARAM, LPARAM)
{
if (MessageBox(nullptr, TranslateT("Are you sure?"), TranslateT(MRA_CHK_USERS_AVATARS_STR), MB_YESNO | MB_ICONQUESTION) == IDYES) {
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
CMStringA szEmail;
if (mraGetStringA(hContact, "e-mail", szEmail))
if (!IsEMailChatAgent(szEmail))
@@ -59,7 +59,7 @@ INT_PTR CMraProto::MraRequestAuthForAll(WPARAM, LPARAM) return 0;
if (MessageBox(nullptr, TranslateT("Are you sure?"), TranslateT(MRA_REQ_AUTH_FOR_ALL_STR), MB_YESNO | MB_ICONQUESTION) == IDYES) {
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
DWORD dwContactSeverFlags;
if (GetContactBasicInfoW(hContact, nullptr, nullptr, nullptr, &dwContactSeverFlags, nullptr, nullptr, nullptr, nullptr) == NO_ERROR)
if (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED && dwContactSeverFlags != -1)
diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp index 0cf552080d..ea5663733d 100644 --- a/protocols/MRA/src/Mra_proto.cpp +++ b/protocols/MRA/src/Mra_proto.cpp @@ -1308,7 +1308,7 @@ bool CMraProto::CmdClist2(BinBuffer &buf) if (mraGetStringW(NULL, "AuthMessage", wszAuthMessage) == FALSE) // def auth message
wszAuthMessage = TranslateW(MRA_DEFAULT_AUTH_MESSAGE);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (GetContactBasicInfoW(hContact, &dwID, nullptr, nullptr, nullptr, nullptr, &email, nullptr, nullptr) == NO_ERROR)
if (dwID == -1) {
if (IsEMailChatAgent(email)) {// чат: ещё раз запросим авторизацию, пометим как видимый в списке, постоянный
@@ -1337,7 +1337,7 @@ bool CMraProto::CmdClist2(BinBuffer &buf) }
else { // контакт лист почемуто не получили
// всех в offline и id в нестандарт
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID | SCBIF_GROUP_ID | SCBIF_SERVER_FLAG | SCBIF_STATUS),
-1, -2, 0, 0, ID_STATUS_OFFLINE, nullptr, nullptr, nullptr);
// request user info from server
diff --git a/protocols/MSN/src/msn_chat.cpp b/protocols/MSN/src/msn_chat.cpp index 804cb64951..c484d9f2f6 100644 --- a/protocols/MSN/src/msn_chat.cpp +++ b/protocols/MSN/src/msn_chat.cpp @@ -241,10 +241,9 @@ void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const wchar_t *mChatID void CMsnProto::MSN_GCRefreshThreadsInfo(void)
{
CMStringA buf;
- MCONTACT hContact;
int nThreads = 0;
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (isChatRoom(hContact) != 0) {
DBVARIANT dbv;
if (getString(hContact, "ChatRoomID", &dbv) == 0) {
diff --git a/protocols/MSN/src/msn_contact.cpp b/protocols/MSN/src/msn_contact.cpp index bf9de7dbfd..ae5abebf9d 100644 --- a/protocols/MSN/src/msn_contact.cpp +++ b/protocols/MSN/src/msn_contact.cpp @@ -53,11 +53,7 @@ MCONTACT CMsnProto::MSN_HContactFromEmail(const char* wlid, const char* msnNick, MCONTACT CMsnProto::MSN_HContactFromChatID(const char* wlid)
{
- MCONTACT hContact = NULL;
-
- for (hContact = db_find_first(m_szModuleName); hContact;
- hContact = db_find_next(hContact, m_szModuleName))
- {
+ for (auto &hContact : acc_contact_iter()) {
if (isChatRoom(hContact) != 0) {
DBVARIANT dbv;
if (getString(hContact, "ChatRoomID", &dbv) == 0) {
diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index 78ec94f5dd..8b82cd9231 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -674,11 +674,8 @@ void CMsnProto::MSN_FetchRecentMessages(time_t since) /* Assuming that you want all messages that were sent after the last
* user conversation according to DB
*/
- MCONTACT hContact;
MEVENT hDbEvent;
- for (hContact = db_find_first(m_szModuleName); hContact;
- hContact = db_find_next(hContact, m_szModuleName))
- {
+ for (auto &hContact : acc_contact_iter()) {
if (!(hDbEvent = db_event_last(hContact)))
continue;
diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index d4498913e1..85c2344b32 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -88,7 +88,7 @@ CMsnProto::CMsnProto(const char* aProtoName, const wchar_t* aUserName) : LoadOptions();
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
delSetting(hContact, "Status");
delSetting(hContact, "IdleTS");
delSetting(hContact, "p2pMsgId");
diff --git a/protocols/MinecraftDynmap/src/chat.cpp b/protocols/MinecraftDynmap/src/chat.cpp index 5b5a52cd81..d51d02fcd1 100644 --- a/protocols/MinecraftDynmap/src/chat.cpp +++ b/protocols/MinecraftDynmap/src/chat.cpp @@ -189,7 +189,7 @@ MCONTACT MinecraftDynmapProto::GetChatHandle() /*if (chatHandle_ != NULL) return chatHandle_; - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) > 0) { ptrA id = db_get_sa(hContact, m_szModuleName, "ChatRoomId"); if (id != NULL && !strcmp(id, m_szModuleName)) diff --git a/protocols/Omegle/src/chat.cpp b/protocols/Omegle/src/chat.cpp index 1ff3b69bba..e3ab206286 100644 --- a/protocols/Omegle/src/chat.cpp +++ b/protocols/Omegle/src/chat.cpp @@ -336,7 +336,7 @@ MCONTACT OmegleProto::GetChatHandle() /*if (facy.chatHandle_ != NULL)
return facy.chatHandle_;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) > 0) {
ptrA id = db_get_sa(hContact, m_szModuleName, "ChatRoomId");
if (id != NULL && !mir_strcmp(id, m_szModuleName))
diff --git a/protocols/Sametime/src/sametime.cpp b/protocols/Sametime/src/sametime.cpp index dfb4166223..01770d382c 100644 --- a/protocols/Sametime/src/sametime.cpp +++ b/protocols/Sametime/src/sametime.cpp @@ -223,7 +223,7 @@ void CSametimeProto::SetAllOffline() {
debugLogW(L"SetAllOffline() start");
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0)) {
db_delete_contact(hContact);
continue;
diff --git a/protocols/Sametime/src/session_announce_win.cpp b/protocols/Sametime/src/session_announce_win.cpp index 45c4dffa2d..50f564f1d3 100644 --- a/protocols/Sametime/src/session_announce_win.cpp +++ b/protocols/Sametime/src/session_announce_win.cpp @@ -40,7 +40,7 @@ INT_PTR CALLBACK SessionAnnounceDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wPara lvI.iItem = 0;
lvI.iSubItem = 0;
- for (MCONTACT hContact = db_find_first(proto->m_szModuleName); hContact; hContact = db_find_next(hContact, proto->m_szModuleName)) {
+ for (auto &hContact : proto->acc_contact_iter()) {
if (db_get_b(hContact, proto->m_szModuleName, "ChatRoom", 0) == 0
&& db_get_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) {
lvI.lParam = (LPARAM)hContact;
diff --git a/protocols/Sametime/src/userlist.cpp b/protocols/Sametime/src/userlist.cpp index a61398189a..777d174aa0 100644 --- a/protocols/Sametime/src/userlist.cpp +++ b/protocols/Sametime/src/userlist.cpp @@ -4,7 +4,7 @@ MCONTACT CSametimeProto::FindContactByUserId(const char* id)
{
DBVARIANT dbv;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) {
if (dbv.pszVal && mir_strcmp(id, dbv.pszVal) == 0) {
db_free(&dbv);
@@ -204,7 +204,7 @@ void CSametimeProto::ExportContactsToList(mwSametimeList* user_list) mwIdBlock uid;
GList* gl = nullptr;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) {
if (dbv.pszVal) {
if (GetAwareIdFromContact(hContact, &id_block)) {
@@ -223,7 +223,6 @@ void CSametimeProto::ExportContactsToList(mwSametimeList* user_list) db_free(&dbv);
free(id_block.user);
free(group_alias);
- hContact = db_find_next(hContact, m_szModuleName);
continue;
}
@@ -595,7 +594,7 @@ void CSametimeProto::UserListCreate() mwAwareIdBlock id_block;
GList *gl = nullptr;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) == 0 /*&& proto && !mir_strcmp( PROTO, proto)*/) {
if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) {
if (dbv.pszVal) {
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index bc10cf333f..956624daa9 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -59,12 +59,11 @@ MCONTACT CSkypeProto::GetContactFromAuthEvent(MEVENT hEvent) MCONTACT CSkypeProto::FindContact(const char *skypename)
{
- MCONTACT hContact = NULL;
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter())
if (!mir_strcmpi(skypename, Contacts[hContact]))
- break;
- }
- return hContact;
+ return hContact;
+
+ return 0;
}
MCONTACT CSkypeProto::AddContact(const char *skypename, bool isTemporary)
diff --git a/protocols/SkypeWeb/src/skype_dialogs.cpp b/protocols/SkypeWeb/src/skype_dialogs.cpp index 2af7213b51..6a58c70d38 100644 --- a/protocols/SkypeWeb/src/skype_dialogs.cpp +++ b/protocols/SkypeWeb/src/skype_dialogs.cpp @@ -39,7 +39,7 @@ CSkypeInviteDlg::CSkypeInviteDlg(CSkypeProto *proto) : void CSkypeInviteDlg::OnInitDialog()
{
- for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
+ for (auto &hContact : m_proto->acc_contact_iter()) {
if (!m_proto->isChatRoom(hContact)) {
wchar_t *ptszNick = pcli->pfnGetContactDisplayName(hContact, 0);
m_combo.AddString(ptszNick, hContact);
@@ -77,7 +77,7 @@ void CSkypeGCCreateDlg::OnInitDialog() void CSkypeGCCreateDlg::btnOk_OnOk(CCtrlButton*)
{
- for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
+ for (auto &hContact : m_proto->acc_contact_iter()) {
if (!m_proto->isChatRoom(hContact)) {
if (HANDLE hItem = m_clc.FindContact(hContact)) {
if (m_clc.GetCheck(hItem)) {
@@ -94,7 +94,7 @@ void CSkypeGCCreateDlg::btnOk_OnOk(CCtrlButton*) void CSkypeGCCreateDlg::FilterList(CCtrlClc *)
{
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
char *proto = GetContactProto(hContact);
if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact))
if (HANDLE hItem = m_clc.FindContact(hContact))
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 2f4a4c6d14..cc145420b4 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -232,7 +232,7 @@ void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response) SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), li), &CSkypeProto::OnStatusChanged);
LIST<char> skypenames(1);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ for (auto &hContact : acc_contact_iter())
if (!isChatRoom(hContact))
skypenames.insert(getStringA(hContact, SKYPE_SETTINGS_ID));
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index e3d3c8c9c7..9bdfdc8bf3 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -2,7 +2,7 @@ void CSteamProto::SetAllContactStatuses(int status) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + for (auto &hContact : acc_contact_iter()) SetContactStatus(hContact, status); } @@ -71,7 +71,7 @@ MCONTACT CSteamProto::GetContactFromAuthEvent(MEVENT hEvent) MCONTACT CSteamProto::GetContact(const char *steamId) { - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrA cSteamId(getStringA(hContact, "SteamID")); if (!mir_strcmp(cSteamId, steamId)) return hContact; @@ -428,7 +428,7 @@ void CSteamProto::OnGotFriendList(const JSONNode &root, void*) } // Check and update contacts in database - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { + for (auto &hContact : acc_contact_iter()) { ptrA steamId(getStringA(hContact, "SteamID")); if (steamId == nullptr) continue; diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index ad2ac177e8..2e39986fa8 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -64,7 +64,7 @@ void CToxProto::SetToxAvatar(const wchar_t* path) db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH);
if (IsOnline()) {
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (GetContactStatus(hContact) == ID_STATUS_OFFLINE)
continue;
@@ -162,7 +162,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam) }
if (IsOnline()) {
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (GetContactStatus(hContact) == ID_STATUS_OFFLINE)
continue;
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 5533d78983..7f945bf1a4 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -49,7 +49,7 @@ MCONTACT CToxProto::GetContact(const Tox *tox, const int friendNumber) MCONTACT CToxProto::GetContact(const char *pubKey)
{
MCONTACT hContact = NULL;
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
ptrA contactPubKey(getStringA(hContact, TOX_SETTINGS_ID));
// check only public key part of address
if (mir_strncmpi(pubKey, contactPubKey, TOX_PUBLIC_KEY_SIZE) == 0)
diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp index 3e0ed8e613..2be12c4f20 100644 --- a/protocols/Twitter/src/chat.cpp +++ b/protocols/Twitter/src/chat.cpp @@ -145,7 +145,7 @@ void TwitterProto::SetChatStatus(int status) {
if (status == ID_STATUS_ONLINE) {
// Add all friends to contact list
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (isChatRoom(hContact))
continue;
diff --git a/protocols/Twitter/src/contacts.cpp b/protocols/Twitter/src/contacts.cpp index ff13bdff26..9e5d80c657 100644 --- a/protocols/Twitter/src/contacts.cpp +++ b/protocols/Twitter/src/contacts.cpp @@ -211,7 +211,7 @@ bool TwitterProto::IsMyContact(MCONTACT hContact, bool include_chat) MCONTACT TwitterProto::UsernameToHContact(const char *name)
{
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (getByte(hContact, "ChatRoom"))
continue;
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 07bf5cd0b5..918d9441da 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -158,7 +158,7 @@ wchar_t* CVkProto::GetUserStoredPassword() void CVkProto::SetAllContactStatuses(int iStatus)
{
debugLogA("CVkProto::SetAllContactStatuses (%d)", iStatus);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (isChatRoom(hContact))
SetChatStatus(hContact, iStatus);
else if (getWord(hContact, "Status") != iStatus)
@@ -178,7 +178,7 @@ MCONTACT CVkProto::FindUser(LONG dwUserid, bool bCreate) if (!dwUserid)
return 0;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
LONG dbUserid = getDword(hContact, "ID", VK_INVALID_USER);
if (dbUserid == VK_INVALID_USER)
continue;
@@ -204,7 +204,7 @@ MCONTACT CVkProto::FindChat(LONG dwUserid) if (!dwUserid)
return 0;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
LONG dbUserid = getDword(hContact, "vk_chat_id", VK_INVALID_USER);
if (dbUserid == VK_INVALID_USER)
continue;
diff --git a/protocols/VKontakte/src/vk_dialogs.cpp b/protocols/VKontakte/src/vk_dialogs.cpp index 6e957b7b79..09eb855ccf 100644 --- a/protocols/VKontakte/src/vk_dialogs.cpp +++ b/protocols/VKontakte/src/vk_dialogs.cpp @@ -157,7 +157,7 @@ CVkInviteChatForm::CVkInviteChatForm(CVkProto *proto) : void CVkInviteChatForm::OnInitDialog()
{
- for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
+ for (auto &hContact : m_proto->acc_contact_iter()) {
if (!m_proto->isChatRoom(hContact)) {
wchar_t *pwszNick = pcli->pfnGetContactDisplayName(hContact, 0);
m_cbxCombo.AddString(pwszNick, hContact);
@@ -195,7 +195,7 @@ void CVkGCCreateForm::OnInitDialog() void CVkGCCreateForm::btnOk_OnOk(CCtrlButton*)
{
CMStringA szUIds;
- for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
+ for (auto &hContact : m_proto->acc_contact_iter()) {
if (m_proto->isChatRoom(hContact))
continue;
@@ -219,7 +219,7 @@ void CVkGCCreateForm::btnOk_OnOk(CCtrlButton*) void CVkGCCreateForm::FilterList(CCtrlClc*)
{
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ for (auto &hContact : contact_iter()) {
char *proto = GetContactProto(hContact);
if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact) || m_proto->getDword(hContact, "ID") == VK_FEED_USER)
if (HANDLE hItem = m_clCList.FindContact(hContact))
diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp index 09447ea84f..4781cb4cdb 100644 --- a/protocols/VKontakte/src/vk_history.cpp +++ b/protocols/VKontakte/src/vk_history.cpp @@ -61,7 +61,7 @@ INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM, LPARAM) if (IDNO == MessageBoxW(nullptr, str, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
return 0;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
if (userID == VK_INVALID_USER || userID == VK_FEED_USER)
continue;
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index c7efb61344..044b6e5757 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -550,7 +550,7 @@ void CVkProto::RetrieveUsersInfo(bool bFreeOffline, bool bRepeat) CMStringA userIDs;
int i = 0;
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
if (userID == VK_INVALID_USER || userID == VK_FEED_USER || userID < 0)
continue;
@@ -602,7 +602,7 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe MCONTACT hContact;
LIST<void> arContacts(10, PtrKeySortT);
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ for (auto &hContact : acc_contact_iter())
if (!isChatRoom(hContact) && !IsGroupUser(hContact))
arContacts.insert((HANDLE)hContact);
@@ -755,7 +755,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq LIST<void> arContacts(10, PtrKeySortT);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ for (auto &hContact : acc_contact_iter()) {
if (!isChatRoom(hContact) && !IsGroupUser(hContact))
setByte(hContact, "Auth", 1);
db_unset(hContact, m_szModuleName, "ReqAuth");
|