Source code of Windows XP (NT5)
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.

242 lines
7.4 KiB

  1. #ifndef _T120_TRANSPORT_H_
  2. #define _T120_TRANSPORT_H_
  3. #include "iplgxprt.h"
  4. #include "it120xprt.h"
  5. #include "socket.h"
  6. #include "mcattprt.h"
  7. #include "imst123.h"
  8. #define MAX_PLUGGABLE_OUT_BUF_SIZE 32
  9. #define MAX_PLUGXPRT_CONNECTIONS 16
  10. #define MAX_PLUGXPRT_EVENTS 5 // read, write, close, pending read, and pending write
  11. #define MAKE_PLUGXPRT_WPARAM(id,type) (MAKELONG(id,type))
  12. #define PLUGXPRT_WPARAM_TO_ID(wParam) (LOWORD(wParam))
  13. #define PLUGXPRT_WPARAM_TO_TYPE(wParam) (HIWORD(wParam))
  14. #define MAKE_PLUGXPRT_LPARAM(evt,err) (MAKELONG(evt,err))
  15. #define PLUGXPRT_LPARAM_TO_EVENT(lParam) (LOWORD(lParam))
  16. #define PLUGXPRT_LPARAM_TO_ERROR(lParam) (HIWORD(lParam))
  17. enum
  18. {
  19. PLUGXPRT_PENDING_EVENT = 0,
  20. PLUGXPRT_EVENT_READ = 1,
  21. PLUGXPRT_EVENT_WRITE = 2,
  22. PLUGXPRT_EVENT_CLOSE = 3,
  23. PLUGXPRT_EVENT_ACCEPT = 4,
  24. PLUGXPRT_EVENT_CONNECT = 5,
  25. PLUGXPRT_HIGH_LEVEL_READ = 6,
  26. PLUGXPRT_HIGH_LEVEL_WRITE = 7,
  27. };
  28. class CPluggableOutBufQueue2 : public CQueue2
  29. {
  30. DEFINE_CQUEUE2(CPluggableOutBufQueue2, LPBYTE, int)
  31. };
  32. class CPluggableConnection : public CRefCount
  33. {
  34. public:
  35. CPluggableConnection(PLUGXPRT_CALL_TYPE eCaller, HANDLE hCommLink,
  36. HANDLE hevtRead, HANDLE hevtWrite, HANDLE hevtClose,
  37. PLUGXPRT_FRAMING eFraming, PLUGXPRT_PARAMETERS *pParams,
  38. T120Error *);
  39. ~CPluggableConnection(void);
  40. LPSTR GetConnString(void) { return &m_szConnID[0]; }
  41. UINT GetConnID(void) { return m_nConnID; }
  42. HANDLE GetCommLink(void) { return m_hCommLink; }
  43. HANDLE GetReadEvent(void) { return m_hevtRead; }
  44. HANDLE GetWriteEvent(void) { return m_hevtWrite; }
  45. HANDLE GetCloseEvent(void) { return m_hevtClose; }
  46. void SetSocket(PSocket pSocket) { m_pSocket = pSocket; }
  47. PSocket GetSocket(void) { return m_pSocket; }
  48. TransportType GetType(void) { return m_eType; }
  49. BOOL IsCaller(void) { return (PLUGXPRT_CALLER == m_eCaller); }
  50. BOOL IsCallee(void) { return (PLUGXPRT_CALLEE == m_eCaller); }
  51. HANDLE GetPendingReadEvent(void) { return m_hevtPendingRead; }
  52. HANDLE GetPendingWriteEvent(void) { return m_hevtPendingWrite; }
  53. T120Error UpdateCommLink(HANDLE hCommLink);
  54. int Read(LPBYTE buffer, int length, PLUGXPRT_RESULT *);
  55. BOOL OnPendingRead(void);
  56. int Write(LPBYTE buffer, int length, PLUGXPRT_RESULT *);
  57. BOOL OnPendingWrite(void);
  58. void WriteTheFirst(void);
  59. void NotifyHighLevelRead(void);
  60. void NotifyReadFailure(void);
  61. void NotifyHighLevelWrite(void);
  62. void NotifyWriteFailure(void);
  63. void NotifyWriteEvent(void);
  64. BOOL SetupReadState(int length);
  65. void CleanupReadState(void);
  66. void CleanupWriteState(void);
  67. void Shutdown(void);
  68. //
  69. // Legacy PSTN transport
  70. //
  71. LEGACY_HANDLE GetLegacyHandle(void) { return m_nLegacyLogicalHandle; }
  72. void SetLegacyHandle(LEGACY_HANDLE logical_handle) { m_nLegacyLogicalHandle = logical_handle; }
  73. TransportError TConnectRequest(void);
  74. TransportError TDisconnectRequest(void);
  75. int TDataRequest(LPBYTE pbData, ULONG cbDataSize, PLUGXPRT_RESULT *);
  76. TransportError TPurgeRequest(void);
  77. private:
  78. PLUGXPRT_STATE m_eState;
  79. PLUGXPRT_CALL_TYPE m_eCaller;
  80. HANDLE m_hCommLink;
  81. HANDLE m_hevtRead;
  82. HANDLE m_hevtWrite;
  83. HANDLE m_hevtClose;
  84. TransportType m_eType;
  85. PSocket m_pSocket;
  86. UINT m_nConnID;
  87. char m_szConnID[T120_CONNECTION_ID_LENGTH];
  88. //
  89. // Legacy PSTN transport
  90. //
  91. LEGACY_HANDLE m_nLegacyLogicalHandle;
  92. //
  93. // X.224 framing
  94. //
  95. HANDLE m_hevtPendingRead; // for asynchronous ReadFile()
  96. HANDLE m_hevtPendingWrite; // for asynchronous WriteFile()
  97. // IO queue management for X.224
  98. BOOL m_fPendingReadDone;
  99. int m_cbPendingRead;
  100. LPBYTE m_pbPendingRead;
  101. OVERLAPPED m_OverlappedRead;
  102. int m_cbPendingWrite;
  103. LPBYTE m_pbPendingWrite;
  104. OVERLAPPED m_OverlappedWrite;
  105. CPluggableOutBufQueue2 m_OutBufQueue2;
  106. };
  107. class CPluggableConnectionList : public CList
  108. {
  109. DEFINE_CLIST(CPluggableConnectionList, CPluggableConnection *)
  110. };
  111. class CPluggableTransport : public IT120PluggableTransport,
  112. public CRefCount
  113. {
  114. public:
  115. CPluggableTransport(void);
  116. ~CPluggableTransport(void);
  117. STDMETHOD_(void, ReleaseInterface) (THIS);
  118. STDMETHOD_(T120Error, CreateConnection) (THIS_
  119. char szConnID[],
  120. PLUGXPRT_CALL_TYPE eCaller,
  121. HANDLE hCommLink,
  122. HANDLE hevtRead,
  123. HANDLE hevtWrite,
  124. HANDLE hevtClose,
  125. PLUGXPRT_FRAMING eFraming,
  126. PLUGXPRT_PARAMETERS *pParams);
  127. STDMETHOD_(T120Error, UpdateConnection) (THIS_
  128. LPSTR pszConnID,
  129. HANDLE hCommLink);
  130. STDMETHOD_(T120Error, CloseConnection) (THIS_ LPSTR pszConnID);
  131. STDMETHOD_(T120Error, EnableWinsock) (THIS);
  132. STDMETHOD_(T120Error, DisableWinsock) (THIS);
  133. STDMETHOD_(void, Advise) (THIS_ LPFN_PLUGXPRT_CB, LPVOID pContext);
  134. STDMETHOD_(void, UnAdvise) (THIS);
  135. STDMETHOD_(void, ResetConnCounter) (THIS);
  136. void OnProtocolControl(TransportConnection, PLUGXPRT_STATE, PLUGXPRT_RESULT);
  137. ULONG UpdateEvents(HANDLE *aHandles);
  138. void OnEventSignaled(HANDLE hevtSignaled);
  139. void OnEventAbandoned(HANDLE hevtSignaled);
  140. CPluggableConnection * GetPluggableConnection(PSocket pSocket);
  141. CPluggableConnection * GetPluggableConnection(UINT_PTR nConnID);
  142. CPluggableConnection * GetPluggableConnection(HANDLE hCommLink);
  143. CPluggableConnection * GetPluggableConnectionByLegacyHandle(LEGACY_HANDLE);
  144. //
  145. // legacy tranport
  146. //
  147. BOOL EnsureLegacyTransportLoaded(void);
  148. private:
  149. LPFN_PLUGXPRT_CB m_pfnNotify;
  150. LPVOID m_pContext;
  151. CPluggableConnectionList m_PluggableConnectionList;
  152. };
  153. void OnProtocolControl(TransportConnection, PLUGXPRT_STATE,
  154. PLUGXPRT_RESULT eResult = PLUGXPRT_RESULT_SUCCESSFUL);
  155. ULONG CreateConnString(int nConnID, char szConnID[]);
  156. BOOL IsValidPluggableTransportName(LPCSTR pcszNodeAddress);
  157. UINT GetPluggableTransportConnID(LPCSTR pcszNodeAddress);
  158. CPluggableConnection * GetPluggableConnection(PSocket pSocket);
  159. CPluggableConnection * GetPluggableConnection(UINT_PTR nConnID);
  160. CPluggableConnection * GetPluggableConnection(HANDLE hCommLink);
  161. CPluggableConnection * GetPluggableConnectionByLegacyHandle(LEGACY_HANDLE);
  162. int SubmitPluggableRead(PSocket, LPBYTE buffer, int length, PLUGXPRT_RESULT *);
  163. int SubmitPluggableWrite(PSocket, LPBYTE buffer, int length, PLUGXPRT_RESULT *);
  164. void PluggableWriteTheFirst(TransportConnection);
  165. void PluggableShutdown(TransportConnection);
  166. //
  167. // PSTN framing
  168. //
  169. TransportError TReceiveBufferAvailable(void);
  170. extern ILegacyTransport *g_pLegacyTransport;
  171. extern BOOL g_fWinsockDisabled;
  172. extern CRITICAL_SECTION g_csTransport;
  173. #if defined(TEST_PLUGGABLE) && defined(_DEBUG)
  174. LPCSTR FakeNodeAddress(LPCSTR pcszNodeAddress);
  175. #endif
  176. #endif // _T120_TRANSPORT_H_
  177.