summaryrefslogtreecommitdiff
path: root/db3x_autobackups/dbcontacts.c
diff options
context:
space:
mode:
Diffstat (limited to 'db3x_autobackups/dbcontacts.c')
-rw-r--r--db3x_autobackups/dbcontacts.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/db3x_autobackups/dbcontacts.c b/db3x_autobackups/dbcontacts.c
index 5985590..41253c0 100644
--- a/db3x_autobackups/dbcontacts.c
+++ b/db3x_autobackups/dbcontacts.c
@@ -22,7 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "commonheaders.h"
-#include "database.h"
+
+extern HANDLE hCacheHeap;
+extern SortedList lContacts;
+extern HANDLE hLastCachedContact;
+
+int GetContactSettingStatic(WPARAM wParam,LPARAM lParam);
+void FreeCachedVariant( DBVARIANT* V );
static int GetContactCount(WPARAM wParam,LPARAM lParam);
static int FindFirstContact(WPARAM wParam,LPARAM lParam);
@@ -31,12 +37,8 @@ static int DeleteContact(WPARAM wParam,LPARAM lParam);
static int AddContact(WPARAM wParam,LPARAM lParam);
static int IsDbContact(WPARAM wParam,LPARAM lParam);
-extern CRITICAL_SECTION csDbAccess;
-extern struct DBHeader dbHeader;
static HANDLE hContactDeletedEvent,hContactAddedEvent;
-extern HANDLE hCacheHeap;
-extern SortedList lContacts;
int InitContacts(void)
{
@@ -55,7 +57,15 @@ void UninitContacts(void)
{
}
-int GetContactSettingStatic(WPARAM wParam,LPARAM lParam);
+DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index)
+{
+ DBCachedContactValueList* VL;
+ VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList));
+ VL->hContact = hContact;
+ if (index == -1) li.List_GetIndex(&lContacts,VL,&index);
+ li.List_Insert(&lContacts,VL,index);
+ return VL;
+}
static int GetContactCount(WPARAM wParam,LPARAM lParam)
{
@@ -104,7 +114,7 @@ static int FindNextContact(WPARAM wParam,LPARAM lParam)
DBCachedContactValueList VLtemp, *VL = NULL;
VLtemp.hContact = (HANDLE)wParam;
EnterCriticalSection(&csDbAccess);
- while ( VLtemp.hContact ) {
+ while(VLtemp.hContact) {
if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) {
VL = ( DBCachedContactValueList* )lContacts.items[index];
if (VL->hNext != NULL) {
@@ -112,20 +122,18 @@ static int FindNextContact(WPARAM wParam,LPARAM lParam)
LeaveCriticalSection(&csDbAccess);
return (int)VL->hNext;
}
-
- VLtemp.hContact = VL->hNext;
- continue;
- } }
+ else {
+ VLtemp.hContact = VL->hNext;
+ continue;
+ } } }
dbc=(struct DBContact*)DBRead((DWORD)VLtemp.hContact,sizeof(struct 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;
- li.List_Insert(&lContacts,VL,index);
- }
+ if ( VL == NULL )
+ VL = AddToCachedContactList(VLtemp.hContact,index);
+
VL->hNext = (HANDLE)dbc->ofsNext;
if (VL->hNext != NULL && (!lParam || CheckProto(VL->hNext,(const char*)lParam))) {
LeaveCriticalSection(&csDbAccess);
@@ -172,13 +180,14 @@ static int DeleteContact(WPARAM wParam,LPARAM lParam)
DBCachedContactValue* V = VL->first;
while ( V != NULL ) {
DBCachedContactValue* V1 = V->next;
- if ( V->value.type == DBVT_ASCIIZ )
- HeapFree( hCacheHeap, 0, V->value.pszVal );
+ FreeCachedVariant(&V->value);
HeapFree( hCacheHeap, 0, V );
V = V1;
}
HeapFree( hCacheHeap, 0, VL );
+ if (VLtemp.hContact == hLastCachedContact)
+ hLastCachedContact = NULL;
li.List_Remove(&lContacts,index);
} }
@@ -211,7 +220,7 @@ static int DeleteContact(WPARAM wParam,LPARAM lParam)
ofsThis=dbHeader.ofsFirstContact;
dbcPrev=(struct DBContact*)DBRead(ofsThis,sizeof(struct DBContact),NULL);
while(dbcPrev->ofsNext!=wParam) {
- if(dbcPrev->ofsNext==0) DatabaseCorruption();
+ if(dbcPrev->ofsNext==0) DatabaseCorruption(NULL);
ofsThis=dbcPrev->ofsNext;
dbcPrev=(struct DBContact*)DBRead(ofsThis,sizeof(struct DBContact),NULL);
}
@@ -258,14 +267,7 @@ static int AddContact(WPARAM wParam,LPARAM lParam)
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFlush(0);
- { int index;
-
- DBCachedContactValueList *VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList));
- VL->hContact = (HANDLE)ofsNew;
-
- li.List_GetIndex(&lContacts,VL,&index);
- li.List_Insert(&lContacts,VL,index);
- }
+ AddToCachedContactList((HANDLE)ofsNew, -1);
LeaveCriticalSection(&csDbAccess);
NotifyEventHooks(hContactAddedEvent,(WPARAM)ofsNew,0);
@@ -274,26 +276,23 @@ static int AddContact(WPARAM wParam,LPARAM lParam)
static int IsDbContact(WPARAM wParam,LPARAM lParam)
{
- struct DBContact dbc;
+ struct DBContact *dbc;
DWORD ofsContact=(DWORD)wParam;
int ret;
EnterCriticalSection(&csDbAccess);
{
int index;
- DBCachedContactValueList VLtemp,*VL;
+ DBCachedContactValueList VLtemp;
VLtemp.hContact = (HANDLE)wParam;
if ( li.List_GetIndex(&lContacts,&VLtemp,&index))
ret = TRUE;
else {
- dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
- ret=dbc.signature==DBCONTACT_SIGNATURE;
-
- if (ret) {
- VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList));
- VL->hContact = (HANDLE)wParam;
- li.List_Insert(&lContacts,VL,index);
- } } }
+ dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL);
+ ret=dbc->signature==DBCONTACT_SIGNATURE;
+ if (ret)
+ AddToCachedContactList((HANDLE)wParam, index);
+ } }
LeaveCriticalSection(&csDbAccess);
return ret;