From 90ac4c689e1322b48f6ca53a0c8fff81daf73c9c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 10 Apr 2023 18:50:46 +0300 Subject: code cleaning --- include/m_database.h | 17 +++++++------ libs/win32/mir_app.lib | Bin 241120 -> 241856 bytes libs/win64/mir_app.lib | Bin 238072 -> 238824 bytes plugins/AutoShutdown/src/watcher.cpp | 5 ++-- plugins/AvatarHistory/src/AvatarDlg.cpp | 5 ++-- plugins/Boltun/src/boltun.cpp | 4 +--- plugins/ContactsPlus/src/receive.cpp | 4 +--- plugins/DbChecker/src/worker.cpp | 6 ++--- plugins/HistoryLinkListPlus/src/linklist.cpp | 5 +--- plugins/HistoryLinkListPlus/src/linklist_fct.cpp | 19 +++++---------- plugins/IEView/src/HTMLBuilder.cpp | 5 ++-- plugins/MirandaG15/src/CAppletManager.cpp | 29 +++++++++++------------ plugins/Msg_Export/src/utils.cpp | 5 ++-- plugins/NewEventNotify/src/popup.cpp | 5 +--- plugins/NewStory/src/history.cpp | 5 ++-- plugins/Scriver/src/msgdialog.cpp | 5 ++-- plugins/Scriver/src/msglog.cpp | 5 ++-- plugins/StopSpamMod/src/stopspam.cpp | 5 ++-- plugins/StopSpamPlus/src/events.cpp | 5 ++-- plugins/Variables/src/parse_miranda.cpp | 8 ++----- plugins/YARelay/src/main.cpp | 4 +--- plugins/wbOSD/src/events.cpp | 5 ++-- protocols/JabberG/src/jabber_proto.cpp | 15 +++++------- protocols/JabberG/src/jabber_rc.cpp | 12 ++++------ protocols/JabberG/src/jabber_thread.cpp | 7 ++---- protocols/SkypeWeb/src/skype_db.cpp | 5 ++-- protocols/SkypeWeb/src/skype_proto.cpp | 5 ++-- protocols/Steam/src/steam_proto.cpp | 5 ++-- protocols/VKontakte/src/misc.cpp | 5 +--- src/core/stdfile/src/filerecvdlg.cpp | 5 ++-- src/core/stdmsg/src/msglog.cpp | 5 ++-- src/core/stduihist/src/history.cpp | 5 ++-- src/mir_app/src/auth.cpp | 8 ++----- src/mir_app/src/chat_svc.cpp | 5 ++-- src/mir_app/src/db_events.cpp | 21 ++++++++++++++++ src/mir_app/src/mir_app.def | 3 +++ src/mir_app/src/mir_app64.def | 3 +++ src/mir_app/src/srmm_base.cpp | 5 ++-- 38 files changed, 115 insertions(+), 150 deletions(-) diff --git a/include/m_database.h b/include/m_database.h index 14c0c9fa1b..157046603f 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -681,17 +681,16 @@ namespace DB ///////////////////////////////////////////////////////////////////////////////////////// // Helper to free event contents automatically - struct EventInfo : public DBEVENTINFO + class MIR_APP_EXPORT EventInfo : public DBEVENTINFO, public MNonCopyable { - __forceinline explicit EventInfo() - { - memset(this, 0, sizeof(*this)); - } + bool bValid; - __forceinline ~EventInfo() - { - mir_free(pBlob); - } + public: + explicit EventInfo(); + explicit EventInfo(MEVENT, bool bFetchBlob = true); + ~EventInfo(); + + __forceinline operator bool() const { return bValid; } }; ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 5a657dcb1b..eb18497880 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index 2dae456529..d116c8f346 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/AutoShutdown/src/watcher.cpp b/plugins/AutoShutdown/src/watcher.cpp index 17ced0e11a..271e619180 100644 --- a/plugins/AutoShutdown/src/watcher.cpp +++ b/plugins/AutoShutdown/src/watcher.cpp @@ -64,9 +64,8 @@ static void __inline ShutdownAndStopWatcher(void) static int MsgEventAdded(WPARAM, LPARAM hDbEvent) { if (currentWatcherType & SDWTF_MESSAGE) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 0; if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_SENT)) { diff --git a/plugins/AvatarHistory/src/AvatarDlg.cpp b/plugins/AvatarHistory/src/AvatarDlg.cpp index 8a76311ffa..11da22cfb6 100644 --- a/plugins/AvatarHistory/src/AvatarDlg.cpp +++ b/plugins/AvatarHistory/src/AvatarDlg.cpp @@ -412,9 +412,8 @@ int FillAvatarListFromDB(HWND list, MCONTACT hContact) int max_pos = 0; DB::ECPTR pCursor(DB::Events(hContact)); while (MEVENT hDbEvent = pCursor.FetchNext()) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) continue; if (dbei.eventType != EVENTTYPE_AVATAR_CHANGE) continue; diff --git a/plugins/Boltun/src/boltun.cpp b/plugins/Boltun/src/boltun.cpp index 95de2e9443..beaee86406 100644 --- a/plugins/Boltun/src/boltun.cpp +++ b/plugins/Boltun/src/boltun.cpp @@ -195,9 +195,7 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) if (!BoltunAutoChat(hContact)) return 0; - DB::EventInfo dbei; - dbei.cbBlob = -1; - db_event_get(hDbEvent, &dbei); + DB::EventInfo dbei(hDbEvent); if (dbei.flags & DBEF_SENT || dbei.flags & DBEF_READ || dbei.eventType != EVENTTYPE_MESSAGE) return 0; diff --git a/plugins/ContactsPlus/src/receive.cpp b/plugins/ContactsPlus/src/receive.cpp index f3b0f2355b..2c122ea09c 100644 --- a/plugins/ContactsPlus/src/receive.cpp +++ b/plugins/ContactsPlus/src/receive.cpp @@ -196,9 +196,7 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara RebuildGroupCombo(hwndDlg); { // fill listview with received contacts - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(wndData->mhDbEvent, &dbe); + DB::EventInfo dbe(wndData->mhDbEvent); char* pcBlob = (char*)dbe.pBlob; char* pcEnd = (char*)dbe.pBlob + dbe.cbBlob; diff --git a/plugins/DbChecker/src/worker.cpp b/plugins/DbChecker/src/worker.cpp index e5590bb127..c2e458a921 100644 --- a/plugins/DbChecker/src/worker.cpp +++ b/plugins/DbChecker/src/worker.cpp @@ -90,10 +90,8 @@ void __cdecl WorkerThread(DbToolOptions *opts) DB::ECPTR pCursor(DB::Events(cc)); DBEVENTINFO dboldev = {}; while (MEVENT hEvent = pCursor.FetchNext()) { - DB::EventInfo dbei; - if (opts->bCheckUtf || opts->bCheckDups) // read also event's body - dbei.cbBlob = -1; - if (db_event_get(hEvent, &dbei)) + DB::EventInfo dbei(hEvent, opts->bCheckUtf || opts->bCheckDups); + if (!dbei) continue; if (opts->bMarkRead && !dbei.markedRead()) { diff --git a/plugins/HistoryLinkListPlus/src/linklist.cpp b/plugins/HistoryLinkListPlus/src/linklist.cpp index 016724e8fe..69cd060b33 100644 --- a/plugins/HistoryLinkListPlus/src/linklist.cpp +++ b/plugins/HistoryLinkListPlus/src/linklist.cpp @@ -90,10 +90,7 @@ static INT_PTR LinkList_Main(WPARAM hContact, LPARAM) memset(listStart, 0, sizeof(LISTELEMENT)); do { - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(hEvent, &dbe); - + DB::EventInfo dbe(hEvent); if (dbe.eventType == EVENTTYPE_MESSAGE) { // Call function to find URIs if (ExtractURI(&dbe, hEvent, listStart) < 0) { diff --git a/plugins/HistoryLinkListPlus/src/linklist_fct.cpp b/plugins/HistoryLinkListPlus/src/linklist_fct.cpp index 406ce734be..4b4736ea53 100644 --- a/plugins/HistoryLinkListPlus/src/linklist_fct.cpp +++ b/plugins/HistoryLinkListPlus/src/linklist_fct.cpp @@ -380,9 +380,7 @@ void WriteLinkList(HWND hDlg, uint8_t params, LISTELEMENT *listStart, LPCTSTR se // Perform deep scan if (actualElement->hEvent != NULL) { - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(actualElement->hEvent, &dbe); + DB::EventInfo dbe(actualElement->hEvent); ptrW msg(DbEvent_GetTextW(&dbe, CP_ACP)); if (wcsstr(msg, searchString)) @@ -610,11 +608,9 @@ void WriteMessage(HWND hDlg, LISTELEMENT *listStart, int actLinePos) if (actualElement->linePos == actLinePos) { MEVENT hEvent = actualElement->hEvent; if (hEvent != NULL) { - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(hEvent, &dbe); - SetDlgItemTextW(hDlg, IDC_MESSAGE, L""); + + DB::EventInfo dbe(hEvent); SendDlgItemMessage(hDlg, IDC_MESSAGE, EM_REPLACESEL, FALSE, ptrW(DbEvent_GetTextW(&dbe, CP_ACP))); } break; @@ -763,9 +759,7 @@ void GetListInfo(uint8_t params, LISTELEMENT *listStart, LPCTSTR searchString, s // Perform deep scan if (actualElement->hEvent != NULL) { - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(actualElement->hEvent, &dbe); + DB::EventInfo dbe(actualElement->hEvent); if (wcsstr((LPTSTR)dbe.pBlob, searchString)) filter3 = 1; @@ -1165,9 +1159,8 @@ int DBUpdate(WPARAM wParam, LPARAM hEvent) return 0; if (hDlg) { - DB::EventInfo dbe; - dbe.cbBlob = -1; - if (db_event_get(hEvent, &dbe)) + DB::EventInfo dbe(hEvent); + if (!dbe) return 0; if (dbe.eventType == EVENTTYPE_MESSAGE) { diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp index e61573164e..c853a9b97e 100644 --- a/plugins/IEView/src/HTMLBuilder.cpp +++ b/plugins/IEView/src/HTMLBuilder.cpp @@ -198,9 +198,8 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) newEvent.hwnd = event->hwnd; for (int eventIdx = 0; hDbEvent != NULL && (eventIdx < event->count || event->count == -1); eventIdx++) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (!dbei) { hDbEvent = db_event_next(event->hContact, hDbEvent); continue; } diff --git a/plugins/MirandaG15/src/CAppletManager.cpp b/plugins/MirandaG15/src/CAppletManager.cpp index 62bd9e5ab9..61135eac38 100644 --- a/plugins/MirandaG15/src/CAppletManager.cpp +++ b/plugins/MirandaG15/src/CAppletManager.cpp @@ -791,41 +791,40 @@ void CAppletManager::MarkMessageAsRead(MCONTACT hContact, MEVENT hEvent) //************************************************************************ bool CAppletManager::TranslateDBEvent(CEvent *pEvent, WPARAM hContact, LPARAM hdbevent) { - // Create struct for dbevent - DB::EventInfo dbevent; - dbevent.cbBlob = -1; - if (db_event_get(hdbevent, &dbevent) != 0) + // Create struct for event + DB::EventInfo dbei(hdbevent); + if (!dbei) return false; - pEvent->dwFlags = dbevent.flags; + pEvent->dwFlags = dbei.flags; pEvent->hContact = hContact; pEvent->hValue = hdbevent; - time_t timestamp = (time_t)dbevent.timestamp; + time_t timestamp = (time_t)dbei.timestamp; localtime_s(&pEvent->Time, ×tamp); pEvent->bTime = true; // Skip events from the user except for messages - if (dbevent.eventType != EVENTTYPE_MESSAGE && (dbevent.flags & DBEF_SENT)) + if (dbei.eventType != EVENTTYPE_MESSAGE && (dbei.flags & DBEF_SENT)) return false; int msglen = 0; tstring strName = CAppletManager::GetContactDisplayname(hContact, true); - switch (dbevent.eventType) { + switch (dbei.eventType) { case EVENTTYPE_MESSAGE: - msglen = (int)mir_strlen((char *)dbevent.pBlob) + 1; - if (dbevent.flags & DBEF_UTF) { - pEvent->strValue = Utf8_Decode((char*)dbevent.pBlob); + msglen = (int)mir_strlen((char *)dbei.pBlob) + 1; + if (dbei.flags & DBEF_UTF) { + pEvent->strValue = Utf8_Decode((char*)dbei.pBlob); } - else if ((int)dbevent.cbBlob == msglen * 3) { - pEvent->strValue = (wchar_t *)& dbevent.pBlob[msglen]; + else if ((int)dbei.cbBlob == msglen * 3) { + pEvent->strValue = (wchar_t *)& dbei.pBlob[msglen]; } else { - pEvent->strValue = toTstring((char*)dbevent.pBlob); + pEvent->strValue = toTstring((char*)dbei.pBlob); } - pEvent->eType = (dbevent.flags & DBEF_SENT) ? EVENT_MSG_SENT : EVENT_MSG_RECEIVED; + pEvent->eType = (dbei.flags & DBEF_SENT) ? EVENT_MSG_SENT : EVENT_MSG_RECEIVED; if (pEvent->eType == EVENT_MSG_RECEIVED) { pEvent->dwFlags = MSG_UNREAD; if (CConfig::GetBoolSetting(NOTIFY_MESSAGES)) diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 75c751a47c..6efee874e7 100644 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -975,9 +975,8 @@ bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, const wstrin { bool result = true; - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (!db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (dbei) { if (db_mc_isMeta(hContact)) hContact = db_event_getContact(hDbEvent); diff --git a/plugins/NewEventNotify/src/popup.cpp b/plugins/NewEventNotify/src/popup.cpp index 4da66331b7..535e981af9 100644 --- a/plugins/NewEventNotify/src/popup.cpp +++ b/plugins/NewEventNotify/src/popup.cpp @@ -435,10 +435,7 @@ int PopupUpdate(PLUGIN_DATA &pdata, MEVENT hEvent) wszText.AppendChar('\n'); // get DBEVENTINFO with pBlob if preview is needed (when is test then is off) - DB::EventInfo dbe; - if (g_plugin.bPreview) - dbe.cbBlob = -1; - db_event_get(pdata.events[i], &dbe); + DB::EventInfo dbe(pdata.events[i], g_plugin.bPreview); CMStringW wszFormat; if (g_plugin.bShowDate) diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index 040f67e2c4..54fd1092e7 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -709,9 +709,8 @@ public: bool bAppendOnly = false; DB::ECPTR pCursor(DB::Events(m_hContact)); while (MEVENT hDbEvent = pCursor.FetchNext()) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (!db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (dbei) { if (bAppendOnly) { SetFilePointer(hFile, -3, nullptr, FILE_END); WriteFile(hFile, ",", 1, &dwBytesWritten, nullptr); diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 4f65a5cd52..4c6c1f9af0 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -430,9 +430,8 @@ void CMsgDialog::onClick_Quote(CCtrlButton*) mir_free(buffer); } else { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(m_hDbEventLast, &dbei)) + DB::EventInfo dbei(m_hDbEventLast); + if (!dbei) return; if (DbEventIsMessageOrCustom(&dbei)) { diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index ea8dbd2747..f191432ba4 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -78,9 +78,8 @@ bool DbEventIsShown(const DBEVENTINFO &dbei) EventData* CMsgDialog::GetEventFromDB(MCONTACT hContact, MEVENT hDbEvent) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return nullptr; if (!DbEventIsShown(dbei)) diff --git a/plugins/StopSpamMod/src/stopspam.cpp b/plugins/StopSpamMod/src/stopspam.cpp index 25a25506a3..4b52c0b6e5 100644 --- a/plugins/StopSpamMod/src/stopspam.cpp +++ b/plugins/StopSpamMod/src/stopspam.cpp @@ -19,9 +19,8 @@ int OnDbEventAdded(WPARAM hContact, LPARAM hDbEvent) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 0; // if event is in protocol that is not despammed diff --git a/plugins/StopSpamPlus/src/events.cpp b/plugins/StopSpamPlus/src/events.cpp index 08da0fbf42..fcea573c55 100644 --- a/plugins/StopSpamPlus/src/events.cpp +++ b/plugins/StopSpamPlus/src/events.cpp @@ -4,9 +4,8 @@ int OnDbEventAdded(WPARAM, LPARAM lParam) { MEVENT hDbEvent = (MEVENT)lParam; - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 0; // if event is in protocol that is not despammed diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index 72cf34604e..8996cbbc46 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -564,12 +564,8 @@ static wchar_t* parseDbEvent(ARGUMENTSINFO *ai) if (hDbEvent == NULL) return nullptr; - DB::EventInfo dbe; - dbe.cbBlob = -1; - if (db_event_get(hDbEvent, &dbe)) - return nullptr; - - return DbEvent_GetTextW(&dbe, CP_ACP); + DB::EventInfo dbe(hDbEvent); + return (dbe) ? DbEvent_GetTextW(&dbe, CP_ACP) : nullptr; } static wchar_t* parseTranslate(ARGUMENTSINFO *ai) diff --git a/plugins/YARelay/src/main.cpp b/plugins/YARelay/src/main.cpp index 7f2f1f607f..472f3e17d8 100644 --- a/plugins/YARelay/src/main.cpp +++ b/plugins/YARelay/src/main.cpp @@ -113,9 +113,7 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDBEvent) return 0; // receive message from DB - DB::EventInfo dbei; - dbei.cbBlob = -1; - db_event_get(hDBEvent, &dbei); + DB::EventInfo dbei(hDBEvent); if (dbei.flags & DBEF_SENT || dbei.flags & DBEF_READ || (dbei.eventType != EVENTTYPE_MESSAGE)) return 0; diff --git a/plugins/wbOSD/src/events.cpp b/plugins/wbOSD/src/events.cpp index 993ece3475..f456b4aab1 100644 --- a/plugins/wbOSD/src/events.cpp +++ b/plugins/wbOSD/src/events.cpp @@ -129,9 +129,8 @@ int ContactStatusChanged(WPARAM wParam, LPARAM lParam) int HookedNewEvent(WPARAM wParam, LPARAM hDBEvent) { logmsg("HookedNewEvent1"); - DB::EventInfo dbe; - dbe.cbBlob = -1; - if (db_event_get(hDBEvent, &dbe)) + DB::EventInfo dbe(hDBEvent); + if (!dbe) return 0; if (dbe.flags & DBEF_SENT) diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 282672e4ea..9891bfd60f 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -402,9 +402,8 @@ MCONTACT CJabberProto::AddToListByEvent(int flags, int /*iContact*/, MEVENT hDbE { debugLogA("AddToListByEvent"); - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 0; if (mir_strcmp(dbei.szModule, m_szModuleName)) return 0; @@ -423,9 +422,8 @@ int CJabberProto::Authorize(MEVENT hDbEvent) if (!m_bJabberOnline) return 1; - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 1; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1; @@ -463,9 +461,8 @@ int CJabberProto::AuthDeny(MEVENT hDbEvent, const wchar_t*) debugLogA("Entering AuthDeny"); - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 1; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp index 27d389cee3..983683ec43 100644 --- a/protocols/JabberG/src/jabber_rc.cpp +++ b/protocols/JabberG/src/jabber_rc.cpp @@ -449,11 +449,8 @@ int CJabberProto::RcGetUnreadEventsCount() if (jid == nullptr) continue; for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - - int nGetTextResult = db_event_get(hDbEvent, &dbei); - if (!nGetTextResult && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT)) { + DB::EventInfo dbei(hDbEvent); + if (dbei && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT)) { ptrW szEventText(DbEvent_GetTextW(&dbei, CP_ACP)); if (szEventText) nEventsSent++; @@ -525,9 +522,8 @@ int CJabberProto::AdhocForwardHandler(const TiXmlElement*, CJabberIqInfo *pInfo, continue; for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) continue; if (dbei.eventType != EVENTTYPE_MESSAGE || (dbei.flags & (DBEF_READ | DBEF_SENT))) diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 02a5bc4b28..1475657ecb 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -989,11 +989,8 @@ uint32_t JabberGetLastContactMessageTime(MCONTACT hContact) if (!hDbEvent) return 0; - DB::EventInfo dbei; - if (!db_event_get(hDbEvent, &dbei)) - return dbei.timestamp; - - return 0; + DB::EventInfo dbei(hDbEvent, false); + return (dbei) ? dbei.timestamp : 0; } MCONTACT CJabberProto::CreateTemporaryContact(const char *szJid, JABBER_LIST_ITEM *chatItem) diff --git a/protocols/SkypeWeb/src/skype_db.cpp b/protocols/SkypeWeb/src/skype_db.cpp index 8d815088d1..47a8272777 100644 --- a/protocols/SkypeWeb/src/skype_db.cpp +++ b/protocols/SkypeWeb/src/skype_db.cpp @@ -59,9 +59,8 @@ void CSkypeProto::EditEvent(MCONTACT hContact, MEVENT hEvent, const CMStringW &s { mir_cslock lck(m_AppendMessageLock); - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hEvent, &dbei)) + DB::EventInfo dbei(hEvent); + if (!dbei) return; JSONNode jMsg = JSONNode::parse((char*)dbei.pBlob); diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index f146b1ebdf..b365b6a1ef 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -169,9 +169,8 @@ MCONTACT CSkypeProto::AddToListByEvent(int, int, MEVENT hDbEvent) { debugLogA(__FUNCTION__); - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return NULL; if (mir_strcmp(dbei.szModule, m_szModuleName)) return NULL; diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index 5f42e3ebe2..f64600bfa0 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -106,9 +106,8 @@ MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT *psr) MCONTACT CSteamProto::AddToListByEvent(int, int, MEVENT hDbEvent) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 0; if (mir_strcmp(dbei.szModule, m_szModuleName)) return 0; diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 5b5a548350..bd918b7b93 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -1770,10 +1770,7 @@ MEVENT CVkProto::GetMessageFromDb(const char *messageId, UINT ×tamp, CMStri if (!hDbEvent) return 0; - DB::EventInfo dbei; - dbei.cbBlob = -1; - db_event_get(hDbEvent, &dbei); - + DB::EventInfo dbei(hDbEvent); msg = ptrW(mir_utf8decodeW((char*)dbei.pBlob)); timestamp = dbei.timestamp; diff --git a/src/core/stdfile/src/filerecvdlg.cpp b/src/core/stdfile/src/filerecvdlg.cpp index 760633e225..29e0a7f53c 100644 --- a/src/core/stdfile/src/filerecvdlg.cpp +++ b/src/core/stdfile/src/filerecvdlg.cpp @@ -243,9 +243,8 @@ public: db_event_markRead(dat->hContact, dat->hDbEvent); - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(dat->hDbEvent, &dbei)) + DB::EventInfo dbei(dat->hDbEvent); + if (!dbei) return false; dat->fs = m_lParam ? (HANDLE)m_lParam : (HANDLE)*(PDWORD)dbei.pBlob; diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 2b501c487b..c20b597beb 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -200,9 +200,8 @@ bool DbEventIsShown(const DBEVENTINFO *dbei) static bool CreateRTFFromDbEvent(LogStreamData *dat) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(dat->hDbEvent, &dbei)) + DB::EventInfo dbei(dat->hDbEvent); + if (!dbei) return false; if (!DbEventIsShown(&dbei)) diff --git a/src/core/stduihist/src/history.cpp b/src/core/stduihist/src/history.cpp index ae92875fab..2e59abcf9e 100644 --- a/src/core/stduihist/src/history.cpp +++ b/src/core/stduihist/src/history.cpp @@ -272,9 +272,8 @@ static INT_PTR CALLBACK DlgProcHistory(HWND hwndDlg, UINT msg, WPARAM wParam, LP EnableWindow(GetDlgItem(hwndDlg, IDC_DELETEHISTORY), TRUE); MEVENT hDbEvent = SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETITEMDATA, sel, 0); - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (!db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (dbei) { ptrW wszDescr(DbEvent_GetTextW(&dbei, CP_ACP)); if (wszDescr) SetDlgItemText(hwndDlg, IDC_EDIT, wszDescr); diff --git a/src/mir_app/src/auth.cpp b/src/mir_app/src/auth.cpp index 0520c20a11..f49def1505 100644 --- a/src/mir_app/src/auth.cpp +++ b/src/mir_app/src/auth.cpp @@ -204,10 +204,7 @@ public: Button_SetSkin_IcoLib(m_hwnd, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list")); // blob is: uin(uint32_t), hcontact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) - DB::EventInfo dbei; - dbei.cbBlob = -1; - db_event_get(m_hDbEvent, &dbei); - + DB::EventInfo dbei(m_hDbEvent); m_hContact = DbGetAuthEventContact(&dbei); uint32_t uin = *(uint32_t*)dbei.pBlob; @@ -306,8 +303,7 @@ static int AuthEventAdded(WPARAM, LPARAM lParam) wchar_t szTooltip[256]; MEVENT hDbEvent = (MEVENT)lParam; - DB::EventInfo dbei; - db_event_get(lParam, &dbei); + DB::EventInfo dbei(lParam); if (dbei.flags & (DBEF_SENT | DBEF_READ) || (dbei.eventType != EVENTTYPE_AUTHREQUEST && dbei.eventType != EVENTTYPE_ADDED)) return 0; diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index dd6a377106..e1257c5ea2 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -822,9 +822,8 @@ static int OnEventAdded(WPARAM hContact, LPARAM hDbEvent) if (Contact::IsGroupChat(hContact)) { if (auto *si = SM_FindSessionByContact(hContact)) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (!db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (dbei) { auto *szProto = Proto_GetBaseAccountName(si->hContact); if (si && !mir_strcmp(szProto, dbei.szModule) && dbei.eventType == EVENTTYPE_MESSAGE && dbei.szUserId) { CMStringA szText((char *)dbei.pBlob); diff --git a/src/mir_app/src/db_events.cpp b/src/mir_app/src/db_events.cpp index b6bce698d4..f4153d6850 100644 --- a/src/mir_app/src/db_events.cpp +++ b/src/mir_app/src/db_events.cpp @@ -265,6 +265,27 @@ MIR_APP_DLL(wchar_t*) DbEvent_GetString(DBEVENTINFO *dbei, const char *str) ///////////////////////////////////////////////////////////////////////////////////////// +DB::EventInfo::EventInfo(MEVENT hEvent, bool bFetchBlob) +{ + memset(this, 0, sizeof(*this)); + if (bFetchBlob) + cbBlob = -1; + bValid = ::db_event_get(hEvent, this) == 0; +} + +DB::EventInfo::EventInfo() : + bValid(false) +{ + memset(this, 0, sizeof(*this)); +} + +DB::EventInfo::~EventInfo() +{ + mir_free(pBlob); +} + +///////////////////////////////////////////////////////////////////////////////////////// + DB::AUTH_BLOB::AUTH_BLOB(MCONTACT hContact, LPCSTR nick, LPCSTR fname, LPCSTR lname, LPCSTR email, LPCSTR reason) : m_dwUin(0), m_hContact(hContact), diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index c454bed1ca..a9fbe03f05 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -833,3 +833,6 @@ Chat_IsMuted @941 NONAME ?UpdateFilterButton@CSrmmBaseDialog@@UAEXXZ @948 NONAME ?Chat_SetFilters@@YGXPAUSESSION_INFO@@@Z @949 NONAME ?Chat_ReconfigureFilters@@YGXXZ @950 NONAME +??0EventInfo@DB@@QAE@I_N@Z @951 NONAME +??0EventInfo@DB@@QAE@XZ @952 NONAME +??1EventInfo@DB@@QAE@XZ @953 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 1f447d3ff0..3785f6e784 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -833,3 +833,6 @@ Chat_IsMuted @941 NONAME ?UpdateFilterButton@CSrmmBaseDialog@@UEAAXXZ @948 NONAME ?Chat_SetFilters@@YAXPEAUSESSION_INFO@@@Z @949 NONAME ?Chat_ReconfigureFilters@@YAXXZ @950 NONAME +??0EventInfo@DB@@QEAA@I_N@Z @951 NONAME +??0EventInfo@DB@@QEAA@XZ @952 NONAME +??1EventInfo@DB@@QEAA@XZ @953 NONAME diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index 1b3350552c..6e567643d6 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -660,9 +660,8 @@ void CSrmmBaseDialog::UpdateChatLog() auto *szProto = Proto_GetBaseAccountName(m_hContact); for (MEVENT hDbEvent = m_hDbEventFirst; hDbEvent; hDbEvent = db_event_next(m_hContact, hDbEvent)) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (!db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (dbei) { if (!mir_strcmp(szProto, dbei.szModule) && dbei.eventType == EVENTTYPE_MESSAGE && dbei.szUserId) { auto *pUser = g_chatApi.UM_FindUser(m_si, Utf2T(dbei.szUserId)); if (pUser == nullptr) -- cgit v1.2.3