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.

322 lines
9.9 KiB

  1. // --------------------------------------------------------------------------------
  2. // Smtpcall.cpp
  3. // --------------------------------------------------------------------------------
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include "smtpcall.h"
  7. extern DWORD MsgSMTP;
  8. // --------------------------------------------------------------------------------
  9. // HrCreateSMTPTransport
  10. // --------------------------------------------------------------------------------
  11. HRESULT HrCreateSMTPTransport(ISMTPTransport **ppSMTP)
  12. {
  13. // Locals
  14. HRESULT hr;
  15. CSMTPCallback *pCallback=NULL;
  16. // Create callback object
  17. pCallback = new CSMTPCallback();
  18. if (NULL == pCallback)
  19. {
  20. printf("Memory allocation failure\n");
  21. return E_OUTOFMEMORY;
  22. }
  23. // Load SMTP Transport
  24. hr = CoCreateInstance(CLSID_ISMTPTransport, NULL, CLSCTX_INPROC_SERVER, IID_ISMTPTransport, (LPVOID *)ppSMTP);
  25. if (FAILED(hr))
  26. {
  27. pCallback->Release();
  28. printf("Unable to load CLSID_IMNXPORT - IID_ISMTPTransport\n");
  29. return E_FAIL;
  30. }
  31. // InitNew
  32. hr = (*ppSMTP)->InitNew(NULL, pCallback);
  33. if (FAILED(hr))
  34. {
  35. pCallback->Release();
  36. printf("Unable to load CLSID_IMNXPORT - IID_ISMTPTransport\n");
  37. return E_FAIL;
  38. }
  39. // Done
  40. pCallback->Release();
  41. return S_OK;
  42. }
  43. // --------------------------------------------------------------------------------
  44. // CSMTPCallback::CSMTPCallback
  45. // --------------------------------------------------------------------------------
  46. CSMTPCallback::CSMTPCallback(void)
  47. {
  48. m_cRef = 1;
  49. }
  50. // --------------------------------------------------------------------------------
  51. // CSMTPCallback::~CSMTPCallback
  52. // --------------------------------------------------------------------------------
  53. CSMTPCallback::~CSMTPCallback(void)
  54. {
  55. }
  56. // --------------------------------------------------------------------------------
  57. // CSMTPCallback::QueryInterface
  58. // --------------------------------------------------------------------------------
  59. STDMETHODIMP CSMTPCallback::QueryInterface(REFIID riid, LPVOID *ppv)
  60. {
  61. // Locals
  62. HRESULT hr=S_OK;
  63. // Bad param
  64. if (ppv == NULL)
  65. {
  66. hr = E_INVALIDARG;
  67. goto exit;
  68. }
  69. // Init
  70. *ppv=NULL;
  71. // IID_IUnknown
  72. if (IID_IUnknown == riid)
  73. *ppv = (IUnknown *)this;
  74. // IID_ISMTPCallback
  75. else if (IID_ISMTPCallback == riid)
  76. *ppv = (ISMTPCallback *)this;
  77. // If not null, addref it and return
  78. if (NULL != *ppv)
  79. {
  80. ((LPUNKNOWN)*ppv)->AddRef();
  81. goto exit;
  82. }
  83. // No Interface
  84. hr = E_NOINTERFACE;
  85. exit:
  86. // Done
  87. return hr;
  88. }
  89. // --------------------------------------------------------------------------------
  90. // CSMTPCallback::AddRef
  91. // --------------------------------------------------------------------------------
  92. STDMETHODIMP_(ULONG) CSMTPCallback::AddRef(void)
  93. {
  94. return ++m_cRef;
  95. }
  96. // --------------------------------------------------------------------------------
  97. // CSMTPCallback::Release
  98. // --------------------------------------------------------------------------------
  99. STDMETHODIMP_(ULONG) CSMTPCallback::Release(void)
  100. {
  101. if (0 != --m_cRef)
  102. return m_cRef;
  103. delete this;
  104. return 0;
  105. }
  106. // --------------------------------------------------------------------------------
  107. // CSMTPCallback::OnLogonPrompt
  108. // --------------------------------------------------------------------------------
  109. STDMETHODIMP CSMTPCallback::OnLogonPrompt(
  110. LPINETSERVER pInetServer,
  111. IInternetTransport *pTransport)
  112. {
  113. return S_OK;
  114. }
  115. // --------------------------------------------------------------------------------
  116. // CSMTPCallback::OnPrompt
  117. // --------------------------------------------------------------------------------
  118. STDMETHODIMP_(INT) CSMTPCallback::OnPrompt(
  119. HRESULT hrError,
  120. LPCTSTR pszText,
  121. LPCTSTR pszCaption,
  122. UINT uType,
  123. IInternetTransport *pTransport)
  124. {
  125. return S_OK;
  126. }
  127. // --------------------------------------------------------------------------------
  128. // CSMTPCallback::OnError
  129. // --------------------------------------------------------------------------------
  130. STDMETHODIMP CSMTPCallback::OnError(
  131. IXPSTATUS ixpstatus,
  132. LPIXPRESULT pIxpResult,
  133. IInternetTransport *pTransport)
  134. {
  135. printf("CSMTPCallback::OnError - Status: %d, hrResult: %08x\n", ixpstatus, pIxpResult->hrResult);
  136. return S_OK;
  137. }
  138. // --------------------------------------------------------------------------------
  139. // CSMTPCallback::OnStatus
  140. // --------------------------------------------------------------------------------
  141. STDMETHODIMP CSMTPCallback::OnStatus(
  142. IXPSTATUS ixpstatus,
  143. IInternetTransport *pTransport)
  144. {
  145. INETSERVER rServer;
  146. pTransport->GetServerInfo(&rServer);
  147. switch(ixpstatus)
  148. {
  149. case IXP_FINDINGHOST:
  150. printf("Finding '%s'...\n", rServer.szServerName);
  151. break;
  152. case IXP_CONNECTING:
  153. printf("Connecting '%s'...\n", rServer.szServerName);
  154. break;
  155. case IXP_SECURING:
  156. printf("Establishing secure connection to '%s'...\n", rServer.szServerName);
  157. break;
  158. case IXP_CONNECTED:
  159. printf("Connected '%s'\n", rServer.szServerName);
  160. break;
  161. case IXP_AUTHORIZING:
  162. printf("Authorizing '%s'...\n", rServer.szServerName);
  163. break;
  164. case IXP_AUTHRETRY:
  165. printf("Retrying Logon '%s'...\n", rServer.szServerName);
  166. break;
  167. case IXP_DISCONNECTING:
  168. printf("Disconnecting '%s'...\n", rServer.szServerName);
  169. break;
  170. case IXP_DISCONNECTED:
  171. printf("Disconnected '%s'\n", rServer.szServerName);
  172. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, IXP_DISCONNECTED, 0);
  173. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_QUIT, 0);
  174. break;
  175. }
  176. return S_OK;
  177. }
  178. // --------------------------------------------------------------------------------
  179. // CSMTPCallback::OnProgress
  180. // --------------------------------------------------------------------------------
  181. STDMETHODIMP CSMTPCallback::OnProgress(
  182. DWORD dwIncrement,
  183. DWORD dwCurrent,
  184. DWORD dwMaximum,
  185. IInternetTransport *pTransport)
  186. {
  187. return S_OK;
  188. }
  189. // --------------------------------------------------------------------------------
  190. // CSMTPCallback::OnCommand
  191. // --------------------------------------------------------------------------------
  192. STDMETHODIMP CSMTPCallback::OnCommand(
  193. CMDTYPE cmdtype,
  194. LPSTR pszLine,
  195. HRESULT hrResponse,
  196. IInternetTransport *pTransport)
  197. {
  198. INETSERVER rServer;
  199. pTransport->GetServerInfo(&rServer);
  200. if (CMD_SEND == cmdtype)
  201. {
  202. printf("%s[TX]: %s", rServer.szServerName, pszLine);
  203. }
  204. else if (CMD_RESP == cmdtype)
  205. printf("%s[RX]: %s - %08x\n", rServer.szServerName, pszLine, hrResponse);
  206. return S_OK;
  207. }
  208. // --------------------------------------------------------------------------------
  209. // CSMTPCallback::OnTimeout
  210. // --------------------------------------------------------------------------------
  211. STDMETHODIMP CSMTPCallback::OnTimeout(
  212. DWORD *pdwTimeout,
  213. IInternetTransport *pTransport)
  214. {
  215. INETSERVER rServer;
  216. pTransport->GetServerInfo(&rServer);
  217. printf("Timeout '%s' !!!\n", rServer.szServerName);
  218. return S_OK;
  219. }
  220. // --------------------------------------------------------------------------------
  221. // CSMTPCallback::OnResponse
  222. // --------------------------------------------------------------------------------
  223. STDMETHODIMP CSMTPCallback::OnResponse(
  224. LPSMTPRESPONSE pResponse)
  225. {
  226. switch(pResponse->command)
  227. {
  228. case SMTP_NONE:
  229. break;
  230. case SMTP_BANNER:
  231. break;
  232. case SMTP_CONNECTED:
  233. if (pResponse->fDone)
  234. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_CONNECTED, 0);
  235. break;
  236. case SMTP_SEND_MESSAGE:
  237. if (pResponse->fDone)
  238. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_SEND_MESSAGE, 0);
  239. break;
  240. case SMTP_EHLO:
  241. if (pResponse->fDone)
  242. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_EHLO, 0);
  243. break;
  244. case SMTP_HELO:
  245. if (pResponse->fDone)
  246. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_HELO, 0);
  247. break;
  248. case SMTP_MAIL:
  249. if (pResponse->fDone)
  250. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_MAIL, 0);
  251. break;
  252. case SMTP_RCPT:
  253. if (pResponse->fDone)
  254. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_RCPT, 0);
  255. break;
  256. case SMTP_RSET:
  257. if (pResponse->fDone)
  258. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_RSET, 0);
  259. break;
  260. case SMTP_QUIT:
  261. if (pResponse->fDone)
  262. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_QUIT, 0);
  263. break;
  264. case SMTP_DATA:
  265. if (pResponse->fDone)
  266. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_DATA, 0);
  267. break;
  268. case SMTP_DOT:
  269. if (pResponse->fDone)
  270. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_DOT, 0);
  271. break;
  272. case SMTP_SEND_STREAM:
  273. if (pResponse->fDone)
  274. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_SEND_STREAM, 0);
  275. break;
  276. case SMTP_CUSTOM:
  277. if (pResponse->fDone)
  278. PostThreadMessage(GetCurrentThreadId(), MsgSMTP, SMTP_CUSTOM, 0);
  279. break;
  280. }
  281. return S_OK;
  282. }