From b97306f8dc5e4f93bd3e6e5500a8b8338d6249a2 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Sat, 16 May 2015 17:34:54 +0000 Subject: cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@13625 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Ping/src/utils.cpp | 142 ++++++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 67 deletions(-) (limited to 'plugins/Ping/src/utils.cpp') diff --git a/plugins/Ping/src/utils.cpp b/plugins/Ping/src/utils.cpp index 8e57dde2ff..84d86718b7 100644 --- a/plugins/Ping/src/utils.cpp +++ b/plugins/Ping/src/utils.cpp @@ -1,56 +1,57 @@ #include "common.h" -LRESULT CALLBACK NullWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) +LRESULT CALLBACK NullWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch( message ) { - case WM_COMMAND: { - PUDeletePopup( hWnd ); - break; - } + switch (message) { + case WM_COMMAND: { + PUDeletePopup(hWnd); + break; + } - case WM_CONTEXTMENU: - PUDeletePopup( hWnd ); - break; + case WM_CONTEXTMENU: + PUDeletePopup(hWnd); + break; } return DefWindowProc(hWnd, message, wParam, lParam); } -void CALLBACK sttMainThreadCallback( ULONG_PTR dwParam ) +void CALLBACK sttMainThreadCallback(ULONG_PTR dwParam) { - POPUPDATAT* ppd = ( POPUPDATAT* )dwParam; + POPUPDATAT* ppd = (POPUPDATAT*)dwParam; - if ( ServiceExists(MS_POPUP_ADDPOPUPT)) + if (ServiceExists(MS_POPUP_ADDPOPUPT)) PUAddPopupT(ppd); - free( ppd ); + free(ppd); } -void __stdcall ShowPopup(TCHAR *line1,TCHAR *line2, int flags ) +void __stdcall ShowPopup(TCHAR *line1, TCHAR *line2, int flags) { - if(CallService(MS_SYSTEM_TERMINATED, 0, 0)) return; + if (CallService(MS_SYSTEM_TERMINATED, 0, 0)) return; - if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) { - ShowClassPopupT("pingpopups",line1,line2); - } else if ( ServiceExists(MS_POPUP_ADDPOPUPT)) { - POPUPDATAT *ppd = ( POPUPDATAT* )calloc( sizeof( POPUPDATAT ), 1 ); + if (ServiceExists(MS_POPUP_ADDPOPUPCLASS)) { + ShowClassPopupT("pingpopups", line1, line2); + } + else if (ServiceExists(MS_POPUP_ADDPOPUPT)) { + POPUPDATAT *ppd = (POPUPDATAT*)calloc(sizeof(POPUPDATAT), 1); ppd->lchContact = NULL; ppd->lchIcon = (flags ? hIconResponding : hIconNotResponding); - _tcsncpy( ppd->lptzContactName, line1, MAX_CONTACTNAME); - _tcsncpy( ppd->lptzText, line2, MAX_SECONDLINE); + mir_tstrncpy(ppd->lptzContactName, line1, SIZEOF(ppd->lptzContactName)); + mir_tstrncpy(ppd->lptzText, line2, SIZEOF(ppd->lptzText)); - ppd->colorBack = GetSysColor( COLOR_BTNFACE ); - ppd->colorText = GetSysColor( COLOR_WINDOWTEXT ); + ppd->colorBack = GetSysColor(COLOR_BTNFACE); + ppd->colorText = GetSysColor(COLOR_WINDOWTEXT); ppd->iSeconds = 10; ppd->PluginWindowProc = NullWindowProc; ppd->PluginData = NULL; - QueueUserAPC(sttMainThreadCallback, mainThread, ( ULONG_PTR)ppd ); + QueueUserAPC(sttMainThreadCallback, mainThread, (ULONG_PTR)ppd); } else{ - MessageBox( NULL, line2, _T(PLUG) _T(" Message"), MB_OK | MB_ICONINFORMATION ); + MessageBox(NULL, line2, _T(PLUG) _T(" Message"), MB_OK | MB_ICONINFORMATION); return; } } @@ -60,31 +61,33 @@ void __stdcall ShowPopup(TCHAR *line1,TCHAR *line2, int flags ) // wParam is zero // lParam is address of PINGADDRESS structure where ping result is placed (i.e. modifies 'responding' // and 'round_trip_time') -INT_PTR PluginPing(WPARAM,LPARAM lParam) +INT_PTR PluginPing(WPARAM, LPARAM lParam) { PINGADDRESS *pa = (PINGADDRESS *)lParam; - if(pa->port == -1) { + if (pa->port == -1) { // ICMP echo - if(use_raw_ping) { + if (use_raw_ping) { pa->round_trip_time = raw_ping(_T2A(pa->pszName), options.ping_timeout * 1000); pa->responding = (pa->round_trip_time != -1); - } else { - + } + else { + ICMP_ECHO_REPLY result; pa->responding = ICMP::get_instance()->ping(_T2A(pa->pszName), result); - if(pa->responding) + if (pa->responding) pa->round_trip_time = (short)result.RoundTripTime; else pa->round_trip_time = -1; } - } else if(hNetlibUser) { + } + else if (hNetlibUser) { // TCP connect clock_t start_tcp = clock(); - + //GetLocalTime(&systime); - NETLIBOPENCONNECTION conn = {0}; + NETLIBOPENCONNECTION conn = { 0 }; conn.cbSize = sizeof(NETLIBOPENCONNECTION); conn.szHost = mir_t2a(pa->pszName); conn.wPort = pa->port; @@ -94,8 +97,8 @@ INT_PTR PluginPing(WPARAM,LPARAM lParam) mir_free((void*)conn.szHost); clock_t end_tcp = clock(); - - if(s) { + + if (s) { LINGER l; char buf[1024]; SOCKET socket = (SOCKET)CallService(MS_NETLIB_GETSOCKET, (WPARAM)s, (LPARAM)NLOCF_HTTP); @@ -110,9 +113,9 @@ INT_PTR PluginPing(WPARAM,LPARAM lParam) unsigned long bytes_remaining; ioctlsocket(socket, FIONBIO, &bytes_remaining); - if(bytes_remaining > 0) { + if (bytes_remaining > 0) { int retval, rx = 0; - while((retval = Netlib_Recv(s, buf, 1024, 0)) != SOCKET_ERROR && (retval > 0) && rx < 2048) { + while ((retval = Netlib_Recv(s, buf, 1024, 0)) != SOCKET_ERROR && (retval > 0) && rx < 2048) { rx += retval; // recv at most 2kb before closing connection } } @@ -121,7 +124,8 @@ INT_PTR PluginPing(WPARAM,LPARAM lParam) pa->round_trip_time = (int)(((end_tcp - start_tcp) / (double)CLOCKS_PER_SEC) * 1000); Netlib_CloseHandle(s); - } else { + } + else { pa->responding = false; pa->round_trip_time = -1; } @@ -133,7 +137,7 @@ INT_PTR PluginPing(WPARAM,LPARAM lParam) INT_PTR PingDisableAll(WPARAM wParam, LPARAM lParam) { PINGLIST pl; CallService(PLUG "/GetPingList", 0, (LPARAM)&pl); - for(pinglist_it i = pl.begin(); i != pl.end(); ++i) { + for (pinglist_it i = pl.begin(); i != pl.end(); ++i) { i->status = PS_DISABLED; i->miss_count = 0; } @@ -144,8 +148,8 @@ INT_PTR PingDisableAll(WPARAM wParam, LPARAM lParam) { INT_PTR PingEnableAll(WPARAM wParam, LPARAM lParam) { PINGLIST pl; CallService(PLUG "/GetPingList", 0, (LPARAM)&pl); - for(pinglist_it i = pl.begin(); i != pl.end(); ++i) { - if(i->status == PS_DISABLED) { + for (pinglist_it i = pl.begin(); i != pl.end(); ++i) { + if (i->status == PS_DISABLED) { i->status = PS_NOTRESPONDING; } } @@ -158,10 +162,10 @@ INT_PTR ToggleEnabled(WPARAM wParam, LPARAM lParam) { int retval = 0; PINGLIST pl; CallService(PLUG "/GetPingList", 0, (LPARAM)&pl); - for(pinglist_it i = pl.begin(); i != pl.end(); ++i) { - if(i->item_id == (DWORD)wParam) { + for (pinglist_it i = pl.begin(); i != pl.end(); ++i) { + if (i->item_id == (DWORD)wParam) { - if(i->status == PS_DISABLED) + if (i->status == PS_DISABLED) i->status = PS_NOTRESPONDING; else { i->status = PS_DISABLED; @@ -179,13 +183,13 @@ INT_PTR EditContact(WPARAM wParam, LPARAM lParam) { HWND hwndList = (HWND)CallService(MS_CLUI_GETHWND, 0, 0); CallService(PLUG "/GetPingList", 0, (LPARAM)&pl); - for(pinglist_it i = pl.begin(); i != pl.end(); ++i) { - if(i->item_id == (DWORD)wParam) { + for (pinglist_it i = pl.begin(); i != pl.end(); ++i) { + if (i->item_id == (DWORD)wParam) { add_edit_addr = *i; - - if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndList, DlgProcDestEdit) == IDOK) { - + + if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndList, DlgProcDestEdit) == IDOK) { + *i = add_edit_addr; CallService(PLUG "/SetAndSavePingList", (WPARAM)&pl, 0); return 0; @@ -198,11 +202,12 @@ INT_PTR EditContact(WPARAM wParam, LPARAM lParam) { INT_PTR DblClick(WPARAM wParam, LPARAM lParam) { PINGLIST pl; CallService(PLUG "/GetPingList", 0, (LPARAM)&pl); - for(pinglist_it i = pl.begin(); i != pl.end(); ++i) { - if(i->item_id == (DWORD)wParam) { - if(_tcslen(i->pszCommand)) { + for (pinglist_it i = pl.begin(); i != pl.end(); ++i) { + if (i->item_id == (DWORD)wParam) { + if (mir_tstrlen(i->pszCommand)) { ShellExecute(0, _T("open"), i->pszCommand, i->pszParams, 0, SW_SHOW); - } else { + } + else { return CallService(PLUG "/ToggleEnabled", wParam, 0); } } @@ -215,31 +220,34 @@ void import_ping_address(int index, PINGADDRESS &pa) { DBVARIANT dbv; char buf[256]; mir_snprintf(buf, SIZEOF(buf), "Address%d", index); - if(!db_get_ts(0, "PingPlug", buf, &dbv)) { - _tcsncpy(pa.pszName, dbv.ptszVal, MAX_PINGADDRESS_STRING_LENGTH); + if (!db_get_ts(0, "PingPlug", buf, &dbv)) { + mir_tstrncpy(pa.pszName, dbv.ptszVal, SIZEOF(pa.pszName)); db_free(&dbv); - } else - _tcsncpy(pa.pszName, TranslateT("Unknown Address"), MAX_PINGADDRESS_STRING_LENGTH); + } + else + mir_tstrncpy(pa.pszName, TranslateT("Unknown Address"), SIZEOF(pa.pszName)); mir_snprintf(buf, SIZEOF(buf), "Label%d", index); - if(!db_get_ts(0, "PingPlug", buf, &dbv)) { - _tcsncpy(pa.pszLabel, dbv.ptszVal, MAX_PINGADDRESS_STRING_LENGTH); + if (!db_get_ts(0, "PingPlug", buf, &dbv)) { + mir_tstrncpy(pa.pszLabel, dbv.ptszVal, SIZEOF(pa.pszLabel)); db_free(&dbv); - } else - _tcsncpy(pa.pszLabel, TranslateT("Unknown"), MAX_PINGADDRESS_STRING_LENGTH); + } + else + mir_tstrncpy(pa.pszLabel, TranslateT("Unknown"), SIZEOF(pa.pszLabel)); mir_snprintf(buf, SIZEOF(buf), "Port%d", index); pa.port = (int)db_get_dw(0, "PingPlug", buf, -1); mir_snprintf(buf, SIZEOF(buf), "Proto%d", index); - if(!db_get_s(0, "PingPlug", buf, &dbv)) { - strncpy(pa.pszProto, dbv.pszVal, MAX_PINGADDRESS_STRING_LENGTH); + if (!db_get_s(0, "PingPlug", buf, &dbv)) { + mir_strncpy(pa.pszProto, dbv.pszVal, SIZEOF(pa.pszProto)); db_free(&dbv); mir_snprintf(buf, SIZEOF(buf), "Status%d", index); pa.set_status = db_get_w(0, "PingPlug", buf, ID_STATUS_ONLINE); mir_snprintf(buf, SIZEOF(buf), "Status2%d", index); pa.get_status = db_get_w(0, "PingPlug", buf, ID_STATUS_OFFLINE); - } else + } + else pa.pszProto[0] = '\0'; @@ -252,7 +260,7 @@ void import_ping_address(int index, PINGADDRESS &pa) { pa.item_id = 0; mir_snprintf(buf, SIZEOF(buf), "Enabled%d", index); - if(db_get_b(0, "PingPlug", buf, 1) == 1) + if (db_get_b(0, "PingPlug", buf, 1) == 1) pa.status = PS_NOTRESPONDING; else pa.status = PS_DISABLED; @@ -266,7 +274,7 @@ void import_ping_addresses() mir_cslock lck(list_cs); list_items.clear(); - for(int index = 0; index < count; index++) + for (int index = 0; index < count; index++) { import_ping_address(index, pa); list_items.push_back(pa); -- cgit v1.2.3