kabc Library API Documentation

ldapclient.h

00001 /* kldapclient.h - LDAP access
00002  *      Copyright (C) 2002 Klarälvdalens Datakonsult AB
00003  *
00004  *      Author: Steffen Hansen <hansen@kde.org>
00005  *
00006  * This file is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This file is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00019  */
00020 
00021 
00022 #ifndef KABC_LDAPCLIENT_H
00023 #define KABC_LDAPCLIENT_H
00024 
00025 
00026 #include <qobject.h>
00027 #include <qstring.h>
00028 #include <qcstring.h>
00029 #include <qstringlist.h>
00030 #include <qmemarray.h>
00031 #include <qguardedptr.h>
00032 #include <qtimer.h>
00033 
00034 #include <kio/job.h>
00035 
00036 namespace KABC {
00037 
00038 typedef QValueList<QByteArray> LdapAttrValue;
00039 typedef QMap<QString,LdapAttrValue > LdapAttrMap;
00040 
00048 class LdapObject
00049 {
00050   public:
00051     LdapObject()
00052       : dn( QString::null ) {};  
00053     explicit LdapObject( QString _dn ) : dn( _dn ) {};
00054     LdapObject( const LdapObject& that ) { assign( that ); }
00055   
00056     LdapObject& operator=( const LdapObject& that )
00057     {
00058       assign( that );
00059       return *this;
00060     }
00061 
00062     QString toString() const;
00063 
00064     void clear();
00065 
00066     QString dn;
00067     LdapAttrMap attrs;
00068 
00069   protected:
00070     void assign( const LdapObject& that );
00071 
00072   private:
00073     class LdapObjectPrivate* d;
00074 };
00075 
00083 class LdapClient : public QObject
00084 {
00085   Q_OBJECT
00086 
00087   public:
00088     LdapClient( QObject* parent = 0, const char* name = 0 );
00089     virtual ~LdapClient();
00090 
00092     bool isActive() const { return mActive; }
00093 
00094   signals:
00096     void done();
00097 
00099     void error( const QString& );
00100 
00104     void result( const KABC::LdapObject& );
00105 
00106   public slots:
00110     void setHost( const QString& host );
00111     QString host() const { return mHost; }
00112 
00117     void setPort( const QString& port );
00118     QString port() const { return mPort; }
00119 
00123     void setBase( const QString& base );
00124     QString base() const { return mBase; }
00125 
00130     void setAttrs( const QStringList& attrs );
00131     QStringList attrs() const { return mAttrs; }
00132 
00133     void setScope( const QString scope ) { mScope = scope; }
00134 
00138     void startQuery( const QString& filter );
00139 
00143     void cancelQuery();
00144 
00145   protected slots:
00146     void slotData( KIO::Job*, const QByteArray &data );
00147     void slotInfoMessage( KIO::Job*, const QString &info );
00148     void slotDone();
00149 
00150   protected:
00151     void startParseLDIF();
00152     void parseLDIF( const QByteArray& data );
00153     void endParseLDIF();
00154 
00155     QString mHost;
00156     QString mPort;
00157     QString mBase;
00158     QString mScope;
00159     QStringList mAttrs;
00160   
00161     QGuardedPtr<KIO::SimpleJob> mJob;
00162     bool mActive;
00163   
00164     LdapObject mCurrentObject;
00165     QCString mBuf;
00166     QCString mLastAttrName;
00167     QCString mLastAttrValue;
00168     bool mIsBase64;
00169 
00170   private:
00171     class LdapClientPrivate* d;
00172 };
00173 
00174 
00182 class LdapSearch : public QObject
00183 {
00184   Q_OBJECT
00185 
00186   public:
00187     LdapSearch();
00188 
00189     void startSearch( const QString& txt );
00190     void cancelSearch();
00191     bool isAvailable() const;
00192 
00193   signals:
00194     void searchData( const QStringList& );
00195     void searchDone();
00196 
00197   private slots:
00198     void slotLDAPResult( const KABC::LdapObject& );
00199     void slotLDAPError( const QString& );
00200     void slotLDAPDone();
00201     void slotDataTimer();
00202 
00203   private:
00204     void finish();
00205     QStringList makeSearchData();
00206     QValueList< LdapClient* > mClients;
00207     QString mSearchText;
00208     QTimer mDataTimer;
00209     int mActiveClients;
00210     bool mNoLDAPLookup;
00211     QValueList< LdapObject > mResults;
00212 
00213   private:
00214     class LdapSearchPrivate* d;
00215 };
00216 
00217 }    
00218 #endif // KABC_LDAPCLIENT_H
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:29:20 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001