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.

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