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.

346 lines
6.4 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1997 - 1999
  4. Module Name:
  5. Vendors.cpp
  6. Abstract:
  7. Implementation file for NAS Vendor ID info.
  8. Revision History:
  9. mmaguire 02/19/98 created
  10. byao 3/13/98 Modified. use '0' for RADIUS
  11. mmaguire 11/04/98 Revamped to be a static COM object populated from the SDO's.
  12. --*/
  13. //////////////////////////////////////////////////////////////////////////////
  14. //////////////////////////////////////////////////////////////////////////////
  15. // BEGIN INCLUDES
  16. //
  17. // standard includes:
  18. //
  19. #include "Precompiled.h"
  20. //
  21. // where we can find declaration for main class in this file:
  22. //
  23. #include "Vendors.h"
  24. //
  25. // where we can find declarations needed in this file:
  26. //
  27. //
  28. // END INCLUDES
  29. //////////////////////////////////////////////////////////////////////////////
  30. //////////////////////////////////////////////////////////////////////////////
  31. /*++
  32. CIASNASVendors::CIASNASVendors
  33. Constructor
  34. --*/
  35. //////////////////////////////////////////////////////////////////////////////
  36. CIASNASVendors::CIASNASVendors()
  37. {
  38. m_bUninitialized = TRUE;
  39. }
  40. //////////////////////////////////////////////////////////////////////////////
  41. /*++
  42. CIASNASVendors::InitFromSdo
  43. IIASNASVendors implementation.
  44. --*/
  45. //////////////////////////////////////////////////////////////////////////////
  46. STDMETHODIMP CIASNASVendors::InitFromSdo( /* [in] */ ISdoCollection *pSdoVendors )
  47. {
  48. // Check to see if we've already been initialized.
  49. if( ! m_bUninitialized )
  50. {
  51. return S_FALSE;
  52. }
  53. HRESULT hr = S_OK;
  54. CComPtr<IUnknown> spUnknown;
  55. CComPtr<IEnumVARIANT> spEnumVariant;
  56. CComVariant spVariant;
  57. long ulCount;
  58. ULONG ulCountReceived;
  59. if( ! pSdoVendors )
  60. {
  61. return E_FAIL; // Is there a better error to return here?
  62. }
  63. try // push_back can throw exceptions.
  64. {
  65. // We check the count of items in our collection and don't bother getting the
  66. // enumerator if the count is zero.
  67. // This saves time and also helps us to avoid a bug in the the enumerator which
  68. // causes it to fail if we call next when it is empty.
  69. pSdoVendors->get_Count( & ulCount );
  70. if( ulCount > 0 )
  71. {
  72. // Get the enumerator for the Clients collection.
  73. hr = pSdoVendors->get__NewEnum( (IUnknown **) & spUnknown );
  74. if( FAILED( hr ) || ! spUnknown )
  75. {
  76. return E_FAIL;
  77. }
  78. hr = spUnknown->QueryInterface( IID_IEnumVARIANT, (void **) &spEnumVariant );
  79. spUnknown.Release();
  80. if( FAILED( hr ) || ! spEnumVariant )
  81. {
  82. return E_FAIL;
  83. }
  84. // Get the first item.
  85. hr = spEnumVariant->Next( 1, & spVariant, &ulCountReceived );
  86. while( SUCCEEDED( hr ) && ulCountReceived == 1 )
  87. {
  88. // Get an sdo pointer from the variant we received.
  89. if( spVariant.vt != VT_DISPATCH || ! spVariant.pdispVal )
  90. {
  91. _ASSERTE( FALSE );
  92. continue;
  93. }
  94. CComPtr<ISdo> spSdo;
  95. hr = spVariant.pdispVal->QueryInterface( IID_ISdo, (void **) &spSdo );
  96. spVariant.Clear();
  97. if( FAILED( hr ) )
  98. {
  99. _ASSERTE( FALSE );
  100. continue;
  101. }
  102. // Get Vendor Name.
  103. hr = spSdo->GetProperty( PROPERTY_SDO_NAME, &spVariant );
  104. if( FAILED( hr ) )
  105. {
  106. _ASSERTE( FALSE );
  107. continue;
  108. }
  109. _ASSERTE( spVariant.vt == VT_BSTR );
  110. CComBSTR bstrVendorName = spVariant.bstrVal;
  111. spVariant.Clear();
  112. // Get Vendor ID.
  113. hr = spSdo->GetProperty( PROPERTY_NAS_VENDOR_ID, &spVariant );
  114. if( FAILED( hr ) )
  115. {
  116. _ASSERTE( FALSE );
  117. continue;
  118. }
  119. _ASSERTE( spVariant.vt == VT_I4 );
  120. LONG lVendorID = spVariant.lVal;
  121. spVariant.Clear();
  122. // Add the vendor infor to the list of vendors.
  123. push_back( std::make_pair(bstrVendorName, lVendorID) );
  124. // Get the next item.
  125. hr = spEnumVariant->Next( 1, & spVariant, &ulCountReceived );
  126. }
  127. }
  128. else
  129. {
  130. // There are no items in the enumeration
  131. // Do nothing.
  132. }
  133. }
  134. catch(...)
  135. {
  136. return E_FAIL;
  137. }
  138. m_bUninitialized = FALSE;
  139. return hr;
  140. }
  141. //////////////////////////////////////////////////////////////////////////////
  142. /*++
  143. CIASNASVendors::get_Size
  144. IIASNASVendors implementation.
  145. --*/
  146. //////////////////////////////////////////////////////////////////////////////
  147. STDMETHODIMP CIASNASVendors::get_Size( /* [retval][out] */ long *plCount )
  148. {
  149. if( m_bUninitialized )
  150. {
  151. return OLE_E_BLANK;
  152. }
  153. *plCount = size();
  154. return S_OK;
  155. }
  156. //////////////////////////////////////////////////////////////////////////////
  157. /*++
  158. CIASNASVendors::get_VendorName
  159. IIASNASVendors implementation.
  160. --*/
  161. //////////////////////////////////////////////////////////////////////////////
  162. STDMETHODIMP CIASNASVendors::get_VendorName( long lIndex, /* [retval][out] */ BSTR *pbstrVendorName )
  163. {
  164. if( m_bUninitialized )
  165. {
  166. return OLE_E_BLANK;
  167. }
  168. try
  169. {
  170. *pbstrVendorName = operator[]( lIndex ).first.Copy();
  171. }
  172. catch(...)
  173. {
  174. return ERROR_NOT_FOUND;
  175. }
  176. return S_OK;
  177. }
  178. HRESULT MakeVendorNameFromVendorID(DWORD dwVendorId, BSTR* pbstrVendorName )
  179. {
  180. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  181. if(!pbstrVendorName) return E_INVALIDARG;
  182. ::CString str, str1;
  183. str1.LoadString(IDS_IAS_VAS_VENDOR_ID);
  184. str.Format(str1, dwVendorId);
  185. USES_CONVERSION;
  186. *pbstrVendorName = T2BSTR((LPTSTR)(LPCTSTR)str);
  187. return S_OK;
  188. }
  189. //////////////////////////////////////////////////////////////////////////////
  190. /*++
  191. CIASNASVendors::get_VendorID
  192. IIASNASVendors implementation.
  193. --*/
  194. //////////////////////////////////////////////////////////////////////////////
  195. STDMETHODIMP CIASNASVendors::get_VendorID( long lIndex, /* [retval][out] */ long *plVendorID )
  196. {
  197. if( m_bUninitialized )
  198. {
  199. return OLE_E_BLANK;
  200. }
  201. try
  202. {
  203. *plVendorID = operator[]( lIndex ).second;
  204. }
  205. catch(...)
  206. {
  207. return ERROR_NOT_FOUND;
  208. }
  209. return S_OK;
  210. }
  211. //////////////////////////////////////////////////////////////////////////////
  212. /*++
  213. CIASNASVendors::get_VendorIDToOrdinal
  214. IIASNASVendors implementation.
  215. --*/
  216. //////////////////////////////////////////////////////////////////////////////
  217. STDMETHODIMP CIASNASVendors::get_VendorIDToOrdinal( long lVendorID, /* [retval][out] */ long *plIndex )
  218. {
  219. if( m_bUninitialized )
  220. {
  221. return OLE_E_BLANK;
  222. }
  223. try
  224. {
  225. for (int i = 0; i < size() ; ++i)
  226. {
  227. if( lVendorID == operator[](i).second )
  228. {
  229. *plIndex = i;
  230. return S_OK;
  231. }
  232. }
  233. }
  234. catch(...)
  235. {
  236. return E_FAIL;
  237. }
  238. // When we can't find a vendor, we have arranged the dictionary so
  239. // that the zero'th vendor is the default "RADIUS Standard" so
  240. // use this as the fallback.
  241. *plIndex = 0;
  242. return S_FALSE;
  243. }