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.

168 lines
4.8 KiB

  1. // --------------------------------------------------------------------------------
  2. // Rascall.cpp
  3. // --------------------------------------------------------------------------------
  4. #include "pch.h"
  5. #include "iconsole.h"
  6. #include "rascall.h"
  7. // --------------------------------------------------------------------------------
  8. // HrCreateRASTransport
  9. // --------------------------------------------------------------------------------
  10. HRESULT HrCreateRASTransport(IRASTransport **ppRAS)
  11. {
  12. // Locals
  13. HRESULT hr;
  14. CRASCallback *pCallback=NULL;
  15. // Create callback object
  16. pCallback = new CRASCallback();
  17. if (NULL == pCallback)
  18. {
  19. printf("Memory allocation failure\n");
  20. return E_OUTOFMEMORY;
  21. }
  22. // Load SMTP Transport
  23. hr = CoCreateInstance(CLSID_IRASTransport, NULL, CLSCTX_INPROC_SERVER, IID_IRASTransport, (LPVOID *)ppRAS);
  24. if (FAILED(hr))
  25. {
  26. pCallback->Release();
  27. printf("Unable to load CLSID_IMNXPORT - IID_IRASTransport\n");
  28. return E_FAIL;
  29. }
  30. // InitNew
  31. hr = (*ppRAS)->InitNew(pCallback);
  32. if (FAILED(hr))
  33. {
  34. pCallback->Release();
  35. printf("Unable to load CLSID_IMNXPORT - IID_IRASTransport\n");
  36. return E_FAIL;
  37. }
  38. // Done
  39. pCallback->Release();
  40. return S_OK;
  41. }
  42. // --------------------------------------------------------------------------------
  43. // CRASCallback::CRASCallback
  44. // --------------------------------------------------------------------------------
  45. CRASCallback::CRASCallback(void)
  46. {
  47. m_cRef = 1;
  48. }
  49. // --------------------------------------------------------------------------------
  50. // CRASCallback::~CRASCallback
  51. // --------------------------------------------------------------------------------
  52. CRASCallback::~CRASCallback(void)
  53. {
  54. }
  55. // --------------------------------------------------------------------------------
  56. // CRASCallback::QueryInterface
  57. // --------------------------------------------------------------------------------
  58. STDMETHODIMP CRASCallback::QueryInterface(REFIID riid, LPVOID *ppv)
  59. {
  60. // Locals
  61. HRESULT hr=S_OK;
  62. // Bad param
  63. if (ppv == NULL)
  64. {
  65. hr = E_INVALIDARG;
  66. goto exit;
  67. }
  68. // Init
  69. *ppv=NULL;
  70. // IID_IUnknown
  71. if (IID_IUnknown == riid)
  72. *ppv = (IUnknown *)this;
  73. // IID_IRASCallback
  74. else if (IID_IRASCallback == riid)
  75. *ppv = (IRASCallback *)this;
  76. // If not null, addref it and return
  77. if (NULL != *ppv)
  78. {
  79. ((LPUNKNOWN)*ppv)->AddRef();
  80. goto exit;
  81. }
  82. // No Interface
  83. hr = E_NOINTERFACE;
  84. exit:
  85. // Done
  86. return hr;
  87. }
  88. // --------------------------------------------------------------------------------
  89. // CRASCallback::AddRef
  90. // --------------------------------------------------------------------------------
  91. STDMETHODIMP_(ULONG) CRASCallback::AddRef(void)
  92. {
  93. return ++m_cRef;
  94. }
  95. // --------------------------------------------------------------------------------
  96. // CRASCallback::Release
  97. // --------------------------------------------------------------------------------
  98. STDMETHODIMP_(ULONG) CRASCallback::Release(void)
  99. {
  100. if (0 != --m_cRef)
  101. return m_cRef;
  102. delete this;
  103. return 0;
  104. }
  105. STDMETHODIMP CRASCallback::OnReconnect(
  106. LPSTR pszCurrentConnectoid,
  107. LPSTR pszNewConnectoid,
  108. IRASTransport *pTransport)
  109. {
  110. printf("CRASCallback::OnReconnect - %s --> %s\n", pszCurrentConnectoid, pszNewConnectoid);
  111. return S_OK;
  112. }
  113. STDMETHODIMP CRASCallback::OnLogonPrompt(
  114. LPIXPRASLOGON pRasLogon,
  115. IRASTransport *pTransport)
  116. {
  117. printf("CRASCallback::OnLogonPrompt\n");
  118. return S_OK;
  119. }
  120. STDMETHODIMP CRASCallback::OnRasDialStatus(
  121. RASCONNSTATE rasconnstate,
  122. DWORD dwError,
  123. IRASTransport *pTransport)
  124. {
  125. printf("CRASCallback::OnRasDialStatus - State: %d, dwError: %d\n", rasconnstate, dwError);
  126. if (dwError || (rasconnstate == RASCS_Connected || rasconnstate == RASCS_Disconnected))
  127. {
  128. if (dwError)
  129. {
  130. CHAR szError[1024];
  131. DWORD dwResult;
  132. g_pRAS->GetRasErrorString(dwError, szError, 1024, &dwResult);
  133. if (dwResult == 0)
  134. printf("Ras Error: %s\n", szError);
  135. }
  136. PostThreadMessage(GetCurrentThreadId(), g_msgRAS, RAS_CONNECT, 0);
  137. }
  138. return S_OK;
  139. }
  140. STDMETHODIMP CRASCallback::OnDisconnect(
  141. LPSTR pszCurrentConnectoid,
  142. boolean fConnectionOwner,
  143. IRASTransport *pTransport)
  144. {
  145. printf("CRASCallback::OnDisconnect - %s, Connection Owner: %d\n", pszCurrentConnectoid, fConnectionOwner);
  146. return S_OK;
  147. }