summaryrefslogtreecommitdiff
path: root/plugins/ConnectionNotify/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-09-25 10:00:22 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-09-25 10:00:22 +0000
commit77cc30f66c53cd638eb73bb92340c9144114e07a (patch)
treea5462767042dd144390a08ba49be1e7ebfce22ea /plugins/ConnectionNotify/src
parent66fe24c1af7b15aaf749413bf2aacc1d030610e2 (diff)
warning fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@6223 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/ConnectionNotify/src')
-rw-r--r--plugins/ConnectionNotify/src/ConnectionNotify.cpp595
-rw-r--r--plugins/ConnectionNotify/src/ConnectionNotify.h2
-rw-r--r--plugins/ConnectionNotify/src/debug.cpp112
-rw-r--r--plugins/ConnectionNotify/src/filter.cpp6
-rw-r--r--plugins/ConnectionNotify/src/netstat.cpp22
-rw-r--r--plugins/ConnectionNotify/src/netstat.h2
-rw-r--r--plugins/ConnectionNotify/src/pid2name.cpp123
-rw-r--r--plugins/ConnectionNotify/src/pid2name.h2
8 files changed, 350 insertions, 514 deletions
diff --git a/plugins/ConnectionNotify/src/ConnectionNotify.cpp b/plugins/ConnectionNotify/src/ConnectionNotify.cpp
index 7edc537f0e..6a4d4a850c 100644
--- a/plugins/ConnectionNotify/src/ConnectionNotify.cpp
+++ b/plugins/ConnectionNotify/src/ConnectionNotify.cpp
@@ -68,7 +68,7 @@ BOOL strrep(TCHAR *src,TCHAR *needle,TCHAR *newstring)
//strset(begining,' ');
//strset(tail,' ');
- if(!(found=_tcsstr(src,needle)))
+ if (!(found=_tcsstr(src,needle)))
return FALSE;
pos=(int)(found-src);
@@ -82,14 +82,6 @@ BOOL strrep(TCHAR *src,TCHAR *needle,TCHAR *newstring)
pos=mir_sntprintf(src,_tcslen(src),_T("%s%s%s"),begining,newstring,tail);
return TRUE;
}
-/*miranda IM
-__declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
-{
- if(mirandaVersion<PLUGIN_MAKE_VERSION(0,1,0,1)) return NULL;
- pluginInfo.cbSize=sizeof(PLUGININFO); // needed as v0.6 does equality check
- return (PLUGININFO*)&pluginInfo;
-}
-*/
extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
@@ -137,16 +129,16 @@ struct CONNECTION* LoadSettingsConnections()
{
struct CONNECTION *conn=(struct CONNECTION*)mir_alloc(sizeof(struct CONNECTION));
mir_snprintf(buff,sizeof(buff), "%dFilterIntIp", i);
- if(!db_get_ts(NULL, PLUGINNAME, buff, &dbv))
- wcsncpy(conn->strIntIp,dbv.ptszVal,_countof(conn->strIntIp) );
+ if (!db_get_ts(NULL, PLUGINNAME, buff, &dbv))
+ wcsncpy(conn->strIntIp,dbv.ptszVal,_countof(conn->strIntIp));
db_free(&dbv);
mir_snprintf(buff,sizeof(buff), "%dFilterExtIp", i);
- if(!db_get_ts(NULL, PLUGINNAME, buff, &dbv))
- wcsncpy(conn->strExtIp,dbv.ptszVal,_countof(conn->strExtIp) );
+ if (!db_get_ts(NULL, PLUGINNAME, buff, &dbv))
+ wcsncpy(conn->strExtIp,dbv.ptszVal,_countof(conn->strExtIp));
db_free(&dbv);
mir_snprintf(buff,sizeof(buff), "%dFilterPName", i);
- if(!db_get_ts(NULL, PLUGINNAME, buff, &dbv))
- wcsncpy(conn->PName,dbv.ptszVal,_countof(conn->PName) );
+ if (!db_get_ts(NULL, PLUGINNAME, buff, &dbv))
+ wcsncpy(conn->PName,dbv.ptszVal,_countof(conn->PName));
db_free(&dbv);
mir_snprintf(buff,sizeof(buff), "%dFilterIntPort", i);
@@ -206,14 +198,14 @@ void fillExceptionsListView(HWND hwndDlg)
lvI.pszText=tmp->PName;
ListView_InsertItem(hwndList, &lvI);
lvI.iSubItem=1;
- if(tmp->intIntPort==-1)
+ if (tmp->intIntPort==-1)
mir_sntprintf(tmpAddress,_countof(tmpAddress),_T("%s:*"),tmp->strIntIp);
else
mir_sntprintf(tmpAddress,_countof(tmpAddress),_T("%s:%d"),tmp->strIntIp,tmp->intIntPort);
lvI.pszText=tmpAddress;
ListView_SetItem(hwndList, &lvI);
lvI.iSubItem=2;
- if(tmp->intExtPort==-1)
+ if (tmp->intExtPort==-1)
mir_sntprintf(tmpAddress,_countof(tmpAddress),_T("%s:*"),tmp->strExtIp);
else
mir_sntprintf(tmpAddress,_countof(tmpAddress),_T("%s:%d"),tmp->strExtIp,tmp->intExtPort);
@@ -241,12 +233,12 @@ static INT_PTR CALLBACK FilterEditProc(HWND hWnd, UINT message, WPARAM wParam, L
SetDlgItemText(hWnd, ID_TXT_LOCAL_IP,conn->strIntIp);
SetDlgItemText(hWnd, ID_TXT_REMOTE_IP,conn->strExtIp);
- if(conn->intIntPort==-1)
+ if (conn->intIntPort==-1)
SetDlgItemText(hWnd, ID_TXT_LOCAL_PORT,_T("*"));
else
SetDlgItemInt(hWnd, ID_TXT_LOCAL_PORT,conn->intIntPort,FALSE);
- if(conn->intExtPort==-1)
+ if (conn->intExtPort==-1)
SetDlgItemText(hWnd, ID_TXT_REMOTE_PORT,_T("*"));
else
SetDlgItemInt(hWnd, ID_TXT_REMOTE_PORT,conn->intExtPort,FALSE);
@@ -304,11 +296,9 @@ static INT_PTR CALLBACK FilterEditProc(HWND hWnd, UINT message, WPARAM wParam, L
INT_PTR CALLBACK DlgProcConnectionNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND hwndList;
- switch(msg)
- {
- case WM_INITDIALOG://initialize dialog, so set properties from db.
+ switch(msg) {
+ case WM_INITDIALOG://initialize dialog, so set properties from db.
{
-
LVCOLUMN lvc={0};
LVITEM lvI={0};
TCHAR buff[256];
@@ -331,8 +321,7 @@ INT_PTR CALLBACK DlgProcConnectionNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wPar
SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_SETCOLOUR, 0, (LPARAM)settingBgColor);
SendDlgItemMessage(hwndDlg, IDC_FGCOLOR, CPM_SETCOLOUR, 0, (LPARAM)settingFgColor);
- if(!settingSetColours)
- {
+ if (!settingSetColours) {
HWND hwnd = GetDlgItem(hwndDlg, IDC_BGCOLOR);
CheckDlgButton(hwndDlg, IDC_SETCOLOURS, FALSE);
EnableWindow(hwnd, FALSE);
@@ -360,15 +349,13 @@ INT_PTR CALLBACK DlgProcConnectionNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wPar
// Initialize LVITEM members that are common to all
// items.
lvI.mask = LVIF_TEXT;
- for(int i = 0; i < STATUS_COUNT; i++)
- {
+ for(int i = 0; i < STATUS_COUNT; i++) {
lvI.pszText= (TCHAR *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)(ID_STATUS_ONLINE + i), GSMDF_TCHAR);
lvI.iItem = i;
ListView_InsertItem(hwndList, &lvI);
ListView_SetCheckState(hwndList, i, settingStatus[i]);
}
-
connExceptionsTmp=LoadSettingsConnections();
hwndList = GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS);
SendMessage(hwndList,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT);
@@ -389,255 +376,232 @@ INT_PTR CALLBACK DlgProcConnectionNotifyOpts(HWND hwndDlg, UINT msg, WPARAM wPar
//fill exceptions list
fillExceptionsListView(hwndDlg);
-
- break;
}
- case WM_COMMAND://user changed something, so get changes to variables
- PostMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- switch(LOWORD(wParam))
+ break;
+
+ case WM_COMMAND://user changed something, so get changes to variables
+ PostMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ switch(LOWORD(wParam)) {
+ case IDC_INTERVAL: settingInterval =GetDlgItemInt(hwndDlg, IDC_INTERVAL, NULL, FALSE); break;
+ case IDC_INTERVAL1: settingInterval1 =GetDlgItemInt(hwndDlg, IDC_INTERVAL1, NULL, TRUE); break;
+ case IDC_RESOLVEIP: settingResolveIp=(BYTE) IsDlgButtonChecked(hwndDlg, IDC_RESOLVEIP); break;
+ case ID_CHK_DEFAULTACTION: settingDefaultAction=(BYTE) IsDlgButtonChecked(hwndDlg, ID_CHK_DEFAULTACTION); break;
+ case ID_ADD:
{
- case IDC_INTERVAL: settingInterval =GetDlgItemInt(hwndDlg, IDC_INTERVAL, NULL, FALSE); break;
- case IDC_INTERVAL1: settingInterval1 =GetDlgItemInt(hwndDlg, IDC_INTERVAL1, NULL, TRUE); break;
- case IDC_RESOLVEIP: settingResolveIp=(BYTE) IsDlgButtonChecked(hwndDlg, IDC_RESOLVEIP); break;
- case ID_CHK_DEFAULTACTION: settingDefaultAction=(BYTE) IsDlgButtonChecked(hwndDlg, ID_CHK_DEFAULTACTION); break;
- case ID_ADD:
+ struct CONNECTION *cur=(struct CONNECTION *)mir_alloc(sizeof(struct CONNECTION));
+ memset(cur,0,sizeof(struct CONNECTION));
+ cur->intExtPort=-1;
+ cur->intIntPort=-1;
+ cur->Pid=0;
+ cur->PName[0]='*';
+ cur->strExtIp[0]='*';
+ cur->strIntIp[0]='*';
+
+ if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_FILTER_DIALOG), hwndDlg, FilterEditProc, (LPARAM)cur)==IDCANCEL) {
+ mir_free(cur);
+ cur = NULL;
+ }
+ else {
+ cur->next = connExceptionsTmp;
+ connExceptionsTmp = cur;
+ }
+
+ fillExceptionsListView(hwndDlg);
+ ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),0,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
+ SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
+ }
+ break;
+
+ case ID_DELETE:
+ {
+ int pos,pos1;
+ struct CONNECTION *cur = connExceptionsTmp, *pre = NULL;
+
+ pos=(int)ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS),-1,LVNI_FOCUSED );
+ if (pos==-1)break;
+ pos1=pos;
+ while(pos--)
{
- struct CONNECTION *cur=(struct CONNECTION *)mir_alloc(sizeof(struct CONNECTION));
- memset(cur,0,sizeof(struct CONNECTION));
- cur->intExtPort=-1;
- cur->intIntPort=-1;
- cur->Pid=0;
- cur->PName[0]='*';
- cur->strExtIp[0]='*';
- cur->strIntIp[0]='*';
-
- if(DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_FILTER_DIALOG), hwndDlg, FilterEditProc, (LPARAM)cur)==IDCANCEL)
- {
- mir_free(cur);
- cur=NULL;
- }
- else
- {
- cur->next=connExceptionsTmp;
- connExceptionsTmp=cur;
- }
+ pre=cur;
+ cur=cur->next;
+ }
+ if (pre==NULL)
+ connExceptionsTmp=connExceptionsTmp->next;
+ else
+ (pre)->next=cur->next;
+ mir_free(cur);
+ fillExceptionsListView(hwndDlg);
+ ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),pos1,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
+ SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
+ break;
+ }
+ case ID_UP:
+ {
+ int pos,pos1;
+ struct CONNECTION *cur=NULL,*pre=NULL,*prepre=NULL;
- fillExceptionsListView(hwndDlg);
- ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),0,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
- SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
- break;
+ cur=connExceptionsTmp;
+
+ pos=(int)ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS),-1,LVNI_FOCUSED );
+ if (pos==-1)break;
+ pos1=pos;
+ while(pos--)
+ {
+ prepre=pre;
+ pre=cur;
+ cur=cur->next;
}
- case ID_DELETE:
+ if (prepre!=NULL)
{
- int pos,pos1;
- struct CONNECTION *cur=NULL,*pre=NULL;
+ pre->next=cur->next;
+ cur->next=pre;
+ prepre->next=cur;
+ }
+ else if (pre!=NULL)
+ {
+ pre->next=cur->next;
+ cur->next=pre;
+ connExceptionsTmp=cur;
+ }
+ fillExceptionsListView(hwndDlg);
+ ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),pos1-1,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
+ SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
+ break;
+ }
+ case ID_DOWN:
+ {
+ int pos,pos1;
+ struct CONNECTION *cur=NULL,*pre=NULL;
- cur=connExceptionsTmp;
+ cur=connExceptionsTmp;
- pos=(int)ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS),-1,LVNI_FOCUSED );
- if(pos==-1)break;
- pos1=pos;
- while(pos--)
- {
- pre=cur;
- cur=cur->next;
- }
- if (pre==NULL)
- connExceptionsTmp=connExceptionsTmp->next;
- else
- (pre)->next=cur->next;
- mir_free(cur);
- fillExceptionsListView(hwndDlg);
- ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),pos1,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
- SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
- break;
+ pos=(int)ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS),-1,LVNI_FOCUSED );
+ if (pos==-1)break;
+ pos1=pos;
+ while(pos--)
+ {
+ pre=cur;
+ cur=cur->next;
}
- case ID_UP:
+ if (cur==connExceptionsTmp&&cur->next!=NULL)
{
- int pos,pos1;
- struct CONNECTION *cur=NULL,*pre=NULL,*prepre=NULL;
+ connExceptionsTmp=cur->next;
+ cur->next=cur->next->next;
+ connExceptionsTmp->next=cur;
+ }
+ else if (cur->next!=NULL)
+ {
+ struct CONNECTION *tmp=cur->next->next;
+ pre->next=cur->next;
+ cur->next->next=cur;
+ cur->next=tmp;
+ }
+ fillExceptionsListView(hwndDlg);
+ ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),pos1+1,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
+ SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
+ break;
+ }
+ case IDC_SETCOLOURS:
+ {
+ HWND hwnd = GetDlgItem(hwndDlg, IDC_BGCOLOR);
+ settingSetColours=IsDlgButtonChecked(hwndDlg, IDC_SETCOLOURS);
+ EnableWindow(hwnd,settingSetColours );
+ hwnd = GetDlgItem(hwndDlg, IDC_FGCOLOR);
+ EnableWindow(hwnd, settingSetColours);
+ break;
+ }
+ case IDC_BGCOLOR: settingBgColor = (COLORREF)SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0);break;
+ case IDC_FGCOLOR: settingFgColor = (COLORREF)SendDlgItemMessage(hwndDlg, IDC_FGCOLOR, CPM_GETCOLOUR, 0, 0);break;
- cur=connExceptionsTmp;
+ }
+ break;
+
+ case WM_NOTIFY://apply changes so write it to db
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_RESET:
+ LoadSettings();
+ deleteConnectionsTable(connExceptionsTmp);
+ connExceptionsTmp=LoadSettingsConnections();
+ return TRUE;
- pos=(int)ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS),-1,LVNI_FOCUSED );
- if(pos==-1)break;
- pos1=pos;
- while(pos--)
- {
- prepre=pre;
- pre=cur;
- cur=cur->next;
- }
- if (prepre!=NULL)
- {
- pre->next=cur->next;
- cur->next=pre;
- prepre->next=cur;
- }
- else if(pre!=NULL)
- {
- pre->next=cur->next;
- cur->next=pre;
- connExceptionsTmp=cur;
- }
- fillExceptionsListView(hwndDlg);
- ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),pos1-1,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
- SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
- break;
+ case PSN_APPLY:
+ db_set_dw (NULL, PLUGINNAME, "Interval", settingInterval );
+ db_set_dw (NULL, PLUGINNAME, "PopupInterval", settingInterval1 );
+ db_set_b(NULL, PLUGINNAME, "PopupSetColours", settingSetColours);
+ db_set_dw(NULL, PLUGINNAME, "PopupBgColor", (DWORD)settingBgColor);
+ db_set_dw(NULL, PLUGINNAME, "PopupFgColor", (DWORD)settingFgColor);
+ db_set_b(NULL, PLUGINNAME, "ResolveIp", settingResolveIp);
+ db_set_b(NULL, PLUGINNAME, "FilterDefaultAction", settingDefaultAction);
+
+ for(int i = 0; i < STATUS_COUNT ; i++) {
+ char buff[128];
+ mir_snprintf(buff,_countof(buff), "Status%d", i);
+ settingStatus[i] = (ListView_GetCheckState(GetDlgItem(hwndDlg, IDC_STATUS), i) ? TRUE : FALSE);
+ db_set_b(0, PLUGINNAME, buff, settingStatus[i] ? 1 : 0);
}
- case ID_DOWN:
+ if (WAIT_OBJECT_0 == WaitForSingleObject(hExceptionsMutex, 100)) {
+ deleteConnectionsTable(connExceptions);
+ saveSettingsConnections(connExceptionsTmp);
+ connExceptions = connExceptionsTmp;
+ connExceptionsTmp = LoadSettingsConnections();
+ ReleaseMutex(hExceptionsMutex);
+ }
+ return TRUE;
+ }
+ break;
+ }
+
+ if (GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS)==((LPNMHDR) lParam)->hwndFrom) {
+ switch (((LPNMHDR) lParam)->code) {
+ case NM_DBLCLK:
{
int pos,pos1;
- struct CONNECTION *cur=NULL,*pre=NULL;
+ struct CONNECTION *cur=NULL;
cur=connExceptionsTmp;
pos=(int)ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS),-1,LVNI_FOCUSED );
- if(pos==-1)break;
+ if (pos==-1)break;
pos1=pos;
while(pos--)
{
- pre=cur;
cur=cur->next;
}
- if (cur==connExceptionsTmp&&cur->next!=NULL)
- {
- connExceptionsTmp=cur->next;
- cur->next=cur->next->next;
- connExceptionsTmp->next=cur;
- }
- else if (cur->next!=NULL)
- {
- struct CONNECTION *tmp=cur->next->next;
- pre->next=cur->next;
- cur->next->next=cur;
- cur->next=tmp;
- }
+ DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_FILTER_DIALOG), hwndDlg, FilterEditProc, (LPARAM)cur);
fillExceptionsListView(hwndDlg);
- ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),pos1+1,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
+ ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),pos1,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
break;
- }
- case IDC_SETCOLOURS:
- {
- HWND hwnd = GetDlgItem(hwndDlg, IDC_BGCOLOR);
- settingSetColours=IsDlgButtonChecked(hwndDlg, IDC_SETCOLOURS);
- EnableWindow(hwnd,settingSetColours );
- hwnd = GetDlgItem(hwndDlg, IDC_FGCOLOR);
- EnableWindow(hwnd, settingSetColours);
- break;
}
- case IDC_BGCOLOR: settingBgColor = (COLORREF)SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0);break;
- case IDC_FGCOLOR: settingFgColor = (COLORREF)SendDlgItemMessage(hwndDlg, IDC_FGCOLOR, CPM_GETCOLOUR, 0, 0);break;
-
}
- break;
+ }
- case WM_NOTIFY://apply changes so write it to db
- switch(((LPNMHDR)lParam)->idFrom)
- {
- case 0:
- {
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_RESET:
- LoadSettings();
- deleteConnectionsTable(connExceptionsTmp);
- connExceptionsTmp=LoadSettingsConnections();
- return TRUE;
- case PSN_APPLY:
- {
- db_set_dw (NULL, PLUGINNAME, "Interval", settingInterval );
- db_set_dw (NULL, PLUGINNAME, "PopupInterval", settingInterval1 );
- db_set_b(NULL, PLUGINNAME, "PopupSetColours", settingSetColours);
- db_set_dw(NULL, PLUGINNAME, "PopupBgColor", (DWORD)settingBgColor);
- db_set_dw(NULL, PLUGINNAME, "PopupFgColor", (DWORD)settingFgColor);
- db_set_b(NULL, PLUGINNAME, "ResolveIp", settingResolveIp);
- db_set_b(NULL, PLUGINNAME, "FilterDefaultAction", settingDefaultAction);
-
- for(int i = 0; i < STATUS_COUNT ; i++)
- {
- char buff[128];
- mir_snprintf(buff,_countof(buff), "Status%d", i);
- settingStatus[i] = (ListView_GetCheckState(GetDlgItem(hwndDlg, IDC_STATUS), i) ? TRUE : FALSE);
- db_set_b(0, PLUGINNAME, buff, settingStatus[i] ? 1 : 0);
- }
- if( WAIT_OBJECT_0 == WaitForSingleObject( hExceptionsMutex, 100 ) )
- {
- deleteConnectionsTable(connExceptions);
- saveSettingsConnections(connExceptionsTmp);
- connExceptions=connExceptionsTmp;
- connExceptionsTmp=LoadSettingsConnections();
- ReleaseMutex(hExceptionsMutex);
- }
- }//case PSN_APPLY
-
-
- return TRUE;
- break;
- }//switch ->code
- break;
- }//case 0
- }//id from
- if (GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS)==((LPNMHDR) lParam)->hwndFrom)
- {
- switch (((LPNMHDR) lParam)->code)
- {
- case NM_DBLCLK:
- {
- int pos,pos1;
- struct CONNECTION *cur=NULL;
-
- cur=connExceptionsTmp;
-
- pos=(int)ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LIST_EXCEPTIONS),-1,LVNI_FOCUSED );
- if(pos==-1)break;
- pos1=pos;
- while(pos--)
- {
- cur=cur->next;
- }
- DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_FILTER_DIALOG), hwndDlg, FilterEditProc, (LPARAM)cur);
- fillExceptionsListView(hwndDlg);
- ListView_SetItemState(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS),pos1,LVNI_FOCUSED|LVIS_SELECTED , LVNI_FOCUSED|LVIS_SELECTED );
- SetFocus(GetDlgItem(hwndDlg,IDC_LIST_EXCEPTIONS));
- break;
- }
- }
- }
- if (GetDlgItem(hwndDlg, IDC_STATUS)==((LPNMHDR) lParam)->hwndFrom)
- {
- switch (((LPNMHDR) lParam)->code)
- {
- case LVN_ITEMCHANGED:
- {
- NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
- if((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK)
- {
- SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
- }
- break;
-
- }
- break;
- }
- }
- break;//switch(msg)
- case WM_DESTROY:
- {
- bOptionsOpen=FALSE;
- deleteConnectionsTable(connExceptionsTmp);
- connExceptionsTmp=NULL;
- return TRUE;
+ if (GetDlgItem(hwndDlg, IDC_STATUS) == ((LPNMHDR) lParam)->hwndFrom) {
+ switch (((LPNMHDR) lParam)->code) {
+ case LVN_ITEMCHANGED:
+ NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
+ if ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK)
+ SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
+ break;
}
- }//end switch(msg)
+ }
+ break;
+
+ case WM_DESTROY:
+ bOptionsOpen=FALSE;
+ deleteConnectionsTable(connExceptionsTmp);
+ connExceptionsTmp=NULL;
+ return TRUE;
+ }
return 0;
}
+
//options page on miranda called
int ConnectionNotifyOptInit(WPARAM wParam,LPARAM)
{
- OPTIONSDIALOGPAGE odp={0};
- odp.cbSize = sizeof(odp);
+ OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.hInstance = hInst;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_DIALOG);
odp.ptszTitle = _T(PLUGINNAME);
@@ -648,18 +612,18 @@ int ConnectionNotifyOptInit(WPARAM wParam,LPARAM)
return 0;
}
-
//gives protocol avainable statuses
INT_PTR GetCaps(WPARAM wParam,LPARAM lParam)
{
- if(wParam==PFLAGNUM_1)
+ if (wParam==PFLAGNUM_1)
return 0;
- if(wParam==PFLAGNUM_2)
+ if (wParam==PFLAGNUM_2)
return PF2_ONLINE; // add the possible statuses here.
- if(wParam==PFLAGNUM_3)
+ if (wParam==PFLAGNUM_3)
return 0;
return 0;
}
+
//gives name to protocol module
INT_PTR GetName(WPARAM wParam,LPARAM lParam)
{
@@ -696,14 +660,14 @@ INT_PTR SetStatus(WPARAM wParam,LPARAM lParam)
{
diffstat=0;
ResetEvent(killCheckThreadEvent);
- if(!hConnectionCheckThread)
+ if (!hConnectionCheckThread)
hConnectionCheckThread = (HANDLE)mir_forkthreadex(checkthread, 0, (unsigned int*)&ConnectionCheckThreadId);
}
else
{
int retv=0;
- if(settingStatus[wParam - ID_STATUS_ONLINE])
+ if (settingStatus[wParam - ID_STATUS_ONLINE])
retv= SetStatus(ID_STATUS_OFFLINE,lParam);
else
retv= SetStatus(ID_STATUS_ONLINE,lParam);
@@ -716,7 +680,7 @@ INT_PTR SetStatus(WPARAM wParam,LPARAM lParam)
//broadcast the message
//oldStatus = currentStatus;
- if(currentStatus!=wParam)
+ if (currentStatus!=wParam)
ProtoBroadcastAck(PLUGINNAME,NULL,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)currentStatus,wParam);
currentStatus = wParam;
return 0;
@@ -746,36 +710,28 @@ static unsigned __stdcall checkthread(void *dummy)
{
struct CONNECTION* conn=NULL,*connOld=first,*cur=NULL;
#ifdef _DEBUG
- _OutputDebugString(_T("checking connections table..."));
+ _OutputDebugString(_T("checking connections table..."));
#endif
- if(WAIT_OBJECT_0 == WaitForSingleObject(killCheckThreadEvent,100))
- {
- hConnectionCheckThread=NULL;
- return 0;
- }
- //TranslateMessage(&msg);
- //DispatchMessage(&msg);
-
-// if(currentStatus==ID_STATUS_OFFLINE)
-// continue;//if status lets to check
+ if (WAIT_OBJECT_0 == WaitForSingleObject(killCheckThreadEvent,100))
+ {
+ hConnectionCheckThread=NULL;
+ return 0;
+ }
conn=GetConnectionsTable();
cur=conn;
- while(cur!=NULL)
- {
- if (searchConnection(first,cur->strIntIp,cur->strExtIp,cur->intIntPort,cur->intExtPort,cur->state)==NULL && (settingStatusMask & (1 << (cur->state-1))))
- {
-
+ while(cur!=NULL) {
+ if (searchConnection(first,cur->strIntIp,cur->strExtIp,cur->intIntPort,cur->intExtPort,cur->state)==NULL && (settingStatusMask & (1 << (cur->state-1)))) {
#ifdef _DEBUG
- TCHAR msg[1024];
- mir_sntprintf(msg,_countof(msg),_T("%s:%d\n%s:%d"),cur->strIntIp,cur->intIntPort,cur->strExtIp,cur->intExtPort);
- _OutputDebugString(_T("New connection: %s"),msg);
+ TCHAR msg[1024];
+ mir_sntprintf(msg,_countof(msg),_T("%s:%d\n%s:%d"),cur->strIntIp,cur->intIntPort,cur->strExtIp,cur->intExtPort);
+ _OutputDebugString(_T("New connection: %s"),msg);
#endif
- pid2name(cur->Pid,cur->PName);
- if( WAIT_OBJECT_0 == WaitForSingleObject( hExceptionsMutex, 100 ) )
+ pid2name(cur->Pid, cur->PName, SIZEOF(cur->PName));
+ if ( WAIT_OBJECT_0 == WaitForSingleObject( hExceptionsMutex, 100 ))
{
- if(checkFilter(connExceptions,cur))
+ if (checkFilter(connExceptions,cur))
{
showMsg(cur->PName,cur->Pid,cur->strIntIp,cur->strExtIp,cur->intIntPort,cur->intExtPort,cur->state);
SkinPlaySound(PLUGINNAME_NEWSOUND);
@@ -797,45 +753,34 @@ static unsigned __stdcall checkthread(void *dummy)
//popup reactions
static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch(message)
- {
- case WM_COMMAND:
- {
- if (HIWORD(wParam) == STN_CLICKED)//client clicked on popup with left mouse button
- {
- struct CONNECTION *conn = (struct CONNECTION*)mir_alloc(sizeof(struct CONNECTION));
- struct CONNECTION *mpd=(struct CONNECTION*) PUGetPluginData(hWnd);
-
- memcpy(conn,mpd,sizeof(struct CONNECTION));
- PUDeletePopup(hWnd);
- PostThreadMessage(FilterOptionsThreadId,WM_ADD_FILTER,(WPARAM)0, (LPARAM)conn);
- }
- break;
- }
-
- case WM_RBUTTONUP:
- {
- PUDeletePopup(hWnd);
- break;
- }
-
- case UM_INITPOPUP:
- {
- //struct CONNECTON *conn=NULL;
- //conn = (struct CONNECTION*)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd,(LPARAM)conn);
- //MessageBox(NULL,conn->extIp);
- //PUDeletePopUp(hWnd);
- break;
- }
+ switch(message) {
+ case WM_COMMAND:
+ if (HIWORD(wParam) == STN_CLICKED)//client clicked on popup with left mouse button
+ {
+ struct CONNECTION *conn = (struct CONNECTION*)mir_alloc(sizeof(struct CONNECTION));
+ struct CONNECTION *mpd=(struct CONNECTION*) PUGetPluginData(hWnd);
- case UM_FREEPLUGINDATA:
- {
- struct CONNECTION *mpd = (struct CONNECTION*)PUGetPluginData(hWnd);
- if (mpd > 0) mir_free(mpd);
- return TRUE; //TRUE or FALSE is the same, it gets ignored.
- }
- default:
- break;
+ memcpy(conn,mpd,sizeof(struct CONNECTION));
+ PUDeletePopup(hWnd);
+ PostThreadMessage(FilterOptionsThreadId,WM_ADD_FILTER,(WPARAM)0, (LPARAM)conn);
+ }
+ break;
+
+ case WM_RBUTTONUP:
+ PUDeletePopup(hWnd);
+ break;
+
+ case UM_INITPOPUP:
+ //struct CONNECTON *conn=NULL;
+ //conn = (struct CONNECTION*)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd,(LPARAM)conn);
+ //MessageBox(NULL,conn->extIp);
+ //PUDeletePopUp(hWnd);
+ break;
+
+ case UM_FREEPLUGINDATA:
+ struct CONNECTION *mpd = (struct CONNECTION*)PUGetPluginData(hWnd);
+ if (mpd > 0) mir_free(mpd);
+ return TRUE; //TRUE or FALSE is the same, it gets ignored.
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
@@ -859,19 +804,16 @@ void showMsg(TCHAR *pName, DWORD pid,TCHAR *intIp,TCHAR *extIp,int intPort,int e
ZeroMemory(&ppd, sizeof(ppd)); //This is always a good thing to do.
ppd.lchContact = NULL;//(HANDLE)hContact; //Be sure to use a GOOD handle, since this will not be checked.
ppd.lchIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
- if(settingResolveIp)
- {
+ if (settingResolveIp) {
TCHAR hostName[128];
- getDnsName(extIp,hostName);
+ getDnsName(extIp, hostName, SIZEOF(hostName));
mir_sntprintf(ppd.lptzText,MAX_SECONDLINE,_T("%s:%d\n%s:%d"),hostName,extPort,intIp,intPort);
}
- else
- mir_sntprintf(ppd.lptzText,MAX_SECONDLINE,_T("%s:%d\n%s:%d"),extIp,extPort,intIp,intPort);
+ else mir_sntprintf(ppd.lptzText,MAX_SECONDLINE,_T("%s:%d\n%s:%d"),extIp,extPort,intIp,intPort);
mir_sntprintf(ppd.lptzContactName,MAX_CONTACTNAME,_T("%s (%s)"),pName,tcpStates[state-1]);
- //lstrcpy(ppd.lpzText, text);
- if(settingSetColours)
- {
+
+ if (settingSetColours) {
ppd.colorBack = settingBgColor;
ppd.colorText = settingFgColor;
}
@@ -884,10 +826,7 @@ void showMsg(TCHAR *pName, DWORD pid,TCHAR *intIp,TCHAR *extIp,int intPort,int e
mir_sntprintf(mpd->PName,_countof(mpd->PName),_T("%s"),pName);
mpd->intIntPort = intPort;
mpd->intExtPort = extPort;
- mpd->Pid=pid;
-
-
- //mpd->newStatus = ID_STATUS_ONLINE;
+ mpd->Pid = pid;
//Now that the plugin data has been filled, we add it to the PopUpData.
ppd.PluginData = mpd;
@@ -896,8 +835,6 @@ void showMsg(TCHAR *pName, DWORD pid,TCHAR *intIp,TCHAR *extIp,int intPort,int e
PUAddPopupT(&ppd);
}
-
-
//called after all plugins loaded.
//all Connection staff will be called, that will not hang miranda on startup
static int modulesloaded(WPARAM,LPARAM)
@@ -986,16 +923,16 @@ extern "C" int __declspec(dllexport) Load(void)
extern "C" int __declspec(dllexport) Unload(void)
{
WaitForSingleObjectEx(hConnectionCheckThread, INFINITE, FALSE);
- if(hConnectionCheckThread )CloseHandle(hConnectionCheckThread);
- if(hCheckEvent)DestroyHookableEvent(hCheckEvent);
+ if (hConnectionCheckThread )CloseHandle(hConnectionCheckThread);
+ if (hCheckEvent)DestroyHookableEvent(hCheckEvent);
if (hOptInit) UnhookEvent(hOptInit);
if (hCheckHook)UnhookEvent(hCheckHook);
- if(hHookModulesLoaded)UnhookEvent(hHookModulesLoaded);
- if(hHookPreShutdown)UnhookEvent(hHookPreShutdown);
- if(killCheckThreadEvent)
+ if (hHookModulesLoaded)UnhookEvent(hHookModulesLoaded);
+ if (hHookPreShutdown)UnhookEvent(hHookPreShutdown);
+ if (killCheckThreadEvent)
CloseHandle(killCheckThreadEvent);
- //if(hCurrentEditMutex) CloseHandle(hCurrentEditMutex);
- if(hExceptionsMutex) CloseHandle(hExceptionsMutex);
+ //if (hCurrentEditMutex) CloseHandle(hCurrentEditMutex);
+ if (hExceptionsMutex) CloseHandle(hExceptionsMutex);
#ifdef _DEBUG
_OutputDebugString(_T("Unloaded"));
diff --git a/plugins/ConnectionNotify/src/ConnectionNotify.h b/plugins/ConnectionNotify/src/ConnectionNotify.h
index 75b64b0148..7480c5b38f 100644
--- a/plugins/ConnectionNotify/src/ConnectionNotify.h
+++ b/plugins/ConnectionNotify/src/ConnectionNotify.h
@@ -1,3 +1,5 @@
+#define _CRT_SECURE_NO_WARNINGS
+
#include <windows.h>
#include <Commctrl.h>
#include <assert.h>
diff --git a/plugins/ConnectionNotify/src/debug.cpp b/plugins/ConnectionNotify/src/debug.cpp
index 0400b3a673..2af13f218c 100644
--- a/plugins/ConnectionNotify/src/debug.cpp
+++ b/plugins/ConnectionNotify/src/debug.cpp
@@ -2,71 +2,63 @@
void _OutputDebugString(TCHAR* lpOutputString, ... )
{
- TCHAR OutMsg[MAX_LENGTH];
- TCHAR format[MAX_LENGTH];
+ TCHAR OutMsg[MAX_LENGTH];
+ TCHAR format[MAX_LENGTH];
int i,j;
- va_list argptr;
-
- va_start( argptr, lpOutputString );
-
+ va_list argptr;
-
- for(i=0,j=0;lpOutputString[i] != '\0';i++)
- {
- format[j++] = lpOutputString[i];
+ va_start( argptr, lpOutputString );
+
+
+
+ for(i=0,j=0;lpOutputString[i] != '\0';i++)
+ {
+ format[j++] = lpOutputString[i];
+ format[j] = '\0';
+
+ if (lpOutputString[i] != '%')
+ continue;
+
+ format[j++] = lpOutputString[++i];
format[j] = '\0';
- // If escape character
- //if(lpOutputString[i] == '\\')
- //{
- // i++;
- // continue;
- //}
- // if not a substitutal character
- if(lpOutputString[i] != '%')
- continue;
-
- format[j++] = lpOutputString[++i];
- format[j] = '\0';
- switch(lpOutputString[i])
- {
- // string
- case 's':
- {
- TCHAR* s = va_arg( argptr, TCHAR * );
- mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, s);
- _tcsncpy(format,OutMsg,_countof(OutMsg));
- j = _tcslen(format);
- _tcscat(format,_T(" "));
- break;
- }
- // character
- case 'c':
- {
- char c = (char) va_arg( argptr, int );
- mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, c);
- _tcsncpy(format,OutMsg,_countof(OutMsg));
- j = _tcslen(format);
- _tcscat(format,_T(" "));
- break;
- }
- // integer
- case 'd':
- {
- int d = va_arg( argptr, int );
- mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, d);
- _tcsncpy(format,OutMsg,_countof(OutMsg));
- j = _tcslen(format);
- _tcscat(format,_T(" "));
- break;
- }
- }
+ switch(lpOutputString[i])
+ {
+ // string
+ case 's':
+ {
+ TCHAR* s = va_arg( argptr, TCHAR * );
+ mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, s);
+ _tcsncpy(format,OutMsg,_countof(OutMsg));
+ j = (int)_tcslen(format);
+ _tcscat(format,_T(" "));
+ break;
+ }
+ // character
+ case 'c':
+ {
+ char c = (char) va_arg( argptr, int );
+ mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, c);
+ _tcsncpy(format,OutMsg,_countof(OutMsg));
+ j = (int)_tcslen(format);
+ _tcscat(format,_T(" "));
+ break;
+ }
+ // integer
+ case 'd':
+ {
+ int d = va_arg( argptr, int );
+ mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, d);
+ _tcsncpy(format,OutMsg,_countof(OutMsg));
+ j = (int)_tcslen(format);
+ _tcscat(format,_T(" "));
+ break;
+ }
+ }
format[j+1] = '\0';
- }
+ }
_tcscat(format,_T("\n"));
- OutputDebugString(format);
+ OutputDebugString(format);
- va_end( argptr );
+ va_end( argptr );
}
-
-
diff --git a/plugins/ConnectionNotify/src/filter.cpp b/plugins/ConnectionNotify/src/filter.cpp
index 50defeb1d7..2570826157 100644
--- a/plugins/ConnectionNotify/src/filter.cpp
+++ b/plugins/ConnectionNotify/src/filter.cpp
@@ -33,7 +33,7 @@ static unsigned __stdcall filterQueue(void *dummy)
//while(1)
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
- if(msg.message==WM_ADD_FILTER )
+ if (msg.message==WM_ADD_FILTER )
{
struct CONNECTION *conn=(struct CONNECTION *)msg.lParam;
filterAddDlg=CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILTER_DIALOG), NULL, ConnectionFilterEditProc,(LPARAM)conn);
@@ -87,7 +87,7 @@ static INT_PTR CALLBACK ConnectionFilterEditProc(HWND hWnd, UINT message, WPARAM
MessageBox(hWnd,TranslateT("First close options window"),_T("ConnectionNotify"),MB_OK | MB_ICONSTOP);
break;
}
- if( WAIT_OBJECT_0 == WaitForSingleObject( hExceptionsMutex, 100 ) )
+ if ( WAIT_OBJECT_0 == WaitForSingleObject( hExceptionsMutex, 100 ))
{
if (connCurrentEdit==NULL)
{
@@ -145,7 +145,7 @@ BOOL checkFilter(struct CONNECTION *head,struct CONNECTION *conn)
struct CONNECTION *cur=head;
while(cur!=NULL)
{
- if(wildcmp(cur->PName,conn->PName)&&wildcmp(cur->strIntIp,conn->strIntIp)&&wildcmp(cur->strExtIp,conn->strExtIp)&&(cur->intIntPort==-1||cur->intIntPort==conn->intIntPort)&&(cur->intExtPort==-1||cur->intExtPort==conn->intExtPort))
+ if (wildcmp(cur->PName,conn->PName)&&wildcmp(cur->strIntIp,conn->strIntIp)&&wildcmp(cur->strExtIp,conn->strExtIp)&&(cur->intIntPort==-1||cur->intIntPort==conn->intIntPort)&&(cur->intExtPort==-1||cur->intExtPort==conn->intExtPort))
return cur->Pid;
cur=cur->next;
}
diff --git a/plugins/ConnectionNotify/src/netstat.cpp b/plugins/ConnectionNotify/src/netstat.cpp
index 36a8302571..ae813c9d1d 100644
--- a/plugins/ConnectionNotify/src/netstat.cpp
+++ b/plugins/ConnectionNotify/src/netstat.cpp
@@ -45,14 +45,14 @@ struct CONNECTION* GetConnectionsTable()
memset(newConn,0,sizeof(struct CONNECTION));
//pid2name(pTcpTable->table[i].dwOwningPid,&newConn->Pname);
- if(pTcpTable->table[i].dwLocalAddr)
+ if (pTcpTable->table[i].dwLocalAddr)
{
IpAddr.S_un.S_addr = (ULONG) pTcpTable->table[i].dwLocalAddr;
//_snprintf(newConn->strIntIp,_countof(newConn->strIntIp),"%d.%d.%d.%d",IpAddr.S_un.S_un_b.s_b1,IpAddr.S_un.S_un_b.s_b2,IpAddr.S_un.S_un_b.s_b3,IpAddr.S_un.S_un_b.s_b4);
wcsncpy(newConn->strIntIp, mir_a2t(inet_ntoa(IpAddr)),_tcslen(mir_a2t(inet_ntoa(IpAddr))));
}
- if(pTcpTable->table[i].dwRemoteAddr)
+ if (pTcpTable->table[i].dwRemoteAddr)
{
IpAddr.S_un.S_addr = (u_long) pTcpTable->table[i].dwRemoteAddr;
wcsncpy(newConn->strExtIp, mir_a2t(inet_ntoa(IpAddr)),_tcslen(mir_a2t(inet_ntoa(IpAddr))));
@@ -147,27 +147,19 @@ struct CONNECTION* searchConnection(struct CONNECTION* head,TCHAR *intIp,TCHAR *
struct CONNECTION *cur=head;
while(cur!=NULL)
{
- if(wcscmp(cur->strIntIp,intIp)==0 && wcscmp(cur->strExtIp,extIp)==0 && cur->intExtPort==extPort && cur->intIntPort==intPort && cur->state==state)
+ if (wcscmp(cur->strIntIp,intIp)==0 && wcscmp(cur->strExtIp,extIp)==0 && cur->intExtPort==extPort && cur->intIntPort==intPort && cur->state==state)
return cur;
cur=cur->next;
}
return NULL;
}
-void getDnsName(TCHAR *strIp,TCHAR *strHostName)
+void getDnsName(TCHAR *strIp, TCHAR *strHostName, size_t len)
{
- struct in_addr iaHost;
- struct hostent *h;
-
+ in_addr iaHost;
iaHost.s_addr = inet_addr(mir_t2a(strIp));
- if ((h = gethostbyaddr ((char *)&iaHost, sizeof(struct in_addr), AF_INET))== NULL)
- { // get the host info error
- _stprintf(strHostName,_T("%s"), strIp); //!!!!!!!!!!!
- return;
- }
- _stprintf(strHostName,_T("%s"),mir_a2t(h->h_name)); //!!!!!!!!!!!!!
- //_tcsncpy_s(strHostName,128, h->h_name,_tcslen(h->h_name));
-
+ hostent *h = gethostbyaddr((char *)&iaHost, sizeof(struct in_addr), AF_INET);
+ _tcsncpy_s(strHostName, len, (h == NULL) ? strIp : _A2T(h->h_name), _TRUNCATE);
}
int wildcmp(const TCHAR *wild, const TCHAR *string) {
diff --git a/plugins/ConnectionNotify/src/netstat.h b/plugins/ConnectionNotify/src/netstat.h
index ccabf3df4b..fdd0908a72 100644
--- a/plugins/ConnectionNotify/src/netstat.h
+++ b/plugins/ConnectionNotify/src/netstat.h
@@ -17,5 +17,5 @@ struct CONNECTION
struct CONNECTION* GetConnectionsTable();
void deleteConnectionsTable(struct CONNECTION* head);
struct CONNECTION* searchConnection(struct CONNECTION* head,TCHAR *intIp,TCHAR *extIp,int intPort,int extPort,int state);
-void getDnsName(TCHAR *strIp,TCHAR *strHostName);
+void getDnsName(TCHAR *strIp, TCHAR *strHostName, size_t len);
int wildcmp(const TCHAR *wild, const TCHAR *string); \ No newline at end of file
diff --git a/plugins/ConnectionNotify/src/pid2name.cpp b/plugins/ConnectionNotify/src/pid2name.cpp
index e3365a574f..60dba4d241 100644
--- a/plugins/ConnectionNotify/src/pid2name.cpp
+++ b/plugins/ConnectionNotify/src/pid2name.cpp
@@ -1,111 +1,24 @@
#include "ConnectionNotify.h"
-void pid2name(DWORD procid,TCHAR* buffer)
+void pid2name(DWORD procid, TCHAR *buffer, size_t bufLen)
{
- HANDLE hSnap = INVALID_HANDLE_VALUE;
- HANDLE hProcess = INVALID_HANDLE_VALUE;
- PROCESSENTRY32 ProcessStruct;
- ProcessStruct.dwSize = sizeof(PROCESSENTRY32);
- hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if(hSnap == INVALID_HANDLE_VALUE)
- return;
- if(Process32First(hSnap, &ProcessStruct) == FALSE)
- return;
- do
- {
- if(ProcessStruct.th32ProcessID==procid)
- {
- _stprintf(buffer,_T("%s"),ProcessStruct.szExeFile); //!!!!!!!!!!!!
- break;
- }
- }
- while( Process32Next( hSnap, &ProcessStruct ) );
-
- CloseHandle( hSnap );
-}
-
-/*
-#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
-#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
-
-typedef enum _SYSTEM_INFORMATION_CLASS {
- SystemProcessInformation = 5
-} SYSTEM_INFORMATION_CLASS;
-
-typedef struct _UNICODE_STRING {
- USHORT Length;
- USHORT MaximumLength;
- PWSTR Buffer;
-} UNICODE_STRING;
-
-typedef LONG KPRIORITY; // Thread priority
-
-typedef struct _SYSTEM_PROCESS_INFORMATION_DETAILD {
- ULONG NextEntryOffset;
- ULONG NumberOfThreads;
- LARGE_INTEGER SpareLi1;
- LARGE_INTEGER SpareLi2;
- LARGE_INTEGER SpareLi3;
- LARGE_INTEGER CreateTime;
- LARGE_INTEGER UserTime;
- LARGE_INTEGER KernelTime;
- UNICODE_STRING ImageName;
- KPRIORITY BasePriority;
- HANDLE UniqueProcessId;
- ULONG InheritedFromUniqueProcessId;
- ULONG HandleCount;
- BYTE Reserved4[4];
- PVOID Reserved5[11];
- SIZE_T PeakPagefileUsage;
- SIZE_T PrivatePageCount;
- LARGE_INTEGER Reserved6[6];
-} SYSTEM_PROCESS_INFORMATION_DETAILD, *PSYSTEM_PROCESS_INFORMATION_DETAILD;
-
-typedef NTSTATUS (WINAPI *PFN_NT_QUERY_SYSTEM_INFORMATION)(
- IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
- IN OUT PVOID SystemInformation,
- IN ULONG SystemInformationLength,
- OUT OPTIONAL PULONG ReturnLength
-);
-
-void pid2name(DWORD procid,TCHAR* buffer)
-{
- size_t bufferSize = 102400;
- PSYSTEM_PROCESS_INFORMATION_DETAILD pspid=(PSYSTEM_PROCESS_INFORMATION_DETAILD) malloc (bufferSize);
- ULONG ReturnLength;
- PFN_NT_QUERY_SYSTEM_INFORMATION pfnNtQuerySystemInformation = (PFN_NT_QUERY_SYSTEM_INFORMATION)GetProcAddress (GetModuleHandle(TEXT("ntdll.dll")), "NtQuerySystemInformation");
- NTSTATUS status;
-
- while (TRUE)
- {
- status = pfnNtQuerySystemInformation (SystemProcessInformation, (PVOID)pspid, bufferSize, &ReturnLength);
- if (status == STATUS_SUCCESS)
- break;
- else if (status != STATUS_INFO_LENGTH_MISMATCH)
- { // 0xC0000004L
- //_tprintf (TEXT("ERROR 0x%X\n"), status);
- goto error_block;
- }
-
- bufferSize *= 2;
- pspid = (PSYSTEM_PROCESS_INFORMATION_DETAILD) realloc ((PVOID)pspid, bufferSize);
- }
-
- for (;;pspid=(PSYSTEM_PROCESS_INFORMATION_DETAILD)(pspid->NextEntryOffset + (PBYTE)pspid)) {
- if (pspid->UniqueProcessId == (HANDLE)procid)
- {
- _stprintf(buffer,"%ls",pspid->ImageName.Buffer);
+ HANDLE hSnap = INVALID_HANDLE_VALUE;
+ HANDLE hProcess = INVALID_HANDLE_VALUE;
+ PROCESSENTRY32 ProcessStruct;
+ ProcessStruct.dwSize = sizeof(PROCESSENTRY32);
+ hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+ if (hSnap == INVALID_HANDLE_VALUE)
+ return;
+ if (Process32First(hSnap, &ProcessStruct) == FALSE)
+ return;
+
+ do {
+ if (ProcessStruct.th32ProcessID == procid) {
+ _tcsncpy_s(buffer, bufLen, ProcessStruct.szExeFile, _TRUNCATE);
break;
}
- //_tprintf (TEXT("ProcessId: %d, ImageFileName: %ls\n"), pspid->UniqueProcessId,(pspid->ImageName.Length && pspid->ImageName.Buffer)? pspid->ImageName.Buffer: L"");
- if (pspid->NextEntryOffset == 0) break;
- }
-error_block:
-if (pspid!=NULL)
-{
- free(pspid);
- pspid=NULL;
-}
-return;
+ }
+ while( Process32Next( hSnap, &ProcessStruct ));
+
+ CloseHandle( hSnap );
}
-*/ \ No newline at end of file
diff --git a/plugins/ConnectionNotify/src/pid2name.h b/plugins/ConnectionNotify/src/pid2name.h
index a3e46fca25..d1e7609f10 100644
--- a/plugins/ConnectionNotify/src/pid2name.h
+++ b/plugins/ConnectionNotify/src/pid2name.h
@@ -3,6 +3,6 @@
#ifndef _INC_PID2NAME
#define _INC_PID2NAME
-void pid2name(DWORD,TCHAR* );
+void pid2name(DWORD, TCHAR*, size_t);
#endif