summaryrefslogtreecommitdiff
path: root/protocols/JabberG
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-04-09 21:40:22 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-04-09 21:40:22 +0000
commit3dc0d9b0b7c30ea2f77d74c4ce5b6ccd67bd525c (patch)
treeefee912ee654baafeb98efcd117921db6b7489bc /protocols/JabberG
parentbcb27264ba737778e5d3edad36088bacf74f0236 (diff)
- the kernel filters out contacts by proto names much faster than a plugin;
- database cycles simplified git-svn-id: http://svn.miranda-ng.org/main/trunk@4404 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/JabberG')
-rw-r--r--protocols/JabberG/src/jabber_chat.cpp25
-rw-r--r--protocols/JabberG/src/jabber_icolib.cpp16
-rw-r--r--protocols/JabberG/src/jabber_iqid.cpp31
-rw-r--r--protocols/JabberG/src/jabber_misc.cpp26
-rw-r--r--protocols/JabberG/src/jabber_opt.cpp57
-rw-r--r--protocols/JabberG/src/jabber_privacy.cpp22
-rw-r--r--protocols/JabberG/src/jabber_proto.cpp31
-rw-r--r--protocols/JabberG/src/jabber_rc.cpp143
-rw-r--r--protocols/JabberG/src/jabber_thread.cpp8
-rw-r--r--protocols/JabberG/src/jabber_util.cpp96
10 files changed, 209 insertions, 246 deletions
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp
index 6a8adbc714..ff98ee0034 100644
--- a/protocols/JabberG/src/jabber_chat.cpp
+++ b/protocols/JabberG/src/jabber_chat.cpp
@@ -817,20 +817,17 @@ public:
HWND hwndList = GetDlgItem(m_hwnd, IDC_CLIST);
// invite users from roster
- 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 (int hItem = SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0))
- {
- if (SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0))
- {
- DBVARIANT dbv={0};
- m_proto->JGetStringT(hContact, "jid", &dbv);
- if (dbv.ptszVal && (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_WCHAR))
- InviteUser(dbv.ptszVal, text);
- db_free(&dbv);
- }
+ for (HANDLE hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
+ if ( db_get_b(hContact, m_proto->m_szModuleName, "ChatRoom", 0))
+ continue;
+
+ if (int hItem = SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0)) {
+ if (SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
+ DBVARIANT dbv={0};
+ m_proto->JGetStringT(hContact, "jid", &dbv);
+ if (dbv.ptszVal && (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_WCHAR))
+ InviteUser(dbv.ptszVal, text);
+ db_free(&dbv);
}
}
}
diff --git a/protocols/JabberG/src/jabber_icolib.cpp b/protocols/JabberG/src/jabber_icolib.cpp
index ea7203bd5d..e1a582c51b 100644
--- a/protocols/JabberG/src/jabber_icolib.cpp
+++ b/protocols/JabberG/src/jabber_icolib.cpp
@@ -462,14 +462,14 @@ BOOL CJabberProto::DBCheckIsTransportedContact(const TCHAR *jid, HANDLE hContact
void CJabberProto::CheckAllContactsAreTransported()
{
- 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);
-} } } }
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ DBVARIANT dbv;
+ if ( !JGetStringT(hContact, "jid", &dbv)) {
+ DBCheckIsTransportedContact(dbv.ptszVal, hContact);
+ db_free(&dbv);
+ }
+ }
+}
/////////////////////////////////////////////////////////////////////////////////////////
// Cross-instance shared icons
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp
index eced1ebbd9..3dbfd2d69d 100644
--- a/protocols/JabberG/src/jabber_iqid.cpp
+++ b/protocols/JabberG/src/jabber_iqid.cpp
@@ -535,24 +535,21 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo* pInfo)
if (m_options.RosterSync == TRUE) {
int listSize = 0, listAllocSize = 0;
HANDLE* list = 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;
- if ( !JGetStringT(hContact, "jid", &dbv)) {
- if ( !ListExist(LIST_ROSTER, dbv.ptszVal)) {
- Log("Syncing roster: preparing to delete %S (hContact=0x%x)", dbv.ptszVal, hContact);
- if (listSize >= listAllocSize) {
- listAllocSize = listSize + 100;
- if ((list=(HANDLE *) mir_realloc(list, listAllocSize * sizeof(HANDLE))) == NULL) {
- listSize = 0;
- break;
- } }
-
- list[listSize++] = hContact;
- }
- db_free(&dbv);
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ DBVARIANT dbv;
+ if ( !JGetStringT(hContact, "jid", &dbv)) {
+ if ( !ListExist(LIST_ROSTER, dbv.ptszVal)) {
+ Log("Syncing roster: preparing to delete %S (hContact=0x%x)", dbv.ptszVal, hContact);
+ if (listSize >= listAllocSize) {
+ listAllocSize = listSize + 100;
+ if ((list=(HANDLE *) mir_realloc(list, listAllocSize * sizeof(HANDLE))) == NULL) {
+ listSize = 0;
+ break;
+ } }
+
+ list[listSize++] = hContact;
}
+ db_free(&dbv);
}
}
diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp
index 10d23186a4..935662d9f6 100644
--- a/protocols/JabberG/src/jabber_misc.cpp
+++ b/protocols/JabberG/src/jabber_misc.cpp
@@ -157,7 +157,6 @@ HANDLE CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, BOOL t
HANDLE hContact;
TCHAR* s, *p, *q;
size_t len;
- char *szProto;
if (jid==NULL || jid[0]=='\0')
return NULL;
@@ -174,18 +173,15 @@ 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
- for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- szProto = GetContactProto(hContact);
- if (szProto!=NULL && !strcmp(m_szModuleName, szProto)) {
- DBVARIANT dbv;
- if ( !JGetStringT(hContact, "jid", &dbv)) {
- p = dbv.ptszVal;
- if (p && _tcslen(p)>=len && (p[len]=='\0'||p[len]=='/') && !_tcsnicmp(p, s, len)) {
- db_free(&dbv);
- break;
- }
+ for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ DBVARIANT dbv;
+ if ( !JGetStringT(hContact, "jid", &dbv)) {
+ p = dbv.ptszVal;
+ if (p && _tcslen(p) >= len && (p[len]=='\0'||p[len]=='/') && !_tcsnicmp(p, s, len)) {
db_free(&dbv);
+ break;
}
+ db_free(&dbv);
}
}
@@ -318,13 +314,9 @@ void CJabberProto::ResolveTransportNicks(const TCHAR *jid)
// Set all contacts to offline
HANDLE hContact = m_ThreadInfo->resolveContact;
if (hContact == NULL)
- hContact = (HANDLE)db_find_first();
-
- for (; hContact != NULL; hContact = db_find_next(hContact)) {
- char *szProto = GetContactProto(hContact);
- if (lstrcmpA(szProto, m_szModuleName))
- continue;
+ hContact = (HANDLE)db_find_first(m_szModuleName);
+ for (; hContact != NULL; hContact = db_find_next(hContact, m_szModuleName)) {
if ( !JGetByte(hContact, "IsTransported", 0))
continue;
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp
index dbe3ca3d1f..e3397736fe 100644
--- a/protocols/JabberG/src/jabber_opt.cpp
+++ b/protocols/JabberG/src/jabber_opt.cpp
@@ -1057,39 +1057,36 @@ void CJabberProto::_RosterHandleGetRequest(HXML node)
}
// now it is require to process whole contact list to add not in roster contacts
- 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');
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, 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);
}
}
rrud.bReadyToDownload = FALSE;
diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp
index 39da2ae3f1..2e4e1bd282 100644
--- a/protocols/JabberG/src/jabber_privacy.cpp
+++ b/protocols/JabberG/src/jabber_privacy.cpp
@@ -432,14 +432,11 @@ public:
SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0);
- 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)) {
- DBVARIANT dbv;
- if ( !m_proto->JGetStringT(hContact, "jid", &dbv)) {
- SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_ADDSTRING, 0, (LPARAM)dbv.ptszVal);
- db_free(&dbv);
- }
+ for (HANDLE hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
+ DBVARIANT dbv;
+ if ( !m_proto->JGetStringT(hContact, "jid", &dbv)) {
+ SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_ADDSTRING, 0, (LPARAM)dbv.ptszVal);
+ db_free(&dbv);
}
}
@@ -1359,12 +1356,9 @@ void CJabberDlgPrivacyLists::CListResetOptions(HWND)
void CJabberDlgPrivacyLists::CListFilter(HWND)
{
- 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))
- m_clcClist.DeleteItem(hItem);
- }
+ for (HANDLE hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName))
+ if (HANDLE hItem = m_clcClist.FindContact(hContact))
+ m_clcClist.DeleteItem(hItem);
}
bool CJabberDlgPrivacyLists::CListIsGroup(HANDLE hGroup)
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 25e9da3411..aa705faea9 100644
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -328,21 +328,22 @@ int CJabberProto::OnModulesLoadedEx(WPARAM, LPARAM)
CheckAllContactsAreTransported();
// Set all contacts to offline
- 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);
-
- if (JGetByte(hContact, "IsTransport", 0)) {
- DBVARIANT dbv;
- if ( !JGetStringT(hContact, "jid", &dbv)) {
- TCHAR* domain = NEWTSTR_ALLOCA(dbv.ptszVal);
- TCHAR* resourcepos = _tcschr(domain, '/');
- if (resourcepos != NULL)
- *resourcepos = '\0';
- m_lstTransports.insert(mir_tstrdup(domain));
- db_free(&dbv);
- } } } }
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ SetContactOfflineStatus(hContact);
+
+ if ( !JGetByte(hContact, "IsTransport", 0))
+ continue;
+
+ DBVARIANT dbv;
+ if ( !JGetStringT(hContact, "jid", &dbv)) {
+ TCHAR* domain = NEWTSTR_ALLOCA(dbv.ptszVal);
+ TCHAR* resourcepos = _tcschr(domain, '/');
+ if (resourcepos != NULL)
+ *resourcepos = '\0';
+ m_lstTransports.insert(mir_tstrdup(domain));
+ db_free(&dbv);
+ }
+ }
CleanLastResourceMap();
return 0;
diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp
index 0081409290..05adbeb2e6 100644
--- a/protocols/JabberG/src/jabber_rc.cpp
+++ b/protocols/JabberG/src/jabber_rc.cpp
@@ -477,31 +477,28 @@ int CJabberProto::AdhocOptionsHandler(HXML, CJabberIqInfo* pInfo, CJabberAdhocSe
int CJabberProto::RcGetUnreadEventsCount()
{
int nEventsSent = 0;
- 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;
- if ( !JGetStringT(hContact, "jid", &dbv)) {
- HANDLE hDbEvent = db_event_firstUnread(hContact);
- while (hDbEvent) {
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.cbBlob = db_event_getBlobSize(hDbEvent);
- if (dbei.cbBlob != -1) {
- dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 1);
- int nGetTextResult = db_event_get(hDbEvent, &dbei);
- if ( !nGetTextResult && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT)) {
- TCHAR* szEventText = DbGetEventTextT(&dbei, CP_ACP);
- if (szEventText) {
- nEventsSent++;
- mir_free(szEventText);
- }
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ DBVARIANT dbv;
+ if ( !JGetStringT(hContact, "jid", &dbv)) {
+ HANDLE hDbEvent = db_event_firstUnread(hContact);
+ while (hDbEvent) {
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.cbBlob = db_event_getBlobSize(hDbEvent);
+ if (dbei.cbBlob != -1) {
+ dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 1);
+ int nGetTextResult = db_event_get(hDbEvent, &dbei);
+ if ( !nGetTextResult && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT)) {
+ TCHAR* szEventText = DbGetEventTextT(&dbei, CP_ACP);
+ if (szEventText) {
+ nEventsSent++;
+ mir_free(szEventText);
}
- mir_free(dbei.pBlob);
}
- hDbEvent = db_event_next(hDbEvent);
+ mir_free(dbei.pBlob);
}
- db_free(&dbv);
+ hDbEvent = db_event_next(hDbEvent);
}
+ db_free(&dbv);
}
}
return nEventsSent;
@@ -571,63 +568,61 @@ int CJabberProto::AdhocForwardHandler(HXML, CJabberIqInfo* pInfo, CJabberAdhocSe
m_options.RcMarkMessagesAsRead = bRemoveCListEvents ? 1 : 0;
int nEventsSent = 0;
- 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;
- if ( !JGetStringT(hContact, "jid", &dbv)) {
- HANDLE hDbEvent = db_event_firstUnread(hContact);
- while (hDbEvent) {
- DBEVENTINFO dbei = { 0 };
- dbei.cbSize = sizeof(dbei);
- dbei.cbBlob = db_event_getBlobSize(hDbEvent);
- if (dbei.cbBlob != -1) {
- dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 1);
- int nGetTextResult = db_event_get(hDbEvent, &dbei);
- if ( !nGetTextResult && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT)) {
- TCHAR* szEventText = DbGetEventTextT(&dbei, CP_ACP);
- if (szEventText) {
- XmlNode msg(_T("message"));
- msg << XATTR(_T("to"), pInfo->GetFrom()) << XATTRID(SerialNext())
- << XCHILD(_T("body"), szEventText);
-
- HXML addressesNode = msg << XCHILDNS(_T("addresses"), _T(JABBER_FEAT_EXT_ADDRESSING));
- TCHAR szOFrom[ JABBER_MAX_JID_LEN ];
- EnterCriticalSection(&m_csLastResourceMap);
- TCHAR *szOResource = FindLastResourceByDbEvent(hDbEvent);
- if (szOResource)
- mir_sntprintf(szOFrom, SIZEOF(szOFrom), _T("%s/%s"), dbv.ptszVal, szOResource);
- else
- mir_sntprintf(szOFrom, SIZEOF(szOFrom), _T("%s"), dbv.ptszVal);
- LeaveCriticalSection(&m_csLastResourceMap);
- addressesNode << XCHILD(_T("address")) << XATTR(_T("type"), _T("ofrom")) << XATTR(_T("jid"), szOFrom);
- addressesNode << XCHILD(_T("address")) << XATTR(_T("type"), _T("oto")) << XATTR(_T("jid"), m_ThreadInfo->fullJID);
-
- time_t ltime = (time_t)dbei.timestamp;
- struct tm *gmt = gmtime(&ltime);
- TCHAR stime[ 512 ];
- wsprintf(stime, _T("%.4i-%.2i-%.2iT%.2i:%.2i:%.2iZ"), gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
- gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
- msg << XCHILDNS(_T("delay"), _T("urn:xmpp:delay")) << XATTR(_T("stamp"), stime);
-
- m_ThreadInfo->send(msg);
-
- nEventsSent++;
-
- db_event_markRead(hContact, hDbEvent);
- if (bRemoveCListEvents)
- CallService(MS_CLIST_REMOVEEVENT, (WPARAM)hContact, (LPARAM)hDbEvent);
-
- mir_free(szEventText);
- }
- }
- mir_free(dbei.pBlob);
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ DBVARIANT dbv;
+ if ( JGetStringT(hContact, "jid", &dbv))
+ continue;
+
+ HANDLE hDbEvent = db_event_firstUnread(hContact);
+ while (hDbEvent) {
+ DBEVENTINFO dbei = { 0 };
+ dbei.cbSize = sizeof(dbei);
+ dbei.cbBlob = db_event_getBlobSize(hDbEvent);
+ if (dbei.cbBlob != -1) {
+ dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 1);
+ int nGetTextResult = db_event_get(hDbEvent, &dbei);
+ if ( !nGetTextResult && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT)) {
+ TCHAR* szEventText = DbGetEventTextT(&dbei, CP_ACP);
+ if (szEventText) {
+ XmlNode msg(_T("message"));
+ msg << XATTR(_T("to"), pInfo->GetFrom()) << XATTRID(SerialNext())
+ << XCHILD(_T("body"), szEventText);
+
+ HXML addressesNode = msg << XCHILDNS(_T("addresses"), _T(JABBER_FEAT_EXT_ADDRESSING));
+ TCHAR szOFrom[ JABBER_MAX_JID_LEN ];
+ EnterCriticalSection(&m_csLastResourceMap);
+ TCHAR *szOResource = FindLastResourceByDbEvent(hDbEvent);
+ if (szOResource)
+ mir_sntprintf(szOFrom, SIZEOF(szOFrom), _T("%s/%s"), dbv.ptszVal, szOResource);
+ else
+ mir_sntprintf(szOFrom, SIZEOF(szOFrom), _T("%s"), dbv.ptszVal);
+ LeaveCriticalSection(&m_csLastResourceMap);
+ addressesNode << XCHILD(_T("address")) << XATTR(_T("type"), _T("ofrom")) << XATTR(_T("jid"), szOFrom);
+ addressesNode << XCHILD(_T("address")) << XATTR(_T("type"), _T("oto")) << XATTR(_T("jid"), m_ThreadInfo->fullJID);
+
+ time_t ltime = (time_t)dbei.timestamp;
+ struct tm *gmt = gmtime(&ltime);
+ TCHAR stime[ 512 ];
+ wsprintf(stime, _T("%.4i-%.2i-%.2iT%.2i:%.2i:%.2iZ"), gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
+ gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
+ msg << XCHILDNS(_T("delay"), _T("urn:xmpp:delay")) << XATTR(_T("stamp"), stime);
+
+ m_ThreadInfo->send(msg);
+
+ nEventsSent++;
+
+ db_event_markRead(hContact, hDbEvent);
+ if (bRemoveCListEvents)
+ CallService(MS_CLIST_REMOVEEVENT, (WPARAM)hContact, (LPARAM)hDbEvent);
+
+ mir_free(szEventText);
}
- hDbEvent = db_event_next(hDbEvent);
}
- db_free(&dbv);
+ mir_free(dbei.pBlob);
}
+ hDbEvent = db_event_next(hDbEvent);
}
+ db_free(&dbv);
}
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 85cc395218..f1331af187 100644
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -595,11 +595,9 @@ recvRest:
JSendBroadcast(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
// Set all contacts to offline
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if ( !lstrcmpA(GetContactProto(hContact), m_szModuleName)) {
- SetContactOfflineStatus(hContact);
- MenuHideSrmmIcon(hContact);
- }
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ SetContactOfflineStatus(hContact);
+ MenuHideSrmmIcon(hContact);
}
mir_free(m_szJabberJID);
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp
index 2f5a02f792..35acf12005 100644
--- a/protocols/JabberG/src/jabber_util.cpp
+++ b/protocols/JabberG/src/jabber_util.cpp
@@ -72,27 +72,23 @@ void CJabberProto::Log(const char* fmt, ...)
HANDLE CJabberProto::ChatRoomHContactFromJID(const TCHAR *jid)
{
if (jid == NULL)
- return (HANDLE)NULL;
+ return NULL;
- HANDLE hContactMatched = 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;
- int result = JGetStringT(hContact, "ChatRoomID", &dbv);
- if (result)
- result = JGetStringT(hContact, "jid", &dbv);
-
- if ( !result) {
- int result;
- result = lstrcmpi(jid, dbv.ptszVal);
- db_free(&dbv);
- if ( !result && JGetByte(hContact, "ChatRoom", 0) != 0) {
- hContactMatched = hContact;
- break;
- } } } }
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ DBVARIANT dbv;
+ int result = JGetStringT(hContact, "ChatRoomID", &dbv);
+ if (result)
+ result = JGetStringT(hContact, "jid", &dbv);
- return hContactMatched;
+ if ( !result) {
+ int result;
+ result = lstrcmpi(jid, dbv.ptszVal);
+ db_free(&dbv);
+ if ( !result && JGetByte(hContact, "ChatRoom", 0) != 0)
+ return hContact;
+ } }
+
+ return NULL;
}
///////////////////////////////////////////////////////////////////////////////
@@ -105,44 +101,40 @@ HANDLE CJabberProto::HContactFromJID(const TCHAR *jid , BOOL bStripResource)
JABBER_LIST_ITEM* item = ListGetItemPtr(LIST_CHATROOM, jid);
- HANDLE hContactMatched = NULL;
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ DBVARIANT dbv;
+ int result;
+ //safer way to check UID (coz some contact have both setting from convert to chat)
+ if (db_get_b(hContact, m_szModuleName, "ChatRoom",0))
+ result = JGetStringT(hContact, "ChatRoomID", &dbv);
+ else
+ result = JGetStringT(hContact, "jid", &dbv);
- 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;
+ if ( !result) {
int result;
- //safer way to check UID (coz some contact have both setting from convert to chat)
- if (db_get_b(hContact, szProto, "ChatRoom",0))
- result = JGetStringT(hContact, "ChatRoomID", &dbv);
- else
- result = JGetStringT(hContact, "jid", &dbv);
-
- if ( !result) {
- int result;
- if (item != NULL)
- result = lstrcmpi(jid, dbv.ptszVal);
- else {
- if (bStripResource == 3) {
- if (JGetByte(hContact, "ChatRoom", 0))
- result = lstrcmpi(jid, dbv.ptszVal); // for chat room we have to have full contact matched
- else if (TRUE)
- result = _tcsnicmp(jid, dbv.ptszVal, _tcslen(dbv.ptszVal));
- else
- result = JabberCompareJids(jid, dbv.ptszVal);
- }
- // most probably it should just look full matching contact
+ if (item != NULL)
+ result = lstrcmpi(jid, dbv.ptszVal);
+ else {
+ if (bStripResource == 3) {
+ if (JGetByte(hContact, "ChatRoom", 0))
+ result = lstrcmpi(jid, dbv.ptszVal); // for chat room we have to have full contact matched
+ else if (TRUE)
+ result = _tcsnicmp(jid, dbv.ptszVal, _tcslen(dbv.ptszVal));
else
- result = lstrcmpi(jid, dbv.ptszVal);
-
+ result = JabberCompareJids(jid, dbv.ptszVal);
}
- db_free(&dbv);
- if ( !result) {
- hContactMatched = hContact;
- break;
- } } } }
+ // most probably it should just look full matching contact
+ else
+ result = lstrcmpi(jid, dbv.ptszVal);
- return hContactMatched;
+ }
+ db_free(&dbv);
+ if ( !result)
+ return hContact;
+ }
+ }
+
+ return NULL;
}
TCHAR* __stdcall JabberNickFromJID(const TCHAR *jid)