summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_rc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/JabberG/src/jabber_rc.cpp')
-rw-r--r--protocols/JabberG/src/jabber_rc.cpp92
1 files changed, 46 insertions, 46 deletions
diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp
index 9cfc9aceb3..aa660ff8ff 100644
--- a/protocols/JabberG/src/jabber_rc.cpp
+++ b/protocols/JabberG/src/jabber_rc.cpp
@@ -554,60 +554,60 @@ int CJabberProto::AdhocForwardHandler(HXML, CJabberIqInfo* pInfo, CJabberAdhocSe
int nEventsSent = 0;
for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- DBVARIANT dbv;
- if ( getTString(hContact, "jid", &dbv))
+ ptrT tszJid( getTStringA(hContact, "jid"));
+ if (tszJid == NULL)
continue;
- HANDLE hDbEvent = db_event_firstUnread(hContact);
- while (hDbEvent) {
- DBEVENTINFO dbei = { 0 };
- dbei.cbSize = sizeof(dbei);
+ for (HANDLE hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(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) {
- XmlNode msg(_T("message"));
- msg << XATTR(_T("to"), pInfo->GetFrom()) << XATTRID(SerialNext())
- << XCHILD(_T("body"), szEventText);
-
- HXML addressesNode = msg << XCHILDNS(_T("addresses"), 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];
- mir_sntprintf(stime, SIZEOF(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);
+ if (dbei.cbBlob == -1)
+ continue;
- nEventsSent++;
+ mir_ptr<BYTE> pEventBuf((PBYTE)mir_alloc(dbei.cbBlob + 1));
+ dbei.pBlob = pEventBuf;
+ if ( db_event_get(hDbEvent, &dbei))
+ continue;
- db_event_markRead(hContact, hDbEvent);
- if (bRemoveCListEvents)
- CallService(MS_CLIST_REMOVEEVENT, (WPARAM)hContact, (LPARAM)hDbEvent);
+ if (dbei.eventType != EVENTTYPE_MESSAGE || (dbei.flags & (DBEF_READ | DBEF_SENT)))
+ continue;
- mir_free(szEventText);
- }
- }
- mir_free(dbei.pBlob);
+ ptrT szEventText( DbGetEventTextT(&dbei, CP_ACP));
+ if (szEventText == NULL)
+ continue;
+
+ XmlNode msg(_T("message"));
+ msg << XATTR(_T("to"), pInfo->GetFrom()) << XATTRID(SerialNext())
+ << XCHILD(_T("body"), szEventText);
+
+ HXML addressesNode = msg << XCHILDNS(_T("addresses"), JABBER_FEAT_EXT_ADDRESSING);
+ TCHAR szOFrom[JABBER_MAX_JID_LEN];
+
+ size_t cbBlob = strlen((LPSTR)dbei.pBlob)+1;
+ if (cbBlob < dbei.cbBlob) { // rest of message contains a sender's resource
+ ptrT szOResource( mir_utf8decodeT((LPSTR)dbei.pBlob + cbBlob+1));
+ mir_sntprintf(szOFrom, SIZEOF(szOFrom), _T("%s/%s"), tszJid, szOResource);
}
- hDbEvent = db_event_next(hDbEvent);
+ else mir_sntprintf(szOFrom, SIZEOF(szOFrom), _T("%s"), tszJid);
+
+ 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];
+ mir_sntprintf(stime, SIZEOF(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);
}
- db_free(&dbv);
}
mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("%d message(s) forwarded"), nEventsSent);