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.

3088 lines
73 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: localusr.cpp
  5. // Content: This file contains the LocalUser 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 "localusr.h"
  14. #include "localprt.h"
  15. #include "callback.h"
  16. #include "attribs.h"
  17. #include "culs.h"
  18. #define DEFAULT_COUNTRY _T("-")
  19. #ifdef OLD
  20. //****************************************************************************
  21. // Registry keys and values - defined in ULSREG.H
  22. //****************************************************************************
  23. #define REGSTR_ILS_CLIENT_KEY ILS_REGISTRY TEXT("\\") ILS_REGFLD_CLIENT
  24. #define REGSTR_ILS_FIRSTNAME_VALUE ILS_REGKEY_FIRST_NAME
  25. #define REGSTR_ILS_LASTNAME_VALUE ILS_REGKEY_LAST_NAME
  26. #define REGSTR_ILS_EMAIL_VALUE ILS_REGKEY_EMAIL_NAME
  27. #define REGSTR_ILS_CITY_VALUE ILS_REGKEY_CITY
  28. #define REGSTR_ILS_COUNTRY_VALUE ILS_REGKEY_COUNTRY
  29. #define REGSTR_ILS_COMMENT_VALUE ILS_REGKEY_COMMENTS
  30. #define REGSTR_ILS_FLAGS_VALUE ILS_REGKEY_DONT_PUBLISH
  31. #endif //OLD
  32. #ifdef TEST
  33. _cdecl main()
  34. {
  35. return (0);
  36. }
  37. #endif //TEST
  38. //****************************************************************************
  39. // HRESULT
  40. // OnNotifyRegisterResult (IUnknown *pUnk, void *pv)
  41. //
  42. // History:
  43. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  44. // Created.
  45. //****************************************************************************
  46. HRESULT
  47. OnNotifyRegisterResult (IUnknown *pUnk, void *pv)
  48. {
  49. PSRINFO psri = (PSRINFO)pv;
  50. ((IIlsUserNotify*)pUnk)->RegisterResult(psri->uReqID, psri->hResult);
  51. return S_OK;
  52. }
  53. //****************************************************************************
  54. // HRESULT
  55. // OnNotifyUpdateUserResult (IUnknown *pUnk, void *pv)
  56. //
  57. // History:
  58. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  59. // Created.
  60. //****************************************************************************
  61. HRESULT
  62. OnNotifyUpdateResult (IUnknown *pUnk, void *pv)
  63. {
  64. PSRINFO psri = (PSRINFO)pv;
  65. ((IIlsUserNotify*)pUnk)->UpdateResult(psri->uReqID, psri->hResult);
  66. return S_OK;
  67. }
  68. //****************************************************************************
  69. // HRESULT
  70. // OnNotifyProtocolChangeResult (IUnknown *pUnk, void *pv)
  71. //
  72. // History:
  73. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  74. // Created.
  75. //****************************************************************************
  76. HRESULT
  77. OnNotifyProtocolChangeResult (IUnknown *pUnk, void *pv)
  78. {
  79. PSRINFO psri = (PSRINFO)pv;
  80. ((IIlsUserNotify*)pUnk)->ProtocolChangeResult(psri->uReqID,
  81. psri->hResult);
  82. return S_OK;
  83. }
  84. //****************************************************************************
  85. // HRESULT
  86. // OnNotifyGetProtocolResult (IUnknown *pUnk, void *pv)
  87. //
  88. // History:
  89. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  90. // Created.
  91. //****************************************************************************
  92. HRESULT
  93. OnNotifyGetProtocolResult (IUnknown *pUnk, void *pv)
  94. {
  95. POBJRINFO pobjri = (POBJRINFO)pv;
  96. ((IIlsUserNotify*)pUnk)->GetProtocolResult(pobjri->uReqID,
  97. (IIlsProtocol *)pobjri->pv,
  98. pobjri->hResult);
  99. return S_OK;
  100. }
  101. //****************************************************************************
  102. // HRESULT
  103. // OnNotifyEnumProtocolsResult (IUnknown *pUnk, void *pv)
  104. //
  105. // History:
  106. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  107. // Created.
  108. //****************************************************************************
  109. HRESULT
  110. OnNotifyEnumProtocolsResult (IUnknown *pUnk, void *pv)
  111. {
  112. CEnumNames *penum = NULL;
  113. PENUMRINFO peri = (PENUMRINFO)pv;
  114. HRESULT hr = peri->hResult;
  115. if (SUCCEEDED(hr))
  116. {
  117. penum = new CEnumNames;
  118. if (penum != NULL)
  119. {
  120. hr = penum->Init((LPTSTR)peri->pv, peri->cItems);
  121. if (SUCCEEDED(hr))
  122. {
  123. penum->AddRef();
  124. }
  125. else
  126. {
  127. delete penum;
  128. penum = NULL;
  129. };
  130. }
  131. else
  132. {
  133. hr = ILS_E_MEMORY;
  134. };
  135. };
  136. // Notify the sink object
  137. //
  138. ((IIlsUserNotify*)pUnk)->EnumProtocolsResult(peri->uReqID,
  139. penum != NULL ?
  140. (IEnumIlsNames *)penum :
  141. NULL,
  142. hr);
  143. if (penum != NULL)
  144. {
  145. penum->Release();
  146. };
  147. return hr;
  148. }
  149. #ifdef MAYBE
  150. //****************************************************************************
  151. // HRESULT
  152. // OnNotifyStateChanged ( IUnknown *pUnk, LONG State, VOID *pv )
  153. //
  154. // History:
  155. // Thu 07-Nov-1996 13:05:00 -by- Chu, Lon-Chan [lonchanc]
  156. // Created.
  157. //****************************************************************************
  158. HRESULT
  159. CIlsUser::OnNotifyStateChanged ( IUnknown *pUnk, LONG State, BSTR bstrServerName, BOOL fPrimary )
  160. {
  161. // If the server object does not exist, not registered
  162. //
  163. if (m_pServer == NULL)
  164. return NOERROR;
  165. // Set server internal state
  166. //
  167. SetULSState ((ULSSVRSTATE) State);
  168. // Notify the app to logoff and re-logon
  169. // This app must NOT pop up an UI upon receiving this
  170. //
  171. ((IIlsUserNotify *) pUnk)->StateChanged (fPrimary, bstrServerName);
  172. return NOERROR;
  173. }
  174. #endif //MAYBE
  175. HRESULT
  176. OnNotifyStateChanged_UI_NoSuchObject ( IUnknown *pUnk, VOID *pv )
  177. {
  178. return ((IIlsUserNotify *)pUnk)->StateChanged (TRUE, (BSTR) pv);
  179. }
  180. HRESULT
  181. OnNotifyStateChanged_NoUI_NoSuchObject ( IUnknown *pUnk, VOID *pv )
  182. {
  183. return ((IIlsUserNotify *)pUnk)->StateChanged (FALSE, (BSTR) pv);
  184. }
  185. HRESULT
  186. OnNotifyStateChanged_UI_NetworkDown ( IUnknown *pUnk, VOID *pv )
  187. {
  188. return ((IIlsUserNotify *)pUnk)->StateChanged (TRUE, (BSTR) pv);
  189. }
  190. HRESULT
  191. OnNotifyStateChanged_NoUI_NetworkDown ( IUnknown *pUnk, VOID *pv )
  192. {
  193. return ((IIlsUserNotify *)pUnk)->StateChanged (FALSE, (BSTR) pv);
  194. }
  195. //****************************************************************************
  196. // STDMETHODIMP
  197. // CIlsUser::ProtocolChangeResult ( IIlsProtocol *pProtocol, ULONG uReqID, HRESULT hResult,
  198. // APP_CHANGE_PROT uCmd)
  199. //
  200. //****************************************************************************
  201. STDMETHODIMP
  202. CIlsUser::ProtocolChangeResult ( IIlsProtocol *pProtocol, ULONG uReqID, HRESULT hResult,
  203. APP_CHANGE_PROT uCmd)
  204. {
  205. SRINFO sri;
  206. // If the server accepts the changes, modify the local information
  207. //
  208. if (FAILED (hResult))
  209. {
  210. // Update based on the command.
  211. //
  212. switch(uCmd)
  213. {
  214. case ILS_APP_ADD_PROT:
  215. m_ProtList.Remove ((CLocalProt *) pProtocol);
  216. pProtocol->Release (); // AddRef by RegisterLocalProtocol
  217. break;
  218. case ILS_APP_REMOVE_PROT:
  219. // Release already by UnregisterLocalProtocol
  220. break;
  221. default:
  222. ASSERT(0);
  223. break;
  224. };
  225. }
  226. if (uReqID) {
  227. // Notify the sink object
  228. //
  229. sri.uReqID = uReqID;
  230. sri.hResult = hResult;
  231. hResult = NotifySink((void *)&sri, OnNotifyProtocolChangeResult);
  232. }
  233. #ifdef DEBUG
  234. DPRINTF (TEXT("CIlsUser--current Protocols********************\r\n"));
  235. DPRINTF (TEXT("\r\n*************************************************"));
  236. #endif // DEBUG;
  237. return hResult;
  238. }
  239. //****************************************************************************
  240. // CIlsUser::CIlsUser (HANDLE hMutex)
  241. //
  242. // History:
  243. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  244. // Created.
  245. //****************************************************************************
  246. CIlsUser::CIlsUser ()
  247. :
  248. m_cRef (0),
  249. // user
  250. m_fReadonly (FALSE),
  251. m_uModify (LU_MOD_NONE),
  252. m_cLock (0),
  253. m_szID (NULL),
  254. m_szFirstName (NULL),
  255. m_szLastName (NULL),
  256. m_szEMailName (NULL),
  257. m_szCityName (NULL),
  258. m_szCountryName (NULL),
  259. m_szComment (NULL),
  260. m_dwFlags (1), // default is visible
  261. m_szIPAddr (NULL),
  262. m_szAppName (NULL),
  263. m_szMimeType (NULL),
  264. m_pIlsServer (NULL),
  265. m_pConnPt (NULL),
  266. // server
  267. m_uState (ULSSVR_INVALID),
  268. m_hLdapUser (NULL),
  269. m_pep (NULL),
  270. m_uReqID (0),
  271. m_uLastMsgID (0)
  272. {
  273. m_guid = GUID_NULL;
  274. m_ExtendedAttrs.SetAccessType (ILS_ATTRTYPE_NAME_VALUE);
  275. // m_szCountryName can't be a NULL string... see notes on NetMeeting 3.0 Bug 1643 for the reason why...
  276. m_szCountryName = static_cast<LPTSTR>(MemAlloc( lstrlen( DEFAULT_COUNTRY ) + sizeof(TCHAR) ));
  277. lstrcpy( m_szCountryName, DEFAULT_COUNTRY );
  278. }
  279. //****************************************************************************
  280. // CIlsUser::~CIlsUser (void)
  281. //
  282. // History:
  283. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  284. // Created.
  285. //****************************************************************************
  286. CIlsUser::~CIlsUser (void)
  287. {
  288. /* ------ server ------ */
  289. // Unregister everything, including protocols
  290. //
  291. InternalCleanupRegistration(FALSE);
  292. // We expect someone explicitly unregister this
  293. //
  294. ASSERT ((m_uState == ULSSVR_INVALID) || (m_uState == ULSSVR_INIT));
  295. ASSERT (m_hLdapUser == NULL);
  296. ASSERT (m_pep == NULL);
  297. ASSERT (m_uReqID == 0);
  298. ASSERT (m_uLastMsgID == 0);
  299. /* ------ user ------ */
  300. ::MemFree (m_szID);
  301. ::MemFree (m_szFirstName);
  302. ::MemFree (m_szLastName);
  303. ::MemFree (m_szEMailName);
  304. ::MemFree (m_szCityName);
  305. ::MemFree (m_szCountryName);
  306. ::MemFree (m_szComment);
  307. ::MemFree (m_szIPAddr);
  308. // Release the protocol objects
  309. //
  310. CLocalProt *plp = NULL;
  311. HANDLE hEnum = NULL;
  312. m_ProtList.Enumerate(&hEnum);
  313. while(m_ProtList.Next (&hEnum, (PVOID *)&plp) == NOERROR)
  314. {
  315. plp->Release(); // AddRef by RegisterLocalProtocol or UpdateProtocol
  316. }
  317. m_ProtList.Flush();
  318. // Release the buffer resources
  319. //
  320. ::MemFree (m_szAppName);
  321. ::MemFree (m_szMimeType);
  322. // Release the connection point
  323. //
  324. if (m_pConnPt != NULL)
  325. {
  326. m_pConnPt->ContainerReleased();
  327. ((IConnectionPoint*)m_pConnPt)->Release();
  328. };
  329. // Free server object
  330. //
  331. if (m_pIlsServer != NULL)
  332. m_pIlsServer->Release ();
  333. }
  334. //****************************************************************************
  335. // STDMETHODIMP
  336. // CIlsUser::Clone
  337. //
  338. // History:
  339. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  340. // Created.
  341. //****************************************************************************
  342. STDMETHODIMP CIlsUser::
  343. Clone ( IIlsUser **ppUser )
  344. {
  345. if (ppUser == NULL)
  346. return ILS_E_POINTER;
  347. // Create a new user object
  348. //
  349. CIlsUser *p = new CIlsUser;
  350. if (p == NULL)
  351. return ILS_E_MEMORY;
  352. // Snap-shot the user information now
  353. //
  354. LDAP_CLIENTINFO *pci = NULL;
  355. HRESULT hr = InternalGetUserInfo (TRUE, &pci, LU_MOD_ALL);
  356. if (SUCCEEDED (hr))
  357. {
  358. // Fake the size to make it consistent with what Init() wants
  359. //
  360. pci->uSize = sizeof (*pci);
  361. // Unpack the user information
  362. //
  363. hr = p->Init (NULL, pci);
  364. }
  365. if (FAILED (hr))
  366. {
  367. delete p;
  368. p = NULL;
  369. }
  370. p->AddRef ();
  371. p->m_fReadonly = FALSE;
  372. p->m_uState = ULSSVR_INIT;
  373. *ppUser = (IIlsUser *) p;
  374. return hr;
  375. }
  376. //****************************************************************************
  377. // STDMETHODIMP
  378. // CIlsUser::Init (BSTR bstrUserID, BSTR bstrAppName)
  379. //
  380. // History:
  381. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  382. // Created.
  383. //****************************************************************************
  384. STDMETHODIMP
  385. CIlsUser::Init (BSTR bstrUserID, BSTR bstrAppName)
  386. {
  387. HRESULT hr;
  388. ASSERT(!m_szID && !m_szAppName);
  389. if (!bstrUserID || !bstrAppName) {
  390. return (ILS_E_PARAMETER);
  391. }
  392. hr = BSTR_to_LPTSTR(&m_szID, bstrUserID);
  393. if (FAILED(hr)) {
  394. m_szID = NULL; // set it to NULL for safety
  395. return (hr);
  396. }
  397. hr = BSTR_to_LPTSTR(&m_szAppName, bstrAppName);
  398. if (SUCCEEDED(hr))
  399. {
  400. // Make the connection point
  401. //
  402. m_pConnPt = new CConnectionPoint (&IID_IIlsUserNotify,
  403. (IConnectionPointContainer *)this);
  404. if (m_pConnPt != NULL)
  405. {
  406. ((IConnectionPoint*)m_pConnPt)->AddRef();
  407. hr = NOERROR;
  408. m_ExtendedAttrs.SetAccessType (ILS_ATTRTYPE_NAME_VALUE);
  409. }
  410. else
  411. {
  412. hr = ILS_E_MEMORY;
  413. };
  414. };
  415. if (FAILED(hr)) {
  416. ::MemFree (m_szID);
  417. ::MemFree (m_szAppName);
  418. m_szID = m_szAppName = NULL;
  419. return hr;
  420. }
  421. return NOERROR;
  422. }
  423. //****************************************************************************
  424. // STDMETHODIMP
  425. // CIlsUser::Init (LPTSTR szServerName, PLDAP_CLIENTINFO *pui)
  426. //
  427. // History:
  428. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  429. // Created.
  430. //****************************************************************************
  431. STDMETHODIMP
  432. CIlsUser::Init (CIlsServer *pIlsServer, PLDAP_CLIENTINFO pui)
  433. {
  434. // Validate parameter
  435. //
  436. if ((pui->uSize != sizeof(*pui)) ||
  437. (pui->uOffsetCN == 0) /*||
  438. (pui->uOffsetAppName == 0)*/
  439. )
  440. {
  441. return ILS_E_PARAMETER;
  442. };
  443. // Remember the server if necessary
  444. //
  445. if (pIlsServer != NULL)
  446. {
  447. pIlsServer->AddRef ();
  448. }
  449. m_pIlsServer = pIlsServer;
  450. // Allocate strings
  451. //
  452. BOOL fSuccess = SUCCEEDED (SetOffsetString (&m_szID, (BYTE *) pui, pui->uOffsetCN)) && (m_szID != NULL);
  453. fSuccess &= SUCCEEDED (SetOffsetString (&m_szAppName, (BYTE *) pui, pui->uOffsetAppName));
  454. fSuccess &= SUCCEEDED (SetOffsetString (&m_szFirstName, (BYTE *) pui, pui->uOffsetFirstName));
  455. fSuccess &= SUCCEEDED (SetOffsetString (&m_szLastName, (BYTE *) pui, pui->uOffsetLastName));
  456. fSuccess &= SUCCEEDED (SetOffsetString (&m_szEMailName, (BYTE *) pui, pui->uOffsetEMailName));
  457. fSuccess &= SUCCEEDED (SetOffsetString (&m_szCityName, (BYTE *) pui, pui->uOffsetCityName));
  458. fSuccess &= SUCCEEDED (SetOffsetString (&m_szCountryName, (BYTE *) pui, pui->uOffsetCountryName));
  459. fSuccess &= SUCCEEDED (SetOffsetString (&m_szComment, (BYTE *) pui, pui->uOffsetComment));
  460. fSuccess &= SUCCEEDED (SetOffsetString (&m_szIPAddr, (BYTE *) pui, pui->uOffsetIPAddress));
  461. fSuccess &= SUCCEEDED (SetOffsetString (&m_szMimeType, (BYTE *) pui, pui->uOffsetAppMimeType));
  462. HRESULT hr = fSuccess ? S_OK : ILS_E_MEMORY;
  463. if (SUCCEEDED(hr))
  464. {
  465. // Set non-allocation data
  466. //
  467. m_dwFlags = pui->dwFlags;
  468. m_guid = pui->AppGuid;
  469. // Set extended attributes
  470. //
  471. m_ExtendedAttrs.SetAccessType (ILS_ATTRTYPE_NAME_VALUE);
  472. if (pui->cAttrsReturned != 0)
  473. {
  474. hr = m_ExtendedAttrs.SetAttributePairs((LPTSTR)(((PBYTE)pui)+pui->uOffsetAttrsReturned),
  475. pui->cAttrsReturned);
  476. }
  477. }
  478. if (SUCCEEDED(hr))
  479. {
  480. // Make the connection point
  481. //
  482. m_pConnPt = new CConnectionPoint (&IID_IIlsUserNotify,
  483. (IConnectionPointContainer *)this);
  484. if (m_pConnPt != NULL)
  485. {
  486. ((IConnectionPoint*)m_pConnPt)->AddRef();
  487. hr = NOERROR;
  488. m_fReadonly = TRUE;
  489. }
  490. else
  491. {
  492. hr = ILS_E_MEMORY;
  493. };
  494. };
  495. // cleanup is done in destructor
  496. return hr;
  497. }
  498. //****************************************************************************
  499. // STDMETHODIMP
  500. // CIlsUser::IsWritable (BOOL *pfWriteable)
  501. //
  502. //****************************************************************************
  503. STDMETHODIMP
  504. CIlsUser::IsWritable(BOOL *pfWriteable)
  505. {
  506. HRESULT hr;
  507. if (pfWriteable != NULL)
  508. {
  509. *pfWriteable = !m_fReadonly;
  510. hr = S_OK;
  511. }
  512. else
  513. {
  514. hr = ILS_E_POINTER;
  515. }
  516. return hr;
  517. }
  518. //****************************************************************************
  519. // STDMETHODIMP
  520. // CIlsUser::QueryInterface (REFIID riid, void **ppv)
  521. //
  522. // History:
  523. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  524. // Created.
  525. //****************************************************************************
  526. STDMETHODIMP
  527. CIlsUser::QueryInterface (REFIID riid, void **ppv)
  528. {
  529. *ppv = NULL;
  530. if (riid == IID_IIlsUser || riid == IID_IUnknown)
  531. {
  532. *ppv = (IIlsUser *) this;
  533. }
  534. else
  535. {
  536. if (riid == IID_IConnectionPointContainer)
  537. {
  538. *ppv = (IConnectionPointContainer *) this;
  539. };
  540. }
  541. if (*ppv != NULL)
  542. {
  543. ((LPUNKNOWN)*ppv)->AddRef();
  544. return S_OK;
  545. }
  546. else
  547. {
  548. return ILS_E_NO_INTERFACE;
  549. };
  550. }
  551. //****************************************************************************
  552. // STDMETHODIMP_(ULONG)
  553. // CIlsUser::AddRef (void)
  554. //
  555. // History:
  556. // Wed 17-Apr-1996 11:14:17 -by- Viroon Touranachun [viroont]
  557. // Created.
  558. //****************************************************************************
  559. STDMETHODIMP_(ULONG)
  560. CIlsUser::AddRef (void)
  561. {
  562. DllLock();
  563. MyDebugMsg ((DM_REFCOUNT, "CIlsUser::AddRef: ref=%ld\r\n", m_cRef));
  564. ::InterlockedIncrement (&m_cRef);
  565. return (ULONG) m_cRef;
  566. }
  567. //****************************************************************************
  568. // STDMETHODIMP_(ULONG)
  569. // CIlsUser::Release (void)
  570. //
  571. // History:
  572. // Wed 17-Apr-1996 11:14:26 -by- Viroon Touranachun [viroont]
  573. // Created.
  574. //****************************************************************************
  575. STDMETHODIMP_(ULONG)
  576. CIlsUser::Release (void)
  577. {
  578. DllRelease();
  579. ASSERT (m_cRef > 0);
  580. MyDebugMsg ((DM_REFCOUNT, "CIlsUser::Release: ref=%ld\r\n", m_cRef));
  581. if (::InterlockedDecrement (&m_cRef) == 0)
  582. {
  583. delete this;
  584. return 0;
  585. }
  586. return (ULONG) m_cRef;
  587. }
  588. //****************************************************************************
  589. // STDMETHODIMP
  590. // CIlsUser::GetStandardAttribute (ILS_STD_ATTR_NAME stdAttr, BSTR *pbstrStdAttr)
  591. //
  592. // History:
  593. // 1-16-97 Shishir Pardikar
  594. // Created.
  595. //****************************************************************************
  596. STDMETHODIMP
  597. CIlsUser::GetStandardAttribute(
  598. ILS_STD_ATTR_NAME stdAttr,
  599. BSTR *pbstrStdAttr
  600. )
  601. {
  602. LPTSTR lpszAttr = NULL;
  603. BOOL fValid = TRUE;
  604. HRESULT hr;
  605. if (pbstrStdAttr == NULL) {
  606. return ILS_E_POINTER;
  607. }
  608. switch(stdAttr) {
  609. case ILS_STDATTR_USER_ID:
  610. lpszAttr = m_szID;
  611. break;
  612. case ILS_STDATTR_APP_NAME:
  613. lpszAttr = m_szAppName;
  614. break;
  615. case ILS_STDATTR_IP_ADDRESS:
  616. lpszAttr = m_szIPAddr;
  617. break;
  618. case ILS_STDATTR_EMAIL_NAME:
  619. lpszAttr = m_szEMailName;
  620. break;
  621. case ILS_STDATTR_FIRST_NAME:
  622. lpszAttr = m_szFirstName;
  623. break;
  624. case ILS_STDATTR_LAST_NAME:
  625. lpszAttr = m_szLastName;
  626. break;
  627. case ILS_STDATTR_CITY_NAME:
  628. lpszAttr = m_szCityName;
  629. break;
  630. case ILS_STDATTR_COUNTRY_NAME:
  631. lpszAttr = m_szCountryName;
  632. break;
  633. case ILS_STDATTR_COMMENT:
  634. lpszAttr = m_szComment;
  635. break;
  636. case ILS_STDATTR_APP_MIME_TYPE:
  637. lpszAttr = m_szMimeType;
  638. break;
  639. default:
  640. fValid = FALSE;
  641. break;
  642. }
  643. if (fValid) {
  644. if (lpszAttr){
  645. hr = LPTSTR_to_BSTR(pbstrStdAttr, lpszAttr);
  646. }
  647. else {
  648. *pbstrStdAttr = NULL;
  649. hr = NOERROR;
  650. }
  651. }
  652. else {
  653. hr = ILS_E_PARAMETER;
  654. }
  655. return (hr);
  656. }
  657. //****************************************************************************
  658. // STDMETHODIMP
  659. // CIlsUser::SetStandardAttribute (ILS_STD_ATTR_NAME stdAttr, BSTR bstrStdAttr)
  660. //
  661. // History:
  662. // 1-16-97 Shishir Pardikar
  663. // Created.
  664. //****************************************************************************
  665. STDMETHODIMP
  666. CIlsUser::SetStandardAttribute(
  667. ILS_STD_ATTR_NAME stdAttr,
  668. BSTR bstrStdAttr
  669. )
  670. {
  671. LPTSTR *ppszAttr = NULL, pszNewAttr;
  672. BOOL fValid = TRUE;
  673. ULONG ulModBit = 0;
  674. HRESULT hr;
  675. // It is ok to have a null bstrStdAttr
  676. //
  677. // Make sure this is not a read-only object
  678. //
  679. if (m_fReadonly)
  680. return ILS_E_ACCESS_DENIED;
  681. switch(stdAttr) {
  682. case ILS_STDATTR_IP_ADDRESS:
  683. ppszAttr = &m_szIPAddr;
  684. ulModBit = LU_MOD_IP_ADDRESS;
  685. break;
  686. case ILS_STDATTR_EMAIL_NAME:
  687. ppszAttr = &m_szEMailName;
  688. ulModBit = LU_MOD_EMAIL;
  689. break;
  690. case ILS_STDATTR_FIRST_NAME:
  691. ppszAttr = &m_szFirstName;
  692. ulModBit = LU_MOD_FIRSTNAME;
  693. break;
  694. case ILS_STDATTR_LAST_NAME:
  695. ppszAttr = &m_szLastName;
  696. ulModBit = LU_MOD_LASTNAME;
  697. break;
  698. case ILS_STDATTR_CITY_NAME:
  699. ppszAttr = &m_szCityName;
  700. ulModBit = LU_MOD_CITY;
  701. break;
  702. case ILS_STDATTR_COUNTRY_NAME:
  703. ppszAttr = &m_szCountryName;
  704. ulModBit = LU_MOD_COUNTRY;
  705. break;
  706. case ILS_STDATTR_COMMENT:
  707. ppszAttr = &m_szComment;
  708. ulModBit = LU_MOD_COMMENT;
  709. break;
  710. case ILS_STDATTR_APP_MIME_TYPE:
  711. ppszAttr = &m_szMimeType;
  712. ulModBit = LU_MOD_MIME;
  713. break;
  714. default:
  715. fValid = FALSE;
  716. break;
  717. }
  718. if (fValid) {
  719. pszNewAttr = NULL;
  720. if (bstrStdAttr == NULL || *bstrStdAttr == L'\0')
  721. {
  722. // pszNewAttr is null now
  723. //
  724. hr = S_OK;
  725. }
  726. else
  727. {
  728. // Duplicate the string
  729. //
  730. hr = BSTR_to_LPTSTR (&pszNewAttr, bstrStdAttr);
  731. }
  732. if (SUCCEEDED(hr))
  733. {
  734. ::MemFree (*ppszAttr);
  735. *ppszAttr = pszNewAttr;
  736. m_uModify |= ulModBit;
  737. }
  738. }
  739. else {
  740. hr = ILS_E_PARAMETER;
  741. }
  742. return (hr);
  743. }
  744. //****************************************************************************
  745. // STDMETHODIMP
  746. // CIlsUser::GetVisible ( DWORD *pfVisible )
  747. //
  748. // History:
  749. // Tue 05-Nov-1996 10:30:00 -by- Chu, Lon-Chan [lonchanc]
  750. // Created.
  751. //****************************************************************************
  752. STDMETHODIMP
  753. CIlsUser::GetVisible ( DWORD *pfVisible )
  754. {
  755. HRESULT hr = ILS_E_POINTER;
  756. if (pfVisible != NULL)
  757. {
  758. *pfVisible = m_dwFlags;
  759. hr = S_OK;
  760. }
  761. return hr;
  762. }
  763. //****************************************************************************
  764. // STDMETHODIMP
  765. // CIlsUser::SetVisible ( DWORD fVisible )
  766. //
  767. // History:
  768. // Tue 05-Nov-1996 10:30:00 -by- Chu, Lon-Chan [lonchanc]
  769. // Created.
  770. //****************************************************************************
  771. STDMETHODIMP
  772. CIlsUser::SetVisible ( DWORD fVisible )
  773. {
  774. // Make sure this is not a read-only object
  775. //
  776. if (m_fReadonly)
  777. return ILS_E_ACCESS_DENIED;
  778. m_dwFlags = fVisible;
  779. m_uModify |= LU_MOD_FLAGS;
  780. return S_OK;
  781. }
  782. //****************************************************************************
  783. // STDMETHODIMP
  784. // CIlsUser::GetGuid ( GUID *pGuid )
  785. //
  786. // History:
  787. // Tue 05-Nov-1996 10:30:00 -by- Chu, Lon-Chan [lonchanc]
  788. // Created.
  789. //****************************************************************************
  790. STDMETHODIMP
  791. CIlsUser::GetGuid ( GUID *pGuid )
  792. {
  793. HRESULT hr = ILS_E_POINTER;
  794. if (pGuid != NULL)
  795. {
  796. *pGuid = m_guid;
  797. hr = S_OK;
  798. }
  799. return hr;
  800. }
  801. //****************************************************************************
  802. // STDMETHODIMP
  803. // CIlsUser::SetGuid ( GUID *pGuid )
  804. //
  805. // History:
  806. // Tue 05-Nov-1996 10:30:00 -by- Chu, Lon-Chan [lonchanc]
  807. // Created.
  808. //****************************************************************************
  809. STDMETHODIMP
  810. CIlsUser::SetGuid ( GUID *pGuid )
  811. {
  812. // Make sure this is not a read-only object
  813. //
  814. if (m_fReadonly)
  815. return ILS_E_ACCESS_DENIED;
  816. HRESULT hr = ILS_E_POINTER;
  817. if (pGuid != NULL)
  818. {
  819. m_guid = *pGuid;
  820. m_uModify |= LU_MOD_GUID;
  821. hr = S_OK;
  822. }
  823. return hr;
  824. }
  825. //****************************************************************************
  826. // STDMETHODIMP
  827. // CIlsUser::InternalGetUserInfo (BOOL fAddNew, PLDAP_CLIENTINFO *ppUserInfo, ULONG uFields)
  828. //
  829. // History:
  830. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  831. // Created.
  832. //****************************************************************************
  833. STDMETHODIMP
  834. CIlsUser::InternalGetUserInfo (BOOL fAddNew, PLDAP_CLIENTINFO *ppUserInfo, ULONG uFields)
  835. {
  836. PLDAP_CLIENTINFO pui;
  837. ULONG cFName,
  838. cLName,
  839. cEName,
  840. cCity,
  841. cCountry,
  842. cComment;
  843. ULONG cName, cAppName, cMime;
  844. LPTSTR szAttrs;
  845. ULONG uOffsetDstAnyAttrs;
  846. ULONG cAttrs, cbAttrs;
  847. HRESULT hr;
  848. ULONG cchIPAddr;
  849. // Should not call this guy if nothing has been updated
  850. //
  851. ASSERT(uFields);
  852. // Assume failure
  853. //
  854. *ppUserInfo = NULL;
  855. // Calculate the buffer size
  856. //
  857. ASSERT(m_szID && m_szAppName);
  858. cName = lstrlen(m_szID)+1;
  859. cAppName = lstrlen(m_szAppName)+1;
  860. cFName = (((uFields & LU_MOD_FIRSTNAME) && m_szFirstName) ? lstrlen(m_szFirstName)+1 : 0);
  861. cLName = (((uFields & LU_MOD_LASTNAME) && m_szLastName) ? lstrlen(m_szLastName)+1 : 0);
  862. cEName = (((uFields & LU_MOD_EMAIL)&& m_szEMailName) ? lstrlen(m_szEMailName)+1 : 0);
  863. cCity = (((uFields & LU_MOD_CITY)&& m_szCityName) ? lstrlen(m_szCityName)+1 : 0);
  864. cCountry=(((uFields & LU_MOD_COUNTRY)&& m_szCountryName) ? lstrlen(m_szCountryName)+1 : 0);
  865. cComment=(((uFields & LU_MOD_COMMENT)&& m_szComment) ? lstrlen(m_szComment)+1 : 0);
  866. cMime = (((uFields & LU_MOD_MIME)&&m_szMimeType) ? lstrlen(m_szMimeType)+1 : 0);
  867. cchIPAddr = (((uFields & LU_MOD_IP_ADDRESS) && m_szIPAddr != NULL) ? lstrlen(m_szIPAddr)+1 : 0);
  868. if (uFields & LU_MOD_ATTRIB) {
  869. // Get the attribute pairs
  870. //
  871. hr = m_ExtendedAttrs.GetAttributePairs(&szAttrs, &cAttrs, &cbAttrs);
  872. if (FAILED(hr))
  873. {
  874. return hr;
  875. };
  876. }
  877. else {
  878. cAttrs = 0;
  879. cbAttrs = 0;
  880. szAttrs = NULL;
  881. }
  882. uOffsetDstAnyAttrs = 0;
  883. // Allocate the buffer
  884. //
  885. ULONG cbTotalSize = sizeof (LDAP_CLIENTINFO) +
  886. (cName + cAppName + cFName + cLName + cEName + cchIPAddr +
  887. cCity + cCountry + cComment + cMime+cbAttrs) * sizeof (TCHAR);
  888. pui = (PLDAP_CLIENTINFO) ::MemAlloc (cbTotalSize);
  889. if (pui == NULL)
  890. {
  891. hr = ILS_E_MEMORY;
  892. goto bailout;
  893. };
  894. // Fill the structure content
  895. //
  896. pui->uSize = cbTotalSize;
  897. pui->uOffsetCN = sizeof(*pui);
  898. pui->uOffsetAppName = pui->uOffsetCN + (cName*sizeof(TCHAR));
  899. pui->uOffsetFirstName = pui->uOffsetAppName + (cAppName*sizeof(TCHAR));
  900. pui->uOffsetLastName = pui->uOffsetFirstName + (cFName*sizeof(TCHAR));
  901. pui->uOffsetEMailName = pui->uOffsetLastName + (cLName*sizeof(TCHAR));
  902. pui->uOffsetCityName = pui->uOffsetEMailName + (cEName*sizeof(TCHAR));
  903. pui->uOffsetCountryName = pui->uOffsetCityName + (cCity*sizeof(TCHAR));
  904. pui->uOffsetComment = pui->uOffsetCountryName + (cCountry*sizeof(TCHAR));
  905. pui->uOffsetIPAddress = pui->uOffsetComment + (cComment * sizeof (TCHAR));
  906. pui->uOffsetAppMimeType = pui->uOffsetIPAddress + (cchIPAddr * sizeof(TCHAR));
  907. pui->dwFlags = m_dwFlags;
  908. pui->AppGuid = m_guid;
  909. // Fill in extended attributes
  910. //
  911. uOffsetDstAnyAttrs = (cAttrs != 0) ?
  912. pui->uOffsetAppMimeType + (cMime*sizeof(TCHAR)) :
  913. 0;
  914. if (fAddNew)
  915. {
  916. pui->cAttrsToAdd = cAttrs;
  917. pui->uOffsetAttrsToAdd = uOffsetDstAnyAttrs;
  918. }
  919. else
  920. {
  921. pui->cAttrsToModify = cAttrs;
  922. pui->uOffsetAttrsToModify = uOffsetDstAnyAttrs;
  923. }
  924. // Copy the user information
  925. //
  926. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetCN), m_szID);
  927. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetAppName), m_szAppName);
  928. if ((uFields & LU_MOD_FIRSTNAME)&&m_szFirstName)
  929. {
  930. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetFirstName), m_szFirstName);
  931. }
  932. else
  933. {
  934. pui->uOffsetFirstName = 0;
  935. };
  936. if ((uFields & LU_MOD_LASTNAME)&&m_szLastName)
  937. {
  938. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetLastName), m_szLastName);
  939. }
  940. else
  941. {
  942. pui->uOffsetLastName = 0;
  943. };
  944. if ((uFields & LU_MOD_EMAIL)&&m_szEMailName)
  945. {
  946. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetEMailName), m_szEMailName);
  947. }
  948. else
  949. {
  950. pui->uOffsetEMailName = 0;
  951. };
  952. if ((uFields & LU_MOD_CITY)&&m_szCityName)
  953. {
  954. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetCityName), m_szCityName);
  955. }
  956. else
  957. {
  958. pui->uOffsetCityName = 0;
  959. };
  960. if ((uFields & LU_MOD_COUNTRY)&&m_szCountryName)
  961. {
  962. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetCountryName), m_szCountryName);
  963. }
  964. else
  965. {
  966. pui->uOffsetCountryName = 0;
  967. };
  968. if ((uFields & LU_MOD_COMMENT)&&m_szComment)
  969. {
  970. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetComment), m_szComment);
  971. }
  972. else
  973. {
  974. pui->uOffsetComment = 0;
  975. };
  976. if ((uFields & LU_MOD_MIME)&&m_szMimeType)
  977. {
  978. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetAppMimeType), m_szMimeType);
  979. }
  980. else
  981. {
  982. pui->uOffsetAppMimeType = 0;
  983. }
  984. if ((uFields & LU_MOD_IP_ADDRESS) && m_szIPAddr != NULL)
  985. {
  986. lstrcpy((LPTSTR)(((PBYTE)pui)+pui->uOffsetIPAddress), m_szIPAddr);
  987. }
  988. else
  989. {
  990. pui->uOffsetIPAddress = 0;
  991. }
  992. if (cAttrs)
  993. {
  994. CopyMemory(((PBYTE)pui) + uOffsetDstAnyAttrs, szAttrs, cbAttrs);
  995. };
  996. // Return the structure
  997. //
  998. *ppUserInfo = pui;
  999. hr = NOERROR;
  1000. bailout:
  1001. if (szAttrs != NULL)
  1002. {
  1003. ::MemFree (szAttrs);
  1004. };
  1005. return hr;
  1006. }
  1007. //****************************************************************************
  1008. // STDMETHODIMP
  1009. // CIlsUser::Register (BSTR bstrServerName, ULONG *puReqID)
  1010. //
  1011. // History:
  1012. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1013. // Created.
  1014. //****************************************************************************
  1015. STDMETHODIMP CIlsUser::
  1016. Register (
  1017. IIlsServer *pIlsServer,
  1018. ULONG *puReqID)
  1019. {
  1020. HRESULT hr;
  1021. // Make sure it is not registered
  1022. //
  1023. if (GetULSState () != ILS_UNREGISTERED)
  1024. return ILS_E_ALREADY_REGISTERED;
  1025. // Validate parameter
  1026. //
  1027. if (::MyIsBadServer (pIlsServer) || puReqID == NULL)
  1028. return ILS_E_POINTER;
  1029. // Make sure this is not a read-only object
  1030. //
  1031. if (m_fReadonly)
  1032. return ILS_E_ACCESS_DENIED;
  1033. // Clone the server object
  1034. //
  1035. pIlsServer = ((CIlsServer *) pIlsServer)->Clone ();
  1036. if (pIlsServer == NULL)
  1037. return ILS_E_MEMORY;
  1038. // Free the old server object if necessary
  1039. //
  1040. if (m_pIlsServer != NULL)
  1041. m_pIlsServer->Release ();
  1042. // Keep the new server object
  1043. //
  1044. m_pIlsServer = (CIlsServer *) pIlsServer;
  1045. // Initialize the state
  1046. //
  1047. m_uState = ULSSVR_INIT;
  1048. // Prepare the asynchronous request
  1049. //
  1050. COM_REQ_INFO ri;
  1051. ReqInfo_Init (&ri);
  1052. ri.uReqType = WM_ILS_LOCAL_REGISTER;
  1053. ri.uMsgID = 0;
  1054. ReqInfo_SetUser (&ri, this);
  1055. // Enter the request
  1056. //
  1057. hr = g_pReqMgr->NewRequest(&ri);
  1058. if (SUCCEEDED(hr))
  1059. {
  1060. // Make sure the objects do not disappear before we get the response
  1061. //
  1062. this->AddRef();
  1063. // Register the client
  1064. //
  1065. hr = InternalRegister (ri.uReqID);
  1066. if (SUCCEEDED(hr))
  1067. {
  1068. Lock();
  1069. *puReqID = ri.uReqID;
  1070. }
  1071. else
  1072. {
  1073. // Clean up the async pending request
  1074. //
  1075. this->Release();
  1076. g_pReqMgr->RequestDone(&ri);
  1077. };
  1078. };
  1079. return hr;
  1080. }
  1081. //****************************************************************************
  1082. // STDMETHODIMP
  1083. // CIlsUser::RegisterResult (ULONG uReqID, HRESULT hResult)
  1084. //
  1085. // History:
  1086. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1087. // Created.
  1088. //****************************************************************************
  1089. STDMETHODIMP
  1090. CIlsUser::RegisterResult (ULONG uReqID, HRESULT hResult)
  1091. {
  1092. SRINFO sri;
  1093. Unlock();
  1094. // Notify the sink object
  1095. //
  1096. sri.uReqID = uReqID;
  1097. sri.hResult = hResult;
  1098. if (hResult == S_OK)
  1099. {
  1100. m_uModify = LU_MOD_NONE;
  1101. }
  1102. hResult = NotifySink((void *)&sri, OnNotifyRegisterResult);
  1103. return hResult;
  1104. }
  1105. //****************************************************************************
  1106. // STDMETHODIMP
  1107. // CIlsUser::Unregister (BSTR bstrServerName, ULONG *puReqID)
  1108. //
  1109. // History:
  1110. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1111. // Created.
  1112. //****************************************************************************
  1113. STDMETHODIMP CIlsUser::
  1114. Unregister ( ULONG *puReqID )
  1115. {
  1116. HRESULT hr;
  1117. // Make sure it is registered somehow (network down, need relogon, or registered)
  1118. //
  1119. if (GetULSState () == ILS_UNREGISTERED)
  1120. return ILS_E_NOT_REGISTERED;
  1121. // Make sure this is not a read-only object
  1122. //
  1123. if (m_fReadonly)
  1124. return ILS_E_ACCESS_DENIED;
  1125. // If puReqID is null, do it synchronously
  1126. //
  1127. if (puReqID == NULL)
  1128. {
  1129. hr = InternalCleanupRegistration (TRUE);
  1130. }
  1131. else
  1132. {
  1133. // Prepare the asynchronous request
  1134. //
  1135. COM_REQ_INFO ri;
  1136. ReqInfo_Init (&ri);
  1137. ri.uReqType = WM_ILS_LOCAL_UNREGISTER;
  1138. ri.uMsgID = 0;
  1139. ReqInfo_SetUser (&ri, this);
  1140. // Enter new request
  1141. //
  1142. hr = g_pReqMgr->NewRequest(&ri);
  1143. if (SUCCEEDED(hr))
  1144. {
  1145. // Make sure the objects do not disappear before we get the response
  1146. //
  1147. this->AddRef();
  1148. // Unregister the application
  1149. //
  1150. hr = InternalUnregister (ri.uReqID);
  1151. if (SUCCEEDED(hr))
  1152. {
  1153. Lock();
  1154. *puReqID = ri.uReqID;
  1155. }
  1156. else
  1157. {
  1158. // Clean up the async pending request
  1159. //
  1160. this->Release();
  1161. g_pReqMgr->RequestDone(&ri);
  1162. };
  1163. };
  1164. }
  1165. return hr;
  1166. }
  1167. //****************************************************************************
  1168. // STDMETHODIMP
  1169. // CIlsUser::UnregisterResult (ULONG uReqID, HRESULT hResult)
  1170. //
  1171. // History:
  1172. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1173. // Created.
  1174. //****************************************************************************
  1175. STDMETHODIMP
  1176. CIlsUser::UnregisterResult (ULONG uReqID, HRESULT hResult)
  1177. {
  1178. SRINFO sri;
  1179. Unlock();
  1180. // Notify the sink object
  1181. //
  1182. sri.uReqID = uReqID;
  1183. sri.hResult = hResult;
  1184. hResult = NotifySink((void *)&sri, OnNotifyRegisterResult);
  1185. return hResult;
  1186. }
  1187. //****************************************************************************
  1188. // STDMETHODIMP
  1189. // CIlsUser::Update(ULONG *puReqID)
  1190. //
  1191. // History:
  1192. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1193. // Created.
  1194. //****************************************************************************
  1195. STDMETHODIMP CIlsUser::
  1196. Update ( ULONG *puReqID )
  1197. {
  1198. PLDAP_CLIENTINFO pUserInfo;
  1199. LDAP_ASYNCINFO ldai;
  1200. ULONG uReqID;
  1201. HRESULT hr;
  1202. if (GetULSState () != ILS_REGISTERED)
  1203. return ILS_E_NOT_REGISTERED;
  1204. if (puReqID == NULL)
  1205. return ILS_E_POINTER;
  1206. // We already registered with the server.
  1207. // Get the user information
  1208. //
  1209. hr = (m_uModify == LU_MOD_NONE) ?
  1210. S_FALSE :
  1211. InternalGetUserInfo (FALSE, &pUserInfo, m_uModify);
  1212. if (hr == NOERROR)
  1213. {
  1214. // Make sure that we do not update User ID and App Name
  1215. //
  1216. pUserInfo->uOffsetCN = INVALID_OFFSET;
  1217. pUserInfo->uOffsetAppName = INVALID_OFFSET;
  1218. // Some fields have been updated, notify the server first
  1219. //
  1220. hr = ::UlsLdap_SetClientInfo (m_hLdapUser, pUserInfo, &ldai);
  1221. ::MemFree (pUserInfo);
  1222. // If updating server was successfully requested, wait for the response
  1223. //
  1224. COM_REQ_INFO ri;
  1225. ReqInfo_Init (&ri);
  1226. ri.uReqType = WM_ILS_SET_CLIENT_INFO;
  1227. ri.uMsgID = ldai.uMsgID;
  1228. ReqInfo_SetUser (&ri, this);
  1229. hr = g_pReqMgr->NewRequest(&ri);
  1230. if (SUCCEEDED(hr))
  1231. {
  1232. // Make sure the objects do not disappear before we get the response
  1233. //
  1234. this->AddRef();
  1235. // Return the request ID
  1236. //
  1237. *puReqID = ri.uReqID;
  1238. Lock();
  1239. };
  1240. };
  1241. return hr;
  1242. }
  1243. //****************************************************************************
  1244. // STDMETHODIMP
  1245. // CIlsUser::UpdateResult (ULONG uReqID, HRESULT hResult)
  1246. //
  1247. // History:
  1248. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1249. // Created.
  1250. //****************************************************************************
  1251. STDMETHODIMP
  1252. CIlsUser::UpdateResult (ULONG uReqID,
  1253. HRESULT hResult)
  1254. {
  1255. SRINFO sri;
  1256. Unlock ();
  1257. // Notify the sink object
  1258. //
  1259. sri.uReqID = uReqID;
  1260. sri.hResult = hResult;
  1261. if (hResult == S_OK)
  1262. {
  1263. m_uModify = LU_MOD_NONE;
  1264. }
  1265. hResult = NotifySink((void *)&sri, OnNotifyUpdateResult);
  1266. return hResult;
  1267. }
  1268. //****************************************************************************
  1269. // STDMETHODIMP
  1270. // CIlsUser::GetProtocolHandle (CLocalProt *pLocalProt, PHANDLE phProt)
  1271. //
  1272. // History:
  1273. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  1274. // Created.
  1275. //****************************************************************************
  1276. HRESULT CIlsUser::
  1277. GetProtocolHandle (CLocalProt *pLocalProt, PHANDLE phProt)
  1278. {
  1279. ASSERT (pLocalProt != NULL);
  1280. ASSERT (phProt != NULL);
  1281. // Cannot retreive the handle if ULS is locked, i.e. registering something
  1282. //
  1283. if (IsLocked())
  1284. return ILS_E_FAIL;
  1285. /* ------ server ------ */
  1286. if (m_uState != ULSSVR_CONNECT)
  1287. return ILS_E_FAIL;
  1288. // Find the matching protocol
  1289. //
  1290. *phProt = pLocalProt->GetProviderHandle ();
  1291. return S_OK;
  1292. }
  1293. //****************************************************************************
  1294. // STDMETHODIMP
  1295. // CIlsUser::RegisterLocalProtocol (BOOL fAddToList, CLocalProt *plp, PLDAP_ASYNCINFO plai)
  1296. //
  1297. // History:
  1298. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  1299. // Created.
  1300. //****************************************************************************
  1301. HRESULT CIlsUser::
  1302. RegisterLocalProtocol ( BOOL fAddToList, CLocalProt *plp, PLDAP_ASYNCINFO plai )
  1303. {
  1304. ASSERT (plp != NULL);
  1305. ASSERT (plai != NULL);
  1306. // Let's register the protocol now
  1307. //
  1308. ASSERT (m_hLdapUser != NULL);
  1309. PLDAP_PROTINFO ppi = NULL;
  1310. HRESULT hr = plp->GetProtocolInfo(&ppi);
  1311. if (SUCCEEDED(hr))
  1312. {
  1313. // Remember the protocol to register
  1314. //
  1315. if (fAddToList)
  1316. {
  1317. plp->AddRef ();
  1318. hr = m_ProtList.Insert(plp);
  1319. }
  1320. if (SUCCEEDED(hr))
  1321. {
  1322. HANDLE hProt = NULL;
  1323. hr = ::UlsLdap_RegisterProtocol (m_hLdapUser, ppi, &hProt, plai);
  1324. plp->SetProviderHandle (hProt);
  1325. if (FAILED(hr) && fAddToList)
  1326. {
  1327. m_ProtList.Remove(plp);
  1328. };
  1329. };
  1330. if (FAILED (hr) && fAddToList)
  1331. {
  1332. plp->Release ();
  1333. };
  1334. ::MemFree (ppi);
  1335. };
  1336. return hr;
  1337. }
  1338. //****************************************************************************
  1339. // STDMETHODIMP
  1340. // CIlsUser::UnregisterLocalProtocol (CLocalProt *plp, PLDAP_ASYNCINFO plai)
  1341. //
  1342. // History:
  1343. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  1344. // Created.
  1345. //****************************************************************************
  1346. HRESULT CIlsUser::
  1347. UnregisterLocalProtocol (CLocalProt *plp, PLDAP_ASYNCINFO plai)
  1348. {
  1349. ASSERT (plp != NULL);
  1350. ASSERT (plai != NULL);
  1351. // Cannot retreive the handle if ULS is locked, i.e. registering something
  1352. //
  1353. if (IsLocked())
  1354. return ILS_E_FAIL;
  1355. // Must be registered to perform this operation
  1356. //
  1357. HRESULT hr;
  1358. ILS_STATE uULSState = GetULSState ();
  1359. if (uULSState == ILS_REGISTERED ||
  1360. uULSState == ILS_REGISTERED_BUT_INVALID ||
  1361. uULSState == ILS_NETWORK_DOWN)
  1362. {
  1363. // Search for the protocol
  1364. //
  1365. if (m_ProtList.Remove (plp) == S_OK)
  1366. {
  1367. ASSERT (plp != NULL);
  1368. // Another protocol to unregister
  1369. //
  1370. hr = ::UlsLdap_UnRegisterProtocol (plp->GetProviderHandle (), plai);
  1371. plp->Release (); // AddRef by RegisterLocalProtocol
  1372. }
  1373. else
  1374. {
  1375. hr = S_FALSE;
  1376. };
  1377. }
  1378. else
  1379. {
  1380. hr = ILS_E_FAIL;
  1381. };
  1382. return hr;
  1383. }
  1384. //****************************************************************************
  1385. // STDMETHODIMP
  1386. // CIlsUser::GetState (BSTR bstrServerName, ULSSTATE *puULSState)
  1387. //
  1388. // History:
  1389. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1390. // Created.
  1391. //****************************************************************************
  1392. STDMETHODIMP CIlsUser::
  1393. GetState ( ILS_STATE *puULSState )
  1394. {
  1395. HRESULT hr;
  1396. if (puULSState != NULL)
  1397. {
  1398. *puULSState = GetULSState ();
  1399. hr = S_OK;
  1400. }
  1401. else
  1402. {
  1403. hr = ILS_E_POINTER;
  1404. }
  1405. return hr;
  1406. }
  1407. //****************************************************************************
  1408. // CEnumUsers::CEnumUsers (void)
  1409. //
  1410. // History:
  1411. // Wed 17-Apr-1996 11:15:18 -by- Viroon Touranachun [viroont]
  1412. // Created.
  1413. //****************************************************************************
  1414. CEnumUsers::CEnumUsers (void)
  1415. {
  1416. m_cRef = 0;
  1417. m_ppu = NULL;
  1418. m_cUsers = 0;
  1419. m_iNext = 0;
  1420. return;
  1421. }
  1422. //****************************************************************************
  1423. // CEnumUsers::~CEnumUsers (void)
  1424. //
  1425. // History:
  1426. // Wed 17-Apr-1996 11:15:18 -by- Viroon Touranachun [viroont]
  1427. // Created.
  1428. //****************************************************************************
  1429. CEnumUsers::~CEnumUsers (void)
  1430. {
  1431. ULONG i;
  1432. if (m_ppu != NULL)
  1433. {
  1434. for (i = 0; i < m_cUsers; i++)
  1435. {
  1436. m_ppu[i]->Release();
  1437. };
  1438. ::MemFree (m_ppu);
  1439. };
  1440. return;
  1441. }
  1442. //****************************************************************************
  1443. // STDMETHODIMP
  1444. // CEnumUsers::Init (CIlsUser **ppuList, ULONG cUsers)
  1445. //
  1446. // History:
  1447. // Wed 17-Apr-1996 11:15:25 -by- Viroon Touranachun [viroont]
  1448. // Created.
  1449. //****************************************************************************
  1450. STDMETHODIMP
  1451. CEnumUsers::Init (CIlsUser **ppuList, ULONG cUsers)
  1452. {
  1453. HRESULT hr = NOERROR;
  1454. // If no list, do nothing
  1455. //
  1456. if (cUsers != 0)
  1457. {
  1458. ASSERT(ppuList != NULL);
  1459. // Allocate the snapshot buffer
  1460. //
  1461. m_ppu = (CIlsUser **) ::MemAlloc (cUsers*sizeof(CIlsUser *));
  1462. if (m_ppu != NULL)
  1463. {
  1464. ULONG i;
  1465. // Snapshot the object list
  1466. //
  1467. for (i =0; i < cUsers; i++)
  1468. {
  1469. m_ppu[i] = ppuList[i];
  1470. m_ppu[i]->AddRef();
  1471. };
  1472. this->m_cUsers = cUsers;
  1473. }
  1474. else
  1475. {
  1476. hr = ILS_E_MEMORY;
  1477. };
  1478. };
  1479. return hr;
  1480. }
  1481. //****************************************************************************
  1482. // STDMETHODIMP
  1483. // CEnumUsers::QueryInterface (REFIID riid, void **ppv)
  1484. //
  1485. // History:
  1486. // Wed 17-Apr-1996 11:15:31 -by- Viroon Touranachun [viroont]
  1487. // Created.
  1488. //****************************************************************************
  1489. STDMETHODIMP
  1490. CEnumUsers::QueryInterface (REFIID riid, void **ppv)
  1491. {
  1492. if (riid == IID_IEnumIlsUsers || riid == IID_IUnknown)
  1493. {
  1494. *ppv = (IEnumIlsUsers *) this;
  1495. AddRef();
  1496. return S_OK;
  1497. }
  1498. else
  1499. {
  1500. *ppv = NULL;
  1501. return ILS_E_NO_INTERFACE;
  1502. };
  1503. }
  1504. //****************************************************************************
  1505. // STDMETHODIMP_(ULONG)
  1506. // CEnumUsers::AddRef (void)
  1507. //
  1508. // History:
  1509. // Wed 17-Apr-1996 11:15:37 -by- Viroon Touranachun [viroont]
  1510. // Created.
  1511. //****************************************************************************
  1512. STDMETHODIMP_(ULONG)
  1513. CEnumUsers::AddRef (void)
  1514. {
  1515. DllLock();
  1516. MyDebugMsg ((DM_REFCOUNT, "CEnumUsers::AddRef: ref=%ld\r\n", m_cRef));
  1517. ::InterlockedIncrement (&m_cRef);
  1518. return m_cRef;
  1519. }
  1520. //****************************************************************************
  1521. // STDMETHODIMP_(ULONG)
  1522. // CEnumUsers::Release (void)
  1523. //
  1524. // History:
  1525. // Wed 17-Apr-1996 11:15:43 -by- Viroon Touranachun [viroont]
  1526. // Created.
  1527. //****************************************************************************
  1528. STDMETHODIMP_(ULONG)
  1529. CEnumUsers::Release (void)
  1530. {
  1531. DllRelease();
  1532. ASSERT (m_cRef > 0);
  1533. MyDebugMsg ((DM_REFCOUNT, "CEnumUsers::Release: ref=%ld\r\n", m_cRef));
  1534. if (::InterlockedDecrement (&m_cRef) == 0)
  1535. {
  1536. delete this;
  1537. return 0;
  1538. }
  1539. return m_cRef;
  1540. }
  1541. //****************************************************************************
  1542. // STDMETHODIMP
  1543. // CEnumUsers::Next (ULONG cUsers, IIlsUser **rgpu, ULONG *pcFetched)
  1544. //
  1545. // History:
  1546. // Wed 17-Apr-1996 11:15:49 -by- Viroon Touranachun [viroont]
  1547. // Created.
  1548. //****************************************************************************
  1549. STDMETHODIMP
  1550. CEnumUsers::Next (ULONG cUsers, IIlsUser **rgpu, ULONG *pcFetched)
  1551. {
  1552. ULONG cCopied;
  1553. HRESULT hr;
  1554. // Validate the pointer
  1555. //
  1556. if (rgpu == NULL)
  1557. return E_POINTER;
  1558. // Validate the parameters
  1559. //
  1560. if ((cUsers == 0) ||
  1561. ((cUsers > 1) && (pcFetched == NULL)))
  1562. return ILS_E_PARAMETER;
  1563. // Check the enumeration index
  1564. //
  1565. cCopied = 0;
  1566. // Can copy if we still have more attribute names
  1567. //
  1568. while ((cCopied < cUsers) &&
  1569. (m_iNext < this->m_cUsers))
  1570. {
  1571. m_ppu[m_iNext]->AddRef();
  1572. rgpu[cCopied++] = m_ppu[m_iNext++];
  1573. };
  1574. // Determine the returned information based on other parameters
  1575. //
  1576. if (pcFetched != NULL)
  1577. {
  1578. *pcFetched = cCopied;
  1579. };
  1580. return (cUsers == cCopied ? S_OK : S_FALSE);
  1581. }
  1582. //****************************************************************************
  1583. // STDMETHODIMP
  1584. // CEnumUsers::Skip (ULONG cUsers)
  1585. //
  1586. // History:
  1587. // Wed 17-Apr-1996 11:15:56 -by- Viroon Touranachun [viroont]
  1588. // Created.
  1589. //****************************************************************************
  1590. STDMETHODIMP
  1591. CEnumUsers::Skip (ULONG cUsers)
  1592. {
  1593. ULONG iNewIndex;
  1594. // Validate the parameters
  1595. //
  1596. if (cUsers == 0)
  1597. return ILS_E_PARAMETER;
  1598. // Check the enumeration index limit
  1599. //
  1600. iNewIndex = m_iNext+cUsers;
  1601. if (iNewIndex <= this->m_cUsers)
  1602. {
  1603. m_iNext = iNewIndex;
  1604. return S_OK;
  1605. }
  1606. else
  1607. {
  1608. m_iNext = this->m_cUsers;
  1609. return S_FALSE;
  1610. };
  1611. }
  1612. //****************************************************************************
  1613. // STDMETHODIMP
  1614. // CEnumUsers::Reset (void)
  1615. //
  1616. // History:
  1617. // Wed 17-Apr-1996 11:16:02 -by- Viroon Touranachun [viroont]
  1618. // Created.
  1619. //****************************************************************************
  1620. STDMETHODIMP
  1621. CEnumUsers::Reset (void)
  1622. {
  1623. m_iNext = 0;
  1624. return S_OK;
  1625. }
  1626. //****************************************************************************
  1627. // STDMETHODIMP
  1628. // CEnumUsers::Clone(IEnumIlsUsers **ppEnum)
  1629. //
  1630. // History:
  1631. // Wed 17-Apr-1996 11:16:11 -by- Viroon Touranachun [viroont]
  1632. // Created.
  1633. //****************************************************************************
  1634. STDMETHODIMP
  1635. CEnumUsers::Clone(IEnumIlsUsers **ppEnum)
  1636. {
  1637. CEnumUsers *peu;
  1638. HRESULT hr;
  1639. // Validate parameters
  1640. //
  1641. if (ppEnum == NULL)
  1642. {
  1643. return E_POINTER;
  1644. };
  1645. *ppEnum = NULL;
  1646. // Create an enumerator
  1647. //
  1648. peu = new CEnumUsers;
  1649. if (peu == NULL)
  1650. return ILS_E_MEMORY;
  1651. // Clone the information
  1652. //
  1653. hr = peu->Init(m_ppu, m_cUsers);
  1654. if (SUCCEEDED(hr))
  1655. {
  1656. peu->m_iNext = m_iNext;
  1657. // Return the cloned enumerator
  1658. //
  1659. peu->AddRef();
  1660. *ppEnum = peu;
  1661. }
  1662. else
  1663. {
  1664. delete peu;
  1665. };
  1666. return hr;
  1667. }
  1668. //****************************************************************************
  1669. // STDMETHODIMP
  1670. // CIlsUser::SetExtendedAttributes (IIlsAttributes *pAttributes, ULONG *puReqID)
  1671. //
  1672. // History:
  1673. //****************************************************************************
  1674. STDMETHODIMP CIlsUser::
  1675. SetExtendedAttribute ( BSTR bstrName, BSTR bstrValue )
  1676. {
  1677. // Make sure this is not a read-only object
  1678. //
  1679. if (m_fReadonly)
  1680. return ILS_E_ACCESS_DENIED;
  1681. m_uModify |= LU_MOD_ATTRIB;
  1682. return m_ExtendedAttrs.SetAttribute (bstrName, bstrValue);
  1683. }
  1684. //****************************************************************************
  1685. // STDMETHODIMP
  1686. // CIlsUser::RemoveExtendedAttributes (IIlsAttributes *pAttributes, ULONG *puReqID)
  1687. //
  1688. // History:
  1689. //****************************************************************************
  1690. STDMETHODIMP CIlsUser::
  1691. RemoveExtendedAttribute ( BSTR bstrName )
  1692. {
  1693. // Make sure this is not a read-only object
  1694. //
  1695. if (m_fReadonly)
  1696. return ILS_E_ACCESS_DENIED;
  1697. m_uModify |= LU_MOD_ATTRIB;
  1698. return m_ExtendedAttrs.SetAttribute (bstrName, NULL);
  1699. }
  1700. //****************************************************************************
  1701. // STDMETHODIMP
  1702. // CIlsUser::GetExtendedAttributes (IIlsAttributes **pAttributes)
  1703. //
  1704. //****************************************************************************
  1705. STDMETHODIMP CIlsUser::
  1706. GetExtendedAttribute ( BSTR bstrName, BSTR *pbstrValue )
  1707. {
  1708. return m_ExtendedAttrs.GetAttribute (bstrName, pbstrValue);
  1709. }
  1710. //****************************************************************************
  1711. // STDMETHODIMP
  1712. // CIlsUser::GetAllExtendedAttributes (IIlsAttributes **pAttributes)
  1713. //
  1714. //****************************************************************************
  1715. STDMETHODIMP CIlsUser::
  1716. GetAllExtendedAttributes ( IIlsAttributes **ppAttributes )
  1717. {
  1718. if (ppAttributes == NULL)
  1719. return ILS_E_PARAMETER;
  1720. return m_ExtendedAttrs.CloneNameValueAttrib((CAttributes **) ppAttributes);
  1721. }
  1722. //****************************************************************************
  1723. // STDMETHODIMP
  1724. // CIlsUser::CreateProtocol(
  1725. // BSTR bstrProtocolID,
  1726. // ULONG uPortNumber,
  1727. // BSTR bstrMimeType,
  1728. // IIlsProtocol **ppProtocol)
  1729. //****************************************************************************
  1730. STDMETHODIMP
  1731. CIlsUser::CreateProtocol(
  1732. BSTR bstrProtocolID,
  1733. ULONG uPortNumber,
  1734. BSTR bstrMimeType,
  1735. IIlsProtocol **ppProtocol)
  1736. {
  1737. HRESULT hr= NOERROR;
  1738. CLocalProt *pProt;
  1739. if (!ppProtocol) {
  1740. return (ILS_E_POINTER);
  1741. }
  1742. *ppProtocol = NULL;
  1743. pProt = new CLocalProt;
  1744. if (!pProt) {
  1745. return ILS_E_MEMORY;
  1746. }
  1747. hr = pProt->Init(bstrProtocolID, uPortNumber, bstrMimeType);
  1748. if (SUCCEEDED(hr)) {
  1749. pProt->QueryInterface(IID_IIlsProtocol, (void **)ppProtocol);
  1750. }
  1751. else {
  1752. delete pProt;
  1753. }
  1754. return hr;
  1755. }
  1756. //****************************************************************************
  1757. // STDMETHODIMP
  1758. // CIlsUser::UpdateProtocol (IIlsProtocol *pProtocol,
  1759. // ULONG *puReqID, APP_CHANGE_PROT uCmd)
  1760. //
  1761. // History:
  1762. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1763. // Created.
  1764. //****************************************************************************
  1765. HRESULT CIlsUser::
  1766. UpdateProtocol (
  1767. IIlsProtocol *pProtocol,
  1768. ULONG *puReqID,
  1769. APP_CHANGE_PROT uCmd)
  1770. {
  1771. ASSERT (uCmd == ILS_APP_ADD_PROT || uCmd == ILS_APP_REMOVE_PROT);
  1772. // Validate parameters
  1773. //
  1774. if (pProtocol == NULL || puReqID == NULL)
  1775. return ILS_E_POINTER;
  1776. HRESULT hr;
  1777. HANDLE hLdapApp;
  1778. LDAP_ASYNCINFO ldai;
  1779. // Check whether the protocol exists
  1780. //
  1781. CLocalProt *plp = NULL;
  1782. HANDLE hEnum = NULL;
  1783. m_ProtList.Enumerate(&hEnum);
  1784. while(m_ProtList.Next(&hEnum, (VOID **)&plp) == NOERROR)
  1785. {
  1786. ASSERT (plp != NULL);
  1787. if (plp->IsSameAs((CLocalProt *)pProtocol) == NOERROR)
  1788. {
  1789. break;
  1790. };
  1791. plp = NULL;
  1792. };
  1793. if (plp != NULL)
  1794. {
  1795. // The protocol exists, fail if this add request
  1796. //
  1797. if (uCmd == ILS_APP_ADD_PROT)
  1798. {
  1799. return ILS_E_PARAMETER;
  1800. };
  1801. }
  1802. else
  1803. {
  1804. // The protocol does not exist, fail if this remove request
  1805. //
  1806. if (uCmd == ILS_APP_REMOVE_PROT)
  1807. {
  1808. return ILS_E_PARAMETER;
  1809. };
  1810. };
  1811. // Make sure we are not in the middle of registration/unregistration.
  1812. //
  1813. if (IsLocked ())
  1814. return ILS_E_FAIL;
  1815. // Must be registered to perform this operation
  1816. //
  1817. ILS_STATE uULSState = GetULSState ();
  1818. if (uULSState == ILS_REGISTERED)
  1819. {
  1820. // Update the server information first
  1821. //
  1822. switch (uCmd)
  1823. {
  1824. case ILS_APP_ADD_PROT:
  1825. hr = RegisterLocalProtocol(TRUE, (CLocalProt*)pProtocol, &ldai);
  1826. break;
  1827. case ILS_APP_REMOVE_PROT:
  1828. hr = UnregisterLocalProtocol((CLocalProt*)pProtocol, &ldai);
  1829. break;
  1830. };
  1831. switch (hr)
  1832. {
  1833. case NOERROR:
  1834. //
  1835. // Server starts updating the protocol successfullly
  1836. // We will wait for the server response.
  1837. //
  1838. break;
  1839. default:
  1840. // ULS is locked. Return failure.
  1841. //
  1842. hr = ILS_E_ABORT;
  1843. break;
  1844. }
  1845. if (SUCCEEDED(hr))
  1846. {
  1847. ASSERT(ldai.uMsgID);
  1848. ULONG uMsg;
  1849. switch(uCmd)
  1850. {
  1851. case ILS_APP_ADD_PROT:
  1852. uMsg = WM_ILS_REGISTER_PROTOCOL;
  1853. break;
  1854. case ILS_APP_REMOVE_PROT:
  1855. uMsg = WM_ILS_UNREGISTER_PROTOCOL;
  1856. break;
  1857. default:
  1858. ASSERT(0);
  1859. uCmd = ILS_APP_ADD_PROT;
  1860. break;
  1861. };
  1862. COM_REQ_INFO ri;
  1863. ReqInfo_Init (&ri);
  1864. ri.uReqType = uMsg;
  1865. ri.uMsgID = ldai.uMsgID;
  1866. ReqInfo_SetUser (&ri, this);
  1867. ReqInfo_SetProtocol (&ri, pProtocol);
  1868. hr = g_pReqMgr->NewRequest(&ri);
  1869. if (SUCCEEDED(hr))
  1870. {
  1871. // Make sure the objects do not disappear before we get the response
  1872. //
  1873. this->AddRef();
  1874. pProtocol->AddRef();
  1875. // Return the request ID
  1876. //
  1877. *puReqID = ri.uReqID;
  1878. }
  1879. }
  1880. }
  1881. else
  1882. {
  1883. // Just make local change
  1884. //
  1885. switch (uCmd)
  1886. {
  1887. case ILS_APP_ADD_PROT:
  1888. pProtocol->AddRef ();
  1889. hr = m_ProtList.Insert ((CLocalProt*)pProtocol);
  1890. break;
  1891. case ILS_APP_REMOVE_PROT:
  1892. ASSERT (plp != NULL && plp->IsSameAs((CLocalProt *)pProtocol) == S_OK);
  1893. if (plp != NULL)
  1894. {
  1895. hr = m_ProtList.Remove (plp);
  1896. if (hr == S_OK)
  1897. {
  1898. // The protocol object really exists in ths list
  1899. //
  1900. plp->Release (); // AddRef by above case
  1901. }
  1902. }
  1903. break;
  1904. };
  1905. *puReqID = 0;
  1906. };
  1907. return hr;
  1908. }
  1909. //****************************************************************************
  1910. // STDMETHODIMP
  1911. // CIlsUser::AddProtocol (IIlsProtocol *pProtocol,
  1912. // ULONG *puReqID)
  1913. //
  1914. // History:
  1915. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1916. // Created.
  1917. //****************************************************************************
  1918. STDMETHODIMP CIlsUser::
  1919. AddProtocol (IIlsProtocol *pProtocol, ULONG *puReqID)
  1920. {
  1921. return UpdateProtocol (pProtocol, puReqID, ILS_APP_ADD_PROT);
  1922. }
  1923. //****************************************************************************
  1924. // STDMETHODIMP
  1925. // CIlsUser::RemoveProtocol (IIlsProtocol *pProtocol,
  1926. // ULONG *puReqID)
  1927. //
  1928. // History:
  1929. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1930. // Created.
  1931. //****************************************************************************
  1932. STDMETHODIMP CIlsUser::
  1933. RemoveProtocol ( IIlsProtocol *pProtocol, ULONG *puReqID )
  1934. {
  1935. return UpdateProtocol (pProtocol, puReqID, ILS_APP_REMOVE_PROT);
  1936. }
  1937. //****************************************************************************
  1938. // STDMETHODIMP
  1939. // CIlsUser::EnumProtocols (IEnumIlsProtocols **ppEnumProtocol)
  1940. //
  1941. // History:
  1942. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  1943. // Created.
  1944. //****************************************************************************
  1945. HRESULT
  1946. CIlsUser::EnumLocalProtocols (IEnumIlsProtocols **ppEnumProtocol)
  1947. {
  1948. CEnumProtocols *pep;
  1949. HRESULT hr;
  1950. // Validate parameters
  1951. //
  1952. if (ppEnumProtocol == NULL)
  1953. {
  1954. return ILS_E_POINTER;
  1955. };
  1956. // Assume failure
  1957. //
  1958. *ppEnumProtocol = NULL;
  1959. // Create a peer enumerator
  1960. //
  1961. pep = new CEnumProtocols;
  1962. if (pep != NULL)
  1963. {
  1964. hr = pep->Init(&m_ProtList);
  1965. if (SUCCEEDED(hr))
  1966. {
  1967. // Get the enumerator interface
  1968. //
  1969. pep->AddRef();
  1970. *ppEnumProtocol = pep;
  1971. }
  1972. else
  1973. {
  1974. delete pep;
  1975. };
  1976. }
  1977. else
  1978. {
  1979. hr = ILS_E_MEMORY;
  1980. };
  1981. return hr;
  1982. }
  1983. //****************************************************************************
  1984. // STDMETHODIMP
  1985. // CIlsUser::EnumProtocols(
  1986. // IIlsFilter *pFilter,
  1987. // IIlsAttributes *pAttributes,
  1988. // IEnumIlsProtocols **pEnumProtocol,
  1989. // ULONG *puReqID)
  1990. //
  1991. // History:
  1992. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  1993. // Created.
  1994. //****************************************************************************
  1995. STDMETHODIMP
  1996. CIlsUser::EnumProtocols(
  1997. IIlsFilter *pFilter,
  1998. IIlsAttributes *pAttributes,
  1999. IEnumIlsProtocols **ppEnumProtocol,
  2000. ULONG *puReqID)
  2001. {
  2002. LDAP_ASYNCINFO ldai;
  2003. HRESULT hr=ILS_E_FAIL;
  2004. // Validate parameter
  2005. //
  2006. if (puReqID == NULL)
  2007. {
  2008. return ILS_E_POINTER;
  2009. };
  2010. // We do not implement synchronous operation
  2011. //
  2012. if (ppEnumProtocol != NULL)
  2013. return ILS_E_NOT_IMPL;
  2014. if (m_fReadonly)
  2015. {
  2016. hr = ::UlsLdap_EnumProtocols (m_pIlsServer->GetServerInfo (), m_szID, m_szAppName, &ldai);
  2017. }
  2018. else
  2019. {
  2020. return ILS_E_ACCESS_DENIED;
  2021. }
  2022. if (SUCCEEDED(hr))
  2023. {
  2024. COM_REQ_INFO ri;
  2025. ReqInfo_Init (&ri);
  2026. // If updating server was successfully requested, wait for the response
  2027. //
  2028. ri.uReqType = WM_ILS_ENUM_PROTOCOLS;
  2029. ri.uMsgID = ldai.uMsgID;
  2030. ReqInfo_SetUser (&ri, this);
  2031. hr = g_pReqMgr->NewRequest(&ri);
  2032. if (SUCCEEDED(hr))
  2033. {
  2034. // Make sure the objects do not disappear before we get the response
  2035. //
  2036. this->AddRef();
  2037. // Return the request ID
  2038. //
  2039. *puReqID = ri.uReqID;
  2040. };
  2041. };
  2042. return hr;
  2043. }
  2044. //****************************************************************************
  2045. // STDMETHODIMP
  2046. // CIlsUser::GetProtocol (BSTR bstrProtocolID, IIlsAttributes *pAttributes,
  2047. // IIlsProtocol **ppProtocol, ULONG *puReqID)
  2048. //
  2049. // History:
  2050. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  2051. // Created.
  2052. //****************************************************************************
  2053. STDMETHODIMP CIlsUser::
  2054. GetProtocol (
  2055. BSTR bstrProtocolID,
  2056. IIlsAttributes *pAttributes,
  2057. IIlsProtocol **ppProtocol,
  2058. ULONG *puReqID )
  2059. {
  2060. LDAP_ASYNCINFO ldai;
  2061. LPTSTR pszID;
  2062. HRESULT hr;
  2063. TCHAR *pszAttrNameList = NULL;
  2064. ULONG cAttrNames = 0;
  2065. ULONG cbNames = 0;
  2066. // Validate parameter
  2067. //
  2068. if (bstrProtocolID == NULL || puReqID == NULL)
  2069. return ILS_E_POINTER;
  2070. // Make sure this is a read-only object from server
  2071. //
  2072. if (! m_fReadonly)
  2073. return ILS_E_ACCESS_DENIED;
  2074. // Make sure we have a valid server object
  2075. //
  2076. if (m_pIlsServer == NULL)
  2077. return ILS_E_FAIL;
  2078. // Convert protocol name
  2079. //
  2080. hr = BSTR_to_LPTSTR(&pszID, bstrProtocolID);
  2081. if (hr != S_OK)
  2082. return hr;
  2083. // Get arbitrary attribute name list if any
  2084. //
  2085. if (pAttributes != NULL)
  2086. {
  2087. hr = ((CAttributes *) pAttributes)->GetAttributeList (&pszAttrNameList, &cAttrNames, &cbNames);
  2088. if (hr != S_OK)
  2089. goto MyExit;
  2090. }
  2091. hr = ::UlsLdap_ResolveProtocol (m_pIlsServer->GetServerInfo (),
  2092. m_szID,
  2093. m_szAppName,
  2094. pszID,
  2095. pszAttrNameList,
  2096. cAttrNames,
  2097. &ldai);
  2098. if (hr != S_OK)
  2099. goto MyExit;
  2100. // If updating server was successfully requested, wait for the response
  2101. //
  2102. COM_REQ_INFO ri;
  2103. ReqInfo_Init (&ri);
  2104. ri.uReqType = WM_ILS_RESOLVE_PROTOCOL;
  2105. ri.uMsgID = ldai.uMsgID;
  2106. ReqInfo_SetUser (&ri, this);
  2107. // Remember this request
  2108. //
  2109. hr = g_pReqMgr->NewRequest(&ri);
  2110. if (SUCCEEDED(hr))
  2111. {
  2112. // Make sure the objects do not disappear before we get the response
  2113. //
  2114. this->AddRef();
  2115. // Return the request ID
  2116. //
  2117. *puReqID = ri.uReqID;
  2118. };
  2119. MyExit:
  2120. ::MemFree(pszAttrNameList);
  2121. ::MemFree (pszID);
  2122. return hr;
  2123. }
  2124. //****************************************************************************
  2125. // STDMETHODIMP
  2126. // CIlsUser::EnumProtocolsResult (ULONG uReqID, PLDAP_ENUM ple)
  2127. //
  2128. // History:
  2129. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  2130. // Created.
  2131. //****************************************************************************
  2132. STDMETHODIMP
  2133. CIlsUser::EnumProtocolsResult (ULONG uReqID, PLDAP_ENUM ple)
  2134. {
  2135. ENUMRINFO eri;
  2136. // Package the notification info
  2137. //
  2138. eri.uReqID = uReqID;
  2139. if (ple != NULL)
  2140. {
  2141. eri.hResult = ple->hResult;
  2142. eri.cItems = ple->cItems;
  2143. eri.pv = (void *)(((PBYTE)ple)+ple->uOffsetItems);
  2144. }
  2145. else
  2146. {
  2147. eri.hResult = ILS_E_MEMORY;
  2148. eri.cItems = 0;
  2149. eri.pv = NULL;
  2150. }
  2151. NotifySink((void *)&eri, OnNotifyEnumProtocolsResult);
  2152. return NOERROR;
  2153. }
  2154. //****************************************************************************
  2155. // STDMETHODIMP
  2156. // CIlsUser::StateChanged ( BOOL fPrimary, TCHAR *pszServerName )
  2157. //
  2158. // History:
  2159. // Thu 07-Nov-1996 12:52:00 -by- Chu, Lon-Chan [lonchanc]
  2160. // Created.
  2161. //****************************************************************************
  2162. STDMETHODIMP
  2163. CIlsUser::StateChanged ( LONG Type, BOOL fPrimary )
  2164. {
  2165. BSTR bstrServerName;
  2166. HRESULT hr;
  2167. if (m_pIlsServer != NULL)
  2168. {
  2169. bstrServerName = m_pIlsServer->DuplicateServerNameBSTR ();
  2170. }
  2171. else
  2172. {
  2173. bstrServerName = NULL;
  2174. ASSERT (FALSE);
  2175. }
  2176. switch (Type)
  2177. {
  2178. case WM_ILS_CLIENT_NEED_RELOGON:
  2179. SetULSState(ULSSVR_RELOGON);
  2180. hr = NotifySink (bstrServerName, fPrimary ?
  2181. OnNotifyStateChanged_UI_NoSuchObject :
  2182. OnNotifyStateChanged_NoUI_NoSuchObject);
  2183. break;
  2184. case WM_ILS_CLIENT_NETWORK_DOWN:
  2185. SetULSState(ULSSVR_NETWORK_DOWN);
  2186. hr = NotifySink (bstrServerName, fPrimary ?
  2187. OnNotifyStateChanged_UI_NetworkDown :
  2188. OnNotifyStateChanged_NoUI_NetworkDown);
  2189. break;
  2190. }
  2191. return hr;
  2192. }
  2193. //****************************************************************************
  2194. // STDMETHODIMP
  2195. // CIlsUser::GetProtocolResult (ULONG uReqID, PLDAP_PROTINFO_RES ppir)
  2196. //
  2197. // History:
  2198. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  2199. // Created.
  2200. //****************************************************************************
  2201. STDMETHODIMP
  2202. CIlsUser::GetProtocolResult (ULONG uReqID, PLDAP_PROTINFO_RES ppir)
  2203. {
  2204. CLocalProt *pp;
  2205. OBJRINFO objri;
  2206. // Default to the server's result
  2207. //
  2208. objri.hResult = (ppir != NULL) ? ppir->hResult : ILS_E_MEMORY;
  2209. if (SUCCEEDED(objri.hResult))
  2210. {
  2211. // The server returns PROTINFO, create a Application object
  2212. //
  2213. pp = new CLocalProt;
  2214. if (pp != NULL)
  2215. {
  2216. objri.hResult = pp->Init(m_pIlsServer, m_szID, m_szAppName, &ppir->lpi);
  2217. if (SUCCEEDED(objri.hResult))
  2218. {
  2219. pp->AddRef();
  2220. }
  2221. else
  2222. {
  2223. delete pp;
  2224. pp = NULL;
  2225. };
  2226. }
  2227. else
  2228. {
  2229. objri.hResult = ILS_E_MEMORY;
  2230. };
  2231. }
  2232. else
  2233. {
  2234. pp = NULL;
  2235. };
  2236. // Package the notification info
  2237. //
  2238. objri.uReqID = uReqID;
  2239. objri.pv = (void *)(pp == NULL ? NULL : (IIlsProtocol *)pp);
  2240. NotifySink((void *)&objri, OnNotifyGetProtocolResult);
  2241. if (pp != NULL)
  2242. {
  2243. pp->Release();
  2244. };
  2245. return NOERROR;
  2246. }
  2247. //****************************************************************************
  2248. // STDMETHODIMP
  2249. // CIlsUser::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  2250. //
  2251. // History:
  2252. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  2253. // Created.
  2254. //****************************************************************************
  2255. STDMETHODIMP
  2256. CIlsUser::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  2257. {
  2258. HRESULT hr = S_OK;
  2259. if (m_pConnPt != NULL)
  2260. {
  2261. hr = m_pConnPt->Notify(pv, pfn);
  2262. };
  2263. return hr;
  2264. }
  2265. //****************************************************************************
  2266. // CEnumProtocols::CEnumProtocols (void)
  2267. //
  2268. // History:
  2269. // Wed 17-Apr-1996 11:15:18 -by- Viroon Touranachun [viroont]
  2270. // Created.
  2271. //****************************************************************************
  2272. CEnumProtocols::CEnumProtocols (void)
  2273. {
  2274. m_cRef = 0;
  2275. hEnum = NULL;
  2276. return;
  2277. }
  2278. //****************************************************************************
  2279. // CEnumProtocols::~CEnumProtocols (void)
  2280. //
  2281. // History:
  2282. // Wed 17-Apr-1996 11:15:18 -by- Viroon Touranachun [viroont]
  2283. // Created.
  2284. //****************************************************************************
  2285. CEnumProtocols::~CEnumProtocols (void)
  2286. {
  2287. CLocalProt *plp;
  2288. ASSERT (m_cRef == 0);
  2289. m_ProtList.Enumerate(&hEnum);
  2290. while(m_ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR)
  2291. {
  2292. plp->Release();
  2293. };
  2294. m_ProtList.Flush();
  2295. return;
  2296. }
  2297. //****************************************************************************
  2298. // STDMETHODIMP
  2299. // CEnumProtocols::Init (CList *pProtList)
  2300. //
  2301. // History:
  2302. // Wed 17-Apr-1996 11:15:25 -by- Viroon Touranachun [viroont]
  2303. // Created.
  2304. //****************************************************************************
  2305. STDMETHODIMP
  2306. CEnumProtocols::Init (CList *pProtList)
  2307. {
  2308. CLocalProt *plp;
  2309. HRESULT hr;
  2310. // Duplicate the protocol list
  2311. //
  2312. hr = m_ProtList.Clone (pProtList, NULL);
  2313. if (SUCCEEDED(hr))
  2314. {
  2315. // Add reference to each protocol object
  2316. //
  2317. m_ProtList.Enumerate(&hEnum);
  2318. while(m_ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR)
  2319. {
  2320. plp->AddRef();
  2321. };
  2322. // Reset the enumerator
  2323. //
  2324. m_ProtList.Enumerate(&hEnum);
  2325. };
  2326. return hr;
  2327. }
  2328. //****************************************************************************
  2329. // STDMETHODIMP
  2330. // CEnumProtocols::QueryInterface (REFIID riid, void **ppv)
  2331. //
  2332. // History:
  2333. // Wed 17-Apr-1996 11:15:31 -by- Viroon Touranachun [viroont]
  2334. // Created.
  2335. //****************************************************************************
  2336. STDMETHODIMP
  2337. CEnumProtocols::QueryInterface (REFIID riid, void **ppv)
  2338. {
  2339. if (riid == IID_IEnumIlsProtocols || riid == IID_IUnknown)
  2340. {
  2341. *ppv = (IEnumIlsProtocols *) this;
  2342. AddRef();
  2343. return S_OK;
  2344. }
  2345. else
  2346. {
  2347. *ppv = NULL;
  2348. return ILS_E_NO_INTERFACE;
  2349. };
  2350. }
  2351. //****************************************************************************
  2352. // STDMETHODIMP_(ULONG)
  2353. // CEnumProtocols::AddRef (void)
  2354. //
  2355. // History:
  2356. // Wed 17-Apr-1996 11:15:37 -by- Viroon Touranachun [viroont]
  2357. // Created.
  2358. //****************************************************************************
  2359. STDMETHODIMP_(ULONG)
  2360. CEnumProtocols::AddRef (void)
  2361. {
  2362. DllLock();
  2363. MyDebugMsg ((DM_REFCOUNT, "CEnumProtocols::AddRef: ref=%ld\r\n", m_cRef));
  2364. ::InterlockedIncrement (&m_cRef);
  2365. return (ULONG) m_cRef;
  2366. }
  2367. //****************************************************************************
  2368. // STDMETHODIMP_(ULONG)
  2369. // CEnumProtocols::Release (void)
  2370. //
  2371. // History:
  2372. // Wed 17-Apr-1996 11:15:43 -by- Viroon Touranachun [viroont]
  2373. // Created.
  2374. //****************************************************************************
  2375. STDMETHODIMP_(ULONG)
  2376. CEnumProtocols::Release (void)
  2377. {
  2378. DllRelease();
  2379. ASSERT (m_cRef > 0);
  2380. MyDebugMsg ((DM_REFCOUNT, "CEnumProtocols::Release: ref=%ld\r\n", m_cRef));
  2381. if (::InterlockedDecrement (&m_cRef) == 0)
  2382. {
  2383. delete this;
  2384. return 0;
  2385. }
  2386. return (ULONG) m_cRef;
  2387. }
  2388. //****************************************************************************
  2389. // STDMETHODIMP
  2390. // CEnumProtocols::Next (ULONG cProtocols,
  2391. // IIlsProtocol **rgpProt,
  2392. // ULONG *pcFetched)
  2393. //
  2394. // History:
  2395. // Wed 17-Apr-1996 11:15:49 -by- Viroon Touranachun [viroont]
  2396. // Created.
  2397. //****************************************************************************
  2398. STDMETHODIMP
  2399. CEnumProtocols::Next (ULONG cProtocols, IIlsProtocol **rgpProt,
  2400. ULONG *pcFetched)
  2401. {
  2402. CLocalProt *plp;
  2403. ULONG cCopied;
  2404. HRESULT hr;
  2405. // Validate the pointer
  2406. //
  2407. if (rgpProt == NULL)
  2408. return ILS_E_POINTER;
  2409. // Validate the parameters
  2410. //
  2411. if ((cProtocols == 0) ||
  2412. ((cProtocols > 1) && (pcFetched == NULL)))
  2413. return ILS_E_PARAMETER;
  2414. // Check the enumeration index
  2415. //
  2416. cCopied = 0;
  2417. // Can copy if we still have more protocols
  2418. //
  2419. while ((cCopied < cProtocols) &&
  2420. (m_ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR))
  2421. {
  2422. rgpProt[cCopied] = plp;
  2423. plp->AddRef();
  2424. cCopied++;
  2425. };
  2426. // Determine the returned information based on other parameters
  2427. //
  2428. if (pcFetched != NULL)
  2429. {
  2430. *pcFetched = cCopied;
  2431. };
  2432. return (cProtocols == cCopied ? S_OK : S_FALSE);
  2433. }
  2434. //****************************************************************************
  2435. // STDMETHODIMP
  2436. // CEnumProtocols::Skip (ULONG cProtocols)
  2437. //
  2438. // History:
  2439. // Wed 17-Apr-1996 11:15:56 -by- Viroon Touranachun [viroont]
  2440. // Created.
  2441. //****************************************************************************
  2442. STDMETHODIMP
  2443. CEnumProtocols::Skip (ULONG cProtocols)
  2444. {
  2445. CLocalProt *plp;
  2446. ULONG cSkipped;
  2447. // Validate the parameters
  2448. //
  2449. if (cProtocols == 0)
  2450. return ILS_E_PARAMETER;
  2451. // Check the enumeration index limit
  2452. //
  2453. cSkipped = 0;
  2454. // Can skip only if we still have more attributes
  2455. //
  2456. while ((cSkipped < cProtocols) &&
  2457. (m_ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR))
  2458. {
  2459. cSkipped++;
  2460. };
  2461. return (cProtocols == cSkipped ? S_OK : S_FALSE);
  2462. }
  2463. //****************************************************************************
  2464. // STDMETHODIMP
  2465. // CEnumProtocols::Reset (void)
  2466. //
  2467. // History:
  2468. // Wed 17-Apr-1996 11:16:02 -by- Viroon Touranachun [viroont]
  2469. // Created.
  2470. //****************************************************************************
  2471. STDMETHODIMP
  2472. CEnumProtocols::Reset (void)
  2473. {
  2474. m_ProtList.Enumerate(&hEnum);
  2475. return S_OK;
  2476. }
  2477. //****************************************************************************
  2478. // STDMETHODIMP
  2479. // CEnumProtocols::Clone(IEnumIlsProtocols **ppEnum)
  2480. //
  2481. // History:
  2482. // Wed 17-Apr-1996 11:16:11 -by- Viroon Touranachun [viroont]
  2483. // Created.
  2484. //****************************************************************************
  2485. STDMETHODIMP
  2486. CEnumProtocols::Clone(IEnumIlsProtocols **ppEnum)
  2487. {
  2488. CEnumProtocols *pep;
  2489. HRESULT hr;
  2490. // Validate parameters
  2491. //
  2492. if (ppEnum == NULL)
  2493. {
  2494. return ILS_E_POINTER;
  2495. };
  2496. *ppEnum = NULL;
  2497. // Create an enumerator
  2498. //
  2499. pep = new CEnumProtocols;
  2500. if (pep == NULL)
  2501. return ILS_E_MEMORY;
  2502. // Clone the information
  2503. //
  2504. pep->hEnum = hEnum;
  2505. hr = pep->m_ProtList.Clone (&m_ProtList, &(pep->hEnum));
  2506. if (SUCCEEDED(hr))
  2507. {
  2508. CLocalProt *plp;
  2509. HANDLE hEnumTemp;
  2510. // Add reference to each protocol object
  2511. //
  2512. pep->m_ProtList.Enumerate(&hEnumTemp);
  2513. while(pep->m_ProtList.Next(&hEnumTemp, (PVOID *)&plp) == NOERROR)
  2514. {
  2515. plp->AddRef();
  2516. };
  2517. // Return the cloned enumerator
  2518. //
  2519. pep->AddRef();
  2520. *ppEnum = pep;
  2521. }
  2522. else
  2523. {
  2524. delete pep;
  2525. };
  2526. return hr;
  2527. }
  2528. //****************************************************************************
  2529. // STDMETHODIMP
  2530. // CIlsUser::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  2531. //
  2532. // History:
  2533. // Wed 17-Apr-1996 11:15:02 -by- Viroon Touranachun [viroont]
  2534. // Created.
  2535. //****************************************************************************
  2536. STDMETHODIMP
  2537. CIlsUser::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  2538. {
  2539. CEnumConnectionPoints *pecp;
  2540. HRESULT hr;
  2541. // Validate parameters
  2542. //
  2543. if (ppEnum == NULL)
  2544. {
  2545. return E_POINTER;
  2546. };
  2547. // Assume failure
  2548. //
  2549. *ppEnum = NULL;
  2550. // Create an enumerator
  2551. //
  2552. pecp = new CEnumConnectionPoints;
  2553. if (pecp == NULL)
  2554. return ILS_E_MEMORY;
  2555. // Initialize the enumerator
  2556. //
  2557. hr = pecp->Init((IConnectionPoint *)m_pConnPt);
  2558. if (FAILED(hr))
  2559. {
  2560. delete pecp;
  2561. return hr;
  2562. };
  2563. // Give it back to the caller
  2564. //
  2565. pecp->AddRef();
  2566. *ppEnum = pecp;
  2567. return S_OK;
  2568. }
  2569. //****************************************************************************
  2570. // STDMETHODIMP
  2571. // CIlsUser::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  2572. //
  2573. // History:
  2574. // Wed 17-Apr-1996 11:15:09 -by- Viroon Touranachun [viroont]
  2575. // Created.
  2576. //****************************************************************************
  2577. STDMETHODIMP
  2578. CIlsUser::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  2579. {
  2580. IID siid;
  2581. HRESULT hr;
  2582. // Validate parameters
  2583. //
  2584. if (ppcp == NULL)
  2585. {
  2586. return E_POINTER;
  2587. };
  2588. // Assume failure
  2589. //
  2590. *ppcp = NULL;
  2591. if (m_pConnPt != NULL)
  2592. {
  2593. hr = m_pConnPt->GetConnectionInterface(&siid);
  2594. if (SUCCEEDED(hr))
  2595. {
  2596. if (riid == siid)
  2597. {
  2598. *ppcp = (IConnectionPoint *)m_pConnPt;
  2599. (*ppcp)->AddRef();
  2600. hr = S_OK;
  2601. }
  2602. else
  2603. {
  2604. hr = ILS_E_NO_INTERFACE;
  2605. };
  2606. };
  2607. }
  2608. else
  2609. {
  2610. hr = ILS_E_NO_INTERFACE;
  2611. };
  2612. return hr;
  2613. }