diff options
author | George Hazan <ghazan@miranda.im> | 2023-04-10 18:50:46 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-04-10 18:50:46 +0300 |
commit | 90ac4c689e1322b48f6ca53a0c8fff81daf73c9c (patch) | |
tree | 63e000a99864d819650634fe8a7fa8b2be0cd1d2 /src | |
parent | 79ac0acda98f8f7a34bde30b7720a11c04281cb4 (diff) |
code cleaning
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdfile/src/filerecvdlg.cpp | 5 | ||||
-rw-r--r-- | src/core/stdmsg/src/msglog.cpp | 5 | ||||
-rw-r--r-- | src/core/stduihist/src/history.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/auth.cpp | 8 | ||||
-rw-r--r-- | src/mir_app/src/chat_svc.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/db_events.cpp | 21 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 3 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 3 | ||||
-rw-r--r-- | src/mir_app/src/srmm_base.cpp | 5 |
9 files changed, 39 insertions, 21 deletions
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)
|