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 --- include/m_database.h | 175 ++++++++++++----------- plugins/AutoShutdown/src/watcher.cpp | 28 ++-- plugins/AvatarHistory/src/AvatarDlg.cpp | 12 +- plugins/Boltun/src/boltun.cpp | 16 +-- plugins/ContactsPlus/src/main.cpp | 45 +++--- plugins/ContactsPlus/src/receive.cpp | 11 +- plugins/Db3x_mmap/src/dbevents.cpp | 9 +- plugins/Dbx_mdbx/src/dbevents.cpp | 13 +- plugins/Dbx_sqlite/src/dbevents.cpp | 7 +- plugins/HistoryLinkListPlus/src/linklist.cpp | 7 +- plugins/HistoryLinkListPlus/src/linklist_fct.cpp | 58 +++----- plugins/IEView/src/HTMLBuilder.cpp | 12 +- plugins/Import/src/dbrw/dbevents.cpp | 16 ++- plugins/MirLua/src/Modules/m_database.cpp | 6 +- plugins/MirandaG15/src/CAppletManager.cpp | 27 +--- plugins/Msg_Export/src/utils.cpp | 17 +-- plugins/NewEventNotify/src/popup.cpp | 26 ++-- plugins/NewStory/src/history.cpp | 15 +- plugins/Scriver/src/msgdialog.cpp | 12 +- plugins/Scriver/src/msglog.cpp | 13 +- plugins/StopSpamMod/src/stopspam.cpp | 9 +- plugins/StopSpamPlus/src/events.cpp | 10 +- plugins/TabSRMM/src/eventpopups.cpp | 22 +-- plugins/TabSRMM/src/msglog.cpp | 6 +- plugins/Variables/src/parse_miranda.cpp | 13 +- plugins/YARelay/src/main.cpp | 8 +- plugins/wbOSD/src/events.cpp | 13 +- protocols/Discord/src/dispatch.cpp | 6 +- protocols/Discord/src/proto.cpp | 10 +- protocols/JabberG/src/jabber_proto.cpp | 24 +--- protocols/JabberG/src/jabber_rc.cpp | 23 +-- protocols/JabberG/src/jabber_thread.cpp | 17 +-- protocols/SkypeWeb/src/skype_db.cpp | 10 +- protocols/SkypeWeb/src/skype_proto.cpp | 12 +- protocols/Steam/src/steam_proto.cpp | 13 +- protocols/VKontakte/src/misc.cpp | 6 +- src/core/stdfile/src/filerecvdlg.cpp | 9 +- src/core/stdmsg/src/msglog.cpp | 13 +- src/core/stduihist/src/history.cpp | 33 ++--- src/mir_app/src/auth.cpp | 17 +-- 40 files changed, 318 insertions(+), 481 deletions(-) diff --git a/include/m_database.h b/include/m_database.h index 1245c2a085..5947ce1c4f 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -178,7 +178,7 @@ struct DBEVENTINFO // signed and can only do until 2038. In GMT. DWORD flags; // combination of DBEF_* flags WORD eventType; // module-defined event type field - DWORD cbBlob; // size of pBlob in bytes + int cbBlob; // size of pBlob in bytes PBYTE pBlob; // pointer to buffer containing module-defined event data const char *szId; // server id @@ -670,109 +670,124 @@ __inline DWORD DBGetContactSettingRangedDword(MCONTACT hContact, const char *szM namespace DB { -///////////////////////////////////////////////////////////////////////////////////////// -// Helper to process the auth req body -// blob is: 0(DWORD), hContact(DWORD), nick(UTF8), firstName(UTF8), lastName(UTF8), email(UTF8), reason(UTF8) + ///////////////////////////////////////////////////////////////////////////////////////// + // Helper to free event contents automatically -#pragma warning(disable : 4251) + struct EventInfo : public DBEVENTINFO + { + __forceinline explicit EventInfo() + { + memset(this, 0, sizeof(*this)); + } + + __forceinline ~EventInfo() + { + mir_free(pBlob); + } + }; -class MIR_APP_EXPORT AUTH_BLOB -{ - MCONTACT m_hContact; - DWORD m_dwUin; - ptrA m_szNick, m_szFirstName, m_szLastName, m_szEmail, m_szReason; - DWORD m_size; + ///////////////////////////////////////////////////////////////////////////////////////// + // Helper to process the auth req body + // blob is: 0(DWORD), hContact(DWORD), nick(UTF8), firstName(UTF8), lastName(UTF8), email(UTF8), reason(UTF8) - PBYTE makeBlob(); + #pragma warning(disable : 4251) -public: - explicit AUTH_BLOB(MCONTACT hContact, const char *nick, const char *fname, const char *lname, const char *id, const char *reason); - explicit AUTH_BLOB(PBYTE blob); - ~AUTH_BLOB(); + class MIR_APP_EXPORT AUTH_BLOB + { + MCONTACT m_hContact; + DWORD m_dwUin; + ptrA m_szNick, m_szFirstName, m_szLastName, m_szEmail, m_szReason; + DWORD m_size; - __forceinline operator char*() { return (char*)makeBlob(); } - __forceinline operator BYTE*() { return makeBlob(); } + PBYTE makeBlob(); - __forceinline DWORD size() const { return m_size; } + public: + explicit AUTH_BLOB(MCONTACT hContact, const char *nick, const char *fname, const char *lname, const char *id, const char *reason); + explicit AUTH_BLOB(PBYTE blob); + ~AUTH_BLOB(); - __forceinline MCONTACT get_contact() const { return m_hContact; } - __forceinline const char* get_nick() const { return m_szNick; } - __forceinline const char* get_firstName() const { return m_szFirstName; } - __forceinline const char* get_lastName() const { return m_szLastName; } - __forceinline const char* get_email() const { return m_szEmail; } - __forceinline const char* get_reason() const { return m_szReason; } - - __forceinline DWORD get_uin() const { return m_dwUin; } - __forceinline void set_uin(DWORD dwValue) { m_dwUin = dwValue; } -}; + __forceinline operator char*() { return (char*)makeBlob(); } + __forceinline operator BYTE*() { return makeBlob(); } -///////////////////////////////////////////////////////////////////////////////////////// -// Event cursors + __forceinline DWORD size() const { return m_size; } -class MIR_CORE_EXPORT EventCursor : public MZeroedObject -{ - friend class EventIterator; + __forceinline MCONTACT get_contact() const { return m_hContact; } + __forceinline const char* get_nick() const { return m_szNick; } + __forceinline const char* get_firstName() const { return m_szFirstName; } + __forceinline const char* get_lastName() const { return m_szLastName; } + __forceinline const char* get_email() const { return m_szEmail; } + __forceinline const char* get_reason() const { return m_szReason; } + + __forceinline DWORD get_uin() const { return m_dwUin; } + __forceinline void set_uin(DWORD dwValue) { m_dwUin = dwValue; } + }; -protected: - MCONTACT hContact; + ///////////////////////////////////////////////////////////////////////////////////////// + // Event cursors -public: - EventCursor(MCONTACT _1) : - hContact(_1) - { } + class MIR_CORE_EXPORT EventCursor : public MZeroedObject + { + friend class EventIterator; - virtual ~EventCursor(); - virtual MEVENT FetchNext() = 0; + protected: + MCONTACT hContact; - __forceinline MEVENT begin() { - return FetchNext(); - } + public: + EventCursor(MCONTACT _1) : + hContact(_1) + { } - __forceinline MEVENT end() { - return 0; - } -}; + virtual ~EventCursor(); + virtual MEVENT FetchNext() = 0; -class MIR_CORE_EXPORT ECPTR : public MNonCopyable -{ - EventCursor *m_cursor; - MEVENT m_prevFetched, m_currEvent; + __forceinline MEVENT begin() { + return FetchNext(); + } -public: - ECPTR(EventCursor *_1); - ~ECPTR(); + __forceinline MEVENT end() { + return 0; + } + }; - void DeleteEvent(); - MEVENT FetchNext(); -}; + class MIR_CORE_EXPORT ECPTR : public MNonCopyable + { + EventCursor *m_cursor; + MEVENT m_prevFetched, m_currEvent; -class EventIterator -{ - EventCursor *cursor; - MEVENT hCurr = 0; + public: + ECPTR(EventCursor *_1); + ~ECPTR(); -public: - EventIterator(EventCursor *_1) : - cursor(_1) - {} + void DeleteEvent(); + MEVENT FetchNext(); + }; - EventIterator operator++() { - hCurr = cursor->FetchNext(); - return *this; - } + class EventIterator + { + EventCursor *cursor; + MEVENT hCurr = 0; - bool operator!=(const EventIterator &p) { - return hCurr != p.hCurr; - } + public: + EventIterator(EventCursor *_1) : + cursor(_1) + {} - operator MEVENT() const { - return hCurr; - } -}; + EventIterator operator++() { + hCurr = cursor->FetchNext(); + return *this; + } -MIR_CORE_DLL(EventCursor*) Events(MCONTACT, MEVENT iStartEvent = 0); -MIR_CORE_DLL(EventCursor*) EventsRev(MCONTACT, MEVENT iStartEvent = 0); + bool operator!=(const EventIterator &p) { + return hCurr != p.hCurr; + } + + operator MEVENT() const { + return hCurr; + } + }; + MIR_CORE_DLL(EventCursor*) Events(MCONTACT, MEVENT iStartEvent = 0); + MIR_CORE_DLL(EventCursor*) EventsRev(MCONTACT, MEVENT iStartEvent = 0); }; #endif // M_DATABASE_H__ diff --git a/plugins/AutoShutdown/src/watcher.cpp b/plugins/AutoShutdown/src/watcher.cpp index e30ab9ad5f..b01cb95735 100644 --- a/plugins/AutoShutdown/src/watcher.cpp +++ b/plugins/AutoShutdown/src/watcher.cpp @@ -91,23 +91,21 @@ static wchar_t* GetMessageText(BYTE **ppBlob, DWORD *pcbBlob) static int MsgEventAdded(WPARAM, LPARAM hDbEvent) { if (currentWatcherType & SDWTF_MESSAGE) { - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(hDbEvent); - dbe.pBlob = (BYTE*)mir_alloc(dbe.cbBlob + 2); /* ensure term zero */ - if (dbe.pBlob == nullptr) + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(hDbEvent, &dbei)) return 0; - if (!db_event_get(hDbEvent, &dbe)) - if (dbe.eventType == EVENTTYPE_MESSAGE && !(dbe.flags & DBEF_SENT)) { - DBVARIANT dbv; - if (!g_plugin.getWString("Message", &dbv)) { - TrimString(dbv.pwszVal); - wchar_t *pszMsg = GetMessageText(&dbe.pBlob, &dbe.cbBlob); - if (pszMsg != nullptr && wcsstr(pszMsg, dbv.pwszVal) != nullptr) - ShutdownAndStopWatcher(); /* msg with specified text recvd */ - mir_free(dbv.pwszVal); /* does NULL check */ - } + + if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_SENT)) { + DBVARIANT dbv; + if (!g_plugin.getWString("Message", &dbv)) { + TrimString(dbv.pwszVal); + wchar_t *pszMsg = GetMessageText(&dbei.pBlob, &dbei.cbBlob); + if (pszMsg != nullptr && wcsstr(pszMsg, dbv.pwszVal) != nullptr) + ShutdownAndStopWatcher(); /* msg with specified text recvd */ + mir_free(dbv.pwszVal); /* does NULL check */ } - mir_free(dbe.pBlob); + } } return 0; } diff --git a/plugins/AvatarHistory/src/AvatarDlg.cpp b/plugins/AvatarHistory/src/AvatarDlg.cpp index 245c58005a..a03378ec28 100644 --- a/plugins/AvatarHistory/src/AvatarDlg.cpp +++ b/plugins/AvatarHistory/src/AvatarDlg.cpp @@ -412,12 +412,12 @@ int FillAvatarListFromDB(HWND list, MCONTACT hContact) int max_pos = 0; DB::ECPTR pCursor(DB::Events(hContact)); while (MEVENT hDbEvent = pCursor.FetchNext()) { - DBEVENTINFO dbei = {}; - BYTE blob[2048]; - dbei.cbBlob = sizeof(blob); - dbei.pBlob = blob; - if (db_event_get(hDbEvent, &dbei) != 0) continue; - if (dbei.eventType != EVENTTYPE_AVATAR_CHANGE) continue; + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(hDbEvent, &dbei)) + continue; + if (dbei.eventType != EVENTTYPE_AVATAR_CHANGE) + continue; // Get time wchar_t date[64]; diff --git a/plugins/Boltun/src/boltun.cpp b/plugins/Boltun/src/boltun.cpp index 82a9994073..f764e3fc84 100644 --- a/plugins/Boltun/src/boltun.cpp +++ b/plugins/Boltun/src/boltun.cpp @@ -195,26 +195,16 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) if (!BoltunAutoChat(hContact)) return 0; - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if (dbei.cbBlob == -1) - return 0; - - dbei.pBlob = (PBYTE)malloc(dbei.cbBlob); - if (dbei.pBlob == nullptr) - return 0; - + DB::EventInfo dbei; + dbei.cbBlob = -1; db_event_get(hDbEvent, &dbei); if (dbei.flags & DBEF_SENT || dbei.flags & DBEF_READ || dbei.eventType != EVENTTYPE_MESSAGE) return 0; - wchar_t *s = DbEvent_GetTextW(&dbei, CP_ACP); - free(dbei.pBlob); if (Config.MarkAsRead) db_event_markRead(hContact, hDbEvent); - AnswerToContact(hContact, s); - mir_free(s); + AnswerToContact(hContact, ptrW(DbEvent_GetTextW(&dbei, CP_ACP))); return 0; } diff --git a/plugins/ContactsPlus/src/main.cpp b/plugins/ContactsPlus/src/main.cpp index 1b759ce240..905eaab7e3 100644 --- a/plugins/ContactsPlus/src/main.cpp +++ b/plugins/ContactsPlus/src/main.cpp @@ -56,33 +56,30 @@ CMPlugin::CMPlugin() : static int HookDBEventAdded(WPARAM hContact, LPARAM hDbEvent) { - //process the event + // process the event DBEVENTINFO dbe = {}; db_event_get(hDbEvent, &dbe); - //check if we should process the event - if (dbe.flags & (DBEF_SENT | DBEF_READ) || dbe.eventType != EVENTTYPE_CONTACTS) return 0; - //get event contents - dbe.cbBlob = db_event_getBlobSize(hDbEvent); - if (dbe.cbBlob != -1) - dbe.pBlob = (PBYTE)_alloca(dbe.cbBlob); - db_event_get(hDbEvent, &dbe); - //play received sound + + // check if we should process the event + if (dbe.flags & (DBEF_SENT | DBEF_READ) || dbe.eventType != EVENTTYPE_CONTACTS) + return 0; + + // play received sound Skin_PlaySound("RecvContacts"); - { - //add event to the contact list - wchar_t caToolTip[128]; - mir_snwprintf(caToolTip, L"%s %s", TranslateT("Contacts received from"), Clist_GetContactDisplayName(hContact)); - - CLISTEVENT cle = {}; - cle.hContact = hContact; - cle.hDbEvent = hDbEvent; - cle.hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_CONTACTS)); - cle.pszService = MS_CONTACTS_RECEIVE; - cle.szTooltip.w = caToolTip; - cle.flags |= CLEF_UNICODE; - g_clistApi.pfnAddEvent(&cle); - } - return 0; //continue processing by other hooks + + // add event to the contact list + wchar_t caToolTip[128]; + mir_snwprintf(caToolTip, L"%s %s", TranslateT("Contacts received from"), Clist_GetContactDisplayName(hContact)); + + CLISTEVENT cle = {}; + cle.hContact = hContact; + cle.hDbEvent = hDbEvent; + cle.hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_CONTACTS)); + cle.pszService = MS_CONTACTS_RECEIVE; + cle.szTooltip.w = caToolTip; + cle.flags |= CLEF_UNICODE; + g_clistApi.pfnAddEvent(&cle); + return 0; } static void ProcessUnreadEvents(void) diff --git a/plugins/ContactsPlus/src/receive.cpp b/plugins/ContactsPlus/src/receive.cpp index f4a0b1335d..da8b2230f3 100644 --- a/plugins/ContactsPlus/src/receive.cpp +++ b/plugins/ContactsPlus/src/receive.cpp @@ -195,11 +195,9 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara CheckDlgButton(hwndDlg, IDC_ENABLEGROUPS, BST_UNCHECKED); RebuildGroupCombo(hwndDlg); - { // fill listview with received contacts - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(wndData->mhDbEvent); - if (dbe.cbBlob != -1) // this marks an invalid hDbEvent - all smashed anyway... - dbe.pBlob = (PBYTE)_alloca(dbe.cbBlob); + { // fill listview with received contacts + DB::EventInfo dbe; + dbe.cbBlob = -1; db_event_get(wndData->mhDbEvent, &dbe); char* pcBlob = (char*)dbe.pBlob; char* pcEnd = (char*)dbe.pBlob + dbe.cbBlob; @@ -212,8 +210,7 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara lvi.iImage = 0; lvi.mask = LVIF_TEXT | LVIF_IMAGE; - for (int nItem = 0; ; nItem++) - { // Nick + for (int nItem = 0; ; nItem++) { // Nick int strsize = (int)strlennull(pcBlob); TReceivedItem* pItem = wndData->AddReceivedItem(); diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index e3b91a52be..68384fa348 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -292,7 +292,14 @@ BOOL CDb3Mmap::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) dbei->timestamp = dbe->timestamp; dbei->flags = dbe->flags; dbei->eventType = dbe->wEventType; - int bytesToCopy = (dbei->cbBlob < dbe->cbBlob) ? dbei->cbBlob : dbe->cbBlob; + + DWORD cbBlob = dbe->cbBlob; + size_t bytesToCopy = cbBlob; + if (dbei->cbBlob == -1) + dbei->pBlob = (PBYTE)mir_calloc(cbBlob + 2); + else if (dbei->cbBlob < cbBlob) + bytesToCopy = dbei->cbBlob; + dbei->cbBlob = dbe->cbBlob; if (bytesToCopy && dbei->pBlob) { BYTE *pSrc; diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp index 2c9a1d71f0..aa7f634f64 100644 --- a/plugins/Dbx_mdbx/src/dbevents.cpp +++ b/plugins/Dbx_mdbx/src/dbevents.cpp @@ -296,7 +296,6 @@ BOOL CDbxMDBX::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) return 1; } - size_t cbBlob; const DBEvent *dbe; { MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data; @@ -304,15 +303,21 @@ BOOL CDbxMDBX::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) return 1; dbe = (const DBEvent*)data.iov_base; - cbBlob = data.iov_len - sizeof(DBEvent); } dbei->szModule = GetModuleName(dbe->iModuleId); dbei->timestamp = dbe->timestamp; dbei->flags = dbe->flags; dbei->eventType = dbe->wEventType; - size_t bytesToCopy = min(dbei->cbBlob, cbBlob); - dbei->cbBlob = dbe->cbBlob; + + DWORD cbBlob = dbe->cbBlob; + size_t bytesToCopy = cbBlob; + if (dbei->cbBlob == -1) + dbei->pBlob = (PBYTE)mir_calloc(cbBlob + 2); + else if (dbei->cbBlob < cbBlob) + bytesToCopy = dbei->cbBlob; + + dbei->cbBlob = (DWORD)cbBlob; if (bytesToCopy && dbei->pBlob) { BYTE *pSrc = (BYTE*)dbe + sizeof(DBEvent); if (dbe->flags & DBEF_ENCRYPTED) { diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index cbfa67485a..6244928107 100755 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -307,7 +307,12 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) dbei->flags = sqlite3_column_int64(stmt, 3); DWORD cbBlob = sqlite3_column_int64(stmt, 4); - int bytesToCopy = (dbei->cbBlob < cbBlob) ? dbei->cbBlob : cbBlob; + size_t bytesToCopy = cbBlob; + if (dbei->cbBlob == -1) + dbei->pBlob = (PBYTE)mir_calloc(cbBlob + 2); + else if (dbei->cbBlob < cbBlob) + bytesToCopy = dbei->cbBlob; + dbei->cbBlob = cbBlob; if (bytesToCopy && dbei->pBlob) { BYTE *data = (BYTE *)sqlite3_column_blob(stmt, 5); diff --git a/plugins/HistoryLinkListPlus/src/linklist.cpp b/plugins/HistoryLinkListPlus/src/linklist.cpp index 4b0e97f785..016724e8fe 100644 --- a/plugins/HistoryLinkListPlus/src/linklist.cpp +++ b/plugins/HistoryLinkListPlus/src/linklist.cpp @@ -90,11 +90,9 @@ static INT_PTR LinkList_Main(WPARAM hContact, LPARAM) memset(listStart, 0, sizeof(LISTELEMENT)); do { - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob + 1); + DB::EventInfo dbe; + dbe.cbBlob = -1; db_event_get(hEvent, &dbe); - dbe.pBlob[dbe.cbBlob] = 0; if (dbe.eventType == EVENTTYPE_MESSAGE) { // Call function to find URIs @@ -109,7 +107,6 @@ static INT_PTR LinkList_Main(WPARAM hContact, LPARAM) actCount++; if (((int)(((float)actCount / histCount) * 100.00)) % 10 == 0) SendMessage(hWndProgress, WM_COMMAND, 100, ((int)(((float)actCount / histCount) * 100.00))); - mir_free(dbe.pBlob); } while (hEvent = pCursor.FetchNext()); diff --git a/plugins/HistoryLinkListPlus/src/linklist_fct.cpp b/plugins/HistoryLinkListPlus/src/linklist_fct.cpp index dcfbe5711f..63fbd15fa3 100644 --- a/plugins/HistoryLinkListPlus/src/linklist_fct.cpp +++ b/plugins/HistoryLinkListPlus/src/linklist_fct.cpp @@ -380,17 +380,13 @@ void WriteLinkList(HWND hDlg, BYTE params, LISTELEMENT *listStart, LPCTSTR searc // Perform deep scan if (actualElement->hEvent != NULL) { - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(actualElement->hEvent); - dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob + 1); + DB::EventInfo dbe; + dbe.cbBlob = -1; db_event_get(actualElement->hEvent, &dbe); - dbe.pBlob[dbe.cbBlob] = 0; - LPTSTR msg = DbEvent_GetTextW(&dbe, CP_ACP); + + ptrW msg(DbEvent_GetTextW(&dbe, CP_ACP)); if (wcsstr(msg, searchString)) filter3 = 1; - - mir_free(dbe.pBlob); - mir_free(msg); } else filter3 = 0; } @@ -614,16 +610,12 @@ void WriteMessage(HWND hDlg, LISTELEMENT *listStart, int actLinePos) if (actualElement->linePos == actLinePos) { MEVENT hEvent = actualElement->hEvent; if (hEvent != NULL) { - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob + 1); + DB::EventInfo dbe; + dbe.cbBlob = -1; db_event_get(hEvent, &dbe); - dbe.pBlob[dbe.cbBlob] = 0; - LPCTSTR msg = DbEvent_GetTextW(&dbe, CP_ACP); - SetDlgItemText(hDlg, IDC_MESSAGE, nullptr); - SendDlgItemMessage(hDlg, IDC_MESSAGE, EM_REPLACESEL, FALSE, (LPARAM)msg); - mir_free((void*)msg); - mir_free(dbe.pBlob); + + SetDlgItemTextW(hDlg, IDC_MESSAGE, L""); + SendDlgItemMessage(hDlg, IDC_MESSAGE, EM_REPLACESEL, FALSE, ptrW(DbEvent_GetTextW(&dbe, CP_ACP))); } break; } @@ -771,18 +763,14 @@ void GetListInfo(BYTE params, LISTELEMENT *listStart, LPCTSTR searchString, size // Perform deep scan if (actualElement->hEvent != NULL) { - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(actualElement->hEvent); - dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob + 1); + DB::EventInfo dbe; + dbe.cbBlob = -1; db_event_get(actualElement->hEvent, &dbe); - dbe.pBlob[dbe.cbBlob] = 0; + if (wcsstr((LPTSTR)dbe.pBlob, searchString)) filter3 = 1; - - mir_free(dbe.pBlob); } - else - filter3 = 0; + else filter3 = 0; } else { @@ -790,8 +778,7 @@ void GetListInfo(BYTE params, LISTELEMENT *listStart, LPCTSTR searchString, size filter3 = 1; } } - else - filter3 = 1; + else filter3 = 1; if ((filter1 == 1) && (filter2 == 1) && (filter3 == 1)) { @@ -1171,27 +1158,24 @@ This function is derived from his Wordlookup Plugin int DBUpdate(WPARAM wParam, LPARAM hEvent) { HWND hDlg = WindowList_Find(hWindowList, wParam); - DIALOGPARAM *DlgParam; HMENU listMenu = GetMenu(hDlg); - int linkNum = 0; - - DlgParam = (DIALOGPARAM *)GetWindowLongPtr(hDlg, GWLP_USERDATA); + DIALOGPARAM *DlgParam = (DIALOGPARAM *)GetWindowLongPtr(hDlg, GWLP_USERDATA); if (GetUpdateSetting() != 1) return 0; if (hDlg) { - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)mir_alloc((size_t)dbe.cbBlob + 1); - db_event_get(hEvent, &dbe); + DB::EventInfo dbe; + dbe.cbBlob = -1; + if (db_event_get(hEvent, &dbe)) + return 0; + if (dbe.eventType == EVENTTYPE_MESSAGE) { // Call function to find URIs - linkNum = ExtractURI(&dbe, hEvent, DlgParam->listStart); + int linkNum = ExtractURI(&dbe, hEvent, DlgParam->listStart); if (linkNum > 0) WriteLinkList(hDlg, GetFlags(listMenu), DlgParam->listStart, nullptr, linkNum); } - mir_free(dbe.pBlob); } return 0; } diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp index a0ad5d7528..fcbd404f80 100644 --- a/plugins/IEView/src/HTMLBuilder.cpp +++ b/plugins/IEView/src/HTMLBuilder.cpp @@ -198,21 +198,19 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) newEvent.hwnd = event->hwnd; for (int eventIdx = 0; hDbEvent != NULL && (eventIdx < event->count || event->count == -1); eventIdx++) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if (dbei.cbBlob == 0xFFFFFFFF) { + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(hDbEvent, &dbei)) { hDbEvent = db_event_next(event->hContact, hDbEvent); continue; } - dbei.pBlob = (PBYTE)malloc(dbei.cbBlob); - db_event_get(hDbEvent, &dbei); + if (!(dbei.flags & DBEF_SENT) && dbei.eventType == EVENTTYPE_MESSAGE) { db_event_markRead(event->hContact, hDbEvent); g_clistApi.pfnRemoveEvent(event->hContact, hDbEvent); } if (!isDbEventShown(&dbei)) { - free(dbei.pBlob); hDbEvent = db_event_next(event->hContact, hDbEvent); continue; } @@ -265,7 +263,7 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) eventData->szText.w = DbEvent_GetTextW(&dbei, newEvent.codepage); eventData->iType = IEED_EVENT_MESSAGE; } - free(dbei.pBlob); + eventData->next = nullptr; if (prevEventData != nullptr) prevEventData->next = eventData; diff --git a/plugins/Import/src/dbrw/dbevents.cpp b/plugins/Import/src/dbrw/dbevents.cpp index ceb1a9a8f4..4fcfa650fe 100644 --- a/plugins/Import/src/dbrw/dbevents.cpp +++ b/plugins/Import/src/dbrw/dbevents.cpp @@ -78,17 +78,23 @@ STDMETHODIMP_(BOOL) CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_GET]; sqlite3_bind_int(stmt, 1, hDbEvent); if (sql_step(stmt) == SQLITE_ROW) { - unsigned copySize; const void *blob = sqlite3_column_blob(stmt, 4); - const unsigned size = sqlite3_column_int(stmt, 5); dbei->timestamp = (DWORD)sqlite3_column_int(stmt, 1); dbei->flags = (DWORD)sqlite3_column_int(stmt, 2); dbei->eventType = (WORD)sqlite3_column_int(stmt, 3); dbei->szModule = mir_strdup((char*)sqlite3_column_text(stmt, 7)); - copySize = sizecbBlob ? size : dbei->cbBlob; - memcpy(dbei->pBlob, blob, copySize); - dbei->cbBlob = copySize; + + DWORD cbBlob = sqlite3_column_int(stmt, 5); + size_t bytesToCopy = cbBlob; + if (dbei->cbBlob == -1) + dbei->pBlob = (PBYTE)mir_calloc(cbBlob + 2); + else if (dbei->cbBlob < cbBlob) + bytesToCopy = dbei->cbBlob; + + dbei->cbBlob = cbBlob; + if (bytesToCopy && dbei->pBlob) + memcpy(dbei->pBlob, blob, bytesToCopy); res = 0; } sql_reset(stmt); diff --git a/plugins/MirLua/src/Modules/m_database.cpp b/plugins/MirLua/src/Modules/m_database.cpp index f00887a7da..538f7682a3 100644 --- a/plugins/MirLua/src/Modules/m_database.cpp +++ b/plugins/MirLua/src/Modules/m_database.cpp @@ -636,11 +636,9 @@ DBEVENTINFO* MT::Init(lua_State *L) { MEVENT hDbEvent = luaL_checkinteger(L, 1); - DBEVENTINFO* dbei = (DBEVENTINFO*)mir_calloc(sizeof(DBEVENTINFO)); - dbei->cbBlob = db_event_getBlobSize((MEVENT)hDbEvent); - dbei->pBlob = (PBYTE)mir_calloc(dbei->cbBlob); + DBEVENTINFO *dbei = (DBEVENTINFO *)mir_calloc(sizeof(DBEVENTINFO)); + dbei->cbBlob = -1; db_event_get((MEVENT)hDbEvent, dbei); - return dbei; } diff --git a/plugins/MirandaG15/src/CAppletManager.cpp b/plugins/MirandaG15/src/CAppletManager.cpp index 24d0c75abe..00ed5f39ac 100644 --- a/plugins/MirandaG15/src/CAppletManager.cpp +++ b/plugins/MirandaG15/src/CAppletManager.cpp @@ -793,17 +793,11 @@ void CAppletManager::MarkMessageAsRead(MCONTACT hContact, MEVENT hEvent) bool CAppletManager::TranslateDBEvent(CEvent *pEvent, WPARAM hContact, LPARAM hdbevent) { // Create struct for dbevent - DBEVENTINFO dbevent = {}; - dbevent.cbBlob = db_event_getBlobSize(hdbevent); - if (dbevent.cbBlob == -1) // hdbevent is invalid + DB::EventInfo dbevent; + dbevent.cbBlob = -1; + if (db_event_get(hdbevent, &dbevent) != 0) return false; - dbevent.pBlob = (PBYTE)malloc(dbevent.cbBlob); - if (db_event_get(hdbevent, &dbevent) != 0) { - free(dbevent.pBlob); - return false; - } - pEvent->dwFlags = dbevent.flags; pEvent->hContact = hContact; pEvent->hValue = hdbevent; @@ -811,17 +805,10 @@ bool CAppletManager::TranslateDBEvent(CEvent *pEvent, WPARAM hContact, LPARAM hd time_t timestamp = (time_t)dbevent.timestamp; localtime_s(&pEvent->Time, ×tamp); pEvent->bTime = true; - /* - if(dbevent.eventType == EVENTTYPE_MESSAGE && dbevent.flags & DBEF_READ) { - free(dbevent.pBlob); - return false; - } - */ + // Skip events from the user except for messages - if (dbevent.eventType != EVENTTYPE_MESSAGE && (dbevent.flags & DBEF_SENT)) { - free(dbevent.pBlob); + if (dbevent.eventType != EVENTTYPE_MESSAGE && (dbevent.flags & DBEF_SENT)) return false; - } int msglen = 0; @@ -877,9 +864,9 @@ bool CAppletManager::TranslateDBEvent(CEvent *pEvent, WPARAM hContact, LPARAM hd pEvent->strDescription = TranslateString(L"Incoming file from %s", strName.c_str()); pEvent->eType = EVENT_FILE; break; + default: return false; - break; } if (CConfig::GetBoolSetting(NOTIFY_SHOWPROTO)) { @@ -887,8 +874,6 @@ bool CAppletManager::TranslateDBEvent(CEvent *pEvent, WPARAM hContact, LPARAM hd pEvent->strDescription = L"(" + toTstring(szProto) + L") " + pEvent->strDescription; } - // Clean up - free(dbevent.pBlob); return true; } diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index d629ff16f1..e5cba7f1f7 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -961,18 +961,10 @@ int nExportEvent(WPARAM hContact, LPARAM hDbEvent) bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, const wstring &sFilePath, bool bAppendOnly) { - DBEVENTINFO dbei = {}; - int nSize = db_event_getBlobSize(hDbEvent); - if (nSize > 0) { - dbei.cbBlob = nSize; - dbei.pBlob = (PBYTE)malloc(dbei.cbBlob + 2); - dbei.pBlob[dbei.cbBlob] = 0; - dbei.pBlob[dbei.cbBlob + 1] = 0; - // Double null terminate, this should prevent most errors - // where the blob received has an invalid format - } - bool result = true; + + DB::EventInfo dbei; + dbei.cbBlob = -1; if (!db_event_get(hDbEvent, &dbei)) { if (db_mc_isMeta(hContact)) hContact = db_event_getContact(hDbEvent); @@ -980,8 +972,7 @@ bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, const wstrin // Write the event result = ExportDBEventInfo(hContact, hFile, sFilePath, dbei, bAppendOnly); } - if (dbei.pBlob) - free(dbei.pBlob); + return result; } diff --git a/plugins/NewEventNotify/src/popup.cpp b/plugins/NewEventNotify/src/popup.cpp index 07a074042e..b2bd6190f0 100644 --- a/plugins/NewEventNotify/src/popup.cpp +++ b/plugins/NewEventNotify/src/popup.cpp @@ -358,12 +358,10 @@ int PopupShow(MCONTACT hContact, MEVENT hEvent, UINT eventType) } // get DBEVENTINFO with pBlob if preview is needed (when is test then is off) - DBEVENTINFO dbe = {}; + DB::EventInfo dbe; if (hEvent) { - if ((g_plugin.bPreview || eventType == EVENTTYPE_ADDED || eventType == EVENTTYPE_AUTHREQUEST)) { - dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob); - } + if ((g_plugin.bPreview || eventType == EVENTTYPE_ADDED || eventType == EVENTTYPE_AUTHREQUEST)) + dbe.cbBlob = -1; db_event_get(hEvent, &dbe); } @@ -412,8 +410,6 @@ int PopupShow(MCONTACT hContact, MEVENT hEvent, UINT eventType) mir_free(pdata); } - if (dbe.pBlob) - mir_free(dbe.pBlob); return 0; } @@ -458,16 +454,12 @@ int PopupUpdate(MCONTACT hContact, MEVENT hEvent) iEvent++; // get DBEVENTINFO with pBlob if preview is needed (when is test then is off) - DBEVENTINFO dbe = {}; - dbe.pBlob = nullptr; - dbe.cbBlob = 0; - if (g_plugin.bPreview && eventData->hEvent) { - dbe.cbBlob = db_event_getBlobSize(eventData->hEvent); - dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob); - } - - if (eventData->hEvent) + DB::EventInfo dbe; + if (eventData->hEvent) { + if (g_plugin.bPreview) + dbe.cbBlob = -1; db_event_get(eventData->hEvent, &dbe); + } if (g_plugin.bShowDate || g_plugin.bShowTime) { wchar_t timestamp[MAX_DATASIZE]; @@ -486,8 +478,6 @@ int PopupUpdate(MCONTACT hContact, MEVENT hEvent) mir_snwprintf(lpzText, L"%s%s", lpzText, szEventPreview); mir_free(szEventPreview); - if (dbe.pBlob) - mir_free(dbe.pBlob); if (doReverse) { if ((iEvent >= g_plugin.iNumberMsg && g_plugin.iNumberMsg) || !eventData->next) break; diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index f0f3fae9a4..d69706efad 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -709,17 +709,8 @@ public: bool bAppendOnly = false; DB::ECPTR pCursor(DB::Events(m_hContact)); while (MEVENT hDbEvent = pCursor.FetchNext()) { - DBEVENTINFO dbei = {}; - int nSize = db_event_getBlobSize(hDbEvent); - if (nSize > 0) { - dbei.cbBlob = nSize; - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 2); - dbei.pBlob[dbei.cbBlob] = 0; - dbei.pBlob[dbei.cbBlob + 1] = 0; - // Double null terminate, this should prevent most errors - // where the blob received has an invalid format - } - + DB::EventInfo dbei; + dbei.cbBlob = -1; if (!db_event_get(hDbEvent, &dbei)) { if (bAppendOnly) { SetFilePointer(hFile, -3, nullptr, FILE_END); @@ -753,8 +744,6 @@ public: output += "\n]}"; WriteFile(hFile, output.c_str(), (int)output.size(), &dwBytesWritten, nullptr); - if (dbei.pBlob) - mir_free(dbei.pBlob); } bAppendOnly = true; diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index c8b0f89f2e..b9a57e3f00 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -484,7 +484,7 @@ void CMsgDialog::onClick_Quote(CCtrlButton*) if (m_hDbEventLast == 0) return; - SETTEXTEX st; + SETTEXTEX st; st.flags = ST_SELECTION; st.codepage = 1200; @@ -495,12 +495,11 @@ void CMsgDialog::onClick_Quote(CCtrlButton*) mir_free(buffer); } else { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(m_hDbEventLast); - if (dbei.cbBlob == 0xFFFFFFFF) + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(m_hDbEventLast, &dbei)) return; - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); - db_event_get(m_hDbEventLast, &dbei); + if (DbEventIsMessageOrCustom(&dbei)) { buffer = DbEvent_GetTextW(&dbei, CP_ACP); if (buffer != nullptr) { @@ -509,7 +508,6 @@ void CMsgDialog::onClick_Quote(CCtrlButton*) mir_free(buffer); } } - mir_free(dbei.pBlob); } SetFocus(m_message.GetHwnd()); } diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index 062657a3ac..f0914bd2cd 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -78,17 +78,13 @@ int DbEventIsShown(DBEVENTINFO &dbei) EventData* CMsgDialog::GetEventFromDB(MCONTACT hContact, MEVENT hDbEvent) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if (dbei.cbBlob == -1) + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(hDbEvent, &dbei)) return nullptr; - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); - db_event_get(hDbEvent, &dbei); - if (!DbEventIsShown(dbei)) { - mir_free(dbei.pBlob); + if (!DbEventIsShown(dbei)) return nullptr; - } EventData *evt = (EventData*)mir_calloc(sizeof(EventData)); evt->custom = DbEventIsCustomForMsgWindow(&dbei); @@ -125,7 +121,6 @@ EventData* CMsgDialog::GetEventFromDB(MCONTACT hContact, MEVENT hDbEvent) if (!m_bUseRtl && Utils_IsRtl(evt->szText.w)) evt->dwFlags |= IEEDF_RTL; - mir_free(dbei.pBlob); return evt; } diff --git a/plugins/StopSpamMod/src/stopspam.cpp b/plugins/StopSpamMod/src/stopspam.cpp index b32afb3e90..f1e7ca9361 100755 --- a/plugins/StopSpamMod/src/stopspam.cpp +++ b/plugins/StopSpamMod/src/stopspam.cpp @@ -19,14 +19,11 @@ int OnDbEventAdded(WPARAM hContact, LPARAM hDbEvent) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if (dbei.cbBlob == -1) + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(hDbEvent, &dbei)) return 0; - dbei.pBlob = (BYTE*)alloca(dbei.cbBlob); - db_event_get(hDbEvent, &dbei); - // if event is in protocol that is not despammed if (!ProtoInList(dbei.szModule)) return 0; diff --git a/plugins/StopSpamPlus/src/events.cpp b/plugins/StopSpamPlus/src/events.cpp index ae3c4794a6..e6f948f2ef 100644 --- a/plugins/StopSpamPlus/src/events.cpp +++ b/plugins/StopSpamPlus/src/events.cpp @@ -4,15 +4,11 @@ int OnDbEventAdded(WPARAM, LPARAM lParam) { MEVENT hDbEvent = (MEVENT)lParam; - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if (-1 == dbei.cbBlob) + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(hDbEvent, &dbei)) return 0; - mir_ptr blob((LPBYTE)mir_alloc(dbei.cbBlob)); - dbei.pBlob = blob; - db_event_get(hDbEvent, &dbei); - // if event is in protocol that is not despammed if (g_sets.ProtoDisabled(dbei.szModule)) return 0; diff --git a/plugins/TabSRMM/src/eventpopups.cpp b/plugins/TabSRMM/src/eventpopups.cpp index fd2538208a..c69982526f 100644 --- a/plugins/TabSRMM/src/eventpopups.cpp +++ b/plugins/TabSRMM/src/eventpopups.cpp @@ -313,11 +313,9 @@ static int PopupUpdateT(MCONTACT hContact, MEVENT hEvent) else szHeader[0] = 0; - DBEVENTINFO dbe = {}; - if (pdata->pluginOptions->bPreview && hContact) { - dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob); - } + DB::EventInfo dbe; + if (pdata->pluginOptions->bPreview && hContact) + dbe.cbBlob = -1; db_event_get(hEvent, &dbe); wchar_t timestamp[MAX_DATASIZE]; @@ -360,8 +358,6 @@ static int PopupUpdateT(MCONTACT hContact, MEVENT hEvent) pdata->nrEventsAlloced += 5; pdata->eventData = (EVENT_DATAT *)mir_realloc(pdata->eventData, pdata->nrEventsAlloced * sizeof(EVENT_DATAT)); } - if (dbe.pBlob) - mir_free(dbe.pBlob); PUChangeTextW(pdata->hWnd, lpzText); return 0; @@ -373,12 +369,10 @@ static int PopupShowT(NEN_OPTIONS *pluginOptions, MCONTACT hContact, MEVENT hEve if (arPopupList.getCount() >= MAX_POPUPS) return 2; - DBEVENTINFO dbe = {}; + DB::EventInfo dbe; // fix for a crash - if (hEvent && (pluginOptions->bPreview || hContact == 0)) { - dbe.cbBlob = db_event_getBlobSize(hEvent); - dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob); - } + if (hEvent && (pluginOptions->bPreview || hContact == 0)) + dbe.cbBlob = -1; db_event_get(hEvent, &dbe); if (hEvent == 0 && hContact == 0) @@ -437,10 +431,6 @@ static int PopupShowT(NEN_OPTIONS *pluginOptions, MCONTACT hContact, MEVENT hEve pdata->nrMerged = 1; PUAddPopupW(&pud); arPopupList.insert(pdata); - - if (dbe.pBlob) - mir_free(dbe.pBlob); - return 0; } diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index 49d03fa2bd..1d9a5d56c2 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -437,11 +437,7 @@ static char* Template_CreateRTFFromDbEvent(CMsgDialog *dat, MCONTACT hContact, M if (streamData->dbei != nullptr) dbei = *(streamData->dbei); else { - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if (dbei.cbBlob == -1) - return nullptr; - - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); + dbei.cbBlob = -1; db_event_get(hDbEvent, &dbei); if (!DbEventIsShown(&dbei)) { mir_free(dbei.pBlob); diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index b2687e5490..452989048d 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -564,17 +564,12 @@ static wchar_t* parseDbEvent(ARGUMENTSINFO *ai) if (hDbEvent == NULL) return nullptr; - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(hDbEvent); - dbe.pBlob = (PBYTE)mir_calloc(dbe.cbBlob); - if (db_event_get(hDbEvent, &dbe)) { - mir_free(dbe.pBlob); + DB::EventInfo dbe; + dbe.cbBlob = -1; + if (db_event_get(hDbEvent, &dbe)) return nullptr; - } - wchar_t *res = DbEvent_GetTextW(&dbe, CP_ACP); - mir_free(dbe.pBlob); - return res; + return DbEvent_GetTextW(&dbe, CP_ACP); } static wchar_t* parseTranslate(ARGUMENTSINFO *ai) diff --git a/plugins/YARelay/src/main.cpp b/plugins/YARelay/src/main.cpp index 4a29fedc9f..5abc1cbc44 100644 --- a/plugins/YARelay/src/main.cpp +++ b/plugins/YARelay/src/main.cpp @@ -113,12 +113,8 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDBEvent) return 0; // receive message from DB - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDBEvent); - if (dbei.cbBlob == -1) - return 0; - - dbei.pBlob = (unsigned char*)alloca(dbei.cbBlob); + DB::EventInfo dbei; + dbei.cbBlob = -1; db_event_get(hDBEvent, &dbei); 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 81429c9b09..e82fd92025 100644 --- a/plugins/wbOSD/src/events.cpp +++ b/plugins/wbOSD/src/events.cpp @@ -129,12 +129,8 @@ int ContactStatusChanged(WPARAM wParam, LPARAM lParam) int HookedNewEvent(WPARAM wParam, LPARAM hDBEvent) { logmsg("HookedNewEvent1"); - DBEVENTINFO dbe; - dbe.cbBlob = db_event_getBlobSize(hDBEvent); - if (dbe.cbBlob == -1) - return 0; - - dbe.pBlob = (PBYTE)malloc(dbe.cbBlob); + DB::EventInfo dbe; + dbe.cbBlob = -1; if (db_event_get(hDBEvent, &dbe)) return 0; @@ -182,7 +178,7 @@ int HookedNewEvent(WPARAM wParam, LPARAM hDBEvent) pbuf++; } - wchar_t *c1 = nullptr, *c2 = nullptr; + ptrW c1, c2; if (i1 == 1) c1 = mir_wstrdup(Clist_GetContactDisplayName(wParam)); else if (i1 == 2) @@ -196,8 +192,5 @@ int HookedNewEvent(WPARAM wParam, LPARAM hDBEvent) wchar_t buffer[512]; mir_snwprintf(buffer, buf, c1, c2); ShowOSD(buffer, 0, g_plugin.getDword("clr_msg", DEFAULT_CLRMSG), wParam); - - mir_free(c1); - mir_free(c2); return 0; } diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 4f2d25d35d..6cdef5e4de 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -390,9 +390,8 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) if (!bIsNew) { MEVENT hOldEvent = db_event_getById(m_szModuleName, szMsgId); if (hOldEvent) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hOldEvent); - dbei.pBlob = (BYTE*)mir_alloc(dbei.cbBlob); + DB::EventInfo dbei; + dbei.cbBlob = -1; if (!db_event_get(hOldEvent, &dbei)) { ptrW wszOldText(DbEvent_GetTextW(&dbei, CP_UTF8)); if (wszOldText) @@ -400,7 +399,6 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) if (dbei.flags & DBEF_SENT) bOurMessage = true; } - mir_free(dbei.pBlob); } } diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index c8304b6375..e5a62df682 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -374,9 +374,8 @@ int CDiscordProto::AuthRecv(MCONTACT, PROTORECVEVENT *pre) int CDiscordProto::Authorize(MEVENT hDbEvent) { - 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) return 1; if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1; @@ -390,9 +389,8 @@ int CDiscordProto::Authorize(MEVENT hDbEvent) int CDiscordProto::AuthDeny(MEVENT hDbEvent, const wchar_t*) { - 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) return 1; if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1; 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) diff --git a/protocols/SkypeWeb/src/skype_db.cpp b/protocols/SkypeWeb/src/skype_db.cpp index 0dc8e8ce8b..e8ac1ab738 100644 --- a/protocols/SkypeWeb/src/skype_db.cpp +++ b/protocols/SkypeWeb/src/skype_db.cpp @@ -58,11 +58,11 @@ MEVENT CSkypeProto::AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DW void CSkypeProto::EditEvent(MCONTACT hContact, MEVENT hEvent, const CMStringW &szContent, time_t edit_time) { mir_cslock lck(m_AppendMessageLock); - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hEvent); - mir_ptr blob((PBYTE)mir_alloc(dbei.cbBlob)); - dbei.pBlob = blob; - db_event_get(hEvent, &dbei); + + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(hEvent, &dbei)) + return; JSONNode jMsg = JSONNode::parse((char*)dbei.pBlob); if (jMsg) { diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index f5cc5f5bd9..6bc6e8e66e 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -192,11 +192,9 @@ MCONTACT CSkypeProto::AddToList(int, PROTOSEARCHRESULT *psr) MCONTACT CSkypeProto::AddToListByEvent(int, int, MEVENT hDbEvent) { debugLogA(__FUNCTION__); - DBEVENTINFO dbei = {}; - if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) - return NULL; - if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == nullptr) - return NULL; + + DB::EventInfo dbei; + dbei.cbBlob = -1; if (db_event_get(hDbEvent, &dbei)) return NULL; if (mir_strcmp(dbei.szModule, m_szModuleName)) @@ -205,9 +203,7 @@ MCONTACT CSkypeProto::AddToListByEvent(int, int, MEVENT hDbEvent) return NULL; DB::AUTH_BLOB blob(dbei.pBlob); - - MCONTACT hContact = AddContact(blob.get_email(), blob.get_nick()); - return hContact; + return AddContact(blob.get_email(), blob.get_nick()); } int CSkypeProto::Authorize(MEVENT hDbEvent) diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index 35bef1b6db..4b05b6c32d 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -109,17 +109,14 @@ MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT *psr) MCONTACT CSteamProto::AddToListByEvent(int, int, MEVENT hDbEvent) { - DBEVENTINFO dbei = {}; - if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) - return NULL; - if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == nullptr) - return NULL; + DB::EventInfo dbei; + dbei.cbBlob = -1; if (db_event_get(hDbEvent, &dbei)) - return NULL; + return 0; if (mir_strcmp(dbei.szModule, m_szModuleName)) - return NULL; + return 0; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) - return NULL; + return 0; DB::AUTH_BLOB blob(dbei.pBlob); return AddContact(blob.get_email(), Utf2T(blob.get_nick())); diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 3859a1696c..2f3d8f74e6 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -1739,10 +1739,8 @@ MEVENT CVkProto::GetMessageFromDb(const char *messageId, UINT ×tamp, CMStri if (!hDbEvent) return 0; - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - mir_ptr blob((PBYTE)mir_alloc(dbei.cbBlob)); - dbei.pBlob = blob; + DB::EventInfo dbei; + dbei.cbBlob = -1; db_event_get(hDbEvent, &dbei); msg = ptrW(mir_utf8decodeW((char*)dbei.pBlob)); diff --git a/src/core/stdfile/src/filerecvdlg.cpp b/src/core/stdfile/src/filerecvdlg.cpp index d9b54d4f8a..a1e11bafb5 100644 --- a/src/core/stdfile/src/filerecvdlg.cpp +++ b/src/core/stdfile/src/filerecvdlg.cpp @@ -222,12 +222,9 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l db_event_markRead(dat->hContact, dat->hDbEvent); - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent); - if (dbei.cbBlob > 4 && dbei.cbBlob <= 8196) { - dbei.pBlob = (PBYTE)alloca(dbei.cbBlob + 1); - db_event_get(dat->hDbEvent, &dbei); - dbei.pBlob[dbei.cbBlob] = 0; + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (!db_event_get(dat->hDbEvent, &dbei)) { dat->fs = cle->lParam ? (HANDLE)cle->lParam : (HANDLE)*(PDWORD)dbei.pBlob; char *str = (char*)dbei.pBlob + 4; diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 3161dff215..7905452248 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -201,17 +201,13 @@ int DbEventIsShown(DBEVENTINFO *dbei) //mir_free() the return value static bool CreateRTFFromDbEvent(LogStreamData *dat) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent); - if (dbei.cbBlob == -1) + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(dat->hDbEvent, &dbei)) return false; - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); - db_event_get(dat->hDbEvent, &dbei); - if (!DbEventIsShown(&dbei)) { - mir_free(dbei.pBlob); + if (!DbEventIsShown(&dbei)) return false; - } if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) { db_event_markRead(dat->hContact, dat->hDbEvent); @@ -338,7 +334,6 @@ static bool CreateRTFFromDbEvent(LogStreamData *dat) if (bIsRtl) buf.Append("\\par"); - mir_free(dbei.pBlob); return true; } diff --git a/src/core/stduihist/src/history.cpp b/src/core/stduihist/src/history.cpp index f76bf5c6cb..aadf8491e5 100644 --- a/src/core/stduihist/src/history.cpp +++ b/src/core/stduihist/src/history.cpp @@ -122,19 +122,12 @@ static void FillHistoryThread(THistoryThread *hInfo) int i = db_event_count(hInfo->hContact); SendDlgItemMessage(hInfo->hwnd, IDC_LIST, LB_INITSTORAGE, i, i * 40); - DBEVENTINFO dbei = {}; - int oldBlobSize = 0; - MEVENT hDbEvent = db_event_last(hInfo->hContact); - - while (hDbEvent != NULL) { + DB::ECPTR pCursor(DB::EventsRev(hInfo->hContact)); + while (MEVENT hDbEvent = pCursor.FetchNext()) { if (!IsWindow(hInfo->hwnd)) break; - int newBlobSize = db_event_getBlobSize(hDbEvent); - if (newBlobSize > oldBlobSize) { - dbei.pBlob = (PBYTE)mir_realloc(dbei.pBlob, newBlobSize); - oldBlobSize = newBlobSize; - } - dbei.cbBlob = oldBlobSize; + + DBEVENTINFO dbei = {}; db_event_get(hDbEvent, &dbei); wchar_t str[200], eventText[256], strdatetime[64]; @@ -145,9 +138,7 @@ static void FillHistoryThread(THistoryThread *hInfo) i = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)eventText); SendMessage(hwndList, LB_SETITEMDATA, i, (LPARAM)hDbEvent); } - hDbEvent = db_event_prev(hInfo->hContact, hDbEvent); } - mir_free(dbei.pBlob); SendDlgItemMessage(hInfo->hwnd, IDC_LIST, LB_SETCURSEL, 0, 0); SendMessage(hInfo->hwnd, WM_COMMAND, MAKEWPARAM(IDC_LIST, LBN_SELCHANGE), 0); @@ -281,16 +272,12 @@ 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); - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if ((int)dbei.cbBlob != -1) { - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); - if (db_event_get(hDbEvent, &dbei) == 0) { - ptrW wszDescr(DbEvent_GetTextW(&dbei, CP_ACP)); - if (wszDescr) - SetDlgItemText(hwndDlg, IDC_EDIT, wszDescr); - } - mir_free(dbei.pBlob); + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (!db_event_get(hDbEvent, &dbei)) { + ptrW wszDescr(DbEvent_GetTextW(&dbei, CP_ACP)); + if (wszDescr) + SetDlgItemText(hwndDlg, IDC_EDIT, wszDescr); } } return TRUE; diff --git a/src/mir_app/src/auth.cpp b/src/mir_app/src/auth.cpp index 7419de4513..dd448a2b61 100644 --- a/src/mir_app/src/auth.cpp +++ b/src/mir_app/src/auth.cpp @@ -53,14 +53,9 @@ public: Button_SetSkin_IcoLib(m_hwnd, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details")); Button_SetSkin_IcoLib(m_hwnd, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list")); - int iBlobSize = db_event_getBlobSize(m_hDbEvent); - if (iBlobSize == -1) - return false; - // blob is: uin(DWORD), hcontact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ) DBEVENTINFO dbei = {}; - dbei.cbBlob = iBlobSize; - dbei.pBlob = (PBYTE)alloca(dbei.cbBlob); + dbei.cbBlob = -1; if (db_event_get(m_hDbEvent, &dbei)) return false; @@ -200,9 +195,8 @@ public: Button_SetSkin_IcoLib(m_hwnd, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list")); // blob is: uin(DWORD), hcontact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(m_hDbEvent); - dbei.pBlob = (PBYTE)alloca(dbei.cbBlob); + DB::EventInfo dbei; + dbei.cbBlob = -1; db_event_get(m_hDbEvent, &dbei); m_hContact = DbGetAuthEventContact(&dbei); @@ -298,13 +292,12 @@ static int AuthEventAdded(WPARAM, LPARAM lParam) wchar_t szTooltip[256]; MEVENT hDbEvent = (MEVENT)lParam; - DBEVENTINFO dbei = {}; + DB::EventInfo dbei; db_event_get(lParam, &dbei); if (dbei.flags & (DBEF_SENT | DBEF_READ) || (dbei.eventType != EVENTTYPE_AUTHREQUEST && dbei.eventType != EVENTTYPE_ADDED)) return 0; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - dbei.pBlob = (PBYTE)alloca(dbei.cbBlob); + dbei.cbBlob = -1; db_event_get(hDbEvent, &dbei); MCONTACT hContact = DbGetAuthEventContact(&dbei); -- cgit v1.2.3