| 69 | } |
| 70 | |
| 71 | void PollServer::onReplyFinished() |
| 72 | { |
| 73 | QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); |
| 74 | |
| 75 | if (!reply) { |
| 76 | qDebug() << "PollServer::onReplyFinished: reply is null"; |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | QByteArray replyData = reply->readAll(); |
| 81 | QMap<QString, QString> params = toVerificationParams(parseJsonResponse(replyData)); |
| 82 | |
| 83 | // Dump replyData |
| 84 | // SENSITIVE DATA in RelWithDebInfo or Debug builds |
| 85 | // qDebug() << "PollServer::onReplyFinished: replyData\n"; |
| 86 | // qDebug() << QString( replyData ); |
| 87 | |
| 88 | if (reply->error() == QNetworkReply::TimeoutError) { |
| 89 | // rfc8628#section-3.2 |
| 90 | // "On encountering a connection timeout, clients MUST unilaterally |
| 91 | // reduce their polling frequency before retrying. The use of an |
| 92 | // exponential backoff algorithm to achieve this, such as doubling the |
| 93 | // polling interval on each such connection timeout, is RECOMMENDED." |
| 94 | setInterval(interval() * 2); |
| 95 | pollTimer.start(); |
| 96 | } |
| 97 | else { |
| 98 | QString error = params.value("error"); |
| 99 | if (error == "slow_down") { |
| 100 | // rfc8628#section-3.2 |
| 101 | // "A variant of 'authorization_pending', the authorization request is |
| 102 | // still pending and polling should continue, but the interval MUST |
| 103 | // be increased by 5 seconds for this and all subsequent requests." |
| 104 | setInterval(interval() + 5); |
| 105 | pollTimer.start(); |
| 106 | } |
| 107 | else if (error == "authorization_pending") { |
| 108 | // keep trying - rfc8628#section-3.2 |
| 109 | // "The authorization request is still pending as the end user hasn't |
| 110 | // yet completed the user-interaction steps (Section 3.3)." |
| 111 | pollTimer.start(); |
| 112 | } |
| 113 | else { |
| 114 | expirationTimer.stop(); |
| 115 | emit serverClosed(true); |
| 116 | // let O2 handle the other cases |
| 117 | emit verificationReceived(params); |
| 118 | } |
| 119 | } |
| 120 | reply->deleteLater(); |
| 121 | } |
| 122 | |
| 123 | } |
nothing calls this directly
no test coverage detected