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.

268 lines
7.0 KiB

  1. /****************************************************************************************
  2. * NAME: MatchCondition.cpp
  3. *
  4. * CLASS: CMatchCondition
  5. *
  6. * OVERVIEW
  7. *
  8. * Match type condition
  9. *
  10. * ex: MachineType MATCH <a..z*>
  11. *
  12. *
  13. * Copyright (C) Microsoft Corporation, 1998 - 1999 . All Rights Reserved.
  14. *
  15. * History:
  16. * 1/28/98 Created by Byao (using ATL wizard)
  17. *
  18. *****************************************************************************************/
  19. #include "precompiled.h"
  20. #include "MatchCondition.h"
  21. #include "MatchCondEdit.h"
  22. //////////////////////////////////////////////////////////////////////
  23. // Construction/Destruction
  24. //////////////////////////////////////////////////////////////////////
  25. CMatchCondition::CMatchCondition(IIASAttributeInfo* pCondAttr)
  26. :CCondition(pCondAttr)
  27. {
  28. TRACE_FUNCTION("CMatchCondition::CMatchCondition()");
  29. // we don't need to do the parsing since there's no condition text
  30. m_fParsed = TRUE;
  31. }
  32. CMatchCondition::CMatchCondition(IIASAttributeInfo* pCondAttr,
  33. ATL::CString& strConditionText
  34. )
  35. :CCondition(pCondAttr, strConditionText)
  36. {
  37. TRACE_FUNCTION("CMatchCondition::CMatchCondition()");
  38. //
  39. // we need initialization later
  40. //
  41. m_fParsed = FALSE;
  42. }
  43. CMatchCondition::~CMatchCondition()
  44. {
  45. TRACE_FUNCTION("CMatchCondition::~CMatchCondition()");
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // Function: Edit
  50. //
  51. // Class: CMatchCondition
  52. //
  53. // Synopsis: edit the match-typed condition
  54. //
  55. // Arguments: None
  56. //
  57. // Returns: HRESULT -
  58. //
  59. // History: Created Header byao 2/20/98 12:42:59 AM
  60. //
  61. //+---------------------------------------------------------------------------
  62. HRESULT CMatchCondition::Edit()
  63. {
  64. TRACE_FUNCTION("CMatchCondition::Edit()");
  65. HRESULT hr = S_OK;
  66. if ( !m_fParsed )
  67. {
  68. // we need to parse this condition text first
  69. DebugTrace(DEBUG_NAPMMC_MATCHCOND, "Need to parse condition %ws", (LPCTSTR)m_strConditionText);
  70. hr = ParseConditionText();
  71. if ( FAILED(hr) )
  72. {
  73. ErrorTrace(ERROR_NAPMMC_MATCHCOND, "Invalid Condition %ws, err=%x", (LPCTSTR)m_strConditionText, hr);
  74. ShowErrorDialog(NULL,
  75. IDS_ERROR_PARSE_CONDITION,
  76. (LPTSTR)(LPCTSTR)m_strConditionText,
  77. hr
  78. );
  79. return hr;
  80. }
  81. DebugTrace(DEBUG_NAPMMC_MATCHCOND, "Parsing Succeeded!");
  82. }
  83. // now we create a new condition editor object
  84. DebugTrace(DEBUG_NAPMMC_MATCHCOND, "Calling new CMatchCondEditor ...");
  85. CMatchCondEditor *pEditor = new CMatchCondEditor();
  86. if (!pEditor)
  87. {
  88. hr = HRESULT_FROM_WIN32(GetLastError());
  89. ErrorTrace(ERROR_NAPMMC_MATCHCOND, "Can't new a CMatchCondEditor object: err %x", hr);
  90. return hr;
  91. }
  92. pEditor->m_strRegExp = m_strRegExp;
  93. CComBSTR bstrName;
  94. hr = m_spAttributeInfo->get_AttributeName( &bstrName );
  95. _ASSERTE( SUCCEEDED( hr ) );
  96. pEditor->m_strAttrName = bstrName;
  97. DebugTrace(DEBUG_NAPMMC_MATCHCOND,
  98. "Start Match condition editor for %ws, %ws",
  99. (LPCTSTR)pEditor->m_strAttrName,
  100. (LPCTSTR)pEditor->m_strRegExp
  101. );
  102. if ( pEditor->DoModal() == IDOK)
  103. {
  104. // user clicked "OK" -- get the regular expression
  105. m_strRegExp = pEditor->m_strRegExp;
  106. //
  107. // fix up the condition text for SDO
  108. //
  109. // Escape any magic characters.
  110. ::CString raw(m_strRegExp);
  111. raw.Replace(L"\"", L"\"\"");
  112. m_strConditionText = bstrName;
  113. m_strConditionText += L"=" ;
  114. m_strConditionText += raw;
  115. hr = S_OK;
  116. }
  117. DebugTrace(DEBUG_NAPMMC_MATCHCOND, "New condition: %ws", (LPCTSTR)m_strConditionText);
  118. // clean up
  119. if ( pEditor )
  120. {
  121. delete pEditor;
  122. }
  123. return hr;
  124. }
  125. //+---------------------------------------------------------------------------
  126. //
  127. // Function: CMatchCondition::GetDisplayText
  128. //
  129. // Synopsis: Get the displayable text format for this condition,
  130. // which should be like this:
  131. //
  132. // DialinProperty.NASIPAddress matches "220.23"
  133. //
  134. // compared to the condition text:
  135. //
  136. // DialinProperty.NASIPAddress = 220.23
  137. //
  138. // Arguments: None
  139. //
  140. // Returns: ATL::CString& - the displayable text
  141. //
  142. // History: Created Header byao 2/22/98 11:41:28 PM
  143. //
  144. //+---------------------------------------------------------------------------
  145. ATL::CString CMatchCondition::GetDisplayText()
  146. {
  147. TRACE_FUNCTION("CMatchCondition::GetDisplayText()");
  148. HRESULT hr = S_OK;
  149. if ( !m_fParsed)
  150. {
  151. // we need to parse this condition text first
  152. DebugTrace(DEBUG_NAPMMC_MATCHCOND, "Need to parse condition %ws", (LPCTSTR)m_strConditionText);
  153. hr = ParseConditionText();
  154. if ( FAILED(hr) )
  155. {
  156. ErrorTrace(ERROR_NAPMMC_MATCHCOND, "Invalid Condition %ws, err=%x", (LPCTSTR)m_strConditionText, hr);
  157. ShowErrorDialog(NULL,
  158. IDS_ERROR_PARSE_CONDITION,
  159. (LPTSTR)(LPCTSTR)m_strConditionText,
  160. hr
  161. );
  162. return ATL::CString(_T(" "));
  163. }
  164. }
  165. // generate the displayable condition text
  166. ATL::CString strDispText;
  167. CComBSTR bstrName;
  168. hr = m_spAttributeInfo->get_AttributeName( &bstrName );
  169. _ASSERTE( SUCCEEDED( hr ) );
  170. strDispText = bstrName;
  171. // ISSUE: The word "matches" below is hardcoded and it shouldn't be.
  172. { ATL::CString matches;
  173. matches.LoadString(IDS_TEXT_MATCHES);
  174. strDispText += matches;
  175. }
  176. strDispText += L"\"";
  177. strDispText += m_strRegExp;
  178. strDispText += L"\" ";
  179. DebugTrace(DEBUG_NAPMMC_MATCHCOND, "Returning displayable text: %ws", (LPCTSTR)strDispText);
  180. return strDispText;
  181. }
  182. //+---------------------------------------------------------------------------
  183. //
  184. // Function: CMatchCondition::ParseConditionText
  185. //
  186. // Synopsis: Parse the condition text, to get the regular expression.
  187. //
  188. // Arguments: None
  189. //
  190. // Returns: HRESULT -
  191. //
  192. // History: Created Header byao 2/22/98 11:58:38 PM
  193. //
  194. //+---------------------------------------------------------------------------
  195. HRESULT CMatchCondition::ParseConditionText()
  196. {
  197. TRACE_FUNCTION("CMatchCondition::ParseConditionText()");
  198. _ASSERTE( !m_fParsed );
  199. HRESULT hr = S_OK;
  200. if (m_fParsed)
  201. {
  202. DebugTrace(DEBUG_NAPMMC_MATCHCOND,"Weird ... parsed flag already set!");
  203. // do nothing
  204. return S_OK;
  205. }
  206. //
  207. // parse strConditionText, return the regular expression only
  208. //
  209. WCHAR *pwzCondText = (LPTSTR) ((LPCTSTR)m_strConditionText);
  210. // look for the '=' in the condition text
  211. WCHAR *pwzEqualSign = wcschr(pwzCondText, L'=');
  212. // no '=' found -- something weird has happened
  213. if ( pwzEqualSign == NULL )
  214. {
  215. ErrorTrace(ERROR_NAPMMC_MATCHCOND, "Can't find '=' in the regular expression!");
  216. return E_UNEXPECTED;
  217. }
  218. // The right side of the equal sign is the regular expression.
  219. ::CString raw = pwzEqualSign + 1;
  220. // Remove any escape sequences.
  221. raw.Replace(L"\"\"", L"\"");
  222. m_strRegExp = raw;
  223. DebugTrace(DEBUG_NAPMMC_MATCHCOND, "Regular expression: %ws", (LPCTSTR)m_strRegExp);
  224. m_fParsed = TRUE;
  225. return S_OK;
  226. }