blob: c9e4ac8d7574f60eccad02b0f79433ac03587920 [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>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000035
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();
Pierre Ossman04e62db2009-03-23 16:57:07 +000066 void screenLayoutChange(rdr::U16 reason);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067 void setColourMapEntriesOrClose(int firstColour, int nColours);
68 void bell();
69 void serverCutText(const char *str, int len);
Peter Åstrandc39e0782009-01-15 12:21:42 +000070 void setDesktopName(const char *name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000071 void setCursorOrClose();
72
73 // checkIdleTimeout() returns the number of milliseconds left until the
74 // idle timeout expires. If it has expired, the connection is closed and
75 // zero is returned. Zero is also returned if there is no idle timeout.
76 int checkIdleTimeout();
77
78 // The following methods never throw exceptions nor do they ever delete the
79 // SConnectionST object.
80
81 // renderedCursorChange() is called whenever the server-side rendered
82 // cursor changes shape or position. It ensures that the next update will
83 // clean up the old rendered cursor and if necessary draw the new rendered
84 // cursor.
85 void renderedCursorChange();
86
87 // needRenderedCursor() returns true if this client needs the server-side
88 // rendered cursor. This may be because it does not support local cursor
89 // or because the current cursor position has not been set by this client.
90 bool needRenderedCursor();
91
92 network::Socket* getSock() { return sock; }
93 bool readyForUpdate() { return !requested.is_empty(); }
94 void add_changed(const Region& region) { updates.add_changed(region); }
95 void add_copied(const Region& dest, const Point& delta) {
96 updates.add_copied(dest, delta);
97 }
98
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
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000114 private:
115 // SConnection callbacks
116
117 // These methods are invoked as callbacks from processMsg(). Note that
118 // none of these methods should call any of the above methods which may
119 // delete the SConnectionST object.
120
121 virtual void authSuccess();
122 virtual void queryConnection(const char* userName);
123 virtual void clientInit(bool shared);
124 virtual void setPixelFormat(const PixelFormat& pf);
125 virtual void pointerEvent(const Point& pos, int buttonMask);
126 virtual void keyEvent(rdr::U32 key, bool down);
127 virtual void clientCutText(const char* str, int len);
128 virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
Pierre Ossman34bb0612009-03-21 21:16:14 +0000129 virtual void setDesktopSize(int fb_width, int fb_height,
130 const ScreenSet& layout);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000131 virtual void setInitialColourMap();
132 virtual void supportsLocalCursor();
133
134 // setAccessRights() allows a security package to limit the access rights
135 // of a VNCSConnectioST to the server. These access rights are applied
136 // such that the actual rights granted are the minimum of the server's
137 // default access settings and the connection's access settings.
138 virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
139
140 // WriteSetCursorCallback
141 virtual void writeSetCursorCallback();
142
143 // Internal methods
144
145 // writeFramebufferUpdate() attempts to write a framebuffer update to the
146 // client.
147
148 void writeFramebufferUpdate();
149
150 void writeRenderedCursorRect();
151 void setColourMapEntries(int firstColour, int nColours);
152 void setCursor();
153 void setSocketTimeouts();
154
155 network::Socket* sock;
156 CharArray peerEndpoint;
157 VNCServerST* server;
158 SimpleUpdateTracker updates;
159 TransImageGetter image_getter;
160 Region requested;
161 bool drawRenderedCursor, removeRenderedCursor;
162 Rect renderedCursorRect;
163
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000164 std::set<rdr::U32> pressedKeys;
165
166 time_t lastEventTime;
167 time_t pointerEventTime;
168 Point pointerEventPos;
169
170 AccessRights accessRights;
171
172 CharArray closeReason;
173 time_t startTime;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000174 };
175}
176#endif