Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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