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.

361 lines
7.0 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: object.cxx
  7. //
  8. // Contents: Windows NT 3.5 Enumerator Code
  9. //
  10. // History:
  11. //----------------------------------------------------------------------------
  12. #include "ldap.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. // if actually the filter is not specified, we don't do anything
  36. if (V_VT(&vFilter) == VT_EMPTY) {
  37. *ppObjectTypeList = pObjectTypeList;
  38. RRETURN(hr);
  39. }
  40. hr = BuildObjectArray(
  41. vFilter,
  42. &pObjectTypeList->_pObjList,
  43. &pObjectTypeList->_dwMaxElements
  44. );
  45. if (FAILED(hr)) {
  46. *ppObjectTypeList = pObjectTypeList;
  47. RRETURN(S_OK);
  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. BSTR* pszObject
  80. )
  81. {
  82. HRESULT hr = S_OK;
  83. if ((_dwCurrentIndex > _dwUBound) || (_pObjList == NULL)) {
  84. return(E_FAIL);
  85. }
  86. hr = SafeArrayGetElement(
  87. _pObjList,
  88. (long FAR *)&_dwCurrentIndex,
  89. (void *)pszObject
  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. _dwCurrentIndex = _dwLBound;
  108. return(hr);
  109. }
  110. BOOL
  111. ObjectTypeList::IsEmpty()
  112. {
  113. if(_dwMaxElements > 0) {
  114. return FALSE;
  115. }
  116. else{
  117. return TRUE;
  118. }
  119. }
  120. HRESULT
  121. IsValidFilter(
  122. LPTSTR ObjectName,
  123. DWORD *pdwFilterId,
  124. PFILTERS pFilters,
  125. DWORD dwMaxFilters
  126. )
  127. {
  128. DWORD i = 0;
  129. for (i = 0; i < dwMaxFilters; i++) {
  130. if (!_tcsicmp(ObjectName, (pFilters + i)->szObjectName)) {
  131. *pdwFilterId = (pFilters + i)->dwFilterId;
  132. RRETURN(S_OK);
  133. }
  134. }
  135. *pdwFilterId = 0;
  136. RRETURN(E_FAIL);
  137. }
  138. HRESULT
  139. BuildDefaultObjectArray(
  140. PFILTERS pFilters,
  141. DWORD dwMaxFilters,
  142. SAFEARRAY ** ppFilter,
  143. DWORD * pdwNumElements
  144. )
  145. {
  146. DWORD i;
  147. HRESULT hr = S_OK;
  148. SAFEARRAYBOUND sabNewArray;
  149. SAFEARRAY * pFilter = NULL;
  150. sabNewArray.cElements = dwMaxFilters;
  151. sabNewArray.lLbound = 0;
  152. pFilter = SafeArrayCreate(
  153. VT_I4,
  154. 1,
  155. &sabNewArray
  156. );
  157. if (!pFilter){
  158. hr = E_OUTOFMEMORY;
  159. BAIL_ON_FAILURE(hr);
  160. }
  161. for (i = 0; i < dwMaxFilters; i++) {
  162. hr = SafeArrayPutElement(
  163. pFilter,
  164. (long *)&i,
  165. (void *)&((pFilters + i)->dwFilterId)
  166. );
  167. BAIL_ON_FAILURE(hr);
  168. }
  169. *ppFilter = pFilter;
  170. *pdwNumElements = dwMaxFilters;
  171. RRETURN(S_OK);
  172. error:
  173. if (pFilter) {
  174. SafeArrayDestroy(pFilter);
  175. }
  176. *ppFilter = NULL;
  177. *pdwNumElements = 0;
  178. RRETURN(hr);
  179. }
  180. HRESULT
  181. BuildObjectArray(
  182. VARIANT var,
  183. SAFEARRAY ** ppFilter,
  184. DWORD * pdwNumElements
  185. )
  186. {
  187. LONG uDestCount = 0;
  188. LONG dwSLBound = 0;
  189. LONG dwSUBound = 0;
  190. VARIANT v;
  191. VARIANT varDest;
  192. LONG i;
  193. HRESULT hr = S_OK;
  194. SAFEARRAYBOUND sabNewArray;
  195. DWORD dwFilterId;
  196. SAFEARRAY * pFilter = NULL;
  197. if(!((V_VT(&var) & VT_VARIANT) && V_ISARRAY(&var))) {
  198. RRETURN(E_FAIL);
  199. }
  200. //
  201. // Check that there is only one dimension in this array
  202. //
  203. if ((V_ARRAY(&var))->cDims != 1) {
  204. hr = E_FAIL;
  205. BAIL_ON_FAILURE(hr);
  206. }
  207. //
  208. // Check that there is atleast one element in this array
  209. //
  210. if ((V_ARRAY(&var))->rgsabound[0].cElements == 0){
  211. hr = E_FAIL;
  212. BAIL_ON_FAILURE(hr);
  213. }
  214. //
  215. // We know that this is a valid single dimension array
  216. //
  217. hr = SafeArrayGetLBound(V_ARRAY(&var),
  218. 1,
  219. (long FAR *)&dwSLBound
  220. );
  221. BAIL_ON_FAILURE(hr);
  222. hr = SafeArrayGetUBound(V_ARRAY(&var),
  223. 1,
  224. (long FAR *)&dwSUBound
  225. );
  226. BAIL_ON_FAILURE(hr);
  227. sabNewArray.cElements = dwSUBound - dwSLBound + 1;
  228. sabNewArray.lLbound = dwSLBound;
  229. // creates a safe array filter (contains object class name)
  230. pFilter = SafeArrayCreate(
  231. VT_BSTR,
  232. 1,
  233. &sabNewArray
  234. );
  235. if (!pFilter) {
  236. hr = E_OUTOFMEMORY;
  237. BAIL_ON_FAILURE(hr);
  238. }
  239. for (i = dwSLBound; i <= dwSUBound; i++) {
  240. VariantInit(&v);
  241. hr = SafeArrayGetElement(V_ARRAY(&var),
  242. (long FAR *)&i,
  243. &v
  244. );
  245. if (FAILED(hr)) {
  246. continue;
  247. }
  248. hr = SafeArrayPutElement(
  249. pFilter,
  250. (long*)&uDestCount,
  251. V_BSTR(&v)
  252. );
  253. VariantClear(&v);
  254. if(FAILED(hr)){
  255. continue;
  256. }
  257. uDestCount++;
  258. }
  259. //
  260. // There was nothing of value that could be retrieved from the
  261. // filter.
  262. //
  263. if (!uDestCount ) {
  264. hr = E_FAIL;
  265. BAIL_ON_FAILURE(hr);
  266. }
  267. *pdwNumElements = uDestCount;
  268. *ppFilter = pFilter;
  269. RRETURN(S_OK);
  270. error:
  271. if (pFilter) {
  272. SafeArrayDestroy(pFilter);
  273. }
  274. *ppFilter = NULL;
  275. *pdwNumElements = 0;
  276. RRETURN(hr);
  277. }