blob: e06522b9e6a4f7e0c4f4b66a1c446f70fd833ad9 [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();
Pierre Ossman2c764942011-11-14 15:54:30 +0000136 virtual void fence(rdr::U32 flags, unsigned len, const char data[]);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000137 virtual void supportsLocalCursor();
Pierre Ossman2c764942011-11-14 15:54:30 +0000138 virtual void supportsFence();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000139
140 // setAccessRights() allows a security package to limit the access rights
141 // of a VNCSConnectioST to the server. These access rights are applied
142 // such that the actual rights granted are the minimum of the server's
143 // default access settings and the connection's access settings.
144 virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
145
146 // WriteSetCursorCallback
147 virtual void writeSetCursorCallback();
148
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000149 // Timer callbacks
150 virtual bool handleTimeout(Timer* t);
151
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000152 // Internal methods
153
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000154 bool isCongested();
155
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000156 // writeFramebufferUpdate() attempts to write a framebuffer update to the
157 // client.
158
159 void writeFramebufferUpdate();
160
161 void writeRenderedCursorRect();
Pierre Ossmana3ac01e2011-11-07 21:13:54 +0000162 void screenLayoutChange(rdr::U16 reason);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000163 void setColourMapEntries(int firstColour, int nColours);
164 void setCursor();
Pierre Ossmana3ac01e2011-11-07 21:13:54 +0000165 void setDesktopName(const char *name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000166 void setSocketTimeouts();
167
168 network::Socket* sock;
169 CharArray peerEndpoint;
Pierre Ossmana3ac01e2011-11-07 21:13:54 +0000170
171 bool inProcessMessages;
172
Pierre Ossman2c764942011-11-14 15:54:30 +0000173 bool syncFence;
174 rdr::U32 fenceFlags;
175 unsigned fenceDataLen;
176 char *fenceData;
177
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000178 VNCServerST* server;
179 SimpleUpdateTracker updates;
180 TransImageGetter image_getter;
181 Region requested;
182 bool drawRenderedCursor, removeRenderedCursor;
183 Rect renderedCursorRect;
184
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000185 Timer updateTimer;
186
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000187 std::set<rdr::U32> pressedKeys;
188
189 time_t lastEventTime;
190 time_t pointerEventTime;
191 Point pointerEventPos;
192
193 AccessRights accessRights;
194
195 CharArray closeReason;
196 time_t startTime;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000197 };
198}
199#endif