caps.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * Copyright (c) 2014-2015 Sylvain Peyrefitte
  3. *
  4. * This file is part of node-rdpjs.
  5. *
  6. * node-rdpjs is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. var type = require('../../core').type;
  20. var log = require('../../core').log;
  21. var error = require('../../core').error;
  22. /**
  23. * @see http://msdn.microsoft.com/en-us/library/cc240486.aspx
  24. */
  25. var CapsType = {
  26. CAPSTYPE_GENERAL : 0x0001,
  27. CAPSTYPE_BITMAP : 0x0002,
  28. CAPSTYPE_ORDER : 0x0003,
  29. CAPSTYPE_BITMAPCACHE : 0x0004,
  30. CAPSTYPE_CONTROL : 0x0005,
  31. CAPSTYPE_ACTIVATION : 0x0007,
  32. CAPSTYPE_POINTER : 0x0008,
  33. CAPSTYPE_SHARE : 0x0009,
  34. CAPSTYPE_COLORCACHE : 0x000A,
  35. CAPSTYPE_SOUND : 0x000C,
  36. CAPSTYPE_INPUT : 0x000D,
  37. CAPSTYPE_FONT : 0x000E,
  38. CAPSTYPE_BRUSH : 0x000F,
  39. CAPSTYPE_GLYPHCACHE : 0x0010,
  40. CAPSTYPE_OFFSCREENCACHE : 0x0011,
  41. CAPSTYPE_BITMAPCACHE_HOSTSUPPORT : 0x0012,
  42. CAPSTYPE_BITMAPCACHE_REV2 : 0x0013,
  43. CAPSTYPE_VIRTUALCHANNEL : 0x0014,
  44. CAPSTYPE_DRAWNINEGRIDCACHE : 0x0015,
  45. CAPSTYPE_DRAWGDIPLUS : 0x0016,
  46. CAPSTYPE_RAIL : 0x0017,
  47. CAPSTYPE_WINDOW : 0x0018,
  48. CAPSETTYPE_COMPDESK : 0x0019,
  49. CAPSETTYPE_MULTIFRAGMENTUPDATE : 0x001A,
  50. CAPSETTYPE_LARGE_POINTER : 0x001B,
  51. CAPSETTYPE_SURFACE_COMMANDS : 0x001C,
  52. CAPSETTYPE_BITMAP_CODECS : 0x001D,
  53. CAPSSETTYPE_FRAME_ACKNOWLEDGE : 0x001E
  54. };
  55. /**
  56. * @see http://msdn.microsoft.com/en-us/library/cc240549.aspx
  57. */
  58. var MajorType = {
  59. OSMAJORTYPE_UNSPECIFIED : 0x0000,
  60. OSMAJORTYPE_WINDOWS : 0x0001,
  61. OSMAJORTYPE_OS2 : 0x0002,
  62. OSMAJORTYPE_MACINTOSH : 0x0003,
  63. OSMAJORTYPE_UNIX : 0x0004,
  64. OSMAJORTYPE_IOS : 0x0005,
  65. OSMAJORTYPE_OSX : 0x0006,
  66. OSMAJORTYPE_ANDROID : 0x0007
  67. };
  68. /**
  69. * @see http://msdn.microsoft.com/en-us/library/cc240549.aspx
  70. */
  71. var MinorType = {
  72. OSMINORTYPE_UNSPECIFIED : 0x0000,
  73. OSMINORTYPE_WINDOWS_31X : 0x0001,
  74. OSMINORTYPE_WINDOWS_95 : 0x0002,
  75. OSMINORTYPE_WINDOWS_NT : 0x0003,
  76. OSMINORTYPE_OS2_V21 : 0x0004,
  77. OSMINORTYPE_POWER_PC : 0x0005,
  78. OSMINORTYPE_MACINTOSH : 0x0006,
  79. OSMINORTYPE_NATIVE_XSERVER : 0x0007,
  80. OSMINORTYPE_PSEUDO_XSERVER : 0x0008,
  81. OSMINORTYPE_WINDOWS_RT : 0x0009
  82. };
  83. /**
  84. * @see http://msdn.microsoft.com/en-us/library/cc240549.aspx
  85. */
  86. var GeneralExtraFlag = {
  87. FASTPATH_OUTPUT_SUPPORTED : 0x0001,
  88. NO_BITMAP_COMPRESSION_HDR : 0x0400,
  89. LONG_CREDENTIALS_SUPPORTED : 0x0004,
  90. AUTORECONNECT_SUPPORTED : 0x0008,
  91. ENC_SALTED_CHECKSUM : 0x0010
  92. };
  93. var Boolean = {
  94. FALSE : 0x00,
  95. TRUE : 0x01
  96. };
  97. /**
  98. * @see http://msdn.microsoft.com/en-us/library/cc240556.aspx
  99. */
  100. var OrderFlag = {
  101. NEGOTIATEORDERSUPPORT : 0x0002,
  102. ZEROBOUNDSDELTASSUPPORT : 0x0008,
  103. COLORINDEXSUPPORT : 0x0020,
  104. SOLIDPATTERNBRUSHONLY : 0x0040,
  105. ORDERFLAGS_EXTRA_FLAGS : 0x0080
  106. };
  107. /**
  108. * @see http://msdn.microsoft.com/en-us/library/cc240556.aspx
  109. */
  110. var Order = {
  111. TS_NEG_DSTBLT_INDEX : 0x00,
  112. TS_NEG_PATBLT_INDEX : 0x01,
  113. TS_NEG_SCRBLT_INDEX : 0x02,
  114. TS_NEG_MEMBLT_INDEX : 0x03,
  115. TS_NEG_MEM3BLT_INDEX : 0x04,
  116. TS_NEG_DRAWNINEGRID_INDEX : 0x07,
  117. TS_NEG_LINETO_INDEX : 0x08,
  118. TS_NEG_MULTI_DRAWNINEGRID_INDEX : 0x09,
  119. TS_NEG_SAVEBITMAP_INDEX : 0x0B,
  120. TS_NEG_MULTIDSTBLT_INDEX : 0x0F,
  121. TS_NEG_MULTIPATBLT_INDEX : 0x10,
  122. TS_NEG_MULTISCRBLT_INDEX : 0x11,
  123. TS_NEG_MULTIOPAQUERECT_INDEX : 0x12,
  124. TS_NEG_FAST_INDEX_INDEX : 0x13,
  125. TS_NEG_POLYGON_SC_INDEX : 0x14,
  126. TS_NEG_POLYGON_CB_INDEX : 0x15,
  127. TS_NEG_POLYLINE_INDEX : 0x16,
  128. TS_NEG_FAST_GLYPH_INDEX : 0x18,
  129. TS_NEG_ELLIPSE_SC_INDEX : 0x19,
  130. TS_NEG_ELLIPSE_CB_INDEX : 0x1A,
  131. TS_NEG_INDEX_INDEX : 0x1B
  132. };
  133. var OrderEx = {
  134. ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT : 0x0002,
  135. ORDERFLAGS_EX_ALTSEC_FRAME_MARKER_SUPPORT : 0x0004
  136. };
  137. /**
  138. * @see http://msdn.microsoft.com/en-us/library/cc240563.aspx
  139. */
  140. var InputFlags = {
  141. INPUT_FLAG_SCANCODES : 0x0001,
  142. INPUT_FLAG_MOUSEX : 0x0004,
  143. INPUT_FLAG_FASTPATH_INPUT : 0x0008,
  144. INPUT_FLAG_UNICODE : 0x0010,
  145. INPUT_FLAG_FASTPATH_INPUT2 : 0x0020,
  146. INPUT_FLAG_UNUSED1 : 0x0040,
  147. INPUT_FLAG_UNUSED2 : 0x0080,
  148. TS_INPUT_FLAG_MOUSE_HWHEEL : 0x0100
  149. };
  150. /**
  151. * @see http://msdn.microsoft.com/en-us/library/cc240564.aspx
  152. */
  153. var BrushSupport = {
  154. BRUSH_DEFAULT : 0x00000000,
  155. BRUSH_COLOR_8x8 : 0x00000001,
  156. BRUSH_COLOR_FULL : 0x00000002
  157. };
  158. /**
  159. * @see http://msdn.microsoft.com/en-us/library/cc240565.aspx
  160. */
  161. var GlyphSupport = {
  162. GLYPH_SUPPORT_NONE : 0x0000,
  163. GLYPH_SUPPORT_PARTIAL : 0x0001,
  164. GLYPH_SUPPORT_FULL : 0x0002,
  165. GLYPH_SUPPORT_ENCODE : 0x0003
  166. };
  167. /**
  168. * @see http://msdn.microsoft.com/en-us/library/cc240550.aspx
  169. */
  170. var OffscreenSupportLevel = {
  171. FALSE : 0x00000000,
  172. TRUE : 0x00000001
  173. };
  174. /**
  175. * @see http://msdn.microsoft.com/en-us/library/cc240551.aspx
  176. */
  177. var VirtualChannelCompressionFlag = {
  178. VCCAPS_NO_COMPR : 0x00000000,
  179. VCCAPS_COMPR_SC : 0x00000001,
  180. VCCAPS_COMPR_CS_8K : 0x00000002
  181. };
  182. /**
  183. * @see http://msdn.microsoft.com/en-us/library/cc240552.aspx
  184. */
  185. var SoundFlag = {
  186. NONE : 0x0000,
  187. SOUND_BEEPS_FLAG : 0x0001
  188. };
  189. /**
  190. * @see http://msdn.microsoft.com/en-us/library/cc240549.aspx
  191. * @param opt {object} type options
  192. * @returns {type.Component}
  193. */
  194. function generalCapability(opt) {
  195. var self = {
  196. __TYPE__ : CapsType.CAPSTYPE_GENERAL,
  197. osMajorType : new type.UInt16Le(),
  198. osMinorType : new type.UInt16Le(),
  199. protocolVersion : new type.UInt16Le(0x0200, {constant : true}),
  200. pad2octetsA : new type.UInt16Le(),
  201. generalCompressionTypes : new type.UInt16Le(0, {constant : true}),
  202. extraFlags : new type.UInt16Le(),
  203. updateCapabilityFlag : new type.UInt16Le(0, {constant : true}),
  204. remoteUnshareFlag : new type.UInt16Le(0, {constant : true}),
  205. generalCompressionLevel : new type.UInt16Le(0, {constant : true}),
  206. refreshRectSupport : new type.UInt8(),
  207. suppressOutputSupport : new type.UInt8()
  208. };
  209. return new type.Component(self, opt);
  210. }
  211. /**
  212. * @see http://msdn.microsoft.com/en-us/library/cc240554.aspx
  213. * @param opt {object} type options
  214. * @returns {type.Component}
  215. */
  216. function bitmapCapability(opt) {
  217. var self = {
  218. __TYPE__ : CapsType.CAPSTYPE_BITMAP,
  219. preferredBitsPerPixel : new type.UInt16Le(),
  220. receive1BitPerPixel : new type.UInt16Le(0x0001),
  221. receive4BitsPerPixel : new type.UInt16Le(0x0001),
  222. receive8BitsPerPixel : new type.UInt16Le(0x0001),
  223. desktopWidth : new type.UInt16Le(),
  224. desktopHeight : new type.UInt16Le(),
  225. pad2octets : new type.UInt16Le(),
  226. desktopResizeFlag : new type.UInt16Le(),
  227. bitmapCompressionFlag : new type.UInt16Le(0x0001, {constant : true}),
  228. highColorFlags : new type.UInt8(0),
  229. drawingFlags : new type.UInt8(),
  230. multipleRectangleSupport : new type.UInt16Le(0x0001, {constant : true}),
  231. pad2octetsB : new type.UInt16Le()
  232. };
  233. return new type.Component(self, opt);
  234. }
  235. /**
  236. * @see http://msdn.microsoft.com/en-us/library/cc240556.aspx
  237. * @param orders {type.BinaryString|null} list of available orders
  238. * @param opt {object} type options
  239. * @returns {type.Component}
  240. */
  241. function orderCapability(orders, opt) {
  242. if(orders && orders.size() !== 32) {
  243. throw new error.FatalError('NODE_RDP_PROTOCOL_PDU_CAPS_BAD_ORDERS_SIZE');
  244. }
  245. var self = {
  246. __TYPE__ : CapsType.CAPSTYPE_ORDER,
  247. terminalDescriptor : new type.BinaryString(Buffer.from(Array(16 + 1).join('\x00'), 'binary'), {readLength : new type.CallableValue(16)}),
  248. pad4octetsA : new type.UInt32Le(0),
  249. desktopSaveXGranularity : new type.UInt16Le(1),
  250. desktopSaveYGranularity : new type.UInt16Le(20),
  251. pad2octetsA : new type.UInt16Le(0),
  252. maximumOrderLevel : new type.UInt16Le(1),
  253. numberFonts : new type.UInt16Le(),
  254. orderFlags : new type.UInt16Le(OrderFlag.NEGOTIATEORDERSUPPORT),
  255. orderSupport : orders || new type.Factory(function(s) {
  256. self.orderSupport = new type.BinaryString(null, {readLength : new type.CallableValue(32)}).read(s);
  257. }),
  258. textFlags : new type.UInt16Le(),
  259. orderSupportExFlags : new type.UInt16Le(),
  260. pad4octetsB : new type.UInt32Le(),
  261. desktopSaveSize : new type.UInt32Le(480 * 480),
  262. pad2octetsC : new type.UInt16Le(),
  263. pad2octetsD : new type.UInt16Le(),
  264. textANSICodePage : new type.UInt16Le(0),
  265. pad2octetsE : new type.UInt16Le()
  266. };
  267. return new type.Component(self, opt);
  268. }
  269. /**
  270. * @see http://msdn.microsoft.com/en-us/library/cc240559.aspx
  271. * @param opt type options
  272. * @returns {type.Component}
  273. */
  274. function bitmapCacheCapability(opt) {
  275. var self = {
  276. __TYPE__ : CapsType.CAPSTYPE_BITMAPCACHE,
  277. pad1 : new type.UInt32Le(),
  278. pad2 : new type.UInt32Le(),
  279. pad3 : new type.UInt32Le(),
  280. pad4 : new type.UInt32Le(),
  281. pad5 : new type.UInt32Le(),
  282. pad6 : new type.UInt32Le(),
  283. cache0Entries : new type.UInt16Le(),
  284. cache0MaximumCellSize : new type.UInt16Le(),
  285. cache1Entries : new type.UInt16Le(),
  286. cache1MaximumCellSize : new type.UInt16Le(),
  287. cache2Entries : new type.UInt16Le(),
  288. cache2MaximumCellSize : new type.UInt16Le()
  289. };
  290. return new type.Component(self, opt);
  291. }
  292. /**
  293. *
  294. * @param isServer {boolean} true if in server mode
  295. * @param opt {object} type options
  296. * @returns {type.Component}
  297. */
  298. function pointerCapability(isServer, opt) {
  299. var self = {
  300. __TYPE__ : CapsType.CAPSTYPE_POINTER,
  301. colorPointerFlag : new type.UInt16Le(),
  302. colorPointerCacheSize : new type.UInt16Le(20),
  303. //old version of rdp doesn't support ...
  304. pointerCacheSize : new type.UInt16Le(null, {conditional : function() {
  305. return isServer || false;
  306. }})
  307. };
  308. return new type.Component(self, opt);
  309. }
  310. /**
  311. * @see http://msdn.microsoft.com/en-us/library/cc240563.aspx
  312. * @param opt {object} type options
  313. * @returns {type.Component}
  314. */
  315. function inputCapability(opt) {
  316. var self = {
  317. __TYPE__ : CapsType.CAPSTYPE_INPUT,
  318. inputFlags : new type.UInt16Le(),
  319. pad2octetsA : new type.UInt16Le(),
  320. // same value as gcc.ClientCoreSettings.kbdLayout
  321. keyboardLayout : new type.UInt32Le(),
  322. // same value as gcc.ClientCoreSettings.keyboardType
  323. keyboardType : new type.UInt32Le(),
  324. // same value as gcc.ClientCoreSettings.keyboardSubType
  325. keyboardSubType : new type.UInt32Le(),
  326. // same value as gcc.ClientCoreSettings.keyboardFnKeys
  327. keyboardFunctionKey : new type.UInt32Le(),
  328. // same value as gcc.ClientCoreSettingrrs.imeFileName
  329. imeFileName : new type.BinaryString(Buffer.from(Array(64 + 1).join('\x00'), 'binary'), {readLength : new type.CallableValue(64)})
  330. };
  331. return new type.Component(self, opt);
  332. }
  333. /**
  334. * @see http://msdn.microsoft.com/en-us/library/cc240564.aspx
  335. * @param opt {object} type options
  336. * @returns {type.Component}
  337. */
  338. function brushCapability(opt) {
  339. var self = {
  340. __TYPE__ : CapsType.CAPSTYPE_BRUSH,
  341. brushSupportLevel : new type.UInt32Le(BrushSupport.BRUSH_DEFAULT)
  342. };
  343. return new type.Component(self, opt);
  344. }
  345. /**
  346. * @see http://msdn.microsoft.com/en-us/library/cc240566.aspx
  347. * @param opt {object} type options
  348. * @returns {type.Component}
  349. */
  350. function cacheEntry(opt) {
  351. var self = {
  352. cacheEntries : new type.UInt16Le(),
  353. cacheMaximumCellSize : new type.UInt16Le()
  354. };
  355. return new type.Component(self, opt);
  356. }
  357. /**
  358. * @see http://msdn.microsoft.com/en-us/library/cc240565.aspx
  359. * @param entries {type.Component} cache entries
  360. * @param opt {object} type options
  361. * @returns {type.Component}
  362. */
  363. function glyphCapability(entries, opt) {
  364. var self = {
  365. __TYPE__ : CapsType.CAPSTYPE_GLYPHCACHE,
  366. glyphCache : entries || new type.Factory(function(s) {
  367. self.glyphCache = new type.Component([]);
  368. for(var i = 0; i < 10; i++) {
  369. self.glyphCache.obj.push(cacheEntry().read(s));
  370. }
  371. }),
  372. fragCache : new type.UInt32Le(),
  373. // all fonts are sent with bitmap format (very expensive)
  374. glyphSupportLevel : new type.UInt16Le(GlyphSupport.GLYPH_SUPPORT_NONE),
  375. pad2octets : new type.UInt16Le()
  376. };
  377. return new type.Component(self, opt);
  378. }
  379. /**
  380. * @see http://msdn.microsoft.com/en-us/library/cc240550.aspx
  381. * @param opt {object} type options
  382. * @returns {type.Component}
  383. */
  384. function offscreenBitmapCacheCapability(opt) {
  385. var self = {
  386. __TYPE__ : CapsType.CAPSTYPE_OFFSCREENCACHE,
  387. offscreenSupportLevel : new type.UInt32Le(OffscreenSupportLevel.FALSE),
  388. offscreenCacheSize : new type.UInt16Le(),
  389. offscreenCacheEntries : new type.UInt16Le()
  390. };
  391. return new type.Component(self, opt);
  392. }
  393. /**
  394. * @see http://msdn.microsoft.com/en-us/library/cc240551.aspx
  395. * @param opt {object} type options
  396. * @returns {type.Component}
  397. */
  398. function virtualChannelCapability(opt) {
  399. var self = {
  400. __TYPE__ : CapsType.CAPSTYPE_VIRTUALCHANNEL,
  401. flags : new type.UInt32Le(VirtualChannelCompressionFlag.VCCAPS_NO_COMPR),
  402. VCChunkSize : new type.UInt32Le(null, {optional : true})
  403. };
  404. return new type.Component(self, opt);
  405. }
  406. /**
  407. * @see http://msdn.microsoft.com/en-us/library/cc240552.aspx
  408. * @param opt {object} type options
  409. * @returns {type.Component}
  410. */
  411. function soundCapability(opt) {
  412. var self = {
  413. __TYPE__ : CapsType.CAPSTYPE_SOUND,
  414. soundFlags : new type.UInt16Le(SoundFlag.NONE),
  415. pad2octetsA : new type.UInt16Le()
  416. };
  417. return new type.Component(self, opt);
  418. }
  419. /**
  420. * @see http://msdn.microsoft.com/en-us/library/cc240568.aspx
  421. * @param opt {object} type options
  422. * @returns {type.Component}
  423. */
  424. function controlCapability(opt) {
  425. var self = {
  426. __TYPE__ : CapsType.CAPSTYPE_CONTROL,
  427. controlFlags : new type.UInt16Le(),
  428. remoteDetachFlag : new type.UInt16Le(),
  429. controlInterest : new type.UInt16Le(0x0002),
  430. detachInterest : new type.UInt16Le(0x0002)
  431. };
  432. return new type.Component(self, opt);
  433. }
  434. /**
  435. * @see http://msdn.microsoft.com/en-us/library/cc240569.aspx
  436. * @param opt {object} type options
  437. * @returns {type.Component}
  438. */
  439. function windowActivationCapability(opt) {
  440. var self = {
  441. __TYPE__ : CapsType.CAPSTYPE_ACTIVATION,
  442. helpKeyFlag : new type.UInt16Le(),
  443. helpKeyIndexFlag : new type.UInt16Le(),
  444. helpExtendedKeyFlag : new type.UInt16Le(),
  445. windowManagerKeyFlag : new type.UInt16Le()
  446. };
  447. return new type.Component(self, opt);
  448. }
  449. /**
  450. * @see http://msdn.microsoft.com/en-us/library/cc240571.aspx
  451. * @param opt {object} type options
  452. * @returns {type.Component}
  453. */
  454. function fontCapability(opt) {
  455. var self = {
  456. __TYPE__ : CapsType.CAPSTYPE_FONT,
  457. fontSupportFlags : new type.UInt16Le(0x0001),
  458. pad2octets : new type.UInt16Le()
  459. };
  460. return new type.Component(self, opt);
  461. }
  462. /**
  463. * @see http://msdn.microsoft.com/en-us/library/cc241564.aspx
  464. * @param opt {object} type options
  465. * @returns {type.Component}
  466. */
  467. function colorCacheCapability(opt) {
  468. var self = {
  469. __TYPE__ : CapsType.CAPSTYPE_COLORCACHE,
  470. colorTableCacheSize : new type.UInt16Le(0x0006),
  471. pad2octets : new type.UInt16Le()
  472. };
  473. return new type.Component(self, opt);
  474. }
  475. /**
  476. * @see http://msdn.microsoft.com/en-us/library/cc240570.aspx
  477. * @param opt {object} type options
  478. * @returns {type.Component}
  479. */
  480. function shareCapability(opt) {
  481. var self = {
  482. __TYPE__ : CapsType.CAPSTYPE_SHARE,
  483. nodeId : new type.UInt16Le(),
  484. pad2octets : new type.UInt16Le()
  485. };
  486. return new type.Component(self, opt);
  487. }
  488. /**
  489. * @see http://msdn.microsoft.com/en-us/library/cc240649.aspx
  490. * @param opt {object} type options
  491. * @returns {type.Component}
  492. */
  493. function multiFragmentUpdate(opt) {
  494. var self = {
  495. __TYPE__ : CapsType.CAPSETTYPE_MULTIFRAGMENTUPDATE,
  496. MaxRequestSize : new type.UInt32Le(0)
  497. };
  498. return new type.Component(self, opt);
  499. }
  500. /**
  501. * Capability wrapper packet
  502. * @see http://msdn.microsoft.com/en-us/library/cc240486.aspx
  503. * @param cap {type.Component}
  504. * @param opt {object} type options
  505. * @returns {type.Component}
  506. */
  507. function capability(cap, opt) {
  508. var self = {
  509. capabilitySetType : new type.UInt16Le(function() {
  510. return self.capability.obj.__TYPE__;
  511. }),
  512. lengthCapability : new type.UInt16Le(function() {
  513. return new type.Component(self).size();
  514. }),
  515. capability : cap || new type.Factory(function(s) {
  516. switch(self.capabilitySetType.value) {
  517. case CapsType.CAPSTYPE_GENERAL:
  518. self.capability = generalCapability({readLength : new type.CallableValue(function() {
  519. return self.lengthCapability.value - 4;
  520. })}).read(s);
  521. break;
  522. case CapsType.CAPSTYPE_BITMAP:
  523. self.capability = bitmapCapability({readLength : new type.CallableValue(function() {
  524. return self.lengthCapability.value - 4;
  525. })}).read(s);
  526. break;
  527. case CapsType.CAPSTYPE_ORDER:
  528. self.capability = orderCapability(null, {readLength : new type.CallableValue(function() {
  529. return self.lengthCapability.value - 4;
  530. })}).read(s);
  531. break;
  532. case CapsType.CAPSTYPE_BITMAPCACHE:
  533. self.capability = bitmapCacheCapability({readLength : new type.CallableValue(function() {
  534. return self.lengthCapability.value - 4;
  535. })}).read(s);
  536. break;
  537. case CapsType.CAPSTYPE_POINTER:
  538. self.capability = pointerCapability(false, {readLength : new type.CallableValue(function() {
  539. return self.lengthCapability.value - 4;
  540. })}).read(s);
  541. break;
  542. case CapsType.CAPSTYPE_INPUT:
  543. self.capability = inputCapability({readLength : new type.CallableValue(function() {
  544. return self.lengthCapability.value - 4;
  545. })}).read(s);
  546. break;
  547. case CapsType.CAPSTYPE_BRUSH:
  548. self.capability = brushCapability({readLength : new type.CallableValue(function() {
  549. return self.lengthCapability.value - 4;
  550. })}).read(s);
  551. break;
  552. case CapsType.CAPSTYPE_GLYPHCACHE:
  553. self.capability = glyphCapability(null, {readLength : new type.CallableValue(function() {
  554. return self.lengthCapability.value - 4;
  555. })}).read(s);
  556. break;
  557. case CapsType.CAPSTYPE_OFFSCREENCACHE:
  558. self.capability = offscreenBitmapCacheCapability({readLength : new type.CallableValue(function() {
  559. return self.lengthCapability.value - 4;
  560. })}).read(s);
  561. break;
  562. case CapsType.CAPSTYPE_VIRTUALCHANNEL:
  563. self.capability = virtualChannelCapability({readLength : new type.CallableValue(function() {
  564. return self.lengthCapability.value - 4;
  565. })}).read(s);
  566. break;
  567. case CapsType.CAPSTYPE_SOUND:
  568. self.capability = soundCapability({readLength : new type.CallableValue(function() {
  569. return self.lengthCapability.value - 4;
  570. })}).read(s);
  571. break;
  572. case CapsType.CAPSTYPE_CONTROL:
  573. self.capability = controlCapability({readLength : new type.CallableValue(function() {
  574. return self.lengthCapability.value - 4;
  575. })}).read(s);
  576. break;
  577. case CapsType.CAPSTYPE_ACTIVATION:
  578. self.capability = windowActivationCapability({readLength : new type.CallableValue(function() {
  579. return self.lengthCapability.value - 4;
  580. })}).read(s);
  581. break;
  582. case CapsType.CAPSTYPE_FONT:
  583. self.capability = fontCapability({readLength : new type.CallableValue(function() {
  584. return self.lengthCapability.value - 4;
  585. })}).read(s);
  586. break;
  587. case CapsType.CAPSTYPE_COLORCACHE:
  588. self.capability = colorCacheCapability({readLength : new type.CallableValue(function() {
  589. return self.lengthCapability.value - 4;
  590. })}).read(s);
  591. break;
  592. case CapsType.CAPSTYPE_SHARE:
  593. self.capability = shareCapability({readLength : new type.CallableValue(function() {
  594. return self.lengthCapability.value - 4;
  595. })}).read(s);
  596. break;
  597. case CapsType.CAPSETTYPE_MULTIFRAGMENTUPDATE:
  598. self.capability = multiFragmentUpdate({readLength : new type.CallableValue(function() {
  599. return self.lengthCapability.value - 4;
  600. })}).read(s);
  601. break;
  602. default:
  603. log.debug('unknown capability ' + self.capabilitySetType.value);
  604. self.capability = new type.BinaryString(null, {readLength : new type.CallableValue(function() {
  605. return self.lengthCapability.value - 4;
  606. })}).read(s);
  607. }
  608. })
  609. };
  610. return new type.Component(self, opt);
  611. }
  612. /**
  613. * Module exports
  614. */
  615. module.exports = {
  616. CapsType : CapsType,
  617. MajorType : MajorType,
  618. MinorType : MinorType,
  619. GeneralExtraFlag : GeneralExtraFlag,
  620. Boolean : Boolean,
  621. OrderFlag : OrderFlag,
  622. Order : Order,
  623. OrderEx : OrderEx,
  624. InputFlags : InputFlags,
  625. BrushSupport : BrushSupport,
  626. GlyphSupport : GlyphSupport,
  627. OffscreenSupportLevel : OffscreenSupportLevel,
  628. VirtualChannelCompressionFlag : VirtualChannelCompressionFlag,
  629. SoundFlag : SoundFlag,
  630. generalCapability : generalCapability,
  631. bitmapCapability : bitmapCapability,
  632. orderCapability : orderCapability,
  633. bitmapCacheCapability : bitmapCacheCapability,
  634. pointerCapability : pointerCapability,
  635. inputCapability : inputCapability,
  636. brushCapability : brushCapability,
  637. cacheEntry : cacheEntry,
  638. glyphCapability : glyphCapability,
  639. offscreenBitmapCacheCapability : offscreenBitmapCacheCapability,
  640. virtualChannelCapability : virtualChannelCapability,
  641. soundCapability : soundCapability,
  642. controlCapability : controlCapability,
  643. windowActivationCapability : windowActivationCapability,
  644. fontCapability : fontCapability,
  645. colorCacheCapability : colorCacheCapability,
  646. shareCapability : shareCapability,
  647. multiFragmentUpdate : multiFragmentUpdate,
  648. capability : capability
  649. };