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.

392 lines
8.4 KiB

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