From bcb27264ba737778e5d3edad36088bacf74f0236 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 9 Apr 2013 20:03:46 +0000 Subject: - short function names allows to write database loops in one string; - 'continue' operator can be used then; - multiple bugs fixed in clists; - code becomes much more compact; git-svn-id: http://svn.miranda-ng.org/main/trunk@4403 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/src/jabber_chat.cpp | 13 ++----- protocols/JabberG/src/jabber_icolib.cpp | 8 +--- protocols/JabberG/src/jabber_iqid.cpp | 8 ++-- protocols/JabberG/src/jabber_misc.cpp | 8 ++-- protocols/JabberG/src/jabber_opt.cpp | 66 +++++++++++++++----------------- protocols/JabberG/src/jabber_privacy.cpp | 40 ++++++------------- protocols/JabberG/src/jabber_proto.cpp | 18 +++------ protocols/JabberG/src/jabber_rc.cpp | 8 +--- protocols/JabberG/src/jabber_thread.cpp | 8 +--- protocols/JabberG/src/jabber_util.cpp | 17 +++----- 10 files changed, 69 insertions(+), 125 deletions(-) (limited to 'protocols/JabberG/src') diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index 36a4dbcf40..6a8adbc714 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -701,15 +701,13 @@ class CGroupchatInviteDlg : public CJabberDlgBase void FilterList(CCtrlClc *) { - for (HANDLE hContact = db_find_first(); - hContact; - hContact = db_find_next(hContact)) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *proto = GetContactProto(hContact); if (lstrcmpA(proto, m_proto->m_szModuleName) || db_get_b(hContact, proto, "ChatRoom", 0)) if (HANDLE hItem = m_clc.FindContact(hContact)) m_clc.DeleteItem(hItem); - } } + } + } void ResetListOptions(CCtrlClc *) { @@ -819,10 +817,7 @@ public: HWND hwndList = GetDlgItem(m_hwnd, IDC_CLIST); // invite users from roster - for (HANDLE hContact = db_find_first(); - hContact; - hContact = db_find_next(hContact)) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *proto = GetContactProto(hContact); if ( !lstrcmpA(proto, m_proto->m_szModuleName) && !db_get_b(hContact, proto, "ChatRoom", 0)) { diff --git a/protocols/JabberG/src/jabber_icolib.cpp b/protocols/JabberG/src/jabber_icolib.cpp index f727d0ee1f..ea7203bd5d 100644 --- a/protocols/JabberG/src/jabber_icolib.cpp +++ b/protocols/JabberG/src/jabber_icolib.cpp @@ -462,18 +462,14 @@ BOOL CJabberProto::DBCheckIsTransportedContact(const TCHAR *jid, HANDLE hContact void CJabberProto::CheckAllContactsAreTransported() { - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *szProto = GetContactProto(hContact); if ( !lstrcmpA(m_szModuleName, szProto)) { DBVARIANT dbv; if ( !JGetStringT(hContact, "jid", &dbv)) { DBCheckIsTransportedContact(dbv.ptszVal, hContact); db_free(&dbv); - } } - - hContact = db_find_next(hContact); -} } +} } } } ///////////////////////////////////////////////////////////////////////////////////////// // Cross-instance shared icons diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 9d3bb562cf..eced1ebbd9 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -535,8 +535,7 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo* pInfo) if (m_options.RosterSync == TRUE) { int listSize = 0, listAllocSize = 0; HANDLE* list = NULL; - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char* str = GetContactProto(hContact); if (str != NULL && !strcmp(str, m_szModuleName)) { DBVARIANT dbv; @@ -553,9 +552,8 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo* pInfo) list[listSize++] = hContact; } db_free(&dbv); - } } - - hContact = db_find_next(hContact); + } + } } for (i=0; i < listSize; i++) { diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index 4ed270192e..10d23186a4 100644 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -154,6 +154,7 @@ void CJabberProto::DBAddAuthRequest(const TCHAR *jid, const TCHAR *nick) HANDLE CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, BOOL temporary, BOOL stripResource) { + HANDLE hContact; TCHAR* s, *p, *q; size_t len; char *szProto; @@ -173,8 +174,7 @@ HANDLE CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, BOOL t len = _tcslen(s); // We can't use JabberHContactFromJID() here because of the stripResource option - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { + for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { szProto = GetContactProto(hContact); if (szProto!=NULL && !strcmp(m_szModuleName, szProto)) { DBVARIANT dbv; @@ -185,8 +185,8 @@ HANDLE CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, BOOL t break; } db_free(&dbv); - } } - hContact = db_find_next(hContact); + } + } } if (hContact == NULL) { diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index 614baef47f..dbe3ca3d1f 100644 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -1055,47 +1055,41 @@ void CJabberProto::_RosterHandleGetRequest(HXML node) group = xmlGetText(groupNode); _RosterInsertListItem(hList, jid, name, group, subscription, TRUE); } + // now it is require to process whole contact list to add not in roster contacts - { - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) - { - char* str = GetContactProto(hContact); - if (str != NULL && !strcmp(str, m_szModuleName)) - { - DBVARIANT dbv; - if ( !JGetStringT(hContact, "jid", &dbv)) - { - LVFINDINFO lvfi={0}; - lvfi.flags = LVFI_STRING; - lvfi.psz = dbv.ptszVal; - TCHAR *p = _tcschr(dbv.ptszVal,_T('@')); - if (p) { - p = _tcschr(dbv.ptszVal, _T('/')); - if (p) *p = _T('\0'); + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + char* str = GetContactProto(hContact); + if (str != NULL && !strcmp(str, m_szModuleName)) { + DBVARIANT dbv; + if ( !JGetStringT(hContact, "jid", &dbv)) { + LVFINDINFO lvfi={0}; + lvfi.flags = LVFI_STRING; + lvfi.psz = dbv.ptszVal; + TCHAR *p = _tcschr(dbv.ptszVal,_T('@')); + if (p) { + p = _tcschr(dbv.ptszVal, _T('/')); + if (p) *p = _T('\0'); + } + if (ListView_FindItem(hList, -1, &lvfi) == -1) { + TCHAR *jid = mir_tstrdup(dbv.ptszVal); + TCHAR *name = NULL; + TCHAR *group = NULL; + DBVARIANT dbvtemp; + if ( !db_get_ts(hContact, "CList", "MyHandle", &dbvtemp)) { + name = mir_tstrdup(dbvtemp.ptszVal); + db_free(&dbvtemp); } - if (ListView_FindItem(hList, -1, &lvfi) == -1) { - TCHAR *jid = mir_tstrdup(dbv.ptszVal); - TCHAR *name = NULL; - TCHAR *group = NULL; - DBVARIANT dbvtemp; - if ( !db_get_ts(hContact, "CList", "MyHandle", &dbvtemp)) { - name = mir_tstrdup(dbvtemp.ptszVal); - db_free(&dbvtemp); - } - if ( !db_get_ts(hContact, "CList", "Group", &dbvtemp)) { - group = mir_tstrdup(dbvtemp.ptszVal); - db_free(&dbvtemp); - } - _RosterInsertListItem(hList, jid, name, group, NULL, FALSE); - if (jid) mir_free(jid); - if (name) mir_free(name); - if (group) mir_free(group); + if ( !db_get_ts(hContact, "CList", "Group", &dbvtemp)) { + group = mir_tstrdup(dbvtemp.ptszVal); + db_free(&dbvtemp); } - db_free(&dbv); + _RosterInsertListItem(hList, jid, name, group, NULL, FALSE); + if (jid) mir_free(jid); + if (name) mir_free(name); + if (group) mir_free(group); } + db_free(&dbv); } - hContact = db_find_next(hContact); } } rrud.bReadyToDownload = FALSE; diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp index e0c5f041f2..39da2ae3f1 100644 --- a/protocols/JabberG/src/jabber_privacy.cpp +++ b/protocols/JabberG/src/jabber_privacy.cpp @@ -424,8 +424,7 @@ public: return; LRESULT nItemData = SendDlgItemMessage(m_hwnd, IDC_COMBO_TYPE, CB_GETITEMDATA, nCurSel, 0); - switch (nItemData) - { + switch (nItemData) { case Jid: { ShowWindow(GetDlgItem(m_hwnd, IDC_COMBO_VALUES), SW_SHOW); @@ -433,20 +432,15 @@ public: SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0); - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *szProto = GetContactProto(hContact); - if (szProto != NULL && !strcmp(szProto, m_proto->m_szModuleName)) - { + if (szProto != NULL && !strcmp(szProto, m_proto->m_szModuleName)) { DBVARIANT dbv; - if ( !m_proto->JGetStringT(hContact, "jid", &dbv)) - { + if ( !m_proto->JGetStringT(hContact, "jid", &dbv)) { SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_ADDSTRING, 0, (LPARAM)dbv.ptszVal); db_free(&dbv); } } - hContact = db_find_next(hContact); } // append known chatroom jids from bookmarks @@ -1365,10 +1359,7 @@ void CJabberDlgPrivacyLists::CListResetOptions(HWND) void CJabberDlgPrivacyLists::CListFilter(HWND) { - for (HANDLE hContact = db_find_first(); - hContact; - hContact = db_find_next(hContact)) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *proto = GetContactProto(hContact); if ( !proto || lstrcmpA(proto, m_proto->m_szModuleName)) if (HANDLE hItem = m_clcClist.FindContact(hContact)) @@ -1468,12 +1459,10 @@ void CJabberDlgPrivacyLists::CListApplyList(HWND hwndList, CPrivacyList *pList) CListResetIcons(hwndList, hItem, bHideIcons); } - for (HANDLE hContact=db_find_first(); hContact; - hContact=db_find_next(hContact)) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { HANDLE hItem = m_clcClist.FindContact(hContact); - if ( !hItem) continue; - CListResetIcons(hwndList, hItem, bHideIcons); + if (hItem) + CListResetIcons(hwndList, hItem, bHideIcons); } for (int iJid = 0; iJid < clc_info.newJids.getCount(); ++iJid) @@ -1569,8 +1558,7 @@ void CJabberDlgPrivacyLists::CListBuildList(HWND hwndList, CPrivacyList *pList) pList->RemoveAllRules(); - for (int iJid = 0; iJid < clc_info.newJids.getCount(); ++iJid) - { + for (int iJid = 0; iJid < clc_info.newJids.getCount(); ++iJid) { hItem = clc_info.newJids[iJid]->hItem; szJid = clc_info.newJids[iJid]->jid; @@ -1580,16 +1568,13 @@ void CJabberDlgPrivacyLists::CListBuildList(HWND hwndList, CPrivacyList *pList) pList->AddRule(Jid, szJid, FALSE, dwOrder++, dwPackets); } - for (HANDLE hContact=db_find_first(); hContact; - hContact=db_find_next(hContact)) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { hItem = m_clcClist.FindContact(hContact); DBVARIANT dbv = {0}; - if (m_proto->JGetStringT(hContact, "jid", &dbv)) { + if (m_proto->JGetStringT(hContact, "jid", &dbv)) if (m_proto->JGetStringT(hContact, "ChatRoomID", &dbv)) continue; - } szJid = dbv.ptszVal; @@ -1602,8 +1587,7 @@ void CJabberDlgPrivacyLists::CListBuildList(HWND hwndList, CPrivacyList *pList) } // group handles start with 1 (0 is "root") - for (int iGroup = 1; ; ++iGroup) - { + for (int iGroup = 1; ; ++iGroup) { char idstr[33]; _itoa(iGroup-1, idstr, 10); DBVARIANT dbv = {0}; diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index fc296d7c18..25e9da3411 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -307,13 +307,9 @@ int CJabberProto::OnModulesLoadedEx(WPARAM, LPARAM) JHookEvent(ME_MSG_ICONPRESSED, &CJabberProto::OnProcessSrmmIconClick); JHookEvent(ME_MSG_WINDOWEVENT, &CJabberProto::OnProcessSrmmEvent); - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { - char *szProto = GetContactProto(hContact); - if (szProto != NULL && !strcmp(szProto, m_szModuleName)) - MenuHideSrmmIcon(hContact); - hContact = db_find_next(hContact); - } } + for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + MenuHideSrmmIcon(hContact); + } DBEVENTTYPEDESCR dbEventType = {0}; dbEventType.cbSize = sizeof(DBEVENTTYPEDESCR); @@ -332,8 +328,7 @@ int CJabberProto::OnModulesLoadedEx(WPARAM, LPARAM) CheckAllContactsAreTransported(); // Set all contacts to offline - HANDLE hContact = db_find_first(); - while (hContact != NULL) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *szProto = GetContactProto(hContact); if (szProto != NULL && !strcmp(szProto, m_szModuleName)) { SetContactOfflineStatus(hContact); @@ -347,10 +342,7 @@ int CJabberProto::OnModulesLoadedEx(WPARAM, LPARAM) *resourcepos = '\0'; m_lstTransports.insert(mir_tstrdup(domain)); db_free(&dbv); - } } } - - hContact = db_find_next(hContact); - } + } } } } CleanLastResourceMap(); return 0; diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp index 23800fc307..0081409290 100644 --- a/protocols/JabberG/src/jabber_rc.cpp +++ b/protocols/JabberG/src/jabber_rc.cpp @@ -477,8 +477,7 @@ int CJabberProto::AdhocOptionsHandler(HXML, CJabberIqInfo* pInfo, CJabberAdhocSe int CJabberProto::RcGetUnreadEventsCount() { int nEventsSent = 0; - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *szProto = GetContactProto(hContact); if (szProto != NULL && !strcmp(szProto, m_szModuleName)) { DBVARIANT dbv; @@ -504,7 +503,6 @@ int CJabberProto::RcGetUnreadEventsCount() db_free(&dbv); } } - hContact = db_find_next(hContact); } return nEventsSent; } @@ -573,8 +571,7 @@ int CJabberProto::AdhocForwardHandler(HXML, CJabberIqInfo* pInfo, CJabberAdhocSe m_options.RcMarkMessagesAsRead = bRemoveCListEvents ? 1 : 0; int nEventsSent = 0; - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *szProto = GetContactProto(hContact); if (szProto != NULL && !strcmp(szProto, m_szModuleName)) { DBVARIANT dbv; @@ -631,7 +628,6 @@ int CJabberProto::AdhocForwardHandler(HXML, CJabberIqInfo* pInfo, CJabberAdhocSe db_free(&dbv); } } - hContact = db_find_next(hContact); } mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("%d message(s) forwarded"), nEventsSent); diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 3660fbce04..85cc395218 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -595,15 +595,11 @@ recvRest: JSendBroadcast(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); // Set all contacts to offline - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { - if ( !lstrcmpA(GetContactProto(hContact), m_szModuleName)) - { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + if ( !lstrcmpA(GetContactProto(hContact), m_szModuleName)) { SetContactOfflineStatus(hContact); MenuHideSrmmIcon(hContact); } - - hContact = db_find_next(hContact); } mir_free(m_szJabberJID); diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 2a365c562e..2f5a02f792 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -75,8 +75,7 @@ HANDLE CJabberProto::ChatRoomHContactFromJID(const TCHAR *jid) return (HANDLE)NULL; HANDLE hContactMatched = NULL; - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *szProto = GetContactProto(hContact); if (szProto != NULL && !strcmp(m_szModuleName, szProto)) { DBVARIANT dbv; @@ -91,10 +90,7 @@ HANDLE CJabberProto::ChatRoomHContactFromJID(const TCHAR *jid) if ( !result && JGetByte(hContact, "ChatRoom", 0) != 0) { hContactMatched = hContact; break; - } } } - - hContact = db_find_next(hContact); - } + } } } } return hContactMatched; } @@ -110,8 +106,8 @@ HANDLE CJabberProto::HContactFromJID(const TCHAR *jid , BOOL bStripResource) JABBER_LIST_ITEM* item = ListGetItemPtr(LIST_CHATROOM, jid); HANDLE hContactMatched = NULL; - HANDLE hContact = (HANDLE)db_find_first(); - while (hContact != NULL) { + + for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *szProto = GetContactProto(hContact); if (szProto != NULL && !strcmp(m_szModuleName, szProto)) { DBVARIANT dbv; @@ -144,10 +140,7 @@ HANDLE CJabberProto::HContactFromJID(const TCHAR *jid , BOOL bStripResource) if ( !result) { hContactMatched = hContact; break; - } } } - - hContact = db_find_next(hContact); - } + } } } } return hContactMatched; } -- cgit v1.2.3