summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-18 14:11:28 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-18 14:11:28 +0000
commit4bc88d46fa9859615521f436511d4f102f20eb67 (patch)
tree3a6ee91b74be2a4f5e60520885aa601c74bc3fa7
parent4f8f5427687792492ee49e06cafb9bd50cfc53d4 (diff)
databases are still static, but are controlled via classes
git-svn-id: http://svn.miranda-ng.org/main/trunk@1014 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--bin10/lib/mir_core.libbin28388 -> 28694 bytes
-rw-r--r--include/newpluginapi.h85
-rw-r--r--plugins/Db3x/db3x_10.vcxproj3
-rw-r--r--plugins/Db3x/db3x_10.vcxproj.filters7
-rw-r--r--plugins/Db3x/src/commonheaders.h5
-rw-r--r--plugins/Db3x/src/database.cpp41
-rw-r--r--plugins/Db3x/src/database.h15
-rw-r--r--plugins/Db3x/src/dbcache.cpp92
-rw-r--r--plugins/Db3x/src/dbcontacts.cpp268
-rw-r--r--plugins/Db3x/src/dbevents.cpp392
-rw-r--r--plugins/Db3x/src/dbheaders.cpp40
-rw-r--r--plugins/Db3x/src/dbintf.cpp (renamed from plugins/Db3x_mmap/encryption.h)27
-rw-r--r--plugins/Db3x/src/dbintf.h68
-rw-r--r--plugins/Db3x/src/dbmodulechain.cpp71
-rw-r--r--plugins/Db3x/src/dbsettings.cpp406
-rw-r--r--plugins/Db3x/src/encrypt.cpp66
-rw-r--r--plugins/Db3x/src/init.cpp49
-rw-r--r--plugins/Db3x_mmap/commonheaders.h6
-rw-r--r--plugins/Db3x_mmap/database.cpp49
-rw-r--r--plugins/Db3x_mmap/database.h67
-rw-r--r--plugins/Db3x_mmap/db3x_mmap_10.vcxproj3
-rw-r--r--plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters10
-rw-r--r--plugins/Db3x_mmap/dbcache.cpp17
-rw-r--r--plugins/Db3x_mmap/dbcontacts.cpp291
-rw-r--r--plugins/Db3x_mmap/dbevents.cpp384
-rw-r--r--plugins/Db3x_mmap/dbheaders.cpp38
-rw-r--r--plugins/Db3x_mmap/dbmodulechain.cpp37
-rw-r--r--plugins/Db3x_mmap/dbsettings.cpp362
-rw-r--r--plugins/Db3x_mmap/init.cpp58
-rw-r--r--plugins/Dbx_mmap_SA/commonheaders.h17
-rw-r--r--plugins/Dbx_mmap_SA/database.cpp64
-rw-r--r--plugins/Dbx_mmap_SA/database.h19
-rw-r--r--plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj2
-rw-r--r--plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters6
-rw-r--r--plugins/Dbx_mmap_SA/dbcache.cpp22
-rw-r--r--plugins/Dbx_mmap_SA/dbcontacts.cpp202
-rw-r--r--plugins/Dbx_mmap_SA/dbevents.cpp452
-rw-r--r--plugins/Dbx_mmap_SA/dbheaders.cpp38
-rw-r--r--plugins/Dbx_mmap_SA/dbintf.cpp38
-rw-r--r--plugins/Dbx_mmap_SA/dbintf.h87
-rw-r--r--plugins/Dbx_mmap_SA/dbmodulechain.cpp37
-rw-r--r--plugins/Dbx_mmap_SA/dbpreset.cpp60
-rw-r--r--plugins/Dbx_mmap_SA/dbsettings.cpp380
-rw-r--r--plugins/Dbx_mmap_SA/dialogs.cpp95
-rw-r--r--plugins/Dbx_mmap_SA/encrypt.cpp8
-rw-r--r--plugins/Dbx_mmap_SA/init.cpp50
-rw-r--r--plugins/Dbx_mmap_SA/security.cpp75
-rw-r--r--plugins/Dbx_tree/Compatibility.cpp273
-rw-r--r--plugins/Dbx_tree/Compatibility.h34
-rw-r--r--plugins/Dbx_tree/DataBase.cpp8
-rw-r--r--plugins/Dbx_tree/DataBase.h40
-rw-r--r--plugins/Dbx_tree/DatabaseLink.cpp44
-rw-r--r--plugins/Dbx_tree/Interface.h3
-rw-r--r--src/core/commonheaders.h1
-rw-r--r--src/core/miranda.h4
-rw-r--r--src/core/modules.cpp2
-rw-r--r--src/mir_core/commonheaders.h1
-rw-r--r--src/mir_core/db.cpp7
-rw-r--r--src/miranda32_10.vcxproj7
-rw-r--r--src/miranda32_10.vcxproj.filters18
-rw-r--r--src/modules/crypt/encrypt.cpp (renamed from plugins/Db3x_mmap/encrypt.cpp)11
-rw-r--r--src/modules/database/database.cpp21
-rw-r--r--src/modules/database/profilemanager.cpp17
-rw-r--r--src/modules/utils/utils.cpp6
64 files changed, 2480 insertions, 2626 deletions
diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib
index ad2dc04458..5b5d5dc181 100644
--- a/bin10/lib/mir_core.lib
+++ b/bin10/lib/mir_core.lib
Binary files differ
diff --git a/include/newpluginapi.h b/include/newpluginapi.h
index 3e70b8adc4..2437a0b1d2 100644
--- a/include/newpluginapi.h
+++ b/include/newpluginapi.h
@@ -122,35 +122,6 @@ typedef struct PLUGININFOEX_tag
//lParam = HINSTANCE of the plugin to be unloaded
#define ME_SYSTEM_MODULEUNLOAD "Miranda/System/UnloadModule"
-//see modules.h for what all this stuff is
-typedef struct tagPLUGINLINK {
- HANDLE (*CreateHookableEvent)(const char *);
- int (*DestroyHookableEvent)(HANDLE);
- int (*NotifyEventHooks)(HANDLE, WPARAM, LPARAM);
- HANDLE (*HookEvent)(const char *, MIRANDAHOOK);
- HANDLE (*HookEventMessage)(const char *, HWND, UINT);
- int (*UnhookEvent)(HANDLE);
- HANDLE (*CreateServiceFunction)(const char *, MIRANDASERVICE);
- HANDLE (*CreateTransientServiceFunction)(const char *, MIRANDASERVICE);
- int (*DestroyServiceFunction)(HANDLE);
- INT_PTR (*CallService)(const char *, WPARAM, LPARAM);
- int (*ServiceExists)(const char *); //v0.1.0.1+
- INT_PTR (*CallServiceSync)(const char *, WPARAM, LPARAM); //v0.3.3+
- int (*CallFunctionAsync) (void (__stdcall *)(void *), void *); //v0.3.4+
- int (*SetHookDefaultForHookableEvent) (HANDLE, MIRANDAHOOK); // v0.3.4 (2004/09/15)
- HANDLE (*CreateServiceFunctionParam)(const char *, MIRANDASERVICEPARAM, LPARAM); // v0.7+ (2007/04/24)
- int (*NotifyEventHooksDirect)(HANDLE, WPARAM, LPARAM); // v0.7+
- INT_PTR (*CallProtoService)(const char *, const char *, WPARAM, LPARAM);
- INT_PTR (*CallContactService)(HANDLE, const char *, WPARAM, LPARAM);
- HANDLE (*HookEventParam)(const char *, MIRANDAHOOKPARAM, LPARAM);
- HANDLE (*HookEventObj)(const char *, MIRANDAHOOKOBJ, void*);
- HANDLE (*HookEventObjParam)(const char *, MIRANDAHOOKOBJPARAM, void*, LPARAM);
- HANDLE (*CreateServiceFunctionObj)(const char *, MIRANDASERVICEOBJ, void*);
- HANDLE (*CreateServiceFunctionObjParam)(const char *, MIRANDASERVICEOBJPARAM, void*, LPARAM);
- void (*KillObjectServices)(void *);
- void (*KillObjectEventHooks)(void *);
-} PLUGINLINK;
-
/*
Database plugin stuff
*/
@@ -165,60 +136,4 @@ typedef struct tagPLUGINLINK {
// makeDatabase() error codes
#define EMKPRF_CREATEFAILED 1 // for some reason CreateFile() didnt like something
-typedef struct {
- int cbSize;
-
- /*
- returns what the driver can do given the flag
- */
- int (*getCapability) (int flag);
-
- /*
- buf: pointer to a string buffer
- cch: length of buffer
- shortName: if true, the driver should return a short but descriptive name, e.g. "3.xx profile"
- Affect: The database plugin must return a "friendly name" into buf and not exceed cch bytes,
- e.g. "Database driver for 3.xx profiles"
- Returns: 0 on success, non zero on failure
- */
- int (*getFriendlyName) (char * buf, size_t cch, int shortName);
-
- /*
- profile: pointer to a string which contains full path + name
- Affect: The database plugin should create the profile, the filepath will not exist at
- the time of this call, profile will be C:\..\<name>.dat
- Note: Do not prompt the user in anyway about this operation.
- Note: Do not initialise internal data structures at this point!
- Returns: 0 on success, non zero on failure - error contains extended error information, see EMKPRF_*
- */
- int (*makeDatabase) (char * profile, int * error);
-
- /*
- profile: [in] a null terminated string to file path of selected profile
- error: [in/out] pointer to an int to set with error if any
- Affect: Ask the database plugin if it supports the given profile, if it does it will
- return 0, if it doesnt return 1, with the error set in error -- EGROKPRF_* can be valid error
- condition, most common error would be [EGROKPRF_UNKHEADER]
- Note: Just because 1 is returned, doesnt mean the profile is not supported, the profile might be damaged
- etc.
- Returns: 0 on success, non zero on failure
- */
- int (*grokHeader) (char * profile, int * error);
-
- /*
- Affect: Tell the database to create all services/hooks that a 3.xx legecy database might support into link,
- which is a PLUGINLINK structure
- Returns: 0 on success, nonzero on failure
- */
- int (*Load) (char * profile);
-
- /*
- Affect: The database plugin should shutdown, unloading things from the core and freeing internal structures
- Returns: 0 on success, nonzero on failure
- Note: Unload() might be called even if Load(void) was never called, wasLoaded is set to 1 if Load(void) was ever called.
- */
- int (*Unload) (int wasLoaded);
-
-} DATABASELINK;
-
#endif // M_NEWPLUGINAPI_H__
diff --git a/plugins/Db3x/db3x_10.vcxproj b/plugins/Db3x/db3x_10.vcxproj
index bd702267d1..441e103858 100644
--- a/plugins/Db3x/db3x_10.vcxproj
+++ b/plugins/Db3x/db3x_10.vcxproj
@@ -204,9 +204,9 @@
<ClCompile Include="src\dbcontacts.cpp" />
<ClCompile Include="src\dbevents.cpp" />
<ClCompile Include="src\dbheaders.cpp" />
+ <ClCompile Include="src\dbintf.cpp" />
<ClCompile Include="src\dbmodulechain.cpp" />
<ClCompile Include="src\dbsettings.cpp" />
- <ClCompile Include="src\encrypt.cpp" />
<ClCompile Include="src\init.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
@@ -214,6 +214,7 @@
<ItemGroup>
<ClInclude Include="src\commonheaders.h" />
<ClInclude Include="src\database.h" />
+ <ClInclude Include="src\dbintf.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc" />
diff --git a/plugins/Db3x/db3x_10.vcxproj.filters b/plugins/Db3x/db3x_10.vcxproj.filters
index 19e4fdcf15..682ea4edc7 100644
--- a/plugins/Db3x/db3x_10.vcxproj.filters
+++ b/plugins/Db3x/db3x_10.vcxproj.filters
@@ -36,10 +36,10 @@
<ClCompile Include="src\dbsettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\encrypt.cpp">
+ <ClCompile Include="src\init.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\init.cpp">
+ <ClCompile Include="src\dbintf.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@@ -50,6 +50,9 @@
<ClInclude Include="src\database.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="src\dbintf.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc">
diff --git a/plugins/Db3x/src/commonheaders.h b/plugins/Db3x/src/commonheaders.h
index cf4b2d4985..52734be2d0 100644
--- a/plugins/Db3x/src/commonheaders.h
+++ b/plugins/Db3x/src/commonheaders.h
@@ -43,11 +43,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <newpluginapi.h>
#include <win2k.h>
#include <m_system.h>
+#include <m_system_cpp.h>
#include <m_database.h>
+#include <m_db_int.h>
#include <m_langpack.h>
#include "version.h"
#include "database.h"
+#include "dbintf.h"
#include "resource.h"
extern HANDLE hDbFile;
@@ -55,7 +58,7 @@ extern CRITICAL_SECTION csDbAccess;
extern struct DBHeader dbHeader;
extern HANDLE hCacheHeap;
extern SortedList lContacts;
-extern char szDbPath[MAX_PATH];
+extern TCHAR szDbPath[MAX_PATH];
#ifdef __GNUC__
#define mir_i64(x) (x##LL)
diff --git a/plugins/Db3x/src/database.cpp b/plugins/Db3x/src/database.cpp
index 0172bde5b2..a9054bb591 100644
--- a/plugins/Db3x/src/database.cpp
+++ b/plugins/Db3x/src/database.cpp
@@ -31,8 +31,6 @@ void UninitSettings(void);
int InitContacts(void);
void UninitContacts(void);
int InitEvents(void);
-void UninitEvents(void);
-int InitCrypt(void);
int InitModuleNames(void);
void UninitModuleNames(void);
int InitCache(void);
@@ -40,10 +38,10 @@ void UninitCache(void);
int InitIni(void);
void UninitIni(void);
-HANDLE hDbFile=INVALID_HANDLE_VALUE;
+HANDLE hDbFile = INVALID_HANDLE_VALUE;
CRITICAL_SECTION csDbAccess;
struct DBHeader dbHeader;
-char szDbPath[MAX_PATH];
+TCHAR szDbPath[MAX_PATH];
static void UnloadDatabase(void)
{
@@ -54,8 +52,8 @@ DWORD CreateNewSpace(int bytes)
{
DWORD ofsNew;
- ofsNew=dbHeader.ofsFileEnd;
- dbHeader.ofsFileEnd+=bytes;
+ ofsNew = dbHeader.ofsFileEnd;
+ dbHeader.ofsFileEnd += bytes;
DBWrite(0,&dbHeader,sizeof(dbHeader));
log2("newspace %d@%08x",bytes,ofsNew);
return ofsNew;
@@ -65,9 +63,9 @@ void DeleteSpace(DWORD ofs,int bytes)
{
PBYTE buf;
log2("deletespace %d@%08x",bytes,ofs);
- dbHeader.slackSpace+=bytes;
+ dbHeader.slackSpace += bytes;
DBWrite(0,&dbHeader,sizeof(dbHeader));
- buf=(PBYTE)mir_alloc(bytes);
+ buf = (PBYTE)mir_alloc(bytes);
memset(buf,0,bytes);
DBWrite(ofs,buf,bytes);
mir_free(buf);
@@ -75,8 +73,6 @@ void DeleteSpace(DWORD ofs,int bytes)
void UnloadDatabaseModule(void)
{
- //UninitIni();
- UninitEvents();
UninitSettings();
UninitContacts();
UninitModuleNames();
@@ -90,8 +86,8 @@ int LoadDatabaseModule(void)
InitializeCriticalSection(&csDbAccess);
log0("DB logging running");
{
- DWORD dummy=0;
- hDbFile=CreateFileA(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
+ DWORD dummy = 0;
+ hDbFile = CreateFile(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
if ( hDbFile == INVALID_HANDLE_VALUE ) {
return 1;
}
@@ -100,17 +96,16 @@ int LoadDatabaseModule(void)
return 1;
}
}
- //if(ParseCommandLine()) return 1;
- if(InitCache()) return 1;
- if(InitModuleNames()) return 1;
- if(InitContacts()) return 1;
- if(InitSettings()) return 1;
- if(InitEvents()) return 1;
- if(InitCrypt()) return 1;
+ //if (ParseCommandLine()) return 1;
+ if (InitCache()) return 1;
+ if (InitModuleNames()) return 1;
+ if (InitContacts()) return 1;
+ if (InitSettings()) return 1;
+ if (InitEvents()) return 1;
return 0;
}
-static DWORD DatabaseCorrupted=0;
+static DWORD DatabaseCorrupted = 0;
void __cdecl dbpanic(void *arg)
{
@@ -121,10 +116,10 @@ void __cdecl dbpanic(void *arg)
void DatabaseCorruption(void)
{
- int kill=0;
+ int kill = 0;
EnterCriticalSection(&csDbAccess);
- if (DatabaseCorrupted==0) {
+ if (DatabaseCorrupted == 0) {
DatabaseCorrupted++;
kill++;
} else {
@@ -151,7 +146,7 @@ void DBLog(const char *file,int line,const char *fmt,...)
va_start(vararg,fmt);
mir_vsnprintf(str,sizeof(str),fmt,vararg);
va_end(vararg);
- fp=fopen("c:\\mirandadatabase.log.txt","at");
+ fp = fopen("c:\\mirandadatabase.log.txt","at");
fprintf(fp,"%u: %s %d: %s\n",GetTickCount(),file,line,str);
fclose(fp);
}
diff --git a/plugins/Db3x/src/database.h b/plugins/Db3x/src/database.h
index 334e47002d..2394655e73 100644
--- a/plugins/Db3x/src/database.h
+++ b/plugins/Db3x/src/database.h
@@ -39,7 +39,7 @@ DBHeader
| | \-->module name (DBModuleName)
| \-->first/last/firstunread event
|-->user contact (DBContact)
- | |-->next contact=NULL
+ | |-->next contact = NULL
| |-->first settings as above
| \-->first/last/firstunread event as above
\-->first module name (DBModuleName)
@@ -54,7 +54,7 @@ DBHeader
#include <pshpack1.h>
struct DBHeader {
BYTE signature[16]; // 'Miranda ICQ DB',0,26
- DWORD version; //as 4 bytes, ie 1.2.3.10=0x0102030a
+ 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
@@ -63,8 +63,8 @@ struct DBHeader {
//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 struct DBContact in the chain
- DWORD ofsUser; //offset to struct DBContact representing 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
};
@@ -102,13 +102,13 @@ struct DBContactSettings {
//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
+ //structs, the last has cbName = 0
};
/* not a valid structure, content is figured out on the fly
struct DBSetting {
BYTE cbName; //number of bytes in the name of this setting
- //this =0 marks the end
+ //this = 0 marks the end
char szName[...]; //setting name, excluding nul
BYTE dataType; //type of data. see m_database.h, db/contact/getsetting
union { //a load of types of data, length is defined by dataType
@@ -174,6 +174,9 @@ typedef struct
//databasecorruption: called if any signatures are broken. very very fatal
void DatabaseCorruption(void);
PBYTE DBRead(DWORD ofs,int bytesRequired,int *bytesAvail); //any preview result could be invalidated by the next call
+__forceinline PBYTE DBRead(HANDLE hContact,int bytesRequired,int *bytesAvail)
+{ return DBRead((DWORD)hContact, bytesRequired, bytesAvail);
+}
void DBWrite(DWORD ofs,PVOID pData,int count);
void DBFlush(int setting);
void DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes);
diff --git a/plugins/Db3x/src/dbcache.cpp b/plugins/Db3x/src/dbcache.cpp
index 10d34e1ec3..c68db53a0a 100644
--- a/plugins/Db3x/src/dbcache.cpp
+++ b/plugins/Db3x/src/dbcache.cpp
@@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define CACHESECTIONSIZE 4096
#define CACHESECTIONCOUNT 32
-static BOOL safetyMode=TRUE;
+static BOOL safetyMode = TRUE;
static PBYTE pDbCache;
static DWORD lastUseCounter;
struct DBCacheSectionInfo {
@@ -37,23 +37,23 @@ struct DBCacheSectionInfo {
static __inline int FindSectionForOffset(const DWORD ofs)
{
int i;
- for(i=0;i<CACHESECTIONCOUNT;i++)
- if(ofs>=cacheSectionInfo[i].ofsBase && ofs<cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE)
+ for(i = 0;i<CACHESECTIONCOUNT;i++)
+ if (ofs >= cacheSectionInfo[i].ofsBase && ofs<cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE)
return i;
return -1;
}
static __inline int FindLRUSection(void)
{
- int i,lru=0;
- DWORD lowestLastUse=cacheSectionInfo[0].lastUsed;
- for(i=1;i<CACHESECTIONCOUNT;i++) if(cacheSectionInfo[i].lastUsed<lowestLastUse) {lru=i; lowestLastUse=cacheSectionInfo[i].lastUsed;}
+ int i,lru = 0;
+ DWORD lowestLastUse = cacheSectionInfo[0].lastUsed;
+ for(i = 1;i<CACHESECTIONCOUNT;i++) if (cacheSectionInfo[i].lastUsed<lowestLastUse) {lru = i; lowestLastUse = cacheSectionInfo[i].lastUsed;}
return lru;
}
static __inline void LoadSection(const int i,DWORD ofs)
{
- cacheSectionInfo[i].ofsBase=ofs-ofs%CACHESECTIONSIZE;
+ cacheSectionInfo[i].ofsBase = ofs-ofs%CACHESECTIONSIZE;
log1("readsect %08x",ofs);
SetFilePointer(hDbFile,cacheSectionInfo[i].ofsBase,NULL,FILE_BEGIN);
ReadFile(hDbFile,pDbCache+i*CACHESECTIONSIZE,CACHESECTIONSIZE,&ofs,NULL);
@@ -62,8 +62,8 @@ static __inline void LoadSection(const int i,DWORD ofs)
static __inline void MoveSection(int *sectId,int dest)
{
CopyMemory(pDbCache+dest*CACHESECTIONSIZE,pDbCache+(*sectId)*CACHESECTIONSIZE,CACHESECTIONSIZE);
- cacheSectionInfo[dest].ofsBase=cacheSectionInfo[*sectId].ofsBase;
- *sectId=dest;
+ cacheSectionInfo[dest].ofsBase = cacheSectionInfo[*sectId].ofsBase;
+ *sectId = dest;
}
@@ -79,25 +79,25 @@ PBYTE DBRead(DWORD ofs,int bytesRequired,int *bytesAvail)
part1sect = FindSectionForOffset(ofs);
if (ofs%CACHESECTIONSIZE+bytesRequired<CACHESECTIONSIZE) {
//only one section required
- if(part1sect==-1) {
- part1sect=FindLRUSection();
+ if (part1sect == -1) {
+ part1sect = FindLRUSection();
LoadSection(part1sect,ofs);
}
- cacheSectionInfo[part1sect].lastUsed=++lastUseCounter;
- if(bytesAvail!=NULL) *bytesAvail=cacheSectionInfo[part1sect].ofsBase+CACHESECTIONSIZE-ofs;
+ cacheSectionInfo[part1sect].lastUsed = ++lastUseCounter;
+ if (bytesAvail!= NULL) *bytesAvail = cacheSectionInfo[part1sect].ofsBase+CACHESECTIONSIZE-ofs;
return pDbCache+part1sect*CACHESECTIONSIZE+(ofs-cacheSectionInfo[part1sect].ofsBase);
}
//two sections are required
- part2sect=FindSectionForOffset(ofs+CACHESECTIONSIZE);
- if(part1sect!=-1) {
- if(part2sect==-1) { //first part in cache, but not second part
- if(part1sect==CACHESECTIONCOUNT-1) MoveSection(&part1sect,0);
+ part2sect = FindSectionForOffset(ofs+CACHESECTIONSIZE);
+ if (part1sect!= -1) {
+ if (part2sect == -1) { //first part in cache, but not second part
+ if (part1sect == CACHESECTIONCOUNT-1) MoveSection(&part1sect,0);
LoadSection(part1sect+1,ofs+CACHESECTIONSIZE);
}
- else if(part2sect!=part1sect+1) { //both parts are in cache, but not already consecutive
- if(part1sect==CACHESECTIONCOUNT-1) {
+ else if (part2sect!= part1sect+1) { //both parts are in cache, but not already consecutive
+ if (part1sect == CACHESECTIONCOUNT-1) {
//first part is at end, move to before second part
- if(part2sect==0) //second part is at start: need to move both
+ if (part2sect == 0) //second part is at start: need to move both
MoveSection(&part2sect,1);
MoveSection(&part1sect,part2sect-1);
}
@@ -106,20 +106,20 @@ PBYTE DBRead(DWORD ofs,int bytesRequired,int *bytesAvail)
}
}
else {
- if(part2sect==-1) { //neither section is in cache
- part1sect=0; part2sect=1;
+ if (part2sect == -1) { //neither section is in cache
+ part1sect = 0; part2sect = 1;
LoadSection(part1sect,ofs); LoadSection(part2sect,ofs+CACHESECTIONSIZE);
}
else { //part 2 is in cache, but not part 1
- if(part2sect==0) MoveSection(&part2sect,1);
- part1sect=part2sect-1;
+ if (part2sect == 0) MoveSection(&part2sect,1);
+ part1sect = part2sect-1;
LoadSection(part1sect,ofs);
}
}
//both sections are now consecutive, starting at part1sect
- cacheSectionInfo[part1sect].lastUsed=++lastUseCounter;
- cacheSectionInfo[part1sect+1].lastUsed=++lastUseCounter;
- if(bytesAvail!=NULL) *bytesAvail=cacheSectionInfo[part1sect+1].ofsBase+CACHESECTIONSIZE-ofs;
+ cacheSectionInfo[part1sect].lastUsed = ++lastUseCounter;
+ cacheSectionInfo[part1sect+1].lastUsed = ++lastUseCounter;
+ if (bytesAvail!= NULL) *bytesAvail = cacheSectionInfo[part1sect+1].ofsBase+CACHESECTIONSIZE-ofs;
return pDbCache+part1sect*CACHESECTIONSIZE+(ofs-cacheSectionInfo[part1sect].ofsBase);
}
@@ -134,21 +134,21 @@ void DBWrite(DWORD ofs,PVOID pData,int bytes)
log2("write %d@%08x",bytes,ofs);
SetFilePointer(hDbFile,ofs,NULL,FILE_BEGIN);
- if (WriteFile(hDbFile,pData,bytes,&bytesWritten,NULL)==0)
+ if (WriteFile(hDbFile,pData,bytes,&bytesWritten,NULL) == 0)
{
DatabaseCorruption();
}
logg();
//check if any of the cache sections contain this bit
- for(i=0;i<CACHESECTIONCOUNT;i++) {
- if(ofs+bytes>=cacheSectionInfo[i].ofsBase && ofs<cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) {
- if(ofs<cacheSectionInfo[i].ofsBase) { //don't start at beginning
- if(ofs+bytes>=cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end
+ for(i = 0;i<CACHESECTIONCOUNT;i++) {
+ if (ofs+bytes >= cacheSectionInfo[i].ofsBase && ofs<cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) {
+ if (ofs<cacheSectionInfo[i].ofsBase) { //don't start at beginning
+ if (ofs+bytes >= cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end
CopyMemory(pDbCache+i*CACHESECTIONSIZE,(PBYTE)pData+cacheSectionInfo[i].ofsBase-ofs,CACHESECTIONSIZE);
else CopyMemory(pDbCache+i*CACHESECTIONSIZE,(PBYTE)pData+cacheSectionInfo[i].ofsBase-ofs,bytes-(cacheSectionInfo[i].ofsBase-ofs));
}
else { //start at beginning
- if(ofs+bytes>=cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end
+ if (ofs+bytes >= cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE) //don't finish at end
CopyMemory(pDbCache+i*CACHESECTIONSIZE+ofs-cacheSectionInfo[i].ofsBase,pData,cacheSectionInfo[i].ofsBase+CACHESECTIONSIZE-ofs);
else CopyMemory(pDbCache+i*CACHESECTIONSIZE+ofs-cacheSectionInfo[i].ofsBase,pData,bytes);
}
@@ -162,7 +162,7 @@ void DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes)
PBYTE buf;
log3("move %d %08x->%08x",bytes,ofsSource,ofsDest);
- buf=(PBYTE)mir_alloc(bytes);
+ buf = (PBYTE)mir_alloc(bytes);
SetFilePointer(hDbFile,ofsSource,NULL,FILE_BEGIN);
ReadFile(hDbFile,buf,bytes,&bytesRead,NULL);
DBWrite(ofsDest,buf,bytes);
@@ -183,35 +183,33 @@ void DBFlush(int setting)
{
if (!setting) {
log0("nflush1");
- if(safetyMode) FlushFileBuffers(hDbFile);
+ if (safetyMode) FlushFileBuffers(hDbFile);
log0("nflush2");
return;
}
KillTimer(NULL,flushBuffersTimerId);
- flushBuffersTimerId=SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc);
+ flushBuffersTimerId = SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc);
}
static INT_PTR CacheSetSafetyMode(WPARAM wParam,LPARAM lParam)
{
EnterCriticalSection(&csDbAccess);
- safetyMode=wParam;
+ safetyMode = wParam;
LeaveCriticalSection(&csDbAccess);
- if(safetyMode) FlushFileBuffers(hDbFile);
+ if (safetyMode) FlushFileBuffers(hDbFile);
return 0;
}
int InitCache(void)
{
- int i;
- DWORD bytesRead;
-
- CreateServiceFunction(MS_DB_SETSAFETYMODE,CacheSetSafetyMode);
- pDbCache=(PBYTE)mir_alloc(CACHESECTIONSIZE*CACHESECTIONCOUNT);
- lastUseCounter=CACHESECTIONCOUNT;
- for(i=0;i<CACHESECTIONCOUNT;i++) {
- cacheSectionInfo[i].ofsBase=0;
- cacheSectionInfo[i].lastUsed=i;
+ pDbCache = (PBYTE)mir_alloc(CACHESECTIONSIZE*CACHESECTIONCOUNT);
+ lastUseCounter = CACHESECTIONCOUNT;
+ for(int i = 0; i < CACHESECTIONCOUNT; i++) {
+ cacheSectionInfo[i].ofsBase = 0;
+ cacheSectionInfo[i].lastUsed = i;
SetFilePointer(hDbFile,cacheSectionInfo[i].ofsBase,NULL,FILE_BEGIN);
+
+ DWORD bytesRead;
ReadFile(hDbFile,pDbCache+i*CACHESECTIONSIZE,CACHESECTIONSIZE,&bytesRead,NULL);
}
return 0;
diff --git a/plugins/Db3x/src/dbcontacts.cpp b/plugins/Db3x/src/dbcontacts.cpp
index ef128a491e..d0fb0bbc97 100644
--- a/plugins/Db3x/src/dbcontacts.cpp
+++ b/plugins/Db3x/src/dbcontacts.cpp
@@ -23,25 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-static INT_PTR GetContactCount(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindFirstContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR AddContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam);
-
static HANDLE hContactDeletedEvent,hContactAddedEvent;
int InitContacts(void)
{
- CreateServiceFunction(MS_DB_CONTACT_GETCOUNT,GetContactCount);
- CreateServiceFunction(MS_DB_CONTACT_FINDFIRST,FindFirstContact);
- CreateServiceFunction(MS_DB_CONTACT_FINDNEXT,FindNextContact);
- CreateServiceFunction(MS_DB_CONTACT_DELETE,DeleteContact);
- CreateServiceFunction(MS_DB_CONTACT_ADD,AddContact);
- CreateServiceFunction(MS_DB_CONTACT_IS,IsDbContact);
- hContactDeletedEvent=CreateHookableEvent(ME_DB_CONTACT_DELETED);
- hContactAddedEvent=CreateHookableEvent(ME_DB_CONTACT_ADDED);
+ hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED);
+ hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED);
return 0;
}
@@ -51,166 +38,161 @@ void UninitContacts(void)
INT_PTR GetContactSettingStatic(WPARAM wParam,LPARAM lParam);
-static INT_PTR GetContactCount(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::GetContactCount(void)
{
- INT_PTR ret;
-
- EnterCriticalSection(&csDbAccess);
- ret=dbHeader.contactCount;
- LeaveCriticalSection(&csDbAccess);
- return ret;
+ mir_cslock lck(csDbAccess);
+ return dbHeader.contactCount;
}
#define proto_module "Protocol"
#define proto_setting "p"
-static int CheckProto(HANDLE hContact, const char *proto)
+int CDdxMmap::CheckProto(HANDLE hContact, const char *proto)
{
- static char protobuf[MAX_PATH] = {0};
- static DBVARIANT dbv;
- static DBCONTACTGETSETTING sVal = {proto_module,proto_setting,&dbv};
+ char protobuf[MAX_PATH] = {0};
+ DBVARIANT dbv;
+ DBCONTACTGETSETTING sVal = {proto_module,proto_setting,&dbv};
dbv.type = DBVT_ASCIIZ;
dbv.pszVal = protobuf;
dbv.cchVal = sizeof(protobuf);
- if (GetContactSettingStatic((WPARAM)hContact, (LPARAM )&sVal) != 0
- || (dbv.type != DBVT_ASCIIZ)) return 0;
+ if (GetContactSettingStatic(hContact, &sVal) != 0 || dbv.type != DBVT_ASCIIZ)
+ return 0;
return !strcmp(protobuf,proto);
}
-static INT_PTR FindFirstContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstContact(const char* szProto)
{
- INT_PTR ret = 0;
- EnterCriticalSection(&csDbAccess);
- ret = (INT_PTR)dbHeader.ofsFirstContact;
- if (lParam && !CheckProto((HANDLE)ret,(const char*)lParam))
- ret = FindNextContact((WPARAM)ret,lParam);
- LeaveCriticalSection(&csDbAccess);
+ mir_cslock lck(csDbAccess);
+
+ HANDLE ret = (HANDLE)dbHeader.ofsFirstContact;
+ if (szProto && !CheckProto(ret, szProto))
+ ret = FindNextContact(ret, szProto);
return ret;
}
-static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindNextContact(HANDLE hContact, const char* szProto)
{
- int index;
- struct DBContact *dbc;
DBCachedContactValueList VLtemp, *VL = NULL;
- VLtemp.hContact = (HANDLE)wParam;
- EnterCriticalSection(&csDbAccess);
+ VLtemp.hContact = hContact;
+
+ mir_cslock lck(csDbAccess);
+
while ( VLtemp.hContact ) {
- if ( List_GetIndex(&lContacts,&VLtemp,&index)) {
+ int index;
+ if ( List_GetIndex(&lContacts, &VLtemp, &index)) {
VL = ( DBCachedContactValueList* )lContacts.items[index];
if (VL->hNext != NULL) {
- if (!lParam || CheckProto(VL->hNext,(const char*)lParam)) {
- LeaveCriticalSection(&csDbAccess);
- return (INT_PTR)VL->hNext;
- }
+ if ( !szProto || CheckProto(VL->hNext, szProto))
+ return VL->hNext;
VLtemp.hContact = VL->hNext;
continue;
} }
- dbc=(struct DBContact*)DBRead((DWORD)VLtemp.hContact,sizeof(struct DBContact),NULL);
- if (dbc->signature!=DBCONTACT_SIGNATURE)
+ DBContact *dbc = (DBContact*)DBRead(VLtemp.hContact,sizeof(DBContact),NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
break;
- else {
- if ( VL == NULL ) {
- VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList));
- VL->hContact = VLtemp.hContact;
- List_Insert(&lContacts,VL,index);
- }
- VL->hNext = (HANDLE)dbc->ofsNext;
- if (VL->hNext != NULL && (!lParam || CheckProto(VL->hNext,(const char*)lParam))) {
- LeaveCriticalSection(&csDbAccess);
- return (INT_PTR)VL->hNext;
- }
- VLtemp.hContact = VL->hNext;
- } }
- LeaveCriticalSection(&csDbAccess);
+
+ if ( VL == NULL ) {
+ VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList));
+ VL->hContact = VLtemp.hContact;
+ List_Insert(&lContacts,VL,index);
+ }
+ VL->hNext = (HANDLE)dbc->ofsNext;
+ if (VL->hNext != NULL && (!szProto || CheckProto(VL->hNext, szProto)))
+ return VL->hNext;
+
+ VLtemp.hContact = VL->hNext;
+ }
return 0;
}
-static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::DeleteContact(HANDLE hContact)
{
- struct DBContact *dbc,*dbcPrev;
+ DBContact *dbcPrev;
DWORD ofsThis,ofsNext,ofsFirstEvent;
- struct DBContactSettings *dbcs;
- struct DBEvent *dbe;
+ DBContactSettings *dbcs;
+ DBEvent *dbe;
int index;
- if ((HANDLE)wParam==NULL) return 1;
- EnterCriticalSection(&csDbAccess);
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
- LeaveCriticalSection(&csDbAccess);
- return 1;
- }
- if ( (HANDLE)wParam == (HANDLE)dbHeader.ofsUser ) {
- LeaveCriticalSection(&csDbAccess);
- log0("FATAL: del of user chain attempted.");
- return 1;
+ if (hContact == NULL) return 1;
+ {
+ mir_cslock lck(csDbAccess);
+
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
+ return 1;
+
+ if ((DWORD)hContact == dbHeader.ofsUser ) {
+ log0("FATAL: del of user chain attempted.");
+ return 1;
+ }
+
+ log0("del contact");
}
- log0("del contact");
- LeaveCriticalSection(&csDbAccess);
+
//call notifier while outside mutex
- NotifyEventHooks(hContactDeletedEvent,wParam,0);
+ NotifyEventHooks(hContactDeletedEvent, (WPARAM)hContact, 0);
+
//get back in
- EnterCriticalSection(&csDbAccess);
+ mir_cslock lck(csDbAccess);
- { DBCachedContactValueList VLtemp;
- VLtemp.hContact = (HANDLE)wParam;
- if ( List_GetIndex(&lContacts,&VLtemp,&index))
- {
- DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index];
- DBCachedContactValue* V = VL->first;
- while ( V != NULL ) {
- DBCachedContactValue* V1 = V->next;
- if ( V->value.type == DBVT_ASCIIZ )
- HeapFree( hCacheHeap, 0, V->value.pszVal );
- HeapFree( hCacheHeap, 0, V );
- V = V1;
- }
- HeapFree( hCacheHeap, 0, VL );
-
- List_Remove(&lContacts,index);
- } }
-
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
+ DBCachedContactValueList VLtemp;
+ VLtemp.hContact = hContact;
+ if ( List_GetIndex(&lContacts,&VLtemp,&index))
+ {
+ DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index];
+ DBCachedContactValue* V = VL->first;
+ while ( V != NULL ) {
+ DBCachedContactValue* V1 = V->next;
+ if ( V->value.type == DBVT_ASCIIZ )
+ HeapFree( hCacheHeap, 0, V->value.pszVal );
+ HeapFree( hCacheHeap, 0, V );
+ V = V1;
+ }
+ HeapFree( hCacheHeap, 0, VL );
+
+ List_Remove(&lContacts,index);
+ }
+
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
//delete settings chain
- ofsThis=dbc->ofsFirstSettings;
- ofsFirstEvent=dbc->ofsFirstEvent;
+ ofsThis = dbc->ofsFirstSettings;
+ ofsFirstEvent = dbc->ofsFirstEvent;
while(ofsThis) {
- dbcs=(struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
- ofsNext=dbcs->ofsNext;
+ dbcs = (struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
+ ofsNext = dbcs->ofsNext;
DeleteSpace(ofsThis,offsetof(struct DBContactSettings,blob)+dbcs->cbBlob);
- ofsThis=ofsNext;
+ ofsThis = ofsNext;
}
//delete event chain
- ofsThis=ofsFirstEvent;
+ ofsThis = ofsFirstEvent;
while(ofsThis) {
- dbe=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
- ofsNext=dbe->ofsNext;
- DeleteSpace(ofsThis,offsetof(struct DBEvent,blob)+dbe->cbBlob);
- ofsThis=ofsNext;
+ dbe = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
+ ofsNext = dbe->ofsNext;
+ DeleteSpace(ofsThis,offsetof(DBEvent,blob)+dbe->cbBlob);
+ ofsThis = ofsNext;
}
//find previous contact in chain and change ofsNext
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbHeader.ofsFirstContact==wParam) {
- dbHeader.ofsFirstContact=dbc->ofsNext;
+ dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ if (dbHeader.ofsFirstContact == (DWORD)hContact) {
+ dbHeader.ofsFirstContact = dbc->ofsNext;
DBWrite(0,&dbHeader,sizeof(dbHeader));
}
else {
- ofsNext=dbc->ofsNext;
- ofsThis=dbHeader.ofsFirstContact;
- dbcPrev=(struct DBContact*)DBRead(ofsThis,sizeof(struct DBContact),NULL);
- while(dbcPrev->ofsNext!=wParam) {
- if(dbcPrev->ofsNext==0) DatabaseCorruption();
- ofsThis=dbcPrev->ofsNext;
- dbcPrev=(struct DBContact*)DBRead(ofsThis,sizeof(struct DBContact),NULL);
+ ofsNext = dbc->ofsNext;
+ ofsThis = dbHeader.ofsFirstContact;
+ dbcPrev = (DBContact*)DBRead(ofsThis,sizeof(DBContact),NULL);
+ while(dbcPrev->ofsNext!= (DWORD)hContact) {
+ if (dbcPrev->ofsNext == 0) DatabaseCorruption();
+ ofsThis = dbcPrev->ofsNext;
+ dbcPrev = (DBContact*)DBRead(ofsThis,sizeof(DBContact),NULL);
}
- dbcPrev->ofsNext=ofsNext;
- DBWrite(ofsThis,dbcPrev,sizeof(struct DBContact));
+ dbcPrev->ofsNext = ofsNext;
+ DBWrite(ofsThis,dbcPrev,sizeof(DBContact));
{
DBCachedContactValueList VLtemp;
VLtemp.hContact = (HANDLE)ofsThis;
@@ -221,34 +203,34 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam)
} }
}
//delete contact
- DeleteSpace(wParam,sizeof(struct DBContact));
+ DeleteSpace((DWORD)hContact,sizeof(DBContact));
//decrement contact count
dbHeader.contactCount--;
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFlush(0);
+
//quit
- LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR AddContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::AddContact(void)
{
- struct DBContact dbc;
+ DBContact dbc;
DWORD ofsNew;
log0("add contact");
EnterCriticalSection(&csDbAccess);
- ofsNew=CreateNewSpace(sizeof(struct DBContact));
- dbc.signature=DBCONTACT_SIGNATURE;
- dbc.eventCount=0;
- dbc.ofsFirstEvent=dbc.ofsLastEvent=0;
- dbc.ofsFirstSettings=0;
- dbc.ofsNext=dbHeader.ofsFirstContact;
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
- dbHeader.ofsFirstContact=ofsNew;
+ ofsNew = CreateNewSpace(sizeof(DBContact));
+ dbc.signature = DBCONTACT_SIGNATURE;
+ dbc.eventCount = 0;
+ dbc.ofsFirstEvent = dbc.ofsLastEvent = 0;
+ dbc.ofsFirstSettings = 0;
+ dbc.ofsNext = dbHeader.ofsFirstContact;
+ dbc.ofsFirstUnreadEvent = 0;
+ dbc.timestampFirstUnread = 0;
+ dbHeader.ofsFirstContact = ofsNew;
dbHeader.contactCount++;
- DBWrite(ofsNew,&dbc,sizeof(struct DBContact));
+ DBWrite(ofsNew,&dbc,sizeof(DBContact));
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFlush(0);
@@ -263,29 +245,29 @@ static INT_PTR AddContact(WPARAM wParam,LPARAM lParam)
LeaveCriticalSection(&csDbAccess);
NotifyEventHooks(hContactAddedEvent,(WPARAM)ofsNew,0);
- return (INT_PTR)ofsNew;
+ return (HANDLE)ofsNew;
}
-static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::IsDbContact(HANDLE hContact)
{
- struct DBContact dbc;
- DWORD ofsContact=(DWORD)wParam;
+ DBContact dbc;
+ DWORD ofsContact = (DWORD)hContact;
INT_PTR ret;
EnterCriticalSection(&csDbAccess);
{
int index;
DBCachedContactValueList VLtemp,*VL;
- VLtemp.hContact = (HANDLE)wParam;
+ VLtemp.hContact = hContact;
if ( List_GetIndex(&lContacts,&VLtemp,&index))
ret = TRUE;
else {
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- ret=dbc.signature==DBCONTACT_SIGNATURE;
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ ret = dbc.signature == DBCONTACT_SIGNATURE;
if (ret) {
VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList));
- VL->hContact = (HANDLE)wParam;
+ VL->hContact = hContact;
List_Insert(&lContacts,VL,index);
} } }
diff --git a/plugins/Db3x/src/dbevents.cpp b/plugins/Db3x/src/dbevents.cpp
index be50babe57..2deb70c647 100644
--- a/plugins/Db3x/src/dbevents.cpp
+++ b/plugins/Db3x/src/dbevents.cpp
@@ -28,398 +28,380 @@ char *GetModuleNameByOfs(DWORD ofs);
static HANDLE hEventDeletedEvent,hEventAddedEvent,hEventFilterAddedEvent;
-static INT_PTR GetEventCount(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::GetEventCount(HANDLE hContact)
{
INT_PTR ret;
- struct DBContact *dbc;
+ DBContact *dbc;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=-1;
- else ret=dbc->eventCount;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ dbc = (DBContact*)DBRead(hContact, sizeof(DBContact),NULL);
+ if (dbc->signature!= DBCONTACT_SIGNATURE) ret = -1;
+ else ret = dbc->eventCount;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
{
- DBEVENTINFO *dbei=(DBEVENTINFO*)lParam;
- struct DBContact dbc;
- struct DBEvent dbe,*dbeTest;
+ DBContact dbc;
+ DBEvent dbe,*dbeTest;
DWORD ofsNew,ofsModuleName,ofsContact,ofsThis;
- if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 0;
- if(dbei->timestamp==0) return 0;
- if (NotifyEventHooks(hEventFilterAddedEvent,wParam,lParam)) {
+ if (dbei == NULL||dbei->cbSize!= sizeof(DBEVENTINFO)) return 0;
+ if (dbei->timestamp == 0) return 0;
+ if (NotifyEventHooks(hEventFilterAddedEvent, (WPARAM)hContact, (LPARAM)dbei))
return 0;
- }
+
EnterCriticalSection(&csDbAccess);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE) {
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ else
+ ofsContact = (DWORD)hContact;
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc.signature!= DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 0;
}
- ofsNew=CreateNewSpace(offsetof(struct DBEvent,blob)+dbei->cbBlob);
- ofsModuleName=GetModuleNameOfs(dbei->szModule);
-
- dbe.signature=DBEVENT_SIGNATURE;
- dbe.ofsModuleName=ofsModuleName;
- dbe.timestamp=dbei->timestamp;
- dbe.flags=dbei->flags;
- dbe.eventType=dbei->eventType;
- dbe.cbBlob=dbei->cbBlob;
+ ofsNew = CreateNewSpace(offsetof(DBEvent,blob)+dbei->cbBlob);
+ ofsModuleName = GetModuleNameOfs(dbei->szModule);
+
+ dbe.signature = DBEVENT_SIGNATURE;
+ dbe.ofsModuleName = ofsModuleName;
+ dbe.timestamp = dbei->timestamp;
+ dbe.flags = dbei->flags;
+ dbe.eventType = dbei->eventType;
+ dbe.cbBlob = dbei->cbBlob;
//find where to put it - sort by timestamp
- if(dbc.eventCount==0) {
- dbe.ofsPrev=wParam;
- dbe.ofsNext=0;
- dbe.flags|=DBEF_FIRST;
- dbc.ofsFirstEvent=dbc.ofsLastEvent=ofsNew;
+ if (dbc.eventCount == 0) {
+ dbe.ofsPrev = (DWORD)hContact;
+ dbe.ofsNext = 0;
+ dbe.flags |= DBEF_FIRST;
+ dbc.ofsFirstEvent = dbc.ofsLastEvent = ofsNew;
}
else {
- dbeTest=(struct DBEvent*)DBRead(dbc.ofsFirstEvent,sizeof(struct DBEvent),NULL);
+ dbeTest = (DBEvent*)DBRead(dbc.ofsFirstEvent,sizeof(DBEvent),NULL);
// Should new event be placed before first event in chain?
if (dbei->timestamp < dbeTest->timestamp) {
- dbe.ofsPrev=wParam;
- dbe.ofsNext=dbc.ofsFirstEvent;
- dbe.flags|=DBEF_FIRST;
- dbc.ofsFirstEvent=ofsNew;
- dbeTest=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeTest->flags&=~DBEF_FIRST;
- dbeTest->ofsPrev=ofsNew;
- DBWrite(dbe.ofsNext,dbeTest,sizeof(struct DBEvent));
+ dbe.ofsPrev = (DWORD)hContact;
+ dbe.ofsNext = dbc.ofsFirstEvent;
+ dbe.flags |= DBEF_FIRST;
+ dbc.ofsFirstEvent = ofsNew;
+ dbeTest = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeTest->flags &= ~DBEF_FIRST;
+ dbeTest->ofsPrev = ofsNew;
+ DBWrite(dbe.ofsNext,dbeTest,sizeof(DBEvent));
}
else {
// Loop through the chain, starting at the end
ofsThis = dbc.ofsLastEvent;
- dbeTest = (struct DBEvent*)DBRead(ofsThis, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
for (;;) {
// If the new event's timesstamp is equal to or greater than the
// current dbevent, it will be inserted after. If not, continue
// with the previous dbevent in chain.
- if (dbe.timestamp >= dbeTest->timestamp) {
+ if (dbe.timestamp >= dbeTest->timestamp) {
dbe.ofsPrev = ofsThis;
dbe.ofsNext = dbeTest->ofsNext;
dbeTest->ofsNext = ofsNew;
- DBWrite(ofsThis, dbeTest, sizeof(struct DBEvent));
+ DBWrite(ofsThis, dbeTest, sizeof(DBEvent));
if (dbe.ofsNext == 0)
dbc.ofsLastEvent = ofsNew;
else {
- dbeTest = (struct DBEvent*)DBRead(dbe.ofsNext, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(dbe.ofsNext, sizeof(DBEvent), NULL);
dbeTest->ofsPrev = ofsNew;
- DBWrite(dbe.ofsNext, dbeTest, sizeof(struct DBEvent));
+ DBWrite(dbe.ofsNext, dbeTest, sizeof(DBEvent));
}
break;
}
ofsThis = dbeTest->ofsPrev;
- dbeTest = (struct DBEvent*)DBRead(ofsThis, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
}
}
}
dbc.eventCount++;
if (!(dbe.flags&(DBEF_READ|DBEF_SENT))) {
- if(dbe.timestamp<dbc.timestampFirstUnread || dbc.timestampFirstUnread==0) {
- dbc.timestampFirstUnread=dbe.timestamp;
- dbc.ofsFirstUnreadEvent=ofsNew;
+ if (dbe.timestamp<dbc.timestampFirstUnread || dbc.timestampFirstUnread == 0) {
+ dbc.timestampFirstUnread = dbe.timestamp;
+ dbc.ofsFirstUnreadEvent = ofsNew;
}
}
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
- DBWrite(ofsNew,&dbe,offsetof(struct DBEvent,blob));
- DBWrite(ofsNew+offsetof(struct DBEvent,blob),dbei->pBlob,dbei->cbBlob);
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
+ DBWrite(ofsNew,&dbe,offsetof(DBEvent,blob));
+ DBWrite(ofsNew+offsetof(DBEvent,blob),dbei->pBlob,dbei->cbBlob);
DBFlush(0);
LeaveCriticalSection(&csDbAccess);
log1("add event @ %08x",ofsNew);
- NotifyEventHooks(hEventAddedEvent,wParam,(LPARAM)ofsNew);
- return (INT_PTR)ofsNew;
+ NotifyEventHooks(hEventAddedEvent,(WPARAM)hContact,(LPARAM)ofsNew);
+ return (HANDLE)ofsNew;
}
-static INT_PTR DeleteEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
{
- struct DBContact dbc;
+ DBContact dbc;
DWORD ofsContact,ofsThis;
- struct DBEvent dbe,*dbeNext,*dbePrev;
+ DBEvent dbe,*dbeNext,*dbePrev;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- dbe=*(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE || dbe.signature!=DBEVENT_SIGNATURE) {
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ else
+ ofsContact = (DWORD)hContact;
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ dbe = *(DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbc.signature!= DBCONTACT_SIGNATURE || dbe.signature!= DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
log1("delete event @ %08x",wParam);
LeaveCriticalSection(&csDbAccess);
+
//call notifier while outside mutex
- NotifyEventHooks(hEventDeletedEvent,wParam,lParam);
+ NotifyEventHooks(hEventDeletedEvent, (WPARAM)hContact, (LPARAM)hDbEvent);
+
//get back in
EnterCriticalSection(&csDbAccess);
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- dbe=*(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ dbe = *(DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
//check if this was the first unread, if so, recalc the first unread
- if(dbc.ofsFirstUnreadEvent==(DWORD)lParam) {
- dbeNext=&dbe;
+ if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
+ dbeNext = &dbe;
for (;;) {
- if(dbeNext->ofsNext==0) {
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
+ if (dbeNext->ofsNext == 0) {
+ dbc.ofsFirstUnreadEvent = 0;
+ dbc.timestampFirstUnread = 0;
break;
}
- ofsThis=dbeNext->ofsNext;
- dbeNext=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
+ ofsThis = dbeNext->ofsNext;
+ dbeNext = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
if (!(dbeNext->flags&(DBEF_READ|DBEF_SENT))) {
- dbc.ofsFirstUnreadEvent=ofsThis;
- dbc.timestampFirstUnread=dbeNext->timestamp;
+ dbc.ofsFirstUnreadEvent = ofsThis;
+ dbc.timestampFirstUnread = dbeNext->timestamp;
break;
}
}
}
//get previous and next events in chain and change offsets
- if(dbe.flags&DBEF_FIRST) {
- if(dbe.ofsNext==0) {
- dbc.ofsFirstEvent=dbc.ofsLastEvent=0;
+ if (dbe.flags&DBEF_FIRST) {
+ if (dbe.ofsNext == 0) {
+ dbc.ofsFirstEvent = dbc.ofsLastEvent = 0;
}
else {
- dbeNext=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeNext->flags|=DBEF_FIRST;
- dbeNext->ofsPrev=dbe.ofsPrev;
- DBWrite(dbe.ofsNext,dbeNext,sizeof(struct DBEvent));
- dbc.ofsFirstEvent=dbe.ofsNext;
+ dbeNext = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeNext->flags |= DBEF_FIRST;
+ dbeNext->ofsPrev = dbe.ofsPrev;
+ DBWrite(dbe.ofsNext,dbeNext,sizeof(DBEvent));
+ dbc.ofsFirstEvent = dbe.ofsNext;
}
}
else {
- if(dbe.ofsNext==0) {
- dbePrev=(struct DBEvent*)DBRead(dbe.ofsPrev,sizeof(struct DBEvent),NULL);
- dbePrev->ofsNext=0;
- DBWrite(dbe.ofsPrev,dbePrev,sizeof(struct DBEvent));
- dbc.ofsLastEvent=dbe.ofsPrev;
+ if (dbe.ofsNext == 0) {
+ dbePrev = (DBEvent*)DBRead(dbe.ofsPrev,sizeof(DBEvent),NULL);
+ dbePrev->ofsNext = 0;
+ DBWrite(dbe.ofsPrev,dbePrev,sizeof(DBEvent));
+ dbc.ofsLastEvent = dbe.ofsPrev;
}
else {
- dbePrev=(struct DBEvent*)DBRead(dbe.ofsPrev,sizeof(struct DBEvent),NULL);
- dbePrev->ofsNext=dbe.ofsNext;
- DBWrite(dbe.ofsPrev,dbePrev,sizeof(struct DBEvent));
- dbeNext=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeNext->ofsPrev=dbe.ofsPrev;
- DBWrite(dbe.ofsNext,dbeNext,sizeof(struct DBEvent));
+ dbePrev = (DBEvent*)DBRead(dbe.ofsPrev,sizeof(DBEvent),NULL);
+ dbePrev->ofsNext = dbe.ofsNext;
+ DBWrite(dbe.ofsPrev,dbePrev,sizeof(DBEvent));
+ dbeNext = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeNext->ofsPrev = dbe.ofsPrev;
+ DBWrite(dbe.ofsNext,dbeNext,sizeof(DBEvent));
}
}
//delete event
- DeleteSpace(lParam,offsetof(struct DBEvent,blob)+dbe.cbBlob);
+ DeleteSpace((DWORD)hDbEvent,offsetof(DBEvent,blob)+dbe.cbBlob);
//decrement event count
dbc.eventCount--;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
DBFlush(0);
//quit
LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR GetBlobSize(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::GetBlobSize(HANDLE hDbEvent)
{
INT_PTR ret;
- struct DBEvent *dbe;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=-1;
- else ret=dbe->cbBlob;
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!= DBEVENT_SIGNATURE) ret = -1;
+ else ret = dbe->cbBlob;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR GetEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
{
- struct DBEvent *dbe;
- DBEVENTINFO *dbei=(DBEVENTINFO*)lParam;
int bytesToCopy,i;
- if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 1;
- if(dbei->cbBlob > 0 && dbei->pBlob == NULL) {
+ if (dbei == NULL||dbei->cbSize!= sizeof(DBEVENTINFO)) return 1;
+ if (dbei->cbBlob > 0 && dbei->pBlob == NULL) {
dbei->cbBlob = 0;
return 1;
}
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) {
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!= DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- dbei->szModule=GetModuleNameByOfs(dbe->ofsModuleName);
- dbei->timestamp=dbe->timestamp;
- dbei->flags=dbe->flags;
- dbei->eventType=dbe->eventType;
- if(dbei->cbBlob<dbe->cbBlob) bytesToCopy=dbei->cbBlob;
- else bytesToCopy=dbe->cbBlob;
- dbei->cbBlob=dbe->cbBlob;
- for(i=0;;i+=MAXCACHEDREADSIZE) {
- if(bytesToCopy-i<=MAXCACHEDREADSIZE) {
- CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i);
+ dbei->szModule = GetModuleNameByOfs(dbe->ofsModuleName);
+ dbei->timestamp = dbe->timestamp;
+ dbei->flags = dbe->flags;
+ dbei->eventType = dbe->eventType;
+ if (dbei->cbBlob<dbe->cbBlob) bytesToCopy = dbei->cbBlob;
+ else bytesToCopy = dbe->cbBlob;
+ dbei->cbBlob = dbe->cbBlob;
+ for(i = 0;;i += MAXCACHEDREADSIZE) {
+ if (bytesToCopy-i <= MAXCACHEDREADSIZE) {
+ CopyMemory(dbei->pBlob+i,DBRead(DWORD(hDbEvent)+offsetof(DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i);
break;
}
- CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE);
+ CopyMemory(dbei->pBlob+i,DBRead(DWORD(hDbEvent)+offsetof(DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE);
}
LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR MarkEventRead(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
{
INT_PTR ret;
- struct DBEvent *dbe;
- struct DBContact dbc;
DWORD ofsThis;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=*(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- dbe=(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE || dbc.signature!=DBCONTACT_SIGNATURE) {
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ DBContact dbc = *(DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!= DBEVENT_SIGNATURE || dbc.signature!= DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- if(dbe->flags&DBEF_READ || dbe->flags&DBEF_SENT) {
- ret=(INT_PTR)dbe->flags;
+ if (dbe->flags & DBEF_READ || dbe->flags & DBEF_SENT) {
+ ret = (INT_PTR)dbe->flags;
LeaveCriticalSection(&csDbAccess);
return ret;
}
log1("mark read @ %08x",wParam);
- dbe->flags|=DBEF_READ;
- DBWrite(lParam,dbe,sizeof(struct DBEvent));
- ret=(INT_PTR)dbe->flags;
- if(dbc.ofsFirstUnreadEvent==(DWORD)lParam) {
+ dbe->flags |= DBEF_READ;
+ DBWrite((DWORD)hDbEvent, dbe, sizeof(DBEvent));
+ ret = (INT_PTR)dbe->flags;
+ if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
for (;;) {
- if(dbe->ofsNext==0) {
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
+ if (dbe->ofsNext == 0) {
+ dbc.ofsFirstUnreadEvent = 0;
+ dbc.timestampFirstUnread = 0;
break;
}
- ofsThis=dbe->ofsNext;
- dbe=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
+ ofsThis = dbe->ofsNext;
+ dbe = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
if (!(dbe->flags&(DBEF_READ|DBEF_SENT))) {
- dbc.ofsFirstUnreadEvent=ofsThis;
- dbc.timestampFirstUnread=dbe->timestamp;
+ dbc.ofsFirstUnreadEvent = ofsThis;
+ dbc.timestampFirstUnread = dbe->timestamp;
break;
}
}
}
- DBWrite(wParam,&dbc,sizeof(struct DBContact));
+ DBWrite((DWORD)hContact,&dbc,sizeof(DBContact));
DBFlush(0);
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR GetEventContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::GetEventContact(HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) {
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!= DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
- return -1;
+ return (HANDLE)-1;
}
- while(!(dbe->flags&DBEF_FIRST))
- dbe=(struct DBEvent*)DBRead(dbe->ofsPrev,sizeof(struct DBEvent),NULL);
- ret=(INT_PTR)dbe->ofsPrev;
+ while(!(dbe->flags & DBEF_FIRST))
+ dbe = (DBEvent*)DBRead(dbe->ofsPrev,sizeof(DBEvent),NULL);
+ ret = (HANDLE)dbe->ofsPrev;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindFirstEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsFirstEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature!= DBCONTACT_SIGNATURE)
+ ret = 0;
+ else
+ ret = (HANDLE)dbc->ofsFirstEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindFirstUnreadEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstUnreadEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsFirstUnreadEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature!= DBCONTACT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbc->ofsFirstUnreadEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindLastEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindLastEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsLastEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature!= DBCONTACT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbc->ofsLastEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindNextEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindNextEvent(HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbe->ofsNext;
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!= DBEVENT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbe->ofsNext;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindPrevEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindPrevEvent(HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=0;
- else if(dbe->flags&DBEF_FIRST) ret=0;
- else ret=(INT_PTR)dbe->ofsPrev;
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!= DBEVENT_SIGNATURE) ret = 0;
+ else if (dbe->flags&DBEF_FIRST) ret = 0;
+ else ret = (HANDLE)dbe->ofsPrev;
LeaveCriticalSection(&csDbAccess);
return ret;
}
int InitEvents(void)
{
- CreateServiceFunction(MS_DB_EVENT_GETCOUNT,GetEventCount);
- CreateServiceFunction(MS_DB_EVENT_ADD,AddEvent);
- CreateServiceFunction(MS_DB_EVENT_DELETE,DeleteEvent);
- CreateServiceFunction(MS_DB_EVENT_GETBLOBSIZE,GetBlobSize);
- CreateServiceFunction(MS_DB_EVENT_GET,GetEvent);
- CreateServiceFunction(MS_DB_EVENT_MARKREAD,MarkEventRead);
- CreateServiceFunction(MS_DB_EVENT_GETCONTACT,GetEventContact);
- CreateServiceFunction(MS_DB_EVENT_FINDFIRST,FindFirstEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDFIRSTUNREAD,FindFirstUnreadEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDLAST,FindLastEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDNEXT,FindNextEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDPREV,FindPrevEvent);
- hEventDeletedEvent=CreateHookableEvent(ME_DB_EVENT_DELETED);
- hEventAddedEvent=CreateHookableEvent(ME_DB_EVENT_ADDED);
- hEventFilterAddedEvent=CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
+ hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED);
+ hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED);
+ hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
return 0;
}
-
-void UninitEvents(void)
-{
- DestroyHookableEvent(hEventAddedEvent); hEventAddedEvent = 0;
- DestroyHookableEvent(hEventDeletedEvent); hEventDeletedEvent = 0;
- DestroyHookableEvent(hEventFilterAddedEvent); hEventFilterAddedEvent = 0;
-}
diff --git a/plugins/Db3x/src/dbheaders.cpp b/plugins/Db3x/src/dbheaders.cpp
index 8320102888..7092dc4630 100644
--- a/plugins/Db3x/src/dbheaders.cpp
+++ b/plugins/Db3x/src/dbheaders.cpp
@@ -27,44 +27,44 @@ struct DBSignature {
char name[15];
BYTE eof;
};
-static struct DBSignature dbSignature={"Miranda ICQ DB",0x1A};
+static struct DBSignature dbSignature = {"Miranda ICQ DB",0x1A};
//the cache has not been loaded when these functions are used
int CreateDbHeaders(HANDLE hFile)
{
- struct DBContact user;
+ DBContact user;
DWORD bytesWritten;
CopyMemory(dbHeader.signature,&dbSignature,sizeof(dbHeader.signature));
- dbHeader.version=DB_THIS_VERSION;
- dbHeader.ofsFileEnd=sizeof(struct DBHeader);
- dbHeader.slackSpace=0;
- dbHeader.contactCount=0;
- dbHeader.ofsFirstContact=0;
- dbHeader.ofsFirstModuleName=0;
- dbHeader.ofsUser=0;
+ dbHeader.version = DB_THIS_VERSION;
+ dbHeader.ofsFileEnd = sizeof(struct DBHeader);
+ dbHeader.slackSpace = 0;
+ dbHeader.contactCount = 0;
+ dbHeader.ofsFirstContact = 0;
+ dbHeader.ofsFirstModuleName = 0;
+ dbHeader.ofsUser = 0;
//create user
- dbHeader.ofsUser=dbHeader.ofsFileEnd;
- dbHeader.ofsFileEnd+=sizeof(struct DBContact);
+ dbHeader.ofsUser = dbHeader.ofsFileEnd;
+ dbHeader.ofsFileEnd += sizeof(DBContact);
SetFilePointer(hFile,0,NULL,FILE_BEGIN);
WriteFile(hFile,&dbHeader,sizeof(dbHeader),&bytesWritten,NULL);
- user.signature=DBCONTACT_SIGNATURE;
- user.ofsNext=0;
- user.ofsFirstSettings=0;
- user.eventCount=0;
- user.ofsFirstEvent=user.ofsLastEvent=0;
+ user.signature = DBCONTACT_SIGNATURE;
+ user.ofsNext = 0;
+ user.ofsFirstSettings = 0;
+ user.eventCount = 0;
+ user.ofsFirstEvent = user.ofsLastEvent = 0;
SetFilePointer(hFile,dbHeader.ofsUser,NULL,FILE_BEGIN);
- WriteFile(hFile,&user,sizeof(struct DBContact),&bytesWritten,NULL);
+ WriteFile(hFile,&user,sizeof(DBContact),&bytesWritten,NULL);
FlushFileBuffers(hFile);
return 0;
}
int CheckDbHeaders(struct DBHeader * hdr)
{
- if(memcmp(hdr->signature,&dbSignature,sizeof(hdr->signature))) return 1;
- if(hdr->version!=DB_THIS_VERSION) return 2;
- if(hdr->ofsUser==0) return 3;
+ if (memcmp(hdr->signature,&dbSignature,sizeof(hdr->signature))) return 1;
+ if (hdr->version!= DB_THIS_VERSION) return 2;
+ if (hdr->ofsUser == 0) return 3;
return 0;
}
diff --git a/plugins/Db3x_mmap/encryption.h b/plugins/Db3x/src/dbintf.cpp
index 73c2d7e13a..c30d8206cc 100644
--- a/plugins/Db3x_mmap/encryption.h
+++ b/plugins/Db3x/src/dbintf.cpp
@@ -1,6 +1,10 @@
/*
-Miranda ICQ: the free icq client for MS Windows
-Copyright (C) 2000-2 Richard Hughes, Roland Rabien & Tristan Van de Vreede
+
+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
@@ -16,8 +20,19 @@ 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.
*/
-#ifndef MODULAR
-#include <windows.h>
-void Encrypt(char*msg,BOOL up);
-#endif \ No newline at end of file
+#include "commonheaders.h"
+
+extern BOOL safetyMode;
+
+CDdxMmap::CDdxMmap(const TCHAR* tszFileName)
+{
+}
+
+STDMETHODIMP_(void) CDdxMmap::SetCacheSafetyMode(BOOL bIsSet)
+{
+ { mir_cslock lck(csDbAccess);
+ safetyMode = bIsSet;
+ }
+ DBFlush(1);
+}
diff --git a/plugins/Db3x/src/dbintf.h b/plugins/Db3x/src/dbintf.h
new file mode 100644
index 0000000000..6e9714640b
--- /dev/null
+++ b/plugins/Db3x/src/dbintf.h
@@ -0,0 +1,68 @@
+/*
+
+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>
+
+struct CDdxMmap : public MIDatabase
+{
+ CDdxMmap(const TCHAR* tszFileName);
+
+ 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 *dbei);
+ STDMETHODIMP_(BOOL) DeleteEvent(HANDLE hContact, HANDLE hDbEvent);
+ STDMETHODIMP_(LONG) GetBlobSize(HANDLE hDbEvent);
+ STDMETHODIMP_(BOOL) GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei);
+ 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);
+
+private:
+ int CheckProto(HANDLE hContact, const char *proto);
+
+ BOOL safetyMode;
+};
diff --git a/plugins/Db3x/src/dbmodulechain.cpp b/plugins/Db3x/src/dbmodulechain.cpp
index f130937af2..fb7c6e4ce3 100644
--- a/plugins/Db3x/src/dbmodulechain.cpp
+++ b/plugins/Db3x/src/dbmodulechain.cpp
@@ -39,40 +39,39 @@ int InitModuleNames(void)
DWORD ofsThis,ofsNext;
int nameLen;
- moduleNameCount=0;
- moduleName=NULL;
- ofsThis=dbHeader.ofsFirstModuleName;
- dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
+ moduleNameCount = 0;
+ moduleName = NULL;
+ ofsThis = dbHeader.ofsFirstModuleName;
+ dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
while(ofsThis) {
- if(dbmn->signature!=DBMODULENAME_SIGNATURE) DatabaseCorruption();
- moduleName=(struct ModuleName*)mir_realloc(moduleName,sizeof(struct ModuleName)*(moduleNameCount+1));
- moduleName[moduleNameCount].ofs=ofsThis;
- moduleName[moduleNameCount].hash=dbmn->cbName; //very very simple hash so far
- moduleName[moduleNameCount].name=(char*)mir_alloc(dbmn->cbName+1);
- ofsNext=dbmn->ofsNext;
- nameLen=dbmn->cbName;
+ if (dbmn->signature!= DBMODULENAME_SIGNATURE) DatabaseCorruption();
+ moduleName = (struct ModuleName*)mir_realloc(moduleName,sizeof(struct ModuleName)*(moduleNameCount+1));
+ moduleName[moduleNameCount].ofs = ofsThis;
+ moduleName[moduleNameCount].hash = dbmn->cbName; //very very simple hash so far
+ moduleName[moduleNameCount].name = (char*)mir_alloc(dbmn->cbName+1);
+ ofsNext = dbmn->ofsNext;
+ nameLen = dbmn->cbName;
CopyMemory(moduleName[moduleNameCount].name,DBRead(ofsThis+offsetof(struct DBModuleName,name),nameLen,NULL),nameLen);
- moduleName[moduleNameCount].name[nameLen]=0;
+ moduleName[moduleNameCount].name[nameLen] = 0;
moduleNameCount++;
- ofsThis=ofsNext;
- dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
+ ofsThis = ofsNext;
+ dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
}
- CreateServiceFunction(MS_DB_MODULES_ENUM,EnumModuleNames);
return 0;
}
void UninitModuleNames(void)
{
int i;
- for(i=0;i<moduleNameCount;i++) mir_free(moduleName[i].name);
- if(moduleNameCount) mir_free(moduleName);
+ for(i = 0;i<moduleNameCount;i++) mir_free(moduleName[i].name);
+ if (moduleNameCount) mir_free(moduleName);
}
static DWORD FindExistingModuleNameOfs(const char *szName,int nameLen)
{
int i;
- for(i=0;i<moduleNameCount;i++)
- if(moduleName[i].hash==(DWORD)nameLen && !strcmp(moduleName[i].name,szName)) return moduleName[i].ofs;
+ for(i = 0;i<moduleNameCount;i++)
+ if (moduleName[i].hash == (DWORD)nameLen && !strcmp(moduleName[i].name,szName)) return moduleName[i].ofs;
return 0;
}
@@ -80,26 +79,26 @@ static DWORD FindExistingModuleNameOfs(const char *szName,int nameLen)
DWORD GetModuleNameOfs(const char *szName)
{
struct DBModuleName dbmn;
- int nameLen=(int)strlen(szName);
+ int nameLen = (int)strlen(szName);
DWORD ofsNew,ofsExisting;
- ofsExisting=FindExistingModuleNameOfs(szName,nameLen);
- if(ofsExisting) return ofsExisting;
+ ofsExisting = FindExistingModuleNameOfs(szName,nameLen);
+ if (ofsExisting) return ofsExisting;
//need to create the module name
- ofsNew=CreateNewSpace(nameLen+offsetof(struct DBModuleName,name));
- dbmn.signature=DBMODULENAME_SIGNATURE;
- dbmn.cbName=nameLen;
- dbmn.ofsNext=dbHeader.ofsFirstModuleName;
- dbHeader.ofsFirstModuleName=ofsNew;
+ ofsNew = CreateNewSpace(nameLen+offsetof(struct DBModuleName,name));
+ dbmn.signature = DBMODULENAME_SIGNATURE;
+ dbmn.cbName = nameLen;
+ dbmn.ofsNext = dbHeader.ofsFirstModuleName;
+ dbHeader.ofsFirstModuleName = ofsNew;
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBWrite(ofsNew,&dbmn,offsetof(struct DBModuleName,name));
DBWrite(ofsNew+offsetof(struct DBModuleName,name),(PVOID)szName,nameLen);
DBFlush(0);
//add to cache
- moduleName=(struct ModuleName*)mir_realloc(moduleName,sizeof(struct ModuleName)*(moduleNameCount+1));
- moduleName[moduleNameCount].ofs=ofsNew;
- moduleName[moduleNameCount].hash=nameLen; //very very simple hash so far
- moduleName[moduleNameCount].name=(char*)mir_alloc(nameLen+1);
+ moduleName = (struct ModuleName*)mir_realloc(moduleName,sizeof(struct ModuleName)*(moduleNameCount+1));
+ moduleName[moduleNameCount].ofs = ofsNew;
+ moduleName[moduleNameCount].hash = nameLen; //very very simple hash so far
+ moduleName[moduleNameCount].name = (char*)mir_alloc(nameLen+1);
strcpy(moduleName[moduleNameCount].name,szName);
moduleNameCount++;
//quit
@@ -111,18 +110,18 @@ char *GetModuleNameByOfs(DWORD ofs)
{
int i;
- for(i=0;i<moduleNameCount;i++)
- if(moduleName[i].ofs==ofs) return moduleName[i].name;
+ for(i = 0;i<moduleNameCount;i++)
+ if (moduleName[i].ofs == ofs) return moduleName[i].name;
DatabaseCorruption();
return NULL;
}
-static INT_PTR EnumModuleNames(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
{
int i;
INT_PTR ret;
- for(i=0;i<moduleNameCount;i++) {
- ret=((DBMODULEENUMPROC)lParam)(moduleName[i].name,moduleName[i].ofs,wParam);
+ for(i = 0;i<moduleNameCount;i++) {
+ ret = pFunc(moduleName[i].name,moduleName[i].ofs, (LPARAM)pParam);
if (ret) return ret;
}
return 0;
diff --git a/plugins/Db3x/src/dbsettings.cpp b/plugins/Db3x/src/dbsettings.cpp
index 209b7a13ab..db21b64db8 100644
--- a/plugins/Db3x/src/dbsettings.cpp
+++ b/plugins/Db3x/src/dbsettings.cpp
@@ -42,47 +42,45 @@ static int nextSGOCacheEntry;
static int mirCp = CP_ACP;
//this function caches results
-static DWORD GetSettingsGroupOfsByModuleNameOfs(struct DBContact *dbc,DWORD ofsContact,DWORD ofsModuleName)
+static DWORD GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsContact,DWORD ofsModuleName)
{
struct DBContactSettings *dbcs;
DWORD ofsThis;
int i;
- for(i=0;i<SETTINGSGROUPOFSCOUNT;i++) {
- if(settingsGroupOfsCache[i].ofsContact==ofsContact && settingsGroupOfsCache[i].ofsModuleName==ofsModuleName)
+ for(i = 0;i<SETTINGSGROUPOFSCOUNT;i++) {
+ if (settingsGroupOfsCache[i].ofsContact == ofsContact && settingsGroupOfsCache[i].ofsModuleName == ofsModuleName)
return settingsGroupOfsCache[i].ofsSettingsGroup;
}
- ofsThis=dbc->ofsFirstSettings;
+ ofsThis = dbc->ofsFirstSettings;
while(ofsThis) {
- dbcs=(struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
- if(dbcs->signature!=DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption();
- if(dbcs->ofsModuleName==ofsModuleName) {
- settingsGroupOfsCache[nextSGOCacheEntry].ofsContact=ofsContact;
- settingsGroupOfsCache[nextSGOCacheEntry].ofsModuleName=ofsModuleName;
- settingsGroupOfsCache[nextSGOCacheEntry].ofsSettingsGroup=ofsThis;
- if (++nextSGOCacheEntry==SETTINGSGROUPOFSCOUNT) nextSGOCacheEntry=0;
+ dbcs = (struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
+ if (dbcs->signature!= DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption();
+ if (dbcs->ofsModuleName == ofsModuleName) {
+ settingsGroupOfsCache[nextSGOCacheEntry].ofsContact = ofsContact;
+ settingsGroupOfsCache[nextSGOCacheEntry].ofsModuleName = ofsModuleName;
+ settingsGroupOfsCache[nextSGOCacheEntry].ofsSettingsGroup = ofsThis;
+ if (++nextSGOCacheEntry == SETTINGSGROUPOFSCOUNT) nextSGOCacheEntry = 0;
return ofsThis;
}
- ofsThis=dbcs->ofsNext;
+ ofsThis = dbcs->ofsNext;
}
return 0;
}
static void InvalidateSettingsGroupOfsCacheEntry(DWORD ofsSettingsGroup)
{
- int i;
-
- for(i=0;i<SETTINGSGROUPOFSCOUNT;i++) {
- if(settingsGroupOfsCache[i].ofsSettingsGroup==ofsSettingsGroup) {
- settingsGroupOfsCache[i].ofsContact=0;
- settingsGroupOfsCache[i].ofsModuleName=0;
- settingsGroupOfsCache[i].ofsSettingsGroup=0;
+ for(int i = 0;i<SETTINGSGROUPOFSCOUNT;i++) {
+ if (settingsGroupOfsCache[i].ofsSettingsGroup == ofsSettingsGroup) {
+ settingsGroupOfsCache[i].ofsContact = 0;
+ settingsGroupOfsCache[i].ofsModuleName = 0;
+ settingsGroupOfsCache[i].ofsSettingsGroup = 0;
break;
} } }
static DWORD __inline GetSettingValueLength(PBYTE pSetting)
{
- if(pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1);
+ if (pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1);
return pSetting[0];
}
@@ -102,7 +100,7 @@ static char* GetCachedSetting(const char *szModuleName,const char *szSettingName
char *szFullName = (char*)alloca(moduleNameLen+settingNameLen+3);
strcpy(szFullName+1,szModuleName);
- szFullName[moduleNameLen+1]='/';
+ szFullName[moduleNameLen+1] = '/';
strcpy(szFullName+moduleNameLen+2,szSettingName);
if (lastsetting && strcmp(szFullName+1,lastsetting) == 0)
@@ -173,7 +171,7 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
DBCachedContactValue *V, *V1;
DBCachedContactValueList VLtemp,*VL;
- VLtemp.hContact=hContact;
+ VLtemp.hContact = hContact;
if ( List_GetIndex(&lContacts,&VLtemp,&index)) {
VL = (DBCachedContactValueList*)lContacts.items[index];
}
@@ -187,7 +185,7 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
}
for ( V = VL->first; V != NULL; V = V->next)
- if (strcmp(V->name,szSetting)==0)
+ if (strcmp(V->name,szSetting) == 0)
break;
if ( V == NULL ) {
@@ -203,7 +201,7 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
FreeCachedVariant(&V->value);
if ( VL->first == V )
VL->first = V->next;
- for ( V1=VL->first; V1 != NULL; V1 = V1->next )
+ for ( V1 = VL->first; V1 != NULL; V1 = V1->next )
if ( V1->next == V ) {
V1->next = V->next;
break;
@@ -215,12 +213,12 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
return &V->value;
} }
-#define NeedBytes(n) if(bytesRemaining<(n)) pBlob=(PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining)
-#define MoveAlong(n) {int x=n; pBlob+=(x); ofsBlobPtr+=(x); bytesRemaining-=(x);}
-#define VLT(n) ((n==DBVT_UTF8)?DBVT_ASCIIZ:n)
+#define NeedBytes(n) if (bytesRemaining<(n)) pBlob = (PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining)
+#define MoveAlong(n) {int x = n; pBlob += (x); ofsBlobPtr += (x); bytesRemaining -= (x);}
+#define VLT(n) ((n == DBVT_UTF8)?DBVT_ASCIIZ:n)
static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic)
{
- struct DBContact dbc;
+ DBContact dbc;
struct DBContactSettings dbcs;
DWORD ofsModuleName,ofsContact,ofsSettingsGroup,ofsBlobPtr;
int settingNameLen;
@@ -230,7 +228,7 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
if ((!dbcgs->szSetting) || (!dbcgs->szModule))
return 1;
- settingNameLen=(int)strlen(dbcgs->szSetting);
+ settingNameLen = (int)strlen(dbcgs->szSetting);
EnterCriticalSection(&csDbAccess);
@@ -251,10 +249,10 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
cbOrigLen--;
dbcgs->pValue->pszVal = cbOrigPtr;
- if(cbLen<cbOrigLen) cbOrigLen=cbLen;
+ if (cbLen<cbOrigLen) cbOrigLen = cbLen;
CopyMemory(dbcgs->pValue->pszVal,pCachedValue->pszVal,cbOrigLen);
- dbcgs->pValue->pszVal[cbOrigLen]=0;
- dbcgs->pValue->cchVal=cbLen;
+ dbcgs->pValue->pszVal[cbOrigLen] = 0;
+ dbcgs->pValue->cchVal = cbLen;
}
else {
dbcgs->pValue->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal)+1);
@@ -277,65 +275,65 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
return ( pCachedValue->type == DBVT_DELETED ) ? 1 : 0;
} }
- ofsModuleName=GetModuleNameOfs(dbcgs->szModule);
- if(hContact==NULL) ofsContact=dbHeader.ofsUser;
- else ofsContact=(DWORD)hContact;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE) {
+ ofsModuleName = GetModuleNameOfs(dbcgs->szModule);
+ if (hContact == NULL) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc.signature!= DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
- if(ofsSettingsGroup) {
- dbcs=*(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
+ if (ofsSettingsGroup) {
+ dbcs = *(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(1+settingNameLen);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) {
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) {
MoveAlong(1+settingNameLen);
NeedBytes(5);
- if(isStatic && pBlob[0]&DBVTF_VARIABLELENGTH && VLT(dbcgs->pValue->type) != VLT(pBlob[0])) {
+ if (isStatic && pBlob[0]&DBVTF_VARIABLELENGTH && VLT(dbcgs->pValue->type) != VLT(pBlob[0])) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- dbcgs->pValue->type=pBlob[0];
+ dbcgs->pValue->type = pBlob[0];
switch(pBlob[0]) {
case DBVT_DELETED: { /* this setting is deleted */
- dbcgs->pValue->type=DBVT_DELETED;
+ dbcgs->pValue->type = DBVT_DELETED;
LeaveCriticalSection(&csDbAccess);
return 2;
}
- case DBVT_BYTE: dbcgs->pValue->bVal=pBlob[1]; break;
- case DBVT_WORD: dbcgs->pValue->wVal=*(PWORD)(pBlob+1); break;
- case DBVT_DWORD: dbcgs->pValue->dVal=*(PDWORD)(pBlob+1); break;
+ case DBVT_BYTE: dbcgs->pValue->bVal = pBlob[1]; break;
+ case DBVT_WORD: dbcgs->pValue->wVal = *(PWORD)(pBlob+1); break;
+ case DBVT_DWORD: dbcgs->pValue->dVal = *(PDWORD)(pBlob+1); break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
NeedBytes(3+*(PWORD)(pBlob+1));
- if(isStatic) {
+ if (isStatic) {
dbcgs->pValue->cchVal--;
- if (*(PWORD)(pBlob+1)<dbcgs->pValue->cchVal) dbcgs->pValue->cchVal=*(PWORD)(pBlob+1);
+ if (*(PWORD)(pBlob+1)<dbcgs->pValue->cchVal) dbcgs->pValue->cchVal = *(PWORD)(pBlob+1);
CopyMemory(dbcgs->pValue->pszVal,pBlob+3,dbcgs->pValue->cchVal);
- dbcgs->pValue->pszVal[dbcgs->pValue->cchVal]=0;
- dbcgs->pValue->cchVal=*(PWORD)(pBlob+1);
+ dbcgs->pValue->pszVal[dbcgs->pValue->cchVal] = 0;
+ dbcgs->pValue->cchVal = *(PWORD)(pBlob+1);
}
else {
- dbcgs->pValue->pszVal=(char*)mir_alloc(1+*(PWORD)(pBlob+1));
+ dbcgs->pValue->pszVal = (char*)mir_alloc(1+*(PWORD)(pBlob+1));
CopyMemory(dbcgs->pValue->pszVal,pBlob+3,*(PWORD)(pBlob+1));
- dbcgs->pValue->pszVal[*(PWORD)(pBlob+1)]=0;
+ dbcgs->pValue->pszVal[*(PWORD)(pBlob+1)] = 0;
}
break;
case DBVT_BLOB:
NeedBytes(3+*(PWORD)(pBlob+1));
- if(isStatic) {
- if (*(PWORD)(pBlob+1)<dbcgs->pValue->cpbVal) dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1);
+ if (isStatic) {
+ if (*(PWORD)(pBlob+1)<dbcgs->pValue->cpbVal) dbcgs->pValue->cpbVal = *(PWORD)(pBlob+1);
CopyMemory(dbcgs->pValue->pbVal,pBlob+3,dbcgs->pValue->cpbVal);
}
else {
dbcgs->pValue->pbVal = (BYTE *)mir_alloc(*(PWORD)(pBlob + 1));
CopyMemory(dbcgs->pValue->pbVal,pBlob+3,*(PWORD)(pBlob+1));
}
- dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1);
+ dbcgs->pValue->cpbVal = *(PWORD)(pBlob+1);
break;
}
@@ -371,11 +369,10 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
return 1;
}
-static INT_PTR GetContactSetting(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = ( DBCONTACTGETSETTING* )lParam;
dgs->pValue->type = 0;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 0 ))
+ if ( GetContactSettingWorker(hContact, dgs, 0))
return 1;
if ( dgs->pValue->type == DBVT_UTF8 ) {
@@ -406,12 +403,11 @@ static INT_PTR GetContactSetting(WPARAM wParam,LPARAM lParam)
return 0;
}
-static INT_PTR GetContactSettingStr(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStr(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = (DBCONTACTGETSETTING*)lParam;
int iSaveType = dgs->pValue->type;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 0 ))
+ if ( GetContactSettingWorker(hContact, dgs, 0))
return 1;
if ( iSaveType == 0 || iSaveType == dgs->pValue->type )
@@ -454,10 +450,9 @@ static INT_PTR GetContactSettingStr(WPARAM wParam,LPARAM lParam)
return 0;
}
-INT_PTR GetContactSettingStatic(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStatic(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = (DBCONTACTGETSETTING*)lParam;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 1 ))
+ if ( GetContactSettingWorker(hContact, dgs, 1))
return 1;
if ( dgs->pValue->type == DBVT_UTF8 ) {
@@ -468,9 +463,8 @@ INT_PTR GetContactSettingStatic(WPARAM wParam,LPARAM lParam)
return 0;
}
-static INT_PTR FreeVariant(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::FreeVariant(DBVARIANT *dbv)
{
- DBVARIANT *dbv=(DBVARIANT*)lParam;
if ( dbv == 0 ) return 1;
switch ( dbv->type ) {
case DBVT_ASCIIZ:
@@ -478,27 +472,27 @@ static INT_PTR FreeVariant(WPARAM wParam,LPARAM lParam)
case DBVT_WCHAR:
{
if ( dbv->pszVal ) mir_free(dbv->pszVal);
- dbv->pszVal=0;
+ dbv->pszVal = 0;
break;
}
case DBVT_BLOB:
{
if ( dbv->pbVal ) mir_free(dbv->pbVal);
- dbv->pbVal=0;
+ dbv->pbVal = 0;
break;
}
}
- dbv->type=0;
+ dbv->type = 0;
return 0;
}
-static INT_PTR SetSettingResident(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::SetSettingResident(BOOL bIsResident, const char *pszSettingName)
{
char* szSetting;
- size_t cbSettingNameLen = strlen(( char* )lParam );
+ size_t cbSettingNameLen = strlen(pszSettingName);
int idx;
- char* szTemp = ( char* )alloca( cbSettingNameLen+2 );
- strcpy( szTemp+1, ( char* )lParam );
+ char* szTemp = (char*)alloca( cbSettingNameLen+2 );
+ strcpy( szTemp+1, pszSettingName);
EnterCriticalSection(&csDbAccess);
if ( !List_GetIndex( &lSettings, szTemp, &idx ))
@@ -506,27 +500,26 @@ static INT_PTR SetSettingResident(WPARAM wParam,LPARAM lParam)
else
szSetting = (char *)lSettings.items[idx];
- *szSetting = (char)wParam;
+ *szSetting = (char)bIsResident;
LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
{
- DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam;
DBCONTACTWRITESETTING tmp;
- struct DBContact dbc;
+ DBContact dbc;
DWORD ofsModuleName;
struct DBContactSettings dbcs;
PBYTE pBlob;
- int settingNameLen=0;
- int moduleNameLen=0;
- int settingDataLen=0;
+ int settingNameLen = 0;
+ int moduleNameLen = 0;
+ int settingDataLen = 0;
int bytesRequired,bytesRemaining;
DWORD ofsContact,ofsSettingsGroup,ofsBlobPtr;
- if (dbcws == NULL || dbcws->szSetting==NULL || dbcws->szModule==NULL )
+ if (dbcws == NULL || dbcws->szSetting == NULL || dbcws->szModule == NULL )
return 1;
tmp = *dbcws;
@@ -544,13 +537,13 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
else return 1;
}
- if(tmp.value.type!=DBVT_BYTE && tmp.value.type!=DBVT_WORD && tmp.value.type!=DBVT_DWORD && tmp.value.type!=DBVT_ASCIIZ && tmp.value.type!=DBVT_UTF8 && tmp.value.type!=DBVT_BLOB)
+ if (tmp.value.type!= DBVT_BYTE && tmp.value.type!= DBVT_WORD && tmp.value.type!= DBVT_DWORD && tmp.value.type!= DBVT_ASCIIZ && tmp.value.type!= DBVT_UTF8 && tmp.value.type!= DBVT_BLOB)
return 1;
if ((!tmp.szModule) || (!tmp.szSetting) || ((tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8 )&& tmp.value.pszVal == NULL) || (tmp.value.type == DBVT_BLOB && tmp.value.pbVal == NULL))
return 1;
// the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
- settingNameLen=(int)strlen(tmp.szSetting);
- moduleNameLen=(int)strlen(tmp.szModule);
+ settingNameLen = (int)strlen(tmp.szSetting);
+ moduleNameLen = (int)strlen(tmp.szModule);
if ( settingNameLen > 0xFE )
{
#ifdef _DEBUG
@@ -570,9 +563,9 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
switch( tmp.value.type ) {
case DBVT_ASCIIZ: case DBVT_BLOB: case DBVT_UTF8:
{ int len = ( tmp.value.type != DBVT_BLOB ) ? (int)strlen(tmp.value.pszVal) : tmp.value.cpbVal;
- if ( len >= 0xFFFF ) {
+ if ( len >= 0xFFFF ) {
#ifdef _DEBUG
- OutputDebugString(_T("WriteContactSetting() writing huge string/blob, rejecting ( >= 0xFFFF ) \n"));
+ OutputDebugString(_T("WriteContactSetting() writing huge string/blob, rejecting ( >= 0xFFFF ) \n"));
#endif
return 1;
}
@@ -583,7 +576,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
{
char* szCachedSettingName = GetCachedSetting(tmp.szModule, tmp.szSetting, settingNameLen);
if ( tmp.value.type != DBVT_BLOB ) {
- DBVARIANT* pCachedValue = GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, 1);
+ DBVARIANT* pCachedValue = GetCachedValuePtr(hContact, szCachedSettingName, 1);
if ( pCachedValue != NULL ) {
BOOL bIsIdentical = FALSE;
if ( pCachedValue->type == tmp.value.type ) {
@@ -603,53 +596,55 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
}
if ( szCachedSettingName[-1] != 0 ) {
LeaveCriticalSection(&csDbAccess);
- NotifyEventHooks(hSettingChangeEvent,wParam,(LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
return 0;
}
}
- else GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, -1);
+ else GetCachedValuePtr(hContact, szCachedSettingName, -1);
}
- ofsModuleName=GetModuleNameOfs(tmp.szModule);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
+ ofsModuleName = GetModuleNameOfs(tmp.szModule);
+ if (hContact == 0)
+ ofsContact = dbHeader.ofsUser;
+ else
+ ofsContact = (DWORD)hContact;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE) {
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc.signature!= DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
log0("write setting");
//make sure the module group exists
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
- if(ofsSettingsGroup==0) { //module group didn't exist - make it
- if(tmp.value.type&DBVTF_VARIABLELENGTH) {
- if(tmp.value.type==DBVT_ASCIIZ || tmp.value.type==DBVT_UTF8) bytesRequired=(int)strlen(tmp.value.pszVal)+2;
- else if(tmp.value.type==DBVT_BLOB) bytesRequired=tmp.value.cpbVal+2;
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
+ if (ofsSettingsGroup == 0) { //module group didn't exist - make it
+ if (tmp.value.type&DBVTF_VARIABLELENGTH) {
+ if (tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2;
+ else if (tmp.value.type == DBVT_BLOB) bytesRequired = tmp.value.cpbVal+2;
}
- else bytesRequired=tmp.value.type;
- bytesRequired+=2+settingNameLen;
- bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
- ofsSettingsGroup=CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
- dbcs.signature=DBCONTACTSETTINGS_SIGNATURE;
- dbcs.ofsNext=dbc.ofsFirstSettings;
- dbcs.ofsModuleName=ofsModuleName;
- dbcs.cbBlob=bytesRequired;
- dbcs.blob[0]=0;
- dbc.ofsFirstSettings=ofsSettingsGroup;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ else bytesRequired = tmp.value.type;
+ bytesRequired += 2+settingNameLen;
+ bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
+ ofsSettingsGroup = CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
+ dbcs.signature = DBCONTACTSETTINGS_SIGNATURE;
+ dbcs.ofsNext = dbc.ofsFirstSettings;
+ dbcs.ofsModuleName = ofsModuleName;
+ dbcs.cbBlob = bytesRequired;
+ dbcs.blob[0] = 0;
+ dbc.ofsFirstSettings = ofsSettingsGroup;
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
DBWrite(ofsSettingsGroup,&dbcs,sizeof(struct DBContactSettings));
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
else {
- dbcs=*(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
+ dbcs = *(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
//find if the setting exists
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(settingNameLen+1);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,tmp.szSetting,settingNameLen))
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,tmp.szSetting,settingNameLen))
break;
NeedBytes(1);
MoveAlong(pBlob[0]+1);
@@ -657,18 +652,18 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
MoveAlong(1+GetSettingValueLength(pBlob));
NeedBytes(1);
}
- if(pBlob[0]) { //setting already existed, and up to end of name is in cache
+ if (pBlob[0]) { //setting already existed, and up to end of name is in cache
MoveAlong(1+settingNameLen);
//if different type or variable length and length is different
NeedBytes(3);
- if(pBlob[0]!=tmp.value.type || ((pBlob[0]==DBVT_ASCIIZ || pBlob[0]==DBVT_UTF8) && *(PWORD)(pBlob+1)!=strlen(tmp.value.pszVal)) || (pBlob[0]==DBVT_BLOB && *(PWORD)(pBlob+1)!=tmp.value.cpbVal)) {
+ if (pBlob[0]!= tmp.value.type || ((pBlob[0] == DBVT_ASCIIZ || pBlob[0] == DBVT_UTF8) && *(PWORD)(pBlob+1)!= strlen(tmp.value.pszVal)) || (pBlob[0] == DBVT_BLOB && *(PWORD)(pBlob+1)!= tmp.value.cpbVal)) {
//bin it
int nameLen,valLen;
DWORD ofsSettingToCut;
NeedBytes(3);
- nameLen=1+settingNameLen;
- valLen=1+GetSettingValueLength(pBlob);
- ofsSettingToCut=ofsBlobPtr-nameLen;
+ nameLen = 1+settingNameLen;
+ valLen = 1+GetSettingValueLength(pBlob);
+ ofsSettingToCut = ofsBlobPtr-nameLen;
MoveAlong(valLen);
NeedBytes(1);
while(pBlob[0]) {
@@ -678,8 +673,8 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
NeedBytes(1);
}
DBMoveChunk(ofsSettingToCut,ofsSettingToCut+nameLen+valLen,ofsBlobPtr+1-ofsSettingToCut);
- ofsBlobPtr-=nameLen+valLen;
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr -= nameLen+valLen;
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
else {
//replace existing setting at pBlob
@@ -696,7 +691,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
//notify
- NotifyEventHooks(hSettingChangeEvent,wParam,(LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
return 0;
}
}
@@ -704,51 +699,51 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
//cannot do a simple replace, add setting to end of list
//pBlob already points to end of list
//see if it fits
- if(tmp.value.type&DBVTF_VARIABLELENGTH) {
- if(tmp.value.type==DBVT_ASCIIZ || tmp.value.type==DBVT_UTF8) bytesRequired=(int)strlen(tmp.value.pszVal)+2;
- else if(tmp.value.type==DBVT_BLOB) bytesRequired=tmp.value.cpbVal+2;
+ if (tmp.value.type&DBVTF_VARIABLELENGTH) {
+ if (tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2;
+ else if (tmp.value.type == DBVT_BLOB) bytesRequired = tmp.value.cpbVal+2;
}
- else bytesRequired=tmp.value.type;
- bytesRequired+=2+settingNameLen;
- bytesRequired+=ofsBlobPtr+1-(ofsSettingsGroup+offsetof(struct DBContactSettings,blob));
+ else bytesRequired = tmp.value.type;
+ bytesRequired += 2+settingNameLen;
+ bytesRequired += ofsBlobPtr+1-(ofsSettingsGroup+offsetof(struct DBContactSettings,blob));
if ((DWORD)bytesRequired>dbcs.cbBlob) {
//doesn't fit: move entire group
struct DBContactSettings *dbcsPrev;
DWORD ofsDbcsPrev,oldSize,ofsNew;
InvalidateSettingsGroupOfsCacheEntry(ofsSettingsGroup);
- bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
+ bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
//find previous group to change its offset
- ofsDbcsPrev=dbc.ofsFirstSettings;
- if(ofsDbcsPrev==ofsSettingsGroup) ofsDbcsPrev=0;
+ ofsDbcsPrev = dbc.ofsFirstSettings;
+ if (ofsDbcsPrev == ofsSettingsGroup) ofsDbcsPrev = 0;
else {
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
- while(dbcsPrev->ofsNext!=ofsSettingsGroup) {
- if(dbcsPrev->ofsNext==0) DatabaseCorruption();
- ofsDbcsPrev=dbcsPrev->ofsNext;
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ while(dbcsPrev->ofsNext!= ofsSettingsGroup) {
+ if (dbcsPrev->ofsNext == 0) DatabaseCorruption();
+ ofsDbcsPrev = dbcsPrev->ofsNext;
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
}
}
//create the new one
- ofsNew=CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
+ ofsNew = CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
//copy across
DBMoveChunk(ofsNew,ofsSettingsGroup,bytesRequired+offsetof(struct DBContactSettings,blob));
- oldSize=dbcs.cbBlob;
- dbcs.cbBlob=bytesRequired;
+ oldSize = dbcs.cbBlob;
+ dbcs.cbBlob = bytesRequired;
DBWrite(ofsNew,&dbcs,offsetof(struct DBContactSettings,blob));
- if(ofsDbcsPrev==0) {
- dbc.ofsFirstSettings=ofsNew;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ if (ofsDbcsPrev == 0) {
+ dbc.ofsFirstSettings = ofsNew;
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
}
else {
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
- dbcsPrev->ofsNext=ofsNew;
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ dbcsPrev->ofsNext = ofsNew;
DBWrite(ofsDbcsPrev,dbcsPrev,offsetof(struct DBContactSettings,blob));
}
DeleteSpace(ofsSettingsGroup,oldSize+offsetof(struct DBContactSettings,blob));
- ofsBlobPtr+=ofsNew-ofsSettingsGroup;
- ofsSettingsGroup=ofsNew;
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr += ofsNew-ofsSettingsGroup;
+ ofsSettingsGroup = ofsNew;
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
//we now have a place to put it and enough space: make it
DBWrite(ofsBlobPtr,&settingNameLen,1);
@@ -762,7 +757,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
case DBVT_DWORD: DBWrite(ofsBlobPtr,&tmp.value.dVal,4); MoveAlong(4); break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
- { int len=(int)strlen(tmp.value.pszVal);
+ { int len = (int)strlen(tmp.value.pszVal);
DBWrite(ofsBlobPtr,&len,2);
DBWrite(ofsBlobPtr+2,tmp.value.pszVal,len);
MoveAlong(2+len);
@@ -774,63 +769,63 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
MoveAlong(2+tmp.value.cpbVal);
break;
}
- { BYTE zero=0;
+ { BYTE zero = 0;
DBWrite(ofsBlobPtr,&zero,1);
}
//quit
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
//notify
- NotifyEventHooks(hSettingChangeEvent, wParam, (LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
return 0;
}
-static INT_PTR DeleteContactSetting(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::DeleteContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
{
- DBCONTACTGETSETTING *dbcgs=(DBCONTACTGETSETTING*)lParam;
- struct DBContact *dbc;
+ DBContact *dbc;
DWORD ofsModuleName,ofsSettingsGroup,ofsBlobPtr;
struct DBContactSettings dbcs;
PBYTE pBlob;
- int settingNameLen=(int)strlen(dbcgs->szSetting),bytesRemaining;
+ int settingNameLen = (int)strlen(dbcgs->szSetting),bytesRemaining;
char* szCachedSettingName;
- WPARAM saveWparam = wParam;
+ HANDLE saveContact = hContact;
if ((!dbcgs->szModule) || (!dbcgs->szSetting))
return 1;
EnterCriticalSection(&csDbAccess);
- ofsModuleName=GetModuleNameOfs(dbcgs->szModule);
- if(wParam==0) wParam=dbHeader.ofsUser;
+ ofsModuleName = GetModuleNameOfs(dbcgs->szModule);
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature!= DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
//make sure the module group exists
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,wParam,ofsModuleName);
- if(ofsSettingsGroup==0) {
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc, (DWORD)hContact,ofsModuleName);
+ if (ofsSettingsGroup == 0) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature!= DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,wParam,ofsModuleName);
- if(ofsSettingsGroup==0) {
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc,(DWORD)hContact,ofsModuleName);
+ if (ofsSettingsGroup == 0) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- dbcs=*(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),NULL);
+ dbcs = *(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),NULL);
//find if the setting exists
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(settingNameLen+1);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen))
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen))
break;
NeedBytes(1);
MoveAlong(pBlob[0]+1);
@@ -847,9 +842,9 @@ static INT_PTR DeleteContactSetting(WPARAM wParam,LPARAM lParam)
DWORD ofsSettingToCut;
MoveAlong(1+settingNameLen);
NeedBytes(3);
- nameLen=1+settingNameLen;
- valLen=1+GetSettingValueLength(pBlob);
- ofsSettingToCut=ofsBlobPtr-nameLen;
+ nameLen = 1+settingNameLen;
+ valLen = 1+GetSettingValueLength(pBlob);
+ ofsSettingToCut = ofsBlobPtr-nameLen;
MoveAlong(valLen);
NeedBytes(1);
while(pBlob[0]) {
@@ -862,25 +857,24 @@ static INT_PTR DeleteContactSetting(WPARAM wParam,LPARAM lParam)
}
szCachedSettingName = GetCachedSetting(dbcgs->szModule,dbcgs->szSetting,settingNameLen);
- GetCachedValuePtr((HANDLE)saveWparam, szCachedSettingName, -1 );
+ GetCachedValuePtr(saveContact, szCachedSettingName, -1 );
//quit
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
{ //notify
DBCONTACTWRITESETTING dbcws;
- dbcws.szModule=dbcgs->szModule;
- dbcws.szSetting=dbcgs->szSetting;
- dbcws.value.type=DBVT_DELETED;
- NotifyEventHooks(hSettingChangeEvent,saveWparam,(LPARAM)&dbcws);
+ dbcws.szModule = dbcgs->szModule;
+ dbcws.szSetting = dbcgs->szSetting;
+ dbcws.value.type = DBVT_DELETED;
+ NotifyEventHooks(hSettingChangeEvent,(WPARAM)saveContact,(LPARAM)&dbcws);
}
return 0;
}
-static INT_PTR EnumContactSettings(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces)
{
- DBCONTACTENUMSETTINGS *dbces=(DBCONTACTENUMSETTINGS*)lParam;
- struct DBContact dbc;
+ DBContact dbc;
struct DBContactSettings dbcs;
DWORD ofsModuleName,ofsContact,ofsBlobPtr;
int bytesRemaining, result;
@@ -892,23 +886,25 @@ static INT_PTR EnumContactSettings(WPARAM wParam,LPARAM lParam)
EnterCriticalSection(&csDbAccess);
- ofsModuleName=GetModuleNameOfs(dbces->szModule);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE) {
+ ofsModuleName = GetModuleNameOfs(dbces->szModule);
+ if (hContact == 0)
+ ofsContact = dbHeader.ofsUser;
+ else
+ ofsContact = (DWORD)hContact;
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc.signature!= DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- dbces->ofsSettings=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
+ dbces->ofsSettings = GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
if (!dbces->ofsSettings) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- dbcs=*(struct DBContactSettings*)DBRead(dbces->ofsSettings,sizeof(struct DBContactSettings),&bytesRemaining);
- ofsBlobPtr=dbces->ofsSettings+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
- if(pBlob[0]==0) {
+ dbcs = *(struct DBContactSettings*)DBRead(dbces->ofsSettings,sizeof(struct DBContactSettings),&bytesRemaining);
+ ofsBlobPtr = dbces->ofsSettings+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ if (pBlob[0] == 0) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
@@ -916,7 +912,7 @@ static INT_PTR EnumContactSettings(WPARAM wParam,LPARAM lParam)
while(pBlob[0]) {
NeedBytes(1);
NeedBytes(1+pBlob[0]);
- CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]]=0;
+ CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]] = 0;
result = (dbces->pfnEnumProc)(szSetting,dbces->lParam);
MoveAlong(1+pBlob[0]);
NeedBytes(3);
@@ -927,6 +923,15 @@ static INT_PTR EnumContactSettings(WPARAM wParam,LPARAM lParam)
return result;
}
+STDMETHODIMP_(BOOL) CDdxMmap::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
+{
+ for(int i = 0; i < lSettings.realCount; i++) {
+ int ret = pFunc((char *)lSettings.items[i], 0, (LPARAM)pParam);
+ if (ret) return ret;
+ }
+ return 0;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
//
// Module initialization procedure
@@ -943,15 +948,6 @@ static int stringCompare2( DBCachedGlobalValue* p1, DBCachedGlobalValue* p2 )
int InitSettings(void)
{
- CreateServiceFunction(MS_DB_CONTACT_GETSETTING,GetContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_GETSETTING_STR,GetContactSettingStr);
- CreateServiceFunction(MS_DB_CONTACT_GETSETTINGSTATIC,GetContactSettingStatic);
- CreateServiceFunction(MS_DB_CONTACT_FREEVARIANT,FreeVariant);
- CreateServiceFunction(MS_DB_CONTACT_WRITESETTING,WriteContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_DELETESETTING,DeleteContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_ENUMSETTINGS,EnumContactSettings);
- CreateServiceFunction(MS_DB_SETSETTINGRESIDENT,SetSettingResident);
-
hSettingChangeEvent = CreateHookableEvent(ME_DB_CONTACT_SETTINGCHANGED);
mirCp = CallService( MS_LANGPACK_GETCODEPAGE, 0, 0 );
diff --git a/plugins/Db3x/src/encrypt.cpp b/plugins/Db3x/src/encrypt.cpp
deleted file mode 100644
index 7426a50cd7..0000000000
--- a/plugins/Db3x/src/encrypt.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-
-Copyright 2000-2003 Miranda ICQ/IM 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"
-
-//VERY VERY VERY BASIC ENCRYPTION FUNCTION
-
-
-void Encrypt(char*msg,BOOL up)
-{
- int i;
- int jump;
- if (up)
- {
- jump=5;
- }
- else
- {
- jump=-5;
- }
-
- for (i=0;msg[i];i++)
- {
- msg[i]=msg[i]+jump;
- }
-
-}
-
-static INT_PTR EncodeString(WPARAM wParam,LPARAM lParam)
-{
- Encrypt((char*)lParam,TRUE);
- return 0;
-}
-
-static INT_PTR DecodeString(WPARAM wParam,LPARAM lParam)
-{
- Encrypt((char*)lParam,FALSE);
- return 0;
-}
-
-int InitCrypt(void)
-{
- CreateServiceFunction(MS_DB_CRYPT_ENCODESTRING,EncodeString);
- CreateServiceFunction(MS_DB_CRYPT_DECODESTRING,DecodeString);
- return 0;
-}
diff --git a/plugins/Db3x/src/init.cpp b/plugins/Db3x/src/init.cpp
index f9b1269bda..b2b3f1fa72 100644
--- a/plugins/Db3x/src/init.cpp
+++ b/plugins/Db3x/src/init.cpp
@@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int hLangpack;
-HINSTANCE g_hInst=NULL;
+HINSTANCE g_hInst = NULL;
static PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
@@ -40,6 +40,8 @@ static PLUGININFOEX pluginInfo = {
{0x1394a3ab, 0x2585, 0x4196, { 0x8f, 0x72, 0xe, 0xae, 0xc2, 0x45, 0xe, 0x11 }} //{1394A3AB-2585-4196-8F72-0EAEC2450E11}
};
+CDdxMmap* g_Db = NULL;
+
/////////////////////////////////////////////////////////////////////////////////////////
static int getCapability( int flag )
@@ -48,43 +50,43 @@ static int getCapability( int flag )
}
// returns 0 if the profile is created, EMKPRF*
-static int makeDatabase(char * profile, int * error)
+static int makeDatabase(TCHAR *profile, int * error)
{
- HANDLE hFile=CreateFileA(profile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+ HANDLE hFile = CreateFile(profile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
if ( hFile != INVALID_HANDLE_VALUE ) {
CreateDbHeaders(hFile);
CloseHandle(hFile);
return 0;
}
- if ( error != NULL ) *error=EMKPRF_CREATEFAILED;
+ if ( error != NULL ) *error = EMKPRF_CREATEFAILED;
return 1;
}
// returns 0 if the given profile has a valid header
-static int grokHeader( char * profile, int * error )
+static int grokHeader(TCHAR *profile, int * error )
{
- int rc=1;
- int chk=0;
+ int rc = 1;
+ int chk = 0;
struct DBHeader hdr;
HANDLE hFile = INVALID_HANDLE_VALUE;
- DWORD dummy=0;
+ DWORD dummy = 0;
- hFile = CreateFileA(profile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ hFile = CreateFile(profile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if ( hFile == INVALID_HANDLE_VALUE ) {
- if ( error != NULL ) *error=EGROKPRF_CANTREAD;
+ if ( error != NULL ) *error = EGROKPRF_CANTREAD;
return 1;
}
// read the header, which can fail (for various reasons)
if ( !ReadFile(hFile, &hdr, sizeof(struct DBHeader), &dummy, NULL)) {
- if ( error != NULL) *error=EGROKPRF_CANTREAD;
+ if ( error != NULL) *error = EGROKPRF_CANTREAD;
CloseHandle(hFile);
return 1;
}
- chk=CheckDbHeaders(&hdr);
+ chk = CheckDbHeaders(&hdr);
if ( chk == 0 ) {
// all the internal tests passed, hurrah
- rc=0;
- if ( error != NULL ) *error=0;
+ rc = 0;
+ if ( error != NULL ) *error = 0;
} else {
// didn't pass at all, or some did.
switch ( chk ) {
@@ -97,13 +99,13 @@ static int grokHeader( char * profile, int * error )
case 2:
{
// header was present, but version information newer
- if ( error != NULL ) *error= EGROKPRF_VERNEWER;
+ if ( error != NULL ) *error = EGROKPRF_VERNEWER;
break;
}
case 3:
{
// header/version OK, internal data missing
- if ( error != NULL ) *error=EGROKPRF_DAMAGED;
+ if ( error != NULL ) *error = EGROKPRF_DAMAGED;
break;
}
} // switch
@@ -113,15 +115,20 @@ static int grokHeader( char * profile, int * error )
}
// returns 0 if all the APIs are injected otherwise, 1
-static int LoadDatabase( char* profile )
+static MIDatabase* LoadDatabase(TCHAR *profile)
{
+ if (g_Db) delete g_Db;
+ g_Db = new CDdxMmap(profile);
+
// don't need thread notifications
- strncpy(szDbPath, profile, sizeof(szDbPath));
+ _tcsncpy(szDbPath, profile, SIZEOF(szDbPath));
mir_getLP(&pluginInfo);
// inject all APIs and hooks into the core
- return LoadDatabaseModule();
+ LoadDatabaseModule();
+
+ return g_Db;
}
static int UnloadDatabase(int wasLoaded)
@@ -131,9 +138,9 @@ static int UnloadDatabase(int wasLoaded)
return 0;
}
-static int getFriendlyName( char * buf, size_t cch, int shortName )
+static int getFriendlyName( TCHAR *buf, size_t cch, int shortName )
{
- strncpy(buf,shortName ? "db3x driver" : "db3x database support",cch);
+ _tcsncpy(buf, shortName ? _T("db3x driver") : _T("db3x database support"), cch);
return 0;
}
diff --git a/plugins/Db3x_mmap/commonheaders.h b/plugins/Db3x_mmap/commonheaders.h
index dd796f9b48..7dc31a1615 100644
--- a/plugins/Db3x_mmap/commonheaders.h
+++ b/plugins/Db3x_mmap/commonheaders.h
@@ -44,18 +44,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <newpluginapi.h>
#include <win2k.h>
#include <m_system.h>
+#include <m_system_cpp.h>
#include <m_database.h>
#include <m_langpack.h>
#include <m_utils.h>
#include "database.h"
+#include "dbintf.h"
#include "resource.h"
#include "version.h"
-extern CRITICAL_SECTION csDbAccess;
-extern struct DBHeader dbHeader;
-extern HANDLE hDbFile;
-
#ifdef __GNUC__
#define mir_i64(x) (x##LL)
#else
diff --git a/plugins/Db3x_mmap/database.cpp b/plugins/Db3x_mmap/database.cpp
index 0e8f45cc24..a69c902772 100644
--- a/plugins/Db3x_mmap/database.cpp
+++ b/plugins/Db3x_mmap/database.cpp
@@ -29,10 +29,7 @@ int InitialiseDbHeaders(void);
int InitSettings(void);
void UninitSettings(void);
int InitContacts(void);
-void UninitContacts(void);
int InitEvents(void);
-void UninitEvents(void);
-int InitCrypt(void);
int InitModuleNames(void);
void UninitModuleNames(void);
int InitCache(void);
@@ -40,10 +37,10 @@ void UninitCache(void);
int InitIni(void);
void UninitIni(void);
-HANDLE hDbFile=INVALID_HANDLE_VALUE;
+HANDLE hDbFile = INVALID_HANDLE_VALUE;
CRITICAL_SECTION csDbAccess;
struct DBHeader dbHeader;
-char szDbPath[MAX_PATH];
+TCHAR szDbPath[MAX_PATH];
static void UnloadDatabase(void)
{
@@ -58,8 +55,8 @@ static void UnloadDatabase(void)
DWORD CreateNewSpace(int bytes)
{
DWORD ofsNew;
- ofsNew=dbHeader.ofsFileEnd;
- dbHeader.ofsFileEnd+=bytes;
+ ofsNew = dbHeader.ofsFileEnd;
+ dbHeader.ofsFileEnd += bytes;
DBWrite(0,&dbHeader,sizeof(dbHeader));
log2("newspace %d@%08x",bytes,ofsNew);
return ofsNew;
@@ -69,10 +66,10 @@ void DeleteSpace(DWORD ofs,int bytes)
{
if (ofs+bytes == dbHeader.ofsFileEnd) {
log2("freespace %d@%08x",bytes,ofs);
- dbHeader.ofsFileEnd=ofs;
+ dbHeader.ofsFileEnd = ofs;
} else {
log2("deletespace %d@%08x",bytes,ofs);
- dbHeader.slackSpace+=bytes;
+ dbHeader.slackSpace += bytes;
}
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFill(ofs,bytes);
@@ -86,11 +83,11 @@ DWORD ReallocSpace(DWORD ofs,int oldSize,int newSize)
if (ofs+oldSize == dbHeader.ofsFileEnd) {
ofsNew = ofs;
- dbHeader.ofsFileEnd+=newSize-oldSize;
+ dbHeader.ofsFileEnd += newSize-oldSize;
DBWrite(0,&dbHeader,sizeof(dbHeader));
log3("adding newspace %d@%08x+%d",newSize,ofsNew,oldSize);
} else {
- ofsNew=CreateNewSpace(newSize);
+ ofsNew = CreateNewSpace(newSize);
DBMoveChunk(ofsNew,ofs,oldSize);
DeleteSpace(ofs,oldSize);
}
@@ -99,10 +96,7 @@ DWORD ReallocSpace(DWORD ofs,int oldSize,int newSize)
void UnloadDatabaseModule(void)
{
- //UninitIni();
- UninitEvents();
UninitSettings();
- UninitContacts();
UninitModuleNames();
UninitCache();
UnloadDatabase();
@@ -114,8 +108,8 @@ int LoadDatabaseModule(void)
InitializeCriticalSection(&csDbAccess);
log0("DB logging running");
{
- DWORD dummy=0;
- hDbFile=CreateFileA(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
+ DWORD dummy = 0;
+ hDbFile = CreateFile(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
if ( hDbFile == INVALID_HANDLE_VALUE ) {
return 1;
}
@@ -124,17 +118,16 @@ int LoadDatabaseModule(void)
return 1;
}
}
- //if(ParseCommandLine()) return 1;
- if(InitCache()) return 1;
- if(InitModuleNames()) return 1;
- if(InitContacts()) return 1;
- if(InitSettings()) return 1;
- if(InitEvents()) return 1;
- if(InitCrypt()) return 1;
+
+ if (InitCache()) return 1;
+ if (InitModuleNames()) return 1;
+ if (InitContacts()) return 1;
+ if (InitSettings()) return 1;
+ if (InitEvents()) return 1;
return 0;
}
-static DWORD DatabaseCorrupted=0;
+static DWORD DatabaseCorrupted = 0;
static TCHAR *msg = NULL;
static DWORD dwErr = 0;
@@ -144,7 +137,7 @@ void __cdecl dbpanic(void *arg)
{
TCHAR err[256];
- if (dwErr==ERROR_DISK_FULL)
+ if (dwErr == ERROR_DISK_FULL)
msg = TranslateT("Disk is full. Miranda will now shutdown.");
mir_sntprintf(err, SIZEOF(err), msg, TranslateT("Database failure. Miranda will now shutdown."), dwErr);
@@ -159,10 +152,10 @@ void __cdecl dbpanic(void *arg)
void DatabaseCorruption(TCHAR *text)
{
- int kill=0;
+ int kill = 0;
EnterCriticalSection(&csDbAccess);
- if (DatabaseCorrupted==0) {
+ if (DatabaseCorrupted == 0) {
DatabaseCorrupted++;
kill++;
msg = text;
@@ -191,7 +184,7 @@ void DBLog(const char *file,int line,const char *fmt,...)
va_start(vararg,fmt);
mir_vsnprintf(str,sizeof(str),fmt,vararg);
va_end(vararg);
- fp=fopen("c:\\mirandadatabase.log.txt","at");
+ fp = fopen("c:\\mirandadatabase.log.txt","at");
fprintf(fp,"%u: %s %d: %s\n",GetTickCount(),file,line,str);
fclose(fp);
}
diff --git a/plugins/Db3x_mmap/database.h b/plugins/Db3x_mmap/database.h
index 3dd602c8b9..3760711db3 100644
--- a/plugins/Db3x_mmap/database.h
+++ b/plugins/Db3x_mmap/database.h
@@ -39,7 +39,7 @@ DBHeader
| | \-->module name (DBModuleName)
| \-->first/last/firstunread event
|-->user contact (DBContact)
- | |-->next contact=NULL
+ | |-->next contact = NULL
| |-->first settings as above
| \-->first/last/firstunread event as above
\-->first module name (DBModuleName)
@@ -56,12 +56,12 @@ struct DBSignature {
BYTE eof;
};
-static struct DBSignature dbSignature={"Miranda ICQ DB",0x1A};
+static struct DBSignature dbSignature = {"Miranda ICQ DB",0x1A};
#include <pshpack1.h>
struct DBHeader {
BYTE signature[16]; // 'Miranda ICQ DB',0,26
- DWORD version; //as 4 bytes, ie 1.2.3.10=0x0102030a
+ 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
@@ -70,13 +70,15 @@ struct DBHeader {
//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 struct DBContact in the chain
- DWORD ofsUser; //offset to struct DBContact representing 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 {
+
+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
@@ -92,7 +94,8 @@ struct DBContact {
};
#define DBMODULENAME_SIGNATURE 0x4DDECADEu
-struct DBModuleName {
+struct DBModuleName
+{
DWORD signature;
DWORD ofsNext; //offset to the next module name in the chain
BYTE cbName; //number of characters in this module name
@@ -100,7 +103,8 @@ struct DBModuleName {
};
#define DBCONTACTSETTINGS_SIGNATURE 0x53DECADEu
-struct DBContactSettings {
+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
@@ -109,13 +113,13 @@ struct DBContactSettings {
//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
+ //structs, the last has cbName = 0
};
/* not a valid structure, content is figured out on the fly
struct DBSetting {
BYTE cbName; //number of bytes in the name of this setting
- //this =0 marks the end
+ //this = 0 marks the end
char szName[...]; //setting name, excluding nul
BYTE dataType; //type of data. see m_database.h, db/contact/getsetting
union { //a load of types of data, length is defined by dataType
@@ -133,18 +137,20 @@ struct DBSetting {
*/
#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
+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>
typedef struct
@@ -181,6 +187,9 @@ typedef struct
//databasecorruption: with NULL called if any signatures are broken. very very fatal
void DatabaseCorruption(TCHAR *text);
PBYTE DBRead(DWORD ofs,int bytesRequired,int *bytesAvail); //any preview result could be invalidated by the next call
+__forceinline PBYTE DBRead(HANDLE hContact,int bytesRequired,int *bytesAvail)
+{ return DBRead((DWORD)hContact, bytesRequired, bytesAvail);
+}
void DBWrite(DWORD ofs,PVOID pData,int count);
void DBFill(DWORD ofs,int bytes);
void DBFlush(int setting);
@@ -196,6 +205,22 @@ int CreateDbHeaders(HANDLE hFile);
int LoadDatabaseModule(void);
void UnloadDatabaseModule(void);
+DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index);
+int CheckProto(HANDLE hContact, const char *proto);
+
+void FreeCachedVariant( DBVARIANT* V );
+
+extern CRITICAL_SECTION csDbAccess;
+extern struct DBHeader dbHeader;
+extern HANDLE hDbFile;
+
+extern HANDLE hCacheHeap;
+extern SortedList lContacts;
+extern HANDLE hLastCachedContact;
+extern HANDLE hContactDeletedEvent,hContactAddedEvent;
+
+extern BOOL safetyMode;
+
#define MAXCACHEDREADSIZE 65536
//#define DBLOGGING
diff --git a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj
index 793f1ac4ef..22cbaeca69 100644
--- a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj
+++ b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj
@@ -208,9 +208,9 @@
<ClCompile Include="dbcontacts.cpp" />
<ClCompile Include="dbevents.cpp" />
<ClCompile Include="dbheaders.cpp" />
+ <ClCompile Include="dbintf.cpp" />
<ClCompile Include="dbmodulechain.cpp" />
<ClCompile Include="dbsettings.cpp" />
- <ClCompile Include="encrypt.cpp" />
<ClCompile Include="init.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
@@ -218,6 +218,7 @@
<ItemGroup>
<ClInclude Include="commonheaders.h" />
<ClInclude Include="database.h" />
+ <ClInclude Include="dbintf.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="db3x_mmap.rc" />
diff --git a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters
index 667339ebe6..2f8143f35e 100644
--- a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters
+++ b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters
@@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="commonheaders.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="database.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -39,10 +36,10 @@
<ClCompile Include="dbsettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="encrypt.cpp">
+ <ClCompile Include="init.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="init.cpp">
+ <ClCompile Include="dbintf.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@@ -53,6 +50,9 @@
<ClInclude Include="database.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="dbintf.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="db3x_mmap.rc">
diff --git a/plugins/Db3x_mmap/dbcache.cpp b/plugins/Db3x_mmap/dbcache.cpp
index f5b953f615..1e9369cc85 100644
--- a/plugins/Db3x_mmap/dbcache.cpp
+++ b/plugins/Db3x_mmap/dbcache.cpp
@@ -65,7 +65,7 @@ void ReMap(DWORD needed)
}
}
else
- dwFileSize += ChunkSize;
+ dwFileSize += ChunkSize;
// FlushViewOfFile(pDbCache, 0);
UnmapViewOfFile(pDbCache);
@@ -97,7 +97,7 @@ void DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes)
PBYTE DBRead(DWORD ofs,int bytesRequired,int *bytesAvail)
{
// buggy read
- if (ofs>=dwFileSize) {
+ if (ofs>= dwFileSize) {
log2("read from outside %d@%08x",bytesRequired,ofs);
if (bytesAvail!=NULL) *bytesAvail = ChunkSize;
return pNull;
@@ -120,7 +120,7 @@ void DBWrite(DWORD ofs,PVOID pData,int bytes)
void DBFill(DWORD ofs,int bytes)
{
log2("zerofill %d@%08x",bytes,ofs);
- if (ofs+bytes<=dwFileSize)
+ if (ofs+bytes <= dwFileSize)
ZeroMemory(pDbCache+ofs,bytes);
logg();
}
@@ -146,7 +146,7 @@ void DBFlush(int setting)
{
if (!setting) {
log0("nflush1");
- if(safetyMode && pDbCache) {
+ if (safetyMode && pDbCache) {
if (FlushViewOfFile(pDbCache, 0) == 0) {
if (flushFailTick == 0)
flushFailTick = GetTickCount();
@@ -160,13 +160,13 @@ void DBFlush(int setting)
return;
}
KillTimer(NULL,flushBuffersTimerId);
- flushBuffersTimerId=SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc);
+ flushBuffersTimerId = SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc);
}
static INT_PTR CacheSetSafetyMode(WPARAM wParam,LPARAM lParam)
{
EnterCriticalSection(&csDbAccess);
- safetyMode=wParam;
+ safetyMode = wParam;
LeaveCriticalSection(&csDbAccess);
DBFlush(1);
return 0;
@@ -184,15 +184,12 @@ int InitCache(void)
// Align to chunk
x = dwFileSize % ChunkSize;
- if (x) dwFileSize += ChunkSize - x;
+ if (x) dwFileSize += ChunkSize - x;
Map();
// zero region for reads outside the file
pNull = (PBYTE)calloc(ChunkSize, 1);
-
- CreateServiceFunction(MS_DB_SETSAFETYMODE, CacheSetSafetyMode);
-
return 0;
}
diff --git a/plugins/Db3x_mmap/dbcontacts.cpp b/plugins/Db3x_mmap/dbcontacts.cpp
index 0afd3469ab..a827db3385 100644
--- a/plugins/Db3x_mmap/dbcontacts.cpp
+++ b/plugins/Db3x_mmap/dbcontacts.cpp
@@ -23,39 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-extern HANDLE hCacheHeap;
-extern SortedList lContacts;
-extern HANDLE hLastCachedContact;
-
-INT_PTR GetContactSettingStatic(WPARAM wParam,LPARAM lParam);
-void FreeCachedVariant( DBVARIANT* V );
-
-static INT_PTR GetContactCount(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindFirstContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR AddContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam);
-
-static HANDLE hContactDeletedEvent,hContactAddedEvent;
-
-
-int InitContacts(void)
-{
- CreateServiceFunction(MS_DB_CONTACT_GETCOUNT,GetContactCount);
- CreateServiceFunction(MS_DB_CONTACT_FINDFIRST,FindFirstContact);
- CreateServiceFunction(MS_DB_CONTACT_FINDNEXT,FindNextContact);
- CreateServiceFunction(MS_DB_CONTACT_DELETE,DeleteContact);
- CreateServiceFunction(MS_DB_CONTACT_ADD,AddContact);
- CreateServiceFunction(MS_DB_CONTACT_IS,IsDbContact);
- hContactDeletedEvent=CreateHookableEvent(ME_DB_CONTACT_DELETED);
- hContactAddedEvent=CreateHookableEvent(ME_DB_CONTACT_ADDED);
- return 0;
-}
-
-void UninitContacts(void)
-{
-}
+HANDLE hContactDeletedEvent, hContactAddedEvent;
DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index)
{
@@ -67,20 +35,10 @@ DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index)
return VL;
}
-static INT_PTR GetContactCount(WPARAM wParam,LPARAM lParam)
-{
- int ret;
-
- EnterCriticalSection(&csDbAccess);
- ret=dbHeader.contactCount;
- LeaveCriticalSection(&csDbAccess);
- return ret;
-}
-
#define proto_module "Protocol"
#define proto_setting "p"
-static int CheckProto(HANDLE hContact, const char *proto)
+int CDdxMmap::CheckProto(HANDLE hContact, const char *proto)
{
static char protobuf[MAX_PATH] = {0};
static DBVARIANT dbv;
@@ -90,44 +48,54 @@ static int CheckProto(HANDLE hContact, const char *proto)
dbv.pszVal = protobuf;
dbv.cchVal = sizeof(protobuf);
- if (GetContactSettingStatic((WPARAM)hContact, (LPARAM )&sVal) != 0
- || (dbv.type != DBVT_ASCIIZ)) return 0;
+ if (GetContactSettingStatic(hContact, &sVal) != 0 || (dbv.type != DBVT_ASCIIZ))
+ return 0;
return !strcmp(protobuf,proto);
}
-static INT_PTR FindFirstContact(WPARAM wParam,LPARAM lParam)
+int InitContacts(void)
{
- INT_PTR ret = 0;
- EnterCriticalSection(&csDbAccess);
- ret = (INT_PTR)dbHeader.ofsFirstContact;
- if (lParam && !CheckProto((HANDLE)ret,(const char*)lParam))
- ret = FindNextContact((WPARAM)ret,lParam);
- LeaveCriticalSection(&csDbAccess);
+ hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED);
+ hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED);
+ return 0;
+}
+
+STDMETHODIMP_(LONG) CDdxMmap::GetContactCount(void)
+{
+ mir_cslock lck(csDbAccess);
+ return dbHeader.contactCount;
+}
+
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstContact(const char *szProto)
+{
+ mir_cslock lck(csDbAccess);
+ HANDLE ret = (HANDLE)dbHeader.ofsFirstContact;
+ if (szProto && !CheckProto(ret, szProto))
+ ret = FindNextContact(ret, szProto);
return ret;
}
-static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindNextContact(HANDLE hContact, const char *szProto)
{
int index;
- struct DBContact *dbc;
+ DBContact *dbc;
DBCachedContactValueList VLtemp, *VL = NULL;
- VLtemp.hContact = (HANDLE)wParam;
- EnterCriticalSection(&csDbAccess);
+ VLtemp.hContact = hContact;
+
+ mir_cslock lck(csDbAccess);
while(VLtemp.hContact) {
if ( List_GetIndex(&lContacts,&VLtemp,&index)) {
VL = ( DBCachedContactValueList* )lContacts.items[index];
if (VL->hNext != NULL) {
- if (!lParam || CheckProto(VL->hNext,(const char*)lParam)) {
- LeaveCriticalSection(&csDbAccess);
- return (INT_PTR)VL->hNext;
- }
- else {
- VLtemp.hContact = VL->hNext;
- continue;
- } } }
-
- dbc=(struct DBContact*)DBRead((DWORD)VLtemp.hContact,sizeof(struct DBContact),NULL);
+ if (!szProto || CheckProto(VL->hNext, szProto))
+ return VL->hNext;
+
+ VLtemp.hContact = VL->hNext;
+ continue;
+ } }
+
+ dbc = (DBContact*)DBRead(VLtemp.hContact,sizeof(DBContact),NULL);
if (dbc->signature!=DBCONTACT_SIGNATURE)
break;
else {
@@ -135,135 +103,132 @@ static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam)
VL = AddToCachedContactList(VLtemp.hContact,index);
VL->hNext = (HANDLE)dbc->ofsNext;
- if (VL->hNext != NULL && (!lParam || CheckProto(VL->hNext,(const char*)lParam))) {
+ if (VL->hNext != NULL && (!szProto || CheckProto(VL->hNext, szProto))) {
LeaveCriticalSection(&csDbAccess);
- return (INT_PTR)VL->hNext;
+ return VL->hNext;
}
VLtemp.hContact = VL->hNext;
} }
- LeaveCriticalSection(&csDbAccess);
- return 0;
+
+ return NULL;
}
-static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::DeleteContact(HANDLE hContact)
{
- struct DBContact *dbc,*dbcPrev;
DWORD ofsThis,ofsNext,ofsFirstEvent;
- struct DBContactSettings *dbcs;
- struct DBEvent *dbe;
+ DBContactSettings *dbcs;
+ DBEvent *dbe;
int index;
- if ((HANDLE)wParam==NULL) return 1;
- EnterCriticalSection(&csDbAccess);
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
- LeaveCriticalSection(&csDbAccess);
- return 1;
- }
- if ( (HANDLE)wParam == (HANDLE)dbHeader.ofsUser ) {
- LeaveCriticalSection(&csDbAccess);
- log0("FATAL: del of user chain attempted.");
+ if (hContact == NULL)
return 1;
+
+ {
+ mir_cslock lck(csDbAccess);
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) {
+ LeaveCriticalSection(&csDbAccess);
+ return 1;
+ }
+ if (hContact == (HANDLE)dbHeader.ofsUser) {
+ LeaveCriticalSection(&csDbAccess);
+ log0("FATAL: del of user chain attempted.");
+ return 1;
+ }
+ log0("del contact");
}
- log0("del contact");
- LeaveCriticalSection(&csDbAccess);
+
//call notifier while outside mutex
- NotifyEventHooks(hContactDeletedEvent,wParam,0);
+ NotifyEventHooks(hContactDeletedEvent, (WPARAM)hContact, 0);
+
//get back in
- EnterCriticalSection(&csDbAccess);
+ mir_cslock lck(csDbAccess);
- { DBCachedContactValueList VLtemp;
- VLtemp.hContact = (HANDLE)wParam;
- if ( List_GetIndex(&lContacts,&VLtemp,&index))
- {
- DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index];
- DBCachedContactValue* V = VL->first;
- while ( V != NULL ) {
- DBCachedContactValue* V1 = V->next;
- FreeCachedVariant(&V->value);
- HeapFree( hCacheHeap, 0, V );
- V = V1;
- }
- HeapFree( hCacheHeap, 0, VL );
+ DBCachedContactValueList VLtemp;
+ VLtemp.hContact = hContact;
+ if ( List_GetIndex(&lContacts,&VLtemp,&index))
+ {
+ DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index];
+ DBCachedContactValue* V = VL->first;
+ while ( V != NULL ) {
+ DBCachedContactValue* V1 = V->next;
+ FreeCachedVariant(&V->value);
+ HeapFree( hCacheHeap, 0, V );
+ V = V1;
+ }
+ HeapFree( hCacheHeap, 0, VL );
- if (VLtemp.hContact == hLastCachedContact)
- hLastCachedContact = NULL;
- List_Remove(&lContacts,index);
- } }
+ if (VLtemp.hContact == hLastCachedContact)
+ hLastCachedContact = NULL;
+ List_Remove(&lContacts,index);
+ }
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
//delete settings chain
- ofsThis=dbc->ofsFirstSettings;
- ofsFirstEvent=dbc->ofsFirstEvent;
+ ofsThis = dbc->ofsFirstSettings;
+ ofsFirstEvent = dbc->ofsFirstEvent;
while(ofsThis) {
- dbcs=(struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
- ofsNext=dbcs->ofsNext;
+ dbcs = (struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
+ ofsNext = dbcs->ofsNext;
DeleteSpace(ofsThis,offsetof(struct DBContactSettings,blob)+dbcs->cbBlob);
- ofsThis=ofsNext;
+ ofsThis = ofsNext;
}
//delete event chain
- ofsThis=ofsFirstEvent;
+ ofsThis = ofsFirstEvent;
while(ofsThis) {
- dbe=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
- ofsNext=dbe->ofsNext;
- DeleteSpace(ofsThis,offsetof(struct DBEvent,blob)+dbe->cbBlob);
- ofsThis=ofsNext;
+ dbe = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
+ ofsNext = dbe->ofsNext;
+ DeleteSpace(ofsThis,offsetof(DBEvent,blob)+dbe->cbBlob);
+ ofsThis = ofsNext;
}
//find previous contact in chain and change ofsNext
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbHeader.ofsFirstContact==wParam) {
- dbHeader.ofsFirstContact=dbc->ofsNext;
+ dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ if (dbHeader.ofsFirstContact == (DWORD)hContact) {
+ dbHeader.ofsFirstContact = dbc->ofsNext;
DBWrite(0,&dbHeader,sizeof(dbHeader));
}
else {
- ofsNext=dbc->ofsNext;
- ofsThis=dbHeader.ofsFirstContact;
- dbcPrev=(struct DBContact*)DBRead(ofsThis,sizeof(struct DBContact),NULL);
- while(dbcPrev->ofsNext!=wParam) {
- if(dbcPrev->ofsNext==0) DatabaseCorruption(NULL);
- ofsThis=dbcPrev->ofsNext;
- dbcPrev=(struct DBContact*)DBRead(ofsThis,sizeof(struct DBContact),NULL);
+ ofsNext = dbc->ofsNext;
+ ofsThis = dbHeader.ofsFirstContact;
+ DBContact *dbcPrev = (DBContact*)DBRead(ofsThis,sizeof(DBContact),NULL);
+ while(dbcPrev->ofsNext != (DWORD)hContact) {
+ if (dbcPrev->ofsNext == 0) DatabaseCorruption(NULL);
+ ofsThis = dbcPrev->ofsNext;
+ dbcPrev = (DBContact*)DBRead(ofsThis,sizeof(DBContact),NULL);
+ }
+ dbcPrev->ofsNext = ofsNext;
+ DBWrite(ofsThis,dbcPrev,sizeof(DBContact));
+
+ DBCachedContactValueList VLtemp;
+ VLtemp.hContact = (HANDLE)ofsThis;
+ if ( List_GetIndex(&lContacts,&VLtemp,&index)) {
+ DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index];
+ VL->hNext = ( HANDLE )ofsNext;
}
- dbcPrev->ofsNext=ofsNext;
- DBWrite(ofsThis,dbcPrev,sizeof(struct DBContact));
- {
- DBCachedContactValueList VLtemp;
- VLtemp.hContact = (HANDLE)ofsThis;
- if ( List_GetIndex(&lContacts,&VLtemp,&index))
- {
- DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index];
- VL->hNext = ( HANDLE )ofsNext;
- } }
}
+
//delete contact
- DeleteSpace(wParam,sizeof(struct DBContact));
+ DeleteSpace((DWORD)hContact, sizeof(DBContact));
//decrement contact count
dbHeader.contactCount--;
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFlush(0);
- //quit
- LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR AddContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::AddContact()
{
- struct DBContact dbc;
- DWORD ofsNew;
-
log0("add contact");
- EnterCriticalSection(&csDbAccess);
- ofsNew=CreateNewSpace(sizeof(struct DBContact));
- dbc.signature=DBCONTACT_SIGNATURE;
- dbc.eventCount=0;
- dbc.ofsFirstEvent=dbc.ofsLastEvent=0;
- dbc.ofsFirstSettings=0;
- dbc.ofsNext=dbHeader.ofsFirstContact;
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
- dbHeader.ofsFirstContact=ofsNew;
+
+ mir_cslock lck(csDbAccess);
+ DWORD ofsNew = CreateNewSpace(sizeof(DBContact));
+
+ DBContact dbc = { 0 };
+ dbc.signature = DBCONTACT_SIGNATURE;
+ dbc.ofsNext = dbHeader.ofsFirstContact;
+ dbHeader.ofsFirstContact = ofsNew;
dbHeader.contactCount++;
- DBWrite(ofsNew,&dbc,sizeof(struct DBContact));
+ DBWrite(ofsNew,&dbc,sizeof(DBContact));
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFlush(0);
@@ -271,27 +236,27 @@ static INT_PTR AddContact(WPARAM wParam,LPARAM lParam)
LeaveCriticalSection(&csDbAccess);
NotifyEventHooks(hContactAddedEvent,(WPARAM)ofsNew,0);
- return (INT_PTR)ofsNew;
+ return (HANDLE)ofsNew;
}
-static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::IsDbContact(HANDLE hContact)
{
- struct DBContact *dbc;
- DWORD ofsContact=(DWORD)wParam;
+ DBContact *dbc;
+ DWORD ofsContact = (DWORD)hContact;
int ret;
EnterCriticalSection(&csDbAccess);
{
int index;
DBCachedContactValueList VLtemp;
- VLtemp.hContact = (HANDLE)wParam;
+ VLtemp.hContact = hContact;
if ( List_GetIndex(&lContacts,&VLtemp,&index))
ret = TRUE;
else {
- dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- ret=dbc->signature==DBCONTACT_SIGNATURE;
+ dbc = (DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ ret = dbc->signature == DBCONTACT_SIGNATURE;
if (ret)
- AddToCachedContactList((HANDLE)wParam, index);
+ AddToCachedContactList(hContact, index);
} }
LeaveCriticalSection(&csDbAccess);
diff --git a/plugins/Db3x_mmap/dbevents.cpp b/plugins/Db3x_mmap/dbevents.cpp
index 76d1cd4a28..c7a44d2e4e 100644
--- a/plugins/Db3x_mmap/dbevents.cpp
+++ b/plugins/Db3x_mmap/dbevents.cpp
@@ -30,74 +30,73 @@ char *GetModuleNameByOfs(DWORD ofs);
static HANDLE hEventDeletedEvent,hEventAddedEvent,hEventFilterAddedEvent;
-static INT_PTR GetEventCount(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::GetEventCount(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ LONG ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=-1;
- else ret=dbc->eventCount;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) ret = -1;
+ else ret = dbc->eventCount;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
{
- DBEVENTINFO *dbei=(DBEVENTINFO*)lParam;
- struct DBContact dbc;
- struct DBEvent dbe,*dbeTest;
+ DBContact dbc;
+ DBEvent dbe,*dbeTest;
DWORD ofsNew,ofsModuleName,ofsContact,ofsThis;
BOOL neednotify;
- if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 0;
- if(dbei->timestamp==0) return 0;
- if (NotifyEventHooks(hEventFilterAddedEvent,wParam,lParam)) {
+ if (dbei == NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 0;
+ if (dbei->timestamp == 0) return 0;
+ if (NotifyEventHooks(hEventFilterAddedEvent, (WPARAM)hContact, (LPARAM)dbei)) {
return 0;
}
EnterCriticalSection(&csDbAccess);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=(DWORD)wParam;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE) {
+ if (hContact == 0) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc.signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 0;
}
- ofsNew=CreateNewSpace(offsetof(struct DBEvent,blob)+dbei->cbBlob);
- ofsModuleName=GetModuleNameOfs(dbei->szModule);
-
- dbe.signature=DBEVENT_SIGNATURE;
- dbe.ofsModuleName=ofsModuleName;
- dbe.timestamp=dbei->timestamp;
- dbe.flags=dbei->flags;
- dbe.eventType=dbei->eventType;
- dbe.cbBlob=dbei->cbBlob;
+ ofsNew = CreateNewSpace(offsetof(DBEvent,blob)+dbei->cbBlob);
+ ofsModuleName = GetModuleNameOfs(dbei->szModule);
+
+ dbe.signature = DBEVENT_SIGNATURE;
+ dbe.ofsModuleName = ofsModuleName;
+ dbe.timestamp = dbei->timestamp;
+ dbe.flags = dbei->flags;
+ dbe.eventType = dbei->eventType;
+ dbe.cbBlob = dbei->cbBlob;
//find where to put it - sort by timestamp
- if(dbc.eventCount==0) {
- dbe.ofsPrev=wParam;
- dbe.ofsNext=0;
- dbe.flags|=DBEF_FIRST;
- dbc.ofsFirstEvent=dbc.ofsLastEvent=ofsNew;
+ if (dbc.eventCount == 0) {
+ dbe.ofsPrev = (DWORD)hContact;
+ dbe.ofsNext = 0;
+ dbe.flags |= DBEF_FIRST;
+ dbc.ofsFirstEvent = dbc.ofsLastEvent = ofsNew;
}
else {
- dbeTest=(struct DBEvent*)DBRead(dbc.ofsFirstEvent,sizeof(struct DBEvent),NULL);
+ dbeTest = (DBEvent*)DBRead(dbc.ofsFirstEvent,sizeof(DBEvent),NULL);
// Should new event be placed before first event in chain?
if (dbei->timestamp < dbeTest->timestamp) {
- dbe.ofsPrev=wParam;
- dbe.ofsNext=dbc.ofsFirstEvent;
- dbe.flags|=DBEF_FIRST;
- dbc.ofsFirstEvent=ofsNew;
- dbeTest=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeTest->flags&=~DBEF_FIRST;
- dbeTest->ofsPrev=ofsNew;
- DBWrite(dbe.ofsNext,dbeTest,sizeof(struct DBEvent));
+ dbe.ofsPrev = (DWORD)hContact;
+ dbe.ofsNext = dbc.ofsFirstEvent;
+ dbe.flags |= DBEF_FIRST;
+ dbc.ofsFirstEvent = ofsNew;
+ dbeTest = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeTest->flags &= ~DBEF_FIRST;
+ dbeTest->ofsPrev = ofsNew;
+ DBWrite(dbe.ofsNext,dbeTest,sizeof(DBEvent));
}
else {
// Loop through the chain, starting at the end
ofsThis = dbc.ofsLastEvent;
- dbeTest = (struct DBEvent*)DBRead(ofsThis, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
for (;;) {
// If the new event's timesstamp is equal to or greater than the
// current dbevent, it will be inserted after. If not, continue
@@ -106,34 +105,34 @@ static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam)
dbe.ofsPrev = ofsThis;
dbe.ofsNext = dbeTest->ofsNext;
dbeTest->ofsNext = ofsNew;
- DBWrite(ofsThis, dbeTest, sizeof(struct DBEvent));
+ DBWrite(ofsThis, dbeTest, sizeof(DBEvent));
if (dbe.ofsNext == 0)
dbc.ofsLastEvent = ofsNew;
else {
- dbeTest = (struct DBEvent*)DBRead(dbe.ofsNext, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(dbe.ofsNext, sizeof(DBEvent), NULL);
dbeTest->ofsPrev = ofsNew;
- DBWrite(dbe.ofsNext, dbeTest, sizeof(struct DBEvent));
+ DBWrite(dbe.ofsNext, dbeTest, sizeof(DBEvent));
}
break;
}
ofsThis = dbeTest->ofsPrev;
- dbeTest = (struct DBEvent*)DBRead(ofsThis, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
}
}
}
dbc.eventCount++;
if (!(dbe.flags&(DBEF_READ|DBEF_SENT))) {
- if(dbe.timestamp<dbc.timestampFirstUnread || dbc.timestampFirstUnread==0) {
- dbc.timestampFirstUnread=dbe.timestamp;
- dbc.ofsFirstUnreadEvent=ofsNew;
+ if (dbe.timestamp<dbc.timestampFirstUnread || dbc.timestampFirstUnread == 0) {
+ dbc.timestampFirstUnread = dbe.timestamp;
+ dbc.ofsFirstUnreadEvent = ofsNew;
}
neednotify = TRUE;
}
else neednotify = safetyMode;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
- DBWrite(ofsNew,&dbe,offsetof(struct DBEvent,blob));
- DBWrite(ofsNew+offsetof(struct DBEvent,blob),dbei->pBlob,dbei->cbBlob);
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
+ DBWrite(ofsNew,&dbe,offsetof(DBEvent,blob));
+ DBWrite(ofsNew+offsetof(DBEvent,blob),dbei->pBlob,dbei->cbBlob);
DBFlush(0);
LeaveCriticalSection(&csDbAccess);
@@ -141,272 +140,271 @@ static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam)
// Notify only in safe mode or on really new events
if (neednotify)
- NotifyEventHooks(hEventAddedEvent,wParam,(LPARAM)ofsNew);
+ NotifyEventHooks(hEventAddedEvent, (WPARAM)hContact, (LPARAM)ofsNew);
- return (INT_PTR)ofsNew;
+ return (HANDLE)ofsNew;
}
-static INT_PTR DeleteEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
{
- struct DBContact dbc;
+ DBContact dbc;
DWORD ofsContact,ofsThis;
- struct DBEvent dbe,*dbeNext,*dbePrev;
+ DBEvent dbe,*dbeNext,*dbePrev;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- dbe=*(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE || dbe.signature!=DBEVENT_SIGNATURE) {
+ if (hContact == 0) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ dbe = *(DBEvent*)DBRead(hContact,sizeof(DBEvent),NULL);
+ if (dbc.signature!=DBCONTACT_SIGNATURE || dbe.signature!=DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
log1("delete event @ %08x",wParam);
LeaveCriticalSection(&csDbAccess);
//call notifier while outside mutex
- NotifyEventHooks(hEventDeletedEvent,wParam,lParam);
+ NotifyEventHooks(hEventDeletedEvent,(WPARAM)hContact, (LPARAM)hDbEvent);
//get back in
EnterCriticalSection(&csDbAccess);
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- dbe=*(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ dbe = *(DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
//check if this was the first unread, if so, recalc the first unread
- if(dbc.ofsFirstUnreadEvent==(DWORD)lParam) {
- dbeNext=&dbe;
+ if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
+ dbeNext = &dbe;
for (;;) {
- if(dbeNext->ofsNext==0) {
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
+ if (dbeNext->ofsNext == 0) {
+ dbc.ofsFirstUnreadEvent = 0;
+ dbc.timestampFirstUnread = 0;
break;
}
- ofsThis=dbeNext->ofsNext;
- dbeNext=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
+ ofsThis = dbeNext->ofsNext;
+ dbeNext = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
if (!(dbeNext->flags&(DBEF_READ|DBEF_SENT))) {
- dbc.ofsFirstUnreadEvent=ofsThis;
- dbc.timestampFirstUnread=dbeNext->timestamp;
+ dbc.ofsFirstUnreadEvent = ofsThis;
+ dbc.timestampFirstUnread = dbeNext->timestamp;
break;
}
}
}
//get previous and next events in chain and change offsets
- if(dbe.flags&DBEF_FIRST) {
- if(dbe.ofsNext==0) {
- dbc.ofsFirstEvent=dbc.ofsLastEvent=0;
+ if (dbe.flags&DBEF_FIRST) {
+ if (dbe.ofsNext == 0) {
+ dbc.ofsFirstEvent = dbc.ofsLastEvent = 0;
}
else {
- dbeNext=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeNext->flags|=DBEF_FIRST;
- dbeNext->ofsPrev=dbe.ofsPrev;
- DBWrite(dbe.ofsNext,dbeNext,sizeof(struct DBEvent));
- dbc.ofsFirstEvent=dbe.ofsNext;
+ dbeNext = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeNext->flags |= DBEF_FIRST;
+ dbeNext->ofsPrev = dbe.ofsPrev;
+ DBWrite(dbe.ofsNext,dbeNext,sizeof(DBEvent));
+ dbc.ofsFirstEvent = dbe.ofsNext;
}
}
else {
- if(dbe.ofsNext==0) {
- dbePrev=(struct DBEvent*)DBRead(dbe.ofsPrev,sizeof(struct DBEvent),NULL);
- dbePrev->ofsNext=0;
- DBWrite(dbe.ofsPrev,dbePrev,sizeof(struct DBEvent));
- dbc.ofsLastEvent=dbe.ofsPrev;
+ if (dbe.ofsNext == 0) {
+ dbePrev = (DBEvent*)DBRead(dbe.ofsPrev,sizeof(DBEvent),NULL);
+ dbePrev->ofsNext = 0;
+ DBWrite(dbe.ofsPrev,dbePrev,sizeof(DBEvent));
+ dbc.ofsLastEvent = dbe.ofsPrev;
}
else {
- dbePrev=(struct DBEvent*)DBRead(dbe.ofsPrev,sizeof(struct DBEvent),NULL);
- dbePrev->ofsNext=dbe.ofsNext;
- DBWrite(dbe.ofsPrev,dbePrev,sizeof(struct DBEvent));
- dbeNext=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeNext->ofsPrev=dbe.ofsPrev;
- DBWrite(dbe.ofsNext,dbeNext,sizeof(struct DBEvent));
+ dbePrev = (DBEvent*)DBRead(dbe.ofsPrev,sizeof(DBEvent),NULL);
+ dbePrev->ofsNext = dbe.ofsNext;
+ DBWrite(dbe.ofsPrev,dbePrev,sizeof(DBEvent));
+ dbeNext = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeNext->ofsPrev = dbe.ofsPrev;
+ DBWrite(dbe.ofsNext,dbeNext,sizeof(DBEvent));
}
}
//delete event
- DeleteSpace(lParam,offsetof(struct DBEvent,blob)+dbe.cbBlob);
+ DeleteSpace((DWORD)hDbEvent, offsetof(DBEvent,blob)+dbe.cbBlob);
//decrement event count
dbc.eventCount--;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
DBFlush(0);
//quit
LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR GetBlobSize(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::GetBlobSize(HANDLE hDbEvent)
{
INT_PTR ret;
- struct DBEvent *dbe;
+ DBEvent *dbe;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=-1;
- else ret=dbe->cbBlob;
+ dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ if (dbe->signature!=DBEVENT_SIGNATURE) ret = -1;
+ else ret = dbe->cbBlob;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR GetEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
{
- struct DBEvent *dbe;
- DBEVENTINFO *dbei=(DBEVENTINFO*)lParam;
+ DBEvent *dbe;
int bytesToCopy,i;
- if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 1;
- if(dbei->cbBlob>0 && dbei->pBlob==NULL) {
+ if (dbei == NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 1;
+ if (dbei->cbBlob>0 && dbei->pBlob == NULL) {
dbei->cbBlob = 0;
return 1;
}
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) {
+ dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!=DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- dbei->szModule=GetModuleNameByOfs(dbe->ofsModuleName);
- dbei->timestamp=dbe->timestamp;
- dbei->flags=dbe->flags;
- dbei->eventType=dbe->eventType;
- if(dbei->cbBlob<dbe->cbBlob) bytesToCopy=dbei->cbBlob;
- else bytesToCopy=dbe->cbBlob;
- dbei->cbBlob=dbe->cbBlob;
+ dbei->szModule = GetModuleNameByOfs(dbe->ofsModuleName);
+ dbei->timestamp = dbe->timestamp;
+ dbei->flags = dbe->flags;
+ dbei->eventType = dbe->eventType;
+ if (dbei->cbBlob<dbe->cbBlob) bytesToCopy = dbei->cbBlob;
+ else bytesToCopy = dbe->cbBlob;
+ dbei->cbBlob = dbe->cbBlob;
if (bytesToCopy && dbei->pBlob)
{
- for(i=0;;i+=MAXCACHEDREADSIZE) {
- if(bytesToCopy-i<=MAXCACHEDREADSIZE) {
- CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i);
+ for(i = 0;;i += MAXCACHEDREADSIZE) {
+ if (bytesToCopy-i <= MAXCACHEDREADSIZE) {
+ CopyMemory(dbei->pBlob+i,DBRead(DWORD(hDbEvent)+offsetof(DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i);
break;
}
- CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE);
+ CopyMemory(dbei->pBlob+i,DBRead(DWORD(hDbEvent)+offsetof(DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE);
}
}
LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR MarkEventRead(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
{
INT_PTR ret;
- struct DBEvent *dbe;
- struct DBContact dbc;
+ DBEvent *dbe;
+ DBContact dbc;
DWORD ofsThis;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=*(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- dbe=(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE || dbc.signature!=DBCONTACT_SIGNATURE) {
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ dbc = *(DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!=DBEVENT_SIGNATURE || dbc.signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- if(dbe->flags&DBEF_READ || dbe->flags&DBEF_SENT) {
- ret=(INT_PTR)dbe->flags;
+ if (dbe->flags&DBEF_READ || dbe->flags&DBEF_SENT) {
+ ret = (INT_PTR)dbe->flags;
LeaveCriticalSection(&csDbAccess);
return ret;
}
log1("mark read @ %08x",wParam);
- dbe->flags|=DBEF_READ;
- DBWrite(lParam,dbe,sizeof(struct DBEvent));
- ret=(int)dbe->flags;
- if(dbc.ofsFirstUnreadEvent==(DWORD)lParam) {
+ dbe->flags |= DBEF_READ;
+ DBWrite((DWORD)hDbEvent,dbe,sizeof(DBEvent));
+ ret = (int)dbe->flags;
+ if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
for (;;) {
- if(dbe->ofsNext==0) {
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
+ if (dbe->ofsNext == 0) {
+ dbc.ofsFirstUnreadEvent = 0;
+ dbc.timestampFirstUnread = 0;
break;
}
- ofsThis=dbe->ofsNext;
- dbe=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
+ ofsThis = dbe->ofsNext;
+ dbe = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
if (!(dbe->flags&(DBEF_READ|DBEF_SENT))) {
- dbc.ofsFirstUnreadEvent=ofsThis;
- dbc.timestampFirstUnread=dbe->timestamp;
+ dbc.ofsFirstUnreadEvent = ofsThis;
+ dbc.timestampFirstUnread = dbe->timestamp;
break;
}
}
}
- DBWrite(wParam,&dbc,sizeof(struct DBContact));
+ DBWrite((DWORD)hContact,&dbc,sizeof(DBContact));
DBFlush(0);
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR GetEventContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::GetEventContact(HANDLE hDbEvent)
{
- int ret;
- struct DBEvent *dbe;
-
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) {
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
- return -1;
+ return (HANDLE)-1;
}
- while(!(dbe->flags&DBEF_FIRST))
- dbe=(struct DBEvent*)DBRead(dbe->ofsPrev,sizeof(struct DBEvent),NULL);
- ret=(INT_PTR)dbe->ofsPrev;
+ while(!(dbe->flags & DBEF_FIRST))
+ dbe = (DBEvent*)DBRead(dbe->ofsPrev,sizeof(DBEvent),NULL);
+
+ HANDLE ret = (HANDLE)dbe->ofsPrev;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindFirstEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsFirstEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
+ ret = 0;
+ else
+ ret = (HANDLE)dbc->ofsFirstEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindFirstUnreadEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstUnreadEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsFirstUnreadEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature!=DBCONTACT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbc->ofsFirstUnreadEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindLastEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindLastEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsLastEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature!=DBCONTACT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbc->ofsLastEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindNextEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindNextEvent(HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbe->ofsNext;
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!=DBEVENT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbe->ofsNext;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindPrevEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindPrevEvent(HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=0;
- else if(dbe->flags&DBEF_FIRST) ret=0;
- else ret=(INT_PTR)dbe->ofsPrev;
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!=DBEVENT_SIGNATURE) ret = 0;
+ else if (dbe->flags&DBEF_FIRST) ret = 0;
+ else ret = (HANDLE)dbe->ofsPrev;
LeaveCriticalSection(&csDbAccess);
return ret;
}
@@ -415,28 +413,8 @@ static INT_PTR FindPrevEvent(WPARAM wParam,LPARAM lParam)
int InitEvents(void)
{
- CreateServiceFunction(MS_DB_EVENT_GETCOUNT,GetEventCount);
- CreateServiceFunction(MS_DB_EVENT_ADD,AddEvent);
- CreateServiceFunction(MS_DB_EVENT_DELETE,DeleteEvent);
- CreateServiceFunction(MS_DB_EVENT_GETBLOBSIZE,GetBlobSize);
- CreateServiceFunction(MS_DB_EVENT_GET,GetEvent);
- CreateServiceFunction(MS_DB_EVENT_MARKREAD,MarkEventRead);
- CreateServiceFunction(MS_DB_EVENT_GETCONTACT,GetEventContact);
- CreateServiceFunction(MS_DB_EVENT_FINDFIRST,FindFirstEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDFIRSTUNREAD,FindFirstUnreadEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDLAST,FindLastEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDNEXT,FindNextEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDPREV,FindPrevEvent);
-
hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED);
hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED);
hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
return 0;
}
-
-void UninitEvents(void)
-{
- DestroyHookableEvent(hEventAddedEvent); hEventAddedEvent = 0;
- DestroyHookableEvent(hEventDeletedEvent); hEventDeletedEvent = 0;
- DestroyHookableEvent(hEventFilterAddedEvent); hEventFilterAddedEvent = 0;
-}
diff --git a/plugins/Db3x_mmap/dbheaders.cpp b/plugins/Db3x_mmap/dbheaders.cpp
index 6ae9b33002..a7eede6475 100644
--- a/plugins/Db3x_mmap/dbheaders.cpp
+++ b/plugins/Db3x_mmap/dbheaders.cpp
@@ -27,38 +27,38 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int CreateDbHeaders(HANDLE hFile)
{
- struct DBContact user;
+ DBContact user;
DWORD bytesWritten;
CopyMemory(dbHeader.signature,&dbSignature,sizeof(dbHeader.signature));
- dbHeader.version=DB_THIS_VERSION;
- dbHeader.ofsFileEnd=sizeof(struct DBHeader);
- dbHeader.slackSpace=0;
- dbHeader.contactCount=0;
- dbHeader.ofsFirstContact=0;
- dbHeader.ofsFirstModuleName=0;
- dbHeader.ofsUser=0;
+ dbHeader.version = DB_THIS_VERSION;
+ dbHeader.ofsFileEnd = sizeof(struct DBHeader);
+ dbHeader.slackSpace = 0;
+ dbHeader.contactCount = 0;
+ dbHeader.ofsFirstContact = 0;
+ dbHeader.ofsFirstModuleName = 0;
+ dbHeader.ofsUser = 0;
//create user
- dbHeader.ofsUser=dbHeader.ofsFileEnd;
- dbHeader.ofsFileEnd+=sizeof(struct DBContact);
+ dbHeader.ofsUser = dbHeader.ofsFileEnd;
+ dbHeader.ofsFileEnd += sizeof(DBContact);
SetFilePointer(hFile,0,NULL,FILE_BEGIN);
WriteFile(hFile,&dbHeader,sizeof(dbHeader),&bytesWritten,NULL);
- user.signature=DBCONTACT_SIGNATURE;
- user.ofsNext=0;
- user.ofsFirstSettings=0;
- user.eventCount=0;
- user.ofsFirstEvent=user.ofsLastEvent=0;
+ user.signature = DBCONTACT_SIGNATURE;
+ user.ofsNext = 0;
+ user.ofsFirstSettings = 0;
+ user.eventCount = 0;
+ user.ofsFirstEvent = user.ofsLastEvent = 0;
SetFilePointer(hFile,dbHeader.ofsUser,NULL,FILE_BEGIN);
- WriteFile(hFile,&user,sizeof(struct DBContact),&bytesWritten,NULL);
+ WriteFile(hFile,&user,sizeof(DBContact),&bytesWritten,NULL);
FlushFileBuffers(hFile);
return 0;
}
int CheckDbHeaders(struct DBHeader * hdr)
{
- if(memcmp(hdr->signature,&dbSignature,sizeof(hdr->signature))) return 1;
- if(hdr->version!=DB_THIS_VERSION) return 2;
- if(hdr->ofsUser==0) return 3;
+ if (memcmp(hdr->signature,&dbSignature,sizeof(hdr->signature))) return 1;
+ if (hdr->version!=DB_THIS_VERSION) return 2;
+ if (hdr->ofsUser == 0) return 3;
return 0;
}
diff --git a/plugins/Db3x_mmap/dbmodulechain.cpp b/plugins/Db3x_mmap/dbmodulechain.cpp
index 5ad05b5abd..ce835c3f94 100644
--- a/plugins/Db3x_mmap/dbmodulechain.cpp
+++ b/plugins/Db3x_mmap/dbmodulechain.cpp
@@ -75,12 +75,12 @@ int InitModuleNames(void)
lOfs.sortFunc = (FSortFunc)OfsCompare;
lOfs.increment = 50;
- ofsThis=dbHeader.ofsFirstModuleName;
- dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
+ ofsThis = dbHeader.ofsFirstModuleName;
+ dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
while(ofsThis) {
- if(dbmn->signature!=DBMODULENAME_SIGNATURE) DatabaseCorruption(NULL);
+ if (dbmn->signature != DBMODULENAME_SIGNATURE) DatabaseCorruption(NULL);
- nameLen=dbmn->cbName;
+ nameLen = dbmn->cbName;
mod = (char*)HeapAlloc(hModHeap,0,nameLen+1);
CopyMemory(mod,DBRead(ofsThis+offsetof(struct DBModuleName,name),nameLen,NULL),nameLen);
@@ -88,10 +88,9 @@ int InitModuleNames(void)
AddToList(mod, nameLen, ofsThis);
- ofsThis=dbmn->ofsNext;
- dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
+ ofsThis = dbmn->ofsNext;
+ dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
}
- CreateServiceFunction(MS_DB_MODULES_ENUM,EnumModuleNames);
return 0;
}
@@ -131,17 +130,17 @@ DWORD GetModuleNameOfs(const char *szName)
DWORD ofsNew,ofsExisting;
char *mod;
- ofsExisting=FindExistingModuleNameOfs(szName);
- if(ofsExisting) return ofsExisting;
+ ofsExisting = FindExistingModuleNameOfs(szName);
+ if (ofsExisting) return ofsExisting;
nameLen = (int)strlen(szName);
//need to create the module name
- ofsNew=CreateNewSpace(nameLen+offsetof(struct DBModuleName,name));
- dbmn.signature=DBMODULENAME_SIGNATURE;
- dbmn.cbName=nameLen;
- dbmn.ofsNext=dbHeader.ofsFirstModuleName;
- dbHeader.ofsFirstModuleName=ofsNew;
+ ofsNew = CreateNewSpace(nameLen+offsetof(struct DBModuleName,name));
+ dbmn.signature = DBMODULENAME_SIGNATURE;
+ dbmn.cbName = nameLen;
+ dbmn.ofsNext = dbHeader.ofsFirstModuleName;
+ dbHeader.ofsFirstModuleName = ofsNew;
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBWrite(ofsNew,&dbmn,offsetof(struct DBModuleName,name));
DBWrite(ofsNew+offsetof(struct DBModuleName,name),(PVOID)szName,nameLen);
@@ -178,15 +177,15 @@ char *GetModuleNameByOfs(DWORD ofs)
return NULL;
}
-static INT_PTR EnumModuleNames(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
{
- int i;
int ret;
ModuleName *pmn;
- for(i = 0; i < lMods.realCount; i++) {
+ for(int i = 0; i < lMods.realCount; i++) {
pmn = (ModuleName *)lMods.items[i];
- ret=((DBMODULEENUMPROC)lParam)(pmn->name,pmn->ofs,wParam);
- if(ret) return ret;
+ ret = pFunc(pmn->name, pmn->ofs, (LPARAM)pParam);
+ if (ret)
+ return ret;
}
return 0;
}
diff --git a/plugins/Db3x_mmap/dbsettings.cpp b/plugins/Db3x_mmap/dbsettings.cpp
index 5bdc0707f6..d55f71d189 100644
--- a/plugins/Db3x_mmap/dbsettings.cpp
+++ b/plugins/Db3x_mmap/dbsettings.cpp
@@ -33,29 +33,29 @@ SortedList lContacts = {0};
HANDLE hLastCachedContact = NULL;
static DBCachedContactValueList *LastVL = NULL;
-static SortedList lSettings={0}, lGlobalSettings={0}, lResidentSettings={0};
+static SortedList lSettings = {0}, lGlobalSettings = {0}, lResidentSettings = {0};
static HANDLE hSettingChangeEvent = NULL;
-static DWORD GetSettingsGroupOfsByModuleNameOfs(struct DBContact *dbc,DWORD ofsModuleName)
+static DWORD GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsModuleName)
{
struct DBContactSettings *dbcs;
DWORD ofsThis;
- ofsThis=dbc->ofsFirstSettings;
+ ofsThis = dbc->ofsFirstSettings;
while(ofsThis) {
- dbcs=(struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
- if(dbcs->signature!=DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL);
- if(dbcs->ofsModuleName==ofsModuleName)
+ dbcs = (struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
+ if (dbcs->signature!=DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL);
+ if (dbcs->ofsModuleName == ofsModuleName)
return ofsThis;
- ofsThis=dbcs->ofsNext;
+ ofsThis = dbcs->ofsNext;
}
return 0;
}
static DWORD __inline GetSettingValueLength(PBYTE pSetting)
{
- if(pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1);
+ if (pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1);
return pSetting[0];
}
@@ -75,7 +75,7 @@ static char* GetCachedSetting(const char *szModuleName,const char *szSettingName
char szFullName[512];
strcpy(szFullName+1,szModuleName);
- szFullName[moduleNameLen+1]='/';
+ szFullName[moduleNameLen+1] = '/';
strcpy(szFullName+moduleNameLen+2,szSettingName);
if (lastsetting && strcmp(szFullName+1,lastsetting) == 0)
@@ -152,11 +152,11 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
DBCachedContactValue *V, *V1;
DBCachedContactValueList VLtemp,*VL;
- if (hLastCachedContact==hContact && LastVL) {
+ if (hLastCachedContact == hContact && LastVL) {
VL = LastVL;
}
else {
- VLtemp.hContact=hContact;
+ VLtemp.hContact = hContact;
if ( !List_GetIndex(&lContacts,&VLtemp,&index))
{
@@ -210,12 +210,12 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
return &V->value;
} }
-#define NeedBytes(n) if(bytesRemaining<(n)) pBlob=(PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining)
-#define MoveAlong(n) {int x=n; pBlob+=(x); ofsBlobPtr+=(x); bytesRemaining-=(x);}
-#define VLT(n) ((n==DBVT_UTF8)?DBVT_ASCIIZ:n)
+#define NeedBytes(n) if (bytesRemaining<(n)) pBlob = (PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining)
+#define MoveAlong(n) {int x = n; pBlob += (x); ofsBlobPtr += (x); bytesRemaining -= (x);}
+#define VLT(n) ((n == DBVT_UTF8)?DBVT_ASCIIZ:n)
static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic)
{
- struct DBContact *dbc;
+ DBContact *dbc;
DWORD ofsModuleName,ofsContact,ofsSettingsGroup,ofsBlobPtr;
int settingNameLen,moduleNameLen;
int bytesRemaining;
@@ -225,8 +225,8 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
if ((!dbcgs->szSetting) || (!dbcgs->szModule))
return 1;
// the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
- settingNameLen=(int)strlen(dbcgs->szSetting);
- moduleNameLen=(int)strlen(dbcgs->szModule);
+ settingNameLen = (int)strlen(dbcgs->szSetting);
+ moduleNameLen = (int)strlen(dbcgs->szModule);
if ( settingNameLen > 0xFE )
{
#ifdef _DEBUG
@@ -261,10 +261,10 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
cbOrigLen--;
dbcgs->pValue->pszVal = cbOrigPtr;
- if(cbLen<cbOrigLen) cbOrigLen=cbLen;
+ if (cbLen<cbOrigLen) cbOrigLen = cbLen;
CopyMemory(dbcgs->pValue->pszVal,pCachedValue->pszVal,cbOrigLen);
- dbcgs->pValue->pszVal[cbOrigLen]=0;
- dbcgs->pValue->cchVal=cbLen;
+ dbcgs->pValue->pszVal[cbOrigLen] = 0;
+ dbcgs->pValue->cchVal = cbLen;
}
else {
dbcgs->pValue->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal)+1);
@@ -287,64 +287,64 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
return ( pCachedValue->type == DBVT_DELETED ) ? 1 : 0;
} }
- ofsModuleName=GetModuleNameOfs(dbcgs->szModule);
- if(hContact==NULL) ofsContact=dbHeader.ofsUser;
- else ofsContact=(DWORD)hContact;
- dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ ofsModuleName = GetModuleNameOfs(dbcgs->szModule);
+ if (hContact == NULL) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ dbc = (DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc->signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
- if(ofsSettingsGroup) {
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
+ if (ofsSettingsGroup) {
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
pBlob = DBRead(ofsBlobPtr,sizeof(struct DBContactSettings),&bytesRemaining);
while(pBlob[0]) {
NeedBytes(1+settingNameLen);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) {
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) {
MoveAlong(1+settingNameLen);
NeedBytes(5);
- if(isStatic && pBlob[0]&DBVTF_VARIABLELENGTH && VLT(dbcgs->pValue->type) != VLT(pBlob[0])) {
+ if (isStatic && pBlob[0]&DBVTF_VARIABLELENGTH && VLT(dbcgs->pValue->type) != VLT(pBlob[0])) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- dbcgs->pValue->type=pBlob[0];
+ dbcgs->pValue->type = pBlob[0];
switch(pBlob[0]) {
case DBVT_DELETED: { /* this setting is deleted */
- dbcgs->pValue->type=DBVT_DELETED;
+ dbcgs->pValue->type = DBVT_DELETED;
LeaveCriticalSection(&csDbAccess);
return 2;
}
- case DBVT_BYTE: dbcgs->pValue->bVal=pBlob[1]; break;
- case DBVT_WORD: dbcgs->pValue->wVal=*(PWORD)(pBlob+1); break;
- case DBVT_DWORD: dbcgs->pValue->dVal=*(PDWORD)(pBlob+1); break;
+ case DBVT_BYTE: dbcgs->pValue->bVal = pBlob[1]; break;
+ case DBVT_WORD: dbcgs->pValue->wVal = *(PWORD)(pBlob+1); break;
+ case DBVT_DWORD: dbcgs->pValue->dVal = *(PDWORD)(pBlob+1); break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
NeedBytes(3+*(PWORD)(pBlob+1));
- if(isStatic) {
+ if (isStatic) {
dbcgs->pValue->cchVal--;
- if (*(PWORD)(pBlob+1)<dbcgs->pValue->cchVal) dbcgs->pValue->cchVal=*(PWORD)(pBlob+1);
+ if (*(PWORD)(pBlob+1)<dbcgs->pValue->cchVal) dbcgs->pValue->cchVal = *(PWORD)(pBlob+1);
CopyMemory(dbcgs->pValue->pszVal,pBlob+3,dbcgs->pValue->cchVal);
- dbcgs->pValue->pszVal[dbcgs->pValue->cchVal]=0;
- dbcgs->pValue->cchVal=*(PWORD)(pBlob+1);
+ dbcgs->pValue->pszVal[dbcgs->pValue->cchVal] = 0;
+ dbcgs->pValue->cchVal = *(PWORD)(pBlob+1);
}
else {
- dbcgs->pValue->pszVal=(char*)mir_alloc(1+*(PWORD)(pBlob+1));
+ dbcgs->pValue->pszVal = (char*)mir_alloc(1+*(PWORD)(pBlob+1));
CopyMemory(dbcgs->pValue->pszVal,pBlob+3,*(PWORD)(pBlob+1));
- dbcgs->pValue->pszVal[*(PWORD)(pBlob+1)]=0;
+ dbcgs->pValue->pszVal[*(PWORD)(pBlob+1)] = 0;
}
break;
case DBVT_BLOB:
NeedBytes(3+*(PWORD)(pBlob+1));
- if(isStatic) {
- if (*(PWORD)(pBlob+1)<dbcgs->pValue->cpbVal) dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1);
+ if (isStatic) {
+ if (*(PWORD)(pBlob+1)<dbcgs->pValue->cpbVal) dbcgs->pValue->cpbVal = *(PWORD)(pBlob+1);
CopyMemory(dbcgs->pValue->pbVal,pBlob+3,dbcgs->pValue->cpbVal);
}
else {
- dbcgs->pValue->pbVal=(BYTE *)mir_alloc(*(PWORD)(pBlob+1));
+ dbcgs->pValue->pbVal = (BYTE *)mir_alloc(*(PWORD)(pBlob+1));
CopyMemory(dbcgs->pValue->pbVal,pBlob+3,*(PWORD)(pBlob+1));
}
- dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1);
+ dbcgs->pValue->cpbVal = *(PWORD)(pBlob+1);
break;
}
@@ -380,11 +380,10 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
return 1;
}
-static INT_PTR GetContactSetting(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = ( DBCONTACTGETSETTING* )lParam;
dgs->pValue->type = 0;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 0 ))
+ if ( GetContactSettingWorker(hContact, dgs, 0 ))
return 1;
if ( dgs->pValue->type == DBVT_UTF8 ) {
@@ -415,12 +414,11 @@ static INT_PTR GetContactSetting(WPARAM wParam,LPARAM lParam)
return 0;
}
-static INT_PTR GetContactSettingStr(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStr(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = (DBCONTACTGETSETTING*)lParam;
int iSaveType = dgs->pValue->type;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 0 ))
+ if ( GetContactSettingWorker(hContact, dgs, 0 ))
return 1;
if ( iSaveType == 0 || iSaveType == dgs->pValue->type )
@@ -463,10 +461,9 @@ static INT_PTR GetContactSettingStr(WPARAM wParam,LPARAM lParam)
return 0;
}
-INT_PTR GetContactSettingStatic(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStatic(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = (DBCONTACTGETSETTING*)lParam;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 1 ))
+ if ( GetContactSettingWorker(hContact, dgs, 1 ))
return 1;
if ( dgs->pValue->type == DBVT_UTF8 ) {
@@ -477,9 +474,8 @@ INT_PTR GetContactSettingStatic(WPARAM wParam,LPARAM lParam)
return 0;
}
-static INT_PTR FreeVariant(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::FreeVariant(DBVARIANT *dbv)
{
- DBVARIANT *dbv=(DBVARIANT*)lParam;
if ( dbv == 0 ) return 1;
switch ( dbv->type ) {
case DBVT_ASCIIZ:
@@ -487,29 +483,29 @@ static INT_PTR FreeVariant(WPARAM wParam,LPARAM lParam)
case DBVT_WCHAR:
{
if ( dbv->pszVal ) mir_free(dbv->pszVal);
- dbv->pszVal=0;
+ dbv->pszVal = 0;
break;
}
case DBVT_BLOB:
{
if ( dbv->pbVal ) mir_free(dbv->pbVal);
- dbv->pbVal=0;
+ dbv->pbVal = 0;
break;
}
}
- dbv->type=0;
+ dbv->type = 0;
return 0;
}
-static INT_PTR SetSettingResident(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::SetSettingResident(BOOL bIsResident, const char *pszSettingName)
{
- size_t cbSettingNameLen = strlen(( char* )lParam) + 2;
+ size_t cbSettingNameLen = strlen(pszSettingName) + 2;
if (cbSettingNameLen < 512)
{
char* szSetting;
int idx;
char szTemp[512];
- strcpy( szTemp+1, ( char* )lParam );
+ strcpy( szTemp+1, pszSettingName);
EnterCriticalSection(&csDbAccess);
if ( !List_GetIndex( &lSettings, szTemp, &idx ))
@@ -517,14 +513,14 @@ static INT_PTR SetSettingResident(WPARAM wParam,LPARAM lParam)
else
szSetting = (char *)lSettings.items[idx];
- *szSetting = (char)wParam;
+ *szSetting = (char)bIsResident;
if ( !List_GetIndex( &lResidentSettings, szSetting+1, &idx ))
{
- if (wParam)
+ if (bIsResident)
List_Insert(&lResidentSettings,szSetting+1,idx);
}
- else if (!wParam)
+ else if (!bIsResident)
List_Remove(&lResidentSettings,idx);
LeaveCriticalSection(&csDbAccess);
@@ -532,26 +528,25 @@ static INT_PTR SetSettingResident(WPARAM wParam,LPARAM lParam)
return 0;
}
-static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
{
- DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam;
DBCONTACTWRITESETTING tmp;
- struct DBContact dbc;
+ DBContact dbc;
DWORD ofsModuleName;
struct DBContactSettings dbcs;
PBYTE pBlob;
- int settingNameLen=0;
- int moduleNameLen=0;
- int settingDataLen=0;
+ int settingNameLen = 0;
+ int moduleNameLen = 0;
+ int settingDataLen = 0;
int bytesRequired,bytesRemaining;
DWORD ofsContact,ofsSettingsGroup,ofsBlobPtr;
- if (dbcws == NULL || dbcws->szSetting==NULL || dbcws->szModule==NULL )
+ if (dbcws == NULL || dbcws->szSetting == NULL || dbcws->szModule == NULL )
return 1;
// the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
- settingNameLen=(int)strlen(dbcws->szSetting);
- moduleNameLen=(int)strlen(dbcws->szModule);
+ settingNameLen = (int)strlen(dbcws->szSetting);
+ moduleNameLen = (int)strlen(dbcws->szModule);
if ( settingNameLen > 0xFE )
{
#ifdef _DEBUG
@@ -583,7 +578,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
else return 1;
}
- if(tmp.value.type!=DBVT_BYTE && tmp.value.type!=DBVT_WORD && tmp.value.type!=DBVT_DWORD && tmp.value.type!=DBVT_ASCIIZ && tmp.value.type!=DBVT_UTF8 && tmp.value.type!=DBVT_BLOB)
+ if (tmp.value.type!=DBVT_BYTE && tmp.value.type!=DBVT_WORD && tmp.value.type!=DBVT_DWORD && tmp.value.type!=DBVT_ASCIIZ && tmp.value.type!=DBVT_UTF8 && tmp.value.type!=DBVT_BLOB)
return 1;
if ((!tmp.szModule) || (!tmp.szSetting) || ((tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8 )&& tmp.value.pszVal == NULL) || (tmp.value.type == DBVT_BLOB && tmp.value.pbVal == NULL))
return 1;
@@ -605,7 +600,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
{
char* szCachedSettingName = GetCachedSetting(tmp.szModule, tmp.szSetting, moduleNameLen, settingNameLen);
if ( tmp.value.type != DBVT_BLOB ) {
- DBVARIANT* pCachedValue = GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, 1);
+ DBVARIANT* pCachedValue = GetCachedValuePtr(hContact, szCachedSettingName, 1);
if ( pCachedValue != NULL ) {
BOOL bIsIdentical = FALSE;
if ( pCachedValue->type == tmp.value.type ) {
@@ -625,53 +620,53 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
}
if ( szCachedSettingName[-1] != 0 ) {
LeaveCriticalSection(&csDbAccess);
- NotifyEventHooks(hSettingChangeEvent,wParam,(LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
return 0;
}
}
- else GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, -1);
+ else GetCachedValuePtr(hContact, szCachedSettingName, -1);
}
- ofsModuleName=GetModuleNameOfs(tmp.szModule);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
+ ofsModuleName = GetModuleNameOfs(tmp.szModule);
+ if (hContact == 0) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE) {
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc.signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
log0("write setting");
//make sure the module group exists
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsModuleName);
- if(ofsSettingsGroup==0) { //module group didn't exist - make it
- if(tmp.value.type&DBVTF_VARIABLELENGTH) {
- if(tmp.value.type==DBVT_ASCIIZ || tmp.value.type==DBVT_UTF8) bytesRequired=(int)strlen(tmp.value.pszVal)+2;
- else if(tmp.value.type==DBVT_BLOB) bytesRequired=tmp.value.cpbVal+2;
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsModuleName);
+ if (ofsSettingsGroup == 0) { //module group didn't exist - make it
+ if (tmp.value.type&DBVTF_VARIABLELENGTH) {
+ if (tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2;
+ else if (tmp.value.type == DBVT_BLOB) bytesRequired = tmp.value.cpbVal+2;
}
- else bytesRequired=tmp.value.type;
- bytesRequired+=2+settingNameLen;
- bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
- ofsSettingsGroup=CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
- dbcs.signature=DBCONTACTSETTINGS_SIGNATURE;
- dbcs.ofsNext=dbc.ofsFirstSettings;
- dbcs.ofsModuleName=ofsModuleName;
- dbcs.cbBlob=bytesRequired;
- dbcs.blob[0]=0;
- dbc.ofsFirstSettings=ofsSettingsGroup;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ else bytesRequired = tmp.value.type;
+ bytesRequired += 2+settingNameLen;
+ bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
+ ofsSettingsGroup = CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
+ dbcs.signature = DBCONTACTSETTINGS_SIGNATURE;
+ dbcs.ofsNext = dbc.ofsFirstSettings;
+ dbcs.ofsModuleName = ofsModuleName;
+ dbcs.cbBlob = bytesRequired;
+ dbcs.blob[0] = 0;
+ dbc.ofsFirstSettings = ofsSettingsGroup;
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
DBWrite(ofsSettingsGroup,&dbcs,sizeof(struct DBContactSettings));
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
else {
- dbcs=*(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
+ dbcs = *(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
//find if the setting exists
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(settingNameLen+1);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,tmp.szSetting,settingNameLen))
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,tmp.szSetting,settingNameLen))
break;
NeedBytes(1);
MoveAlong(pBlob[0]+1);
@@ -679,18 +674,18 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
MoveAlong(1+GetSettingValueLength(pBlob));
NeedBytes(1);
}
- if(pBlob[0]) { //setting already existed, and up to end of name is in cache
+ if (pBlob[0]) { //setting already existed, and up to end of name is in cache
MoveAlong(1+settingNameLen);
//if different type or variable length and length is different
NeedBytes(3);
- if(pBlob[0]!=tmp.value.type || ((pBlob[0]==DBVT_ASCIIZ || pBlob[0]==DBVT_UTF8) && *(PWORD)(pBlob+1)!=strlen(tmp.value.pszVal)) || (pBlob[0]==DBVT_BLOB && *(PWORD)(pBlob+1)!=tmp.value.cpbVal)) {
+ if (pBlob[0]!=tmp.value.type || ((pBlob[0] == DBVT_ASCIIZ || pBlob[0] == DBVT_UTF8) && *(PWORD)(pBlob+1)!=strlen(tmp.value.pszVal)) || (pBlob[0] == DBVT_BLOB && *(PWORD)(pBlob+1)!=tmp.value.cpbVal)) {
//bin it
int nameLen,valLen;
DWORD ofsSettingToCut;
NeedBytes(3);
- nameLen=1+settingNameLen;
- valLen=1+GetSettingValueLength(pBlob);
- ofsSettingToCut=ofsBlobPtr-nameLen;
+ nameLen = 1+settingNameLen;
+ valLen = 1+GetSettingValueLength(pBlob);
+ ofsSettingToCut = ofsBlobPtr-nameLen;
MoveAlong(valLen);
NeedBytes(1);
while(pBlob[0]) {
@@ -700,8 +695,8 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
NeedBytes(1);
}
DBMoveChunk(ofsSettingToCut,ofsSettingToCut+nameLen+valLen,ofsBlobPtr+1-ofsSettingToCut);
- ofsBlobPtr-=nameLen+valLen;
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr -= nameLen+valLen;
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
else {
//replace existing setting at pBlob
@@ -718,7 +713,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
//notify
- NotifyEventHooks(hSettingChangeEvent,wParam,(LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
return 0;
}
}
@@ -726,49 +721,49 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
//cannot do a simple replace, add setting to end of list
//pBlob already points to end of list
//see if it fits
- if(tmp.value.type&DBVTF_VARIABLELENGTH) {
- if(tmp.value.type==DBVT_ASCIIZ || tmp.value.type==DBVT_UTF8) bytesRequired=(int)strlen(tmp.value.pszVal)+2;
- else if(tmp.value.type==DBVT_BLOB) bytesRequired=tmp.value.cpbVal+2;
+ if (tmp.value.type&DBVTF_VARIABLELENGTH) {
+ if (tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2;
+ else if (tmp.value.type == DBVT_BLOB) bytesRequired = tmp.value.cpbVal+2;
}
- else bytesRequired=tmp.value.type;
- bytesRequired+=2+settingNameLen;
- bytesRequired+=ofsBlobPtr+1-(ofsSettingsGroup+offsetof(struct DBContactSettings,blob));
+ else bytesRequired = tmp.value.type;
+ bytesRequired += 2+settingNameLen;
+ bytesRequired += ofsBlobPtr+1-(ofsSettingsGroup+offsetof(struct DBContactSettings,blob));
if ((DWORD)bytesRequired>dbcs.cbBlob) {
//doesn't fit: move entire group
struct DBContactSettings *dbcsPrev;
DWORD ofsDbcsPrev,ofsNew;
- bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
+ bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
//find previous group to change its offset
- ofsDbcsPrev=dbc.ofsFirstSettings;
- if(ofsDbcsPrev==ofsSettingsGroup) ofsDbcsPrev=0;
+ ofsDbcsPrev = dbc.ofsFirstSettings;
+ if (ofsDbcsPrev == ofsSettingsGroup) ofsDbcsPrev = 0;
else {
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
while(dbcsPrev->ofsNext!=ofsSettingsGroup) {
- if(dbcsPrev->ofsNext==0) DatabaseCorruption(NULL);
- ofsDbcsPrev=dbcsPrev->ofsNext;
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ if (dbcsPrev->ofsNext == 0) DatabaseCorruption(NULL);
+ ofsDbcsPrev = dbcsPrev->ofsNext;
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
}
}
//create the new one
- ofsNew=ReallocSpace(ofsSettingsGroup, dbcs.cbBlob+offsetof(struct DBContactSettings,blob), bytesRequired+offsetof(struct DBContactSettings,blob));
+ ofsNew = ReallocSpace(ofsSettingsGroup, dbcs.cbBlob+offsetof(struct DBContactSettings,blob), bytesRequired+offsetof(struct DBContactSettings,blob));
- dbcs.cbBlob=bytesRequired;
+ dbcs.cbBlob = bytesRequired;
DBWrite(ofsNew,&dbcs,offsetof(struct DBContactSettings,blob));
- if(ofsDbcsPrev==0) {
- dbc.ofsFirstSettings=ofsNew;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ if (ofsDbcsPrev == 0) {
+ dbc.ofsFirstSettings = ofsNew;
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
}
else {
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
- dbcsPrev->ofsNext=ofsNew;
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ dbcsPrev->ofsNext = ofsNew;
DBWrite(ofsDbcsPrev,dbcsPrev,offsetof(struct DBContactSettings,blob));
}
- ofsBlobPtr+=ofsNew-ofsSettingsGroup;
- ofsSettingsGroup=ofsNew;
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr += ofsNew-ofsSettingsGroup;
+ ofsSettingsGroup = ofsNew;
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
//we now have a place to put it and enough space: make it
DBWrite(ofsBlobPtr,&settingNameLen,1);
@@ -782,7 +777,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
case DBVT_DWORD: DBWrite(ofsBlobPtr,&tmp.value.dVal,4); MoveAlong(4); break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
- { int len=(int)strlen(tmp.value.pszVal);
+ { int len = (int)strlen(tmp.value.pszVal);
DBWrite(ofsBlobPtr,&len,2);
DBWrite(ofsBlobPtr+2,tmp.value.pszVal,len);
MoveAlong(2+len);
@@ -794,32 +789,31 @@ static INT_PTR WriteContactSetting(WPARAM wParam,LPARAM lParam)
MoveAlong(2+tmp.value.cpbVal);
break;
}
- { BYTE zero=0;
+ { BYTE zero = 0;
DBWrite(ofsBlobPtr,&zero,1);
}
//quit
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
//notify
- NotifyEventHooks(hSettingChangeEvent, wParam, (LPARAM)&tmp );
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp );
return 0;
}
-static INT_PTR DeleteContactSetting(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::DeleteContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
{
- DBCONTACTGETSETTING *dbcgs=(DBCONTACTGETSETTING*)lParam;
- struct DBContact *dbc;
+ DBContact *dbc;
DWORD ofsModuleName,ofsSettingsGroup,ofsBlobPtr;
PBYTE pBlob;
int settingNameLen,moduleNameLen,bytesRemaining;
char* szCachedSettingName;
- WPARAM saveWparam = wParam;
+ WPARAM saveWparam = (WPARAM)hContact;
if ((!dbcgs->szModule) || (!dbcgs->szSetting))
return 1;
// the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
- settingNameLen=(int)strlen(dbcgs->szSetting);
- moduleNameLen=(int)strlen(dbcgs->szModule);
+ settingNameLen = (int)strlen(dbcgs->szSetting);
+ moduleNameLen = (int)strlen(dbcgs->szModule);
if ( settingNameLen > 0xFE )
{
#ifdef _DEBUG
@@ -836,26 +830,27 @@ static INT_PTR DeleteContactSetting(WPARAM wParam,LPARAM lParam)
}
EnterCriticalSection(&csDbAccess);
- ofsModuleName=GetModuleNameOfs(dbcgs->szModule);
- if(wParam==0) wParam=dbHeader.ofsUser;
+ ofsModuleName = GetModuleNameOfs(dbcgs->szModule);
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
//make sure the module group exists
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
- if(ofsSettingsGroup==0) {
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
+ if (ofsSettingsGroup == 0) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
//find if the setting exists
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(settingNameLen+1);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen))
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen))
break;
NeedBytes(1);
MoveAlong(pBlob[0]+1);
@@ -872,9 +867,9 @@ static INT_PTR DeleteContactSetting(WPARAM wParam,LPARAM lParam)
DWORD ofsSettingToCut;
MoveAlong(1+settingNameLen);
NeedBytes(3);
- nameLen=1+settingNameLen;
- valLen=1+GetSettingValueLength(pBlob);
- ofsSettingToCut=ofsBlobPtr-nameLen;
+ nameLen = 1+settingNameLen;
+ valLen = 1+GetSettingValueLength(pBlob);
+ ofsSettingToCut = ofsBlobPtr-nameLen;
MoveAlong(valLen);
NeedBytes(1);
while(pBlob[0]) {
@@ -893,19 +888,18 @@ static INT_PTR DeleteContactSetting(WPARAM wParam,LPARAM lParam)
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
{ //notify
- DBCONTACTWRITESETTING dbcws={0};
- dbcws.szModule=dbcgs->szModule;
- dbcws.szSetting=dbcgs->szSetting;
- dbcws.value.type=DBVT_DELETED;
+ DBCONTACTWRITESETTING dbcws = {0};
+ dbcws.szModule = dbcgs->szModule;
+ dbcws.szSetting = dbcgs->szSetting;
+ dbcws.value.type = DBVT_DELETED;
NotifyEventHooks(hSettingChangeEvent,saveWparam,(LPARAM)&dbcws);
}
return 0;
}
-static INT_PTR EnumContactSettings(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces)
{
- DBCONTACTENUMSETTINGS *dbces=(DBCONTACTENUMSETTINGS*)lParam;
- struct DBContact *dbc;
+ DBContact *dbc;
DWORD ofsModuleName,ofsContact,ofsBlobPtr;
int bytesRemaining, result;
PBYTE pBlob;
@@ -916,22 +910,22 @@ static INT_PTR EnumContactSettings(WPARAM wParam,LPARAM lParam)
EnterCriticalSection(&csDbAccess);
- ofsModuleName=GetModuleNameOfs(dbces->szModule);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
- dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ ofsModuleName = GetModuleNameOfs(dbces->szModule);
+ if (hContact == 0) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ dbc = (DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- dbces->ofsSettings=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
+ dbces->ofsSettings = GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
if (!dbces->ofsSettings) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- ofsBlobPtr=dbces->ofsSettings+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
- if(pBlob[0]==0) {
+ ofsBlobPtr = dbces->ofsSettings+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ if (pBlob[0] == 0) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
@@ -939,7 +933,7 @@ static INT_PTR EnumContactSettings(WPARAM wParam,LPARAM lParam)
while(pBlob[0]) {
NeedBytes(1);
NeedBytes(1+pBlob[0]);
- CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]]=0;
+ CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]] = 0;
result = (dbces->pfnEnumProc)(szSetting,dbces->lParam);
MoveAlong(1+pBlob[0]);
NeedBytes(3);
@@ -950,13 +944,11 @@ static INT_PTR EnumContactSettings(WPARAM wParam,LPARAM lParam)
return result;
}
-static INT_PTR EnumResidentSettings(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
{
- int i;
- int ret;
- for(i = 0; i < lResidentSettings.realCount; i++) {
- ret=((DBMODULEENUMPROC)lParam)((char *)lResidentSettings.items[i], 0, wParam);
- if(ret) return ret;
+ for(int i = 0; i < lResidentSettings.realCount; i++) {
+ int ret = pFunc((char *)lResidentSettings.items[i], 0, (LPARAM)pParam);
+ if (ret) return ret;
}
return 0;
}
@@ -977,16 +969,6 @@ static int stringCompare2( char* p1, char* p2 )
int InitSettings(void)
{
- CreateServiceFunction(MS_DB_CONTACT_GETSETTING,GetContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_GETSETTING_STR,GetContactSettingStr);
- CreateServiceFunction(MS_DB_CONTACT_GETSETTINGSTATIC,GetContactSettingStatic);
- CreateServiceFunction(MS_DB_CONTACT_FREEVARIANT,FreeVariant);
- CreateServiceFunction(MS_DB_CONTACT_WRITESETTING,WriteContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_DELETESETTING,DeleteContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_ENUMSETTINGS,EnumContactSettings);
- CreateServiceFunction(MS_DB_SETSETTINGRESIDENT,SetSettingResident);
- CreateServiceFunction("DB/ResidentSettings/Enum",EnumResidentSettings);
-
hSettingChangeEvent = CreateHookableEvent(ME_DB_CONTACT_SETTINGCHANGED);
hCacheHeap = HeapCreate(0, 0, 0);
diff --git a/plugins/Db3x_mmap/init.cpp b/plugins/Db3x_mmap/init.cpp
index dbb83d76ab..b655e61499 100644
--- a/plugins/Db3x_mmap/init.cpp
+++ b/plugins/Db3x_mmap/init.cpp
@@ -25,15 +25,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int hLangpack;
-extern char szDbPath[MAX_PATH];
+extern TCHAR szDbPath[MAX_PATH];
-static PLUGININFOEX pluginInfo = {
+CDdxMmap* g_Db = NULL;
+
+static PLUGININFOEX pluginInfo =
+{
sizeof(PLUGININFOEX),
"Miranda mmap database driver",
__VERSION_DWORD,
"Provides Miranda database support: global settings, contacts, history, settings per contact.",
"Miranda-IM project",
- "bio@msx.ru; ghazan@miranda-im.org",
+ "bio@msx.ru; ghazan@miranda.im",
"Copyright 2000-2011 Miranda IM project",
"",
UNICODE_AWARE,
@@ -48,43 +51,43 @@ static int getCapability( int flag )
}
// returns 0 if the profile is created, EMKPRF*
-static int makeDatabase(char * profile, int * error)
+static int makeDatabase(TCHAR *profile, int *error)
{
- HANDLE hFile = CreateFileA(profile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+ HANDLE hFile = CreateFile(profile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
if ( hFile != INVALID_HANDLE_VALUE ) {
CreateDbHeaders(hFile);
CloseHandle(hFile);
return 0;
}
- if ( error != NULL ) *error=EMKPRF_CREATEFAILED;
+ if ( error != NULL ) *error = EMKPRF_CREATEFAILED;
return 1;
}
// returns 0 if the given profile has a valid header
-static int grokHeader( char * profile, int * error )
+static int grokHeader(TCHAR *profile, int *error)
{
- int rc=1;
- int chk=0;
+ int rc = 1;
+ int chk = 0;
struct DBHeader hdr;
HANDLE hFile = INVALID_HANDLE_VALUE;
- DWORD dummy=0;
+ DWORD dummy = 0;
- hFile = CreateFileA(profile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ hFile = CreateFile(profile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if ( hFile == INVALID_HANDLE_VALUE ) {
- if ( error != NULL ) *error=EGROKPRF_CANTREAD;
+ if ( error != NULL ) *error = EGROKPRF_CANTREAD;
return 1;
}
// read the header, which can fail (for various reasons)
if ( !ReadFile(hFile, &hdr, sizeof(struct DBHeader), &dummy, NULL)) {
- if ( error != NULL) *error=EGROKPRF_CANTREAD;
+ if ( error != NULL) *error = EGROKPRF_CANTREAD;
CloseHandle(hFile);
return 1;
}
- chk=CheckDbHeaders(&hdr);
+ chk = CheckDbHeaders(&hdr);
if ( chk == 0 ) {
// all the internal tests passed, hurrah
- rc=0;
- if ( error != NULL ) *error=0;
+ rc = 0;
+ if ( error != NULL ) *error = 0;
} else {
// didn't pass at all, or some did.
switch ( chk ) {
@@ -97,13 +100,13 @@ static int grokHeader( char * profile, int * error )
case 2:
{
// header was present, but version information newer
- if ( error != NULL ) *error= EGROKPRF_VERNEWER;
+ if ( error != NULL ) *error = EGROKPRF_VERNEWER;
break;
}
case 3:
{
// header/version OK, internal data missing
- if ( error != NULL ) *error=EGROKPRF_DAMAGED;
+ if ( error != NULL ) *error = EGROKPRF_DAMAGED;
break;
}
} // switch
@@ -113,16 +116,21 @@ static int grokHeader( char * profile, int * error )
}
// returns 0 if all the APIs are injected otherwise, 1
-static int LoadDatabase(char * profile)
+static MIDatabase* LoadDatabase(TCHAR *profile)
{
+ if (g_Db) delete g_Db;
+ g_Db = new CDdxMmap(profile);
+
// don't need thread notifications
- strncpy(szDbPath, profile, sizeof(szDbPath));
+ _tcsncpy(szDbPath, profile, SIZEOF(szDbPath));
// set the memory, lists & UTF8 manager
mir_getLP( &pluginInfo );
// inject all APIs and hooks into the core
- return LoadDatabaseModule();
+ LoadDatabaseModule();
+
+ return g_Db;
}
static int UnloadDatabase(int wasLoaded)
@@ -132,9 +140,9 @@ static int UnloadDatabase(int wasLoaded)
return 0;
}
-static int getFriendlyName( char * buf, size_t cch, int shortName )
+static int getFriendlyName( TCHAR *buf, size_t cch, int shortName )
{
- strncpy(buf,shortName ? "db3x mmap driver" : "db3x mmap database support",cch);
+ _tcsncpy(buf,shortName ? _T("db3x mmap driver") : _T("db3x mmap database support"), cch);
return 0;
}
@@ -150,7 +158,7 @@ static DATABASELINK dblink = {
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID reserved)
{
- g_hInst=hInstDLL;
+ g_hInst = hInstDLL;
return TRUE;
}
@@ -174,4 +182,4 @@ extern "C" __declspec(dllexport) int Load(void)
extern "C" __declspec(dllexport) int Unload(void)
{
return 0;
-} \ No newline at end of file
+}
diff --git a/plugins/Dbx_mmap_SA/commonheaders.h b/plugins/Dbx_mmap_SA/commonheaders.h
index cfa7ff2d2e..56a9d54ddd 100644
--- a/plugins/Dbx_mmap_SA/commonheaders.h
+++ b/plugins/Dbx_mmap_SA/commonheaders.h
@@ -46,7 +46,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <newpluginapi.h>
#include <win2k.h>
#include <m_system.h>
+#include <m_system_cpp.h>
#include <m_database.h>
+#include <m_db_int.h>
#include <m_langpack.h>
#include <m_utils.h>
#include <m_options.h>
@@ -56,6 +58,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//own headers
#include "database.h"
+#include "dbintf.h"
#include "resource.h"
#include "version.h"
@@ -65,6 +68,7 @@ extern HANDLE hDbFile;
extern BOOL bEncoding;
extern HINSTANCE g_hInst;
extern HANDLE hSetPwdMenu;
+extern CDdxMmap* g_Db;
#ifdef __GNUC__
#define mir_i64(x) (x##LL)
@@ -78,19 +82,6 @@ void EncodeCopyMemory(void * dst, void * src, size_t size );
void DecodeCopyMemory(void * dst, void * src, size_t size );
void EncodeDBWrite(DWORD ofs, void * src, size_t size);
void DecodeDBWrite(DWORD ofs, void * src, size_t size);
-int CheckPassword(WORD checkWord, char * szDBName);
-
-void EncryptDB();
-void DecryptDB();
-void RecryptDB();
-void ChangePwd();
-
-void EncodeEvent(HANDLE hEvent);
-void EncodeContactEvents(HANDLE hContact);
-void DecodeEvent(HANDLE hEvent);
-void DecodeContactEvents(HANDLE hContact);
-void EncodeContactSettings(HANDLE hContact);
-void DecodeContactSettings(HANDLE hContact);
BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK DlgStdNewPass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam);
diff --git a/plugins/Dbx_mmap_SA/database.cpp b/plugins/Dbx_mmap_SA/database.cpp
index c1e1483fb0..288c7b898a 100644
--- a/plugins/Dbx_mmap_SA/database.cpp
+++ b/plugins/Dbx_mmap_SA/database.cpp
@@ -29,9 +29,7 @@ int InitialiseDbHeaders(void);
int InitSettings(void);
void UninitSettings(void);
int InitContacts(void);
-void UninitContacts(void);
int InitEvents(void);
-void UninitEvents(void);
int InitCrypt(void);
int InitModuleNames(void);
void UninitModuleNames(void);
@@ -45,10 +43,10 @@ int InitDialogs(void);
void InitSecurity(void);
void UnloadSecurity(void);
-HANDLE hDbFile=INVALID_HANDLE_VALUE;
+HANDLE hDbFile = INVALID_HANDLE_VALUE;
CRITICAL_SECTION csDbAccess;
struct DBHeader dbHeader;
-char szDbPath[MAX_PATH];
+TCHAR szDbPath[MAX_PATH];
static void UnloadDatabase(void)
{
@@ -63,8 +61,8 @@ static void UnloadDatabase(void)
DWORD CreateNewSpace(int bytes)
{
DWORD ofsNew;
- ofsNew=dbHeader.ofsFileEnd;
- dbHeader.ofsFileEnd+=bytes;
+ ofsNew = dbHeader.ofsFileEnd;
+ dbHeader.ofsFileEnd += bytes;
DBWrite(0,&dbHeader,sizeof(dbHeader));
log2("newspace %d@%08x",bytes,ofsNew);
return ofsNew;
@@ -74,10 +72,10 @@ void DeleteSpace(DWORD ofs,int bytes)
{
if (ofs+bytes == dbHeader.ofsFileEnd) {
log2("freespace %d@%08x",bytes,ofs);
- dbHeader.ofsFileEnd=ofs;
+ dbHeader.ofsFileEnd = ofs;
} else {
log2("deletespace %d@%08x",bytes,ofs);
- dbHeader.slackSpace+=bytes;
+ dbHeader.slackSpace += bytes;
}
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFill(ofs,bytes);
@@ -91,11 +89,11 @@ DWORD ReallocSpace(DWORD ofs,int oldSize,int newSize)
if (ofs+oldSize == dbHeader.ofsFileEnd) {
ofsNew = ofs;
- dbHeader.ofsFileEnd+=newSize-oldSize;
+ dbHeader.ofsFileEnd += newSize-oldSize;
DBWrite(0,&dbHeader,sizeof(dbHeader));
log3("adding newspace %d@%08x+%d",newSize,ofsNew,oldSize);
} else {
- ofsNew=CreateNewSpace(newSize);
+ ofsNew = CreateNewSpace(newSize);
DBMoveChunk(ofsNew,ofs,oldSize);
DeleteSpace(ofs,oldSize);
}
@@ -106,9 +104,7 @@ void UnloadDatabaseModule(void)
{
//UninitIni();
UninitPreset();
- UninitEvents();
UninitSettings();
- UninitContacts();
UninitModuleNames();
UninitCache();
UnloadDatabase();
@@ -118,22 +114,20 @@ void UnloadDatabaseModule(void)
INT_PTR GetProfileName(WPARAM wParam, LPARAM lParam)
{
- char * p = 0;
- p = strrchr(szDbPath, '\\');
+ TCHAR *p = _tcsrchr(szDbPath, '\\');
if ( p == 0 ) return 1;
p++;
- strncpy((char*)lParam, p, (size_t) wParam);
+ _tcsncpy((TCHAR*)lParam, p, (size_t) wParam);
return 0;
}
int LoadDatabaseModule(void)
{
- char szDBName[255];
InitializeCriticalSection(&csDbAccess);
log0("DB logging running");
{
- DWORD dummy=0;
- hDbFile=CreateFileA(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
+ DWORD dummy = 0;
+ hDbFile = CreateFile(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
if ( hDbFile == INVALID_HANDLE_VALUE ) {
return 1;
}
@@ -144,22 +138,24 @@ int LoadDatabaseModule(void)
}
InitSecurity();
CheckDbHeaders(&dbHeader);
+
+ TCHAR szDBName[MAX_PATH];
GetProfileName((WPARAM)50, (LPARAM)szDBName);
- if(bEncoding && !CheckPassword(dbHeader.checkWord, szDBName)) return 1;
- //if(ParseCommandLine()) return 1;
- if(InitCache()) return 1;
- if(InitModuleNames()) return 1;
- if(InitContacts()) return 1;
- if(InitSettings()) return 1;
- if(InitEvents()) return 1;
- if(InitCrypt()) return 1;
- if(InitPreset()) return 1;
- if(InitDialogs()) return 1;
- //EncryptDB();
+ if (bEncoding && !g_Db->CheckPassword(dbHeader.checkWord, szDBName))
+ return 1;
+
+ if (InitCache()) return 1;
+ if (InitModuleNames()) return 1;
+ if (InitContacts()) return 1;
+ if (InitSettings()) return 1;
+ if (InitEvents()) return 1;
+ if (InitCrypt()) return 1;
+ if (InitPreset()) return 1;
+ if (InitDialogs()) return 1;
return 0;
}
-static DWORD DatabaseCorrupted=0;
+static DWORD DatabaseCorrupted = 0;
static TCHAR *msg = NULL;
static DWORD dwErr = 0;
@@ -169,7 +165,7 @@ void __cdecl dbpanic(void *arg)
{
TCHAR err[256];
- if (dwErr==ERROR_DISK_FULL)
+ if (dwErr == ERROR_DISK_FULL)
msg = TranslateT("Disk is full. Miranda will now shutdown.");
mir_sntprintf(err, SIZEOF(err), msg, TranslateT("Database failure. Miranda will now shutdown."), dwErr);
@@ -185,10 +181,10 @@ void __cdecl dbpanic(void *arg)
void DatabaseCorruption(TCHAR *text)
{
- int kill=0;
+ int kill = 0;
EnterCriticalSection(&csDbAccess);
- if (DatabaseCorrupted==0) {
+ if (DatabaseCorrupted == 0) {
DatabaseCorrupted++;
kill++;
msg = text;
@@ -217,7 +213,7 @@ void DBLog(const char *file,int line,const char *fmt,...)
va_start(vararg,fmt);
mir_vsnprintf(str,sizeof(str),fmt,vararg);
va_end(vararg);
- fp=fopen("c:\\mirandadatabase.log.txt","at");
+ fp = fopen("c:\\mirandadatabase.log.txt","at");
fprintf(fp,"%u: %s %d: %s\n",GetTickCount(),file,line,str);
fclose(fp);
}
diff --git a/plugins/Dbx_mmap_SA/database.h b/plugins/Dbx_mmap_SA/database.h
index 290df81723..bbacb9670a 100644
--- a/plugins/Dbx_mmap_SA/database.h
+++ b/plugins/Dbx_mmap_SA/database.h
@@ -39,7 +39,7 @@ DBHeader
| | \-->module name (DBModuleName)
| \-->first/last/firstunread event
|-->user contact (DBContact)
- | |-->next contact=NULL
+ | |-->next contact = NULL
| |-->first settings as above
| \-->first/last/firstunread event as above
\-->first module name (DBModuleName)
@@ -56,15 +56,15 @@ struct DBSignature {
BYTE eof;
};
-static struct DBSignature dbSignature={"Miranda ICQ DB",0x1A};
-static struct DBSignature dbSignatureSecured={"Miranda ICQ SD",0x1A};
+static struct DBSignature dbSignature = {"Miranda ICQ DB",0x1A};
+static struct DBSignature dbSignatureSecured = {"Miranda ICQ SD",0x1A};
#include <pshpack1.h>
struct DBHeader {
BYTE signature[16]; // 'Miranda ICQ DB',0,26
/*
- DWORD version; //as 4 bytes, ie 1.2.3.10=0x0102030a
+ DWORD version; //as 4 bytes, ie 1.2.3.10 = 0x0102030a
//this version is 0x00000700
*/
@@ -78,8 +78,8 @@ struct DBHeader {
//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 struct DBContact in the chain
- DWORD ofsUser; //offset to struct DBContact representing 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
};
@@ -117,13 +117,13 @@ struct DBContactSettings {
//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
+ //structs, the last has cbName = 0
};
/* not a valid structure, content is figured out on the fly
struct DBSetting {
BYTE cbName; //number of bytes in the name of this setting
- //this =0 marks the end
+ //this = 0 marks the end
char szName[...]; //setting name, excluding nul
BYTE dataType; //type of data. see m_database.h, db/contact/getsetting
union { //a load of types of data, length is defined by dataType
@@ -189,6 +189,9 @@ typedef struct
//databasecorruption: with NULL called if any signatures are broken. very very fatal
void DatabaseCorruption(TCHAR *text);
PBYTE DBRead(DWORD ofs,int bytesRequired,int *bytesAvail); //any preview result could be invalidated by the next call
+__forceinline PBYTE DBRead(HANDLE hContact,int bytesRequired,int *bytesAvail)
+{ return DBRead((DWORD)hContact, bytesRequired, bytesAvail);
+}
void DBWrite(DWORD ofs,PVOID pData,int count);
void DBFill(DWORD ofs,int bytes);
void DBFlush(int setting);
diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj
index f76b09b895..197f7668ba 100644
--- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj
+++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj
@@ -194,6 +194,7 @@
<ClCompile Include="dbcontacts.cpp" />
<ClCompile Include="dbevents.cpp" />
<ClCompile Include="dbheaders.cpp" />
+ <ClCompile Include="dbintf.cpp" />
<ClCompile Include="dbmodulechain.cpp" />
<ClCompile Include="dbpreset.cpp" />
<ClCompile Include="dbsettings.cpp" />
@@ -207,6 +208,7 @@
<ItemGroup>
<ClInclude Include="commonheaders.h" />
<ClInclude Include="database.h" />
+ <ClInclude Include="dbintf.h" />
<ClInclude Include="options.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="version.h" />
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 3b68708b63..af0a5f88ba 100644
--- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters
+++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters
@@ -51,6 +51,9 @@
<ClCompile Include="security.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="dbintf.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="commonheaders.h">
@@ -68,6 +71,9 @@
<ClInclude Include="version.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="dbintf.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="db3x_mmap.rc">
diff --git a/plugins/Dbx_mmap_SA/dbcache.cpp b/plugins/Dbx_mmap_SA/dbcache.cpp
index bf5538a64f..1e5764ae22 100644
--- a/plugins/Dbx_mmap_SA/dbcache.cpp
+++ b/plugins/Dbx_mmap_SA/dbcache.cpp
@@ -65,7 +65,7 @@ void ReMap(DWORD needed)
}
}
else
- dwFileSize += ChunkSize;
+ dwFileSize += ChunkSize;
// FlushViewOfFile(pDbCache, 0);
UnmapViewOfFile(pDbCache);
@@ -120,7 +120,7 @@ void DBWrite(DWORD ofs,PVOID pData,int bytes)
void DBFill(DWORD ofs,int bytes)
{
log2("zerofill %d@%08x",bytes,ofs);
- if (ofs+bytes<=dwFileSize)
+ if (ofs+bytes <= dwFileSize)
ZeroMemory(pDbCache+ofs,bytes);
logg();
}
@@ -146,7 +146,7 @@ void DBFlush(int setting)
{
if (!setting) {
log0("nflush1");
- if(safetyMode && pDbCache) {
+ if (safetyMode && pDbCache) {
if (FlushViewOfFile(pDbCache, 0) == 0) {
if (flushFailTick == 0)
flushFailTick = GetTickCount();
@@ -160,16 +160,7 @@ void DBFlush(int setting)
return;
}
KillTimer(NULL,flushBuffersTimerId);
- flushBuffersTimerId=SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc);
-}
-
-static INT_PTR CacheSetSafetyMode(WPARAM wParam,LPARAM lParam)
-{
- EnterCriticalSection(&csDbAccess);
- safetyMode=wParam;
- LeaveCriticalSection(&csDbAccess);
- DBFlush(1);
- return 0;
+ flushBuffersTimerId = SetTimer(NULL,flushBuffersTimerId,50,DoBufferFlushTimerProc);
}
int InitCache(void)
@@ -184,15 +175,12 @@ int InitCache(void)
// Align to chunk
x = dwFileSize % ChunkSize;
- if (x) dwFileSize += ChunkSize - x;
+ if (x) dwFileSize += ChunkSize - x;
Map();
// zero region for reads outside the file
pNull = (PBYTE)calloc(ChunkSize, 1);
-
- CreateServiceFunction(MS_DB_SETSAFETYMODE,CacheSetSafetyMode);
-
return 0;
}
diff --git a/plugins/Dbx_mmap_SA/dbcontacts.cpp b/plugins/Dbx_mmap_SA/dbcontacts.cpp
index 0afd3469ab..40a8e4faac 100644
--- a/plugins/Dbx_mmap_SA/dbcontacts.cpp
+++ b/plugins/Dbx_mmap_SA/dbcontacts.cpp
@@ -30,33 +30,15 @@ extern HANDLE hLastCachedContact;
INT_PTR GetContactSettingStatic(WPARAM wParam,LPARAM lParam);
void FreeCachedVariant( DBVARIANT* V );
-static INT_PTR GetContactCount(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindFirstContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR AddContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam);
-
static HANDLE hContactDeletedEvent,hContactAddedEvent;
-
int InitContacts(void)
{
- CreateServiceFunction(MS_DB_CONTACT_GETCOUNT,GetContactCount);
- CreateServiceFunction(MS_DB_CONTACT_FINDFIRST,FindFirstContact);
- CreateServiceFunction(MS_DB_CONTACT_FINDNEXT,FindNextContact);
- CreateServiceFunction(MS_DB_CONTACT_DELETE,DeleteContact);
- CreateServiceFunction(MS_DB_CONTACT_ADD,AddContact);
- CreateServiceFunction(MS_DB_CONTACT_IS,IsDbContact);
- hContactDeletedEvent=CreateHookableEvent(ME_DB_CONTACT_DELETED);
- hContactAddedEvent=CreateHookableEvent(ME_DB_CONTACT_ADDED);
+ hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED);
+ hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED);
return 0;
}
-void UninitContacts(void)
-{
-}
-
DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index)
{
DBCachedContactValueList* VL;
@@ -67,12 +49,12 @@ DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index)
return VL;
}
-static INT_PTR GetContactCount(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::GetContactCount(void)
{
int ret;
EnterCriticalSection(&csDbAccess);
- ret=dbHeader.contactCount;
+ ret = dbHeader.contactCount;
LeaveCriticalSection(&csDbAccess);
return ret;
}
@@ -80,7 +62,7 @@ static INT_PTR GetContactCount(WPARAM wParam,LPARAM lParam)
#define proto_module "Protocol"
#define proto_setting "p"
-static int CheckProto(HANDLE hContact, const char *proto)
+int CDdxMmap::CheckProto(HANDLE hContact, const char *proto)
{
static char protobuf[MAX_PATH] = {0};
static DBVARIANT dbv;
@@ -90,44 +72,46 @@ static int CheckProto(HANDLE hContact, const char *proto)
dbv.pszVal = protobuf;
dbv.cchVal = sizeof(protobuf);
- if (GetContactSettingStatic((WPARAM)hContact, (LPARAM )&sVal) != 0
- || (dbv.type != DBVT_ASCIIZ)) return 0;
+ if (GetContactSettingStatic(hContact, &sVal) != 0 || dbv.type != DBVT_ASCIIZ)
+ return 0;
return !strcmp(protobuf,proto);
}
-static INT_PTR FindFirstContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstContact(const char* szProto)
{
- INT_PTR ret = 0;
+ HANDLE ret = 0;
EnterCriticalSection(&csDbAccess);
- ret = (INT_PTR)dbHeader.ofsFirstContact;
- if (lParam && !CheckProto((HANDLE)ret,(const char*)lParam))
- ret = FindNextContact((WPARAM)ret,lParam);
+ ret = (HANDLE)dbHeader.ofsFirstContact;
+ if (szProto && !CheckProto(ret, szProto))
+ ret = FindNextContact(ret, szProto);
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindNextContact(HANDLE hContact, const char* szProto)
{
int index;
- struct DBContact *dbc;
+ DBContact *dbc;
DBCachedContactValueList VLtemp, *VL = NULL;
- VLtemp.hContact = (HANDLE)wParam;
+ VLtemp.hContact = hContact;
+
EnterCriticalSection(&csDbAccess);
+
while(VLtemp.hContact) {
if ( List_GetIndex(&lContacts,&VLtemp,&index)) {
VL = ( DBCachedContactValueList* )lContacts.items[index];
if (VL->hNext != NULL) {
- if (!lParam || CheckProto(VL->hNext,(const char*)lParam)) {
+ if (!szProto || CheckProto(VL->hNext, szProto)) {
LeaveCriticalSection(&csDbAccess);
- return (INT_PTR)VL->hNext;
+ return VL->hNext;
}
else {
VLtemp.hContact = VL->hNext;
continue;
} } }
- dbc=(struct DBContact*)DBRead((DWORD)VLtemp.hContact,sizeof(struct DBContact),NULL);
+ dbc = (DBContact*)DBRead((DWORD)VLtemp.hContact,sizeof(DBContact),NULL);
if (dbc->signature!=DBCONTACT_SIGNATURE)
break;
else {
@@ -135,9 +119,9 @@ static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam)
VL = AddToCachedContactList(VLtemp.hContact,index);
VL->hNext = (HANDLE)dbc->ofsNext;
- if (VL->hNext != NULL && (!lParam || CheckProto(VL->hNext,(const char*)lParam))) {
+ if (VL->hNext != NULL && (!szProto || CheckProto(VL->hNext, szProto))) {
LeaveCriticalSection(&csDbAccess);
- return (INT_PTR)VL->hNext;
+ return VL->hNext;
}
VLtemp.hContact = VL->hNext;
} }
@@ -145,22 +129,24 @@ static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam)
return 0;
}
-static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::DeleteContact(HANDLE hContact)
{
- struct DBContact *dbc,*dbcPrev;
- DWORD ofsThis,ofsNext,ofsFirstEvent;
+ DBContact *dbcPrev;
+ DWORD ofsThis, ofsNext, ofsFirstEvent;
struct DBContactSettings *dbcs;
- struct DBEvent *dbe;
+ DBEvent *dbe;
int index;
- if ((HANDLE)wParam==NULL) return 1;
+ if (hContact == NULL)
+ return 1;
+
EnterCriticalSection(&csDbAccess);
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- if ( (HANDLE)wParam == (HANDLE)dbHeader.ofsUser ) {
+ if (hContact == (HANDLE)dbHeader.ofsUser ) {
LeaveCriticalSection(&csDbAccess);
log0("FATAL: del of user chain attempted.");
return 1;
@@ -168,64 +154,64 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam)
log0("del contact");
LeaveCriticalSection(&csDbAccess);
//call notifier while outside mutex
- NotifyEventHooks(hContactDeletedEvent,wParam,0);
+ NotifyEventHooks(hContactDeletedEvent, (WPARAM)hContact, 0);
//get back in
EnterCriticalSection(&csDbAccess);
- { DBCachedContactValueList VLtemp;
- VLtemp.hContact = (HANDLE)wParam;
- if ( List_GetIndex(&lContacts,&VLtemp,&index))
- {
- DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index];
- DBCachedContactValue* V = VL->first;
- while ( V != NULL ) {
- DBCachedContactValue* V1 = V->next;
- FreeCachedVariant(&V->value);
- HeapFree( hCacheHeap, 0, V );
- V = V1;
- }
- HeapFree( hCacheHeap, 0, VL );
+ DBCachedContactValueList VLtemp;
+ VLtemp.hContact = hContact;
+ if ( List_GetIndex(&lContacts,&VLtemp,&index)) {
+ DBCachedContactValueList *VL = (DBCachedContactValueList*)lContacts.items[index];
+ DBCachedContactValue* V = VL->first;
+ while ( V != NULL ) {
+ DBCachedContactValue* V1 = V->next;
+ FreeCachedVariant(&V->value);
+ HeapFree( hCacheHeap, 0, V );
+ V = V1;
+ }
+ HeapFree( hCacheHeap, 0, VL );
- if (VLtemp.hContact == hLastCachedContact)
- hLastCachedContact = NULL;
- List_Remove(&lContacts,index);
- } }
+ if (VLtemp.hContact == hLastCachedContact)
+ hLastCachedContact = NULL;
+ List_Remove(&lContacts,index);
+ }
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
+ dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
//delete settings chain
- ofsThis=dbc->ofsFirstSettings;
- ofsFirstEvent=dbc->ofsFirstEvent;
+ ofsThis = dbc->ofsFirstSettings;
+ ofsFirstEvent = dbc->ofsFirstEvent;
while(ofsThis) {
- dbcs=(struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
- ofsNext=dbcs->ofsNext;
+ dbcs = (struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
+ ofsNext = dbcs->ofsNext;
DeleteSpace(ofsThis,offsetof(struct DBContactSettings,blob)+dbcs->cbBlob);
- ofsThis=ofsNext;
+ ofsThis = ofsNext;
}
//delete event chain
- ofsThis=ofsFirstEvent;
+ ofsThis = ofsFirstEvent;
while(ofsThis) {
- dbe=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
- ofsNext=dbe->ofsNext;
- DeleteSpace(ofsThis,offsetof(struct DBEvent,blob)+dbe->cbBlob);
- ofsThis=ofsNext;
+ dbe = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
+ ofsNext = dbe->ofsNext;
+ DeleteSpace(ofsThis,offsetof(DBEvent,blob)+dbe->cbBlob);
+ ofsThis = ofsNext;
}
//find previous contact in chain and change ofsNext
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbHeader.ofsFirstContact==wParam) {
- dbHeader.ofsFirstContact=dbc->ofsNext;
+ dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbHeader.ofsFirstContact == (DWORD)hContact) {
+ dbHeader.ofsFirstContact = dbc->ofsNext;
DBWrite(0,&dbHeader,sizeof(dbHeader));
}
else {
- ofsNext=dbc->ofsNext;
- ofsThis=dbHeader.ofsFirstContact;
- dbcPrev=(struct DBContact*)DBRead(ofsThis,sizeof(struct DBContact),NULL);
- while(dbcPrev->ofsNext!=wParam) {
- if(dbcPrev->ofsNext==0) DatabaseCorruption(NULL);
- ofsThis=dbcPrev->ofsNext;
- dbcPrev=(struct DBContact*)DBRead(ofsThis,sizeof(struct DBContact),NULL);
+ ofsNext = dbc->ofsNext;
+ ofsThis = dbHeader.ofsFirstContact;
+ dbcPrev = (DBContact*)DBRead(ofsThis,sizeof(DBContact),NULL);
+ while(dbcPrev->ofsNext != (DWORD)hContact) {
+ if (dbcPrev->ofsNext == 0)
+ DatabaseCorruption(NULL);
+ ofsThis = dbcPrev->ofsNext;
+ dbcPrev = (DBContact*)DBRead(ofsThis,sizeof(DBContact),NULL);
}
- dbcPrev->ofsNext=ofsNext;
- DBWrite(ofsThis,dbcPrev,sizeof(struct DBContact));
+ dbcPrev->ofsNext = ofsNext;
+ DBWrite(ofsThis,dbcPrev,sizeof(DBContact));
{
DBCachedContactValueList VLtemp;
VLtemp.hContact = (HANDLE)ofsThis;
@@ -236,7 +222,7 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam)
} }
}
//delete contact
- DeleteSpace(wParam,sizeof(struct DBContact));
+ DeleteSpace((DWORD)hContact,sizeof(DBContact));
//decrement contact count
dbHeader.contactCount--;
DBWrite(0,&dbHeader,sizeof(dbHeader));
@@ -246,24 +232,24 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam)
return 0;
}
-static INT_PTR AddContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::AddContact(void)
{
- struct DBContact dbc;
+ DBContact dbc;
DWORD ofsNew;
log0("add contact");
EnterCriticalSection(&csDbAccess);
- ofsNew=CreateNewSpace(sizeof(struct DBContact));
- dbc.signature=DBCONTACT_SIGNATURE;
- dbc.eventCount=0;
- dbc.ofsFirstEvent=dbc.ofsLastEvent=0;
- dbc.ofsFirstSettings=0;
- dbc.ofsNext=dbHeader.ofsFirstContact;
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
- dbHeader.ofsFirstContact=ofsNew;
+ ofsNew = CreateNewSpace(sizeof(DBContact));
+ dbc.signature = DBCONTACT_SIGNATURE;
+ dbc.eventCount = 0;
+ dbc.ofsFirstEvent = dbc.ofsLastEvent = 0;
+ dbc.ofsFirstSettings = 0;
+ dbc.ofsNext = dbHeader.ofsFirstContact;
+ dbc.ofsFirstUnreadEvent = 0;
+ dbc.timestampFirstUnread = 0;
+ dbHeader.ofsFirstContact = ofsNew;
dbHeader.contactCount++;
- DBWrite(ofsNew,&dbc,sizeof(struct DBContact));
+ DBWrite(ofsNew,&dbc,sizeof(DBContact));
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFlush(0);
@@ -271,27 +257,27 @@ static INT_PTR AddContact(WPARAM wParam,LPARAM lParam)
LeaveCriticalSection(&csDbAccess);
NotifyEventHooks(hContactAddedEvent,(WPARAM)ofsNew,0);
- return (INT_PTR)ofsNew;
+ return (HANDLE)ofsNew;
}
-static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::IsDbContact(HANDLE hContact)
{
- struct DBContact *dbc;
- DWORD ofsContact=(DWORD)wParam;
+ DBContact *dbc;
+ DWORD ofsContact = (DWORD)hContact;
int ret;
EnterCriticalSection(&csDbAccess);
{
int index;
DBCachedContactValueList VLtemp;
- VLtemp.hContact = (HANDLE)wParam;
+ VLtemp.hContact = hContact;
if ( List_GetIndex(&lContacts,&VLtemp,&index))
ret = TRUE;
else {
- dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- ret=dbc->signature==DBCONTACT_SIGNATURE;
+ dbc = (DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ ret = dbc->signature == DBCONTACT_SIGNATURE;
if (ret)
- AddToCachedContactList((HANDLE)wParam, index);
+ AddToCachedContactList(hContact, index);
} }
LeaveCriticalSection(&csDbAccess);
diff --git a/plugins/Dbx_mmap_SA/dbevents.cpp b/plugins/Dbx_mmap_SA/dbevents.cpp
index 6ecde67a55..4f80f31b41 100644
--- a/plugins/Dbx_mmap_SA/dbevents.cpp
+++ b/plugins/Dbx_mmap_SA/dbevents.cpp
@@ -28,113 +28,83 @@ extern BOOL safetyMode;
DWORD GetModuleNameOfs(const char *szName);
char *GetModuleNameByOfs(DWORD ofs);
-static INT_PTR GetEventCount(WPARAM wParam,LPARAM lParam);
-static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam);
-static INT_PTR DeleteEvent(WPARAM wParam,LPARAM lParam);
-static INT_PTR GetBlobSize(WPARAM wParam,LPARAM lParam);
-static INT_PTR GetEvent(WPARAM wParam,LPARAM lParam);
-static INT_PTR MarkEventRead(WPARAM wParam,LPARAM lParam);
-static INT_PTR GetEventContact(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindFirstEvent(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindFirstUnreadEvent(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindLastEvent(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindNextEvent(WPARAM wParam,LPARAM lParam);
-static INT_PTR FindPrevEvent(WPARAM wParam,LPARAM lParam);
-
static HANDLE hEventDeletedEvent,hEventAddedEvent,hEventFilterAddedEvent;
int InitEvents(void)
{
- CreateServiceFunction(MS_DB_EVENT_GETCOUNT,GetEventCount);
- CreateServiceFunction(MS_DB_EVENT_ADD,AddEvent);
- CreateServiceFunction(MS_DB_EVENT_DELETE,DeleteEvent);
- CreateServiceFunction(MS_DB_EVENT_GETBLOBSIZE,GetBlobSize);
- CreateServiceFunction(MS_DB_EVENT_GET,GetEvent);
- CreateServiceFunction(MS_DB_EVENT_MARKREAD,MarkEventRead);
- CreateServiceFunction(MS_DB_EVENT_GETCONTACT,GetEventContact);
- CreateServiceFunction(MS_DB_EVENT_FINDFIRST,FindFirstEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDFIRSTUNREAD,FindFirstUnreadEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDLAST,FindLastEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDNEXT,FindNextEvent);
- CreateServiceFunction(MS_DB_EVENT_FINDPREV,FindPrevEvent);
- hEventDeletedEvent=CreateHookableEvent(ME_DB_EVENT_DELETED);
- hEventAddedEvent=CreateHookableEvent(ME_DB_EVENT_ADDED);
- hEventFilterAddedEvent=CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
+ hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED);
+ hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED);
+ hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
return 0;
}
-void UninitEvents(void)
-{
-}
-
-static INT_PTR GetEventCount(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::GetEventCount(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ LONG ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=-1;
- else ret=dbc->eventCount;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) ret = -1;
+ else ret = dbc->eventCount;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
{
- DBEVENTINFO *dbei=(DBEVENTINFO*)lParam;
- struct DBContact dbc;
- struct DBEvent dbe,*dbeTest;
+ DBEvent dbe,*dbeTest;
DWORD ofsNew,ofsModuleName,ofsContact,ofsThis;
BOOL neednotify;
- if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 0;
- if(dbei->timestamp==0) return 0;
- if (NotifyEventHooks(hEventFilterAddedEvent,wParam,lParam)) {
+ if (dbei == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) return 0;
+ if (dbei->timestamp == 0) return 0;
+ if (NotifyEventHooks(hEventFilterAddedEvent, (WPARAM)hContact, (LPARAM)dbei))
return 0;
- }
+
EnterCriticalSection(&csDbAccess);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=(DWORD)wParam;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE) {
+ if (hContact == 0) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ DBContact dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc.signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 0;
}
- ofsNew=CreateNewSpace(offsetof(struct DBEvent,blob)+dbei->cbBlob);
- ofsModuleName=GetModuleNameOfs(dbei->szModule);
-
- dbe.signature=DBEVENT_SIGNATURE;
- dbe.ofsModuleName=ofsModuleName;
- dbe.timestamp=dbei->timestamp;
- dbe.flags=dbei->flags;
- dbe.eventType=dbei->eventType;
- dbe.cbBlob=dbei->cbBlob;
+ ofsNew = CreateNewSpace(offsetof(DBEvent,blob)+dbei->cbBlob);
+ ofsModuleName = GetModuleNameOfs(dbei->szModule);
+
+ dbe.signature = DBEVENT_SIGNATURE;
+ dbe.ofsModuleName = ofsModuleName;
+ dbe.timestamp = dbei->timestamp;
+ dbe.flags = dbei->flags;
+ dbe.eventType = dbei->eventType;
+ dbe.cbBlob = dbei->cbBlob;
//find where to put it - sort by timestamp
- if(dbc.eventCount==0) {
- dbe.ofsPrev=wParam;
- dbe.ofsNext=0;
- dbe.flags|=DBEF_FIRST;
- dbc.ofsFirstEvent=dbc.ofsLastEvent=ofsNew;
+ if (dbc.eventCount == 0) {
+ dbe.ofsPrev = (DWORD)hContact;
+ dbe.ofsNext = 0;
+ dbe.flags |= DBEF_FIRST;
+ dbc.ofsFirstEvent = dbc.ofsLastEvent = ofsNew;
}
else {
- dbeTest=(struct DBEvent*)DBRead(dbc.ofsFirstEvent,sizeof(struct DBEvent),NULL);
+ dbeTest = (DBEvent*)DBRead(dbc.ofsFirstEvent,sizeof(DBEvent),NULL);
// Should new event be placed before first event in chain?
if (dbei->timestamp < dbeTest->timestamp) {
- dbe.ofsPrev=wParam;
- dbe.ofsNext=dbc.ofsFirstEvent;
- dbe.flags|=DBEF_FIRST;
- dbc.ofsFirstEvent=ofsNew;
- dbeTest=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeTest->flags&=~DBEF_FIRST;
- dbeTest->ofsPrev=ofsNew;
- DBWrite(dbe.ofsNext,dbeTest,sizeof(struct DBEvent));
+ dbe.ofsPrev = (DWORD)hContact;
+ dbe.ofsNext = dbc.ofsFirstEvent;
+ dbe.flags |= DBEF_FIRST;
+ dbc.ofsFirstEvent = ofsNew;
+ dbeTest = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeTest->flags &= ~DBEF_FIRST;
+ dbeTest->ofsPrev = ofsNew;
+ DBWrite(dbe.ofsNext,dbeTest,sizeof(DBEvent));
}
else {
// Loop through the chain, starting at the end
ofsThis = dbc.ofsLastEvent;
- dbeTest = (struct DBEvent*)DBRead(ofsThis, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
for (;;) {
// If the new event's timesstamp is equal to or greater than the
// current dbevent, it will be inserted after. If not, continue
@@ -143,34 +113,34 @@ static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam)
dbe.ofsPrev = ofsThis;
dbe.ofsNext = dbeTest->ofsNext;
dbeTest->ofsNext = ofsNew;
- DBWrite(ofsThis, dbeTest, sizeof(struct DBEvent));
+ DBWrite(ofsThis, dbeTest, sizeof(DBEvent));
if (dbe.ofsNext == 0)
dbc.ofsLastEvent = ofsNew;
else {
- dbeTest = (struct DBEvent*)DBRead(dbe.ofsNext, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(dbe.ofsNext, sizeof(DBEvent), NULL);
dbeTest->ofsPrev = ofsNew;
- DBWrite(dbe.ofsNext, dbeTest, sizeof(struct DBEvent));
+ DBWrite(dbe.ofsNext, dbeTest, sizeof(DBEvent));
}
break;
}
ofsThis = dbeTest->ofsPrev;
- dbeTest = (struct DBEvent*)DBRead(ofsThis, sizeof(struct DBEvent), NULL);
+ dbeTest = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
}
}
}
dbc.eventCount++;
if (!(dbe.flags&(DBEF_READ|DBEF_SENT))) {
- if(dbe.timestamp<dbc.timestampFirstUnread || dbc.timestampFirstUnread==0) {
- dbc.timestampFirstUnread=dbe.timestamp;
- dbc.ofsFirstUnreadEvent=ofsNew;
+ if (dbe.timestamp<dbc.timestampFirstUnread || dbc.timestampFirstUnread == 0) {
+ dbc.timestampFirstUnread = dbe.timestamp;
+ dbc.ofsFirstUnreadEvent = ofsNew;
}
neednotify = TRUE;
}
else neednotify = safetyMode;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
- DBWrite(ofsNew,&dbe,offsetof(struct DBEvent,blob));
- EncodeDBWrite(ofsNew+offsetof(struct DBEvent,blob),dbei->pBlob,dbei->cbBlob);
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
+ DBWrite(ofsNew,&dbe,offsetof(DBEvent,blob));
+ EncodeDBWrite(ofsNew+offsetof(DBEvent,blob),dbei->pBlob,dbei->cbBlob);
DBFlush(0);
LeaveCriticalSection(&csDbAccess);
@@ -178,322 +148,310 @@ static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam)
// Notify only in safe mode or on really new events
if (neednotify)
- NotifyEventHooks(hEventAddedEvent,wParam,(LPARAM)ofsNew);
+ NotifyEventHooks(hEventAddedEvent, (WPARAM)hContact, (LPARAM)ofsNew);
- return (INT_PTR)ofsNew;
+ return (HANDLE)ofsNew;
}
-static INT_PTR DeleteEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
{
- struct DBContact dbc;
+ DBContact dbc;
DWORD ofsContact,ofsThis;
- struct DBEvent dbe,*dbeNext,*dbePrev;
+ DBEvent dbe,*dbeNext,*dbePrev;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- dbe=*(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE || dbe.signature!=DBEVENT_SIGNATURE) {
+ if (hContact == 0) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ dbe = *(DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbc.signature != DBCONTACT_SIGNATURE || dbe.signature != DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
log1("delete event @ %08x",wParam);
LeaveCriticalSection(&csDbAccess);
//call notifier while outside mutex
- NotifyEventHooks(hEventDeletedEvent,wParam,lParam);
+ NotifyEventHooks(hEventDeletedEvent, (WPARAM)hContact, (LPARAM)hDbEvent);
//get back in
EnterCriticalSection(&csDbAccess);
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- dbe=*(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ dbe = *(DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
//check if this was the first unread, if so, recalc the first unread
- if(dbc.ofsFirstUnreadEvent==(DWORD)lParam) {
- dbeNext=&dbe;
+ if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
+ dbeNext = &dbe;
for (;;) {
- if(dbeNext->ofsNext==0) {
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
+ if (dbeNext->ofsNext == 0) {
+ dbc.ofsFirstUnreadEvent = 0;
+ dbc.timestampFirstUnread = 0;
break;
}
- ofsThis=dbeNext->ofsNext;
- dbeNext=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
+ ofsThis = dbeNext->ofsNext;
+ dbeNext = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
if (!(dbeNext->flags&(DBEF_READ|DBEF_SENT))) {
- dbc.ofsFirstUnreadEvent=ofsThis;
- dbc.timestampFirstUnread=dbeNext->timestamp;
+ dbc.ofsFirstUnreadEvent = ofsThis;
+ dbc.timestampFirstUnread = dbeNext->timestamp;
break;
}
}
}
//get previous and next events in chain and change offsets
- if(dbe.flags&DBEF_FIRST) {
- if(dbe.ofsNext==0) {
- dbc.ofsFirstEvent=dbc.ofsLastEvent=0;
+ if (dbe.flags&DBEF_FIRST) {
+ if (dbe.ofsNext == 0) {
+ dbc.ofsFirstEvent = dbc.ofsLastEvent = 0;
}
else {
- dbeNext=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeNext->flags|=DBEF_FIRST;
- dbeNext->ofsPrev=dbe.ofsPrev;
- DBWrite(dbe.ofsNext,dbeNext,sizeof(struct DBEvent));
- dbc.ofsFirstEvent=dbe.ofsNext;
+ dbeNext = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeNext->flags |= DBEF_FIRST;
+ dbeNext->ofsPrev = dbe.ofsPrev;
+ DBWrite(dbe.ofsNext,dbeNext,sizeof(DBEvent));
+ dbc.ofsFirstEvent = dbe.ofsNext;
}
}
else {
- if(dbe.ofsNext==0) {
- dbePrev=(struct DBEvent*)DBRead(dbe.ofsPrev,sizeof(struct DBEvent),NULL);
- dbePrev->ofsNext=0;
- DBWrite(dbe.ofsPrev,dbePrev,sizeof(struct DBEvent));
- dbc.ofsLastEvent=dbe.ofsPrev;
+ if (dbe.ofsNext == 0) {
+ dbePrev = (DBEvent*)DBRead(dbe.ofsPrev,sizeof(DBEvent),NULL);
+ dbePrev->ofsNext = 0;
+ DBWrite(dbe.ofsPrev,dbePrev,sizeof(DBEvent));
+ dbc.ofsLastEvent = dbe.ofsPrev;
}
else {
- dbePrev=(struct DBEvent*)DBRead(dbe.ofsPrev,sizeof(struct DBEvent),NULL);
- dbePrev->ofsNext=dbe.ofsNext;
- DBWrite(dbe.ofsPrev,dbePrev,sizeof(struct DBEvent));
- dbeNext=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL);
- dbeNext->ofsPrev=dbe.ofsPrev;
- DBWrite(dbe.ofsNext,dbeNext,sizeof(struct DBEvent));
+ dbePrev = (DBEvent*)DBRead(dbe.ofsPrev,sizeof(DBEvent),NULL);
+ dbePrev->ofsNext = dbe.ofsNext;
+ DBWrite(dbe.ofsPrev,dbePrev,sizeof(DBEvent));
+ dbeNext = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeNext->ofsPrev = dbe.ofsPrev;
+ DBWrite(dbe.ofsNext,dbeNext,sizeof(DBEvent));
}
}
//delete event
- DeleteSpace(lParam,offsetof(struct DBEvent,blob)+dbe.cbBlob);
+ DeleteSpace((DWORD)hDbEvent,offsetof(DBEvent,blob)+dbe.cbBlob);
//decrement event count
dbc.eventCount--;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
DBFlush(0);
//quit
LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR GetBlobSize(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(LONG) CDdxMmap::GetBlobSize(HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
+ LONG ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=-1;
- else ret=dbe->cbBlob;
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE) ret = -1;
+ else ret = dbe->cbBlob;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-void EncodeContactEvents(HANDLE hContact)
+void CDdxMmap::EncodeContactEvents(HANDLE hContact)
{
- HANDLE hEvent;
-
- hEvent = (HANDLE)FindFirstEvent((WPARAM)hContact, 0);
- if(hEvent == 0) return;
- do{
+ HANDLE hEvent = FindFirstEvent(hContact);
+ if (hEvent == 0) return;
+ do {
EncodeEvent(hEvent);
- }while (hEvent = (HANDLE)FindNextEvent((WPARAM)hEvent, 0));
+ }
+ while (hEvent = FindNextEvent(hEvent));
}
extern Cryptor* CryptoEngine;
extern void* key;
-void EncodeEvent(HANDLE hEvent)
+void CDdxMmap::EncodeEvent(HANDLE hEvent)
{
- struct DBEvent *dbe;
-
- dbe=(struct DBEvent*)DBRead((DWORD)hEvent,sizeof(struct DBEvent),NULL);
- if(dbe->signature=DBEVENT_SIGNATURE){
- CryptoEngine->EncryptMem(DBRead((DWORD)hEvent + offsetof(struct DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob, key);
- //EncodeDBWrite((DWORD)hEvent + offsetof(struct DBEvent,blob), DBRead((DWORD)hEvent + offsetof(struct DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob);
- }
-
+ DBEvent *dbe = (DBEvent*)DBRead((DWORD)hEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature = DBEVENT_SIGNATURE)
+ CryptoEngine->EncryptMem(DBRead((DWORD)hEvent + offsetof(DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob, key);
}
-void DecodeEvent(HANDLE hEvent)
+void CDdxMmap::DecodeEvent(HANDLE hEvent)
{
- struct DBEvent *dbe;
-
- dbe=(struct DBEvent*)DBRead((DWORD)hEvent,sizeof(struct DBEvent),NULL);
- if(dbe->signature=DBEVENT_SIGNATURE){
- CryptoEngine->DecryptMem(DBRead((DWORD)hEvent + offsetof(struct DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob, key);
- }
-
+ DBEvent *dbe = (DBEvent*)DBRead((DWORD)hEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature = DBEVENT_SIGNATURE)
+ CryptoEngine->DecryptMem(DBRead((DWORD)hEvent + offsetof(DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob, key);
}
-void DecodeContactEvents(HANDLE hContact)
+void CDdxMmap::DecodeContactEvents(HANDLE hContact)
{
HANDLE hEvent;
- hEvent = (HANDLE)FindFirstEvent((WPARAM)hContact, 0);
- if(hEvent == 0) return;
- do{
+ hEvent = FindFirstEvent(hContact);
+ if (hEvent == 0) return;
+ do {
DecodeEvent(hEvent);
- }while (hEvent = (HANDLE)FindNextEvent((WPARAM)hEvent, 0));
+ }
+ while (hEvent = FindNextEvent(hEvent));
}
-
-INT_PTR GetEvent(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
{
- struct DBEvent *dbe;
- DBEVENTINFO *dbei=(DBEVENTINFO*)lParam;
int bytesToCopy,i;
- if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 1;
- if(dbei->cbBlob>0 && dbei->pBlob==NULL) {
+ if (dbei == NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 1;
+ if (dbei->cbBlob>0 && dbei->pBlob == NULL) {
dbei->cbBlob = 0;
return 1;
}
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) {
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- dbei->szModule=GetModuleNameByOfs(dbe->ofsModuleName);
- dbei->timestamp=dbe->timestamp;
- dbei->flags=dbe->flags;
- dbei->eventType=dbe->eventType;
- if(dbei->cbBlob<dbe->cbBlob) bytesToCopy=dbei->cbBlob;
- else bytesToCopy=dbe->cbBlob;
- dbei->cbBlob=dbe->cbBlob;
+ dbei->szModule = GetModuleNameByOfs(dbe->ofsModuleName);
+ dbei->timestamp = dbe->timestamp;
+ dbei->flags = dbe->flags;
+ dbei->eventType = dbe->eventType;
+ if (dbei->cbBlob<dbe->cbBlob) bytesToCopy = dbei->cbBlob;
+ else bytesToCopy = dbe->cbBlob;
+ dbei->cbBlob = dbe->cbBlob;
if (bytesToCopy && dbei->pBlob)
{
- for(i=0;;i+=MAXCACHEDREADSIZE) {
- if(bytesToCopy-i<=MAXCACHEDREADSIZE) {
- DecodeCopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i);
+ for(i = 0;;i += MAXCACHEDREADSIZE) {
+ if (bytesToCopy-i <= MAXCACHEDREADSIZE) {
+ DecodeCopyMemory(dbei->pBlob+i,DBRead(DWORD(hDbEvent)+offsetof(DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i);
break;
}
- DecodeCopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE);
+ DecodeCopyMemory(dbei->pBlob+i,DBRead(DWORD(hDbEvent)+offsetof(DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE);
}
}
LeaveCriticalSection(&csDbAccess);
return 0;
}
-static INT_PTR MarkEventRead(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
- struct DBContact dbc;
+ LONG ret;
+ DBEvent *dbe;
+ DBContact dbc;
DWORD ofsThis;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=*(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- dbe=(struct DBEvent*)DBRead(lParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE || dbc.signature!=DBCONTACT_SIGNATURE) {
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+ dbc = *(DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!=DBEVENT_SIGNATURE || dbc.signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- if(dbe->flags&DBEF_READ || dbe->flags&DBEF_SENT) {
- ret=(INT_PTR)dbe->flags;
+ if (dbe->flags&DBEF_READ || dbe->flags&DBEF_SENT) {
+ ret = (INT_PTR)dbe->flags;
LeaveCriticalSection(&csDbAccess);
return ret;
}
log1("mark read @ %08x",wParam);
- dbe->flags|=DBEF_READ;
- DBWrite(lParam,dbe,sizeof(struct DBEvent));
- ret=(int)dbe->flags;
- if(dbc.ofsFirstUnreadEvent==(DWORD)lParam) {
+ dbe->flags |= DBEF_READ;
+ DBWrite((DWORD)hDbEvent,dbe,sizeof(DBEvent));
+ ret = (int)dbe->flags;
+ if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
for (;;) {
- if(dbe->ofsNext==0) {
- dbc.ofsFirstUnreadEvent=0;
- dbc.timestampFirstUnread=0;
+ if (dbe->ofsNext == 0) {
+ dbc.ofsFirstUnreadEvent = 0;
+ dbc.timestampFirstUnread = 0;
break;
}
- ofsThis=dbe->ofsNext;
- dbe=(struct DBEvent*)DBRead(ofsThis,sizeof(struct DBEvent),NULL);
+ ofsThis = dbe->ofsNext;
+ dbe = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
if (!(dbe->flags&(DBEF_READ|DBEF_SENT))) {
- dbc.ofsFirstUnreadEvent=ofsThis;
- dbc.timestampFirstUnread=dbe->timestamp;
+ dbc.ofsFirstUnreadEvent = ofsThis;
+ dbc.timestampFirstUnread = dbe->timestamp;
break;
}
}
}
- DBWrite(wParam,&dbc,sizeof(struct DBContact));
+ DBWrite(DWORD(hContact),&dbc,sizeof(DBContact));
DBFlush(0);
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR GetEventContact(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::GetEventContact(HANDLE hDbEvent)
{
- int ret;
- struct DBEvent *dbe;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) {
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
- return -1;
+ return (HANDLE)-1;
}
- while(!(dbe->flags&DBEF_FIRST))
- dbe=(struct DBEvent*)DBRead(dbe->ofsPrev,sizeof(struct DBEvent),NULL);
- ret=(INT_PTR)dbe->ofsPrev;
+ while( !(dbe->flags & DBEF_FIRST))
+ dbe = (DBEvent*)DBRead(dbe->ofsPrev,sizeof(DBEvent),NULL);
+ ret = (HANDLE)dbe->ofsPrev;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindFirstEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsFirstEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbc->ofsFirstEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindFirstUnreadEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindFirstUnreadEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsFirstUnreadEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbc->ofsFirstUnreadEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindLastEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindLastEvent(HANDLE hContact)
{
- INT_PTR ret;
- struct DBContact *dbc;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- if(wParam==0) wParam=dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbc->ofsLastEvent;
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
+
+ DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbc->ofsLastEvent;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindNextEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindNextEvent(HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=0;
- else ret=(INT_PTR)dbe->ofsNext;
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE) ret = 0;
+ else ret = (HANDLE)dbe->ofsNext;
LeaveCriticalSection(&csDbAccess);
return ret;
}
-static INT_PTR FindPrevEvent(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDdxMmap::FindPrevEvent(HANDLE hDbEvent)
{
- INT_PTR ret;
- struct DBEvent *dbe;
+ HANDLE ret;
EnterCriticalSection(&csDbAccess);
- dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL);
- if(dbe->signature!=DBEVENT_SIGNATURE) ret=0;
- else if(dbe->flags&DBEF_FIRST) ret=0;
- else ret=(INT_PTR)dbe->ofsPrev;
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ if (dbe->signature!=DBEVENT_SIGNATURE) ret = 0;
+ else if (dbe->flags&DBEF_FIRST) ret = 0;
+ else ret = (HANDLE)dbe->ofsPrev;
LeaveCriticalSection(&csDbAccess);
return ret;
}
diff --git a/plugins/Dbx_mmap_SA/dbheaders.cpp b/plugins/Dbx_mmap_SA/dbheaders.cpp
index 16c33dff2f..af42b2b996 100644
--- a/plugins/Dbx_mmap_SA/dbheaders.cpp
+++ b/plugins/Dbx_mmap_SA/dbheaders.cpp
@@ -27,45 +27,45 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int CreateDbHeaders(HANDLE hFile)
{
- struct DBContact user;
+ DBContact user;
DWORD bytesWritten;
CopyMemory(dbHeader.signature,&dbSignature,sizeof(dbHeader.signature));
dbHeader.checkWord = 0x0700;
dbHeader.cryptorUID = 0x0000;
- dbHeader.ofsFileEnd=sizeof(struct DBHeader);
- dbHeader.slackSpace=0;
- dbHeader.contactCount=0;
- dbHeader.ofsFirstContact=0;
- dbHeader.ofsFirstModuleName=0;
- dbHeader.ofsUser=0;
+ dbHeader.ofsFileEnd = sizeof(struct DBHeader);
+ dbHeader.slackSpace = 0;
+ dbHeader.contactCount = 0;
+ dbHeader.ofsFirstContact = 0;
+ dbHeader.ofsFirstModuleName = 0;
+ dbHeader.ofsUser = 0;
//create user
- dbHeader.ofsUser=dbHeader.ofsFileEnd;
- dbHeader.ofsFileEnd+=sizeof(struct DBContact);
+ dbHeader.ofsUser = dbHeader.ofsFileEnd;
+ dbHeader.ofsFileEnd += sizeof(DBContact);
SetFilePointer(hFile,0,NULL,FILE_BEGIN);
WriteFile(hFile,&dbHeader,sizeof(dbHeader),&bytesWritten,NULL);
- user.signature=DBCONTACT_SIGNATURE;
- user.ofsNext=0;
- user.ofsFirstSettings=0;
- user.eventCount=0;
- user.ofsFirstEvent=user.ofsLastEvent=0;
+ user.signature = DBCONTACT_SIGNATURE;
+ user.ofsNext = 0;
+ user.ofsFirstSettings = 0;
+ user.eventCount = 0;
+ user.ofsFirstEvent = user.ofsLastEvent = 0;
SetFilePointer(hFile,dbHeader.ofsUser,NULL,FILE_BEGIN);
- WriteFile(hFile,&user,sizeof(struct DBContact),&bytesWritten,NULL);
+ WriteFile(hFile,&user,sizeof(DBContact),&bytesWritten,NULL);
FlushFileBuffers(hFile);
return 0;
}
int CheckDbHeaders(struct DBHeader * hdr)
{
- if(memcmp(hdr->signature,&dbSignatureSecured,sizeof(hdr->signature)) == 0){
+ if (memcmp(hdr->signature,&dbSignatureSecured,sizeof(hdr->signature)) == 0){
bEncoding = 1;
}else{
bEncoding = 0;
- if(memcmp(hdr->signature,&dbSignature,sizeof(hdr->signature))) return 1;
- if(hdr->checkWord!=0x0700) return 2;
+ if (memcmp(hdr->signature,&dbSignature,sizeof(hdr->signature))) return 1;
+ if (hdr->checkWord!=0x0700) return 2;
}
- if(hdr->ofsUser==0) return 3;
+ if (hdr->ofsUser == 0) return 3;
return 0;
}
diff --git a/plugins/Dbx_mmap_SA/dbintf.cpp b/plugins/Dbx_mmap_SA/dbintf.cpp
new file mode 100644
index 0000000000..c30d8206cc
--- /dev/null
+++ b/plugins/Dbx_mmap_SA/dbintf.cpp
@@ -0,0 +1,38 @@
+/*
+
+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"
+
+extern BOOL safetyMode;
+
+CDdxMmap::CDdxMmap(const TCHAR* tszFileName)
+{
+}
+
+STDMETHODIMP_(void) CDdxMmap::SetCacheSafetyMode(BOOL bIsSet)
+{
+ { mir_cslock lck(csDbAccess);
+ safetyMode = bIsSet;
+ }
+ DBFlush(1);
+}
diff --git a/plugins/Dbx_mmap_SA/dbintf.h b/plugins/Dbx_mmap_SA/dbintf.h
new file mode 100644
index 0000000000..74740cd31d
--- /dev/null
+++ b/plugins/Dbx_mmap_SA/dbintf.h
@@ -0,0 +1,87 @@
+/*
+
+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>
+
+struct CDdxMmap : public MIDatabase
+{
+ CDdxMmap(const TCHAR* tszFileName);
+
+ 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 *dbei);
+ STDMETHODIMP_(BOOL) DeleteEvent(HANDLE hContact, HANDLE hDbEvent);
+ STDMETHODIMP_(LONG) GetBlobSize(HANDLE hDbEvent);
+ STDMETHODIMP_(BOOL) GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei);
+ 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);
+
+ int CheckPassword(WORD checkWord, TCHAR *szDBName);
+
+ void ChangePwd();
+ void EncryptDB();
+ void DecryptDB();
+ void RecryptDB();
+
+private:
+ int CheckProto(HANDLE hContact, const char *proto);
+
+ void EncodeContactEvents(HANDLE hContact);
+ void EncodeEvent(HANDLE hEvent);
+ void DecodeEvent(HANDLE hEvent);
+ void DecodeContactEvents(HANDLE hContact);
+
+ void DecodeContactSettings(HANDLE hContact);
+ void EncodeContactSettings(HANDLE hContact);
+
+ void WritePlainHeader();
+ void WriteCryptHeader();
+
+ void EncodeAll();
+ void DecodeAll();
+};
diff --git a/plugins/Dbx_mmap_SA/dbmodulechain.cpp b/plugins/Dbx_mmap_SA/dbmodulechain.cpp
index cc73248182..257681b1a9 100644
--- a/plugins/Dbx_mmap_SA/dbmodulechain.cpp
+++ b/plugins/Dbx_mmap_SA/dbmodulechain.cpp
@@ -23,8 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-static INT_PTR EnumModuleNames(WPARAM wParam,LPARAM lParam);
-
typedef struct {
char *name;
DWORD ofs;
@@ -76,11 +74,11 @@ int InitModuleNames(void)
lOfs.increment = 50;
ofsThis = dbHeader.ofsFirstModuleName;
- dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
+ dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
while(ofsThis) {
- if(dbmn->signature!=DBMODULENAME_SIGNATURE) DatabaseCorruption(NULL);
+ if (dbmn->signature!=DBMODULENAME_SIGNATURE) DatabaseCorruption(NULL);
- nameLen=dbmn->cbName;
+ nameLen = dbmn->cbName;
mod = (char*)HeapAlloc(hModHeap,0,nameLen+1);
CopyMemory(mod,DBRead(ofsThis+offsetof(struct DBModuleName,name),nameLen,NULL),nameLen);
@@ -88,10 +86,9 @@ int InitModuleNames(void)
AddToList(mod, nameLen, ofsThis);
- ofsThis=dbmn->ofsNext;
- dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
+ ofsThis = dbmn->ofsNext;
+ dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
}
- CreateServiceFunction(MS_DB_MODULES_ENUM,EnumModuleNames);
return 0;
}
@@ -131,17 +128,17 @@ DWORD GetModuleNameOfs(const char *szName)
DWORD ofsNew,ofsExisting;
char *mod;
- ofsExisting=FindExistingModuleNameOfs(szName);
- if(ofsExisting) return ofsExisting;
+ ofsExisting = FindExistingModuleNameOfs(szName);
+ if (ofsExisting) return ofsExisting;
nameLen = (int)strlen(szName);
//need to create the module name
- ofsNew=CreateNewSpace(nameLen+offsetof(struct DBModuleName,name));
- dbmn.signature=DBMODULENAME_SIGNATURE;
- dbmn.cbName=nameLen;
- dbmn.ofsNext=dbHeader.ofsFirstModuleName;
- dbHeader.ofsFirstModuleName=ofsNew;
+ ofsNew = CreateNewSpace(nameLen+offsetof(struct DBModuleName,name));
+ dbmn.signature = DBMODULENAME_SIGNATURE;
+ dbmn.cbName = nameLen;
+ dbmn.ofsNext = dbHeader.ofsFirstModuleName;
+ dbHeader.ofsFirstModuleName = ofsNew;
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBWrite(ofsNew,&dbmn,offsetof(struct DBModuleName,name));
DBWrite(ofsNew+offsetof(struct DBModuleName,name),(PVOID)szName,nameLen);
@@ -178,15 +175,15 @@ char *GetModuleNameByOfs(DWORD ofs)
return NULL;
}
-static INT_PTR EnumModuleNames(WPARAM wParam,LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
{
- int i;
int ret;
ModuleName *pmn;
- for(i = 0; i < lMods.realCount; i++) {
+ for(int i = 0; i < lMods.realCount; i++) {
pmn = (ModuleName *)lMods.items[i];
- ret=((DBMODULEENUMPROC)lParam)(pmn->name,pmn->ofs,wParam);
- if(ret) return ret;
+ ret = pFunc(pmn->name, pmn->ofs, (LPARAM)pParam);
+ if (ret)
+ return ret;
}
return 0;
}
diff --git a/plugins/Dbx_mmap_SA/dbpreset.cpp b/plugins/Dbx_mmap_SA/dbpreset.cpp
index 9e04f56353..e690dc1aaa 100644
--- a/plugins/Dbx_mmap_SA/dbpreset.cpp
+++ b/plugins/Dbx_mmap_SA/dbpreset.cpp
@@ -59,7 +59,7 @@ int InitPreset()
GetModuleFileNameA(GetModuleHandle(NULL), szIniPath, SIZEOF(szIniPath));
strcpy(strrchr(szIniPath, '\\')+1, "dbpreset.ini");
- fp=fopen(szIniPath,"rt");
+ fp = fopen(szIniPath,"rt");
// no preset
if (!fp) return 0;
@@ -69,16 +69,16 @@ int InitPreset()
while(!feof(fp))
{
- if(fgets(szLine,sizeof(szLine),fp)==NULL) break;
- lineLength=lstrlenA(szLine);
- while(lineLength && (BYTE)(szLine[lineLength-1])<=' ') szLine[--lineLength]='\0';
- if(szLine[0]==';' || szLine[0]<=' ') continue;
- if(szLine[0]=='[')
+ if (fgets(szLine,sizeof(szLine),fp) == NULL) break;
+ lineLength = lstrlenA(szLine);
+ while(lineLength && (BYTE)(szLine[lineLength-1]) <= ' ') szLine[--lineLength] = '\0';
+ if (szLine[0] == ';' || szLine[0] <= ' ') continue;
+ if (szLine[0] == '[')
{
- char *szEnd=strchr(szLine+1,']');
- if(szEnd==NULL) continue;
- if(szLine[1]=='!')
- szSection[0]='\0';
+ char *szEnd = strchr(szLine+1,']');
+ if (szEnd == NULL) continue;
+ if (szLine[1] == '!')
+ szSection[0] = '\0';
else
lstrcpynA(szSection, szLine+1, (int)min(sizeof(szSection), szEnd-szLine));
} else
@@ -87,9 +87,9 @@ int InitPreset()
char szName[128];
DBPresetItem *item;
- if(szSection[0]=='\0') continue;
- szValue=strchr(szLine,'=');
- if(szValue==NULL) continue;
+ if (szSection[0] == '\0') continue;
+ szValue = strchr(szLine,' = ');
+ if (szValue == NULL) continue;
lstrcpynA(szName, szLine, (int)min(sizeof(szName), szValue-szLine+1));
szValue++;
@@ -132,11 +132,11 @@ int InitPreset()
int len;
char *pszValue,*pszEnd;
- buf=(PBYTE)mir_alloc(lstrlenA(szValue+1));
- for(len=0,pszValue=szValue+1;;len++) {
- buf[len]=(BYTE)strtol(pszValue,&pszEnd,0x10);
- if(pszValue==pszEnd) break;
- pszValue=pszEnd;
+ buf = (PBYTE)mir_alloc(lstrlenA(szValue+1));
+ for(len = 0,pszValue = szValue+1;;len++) {
+ buf[len] = (BYTE)strtol(pszValue,&pszEnd,0x10);
+ if (pszValue == pszEnd) break;
+ pszValue = pszEnd;
}
item = DBPresetItem_Create(szSection, szName, DBVT_BLOB);
@@ -256,14 +256,14 @@ static void DBPresetItem_Destroy(DBPresetItem *item)
{
if (item->dbv.pszVal)
mir_free(item->dbv.pszVal);
- item->dbv.pszVal=0;
+ item->dbv.pszVal = 0;
break;
}
case DBVT_BLOB:
{
if (item->dbv.pbVal)
mir_free(item->dbv.pbVal);
- item->dbv.pbVal=0;
+ item->dbv.pbVal = 0;
break;
}
}
@@ -273,19 +273,19 @@ static void DBPresetItem_Destroy(DBPresetItem *item)
static void DBPresetItem_Hash(DBPresetItem *item)
{
int i;
- int shift=0;
- item->dwHash=0;
- for(i=0;item->szModule[i];i++)
+ int shift = 0;
+ item->dwHash = 0;
+ for(i = 0;item->szModule[i];i++)
{
- item->dwHash^=item->szModule[i]<<shift;
- if (shift>24) item->dwHash^=(item->szModule[i]>>(32-shift))&0x7F;
- shift=(shift+5)&0x1F;
+ item->dwHash ^= item->szModule[i]<<shift;
+ if (shift>24) item->dwHash ^= (item->szModule[i]>>(32-shift))&0x7F;
+ shift = (shift+5)&0x1F;
}
- for(i=0;item->szSetting[i];i++)
+ for(i = 0;item->szSetting[i];i++)
{
- item->dwHash^=item->szSetting[i]<<shift;
- if (shift>24) item->dwHash^=(item->szSetting[i]>>(32-shift))&0x7F;
- shift=(shift+5)&0x1F;
+ item->dwHash ^= item->szSetting[i]<<shift;
+ if (shift>24) item->dwHash ^= (item->szSetting[i]>>(32-shift))&0x7F;
+ shift = (shift+5)&0x1F;
}
}
diff --git a/plugins/Dbx_mmap_SA/dbsettings.cpp b/plugins/Dbx_mmap_SA/dbsettings.cpp
index 469abc97fd..980385bad2 100644
--- a/plugins/Dbx_mmap_SA/dbsettings.cpp
+++ b/plugins/Dbx_mmap_SA/dbsettings.cpp
@@ -36,30 +36,29 @@ static DBCachedContactValueList *LastVL = NULL;
static int mirCp = CP_ACP;
-static SortedList lSettings={0}, lGlobalSettings={0}, lResidentSettings={0};
+static SortedList lSettings = {0}, lGlobalSettings = {0}, lResidentSettings = {0};
static HANDLE hSettingChangeEvent = NULL;
-
-static DWORD GetSettingsGroupOfsByModuleNameOfs(struct DBContact *dbc,DWORD ofsModuleName)
+static DWORD GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsModuleName)
{
struct DBContactSettings *dbcs;
DWORD ofsThis;
- ofsThis=dbc->ofsFirstSettings;
+ ofsThis = dbc->ofsFirstSettings;
while(ofsThis) {
- dbcs=(struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
- if(dbcs->signature!=DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL);
- if(dbcs->ofsModuleName==ofsModuleName)
+ dbcs = (struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL);
+ if (dbcs->signature!=DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL);
+ if (dbcs->ofsModuleName == ofsModuleName)
return ofsThis;
- ofsThis=dbcs->ofsNext;
+ ofsThis = dbcs->ofsNext;
}
return 0;
}
static DWORD __inline GetSettingValueLength(PBYTE pSetting)
{
- if(pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1);
+ if (pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1);
return pSetting[0];
}
@@ -79,7 +78,7 @@ static char* GetCachedSetting(const char *szModuleName,const char *szSettingName
char szFullName[512];
strcpy(szFullName+1,szModuleName);
- szFullName[moduleNameLen+1]='/';
+ szFullName[moduleNameLen+1] = '/';
strcpy(szFullName+moduleNameLen+2,szSettingName);
if (lastsetting && strcmp(szFullName+1,lastsetting) == 0)
@@ -156,11 +155,11 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
DBCachedContactValue *V, *V1;
DBCachedContactValueList VLtemp,*VL;
- if (hLastCachedContact==hContact && LastVL) {
+ if (hLastCachedContact == hContact && LastVL) {
VL = LastVL;
}
else {
- VLtemp.hContact=hContact;
+ VLtemp.hContact = hContact;
if ( !List_GetIndex(&lContacts,&VLtemp,&index))
{
@@ -214,12 +213,12 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
return &V->value;
} }
-#define NeedBytes(n) if(bytesRemaining<(n)) pBlob=(PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining)
-#define MoveAlong(n) {int x=n; pBlob+=(x); ofsBlobPtr+=(x); bytesRemaining-=(x);}
-#define VLT(n) ((n==DBVT_UTF8)?DBVT_ASCIIZ:n)
+#define NeedBytes(n) if (bytesRemaining<(n)) pBlob = (PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining)
+#define MoveAlong(n) {int x = n; pBlob += (x); ofsBlobPtr += (x); bytesRemaining -= (x);}
+#define VLT(n) ((n == DBVT_UTF8)?DBVT_ASCIIZ:n)
static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic)
{
- struct DBContact *dbc;
+ DBContact *dbc;
DWORD ofsModuleName,ofsContact,ofsSettingsGroup,ofsBlobPtr;
int settingNameLen,moduleNameLen;
int bytesRemaining;
@@ -265,10 +264,10 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
cbOrigLen--;
dbcgs->pValue->pszVal = cbOrigPtr;
- if(cbLen<cbOrigLen) cbOrigLen=cbLen;
+ if (cbLen<cbOrigLen) cbOrigLen = cbLen;
CopyMemory(dbcgs->pValue->pszVal,pCachedValue->pszVal,cbOrigLen);
- dbcgs->pValue->pszVal[cbOrigLen]=0;
- dbcgs->pValue->cchVal=cbLen;
+ dbcgs->pValue->pszVal[cbOrigLen] = 0;
+ dbcgs->pValue->cchVal = cbLen;
}
else {
dbcgs->pValue->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal)+1);
@@ -291,64 +290,64 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
return ( pCachedValue->type == DBVT_DELETED ) ? 1 : 0;
} }
- ofsModuleName=GetModuleNameOfs(dbcgs->szModule);
- if(hContact==NULL) ofsContact=dbHeader.ofsUser;
- else ofsContact=(DWORD)hContact;
- dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ ofsModuleName = GetModuleNameOfs(dbcgs->szModule);
+ if (hContact == NULL) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ dbc = (DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc->signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
- if(ofsSettingsGroup) {
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
+ if (ofsSettingsGroup) {
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
pBlob = DBRead(ofsBlobPtr,sizeof(struct DBContactSettings),&bytesRemaining);
while(pBlob[0]) {
NeedBytes(1+settingNameLen);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) {
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) {
MoveAlong(1+settingNameLen);
NeedBytes(5);
- if(isStatic && pBlob[0]&DBVTF_VARIABLELENGTH && VLT(dbcgs->pValue->type) != VLT(pBlob[0])) {
+ if (isStatic && pBlob[0]&DBVTF_VARIABLELENGTH && VLT(dbcgs->pValue->type) != VLT(pBlob[0])) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- dbcgs->pValue->type=pBlob[0];
+ dbcgs->pValue->type = pBlob[0];
switch(pBlob[0]) {
case DBVT_DELETED: { /* this setting is deleted */
- dbcgs->pValue->type=DBVT_DELETED;
+ dbcgs->pValue->type = DBVT_DELETED;
LeaveCriticalSection(&csDbAccess);
return 2;
}
- case DBVT_BYTE: dbcgs->pValue->bVal=pBlob[1]; break;
+ case DBVT_BYTE: dbcgs->pValue->bVal = pBlob[1]; break;
case DBVT_WORD: DecodeCopyMemory(&(dbcgs->pValue->wVal), (PWORD)(pBlob+1), 2); break;
case DBVT_DWORD: DecodeCopyMemory(&(dbcgs->pValue->dVal), (PDWORD)(pBlob+1), 4); break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
NeedBytes(3+*(PWORD)(pBlob+1));
- if(isStatic) {
+ if (isStatic) {
dbcgs->pValue->cchVal--;
- if (*(PWORD)(pBlob+1)<dbcgs->pValue->cchVal) dbcgs->pValue->cchVal=*(PWORD)(pBlob+1);
+ if (*(PWORD)(pBlob+1)<dbcgs->pValue->cchVal) dbcgs->pValue->cchVal = *(PWORD)(pBlob+1);
DecodeCopyMemory(dbcgs->pValue->pszVal,pBlob+3,dbcgs->pValue->cchVal);
- dbcgs->pValue->pszVal[dbcgs->pValue->cchVal]=0;
- dbcgs->pValue->cchVal=*(PWORD)(pBlob+1);
+ dbcgs->pValue->pszVal[dbcgs->pValue->cchVal] = 0;
+ dbcgs->pValue->cchVal = *(PWORD)(pBlob+1);
}
else {
- dbcgs->pValue->pszVal=(char*)mir_alloc(1+*(PWORD)(pBlob+1));
+ dbcgs->pValue->pszVal = (char*)mir_alloc(1+*(PWORD)(pBlob+1));
DecodeCopyMemory(dbcgs->pValue->pszVal,pBlob+3,*(PWORD)(pBlob+1));
- dbcgs->pValue->pszVal[*(PWORD)(pBlob+1)]=0;
+ dbcgs->pValue->pszVal[*(PWORD)(pBlob+1)] = 0;
}
break;
case DBVT_BLOB:
NeedBytes(3+*(PWORD)(pBlob+1));
- if(isStatic) {
- if (*(PWORD)(pBlob+1)<dbcgs->pValue->cpbVal) dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1);
+ if (isStatic) {
+ if (*(PWORD)(pBlob+1)<dbcgs->pValue->cpbVal) dbcgs->pValue->cpbVal = *(PWORD)(pBlob+1);
DecodeCopyMemory(dbcgs->pValue->pbVal,pBlob+3,dbcgs->pValue->cpbVal);
}
else {
dbcgs->pValue->pbVal = (BYTE *)mir_alloc(*(PWORD)(pBlob+1));
DecodeCopyMemory(dbcgs->pValue->pbVal,pBlob+3,*(PWORD)(pBlob+1));
}
- dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1);
+ dbcgs->pValue->cpbVal = *(PWORD)(pBlob+1);
break;
}
@@ -397,11 +396,10 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
return 1;
}
-static INT_PTR GetContactSetting(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = ( DBCONTACTGETSETTING* )lParam;
dgs->pValue->type = 0;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 0 ))
+ if ( GetContactSettingWorker(hContact, dgs, 0 ))
return 1;
if ( dgs->pValue->type == DBVT_UTF8 ) {
@@ -432,12 +430,11 @@ static INT_PTR GetContactSetting(WPARAM wParam, LPARAM lParam)
return 0;
}
-static INT_PTR GetContactSettingStr(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStr(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = (DBCONTACTGETSETTING*)lParam;
int iSaveType = dgs->pValue->type;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 0 ))
+ if ( GetContactSettingWorker(hContact, dgs, 0 ))
return 1;
if ( iSaveType == 0 || iSaveType == dgs->pValue->type )
@@ -480,10 +477,9 @@ static INT_PTR GetContactSettingStr(WPARAM wParam, LPARAM lParam)
return 0;
}
-INT_PTR GetContactSettingStatic(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::GetContactSettingStatic(HANDLE hContact, DBCONTACTGETSETTING *dgs)
{
- DBCONTACTGETSETTING* dgs = (DBCONTACTGETSETTING*)lParam;
- if ( GetContactSettingWorker(( HANDLE )wParam, dgs, 1 ))
+ if ( GetContactSettingWorker(hContact, dgs, 1 ))
return 1;
if ( dgs->pValue->type == DBVT_UTF8 ) {
@@ -494,9 +490,8 @@ INT_PTR GetContactSettingStatic(WPARAM wParam, LPARAM lParam)
return 0;
}
-static INT_PTR FreeVariant(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::FreeVariant(DBVARIANT *dbv)
{
- DBVARIANT *dbv=(DBVARIANT*)lParam;
if ( dbv == 0 ) return 1;
switch ( dbv->type ) {
case DBVT_ASCIIZ:
@@ -504,29 +499,29 @@ static INT_PTR FreeVariant(WPARAM wParam, LPARAM lParam)
case DBVT_WCHAR:
{
if ( dbv->pszVal ) mir_free(dbv->pszVal);
- dbv->pszVal=0;
+ dbv->pszVal = 0;
break;
}
case DBVT_BLOB:
{
if ( dbv->pbVal ) mir_free(dbv->pbVal);
- dbv->pbVal=0;
+ dbv->pbVal = 0;
break;
}
}
- dbv->type=0;
+ dbv->type = 0;
return 0;
}
-static INT_PTR SetSettingResident(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::SetSettingResident(BOOL bIsResident, const char *pszSettingName)
{
- size_t cbSettingNameLen = strlen(( char* )lParam) + 2;
+ size_t cbSettingNameLen = strlen(pszSettingName) + 2;
if (cbSettingNameLen < 512)
{
char* szSetting;
int idx;
char szTemp[512];
- strcpy( szTemp+1, ( char* )lParam );
+ strcpy(szTemp+1, pszSettingName);
EnterCriticalSection(&csDbAccess);
if ( !List_GetIndex( &lSettings, szTemp, &idx ))
@@ -534,14 +529,14 @@ static INT_PTR SetSettingResident(WPARAM wParam, LPARAM lParam)
else
szSetting = (char *)lSettings.items[idx];
- *szSetting = (char)wParam;
+ *szSetting = (char)bIsResident;
if ( !List_GetIndex( &lResidentSettings, szSetting+1, &idx ))
{
- if (wParam)
+ if (bIsResident)
List_Insert(&lResidentSettings,szSetting+1,idx);
}
- else if (!wParam)
+ else if (!bIsResident)
List_Remove(&lResidentSettings,idx);
LeaveCriticalSection(&csDbAccess);
@@ -549,26 +544,25 @@ static INT_PTR SetSettingResident(WPARAM wParam, LPARAM lParam)
return 0;
}
-static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
{
- DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam;
DBCONTACTWRITESETTING tmp;
- struct DBContact dbc;
+ DBContact dbc;
DWORD ofsModuleName;
struct DBContactSettings dbcs;
PBYTE pBlob;
- int settingNameLen=0;
- int moduleNameLen=0;
- int settingDataLen=0;
+ int settingNameLen = 0;
+ int moduleNameLen = 0;
+ int settingDataLen = 0;
int bytesRequired,bytesRemaining;
DWORD ofsContact,ofsSettingsGroup,ofsBlobPtr;
- if (dbcws == NULL || dbcws->szSetting==NULL || dbcws->szModule==NULL )
+ if (dbcws == NULL || dbcws->szSetting == NULL || dbcws->szModule == NULL )
return 1;
// the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
- settingNameLen=(int)strlen(dbcws->szSetting);
- moduleNameLen=(int)strlen(dbcws->szModule);
+ settingNameLen = (int)strlen(dbcws->szSetting);
+ moduleNameLen = (int)strlen(dbcws->szModule);
if ( settingNameLen > 0xFE )
{
#ifdef _DEBUG
@@ -599,7 +593,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
else return 1;
}
- if(tmp.value.type!=DBVT_BYTE && tmp.value.type!=DBVT_WORD && tmp.value.type!=DBVT_DWORD && tmp.value.type!=DBVT_ASCIIZ && tmp.value.type!=DBVT_UTF8 && tmp.value.type!=DBVT_BLOB)
+ if (tmp.value.type!=DBVT_BYTE && tmp.value.type!=DBVT_WORD && tmp.value.type!=DBVT_DWORD && tmp.value.type!=DBVT_ASCIIZ && tmp.value.type!=DBVT_UTF8 && tmp.value.type!=DBVT_BLOB)
return 1;
if ((!tmp.szModule) || (!tmp.szSetting) || ((tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8 )&& tmp.value.pszVal == NULL) || (tmp.value.type == DBVT_BLOB && tmp.value.pbVal == NULL))
return 1;
@@ -621,7 +615,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
{
char* szCachedSettingName = GetCachedSetting(tmp.szModule, tmp.szSetting, moduleNameLen, settingNameLen);
if ( tmp.value.type != DBVT_BLOB ) {
- DBVARIANT* pCachedValue = GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, 1);
+ DBVARIANT* pCachedValue = GetCachedValuePtr(hContact, szCachedSettingName, 1);
if ( pCachedValue != NULL ) {
BOOL bIsIdentical = FALSE;
if ( pCachedValue->type == tmp.value.type ) {
@@ -641,53 +635,55 @@ static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
}
if ( szCachedSettingName[-1] != 0 ) {
LeaveCriticalSection(&csDbAccess);
- NotifyEventHooks(hSettingChangeEvent,wParam,(LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
return 0;
}
}
- else GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, -1);
+ else GetCachedValuePtr(hContact, szCachedSettingName, -1);
}
- ofsModuleName=GetModuleNameOfs(tmp.szModule);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
+ ofsModuleName = GetModuleNameOfs(tmp.szModule);
+ if (hContact == 0)
+ ofsContact = dbHeader.ofsUser;
+ else
+ ofsContact = (DWORD)hContact;
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc.signature!=DBCONTACT_SIGNATURE) {
+ dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc.signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
log0("write setting");
//make sure the module group exists
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsModuleName);
- if(ofsSettingsGroup==0) { //module group didn't exist - make it
- if(tmp.value.type&DBVTF_VARIABLELENGTH) {
- if(tmp.value.type==DBVT_ASCIIZ || tmp.value.type==DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2;
- else if(tmp.value.type==DBVT_BLOB) bytesRequired=tmp.value.cpbVal+2;
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsModuleName);
+ if (ofsSettingsGroup == 0) { //module group didn't exist - make it
+ if (tmp.value.type&DBVTF_VARIABLELENGTH) {
+ if (tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2;
+ else if (tmp.value.type == DBVT_BLOB) bytesRequired = tmp.value.cpbVal+2;
}
- else bytesRequired=tmp.value.type;
- bytesRequired+=2+settingNameLen;
- bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
- ofsSettingsGroup=CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
- dbcs.signature=DBCONTACTSETTINGS_SIGNATURE;
- dbcs.ofsNext=dbc.ofsFirstSettings;
- dbcs.ofsModuleName=ofsModuleName;
- dbcs.cbBlob=bytesRequired;
- dbcs.blob[0]=0;
- dbc.ofsFirstSettings=ofsSettingsGroup;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ else bytesRequired = tmp.value.type;
+ bytesRequired += 2+settingNameLen;
+ bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
+ ofsSettingsGroup = CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
+ dbcs.signature = DBCONTACTSETTINGS_SIGNATURE;
+ dbcs.ofsNext = dbc.ofsFirstSettings;
+ dbcs.ofsModuleName = ofsModuleName;
+ dbcs.cbBlob = bytesRequired;
+ dbcs.blob[0] = 0;
+ dbc.ofsFirstSettings = ofsSettingsGroup;
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
DBWrite(ofsSettingsGroup,&dbcs,sizeof(struct DBContactSettings));
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
else {
- dbcs=*(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
+ dbcs = *(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
//find if the setting exists
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(settingNameLen+1);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,tmp.szSetting,settingNameLen))
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,tmp.szSetting,settingNameLen))
break;
NeedBytes(1);
MoveAlong(pBlob[0]+1);
@@ -695,18 +691,18 @@ static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
MoveAlong(1+GetSettingValueLength(pBlob));
NeedBytes(1);
}
- if(pBlob[0]) { //setting already existed, and up to end of name is in cache
+ if (pBlob[0]) { //setting already existed, and up to end of name is in cache
MoveAlong(1+settingNameLen);
//if different type or variable length and length is different
NeedBytes(3);
- if(pBlob[0]!=tmp.value.type || ((pBlob[0]==DBVT_ASCIIZ || pBlob[0]==DBVT_UTF8) && *(PWORD)(pBlob+1)!=strlen(tmp.value.pszVal)) || (pBlob[0]==DBVT_BLOB && *(PWORD)(pBlob+1)!=tmp.value.cpbVal)) {
+ if (pBlob[0]!=tmp.value.type || ((pBlob[0] == DBVT_ASCIIZ || pBlob[0] == DBVT_UTF8) && *(PWORD)(pBlob+1)!=strlen(tmp.value.pszVal)) || (pBlob[0] == DBVT_BLOB && *(PWORD)(pBlob+1)!=tmp.value.cpbVal)) {
//bin it
int nameLen,valLen;
DWORD ofsSettingToCut;
NeedBytes(3);
- nameLen=1+settingNameLen;
- valLen=1+GetSettingValueLength(pBlob);
- ofsSettingToCut=ofsBlobPtr-nameLen;
+ nameLen = 1+settingNameLen;
+ valLen = 1+GetSettingValueLength(pBlob);
+ ofsSettingToCut = ofsBlobPtr-nameLen;
MoveAlong(valLen);
NeedBytes(1);
while(pBlob[0]) {
@@ -716,8 +712,8 @@ static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
NeedBytes(1);
}
DBMoveChunk(ofsSettingToCut,ofsSettingToCut+nameLen+valLen,ofsBlobPtr+1-ofsSettingToCut);
- ofsBlobPtr-=nameLen+valLen;
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr -= nameLen+valLen;
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
else {
//replace existing setting at pBlob
@@ -734,7 +730,7 @@ static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
//notify
- NotifyEventHooks(hSettingChangeEvent,wParam,(LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
return 0;
}
}
@@ -742,49 +738,49 @@ static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
//cannot do a simple replace, add setting to end of list
//pBlob already points to end of list
//see if it fits
- if(tmp.value.type&DBVTF_VARIABLELENGTH) {
- if(tmp.value.type==DBVT_ASCIIZ || tmp.value.type==DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2;
- else if(tmp.value.type==DBVT_BLOB) bytesRequired=tmp.value.cpbVal+2;
+ if (tmp.value.type&DBVTF_VARIABLELENGTH) {
+ if (tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2;
+ else if (tmp.value.type == DBVT_BLOB) bytesRequired = tmp.value.cpbVal+2;
}
- else bytesRequired=tmp.value.type;
- bytesRequired+=2+settingNameLen;
- bytesRequired+=ofsBlobPtr+1-(ofsSettingsGroup+offsetof(struct DBContactSettings,blob));
+ else bytesRequired = tmp.value.type;
+ bytesRequired += 2+settingNameLen;
+ bytesRequired += ofsBlobPtr+1-(ofsSettingsGroup+offsetof(struct DBContactSettings,blob));
if ((DWORD)bytesRequired>dbcs.cbBlob) {
//doesn't fit: move entire group
struct DBContactSettings *dbcsPrev;
DWORD ofsDbcsPrev,ofsNew;
- bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
+ bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
//find previous group to change its offset
- ofsDbcsPrev=dbc.ofsFirstSettings;
- if(ofsDbcsPrev==ofsSettingsGroup) ofsDbcsPrev=0;
+ ofsDbcsPrev = dbc.ofsFirstSettings;
+ if (ofsDbcsPrev == ofsSettingsGroup) ofsDbcsPrev = 0;
else {
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
while(dbcsPrev->ofsNext!=ofsSettingsGroup) {
- if(dbcsPrev->ofsNext==0) DatabaseCorruption(NULL);
- ofsDbcsPrev=dbcsPrev->ofsNext;
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ if (dbcsPrev->ofsNext == 0) DatabaseCorruption(NULL);
+ ofsDbcsPrev = dbcsPrev->ofsNext;
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
}
}
//create the new one
- ofsNew=ReallocSpace(ofsSettingsGroup, dbcs.cbBlob+offsetof(struct DBContactSettings,blob), bytesRequired+offsetof(struct DBContactSettings,blob));
+ ofsNew = ReallocSpace(ofsSettingsGroup, dbcs.cbBlob+offsetof(struct DBContactSettings,blob), bytesRequired+offsetof(struct DBContactSettings,blob));
- dbcs.cbBlob=bytesRequired;
+ dbcs.cbBlob = bytesRequired;
DBWrite(ofsNew,&dbcs,offsetof(struct DBContactSettings,blob));
- if(ofsDbcsPrev==0) {
- dbc.ofsFirstSettings=ofsNew;
- DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
+ if (ofsDbcsPrev == 0) {
+ dbc.ofsFirstSettings = ofsNew;
+ DBWrite(ofsContact,&dbc,sizeof(DBContact));
}
else {
- dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
- dbcsPrev->ofsNext=ofsNew;
+ dbcsPrev = (struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
+ dbcsPrev->ofsNext = ofsNew;
DBWrite(ofsDbcsPrev,dbcsPrev,offsetof(struct DBContactSettings,blob));
}
- ofsBlobPtr+=ofsNew-ofsSettingsGroup;
- ofsSettingsGroup=ofsNew;
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr += ofsNew-ofsSettingsGroup;
+ ofsSettingsGroup = ofsNew;
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
}
//we now have a place to put it and enough space: make it
DBWrite(ofsBlobPtr,&settingNameLen,1);
@@ -810,26 +806,25 @@ static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam)
MoveAlong(2+tmp.value.cpbVal);
break;
}
- { BYTE zero=0;
+ { BYTE zero = 0;
DBWrite(ofsBlobPtr,&zero,1);
}
//quit
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
//notify
- NotifyEventHooks(hSettingChangeEvent, wParam, (LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
return 0;
}
-static INT_PTR DeleteContactSetting(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::DeleteContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
{
- DBCONTACTGETSETTING *dbcgs=(DBCONTACTGETSETTING*)lParam;
- struct DBContact *dbc;
+ DBContact *dbc;
DWORD ofsModuleName,ofsSettingsGroup,ofsBlobPtr;
PBYTE pBlob;
int settingNameLen,moduleNameLen,bytesRemaining;
char* szCachedSettingName;
- WPARAM saveWparam = wParam;
+ HANDLE saveContact = hContact;
if ((!dbcgs->szModule) || (!dbcgs->szSetting))
return 1;
@@ -852,26 +847,27 @@ static INT_PTR DeleteContactSetting(WPARAM wParam, LPARAM lParam)
}
EnterCriticalSection(&csDbAccess);
- ofsModuleName=GetModuleNameOfs(dbcgs->szModule);
- if(wParam==0) wParam=dbHeader.ofsUser;
+ ofsModuleName = GetModuleNameOfs(dbcgs->szModule);
+ if (hContact == 0)
+ hContact = (HANDLE)dbHeader.ofsUser;
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
//make sure the module group exists
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
- if(ofsSettingsGroup==0) {
+ ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
+ if (ofsSettingsGroup == 0) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
//find if the setting exists
- ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ ofsBlobPtr = ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(settingNameLen+1);
- if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen))
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen))
break;
NeedBytes(1);
MoveAlong(pBlob[0]+1);
@@ -888,9 +884,9 @@ static INT_PTR DeleteContactSetting(WPARAM wParam, LPARAM lParam)
DWORD ofsSettingToCut;
MoveAlong(1+settingNameLen);
NeedBytes(3);
- nameLen=1+settingNameLen;
- valLen=1+GetSettingValueLength(pBlob);
- ofsSettingToCut=ofsBlobPtr-nameLen;
+ nameLen = 1+settingNameLen;
+ valLen = 1+GetSettingValueLength(pBlob);
+ ofsSettingToCut = ofsBlobPtr-nameLen;
MoveAlong(valLen);
NeedBytes(1);
while(pBlob[0]) {
@@ -903,25 +899,24 @@ static INT_PTR DeleteContactSetting(WPARAM wParam, LPARAM lParam)
}
szCachedSettingName = GetCachedSetting(dbcgs->szModule,dbcgs->szSetting,moduleNameLen,settingNameLen);
- GetCachedValuePtr((HANDLE)saveWparam, szCachedSettingName, -1 );
+ GetCachedValuePtr(saveContact, szCachedSettingName, -1);
//quit
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
{ //notify
- DBCONTACTWRITESETTING dbcws={0};
- dbcws.szModule=dbcgs->szModule;
- dbcws.szSetting=dbcgs->szSetting;
- dbcws.value.type=DBVT_DELETED;
- NotifyEventHooks(hSettingChangeEvent,saveWparam,(LPARAM)&dbcws);
+ DBCONTACTWRITESETTING dbcws = {0};
+ dbcws.szModule = dbcgs->szModule;
+ dbcws.szSetting = dbcgs->szSetting;
+ dbcws.value.type = DBVT_DELETED;
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)saveContact, (LPARAM)&dbcws);
}
return 0;
}
-static INT_PTR EnumContactSettings(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces)
{
- DBCONTACTENUMSETTINGS *dbces=(DBCONTACTENUMSETTINGS*)lParam;
- struct DBContact *dbc;
+ DBContact *dbc;
DWORD ofsModuleName,ofsContact,ofsBlobPtr;
int bytesRemaining, result;
PBYTE pBlob;
@@ -932,22 +927,22 @@ static INT_PTR EnumContactSettings(WPARAM wParam, LPARAM lParam)
EnterCriticalSection(&csDbAccess);
- ofsModuleName=GetModuleNameOfs(dbces->szModule);
- if(wParam==0) ofsContact=dbHeader.ofsUser;
- else ofsContact=wParam;
- dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
+ ofsModuleName = GetModuleNameOfs(dbces->szModule);
+ if (hContact == 0) ofsContact = dbHeader.ofsUser;
+ else ofsContact = (DWORD)hContact;
+ dbc = (DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ if (dbc->signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- dbces->ofsSettings=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
+ dbces->ofsSettings = GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
if (!dbces->ofsSettings) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- ofsBlobPtr=dbces->ofsSettings+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
- if(pBlob[0]==0) {
+ ofsBlobPtr = dbces->ofsSettings+offsetof(struct DBContactSettings,blob);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ if (pBlob[0] == 0) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
@@ -955,7 +950,7 @@ static INT_PTR EnumContactSettings(WPARAM wParam, LPARAM lParam)
while(pBlob[0]) {
NeedBytes(1);
NeedBytes(1+pBlob[0]);
- CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]]=0;
+ CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]] = 0;
result = (dbces->pfnEnumProc)(szSetting,dbces->lParam);
MoveAlong(1+pBlob[0]);
NeedBytes(3);
@@ -966,13 +961,13 @@ static INT_PTR EnumContactSettings(WPARAM wParam, LPARAM lParam)
return result;
}
-static INT_PTR EnumResidentSettings(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDdxMmap::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
{
int i;
int ret;
for(i = 0; i < lResidentSettings.realCount; i++) {
- ret = ((DBMODULEENUMPROC)lParam)((char *)lResidentSettings.items[i], 0, wParam);
- if(ret) return ret;
+ ret = pFunc((char*)lResidentSettings.items[i], 0, (LPARAM)pParam);
+ if (ret) return ret;
}
return 0;
}
@@ -980,15 +975,15 @@ static INT_PTR EnumResidentSettings(WPARAM wParam, LPARAM lParam)
extern Cryptor* CryptoEngine;
extern void* key;
-void EncodeContactSettings(HANDLE hContact)
+void CDdxMmap::EncodeContactSettings(HANDLE hContact)
{
- struct DBContact * contact;
+ DBContact * contact;
struct DBContactSettings * setting;
DWORD offset;
if (!hContact) hContact = (HANDLE)dbHeader.ofsUser;
- contact = (struct DBContact *)DBRead((DWORD)hContact, sizeof(struct DBContact), NULL);
- if(contact -> ofsFirstSettings){
+ contact = (DBContact *)DBRead((DWORD)hContact, sizeof(DBContact), NULL);
+ if (contact -> ofsFirstSettings){
setting = (struct DBContactSettings *)DBRead(contact -> ofsFirstSettings, sizeof(struct DBContactSettings), NULL);
offset = contact -> ofsFirstSettings;
do{
@@ -1003,11 +998,11 @@ void EncodeContactSettings(HANDLE hContact)
namestr[name->cbName] = '\0';
MessageBox(0, namestr, "Module", MB_OK);*/
ofsBlobPtr = offset + offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(1);
NeedBytes(1+pBlob[0]);
- //CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]]=0;
+ //CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]] = 0;
MoveAlong(1+pBlob[0]);
NeedBytes(5);
@@ -1041,7 +1036,7 @@ void EncodeContactSettings(HANDLE hContact)
NeedBytes(1);
}
- if(setting -> ofsNext){
+ if (setting -> ofsNext){
offset = setting -> ofsNext;
setting = (struct DBContactSettings *)DBRead(setting -> ofsNext, sizeof(struct DBContactSettings), NULL);
}
@@ -1049,19 +1044,18 @@ void EncodeContactSettings(HANDLE hContact)
break;
}while(1);
}
-
-
}
-void DecodeContactSettings(HANDLE hContact)
+
+void CDdxMmap::DecodeContactSettings(HANDLE hContact)
{
- struct DBContact * contact;
+ DBContact * contact;
struct DBContactSettings * setting;
DWORD offset;
if (!hContact) hContact = (HANDLE)dbHeader.ofsUser;
- contact = (struct DBContact *)DBRead((DWORD)hContact, sizeof(struct DBContact), NULL);
- if(contact -> ofsFirstSettings){
+ contact = (DBContact *)DBRead((DWORD)hContact, sizeof(DBContact), NULL);
+ if (contact -> ofsFirstSettings){
setting = (struct DBContactSettings *)DBRead(contact -> ofsFirstSettings, sizeof(struct DBContactSettings), NULL);
offset = contact -> ofsFirstSettings;
do{
@@ -1070,11 +1064,11 @@ void DecodeContactSettings(HANDLE hContact)
int bytesRemaining;
DWORD len;
ofsBlobPtr = offset + offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
while(pBlob[0]) {
NeedBytes(1);
NeedBytes(1+pBlob[0]);
- //CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]]=0;
+ //CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]] = 0;
MoveAlong(1+pBlob[0]);
NeedBytes(5);
@@ -1108,7 +1102,7 @@ void DecodeContactSettings(HANDLE hContact)
NeedBytes(1);
}
- if(setting -> ofsNext){
+ if (setting -> ofsNext){
offset = setting -> ofsNext;
setting = (struct DBContactSettings *)DBRead(setting -> ofsNext, sizeof(struct DBContactSettings), NULL);
}
@@ -1134,16 +1128,6 @@ static int stringCompare2( char* p1, char* p2 )
int InitSettings(void)
{
- CreateServiceFunction(MS_DB_CONTACT_GETSETTING, GetContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_GETSETTING_STR, GetContactSettingStr);
- CreateServiceFunction(MS_DB_CONTACT_GETSETTINGSTATIC, GetContactSettingStatic);
- CreateServiceFunction(MS_DB_CONTACT_FREEVARIANT, FreeVariant);
- CreateServiceFunction(MS_DB_CONTACT_WRITESETTING, WriteContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_DELETESETTING, DeleteContactSetting);
- CreateServiceFunction(MS_DB_CONTACT_ENUMSETTINGS, EnumContactSettings);
- CreateServiceFunction(MS_DB_SETSETTINGRESIDENT, SetSettingResident);
- CreateServiceFunction("DB/ResidentSettings/Enum", EnumResidentSettings);
-
hSettingChangeEvent = CreateHookableEvent(ME_DB_CONTACT_SETTINGCHANGED);
hCacheHeap = HeapCreate(0, 0, 0);
diff --git a/plugins/Dbx_mmap_SA/dialogs.cpp b/plugins/Dbx_mmap_SA/dialogs.cpp
index c5503773ce..7bd1347647 100644
--- a/plugins/Dbx_mmap_SA/dialogs.cpp
+++ b/plugins/Dbx_mmap_SA/dialogs.cpp
@@ -61,11 +61,13 @@ static int OptionsInit(WPARAM wParam, LPARAM lParam)
INT_PTR ChangePassword(WPARAM wParam, LPARAM lParam)
{
- if(bEncoding){
- ChangePwd();
- }else{
- EncryptDB();
+ if (g_Db) {
+ if (bEncoding)
+ g_Db->ChangePwd();
+ else
+ g_Db->EncryptDB();
}
+
return 0;
}
@@ -75,11 +77,11 @@ void xModifyMenu(HANDLE hMenu,long flags,const TCHAR* name, HICON hIcon)
ZeroMemory(&menu,sizeof(menu));
menu.cbSize = sizeof(menu);
menu.flags = CMIM_FLAGS | CMIF_TCHAR;
- menu.flags |= name ? CMIM_NAME : 0;
- menu.flags |= hIcon ? CMIM_ICON : 0;
- menu.flags |= flags;
+ menu.flags |= name ? CMIM_NAME : 0;
+ menu.flags |= hIcon ? CMIM_ICON : 0;
+ menu.flags |= flags;
menu.ptszName = (TCHAR*)name;
- menu.hIcon=hIcon;
+ menu.hIcon = hIcon;
CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)hMenu,(LPARAM)&menu);
}
@@ -96,18 +98,18 @@ static int ModulesLoad(WPARAM wParam, LPARAM lParam)
// icolib init
GetModuleFileName(g_hInst, szFile, MAX_PATH);
- sid.cbSize = sizeof(sid);
- sid.ptszDefaultFile = szFile;
- sid.flags = SIDF_ALL_TCHAR;
- sid.ptszSection = LPGENT("Database");
+ sid.cbSize = sizeof(sid);
+ sid.ptszDefaultFile = szFile;
+ sid.flags = SIDF_ALL_TCHAR;
+ sid.ptszSection = LPGENT("Database");
sid.ptszDescription = LPGENT("Database");
- sid.pszName = "database";
- sid.iDefaultIndex = -IDI_ICON2;
+ sid.pszName = "database";
+ sid.iDefaultIndex = -IDI_ICON2;
Skin_AddIcon(&sid);
sid.ptszDescription = LPGENT("Change Password");
- sid.pszName = "password";
- sid.iDefaultIndex = -IDI_ICON3;
+ sid.pszName = "password";
+ sid.iDefaultIndex = -IDI_ICON3;
Skin_AddIcon(&sid);
menu.cbSize = sizeof(menu);
@@ -124,9 +126,9 @@ static int ModulesLoad(WPARAM wParam, LPARAM lParam)
hSetPwdMenu = Menu_AddMainMenuItem(&menu);
ZeroMemory(&menu,sizeof(menu));
- menu.cbSize = sizeof(menu);
- menu.flags = CMIM_ICON;
- menu.hIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"password");
+ menu.cbSize = sizeof(menu);
+ menu.flags = CMIM_ICON;
+ menu.hIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"password");
CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hSetPwdMenu, (LPARAM)&menu);
return 0;
@@ -221,7 +223,7 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
mir_snprintf(buf,SIZEOF(buf),"%d.%d.%d.%d", HIBYTE(HIWORD(Modules[i]->cryptor->Version)), LOBYTE(HIWORD(Modules[i]->cryptor->Version)), HIBYTE(LOWORD(Modules[i]->cryptor->Version)), LOBYTE(LOWORD(Modules[i]->cryptor->Version)));
ListView_SetItemText(hwndList, iRow, 3, (LPWSTR)buf);
- if(uid == Modules[i]->cryptor->uid && bEncoding)
+ if (uid == Modules[i]->cryptor->uid && bEncoding)
ListView_SetCheckState(hwndList, i, 1);
item.mask = LVIF_IMAGE;
@@ -247,7 +249,7 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
char * p = &buf[7];
lstrcpyA(buf,"mailto:");
if ( GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), p, SIZEOF(buf) - 7)) {
- CallService(MS_UTILS_OPENURL,0,(LPARAM) (LOWORD(wParam)==IDC_EMAIL ? buf : p));
+ CallService(MS_UTILS_OPENURL,0,(LPARAM) (LOWORD(wParam) == IDC_EMAIL ? buf : p));
}
break;
} } }
@@ -256,18 +258,18 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
case WM_NOTIFY:
if ( hdr && hdr->hdr.code == LVN_ITEMCHANGED && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) {
iIndex = hdr->iItem;
- if(hdr->uNewState & 0x2000){
+ if (hdr->uNewState & 0x2000){
for(i = 0; i < ModulesCount; i++) {
- if(i != iIndex) ListView_SetCheckState(hwndList, i, 0);
+ if (i != iIndex) ListView_SetCheckState(hwndList, i, 0);
}
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
}
- if(hdr->uNewState & 0x1000){
+ if (hdr->uNewState & 0x1000){
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
}
- if(hdr->uNewState & LVIS_SELECTED){
+ if (hdr->uNewState & LVIS_SELECTED){
SetDlgItemTextA(hwndDlg, IDC_AUTHOR, Modules[iIndex]->cryptor->Author);
{
TCHAR* info_t = mir_a2t((char*)(Modules[iIndex]->cryptor->Info));
@@ -292,32 +294,31 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
if (((LPNMHDR)lParam)->code == PSN_APPLY ) {
int alg = -1;
for(i = 0; i < ModulesCount; i++) {
- if(ListView_GetCheckState(hwndList, i)) {
+ if (ListView_GetCheckState(hwndList, i)) {
alg = i;
break;
}
}
- if(alg > -1){
+ if (alg > -1){
if (!bEncoding){
DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", Modules[alg]->cryptor->uid);
- EncryptDB();
- }else{
- if(Modules[alg]->cryptor->uid != DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", -1)) {
+ g_Db->EncryptDB();
+ }
+ else {
+ if (Modules[alg]->cryptor->uid != DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", -1)) {
DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", Modules[alg]->cryptor->uid);
- RecryptDB();
+ g_Db->RecryptDB();
}
}
- }else{
- if(bEncoding){
- DecryptDB();
- }
}
+ else if (bEncoding)
+ g_Db->DecryptDB();
uid = DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0);
for(i = 0; i < ModulesCount; i++) {
- if(uid == Modules[i]->cryptor->uid && bEncoding)
+ if (uid == Modules[i]->cryptor->uid && bEncoding)
ListView_SetCheckState(hwndList, i, 1);
item.mask = LVIF_IMAGE;
@@ -412,7 +413,7 @@ BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam)
{
UINT uid = LOWORD(wParam);
- if(uid == IDOK){
+ if (uid == IDOK){
if (!GetWindowLongPtr(hDlg,GWLP_USERDATA))
{
encryptKeyLength = GetDlgItemTextA(hDlg, IDC_USERPASS, encryptKey, 254);
@@ -420,7 +421,7 @@ BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam)
}else{
}
- }else if(uid == IDCANCEL){
+ }else if (uid == IDCANCEL){
EndDialog(hDlg,IDCANCEL);
}
}
@@ -477,11 +478,11 @@ BOOL CALLBACK DlgStdNewPass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam)
{
UINT uid = LOWORD(wParam);
- if(uid == IDOK){
+ if (uid == IDOK){
if (!GetWindowLongPtr(hDlg,GWLP_USERDATA))
{
char pass1[255], pass2[255];
- if(GetDlgItemTextA(hDlg, IDC_USERPASS1, pass1, 254) < 3){
+ if (GetDlgItemTextA(hDlg, IDC_USERPASS1, pass1, 254) < 3){
SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is too short!"));
SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0);
SetDlgItemTextA(hDlg,IDC_USERPASS1,"");
@@ -503,7 +504,7 @@ BOOL CALLBACK DlgStdNewPass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam)
}else{
}
- }else if(uid == IDCANCEL){
+ }else if (uid == IDCANCEL){
EndDialog(hDlg,IDCANCEL);
}
}
@@ -562,15 +563,15 @@ BOOL CALLBACK DlgChangePass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam)
{
UINT uid = LOWORD(wParam);
- if(uid == IDOK){
+ if (uid == IDOK){
char pass1[255], pass2[255], oldpass[255];
GetDlgItemTextA(hDlg, IDC_OLDPASS, oldpass, 254);
- if(strcmp(oldpass, encryptKey)) {
+ if (strcmp(oldpass, encryptKey)) {
SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Wrong password!"));
SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0);
break;
}
- if(GetDlgItemTextA(hDlg, IDC_NEWPASS1, pass1, 254) < 3){
+ if (GetDlgItemTextA(hDlg, IDC_NEWPASS1, pass1, 254) < 3){
SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is too short!"));
SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0);
@@ -584,12 +585,12 @@ BOOL CALLBACK DlgChangePass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam)
SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0);
}
}
- }else if(uid == IDCANCEL){
+ }else if (uid == IDCANCEL){
EndDialog(hDlg,IDCANCEL);
- }else if(uid == IDREMOVE){
+ }else if (uid == IDREMOVE){
char oldpass[255];
GetDlgItemTextA(hDlg, IDC_OLDPASS, oldpass, 254);
- if(strcmp(oldpass, encryptKey)) {
+ if (strcmp(oldpass, encryptKey)) {
SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Wrong password!"));
SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0);
break;
diff --git a/plugins/Dbx_mmap_SA/encrypt.cpp b/plugins/Dbx_mmap_SA/encrypt.cpp
index a42d79eae2..0837e5cbd8 100644
--- a/plugins/Dbx_mmap_SA/encrypt.cpp
+++ b/plugins/Dbx_mmap_SA/encrypt.cpp
@@ -32,16 +32,16 @@ void Encrypt(char*msg,BOOL up)
int jump;
if (up)
{
- jump=5;
+ jump = 5;
}
else
{
- jump=-5;
+ jump = -5;
}
- for (i=0;msg[i];i++)
+ for (i = 0;msg[i];i++)
{
- msg[i]=msg[i]+jump;
+ msg[i] = msg[i]+jump;
}
}
diff --git a/plugins/Dbx_mmap_SA/init.cpp b/plugins/Dbx_mmap_SA/init.cpp
index 4996bed435..97c6353d69 100644
--- a/plugins/Dbx_mmap_SA/init.cpp
+++ b/plugins/Dbx_mmap_SA/init.cpp
@@ -25,10 +25,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int hLangpack;
-extern char szDbPath[MAX_PATH];
+extern TCHAR szDbPath[MAX_PATH];
HINSTANCE g_hInst = NULL;
+CDdxMmap* g_Db = NULL;
PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
@@ -50,43 +51,43 @@ static int getCapability( int flag )
}
// returns 0 if the profile is created, EMKPRF*
-static int makeDatabase(char * profile, int * error)
+static int makeDatabase(TCHAR *profile, int *error)
{
- HANDLE hFile=CreateFileA(profile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+ HANDLE hFile = CreateFile(profile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
if ( hFile != INVALID_HANDLE_VALUE ) {
CreateDbHeaders(hFile);
CloseHandle(hFile);
return 0;
}
- if ( error != NULL ) *error=EMKPRF_CREATEFAILED;
+ if ( error != NULL ) *error = EMKPRF_CREATEFAILED;
return 1;
}
// returns 0 if the given profile has a valid header
-static int grokHeader( char * profile, int * error )
+static int grokHeader(TCHAR *profile, int *error )
{
- int rc=1;
- int chk=0;
+ int rc = 1;
+ int chk = 0;
struct DBHeader hdr;
HANDLE hFile = INVALID_HANDLE_VALUE;
- DWORD dummy=0;
+ DWORD dummy = 0;
- hFile = CreateFileA(profile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ hFile = CreateFile(profile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if ( hFile == INVALID_HANDLE_VALUE ) {
- if ( error != NULL ) *error=EGROKPRF_CANTREAD;
+ if ( error != NULL ) *error = EGROKPRF_CANTREAD;
return 1;
}
// read the header, which can fail (for various reasons)
if ( !ReadFile(hFile, &hdr, sizeof(struct DBHeader), &dummy, NULL)) {
- if ( error != NULL) *error=EGROKPRF_CANTREAD;
+ if ( error != NULL) *error = EGROKPRF_CANTREAD;
CloseHandle(hFile);
return 1;
}
- chk=CheckDbHeaders(&hdr);
+ chk = CheckDbHeaders(&hdr);
if ( chk == 0 ) {
// all the internal tests passed, hurrah
- rc=0;
- if ( error != NULL ) *error=0;
+ rc = 0;
+ if ( error != NULL ) *error = 0;
} else {
// didn't pass at all, or some did.
switch ( chk ) {
@@ -99,13 +100,13 @@ static int grokHeader( char * profile, int * error )
case 2:
{
// header was present, but version information newer
- if ( error != NULL ) *error= EGROKPRF_VERNEWER;
+ if ( error != NULL ) *error = EGROKPRF_VERNEWER;
break;
}
case 3:
{
// header/version OK, internal data missing
- if ( error != NULL ) *error=EGROKPRF_DAMAGED;
+ if ( error != NULL ) *error = EGROKPRF_DAMAGED;
break;
}
} // switch
@@ -115,10 +116,13 @@ static int grokHeader( char * profile, int * error )
}
// returns 0 if all the APIs are injected otherwise, 1
-static int LoadDatabase(char *profile)
+static MIDatabase* LoadDatabase(TCHAR *profile)
{
+ if (g_Db) delete g_Db;
+ g_Db = new CDdxMmap(profile);
+
// don't need thread notifications
- strncpy(szDbPath, profile, sizeof(szDbPath));
+ _tcsncpy(szDbPath, profile, SIZEOF(szDbPath));
// set the memory, lists & UTF8 manager
mir_getLP( &pluginInfo );
@@ -143,7 +147,9 @@ static int LoadDatabase(char *profile)
}
// inject all APIs and hooks into the core
- return LoadDatabaseModule();
+ LoadDatabaseModule();
+
+ return g_Db;
}
static int UnloadDatabase(int wasLoaded)
@@ -153,9 +159,9 @@ static int UnloadDatabase(int wasLoaded)
return 0;
}
-static int getFriendlyName( char * buf, size_t cch, int shortName )
+static int getFriendlyName( TCHAR* buf, size_t cch, int shortName )
{
- strncpy(buf,shortName ? "db3x secured_mmap driver" : "db3x mmap database support",cch);
+ _tcsncpy(buf,shortName ? _T("db3x secured_mmap driver") : _T("db3x mmap database support"), cch);
return 0;
}
@@ -171,7 +177,7 @@ static DATABASELINK dblink = {
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID reserved)
{
- g_hInst=hInstDLL;
+ g_hInst = hInstDLL;
return TRUE;
}
diff --git a/plugins/Dbx_mmap_SA/security.cpp b/plugins/Dbx_mmap_SA/security.cpp
index 53eddc4816..618476e12f 100644
--- a/plugins/Dbx_mmap_SA/security.cpp
+++ b/plugins/Dbx_mmap_SA/security.cpp
@@ -41,9 +41,9 @@ void InitSecurity()
strcat(tmp, fd.cFileName);
hLib = LoadLibraryA(tmp);
- if(hLib){
+ if (hLib){
GetCryptor = (Cryptor* (__stdcall *)()) GetProcAddress(hLib, "GetCryptor");
- if(GetCryptor){
+ if (GetCryptor){
Modules[ModulesCount] = (CryptoModule*) malloc(sizeof(CryptoModule));
Modules[ModulesCount]->cryptor = GetCryptor();
strcpy(Modules[ModulesCount]->dllname, fd.cFileName);
@@ -54,7 +54,7 @@ void InitSecurity()
FreeLibrary(hLib);
}
}
- if(ModulesCount >= 100) break;
+ if (ModulesCount >= 100) break;
if (!FindNextFileA(hFile, &fd)) break;
}
}
@@ -63,7 +63,7 @@ void UnloadSecurity()
{
int i;
- if(CryptoEngine) CryptoEngine->FreeKey(key);
+ if (CryptoEngine) CryptoEngine->FreeKey(key);
for(i = 0; i < ModulesCount; i++)
{
@@ -102,7 +102,7 @@ void DecodeCopyMemory(void * dst, void * src, size_t size )
void EncodeDBWrite(DWORD ofs, void * src, size_t size)
{
- if(bEncoding)
+ if (bEncoding)
{
BYTE * buf;
@@ -120,7 +120,7 @@ void EncodeDBWrite(DWORD ofs, void * src, size_t size)
void DecodeDBWrite(DWORD ofs, void * src, size_t size)
{
- if(bEncoding)
+ if (bEncoding)
{
BYTE * buf;
@@ -137,19 +137,19 @@ void DecodeDBWrite(DWORD ofs, void * src, size_t size)
int bCheckingPass = 0;
-int CheckPassword(WORD checkWord, char * szDBName)
+int CDdxMmap::CheckPassword(WORD checkWord, TCHAR *szDBName)
{
WORD ver;
int res;
- if(bCheckingPass) return 0;
+ if (bCheckingPass) return 0;
bCheckingPass = 1;
{
int i;
int Found = 0;
for(i = 0; i < ModulesCount; i++) {
- if(dbHeader.cryptorUID == Modules[i]->cryptor->uid){
+ if (dbHeader.cryptorUID == Modules[i]->cryptor->uid){
CryptoEngine = Modules[i]->cryptor;
Found = 1;
break;
@@ -164,16 +164,16 @@ int CheckPassword(WORD checkWord, char * szDBName)
while(1){
res = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_LOGIN), NULL, (DLGPROC)DlgStdInProc, (LPARAM)szDBName);
- if(res == IDCANCEL)
+ if (res == IDCANCEL)
{
wrongPass = 0;
bCheckingPass = 0;
return 0;
}
- if(encryptKeyLength < 1) continue;
+ if (encryptKeyLength < 1) continue;
EncoderInit();
DecodeCopyMemory(&ver, &checkWord, sizeof(checkWord));
- if(ver == 0x5195)
+ if (ver == 0x5195)
{
wrongPass = 0;
bCheckingPass = 0;
@@ -190,14 +190,14 @@ int SelectEncoder()
WORD uid;
int i;
- if(ModulesCount == 0){
+ if (ModulesCount == 0){
MessageBox(0, TranslateT("Crypto modules not found"), TranslateT("Error"), MB_OK);
return 1;
}
uid = DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0);
- if(uid == 0){
+ if (uid == 0){
MessageBox(0, TranslateT("Crypto module hasn't been chosen, using first one found"), TranslateT("Notice"), MB_OK);
DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", Modules[0]->cryptor->uid);
CryptoEngine = Modules[0]->cryptor;
@@ -205,7 +205,7 @@ int SelectEncoder()
else{
int Found = 0;
for(i = 0; i < ModulesCount; i++) {
- if(Modules[i]->cryptor->uid == uid){
+ if (Modules[i]->cryptor->uid == uid){
CryptoEngine = Modules[i]->cryptor;
Found = 1;
break;
@@ -221,28 +221,29 @@ int SelectEncoder()
return 0;
}
-void EncodeAll()
+void CDdxMmap::EncodeAll()
{
HANDLE hContact;
hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
- if(hContact){
- do{
+ if (hContact){
+ do {
EncodeContactEvents(hContact);
EncodeContactSettings(hContact);
- }while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0));
+ }
+ while(hContact = FindNextContact(hContact));
}
EncodeContactEvents(NULL);
EncodeContactSettings(NULL);
}
-void DecodeAll()
+void CDdxMmap::DecodeAll()
{
HANDLE hContact;
hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
- if(hContact){
+ if (hContact){
do{
DecodeContactEvents(hContact);
DecodeContactSettings(hContact);
@@ -252,7 +253,7 @@ void DecodeAll()
DecodeContactSettings(NULL);
}
-void WritePlainHeader()
+void CDdxMmap::WritePlainHeader()
{
DWORD bytesWritten;
@@ -270,7 +271,7 @@ void WritePlainHeader()
}
}
-void WriteCryptHeader()
+void CDdxMmap::WriteCryptHeader()
{
DWORD bytesWritten;
@@ -288,24 +289,24 @@ void WriteCryptHeader()
}
}
-void EncryptDB()
+void CDdxMmap::EncryptDB()
{
int action = 0;
- if(bEncProcess) return;
+ if (bEncProcess) return;
- if(memcmp(dbHeader.signature, &dbSignatureSecured, sizeof(dbHeader.signature)) == 0){
+ if (memcmp(dbHeader.signature, &dbSignatureSecured, sizeof(dbHeader.signature)) == 0){
MessageBox(0, TranslateT("DB is already secured!"), TranslateT("Error"), MB_OK);
return;
}
- if(SelectEncoder()) {
+ if (SelectEncoder()) {
return;
}
bEncProcess = 1;
action = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_NEWPASS), NULL, (DLGPROC)DlgStdNewPass, (LPARAM)NULL);
- if(action != IDOK || !strlen(encryptKey)) {
+ if (action != IDOK || !strlen(encryptKey)) {
bEncProcess = 0;
db_set_b(NULL, "SecureMMAP", "CryptoModule", 0);
return;
@@ -327,12 +328,16 @@ void EncryptDB()
bEncProcess = 0;
}
-void DecryptDB()
+void CDdxMmap::DecryptDB()
{
char oldKey[255];
strcpy(oldKey, encryptKey);
- if (!CheckPassword(dbHeader.checkWord, Translate("current database"))){strcpy(encryptKey, oldKey); encryptKeyLength = strlen(oldKey); return;}
+ if ( !CheckPassword(dbHeader.checkWord, TranslateT("current database"))) {
+ strcpy(encryptKey, oldKey);
+ encryptKeyLength = strlen(oldKey);
+ return;
+ }
WritePlainHeader();
@@ -353,7 +358,7 @@ void DecryptDB()
CryptoEngine = NULL;
}
-void RecryptDB()
+void CDdxMmap::RecryptDB()
{
EnterCriticalSection(&csDbAccess);
@@ -374,13 +379,13 @@ void RecryptDB()
LeaveCriticalSection(&csDbAccess);
}
-void ChangePwd()
+void CDdxMmap::ChangePwd()
{
char newpass[255] = {0};
int action = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHANGEPASS), NULL, (DLGPROC)DlgChangePass, (LPARAM)newpass);
- if(action == IDCANCEL || (action == IDOK && !strlen(newpass)))
+ if (action == IDCANCEL || (action == IDOK && !strlen(newpass)))
return;
EnterCriticalSection(&csDbAccess);
@@ -389,7 +394,7 @@ void ChangePwd()
CryptoEngine->FreeKey(key);
- if(action == IDREMOVE){
+ if (action == IDREMOVE){
WritePlainHeader();
bEncoding = 0;
@@ -401,7 +406,7 @@ void ChangePwd()
xModifyMenu(hSetPwdMenu, 0, LPGENT("Set Password"), 0);
}
- if(action == IDOK){
+ if (action == IDOK){
strcpy(encryptKey, newpass);
encryptKeyLength = strlen(newpass);
diff --git a/plugins/Dbx_tree/Compatibility.cpp b/plugins/Dbx_tree/Compatibility.cpp
index 4cfe37925b..9247e4d744 100644
--- a/plugins/Dbx_tree/Compatibility.cpp
+++ b/plugins/Dbx_tree/Compatibility.cpp
@@ -23,23 +23,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Compatibility.h"
#include "Logger.h"
#define DB_NOHELPERFUNCTIONS
- #include "m_database.h"
+#include "m_database.h"
+#include "m_db_int.h"
#undef DB_NOHELPERFUNCTIONS
#ifndef _MSC_VER
#include "savestrings_gcc.h"
#endif
-HANDLE gCompServices[31] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
HANDLE gEvents[6] = {0,0,0,0,0,0};
HANDLE hEventDeletedEvent,
hEventAddedEvent,
- hEventFilterAddedEvent,
- hSettingChangeEvent,
- hContactDeletedEvent,
- hContactAddedEvent;
+ hEventFilterAddedEvent,
+ hSettingChangeEvent,
+ hContactDeletedEvent,
+ hContactAddedEvent;
-INT_PTR CompAddContact(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(HANDLE) CDataBase::AddContact(void)
{
TDBTEntity entity = {0,0,0,0};
entity.hParentEntity = DBEntityGetRoot(0, 0);
@@ -47,28 +47,31 @@ INT_PTR CompAddContact(WPARAM wParam, LPARAM lParam)
TDBTEntityHandle res = gDataBase->getEntities().CreateEntity(entity);
if (res == DBT_INVALIDPARAM)
- return 1;
+ return (HANDLE)1;
NotifyEventHooks(hContactAddedEvent, res, 0);
- return res;
+ return (HANDLE)res;
}
-INT_PTR CompDeleteContact(WPARAM hContact, LPARAM lParam)
+
+STDMETHODIMP_(LONG) CDataBase::DeleteContact(HANDLE hContact)
{
- NotifyEventHooks(hContactDeletedEvent, hContact, 0);
+ NotifyEventHooks(hContactDeletedEvent, (WPARAM)hContact, 0);
- int res = DBEntityDelete(hContact, 0);
+ int res = DBEntityDelete((WPARAM)hContact, 0);
if (res == DBT_INVALIDPARAM)
return 1;
return res;
}
-INT_PTR CompIsDbContact(WPARAM hContact, LPARAM lParam)
+
+STDMETHODIMP_(BOOL) CDataBase::IsDbContact(HANDLE hContact)
{
- int flags = DBEntityGetFlags(hContact, 0);
+ int flags = DBEntityGetFlags((WPARAM)hContact, 0);
return (flags != DBT_INVALIDPARAM) &&
((flags & DBT_NFM_SpecialEntity) == 0);
}
-INT_PTR CompGetContactCount(WPARAM wParam, LPARAM lParam)
+
+STDMETHODIMP_(LONG) CDataBase::GetContactCount(void)
{
TDBTEntityIterFilter f = {0,0,0,0};
f.cbSize = sizeof(f);
@@ -92,18 +95,21 @@ INT_PTR CompGetContactCount(WPARAM wParam, LPARAM lParam)
}
return c;
}
-INT_PTR CompFindFirstContact(WPARAM wParam, LPARAM lParam)
+
+//!!!!!!!!!!!!!!!!!!!! szProto ignored
+STDMETHODIMP_(HANDLE) CDataBase::FindFirstContact(const char* szProto)
{
- return gDataBase->getEntities().compFirstContact();
+ return (HANDLE)gDataBase->getEntities().compFirstContact();
}
-INT_PTR CompFindNextContact(WPARAM hContact, LPARAM lParam)
+
+//!!!!!!!!!!!!!!!!!!!! szProto ignored
+STDMETHODIMP_(HANDLE) CDataBase::FindNextContact(HANDLE hContact, const char* szProto)
{
- return gDataBase->getEntities().compNextContact(hContact);
+ return (HANDLE)gDataBase->getEntities().compNextContact((WPARAM)hContact);
}
-INT_PTR CompGetContactSetting(WPARAM hContact, LPARAM pSetting)
+STDMETHODIMP_(BOOL) CDataBase::GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
{
- DBCONTACTGETSETTING * dbcgs = reinterpret_cast<DBCONTACTGETSETTING *>(pSetting);
dbcgs->pValue->type = 0;
char namebuf[512];
@@ -121,7 +127,7 @@ INT_PTR CompGetContactSetting(WPARAM hContact, LPARAM pSetting)
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
TDBTSetting set = {0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = hContact;
+ desc.Entity = (WPARAM)hContact;
desc.pszSettingName = namebuf;
set.cbSize = sizeof(set);
@@ -188,21 +194,19 @@ INT_PTR CompGetContactSetting(WPARAM hContact, LPARAM pSetting)
dbcgs->pValue->pbVal = reinterpret_cast<BYTE*>(mir_alloc(sizeof(set.Value)));
memcpy(dbcgs->pValue->pbVal, &set.Value, sizeof(set.Value));
} break;
+
default:
- {
return -1;
- }
}
return 0;
}
-INT_PTR CompGetContactSettingStr(WPARAM hContact, LPARAM pSetting)
-{
- DBCONTACTGETSETTING * dbcgs = reinterpret_cast<DBCONTACTGETSETTING *>(pSetting);
+STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStr(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
+{
if ((dbcgs->pValue->type & DBVTF_VARIABLELENGTH) == 0)
{
- CompFreeVariant(0, reinterpret_cast<LPARAM>(dbcgs->pValue));
+ FreeVariant(dbcgs->pValue);
dbcgs->pValue->type = 0;
}
@@ -217,7 +221,7 @@ INT_PTR CompGetContactSettingStr(WPARAM hContact, LPARAM pSetting)
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
TDBTSetting set = {0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = hContact;
+ desc.Entity = (WPARAM)hContact;
desc.pszSettingName = namebuf;
set.cbSize = sizeof(set);
@@ -297,17 +301,14 @@ INT_PTR CompGetContactSettingStr(WPARAM hContact, LPARAM pSetting)
memcpy(dbcgs->pValue->pbVal, &set.Value, sizeof(set.Value));
} break;
default:
- {
return -1;
- }
}
return 0;
}
-INT_PTR CompGetContactSettingStatic(WPARAM hContact, LPARAM pSetting)
-{
- DBCONTACTGETSETTING * dbcgs = reinterpret_cast<DBCONTACTGETSETTING *>(pSetting);
+STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStatic(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
+{
char namebuf[512];
namebuf[0] = 0;
if (dbcgs->szModule)
@@ -319,7 +320,7 @@ INT_PTR CompGetContactSettingStatic(WPARAM hContact, LPARAM pSetting)
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
TDBTSetting set = {0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = hContact;
+ desc.Entity = (WPARAM)hContact;
desc.pszSettingName = namebuf;
set.cbSize = sizeof(set);
@@ -420,17 +421,14 @@ INT_PTR CompGetContactSettingStatic(WPARAM hContact, LPARAM pSetting)
dbcgs->pValue->dVal = set.Value.DWord;
} break;
default:
- {
return -1;
- }
}
return 0;
}
-INT_PTR CompFreeVariant(WPARAM wParam, LPARAM pSetting)
-{
- DBVARIANT * dbv = reinterpret_cast<DBVARIANT *>(pSetting);
+STDMETHODIMP_(BOOL) CDataBase::FreeVariant(DBVARIANT *dbv)
+{
if ((dbv->type == DBVT_BLOB) && (dbv->pbVal))
{
mir_free(dbv->pbVal);
@@ -443,10 +441,9 @@ INT_PTR CompFreeVariant(WPARAM wParam, LPARAM pSetting)
dbv->type = 0;
return 0;
}
-INT_PTR CompWriteContactSetting(WPARAM hContact, LPARAM pSetting)
-{
- DBCONTACTWRITESETTING * dbcws = reinterpret_cast<DBCONTACTWRITESETTING *>(pSetting);
+STDMETHODIMP_(BOOL) CDataBase::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
+{
char namebuf[512];
namebuf[0] = 0;
if (dbcws->szModule)
@@ -458,7 +455,7 @@ INT_PTR CompWriteContactSetting(WPARAM hContact, LPARAM pSetting)
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
TDBTSetting set = {0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = hContact;
+ desc.Entity = (WPARAM)hContact;
desc.pszSettingName = namebuf;
set.cbSize = sizeof(set);
@@ -533,21 +530,19 @@ INT_PTR CompWriteContactSetting(WPARAM hContact, LPARAM pSetting)
dbcws->value.type = DBVT_UTF8;
wchar_t * tmp = dbcws->value.pwszVal;
dbcws->value.pszVal = mir_utf8encodeW(dbcws->value.pwszVal);
- NotifyEventHooks(hSettingChangeEvent, hContact, pSetting);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)dbcws);
mir_free(dbcws->value.pszVal);
dbcws->value.type = DBVT_WCHAR;
dbcws->value.pwszVal = tmp;
} else {
- NotifyEventHooks(hSettingChangeEvent, hContact, pSetting);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)dbcws);
}
return 0;
}
-INT_PTR CompDeleteContactSetting(WPARAM hContact, LPARAM pSetting)
+STDMETHODIMP_(BOOL) CDataBase::DeleteContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
{
- DBCONTACTGETSETTING * dbcgs = reinterpret_cast<DBCONTACTGETSETTING *>(pSetting);
-
char namebuf[512];
namebuf[0] = 0;
if (dbcgs->szModule)
@@ -558,7 +553,7 @@ INT_PTR CompDeleteContactSetting(WPARAM hContact, LPARAM pSetting)
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = hContact;
+ desc.Entity = (WPARAM)hContact;
desc.pszSettingName = namebuf;
if (DBSettingDelete(reinterpret_cast<WPARAM>(&desc), 0) == DBT_INVALIDPARAM)
@@ -569,18 +564,17 @@ INT_PTR CompDeleteContactSetting(WPARAM hContact, LPARAM pSetting)
tmp.szModule = dbcgs->szModule;
tmp.szSetting = dbcgs->szSetting;
tmp.value.type = 0;
- NotifyEventHooks(hSettingChangeEvent, hContact, reinterpret_cast<LPARAM>(&tmp));
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
}
return 0;
}
-INT_PTR CompEnumContactSettings(WPARAM hContact, LPARAM pEnum)
-{
- DBCONTACTENUMSETTINGS * pces = reinterpret_cast<DBCONTACTENUMSETTINGS *>(pEnum);
+STDMETHODIMP_(BOOL) CDataBase::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* pces)
+{
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = hContact;
+ desc.Entity = (WPARAM)hContact;
char namebuf[512];
namebuf[0] = 0;
@@ -591,7 +585,7 @@ INT_PTR CompEnumContactSettings(WPARAM hContact, LPARAM pEnum)
TDBTSettingIterFilter filter = {0,0,0,0,0,0,0,0};
filter.cbSize = sizeof(filter);
filter.Descriptor = &desc;
- filter.hEntity = hContact;
+ filter.hEntity = (WPARAM)(WPARAM)hContact;
filter.NameStart = namebuf;
TDBTSettingIterationHandle hiter = DBSettingIterInit(reinterpret_cast<WPARAM>(&filter), 0);
@@ -626,26 +620,25 @@ INT_PTR CompEnumContactSettings(WPARAM hContact, LPARAM pEnum)
return res;
}
-
-INT_PTR CompGetEventCount(WPARAM hContact, LPARAM lParam)
+STDMETHODIMP_(LONG) CDataBase::GetEventCount(HANDLE hContact)
{
if (hContact == 0)
- hContact = gDataBase->getEntities().getRootEntity();
+ hContact = (HANDLE)gDataBase->getEntities().getRootEntity();
- return DBEventGetCount(hContact, 0);
+ return DBEventGetCount((WPARAM)hContact, 0);
}
-INT_PTR CompAddEvent(WPARAM hContact, LPARAM pEventInfo)
+
+STDMETHODIMP_(HANDLE) CDataBase::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
{
- DBEVENTINFO * dbei = reinterpret_cast<DBEVENTINFO*>(pEventInfo);
if (dbei->cbSize < sizeof(DBEVENTINFO))
- return -1;
+ return (HANDLE)-1;
- int tmp = NotifyEventHooks(hEventFilterAddedEvent, hContact, pEventInfo);
+ int tmp = NotifyEventHooks(hEventFilterAddedEvent, (WPARAM)hContact, (LPARAM)dbei);
if (tmp != 0)
- return tmp;
+ return (HANDLE)tmp;
if (hContact == 0)
- hContact = gDataBase->getEntities().getRootEntity();
+ hContact = (HANDLE)gDataBase->getEntities().getRootEntity();
TDBTEvent ev = {0,0,0,0,0,0,0};
@@ -659,37 +652,39 @@ INT_PTR CompAddEvent(WPARAM hContact, LPARAM pEventInfo)
ev.cbBlob = dbei->cbBlob;
ev.pBlob = dbei->pBlob;
- int res = DBEventAdd(hContact, reinterpret_cast<LPARAM>(&ev));
+ int res = DBEventAdd((WPARAM)hContact, reinterpret_cast<LPARAM>(&ev));
if (res != DBT_INVALIDPARAM)
{
- NotifyEventHooks(hEventAddedEvent, hContact, res);
- return res;
+ NotifyEventHooks(hEventAddedEvent, (WPARAM)hContact, res);
+ return (HANDLE)res;
}
- return 0;
+ return NULL;
}
-INT_PTR CompDeleteEvent(WPARAM hContact, LPARAM hEvent)
+
+STDMETHODIMP_(BOOL) CDataBase::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
{
- int res = NotifyEventHooks(hEventDeletedEvent, hContact, hEvent);
+ int res = NotifyEventHooks(hEventDeletedEvent, (WPARAM)hContact, (WPARAM)hDbEvent);
if (hContact == 0)
- hContact = gDataBase->getEntities().getRootEntity();
+ hContact = (HANDLE)gDataBase->getEntities().getRootEntity();
if (res == 0)
- return DBEventDelete(hEvent, 0);
+ return DBEventDelete((WPARAM)hDbEvent, 0);
return res;
}
-INT_PTR CompGetBlobSize(WPARAM hEvent, LPARAM lParam)
+
+STDMETHODIMP_(LONG) CDataBase::GetBlobSize(HANDLE hDbEvent)
{
- int res = DBEventGetBlobSize(hEvent, 0);
+ int res = DBEventGetBlobSize((WPARAM)hDbEvent, 0);
if (res == DBT_INVALIDPARAM)
return -1;
return res;
}
-INT_PTR CompGetEvent(WPARAM hEvent, LPARAM pEventInfo)
+
+STDMETHODIMP_(BOOL) CDataBase::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
{
- DBEVENTINFO * dbei = reinterpret_cast<DBEVENTINFO*>(pEventInfo);
if (dbei->cbSize < sizeof(DBEVENTINFO))
return -1;
@@ -698,7 +693,7 @@ INT_PTR CompGetEvent(WPARAM hEvent, LPARAM pEventInfo)
ev.cbBlob = 0;
ev.pBlob = NULL;
- int res = DBEventGet(hEvent, reinterpret_cast<LPARAM>(&ev));
+ int res = DBEventGet((WPARAM)hDbEvent, reinterpret_cast<LPARAM>(&ev));
dbei->szModule = ev.ModuleName;
dbei->timestamp = ev.Timestamp;
@@ -722,131 +717,78 @@ INT_PTR CompGetEvent(WPARAM hEvent, LPARAM pEventInfo)
return res;
}
-INT_PTR CompMarkEventRead(WPARAM hContact, LPARAM hEvent)
+
+STDMETHODIMP_(BOOL) CDataBase::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
{
- int res = DBEventMarkRead(hEvent, 0);
+ int res = DBEventMarkRead((WPARAM)hDbEvent, 0);
if ((res != DBT_INVALIDPARAM) && (res & DBEF_SENT))
res = res & ~DBEF_READ;
return res;
}
-INT_PTR CompGetEventContact(WPARAM hEvent, LPARAM lParam)
+
+STDMETHODIMP_(HANDLE) CDataBase::GetEventContact(HANDLE hDbEvent)
{
- TDBTEntityHandle res = DBEventGetEntity(hEvent, 0);
+ TDBTEntityHandle res = DBEventGetEntity((WPARAM)hDbEvent, 0);
if (res == gDataBase->getEntities().getRootEntity())
res = 0;
- return res;
+ return (HANDLE)res;
}
-INT_PTR CompFindFirstEvent(WPARAM hContact, LPARAM lParam)
+
+STDMETHODIMP_(HANDLE) CDataBase::FindFirstEvent(HANDLE hContact)
{
if (hContact == 0)
- hContact = gDataBase->getEntities().getRootEntity();
+ hContact = (HANDLE)gDataBase->getEntities().getRootEntity();
- return gDataBase->getEvents().compFirstEvent(hContact);
+ return (HANDLE)gDataBase->getEvents().compFirstEvent((WPARAM)hContact);
}
-INT_PTR CompFindFirstUnreadEvent(WPARAM hContact, LPARAM lParam)
+
+STDMETHODIMP_(HANDLE) CDataBase::FindFirstUnreadEvent(HANDLE hContact)
{
if (hContact == 0)
- hContact = gDataBase->getEntities().getRootEntity();
- return gDataBase->getEvents().compFirstUnreadEvent(hContact);
+ hContact = (HANDLE)gDataBase->getEntities().getRootEntity();
+ return (HANDLE)gDataBase->getEvents().compFirstUnreadEvent((WPARAM)hContact);
}
-INT_PTR CompFindLastEvent(WPARAM hContact, LPARAM lParam)
+
+STDMETHODIMP_(HANDLE) CDataBase::FindLastEvent(HANDLE hContact)
{
if (hContact == 0)
- hContact = gDataBase->getEntities().getRootEntity();
- return gDataBase->getEvents().compLastEvent(hContact);
+ hContact = (HANDLE)gDataBase->getEntities().getRootEntity();
+ return (HANDLE)gDataBase->getEvents().compLastEvent((WPARAM)hContact);
}
-INT_PTR CompFindNextEvent(WPARAM hEvent, LPARAM lParam)
+
+STDMETHODIMP_(HANDLE) CDataBase::FindNextEvent(HANDLE hDbEvent)
{
- return gDataBase->getEvents().compNextEvent(hEvent);
+ return (HANDLE)gDataBase->getEvents().compNextEvent((WPARAM)hDbEvent);
}
-INT_PTR CompFindPrevEvent(WPARAM hEvent, LPARAM lParam)
+
+STDMETHODIMP_(HANDLE) CDataBase::FindPrevEvent(HANDLE hDbEvent)
{
- return gDataBase->getEvents().compPrevEvent(hEvent);
+ return (HANDLE)gDataBase->getEvents().compPrevEvent((WPARAM)hDbEvent);
}
-INT_PTR CompEnumModules(WPARAM wParam, LPARAM pCallback)
+STDMETHODIMP_(BOOL) CDataBase::EnumModuleNames(DBMODULEENUMPROC pCallback, void *pParam)
{
if (!pCallback)
return -1;
- return gDataBase->getSettings().CompEnumModules(reinterpret_cast<DBMODULEENUMPROC>(pCallback), wParam);
-}
-
-void Encrypt(char* msg, BOOL up)
-{
- int i;
- const int jump = up ? 5 : -5;
-
- for (i=0; msg[i]; i++)
- {
- msg[i] = msg[i] + jump;
- }
-
-}
-
-INT_PTR CompEncodeString(WPARAM wParam, LPARAM lParam)
-{
- Encrypt(reinterpret_cast<char*>(lParam),TRUE);
- return 0;
+ return gDataBase->getSettings().CompEnumModules(pCallback, (WPARAM)pParam);
}
-INT_PTR CompDecodeString(WPARAM wParam, LPARAM lParam)
+STDMETHODIMP_(BOOL) CDataBase::SetSettingResident(BOOL bIsResident, const char *pszSettingName)
{
- Encrypt(reinterpret_cast<char*>(lParam),FALSE);
- return 0;
+ return FALSE;
}
-INT_PTR CompGetProfileName(WPARAM cbBytes, LPARAM pszName)
+STDMETHODIMP_(BOOL) CDataBase::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
{
- return gDataBase->getProfileName(cbBytes, reinterpret_cast<char*>(pszName));
+ return FALSE;
}
-INT_PTR CompGetProfilePath(WPARAM cbBytes, LPARAM pszName)
-{
- return gDataBase->getProfilePath(cbBytes, reinterpret_cast<char*>(pszName));
-}
+STDMETHODIMP_(void) CDataBase::SetCacheSafetyMode(BOOL) {}
bool CompatibilityRegister()
{
- gCompServices[ 0] = CreateServiceFunction(MS_DB_CONTACT_GETCOUNT, CompGetContactCount);
- gCompServices[ 1] = CreateServiceFunction(MS_DB_CONTACT_FINDFIRST, CompFindFirstContact);
- gCompServices[ 2] = CreateServiceFunction(MS_DB_CONTACT_FINDNEXT, CompFindNextContact);
- gCompServices[ 3] = CreateServiceFunction(MS_DB_CONTACT_DELETE, CompDeleteContact);
- gCompServices[ 4] = CreateServiceFunction(MS_DB_CONTACT_ADD, CompAddContact);
- gCompServices[ 5] = CreateServiceFunction(MS_DB_CONTACT_IS, CompIsDbContact);
-
- gCompServices[ 6] = CreateServiceFunction(MS_DB_CONTACT_GETSETTING, CompGetContactSetting);
- gCompServices[ 7] = CreateServiceFunction(MS_DB_CONTACT_GETSETTING_STR, CompGetContactSettingStr);
- gCompServices[ 8] = CreateServiceFunction(MS_DB_CONTACT_GETSETTINGSTATIC, CompGetContactSettingStatic);
- gCompServices[ 9] = CreateServiceFunction(MS_DB_CONTACT_FREEVARIANT, CompFreeVariant);
- gCompServices[10] = CreateServiceFunction(MS_DB_CONTACT_WRITESETTING, CompWriteContactSetting);
- gCompServices[11] = CreateServiceFunction(MS_DB_CONTACT_DELETESETTING, CompDeleteContactSetting);
- gCompServices[12] = CreateServiceFunction(MS_DB_CONTACT_ENUMSETTINGS, CompEnumContactSettings);
- //gCompServices[13] = CreateServiceFunction(MS_DB_SETSETTINGRESIDENT, CompSetSettingResident);
-
- gCompServices[14] = CreateServiceFunction(MS_DB_EVENT_GETCOUNT, CompGetEventCount);
- gCompServices[15] = CreateServiceFunction(MS_DB_EVENT_ADD, CompAddEvent);
- gCompServices[16] = CreateServiceFunction(MS_DB_EVENT_DELETE, CompDeleteEvent);
- gCompServices[17] = CreateServiceFunction(MS_DB_EVENT_GETBLOBSIZE, CompGetBlobSize);
- gCompServices[18] = CreateServiceFunction(MS_DB_EVENT_GET, CompGetEvent);
- gCompServices[19] = CreateServiceFunction(MS_DB_EVENT_MARKREAD, CompMarkEventRead);
- gCompServices[20] = CreateServiceFunction(MS_DB_EVENT_GETCONTACT, CompGetEventContact);
- gCompServices[21] = CreateServiceFunction(MS_DB_EVENT_FINDFIRST, CompFindFirstEvent);
- gCompServices[22] = CreateServiceFunction(MS_DB_EVENT_FINDFIRSTUNREAD, CompFindFirstUnreadEvent);
- gCompServices[23] = CreateServiceFunction(MS_DB_EVENT_FINDLAST, CompFindLastEvent);
- gCompServices[24] = CreateServiceFunction(MS_DB_EVENT_FINDNEXT, CompFindNextEvent);
- gCompServices[25] = CreateServiceFunction(MS_DB_EVENT_FINDPREV, CompFindPrevEvent);
-
- gCompServices[26] = CreateServiceFunction(MS_DB_MODULES_ENUM, CompEnumModules);
-
- gCompServices[27] = CreateServiceFunction(MS_DB_CRYPT_ENCODESTRING, CompEncodeString);
- gCompServices[28] = CreateServiceFunction(MS_DB_CRYPT_DECODESTRING, CompDecodeString);
-
- gCompServices[29] = CreateServiceFunction(MS_DB_GETPROFILENAME, CompGetProfileName);
- gCompServices[30] = CreateServiceFunction(MS_DB_GETPROFILEPATH, CompGetProfilePath);
-
-
hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED);
hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED);
hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
@@ -858,8 +800,5 @@ bool CompatibilityRegister()
bool CompatibilityUnRegister()
{
- for (int i = 0; i < SIZEOF(gCompServices); ++i)
- DestroyServiceFunction(gCompServices[i]);
-
return true;
}
diff --git a/plugins/Dbx_tree/Compatibility.h b/plugins/Dbx_tree/Compatibility.h
index b6b6c16f89..4d89ca6cda 100644
--- a/plugins/Dbx_tree/Compatibility.h
+++ b/plugins/Dbx_tree/Compatibility.h
@@ -29,37 +29,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
bool CompatibilityRegister();
bool CompatibilityUnRegister();
-INT_PTR CompGetContactCount(WPARAM wParam,LPARAM lParam);
-INT_PTR CompFindFirstContact(WPARAM wParam,LPARAM lParam);
-INT_PTR CompFindNextContact(WPARAM hContact,LPARAM lParam);
-INT_PTR CompDeleteContact(WPARAM hContact,LPARAM lParam);
-INT_PTR CompAddContact(WPARAM wParam,LPARAM lParam);
-INT_PTR CompIsDbContact(WPARAM hContact,LPARAM lParam);
-
-INT_PTR CompGetContactSetting(WPARAM hContact, LPARAM pSetting);
-INT_PTR CompGetContactSettingStr(WPARAM hContact, LPARAM pSetting);
-INT_PTR CompGetContactSettingStatic(WPARAM hContact, LPARAM pSetting);
-INT_PTR CompFreeVariant(WPARAM wParam, LPARAM pSetting);
-INT_PTR CompWriteContactSetting(WPARAM hContact, LPARAM pSetting);
-INT_PTR CompDeleteContactSetting(WPARAM hContact, LPARAM pSetting);
-INT_PTR CompEnumContactSettings(WPARAM hContact, LPARAM pEnum);
-
-INT_PTR CompGetEventCount(WPARAM wParam, LPARAM lParam);
-INT_PTR CompAddEvent(WPARAM hContact, LPARAM pEventInfo);
-INT_PTR CompDeleteEvent(WPARAM hContact, LPARAM hEvent);
-INT_PTR CompGetBlobSize(WPARAM hEvent, LPARAM lParam);
-INT_PTR CompGetEvent(WPARAM hEvent, LPARAM pEventInfo);
-INT_PTR CompMarkEventRead(WPARAM hContact, LPARAM hEvent);
-INT_PTR CompGetEventContact(WPARAM hEvent, LPARAM lParam);
-INT_PTR CompFindFirstEvent(WPARAM hContact, LPARAM lParam);
-INT_PTR CompFindFirstUnreadEvent(WPARAM hContact, LPARAM lParam);
-INT_PTR CompFindLastEvent(WPARAM hContact, LPARAM lParam);
-INT_PTR CompFindNextEvent(WPARAM hEvent, LPARAM lParam);
-INT_PTR CompFindPrevEvent(WPARAM hEvent, LPARAM lParam);
-
-
-INT_PTR CompEncodeString(WPARAM wParam, LPARAM lParam);
-INT_PTR CompDecodeString(WPARAM wParam, LPARAM lParam);
-
-INT_PTR CompGetProfileName(WPARAM cbBytes, LPARAM pszName);
-INT_PTR CompGetProfilePath(WPARAM cbBytes, LPARAM pszName);
diff --git a/plugins/Dbx_tree/DataBase.cpp b/plugins/Dbx_tree/DataBase.cpp
index 101d4b5d34..b685981037 100644
--- a/plugins/Dbx_tree/DataBase.cpp
+++ b/plugins/Dbx_tree/DataBase.cpp
@@ -29,13 +29,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
CDataBase *gDataBase = NULL;
-CDataBase::CDataBase(const char* FileName)
+CDataBase::CDataBase(const TCHAR *FileName)
{
- int len;
-
- len = MultiByteToWideChar(CP_ACP, 0, FileName, -1, NULL, 0);
+ int len = _tcslen(FileName);
m_FileName[0] = new TCHAR[len + 1];
- MultiByteToWideChar(CP_ACP, 0, FileName, -1, m_FileName[0], len + 1);
+ _tcsncpy_s(m_FileName[0], len + 1, FileName, len);
m_FileName[0][len] = 0;
diff --git a/plugins/Dbx_tree/DataBase.h b/plugins/Dbx_tree/DataBase.h
index 2577249572..124fee4f9d 100644
--- a/plugins/Dbx_tree/DataBase.h
+++ b/plugins/Dbx_tree/DataBase.h
@@ -96,8 +96,7 @@ typedef union TGenericFileHeader {
#pragma pack(pop)
-
-class CDataBase : public sigslot::has_slots<>
+class CDataBase : public sigslot::has_slots<>, public MIDatabase
{
private:
TCHAR* m_FileName[DBFileMax];
@@ -128,7 +127,7 @@ protected:
void ReWriteHeader(TDBFileType Index);
public:
- CDataBase(const char* FileName);
+ CDataBase(const TCHAR* FileName);
virtual ~CDataBase();
int CreateDB();
@@ -151,7 +150,40 @@ public:
int getProfileName(int BufferSize, char * Buffer);
int getProfilePath(int BufferSize, char * Buffer);
+protected: // to be compatible with the standard Miranda databases
+ 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);
};
-
extern CDataBase *gDataBase;
diff --git a/plugins/Dbx_tree/DatabaseLink.cpp b/plugins/Dbx_tree/DatabaseLink.cpp
index 3e75ce591e..850e798ef9 100644
--- a/plugins/Dbx_tree/DatabaseLink.cpp
+++ b/plugins/Dbx_tree/DatabaseLink.cpp
@@ -25,23 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "savestrings_gcc.h"
#endif
-static int getCapability(int);
-static int getFriendlyName(char*, size_t, int);
-static int makeDatabase(char*, int*);
-static int grokHeader(char*, int*);
-static int Load(char*);
-static int Unload(int);
-
-DATABASELINK gDBLink = {
- sizeof(DATABASELINK),
- getCapability,
- getFriendlyName,
- makeDatabase,
- grokHeader,
- Load,
- Unload,
-};
-
HANDLE hSystemModulesLoaded = 0;
static int SystemModulesLoaded(WPARAM wParam, LPARAM lParam)
@@ -70,12 +53,12 @@ static int getCapability(int flag)
Returns: 0 on success, non zero on failure
*/
-static int getFriendlyName(char* buf, size_t cch, int shortName)
+static int getFriendlyName(TCHAR *buf, size_t cch, int shortName)
{
if (shortName)
- strncpy_s(buf, cch, gInternalName, strlen(gInternalName));
+ _tcsncpy_s(buf, cch, _T(gInternalName), SIZEOF(gInternalName));
else
- strncpy_s(buf, cch, gInternalNameLong, strlen(gInternalNameLong));
+ _tcsncpy_s(buf, cch, _T(gInternalNameLong), SIZEOF(gInternalNameLong));
return 0;
}
@@ -87,10 +70,10 @@ static int getFriendlyName(char* buf, size_t cch, int shortName)
Note: Do not initialise internal data structures at this point!
Returns: 0 on success, non zero on failure - error contains extended error information, see EMKPRF_*
*/
-static int makeDatabase(char* profile, int* error)
+static int makeDatabase(TCHAR *profile, int* error)
{
if (gDataBase) delete gDataBase;
- gDataBase = new CDataBase(profile);
+ gDataBase = new CDataBase(profile);
*error = gDataBase->CreateDB();
return *error;
@@ -106,7 +89,7 @@ static int makeDatabase(char* profile, int* error)
etc.
Returns: 0 on success, non zero on failure
*/
-static int grokHeader(char* profile, int* error)
+static int grokHeader(TCHAR *profile, int* error)
{
if (gDataBase) delete gDataBase;
gDataBase = new CDataBase(profile);
@@ -121,7 +104,7 @@ Affect: Tell the database to create all services/hooks that a 3.xx legecy databa
Returns: 0 on success, nonzero on failure
*/
-static int Load(char* profile)
+static MIDatabase* Load(TCHAR *profile)
{
if (gDataBase) delete gDataBase;
gDataBase = new CDataBase(profile);
@@ -131,7 +114,8 @@ static int Load(char* profile)
hSystemModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, SystemModulesLoaded);
- return gDataBase->OpenDB();
+ gDataBase->OpenDB();
+ return gDataBase;
}
/*
@@ -147,3 +131,13 @@ static int Unload(int wasLoaded)
gDataBase = NULL;
return 0;
}
+
+DATABASELINK gDBLink = {
+ sizeof(DATABASELINK),
+ getCapability,
+ getFriendlyName,
+ makeDatabase,
+ grokHeader,
+ Load,
+ Unload,
+};
diff --git a/plugins/Dbx_tree/Interface.h b/plugins/Dbx_tree/Interface.h
index 0f2093d3a4..bde0a74511 100644
--- a/plugins/Dbx_tree/Interface.h
+++ b/plugins/Dbx_tree/Interface.h
@@ -28,6 +28,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <windows.h>
#include "newpluginapi.h"
#include "m_system.h"
+#include "m_system_cpp.h"
+#include "m_database.h"
+#include "m_db_int.h"
#include "m_utils.h"
#include "win2k.h"
diff --git a/src/core/commonheaders.h b/src/core/commonheaders.h
index 13287d770a..ae6790a974 100644
--- a/src/core/commonheaders.h
+++ b/src/core/commonheaders.h
@@ -61,6 +61,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_core.h>
#include <newpluginapi.h>
#include <m_database.h>
+#include <m_db_int.h>
#include <m_clc.h>
#include <m_clui.h>
#include <m_crypto.h>
diff --git a/src/core/miranda.h b/src/core/miranda.h
index 8c3a3b1d20..00eab4fcae 100644
--- a/src/core/miranda.h
+++ b/src/core/miranda.h
@@ -108,6 +108,10 @@ extern LPFN_FREEADDRINFO MyFreeaddrinfo;
extern LPFN_WSASTRINGTOADDRESSA MyWSAStringToAddress;
extern LPFN_WSAADDRESSTOSTRINGA MyWSAAddressToString;
+/**** database.cpp *********************************************************************/
+
+extern MIDatabase* currDb;
+
/**** fontService.cpp ******************************************************************/
void KillModuleFonts(int hLangpack);
diff --git a/src/core/modules.cpp b/src/core/modules.cpp
index 423bd3471a..e44114cf96 100644
--- a/src/core/modules.cpp
+++ b/src/core/modules.cpp
@@ -41,6 +41,7 @@ int LoadLangpackModule(void); // core: translation
int LoadProtocolsModule(void); // core: protocol manager
int LoadAccountsModule(void); // core: account manager
int LoadIgnoreModule(void); // protocol filter: ignore
+int LoadDbintfModule(void);
int LoadContactListModule(void);// ui: clist
int LoadOptionsModule(void); // ui: options dialog
@@ -89,6 +90,7 @@ int LoadDefaultModules(void)
if ( LoadUtilsModule()) return 1; //order not important for this, but no dependencies and no point in pluginising
if ( LoadIcoTabsModule()) return 1;
if ( LoadHeaderbarModule()) return 1;
+ if ( LoadDbintfModule()) return 1;
if ( LoadNewPluginsModuleInfos()) return 1;
// database is available here
diff --git a/src/mir_core/commonheaders.h b/src/mir_core/commonheaders.h
index 2d04e12f4b..5afcda256e 100644
--- a/src/mir_core/commonheaders.h
+++ b/src/mir_core/commonheaders.h
@@ -55,6 +55,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_system.h>
#include <m_system_cpp.h>
#include <m_database.h>
+#include <m_db_int.h>
#include <newpluginapi.h>
#include "miranda.h"
diff --git a/src/mir_core/db.cpp b/src/mir_core/db.cpp
index af6a89537f..36902702ff 100644
--- a/src/mir_core/db.cpp
+++ b/src/mir_core/db.cpp
@@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
+static MIDatabase* currDb = NULL;
+
MIR_CORE_DLL(int) db_get_b(HANDLE hContact, const char *szModule, const char *szSetting, int errorValue)
{
DBVARIANT dbv;
@@ -202,3 +204,8 @@ MIR_CORE_DLL(INT_PTR) db_set_blob(HANDLE hContact, const char *szModule, const c
cws.value.pbVal = (unsigned char*)val;
return CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)hContact, (LPARAM)&cws);
}
+
+MIR_CORE_DLL(void) db_setCurrent(MIDatabase* _db)
+{
+ currDb = _db;
+}
diff --git a/src/miranda32_10.vcxproj b/src/miranda32_10.vcxproj
index 5b817e1d8e..540be17025 100644
--- a/src/miranda32_10.vcxproj
+++ b/src/miranda32_10.vcxproj
@@ -220,6 +220,7 @@
<ClInclude Include="..\include\m_clui.h" />
<ClInclude Include="..\include\m_contacts.h" />
<ClInclude Include="..\include\m_database.h" />
+ <ClInclude Include="..\include\m_db_int.h" />
<ClInclude Include="..\include\m_email.h" />
<ClInclude Include="..\include\m_file.h" />
<ClInclude Include="..\include\m_findadd.h" />
@@ -290,12 +291,18 @@
<ClCompile Include="modules\button\button.cpp">
<PrecompiledHeaderFile>..\..\core\commonheaders.h</PrecompiledHeaderFile>
</ClCompile>
+ <ClCompile Include="modules\crypt\encrypt.cpp">
+ <PrecompiledHeaderFile>..\..\core\commonheaders.h</PrecompiledHeaderFile>
+ </ClCompile>
<ClCompile Include="modules\database\database.cpp">
<PrecompiledHeaderFile>..\..\core\commonheaders.h</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="modules\database\dbini.cpp">
<PrecompiledHeaderFile>..\..\core\commonheaders.h</PrecompiledHeaderFile>
</ClCompile>
+ <ClCompile Include="modules\database\dbintf.cpp">
+ <PrecompiledHeaderFile>..\..\core\commonheaders.h</PrecompiledHeaderFile>
+ </ClCompile>
<ClCompile Include="modules\database\dbutils.cpp">
<PrecompiledHeaderFile>..\..\core\commonheaders.h</PrecompiledHeaderFile>
</ClCompile>
diff --git a/src/miranda32_10.vcxproj.filters b/src/miranda32_10.vcxproj.filters
index 90c60ffac7..8be88946e7 100644
--- a/src/miranda32_10.vcxproj.filters
+++ b/src/miranda32_10.vcxproj.filters
@@ -67,6 +67,9 @@
<Filter Include="Modules\json">
<UniqueIdentifier>{8aad13dd-0e8d-4154-ad6f-913724b5a499}</UniqueIdentifier>
</Filter>
+ <Filter Include="Modules\crypt">
+ <UniqueIdentifier>{15d84b6a-4aa3-4cd5-93b3-2559709224ea}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\m_addcontact.h">
@@ -90,9 +93,6 @@
<ClInclude Include="..\include\m_contacts.h">
<Filter>SDK</Filter>
</ClInclude>
- <ClInclude Include="..\include\m_database.h">
- <Filter>SDK</Filter>
- </ClInclude>
<ClInclude Include="..\include\m_email.h">
<Filter>SDK</Filter>
</ClInclude>
@@ -270,6 +270,12 @@
<ClInclude Include="..\include\m_button.h">
<Filter>Modules\button</Filter>
</ClInclude>
+ <ClInclude Include="..\include\m_database.h">
+ <Filter>Modules\database</Filter>
+ </ClInclude>
+ <ClInclude Include="..\include\m_db_int.h">
+ <Filter>Modules\database</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="core\commonheaders.cpp">
@@ -563,6 +569,12 @@
<ClCompile Include="modules\plugins\dll_sniffer.cpp">
<Filter>Modules\plugins</Filter>
</ClCompile>
+ <ClCompile Include="modules\database\dbintf.cpp">
+ <Filter>Modules\database</Filter>
+ </ClCompile>
+ <ClCompile Include="modules\crypt\encrypt.cpp">
+ <Filter>Modules\crypt</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="res\_blank.ico">
diff --git a/plugins/Db3x_mmap/encrypt.cpp b/src/modules/crypt/encrypt.cpp
index a42d79eae2..8880341c58 100644
--- a/plugins/Db3x_mmap/encrypt.cpp
+++ b/src/modules/crypt/encrypt.cpp
@@ -21,27 +21,26 @@ 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"
+#include "..\..\core\commonheaders.h"
//VERY VERY VERY BASIC ENCRYPTION FUNCTION
-
void Encrypt(char*msg,BOOL up)
{
int i;
int jump;
if (up)
{
- jump=5;
+ jump = 5;
}
else
{
- jump=-5;
+ jump = -5;
}
- for (i=0;msg[i];i++)
+ for (i = 0;msg[i];i++)
{
- msg[i]=msg[i]+jump;
+ msg[i] = msg[i]+jump;
}
}
diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp
index ec25931527..8686d50bc6 100644
--- a/src/modules/database/database.cpp
+++ b/src/modules/database/database.cpp
@@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "..\..\core\commonheaders.h"
#include "profilemanager.h"
+MIR_CORE_DLL(void) db_setCurrent(MIDatabase* _db);
+
// contains the location of mirandaboot.ini
extern TCHAR mirandabootini[MAX_PATH];
bool dbCreated;
@@ -400,16 +402,13 @@ int makeDatabase(TCHAR *profile, DATABASELINK * link, HWND hwndDlg)
}
// ask the database to create the profile
CreatePathToFileT(profile);
- char *prf = makeFileName(profile);
- if (link->makeDatabase(prf, &err)) {
+ if (link->makeDatabase(profile, &err)) {
mir_sntprintf(buf, SIZEOF(buf), TranslateT("Unable to create the profile '%s', the error was %x"), file, err);
MessageBox(hwndDlg, buf, TranslateT("Problem creating profile"), MB_ICONERROR|MB_OK);
- mir_free(prf);
return 0;
}
dbCreated = true;
// the profile has been created! woot
- mir_free(prf);
return 1;
}
@@ -419,13 +418,14 @@ static int FindDbPluginForProfile(const TCHAR*, DATABASELINK *dblink, LPARAM lPa
TCHAR* tszProfile = (TCHAR*)lParam;
int res = DBPE_CONT;
if (dblink && dblink->cbSize == sizeof(DATABASELINK)) {
- char* szProfile = makeFileName(tszProfile);
// liked the profile?
int err = 0;
- if (dblink->grokHeader(szProfile, &err) == 0) {
+ if (dblink->grokHeader(tszProfile, &err) == 0) {
// added APIs?
- if ( !dblink->Load(szProfile)) {
+ MIDatabase* pDb = dblink->Load(tszProfile);
+ if (pDb) {
fillProfileName(tszProfile);
+ db_setCurrent(currDb = pDb);
res = DBPE_DONE;
}
else res = DBPE_HALT;
@@ -443,7 +443,6 @@ static int FindDbPluginForProfile(const TCHAR*, DATABASELINK *dblink, LPARAM lPa
break;
}
} //if
- mir_free(szProfile);
}
return res;
}
@@ -457,16 +456,14 @@ static int FindDbPluginAutoCreate(const TCHAR* ptszProfile, DATABASELINK * dblin
CreatePathToFileT(tszProfile);
int err;
- char *szProfile = makeFileName(tszProfile);
- if (dblink->makeDatabase(szProfile, &err) == 0) {
+ if (dblink->makeDatabase(tszProfile, &err) == 0) {
dbCreated = true;
- if ( !dblink->Load(szProfile)) {
+ if ( !dblink->Load(tszProfile)) {
fillProfileName(tszProfile);
res = DBPE_DONE;
}
else res = DBPE_HALT;
}
- mir_free(szProfile);
}
return res;
}
diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp
index 63e6cd1c4d..4e8ebc381f 100644
--- a/src/modules/database/profilemanager.cpp
+++ b/src/modules/database/profilemanager.cpp
@@ -119,13 +119,11 @@ static int FindDbProviders(const TCHAR* tszProfileName, DATABASELINK *dblink, LP
{
HWND hwndDlg = (HWND)lParam;
HWND hwndCombo = GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS);
- char szName[64];
+ TCHAR szName[64];
if (dblink->getFriendlyName(szName, SIZEOF(szName), 1) == 0) {
// add to combo box
- TCHAR* p = Langpack_PcharToTchar(szName);
- LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)p);
- mir_free(p);
+ LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)szName);
SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)dblink);
}
return DBPE_CONT;
@@ -221,17 +219,12 @@ static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
static int DetectDbProvider(const TCHAR*, DATABASELINK * dblink, LPARAM lParam)
{
int error;
-
- char* fullpath = makeFileName((TCHAR*)lParam);
-
- int ret = dblink->grokHeader(fullpath, &error);
- mir_free(fullpath);
+ int ret = dblink->grokHeader((TCHAR*)lParam, &error);
if (ret == 0) {
- char tmp[ MAX_PATH ];
+ TCHAR tmp[ MAX_PATH ];
dblink->getFriendlyName(tmp, SIZEOF(tmp), 1);
- MultiByteToWideChar(CP_ACP, 0, tmp, -1, (TCHAR*)lParam, MAX_PATH);
-
+ _tcsncpy((TCHAR*)lParam, tmp, MAX_PATH);
return DBPE_HALT;
}
diff --git a/src/modules/utils/utils.cpp b/src/modules/utils/utils.cpp
index 64941a9b85..9d553b333b 100644
--- a/src/modules/utils/utils.cpp
+++ b/src/modules/utils/utils.cpp
@@ -36,6 +36,7 @@ int InitBitmapFilter(void);
void InitXmlApi(void);
void InitTimeZones(void);
void UninitTimeZones(void);
+int InitCrypt(void);
static BOOL bModuleInitialized = FALSE;
@@ -471,6 +472,7 @@ int LoadUtilsModule(void)
CreateServiceFunction(MS_UTILS_GETCOUNTRYLIST, GetCountryList);
CreateServiceFunction(MS_UTILS_GETRANDOM, GenerateRandom);
CreateServiceFunction(MS_SYSTEM_RESTART, RestartMiranda);
+
InitOpenUrl();
InitWindowList();
InitHyperlink();
@@ -480,12 +482,14 @@ int LoadUtilsModule(void)
InitXmlApi();
InitJson();
InitTimeZones();
+ InitCrypt();
return 0;
}
void UnloadUtilsModule(void)
{
- if ( !bModuleInitialized) return;
+ if ( !bModuleInitialized)
+ return;
FreeWindowList();
UninitTimeZones();