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.

774 lines
19 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: ulsapp.cpp
  5. // Content: This file contains the Application 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 "ulsapp.h"
  14. #include "ulsprot.h"
  15. #include "attribs.h"
  16. #include "callback.h"
  17. //****************************************************************************
  18. // Event Notifiers
  19. //****************************************************************************
  20. //
  21. //****************************************************************************
  22. // HRESULT
  23. // OnNotifyGetProtocolResult (IUnknown *pUnk, void *pv)
  24. //
  25. // History:
  26. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  27. // Created.
  28. //****************************************************************************
  29. HRESULT
  30. OnNotifyGetProtocolResult (IUnknown *pUnk, void *pv)
  31. {
  32. POBJRINFO pobjri = (POBJRINFO)pv;
  33. ((IULSApplicationNotify*)pUnk)->GetProtocolResult(pobjri->uReqID,
  34. (IULSAppProtocol *)pobjri->pv,
  35. pobjri->hResult);
  36. return S_OK;
  37. }
  38. //****************************************************************************
  39. // HRESULT
  40. // OnNotifyEnumProtocolsResult (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. OnNotifyEnumProtocolsResult (IUnknown *pUnk, void *pv)
  48. {
  49. CEnumNames *penum = NULL;
  50. PENUMRINFO peri = (PENUMRINFO)pv;
  51. HRESULT hr = peri->hResult;
  52. if (SUCCEEDED(hr))
  53. {
  54. // Create a Application enumerator
  55. //
  56. penum = new CEnumNames;
  57. if (penum != NULL)
  58. {
  59. hr = penum->Init((LPTSTR)peri->pv, peri->cItems);
  60. if (SUCCEEDED(hr))
  61. {
  62. penum->AddRef();
  63. }
  64. else
  65. {
  66. delete penum;
  67. penum = NULL;
  68. };
  69. }
  70. else
  71. {
  72. hr = ULS_E_MEMORY;
  73. };
  74. };
  75. // Notify the sink object
  76. //
  77. ((IULSApplicationNotify*)pUnk)->EnumProtocolsResult(peri->uReqID,
  78. penum != NULL ?
  79. (IEnumULSNames *)penum :
  80. NULL,
  81. hr);
  82. if (penum != NULL)
  83. {
  84. penum->Release();
  85. };
  86. return hr;
  87. }
  88. //****************************************************************************
  89. // Class Implementation
  90. //****************************************************************************
  91. //
  92. //****************************************************************************
  93. // CUlsApp::CUlsApp (void)
  94. //
  95. // History:
  96. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  97. // Created.
  98. //****************************************************************************
  99. CUlsApp::CUlsApp (void)
  100. {
  101. cRef = 0;
  102. szServer = NULL;
  103. szUser = NULL;
  104. guid = GUID_NULL;
  105. szName = NULL;
  106. szMimeType = NULL;
  107. pAttrs = NULL;
  108. pConnPt = NULL;
  109. return;
  110. }
  111. //****************************************************************************
  112. // CUlsApp::~CUlsApp (void)
  113. //
  114. // History:
  115. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  116. // Created.
  117. //****************************************************************************
  118. CUlsApp::~CUlsApp (void)
  119. {
  120. if (szServer != NULL)
  121. FreeLPTSTR(szServer);
  122. if (szUser != NULL)
  123. FreeLPTSTR(szUser);
  124. if (szName != NULL)
  125. FreeLPTSTR(szName);
  126. if (szMimeType != NULL)
  127. FreeLPTSTR(szMimeType);
  128. // Release attribute object
  129. //
  130. if (pAttrs != NULL)
  131. {
  132. pAttrs->Release();
  133. };
  134. // Release the connection point
  135. //
  136. if (pConnPt != NULL)
  137. {
  138. pConnPt->ContainerReleased();
  139. ((IConnectionPoint*)pConnPt)->Release();
  140. };
  141. return;
  142. }
  143. //****************************************************************************
  144. // STDMETHODIMP
  145. // CUlsApp::Init (LPTSTR szServerName, LPTSTR szUserName, PLDAP_APPINFO pai)
  146. //
  147. // History:
  148. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  149. // Created.
  150. //****************************************************************************
  151. STDMETHODIMP
  152. CUlsApp::Init (LPTSTR szServerName, LPTSTR szUserName, PLDAP_APPINFO pai)
  153. {
  154. HRESULT hr;
  155. // Validate parameter
  156. //
  157. if ((pai->uSize != sizeof(*pai)) ||
  158. // (pai->guid == GUID_NULL) || // Allow null GUID for http register
  159. (pai->uOffsetName == 0) ||
  160. (pai->uOffsetMimeType == 0))
  161. {
  162. return ULS_E_PARAMETER;
  163. };
  164. if ((pai->cAttributes != 0) && (pai->uOffsetAttributes == 0))
  165. {
  166. return ULS_E_PARAMETER;
  167. };
  168. // Remember application GUID
  169. //
  170. guid = pai->guid;
  171. // Remember the server name
  172. //
  173. hr = SetLPTSTR(&szServer, szServerName);
  174. if (SUCCEEDED(hr))
  175. {
  176. hr = SetLPTSTR(&szUser, szUserName);
  177. if (SUCCEEDED(hr))
  178. {
  179. hr = SetLPTSTR(&szName,
  180. (LPCTSTR)(((PBYTE)pai)+pai->uOffsetName));
  181. if (SUCCEEDED(hr))
  182. {
  183. hr = SetLPTSTR(&szMimeType,
  184. (LPCTSTR)(((PBYTE)pai)+pai->uOffsetMimeType));
  185. if (SUCCEEDED(hr))
  186. {
  187. CAttributes *pNewAttrs;
  188. // Build the attribute object
  189. //
  190. pNewAttrs = new CAttributes (ULS_ATTRACCESS_NAME_VALUE);
  191. if (pNewAttrs != NULL)
  192. {
  193. if (pai->cAttributes != 0)
  194. {
  195. hr = pNewAttrs->SetAttributePairs((LPTSTR)(((PBYTE)pai)+pai->uOffsetAttributes),
  196. pai->cAttributes);
  197. };
  198. if (SUCCEEDED(hr))
  199. {
  200. pAttrs = pNewAttrs;
  201. pNewAttrs->AddRef();
  202. }
  203. else
  204. {
  205. delete pNewAttrs;
  206. };
  207. }
  208. else
  209. {
  210. hr = ULS_E_MEMORY;
  211. };
  212. };
  213. };
  214. };
  215. };
  216. if (SUCCEEDED(hr))
  217. {
  218. // Make the connection point
  219. //
  220. pConnPt = new CConnectionPoint (&IID_IULSApplicationNotify,
  221. (IConnectionPointContainer *)this);
  222. if (pConnPt != NULL)
  223. {
  224. ((IConnectionPoint*)pConnPt)->AddRef();
  225. hr = NOERROR;
  226. }
  227. else
  228. {
  229. hr = ULS_E_MEMORY;
  230. };
  231. };
  232. return hr;
  233. }
  234. //****************************************************************************
  235. // STDMETHODIMP
  236. // CUlsApp::QueryInterface (REFIID riid, void **ppv)
  237. //
  238. // History:
  239. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  240. // Created.
  241. //****************************************************************************
  242. STDMETHODIMP
  243. CUlsApp::QueryInterface (REFIID riid, void **ppv)
  244. {
  245. *ppv = NULL;
  246. if (riid == IID_IULSApplication || riid == IID_IUnknown)
  247. {
  248. *ppv = (IULSUser *) this;
  249. }
  250. else
  251. {
  252. if (riid == IID_IConnectionPointContainer)
  253. {
  254. *ppv = (IConnectionPointContainer *) this;
  255. };
  256. };
  257. if (*ppv != NULL)
  258. {
  259. ((LPUNKNOWN)*ppv)->AddRef();
  260. return S_OK;
  261. }
  262. else
  263. {
  264. return ULS_E_NO_INTERFACE;
  265. };
  266. }
  267. //****************************************************************************
  268. // STDMETHODIMP_(ULONG)
  269. // CUlsApp::AddRef (void)
  270. //
  271. // History:
  272. // Wed 17-Apr-1996 11:14:17 -by- Viroon Touranachun [viroont]
  273. // Created.
  274. //****************************************************************************
  275. STDMETHODIMP_(ULONG)
  276. CUlsApp::AddRef (void)
  277. {
  278. cRef++;
  279. return cRef;
  280. }
  281. //****************************************************************************
  282. // STDMETHODIMP_(ULONG)
  283. // CUlsApp::Release (void)
  284. //
  285. // History:
  286. // Wed 17-Apr-1996 11:14:26 -by- Viroon Touranachun [viroont]
  287. // Created.
  288. //****************************************************************************
  289. STDMETHODIMP_(ULONG)
  290. CUlsApp::Release (void)
  291. {
  292. cRef--;
  293. if (cRef == 0)
  294. {
  295. delete this;
  296. return 0;
  297. }
  298. else
  299. {
  300. return cRef;
  301. };
  302. }
  303. //****************************************************************************
  304. // STDMETHODIMP
  305. // CUlsApp::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  306. //
  307. // History:
  308. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  309. // Created.
  310. //****************************************************************************
  311. STDMETHODIMP
  312. CUlsApp::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  313. {
  314. HRESULT hr = S_OK;
  315. if (pConnPt != NULL)
  316. {
  317. hr = pConnPt->Notify(pv, pfn);
  318. };
  319. return hr;
  320. }
  321. //****************************************************************************
  322. // STDMETHODIMP
  323. // CUlsApp::GetID (GUID *pGUID)
  324. //
  325. // History:
  326. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  327. // Created.
  328. //****************************************************************************
  329. STDMETHODIMP
  330. CUlsApp::GetID (GUID *pGUID)
  331. {
  332. // Validate parameter
  333. //
  334. if (pGUID == NULL)
  335. {
  336. return ULS_E_POINTER;
  337. };
  338. *pGUID = guid;
  339. return NOERROR;
  340. }
  341. //****************************************************************************
  342. // STDMETHODIMP
  343. // CUlsApp::GetName (BSTR *pbstrAppName)
  344. //
  345. // History:
  346. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  347. // Created.
  348. //****************************************************************************
  349. STDMETHODIMP
  350. CUlsApp::GetName (BSTR *pbstrAppName)
  351. {
  352. // Validate parameter
  353. //
  354. if (pbstrAppName == NULL)
  355. {
  356. return ULS_E_POINTER;
  357. };
  358. return LPTSTR_to_BSTR(pbstrAppName, szName);
  359. }
  360. //****************************************************************************
  361. // STDMETHODIMP
  362. // CUlsApp::GetMimeType (BSTR *pbstrMimeType)
  363. //
  364. // History:
  365. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  366. // Created.
  367. //****************************************************************************
  368. STDMETHODIMP
  369. CUlsApp::GetMimeType (BSTR *pbstrMimeType)
  370. {
  371. // Validate parameter
  372. //
  373. if (pbstrMimeType == NULL)
  374. {
  375. return ULS_E_POINTER;
  376. };
  377. return LPTSTR_to_BSTR(pbstrMimeType, szMimeType);
  378. }
  379. //****************************************************************************
  380. // STDMETHODIMP
  381. // CUlsApp::GetAttributes (IULSAttributes **ppAttributes)
  382. //
  383. // History:
  384. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  385. // Created.
  386. //****************************************************************************
  387. STDMETHODIMP
  388. CUlsApp::GetAttributes (IULSAttributes **ppAttributes)
  389. {
  390. // Validate parameter
  391. //
  392. if (ppAttributes == NULL)
  393. {
  394. return ULS_E_POINTER;
  395. };
  396. *ppAttributes = pAttrs;
  397. pAttrs->AddRef();
  398. return NOERROR;
  399. }
  400. //****************************************************************************
  401. // STDMETHODIMP
  402. // CUlsApp::GetProtocol (BSTR bstrProtocolID, ULONG *puReqID)
  403. //
  404. // History:
  405. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  406. // Created.
  407. //****************************************************************************
  408. STDMETHODIMP
  409. CUlsApp::GetProtocol (BSTR bstrProtocolID, IULSAttributes *pAttributes, ULONG *puReqID)
  410. {
  411. LDAP_ASYNCINFO ldai;
  412. LPTSTR pszID;
  413. HRESULT hr;
  414. // Validate parameter
  415. //
  416. if (bstrProtocolID == NULL || puReqID == NULL)
  417. return ULS_E_POINTER;
  418. // Convert protocol name
  419. //
  420. hr = BSTR_to_LPTSTR(&pszID, bstrProtocolID);
  421. if (hr != S_OK)
  422. return hr;
  423. // Get arbitrary attribute name list if any
  424. //
  425. ULONG cAttrNames = 0;
  426. ULONG cbNames = 0;
  427. TCHAR *pszAttrNameList = NULL;
  428. if (pAttributes != NULL)
  429. {
  430. hr = ((CAttributes *) pAttributes)->GetAttributeList (&pszAttrNameList, &cAttrNames, &cbNames);
  431. if (hr != S_OK)
  432. return hr;
  433. }
  434. hr = ::UlsLdap_ResolveProtocol (szServer, szUser, szName, pszID,
  435. pszAttrNameList, cAttrNames, &ldai);
  436. if (hr != S_OK)
  437. goto MyExit;
  438. // If updating server was successfully requested, wait for the response
  439. //
  440. REQUESTINFO ri;
  441. ZeroMemory (&ri, sizeof (ri));
  442. ri.uReqType = WM_ULS_RESOLVE_PROTOCOL;
  443. ri.uMsgID = ldai.uMsgID;
  444. ri.pv = (PVOID) this;
  445. ri.lParam = NULL;
  446. // Remember this request
  447. //
  448. hr = g_pReqMgr->NewRequest(&ri);
  449. if (SUCCEEDED(hr))
  450. {
  451. // Make sure the objects do not disappear before we get the response
  452. //
  453. this->AddRef();
  454. // Return the request ID
  455. //
  456. *puReqID = ri.uReqID;
  457. };
  458. MyExit:
  459. if (pszAttrNameList != NULL)
  460. FreeLPTSTR (pszAttrNameList);
  461. if (pszID != NULL)
  462. FreeLPTSTR(pszID);
  463. return hr;
  464. }
  465. //****************************************************************************
  466. // STDMETHODIMP
  467. // CUlsApp::GetProtocolResult (ULONG uReqID, PLDAP_PROTINFO_RES ppir)
  468. //
  469. // History:
  470. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  471. // Created.
  472. //****************************************************************************
  473. STDMETHODIMP
  474. CUlsApp::GetProtocolResult (ULONG uReqID, PLDAP_PROTINFO_RES ppir)
  475. {
  476. CUlsProt *pp;
  477. OBJRINFO objri;
  478. // Default to the server's result
  479. //
  480. objri.hResult = ppir->hResult;
  481. if (SUCCEEDED(objri.hResult))
  482. {
  483. // The server returns PROTINFO, create a Application object
  484. //
  485. pp = new CUlsProt;
  486. if (pp != NULL)
  487. {
  488. objri.hResult = pp->Init(szServer, szUser, szName, &ppir->lpi);
  489. if (SUCCEEDED(objri.hResult))
  490. {
  491. pp->AddRef();
  492. }
  493. else
  494. {
  495. delete pp;
  496. pp = NULL;
  497. };
  498. }
  499. else
  500. {
  501. objri.hResult = ULS_E_MEMORY;
  502. };
  503. }
  504. else
  505. {
  506. pp = NULL;
  507. };
  508. // Package the notification info
  509. //
  510. objri.uReqID = uReqID;
  511. objri.pv = (void *)(pp == NULL ? NULL : (IULSAppProtocol *)pp);
  512. NotifySink((void *)&objri, OnNotifyGetProtocolResult);
  513. if (pp != NULL)
  514. {
  515. pp->Release();
  516. };
  517. return NOERROR;
  518. }
  519. //****************************************************************************
  520. // STDMETHODIMP
  521. // CUlsApp::EnumProtocols (ULONG *puReqID)
  522. //
  523. // History:
  524. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  525. // Created.
  526. //****************************************************************************
  527. STDMETHODIMP
  528. CUlsApp::EnumProtocols (ULONG *puReqID)
  529. {
  530. LDAP_ASYNCINFO ldai;
  531. HRESULT hr;
  532. // Validate parameter
  533. //
  534. if (puReqID == NULL)
  535. {
  536. return ULS_E_POINTER;
  537. };
  538. hr = ::UlsLdap_EnumProtocols(szServer, szUser, szName, &ldai);
  539. if (SUCCEEDED(hr))
  540. {
  541. REQUESTINFO ri;
  542. // If updating server was successfully requested, wait for the response
  543. //
  544. ri.uReqType = WM_ULS_ENUM_PROTOCOLS;
  545. ri.uMsgID = ldai.uMsgID;
  546. ri.pv = (PVOID)this;
  547. ri.lParam = (LPARAM)NULL;
  548. hr = g_pReqMgr->NewRequest(&ri);
  549. if (SUCCEEDED(hr))
  550. {
  551. // Make sure the objects do not disappear before we get the response
  552. //
  553. this->AddRef();
  554. // Return the request ID
  555. //
  556. *puReqID = ri.uReqID;
  557. };
  558. };
  559. return hr;
  560. }
  561. //****************************************************************************
  562. // STDMETHODIMP
  563. // CUlsApp::EnumProtocolsResult (ULONG uReqID, PLDAP_ENUM ple)
  564. //
  565. // History:
  566. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  567. // Created.
  568. //****************************************************************************
  569. STDMETHODIMP
  570. CUlsApp::EnumProtocolsResult (ULONG uReqID, PLDAP_ENUM ple)
  571. {
  572. ENUMRINFO eri;
  573. // Package the notification info
  574. //
  575. eri.uReqID = uReqID;
  576. eri.hResult = ple->hResult;
  577. eri.cItems = ple->cItems;
  578. eri.pv = (void *)(((PBYTE)ple)+ple->uOffsetItems);
  579. NotifySink((void *)&eri, OnNotifyEnumProtocolsResult);
  580. return NOERROR;
  581. }
  582. //****************************************************************************
  583. // STDMETHODIMP
  584. // CUlsApp::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  585. //
  586. // History:
  587. // Wed 17-Apr-1996 11:15:02 -by- Viroon Touranachun [viroont]
  588. // Created.
  589. //****************************************************************************
  590. STDMETHODIMP
  591. CUlsApp::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  592. {
  593. CEnumConnectionPoints *pecp;
  594. HRESULT hr;
  595. // Validate parameters
  596. //
  597. if (ppEnum == NULL)
  598. {
  599. return ULS_E_POINTER;
  600. };
  601. // Assume failure
  602. //
  603. *ppEnum = NULL;
  604. // Create an enumerator
  605. //
  606. pecp = new CEnumConnectionPoints;
  607. if (pecp == NULL)
  608. return ULS_E_MEMORY;
  609. // Initialize the enumerator
  610. //
  611. hr = pecp->Init((IConnectionPoint *)pConnPt);
  612. if (FAILED(hr))
  613. {
  614. delete pecp;
  615. return hr;
  616. };
  617. // Give it back to the caller
  618. //
  619. pecp->AddRef();
  620. *ppEnum = pecp;
  621. return S_OK;
  622. }
  623. //****************************************************************************
  624. // STDMETHODIMP
  625. // CUlsApp::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  626. //
  627. // History:
  628. // Wed 17-Apr-1996 11:15:09 -by- Viroon Touranachun [viroont]
  629. // Created.
  630. //****************************************************************************
  631. STDMETHODIMP
  632. CUlsApp::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  633. {
  634. IID siid;
  635. HRESULT hr;
  636. // Validate parameters
  637. //
  638. if (ppcp == NULL)
  639. {
  640. return ULS_E_POINTER;
  641. };
  642. // Assume failure
  643. //
  644. *ppcp = NULL;
  645. if (pConnPt != NULL)
  646. {
  647. hr = pConnPt->GetConnectionInterface(&siid);
  648. if (SUCCEEDED(hr))
  649. {
  650. if (riid == siid)
  651. {
  652. *ppcp = (IConnectionPoint *)pConnPt;
  653. (*ppcp)->AddRef();
  654. hr = S_OK;
  655. }
  656. else
  657. {
  658. hr = ULS_E_NO_INTERFACE;
  659. };
  660. };
  661. }
  662. else
  663. {
  664. hr = ULS_E_NO_INTERFACE;
  665. };
  666. return hr;
  667. }