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.

329 lines
8.3 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: ulsprot.cpp
  5. // Content: This file contains the Protocol 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 "ulsprot.h"
  14. #include "attribs.h"
  15. //****************************************************************************
  16. // CUlsProt::CUlsProt (void)
  17. //
  18. // History:
  19. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  20. // Created.
  21. //****************************************************************************
  22. CUlsProt::CUlsProt (void)
  23. {
  24. cRef = 0;
  25. szServer = NULL;
  26. szUser = NULL;
  27. szApp = NULL;
  28. szName = NULL;
  29. szMimeType = NULL;
  30. uPort = 0;
  31. pAttrs = NULL;
  32. return;
  33. }
  34. //****************************************************************************
  35. // CUlsProt::~CUlsProt (void)
  36. //
  37. // History:
  38. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  39. // Created.
  40. //****************************************************************************
  41. CUlsProt::~CUlsProt (void)
  42. {
  43. if (szServer != NULL)
  44. FreeLPTSTR(szServer);
  45. if (szUser != NULL)
  46. FreeLPTSTR(szUser);
  47. if (szApp != NULL)
  48. FreeLPTSTR(szApp);
  49. if (szName != NULL)
  50. FreeLPTSTR(szName);
  51. if (szMimeType != NULL)
  52. FreeLPTSTR(szMimeType);
  53. // Release attribute object
  54. //
  55. if (pAttrs != NULL)
  56. {
  57. pAttrs->Release();
  58. };
  59. return;
  60. }
  61. //****************************************************************************
  62. // STDMETHODIMP
  63. // CUlsProt::Init (LPTSTR szServerName, LPTSTR szUserName,
  64. // LPTSTR szAppName, PLDAP_PROTINFO ppi)
  65. //
  66. // History:
  67. // Wed 17-Apr-1996 11:14:03 -by- Viroon Touranachun [viroont]
  68. // Created.
  69. //****************************************************************************
  70. STDMETHODIMP
  71. CUlsProt::Init (LPTSTR szServerName, LPTSTR szUserName,
  72. LPTSTR szAppName, PLDAP_PROTINFO ppi)
  73. {
  74. HRESULT hr;
  75. // Validate parameter
  76. //
  77. if ((ppi->uSize != sizeof(*ppi)) ||
  78. (ppi->uPortNumber == 0) ||
  79. (ppi->uOffsetName == 0) ||
  80. (ppi->uOffsetMimeType == 0))
  81. {
  82. return ULS_E_PARAMETER;
  83. };
  84. if ((ppi->cAttributes != 0) && (ppi->uOffsetAttributes == 0))
  85. {
  86. return ULS_E_PARAMETER;
  87. };
  88. // Remember port name
  89. //
  90. uPort = ppi->uPortNumber;
  91. // Remember the server name
  92. //
  93. hr = SetLPTSTR(&szServer, szServerName);
  94. if (SUCCEEDED(hr))
  95. {
  96. hr = SetLPTSTR(&szUser, szUserName);
  97. if (SUCCEEDED(hr))
  98. {
  99. hr = SetLPTSTR(&szApp, szAppName);
  100. if (SUCCEEDED(hr))
  101. {
  102. hr = SetLPTSTR(&szName,
  103. (LPCTSTR)(((PBYTE)ppi)+ppi->uOffsetName));
  104. if (SUCCEEDED(hr))
  105. {
  106. hr = SetLPTSTR(&szMimeType,
  107. (LPCTSTR)(((PBYTE)ppi)+ppi->uOffsetMimeType));
  108. if (SUCCEEDED(hr))
  109. {
  110. CAttributes *pNewAttrs;
  111. // Build the attribute object
  112. //
  113. pNewAttrs = new CAttributes (ULS_ATTRACCESS_NAME_VALUE);
  114. if (pNewAttrs != NULL)
  115. {
  116. if (ppi->cAttributes != 0)
  117. {
  118. hr = pNewAttrs->SetAttributePairs((LPTSTR)(((PBYTE)ppi)+ppi->uOffsetAttributes),
  119. ppi->cAttributes);
  120. };
  121. if (SUCCEEDED(hr))
  122. {
  123. pAttrs = pNewAttrs;
  124. pNewAttrs->AddRef();
  125. }
  126. else
  127. {
  128. delete pNewAttrs;
  129. };
  130. }
  131. else
  132. {
  133. hr = ULS_E_MEMORY;
  134. };
  135. };
  136. };
  137. };
  138. };
  139. };
  140. return hr;
  141. }
  142. //****************************************************************************
  143. // STDMETHODIMP
  144. // CUlsProt::QueryInterface (REFIID riid, void **ppv)
  145. //
  146. // History:
  147. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  148. // Created.
  149. //****************************************************************************
  150. STDMETHODIMP
  151. CUlsProt::QueryInterface (REFIID riid, void **ppv)
  152. {
  153. *ppv = NULL;
  154. if (riid == IID_IULSAppProtocol || riid == IID_IUnknown)
  155. {
  156. *ppv = (IULSUser *) this;
  157. };
  158. if (*ppv != NULL)
  159. {
  160. ((LPUNKNOWN)*ppv)->AddRef();
  161. return S_OK;
  162. }
  163. else
  164. {
  165. return ULS_E_NO_INTERFACE;
  166. };
  167. }
  168. //****************************************************************************
  169. // STDMETHODIMP_(ULONG)
  170. // CUlsProt::AddRef (void)
  171. //
  172. // History:
  173. // Wed 17-Apr-1996 11:14:17 -by- Viroon Touranachun [viroont]
  174. // Created.
  175. //****************************************************************************
  176. STDMETHODIMP_(ULONG)
  177. CUlsProt::AddRef (void)
  178. {
  179. cRef++;
  180. return cRef;
  181. }
  182. //****************************************************************************
  183. // STDMETHODIMP_(ULONG)
  184. // CUlsProt::Release (void)
  185. //
  186. // History:
  187. // Wed 17-Apr-1996 11:14:26 -by- Viroon Touranachun [viroont]
  188. // Created.
  189. //****************************************************************************
  190. STDMETHODIMP_(ULONG)
  191. CUlsProt::Release (void)
  192. {
  193. cRef--;
  194. if (cRef == 0)
  195. {
  196. delete this;
  197. return 0;
  198. }
  199. else
  200. {
  201. return cRef;
  202. };
  203. }
  204. //****************************************************************************
  205. // STDMETHODIMP
  206. // CUlsProt::GetID (BSTR *pbstrID)
  207. //
  208. // History:
  209. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  210. // Created.
  211. //****************************************************************************
  212. STDMETHODIMP
  213. CUlsProt::GetID (BSTR *pbstrID)
  214. {
  215. // Validate parameter
  216. //
  217. if (pbstrID == NULL)
  218. {
  219. return ULS_E_POINTER;
  220. };
  221. return LPTSTR_to_BSTR(pbstrID, szName);
  222. }
  223. //****************************************************************************
  224. // STDMETHODIMP
  225. // CUlsProt::GetPortNumber (ULONG *puPortNumber)
  226. //
  227. // History:
  228. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  229. // Created.
  230. //****************************************************************************
  231. STDMETHODIMP
  232. CUlsProt::GetPortNumber (ULONG *puPortNumber)
  233. {
  234. // Validate parameter
  235. //
  236. if (puPortNumber == NULL)
  237. {
  238. return ULS_E_POINTER;
  239. };
  240. *puPortNumber = uPort;
  241. return NOERROR;
  242. }
  243. //****************************************************************************
  244. // STDMETHODIMP
  245. // CUlsProt::GetMimeType (BSTR *pbstrMimeType)
  246. //
  247. // History:
  248. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  249. // Created.
  250. //****************************************************************************
  251. STDMETHODIMP
  252. CUlsProt::GetMimeType (BSTR *pbstrMimeType)
  253. {
  254. // Validate parameter
  255. //
  256. if (pbstrMimeType == NULL)
  257. {
  258. return ULS_E_POINTER;
  259. };
  260. return LPTSTR_to_BSTR(pbstrMimeType, szMimeType);
  261. }
  262. //****************************************************************************
  263. // STDMETHODIMP
  264. // CUlsProt::GetAttributes (IULSAttributes **ppAttributes)
  265. //
  266. // History:
  267. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  268. // Created.
  269. //****************************************************************************
  270. STDMETHODIMP
  271. CUlsProt::GetAttributes (IULSAttributes **ppAttributes)
  272. {
  273. // Validate parameter
  274. //
  275. if (ppAttributes == NULL)
  276. {
  277. return ULS_E_POINTER;
  278. };
  279. *ppAttributes = pAttrs;
  280. pAttrs->AddRef();
  281. return NOERROR;
  282. }