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 --- plugins/ContactsPlus/src/main.cpp | 45 +++++++++++++++++------------------- plugins/ContactsPlus/src/receive.cpp | 11 ++++----- 2 files changed, 25 insertions(+), 31 deletions(-) (limited to 'plugins/ContactsPlus') 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(); -- cgit v1.2.3