diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Db3x_mmap/db3x_mmap_10.vcxproj | 1 | ||||
-rw-r--r-- | plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters | 28 | ||||
-rw-r--r-- | plugins/Db3x_mmap/dbcache.cpp | 174 | ||||
-rw-r--r-- | plugins/Db3x_mmap/dbintf.h | 311 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/commonheaders.h | 2 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/database.cpp | 8 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbcache.cpp | 19 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbcontacts.cpp | 16 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbevents.cpp | 24 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbheaders.cpp | 4 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.cpp | 22 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.h | 50 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbmodulechain.cpp | 12 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbsettings.cpp | 32 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/init.cpp | 12 | ||||
-rw-r--r-- | plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj | 1 | ||||
-rw-r--r-- | plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters | 3 | ||||
-rw-r--r-- | plugins/Dbx_mmap_SA/src/dbintf_sa.cpp | 4 | ||||
-rw-r--r-- | plugins/Dbx_mmap_SA/src/dbintf_sa.h | 2 |
19 files changed, 616 insertions, 109 deletions
diff --git a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj index 5e19ec66f3..620786b9c6 100644 --- a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj +++ b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj @@ -205,6 +205,7 @@ <ClCompile Include="src\dbevents.cpp" />
<ClCompile Include="src\dbheaders.cpp" />
<ClCompile Include="src\dbintf.cpp" />
+ <ClCompile Include="src\dbintfm.cpp" />
<ClCompile Include="src\dbmodulechain.cpp" />
<ClCompile Include="src\dbsettings.cpp" />
<ClCompile Include="src\init.cpp">
diff --git a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters index a087e1d883..2d3667a179 100644 --- a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters +++ b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters @@ -15,50 +15,50 @@ </Filter>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="src\database.cpp">
+ <ClCompile Include="database.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbcache.cpp">
+ <ClCompile Include="dbcontacts.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbcontacts.cpp">
+ <ClCompile Include="dbevents.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbevents.cpp">
+ <ClCompile Include="dbheaders.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbheaders.cpp">
+ <ClCompile Include="dbmodulechain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbmodulechain.cpp">
+ <ClCompile Include="dbsettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbsettings.cpp">
+ <ClCompile Include="init.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\init.cpp">
+ <ClCompile Include="dbintf.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbintf.cpp">
+ <ClCompile Include="dbcache.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\commonheaders.h">
+ <ClInclude Include="commonheaders.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\database.h">
+ <ClInclude Include="database.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\dbintf.h">
+ <ClInclude Include="dbintf.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
- <ResourceCompile Include="res\db3x_mmap.rc">
+ <ResourceCompile Include="db3x_mmap.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
- <ResourceCompile Include="res\version.rc">
+ <ResourceCompile Include="version.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
diff --git a/plugins/Db3x_mmap/dbcache.cpp b/plugins/Db3x_mmap/dbcache.cpp new file mode 100644 index 0000000000..4092940c97 --- /dev/null +++ b/plugins/Db3x_mmap/dbcache.cpp @@ -0,0 +1,174 @@ +/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright 2012 Miranda NG project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "commonheaders.h"
+
+void CDdxMmap::Map()
+{
+ m_hMap = CreateFileMapping(m_hDbFile, NULL, PAGE_READWRITE, 0, m_dwFileSize, NULL);
+
+ if (m_hMap)
+ {
+ m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, FILE_MAP_ALL_ACCESS/*FILE_MAP_WRITE*/, 0, 0 ,0);
+ if (!m_pDbCache)
+ DatabaseCorruption( _T("%s (MapViewOfFile failed. Code: %d)"));
+ }
+ else
+ DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)"));
+}
+
+void CDdxMmap::ReMap(DWORD needed)
+{
+ KillTimer(NULL,m_flushBuffersTimerId);
+
+ log3("remapping %d + %d (file end: %d)",m_dwFileSize,needed,m_dbHeader.ofsFileEnd);
+
+ if (needed > m_ChunkSize)
+ {
+ if (needed + m_dwFileSize > m_dbHeader.ofsFileEnd + m_ChunkSize)
+ DatabaseCorruption( _T("%s (Too large increment)"));
+ else
+ {
+ DWORD x = m_dbHeader.ofsFileEnd/m_ChunkSize;
+ m_dwFileSize = (x+1)*m_ChunkSize;
+ }
+ }
+ else
+ m_dwFileSize += m_ChunkSize;
+
+// FlushViewOfFile(m_pDbCache, 0);
+ UnmapViewOfFile(m_pDbCache);
+ m_pDbCache = NULL;
+ CloseHandle(m_hMap);
+
+ Map();
+}
+
+void CDdxMmap::DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes)
+{
+ int x = 0;
+ log3("move %d %08x->%08x",bytes,ofsSource,ofsDest);
+ if (ofsDest+bytes > m_dwFileSize) ReMap(ofsDest+bytes-m_dwFileSize);
+ if (ofsSource+bytes > m_dwFileSize) {
+ x = ofsSource+bytes-m_dwFileSize;
+ log0("buggy move!");
+ }
+ if (x > 0)
+ ZeroMemory(m_pDbCache+ofsDest+bytes-x, x);
+ if (ofsSource < m_dwFileSize)
+ MoveMemory(m_pDbCache+ofsDest,m_pDbCache+ofsSource, bytes-x);
+
+ logg();
+}
+
+//we are assumed to be in a mutex here
+PBYTE CDdxMmap::DBRead(DWORD ofs,int bytesRequired,int *bytesAvail)
+{
+ // buggy read
+ if (ofs>= m_dwFileSize) {
+ log2("read from outside %d@%08x",bytesRequired,ofs);
+ if (bytesAvail != NULL) *bytesAvail = m_ChunkSize;
+ return m_pNull;
+ }
+ log3((ofs+bytesRequired > m_dwFileSize)?"read %d@%08x, only %d avaliable":"read %d@%08x",bytesRequired,ofs,m_dwFileSize-ofs);
+ if (bytesAvail != NULL) *bytesAvail = m_dwFileSize - ofs;
+ return m_pDbCache+ofs;
+}
+
+//we are assumed to be in a mutex here
+void CDdxMmap::DBWrite(DWORD ofs,PVOID pData,int bytes)
+{
+ log2("write %d@%08x",bytes,ofs);
+ if (ofs+bytes > m_dwFileSize) ReMap(ofs+bytes-m_dwFileSize);
+ MoveMemory(m_pDbCache+ofs,pData,bytes);
+ logg();
+}
+
+//we are assumed to be in a mutex here
+void CDdxMmap::DBFill(DWORD ofs,int bytes)
+{
+ log2("zerofill %d@%08x",bytes,ofs);
+ if (ofs+bytes <= m_dwFileSize)
+ ZeroMemory(m_pDbCache+ofs,bytes);
+ logg();
+}
+
+static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT message, UINT_PTR idEvent, DWORD dwTime)
+{
+ for (int i=0; i < g_Dbs.getCount(); i++) {
+ CDdxMmap* db = g_Dbs[i];
+ if (db->m_flushBuffersTimerId != idEvent)
+ continue;
+
+ if (!db->m_pDbCache)
+ return;
+
+ KillTimer(NULL, db->m_flushBuffersTimerId);
+ log0("tflush1");
+ if (FlushViewOfFile(db->m_pDbCache, 0) == 0) {
+ if (db->m_flushFailTick == 0)
+ db->m_flushFailTick = GetTickCount();
+ else if (GetTickCount() - db->m_flushFailTick > 5000)
+ db->DatabaseCorruption(NULL);
+ }
+ else db->m_flushFailTick = 0;
+ log0("tflush2");
+ }
+}
+
+void CDdxMmap::DBFlush(int setting)
+{
+ if (!setting) {
+ log0("nflush1");
+ if (m_safetyMode && m_pDbCache) {
+ if (FlushViewOfFile(m_pDbCache, 0) == 0) {
+ if (m_flushFailTick == 0)
+ m_flushFailTick = GetTickCount();
+ else if (GetTickCount() - m_flushFailTick > 5000)
+ DatabaseCorruption(NULL);
+ }
+ else
+ m_flushFailTick = 0;
+ }
+ log0("nflush2");
+ return;
+ }
+ KillTimer(NULL, m_flushBuffersTimerId);
+ m_flushBuffersTimerId = SetTimer(NULL, m_flushBuffersTimerId, 50, DoBufferFlushTimerProc);
+}
+
+int CDdxMmap::InitCache(void)
+{
+ m_dwFileSize = GetFileSize(m_hDbFile, NULL);
+
+ // Align to chunk
+ DWORD x = m_dwFileSize % m_ChunkSize;
+ if (x)
+ m_dwFileSize += m_ChunkSize - x;
+
+ Map();
+
+ // zero region for reads outside the file
+ m_pNull = (PBYTE)calloc(m_ChunkSize, 1);
+ return 0;
+}
diff --git a/plugins/Db3x_mmap/dbintf.h b/plugins/Db3x_mmap/dbintf.h new file mode 100644 index 0000000000..c3a14c0c01 --- /dev/null +++ b/plugins/Db3x_mmap/dbintf.h @@ -0,0 +1,311 @@ +/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright 2012 Miranda NG project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include <m_db_int.h>
+
+/* tree diagram
+
+DBHeader
+ |-->end of file (plain offset)
+ |-->first contact (DBContact)
+ | |-->next contact (DBContact)
+ | | \--> ...
+ | |-->first settings (DBContactSettings)
+ | | |-->next settings (DBContactSettings)
+ | | | \--> ...
+ | | \-->module name (DBModuleName)
+ | \-->first/last/firstunread event
+ |-->user contact (DBContact)
+ | |-->next contact = NULL
+ | |-->first settings as above
+ | \-->first/last/firstunread event as above
+ \-->first module name (DBModuleName)
+ \-->next module name (DBModuleName)
+ \--> ...
+*/
+
+#define DB_THIS_VERSION 0x00000700u
+#define DB_SETTINGS_RESIZE_GRANULARITY 128
+
+struct DBSignature {
+ char name[15];
+ BYTE eof;
+};
+
+struct ModuleName
+{
+ char *name;
+ DWORD ofs;
+};
+
+#include <pshpack1.h>
+struct DBHeader {
+ BYTE signature[16]; // 'Miranda ICQ DB',0,26
+ DWORD version; //as 4 bytes, ie 1.2.3.10 = 0x0102030a
+ //this version is 0x00000700
+ DWORD ofsFileEnd; //offset of the end of the database - place to write
+ //new structures
+ DWORD slackSpace; //a counter of the number of bytes that have been
+ //wasted so far due to deleting structures and/or
+ //re-making them at the end. We should compact when
+ //this gets above a threshold
+ DWORD contactCount; //number of contacts in the chain,excluding the user
+ DWORD ofsFirstContact; //offset to first DBContact in the chain
+ DWORD ofsUser; //offset to DBContact representing the user
+ DWORD ofsFirstModuleName; //offset to first struct DBModuleName in the chain
+};
+
+#define DBCONTACT_SIGNATURE 0x43DECADEu
+
+struct DBContact
+{
+ DWORD signature;
+ DWORD ofsNext; //offset to the next contact in the chain. zero if
+ //this is the 'user' contact or the last contact
+ //in the chain
+ DWORD ofsFirstSettings; //offset to the first DBContactSettings in the
+ //chain for this contact.
+ DWORD eventCount; //number of events in the chain for this contact
+ DWORD ofsFirstEvent,ofsLastEvent; //offsets to the first and last DBEvent in
+ //the chain for this contact
+ DWORD ofsFirstUnreadEvent; //offset to the first (chronological) unread event
+ //in the chain, 0 if all are read
+ DWORD timestampFirstUnread; //timestamp of the event at ofsFirstUnreadEvent
+};
+
+#define DBMODULENAME_SIGNATURE 0x4DDECADEu
+struct DBModuleName
+{
+ DWORD signature;
+ DWORD ofsNext; //offset to the next module name in the chain
+ BYTE cbName; //number of characters in this module name
+ char name[1]; //name, no nul terminator
+};
+
+#define DBCONTACTSETTINGS_SIGNATURE 0x53DECADEu
+struct DBContactSettings
+{
+ DWORD signature;
+ DWORD ofsNext; //offset to the next contactsettings in the chain
+ DWORD ofsModuleName; //offset to the DBModuleName of the owner of these
+ //settings
+ DWORD cbBlob; //size of the blob in bytes. May be larger than the
+ //actual size for reducing the number of moves
+ //required using granularity in resizing
+ BYTE blob[1]; //the blob. a back-to-back sequence of DBSetting
+ //structs, the last has cbName = 0
+};
+
+#define DBEVENT_SIGNATURE 0x45DECADEu
+struct DBEvent
+{
+ DWORD signature;
+ DWORD ofsPrev,ofsNext; //offset to the previous and next events in the
+ //chain. Chain is sorted chronologically
+ DWORD ofsModuleName; //offset to a DBModuleName struct of the name of
+ //the owner of this event
+ DWORD timestamp; //seconds since 00:00:00 01/01/1970
+ DWORD flags; //see m_database.h, db/event/add
+ WORD eventType; //module-defined event type
+ DWORD cbBlob; //number of bytes in the blob
+ BYTE blob[1]; //the blob. module-defined formatting
+};
+
+#include <poppack.h>
+
+struct DBCachedGlobalValue
+{
+ char* name;
+ DBVARIANT value;
+};
+
+struct DBCachedContactValue
+{
+ char* name;
+ DBVARIANT value;
+ DBCachedContactValue* next;
+};
+
+struct DBCachedContactValueList
+{
+ HANDLE hContact;
+ HANDLE hNext;
+ DBCachedContactValue* first;
+ DBCachedContactValue* last;
+};
+
+#define MAXCACHEDREADSIZE 65536
+
+struct CDb3Base : public MIDatabase, public MZeroedObject
+{
+ CDb3Base(const TCHAR* tszFileName);
+ ~CDb3Base();
+
+ int Load(bool bSkipInit);
+ int Create(void);
+ int CreateDbHeaders();
+ int CheckDbHeaders();
+ void DatabaseCorruption(TCHAR *text);
+
+ __forceinline HANDLE getFile() const { return m_hDbFile; }
+
+protected:
+ STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
+
+ STDMETHODIMP_(LONG) GetContactCount(void);
+ STDMETHODIMP_(HANDLE) FindFirstContact(const char* szProto = NULL);
+ STDMETHODIMP_(HANDLE) FindNextContact(HANDLE hContact, const char* szProto = NULL);
+ STDMETHODIMP_(LONG) DeleteContact(HANDLE hContact);
+ STDMETHODIMP_(HANDLE) AddContact(void);
+ STDMETHODIMP_(BOOL) IsDbContact(HANDLE hContact);
+
+ STDMETHODIMP_(LONG) GetEventCount(HANDLE hContact);
+ STDMETHODIMP_(HANDLE) AddEvent(HANDLE hContact, DBEVENTINFO *dbe);
+ STDMETHODIMP_(BOOL) DeleteEvent(HANDLE hContact, HANDLE hDbEvent);
+ STDMETHODIMP_(LONG) GetBlobSize(HANDLE hDbEvent);
+ STDMETHODIMP_(BOOL) GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbe);
+ STDMETHODIMP_(BOOL) MarkEventRead(HANDLE hContact, HANDLE hDbEvent);
+ STDMETHODIMP_(HANDLE) GetEventContact(HANDLE hDbEvent);
+ STDMETHODIMP_(HANDLE) FindFirstEvent(HANDLE hContact);
+ STDMETHODIMP_(HANDLE) FindFirstUnreadEvent(HANDLE hContact);
+ STDMETHODIMP_(HANDLE) FindLastEvent(HANDLE hContact);
+ STDMETHODIMP_(HANDLE) FindNextEvent(HANDLE hDbEvent);
+ STDMETHODIMP_(HANDLE) FindPrevEvent(HANDLE hDbEvent);
+
+ STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam);
+
+ STDMETHODIMP_(BOOL) GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs);
+ STDMETHODIMP_(BOOL) GetContactSettingStr(HANDLE hContact, DBCONTACTGETSETTING *dbcgs);
+ STDMETHODIMP_(BOOL) GetContactSettingStatic(HANDLE hContact, DBCONTACTGETSETTING *dbcgs);
+ STDMETHODIMP_(BOOL) FreeVariant(DBVARIANT *dbv);
+ STDMETHODIMP_(BOOL) WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws);
+ STDMETHODIMP_(BOOL) DeleteContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs);
+ STDMETHODIMP_(BOOL) EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces);
+ STDMETHODIMP_(BOOL) SetSettingResident(BOOL bIsResident, const char *pszSettingName);
+ STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam);
+
+protected:
+ virtual void DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes) = 0;
+ virtual PBYTE DBRead(DWORD ofs, int bytesRequired, int *bytesAvail) = 0;
+ virtual void DBWrite(DWORD ofs, PVOID pData, int bytes) = 0;
+ virtual void DBFill(DWORD ofs, int bytes) = 0;
+ virtual void DBFlush(int setting) = 0;
+ virtual int InitCache(void) = 0;
+
+protected:
+ virtual void EncodeCopyMemory(void *dst, void *src, size_t size);
+ virtual void DecodeCopyMemory(void *dst, void *src, size_t size);
+ virtual void EncodeDBWrite(DWORD ofs, void *src, int size);
+ virtual void DecodeDBWrite(DWORD ofs, void *src, int size);
+
+protected:
+ TCHAR* m_tszProfileName;
+ HANDLE m_hDbFile;
+ DBHeader m_dbHeader;
+ DWORD m_ChunkSize;
+ BOOL m_safetyMode;
+
+ ////////////////////////////////////////////////////////////////////////////
+ // database stuff
+public:
+ UINT_PTR m_flushBuffersTimerId;
+ DWORD m_flushFailTick;
+ PBYTE m_pDbCache;
+
+protected:
+ DWORD m_dwFileSize;
+
+ CRITICAL_SECTION m_csDbAccess;
+
+ int CheckProto(HANDLE hContact, const char *proto);
+ DWORD CreateNewSpace(int bytes);
+ void DeleteSpace(DWORD ofs, int bytes);
+ DWORD ReallocSpace(DWORD ofs, int oldSize, int newSize);
+
+ __forceinline PBYTE DBRead(HANDLE hContact, int bytesRequired, int *bytesAvail)
+ { return DBRead((DWORD)hContact, bytesRequired, bytesAvail);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // settings
+
+ int m_codePage;
+
+ HANDLE m_hCacheHeap;
+ HANDLE m_hLastCachedContact;
+ char* m_lastSetting;
+ DBCachedContactValueList *m_lastVL;
+
+ LIST<DBCachedContactValueList> m_lContacts;
+ LIST<DBCachedGlobalValue> m_lGlobalSettings;
+ LIST<char> m_lSettings, m_lResidentSettings;
+ HANDLE hSettingChangeEvent, hContactDeletedEvent, hContactAddedEvent;
+
+ DWORD GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsModuleName);
+ char* InsertCachedSetting(const char* szName, size_t cbNameLen);
+ char* GetCachedSetting(const char *szModuleName,const char *szSettingName, int moduleNameLen, int settingNameLen);
+ void SetCachedVariant(DBVARIANT* s, DBVARIANT* d);
+ void FreeCachedVariant(DBVARIANT* V);
+ DBVARIANT* GetCachedValuePtr(HANDLE hContact, char* szSetting, int bAllocate);
+ int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic);
+
+ ////////////////////////////////////////////////////////////////////////////
+ // contacts
+
+ DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index);
+
+ ////////////////////////////////////////////////////////////////////////////
+ // modules
+
+ HANDLE m_hModHeap;
+ LIST<ModuleName> m_lMods, m_lOfs;
+ HANDLE hEventAddedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
+ ModuleName *m_lastmn;
+
+ void AddToList(char *name, DWORD len, DWORD ofs);
+ DWORD FindExistingModuleNameOfs(const char *szName);
+ int InitModuleNames(void);
+ DWORD GetModuleNameOfs(const char *szName);
+ char *GetModuleNameByOfs(DWORD ofs);
+};
+
+struct CDb3Mmap : public CDb3Base
+{
+ CDb3Mmap(const TCHAR* ptszFileName);
+ ~CDb3Mmap();
+
+protected:
+ virtual void DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes);
+ virtual PBYTE DBRead(DWORD ofs, int bytesRequired, int *bytesAvail);
+ virtual void DBWrite(DWORD ofs, PVOID pData, int bytes);
+ virtual void DBFill(DWORD ofs, int bytes);
+ virtual void DBFlush(int setting);
+ virtual int InitCache(void);
+
+protected:
+ PBYTE m_pNull;
+ HANDLE m_hMap;
+
+ void Map();
+ void ReMap(DWORD needed);
+};
diff --git a/plugins/Db3x_mmap/src/commonheaders.h b/plugins/Db3x_mmap/src/commonheaders.h index ea615956e1..8fe5b1f87f 100644 --- a/plugins/Db3x_mmap/src/commonheaders.h +++ b/plugins/Db3x_mmap/src/commonheaders.h @@ -53,7 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "resource.h"
#include "version.h"
-extern LIST<CDdxMmap> g_Dbs;
+extern LIST<CDb3Mmap> g_Dbs;
#ifdef __GNUC__
#define mir_i64(x) (x##LL)
diff --git a/plugins/Db3x_mmap/src/database.cpp b/plugins/Db3x_mmap/src/database.cpp index 1962805a35..4a0357d680 100644 --- a/plugins/Db3x_mmap/src/database.cpp +++ b/plugins/Db3x_mmap/src/database.cpp @@ -28,7 +28,7 @@ int InitCache(void); int InitIni(void);
void UninitIni(void);
-DWORD CDdxMmap::CreateNewSpace(int bytes)
+DWORD CDb3Base::CreateNewSpace(int bytes)
{
DWORD ofsNew = m_dbHeader.ofsFileEnd;
m_dbHeader.ofsFileEnd += bytes;
@@ -37,7 +37,7 @@ DWORD CDdxMmap::CreateNewSpace(int bytes) return ofsNew;
}
-void CDdxMmap::DeleteSpace(DWORD ofs, int bytes)
+void CDb3Base::DeleteSpace(DWORD ofs, int bytes)
{
if (ofs+bytes == m_dbHeader.ofsFileEnd) {
log2("freespace %d@%08x",bytes,ofs);
@@ -51,7 +51,7 @@ void CDdxMmap::DeleteSpace(DWORD ofs, int bytes) DBFill(ofs, bytes);
}
-DWORD CDdxMmap::ReallocSpace(DWORD ofs, int oldSize, int newSize)
+DWORD CDb3Base::ReallocSpace(DWORD ofs, int oldSize, int newSize)
{
if (oldSize >= newSize)
return ofs;
@@ -96,7 +96,7 @@ void __cdecl dbpanic(void *arg) TerminateProcess(GetCurrentProcess(),255);
}
-void CDdxMmap::DatabaseCorruption(TCHAR *text)
+void CDb3Base::DatabaseCorruption(TCHAR *text)
{
int kill = 0;
diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp index 466aa7a00d..4e09335bae 100644 --- a/plugins/Db3x_mmap/src/dbcache.cpp +++ b/plugins/Db3x_mmap/src/dbcache.cpp @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
-void CDdxMmap::Map()
+void CDb3Mmap::Map()
{
m_hMap = CreateFileMapping(m_hDbFile, NULL, PAGE_READWRITE, 0, m_dwFileSize, NULL);
@@ -37,7 +37,7 @@ void CDdxMmap::Map() DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)"));
}
-void CDdxMmap::ReMap(DWORD needed)
+void CDb3Mmap::ReMap(DWORD needed)
{
KillTimer(NULL,m_flushBuffersTimerId);
@@ -64,7 +64,7 @@ void CDdxMmap::ReMap(DWORD needed) Map();
}
-void CDdxMmap::DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes)
+void CDb3Mmap::DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes)
{
int x = 0;
log3("move %d %08x->%08x",bytes,ofsSource,ofsDest);
@@ -72,7 +72,6 @@ void CDdxMmap::DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes) if (ofsSource+bytes > m_dwFileSize) {
x = ofsSource+bytes-m_dwFileSize;
log0("buggy move!");
- _ASSERT(0);
}
if (x > 0)
ZeroMemory(m_pDbCache+ofsDest+bytes-x, x);
@@ -83,7 +82,7 @@ void CDdxMmap::DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes) }
//we are assumed to be in a mutex here
-PBYTE CDdxMmap::DBRead(DWORD ofs,int bytesRequired,int *bytesAvail)
+PBYTE CDb3Mmap::DBRead(DWORD ofs,int bytesRequired,int *bytesAvail)
{
// buggy read
if (ofs>= m_dwFileSize) {
@@ -97,7 +96,7 @@ PBYTE CDdxMmap::DBRead(DWORD ofs,int bytesRequired,int *bytesAvail) }
//we are assumed to be in a mutex here
-void CDdxMmap::DBWrite(DWORD ofs,PVOID pData,int bytes)
+void CDb3Mmap::DBWrite(DWORD ofs,PVOID pData,int bytes)
{
log2("write %d@%08x",bytes,ofs);
if (ofs+bytes > m_dwFileSize) ReMap(ofs+bytes-m_dwFileSize);
@@ -106,7 +105,7 @@ void CDdxMmap::DBWrite(DWORD ofs,PVOID pData,int bytes) }
//we are assumed to be in a mutex here
-void CDdxMmap::DBFill(DWORD ofs,int bytes)
+void CDb3Mmap::DBFill(DWORD ofs,int bytes)
{
log2("zerofill %d@%08x",bytes,ofs);
if (ofs+bytes <= m_dwFileSize)
@@ -117,7 +116,7 @@ void CDdxMmap::DBFill(DWORD ofs,int bytes) static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT message, UINT_PTR idEvent, DWORD dwTime)
{
for (int i=0; i < g_Dbs.getCount(); i++) {
- CDdxMmap* db = g_Dbs[i];
+ CDb3Mmap* db = g_Dbs[i];
if (db->m_flushBuffersTimerId != idEvent)
continue;
@@ -137,7 +136,7 @@ static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT message, UINT_PTR id }
}
-void CDdxMmap::DBFlush(int setting)
+void CDb3Mmap::DBFlush(int setting)
{
if (!setting) {
log0("nflush1");
@@ -158,7 +157,7 @@ void CDdxMmap::DBFlush(int setting) m_flushBuffersTimerId = SetTimer(NULL, m_flushBuffersTimerId, 50, DoBufferFlushTimerProc);
}
-int CDdxMmap::InitCache(void)
+int CDb3Mmap::InitCache(void)
{
m_dwFileSize = GetFileSize(m_hDbFile, NULL);
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index b8d4a843b8..3dc0260fa8 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
-DBCachedContactValueList* CDdxMmap::AddToCachedContactList(HANDLE hContact, int index)
+DBCachedContactValueList* CDb3Base::AddToCachedContactList(HANDLE hContact, int index)
{
DBCachedContactValueList* VL = (DBCachedContactValueList*)HeapAlloc(m_hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList));
VL->hContact = hContact;
@@ -37,7 +37,7 @@ DBCachedContactValueList* CDdxMmap::AddToCachedContactList(HANDLE hContact, int #define proto_module "Protocol"
#define proto_setting "p"
-int CDdxMmap::CheckProto(HANDLE hContact, const char *proto)
+int CDb3Base::CheckProto(HANDLE hContact, const char *proto)
{
char protobuf[MAX_PATH] = {0};
DBVARIANT dbv;
@@ -53,13 +53,13 @@ int CDdxMmap::CheckProto(HANDLE hContact, const char *proto) return !strcmp(protobuf,proto);
}
-STDMETHODIMP_(LONG) CDdxMmap::GetContactCount(void)
+STDMETHODIMP_(LONG) CDb3Base::GetContactCount(void)
{
mir_cslock lck(m_csDbAccess);
return m_dbHeader.contactCount;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstContact(const char *szProto)
+STDMETHODIMP_(HANDLE) CDb3Base::FindFirstContact(const char *szProto)
{
mir_cslock lck(m_csDbAccess);
HANDLE ret = (HANDLE)m_dbHeader.ofsFirstContact;
@@ -68,7 +68,7 @@ STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstContact(const char *szProto) return ret;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::FindNextContact(HANDLE hContact, const char *szProto)
+STDMETHODIMP_(HANDLE) CDb3Base::FindNextContact(HANDLE hContact, const char *szProto)
{
int index;
DBContact *dbc;
@@ -104,7 +104,7 @@ STDMETHODIMP_(HANDLE) CDdxMmap::FindNextContact(HANDLE hContact, const char *szP return NULL;
}
-STDMETHODIMP_(LONG) CDdxMmap::DeleteContact(HANDLE hContact)
+STDMETHODIMP_(LONG) CDb3Base::DeleteContact(HANDLE hContact)
{
if (hContact == NULL)
return 1;
@@ -200,7 +200,7 @@ STDMETHODIMP_(LONG) CDdxMmap::DeleteContact(HANDLE hContact) return 0;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::AddContact()
+STDMETHODIMP_(HANDLE) CDb3Base::AddContact()
{
DWORD ofsNew;
log0("add contact");
@@ -224,7 +224,7 @@ STDMETHODIMP_(HANDLE) CDdxMmap::AddContact() return (HANDLE)ofsNew;
}
-STDMETHODIMP_(BOOL) CDdxMmap::IsDbContact(HANDLE hContact)
+STDMETHODIMP_(BOOL) CDb3Base::IsDbContact(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index 917d1680b2..c499361557 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -30,7 +30,7 @@ char *GetModuleNameByOfs(DWORD ofs); static HANDLE hEventDeletedEvent,hEventAddedEvent,hEventFilterAddedEvent;
-STDMETHODIMP_(LONG) CDdxMmap::GetEventCount(HANDLE hContact)
+STDMETHODIMP_(LONG) CDb3Base::GetEventCount(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -40,7 +40,7 @@ STDMETHODIMP_(LONG) CDdxMmap::GetEventCount(HANDLE hContact) return (dbc->signature != DBCONTACT_SIGNATURE) ? -1 : dbc->eventCount;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
+STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
{
if (dbei == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) return 0;
if (dbei->timestamp == 0) return 0;
@@ -138,7 +138,7 @@ STDMETHODIMP_(HANDLE) CDdxMmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei) return (HANDLE)ofsNew;
}
-STDMETHODIMP_(BOOL) CDdxMmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
+STDMETHODIMP_(BOOL) CDb3Base::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
{
mir_cslockfull lck(m_csDbAccess);
@@ -216,14 +216,14 @@ STDMETHODIMP_(BOOL) CDdxMmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent) return 0;
}
-STDMETHODIMP_(LONG) CDdxMmap::GetBlobSize(HANDLE hDbEvent)
+STDMETHODIMP_(LONG) CDb3Base::GetBlobSize(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
return (dbe->signature != DBEVENT_SIGNATURE) ? -1 : dbe->cbBlob;
}
-STDMETHODIMP_(BOOL) CDdxMmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
+STDMETHODIMP_(BOOL) CDb3Base::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
{
if (dbei == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) return 1;
if (dbei->cbBlob > 0 && dbei->pBlob == NULL) {
@@ -254,7 +254,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei) return 0;
}
-STDMETHODIMP_(BOOL) CDdxMmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
+STDMETHODIMP_(BOOL) CDb3Base::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
{
DBEvent *dbe;
DBContact dbc;
@@ -296,7 +296,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent) return ret;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::GetEventContact(HANDLE hDbEvent)
+STDMETHODIMP_(HANDLE) CDb3Base::GetEventContact(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
@@ -309,7 +309,7 @@ STDMETHODIMP_(HANDLE) CDdxMmap::GetEventContact(HANDLE hDbEvent) return (HANDLE)dbe->ofsPrev;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Base::FindFirstEvent(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -319,7 +319,7 @@ STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstEvent(HANDLE hContact) return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstEvent;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstUnreadEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Base::FindFirstUnreadEvent(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -329,7 +329,7 @@ STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstUnreadEvent(HANDLE hContact) return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstUnreadEvent;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::FindLastEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Base::FindLastEvent(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -339,14 +339,14 @@ STDMETHODIMP_(HANDLE) CDdxMmap::FindLastEvent(HANDLE hContact) return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsLastEvent;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::FindNextEvent(HANDLE hDbEvent)
+STDMETHODIMP_(HANDLE) CDb3Base::FindNextEvent(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
return (dbe->signature != DBEVENT_SIGNATURE) ? 0 : (HANDLE)dbe->ofsNext;
}
-STDMETHODIMP_(HANDLE) CDdxMmap::FindPrevEvent(HANDLE hDbEvent)
+STDMETHODIMP_(HANDLE) CDb3Base::FindPrevEvent(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
diff --git a/plugins/Db3x_mmap/src/dbheaders.cpp b/plugins/Db3x_mmap/src/dbheaders.cpp index 3d18a373fa..394b66acfc 100644 --- a/plugins/Db3x_mmap/src/dbheaders.cpp +++ b/plugins/Db3x_mmap/src/dbheaders.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern DBSignature dbSignature;
-int CDdxMmap::CreateDbHeaders()
+int CDb3Base::CreateDbHeaders()
{
DBContact user;
DWORD bytesWritten;
@@ -56,7 +56,7 @@ int CDdxMmap::CreateDbHeaders() return 0;
}
-int CDdxMmap::CheckDbHeaders()
+int CDb3Base::CheckDbHeaders()
{
if (memcmp(m_dbHeader.signature, &dbSignature, sizeof(m_dbHeader.signature))) return 1;
if (m_dbHeader.version != DB_THIS_VERSION) return 2;
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 83ae3aa4ca..0479be3691 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -50,7 +50,7 @@ static int OfsCompare(const ModuleName *mn1, const ModuleName *mn2 ) return ( mn1->ofs - mn2->ofs );
}
-CDdxMmap::CDdxMmap(const TCHAR* tszFileName) :
+CDb3Base::CDb3Base(const TCHAR* tszFileName) :
m_hDbFile(INVALID_HANDLE_VALUE),
m_safetyMode(TRUE),
m_lSettings(100, stringCompare),
@@ -73,7 +73,7 @@ CDdxMmap::CDdxMmap(const TCHAR* tszFileName) : m_hModHeap = HeapCreate(0,0,0);
}
-CDdxMmap::~CDdxMmap()
+CDb3Base::~CDb3Base()
{
// destroy settings
HeapDestroy(m_hCacheHeap);
@@ -93,10 +93,6 @@ CDdxMmap::~CDdxMmap() FlushViewOfFile(m_pDbCache, 0);
UnmapViewOfFile(m_pDbCache);
}
- if (m_hMap)
- CloseHandle(m_hMap);
- if (m_pNull)
- free(m_pNull);
// update profile last modified time
DWORD bytesWritten;
@@ -109,7 +105,7 @@ CDdxMmap::~CDdxMmap() mir_free(m_tszProfileName);
}
-int CDdxMmap::Load(bool bSkipInit)
+int CDb3Base::Load(bool bSkipInit)
{
log0("DB logging running");
@@ -138,13 +134,13 @@ int CDdxMmap::Load(bool bSkipInit) return 0;
}
-int CDdxMmap::Create()
+int CDb3Base::Create()
{
m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
return ( m_hDbFile == INVALID_HANDLE_VALUE );
}
-STDMETHODIMP_(void) CDdxMmap::SetCacheSafetyMode(BOOL bIsSet)
+STDMETHODIMP_(void) CDb3Base::SetCacheSafetyMode(BOOL bIsSet)
{
{ mir_cslock lck(m_csDbAccess);
m_safetyMode = bIsSet;
@@ -152,22 +148,22 @@ STDMETHODIMP_(void) CDdxMmap::SetCacheSafetyMode(BOOL bIsSet) DBFlush(1);
}
-void CDdxMmap::EncodeCopyMemory(void *dst, void *src, size_t size)
+void CDb3Base::EncodeCopyMemory(void *dst, void *src, size_t size)
{
MoveMemory(dst, src, size);
}
-void CDdxMmap::DecodeCopyMemory(void *dst, void *src, size_t size)
+void CDb3Base::DecodeCopyMemory(void *dst, void *src, size_t size)
{
MoveMemory(dst, src, size);
}
-void CDdxMmap::EncodeDBWrite(DWORD ofs, void *src, int size)
+void CDb3Base::EncodeDBWrite(DWORD ofs, void *src, int size)
{
DBWrite(ofs, src, size);
}
-void CDdxMmap::DecodeDBWrite(DWORD ofs, void *src, int size)
+void CDb3Base::DecodeDBWrite(DWORD ofs, void *src, int size)
{
DBWrite(ofs, src, size);
}
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index 4dff427516..c3a14c0c01 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -156,16 +156,19 @@ struct DBCachedContactValueList #define MAXCACHEDREADSIZE 65536
-struct CDdxMmap : public MIDatabase, public MZeroedObject
+struct CDb3Base : public MIDatabase, public MZeroedObject
{
- CDdxMmap(const TCHAR* tszFileName);
- ~CDdxMmap();
+ CDb3Base(const TCHAR* tszFileName);
+ ~CDb3Base();
int Load(bool bSkipInit);
int Create(void);
int CreateDbHeaders();
int CheckDbHeaders();
void DatabaseCorruption(TCHAR *text);
+
+ __forceinline HANDLE getFile() const { return m_hDbFile; }
+
protected:
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
@@ -202,6 +205,14 @@ protected: STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam);
protected:
+ virtual void DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes) = 0;
+ virtual PBYTE DBRead(DWORD ofs, int bytesRequired, int *bytesAvail) = 0;
+ virtual void DBWrite(DWORD ofs, PVOID pData, int bytes) = 0;
+ virtual void DBFill(DWORD ofs, int bytes) = 0;
+ virtual void DBFlush(int setting) = 0;
+ virtual int InitCache(void) = 0;
+
+protected:
virtual void EncodeCopyMemory(void *dst, void *src, size_t size);
virtual void DecodeCopyMemory(void *dst, void *src, size_t size);
virtual void EncodeDBWrite(DWORD ofs, void *src, int size);
@@ -220,9 +231,8 @@ public: UINT_PTR m_flushBuffersTimerId;
DWORD m_flushFailTick;
PBYTE m_pDbCache;
+
protected:
- PBYTE m_pNull;
- HANDLE m_hMap;
DWORD m_dwFileSize;
CRITICAL_SECTION m_csDbAccess;
@@ -232,15 +242,6 @@ protected: void DeleteSpace(DWORD ofs, int bytes);
DWORD ReallocSpace(DWORD ofs, int oldSize, int newSize);
- void Map();
- void ReMap(DWORD needed);
- void DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes);
- PBYTE DBRead(DWORD ofs, int bytesRequired, int *bytesAvail);
- void DBWrite(DWORD ofs, PVOID pData, int bytes);
- void DBFill(DWORD ofs, int bytes);
- void DBFlush(int setting);
- int InitCache(void);
-
__forceinline PBYTE DBRead(HANDLE hContact, int bytesRequired, int *bytesAvail)
{ return DBRead((DWORD)hContact, bytesRequired, bytesAvail);
}
@@ -287,3 +288,24 @@ protected: DWORD GetModuleNameOfs(const char *szName);
char *GetModuleNameByOfs(DWORD ofs);
};
+
+struct CDb3Mmap : public CDb3Base
+{
+ CDb3Mmap(const TCHAR* ptszFileName);
+ ~CDb3Mmap();
+
+protected:
+ virtual void DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes);
+ virtual PBYTE DBRead(DWORD ofs, int bytesRequired, int *bytesAvail);
+ virtual void DBWrite(DWORD ofs, PVOID pData, int bytes);
+ virtual void DBFill(DWORD ofs, int bytes);
+ virtual void DBFlush(int setting);
+ virtual int InitCache(void);
+
+protected:
+ PBYTE m_pNull;
+ HANDLE m_hMap;
+
+ void Map();
+ void ReMap(DWORD needed);
+};
diff --git a/plugins/Db3x_mmap/src/dbmodulechain.cpp b/plugins/Db3x_mmap/src/dbmodulechain.cpp index f8b25ef879..67d723eec3 100644 --- a/plugins/Db3x_mmap/src/dbmodulechain.cpp +++ b/plugins/Db3x_mmap/src/dbmodulechain.cpp @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
-void CDdxMmap::AddToList(char *name, DWORD len, DWORD ofs)
+void CDb3Base::AddToList(char *name, DWORD len, DWORD ofs)
{
ModuleName *mn = (ModuleName*)HeapAlloc(m_hModHeap,0,sizeof(ModuleName));
mn->name = name;
@@ -38,7 +38,7 @@ void CDdxMmap::AddToList(char *name, DWORD len, DWORD ofs) m_lOfs.insert(mn);
}
-int CDdxMmap::InitModuleNames(void)
+int CDb3Base::InitModuleNames(void)
{
DWORD ofsThis = m_dbHeader.ofsFirstModuleName;
DBModuleName *dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
@@ -60,7 +60,7 @@ int CDdxMmap::InitModuleNames(void) return 0;
}
-DWORD CDdxMmap::FindExistingModuleNameOfs(const char *szName)
+DWORD CDb3Base::FindExistingModuleNameOfs(const char *szName)
{
ModuleName mn = { (char*)szName, 0 };
if (m_lastmn && !strcmp(mn.name, m_lastmn->name))
@@ -77,7 +77,7 @@ DWORD CDdxMmap::FindExistingModuleNameOfs(const char *szName) }
//will create the offset if it needs to
-DWORD CDdxMmap::GetModuleNameOfs(const char *szName)
+DWORD CDb3Base::GetModuleNameOfs(const char *szName)
{
struct DBModuleName dbmn;
int nameLen;
@@ -109,7 +109,7 @@ DWORD CDdxMmap::GetModuleNameOfs(const char *szName) return ofsNew;
}
-char* CDdxMmap::GetModuleNameByOfs(DWORD ofs)
+char* CDb3Base::GetModuleNameByOfs(DWORD ofs)
{
if (m_lastmn && m_lastmn->ofs == ofs)
return m_lastmn->name;
@@ -126,7 +126,7 @@ char* CDdxMmap::GetModuleNameByOfs(DWORD ofs) return NULL;
}
-STDMETHODIMP_(BOOL) CDdxMmap::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
+STDMETHODIMP_(BOOL) CDb3Base::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
{
for (int i = 0; i < m_lMods.getCount(); i++) {
ModuleName *pmn = m_lMods[i];
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp index 49ac018047..dac7f88b18 100644 --- a/plugins/Db3x_mmap/src/dbsettings.cpp +++ b/plugins/Db3x_mmap/src/dbsettings.cpp @@ -28,7 +28,7 @@ DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index); int DBPreset_QuerySetting(const char *szModule, const char *szSetting, DBVARIANT *dbv, BOOL isStatic);
-DWORD CDdxMmap::GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsModuleName)
+DWORD CDb3Base::GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsModuleName)
{
DWORD ofsThis = dbc->ofsFirstSettings;
while (ofsThis) {
@@ -49,7 +49,7 @@ DWORD __forceinline GetSettingValueLength(PBYTE pSetting) return pSetting[0];
}
-char* CDdxMmap::InsertCachedSetting(const char* szName, size_t cbNameLen)
+char* CDb3Base::InsertCachedSetting(const char* szName, size_t cbNameLen)
{
char* newValue = (char*)HeapAlloc(m_hCacheHeap, 0, cbNameLen);
*newValue = 0;
@@ -58,7 +58,7 @@ char* CDdxMmap::InsertCachedSetting(const char* szName, size_t cbNameLen) return newValue;
}
-char* CDdxMmap::GetCachedSetting(const char *szModuleName,const char *szSettingName, int moduleNameLen, int settingNameLen)
+char* CDb3Base::GetCachedSetting(const char *szModuleName,const char *szSettingName, int moduleNameLen, int settingNameLen)
{
char szFullName[512];
strcpy(szFullName+1,szModuleName);
@@ -77,7 +77,7 @@ char* CDdxMmap::GetCachedSetting(const char *szModuleName,const char *szSettingN return m_lastSetting;
}
-void CDdxMmap::SetCachedVariant( DBVARIANT* s /* new */, DBVARIANT* d /* cached */ )
+void CDb3Base::SetCachedVariant( DBVARIANT* s /* new */, DBVARIANT* d /* cached */ )
{
char* szSave = ( d->type == DBVT_UTF8 || d->type == DBVT_ASCIIZ ) ? d->pszVal : NULL;
@@ -104,13 +104,13 @@ void CDdxMmap::SetCachedVariant( DBVARIANT* s /* new */, DBVARIANT* d /* cached #endif
}
-void CDdxMmap::FreeCachedVariant( DBVARIANT* V )
+void CDb3Base::FreeCachedVariant( DBVARIANT* V )
{
if (( V->type == DBVT_ASCIIZ || V->type == DBVT_UTF8 ) && V->pszVal != NULL )
HeapFree(m_hCacheHeap,0,V->pszVal);
}
-DBVARIANT* CDdxMmap::GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllocate )
+DBVARIANT* CDb3Base::GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllocate )
{
if ( hContact == 0 ) {
DBCachedGlobalValue Vtemp, *V;
@@ -201,7 +201,7 @@ DBVARIANT* CDdxMmap::GetCachedValuePtr( HANDLE hContact, char* szSetting, int bA #define MoveAlong(n) {int x = n; pBlob += (x); ofsBlobPtr += (x); bytesRemaining -= (x);}
#define VLT(n) ((n == DBVT_UTF8)?DBVT_ASCIIZ:n)
-int CDdxMmap::GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic)
+int CDb3Base::GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic)
{
DBContact *dbc;
DWORD ofsModuleName,ofsContact,ofsSettingsGroup,ofsBlobPtr;
@@ -374,7 +374,7 @@ int CDdxMmap::GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs return 1;
}
-STDMETHODIMP_(BOOL) CDdxMmap::GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dgs)
+STDMETHODIMP_(BOOL) CDb3Base::GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
dgs->pValue->type = 0;
if ( GetContactSettingWorker(hContact, dgs, 0 ))
@@ -408,7 +408,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::GetContactSetting(HANDLE hContact, DBCONTACTGETSET return 0;
}
-STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStr(HANDLE hContact, DBCONTACTGETSETTING *dgs)
+STDMETHODIMP_(BOOL) CDb3Base::GetContactSettingStr(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
int iSaveType = dgs->pValue->type;
@@ -455,7 +455,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStr(HANDLE hContact, DBCONTACTGET return 0;
}
-STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStatic(HANDLE hContact, DBCONTACTGETSETTING *dgs)
+STDMETHODIMP_(BOOL) CDb3Base::GetContactSettingStatic(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
if ( GetContactSettingWorker(hContact, dgs, 1 ))
return 1;
@@ -468,7 +468,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStatic(HANDLE hContact, DBCONTACT return 0;
}
-STDMETHODIMP_(BOOL) CDdxMmap::FreeVariant(DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDb3Base::FreeVariant(DBVARIANT *dbv)
{
if ( dbv == 0 ) return 1;
switch ( dbv->type ) {
@@ -491,7 +491,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::FreeVariant(DBVARIANT *dbv) return 0;
}
-STDMETHODIMP_(BOOL) CDdxMmap::SetSettingResident(BOOL bIsResident, const char *pszSettingName)
+STDMETHODIMP_(BOOL) CDb3Base::SetSettingResident(BOOL bIsResident, const char *pszSettingName)
{
size_t cbSettingNameLen = strlen(pszSettingName) + 2;
if (cbSettingNameLen < 512) {
@@ -519,7 +519,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::SetSettingResident(BOOL bIsResident, const char *p return 0;
}
-STDMETHODIMP_(BOOL) CDdxMmap::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
+STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
{
DBCONTACTWRITESETTING tmp;
DWORD ofsModuleName;
@@ -788,7 +788,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT return 0;
}
-STDMETHODIMP_(BOOL) CDdxMmap::DeleteContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
+STDMETHODIMP_(BOOL) CDb3Base::DeleteContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
{
DBContact *dbc;
DWORD ofsModuleName,ofsSettingsGroup,ofsBlobPtr;
@@ -880,7 +880,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::DeleteContactSetting(HANDLE hContact, DBCONTACTGET return 0;
}
-STDMETHODIMP_(BOOL) CDdxMmap::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces)
+STDMETHODIMP_(BOOL) CDb3Base::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces)
{
DBContact *dbc;
DWORD ofsModuleName,ofsContact,ofsBlobPtr;
@@ -923,7 +923,7 @@ STDMETHODIMP_(BOOL) CDdxMmap::EnumContactSettings(HANDLE hContact, DBCONTACTENUM return result;
}
-STDMETHODIMP_(BOOL) CDdxMmap::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
+STDMETHODIMP_(BOOL) CDb3Base::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
{
for(int i = 0; i < m_lResidentSettings.getCount(); i++) {
int ret = pFunc(m_lResidentSettings[i], 0, (LPARAM)pParam);
diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp index b38fab0ce2..032b43b5d4 100644 --- a/plugins/Db3x_mmap/src/init.cpp +++ b/plugins/Db3x_mmap/src/init.cpp @@ -41,14 +41,14 @@ static PLUGININFOEX pluginInfo = HINSTANCE g_hInst = NULL;
-LIST<CDdxMmap> g_Dbs(1, (LIST<CDdxMmap>::FTSortFunc)HandleKeySort);
+LIST<CDb3Mmap> g_Dbs(1, (LIST<CDb3Mmap>::FTSortFunc)HandleKeySort);
/////////////////////////////////////////////////////////////////////////////////////////
// returns 0 if the profile is created, EMKPRF*
static int makeDatabase(const TCHAR *profile, int *error)
{
- CDdxMmap *tmp = new CDdxMmap(profile);
+ CDb3Mmap *tmp = new CDb3Mmap(profile);
if (tmp->Create() == ERROR_SUCCESS) {
tmp->CreateDbHeaders();
delete tmp;
@@ -62,7 +62,7 @@ static int makeDatabase(const TCHAR *profile, int *error) // returns 0 if the given profile has a valid header
static int grokHeader(const TCHAR *profile, int *error)
{
- CDdxMmap *tmp = new CDdxMmap(profile);
+ CDb3Mmap *tmp = new CDb3Mmap(profile);
if (tmp->Load(true) != ERROR_SUCCESS) {
delete tmp;
if (error != NULL) *error = EGROKPRF_CANTREAD;
@@ -104,7 +104,7 @@ static MIDatabase* LoadDatabase(const TCHAR *profile) // set the memory, lists & UTF8 manager
mir_getLP( &pluginInfo );
- CDdxMmap* db = new CDdxMmap(profile);
+ CDb3Mmap* db = new CDb3Mmap(profile);
if (db->Load(false) != ERROR_SUCCESS) {
delete db;
return NULL;
@@ -116,8 +116,8 @@ static MIDatabase* LoadDatabase(const TCHAR *profile) static int UnloadDatabase(MIDatabase* db)
{
- g_Dbs.remove((CDdxMmap*)db);
- delete (CDdxMmap*)db;
+ g_Dbs.remove((CDb3Mmap*)db);
+ delete (CDb3Mmap*)db;
return 0;
}
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj index 096c15d901..b31504a3f1 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj @@ -191,6 +191,7 @@ <ClCompile Include="..\Db3x_mmap\src\dbevents.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbheaders.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbintf.cpp" />
+ <ClCompile Include="..\Db3x_mmap\src\dbintfm.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbmodulechain.cpp" />
<ClCompile Include="..\Db3x_mmap\src\dbsettings.cpp" />
<ClCompile Include="src\dbintf_sa.cpp" />
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters index f7ebe6ae7e..92622e59c8 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters @@ -57,6 +57,9 @@ <ClCompile Include="..\Db3x_mmap\src\dbevents.cpp">
<Filter>Mmap files</Filter>
</ClCompile>
+ <ClCompile Include="..\Db3x_mmap\src\dbintfm.cpp">
+ <Filter>Mmap files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\commonheaders.h">
diff --git a/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp b/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp index b85b3481cb..05db621e7a 100644 --- a/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp +++ b/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp @@ -34,13 +34,13 @@ int InitDialogs(void); DBSignature dbSignatureSecured = {"Miranda ICQ SD",0x1A};
CDdxMmapSA::CDdxMmapSA(const TCHAR* tszFileName) :
- CDdxMmap(tszFileName)
+ CDb3Mmap(tszFileName)
{
}
int CDdxMmapSA::Load(bool bSkipInit)
{
- if ( CDdxMmap::Load(bSkipInit) != ERROR_SUCCESS)
+ if ( CDb3Mmap::Load(bSkipInit) != ERROR_SUCCESS)
return 1;
if ( CheckDbHeaders())
diff --git a/plugins/Dbx_mmap_SA/src/dbintf_sa.h b/plugins/Dbx_mmap_SA/src/dbintf_sa.h index 8c6c9c04dc..d532855420 100644 --- a/plugins/Dbx_mmap_SA/src/dbintf_sa.h +++ b/plugins/Dbx_mmap_SA/src/dbintf_sa.h @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\Db3x_mmap\src\dbintf.h"
-struct CDdxMmapSA : public CDdxMmap
+struct CDdxMmapSA : public CDb3Mmap
{
CDdxMmapSA(const TCHAR* tszFileName);
|