[Pkg-owncloud-commits] [owncloud-client] 378/484: NetworkJobs: JSON network job now reports OCS reply code.

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:38:08 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 421c6a92f3ece99724ca0c04e48db5ae76a880cc
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Thu Nov 19 15:59:10 2015 +0100

    NetworkJobs: JSON network job now reports OCS reply code.
    
    The signal jsonReceived() now not only delivers the raw json string, but
    also the status code that came as OCS reply.
    
    Also, fixed a typo in the signals name (recieved => received).
---
 src/gui/activitywidget.cpp                     |  6 ++++--
 src/gui/activitywidget.h                       |  2 +-
 src/gui/creds/shibboleth/shibbolethuserjob.cpp |  7 +++++--
 src/gui/creds/shibboleth/shibbolethuserjob.h   |  2 +-
 src/libsync/connectionvalidator.cpp            |  2 +-
 src/libsync/networkjobs.cpp                    | 25 +++++++++++++++++++++----
 src/libsync/networkjobs.h                      | 12 ++++++++++--
 7 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index 8eb93f0..4cb8cf2 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -142,7 +142,8 @@ void ActivityListModel::startFetchJob(AccountState* s)
         return;
     }
     JsonApiJob *job = new JsonApiJob(s->account(), QLatin1String("ocs/v1.php/cloud/activity"), this);
-    QObject::connect(job, SIGNAL(jsonRecieved(QVariantMap)), this, SLOT(slotActivitiesReceived(QVariantMap)));
+    QObject::connect(job, SIGNAL(jsonReceived(QVariantMap, int)),
+                     this, SLOT(slotActivitiesReceived(QVariantMap, int)));
     job->setProperty("AccountStatePtr", QVariant::fromValue<AccountState*>(s));
 
     QList< QPair<QString,QString> > params;
@@ -155,7 +156,7 @@ void ActivityListModel::startFetchJob(AccountState* s)
     job->start();
 }
 
-void ActivityListModel::slotActivitiesReceived(const QVariantMap& json)
+void ActivityListModel::slotActivitiesReceived(const QVariantMap& json, int statusCode)
 {
     auto activities = json.value("ocs").toMap().value("data").toList();
     qDebug() << "*** activities" << activities;
@@ -164,6 +165,7 @@ void ActivityListModel::slotActivitiesReceived(const QVariantMap& json)
     AccountState* ai = qvariant_cast<AccountState*>(sender()->property("AccountStatePtr"));
     _currentlyFetching.remove(ai);
     list.setAccountName( ai->account()->displayName());
+
     foreach( auto activ, activities ) {
         auto json = activ.toMap();
 
diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h
index 61f63ee..0158233 100644
--- a/src/gui/activitywidget.h
+++ b/src/gui/activitywidget.h
@@ -110,7 +110,7 @@ public slots:
     void slotRemoveAccount( AccountState *ast );
 
 private slots:
-    void slotActivitiesReceived(const QVariantMap& json);
+    void slotActivitiesReceived(const QVariantMap& json, int statusCode);
 
 private:
     void startFetchJob(AccountState* s);
diff --git a/src/gui/creds/shibboleth/shibbolethuserjob.cpp b/src/gui/creds/shibboleth/shibbolethuserjob.cpp
index c317dfd..a36bc29 100644
--- a/src/gui/creds/shibboleth/shibbolethuserjob.cpp
+++ b/src/gui/creds/shibboleth/shibbolethuserjob.cpp
@@ -22,11 +22,14 @@ ShibbolethUserJob::ShibbolethUserJob(AccountPtr account, QObject* parent)
     : JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/user"), parent)
 {
     setIgnoreCredentialFailure(true);
-    connect(this, SIGNAL(jsonRecieved(QVariantMap)), this, SLOT(slotJsonRecieved(QVariantMap)));
+    connect(this, SIGNAL(jsonReceived(QVariantMap, int)), this, SLOT(slotJsonReceived(QVariantMap, int)));
 }
 
-void ShibbolethUserJob::slotJsonRecieved(const QVariantMap &json)
+void ShibbolethUserJob::slotJsonReceived(const QVariantMap &json, int statusCode)
 {
+    if( statusCode != 100 ) {
+        qWarning() << "JSON Api call resulted in status code != 100";
+    }
     QString user =  json.value("ocs").toMap().value("data").toMap().value("id").toString();
     //qDebug() << "cloud/user: " << json << "->" << user;
     emit userFetched(user);
diff --git a/src/gui/creds/shibboleth/shibbolethuserjob.h b/src/gui/creds/shibboleth/shibbolethuserjob.h
index 57ee34c..7f53b68 100644
--- a/src/gui/creds/shibboleth/shibbolethuserjob.h
+++ b/src/gui/creds/shibboleth/shibbolethuserjob.h
@@ -33,7 +33,7 @@ signals:
     void userFetched(const QString &user);
 
 private slots:
-    void slotJsonRecieved(const QVariantMap &);
+    void slotJsonReceived(const QVariantMap &, int statusCode);
 };
 
 
diff --git a/src/libsync/connectionvalidator.cpp b/src/libsync/connectionvalidator.cpp
index ba81cf4..651a9b3 100644
--- a/src/libsync/connectionvalidator.cpp
+++ b/src/libsync/connectionvalidator.cpp
@@ -209,7 +209,7 @@ void ConnectionValidator::slotAuthSuccess()
 void ConnectionValidator::checkServerCapabilities()
 {
     JsonApiJob *job = new JsonApiJob(_account, QLatin1String("ocs/v1.php/cloud/capabilities"), this);
-    QObject::connect(job, SIGNAL(jsonRecieved(QVariantMap)), this, SLOT(slotCapabilitiesRecieved(QVariantMap)));
+    QObject::connect(job, SIGNAL(jsonReceived(QVariantMap, int)), this, SLOT(slotCapabilitiesRecieved(QVariantMap)));
     job->start();
 }
 
diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp
index 424a43b..aca38bd 100644
--- a/src/libsync/networkjobs.cpp
+++ b/src/libsync/networkjobs.cpp
@@ -608,23 +608,40 @@ void JsonApiJob::start()
 
 bool JsonApiJob::finished()
 {
+    int statusCode = 0;
+
     if (reply()->error() != QNetworkReply::NoError) {
         qWarning() << "Network error: " << path() << reply()->errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute);
-        emit jsonRecieved(QVariantMap());
+        emit jsonReceived(QVariantMap(), statusCode);
         return true;
     }
 
-    bool success = false;
     QString jsonStr = QString::fromUtf8(reply()->readAll());
+    if( jsonStr.contains( "<?xml version=\"1.0\"?>") ) {
+        QRegExp rex("<statuscode>(\\d+)</statuscode>");
+        if( jsonStr.contains(rex) ) {
+            // this is a error message coming back from ocs.
+            statusCode = rex.cap(1).toInt();
+        }
+
+    } else {
+        QRegExp rex("\"statuscode\":(\\d+),");
+        // example: "{"ocs":{"meta":{"status":"ok","statuscode":100,"message":null},"data":{"version":{"major":8,"minor":"... (504)
+        if( jsonStr.contains(rex) ) {
+            statusCode = rex.cap(1).toInt();
+        }
+    }
+
+    bool success = false;
     QVariantMap json = QtJson::parse(jsonStr, success).toMap();
     // empty or invalid response
     if (!success || json.isEmpty()) {
         qWarning() << "invalid JSON!" << jsonStr;
-        emit jsonRecieved(QVariantMap());
+        emit jsonReceived(QVariantMap(), statusCode);
         return true;
     }
 
-    emit jsonRecieved(json);
+    emit jsonReceived(json, statusCode);
     return true;
 }
 
diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h
index 23e1461..69c8f8e 100644
--- a/src/libsync/networkjobs.h
+++ b/src/libsync/networkjobs.h
@@ -199,7 +199,7 @@ private slots:
  * To be used like this:
  * \code
  * _job = new JsonApiJob(account, QLatin1String("ocs/v1.php/foo/bar"), this);
- * connect(job, SIGNAL(jsonRecieved(QVariantMap)), ...)
+ * connect(job, SIGNAL(jsonReceived(QVariantMap)), ...)
  * The received QVariantMap is empty in case of error or otherwise is a map as parsed by QtJson
  * \encode
  *
@@ -221,12 +221,20 @@ public:
      * This function needs to be called before start() obviously.
      */
     void addQueryParams(QList< QPair<QString,QString> > params);
+
 public slots:
     void start() Q_DECL_OVERRIDE;
 protected:
     bool finished() Q_DECL_OVERRIDE;
 signals:
-    void jsonRecieved(const QVariantMap &json);
+
+    /**
+     * @brief jsonReceived - signal to report the json answer from ocs
+     * @param json - the raw json string
+     * @param statusCode - the OCS status code: 100 (!) for success
+     */
+    void jsonReceived(const QVariantMap &json, int statusCode);
+
 private:
     QList< QPair<QString,QString> > _additionalParams;
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list