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.

377 lines
7.2 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cLocality.cxx
  7. //
  8. // Contents: Locality object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "ldap.hxx"
  14. #pragma hdrstop
  15. struct _propmap
  16. {
  17. LPTSTR pszADsProp;
  18. LPTSTR pszLDAPProp;
  19. } aLocalityPropMapping[] =
  20. { // { TEXT("Description"), TEXT("description") },
  21. { TEXT("LocalityName"), TEXT("l") },
  22. { TEXT("PostalAddress"), TEXT("street") } // NTDS
  23. // { TEXT("SeeAlso"), TEXT("seeAlso") }
  24. };
  25. // Class CLDAPLocality
  26. // IADsExtension::PrivateGetIDsOfNames()/Invoke(), Operate() not included
  27. DEFINE_IADsExtension_Implementation(CLDAPLocality)
  28. DEFINE_IPrivateDispatch_Implementation(CLDAPLocality)
  29. DEFINE_DELEGATING_IDispatch_Implementation(CLDAPLocality)
  30. DEFINE_CONTAINED_IADs_Implementation(CLDAPLocality)
  31. DEFINE_CONTAINED_IADsPutGet_Implementation(CLDAPLocality, aLocalityPropMapping)
  32. CLDAPLocality::CLDAPLocality():
  33. _pUnkOuter(NULL),
  34. _pADs(NULL),
  35. _fDispInitialized(FALSE),
  36. _pDispMgr(NULL)
  37. {
  38. ENLIST_TRACKING(CLDAPLocality);
  39. }
  40. HRESULT
  41. CLDAPLocality::CreateLocality(
  42. IUnknown *pUnkOuter,
  43. REFIID riid,
  44. void **ppvObj
  45. )
  46. {
  47. HRESULT hr = S_OK;
  48. CLDAPLocality FAR * pLocality = NULL;
  49. IADs FAR * pADs = NULL;
  50. CAggregateeDispMgr FAR * pDispMgr = NULL;
  51. //
  52. // our extension object only works in a provider (aggregator) environment
  53. // environment
  54. //
  55. ASSERT(pUnkOuter);
  56. ASSERT(ppvObj);
  57. ASSERT(IsEqualIID(riid, IID_IUnknown));
  58. pLocality = new CLDAPLocality();
  59. if (pLocality == NULL) {
  60. hr = E_OUTOFMEMORY;
  61. BAIL_ON_FAILURE(hr);
  62. }
  63. //
  64. // Ref Count = 1 from object tracker
  65. //
  66. //
  67. // CAggregateeDispMgr to handle
  68. // IADsExtension::PrivateGetIDsOfNames()/PrivatInovke()
  69. //
  70. pDispMgr = new CAggregateeDispMgr;
  71. if (pDispMgr == NULL) {
  72. hr = E_OUTOFMEMORY;
  73. BAIL_ON_FAILURE(hr);
  74. }
  75. pLocality->_pDispMgr = pDispMgr;
  76. hr = pDispMgr->LoadTypeInfoEntry(
  77. LIBID_ADs,
  78. IID_IADsLocality,
  79. (IADsLocality *)pLocality,
  80. DISPID_REGULAR
  81. );
  82. BAIL_ON_FAILURE(hr);
  83. //
  84. // Store the pointer to the pUnkOuter object to delegate all IUnknown
  85. // calls to the aggregator AND DO NOT add ref this pointer
  86. //
  87. pLocality->_pUnkOuter = pUnkOuter;
  88. //
  89. // Ccache pADs Pointer to delegate all IDispatch calls to
  90. // the aggregator. But release immediately to avoid the aggregatee
  91. // having a reference count on the aggregator -> cycle ref counting
  92. //
  93. hr = pUnkOuter->QueryInterface(
  94. IID_IADs,
  95. (void **)&pADs
  96. );
  97. //
  98. // Our spec stated extesnion writers can expect the aggregator in our
  99. // provider ot support IDispatch. If not, major bug.
  100. //
  101. ASSERT(SUCCEEDED(hr));
  102. pADs->Release(); // see doc above pUnkOuter->QI
  103. pLocality->_pADs = pADs;
  104. //
  105. // pass non-delegating IUnknown back to the aggregator
  106. //
  107. *ppvObj = (INonDelegatingUnknown FAR *) pLocality;
  108. RRETURN(hr);
  109. error:
  110. if (pLocality)
  111. delete pLocality;
  112. *ppvObj = NULL;
  113. RRETURN(hr);
  114. }
  115. CLDAPLocality::~CLDAPLocality( )
  116. {
  117. //
  118. // Remember that the aggregatee has no reference counts to
  119. // decrement.
  120. //
  121. delete _pDispMgr;
  122. }
  123. STDMETHODIMP
  124. CLDAPLocality::QueryInterface(
  125. REFIID iid,
  126. LPVOID FAR* ppv
  127. )
  128. {
  129. HRESULT hr = S_OK;
  130. hr = _pUnkOuter->QueryInterface(iid,ppv);
  131. RRETURN(hr);
  132. }
  133. STDMETHODIMP
  134. CLDAPLocality::NonDelegatingQueryInterface(
  135. REFIID iid,
  136. LPVOID FAR* ppv
  137. )
  138. {
  139. ASSERT(ppv);
  140. if (IsEqualIID(iid, IID_IADsLocality)) {
  141. *ppv = (IADsLocality FAR *) this;
  142. } else if (IsEqualIID(iid, IID_IADsExtension)) {
  143. *ppv = (IADsExtension FAR *) this;
  144. } else if (IsEqualIID(iid, IID_IUnknown)) {
  145. //
  146. // probably not needed since our 3rd party extension does not stand
  147. // alone and provider does not ask for this, but to be safe
  148. //
  149. *ppv = (INonDelegatingUnknown FAR *) this;
  150. } else {
  151. *ppv = NULL;
  152. return E_NOINTERFACE;
  153. }
  154. //
  155. // Delegating AddRef to aggregator for IADsExtesnion and.
  156. // AddRef on itself for IPrivateUnknown. (both tested.)
  157. //
  158. ((IUnknown *) (*ppv)) -> AddRef();
  159. return S_OK;
  160. }
  161. STDMETHODIMP
  162. CLDAPLocality::ADSIInitializeObject(
  163. THIS_ BSTR lpszUserName,
  164. BSTR lpszPassword,
  165. long lnReserved
  166. )
  167. {
  168. CCredentials NewCredentials(lpszUserName, lpszPassword, lnReserved);
  169. _Credentials = NewCredentials;
  170. RRETURN(S_OK);
  171. }
  172. STDMETHODIMP
  173. CLDAPLocality::ADSIInitializeDispatchManager(
  174. long dwExtensionId
  175. )
  176. {
  177. HRESULT hr = S_OK;
  178. if (_fDispInitialized) {
  179. RRETURN(E_FAIL);
  180. }
  181. hr = _pDispMgr->InitializeDispMgr(dwExtensionId);
  182. if (SUCCEEDED(hr)) {
  183. _fDispInitialized = TRUE;
  184. }
  185. RRETURN(hr);
  186. }
  187. STDMETHODIMP CLDAPLocality::get_Description(THIS_ BSTR FAR* retval)
  188. {
  189. GET_PROPERTY_BSTR((IADsLocality *)this,Description);
  190. }
  191. STDMETHODIMP CLDAPLocality::put_Description(THIS_ BSTR bstrDescription)
  192. {
  193. PUT_PROPERTY_BSTR((IADsLocality *)this,Description);
  194. }
  195. STDMETHODIMP CLDAPLocality::get_LocalityName(THIS_ BSTR FAR* retval)
  196. {
  197. GET_PROPERTY_BSTR((IADsLocality *)this,LocalityName);
  198. }
  199. STDMETHODIMP CLDAPLocality::put_LocalityName(THIS_ BSTR bstrLocalityName)
  200. {
  201. PUT_PROPERTY_BSTR((IADsLocality *)this,LocalityName);
  202. }
  203. STDMETHODIMP CLDAPLocality::get_PostalAddress(THIS_ BSTR FAR* retval)
  204. {
  205. GET_PROPERTY_BSTR((IADsLocality *)this,PostalAddress);
  206. }
  207. STDMETHODIMP CLDAPLocality::put_PostalAddress(THIS_ BSTR bstrPostalAddress)
  208. {
  209. PUT_PROPERTY_BSTR((IADsLocality *)this,PostalAddress);
  210. }
  211. STDMETHODIMP CLDAPLocality::get_SeeAlso(THIS_ VARIANT FAR* retval)
  212. {
  213. GET_PROPERTY_VARIANT((IADsLocality *)this,SeeAlso);
  214. }
  215. STDMETHODIMP CLDAPLocality::put_SeeAlso(THIS_ VARIANT vSeeAlso)
  216. {
  217. PUT_PROPERTY_VARIANT((IADsLocality *)this,SeeAlso);
  218. }
  219. STDMETHODIMP
  220. CLDAPLocality::ADSIReleaseObject()
  221. {
  222. delete this;
  223. RRETURN(S_OK);
  224. }
  225. //
  226. // IADsExtension::Operate()
  227. //
  228. STDMETHODIMP
  229. CLDAPLocality::Operate(
  230. THIS_ DWORD dwCode,
  231. VARIANT varData1,
  232. VARIANT varData2,
  233. VARIANT varData3
  234. )
  235. {
  236. HRESULT hr = S_OK;
  237. switch (dwCode) {
  238. case ADS_EXT_INITCREDENTIALS:
  239. hr = InitCredentials(
  240. &varData1,
  241. &varData2,
  242. &varData3
  243. );
  244. break;
  245. default:
  246. hr = E_FAIL;
  247. break;
  248. }
  249. RRETURN(hr);
  250. }
  251. HRESULT
  252. CLDAPLocality::InitCredentials(
  253. VARIANT * pvarUserName,
  254. VARIANT * pvarPassword,
  255. VARIANT * pvarFlags
  256. )
  257. {
  258. BSTR bstrUser = NULL;
  259. BSTR bstrPwd = NULL;
  260. DWORD dwFlags = 0;
  261. ASSERT(V_VT(pvarUserName) == VT_BSTR);
  262. ASSERT(V_VT(pvarPassword) == VT_BSTR);
  263. ASSERT(V_VT(pvarFlags) == VT_I4);
  264. bstrUser = V_BSTR(pvarUserName);
  265. bstrPwd = V_BSTR(pvarPassword);
  266. dwFlags = V_I4(pvarFlags);
  267. CCredentials NewCredentials(bstrUser, bstrPwd, dwFlags);
  268. _Credentials = NewCredentials;
  269. RRETURN(S_OK);
  270. }