blob: abf4383824b5ffae5b05a363cdc5541bc991eaf6 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossmanc5e25602009-03-20 12:59:05 +00002 * Copyright 2009 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
66 void writeFramebufferUpdateOrClose();
67 void pixelBufferChange();
Pierre Ossman04e62db2009-03-23 16:57:07 +000068 void screenLayoutChange(rdr::U16 reason);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000069 void setColourMapEntriesOrClose(int firstColour, int nColours);
70 void bell();
71 void serverCutText(const char *str, int len);
Peter Åstrandc39e0782009-01-15 12:21:42 +000072 void setDesktopName(const char *name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000073 void setCursorOrClose();
74
75 // checkIdleTimeout() returns the number of milliseconds left until the
76 // idle timeout expires. If it has expired, the connection is closed and
77 // zero is returned. Zero is also returned if there is no idle timeout.
78 int checkIdleTimeout();
79
80 // The following methods never throw exceptions nor do they ever delete the
81 // SConnectionST object.
82
83 // renderedCursorChange() is called whenever the server-side rendered
84 // cursor changes shape or position. It ensures that the next update will
85 // clean up the old rendered cursor and if necessary draw the new rendered
86 // cursor.
87 void renderedCursorChange();
88
89 // needRenderedCursor() returns true if this client needs the server-side
90 // rendered cursor. This may be because it does not support local cursor
91 // or because the current cursor position has not been set by this client.
92 bool needRenderedCursor();
93
94 network::Socket* getSock() { return sock; }
95 bool readyForUpdate() { return !requested.is_empty(); }
96 void add_changed(const Region& region) { updates.add_changed(region); }
97 void add_copied(const Region& dest, const Point& delta) {
98 updates.add_copied(dest, delta);
99 }
100
101 const char* getPeerEndpoint() const {return peerEndpoint.buf;}
102
103 // approveConnectionOrClose() is called some time after
104 // VNCServerST::queryConnection() has returned with PENDING to accept or
105 // reject the connection. The accept argument should be true for
106 // acceptance, or false for rejection, in which case a string reason may
107 // also be given.
108
109 void approveConnectionOrClose(bool accept, const char* reason);
110
111 char* getStartTime();
112
113 void setStatus(int status);
114 int getStatus();
115
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000116 private:
117 // SConnection callbacks
118
119 // These methods are invoked as callbacks from processMsg(). Note that
120 // none of these methods should call any of the above methods which may
121 // delete the SConnectionST object.
122
123 virtual void authSuccess();
124 virtual void queryConnection(const char* userName);
125 virtual void clientInit(bool shared);
126 virtual void setPixelFormat(const PixelFormat& pf);
127 virtual void pointerEvent(const Point& pos, int buttonMask);
128 virtual void keyEvent(rdr::U32 key, bool down);
129 virtual void clientCutText(const char* str, int len);
130 virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
Pierre Ossman34bb0612009-03-21 21:16:14 +0000131 virtual void setDesktopSize(int fb_width, int fb_height,
132 const ScreenSet& layout);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000133 virtual void setInitialColourMap();
134 virtual void supportsLocalCursor();
135
136 // setAccessRights() allows a security package to limit the access rights
137 // of a VNCSConnectioST to the server. These access rights are applied
138 // such that the actual rights granted are the minimum of the server's
139 // default access settings and the connection's access settings.
140 virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
141
142 // WriteSetCursorCallback
143 virtual void writeSetCursorCallback();
144
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000145 // Timer callbacks
146 virtual bool handleTimeout(Timer* t);
147
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000148 // Internal methods
149
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000150 bool isCongested();
151
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000152 // writeFramebufferUpdate() attempts to write a framebuffer update to the
153 // client.
154
155 void writeFramebufferUpdate();
156
157 void writeRenderedCursorRect();
158 void setColourMapEntries(int firstColour, int nColours);
159 void setCursor();
160 void setSocketTimeouts();
161
162 network::Socket* sock;
163 CharArray peerEndpoint;
164 VNCServerST* server;
165 SimpleUpdateTracker updates;
166 TransImageGetter image_getter;
167 Region requested;
168 bool drawRenderedCursor, removeRenderedCursor;
169 Rect renderedCursorRect;
170
Pierre Ossman1bb8b6c2011-10-25 15:20:05 +0000171 Timer updateTimer;
172
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000173 std::set<rdr::U32> pressedKeys;
174
175 time_t lastEventTime;
176 time_t pointerEventTime;
177 Point pointerEventPos;
178
179 AccessRights accessRights;
180
181 CharArray closeReason;
182 time_t startTime;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000183 };
184}
185#endif