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.

515 lines
12 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cenumsch.cxx
  7. //
  8. // Contents: NDS Schema Enumeration Code
  9. //
  10. // CNDSSchemaEnum::CNDSSchemaEnum()
  11. // CNDSSchemaEnum::CNDSSchemaEnum
  12. // CNDSSchemaEnum::EnumObjects
  13. // CNDSSchemaEnum::EnumObjects
  14. //
  15. // History:
  16. //----------------------------------------------------------------------------
  17. #include "NDS.hxx"
  18. #pragma hdrstop
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: CNDSSchemaEnum::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. CNDSSchemaEnum::Create(
  37. CNDSSchemaEnum FAR* FAR* ppenumvariant,
  38. BSTR bstrNDSTreeName,
  39. BSTR bstrADsPath,
  40. BSTR bstrName,
  41. VARIANT var,
  42. CCredentials& Credentials
  43. )
  44. {
  45. HRESULT hr = S_OK;
  46. CNDSSchemaEnum FAR* penumvariant = NULL;
  47. WCHAR szObjectFullName[MAX_PATH];
  48. WCHAR szObjectClassName[MAX_PATH];
  49. DWORD dwModificationTime = 0L;
  50. DWORD dwNumberOfEntries = 0L;
  51. DWORD dwStatus = 0L;
  52. *ppenumvariant = NULL;
  53. penumvariant = new CNDSSchemaEnum();
  54. if (!penumvariant)
  55. {
  56. hr = E_OUTOFMEMORY;
  57. BAIL_ON_FAILURE(hr);
  58. }
  59. hr = ADsAllocString( bstrNDSTreeName, &penumvariant->_bstrNDSTreeName);
  60. BAIL_ON_FAILURE(hr);
  61. dwStatus = ADsNwNdsOpenObject(
  62. penumvariant->_bstrNDSTreeName,
  63. Credentials,
  64. &penumvariant->_hTree,
  65. szObjectFullName,
  66. szObjectClassName,
  67. &dwModificationTime,
  68. &dwNumberOfEntries
  69. );
  70. if (dwStatus) {
  71. hr = HRESULT_FROM_WIN32(GetLastError());
  72. BAIL_ON_FAILURE(hr);
  73. }
  74. hr = ADsAllocString( bstrADsPath, &penumvariant->_bstrADsPath);
  75. BAIL_ON_FAILURE(hr);
  76. hr = ADsAllocString( bstrName, &penumvariant->_bstrName);
  77. BAIL_ON_FAILURE(hr);
  78. hr = ObjectTypeList::CreateObjectTypeList(
  79. var,
  80. &penumvariant->_pObjList
  81. );
  82. BAIL_ON_FAILURE(hr);
  83. penumvariant->_Credentials = Credentials;
  84. *ppenumvariant = penumvariant;
  85. RRETURN(hr);
  86. error:
  87. delete penumvariant;
  88. RRETURN_EXP_IF_ERR(hr);
  89. }
  90. CNDSSchemaEnum::CNDSSchemaEnum()
  91. : _bstrADsPath( NULL ),
  92. _bstrName( NULL ),
  93. _bstrNDSTreeName( NULL ),
  94. _pObjList( NULL ),
  95. _dwCurrentEntry( 0 ),
  96. _dwSyntaxCurrentEntry( 0 )
  97. {
  98. _hOperationData = NULL;
  99. _hTree = NULL;
  100. _lpClassDefs = NULL;
  101. _dwObjectCurrentEntry = 0;
  102. _dwObjectReturned = 0;
  103. _dwInfoType = 0;
  104. _dwPropCurrentEntry = 0;
  105. _hPropOperationData = NULL;
  106. _lpAttrDefs = NULL;
  107. _dwPropObjectCurrentEntry = 0;
  108. _dwPropObjectReturned = 0;
  109. _dwPropInfoType = 0;
  110. }
  111. CNDSSchemaEnum::~CNDSSchemaEnum()
  112. {
  113. ADsFreeString( _bstrName );
  114. ADsFreeString( _bstrADsPath );
  115. ADsFreeString( _bstrNDSTreeName );
  116. if ( _pObjList != NULL )
  117. {
  118. delete _pObjList;
  119. _pObjList = NULL;
  120. }
  121. }
  122. //+---------------------------------------------------------------------------
  123. //
  124. // Function: CNDSSchemaEnum::Next
  125. //
  126. // Synopsis: Returns cElements number of requested NetOle objects in the
  127. // array supplied in pvar.
  128. //
  129. // Arguments: [cElements] -- The number of elements requested by client
  130. // [pvar] -- ptr to array of VARIANTs to for return objects
  131. // [pcElementFetched] -- if non-NULL, then number of elements
  132. // -- actually returned is placed here
  133. //
  134. // Returns: HRESULT -- S_OK if number of elements requested are returned
  135. // -- S_FALSE if number of elements is < requested
  136. //
  137. // Modifies:
  138. //
  139. // History: 11-3-95 yihsins Created.
  140. //
  141. //----------------------------------------------------------------------------
  142. STDMETHODIMP
  143. CNDSSchemaEnum::Next(
  144. ULONG cElements,
  145. VARIANT FAR* pvar,
  146. ULONG FAR* pcElementFetched
  147. )
  148. {
  149. ULONG cElementFetched = 0;
  150. HRESULT hr = S_OK;
  151. hr = EnumObjects(
  152. cElements,
  153. pvar,
  154. &cElementFetched
  155. );
  156. if ( pcElementFetched )
  157. *pcElementFetched = cElementFetched;
  158. RRETURN_EXP_IF_ERR(hr);
  159. }
  160. HRESULT
  161. CNDSSchemaEnum::EnumObjects(
  162. DWORD ObjectType,
  163. ULONG cElements,
  164. VARIANT FAR * pvar,
  165. ULONG FAR * pcElementFetched
  166. )
  167. {
  168. switch (ObjectType)
  169. {
  170. case NDS_CLASS_ID:
  171. RRETURN (EnumClasses(cElements, pvar, pcElementFetched));
  172. case NDS_PROPERTY_ID:
  173. RRETURN (EnumProperties(cElements, pvar, pcElementFetched));
  174. case NDS_SYNTAX_ID:
  175. RRETURN(EnumSyntaxes(cElements, pvar, pcElementFetched));
  176. default:
  177. RRETURN(S_FALSE);
  178. }
  179. }
  180. HRESULT
  181. CNDSSchemaEnum::EnumObjects(
  182. ULONG cElements,
  183. VARIANT FAR* pvar,
  184. ULONG FAR* pcElementFetched
  185. )
  186. {
  187. DWORD i;
  188. ULONG cRequested = 0;
  189. ULONG cFetchedByPath = 0;
  190. ULONG cTotalFetched = 0;
  191. VARIANT FAR* pPathvar = pvar;
  192. HRESULT hr = S_OK;
  193. DWORD ObjectType;
  194. for (i = 0; i < cElements; i++)
  195. VariantInit(&pvar[i]);
  196. cRequested = cElements;
  197. while ( SUCCEEDED( _pObjList->GetCurrentObject(&ObjectType))
  198. && ((hr = EnumObjects( ObjectType,
  199. cRequested,
  200. pPathvar,
  201. &cFetchedByPath)) == S_FALSE )
  202. )
  203. {
  204. pPathvar += cFetchedByPath;
  205. cRequested -= cFetchedByPath;
  206. cTotalFetched += cFetchedByPath;
  207. cFetchedByPath = 0;
  208. if ( FAILED(_pObjList->Next()) )
  209. {
  210. if ( pcElementFetched )
  211. *pcElementFetched = cTotalFetched;
  212. RRETURN(S_FALSE);
  213. }
  214. _dwCurrentEntry = 0;
  215. }
  216. if ( pcElementFetched )
  217. *pcElementFetched = cTotalFetched + cFetchedByPath;
  218. RRETURN(hr);
  219. }
  220. HRESULT
  221. CNDSSchemaEnum::EnumClasses(
  222. ULONG cElements,
  223. VARIANT FAR* pvar,
  224. ULONG FAR* pcElementFetched
  225. )
  226. {
  227. HRESULT hr = S_OK;
  228. DWORD i = 0;
  229. IDispatch *pDispatch = NULL;
  230. while ( i < cElements )
  231. {
  232. hr = GetClassObject(&pDispatch);
  233. if ( hr == S_FALSE )
  234. break;
  235. VariantInit( &pvar[i] );
  236. pvar[i].vt = VT_DISPATCH;
  237. pvar[i].pdispVal = pDispatch;
  238. (*pcElementFetched)++;
  239. i++;
  240. }
  241. RRETURN(hr);
  242. }
  243. HRESULT
  244. CNDSSchemaEnum::GetClassObject(
  245. IDispatch ** ppDispatch
  246. )
  247. {
  248. HRESULT hr = S_OK;
  249. LPNDS_CLASS_DEF lpCurrentObject = NULL;
  250. DWORD dwStatus;
  251. if (!_hOperationData || (_dwObjectCurrentEntry == _dwObjectReturned)) {
  252. _dwObjectCurrentEntry = 0;
  253. _dwObjectReturned = 0;
  254. dwStatus = NwNdsReadClassDef(
  255. _hTree,
  256. NDS_INFO_NAMES_DEFS,
  257. &_hOperationData
  258. );
  259. if (dwStatus) {
  260. hr = HRESULT_FROM_WIN32(GetLastError());
  261. BAIL_ON_FAILURE(hr);
  262. }
  263. dwStatus = NwNdsGetClassDefListFromBuffer(
  264. _hOperationData,
  265. &_dwObjectReturned,
  266. &_dwInfoType,
  267. (LPVOID *) &_lpClassDefs
  268. );
  269. if (dwStatus) {
  270. hr = HRESULT_FROM_WIN32(GetLastError());
  271. BAIL_ON_FAILURE(hr);
  272. }
  273. }
  274. if (_dwObjectCurrentEntry < _dwObjectReturned) {
  275. //
  276. // Now send back the current object
  277. //
  278. lpCurrentObject = _lpClassDefs + _dwObjectCurrentEntry;
  279. hr = CNDSClass::CreateClass(
  280. _bstrADsPath,
  281. lpCurrentObject->szClassName,
  282. lpCurrentObject,
  283. _Credentials,
  284. ADS_OBJECT_BOUND,
  285. IID_IDispatch,
  286. (void **)ppDispatch
  287. );
  288. BAIL_ON_FAILURE(hr);
  289. _dwObjectCurrentEntry++;
  290. RRETURN(S_OK);
  291. }
  292. error:
  293. *ppDispatch = NULL;
  294. RRETURN(S_FALSE);
  295. }
  296. HRESULT
  297. CNDSSchemaEnum::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. CNDSSchemaEnum::GetPropertyObject(
  321. IDispatch ** ppDispatch
  322. )
  323. {
  324. HRESULT hr = S_OK;
  325. LPNDS_ATTR_DEF lpCurrentPropObject = NULL;
  326. DWORD dwStatus;
  327. if (!_hPropOperationData || (_dwPropObjectCurrentEntry == _dwPropObjectReturned)) {
  328. _dwPropObjectCurrentEntry = 0;
  329. _dwPropObjectReturned = 0;
  330. dwStatus = NwNdsReadAttrDef(
  331. _hTree,
  332. NDS_INFO_NAMES_DEFS,
  333. &_hPropOperationData
  334. );
  335. if (dwStatus) {
  336. hr = HRESULT_FROM_WIN32(GetLastError());
  337. BAIL_ON_FAILURE(hr);
  338. }
  339. dwStatus = NwNdsGetAttrDefListFromBuffer(
  340. _hPropOperationData,
  341. &_dwPropObjectReturned,
  342. &_dwInfoType,
  343. (LPVOID *) &_lpAttrDefs
  344. );
  345. if (dwStatus) {
  346. hr = HRESULT_FROM_WIN32(GetLastError());
  347. BAIL_ON_FAILURE(hr);
  348. }
  349. }
  350. if (_dwPropObjectCurrentEntry < _dwPropObjectReturned) {
  351. //
  352. // Now send back the current object
  353. //
  354. lpCurrentPropObject = _lpAttrDefs + _dwPropObjectCurrentEntry;
  355. hr = CNDSProperty::CreateProperty(
  356. _bstrADsPath,
  357. lpCurrentPropObject->szAttributeName,
  358. lpCurrentPropObject,
  359. _Credentials,
  360. ADS_OBJECT_BOUND,
  361. IID_IDispatch,
  362. (void **)ppDispatch
  363. );
  364. BAIL_ON_FAILURE(hr);
  365. _dwPropObjectCurrentEntry++;
  366. RRETURN(S_OK);
  367. }
  368. error:
  369. *ppDispatch = NULL;
  370. RRETURN(S_FALSE);
  371. }
  372. HRESULT
  373. CNDSSchemaEnum::EnumSyntaxes(
  374. ULONG cElements,
  375. VARIANT FAR* pvar,
  376. ULONG FAR* pcElementFetched
  377. )
  378. {
  379. HRESULT hr = S_OK;
  380. DWORD i = 0;
  381. IDispatch *pDispatch = NULL;
  382. while ( i < cElements )
  383. {
  384. hr = GetSyntaxObject(&pDispatch);
  385. if ( hr == S_FALSE )
  386. break;
  387. VariantInit( &pvar[i] );
  388. pvar[i].vt = VT_DISPATCH;
  389. pvar[i].pdispVal = pDispatch;
  390. (*pcElementFetched)++;
  391. i++;
  392. }
  393. RRETURN(hr);
  394. }
  395. HRESULT
  396. CNDSSchemaEnum::GetSyntaxObject(
  397. IDispatch ** ppDispatch
  398. )
  399. {
  400. HRESULT hr = S_OK;
  401. //
  402. // Now send back the current object
  403. //
  404. if ( _dwSyntaxCurrentEntry >= g_cNDSSyntax )
  405. goto error;
  406. hr = CNDSSyntax::CreateSyntax(
  407. _bstrADsPath,
  408. &g_aNDSSyntax[_dwSyntaxCurrentEntry],
  409. ADS_OBJECT_BOUND,
  410. IID_IDispatch,
  411. (void **)ppDispatch
  412. );
  413. BAIL_ON_FAILURE(hr);
  414. _dwSyntaxCurrentEntry++;
  415. RRETURN(S_OK);
  416. error:
  417. *ppDispatch = NULL;
  418. RRETURN(S_FALSE);
  419. }