summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-03-21 17:47:28 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-03-21 17:47:28 +0000
commit00a8ec3be1ebc0367e6725f93833bd53323ffae5 (patch)
tree1eebc55aaa1ae5374afe791a082056bfa999141f /plugins/Db3x_mmap/src
parent099decfc4c419bb0b12a2b1c4c285c0ef1568430 (diff)
fix for running dbchecker over the locked profile
git-svn-id: http://svn.miranda-ng.org/main/trunk@8673 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x_mmap/src')
-rw-r--r--plugins/Db3x_mmap/src/dbintf.cpp24
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h7
-rw-r--r--plugins/Db3x_mmap/src/init.cpp10
-rw-r--r--plugins/Db3x_mmap/src/version.h2
4 files changed, 26 insertions, 17 deletions
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp
index 888d47e1d3..0e2187e993 100644
--- a/plugins/Db3x_mmap/src/dbintf.cpp
+++ b/plugins/Db3x_mmap/src/dbintf.cpp
@@ -43,10 +43,11 @@ static int stringCompare2(const char *p1, const char *p2)
return strcmp(p1, p2);
}
-CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName, bool bReadOnly) :
+CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName, int iMode) :
m_hDbFile(INVALID_HANDLE_VALUE),
m_safetyMode(true),
- m_bReadOnly(bReadOnly),
+ m_bReadOnly((iMode & DBMODE_READONLY) != 0),
+ m_bShared((iMode & DBMODE_SHARED) != 0),
m_dwMaxContactId(1),
m_lMods(50, ModCompare),
m_lOfs(50, OfsCompare),
@@ -79,7 +80,7 @@ CDb3Mmap::~CDb3Mmap()
}
DestroyServiceFunction(hService);
- UnhookEvent(hHook);
+ UnhookEvent(hHook);
if (m_crypto)
m_crypto->destroy();
@@ -93,7 +94,9 @@ CDb3Mmap::~CDb3Mmap()
SetFilePointer(m_hDbFile, 0, NULL, FILE_BEGIN);
WriteFile(m_hDbFile, &dbSignatureIM, 1, &bytesWritten, NULL);
}
- CloseHandle(m_hDbFile);
+
+ if (m_hDbFile != INVALID_HANDLE_VALUE)
+ CloseHandle(m_hDbFile);
DestroyHookableEvent(hContactDeletedEvent);
DestroyHookableEvent(hContactAddedEvent);
@@ -118,13 +121,16 @@ static TCHAR szMsgConvert[] =
int CDb3Mmap::Load(bool bSkipInit)
{
log0("DB logging running");
-
- DWORD dummy = 0;
+
+ DWORD dummy = 0, dwMode = FILE_SHARE_READ;
+ if (m_bShared)
+ dwMode |= FILE_SHARE_WRITE;
if (m_bReadOnly)
- m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, dwMode, NULL, OPEN_EXISTING, 0, NULL);
else
- m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
- if ( m_hDbFile == INVALID_HANDLE_VALUE )
+ m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, dwMode, NULL, OPEN_ALWAYS, 0, NULL);
+
+ if (m_hDbFile == INVALID_HANDLE_VALUE)
return EGROKPRF_CANTREAD;
if (!ReadFile(m_hDbFile, &m_dbHeader, sizeof(m_dbHeader), &dummy, NULL)) {
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index bc9bd220da..9582c928bb 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -44,6 +44,9 @@ DBHeader
\--> ...
*/
+#define DBMODE_SHARED 0x0001
+#define DBMODE_READONLY 0x0002
+
#define DB_OLD_VERSION 0x00000700u
#define DB_094_VERSION 0x00000701u
#define DB_095_VERSION 0x00000800u
@@ -174,7 +177,7 @@ struct ConvertedContact
struct CDb3Mmap : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
{
- CDb3Mmap(const TCHAR *tszFileName, bool bReadOnly);
+ CDb3Mmap(const TCHAR *tszFileName, int mode);
~CDb3Mmap();
int Load(bool bSkipInit);
@@ -275,7 +278,7 @@ protected:
HANDLE m_hDbFile;
DBHeader m_dbHeader;
DWORD m_ChunkSize;
- bool m_safetyMode, m_bReadOnly, m_bEncrypted, m_bUsesPassword;
+ bool m_safetyMode, m_bReadOnly, m_bShared, m_bEncrypted, m_bUsesPassword;
////////////////////////////////////////////////////////////////////////////
// database stuff
diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp
index d283f944cb..928ec0739f 100644
--- a/plugins/Db3x_mmap/src/init.cpp
+++ b/plugins/Db3x_mmap/src/init.cpp
@@ -49,7 +49,7 @@ LIST<CDb3Mmap> g_Dbs(1, HandleKeySortT);
// returns 0 if the profile is created, EMKPRF*
static int makeDatabase(const TCHAR *profile)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, false));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, 0));
if (db->Create() != ERROR_SUCCESS)
return EMKPRF_CREATEFAILED;
@@ -59,7 +59,7 @@ static int makeDatabase(const TCHAR *profile)
// returns 0 if the given profile has a valid header
static int grokHeader(const TCHAR *profile)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, true));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, DBMODE_SHARED | DBMODE_READONLY));
if (db->Load(true) != ERROR_SUCCESS)
return EGROKPRF_CANTREAD;
@@ -72,7 +72,7 @@ static MIDatabase* LoadDatabase(const TCHAR *profile, BOOL bReadOnly)
// set the memory, lists & UTF8 manager
mir_getLP(&pluginInfo);
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, bReadOnly != 0));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, (bReadOnly) ? DBMODE_READONLY : 0));
if (db->Load(false) != ERROR_SUCCESS)
return NULL;
@@ -89,9 +89,9 @@ static int UnloadDatabase(MIDatabase *db)
MIDatabaseChecker* CheckDb(const TCHAR *profile, int *error)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, true));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, DBMODE_READONLY));
if (db->Load(true) != ERROR_SUCCESS) {
- *error = EGROKPRF_CANTREAD;
+ *error = ERROR_ACCESS_DENIED;
return NULL;
}
diff --git a/plugins/Db3x_mmap/src/version.h b/plugins/Db3x_mmap/src/version.h
index 7e85a65adc..2f1eb214a5 100644
--- a/plugins/Db3x_mmap/src/version.h
+++ b/plugins/Db3x_mmap/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
#define __RELEASE_NUM 0
-#define __BUILD_NUM 3
+#define __BUILD_NUM 4
#include <stdver.h>