2015-07-05 14:23:53 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2015 Vineet Garg <grg.vineet@gmail.com>
|
2015-07-05 14:23:53 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2015-07-05 14:23:53 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "server.h"
|
|
|
|
|
|
|
|
#include "kdeconnectconfig.h"
|
|
|
|
#include "lanlinkprovider.h"
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QSslError>
|
2015-07-05 14:23:53 +01:00
|
|
|
#include <QSslKey>
|
|
|
|
#include <QSslSocket>
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
Server::Server(QObject *parent)
|
|
|
|
: QTcpServer(parent)
|
2015-07-05 14:23:53 +01:00
|
|
|
{
|
2016-07-04 18:34:28 +01:00
|
|
|
connect(this, &QTcpServer::acceptError, this, &Server::errorFound);
|
2015-07-05 14:23:53 +01:00
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void Server::incomingConnection(qintptr socketDescriptor)
|
|
|
|
{
|
|
|
|
QSslSocket *serverSocket = new QSslSocket(parent());
|
2015-07-05 14:23:53 +01:00
|
|
|
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
|
2020-04-06 01:38:19 +01:00
|
|
|
QObject::connect(this, &Server::closed, serverSocket, &QSslSocket::abort);
|
2018-11-19 11:08:02 +00:00
|
|
|
addPendingConnection(serverSocket);
|
2015-07-05 14:23:53 +01:00
|
|
|
} else {
|
2019-06-10 15:40:28 +01:00
|
|
|
qWarning() << "setSocketDescriptor failed" << serverSocket->errorString();
|
2015-07-05 14:23:53 +01:00
|
|
|
delete serverSocket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QSslSocket *Server::nextPendingConnection()
|
|
|
|
{
|
2018-11-19 11:08:02 +00:00
|
|
|
return qobject_cast<QSslSocket *>(QTcpServer::nextPendingConnection());
|
2015-07-09 23:27:27 +01:00
|
|
|
}
|
2016-07-04 18:34:28 +01:00
|
|
|
|
|
|
|
void Server::errorFound(QAbstractSocket::SocketError socketError)
|
|
|
|
{
|
|
|
|
qDebug() << "error:" << socketError;
|
|
|
|
}
|
2020-04-06 01:38:19 +01:00
|
|
|
|
|
|
|
void Server::close()
|
|
|
|
{
|
|
|
|
QTcpServer::close();
|
|
|
|
Q_EMIT closed();
|
|
|
|
}
|
2023-07-26 09:15:11 +01:00
|
|
|
|
|
|
|
#include "moc_server.cpp"
|