diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-18 14:11:28 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-18 14:11:28 +0000 |
commit | 4bc88d46fa9859615521f436511d4f102f20eb67 (patch) | |
tree | 3a6ee91b74be2a4f5e60520885aa601c74bc3fa7 /plugins/Dbx_mmap_SA/dbevents.cpp | |
parent | 4f8f5427687792492ee49e06cafb9bd50cfc53d4 (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
Diffstat (limited to 'plugins/Dbx_mmap_SA/dbevents.cpp')
-rw-r--r-- | plugins/Dbx_mmap_SA/dbevents.cpp | 452 |
1 files changed, 205 insertions, 247 deletions
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;
}
|