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.

396 lines
8.6 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cenumsch.cxx
  7. //
  8. // Contents: Windows NT 3.5 Schema Enumeration Code
  9. //
  10. // CWinNTSchemaEnum::CWinNTSchemaEnum()
  11. // CWinNTSchemaEnum::CWinNTSchemaEnum
  12. // CWinNTSchemaEnum::EnumObjects
  13. // CWinNTSchemaEnum::EnumObjects
  14. //
  15. // History:
  16. //----------------------------------------------------------------------------
  17. #include "winnt.hxx"
  18. #pragma hdrstop
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: CWinNTSchemaEnum::Create
  22. //
  23. // Synopsis:
  24. //
  25. // Arguments: [pCollection]
  26. // [ppEnumVariant]
  27. //
  28. // Returns: HRESULT
  29. //
  30. // Modifies:
  31. //
  32. // History: 01-30-95 yihsins Created.
  33. //
  34. //----------------------------------------------------------------------------
  35. HRESULT
  36. CWinNTSchemaEnum::Create(
  37. CWinNTSchemaEnum FAR* FAR* ppenumvariant,
  38. BSTR bstrADsPath,
  39. BSTR bstrName,
  40. VARIANT vFilter,
  41. CWinNTCredentials& Credentials
  42. )
  43. {
  44. HRESULT hr = S_OK;
  45. CWinNTSchemaEnum FAR* penumvariant = NULL;
  46. *ppenumvariant = NULL;
  47. penumvariant = new CWinNTSchemaEnum();
  48. if (!penumvariant)
  49. {
  50. hr = E_OUTOFMEMORY;
  51. BAIL_ON_FAILURE(hr);
  52. }
  53. hr = ADsAllocString( bstrADsPath, &penumvariant->_bstrADsPath);
  54. BAIL_ON_FAILURE(hr);
  55. hr = ADsAllocString( bstrName, &penumvariant->_bstrName);
  56. BAIL_ON_FAILURE(hr);
  57. hr = ObjectTypeList::CreateObjectTypeList(
  58. vFilter,
  59. &penumvariant->_pObjList );
  60. BAIL_ON_FAILURE(hr);
  61. penumvariant->_Credentials = Credentials;
  62. *ppenumvariant = penumvariant;
  63. RRETURN(hr);
  64. error:
  65. delete penumvariant;
  66. RRETURN(hr);
  67. }
  68. CWinNTSchemaEnum::CWinNTSchemaEnum()
  69. : _bstrADsPath( NULL ),
  70. _bstrName( NULL ),
  71. _pObjList( NULL ),
  72. _dwCurrentEntry( 0 ),
  73. _dwPropCurrentEntry( 0)
  74. {
  75. }
  76. CWinNTSchemaEnum::~CWinNTSchemaEnum()
  77. {
  78. ADsFreeString( _bstrName );
  79. ADsFreeString( _bstrADsPath );
  80. if ( _pObjList != NULL )
  81. {
  82. delete _pObjList;
  83. _pObjList = NULL;
  84. }
  85. }
  86. //+---------------------------------------------------------------------------
  87. //
  88. // Function: CWinNTSchemaEnum::Next
  89. //
  90. // Synopsis: Returns cElements number of requested NetOle objects in the
  91. // array supplied in pvar.
  92. //
  93. // Arguments: [cElements] -- The number of elements requested by client
  94. // [pvar] -- ptr to array of VARIANTs to for return objects
  95. // [pcElementFetched] -- if non-NULL, then number of elements
  96. // -- actually returned is placed here
  97. //
  98. // Returns: HRESULT -- S_OK if number of elements requested are returned
  99. // -- S_FALSE if number of elements is < requested
  100. //
  101. // Modifies:
  102. //
  103. // History: 11-3-95 yihsins Created.
  104. //
  105. //----------------------------------------------------------------------------
  106. STDMETHODIMP
  107. CWinNTSchemaEnum::Next(
  108. ULONG cElements,
  109. VARIANT FAR* pvar,
  110. ULONG FAR* pcElementFetched
  111. )
  112. {
  113. ULONG cElementFetched = 0;
  114. HRESULT hr = S_OK;
  115. hr = EnumObjects( cElements,
  116. pvar,
  117. &cElementFetched );
  118. if ( pcElementFetched )
  119. *pcElementFetched = cElementFetched;
  120. RRETURN(hr);
  121. }
  122. HRESULT
  123. CWinNTSchemaEnum::EnumObjects(
  124. DWORD ObjectType,
  125. ULONG cElements,
  126. VARIANT FAR * pvar,
  127. ULONG FAR * pcElementFetched
  128. )
  129. {
  130. HRESULT hr = S_OK;
  131. switch (ObjectType)
  132. {
  133. case WINNT_CLASS_ID:
  134. hr = EnumClasses(cElements, pvar, pcElementFetched);
  135. break;
  136. case WINNT_SYNTAX_ID:
  137. hr = EnumSyntaxObjects(cElements, pvar, pcElementFetched);
  138. break;
  139. case WINNT_PROPERTY_ID:
  140. hr = EnumProperties(cElements, pvar, pcElementFetched);
  141. break;
  142. default:
  143. RRETURN(S_FALSE);
  144. }
  145. RRETURN_EXP_IF_ERR(hr);
  146. }
  147. HRESULT
  148. CWinNTSchemaEnum::EnumObjects(
  149. ULONG cElements,
  150. VARIANT FAR* pvar,
  151. ULONG FAR* pcElementFetched
  152. )
  153. {
  154. DWORD i;
  155. ULONG cRequested = 0;
  156. ULONG cFetchedByPath = 0;
  157. ULONG cTotalFetched = 0;
  158. VARIANT FAR* pPathvar = pvar;
  159. HRESULT hr = S_FALSE;
  160. DWORD ObjectType;
  161. for (i = 0; i < cElements; i++)
  162. VariantInit(&pvar[i]);
  163. cRequested = cElements;
  164. while ( SUCCEEDED( _pObjList->GetCurrentObject(&ObjectType))
  165. && ((hr = EnumObjects( ObjectType,
  166. cRequested,
  167. pPathvar,
  168. &cFetchedByPath)) == S_FALSE )
  169. )
  170. {
  171. pPathvar += cFetchedByPath;
  172. cRequested -= cFetchedByPath;
  173. cTotalFetched += cFetchedByPath;
  174. cFetchedByPath = 0;
  175. if ( FAILED(_pObjList->Next()) )
  176. {
  177. if ( pcElementFetched )
  178. *pcElementFetched = cTotalFetched;
  179. RRETURN(S_FALSE);
  180. }
  181. _dwCurrentEntry = 0;
  182. }
  183. if ( pcElementFetched )
  184. *pcElementFetched = cTotalFetched + cFetchedByPath;
  185. RRETURN_EXP_IF_ERR(hr);
  186. }
  187. HRESULT
  188. CWinNTSchemaEnum::EnumClasses(
  189. ULONG cElements,
  190. VARIANT FAR* pvar,
  191. ULONG FAR* pcElementFetched
  192. )
  193. {
  194. HRESULT hr = S_OK;
  195. DWORD i = 0;
  196. IDispatch *pDispatch = NULL;
  197. while ( i < cElements )
  198. {
  199. hr = GetClassObject(&pDispatch);
  200. if ( hr == S_FALSE )
  201. break;
  202. VariantInit( &pvar[i] );
  203. pvar[i].vt = VT_DISPATCH;
  204. pvar[i].pdispVal = pDispatch;
  205. (*pcElementFetched)++;
  206. i++;
  207. }
  208. RRETURN(hr);
  209. }
  210. HRESULT
  211. CWinNTSchemaEnum::GetClassObject(
  212. IDispatch ** ppDispatch
  213. )
  214. {
  215. HRESULT hr = S_OK;
  216. //
  217. // Now send back the current ovbject
  218. //
  219. if ( _dwCurrentEntry >= g_cWinNTClasses )
  220. goto error;
  221. hr = CWinNTClass::CreateClass(
  222. _bstrADsPath,
  223. &g_aWinNTClasses[_dwCurrentEntry],
  224. ADS_OBJECT_BOUND,
  225. IID_IDispatch,
  226. _Credentials,
  227. (void **)ppDispatch
  228. );
  229. BAIL_ON_FAILURE(hr);
  230. _dwCurrentEntry++;
  231. RRETURN(S_OK);
  232. error:
  233. *ppDispatch = NULL;
  234. RRETURN(S_FALSE);
  235. }
  236. HRESULT
  237. CWinNTSchemaEnum::EnumSyntaxObjects(
  238. ULONG cElements,
  239. VARIANT FAR* pvar,
  240. ULONG FAR* pcElementFetched
  241. )
  242. {
  243. HRESULT hr = S_OK;
  244. DWORD i = 0;
  245. IDispatch *pDispatch = NULL;
  246. while ( i < cElements )
  247. {
  248. hr = GetSyntaxObject(&pDispatch);
  249. if ( hr == S_FALSE )
  250. break;
  251. VariantInit( &pvar[i] );
  252. pvar[i].vt = VT_DISPATCH;
  253. pvar[i].pdispVal = pDispatch;
  254. (*pcElementFetched)++;
  255. i++;
  256. }
  257. RRETURN(hr);
  258. }
  259. HRESULT
  260. CWinNTSchemaEnum::GetSyntaxObject(
  261. IDispatch ** ppDispatch
  262. )
  263. {
  264. HRESULT hr = S_OK;
  265. //
  266. // Now send back the current object
  267. //
  268. if ( _dwCurrentEntry >= g_cWinNTSyntax )
  269. goto error;
  270. hr = CWinNTSyntax::CreateSyntax(
  271. _bstrADsPath,
  272. &g_aWinNTSyntax[_dwCurrentEntry],
  273. ADS_OBJECT_BOUND,
  274. IID_IDispatch,
  275. _Credentials,
  276. (void **)ppDispatch
  277. );
  278. BAIL_ON_FAILURE(hr);
  279. _dwCurrentEntry++;
  280. RRETURN(S_OK);
  281. error:
  282. *ppDispatch = NULL;
  283. RRETURN(S_FALSE);
  284. }
  285. HRESULT
  286. CWinNTSchemaEnum::EnumProperties(
  287. ULONG cElements,
  288. VARIANT FAR* pvar,
  289. ULONG FAR* pcElementFetched
  290. )
  291. {
  292. HRESULT hr = S_OK;
  293. DWORD i = 0;
  294. IDispatch *pDispatch = NULL;
  295. while ( i < cElements )
  296. {
  297. hr = GetPropertyObject(&pDispatch);
  298. if ( hr == S_FALSE )
  299. break;
  300. VariantInit( &pvar[i] );
  301. pvar[i].vt = VT_DISPATCH;
  302. pvar[i].pdispVal = pDispatch;
  303. (*pcElementFetched)++;
  304. i++;
  305. }
  306. RRETURN(hr);
  307. }
  308. HRESULT
  309. CWinNTSchemaEnum::GetPropertyObject(
  310. IDispatch ** ppDispatch
  311. )
  312. {
  313. HRESULT hr = S_OK;
  314. //
  315. // Now send back the current ovbject
  316. //
  317. if ( _dwPropCurrentEntry >= g_cWinNTProperties )
  318. goto error;
  319. hr = CWinNTProperty::CreateProperty(
  320. _bstrADsPath,
  321. &g_aWinNTProperties[_dwPropCurrentEntry],
  322. ADS_OBJECT_BOUND,
  323. IID_IDispatch,
  324. _Credentials,
  325. (void **)ppDispatch
  326. );
  327. BAIL_ON_FAILURE(hr);
  328. _dwPropCurrentEntry++;
  329. RRETURN(S_OK);
  330. error:
  331. *ppDispatch = NULL;
  332. RRETURN(S_FALSE);
  333. }