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.

358 lines
6.9 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: object.cxx
  7. //
  8. // Contents: ADSI object type code
  9. //
  10. // History:
  11. //----------------------------------------------------------------------------
  12. #include "iis.hxx"
  13. #pragma hdrstop
  14. ObjectTypeList::ObjectTypeList()
  15. {
  16. _pObjList = NULL;
  17. _dwCurrentIndex = 0;
  18. _dwMaxElements = 0;
  19. _dwUBound = 0;
  20. _dwLBound = 0;
  21. }
  22. HRESULT
  23. ObjectTypeList::CreateObjectTypeList(
  24. VARIANT vFilter,
  25. ObjectTypeList ** ppObjectTypeList
  26. )
  27. {
  28. ObjectTypeList * pObjectTypeList = NULL;
  29. HRESULT hr = S_OK;
  30. pObjectTypeList = new ObjectTypeList;
  31. if (!pObjectTypeList) {
  32. hr = E_OUTOFMEMORY;
  33. BAIL_ON_FAILURE(hr);
  34. }
  35. hr = BuildObjectArray(
  36. vFilter,
  37. &pObjectTypeList->_pObjList,
  38. &pObjectTypeList->_dwMaxElements
  39. );
  40. if (FAILED(hr)) {
  41. hr = BuildDefaultObjectArray(
  42. gpFilters,
  43. gdwMaxFilters,
  44. &pObjectTypeList->_pObjList,
  45. &pObjectTypeList->_dwMaxElements
  46. );
  47. BAIL_ON_FAILURE(hr);
  48. }
  49. hr = SafeArrayGetUBound(
  50. pObjectTypeList->_pObjList,
  51. 1,
  52. (long FAR *)&pObjectTypeList->_dwUBound
  53. );
  54. BAIL_ON_FAILURE(hr);
  55. hr = SafeArrayGetLBound(
  56. pObjectTypeList->_pObjList,
  57. 1,
  58. (long FAR *)&pObjectTypeList->_dwLBound
  59. );
  60. BAIL_ON_FAILURE(hr);
  61. pObjectTypeList->_dwCurrentIndex = pObjectTypeList->_dwLBound;
  62. *ppObjectTypeList = pObjectTypeList;
  63. RRETURN(S_OK);
  64. error:
  65. if (pObjectTypeList) {
  66. delete pObjectTypeList;
  67. }
  68. RRETURN(hr);
  69. }
  70. ObjectTypeList::~ObjectTypeList()
  71. {
  72. HRESULT hr = S_OK;
  73. if (_pObjList) {
  74. hr = SafeArrayDestroy(_pObjList);
  75. }
  76. }
  77. HRESULT
  78. ObjectTypeList::GetCurrentObject(
  79. PDWORD pdwObject
  80. )
  81. {
  82. HRESULT hr = S_OK;
  83. if (_dwCurrentIndex > _dwUBound) {
  84. return(E_FAIL);
  85. }
  86. hr = SafeArrayGetElement(
  87. _pObjList,
  88. (long FAR *)&_dwCurrentIndex,
  89. (void *)pdwObject
  90. );
  91. RRETURN(hr);
  92. }
  93. HRESULT
  94. ObjectTypeList::Next()
  95. {
  96. HRESULT hr = S_OK;
  97. _dwCurrentIndex++;
  98. if (_dwCurrentIndex > _dwUBound) {
  99. return(E_FAIL);
  100. }
  101. return(hr);
  102. }
  103. HRESULT
  104. ObjectTypeList::Reset()
  105. {
  106. HRESULT hr = S_OK;
  107. return(hr);
  108. }
  109. HRESULT
  110. IsValidFilter(
  111. LPWSTR ObjectName,
  112. DWORD *pdwFilterId,
  113. PFILTERS pFilters,
  114. DWORD dwMaxFilters
  115. )
  116. {
  117. DWORD i = 0;
  118. for (i = 0; i < dwMaxFilters; i++) {
  119. if (!_wcsicmp(ObjectName, (pFilters + i)->szObjectName)) {
  120. *pdwFilterId = (pFilters + i)->dwFilterId;
  121. RRETURN(S_OK);
  122. }
  123. }
  124. *pdwFilterId = 0;
  125. RRETURN(E_FAIL);
  126. }
  127. HRESULT
  128. BuildDefaultObjectArray(
  129. PFILTERS pFilters,
  130. DWORD dwMaxFilters,
  131. SAFEARRAY ** ppFilter,
  132. DWORD * pdwNumElements
  133. )
  134. {
  135. DWORD i;
  136. HRESULT hr = S_OK;
  137. SAFEARRAYBOUND sabNewArray;
  138. SAFEARRAY * pFilter = NULL;
  139. sabNewArray.cElements = dwMaxFilters;
  140. sabNewArray.lLbound = 0;
  141. pFilter = SafeArrayCreate(
  142. VT_I4,
  143. 1,
  144. &sabNewArray
  145. );
  146. if (!pFilter){
  147. hr = E_OUTOFMEMORY;
  148. BAIL_ON_FAILURE(hr);
  149. }
  150. for (i = 0; i < dwMaxFilters; i++) {
  151. hr = SafeArrayPutElement(
  152. pFilter,
  153. (long *)&i,
  154. (void *)&((pFilters + i)->dwFilterId)
  155. );
  156. BAIL_ON_FAILURE(hr);
  157. }
  158. *ppFilter = pFilter;
  159. *pdwNumElements = dwMaxFilters;
  160. RRETURN(S_OK);
  161. error:
  162. if (pFilter) {
  163. SafeArrayDestroy(pFilter);
  164. }
  165. *ppFilter = NULL;
  166. *pdwNumElements = 0;
  167. RRETURN(hr);
  168. }
  169. HRESULT
  170. BuildObjectArray(
  171. VARIANT var,
  172. SAFEARRAY ** ppFilter,
  173. DWORD * pdwNumElements
  174. )
  175. {
  176. LONG uDestCount = 0;
  177. LONG dwSLBound = 0;
  178. LONG dwSUBound = 0;
  179. VARIANT v;
  180. LONG i;
  181. HRESULT hr = S_OK;
  182. SAFEARRAYBOUND sabNewArray;
  183. DWORD dwFilterId;
  184. SAFEARRAY * pFilter = NULL;
  185. if(!((V_VT(&var) & VT_VARIANT) && V_ISARRAY(&var))) {
  186. RRETURN(E_FAIL);
  187. }
  188. //
  189. // Check that there is only one dimension in this array
  190. //
  191. if ((V_ARRAY(&var))->cDims != 1) {
  192. hr = E_FAIL;
  193. BAIL_ON_FAILURE(hr);
  194. }
  195. //
  196. // Check that there is atleast one element in this array
  197. //
  198. if ((V_ARRAY(&var))->rgsabound[0].cElements == 0){
  199. hr = E_FAIL;
  200. BAIL_ON_FAILURE(hr);
  201. }
  202. //
  203. // We know that this is a valid single dimension array
  204. //
  205. hr = SafeArrayGetLBound(V_ARRAY(&var),
  206. 1,
  207. (long FAR *)&dwSLBound
  208. );
  209. BAIL_ON_FAILURE(hr);
  210. hr = SafeArrayGetUBound(V_ARRAY(&var),
  211. 1,
  212. (long FAR *)&dwSUBound
  213. );
  214. BAIL_ON_FAILURE(hr);
  215. sabNewArray.cElements = dwSUBound - dwSLBound + 1;
  216. sabNewArray.lLbound = dwSLBound;
  217. pFilter = SafeArrayCreate(
  218. VT_I4,
  219. 1,
  220. &sabNewArray
  221. );
  222. if (!pFilter) {
  223. hr = E_OUTOFMEMORY;
  224. BAIL_ON_FAILURE(hr);
  225. }
  226. for (i = dwSLBound; i <= dwSUBound; i++) {
  227. VariantInit(&v);
  228. hr = SafeArrayGetElement(V_ARRAY(&var),
  229. (long FAR *)&i,
  230. &v
  231. );
  232. if (FAILED(hr)) {
  233. continue;
  234. }
  235. hr = IsValidFilter(
  236. V_BSTR(&v),
  237. &dwFilterId,
  238. gpFilters,
  239. gdwMaxFilters
  240. );
  241. if (FAILED(hr)) {
  242. VariantClear(&v);
  243. continue;
  244. }
  245. VariantClear(&v);
  246. hr = SafeArrayPutElement(
  247. pFilter,
  248. (long*)&uDestCount,
  249. (void *)&dwFilterId
  250. );
  251. if(FAILED(hr)){
  252. continue;
  253. }
  254. uDestCount++;
  255. }
  256. //
  257. // There was nothing of value that could be retrieved from the
  258. // filter.
  259. //
  260. if (!uDestCount ) {
  261. hr = E_FAIL;
  262. BAIL_ON_FAILURE(hr);
  263. }
  264. *pdwNumElements = uDestCount;
  265. *ppFilter = pFilter;
  266. RRETURN(S_OK);
  267. error:
  268. if (pFilter) {
  269. SafeArrayDestroy(pFilter);
  270. }
  271. *ppFilter = NULL;
  272. *pdwNumElements = 0;
  273. RRETURN(hr);
  274. }