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.

SMsgReader.cxx 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <stdio.h>
  19. #include <rdr/InStream.h>
  20. #include <rfb/Exception.h>
  21. #include <rfb/util.h>
  22. #include <rfb/SMsgHandler.h>
  23. #include <rfb/SMsgReader.h>
  24. #include <rfb/Configuration.h>
  25. #include <rfb/LogWriter.h>
  26. using namespace rfb;
  27. static LogWriter vlog("SMsgReader");
  28. static IntParameter maxCutText("MaxCutText", "Maximum permitted length of an incoming clipboard update", 256*1024);
  29. SMsgReader::SMsgReader(SMsgHandler* handler_, rdr::InStream* is_)
  30. : handler(handler_), is(is_)
  31. {
  32. }
  33. SMsgReader::~SMsgReader()
  34. {
  35. }
  36. void SMsgReader::readSetPixelFormat()
  37. {
  38. is->skip(3);
  39. PixelFormat pf;
  40. pf.read(is);
  41. handler->setPixelFormat(pf);
  42. }
  43. void SMsgReader::readSetEncodings()
  44. {
  45. is->skip(1);
  46. int nEncodings = is->readU16();
  47. rdr::S32Array encodings(nEncodings);
  48. for (int i = 0; i < nEncodings; i++)
  49. encodings.buf[i] = is->readU32();
  50. handler->setEncodings(nEncodings, encodings.buf);
  51. }
  52. void SMsgReader::readFramebufferUpdateRequest()
  53. {
  54. bool inc = is->readU8();
  55. int x = is->readU16();
  56. int y = is->readU16();
  57. int w = is->readU16();
  58. int h = is->readU16();
  59. handler->framebufferUpdateRequest(Rect(x, y, x+w, y+h), inc);
  60. }
  61. void SMsgReader::readKeyEvent()
  62. {
  63. bool down = is->readU8();
  64. is->skip(2);
  65. rdr::U32 key = is->readU32();
  66. handler->keyEvent(key, down);
  67. }
  68. void SMsgReader::readPointerEvent()
  69. {
  70. int mask = is->readU8();
  71. int x = is->readU16();
  72. int y = is->readU16();
  73. handler->pointerEvent(Point(x, y), mask);
  74. }
  75. void SMsgReader::readClientCutText()
  76. {
  77. is->skip(3);
  78. int len = is->readU32();
  79. if (len > maxCutText) {
  80. is->skip(len);
  81. vlog.error("Cut text too long (%d bytes) - ignoring", len);
  82. return;
  83. }
  84. CharArray ca(len+1);
  85. ca.buf[len] = 0;
  86. is->readBytes(ca.buf, len);
  87. handler->clientCutText(ca.buf, len);
  88. }