Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 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 | |
| 26 | using namespace rfb; |
| 27 | |
| 28 | static IntParameter maxCutText("MaxCutText", "Maximum permitted length of an incoming clipboard update", 256*1024); |
| 29 | |
| 30 | SMsgReader::SMsgReader(SMsgHandler* handler_, rdr::InStream* is_) |
| 31 | : handler(handler_), is(is_) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | SMsgReader::~SMsgReader() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void SMsgReader::readSetPixelFormat() |
| 40 | { |
| 41 | is->skip(3); |
| 42 | PixelFormat pf; |
| 43 | pf.read(is); |
| 44 | handler->setPixelFormat(pf); |
| 45 | } |
| 46 | |
| 47 | void SMsgReader::readSetEncodings() |
| 48 | { |
| 49 | is->skip(1); |
| 50 | int nEncodings = is->readU16(); |
| 51 | rdr::U32Array encodings(nEncodings); |
| 52 | for (int i = 0; i < nEncodings; i++) |
| 53 | encodings.buf[i] = is->readU32(); |
| 54 | handler->setEncodings(nEncodings, encodings.buf); |
| 55 | } |
| 56 | |
| 57 | void SMsgReader::readFramebufferUpdateRequest() |
| 58 | { |
| 59 | bool inc = is->readU8(); |
| 60 | int x = is->readU16(); |
| 61 | int y = is->readU16(); |
| 62 | int w = is->readU16(); |
| 63 | int h = is->readU16(); |
| 64 | handler->framebufferUpdateRequest(Rect(x, y, x+w, y+h), inc); |
| 65 | } |
| 66 | |
| 67 | void SMsgReader::readKeyEvent() |
| 68 | { |
| 69 | bool down = is->readU8(); |
| 70 | is->skip(2); |
| 71 | rdr::U32 key = is->readU32(); |
| 72 | handler->keyEvent(key, down); |
| 73 | } |
| 74 | |
| 75 | void SMsgReader::readPointerEvent() |
| 76 | { |
| 77 | int mask = is->readU8(); |
| 78 | int x = is->readU16(); |
| 79 | int y = is->readU16(); |
| 80 | handler->pointerEvent(Point(x, y), mask); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | void SMsgReader::readClientCutText() |
| 85 | { |
| 86 | is->skip(3); |
| 87 | int len = is->readU32(); |
| 88 | if (len > maxCutText) { |
| 89 | is->skip(len); |
| 90 | fprintf(stderr,"cut text too long (%d bytes) - ignoring\n",len); |
| 91 | return; |
| 92 | } |
| 93 | CharArray ca(len+1); |
| 94 | ca.buf[len] = 0; |
| 95 | is->readBytes(ca.buf, len); |
| 96 | handler->clientCutText(ca.buf, len); |
| 97 | } |
Constantin Kaplinsky | dafbb01 | 2007-04-05 08:43:25 +0000 | [diff] [blame] | 98 | |
| 99 | void SMsgReader::readEnableContinuousUpdates() |
| 100 | { |
| 101 | bool enable = is->readU8(); |
| 102 | int x = is->readU16(); |
| 103 | int y = is->readU16(); |
| 104 | int w = is->readU16(); |
| 105 | int h = is->readU16(); |
| 106 | if (enable) { |
| 107 | handler->enableContinuousUpdates(Rect(x, y, x+w, y+h)); |
| 108 | } else { |
| 109 | handler->disableContinuousUpdates(); |
| 110 | } |
| 111 | } |
| 112 | |
Constantin Kaplinsky | 8232831 | 2008-04-24 08:44:24 +0000 | [diff] [blame^] | 113 | void SMsgReader::readVideoRectangleSelection() |
| 114 | { |
| 115 | (void)is->readU8(); |
| 116 | int x = is->readU16(); |
| 117 | int y = is->readU16(); |
| 118 | int w = is->readU16(); |
| 119 | int h = is->readU16(); |
| 120 | bool enable = w > 0 && h > 0; |
| 121 | |
| 122 | // FIXME: Use proper logger. |
| 123 | fprintf(stderr, "Ignoring VideoRectangleSelection message\n"); |
| 124 | |
| 125 | // FIXME: Implement VideoRectangleSelection message handling. |
| 126 | } |
| 127 | |