summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/m_database.h27
-rw-r--r--include/m_db_int.h6
-rw-r--r--libs/win32/mir_app.libbin242102 -> 243830 bytes
-rw-r--r--libs/win32/mir_core.libbin491056 -> 491050 bytes
-rw-r--r--libs/win64/mir_app.libbin239074 -> 240858 bytes
-rw-r--r--plugins/Db3x_mmap/src/dbevents.cpp2
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h2
-rw-r--r--plugins/DbChecker/src/worker.cpp2
-rw-r--r--plugins/Dbx_mdbx/src/dbevents.cpp26
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h4
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp53
-rw-r--r--plugins/Dbx_sqlite/src/dbintf.h2
-rw-r--r--plugins/Dbx_sqlite/src/dbsettings.cpp2
-rw-r--r--plugins/IEView/src/HTMLBuilder.cpp6
-rw-r--r--plugins/Import/src/dbrw/dbevents.cpp2
-rw-r--r--plugins/Import/src/dbrw/dbintf.h2
-rw-r--r--plugins/Import/src/textjson.cpp18
-rw-r--r--plugins/Msg_Export/src/utils.cpp22
-rw-r--r--plugins/NewEventNotify/src/popup.cpp40
-rw-r--r--plugins/NewStory/src/history_array.cpp4
-rw-r--r--plugins/NewStory/src/history_array.h2
-rw-r--r--plugins/NewStory/src/history_control.cpp2
-rw-r--r--plugins/Scriver/src/msglog.cpp12
-rw-r--r--plugins/TabSRMM/src/msgdialog.cpp39
-rw-r--r--plugins/TabSRMM/src/msglog.cpp31
-rw-r--r--protocols/Discord/src/server.cpp2
-rw-r--r--protocols/EmLanProto/src/mlan.cpp5
-rw-r--r--protocols/ICQCorp/src/services.cpp6
-rw-r--r--protocols/ICQCorp/src/stdafx.h12
-rw-r--r--protocols/SkypeWeb/src/skype_db.cpp2
-rw-r--r--src/core/stdfile/src/file.cpp50
-rw-r--r--src/core/stdfile/src/filexferdlg.cpp32
-rw-r--r--src/core/stdmsg/src/msglog.cpp10
-rw-r--r--src/mir_app/src/MDatabaseReadonly.cpp2
-rw-r--r--src/mir_app/src/db_events.cpp49
-rw-r--r--src/mir_app/src/mir_app.def8
-rw-r--r--src/mir_app/src/mir_app64.def8
-rw-r--r--src/mir_app/src/proto_interface.cpp2
-rw-r--r--src/mir_core/src/db.cpp4
39 files changed, 240 insertions, 258 deletions
diff --git a/include/m_database.h b/include/m_database.h
index 157046603f..59c0dacb82 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -294,7 +294,7 @@ EXTERN_C MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent, bool bFromServer = f
// Edits an event in the database
// Returns 0 on success, or nonzero on error
-EXTERN_C MIR_CORE_DLL(int) db_event_edit(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO *dbei);
+EXTERN_C MIR_CORE_DLL(int) db_event_edit(MEVENT hDbEvent, const DBEVENTINFO *dbei);
// Tries to find an event by its id if present
// if an event is found, it's edited, otherwise a new event is added
@@ -694,11 +694,30 @@ namespace DB
};
/////////////////////////////////////////////////////////////////////////////////////////
- // Helper to process the auth req body
- // blob is: 0(uint32_t), hContact(uint32_t), nick(UTF8), firstName(UTF8), lastName(UTF8), email(UTF8), reason(UTF8)
+ // Helper for file transfer events
+ #pragma warning(push)
#pragma warning(disable : 4251)
+ class MIR_APP_EXPORT FILE_BLOB : public MNonCopyable
+ {
+ ptrW m_wszFileName, m_wszDescription;
+
+ public:
+ explicit FILE_BLOB(const wchar_t *pwszName, const wchar_t *pwszDescr = nullptr);
+ explicit FILE_BLOB(const EventInfo &dbei);
+ ~FILE_BLOB();
+
+ void write(EventInfo &dbei);
+
+ __forceinline const wchar_t* getName() const { return m_wszFileName; }
+ __forceinline const wchar_t* getDescr() const { return m_wszDescription; }
+ };
+
+ /////////////////////////////////////////////////////////////////////////////////////////
+ // Helper to process the auth req body
+ // blob is: 0(uint32_t), hContact(uint32_t), nick(UTF8), firstName(UTF8), lastName(UTF8), email(UTF8), reason(UTF8)
+
class MIR_APP_EXPORT AUTH_BLOB
{
MCONTACT m_hContact;
@@ -729,6 +748,8 @@ namespace DB
__forceinline void set_uin(uint32_t dwValue) { m_dwUin = dwValue; }
};
+ #pragma warning(pop)
+
/////////////////////////////////////////////////////////////////////////////////////////
// Event cursors
diff --git a/include/m_db_int.h b/include/m_db_int.h
index 661ad565f4..7c1e5f2461 100644
--- a/include/m_db_int.h
+++ b/include/m_db_int.h
@@ -122,7 +122,7 @@ interface MIR_APP_EXPORT MIDatabase
STDMETHOD_(int, GetEventCount)(MCONTACT contactID) PURE;
STDMETHOD_(MEVENT, AddEvent)(MCONTACT contactID, const DBEVENTINFO *dbe) PURE;
STDMETHOD_(BOOL, DeleteEvent)(MEVENT hDbEvent) PURE;
- STDMETHOD_(BOOL, EditEvent)(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe) PURE;
+ STDMETHOD_(BOOL, EditEvent)(MEVENT hDbEvent, const DBEVENTINFO *dbe) PURE;
STDMETHOD_(int, GetBlobSize)(MEVENT hDbEvent) PURE;
STDMETHOD_(BOOL, GetEvent)(MEVENT hDbEvent, DBEVENTINFO *dbe) PURE;
STDMETHOD_(BOOL, MarkEventRead)(MCONTACT contactID, MEVENT hDbEvent) PURE;
@@ -170,7 +170,7 @@ interface MIR_APP_EXPORT MIDatabase
/////////////////////////////////////////////////////////////////////////////////////////
#pragma warning(push)
-#pragma warning(disable:4275)
+#pragma warning(disable:4275 4251)
struct MICryptoEngine;
struct CRYPTO_PROVIDER;
@@ -284,7 +284,7 @@ public:
////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP_(MEVENT) AddEvent(MCONTACT, const DBEVENTINFO*) override;
STDMETHODIMP_(BOOL) DeleteEvent(MEVENT) override;
- STDMETHODIMP_(BOOL) EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
+ STDMETHODIMP_(BOOL) EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(int) GetBlobSize(MEVENT) override;
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT, MEVENT) override;
STDMETHODIMP_(MCONTACT) GetEventContact(MEVENT) override;
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib
index a5b960b509..8a1dbc3fab 100644
--- a/libs/win32/mir_app.lib
+++ b/libs/win32/mir_app.lib
Binary files differ
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib
index d9dbb534ec..0fcd25d444 100644
--- a/libs/win32/mir_core.lib
+++ b/libs/win32/mir_core.lib
Binary files differ
diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib
index adcf351afd..f1f10235c0 100644
--- a/libs/win64/mir_app.lib
+++ b/libs/win64/mir_app.lib
Binary files differ
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp
index e566ff120b..d2a694bd53 100644
--- a/plugins/Db3x_mmap/src/dbevents.cpp
+++ b/plugins/Db3x_mmap/src/dbevents.cpp
@@ -263,7 +263,7 @@ BOOL CDb3Mmap::DeleteEvent(MEVENT hDbEvent)
return 0;
}
-BOOL CDb3Mmap::EditEvent(MCONTACT, MEVENT, const DBEVENTINFO*)
+BOOL CDb3Mmap::EditEvent(MEVENT, const DBEVENTINFO*)
{
return 1;
}
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index 287d052d02..e9a558dec7 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -210,7 +210,7 @@ public:
STDMETHODIMP_(int) GetEventCount(MCONTACT contactID) override;
STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) DeleteEvent(MEVENT hDbEvent) override;
- STDMETHODIMP_(BOOL) EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
+ STDMETHODIMP_(BOOL) EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(int) GetBlobSize(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) override;
diff --git a/plugins/DbChecker/src/worker.cpp b/plugins/DbChecker/src/worker.cpp
index c2e458a921..8ee18e45da 100644
--- a/plugins/DbChecker/src/worker.cpp
+++ b/plugins/DbChecker/src/worker.cpp
@@ -101,7 +101,7 @@ void __cdecl WorkerThread(DbToolOptions *opts)
if (opts->bCheckUtf && dbei.eventType == EVENTTYPE_MESSAGE) {
if (ConvertOldEvent(dbei)) {
- db_event_edit(cc, hEvent, &dbei);
+ db_event_edit(hEvent, &dbei);
nUtfCount++;
}
}
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp
index 3b2c0e4650..3cbb5e5e5a 100644
--- a/plugins/Dbx_mdbx/src/dbevents.cpp
+++ b/plugins/Dbx_mdbx/src/dbevents.cpp
@@ -137,7 +137,7 @@ BOOL CDbxMDBX::DeleteEvent(MEVENT hDbEvent)
/////////////////////////////////////////////////////////////////////////////////////////
-BOOL CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbei)
+BOOL CDbxMDBX::EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbei)
{
if (dbei == nullptr) return 1;
if (dbei->timestamp == 0) return 1;
@@ -150,19 +150,19 @@ BOOL CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO
DBEvent *dbe = (DBEvent*)data.iov_base;
tmp.timestamp = dbe->timestamp;
- return !EditEvent(contactID, hDbEvent, &tmp, false);
+ return !EditEvent(dbe->dwContactID, hDbEvent, &tmp, false);
}
-bool CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbei, bool bNew)
+bool CDbxMDBX::EditEvent(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO *dbei, bool bNew)
{
DBEvent dbe;
- dbe.dwContactID = contactID; // store native or subcontact's id
+ dbe.dwContactID = hContact; // store native or subcontact's id
dbe.iModuleId = GetModuleID(dbei->szModule);
- MCONTACT contactNotifyID = contactID;
+ MCONTACT contactNotifyID = hContact;
DBCachedContact *cc, *ccSub = nullptr;
- if (contactID != 0) {
- if ((cc = m_cache->GetCachedContact(contactID)) == nullptr)
+ if (hContact != 0) {
+ if ((cc = m_cache->GetCachedContact(hContact)) == nullptr)
return false;
if (cc->IsSub()) {
@@ -172,10 +172,10 @@ bool CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO
// set default sub to the event's source
if (!(dbei->flags & DBEF_SENT))
- db_mc_setDefault(cc->contactID, contactID, false);
- contactID = cc->contactID; // and add an event to a metahistory
+ db_mc_setDefault(cc->contactID, hContact, false);
+ hContact = cc->contactID; // and add an event to a metahistory
if (db_mc_isEnabled())
- contactNotifyID = contactID;
+ contactNotifyID = hContact;
}
}
else cc = &m_ccDummy;
@@ -224,15 +224,15 @@ bool CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO
return false;
// add a sorting key
- DBEventSortingKey key2 = { contactID, hDbEvent, dbe.timestamp };
+ DBEventSortingKey key2 = { hContact, hDbEvent, dbe.timestamp };
key.iov_len = sizeof(key2); key.iov_base = &key2;
data.iov_len = 1; data.iov_base = (char*)("");
if (mdbx_put(trnlck, m_dbEventsSort, &key, &data, MDBX_UPSERT) != MDBX_SUCCESS)
return false;
cc->Advance(hDbEvent, dbe);
- if (contactID != 0) {
- MDBX_val keyc = { &contactID, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
+ if (hContact != 0) {
+ MDBX_val keyc = { &hContact, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, MDBX_UPSERT) != MDBX_SUCCESS)
return false;
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index f0e931667b..8166864881 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -162,7 +162,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe
MDBX_txn* StartTran();
bool CheckEvent(DBCachedContact *cc, const DBEvent *dbe, DBCachedContact *&cc2);
- bool EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe, bool bNew);
+ bool EditEvent(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO *dbe, bool bNew);
int PrepareCheck(void);
void TouchFile(void);
@@ -249,7 +249,7 @@ public:
STDMETHODIMP_(int) GetEventCount(MCONTACT contactID) override;
STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) DeleteEvent(MEVENT hDbEvent) override;
- STDMETHODIMP_(BOOL) EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
+ STDMETHODIMP_(BOOL) EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(int) GetBlobSize(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) override;
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index b16a1fd91f..bc8ab23c78 100644
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -11,16 +11,45 @@ static const char add_event_sort_query[] = "INSERT INTO events_srt(id, contact_i
void CDbxSQLite::InitEvents()
{
- sqlite3_stmt *stmt = nullptr;
- sqlite3_prepare_v2(m_db, "SELECT DISTINCT module FROM events;", -1, &stmt, nullptr);
int rc = 0;
- while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
- const char *module = (char*)sqlite3_column_text(stmt, 0);
- if (mir_strlen(module) > 0)
- m_modules.insert(mir_strdup(module));
+ {
+ sqlite3_stmt *stmt = nullptr;
+ sqlite3_prepare_v2(m_db, "SELECT DISTINCT module FROM events;", -1, &stmt, nullptr);
+ while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
+ const char *module = (char *)sqlite3_column_text(stmt, 0);
+ if (mir_strlen(module) > 0)
+ m_modules.insert(mir_strdup(module));
+ }
+ logError(rc, __FILE__, __LINE__);
+ sqlite3_finalize(stmt);
+ }
+
+ // Events convertor
+ DBVARIANT dbv = { DBVT_BYTE };
+ if (GetContactSettingWorker(0, "Compatibility", "DbEvents", &dbv, 0))
+ dbv.bVal = 0;
+
+ if (dbv.bVal < 1) {
+ sqlite3_stmt *stmt = nullptr;
+ sqlite3_prepare_v2(m_db, "SELECT id FROM events WHERE type=1002;", -1, &stmt, nullptr);
+ while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
+ MEVENT hEvent = sqlite3_column_int(stmt, 0);
+
+ DB::EventInfo dbei;
+ dbei.cbBlob = -1;
+ GetEvent(hEvent, &dbei);
+
+ const char *p = (const char*)dbei.pBlob + sizeof(uint32_t);
+ DB::FILE_BLOB blob(DbEvent_GetString(&dbei, p), DbEvent_GetString(&dbei, p + mir_strlen(p) + 1));
+ blob.write(dbei);
+ EditEvent(hEvent, &dbei);
+ }
+ logError(rc, __FILE__, __LINE__);
+ sqlite3_finalize(stmt);
+
+ dbv.bVal = 1;
+ WriteContactSetting(0, "Compatibility", "DbEvents", &dbv);
}
- logError(rc, __FILE__, __LINE__);
- sqlite3_finalize(stmt);
}
void CDbxSQLite::UninitEvents()
@@ -222,7 +251,7 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent)
/////////////////////////////////////////////////////////////////////////////////////////
-BOOL CDbxSQLite::EditEvent(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO *dbei)
+BOOL CDbxSQLite::EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbei)
{
if (dbei == nullptr)
return 1;
@@ -230,10 +259,6 @@ BOOL CDbxSQLite::EditEvent(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO
if (dbei->timestamp == 0)
return 1;
- DBCachedContact *cc = (hContact) ? m_cache->GetCachedContact(hContact) : &m_system;
- if (cc == nullptr)
- return 1;
-
DBEVENTINFO tmp = *dbei;
mir_ptr<uint8_t> pCryptBlob;
if (m_bEncrypted) {
@@ -266,7 +291,7 @@ BOOL CDbxSQLite::EditEvent(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO
lock.unlock();
DBFlush();
- NotifyEventHooks(g_hevEventEdited, hContact, (LPARAM)hDbEvent);
+ NotifyEventHooks(g_hevEventEdited, 0, hDbEvent);
return 0;
}
diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h
index b21abbe51b..6712570cf9 100644
--- a/plugins/Dbx_sqlite/src/dbintf.h
+++ b/plugins/Dbx_sqlite/src/dbintf.h
@@ -126,7 +126,7 @@ public:
STDMETHODIMP_(int) GetEventCount(MCONTACT contactID) override;
STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) DeleteEvent(MEVENT hDbEvent) override;
- STDMETHODIMP_(BOOL) EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
+ STDMETHODIMP_(BOOL) EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(int) GetBlobSize(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) override;
diff --git a/plugins/Dbx_sqlite/src/dbsettings.cpp b/plugins/Dbx_sqlite/src/dbsettings.cpp
index 249a8bc059..d9e33abb91 100644
--- a/plugins/Dbx_sqlite/src/dbsettings.cpp
+++ b/plugins/Dbx_sqlite/src/dbsettings.cpp
@@ -60,7 +60,7 @@ void CDbxSQLite::InitSettings()
FillContactSettings();
DBVARIANT dbv = { DBVT_BYTE };
- if (GetContactSetting(0, "Compatibility", "Sqlite", &dbv))
+ if (GetContactSettingWorker(0, "Compatibility", "Sqlite", &dbv, 0))
dbv.bVal = 0;
if (dbv.bVal < 1) {
diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp
index c853a9b97e..aeab02c14f 100644
--- a/plugins/IEView/src/HTMLBuilder.cpp
+++ b/plugins/IEView/src/HTMLBuilder.cpp
@@ -238,10 +238,8 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event)
eventData->iType = IEED_EVENT_STATUSCHANGE;
}
else if (dbei.eventType == EVENTTYPE_FILE) {
- // blob is: sequenceid(uint32_t),filename(ASCIIZ),description(ASCIIZ)
- char* filename = ((char *)dbei.pBlob) + sizeof(uint32_t);
- char* descr = filename + mir_strlen(filename) + 1;
- eventData->szText.w = DbEvent_GetString(&dbei, filename);
+ DB::FILE_BLOB blob(dbei);
+ eventData->szText.w = mir_wstrdup(blob.getName());
/*if (*descr != '\0') {
CMStringW tmp(FORMAT, L"%s (%s)", eventData->szText.w, ptrW(DbEvent_GetString(&dbei, descr)).get());
mir_free((void*)eventData->szText.w);
diff --git a/plugins/Import/src/dbrw/dbevents.cpp b/plugins/Import/src/dbrw/dbevents.cpp
index 06995bd4a9..95fc34eca3 100644
--- a/plugins/Import/src/dbrw/dbevents.cpp
+++ b/plugins/Import/src/dbrw/dbevents.cpp
@@ -44,7 +44,7 @@ STDMETHODIMP_(BOOL) CDbxSQLite::DeleteEvent(MEVENT)
return FALSE;
}
-BOOL CDbxSQLite::EditEvent(MCONTACT, MEVENT, const DBEVENTINFO*)
+BOOL CDbxSQLite::EditEvent(MEVENT, const DBEVENTINFO*)
{
return 1;
}
diff --git a/plugins/Import/src/dbrw/dbintf.h b/plugins/Import/src/dbrw/dbintf.h
index 2a843b025d..b3494a44c1 100644
--- a/plugins/Import/src/dbrw/dbintf.h
+++ b/plugins/Import/src/dbrw/dbintf.h
@@ -134,7 +134,7 @@ public:
STDMETHODIMP_(int) GetEventCount(MCONTACT contactID) override;
STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) DeleteEvent(MEVENT hDbEvent) override;
- STDMETHODIMP_(BOOL) EditEvent(MCONTACT contactID, MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
+ STDMETHODIMP_(BOOL) EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(int) GetBlobSize(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) override;
diff --git a/plugins/Import/src/textjson.cpp b/plugins/Import/src/textjson.cpp
index d419807ac0..540a414e32 100644
--- a/plugins/Import/src/textjson.cpp
+++ b/plugins/Import/src/textjson.cpp
@@ -156,23 +156,10 @@ public:
}
if (dbei->eventType == EVENTTYPE_FILE) {
- std::string szFile = (*node)["file"].as_string();
- std::string szDescr = (*node)["descr"].as_string();
-
dbei->flags |= DBEF_UTF;
- MBinBuffer buf;
- uint32_t tmp = 0;
- buf.append(&tmp, sizeof(tmp));
- buf.append(szFile.c_str(), szFile.size());
- if (!szDescr.empty()) {
- buf.append(&tmp, 1);
- buf.append(szDescr.c_str(), szDescr.size());
- }
- buf.append(&tmp, 1);
- dbei->cbBlob = (int)buf.length();
- dbei->pBlob = (uint8_t*)mir_alloc(dbei->cbBlob);
- memcpy(dbei->pBlob, buf.data(), buf.length());
+ DB::FILE_BLOB blob((*node)["file"].as_mstring(), (*node)["descr"].as_mstring());
+ blob.write(*(DB::EventInfo*)dbei);
}
else {
std::string szBody = (*node)["body"].as_string();
@@ -180,7 +167,6 @@ public:
int offset;
switch (dbei->eventType) {
case EVENTTYPE_ADDED:
- case EVENTTYPE_FILE:
offset = sizeof(uint32_t);
break;
diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp
index 6efee874e7..ba97c46228 100644
--- a/plugins/Msg_Export/src/utils.cpp
+++ b/plugins/Msg_Export/src/utils.cpp
@@ -629,7 +629,7 @@ static wchar_t* getEventString(DBEVENTINFO &dbei, char *&buf)
return (dbei.flags & DBEF_UTF) ? mir_utf8decodeW(in) : mir_a2u(in);
}
-static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sFilePath, DBEVENTINFO &dbei, bool bAppendOnly)
+static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sFilePath, DB::EventInfo &dbei, bool bAppendOnly)
{
wstring sLocalUser;
wstring sRemoteUser;
@@ -779,13 +779,11 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF
pRoot.push_back(JSONNode("flags", flags));
if (dbei.eventType == EVENTTYPE_FILE) {
- char *p = (char*)dbei.pBlob + sizeof(uint32_t);
- ptrW wszFileName(getEventString(dbei, p));
- ptrW wszDescr(getEventString(dbei, p));
+ DB::FILE_BLOB blob(dbei);
- pRoot << WCHAR_PARAM("file", wszFileName);
- if (mir_wstrlen(wszDescr))
- pRoot << WCHAR_PARAM("descr", wszDescr);
+ pRoot << WCHAR_PARAM("file", blob.getName());
+ if (mir_wstrlen(blob.getDescr()))
+ pRoot << WCHAR_PARAM("descr", blob.getDescr());
}
else {
ptrW msg(DbEvent_GetTextW(&dbei, CP_ACP));
@@ -824,18 +822,16 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF
case EVENTTYPE_FILE:
{
- char *p = (char*)dbei.pBlob + sizeof(uint32_t);
- ptrW wszFileName(getEventString(dbei, p));
- ptrW wszDescr(getEventString(dbei, p));
+ DB::FILE_BLOB blob(dbei);
const wchar_t *pszType = LPGENW("File: ");
bWriteTextToFile(hFile, pszType, bWriteUTF8Format);
- bWriteIndentedToFile(hFile, nIndent, wszFileName, bWriteUTF8Format);
+ bWriteIndentedToFile(hFile, nIndent, blob.getName(), bWriteUTF8Format);
- if (mir_wstrlen(wszDescr)) {
+ if (mir_wstrlen(blob.getDescr())) {
bWriteNewLine(hFile, nIndent);
bWriteTextToFile(hFile, LPGENW("Description: "), bWriteUTF8Format);
- bWriteIndentedToFile(hFile, nIndent, wszDescr, bWriteUTF8Format);
+ bWriteIndentedToFile(hFile, nIndent, blob.getDescr(), bWriteUTF8Format);
}
}
break;
diff --git a/plugins/NewEventNotify/src/popup.cpp b/plugins/NewEventNotify/src/popup.cpp
index 535e981af9..870d0b0835 100644
--- a/plugins/NewEventNotify/src/popup.cpp
+++ b/plugins/NewEventNotify/src/popup.cpp
@@ -144,14 +144,14 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA
/////////////////////////////////////////////////////////////////////////////////////////
-static wchar_t* ShortenPreview(DBEVENTINFO *dbe)
+static wchar_t* ShortenPreview(DB::EventInfo &dbei)
{
bool fAddEllipsis = false;
size_t iPreviewLimit = g_plugin.iLimitPreview;
if (iPreviewLimit > 500 || iPreviewLimit == 0)
iPreviewLimit = 500;
- wchar_t *buf = DbEvent_GetTextW(dbe, CP_ACP);
+ wchar_t *buf = DbEvent_GetTextW(&dbei, CP_ACP);
if (mir_wstrlen(buf) > iPreviewLimit) {
fAddEllipsis = true;
size_t iIndex = iPreviewLimit;
@@ -168,15 +168,15 @@ static wchar_t* ShortenPreview(DBEVENTINFO *dbe)
return buf;
}
-static wchar_t* GetEventPreview(DBEVENTINFO *dbei)
+static wchar_t* GetEventPreview(DB::EventInfo &dbei)
{
wchar_t *comment1 = nullptr;
wchar_t *comment2 = nullptr;
char *commentFix = nullptr;
- char *pBlob = (char *)dbei->pBlob;
+ char *pBlob = (char *)dbei.pBlob;
// now get text
- switch (dbei->eventType) {
+ switch (dbei.eventType) {
case EVENTTYPE_MESSAGE:
if (pBlob)
comment1 = ShortenPreview(dbei);
@@ -185,13 +185,13 @@ static wchar_t* GetEventPreview(DBEVENTINFO *dbei)
case EVENTTYPE_FILE:
if (pBlob) {
- char *p = pBlob + sizeof(uint32_t);
+ DB::FILE_BLOB blob(dbei);
+
// filenames
- comment2 = DbEvent_GetString(dbei, p);
+ comment2 = mir_wstrdup(blob.getName());
// description
- p += mir_strlen(p) + 1;
- if (*p)
- comment1 = DbEvent_GetString(dbei, p);
+ if (*blob.getDescr())
+ comment1 = mir_wstrdup(blob.getDescr());
}
commentFix = POPUP_COMMENT_FILE;
break;
@@ -203,7 +203,7 @@ static wchar_t* GetEventPreview(DBEVENTINFO *dbei)
if (pBlob) {
// count contacts in event
char* pcBlob = pBlob;
- char* pcEnd = pBlob + dbei->cbBlob;
+ char* pcEnd = pBlob + dbei.cbBlob;
int nContacts;
wchar_t szBuf[512];
@@ -241,13 +241,13 @@ static wchar_t* GetEventPreview(DBEVENTINFO *dbei)
mir_snprintf(szUin, "%d", *((uint32_t*)pBlob));
if (mir_strlen(pszNick) > 0) {
- if (dbei->flags & DBEF_UTF)
+ if (dbei.flags & DBEF_UTF)
szNick = mir_utf8decodeW(pszNick);
else
szNick = mir_a2u(pszNick);
}
else if (mir_strlen(pszEmail) > 0) {
- if (dbei->flags & DBEF_UTF)
+ if (dbei.flags & DBEF_UTF)
szNick = mir_utf8decodeW(pszEmail);
else
szNick = mir_a2u(pszEmail);
@@ -267,13 +267,13 @@ static wchar_t* GetEventPreview(DBEVENTINFO *dbei)
case EVENTTYPE_AUTHREQUEST:
if (pBlob) {
- DB::AUTH_BLOB blob(dbei->pBlob);
+ DB::AUTH_BLOB blob(dbei.pBlob);
wchar_t *szNick = nullptr;
if (blob.get_nick())
- szNick = dbei->getString(blob.get_nick());
+ szNick = dbei.getString(blob.get_nick());
else if (blob.get_email())
- szNick = dbei->getString(blob.get_email());
+ szNick = dbei.getString(blob.get_email());
else if (blob.get_uin()) {
char szUin[16];
szNick = mir_a2u(itoa(blob.get_uin(), szUin, 10));
@@ -287,9 +287,9 @@ static wchar_t* GetEventPreview(DBEVENTINFO *dbei)
default:
// support for custom database event types
- DBEVENTTYPEDESCR *pei = DbEvent_GetType(dbei->szModule, dbei->eventType);
+ DBEVENTTYPEDESCR *pei = DbEvent_GetType(dbei.szModule, dbei.eventType);
if (pei && pBlob) {
- comment1 = DbEvent_GetTextW(dbei, CP_ACP);
+ comment1 = DbEvent_GetTextW(&dbei, CP_ACP);
commentFix = pei->descr;
}
else commentFix = POPUP_COMMENT_OTHER;
@@ -392,7 +392,7 @@ int PopupShow(MCONTACT hContact, MEVENT hEvent, UINT eventType)
}
else { // get the needed event data
wcsncpy(pudw.lpwzContactName, Clist_GetContactDisplayName(hContact), MAX_CONTACTNAME);
- wcsncpy(pudw.lpwzText, ptrW(GetEventPreview(&dbe)), MAX_SECONDLINE);
+ wcsncpy(pudw.lpwzText, ptrW(GetEventPreview(dbe)), MAX_SECONDLINE);
}
// send data to popup plugin
@@ -450,7 +450,7 @@ int PopupUpdate(PLUGIN_DATA &pdata, MEVENT hEvent)
}
// prepare event preview
- wszText.Append(ptrW(GetEventPreview(&dbe)));
+ wszText.Append(ptrW(GetEventPreview(dbe)));
wszText.AppendChar('\n');
}
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index 6b64e08c63..08baac7ff7 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -127,8 +127,10 @@ void ItemData::load(bool bFullLoad)
wchar_t buf[MAX_PATH];
CallService(MS_FILE_GETRECEIVEDFILESFOLDERW, hContact, (LPARAM)buf);
{
+ DB::FILE_BLOB blob(dbe);
+
CMStringW wszFileName(buf);
- wszFileName.Append(ptrW(DbEvent_GetTextW(&dbe, CP_ACP)));
+ wszFileName.Append(blob.getName());
// if a filename contains spaces, URL will be broken
if (wszFileName.Find(' ') != -1) {
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index a57b5f42ca..1df5ee2c76 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -10,7 +10,7 @@ struct ItemData
bool bLoaded;
int savedTop;
- DBEVENTINFO dbe;
+ DB::EventInfo dbe;
wchar_t *wtext;
wchar_t *wszNick;
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 398c6b24ab..bcb75402f8 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -179,7 +179,7 @@ struct NewstoryListData : public MZeroedObject
ptrA szUtf(mir_utf8encodeW(pItem->wtext));
pItem->dbe.cbBlob = (int)mir_strlen(szUtf) + 1;
pItem->dbe.pBlob = (uint8_t *)szUtf.get();
- db_event_edit(pItem->hContact, pItem->hEvent, &pItem->dbe);
+ db_event_edit(pItem->hEvent, &pItem->dbe);
if (auto *ppro = Proto_GetInstance(pItem->hContact))
ppro->OnEventEdited(pItem->hContact, pItem->hEvent);
diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp
index f191432ba4..5bd6e406f7 100644
--- a/plugins/Scriver/src/msglog.cpp
+++ b/plugins/Scriver/src/msglog.cpp
@@ -108,17 +108,7 @@ EventData* CMsgDialog::GetEventFromDB(MCONTACT hContact, MEVENT hDbEvent)
else
evt->szNick.w = mir_wstrdup(Clist_GetContactDisplayName(hContact));
- if (evt->eventType == EVENTTYPE_FILE) {
- char *filename = ((char*)dbei.pBlob) + sizeof(uint32_t);
- char *descr = filename + mir_strlen(filename) + 1;
- evt->szText.w = DbEvent_GetString(&dbei, filename);
- if (*descr != 0) {
- ptrW wszDescr(DbEvent_GetString(&dbei, descr));
- CMStringW tmp(FORMAT, L"%s (%s)", evt->szText.w, wszDescr.get());
- replaceStrW(evt->szText.w, tmp.Detach());
- }
- }
- else evt->szText.w = DbEvent_GetTextW(&dbei, CP_UTF8);
+ evt->szText.w = DbEvent_GetTextW(&dbei, CP_UTF8);
if (!m_bUseRtl && Utils_IsRtl(evt->szText.w))
evt->dwFlags |= IEEDF_RTL;
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp
index 5451beac4d..11065a5733 100644
--- a/plugins/TabSRMM/src/msgdialog.cpp
+++ b/plugins/TabSRMM/src/msgdialog.cpp
@@ -935,46 +935,13 @@ void CMsgDialog::onClick_Quote(CCtrlButton*)
}
if (!bUseSelection) {
- DBEVENTINFO dbei = {};
- dbei.cbBlob = db_event_getBlobSize(hDBEvent);
- wchar_t *szText = (wchar_t*)mir_alloc((dbei.cbBlob + 1) * sizeof(wchar_t)); // URLs are made one char bigger for crlf
- dbei.pBlob = (uint8_t*)szText;
- db_event_get(hDBEvent, &dbei);
- int iSize = int(mir_strlen((char*)dbei.pBlob)) + 1;
-
- bool bNeedsFree = false;
- wchar_t *szConverted;
- if (dbei.flags & DBEF_UTF) {
- szConverted = mir_utf8decodeW((char*)szText);
- bNeedsFree = true;
- }
- else {
- if (iSize != (int)dbei.cbBlob)
- szConverted = (wchar_t*)&dbei.pBlob[iSize];
- else {
- szConverted = (wchar_t*)mir_alloc(sizeof(wchar_t) * iSize);
- bNeedsFree = true;
- MultiByteToWideChar(CP_ACP, 0, (char*)dbei.pBlob, -1, szConverted, iSize);
- }
- }
-
- if (dbei.eventType == EVENTTYPE_FILE) {
- size_t iDescr = mir_strlen((char *)(szText + sizeof(uint32_t)));
- memmove(szText, szText + sizeof(uint32_t), iDescr);
- memmove(szText + iDescr + 2, szText + sizeof(uint32_t) + iDescr, dbei.cbBlob - iDescr - sizeof(uint32_t) - 1);
- szText[iDescr] = '\r';
- szText[iDescr + 1] = '\n';
- szConverted = (wchar_t*)mir_alloc(sizeof(wchar_t)* (1 + mir_strlen((char *)szText)));
- MultiByteToWideChar(CP_ACP, 0, (char *)szText, -1, szConverted, 1 + (int)mir_strlen((char *)szText));
- bNeedsFree = true;
- }
+ DB::EventInfo dbei(hDBEvent);
+ ptrW szConverted(DbEvent_GetTextW(&dbei, CP_ACP));
if (szConverted != nullptr)
m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, ptrW(QuoteText(szConverted)));
- mir_free(szText);
- if (bNeedsFree)
- mir_free(szConverted);
+ mir_free(szConverted);
}
SetFocus(m_message.GetHwnd());
diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp
index 86b0caf93a..3499e97cc3 100644
--- a/plugins/TabSRMM/src/msglog.cpp
+++ b/plugins/TabSRMM/src/msglog.cpp
@@ -432,16 +432,14 @@ static char* Template_CreateRTFFromDbEvent(CMsgDialog *dat, MCONTACT hContact, M
bool skipToNext = false, skipFont = false;
bool isBold = false, isItalic = false, isUnderline = false;
- DBEVENTINFO dbei = {};
+ DB::EventInfo dbei;
if (streamData->dbei != nullptr)
- dbei = *(streamData->dbei);
+ memcpy(&dbei, streamData->dbei, sizeof(DBEVENTINFO));
else {
dbei.cbBlob = -1;
db_event_get(hDbEvent, &dbei);
- if (!DbEventIsShown(&dbei)) {
- mir_free(dbei.pBlob);
+ if (!DbEventIsShown(&dbei))
return nullptr;
- }
}
if (dbei.eventType == EVENTTYPE_MESSAGE && !dbei.markedRead())
@@ -455,10 +453,9 @@ static char* Template_CreateRTFFromDbEvent(CMsgDialog *dat, MCONTACT hContact, M
}
CMStringW msg(ptrW(DbEvent_GetTextW(&dbei, CP_UTF8)));
- if (msg.IsEmpty()) {
- mir_free(dbei.pBlob);
+ if (msg.IsEmpty())
return nullptr;
- }
+
msg.TrimRight();
dat->FormatRaw(msg, 1, FALSE);
@@ -854,20 +851,8 @@ static char* Template_CreateRTFFromDbEvent(CMsgDialog *dat, MCONTACT hContact, M
str.Append(GetRTFFont(iFontIDOffset + (isSent ? MSGFONTID_MYMISC : MSGFONTID_YOURMISC)));
str.AppendChar(' ');
}
- {
- char *szFileName = (char *)dbei.pBlob + sizeof(uint32_t);
- ptrW tszFileName(DbEvent_GetString(&dbei, szFileName));
-
- char *szDescr = szFileName + mir_strlen(szFileName) + 1;
- if (*szDescr != 0) {
- ptrW tszDescr(DbEvent_GetString(&dbei, szDescr));
- wchar_t buf[1000];
- mir_snwprintf(buf, L"%s (%s)", tszFileName.get(), tszDescr.get());
- AppendUnicodeToBuffer(str, buf, 0);
- }
- else AppendUnicodeToBuffer(str, tszFileName, 0);
- }
+ AppendUnicodeToBuffer(str, ptrW(DbEvent_GetTextW(&dbei, CP_ACP)), 0);
break;
default:
@@ -1000,8 +985,8 @@ skip:
str.Append("\\par");
- if (streamData->dbei == nullptr)
- mir_free(dbei.pBlob);
+ if (streamData->dbei != nullptr)
+ dbei.pBlob = 0;
dat->m_iLastEventType = MAKELONG((dbei.flags & (DBEF_SENT | DBEF_READ | DBEF_RTL)), dbei.eventType);
dat->m_lastEventTime = dbei.timestamp;
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index 7ac73e38bf..839cf698b5 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -124,7 +124,7 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest
_i64toa_s(msgid, szMsgId, _countof(szMsgId), 10);
MEVENT hDbEvent = db_event_getById(m_szModuleName, szMsgId);
if (hDbEvent != 0)
- bSucceeded = 0 == db_event_edit(pUser->hContact, hDbEvent, &dbei);
+ bSucceeded = 0 == db_event_edit(hDbEvent, &dbei);
if (!bSucceeded) {
dbei.szId = szMsgId;
diff --git a/protocols/EmLanProto/src/mlan.cpp b/protocols/EmLanProto/src/mlan.cpp
index 84dd998b60..535a42a7aa 100644
--- a/protocols/EmLanProto/src/mlan.cpp
+++ b/protocols/EmLanProto/src/mlan.cpp
@@ -907,13 +907,12 @@ void CMLan::RecvFile(CCSDATA *ccs)
char *szFile = pre->szMessage + sizeof(uint32_t);
char *szDesc = szFile + mir_strlen(szFile) + 1;
- DBEVENTINFO dbei = {};
+ DB::EventInfo dbei;
dbei.szModule = MODULENAME;
dbei.timestamp = pre->timestamp;
dbei.flags = pre->flags & (PREF_CREATEREAD ? DBEF_READ : 0);
dbei.eventType = EVENTTYPE_FILE;
- dbei.cbBlob = uint32_t(sizeof(uint32_t) + mir_strlen(szFile) + mir_strlen(szDesc) + 2);
- dbei.pBlob = (uint8_t*)pre->szMessage;
+ DB::FILE_BLOB(_A2T(szFile), _A2T(szDesc)).write(dbei);
db_event_add(ccs->hContact, &dbei);
}
diff --git a/protocols/ICQCorp/src/services.cpp b/protocols/ICQCorp/src/services.cpp
index 07301b8e7a..799c6172f6 100644
--- a/protocols/ICQCorp/src/services.cpp
+++ b/protocols/ICQCorp/src/services.cpp
@@ -368,15 +368,13 @@ static INT_PTR icqRecvFile(WPARAM, LPARAM lParam)
char *szFile = pre->szMessage + sizeof(uint32_t);
char *szDesc = szFile + mir_strlen(szFile) + 1;
- DBEVENTINFO dbei = {};
+ DB::EventInfo dbei;
dbei.szModule = protoName;
dbei.timestamp = pre->timestamp;
dbei.flags = pre->flags & (PREF_CREATEREAD ? DBEF_READ : 0);
dbei.eventType = EVENTTYPE_FILE;
- dbei.cbBlob = sizeof(uint32_t) + (uint32_t)mir_strlen(szFile) + (uint32_t)mir_strlen(szDesc) + 2;
- dbei.pBlob = (uint8_t*)pre->szMessage;
+ DB::FILE_BLOB(_A2T(szFile), _A2T(szDesc)).write(dbei);
db_event_add(ccs->hContact, &dbei);
-
return 0;
}
diff --git a/protocols/ICQCorp/src/stdafx.h b/protocols/ICQCorp/src/stdafx.h
index fb733d654a..c5ac8e73ad 100644
--- a/protocols/ICQCorp/src/stdafx.h
+++ b/protocols/ICQCorp/src/stdafx.h
@@ -28,16 +28,16 @@
#include <time.h>
#include <newpluginapi.h>
+#include <m_clist.h>
#include <m_contacts.h>
-#include <m_protosvc.h>
-#include <m_langpack.h>
#include <m_database.h>
+#include <m_langpack.h>
+#include <m_netlib.h>
#include <m_options.h>
-#include <statusmodes.h>
-#include <m_clist.h>
-#include <m_userinfo.h>
+#include <m_protosvc.h>
#include <m_timezones.h>
-#include <m_netlib.h>
+#include <m_userinfo.h>
+#include <statusmodes.h>
#include "user.h"
#include "transfer.h"
diff --git a/protocols/SkypeWeb/src/skype_db.cpp b/protocols/SkypeWeb/src/skype_db.cpp
index 47a8272777..0fb627a2cb 100644
--- a/protocols/SkypeWeb/src/skype_db.cpp
+++ b/protocols/SkypeWeb/src/skype_db.cpp
@@ -94,7 +94,7 @@ void CSkypeProto::EditEvent(MCONTACT hContact, MEVENT hEvent, const CMStringW &s
std::string newMsg = jMsg.write().c_str();
dbei.cbBlob = int(newMsg.size() + 1);
dbei.pBlob = (uint8_t*)newMsg.c_str();
- db_event_edit(hContact, hEvent, &dbei);
+ db_event_edit(hEvent, &dbei);
}
void CSkypeProto::InitDBEvents()
diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp
index abe3152cdd..126b428c99 100644
--- a/src/core/stdfile/src/file.cpp
+++ b/src/core/stdfile/src/file.cpp
@@ -356,7 +356,7 @@ static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam)
if (pre->fileCount == 0)
return 0;
- DBEVENTINFO dbei = {};
+ DB::EventInfo dbei;
dbei.szModule = Proto_GetBaseAccountName(ccs->hContact);
dbei.timestamp = pre->timestamp;
dbei.eventType = EVENTTYPE_FILE;
@@ -364,47 +364,33 @@ static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam)
if (pre->dwFlags & PREF_CREATEREAD)
dbei.flags |= DBEF_READ;
- bool bUnicode = (pre->dwFlags & PRFF_UNICODE) == PRFF_UNICODE;
+ if ((pre->dwFlags & PRFF_UNICODE) == PRFF_UNICODE) {
+ CMStringW wszFiles;
- const char *szDescr, **pszFiles;
- if (bUnicode) {
- pszFiles = (const char**)alloca(pre->fileCount * sizeof(char*));
- for (int i = 0; i < pre->fileCount; i++)
- pszFiles[i] = mir_utf8encodeW(pre->files.w[i]);
+ for (int i = 0; i < pre->fileCount; i++) {
+ if (i != 0)
+ wszFiles.AppendChar(',');
+ wszFiles.Append(pre->files.w[i]);
+ }
- szDescr = mir_utf8encodeW(pre->descr.w);
+ DB::FILE_BLOB blob(wszFiles, pre->descr.w);
+ blob.write(dbei);
}
else {
- pszFiles = pre->files.a;
- szDescr = pre->descr.a;
- }
-
- dbei.cbBlob = sizeof(uint32_t);
+ CMStringW wszFiles;
- for (int i = 0; i < pre->fileCount; i++)
- dbei.cbBlob += (int)mir_strlen(pszFiles[i]) + 1;
-
- dbei.cbBlob += (int)mir_strlen(szDescr) + 1;
-
- if ((dbei.pBlob = (uint8_t*)mir_alloc(dbei.cbBlob)) == nullptr)
- return 0;
+ for (int i = 0; i < pre->fileCount; i++) {
+ if (i != 0)
+ wszFiles.AppendChar(',');
+ wszFiles.Append(_A2T(pre->files.a[i]));
+ }
- *(uint32_t*)dbei.pBlob = 0;
- uint8_t* p = dbei.pBlob + sizeof(uint32_t);
- for (int i = 0; i < pre->fileCount; i++) {
- mir_strcpy((char*)p, pszFiles[i]);
- p += mir_strlen(pszFiles[i]) + 1;
- if (bUnicode)
- mir_free((void*)pszFiles[i]);
+ DB::FILE_BLOB blob(wszFiles, _A2T(pre->descr.a));
+ blob.write(dbei);
}
- mir_strcpy((char*)p, (szDescr == nullptr) ? "" : szDescr);
- if (bUnicode)
- mir_free((void*)szDescr);
-
MEVENT hdbe = db_event_add(ccs->hContact, &dbei);
PushFileEvent(ccs->hContact, hdbe, pre->lParam);
- mir_free(dbei.pBlob);
return 0;
}
diff --git a/src/core/stdfile/src/filexferdlg.cpp b/src/core/stdfile/src/filexferdlg.cpp
index e545649b5b..5ab3a0679b 100644
--- a/src/core/stdfile/src/filexferdlg.cpp
+++ b/src/core/stdfile/src/filexferdlg.cpp
@@ -78,24 +78,6 @@ static void SetOpenFileButtonStyle(HWND hwndButton, int enabled)
EnableWindow(hwndButton, enabled);
}
-void FillSendData(FileDlgData *dat, DBEVENTINFO &dbei)
-{
- dbei.szModule = Proto_GetBaseAccountName(dat->hContact);
- dbei.eventType = EVENTTYPE_FILE;
- dbei.flags = DBEF_SENT;
- dbei.timestamp = time(0);
- char *szFileNames = mir_utf8encodeW(dat->szFilenames), *szMsg = mir_utf8encodeW(dat->szMsg);
- dbei.flags |= DBEF_UTF;
-
- dbei.cbBlob = int(sizeof(uint32_t) + mir_strlen(szFileNames) + mir_strlen(szMsg) + 2);
- dbei.pBlob = (uint8_t*)mir_alloc(dbei.cbBlob);
- *(PDWORD)dbei.pBlob = 0;
- mir_strcpy((char*)dbei.pBlob + sizeof(uint32_t), szFileNames);
- mir_strcpy((char*)dbei.pBlob + sizeof(uint32_t) + mir_strlen(szFileNames) + 1, szMsg);
-
- mir_free(szFileNames), mir_free(szMsg);
-}
-
static void __cdecl RunVirusScannerThread(virusscanthreadstartinfo *info)
{
DBVARIANT dbv;
@@ -650,11 +632,17 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
dat->fs = nullptr; /* protocol will free structure */
SetFtStatus(hwndDlg, LPGENW("Transfer completed."), FTS_TEXT);
- DBEVENTINFO dbei = {};
- FillSendData(dat, dbei);
+ DB::EventInfo dbei;
+ dbei.szModule = Proto_GetBaseAccountName(dat->hContact);
+ dbei.eventType = EVENTTYPE_FILE;
+ dbei.flags = DBEF_SENT;
+ dbei.timestamp = time(0);
+ dbei.flags |= DBEF_UTF;
+
+ DB::FILE_BLOB blob(dat->szFilenames, dat->szMsg);
+ blob.write(dbei);
db_event_add(dat->hContact, &dbei);
- if (dbei.pBlob)
- mir_free(dbei.pBlob);
+
dat->files = nullptr; //protocol library frees this
}
else {
diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp
index c20b597beb..290c8ad77e 100644
--- a/src/core/stdmsg/src/msglog.cpp
+++ b/src/core/stdmsg/src/msglog.cpp
@@ -304,18 +304,16 @@ static bool CreateRTFFromDbEvent(LogStreamData *dat)
case EVENTTYPE_FILE:
{
- char *filename = (char*)dbei.pBlob + sizeof(uint32_t);
- char *descr = filename + mir_strlen(filename) + 1;
+ DB::FILE_BLOB blob(dbei);
SetToStyle(MSGFONTID_NOTICE, buf);
AppendToBufferWithRTF(buf, (dbei.flags & DBEF_SENT) ? TranslateT("File sent") : TranslateT("File received"));
buf.Append(": ");
- AppendToBufferWithRTF(buf, ptrW(DbEvent_GetString(&dbei, filename)));
+ AppendToBufferWithRTF(buf, blob.getName());
- if (*descr != 0) {
- ptrW ptszDescr(DbEvent_GetString(&dbei, descr));
+ if (*blob.getDescr() != 0) {
buf.Append(" (");
- AppendToBufferWithRTF(buf, ptszDescr);
+ AppendToBufferWithRTF(buf, blob.getDescr());
buf.Append(")");
}
}
diff --git a/src/mir_app/src/MDatabaseReadonly.cpp b/src/mir_app/src/MDatabaseReadonly.cpp
index c386c4d6f4..9a0194373a 100644
--- a/src/mir_app/src/MDatabaseReadonly.cpp
+++ b/src/mir_app/src/MDatabaseReadonly.cpp
@@ -108,7 +108,7 @@ BOOL MDatabaseReadonly::DeleteEvent(MEVENT)
return 1;
}
-BOOL MDatabaseReadonly::EditEvent(MCONTACT, MEVENT, const DBEVENTINFO*)
+BOOL MDatabaseReadonly::EditEvent(MEVENT, const DBEVENTINFO*)
{
return 1;
}
diff --git a/src/mir_app/src/db_events.cpp b/src/mir_app/src/db_events.cpp
index f4153d6850..9e413aac76 100644
--- a/src/mir_app/src/db_events.cpp
+++ b/src/mir_app/src/db_events.cpp
@@ -98,7 +98,7 @@ static wchar_t* getEventString(DBEVENTINFO *dbei, LPSTR &buf)
return (dbei->flags & DBEF_UTF) ? mir_utf8decodeW(in) : mir_a2u(in);
}
-static INT_PTR DbEventGetTextWorker(DBEVENTINFO *dbei, int codepage, int datatype)
+static INT_PTR DbEventGetTextWorker(DB::EventInfo *dbei, int codepage, int datatype)
{
if (dbei == nullptr || dbei->szModule == nullptr)
return 0;
@@ -162,13 +162,12 @@ static INT_PTR DbEventGetTextWorker(DBEVENTINFO *dbei, int codepage, int datatyp
}
if (dbei->eventType == EVENTTYPE_FILE) {
- char *buf = LPSTR(dbei->pBlob) + sizeof(uint32_t);
- ptrW tszFileName(getEventString(dbei, buf));
- ptrW tszDescription(getEventString(dbei, buf));
- CMStringW wszText(tszFileName.get());
- if (mir_wstrlen(tszDescription) > 0) {
+ DB::FILE_BLOB blob(*dbei);
+
+ CMStringW wszText(blob.getName());
+ if (mir_wstrlen(blob.getDescr()) > 0) {
wszText.Append(L": ");
- wszText.Append(tszDescription);
+ wszText.Append(blob.getDescr());
}
switch (datatype) {
@@ -208,12 +207,12 @@ static INT_PTR DbEventGetTextWorker(DBEVENTINFO *dbei, int codepage, int datatyp
MIR_APP_DLL(char*) DbEvent_GetTextA(DBEVENTINFO *dbei, int codepage)
{
- return (char*)DbEventGetTextWorker(dbei, codepage, DBVT_ASCIIZ);
+ return (char*)DbEventGetTextWorker((DB::EventInfo *)dbei, codepage, DBVT_ASCIIZ);
}
MIR_APP_DLL(wchar_t*) DbEvent_GetTextW(DBEVENTINFO *dbei, int codepage)
{
- return (wchar_t*)DbEventGetTextWorker(dbei, codepage, DBVT_WCHAR);
+ return (wchar_t*)DbEventGetTextWorker((DB::EventInfo *)dbei, codepage, DBVT_WCHAR);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -285,6 +284,38 @@ DB::EventInfo::~EventInfo()
}
/////////////////////////////////////////////////////////////////////////////////////////
+// File blob helper
+
+DB::FILE_BLOB::FILE_BLOB(const wchar_t *pwszName, const wchar_t *pwszDescr) :
+ m_wszFileName(mir_wstrdup(pwszName)),
+ m_wszDescription(mir_wstrdup(pwszDescr))
+{}
+
+DB::FILE_BLOB::FILE_BLOB(const DB::EventInfo &dbei)
+{
+ JSONNode root = JSONNode::parse((const char *)dbei.pBlob);
+ if (root) {
+ m_wszFileName = root["f"].as_mstring().Detach();
+ m_wszDescription = root["d"].as_mstring().Detach();
+ }
+}
+
+DB::FILE_BLOB::~FILE_BLOB()
+{}
+
+void DB::FILE_BLOB::write(DB::EventInfo &dbei)
+{
+ JSONNode root;
+ root << WCHAR_PARAM("f", m_wszFileName) << WCHAR_PARAM("d", m_wszDescription ? m_wszDescription : L"");
+
+ std::string text = root.write();
+ dbei.cbBlob = (int)text.size() + 1;
+ dbei.pBlob = (uint8_t*)mir_realloc(dbei.pBlob, dbei.cbBlob);
+ memcpy(dbei.pBlob, text.c_str(), dbei.cbBlob);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Auth blob helper
DB::AUTH_BLOB::AUTH_BLOB(MCONTACT hContact, LPCSTR nick, LPCSTR fname, LPCSTR lname, LPCSTR email, LPCSTR reason) :
m_dwUin(0),
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 68c051c394..92990599e4 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -572,7 +572,7 @@ Menu_SetVisible @662
??0MDatabaseReadonly@@QAE@XZ @684 NONAME
??_7MDatabaseReadonly@@6B@ @685 NONAME
?GetEventById@MDatabaseReadonly@@UAGIPBD0@Z @686 NONAME
-?EditEvent@MDatabaseReadonly@@UAGHIIPBUDBEVENTINFO@@@Z @688 NONAME
+?EditEvent@MDatabaseReadonly@@UAGHIPBUDBEVENTINFO@@@Z @688 NONAME
g_hevContactAdded @689 NONAME
g_hevContactDeleted @690 NONAME
g_hevEventAdded @691 NONAME
@@ -837,3 +837,9 @@ Chat_IsMuted @941 NONAME
??0EventInfo@DB@@QAE@XZ @952 NONAME
??1EventInfo@DB@@QAE@XZ @953 NONAME
??BEventInfo@DB@@QBE_NXZ @954 NONAME
+??0FILE_BLOB@DB@@QAE@ABVEventInfo@1@@Z @955 NONAME
+??0FILE_BLOB@DB@@QAE@PB_W0@Z @956 NONAME
+??1FILE_BLOB@DB@@QAE@XZ @957 NONAME
+?getDescr@FILE_BLOB@DB@@QBEPB_WXZ @958 NONAME
+?getName@FILE_BLOB@DB@@QBEPB_WXZ @959 NONAME
+?write@FILE_BLOB@DB@@QAEXAAVEventInfo@2@@Z @960 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 6f977c0379..41bbf55dc6 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -572,7 +572,7 @@ Menu_SetVisible @662
??0MDatabaseReadonly@@QEAA@XZ @684 NONAME
??_7MDatabaseReadonly@@6B@ @685 NONAME
?GetEventById@MDatabaseReadonly@@UEAAIPEBD0@Z @686 NONAME
-?EditEvent@MDatabaseReadonly@@UEAAHIIPEBUDBEVENTINFO@@@Z @688 NONAME
+?EditEvent@MDatabaseReadonly@@UEAAHIPEBUDBEVENTINFO@@@Z @688 NONAME
g_hevContactAdded @689 NONAME
g_hevContactDeleted @690 NONAME
g_hevEventAdded @691 NONAME
@@ -837,3 +837,9 @@ Chat_IsMuted @941 NONAME
??0EventInfo@DB@@QEAA@XZ @952 NONAME
??1EventInfo@DB@@QEAA@XZ @953 NONAME
??BEventInfo@DB@@QEBA_NXZ @954 NONAME
+??0FILE_BLOB@DB@@QEAA@AEBVEventInfo@1@@Z @955 NONAME
+??0FILE_BLOB@DB@@QEAA@PEB_W0@Z @956 NONAME
+??1FILE_BLOB@DB@@QEAA@XZ @957 NONAME
+?getDescr@FILE_BLOB@DB@@QEBAPEB_WXZ @958 NONAME
+?getName@FILE_BLOB@DB@@QEBAPEB_WXZ @959 NONAME
+?write@FILE_BLOB@DB@@QEAAXAEAVEventInfo@2@@Z @960 NONAME
diff --git a/src/mir_app/src/proto_interface.cpp b/src/mir_app/src/proto_interface.cpp
index a1b005d16b..07a276d20a 100644
--- a/src/mir_app/src/proto_interface.cpp
+++ b/src/mir_app/src/proto_interface.cpp
@@ -223,7 +223,7 @@ MEVENT PROTO_INTERFACE::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
// if it's possible to find an existing event by its id, do that
if ((GetCaps(PFLAGNUM_4) & PF4_SERVERMSGID) && pre->szMsgId != nullptr) {
MEVENT hDbEvent = db_event_getById(m_szModuleName, pre->szMsgId);
- if (hDbEvent == 0 || db_event_edit(hContact, hDbEvent, &dbei)) {
+ if (hDbEvent == 0 || db_event_edit(hDbEvent, &dbei)) {
dbei.szId = pre->szMsgId;
hDbEvent = db_event_add(hContact, &dbei);
}
diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp
index 3c92e965c2..e5d8d508ae 100644
--- a/src/mir_core/src/db.cpp
+++ b/src/mir_core/src/db.cpp
@@ -426,9 +426,9 @@ MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent, bool bFromServer)
return g_pCurrDb->DeleteEvent(hDbEvent);
}
-MIR_CORE_DLL(int) db_event_edit(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO *dbei)
+MIR_CORE_DLL(int) db_event_edit(MEVENT hDbEvent, const DBEVENTINFO *dbei)
{
- return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->EditEvent(hContact, hDbEvent, dbei);
+ return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->EditEvent(hDbEvent, dbei);
}
MIR_CORE_DLL(MEVENT) db_event_first(MCONTACT hContact)