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.

938 lines
26 KiB

  1. // DPHttpPage.cpp : implementation file
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // History
  6. //
  7. // 03/03/00 v-marfin Added code to handle the selection of AuthType from
  8. // the combobox.
  9. // Changed handler for combobox from ON_CBN_EDITCHANGE
  10. // to ON_CBN_SELCHANGE since combobox is not type to
  11. // respond to ON_CBN_EDITCHANGE and the Apply button was
  12. // not being set.
  13. // 03/05/00 v-marfin bug 59643 : Make this the default starting page.
  14. // 03/16/00 v-marfin bug 60233 : Added EscapeSpecialChars() and UnEscapeSpecialChars()
  15. // functions and used to double any backslashes contained in strings
  16. // being passed to WMI in the Path. See OnApply(). And to remove those
  17. // double backslashes upon reading back from WMI (see OnInitDialog())
  18. // 03/22/00 v-marfin bug 60632 : converted timeout to a float value and displayed as
  19. // seconds, storing and retrieving as milliseconds.
  20. // 03/29/00 v-marfin bug 62585 : Set new Data collector's ENABLED to TRUE if user presses OK.
  21. // 03/30/00 v-marfin bug 59237 : If user does not change the default name of the data
  22. // collector when they first create it, change it for
  23. // them to a more meaningful name based on the data
  24. // they select in the property pages.
  25. // 04/08/00 v-marfin bug 63116 : Convert and unconvert CRLF from post data and extra headers.
  26. //
  27. //
  28. //
  29. #include "stdafx.h"
  30. #include "snapin.h"
  31. #include "DPHttpPage.h"
  32. #include "HMObject.h"
  33. #include "HttpAdvancedDlg.h"
  34. #include <math.h>
  35. #include "SnapinDefines.h" // v-marfin Bug 61451
  36. #include "DataElement.h"
  37. #include "DataGroupScopeItem.h"
  38. #include "HealthmonResultsPane.h"
  39. #ifdef _DEBUG
  40. #define new DEBUG_NEW
  41. #undef THIS_FILE
  42. static char THIS_FILE[] = __FILE__;
  43. #endif
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CDPHttpPage property page
  46. IMPLEMENT_DYNCREATE(CDPHttpPage, CHMPropertyPage)
  47. CDPHttpPage::CDPHttpPage() : CHMPropertyPage(CDPHttpPage::IDD)
  48. {
  49. //{{AFX_DATA_INIT(CDPHttpPage)
  50. m_bRequireReset = FALSE;
  51. m_bUseProxy = FALSE;
  52. m_sAuthentication = _T("");
  53. m_sPassword = _T("");
  54. m_sProxyAddress = _T("");
  55. m_sProxyPort = _T("");
  56. m_fTimeout = 30.0;
  57. m_sURL = _T("");
  58. m_sUserName = _T("");
  59. //}}AFX_DATA_INIT
  60. m_bFollowRedirects = TRUE;
  61. m_sMethod = _T("GET");
  62. m_sHelpTopic = _T("HMon21.chm::/dDEhttp.htm");
  63. m_iAuthType = 0; // v-marfin Bug 61451
  64. }
  65. CDPHttpPage::~CDPHttpPage()
  66. {
  67. }
  68. void CDPHttpPage::DoDataExchange(CDataExchange* pDX)
  69. {
  70. CHMPropertyPage::DoDataExchange(pDX);
  71. //{{AFX_DATA_MAP(CDPHttpPage)
  72. DDX_Check(pDX, IDC_CHECK_REQUIRE_RESET, m_bRequireReset);
  73. DDX_Check(pDX, IDC_CHECK_USE_PROXY, m_bUseProxy);
  74. DDX_CBString(pDX, IDC_COMBO_AUTHENTICATION, m_sAuthentication);
  75. DDV_MaxChars(pDX, m_sAuthentication, 255);
  76. DDX_Text(pDX, IDC_EDIT_PASSWORD, m_sPassword);
  77. DDV_MaxChars(pDX, m_sPassword, 255);
  78. DDX_Text(pDX, IDC_EDIT_PROXY_ADDRESS, m_sProxyAddress);
  79. DDV_MaxChars(pDX, m_sProxyAddress, 255);
  80. DDX_Text(pDX, IDC_EDIT_PROXY_PORT, m_sProxyPort);
  81. DDV_MaxChars(pDX, m_sProxyPort, 255);
  82. DDX_Text(pDX, IDC_EDIT_TIMEOUT, m_fTimeout);
  83. DDX_Text(pDX, IDC_EDIT_URL, m_sURL);
  84. DDV_MaxChars(pDX, m_sURL, 512);
  85. DDX_Text(pDX, IDC_EDIT_USER_NAME, m_sUserName);
  86. DDV_MaxChars(pDX, m_sUserName, 255);
  87. //}}AFX_DATA_MAP
  88. if( m_bUseProxy )
  89. {
  90. GetDlgItem(IDC_EDIT_PROXY_ADDRESS)->EnableWindow();
  91. GetDlgItem(IDC_EDIT_PROXY_PORT)->EnableWindow();
  92. }
  93. else
  94. {
  95. GetDlgItem(IDC_EDIT_PROXY_ADDRESS)->EnableWindow(FALSE);
  96. GetDlgItem(IDC_EDIT_PROXY_PORT)->EnableWindow(FALSE);
  97. }
  98. }
  99. BEGIN_MESSAGE_MAP(CDPHttpPage, CHMPropertyPage)
  100. //{{AFX_MSG_MAP(CDPHttpPage)
  101. ON_WM_DESTROY()
  102. ON_BN_CLICKED(IDC_BUTTON_ADVANCED, OnButtonAdvanced)
  103. ON_BN_CLICKED(IDC_CHECK_USE_PROXY, OnCheckUseProxy)
  104. ON_BN_CLICKED(IDC_CHECK_REQUIRE_RESET, OnCheckRequireReset)
  105. ON_CBN_SELCHANGE(IDC_COMBO_AUTHENTICATION, OnEditchangeComboAuthentication)
  106. ON_EN_CHANGE(IDC_EDIT_PASSWORD, OnChangeEditPassword)
  107. ON_EN_CHANGE(IDC_EDIT_PROXY_ADDRESS, OnChangeEditProxyAddress)
  108. ON_EN_CHANGE(IDC_EDIT_PROXY_PORT, OnChangeEditProxyPort)
  109. ON_EN_CHANGE(IDC_EDIT_TIMEOUT, OnChangeEditTimeout)
  110. ON_EN_CHANGE(IDC_EDIT_URL, OnChangeEditUrl)
  111. ON_EN_CHANGE(IDC_EDIT_USER_NAME, OnChangeEditUserName)
  112. //}}AFX_MSG_MAP
  113. END_MESSAGE_MAP()
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CDPHttpPage message handlers
  116. BOOL CDPHttpPage::OnInitDialog()
  117. {
  118. // v-marfin : bug 59643 : This will be the default starting page for the property
  119. // sheet so call CnxPropertyPageCreate() to unmarshal the
  120. // connection for this thread. This function must be called
  121. // by the first page of the property sheet. It used to
  122. // be called by the "General" page and its call still remains
  123. // there as well in case the general page is loaded by a
  124. // different code path that does not also load this page.
  125. // The CnxPropertyPageCreate function has been safeguarded
  126. // to simply return if the required call has already been made.
  127. // CnxPropertyPageDestory() must be called from this page's
  128. // OnDestroy function.
  129. // unmarshal connmgr
  130. CnxPropertyPageCreate();
  131. CHMPropertyPage::OnInitDialog();
  132. // v-marfin Bug 61451
  133. // Load combobox
  134. LoadAuthTypeCombo();
  135. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  136. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  137. {
  138. return TRUE;
  139. }
  140. //-------------------------------------------------------------------------
  141. // v-marfin 59237 : Store original name in case this data collector is
  142. // just being created. When they save, we will modify the
  143. // name if they haven't.
  144. pClassObject->GetProperty(IDS_STRING_MOF_NAME,m_sOriginalName);
  145. //-------------------------------------------------------------------------
  146. CString sPath;
  147. pClassObject->GetProperty(IDS_STRING_MOF_PATH,sPath);
  148. if( ! sPath.IsEmpty() )
  149. {
  150. // parse out the Method property value
  151. CWbemClassObject::GetPropertyValueFromString(sPath,_T("Method"),m_sMethod);
  152. // v-marfin Bug 61451
  153. // parse out the AuthType property value and set appropriate value
  154. // in the dropdown combo
  155. CString sAuthType;
  156. CWbemClassObject::GetPropertyValueFromString(sPath,_T("AuthType"),sAuthType);
  157. if( ! sAuthType.IsEmpty() )
  158. {
  159. m_iAuthType = _ttoi(sAuthType);
  160. SetAuthTypeCombo();
  161. }
  162. // parse out the Url property value
  163. CWbemClassObject::GetPropertyValueFromString(sPath,_T("Url"),m_sURL);
  164. CSnapInApp* pApp = (CSnapInApp*) AfxGetApp();
  165. m_sURL = pApp->UnEscapeSpecialChars(m_sURL); // v-marfin bug 60233
  166. // parse out the TimeoutSecs property value
  167. CString sTimeout;
  168. CWbemClassObject::GetPropertyValueFromString(sPath,_T("TimeoutMSecs"),sTimeout);
  169. if( ! sTimeout.IsEmpty() )
  170. {
  171. // v-marfin: 60632
  172. // timeout is stored in milliseconds but we display in seconds so
  173. // adjust accordingly.
  174. m_fTimeout = (float) _ttol(sTimeout);
  175. m_fTimeout /= 1000;
  176. }
  177. // parse out the AuthUser property value
  178. CWbemClassObject::GetPropertyValueFromString(sPath,_T("AuthUser"),m_sUserName);
  179. m_sUserName = pApp->UnEscapeSpecialChars(m_sUserName); // v-marfin bug 60233
  180. // parse out the AuthPassword property value
  181. CWbemClassObject::GetPropertyValueFromString(sPath,_T("AuthPassword"),m_sPassword);
  182. m_sPassword = pApp->UnEscapeSpecialChars(m_sPassword); // v-marfin bug 60233
  183. // parse out the ProxyServer property value
  184. CWbemClassObject::GetPropertyValueFromString(sPath,_T("ProxyServer"),m_sProxyAddress);
  185. m_sProxyAddress = pApp->UnEscapeSpecialChars(m_sProxyAddress); // v-marfin bug 60233
  186. if( ! m_sProxyAddress.IsEmpty() )
  187. {
  188. int iIndex = -1;
  189. m_bUseProxy = m_sProxyAddress.IsEmpty() ? FALSE : TRUE;
  190. if( (iIndex = m_sProxyAddress.Find(_T(":"))) != -1 )
  191. {
  192. m_sProxyPort = m_sProxyAddress.Right(m_sProxyAddress.GetLength()-iIndex-1);
  193. m_sProxyAddress = m_sProxyAddress.Left(iIndex);
  194. }
  195. }
  196. // parse out the ExtraHeaders property value
  197. CWbemClassObject::GetPropertyValueFromString(sPath,_T("ExtraHeaders"),m_sExtraHeaders);
  198. m_sExtraHeaders = UnconvertSpecialChars(m_sExtraHeaders); // 63116
  199. // parse out the PostData property value
  200. CWbemClassObject::GetPropertyValueFromString(sPath,_T("PostData"),m_sPostData);
  201. m_sPostData = UnconvertSpecialChars(m_sPostData); // 63116
  202. // parse out the FollowRedirects property value
  203. CString sFollowRedirects;
  204. CWbemClassObject::GetPropertyValueFromString(sPath,_T("FollowRedirects"),sFollowRedirects);
  205. if( ! sFollowRedirects.IsEmpty() )
  206. {
  207. m_bFollowRedirects = _ttoi(sFollowRedirects);
  208. }
  209. }
  210. // set require reset
  211. bool bReset;
  212. pClassObject->GetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  213. m_bRequireReset = bReset;
  214. delete pClassObject;
  215. // v-marfin 59579
  216. if (m_iAuthType == 0)
  217. {
  218. m_sUserName.Empty();
  219. m_sPassword.Empty();
  220. GetDlgItem(IDC_EDIT_USER_NAME)->EnableWindow(FALSE);
  221. GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(FALSE);
  222. }
  223. UpdateData(FALSE);
  224. return TRUE; // return TRUE unless you set the focus to a control
  225. // EXCEPTION: OCX Property Pages should return FALSE
  226. }
  227. void CDPHttpPage::OnDestroy()
  228. {
  229. // v-marfin 62585 : For this new data collector, set its Enabled property to TRUE, but
  230. // only if the user is not cancelling these property pages.
  231. if (m_bOnApplyUsed)
  232. {
  233. ClearStatistics(); // 62548
  234. CDataElement* pElement = (CDataElement*)GetObjectPtr();
  235. if (pElement && pElement->IsStateSetToEnabledOnOK())
  236. {
  237. TRACE(_T("CDPHttpPage::OnDestroy - New Perfmon Collector: Setting to Enabled\n"));
  238. pElement->SetStateToEnabledOnOK(FALSE); // don't do this again
  239. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  240. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  241. {
  242. TRACE(_T("ERROR: CDPHttpPage::OnDestroy - Failed to GetClassObject()\n"));
  243. return;
  244. }
  245. // Set the new collector to enabled.
  246. BOOL bEnabled=TRUE;
  247. HRESULT hr = pClassObject->GetProperty(IDS_STRING_MOF_ENABLE,bEnabled);
  248. hr = pClassObject->SetProperty(IDS_STRING_MOF_ENABLE,TRUE);
  249. if (!CHECKHRESULT(hr))
  250. {
  251. TRACE(_T("ERROR: CDPHttpPage::OnOK - Failed to set ENABLED property on new collector\n"));
  252. }
  253. //-------------------------------------------------------------------
  254. // v-marfin 59237 : If the user has not changed the original default
  255. // name, do so for them. Compare against original
  256. // name we fetched during OnInitDialog.
  257. CString sName;
  258. pClassObject->GetProperty(IDS_STRING_MOF_NAME,sName);
  259. // Did the user change the default name?
  260. if (m_sOriginalName.CompareNoCase(sName)==0)
  261. {
  262. // No, so set the new name
  263. if (!m_sURL.IsEmpty())
  264. {
  265. // Use parent to ensure name is unique
  266. //CDataGroup* pParent = (CDataGroup*) pElement->GetCollectorsParentClassObject();
  267. if(pElement->GetScopeItemCount())
  268. {
  269. CDataElementScopeItem* pItem = (CDataElementScopeItem*)pElement->GetScopeItem(0);
  270. if( pItem )
  271. {
  272. CDataGroupScopeItem* pDGItem = (CDataGroupScopeItem*)pItem->GetParent();
  273. sName = pDGItem->GetUniqueDisplayName(m_sURL);
  274. }
  275. }
  276. // Set the local element's object data
  277. pElement->SetName(sName);
  278. // Set its WMI property
  279. pClassObject->SetProperty(IDS_STRING_MOF_NAME,sName);
  280. // Refresh to show the new name in the IU
  281. //pElement->Refresh(); // 63005
  282. pElement->UpdateStatus(); // 63005
  283. }
  284. }
  285. //-------------------------------------------------------------------
  286. pClassObject->SaveAllProperties();
  287. delete pClassObject;
  288. } // if (pElement && pElement->IsStateSetToEnabledOnOK())
  289. }
  290. // if (m_bOnApplyUsed)
  291. CHMPropertyPage::OnDestroy();
  292. // v-marfin : bug 59643 : CnxPropertyPageDestory() must be called from this page's
  293. // OnDestroy function.
  294. CnxPropertyPageDestroy();
  295. }
  296. void CDPHttpPage::OnOK()
  297. {
  298. CHMPropertyPage::OnOK();
  299. }
  300. void CDPHttpPage::OnButtonAdvanced()
  301. {
  302. CHttpAdvancedDlg dlg;
  303. dlg.m_bFollowRedirects = m_bFollowRedirects;
  304. dlg.m_sExtraHeaders = m_sExtraHeaders;
  305. dlg.m_sHTTPMethod = m_sMethod;
  306. dlg.m_sPostData = m_sPostData;
  307. if( dlg.DoModal() == IDOK )
  308. {
  309. m_bFollowRedirects = dlg.m_bFollowRedirects;
  310. m_sExtraHeaders = dlg.m_sExtraHeaders;
  311. m_sMethod = dlg.m_sHTTPMethod;
  312. m_sPostData = dlg.m_sPostData;
  313. SetModified();
  314. }
  315. }
  316. void CDPHttpPage::OnCheckUseProxy()
  317. {
  318. UpdateData();
  319. SetModified();
  320. }
  321. BOOL CDPHttpPage::OnApply()
  322. {
  323. if( ! CHMPropertyPage::OnApply() )
  324. {
  325. return FALSE;
  326. }
  327. // v-marfin 62585 : So we can set the collector's state to enabled when OK pressed.
  328. m_bOnApplyUsed=TRUE;
  329. UpdateData();
  330. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  331. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  332. {
  333. return FALSE;
  334. }
  335. CString sPath = _T("HTTPProvider.");
  336. // parse out the Method property value
  337. if( ! m_sMethod.IsEmpty() )
  338. {
  339. sPath += _T("Method=\"");
  340. sPath += m_sMethod;
  341. sPath += _T("\",");
  342. }
  343. CSnapInApp* pApp = (CSnapInApp*) AfxGetApp();
  344. // parse out the Url property value
  345. if( ! m_sURL.IsEmpty() )
  346. {
  347. sPath += _T("Url=\"");
  348. sPath += pApp->EscapeSpecialChars(m_sURL); // v-marfin bug 60233
  349. sPath += _T("\",");
  350. }
  351. // parse out the TimeoutSecs property value
  352. // v-marfin: 60632
  353. // Since timeout is displayed seconds but stored in milliseconds,
  354. // we need to multiply it by 1000.
  355. m_fTimeout = (float) fabs((double)(m_fTimeout * 1000));
  356. CString sTimeout;
  357. sTimeout.Format(_T("%d"),(int)m_fTimeout);
  358. sPath += _T("TimeoutMSecs=");
  359. sPath += sTimeout;
  360. sPath += _T(",");
  361. // v-marfin : 60632
  362. // Now put m_fTimeout back to its original
  363. m_fTimeout /= 1000;
  364. // v-marfin Bug 61451
  365. // parse out the AuthType property value
  366. if (GetAuthTypeFromCombo())
  367. {
  368. CString sAuthType;
  369. sAuthType.Format(_T("%d"),m_iAuthType);
  370. sPath += _T("AuthType=");
  371. sPath += sAuthType;
  372. sPath += _T(",");
  373. }
  374. // parse out the AuthUser property value
  375. if( ! m_sUserName.IsEmpty() )
  376. {
  377. sPath += _T("AuthUser=\"");
  378. sPath += pApp->EscapeSpecialChars(m_sUserName); // v-marfin bug 60233
  379. sPath += _T("\",");
  380. }
  381. // parse out the AuthPassword property value
  382. if( ! m_sPassword.IsEmpty() )
  383. {
  384. sPath += _T("AuthPassword=\"");
  385. sPath += pApp->EscapeSpecialChars(m_sPassword); // v-marfin bug 60233
  386. sPath += _T("\",");
  387. }
  388. // parse out the ProxyServer property value
  389. if( ! m_sProxyAddress.IsEmpty() && m_bUseProxy )
  390. {
  391. sPath += _T("ProxyServer=\"");
  392. sPath += pApp->EscapeSpecialChars(m_sProxyAddress) + _T(":") + m_sProxyPort; // v-marfin bug 60233
  393. sPath += _T("\",");
  394. }
  395. // parse out the ExtraHeaders property value
  396. if( ! m_sExtraHeaders.IsEmpty() )
  397. {
  398. sPath += _T("ExtraHeaders=\"");
  399. sPath += ConvertSpecialChars(m_sExtraHeaders); // 63116
  400. sPath += _T("\",");
  401. }
  402. // parse out the PostData property value
  403. if( ! m_sPostData.IsEmpty() )
  404. {
  405. sPath += _T("PostData=\"");
  406. sPath += ConvertSpecialChars(m_sPostData); // 63116
  407. sPath += _T("\",");
  408. }
  409. // parse out the FollowRedirects property value
  410. CString sFollowRedirects;
  411. sFollowRedirects.Format(_T("%d"),m_bFollowRedirects);
  412. sPath += _T("FollowRedirects=");
  413. sPath += sFollowRedirects;
  414. pClassObject->SetProperty(IDS_STRING_MOF_PATH,sPath);
  415. // set target namespace
  416. CString sNamespace = _T("root\\cimv2\\MicrosoftHealthmonitor");
  417. pClassObject->SetProperty(IDS_STRING_MOF_TARGETNAMESPACE,sNamespace);
  418. // set statistics properties
  419. /* 63128
  420. CStringArray saNames;
  421. saNames.Add(_T("StatusCode"));
  422. saNames.Add(_T("StatusText"));
  423. saNames.Add(_T("ContentLength"));
  424. saNames.Add(_T("TextResponse"));
  425. saNames.Add(_T("RawHeaders"));
  426. saNames.Add(_T("ContentType"));
  427. saNames.Add(_T("Cookie"));
  428. saNames.Add(_T("LastModified"));
  429. saNames.Add(_T("ResponseTime"));
  430. pClassObject->SetProperty(IDS_STRING_MOF_STATISTICSPROPERTYNAMES,saNames);*/
  431. bool bReset = m_bRequireReset ? true : false;
  432. pClassObject->SetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  433. pClassObject->SaveAllProperties();
  434. delete pClassObject;
  435. SetModified(FALSE);
  436. return TRUE;
  437. }
  438. void CDPHttpPage::OnCheckRequireReset()
  439. {
  440. SetModified();
  441. }
  442. void CDPHttpPage::OnEditchangeComboAuthentication()
  443. {
  444. // v-marfin 59579 : If "None" selected as authentication, disable the
  445. // Username and Password.
  446. UpdateData();
  447. GetAuthTypeFromCombo();
  448. BOOL bNoneSelected = (m_iAuthType == 0);
  449. if (bNoneSelected)
  450. {
  451. m_sUserName.Empty();
  452. m_sPassword.Empty();
  453. }
  454. UpdateData(FALSE);
  455. GetDlgItem(IDC_EDIT_USER_NAME)->EnableWindow(!bNoneSelected);
  456. GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(!bNoneSelected);
  457. SetModified();
  458. }
  459. void CDPHttpPage::OnChangeEditPassword()
  460. {
  461. // TODO: If this is a RICHEDIT control, the control will not
  462. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  463. // function and call CRichEditCtrl().SetEventMask()
  464. // with the ENM_CHANGE flag ORed into the mask.
  465. SetModified();
  466. }
  467. void CDPHttpPage::OnChangeEditProxyAddress()
  468. {
  469. // TODO: If this is a RICHEDIT control, the control will not
  470. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  471. // function and call CRichEditCtrl().SetEventMask()
  472. // with the ENM_CHANGE flag ORed into the mask.
  473. SetModified();
  474. }
  475. void CDPHttpPage::OnChangeEditProxyPort()
  476. {
  477. // TODO: If this is a RICHEDIT control, the control will not
  478. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  479. // function and call CRichEditCtrl().SetEventMask()
  480. // with the ENM_CHANGE flag ORed into the mask.
  481. SetModified();
  482. }
  483. void CDPHttpPage::OnChangeEditTimeout()
  484. {
  485. // TODO: If this is a RICHEDIT control, the control will not
  486. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  487. // function and call CRichEditCtrl().SetEventMask()
  488. // with the ENM_CHANGE flag ORed into the mask.
  489. SetModified();
  490. }
  491. void CDPHttpPage::OnChangeEditUrl()
  492. {
  493. // TODO: If this is a RICHEDIT control, the control will not
  494. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  495. // function and call CRichEditCtrl().SetEventMask()
  496. // with the ENM_CHANGE flag ORed into the mask.
  497. SetModified();
  498. }
  499. void CDPHttpPage::OnChangeEditUserName()
  500. {
  501. // TODO: If this is a RICHEDIT control, the control will not
  502. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  503. // function and call CRichEditCtrl().SetEventMask()
  504. // with the ENM_CHANGE flag ORed into the mask.
  505. SetModified();
  506. }
  507. // v-marfin Bug 61451
  508. //*********************************************************
  509. // SetAuthTypeCombo
  510. //
  511. // Set the combo box entry to the value corresponding with the
  512. // member variable
  513. //
  514. // Parms: None
  515. // Returns: TRUE - success
  516. // FALSE - failed
  517. //*********************************************************
  518. BOOL CDPHttpPage::SetAuthTypeCombo()
  519. {
  520. int x=0;
  521. int nAuthType=0;
  522. int nCount=0;
  523. // Get a ptr to the combobox
  524. CComboBox* pBox = (CComboBox*)GetDlgItem(IDC_COMBO_AUTHENTICATION);
  525. if (!pBox)
  526. {
  527. _ASSERTE(FALSE);
  528. return FALSE;
  529. }
  530. // get the number of entries in the combo
  531. nCount = pBox->GetCount();
  532. // Search through each entry
  533. for (x=0; x<nCount; x++)
  534. {
  535. // Get the type of this entry
  536. nAuthType = (int)pBox->GetItemData(x);
  537. _ASSERTE(nAuthType != CB_ERR);
  538. // Is this entry type the one we want?
  539. if (nAuthType == m_iAuthType)
  540. {
  541. // yes. Set this as the selected item and get out
  542. pBox->SetCurSel(x);
  543. return TRUE;
  544. }
  545. }
  546. _ASSERTE(FALSE); // should never get here
  547. return FALSE;
  548. }
  549. // v-marfin Bug 61451
  550. //*********************************************************
  551. // LoadAuthTypeCombo
  552. //
  553. // Loads the combo box from predefined values and sets the
  554. // data item associated with each item to its associated value.
  555. //
  556. // Since the combo is NOT sorted, set the 1st entry to "selected"
  557. // upon loading it. Later in the initialization, if the user
  558. // had saved a previous value it will be set to that.
  559. //
  560. // Parms: None
  561. // Returns: None
  562. //*********************************************************
  563. void CDPHttpPage::LoadAuthTypeCombo()
  564. {
  565. int nRet=0;
  566. // Load the combo in the following order:
  567. /*
  568. #define AUTHTYPE_VALUE_NONE_STRING _T("None")
  569. #define AUTHTYPE_VALUE_BASIC_STRING _T("Clear Text (Basic)")
  570. #define AUTHTYPE_VALUE_NEGOTIATE_STRING _T("Windows Default (Negotiate)")
  571. #define AUTHTYPE_VALUE_NTLM_STRING _T("NTLM")
  572. #define AUTHTYPE_VALUE_DIGEST_STRING _T("Digest")
  573. #define AUTHTYPE_VALUE_KERBEROS_STRING _T("Kerberos")
  574. */
  575. // Get a ptr to the combobox
  576. CComboBox* pBox = (CComboBox*)GetDlgItem(IDC_COMBO_AUTHENTICATION);
  577. if (!pBox)
  578. {
  579. _ASSERTE(FALSE);
  580. return;
  581. }
  582. // Empty it
  583. pBox->ResetContent();
  584. // Load it
  585. // AuthType None
  586. nRet = pBox->AddString(AUTHTYPE_VALUE_NONE_STRING);
  587. if (nRet == CB_ERR)
  588. {
  589. _ASSERTE(FALSE);
  590. return;
  591. }
  592. else
  593. {
  594. pBox->SetItemData(nRet,AUTHTYPE_VALUE_NONE);
  595. }
  596. // AuthType Basic
  597. nRet = pBox->AddString(AUTHTYPE_VALUE_BASIC_STRING);
  598. if (nRet == CB_ERR)
  599. {
  600. _ASSERTE(FALSE);
  601. return;
  602. }
  603. else
  604. {
  605. pBox->SetItemData(nRet,AUTHTYPE_VALUE_BASIC);
  606. }
  607. // AuthType Negotiate
  608. nRet = pBox->AddString(AUTHTYPE_VALUE_NEGOTIATE_STRING);
  609. if (nRet == CB_ERR)
  610. {
  611. _ASSERTE(FALSE);
  612. return;
  613. }
  614. else
  615. {
  616. pBox->SetItemData(nRet,AUTHTYPE_VALUE_NEGOTIATE);
  617. }
  618. // AuthType NTLM
  619. nRet = pBox->AddString(AUTHTYPE_VALUE_NTLM_STRING);
  620. if (nRet == CB_ERR)
  621. {
  622. _ASSERTE(FALSE);
  623. return;
  624. }
  625. else
  626. {
  627. pBox->SetItemData(nRet,AUTHTYPE_VALUE_NTLM);
  628. }
  629. // AuthType Digest
  630. nRet = pBox->AddString(AUTHTYPE_VALUE_DIGEST_STRING);
  631. if (nRet == CB_ERR)
  632. {
  633. _ASSERTE(FALSE);
  634. return;
  635. }
  636. else
  637. {
  638. pBox->SetItemData(nRet,AUTHTYPE_VALUE_DIGEST);
  639. }
  640. // AuthType Kerberos
  641. nRet = pBox->AddString(AUTHTYPE_VALUE_KERBEROS_STRING);
  642. if (nRet == CB_ERR)
  643. {
  644. _ASSERTE(FALSE);
  645. return;
  646. }
  647. else
  648. {
  649. pBox->SetItemData(nRet,AUTHTYPE_VALUE_KERBEROS);
  650. }
  651. // Set the 1st entry as selected by default ("None")
  652. pBox->SetCurSel(0);
  653. }
  654. // v-marfin Bug 61451
  655. //*********************************************************
  656. // GetAuthTypeFromCombo
  657. //
  658. // Gets the numeric value of the currently selected AuthType
  659. // from the combobox
  660. //
  661. // Parms: None
  662. // Returns: TRUE - success
  663. // FALSE - failed
  664. //*********************************************************
  665. BOOL CDPHttpPage::GetAuthTypeFromCombo()
  666. {
  667. // Get a ptr to the combobox
  668. CComboBox* pBox = (CComboBox*)GetDlgItem(IDC_COMBO_AUTHENTICATION);
  669. if (!pBox)
  670. {
  671. _ASSERTE(FALSE);
  672. return FALSE;
  673. }
  674. // Get the current selection.
  675. int nRet = pBox->GetCurSel();
  676. if (nRet == CB_ERR)
  677. {
  678. _ASSERTE(FALSE);
  679. return FALSE;
  680. }
  681. // Get the authtype of the selected item
  682. nRet = (int)pBox->GetItemData(nRet);
  683. if (nRet == CB_ERR)
  684. {
  685. _ASSERTE(FALSE);
  686. return FALSE;
  687. }
  688. // OK. Set our local member to it.
  689. m_iAuthType = nRet;
  690. return TRUE;
  691. }
  692. //***************************************************************
  693. // ConvertSpecialChars 63116 Converts \r\n to "%0D%0A" and adds trailing "%0D%0A"
  694. //***************************************************************
  695. CString CDPHttpPage::ConvertSpecialChars(const CString &sString)
  696. {
  697. CString sRet;
  698. int nPos=0;
  699. CString sCRLF = _T("\r\n");
  700. CString sFormattedCRLF = _T("%0D%0A");
  701. if (sString.IsEmpty())
  702. return sRet;
  703. CString sWrk = sString;
  704. // remove any leading / trailing crlf
  705. while (sWrk.Right(sCRLF.GetLength()).CompareNoCase(sCRLF)==0)
  706. {
  707. sWrk = sWrk.Left(sWrk.GetLength()-sCRLF.GetLength());
  708. }
  709. while (sWrk.Left(sCRLF.GetLength()).CompareNoCase(sCRLF)==0)
  710. {
  711. sWrk = sWrk.Mid(sCRLF.GetLength());
  712. }
  713. while (sWrk.GetLength())
  714. {
  715. nPos = sWrk.Find(sCRLF);
  716. if (nPos == -1)
  717. break;
  718. sRet += sWrk.Mid(0,nPos); // take chars before CRLF
  719. sRet += sFormattedCRLF; // add "%0D%0A"
  720. sWrk = sWrk.Mid(nPos+sCRLF.GetLength());
  721. }
  722. // Add final
  723. sRet += sWrk;
  724. sRet += sFormattedCRLF;
  725. return sRet;
  726. }
  727. //***************************************************************
  728. // UnconvertSpecialChars 63116 converts "%0D%0A" to \r\n and removes trailing "%0D%0A"
  729. //***************************************************************
  730. CString CDPHttpPage::UnconvertSpecialChars(const CString &sString)
  731. {
  732. CString sRet;
  733. int nPos=0;
  734. CString sCRLF = _T("\r\n");
  735. CString sFormattedCRLF = _T("%0D%0A");
  736. if (sString.IsEmpty())
  737. return sRet;
  738. CString sWrk = sString;
  739. // remove any leading / trailing "%0D%0A"
  740. while (sWrk.Right(sFormattedCRLF.GetLength()).CompareNoCase(sFormattedCRLF)==0)
  741. {
  742. sWrk = sWrk.Left(sWrk.GetLength()-sFormattedCRLF.GetLength());
  743. }
  744. while (sWrk.Left(sFormattedCRLF.GetLength()).CompareNoCase(sFormattedCRLF)==0)
  745. {
  746. sWrk = sWrk.Mid(sFormattedCRLF.GetLength());
  747. }
  748. while (sWrk.GetLength())
  749. {
  750. nPos = sWrk.Find(sFormattedCRLF);
  751. if (nPos == -1)
  752. break;
  753. sRet += sWrk.Mid(0,nPos); // take chars before "%0D%0A"
  754. sRet += sCRLF; // add "\r\n"
  755. sWrk = sWrk.Mid(nPos+sFormattedCRLF.GetLength());
  756. }
  757. // Add final
  758. sRet += sWrk;
  759. // Remove trailing
  760. while (sRet.Right(sCRLF.GetLength()).CompareNoCase(sCRLF)==0)
  761. {
  762. sRet = sRet.Left(sRet.GetLength()-sCRLF.GetLength());
  763. }
  764. return sRet;
  765. }