diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/database/database.h | 10 | ||||
-rw-r--r-- | src/modules/database/dbintf.cpp | 6 | ||||
-rw-r--r-- | src/modules/database/mdatabasecache.cpp | 90 | ||||
-rw-r--r-- | src/modules/protocols/protochains.cpp | 12 |
4 files changed, 64 insertions, 54 deletions
diff --git a/src/modules/database/database.h b/src/modules/database/database.h index 33121c8fcf..286c651c02 100644 --- a/src/modules/database/database.h +++ b/src/modules/database/database.h @@ -39,12 +39,14 @@ public: ~MDatabaseCache();
protected:
- STDMETHODIMP_(DBCachedContact*) AddContactToCache(HANDLE hContact);
- STDMETHODIMP_(DBCachedContact*) GetCachedContact(HANDLE hContact);
- STDMETHODIMP_(void) FreeCachedContact(HANDLE hContact);
+ STDMETHODIMP_(DBCachedContact*) AddContactToCache(MCONTACT contactID);
+ STDMETHODIMP_(DBCachedContact*) GetCachedContact(MCONTACT contactID);
+ STDMETHODIMP_(DBCachedContact*) GetFirstContact(void);
+ STDMETHODIMP_(DBCachedContact*) GetNextContact(MCONTACT contactID);
+ STDMETHODIMP_(void) FreeCachedContact(MCONTACT contactID);
STDMETHODIMP_(char*) InsertCachedSetting(const char *szName, int);
STDMETHODIMP_(char*) GetCachedSetting(const char *szModuleName, const char *szSettingName, int, int);
STDMETHODIMP_(void) SetCachedVariant(DBVARIANT *s, DBVARIANT *d);
- STDMETHODIMP_(DBVARIANT*) GetCachedValuePtr(HANDLE hContact, char *szSetting, int bAllocate);
+ STDMETHODIMP_(DBVARIANT*) GetCachedValuePtr(MCONTACT contactID, char *szSetting, int bAllocate);
};
diff --git a/src/modules/database/dbintf.cpp b/src/modules/database/dbintf.cpp index a03ac5b97c..a4a4e7a1a7 100644 --- a/src/modules/database/dbintf.cpp +++ b/src/modules/database/dbintf.cpp @@ -52,7 +52,7 @@ static INT_PTR srvDeleteContact(WPARAM wParam, LPARAM) DeleteFile(dbv.ptszVal);
db_free(&dbv);
}
- return (currDb) ? currDb->DeleteContact((HANDLE)wParam) : 0;
+ return (currDb) ? currDb->DeleteContact(wParam) : 0;
}
static INT_PTR srvAddContact(WPARAM wParam, LPARAM)
@@ -62,7 +62,7 @@ static INT_PTR srvAddContact(WPARAM wParam, LPARAM) static INT_PTR srvIsDbContact(WPARAM wParam, LPARAM)
{
- return (currDb) ? currDb->IsDbContact((HANDLE)wParam) : 0;
+ return (currDb) ? currDb->IsDbContact(wParam) : 0;
}
///////////////////////////////////////////////////////////////////////////////
@@ -78,7 +78,7 @@ static INT_PTR srvEnumModuleNames(WPARAM wParam,LPARAM lParam) static INT_PTR srvEnumContactSettings(WPARAM wParam,LPARAM lParam)
{
- return (currDb) ? (INT_PTR)currDb->EnumContactSettings((HANDLE)wParam, (DBCONTACTENUMSETTINGS*)lParam) : 0;
+ return (currDb) ? (INT_PTR)currDb->EnumContactSettings(wParam, (DBCONTACTENUMSETTINGS*)lParam) : 0;
}
static INT_PTR srvEnumResidentSettings(WPARAM wParam,LPARAM lParam)
diff --git a/src/modules/database/mdatabasecache.cpp b/src/modules/database/mdatabasecache.cpp index f6c13e0cda..1dcd29861e 100644 --- a/src/modules/database/mdatabasecache.cpp +++ b/src/modules/database/mdatabasecache.cpp @@ -36,7 +36,7 @@ static int compareGlobals(const DBCachedGlobalValue* p1, const DBCachedGlobalVal MDatabaseCache::MDatabaseCache() :
m_lSettings(100, stringCompare),
- m_lContacts(50, HandleKeySortT),
+ m_lContacts(50, NumericKeySortT),
m_lGlobalSettings(50, compareGlobals)
{
m_hCacheHeap = HeapCreate(0, 0, 0);
@@ -51,34 +51,48 @@ MDatabaseCache::~MDatabaseCache() /////////////////////////////////////////////////////////////////////////////////////////
-DBCachedContact* MDatabaseCache::AddContactToCache(HANDLE hContact)
+DBCachedContact* MDatabaseCache::AddContactToCache(MCONTACT contactID)
{
mir_cslock lck(m_cs);
- int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
+ int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
if (index == -1) {
DBCachedContact* VL = (DBCachedContact*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedContact));
- VL->hContact = hContact;
+ VL->contactID = contactID;
m_lContacts.insert(VL);
return VL;
}
- return m_lContacts[ index ];
+ return m_lContacts[index];
}
-DBCachedContact* MDatabaseCache::GetCachedContact(HANDLE hContact)
+DBCachedContact* MDatabaseCache::GetCachedContact(MCONTACT contactID)
{
mir_cslock lck(m_cs);
- int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
+ int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
return (index == -1) ? NULL : m_lContacts[index];
}
-void MDatabaseCache::FreeCachedContact(HANDLE hContact)
+DBCachedContact* MDatabaseCache::GetFirstContact()
{
mir_cslock lck(m_cs);
+ return m_lContacts[0];
+}
+
+DBCachedContact* MDatabaseCache::GetNextContact(MCONTACT contactID)
+{
+ mir_cslock lck(m_cs);
+
+ int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
+ return (index == -1) ? NULL : m_lContacts[index+1];
+}
- int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
+void MDatabaseCache::FreeCachedContact(MCONTACT contactID)
+{
+ mir_cslock lck(m_cs);
+
+ int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
if (index == -1)
return;
@@ -87,18 +101,12 @@ void MDatabaseCache::FreeCachedContact(HANDLE hContact) while (V != NULL) {
DBCachedContactValue* V1 = V->next;
FreeCachedVariant(&V->value);
- HeapFree( m_hCacheHeap, 0, V );
+ HeapFree(m_hCacheHeap, 0, V);
V = V1;
}
- HeapFree( m_hCacheHeap, 0, VL );
+ HeapFree(m_hCacheHeap, 0, VL);
m_lContacts.remove(index);
-
- for (int i=0; i < m_lContacts.getCount(); i++) {
- DBCachedContact *cc = m_lContacts[i];
- if (cc->hNext == hContact)
- cc->hNext = NULL;
- }
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -112,14 +120,14 @@ char* MDatabaseCache::InsertCachedSetting(const char* szName, int cbLen) return newValue;
}
-char* MDatabaseCache::GetCachedSetting(const char *szModuleName,const char *szSettingName, int moduleNameLen, int settingNameLen)
+char* MDatabaseCache::GetCachedSetting(const char *szModuleName, const char *szSettingName, int moduleNameLen, int settingNameLen)
{
char szFullName[512];
const char *szKey;
if (szModuleName != NULL) {
strcpy(szFullName, szModuleName);
szFullName[moduleNameLen] = '/';
- strcpy(szFullName+moduleNameLen+1,szSettingName);
+ strcpy(szFullName + moduleNameLen + 1, szSettingName);
szKey = szFullName;
}
else szKey = szSettingName;
@@ -131,56 +139,56 @@ char* MDatabaseCache::GetCachedSetting(const char *szModuleName,const char *szSe if (index != -1)
m_lastSetting = m_lSettings[index];
else
- m_lastSetting = InsertCachedSetting(szKey, settingNameLen+moduleNameLen+3);
+ m_lastSetting = InsertCachedSetting(szKey, settingNameLen + moduleNameLen + 3);
return m_lastSetting;
}
-void MDatabaseCache::SetCachedVariant(DBVARIANT* s /* new */, DBVARIANT* d /* cached */ )
+void MDatabaseCache::SetCachedVariant(DBVARIANT* s /* new */, DBVARIANT* d /* cached */)
{
- char* szSave = ( d->type == DBVT_UTF8 || d->type == DBVT_ASCIIZ ) ? d->pszVal : NULL;
+ char* szSave = (d->type == DBVT_UTF8 || d->type == DBVT_ASCIIZ) ? d->pszVal : NULL;
- memcpy( d, s, sizeof( DBVARIANT ));
- if (( s->type == DBVT_UTF8 || s->type == DBVT_ASCIIZ ) && s->pszVal != NULL ) {
- if ( szSave != NULL )
- d->pszVal = (char*)HeapReAlloc(m_hCacheHeap,0,szSave,strlen(s->pszVal)+1);
+ memcpy(d, s, sizeof(DBVARIANT));
+ if ((s->type == DBVT_UTF8 || s->type == DBVT_ASCIIZ) && s->pszVal != NULL) {
+ if (szSave != NULL)
+ d->pszVal = (char*)HeapReAlloc(m_hCacheHeap, 0, szSave, strlen(s->pszVal) + 1);
else
- d->pszVal = (char*)HeapAlloc(m_hCacheHeap,0,strlen(s->pszVal)+1);
- strcpy(d->pszVal,s->pszVal);
+ d->pszVal = (char*)HeapAlloc(m_hCacheHeap, 0, strlen(s->pszVal) + 1);
+ strcpy(d->pszVal, s->pszVal);
}
- else if ( szSave != NULL ) {
- HeapFree(m_hCacheHeap,0,szSave);
+ else if (szSave != NULL) {
+ HeapFree(m_hCacheHeap, 0, szSave);
d->pszVal = NULL;
}
}
void MDatabaseCache::FreeCachedVariant(DBVARIANT* V)
{
- if (( V->type == DBVT_ASCIIZ || V->type == DBVT_UTF8 ) && V->pszVal != NULL )
- HeapFree(m_hCacheHeap,0,V->pszVal);
+ if ((V->type == DBVT_ASCIIZ || V->type == DBVT_UTF8) && V->pszVal != NULL)
+ HeapFree(m_hCacheHeap, 0, V->pszVal);
}
-STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(HANDLE hContact, char *szSetting, int bAllocate)
+STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(MCONTACT contactID, char *szSetting, int bAllocate)
{
// a global setting
- if ( hContact == 0 ) {
+ if (contactID == 0) {
DBCachedGlobalValue Vtemp, *V;
Vtemp.name = szSetting;
int index = m_lGlobalSettings.getIndex(&Vtemp);
if (index != -1) {
V = m_lGlobalSettings[index];
- if ( bAllocate == -1 ) {
- FreeCachedVariant( &V->value );
+ if (bAllocate == -1) {
+ FreeCachedVariant(&V->value);
m_lGlobalSettings.remove(index);
- HeapFree(m_hCacheHeap,0,V);
+ HeapFree(m_hCacheHeap, 0, V);
return NULL;
}
}
else {
- if ( bAllocate != 1 )
+ if (bAllocate != 1)
return NULL;
- V = (DBCachedGlobalValue*)HeapAlloc(m_hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedGlobalValue));
+ V = (DBCachedGlobalValue*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedGlobalValue));
V->name = szSetting;
m_lGlobalSettings.insert(V);
}
@@ -192,14 +200,14 @@ STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(HANDLE hContact, cha DBCachedContactValue *V, *V1;
DBCachedContact VLtemp,*VL;
- VLtemp.hContact = hContact;
+ VLtemp.contactID = contactID;
int index = m_lContacts.getIndex(&VLtemp);
if (index == -1) {
if ( bAllocate != 1 )
return NULL;
- VL = AddContactToCache(hContact);
+ VL = AddContactToCache(contactID);
}
else VL = m_lContacts[index];
diff --git a/src/modules/protocols/protochains.cpp b/src/modules/protocols/protochains.cpp index 3841d1842f..e14837c18f 100644 --- a/src/modules/protocols/protochains.cpp +++ b/src/modules/protocols/protochains.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern LIST<PROTOCOLDESCRIPTOR> filters;
-static int GetProtocolP(HANDLE hContact, char *szBuf, int cbLen)
+static int GetProtocolP(MCONTACT hContact, char *szBuf, int cbLen)
{
if (currDb == NULL)
return 1;
@@ -69,7 +69,7 @@ INT_PTR CallContactService(HANDLE hContact, const char *szProtoService, WPARAM w }
char szProto[40];
- if ( GetProtocolP(hContact, szProto, sizeof(szProto)))
+ if ( GetProtocolP((MCONTACT)hContact, szProto, sizeof(szProto)))
return 1;
PROTOACCOUNT *pa = Proto_GetAccount(szProto);
@@ -104,7 +104,7 @@ INT_PTR Proto_CallContactService(WPARAM wParam, LPARAM lParam) }
char szProto[40];
- if ( GetProtocolP(ccs->hContact, szProto, sizeof(szProto)))
+ if (GetProtocolP((MCONTACT)ccs->hContact, szProto, sizeof(szProto)))
return 1;
PROTOACCOUNT *pa = Proto_GetAccount(szProto);
@@ -144,7 +144,7 @@ static INT_PTR Proto_RecvChain(WPARAM wParam, LPARAM lParam) //end of chain, call network protocol again
char szProto[40];
- if ( GetProtocolP(ccs->hContact, szProto, sizeof(szProto)))
+ if (GetProtocolP((MCONTACT)ccs->hContact, szProto, sizeof(szProto)))
return 1;
PROTOACCOUNT *pa = Proto_GetAccount(szProto);
@@ -167,7 +167,7 @@ PROTOACCOUNT* __fastcall Proto_GetAccount(HANDLE hContact) return NULL;
char szProto[40];
- if ( GetProtocolP(hContact, szProto, sizeof(szProto)))
+ if (GetProtocolP((MCONTACT)hContact, szProto, sizeof(szProto)))
return NULL;
return Proto_GetAccount(szProto);
@@ -192,7 +192,7 @@ static INT_PTR Proto_IsProtoOnContact(WPARAM wParam, LPARAM lParam) return 0;
char szContactProto[40];
- if (!GetProtocolP((HANDLE)wParam, szContactProto, sizeof(szContactProto)))
+ if (!GetProtocolP(wParam, szContactProto, sizeof(szContactProto)))
if (!_stricmp(szProto, szContactProto))
return -1;
|