• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

krfb

  • sources
  • kde-4.12
  • kdenetwork
  • krfb
  • krfb
rfbclient.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009-2010 Collabora Ltd <info@collabora.co.uk>
3  @author George Goldberg <george.goldberg@collabora.co.uk>
4  @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
5  Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #include "rfbclient.h"
21 #include "connectiondialog.h"
22 #include "krfbconfig.h"
23 #include "sockethelpers.h"
24 #include "events.h"
25 #include <QtCore/QSocketNotifier>
26 #include <KDebug>
27 #include <KNotification>
28 #include <poll.h>
29 #include <strings.h> //for bzero()
30 
31 struct RfbClient::Private
32 {
33  Private(rfbClientPtr client) :
34  controlEnabled(KrfbConfig::allowDesktopControl()),
35  client(client)
36  {}
37 
38  bool controlEnabled;
39  rfbClientPtr client;
40  QSocketNotifier *notifier;
41  QString remoteAddressString;
42 };
43 
44 RfbClient::RfbClient(rfbClientPtr client, QObject* parent)
45  : QObject(parent), d(new Private(client))
46 {
47  d->remoteAddressString = peerAddress(d->client->sock) + ":" +
48  QString::number(peerPort(d->client->sock));
49 
50  d->notifier = new QSocketNotifier(client->sock, QSocketNotifier::Read, this);
51  d->notifier->setEnabled(false);
52  connect(d->notifier, SIGNAL(activated(int)), this, SLOT(onSocketActivated()));
53 }
54 
55 RfbClient::~RfbClient()
56 {
57  kDebug();
58  delete d;
59 }
60 
61 QString RfbClient::name() const
62 {
63  return d->remoteAddressString;
64 }
65 
66 //static
67 bool RfbClient::controlCanBeEnabled()
68 {
69  return KrfbConfig::allowDesktopControl();
70 }
71 
72 bool RfbClient::controlEnabled() const
73 {
74  return d->controlEnabled;
75 }
76 
77 void RfbClient::setControlEnabled(bool enabled)
78 {
79  if (controlCanBeEnabled() && d->controlEnabled != enabled) {
80  d->controlEnabled = enabled;
81  Q_EMIT controlEnabledChanged(enabled);
82  }
83 }
84 
85 bool RfbClient::isOnHold() const
86 {
87  return d->client->onHold ? true : false;
88 }
89 
90 void RfbClient::setOnHold(bool onHold)
91 {
92  if (isOnHold() != onHold) {
93  d->client->onHold = onHold;
94  d->notifier->setEnabled(!onHold);
95  Q_EMIT holdStatusChanged(onHold);
96  }
97 }
98 
99 void RfbClient::closeConnection()
100 {
101  d->notifier->setEnabled(false);
102  rfbCloseClient(d->client);
103  rfbClientConnectionGone(d->client);
104 }
105 
106 void RfbClient::handleKeyboardEvent(bool down, rfbKeySym keySym)
107 {
108  if (d->controlEnabled) {
109  EventHandler::handleKeyboard(down, keySym);
110  }
111 }
112 
113 void RfbClient::handleMouseEvent(int buttonMask, int x, int y)
114 {
115  if (d->controlEnabled) {
116  EventHandler::handlePointer(buttonMask, x, y);
117  }
118 }
119 
120 bool RfbClient::checkPassword(const QByteArray & encryptedPassword)
121 {
122  Q_UNUSED(encryptedPassword);
123 
124  return d->client->screen->authPasswdData == (void*)0;
125 }
126 
127 bool RfbClient::vncAuthCheckPassword(const QByteArray& password, const QByteArray& encryptedPassword) const
128 {
129  if (password.isEmpty() && encryptedPassword.isEmpty()) {
130  return true;
131  }
132 
133  char passwd[MAXPWLEN];
134  unsigned char challenge[CHALLENGESIZE];
135 
136  memcpy(challenge, d->client->authChallenge, CHALLENGESIZE);
137  bzero(passwd, MAXPWLEN);
138 
139  if (!password.isEmpty()) {
140  strncpy(passwd, password,
141  (MAXPWLEN <= password.size()) ? MAXPWLEN : password.size());
142  }
143 
144  rfbEncryptBytes(challenge, passwd);
145  return memcmp(challenge, encryptedPassword, encryptedPassword.size()) == 0;
146 }
147 
148 void RfbClient::onSocketActivated()
149 {
150  //Process not only one, but all pending messages.
151  //poll() idea/code copied from vino:
152  // Copyright (C) 2003 Sun Microsystems, Inc.
153  // License: GPL v2 or later
154  struct pollfd pollfd = { d->client->sock, POLLIN|POLLPRI, 0 };
155 
156  while(poll(&pollfd, 1, 0) == 1) {
157  rfbProcessClientMessage(d->client);
158 
159  //This is how we handle disconnection.
160  //if rfbProcessClientMessage() finds out that it can't read the socket,
161  //it closes it and sets it to -1. So, we just have to check this here
162  //and call rfbClientConnectionGone() if necessary. This will call
163  //the clientGoneHook which in turn will remove this RfbClient instance
164  //from the server manager and will call deleteLater() to delete it
165  if (d->client->sock == -1) {
166  kDebug() << "disconnected from socket signal";
167  d->notifier->setEnabled(false);
168  rfbClientConnectionGone(d->client);
169  break;
170  }
171  }
172 }
173 
174 void RfbClient::update()
175 {
176  rfbUpdateClient(d->client);
177 
178  //This is how we handle disconnection.
179  //if rfbUpdateClient() finds out that it can't write to the socket,
180  //it closes it and sets it to -1. So, we just have to check this here
181  //and call rfbClientConnectionGone() if necessary. This will call
182  //the clientGoneHook which in turn will remove this RfbClient instance
183  //from the server manager and will call deleteLater() to delete it
184  if (d->client->sock == -1) {
185  kDebug() << "disconnected during update";
186  d->notifier->setEnabled(false);
187  rfbClientConnectionGone(d->client);
188  }
189 }
190 
191 //*************
192 
193 PendingRfbClient::PendingRfbClient(rfbClientPtr client, QObject *parent)
194  : QObject(parent), m_rfbClient(client)
195 {
196  kDebug();
197  QMetaObject::invokeMethod(this, "processNewClient", Qt::QueuedConnection);
198 }
199 
200 PendingRfbClient::~PendingRfbClient()
201 {
202  kDebug();
203 }
204 
205 void PendingRfbClient::accept(RfbClient *newClient)
206 {
207  kDebug() << "accepted connection";
208 
209  m_rfbClient->clientData = newClient;
210  newClient->setOnHold(false);
211 
212  Q_EMIT finished(newClient);
213  deleteLater();
214 }
215 
216 static void clientGoneHookNoop(rfbClientPtr cl) { Q_UNUSED(cl); }
217 
218 void PendingRfbClient::reject()
219 {
220  kDebug() << "refused connection";
221 
222  //override the clientGoneHook that was previously set by RfbServer
223  m_rfbClient->clientGoneHook = clientGoneHookNoop;
224  rfbCloseClient(m_rfbClient);
225  rfbClientConnectionGone(m_rfbClient);
226 
227  Q_EMIT finished(NULL);
228  deleteLater();
229 }
230 
231 
232 #include "rfbclient.moc"
CHALLENGESIZE
#define CHALLENGESIZE
Definition: rfbproto.h:1423
RfbClient::controlEnabledChanged
void controlEnabledChanged(bool enabled)
connectiondialog.h
PendingRfbClient::~PendingRfbClient
virtual ~PendingRfbClient()
Definition: rfbclient.cpp:200
RfbClient::setOnHold
void setOnHold(bool onHold)
Definition: rfbclient.cpp:90
MAXPWLEN
#define MAXPWLEN
Definition: rfbproto.h:1422
KrfbConfig
Definition: krfbconfig.h:9
RfbClient::handleKeyboardEvent
virtual void handleKeyboardEvent(bool down, rfbKeySym keySym)
Definition: rfbclient.cpp:106
KrfbConfig::allowDesktopControl
static bool allowDesktopControl()
Get Allow remote connections to manage the desktop.
Definition: krfbconfig.h:51
RfbClient::isOnHold
bool isOnHold() const
Definition: rfbclient.cpp:85
peerPort
unsigned short peerPort(int sock)
Definition: sockethelpers.cpp:54
QObject
rfbKeySym
uint32_t rfbKeySym
Definition: rfbproto.h:109
RfbClient::onHold
bool onHold
Definition: krfb/rfbclient.h:30
_rfbClientRec::sock
SOCKET sock
Definition: libvncserver/rfb/rfb.h:437
_rfbClientRec
Definition: libvncserver/rfb/rfb.h:417
EventHandler::handleKeyboard
static void handleKeyboard(bool down, rfbKeySym key)
Definition: events.cpp:144
RfbClient::checkPassword
virtual bool checkPassword(const QByteArray &encryptedPassword)
This method is supposed to check if the provided encryptedPassword matches the criteria for authentic...
Definition: rfbclient.cpp:120
peerAddress
QString peerAddress(int sock)
Definition: sockethelpers.cpp:29
PendingRfbClient::PendingRfbClient
PendingRfbClient(rfbClientPtr client, QObject *parent=0)
Definition: pendingrfbclient.cpp:24
krfbconfig.h
RfbClient::holdStatusChanged
void holdStatusChanged(bool onHold)
RfbClient::controlCanBeEnabled
static bool controlCanBeEnabled()
Definition: rfbclient.cpp:67
events.h
PendingRfbClient::finished
void finished(RfbClient *client)
RfbClient::closeConnection
void closeConnection()
Definition: rfbclient.cpp:99
rfbclient.h
RfbClient::RfbClient
RfbClient(rfbClientPtr client, QObject *parent=0)
Definition: rfbclient.cpp:44
PendingRfbClient::accept
void accept()
Definition: pendingrfbclient.cpp:30
RfbClient::vncAuthCheckPassword
bool vncAuthCheckPassword(const QByteArray &password, const QByteArray &encryptedPassword) const
This method checks if the encryptedPassword that was sent from the remote user matches the password t...
Definition: rfbclient.cpp:127
RfbClient
Definition: krfb/rfbclient.h:26
PendingRfbClient::reject
void reject()
Definition: pendingrfbclient.cpp:40
RfbClient::~RfbClient
virtual ~RfbClient()
Definition: rfbclient.cpp:55
RfbClient::handleMouseEvent
virtual void handleMouseEvent(int buttonMask, int x, int y)
Definition: rfbclient.cpp:113
clientGoneHookNoop
static void clientGoneHookNoop(rfbClientPtr cl)
Definition: rfbclient.cpp:216
rfbProcessClientMessage
void rfbProcessClientMessage(rfbClientPtr cl)
_rfbClientRec::clientGoneHook
ClientGoneHookPtr clientGoneHook
Definition: libvncserver/rfb/rfb.h:435
RfbClient::name
virtual QString name() const
Returns a name for the client, to be shown to the user.
Definition: rfbclient.cpp:61
rfbUpdateClient
rfbBool rfbUpdateClient(rfbClientPtr cl)
PendingRfbClient::m_rfbClient
rfbClientPtr m_rfbClient
Definition: pendingrfbclient.h:43
_rfbClientRec::clientData
void * clientData
private data.
Definition: libvncserver/rfb/rfb.h:434
RfbClient::controlEnabled
bool controlEnabled() const
EventHandler::handlePointer
static void handlePointer(int buttonMask, int x, int y)
Definition: events.cpp:178
sockethelpers.h
rfbEncryptBytes
void rfbEncryptBytes(unsigned char *bytes, char *passwd)
RfbClient::setControlEnabled
void setControlEnabled(bool enabled)
Definition: rfbclient.cpp:77
rfbClientConnectionGone
void rfbClientConnectionGone(rfbClientPtr cl)
rfbCloseClient
void rfbCloseClient(rfbClientPtr cl)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krfb

Skip menu "krfb"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal