Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1415 lines
35 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: localapp.cpp
  5. // Content: This file contains the LocalApplication 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 "localapp.h"
  14. #include "localprt.h"
  15. #include "attribs.h"
  16. #include "callback.h"
  17. #include "culs.h"
  18. //****************************************************************************
  19. // Event Notifiers
  20. //****************************************************************************
  21. //
  22. //****************************************************************************
  23. // HRESULT
  24. // OnNotifyLocalAppAttributesChangeResult (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. OnNotifyLocalAppAttributesChangeResult (IUnknown *pUnk, void *pv)
  32. {
  33. PSRINFO psri = (PSRINFO)pv;
  34. ((IULSLocalAppNotify*)pUnk)->AttributesChangeResult(psri->uReqID,
  35. psri->hResult);
  36. return S_OK;
  37. }
  38. //****************************************************************************
  39. // HRESULT
  40. // OnNotifyLocalAppProtocolChangeResult (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. OnNotifyLocalAppProtocolChangeResult (IUnknown *pUnk, void *pv)
  48. {
  49. PSRINFO psri = (PSRINFO)pv;
  50. ((IULSLocalAppNotify*)pUnk)->ProtocolChangeResult(psri->uReqID,
  51. psri->hResult);
  52. return S_OK;
  53. }
  54. //****************************************************************************
  55. // Class Implementation
  56. //****************************************************************************
  57. //
  58. //****************************************************************************
  59. // CLocalApp::CLocalApp (void)
  60. //
  61. // History:
  62. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  63. // Created.
  64. //****************************************************************************
  65. CLocalApp::CLocalApp (void)
  66. {
  67. cRef = 0;
  68. szName = NULL;
  69. guid = GUID_NULL;
  70. szMimeType = NULL;
  71. pAttrs = NULL;
  72. pConnPt = NULL;
  73. return;
  74. }
  75. //****************************************************************************
  76. // CLocalApp::~CLocalApp (void)
  77. //
  78. // History:
  79. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  80. // Created.
  81. //****************************************************************************
  82. CLocalApp::~CLocalApp (void)
  83. {
  84. CLocalProt *plp;
  85. HANDLE hEnum;
  86. // Release the connection point
  87. //
  88. if (pConnPt != NULL)
  89. {
  90. pConnPt->ContainerReleased();
  91. ((IConnectionPoint*)pConnPt)->Release();
  92. };
  93. // Release the protocol objects
  94. //
  95. ProtList.Enumerate(&hEnum);
  96. while(ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR)
  97. {
  98. plp->Release();
  99. };
  100. ProtList.Flush();
  101. // Release the attributes object
  102. //
  103. if (pAttrs != NULL)
  104. {
  105. pAttrs->Release();
  106. };
  107. // Release the buffer resources
  108. //
  109. if (szName != NULL)
  110. {
  111. FreeLPTSTR(szName);
  112. };
  113. if (szMimeType != NULL)
  114. {
  115. FreeLPTSTR(szMimeType);
  116. };
  117. return;
  118. }
  119. //****************************************************************************
  120. // STDMETHODIMP
  121. // CLocalApp::Init (BSTR bstrName, REFGUID rguid, BSTR bstrMimeType)
  122. //
  123. // History:
  124. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  125. // Created.
  126. //****************************************************************************
  127. STDMETHODIMP
  128. CLocalApp::Init (BSTR bstrName, REFGUID rguid, BSTR bstrMimeType)
  129. {
  130. HRESULT hr;
  131. // Cache the application information
  132. //
  133. guid = rguid;
  134. hr = BSTR_to_LPTSTR(&szName, bstrName);
  135. if (SUCCEEDED(hr))
  136. {
  137. hr = BSTR_to_LPTSTR(&szMimeType, bstrMimeType);
  138. if (SUCCEEDED(hr))
  139. {
  140. // Initialize the attributes list
  141. //
  142. pAttrs = new CAttributes (ULS_ATTRACCESS_NAME_VALUE);
  143. if (pAttrs != NULL)
  144. {
  145. // Make the connection point
  146. //
  147. pConnPt = new CConnectionPoint (&IID_IULSLocalAppNotify,
  148. (IConnectionPointContainer *)this);
  149. if (pConnPt != NULL)
  150. {
  151. ((IConnectionPoint*)pConnPt)->AddRef();
  152. hr = NOERROR;
  153. }
  154. else
  155. {
  156. hr = ULS_E_MEMORY;
  157. };
  158. }
  159. else
  160. {
  161. hr = ULS_E_MEMORY;
  162. };
  163. };
  164. };
  165. return hr;
  166. }
  167. //****************************************************************************
  168. // STDMETHODIMP
  169. // CLocalApp::QueryInterface (REFIID riid, void **ppv)
  170. //
  171. // History:
  172. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  173. // Created.
  174. //****************************************************************************
  175. STDMETHODIMP
  176. CLocalApp::QueryInterface (REFIID riid, void **ppv)
  177. {
  178. *ppv = NULL;
  179. if (riid == IID_IULSLocalApplication || riid == IID_IUnknown)
  180. {
  181. *ppv = (IULS *) this;
  182. }
  183. else
  184. {
  185. if (riid == IID_IConnectionPointContainer)
  186. {
  187. *ppv = (IConnectionPointContainer *) this;
  188. };
  189. };
  190. if (*ppv != NULL)
  191. {
  192. ((LPUNKNOWN)*ppv)->AddRef();
  193. return S_OK;
  194. }
  195. else
  196. {
  197. return ULS_E_NO_INTERFACE;
  198. };
  199. }
  200. //****************************************************************************
  201. // STDMETHODIMP_(ULONG)
  202. // CLocalApp::AddRef (void)
  203. //
  204. // History:
  205. // Wed 17-Apr-1996 11:14:17 -by- Viroon Touranachun [viroont]
  206. // Created.
  207. //****************************************************************************
  208. STDMETHODIMP_(ULONG)
  209. CLocalApp::AddRef (void)
  210. {
  211. cRef++;
  212. return cRef;
  213. }
  214. //****************************************************************************
  215. // STDMETHODIMP_(ULONG)
  216. // CLocalApp::Release (void)
  217. //
  218. // History:
  219. // Wed 17-Apr-1996 11:14:26 -by- Viroon Touranachun [viroont]
  220. // Created.
  221. //****************************************************************************
  222. STDMETHODIMP_(ULONG)
  223. CLocalApp::Release (void)
  224. {
  225. cRef--;
  226. if (cRef == 0)
  227. {
  228. delete this;
  229. return 0;
  230. }
  231. else
  232. {
  233. return cRef;
  234. };
  235. }
  236. //****************************************************************************
  237. // STDMETHODIMP
  238. // CLocalApp::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  239. //
  240. // History:
  241. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  242. // Created.
  243. //****************************************************************************
  244. STDMETHODIMP
  245. CLocalApp::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  246. {
  247. HRESULT hr = S_OK;
  248. if (pConnPt != NULL)
  249. {
  250. hr = pConnPt->Notify(pv, pfn);
  251. };
  252. return hr;
  253. }
  254. //****************************************************************************
  255. // STDMETHODIMP
  256. // CLocalApp::AttributesChangeResult (CAttributes *pAttributes,
  257. // ULONG uReqID, HRESULT hResult,
  258. // APP_CHANGE_ATTRS uCmd)
  259. //
  260. // History:
  261. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  262. // Created.
  263. //****************************************************************************
  264. STDMETHODIMP
  265. CLocalApp::AttributesChangeResult (CAttributes *pAttributes,
  266. ULONG uReqID, HRESULT hResult,
  267. APP_CHANGE_ATTRS uCmd)
  268. {
  269. SRINFO sri;
  270. // If the server accepts the changes, modify the local information
  271. //
  272. if (SUCCEEDED(hResult))
  273. {
  274. // Update based on the command.
  275. //
  276. switch(uCmd)
  277. {
  278. case ULS_APP_SET_ATTRIBUTES:
  279. hResult = pAttrs->SetAttributes(pAttributes);
  280. break;
  281. case ULS_APP_REMOVE_ATTRIBUTES:
  282. hResult = pAttrs->RemoveAttributes(pAttributes);
  283. break;
  284. default:
  285. ASSERT(0);
  286. break;
  287. };
  288. };
  289. // Notify the sink object
  290. //
  291. sri.uReqID = uReqID;
  292. sri.hResult = hResult;
  293. hResult = NotifySink((void *)&sri, OnNotifyLocalAppAttributesChangeResult);
  294. #ifdef DEBUG
  295. DPRINTF (TEXT("CLocalApp--current attributes********************\r\n"));
  296. pAttrs->DebugOut();
  297. DPRINTF (TEXT("\r\n*************************************************"));
  298. #endif // DEBUG;
  299. return hResult;
  300. }
  301. //****************************************************************************
  302. // STDMETHODIMP
  303. // CLocalApp::ProtocolChangeResult (CLocalProt *pProtocol,
  304. // ULONG uReqID, HRESULT hResult,
  305. // APP_CHANGE_PROT uCmd)
  306. //
  307. // History:
  308. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  309. // Created.
  310. //****************************************************************************
  311. STDMETHODIMP
  312. CLocalApp::ProtocolChangeResult (CLocalProt *pProtocol,
  313. ULONG uReqID, HRESULT hResult,
  314. APP_CHANGE_PROT uCmd)
  315. {
  316. SRINFO sri;
  317. // If the server accepts the changes, modify the local information
  318. //
  319. if (SUCCEEDED(hResult))
  320. {
  321. // Update based on the command.
  322. //
  323. switch(uCmd)
  324. {
  325. case ULS_APP_ADD_PROT:
  326. hResult = ProtList.Insert((PVOID)pProtocol);
  327. if (SUCCEEDED(hResult))
  328. {
  329. pProtocol->AddRef();
  330. };
  331. break;
  332. case ULS_APP_REMOVE_PROT:
  333. hResult = ProtList.Remove((PVOID)pProtocol);
  334. if (SUCCEEDED(hResult))
  335. {
  336. pProtocol->Release();
  337. };
  338. break;
  339. default:
  340. ASSERT(0);
  341. break;
  342. };
  343. };
  344. // Notify the sink object
  345. //
  346. sri.uReqID = uReqID;
  347. sri.hResult = hResult;
  348. hResult = NotifySink((void *)&sri, OnNotifyLocalAppProtocolChangeResult);
  349. #ifdef DEBUG
  350. DPRINTF (TEXT("CLocalApp--current Protocols********************\r\n"));
  351. DebugProtocolDump();
  352. DPRINTF (TEXT("\r\n*************************************************"));
  353. #endif // DEBUG;
  354. return hResult;
  355. }
  356. //****************************************************************************
  357. // STDMETHODIMP
  358. // CLocalApp::CreateProtocol (BSTR bstrProtocolID, ULONG uPortNumber,
  359. // BSTR bstrMimeType,
  360. // IULSLocalAppProtocol **ppProtocol)
  361. //
  362. // History:
  363. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  364. // Created.
  365. //****************************************************************************
  366. STDMETHODIMP
  367. CLocalApp::CreateProtocol (BSTR bstrProtocolID, ULONG uPortNumber,
  368. BSTR bstrMimeType,
  369. IULSLocalAppProtocol **ppProtocol)
  370. {
  371. CLocalProt *plp;
  372. HRESULT hr;
  373. // Validate parameter
  374. //
  375. if (ppProtocol == NULL)
  376. {
  377. return ULS_E_POINTER;
  378. };
  379. // Assume failure
  380. //
  381. *ppProtocol = NULL;
  382. // Create a new object
  383. //
  384. plp = new CLocalProt;
  385. if (plp != NULL)
  386. {
  387. hr = plp->Init(bstrProtocolID, uPortNumber, bstrMimeType);
  388. if (SUCCEEDED(hr))
  389. {
  390. plp->AddRef();
  391. *ppProtocol = plp;
  392. };
  393. }
  394. else
  395. {
  396. hr = ULS_E_MEMORY;
  397. };
  398. return hr;
  399. }
  400. //****************************************************************************
  401. // STDMETHODIMP
  402. // CLocalApp::ChangeProtocol (IULSLocalAppProtocol *pProtocol,
  403. // ULONG *puReqID, APP_CHANGE_PROT uCmd)
  404. //
  405. // History:
  406. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  407. // Created.
  408. //****************************************************************************
  409. STDMETHODIMP
  410. CLocalApp::ChangeProtocol (IULSLocalAppProtocol *pProtocol,
  411. ULONG *puReqID, APP_CHANGE_PROT uCmd)
  412. {
  413. CLocalProt *plp;
  414. PVOID pv;
  415. HRESULT hr;
  416. HANDLE hLdapApp;
  417. LDAP_ASYNCINFO ldai;
  418. HANDLE hEnum;
  419. // Validate parameters
  420. //
  421. if ((pProtocol == NULL) ||
  422. (puReqID == NULL))
  423. {
  424. return ULS_E_POINTER;
  425. };
  426. hr = pProtocol->QueryInterface(IID_IULSLocalAppProtocol, &pv);
  427. if (FAILED(hr))
  428. {
  429. return ULS_E_PARAMETER;
  430. };
  431. pProtocol->Release();
  432. // Check whether the protocol exists
  433. //
  434. ProtList.Enumerate(&hEnum);
  435. while(ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR)
  436. {
  437. if (plp->IsSameAs((CLocalProt *)pProtocol) == NOERROR)
  438. {
  439. break;
  440. };
  441. };
  442. if (plp != NULL)
  443. {
  444. // The protocol exists, fail if this add request
  445. //
  446. if (uCmd == ULS_APP_ADD_PROT)
  447. {
  448. return ULS_E_PARAMETER;
  449. };
  450. }
  451. else
  452. {
  453. // The protocol does not exist, fail if this remove request
  454. //
  455. if (uCmd == ULS_APP_REMOVE_PROT)
  456. {
  457. return ULS_E_PARAMETER;
  458. };
  459. };
  460. // Update the server information first
  461. //
  462. switch (uCmd)
  463. {
  464. case ULS_APP_ADD_PROT:
  465. hr = g_pCUls->RegisterLocalProtocol((CLocalProt*)pProtocol, &ldai);
  466. break;
  467. case ULS_APP_REMOVE_PROT:
  468. hr = g_pCUls->UnregisterLocalProtocol((CLocalProt*)pProtocol, &ldai);
  469. break;
  470. default:
  471. ASSERT(0);
  472. break;
  473. };
  474. switch (hr)
  475. {
  476. case NOERROR:
  477. //
  478. // Server starts updating the protocol successfullly
  479. // We will wait for the server response.
  480. //
  481. break;
  482. case S_FALSE:
  483. //
  484. // We have not registered, will do local response
  485. //
  486. hr = NOERROR;
  487. ldai.uMsgID = 0;
  488. break;
  489. default:
  490. // ULS is locked. Return failure.
  491. //
  492. hr = ULS_E_ABORT;
  493. break;
  494. }
  495. if (SUCCEEDED(hr))
  496. {
  497. REQUESTINFO ri;
  498. ULONG uMsg;
  499. switch(uCmd)
  500. {
  501. case ULS_APP_ADD_PROT:
  502. uMsg = (ldai.uMsgID == 0 ? WM_ULS_LOCAL_REGISTER_PROTOCOL:
  503. WM_ULS_REGISTER_PROTOCOL);
  504. break;
  505. case ULS_APP_REMOVE_PROT:
  506. uMsg = (ldai.uMsgID == 0 ? WM_ULS_LOCAL_UNREGISTER_PROTOCOL :
  507. WM_ULS_UNREGISTER_PROTOCOL);
  508. break;
  509. default:
  510. ASSERT(0);
  511. break;
  512. };
  513. // If updating server was successfully requested, wait for the response
  514. //
  515. ri.uReqType = uMsg;
  516. ri.uMsgID = ldai.uMsgID;
  517. ri.pv = (PVOID)this;
  518. ri.lParam = (LPARAM)((CLocalProt*)pProtocol);
  519. hr = g_pReqMgr->NewRequest(&ri);
  520. if (SUCCEEDED(hr))
  521. {
  522. // Make sure the objects do not disappear before we get the response
  523. //
  524. this->AddRef();
  525. pProtocol->AddRef();
  526. // Return the request ID
  527. //
  528. *puReqID = ri.uReqID;
  529. // If not registered with server, start async response ourselves
  530. //
  531. if (ldai.uMsgID == 0)
  532. {
  533. g_pCUls->LocalAsyncRespond(uMsg, ri.uReqID, NOERROR);
  534. };
  535. };
  536. };
  537. return hr;
  538. }
  539. //****************************************************************************
  540. // STDMETHODIMP
  541. // CLocalApp::AddProtocol (IULSLocalAppProtocol *pProtocol,
  542. // ULONG *puReqID)
  543. //
  544. // History:
  545. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  546. // Created.
  547. //****************************************************************************
  548. STDMETHODIMP
  549. CLocalApp::AddProtocol (IULSLocalAppProtocol *pProtocol,
  550. ULONG *puReqID)
  551. {
  552. return ChangeProtocol(pProtocol, puReqID, ULS_APP_ADD_PROT);
  553. }
  554. //****************************************************************************
  555. // STDMETHODIMP
  556. // CLocalApp::RemoveProtocol (IULSLocalAppProtocol *pProtocol,
  557. // ULONG *puReqID)
  558. //
  559. // History:
  560. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  561. // Created.
  562. //****************************************************************************
  563. STDMETHODIMP
  564. CLocalApp::RemoveProtocol (IULSLocalAppProtocol *pProtocol,
  565. ULONG *puReqID)
  566. {
  567. return ChangeProtocol(pProtocol, puReqID, ULS_APP_REMOVE_PROT);
  568. }
  569. //****************************************************************************
  570. // STDMETHODIMP
  571. // CLocalApp::EnumProtocols (IEnumULSLocalAppProtocols **ppEnumProtocol)
  572. //
  573. // History:
  574. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  575. // Created.
  576. //****************************************************************************
  577. STDMETHODIMP
  578. CLocalApp::EnumProtocols (IEnumULSLocalAppProtocols **ppEnumProtocol)
  579. {
  580. CEnumLocalAppProtocols *pep;
  581. HRESULT hr;
  582. // Validate parameters
  583. //
  584. if (ppEnumProtocol == NULL)
  585. {
  586. return ULS_E_POINTER;
  587. };
  588. // Assume failure
  589. //
  590. *ppEnumProtocol = NULL;
  591. // Create a peer enumerator
  592. //
  593. pep = new CEnumLocalAppProtocols;
  594. if (pep != NULL)
  595. {
  596. hr = pep->Init(&ProtList);
  597. if (SUCCEEDED(hr))
  598. {
  599. // Get the enumerator interface
  600. //
  601. pep->AddRef();
  602. *ppEnumProtocol = pep;
  603. }
  604. else
  605. {
  606. delete pep;
  607. };
  608. }
  609. else
  610. {
  611. hr = ULS_E_MEMORY;
  612. };
  613. return hr;
  614. }
  615. //****************************************************************************
  616. // STDMETHODIMP
  617. // CLocalApp::ChangeAttributes (IULSAttributes *pAttributes, ULONG *puReqID,
  618. // APP_CHANGE_ATTRS uCmd)
  619. //
  620. // History:
  621. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  622. // Created.
  623. //****************************************************************************
  624. STDMETHODIMP
  625. CLocalApp::ChangeAttributes (IULSAttributes *pAttributes, ULONG *puReqID,
  626. APP_CHANGE_ATTRS uCmd)
  627. {
  628. PVOID pv;
  629. HRESULT hr;
  630. HANDLE hLdapApp;
  631. LDAP_ASYNCINFO ldai;
  632. // Validate parameters
  633. //
  634. if ((pAttributes == NULL) ||
  635. (puReqID == NULL))
  636. {
  637. return ULS_E_POINTER;
  638. };
  639. hr = pAttributes->QueryInterface(IID_IULSAttributes, &pv);
  640. if (FAILED(hr))
  641. {
  642. return ULS_E_PARAMETER;
  643. };
  644. // If no attributes, fails the call
  645. //
  646. if (((CAttributes*)pAttributes)->GetCount() == 0)
  647. {
  648. return ULS_E_PARAMETER;
  649. };
  650. // Check if already registered
  651. //
  652. hr = g_pCUls->GetAppHandle(&hLdapApp);
  653. switch (hr)
  654. {
  655. case NOERROR:
  656. {
  657. LPTSTR pAttrList;
  658. ULONG cAttrs, cb;
  659. // Yes, get the attributes list
  660. //
  661. switch (uCmd)
  662. {
  663. case ULS_APP_SET_ATTRIBUTES:
  664. hr = ((CAttributes*)pAttributes)->GetAttributePairs(&pAttrList,
  665. &cAttrs,
  666. &cb);
  667. if (SUCCEEDED(hr))
  668. {
  669. hr = ::UlsLdap_SetAppAttrs(hLdapApp, cAttrs, pAttrList,
  670. &ldai);
  671. FreeLPTSTR(pAttrList);
  672. };
  673. break;
  674. case ULS_APP_REMOVE_ATTRIBUTES:
  675. hr = ((CAttributes*)pAttributes)->GetAttributeList(&pAttrList,
  676. &cAttrs,
  677. &cb);
  678. if (SUCCEEDED(hr))
  679. {
  680. hr = ::UlsLdap_RemoveAppAttrs(hLdapApp, cAttrs, pAttrList,
  681. &ldai);
  682. FreeLPTSTR(pAttrList);
  683. };
  684. break;
  685. default:
  686. ASSERT(0);
  687. break;
  688. };
  689. break;
  690. }
  691. case S_FALSE:
  692. //
  693. // Not registered, will do local response
  694. //
  695. hr = NOERROR;
  696. ldai.uMsgID = 0;
  697. break;
  698. default:
  699. // ULS is locked. Return failure.
  700. //
  701. hr = ULS_E_ABORT;
  702. break;
  703. };
  704. if (SUCCEEDED(hr))
  705. {
  706. REQUESTINFO ri;
  707. ULONG uMsg;
  708. switch(uCmd)
  709. {
  710. case ULS_APP_SET_ATTRIBUTES:
  711. uMsg = (ldai.uMsgID == 0 ? WM_ULS_LOCAL_SET_APP_ATTRS :
  712. WM_ULS_SET_APP_ATTRS);
  713. break;
  714. case ULS_APP_REMOVE_ATTRIBUTES:
  715. uMsg = (ldai.uMsgID == 0 ? WM_ULS_LOCAL_REMOVE_APP_ATTRS :
  716. WM_ULS_REMOVE_APP_ATTRS);
  717. break;
  718. default:
  719. ASSERT(0);
  720. break;
  721. };
  722. // If updating server was successfully requested, wait for the response
  723. //
  724. ri.uReqType = uMsg;
  725. ri.uMsgID = ldai.uMsgID;
  726. ri.pv = (PVOID)this;
  727. ri.lParam = (LPARAM)((CAttributes *)pAttributes);
  728. hr = g_pReqMgr->NewRequest(&ri);
  729. if (SUCCEEDED(hr))
  730. {
  731. // Make sure the objects do not disappear before we get the response
  732. //
  733. this->AddRef();
  734. pAttributes->AddRef();
  735. // Return the request ID
  736. //
  737. *puReqID = ri.uReqID;
  738. // If not registered with server, start async response ourselves
  739. //
  740. if (ldai.uMsgID == 0)
  741. {
  742. g_pCUls->LocalAsyncRespond(uMsg, ri.uReqID, NOERROR);
  743. };
  744. };
  745. };
  746. // Matching the QueryInterface
  747. //
  748. pAttributes->Release();
  749. return hr;
  750. }
  751. //****************************************************************************
  752. // STDMETHODIMP
  753. // CLocalApp::SetAttributes (IULSAttributes *pAttributes, ULONG *puReqID)
  754. //
  755. // History:
  756. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  757. // Created.
  758. //****************************************************************************
  759. STDMETHODIMP
  760. CLocalApp::SetAttributes (IULSAttributes *pAttributes, ULONG *puReqID)
  761. {
  762. return ChangeAttributes(pAttributes, puReqID, ULS_APP_SET_ATTRIBUTES);
  763. }
  764. //****************************************************************************
  765. // STDMETHODIMP
  766. // CLocalApp::RemoveAttributes (IULSAttributes *pAttributes, ULONG *puReqID)
  767. //
  768. // History:
  769. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  770. // Created.
  771. //****************************************************************************
  772. STDMETHODIMP
  773. CLocalApp::RemoveAttributes (IULSAttributes *pAttributes, ULONG *puReqID)
  774. {
  775. return ChangeAttributes(pAttributes, puReqID, ULS_APP_REMOVE_ATTRIBUTES);
  776. }
  777. //****************************************************************************
  778. // STDMETHODIMP
  779. // CLocalApp::GetAppInfo (PLDAP_APPINFO *ppAppInfo)
  780. //
  781. // History:
  782. // Wed 17-Apr-1996 11:15:02 -by- Viroon Touranachun [viroont]
  783. // Created.
  784. //****************************************************************************
  785. STDMETHODIMP
  786. CLocalApp::GetAppInfo (PLDAP_APPINFO *ppAppInfo)
  787. {
  788. PLDAP_APPINFO pai;
  789. ULONG cName, cMime;
  790. LPTSTR szAttrs;
  791. ULONG cAttrs, cbAttrs;
  792. HRESULT hr;
  793. // Assume failure
  794. //
  795. *ppAppInfo = NULL;
  796. // Calculate the buffer size
  797. //
  798. cName = lstrlen(szName)+1;
  799. cMime = lstrlen(szMimeType)+1;
  800. // Get the attribute pairs
  801. //
  802. hr = pAttrs->GetAttributePairs(&szAttrs, &cAttrs, &cbAttrs);
  803. if (FAILED(hr))
  804. {
  805. return hr;
  806. };
  807. // Allocate the buffer
  808. //
  809. pai = (PLDAP_APPINFO)LocalAlloc(LPTR, sizeof(LDAP_APPINFO) +
  810. ((cName + cMime)* sizeof(TCHAR)) +
  811. cbAttrs);
  812. if (pai == NULL)
  813. {
  814. hr = ULS_E_MEMORY;
  815. }
  816. else
  817. {
  818. // Fill the structure content
  819. //
  820. pai->uSize = sizeof(*pai);
  821. pai->guid = guid;
  822. pai->uOffsetName = sizeof(*pai);
  823. pai->uOffsetMimeType = pai->uOffsetName + (cName*sizeof(TCHAR));
  824. pai->cAttributes = cAttrs;
  825. pai->uOffsetAttributes = (cAttrs != 0 ?
  826. pai->uOffsetMimeType + (cMime*sizeof(TCHAR)) :
  827. 0);
  828. // Copy the user information
  829. //
  830. lstrcpy((LPTSTR)(((PBYTE)pai)+pai->uOffsetName), szName);
  831. lstrcpy((LPTSTR)(((PBYTE)pai)+pai->uOffsetMimeType), szMimeType);
  832. if (cAttrs)
  833. {
  834. CopyMemory(((PBYTE)pai)+pai->uOffsetAttributes, szAttrs, cbAttrs);
  835. };
  836. // Return the structure
  837. //
  838. *ppAppInfo = pai;
  839. };
  840. if (szAttrs != NULL)
  841. {
  842. FreeLPTSTR(szAttrs);
  843. };
  844. return NOERROR;
  845. }
  846. //****************************************************************************
  847. // STDMETHODIMP
  848. // CLocalApp::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  849. //
  850. // History:
  851. // Wed 17-Apr-1996 11:15:02 -by- Viroon Touranachun [viroont]
  852. // Created.
  853. //****************************************************************************
  854. STDMETHODIMP
  855. CLocalApp::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  856. {
  857. CEnumConnectionPoints *pecp;
  858. HRESULT hr;
  859. // Validate parameters
  860. //
  861. if (ppEnum == NULL)
  862. {
  863. return ULS_E_POINTER;
  864. };
  865. // Assume failure
  866. //
  867. *ppEnum = NULL;
  868. // Create an enumerator
  869. //
  870. pecp = new CEnumConnectionPoints;
  871. if (pecp == NULL)
  872. return ULS_E_MEMORY;
  873. // Initialize the enumerator
  874. //
  875. hr = pecp->Init((IConnectionPoint *)pConnPt);
  876. if (FAILED(hr))
  877. {
  878. delete pecp;
  879. return hr;
  880. };
  881. // Give it back to the caller
  882. //
  883. pecp->AddRef();
  884. *ppEnum = pecp;
  885. return S_OK;
  886. }
  887. //****************************************************************************
  888. // STDMETHODIMP
  889. // CLocalApp::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  890. //
  891. // History:
  892. // Wed 17-Apr-1996 11:15:09 -by- Viroon Touranachun [viroont]
  893. // Created.
  894. //****************************************************************************
  895. STDMETHODIMP
  896. CLocalApp::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  897. {
  898. IID siid;
  899. HRESULT hr;
  900. // Validate parameters
  901. //
  902. if (ppcp == NULL)
  903. {
  904. return ULS_E_POINTER;
  905. };
  906. // Assume failure
  907. //
  908. *ppcp = NULL;
  909. if (pConnPt != NULL)
  910. {
  911. hr = pConnPt->GetConnectionInterface(&siid);
  912. if (SUCCEEDED(hr))
  913. {
  914. if (riid == siid)
  915. {
  916. *ppcp = (IConnectionPoint *)pConnPt;
  917. (*ppcp)->AddRef();
  918. hr = S_OK;
  919. }
  920. else
  921. {
  922. hr = ULS_E_NO_INTERFACE;
  923. };
  924. };
  925. }
  926. else
  927. {
  928. hr = ULS_E_NO_INTERFACE;
  929. };
  930. return hr;
  931. }
  932. #ifdef DEBUG
  933. //****************************************************************************
  934. // void
  935. // CLocalApp::DebugProtocolDump (void)
  936. //
  937. // History:
  938. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  939. // Created.
  940. //****************************************************************************
  941. void
  942. CLocalApp::DebugProtocolDump (void)
  943. {
  944. CLocalProt *plp;
  945. BSTR bstrID;
  946. LPTSTR pszID;
  947. ULONG cCount;
  948. HANDLE hEnum;
  949. // Each protocol
  950. //
  951. cCount = 1;
  952. ProtList.Enumerate(&hEnum);
  953. while(ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR)
  954. {
  955. if (SUCCEEDED(plp->GetID (&bstrID)))
  956. {
  957. BSTR_to_LPTSTR(&pszID, bstrID);
  958. DPRINTF2(TEXT("%d> %s"), cCount++, pszID);
  959. FreeLPTSTR(pszID);
  960. SysFreeString(bstrID);
  961. };
  962. };
  963. return;
  964. }
  965. #endif // DEBUG
  966. //****************************************************************************
  967. // CEnumLocalAppProtocols::CEnumLocalAppProtocols (void)
  968. //
  969. // History:
  970. // Wed 17-Apr-1996 11:15:18 -by- Viroon Touranachun [viroont]
  971. // Created.
  972. //****************************************************************************
  973. CEnumLocalAppProtocols::CEnumLocalAppProtocols (void)
  974. {
  975. cRef = 0;
  976. hEnum = NULL;
  977. return;
  978. }
  979. //****************************************************************************
  980. // CEnumLocalAppProtocols::~CEnumLocalAppProtocols (void)
  981. //
  982. // History:
  983. // Wed 17-Apr-1996 11:15:18 -by- Viroon Touranachun [viroont]
  984. // Created.
  985. //****************************************************************************
  986. CEnumLocalAppProtocols::~CEnumLocalAppProtocols (void)
  987. {
  988. CLocalProt *plp;
  989. ProtList.Enumerate(&hEnum);
  990. while(ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR)
  991. {
  992. plp->Release();
  993. };
  994. ProtList.Flush();
  995. return;
  996. }
  997. //****************************************************************************
  998. // STDMETHODIMP
  999. // CEnumLocalAppProtocols::Init (CList *pProtList)
  1000. //
  1001. // History:
  1002. // Wed 17-Apr-1996 11:15:25 -by- Viroon Touranachun [viroont]
  1003. // Created.
  1004. //****************************************************************************
  1005. STDMETHODIMP
  1006. CEnumLocalAppProtocols::Init (CList *pProtList)
  1007. {
  1008. CLocalProt *plp;
  1009. HRESULT hr;
  1010. // Duplicate the protocol list
  1011. //
  1012. hr = ProtList.Clone (pProtList, NULL);
  1013. if (SUCCEEDED(hr))
  1014. {
  1015. // Add reference to each protocol object
  1016. //
  1017. ProtList.Enumerate(&hEnum);
  1018. while(ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR)
  1019. {
  1020. plp->AddRef();
  1021. };
  1022. // Reset the enumerator
  1023. //
  1024. ProtList.Enumerate(&hEnum);
  1025. };
  1026. return hr;
  1027. }
  1028. //****************************************************************************
  1029. // STDMETHODIMP
  1030. // CEnumLocalAppProtocols::QueryInterface (REFIID riid, void **ppv)
  1031. //
  1032. // History:
  1033. // Wed 17-Apr-1996 11:15:31 -by- Viroon Touranachun [viroont]
  1034. // Created.
  1035. //****************************************************************************
  1036. STDMETHODIMP
  1037. CEnumLocalAppProtocols::QueryInterface (REFIID riid, void **ppv)
  1038. {
  1039. if (riid == IID_IEnumULSLocalAppProtocols || riid == IID_IUnknown)
  1040. {
  1041. *ppv = (IEnumULSLocalAppProtocols *) this;
  1042. AddRef();
  1043. return S_OK;
  1044. }
  1045. else
  1046. {
  1047. *ppv = NULL;
  1048. return ULS_E_NO_INTERFACE;
  1049. };
  1050. }
  1051. //****************************************************************************
  1052. // STDMETHODIMP_(ULONG)
  1053. // CEnumLocalAppProtocols::AddRef (void)
  1054. //
  1055. // History:
  1056. // Wed 17-Apr-1996 11:15:37 -by- Viroon Touranachun [viroont]
  1057. // Created.
  1058. //****************************************************************************
  1059. STDMETHODIMP_(ULONG)
  1060. CEnumLocalAppProtocols::AddRef (void)
  1061. {
  1062. cRef++;
  1063. return cRef;
  1064. }
  1065. //****************************************************************************
  1066. // STDMETHODIMP_(ULONG)
  1067. // CEnumLocalAppProtocols::Release (void)
  1068. //
  1069. // History:
  1070. // Wed 17-Apr-1996 11:15:43 -by- Viroon Touranachun [viroont]
  1071. // Created.
  1072. //****************************************************************************
  1073. STDMETHODIMP_(ULONG)
  1074. CEnumLocalAppProtocols::Release (void)
  1075. {
  1076. cRef--;
  1077. if (cRef == 0)
  1078. {
  1079. delete this;
  1080. return 0;
  1081. }
  1082. else
  1083. {
  1084. return cRef;
  1085. };
  1086. }
  1087. //****************************************************************************
  1088. // STDMETHODIMP
  1089. // CEnumLocalAppProtocols::Next (ULONG cProtocols,
  1090. // IULSLocalAppProtocol **rgpProt,
  1091. // ULONG *pcFetched)
  1092. //
  1093. // History:
  1094. // Wed 17-Apr-1996 11:15:49 -by- Viroon Touranachun [viroont]
  1095. // Created.
  1096. //****************************************************************************
  1097. STDMETHODIMP
  1098. CEnumLocalAppProtocols::Next (ULONG cProtocols, IULSLocalAppProtocol **rgpProt,
  1099. ULONG *pcFetched)
  1100. {
  1101. CLocalProt *plp;
  1102. ULONG cCopied;
  1103. HRESULT hr;
  1104. // Validate the pointer
  1105. //
  1106. if (rgpProt == NULL)
  1107. return ULS_E_POINTER;
  1108. // Validate the parameters
  1109. //
  1110. if ((cProtocols == 0) ||
  1111. ((cProtocols > 1) && (pcFetched == NULL)))
  1112. return ULS_E_PARAMETER;
  1113. // Check the enumeration index
  1114. //
  1115. cCopied = 0;
  1116. // Can copy if we still have more protocols
  1117. //
  1118. while ((cCopied < cProtocols) &&
  1119. (ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR))
  1120. {
  1121. rgpProt[cCopied] = plp;
  1122. plp->AddRef();
  1123. cCopied++;
  1124. };
  1125. // Determine the returned information based on other parameters
  1126. //
  1127. if (pcFetched != NULL)
  1128. {
  1129. *pcFetched = cCopied;
  1130. };
  1131. return (cProtocols == cCopied ? S_OK : S_FALSE);
  1132. }
  1133. //****************************************************************************
  1134. // STDMETHODIMP
  1135. // CEnumLocalAppProtocols::Skip (ULONG cProtocols)
  1136. //
  1137. // History:
  1138. // Wed 17-Apr-1996 11:15:56 -by- Viroon Touranachun [viroont]
  1139. // Created.
  1140. //****************************************************************************
  1141. STDMETHODIMP
  1142. CEnumLocalAppProtocols::Skip (ULONG cProtocols)
  1143. {
  1144. CLocalProt *plp;
  1145. ULONG cSkipped;
  1146. // Validate the parameters
  1147. //
  1148. if (cProtocols == 0)
  1149. return ULS_E_PARAMETER;
  1150. // Check the enumeration index limit
  1151. //
  1152. cSkipped = 0;
  1153. // Can skip only if we still have more attributes
  1154. //
  1155. while ((cSkipped < cProtocols) &&
  1156. (ProtList.Next(&hEnum, (PVOID *)&plp) == NOERROR))
  1157. {
  1158. cSkipped++;
  1159. };
  1160. return (cProtocols == cSkipped ? S_OK : S_FALSE);
  1161. }
  1162. //****************************************************************************
  1163. // STDMETHODIMP
  1164. // CEnumLocalAppProtocols::Reset (void)
  1165. //
  1166. // History:
  1167. // Wed 17-Apr-1996 11:16:02 -by- Viroon Touranachun [viroont]
  1168. // Created.
  1169. //****************************************************************************
  1170. STDMETHODIMP
  1171. CEnumLocalAppProtocols::Reset (void)
  1172. {
  1173. ProtList.Enumerate(&hEnum);
  1174. return S_OK;
  1175. }
  1176. //****************************************************************************
  1177. // STDMETHODIMP
  1178. // CEnumLocalAppProtocols::Clone(IEnumULSLocalAppProtocols **ppEnum)
  1179. //
  1180. // History:
  1181. // Wed 17-Apr-1996 11:16:11 -by- Viroon Touranachun [viroont]
  1182. // Created.
  1183. //****************************************************************************
  1184. STDMETHODIMP
  1185. CEnumLocalAppProtocols::Clone(IEnumULSLocalAppProtocols **ppEnum)
  1186. {
  1187. CEnumLocalAppProtocols *pep;
  1188. HRESULT hr;
  1189. // Validate parameters
  1190. //
  1191. if (ppEnum == NULL)
  1192. {
  1193. return ULS_E_POINTER;
  1194. };
  1195. *ppEnum = NULL;
  1196. // Create an enumerator
  1197. //
  1198. pep = new CEnumLocalAppProtocols;
  1199. if (pep == NULL)
  1200. return ULS_E_MEMORY;
  1201. // Clone the information
  1202. //
  1203. pep->hEnum = hEnum;
  1204. hr = pep->ProtList.Clone (&ProtList, &(pep->hEnum));
  1205. if (SUCCEEDED(hr))
  1206. {
  1207. CLocalProt *plp;
  1208. HANDLE hEnumTemp;
  1209. // Add reference to each protocol object
  1210. //
  1211. pep->ProtList.Enumerate(&hEnumTemp);
  1212. while(pep->ProtList.Next(&hEnumTemp, (PVOID *)&plp) == NOERROR)
  1213. {
  1214. plp->AddRef();
  1215. };
  1216. // Return the cloned enumerator
  1217. //
  1218. pep->AddRef();
  1219. *ppEnum = pep;
  1220. }
  1221. else
  1222. {
  1223. delete pep;
  1224. };
  1225. return hr;
  1226. }