1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright 2009 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
//
// VNCSConnectionST is our derived class of SConnection for VNCServerST - there
// is one for each connected client. We think of VNCSConnectionST as part of
// the VNCServerST implementation, so its methods are allowed full access to
// members of VNCServerST.
//
#ifndef __RFB_VNCSCONNECTIONST_H__
#define __RFB_VNCSCONNECTIONST_H__
#include <set>
#include <rfb/SConnection.h>
#include <rfb/SMsgWriter.h>
#include <rfb/TransImageGetter.h>
#include <rfb/VNCServerST.h>
namespace rfb {
class VNCSConnectionST : public SConnection,
public WriteSetCursorCallback {
public:
VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
virtual ~VNCSConnectionST();
// Methods called from VNCServerST. None of these methods ever knowingly
// throw an exception.
// Unless otherwise stated, the SConnectionST may not be valid after any of
// these methods are called, since they catch exceptions and may have
// called close() which deletes the object.
// init() must be called to initialise the protocol. If it fails it
// returns false, and close() will have been called.
bool init();
// close() shuts down the socket to the client and deletes the
// SConnectionST object.
void close(const char* reason);
// processMessages() processes incoming messages from the client, invoking
// various callbacks as a result. It continues to process messages until
// reading might block. shutdown() will be called on the connection's
// Socket if an error occurs, via the close() call.
void processMessages();
void writeFramebufferUpdateOrClose();
void pixelBufferChange();
void screenLayoutChange(rdr::U16 reason);
void setColourMapEntriesOrClose(int firstColour, int nColours);
void bell();
void serverCutText(const char *str, int len);
void setDesktopName(const char *name);
void setCursorOrClose();
// checkIdleTimeout() returns the number of milliseconds left until the
// idle timeout expires. If it has expired, the connection is closed and
// zero is returned. Zero is also returned if there is no idle timeout.
int checkIdleTimeout();
// The following methods never throw exceptions nor do they ever delete the
// SConnectionST object.
// renderedCursorChange() is called whenever the server-side rendered
// cursor changes shape or position. It ensures that the next update will
// clean up the old rendered cursor and if necessary draw the new rendered
// cursor.
void renderedCursorChange();
// needRenderedCursor() returns true if this client needs the server-side
// rendered cursor. This may be because it does not support local cursor
// or because the current cursor position has not been set by this client.
bool needRenderedCursor();
network::Socket* getSock() { return sock; }
bool readyForUpdate() { return !requested.is_empty(); }
void add_changed(const Region& region) { updates.add_changed(region); }
void add_copied(const Region& dest, const Point& delta) {
updates.add_copied(dest, delta);
}
const char* getPeerEndpoint() const {return peerEndpoint.buf;}
// approveConnectionOrClose() is called some time after
// VNCServerST::queryConnection() has returned with PENDING to accept or
// reject the connection. The accept argument should be true for
// acceptance, or false for rejection, in which case a string reason may
// also be given.
void approveConnectionOrClose(bool accept, const char* reason);
char* getStartTime();
void setStatus(int status);
int getStatus();
private:
// SConnection callbacks
// These methods are invoked as callbacks from processMsg(). Note that
// none of these methods should call any of the above methods which may
// delete the SConnectionST object.
virtual void authSuccess();
virtual void queryConnection(const char* userName);
virtual void clientInit(bool shared);
virtual void setPixelFormat(const PixelFormat& pf);
virtual void pointerEvent(const Point& pos, int buttonMask);
virtual void keyEvent(rdr::U32 key, bool down);
virtual void clientCutText(const char* str, int len);
virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
virtual void setDesktopSize(int fb_width, int fb_height,
const ScreenSet& layout);
virtual void setInitialColourMap();
virtual void supportsLocalCursor();
// setAccessRights() allows a security package to limit the access rights
// of a VNCSConnectioST to the server. These access rights are applied
// such that the actual rights granted are the minimum of the server's
// default access settings and the connection's access settings.
virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
// WriteSetCursorCallback
virtual void writeSetCursorCallback();
// Internal methods
// writeFramebufferUpdate() attempts to write a framebuffer update to the
// client.
void writeFramebufferUpdate();
void writeRenderedCursorRect();
void setColourMapEntries(int firstColour, int nColours);
void setCursor();
void setSocketTimeouts();
network::Socket* sock;
CharArray peerEndpoint;
VNCServerST* server;
SimpleUpdateTracker updates;
TransImageGetter image_getter;
Region requested;
bool drawRenderedCursor, removeRenderedCursor;
Rect renderedCursorRect;
std::set<rdr::U32> pressedKeys;
time_t lastEventTime;
time_t pointerEventTime;
Point pointerEventPos;
AccessRights accessRights;
CharArray closeReason;
time_t startTime;
};
}
#endif
|