summaryrefslogtreecommitdiff
path: root/plugins/SeenPlugin/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-07-23 14:35:33 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-07-23 14:35:33 +0300
commit43f46d63825a96165dc5e1fb49a03050aa44f1c1 (patch)
tree88058fd2d432120c88578b0c9ce3b895b066ca9b /plugins/SeenPlugin/src
parent5bcd9e270692e1c3839d9905dbe28d30108fc1a3 (diff)
fixes #2011 (random crash in Seen plugin)
Diffstat (limited to 'plugins/SeenPlugin/src')
-rw-r--r--plugins/SeenPlugin/src/history.cpp10
-rw-r--r--plugins/SeenPlugin/src/menu.cpp10
-rw-r--r--plugins/SeenPlugin/src/stdafx.h2
-rw-r--r--plugins/SeenPlugin/src/userinfo.cpp2
-rw-r--r--plugins/SeenPlugin/src/utils.cpp208
-rw-r--r--plugins/SeenPlugin/src/version.h2
6 files changed, 99 insertions, 135 deletions
diff --git a/plugins/SeenPlugin/src/history.cpp b/plugins/SeenPlugin/src/history.cpp
index 5284183ff8..6b88ee8e4a 100644
--- a/plugins/SeenPlugin/src/history.cpp
+++ b/plugins/SeenPlugin/src/history.cpp
@@ -50,14 +50,8 @@ void HistoryWrite(MCONTACT hContact)
if (historyLast >= historyMax)
historyLast = historyMax - 1;
- wchar_t *ptszString;
- DBVARIANT dbv;
- if (!g_plugin.getWString("HistoryStamp", &dbv)) {
- ptszString = ParseString(dbv.pwszVal, hContact);
- db_free(&dbv);
- }
- else ptszString = ParseString(DEFAULT_HISTORYSTAMP, hContact);
- g_plugin.setWString(hContact, BuildSetting(historyLast), ptszString);
+ ptrW str(g_plugin.getWStringA("HistoryStamp"));
+ g_plugin.setWString(hContact, BuildSetting(historyLast), ParseString(str ? str : DEFAULT_HISTORYSTAMP, hContact));
historyLast = (historyLast + 1) % historyMax;
g_plugin.setWord(hContact, "HistoryLast", historyLast);
diff --git a/plugins/SeenPlugin/src/menu.cpp b/plugins/SeenPlugin/src/menu.cpp
index 1683c303dc..15651965fb 100644
--- a/plugins/SeenPlugin/src/menu.cpp
+++ b/plugins/SeenPlugin/src/menu.cpp
@@ -42,16 +42,12 @@ int BuildContactMenu(WPARAM hContact, LPARAM)
return 0;
}
- LPCTSTR ptszName;
ptrW tszStamp(g_plugin.getWStringA("MenuStamp"));
- if (tszStamp != NULL)
- ptszName = ParseString(tszStamp , hContact);
- else
- ptszName = ParseString(DEFAULT_MENUSTAMP, hContact);
+ CMStringW wszName(ParseString(tszStamp ? tszStamp : DEFAULT_MENUSTAMP, hContact));
int flags = 0;
HANDLE hIcon = nullptr;
- if (!mir_wstrcmp(ptszName, TranslateT("<unknown>"))) {
+ if (wszName == TranslateT("<unknown>")) {
if (IsWatchedProtocol(szProto))
flags |= CMIF_GRAYED;
else
@@ -61,7 +57,7 @@ int BuildContactMenu(WPARAM hContact, LPARAM)
int isetting = g_plugin.getWord(hContact, "StatusTriger", -1);
hIcon = Skin_GetProtoIcon(szProto, isetting | 0x8000);
}
- Menu_ModifyItem(hmenuitem, ptszName, hIcon, flags);
+ Menu_ModifyItem(hmenuitem, wszName, hIcon, flags);
return 0;
}
diff --git a/plugins/SeenPlugin/src/stdafx.h b/plugins/SeenPlugin/src/stdafx.h
index f8f4c338e2..f549c3ef0b 100644
--- a/plugins/SeenPlugin/src/stdafx.h
+++ b/plugins/SeenPlugin/src/stdafx.h
@@ -104,7 +104,7 @@ typedef struct{
} MISSEDCONTACTS;
int IsWatchedProtocol(const char* szProto);
-wchar_t *ParseString(wchar_t*, MCONTACT);
+CMStringW ParseString(const wchar_t *pwszFormat, MCONTACT);
void GetColorsFromDWord(LPCOLORREF First, LPCOLORREF Second, DWORD colDword);
DWORD GetDWordFromColors(COLORREF First, COLORREF Second);
int OptionsInit(WPARAM,LPARAM);
diff --git a/plugins/SeenPlugin/src/userinfo.cpp b/plugins/SeenPlugin/src/userinfo.cpp
index b9691bfa4e..e5991e8e86 100644
--- a/plugins/SeenPlugin/src/userinfo.cpp
+++ b/plugins/SeenPlugin/src/userinfo.cpp
@@ -42,7 +42,7 @@ INT_PTR CALLBACK UserinfoDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lpar
case WM_REFRESH_UI:
{
ptrW szout(g_plugin.getWStringA("UserStamp"));
- wchar_t *str = ParseString((szout != NULL) ? szout : DEFAULT_USERSTAMP, wparam);
+ CMStringW str = ParseString((szout != NULL) ? szout : DEFAULT_USERSTAMP, wparam);
SetDlgItemText(hdlg, IDC_INFOTEXT, str);
if (!mir_wstrcmp(str, TranslateT("<unknown>")))
diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp
index 59e62d1c71..0364a99da1 100644
--- a/plugins/SeenPlugin/src/utils.cpp
+++ b/plugins/SeenPlugin/src/utils.cpp
@@ -155,35 +155,19 @@ wchar_t *wdays_short[] = { LPGENW("Sun."), LPGENW("Mon."), LPGENW("Tue."), LPGEN
wchar_t *monthnames[] = { LPGENW("January"), LPGENW("February"), LPGENW("March"), LPGENW("April"), LPGENW("May"), LPGENW("June"), LPGENW("July"), LPGENW("August"), LPGENW("September"), LPGENW("October"), LPGENW("November"), LPGENW("December") };
wchar_t *mnames_short[] = { LPGENW("Jan."), LPGENW("Feb."), LPGENW("Mar."), LPGENW("Apr."), LPGENW("May"), LPGENW("Jun."), LPGENW("Jul."), LPGENW("Aug."), LPGENW("Sep."), LPGENW("Oct."), LPGENW("Nov."), LPGENW("Dec.") };
-wchar_t* ParseString(wchar_t *szstring, MCONTACT hcontact)
+CMStringW ParseString(const wchar_t *pwszFormat, MCONTACT hcontact)
{
-#define MAXSIZE 1024
- static wchar_t sztemp[MAXSIZE + 1];
- wchar_t szdbsetting[128];
- wchar_t *charPtr;
- int isetting = 0;
- DWORD dwsetting = 0;
- struct in_addr ia;
- DBVARIANT dbv;
-
- sztemp[0] = '\0';
-
SYSTEMTIME st;
- if (!isSeen(hcontact, &st)) {
- mir_wstrcat(sztemp, TranslateT("<never seen>"));
- return sztemp;
- }
+ if (!isSeen(hcontact, &st))
+ return TranslateT("<never seen>");
char *szProto = hcontact ? GetContactProto(hcontact) : courProtoName;
ptrW info;
- wchar_t *d = sztemp;
- for (wchar_t *p = szstring; *p; p++) {
- if (d >= sztemp + MAXSIZE)
- break;
-
+ CMStringW res;
+ for (const wchar_t *p = pwszFormat; *p; p++) {
if (*p != '%' && *p != '#') {
- *d++ = *p;
+ res.AppendChar(*p);
continue;
}
@@ -191,133 +175,129 @@ wchar_t* ParseString(wchar_t *szstring, MCONTACT hcontact)
switch (*++p) {
case 'Y':
if (!st.wYear) goto LBL_noData;
- d += swprintf(d, L"%04i", st.wYear); //!!!!!!!!!!!!
+ res.AppendFormat(L"%04i", st.wYear);
break;
case 'y':
if (!st.wYear) goto LBL_noData;
- d += swprintf(d, L"%02i", st.wYear % 100); //!!!!!!!!!!!!
+ res.AppendFormat(L"%02i", st.wYear % 100);
break;
case 'm':
- if (!(isetting = st.wMonth)) goto LBL_noData;
- LBL_2DigNum:
- d += swprintf(d, L"%02i", isetting); //!!!!!!!!!!!!
+ if (!st.wMonth) goto LBL_noData;
+ res.AppendFormat(L"%02i", st.wMonth);
break;
case 'd':
- if (isetting = st.wDay) goto LBL_2DigNum;
- else goto LBL_noData;
+ if (!st.wDay) goto LBL_noData;
+ res.AppendFormat(L"%02i", st.wDay);
+ break;
case 'W':
- isetting = st.wDayOfWeek;
- if (isetting == -1) {
- LBL_noData:
- charPtr = wantempty ? L"" : TranslateT("<unknown>");
- goto LBL_charPtr;
+ if (st.wDayOfWeek != -1) {
+ res.Append(TranslateW(weekdays[st.wDayOfWeek]));
+ break;
}
- charPtr = TranslateW(weekdays[isetting]);
- LBL_charPtr:
- d += mir_snwprintf(d, MAXSIZE - (d - sztemp), L"%s", charPtr);
- break;
+LBL_noData:
+ res.Append(wantempty ? L"" : TranslateT("<unknown>"));
+ break;
+
case 'w':
- isetting = st.wDayOfWeek;
- if (isetting == -1) goto LBL_noData;
- charPtr = TranslateW(wdays_short[isetting]);
- goto LBL_charPtr;
+ if (st.wDayOfWeek == -1) goto LBL_noData;
+ res.Append(TranslateW(wdays_short[st.wDayOfWeek]));
+ break;
case 'E':
- if (!(isetting = st.wMonth)) goto LBL_noData;
- charPtr = TranslateW(monthnames[isetting - 1]);
- goto LBL_charPtr;
+ if (!st.wMonth) goto LBL_noData;
+ res.Append(TranslateW(monthnames[st.wMonth - 1]));
+ break;
case 'e':
- if (!(isetting = st.wMonth)) goto LBL_noData;
- charPtr = TranslateW(mnames_short[isetting - 1]);
- goto LBL_charPtr;
+ if (!st.wMonth) goto LBL_noData;
+ res.Append(TranslateW(mnames_short[st.wMonth - 1]));
+ break;
case 'H':
- if ((isetting = st.wHour) == -1) goto LBL_noData;
- goto LBL_2DigNum;
+ if (st.wHour == -1) goto LBL_noData;
+ res.AppendFormat(L"%02i", st.wHour);
+ break;
case 'h':
- if ((isetting = st.wHour) == -1) goto LBL_noData;
- if (!isetting) isetting = 12;
- isetting = isetting - ((isetting > 12) ? 12 : 0);
- goto LBL_2DigNum;
+ if (st.wHour == -1) goto LBL_noData;
+ if (!st.wHour) st.wHour = 12;
+ st.wHour = st.wHour - ((st.wHour > 12) ? 12 : 0);
+ res.AppendFormat(L"%02i", st.wHour);
+ break;
case 'p':
- if ((isetting = st.wHour) == -1) goto LBL_noData;
- charPtr = (isetting >= 12) ? L"PM" : L"AM";
- goto LBL_charPtr;
+ if (st.wHour == -1) goto LBL_noData;
+ res.Append((st.wHour >= 12) ? L"PM" : L"AM");
+ break;
case 'M':
- if ((isetting = st.wMinute) == -1) goto LBL_noData;
- goto LBL_2DigNum;
+ if (st.wMinute == -1) goto LBL_noData;
+ res.AppendFormat(L"%02i", st.wMinute);
+ break;
case 'S':
- if ((isetting = st.wHour) == -1) goto LBL_noData;
- goto LBL_2DigNum;
+ if (st.wSecond == -1) goto LBL_noData;
+ res.AppendFormat(L"%02i", st.wSecond);
+ break;
case 'n':
- charPtr = hcontact ? Clist_GetContactDisplayName(hcontact) : (wantempty ? L"" : L"---");
- goto LBL_charPtr;
+ res.Append(hcontact ? Clist_GetContactDisplayName(hcontact) : (wantempty ? L"" : L"---"));
+ break;
case 'N':
if (info = Contact_GetInfo(CNF_NICK, hcontact, szProto)) {
- charPtr = info;
- goto LBL_charPtr;
+ res.Append(info);
+ break;
}
goto LBL_noData;
case 'G':
{
ptrW wszGroup(Clist_GetGroup(hcontact));
- if (wszGroup) {
- wcsncpy_s(szdbsetting, wszGroup, _TRUNCATE);
- charPtr = szdbsetting;
- goto LBL_charPtr;
- }
+ if (wszGroup)
+ res.Append(wszGroup);
}
break;
case 'u':
if (info = Contact_GetInfo(CNF_UNIQUEID, hcontact, szProto)) {
- charPtr = info;
- goto LBL_charPtr;
+ res.Append(info);
+ break;
}
goto LBL_noData;
case 's':
- if (isetting = g_plugin.getWord(hcontact, hcontact ? "StatusTriger" : courProtoName, 0)) {
- wcsncpy(szdbsetting, Clist_GetStatusModeDescription(isetting | 0x8000, 0), _countof(szdbsetting));
- if (!(isetting & 0x8000)) {
- mir_wstrncat(szdbsetting, L"/", _countof(szdbsetting) - mir_wstrlen(szdbsetting));
- mir_wstrncat(szdbsetting, TranslateT("Idle"), _countof(szdbsetting) - mir_wstrlen(szdbsetting));
+ if (int iStatus = g_plugin.getWord(hcontact, hcontact ? "StatusTriger" : courProtoName, 0)) {
+ res.Append(Clist_GetStatusModeDescription(iStatus | 0x8000, 0));
+ if (!(iStatus & 0x8000)) {
+ res.AppendChar('/');
+ res.Append(TranslateT("Idle"));
}
- charPtr = szdbsetting;
- goto LBL_charPtr;
+ break;
}
goto LBL_noData;
case 'T':
- if (db_get_ws(hcontact, "CList", "StatusMsg", &dbv))
- goto LBL_noData;
+ if (info = db_get_wsa(hcontact, "CList", "StatusMsg")) {
+ res.Append(info);
+ break;
+ }
- d += mir_snwprintf(d, MAXSIZE - (d - sztemp), L"%s", dbv.pwszVal);
- db_free(&dbv);
- break;
+ goto LBL_noData;
case 'o':
- if (isetting = g_plugin.getWord(hcontact, hcontact ? "OldStatus" : courProtoName, 0)) {
- wcsncpy(szdbsetting, Clist_GetStatusModeDescription(isetting, 0), _countof(szdbsetting));
+ if (int iStatus = g_plugin.getWord(hcontact, hcontact ? "OldStatus" : courProtoName, 0)) {
+ res.Append(Clist_GetStatusModeDescription(iStatus, 0));
if (includeIdle && hcontact && g_plugin.getByte(hcontact, "OldIdle")) {
- mir_wstrncat(szdbsetting, L"/", _countof(szdbsetting) - mir_wstrlen(szdbsetting));
- mir_wstrncat(szdbsetting, TranslateT("Idle"), _countof(szdbsetting) - mir_wstrlen(szdbsetting));
+ res.Append(L"/");
+ res.Append(TranslateT("Idle"));
}
- charPtr = szdbsetting;
- goto LBL_charPtr;
+ break;
}
goto LBL_noData;
@@ -325,61 +305,55 @@ wchar_t* ParseString(wchar_t *szstring, MCONTACT hcontact)
case 'r':
if (isJabber(szProto)) {
if (info = db_get_wsa(hcontact, szProto, *p == 'i' ? "Resource" : "System")) {
- charPtr = info;
- goto LBL_charPtr;
+ res.Append(info);
+ break;
}
goto LBL_noData;
}
else {
- dwsetting = db_get_dw(hcontact, szProto, *p == 'i' ? "IP" : "RealIP", 0);
+ int dwsetting = db_get_dw(hcontact, szProto, *p == 'i' ? "IP" : "RealIP", 0);
if (!dwsetting)
goto LBL_noData;
+ struct in_addr ia;
ia.S_un.S_addr = htonl(dwsetting);
- wcsncpy(szdbsetting, _A2T(inet_ntoa(ia)), _countof(szdbsetting));
- charPtr = szdbsetting;
+ res.Append(_A2T(inet_ntoa(ia)));
}
- goto LBL_charPtr;
+ break;
case 'P':
- wcsncpy(szdbsetting, szProto ? _A2T(szProto) : (wantempty ? L"" : L"ProtoUnknown"), _countof(szdbsetting));
- charPtr = szdbsetting;
- goto LBL_charPtr;
+ res.Append(szProto ? _A2T(szProto) : (wantempty ? L"" : L"ProtoUnknown"));
+ break;
case 'b':
- charPtr = L"\x0D\x0A";
- goto LBL_charPtr;
+ res.Append(L"\x0D\x0A");
+ break;
case 'C': // Get Client Info
if (info = db_get_wsa(hcontact, szProto, "MirVer")) {
- charPtr = info;
- goto LBL_charPtr;
+ res.Append(info);
+ break;
}
goto LBL_noData;
case 't':
- charPtr = L"\t";
- goto LBL_charPtr;
+ res.Append(L"\t");
+ break;
case 'A':
- {
- PROTOACCOUNT *pa = Proto_GetAccount(szProto);
- if (!pa)
- goto LBL_noData;
-
- wcsncpy(szdbsetting, pa->tszAccountName, _countof(szdbsetting));
- charPtr = szdbsetting;
+ if (PROTOACCOUNT *pa = Proto_GetAccount(szProto)) {
+ res.Append(pa->tszAccountName);
+ break;
}
- goto LBL_charPtr;
+ goto LBL_noData;
default:
- *d++ = p[-1];
- *d++ = *p;
+ res.AppendChar(p[-1]);
+ res.AppendChar(*p);
}
}
- *d = 0;
- return sztemp;
+ return res;
}
void DBWriteTimeTS(DWORD t, MCONTACT hcontact)
diff --git a/plugins/SeenPlugin/src/version.h b/plugins/SeenPlugin/src/version.h
index 7f5b5c5074..4cad78a115 100644
--- a/plugins/SeenPlugin/src/version.h
+++ b/plugins/SeenPlugin/src/version.h
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define __MAJOR_VERSION 5
#define __MINOR_VERSION 0
#define __RELEASE_NUM 5
-#define __BUILD_NUM 4
+#define __BUILD_NUM 5
#include <stdver.h>