mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:13:29 +02:00
add HTTPS versions of webserver classes
This commit is contained in:
parent
04f3e01a1b
commit
260966915a
10 changed files with 139 additions and 15 deletions
|
@ -31,11 +31,13 @@
|
||||||
|
|
||||||
#include "DomainServer.h"
|
#include "DomainServer.h"
|
||||||
|
|
||||||
const quint16 DOMAIN_SERVER_HTTP_PORT = 8080;
|
const quint16 DOMAIN_SERVER_HTTP_PORT = 40100;
|
||||||
|
const quint16 DOMAIN_SERVER_HTTPS_PORT = 40101;
|
||||||
|
|
||||||
DomainServer::DomainServer(int argc, char* argv[]) :
|
DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
QCoreApplication(argc, argv),
|
QCoreApplication(argc, argv),
|
||||||
_HTTPManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this),
|
_httpManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this),
|
||||||
|
_httpsManager(NULL),
|
||||||
_staticAssignmentHash(),
|
_staticAssignmentHash(),
|
||||||
_assignmentQueue(),
|
_assignmentQueue(),
|
||||||
_isUsingDTLS(false),
|
_isUsingDTLS(false),
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <Assignment.h>
|
#include <Assignment.h>
|
||||||
#include <HTTPManager.h>
|
#include <HTTPManager.h>
|
||||||
|
#include <HTTPSManager.h>
|
||||||
#include <LimitedNodeList.h>
|
#include <LimitedNodeList.h>
|
||||||
|
|
||||||
#include "DTLSServerSession.h"
|
#include "DTLSServerSession.h"
|
||||||
|
@ -79,7 +80,8 @@ private:
|
||||||
QJsonObject jsonForSocket(const HifiSockAddr& socket);
|
QJsonObject jsonForSocket(const HifiSockAddr& socket);
|
||||||
QJsonObject jsonObjectForNode(const SharedNodePointer& node);
|
QJsonObject jsonObjectForNode(const SharedNodePointer& node);
|
||||||
|
|
||||||
HTTPManager _HTTPManager;
|
HTTPManager _httpManager;
|
||||||
|
HTTPSManager* _httpsManager;
|
||||||
|
|
||||||
QHash<QUuid, SharedAssignmentPointer> _staticAssignmentHash;
|
QHash<QUuid, SharedAssignmentPointer> _staticAssignmentHash;
|
||||||
QQueue<SharedAssignmentPointer> _assignmentQueue;
|
QQueue<SharedAssignmentPointer> _assignmentQueue;
|
||||||
|
|
|
@ -28,8 +28,8 @@ HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager)
|
||||||
_parentManager(parentManager),
|
_parentManager(parentManager),
|
||||||
_socket(socket),
|
_socket(socket),
|
||||||
_stream(socket),
|
_stream(socket),
|
||||||
_address(socket->peerAddress()) {
|
_address(socket->peerAddress())
|
||||||
|
{
|
||||||
// take over ownership of the socket
|
// take over ownership of the socket
|
||||||
_socket->setParent(this);
|
_socket->setParent(this);
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
|
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QHostAddress>
|
#include <QtNetwork/QHostAddress>
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QNetworkAccessManager>
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
|
@ -138,14 +138,14 @@ HTTPManager::HTTPManager(quint16 port, const QString& documentRoot, HTTPRequestH
|
||||||
qDebug() << "Failed to open HTTP server socket:" << errorString();
|
qDebug() << "Failed to open HTTP server socket:" << errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect the connection signal
|
|
||||||
connect(this, SIGNAL(newConnection()), SLOT(acceptConnections()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPManager::acceptConnections() {
|
void HTTPManager::incomingConnection(qintptr socketDescriptor) {
|
||||||
QTcpSocket* socket;
|
QTcpSocket* socket = new QTcpSocket(this);
|
||||||
while ((socket = nextPendingConnection()) != 0) {
|
|
||||||
|
if (socket->setSocketDescriptor(socketDescriptor)) {
|
||||||
new HTTPConnection(socket, this);
|
new HTTPConnection(socket, this);
|
||||||
|
} else {
|
||||||
|
delete socket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,9 @@ public:
|
||||||
|
|
||||||
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url);
|
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url);
|
||||||
|
|
||||||
protected slots:
|
protected:
|
||||||
/// Accepts all pending connections
|
/// Accepts all pending connections
|
||||||
void acceptConnections();
|
virtual void incomingConnection(qintptr socketDescriptor);
|
||||||
protected:
|
protected:
|
||||||
QString _documentRoot;
|
QString _documentRoot;
|
||||||
HTTPRequestHandler* _requestHandler;
|
HTTPRequestHandler* _requestHandler;
|
||||||
|
|
23
libraries/embedded-webserver/src/HTTPSConnection.cpp
Normal file
23
libraries/embedded-webserver/src/HTTPSConnection.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
//
|
||||||
|
// HTTPSConnection.cpp
|
||||||
|
// libraries/embedded-webserver/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-04-24.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "HTTPSConnection.h"
|
||||||
|
|
||||||
|
HTTPSConnection::HTTPSConnection(QSslSocket* sslSocket, HTTPSManager* parentManager) :
|
||||||
|
HTTPConnection(sslSocket, parentManager)
|
||||||
|
{
|
||||||
|
connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(sslErrors(const QList<QSslError>&)));
|
||||||
|
sslSocket->startServerEncryption();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTTPSConnection::handleSSLErrors(const QList<QSslError>& errors) {
|
||||||
|
qDebug() << "SSL errors:" << errors;
|
||||||
|
}
|
26
libraries/embedded-webserver/src/HTTPSConnection.h
Normal file
26
libraries/embedded-webserver/src/HTTPSConnection.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
//
|
||||||
|
// HTTPSConnection.h
|
||||||
|
// libraries/embedded-webserver/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-04-24.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_HTTPSConnection_h
|
||||||
|
#define hifi_HTTPSConnection_h
|
||||||
|
|
||||||
|
#include "HTTPConnection.h"
|
||||||
|
#include "HTTPSManager.h"
|
||||||
|
|
||||||
|
class HTTPSConnection : public HTTPConnection {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
HTTPSConnection(QSslSocket* sslSocket, HTTPSManager* parentManager);
|
||||||
|
protected slots:
|
||||||
|
void handleSSLErrors(const QList<QSslError>& errors);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_HTTPSConnection_h
|
34
libraries/embedded-webserver/src/HTTPSManager.cpp
Normal file
34
libraries/embedded-webserver/src/HTTPSManager.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
//
|
||||||
|
// HTTPSManager.cpp
|
||||||
|
// libraries/embedded-webserver/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-04-24.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <QtNetwork/QSslSocket>
|
||||||
|
|
||||||
|
#include "HTTPSConnection.h"
|
||||||
|
|
||||||
|
#include "HTTPSManager.h"
|
||||||
|
|
||||||
|
HTTPSManager::HTTPSManager(quint16 port, const QString& documentRoot, HTTPRequestHandler* requestHandler, QObject* parent) :
|
||||||
|
HTTPManager(port, documentRoot, requestHandler, parent),
|
||||||
|
_certificate(),
|
||||||
|
_privateKey()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTTPSManager::incomingConnection(qintptr socketDescriptor) {
|
||||||
|
QSslSocket* sslSocket = new QSslSocket(this);
|
||||||
|
|
||||||
|
if (sslSocket->setSocketDescriptor(socketDescriptor)) {
|
||||||
|
new HTTPSConnection(sslSocket, this);
|
||||||
|
} else {
|
||||||
|
delete sslSocket;
|
||||||
|
}
|
||||||
|
}
|
37
libraries/embedded-webserver/src/HTTPSManager.h
Normal file
37
libraries/embedded-webserver/src/HTTPSManager.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
//
|
||||||
|
// HTTPSManager.h
|
||||||
|
// libraries/embedded-webserver/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-04-24.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_HTTPSManager_h
|
||||||
|
#define hifi_HTTPSManager_h
|
||||||
|
|
||||||
|
#include <QtNetwork/QSslKey>
|
||||||
|
#include <QtNetwork/QSslCertificate>
|
||||||
|
|
||||||
|
#include "HTTPManager.h"
|
||||||
|
|
||||||
|
class HTTPSManager : public HTTPManager {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
HTTPSManager(quint16 port,
|
||||||
|
const QString& documentRoot,
|
||||||
|
HTTPRequestHandler* requestHandler = NULL, QObject* parent = 0);
|
||||||
|
|
||||||
|
void setCertificate(const QSslCertificate& certificate) { _certificate = certificate; }
|
||||||
|
void setPrivateKey(const QSslKey& privateKey) { _privateKey = privateKey; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void incomingConnection(qintptr socketDescriptor);
|
||||||
|
private:
|
||||||
|
QSslCertificate _certificate;
|
||||||
|
QSslKey _privateKey;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_HTTPSManager_h
|
Loading…
Reference in a new issue