blob: 6d9e254b4d66d332aa01a1dcc6b1d031dfe2e3d8 [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;
54 default:
55 vlog.error("unknown message type "+type);
56 throw new Exception("unknown message type");
57 }
58
59 } else {
60
61 int x = is.readU16();
62 int y = is.readU16();
63 int w = is.readU16();
64 int h = is.readU16();
Brian Hinze7681412011-05-17 21:00:34 +000065 int encoding = is.readS32();
DRCc5dc0382011-05-13 21:42:14 +000066
67 switch (encoding) {
68 case Encodings.pseudoEncodingDesktopSize:
69 handler.setDesktopSize(w, h);
70 break;
71 case Encodings.pseudoEncodingExtendedDesktopSize:
72 readExtendedDesktopSize(x, y, w, h);
73 break;
74 case Encodings.pseudoEncodingDesktopName:
75 readSetDesktopName(x, y, w, h);
76 break;
77 case Encodings.pseudoEncodingCursor:
78 readSetCursor(w, h, new Point(x,y));
79 break;
80 case Encodings.pseudoEncodingLastRect:
81 nUpdateRectsLeft = 1; // this rectangle is the last one
82 break;
Brian Hinzf7ed1f62011-06-10 00:44:05 +000083 case Encodings.pseudoEncodingClientRedirect:
84 readClientRedirect(x, y, w, h);
85 break;
DRCc5dc0382011-05-13 21:42:14 +000086 default:
87 readRect(new Rect(x, y, x+w, y+h), encoding);
88 break;
89 }
90
91 nUpdateRectsLeft--;
92 if (nUpdateRectsLeft == 0) handler.framebufferUpdateEnd();
93 }
94 }
95
96 void readFramebufferUpdate()
97 {
98 is.skip(1);
99 nUpdateRectsLeft = is.readU16();
100 handler.framebufferUpdateStart();
101 }
102
103 void readSetDesktopName(int x, int y, int w, int h)
104 {
105 String name = is.readString();
106
107 if (x != 0 || y != 0 || w != 0 || h != 0) {
108 vlog.error("Ignoring DesktopName rect with non-zero position/size");
109 } else {
110 handler.setName(name);
111 }
112
113 }
114
115 void readExtendedDesktopSize(int x, int y, int w, int h)
116 {
117 int screens, i;
118 int id, flags;
119 int sx, sy, sw, sh;
120 ScreenSet layout = new ScreenSet();
121
122 screens = is.readU8();
123 is.skip(3);
124
125 for (i = 0;i < screens;i++) {
126 id = is.readU32();
127 sx = is.readU16();
128 sy = is.readU16();
129 sw = is.readU16();
130 sh = is.readU16();
131 flags = is.readU32();
132
133 layout.add_screen(new Screen(id, sx, sy, sw, sh, flags));
134 }
135
136 handler.setExtendedDesktopSize(x, y, w, h, layout);
137 }
138
Brian Hinzf7ed1f62011-06-10 00:44:05 +0000139 void readClientRedirect(int x, int y, int w, int h)
140 {
141 int port = is.readU16();
142 String host = is.readString();
143 String x509subject = is.readString();
144
145 if (x != 0 || y != 0 || w != 0 || h != 0) {
146 vlog.error("Ignoring ClientRedirect rect with non-zero position/size");
147 } else {
148 handler.clientRedirect(port, host, x509subject);
149 }
150 }
151
DRCc5dc0382011-05-13 21:42:14 +0000152 int nUpdateRectsLeft;
153
154 static LogWriter vlog = new LogWriter("CMsgReaderV3");
155}