diff options
Diffstat (limited to 'plugins/Dbx_mmap_SA/dbsettings.cpp')
-rw-r--r-- | plugins/Dbx_mmap_SA/dbsettings.cpp | 380 |
1 files changed, 182 insertions, 198 deletions
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);
|