blob: 49d8dcf18ccfa8a4d7504ac5abe13994cc7dd4ca [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* 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 Kaplinskyc7755da2008-04-24 11:01:55 +000025#include <rfb/LogWriter.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000026
27using namespace rfb;
28
Constantin Kaplinskyc7755da2008-04-24 11:01:55 +000029static LogWriter vlog("SMsgReader");
30
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000031static IntParameter maxCutText("MaxCutText", "Maximum permitted length of an incoming clipboard update", 256*1024);
32
33SMsgReader::SMsgReader(SMsgHandler* handler_, rdr::InStream* is_)
34 : handler(handler_), is(is_)
35{
36}
37
38SMsgReader::~SMsgReader()
39{
40}
41
42void SMsgReader::readSetPixelFormat()
43{
44 is->skip(3);
45 PixelFormat pf;
46 pf.read(is);
47 handler->setPixelFormat(pf);
48}
49
50void SMsgReader::readSetEncodings()
51{
52 is->skip(1);
53 int nEncodings = is->readU16();
Peter Åstrand98fe98c2010-02-10 07:43:02 +000054 rdr::S32Array encodings(nEncodings);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000055 for (int i = 0; i < nEncodings; i++)
56 encodings.buf[i] = is->readU32();
57 handler->setEncodings(nEncodings, encodings.buf);
58}
59
60void 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
70void 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
78void 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
87void SMsgReader::readClientCutText()
88{
89 is->skip(3);
90 int len = is->readU32();
91 if (len > maxCutText) {
92 is->skip(len);
Constantin Kaplinskyc7755da2008-04-24 11:01:55 +000093 vlog.error("Cut text too long (%d bytes) - ignoring", len);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000094 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 Kaplinskydafbb012007-04-05 08:43:25 +0000101