Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

376 lines
8.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. pgnetwk.cpp
  7. Implemenation of CPgNetworking -- property page to edit
  8. profile attributes related to inter-networking
  9. FILE HISTORY:
  10. */
  11. // PgNetwk.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. // #include "dlgfilt.h"
  16. #include "PgNetwk.h"
  17. #include "hlptable.h"
  18. #include "mprapi.h"
  19. #include "std.h"
  20. #include "mprsnap.h"
  21. #include "infobase.h"
  22. #include "router.h"
  23. #include "mprfltr.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CPgNetworkingMerge property page
  31. IMPLEMENT_DYNCREATE(CPgNetworkingMerge, CManagedPage)
  32. CPgNetworkingMerge::CPgNetworkingMerge(CRASProfileMerge* profile)
  33. : CManagedPage(CPgNetworkingMerge::IDD),
  34. m_pProfile(profile),
  35. m_bInited(false),
  36. m_dwStaticIP(0)
  37. {
  38. //{{AFX_DATA_INIT(CPgNetworkingMerge)
  39. m_nRadioStatic = -1;
  40. //}}AFX_DATA_INIT
  41. m_pBox = NULL;
  42. m_nFiltersSize = 0;
  43. if(!(m_pProfile->m_dwAttributeFlags & PABF_msRADIUSFramedIPAddress)) // not defined in policy
  44. {
  45. m_nRadioStatic = 2;
  46. }
  47. else
  48. {
  49. m_dwStaticIP = m_pProfile->m_dwFramedIPAddress;
  50. switch(m_dwStaticIP)
  51. {
  52. case RAS_IP_USERSELECT:
  53. m_nRadioStatic = 1;
  54. break;
  55. case RAS_IP_SERVERASSIGN:
  56. m_nRadioStatic = 0;
  57. break;
  58. default:
  59. m_nRadioStatic = 3;
  60. break;
  61. }
  62. }
  63. // filters
  64. if((BSTR)m_pProfile->m_cbstrFilters)
  65. {
  66. m_cbstrFilters.AssignBSTR(m_pProfile->m_cbstrFilters);
  67. }
  68. SetHelpTable(g_aHelpIDs_IDD_NETWORKING_MERGE);
  69. }
  70. CPgNetworkingMerge::~CPgNetworkingMerge()
  71. {
  72. delete m_pBox;
  73. }
  74. void CPgNetworkingMerge::DoDataExchange(CDataExchange* pDX)
  75. {
  76. ASSERT(m_pProfile);
  77. CPropertyPage::DoDataExchange(pDX);
  78. //{{AFX_DATA_MAP(CPgNetworkingMerge)
  79. DDX_Radio(pDX, IDC_RADIOSERVER, m_nRadioStatic);
  80. //}}AFX_DATA_MAP
  81. if(pDX->m_bSaveAndValidate) // save data to this class
  82. {
  83. // ip adress control
  84. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_GETADDRESS, 0, (LPARAM)&m_dwStaticIP);
  85. }
  86. else // put to dialog
  87. {
  88. // ip adress control
  89. if(m_bInited)
  90. {
  91. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_SETADDRESS, 0, m_dwStaticIP);
  92. }
  93. else
  94. {
  95. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_CLEARADDRESS, 0, m_dwStaticIP);
  96. }
  97. }
  98. }
  99. BEGIN_MESSAGE_MAP(CPgNetworkingMerge, CPropertyPage)
  100. //{{AFX_MSG_MAP(CPgNetworkingMerge)
  101. ON_BN_CLICKED(IDC_RADIOCLIENT, OnRadioclient)
  102. ON_BN_CLICKED(IDC_RADIOSERVER, OnRadioserver)
  103. ON_WM_HELPINFO()
  104. ON_WM_CONTEXTMENU()
  105. ON_BN_CLICKED(IDC_RADIODEFAULT, OnRadiodefault)
  106. ON_BN_CLICKED(IDC_RADIOSTATIC, OnRadioStatic)
  107. ON_BN_CLICKED(IDC_BUTTON_TOCLIENT, OnButtonToclient)
  108. ON_BN_CLICKED(IDC_BUTTON_FROMCLIENT, OnButtonFromclient)
  109. ON_EN_CHANGE(IDC_EDIT_STATIC_IP_ADDRESS, OnStaticIPAddressChanged)
  110. //}}AFX_MSG_MAP
  111. END_MESSAGE_MAP()
  112. // ON_NOTIFY(EN_CHANGE, IDC_EDIT_STATIC_IP_ADDRESS, OnStaticIPAddressChanged)
  113. // ON_BN_CLICKED(IDC_EDIT_STATIC_IP_ADDRESS, OnStaticIPAddress)
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CPgNetworking message handlers
  116. BOOL CPgNetworkingMerge::OnInitDialog()
  117. {
  118. // necessary?
  119. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  120. CPropertyPage::OnInitDialog();
  121. m_bInited = true;
  122. // tperraut HACK should be replaced by a proper init of the control
  123. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  124. if (IPWnd != NULL)
  125. {
  126. IPWnd->EnableWindow(TRUE);
  127. }
  128. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_SETADDRESS, 0, m_dwStaticIP);
  129. if (m_nRadioStatic == 3)
  130. {
  131. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  132. if (IPWnd != NULL)
  133. {
  134. IPWnd->EnableWindow(TRUE);
  135. }
  136. }
  137. else
  138. {
  139. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  140. if (IPWnd != NULL)
  141. {
  142. IPWnd->EnableWindow(FALSE);
  143. }
  144. }
  145. return TRUE; // return TRUE unless you set the focus to a control
  146. // EXCEPTION: OCX Property Pages should return FALSE
  147. }
  148. void CPgNetworkingMerge::OnRadioclient()
  149. {
  150. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  151. if (IPWnd != NULL)
  152. {
  153. IPWnd->EnableWindow(FALSE);
  154. }
  155. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_SETADDRESS, 0, m_dwStaticIP);
  156. SetModified();
  157. }
  158. void CPgNetworkingMerge::OnRadioserver()
  159. {
  160. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  161. if (IPWnd != NULL)
  162. {
  163. IPWnd->EnableWindow(FALSE);
  164. }
  165. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_SETADDRESS, 0, m_dwStaticIP);
  166. SetModified();
  167. }
  168. void CPgNetworkingMerge::OnRadiodefault()
  169. {
  170. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  171. if (IPWnd != NULL)
  172. {
  173. IPWnd->EnableWindow(FALSE);
  174. }
  175. SetModified();
  176. }
  177. void CPgNetworkingMerge::OnRadioStatic()
  178. {
  179. if (m_bInited)
  180. {
  181. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  182. if (IPWnd != NULL)
  183. {
  184. IPWnd->EnableWindow(TRUE);
  185. }
  186. }
  187. SetModified();
  188. }
  189. void CPgNetworkingMerge::OnStaticIPAddressChanged()
  190. {
  191. SetModified();
  192. }
  193. void CPgNetworkingMerge::EnableFilterSettings(BOOL bEnable)
  194. {
  195. m_pBox->Enable(bEnable);
  196. }
  197. BOOL CPgNetworkingMerge::OnApply()
  198. {
  199. if (!GetModified()) return TRUE;
  200. // get the IP policy value
  201. switch(m_nRadioStatic)
  202. {
  203. // tperraut: check what kind of IP first?
  204. case 3:
  205. {
  206. m_pProfile->m_dwAttributeFlags |= PABF_msRADIUSFramedIPAddress;
  207. m_pProfile->m_dwFramedIPAddress = m_dwStaticIP;
  208. break;
  209. }
  210. case 2: // default server settings
  211. {
  212. m_pProfile->m_dwFramedIPAddress = 0;
  213. m_pProfile->m_dwAttributeFlags &= ~PABF_msRADIUSFramedIPAddress; // not defined in policy
  214. break;
  215. }
  216. case 1: // client requre
  217. {
  218. m_pProfile->m_dwAttributeFlags |= PABF_msRADIUSFramedIPAddress;
  219. m_pProfile->m_dwFramedIPAddress = RAS_IP_USERSELECT;
  220. break; // server assign
  221. }
  222. case 0:
  223. {
  224. m_pProfile->m_dwAttributeFlags |= PABF_msRADIUSFramedIPAddress;
  225. m_pProfile->m_dwFramedIPAddress = RAS_IP_SERVERASSIGN;
  226. break;
  227. }
  228. default:
  229. {
  230. // assert ?
  231. break;
  232. }
  233. }
  234. // filters
  235. m_pProfile->m_cbstrFilters.AssignBSTR((BSTR)m_cbstrFilters);
  236. m_pProfile->m_nFiltersSize = m_nFiltersSize;
  237. return CManagedPage::OnApply();
  238. }
  239. BOOL CPgNetworkingMerge::OnHelpInfo(HELPINFO* pHelpInfo)
  240. {
  241. return CManagedPage::OnHelpInfo(pHelpInfo);
  242. }
  243. void CPgNetworkingMerge::OnContextMenu(CWnd* pWnd, CPoint point)
  244. {
  245. CManagedPage::OnContextMenu(pWnd, point);
  246. }
  247. void CPgNetworkingMerge::OnButtonToclient()
  248. {
  249. // Create Info base,
  250. SPIInfoBase spInfoBase;
  251. HRESULT hr = S_OK;
  252. PBYTE pByte = NULL;
  253. SAFEARRAY* pSA = NULL;
  254. DWORD size = 0;
  255. CHECK_HR( hr = CreateInfoBase(&spInfoBase) );
  256. size = m_cbstrFilters.ByteLen();
  257. pByte = (PBYTE)(BSTR)m_cbstrFilters;
  258. if(size && pByte)
  259. {
  260. CHECK_HR(hr = spInfoBase->LoadFrom(size, pByte));
  261. }
  262. pByte = NULL;
  263. // call API to bring up the UI to edit filter
  264. CHECK_HR( hr = MprUIFilterConfigInfoBase(GetSafeHwnd(), spInfoBase, NULL, PID_IP, FILTER_TO_USER));
  265. if(hr == S_OK)
  266. {
  267. int iBlocks = 0;
  268. spInfoBase->GetInfo(&size, &iBlocks);
  269. CHECK_HR( hr = spInfoBase->WriteTo(&pByte, &size));
  270. m_cbstrFilters.AssignBlob((const char*)pByte, size);
  271. m_nFiltersSize = size;
  272. SetModified();
  273. }
  274. // if user chooses OK, then set back the value, and set dirty bit
  275. L_ERR:
  276. CoTaskMemFree(pByte);
  277. return;
  278. }
  279. void CPgNetworkingMerge::OnButtonFromclient()
  280. {
  281. // Create Info base,
  282. SPIInfoBase spInfoBase;
  283. HRESULT hr = S_OK;
  284. PBYTE pByte = NULL;
  285. DWORD size = 0;
  286. CHECK_HR( hr = CreateInfoBase(&spInfoBase) );
  287. size = m_cbstrFilters.ByteLen();
  288. pByte = (PBYTE)(BSTR)m_cbstrFilters;
  289. if(size && pByte)
  290. {
  291. CHECK_HR(hr = spInfoBase->LoadFrom(size, pByte));
  292. }
  293. pByte = NULL;
  294. // call API to bring up the UI to edit filter
  295. CHECK_HR( hr = MprUIFilterConfigInfoBase(GetSafeHwnd(), spInfoBase, NULL, PID_IP, FILTER_FROM_USER));
  296. if(hr == S_OK)
  297. {
  298. int iBlocks = 0;
  299. spInfoBase->GetInfo(&size, &iBlocks);
  300. CHECK_HR( hr = spInfoBase->WriteTo(&pByte, &size));
  301. m_cbstrFilters.AssignBlob((const char*)pByte, size);
  302. m_nFiltersSize = size;
  303. SetModified();
  304. }
  305. // if user chooses OK, then set back the value, and set dirty bit
  306. L_ERR:
  307. CoTaskMemFree(pByte);
  308. return;
  309. }