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

List:       kde-devel
Subject:    [PATCH] ldapkio
From:       Szombathelyi György <gyurco () freemail ! hu>
Date:       2003-11-17 22:18:12
[Download RAW message or body]

Hi!

Here's a small patch for the LDAPKIO module. I made this because it seems it 
will be in the public API, and the constructor with the lot of parameters 
will make it very hard to extend this class in a sane way. (I already added 
at least three new option to the plugin in my development version, and three 
new parameters in the constructor (and init()) is very very ugly.)
The patch also fixes some annoyances:
1. The specified filter is used
2. If an invalid attribute read from the config file, attribute dialog will 
not crash
3. Attach a '/' to the LDAP URL, before the path component.

I know there is a deep freeze, and hope the patch will accepted (it's really 
small)

Regards,
György

____________________________________________________________________
Miert fizetsz az internetert? Korlatlan, ingyenes internet hozzaferes a FreeStarttol.
Probald ki most! http://www.freestart.hu

["ldapkio.diff" (text/x-diff)]

Index: kabc/plugins/ldapkio/resourceldapkio.cpp
===================================================================
RCS file: /home/kdecvs/kde/kdelibs/kabc/plugins/ldapkio/resourceldapkio.cpp,v
retrieving revision 1.3
diff -u -r1.3 resourceldapkio.cpp
--- kabc/plugins/ldapkio/resourceldapkio.cpp	14 Oct 2003 15:15:31 -0000	1.3
+++ kabc/plugins/ldapkio/resourceldapkio.cpp	17 Nov 2003 22:16:15 -0000
@@ -41,50 +41,34 @@
     QMap<QString, QString> attrList;
     QStringList attributes = config->readListEntry( "LdapAttributes" );
     for ( uint pos = 0; pos < attributes.count(); pos += 2 )
-      attrList.insert( attributes[ pos ], attributes[ pos + 1 ] );
+      mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] );
 
-    init( config->readEntry( "LdapUser" ),
-          KStringHandler::obscure( config->readEntry( "LdapPassword" ) ),
-          config->readEntry( "LdapDn" ),
-          config->readEntry( "LdapHost" ),
-          config->readNumEntry( "LdapPort", 389 ),
-          config->readEntry( "LdapFilter" ),
-          config->readBoolEntry( "LdapAnonymous" ),
-          attrList );
+    mUser = config->readEntry( "LdapUser" );
+    mPassword = KStringHandler::obscure( config->readEntry( "LdapPassword" ) );
+    mDn = config->readEntry( "LdapDn" );
+    mHost = config->readEntry( "LdapHost" );
+    mPort = config->readNumEntry( "LdapPort", 389 );
+    mFilter = config->readEntry( "LdapFilter" );
+    mAnonymous = config->readBoolEntry( "LdapAnonymous" );
   } else {
-    init( "", "", "", "", 389, "", true, QMap<QString, QString>() );
+    mPort = 389;
+    mAnonymous = true;
   }
+  init();
 }
-
-ResourceLDAPKIO::ResourceLDAPKIO( const QString &user, const QString &passwd,
-                            const QString &dn, const QString &host,
-                            int port, const QString &filter, bool anonymous,
-                            const QMap<QString, QString> &attributes )
-  : Resource( 0 ), mGetCounter( 0 ), mErrorOccured( false )
-{
-  init( user, passwd, dn, host, port, filter, anonymous, attributes );
-}
-
-void ResourceLDAPKIO::init( const QString &user, const QString &passwd,
-                         const QString &dn, const QString &host,
-                         int port, const QString &filter, bool anonymous,
-                         const QMap<QString, QString> &attributes )
+    
+void ResourceLDAPKIO::init()
 {
-  mUser = user;
-  mPassword = passwd;
-  mDn = dn;
-  mHost = host;
-  mPort = port;
-  mFilter = filter;
-  mAnonymous = anonymous;
-
   /**
     If you want to add new attributes, append them here, add a
     translation string in the ctor of AttributesDialog and
     handle them in the load() method below.
     These are the default values
    */
-  if ( attributes.count() == 0 ) {
+  if ( mPort == 0 ) mPort = 389;
+  if ( mUser.isEmpty() && mPassword.isEmpty() ) mAnonymous = true;
+  
+  if ( mAttributes.count() == 0 ) {
     mAttributes.insert( "commonName", "cn" );
     mAttributes.insert( "formattedName", "displayName" );
     mAttributes.insert( "familyName", "sn" );
@@ -93,8 +77,6 @@
     mAttributes.insert( "mailAlias", "" );
     mAttributes.insert( "phoneNumber", "telephoneNumber" );
     mAttributes.insert( "uid", "uid" );
-  } else {
-    mAttributes = attributes;
   }
 
   mLDAPUrl.setProtocol( "ldap" );
@@ -104,8 +86,11 @@
   }
   mLDAPUrl.setHost( mHost );
   mLDAPUrl.setPort( mPort );
-  mLDAPUrl.setPath( mDn );
-  mLDAPUrl.setQuery( "?dn?sub" );  // how to set filters?
+  mLDAPUrl.setPath( "/"+mDn );
+  
+  QString query = "?dn?sub";
+  if ( !mFilter.isEmpty() ) query += "?"+mFilter;
+  mLDAPUrl.setQuery( query );
 }
 
 void ResourceLDAPKIO::writeConfig( KConfig *config )
Index: kabc/plugins/ldapkio/resourceldapkio.h
===================================================================
RCS file: /home/kdecvs/kde/kdelibs/kabc/plugins/ldapkio/resourceldapkio.h,v
retrieving revision 1.2
diff -u -r1.2 resourceldapkio.h
--- kabc/plugins/ldapkio/resourceldapkio.h	29 Aug 2003 10:17:01 -0000	1.2
+++ kabc/plugins/ldapkio/resourceldapkio.h	17 Nov 2003 22:16:15 -0000
@@ -34,11 +34,12 @@
 
   public:
     ResourceLDAPKIO( const KConfig* );
-    ResourceLDAPKIO( const QString &user, const QString &passwd,
-                     const QString &dn, const QString &host,
-                     int port, const QString &filter, bool anonymous,
-                     const QMap<QString, QString> &attributes );
-
+    
+    /**
+     *  Call this after you used one of the set... methods 
+     */
+    virtual void init();
+    
     virtual void writeConfig( KConfig* );
 
     virtual bool doOpen();
@@ -80,12 +81,6 @@
     void setAttributes( const QMap<QString, QString> &attributes );
     QMap<QString, QString> attributes() const;
 
-  protected:
-    void init( const QString &user, const QString &passwd,
-               const QString &dn, const QString &host,
-               int port, const QString &filter, bool anonymous,
-               const QMap<QString, QString> &attributes );
-
   protected slots:
     void entries( KIO::Job*, const KIO::UDSEntryList& );
     void data( KIO::Job*, const QByteArray& );
Index: kabc/plugins/ldapkio/resourceldapkioconfig.cpp
===================================================================
RCS file: /home/kdecvs/kde/kdelibs/kabc/plugins/ldapkio/resourceldapkioconfig.cpp,v
retrieving revision 1.2
diff -u -r1.2 resourceldapkioconfig.cpp
--- kabc/plugins/ldapkio/resourceldapkioconfig.cpp	14 Oct 2003 15:15:31 -0000	1.2
+++ kabc/plugins/ldapkio/resourceldapkioconfig.cpp	17 Nov 2003 22:16:16 -0000
@@ -132,6 +132,7 @@
   resource->setFilter( mFilter->text() );
   resource->setIsAnonymous( mAnonymous->isChecked() );
   resource->setAttributes( mAttributes );
+  resource->init();
 }
 
 void ResourceLDAPKIOConfig::editAttributes()
@@ -191,6 +192,8 @@
   QMap<QString, QString>::ConstIterator it;
   int i;
   for ( i = 1, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
+    
+    if ( mNameDict[ it.key() ] == 0 ) continue;
     label = new QLabel( *mNameDict[ it.key() ] + ":", page );
     KLineEdit *lineedit = new KLineEdit( page );
     mLineEditDict.insert( it.key(), lineedit );


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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