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.

316 lines
6.2 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: CDNWithBinary.cxx
  7. //
  8. // Contents: DNWithBinary object
  9. //
  10. // History: 4-23-99 AjayR Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "oleds.hxx"
  14. #pragma hdrstop
  15. // Class CDNWithBinary
  16. DEFINE_IDispatch_Implementation(CDNWithBinary)
  17. CDNWithBinary::CDNWithBinary():
  18. _pDispMgr(NULL),
  19. _pszDNStr(NULL),
  20. _dwLength(0),
  21. _lpOctetStr(NULL)
  22. {
  23. ENLIST_TRACKING(CDNWithBinary);
  24. }
  25. HRESULT
  26. CDNWithBinary::CreateDNWithBinary(
  27. REFIID riid,
  28. void **ppvObj
  29. )
  30. {
  31. CDNWithBinary FAR * pDNWithBinary = NULL;
  32. HRESULT hr = S_OK;
  33. hr = AllocateDNWithBinaryObject(&pDNWithBinary);
  34. BAIL_ON_FAILURE(hr);
  35. hr = pDNWithBinary->QueryInterface(riid, ppvObj);
  36. BAIL_ON_FAILURE(hr);
  37. pDNWithBinary->Release();
  38. RRETURN(hr);
  39. error:
  40. delete pDNWithBinary;
  41. RRETURN_EXP_IF_ERR(hr);
  42. }
  43. CDNWithBinary::~CDNWithBinary( )
  44. {
  45. delete _pDispMgr;
  46. if (_lpOctetStr) {
  47. FreeADsMem(_lpOctetStr);
  48. }
  49. if (_pszDNStr) {
  50. FreeADsStr(_pszDNStr);
  51. }
  52. }
  53. STDMETHODIMP
  54. CDNWithBinary::QueryInterface(
  55. REFIID iid,
  56. LPVOID FAR* ppv
  57. )
  58. {
  59. if (IsEqualIID(iid, IID_IUnknown))
  60. {
  61. *ppv = (IADsDNWithBinary FAR *) this;
  62. }
  63. else if (IsEqualIID(iid, IID_IADsDNWithBinary))
  64. {
  65. *ppv = (IADsDNWithBinary FAR *) this;
  66. }
  67. else if (IsEqualIID(iid, IID_IDispatch))
  68. {
  69. *ppv = (IADsDNWithBinary FAR *) this;
  70. }
  71. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  72. {
  73. *ppv = (ISupportErrorInfo FAR *) this;
  74. }
  75. else
  76. {
  77. *ppv = NULL;
  78. return E_NOINTERFACE;
  79. }
  80. AddRef();
  81. return NOERROR;
  82. }
  83. HRESULT
  84. CDNWithBinary::AllocateDNWithBinaryObject(
  85. CDNWithBinary ** ppDNWithBinary
  86. )
  87. {
  88. CDNWithBinary FAR * pDNWithBinary = NULL;
  89. CDispatchMgr FAR * pDispMgr = NULL;
  90. HRESULT hr = S_OK;
  91. pDNWithBinary = new CDNWithBinary();
  92. if (pDNWithBinary == NULL) {
  93. hr = E_OUTOFMEMORY;
  94. }
  95. BAIL_ON_FAILURE(hr);
  96. pDispMgr = new CDispatchMgr;
  97. if (pDispMgr == NULL) {
  98. hr = E_OUTOFMEMORY;
  99. }
  100. BAIL_ON_FAILURE(hr);
  101. hr = LoadTypeInfoEntry(
  102. pDispMgr,
  103. LIBID_ADs,
  104. IID_IADsDNWithBinary,
  105. (IADsDNWithBinary *)pDNWithBinary,
  106. DISPID_REGULAR
  107. );
  108. BAIL_ON_FAILURE(hr);
  109. pDNWithBinary->_pDispMgr = pDispMgr;
  110. *ppDNWithBinary = pDNWithBinary;
  111. RRETURN(hr);
  112. error:
  113. delete pDNWithBinary;
  114. delete pDispMgr;
  115. RRETURN_EXP_IF_ERR(hr);
  116. }
  117. STDMETHODIMP
  118. CDNWithBinary::InterfaceSupportsErrorInfo(THIS_ REFIID riid)
  119. {
  120. if (IsEqualIID(riid, IID_IADsDNWithBinary)) {
  121. return S_OK;
  122. } else {
  123. return S_FALSE;
  124. }
  125. }
  126. //
  127. // Methods to get and put the octet string part.
  128. //
  129. STDMETHODIMP
  130. CDNWithBinary::get_BinaryValue(THIS_ VARIANT FAR* pvBinaryValue)
  131. {
  132. HRESULT hr = S_OK;
  133. SAFEARRAY *aList = NULL;
  134. SAFEARRAYBOUND aBound;
  135. CHAR HUGEP *pArray = NULL;
  136. /*
  137. if (!pvBinaryValue) {
  138. }
  139. RRETURN_EXP_IF_ERR(hr = E_ADS_BAD_PARAMETER);
  140. }
  141. */
  142. aBound.lLbound = 0;
  143. aBound.cElements = _dwLength;
  144. aList = SafeArrayCreate( VT_UI1, 1, &aBound );
  145. if ( aList == NULL )
  146. {
  147. hr = E_OUTOFMEMORY;
  148. BAIL_ON_FAILURE(hr);
  149. }
  150. hr = SafeArrayAccessData( aList, (void HUGEP * FAR *) &pArray );
  151. BAIL_ON_FAILURE(hr);
  152. memcpy( pArray, _lpOctetStr, aBound.cElements );
  153. SafeArrayUnaccessData( aList );
  154. V_VT(pvBinaryValue) = VT_ARRAY | VT_UI1;
  155. V_ARRAY(pvBinaryValue) = aList;
  156. RRETURN(hr);
  157. error:
  158. if ( aList )
  159. SafeArrayDestroy( aList );
  160. RRETURN(hr);
  161. }
  162. STDMETHODIMP
  163. CDNWithBinary::put_BinaryValue(THIS_ VARIANT vBinaryValue)
  164. {
  165. HRESULT hr = S_OK;
  166. VARIANT *pvProp = NULL;
  167. LONG dwSLBound = 0;
  168. LONG dwSUBound = 0;
  169. CHAR HUGEP *pArray = NULL;
  170. //
  171. // Check for variant by ref.
  172. //
  173. pvProp = &vBinaryValue;
  174. if (V_VT(pvProp) == (VT_BYREF|VT_VARIANT)) {
  175. pvProp = V_VARIANTREF(&vBinaryValue);
  176. }
  177. if (_lpOctetStr) {
  178. FreeADsMem(_lpOctetStr);
  179. _lpOctetStr = NULL;
  180. _dwLength = 0;
  181. }
  182. if( pvProp->vt != (VT_ARRAY | VT_UI1)) {
  183. RRETURN(hr = E_ADS_BAD_PARAMETER);
  184. }
  185. hr = SafeArrayGetLBound(
  186. V_ARRAY(pvProp),
  187. 1,
  188. (long FAR *) &dwSLBound
  189. );
  190. BAIL_ON_FAILURE(hr);
  191. hr = SafeArrayGetUBound(
  192. V_ARRAY(pvProp),
  193. 1,
  194. (long FAR *) &dwSUBound
  195. );
  196. BAIL_ON_FAILURE(hr);
  197. _dwLength = dwSUBound -dwSLBound + 1;
  198. _lpOctetStr = (LPBYTE) AllocADsMem(_dwLength);
  199. if (!_lpOctetStr) {
  200. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  201. }
  202. hr = SafeArrayAccessData(
  203. V_ARRAY(pvProp),
  204. (void HUGEP * FAR *) &pArray
  205. );
  206. BAIL_ON_FAILURE(hr);
  207. memcpy(_lpOctetStr, pArray, _dwLength);
  208. SafeArrayUnaccessData( V_ARRAY(pvProp) );
  209. error:
  210. if (_lpOctetStr && FAILED(hr)) {
  211. FreeADsMem(_lpOctetStr);
  212. _lpOctetStr = NULL;
  213. _dwLength = NULL;
  214. }
  215. RRETURN(hr);
  216. }
  217. //
  218. // Methods to get and put the DN string.
  219. //
  220. STDMETHODIMP
  221. CDNWithBinary::get_DNString(THIS_ BSTR FAR* pbstrDNString)
  222. {
  223. HRESULT hr = S_OK;
  224. if (FAILED(hr = ValidateOutParameter(pbstrDNString))){
  225. RRETURN_EXP_IF_ERR(hr);
  226. }
  227. hr = ADsAllocString(_pszDNStr, pbstrDNString);
  228. RRETURN_EXP_IF_ERR(hr);
  229. }
  230. STDMETHODIMP
  231. CDNWithBinary::put_DNString(THIS_ BSTR bstrDNString)
  232. {
  233. HRESULT hr = S_OK;
  234. if (_pszDNStr) {
  235. FreeADsStr(_pszDNStr);
  236. _pszDNStr = NULL;
  237. }
  238. _pszDNStr = AllocADsStr(bstrDNString);
  239. if (bstrDNString && !_pszDNStr) {
  240. hr = E_OUTOFMEMORY;
  241. }
  242. RRETURN(hr);
  243. }