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.

533 lines
12 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. _pDSSchemaMgmt(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_EXP_IF_ERR(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 (_pDSSchemaMgmt) {
  76. _pDSSchemaMgmt->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_ISupportErrorInfo))
  109. {
  110. *ppv = (ISupportErrorInfo FAR *) this;
  111. }
  112. else if (IsEqualIID(iid, IID_IADsContainer) && _pADsContainer)
  113. {
  114. *ppv = (IADsContainer FAR *) this;
  115. }
  116. else if (IsEqualIID(iid, IID_IDirectoryObject))
  117. {
  118. *ppv = (IDirectoryObject FAR *) this;
  119. }
  120. else if (IsEqualIID(iid, IID_IDirectorySearch))
  121. {
  122. *ppv = (IDirectorySearch FAR *) this;
  123. }
  124. else if (IsEqualIID(iid, IID_IADsPropertyList) && _pADsPropList)
  125. {
  126. *ppv = (IADsPropertyList FAR *) this;
  127. }
  128. else if (IsEqualIID(iid, IID_IDirectorySchemaMgmt))
  129. {
  130. *ppv = (IDirectorySchemaMgmt FAR *) this;
  131. }
  132. else
  133. {
  134. *ppv = NULL;
  135. return E_NOINTERFACE;
  136. }
  137. AddRef();
  138. return NOERROR;
  139. }
  140. HRESULT
  141. CNDSLocality::AllocateLocalityObject(
  142. IADs *pADs,
  143. CNDSLocality ** ppLocality
  144. )
  145. {
  146. CNDSLocality FAR * pLocality = NULL;
  147. CDispatchMgr FAR * pDispMgr = NULL;
  148. HRESULT hr = S_OK;
  149. IADsContainer FAR * pADsContainer = NULL;
  150. IDirectoryObject * pDSObject = NULL;
  151. IDirectorySearch * pDSSearch = NULL;
  152. IDirectorySchemaMgmt * pDSSchemaMgmt = NULL;
  153. IADsPropertyList * pADsPropList = NULL;
  154. pLocality = new CNDSLocality();
  155. if (pLocality == NULL) {
  156. hr = E_OUTOFMEMORY;
  157. }
  158. BAIL_ON_FAILURE(hr);
  159. pDispMgr = new CDispatchMgr;
  160. if (pDispMgr == NULL) {
  161. hr = E_OUTOFMEMORY;
  162. }
  163. BAIL_ON_FAILURE(hr);
  164. hr = LoadTypeInfoEntry(
  165. pDispMgr,
  166. LIBID_ADs,
  167. IID_IADsLocality,
  168. (IADsLocality *)pLocality,
  169. DISPID_REGULAR
  170. );
  171. BAIL_ON_FAILURE(hr);
  172. hr = LoadTypeInfoEntry(
  173. pDispMgr,
  174. LIBID_ADs,
  175. IID_IADsContainer,
  176. (IADsContainer *)pLocality,
  177. DISPID_NEWENUM
  178. );
  179. BAIL_ON_FAILURE(hr);
  180. hr = LoadTypeInfoEntry(
  181. pDispMgr,
  182. LIBID_ADs,
  183. IID_IADsPropertyList,
  184. (IADsPropertyList *)pADsPropList,
  185. DISPID_VALUE
  186. );
  187. BAIL_ON_FAILURE(hr);
  188. hr = pADs->QueryInterface(
  189. IID_IDirectoryObject,
  190. (void **)&pDSObject
  191. );
  192. BAIL_ON_FAILURE(hr);
  193. pLocality->_pDSObject = pDSObject;
  194. hr = pADs->QueryInterface(
  195. IID_IDirectorySearch,
  196. (void **)&pDSSearch
  197. );
  198. BAIL_ON_FAILURE(hr);
  199. pLocality->_pDSSearch = pDSSearch;
  200. hr = pADs->QueryInterface(
  201. IID_IDirectorySchemaMgmt,
  202. (void **)&pDSSchemaMgmt
  203. );
  204. BAIL_ON_FAILURE(hr);
  205. pLocality->_pDSSchemaMgmt = pDSSchemaMgmt;
  206. hr = pADs->QueryInterface(
  207. IID_IADsPropertyList,
  208. (void **)&pADsPropList
  209. );
  210. BAIL_ON_FAILURE(hr);
  211. pLocality->_pADsPropList = pADsPropList;
  212. //
  213. // Store the pointer to the internal generic object
  214. // AND add ref this pointer
  215. //
  216. pLocality->_pADs = pADs;
  217. pADs->AddRef();
  218. //
  219. // Store a pointer to the Container interface
  220. //
  221. hr = pADs->QueryInterface(
  222. IID_IADsContainer,
  223. (void **)&pADsContainer
  224. );
  225. BAIL_ON_FAILURE(hr);
  226. pLocality->_pADsContainer = pADsContainer;
  227. pLocality->_pDispMgr = pDispMgr;
  228. *ppLocality = pLocality;
  229. RRETURN(hr);
  230. error:
  231. delete pDispMgr;
  232. delete pLocality;
  233. *ppLocality = NULL;
  234. RRETURN(hr);
  235. }
  236. /* ISupportErrorInfo method */
  237. STDMETHODIMP
  238. CNDSLocality::InterfaceSupportsErrorInfo(
  239. THIS_ REFIID riid
  240. )
  241. {
  242. if (IsEqualIID(riid, IID_IADs) ||
  243. #if 0
  244. IsEqualIID(riid, IID_IDirectoryObject) ||
  245. IsEqualIID(riid, IID_IDirectorySearch) ||
  246. IsequalIID(riid, IID_IdirecotryAttrMgmt) ||
  247. #endif
  248. IsEqualIID(riid, IID_IADsPropertyList) ||
  249. IsEqualIID(riid, IID_IADsContainer) ||
  250. IsEqualIID(riid, IID_IADsLocality)) {
  251. RRETURN(S_OK);
  252. } else {
  253. RRETURN(S_FALSE);
  254. }
  255. }
  256. STDMETHODIMP CNDSLocality::get_Description(THIS_ BSTR FAR* retval)
  257. {
  258. GET_PROPERTY_BSTR((IADsLocality *)this,Description);
  259. }
  260. STDMETHODIMP CNDSLocality::put_Description(THIS_ BSTR bstrDescription)
  261. {
  262. PUT_PROPERTY_BSTR((IADsLocality *)this,Description);
  263. }
  264. STDMETHODIMP CNDSLocality::get_LocalityName(THIS_ BSTR FAR* retval)
  265. {
  266. GET_PROPERTY_BSTR((IADsLocality *)this,LocalityName);
  267. }
  268. STDMETHODIMP CNDSLocality::put_LocalityName(THIS_ BSTR bstrLocalityName)
  269. {
  270. PUT_PROPERTY_BSTR((IADsLocality *)this,LocalityName);
  271. }
  272. STDMETHODIMP CNDSLocality::get_PostalAddress(THIS_ BSTR FAR* retval)
  273. {
  274. GET_PROPERTY_BSTR((IADsLocality *)this,PostalAddress);
  275. }
  276. STDMETHODIMP CNDSLocality::put_PostalAddress(THIS_ BSTR bstrPostalAddress)
  277. {
  278. PUT_PROPERTY_BSTR((IADsLocality *)this,PostalAddress);
  279. }
  280. STDMETHODIMP CNDSLocality::get_SeeAlso(THIS_ VARIANT FAR* retval)
  281. {
  282. GET_PROPERTY_VARIANT((IADsLocality *)this,SeeAlso);
  283. }
  284. STDMETHODIMP CNDSLocality::put_SeeAlso(THIS_ VARIANT vSeeAlso)
  285. {
  286. PUT_PROPERTY_VARIANT((IADsLocality *)this,SeeAlso);
  287. }
  288. /* IADsContainer methods */
  289. STDMETHODIMP
  290. CNDSLocality::get_Count(long FAR* retval)
  291. {
  292. HRESULT hr = E_NOTIMPL;
  293. if (_pADsContainer) {
  294. hr = _pADsContainer->get_Count(
  295. retval
  296. );
  297. }
  298. RRETURN_EXP_IF_ERR(hr);
  299. }
  300. STDMETHODIMP
  301. CNDSLocality::get_Filter(THIS_ VARIANT FAR* pVar)
  302. {
  303. HRESULT hr = E_NOTIMPL;
  304. if (_pADsContainer) {
  305. hr = _pADsContainer->get_Filter(
  306. pVar
  307. );
  308. }
  309. RRETURN_EXP_IF_ERR(hr);
  310. }
  311. STDMETHODIMP
  312. CNDSLocality::put_Filter(THIS_ VARIANT Var)
  313. {
  314. HRESULT hr = E_NOTIMPL;
  315. if (_pADsContainer) {
  316. hr = _pADsContainer->put_Filter(
  317. Var
  318. );
  319. }
  320. RRETURN_EXP_IF_ERR(hr);
  321. }
  322. STDMETHODIMP
  323. CNDSLocality::put_Hints(THIS_ VARIANT Var)
  324. {
  325. HRESULT hr = E_NOTIMPL;
  326. if (_pADsContainer) {
  327. hr = _pADsContainer->put_Hints(
  328. Var
  329. );
  330. }
  331. RRETURN_EXP_IF_ERR(hr);
  332. }
  333. STDMETHODIMP
  334. CNDSLocality::get_Hints(THIS_ VARIANT FAR* pVar)
  335. {
  336. HRESULT hr = E_NOTIMPL;
  337. if (_pADsContainer) {
  338. hr = _pADsContainer->get_Hints(
  339. pVar
  340. );
  341. }
  342. RRETURN_EXP_IF_ERR(hr);
  343. }
  344. STDMETHODIMP
  345. CNDSLocality::GetObject(
  346. BSTR ClassName,
  347. BSTR RelativeName,
  348. IDispatch * FAR* ppObject
  349. )
  350. {
  351. HRESULT hr = E_NOTIMPL;
  352. if (_pADsContainer) {
  353. hr = _pADsContainer->GetObject(
  354. ClassName,
  355. RelativeName,
  356. ppObject
  357. );
  358. }
  359. RRETURN_EXP_IF_ERR(hr);
  360. }
  361. STDMETHODIMP
  362. CNDSLocality::get__NewEnum(
  363. THIS_ IUnknown * FAR* retval
  364. )
  365. {
  366. HRESULT hr = E_NOTIMPL;
  367. if (_pADsContainer) {
  368. hr = _pADsContainer->get__NewEnum(
  369. retval
  370. );
  371. }
  372. RRETURN_EXP_IF_ERR(hr);
  373. }
  374. STDMETHODIMP
  375. CNDSLocality::Create(
  376. THIS_ BSTR ClassName,
  377. BSTR RelativeName,
  378. IDispatch * FAR* ppObject
  379. )
  380. {
  381. HRESULT hr = E_NOTIMPL;
  382. if (_pADsContainer) {
  383. hr = _pADsContainer->Create(
  384. ClassName,
  385. RelativeName,
  386. ppObject
  387. );
  388. }
  389. RRETURN_EXP_IF_ERR(hr);
  390. }
  391. STDMETHODIMP
  392. CNDSLocality::Delete(
  393. THIS_ BSTR bstrClassName,
  394. BSTR bstrRelativeName
  395. )
  396. {
  397. HRESULT hr = E_NOTIMPL;
  398. if (_pADsContainer) {
  399. hr = _pADsContainer->Delete(
  400. bstrClassName,
  401. bstrRelativeName
  402. );
  403. }
  404. RRETURN_EXP_IF_ERR(hr);
  405. }
  406. STDMETHODIMP
  407. CNDSLocality::CopyHere(
  408. THIS_ BSTR SourceName,
  409. BSTR NewName,
  410. IDispatch * FAR* ppObject
  411. )
  412. {
  413. HRESULT hr = E_NOTIMPL;
  414. if (_pADsContainer) {
  415. hr = _pADsContainer->CopyHere(
  416. SourceName,
  417. NewName,
  418. ppObject
  419. );
  420. }
  421. RRETURN_EXP_IF_ERR(hr);
  422. }
  423. STDMETHODIMP
  424. CNDSLocality::MoveHere(
  425. THIS_ BSTR SourceName,
  426. BSTR NewName,
  427. IDispatch * FAR* ppObject
  428. )
  429. {
  430. HRESULT hr = E_NOTIMPL;
  431. if (_pADsContainer) {
  432. hr = _pADsContainer->MoveHere(
  433. SourceName,
  434. NewName,
  435. ppObject
  436. );
  437. }
  438. RRETURN_EXP_IF_ERR(hr);
  439. }
  440.