• 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
invitationsrfbclient.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  Copyright (C) 2001-2003 by Tim Jansen <tim@tjansen.de>
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include "rfb.h"
22 #include "invitationsrfbclient.h"
23 #include "invitationsrfbserver.h"
24 #include "krfbconfig.h"
25 #include "sockethelpers.h"
26 #include "connectiondialog.h"
27 #include <KNotification>
28 #include <KLocale>
29 #include <QtCore/QSocketNotifier>
30 #include <poll.h>
31 
32 struct PendingInvitationsRfbClient::Private
33 {
34  Private(rfbClientPtr client) :
35  client(client),
36  askOnConnect(true)
37  {}
38 
39  rfbClientPtr client;
40  QSocketNotifier *notifier;
41  bool askOnConnect;
42 };
43 
44 static void clientGoneHookNoop(rfbClientPtr cl) { Q_UNUSED(cl); }
45 
46 PendingInvitationsRfbClient::PendingInvitationsRfbClient(rfbClientPtr client, QObject *parent) :
47  PendingRfbClient(client, parent),
48  d(new Private(client))
49 {
50  d->client->clientGoneHook = clientGoneHookNoop;
51  d->notifier = new QSocketNotifier(client->sock, QSocketNotifier::Read, this);
52  d->notifier->setEnabled(true);
53  connect(d->notifier, SIGNAL(activated(int)),
54  this, SLOT(onSocketActivated()));
55 }
56 
57 PendingInvitationsRfbClient::~PendingInvitationsRfbClient()
58 {
59  delete d;
60 }
61 
62 void PendingInvitationsRfbClient::processNewClient()
63 {
64  QString host = peerAddress(m_rfbClient->sock) + ":" + QString::number(peerPort(m_rfbClient->sock));
65 
66  if (d->askOnConnect == false) {
67 
68  KNotification::event("NewConnectionAutoAccepted",
69  i18n("Accepted connection from %1", host));
70  accept(new InvitationsRfbClient(m_rfbClient, parent()));
71 
72  } else {
73 
74  KNotification::event("NewConnectionOnHold",
75  i18n("Received connection from %1, on hold (waiting for confirmation)",
76  host));
77 
78  InvitationsConnectionDialog *dialog = new InvitationsConnectionDialog(0);
79  dialog->setRemoteHost(host);
80  dialog->setAllowRemoteControl(KrfbConfig::allowDesktopControl());
81 
82  connect(dialog, SIGNAL(okClicked()), SLOT(dialogAccepted()));
83  connect(dialog, SIGNAL(cancelClicked()), SLOT(reject()));
84 
85  dialog->show();
86  }
87 }
88 
89 void PendingInvitationsRfbClient::onSocketActivated()
90 {
91  //Process not only one, but all pending messages.
92  //poll() idea/code copied from vino:
93  // Copyright (C) 2003 Sun Microsystems, Inc.
94  // License: GPL v2 or later
95  struct pollfd pollfd = { d->client->sock, POLLIN|POLLPRI, 0 };
96 
97  while(poll(&pollfd, 1, 0) == 1) {
98 
99  if(d->client->state == rfbClientRec::RFB_INITIALISATION) {
100  d->notifier->setEnabled(false);
101  //Client is Authenticated
102  processNewClient();
103  break;
104  }
105  rfbProcessClientMessage(d->client);
106 
107  //This is how we handle disconnection.
108  //if rfbProcessClientMessage() finds out that it can't read the socket,
109  //it closes it and sets it to -1. So, we just have to check this here
110  //and call rfbClientConnectionGone() if necessary. This will call
111  //the clientGoneHook which in turn will remove this RfbClient instance
112  //from the server manager and will call deleteLater() to delete it
113  if (d->client->sock == -1) {
114  kDebug() << "disconnected from socket signal";
115  d->notifier->setEnabled(false);
116  rfbClientConnectionGone(d->client);
117  break;
118  }
119  }
120 }
121 
122 bool PendingInvitationsRfbClient::checkPassword(const QByteArray & encryptedPassword)
123 {
124  QByteArray password ;
125  kDebug() << "about to start autentication";
126 
127  if(InvitationsRfbServer::instance->allowUnattendedAccess() && vncAuthCheckPassword(
128  InvitationsRfbServer::instance->unattendedPassword().toLocal8Bit(),
129  encryptedPassword) ) {
130  d->askOnConnect = false;
131  return true;
132  }
133 
134  return vncAuthCheckPassword(
135  InvitationsRfbServer::instance->desktopPassword().toLocal8Bit(),
136  encryptedPassword);
137 }
138 
139 void PendingInvitationsRfbClient::dialogAccepted()
140 {
141  InvitationsConnectionDialog *dialog = qobject_cast<InvitationsConnectionDialog *>(sender());
142  Q_ASSERT(dialog);
143 
144  InvitationsRfbClient *client = new InvitationsRfbClient(m_rfbClient, parent());
145  client->setControlEnabled(dialog->allowRemoteControl());
146  accept(client);
147 }
148 
149 #include "invitationsrfbclient.moc"
QSocketNotifier
QByteArray
connectiondialog.h
QObject::sender
QObject * sender() const
KrfbConfig::allowDesktopControl
static bool allowDesktopControl()
Get Allow remote connections to manage the desktop.
Definition: krfbconfig.h:51
ConnectionDialog::allowRemoteControl
bool allowRemoteControl()
Definition: connectiondialog.h:51
_rfbClientRec::RFB_INITIALISATION
sending initialisation messages
Definition: libvncserver/rfb/rfb.h:452
InvitationsConnectionDialog::setRemoteHost
void setRemoteHost(const QString &host)
Definition: connectiondialog.cpp:65
peerPort
unsigned short peerPort(int sock)
Definition: sockethelpers.cpp:54
ConnectionDialog::setAllowRemoteControl
void setAllowRemoteControl(bool b)
Definition: connectiondialog.h:44
_rfbClientRec::sock
SOCKET sock
Definition: libvncserver/rfb/rfb.h:437
_rfbClientRec
Definition: libvncserver/rfb/rfb.h:417
InvitationsRfbClient
Definition: invitationsrfbclient.h:23
QString::number
QString number(int n, int base)
peerAddress
QString peerAddress(int sock)
Definition: sockethelpers.cpp:29
krfbconfig.h
QObject
InvitationsConnectionDialog
Definition: connectiondialog.h:58
PendingInvitationsRfbClient::PendingInvitationsRfbClient
PendingInvitationsRfbClient(rfbClientPtr client, QObject *parent=0)
Definition: invitationsrfbclient.cpp:46
QString
PendingRfbClient::accept
void accept(RfbClient *newClient)
Definition: rfbclient.cpp:179
invitationsrfbclient.h
rfb.h
clientGoneHookNoop
static void clientGoneHookNoop(rfbClientPtr cl)
Definition: invitationsrfbclient.cpp:44
PendingInvitationsRfbClient::checkPassword
virtual bool checkPassword(const QByteArray &encryptedPassword)
Definition: invitationsrfbclient.cpp:122
PendingInvitationsRfbClient::~PendingInvitationsRfbClient
virtual ~PendingInvitationsRfbClient()
Definition: invitationsrfbclient.cpp:57
Phonon::BackendCapabilities::notifier
Notifier * notifier()
InvitationsRfbServer::instance
static InvitationsRfbServer * instance
Definition: invitationsrfbserver.h:37
PendingRfbClient::reject
void reject()
Definition: rfbclient.cpp:192
rfbProcessClientMessage
void rfbProcessClientMessage(rfbClientPtr cl)
invitationsrfbserver.h
PendingRfbClient::m_rfbClient
rfbClientPtr m_rfbClient
Definition: krfb/rfbclient.h:106
PendingRfbClient
Definition: krfb/rfbclient.h:72
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
PendingInvitationsRfbClient::onSocketActivated
virtual void onSocketActivated()
Definition: invitationsrfbclient.cpp:89
PendingInvitationsRfbClient::processNewClient
virtual void processNewClient()
Definition: invitationsrfbclient.cpp:62
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
sockethelpers.h
RfbClient::setControlEnabled
void setControlEnabled(bool enabled)
Definition: rfbclient.cpp:77
rfbClientConnectionGone
void rfbClientConnectionGone(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