PacketMonitor.cpp
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:5k
开发平台:

Visual C++

  1. // PacketMonitor.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Property.h"
  5. #include "PacketMonitor.h"
  6. //owner add
  7. #include "GuiRes.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. //=============================================================================================
  14. // CPacketMonitor property page
  15. extern CAclFile m_AclFile;
  16. extern CPropertyApp theApp;
  17. BOOL CPacketMonitor::IsScroll = TRUE;
  18. BOOL CPacketMonitor::IsMonitor = TRUE;
  19. CListCtrl *CPacketMonitor::m_pListPacketMonitor = NULL;
  20. IMPLEMENT_DYNCREATE(CPacketMonitor, CPropertyPage)
  21. CPacketMonitor::CPacketMonitor() : CPropertyPage(CPacketMonitor::IDD)
  22. {
  23. }
  24. CPacketMonitor::~CPacketMonitor()
  25. {
  26. }
  27. void CPacketMonitor::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CPropertyPage::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CPacketMonitor)
  31. DDX_Control(pDX, IDC_LIST_PACKET_MONITOR, m_ListPacketMonitor);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CPacketMonitor, CPropertyPage)
  35. //{{AFX_MSG_MAP(CPacketMonitor)
  36. ON_BN_CLICKED(IDC_BUTTON_MONITOR, OnButtonMonitor)
  37. ON_BN_CLICKED(IDC_BUTTON_SCROLL, OnButtonScroll)
  38. ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. //=============================================================================================
  42. // CPacketMonitor message handlers
  43. BOOL CPacketMonitor::OnInitDialog() 
  44. {
  45. CPropertyPage::OnInitDialog();
  46. InitDlgResource();
  47. return TRUE;  
  48. }
  49. //---------------------------------------------------------------------------------------------
  50. //initialize dialog's resource
  51. void CPacketMonitor::InitDlgResource()
  52. {
  53. SetDlgItemText(IDC_PACKET_MONITOR_LABLE, GUI_PACKET_MONITOR_LABLE);
  54. SetDlgItemText(IDC_BUTTON_SCROLL, GUI_PACKET_MONITOR_TOOLBAR_STOP_SCROLL);
  55. SetDlgItemText(IDC_BUTTON_MONITOR, GUI_PACKET_MONITOR_TOOLBAR_STOP_MONITOR);
  56. SetDlgItemText(IDC_BUTTON_CLEAR, GUI_PACKET_MONITOR_TOOLBAR_CLEAR);
  57. m_pListPacketMonitor = &m_ListPacketMonitor;
  58. InitList(&m_ListPacketMonitor);
  59. }
  60. //=============================================================================================
  61. // static function
  62. void CPacketMonitor::InitList(CListCtrl *mList)
  63. {
  64. ListView_SetExtendedListViewStyle(
  65. mList->m_hWnd, 
  66. LVS_EX_GRIDLINES  | LVS_EX_FULLROWSELECT
  67. ); 
  68. mList->InsertColumn(0, GUI_PACKET_MONITOR_LIST_ACTION,
  69. LVCFMT_LEFT,
  70. GUI_PACKET_MONITOR_LIST_ACTION_SIZE 
  71. );
  72. mList->InsertColumn(1, GUI_PACKET_MONITOR_LIST_STARTTIME_ENDTIME,
  73. LVCFMT_LEFT,
  74. GUI_PACKET_MONITOR_LIST_STARTTIME_ENDTIME_SIZE + 2
  75. );
  76. mList->InsertColumn(2, GUI_PACKET_MONITOR_LIST_PROTOCOL,
  77. LVCFMT_LEFT,
  78. GUI_PACKET_MONITOR_LIST_PROTOCOL_SIZE + 10
  79. );
  80. mList->InsertColumn(3, GUI_PACKET_MONITOR_LIST_IN_DATA,
  81. LVCFMT_LEFT,
  82. GUI_PACKET_MONITOR_LIST_IN_DATA_SIZE - 8
  83. );
  84. mList->InsertColumn(4, GUI_PACKET_MONITOR_LIST_OUT_DATA,
  85. LVCFMT_LEFT,
  86. GUI_PACKET_MONITOR_LIST_OUT_DATA_SIZE - 8
  87. );
  88. mList->InsertColumn(5, GUI_PACKET_MONITOR_LIST_IP_PORT,
  89. LVCFMT_LEFT,
  90. GUI_PACKET_MONITOR_LIST_IP_PORT_SIZE + 32
  91. );
  92. mList->InsertColumn(6, GUI_PACKET_MONITOR_LIST_APPLICATION,
  93. LVCFMT_LEFT,
  94. GUI_PACKET_MONITOR_LIST_APPLICATION_SIZE + MAX_PATH * 4
  95. );
  96. }
  97. int CPacketMonitor::InsertOneList(
  98. CListCtrl * mList, 
  99. SESSION *session, 
  100. BOOL mIsAdd, 
  101. BOOL mIsScroll
  102. )
  103. {
  104. if(mList == NULL)
  105. return XERR_LOG_INVALID_LIST;
  106. if(!mIsAdd)
  107. return XERR_LOG_NOT_MONITOR;
  108. if(session == NULL || session->s == 0)
  109. return XERR_LOG_INVALID_SESSION;
  110. CString tmpStr;
  111. int iIndex = mList->GetItemCount();
  112. mList->InsertItem(iIndex, GUI_ACTION[session->bAction]);
  113. tmpStr.Format(_T("%s - %s"),
  114. session->tStartTime.Format(_T("%m/%d %H:%M:%S")),
  115. session->tEndTime.Format(_T("%H:%M:%S"))
  116. );
  117. mList->SetItemText(iIndex, 1, tmpStr);
  118. mList->SetItemText(iIndex, 2, GUI_SERVICE_TYPE[session->bProtocol]);
  119. tmpStr.Format(_T("%u"),
  120. session->ulRecvData
  121. );
  122. mList->SetItemText(iIndex, 3, tmpStr);
  123. tmpStr.Format(_T("%u"),
  124. session->ulSendData
  125. );
  126. mList->SetItemText(iIndex, 4, tmpStr);
  127. tmpStr.Format(_T("%s,%u %s %s,%u"), 
  128. CAclFile::DIPToSIP(&session->ulLocalIP),
  129. session->uiLocalPort,
  130. GUI_DIRECTION_EX[session->bDirection],
  131. CAclFile::DIPToSIP(&session->ulRemoteIP),
  132. session->uiPort
  133. );
  134. mList->SetItemText(iIndex, 5, tmpStr);
  135. tmpStr.Format(_T("%s :: %s"),
  136. session->sPathName,
  137. session->sMemo[0] == '' ? CAclFile::DIPToSIP(&session->ulRemoteIP) : session->sMemo 
  138. );
  139. mList->SetItemText(iIndex, 6, tmpStr);
  140. if(mIsScroll)
  141. mList->EnsureVisible(iIndex, TRUE);
  142. return XERR_SUCCESS;
  143. }
  144. void CPacketMonitor::OnButtonScroll() 
  145. {
  146. IsScroll = !IsScroll;
  147. SetDlgItemText(IDC_BUTTON_SCROLL, IsScroll ? GUI_PACKET_MONITOR_TOOLBAR_STOP_SCROLL 
  148. : GUI_PACKET_MONITOR_TOOLBAR_START_SCROLL);
  149. }
  150. void CPacketMonitor::OnButtonMonitor() 
  151. {
  152. IsMonitor = !IsMonitor;
  153. SetDlgItemText(IDC_BUTTON_MONITOR, IsMonitor ? GUI_PACKET_MONITOR_TOOLBAR_STOP_MONITOR 
  154. : GUI_PACKET_MONITOR_TOOLBAR_START_MONITOR);
  155. }
  156. void CPacketMonitor::OnButtonClear() 
  157. {
  158. m_ListPacketMonitor.DeleteAllItems();
  159. }