summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-08-07 16:50:15 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-08-07 16:50:15 +0300
commitf0428e851dc8a3acbcc120dde478273a718df25c (patch)
treedf4447858a48bb3e9069327e6758bc99535bfa66 /plugins
parent48932c71fe42c09d92adbaa5d0ffec1a17c06ea3 (diff)
Dbx_Mdbx: first two integrity checks
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Dbx_mdbx/src/dbcheck.cpp50
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp4
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h1
3 files changed, 53 insertions, 2 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcheck.cpp b/plugins/Dbx_mdbx/src/dbcheck.cpp
index e636e196c4..f32469c6c4 100644
--- a/plugins/Dbx_mdbx/src/dbcheck.cpp
+++ b/plugins/Dbx_mdbx/src/dbcheck.cpp
@@ -23,7 +23,57 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
+/////////////////////////////////////////////////////////////////////////////////////////
+// we are tracing EventsSort table to verify that they have correct event ids
+
int CDbxMDBX::CheckEvents1(void)
{
+ txn_ptr trnlck(StartTran());
+ cursor_ptr cursor(trnlck, m_dbEventsSort);
+
+ MDBX_val key, data;
+ for (int ret = mdbx_cursor_get(cursor, &key, &data, MDBX_FIRST); ret == MDBX_SUCCESS; ret = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
+ auto *pData = (DBEventSortingKey *)key.iov_base;
+
+ // if that's not a member of system event, check contact's existence first
+ if (pData->hContact != 0) {
+ auto *cc = m_cache->GetCachedContact(pData->hContact);
+ if (cc == nullptr) {
+ mdbx_cursor_del(cursor, 0);
+ cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned sorting event with wrong contact ID %d, deleting"), pData->hContact));
+ continue;
+ }
+ }
+
+ if (GetBlobSize(pData->hEvent) == -1) {
+ mdbx_cursor_del(cursor, 0);
+ cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned sorting event with wrong event ID %d:%08X, deleting"), pData->hContact, pData->hEvent));
+ continue;
+ }
+ }
+
+ trnlck.commit();
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// we are tracing EventId tables to verify that they have correct event ids
+
+int CDbxMDBX::CheckEvents2(void)
+{
+ txn_ptr trnlck(StartTran());
+ cursor_ptr cursor(trnlck, m_dbEventIds);
+
+ MDBX_val key, data;
+ for (int ret = mdbx_cursor_get(cursor, &key, &data, MDBX_FIRST); ret == MDBX_SUCCESS; ret = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
+ MEVENT hDbEvent = *(MEVENT *)data.iov_base;
+ if (GetBlobSize(hDbEvent) == -1) {
+ mdbx_cursor_del(cursor, 0);
+ cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned event id with wrong event ID %08X, deleting"), hDbEvent));
+ continue;
+ }
+ }
+
+ trnlck.commit();
return 0;
}
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp
index 6803f2d322..18b570a3e6 100644
--- a/plugins/Dbx_mdbx/src/dbintf.cpp
+++ b/plugins/Dbx_mdbx/src/dbintf.cpp
@@ -305,7 +305,8 @@ int CDbxMDBX::Start(DBCHeckCallback *callback)
static CheckWorker Workers[] =
{
- &CDbxMDBX::CheckEvents1
+ &CDbxMDBX::CheckEvents1,
+ &CDbxMDBX::CheckEvents2
};
int CDbxMDBX::CheckDb(int phase)
@@ -318,5 +319,4 @@ int CDbxMDBX::CheckDb(int phase)
void CDbxMDBX::Destroy()
{
- delete this;
}
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index 7a563f68d8..50b10109f8 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -252,6 +252,7 @@ public:
void SetPassword(const wchar_t *ptszPassword);
int CheckEvents1(void);
+ int CheckEvents2(void);
__forceinline LPSTR GetMenuTitle() const { return m_bUsesPassword ? (char*)LPGEN("Change/remove password") : (char*)LPGEN("Set password"); }