2012-11-30 14:40:54 +01:00
|
|
|
#ifndef LOCALREDIRECTSERVER_H
|
|
|
|
#define LOCALREDIRECTSERVER_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
class QTcpServer;
|
|
|
|
class QTcpSocket;
|
|
|
|
|
|
|
|
class LocalRedirectServer : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
LocalRedirectServer(QObject* parent = nullptr);
|
2012-11-30 14:40:54 +01:00
|
|
|
|
|
|
|
// Causes the server to listen for _one_ request.
|
|
|
|
void Listen();
|
|
|
|
|
|
|
|
// Returns the HTTP URL of this server.
|
|
|
|
const QUrl& url() const { return url_; }
|
|
|
|
|
|
|
|
// Returns the URL requested by the OAuth redirect.
|
|
|
|
const QUrl& request_url() const { return request_url_; }
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
signals:
|
2012-11-30 14:40:54 +01:00
|
|
|
void Finished();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void NewConnection();
|
|
|
|
void ReadyRead(QTcpSocket* socket, QByteArray buffer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void WriteTemplate(QTcpSocket* socket) const;
|
|
|
|
QUrl ParseUrlFromRequest(const QByteArray& request) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QTcpServer* server_;
|
|
|
|
QUrl url_;
|
|
|
|
QUrl request_url_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LOCALREDIRECTSERVER_H
|