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.

2746 lines
60 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: culs.cpp
  5. // Content: This file contains the ULS object.
  6. // History:
  7. // Wed 17-Apr-1996 11:13:54 -by- Viroon Touranachun [viroont]
  8. //
  9. // Copyright (c) Microsoft Corporation 1996-1997
  10. //
  11. //****************************************************************************
  12. #include "ulsp.h"
  13. #include "culs.h"
  14. #include "localusr.h"
  15. #include "attribs.h"
  16. #include "localprt.h"
  17. #include "callback.h"
  18. #include "filter.h"
  19. #include "sputils.h"
  20. #include "ulsmeet.h"
  21. //****************************************************************************
  22. // Constant and static text definition
  23. //****************************************************************************
  24. //
  25. #define ILS_WND_CLASS TEXT("UserLocationServicesClass")
  26. #define ILS_WND_NAME TEXT("ULSWnd")
  27. #define ILS_DATABASE_MUTEX TEXT("User Location Service Database")
  28. //****************************************************************************
  29. // Global Parameters
  30. //****************************************************************************
  31. //
  32. CIlsMain *g_pCIls = NULL;
  33. CReqMgr *g_pReqMgr = NULL;
  34. HWND g_hwndCulsWindow = NULL;
  35. //****************************************************************************
  36. // Event Notifiers
  37. //****************************************************************************
  38. //
  39. //****************************************************************************
  40. // HRESULT
  41. // OnNotifyEnumUserNamesResult (IUnknown *pUnk, void *pv)
  42. //
  43. // History:
  44. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  45. // Created.
  46. //****************************************************************************
  47. HRESULT
  48. OnNotifyEnumUserNamesResult (IUnknown *pUnk, void *pv)
  49. {
  50. CEnumNames *penum = NULL;
  51. PENUMRINFO peri = (PENUMRINFO)pv;
  52. HRESULT hr = peri->hResult;
  53. // Create the enumerator only when there is anything to be enumerated
  54. //
  55. if (hr == NOERROR)
  56. {
  57. ASSERT (peri->pv != NULL);
  58. // Create a UserName enumerator
  59. //
  60. penum = new CEnumNames;
  61. if (penum != NULL)
  62. {
  63. hr = penum->Init((LPTSTR)peri->pv, peri->cItems);
  64. if (SUCCEEDED(hr))
  65. {
  66. penum->AddRef();
  67. }
  68. else
  69. {
  70. delete penum;
  71. penum = NULL;
  72. };
  73. }
  74. else
  75. {
  76. hr = ILS_E_MEMORY;
  77. };
  78. };
  79. // Notify the sink object
  80. //
  81. ((IIlsNotify*)pUnk)->EnumUserNamesResult(peri->uReqID,
  82. penum != NULL ?
  83. (IEnumIlsNames *)penum :
  84. NULL,
  85. hr);
  86. if (penum != NULL)
  87. {
  88. penum->Release();
  89. };
  90. return hr;
  91. }
  92. //****************************************************************************
  93. // HRESULT
  94. // OnNotifyGetUserResult (IUnknown *pUnk, void *pv)
  95. //
  96. // History:
  97. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  98. // Created.
  99. //****************************************************************************
  100. HRESULT
  101. OnNotifyGetUserResult (IUnknown *pUnk, void *pv)
  102. {
  103. POBJRINFO pobjri = (POBJRINFO)pv;
  104. ((IIlsNotify*)pUnk)->GetUserResult(pobjri->uReqID,
  105. (IIlsUser *)pobjri->pv,
  106. pobjri->hResult);
  107. return S_OK;
  108. }
  109. //****************************************************************************
  110. // HRESULT
  111. // OnNotifyGetUserResult (IUnknown *pUnk, void *pv)
  112. //
  113. // History:
  114. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  115. // Created.
  116. //****************************************************************************
  117. #ifdef ENABLE_MEETING_PLACE
  118. HRESULT
  119. OnNotifyGetMeetingPlaceResult (IUnknown *pUnk, void *pv)
  120. {
  121. POBJRINFO pobjri = (POBJRINFO)pv;
  122. ((IIlsNotify*)pUnk)->GetMeetingPlaceResult(pobjri->uReqID,
  123. (IIlsMeetingPlace *)pobjri->pv,
  124. pobjri->hResult);
  125. return S_OK;
  126. }
  127. #endif // ENABLE_MEETING_PLACE
  128. //****************************************************************************
  129. // HRESULT
  130. // OnNotifyEnumUsersResult (IUnknown *pUnk, void *pv)
  131. //
  132. // History:
  133. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  134. // Created.
  135. //****************************************************************************
  136. HRESULT
  137. OnNotifyEnumUsersResult (IUnknown *pUnk, void *pv)
  138. {
  139. CEnumUsers *penum = NULL;
  140. PENUMRINFO peri = (PENUMRINFO)pv;
  141. HRESULT hr = peri->hResult;
  142. if (hr == NOERROR)
  143. {
  144. ASSERT (peri->pv != NULL);
  145. // Create a UserName enumerator
  146. //
  147. penum = new CEnumUsers;
  148. if (penum != NULL)
  149. {
  150. hr = penum->Init((CIlsUser **)peri->pv, peri->cItems);
  151. if (SUCCEEDED(hr))
  152. {
  153. penum->AddRef();
  154. }
  155. else
  156. {
  157. delete penum;
  158. penum = NULL;
  159. };
  160. }
  161. else
  162. {
  163. hr = ILS_E_MEMORY;
  164. };
  165. };
  166. // Notify the sink object
  167. //
  168. ((IIlsNotify*)pUnk)->EnumUsersResult(peri->uReqID,
  169. penum != NULL ?
  170. (IEnumIlsUsers *)penum :
  171. NULL,
  172. hr);
  173. if (penum != NULL)
  174. {
  175. penum->Release();
  176. };
  177. return hr;
  178. }
  179. //****************************************************************************
  180. // HRESULT
  181. // OnNotifyEnumMeetingPlacesResult (IUnknown *pUnk, void *pv)
  182. //
  183. // History:
  184. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  185. // Created.
  186. //****************************************************************************
  187. #ifdef ENABLE_MEETING_PLACE
  188. HRESULT
  189. OnNotifyEnumMeetingPlacesResult (IUnknown *pUnk, void *pv)
  190. {
  191. CEnumMeetingPlaces *penum = NULL;
  192. PENUMRINFO peri = (PENUMRINFO)pv;
  193. HRESULT hr = peri->hResult;
  194. if (hr == NOERROR)
  195. {
  196. ASSERT (peri->pv != NULL);
  197. // Create a MeetingPlace enumerator
  198. //
  199. penum = new CEnumMeetingPlaces;
  200. if (penum != NULL)
  201. {
  202. // jam it with the data that we got
  203. hr = penum->Init((CIlsMeetingPlace **)peri->pv, peri->cItems);
  204. if (SUCCEEDED(hr))
  205. {
  206. penum->AddRef();
  207. }
  208. else
  209. {
  210. delete penum;
  211. penum = NULL;
  212. };
  213. }
  214. else
  215. {
  216. hr = ILS_E_MEMORY;
  217. };
  218. };
  219. // Notify the sink object
  220. //
  221. ((IIlsNotify*)pUnk)->EnumMeetingPlacesResult(peri->uReqID,
  222. penum != NULL ?
  223. (IEnumIlsMeetingPlaces *)penum :
  224. NULL,
  225. hr);
  226. if (penum != NULL)
  227. {
  228. penum->Release();
  229. };
  230. return hr;
  231. }
  232. #endif // ENABLE_MEETING_PLACE
  233. //****************************************************************************
  234. // HRESULT
  235. // OnNotifyEnumMeetingPlaceNamesResult (IUnknown *pUnk, void *pv)
  236. //
  237. // History:
  238. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  239. // Created.
  240. //****************************************************************************
  241. #ifdef ENABLE_MEETING_PLACE
  242. HRESULT
  243. OnNotifyEnumMeetingPlaceNamesResult (IUnknown *pUnk, void *pv)
  244. {
  245. CEnumNames *penum = NULL;
  246. PENUMRINFO peri = (PENUMRINFO)pv;
  247. HRESULT hr = peri->hResult;
  248. // Create the enumerator only when there is anything to be enumerated
  249. //
  250. if (hr == NOERROR)
  251. {
  252. ASSERT (peri->pv != NULL);
  253. // Create a MeetingPlaceName enumerator
  254. //
  255. penum = new CEnumNames;
  256. if (penum != NULL)
  257. {
  258. hr = penum->Init((LPTSTR)peri->pv, peri->cItems);
  259. if (SUCCEEDED(hr))
  260. {
  261. penum->AddRef();
  262. }
  263. else
  264. {
  265. delete penum;
  266. penum = NULL;
  267. };
  268. }
  269. else
  270. {
  271. hr = ILS_E_MEMORY;
  272. };
  273. };
  274. // Notify the sink object
  275. //
  276. ((IIlsNotify*)pUnk)->EnumMeetingPlaceNamesResult(peri->uReqID,
  277. penum != NULL ?
  278. (IEnumIlsNames *)penum :
  279. NULL,
  280. hr);
  281. if (penum != NULL)
  282. {
  283. penum->Release();
  284. };
  285. return hr;
  286. }
  287. #endif // ENABLE_MEETING_PLACE
  288. //****************************************************************************
  289. // Class Implementation
  290. //****************************************************************************
  291. //
  292. //****************************************************************************
  293. // CIlsMain::CIls (void)
  294. //
  295. // History:
  296. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  297. // Created.
  298. //****************************************************************************
  299. CIlsMain::
  300. CIlsMain ( VOID )
  301. :m_cRef (0),
  302. fInit (FALSE),
  303. hwndCallback (NULL),
  304. pConnPt (NULL)
  305. {
  306. ::EnterCriticalSection (&g_ULSSem);
  307. g_pCIls = this;
  308. ::LeaveCriticalSection (&g_ULSSem);
  309. }
  310. //****************************************************************************
  311. // CIlsMain::~CIls (void)
  312. //
  313. // History:
  314. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  315. // Created.
  316. //****************************************************************************
  317. CIlsMain::
  318. ~CIlsMain ( VOID )
  319. {
  320. ASSERT (m_cRef == 0);
  321. // Free up resources
  322. //
  323. Uninitialize();
  324. // Release the connection point
  325. //
  326. if (pConnPt != NULL)
  327. {
  328. pConnPt->ContainerReleased();
  329. ((IConnectionPoint*)pConnPt)->Release();
  330. };
  331. // We are gone now
  332. //
  333. ::EnterCriticalSection (&g_ULSSem);
  334. g_pCIls = NULL;
  335. ::LeaveCriticalSection (&g_ULSSem);
  336. return;
  337. }
  338. //****************************************************************************
  339. // STDMETHODIMP
  340. // CIlsMain::Init (void)
  341. //
  342. // History:
  343. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  344. // Created.
  345. //****************************************************************************
  346. STDMETHODIMP
  347. CIlsMain::Init (void)
  348. {
  349. HRESULT hr;
  350. // Make the connection point
  351. //
  352. pConnPt = new CConnectionPoint (&IID_IIlsNotify,
  353. (IConnectionPointContainer *)this);
  354. if (pConnPt != NULL)
  355. {
  356. ((IConnectionPoint*)pConnPt)->AddRef();
  357. hr = S_OK;
  358. }
  359. else
  360. {
  361. hr = ILS_E_MEMORY;
  362. };
  363. return hr;
  364. }
  365. //****************************************************************************
  366. // STDMETHODIMP
  367. // CIlsMain::QueryInterface (REFIID riid, void **ppv)
  368. //
  369. // History:
  370. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  371. // Created.
  372. //****************************************************************************
  373. STDMETHODIMP
  374. CIlsMain::QueryInterface (REFIID riid, void **ppv)
  375. {
  376. *ppv = NULL;
  377. if (riid == IID_IIlsMain || riid == IID_IUnknown)
  378. {
  379. *ppv = (IIlsMain *) this;
  380. }
  381. else
  382. {
  383. if (riid == IID_IConnectionPointContainer)
  384. {
  385. *ppv = (IConnectionPointContainer *) this;
  386. };
  387. };
  388. if (*ppv != NULL)
  389. {
  390. ((LPUNKNOWN)*ppv)->AddRef();
  391. return S_OK;
  392. }
  393. else
  394. {
  395. return ILS_E_NO_INTERFACE;
  396. };
  397. }
  398. //****************************************************************************
  399. // STDMETHODIMP_(ULONG)
  400. // CIlsMain::AddRef (void)
  401. //
  402. // History:
  403. // Wed 17-Apr-1996 11:14:17 -by- Viroon Touranachun [viroont]
  404. // Created.
  405. //****************************************************************************
  406. STDMETHODIMP_(ULONG)
  407. CIlsMain::AddRef (void)
  408. {
  409. DllLock();
  410. MyDebugMsg ((DM_REFCOUNT, "CIlsMain::AddRef: ref=%ld\r\n", m_cRef));
  411. ::InterlockedIncrement (&m_cRef);
  412. return (ULONG) m_cRef;
  413. }
  414. //****************************************************************************
  415. // STDMETHODIMP_(ULONG)
  416. // CIlsMain::Release (void)
  417. //
  418. // History:
  419. // Wed 17-Apr-1996 11:14:26 -by- Viroon Touranachun [viroont]
  420. // Created.
  421. //****************************************************************************
  422. STDMETHODIMP_(ULONG)
  423. CIlsMain::Release (void)
  424. {
  425. DllRelease();
  426. ASSERT (m_cRef > 0);
  427. MyDebugMsg ((DM_REFCOUNT, "CIlsMain::Release: ref=%ld\r\n", m_cRef));
  428. if (::InterlockedDecrement (&m_cRef) == 0)
  429. {
  430. delete this;
  431. return 0;
  432. }
  433. return (ULONG) m_cRef;
  434. }
  435. //****************************************************************************
  436. // STDMETHODIMP
  437. // CIlsMain::Initialize (BSTR bstrAppName, REFGUID rguid, BSTR bstrMimeType)
  438. //
  439. // History:
  440. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  441. // Created.
  442. //****************************************************************************
  443. STDMETHODIMP
  444. CIlsMain::Initialize ()
  445. {
  446. WNDCLASS wc;
  447. HRESULT hr;
  448. if (IsInitialized())
  449. {
  450. return ILS_E_FAIL;
  451. };
  452. // Activate the services
  453. //
  454. hr = ILS_E_FAIL;
  455. fInit = TRUE;
  456. // Fill in window class structure with parameters that describe the
  457. // working window.
  458. //
  459. wc.style = CS_NOCLOSE;
  460. wc.lpfnWndProc = ULSNotifyProc;
  461. wc.cbClsExtra = 0;
  462. wc.cbWndExtra = 0;
  463. wc.hInstance = g_hInstance;
  464. wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
  465. wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
  466. wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
  467. wc.lpszMenuName = NULL;
  468. wc.lpszClassName = ILS_WND_CLASS;
  469. if (::RegisterClass(&wc) != 0)
  470. {
  471. hwndCallback = ::CreateWindowEx(0L, ILS_WND_CLASS,
  472. ILS_WND_NAME,
  473. WS_OVERLAPPED,
  474. 0, 0, 100, 50,
  475. NULL, NULL, g_hInstance, NULL);
  476. if (hwndCallback != NULL)
  477. {
  478. // Initialize the request manager
  479. //
  480. g_pReqMgr = new CReqMgr;
  481. if (g_pReqMgr != NULL)
  482. {
  483. // Initialize the LDAP layer
  484. //
  485. hr = ::UlsLdap_Initialize(hwndCallback);
  486. }
  487. else
  488. {
  489. hr = ILS_E_MEMORY;
  490. };
  491. };
  492. };
  493. if (FAILED(hr))
  494. {
  495. Uninitialize();
  496. }
  497. else {
  498. g_hwndCulsWindow = hwndCallback;
  499. }
  500. return hr;
  501. }
  502. //****************************************************************************
  503. // STDMETHODIMP
  504. // CIlsMain::CreateUser
  505. //
  506. // History:
  507. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  508. // Created.
  509. //****************************************************************************
  510. STDMETHODIMP CIlsMain::
  511. CreateUser (
  512. BSTR bstrUserID,
  513. BSTR bstrAppName,
  514. IIlsUser **ppUser)
  515. {
  516. CIlsUser *plu;
  517. HRESULT hr;
  518. // Make sure ils main is initialized
  519. //
  520. if (! IsInitialized ())
  521. {
  522. return ILS_E_NOT_INITIALIZED;
  523. }
  524. // Validate parameter
  525. //
  526. if (ppUser == NULL)
  527. {
  528. return ILS_E_POINTER;
  529. };
  530. // Assume failure
  531. //
  532. *ppUser = NULL;
  533. //
  534. // Allocate a new user object
  535. //
  536. plu = new CIlsUser;
  537. if (plu != NULL)
  538. {
  539. // Initialize the object
  540. //
  541. hr = plu->Init(bstrUserID, bstrAppName);
  542. if (SUCCEEDED(hr))
  543. {
  544. *ppUser = (IIlsUser *)plu;
  545. (*ppUser)->AddRef();
  546. }
  547. else
  548. {
  549. delete plu;
  550. };
  551. }
  552. else
  553. {
  554. hr = ILS_E_MEMORY;
  555. };
  556. return hr;
  557. }
  558. //****************************************************************************
  559. // STDMETHODIMP
  560. // CIlsMain::Uninitialize (void)
  561. //
  562. // History:
  563. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  564. // Created.
  565. //****************************************************************************
  566. STDMETHODIMP
  567. CIlsMain::Uninitialize (void)
  568. {
  569. // Make sure ils main is initialized
  570. //
  571. if (! IsInitialized ())
  572. {
  573. return ILS_E_NOT_INITIALIZED;
  574. }
  575. // Uninitialize the LDAP layer
  576. //
  577. ::UlsLdap_Deinitialize();
  578. // Remove the request manager
  579. //
  580. if (g_pReqMgr != NULL)
  581. {
  582. delete g_pReqMgr;
  583. g_pReqMgr = NULL;
  584. };
  585. // Clear the callback window
  586. //
  587. if (hwndCallback != NULL)
  588. {
  589. ::DestroyWindow(hwndCallback);
  590. hwndCallback = NULL;
  591. };
  592. ::UnregisterClass(ILS_WND_CLASS, g_hInstance);
  593. // Flag that is is uninitialized
  594. //
  595. fInit = FALSE;
  596. return S_OK;
  597. };
  598. //****************************************************************************
  599. // STDMETHODIMP
  600. // CIlsMain::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  601. //
  602. // History:
  603. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  604. // Created.
  605. //****************************************************************************
  606. STDMETHODIMP
  607. CIlsMain::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  608. {
  609. HRESULT hr = S_OK;
  610. if (pConnPt != NULL)
  611. {
  612. hr = pConnPt->Notify(pv, pfn);
  613. };
  614. return hr;
  615. }
  616. //****************************************************************************
  617. // STDMETHODIMP
  618. // CIlsMain::CreateAttributes (ILS_ACCESS_CONTROL AccessControl, IIlsAttributes **ppAttributes)
  619. //
  620. // History:
  621. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  622. // Created.
  623. // 12/05/96 -by- Chu, Lon-Chan [lonchanc]
  624. // Added access control.
  625. //****************************************************************************
  626. STDMETHODIMP CIlsMain::
  627. CreateAttributes ( ILS_ATTR_TYPE AttrType, IIlsAttributes **ppAttributes )
  628. {
  629. // Make sure ils main is initialized
  630. //
  631. if (! IsInitialized ())
  632. {
  633. return ILS_E_NOT_INITIALIZED;
  634. }
  635. CAttributes *pa;
  636. HRESULT hr;
  637. // Validate parameter
  638. //
  639. if (ppAttributes == NULL)
  640. {
  641. return ILS_E_POINTER;
  642. };
  643. // Validate access control
  644. //
  645. if (AttrType != ILS_ATTRTYPE_NAME_ONLY &&
  646. AttrType != ILS_ATTRTYPE_NAME_VALUE)
  647. return ILS_E_PARAMETER;
  648. // Assume failure
  649. //
  650. *ppAttributes = NULL;
  651. // Allocate an attributes object
  652. //
  653. pa = new CAttributes;
  654. if (pa != NULL)
  655. {
  656. pa->SetAccessType (AttrType);
  657. pa->AddRef();
  658. *ppAttributes = pa;
  659. hr = NOERROR;
  660. }
  661. else
  662. {
  663. hr = ILS_E_MEMORY;
  664. };
  665. return hr;
  666. }
  667. //****************************************************************************
  668. // STDMETHODIMP
  669. // CIlsMain::GetUser (BSTR bstrServerName, BSTR bstrUserID,
  670. // ULONG *puReqID)
  671. //
  672. // History:
  673. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  674. // Created.
  675. //****************************************************************************
  676. STDMETHODIMP CIlsMain::
  677. GetUser (
  678. IIlsServer *pIlsServer,
  679. BSTR bstrUserID,
  680. BSTR bstrAppID,
  681. BSTR bstrProtID,
  682. IIlsAttributes *pAttrib,
  683. IIlsUser **ppUser,
  684. ULONG *puReqID )
  685. {
  686. // Make sure ils main is initialized
  687. //
  688. if (! IsInitialized ())
  689. {
  690. return ILS_E_NOT_INITIALIZED;
  691. }
  692. LDAP_ASYNCINFO ldai;
  693. HRESULT hr;
  694. // We do not implement synchronous operation
  695. //
  696. if (ppUser != NULL)
  697. return ILS_E_NOT_IMPL;
  698. // Validate parameters
  699. //
  700. if (::MyIsBadServer (pIlsServer) || bstrUserID == NULL || puReqID == NULL)
  701. return ILS_E_POINTER;
  702. // Clone the server object
  703. //
  704. pIlsServer = ((CIlsServer *) pIlsServer)->Clone ();
  705. if (pIlsServer == NULL)
  706. return ILS_E_MEMORY;
  707. // Get a list of extended attribute names
  708. //
  709. TCHAR *pszList = NULL;
  710. ULONG cList =0, cbList = 0;
  711. if (pAttrib != NULL)
  712. {
  713. hr = ((CAttributes *) pAttrib)->GetAttributeList (&pszList, &cList, &cbList);
  714. if (FAILED (hr))
  715. {
  716. pIlsServer->Release ();
  717. return hr;
  718. }
  719. }
  720. // Initialize locals
  721. //
  722. TCHAR *pszUserID = NULL, *pszAppID = NULL, *pszProtID = NULL;
  723. // Get from the specified server
  724. //
  725. hr = BSTR_to_LPTSTR(&pszUserID, bstrUserID);
  726. if (FAILED (hr))
  727. goto MyExit;
  728. // Get the app id if given
  729. //
  730. if (bstrAppID != NULL)
  731. {
  732. hr = BSTR_to_LPTSTR (&pszAppID, bstrAppID);
  733. if (FAILED (hr))
  734. goto MyExit;
  735. }
  736. // Get the protocol id if given
  737. //
  738. if (bstrProtID != NULL)
  739. {
  740. hr = BSTR_to_LPTSTR (&pszProtID, bstrProtID);
  741. if (FAILED (hr))
  742. goto MyExit;
  743. }
  744. hr = ::UlsLdap_ResolveClient (((CIlsServer *) pIlsServer)->GetServerInfo (),
  745. pszUserID,
  746. pszAppID,
  747. pszProtID,
  748. pszList,
  749. cList,
  750. &ldai);
  751. if (SUCCEEDED(hr))
  752. {
  753. COM_REQ_INFO ri;
  754. ReqInfo_Init (&ri);
  755. // If updating server was successfully requested, wait for the response
  756. //
  757. ri.uReqType = WM_ILS_RESOLVE_CLIENT;
  758. ri.uMsgID = ldai.uMsgID;
  759. ReqInfo_SetMain (&ri, this);
  760. ReqInfo_SetServer (&ri, pIlsServer);
  761. pIlsServer->AddRef ();
  762. hr = g_pReqMgr->NewRequest(&ri);
  763. if (SUCCEEDED(hr))
  764. {
  765. // Make sure the objects do not disappear before we get the response
  766. //
  767. this->AddRef();
  768. // Return the request ID
  769. //
  770. *puReqID = ri.uReqID;
  771. }
  772. };
  773. MyExit:
  774. // Release the server object
  775. //
  776. pIlsServer->Release ();
  777. // Free the list of extended attribute names
  778. //
  779. ::MemFree (pszList);
  780. // Free the names
  781. ::MemFree (pszUserID);
  782. ::MemFree (pszAppID);
  783. ::MemFree (pszProtID);
  784. return hr;
  785. }
  786. //****************************************************************************
  787. // STDMETHODIMP
  788. // CIlsMain::GetUserResult (ULONG uReqID, PLDAP_CLIENTINFO_RES puir,
  789. // LPTSTR szServer)
  790. //
  791. // History:
  792. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  793. // Created.
  794. //****************************************************************************
  795. STDMETHODIMP
  796. CIlsMain::GetUserResult (ULONG uReqID, PLDAP_CLIENTINFO_RES puir,
  797. CIlsServer *pIlsServer)
  798. {
  799. CIlsUser *pu;
  800. OBJRINFO objri;
  801. // Default to the server's result
  802. //
  803. objri.hResult = (puir != NULL) ? puir->hResult : ILS_E_MEMORY;
  804. if (SUCCEEDED(objri.hResult))
  805. {
  806. ASSERT (! MyIsBadServer (pIlsServer));
  807. // The server returns CLIENTINFO, create a User object
  808. //
  809. pu = new CIlsUser;
  810. if (pu != NULL)
  811. {
  812. objri.hResult = pu->Init(pIlsServer, &puir->lci);
  813. if (SUCCEEDED(objri.hResult))
  814. {
  815. pu->AddRef();
  816. }
  817. else
  818. {
  819. delete pu;
  820. pu = NULL;
  821. };
  822. }
  823. else
  824. {
  825. objri.hResult = ILS_E_MEMORY;
  826. };
  827. }
  828. else
  829. {
  830. pu = NULL;
  831. };
  832. // Package the notification info
  833. //
  834. objri.uReqID = uReqID;
  835. objri.pv = (void *)(pu == NULL ? NULL : (IIlsUser *)pu);
  836. NotifySink((void *)&objri, OnNotifyGetUserResult);
  837. if (pu != NULL)
  838. {
  839. pu->Release();
  840. };
  841. return NOERROR;
  842. }
  843. //****************************************************************************
  844. // STDMETHODIMP
  845. // CIlsMain::EnumUserNames (BSTR bstrServerName, IIlsFilter *pFilter,
  846. // ULONG *puReqID)
  847. //
  848. // History:
  849. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  850. // Created.
  851. //****************************************************************************
  852. HRESULT CIlsMain::
  853. EnumUsersEx (
  854. BOOL fNameOnly,
  855. CIlsServer *pIlsServer,
  856. IIlsFilter *pFilter,
  857. CAttributes *pAttrib,
  858. ULONG *puReqID )
  859. {
  860. LDAP_ASYNCINFO ldai;
  861. HRESULT hr;
  862. // Validate parameter
  863. //
  864. if (::MyIsBadServer (pIlsServer) || puReqID == NULL)
  865. return ILS_E_POINTER;
  866. // Clone the server object
  867. //
  868. pIlsServer = ((CIlsServer *) pIlsServer)->Clone ();
  869. if (pIlsServer == NULL)
  870. return ILS_E_MEMORY;
  871. // Get a list of extended attribute names
  872. //
  873. TCHAR *pszList = NULL;
  874. ULONG cList =0, cbList = 0;
  875. if (pAttrib != NULL)
  876. {
  877. ASSERT (!fNameOnly);
  878. hr = pAttrib->GetAttributeList(&pszList, &cList, &cbList);
  879. if (FAILED(hr))
  880. {
  881. pIlsServer->Release ();
  882. return hr;
  883. }
  884. }
  885. // Construct default filter if needed
  886. //
  887. TCHAR *pszFilter = NULL;
  888. BOOL fDefaultRenderer = FALSE;
  889. if (pFilter == NULL)
  890. {
  891. // Build default filter string
  892. //
  893. TCHAR szLocalFilter[32];
  894. wsprintf (&szLocalFilter[0], TEXT ("($%u=*)"), (UINT) ILS_STDATTR_USER_ID);
  895. // Render this filter
  896. //
  897. hr = StringToFilter (&szLocalFilter[0], (CFilter **) &pFilter);
  898. if (! SUCCEEDED (hr))
  899. goto MyExit;
  900. // Indicate we have default filter string
  901. //
  902. fDefaultRenderer = TRUE;
  903. }
  904. // Create a ldap-like filter
  905. //
  906. hr = ::FilterToLdapString ((CFilter *) pFilter, &pszFilter);
  907. if (hr != S_OK)
  908. goto MyExit;
  909. // Enumerate users
  910. //
  911. hr = fNameOnly ? ::UlsLdap_EnumClients (pIlsServer->GetServerInfo (),
  912. pszFilter,
  913. &ldai) :
  914. ::UlsLdap_EnumClientInfos (pIlsServer->GetServerInfo (),
  915. pszList,
  916. cList,
  917. pszFilter,
  918. &ldai);
  919. if (hr != S_OK)
  920. goto MyExit;
  921. // If updating server was successfully requested, wait for the response
  922. //
  923. COM_REQ_INFO ri;
  924. ReqInfo_Init (&ri);
  925. ri.uReqType = fNameOnly ? WM_ILS_ENUM_CLIENTS : WM_ILS_ENUM_CLIENTINFOS;
  926. ri.uMsgID = ldai.uMsgID;
  927. ReqInfo_SetMain (&ri, this);
  928. if (! fNameOnly)
  929. {
  930. ReqInfo_SetServer (&ri, pIlsServer);
  931. pIlsServer->AddRef ();
  932. }
  933. // Remember this request
  934. //
  935. hr = g_pReqMgr->NewRequest (&ri);
  936. if (hr == S_OK)
  937. {
  938. // Make sure the objects do not disappear before we get the response
  939. //
  940. this->AddRef ();
  941. // Return the request ID
  942. //
  943. *puReqID = ri.uReqID;
  944. }
  945. MyExit:
  946. // Release server object
  947. //
  948. pIlsServer->Release ();
  949. // Free the filter string
  950. //
  951. ::MemFree (pszFilter);
  952. // Release default filter if needed
  953. //
  954. if (fDefaultRenderer && pFilter != NULL)
  955. pFilter->Release ();
  956. // Free the list of extended attribute names
  957. //
  958. ::MemFree (pszList);
  959. return hr;
  960. }
  961. STDMETHODIMP
  962. CIlsMain::EnumUserNames (
  963. IIlsServer *pIlsServer,
  964. IIlsFilter *pFilter,
  965. IEnumIlsNames **ppEnumUserNames,
  966. ULONG *puReqID )
  967. {
  968. // Make sure ils main is initialized
  969. //
  970. if (! IsInitialized ())
  971. {
  972. return ILS_E_NOT_INITIALIZED;
  973. }
  974. // We do not implement synchronous operation
  975. //
  976. if (ppEnumUserNames != NULL)
  977. return ILS_E_NOT_IMPL;
  978. return EnumUsersEx (TRUE,
  979. (CIlsServer *) pIlsServer,
  980. pFilter,
  981. NULL,
  982. puReqID);
  983. }
  984. //****************************************************************************
  985. // STDMETHODIMP
  986. // CIlsMain::EnumUserNamesResult (ULONG uReqID, PLDAP_ENUM ple)
  987. //
  988. // History:
  989. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  990. // Created.
  991. //****************************************************************************
  992. STDMETHODIMP
  993. CIlsMain::EnumUserNamesResult (ULONG uReqID, PLDAP_ENUM ple)
  994. {
  995. ENUMRINFO eri;
  996. // Package the notification info
  997. //
  998. eri.uReqID = uReqID;
  999. // PLDAP_ENUM is NULL when the enumeration is terminated successfully
  1000. //
  1001. if (ple != NULL)
  1002. {
  1003. eri.hResult = ple->hResult;
  1004. eri.cItems = ple->cItems;
  1005. eri.pv = (void *)(((PBYTE)ple)+ple->uOffsetItems);
  1006. }
  1007. else
  1008. {
  1009. eri.hResult = S_FALSE;
  1010. eri.cItems = 0;
  1011. eri.pv = NULL;
  1012. };
  1013. NotifySink((void *)&eri, OnNotifyEnumUserNamesResult);
  1014. return NOERROR;
  1015. }
  1016. //****************************************************************************
  1017. // STDMETHODIMP
  1018. // CIlsMain::EnumUsers (BSTR bstrServerName, IIlsFilter *pFilter,
  1019. // ULONG *puReqID)
  1020. //
  1021. // History:
  1022. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1023. // Created.
  1024. //****************************************************************************
  1025. STDMETHODIMP CIlsMain::
  1026. EnumUsers (
  1027. IIlsServer *pIlsServer,
  1028. IIlsFilter *pFilter,
  1029. IIlsAttributes *pAttrib,
  1030. IEnumIlsUsers **ppEnumUsers,
  1031. ULONG *puReqID)
  1032. {
  1033. // Make sure ils main is initialized
  1034. //
  1035. if (! IsInitialized ())
  1036. {
  1037. return ILS_E_NOT_INITIALIZED;
  1038. }
  1039. // We do not implement synchronous operation
  1040. //
  1041. if (ppEnumUsers != NULL)
  1042. return ILS_E_NOT_IMPL;
  1043. return EnumUsersEx (FALSE,
  1044. (CIlsServer *) pIlsServer,
  1045. pFilter,
  1046. (CAttributes *) pAttrib,
  1047. puReqID);
  1048. }
  1049. //****************************************************************************
  1050. // STDMETHODIMP
  1051. // CIlsMain::EnumUsersResult (ULONG uReqID, PLDAP_ENUM ple, LPTSTR szServer)
  1052. //
  1053. // History:
  1054. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1055. // Created.
  1056. //****************************************************************************
  1057. STDMETHODIMP
  1058. CIlsMain::EnumUsersResult (ULONG uReqID, PLDAP_ENUM ple, CIlsServer *pIlsServer)
  1059. {
  1060. CIlsUser **ppu;
  1061. ULONG cUsers;
  1062. ENUMRINFO eri;
  1063. HRESULT hr;
  1064. if (ple != NULL)
  1065. {
  1066. eri.hResult = ple->hResult;
  1067. cUsers = ple->cItems;
  1068. }
  1069. else
  1070. {
  1071. eri.hResult = S_FALSE;
  1072. cUsers = 0;
  1073. };
  1074. eri.uReqID = uReqID;
  1075. eri.cItems = 0;
  1076. if ((eri.hResult == NOERROR) && (cUsers != 0))
  1077. {
  1078. ASSERT (! MyIsBadServer (pIlsServer));
  1079. // Build an array of User objects here
  1080. //
  1081. ppu = (CIlsUser **) ::MemAlloc (cUsers*sizeof(CIlsUser *));
  1082. if (ppu != NULL)
  1083. {
  1084. CIlsUser *pu;
  1085. PLDAP_CLIENTINFO pui;
  1086. ULONG i;
  1087. // Build one User object at a time
  1088. //
  1089. pui = (PLDAP_CLIENTINFO)(((PBYTE)ple)+ple->uOffsetItems);
  1090. for (i = 0; i < cUsers; i++)
  1091. {
  1092. pu = new CIlsUser;
  1093. if (pu != NULL)
  1094. {
  1095. if (SUCCEEDED(pu->Init(pIlsServer, pui)))
  1096. {
  1097. pu->AddRef();
  1098. ppu[eri.cItems++] = pu;
  1099. }
  1100. else
  1101. {
  1102. delete pu;
  1103. };
  1104. };
  1105. pui++;
  1106. };
  1107. }
  1108. else
  1109. {
  1110. eri.hResult = ILS_E_MEMORY;
  1111. };
  1112. }
  1113. else
  1114. {
  1115. ppu = NULL;
  1116. };
  1117. // Package the notification info
  1118. //
  1119. eri.pv = (void *)ppu;
  1120. NotifySink((void *)&eri, OnNotifyEnumUsersResult);
  1121. // Free the resources
  1122. //
  1123. if (ppu != NULL)
  1124. {
  1125. for (; eri.cItems; eri.cItems--)
  1126. {
  1127. ppu[eri.cItems-1]->Release();
  1128. };
  1129. ::MemFree (ppu);
  1130. };
  1131. return NOERROR;
  1132. }
  1133. //****************************************************************************
  1134. // STDMETHODIMP
  1135. // CIlsMain::CreateMeetingPlace (BSTR bstrMeetingPlaceID, LONG lConfType, LONG lMemberType,
  1136. // IIlsMeetingPlace **ppMeetingPlace);
  1137. //
  1138. //
  1139. // History:
  1140. //
  1141. // Created.
  1142. //****************************************************************************
  1143. #ifdef ENABLE_MEETING_PLACE
  1144. STDMETHODIMP
  1145. CIlsMain::CreateMeetingPlace (
  1146. BSTR bstrMeetingPlaceID,
  1147. LONG lConfType,
  1148. LONG lMemberType,
  1149. IIlsMeetingPlace **ppMeetingPlace)
  1150. {
  1151. // Make sure ils main is initialized
  1152. //
  1153. if (! IsInitialized ())
  1154. {
  1155. return ILS_E_NOT_INITIALIZED;
  1156. }
  1157. CIlsMeetingPlace *pCcr = NULL;
  1158. HRESULT hr;
  1159. // we are just createing a place holder object which when registered
  1160. // will be visible by other users
  1161. if (ppMeetingPlace == NULL || bstrMeetingPlaceID == NULL)
  1162. {
  1163. return ILS_E_POINTER;
  1164. }
  1165. *ppMeetingPlace = NULL;
  1166. pCcr = new CIlsMeetingPlace;
  1167. if (pCcr != NULL )
  1168. {
  1169. // succeeded in createing the object
  1170. hr = pCcr->Init(bstrMeetingPlaceID, lConfType, lConfType);
  1171. if (SUCCEEDED(hr))
  1172. {
  1173. *ppMeetingPlace = (IIlsMeetingPlace *) pCcr;
  1174. (*ppMeetingPlace)->AddRef ();
  1175. }
  1176. else
  1177. {
  1178. delete pCcr;
  1179. }
  1180. }
  1181. else
  1182. {
  1183. hr = ILS_E_MEMORY;
  1184. }
  1185. return (hr);
  1186. }
  1187. #endif // ENABLE_MEETING_PLACE
  1188. //****************************************************************************
  1189. // STDMETHODIMP
  1190. // CIlsMain::GetMeetingPlace (BSTR bstrServerName, BSTR bstrMeetingPlaceID, ULONG *puReqID)
  1191. //
  1192. // History:
  1193. // Created.
  1194. //****************************************************************************
  1195. #ifdef ENABLE_MEETING_PLACE
  1196. STDMETHODIMP CIlsMain::
  1197. GetMeetingPlace (
  1198. IIlsServer *pIlsServer,
  1199. BSTR bstrMeetingPlaceID,
  1200. IIlsAttributes *pAttrib,
  1201. IIlsMeetingPlace **ppMeetingPlace,
  1202. ULONG *puReqID)
  1203. {
  1204. // Make sure ils main is initialized
  1205. //
  1206. if (! IsInitialized ())
  1207. {
  1208. return ILS_E_NOT_INITIALIZED;
  1209. }
  1210. LDAP_ASYNCINFO ldai;
  1211. LPTSTR pszMtgID = NULL;
  1212. HRESULT hr;
  1213. // We do not implement synchronous operation
  1214. //
  1215. if (ppMeetingPlace != NULL)
  1216. return ILS_E_NOT_IMPL;
  1217. // Validate parameters
  1218. //
  1219. if (::MyIsBadServer (pIlsServer) || bstrMeetingPlaceID == NULL || puReqID == NULL)
  1220. return ILS_E_POINTER;
  1221. // Clone the server object
  1222. //
  1223. pIlsServer = ((CIlsServer *) pIlsServer)->Clone ();
  1224. if (pIlsServer == NULL)
  1225. return ILS_E_MEMORY;
  1226. // Get a list of extended attribute names
  1227. //
  1228. TCHAR *pszList = NULL;
  1229. ULONG cList =0, cbList = 0;
  1230. if (pAttrib != NULL)
  1231. {
  1232. hr = ((CAttributes *) pAttrib)->GetAttributeList (&pszList, &cList, &cbList);
  1233. if (FAILED (hr))
  1234. {
  1235. pIlsServer->Release ();
  1236. return hr;
  1237. }
  1238. }
  1239. // Get from the specified server
  1240. //
  1241. hr = BSTR_to_LPTSTR(&pszMtgID, bstrMeetingPlaceID);
  1242. if (SUCCEEDED(hr))
  1243. {
  1244. // BUGBUG AppID not given
  1245. hr = ::UlsLdap_ResolveMeeting (((CIlsServer *) pIlsServer)->GetServerInfo (),
  1246. pszMtgID,
  1247. pszList,
  1248. cList,
  1249. &ldai);
  1250. if (SUCCEEDED(hr))
  1251. {
  1252. COM_REQ_INFO ri;
  1253. ReqInfo_Init (&ri);
  1254. // If updating server was successfully requested, wait for the response
  1255. //
  1256. ri.uReqType = WM_ILS_RESOLVE_MEETING;
  1257. ri.uMsgID = ldai.uMsgID;
  1258. ReqInfo_SetMain (&ri, this);
  1259. ReqInfo_SetServer (&ri, pIlsServer);
  1260. pIlsServer->AddRef ();
  1261. hr = g_pReqMgr->NewRequest(&ri);
  1262. if (SUCCEEDED(hr))
  1263. {
  1264. // Make sure the objects do not disappear before we get the response
  1265. //
  1266. this->AddRef();
  1267. // Return the request ID
  1268. //
  1269. *puReqID = ri.uReqID;
  1270. }
  1271. };
  1272. ::MemFree (pszMtgID);
  1273. };
  1274. // Release the server object
  1275. //
  1276. pIlsServer->Release ();
  1277. // Free the list of extended attribute names
  1278. //
  1279. ::MemFree (pszList);
  1280. return hr;
  1281. }
  1282. #endif // ENABLE_MEETING_PLACE
  1283. //****************************************************************************
  1284. // HRESULT
  1285. // CIlsMain::GetMeetingPlaceResult (ULONG uReqID, LDAP_MEETINFO_RES pmir,
  1286. // LPTSTR szServer)
  1287. //
  1288. // History:
  1289. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1290. // Created.
  1291. //****************************************************************************
  1292. #ifdef ENABLE_MEETING_PLACE
  1293. HRESULT CIlsMain::
  1294. GetMeetingPlaceResult (ULONG uReqID, PLDAP_MEETINFO_RES pmir, CIlsServer *pIlsServer)
  1295. {
  1296. CIlsMeetingPlace *pm;
  1297. OBJRINFO objri;
  1298. // Default to the server's result
  1299. //
  1300. objri.hResult = (pmir != NULL) ? pmir->hResult : ILS_E_MEMORY;
  1301. if (SUCCEEDED (objri.hResult))
  1302. {
  1303. ASSERT (! MyIsBadServer (pIlsServer));
  1304. // The server returns CLIENTINFO, create a User object
  1305. //
  1306. pm = new CIlsMeetingPlace;
  1307. if (pm != NULL)
  1308. {
  1309. objri.hResult = pm->Init (pIlsServer, &(pmir->lmi));
  1310. if (SUCCEEDED (objri.hResult))
  1311. {
  1312. pm->AddRef();
  1313. }
  1314. else
  1315. {
  1316. delete pm;
  1317. pm = NULL;
  1318. };
  1319. }
  1320. else
  1321. {
  1322. objri.hResult = ILS_E_MEMORY;
  1323. };
  1324. }
  1325. else
  1326. {
  1327. pm = NULL;
  1328. };
  1329. // Package the notification info
  1330. //
  1331. objri.uReqID = uReqID;
  1332. objri.pv = (void *) (pm == NULL ? NULL : (IIlsMeetingPlace *) pm);
  1333. NotifySink ((void *) &objri, OnNotifyGetMeetingPlaceResult);
  1334. if (pm != NULL)
  1335. pm->Release();
  1336. return NOERROR;
  1337. }
  1338. #endif // ENABLE_MEETING_PLACE
  1339. //****************************************************************************
  1340. // STDMETHODIMP
  1341. // CIlsMain::EnumMeetingPlaces (BSTR bstrServerName, IIlsFilter *pFilter,
  1342. // IIlsAttributes *pAttributes, ULONG *puReqID)
  1343. //
  1344. // History:
  1345. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1346. // Created.
  1347. //****************************************************************************
  1348. #ifdef ENABLE_MEETING_PLACE
  1349. HRESULT CIlsMain::
  1350. EnumMeetingPlacesEx (
  1351. BOOL fNameOnly,
  1352. CIlsServer *pIlsServer,
  1353. IIlsFilter *pFilter,
  1354. CAttributes *pAttrib,
  1355. ULONG *puReqID)
  1356. {
  1357. LDAP_ASYNCINFO ldai;
  1358. HRESULT hr;
  1359. // Validate parameter
  1360. //
  1361. if (::MyIsBadServer (pIlsServer) || puReqID == NULL)
  1362. return ILS_E_POINTER;
  1363. if (pFilter != NULL)
  1364. return ILS_E_PARAMETER;
  1365. // Clone the server object
  1366. //
  1367. pIlsServer = ((CIlsServer *) pIlsServer)->Clone ();
  1368. if (pIlsServer == NULL)
  1369. return ILS_E_MEMORY;
  1370. // Get a list of extended attribute names
  1371. //
  1372. TCHAR *pszList = NULL;
  1373. ULONG cList =0, cbList = 0;
  1374. if (pAttrib != NULL)
  1375. {
  1376. hr = ((CAttributes *) pAttrib)->GetAttributeList (&pszList, &cList, &cbList);
  1377. if (FAILED (hr))
  1378. {
  1379. pIlsServer->Release ();
  1380. return hr;
  1381. }
  1382. }
  1383. // Construct default filter if needed
  1384. //
  1385. TCHAR *pszFilter = NULL;
  1386. BOOL fDefaultRenderer = FALSE;
  1387. if (pFilter == NULL)
  1388. {
  1389. // Build default filter string
  1390. //
  1391. TCHAR szLocalFilter[256];
  1392. wsprintf (&szLocalFilter[0], TEXT ("($%u=*)"), (INT) ILS_STDATTR_MEETING_ID );
  1393. // Render this filter
  1394. //
  1395. hr = StringToFilter (&szLocalFilter[0], (CFilter **) &pFilter);
  1396. if (! SUCCEEDED (hr))
  1397. goto MyExit;
  1398. // Indicate we have default filter string
  1399. //
  1400. fDefaultRenderer = TRUE;
  1401. }
  1402. // Create a ldap-like filter
  1403. //
  1404. hr = ::FilterToLdapString ((CFilter *) pFilter, &pszFilter);
  1405. if (hr != S_OK)
  1406. goto MyExit;
  1407. // Enum meeting places
  1408. //
  1409. hr = fNameOnly ? ::UlsLdap_EnumMeetings (pIlsServer->GetServerInfo (),
  1410. pszFilter,
  1411. &ldai) :
  1412. ::UlsLdap_EnumMeetingInfos (pIlsServer->GetServerInfo (),
  1413. pszList,
  1414. cList,
  1415. pszFilter,
  1416. &ldai);
  1417. if (SUCCEEDED(hr))
  1418. {
  1419. COM_REQ_INFO ri;
  1420. ReqInfo_Init (&ri);
  1421. // If updating server was successfully requested, wait for the response
  1422. //
  1423. ri.uReqType = fNameOnly ? WM_ILS_ENUM_MEETINGS : WM_ILS_ENUM_MEETINGINFOS;
  1424. ri.uMsgID = ldai.uMsgID;
  1425. ReqInfo_SetMain (&ri, this);
  1426. if (! fNameOnly)
  1427. {
  1428. ReqInfo_SetServer (&ri, pIlsServer);
  1429. pIlsServer->AddRef ();
  1430. }
  1431. hr = g_pReqMgr->NewRequest(&ri);
  1432. if (SUCCEEDED(hr))
  1433. {
  1434. // Make sure the objects do not disappear before we get the response
  1435. //
  1436. this->AddRef();
  1437. // Return the request ID
  1438. //
  1439. *puReqID = ri.uReqID;
  1440. };
  1441. };
  1442. MyExit:
  1443. // Free the server object
  1444. //
  1445. pIlsServer->Release ();
  1446. // Free the list of extended attribute names
  1447. //
  1448. ::MemFree (pszList);
  1449. // Free the filter string
  1450. //
  1451. ::MemFree (pszFilter);
  1452. // Release default filter if needed
  1453. //
  1454. if (fDefaultRenderer && pFilter != NULL)
  1455. pFilter->Release ();
  1456. return hr;
  1457. }
  1458. #endif // ENABLE_MEETING_PLACE
  1459. #ifdef ENABLE_MEETING_PLACE
  1460. STDMETHODIMP CIlsMain::
  1461. EnumMeetingPlaces (
  1462. IIlsServer *pServer,
  1463. IIlsFilter *pFilter,
  1464. IIlsAttributes *pAttributes,
  1465. IEnumIlsMeetingPlaces **ppEnum,
  1466. ULONG *puReqID)
  1467. {
  1468. // Make sure ils main is initialized
  1469. //
  1470. if (! IsInitialized ())
  1471. {
  1472. return ILS_E_NOT_INITIALIZED;
  1473. }
  1474. // We do not implement synchronous operation
  1475. //
  1476. if (ppEnum != NULL)
  1477. return ILS_E_NOT_IMPL;
  1478. return EnumMeetingPlacesEx (FALSE,
  1479. (CIlsServer *) pServer,
  1480. pFilter,
  1481. (CAttributes *) pAttributes,
  1482. puReqID);
  1483. }
  1484. #endif // ENABLE_MEETING_PLACE
  1485. //****************************************************************************
  1486. // HRESULT
  1487. // CIlsMain::EnumMeetingPlacesResult (ULONG uReqID, PLDAP_ENUM ple, LPTSTR szServer)
  1488. //
  1489. // History:
  1490. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1491. // Created.
  1492. //****************************************************************************
  1493. #ifdef ENABLE_MEETING_PLACE
  1494. HRESULT
  1495. CIlsMain::EnumMeetingPlacesResult (ULONG uReqID, PLDAP_ENUM ple, CIlsServer *pIlsServer)
  1496. {
  1497. CIlsMeetingPlace **ppm;
  1498. ULONG cMeetingPlaces;
  1499. ENUMRINFO eri;
  1500. HRESULT hr;
  1501. if (ple != NULL)
  1502. {
  1503. eri.hResult = ple->hResult;
  1504. cMeetingPlaces = ple->cItems;
  1505. }
  1506. else
  1507. {
  1508. eri.hResult = S_FALSE;
  1509. cMeetingPlaces = 0;
  1510. };
  1511. eri.uReqID = uReqID;
  1512. eri.cItems = 0;
  1513. if ((eri.hResult == NOERROR) && (cMeetingPlaces != 0))
  1514. {
  1515. ASSERT (! MyIsBadServer (pIlsServer));
  1516. // Build an array of MeetingPlace objects here
  1517. //
  1518. ppm = (CIlsMeetingPlace **) ::MemAlloc (cMeetingPlaces*sizeof(CIlsMeetingPlace *));
  1519. if (ppm != NULL)
  1520. {
  1521. CIlsMeetingPlace *pm;
  1522. PLDAP_MEETINFO pmi;
  1523. ULONG i;
  1524. // Build one MeetingPlace object at a time
  1525. //
  1526. pmi = (PLDAP_MEETINFO)(((PBYTE)ple)+ple->uOffsetItems);
  1527. for (i = 0; i < cMeetingPlaces; i++)
  1528. {
  1529. pm = new CIlsMeetingPlace;
  1530. if (pm != NULL)
  1531. {
  1532. if (SUCCEEDED(pm->Init(pIlsServer, pmi)))
  1533. {
  1534. pm->AddRef();
  1535. ppm[eri.cItems++] = pm;
  1536. }
  1537. else
  1538. {
  1539. delete pm;
  1540. };
  1541. };
  1542. pmi++;
  1543. };
  1544. }
  1545. else
  1546. {
  1547. eri.hResult = ILS_E_MEMORY;
  1548. };
  1549. }
  1550. else
  1551. {
  1552. ppm = NULL;
  1553. };
  1554. // Package the notification info
  1555. //
  1556. eri.pv = (void *)ppm;
  1557. NotifySink((void *)&eri, OnNotifyEnumMeetingPlacesResult);
  1558. // Free the resources
  1559. //
  1560. if (ppm != NULL)
  1561. {
  1562. for (; eri.cItems; eri.cItems--)
  1563. {
  1564. ppm[eri.cItems-1]->Release();
  1565. };
  1566. ::MemFree (ppm);
  1567. };
  1568. return NOERROR;
  1569. }
  1570. #endif // ENABLE_MEETING_PLACE
  1571. //****************************************************************************
  1572. // STDMETHODIMP
  1573. // CIlsMain::EnumMeetingPlaceNames (BSTR bstrServerName, IIlsFilter *pFilter,
  1574. // ULONG *puReqID)
  1575. //
  1576. // History:
  1577. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1578. // Created.
  1579. //****************************************************************************
  1580. #ifdef ENABLE_MEETING_PLACE
  1581. STDMETHODIMP CIlsMain::
  1582. EnumMeetingPlaceNames (
  1583. IIlsServer *pServer,
  1584. IIlsFilter *pFilter,
  1585. IEnumIlsNames **ppEnum,
  1586. ULONG *puReqID)
  1587. {
  1588. // Make sure ils main is initialized
  1589. //
  1590. if (! IsInitialized ())
  1591. {
  1592. return ILS_E_NOT_INITIALIZED;
  1593. }
  1594. // We do not implement synchronous operation
  1595. //
  1596. if (ppEnum != NULL)
  1597. return ILS_E_NOT_IMPL;
  1598. return EnumMeetingPlacesEx (TRUE,
  1599. (CIlsServer *) pServer,
  1600. pFilter,
  1601. NULL,
  1602. puReqID);
  1603. }
  1604. #endif // ENABLE_MEETING_PLACE
  1605. //****************************************************************************
  1606. // HRESULT
  1607. // CIlsMain::EnumMeetingPlaceNamesResult (ULONG uReqID, PLDAP_ENUM ple)
  1608. //
  1609. // History:
  1610. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1611. // Created.
  1612. //****************************************************************************
  1613. #ifdef ENABLE_MEETING_PLACE
  1614. HRESULT
  1615. CIlsMain::EnumMeetingPlaceNamesResult (ULONG uReqID, PLDAP_ENUM ple)
  1616. {
  1617. ENUMRINFO eri;
  1618. // Package the notification info
  1619. //
  1620. eri.uReqID = uReqID;
  1621. // PLDAP_ENUM is NULL when the enumeration is terminated successfully
  1622. //
  1623. if (ple != NULL)
  1624. {
  1625. eri.hResult = ple->hResult;
  1626. eri.cItems = ple->cItems;
  1627. eri.pv = (void *)(((PBYTE)ple)+ple->uOffsetItems);
  1628. }
  1629. else
  1630. {
  1631. eri.hResult = S_FALSE;
  1632. eri.cItems = 0;
  1633. eri.pv = NULL;
  1634. };
  1635. NotifySink((void *)&eri, OnNotifyEnumMeetingPlaceNamesResult);
  1636. return NOERROR;
  1637. }
  1638. #endif // ENABLE_MEETING_PLACE
  1639. //****************************************************************************
  1640. // STDMETHODIMP
  1641. // CIlsMain::Abort (ULONG uReqID)
  1642. //
  1643. // History:
  1644. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1645. // Created.
  1646. //****************************************************************************
  1647. STDMETHODIMP
  1648. CIlsMain::Abort (ULONG uReqID)
  1649. {
  1650. // Make sure ils main is initialized
  1651. //
  1652. if (! IsInitialized ())
  1653. {
  1654. return ILS_E_NOT_INITIALIZED;
  1655. }
  1656. COM_REQ_INFO ri;
  1657. ReqInfo_Init (&ri);
  1658. BOOL fServerReq;
  1659. HRESULT hr;
  1660. // Look for the matching request information
  1661. //
  1662. ri.uReqID = uReqID;
  1663. ri.uMsgID = 0;
  1664. hr = g_pReqMgr->GetRequestInfo(&ri);
  1665. if (FAILED(hr))
  1666. {
  1667. return ILS_E_PARAMETER;
  1668. };
  1669. // Determine the request type
  1670. //
  1671. hr = NOERROR;
  1672. switch(ri.uReqType)
  1673. {
  1674. //*************************************************************************
  1675. // Fail if it is register request.
  1676. // Cancelling register request must be done through unregister
  1677. //*************************************************************************
  1678. //
  1679. case WM_ILS_LOCAL_REGISTER:
  1680. case WM_ILS_LOCAL_UNREGISTER:
  1681. return ILS_E_FAIL;
  1682. //*************************************************************************
  1683. // These requests are parts of register, they should not be exposed to
  1684. // the caller.
  1685. //*************************************************************************
  1686. //
  1687. case WM_ILS_REGISTER_CLIENT:
  1688. case WM_ILS_UNREGISTER_CLIENT:
  1689. ASSERT(0);
  1690. break;
  1691. //*************************************************************************
  1692. // Release the objects and resources refernced or allocated for the request
  1693. // See callback.cpp for the handler in the successful response case
  1694. //*************************************************************************
  1695. //
  1696. case WM_ILS_REGISTER_PROTOCOL:
  1697. case WM_ILS_UNREGISTER_PROTOCOL:
  1698. case WM_ILS_LOCAL_REGISTER_PROTOCOL:
  1699. case WM_ILS_LOCAL_UNREGISTER_PROTOCOL:
  1700. {
  1701. CIlsUser *pUser = ReqInfo_GetUser (&ri);
  1702. if (pUser != NULL)
  1703. pUser->Release ();
  1704. CLocalProt *pProtocol = ReqInfo_GetProtocol (&ri);
  1705. if (pProtocol != NULL)
  1706. pProtocol->Release ();
  1707. }
  1708. break;
  1709. case WM_ILS_SET_CLIENT_INFO:
  1710. case WM_ILS_ENUM_PROTOCOLS:
  1711. case WM_ILS_RESOLVE_PROTOCOL:
  1712. {
  1713. CIlsUser *pUser = ReqInfo_GetUser (&ri);
  1714. if (pUser != NULL)
  1715. pUser->Release ();
  1716. }
  1717. break;
  1718. case WM_ILS_ENUM_CLIENTS:
  1719. {
  1720. CIlsMain *pMain = ReqInfo_GetMain (&ri);
  1721. if (pMain != NULL)
  1722. pMain->Release ();
  1723. }
  1724. break;
  1725. case WM_ILS_RESOLVE_CLIENT:
  1726. case WM_ILS_ENUM_CLIENTINFOS:
  1727. {
  1728. CIlsMain *pMain = ReqInfo_GetMain (&ri);
  1729. if (pMain != NULL)
  1730. pMain->Release ();
  1731. CIlsServer *pServer = ReqInfo_GetServer (&ri);
  1732. if (pServer != NULL)
  1733. pServer->Release ();
  1734. }
  1735. break;
  1736. //*************************************************************************
  1737. // Fail if it is register request.
  1738. // Cancelling register request must be done through unregister
  1739. //*************************************************************************
  1740. //
  1741. #ifdef ENABLE_MEETING_PLACE
  1742. case WM_ILS_REGISTER_MEETING:
  1743. case WM_ILS_UNREGISTER_MEETING:
  1744. return ILS_E_FAIL;
  1745. case WM_ILS_SET_MEETING_INFO:
  1746. case WM_ILS_ADD_ATTENDEE:
  1747. case WM_ILS_REMOVE_ATTENDEE:
  1748. case WM_ILS_ENUM_ATTENDEES:
  1749. {
  1750. CIlsMeetingPlace *pMeeting = ReqInfo_GetMeeting (&ri);
  1751. if (pMeeting != NULL)
  1752. pMeeting->Release ();
  1753. }
  1754. break;
  1755. case WM_ILS_RESOLVE_MEETING:
  1756. case WM_ILS_ENUM_MEETINGINFOS:
  1757. {
  1758. CIlsMain *pMain = ReqInfo_GetMain (&ri);
  1759. if (pMain != NULL)
  1760. pMain->Release ();
  1761. CIlsServer *pServer = ReqInfo_GetServer (&ri);
  1762. if (pServer != NULL)
  1763. pServer->Release ();
  1764. }
  1765. break;
  1766. case WM_ILS_ENUM_MEETINGS:
  1767. {
  1768. CIlsMain *pMain = ReqInfo_GetMain (&ri);
  1769. if (pMain != NULL)
  1770. pMain->Release ();
  1771. }
  1772. break;
  1773. #endif // ENABLE_MEETING_PLACE
  1774. default:
  1775. // Unknown request
  1776. //
  1777. ASSERT(0);
  1778. break;
  1779. };
  1780. // If it is a server request, cancel the request
  1781. //
  1782. if (ri.uMsgID != 0)
  1783. {
  1784. hr = UlsLdap_Cancel(ri.uMsgID);
  1785. };
  1786. if (SUCCEEDED(hr))
  1787. {
  1788. // Remove the request from the queue
  1789. //
  1790. hr = g_pReqMgr->RequestDone(&ri);
  1791. };
  1792. return hr;
  1793. }
  1794. //****************************************************************************
  1795. // STDMETHODIMP
  1796. // CIlsMain::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  1797. //
  1798. // History:
  1799. // Wed 17-Apr-1996 11:15:02 -by- Viroon Touranachun [viroont]
  1800. // Created.
  1801. //****************************************************************************
  1802. STDMETHODIMP
  1803. CIlsMain::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  1804. {
  1805. CEnumConnectionPoints *pecp;
  1806. HRESULT hr;
  1807. // Validate parameters
  1808. //
  1809. if (ppEnum == NULL)
  1810. {
  1811. return ILS_E_POINTER;
  1812. };
  1813. // Assume failure
  1814. //
  1815. *ppEnum = NULL;
  1816. // Create an enumerator
  1817. //
  1818. pecp = new CEnumConnectionPoints;
  1819. if (pecp == NULL)
  1820. return ILS_E_MEMORY;
  1821. // Initialize the enumerator
  1822. //
  1823. hr = pecp->Init((IConnectionPoint *)pConnPt);
  1824. if (FAILED(hr))
  1825. {
  1826. delete pecp;
  1827. return hr;
  1828. };
  1829. // Give it back to the caller
  1830. //
  1831. pecp->AddRef();
  1832. *ppEnum = pecp;
  1833. return S_OK;
  1834. }
  1835. //****************************************************************************
  1836. // STDMETHODIMP
  1837. // CIlsMain::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  1838. //
  1839. // History:
  1840. // Wed 17-Apr-1996 11:15:09 -by- Viroon Touranachun [viroont]
  1841. // Created.
  1842. //****************************************************************************
  1843. STDMETHODIMP
  1844. CIlsMain::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  1845. {
  1846. IID siid;
  1847. HRESULT hr;
  1848. // Validate parameters
  1849. //
  1850. if (ppcp == NULL)
  1851. {
  1852. return ILS_E_POINTER;
  1853. };
  1854. // Assume failure
  1855. //
  1856. *ppcp = NULL;
  1857. if (pConnPt != NULL)
  1858. {
  1859. hr = pConnPt->GetConnectionInterface(&siid);
  1860. if (SUCCEEDED(hr))
  1861. {
  1862. if (riid == siid)
  1863. {
  1864. *ppcp = (IConnectionPoint *)pConnPt;
  1865. (*ppcp)->AddRef();
  1866. hr = S_OK;
  1867. }
  1868. else
  1869. {
  1870. hr = ILS_E_NO_INTERFACE;
  1871. };
  1872. };
  1873. }
  1874. else
  1875. {
  1876. hr = ILS_E_NO_INTERFACE;
  1877. };
  1878. return hr;
  1879. }
  1880. /* ----------------------------------------------------------------------
  1881. CIlsMain::CreateFilter
  1882. Output:
  1883. ppFilter: a placeholder for the new filter object
  1884. Input:
  1885. FilterOp: a filter operation
  1886. History:
  1887. 11/12/96 Chu, Lon-Chan [lonchanc]
  1888. Created.
  1889. ---------------------------------------------------------------------- */
  1890. STDMETHODIMP CIlsMain::
  1891. CreateFilter (
  1892. ILS_FILTER_TYPE FilterType,
  1893. ILS_FILTER_OP FilterOp,
  1894. IIlsFilter **ppFilter )
  1895. {
  1896. // Make sure ils main is initialized
  1897. //
  1898. if (! IsInitialized ())
  1899. {
  1900. return ILS_E_NOT_INITIALIZED;
  1901. }
  1902. // Make sure we have valid return pointer
  1903. //
  1904. if (ppFilter == NULL)
  1905. return ILS_E_POINTER;
  1906. // Make sure type/op are compatible
  1907. //
  1908. HRESULT hr = S_OK;
  1909. switch (FilterType)
  1910. {
  1911. case ILS_FILTERTYPE_COMPOSITE:
  1912. // Make sure type/op are compatible
  1913. //
  1914. switch (FilterOp)
  1915. {
  1916. case ILS_FILTEROP_AND:
  1917. // Supported
  1918. //
  1919. break;
  1920. case ILS_FILTEROP_OR:
  1921. case ILS_FILTEROP_NOT:
  1922. // Not supported
  1923. //
  1924. // lonchanc: let it fail at the server side
  1925. hr = ILS_S_SERVER_MAY_NOT_SUPPORT;
  1926. break;
  1927. default:
  1928. // Invalid
  1929. //
  1930. hr = ILS_E_PARAMETER;
  1931. break;
  1932. }
  1933. break;
  1934. case ILS_FILTERTYPE_SIMPLE:
  1935. // Make sure type/op are compatible
  1936. //
  1937. switch (FilterOp)
  1938. {
  1939. case ILS_FILTEROP_EQUAL:
  1940. case ILS_FILTEROP_EXIST:
  1941. case ILS_FILTEROP_LESS_THAN:
  1942. case ILS_FILTEROP_GREATER_THAN:
  1943. // Supported
  1944. //
  1945. break;
  1946. case ILS_FILTEROP_APPROX:
  1947. // Not supported
  1948. //
  1949. hr = ILS_S_SERVER_MAY_NOT_SUPPORT;
  1950. break;
  1951. default:
  1952. // Invalid
  1953. //
  1954. hr = ILS_E_PARAMETER;
  1955. break;
  1956. }
  1957. break;
  1958. default:
  1959. hr = ILS_E_FILTER_TYPE;
  1960. break;
  1961. }
  1962. // Create filter only if type/op are compatible
  1963. //
  1964. if (SUCCEEDED (hr))
  1965. {
  1966. CFilter *pFilter = new CFilter (FilterType);
  1967. *ppFilter = pFilter;
  1968. if (pFilter != NULL)
  1969. {
  1970. hr = S_OK;
  1971. pFilter->AddRef ();
  1972. pFilter->SetOp (FilterOp);
  1973. }
  1974. else
  1975. hr = ILS_E_MEMORY;
  1976. }
  1977. return hr;
  1978. }
  1979. /* ----------------------------------------------------------------------
  1980. CIlsMain::StringToFilter
  1981. Output:
  1982. ppFilter: a placeholder for the new filter object
  1983. Input:
  1984. bstrFilterString: an LDAP-like filter string
  1985. History:
  1986. 11/12/96 Chu, Lon-Chan [lonchanc]
  1987. Created.
  1988. ---------------------------------------------------------------------- */
  1989. STDMETHODIMP CIlsMain::
  1990. StringToFilter ( BSTR bstrFilterString, IIlsFilter **ppFilter )
  1991. {
  1992. // Make sure ils main is initialized
  1993. //
  1994. if (! IsInitialized ())
  1995. {
  1996. return ILS_E_NOT_INITIALIZED;
  1997. }
  1998. // Make sure the filter string is valid
  1999. //
  2000. if (bstrFilterString == NULL)
  2001. return ILS_E_POINTER;
  2002. // Convert a bstr to an ansi string
  2003. //
  2004. TCHAR *pszFilter = NULL;
  2005. HRESULT hr = ::BSTR_to_LPTSTR (&pszFilter, bstrFilterString);
  2006. if (hr == S_OK)
  2007. {
  2008. ASSERT (pszFilter != NULL);
  2009. // Render this filter
  2010. //
  2011. hr = StringToFilter (pszFilter, (CFilter **) ppFilter);
  2012. // Free the temporary ansi string
  2013. //
  2014. ::MemFree(pszFilter);
  2015. }
  2016. return hr;
  2017. }
  2018. HRESULT CIlsMain::
  2019. StringToFilter ( TCHAR *pszFilter, CFilter **ppFilter )
  2020. {
  2021. // Construct a composite filter
  2022. //
  2023. CFilterParser FilterParser;
  2024. return FilterParser.Expr (ppFilter, pszFilter);
  2025. }
  2026. STDMETHODIMP CIlsMain::
  2027. CreateServer ( BSTR bstrServerName, IIlsServer **ppServer )
  2028. {
  2029. // Make sure ils main is initialized
  2030. //
  2031. if (! IsInitialized ())
  2032. {
  2033. return ILS_E_NOT_INITIALIZED;
  2034. }
  2035. if (bstrServerName == NULL || ppServer == NULL)
  2036. return ILS_E_POINTER;
  2037. HRESULT hr;
  2038. CIlsServer *pIlsServer = new CIlsServer;
  2039. if (pIlsServer != NULL)
  2040. {
  2041. hr = pIlsServer->SetServerName (bstrServerName);
  2042. if (hr == S_OK)
  2043. {
  2044. pIlsServer->AddRef ();
  2045. }
  2046. else
  2047. {
  2048. delete pIlsServer;
  2049. pIlsServer = NULL;
  2050. }
  2051. }
  2052. else
  2053. {
  2054. hr = ILS_E_MEMORY;
  2055. }
  2056. *ppServer = (IIlsServer *) pIlsServer;
  2057. return hr;
  2058. }
  2059. /* ---------- server authentication object ------------ */
  2060. CIlsServer::
  2061. CIlsServer ( VOID )
  2062. :m_cRefs (0),
  2063. m_dwSignature (ILS_SERVER_SIGNATURE)
  2064. {
  2065. ::ZeroMemory (&m_ServerInfo, sizeof (m_ServerInfo));
  2066. m_ServerInfo.AuthMethod = ILS_AUTH_ANONYMOUS;
  2067. }
  2068. CIlsServer::
  2069. ~CIlsServer ( VOID )
  2070. {
  2071. m_dwSignature = 0;
  2072. ::IlsFreeServerInfo (&m_ServerInfo);
  2073. }
  2074. STDMETHODIMP_(ULONG) CIlsServer::
  2075. AddRef ( VOID )
  2076. {
  2077. DllLock();
  2078. MyDebugMsg ((DM_REFCOUNT, "CIlsServer::AddRef: ref=%ld\r\n", m_cRefs));
  2079. ::InterlockedIncrement (&m_cRefs);
  2080. return m_cRefs;
  2081. }
  2082. STDMETHODIMP_(ULONG) CIlsServer::
  2083. Release ( VOID )
  2084. {
  2085. DllRelease();
  2086. ASSERT (m_cRefs > 0);
  2087. MyDebugMsg ((DM_REFCOUNT, "CIlsServer::Release: ref=%ld\r\n", m_cRefs));
  2088. if (::InterlockedDecrement (&m_cRefs) == 0)
  2089. {
  2090. delete this;
  2091. return 0;
  2092. }
  2093. return m_cRefs;
  2094. }
  2095. STDMETHODIMP CIlsServer::
  2096. QueryInterface ( REFIID riid, VOID **ppv )
  2097. {
  2098. *ppv = NULL;
  2099. if (riid == IID_IIlsServer || riid == IID_IUnknown)
  2100. {
  2101. *ppv = (IIlsServer *) this;
  2102. }
  2103. if (*ppv != NULL)
  2104. {
  2105. ((LPUNKNOWN) *ppv)->AddRef();
  2106. return S_OK;
  2107. }
  2108. return ILS_E_NO_INTERFACE;
  2109. }
  2110. STDMETHODIMP CIlsServer::
  2111. SetAuthenticationMethod ( ILS_ENUM_AUTH_METHOD enumAuthMethod )
  2112. {
  2113. HRESULT hr;
  2114. if (ILS_AUTH_ANONYMOUS <= enumAuthMethod &&
  2115. enumAuthMethod < ILS_NUM_OF_AUTH_METHODS)
  2116. {
  2117. m_ServerInfo.AuthMethod = enumAuthMethod;
  2118. hr = S_OK;
  2119. }
  2120. else
  2121. {
  2122. hr = ILS_E_PARAMETER;
  2123. }
  2124. return hr;
  2125. }
  2126. STDMETHODIMP CIlsServer::
  2127. SetLogonName ( BSTR bstrLogonName )
  2128. {
  2129. // Make sure the filter string is valid
  2130. //
  2131. if (bstrLogonName == NULL)
  2132. return ILS_E_POINTER;
  2133. // Convert a bstr to an ansi string
  2134. //
  2135. TCHAR *psz = NULL;
  2136. HRESULT hr = ::BSTR_to_LPTSTR (&psz, bstrLogonName);
  2137. if (hr == S_OK)
  2138. {
  2139. // Free the old string
  2140. //
  2141. ::MemFree (m_ServerInfo.pszLogonName);
  2142. // Keep the new string
  2143. //
  2144. m_ServerInfo.pszLogonName = psz;
  2145. }
  2146. return hr;
  2147. }
  2148. STDMETHODIMP CIlsServer::
  2149. SetLogonPassword ( BSTR bstrLogonPassword )
  2150. {
  2151. // Make sure the filter string is valid
  2152. //
  2153. if (bstrLogonPassword == NULL)
  2154. return ILS_E_POINTER;
  2155. // Convert a bstr to an ansi string
  2156. //
  2157. TCHAR *psz = NULL;
  2158. HRESULT hr = ::BSTR_to_LPTSTR (&psz, bstrLogonPassword);
  2159. if (hr == S_OK)
  2160. {
  2161. // Free the old string
  2162. //
  2163. ::MemFree (m_ServerInfo.pszLogonPassword);
  2164. // Keep the new string
  2165. //
  2166. m_ServerInfo.pszLogonPassword = psz;
  2167. }
  2168. return hr;
  2169. }
  2170. STDMETHODIMP CIlsServer::
  2171. SetDomain ( BSTR bstrDomain )
  2172. {
  2173. // Make sure the filter string is valid
  2174. //
  2175. if (bstrDomain == NULL)
  2176. return ILS_E_POINTER;
  2177. // Convert a bstr to an ansi string
  2178. //
  2179. TCHAR *psz = NULL;
  2180. HRESULT hr = ::BSTR_to_LPTSTR (&psz, bstrDomain);
  2181. if (hr == S_OK)
  2182. {
  2183. // Free the old string
  2184. //
  2185. ::MemFree (m_ServerInfo.pszDomain);
  2186. // Keep the new string
  2187. //
  2188. m_ServerInfo.pszDomain = psz;
  2189. }
  2190. return hr;
  2191. }
  2192. STDMETHODIMP CIlsServer::
  2193. SetCredential ( BSTR bstrCredential )
  2194. {
  2195. // Make sure the filter string is valid
  2196. //
  2197. if (bstrCredential == NULL)
  2198. return ILS_E_POINTER;
  2199. // Convert a bstr to an ansi string
  2200. //
  2201. TCHAR *psz = NULL;
  2202. HRESULT hr = ::BSTR_to_LPTSTR (&psz, bstrCredential);
  2203. if (hr == S_OK)
  2204. {
  2205. // Free the old string
  2206. //
  2207. ::MemFree (m_ServerInfo.pszCredential);
  2208. // Keep the new string
  2209. //
  2210. m_ServerInfo.pszCredential = psz;
  2211. }
  2212. return hr;
  2213. }
  2214. STDMETHODIMP CIlsServer::
  2215. SetTimeout ( ULONG uTimeoutInSecond )
  2216. {
  2217. m_ServerInfo.uTimeoutInSecond = uTimeoutInSecond;
  2218. return S_OK;
  2219. }
  2220. STDMETHODIMP CIlsServer::
  2221. SetBaseDN ( BSTR bstrBaseDN )
  2222. {
  2223. // Make sure the filter string is valid
  2224. //
  2225. if (bstrBaseDN == NULL)
  2226. return ILS_E_POINTER;
  2227. // Convert a bstr to an ansi string
  2228. //
  2229. TCHAR *psz = NULL;
  2230. HRESULT hr = ::BSTR_to_LPTSTR (&psz, bstrBaseDN);
  2231. if (hr == S_OK)
  2232. {
  2233. // Free the old string
  2234. //
  2235. ::MemFree (m_ServerInfo.pszBaseDN);
  2236. // Keep the new string
  2237. //
  2238. m_ServerInfo.pszBaseDN = psz;
  2239. }
  2240. return hr;
  2241. }
  2242. HRESULT CIlsServer::
  2243. SetServerName ( TCHAR *pszServerName )
  2244. {
  2245. // Make sure the filter string is valid
  2246. //
  2247. if (pszServerName == NULL)
  2248. return ILS_E_POINTER;
  2249. // duplicate the server name
  2250. //
  2251. HRESULT hr;
  2252. TCHAR *psz = ::My_strdup (pszServerName);
  2253. if (psz != NULL)
  2254. {
  2255. if (MyIsGoodString (psz))
  2256. {
  2257. // Free the old string
  2258. //
  2259. ::MemFree (m_ServerInfo.pszServerName);
  2260. // Keep the new string
  2261. //
  2262. m_ServerInfo.pszServerName = psz;
  2263. hr = S_OK;
  2264. }
  2265. else
  2266. {
  2267. ::MemFree (psz);
  2268. psz = NULL;
  2269. hr = ILS_E_PARAMETER;
  2270. }
  2271. }
  2272. else
  2273. {
  2274. hr = ILS_E_MEMORY;
  2275. }
  2276. return hr;
  2277. }
  2278. HRESULT CIlsServer::
  2279. SetServerName ( BSTR bstrServerName )
  2280. {
  2281. // Make sure the filter string is valid
  2282. //
  2283. if (bstrServerName == NULL)
  2284. return ILS_E_POINTER;
  2285. // Convert a bstr to an ansi string
  2286. //
  2287. TCHAR *psz = NULL;
  2288. HRESULT hr = ::BSTR_to_LPTSTR (&psz, bstrServerName);
  2289. if (hr == S_OK)
  2290. {
  2291. if (MyIsGoodString (psz))
  2292. {
  2293. // Free the old string
  2294. //
  2295. ::MemFree (m_ServerInfo.pszServerName);
  2296. // Keep the new string
  2297. //
  2298. m_ServerInfo.pszServerName = psz;
  2299. }
  2300. else
  2301. {
  2302. ::MemFree (psz);
  2303. psz = NULL;
  2304. hr = ILS_E_PARAMETER;
  2305. }
  2306. }
  2307. return ((psz != NULL) ? S_OK : ILS_E_MEMORY);
  2308. }
  2309. TCHAR *CIlsServer::
  2310. DuplicateServerName ( VOID )
  2311. {
  2312. return My_strdup (m_ServerInfo.pszServerName);
  2313. }
  2314. BSTR CIlsServer::
  2315. DuplicateServerNameBSTR ( VOID )
  2316. {
  2317. BSTR bstr = NULL;
  2318. TCHAR *psz = DuplicateServerName ();
  2319. if (psz != NULL)
  2320. {
  2321. LPTSTR_to_BSTR (&bstr, psz);
  2322. }
  2323. return bstr;
  2324. }
  2325. CIlsServer *CIlsServer::
  2326. Clone ( VOID )
  2327. {
  2328. CIlsServer *p = new CIlsServer;
  2329. if (p != NULL)
  2330. {
  2331. if (::IlsCopyServerInfo (p->GetServerInfo (), GetServerInfo ()) == S_OK)
  2332. {
  2333. p->AddRef ();
  2334. }
  2335. else
  2336. {
  2337. ::IlsFreeServerInfo (p->GetServerInfo ());
  2338. ::MemFree (p);
  2339. p = NULL;
  2340. }
  2341. }
  2342. return p;
  2343. }