| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #include "qhttpserverstream_p.h" |
| 6 | |
| 7 | #include <QtNetwork/qtcpsocket.h> |
| 8 | |
| 9 | #if QT_CONFIG(ssl) |
| 10 | #include <QtNetwork/qsslsocket.h> |
| 11 | #endif |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | static QHttpServerParser initParserFromSocket(QIODevice *socket) |
| 16 | { |
| 17 | QTcpSocket *tcpSocket = qobject_cast<QTcpSocket *>(object: socket); |
| 18 | if (tcpSocket) { |
| 19 | return QHttpServerParser(tcpSocket->peerAddress(), tcpSocket->peerPort(), |
| 20 | tcpSocket->localAddress(), tcpSocket->localPort()); |
| 21 | } |
| 22 | return QHttpServerParser(QHostAddress::LocalHost, 0, QHostAddress::LocalHost, 0); |
| 23 | } |
| 24 | |
| 25 | #if QT_CONFIG(ssl) |
| 26 | static QSslConfiguration initSslConfigurationFromSocket(QIODevice *socket) |
| 27 | { |
| 28 | if (auto *ssl = qobject_cast<const QSslSocket *>(object: socket)) |
| 29 | return ssl->sslConfiguration(); |
| 30 | |
| 31 | return QSslConfiguration(); |
| 32 | } |
| 33 | #endif |
| 34 | |
| 35 | QHttpServerStream::QHttpServerStream(QIODevice *socket, QObject *parent) |
| 36 | : QObject(parent) |
| 37 | , parser(initParserFromSocket(socket)) |
| 38 | #if QT_CONFIG(ssl) |
| 39 | , sslConfiguration(initSslConfigurationFromSocket(socket)) |
| 40 | #endif |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | QT_END_NAMESPACE |
| 45 |
