diff options
author | Liang Qi <liang.qi@qt.io> | 2017-04-18 22:03:54 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-04-18 22:03:54 +0200 |
commit | aeb49ab5e1d7ebe2aaff6579757dacae45579c84 (patch) | |
tree | 9468fd5bb37dae6b296dd31a3239591c43e4128d | |
parent | 031ab0ce77da942d12e84cb18a76be71f7533544 (diff) | |
parent | 034b35a3bcbc34509f77b46d3754196c9d53552d (diff) |
Merge remote-tracking branch 'origin/5.8' into 5.9v5.9.0-beta3
Change-Id: Iec26fd341732ad9d7bf4a2c5eb556820ec4e2fa2
-rw-r--r-- | examples/oauth/twittertimeline/twitter.cpp | 1 | ||||
-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 |
4 files changed, 31 insertions, 8 deletions
diff --git a/examples/oauth/twittertimeline/twitter.cpp b/examples/oauth/twittertimeline/twitter.cpp index 49061a7..933ae3e 100644 --- a/examples/oauth/twittertimeline/twitter.cpp +++ b/examples/oauth/twittertimeline/twitter.cpp @@ -47,6 +47,7 @@ Twitter::Twitter(const QString &screenName, QOAuth1(clientCredentials.first, clientCredentials.second, nullptr, parent) { replyHandler = new QOAuthHttpServerReplyHandler(this); + replyHandler->setCallbackPath("callback"); setReplyHandler(replyHandler); setTemporaryCredentialsUrl(QUrl("https://api.twitter.com/oauth/request_token")); setAuthorizationUrl(QUrl("https://api.twitter.com/oauth/authenticate")); 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(); |