Commit c671fc90 authored by Daniel O'Neill's avatar Daniel O'Neill Committed by Alberto Mardegan
Browse files

VncClient: basic password authentication support

parent 7f21b0d6
......@@ -5,7 +5,7 @@ import QtQuick.Layouts 1.3
Page {
id: root
signal connectionRequested(string host)
signal connectionRequested(string host, string password)
title: qsTr("VNC Client")
......@@ -26,10 +26,19 @@ Page {
onAccepted: activate()
function activate() {
root.connectionRequested(text)
root.connectionRequested(text, passwordField.text)
}
}
TextFieldWithContextMenu {
id: passwordField
Layout.fillWidth: true
placeholderText: qsTr("Password (optional)")
echoMode: TextInput.PasswordEchoOnEdit
selectByMouse: true
onAccepted: urlField.activate();
}
Button {
Layout.alignment: Qt.AlignHCenter
text: qsTr("Connect")
......
......@@ -22,7 +22,7 @@ ApplicationWindow {
id: mainPageComponent
MainPage {
onConnectionRequested: {
vncClient.connectToServer(host);
vncClient.connectToServer(host, password);
}
}
}
......
......@@ -48,6 +48,7 @@ public:
static void vncError(const char *format, ...);
static void gotFrameBufferUpdate(rfbClient *cl,
int x, int y, int w, int h);
static char *GetPassword(rfbClient *cl);
static rfbBool mallocFrameBuffer(rfbClient* client);
static int qtToRfb(Qt::MouseButtons buttons);
......@@ -56,8 +57,9 @@ public:
void onUpdate(int x, int y, int w, int h);
void onResize();
char *getPassword();
bool connectToServer(const QString &host);
bool connectToServer(const QString &host, const QString &password);
void disconnect();
void onSocketActivated();
......@@ -72,6 +74,7 @@ private:
int m_bytesPerPixel;
QImage m_image;
QList<QQuickItem*> m_viewers;
QString m_password;
rfbClient *m_client;
VncClient *q_ptr;
};
......@@ -124,6 +127,12 @@ void VncClientPrivate::gotFrameBufferUpdate(rfbClient *client,
static_cast<VncClientPrivate*>(ptr)->onUpdate(x, y, w, h);
}
char *VncClientPrivate::GetPassword(rfbClient *client)
{
void *ptr = rfbClientGetClientData(client, dataTag());
return static_cast<VncClientPrivate*>(ptr)->getPassword();
}
rfbBool VncClientPrivate::mallocFrameBuffer(rfbClient* client)
{
void *ptr = rfbClientGetClientData(client, dataTag());
......@@ -271,7 +280,12 @@ void VncClientPrivate::onResize()
}
}
bool VncClientPrivate::connectToServer(const QString &host)
char *VncClientPrivate::getPassword()
{
return strdup(m_password.toUtf8().constData());
}
bool VncClientPrivate::connectToServer(const QString &host, const QString &password)
{
Q_Q(VncClient);
......@@ -279,9 +293,12 @@ bool VncClientPrivate::connectToServer(const QString &host)
disconnect();
}
m_password = QString(password);
m_client = rfbGetClient(8, 3, m_bytesPerPixel);
m_client->MallocFrameBuffer = mallocFrameBuffer;
m_client->GotFrameBufferUpdate = gotFrameBufferUpdate;
m_client->GetPassword = GetPassword;
rfbClientSetClientData(m_client, dataTag(), this);
QByteArrayList arguments = {
......@@ -397,10 +414,10 @@ const QImage &VncClient::image() const
return d->m_image;
}
bool VncClient::connectToServer(const QString &host)
bool VncClient::connectToServer(const QString &host, const QString &password)
{
Q_D(VncClient);
return d->connectToServer(host);
return d->connectToServer(host, password);
}
void VncClient::disconnect()
......
......@@ -46,7 +46,7 @@ public:
void removeViewer(QQuickItem *viewer);
const QImage &image() const;
Q_INVOKABLE bool connectToServer(const QString &host);
Q_INVOKABLE bool connectToServer(const QString &host, const QString &password);
Q_INVOKABLE void disconnect();
void sendKeyEvent(QChar c);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment