summaryrefslogtreecommitdiff
path: root/plugins/ContactsPlus
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-06-05 17:50:34 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-06-05 17:50:34 +0300
commitd7c9eb34f80f207efd47d2fc65e31aedf166c323 (patch)
tree338b9b905674dc31b1efab739dfcedeed3d8d7b3 /plugins/ContactsPlus
parentffc5a3d7550528281976745279e77ac9faba551b (diff)
major code cleaning in regard to db_event_getBlobSize & event memory allocation
Diffstat (limited to 'plugins/ContactsPlus')
-rw-r--r--plugins/ContactsPlus/src/main.cpp45
-rw-r--r--plugins/ContactsPlus/src/receive.cpp11
2 files changed, 25 insertions, 31 deletions
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();