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.

1173 lines
29 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: ulsuser.cpp
  5. // Content: This file contains the User 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 "ulsuser.h"
  14. #include "ulsapp.h"
  15. #include "culs.h"
  16. #include "attribs.h"
  17. #include "callback.h"
  18. //****************************************************************************
  19. // Event Notifiers
  20. //****************************************************************************
  21. //
  22. //****************************************************************************
  23. // HRESULT
  24. // OnNotifyGetApplicationResult (IUnknown *pUnk, void *pv)
  25. //
  26. // History:
  27. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  28. // Created.
  29. //****************************************************************************
  30. HRESULT
  31. OnNotifyGetApplicationResult (IUnknown *pUnk, void *pv)
  32. {
  33. POBJRINFO pobjri = (POBJRINFO)pv;
  34. ((IULSUserNotify*)pUnk)->GetApplicationResult(pobjri->uReqID,
  35. (IULSApplication *)pobjri->pv,
  36. pobjri->hResult);
  37. return S_OK;
  38. }
  39. //****************************************************************************
  40. // HRESULT
  41. // OnNotifyEnumApplicationsResult (IUnknown *pUnk, void *pv)
  42. //
  43. // History:
  44. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  45. // Created.
  46. //****************************************************************************
  47. HRESULT
  48. OnNotifyEnumApplicationsResult (IUnknown *pUnk, void *pv)
  49. {
  50. CEnumNames *penum = NULL;
  51. PENUMRINFO peri = (PENUMRINFO)pv;
  52. HRESULT hr = peri->hResult;
  53. if (SUCCEEDED(hr))
  54. {
  55. // Create a Application enumerator
  56. //
  57. penum = new CEnumNames;
  58. if (penum != NULL)
  59. {
  60. hr = penum->Init((LPTSTR)peri->pv, peri->cItems);
  61. if (SUCCEEDED(hr))
  62. {
  63. penum->AddRef();
  64. }
  65. else
  66. {
  67. delete penum;
  68. penum = NULL;
  69. };
  70. }
  71. else
  72. {
  73. hr = ULS_E_MEMORY;
  74. };
  75. };
  76. // Notify the sink object
  77. //
  78. ((IULSUserNotify*)pUnk)->EnumApplicationsResult(peri->uReqID,
  79. penum != NULL ?
  80. (IEnumULSNames *)penum :
  81. NULL,
  82. hr);
  83. if (penum != NULL)
  84. {
  85. penum->Release();
  86. };
  87. return hr;
  88. }
  89. //****************************************************************************
  90. // Class Implementation
  91. //****************************************************************************
  92. //
  93. //****************************************************************************
  94. // CUlsUser::CUlsUser (void)
  95. //
  96. // History:
  97. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  98. // Created.
  99. //****************************************************************************
  100. CUlsUser::CUlsUser (void)
  101. {
  102. cRef = 0;
  103. szServer = NULL;
  104. szID = NULL;
  105. szFirstName = NULL;
  106. szLastName = NULL;
  107. szEMailName = NULL;
  108. szCityName = NULL;
  109. szCountryName= NULL;
  110. szComment = NULL;
  111. szIPAddr = NULL;
  112. m_dwFlags = 0;
  113. pConnPt = NULL;
  114. return;
  115. }
  116. //****************************************************************************
  117. // CUlsUser::~CUlsUser (void)
  118. //
  119. // History:
  120. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  121. // Created.
  122. //****************************************************************************
  123. CUlsUser::~CUlsUser (void)
  124. {
  125. if (szServer != NULL)
  126. FreeLPTSTR(szServer);
  127. if (szID != NULL)
  128. FreeLPTSTR(szID);
  129. if (szFirstName != NULL)
  130. FreeLPTSTR(szFirstName);
  131. if (szLastName != NULL)
  132. FreeLPTSTR(szLastName);
  133. if (szEMailName != NULL)
  134. FreeLPTSTR(szEMailName);
  135. if (szCityName != NULL)
  136. FreeLPTSTR(szCityName);
  137. if (szCountryName != NULL)
  138. FreeLPTSTR(szCountryName);
  139. if (szComment != NULL)
  140. FreeLPTSTR(szComment);
  141. if (szIPAddr != NULL)
  142. FreeLPTSTR(szIPAddr);
  143. // Release the connection point
  144. //
  145. if (pConnPt != NULL)
  146. {
  147. pConnPt->ContainerReleased();
  148. ((IConnectionPoint*)pConnPt)->Release();
  149. };
  150. return;
  151. }
  152. //****************************************************************************
  153. // STDMETHODIMP
  154. // CUlsUser::Init (LPTSTR szServerName, PLDAP_USERINFO *pui)
  155. //
  156. // History:
  157. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  158. // Created.
  159. //****************************************************************************
  160. STDMETHODIMP
  161. CUlsUser::Init (LPTSTR szServerName, PLDAP_USERINFO pui)
  162. {
  163. HRESULT hr;
  164. // Validate parameter
  165. //
  166. if ((pui->uSize != sizeof(*pui)) ||
  167. (pui->uOffsetName == 0))
  168. {
  169. return ULS_E_PARAMETER;
  170. };
  171. // Remember the server name
  172. //
  173. hr = SafeSetLPTSTR(&szServer, szServerName);
  174. if (SUCCEEDED(hr))
  175. {
  176. hr = SafeSetLPTSTR(&szID, (LPCTSTR)(((PBYTE)pui)+pui->uOffsetName));
  177. if (SUCCEEDED(hr))
  178. {
  179. hr = SafeSetLPTSTR(&szFirstName,
  180. (LPCTSTR)(((PBYTE)pui)+pui->uOffsetFirstName));
  181. if (SUCCEEDED(hr))
  182. {
  183. hr = SafeSetLPTSTR(&szLastName,
  184. (LPCTSTR)(((PBYTE)pui)+pui->uOffsetLastName));
  185. if (SUCCEEDED(hr))
  186. {
  187. hr = SafeSetLPTSTR(&szEMailName,
  188. (LPCTSTR)(((PBYTE)pui)+pui->uOffsetEMailName));
  189. if (SUCCEEDED(hr))
  190. {
  191. hr = SafeSetLPTSTR(&szCityName,
  192. (LPCTSTR)(((PBYTE)pui)+pui->uOffsetCityName));
  193. if (SUCCEEDED(hr))
  194. {
  195. hr = SafeSetLPTSTR(&szCountryName, (LPCTSTR)(((PBYTE)pui)+
  196. pui->uOffsetCountryName));
  197. if (SUCCEEDED(hr))
  198. {
  199. hr = SafeSetLPTSTR(&szComment, (LPCTSTR)(((PBYTE)pui)+
  200. pui->uOffsetComment));
  201. if (SUCCEEDED(hr))
  202. {
  203. hr = SafeSetLPTSTR(&szIPAddr, (LPCTSTR)(((PBYTE)pui)+
  204. pui->uOffsetIPAddress));
  205. m_dwFlags = pui->dwFlags;
  206. };
  207. };
  208. };
  209. };
  210. };
  211. };
  212. };
  213. };
  214. if (SUCCEEDED(hr))
  215. {
  216. // Make the connection point
  217. //
  218. pConnPt = new CConnectionPoint (&IID_IULSUserNotify,
  219. (IConnectionPointContainer *)this);
  220. if (pConnPt != NULL)
  221. {
  222. ((IConnectionPoint*)pConnPt)->AddRef();
  223. hr = NOERROR;
  224. }
  225. else
  226. {
  227. hr = ULS_E_MEMORY;
  228. };
  229. };
  230. return hr;
  231. }
  232. //****************************************************************************
  233. // STDMETHODIMP
  234. // CUlsUser::QueryInterface (REFIID riid, void **ppv)
  235. //
  236. // History:
  237. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  238. // Created.
  239. //****************************************************************************
  240. STDMETHODIMP
  241. CUlsUser::QueryInterface (REFIID riid, void **ppv)
  242. {
  243. *ppv = NULL;
  244. if (riid == IID_IULSUser || riid == IID_IUnknown)
  245. {
  246. *ppv = (IULSUser *) this;
  247. }
  248. else
  249. {
  250. if (riid == IID_IConnectionPointContainer)
  251. {
  252. *ppv = (IConnectionPointContainer *) this;
  253. };
  254. };
  255. if (*ppv != NULL)
  256. {
  257. ((LPUNKNOWN)*ppv)->AddRef();
  258. return S_OK;
  259. }
  260. else
  261. {
  262. return ULS_E_NO_INTERFACE;
  263. };
  264. }
  265. //****************************************************************************
  266. // STDMETHODIMP_(ULONG)
  267. // CUlsUser::AddRef (void)
  268. //
  269. // History:
  270. // Wed 17-Apr-1996 11:14:17 -by- Viroon Touranachun [viroont]
  271. // Created.
  272. //****************************************************************************
  273. STDMETHODIMP_(ULONG)
  274. CUlsUser::AddRef (void)
  275. {
  276. cRef++;
  277. return cRef;
  278. }
  279. //****************************************************************************
  280. // STDMETHODIMP_(ULONG)
  281. // CUlsUser::Release (void)
  282. //
  283. // History:
  284. // Wed 17-Apr-1996 11:14:26 -by- Viroon Touranachun [viroont]
  285. // Created.
  286. //****************************************************************************
  287. STDMETHODIMP_(ULONG)
  288. CUlsUser::Release (void)
  289. {
  290. cRef--;
  291. if (cRef == 0)
  292. {
  293. delete this;
  294. return 0;
  295. }
  296. else
  297. {
  298. return cRef;
  299. };
  300. }
  301. //****************************************************************************
  302. // STDMETHODIMP
  303. // CUlsUser::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  304. //
  305. // History:
  306. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  307. // Created.
  308. //****************************************************************************
  309. STDMETHODIMP
  310. CUlsUser::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  311. {
  312. HRESULT hr = S_OK;
  313. if (pConnPt != NULL)
  314. {
  315. hr = pConnPt->Notify(pv, pfn);
  316. };
  317. return hr;
  318. }
  319. //****************************************************************************
  320. // STDMETHODIMP
  321. // CUlsUser::GetID (BSTR *pbstrID)
  322. //
  323. // History:
  324. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  325. // Created.
  326. //****************************************************************************
  327. STDMETHODIMP
  328. CUlsUser::GetID (BSTR *pbstrID)
  329. {
  330. // Validate parameter
  331. //
  332. if (pbstrID == NULL)
  333. {
  334. return E_POINTER;
  335. };
  336. return LPTSTR_to_BSTR(pbstrID, szID);
  337. }
  338. //****************************************************************************
  339. // STDMETHODIMP
  340. // CUlsUser::GetFirstName (BSTR *pbstrName)
  341. //
  342. // History:
  343. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  344. // Created.
  345. //****************************************************************************
  346. STDMETHODIMP
  347. CUlsUser::GetFirstName (BSTR *pbstrName)
  348. {
  349. // Validate parameter
  350. //
  351. if (pbstrName == NULL)
  352. {
  353. return E_POINTER;
  354. };
  355. return LPTSTR_to_BSTR(pbstrName, szFirstName);
  356. }
  357. //****************************************************************************
  358. // STDMETHODIMP
  359. // CUlsUser::GetLastName (BSTR *pbstrName)
  360. //
  361. // History:
  362. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  363. // Created.
  364. //****************************************************************************
  365. STDMETHODIMP
  366. CUlsUser::GetLastName (BSTR *pbstrName)
  367. {
  368. // Validate parameter
  369. //
  370. if (pbstrName == NULL)
  371. {
  372. return E_POINTER;
  373. };
  374. return LPTSTR_to_BSTR(pbstrName, szLastName);
  375. }
  376. //****************************************************************************
  377. // STDMETHODIMP
  378. // CUlsUser::GetEMailName (BSTR *pbstrName)
  379. //
  380. // History:
  381. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  382. // Created.
  383. //****************************************************************************
  384. STDMETHODIMP
  385. CUlsUser::GetEMailName (BSTR *pbstrName)
  386. {
  387. // Validate parameter
  388. //
  389. if (pbstrName == NULL)
  390. {
  391. return E_POINTER;
  392. };
  393. return LPTSTR_to_BSTR(pbstrName, szEMailName);
  394. }
  395. //****************************************************************************
  396. // STDMETHODIMP
  397. // CUlsUser::GetCityName (BSTR *pbstrName)
  398. //
  399. // History:
  400. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  401. // Created.
  402. //****************************************************************************
  403. STDMETHODIMP
  404. CUlsUser::GetCityName (BSTR *pbstrName)
  405. {
  406. // Validate parameter
  407. //
  408. if (pbstrName == NULL)
  409. {
  410. return E_POINTER;
  411. };
  412. return LPTSTR_to_BSTR(pbstrName, szCityName);
  413. }
  414. //****************************************************************************
  415. // STDMETHODIMP
  416. // CUlsUser::GetCountryName (BSTR *pbstrName)
  417. //
  418. // History:
  419. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  420. // Created.
  421. //****************************************************************************
  422. STDMETHODIMP
  423. CUlsUser::GetCountryName (BSTR *pbstrName)
  424. {
  425. // Validate parameter
  426. //
  427. if (pbstrName == NULL)
  428. {
  429. return E_POINTER;
  430. };
  431. return LPTSTR_to_BSTR(pbstrName, szCountryName);
  432. }
  433. //****************************************************************************
  434. // STDMETHODIMP
  435. // CUlsUser::GetComment (BSTR *pbstrComment)
  436. //
  437. // History:
  438. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  439. // Created.
  440. //****************************************************************************
  441. STDMETHODIMP
  442. CUlsUser::GetComment (BSTR *pbstrComment)
  443. {
  444. // Validate parameter
  445. //
  446. if (pbstrComment == NULL)
  447. {
  448. return E_POINTER;
  449. };
  450. return LPTSTR_to_BSTR(pbstrComment, szComment);
  451. }
  452. //****************************************************************************
  453. // STDMETHODIMP
  454. // CUlsUser::GetFlags ( DWORD *pdwFlags )
  455. //
  456. // History:
  457. // Tue 05-Nov-1996 10:30:00 -by- Chu, Lon-Chan [lonchanc]
  458. // Created.
  459. //****************************************************************************
  460. STDMETHODIMP
  461. CUlsUser::GetFlags ( DWORD *pdwFlags )
  462. {
  463. // Validate parameter
  464. //
  465. if (pdwFlags == NULL)
  466. return ULS_E_POINTER;
  467. *pdwFlags = m_dwFlags;
  468. return S_OK;
  469. }
  470. //****************************************************************************
  471. // STDMETHODIMP
  472. // CUlsUser::GetIPAddress (BSTR *pbstrAddr)
  473. //
  474. // History:
  475. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  476. // Created.
  477. //****************************************************************************
  478. STDMETHODIMP
  479. CUlsUser::GetIPAddress (BSTR *pbstrAddr)
  480. {
  481. // Validate parameter
  482. //
  483. if (pbstrAddr == NULL)
  484. {
  485. return E_POINTER;
  486. };
  487. return LPTSTR_to_BSTR(pbstrAddr, szIPAddr);
  488. }
  489. //****************************************************************************
  490. // STDMETHODIMP
  491. // CUlsUser::GetApplication (REFGUID rguid, ULONG *puReqID)
  492. //
  493. // History:
  494. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  495. // Created.
  496. //****************************************************************************
  497. STDMETHODIMP
  498. CUlsUser::GetApplication (BSTR bstrAppName, IULSAttributes *pAttributes, ULONG *puReqID)
  499. {
  500. LDAP_ASYNCINFO ldai;
  501. LPTSTR pszAppName;
  502. HRESULT hr;
  503. // Validate parameter
  504. //
  505. if (bstrAppName == NULL || puReqID == NULL)
  506. return E_POINTER;
  507. // Convert application name
  508. //
  509. hr = BSTR_to_LPTSTR (&pszAppName, bstrAppName);
  510. if (hr != S_OK)
  511. return hr;
  512. // Get arbitrary attribute name list if any
  513. //
  514. ULONG cAttrNames = 0;
  515. ULONG cbNames = 0;
  516. TCHAR *pszAttrNameList = NULL;
  517. if (pAttributes != NULL)
  518. {
  519. hr = ((CAttributes *) pAttributes)->GetAttributeList (&pszAttrNameList, &cAttrNames, &cbNames);
  520. if (hr != S_OK)
  521. return hr;
  522. }
  523. hr = ::UlsLdap_ResolveApp (szServer, szID, pszAppName,
  524. pszAttrNameList, cAttrNames, &ldai);
  525. if (hr != S_OK)
  526. goto MyExit;
  527. // If updating server was successfully requested, wait for the response
  528. //
  529. REQUESTINFO ri;
  530. ZeroMemory (&ri, sizeof (ri));
  531. ri.uReqType = WM_ULS_RESOLVE_APP;
  532. ri.uMsgID = ldai.uMsgID;
  533. ri.pv = (PVOID) this;
  534. ri.lParam = NULL;
  535. // Remember this request
  536. //
  537. hr = g_pReqMgr->NewRequest (&ri);
  538. if (SUCCEEDED(hr))
  539. {
  540. // Make sure the objects do not disappear before we get the response
  541. //
  542. this->AddRef();
  543. // Return the request ID
  544. //
  545. *puReqID = ri.uReqID;
  546. }
  547. MyExit:
  548. if (pszAttrNameList != NULL)
  549. FreeLPTSTR (pszAttrNameList);
  550. if (pszAppName != NULL)
  551. FreeLPTSTR(pszAppName);
  552. return hr;
  553. }
  554. //****************************************************************************
  555. // STDMETHODIMP
  556. // CUlsUser::GetApplicationResult (ULONG uReqID, PLDAP_APPINFO_RES pair)
  557. //
  558. // History:
  559. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  560. // Created.
  561. //****************************************************************************
  562. STDMETHODIMP
  563. CUlsUser::GetApplicationResult (ULONG uReqID, PLDAP_APPINFO_RES pair)
  564. {
  565. CUlsApp *pa;
  566. OBJRINFO objri;
  567. // Default to the server's result
  568. //
  569. objri.hResult = pair->hResult;
  570. if (SUCCEEDED(objri.hResult))
  571. {
  572. // The server returns APPINFO, create a Application object
  573. //
  574. pa = new CUlsApp;
  575. if (pa != NULL)
  576. {
  577. objri.hResult = pa->Init(szServer, szID, &pair->lai);
  578. if (SUCCEEDED(objri.hResult))
  579. {
  580. pa->AddRef();
  581. }
  582. else
  583. {
  584. delete pa;
  585. pa = NULL;
  586. };
  587. }
  588. else
  589. {
  590. objri.hResult = ULS_E_MEMORY;
  591. };
  592. }
  593. else
  594. {
  595. pa = NULL;
  596. };
  597. // Package the notification info
  598. //
  599. objri.uReqID = uReqID;
  600. objri.pv = (void *)(pa == NULL ? NULL : (IULSApplication *)pa);
  601. NotifySink((void *)&objri, OnNotifyGetApplicationResult);
  602. if (pa != NULL)
  603. {
  604. pa->Release();
  605. };
  606. return NOERROR;
  607. }
  608. //****************************************************************************
  609. // STDMETHODIMP
  610. // CUlsUser::EnumApplications (ULONG *puReqID)
  611. //
  612. // History:
  613. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  614. // Created.
  615. //****************************************************************************
  616. STDMETHODIMP
  617. CUlsUser::EnumApplications (ULONG *puReqID)
  618. {
  619. LDAP_ASYNCINFO ldai;
  620. HRESULT hr;
  621. // Validate parameter
  622. //
  623. if (puReqID == NULL)
  624. {
  625. return E_POINTER;
  626. };
  627. hr = ::UlsLdap_EnumApps(szServer, szID, &ldai);
  628. if (SUCCEEDED(hr))
  629. {
  630. REQUESTINFO ri;
  631. // If updating server was successfully requested, wait for the response
  632. //
  633. ri.uReqType = WM_ULS_ENUM_APPS;
  634. ri.uMsgID = ldai.uMsgID;
  635. ri.pv = (PVOID)this;
  636. ri.lParam = (LPARAM)NULL;
  637. hr = g_pReqMgr->NewRequest(&ri);
  638. if (SUCCEEDED(hr))
  639. {
  640. // Make sure the objects do not disappear before we get the response
  641. //
  642. this->AddRef();
  643. // Return the request ID
  644. //
  645. *puReqID = ri.uReqID;
  646. };
  647. };
  648. return hr;
  649. }
  650. //****************************************************************************
  651. // STDMETHODIMP
  652. // CUlsUser::EnumApplicationsResult (ULONG uReqID, PLDAP_ENUM ple)
  653. //
  654. // History:
  655. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  656. // Created.
  657. //****************************************************************************
  658. STDMETHODIMP
  659. CUlsUser::EnumApplicationsResult (ULONG uReqID, PLDAP_ENUM ple)
  660. {
  661. ENUMRINFO eri;
  662. // Package the notification info
  663. //
  664. eri.uReqID = uReqID;
  665. eri.hResult = ple->hResult;
  666. eri.cItems = ple->cItems;
  667. eri.pv = (void *)(((PBYTE)ple)+ple->uOffsetItems);
  668. NotifySink((void *)&eri, OnNotifyEnumApplicationsResult);
  669. return NOERROR;
  670. }
  671. //****************************************************************************
  672. // STDMETHODIMP
  673. // CUlsUser::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  674. //
  675. // History:
  676. // Wed 17-Apr-1996 11:15:02 -by- Viroon Touranachun [viroont]
  677. // Created.
  678. //****************************************************************************
  679. STDMETHODIMP
  680. CUlsUser::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  681. {
  682. CEnumConnectionPoints *pecp;
  683. HRESULT hr;
  684. // Validate parameters
  685. //
  686. if (ppEnum == NULL)
  687. {
  688. return E_POINTER;
  689. };
  690. // Assume failure
  691. //
  692. *ppEnum = NULL;
  693. // Create an enumerator
  694. //
  695. pecp = new CEnumConnectionPoints;
  696. if (pecp == NULL)
  697. return ULS_E_MEMORY;
  698. // Initialize the enumerator
  699. //
  700. hr = pecp->Init((IConnectionPoint *)pConnPt);
  701. if (FAILED(hr))
  702. {
  703. delete pecp;
  704. return hr;
  705. };
  706. // Give it back to the caller
  707. //
  708. pecp->AddRef();
  709. *ppEnum = pecp;
  710. return S_OK;
  711. }
  712. //****************************************************************************
  713. // STDMETHODIMP
  714. // CUlsUser::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  715. //
  716. // History:
  717. // Wed 17-Apr-1996 11:15:09 -by- Viroon Touranachun [viroont]
  718. // Created.
  719. //****************************************************************************
  720. STDMETHODIMP
  721. CUlsUser::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  722. {
  723. IID siid;
  724. HRESULT hr;
  725. // Validate parameters
  726. //
  727. if (ppcp == NULL)
  728. {
  729. return E_POINTER;
  730. };
  731. // Assume failure
  732. //
  733. *ppcp = NULL;
  734. if (pConnPt != NULL)
  735. {
  736. hr = pConnPt->GetConnectionInterface(&siid);
  737. if (SUCCEEDED(hr))
  738. {
  739. if (riid == siid)
  740. {
  741. *ppcp = (IConnectionPoint *)pConnPt;
  742. (*ppcp)->AddRef();
  743. hr = S_OK;
  744. }
  745. else
  746. {
  747. hr = ULS_E_NO_INTERFACE;
  748. };
  749. };
  750. }
  751. else
  752. {
  753. hr = ULS_E_NO_INTERFACE;
  754. };
  755. return hr;
  756. }
  757. //****************************************************************************
  758. // CEnumUsers::CEnumUsers (void)
  759. //
  760. // History:
  761. // Wed 17-Apr-1996 11:15:18 -by- Viroon Touranachun [viroont]
  762. // Created.
  763. //****************************************************************************
  764. CEnumUsers::CEnumUsers (void)
  765. {
  766. cRef = 0;
  767. ppu = NULL;
  768. cUsers = 0;
  769. iNext = 0;
  770. return;
  771. }
  772. //****************************************************************************
  773. // CEnumUsers::~CEnumUsers (void)
  774. //
  775. // History:
  776. // Wed 17-Apr-1996 11:15:18 -by- Viroon Touranachun [viroont]
  777. // Created.
  778. //****************************************************************************
  779. CEnumUsers::~CEnumUsers (void)
  780. {
  781. ULONG i;
  782. if (ppu != NULL)
  783. {
  784. for (i = 0; i < cUsers; i++)
  785. {
  786. ppu[i]->Release();
  787. };
  788. LocalFree(ppu);
  789. };
  790. return;
  791. }
  792. //****************************************************************************
  793. // STDMETHODIMP
  794. // CEnumUsers::Init (CUlsUser **ppuList, ULONG cUsers)
  795. //
  796. // History:
  797. // Wed 17-Apr-1996 11:15:25 -by- Viroon Touranachun [viroont]
  798. // Created.
  799. //****************************************************************************
  800. STDMETHODIMP
  801. CEnumUsers::Init (CUlsUser **ppuList, ULONG cUsers)
  802. {
  803. HRESULT hr = NOERROR;
  804. // If no list, do nothing
  805. //
  806. if (cUsers != 0)
  807. {
  808. ASSERT(ppuList != NULL);
  809. // Allocate the snapshot buffer
  810. //
  811. ppu = (CUlsUser **)LocalAlloc(LPTR, cUsers*sizeof(CUlsUser *));
  812. if (ppu != NULL)
  813. {
  814. ULONG i;
  815. // Snapshot the object list
  816. //
  817. for (i =0; i < cUsers; i++)
  818. {
  819. ppu[i] = ppuList[i];
  820. ppu[i]->AddRef();
  821. };
  822. this->cUsers = cUsers;
  823. }
  824. else
  825. {
  826. hr = ULS_E_MEMORY;
  827. };
  828. };
  829. return hr;
  830. }
  831. //****************************************************************************
  832. // STDMETHODIMP
  833. // CEnumUsers::QueryInterface (REFIID riid, void **ppv)
  834. //
  835. // History:
  836. // Wed 17-Apr-1996 11:15:31 -by- Viroon Touranachun [viroont]
  837. // Created.
  838. //****************************************************************************
  839. STDMETHODIMP
  840. CEnumUsers::QueryInterface (REFIID riid, void **ppv)
  841. {
  842. if (riid == IID_IEnumULSUsers || riid == IID_IUnknown)
  843. {
  844. *ppv = (IEnumULSUsers *) this;
  845. AddRef();
  846. return S_OK;
  847. }
  848. else
  849. {
  850. *ppv = NULL;
  851. return ULS_E_NO_INTERFACE;
  852. };
  853. }
  854. //****************************************************************************
  855. // STDMETHODIMP_(ULONG)
  856. // CEnumUsers::AddRef (void)
  857. //
  858. // History:
  859. // Wed 17-Apr-1996 11:15:37 -by- Viroon Touranachun [viroont]
  860. // Created.
  861. //****************************************************************************
  862. STDMETHODIMP_(ULONG)
  863. CEnumUsers::AddRef (void)
  864. {
  865. cRef++;
  866. return cRef;
  867. }
  868. //****************************************************************************
  869. // STDMETHODIMP_(ULONG)
  870. // CEnumUsers::Release (void)
  871. //
  872. // History:
  873. // Wed 17-Apr-1996 11:15:43 -by- Viroon Touranachun [viroont]
  874. // Created.
  875. //****************************************************************************
  876. STDMETHODIMP_(ULONG)
  877. CEnumUsers::Release (void)
  878. {
  879. cRef--;
  880. if (cRef == 0)
  881. {
  882. delete this;
  883. return 0;
  884. }
  885. else
  886. {
  887. return cRef;
  888. };
  889. }
  890. //****************************************************************************
  891. // STDMETHODIMP
  892. // CEnumUsers::Next (ULONG cUsers, IULSUser **rgpu, ULONG *pcFetched)
  893. //
  894. // History:
  895. // Wed 17-Apr-1996 11:15:49 -by- Viroon Touranachun [viroont]
  896. // Created.
  897. //****************************************************************************
  898. STDMETHODIMP
  899. CEnumUsers::Next (ULONG cUsers, IULSUser **rgpu, ULONG *pcFetched)
  900. {
  901. ULONG cCopied;
  902. HRESULT hr;
  903. // Validate the pointer
  904. //
  905. if (rgpu == NULL)
  906. return E_POINTER;
  907. // Validate the parameters
  908. //
  909. if ((cUsers == 0) ||
  910. ((cUsers > 1) && (pcFetched == NULL)))
  911. return ULS_E_PARAMETER;
  912. // Check the enumeration index
  913. //
  914. cCopied = 0;
  915. // Can copy if we still have more attribute names
  916. //
  917. while ((cCopied < cUsers) &&
  918. (iNext < this->cUsers))
  919. {
  920. ppu[iNext]->AddRef();
  921. rgpu[cCopied++] = ppu[iNext++];
  922. };
  923. // Determine the returned information based on other parameters
  924. //
  925. if (pcFetched != NULL)
  926. {
  927. *pcFetched = cCopied;
  928. };
  929. return (cUsers == cCopied ? S_OK : S_FALSE);
  930. }
  931. //****************************************************************************
  932. // STDMETHODIMP
  933. // CEnumUsers::Skip (ULONG cUsers)
  934. //
  935. // History:
  936. // Wed 17-Apr-1996 11:15:56 -by- Viroon Touranachun [viroont]
  937. // Created.
  938. //****************************************************************************
  939. STDMETHODIMP
  940. CEnumUsers::Skip (ULONG cUsers)
  941. {
  942. ULONG iNewIndex;
  943. // Validate the parameters
  944. //
  945. if (cUsers == 0)
  946. return ULS_E_PARAMETER;
  947. // Check the enumeration index limit
  948. //
  949. iNewIndex = iNext+cUsers;
  950. if (iNewIndex <= this->cUsers)
  951. {
  952. iNext = iNewIndex;
  953. return S_OK;
  954. }
  955. else
  956. {
  957. iNext = this->cUsers;
  958. return S_FALSE;
  959. };
  960. }
  961. //****************************************************************************
  962. // STDMETHODIMP
  963. // CEnumUsers::Reset (void)
  964. //
  965. // History:
  966. // Wed 17-Apr-1996 11:16:02 -by- Viroon Touranachun [viroont]
  967. // Created.
  968. //****************************************************************************
  969. STDMETHODIMP
  970. CEnumUsers::Reset (void)
  971. {
  972. iNext = 0;
  973. return S_OK;
  974. }
  975. //****************************************************************************
  976. // STDMETHODIMP
  977. // CEnumUsers::Clone(IEnumULSUsers **ppEnum)
  978. //
  979. // History:
  980. // Wed 17-Apr-1996 11:16:11 -by- Viroon Touranachun [viroont]
  981. // Created.
  982. //****************************************************************************
  983. STDMETHODIMP
  984. CEnumUsers::Clone(IEnumULSUsers **ppEnum)
  985. {
  986. CEnumUsers *peu;
  987. HRESULT hr;
  988. // Validate parameters
  989. //
  990. if (ppEnum == NULL)
  991. {
  992. return E_POINTER;
  993. };
  994. *ppEnum = NULL;
  995. // Create an enumerator
  996. //
  997. peu = new CEnumUsers;
  998. if (peu == NULL)
  999. return ULS_E_MEMORY;
  1000. // Clone the information
  1001. //
  1002. hr = peu->Init(ppu, cUsers);
  1003. if (SUCCEEDED(hr))
  1004. {
  1005. peu->iNext = iNext;
  1006. // Return the cloned enumerator
  1007. //
  1008. peu->AddRef();
  1009. *ppEnum = peu;
  1010. }
  1011. else
  1012. {
  1013. delete peu;
  1014. };
  1015. return hr;
  1016. }