summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/clist/clc.cpp11
-rw-r--r--src/modules/clist/clc.h6
-rw-r--r--src/modules/clist/clcitems.cpp40
-rw-r--r--src/modules/database/dbutils.cpp61
-rw-r--r--src/modules/database/mdatabasecache.cpp25
-rw-r--r--src/modules/protocols/protochains.cpp23
6 files changed, 84 insertions, 82 deletions
diff --git a/src/modules/clist/clc.cpp b/src/modules/clist/clc.cpp
index dba24ad84b..71461f83e9 100644
--- a/src/modules/clist/clc.cpp
+++ b/src/modules/clist/clc.cpp
@@ -52,7 +52,7 @@ void fnClcOptionsChanged(void)
cli.pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0);
}
-HMENU fnBuildGroupPopupMenu(struct ClcGroup* group)
+HMENU fnBuildGroupPopupMenu(ClcGroup* group)
{
HMENU hMenu = LoadMenu(cli.hInst, MAKEINTRESOURCE(IDR_CONTEXT));
HMENU hGroupMenu = GetSubMenu(hMenu, 2);
@@ -69,8 +69,11 @@ HMENU fnBuildGroupPopupMenu(struct ClcGroup* group)
static int ClcSettingChanged(WPARAM wParam, LPARAM lParam)
{
+ if ((HANDLE)wParam == NULL)
+ return 0;
+
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam;
- if ((HANDLE)wParam != NULL && !strcmp(cws->szModule, "CList")) {
+ if ( !strcmp(cws->szModule, "CList")) {
if ( !strcmp(cws->szSetting, "MyHandle")) {
cli.pfnInvalidateDisplayNameCacheEntry((HANDLE) wParam);
cli.pfnClcBroadcast(INTM_NAMECHANGED, wParam, lParam);
@@ -90,8 +93,8 @@ static int ClcSettingChanged(WPARAM wParam, LPARAM lParam)
cli.pfnClcBroadcast(INTM_GROUPSCHANGED, wParam, lParam);
}
else {
- char* szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0);
- if (szProto != NULL && (HANDLE) wParam != NULL) {
+ char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0);
+ if (szProto != NULL) {
char *id = NULL;
if ( !strcmp(cws->szModule, "Protocol") && !strcmp(cws->szSetting, "p"))
cli.pfnClcBroadcast(INTM_PROTOCHANGED, wParam, lParam);
diff --git a/src/modules/clist/clc.h b/src/modules/clist/clc.h
index b8bb4d9035..dc5fac0a88 100644
--- a/src/modules/clist/clc.h
+++ b/src/modules/clist/clc.h
@@ -34,7 +34,7 @@ extern int g_IconWidth, g_IconHeight;
void fnClcOptionsChanged(void);
void fnClcBroadcast(int msg, WPARAM wParam, LPARAM lParam);
-HMENU fnBuildGroupPopupMenu(struct ClcGroup* group);
+HMENU fnBuildGroupPopupMenu(ClcGroup* group);
LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
@@ -46,8 +46,8 @@ HANDLE fnContactToHItem(ClcContact* contact);
HANDLE fnContactToItemHandle(ClcContact * contact, DWORD * nmFlags);
/* clcitems.c */
-struct ClcGroup* fnAddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers);
-struct ClcGroup* fnRemoveItemFromGroup(HWND hwnd, ClcGroup *group, ClcContact *contact, int updateTotalCount);
+ClcGroup* fnAddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers);
+ClcGroup* fnRemoveItemFromGroup(HWND hwnd, ClcGroup *group, ClcContact *contact, int updateTotalCount);
void fnFreeContact(ClcContact *p);
void fnFreeGroup(ClcGroup *group);
diff --git a/src/modules/clist/clcitems.cpp b/src/modules/clist/clcitems.cpp
index 0b343f19ca..d7d0fa284b 100644
--- a/src/modules/clist/clcitems.cpp
+++ b/src/modules/clist/clcitems.cpp
@@ -37,7 +37,7 @@ int fnAddItemToGroup(ClcGroup *group, int iAboveItem)
return iAboveItem;
}
-struct ClcGroup* fnAddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers)
+ClcGroup* fnAddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers)
{
TCHAR *pBackslash, *pNextField, szThisField[ SIZEOF(dat->list.cl.items[0]->szText) ];
ClcGroup *group = &dat->list;
@@ -89,11 +89,11 @@ struct ClcGroup* fnAddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName,
group->cl.items[i]->type = CLCIT_GROUP;
lstrcpyn(group->cl.items[i]->szText, szThisField, SIZEOF(group->cl.items[i]->szText));
group->cl.items[i]->groupId = (WORD) (pNextField ? 0 : groupId);
- group->cl.items[i]->group = (ClcGroup *) mir_alloc(sizeof(struct ClcGroup));
+ group->cl.items[i]->group = (ClcGroup *) mir_alloc(sizeof(ClcGroup));
group->cl.items[i]->group->parent = group;
group = group->cl.items[i]->group;
memset(&group->cl, 0, sizeof(group->cl));
- group->cl.increment = 10;
+ group->cl.increment = 10;
if (flags == (DWORD) - 1 || pNextField != NULL) {
group->expanded = 0;
group->hideOffline = 0;
@@ -125,6 +125,7 @@ void fnFreeContact(ClcContact* p)
if (p->type == CLCIT_GROUP) {
cli.pfnFreeGroup(p->group);
mir_free(p->group);
+ p->group = NULL;
} }
void fnFreeGroup(ClcGroup *group)
@@ -169,10 +170,6 @@ int fnAddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText)
int fnAddContactToGroup(struct ClcData *dat, ClcGroup *group, HANDLE hContact)
{
- char *szProto;
- WORD apparentMode;
- DWORD idleMode;
-
int i, index = -1;
dat->needsResort = 1;
@@ -186,14 +183,14 @@ int fnAddContactToGroup(struct ClcData *dat, ClcGroup *group, HANDLE hContact)
}
i = cli.pfnAddItemToGroup(group, index + 1);
- szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
+ char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
group->cl.items[i]->type = CLCIT_CONTACT;
group->cl.items[i]->iImage = CallService(MS_CLIST_GETCONTACTICON, (WPARAM) hContact, 0);
group->cl.items[i]->hContact = hContact;
group->cl.items[i]->proto = szProto;
if (szProto != NULL && !cli.pfnIsHiddenMode(dat, DBGetContactSettingWord(hContact, szProto, "Status", ID_STATUS_OFFLINE)))
group->cl.items[i]->flags |= CONTACTF_ONLINE;
- apparentMode = szProto != NULL ? DBGetContactSettingWord(hContact, szProto, "ApparentMode", 0) : 0;
+ WORD apparentMode = szProto != NULL ? DBGetContactSettingWord(hContact, szProto, "ApparentMode", 0) : 0;
if (apparentMode == ID_STATUS_OFFLINE)
group->cl.items[i]->flags |= CONTACTF_INVISTO;
else if (apparentMode == ID_STATUS_ONLINE)
@@ -202,16 +199,14 @@ int fnAddContactToGroup(struct ClcData *dat, ClcGroup *group, HANDLE hContact)
group->cl.items[i]->flags |= CONTACTF_VISTO | CONTACTF_INVISTO;
if (db_get_b(hContact, "CList", "NotOnList", 0))
group->cl.items[i]->flags |= CONTACTF_NOTONLIST;
- idleMode = szProto != NULL ? db_get_dw(hContact, szProto, "IdleTS", 0) : 0;
+ DWORD idleMode = szProto != NULL ? db_get_dw(hContact, szProto, "IdleTS", 0) : 0;
if (idleMode)
group->cl.items[i]->flags |= CONTACTF_IDLE;
lstrcpyn(group->cl.items[i]->szText, cli.pfnGetContactDisplayName(hContact, 0), SIZEOF(group->cl.items[i]->szText));
- { ClcCacheEntryBase* p = cli.pfnGetCacheEntry(hContact);
- if (p != NULL) {
- if (p->tszGroup) mir_free(p->tszGroup);
- p->tszGroup = NULL;
- } }
+ ClcCacheEntryBase* p = cli.pfnGetCacheEntry(hContact);
+ if (p != NULL)
+ replaceStrT(p->tszGroup, NULL);
return i;
}
@@ -286,20 +281,22 @@ void fnAddContactToTree(HWND hwnd, struct ClcData *dat, HANDLE hContact, int upd
group->totalMembers++;
}
-struct ClcGroup* fnRemoveItemFromGroup(HWND hwnd, ClcGroup *group, ClcContact *contact, int updateTotalCount)
+ClcGroup* fnRemoveItemFromGroup(HWND hwnd, ClcGroup *group, ClcContact *contact, int updateTotalCount)
{
int iContact;
if ((iContact = List_IndexOf((SortedList*)&group->cl, contact)) == -1)
return group;
- if (updateTotalCount && contact->type == CLCIT_CONTACT)
- group->totalMembers--;
+ if (contact->type == CLCIT_CONTACT) {
+ if (updateTotalCount)
+ group->totalMembers--;
- { ClcCacheEntryBase* p = cli.pfnGetCacheEntry(contact->hContact);
+ ClcCacheEntryBase* p = cli.pfnGetCacheEntry(contact->hContact);
if (p != NULL) {
if (p->tszGroup) mir_free(p->tszGroup);
p->tszGroup = NULL;
- } }
+ }
+ }
cli.pfnFreeContact(group->cl.items[iContact]);
mir_free(group->cl.items[iContact]);
@@ -352,8 +349,7 @@ void fnDeleteItemFromTree(HWND hwnd, HANDLE hItem)
}
mir_free(dbv.ptszVal);
}
- else
- cli.pfnRemoveItemFromGroup(hwnd, group, contact, 1);
+ else cli.pfnRemoveItemFromGroup(hwnd, group, contact, 1);
}
void fnRebuildEntireList(HWND hwnd, struct ClcData *dat)
diff --git a/src/modules/database/dbutils.cpp b/src/modules/database/dbutils.cpp
index 4af6e71084..4444c8361c 100644
--- a/src/modules/database/dbutils.cpp
+++ b/src/modules/database/dbutils.cpp
@@ -101,9 +101,9 @@ static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam)
if ( !dbei->pBlob) return 0;
if (dbei->eventType == EVENTTYPE_FILE) {
- char* filename = ((char *)dbei->pBlob) + sizeof(DWORD);
- char* descr = filename + lstrlenA(filename) + 1;
- char* str = (*descr == 0) ? filename : descr;
+ char *filename = ((char *)dbei->pBlob) + sizeof(DWORD);
+ char *descr = filename + lstrlenA(filename) + 1;
+ char *str = (*descr == 0) ? filename : descr;
switch (egt->datatype) {
case DBVT_WCHAR:
return (INT_PTR)((dbei->flags & DBEF_UTF) ? Utf8DecodeT(str) : mir_a2t(str));
@@ -120,9 +120,9 @@ static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam)
egt->datatype &= ~DBVTF_DENYUNICODE;
if (egt->datatype == DBVT_WCHAR) {
- WCHAR* msg = NULL;
+ WCHAR *msg = NULL;
if (dbei->flags & DBEF_UTF) {
- char* str = (char*)alloca(dbei->cbBlob + 1);
+ char *str = (char*)alloca(dbei->cbBlob + 1);
if (str == NULL) return NULL;
memcpy(str, dbei->pBlob, dbei->cbBlob);
str[dbei->cbBlob] = 0;
@@ -132,7 +132,7 @@ static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam)
size_t msglen = strlen((char*)dbei->pBlob) + 1, msglenW = 0;
if (msglen != dbei->cbBlob) {
size_t i, count = ((dbei->cbBlob - msglen) / sizeof(WCHAR));
- WCHAR* p = (WCHAR*)&dbei->pBlob[ msglen ];
+ WCHAR *p = (WCHAR*)&dbei->pBlob[ msglen ];
for (i=0; i < count; i++) {
if (p[i] == 0) {
msglenW = i;
@@ -149,7 +149,7 @@ static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam)
return (INT_PTR)msg;
}
else if (egt->datatype == DBVT_ASCIIZ) {
- char* msg = mir_strdup((char*)dbei->pBlob);
+ char *msg = mir_strdup((char*)dbei->pBlob);
if (dbei->flags & DBEF_UTF)
Utf8DecodeCP(msg, egt->codepage, NULL);
@@ -177,8 +177,7 @@ static INT_PTR DbEventGetIcon(WPARAM wParam, LPARAM lParam)
icon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)szName);
}
- if ( !icon)
- {
+ if ( !icon) {
switch(dbei->eventType) {
case EVENTTYPE_URL:
icon = LoadSkinIcon(SKINICON_EVENT_URL);
@@ -200,7 +199,7 @@ static INT_PTR DbEventGetIcon(WPARAM wParam, LPARAM lParam)
static INT_PTR DbEventGetStringT(WPARAM wParam, LPARAM lParam)
{
DBEVENTINFO* dbei = (DBEVENTINFO*)wParam;
- char* string = (char*)lParam;
+ char *string = (char*)lParam;
if (dbei->flags & DBEF_UTF)
return (INT_PTR)Utf8DecodeW(string);
@@ -210,7 +209,7 @@ static INT_PTR DbEventGetStringT(WPARAM wParam, LPARAM lParam)
/////////////////////////////////////////////////////////////////////////////////////////
-static int sttEnumVars(const char* szVarName, LPARAM lParam)
+static int sttEnumVars(const char *szVarName, LPARAM lParam)
{
LIST<char>* vars = (LIST<char>*)lParam;
vars->insert(mir_strdup(szVarName));
@@ -240,17 +239,9 @@ static INT_PTR GetProfilePath(WPARAM wParam, LPARAM lParam)
if ( !wParam || !lParam)
return 1;
- char* dst = (char*)lParam;
-
- char* tmp = mir_t2a(g_profileDir);
- strncpy(dst, tmp, wParam);
- mir_free(tmp);
-
- if (wParam <= _tcslen(g_profileName))
- {
- dst[wParam - 1] = 0;
- return 1;
- }
+ char *dst = (char*)lParam;
+ strncpy(dst, _T2A(g_profileDir), wParam);
+ dst[wParam-1] = 0;
return 0;
}
@@ -259,17 +250,13 @@ static INT_PTR GetProfileName(WPARAM wParam, LPARAM lParam)
if ( !wParam || !lParam)
return 1;
- char* dst = (char*)lParam;
+ char *dst = (char*)lParam;
- char* tmp = makeFileName(g_profileName);
+ char *tmp = makeFileName(g_profileName);
strncpy(dst, tmp, wParam);
mir_free(tmp);
- if (wParam <= _tcslen(g_profileName))
- {
- dst[wParam - 1] = 0;
- return 1;
- }
+ dst[wParam-1] = 0;
return 0;
}
@@ -278,25 +265,17 @@ static INT_PTR GetProfilePathW(WPARAM wParam, LPARAM lParam)
if ( !wParam || !lParam)
return 1;
- wchar_t* dst = (wchar_t*)lParam;
+ wchar_t *dst = (wchar_t*)lParam;
wcsncpy(dst, g_profileDir, wParam);
- if (wParam <= wcslen(g_profileDir))
- {
- dst[wParam - 1] = 0;
- return 1;
- }
+ dst[wParam-1] = 0;
return 0;
}
static INT_PTR GetProfileNameW(WPARAM wParam, LPARAM lParam)
{
- wchar_t* dst = (wchar_t*)lParam;
+ wchar_t *dst = (wchar_t*)lParam;
wcsncpy(dst, g_profileName, wParam);
- if (wParam <= wcslen(g_profileName))
- {
- dst[wParam - 1] = 0;
- return 1;
- }
+ dst[wParam-1] = 0;
return 0;
}
diff --git a/src/modules/database/mdatabasecache.cpp b/src/modules/database/mdatabasecache.cpp
index abb24dd0fe..04edbc66c2 100644
--- a/src/modules/database/mdatabasecache.cpp
+++ b/src/modules/database/mdatabasecache.cpp
@@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "database.h"
static int stringCompare(const char* p1, const char* p2)
-{ return strcmp(p1+1, p2+1);
+{ return strcmp(p1, p2);
}
static int compareGlobals(const DBCachedGlobalValue* p1, const DBCachedGlobalValue* p2)
@@ -90,8 +90,8 @@ void MDatabaseCache::FreeCachedContact(HANDLE hContact)
char* MDatabaseCache::InsertCachedSetting(const char* szName, int cbLen)
{
char* newValue = (char*)HeapAlloc(m_hCacheHeap, 0, cbLen);
- *newValue = 0;
- strcpy(newValue+1, szName+1);
+ *newValue++ = 0;
+ strcpy(newValue, szName);
m_lSettings.insert(newValue);
return newValue;
}
@@ -99,18 +99,23 @@ char* MDatabaseCache::InsertCachedSetting(const char* szName, int cbLen)
char* MDatabaseCache::GetCachedSetting(const char *szModuleName,const char *szSettingName, int moduleNameLen, int settingNameLen)
{
char szFullName[512];
- strcpy(szFullName+1,szModuleName);
- szFullName[moduleNameLen+1] = '/';
- strcpy(szFullName+moduleNameLen+2,szSettingName);
+ const char *szKey;
+ if (szModuleName != NULL) {
+ strcpy(szFullName, szModuleName);
+ szFullName[moduleNameLen] = '/';
+ strcpy(szFullName+moduleNameLen+1,szSettingName);
+ szKey = szFullName;
+ }
+ else szKey = szSettingName;
- if (m_lastSetting && strcmp(szFullName+1, m_lastSetting) == 0)
+ if (m_lastSetting && !strcmp(szKey, m_lastSetting))
return m_lastSetting;
- int index = m_lSettings.getIndex(szFullName);
+ int index = m_lSettings.getIndex((char*)szKey);
if (index != -1)
- m_lastSetting = m_lSettings[index]+1;
+ m_lastSetting = m_lSettings[index];
else
- m_lastSetting = InsertCachedSetting( szFullName, settingNameLen+moduleNameLen+3)+1;
+ m_lastSetting = InsertCachedSetting(szKey, settingNameLen+moduleNameLen+3);
return m_lastSetting;
}
diff --git a/src/modules/protocols/protochains.cpp b/src/modules/protocols/protochains.cpp
index 4fe8820e18..977ba9090c 100644
--- a/src/modules/protocols/protochains.cpp
+++ b/src/modules/protocols/protochains.cpp
@@ -28,6 +28,18 @@ extern LIST<PROTOCOLDESCRIPTOR> filters;
static int GetProtocolP(HANDLE hContact, char *szBuf, int cbLen)
{
+ if (currDb == NULL)
+ return 1;
+
+ DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact);
+ if (cc == NULL)
+ cc = currDb->m_cache->AddContactToCache(hContact);
+ if (cc->szProto != NULL) {
+ strncpy(szBuf, cc->szProto, cbLen);
+ szBuf[cbLen-1] = 0;
+ return 0;
+ }
+
DBVARIANT dbv;
dbv.type = DBVT_ASCIIZ;
dbv.pszVal = szBuf;
@@ -37,7 +49,11 @@ static int GetProtocolP(HANDLE hContact, char *szBuf, int cbLen)
dbcgs.pValue = &dbv;
dbcgs.szModule = "Protocol";
dbcgs.szSetting = "p";
- return (int)CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&dbcgs);
+
+ int res = currDb->GetContactSettingStatic(hContact, &dbcgs);
+ if (res == 0 && !cc->szProto)
+ cc->szProto = currDb->m_cache->GetCachedSetting(NULL, szBuf, 0, strlen(szBuf));
+ return res;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -154,9 +170,12 @@ static INT_PTR Proto_ChainRecv(WPARAM wParam, LPARAM lParam)
PROTOACCOUNT* __fastcall Proto_GetAccount(HANDLE hContact)
{
+ if (hContact == NULL)
+ return NULL;
+
char szProto[40];
if ( GetProtocolP(hContact, szProto, sizeof(szProto)))
- return 0;
+ return NULL;
return Proto_GetAccount(szProto);
}