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.

511 lines
10 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 "nds.hxx"
  14. #pragma hdrstop
  15. struct _propmap
  16. {
  17. LPTSTR pszADsProp;
  18. LPTSTR pszNDSProp;
  19. } aLocalityPropMapping[] =
  20. { { TEXT("Description"), TEXT("Description") },
  21. { TEXT("LocalityName"), TEXT("L") },
  22. { TEXT("PostalAddress"), TEXT("Postal Address") },
  23. { TEXT("SeeAlso"), TEXT("See Also") }
  24. };
  25. // Class CNDSLocality
  26. DEFINE_IDispatch_Implementation(CNDSLocality)
  27. DEFINE_CONTAINED_IADs_Implementation(CNDSLocality)
  28. DEFINE_CONTAINED_IDirectoryObject_Implementation(CNDSLocality)
  29. DEFINE_CONTAINED_IDirectorySearch_Implementation(CNDSLocality)
  30. DEFINE_CONTAINED_IDirectorySchemaMgmt_Implementation(CNDSLocality)
  31. DEFINE_CONTAINED_IADsPropertyList_Implementation(CNDSLocality)
  32. DEFINE_CONTAINED_IADsPutGet_Implementation(CNDSLocality, aLocalityPropMapping)
  33. CNDSLocality::CNDSLocality():
  34. _pADs(NULL),
  35. _pDSObject(NULL),
  36. _pDSSearch(NULL),
  37. _pDSAttrMgmt(NULL),
  38. _pADsContainer(NULL),
  39. _pADsPropList(NULL),
  40. _pDispMgr(NULL)
  41. {
  42. ENLIST_TRACKING(CNDSLocality);
  43. }
  44. HRESULT
  45. CNDSLocality::CreateLocality(
  46. IADs * pADs,
  47. REFIID riid,
  48. void **ppvObj
  49. )
  50. {
  51. CNDSLocality FAR * pLocality = NULL;
  52. HRESULT hr = S_OK;
  53. hr = AllocateLocalityObject(pADs, &pLocality);
  54. BAIL_ON_FAILURE(hr);
  55. hr = pLocality->QueryInterface(riid, ppvObj);
  56. BAIL_ON_FAILURE(hr);
  57. pLocality->Release();
  58. RRETURN(hr);
  59. error:
  60. delete pLocality;
  61. RRETURN(hr);
  62. }
  63. CNDSLocality::~CNDSLocality( )
  64. {
  65. if ( _pADs )
  66. _pADs->Release();
  67. if ( _pADsContainer )
  68. _pADsContainer->Release();
  69. if (_pDSObject) {
  70. _pDSObject->Release();
  71. }
  72. if (_pDSSearch) {
  73. _pDSSearch->Release();
  74. }
  75. if (_pDSAttrMgmt) {
  76. _pDSAttrMgmt->Release();
  77. }
  78. if (_pADsPropList) {
  79. _pADsPropList->Release();
  80. }
  81. delete _pDispMgr;
  82. }
  83. STDMETHODIMP
  84. CNDSLocality::QueryInterface(
  85. REFIID iid,
  86. LPVOID FAR* ppv
  87. )
  88. {
  89. if (ppv == NULL) {
  90. RRETURN(E_POINTER);
  91. }
  92. if (IsEqualIID(iid, IID_IUnknown))
  93. {
  94. *ppv = (IADsLocality FAR *) this;
  95. }
  96. else if (IsEqualIID(iid, IID_IADsLocality))
  97. {
  98. *ppv = (IADsLocality FAR *) this;
  99. }
  100. else if (IsEqualIID(iid, IID_IADs))
  101. {
  102. *ppv = (IADsLocality FAR *) this;
  103. }
  104. else if (IsEqualIID(iid, IID_IDispatch))
  105. {
  106. *ppv = (IADsLocality FAR *) this;
  107. }
  108. else if (IsEqualIID(iid, IID_IADsContainer) && _pADsContainer)
  109. {
  110. *ppv = (IADsContainer FAR *) this;
  111. }
  112. else if (IsEqualIID(iid, IID_IDirectoryObject))
  113. {
  114. *ppv = (IDirectoryObject FAR *) this;
  115. }
  116. else if (IsEqualIID(iid, IID_IDirectorySearch))
  117. {
  118. *ppv = (IDirectorySearch FAR *) this;
  119. }
  120. else if (IsEqualIID(iid, IID_IADsPropertyList) && _pADsPropList)
  121. {
  122. *ppv = (IADsPropertyList FAR *) this;
  123. }
  124. else if (IsEqualIID(iid, IID_IDirectorySchemaMgmt))
  125. {
  126. *ppv = (IDirectorySchemaMgmt FAR *) this;
  127. }
  128. else
  129. {
  130. *ppv = NULL;
  131. return E_NOINTERFACE;
  132. }
  133. AddRef();
  134. return NOERROR;
  135. }
  136. HRESULT
  137. CNDSLocality::AllocateLocalityObject(
  138. IADs *pADs,
  139. CNDSLocality ** ppLocality
  140. )
  141. {
  142. CNDSLocality FAR * pLocality = NULL;
  143. CDispatchMgr FAR * pDispMgr = NULL;
  144. HRESULT hr = S_OK;
  145. IADsContainer FAR * pADsContainer = NULL;
  146. IDirectoryObject * pDSObject = NULL;
  147. IDirectorySearch * pDSSearch = NULL;
  148. IDirectorySchemaMgmt * pDSAttrMgmt = NULL;
  149. IADsPropertyList * pADsPropList = NULL;
  150. pLocality = new CNDSLocality();
  151. if (pLocality == NULL) {
  152. hr = E_OUTOFMEMORY;
  153. }
  154. BAIL_ON_FAILURE(hr);
  155. pDispMgr = new CDispatchMgr;
  156. if (pDispMgr == NULL) {
  157. hr = E_OUTOFMEMORY;
  158. }
  159. BAIL_ON_FAILURE(hr);
  160. hr = LoadTypeInfoEntry(
  161. pDispMgr,
  162. LIBID_ADs,
  163. IID_IADsLocality,
  164. (IADsLocality *)pLocality,
  165. DISPID_REGULAR
  166. );
  167. BAIL_ON_FAILURE(hr);
  168. hr = LoadTypeInfoEntry(
  169. pDispMgr,
  170. LIBID_ADs,
  171. IID_IADsContainer,
  172. (IADsContainer *)pLocality,
  173. DISPID_NEWENUM
  174. );
  175. BAIL_ON_FAILURE(hr);
  176. hr = LoadTypeInfoEntry(
  177. pDispMgr,
  178. LIBID_ADs,
  179. IID_IADsPropertyList,
  180. (IADsPropertyList *)pADsPropList,
  181. DISPID_VALUE
  182. );
  183. BAIL_ON_FAILURE(hr);
  184. hr = pADs->QueryInterface(
  185. IID_IDirectoryObject,
  186. (void **)&pDSObject
  187. );
  188. BAIL_ON_FAILURE(hr);
  189. pLocality->_pDSObject = pDSObject;
  190. hr = pADs->QueryInterface(
  191. IID_IDirectorySearch,
  192. (void **)&pDSSearch
  193. );
  194. BAIL_ON_FAILURE(hr);
  195. pLocality->_pDSSearch = pDSSearch;
  196. hr = pADs->QueryInterface(
  197. IID_IDirectorySchemaMgmt,
  198. (void **)&pDSAttrMgmt
  199. );
  200. BAIL_ON_FAILURE(hr);
  201. pLocality->_pDSAttrMgmt = pDSAttrMgmt;
  202. hr = pADs->QueryInterface(
  203. IID_IADsPropertyList,
  204. (void **)&pADsPropList
  205. );
  206. BAIL_ON_FAILURE(hr);
  207. pLocality->_pADsPropList = pADsPropList;
  208. //
  209. // Store the pointer to the internal generic object
  210. // AND add ref this pointer
  211. //
  212. pLocality->_pADs = pADs;
  213. pADs->AddRef();
  214. //
  215. // Store a pointer to the Container interface
  216. //
  217. hr = pADs->QueryInterface(
  218. IID_IADsContainer,
  219. (void **)&pADsContainer
  220. );
  221. BAIL_ON_FAILURE(hr);
  222. pLocality->_pADsContainer = pADsContainer;
  223. pLocality->_pDispMgr = pDispMgr;
  224. *ppLocality = pLocality;
  225. RRETURN(hr);
  226. error:
  227. delete pDispMgr;
  228. delete pLocality;
  229. *ppLocality = NULL;
  230. RRETURN(hr);
  231. }
  232. STDMETHODIMP CNDSLocality::get_Description(THIS_ BSTR FAR* retval)
  233. {
  234. GET_PROPERTY_BSTR((IADsLocality *)this,Description);
  235. }
  236. STDMETHODIMP CNDSLocality::put_Description(THIS_ BSTR bstrDescription)
  237. {
  238. PUT_PROPERTY_BSTR((IADsLocality *)this,Description);
  239. }
  240. STDMETHODIMP CNDSLocality::get_LocalityName(THIS_ BSTR FAR* retval)
  241. {
  242. GET_PROPERTY_BSTR((IADsLocality *)this,LocalityName);
  243. }
  244. STDMETHODIMP CNDSLocality::put_LocalityName(THIS_ BSTR bstrLocalityName)
  245. {
  246. PUT_PROPERTY_BSTR((IADsLocality *)this,LocalityName);
  247. }
  248. STDMETHODIMP CNDSLocality::get_PostalAddress(THIS_ BSTR FAR* retval)
  249. {
  250. GET_PROPERTY_BSTR((IADsLocality *)this,PostalAddress);
  251. }
  252. STDMETHODIMP CNDSLocality::put_PostalAddress(THIS_ BSTR bstrPostalAddress)
  253. {
  254. PUT_PROPERTY_BSTR((IADsLocality *)this,PostalAddress);
  255. }
  256. STDMETHODIMP CNDSLocality::get_SeeAlso(THIS_ VARIANT FAR* retval)
  257. {
  258. GET_PROPERTY_VARIANT((IADsLocality *)this,SeeAlso);
  259. }
  260. STDMETHODIMP CNDSLocality::put_SeeAlso(THIS_ VARIANT vSeeAlso)
  261. {
  262. PUT_PROPERTY_VARIANT((IADsLocality *)this,SeeAlso);
  263. }
  264. /* IADsContainer methods */
  265. STDMETHODIMP
  266. CNDSLocality::get_Count(long FAR* retval)
  267. {
  268. HRESULT hr = E_NOTIMPL;
  269. if (_pADsContainer) {
  270. hr = _pADsContainer->get_Count(
  271. retval
  272. );
  273. }
  274. RRETURN(hr);
  275. }
  276. STDMETHODIMP
  277. CNDSLocality::get_Filter(THIS_ VARIANT FAR* pVar)
  278. {
  279. HRESULT hr = E_NOTIMPL;
  280. if (_pADsContainer) {
  281. hr = _pADsContainer->get_Filter(
  282. pVar
  283. );
  284. }
  285. RRETURN(hr);
  286. }
  287. STDMETHODIMP
  288. CNDSLocality::put_Filter(THIS_ VARIANT Var)
  289. {
  290. HRESULT hr = E_NOTIMPL;
  291. if (_pADsContainer) {
  292. hr = _pADsContainer->put_Filter(
  293. Var
  294. );
  295. }
  296. RRETURN(hr);
  297. }
  298. STDMETHODIMP
  299. CNDSLocality::put_Hints(THIS_ VARIANT Var)
  300. {
  301. HRESULT hr = E_NOTIMPL;
  302. if (_pADsContainer) {
  303. hr = _pADsContainer->put_Hints(
  304. Var
  305. );
  306. }
  307. RRETURN(hr);
  308. }
  309. STDMETHODIMP
  310. CNDSLocality::get_Hints(THIS_ VARIANT FAR* pVar)
  311. {
  312. HRESULT hr = E_NOTIMPL;
  313. if (_pADsContainer) {
  314. hr = _pADsContainer->get_Hints(
  315. pVar
  316. );
  317. }
  318. RRETURN(hr);
  319. }
  320. STDMETHODIMP
  321. CNDSLocality::GetObject(
  322. BSTR ClassName,
  323. BSTR RelativeName,
  324. IDispatch * FAR* ppObject
  325. )
  326. {
  327. HRESULT hr = E_NOTIMPL;
  328. if (_pADsContainer) {
  329. hr = _pADsContainer->GetObject(
  330. ClassName,
  331. RelativeName,
  332. ppObject
  333. );
  334. }
  335. RRETURN(hr);
  336. }
  337. STDMETHODIMP
  338. CNDSLocality::get__NewEnum(
  339. THIS_ IUnknown * FAR* retval
  340. )
  341. {
  342. HRESULT hr = E_NOTIMPL;
  343. if (_pADsContainer) {
  344. hr = _pADsContainer->get__NewEnum(
  345. retval
  346. );
  347. }
  348. RRETURN(hr);
  349. }
  350. STDMETHODIMP
  351. CNDSLocality::Create(
  352. THIS_ BSTR ClassName,
  353. BSTR RelativeName,
  354. IDispatch * FAR* ppObject
  355. )
  356. {
  357. HRESULT hr = E_NOTIMPL;
  358. if (_pADsContainer) {
  359. hr = _pADsContainer->Create(
  360. ClassName,
  361. RelativeName,
  362. ppObject
  363. );
  364. }
  365. RRETURN(hr);
  366. }
  367. STDMETHODIMP
  368. CNDSLocality::Delete(
  369. THIS_ BSTR bstrClassName,
  370. BSTR bstrRelativeName
  371. )
  372. {
  373. HRESULT hr = E_NOTIMPL;
  374. if (_pADsContainer) {
  375. hr = _pADsContainer->Delete(
  376. bstrClassName,
  377. bstrRelativeName
  378. );
  379. }
  380. RRETURN(hr);
  381. }
  382. STDMETHODIMP
  383. CNDSLocality::CopyHere(
  384. THIS_ BSTR SourceName,
  385. BSTR NewName,
  386. IDispatch * FAR* ppObject
  387. )
  388. {
  389. HRESULT hr = E_NOTIMPL;
  390. if (_pADsContainer) {
  391. hr = _pADsContainer->CopyHere(
  392. SourceName,
  393. NewName,
  394. ppObject
  395. );
  396. }
  397. RRETURN(hr);
  398. }
  399. STDMETHODIMP
  400. CNDSLocality::MoveHere(
  401. THIS_ BSTR SourceName,
  402. BSTR NewName,
  403. IDispatch * FAR* ppObject
  404. )
  405. {
  406. HRESULT hr = E_NOTIMPL;
  407. if (_pADsContainer) {
  408. hr = _pADsContainer->MoveHere(
  409. SourceName,
  410. NewName,
  411. ppObject
  412. );
  413. }
  414. RRETURN(hr);
  415. }