File indexing completed on 2025-01-19 03:55:39
0001 #include <QDebug> 0002 #include <QDateTime> 0003 #include <QNetworkReply> 0004 #include <QNetworkAccessManager> 0005 0006 #include "o1requestor.h" 0007 #include "o1timedreply.h" 0008 #include "o0globals.h" 0009 0010 O1Requestor::O1Requestor(QNetworkAccessManager *manager, O1 *authenticator, QObject *parent): QObject(parent) { 0011 manager_ = manager; 0012 authenticator_ = authenticator; 0013 } 0014 0015 QNetworkReply *O1Requestor::get(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters) { 0016 QNetworkRequest request = setup(req, signingParameters, QNetworkAccessManager::GetOperation); 0017 return addTimer(manager_->get(request)); 0018 } 0019 0020 QNetworkReply *O1Requestor::post(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, const QByteArray &data) { 0021 QNetworkRequest request = setup(req, signingParameters, QNetworkAccessManager::PostOperation); 0022 return addTimer(manager_->post(request, data)); 0023 } 0024 0025 QNetworkReply *O1Requestor::post(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QHttpMultiPart * multiPart) { 0026 QNetworkRequest request = setup(req, signingParameters, QNetworkAccessManager::PostOperation); 0027 return addTimer(manager_->post(request, multiPart)); 0028 } 0029 0030 QNetworkReply *O1Requestor::put(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, const QByteArray &data) { 0031 QNetworkRequest request = setup(req, signingParameters, QNetworkAccessManager::PutOperation); 0032 return addTimer(manager_->put(request, data)); 0033 } 0034 0035 QNetworkReply *O1Requestor::addTimer(QNetworkReply *reply) { 0036 (void)new O1TimedReply(reply); 0037 return reply; 0038 } 0039 0040 QNetworkRequest O1Requestor::setup(const QNetworkRequest &req, const QList<O0RequestParameter> &signingParameters, QNetworkAccessManager::Operation operation) { 0041 // Collect OAuth parameters 0042 QList<O0RequestParameter> oauthParams; 0043 oauthParams.append(O0RequestParameter(O2_OAUTH_CONSUMER_KEY, authenticator_->clientId().toLatin1())); 0044 oauthParams.append(O0RequestParameter(O2_OAUTH_VERSION, "1.0")); 0045 oauthParams.append(O0RequestParameter(O2_OAUTH_TOKEN, authenticator_->token().toLatin1())); 0046 oauthParams.append(O0RequestParameter(O2_OAUTH_SIGNATURE_METHOD, authenticator_->signatureMethod().toLatin1())); 0047 oauthParams.append(O0RequestParameter(O2_OAUTH_NONCE, O1::nonce())); 0048 #if QT_VERSION >= 0x050800 0049 oauthParams.append(O0RequestParameter(O2_OAUTH_TIMESTAMP, QString::number(QDateTime::currentSecsSinceEpoch()).toLatin1())); 0050 #else 0051 oauthParams.append(O0RequestParameter(O2_OAUTH_TIMESTAMP, QString::number(QDateTime::currentDateTimeUtc().toTime_t()).toLatin1())); 0052 #endif 0053 0054 // Add signature parameter 0055 oauthParams.append(O0RequestParameter(O2_OAUTH_SIGNATURE, authenticator_->generateSignature(oauthParams, req, signingParameters, operation))); 0056 0057 // Return a copy of the original request with authorization header set 0058 QNetworkRequest request(req); 0059 authenticator_->decorateRequest(request, oauthParams); 0060 return request; 0061 } 0062 0063 #include "moc_o1requestor.cpp"