summaryrefslogtreecommitdiff
path: root/protocols/Weather/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2025-04-03 13:55:34 +0300
committerGeorge Hazan <george.hazan@gmail.com>2025-04-03 13:55:34 +0300
commitf46c2504821b4c5cb03d04a2ac6cf02ddec7ce99 (patch)
treee54a26ea02a0149226032131aa7e07d91a6e18a3 /protocols/Weather/src
parent3ee53558d61ce75746f28c4a36255241895a98cb (diff)
static buffers are evil
Diffstat (limited to 'protocols/Weather/src')
-rw-r--r--protocols/Weather/src/stdafx.h2
-rw-r--r--protocols/Weather/src/weather_conv.cpp59
-rw-r--r--protocols/Weather/src/weather_opt.cpp47
-rw-r--r--protocols/Weather/src/weather_popup.cpp4
-rw-r--r--protocols/Weather/src/weather_update.cpp24
-rw-r--r--protocols/Weather/src/weather_userinfo.cpp20
6 files changed, 69 insertions, 87 deletions
diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h
index eec03bd13e..cf1f3240a3 100644
--- a/protocols/Weather/src/stdafx.h
+++ b/protocols/Weather/src/stdafx.h
@@ -146,7 +146,7 @@ void TrimString(wchar_t *str);
void ConvertBackslashes(char *str);
char *GetSearchStr(char *dis);
-wchar_t *GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t* str);
+CMStringW GetDisplay(WEATHERINFO *w, const wchar_t *dis);
wchar_t *GetError(int code);
diff --git a/protocols/Weather/src/weather_conv.cpp b/protocols/Weather/src/weather_conv.cpp
index d9f35264b0..4d2c79f0ce 100644
--- a/protocols/Weather/src/weather_conv.cpp
+++ b/protocols/Weather/src/weather_conv.cpp
@@ -399,7 +399,7 @@ char* GetSearchStr(char *dis)
// dis = the string to parse
// return value = the parsed string
-wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str)
+CMStringW GetDisplay(WEATHERINFO *w, const wchar_t *dis)
{
wchar_t lpzDate[32], chr;
char name[256], temp[2];
@@ -407,7 +407,7 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str)
size_t i;
// Clear the string
- str[0] = 0;
+ CMStringW str;
// looking character by character
for (i = 0; i < mir_wstrlen(dis); i++) {
@@ -416,10 +416,10 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str)
i++;
chr = dis[i];
switch (chr) {
- case '%': mir_wstrcat(str, L"%"); break;
- case 't': mir_wstrcat(str, L"\t"); break;
- case 'n': mir_wstrcat(str, L"\r\n"); break;
- case '\\': mir_wstrcat(str, L"\\"); break;
+ case '%': str.Append(L"%"); break;
+ case 't': str.Append(L"\t"); break;
+ case 'n': str.Append(L"\r\n"); break;
+ case '\\': str.Append(L"\\"); break;
}
}
@@ -430,29 +430,31 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str)
// turn capitalized characters to small case
if (chr < 'a' && chr != '[' && chr != '%') chr = (char)((int)chr + 32);
switch (chr) {
- case 'c': mir_wstrcat(str, w->cond); break;
+ case 'c': str.Append(w->cond); break;
case 'd': // get the current date
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, nullptr, nullptr, lpzDate, _countof(lpzDate));
- mir_wstrcat(str, lpzDate); break;
- case 'e': mir_wstrcat(str, w->dewpoint); break;
- case 'f': mir_wstrcat(str, w->feel); break;
- case 'h': mir_wstrcat(str, w->high); break;
- case 'i': mir_wstrcat(str, w->winddir); break;
- case 'l': mir_wstrcat(str, w->low); break;
- case 'm': mir_wstrcat(str, w->humid); break;
- case 'n': mir_wstrcat(str, w->city); break;
- case 'p': mir_wstrcat(str, w->pressure); break;
- case 'r': mir_wstrcat(str, w->sunrise); break;
- case 's': mir_wstrcat(str, w->id); break;
- case 't': mir_wstrcat(str, w->temp); break;
+ str.Append(lpzDate); break;
+ case 'e': str.Append(w->dewpoint); break;
+ case 'f': str.Append(w->feel); break;
+ case 'h': str.Append(w->high); break;
+ case 'i': str.Append(w->winddir); break;
+ case 'l': str.Append(w->low); break;
+ case 'm': str.Append(w->humid); break;
+ case 'n': str.Append(w->city); break;
+ case 'p': str.Append(w->pressure); break;
+ case 'r': str.Append(w->sunrise); break;
+ case 's': str.Append(w->id); break;
+ case 't': str.Append(w->temp); break;
case 'u':
- if (mir_wstrcmp(w->update, NODATA)) mir_wstrcat(str, w->update);
- else mir_wstrcat(str, TranslateT("<unknown time>"));
+ if (mir_wstrcmp(w->update, NODATA))
+ str.Append(w->update);
+ else
+ str.Append(TranslateT("<unknown time>"));
break;
- case 'v': mir_wstrcat(str, w->vis); break;
- case 'w': mir_wstrcat(str, w->wind); break;
- case 'y': mir_wstrcat(str, w->sunset); break;
- case '%': mir_wstrcat(str, L"%"); break;
+ case 'v': str.Append(w->vis); break;
+ case 'w': str.Append(w->wind); break;
+ case 'y': str.Append(w->sunset); break;
+ case '%': str.Append(L"%"); break;
case '[': // custom variables
i++;
name[0] = 0;
@@ -464,17 +466,14 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str)
// access the database to get its value
if (!db_get_ws(w->hContact, WEATHERCONDITION, name, &dbv)) {
if (dbv.pwszVal != TranslateW(NODATA) && dbv.pwszVal != TranslateT("<Error>"))
- mir_wstrcat(str, dbv.pwszVal);
+ str.Append(dbv.pwszVal);
db_free(&dbv);
}
break;
}
}
// if the character is not a variable, write the original character to the new string
- else {
- mir_snwprintf(lpzDate, L"%c", dis[i]);
- mir_wstrcat(str, lpzDate);
- }
+ else str.AppendChar(dis[i]);
}
return str;
diff --git a/protocols/Weather/src/weather_opt.cpp b/protocols/Weather/src/weather_opt.cpp
index a0b42e21be..015fda2c6c 100644
--- a/protocols/Weather/src/weather_opt.cpp
+++ b/protocols/Weather/src/weather_opt.cpp
@@ -367,8 +367,8 @@ public:
bool OnApply() override
{
// save the option
- wchar_t textstr[MAX_TEXT_SIZE];
for (auto &it : controls) {
+ wchar_t textstr[MAX_TEXT_SIZE];
GetDlgItemText(m_hwnd, it.id, textstr, _countof(textstr));
if (!mir_wstrcmpi(textstr, GetDefaultText(it.c)))
m_proto->delSetting(it.setting);
@@ -384,42 +384,41 @@ public:
void onClick_TM(CCtrlButton *pButton)
{
// display the menu
- RECT pos;
- GetWindowRect(pButton->GetHwnd(), &pos);
HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_TMMENU));
HMENU hMenu1 = GetSubMenu(hMenu, 0);
TranslateMenu(hMenu1);
- {
- auto &var = controls[pButton->GetCtrlId() - IDC_TM1];
-
- switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, m_hwnd, nullptr)) {
- case ID_MPREVIEW:
- {
- // show the preview in a message box, using the weather data from the default station
- WEATHERINFO winfo = m_proto->LoadWeatherInfo(m_proto->opt.DefStn);
- wchar_t buf[MAX_TEXT_SIZE], str[4096];
- GetDlgItemTextW(m_hwnd, var.id, buf, _countof(buf));
- GetDisplay(&winfo, buf, str);
- MessageBox(nullptr, str, TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST);
- }
- break;
-
- case ID_MRESET:
- SetDlgItemTextW(m_hwnd, var.id, GetDefaultText(var.c));
- break;
+
+ auto &var = controls[pButton->GetCtrlId() - IDC_TM1];
+
+ RECT pos;
+ GetWindowRect(pButton->GetHwnd(), &pos);
+ switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, m_hwnd, nullptr)) {
+ case ID_MPREVIEW:
+ {
+ // show the preview in a message box, using the weather data from the default station
+ WEATHERINFO winfo = m_proto->LoadWeatherInfo(m_proto->opt.DefStn);
+ wchar_t buf[MAX_TEXT_SIZE];
+ GetDlgItemTextW(m_hwnd, var.id, buf, _countof(buf));
+ MessageBox(nullptr, GetDisplay(&winfo, buf), TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST);
}
- DestroyMenu(hMenu);
+ break;
+
+ case ID_MRESET:
+ SetDlgItemTextW(m_hwnd, var.id, GetDefaultText(var.c));
+ break;
}
+ DestroyMenu(hMenu);
}
void onClick_Reset(CCtrlButton *)
{
// left click action selection menu
- RECT pos;
- GetWindowRect(btnReset.GetHwnd(), &pos);
HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_TMENU));
HMENU hMenu1 = GetSubMenu(hMenu, 0);
TranslateMenu(hMenu1);
+
+ RECT pos;
+ GetWindowRect(btnReset.GetHwnd(), &pos);
switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, m_hwnd, nullptr)) {
case ID_T1:
// reset to the strings in memory, discard all changes
diff --git a/protocols/Weather/src/weather_popup.cpp b/protocols/Weather/src/weather_popup.cpp
index 91dcf51cb9..b9f938e41d 100644
--- a/protocols/Weather/src/weather_popup.cpp
+++ b/protocols/Weather/src/weather_popup.cpp
@@ -120,8 +120,8 @@ int CWeatherProto::WeatherPopup(MCONTACT hContact, bool bAlways)
POPUPDATAW ppd;
ppd.lchContact = hContact;
ppd.PluginData = ppd.lchIcon = GetStatusIcon(winfo.hContact);
- GetDisplay(&winfo, GetTextValue('P'), ppd.lpwzContactName);
- GetDisplay(&winfo, GetTextValue('p'), ppd.lpwzText);
+ wcsncpy_s(ppd.lpwzContactName, GetDisplay(&winfo, GetTextValue('P')), _TRUNCATE);
+ wcsncpy_s(ppd.lpwzText, GetDisplay(&winfo, GetTextValue('p')), _TRUNCATE);
ppd.PluginWindowProc = PopupDlgProc;
ppd.colorBack = (opt.UseWinColors) ? GetSysColor(COLOR_BTNFACE) : opt.BGColour;
ppd.colorText = (opt.UseWinColors) ? GetSysColor(COLOR_WINDOWTEXT) : opt.TextColour;
diff --git a/protocols/Weather/src/weather_update.cpp b/protocols/Weather/src/weather_update.cpp
index 58a785add5..3f189274e5 100644
--- a/protocols/Weather/src/weather_update.cpp
+++ b/protocols/Weather/src/weather_update.cpp
@@ -32,7 +32,6 @@ menu items).
int CWeatherProto::UpdateWeather(MCONTACT hContact)
{
- wchar_t str2[MAX_TEXT_SIZE];
DBVARIANT dbv;
BOOL Ch = FALSE;
@@ -128,22 +127,18 @@ int CWeatherProto::UpdateWeather(MCONTACT hContact)
setWord(hContact, "Status", iStatus);
AvatarDownloaded(hContact);
- GetDisplay(&winfo, GetTextValue('C'), str2);
- db_set_ws(hContact, "CList", "MyHandle", str2);
+ db_set_ws(hContact, "CList", "MyHandle", GetDisplay(&winfo, GetTextValue('C')));
- GetDisplay(&winfo, GetTextValue('S'), str2);
- if (str2[0])
+ CMStringW str2(GetDisplay(&winfo, GetTextValue('S')));
+ if (!str2.IsEmpty())
db_set_ws(hContact, "CList", "StatusMsg", str2);
else
db_unset(hContact, "CList", "StatusMsg");
-
- ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, nullptr, (LPARAM)(str2[0] ? str2 : nullptr));
+ ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, nullptr, (LPARAM)(str2.IsEmpty() ? nullptr : str2.c_str()));
// save descriptions in MyNotes
- GetDisplay(&winfo, GetTextValue('N'), str2);
- db_set_ws(hContact, "UserInfo", "MyNotes", str2);
- GetDisplay(&winfo, GetTextValue('X'), str2);
- db_set_ws(hContact, WEATHERCONDITION, "WeatherInfo", str2);
+ db_set_ws(hContact, "UserInfo", "MyNotes", GetDisplay(&winfo, GetTextValue('N')));
+ db_set_ws(hContact, WEATHERCONDITION, "WeatherInfo", GetDisplay(&winfo, GetTextValue('X')));
// set the update tag
setByte(hContact, "IsUpdated", TRUE);
@@ -174,8 +169,7 @@ int CWeatherProto::UpdateWeather(MCONTACT hContact)
db_free(&dbv);
if (file != nullptr) {
// write data to the file and close
- GetDisplay(&winfo, GetTextValue('E'), str2);
- fputws(str2, file);
+ fputws(GetDisplay(&winfo, GetTextValue('E')), file);
fclose(file);
}
}
@@ -183,9 +177,7 @@ int CWeatherProto::UpdateWeather(MCONTACT hContact)
if (getByte(hContact, "History")) {
// internal log using history
- GetDisplay(&winfo, GetTextValue('H'), str2);
-
- T2Utf szMessage(str2);
+ T2Utf szMessage(GetDisplay(&winfo, GetTextValue('H')));
DBEVENTINFO dbei = {};
dbei.szModule = m_szModuleName;
diff --git a/protocols/Weather/src/weather_userinfo.cpp b/protocols/Weather/src/weather_userinfo.cpp
index 0679ddf6e9..1207d01b4a 100644
--- a/protocols/Weather/src/weather_userinfo.cpp
+++ b/protocols/Weather/src/weather_userinfo.cpp
@@ -151,8 +151,6 @@ public:
{
m_list.DeleteAllItems();
- wchar_t str[4096];
-
// load weather information from the contact into the WEATHERINFO struct
WEATHERINFO winfo = m_proto->LoadWeatherInfo(hContact);
// check if data exist. If not, display error message box
@@ -160,13 +158,11 @@ public:
SetDlgItemTextW(m_hwnd, IDC_MTEXT, TranslateT("No information available.\r\nPlease update weather condition first."));
else {
// set the display text and show the message box
- GetDisplay(&winfo, m_proto->GetTextValue('B'), str);
- SetDlgItemTextW(m_hwnd, IDC_MTEXT, str);
+ SetDlgItemTextW(m_hwnd, IDC_MTEXT, GetDisplay(&winfo, m_proto->GetTextValue('B')));
}
- GetDisplay(&winfo, L"%c, %t", str);
SetWindowTextW(m_hwnd, winfo.city);
- SetDlgItemTextW(m_hwnd, IDC_HEADERBAR, str);
+ SetDlgItemTextW(m_hwnd, IDC_HEADERBAR, GetDisplay(&winfo, L"%c, %t"));
// get all the settings and store them in a temporary list
LIST<char> arSettings(10);
@@ -311,9 +307,8 @@ public:
ppro = (CWeatherProto *)Proto_GetContactInstance(m_hContact);
// load weather info for the contact
- wchar_t str[MAX_TEXT_SIZE];
WEATHERINFO w = ppro->LoadWeatherInfo(m_hContact);
- SetDlgItemText(m_hwnd, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n"), str));
+ SetDlgItemText(m_hwnd, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n")));
SendDlgItemMessage(m_hwnd, IDC_INFOICON, STM_SETICON, (WPARAM)ppro->GetStatusIconBig(m_hContact), 0);
@@ -327,19 +322,16 @@ public:
SendDlgItemMessage(m_hwnd, IDC_INFO2, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
// set the text for displaying other current weather conditions data
- GetDisplay(&w, L"%c %t", str);
- SetDlgItemText(m_hwnd, IDC_INFO2, str);
+ SetDlgItemText(m_hwnd, IDC_INFO2, GetDisplay(&w, L"%c %t"));
SetDlgItemText(m_hwnd, IDC_INFO3, w.feel);
SetDlgItemText(m_hwnd, IDC_INFO4, w.pressure);
- GetDisplay(&w, L"%i %w", str);
- SetDlgItemText(m_hwnd, IDC_INFO5, str);
+ SetDlgItemText(m_hwnd, IDC_INFO5, GetDisplay(&w, L"%i %w"));
SetDlgItemText(m_hwnd, IDC_INFO6, w.dewpoint);
SetDlgItemText(m_hwnd, IDC_INFO7, w.sunrise);
SetDlgItemText(m_hwnd, IDC_INFO8, w.sunset);
SetDlgItemText(m_hwnd, IDC_INFO9, w.high);
SetDlgItemText(m_hwnd, IDC_INFO10, w.low);
- GetDisplay(&w, TranslateT("Last update on: %u"), str);
- SetDlgItemText(m_hwnd, IDC_INFO11, str);
+ SetDlgItemText(m_hwnd, IDC_INFO11, GetDisplay(&w, TranslateT("Last update on: %u")));
SetDlgItemText(m_hwnd, IDC_INFO12, w.humid);
SetDlgItemText(m_hwnd, IDC_INFO13, w.vis);
return true;