[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:25 UTC 2016


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

The following commit has been merged in the master branch:
commit 0804133b6725bb6c1e648938ae4a4b6b25ed6a92
Author: Marcin Ziemiński <zieminn at gmail.com>
Date:   Thu Aug 21 22:42:35 2014 +0200

    Extracted files from KTpProxy and ktp-text-ui to form the OTR library
---
 CMakeLists.txt                                   |  17 +-
 KTp/CMakeLists.txt                               |   1 +
 KTp/OTR/CMakeLists.txt                           |  43 ++
 KTp/OTR/channel-adapter.cpp                      | 454 +++++++++++++++
 KTp/OTR/channel-adapter.h                        | 116 ++++
 KTp/OTR/channel-proxy-interface.cpp              |  52 ++
 KTp/OTR/channel-proxy-interface.h                | 691 +++++++++++++++++++++++
 KTp/OTR/constants.h                              | 121 ++++
 KTp/OTR/proxy-service-interface.cpp              |  45 ++
 KTp/OTR/proxy-service-interface.h                | 354 ++++++++++++
 {otr-proxy/KTpProxy => KTp/OTR}/types.cpp        |  14 +-
 {otr-proxy/KTpProxy => KTp/OTR}/types.h          |  44 +-
 KTp/OTR/utils.cpp                                |  87 +++
 KTp/OTR/utils.h                                  |  48 ++
 cmake/modules/FindLibOTR.cmake                   |  36 ++
 cmake/modules/FindLibgcrypt.cmake                |  21 +
 otr-proxy/CMakeLists.txt                         |  33 --
 otr-proxy/KTpProxy/CMakeLists.txt                |   4 +-
 otr-proxy/KTpProxy/constants.h                   |  30 -
 otr-proxy/KTpProxy/main.cpp                      |   9 +-
 otr-proxy/KTpProxy/otr-manager.cpp               |  17 +-
 otr-proxy/KTpProxy/otr-manager.h                 |   5 +-
 otr-proxy/KTpProxy/otr-message.cpp               |   8 +-
 otr-proxy/KTpProxy/otr-proxy-channel-adaptee.cpp |   5 +-
 otr-proxy/KTpProxy/otr-proxy-channel.cpp         |   3 +-
 otr-proxy/KTpProxy/otr-session.cpp               |   6 +-
 otr-proxy/KTpProxy/proxy-service.cpp             |   5 +-
 otr-proxy/KTpProxy/proxy-service.h               |   5 +-
 otr-proxy/KTpProxy/svc-proxy-service.cpp         |   8 +-
 otr-proxy/KTpProxy/svc-proxy-service.h           |   8 +-
 otr-proxy/KTpProxy/types.h                       |  44 --
 otr-proxy/test/CMakeLists.txt                    |   1 +
 otr-proxy/test/otr-test.cpp                      |   7 +-
 33 files changed, 2170 insertions(+), 172 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b19b514..9c16c03 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,7 @@ set (KTP_MESSAGE_FILTER_FRAMEWORK_VERSION "4")
 
 find_package (KDE4 REQUIRED)
 find_package (TelepathyQt4 0.9.2.1 REQUIRED)
+find_package (TelepathyQt4Service 0.9.2.1 REQUIRED)
 find_package (TelepathyLoggerQt4)
 find_package (KPeople 0.2.1)
 find_package (KdepimLibs)
@@ -28,12 +29,14 @@ include (MacroLibrary)
 macro_log_feature(KPEOPLE_FOUND "KPeople" "Support for KDE Contact Aggregation" "https://projects.kde.org/libkpeople" FALSE "" "")
 macro_log_feature(KDEPIMLIBS_FOUND "KDE-PIM Libraries" "Support for Contact Aggregation" "https://projects.kde.org/kdepimlibs" FALSE "" "")
 macro_log_feature(TELEPATHY_LOGGER_QT4_FOUND "TelepatyLoggerQt4" "Qt bindings for TelepathyLogger. This is needed to provide access to chat logs. HIGHLY recommended" "http://projects.kde.org/telepathy-logger-qt" FALSE "" "")
+macro_log_feature(ENABLE_OTR_PROXY "KTpProxy" "DBus service responsible for OTR encryption of text channels" "" FALSE "" "")
 macro_display_feature_log()
 
 
 add_definitions (${KDE4_DEFINITIONS}
                  -DQT_NO_CAST_FROM_ASCII
                  -DQT_NO_KEYWORDS
+                 -std=c++11
 )
 
 include_directories (${KDE4_INCLUDES}
@@ -54,7 +57,6 @@ if (KPEOPLE_FOUND AND KDEPIMLIBS_FOUND)
     add_subdirectory(kpeople)
 endif (KPEOPLE_FOUND AND KDEPIMLIBS_FOUND)
 
-
 configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)
 
 set(KTP_GLOBAL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/global.cpp)
@@ -64,3 +66,16 @@ add_subdirectory(tools)
 add_subdirectory(data)
 add_subdirectory(tests)
 
+if (ENABLE_OTR_PROXY)
+    find_package (LibOTR 4.0.0 REQUIRED)
+    find_package (Libgcrypt REQUIRED)
+    FIND_LIBRARY (LIBGCRYPT_LIBS NAMES gcrypt)
+
+    include_directories (${LIBOTR_INCLUDE_DIR}
+                         ${LIBGCRYPT_INCLUDE_DIR}
+    )
+
+    add_subdirectory(otr-proxy)
+endif (ENABLE_OTR_PROXY)
+
+
diff --git a/KTp/CMakeLists.txt b/KTp/CMakeLists.txt
index 535639f..6a5730e 100644
--- a/KTp/CMakeLists.txt
+++ b/KTp/CMakeLists.txt
@@ -114,6 +114,7 @@ add_subdirectory(Declarative)
 add_subdirectory(Models)
 add_subdirectory(Widgets)
 add_subdirectory(Logger)
+add_subdirectory(OTR)
 
 # API docs
 find_package(Doxygen)
diff --git a/KTp/OTR/CMakeLists.txt b/KTp/OTR/CMakeLists.txt
new file mode 100644
index 0000000..2a927e6
--- /dev/null
+++ b/KTp/OTR/CMakeLists.txt
@@ -0,0 +1,43 @@
+include_directories (${CMAKE_CURRENT_BINARY_DIR}
+                     ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set (ktp_otr_private_SRCS
+    ${KTP_GLOBAL_SOURCES}
+    channel-adapter.cpp
+    channel-proxy-interface.cpp
+    proxy-service-interface.cpp
+    types.cpp
+    utils.cpp
+)
+
+set (ktp_otr_private_HDRS
+    channel-adapter.h
+    channel-proxy-interface.h
+    constants.h
+    proxy-service-interface.h
+    types.h
+    utils.h
+)
+
+kde4_add_library (ktpotrprivate SHARED
+                 ${ktp_otr_private_SRCS}
+)
+
+set_target_properties(ktpotrprivate PROPERTIES
+                                       VERSION ${KTP_VERSION}
+                                       SOVERSION ${KTP_SONUMBER}
+                                       DEFINE_SYMBOL MAKE_KTP_LIB)
+
+target_link_libraries (ktpotrprivate
+                       ${KDE4_KDECORE_LIBS}
+                       ${TELEPATHY_QT4_LIBRARIES}
+)
+
+install (TARGETS ktpotrprivate
+         DESTINATION ${LIB_INSTALL_DIR}
+)
+
+install (FILES ${ktp_otr_private_HDRS}
+         DESTINATION ${INCLUDE_INSTALL_DIR}/KTp/OTR
+)
diff --git a/KTp/OTR/channel-adapter.cpp b/KTp/OTR/channel-adapter.cpp
new file mode 100644
index 0000000..344a43f
--- /dev/null
+++ b/KTp/OTR/channel-adapter.cpp
@@ -0,0 +1,454 @@
+/*
+    Copyright (C) 2014  Marcin Ziemiński   <zieminn at gmail.com>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "channel-adapter.h"
+
+#include "channel-proxy-interface.h"
+#include "utils.h"
+#include "constants.h"
+
+#include <KDebug>
+
+#include <TelepathyQt/SharedPtr>
+#include <TelepathyQt/ReceivedMessage>
+#include <QMap>
+#include <QGenericArgument>
+
+typedef QSharedPointer<KTp::Client::ChannelProxyInterfaceOTRInterface> OTRProxyPtr;
+
+static int getId(const Tp::ReceivedMessage &recvMes)
+{
+    return recvMes.header()[QLatin1String("pending-message-id")].variant().toUInt(NULL);
+}
+
+class OTRMessage : public Tp::ReceivedMessage
+{
+    public:
+        OTRMessage(const Tp::ReceivedMessage &recMes)
+            : Tp::ReceivedMessage(recMes)
+        {
+        }
+
+        OTRMessage(const Tp::MessagePartList &message, const Tp::TextChannelPtr channel)
+            : Tp::ReceivedMessage(message, channel)
+        {
+            setSender(channel->targetContact());
+        }
+
+        bool hasId() const
+        {
+            return header().contains(QLatin1String("pending-message-id"));
+        }
+
+        int getId() const
+        {
+            return ::getId(*this);
+        }
+
+        void setId(int id)
+        {
+            header()[QLatin1String("pending-message-id")] = QDBusVariant(id);
+        }
+
+        void setSender(const Tp::ContactPtr &contact)
+        {
+            ReceivedMessage::setSender(contact);
+        }
+};
+
+namespace KTp {
+
+struct ChannelAdapter::Private
+{
+    Private()
+        : otrConnected(false),
+        trustLevel(KTp::OTRTrustLevelNotPrivate)
+    {
+    }
+
+    Tp::TextChannelPtr textChannel;
+    OTRProxyPtr otrProxy;
+
+    bool otrConnected;
+    KTp::OTRTrustLevel trustLevel;
+    QString remoteFp;
+
+    QMap<uint, OTRMessage> messages;
+    QMap<uint, OTRMessage> otrEvents;
+};
+
+ChannelAdapter::ChannelAdapter(const Tp::TextChannelPtr &textChannel, QObject *parent)
+    : QObject(parent),
+    d(new Private())
+{
+    setChannel(textChannel);
+}
+
+ChannelAdapter::~ChannelAdapter()
+{
+    delete d;
+}
+
+bool ChannelAdapter::isValid() const
+{
+    return d->textChannel->isValid();
+}
+
+void ChannelAdapter::setChannel(const Tp::TextChannelPtr &textChannel)
+{
+    d->textChannel = textChannel;
+    QDBusConnection dbusConnection = textChannel->dbusConnection();
+    if(textChannel->targetHandleType() != Tp::HandleTypeContact ||
+            !dbusConnection.interface()->isServiceRegistered(KTP_PROXY_BUS_NAME))
+    {
+        setupTextChannel();
+        return;
+    }
+
+    QString otrProxyPath = KTp::Utils::getOtrProxyObjectPathFor(textChannel);
+    d->otrProxy = OTRProxyPtr(new KTp::Client::ChannelProxyInterfaceOTRInterface(KTP_PROXY_BUS_NAME, otrProxyPath, this));
+
+    if(!d->otrProxy->isValid()) {
+        kDebug() << "No OTR proxy available for channel: " << textChannel->objectPath();
+        setupTextChannel();
+        return;
+    }
+
+    kDebug() << "Connecting to the OTR proxy: " << d->otrProxy->path();
+    QDBusPendingReply<> connectResult = d->otrProxy->ConnectProxy();
+    connectResult.waitForFinished();
+    if(connectResult.isValid()) {
+        setupOTRChannel();
+    } else {
+        kWarning() << "Could not connect to the proxy" << connectResult.error().message();
+        setupTextChannel();
+    }
+}
+
+Tp::TextChannelPtr ChannelAdapter::textChannel()
+{
+    return d->textChannel;
+}
+
+void ChannelAdapter::setupTextChannel()
+{
+    kDebug();
+    connect(d->textChannel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)),
+            SIGNAL(messageReceived(Tp::ReceivedMessage)));
+    connect(d->textChannel.data(), SIGNAL(pendingMessageRemoved(Tp::ReceivedMessage)),
+            SIGNAL(pendingMessageRemoved(Tp::ReceivedMessage)));
+    connect(d->textChannel.data(), SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
+            SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
+}
+
+void ChannelAdapter::setupOTRChannel()
+{
+    kDebug();
+    d->otrConnected = true;
+    d->trustLevel = KTp::OTRTrustLevelNotPrivate;
+
+    connect(d->otrProxy.data(), SIGNAL(SessionRefreshed()), SIGNAL(sessionRefreshed()));
+    connect(d->otrProxy.data(), SIGNAL(MessageReceived(const Tp::MessagePartList&)),
+            SLOT(onMessageReceived(const Tp::MessagePartList&)));
+    connect(d->otrProxy.data(), SIGNAL(PendingMessagesRemoved(const Tp::UIntList&)),
+            SLOT(onPendingMessagesRemoved(const Tp::UIntList&)));
+    connect(d->otrProxy.data(), SIGNAL(MessageSent(const Tp::MessagePartList&, uint, const QString&)),
+            SLOT(onMessageSent(const Tp::MessagePartList&, uint, const QString&)));
+    connect(d->otrProxy.data(), SIGNAL(TrustLevelChanged(uint)), SLOT(onTrustLevelChanged(uint)));
+
+    // smp protocol
+    connect(d->otrProxy.data(), SIGNAL(PeerAuthenticationRequested(const QString&)),
+           SLOT(onPeerAuthenticationRequested(const QString&)));
+    connect(d->otrProxy.data(), SIGNAL(PeerAuthenticationConcluded(bool)),
+           SIGNAL(peerAuthenticationConcluded(bool)));
+    connect(d->otrProxy.data(), SIGNAL(PeerAuthenticationInProgress()),
+           SIGNAL(peerAuthenticationInProgress()));
+    connect(d->otrProxy.data(), SIGNAL(PeerAuthenticationAborted()),
+           SIGNAL(peerAuthenticationAborted()));
+    connect(d->otrProxy.data(), SIGNAL(PeerAuthenticationError()),
+           SIGNAL(peerAuthenticationError()));
+    connect(d->otrProxy.data(), SIGNAL(PeerAuthenticationCheated()),
+           SIGNAL(peerAuthenticationCheated()));
+
+    // initialize message queue;
+    connect(d->otrProxy->requestPropertyPendingMessages(), SIGNAL(finished(Tp::PendingOperation*)),
+                SLOT(onPendingMessagesPropertyGet(Tp::PendingOperation*)));
+    // initialize trust level property
+    connect(d->otrProxy->requestPropertyTrustLevel(), SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(onTrustLevelPropertyGet(Tp::PendingOperation*)));
+    // initialize remote fingerprint property
+    connect(d->otrProxy->requestPropertyRemoteFingerprint(), SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(onRemoteFingerprintPropertyGet(Tp::PendingOperation*)));
+}
+
+KTp::OTRTrustLevel ChannelAdapter::otrTrustLevel() const
+{
+    return d->trustLevel;
+}
+
+void ChannelAdapter::onTrustLevelPropertyGet(Tp::PendingOperation *op)
+{
+    if(op->isError()) {
+        kWarning() << "Could not get property: TrustLevel";
+        return;
+    }
+    // we must have received trust level changed signal before
+    if(d->trustLevel != KTp::OTRTrustLevelNotPrivate) {
+        return;
+    }
+    Tp::PendingVariant *pv = dynamic_cast<Tp::PendingVariant*>(op);
+    d->trustLevel = static_cast<KTp::OTRTrustLevel>(pv->result().toUInt(NULL));
+    Q_EMIT otrTrustLevelChanged(d->trustLevel, KTp::OTRTrustLevelNotPrivate);
+}
+
+bool ChannelAdapter::isOTRsuppored() const
+{
+    return d->otrConnected;
+}
+
+void ChannelAdapter::initializeOTR()
+{
+    kDebug() << "Initializing OTR session";
+    d->otrProxy->Initialize();
+}
+
+void ChannelAdapter::stopOTR()
+{
+    kDebug();
+    d->otrProxy->Stop();
+}
+
+QString ChannelAdapter::remoteFingerprint() const
+{
+    return d->remoteFp;
+}
+
+QDBusPendingReply<> ChannelAdapter::trustFingerprint(const QString &fingerprint, bool trust)
+{
+    return d->otrProxy->TrustFingerprint(fingerprint, trust);
+}
+
+void ChannelAdapter::acknowledge(const QList<Tp::ReceivedMessage> &messages)
+{
+    if(messages.isEmpty()) {
+        return;
+    }
+
+    kDebug();
+    if(isOTRsuppored()) {
+        QList<Tp::ReceivedMessage> toAck;
+        QList<Tp::ReceivedMessage> eventsToRemove;
+
+        Q_FOREACH(const Tp::ReceivedMessage &mes, messages) {
+            if(KTp::Utils::isOtrEvent(mes)) {
+                d->otrEvents.remove(getId(mes));
+                eventsToRemove << mes;
+            } else {
+                toAck << mes;
+            }
+        }
+        d->otrProxy->AcknowledgePendingMessages(KTp::Utils::getPendingMessagesIDs(toAck));
+        Q_FOREACH(const Tp::ReceivedMessage &mes, eventsToRemove) {
+            Q_EMIT pendingMessageRemoved(mes);
+        }
+    } else {
+        d->textChannel->acknowledge(messages);
+    }
+}
+
+void ChannelAdapter::send(const QString& text, Tp::ChannelTextMessageType type, Tp::MessageSendingFlags flags)
+{
+    if(isOTRsuppored()) {
+        Tp::MessagePartList parts;
+        parts << Tp::MessagePart() << Tp::MessagePart();
+        parts[0].insert(QLatin1String("message-type"),
+                QDBusVariant(type));
+        parts[1].insert(QLatin1String("content-type"),
+                QDBusVariant(QLatin1String("text/plain")));
+        parts[1].insert(QLatin1String("content"), QDBusVariant(text));
+
+        d->otrProxy->SendMessage(parts, (uint) flags);
+    } else {
+        d->textChannel->send(text, type, flags);
+    }
+}
+
+bool ChannelAdapter::supportsMessageType(Tp::ChannelTextMessageType messageType) const
+{
+    return d->textChannel->supportsMessageType(messageType);
+}
+
+QList<Tp::ChannelTextMessageType> ChannelAdapter::supportedMessageTypes() const
+{
+    return d->textChannel->supportedMessageTypes();
+}
+
+QStringList ChannelAdapter::supportedContentTypes() const
+{
+    return d->textChannel->supportedContentTypes();
+}
+
+Tp::MessagePartSupportFlags ChannelAdapter::messagePartSupport() const
+{
+    return d->textChannel->messagePartSupport();
+}
+
+Tp::DeliveryReportingSupportFlags ChannelAdapter::deliveryReportingSupport() const
+{
+    return d->textChannel->deliveryReportingSupport();
+}
+
+QList<Tp::ReceivedMessage> ChannelAdapter::messageQueue() const
+{
+    if(isOTRsuppored()) {
+        QList<Tp::ReceivedMessage> messages;
+        Q_FOREACH(const Tp::ReceivedMessage &m, d->messages) {
+            messages << m;
+        }
+        Q_FOREACH(const Tp::ReceivedMessage &m, d->otrEvents) {
+            messages << m;
+        }
+        return messages;
+    } else {
+        return d->textChannel->messageQueue();
+    }
+}
+
+void ChannelAdapter::onMessageReceived(const Tp::MessagePartList &message)
+{
+    kDebug();
+    OTRMessage recvMes(message, d->textChannel);
+    if(recvMes.hasId()) {
+        const int id = recvMes.getId();
+        if(!d->messages.contains(id)) {
+            d->messages.insert(id, recvMes);
+            Q_EMIT messageReceived(recvMes);
+        } else {
+            kWarning() << "Message already in the queue. Id: " << id;
+        }
+    } else if (KTp::Utils::isOtrEvent(recvMes)) {
+        const int id = d->otrEvents.size();
+        recvMes.setId(d->otrEvents.size());
+        d->otrEvents.insert(id, recvMes);
+        Q_EMIT messageReceived(recvMes);
+    } else {
+        kWarning() << "Message has not id and is not an OTR event either";
+    }
+}
+
+void ChannelAdapter::onPendingMessagesPropertyGet(Tp::PendingOperation *op)
+{
+    kDebug();
+    Tp::PendingVariant *variant = dynamic_cast<Tp::PendingVariant*>(op);
+
+    if(!variant->isError()) {
+        QDBusArgument dbusArgument = variant->result().value<QDBusArgument>();
+        Tp::MessagePartListList pendingMessages;
+        dbusArgument >> pendingMessages;
+        Q_FOREACH(const Tp::MessagePartList &message, pendingMessages) {
+            onMessageReceived(message);
+        }
+    } else {
+        kWarning() << "Could not initialize message queue: " << variant->errorName() << " - "
+            << variant->errorMessage();
+    }
+}
+
+void ChannelAdapter::onRemoteFingerprintPropertyGet(Tp::PendingOperation *op)
+{
+    kDebug();
+    Tp::PendingVariant *variant = dynamic_cast<Tp::PendingVariant*>(op);
+
+    if(!variant->isError()) {
+        d->remoteFp = variant->result().toString();
+    } else {
+        kWarning() << "Could not get remote fingerprint: " << variant->errorName() << " - "
+            << variant->errorMessage();
+    }
+}
+
+void ChannelAdapter::onPendingMessagesRemoved(const Tp::UIntList &messageIDs)
+{
+    kDebug();
+    Q_FOREACH(uint id, messageIDs) {
+        const QMap<uint, OTRMessage>::Iterator mIt = d->messages.find(id);
+        if(mIt != d->messages.end()) {
+            OTRMessage message = *mIt;
+            d->messages.erase(mIt);
+            Q_EMIT pendingMessageRemoved(message);
+        } else {
+            kWarning() << "No message to remove with id: " << id;
+        }
+    }
+}
+
+void ChannelAdapter::onMessageSent(const Tp::MessagePartList &content, uint flags, const QString &messageToken)
+{
+    kDebug();
+    OTRMessage message(content, d->textChannel);
+    Q_EMIT messageSent(message, Tp::MessageSendingFlags(flags), messageToken);
+}
+
+void ChannelAdapter::onTrustLevelChanged(uint trustLevel)
+{
+    KTp::OTRTrustLevel oldLevel = d->trustLevel;
+    d->trustLevel = static_cast<KTp::OTRTrustLevel>(trustLevel);
+    // get remote's fingerprint
+    if(oldLevel == KTp::OTRTrustLevelNotPrivate) {
+        connect(d->otrProxy->requestPropertyRemoteFingerprint(), SIGNAL(finished(Tp::PendingOperation*)),
+                SLOT(onRemoteFingerprintPropertyGet(Tp::PendingOperation*)));
+    }
+
+    // it may be a new session and the fingerprint has to be updated
+    if(d->trustLevel == KTp::OTRTrustLevelPrivate || d->trustLevel == KTp::OTRTrustLevelUnverified) {
+        connect(d->otrProxy->requestPropertyRemoteFingerprint(), SIGNAL(finished(Tp::PendingOperation*)),
+                SLOT(onRemoteFingerprintPropertyGet(Tp::PendingOperation*)));
+    }
+
+    Q_EMIT otrTrustLevelChanged(d->trustLevel, oldLevel);
+}
+
+void ChannelAdapter::onPeerAuthenticationRequested(const QString &question)
+{
+    if(question.isEmpty()) {
+        Q_EMIT peerAuthenticationRequestedSS();
+    } else {
+        Q_EMIT peerAuthenticationRequestedQA(question);
+    }
+}
+
+void ChannelAdapter::startPeerAuthenticationQA(const QString &question, const QString &answer)
+{
+    d->otrProxy->StartPeerAuthentication(question, answer);
+}
+
+void ChannelAdapter::startPeerAuthenticationSS(const QString &secret)
+{
+    startPeerAuthenticationQA(QLatin1String(""), secret);
+}
+
+void ChannelAdapter::respondPeerAuthentication(const QString &secret)
+{
+    d->otrProxy->RespondPeerAuthentication(secret);
+}
+
+void ChannelAdapter::abortPeerAuthentication()
+{
+    d->otrProxy->AbortPeerAuthentication();
+}
+
+} /* namespace KTp */
diff --git a/KTp/OTR/channel-adapter.h b/KTp/OTR/channel-adapter.h
new file mode 100644
index 0000000..9b47473
--- /dev/null
+++ b/KTp/OTR/channel-adapter.h
@@ -0,0 +1,116 @@
+/*
+    Copyright (C) 2014  Marcin Ziemiński   <zieminn at gmail.com>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef OTR_CHANNEL_ADAPTER_HEADER
+#define OTR_CHANNEL_ADAPTER_HEADER
+
+#include "types.h"
+#include "constants.h"
+
+#include "KTp/ktp-export.h"
+
+#include <QObject>
+
+#include <TelepathyQt/Types>
+#include <TelepathyQt/TextChannel>
+#include <TelepathyQt/PendingOperation>
+#include <TelepathyQt/RefCounted>
+
+namespace KTp {
+
+class KTP_EXPORT ChannelAdapter : public QObject, public Tp::RefCounted
+{
+    Q_OBJECT
+
+    public:
+        ChannelAdapter(const Tp::TextChannelPtr &textChannel, QObject *parent = 0);
+        ~ChannelAdapter();
+
+        Tp::TextChannelPtr textChannel();
+
+        KTp::OTRTrustLevel otrTrustLevel() const;
+        bool isOTRsuppored() const;
+        QString remoteFingerprint() const;
+        QDBusPendingReply<> trustFingerprint(const QString &fingerprint, bool trust);
+
+        bool isValid() const;
+
+        void initializeOTR();
+        void stopOTR();
+        /** question answer peer authentication */
+        void startPeerAuthenticationQA(const QString &question, const QString &answer);
+        /** shared secret peer authentication*/
+        void startPeerAuthenticationSS(const QString &secret);
+        void respondPeerAuthentication(const QString &secret);
+        void abortPeerAuthentication();
+
+        void acknowledge(const QList<Tp::ReceivedMessage> &messages);
+        void send(const QString& text,
+                Tp::ChannelTextMessageType type = Tp::ChannelTextMessageTypeNormal,
+                Tp::MessageSendingFlags flags = 0);
+
+        bool supportsMessageType(Tp::ChannelTextMessageType messageType) const;
+        QList<Tp::ChannelTextMessageType> supportedMessageTypes() const;
+        QStringList supportedContentTypes() const;
+        Tp::MessagePartSupportFlags messagePartSupport() const;
+        Tp::DeliveryReportingSupportFlags deliveryReportingSupport() const;
+
+        QList<Tp::ReceivedMessage> messageQueue() const;
+
+    private:
+        void setChannel(const Tp::TextChannelPtr &textChannel);
+        void setupOTRChannel();
+        void setupTextChannel();
+
+    private Q_SLOTS:
+        void onTrustLevelPropertyGet(Tp::PendingOperation *op);
+        void onPendingMessagesPropertyGet(Tp::PendingOperation *op);
+        void onRemoteFingerprintPropertyGet(Tp::PendingOperation *op);
+        void onMessageReceived(const Tp::MessagePartList &message);
+        void onPendingMessagesRemoved(const Tp::UIntList &messageIDs);
+        void onMessageSent(const Tp::MessagePartList &content, uint flags, const QString &messageToken);
+        void onTrustLevelChanged(uint trustLevel);
+        void onPeerAuthenticationRequested(const QString &question);
+
+    Q_SIGNALS:
+        void messageSent(const Tp::Message &message,
+                Tp::MessageSendingFlags flags,
+                const QString &sentMessageToken);
+        void messageReceived(const Tp::ReceivedMessage &message);
+        void pendingMessageRemoved( const Tp::ReceivedMessage &message);
+
+        void otrTrustLevelChanged(KTp::OTRTrustLevel newStatus, KTp::OTRTrustLevel oldStatus);
+        void sessionRefreshed();
+        void peerAuthenticationRequestedQA(const QString &question);
+        void peerAuthenticationRequestedSS();
+        void peerAuthenticationConcluded(bool authenticated);
+        void peerAuthenticationInProgress();
+        void peerAuthenticationAborted();
+        void peerAuthenticationError();
+        void peerAuthenticationCheated();
+
+    private:
+        struct Private;
+        friend struct Private;
+        Private *d;
+};
+
+typedef Tp::SharedPtr<ChannelAdapter> ChannelAdapterPtr;
+
+} /* namespace KTp */
+
+#endif
diff --git a/KTp/OTR/channel-proxy-interface.cpp b/KTp/OTR/channel-proxy-interface.cpp
new file mode 100644
index 0000000..61da714
--- /dev/null
+++ b/KTp/OTR/channel-proxy-interface.cpp
@@ -0,0 +1,52 @@
+#define IN_TP_QT_HEADER
+#include "channel-proxy-interface.h"
+
+namespace KTp
+{
+namespace Client
+{
+
+ChannelProxyInterfaceOTRInterface::ChannelProxyInterfaceOTRInterface(const QString& busName, const QString& objectPath, QObject *parent)
+    : Tp::AbstractInterface(busName, objectPath, staticInterfaceName(), QDBusConnection::sessionBus(), parent)
+{
+}
+
+ChannelProxyInterfaceOTRInterface::ChannelProxyInterfaceOTRInterface(const QDBusConnection& connection, const QString& busName, const QString& objectPath, QObject *parent)
+    : Tp::AbstractInterface(busName, objectPath, staticInterfaceName(), connection, parent)
+{
+}
+
+ChannelProxyInterfaceOTRInterface::ChannelProxyInterfaceOTRInterface(Tp::DBusProxy *proxy)
+    : Tp::AbstractInterface(proxy, staticInterfaceName())
+{
+}
+
+ChannelProxyInterfaceOTRInterface::ChannelProxyInterfaceOTRInterface(const Tp::AbstractInterface& mainInterface)
+    : Tp::AbstractInterface(mainInterface.service(), mainInterface.path(), staticInterfaceName(), mainInterface.connection(), mainInterface.parent())
+{
+}
+
+ChannelProxyInterfaceOTRInterface::ChannelProxyInterfaceOTRInterface(const Tp::AbstractInterface& mainInterface, QObject *parent)
+    : Tp::AbstractInterface(mainInterface.service(), mainInterface.path(), staticInterfaceName(), mainInterface.connection(), parent)
+{
+}
+
+void ChannelProxyInterfaceOTRInterface::invalidate(Tp::DBusProxy *proxy,
+        const QString &error, const QString &message)
+{
+    disconnect(this, SIGNAL(MessageSent(const Tp::MessagePartList&, uint, const QString&)), NULL, NULL);
+    disconnect(this, SIGNAL(MessageReceived(const Tp::MessagePartList&)), NULL, NULL);
+    disconnect(this, SIGNAL(PendingMessagesRemoved(const Tp::UIntList&)), NULL, NULL);
+    disconnect(this, SIGNAL(PeerAuthenticationRequested(const QString&)), NULL, NULL);
+    disconnect(this, SIGNAL(PeerAuthenticationConcluded(bool)), NULL, NULL);
+    disconnect(this, SIGNAL(PeerAuthenticationInProgress()), NULL, NULL);
+    disconnect(this, SIGNAL(PeerAuthenticationAborted()), NULL, NULL);
+    disconnect(this, SIGNAL(PeerAuthenticationError()), NULL, NULL);
+    disconnect(this, SIGNAL(PeerAuthenticationCheated()), NULL, NULL);
+    disconnect(this, SIGNAL(SessionRefreshed()), NULL, NULL);
+    disconnect(this, SIGNAL(TrustLevelChanged(uint)), NULL, NULL);
+
+    Tp::AbstractInterface::invalidate(proxy, error, message);
+}
+}
+}
diff --git a/KTp/OTR/channel-proxy-interface.h b/KTp/OTR/channel-proxy-interface.h
new file mode 100644
index 0000000..1f5d980
--- /dev/null
+++ b/KTp/OTR/channel-proxy-interface.h
@@ -0,0 +1,691 @@
+/*
+ * This file contains D-Bus client proxy classes generated by qt-client-gen.py.
+ *
+ * This file can be distributed under the same terms as the specification from
+ * which it was generated.
+ */
+
+#ifndef OTR_CHANNEL_PROXY_HEADER
+#define OTR_CHANNEL_PROXY_HEADER
+
+#include "KTp/ktp-export.h"
+
+#include <QtGlobal>
+
+#include <QString>
+#include <QObject>
+#include <QVariant>
+
+#include <QDBusPendingReply>
+
+#include <TelepathyQt/Types>
+#include <TelepathyQt/AbstractInterface>
+#include <TelepathyQt/DBusProxy>
+#include <TelepathyQt/Global>
+
+namespace Tp
+{
+class PendingVariant;
+class PendingOperation;
+}
+
+namespace KTp
+{
+namespace Client
+{
+
+/**
+ * 
-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list