From d7c9eb34f80f207efd47d2fc65e31aedf166c323 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 5 Jun 2021 17:50:34 +0300 Subject: major code cleaning in regard to db_event_getBlobSize & event memory allocation --- protocols/JabberG/src/jabber_proto.cpp | 24 ++++++------------------ protocols/JabberG/src/jabber_rc.cpp | 23 ++++++----------------- protocols/JabberG/src/jabber_thread.cpp | 17 +++++------------ 3 files changed, 17 insertions(+), 47 deletions(-) (limited to 'protocols/JabberG/src') diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 1ab7f3588a..cb222192d8 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -383,11 +383,8 @@ MCONTACT CJabberProto::AddToListByEvent(int flags, int /*iContact*/, MEVENT hDbE { debugLogA("AddToListByEvent"); - DBEVENTINFO dbei = {}; - if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) - return 0; - if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == nullptr) - return 0; + DB::EventInfo dbei; + dbei.cbBlob = -1; if (db_event_get(hDbEvent, &dbei)) return 0; if (mir_strcmp(dbei.szModule, m_szModuleName)) @@ -407,11 +404,8 @@ int CJabberProto::Authorize(MEVENT hDbEvent) if (!m_bJabberOnline) return 1; - DBEVENTINFO dbei = {}; - if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) - return 1; - if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == nullptr) - return 1; + DB::EventInfo dbei; + dbei.cbBlob = -1; if (db_event_get(hDbEvent, &dbei)) return 1; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) @@ -450,14 +444,8 @@ int CJabberProto::AuthDeny(MEVENT hDbEvent, const wchar_t*) debugLogA("Entering AuthDeny"); - DBEVENTINFO dbei = {}; - if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) - return 1; - - mir_ptr pBlob((PBYTE)mir_alloc(dbei.cbBlob)); - if ((dbei.pBlob = pBlob) == nullptr) - return 1; - + DB::EventInfo dbei; + dbei.cbBlob = -1; if (db_event_get(hDbEvent, &dbei)) return 1; diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp index 8e559e2594..0a1f196cfd 100644 --- a/protocols/JabberG/src/jabber_rc.cpp +++ b/protocols/JabberG/src/jabber_rc.cpp @@ -449,21 +449,15 @@ int CJabberProto::RcGetUnreadEventsCount() if (jid == nullptr) continue; for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if (dbei.cbBlob == -1) - continue; + DB::EventInfo dbei; + 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)) { - wchar_t *szEventText = DbEvent_GetTextW(&dbei, CP_ACP); - if (szEventText) { + ptrW szEventText(DbEvent_GetTextW(&dbei, CP_ACP)); + if (szEventText) nEventsSent++; - mir_free(szEventText); - } } - mir_free(dbei.pBlob); } } return nEventsSent; @@ -531,13 +525,8 @@ int CJabberProto::AdhocForwardHandler(const TiXmlElement*, CJabberIqInfo *pInfo, continue; for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if (dbei.cbBlob == -1) - continue; - - mir_ptr pEventBuf((PBYTE)mir_alloc(dbei.cbBlob + 1)); - dbei.pBlob = pEventBuf; + DB::EventInfo dbei; + dbei.cbBlob = -1; if (db_event_get(hDbEvent, &dbei)) continue; diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index bd85a439c9..7e4a20b731 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -980,18 +980,11 @@ DWORD JabberGetLastContactMessageTime(MCONTACT hContact) if (!hDbEvent) return 0; - DWORD dwTime = 0; - - DBEVENTINFO 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) - dwTime = dbei.timestamp; - mir_free(dbei.pBlob); - } - return dwTime; + DB::EventInfo dbei; + if (!db_event_get(hDbEvent, &dbei)) + return dbei.timestamp; + + return 0; } MCONTACT CJabberProto::CreateTemporaryContact(const char *szJid, JABBER_LIST_ITEM* chatItem) -- cgit v1.2.3