blob: a04296d3b7a804401282c344c07b64809334b8be [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);
69 void setCursorOrClose();
70
71 // checkIdleTimeout() returns the number of milliseconds left until the
72 // idle timeout expires. If it has expired, the connection is closed and
73 // zero is returned. Zero is also returned if there is no idle timeout.
74 int checkIdleTimeout();
75
76 // The following methods never throw exceptions nor do they ever delete the
77 // SConnectionST object.
78
79 // renderedCursorChange() is called whenever the server-side rendered
80 // cursor changes shape or position. It ensures that the next update will
81 // clean up the old rendered cursor and if necessary draw the new rendered
82 // cursor.
83 void renderedCursorChange();
84
85 // needRenderedCursor() returns true if this client needs the server-side
86 // rendered cursor. This may be because it does not support local cursor
87 // or because the current cursor position has not been set by this client.
88 bool needRenderedCursor();
89
90 network::Socket* getSock() { return sock; }
91 bool readyForUpdate() { return !requested.is_empty(); }
92 void add_changed(const Region& region) { updates.add_changed(region); }
93 void add_copied(const Region& dest, const Point& delta) {
94 updates.add_copied(dest, delta);
95 }
96
97 const char* getPeerEndpoint() const {return peerEndpoint.buf;}
98
99 // approveConnectionOrClose() is called some time after
100 // VNCServerST::queryConnection() has returned with PENDING to accept or
101 // reject the connection. The accept argument should be true for
102 // acceptance, or false for rejection, in which case a string reason may
103 // also be given.
104
105 void approveConnectionOrClose(bool accept, const char* reason);
106
107 char* getStartTime();
108
109 void setStatus(int status);
110 int getStatus();
111
112 bool processFTMsg(int type);
113
114 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);
129 virtual void setInitialColourMap();
130 virtual void supportsLocalCursor();
131
132 // setAccessRights() allows a security package to limit the access rights
133 // of a VNCSConnectioST to the server. These access rights are applied
134 // such that the actual rights granted are the minimum of the server's
135 // default access settings and the connection's access settings.
136 virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
137
138 // WriteSetCursorCallback
139 virtual void writeSetCursorCallback();
140
141 // Internal methods
142
143 // writeFramebufferUpdate() attempts to write a framebuffer update to the
144 // client.
145
146 void writeFramebufferUpdate();
147
148 void writeRenderedCursorRect();
149 void setColourMapEntries(int firstColour, int nColours);
150 void setCursor();
151 void setSocketTimeouts();
152
153 network::Socket* sock;
154 CharArray peerEndpoint;
155 VNCServerST* server;
156 SimpleUpdateTracker updates;
157 TransImageGetter image_getter;
158 Region requested;
159 bool drawRenderedCursor, removeRenderedCursor;
160 Rect renderedCursorRect;
161
162 std::set<rdr::U32> pressedKeys;
163
164 time_t lastEventTime;
165 time_t pointerEventTime;
166 Point pointerEventPos;
167
168 AccessRights accessRights;
169
170 CharArray closeReason;
171 time_t startTime;
172
173 SFileTransfer *m_pFileTransfer;
174 };
175}
176#endif