blob: 915b1e01965f06fceaf782ecfdad10c74c37be6b [file] [log] [blame]
DRCc5dc0382011-05-13 21:42:14 +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
19package com.tigervnc.rfb;
20
21import com.tigervnc.rdr.*;
22
23public class CMsgReaderV3 extends CMsgReader {
24
25 public CMsgReaderV3(CMsgHandler handler_, InStream is_)
26 {
27 super(handler_, is_);
28 nUpdateRectsLeft = 0;
29 }
30
31 public void readServerInit()
32 {
33 int width = is.readU16();
34 int height = is.readU16();
35 handler.setDesktopSize(width, height);
36 PixelFormat pf = new PixelFormat();
37 pf.read(is);
38 handler.setPixelFormat(pf);
39 String name = is.readString();
40 handler.setName(name);
41 handler.serverInit();
42 }
43
44 public void readMsg()
45 {
46 if (nUpdateRectsLeft == 0) {
47
48 int type = is.readU8();
49 switch (type) {
50 case MsgTypes.msgTypeFramebufferUpdate: readFramebufferUpdate(); break;
51 case MsgTypes.msgTypeSetColourMapEntries: readSetColourMapEntries(); break;
52 case MsgTypes.msgTypeBell: readBell(); break;
53 case MsgTypes.msgTypeServerCutText: readServerCutText(); break;
Brian Hinzaf15db22012-02-12 20:44:29 +000054 case MsgTypes.msgTypeServerFence: readFence(); break;
55 case MsgTypes.msgTypeEndOfContinuousUpdates: readEndOfContinuousUpdates(); break;
DRCc5dc0382011-05-13 21:42:14 +000056 default:
57 vlog.error("unknown message type "+type);
58 throw new Exception("unknown message type");
59 }
60
61 } else {
62
63 int x = is.readU16();
64 int y = is.readU16();
65 int w = is.readU16();
66 int h = is.readU16();
Brian Hinze7681412011-05-17 21:00:34 +000067 int encoding = is.readS32();
DRCc5dc0382011-05-13 21:42:14 +000068
69 switch (encoding) {
70 case Encodings.pseudoEncodingDesktopSize:
71 handler.setDesktopSize(w, h);
72 break;
73 case Encodings.pseudoEncodingExtendedDesktopSize:
74 readExtendedDesktopSize(x, y, w, h);
75 break;
76 case Encodings.pseudoEncodingDesktopName:
77 readSetDesktopName(x, y, w, h);
78 break;
79 case Encodings.pseudoEncodingCursor:
80 readSetCursor(w, h, new Point(x,y));
81 break;
82 case Encodings.pseudoEncodingLastRect:
83 nUpdateRectsLeft = 1; // this rectangle is the last one
84 break;
Brian Hinzf7ed1f62011-06-10 00:44:05 +000085 case Encodings.pseudoEncodingClientRedirect:
86 readClientRedirect(x, y, w, h);
87 break;
DRCc5dc0382011-05-13 21:42:14 +000088 default:
89 readRect(new Rect(x, y, x+w, y+h), encoding);
90 break;
91 }
92
93 nUpdateRectsLeft--;
94 if (nUpdateRectsLeft == 0) handler.framebufferUpdateEnd();
95 }
96 }
97
98 void readFramebufferUpdate()
99 {
100 is.skip(1);
101 nUpdateRectsLeft = is.readU16();
102 handler.framebufferUpdateStart();
103 }
104
105 void readSetDesktopName(int x, int y, int w, int h)
106 {
107 String name = is.readString();
108
109 if (x != 0 || y != 0 || w != 0 || h != 0) {
110 vlog.error("Ignoring DesktopName rect with non-zero position/size");
111 } else {
112 handler.setName(name);
113 }
114
115 }
116
117 void readExtendedDesktopSize(int x, int y, int w, int h)
118 {
119 int screens, i;
120 int id, flags;
121 int sx, sy, sw, sh;
122 ScreenSet layout = new ScreenSet();
123
124 screens = is.readU8();
125 is.skip(3);
126
127 for (i = 0;i < screens;i++) {
128 id = is.readU32();
129 sx = is.readU16();
130 sy = is.readU16();
131 sw = is.readU16();
132 sh = is.readU16();
133 flags = is.readU32();
134
135 layout.add_screen(new Screen(id, sx, sy, sw, sh, flags));
136 }
137
138 handler.setExtendedDesktopSize(x, y, w, h, layout);
139 }
140
Brian Hinzaf15db22012-02-12 20:44:29 +0000141 void readFence()
142 {
143 int flags;
144 int len;
145 byte[] data = new byte[64];
146
147 is.skip(3);
148
149 flags = is.readU32();
150
151 len = is.readU8();
152 if (len > data.length) {
153 System.out.println("Ignoring fence with too large payload\n");
154 is.skip(len);
155 return;
156 }
157
158 is.readBytes(data, 0, len);
159
160 handler.fence(flags, len, data);
161 }
162
163 void readEndOfContinuousUpdates()
164 {
165 handler.endOfContinuousUpdates();
166 }
167
Brian Hinzf7ed1f62011-06-10 00:44:05 +0000168 void readClientRedirect(int x, int y, int w, int h)
169 {
170 int port = is.readU16();
171 String host = is.readString();
172 String x509subject = is.readString();
173
174 if (x != 0 || y != 0 || w != 0 || h != 0) {
175 vlog.error("Ignoring ClientRedirect rect with non-zero position/size");
176 } else {
177 handler.clientRedirect(port, host, x509subject);
178 }
179 }
180
DRCc5dc0382011-05-13 21:42:14 +0000181 int nUpdateRectsLeft;
182
183 static LogWriter vlog = new LogWriter("CMsgReaderV3");
184}