[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:27:01 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=e86897c

The following commit has been merged in the master branch:
commit e86897cfe3902adb87351dede14662a6f7c4b995
Author: Albert Vaca <albertvaka at gmail.com>
Date:   Fri Sep 20 15:54:30 2013 +0200

    Fixed file transfer, added file size to protocol (optional)
    
    Increased protocol version to 5
    Updated README
---
 README                                             | 22 +++++++--
 kded/backends/lan/downloadjob.cpp                  |  1 +
 kded/backends/lan/landevicelink.cpp                |  2 +-
 kded/backends/lan/uploadjob.cpp                    |  2 +
 kded/backends/loopback/loopbackdevicelink.cpp      |  4 +-
 kded/networkpackage.cpp                            | 21 ++++----
 kded/networkpackage.h                              |  7 ++-
 kded/plugins/filetransfer/filetransferjob.cpp      | 57 +++++++++++++++++-----
 kded/plugins/filetransfer/filetransferjob.h        |  4 +-
 kded/plugins/filetransfer/filetransferplugin.cpp   | 17 ++++---
 .../notifications/notificationsdbusinterface.cpp   |  2 +
 11 files changed, 99 insertions(+), 40 deletions(-)

diff --git a/README b/README
index 1c6445f..0a4b2ec 100644
--- a/README
+++ b/README
@@ -15,11 +15,11 @@ Class diagram
 
 Daemon instantiates Backends
 
-Backends manage to create DeviceLinks with the devices they can reach, and Q_EMIT them to Daemon.
+Backends manage to create DeviceLinks with the devices they can reach, and Q_EMIT them to the Daemon.
 
-When Daemon receives a DeviceLink from a backend it:
-    - If he already knows the Device, adds the DeviceLink to the Device
-    - If not, it creates a new Device.
+When the Daemon receives a DeviceLink from a backend:
+    - If it already knows the Device, adds the new DeviceLink to the existing Device, as a new way to reach it.
+    - If not, it creates a new untrusted (yet to be paired) Device.
 
 Devices contain a list of DeviceLinks, plus a list of Plugins (instantiated automatically)
 
@@ -45,10 +45,22 @@ The basic structure of a NetworkPackage is the following:
     "body": {
 
     },
-    "version": 1
+    "version": 5
 }
 
 Each type of package defines what it should contain inside its "body", so only
 the emisor Plugin and receiver Plugin of this type of package need agree about
 its content.
 
+If the package has a payload attached, it will also contain two more fields:
+ "payloadSize": The size of the file, or -1 if it is a stream without known end
+ "payloadTransferInfo": Another JSON Object containing the information that the
+                        backend wants to send to the peer backend, to actually
+                        transfer the payload.
+
+Encrypted network packages have the following format:
+
+//TODO
+
+
+//TODO: Document the possible contents written for each plugin in the body part
diff --git a/kded/backends/lan/downloadjob.cpp b/kded/backends/lan/downloadjob.cpp
index cc04697..d868015 100644
--- a/kded/backends/lan/downloadjob.cpp
+++ b/kded/backends/lan/downloadjob.cpp
@@ -32,6 +32,7 @@ void DownloadJob::start()
     qDebug() << "start";
     mSocket->connectToHost(mAddress, mPort, QIODevice::ReadOnly);
     connect(mSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
+    //TODO: Implement payload encryption somehow (create an intermediate iodevice to encrypt the payload here?)
 }
 
 void DownloadJob::disconnected()
diff --git a/kded/backends/lan/landevicelink.cpp b/kded/backends/lan/landevicelink.cpp
index 1b159c2..3704696 100644
--- a/kded/backends/lan/landevicelink.cpp
+++ b/kded/backends/lan/landevicelink.cpp
@@ -101,7 +101,7 @@ void LanDeviceLink::dataReceived()
                 qDebug() << "HasPayloadTransferInfo";
                 DownloadJob* job = new DownloadJob(mSocket->peerAddress(), decrypted.payloadTransferInfo());
                 job->start();
-                decrypted.setPayload(job->getPayload());
+                decrypted.setPayload(job->getPayload(), decrypted.payloadSize());
             }
 
             Q_EMIT receivedPackage(decrypted);
diff --git a/kded/backends/lan/uploadjob.cpp b/kded/backends/lan/uploadjob.cpp
index b77ad95..af8009c 100644
--- a/kded/backends/lan/uploadjob.cpp
+++ b/kded/backends/lan/uploadjob.cpp
@@ -62,6 +62,8 @@ void UploadJob::newConnection()
 
 void UploadJob::readyRead()
 {
+    //TODO: Implement payload encryption
+
     qint64 bytes = qMax(mInput->bytesAvailable(), (qint64)4096);
     mSocket->write(mInput->read(bytes));
 }
diff --git a/kded/backends/loopback/loopbackdevicelink.cpp b/kded/backends/loopback/loopbackdevicelink.cpp
index d5e4cba..c16a02e 100644
--- a/kded/backends/loopback/loopbackdevicelink.cpp
+++ b/kded/backends/loopback/loopbackdevicelink.cpp
@@ -47,7 +47,7 @@ bool LoopbackDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackag
     //LoopbackDeviceLink does not need deviceTransferInfo
     if (input.hasPayload()) {
         QIODevice* device = input.payload();
-        output.setPayload(device);
+        output.setPayload(device, input.payloadSize());
     }
 
     Q_EMIT receivedPackage(output);
@@ -63,7 +63,7 @@ bool LoopbackDeviceLink::sendPackage(NetworkPackage& input)
     //LoopbackDeviceLink does not need deviceTransferInfo
     if (input.hasPayload()) {
         QIODevice* device = input.payload();
-        output.setPayload(device);
+        output.setPayload(device, input.payloadSize());
     }
 
     Q_EMIT receivedPackage(output);
diff --git a/kded/networkpackage.cpp b/kded/networkpackage.cpp
index eeb7846..2f20220 100644
--- a/kded/networkpackage.cpp
+++ b/kded/networkpackage.cpp
@@ -34,7 +34,7 @@
 #include <qjson/qobjecthelper.h>
 
 const QCA::EncryptionAlgorithm NetworkPackage::EncryptionAlgorithm = QCA::EME_PKCS1v15;
-const int NetworkPackage::ProtocolVersion = 4;
+const int NetworkPackage::ProtocolVersion = 5;
 
 NetworkPackage::NetworkPackage(const QString& type)
 {
@@ -42,6 +42,7 @@ NetworkPackage::NetworkPackage(const QString& type)
     mType = type;
     mBody = QVariantMap();
     mPayload = 0;
+    mPayloadSize = 0;
 }
 
 void NetworkPackage::createIdentityPackage(NetworkPackage* np)
@@ -51,6 +52,7 @@ void NetworkPackage::createIdentityPackage(NetworkPackage* np)
     np->mId = QString::number(QDateTime::currentMSecsSinceEpoch());
     np->mType = PACKAGE_TYPE_IDENTITY;
     np->mPayload = 0;
+    np->mPayloadSize = 0;
     np->set("deviceId", id);
     np->set("deviceName", QHostInfo::localHostName());
     np->set("protocolVersion",  NetworkPackage::ProtocolVersion);
@@ -69,6 +71,7 @@ QByteArray NetworkPackage::serialize() const
 
     if (hasPayload()) {
         //qDebug() << "Serializing payloadTransferInfo";
+        variant["payloadSize"] = 0;
         variant["payloadTransferInfo"] = mPayloadTransferInfo;
     }
 
@@ -110,10 +113,8 @@ bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np)
         qDebug() << "Unserialize: " << a;
     }
 
-    if (variant.contains("payloadTransferInfo")) {
-        //qDebug() << "Unserializing payloadTransferInfo";
-        np->mPayloadTransferInfo = variant["payloadTransferInfo"].toMap();
-    }
+    np->mPayloadSize = variant["payloadSize"].toInt(); //Will return 0 if was not present, which is ok
+    np->mPayloadTransferInfo = variant["payloadTransferInfo"].toMap(); //Will return an empty qvariantmap if was not present, which is ok
 
     return true;
 
@@ -122,7 +123,6 @@ bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np)
 void NetworkPackage::encrypt(QCA::PublicKey& key)
 {
 
-    //TODO: Implement payload encryption somehow (create an intermediate iodevice to encrypt the payload here?)
     QByteArray serialized = serialize();
 
     int chunkSize = key.maximumEncryptSize(NetworkPackage::EncryptionAlgorithm);
@@ -160,12 +160,15 @@ bool NetworkPackage::decrypt(QCA::PrivateKey& key, NetworkPackage* out) const
         decryptedJson.append(decryptedChunk.toByteArray());
     }
 
-    //TODO: Implement payload encryption somehow (create an intermediate iodevice to decrypt the payload here?)
+    bool success = unserialize(decryptedJson, out);
+
+    if (!success) return false;
+
     if (hasPayload()) {
-        out->setPayload(mPayload);
+        out->mPayload = mPayload;
     }
 
-    return unserialize(decryptedJson, out);
+    return true;
 
 }
 
diff --git a/kded/networkpackage.h b/kded/networkpackage.h
index 4556c4d..61e8330 100644
--- a/kded/networkpackage.h
+++ b/kded/networkpackage.h
@@ -71,8 +71,9 @@ public:
 
     //TODO: Change to a shared pointer
     QIODevice* payload() const { return mPayload; }
-    void setPayload(QIODevice* device) { mPayload = device; }
-    bool hasPayload() const { return (mPayload != 0); }
+    void setPayload(QIODevice* device, int payloadSize) { mPayload = device; mPayloadSize = payloadSize; Q_ASSERT(mPayloadSize >= -1); }
+    bool hasPayload() const { return (mPayloadSize != 0); }
+    int payloadSize() const { return mPayloadSize; } //-1 means it is an endless stream
 
     //To be called by a particular DeviceLink
     QVariantMap payloadTransferInfo() const { return mPayloadTransferInfo; }
@@ -84,12 +85,14 @@ private:
     void setId(const QString& id) { mId = id; }
     void setType(const QString& t) { mType = t; }
     void setBody(const QVariantMap& b) { mBody = b; }
+    void setPayloadSize(int s) { mPayloadSize = s; }
 
     QString mId;
     QString mType;
     QVariantMap mBody;
 
     QIODevice* mPayload;
+    int mPayloadSize;
     QVariantMap mPayloadTransferInfo;
 
 };
diff --git a/kded/plugins/filetransfer/filetransferjob.cpp b/kded/plugins/filetransfer/filetransferjob.cpp
index 5535f10..876b817 100644
--- a/kded/plugins/filetransfer/filetransferjob.cpp
+++ b/kded/plugins/filetransfer/filetransferjob.cpp
@@ -20,13 +20,17 @@
 
 #include "filetransferjob.h"
 
+#include <KLocalizedString>
+
 #include <QDebug>
 #include <qalgorithms.h>
 
-FileTransferJob::FileTransferJob(QIODevice* origin, const KUrl& destination): KJob()
+FileTransferJob::FileTransferJob(QIODevice* origin, int size, const KUrl& destination): KJob()
 {
     mDestination = destination;
     mOrigin = origin;
+    mSize = size;
+    mWritten = 0;
 }
 
 void FileTransferJob::start()
@@ -46,51 +50,80 @@ void FileTransferJob::start()
 void FileTransferJob::open(KIO::Job* job)
 {
     Q_UNUSED(job);
-    
-    //Open source file
 
-    mOrigin->open(QIODevice::ReadOnly);
+    qDebug() << "open";
 
+    if (!mOrigin) {
+        qDebug() << "FileTransferJob: Origin is null";
+        return;
+    }
+
+    //Open source file
+    mOrigin->open(QIODevice::ReadOnly);
     Q_ASSERT(mOrigin->isOpen());
 
     connect(mOrigin, SIGNAL(readyRead()),this, SLOT(readyRead()));
-    connect(mOrigin, SIGNAL(aboutToClose()),this, SLOT(sourceFinished()));
+    connect(mOrigin, SIGNAL(disconnected()),this, SLOT(sourceFinished()));
     if (mOrigin->bytesAvailable() > 0) readyRead();
 
 }
 
 void FileTransferJob::readyRead()
 {
+    qDebug() << "readyRead";
+
     //Copy a chunk of data
 
     int bytes = qMin(qint64(4096), mOrigin->bytesAvailable());
     QByteArray data = mOrigin->read(bytes);
     mTempDestination->write(data);
+    mWritten += bytes;
+
+    if (mSize > -1) {
+        setPercent((mWritten*100)/mSize);
+    }
 
-    if(!mOrigin->atEnd())
+    qDebug() << mSize << mWritten << bytes;
+
+    if (mSize > -1 && mWritten >= mSize) { //At the end or expected size reached
+        qDebug() << "No more data to read";
+        disconnect(mOrigin, SIGNAL(readyRead()),this, SLOT(readyRead()));
+        mOrigin->close();
+    } else if (mOrigin->bytesAvailable() > 0) {
         QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
+    }
 }
 
 void FileTransferJob::sourceFinished()
 {
     qDebug() << "sourceFinished";
 
-    readyRead(); //Read the last chunk of data, if any
+    //Make sure we do not enter this function again
+    disconnect(mOrigin, SIGNAL(aboutToClose()),this, SLOT(sourceFinished()));
+
+    //TODO: MD5 check the file
+    if (mSize > -1 && mWritten != mSize) {
+        qDebug() << "Received incomplete file";
+        setError(1);
+        setErrorText(i18n("Received incomplete file"));
+        emitResult();
+    }
 
-    qDebug() << "Finished" << mTempDestination->url();
+    qDebug() << "Finished" << mTempDestination->url() << mDestination;
     KIO::FileCopyJob* job = KIO::file_move(mTempDestination->url(), mDestination);
     connect(job, SIGNAL(result(KJob*)), this, SLOT(moveResult(KJob*)));
     job->start();
 
-    delete mOrigin; //TODO: Use shared pointers
+    //delete mOrigin; //TODO: Use shared pointers
 }
 
 void FileTransferJob::moveResult(KJob* job)
 {
     //TODO: Error handling, cleanup
-    qDebug() << "Move result";
-    qDebug() << job->errorString();
-    qDebug() << job->errorText();
+    qDebug() << "Move finished";
+    if (job->error()) {
+        qDebug() << job->errorText();
+    }
     emitResult();
 }
 
diff --git a/kded/plugins/filetransfer/filetransferjob.h b/kded/plugins/filetransfer/filetransferjob.h
index 5cf365f..d38d0fe 100644
--- a/kded/plugins/filetransfer/filetransferjob.h
+++ b/kded/plugins/filetransfer/filetransferjob.h
@@ -35,7 +35,7 @@ class FileTransferJob : public KJob
     Q_OBJECT
 
 public:
-    FileTransferJob(QIODevice* origin, const KUrl& destination);
+    FileTransferJob(QIODevice* origin, int size, const KUrl& destination);
     virtual void start();
     KUrl destination() { return mDestination; }
 
@@ -48,7 +48,9 @@ public Q_SLOTS:
 private:
     KIO::FileJob* mTempDestination;
     KUrl mDestination;
+    int mSize;
     QIODevice* mOrigin;
+    int mWritten;
 
 };
 
diff --git a/kded/plugins/filetransfer/filetransferplugin.cpp b/kded/plugins/filetransfer/filetransferplugin.cpp
index 097eab9..7533f73 100644
--- a/kded/plugins/filetransfer/filetransferplugin.cpp
+++ b/kded/plugins/filetransfer/filetransferplugin.cpp
@@ -40,41 +40,42 @@ FileTransferPlugin::FileTransferPlugin(QObject* parent, const QVariantList& args
     //TODO: Use downloads user path
     //TODO: Be able to change this from config
     mDestinationDir = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
+    if (!mDestinationDir.endsWith('/')) mDestinationDir.append('/');
 }
 
 bool FileTransferPlugin::receivePackage(const NetworkPackage& np)
 {
 
     //TODO: Move this code to a test and do a diff between files
-    //if (np.type() == PACKAGE_TYPE_PING) {
+    if (np.type() == PACKAGE_TYPE_PING) {
 
         qDebug() << "sending file" << (QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc");
 
         NetworkPackage out(PACKAGE_TYPE_FILETRANSFER);
-        out.set("filename", mDestinationDir + "/itworks.txt");
+        out.set("filename", mDestinationDir + "itworks.txt");
          //TODO: Use shared pointers
         AutoClosingQFile* file = new AutoClosingQFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc"); //Test file to transfer
 
-        out.setPayload(file);
+        out.setPayload(file, file->size());
 
         device()->sendPackage(out);
 
         return true;
 
-    //}
+    }
 
     if (np.type() != PACKAGE_TYPE_FILETRANSFER) return false;
-
-    qDebug() << "file transfer";
+    qDebug() << "File transfer";
 
     if (np.hasPayload()) {
         qDebug() << "receiving file";
-        QString filename = np.get<QString>("filename");
+        QString filename = np.get<QString>("filename", mDestinationDir + QString::number(QDateTime::currentMSecsSinceEpoch()));
         QIODevice* incoming = np.payload();
-        FileTransferJob* job = new FileTransferJob(incoming,filename);
+        FileTransferJob* job = new FileTransferJob(incoming, np.payloadSize(), filename);
         connect(job,SIGNAL(result(KJob*)), this, SLOT(finished(KJob*)));
         job->start();
     }
+
     return true;
 
 }
diff --git a/kded/plugins/notifications/notificationsdbusinterface.cpp b/kded/plugins/notifications/notificationsdbusinterface.cpp
index 24466a4..a62e2d1 100644
--- a/kded/plugins/notifications/notificationsdbusinterface.cpp
+++ b/kded/plugins/notifications/notificationsdbusinterface.cpp
@@ -51,6 +51,8 @@ void NotificationsDbusInterface::processPackage(const NetworkPackage& np)
     } else {
         Notification* noti = new Notification(np, this);
 
+        //TODO: Store the app icon if any under tmp with the app name as filename (so we only store one per app) and export the path to that file to dbus inside Notification
+
         //Do not show updates to existent notification nor answers to a initialization request
         if (!mInternalIdToPublicId.contains(noti->internalId()) && !np.get<bool>("requestAnswer", false)) {
             KNotification* notification = new KNotification("notification");

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list