[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kio
From:       Michael Leupold <lemma () confuego ! org>
Date:       2009-04-17 16:28:32
Message-ID: 1239985712.825873.3527.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 955430 by mleupold:

Make KIO::SlaveBase use the new async kpasswdserver calls.
Prepare KIO::AuthInfo for marshalling as QDBusArgument.

 M  +1 -0      CMakeLists.txt  
 M  +62 -0     kio/authinfo.cpp  
 M  +18 -1     kio/authinfo.h  
 A             kio/passwdserverloop.cpp   [License: LGPL (v2)]
 A             kio/passwdserverloop_p.h   [License: LGPL (v2)]
 M  +58 -43    kio/slavebase.cpp  


--- trunk/KDE/kdelibs/kio/CMakeLists.txt #955429:955430
@@ -125,6 +125,7 @@
   kio/thumbsequencecreator.cpp
   kio/udsentry.cpp
   kio/hostinfo.cpp
+  kio/passwdserverloop.cpp
 )
 
 qt4_add_dbus_adaptor(kiocore_STAT_SRCS kio/org.kde.kio.FileUndoManager.xml \
fileundomanager_p.h KIO::FileUndoManagerPrivate fileundomanager_adaptor \
                KIOFileUndoManagerAdaptor)
--- trunk/KDE/kdelibs/kio/kio/authinfo.cpp #955429:955430
@@ -31,6 +31,8 @@
 #include <QtCore/QByteArray>
 #include <QtCore/QDir>
 #include <QtCore/QFile>
+#include <QtDBus/QDBusArgument>
+#include <QtDBus/QDBusMetaType>
 #include <kde_file.h>
 
 #include <kdebug.h>
@@ -52,6 +54,7 @@
 
     ExtraField() : flags(AuthInfo::ExtraFieldNoFlags) {}
 };
+Q_DECLARE_METATYPE(ExtraField)
 
 QDataStream& operator<< (QDataStream& s, const ExtraField& extraField)
 {
@@ -71,7 +74,29 @@
     return s;
 }
 
+QDBusArgument &operator<<(QDBusArgument &argument, const ExtraField &extraField)
+{
+    argument.beginStructure();
+    argument << extraField.customTitle << (int)extraField.flags
+             << QDBusVariant(extraField.value);
+    argument.endStructure();
+    return argument;
+}
 
+const QDBusArgument &operator>>(const QDBusArgument &argument, ExtraField \
&extraField) +{
+    QDBusVariant value;
+    int flag;
+    
+    argument.beginStructure();
+    argument >> extraField.customTitle >> flag >> value;
+    argument.endStructure();
+
+    extraField.value = value.variant();
+    extraField.flags = (KIO::AuthInfo::FieldFlags)flag;
+    return argument;
+}
+
 class KIO::AuthInfoPrivate  
 {
 public:
@@ -90,6 +115,7 @@
     readOnly = false;
     verifyPath = false;
     keepPassword = false;
+    AuthInfo::registerMetaTypes();
 }
 
 AuthInfo::AuthInfo( const AuthInfo& info ) : d(new AuthInfoPrivate())
@@ -155,6 +181,14 @@
     return d->extraFields[fieldName].flags; 
 }
 
+void AuthInfo::registerMetaTypes()
+{
+    qRegisterMetaType<ExtraField>();
+    qRegisterMetaType<KIO::AuthInfo>();
+    qDBusRegisterMetaType<ExtraField>();
+    qDBusRegisterMetaType<KIO::AuthInfo>();
+}
+
 /////
 
 QDataStream& KIO::operator<< (QDataStream& s, const AuthInfo& a)
@@ -178,7 +212,35 @@
     return s;
 }
 
+QDBusArgument &KIO::operator<<(QDBusArgument &argument, const AuthInfo &a)
+{
+    argument.beginStructure();
+    argument << (quint8)1
+             << a.url.url() << a.username << a.password << a.prompt << a.caption
+             << a.comment << a.commentLabel << a.realmValue << a.digestInfo
+             << a.verifyPath << a.readOnly << a.keepPassword << a.modified
+             << a.d->extraFields;
+    argument.endStructure();
+    return argument;
+}
 
+const QDBusArgument &KIO::operator>>(const QDBusArgument &argument, AuthInfo &a)
+{
+    QString url;
+    quint8 version;
+    
+    argument.beginStructure();
+    argument >> version
+             >> url >> a.username >> a.password >> a.prompt >> a.caption
+             >> a.comment >> a.commentLabel >> a.realmValue >> a.digestInfo
+             >> a.verifyPath >> a.readOnly >> a.keepPassword >> a.modified
+             >> a.d->extraFields;
+    argument.endStructure();
+
+    a.url = url;
+    return argument;
+}
+
 typedef QList<NetRC::AutoLogin> LoginList;
 typedef QMap<QString, LoginList> LoginMap;
 
--- trunk/KDE/kdelibs/kio/kio/authinfo.h #955429:955430
@@ -28,6 +28,8 @@
 #include <QtCore/QStringList>
 #include <kurl.h>
 
+class QDBusArgument;
+
 namespace KIO {
 
 class AuthInfoPrivate;
@@ -57,6 +59,9 @@
     KIO_EXPORT friend QDataStream& operator<< (QDataStream& s, const AuthInfo& a);
     KIO_EXPORT friend QDataStream& operator>> (QDataStream& s, AuthInfo& a);
 
+    KIO_EXPORT friend QDBusArgument &operator<<(QDBusArgument &argument, const \
AuthInfo &a); +    KIO_EXPORT friend const QDBusArgument &operator>>(const \
QDBusArgument &argument, AuthInfo &a); +
 public:
     
    /**
@@ -239,7 +244,7 @@
        ExtraFieldNoFlags = 0,
        ExtraFieldReadOnly = 1<<1,
        ExtraFieldMandatory = 1<<2
-   };   
+   };
    
    /**
     * Set Extra Field Value. 
@@ -270,6 +275,14 @@
     * @since 4.1
     */
    AuthInfo::FieldFlags getExtraFieldFlags(const QString &fieldName) const;
+
+   /**
+    * Register the meta-types for AuthInfo. This is called from
+    * AuthInfo's constructor but needed by daemons on the DBus such
+    * as kpasswdserver.
+    * @since 4.3
+    */
+   static void registerMetaTypes();
    
 protected:
     bool modified;
@@ -281,6 +294,9 @@
 KIO_EXPORT QDataStream& operator<< (QDataStream& s, const AuthInfo& a);
 KIO_EXPORT QDataStream& operator>> (QDataStream& s, AuthInfo& a);
 
+KIO_EXPORT QDBusArgument &operator<<(QDBusArgument &argument, const AuthInfo &a);
+KIO_EXPORT const QDBusArgument &operator>>(const QDBusArgument &argument, AuthInfo \
&a); +
 /**
  * A Singleton class that provides access to passwords
  * stored in .netrc files for automatic login purposes.
@@ -367,5 +383,6 @@
 };
 }
 Q_DECLARE_OPERATORS_FOR_FLAGS(KIO::NetRC::LookUpMode)
+Q_DECLARE_METATYPE(KIO::AuthInfo)
 
 #endif
--- trunk/KDE/kdelibs/kio/kio/slavebase.cpp #955429:955430
@@ -52,6 +52,7 @@
 #include "connection.h"
 #include "ioslave_defaults.h"
 #include "slaveinterface.h"
+#include "passwdserverloop_p.h"
 
 #ifndef NDEBUG
 #ifdef HAVE_BACKTRACE
@@ -820,45 +821,52 @@
 
 bool SlaveBase::openPasswordDialog( AuthInfo& info, const QString &errorMsg )
 {
-    AuthInfo authResult;
     const long windowId = metaData("window-id").toLong();
     const unsigned long userTimestamp = metaData("user-timestamp").toULong();
 
     kDebug(7019) << "window-id=" << windowId;
 
-    QDBusInterface kps( "org.kde.kded", "/modules/kpasswdserver", \
"org.kde.KPasswdServer" ); +    QDBusConnection conn(QDBusConnection::sessionBus());
+    QDBusMessage pscall(QDBusMessage::createMethodCall("org.kde.kded",
+                                                       "/modules/kpasswdserver",
+                                                       "org.kde.KPasswdServer",
+                                                       "queryAuthInfoAsync"));
+    QDBusArgument arg;
+    arg << info;
+    pscall << QVariant::fromValue(arg);
+    if (metaData("no-auth-prompt").toLower() == "true") {
+        pscall << QString(QLatin1String("<NoAuthPrompt>"));
+    } else {
+        pscall << errorMsg;
+    }
+    pscall << qlonglong(windowId) << SlaveBasePrivate::s_seqNr
+           << qlonglong(userTimestamp);
 
-    // #### TODO rewrite this with QDBusArgument streaming operators
-    // and QDBusReply.
-    QByteArray data;
-    QDataStream stream(&data, QIODevice::WriteOnly);
-    stream << info;
-    QDBusMessage reply;
+    // create the loop to wait for a result before sending the request
+    // because the result signal has to be connected before. Else we might
+    // actually miss a result signal.
+    PasswdServerLoop loop;
+    conn.connect("", "/modules/kpasswdserver", "org.kde.KPasswdServer",
+                 "queryAuthInfoAsyncResult", &loop,
+                 SLOT(slotQueryResult(qlonglong, qlonglong, const KIO::AuthInfo&)));
 
-    if (metaData("no-auth-prompt").toLower() == "true")
-       reply = kps.call(QDBus::Block, "queryAuthInfo", data, \
                QString(QLatin1String("<NoAuthPrompt>")),
-                         qlonglong(windowId), SlaveBasePrivate::s_seqNr, \
                qlonglong(userTimestamp));
-    else
-       reply = kps.call(QDBus::Block, "queryAuthInfo", data, errorMsg, \
                qlonglong(windowId),
-                        SlaveBasePrivate::s_seqNr, qlonglong(userTimestamp));
-
-    bool callOK = reply.type() == QDBusMessage::ReplyMessage;
-
-    if (!callOK)
+    QDBusReply<qlonglong> reply = conn.call(pscall, QDBus::Block);
+    if (!reply.isValid())
     {
        kWarning(7019) << "Can't communicate with kded_kpasswdserver (for \
                queryAuthInfo)!";
-       kDebug(7019) << reply.arguments().at(0).toString();
+       kDebug(7019) << reply.error().name() << reply.error().message();
        return false;
     }
+    if (!loop.waitForResult(reply.value())) {
+        kWarning(7019) << "kded_kpasswdserver died while waiting for reply!";
+        return false;
+    }
 
-    QDataStream stream2( reply.arguments().at(0).toByteArray() );
-    stream2 >> authResult;
-    SlaveBasePrivate::s_seqNr = reply.arguments().at(1).toLongLong();
-
-    if (!authResult.isModified())
+    SlaveBasePrivate::s_seqNr = loop.seqNr();
+    if (!loop.authInfo().isModified())
        return false;
 
-    info = authResult;
+    info = loop.authInfo();
 
     kDebug(7019) << "username=" << info.username << "password=[hidden]";
 
@@ -1196,34 +1204,41 @@
 
     kDebug(7019) << "window =" << windowId << "url =" << info.url;
 
-    QDBusInterface kps( "org.kde.kded", "/modules/kpasswdserver", \
"org.kde.KPasswdServer" ); +    QDBusConnection conn(QDBusConnection::sessionBus());
+    QDBusMessage pscall(QDBusMessage::createMethodCall("org.kde.kded",
+                                                       "/modules/kpasswdserver",
+                                                       "org.kde.KPasswdServer",
+                                                       "checkAuthInfoAsync"));
+    QDBusArgument arg;
+    arg << info;
+    pscall << QVariant::fromValue(arg) << qlonglong(windowId)
+           << qlonglong(userTimestamp);
 
-    QByteArray data;
-    {
-       QDataStream stream(&data, QIODevice::WriteOnly);
-       stream << info;
-    }
-    QDBusReply<QByteArray> reply = kps.call(QDBus::Block, "checkAuthInfo", data, \
                qlonglong(windowId),
-                                            qlonglong(userTimestamp));
+    // create the loop to wait for a result before sending the request
+    // because the result signal has to be connected before. Else we might
+    // actually miss a result signal.
+    PasswdServerLoop loop;
+    conn.connect("", "/modules/kpasswdserver", "org.kde.KPasswdServer",
+                 "checkAuthInfoAsyncResult", &loop,
+                 SLOT(slotQueryResult(qlonglong, qlonglong, const KIO::AuthInfo&)));
 
-    if ( !reply.isValid() )
-    {
+    QDBusReply<qlonglong> reply = conn.call(pscall, QDBus::Block);
+    if (!reply.isValid()) {
        kWarning(7019) << "Can't communicate with kded_kpasswdserver (for \
                checkAuthInfo)!";
-       kDebug(7019) << reply.error().message();
+       kDebug(7019) << reply.error().name() << reply.error().message();
        return false;
     }
-
-    data = reply.value();
-    {
-       QDataStream stream2(&data, QIODevice::ReadOnly);
-       stream2 >> authResult;
+    if (!loop.waitForResult(reply.value())) {
+        kWarning(7019) << "kded_kpasswdserver died while waiting for reply!";
+        return false;
     }
-    if (!authResult.isModified())
+    
+    if (!loop.authInfo().isModified())
     {
        return false;
     }
 
-    info = authResult;
+    info = loop.authInfo();
     return true;
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic