blob: d1c08573674f47139034bab16c13eb31a379155d [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +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
19//
20// VNCSConnectionST is our derived class of SConnection for VNCServerST - there
21// is one for each connected client. We think of VNCSConnectionST as part of
22// the VNCServerST implementation, so its methods are allowed full access to
23// members of VNCServerST.
24//
25
26#ifndef __RFB_VNCSCONNECTIONST_H__
27#define __RFB_VNCSCONNECTIONST_H__
28
29#include <set>
30#include <rfb/SConnection.h>
31#include <rfb/SMsgWriter.h>
32#include <rfb/TransImageGetter.h>
33#include <rfb/VNCServerST.h>
34#include <rfb/SFileTransfer.h>
35
36namespace rfb {
37 class VNCSConnectionST : public SConnection,
38 public WriteSetCursorCallback {
39 public:
40 VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
41 virtual ~VNCSConnectionST();
42
43 // Methods called from VNCServerST. None of these methods ever knowingly
44 // throw an exception.
45
46 // Unless otherwise stated, the SConnectionST may not be valid after any of
47 // these methods are called, since they catch exceptions and may have
48 // called close() which deletes the object.
49
50 // init() must be called to initialise the protocol. If it fails it
51 // returns false, and close() will have been called.
52 bool init();
53
54 // close() shuts down the socket to the client and deletes the
55 // SConnectionST object.
56 void close(const char* reason);
57
58 // processMessages() processes incoming messages from the client, invoking
59 // various callbacks as a result. It continues to process messages until
60 // reading might block. shutdown() will be called on the connection's
61 // Socket if an error occurs, via the close() call.
62 void processMessages();
63
64 void writeFramebufferUpdateOrClose();
65 void pixelBufferChange();
66 void setColourMapEntriesOrClose(int firstColour, int nColours);
67 void bell();
68 void serverCutText(const char *str, int len);
Peter Åstrandc39e0782009-01-15 12:21:42 +000069 void setDesktopName(const char *name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000070 void setCursorOrClose();
71
72 // checkIdleTimeout() returns the number of milliseconds left until the
73 // idle timeout expires. If it has expired, the connection is closed and
74 // zero is returned. Zero is also returned if there is no idle timeout.
75 int checkIdleTimeout();
76
77 // The following methods never throw exceptions nor do they ever delete the
78 // SConnectionST object.
79
80 // renderedCursorChange() is called whenever the server-side rendered
81 // cursor changes shape or position. It ensures that the next update will
82 // clean up the old rendered cursor and if necessary draw the new rendered
83 // cursor.
84 void renderedCursorChange();
85
86 // needRenderedCursor() returns true if this client needs the server-side
87 // rendered cursor. This may be because it does not support local cursor
88 // or because the current cursor position has not been set by this client.
89 bool needRenderedCursor();
90
91 network::Socket* getSock() { return sock; }
92 bool readyForUpdate() { return !requested.is_empty(); }
93 void add_changed(const Region& region) { updates.add_changed(region); }
94 void add_copied(const Region& dest, const Point& delta) {
95 updates.add_copied(dest, delta);
96 }
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +000097 void set_video_area(const Rect &rect) { updates.set_video_area(rect); }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000098
99 const char* getPeerEndpoint() const {return peerEndpoint.buf;}
100
101 // approveConnectionOrClose() is called some time after
102 // VNCServerST::queryConnection() has returned with PENDING to accept or
103 // reject the connection. The accept argument should be true for
104 // acceptance, or false for rejection, in which case a string reason may
105 // also be given.
106
107 void approveConnectionOrClose(bool accept, const char* reason);
108
109 char* getStartTime();
110
111 void setStatus(int status);
112 int getStatus();
113
114 bool processFTMsg(int type);
115
116 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);
131 virtual void setInitialColourMap();
132 virtual void supportsLocalCursor();
133
Constantin Kaplinsky9d1fc6c2008-06-14 05:23:10 +0000134 virtual void setVideoRectangle(const Rect& r);
Constantin Kaplinsky9d1fc6c2008-06-14 05:23:10 +0000135
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000136 // 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
145 // Internal methods
146
147 // writeFramebufferUpdate() attempts to write a framebuffer update to the
148 // client.
149
150 void writeFramebufferUpdate();
151
152 void writeRenderedCursorRect();
153 void setColourMapEntries(int firstColour, int nColours);
154 void setCursor();
155 void setSocketTimeouts();
156
157 network::Socket* sock;
158 CharArray peerEndpoint;
159 VNCServerST* server;
160 SimpleUpdateTracker updates;
161 TransImageGetter image_getter;
162 Region requested;
163 bool drawRenderedCursor, removeRenderedCursor;
164 Rect renderedCursorRect;
165
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000166 std::set<rdr::U32> pressedKeys;
167
168 time_t lastEventTime;
169 time_t pointerEventTime;
170 Point pointerEventPos;
171
172 AccessRights accessRights;
173
174 CharArray closeReason;
175 time_t startTime;
176
177 SFileTransfer *m_pFileTransfer;
178 };
179}
180#endif