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.

342 lines
15 KiB

  1. /****************************************************************************/
  2. /* ausrapi.cpp */
  3. /* */
  4. /* RDP Update sender/receiver API functions */
  5. /* */
  6. /* Copyright(c) Microsoft, PictureTel 1992-1997 */
  7. /* Copyright(c) Microsoft 1997-1999 */
  8. /****************************************************************************/
  9. #include <precomp.h>
  10. #pragma hdrstop
  11. #define TRC_FILE "ausrapi"
  12. #include <as_conf.hpp>
  13. /****************************************************************************/
  14. /* API FUNCTION: USR_Init */
  15. /* */
  16. /* Initializes the USR. */
  17. /****************************************************************************/
  18. void RDPCALL SHCLASS USR_Init(void)
  19. {
  20. TS_BITMAP_CAPABILITYSET BitmapCaps;
  21. TS_FONT_CAPABILITYSET FontCaps;
  22. DC_BEGIN_FN("USR_Init");
  23. /************************************************************************/
  24. /* This initialises all the global data for this component */
  25. /************************************************************************/
  26. #define DC_INIT_DATA
  27. #include <ausrdata.c>
  28. #undef DC_INIT_DATA
  29. /************************************************************************/
  30. /* Setup the local font capabilities */
  31. /************************************************************************/
  32. FontCaps.capabilitySetType = TS_CAPSETTYPE_FONT;
  33. FontCaps.lengthCapability = sizeof(FontCaps);
  34. FontCaps.fontSupportFlags = TS_FONTSUPPORT_FONTLIST;
  35. FontCaps.pad2octets = 0;
  36. CPC_RegisterCapabilities((PTS_CAPABILITYHEADER)&FontCaps,
  37. sizeof(TS_FONTSUPPORT_FONTLIST));
  38. /************************************************************************/
  39. /* Initialize the local bitmap capabilities structure. */
  40. /************************************************************************/
  41. BitmapCaps.capabilitySetType = TS_CAPSETTYPE_BITMAP;
  42. BitmapCaps.preferredBitsPerPixel = (TSUINT16)m_desktopBpp;
  43. BitmapCaps.receive1BitPerPixel = TS_CAPSFLAG_SUPPORTED;
  44. BitmapCaps.receive4BitsPerPixel = TS_CAPSFLAG_SUPPORTED;
  45. BitmapCaps.receive8BitsPerPixel = TS_CAPSFLAG_SUPPORTED;
  46. BitmapCaps.desktopWidth = (TSUINT16)m_desktopWidth;
  47. BitmapCaps.desktopHeight = (TSUINT16)m_desktopHeight;
  48. BitmapCaps.pad2octets = 0;
  49. BitmapCaps.desktopResizeFlag = TS_CAPSFLAG_SUPPORTED;
  50. BitmapCaps.bitmapCompressionFlag = TS_CAPSFLAG_SUPPORTED;
  51. BitmapCaps.highColorFlags = 0;
  52. BitmapCaps.pad1octet = 0;
  53. BitmapCaps.multipleRectangleSupport = TS_CAPSFLAG_SUPPORTED;
  54. BitmapCaps.pad2octetsB = 0;
  55. CPC_RegisterCapabilities((PTS_CAPABILITYHEADER)&BitmapCaps,
  56. sizeof(TS_BITMAP_CAPABILITYSET));
  57. /************************************************************************/
  58. /* Initialize the sub components. */
  59. /************************************************************************/
  60. UP_Init();
  61. OE_Init();
  62. SDG_Init();
  63. OA_Init();
  64. BA_Init();
  65. DC_END_FN();
  66. }
  67. /****************************************************************************/
  68. /* API FUNCTION: USR_Term */
  69. /* */
  70. /* Terminate the USR. */
  71. /****************************************************************************/
  72. void RDPCALL SHCLASS USR_Term(void)
  73. {
  74. DC_BEGIN_FN("USR_Term");
  75. TRC_NRM((TB, "Notify share exit ? %s", m_pShm ? "Y" : "N"));
  76. // Set the "font info sent" flag so we don't try to send it again.
  77. usrRemoteFontInfoSent = TRUE;
  78. usrRemoteFontInfoReceived = FALSE;
  79. // Terminate the sub components.
  80. UP_Term();
  81. OE_Term();
  82. OA_Term();
  83. SDG_Term();
  84. BA_Term();
  85. DC_END_FN();
  86. }
  87. /****************************************************************************/
  88. // USR_ProcessRemoteFonts
  89. //
  90. // Returns a FontMapPDU to the client and releases the DD IOCTL waiting for
  91. // client connection sequence completion.
  92. /****************************************************************************/
  93. void RDPCALL SHCLASS USR_ProcessRemoteFonts(
  94. PTS_FONT_LIST_PDU pFontListPDU,
  95. unsigned DataLength,
  96. LOCALPERSONID localID)
  97. {
  98. unsigned listFlags;
  99. DC_BEGIN_FN("USR_ProcessRemoteFonts");
  100. if (DataLength >= (sizeof(TS_FONT_LIST_PDU) - sizeof(TS_FONT_ATTRIBUTE))) {
  101. listFlags = pFontListPDU->listFlags;
  102. // If this is the last entry we will be receiving, return an empty font
  103. // map PDU (since we no longer support text orders, only the glyph cache).
  104. // Then release the client-connection lock to allow us to return to
  105. // the DD from the DD connection IOCTL.
  106. if (listFlags & TS_FONTLIST_LAST) {
  107. PTS_FONT_MAP_PDU pFontMapPDU;
  108. unsigned pktSize;
  109. usrRemoteFontInfoReceived = TRUE;
  110. // Send font map to client.
  111. if (!usrRemoteFontInfoSent) {
  112. // Calculate the total packet size.
  113. // Allow for the fact that sizeof(TS_FONT_PDU) already
  114. // includes one TS_FONT_ATTRIBUTE structure.
  115. pktSize = sizeof(TS_FONT_MAP_PDU) - sizeof(TS_FONTTABLE_ENTRY);
  116. // Allocate a Network Packet of the correct size.
  117. if ( STATUS_SUCCESS == SC_AllocBuffer((PPVOID)&pFontMapPDU, pktSize) ) {
  118. // Fill in the data and send it.
  119. pFontMapPDU->shareDataHeader.shareControlHeader.pduType =
  120. TS_PDUTYPE_DATAPDU | TS_PROTOCOL_VERSION;
  121. TS_DATAPKT_LEN(pFontMapPDU) = (UINT16)pktSize;
  122. pFontMapPDU->shareDataHeader.pduType2 =
  123. TS_PDUTYPE2_FONTMAP;
  124. pFontMapPDU->data.mapFlags = 0;
  125. pFontMapPDU->data.totalNumEntries = 0;
  126. pFontMapPDU->data.entrySize =
  127. ((UINT16)sizeof(TS_FONTTABLE_ENTRY));
  128. pFontMapPDU->data.mapFlags |= TS_FONTMAP_FIRST;
  129. pFontMapPDU->data.mapFlags |= TS_FONTMAP_LAST;
  130. // Set the number of font mappings we actually put in the
  131. // packet.
  132. pFontMapPDU->data.numberEntries = 0;
  133. SC_SendData((PTS_SHAREDATAHEADER)pFontMapPDU, pktSize,
  134. pktSize, PROT_PRIO_MISC, 0);
  135. TRC_NRM((TB, "Sent font map packet with %hu fonts mappings",
  136. pFontMapPDU->data.numberEntries));
  137. // Set the flag that indicates that we have successfully
  138. // sent the font info.
  139. usrRemoteFontInfoSent = TRUE;
  140. // Kick WDW back into life.
  141. TRC_NRM((TB, "Wake up WDW"));
  142. WDW_ShareCreated(m_pTSWd, TRUE);
  143. }
  144. else {
  145. // Failed to allocate a packet.
  146. TRC_ALT((TB, "Failed to alloc font map packet"));
  147. }
  148. }
  149. }
  150. }
  151. else {
  152. TRC_ERR((TB,"Received FONT_LIST_PDU bad size %u", DataLength));
  153. WDW_LogAndDisconnect(m_pTSWd, TRUE, Log_RDP_ShareDataTooShort,
  154. (BYTE *)pFontListPDU, DataLength);
  155. }
  156. DC_END_FN();
  157. }
  158. /****************************************************************************/
  159. /* API FUNCTION: USR_PartyJoiningShare */
  160. /* */
  161. /* Called when a party is added to the share. */
  162. /* */
  163. /* PARAMETERS: */
  164. /* locPersonID - the local ID of the host. */
  165. /* oldShareSize - the number of people in the share, excluding this one. */
  166. /* */
  167. /* RETURNS: */
  168. /* TRUE if the new person is acceptable, FALSE if not. */
  169. /****************************************************************************/
  170. BOOL RDPCALL SHCLASS USR_PartyJoiningShare(
  171. LOCALPERSONID locPersonID,
  172. unsigned oldShareSize)
  173. {
  174. BOOL rc;
  175. DC_BEGIN_FN("USR_PartyJoiningShare");
  176. DC_IGNORE_PARAMETER(locPersonID)
  177. if (oldShareSize == 0) {
  178. // Reset the "font info sent" flags.
  179. usrRemoteFontInfoSent = FALSE;
  180. usrRemoteFontInfoReceived = FALSE;
  181. // Continue periodic scheduling.
  182. SCH_ContinueScheduling(SCH_MODE_NORMAL);
  183. rc = TRUE;
  184. }
  185. else {
  186. /********************************************************************/
  187. /* There is more than one person in the share now, so check out the */
  188. /* combined capabilities. */
  189. /********************************************************************/
  190. rc = USRDetermineCaps();
  191. }
  192. DC_END_FN();
  193. return rc;
  194. }
  195. /****************************************************************************/
  196. /* API FUNCTION: USR_PartyLeftShare */
  197. /* */
  198. /* Called when a party is leaves the share. */
  199. /* */
  200. /* PARAMETERS: */
  201. /* locPersonID - the local network ID of the host. */
  202. /* newShareSize - the number of people in the share, excluding this one. */
  203. /****************************************************************************/
  204. void RDPCALL SHCLASS USR_PartyLeftShare(
  205. LOCALPERSONID locPersonID,
  206. unsigned newShareSize)
  207. {
  208. DC_BEGIN_FN("USR_PartyLeftShare");
  209. DC_IGNORE_PARAMETER(locPersonID)
  210. if (newShareSize == 0)
  211. {
  212. // Set the "font info sent" flag so we don't try to send it again.
  213. usrRemoteFontInfoSent = TRUE;
  214. usrRemoteFontInfoReceived = FALSE;
  215. }
  216. else if (newShareSize > 1)
  217. {
  218. /********************************************************************/
  219. /* There is still more than one person in the share now, so */
  220. /* redetermine the capabilities for the remaining parties. */
  221. /* USRDetermineCaps returns FALSE if it cannot determine common */
  222. /* caps, but this can never happen when someone is leaving the */
  223. /* share. */
  224. /********************************************************************/
  225. USRDetermineCaps();
  226. }
  227. DC_END_FN();
  228. }
  229. /****************************************************************************/
  230. /* FUNCTION: USRDetermineCaps */
  231. /* */
  232. /* Enumerates the bitmap capabilities of all parties currently in the */
  233. /* share, and determines the common capabilities. */
  234. /* */
  235. /* RETURNS: TRUE if there are good common caps, or false on failure (which */
  236. /* has the effect of rejecting a new party from joining the share). */
  237. /****************************************************************************/
  238. BOOL RDPCALL SHCLASS USRDetermineCaps(void)
  239. {
  240. BOOL CapsOK;
  241. DC_BEGIN_FN("USRDetermineCaps");
  242. CapsOK = TRUE;
  243. CPC_EnumerateCapabilities(TS_CAPSETTYPE_BITMAP, (UINT_PTR)&CapsOK,
  244. USREnumBitmapCaps);
  245. DC_END_FN();
  246. return CapsOK;
  247. }
  248. /****************************************************************************/
  249. /* FUNCTION: USREnumBitmapCaps */
  250. /* */
  251. /* Function passed to CPC_EnumerateCapabilities. It is called once for */
  252. /* each person in the share corresponding to the TS_CAPSETTYPE_BITMAP */
  253. /* capability structure. */
  254. /* */
  255. /* PARAMETERS: */
  256. /* */
  257. /* personID - ID of person with these capabilities. */
  258. /* */
  259. /* pCaps - pointer to capabilities structure for this person. This */
  260. /* pointer is only valid within the call to this function. */
  261. /****************************************************************************/
  262. void CALLBACK SHCLASS USREnumBitmapCaps(
  263. LOCALPERSONID personID,
  264. UINT_PTR UserData,
  265. PTS_CAPABILITYHEADER pCaps)
  266. {
  267. BOOL *pCapsOK = (BOOL *)UserData;
  268. PTS_BITMAP_CAPABILITYSET pBitmapCaps = (PTS_BITMAP_CAPABILITYSET)pCaps;
  269. DC_BEGIN_FN("USREnumBitmapCaps");
  270. if (pBitmapCaps->lengthCapability >= sizeof(TS_BITMAP_CAPABILITYSET)) {
  271. if (!pBitmapCaps->bitmapCompressionFlag) {
  272. TRC_ERR((TB,"PersonID %u: BitmapPDU compression flag not set",
  273. personID));
  274. *pCapsOK = FALSE;
  275. }
  276. // Check for multiple-rectangle-per-PDU support. All clients (4.0
  277. // release and above) should have this capability set.
  278. if (!pBitmapCaps->multipleRectangleSupport) {
  279. TRC_ERR((TB,"PersonID %u: BitmapPDU mult rect flag not set",
  280. personID));
  281. *pCapsOK = FALSE;
  282. }
  283. }
  284. else {
  285. TRC_ERR((TB,"PersonID %u: BitmapPDU caps too short", personID));
  286. *pCapsOK = FALSE;
  287. }
  288. DC_END_FN();
  289. }