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

krfb

  • sources
  • kde-4.14
  • 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 rfbClientPtr RfbClient::getRfbClientPtr()
107 {
108  return d->client;
109 }
110 
111 void RfbClient::handleKeyboardEvent(bool down, rfbKeySym keySym)
112 {
113  if (d->controlEnabled) {
114  EventHandler::handleKeyboard(down, keySym);
115  }
116 }
117 
118 void RfbClient::handleMouseEvent(int buttonMask, int x, int y)
119 {
120  if (d->controlEnabled) {
121  EventHandler::handlePointer(buttonMask, x, y);
122  }
123 }
124 
125 void RfbClient::onSocketActivated()
126 {
127  //Process not only one, but all pending messages.
128  //poll() idea/code copied from vino:
129  // Copyright (C) 2003 Sun Microsystems, Inc.
130  // License: GPL v2 or later
131  struct pollfd pollfd = { d->client->sock, POLLIN|POLLPRI, 0 };
132 
133  while(poll(&pollfd, 1, 0) == 1) {
134  rfbProcessClientMessage(d->client);
135 
136  //This is how we handle disconnection.
137  //if rfbProcessClientMessage() finds out that it can't read the socket,
138  //it closes it and sets it to -1. So, we just have to check this here
139  //and call rfbClientConnectionGone() if necessary. This will call
140  //the clientGoneHook which in turn will remove this RfbClient instance
141  //from the server manager and will call deleteLater() to delete it
142  if (d->client->sock == -1) {
143  kDebug() << "disconnected from socket signal";
144  d->notifier->setEnabled(false);
145  rfbClientConnectionGone(d->client);
146  break;
147  }
148  }
149 }
150 
151 void RfbClient::update()
152 {
153  rfbUpdateClient(d->client);
154 
155  //This is how we handle disconnection.
156  //if rfbUpdateClient() finds out that it can't write to the socket,
157  //it closes it and sets it to -1. So, we just have to check this here
158  //and call rfbClientConnectionGone() if necessary. This will call
159  //the clientGoneHook which in turn will remove this RfbClient instance
160  //from the server manager and will call deleteLater() to delete it
161  if (d->client->sock == -1) {
162  kDebug() << "disconnected during update";
163  d->notifier->setEnabled(false);
164  rfbClientConnectionGone(d->client);
165  }
166 }
167 
168 //*************
169 
170 PendingRfbClient::PendingRfbClient(rfbClientPtr client, QObject *parent)
171  : QObject(parent), m_rfbClient(client)
172 {
173  m_rfbClient->clientData = this;
174 }
175 
176 PendingRfbClient::~PendingRfbClient()
177 {}
178 
179 void PendingRfbClient::accept(RfbClient *newClient)
180 {
181  kDebug() << "accepted connection";
182 
183  m_rfbClient->clientData = newClient;
184  newClient->setOnHold(false);
185 
186  Q_EMIT finished(newClient);
187  deleteLater();
188 }
189 
190 static void clientGoneHookNoop(rfbClientPtr cl) { Q_UNUSED(cl); }
191 
192 void PendingRfbClient::reject()
193 {
194  kDebug() << "refused connection";
195 
196  //override the clientGoneHook that was previously set by RfbServer
197  m_rfbClient->clientGoneHook = clientGoneHookNoop;
198  rfbCloseClient(m_rfbClient);
199  rfbClientConnectionGone(m_rfbClient);
200 
201  Q_EMIT finished(NULL);
202  deleteLater();
203 }
204 
205 bool PendingRfbClient::checkPassword(const QByteArray & encryptedPassword)
206 {
207  Q_UNUSED(encryptedPassword);
208 
209  return m_rfbClient->screen->authPasswdData == (void*)0;
210 }
211 
212 bool PendingRfbClient::vncAuthCheckPassword(const QByteArray& password, const QByteArray& encryptedPassword) const
213 {
214  if (password.isEmpty() && encryptedPassword.isEmpty()) {
215  return true;
216  }
217 
218  char passwd[MAXPWLEN];
219  unsigned char challenge[CHALLENGESIZE];
220 
221  memcpy(challenge, m_rfbClient->authChallenge, CHALLENGESIZE);
222  bzero(passwd, MAXPWLEN);
223 
224  if (!password.isEmpty()) {
225  strncpy(passwd, password,
226  (MAXPWLEN <= password.size()) ? MAXPWLEN : password.size());
227  }
228 
229  rfbEncryptBytes(challenge, passwd);
230  return memcmp(challenge, encryptedPassword, encryptedPassword.size()) == 0;
231 }
232 
233 #include "rfbclient.moc"
RfbClient::getRfbClientPtr
rfbClientPtr getRfbClientPtr()
Definition: rfbclient.cpp:106
CHALLENGESIZE
#define CHALLENGESIZE
Definition: rfbproto.h:1423
RfbClient::controlEnabledChanged
void controlEnabledChanged(bool enabled)
QSocketNotifier
QByteArray
connectiondialog.h
PendingRfbClient::~PendingRfbClient
virtual ~PendingRfbClient()
Definition: rfbclient.cpp:176
RfbClient::setOnHold
void setOnHold(bool onHold)
Definition: rfbclient.cpp:90
_rfbClientRec::authChallenge
uint8_t authChallenge[CHALLENGESIZE]
Definition: libvncserver/rfb/rfb.h:466
MAXPWLEN
#define MAXPWLEN
Definition: rfbproto.h:1422
KrfbConfig
Definition: krfbconfig.h:9
RfbClient::handleKeyboardEvent
virtual void handleKeyboardEvent(bool down, rfbKeySym keySym)
Definition: rfbclient.cpp:111
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
QByteArray::isEmpty
bool isEmpty() const
peerPort
unsigned short peerPort(int sock)
Definition: sockethelpers.cpp:54
rfbKeySym
uint32_t rfbKeySym
Definition: rfbproto.h:109
_rfbClientRec::screen
rfbScreenInfoPtr screen
back pointer to the screen
Definition: libvncserver/rfb/rfb.h:420
RfbClient::onHold
bool onHold
Definition: krfb/rfbclient.h:30
PendingRfbClient::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:205
_rfbClientRec::sock
SOCKET sock
Definition: libvncserver/rfb/rfb.h:437
_rfbClientRec
Definition: libvncserver/rfb/rfb.h:417
QString::number
QString number(int n, int base)
EventHandler::handleKeyboard
static void handleKeyboard(bool down, rfbKeySym key)
Definition: events.cpp:144
peerAddress
QString peerAddress(int sock)
Definition: sockethelpers.cpp:29
PendingRfbClient::PendingRfbClient
PendingRfbClient(rfbClientPtr client, QObject *parent=0)
Definition: rfbclient.cpp:170
krfbconfig.h
RfbClient::holdStatusChanged
void holdStatusChanged(bool onHold)
QObject
RfbClient::controlCanBeEnabled
static bool controlCanBeEnabled()
Definition: rfbclient.cpp:67
events.h
PendingRfbClient::finished
void finished(RfbClient *client)
QObject::deleteLater
void deleteLater()
RfbClient::closeConnection
void closeConnection()
Definition: rfbclient.cpp:99
QString
rfbclient.h
PendingRfbClient::accept
void accept(RfbClient *newClient)
Definition: rfbclient.cpp:179
RfbClient::RfbClient
RfbClient(rfbClientPtr client, QObject *parent=0)
Definition: rfbclient.cpp:44
Phonon::BackendCapabilities::notifier
Notifier * notifier()
RfbClient
Definition: krfb/rfbclient.h:26
PendingRfbClient::reject
void reject()
Definition: rfbclient.cpp:192
RfbClient::~RfbClient
virtual ~RfbClient()
Definition: rfbclient.cpp:55
RfbClient::handleMouseEvent
virtual void handleMouseEvent(int buttonMask, int x, int y)
Definition: rfbclient.cpp:118
clientGoneHookNoop
static void clientGoneHookNoop(rfbClientPtr cl)
Definition: rfbclient.cpp:190
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: krfb/rfbclient.h:106
PendingRfbClient::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:212
_rfbClientRec::clientData
void * clientData
private data.
Definition: libvncserver/rfb/rfb.h:434
_rfbScreenInfo::authPasswdData
void * authPasswdData
Definition: libvncserver/rfb/rfb.h:288
RfbClient::controlEnabled
bool controlEnabled() const
QByteArray::size
int size() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:40 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
  • Namespace List
  • 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