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