home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kabc / ldapclient.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  5.7 KB  |  249 lines

  1. /* kldapclient.h - LDAP access
  2.  *      Copyright (C) 2002 Klar├ñlvdalens Datakonsult AB
  3.  *
  4.  *      Author: Steffen Hansen <hansen@kde.org>
  5.  *
  6.  * This file is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This file is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  19.  */
  20.  
  21.  
  22. #ifndef KABC_LDAPCLIENT_H
  23. #define KABC_LDAPCLIENT_H
  24.  
  25.  
  26. #include <qobject.h>
  27. #include <qstring.h>
  28. #include <qcstring.h>
  29. #include <qstringlist.h>
  30. #include <qmemarray.h>
  31. #include <qguardedptr.h>
  32. #include <qtimer.h>
  33.  
  34. #include <kio/job.h>
  35.  
  36. namespace KABC {
  37.  
  38. class LdapClient;
  39. typedef QValueList<QByteArray> LdapAttrValue;
  40. typedef QMap<QString,LdapAttrValue > LdapAttrMap;
  41.  
  42. /**
  43.   * This class is internal. Binary compatibiliy might be broken any time
  44.   * without notification. Do not use it.
  45.   *
  46.   * We mean it!
  47.   *
  48.   */
  49. class KABC_EXPORT LdapObject
  50. {
  51.   public:
  52.     LdapObject()
  53.       : dn( QString::null ), client( 0 ) {}
  54.     explicit LdapObject( const QString& _dn, LdapClient* _cl ) : dn( _dn ), client( _cl ) {}
  55.     LdapObject( const LdapObject& that ) { assign( that ); }
  56.  
  57.     LdapObject& operator=( const LdapObject& that )
  58.     {
  59.       assign( that );
  60.       return *this;
  61.     }
  62.  
  63.     QString toString() const;
  64.  
  65.     void clear();
  66.  
  67.     QString dn;
  68.     LdapAttrMap attrs;
  69.     LdapClient* client;
  70.  
  71.   protected:
  72.     void assign( const LdapObject& that );
  73.  
  74.   private:
  75.     //class LdapObjectPrivate* d;
  76. };
  77.  
  78. /**
  79.   * This class is internal. Binary compatibiliy might be broken any time
  80.   * without notification. Do not use it.
  81.   *
  82.   * We mean it!
  83.   *
  84.   */
  85. class KABC_EXPORT LdapClient : public QObject
  86. {
  87.   Q_OBJECT
  88.  
  89.   public:
  90.     LdapClient( QObject* parent = 0, const char* name = 0 );
  91.     virtual ~LdapClient();
  92.  
  93.     /*! returns true if there is a query running */
  94.     bool isActive() const { return mActive; }
  95.  
  96.   signals:
  97.     /*! Emitted when the query is done */
  98.     void done();
  99.  
  100.     /*! Emitted in case of error */
  101.     void error( const QString& );
  102.  
  103.     /*! Emitted once for each object returned
  104.      * from the query
  105.      */
  106.     void result( const KABC::LdapObject& );
  107.  
  108.   public slots:
  109.     /*!
  110.      * Set the name or IP of the LDAP server
  111.      */
  112.     void setHost( const QString& host );
  113.     QString host() const { return mHost; }
  114.  
  115.     /*!
  116.      * Set the port of the LDAP server
  117.      * if using a nonstandard port
  118.      */
  119.     void setPort( const QString& port );
  120.     QString port() const { return mPort; }
  121.  
  122.     /*!
  123.      * Set the base DN
  124.      */
  125.     void setBase( const QString& base );
  126.     QString base() const { return mBase; }
  127.  
  128.     /*!
  129.      * Set the bind DN
  130.      */
  131.     void setBindDN( const QString& bindDN );
  132.     QString bindDN() const;
  133.  
  134.     /*!
  135.      * Set the bind password DN
  136.      */
  137.     void setPwdBindDN( const QString& pwdBindDN );
  138.     QString pwdBindDN() const;
  139.  
  140.     /*! Set the attributes that should be
  141.      * returned, or an empty list if
  142.      * all attributes are wanted
  143.      */
  144.     void setAttrs( const QStringList& attrs );
  145.     QStringList attrs() const { return mAttrs; }
  146.  
  147.     void setScope( const QString scope ) { mScope = scope; }
  148.  
  149.     /*!
  150.      * Start the query with filter filter
  151.      */
  152.     void startQuery( const QString& filter );
  153.  
  154.     /*!
  155.      * Abort a running query
  156.      */
  157.     void cancelQuery();
  158.  
  159.   protected slots:
  160.     void slotData( KIO::Job*, const QByteArray &data );
  161.     void slotInfoMessage( KIO::Job*, const QString &info );
  162.     void slotDone();
  163.  
  164.   protected:
  165.     void startParseLDIF();
  166.     void parseLDIF( const QByteArray& data );
  167.     void endParseLDIF();
  168.  
  169.     QString mHost;
  170.     QString mPort;
  171.     QString mBase;
  172.     QString mScope;
  173.     QStringList mAttrs;
  174.  
  175.     QGuardedPtr<KIO::SimpleJob> mJob;
  176.     bool mActive;
  177.  
  178.     LdapObject mCurrentObject;
  179.     QCString mBuf;
  180.     QCString mLastAttrName;
  181.     QCString mLastAttrValue;
  182.     bool mIsBase64;
  183.  
  184.   private:
  185.     class LdapClientPrivate;
  186.     LdapClientPrivate* d;
  187. };
  188.  
  189. /**
  190.  * Structure describing one result returned by a LDAP query
  191.  */
  192. struct LdapResult {
  193.   QString name;     ///< full name
  194.   QString email;    ///< email
  195.   int clientNumber; ///< for sorting
  196. };
  197. typedef QValueList<LdapResult> LdapResultList;
  198.  
  199.  
  200. /**
  201.   * This class is internal. Binary compatibiliy might be broken any time
  202.   * without notification. Do not use it.
  203.   *
  204.   * We mean it!
  205.   *
  206.   */
  207. class KABC_EXPORT LdapSearch : public QObject
  208. {
  209.   Q_OBJECT
  210.  
  211.   public:
  212.     LdapSearch();
  213.  
  214.     void startSearch( const QString& txt );
  215.     void cancelSearch();
  216.     bool isAvailable() const;
  217.  
  218.   signals:
  219.     /// Results, assembled as "Full Name <email>"
  220.     /// (This signal can be emitted many times)
  221.     void searchData( const QStringList& );
  222.     /// Another form for the results, with separate fields
  223.     /// (This signal can be emitted many times)
  224.     void searchData( const KABC::LdapResultList& );
  225.     void searchDone();
  226.  
  227.   private slots:
  228.     void slotLDAPResult( const KABC::LdapObject& );
  229.     void slotLDAPError( const QString& );
  230.     void slotLDAPDone();
  231.     void slotDataTimer();
  232.  
  233.   private:
  234.     void finish();
  235.     void makeSearchData( QStringList& ret, LdapResultList& resList );
  236.     QValueList< LdapClient* > mClients;
  237.     QString mSearchText;
  238.     QTimer mDataTimer;
  239.     int mActiveClients;
  240.     bool mNoLDAPLookup;
  241.     QValueList< LdapObject > mResults;
  242.  
  243.   private:
  244.     class LdapSearchPrivate* d;
  245. };
  246.  
  247. }
  248. #endif // KABC_LDAPCLIENT_H
  249.