summaryrefslogtreecommitdiff
path: root/plugins/TipperYM/src
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2015-03-31 20:38:31 +0000
committerTobias Weimer <wishmaster51@googlemail.com>2015-03-31 20:38:31 +0000
commitff035d5933b88c564fdbf8ef5f899b6fa3ac63bb (patch)
treeb7624e680b476c2115ce09fb6b799792252a6534 /plugins/TipperYM/src
parentc213884746cb362887c9e01058dbc636ed222add (diff)
Tipper YM:
-Minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@12578 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TipperYM/src')
-rw-r--r--plugins/TipperYM/src/message_pump.cpp30
-rw-r--r--plugins/TipperYM/src/options.cpp58
-rw-r--r--plugins/TipperYM/src/popwin.cpp4
-rw-r--r--plugins/TipperYM/src/subst.cpp28
-rw-r--r--plugins/TipperYM/src/subst.h4
5 files changed, 51 insertions, 73 deletions
diff --git a/plugins/TipperYM/src/message_pump.cpp b/plugins/TipperYM/src/message_pump.cpp
index 6a17dd0aba..fcb719d6f8 100644
--- a/plugins/TipperYM/src/message_pump.cpp
+++ b/plugins/TipperYM/src/message_pump.cpp
@@ -31,7 +31,7 @@ bool bStatusMsgReady = false;
__inline bool IsContactTooltip(CLCINFOTIPEX *clc)
{
- return (clc->szProto || clc->swzText) == false;
+ return !(clc->szProto || clc->swzText);
}
void CALLBACK TimerProcWaitForContent(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
@@ -46,17 +46,16 @@ void CALLBACK TimerProcWaitForContent(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DW
bool NeedWaitForContent(CLCINFOTIPEX *clcitex)
{
bool bNeedWait = false;
-
if (opt.bWaitForContent && IsContactTooltip(clcitex))
{
- char *szProto = GetContactProto((MCONTACT)clcitex->hItem);
+ MCONTACT hContact = (MCONTACT) clcitex->hItem;
+ char *szProto = GetContactProto(hContact);
if (!szProto) return false;
if (opt.bWaitForStatusMsg && !bStatusMsgReady)
{
- db_unset((MCONTACT)clcitex->hItem, MODULE, "TempStatusMsg");
- if (CanRetrieveStatusMsg((MCONTACT)clcitex->hItem, szProto) &&
- CallContactService((MCONTACT)clcitex->hItem, PSS_GETAWAYMSG, 0, 0))
+ db_unset(hContact, MODULE, "TempStatusMsg");
+ if (CanRetrieveStatusMsg(hContact, szProto) && CallContactService(hContact, PSS_GETAWAYMSG, 0, 0))
{
if (WaitForContentTimerID)
KillTimer(0, WaitForContentTimerID);
@@ -70,11 +69,11 @@ bool NeedWaitForContent(CLCINFOTIPEX *clcitex)
CallProtoService(szProto, PS_GETAVATARCAPS, AF_ENABLED, 0))
{
DBVARIANT dbv;
- if (!db_get_s((MCONTACT)clcitex->hItem, "ContactPhoto", "File", &dbv))
+ if (!db_get_s(hContact, "ContactPhoto", "File", &dbv))
{
if (!strstr(dbv.pszVal, ".xml"))
{
- AVATARCACHEENTRY *ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)clcitex->hItem, 0);
+ AVATARCACHEENTRY *ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)hContact, 0);
if (!ace)
{
if (WaitForContentTimerID)
@@ -151,7 +150,7 @@ unsigned int CALLBACK MessagePumpThread(void *param)
MCONTACT hContact = (MCONTACT)hwndMsg.wParam;
TCHAR *swzMsg = (TCHAR *)hwndMsg.lParam;
- if (opt.bWaitForContent && bStatusMsgReady == false && clcitex && clcitex->hItem == (HANDLE)hContact) {
+ if (opt.bWaitForContent && !bStatusMsgReady && clcitex && clcitex->hItem == (HANDLE)hContact) {
if (WaitForContentTimerID) {
KillTimer(0, WaitForContentTimerID);
WaitForContentTimerID = 0;
@@ -178,7 +177,7 @@ unsigned int CALLBACK MessagePumpThread(void *param)
case MUM_GOTAVATAR:
{
MCONTACT hContact = (MCONTACT)hwndMsg.wParam;
- if (opt.bWaitForContent && bAvatarReady == false && clcitex && clcitex->hItem == (HANDLE)hContact) {
+ if (opt.bWaitForContent && !bAvatarReady && clcitex && clcitex->hItem == (HANDLE)hContact) {
if (WaitForContentTimerID) {
KillTimer(0, WaitForContentTimerID);
WaitForContentTimerID = 0;
@@ -237,7 +236,7 @@ INT_PTR ShowTip(WPARAM wParam, LPARAM lParam)
HWND clist = (HWND)CallService(MS_CLUI_GETHWNDTREE, 0, 0);
if (clcit->isGroup) return 0; // no group tips (since they're pretty useless)
- if (clcit->isTreeFocused == 0 && opt.bShowNoFocus == false && clist == WindowFromPoint(clcit->ptCursor)) return 0;
+ if (clcit->isTreeFocused == 0 && !opt.bShowNoFocus && clist == WindowFromPoint(clcit->ptCursor)) return 0;
if (clcit->ptCursor.x == pt.x && clcit->ptCursor.y == pt.y) return 0;
pt.x = pt.y = 0;
@@ -269,7 +268,7 @@ INT_PTR ShowTipW(WPARAM wParam, LPARAM lParam)
HWND clist = (HWND)CallService(MS_CLUI_GETHWNDTREE, 0, 0);
if (clcit->isGroup) return 0; // no group tips (since they're pretty useless)
- if (clcit->isTreeFocused == 0 && opt.bShowNoFocus == false && clist == WindowFromPoint(clcit->ptCursor)) return 0;
+ if (clcit->isTreeFocused == 0 && !opt.bShowNoFocus && clist == WindowFromPoint(clcit->ptCursor)) return 0;
if (clcit->ptCursor.x == pt.x && clcit->ptCursor.y == pt.y) return 0;
pt.x = pt.y = -1;
@@ -289,9 +288,8 @@ INT_PTR ShowTipW(WPARAM wParam, LPARAM lParam)
return 1;
}
-INT_PTR HideTip(WPARAM wParam, LPARAM lParam)
+INT_PTR HideTip(WPARAM, LPARAM)
{
- //CLCINFOTIP *clcit = (CLCINFOTIP *)lParam;
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
return 0;
@@ -309,7 +307,7 @@ int HideTipHook(WPARAM wParam, LPARAM lParam)
int ProtoAck(WPARAM wParam, LPARAM lParam)
{
ACKDATA *ack = (ACKDATA*)lParam;
- if (ack->result != ACKRESULT_SUCCESS)
+ if ((ack==NULL) || (ack->result != ACKRESULT_SUCCESS))
return 0;
if (ack->type == ACKTYPE_AWAYMSG) {
@@ -347,7 +345,7 @@ int FramesShowSBTip(WPARAM wParam, LPARAM lParam)
return 0;
}
-int FramesHideSBTip(WPARAM wParam, LPARAM lParam)
+int FramesHideSBTip(WPARAM, LPARAM)
{
if (opt.bStatusBarTips)
{
diff --git a/plugins/TipperYM/src/options.cpp b/plugins/TipperYM/src/options.cpp
index f65d2fdf5a..ed108c4ca4 100644
--- a/plugins/TipperYM/src/options.cpp
+++ b/plugins/TipperYM/src/options.cpp
@@ -47,14 +47,11 @@ extern int IsTrayProto(const TCHAR *swzProto, BOOL bExtendedTip)
void CreateDefaultItems()
{
- DSListNode *ds_node;
- DIListNode *di_node;
-
for (int i = 0; defaultItemList[i].szName; i++)
{
if (defaultItemList[i].szName[0] == '-')
{
- di_node = (DIListNode *)mir_alloc(sizeof(DIListNode));
+ DIListNode *di_node = (DIListNode *)mir_alloc(sizeof(DIListNode));
_tcsncpy(di_node->di.swzLabel, _T(""), LABEL_LEN);
_tcsncpy(di_node->di.swzValue, _T(""), VALUE_LEN);
di_node->di.bLineAbove = true;
@@ -74,7 +71,7 @@ void CreateDefaultItems()
PRESETSUBST *subst = GetPresetSubstByName(item->szNeededSubst[j]);
if (subst == NULL) continue;
- ds_node = (DSListNode *)mir_alloc(sizeof(DSListNode));
+ DSListNode *ds_node = (DSListNode *)mir_alloc(sizeof(DSListNode));
_tcsncpy(ds_node->ds.swzName, subst->swzName, LABEL_LEN);
ds_node->ds.type = subst->type;
strncpy(ds_node->ds.szSettingName, subst->szSettingName, SETTING_NAME_LEN);
@@ -84,7 +81,7 @@ void CreateDefaultItems()
opt.iDsCount++;
}
- di_node = (DIListNode *)mir_alloc(sizeof(DIListNode));
+ DIListNode *di_node = (DIListNode *)mir_alloc(sizeof(DIListNode));
_tcsncpy(di_node->di.swzLabel, TranslateTS(item->swzLabel), LABEL_LEN);
_tcsncpy(di_node->di.swzValue, item->swzValue, VALUE_LEN);
di_node->di.bLineAbove = false;
@@ -105,15 +102,13 @@ bool LoadDS(DISPLAYSUBST *ds, int index)
mir_snprintf(setting, SIZEOF(setting), "Name%d", index);
ds->swzName[0] = 0;
- if (!db_get_ts(0, MODULE_ITEMS, setting, &dbv))
- {
- _tcsncpy(ds->swzName, dbv.ptszVal, SIZEOF(ds->swzName));
- ds->swzName[SIZEOF(ds->swzName) - 1] = 0;
- db_free(&dbv);
- }
- else
+ if (db_get_ts(0, MODULE_ITEMS, setting, &dbv))
return false;
+ _tcsncpy(ds->swzName, dbv.ptszVal, SIZEOF(ds->swzName));
+ ds->swzName[SIZEOF(ds->swzName) - 1] = 0;
+ db_free(&dbv);
+
mir_snprintf(setting, SIZEOF(setting), "Type%d", index);
ds->type = (DisplaySubstType)db_get_b(0, MODULE_ITEMS, setting, DVT_PROTODB);
@@ -171,14 +166,13 @@ bool LoadDI(DISPLAYITEM *di, int index)
mir_snprintf(setting, SIZEOF(setting), "DILabel%d", index);
di->swzLabel[0] = 0;
- if (!db_get_ts(0, MODULE_ITEMS, setting, &dbv))
- {
- _tcsncpy( di->swzLabel, dbv.ptszVal, SIZEOF(di->swzLabel));
- di->swzLabel[SIZEOF(di->swzLabel) - 1] = 0;
- db_free(&dbv);
- } else
+ if (db_get_ts(0, MODULE_ITEMS, setting, &dbv))
return false;
+ _tcsncpy( di->swzLabel, dbv.ptszVal, SIZEOF(di->swzLabel));
+ di->swzLabel[SIZEOF(di->swzLabel) - 1] = 0;
+ db_free(&dbv);
+
mir_snprintf(setting, SIZEOF(setting), "DIValue%d", index);
di->swzValue[0] = 0;
if (!db_get_ts(0, MODULE_ITEMS, setting, &dbv))
@@ -986,13 +980,13 @@ INT_PTR CALLBACK DlgProcOptsContent(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
memset(ds_value, 0, sizeof(DSListNode));
ds_value->next = NULL;
ds_value->ds.type = subst->type;
- _tcscpy(ds_value->ds.swzName, subst->swzName);
+ _tcsncpy(ds_value->ds.swzName, subst->swzName, LABEL_LEN-1);
if (ds_value->ds.type == DVT_DB && subst->szModuleName)
- strncpy(ds_value->ds.szModuleName, subst->szModuleName, SIZEOF(ds_value->ds.szModuleName) - 1);
+ strncpy(ds_value->ds.szModuleName, subst->szModuleName, MODULE_NAME_LEN-1);
if (subst->szSettingName)
- strncpy(ds_value->ds.szSettingName, subst->szSettingName, SIZEOF(ds_value->ds.szSettingName) - 1);
+ strncpy(ds_value->ds.szSettingName, subst->szSettingName, SETTING_NAME_LEN-1);
ds_value->ds.iTranslateFuncId = subst->iTranslateFuncId;
@@ -1304,27 +1298,24 @@ INT_PTR CALLBACK DlgProcOptsContent(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
}
case WM_DESTROY:
{
- DIListNode *di_value;
TVITEM tvi = {0};
tvi.mask = TVIF_PARAM;
- HTREEITEM hItem = TreeView_GetRoot(GetDlgItem(hwndDlg, IDC_TREE_FIRST_ITEMS));
-
- while (hItem != NULL)
+
+ for (HTREEITEM hItem = TreeView_GetRoot(GetDlgItem(hwndDlg, IDC_TREE_FIRST_ITEMS));hItem != NULL;
+ hItem = TreeView_GetNextSibling(GetDlgItem(hwndDlg, IDC_TREE_FIRST_ITEMS), hItem))
{
tvi.hItem = hItem;
if (TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE_FIRST_ITEMS), &tvi))
{
- di_value = (DIListNode *)tvi.lParam;
+ DIListNode *di_value = (DIListNode *)tvi.lParam;
mir_free(di_value);
}
- hItem = TreeView_GetNextSibling(GetDlgItem(hwndDlg, IDC_TREE_FIRST_ITEMS), hItem);
}
- DSListNode *ds_value;
int count = SendDlgItemMessage(hwndDlg, IDC_LST_SUBST, LB_GETCOUNT, 0, 0);
for (int i = 0; i < count; i++)
{
- ds_value = (DSListNode *)SendDlgItemMessage(hwndDlg, IDC_LST_SUBST, LB_GETITEMDATA, i, 0);
+ DSListNode *ds_value = (DSListNode *)SendDlgItemMessage(hwndDlg, IDC_LST_SUBST, LB_GETITEMDATA, i, 0);
mir_free(ds_value);
}
@@ -1453,12 +1444,7 @@ INT_PTR CALLBACK DlgProcOptsAppearance(HWND hwndDlg, UINT msg, WPARAM wParam, LP
case WM_COMMAND:
{
if (LOWORD(wParam) == IDC_CHK_ORIGINALAVSIZE)
- {
- if (IsDlgButtonChecked(hwndDlg, IDC_CHK_ORIGINALAVSIZE))
- SetDlgItemText(hwndDlg, IDC_STATIC_AVATARSIZE, TranslateT("Max avatar size:"));
- else
- SetDlgItemText(hwndDlg, IDC_STATIC_AVATARSIZE, TranslateT("Avatar size:"));
- }
+ SetDlgItemText(hwndDlg, IDC_STATIC_AVATARSIZE, IsDlgButtonChecked(hwndDlg, IDC_CHK_ORIGINALAVSIZE) ? TranslateT("Max avatar size:") : TranslateT("Avatar size:"));
if (HIWORD(wParam) == CBN_SELCHANGE)
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
diff --git a/plugins/TipperYM/src/popwin.cpp b/plugins/TipperYM/src/popwin.cpp
index 1a6e9d0518..23eccb1026 100644
--- a/plugins/TipperYM/src/popwin.cpp
+++ b/plugins/TipperYM/src/popwin.cpp
@@ -338,9 +338,9 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
if (iXstatus) {
char szIconProto[64];
if (strcmp(szProto, META_PROTO) != 0)
- strcpy(szIconProto, szProto);
+ strncpy(szIconProto, szProto, sizeof(szIconProto) - 1);
else if (!db_get_s(pwd->hContact, szProto, "XStatusProto", &dbv)) {
- strcpy(szIconProto, dbv.pszVal);
+ strncpy(szIconProto, dbv.pszVal, sizeof(szIconProto) - 1);
db_free(&dbv);
}
diff --git a/plugins/TipperYM/src/subst.cpp b/plugins/TipperYM/src/subst.cpp
index b2765a9b3b..623b25f81c 100644
--- a/plugins/TipperYM/src/subst.cpp
+++ b/plugins/TipperYM/src/subst.cpp
@@ -469,31 +469,26 @@ bool GetRawSubstText(MCONTACT hContact, char *szRawSpec, TCHAR *buff, int buffle
return false;
}
-bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsFirst, TCHAR *swzDest, int iDestLen)
+bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsFirst, TCHAR *swzDest, size_t iDestLen)
{
// hack - allow empty strings before passing to variables (note - zero length strings return false after this)
- if (swzDest && swzSource && _tcslen(swzSource) == 0) {
+ if (swzDest && swzSource && (*swzSource == 0)) {
swzDest[0] = 0;
return true;
}
// pass to variables plugin if available
- TCHAR *swzVarSrc;
- if (parseTipperVarsFirst)
- swzVarSrc = mir_tstrdup(swzSource);
- else
- swzVarSrc = variables_parsedup((TCHAR *)swzSource, 0, hContact);
+ TCHAR *swzVarSrc = (parseTipperVarsFirst ? mir_tstrdup(swzSource) : variables_parsedup((TCHAR *)swzSource, 0, hContact));
size_t iSourceLen = _tcslen(swzVarSrc);
size_t si = 0, di = 0, v = 0;
- TCHAR swzVName[LABEL_LEN];
- TCHAR swzRep[VALUE_LEN], swzAlt[VALUE_LEN];
- while (si < iSourceLen && di < (size_t)iDestLen - 1) {
+ TCHAR swzVName[LABEL_LEN], swzRep[VALUE_LEN], swzAlt[VALUE_LEN];
+ while (si < iSourceLen && di < iDestLen - 1) {
if (swzVarSrc[si] == _T('%')) {
si++;
v = 0;
- while (si < iSourceLen && v < LABEL_LEN) {
+ while (si < iSourceLen && v < LABEL_LEN - 1) {
if (swzVarSrc[si] == _T('%'))
break;
@@ -507,8 +502,7 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF
{
swzVName[v] = 0;
- bool bAltSubst = false;
- bool bSubst = false;
+ bool bAltSubst = false, bSubst = false;
// apply only to specific protocols
TCHAR *p = _tcsrchr(swzVName, _T('^')); // use last '^', so if you want a ^ in swzAlt text, you can just put a '^' on the end
@@ -648,8 +642,8 @@ bool ApplySubst(MCONTACT hContact, const TCHAR *swzSource, bool parseTipperVarsF
swzDest[di] = 0;
if (parseTipperVarsFirst) {
- swzVarSrc = variables_parsedup((TCHAR *)swzDest, 0, hContact);
- _tcscpy(swzDest, swzVarSrc);
+ swzVarSrc = variables_parsedup(swzDest, 0, hContact);
+ _tcsncpy(swzDest, swzVarSrc, iDestLen);
mir_free(swzVarSrc);
}
@@ -673,12 +667,12 @@ error:
return true;
}
-bool GetLabelText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, int bufflen)
+bool GetLabelText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, size_t bufflen)
{
return ApplySubst(hContact, di.swzLabel, false, buff, bufflen);
}
-bool GetValueText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, int bufflen)
+bool GetValueText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, size_t bufflen)
{
return ApplySubst(hContact, di.swzValue, di.bParseTipperVarsFirst, buff, bufflen);
}
diff --git a/plugins/TipperYM/src/subst.h b/plugins/TipperYM/src/subst.h
index 53c2d9ab51..66b5712462 100644
--- a/plugins/TipperYM/src/subst.h
+++ b/plugins/TipperYM/src/subst.h
@@ -21,8 +21,8 @@ Boston, MA 02111-1307, USA.
#ifndef _SUBST_INC
#define _SUBST_INC
-bool GetLabelText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, int iBufflen);
-bool GetValueText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, int iBufflen);
+bool GetLabelText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, size_t iBufflen);
+bool GetValueText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, size_t iBufflen);
bool CheckContactType(MCONTACT hContact, const DISPLAYITEM &di);