Leaked source code of windows server 2003
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.

502 lines
9.2 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name :
  4. fltdlg.cpp
  5. Abstract:
  6. WWW Filters Property Dialog
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Sergei Antonov (sergeia)
  10. Project:
  11. Internet Services Manager
  12. Revision History:
  13. --*/
  14. #include "stdafx.h"
  15. #include "common.h"
  16. #include "inetprop.h"
  17. #include "InetMgrApp.h"
  18. #include "shts.h"
  19. #include "w3sht.h"
  20. #include "fltdlg.h"
  21. extern CInetmgrApp theApp;
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. #define FILTER_NAME_MAX 24
  28. CFilterDlg::CFilterDlg(
  29. IN OUT CIISFilter & flt,
  30. IN CIISFilterList * & pFilters,
  31. IN BOOL fLocal,
  32. IN CWnd * pParent OPTIONAL
  33. )
  34. /*++
  35. Routine Description:
  36. Filter properties dialog constructor
  37. Arguments:
  38. CIISFilter & flt : Filter being edited
  39. CFilters * & pFilters : List of filters that exist
  40. BOOL fLocal : TRUE on the local system
  41. CWnd * pParent OPTIONAL : Optional parent window
  42. Return Value:
  43. N/A
  44. --*/
  45. : CDialog(CFilterDlg::IDD, pParent),
  46. m_fLocal(fLocal),
  47. m_pFilters(pFilters),
  48. m_fEditMode(FALSE),
  49. m_flt(flt)
  50. {
  51. //{{AFX_DATA_INIT(CFilterDlg)
  52. m_strExecutable = m_flt.m_strExecutable;
  53. m_strFilterName = m_flt.m_strName;
  54. //}}AFX_DATA_INIT
  55. //
  56. // Map priority to string ID
  57. //
  58. m_strPriority.LoadString(IDS_HIGH + 3 - m_flt.m_nPriority);
  59. }
  60. static BOOL
  61. PathIsValidFilter(LPCTSTR path)
  62. {
  63. LPCTSTR p = path;
  64. BOOL rc = TRUE;
  65. if (p == NULL || *p == 0)
  66. return FALSE;
  67. while (*p != 0)
  68. {
  69. switch (*p)
  70. {
  71. case TEXT('|'):
  72. case TEXT('>'):
  73. case TEXT('<'):
  74. case TEXT('/'):
  75. case TEXT('?'):
  76. case TEXT('*'):
  77. // case TEXT(';'):
  78. case TEXT(','):
  79. case TEXT('"'):
  80. rc = FALSE;
  81. break;
  82. default:
  83. if (*p < TEXT(' '))
  84. {
  85. rc = FALSE;
  86. }
  87. break;
  88. }
  89. if (!rc)
  90. {
  91. break;
  92. }
  93. p++;
  94. }
  95. return rc;
  96. }
  97. static BOOL
  98. PathIsValidFilterName(LPCTSTR name)
  99. {
  100. LPCTSTR p = name;
  101. BOOL rc = TRUE;
  102. if (p == NULL || *p == 0)
  103. return FALSE;
  104. while (*p != 0)
  105. {
  106. switch (*p)
  107. {
  108. case TEXT('|'):
  109. case TEXT('>'):
  110. case TEXT('<'):
  111. case TEXT('/'):
  112. case TEXT('\\'):
  113. case TEXT('?'):
  114. case TEXT('*'):
  115. case TEXT(';'):
  116. case TEXT(','):
  117. case TEXT('"'):
  118. rc = FALSE;
  119. break;
  120. default:
  121. if (*p < TEXT(' '))
  122. {
  123. rc = FALSE;
  124. }
  125. break;
  126. }
  127. if (!rc)
  128. {
  129. break;
  130. }
  131. p++;
  132. }
  133. return rc;
  134. }
  135. void
  136. CFilterDlg::DoDataExchange(
  137. IN CDataExchange * pDX
  138. )
  139. /*++
  140. Routine Description:
  141. Initialise/Store control data
  142. Arguments:
  143. CDataExchange * pDX - DDX/DDV control structure
  144. Return Value:
  145. None
  146. --*/
  147. {
  148. CDialog::DoDataExchange(pDX);
  149. //{{AFX_DATA_MAP(CFilterDlg)
  150. DDX_Control(pDX, IDC_STATIC_PRIORITY_VALUE, m_static_Priority);
  151. DDX_Control(pDX, IDC_STATIC_PRIORITY, m_static_PriorityPrompt);
  152. DDX_Control(pDX, IDOK, m_button_Ok);
  153. DDX_Control(pDX, IDC_EDIT_FILTERNAME, m_edit_FilterName);
  154. DDX_Control(pDX, IDC_EDIT_EXECUTABLE, m_edit_Executable);
  155. DDX_Control(pDX, IDC_BUTTON_BROWSE, m_button_Browse);
  156. DDX_Text(pDX, IDC_STATIC_PRIORITY_VALUE, m_strPriority);
  157. //}}AFX_DATA_MAP
  158. DDX_Text(pDX, IDC_EDIT_EXECUTABLE, m_strExecutable);
  159. if (pDX->m_bSaveAndValidate)
  160. {
  161. DDV_FilePath(pDX, m_strExecutable, m_fLocal);
  162. }
  163. DDX_Text(pDX, IDC_EDIT_FILTERNAME, m_strFilterName);
  164. DDV_MaxCharsBalloon(pDX, m_strFilterName, FILTER_NAME_MAX);
  165. if (pDX->m_bSaveAndValidate)
  166. {
  167. m_strFilterName.TrimLeft();
  168. m_strFilterName.TrimRight();
  169. if (m_strFilterName.IsEmpty() || !PathIsValidFilterName(m_strFilterName))
  170. {
  171. DDV_ShowBalloonAndFail(pDX, IDS_ERR_INVALID_FILTER_NAME);
  172. }
  173. }
  174. }
  175. //
  176. // Message Map
  177. //
  178. BEGIN_MESSAGE_MAP(CFilterDlg, CDialog)
  179. //{{AFX_MSG_MAP(CFilterDlg)
  180. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  181. ON_BN_CLICKED(ID_HELP, OnHelp)
  182. ON_EN_CHANGE(IDC_EDIT_EXECUTABLE, OnExecutableChanged)
  183. //}}AFX_MSG_MAP
  184. ON_EN_CHANGE(IDC_EDIT_FILTERNAME, OnItemChanged)
  185. END_MESSAGE_MAP()
  186. //
  187. // Message Handlers
  188. //
  189. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  190. BOOL
  191. CFilterDlg::OnInitDialog()
  192. /*++
  193. Routine Description:
  194. WM_INITDIALOG handler. Initialize the dialog.
  195. Arguments:
  196. None.
  197. Return Value:
  198. TRUE if no focus is to be set automatically, FALSE if the focus
  199. is already set.
  200. --*/
  201. {
  202. CDialog::OnInitDialog();
  203. //
  204. // Available on local connections only
  205. //
  206. m_button_Browse.EnableWindow(m_fLocal);
  207. if ((m_fEditMode = m_edit_FilterName.GetWindowTextLength() > 0))
  208. {
  209. m_edit_FilterName.SetReadOnly();
  210. }
  211. SetControlStates();
  212. #ifdef SUPPORT_SLASH_SLASH_QUESTIONMARK_SLASH_TYPE_PATHS
  213. LimitInputPath(CONTROL_HWND(IDC_EDIT_EXECUTABLE),TRUE);
  214. #else
  215. LimitInputPath(CONTROL_HWND(IDC_EDIT_EXECUTABLE),FALSE);
  216. #endif
  217. return TRUE;
  218. }
  219. void
  220. CFilterDlg::OnHelp()
  221. {
  222. WinHelpDebug(0x20000 + CFilterDlg::IDD);
  223. ::WinHelp(m_hWnd, theApp.m_pszHelpFilePath, HELP_CONTEXT, 0x20000 + CFilterDlg::IDD);
  224. }
  225. void
  226. CFilterDlg::OnButtonBrowse()
  227. /*++
  228. Routine Description:
  229. Browse button handler
  230. Arguments:
  231. None
  232. Return Value:
  233. None
  234. --*/
  235. {
  236. ASSERT(m_fLocal);
  237. CString strFilterMask((LPCTSTR)IDS_FILTER_MASK);
  238. //
  239. // CODEWORK: Derive a class from CFileDialog that allows
  240. // the setting of the initial path
  241. //
  242. //CString strPath;
  243. //m_edit_Executable.GetWindowText(strPath);
  244. CFileDialog dlgBrowse(
  245. TRUE,
  246. NULL,
  247. NULL,
  248. OFN_HIDEREADONLY,
  249. strFilterMask,
  250. this
  251. );
  252. // Disable hook to get Windows 2000 style dialog
  253. dlgBrowse.m_ofn.Flags &= ~(OFN_ENABLEHOOK);
  254. dlgBrowse.m_ofn.Flags |= OFN_DONTADDTORECENT|OFN_FILEMUSTEXIST;
  255. INT_PTR rc = dlgBrowse.DoModal();
  256. if (rc == IDOK)
  257. {
  258. m_edit_Executable.SetWindowText(dlgBrowse.GetPathName());
  259. }
  260. else if (rc == IDCANCEL)
  261. {
  262. DWORD err = CommDlgExtendedError();
  263. }
  264. OnItemChanged();
  265. }
  266. void
  267. CFilterDlg::SetControlStates()
  268. /*++
  269. Routine Description:
  270. Set the states of the dialog control depending on its current
  271. values.
  272. Arguments:
  273. BOOL fAllowAnonymous : If TRUE, 'allow anonymous' is on.
  274. Return Value:
  275. None
  276. --*/
  277. {
  278. m_button_Ok.EnableWindow(
  279. m_edit_FilterName.GetWindowTextLength() > 0
  280. && m_edit_Executable.GetWindowTextLength() > 0);
  281. ActivateControl(m_static_PriorityPrompt, m_flt.m_nPriority != FLTR_PR_INVALID);
  282. ActivateControl(m_static_Priority, m_flt.m_nPriority != FLTR_PR_INVALID);
  283. }
  284. void
  285. CFilterDlg::OnItemChanged()
  286. /*++
  287. Routine Description:
  288. Register a change in control value on this page. Mark the page as dirty.
  289. All change messages map to this function
  290. Arguments:
  291. None
  292. Return Value:
  293. None
  294. --*/
  295. {
  296. SetControlStates();
  297. }
  298. void
  299. CFilterDlg::OnExecutableChanged()
  300. /*++
  301. Routine Description:
  302. Handle change in executable edit box. Remove priority as this
  303. is no longer valid
  304. Arguments:
  305. None
  306. Return Value:
  307. None
  308. --*/
  309. {
  310. //
  311. // Priority no longer makes sense.
  312. //
  313. m_flt.m_nPriority = FLTR_PR_INVALID;
  314. OnItemChanged();
  315. }
  316. BOOL
  317. CFilterDlg::FilterNameExists(
  318. IN LPCTSTR lpName
  319. )
  320. /*++
  321. Routine Description:
  322. Look for a given filter name in the list
  323. Arguments:
  324. LPCTSTR lpName : Filter name to look for
  325. Return Value:
  326. TRUE if the name already existed in the list
  327. --*/
  328. {
  329. m_pFilters->ResetEnumerator();
  330. while(m_pFilters->MoreFilters())
  331. {
  332. CIISFilter * pFilter = m_pFilters->GetNextFilter();
  333. ASSERT(pFilter != NULL);
  334. if (!pFilter->IsFlaggedForDeletion())
  335. {
  336. if (!pFilter->m_strName.CompareNoCase(lpName))
  337. {
  338. return TRUE;
  339. }
  340. }
  341. }
  342. return FALSE;
  343. }
  344. void
  345. CFilterDlg::OnOK()
  346. /*++
  347. Routine Description:
  348. OK button handler. Save data
  349. Arguments:
  350. None
  351. Return Value:
  352. None
  353. --*/
  354. {
  355. if (UpdateData(TRUE))
  356. {
  357. //
  358. // Make sure the filter name is unique
  359. //
  360. if (!m_fEditMode && FilterNameExists(m_strFilterName))
  361. {
  362. EditShowBalloon(m_edit_FilterName.m_hWnd, IDS_ERR_DUP_FILTER);
  363. return;
  364. }
  365. m_flt.m_strExecutable = m_strExecutable;
  366. m_flt.m_strName = m_strFilterName;
  367. //
  368. // Anyway to load this from the DLL?
  369. //
  370. //m_flt.m_nPriority = FLTR_PR_MEDIUM;
  371. CDialog::OnOK();
  372. }
  373. //
  374. // Don't dismiss the dialog
  375. //
  376. }