blob: 5a007ee9d31f551f867a1fe6b3f1b78f410034d7 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossmana3ac01e2011-11-07 21:13:54 +00002 * Copyright 2009-2011 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20//
21// VNCSConnectionST is our derived class of SConnection for VNCServerST - there
22// is one for each connected client. We think of VNCSConnectionST as part of
23// the VNCServerST implementation, so its methods are allowed full access to
24// members of VNCServerST.
25//
26
27#ifndef __RFB_VNCSCONNECTIONST_H__
28#define __RFB_VNCSCONNECTIONST_H__
29
30#include <set>
31#include <rfb/SConnection.h>
32#include <rfb/SMsgWriter.h>
33#include <rfb/TransImageGetter.h>
34#include <rfb/VNCServerST.h>
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +000035#include <rfb/Timer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000036
37namespace rfb {
38 class VNCSConnectionST : public SConnection,
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +000039 public WriteSetCursorCallback,
40 public Timer::Callback {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041 public:
42 VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
43 virtual ~VNCSConnectionST();
44
45 // Methods called from VNCServerST. None of these methods ever knowingly
46 // throw an exception.
47
48 // Unless otherwise stated, the SConnectionST may not be valid after any of
49 // these methods are called, since they catch exceptions and may have
50 // called close() which deletes the object.
51
52 // init() must be called to initialise the protocol. If it fails it
53 // returns false, and close() will have been called.
54 bool init();
55
56 // close() shuts down the socket to the client and deletes the
57 // SConnectionST object.
58 void close(const char* reason);
59
60 // processMessages() processes incoming messages from the client, invoking
61 // various callbacks as a result. It continues to process messages until
62 // reading might block. shutdown() will be called on the connection's
63 // Socket if an error occurs, via the close() call.
64 void processMessages();
65
Pierre Ossmana3ac01e2011-11-07 21:13:54 +000066 // Called when the underlying pixelbuffer is resized or replaced.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067 void pixelBufferChange();
Pierre Ossmana3ac01e2011-11-07 21:13:54 +000068
69 // Wrappers to make these methods "safe" for VNCServerST.
70 void writeFramebufferUpdateOrClose();
71 void screenLayoutChangeOrClose(rdr::U16 reason);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000072 void setColourMapEntriesOrClose(int firstColour, int nColours);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000073 void setCursorOrClose();
Pierre Ossmana3ac01e2011-11-07 21:13:54 +000074 void bellOrClose();
75 void serverCutTextOrClose(const char *str, int len);
76 void setDesktopNameOrClose(const char *name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000077
78 // checkIdleTimeout() returns the number of milliseconds left until the
79 // idle timeout expires. If it has expired, the connection is closed and
80 // zero is returned. Zero is also returned if there is no idle timeout.
81 int checkIdleTimeout();
82
83 // The following methods never throw exceptions nor do they ever delete the
84 // SConnectionST object.
85
86 // renderedCursorChange() is called whenever the server-side rendered
87 // cursor changes shape or position. It ensures that the next update will
88 // clean up the old rendered cursor and if necessary draw the new rendered
89 // cursor.
90 void renderedCursorChange();
91
92 // needRenderedCursor() returns true if this client needs the server-side
93 // rendered cursor. This may be because it does not support local cursor
94 // or because the current cursor position has not been set by this client.
95 bool needRenderedCursor();
96
97 network::Socket* getSock() { return sock; }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000098 void add_changed(const Region& region) { updates.add_changed(region); }
99 void add_copied(const Region& dest, const Point& delta) {
100 updates.add_copied(dest, delta);
101 }
102
103 const char* getPeerEndpoint() const {return peerEndpoint.buf;}
104
105 // approveConnectionOrClose() is called some time after
106 // VNCServerST::queryConnection() has returned with PENDING to accept or
107 // reject the connection. The accept argument should be true for
108 // acceptance, or false for rejection, in which case a string reason may
109 // also be given.
110
111 void approveConnectionOrClose(bool accept, const char* reason);
112
113 char* getStartTime();
114
115 void setStatus(int status);
116 int getStatus();
117
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000118 private:
119 // SConnection callbacks
120
121 // These methods are invoked as callbacks from processMsg(). Note that
122 // none of these methods should call any of the above methods which may
123 // delete the SConnectionST object.
124
125 virtual void authSuccess();
126 virtual void queryConnection(const char* userName);
127 virtual void clientInit(bool shared);
128 virtual void setPixelFormat(const PixelFormat& pf);
129 virtual void pointerEvent(const Point& pos, int buttonMask);
130 virtual void keyEvent(rdr::U32 key, bool down);
131 virtual void clientCutText(const char* str, int len);
132 virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
Pierre Ossman34bb0612009-03-21 21:16:14 +0000133 virtual void setDesktopSize(int fb_width, int fb_height,
134 const ScreenSet& layout);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000135 virtual void setInitialColourMap();
136 virtual void supportsLocalCursor();
137
138 // setAccessRights() allows a security package to limit the access rights
139 // of a VNCSConnectioST to the server. These access rights are applied
140 // such that the actual rights granted are the minimum of the server's
141 // default access settings and the connection's access settings.
142 virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
143
144 // WriteSetCursorCallback
145 virtual void writeSetCursorCallback();
146
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000147 // Timer callbacks
148 virtual bool handleTimeout(Timer* t);
149
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000150 // Internal methods
151
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000152 bool isCongested();
153
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000154 // writeFramebufferUpdate() attempts to write a framebuffer update to the
155 // client.
156
157 void writeFramebufferUpdate();
158
159 void writeRenderedCursorRect();
Pierre Ossmana3ac01e2011-11-07 21:13:54 +0000160 void screenLayoutChange(rdr::U16 reason);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000161 void setColourMapEntries(int firstColour, int nColours);
162 void setCursor();
Pierre Ossmana3ac01e2011-11-07 21:13:54 +0000163 void setDesktopName(const char *name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000164 void setSocketTimeouts();
165
166 network::Socket* sock;
167 CharArray peerEndpoint;
Pierre Ossmana3ac01e2011-11-07 21:13:54 +0000168
169 bool inProcessMessages;
170
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000171 VNCServerST* server;
172 SimpleUpdateTracker updates;
173 TransImageGetter image_getter;
174 Region requested;
175 bool drawRenderedCursor, removeRenderedCursor;
176 Rect renderedCursorRect;
177
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000178 Timer updateTimer;
179
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000180 std::set<rdr::U32> pressedKeys;
181
182 time_t lastEventTime;
183 time_t pointerEventTime;
184 Point pointerEventPos;
185
186 AccessRights accessRights;
187
188 CharArray closeReason;
189 time_t startTime;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000190 };
191}
192#endif