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.

CMsgReader.cxx 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009-2019 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include <assert.h>
  23. #include <stdio.h>
  24. #include <vector>
  25. #include <rdr/InStream.h>
  26. #include <rdr/ZlibInStream.h>
  27. #include <rfb/msgTypes.h>
  28. #include <rfb/clipboardTypes.h>
  29. #include <rfb/Exception.h>
  30. #include <rfb/LogWriter.h>
  31. #include <rfb/util.h>
  32. #include <rfb/CMsgHandler.h>
  33. #include <rfb/CMsgReader.h>
  34. static rfb::LogWriter vlog("CMsgReader");
  35. static rfb::IntParameter maxCutText("MaxCutText", "Maximum permitted length of an incoming clipboard update", 256*1024);
  36. using namespace rfb;
  37. CMsgReader::CMsgReader(CMsgHandler* handler_, rdr::InStream* is_)
  38. : imageBufIdealSize(0), handler(handler_), is(is_),
  39. state(MSGSTATE_IDLE), cursorEncoding(-1)
  40. {
  41. }
  42. CMsgReader::~CMsgReader()
  43. {
  44. }
  45. bool CMsgReader::readServerInit()
  46. {
  47. int width, height;
  48. uint32_t len;
  49. if (!is->hasData(2 + 2 + 16 + 4))
  50. return false;
  51. is->setRestorePoint();
  52. width = is->readU16();
  53. height = is->readU16();
  54. PixelFormat pf;
  55. pf.read(is);
  56. len = is->readU32();
  57. if (!is->hasDataOrRestore(len))
  58. return false;
  59. is->clearRestorePoint();
  60. CharArray name(len + 1);
  61. is->readBytes(name.buf, len);
  62. name.buf[len] = '\0';
  63. handler->serverInit(width, height, pf, name.buf);
  64. return true;
  65. }
  66. bool CMsgReader::readMsg()
  67. {
  68. if (state == MSGSTATE_IDLE) {
  69. if (!is->hasData(1))
  70. return false;
  71. currentMsgType = is->readU8();
  72. state = MSGSTATE_MESSAGE;
  73. }
  74. if (currentMsgType != msgTypeFramebufferUpdate) {
  75. bool ret;
  76. switch (currentMsgType) {
  77. case msgTypeSetColourMapEntries:
  78. ret = readSetColourMapEntries();
  79. break;
  80. case msgTypeBell:
  81. ret = readBell();
  82. break;
  83. case msgTypeServerCutText:
  84. ret = readServerCutText();
  85. break;
  86. case msgTypeFramebufferUpdate:
  87. ret = readFramebufferUpdate();
  88. break;
  89. case msgTypeServerFence:
  90. ret = readFence();
  91. break;
  92. case msgTypeEndOfContinuousUpdates:
  93. ret = readEndOfContinuousUpdates();
  94. break;
  95. default:
  96. throw Exception("Unknown message type %d", currentMsgType);
  97. }
  98. if (ret)
  99. state = MSGSTATE_IDLE;
  100. return ret;
  101. } else {
  102. if (state == MSGSTATE_MESSAGE) {
  103. if (!readFramebufferUpdate())
  104. return false;
  105. // Empty update?
  106. if (nUpdateRectsLeft == 0) {
  107. state = MSGSTATE_IDLE;
  108. handler->framebufferUpdateEnd();
  109. return true;
  110. }
  111. state = MSGSTATE_RECT_HEADER;
  112. }
  113. if (state == MSGSTATE_RECT_HEADER) {
  114. if (!is->hasData(2 + 2 + 2 + 2 + 4))
  115. return false;
  116. int x = is->readU16();
  117. int y = is->readU16();
  118. int w = is->readU16();
  119. int h = is->readU16();
  120. dataRect.setXYWH(x, y, w, h);
  121. rectEncoding = is->readS32();
  122. state = MSGSTATE_RECT_DATA;
  123. }
  124. bool ret;
  125. switch (rectEncoding) {
  126. case pseudoEncodingLastRect:
  127. nUpdateRectsLeft = 1; // this rectangle is the last one
  128. ret = true;
  129. break;
  130. case pseudoEncodingXCursor:
  131. ret = readSetXCursor(dataRect.width(), dataRect.height(), dataRect.tl);
  132. break;
  133. case pseudoEncodingCursor:
  134. ret = readSetCursor(dataRect.width(), dataRect.height(), dataRect.tl);
  135. break;
  136. case pseudoEncodingCursorWithAlpha:
  137. ret = readSetCursorWithAlpha(dataRect.width(), dataRect.height(), dataRect.tl);
  138. break;
  139. case pseudoEncodingVMwareCursor:
  140. ret = readSetVMwareCursor(dataRect.width(), dataRect.height(), dataRect.tl);
  141. break;
  142. case pseudoEncodingVMwareCursorPosition:
  143. handler->setCursorPos(dataRect.tl);
  144. ret = true;
  145. break;
  146. case pseudoEncodingDesktopName:
  147. ret = readSetDesktopName(dataRect.tl.x, dataRect.tl.y,
  148. dataRect.width(), dataRect.height());
  149. break;
  150. case pseudoEncodingDesktopSize:
  151. handler->setDesktopSize(dataRect.width(), dataRect.height());
  152. ret = true;
  153. break;
  154. case pseudoEncodingExtendedDesktopSize:
  155. ret = readExtendedDesktopSize(dataRect.tl.x, dataRect.tl.y,
  156. dataRect.width(), dataRect.height());
  157. break;
  158. case pseudoEncodingLEDState:
  159. ret = readLEDState();
  160. break;
  161. case pseudoEncodingVMwareLEDState:
  162. ret = readVMwareLEDState();
  163. break;
  164. case pseudoEncodingQEMUKeyEvent:
  165. handler->supportsQEMUKeyEvent();
  166. ret = true;
  167. break;
  168. default:
  169. ret = readRect(dataRect, rectEncoding);
  170. break;
  171. };
  172. if (ret) {
  173. state = MSGSTATE_RECT_HEADER;
  174. nUpdateRectsLeft--;
  175. if (nUpdateRectsLeft == 0) {
  176. state = MSGSTATE_IDLE;
  177. handler->framebufferUpdateEnd();
  178. }
  179. }
  180. return ret;
  181. }
  182. }
  183. bool CMsgReader::readSetColourMapEntries()
  184. {
  185. if (!is->hasData(1 + 2 + 2))
  186. return false;
  187. is->setRestorePoint();
  188. is->skip(1);
  189. int firstColour = is->readU16();
  190. int nColours = is->readU16();
  191. if (!is->hasDataOrRestore(nColours * 3 * 2))
  192. return false;
  193. is->clearRestorePoint();
  194. std::vector<uint16_t> rgbs(nColours * 3);
  195. for (size_t i = 0; i < rgbs.size(); i++)
  196. rgbs[i] = is->readU16();
  197. handler->setColourMapEntries(firstColour, nColours, rgbs.data());
  198. return true;
  199. }
  200. bool CMsgReader::readBell()
  201. {
  202. handler->bell();
  203. return true;
  204. }
  205. bool CMsgReader::readServerCutText()
  206. {
  207. if (!is->hasData(3 + 4))
  208. return false;
  209. is->setRestorePoint();
  210. is->skip(3);
  211. uint32_t len = is->readU32();
  212. if (len & 0x80000000) {
  213. int32_t slen = len;
  214. slen = -slen;
  215. if (readExtendedClipboard(slen)) {
  216. is->clearRestorePoint();
  217. return true;
  218. } else {
  219. is->gotoRestorePoint();
  220. return false;
  221. }
  222. }
  223. if (!is->hasDataOrRestore(len))
  224. return false;
  225. is->clearRestorePoint();
  226. if (len > (size_t)maxCutText) {
  227. is->skip(len);
  228. vlog.error("cut text too long (%d bytes) - ignoring",len);
  229. return true;
  230. }
  231. CharArray ca(len);
  232. is->readBytes(ca.buf, len);
  233. std::string filtered(convertLF(ca.buf, len));
  234. handler->serverCutText(filtered.c_str());
  235. return true;
  236. }
  237. bool CMsgReader::readExtendedClipboard(int32_t len)
  238. {
  239. uint32_t flags;
  240. uint32_t action;
  241. if (!is->hasData(len))
  242. return false;
  243. if (len < 4)
  244. throw Exception("Invalid extended clipboard message");
  245. if (len > maxCutText) {
  246. vlog.error("Extended clipboard message too long (%d bytes) - ignoring", len);
  247. is->skip(len);
  248. return true;
  249. }
  250. flags = is->readU32();
  251. action = flags & clipboardActionMask;
  252. if (action & clipboardCaps) {
  253. int i;
  254. size_t num;
  255. uint32_t lengths[16];
  256. num = 0;
  257. for (i = 0;i < 16;i++) {
  258. if (flags & (1 << i))
  259. num++;
  260. }
  261. if (len < (int32_t)(4 + 4*num))
  262. throw Exception("Invalid extended clipboard message");
  263. num = 0;
  264. for (i = 0;i < 16;i++) {
  265. if (flags & (1 << i))
  266. lengths[num++] = is->readU32();
  267. }
  268. handler->handleClipboardCaps(flags, lengths);
  269. } else if (action == clipboardProvide) {
  270. rdr::ZlibInStream zis;
  271. int i;
  272. size_t num;
  273. size_t lengths[16];
  274. uint8_t* buffers[16];
  275. zis.setUnderlying(is, len - 4);
  276. num = 0;
  277. for (i = 0;i < 16;i++) {
  278. if (!(flags & 1 << i))
  279. continue;
  280. if (!zis.hasData(4))
  281. throw Exception("Extended clipboard decode error");
  282. lengths[num] = zis.readU32();
  283. if (lengths[num] > (size_t)maxCutText) {
  284. vlog.error("Extended clipboard data too long (%d bytes) - ignoring",
  285. (unsigned)lengths[num]);
  286. // Slowly (safely) drain away the data
  287. while (lengths[num] > 0) {
  288. size_t chunk;
  289. if (!zis.hasData(1))
  290. throw Exception("Extended clipboard decode error");
  291. chunk = zis.avail();
  292. if (chunk > lengths[num])
  293. chunk = lengths[num];
  294. zis.skip(chunk);
  295. lengths[num] -= chunk;
  296. }
  297. flags &= ~(1 << i);
  298. continue;
  299. }
  300. if (!zis.hasData(lengths[num]))
  301. throw Exception("Extended clipboard decode error");
  302. buffers[num] = new uint8_t[lengths[num]];
  303. zis.readBytes(buffers[num], lengths[num]);
  304. num++;
  305. }
  306. zis.flushUnderlying();
  307. zis.setUnderlying(NULL, 0);
  308. handler->handleClipboardProvide(flags, lengths, buffers);
  309. num = 0;
  310. for (i = 0;i < 16;i++) {
  311. if (!(flags & 1 << i))
  312. continue;
  313. delete [] buffers[num++];
  314. }
  315. } else {
  316. switch (action) {
  317. case clipboardRequest:
  318. handler->handleClipboardRequest(flags);
  319. break;
  320. case clipboardPeek:
  321. handler->handleClipboardPeek();
  322. break;
  323. case clipboardNotify:
  324. handler->handleClipboardNotify(flags);
  325. break;
  326. default:
  327. throw Exception("Invalid extended clipboard action");
  328. }
  329. }
  330. return true;
  331. }
  332. bool CMsgReader::readFence()
  333. {
  334. uint32_t flags;
  335. uint8_t len;
  336. char data[64];
  337. if (!is->hasData(3 + 4 + 1))
  338. return false;
  339. is->setRestorePoint();
  340. is->skip(3);
  341. flags = is->readU32();
  342. len = is->readU8();
  343. if (!is->hasDataOrRestore(len))
  344. return false;
  345. is->clearRestorePoint();
  346. if (len > sizeof(data)) {
  347. vlog.error("Ignoring fence with too large payload");
  348. is->skip(len);
  349. return true;
  350. }
  351. is->readBytes(data, len);
  352. handler->fence(flags, len, data);
  353. return true;
  354. }
  355. bool CMsgReader::readEndOfContinuousUpdates()
  356. {
  357. handler->endOfContinuousUpdates();
  358. return true;
  359. }
  360. bool CMsgReader::readFramebufferUpdate()
  361. {
  362. if (!is->hasData(1 + 2))
  363. return false;
  364. is->skip(1);
  365. nUpdateRectsLeft = is->readU16();
  366. handler->framebufferUpdateStart();
  367. return true;
  368. }
  369. bool CMsgReader::readRect(const Rect& r, int encoding)
  370. {
  371. if ((r.br.x > handler->server.width()) ||
  372. (r.br.y > handler->server.height())) {
  373. vlog.error("Rect too big: %dx%d at %d,%d exceeds %dx%d",
  374. r.width(), r.height(), r.tl.x, r.tl.y,
  375. handler->server.width(), handler->server.height());
  376. throw Exception("Rect too big");
  377. }
  378. if (r.is_empty())
  379. vlog.error("zero size rect");
  380. return handler->dataRect(r, encoding);
  381. }
  382. bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot)
  383. {
  384. if (width > maxCursorSize || height > maxCursorSize)
  385. throw Exception("Too big cursor");
  386. std::vector<uint8_t> rgba(width*height*4);
  387. if (width * height > 0) {
  388. uint8_t pr, pg, pb;
  389. uint8_t sr, sg, sb;
  390. int data_len = ((width+7)/8) * height;
  391. int mask_len = ((width+7)/8) * height;
  392. std::vector<uint8_t> data(data_len);
  393. std::vector<uint8_t> mask(mask_len);
  394. int x, y;
  395. uint8_t* out;
  396. if (!is->hasData(3 + 3 + data_len + mask_len))
  397. return false;
  398. pr = is->readU8();
  399. pg = is->readU8();
  400. pb = is->readU8();
  401. sr = is->readU8();
  402. sg = is->readU8();
  403. sb = is->readU8();
  404. is->readBytes(data.data(), data.size());
  405. is->readBytes(mask.data(), mask.size());
  406. int maskBytesPerRow = (width+7)/8;
  407. out = rgba.data();
  408. for (y = 0;y < height;y++) {
  409. for (x = 0;x < width;x++) {
  410. int byte = y * maskBytesPerRow + x / 8;
  411. int bit = 7 - x % 8;
  412. if (data[byte] & (1 << bit)) {
  413. out[0] = pr;
  414. out[1] = pg;
  415. out[2] = pb;
  416. } else {
  417. out[0] = sr;
  418. out[1] = sg;
  419. out[2] = sb;
  420. }
  421. if (mask[byte] & (1 << bit))
  422. out[3] = 255;
  423. else
  424. out[3] = 0;
  425. out += 4;
  426. }
  427. }
  428. }
  429. handler->setCursor(width, height, hotspot, rgba.data());
  430. return true;
  431. }
  432. bool CMsgReader::readSetCursor(int width, int height, const Point& hotspot)
  433. {
  434. if (width > maxCursorSize || height > maxCursorSize)
  435. throw Exception("Too big cursor");
  436. int data_len = width * height * (handler->server.pf().bpp/8);
  437. int mask_len = ((width+7)/8) * height;
  438. std::vector<uint8_t> data(data_len);
  439. std::vector<uint8_t> mask(mask_len);
  440. int x, y;
  441. std::vector<uint8_t> rgba(width*height*4);
  442. uint8_t* in;
  443. uint8_t* out;
  444. if (!is->hasData(data_len + mask_len))
  445. return false;
  446. is->readBytes(data.data(), data.size());
  447. is->readBytes(mask.data(), mask.size());
  448. int maskBytesPerRow = (width+7)/8;
  449. in = data.data();
  450. out = rgba.data();
  451. for (y = 0;y < height;y++) {
  452. for (x = 0;x < width;x++) {
  453. int byte = y * maskBytesPerRow + x / 8;
  454. int bit = 7 - x % 8;
  455. handler->server.pf().rgbFromBuffer(out, in, 1);
  456. if (mask[byte] & (1 << bit))
  457. out[3] = 255;
  458. else
  459. out[3] = 0;
  460. in += handler->server.pf().bpp/8;
  461. out += 4;
  462. }
  463. }
  464. handler->setCursor(width, height, hotspot, rgba.data());
  465. return true;
  466. }
  467. bool CMsgReader::readSetCursorWithAlpha(int width, int height, const Point& hotspot)
  468. {
  469. if (width > maxCursorSize || height > maxCursorSize)
  470. throw Exception("Too big cursor");
  471. const PixelFormat rgbaPF(32, 32, false, true, 255, 255, 255, 16, 8, 0);
  472. ManagedPixelBuffer pb(rgbaPF, width, height);
  473. PixelFormat origPF;
  474. bool ret;
  475. uint8_t* buf;
  476. int stride;
  477. // We can't use restore points as the decoder likely wants to as well, so
  478. // we need to keep track of the read encoding
  479. if (cursorEncoding == -1) {
  480. if (!is->hasData(4))
  481. return false;
  482. cursorEncoding = is->readS32();
  483. }
  484. origPF = handler->server.pf();
  485. handler->server.setPF(rgbaPF);
  486. ret = handler->readAndDecodeRect(pb.getRect(), cursorEncoding, &pb);
  487. handler->server.setPF(origPF);
  488. if (!ret)
  489. return false;
  490. cursorEncoding = -1;
  491. // On-wire data has pre-multiplied alpha, but we store it
  492. // non-pre-multiplied
  493. buf = pb.getBufferRW(pb.getRect(), &stride);
  494. assert(stride == width);
  495. for (int i = 0;i < pb.area();i++) {
  496. uint8_t alpha;
  497. alpha = buf[3];
  498. if (alpha == 0)
  499. alpha = 1; // Avoid division by zero
  500. buf[0] = (unsigned)buf[0] * 255/alpha;
  501. buf[1] = (unsigned)buf[1] * 255/alpha;
  502. buf[2] = (unsigned)buf[2] * 255/alpha;
  503. buf += 4;
  504. }
  505. pb.commitBufferRW(pb.getRect());
  506. handler->setCursor(width, height, hotspot,
  507. pb.getBuffer(pb.getRect(), &stride));
  508. return true;
  509. }
  510. bool CMsgReader::readSetVMwareCursor(int width, int height, const Point& hotspot)
  511. {
  512. if (width > maxCursorSize || height > maxCursorSize)
  513. throw Exception("Too big cursor");
  514. uint8_t type;
  515. if (!is->hasData(1 + 1))
  516. return false;
  517. is->setRestorePoint();
  518. type = is->readU8();
  519. is->skip(1);
  520. if (type == 0) {
  521. int len = width * height * (handler->server.pf().bpp/8);
  522. std::vector<uint8_t> andMask(len);
  523. std::vector<uint8_t> xorMask(len);
  524. std::vector<uint8_t> data(width*height*4);
  525. uint8_t* andIn;
  526. uint8_t* xorIn;
  527. uint8_t* out;
  528. int Bpp;
  529. if (!is->hasDataOrRestore(len + len))
  530. return false;
  531. is->clearRestorePoint();
  532. is->readBytes(andMask.data(), andMask.size());
  533. is->readBytes(xorMask.data(), xorMask.size());
  534. andIn = andMask.data();
  535. xorIn = xorMask.data();
  536. out = data.data();
  537. Bpp = handler->server.pf().bpp/8;
  538. for (int y = 0;y < height;y++) {
  539. for (int x = 0;x < width;x++) {
  540. Pixel andPixel, xorPixel;
  541. andPixel = handler->server.pf().pixelFromBuffer(andIn);
  542. xorPixel = handler->server.pf().pixelFromBuffer(xorIn);
  543. andIn += Bpp;
  544. xorIn += Bpp;
  545. if (andPixel == 0) {
  546. uint8_t r, g, b;
  547. // Opaque pixel
  548. handler->server.pf().rgbFromPixel(xorPixel, &r, &g, &b);
  549. *out++ = r;
  550. *out++ = g;
  551. *out++ = b;
  552. *out++ = 0xff;
  553. } else if (xorPixel == 0) {
  554. // Fully transparent pixel
  555. *out++ = 0;
  556. *out++ = 0;
  557. *out++ = 0;
  558. *out++ = 0;
  559. } else if (andPixel == xorPixel) {
  560. // Inverted pixel
  561. // We don't really support this, so just turn the pixel black
  562. // FIXME: Do an outline like WinVNC does?
  563. *out++ = 0;
  564. *out++ = 0;
  565. *out++ = 0;
  566. *out++ = 0xff;
  567. } else {
  568. // Partially transparent/inverted pixel
  569. // We _really_ can't handle this, just make it black
  570. *out++ = 0;
  571. *out++ = 0;
  572. *out++ = 0;
  573. *out++ = 0xff;
  574. }
  575. }
  576. }
  577. handler->setCursor(width, height, hotspot, data.data());
  578. } else if (type == 1) {
  579. std::vector<uint8_t> data(width*height*4);
  580. if (!is->hasDataOrRestore(width*height*4))
  581. return false;
  582. is->clearRestorePoint();
  583. // FIXME: Is alpha premultiplied?
  584. is->readBytes(data.data(), data.size());
  585. handler->setCursor(width, height, hotspot, data.data());
  586. } else {
  587. throw Exception("Unknown cursor type");
  588. }
  589. return true;
  590. }
  591. bool CMsgReader::readSetDesktopName(int x, int y, int w, int h)
  592. {
  593. uint32_t len;
  594. if (!is->hasData(4))
  595. return false;
  596. is->setRestorePoint();
  597. len = is->readU32();
  598. if (!is->hasDataOrRestore(len))
  599. return false;
  600. is->clearRestorePoint();
  601. CharArray name(len + 1);
  602. is->readBytes(name.buf, len);
  603. name.buf[len] = '\0';
  604. if (x || y || w || h) {
  605. vlog.error("Ignoring DesktopName rect with non-zero position/size");
  606. } else {
  607. handler->setName(name.buf);
  608. }
  609. return true;
  610. }
  611. bool CMsgReader::readExtendedDesktopSize(int x, int y, int w, int h)
  612. {
  613. unsigned int screens, i;
  614. uint32_t id, flags;
  615. int sx, sy, sw, sh;
  616. ScreenSet layout;
  617. if (!is->hasData(1 + 3))
  618. return false;
  619. is->setRestorePoint();
  620. screens = is->readU8();
  621. is->skip(3);
  622. if (!is->hasDataOrRestore(16 * screens))
  623. return false;
  624. is->clearRestorePoint();
  625. for (i = 0;i < screens;i++) {
  626. id = is->readU32();
  627. sx = is->readU16();
  628. sy = is->readU16();
  629. sw = is->readU16();
  630. sh = is->readU16();
  631. flags = is->readU32();
  632. layout.add_screen(Screen(id, sx, sy, sw, sh, flags));
  633. }
  634. handler->setExtendedDesktopSize(x, y, w, h, layout);
  635. return true;
  636. }
  637. bool CMsgReader::readLEDState()
  638. {
  639. uint8_t state;
  640. if (!is->hasData(1))
  641. return false;
  642. state = is->readU8();
  643. handler->setLEDState(state);
  644. return true;
  645. }
  646. bool CMsgReader::readVMwareLEDState()
  647. {
  648. uint32_t state;
  649. if (!is->hasData(4))
  650. return false;
  651. state = is->readU32();
  652. // As luck has it, this extension uses the same bit definitions,
  653. // so no conversion required
  654. handler->setLEDState(state);
  655. return true;
  656. }