blob: 2121150df06453373949b4032f42095dc88e365b [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>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000034
35namespace rfb {
36 class VNCSConnectionST : public SConnection,
37 public WriteSetCursorCallback {
38 public:
39 VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
40 virtual ~VNCSConnectionST();
41
42 // Methods called from VNCServerST. None of these methods ever knowingly
43 // throw an exception.
44
45 // Unless otherwise stated, the SConnectionST may not be valid after any of
46 // these methods are called, since they catch exceptions and may have
47 // called close() which deletes the object.
48
49 // init() must be called to initialise the protocol. If it fails it
50 // returns false, and close() will have been called.
51 bool init();
52
53 // close() shuts down the socket to the client and deletes the
54 // SConnectionST object.
55 void close(const char* reason);
56
57 // processMessages() processes incoming messages from the client, invoking
58 // various callbacks as a result. It continues to process messages until
59 // reading might block. shutdown() will be called on the connection's
60 // Socket if an error occurs, via the close() call.
61 void processMessages();
62
63 void writeFramebufferUpdateOrClose();
64 void pixelBufferChange();
65 void setColourMapEntriesOrClose(int firstColour, int nColours);
66 void bell();
67 void serverCutText(const char *str, int len);
Peter Åstrandc39e0782009-01-15 12:21:42 +000068 void setDesktopName(const char *name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000069 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
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000112 private:
113 // SConnection callbacks
114
115 // These methods are invoked as callbacks from processMsg(). Note that
116 // none of these methods should call any of the above methods which may
117 // delete the SConnectionST object.
118
119 virtual void authSuccess();
120 virtual void queryConnection(const char* userName);
121 virtual void clientInit(bool shared);
122 virtual void setPixelFormat(const PixelFormat& pf);
123 virtual void pointerEvent(const Point& pos, int buttonMask);
124 virtual void keyEvent(rdr::U32 key, bool down);
125 virtual void clientCutText(const char* str, int len);
126 virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
127 virtual void setInitialColourMap();
128 virtual void supportsLocalCursor();
129
130 // setAccessRights() allows a security package to limit the access rights
131 // of a VNCSConnectioST to the server. These access rights are applied
132 // such that the actual rights granted are the minimum of the server's
133 // default access settings and the connection's access settings.
134 virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
135
136 // WriteSetCursorCallback
137 virtual void writeSetCursorCallback();
138
139 // Internal methods
140
141 // writeFramebufferUpdate() attempts to write a framebuffer update to the
142 // client.
143
144 void writeFramebufferUpdate();
145
146 void writeRenderedCursorRect();
147 void setColourMapEntries(int firstColour, int nColours);
148 void setCursor();
149 void setSocketTimeouts();
150
151 network::Socket* sock;
152 CharArray peerEndpoint;
153 VNCServerST* server;
154 SimpleUpdateTracker updates;
155 TransImageGetter image_getter;
156 Region requested;
157 bool drawRenderedCursor, removeRenderedCursor;
158 Rect renderedCursorRect;
159
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000160 std::set<rdr::U32> pressedKeys;
161
162 time_t lastEventTime;
163 time_t pointerEventTime;
164 Point pointerEventPos;
165
166 AccessRights accessRights;
167
168 CharArray closeReason;
169 time_t startTime;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000170 };
171}
172#endif