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.

416 lines
9.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: iasprofa.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // IASProfA.cpp: implementation of the CIASProfileAttribute class.
  11. //
  12. //////////////////////////////////////////////////////////////////////
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. #include "helper.h"
  16. #include "IASHelper.h"
  17. #include "iasprofa.h"
  18. #include "napmmc.h"
  19. #include "napmmc_i.c"
  20. //////////////////////////////////////////////////////////////////////
  21. // Forward declarations of some utilities used here
  22. //////////////////////////////////////////////////////////////////////
  23. static HRESULT getCLSIDForEditorToUse( /* in */ IIASAttributeInfo *pIASAttributeInfo
  24. , /* in */ VARIANT * pvarValue
  25. , /* out */ CLSID &clsid
  26. );
  27. static HRESULT SetUpAttributeEditor( /* in */ IIASAttributeInfo *pIASAttributeInfo
  28. , /* in */ VARIANT * pvarValue
  29. , /* out */ IIASAttributeEditor ** ppIASAttributeEditor
  30. );
  31. //////////////////////////////////////////////////////////////////////
  32. // Construction/Destruction
  33. //////////////////////////////////////////////////////////////////////
  34. //////////////////////////////////////////////////////////////////////////////
  35. /*++
  36. CIASProfileAttribute::CIASProfileAttribute
  37. Constructor
  38. --*/
  39. //////////////////////////////////////////////////////////////////////////////
  40. CIASProfileAttribute::CIASProfileAttribute(
  41. IIASAttributeInfo * pIASAttributeInfo
  42. , VARIANT & varValue
  43. )
  44. {
  45. TRACE(_T("CIASProfileAttribute::CIASProfileAttribute\n"));
  46. // Check for preconditions:
  47. _ASSERTE( pIASAttributeInfo );
  48. HRESULT hr;
  49. // The smartpointer calls AddRef on this interface.
  50. m_spIASAttributeInfo = pIASAttributeInfo;
  51. // Make a copy of the passed variant.
  52. hr = VariantCopy( &m_varValue, &varValue );
  53. if( FAILED( hr ) ) throw hr;
  54. // ISSUE: Make sure that if anything here fails, m_spIASAttributeInfo gets release.
  55. }
  56. //////////////////////////////////////////////////////////////////////////////
  57. /*++
  58. CIASProfileAttribute::~CIASProfileAttribute
  59. Destructor
  60. --*/
  61. //////////////////////////////////////////////////////////////////////////////
  62. CIASProfileAttribute::~CIASProfileAttribute()
  63. {
  64. TRACE(_T("CIASProfileAttribute::~CIASProfileAttribute\n"));
  65. }
  66. //////////////////////////////////////////////////////////////////////////////
  67. /*++
  68. CIASProfileAttribute::Edit
  69. Call this to ask a profile attribute to edit itself.
  70. --*/
  71. //////////////////////////////////////////////////////////////////////////////
  72. STDMETHODIMP CIASProfileAttribute::Edit()
  73. {
  74. TRACE(_T("CIASProfileAttribute::Edit\n"));
  75. // Check for preconditions:
  76. _ASSERTE( m_spIASAttributeInfo );
  77. CLSID clsidEditorToUse;
  78. HRESULT hr = S_OK;
  79. CComPtr<IIASAttributeEditor> spIASAttributeEditor;
  80. // Get the editor to use.
  81. hr = SetUpAttributeEditor( m_spIASAttributeInfo.p, &m_varValue, &spIASAttributeEditor );
  82. if( FAILED( hr ) ) return hr;
  83. // Edit it!
  84. CComBSTR bstrReserved;
  85. hr = spIASAttributeEditor->Edit( m_spIASAttributeInfo.p, &m_varValue, &bstrReserved );
  86. if( FAILED( hr ) ) return hr;
  87. return hr;
  88. }
  89. //////////////////////////////////////////////////////////////////////////////
  90. /*++
  91. CIASProfileAttribute::getAttributeName
  92. --*/
  93. //////////////////////////////////////////////////////////////////////////////
  94. STDMETHODIMP CIASProfileAttribute::get_AttributeName( BSTR * pbstrVal )
  95. {
  96. TRACE(_T("CIASProfileAttribute::get_AttributeName\n"));
  97. // Check for preconditions:
  98. _ASSERTE( m_spIASAttributeInfo );
  99. HRESULT hr = S_OK;
  100. hr = m_spIASAttributeInfo->get_AttributeName( pbstrVal );
  101. return hr;
  102. }
  103. //////////////////////////////////////////////////////////////////////////////
  104. /*++
  105. CIASProfileAttribute::GetDisplayInfo
  106. Rather than asking the AttributeInfo directly for information
  107. about the vendor name, this method will use an AttributeEditor
  108. to ask for this information.
  109. This is the most generic way of asking for this info as
  110. for some attributes, e.g. RADIUS Vendor Specific, Vendor Name
  111. is not stored in the AttributeInfo but is encapsulated in
  112. the value of the attribute itself.
  113. So we don't use our own knowledge of the attribute, rather we
  114. create an editor and ask the editor to give back this
  115. information for us.
  116. --*/
  117. //////////////////////////////////////////////////////////////////////////////
  118. STDMETHODIMP CIASProfileAttribute::GetDisplayInfo( BSTR * pbstrVendor, BSTR * pbstrDisplayValue )
  119. {
  120. TRACE(_T("CIASProfileAttribute::GetDisplayInfo\n"));
  121. // Check for preconditions:
  122. _ASSERTE( m_spIASAttributeInfo );
  123. HRESULT hr = S_OK;
  124. CComBSTR bstrVendor, bstrDisplayValue, bstrReserved;
  125. try
  126. {
  127. CComPtr<IIASAttributeEditor> spIASAttributeEditor;
  128. // Get the editor to use.
  129. hr = SetUpAttributeEditor( m_spIASAttributeInfo.p, &m_varValue, &spIASAttributeEditor );
  130. if( FAILED( hr ) ) throw hr;
  131. hr = spIASAttributeEditor->GetDisplayInfo( m_spIASAttributeInfo.p, &m_varValue, &bstrVendor, &bstrDisplayValue, &bstrReserved );
  132. if( FAILED( hr ) ) throw hr;
  133. }
  134. catch(...)
  135. {
  136. // If anything above fails, just fall through -- we will return a pointer to an empty bstr.
  137. hr = E_FAIL;
  138. }
  139. *pbstrVendor = bstrVendor.Copy();
  140. *pbstrDisplayValue = bstrDisplayValue.Copy();
  141. return hr;
  142. }
  143. //////////////////////////////////////////////////////////////////////////////
  144. /*++
  145. CIASProfileAttribute::get_VarValue
  146. --*/
  147. //////////////////////////////////////////////////////////////////////////////
  148. STDMETHODIMP CIASProfileAttribute::get_VarValue( VARIANT * pvarVal )
  149. {
  150. TRACE(_T("CIASProfileAttribute::get_VarValue\n"));
  151. // Check for preconditions:
  152. // None.
  153. HRESULT hr = S_OK;
  154. hr = VariantCopy( pvarVal, &m_varValue );
  155. return hr;
  156. }
  157. //////////////////////////////////////////////////////////////////////////////
  158. /*++
  159. CIASProfileAttribute::get_AttributeID
  160. --*/
  161. //////////////////////////////////////////////////////////////////////////////
  162. STDMETHODIMP CIASProfileAttribute::get_AttributeID( ATTRIBUTEID * pID )
  163. {
  164. TRACE(_T("CIASProfileAttribute::get_AttributeID\n"));
  165. // Check for preconditions:
  166. _ASSERTE( m_spIASAttributeInfo );
  167. HRESULT hr = S_OK;
  168. hr = m_spIASAttributeInfo->get_AttributeID( pID );
  169. return hr;
  170. }
  171. //////////////////////////////////////////////////////////////////////////////
  172. /*++
  173. ::getCLSIDForEditorToUse
  174. The ShemaAttribute for a node stores a ProgID which indicates which
  175. editor to use to manipulate an attribute.
  176. For non-multivalued attributes, we query the schema attribute to find
  177. out the ProgID for its editor.
  178. For multivalued attributes, we always create the multivalued editor.
  179. When it is used, the multivalued editor is passed the schema attribute which it will
  180. then use to query for the appropriate editor to pop up for editing
  181. each indivdual elements
  182. --*/
  183. //////////////////////////////////////////////////////////////////////////////
  184. HRESULT getCLSIDForEditorToUse( /* in */ IIASAttributeInfo *pIASAttributeInfo
  185. , /* in */ VARIANT * pvarValue
  186. , /* out */ CLSID &clsid
  187. )
  188. {
  189. TRACE(_T("::getCLSIDForEditorToUse\n"));
  190. // Check for preconditions:
  191. _ASSERTE( pIASAttributeInfo );
  192. HRESULT hr = S_OK;
  193. // Get attribute restrictions to see if multivalued.
  194. long lRestriction;
  195. hr = pIASAttributeInfo->get_AttributeRestriction( &lRestriction );
  196. if( lRestriction & MULTIVALUED )
  197. {
  198. _ASSERTE( V_VT(pvarValue) == (VT_ARRAY | VT_VARIANT) || V_VT(pvarValue) == VT_EMPTY );
  199. // Create the multi-attribute editor.
  200. // It will figure out the appropriate editor to use to
  201. // edit individual attribute values.
  202. clsid = CLSID_IASMultivaluedAttributeEditor;
  203. }
  204. else
  205. {
  206. // Query the schema attribute to see which attribute editor to use.
  207. CComBSTR bstrProgID;
  208. hr = pIASAttributeInfo->get_EditorProgID( &bstrProgID );
  209. if( FAILED( hr ) )
  210. {
  211. // We could try putting up a default (e.g. hex) editor, but for now:
  212. return hr;
  213. }
  214. hr = CLSIDFromProgID( bstrProgID, &clsid );
  215. if( FAILED( hr ) )
  216. {
  217. // We could try putting up a default (e.g. hex) editor, but for now:
  218. return hr;
  219. }
  220. }
  221. return hr;
  222. }
  223. //////////////////////////////////////////////////////////////////////////////
  224. /*++
  225. ::SetUpAttributeEditor
  226. --*/
  227. //////////////////////////////////////////////////////////////////////////////
  228. HRESULT SetUpAttributeEditor( /* in */ IIASAttributeInfo *pIASAttributeInfo
  229. , /* in */ VARIANT * pvarValue
  230. , /* out */ IIASAttributeEditor ** ppIASAttributeEditor
  231. )
  232. {
  233. TRACE(_T("::SetUpAttributeEditor\n"));
  234. // Check for preconditions:
  235. _ASSERTE( pIASAttributeInfo );
  236. _ASSERTE( ppIASAttributeEditor );
  237. // Initialize the interface pointer to NULL so we know whether we need to release it if there is an error.
  238. *ppIASAttributeEditor = NULL;
  239. // Query the schema attribute to see which attribute editor to use.
  240. CLSID clsidEditorToUse;
  241. CComBSTR bstrProgID;
  242. HRESULT hr;
  243. try
  244. {
  245. hr = getCLSIDForEditorToUse( pIASAttributeInfo, pvarValue, clsidEditorToUse );
  246. if( FAILED( hr ) )
  247. {
  248. // We could try putting up a default (e.g. hex) editor, but for now:
  249. return hr;
  250. }
  251. hr = CoCreateInstance( clsidEditorToUse , NULL, CLSCTX_INPROC_SERVER, IID_IIASAttributeEditor, (LPVOID *) ppIASAttributeEditor );
  252. if( FAILED( hr ) )
  253. {
  254. return hr;
  255. }
  256. if( ! *ppIASAttributeEditor )
  257. {
  258. return E_FAIL;
  259. }
  260. }
  261. catch(...)
  262. {
  263. // No smart pointers here -- need to make sure we release ourselves.
  264. if( *ppIASAttributeEditor )
  265. {
  266. (*ppIASAttributeEditor)->Release();
  267. *ppIASAttributeEditor = NULL;
  268. }
  269. }
  270. return hr;
  271. }