[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:08:22 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=652791b

The following commit has been merged in the master branch:
commit 652791bc0b4264cddbf2ab8a2c95cc901805a455
Author: Marcin Ziemiński <zieminn at gmail.com>
Date:   Wed Aug 6 00:05:43 2014 +0200

    Fixed key random generation error.
    
    Signed-off-by: Marcin Ziemiński <zieminn at gmail.com>
---
 otr-proxy/KTpProxy/otr-manager.cpp   | 16 +++++++++-------
 otr-proxy/KTpProxy/otr-manager.h     | 23 +++++++++++++++--------
 otr-proxy/KTpProxy/proxy-service.cpp | 31 +++++++++++++++++++------------
 3 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/otr-proxy/KTpProxy/otr-manager.cpp b/otr-proxy/KTpProxy/otr-manager.cpp
index 06c867c..5bf6024 100644
--- a/otr-proxy/KTpProxy/otr-manager.cpp
+++ b/otr-proxy/KTpProxy/otr-manager.cpp
@@ -421,10 +421,10 @@ void Manager::createNewPrivateKey(Session *session)
             session->context().protocol.toLocal8Bit());
 }
 
-KeyGenerationThread* Manager::createNewPrivateKey(const QString &accountId, const QString &accountName)
+KeyGenerationWorker* Manager::createNewPrivateKey(const QString &accountId, const QString &accountName)
 {
     const QString path = config->saveLocation() + accountId + QLatin1String(".privkeys");
-    return new KeyGenerationThread(
+    return new KeyGenerationWorker(
             accountId,
             accountName,
             utils::protocolFromAccountId(accountId),
@@ -495,7 +495,7 @@ TrustFpResult Manager::trustFingerprint(const SessionContext &ctx, Fingerprint *
 }
 
 
-KeyGenerationThread::KeyGenerationThread(
+KeyGenerationWorker::KeyGenerationWorker(
         const QString &accountId,
         const QString &accountName,
         const QString &protocol,
@@ -510,24 +510,25 @@ KeyGenerationThread::KeyGenerationThread(
 {
 }
 
-gcry_error_t KeyGenerationThread::prepareCreation()
+gcry_error_t KeyGenerationWorker::prepareCreation()
 {
     return err = otrl_privkey_generate_start(userState, accountName.toLocal8Bit(), protocol.toLocal8Bit(), &newKey);
 }
 
-void KeyGenerationThread::run()
+void KeyGenerationWorker::calculate()
 {
     if(!err) {
         err = otrl_privkey_generate_calculate(newKey);
     }
+    Q_EMIT finished();
 }
 
-gcry_error_t KeyGenerationThread::error() const
+gcry_error_t KeyGenerationWorker::error() const
 {
     return err;
 }
 
-gcry_error_t KeyGenerationThread::finalizeCreation()
+gcry_error_t KeyGenerationWorker::finalizeCreation()
 {
     if(!err) {
         return err = otrl_privkey_generate_finish(userState, newKey, path.toLocal8Bit());
@@ -536,4 +537,5 @@ gcry_error_t KeyGenerationThread::finalizeCreation()
     }
 }
 
+
 } /* namespace OTR */
diff --git a/otr-proxy/KTpProxy/otr-manager.h b/otr-proxy/KTpProxy/otr-manager.h
index 4259c44..a62a16f 100644
--- a/otr-proxy/KTpProxy/otr-manager.h
+++ b/otr-proxy/KTpProxy/otr-manager.h
@@ -40,7 +40,7 @@ namespace OTR
         extern const OtrlMessageAppOps appOps;
     }
 
-    class KeyGenerationThread;
+    class KeyGenerationWorker;
 
     class Manager
     {
@@ -59,34 +59,41 @@ namespace OTR
             void createNewPrivateKey(Session *session);
             /** return nullptr if thread could not be craeted
               otherwise returns thread which generates a new private key upon calling start method */
-            KeyGenerationThread* createNewPrivateKey(const QString &accountId, const QString &accountName);
+            KeyGenerationWorker* createNewPrivateKey(const QString &accountId, const QString &accountName);
             QString getFingerprintFor(const QString &accountId, const QString &accountName);
             void createInstag(Session *session);
-
-        private:
+private:
             Config *config;
             // TODO - consider clearing states when not in use
             QMap<QString, UserStateBoxPtr> userStates;
     };
 
-    class KeyGenerationThread : public QThread
+    class KeyGenerationWorker : public QObject
     {
+        Q_OBJECT
+
         public:
-            KeyGenerationThread(
+            KeyGenerationWorker(
                     const QString &accountId,
                     const QString &accountName,
                     const QString &protocol,
                     const QString &path,
                     OtrlUserState userState);
 
-            virtual void run();
             gcry_error_t error() const;
             /* has to called before the thread starts*/
             gcry_error_t prepareCreation();
             /* has to called after the finished() signal is emitted */
             gcry_error_t finalizeCreation();
 
-            const QString &accountId;
+        public Q_SLOTS:
+            void calculate();
+
+        Q_SIGNALS:
+            void finished();
+
+        public:
+            const QString accountId;
             const QString accountName;
             const QString protocol;
             const QString path;
diff --git a/otr-proxy/KTpProxy/proxy-service.cpp b/otr-proxy/KTpProxy/proxy-service.cpp
index 551a630..c0bb282 100644
--- a/otr-proxy/KTpProxy/proxy-service.cpp
+++ b/otr-proxy/KTpProxy/proxy-service.cpp
@@ -186,15 +186,22 @@ void ProxyService::onChannelReady(Tp::PendingOperation *pendingChanReady)
 bool ProxyService::createNewPrivateKey(const QString &accountId, const QString &accountName)
 {
     kDebug() << "Generating new private key for " << accountId;
-    OTR::KeyGenerationThread *keyThread = manager.createNewPrivateKey(accountId, accountName);
-    if(keyThread) {
-        if(keyThread->prepareCreation()) {
+    OTR::KeyGenerationWorker *keyWorker = manager.createNewPrivateKey(accountId, accountName);
+    if(keyWorker) {
+        if(keyWorker->prepareCreation()) {
             // alredy started creation for this account
             kDebug() << "Cannot prepare key generation for " << accountId;
+            keyWorker->deleteLater();
             return false;
         }
-        connect(keyThread, SIGNAL(finished()), SLOT(onKeyGenerationThreadFinished()));
-        keyThread->start();
+        QThread *thread = new QThread();
+        keyWorker->moveToThread(thread);
+        connect(thread, SIGNAL(started()), keyWorker, SLOT(calculate()));
+        connect(keyWorker, SIGNAL(finished()), thread, SLOT(quit()));
+        connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+        connect(keyWorker, SIGNAL(finished()), SLOT(onKeyGenerationThreadFinished()));
+
+        thread->start();
         Q_EMIT keyGenerationStarted(accountId);
         return true;
     } else {
@@ -209,15 +216,15 @@ QString ProxyService::getFingerprintFor(const QString &accountId, const QString
 
 void ProxyService::onKeyGenerationThreadFinished()
 {
-    OTR::KeyGenerationThread *thread = dynamic_cast<OTR::KeyGenerationThread*>(QObject::sender());
-    kDebug() << "Finished generating a new private key for " << thread->accountId;
+    OTR::KeyGenerationWorker *worker = qobject_cast<OTR::KeyGenerationWorker*>(QObject::sender());
+    kDebug() << "Finished generating a new private key for " << worker->accountId;
 
-    if(thread->error() || thread->finalizeCreation()) {
-        kDebug() << "Error generating private key for " << thread->accountId;
-        Q_EMIT keyGenerationFinished(thread->accountId, true);
+    if(worker->error() || worker->finalizeCreation()) {
+        kDebug() << "Error generating private key for " << worker->accountId;
+        Q_EMIT keyGenerationFinished(worker->accountId, true);
     } else{
-        Q_EMIT keyGenerationFinished(thread->accountId, false);
+        Q_EMIT keyGenerationFinished(worker->accountId, false);
     }
 
-    thread->deleteLater();
+    worker->deleteLater();
 }

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list