TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ldapclient.h 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. #ifndef KABC_LDAPCLIENT_H
  21. #define KABC_LDAPCLIENT_H
  22. #include <tqobject.h>
  23. #include <tqstring.h>
  24. #include <tqcstring.h>
  25. #include <tqstringlist.h>
  26. #include <tqmemarray.h>
  27. #include <tqguardedptr.h>
  28. #include <tqtimer.h>
  29. #include <tdeio/job.h>
  30. namespace TDEABC {
  31. class LdapClient;
  32. typedef TQValueList<TQByteArray> LdapAttrValue;
  33. typedef TQMap<TQString,LdapAttrValue > LdapAttrMap;
  34. /**
  35. * This class is internal. Binary compatibiliy might be broken any time
  36. * without notification. Do not use it.
  37. *
  38. * We mean it!
  39. *
  40. */
  41. class KABC_EXPORT LdapObject
  42. {
  43. public:
  44. LdapObject()
  45. : dn( TQString::null ), client( 0 ) {}
  46. explicit LdapObject( const TQString& _dn, LdapClient* _cl ) : dn( _dn ), client( _cl ) {}
  47. LdapObject( const LdapObject& that ) { assign( that ); }
  48. LdapObject& operator=( const LdapObject& that )
  49. {
  50. assign( that );
  51. return *this;
  52. }
  53. TQString toString() const;
  54. void clear();
  55. TQString dn;
  56. LdapAttrMap attrs;
  57. LdapClient* client;
  58. protected:
  59. void assign( const LdapObject& that );
  60. private:
  61. //class LdapObjectPrivate* d;
  62. };
  63. /**
  64. * This class is internal. Binary compatibiliy might be broken any time
  65. * without notification. Do not use it.
  66. *
  67. * We mean it!
  68. *
  69. */
  70. class KABC_EXPORT LdapClient : public TQObject
  71. {
  72. Q_OBJECT
  73. public:
  74. LdapClient( TQObject* parent = 0, const char* name = 0 );
  75. virtual ~LdapClient();
  76. /*! returns true if there is a query running */
  77. bool isActive() const { return mActive; }
  78. signals:
  79. /*! Emitted when the query is done */
  80. void done();
  81. /*! Emitted in case of error */
  82. void error( const TQString& );
  83. /*! Emitted once for each object returned
  84. * from the query
  85. */
  86. void result( const TDEABC::LdapObject& );
  87. public slots:
  88. /*!
  89. * Set the name or IP of the LDAP server
  90. */
  91. void setHost( const TQString& host );
  92. TQString host() const { return mHost; }
  93. /*!
  94. * Set the port of the LDAP server
  95. * if using a nonstandard port
  96. */
  97. void setPort( const TQString& port );
  98. TQString port() const { return mPort; }
  99. /*!
  100. * Set the base DN
  101. */
  102. void setBase( const TQString& base );
  103. TQString base() const { return mBase; }
  104. /*!
  105. * Set the bind DN
  106. */
  107. void setBindDN( const TQString& bindDN );
  108. TQString bindDN() const;
  109. /*!
  110. * Set the bind password DN
  111. */
  112. void setPwdBindDN( const TQString& pwdBindDN );
  113. TQString pwdBindDN() const;
  114. /*! Set the attributes that should be
  115. * returned, or an empty list if
  116. * all attributes are wanted
  117. */
  118. void setAttrs( const TQStringList& attrs );
  119. TQStringList attrs() const { return mAttrs; }
  120. void setScope( const TQString scope ) { mScope = scope; }
  121. /*!
  122. * Start the query with filter filter
  123. */
  124. void startQuery( const TQString& filter );
  125. /*!
  126. * Abort a running query
  127. */
  128. void cancelQuery();
  129. protected slots:
  130. void slotData( TDEIO::Job*, const TQByteArray &data );
  131. void slotInfoMessage( TDEIO::Job*, const TQString &info );
  132. void slotDone();
  133. protected:
  134. void startParseLDIF();
  135. void parseLDIF( const TQByteArray& data );
  136. void endParseLDIF();
  137. TQString mHost;
  138. TQString mPort;
  139. TQString mBase;
  140. TQString mScope;
  141. TQStringList mAttrs;
  142. TQGuardedPtr<TDEIO::SimpleJob> mJob;
  143. bool mActive;
  144. LdapObject mCurrentObject;
  145. TQCString mBuf;
  146. TQCString mLastAttrName;
  147. TQCString mLastAttrValue;
  148. bool mIsBase64;
  149. private:
  150. class LdapClientPrivate;
  151. LdapClientPrivate* d;
  152. };
  153. /**
  154. * Structure describing one result returned by a LDAP query
  155. */
  156. struct LdapResult {
  157. TQString name; ///< full name
  158. TQString email; ///< email
  159. int clientNumber; ///< for sorting
  160. };
  161. typedef TQValueList<LdapResult> LdapResultList;
  162. /**
  163. * This class is internal. Binary compatibiliy might be broken any time
  164. * without notification. Do not use it.
  165. *
  166. * We mean it!
  167. *
  168. */
  169. class KABC_EXPORT LdapSearch : public TQObject
  170. {
  171. Q_OBJECT
  172. public:
  173. LdapSearch();
  174. void startSearch( const TQString& txt );
  175. void cancelSearch();
  176. bool isAvailable() const;
  177. signals:
  178. /// Results, assembled as "Full Name <email>"
  179. /// (This signal can be emitted many times)
  180. void searchData( const TQStringList& );
  181. /// Another form for the results, with separate fields
  182. /// (This signal can be emitted many times)
  183. void searchData( const TDEABC::LdapResultList& );
  184. void searchDone();
  185. private slots:
  186. void slotLDAPResult( const TDEABC::LdapObject& );
  187. void slotLDAPError( const TQString& );
  188. void slotLDAPDone();
  189. void slotDataTimer();
  190. private:
  191. void finish();
  192. void makeSearchData( TQStringList& ret, LdapResultList& resList );
  193. TQValueList< LdapClient* > mClients;
  194. TQString mSearchText;
  195. TQTimer mDataTimer;
  196. int mActiveClients;
  197. bool mNoLDAPLookup;
  198. TQValueList< LdapObject > mResults;
  199. private:
  200. class LdapSearchPrivate* d;
  201. };
  202. }
  203. #endif // KABC_LDAPCLIENT_H