diff options
-rw-r--r-- | plugins/Ping/src/log.cpp | 47 | ||||
-rw-r--r-- | plugins/Ping/src/log.h | 5 | ||||
-rw-r--r-- | plugins/Ping/src/options.cpp | 317 | ||||
-rw-r--r-- | plugins/Ping/src/ping.cpp | 11 | ||||
-rw-r--r-- | plugins/Ping/src/pingthread.cpp | 16 | ||||
-rw-r--r-- | plugins/Ping/src/rawping.cpp | 68 | ||||
-rw-r--r-- | plugins/Ping/src/version.h | 14 |
7 files changed, 218 insertions, 260 deletions
diff --git a/plugins/Ping/src/log.cpp b/plugins/Ping/src/log.cpp index b084eb1f7f..9063b6c314 100644 --- a/plugins/Ping/src/log.cpp +++ b/plugins/Ping/src/log.cpp @@ -1,9 +1,12 @@ #include "stdafx.h"
-INT_PTR Log(WPARAM wParam, LPARAM) {
+void Log(const wchar_t *pwszText)
+{
+ if (!options.logging)
+ return;
wchar_t buf[1024], tbuf[512], dbuf[512];
- CallService(MODULENAME "/GetLogFilename", (WPARAM)1024, (LPARAM)buf);
+ GetLogFilename(buf, _countof(buf));
//char TBcapt[255];
SYSTEMTIME systime;
@@ -13,47 +16,33 @@ INT_PTR Log(WPARAM wParam, LPARAM) { GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, nullptr, tbuf, 512);
GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, nullptr, dbuf, 512);
- wchar_t *line = (wchar_t *)wParam;
-
FILE *f = _wfopen(buf, L"a+");
if (f) {
if (options.log_csv) {
- fwprintf(f, L"%s, %s, %s\n", dbuf, tbuf, line);
+ fwprintf(f, L"%s, %s, %s\n", dbuf, tbuf, pwszText);
}
else {
- fwprintf(f, L"%s, %s: %s\n", dbuf, tbuf, line);
+ fwprintf(f, L"%s, %s: %s\n", dbuf, tbuf, pwszText);
}
fclose(f);
}
-
- return 0;
}
-INT_PTR GetLogFilename(WPARAM wParam, LPARAM lParam) {
- DBVARIANT dbv;
- wchar_t *filename = (wchar_t *)lParam;
- if (g_plugin.getWString("LogFilename", &dbv)) {
- Profile_GetPathW(wParam, filename);
- mir_wstrncat(filename, L"\\ping_log.txt", wParam - mir_wstrlen(filename));
+void GetLogFilename(wchar_t *pBuf, size_t cbLen)
+{
+ ptrW wszLogName(g_plugin.getWStringA("LogFilename"));
+ if (wszLogName == nullptr) {
+ Profile_GetPathW(cbLen, pBuf);
+ mir_wstrncat(pBuf, L"\\ping_log.txt", cbLen - mir_wstrlen(pBuf));
}
- else {
- mir_wstrncpy(filename, dbv.pwszVal, wParam);
- db_free(&dbv);
- }
-
- ((wchar_t *)lParam)[wParam - 1] = 0;
+ else mir_wstrncpy(pBuf, wszLogName, cbLen);
- return 0;
+ pBuf[cbLen - 1] = 0;
}
-INT_PTR SetLogFilename(WPARAM, LPARAM lParam) {
- g_plugin.setWString("LogFilename", (wchar_t *)lParam);
- return 0;
-}
-
-INT_PTR ViewLogData(WPARAM wParam, LPARAM) {
+INT_PTR ViewLogData(WPARAM wParam, LPARAM)
+{
wchar_t buf[MAX_PATH];
- CallService(MODULENAME "/GetLogFilename", (WPARAM)MAX_PATH, (LPARAM)buf);
+ GetLogFilename(buf, _countof(buf));
return (INT_PTR)ShellExecute((HWND)wParam, L"edit", buf, L"", L"", SW_SHOW);
}
-
diff --git a/plugins/Ping/src/log.h b/plugins/Ping/src/log.h index 1930dddede..393f4509d8 100644 --- a/plugins/Ping/src/log.h +++ b/plugins/Ping/src/log.h @@ -1,9 +1,8 @@ #ifndef _PING_LOG
#define _PING_LOG
-INT_PTR Log(WPARAM wParam, LPARAM lParam);
-INT_PTR GetLogFilename(WPARAM wParam, LPARAM lParam);
-INT_PTR SetLogFilename(WPARAM wParam, LPARAM lParam);
+void Log(const wchar_t *pwszText);
+void GetLogFilename(wchar_t *pBuf, size_t cbLen);
INT_PTR ViewLogData(WPARAM wParam, LPARAM lParam);
#endif
diff --git a/plugins/Ping/src/options.cpp b/plugins/Ping/src/options.cpp index 676a864ea0..953b72dc0a 100644 --- a/plugins/Ping/src/options.cpp +++ b/plugins/Ping/src/options.cpp @@ -75,28 +75,28 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA CallService(MODULENAME "/ViewLogData", 0, 0);
break;
case IDC_BTN_LOGBROWSE:
- {
- wchar_t filter[MAX_PATH];
- mir_snwprintf(filter, L"%s%c*.txt%c%s%c*.*%c", TranslateT("Text Files (*.txt)"), 0, 0, TranslateT("All Files"), 0, 0);
- OPENFILENAME ofn = { 0 };
- ofn.lStructSize = sizeof(ofn);
- ofn.lpstrFile = options.log_filename;
- ofn.hwndOwner = hwndDlg;
- ofn.nMaxFile = _countof(options.log_filename);
- ofn.lpstrTitle = TranslateT("Open log file");
- ofn.lpstrFilter = filter;
- ofn.nFilterIndex = 1;
- ofn.lpstrFileTitle = nullptr;
- ofn.nMaxFileTitle = 0;
- ofn.lpstrInitialDir = nullptr;
- ofn.Flags = OFN_PATHMUSTEXIST;
-
- if (GetOpenFileName(&ofn) == TRUE) {
- SetDlgItemText(hwndDlg, IDC_ED_FILENAME, ofn.lpstrFile);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ {
+ wchar_t filter[MAX_PATH];
+ mir_snwprintf(filter, L"%s%c*.txt%c%s%c*.*%c", TranslateT("Text Files (*.txt)"), 0, 0, TranslateT("All Files"), 0, 0);
+ OPENFILENAME ofn = { 0 };
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFile = options.log_filename;
+ ofn.hwndOwner = hwndDlg;
+ ofn.nMaxFile = _countof(options.log_filename);
+ ofn.lpstrTitle = TranslateT("Open log file");
+ ofn.lpstrFilter = filter;
+ ofn.nFilterIndex = 1;
+ ofn.lpstrFileTitle = nullptr;
+ ofn.nMaxFileTitle = 0;
+ ofn.lpstrInitialDir = nullptr;
+ ofn.Flags = OFN_PATHMUSTEXIST;
+
+ if (GetOpenFileName(&ofn) == TRUE) {
+ SetDlgItemText(hwndDlg, IDC_ED_FILENAME, ofn.lpstrFile);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
}
- }
- break;
+ break;
}
break;
}
@@ -145,8 +145,10 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA RefreshWindow(0, 0);
- if (options.logging) CallService(MODULENAME "/Log", (WPARAM)L"options changed", 0);
- if (hWakeEvent) SetEvent(hWakeEvent);
+ Log(L"options changed");
+
+ if (hWakeEvent)
+ SetEvent(hWakeEvent);
return TRUE;
}
break;
@@ -159,7 +161,8 @@ PINGLIST temp_list; PINGADDRESS add_edit_addr;
// host edit
-INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM) {
+INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM)
+{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
@@ -204,6 +207,7 @@ INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM) // ? doesn't work? ?
SetFocus(GetDlgItem(hwndDlg, IDC_ED_DESTLAB));
return FALSE;
+
case WM_COMMAND:
if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_COMBO_DESTPROTO) {
int sel = SendDlgItemMessage(hwndDlg, IDC_COMBO_DESTPROTO, CB_GETCURSEL, 0, 0);
@@ -213,21 +217,19 @@ INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM) }
}
- if (HIWORD(wParam) == BN_CLICKED)
- {
- switch (LOWORD(wParam))
- {
+ if (HIWORD(wParam) == BN_CLICKED) {
+ switch (LOWORD(wParam)) {
case IDC_CHK_DESTTCP:
EnableWindow(GetDlgItem(hwndDlg, IDC_ED_DESTPORT), IsDlgButtonChecked(hwndDlg, IDC_CHK_DESTTCP));
break;
+
case IDOK:
GetDlgItemText(hwndDlg, IDC_ED_DESTADDR, add_edit_addr.pszName, _countof(add_edit_addr.pszName));
GetDlgItemText(hwndDlg, IDC_ED_DESTLAB, add_edit_addr.pszLabel, _countof(add_edit_addr.pszLabel));
GetDlgItemText(hwndDlg, IDC_ED_COMMAND, add_edit_addr.pszCommand, _countof(add_edit_addr.pszCommand));
GetDlgItemText(hwndDlg, IDC_ED_PARAMS, add_edit_addr.pszParams, _countof(add_edit_addr.pszParams));
- if (SendDlgItemMessage(hwndDlg, IDC_COMBO_DESTPROTO, CB_GETCURSEL, 0, 0) != -1)
- {
+ if (SendDlgItemMessage(hwndDlg, IDC_COMBO_DESTPROTO, CB_GETCURSEL, 0, 0) != -1) {
GetDlgItemTextA(hwndDlg, IDC_COMBO_DESTPROTO, add_edit_addr.pszProto, _countof(add_edit_addr.pszProto));
if (!mir_strcmp(add_edit_addr.pszProto, Translate("<none>")))
add_edit_addr.pszProto[0] = '\0';
@@ -241,22 +243,20 @@ INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM) add_edit_addr.get_status = ID_STATUS_OFFLINE + sel;
}
}
- else
- add_edit_addr.pszProto[0] = '\0';
+ else add_edit_addr.pszProto[0] = '\0';
- if (IsDlgButtonChecked(hwndDlg, IDC_CHK_DESTTCP))
- {
+ if (IsDlgButtonChecked(hwndDlg, IDC_CHK_DESTTCP)) {
BOOL tr;
int port = GetDlgItemInt(hwndDlg, IDC_ED_DESTPORT, &tr, FALSE);
if (tr) add_edit_addr.port = port;
else add_edit_addr.port = -1;
}
- else
- add_edit_addr.port = -1;
+ else add_edit_addr.port = -1;
EndDialog(hwndDlg, IDOK);
RefreshWindow(0, 0);
break;
+
case IDCANCEL:
EndDialog(hwndDlg, IDCANCEL);
break;
@@ -271,8 +271,7 @@ INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM) bool Edit(HWND hwnd, PINGADDRESS &addr)
{
add_edit_addr = addr;
- if (DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DIALOG3), hwnd, DlgProcDestEdit) == IDOK)
- {
+ if (DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DIALOG3), hwnd, DlgProcDestEdit) == IDOK) {
addr = add_edit_addr;
return true;
}
@@ -285,26 +284,22 @@ static INT_PTR CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR {
switch (msg) {
case WM_INITDIALOG:
- {
TranslateDialogDefault(hwndDlg);
-
- mir_cslock lck(data_list_cs);
- temp_list = data_list;
-
- for (pinglist_it i = temp_list.begin(); i != temp_list.end(); ++i)
{
- int index = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->pszLabel);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, index, (LPARAM)&(*i));
+ mir_cslock lck(data_list_cs);
+ temp_list = data_list;
+
+ for (pinglist_it i = temp_list.begin(); i != temp_list.end(); ++i) {
+ int index = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->pszLabel);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, index, (LPARAM) & (*i));
+ }
}
- }
- return TRUE;
+ return TRUE;
case WM_COMMAND:
- if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LST_DEST)
- {
+ if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LST_DEST) {
int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
- if (sel != LB_ERR)
- {
+ if (sel != LB_ERR) {
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);
@@ -314,38 +309,34 @@ static INT_PTR CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR }
}
- if (HIWORD(wParam) == BN_CLICKED)
- {
- switch (LOWORD(wParam))
- {
+ if (HIWORD(wParam) == BN_CLICKED) {
+ switch (LOWORD(wParam)) {
case IDC_BTN_DESTEDIT:
- {
- int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
- if (sel != LB_ERR)
{
- PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel, 0);
- PINGADDRESS temp = *item;
- if (Edit(hwndDlg, temp))
- {
- *item = temp;
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel, 0);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel, (LPARAM)item->pszLabel);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel, (LPARAM)item);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)sel, 0);
-
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), sel > 0);
- int count = SendDlgItemMessage(hwndDlg, IDC_BTN_DESTDOWN, LB_GETCOUNT, 0, 0);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel < count - 1));
-
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
+ if (sel != LB_ERR) {
+ PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel, 0);
+ PINGADDRESS temp = *item;
+ if (Edit(hwndDlg, temp)) {
+ *item = temp;
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel, 0);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel, (LPARAM)item->pszLabel);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel, (LPARAM)item);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)sel, 0);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), sel > 0);
+ int count = SendDlgItemMessage(hwndDlg, IDC_BTN_DESTDOWN, LB_GETCOUNT, 0, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel < count - 1));
+
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
}
}
- }
- break;
- case IDC_BTN_DESTADD:
+ break;
+ case IDC_BTN_DESTADD:
memset(&add_edit_addr, 0, sizeof(add_edit_addr));
add_edit_addr.cbSize = sizeof(add_edit_addr);
add_edit_addr.port = -1;
@@ -355,13 +346,12 @@ static INT_PTR CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR add_edit_addr.item_id = 0;
add_edit_addr.index = (int)temp_list.size();
- if (DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, DlgProcDestEdit) == IDOK)
- {
+ if (DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, DlgProcDestEdit) == IDOK) {
temp_list.push_back(add_edit_addr);
int index = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)add_edit_addr.pszLabel);
SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)index, 0);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)index, (LPARAM)&(temp_list.back()));
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)index, (LPARAM) & (temp_list.back()));
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), TRUE);
@@ -373,110 +363,108 @@ static INT_PTR CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
-
break;
+
case IDC_BTN_DESTREM:
- {
- int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
- if (sel != LB_ERR) {
- PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel, 0);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel, 0);
- temp_list.remove(*item);
- }
+ {
+ int sel = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
+ if (sel != LB_ERR) {
+ PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel, 0);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel, 0);
+ temp_list.remove(*item);
+ }
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTREM), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTEDIT), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), FALSE);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- RefreshWindow(0, 0);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ RefreshWindow(0, 0);
+ }
break;
- }
- case IDC_BTN_DESTDOWN:
- {
- int sel2 = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
- if (sel2 != LB_ERR) {
- PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2, 0),
- *item2 = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2 + 1, 0);
- if (item && item2)
- {
- add_edit_addr = *item;
- *item = *item2;
- *item2 = add_edit_addr;
-
- // keep indexes the same, as they're used for sorting the binary tree
- int index = item->index, index2 = item2->index;
- item->index = index2;
- item2->index = index;
-
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel2, 0);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)item->pszLabel);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel2, (LPARAM)item);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)(sel2 + 1), 0);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)(sel2 + 1), (LPARAM)item2->pszLabel);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)(sel2 + 1), (LPARAM)item2);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)(sel2 + 1), 0);
-
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel2 + 1 > 0));
- int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel2 + 1 < count - 1));
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ case IDC_BTN_DESTDOWN:
+ {
+ int sel2 = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
+ if (sel2 != LB_ERR) {
+ PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2, 0),
+ *item2 = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2 + 1, 0);
+ if (item && item2) {
+ add_edit_addr = *item;
+ *item = *item2;
+ *item2 = add_edit_addr;
+
+ // keep indexes the same, as they're used for sorting the binary tree
+ int index = item->index, index2 = item2->index;
+ item->index = index2;
+ item2->index = index;
+
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel2, 0);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)item->pszLabel);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel2, (LPARAM)item);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)(sel2 + 1), 0);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)(sel2 + 1), (LPARAM)item2->pszLabel);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)(sel2 + 1), (LPARAM)item2);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)(sel2 + 1), 0);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel2 + 1 > 0));
+ int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel2 + 1 < count - 1));
+
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
}
}
- }
- break;
+ break;
+
case IDC_BTN_DESTUP:
- {
- int sel2 = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
- if (sel2 != LB_ERR) {
- PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2, 0),
- *item2 = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2 - 1, 0);
+ {
+ int sel2 = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCURSEL, 0, 0);
+ if (sel2 != LB_ERR) {
+ PINGADDRESS *item = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2, 0),
+ *item2 = (PINGADDRESS *)SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETITEMDATA, sel2 - 1, 0);
- if (item && item2)
- {
- add_edit_addr = *item;
- *item = *item2;
- *item2 = add_edit_addr;
+ if (item && item2) {
+ add_edit_addr = *item;
+ *item = *item2;
+ *item2 = add_edit_addr;
- // keep indexes the same, as they're used for sorting the binary tree
- int index = item->index, index2 = item2->index;
- item->index = index2;
- item2->index = index;
+ // keep indexes the same, as they're used for sorting the binary tree
+ int index = item->index, index2 = item2->index;
+ item->index = index2;
+ item2->index = index;
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel2, 0);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)item->pszLabel);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel2, (LPARAM)item);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)sel2, 0);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)item->pszLabel);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)sel2, (LPARAM)item);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)(sel2 - 1), 0);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)(sel2 - 1), (LPARAM)item2->pszLabel);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)(sel2 - 1), (LPARAM)item2);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_DELETESTRING, (WPARAM)(sel2 - 1), 0);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_INSERTSTRING, (WPARAM)(sel2 - 1), (LPARAM)item2->pszLabel);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETITEMDATA, (WPARAM)(sel2 - 1), (LPARAM)item2);
- SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)(sel2 - 1), 0);
+ SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_SETCURSEL, (WPARAM)(sel2 - 1), 0);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel2 - 1 > 0));
- int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel2 - 1 < count - 1));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTUP), (sel2 - 1 > 0));
+ int count = SendDlgItemMessage(hwndDlg, IDC_LST_DEST, LB_GETCOUNT, 0, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DESTDOWN), (sel2 - 1 < count - 1));
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
}
}
- }
- break;
+ break;
}
}
if (LOWORD(wParam) == IDC_BGCOL
- || LOWORD(wParam) == IDC_SP_INDENT || LOWORD(wParam) == IDC_SP_ROWHEIGHT)
- {
+ || LOWORD(wParam) == IDC_SP_INDENT || LOWORD(wParam) == IDC_SP_ROWHEIGHT) {
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
break;
case WM_NOTIFY:
- if (((LPNMHDR)lParam)->code == PSN_APPLY)
- {
+ if (((LPNMHDR)lParam)->code == PSN_APPLY) {
CallService(MODULENAME "/SetAndSavePingList", (WPARAM)&temp_list, 0);
CallService(MODULENAME "/GetPingList", 0, (LPARAM)&temp_list);
// the following will be affected due to list rebuild event
@@ -508,7 +496,8 @@ int PingOptInit(WPARAM wParam, LPARAM) return 0;
}
-void LoadOptions() {
+void LoadOptions()
+{
options.ping_period = g_plugin.getDword("PingPeriod", DEFAULT_PING_PERIOD);
options.ping_timeout = g_plugin.getDword("PingTimeout", DEFAULT_PING_TIMEOUT);
@@ -525,7 +514,7 @@ void LoadOptions() { options.retries = g_plugin.getDword("Retries", 0);
- CallService(MODULENAME "/GetLogFilename", (WPARAM)MAX_PATH, (LPARAM)options.log_filename);
+ GetLogFilename(options.log_filename, _countof(options.log_filename));
ICMP::get_instance()->set_timeout(options.ping_timeout * 1000);
@@ -533,7 +522,8 @@ void LoadOptions() { options.log_csv = (g_plugin.getByte("LogCSV", 0) == 1);
}
-void SaveOptions() {
+void SaveOptions()
+{
g_plugin.setDword("PingPeriod", options.ping_period);
g_plugin.setDword("PingTimeout", options.ping_timeout);
CallService(MODULENAME "/SetPingTimeout", (WPARAM)options.ping_timeout, 0);
@@ -548,8 +538,7 @@ void SaveOptions() { g_plugin.setWord("RowHeight", options.row_height);
g_plugin.setDword("Retries", (uint32_t)options.retries);
-
- CallService(MODULENAME "/SetLogFilename", (WPARAM)MAX_PATH, (LPARAM)options.log_filename);
+ g_plugin.setWString("LogFilename", options.log_filename);
ICMP::get_instance()->set_timeout(options.ping_timeout * 1000);
diff --git a/plugins/Ping/src/ping.cpp b/plugins/Ping/src/ping.cpp index 1cf633c8d9..c9a63554a9 100644 --- a/plugins/Ping/src/ping.cpp +++ b/plugins/Ping/src/ping.cpp @@ -46,10 +46,7 @@ static void CreatePluginServices() reload_event_handle = CreateHookableEvent(MODULENAME "/ListReload");
//log
- CreateServiceFunction(MODULENAME "/Log", Log);
CreateServiceFunction(MODULENAME "/ViewLogData", ViewLogData);
- CreateServiceFunction(MODULENAME "/GetLogFilename", GetLogFilename);
- CreateServiceFunction(MODULENAME "/SetLogFilename", SetLogFilename);
// menu
CreateServiceFunction(MODULENAME "/DisableAll", PingDisableAll);
@@ -102,9 +99,7 @@ static int OnModulesLoaded(WPARAM, LPARAM) graphs_init();
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"start", 0);
-
+ Log(L"start");
return 0;
}
@@ -146,8 +141,6 @@ int CMPlugin::Unload() {
SavePingList(0, 0);
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"stop", 0);
-
+ Log(L"stop");
return 0;
}
diff --git a/plugins/Ping/src/pingthread.cpp b/plugins/Ping/src/pingthread.cpp index 8f866bb8b9..e4957fff04 100644 --- a/plugins/Ping/src/pingthread.cpp +++ b/plugins/Ping/src/pingthread.cpp @@ -31,8 +31,7 @@ static int transparentFocus = 1; bool get_thread_finished()
{
mir_cslock lck(thread_finished_cs);
- bool retval = thread_finished;
- return retval;
+ return thread_finished;
}
void set_thread_finished(bool f)
@@ -65,7 +64,7 @@ void SetProtoStatus(wchar_t *pszLabel, char *pszProto, int if_status, int new_st if (options.logging) {
wchar_t buf[1024];
mir_snwprintf(buf, TranslateT("%s - setting status of protocol '%S' (%d)"), pszLabel, pszProto, new_status);
- CallService(MODULENAME "/Log", (WPARAM)buf, 0);
+ Log(buf);
}
CallProtoService(pszProto, PS_SETSTATUS, new_status, 0);
}
@@ -191,7 +190,7 @@ void __cdecl sttCheckStatusThreadProc(void*) if (pa.miss_count == -1 - options.retries && options.logging) {
wchar_t buf[512];
mir_snwprintf(buf, TranslateT("%s - reply, %d"), pa.pszLabel, pa.round_trip_time);
- CallService(MODULENAME "/Log", (WPARAM)buf, 0);
+ Log(buf);
}
SetProtoStatus(pa.pszLabel, pa.pszProto, pa.get_status, pa.set_status);
}
@@ -205,7 +204,7 @@ void __cdecl sttCheckStatusThreadProc(void*) if (pa.miss_count == 1 + options.retries && options.logging) {
wchar_t buf[512];
mir_snwprintf(buf, TranslateT("%s - timeout"), pa.pszLabel);
- CallService(MODULENAME "/Log", (WPARAM)buf, 0);
+ Log(buf);
}
}
@@ -234,8 +233,7 @@ bool FrameIsFloating() int FillList(WPARAM, LPARAM)
{
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"ping address list reload", 0);
+ Log(L"ping address list reload");
PINGLIST pl;
CallService(MODULENAME "/GetPingList", 0, (LPARAM)&pl);
@@ -680,7 +678,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar if (options.logging) {
wchar_t buf[1024];
mir_snwprintf(buf, L"%s - %s", pItemData->pszLabel, (wake ? TranslateT("enabled") : TranslateT("double clicked")));
- CallService(MODULENAME "/Log", (WPARAM)buf, 0);
+ Log(buf);
}
}
}
@@ -913,6 +911,8 @@ void DeinitList() SetEvent(hWakeEvent);
if (status_update_thread) {
+ set_thread_finished(true);
+
WaitForSingleObject(status_update_thread, INFINITE);
status_update_thread = nullptr;
}
diff --git a/plugins/Ping/src/rawping.cpp b/plugins/Ping/src/rawping.cpp index a2c59aef81..01160998db 100644 --- a/plugins/Ping/src/rawping.cpp +++ b/plugins/Ping/src/rawping.cpp @@ -1,6 +1,6 @@ #include "stdafx.h"
-USHORT ip_checksum(USHORT* buffer, int size)
+USHORT ip_checksum(USHORT *buffer, int size)
{
unsigned long cksum = 0;
@@ -9,9 +9,9 @@ USHORT ip_checksum(USHORT* buffer, int size) cksum += *buffer++;
size -= sizeof(USHORT);
}
- if (size) {
- cksum += *(UCHAR*)buffer;
- }
+
+ if (size)
+ cksum += *(UCHAR *)buffer;
// Do a little shuffling
cksum = (cksum >> 16) + (cksum & 0xffff);
@@ -27,7 +27,7 @@ char recv_buff[1024]; USHORT seq_no = 0;
bool inited = false;
-extern int init_raw_ping()
+int init_raw_ping()
{
WSAData wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
@@ -46,7 +46,7 @@ extern int init_raw_ping() }
int ttl = 255;
- if (setsockopt(sd, IPPROTO_IP, IP_TTL, (const char*)&ttl, sizeof(ttl)) == SOCKET_ERROR) {
+ if (setsockopt(sd, IPPROTO_IP, IP_TTL, (const char *)&ttl, sizeof(ttl)) == SOCKET_ERROR) {
return 3;
}
@@ -69,7 +69,7 @@ extern int init_raw_ping() return 5;
}
-extern int raw_ping(char *host, int timeout)
+int raw_ping(char *host, int timeout)
{
if (!inited) return -1;
@@ -86,7 +86,7 @@ extern int raw_ping(char *host, int timeout) }
else {
// Not in dotted quad form, so try and look it up
- hostent* hp = gethostbyname(host);
+ hostent *hp = gethostbyname(host);
if (hp != nullptr) {
// Found an address for that host, so save it
memcpy(&(dest.sin_addr), hp->h_addr, hp->h_length);
@@ -95,7 +95,7 @@ extern int raw_ping(char *host, int timeout) }
else {
// Not a recognized hostname either!
- if (options.logging) CallService(MODULENAME "/Log", (WPARAM)L"rawping error: unrecognised host", 0);
+ Log(L"rawping error: unrecognised host");
return -1;
}
}
@@ -103,7 +103,7 @@ extern int raw_ping(char *host, int timeout) ICMPHeader *header = (ICMPHeader *)packet;
header->seq = ++seq_no;
header->checksum = 0;
- header->checksum = ip_checksum((USHORT*)header, sizeof(ICMPHeader));
+ header->checksum = ip_checksum((USHORT *)header, sizeof(ICMPHeader));
bool use_hi_res = false;
LARGE_INTEGER hr_freq = { 0 }, hr_send_time = { 0 };
@@ -113,13 +113,12 @@ extern int raw_ping(char *host, int timeout) QueryPerformanceCounter(&hr_send_time);
send_time = 0;
}
- else
- send_time = GetTickCount();
+ else send_time = GetTickCount();
// send packet
- int bwrote = sendto(sd, (char*)packet, sizeof(ICMPHeader), 0, (sockaddr*)&dest, sizeof(dest));
+ int bwrote = sendto(sd, (char *)packet, sizeof(ICMPHeader), 0, (sockaddr *)&dest, sizeof(dest));
if (bwrote == SOCKET_ERROR) {
- if (options.logging) CallService(MODULENAME "/Log", (WPARAM)L"rawping error: unable to send", 0);
+ Log(L"rawping error: unable to send");
return -1;
}
@@ -136,12 +135,10 @@ extern int raw_ping(char *host, int timeout) hr_current_time = hr_start;
current_time = start = 0;
}
- else
- current_time = start = GetTickCount();
+ else current_time = start = GetTickCount();
- while (use_hi_res ? (hr_current_time.QuadPart < hr_start.QuadPart + hr_timeout.QuadPart) : (current_time < start + timeout))
- {
- int bread = recvfrom(sd, recv_buff, 1024, 0, (sockaddr*)&source, &fromlen);
+ while (use_hi_res ? (hr_current_time.QuadPart < hr_start.QuadPart + hr_timeout.QuadPart) : (current_time < start + timeout)) {
+ int bread = recvfrom(sd, recv_buff, 1024, 0, (sockaddr *)&source, &fromlen);
if (use_hi_res)
QueryPerformanceCounter(&hr_current_time);
@@ -149,49 +146,41 @@ extern int raw_ping(char *host, int timeout) current_time = GetTickCount();
if (bread == SOCKET_ERROR) {
- if (WSAGetLastError() != WSAETIMEDOUT) {
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"rawping error: socket error...cycling", 0);
- }
+ if (WSAGetLastError() != WSAETIMEDOUT)
+ Log(L"rawping error: socket error...cycling");
continue;
}
if (reply_header->proto != ICMP_PROTO) {
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"rawping error: packet not ICMP...cycling", 0);
+ Log(L"rawping error: packet not ICMP...cycling");
continue;
}
if (reply_header->tos != 0) {
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"rawping error: TOS not 0...cycling", 0);
+ Log(L"rawping error: TOS not 0...cycling");
continue;
}
reply = (ICMPHeader *)(recv_buff + reply_header->h_len * 4);
if ((unsigned)bread < reply_header->h_len * 4 + sizeof(ICMPHeader)) {
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"rawping error: short header", 0);
+ Log(L"rawping error: short header");
continue;
}
if (reply->id != (USHORT)GetCurrentProcessId()) {
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"rawping error: wrong ID...cycling", 0);
+ Log(L"rawping error: wrong ID...cycling");
continue;
}
if (reply->type != PT_ICMP_ECHO_REPLY && reply->type != PT_ICMP_SOURCE_QUENCH) {
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"rawping error: wrong type...cycling", 0);
+ Log(L"rawping error: wrong type...cycling");
continue;
}
//if(reply->seq < seq_no) continue;
//if(reply->seq > seq_no) return -1;
if (reply->seq != seq_no) {
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"rawping error: wrong sequence number...cycling", 0);
+ Log(L"rawping error: wrong sequence number...cycling");
continue;
}
@@ -206,16 +195,15 @@ extern int raw_ping(char *host, int timeout) ticks.QuadPart = hr_current_time.QuadPart - hr_send_time.QuadPart;
return (int)(ticks.QuadPart * 1000 / hr_freq.QuadPart);
}
- else
- return current_time - send_time;
+
+ return current_time - send_time;
}
- if (options.logging)
- CallService(MODULENAME "/Log", (WPARAM)L"rawping error: timeout", 0);
+ Log(L"rawping error: timeout");
return -1;
}
-extern int cleanup_raw_ping()
+int cleanup_raw_ping()
{
if (inited) {
closesocket(sd);
diff --git a/plugins/Ping/src/version.h b/plugins/Ping/src/version.h index 6a5b2f22e9..fef33b3b7a 100644 --- a/plugins/Ping/src/version.h +++ b/plugins/Ping/src/version.h @@ -1,13 +1,13 @@ -#define __MAJOR_VERSION 0 -#define __MINOR_VERSION 9 +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 9 #define __RELEASE_NUM 1 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include <stdver.h> #define __PLUGIN_NAME "Ping" #define __FILENAME "Ping.dll" -#define __DESCRIPTION "Ping labelled IP addresses or domain names." -#define __AUTHOR "Scott Ellis" -#define __AUTHORWEB "https://miranda-ng.org/p/Ping/" -#define __COPYRIGHT "© 2005 Scott Ellis" +#define __DESCRIPTION "Ping labelled IP addresses or domain names." +#define __AUTHOR "Scott Ellis" +#define __AUTHORWEB "https://miranda-ng.org/p/Ping/" +#define __COPYRIGHT "© 2005 Scott Ellis" |