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.

407 lines
9.2 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. if (NULL == pvar)
  116. {
  117. //
  118. // Returning S_FALSE to indicate that we aren't returning
  119. // as many elements as requested.
  120. //
  121. hr = S_FALSE;
  122. }
  123. else
  124. {
  125. hr = EnumObjects( cElements,
  126. pvar,
  127. &cElementFetched );
  128. }
  129. if ( pcElementFetched )
  130. *pcElementFetched = cElementFetched;
  131. RRETURN(hr);
  132. }
  133. HRESULT
  134. CWinNTSchemaEnum::EnumObjects(
  135. DWORD ObjectType,
  136. ULONG cElements,
  137. VARIANT FAR * pvar,
  138. ULONG FAR * pcElementFetched
  139. )
  140. {
  141. HRESULT hr = S_OK;
  142. switch (ObjectType)
  143. {
  144. case WINNT_CLASS_ID:
  145. hr = EnumClasses(cElements, pvar, pcElementFetched);
  146. break;
  147. case WINNT_SYNTAX_ID:
  148. hr = EnumSyntaxObjects(cElements, pvar, pcElementFetched);
  149. break;
  150. case WINNT_PROPERTY_ID:
  151. hr = EnumProperties(cElements, pvar, pcElementFetched);
  152. break;
  153. default:
  154. RRETURN(S_FALSE);
  155. }
  156. RRETURN_EXP_IF_ERR(hr);
  157. }
  158. HRESULT
  159. CWinNTSchemaEnum::EnumObjects(
  160. ULONG cElements,
  161. VARIANT FAR* pvar,
  162. ULONG FAR* pcElementFetched
  163. )
  164. {
  165. DWORD i;
  166. ULONG cRequested = 0;
  167. ULONG cFetchedByPath = 0;
  168. ULONG cTotalFetched = 0;
  169. VARIANT FAR* pPathvar = pvar;
  170. HRESULT hr = S_FALSE;
  171. DWORD ObjectType;
  172. for (i = 0; i < cElements; i++)
  173. VariantInit(&pvar[i]);
  174. cRequested = cElements;
  175. while ( SUCCEEDED( _pObjList->GetCurrentObject(&ObjectType))
  176. && ((hr = EnumObjects( ObjectType,
  177. cRequested,
  178. pPathvar,
  179. &cFetchedByPath)) == S_FALSE )
  180. )
  181. {
  182. pPathvar += cFetchedByPath;
  183. cRequested -= cFetchedByPath;
  184. cTotalFetched += cFetchedByPath;
  185. cFetchedByPath = 0;
  186. if ( FAILED(_pObjList->Next()) )
  187. {
  188. if ( pcElementFetched )
  189. *pcElementFetched = cTotalFetched;
  190. RRETURN(S_FALSE);
  191. }
  192. _dwCurrentEntry = 0;
  193. }
  194. if ( pcElementFetched )
  195. *pcElementFetched = cTotalFetched + cFetchedByPath;
  196. RRETURN_EXP_IF_ERR(hr);
  197. }
  198. HRESULT
  199. CWinNTSchemaEnum::EnumClasses(
  200. ULONG cElements,
  201. VARIANT FAR* pvar,
  202. ULONG FAR* pcElementFetched
  203. )
  204. {
  205. HRESULT hr = S_OK;
  206. DWORD i = 0;
  207. IDispatch *pDispatch = NULL;
  208. while ( i < cElements )
  209. {
  210. hr = GetClassObject(&pDispatch);
  211. if ( hr == S_FALSE )
  212. break;
  213. VariantInit( &pvar[i] );
  214. pvar[i].vt = VT_DISPATCH;
  215. pvar[i].pdispVal = pDispatch;
  216. (*pcElementFetched)++;
  217. i++;
  218. }
  219. RRETURN(hr);
  220. }
  221. HRESULT
  222. CWinNTSchemaEnum::GetClassObject(
  223. IDispatch ** ppDispatch
  224. )
  225. {
  226. HRESULT hr = S_OK;
  227. //
  228. // Now send back the current ovbject
  229. //
  230. if ( _dwCurrentEntry >= g_cWinNTClasses )
  231. goto error;
  232. hr = CWinNTClass::CreateClass(
  233. _bstrADsPath,
  234. &g_aWinNTClasses[_dwCurrentEntry],
  235. ADS_OBJECT_BOUND,
  236. IID_IDispatch,
  237. _Credentials,
  238. (void **)ppDispatch
  239. );
  240. BAIL_ON_FAILURE(hr);
  241. _dwCurrentEntry++;
  242. RRETURN(S_OK);
  243. error:
  244. *ppDispatch = NULL;
  245. RRETURN(S_FALSE);
  246. }
  247. HRESULT
  248. CWinNTSchemaEnum::EnumSyntaxObjects(
  249. ULONG cElements,
  250. VARIANT FAR* pvar,
  251. ULONG FAR* pcElementFetched
  252. )
  253. {
  254. HRESULT hr = S_OK;
  255. DWORD i = 0;
  256. IDispatch *pDispatch = NULL;
  257. while ( i < cElements )
  258. {
  259. hr = GetSyntaxObject(&pDispatch);
  260. if ( hr == S_FALSE )
  261. break;
  262. VariantInit( &pvar[i] );
  263. pvar[i].vt = VT_DISPATCH;
  264. pvar[i].pdispVal = pDispatch;
  265. (*pcElementFetched)++;
  266. i++;
  267. }
  268. RRETURN(hr);
  269. }
  270. HRESULT
  271. CWinNTSchemaEnum::GetSyntaxObject(
  272. IDispatch ** ppDispatch
  273. )
  274. {
  275. HRESULT hr = S_OK;
  276. //
  277. // Now send back the current object
  278. //
  279. if ( _dwCurrentEntry >= g_cWinNTSyntax )
  280. goto error;
  281. hr = CWinNTSyntax::CreateSyntax(
  282. _bstrADsPath,
  283. &g_aWinNTSyntax[_dwCurrentEntry],
  284. ADS_OBJECT_BOUND,
  285. IID_IDispatch,
  286. _Credentials,
  287. (void **)ppDispatch
  288. );
  289. BAIL_ON_FAILURE(hr);
  290. _dwCurrentEntry++;
  291. RRETURN(S_OK);
  292. error:
  293. *ppDispatch = NULL;
  294. RRETURN(S_FALSE);
  295. }
  296. HRESULT
  297. CWinNTSchemaEnum::EnumProperties(
  298. ULONG cElements,
  299. VARIANT FAR* pvar,
  300. ULONG FAR* pcElementFetched
  301. )
  302. {
  303. HRESULT hr = S_OK;
  304. DWORD i = 0;
  305. IDispatch *pDispatch = NULL;
  306. while ( i < cElements )
  307. {
  308. hr = GetPropertyObject(&pDispatch);
  309. if ( hr == S_FALSE )
  310. break;
  311. VariantInit( &pvar[i] );
  312. pvar[i].vt = VT_DISPATCH;
  313. pvar[i].pdispVal = pDispatch;
  314. (*pcElementFetched)++;
  315. i++;
  316. }
  317. RRETURN(hr);
  318. }
  319. HRESULT
  320. CWinNTSchemaEnum::GetPropertyObject(
  321. IDispatch ** ppDispatch
  322. )
  323. {
  324. HRESULT hr = S_OK;
  325. //
  326. // Now send back the current ovbject
  327. //
  328. if ( _dwPropCurrentEntry >= g_cWinNTProperties )
  329. goto error;
  330. hr = CWinNTProperty::CreateProperty(
  331. _bstrADsPath,
  332. &g_aWinNTProperties[_dwPropCurrentEntry],
  333. ADS_OBJECT_BOUND,
  334. IID_IDispatch,
  335. _Credentials,
  336. (void **)ppDispatch
  337. );
  338. BAIL_ON_FAILURE(hr);
  339. _dwPropCurrentEntry++;
  340. RRETURN(S_OK);
  341. error:
  342. *ppDispatch = NULL;
  343. RRETURN(S_FALSE);
  344. }