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.

343 lines
14 KiB

  1. /**INC+**********************************************************************/
  2. /* Header: cchan.h */
  3. /* */
  4. /* Purpose: Virtual Channel 'internal' API file */
  5. /* */
  6. /* Copyright(C) Microsoft Corporation 1997 */
  7. /* */
  8. /****************************************************************************/
  9. /** Changes:
  10. * $Log$
  11. **/
  12. /**INC-**********************************************************************/
  13. /****************************************************************************/
  14. /* Include 'external' API file */
  15. /****************************************************************************/
  16. #ifndef _H_CHAN_
  17. #define _H_CHAN_
  18. extern "C" {
  19. #include <cchannel.h>
  20. }
  21. #include "objs.h"
  22. #include "cd.h"
  23. #include "drapi.h"
  24. //
  25. // Enable code that verifies each compression
  26. // by decompressing
  27. //
  28. // #define DEBUG_CCHAN_COMPRESSION 1
  29. class CChan;
  30. /****************************************************************************/
  31. /****************************************************************************/
  32. /* TYPEDEFS */
  33. /****************************************************************************/
  34. /****************************************************************************/
  35. /**STRUCT+*******************************************************************/
  36. /* Structure: CHANNEL_INIT_HANDLE */
  37. /* */
  38. /* Description: Channel data held per user */
  39. /****************************************************************************/
  40. //NOTE: This structure needs to be exposed to 'internal' plugins e.g rdpdr
  41. // so the definition is is vchandle.h
  42. // Internal plugins need to know the structure because they access
  43. // the lpInternalAddinParam field
  44. #include "vchandle.h"
  45. #define VC_MIN_COMPRESS_INPUT_BUF 50
  46. #define VC_MAX_COMPRESS_INPUT_BUF CHANNEL_CHUNK_LENGTH
  47. // Size of sample for MPPC compression statistics.
  48. #define VC_MPPC_SAMPLE_SIZE 65535
  49. // Compression scaling factor
  50. #define VC_UNCOMP_BYTES 1024
  51. // Limit to prevent off behaviour
  52. #define VC_COMP_LIMIT 25
  53. #define VC_USER_OUTBUF (CHANNEL_CHUNK_LENGTH+sizeof(CHANNEL_PDU_HEADER))
  54. #define VC_MAX_COMPRESSED_BUFFER (CHANNEL_CHUNK_LENGTH*2)
  55. /**STRUCT-*******************************************************************/
  56. /**STRUCT+*******************************************************************/
  57. /* Structure: CHANNEL_DATA */
  58. /* */
  59. /* Description: Information about all channels */
  60. /****************************************************************************/
  61. typedef struct tagCHANNEL_DATA
  62. {
  63. PCHANNEL_OPEN_EVENT_FN pOpenEventFn;
  64. PCHANNEL_OPEN_EVENT_EX_FN pOpenEventExFn;
  65. DCUINT16 MCSChannelID;
  66. DCUINT16 pad;
  67. PCHANNEL_INIT_HANDLE pInitHandle;
  68. DCUINT status;
  69. #define CHANNEL_STATUS_CLOSED 0
  70. #define CHANNEL_STATUS_OPEN 1
  71. DCUINT priority;
  72. DCUINT SLFlags;
  73. DCUINT VCFlags;
  74. } CHANNEL_DATA, DCPTR PCHANNEL_DATA;
  75. /**STRUCT-*******************************************************************/
  76. /**STRUCT+*******************************************************************/
  77. /* Structure: CHANNEL_WRITE_DECOUPLE */
  78. /* */
  79. /* Description:structure passed to IntChannelWrite */
  80. /****************************************************************************/
  81. typedef struct tagCHANNEL_WRITE_DECOUPLE
  82. {
  83. DCUINT32 signature;
  84. #define CHANNEL_DECOUPLE_SIGNATURE 0x43684465 /* "ChDe" */
  85. LPVOID pData;
  86. HPDCVOID pNextData;
  87. ULONG dataLength;
  88. ULONG dataLeft;
  89. ULONG dataSent;
  90. DWORD openHandle;
  91. LPVOID pUserData;
  92. DCUINT32 flags;
  93. unsigned chanOptions;
  94. struct tagCHANNEL_WRITE_DECOUPLE * pPrev;
  95. struct tagCHANNEL_WRITE_DECOUPLE * pNext;
  96. } CHANNEL_WRITE_DECOUPLE,
  97. DCPTR PCHANNEL_WRITE_DECOUPLE,
  98. DCPTR DCPTR PPCHANNEL_WRITE_DECOUPLE;
  99. /**STRUCT-*******************************************************************/
  100. typedef struct tagDEVICE_PARAMS
  101. {
  102. WPARAM wParam;
  103. LPARAM lParam;
  104. IRDPDR_INTERFACE_OBJ *deviceObj;
  105. } DEVICE_PARAMS, *PDEVICE_PARAMS;
  106. class CCD;
  107. class CSL;
  108. class CUT;
  109. class CUI;
  110. extern "C" {
  111. #ifdef OS_WIN32
  112. BOOL DCAPI
  113. #else //OS_WIN32
  114. BOOL __loadds DCAPI
  115. #endif //OS_WIN32
  116. MSTSCAX_VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS_EX pEntryPointsEx,
  117. PVOID pAxCtlInstance);
  118. } // extern "C"
  119. class CChan
  120. {
  121. public:
  122. CChan(CObjs* objs);
  123. ~CChan();
  124. public:
  125. DCVOID DCCALLBACK ChannelOnInitialized(DCVOID);
  126. DCVOID DCCALLBACK ChannelOnTerminating(DCVOID);
  127. DCVOID DCCALLBACK ChannelOnConnected(DCUINT channelID,
  128. DCUINT32 serverVersion,
  129. PDCVOID pUserData,
  130. DCUINT userDataLength);
  131. DCVOID DCCALLBACK ChannelOnDisconnected(DCUINT reason);
  132. DCVOID DCCALLBACK ChannelOnSuspended(DCUINT reason);
  133. DCVOID DCCALLBACK ChannelOnPacketReceived(PDCUINT8 pData,
  134. DCUINT dataLen,
  135. DCUINT flags,
  136. DCUINT userID,
  137. DCUINT priority);
  138. DCVOID DCCALLBACK ChannelOnBufferAvailable(DCVOID);
  139. DCVOID DCCALLBACK ChannelOnConnecting(PPCHANNEL_DEF ppChannel,
  140. PDCUINT32 pChannelCount);
  141. DCVOID DCCALLBACK ChannelOnInitializing(DCVOID);
  142. //
  143. // Per instance versions of external channel API
  144. //
  145. UINT VCAPITYPE IntVirtualChannelInit(
  146. PVOID pParam,
  147. PVOID * ppInitHandle,
  148. PCHANNEL_DEF pChannel,
  149. INT channelCount,
  150. DWORD versionRequested,
  151. PCHANNEL_INIT_EVENT_FN pChannelInitEventProc,
  152. PCHANNEL_INIT_EVENT_EX_FN pChannelInitEventProcEx);
  153. UINT VCAPITYPE DCEXPORT IntVirtualChannelOpen(
  154. PVOID pInitHandle,
  155. PDWORD pOpenHandle,
  156. PCHAR pChannelName,
  157. PCHANNEL_OPEN_EVENT_FN pChannelOpenEventProc,
  158. PCHANNEL_OPEN_EVENT_EX_FN pChannelOpenEventProcEx);
  159. UINT VCAPITYPE DCEXPORT IntVirtualChannelClose(DWORD openHandle);
  160. UINT VCAPITYPE DCEXPORT IntVirtualChannelWrite(DWORD openHandle,
  161. LPVOID pData,
  162. ULONG dataLength,
  163. LPVOID pUserData);
  164. VOID SetCapabilities(LONG caps);
  165. void OnDeviceChange(ULONG_PTR);
  166. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CChan, OnDeviceChange);
  167. public:
  168. //
  169. // Member data
  170. //
  171. /****************************************************************************/
  172. /* Pointer to first Init Handle */
  173. /****************************************************************************/
  174. PCHANNEL_INIT_HANDLE _pInitHandle;
  175. /****************************************************************************/
  176. /* Pointer to first and last queued write operations - can be accessed only */
  177. /* on SND thread. */
  178. /****************************************************************************/
  179. PCHANNEL_WRITE_DECOUPLE _pFirstWrite;
  180. PCHANNEL_WRITE_DECOUPLE _pLastWrite;
  181. /****************************************************************************/
  182. /* State informtation */
  183. /****************************************************************************/
  184. #define CONNECTION_NONE 0
  185. #define CONNECTION_V1 1
  186. #define CONNECTION_VC 2
  187. #define CONNECTION_SUSPENDED 3
  188. DCUINT _connected;
  189. /****************************************************************************/
  190. /* State information used by IntChannelLoad */
  191. /****************************************************************************/
  192. DCBOOL _inChannelEntry;
  193. DCBOOL _ChannelInitCalled;
  194. PCHANNEL_INIT_HANDLE _newInitHandle;
  195. /****************************************************************************/
  196. /* Channel data */
  197. /****************************************************************************/
  198. CHANNEL_DEF _channel[CHANNEL_MAX_COUNT];
  199. CHANNEL_DATA _channelData[CHANNEL_MAX_COUNT];
  200. DCUINT _channelCount;
  201. /****************************************************************************/
  202. /* Channel entry points */
  203. /****************************************************************************/
  204. CHANNEL_ENTRY_POINTS _channelEntryPoints;
  205. CHANNEL_ENTRY_POINTS_EX _channelEntryPointsEx;
  206. static CChan* pStaticClientInstance;
  207. private:
  208. /****************************************************************************/
  209. /****************************************************************************/
  210. /* Internal functions (defined later) */
  211. /****************************************************************************/
  212. /****************************************************************************/
  213. DCVOID DCINTERNAL IntChannelCallCallbacks(DCUINT event,
  214. PDCVOID pData,
  215. DCUINT dataLength);
  216. DCVOID DCINTERNAL IntChannelFreeLibrary(DCUINT value);
  217. DCVOID DCINTERNAL IntChannelSend(ULONG_PTR value);
  218. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CChan, IntChannelSend);
  219. DCVOID DCINTERNAL IntChannelCancelSend(ULONG_PTR value);
  220. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CChan, IntChannelCancelSend);
  221. DCVOID DCINTERNAL IntChannelWrite(PDCVOID pData, DCUINT dataLength);
  222. EXPOSE_CD_NOTIFICATION_FN(CChan, IntChannelWrite);
  223. DCVOID DCINTERNAL IntChannelLoad(PDCTCHAR DLLName);
  224. DCBOOL DCINTERNAL IntChannelInitAddin(PVIRTUALCHANNELENTRY pChanEntry,
  225. PVIRTUALCHANNELENTRYEX pChanEntryEx,
  226. HMODULE hMod,
  227. PDCTCHAR DLLName,
  228. PVOID pPassParamToEx);
  229. inline UCHAR IntChannelCompressData(UCHAR* pSrcData, ULONG cbSrcLen,
  230. UCHAR* pOutBuf, ULONG* pcbOutLen);
  231. private:
  232. CObjs* _pClientObjs;
  233. CCD* _pCd;
  234. CSL* _pSl;
  235. CUT* _pUt;
  236. CUI* _pUi;
  237. BOOL _fLockInitalized;
  238. CRITICAL_SECTION _VirtualChannelInitLock;
  239. BOOL _fCapsVCCompressionSupported;
  240. //
  241. // VC flag that specifies we are compressing
  242. // channels for this session. Individual channels can choose
  243. // to be compressed or not, be compression will only take place
  244. // if this flag is set.
  245. //
  246. // Same thing for decompressing channel data, we only decompress if
  247. // this flag is set and the virtual channel header specifies the
  248. // channel is compressed.
  249. //
  250. BOOL _fCompressChannels;
  251. //Compression stats
  252. #ifdef DC_DEBUG
  253. unsigned _cbBytesRecvd;
  254. unsigned _cbCompressedBytesRecvd;
  255. unsigned _cbDecompressedBytesRecvd;
  256. unsigned _cbTotalBytesUserAskSend; //total bytes user asked to send
  257. unsigned _cbTotalBytesSent; //total bytes actually sent on net
  258. unsigned _cbComprInput; //total compression input bytes
  259. unsigned _cbComprOutput; //total compression output bytes
  260. #endif
  261. SendContext* _pMPPCContext;
  262. LONG _CompressFlushes;
  263. BOOL _fCompressionFlushed;
  264. //When decompressing, we can't just hand of a pointer to the decompressed
  265. //data as the user may corrupt the decompression context, so we need to make
  266. //a copy into a user outbuf.
  267. PUCHAR _pUserOutBuf;
  268. //Reset the compression context
  269. BOOL _fNeedToResetContext;
  270. #ifdef DEBUG_CCHAN_COMPRESSION
  271. RecvContext2_8K* _pDbgRcvDecompr8K;
  272. RecvContext1 _DbgRcvContext1;
  273. BOOL _fDbgVCTriedAllocRecvContext;
  274. BOOL _fDbgAllocFailedForVCRecvContext;
  275. #endif
  276. INT _iDbgCompressFailedCount;
  277. INT _iChanSuspendCount;
  278. INT _iChanResumeCount;
  279. INT _iChanCapsRecvdCount;
  280. };
  281. #endif // _H_CHAN_