diff options
Diffstat (limited to 'src/oauth')
-rw-r--r-- | src/oauth/qoauthhttpserverreplyhandler.cpp | 34 | ||||
-rw-r--r-- | src/oauth/qoauthhttpserverreplyhandler.h | 3 | ||||
-rw-r--r-- | src/oauth/qoauthhttpserverreplyhandler_p.h | 1 |
3 files changed, 30 insertions, 8 deletions
diff --git a/src/oauth/qoauthhttpserverreplyhandler.cpp b/src/oauth/qoauthhttpserverreplyhandler.cpp index 2c0d336..c39f051 100644 --- a/src/oauth/qoauthhttpserverreplyhandler.cpp +++ b/src/oauth/qoauthhttpserverreplyhandler.cpp @@ -107,7 +107,7 @@ void QOAuthHttpServerReplyHandlerPrivate::_q_readData(QTcpSocket *socket) void QOAuthHttpServerReplyHandlerPrivate::_q_answerClient(QTcpSocket *socket, const QUrl &url) { Q_Q(QOAuthHttpServerReplyHandler); - if (!url.path().startsWith(QStringLiteral("/cb"))) { + if (!url.path().startsWith(QLatin1String("/") + path)) { qWarning("QOAuthHttpServerReplyHandlerPrivate::_q_answerClient: Invalid request: %s", qPrintable(url.toString())); } else { @@ -118,11 +118,11 @@ void QOAuthHttpServerReplyHandlerPrivate::_q_answerClient(QTcpSocket *socket, co receivedData.insert(it->first, it->second); Q_EMIT q->callbackReceived(receivedData); - const QString html = QLatin1String("<html><head><title>") + - qApp->applicationName() + - QLatin1String("</title></head><body>") + - text + - QLatin1String("</body></html>"); + const QByteArray html = QByteArrayLiteral("<html><head><title>") + + qApp->applicationName().toUtf8() + + QByteArrayLiteral("</title></head><body>") + + text.toUtf8() + + QByteArrayLiteral("</body></html>"); const QByteArray htmlSize = QString::number(html.size()).toUtf8(); const QByteArray replyMessage = QByteArrayLiteral("HTTP/1.0 200 OK \r\n" @@ -130,7 +130,7 @@ void QOAuthHttpServerReplyHandlerPrivate::_q_answerClient(QTcpSocket *socket, co "charset=\"utf-8\"\r\n" "Content-Length: ") + htmlSize + QByteArrayLiteral("\r\n\r\n") + - html.toUtf8(); + html; socket->write(replyMessage); } @@ -274,10 +274,28 @@ QString QOAuthHttpServerReplyHandler::callback() const Q_D(const QOAuthHttpServerReplyHandler); Q_ASSERT(d->httpServer.isListening()); - const QUrl url(QString::fromLatin1("http://localhost:%1/cb").arg(d->httpServer.serverPort())); + const QUrl url(QString::fromLatin1("http://localhost:%1/%2") + .arg(d->httpServer.serverPort()).arg(d->path)); return url.toString(QUrl::EncodeDelimiters); } +QString QOAuthHttpServerReplyHandler::callbackPath() const +{ + Q_D(const QOAuthHttpServerReplyHandler); + return d->path; +} + +void QOAuthHttpServerReplyHandler::setCallbackPath(const QString &path) +{ + Q_D(QOAuthHttpServerReplyHandler); + + QString copy = path; + while (copy.startsWith('/')) + copy = copy.mid(1); + + d->path = copy; +} + QString QOAuthHttpServerReplyHandler::callbackText() const { Q_D(const QOAuthHttpServerReplyHandler); diff --git a/src/oauth/qoauthhttpserverreplyhandler.h b/src/oauth/qoauthhttpserverreplyhandler.h index f93eb33..74a99b6 100644 --- a/src/oauth/qoauthhttpserverreplyhandler.h +++ b/src/oauth/qoauthhttpserverreplyhandler.h @@ -55,6 +55,9 @@ public: QString callback() const override; + QString callbackPath() const; + void setCallbackPath(const QString &path); + QString callbackText() const; void setCallbackText(const QString &text); diff --git a/src/oauth/qoauthhttpserverreplyhandler_p.h b/src/oauth/qoauthhttpserverreplyhandler_p.h index 9d666eb..71873fd 100644 --- a/src/oauth/qoauthhttpserverreplyhandler_p.h +++ b/src/oauth/qoauthhttpserverreplyhandler_p.h @@ -63,6 +63,7 @@ public: QTcpServer httpServer; QString text; QHostAddress listenAddress = QHostAddress::LocalHost; + QString path; private: void _q_clientConnected(); |