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.

676 lines
17 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: localprt.cpp
  5. // Content: This file contains the LocalProtocol 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 "localprt.h"
  14. #include "attribs.h"
  15. #include "callback.h"
  16. #include "culs.h"
  17. //****************************************************************************
  18. // Event Notifiers
  19. //****************************************************************************
  20. //
  21. //****************************************************************************
  22. // Class Implementation
  23. //****************************************************************************
  24. //
  25. //****************************************************************************
  26. // CLocalProt::CLocalProt (void)
  27. //
  28. // History:
  29. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  30. // Created.
  31. //****************************************************************************
  32. CLocalProt::CLocalProt (void)
  33. :m_cRef (0),
  34. m_fReadonly (FALSE),
  35. m_hProt (NULL),
  36. m_szName (NULL),
  37. m_uPort (0),
  38. m_szMimeType (NULL),
  39. m_pAttrs (NULL),
  40. m_pConnPt (NULL),
  41. m_pIlsServer (NULL),
  42. m_pszUser (NULL),
  43. m_pszApp (NULL)
  44. {
  45. }
  46. //****************************************************************************
  47. // CLocalProt::~CLocalProt (void)
  48. //
  49. // History:
  50. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  51. // Created.
  52. //****************************************************************************
  53. CLocalProt::~CLocalProt (void)
  54. {
  55. // Release the connection point
  56. //
  57. if (m_pConnPt != NULL)
  58. {
  59. m_pConnPt->ContainerReleased();
  60. ((IConnectionPoint*)m_pConnPt)->Release();
  61. };
  62. // Release the attributes object
  63. //
  64. if (m_pAttrs != NULL)
  65. {
  66. m_pAttrs->Release();
  67. };
  68. // Release the buffer resources
  69. //
  70. ::MemFree (m_szName);
  71. ::MemFree (m_szMimeType);
  72. ::MemFree (m_pszUser);
  73. ::MemFree (m_pszApp);
  74. if (m_pIlsServer != NULL)
  75. m_pIlsServer->Release ();
  76. if (m_hProt != NULL)
  77. ::UlsLdap_VirtualUnRegisterProtocol(m_hProt);
  78. }
  79. //****************************************************************************
  80. // STDMETHODIMP
  81. // CLocalProt::Init (BSTR bstrName, ULONG uPort, BSTR bstrMimeType)
  82. //
  83. // History:
  84. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  85. // Created.
  86. //****************************************************************************
  87. STDMETHODIMP
  88. CLocalProt::Init (BSTR bstrName, ULONG uPort, BSTR bstrMimeType)
  89. {
  90. HRESULT hr;
  91. // Set the port number
  92. //
  93. this->m_uPort = uPort;
  94. hr = BSTR_to_LPTSTR(&m_szName, bstrName);
  95. if (SUCCEEDED(hr))
  96. {
  97. hr = BSTR_to_LPTSTR(&m_szMimeType, bstrMimeType);
  98. if (SUCCEEDED(hr))
  99. {
  100. #ifdef LATER
  101. // Initialize the attributes list
  102. //
  103. m_pAttrs = new CAttributes;
  104. if (m_pAttrs != NULL)
  105. m_pAttrs->SetAccessType (ILS_ATTRTYPE_NAME_VALUE);
  106. #endif //LATER
  107. // Make the connection point
  108. //
  109. m_pConnPt = new CConnectionPoint (&IID_IIlsProtocolNotify,
  110. (IConnectionPointContainer *)this);
  111. if (m_pConnPt != NULL)
  112. {
  113. ((IConnectionPoint*)m_pConnPt)->AddRef();
  114. hr = NOERROR;
  115. }
  116. else
  117. {
  118. hr = ILS_E_MEMORY;
  119. };
  120. };
  121. };
  122. // Make this as read/write access
  123. //
  124. ASSERT (! m_fReadonly);
  125. return hr;
  126. }
  127. //****************************************************************************
  128. // STDMETHODIMP
  129. // CIlsProt::Init (LPTSTR szServerName, LPTSTR szUserName,
  130. // LPTSTR szAppName, PLDAP_PROTINFO ppi)
  131. //
  132. // History:
  133. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  134. // Created.
  135. //****************************************************************************
  136. STDMETHODIMP
  137. CLocalProt::Init (CIlsServer *pIlsServer, LPTSTR szUserName,
  138. LPTSTR szAppName, PLDAP_PROTINFO ppi)
  139. {
  140. HRESULT hr;
  141. // Validate parameter
  142. //
  143. if (ppi == NULL)
  144. return ILS_E_POINTER;
  145. if (ppi->uSize != sizeof(*ppi))
  146. return ILS_E_PARAMETER;
  147. // Make this a readonly guy
  148. //
  149. m_fReadonly = TRUE;
  150. // Remember port name
  151. //
  152. m_uPort = ppi->uPortNumber;
  153. // Remember the server name
  154. //
  155. m_pIlsServer = pIlsServer;
  156. pIlsServer->AddRef ();
  157. hr = SetLPTSTR(&m_pszUser, szUserName);
  158. if (SUCCEEDED(hr))
  159. {
  160. hr = SetLPTSTR(&m_pszApp, szAppName);
  161. if (SUCCEEDED(hr))
  162. {
  163. hr = SetLPTSTR(&m_szName,
  164. (LPCTSTR)(((PBYTE)ppi)+ppi->uOffsetName));
  165. if (SUCCEEDED(hr))
  166. {
  167. hr = SetLPTSTR(&m_szMimeType,
  168. (LPCTSTR)(((PBYTE)ppi)+ppi->uOffsetMimeType));
  169. };
  170. };
  171. };
  172. // cleanup is done in destructor
  173. return hr;
  174. }
  175. //****************************************************************************
  176. // STDMETHODIMP
  177. // CLocalProt::QueryInterface (REFIID riid, void **ppv)
  178. //
  179. // History:
  180. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  181. // Created.
  182. //****************************************************************************
  183. STDMETHODIMP
  184. CLocalProt::QueryInterface (REFIID riid, void **ppv)
  185. {
  186. *ppv = NULL;
  187. if (riid == IID_IIlsProtocol || riid == IID_IUnknown)
  188. {
  189. *ppv = (IIlsMain *) this;
  190. }
  191. else
  192. {
  193. if (riid == IID_IConnectionPointContainer)
  194. {
  195. *ppv = (IConnectionPointContainer *) this;
  196. };
  197. };
  198. if (*ppv != NULL)
  199. {
  200. ((LPUNKNOWN)*ppv)->AddRef();
  201. return S_OK;
  202. }
  203. else
  204. {
  205. return ILS_E_NO_INTERFACE;
  206. };
  207. }
  208. //****************************************************************************
  209. // STDMETHODIMP_(ULONG)
  210. // CLocalProt::AddRef (void)
  211. //
  212. // History:
  213. // Wed 17-Apr-1996 11:14:17 -by- Viroon Touranachun [viroont]
  214. // Created.
  215. //****************************************************************************
  216. STDMETHODIMP_(ULONG)
  217. CLocalProt::AddRef (void)
  218. {
  219. DllLock();
  220. MyDebugMsg ((DM_REFCOUNT, "CLocalProt::AddRef: ref=%ld\r\n", m_cRef));
  221. ::InterlockedIncrement (&m_cRef);
  222. return (ULONG) m_cRef;
  223. }
  224. //****************************************************************************
  225. // STDMETHODIMP_(ULONG)
  226. // CLocalProt::Release (void)
  227. //
  228. // History:
  229. // Wed 17-Apr-1996 11:14:26 -by- Viroon Touranachun [viroont]
  230. // Created.
  231. //****************************************************************************
  232. STDMETHODIMP_(ULONG)
  233. CLocalProt::Release (void)
  234. {
  235. DllRelease();
  236. ASSERT (m_cRef > 0);
  237. MyDebugMsg ((DM_REFCOUNT, "CLocalProt::Release: ref=%ld\r\n", m_cRef));
  238. if (::InterlockedDecrement (&m_cRef) == 0)
  239. {
  240. delete this;
  241. return 0;
  242. }
  243. return (ULONG) m_cRef;
  244. }
  245. //****************************************************************************
  246. // STDMETHODIMP
  247. // CLocalProt::IsWritable (BOOL *pfWriteable)
  248. //
  249. //****************************************************************************
  250. STDMETHODIMP
  251. CLocalProt::IsWritable(BOOL *pfWriteable)
  252. {
  253. HRESULT hr;
  254. if (pfWriteable)
  255. {
  256. *pfWriteable = !m_fReadonly;
  257. hr = S_OK;
  258. }
  259. else
  260. {
  261. hr = ILS_E_POINTER;
  262. }
  263. return (hr);
  264. }
  265. //****************************************************************************
  266. // STDMETHODIMP
  267. // CLocalProt::GetStandardAttribute (ILS_STD_ATTR_NAME stdAttr, BSTR *pbstrStdAttr)
  268. //
  269. // History:
  270. // 1-16-97 Shishir Pardikar
  271. // Created.
  272. //****************************************************************************
  273. STDMETHODIMP
  274. CLocalProt::GetStandardAttribute(
  275. ILS_STD_ATTR_NAME stdAttr,
  276. BSTR *pbstrStdAttr
  277. )
  278. {
  279. LPTSTR lpszAttr = NULL;
  280. BOOL fValid = TRUE;
  281. HRESULT hr;
  282. TCHAR sz[16];
  283. if (pbstrStdAttr == NULL) {
  284. return ILS_E_POINTER;
  285. }
  286. switch(stdAttr) {
  287. case ILS_STDATTR_PROTOCOL_PORT:
  288. lpszAttr = &sz[0];
  289. wsprintf (&sz[0], TEXT ("%lu"), m_uPort);
  290. break;
  291. case ILS_STDATTR_PROTOCOL_NAME:
  292. lpszAttr = m_szName;
  293. break;
  294. case ILS_STDATTR_PROTOCOL_MIME_TYPE:
  295. lpszAttr = m_szMimeType;
  296. break;
  297. default:
  298. fValid = FALSE;
  299. break;
  300. }
  301. if (fValid) {
  302. if (lpszAttr){
  303. hr = LPTSTR_to_BSTR(pbstrStdAttr, lpszAttr);
  304. }
  305. else {
  306. *pbstrStdAttr = NULL;
  307. hr = NOERROR;
  308. }
  309. }
  310. else {
  311. hr = ILS_E_PARAMETER;
  312. }
  313. return (hr);
  314. }
  315. //****************************************************************************
  316. // STDMETHODIMP
  317. // CLocalProt::SetStandardAttribute (ILS_STD_ATTR_NAME stdAttr, BSTR bstrStdAttr)
  318. //
  319. // History:
  320. // 1-16-97 Shishir Pardikar
  321. // Created.
  322. //****************************************************************************
  323. STDMETHODIMP
  324. CLocalProt::SetStandardAttribute(
  325. ILS_STD_ATTR_NAME stdAttr,
  326. BSTR bstrStdAttr
  327. )
  328. {
  329. return (ILS_E_FAIL);
  330. }
  331. //****************************************************************************
  332. // STDMETHODIMP
  333. // CLocalProt::Update(BSTR bstrServerName, ULONG *pulReqId)
  334. //
  335. // History:
  336. // 1-16-97 Shishir Pardikar
  337. // Created.
  338. //****************************************************************************
  339. STDMETHODIMP CLocalProt::
  340. Update ( ULONG *pulReqID )
  341. {
  342. return (ILS_E_FAIL);
  343. }
  344. //****************************************************************************
  345. // STDMETHODIMP
  346. // CLocalProt::IsSameAs (CLocalProt *pProtocol)
  347. //
  348. // History:
  349. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  350. // Created.
  351. //****************************************************************************
  352. STDMETHODIMP
  353. CLocalProt::IsSameAs (CLocalProt *pProtocol)
  354. {
  355. return (!lstrcmp(pProtocol->m_szName, this->m_szName) ?
  356. NOERROR : S_FALSE);
  357. }
  358. //****************************************************************************
  359. // STDMETHODIMP
  360. // CLocalProt::GetProtocolInfo (PLDAP_PROTINFO *ppProtInfo)
  361. //
  362. // History:
  363. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  364. // Created.
  365. //****************************************************************************
  366. STDMETHODIMP
  367. CLocalProt::GetProtocolInfo (PLDAP_PROTINFO *ppProtInfo)
  368. {
  369. PLDAP_PROTINFO ppi;
  370. ULONG cName, cMime;
  371. HRESULT hr;
  372. // Assume failure
  373. //
  374. *ppProtInfo = NULL;
  375. // Calculate the buffer size
  376. //
  377. cName = lstrlen(m_szName)+1;
  378. cMime = lstrlen(m_szMimeType)+1;
  379. // Allocate the buffer
  380. //
  381. ULONG cbTotalSize = sizeof (LDAP_PROTINFO) + (cName + cMime) * sizeof (TCHAR);
  382. ppi = (PLDAP_PROTINFO) ::MemAlloc (cbTotalSize);
  383. if (ppi == NULL)
  384. {
  385. hr = ILS_E_MEMORY;
  386. }
  387. else
  388. {
  389. // Fill the structure content
  390. //
  391. ppi->uSize = cbTotalSize;
  392. ppi->uOffsetName = sizeof(*ppi);
  393. ppi->uPortNumber = m_uPort;
  394. ppi->uOffsetMimeType = ppi->uOffsetName + (cName*sizeof(TCHAR));
  395. // Copy the user information
  396. //
  397. lstrcpy((LPTSTR)(((PBYTE)ppi)+ppi->uOffsetName), m_szName);
  398. lstrcpy((LPTSTR)(((PBYTE)ppi)+ppi->uOffsetMimeType), m_szMimeType);
  399. // Return the structure
  400. //
  401. *ppProtInfo = ppi;
  402. };
  403. return NOERROR;
  404. }
  405. //****************************************************************************
  406. // STDMETHODIMP
  407. // CLocalProt::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  408. //
  409. // History:
  410. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  411. // Created.
  412. //****************************************************************************
  413. STDMETHODIMP
  414. CLocalProt::NotifySink (void *pv, CONN_NOTIFYPROC pfn)
  415. {
  416. HRESULT hr = S_OK;
  417. if (m_pConnPt != NULL)
  418. {
  419. hr = m_pConnPt->Notify(pv, pfn);
  420. };
  421. return hr;
  422. }
  423. //****************************************************************************
  424. // STDMETHODIMP
  425. // CLocalProt::GetID (BSTR *pbstrID)
  426. //
  427. // History:
  428. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  429. // Created.
  430. //****************************************************************************
  431. STDMETHODIMP
  432. CLocalProt::GetPortNumber (ULONG *pulPort)
  433. {
  434. // Validate parameter
  435. //
  436. if (pulPort == NULL)
  437. {
  438. return ILS_E_POINTER;
  439. };
  440. *pulPort = m_uPort;
  441. return (NOERROR);
  442. }
  443. //****************************************************************************
  444. // STDMETHODIMP
  445. // CLocalProt::SetAttributes (IIlsAttributes *pAttributes, ULONG *puReqID)
  446. //
  447. // History:
  448. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  449. // Created.
  450. //****************************************************************************
  451. STDMETHODIMP CLocalProt::
  452. SetExtendedAttribute ( BSTR bstrName, BSTR bstrValue )
  453. {
  454. return ILS_E_NOT_IMPL;
  455. }
  456. //****************************************************************************
  457. // STDMETHODIMP
  458. // CLocalProt::RemoveAttributes (IIlsAttributes *pAttributes, ULONG *puReqID)
  459. //
  460. // History:
  461. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  462. // Created.
  463. //****************************************************************************
  464. STDMETHODIMP CLocalProt::
  465. RemoveExtendedAttribute ( BSTR bstrName )
  466. {
  467. return ILS_E_NOT_IMPL;
  468. }
  469. //****************************************************************************
  470. // STDMETHODIMP
  471. // CLocalProt::GetAttributes (IIlsAttributes **pAttributes)
  472. //
  473. //****************************************************************************
  474. STDMETHODIMP CLocalProt::
  475. GetExtendedAttribute ( BSTR bstrName, BSTR *pbstrValue )
  476. {
  477. return ILS_E_NOT_IMPL;
  478. }
  479. //****************************************************************************
  480. // STDMETHODIMP
  481. // CLocalProt::GetAllExtendedAttributes (IIlsAttributes **pAttributes)
  482. //
  483. //****************************************************************************
  484. STDMETHODIMP CLocalProt::
  485. GetAllExtendedAttributes ( IIlsAttributes **ppAttributes )
  486. {
  487. return ILS_E_NOT_IMPL;
  488. }
  489. //****************************************************************************
  490. // STDMETHODIMP
  491. // CLocalProt::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  492. //
  493. // History:
  494. // Wed 17-Apr-1996 11:15:02 -by- Viroon Touranachun [viroont]
  495. // Created.
  496. //****************************************************************************
  497. STDMETHODIMP
  498. CLocalProt::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  499. {
  500. CEnumConnectionPoints *pecp;
  501. HRESULT hr;
  502. // Validate parameters
  503. //
  504. if (ppEnum == NULL)
  505. {
  506. return ILS_E_POINTER;
  507. };
  508. // Assume failure
  509. //
  510. *ppEnum = NULL;
  511. // Create an enumerator
  512. //
  513. pecp = new CEnumConnectionPoints;
  514. if (pecp == NULL)
  515. return ILS_E_MEMORY;
  516. // Initialize the enumerator
  517. //
  518. hr = pecp->Init((IConnectionPoint *)m_pConnPt);
  519. if (FAILED(hr))
  520. {
  521. delete pecp;
  522. return hr;
  523. };
  524. // Give it back to the caller
  525. //
  526. pecp->AddRef();
  527. *ppEnum = pecp;
  528. return S_OK;
  529. }
  530. //****************************************************************************
  531. // STDMETHODIMP
  532. // CLocalProt::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  533. //
  534. // History:
  535. // Wed 17-Apr-1996 11:15:09 -by- Viroon Touranachun [viroont]
  536. // Created.
  537. //****************************************************************************
  538. STDMETHODIMP
  539. CLocalProt::FindConnectionPoint(REFIID riid, IConnectionPoint **ppcp)
  540. {
  541. IID siid;
  542. HRESULT hr;
  543. // Validate parameters
  544. //
  545. if (ppcp == NULL)
  546. {
  547. return ILS_E_POINTER;
  548. };
  549. // Assume failure
  550. //
  551. *ppcp = NULL;
  552. if (m_pConnPt != NULL)
  553. {
  554. hr = m_pConnPt->GetConnectionInterface(&siid);
  555. if (SUCCEEDED(hr))
  556. {
  557. if (riid == siid)
  558. {
  559. *ppcp = (IConnectionPoint *)m_pConnPt;
  560. (*ppcp)->AddRef();
  561. hr = S_OK;
  562. }
  563. else
  564. {
  565. hr = ILS_E_NO_INTERFACE;
  566. };
  567. };
  568. }
  569. else
  570. {
  571. hr = ILS_E_NO_INTERFACE;
  572. };
  573. return hr;
  574. }