strawberry-audio-player-win.../src/internet/localredirectserver.h

73 lines
1.9 KiB
C
Raw Normal View History

2018-10-14 00:08:33 +02:00
/*
* This file was part of Clementine.
* Copyright 2012, 2014, John Maguire <john.maguire@gmail.com>
* Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-10-14 00:08:33 +02:00
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef LOCALREDIRECTSERVER_H
#define LOCALREDIRECTSERVER_H
2020-02-09 02:29:35 +01:00
#include <QtGlobal>
2018-10-14 00:08:33 +02:00
#include <QByteArray>
#include <QObject>
2020-02-09 02:29:35 +01:00
#include <QList>
#include <QString>
2018-10-14 00:08:33 +02:00
#include <QUrl>
2020-02-09 02:29:35 +01:00
#include <QTcpServer>
class QAbstractSocket;
2018-10-14 00:08:33 +02:00
class LocalRedirectServer : public QTcpServer {
2018-10-14 00:08:33 +02:00
Q_OBJECT
public:
explicit LocalRedirectServer(QObject *parent = nullptr);
2020-06-15 21:55:05 +02:00
~LocalRedirectServer() override;
2018-10-14 00:08:33 +02:00
void set_port(const int port) { port_ = port; }
bool Listen();
const QUrl &url() const { return url_; }
const QUrl &request_url() const { return request_url_; }
const QString &error() const { return error_; }
2018-10-14 00:08:33 +02:00
signals:
2019-04-16 17:48:11 +02:00
void Finished();
2018-10-14 00:08:33 +02:00
public slots:
2018-10-14 00:08:33 +02:00
void NewConnection();
2020-06-15 21:55:05 +02:00
void incomingConnection(qintptr socket_descriptor) override;
void Encrypted();
void Connected();
void Disconnected();
void ReadyRead();
2018-10-14 00:08:33 +02:00
private:
void WriteTemplate() const;
QUrl ParseUrlFromRequest(const QByteArray &request) const;
2018-10-14 00:08:33 +02:00
private:
int port_;
2018-10-14 00:08:33 +02:00
QUrl url_;
QUrl request_url_;
QAbstractSocket *socket_;
QByteArray buffer_;
QString error_;
2018-10-14 00:08:33 +02:00
};
2021-01-26 16:48:04 +01:00
#endif // LOCALREDIRECTSERVER_H