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.

1849 lines
44 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: pgpolicy.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // pgpolicy.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include <objsel.h>
  14. #include "helper.h"
  15. #include "acsadmin.h"
  16. #include "acsdata.h"
  17. #include "acshand.h"
  18. #include "pgpolicy.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. void CACSPolicyPageManager::SetPolicyData(CACSPolicyElement* pPolicy, CACSPolicyHandle* pHandle)
  25. {
  26. ASSERT(pPolicy && pHandle);
  27. m_spPolicy = pPolicy;
  28. m_pHandle = pHandle;
  29. if(pHandle)
  30. pHandle->AddRef();
  31. }
  32. CACSPolicyPageManager::~CACSPolicyPageManager()
  33. {
  34. m_spPolicy.Release();
  35. if(m_pHandle)
  36. m_pHandle->Release();
  37. }
  38. BOOL CACSPolicyPageManager::OnApply()
  39. {
  40. if(CPageManager::OnApply())
  41. {
  42. HRESULT hr = S_OK;
  43. ASSERT((CACSPolicyElement*)m_spPolicy);
  44. // check if data is valid ... // to verify cross page data
  45. UserPolicyType PolicyType = UNDEFINED;
  46. if ((m_nBranchFlag & BRANCH_FLAG_GLOBAL) != 0) // may need to alter the text
  47. {
  48. ASSERT(m_pGeneralPage);
  49. if(m_pGeneralPage->IfAnyAuth())
  50. {
  51. PolicyType = GLOBAL_ANY_AUTHENTICATED;
  52. }
  53. else if (m_pGeneralPage->IfAnyUnauth())
  54. {
  55. PolicyType = GLOBAL_ANY_UNAUTHENTICATED;
  56. }
  57. }
  58. UINT ErrorId = m_spPolicy->PreSaveVerifyData(GetFlags(), PolicyType);
  59. if(ErrorId != 0) // not valid
  60. {
  61. // Display error message,
  62. AfxMessageBox(ErrorId);
  63. // Return FALSE
  64. return FALSE;
  65. }
  66. // persist the data into DS
  67. hr = m_spPolicy->Save(GetFlags());
  68. {
  69. CWaitCursor wc;
  70. Sleep(1000);
  71. }
  72. // modifies the state info on UI ( may change states of other conflicted ones
  73. m_spPolicy->InvalidateConflictState();
  74. // inform container to check conflict
  75. if FAILED(hr)
  76. ReportError(hr, IDS_ERR_SAVESUBNETCONFIG, NULL);
  77. else
  78. {
  79. AfxMessageBox(IDS_WRN_POLICY_EFFECTIVE_FROM_NEXT_RSVP);
  80. m_pHandle->UpdateStrings();
  81. m_pHandle->OnPropertyPageApply();
  82. // Advise super class that the apply button has been activated.
  83. CPageManager::OnApply();
  84. }
  85. ClearFlags();
  86. MMCNotify();
  87. return TRUE;
  88. }
  89. return FALSE;
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CPgPolicyGeneral property page
  93. IMPLEMENT_DYNCREATE(CPgPolicyGeneral, CACSPage)
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CPgTraffic message handlers
  96. enum DirectionIndex
  97. {
  98. DIRECTION_SEND,
  99. DIRECTION_RECEIVE,
  100. DIRECTION_SENDRECEIVE
  101. };
  102. enum ServiceTypeIndex
  103. {
  104. SERVICETYPE_ALL,
  105. SERVICETYPE_CONTROLLEDLOAD,
  106. SERVICETYPE_GUARANTEEDSERVICE,
  107. SERVICETYPE_DISABLED
  108. };
  109. enum IdentityTypeIndex
  110. {
  111. IDENTITYTYPE_DEFAULT,
  112. IDENTITYTYPE_UNKNOWN,
  113. IDENTITYTYPE_USER,
  114. IDENTITYTYPE_OU
  115. };
  116. CPgPolicyGeneral::CPgPolicyGeneral() : CACSPage(CPgPolicyGeneral::IDD)
  117. {
  118. DataInit();
  119. }
  120. CPgPolicyGeneral::CPgPolicyGeneral(CACSPolicyElement* pData) : CACSPage(CPgPolicyGeneral::IDD)
  121. {
  122. ASSERT(pData);
  123. m_spData = pData;
  124. DataInit();
  125. }
  126. void CPgPolicyGeneral::DataInit()
  127. {
  128. //{{AFX_DATA_INIT(CPgPolicyGeneral)
  129. m_strOU = _T("");
  130. m_strUser = _T("");
  131. m_nIdentityChoice = -1;
  132. //}}AFX_DATA_INIT
  133. }
  134. CPgPolicyGeneral::~CPgPolicyGeneral()
  135. {
  136. delete m_pDirection;
  137. delete m_pServiceType;
  138. m_aServiceTypes.DeleteAll();
  139. m_aDirections.DeleteAll();
  140. }
  141. void CPgPolicyGeneral::DoDataExchange(CDataExchange* pDX)
  142. {
  143. CACSPage::DoDataExchange(pDX);
  144. //{{AFX_DATA_MAP(CPgPolicyGeneral)
  145. DDX_Control(pDX, IDC_POLICY_GEN_BROWSEUSER, m_buttonUser);
  146. DDX_Control(pDX, IDC_POLICY_GEN_BROWSEOU, m_buttonOU);
  147. DDX_Control(pDX, IDC_POLICY_GEN_EDIT_USER, m_editUser);
  148. DDX_Control(pDX, IDC_POLICY_GEN_EDIT_OU, m_editOU);
  149. DDX_Text(pDX, IDC_POLICY_GEN_EDIT_OU, m_strOU);
  150. DDX_Text(pDX, IDC_POLICY_GEN_EDIT_USER, m_strUser);
  151. DDX_Radio(pDX, IDC_POLICY_GEN_DEFAULTUSER, m_nIdentityChoice);
  152. //}}AFX_DATA_MAP
  153. }
  154. BEGIN_MESSAGE_MAP(CPgPolicyGeneral, CACSPage)
  155. //{{AFX_MSG_MAP(CPgPolicyGeneral)
  156. ON_BN_CLICKED(IDC_POLICY_GEN_BROWSEOU, OnBrowseOU)
  157. ON_BN_CLICKED(IDC_POLICY_GEN_BROWSEUSER, OnBrowseUser)
  158. ON_BN_CLICKED(IDC_POLICY_GEN_UNKNOWNUSER, OnUnknownuser)
  159. ON_BN_CLICKED(IDC_POLICY_GEN_DEFAULTUSER, OnDefaultuser)
  160. ON_BN_CLICKED(IDC_POLICY_GEN_RADIO_OU, OnRadioOu)
  161. ON_BN_CLICKED(IDC_POLICY_GEN_RADIO_USER, OnRadioUser)
  162. ON_EN_CHANGE(IDC_POLICY_GEN_EDIT_OU, OnChangeEditOu)
  163. ON_EN_CHANGE(IDC_POLICY_GEN_EDIT_USER, OnChangeEditUser)
  164. ON_CBN_SELCHANGE(IDC_POLICY_GEN_SERVICELEVEL, OnSelchangeServicelevel)
  165. ON_CBN_SELCHANGE(IDC_POLICY_GEN_DIRECTION, OnSelchangeDirection)
  166. //}}AFX_MSG_MAP
  167. END_MESSAGE_MAP()
  168. /////////////////////////////////////////////////////////////////////////////
  169. // CPgPolicyGeneral message handlers
  170. void CPgPolicyGeneral::OnBrowseOU()
  171. {
  172. TCHAR szRoot[MAX_PATH] = TEXT("");
  173. TCHAR szBuffer[MAX_PATH] = TEXT("");;
  174. DSBROWSEINFO dsbi = { 0 };
  175. CString strTemp;
  176. strTemp.LoadString(IDS_BROWSEOU_TITLE);
  177. // initialize the structure (its already NULL)
  178. dsbi.cbStruct = sizeof(dsbi);
  179. dsbi.hwndOwner = GetSafeHwnd();
  180. dsbi.pszTitle = strTemp;
  181. dsbi.pszRoot = NULL;
  182. dsbi.pszPath = szBuffer;
  183. dsbi.cchPath = sizeof(szBuffer) / sizeof(TCHAR);
  184. dsbi.dwFlags = 0;
  185. dsbi.pfnCallback = NULL;
  186. dsbi.lParam = (LPARAM)0;
  187. dsbi.dwFlags |= DSBI_ENTIREDIRECTORY;
  188. UINT idResult = DsBrowseForContainer(&dsbi);
  189. if ( idResult != IDOK )
  190. return;
  191. m_strOU = szBuffer;
  192. IADs* pADs = NULL;
  193. VARIANT v;
  194. VariantInit(&v);
  195. if(m_strOU.GetLength())
  196. {
  197. m_strOU = _T("");
  198. CHECK_HR(ADsOpenObject(szBuffer, NULL, NULL, ADS_SECURE_AUTHENTICATION | ADS_USE_SIGNING | ADS_USE_SEALING, IID_IADs, (void**)&pADs));
  199. ASSERT(pADs);
  200. CHECK_HR(pADs->Get(L"distinguishedName", &v));
  201. m_strOU = V_BSTR(&v);
  202. m_editOU.SetWindowText(m_strOU);
  203. }
  204. L_ERR:
  205. VariantClear(&v);
  206. if(pADs)
  207. {
  208. pADs->Release();
  209. pADs = NULL;
  210. }
  211. }
  212. //+--------------------------------------------------------------------------
  213. //
  214. // Function: InitObjectPickerForGroups
  215. //
  216. // Synopsis: Call IDsObjectPicker::Initialize with arguments that will
  217. // set it to allow the user to pick one or more groups.
  218. //
  219. // Arguments: [pDsObjectPicker] - object picker interface instance
  220. //
  221. // Returns: Result of calling IDsObjectPicker::Initialize.
  222. //
  223. // History: 10-14-1998 DavidMun Created
  224. //
  225. //---------------------------------------------------------------------------
  226. HRESULT
  227. InitObjectPickerForGroups(IDsObjectPicker *pDsObjectPicker, BOOL fMultiselect)
  228. {
  229. //
  230. // Prepare to initialize the object picker.
  231. // Set up the array of scope initializer structures.
  232. //
  233. static const int SCOPE_INIT_COUNT = 1;
  234. DSOP_SCOPE_INIT_INFO aScopeInit[SCOPE_INIT_COUNT];
  235. ZeroMemory(aScopeInit, sizeof(DSOP_SCOPE_INIT_INFO) * SCOPE_INIT_COUNT);
  236. //
  237. // Target computer scope. This adds a "Look In" entry for the
  238. // target computer. Computer scopes are always treated as
  239. // downlevel (i.e., they use the WinNT provider).
  240. //
  241. aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  242. aScopeInit[0].flType = DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN | DSOP_SCOPE_TYPE_GLOBAL_CATALOG;
  243. aScopeInit[0].flScope = DSOP_SCOPE_FLAG_STARTING_SCOPE;
  244. aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_USERS;
  245. aScopeInit[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_USERS;
  246. DSOP_INIT_INFO InitInfo;
  247. ZeroMemory(&InitInfo, sizeof(InitInfo));
  248. InitInfo.cbSize = sizeof(InitInfo);
  249. //
  250. // The pwzTargetComputer member allows the object picker to be
  251. // retargetted to a different computer. It will behave as if it
  252. // were being run ON THAT COMPUTER.
  253. //
  254. InitInfo.pwzTargetComputer = NULL; // NULL == local machine
  255. InitInfo.cDsScopeInfos = SCOPE_INIT_COUNT;
  256. InitInfo.aDsScopeInfos = aScopeInit;
  257. InitInfo.flOptions = (fMultiselect) ? DSOP_FLAG_MULTISELECT : 0;
  258. LPCTSTR attrs[] = {_T("distinguishedName")};
  259. InitInfo.cAttributesToFetch = 1;
  260. InitInfo.apwzAttributeNames = attrs;
  261. //
  262. // Note object picker makes its own copy of InitInfo. Also note
  263. // that Initialize may be called multiple times, last call wins.
  264. //
  265. HRESULT hr = pDsObjectPicker->Initialize(&InitInfo);
  266. if (FAILED(hr))
  267. {
  268. ULONG i;
  269. for (i = 0; i < SCOPE_INIT_COUNT; i++)
  270. {
  271. if (FAILED(InitInfo.aDsScopeInfos[i].hr))
  272. {
  273. printf("Initialization failed because of scope %u\n", i);
  274. }
  275. }
  276. }
  277. return hr;
  278. }
  279. #define BREAK_ON_FAIL_HRESULT(hr) \
  280. if (FAILED(hr)) { printf("line %u err 0x%x\n", __LINE__, hr); break; }
  281. void CPgPolicyGeneral::OnBrowseUser()
  282. {
  283. HRESULT hr = S_OK;
  284. IDsObjectPicker * pDsObjectPicker = NULL;
  285. IDataObject * pdo = NULL;
  286. BOOL fSuccess = TRUE;
  287. hr = CoInitialize(NULL);
  288. if(FAILED(hr))
  289. return ;
  290. do
  291. {
  292. //
  293. // Create an instance of the object picker. The implementation in
  294. // objsel.dll is apartment model.
  295. //
  296. hr = CoCreateInstance(CLSID_DsObjectPicker,
  297. NULL,
  298. CLSCTX_INPROC_SERVER,
  299. IID_IDsObjectPicker,
  300. (void **) &pDsObjectPicker);
  301. BREAK_ON_FAIL_HRESULT(hr);
  302. hr = InitObjectPickerForGroups(pDsObjectPicker, FALSE);
  303. //
  304. // Invoke the modal dialog.
  305. //
  306. hr = pDsObjectPicker->InvokeDialog(this->GetSafeHwnd(), &pdo);
  307. BREAK_ON_FAIL_HRESULT(hr);
  308. //
  309. // If the user hit Cancel, hr == S_FALSE
  310. //
  311. if (hr == S_FALSE)
  312. {
  313. Trace0("User canceled object picker dialog\n");
  314. fSuccess = FALSE;
  315. break;
  316. }
  317. //
  318. // Process the user's selections
  319. //
  320. Assert(pdo);
  321. // ProcessSelectedObjects(pdo);
  322. {
  323. UINT g_cfDsObjectPicker = RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
  324. STGMEDIUM stgmedium =
  325. {
  326. TYMED_HGLOBAL,
  327. NULL,
  328. NULL
  329. };
  330. FORMATETC formatetc =
  331. {
  332. (unsigned short)g_cfDsObjectPicker,
  333. NULL,
  334. DVASPECT_CONTENT,
  335. -1,
  336. TYMED_HGLOBAL
  337. };
  338. bool fGotStgMedium = false;
  339. do
  340. {
  341. hr = pdo->GetData(&formatetc, &stgmedium);
  342. BREAK_ON_FAIL_HRESULT(hr);
  343. fGotStgMedium = true;
  344. PDS_SELECTION_LIST pDsSelList =
  345. (PDS_SELECTION_LIST) GlobalLock(stgmedium.hGlobal);
  346. // inteprete the selection
  347. ASSERT(pDsSelList->cItems == 1);
  348. ASSERT(pDsSelList->aDsSelection[0].pvarFetchedAttributes[0].vt == VT_BSTR);
  349. if(pDsSelList->aDsSelection[0].pvarFetchedAttributes[0].vt == VT_BSTR)
  350. {
  351. m_strUser = V_BSTR(&(pDsSelList->aDsSelection[0].pvarFetchedAttributes[0]));
  352. // update the edit field of the property page
  353. m_editUser.SetWindowText(m_strUser);
  354. }
  355. else
  356. {
  357. CString str;
  358. str.LoadString(IDS_ERR_DN);
  359. str.Format(str, pDsSelList->aDsSelection[0].pwzName);
  360. AfxMessageBox(str, MB_OK);
  361. }
  362. GlobalUnlock(stgmedium.hGlobal);
  363. } while (0);
  364. if (fGotStgMedium)
  365. {
  366. ReleaseStgMedium(&stgmedium);
  367. }
  368. }
  369. pdo->Release();
  370. pdo = NULL;
  371. } while (0);
  372. if (pDsObjectPicker)
  373. {
  374. pDsObjectPicker->Release();
  375. }
  376. CoUninitialize();
  377. if (FAILED(hr))
  378. fSuccess = FALSE;
  379. return;
  380. }
  381. void CPgPolicyGeneral::OnUnknownuser()
  382. {
  383. // TODO: Add your control notification handler code here
  384. SetModified();
  385. EnableIdentityCtrls(1);
  386. }
  387. void CPgPolicyGeneral::OnDefaultuser()
  388. {
  389. // TODO: Add your control notification handler code here
  390. SetModified();
  391. EnableIdentityCtrls(0);
  392. }
  393. void CPgPolicyGeneral::OnRadioOu()
  394. {
  395. // TODO: Add your control notification handler code here
  396. SetModified();
  397. EnableIdentityCtrls(3);
  398. }
  399. void CPgPolicyGeneral::OnRadioUser()
  400. {
  401. // TODO: Add your control notification handler code here
  402. SetModified();
  403. EnableIdentityCtrls(2);
  404. }
  405. void CPgPolicyGeneral::OnChangeEditOu()
  406. {
  407. // TODO: If this is a RICHEDIT control, the control will not
  408. // send this notification unless you override the CPropertyPage::OnInitDialog()
  409. // function to send the EM_SETEVENTMASK message to the control
  410. // with the ENM_CHANGE flag ORed into the lParam mask.
  411. // TODO: Add your control notification handler code here
  412. SetModified();
  413. }
  414. void CPgPolicyGeneral::OnChangeEditUser()
  415. {
  416. // TODO: If this is a RICHEDIT control, the control will not
  417. // send this notification unless you override the CPropertyPage::OnInitDialog()
  418. // function to send the EM_SETEVENTMASK message to the control
  419. // with the ENM_CHANGE flag ORed into the lParam mask.
  420. // TODO: Add your control notification handler code here
  421. SetModified();
  422. }
  423. void CPgPolicyGeneral::OnSelchangeServicelevel()
  424. {
  425. // TODO: Add your control notification handler code here
  426. SetModified();
  427. }
  428. void CPgPolicyGeneral::OnSelchangeDirection()
  429. {
  430. // TODO: Add your control notification handler code here
  431. SetModified();
  432. }
  433. BOOL CPgPolicyGeneral::OnKillActive( )
  434. {
  435. // GURANTEEDSERVICE and SEND can not be a policy
  436. if(m_pServiceType->GetSelected() == SERVICETYPE_GUARANTEEDSERVICE && m_pDirection->GetSelected() == DIRECTION_SEND)
  437. {
  438. AfxMessageBox(IDS_NO_POLICY_FOR_SEND_AND_GUARANTEE, MB_OK, 0);
  439. return FALSE;
  440. }
  441. return CACSPage::OnKillActive();
  442. }
  443. BOOL CPgPolicyGeneral::OnApply()
  444. {
  445. if(!GetModified()) return TRUE;
  446. // direction
  447. if(m_pDirection)
  448. {
  449. switch(m_pDirection->GetSelected())
  450. {
  451. case DIRECTION_SEND:
  452. m_spData->m_dwDirection = ACS_DIRECTION_SEND;
  453. break;
  454. case DIRECTION_RECEIVE:
  455. m_spData->m_dwDirection = ACS_DIRECTION_RECEIVE;
  456. break;
  457. case DIRECTION_SENDRECEIVE:
  458. m_spData->m_dwDirection = ACS_DIRECTION_BOTH;
  459. break;
  460. default:
  461. // no valid value should come here
  462. ASSERT(0);
  463. }
  464. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_DIRECTION, true);
  465. }
  466. else // save what ever is loaded
  467. {
  468. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_DIRECTION))
  469. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_DIRECTION, true);
  470. else
  471. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_DIRECTION, false);
  472. }
  473. // service type
  474. if(m_pServiceType)
  475. {
  476. switch(m_pServiceType->GetSelected())
  477. {
  478. case SERVICETYPE_DISABLED:
  479. m_spData->m_dwServiceType = ACS_SERVICETYPE_DISABLED;
  480. break;
  481. case SERVICETYPE_CONTROLLEDLOAD:
  482. m_spData->m_dwServiceType = ACS_SERVICETYPE_CONTROLLEDLOAD;
  483. break;
  484. case SERVICETYPE_GUARANTEEDSERVICE:
  485. m_spData->m_dwServiceType = ACS_SERVICETYPE_GUARANTEEDSERVICE;
  486. break;
  487. case SERVICETYPE_ALL:
  488. m_spData->m_dwServiceType = ACS_SERVICETYPE_ALL;
  489. break;
  490. default:
  491. // no valid value should come here
  492. ASSERT(0);
  493. }
  494. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_SERVICETYPE, true);
  495. }
  496. else // save what ever is loaded
  497. {
  498. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_SERVICETYPE))
  499. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_SERVICETYPE, true);
  500. else
  501. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_SERVICETYPE, false);
  502. }
  503. // GURANTEEDSERVICE and SEND can not be a policy
  504. if(m_spData->m_dwServiceType == ACS_SERVICETYPE_GUARANTEEDSERVICE && m_spData->m_dwDirection == ACS_DIRECTION_SEND)
  505. {
  506. AfxMessageBox(IDS_NO_POLICY_FOR_SEND_AND_GUARANTEE, MB_OK, 0);
  507. return FALSE;
  508. }
  509. // ACS_SERVICETYPE_CONTROLLEDLOAD and SEND can not be a policy
  510. if(m_spData->m_dwServiceType == ACS_SERVICETYPE_CONTROLLEDLOAD && m_spData->m_dwDirection == ACS_DIRECTION_SEND)
  511. {
  512. AfxMessageBox(IDS_NO_POLICY_FOR_SEND_AND_CONTROLLEDLOAD, MB_OK, 0);
  513. return FALSE;
  514. }
  515. // code for identity
  516. CString* pIdentity;
  517. if(m_spData->m_strArrayIdentityName.GetSize())
  518. {
  519. pIdentity = m_spData->m_strArrayIdentityName[(INT_PTR)0];
  520. }
  521. else
  522. {
  523. pIdentity = new CString();
  524. m_spData->m_strArrayIdentityName.Add(pIdentity);
  525. }
  526. switch(m_nIdentityChoice)
  527. {
  528. case 0: // default user
  529. *pIdentity = ACS_IDENTITY_DEFAULT;
  530. break;
  531. case 1: // unknown user
  532. *pIdentity = ACS_IDENTITY_UNKNOWN;
  533. break;
  534. case 2: // user
  535. *pIdentity = ACS_IDENTITY_USER;
  536. if(m_strUser.GetLength() == 0)
  537. {
  538. GotoDlgCtrl(&m_editUser);
  539. AfxMessageBox(IDS_ERR_USER_DN);
  540. return FALSE;
  541. }
  542. *pIdentity += m_strUser;
  543. break;
  544. case 3: // OU
  545. *pIdentity = ACS_IDENTITY_OU;
  546. if(m_strOU.GetLength() == 0)
  547. {
  548. GotoDlgCtrl(&m_editOU);
  549. AfxMessageBox(IDS_ERR_OU_DN);
  550. return FALSE;
  551. }
  552. *pIdentity+= m_strOU;
  553. break;
  554. default:
  555. return FALSE;
  556. }
  557. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_IDENTITYNAME, true);
  558. // check if conflict with other policies in the folder
  559. if(m_spData->IsConflictInContainer())
  560. {
  561. if(AfxMessageBox(IDS_CONFLICTPOLICY, MB_OKCANCEL, 0) != IDOK)
  562. {
  563. return FALSE;
  564. }
  565. }
  566. DWORD dwAttrFlags = 0;
  567. dwAttrFlags |= (ACS_PAF_IDENTITYNAME | ACS_PAF_SERVICETYPE | ACS_PAF_DIRECTION);
  568. AddFlags(dwAttrFlags); // prepare flags for saving
  569. return CACSPage::OnApply();
  570. }
  571. BOOL CPgPolicyGeneral::OnInitDialog()
  572. {
  573. CString* pStr = NULL;
  574. bool bModified = false;
  575. // direction
  576. // fillin the list box
  577. try{
  578. pStr = new CString();
  579. pStr->LoadString(IDS_SEND);
  580. m_aDirections.Add(pStr);
  581. pStr = new CString();
  582. pStr->LoadString(IDS_RECEIVE);
  583. m_aDirections.Add(pStr);
  584. pStr = new CString();
  585. pStr->LoadString(IDS_SENDRECEIVE);
  586. m_aDirections.Add(pStr);
  587. m_pDirection = new CStrBox<CComboBox>(this, IDC_POLICY_GEN_DIRECTION, m_aDirections);
  588. m_pDirection->Fill();
  589. // decide which one to select
  590. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_DIRECTION))
  591. {
  592. int current = -1;
  593. switch(m_spData->m_dwDirection)
  594. {
  595. case ACS_DIRECTION_SEND:
  596. current = DIRECTION_SEND;
  597. break;
  598. case ACS_DIRECTION_RECEIVE:
  599. current = DIRECTION_RECEIVE;
  600. break;
  601. case ACS_DIRECTION_BOTH:
  602. current = DIRECTION_SENDRECEIVE;
  603. break;
  604. default:
  605. // invalid value
  606. ASSERT(0);
  607. // message box
  608. }
  609. m_pDirection->Select(current);
  610. }
  611. else
  612. {
  613. m_pDirection->Select(DIRECTION_SENDRECEIVE); // default
  614. }
  615. }catch(CMemoryException&){};
  616. // service type
  617. try{
  618. pStr = new CString();
  619. pStr->LoadString(IDS_ALL);
  620. m_aServiceTypes.Add(pStr);
  621. pStr = new CString();
  622. pStr->LoadString(IDS_CONTROLLEDLOAD);
  623. m_aServiceTypes.Add(pStr);
  624. pStr = new CString();
  625. pStr->LoadString(IDS_GUARANTEEDSERVICE);
  626. m_aServiceTypes.Add(pStr);
  627. pStr = new CString();
  628. pStr->LoadString(IDS_SERVICETYPE_DISABLED);
  629. m_aServiceTypes.Add(pStr);
  630. m_pServiceType = new CStrBox<CComboBox>(this, IDC_POLICY_GEN_SERVICELEVEL, m_aServiceTypes);
  631. m_pServiceType->Fill();
  632. // decide which one to select
  633. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_SERVICETYPE))
  634. {
  635. int current = -1;
  636. switch(m_spData->m_dwServiceType)
  637. {
  638. case ACS_SERVICETYPE_DISABLED:
  639. current = SERVICETYPE_DISABLED;
  640. break;
  641. case ACS_SERVICETYPE_CONTROLLEDLOAD:
  642. current = SERVICETYPE_CONTROLLEDLOAD;
  643. break;
  644. case ACS_SERVICETYPE_GUARANTEEDSERVICE:
  645. current = SERVICETYPE_GUARANTEEDSERVICE;
  646. break;
  647. case ACS_SERVICETYPE_ALL:
  648. current = SERVICETYPE_ALL;
  649. break;
  650. default:
  651. // invalid value
  652. ASSERT(0);
  653. // message box
  654. }
  655. m_pServiceType->Select(current);
  656. }
  657. else
  658. {
  659. m_pServiceType->Select(SERVICETYPE_ALL); // default
  660. }
  661. }catch(CMemoryException&){};
  662. // Identity -- user / ou
  663. CString strIdentity;
  664. m_nIdentityChoice = m_spData->GetIdentityType(strIdentity);
  665. switch(m_nIdentityChoice){
  666. case 0: // default
  667. case 1: // unknown
  668. break;
  669. case 2: // user
  670. m_strUser = strIdentity;
  671. break;
  672. case 3: // OU
  673. m_strOU = strIdentity;
  674. break;
  675. default:
  676. ASSERT(0);
  677. break;
  678. }
  679. CACSPage::OnInitDialog();
  680. if(bModified)
  681. SetModified();
  682. EnableIdentityCtrls(m_nIdentityChoice);
  683. return TRUE; // return TRUE unless you set the focus to a control
  684. // EXCEPTION: OCX Property Pages should return FALSE
  685. }
  686. void CPgPolicyGeneral::EnableIdentityCtrls(int nChoice)
  687. {
  688. switch(nChoice){
  689. case 0: // default
  690. case 1: // unknown
  691. m_editUser.EnableWindow(FALSE);
  692. m_editOU.EnableWindow(FALSE);
  693. m_buttonUser.EnableWindow(FALSE);
  694. m_buttonOU.EnableWindow(FALSE);
  695. break;
  696. case 2: // user
  697. m_editUser.EnableWindow(TRUE);
  698. m_buttonUser.EnableWindow(TRUE);
  699. m_editOU.EnableWindow(FALSE);
  700. m_buttonOU.EnableWindow(FALSE);
  701. break;
  702. case 3: // OU
  703. m_editUser.EnableWindow(FALSE);
  704. m_buttonUser.EnableWindow(FALSE);
  705. m_editOU.EnableWindow(TRUE);
  706. m_buttonOU.EnableWindow(TRUE);
  707. break;
  708. default:
  709. m_editUser.EnableWindow(FALSE);
  710. m_buttonUser.EnableWindow(FALSE);
  711. m_editOU.EnableWindow(FALSE);
  712. m_buttonOU.EnableWindow(FALSE);
  713. }
  714. }
  715. /////////////////////////////////////////////////////////////////////////////
  716. // CPgPolicyFlow property page
  717. IMPLEMENT_DYNCREATE(CPgPolicyFlow, CACSPage)
  718. CPgPolicyFlow::CPgPolicyFlow(CACSPolicyElement* pData) : CACSPage(CPgPolicyFlow::IDD)
  719. {
  720. ASSERT(pData);
  721. m_spData = pData;
  722. DataInit();
  723. }
  724. CPgPolicyFlow::CPgPolicyFlow() : CACSPage(CPgPolicyFlow::IDD)
  725. {
  726. }
  727. void CPgPolicyFlow::DataInit()
  728. {
  729. //{{AFX_DATA_INIT(CPgPolicyFlow)
  730. m_uDuration = 0;
  731. m_uPeakRate = 0;
  732. m_nDataRateChoice = -1;
  733. m_nDurationChoice = -1;
  734. m_nPeakRateChoice = -1;
  735. m_uDataRate = 0;
  736. //}}AFX_DATA_INIT
  737. m_nBranchFlag = 0;
  738. m_pGeneralPage = NULL;
  739. }
  740. CPgPolicyFlow::~CPgPolicyFlow()
  741. {
  742. m_nBranchFlag = 0;
  743. m_pGeneralPage = NULL;
  744. }
  745. void CPgPolicyFlow::DoDataExchange(CDataExchange* pDX)
  746. {
  747. CACSPage::DoDataExchange(pDX);
  748. //{{AFX_DATA_MAP(CPgPolicyFlow)
  749. DDX_Control(pDX, IDC_POLICY_FLOW_PEAKDATARATE_EDIT_LIMIT, m_editPeakRate);
  750. DDX_Control(pDX, IDC_POLICY_FLOW_DURATION_EDIT_LIMIT, m_editDuration);
  751. DDX_Control(pDX, IDC_POLICY_FLOW_DATARATE_EDIT_LIMIT, m_editDataRate);
  752. DDX_Radio(pDX, IDC_POLICY_FLOW_DATARATE_RES, m_nDataRateChoice);
  753. DDX_Radio(pDX, IDC_POLICY_FLOW_DURATION_RES, m_nDurationChoice);
  754. DDX_Radio(pDX, IDC_POLICY_FLOW_PEAKDATARATE_RES, m_nPeakRateChoice);
  755. DDX_Text(pDX, IDC_POLICY_FLOW_DURATION_EDIT_LIMIT, m_uDuration);
  756. if (m_nDurationChoice == 2)
  757. DDV_MinMaxUInt(pDX, m_uDuration, 0, 71582780);
  758. DDX_Text(pDX, IDC_POLICY_FLOW_PEAKDATARATE_EDIT_LIMIT, m_uPeakRate);
  759. if (m_nPeakRateChoice ==2 )
  760. DDV_MinMaxUInt(pDX, m_uPeakRate, 0, 4194300);
  761. DDX_Text(pDX, IDC_POLICY_FLOW_DATARATE_EDIT_LIMIT, m_uDataRate);
  762. if (m_nDataRateChoice == 2)
  763. DDV_MinMaxUInt(pDX, m_uDataRate, 0, 4194300);
  764. //}}AFX_DATA_MAP
  765. }
  766. BEGIN_MESSAGE_MAP(CPgPolicyFlow, CACSPage)
  767. //{{AFX_MSG_MAP(CPgPolicyFlow)
  768. ON_BN_CLICKED(IDC_POLICY_FLOW_DATARATE_DEF, OnPolicyFlowDatarateDef)
  769. ON_EN_CHANGE(IDC_POLICY_FLOW_DATARATE_EDIT_LIMIT, OnChangePolicyFlowDatarateEditLimit)
  770. ON_BN_CLICKED(IDC_POLICY_FLOW_DATARATE_RADIO_LIMIT, OnPolicyFlowDatarateRadioLimit)
  771. ON_BN_CLICKED(IDC_POLICY_FLOW_DATARATE_RES, OnPolicyFlowDatarateRes)
  772. ON_BN_CLICKED(IDC_POLICY_FLOW_DURATION_DEF, OnPolicyFlowDurationDef)
  773. ON_EN_CHANGE(IDC_POLICY_FLOW_DURATION_EDIT_LIMIT, OnChangePolicyFlowDurationEditLimit)
  774. ON_BN_CLICKED(IDC_POLICY_FLOW_DURATION_RADIO_LIMIT, OnPolicyFlowDurationRadioLimit)
  775. ON_BN_CLICKED(IDC_POLICY_FLOW_DURATION_RES, OnPolicyFlowDurationRes)
  776. ON_BN_CLICKED(IDC_POLICY_FLOW_PEAKDATARATE_DEF, OnPolicyFlowPeakdatarateDef)
  777. ON_EN_CHANGE(IDC_POLICY_FLOW_PEAKDATARATE_EDIT_LIMIT, OnChangePolicyFlowPeakdatarateEditLimit)
  778. ON_BN_CLICKED(IDC_POLICY_FLOW_PEAKDATARATE_RADIO_LIMIT, OnPolicyFlowPeakdatarateRadioLimit)
  779. ON_BN_CLICKED(IDC_POLICY_FLOW_PEAKDATARATE_RES, OnPolicyFlowPeakdatarateRes)
  780. ON_WM_KILLFOCUS()
  781. //}}AFX_MSG_MAP
  782. END_MESSAGE_MAP()
  783. /////////////////////////////////////////////////////////////////////////////
  784. // CPgPolicyFlow message handlers
  785. BOOL CPgPolicyFlow::OnInitDialog()
  786. {
  787. //------------------
  788. // per flow
  789. // data rate
  790. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_PF_TOKENRATE))
  791. {
  792. if IS_LARGE_UNLIMIT(m_spData->m_ddPFTokenRate)
  793. m_nDataRateChoice = 0;
  794. else
  795. {
  796. m_nDataRateChoice = 2; // numbered limit
  797. m_uDataRate = TOKBS(m_spData->m_ddPFTokenRate.LowPart);
  798. }
  799. }
  800. else
  801. m_nDataRateChoice = 1; // default
  802. // Peak data rate
  803. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_PF_PEAKBANDWIDTH))
  804. {
  805. if IS_LARGE_UNLIMIT(m_spData->m_ddPFPeakBandWidth)
  806. m_nPeakRateChoice = 0;
  807. else
  808. {
  809. m_nPeakRateChoice = 2; // numbered limit
  810. m_uPeakRate = TOKBS(m_spData->m_ddPFPeakBandWidth.LowPart);
  811. }
  812. }
  813. else
  814. m_nPeakRateChoice = 1; // default
  815. // duration
  816. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_PF_DURATION))
  817. {
  818. if(m_spData->m_dwPFDuration == UNLIMIT)
  819. m_nDurationChoice = 0;
  820. else
  821. {
  822. m_nDurationChoice = 2;
  823. m_uDuration = SEC2MIN(m_spData->m_dwPFDuration);
  824. }
  825. }
  826. else
  827. m_nDurationChoice = 1;
  828. // ==== data exchange is done within here
  829. CACSPage::OnInitDialog();
  830. if(m_nDataRateChoice != 2)
  831. m_editDataRate.EnableWindow(FALSE);
  832. if(m_nPeakRateChoice != 2)
  833. m_editPeakRate.EnableWindow(FALSE);
  834. if(m_nDurationChoice != 2)
  835. m_editDuration.EnableWindow(FALSE);
  836. GetDlgItem(IDC_POLICY_FLOW_DATARATE_DEF)->GetWindowText(m_strDataRateDefault);
  837. GetDlgItem(IDC_POLICY_FLOW_PEAKDATARATE_DEF)->GetWindowText(m_strPeakRateDefault);
  838. GetDlgItem(IDC_POLICY_FLOW_DURATION_DEF)->GetWindowText(m_strDurationDefault);
  839. return TRUE; // return TRUE unless you set the focus to a control
  840. // EXCEPTION: OCX Property Pages should return FALSE
  841. }
  842. BOOL CPgPolicyFlow::OnSetActive( )
  843. {
  844. // change default button strings based on choice of user
  845. CString datarateStr = m_strDataRateDefault;
  846. CString peakrateStr = m_strPeakRateDefault;
  847. CString durationStr = m_strDurationDefault;
  848. if ((m_nBranchFlag & BRANCH_FLAG_GLOBAL) != 0) // may need to alter the text
  849. {
  850. CString tmp;
  851. ASSERT(m_pGeneralPage);
  852. if(m_pGeneralPage->IfAnyAuth())
  853. {
  854. tmp.LoadString(IDS_A_DEF_DATARATE_SUF);
  855. datarateStr += tmp;
  856. tmp.LoadString(IDS_A_DEF_PEAKRATE_SUF);
  857. peakrateStr += tmp;
  858. tmp.LoadString(IDS_A_DEF_DURATION_SUF);
  859. durationStr += tmp;
  860. }
  861. else if (m_pGeneralPage->IfAnyUnauth())
  862. {
  863. tmp.LoadString(IDS_U_DEF_DATARATE_SUF);
  864. datarateStr += tmp;
  865. tmp.LoadString(IDS_U_DEF_PEAKRATE_SUF);
  866. peakrateStr += tmp;
  867. tmp.LoadString(IDS_U_DEF_DURATION_SUF);
  868. durationStr += tmp;
  869. }
  870. }
  871. // test if the policy is for any authentication/unauthenticaion policy in enterprise level
  872. GetDlgItem(IDC_POLICY_FLOW_DATARATE_DEF)->SetWindowText(datarateStr);
  873. GetDlgItem(IDC_POLICY_FLOW_PEAKDATARATE_DEF)->SetWindowText(peakrateStr);
  874. GetDlgItem(IDC_POLICY_FLOW_DURATION_DEF)->SetWindowText(durationStr);
  875. return CACSPage::OnSetActive();
  876. }
  877. BOOL CPgPolicyFlow::OnKillActive( )
  878. {
  879. UINT cId = 0;
  880. UINT mId = 0;
  881. if(!UpdateData())
  882. return FALSE;
  883. // Peak Rate should be >= data rate
  884. if(m_nPeakRateChoice ==2 && m_nDataRateChoice == 2 && m_uDataRate > m_uPeakRate)
  885. {
  886. cId = IDC_POLICY_FLOW_PEAKDATARATE_EDIT_LIMIT;
  887. mId = IDS_ERR_PEAKRATE_LESS_RATE;
  888. }
  889. if ((m_nBranchFlag & BRANCH_FLAG_GLOBAL) != 0) // need to check again default value
  890. {
  891. CString tmp;
  892. ASSERT(m_pGeneralPage);
  893. if(m_pGeneralPage->IfAnyAuth())
  894. {
  895. // Peak Rate should be >= data rate
  896. if(m_nPeakRateChoice ==2 && m_nDataRateChoice == 1 && DEFAULT_AA_DATARATE > FROMKBS(m_uPeakRate))
  897. {
  898. cId = IDC_POLICY_FLOW_PEAKDATARATE_EDIT_LIMIT;
  899. mId = IDS_ERR_PEAKRATE_LESS_RATE;
  900. }
  901. }
  902. else if (m_pGeneralPage->IfAnyUnauth())
  903. {
  904. // Peak Rate should be >= data rate
  905. if(m_nPeakRateChoice ==2 && m_nDataRateChoice == 1 && DEFAULT_AU_DATARATE > FROMKBS(m_uPeakRate))
  906. {
  907. cId = IDC_POLICY_FLOW_PEAKDATARATE_EDIT_LIMIT;
  908. mId = IDS_ERR_PEAKRATE_LESS_RATE;
  909. }
  910. }
  911. }
  912. // if there is anything wrong
  913. if(cId)
  914. {
  915. CWnd* pWnd = GetDlgItem(cId);
  916. ASSERT(pWnd);
  917. GotoDlgCtrl( pWnd );
  918. AfxMessageBox(mId);
  919. return FALSE;
  920. }
  921. // check if any is set to Zero
  922. if(m_nDataRateChoice == 2 && m_uDataRate == 0) // date rate
  923. {
  924. cId = IDC_POLICY_FLOW_DATARATE_EDIT_LIMIT;
  925. mId = IDS_WRN_ZERO_POLICY_DATA;
  926. }
  927. else if(m_nPeakRateChoice ==2 && m_uPeakRate == 0) // peak data rate
  928. {
  929. cId = IDC_POLICY_FLOW_PEAKDATARATE_EDIT_LIMIT;
  930. mId = IDS_WRN_ZERO_POLICY_DATA;
  931. }
  932. else if(m_nDurationChoice == 2 && m_uDuration == 0) // duration
  933. {
  934. cId = IDC_POLICY_FLOW_DURATION_EDIT_LIMIT;
  935. mId = IDS_WRN_ZERO_POLICY_DATA;
  936. }
  937. if(cId)
  938. {
  939. if(IDNO == AfxMessageBox(mId, MB_YESNO))
  940. {
  941. CWnd* pWnd = GetDlgItem(cId);
  942. ASSERT(pWnd);
  943. GotoDlgCtrl( pWnd );
  944. return FALSE;
  945. }
  946. }
  947. return CACSPage::OnKillActive();
  948. }
  949. // radio buttons here, 0 -- no limit (resouce limit ) , 1 -- default to general level, 2 -- user limit
  950. //
  951. BOOL CPgPolicyFlow::OnApply()
  952. {
  953. CString* pStr = NULL;
  954. // check if the values input on the page is valid
  955. UINT cId = 0;
  956. UINT mId = 0;
  957. if(!GetModified()) return TRUE;
  958. // Peak Rate should be >= data rate
  959. if(m_nPeakRateChoice ==2 && m_nDataRateChoice == 2 && m_uDataRate > m_uPeakRate)
  960. {
  961. cId = IDC_POLICY_FLOW_PEAKDATARATE_EDIT_LIMIT;
  962. mId = IDS_ERR_PEAKRATE_LESS_RATE;
  963. }
  964. // if there is anything wrong
  965. if(cId)
  966. {
  967. CWnd* pWnd = GetDlgItem(cId);
  968. ASSERT(pWnd);
  969. GotoDlgCtrl( pWnd );
  970. AfxMessageBox(mId);
  971. return FALSE;
  972. }
  973. //------------------
  974. // per flow
  975. // data rate
  976. switch(m_nDataRateChoice){
  977. case 2: // limit
  978. m_spData->m_ddPFTokenRate.LowPart = FROMKBS(m_uDataRate);
  979. m_spData->m_ddPFTokenRate.HighPart = 0;
  980. break;
  981. case 1: // default
  982. break;
  983. case 0: // unlimit
  984. SET_LARGE_UNLIMIT(m_spData->m_ddPFTokenRate);
  985. break;
  986. default:
  987. ASSERT(0);
  988. };
  989. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_PF_TOKENRATE, (m_nDataRateChoice != 1));
  990. // Peak data rate
  991. switch(m_nPeakRateChoice){
  992. case 2: // limit
  993. m_spData->m_ddPFPeakBandWidth.LowPart = FROMKBS(m_uPeakRate);
  994. m_spData->m_ddPFPeakBandWidth.HighPart = 0;
  995. break;
  996. case 1: // default
  997. break;
  998. case 0: // unlimit
  999. SET_LARGE_UNLIMIT(m_spData->m_ddPFPeakBandWidth);
  1000. break;
  1001. default:
  1002. ASSERT(0);
  1003. };
  1004. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_PF_PEAKBANDWIDTH, (m_nPeakRateChoice != 1));
  1005. // duration
  1006. switch(m_nDurationChoice){
  1007. case 2: // limit
  1008. m_spData->m_dwPFDuration = MIN2SEC(m_uDuration);
  1009. break;
  1010. case 1: // default
  1011. break;
  1012. case 0: // unlimit
  1013. m_spData->m_dwPFDuration = UNLIMIT;
  1014. break;
  1015. default:
  1016. ASSERT(0);
  1017. };
  1018. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_PF_DURATION, (m_nDurationChoice != 1));
  1019. DWORD dwAttrFlags = 0;
  1020. dwAttrFlags |= (ACS_PAF_PF_TOKENRATE | ACS_PAF_PF_PEAKBANDWIDTH | ACS_PAF_PF_DURATION);
  1021. AddFlags(dwAttrFlags); // prepare flags for saving
  1022. return CACSPage::OnApply();
  1023. }
  1024. void CPgPolicyFlow::OnPolicyFlowDatarateDef()
  1025. {
  1026. SetModified();
  1027. m_editDataRate.EnableWindow(FALSE);
  1028. }
  1029. void CPgPolicyFlow::OnChangePolicyFlowDatarateEditLimit()
  1030. {
  1031. // TODO: If this is a RICHEDIT control, the control will not
  1032. // send this notification unless you override the CACSPage::OnInitDialog()
  1033. // function to send the EM_SETEVENTMASK message to the control
  1034. // with the ENM_CHANGE flag ORed into the lParam mask.
  1035. // TODO: Add your control notification handler code here
  1036. SetModified();
  1037. }
  1038. void CPgPolicyFlow::OnPolicyFlowDatarateRadioLimit()
  1039. {
  1040. // TODO: Add your control notification handler code here
  1041. SetModified();
  1042. m_editDataRate.EnableWindow(TRUE);
  1043. }
  1044. void CPgPolicyFlow::OnPolicyFlowDatarateRes()
  1045. {
  1046. // TODO: Add your control notification handler code here
  1047. SetModified();
  1048. m_editDataRate.EnableWindow(FALSE);
  1049. }
  1050. void CPgPolicyFlow::OnPolicyFlowDurationDef()
  1051. {
  1052. // TODO: Add your control notification handler code here
  1053. m_editDuration.EnableWindow(FALSE);
  1054. SetModified();
  1055. }
  1056. void CPgPolicyFlow::OnChangePolicyFlowDurationEditLimit()
  1057. {
  1058. // TODO: If this is a RICHEDIT control, the control will not
  1059. // send this notification unless you override the CACSPage::OnInitDialog()
  1060. // function to send the EM_SETEVENTMASK message to the control
  1061. // with the ENM_CHANGE flag ORed into the lParam mask.
  1062. // TODO: Add your control notification handler code here
  1063. SetModified();
  1064. }
  1065. void CPgPolicyFlow::OnPolicyFlowDurationRadioLimit()
  1066. {
  1067. // TODO: Add your control notification handler code here
  1068. m_editDuration.EnableWindow(TRUE);
  1069. SetModified();
  1070. }
  1071. void CPgPolicyFlow::OnPolicyFlowDurationRes()
  1072. {
  1073. // TODO: Add your control notification handler code here
  1074. m_editDuration.EnableWindow(FALSE);
  1075. SetModified();
  1076. }
  1077. void CPgPolicyFlow::OnPolicyFlowPeakdatarateDef()
  1078. {
  1079. // TODO: Add your control notification handler code here
  1080. m_editPeakRate.EnableWindow(FALSE);
  1081. SetModified();
  1082. }
  1083. void CPgPolicyFlow::OnChangePolicyFlowPeakdatarateEditLimit()
  1084. {
  1085. // TODO: If this is a RICHEDIT control, the control will not
  1086. // send this notification unless you override the CACSPage::OnInitDialog()
  1087. // function to send the EM_SETEVENTMASK message to the control
  1088. // with the ENM_CHANGE flag ORed into the lParam mask.
  1089. // TODO: Add your control notification handler code here
  1090. SetModified();
  1091. }
  1092. void CPgPolicyFlow::OnPolicyFlowPeakdatarateRadioLimit()
  1093. {
  1094. // TODO: Add your control notification handler code here
  1095. m_editPeakRate.EnableWindow(TRUE);
  1096. SetModified();
  1097. }
  1098. void CPgPolicyFlow::OnPolicyFlowPeakdatarateRes()
  1099. {
  1100. // TODO: Add your control notification handler code here
  1101. m_editPeakRate.EnableWindow(FALSE);
  1102. SetModified();
  1103. }
  1104. /////////////////////////////////////////////////////////////////////////////
  1105. // CPgPolicyAggregate dialog
  1106. CPgPolicyAggregate::CPgPolicyAggregate(CACSPolicyElement* pData) : CACSPage(CPgPolicyAggregate::IDD)
  1107. {
  1108. ASSERT(pData);
  1109. m_spData = pData;
  1110. DataInit();
  1111. }
  1112. CPgPolicyAggregate::CPgPolicyAggregate()
  1113. : CACSPage(CPgPolicyAggregate::IDD)
  1114. {
  1115. DataInit();
  1116. }
  1117. void CPgPolicyAggregate::DataInit()
  1118. {
  1119. //{{AFX_DATA_INIT(CPgPolicyAggregate)
  1120. m_nDataRateChoice = -1;
  1121. m_nFlowsChoice = -1;
  1122. m_nPeakRateChoice = -1;
  1123. m_uDataRate = 0;
  1124. m_uFlows = 0;
  1125. m_uPeakRate = 0;
  1126. //}}AFX_DATA_INIT
  1127. m_nBranchFlag = 0;
  1128. m_pGeneralPage = NULL;
  1129. }
  1130. void CPgPolicyAggregate::DoDataExchange(CDataExchange* pDX)
  1131. {
  1132. CACSPage::DoDataExchange(pDX);
  1133. //{{AFX_DATA_MAP(CPgPolicyAggregate)
  1134. DDX_Control(pDX, IDC_POLICY_AGGR_PEAKDATARATE_EDIT_LIMIT, m_editPeakRate);
  1135. DDX_Control(pDX, IDC_POLICY_AGGR_FLOWS_EDIT_LIMIT, m_editFlows);
  1136. DDX_Control(pDX, IDC_POLICY_AGGR_DATARATE_EDIT_LIMIT, m_editDataRate);
  1137. DDX_Radio(pDX, IDC_POLICY_AGGR_DATARATE_RES, m_nDataRateChoice);
  1138. DDX_Radio(pDX, IDC_POLICY_AGGR_FLOWS_RES, m_nFlowsChoice);
  1139. DDX_Radio(pDX, IDC_POLICY_AGGR_PEAKDATARATE_RES, m_nPeakRateChoice);
  1140. DDX_Text(pDX, IDC_POLICY_AGGR_DATARATE_EDIT_LIMIT, m_uDataRate);
  1141. if(m_nDataRateChoice == 2)
  1142. DDV_MinMaxUInt(pDX, m_uDataRate, 0, DWORD_LIMIT/1024);
  1143. DDX_Text(pDX, IDC_POLICY_AGGR_FLOWS_EDIT_LIMIT, m_uFlows);
  1144. if(m_nFlowsChoice == 2)
  1145. DDV_MinMaxUInt(pDX, m_uFlows, 0, DWORD_LIMIT);
  1146. DDX_Text(pDX, IDC_POLICY_AGGR_PEAKDATARATE_EDIT_LIMIT, m_uPeakRate);
  1147. if(m_nPeakRateChoice == 2)
  1148. DDV_MinMaxUInt(pDX, m_uPeakRate, 0, DWORD_LIMIT/1024);
  1149. //}}AFX_DATA_MAP
  1150. }
  1151. BEGIN_MESSAGE_MAP(CPgPolicyAggregate, CACSPage)
  1152. //{{AFX_MSG_MAP(CPgPolicyAggregate)
  1153. ON_BN_CLICKED(IDC_POLICY_AGGR_DATARATE_DEF, OnPolicyAggrDatarateDef)
  1154. ON_EN_CHANGE(IDC_POLICY_AGGR_DATARATE_EDIT_LIMIT, OnChangePolicyAggrDatarateEditLimit)
  1155. ON_BN_CLICKED(IDC_POLICY_AGGR_DATARATE_RADIO_LIMIT, OnPolicyAggrDatarateRadioLimit)
  1156. ON_BN_CLICKED(IDC_POLICY_AGGR_DATARATE_RES, OnPolicyAggrDatarateRes)
  1157. ON_BN_CLICKED(IDC_POLICY_AGGR_FLOWS_DEF, OnPolicyAggrFlowsDef)
  1158. ON_EN_CHANGE(IDC_POLICY_AGGR_FLOWS_EDIT_LIMIT, OnChangePolicyAggrFlowsEditLimit)
  1159. ON_BN_CLICKED(IDC_POLICY_AGGR_FLOWS_RES, OnPolicyAggrFlowsRes)
  1160. ON_BN_CLICKED(IDC_POLICY_AGGR_PEAKDATARATE_DEF, OnPolicyAggrPeakdatarateDef)
  1161. ON_EN_CHANGE(IDC_POLICY_AGGR_PEAKDATARATE_EDIT_LIMIT, OnChangePolicyAggrPeakdatarateEditLimit)
  1162. ON_BN_CLICKED(IDC_POLICY_AGGR_PEAKDATARATE_RADIO_LIMIT, OnPolicyAggrPeakdatarateRadioLimit)
  1163. ON_BN_CLICKED(IDC_POLICY_AGGR_PEAKDATARATE_RES, OnPolicyAggrPeakdatarateRes)
  1164. ON_BN_CLICKED(IDC_POLICY_AGGR_FLOWS_RADIO_LIMIT, OnPolicyAggrFlowsRadioLimit)
  1165. //}}AFX_MSG_MAP
  1166. END_MESSAGE_MAP()
  1167. /////////////////////////////////////////////////////////////////////////////
  1168. // CPgPolicyAggregate message handlers
  1169. /////////////////////////////////////////////////////////////////////////////
  1170. // CPgPolicyFlow message handlers
  1171. BOOL CPgPolicyAggregate::OnInitDialog()
  1172. {
  1173. //------------------
  1174. // Total
  1175. // data rate
  1176. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_TT_TOKENRATE))
  1177. {
  1178. if IS_LARGE_UNLIMIT(m_spData->m_ddTTTokenRate)
  1179. m_nDataRateChoice = 0;
  1180. else
  1181. {
  1182. m_nDataRateChoice = 2; // numbered limit
  1183. m_uDataRate = TOKBS(m_spData->m_ddTTTokenRate.LowPart);
  1184. }
  1185. }
  1186. else
  1187. m_nDataRateChoice = 1; // default
  1188. // Peak data rate
  1189. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_TT_PEAKBANDWIDTH))
  1190. {
  1191. if IS_LARGE_UNLIMIT(m_spData->m_ddTTPeakBandWidth)
  1192. m_nPeakRateChoice = 0;
  1193. else
  1194. {
  1195. m_nPeakRateChoice = 2; // numbered limit
  1196. m_uPeakRate = TOKBS(m_spData->m_ddTTPeakBandWidth.LowPart);
  1197. }
  1198. }
  1199. else
  1200. m_nPeakRateChoice = 1; // default
  1201. // flows
  1202. if(m_spData->GetFlags(ATTR_FLAG_LOAD, ACS_PAF_TT_FLOWS))
  1203. {
  1204. if(m_spData->m_dwTTFlows == UNLIMIT)
  1205. m_nFlowsChoice = 0;
  1206. else
  1207. {
  1208. m_nFlowsChoice = 2;
  1209. m_uFlows = m_spData->m_dwTTFlows;
  1210. }
  1211. }
  1212. else
  1213. m_nFlowsChoice = 1;
  1214. CACSPage::OnInitDialog();
  1215. if(m_nDataRateChoice != 2)
  1216. m_editDataRate.EnableWindow(FALSE);
  1217. if(m_nPeakRateChoice != 2)
  1218. m_editPeakRate.EnableWindow(FALSE);
  1219. if(m_nFlowsChoice != 2)
  1220. m_editFlows.EnableWindow(FALSE);
  1221. GetDlgItem(IDC_POLICY_AGGR_DATARATE_DEF)->GetWindowText(m_strDataRateDefault);
  1222. GetDlgItem(IDC_POLICY_AGGR_PEAKDATARATE_DEF)->GetWindowText(m_strPeakRateDefault);
  1223. GetDlgItem(IDC_POLICY_AGGR_FLOWS_DEF)->GetWindowText(m_strFlowsDefault);
  1224. return TRUE; // return TRUE unless you set the focus to a control
  1225. // EXCEPTION: OCX Property Pages should return FALSE
  1226. }
  1227. BOOL CPgPolicyAggregate::OnSetActive( )
  1228. {
  1229. // change default button strings based on choice of user
  1230. CString datarateStr = m_strDataRateDefault;
  1231. CString peakrateStr = m_strPeakRateDefault;
  1232. CString flowsStr = m_strFlowsDefault;
  1233. if ((m_nBranchFlag & BRANCH_FLAG_GLOBAL) != 0) // may need to alter the text
  1234. {
  1235. CString tmp;
  1236. ASSERT(m_pGeneralPage);
  1237. if(m_pGeneralPage->IfAnyAuth())
  1238. {
  1239. tmp.LoadString(IDS_A_DEF_DATARATE_SUF);
  1240. datarateStr += tmp;
  1241. tmp.LoadString(IDS_A_DEF_PEAKRATE_SUF);
  1242. peakrateStr += tmp;
  1243. tmp.LoadString(IDS_A_DEF_FLOWS_SUF);
  1244. flowsStr += tmp;
  1245. }
  1246. else if (m_pGeneralPage->IfAnyUnauth())
  1247. {
  1248. tmp.LoadString(IDS_U_DEF_DATARATE_SUF);
  1249. datarateStr += tmp;
  1250. tmp.LoadString(IDS_U_DEF_PEAKRATE_SUF);
  1251. peakrateStr += tmp;
  1252. tmp.LoadString(IDS_U_DEF_FLOWS_SUF);
  1253. flowsStr += tmp;
  1254. }
  1255. }
  1256. // test if the policy is for any authentication/unauthenticaion policy in enterprise level
  1257. GetDlgItem(IDC_POLICY_AGGR_DATARATE_DEF)->SetWindowText(datarateStr);
  1258. GetDlgItem(IDC_POLICY_AGGR_PEAKDATARATE_DEF)->SetWindowText(peakrateStr);
  1259. GetDlgItem(IDC_POLICY_AGGR_FLOWS_DEF)->SetWindowText(flowsStr);
  1260. return CACSPage::OnSetActive();
  1261. }
  1262. BOOL CPgPolicyAggregate::OnKillActive( )
  1263. {
  1264. // check if the values input on the page is valid
  1265. UINT cId = 0;
  1266. UINT mId = 0;
  1267. if(!UpdateData(TRUE)) return FALSE;
  1268. if(!GetModified()) return TRUE;
  1269. // Peak Rate should be >= data rate
  1270. if(m_nPeakRateChoice ==2 && m_nDataRateChoice == 2 && m_uDataRate > m_uPeakRate)
  1271. {
  1272. cId = IDC_POLICY_AGGR_PEAKDATARATE_EDIT_LIMIT;
  1273. mId = IDS_ERR_TOTALPEAK_LESS_TOTALRATE;
  1274. }
  1275. if ((m_nBranchFlag & BRANCH_FLAG_GLOBAL) != 0) // need to check again default value
  1276. {
  1277. CString tmp;
  1278. ASSERT(m_pGeneralPage);
  1279. if(m_pGeneralPage->IfAnyAuth())
  1280. {
  1281. // Peak Rate should be >= data rate
  1282. if(m_nPeakRateChoice ==2 && m_nDataRateChoice == 1 && DEFAULT_AA_DATARATE > FROMKBS(m_uPeakRate))
  1283. {
  1284. cId = IDC_POLICY_AGGR_PEAKDATARATE_EDIT_LIMIT;
  1285. mId = IDS_ERR_TOTALPEAK_LESS_TOTALRATE;
  1286. }
  1287. }
  1288. else if (m_pGeneralPage->IfAnyUnauth())
  1289. {
  1290. // Peak Rate should be >= data rate
  1291. if(m_nPeakRateChoice ==2 && m_nDataRateChoice == 1 && DEFAULT_AU_DATARATE > FROMKBS(m_uPeakRate))
  1292. {
  1293. cId = IDC_POLICY_AGGR_PEAKDATARATE_EDIT_LIMIT;
  1294. mId = IDS_ERR_TOTALPEAK_LESS_TOTALRATE;
  1295. }
  1296. }
  1297. }
  1298. // if there is anything wrong
  1299. if(cId)
  1300. {
  1301. CWnd* pWnd = GetDlgItem(cId);
  1302. ASSERT(pWnd);
  1303. GotoDlgCtrl( pWnd );
  1304. AfxMessageBox(mId);
  1305. return FALSE;
  1306. }
  1307. // check if any is set to Zero
  1308. if(m_nDataRateChoice == 2 && m_uDataRate == 0) // date rate
  1309. {
  1310. cId = IDC_POLICY_AGGR_DATARATE_EDIT_LIMIT;
  1311. mId = IDS_WRN_ZERO_POLICY_DATA;
  1312. }
  1313. else if(m_nPeakRateChoice ==2 && m_uPeakRate == 0) // peak data rate
  1314. {
  1315. cId = IDC_POLICY_AGGR_PEAKDATARATE_EDIT_LIMIT;
  1316. mId = IDS_WRN_ZERO_POLICY_DATA;
  1317. }
  1318. else if(m_nFlowsChoice == 2 && m_uFlows == 0) // duration
  1319. {
  1320. cId = IDC_POLICY_AGGR_FLOWS_EDIT_LIMIT;
  1321. mId = IDS_WRN_ZERO_POLICY_DATA;
  1322. }
  1323. if(cId)
  1324. {
  1325. if(IDNO == AfxMessageBox(mId, MB_YESNO))
  1326. {
  1327. CWnd* pWnd = GetDlgItem(cId);
  1328. ASSERT(pWnd);
  1329. GotoDlgCtrl( pWnd );
  1330. return FALSE;
  1331. }
  1332. }
  1333. return CACSPage::OnKillActive();
  1334. }
  1335. // radio buttons here, 0 -- no limit (resouce limit ) , 1 -- default to general level, 2 -- user limit
  1336. //
  1337. BOOL CPgPolicyAggregate::OnApply()
  1338. {
  1339. CString* pStr = NULL;
  1340. // check if the values input on the page is valid
  1341. UINT cId = 0;
  1342. UINT mId = 0;
  1343. if(!GetModified()) return TRUE;
  1344. // Peak Rate should be >= data rate
  1345. if(m_nPeakRateChoice ==2 && m_nDataRateChoice == 2 && m_uDataRate > m_uPeakRate)
  1346. {
  1347. cId = IDC_POLICY_AGGR_PEAKDATARATE_EDIT_LIMIT;
  1348. mId = IDS_ERR_TOTALPEAK_LESS_TOTALRATE;
  1349. }
  1350. // if there is anything wrong
  1351. if(cId)
  1352. {
  1353. CWnd* pWnd = GetDlgItem(cId);
  1354. ASSERT(pWnd);
  1355. GotoDlgCtrl( pWnd );
  1356. AfxMessageBox(mId);
  1357. return FALSE;
  1358. }
  1359. //------------------
  1360. // per flow
  1361. // data rate
  1362. switch(m_nDataRateChoice){
  1363. case 2: // limit
  1364. m_spData->m_ddTTTokenRate.LowPart = FROMKBS(m_uDataRate);
  1365. m_spData->m_ddTTTokenRate.HighPart = 0;
  1366. break;
  1367. case 1: // default
  1368. break;
  1369. case 0: // unlimit
  1370. SET_LARGE_UNLIMIT(m_spData->m_ddTTTokenRate);
  1371. break;
  1372. default:
  1373. ASSERT(0);
  1374. };
  1375. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_TT_TOKENRATE, (m_nDataRateChoice != 1));
  1376. // Peak data rate
  1377. switch(m_nPeakRateChoice){
  1378. case 2: // limit
  1379. m_spData->m_ddTTPeakBandWidth.LowPart = FROMKBS(m_uPeakRate);
  1380. m_spData->m_ddTTPeakBandWidth.HighPart = 0;
  1381. break;
  1382. case 1: // default
  1383. break;
  1384. case 0: // unlimit
  1385. SET_LARGE_UNLIMIT(m_spData->m_ddTTPeakBandWidth);
  1386. break;
  1387. default:
  1388. ASSERT(0);
  1389. };
  1390. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_TT_PEAKBANDWIDTH, (m_nPeakRateChoice != 1));
  1391. // duration
  1392. switch(m_nFlowsChoice){
  1393. case 2: // limit
  1394. m_spData->m_dwTTFlows = m_uFlows;
  1395. break;
  1396. case 1: // default
  1397. break;
  1398. case 0: // unlimit
  1399. m_spData->m_dwTTFlows = UNLIMIT;
  1400. break;
  1401. default:
  1402. ASSERT(0);
  1403. };
  1404. m_spData->SetFlags(ATTR_FLAG_SAVE, ACS_PAF_TT_FLOWS, (m_nFlowsChoice != 1));
  1405. DWORD dwAttrFlags = 0;
  1406. dwAttrFlags |= (ACS_PAF_TT_TOKENRATE | ACS_PAF_TT_PEAKBANDWIDTH | ACS_PAF_TT_FLOWS);
  1407. AddFlags(dwAttrFlags); // prepare flags for saving
  1408. return CACSPage::OnApply();
  1409. }
  1410. void CPgPolicyAggregate::OnPolicyAggrDatarateDef()
  1411. {
  1412. // TODO: Add your control notification handler code here
  1413. SetModified();
  1414. m_editDataRate.EnableWindow(FALSE);
  1415. }
  1416. void CPgPolicyAggregate::OnChangePolicyAggrDatarateEditLimit()
  1417. {
  1418. // TODO: If this is a RICHEDIT control, the control will not
  1419. // send this notification unless you override the CACSPage::OnInitDialog()
  1420. // function to send the EM_SETEVENTMASK message to the control
  1421. // with the ENM_CHANGE flag ORed into the lParam mask.
  1422. // TODO: Add your control notification handler code here
  1423. SetModified();
  1424. }
  1425. void CPgPolicyAggregate::OnPolicyAggrDatarateRadioLimit()
  1426. {
  1427. // TODO: Add your control notification handler code here
  1428. SetModified();
  1429. m_editDataRate.EnableWindow(TRUE);
  1430. }
  1431. void CPgPolicyAggregate::OnPolicyAggrDatarateRes()
  1432. {
  1433. // TODO: Add your control notification handler code here
  1434. SetModified();
  1435. m_editDataRate.EnableWindow(FALSE);
  1436. }
  1437. void CPgPolicyAggregate::OnPolicyAggrFlowsDef()
  1438. {
  1439. // TODO: Add your control notification handler code here
  1440. SetModified();
  1441. m_editFlows.EnableWindow(FALSE);
  1442. }
  1443. void CPgPolicyAggregate::OnChangePolicyAggrFlowsEditLimit()
  1444. {
  1445. // TODO: If this is a RICHEDIT control, the control will not
  1446. // send this notification unless you override the CACSPage::OnInitDialog()
  1447. // function to send the EM_SETEVENTMASK message to the control
  1448. // with the ENM_CHANGE flag ORed into the lParam mask.
  1449. // TODO: Add your control notification handler code here
  1450. SetModified();
  1451. }
  1452. void CPgPolicyAggregate::OnPolicyAggrFlowsRes()
  1453. {
  1454. // TODO: Add your control notification handler code here
  1455. SetModified();
  1456. m_editFlows.EnableWindow(FALSE);
  1457. }
  1458. void CPgPolicyAggregate::OnPolicyAggrFlowsRadioLimit()
  1459. {
  1460. // TODO: Add your control notification handler code here
  1461. SetModified();
  1462. m_editFlows.EnableWindow(TRUE);
  1463. }
  1464. void CPgPolicyAggregate::OnPolicyAggrPeakdatarateDef()
  1465. {
  1466. // TODO: Add your control notification handler code here
  1467. SetModified();
  1468. m_editPeakRate.EnableWindow(FALSE);
  1469. }
  1470. void CPgPolicyAggregate::OnChangePolicyAggrPeakdatarateEditLimit()
  1471. {
  1472. // TODO: If this is a RICHEDIT control, the control will not
  1473. // send this notification unless you override the CACSPage::OnInitDialog()
  1474. // function to send the EM_SETEVENTMASK message to the control
  1475. // with the ENM_CHANGE flag ORed into the lParam mask.
  1476. // TODO: Add your control notification handler code here
  1477. SetModified();
  1478. }
  1479. void CPgPolicyAggregate::OnPolicyAggrPeakdatarateRadioLimit()
  1480. {
  1481. // TODO: Add your control notification handler code here
  1482. SetModified();
  1483. m_editPeakRate.EnableWindow(TRUE);
  1484. }
  1485. void CPgPolicyAggregate::OnPolicyAggrPeakdatarateRes()
  1486. {
  1487. // TODO: Add your control notification handler code here
  1488. SetModified();
  1489. m_editPeakRate.EnableWindow(FALSE);
  1490. }
  1491. void CPgPolicyFlow::OnKillFocus(CWnd* pNewWnd)
  1492. {
  1493. CACSPage::OnKillFocus(pNewWnd);
  1494. // TODO: Add your message handler code here
  1495. }
  1496.