summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/clientcertificate/server.cpp
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2024-04-15 17:16:04 +0300
committerTarja Sundqvist <tarja.sundqvist@qt.io>2024-04-15 17:16:04 +0300
commitfa4781b6691eff0d9eb2e9c8e536e9c09a23f054 (patch)
tree416b3b3d0fdb89d19f951fae4b7ed779c0c32416 /examples/webenginewidgets/clientcertificate/server.cpp
parent81047475209d3b78a06ec694f5d2aed9b325fe45 (diff)
parent43cd26bfcd78f0b38f286f108ad7a04374695fce (diff)
Merge branch 'tqtc/lts-6.2.8' into 6.2.86.2.8
Diffstat (limited to 'examples/webenginewidgets/clientcertificate/server.cpp')
-rw-r--r--examples/webenginewidgets/clientcertificate/server.cpp99
1 files changed, 0 insertions, 99 deletions
diff --git a/examples/webenginewidgets/clientcertificate/server.cpp b/examples/webenginewidgets/clientcertificate/server.cpp
deleted file mode 100644
index ee83dab8a..000000000
--- a/examples/webenginewidgets/clientcertificate/server.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qpointer.h>
-#include <QtCore/qtimer.h>
-#include <QtNetwork/qsslconfiguration.h>
-#include <QtNetwork/qsslkey.h>
-#include <QtNetwork/qsslserver.h>
-
-struct Request : public QObject
-{
- QByteArray m_data;
-};
-
-static const QByteArray http_ok(QByteArrayLiteral(
- "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"));
-static const QByteArray html_start(QByteArrayLiteral("<html><style>"
- "div {"
- "height: 400px;"
- "width: 200px;"
- "position: fixed;"
- "top: 50%;"
- "left: 50%;"
- "margin-top: -100px;"
- "margin-left: -200px;"
- "}</style><body><div>"));
-static const QByteArray html_end(QByteArrayLiteral("</div></body></html>"));
-
-int main(int argc, char *argv[])
-{
- QCoreApplication::setOrganizationName("QtExamples");
- QCoreApplication app(argc, argv);
-
- QSslServer server;
- QSslConfiguration configuration(QSslConfiguration::defaultConfiguration());
- configuration.setPeerVerifyMode(QSslSocket::VerifyPeer);
-
- QFile keyFile(":/resources/server.key");
- keyFile.open(QIODevice::ReadOnly);
-
- QSslKey key(keyFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
- configuration.setPrivateKey(key);
-
- QList<QSslCertificate> localCerts = QSslCertificate::fromPath(":/resources/server.pem");
- configuration.setLocalCertificateChain(localCerts);
-
- QList<QSslCertificate> caCerts = QSslCertificate::fromPath(":resources/ca.pem");
- configuration.addCaCertificates(caCerts);
-
- server.setSslConfiguration(configuration);
-
- if (!server.listen(QHostAddress::LocalHost, 5555))
- qFatal("Could not start server on localhost:5555");
- else
- qInfo("Server started on localhost:5555");
-
- QObject::connect(&server, &QTcpServer::pendingConnectionAvailable, [&server]() {
- QTcpSocket *socket = server.nextPendingConnection();
- Q_ASSERT(socket);
-
- QPointer<Request> request(new Request);
-
- QObject::connect(socket, &QAbstractSocket::disconnected, socket,
- [socket, request]() mutable {
- delete request;
- socket->deleteLater();
- });
-
- QObject::connect(socket, &QTcpSocket::readyRead, socket, [socket, request]() mutable {
- request->m_data.append(socket->readAll());
-
- if (!request->m_data.endsWith("\r\n\r\n"))
- return;
-
- socket->write(http_ok);
- socket->write(html_start);
-
- if (request->m_data.startsWith("GET / ")) {
- socket->write("<p>ACCESS GRANTED !</p>");
- socket->write("<p>You reached the place, where no one has gone before.</p>");
- socket->write("<button onclick=\"window.location.href='/exit'\">Exit</button>");
- } else if (request->m_data.startsWith("GET /exit ")) {
- socket->write("<p>BYE !</p>");
- socket->write("<p>Have good day ...</p>");
- QTimer::singleShot(0, &QCoreApplication::quit);
- } else {
- socket->write("<p>There is nothing to see here.</p>");
- }
-
- socket->write(html_end);
- delete request;
- socket->disconnectFromHost();
- });
- });
-
- return app.exec();
-}