summaryrefslogtreecommitdiff
path: root/db3x_autobackups/dbsettings.c
diff options
context:
space:
mode:
Diffstat (limited to 'db3x_autobackups/dbsettings.c')
-rw-r--r--db3x_autobackups/dbsettings.c327
1 files changed, 180 insertions, 147 deletions
diff --git a/db3x_autobackups/dbsettings.c b/db3x_autobackups/dbsettings.c
index 2f464f4..a8d347d 100644
--- a/db3x_autobackups/dbsettings.c
+++ b/db3x_autobackups/dbsettings.c
@@ -23,67 +23,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-#include "database.h"
-
DWORD GetModuleNameOfs(const char *szName);
-
-extern CRITICAL_SECTION csDbAccess;
-extern struct DBHeader dbHeader;
+DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index);
HANDLE hCacheHeap = NULL;
-SortedList lContacts;
+SortedList lContacts = {0};
+HANDLE hLastCachedContact = NULL;
+static DBCachedContactValueList *LastVL = NULL;
-static SortedList lSettings, lGlobalSettings;
+static SortedList lSettings={0}, lGlobalSettings={0}, lResidentSettings={0};
static HANDLE hSettingChangeEvent = NULL;
-#define SETTINGSGROUPOFSCOUNT 32
-struct SettingsGroupOfsCacheEntry {
- DWORD ofsContact;
- DWORD ofsModuleName;
- DWORD ofsSettingsGroup;
-};
-static struct SettingsGroupOfsCacheEntry settingsGroupOfsCache[SETTINGSGROUPOFSCOUNT];
-static int nextSGOCacheEntry;
-
-//this function caches results
-static DWORD GetSettingsGroupOfsByModuleNameOfs(struct DBContact *dbc,DWORD ofsContact,DWORD ofsModuleName)
+static DWORD GetSettingsGroupOfsByModuleNameOfs(struct DBContact *dbc,DWORD ofsModuleName)
{
struct DBContactSettings *dbcs;
DWORD ofsThis;
- int i;
- for(i=0;i<SETTINGSGROUPOFSCOUNT;i++) {
- if(settingsGroupOfsCache[i].ofsContact==ofsContact && settingsGroupOfsCache[i].ofsModuleName==ofsModuleName)
- return settingsGroupOfsCache[i].ofsSettingsGroup;
- }
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;
+ if(dbcs->signature!=DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL);
+ if(dbcs->ofsModuleName==ofsModuleName)
return ofsThis;
- }
+
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;
- break;
-} } }
-
static DWORD __inline GetSettingValueLength(PBYTE pSetting)
{
if(pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1);
@@ -99,11 +66,11 @@ static char* InsertCachedSetting( const char* szName, size_t cbNameLen, int inde
return newValue;
}
-static char* GetCachedSetting(const char *szModuleName,const char *szSettingName,int settingNameLen)
+static char* GetCachedSetting(const char *szModuleName,const char *szSettingName, int moduleNameLen, int settingNameLen)
{
static char *lastsetting = NULL;
- int moduleNameLen = strlen(szModuleName),index;
- char *szFullName = (char*)alloca(moduleNameLen+settingNameLen+3);
+ int index;
+ char szFullName[512];
strcpy(szFullName+1,szModuleName);
szFullName[moduleNameLen+1]='/';
@@ -112,10 +79,11 @@ static char* GetCachedSetting(const char *szModuleName,const char *szSettingName
if (lastsetting && strcmp(szFullName+1,lastsetting) == 0)
return lastsetting;
- if ( li.List_GetIndex(&lSettings, szFullName, &index))
- lastsetting = (char*)lSettings.items[index] + 1;
+ if (li.List_GetIndex(&lSettings,szFullName,&index))
+ lastsetting = (char*)lSettings.items[index]+1;
else
- lastsetting = InsertCachedSetting( szFullName, moduleNameLen+settingNameLen+3, index )+1;
+ lastsetting = InsertCachedSetting( szFullName, settingNameLen+moduleNameLen+3, index )+1;
+
return lastsetting;
}
@@ -131,7 +99,10 @@ static void SetCachedVariant( DBVARIANT* s /* new */, DBVARIANT* d /* cached */
d->pszVal = (char*)HeapAlloc(hCacheHeap,0,strlen(s->pszVal)+1);
strcpy(d->pszVal,s->pszVal);
}
+ else if ( szSave != NULL )
+ HeapFree(hCacheHeap,0,szSave);
+#ifdef DBLOGGING
switch( d->type ) {
case DBVT_BYTE: log1( "set cached byte: %d", d->bVal ); break;
case DBVT_WORD: log1( "set cached word: %d", d->wVal ); break;
@@ -139,9 +110,11 @@ static void SetCachedVariant( DBVARIANT* s /* new */, DBVARIANT* d /* cached */
case DBVT_UTF8:
case DBVT_ASCIIZ: log1( "set cached string: '%s'", d->pszVal ); break;
default: log1( "set cached crap: %d", d->type ); break;
-} }
+ }
+#endif
+}
-static void FreeCachedVariant( DBVARIANT* V )
+void FreeCachedVariant( DBVARIANT* V )
{
if (( V->type == DBVT_ASCIIZ || V->type == DBVT_UTF8 ) && V->pszVal != NULL )
HeapFree(hCacheHeap,0,V->pszVal);
@@ -177,21 +150,27 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
DBCachedContactValue *V, *V1;
DBCachedContactValueList VLtemp,*VL;
- VLtemp.hContact=hContact;
- if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) {
- VL = (DBCachedContactValueList*)lContacts.items[index];
+ if (hLastCachedContact==hContact && LastVL) {
+ VL = LastVL;
}
else {
- if ( bAllocate != 1 )
- return NULL;
+ VLtemp.hContact=hContact;
+
+ if ( !li.List_GetIndex(&lContacts,&VLtemp,&index))
+ {
+ if ( bAllocate != 1 )
+ return NULL;
+
+ VL = AddToCachedContactList(hContact,index);
+ }
+ else VL = (DBCachedContactValueList*)lContacts.items[index];
- VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList));
- VL->hContact = hContact;
- li.List_Insert(&lContacts,VL,index);
+ LastVL = VL;
+ hLastCachedContact = hContact;
}
for ( V = VL->first; V != NULL; V = V->next)
- if (strcmp(V->name,szSetting)==0)
+ if (V->name == szSetting)
break;
if ( V == NULL ) {
@@ -199,19 +178,29 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
return NULL;
V = HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValue));
- V->next = VL->first;
- VL->first = V;
+ if (VL->last)
+ VL->last->next = V;
+ else
+ VL->first = V;
+ VL->last = V;
V->name = szSetting;
}
else if ( bAllocate == -1 ) {
+ LastVL = NULL;
FreeCachedVariant(&V->value);
- if ( VL->first == V )
+ if ( VL->first == V ) {
VL->first = V->next;
- for ( V1=VL->first; V1 != NULL; V1 = V1->next )
- if ( V1->next == V ) {
- V1->next = V->next;
- break;
- }
+ if (VL->last == V)
+ VL->last = V->next; // NULL
+ }
+ else
+ for ( V1 = VL->first; V1 != NULL; V1 = V1->next )
+ if ( V1->next == V ) {
+ V1->next = V->next;
+ if (VL->last == V)
+ VL->last = V1;
+ break;
+ }
HeapFree(hCacheHeap,0,V);
return NULL;
}
@@ -224,23 +213,38 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo
#define VLT(n) ((n==DBVT_UTF8)?DBVT_ASCIIZ:n)
static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic)
{
- struct DBContact dbc;
- struct DBContactSettings dbcs;
+ struct DBContact *dbc;
DWORD ofsModuleName,ofsContact,ofsSettingsGroup,ofsBlobPtr;
- int settingNameLen;
+ int settingNameLen,moduleNameLen;
int bytesRemaining;
PBYTE pBlob;
char* szCachedSettingName;
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=strlen(dbcgs->szSetting);
+ moduleNameLen=strlen(dbcgs->szModule);
+ if ( settingNameLen > 0xFE )
+ {
+ #ifdef _DEBUG
+ OutputDebugString("GetContactSettingWorker() got a > 255 setting name length. \n");
+ #endif
+ return 1;
+ }
+ if ( moduleNameLen > 0xFE )
+ {
+ #ifdef _DEBUG
+ OutputDebugString("GetContactSettingWorker() got a > 255 module name length. \n");
+ #endif
+ return 1;
+ }
EnterCriticalSection(&csDbAccess);
log3("get [%08p] %s/%s",hContact,dbcgs->szModule,dbcgs->szSetting);
- szCachedSettingName = GetCachedSetting(dbcgs->szModule,dbcgs->szSetting,settingNameLen);
+ szCachedSettingName = GetCachedSetting(dbcgs->szModule,dbcgs->szSetting,moduleNameLen,settingNameLen);
{
DBVARIANT* pCachedValue = GetCachedValuePtr( hContact, szCachedSettingName, 0 );
if ( pCachedValue != NULL ) {
@@ -284,16 +288,15 @@ static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING
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) {
+ dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
+ if(dbc->signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
+ ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
if(ofsSettingsGroup) {
- dbcs=*(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining);
ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob);
- pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining);
+ pBlob = DBRead(ofsBlobPtr,sizeof(struct DBContactSettings),&bytesRemaining);
while(pBlob[0]) {
NeedBytes(1+settingNameLen);
if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) {
@@ -485,21 +488,32 @@ static int FreeVariant(WPARAM wParam,LPARAM lParam)
static int SetSettingResident(WPARAM wParam,LPARAM lParam)
{
- char* szSetting;
- size_t cbSettingNameLen = strlen(( char* )lParam );
- int idx;
- char* szTemp = ( char* )alloca( cbSettingNameLen+2 );
- strcpy( szTemp+1, ( char* )lParam );
+ size_t cbSettingNameLen = strlen(( char* )lParam) + 2;
+ if (cbSettingNameLen < 512)
+ {
+ char* szSetting;
+ int idx;
+ char szTemp[512];
+ strcpy( szTemp+1, ( char* )lParam );
+
+ EnterCriticalSection(&csDbAccess);
+ if ( !li.List_GetIndex( &lSettings, szTemp, &idx ))
+ szSetting = InsertCachedSetting( szTemp, cbSettingNameLen, idx );
+ else
+ szSetting = lSettings.items[ idx ];
- EnterCriticalSection(&csDbAccess);
- if ( !li.List_GetIndex( &lSettings, szTemp, &idx ))
- szSetting = InsertCachedSetting( szTemp, cbSettingNameLen+2, idx );
- else
- szSetting = lSettings.items[ idx ];
+ *szSetting = (char)wParam;
- *szSetting = (char)wParam;
+ if ( !li.List_GetIndex( &lResidentSettings, szSetting+1, &idx ))
+ {
+ if (wParam)
+ li.List_Insert(&lResidentSettings,szSetting+1,idx);
+ }
+ else if (!wParam)
+ li.List_Remove(&lResidentSettings,idx);
- LeaveCriticalSection(&csDbAccess);
+ LeaveCriticalSection(&csDbAccess);
+ }
return 0;
}
@@ -513,13 +527,30 @@ static int WriteContactSetting(WPARAM wParam,LPARAM lParam)
int settingNameLen=0;
int moduleNameLen=0;
int settingDataLen=0;
-
int bytesRequired,bytesRemaining;
DWORD ofsContact,ofsSettingsGroup,ofsBlobPtr;
if (dbcws == NULL)
return 1;
+ // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
+ settingNameLen=strlen(dbcws->szSetting);
+ moduleNameLen=strlen(dbcws->szModule);
+ if ( settingNameLen > 0xFE )
+ {
+ #ifdef _DEBUG
+ OutputDebugString("WriteContactSetting() got a > 255 setting name length. \n");
+ #endif
+ return 1;
+ }
+ if ( moduleNameLen > 0xFE )
+ {
+ #ifdef _DEBUG
+ OutputDebugString("WriteContactSetting() got a > 255 module name length. \n");
+ #endif
+ return 1;
+ }
+
if (dbcws->value.type == DBVT_WCHAR) {
if (dbcws->value.pszVal != NULL) {
char* val = mir_utf8encodeW(dbcws->value.pwszVal);
@@ -538,23 +569,6 @@ static int WriteContactSetting(WPARAM wParam,LPARAM lParam)
return 1;
if ((!dbcws->szModule) || (!dbcws->szSetting) || ((dbcws->value.type == DBVT_ASCIIZ || dbcws->value.type == DBVT_UTF8 )&& dbcws->value.pszVal == NULL) || (dbcws->value.type == DBVT_BLOB && dbcws->value.pbVal == NULL) )
return 1;
- // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
- settingNameLen=strlen(dbcws->szSetting);
- moduleNameLen=strlen(dbcws->szModule);
- if ( settingNameLen > 0xFE )
- {
- #ifdef _DEBUG
- OutputDebugString("WriteContactSetting() got a > 255 setting name length. \n");
- #endif
- return 1;
- }
- if ( moduleNameLen > 0xFE )
- {
- #ifdef _DEBUG
- OutputDebugString("WriteContactSetting() got a > 255 module name length. \n");
- #endif
- return 1;
- }
// the db can not tolerate strings/blobs longer than 0xFFFF since the format writes 2 lengths
switch( dbcws->value.type ) {
@@ -571,7 +585,7 @@ static int WriteContactSetting(WPARAM wParam,LPARAM lParam)
EnterCriticalSection(&csDbAccess);
{
- char* szCachedSettingName = GetCachedSetting(dbcws->szModule, dbcws->szSetting, settingNameLen);
+ char* szCachedSettingName = GetCachedSetting(dbcws->szModule, dbcws->szSetting, moduleNameLen, settingNameLen);
if ( dbcws->value.type != DBVT_BLOB ) {
DBVARIANT* pCachedValue = GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, 1);
if ( pCachedValue != NULL ) {
@@ -611,7 +625,7 @@ static int WriteContactSetting(WPARAM wParam,LPARAM lParam)
}
log0("write setting");
//make sure the module group exists
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
+ ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsModuleName);
if(ofsSettingsGroup==0) { //module group didn't exist - make it
if(dbcws->value.type&DBVTF_VARIABLELENGTH) {
if(dbcws->value.type==DBVT_ASCIIZ || dbcws->value.type==DBVT_UTF8) bytesRequired=strlen(dbcws->value.pszVal)+2;
@@ -704,9 +718,8 @@ static int WriteContactSetting(WPARAM wParam,LPARAM lParam)
if((DWORD)bytesRequired>dbcs.cbBlob) {
//doesn't fit: move entire group
struct DBContactSettings *dbcsPrev;
- DWORD ofsDbcsPrev,oldSize,ofsNew;
+ DWORD ofsDbcsPrev,ofsNew;
- InvalidateSettingsGroupOfsCacheEntry(ofsSettingsGroup);
bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY;
//find previous group to change its offset
ofsDbcsPrev=dbc.ofsFirstSettings;
@@ -714,17 +727,17 @@ static int WriteContactSetting(WPARAM wParam,LPARAM lParam)
else {
dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
while(dbcsPrev->ofsNext!=ofsSettingsGroup) {
- if(dbcsPrev->ofsNext==0) DatabaseCorruption();
+ if(dbcsPrev->ofsNext==0) DatabaseCorruption(NULL);
ofsDbcsPrev=dbcsPrev->ofsNext;
dbcsPrev=(struct DBContactSettings*)DBRead(ofsDbcsPrev,sizeof(struct DBContactSettings),NULL);
}
}
+
//create the new one
- ofsNew=CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob));
- //copy across
- DBMoveChunk(ofsNew,ofsSettingsGroup,bytesRequired+offsetof(struct DBContactSettings,blob));
- oldSize=dbcs.cbBlob;
+ ofsNew=ReallocSpace(ofsSettingsGroup, dbcs.cbBlob+offsetof(struct DBContactSettings,blob), bytesRequired+offsetof(struct DBContactSettings,blob));
+
dbcs.cbBlob=bytesRequired;
+
DBWrite(ofsNew,&dbcs,offsetof(struct DBContactSettings,blob));
if(ofsDbcsPrev==0) {
dbc.ofsFirstSettings=ofsNew;
@@ -735,7 +748,6 @@ static int WriteContactSetting(WPARAM wParam,LPARAM lParam)
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);
@@ -780,14 +792,30 @@ static int DeleteContactSetting(WPARAM wParam,LPARAM lParam)
DBCONTACTGETSETTING *dbcgs=(DBCONTACTGETSETTING*)lParam;
struct DBContact *dbc;
DWORD ofsModuleName,ofsSettingsGroup,ofsBlobPtr;
- struct DBContactSettings dbcs;
PBYTE pBlob;
- int settingNameLen=strlen(dbcgs->szSetting),bytesRemaining;
+ int settingNameLen,moduleNameLen,bytesRemaining;
char* szCachedSettingName;
WPARAM saveWparam = wParam;
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=strlen(dbcgs->szSetting);
+ moduleNameLen=strlen(dbcgs->szModule);
+ if ( settingNameLen > 0xFE )
+ {
+ #ifdef _DEBUG
+ OutputDebugString("DeleteContactSetting() got a > 255 setting name length. \n");
+ #endif
+ return 1;
+ }
+ if ( moduleNameLen > 0xFE )
+ {
+ #ifdef _DEBUG
+ OutputDebugString("DeleteContactSetting() got a > 255 module name length. \n");
+ #endif
+ return 1;
+ }
EnterCriticalSection(&csDbAccess);
ofsModuleName=GetModuleNameOfs(dbcgs->szModule);
@@ -799,22 +827,11 @@ static int DeleteContactSetting(WPARAM wParam,LPARAM lParam)
return 1;
}
//make sure the module group exists
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,wParam,ofsModuleName);
- if(ofsSettingsGroup==0) {
- LeaveCriticalSection(&csDbAccess);
- return 1;
- }
- dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL);
- if(dbc->signature!=DBCONTACT_SIGNATURE) {
- LeaveCriticalSection(&csDbAccess);
- return 1;
- }
- ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,wParam,ofsModuleName);
+ ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName);
if(ofsSettingsGroup==0) {
LeaveCriticalSection(&csDbAccess);
return 1;
}
- 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);
@@ -851,14 +868,14 @@ static int DeleteContactSetting(WPARAM wParam,LPARAM lParam)
DBMoveChunk(ofsSettingToCut,ofsSettingToCut+nameLen+valLen,ofsBlobPtr+1-ofsSettingToCut);
}
- szCachedSettingName = GetCachedSetting(dbcgs->szModule,dbcgs->szSetting,settingNameLen);
+ szCachedSettingName = GetCachedSetting(dbcgs->szModule,dbcgs->szSetting,moduleNameLen,settingNameLen);
GetCachedValuePtr((HANDLE)saveWparam, szCachedSettingName, -1 );
//quit
DBFlush(1);
LeaveCriticalSection(&csDbAccess);
{ //notify
- DBCONTACTWRITESETTING dbcws;
+ DBCONTACTWRITESETTING dbcws={0};
dbcws.szModule=dbcgs->szModule;
dbcws.szSetting=dbcgs->szSetting;
dbcws.value.type=DBVT_DELETED;
@@ -870,8 +887,7 @@ static int DeleteContactSetting(WPARAM wParam,LPARAM lParam)
static int EnumContactSettings(WPARAM wParam,LPARAM lParam)
{
DBCONTACTENUMSETTINGS *dbces=(DBCONTACTENUMSETTINGS*)lParam;
- struct DBContact dbc;
- struct DBContactSettings dbcs;
+ struct DBContact *dbc;
DWORD ofsModuleName,ofsContact,ofsBlobPtr;
int bytesRemaining, result;
PBYTE pBlob;
@@ -885,17 +901,16 @@ static int EnumContactSettings(WPARAM wParam,LPARAM lParam)
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) {
+ dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
+ if(dbc->signature!=DBCONTACT_SIGNATURE) {
LeaveCriticalSection(&csDbAccess);
return -1;
}
- dbces->ofsSettings=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName);
+ dbces->ofsSettings=GetSettingsGroupOfsByModuleNameOfs(dbc,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) {
@@ -917,6 +932,17 @@ static int EnumContactSettings(WPARAM wParam,LPARAM lParam)
return result;
}
+static int EnumResidentSettings(WPARAM wParam,LPARAM lParam)
+{
+ int i;
+ int ret;
+ for(i = 0; i < lResidentSettings.realCount; i++) {
+ ret=((DBMODULEENUMPROC)lParam)(lResidentSettings.items[i],0,wParam);
+ if(ret) return ret;
+ }
+ return 0;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
//
// Module initialization procedure
@@ -926,16 +952,18 @@ static int stringCompare( DBCachedSettingName* p1, DBCachedSettingName* p2 )
return strcmp( p1->name, p2->name );
}
-static int stringCompare2( DBCachedGlobalValue* p1, DBCachedGlobalValue* p2 )
+static int ptrCompare( DBCachedGlobalValue* p1, DBCachedGlobalValue* p2 )
{
- return strcmp( p1->name, p2->name );
+ return (p1->name - p2->name);
}
-static int handleCompare( void* p1, void* p2 )
+static int stringCompare2( char* p1, char* p2 )
{
- if ( *( long* )p1 == *( long* )p2 )
- return 0;
+ return strcmp( p1, p2);
+}
+static int handleCompare( void* p1, void* p2 )
+{
return *( long* )p1 - *( long* )p2;
}
@@ -949,15 +977,19 @@ int InitSettings(void)
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);
lSettings.sortFunc=stringCompare;
- lSettings.increment=50;
+ lSettings.increment=100;
lContacts.sortFunc=handleCompare;
- lContacts.increment=100;
- lGlobalSettings.sortFunc=stringCompare2;
- lGlobalSettings.increment=100;
+ lContacts.increment=50;
+ lGlobalSettings.sortFunc=ptrCompare;
+ lGlobalSettings.increment=50;
+ lResidentSettings.sortFunc=stringCompare2;
+ lResidentSettings.increment=50;
return 0;
}
@@ -967,4 +999,5 @@ void UninitSettings(void)
li.List_Destroy(&lContacts);
li.List_Destroy(&lSettings);
li.List_Destroy(&lGlobalSettings);
+ li.List_Destroy(&lResidentSettings);
}