[telepathy-qt4/master] OutgoingFileTransferChannel: Added Port access control support.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue Sep 22 20:04:25 PDT 2009


---
 TelepathyQt4/outgoing-file-transfer-channel.cpp |   41 ++++++++++++++++++++--
 1 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/TelepathyQt4/outgoing-file-transfer-channel.cpp b/TelepathyQt4/outgoing-file-transfer-channel.cpp
index ed89cda..ad3e7a3 100644
--- a/TelepathyQt4/outgoing-file-transfer-channel.cpp
+++ b/TelepathyQt4/outgoing-file-transfer-channel.cpp
@@ -31,6 +31,7 @@
 #include <TelepathyQt4/Types>
 
 #include <QIODevice>
+#include <QTcpServer>
 #include <QTcpSocket>
 
 namespace Tp
@@ -49,6 +50,7 @@ struct OutgoingFileTransferChannel::Private
     // Introspection
     QIODevice *input;
     QTcpSocket *socket;
+    SocketAccessControl accessControl;
     SocketAddressIPv4 addr;
 
     qint64 pos;
@@ -161,11 +163,36 @@ PendingOperation *OutgoingFileTransferChannel::provideFile(QIODevice *input)
             SIGNAL(aboutToClose()),
             SLOT(onInputAboutToClose()));
 
+    QDBusVariant accessControlParam;
+    SupportedSocketMap socketTypes = availableSocketTypes();
+    UIntList addressTypeList = socketTypes.value(SocketAddressTypeIPv4);
+    if (addressTypeList.contains(SocketAccessControlPort)) {
+        debug() << "Using SocketAccessControlPort";
+
+        QTcpServer tcpServer;
+        tcpServer.listen(QHostAddress("127.0.0.1"));
+        quint16 port = tcpServer.serverPort();
+        tcpServer.close();
+
+        SocketAddressIPv4 addr;
+        addr.address = "127.0.0.1";
+        addr.port = port;
+
+        mPriv->accessControl = SocketAccessControlPort;
+        // set port here
+        mPriv->addr.port = port;
+        accessControlParam.setVariant(qVariantFromValue(addr));
+    } else {
+        debug() << "Using SocketAccessControlLocalhost";
+
+        mPriv->accessControl = SocketAccessControlLocalhost;
+        accessControlParam = QDBusVariant(QVariant(QString()));
+    }
+
     PendingVariant *pv = new PendingVariant(
             fileTransferInterface(BypassInterfaceCheck)->ProvideFile(
                 SocketAddressTypeIPv4,
-                SocketAccessControlLocalhost,
-                QDBusVariant(QVariant(QString()))),
+                mPriv->accessControl, accessControlParam),
             this);
     connect(pv,
             SIGNAL(finished(Tp::PendingOperation*)),
@@ -182,8 +209,14 @@ void OutgoingFileTransferChannel::onProvideFileFinished(PendingOperation *op)
         return;
     }
 
-    PendingVariant *pv = qobject_cast<PendingVariant *>(op);
-    mPriv->addr = qdbus_cast<SocketAddressIPv4>(pv->result());
+    if (mPriv->accessControl == SocketAccessControlLocalhost) {
+        PendingVariant *pv = qobject_cast<PendingVariant *>(op);
+        mPriv->addr = qdbus_cast<SocketAddressIPv4>(pv->result());
+    } else {
+        mPriv->addr.address = "127.0.0.1";
+        // the port was already set in provideFile
+    }
+
     debug().nospace() << "Got address " << mPriv->addr.address <<
         ":" << mPriv->addr.port;
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list