summaryrefslogtreecommitdiff
path: root/plugins/Db3x/src/dbcontacts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Db3x/src/dbcontacts.cpp')
-rw-r--r--plugins/Db3x/src/dbcontacts.cpp268
1 files changed, 125 insertions, 143 deletions
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);
} } }