summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-09-19 15:34:32 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-09-19 15:34:32 +0300
commit77ea5b95cd68a295068394e9d0c505f0b26221ba (patch)
tree5b3dca3184ba08a040df418bd638efbe8a9ed7c2 /plugins/Dbx_mdbx
parent8dd934a1e0e80b1c14194195f4664bc9a6e685cc (diff)
GetEventById & SetEventId - two new methods to operate with events by their server ids
Diffstat (limited to 'plugins/Dbx_mdbx')
-rw-r--r--plugins/Dbx_mdbx/src/dbcontacts.cpp8
-rw-r--r--plugins/Dbx_mdbx/src/dbevents.cpp63
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp2
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h67
-rw-r--r--plugins/Dbx_mdbx/src/dbmodulechain.cpp2
-rw-r--r--plugins/Dbx_mdbx/src/dbsettings.cpp6
6 files changed, 95 insertions, 53 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcontacts.cpp b/plugins/Dbx_mdbx/src/dbcontacts.cpp
index 320b479984..4216d7da3e 100644
--- a/plugins/Dbx_mdbx/src/dbcontacts.cpp
+++ b/plugins/Dbx_mdbx/src/dbcontacts.cpp
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-STDMETHODIMP_(LONG) CDbxMDBX::GetContactCount(void)
+LONG CDbxMDBX::GetContactCount(void)
{
MDBX_stat st;
txn_ptr_ro trnlck(m_txn_ro);
@@ -31,12 +31,12 @@ STDMETHODIMP_(LONG) CDbxMDBX::GetContactCount(void)
return st.ms_entries;
}
-STDMETHODIMP_(LONG) CDbxMDBX::GetContactSize(void)
+LONG CDbxMDBX::GetContactSize(void)
{
return sizeof(DBCachedContact);
}
-STDMETHODIMP_(LONG) CDbxMDBX::DeleteContact(MCONTACT contactID)
+LONG CDbxMDBX::DeleteContact(MCONTACT contactID)
{
if (contactID == 0) // global contact cannot be removed
return 1;
@@ -84,7 +84,7 @@ STDMETHODIMP_(LONG) CDbxMDBX::DeleteContact(MCONTACT contactID)
return 0;
}
-STDMETHODIMP_(MCONTACT) CDbxMDBX::AddContact()
+MCONTACT CDbxMDBX::AddContact()
{
MCONTACT dwContactId = InterlockedIncrement(&m_maxContactId);
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp
index 7083aa1d18..27b9c1c52e 100644
--- a/plugins/Dbx_mdbx/src/dbevents.cpp
+++ b/plugins/Dbx_mdbx/src/dbevents.cpp
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-STDMETHODIMP_(LONG) CDbxMDBX::GetEventCount(MCONTACT contactID)
+LONG CDbxMDBX::GetEventCount(MCONTACT contactID)
{
if (!contactID)
return m_ccDummy.dbc.dwEventCount;
@@ -34,7 +34,7 @@ STDMETHODIMP_(LONG) CDbxMDBX::GetEventCount(MCONTACT contactID)
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
+MEVENT CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
{
if (dbei == nullptr) return 0;
if (dbei->timestamp == 0) return 0;
@@ -145,7 +145,7 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
+BOOL CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
{
DBCachedContact *cc = (contactID != 0) ? m_cache->GetCachedContact(contactID) : &m_ccDummy, *cc2 = nullptr;
if (cc == nullptr || cc->dbc.dwEventCount == 0)
@@ -230,7 +230,7 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(LONG) CDbxMDBX::GetBlobSize(MEVENT hDbEvent)
+LONG CDbxMDBX::GetBlobSize(MEVENT hDbEvent)
{
txn_ptr_ro txn(m_txn_ro);
@@ -242,7 +242,7 @@ STDMETHODIMP_(LONG) CDbxMDBX::GetBlobSize(MEVENT hDbEvent)
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(BOOL) CDbxMDBX::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
+BOOL CDbxMDBX::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
{
if (dbei == nullptr) return 1;
if (dbei->cbBlob > 0 && dbei->pBlob == nullptr) {
@@ -310,7 +310,7 @@ void CDbxMDBX::FindNextUnread(const txn_ptr &txn, DBCachedContact *cc, DBEventSo
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
+BOOL CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
{
if (hDbEvent == 0) return -1;
@@ -355,9 +355,48 @@ STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
return wRetVal;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MEVENT CDbxMDBX::GetEventById(LPCSTR szModule, LPCSTR szId)
+{
+ if (szModule == nullptr || szId == nullptr)
+ return 0;
+
+ DBEventIdKey keyId;
+ keyId.iModuleId = GetModuleID(szModule);
+ strncpy_s(keyId.szEventId, szId, _TRUNCATE);
+
+ MDBX_val key = { &keyId, sizeof(MEVENT) + strlen(keyId.szEventId) + 1 }, data;
+ txn_ptr_ro txn(m_txn_ro);
+ if (mdbx_get(txn, m_dbEventIds, &key, &data) != MDBX_SUCCESS)
+ return 0;
+
+ return *(MEVENT*)data.iov_base;
+}
+
+BOOL CDbxMDBX::SetEventId(LPCSTR szModule, MEVENT hDbEvent, LPCSTR szId)
+{
+ if (szModule == nullptr || szId == nullptr || !hDbEvent)
+ return 1;
+
+ DBEventIdKey keyId;
+ keyId.iModuleId = GetModuleID(szModule);
+ strncpy_s(keyId.szEventId, szId, _TRUNCATE);
+
+ txn_ptr trnlck(StartTran());
+ MDBX_val key = { &keyId, sizeof(MEVENT) + strlen(keyId.szEventId) + 1 }, data = { &hDbEvent, sizeof(hDbEvent) };
+ if (mdbx_put(trnlck, m_dbEventIds, &key, &data, 0) != MDBX_SUCCESS)
+ return 1;
+ if (trnlck.commit() != MDBX_SUCCESS)
+ return 1;
+
+ return 0;
+}
+
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(MCONTACT) CDbxMDBX::GetEventContact(MEVENT hDbEvent)
+MCONTACT CDbxMDBX::GetEventContact(MEVENT hDbEvent)
{
if (hDbEvent == 0)
return INVALID_CONTACT_ID;
@@ -373,7 +412,7 @@ STDMETHODIMP_(MCONTACT) CDbxMDBX::GetEventContact(MEVENT hDbEvent)
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(MEVENT) CDbxMDBX::FindFirstEvent(MCONTACT contactID)
+MEVENT CDbxMDBX::FindFirstEvent(MCONTACT contactID)
{
DBCachedContact *cc;
if (contactID != 0) {
@@ -399,7 +438,7 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindFirstEvent(MCONTACT contactID)
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(MEVENT) CDbxMDBX::FindFirstUnreadEvent(MCONTACT contactID)
+MEVENT CDbxMDBX::FindFirstUnreadEvent(MCONTACT contactID)
{
DBCachedContact *cc = m_cache->GetCachedContact(contactID);
return (cc == nullptr) ? 0 : cc->dbc.evFirstUnread;
@@ -407,7 +446,7 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindFirstUnreadEvent(MCONTACT contactID)
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(MEVENT) CDbxMDBX::FindLastEvent(MCONTACT contactID)
+MEVENT CDbxMDBX::FindLastEvent(MCONTACT contactID)
{
DBCachedContact *cc;
if (contactID != 0) {
@@ -439,7 +478,7 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindLastEvent(MCONTACT contactID)
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(MEVENT) CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent)
+MEVENT CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent)
{
DBCachedContact *cc;
if (contactID != 0) {
@@ -478,7 +517,7 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEven
///////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(MEVENT) CDbxMDBX::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent)
+MEVENT CDbxMDBX::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent)
{
DBCachedContact *cc;
if (contactID != 0) {
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp
index 51b0c04c60..93463f9850 100644
--- a/plugins/Dbx_mdbx/src/dbintf.cpp
+++ b/plugins/Dbx_mdbx/src/dbintf.cpp
@@ -229,7 +229,7 @@ int CDbxMDBX::PrepareCheck()
/////////////////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(void) CDbxMDBX::SetCacheSafetyMode(BOOL bIsSet)
+void CDbxMDBX::SetCacheSafetyMode(BOOL bIsSet)
{
m_safetyMode = bIsSet != 0;
DBFlush(true);
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index fceabaf5f8..f7986e2b5c 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -242,40 +242,43 @@ public:
__forceinline bool usesPassword() const { return m_bUsesPassword; }
public:
- STDMETHODIMP_(BOOL) IsRelational(void) { return TRUE; }
- STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
-
- STDMETHODIMP_(LONG) GetContactCount(void);
- STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID);
- STDMETHODIMP_(MCONTACT) AddContact(void);
- STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID);
- STDMETHODIMP_(LONG) GetContactSize(void);
-
- STDMETHODIMP_(LONG) GetEventCount(MCONTACT contactID);
- STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, DBEVENTINFO *dbe);
- STDMETHODIMP_(BOOL) DeleteEvent(MCONTACT contactID, MEVENT hDbEvent);
- STDMETHODIMP_(LONG) GetBlobSize(MEVENT hDbEvent);
- STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe);
- STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent);
- STDMETHODIMP_(MCONTACT) GetEventContact(MEVENT hDbEvent);
- STDMETHODIMP_(MEVENT) FindFirstEvent(MCONTACT contactID);
- STDMETHODIMP_(MEVENT) FindFirstUnreadEvent(MCONTACT contactID);
- STDMETHODIMP_(MEVENT) FindLastEvent(MCONTACT contactID);
- STDMETHODIMP_(MEVENT) FindNextEvent(MCONTACT contactID, MEVENT hDbEvent);
- STDMETHODIMP_(MEVENT) FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent);
-
- STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam);
-
- STDMETHODIMP_(BOOL) GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic);
- STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws);
- STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting);
- STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param);
-
- STDMETHODIMP_(BOOL) MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub);
- STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub);
+ STDMETHODIMP_(BOOL) IsRelational(void) override { return TRUE; }
+ STDMETHODIMP_(void) SetCacheSafetyMode(BOOL) override;
+
+ STDMETHODIMP_(LONG) GetContactCount(void) override;
+ STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID) override;
+ STDMETHODIMP_(MCONTACT) AddContact(void) override;
+ STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID) override;
+ STDMETHODIMP_(LONG) GetContactSize(void) override;
+
+ STDMETHODIMP_(LONG) GetEventCount(MCONTACT contactID) override;
+ STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, DBEVENTINFO *dbe) override;
+ STDMETHODIMP_(BOOL) DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) override;
+ STDMETHODIMP_(LONG) GetBlobSize(MEVENT hDbEvent) override;
+ STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe) override;
+ STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) override;
+ STDMETHODIMP_(MCONTACT) GetEventContact(MEVENT hDbEvent) override;
+ STDMETHODIMP_(MEVENT) FindFirstEvent(MCONTACT contactID) override;
+ STDMETHODIMP_(MEVENT) FindFirstUnreadEvent(MCONTACT contactID) override;
+ STDMETHODIMP_(MEVENT) FindLastEvent(MCONTACT contactID) override;
+ STDMETHODIMP_(MEVENT) FindNextEvent(MCONTACT contactID, MEVENT hDbEvent) override;
+ STDMETHODIMP_(MEVENT) FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent) override;
+
+ STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam) override;
+
+ STDMETHODIMP_(BOOL) GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic) override;
+ STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws) override;
+ STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting) override;
+ STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param) override;
+
+ STDMETHODIMP_(BOOL) MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) override;
+ STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) override;
STDMETHODIMP_(BOOL) Compact();
- STDMETHODIMP_(BOOL) Backup(LPCWSTR);
+ STDMETHODIMP_(BOOL) Backup(const wchar_t*);
+
+ STDMETHODIMP_(MEVENT) GetEventById(LPCSTR szModule, LPCSTR szId) override;
+ STDMETHODIMP_(BOOL) SetEventId(LPCSTR szModule, MEVENT, LPCSTR szId) override;
public:
MICryptoEngine *m_crypto;
diff --git a/plugins/Dbx_mdbx/src/dbmodulechain.cpp b/plugins/Dbx_mdbx/src/dbmodulechain.cpp
index 442fe3d5e2..04efbea036 100644
--- a/plugins/Dbx_mdbx/src/dbmodulechain.cpp
+++ b/plugins/Dbx_mdbx/src/dbmodulechain.cpp
@@ -67,7 +67,7 @@ char* CDbxMDBX::GetModuleName(uint32_t dwId)
return it != m_Modules.end() ? const_cast<char*>(it->second.c_str()) : nullptr;
}
-STDMETHODIMP_(BOOL) CDbxMDBX::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
+BOOL CDbxMDBX::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
{
for (auto it = m_Modules.begin(); it != m_Modules.end(); ++it)
if (int ret = pFunc(it->second.c_str(), pParam))
diff --git a/plugins/Dbx_mdbx/src/dbsettings.cpp b/plugins/Dbx_mdbx/src/dbsettings.cpp
index 83211cd36f..d327e50504 100644
--- a/plugins/Dbx_mdbx/src/dbsettings.cpp
+++ b/plugins/Dbx_mdbx/src/dbsettings.cpp
@@ -198,7 +198,7 @@ LBL_Seek:
return 0;
}
-STDMETHODIMP_(BOOL) CDbxMDBX::WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws)
+BOOL CDbxMDBX::WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws)
{
if (dbcws == nullptr || dbcws->szSetting == nullptr || dbcws->szModule == nullptr || m_bReadOnly)
return 1;
@@ -354,7 +354,7 @@ LBL_WriteString:
return 0;
}
-STDMETHODIMP_(BOOL) CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting)
+BOOL CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting)
{
if (!szModule || !szSetting)
return 1;
@@ -394,7 +394,7 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR sz
return 0;
}
-STDMETHODIMP_(BOOL) CDbxMDBX::EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param)
+BOOL CDbxMDBX::EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param)
{
LIST<char> arKeys(100);
{