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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 00022 #ifndef KABC_LDAPCLIENT_H 00023 #define KABC_LDAPCLIENT_H 00024 00025 00026 #include <tqobject.h> 00027 #include <tqstring.h> 00028 #include <tqcstring.h> 00029 #include <tqstringlist.h> 00030 #include <tqmemarray.h> 00031 #include <tqguardedptr.h> 00032 #include <tqtimer.h> 00033 00034 #include <tdeio/job.h> 00035 00036 namespace TDEABC { 00037 00038 class LdapClient; 00039 typedef TQValueList<TQByteArray> LdapAttrValue; 00040 typedef TQMap<TQString,LdapAttrValue > LdapAttrMap; 00041 00049 class KABC_EXPORT LdapObject 00050 { 00051 public: 00052 LdapObject() 00053 : dn( TQString::null ), client( 0 ) {} 00054 explicit LdapObject( const TQString& _dn, LdapClient* _cl ) : dn( _dn ), client( _cl ) {} 00055 LdapObject( const LdapObject& that ) { assign( that ); } 00056 00057 LdapObject& operator=( const LdapObject& that ) 00058 { 00059 assign( that ); 00060 return *this; 00061 } 00062 00063 TQString toString() const; 00064 00065 void clear(); 00066 00067 TQString dn; 00068 LdapAttrMap attrs; 00069 LdapClient* client; 00070 00071 protected: 00072 void assign( const LdapObject& that ); 00073 00074 private: 00075 //class LdapObjectPrivate* d; 00076 }; 00077 00085 class KABC_EXPORT LdapClient : public TQObject 00086 { 00087 Q_OBJECT 00088 00089 public: 00090 LdapClient( TQObject* parent = 0, const char* name = 0 ); 00091 virtual ~LdapClient(); 00092 00094 bool isActive() const { return mActive; } 00095 00096 signals: 00098 void done(); 00099 00101 void error( const TQString& ); 00102 00106 void result( const TDEABC::LdapObject& ); 00107 00108 public slots: 00112 void setHost( const TQString& host ); 00113 TQString host() const { return mHost; } 00114 00119 void setPort( const TQString& port ); 00120 TQString port() const { return mPort; } 00121 00125 void setBase( const TQString& base ); 00126 TQString base() const { return mBase; } 00127 00131 void setBindDN( const TQString& bindDN ); 00132 TQString bindDN() const; 00133 00137 void setPwdBindDN( const TQString& pwdBindDN ); 00138 TQString pwdBindDN() const; 00139 00144 void setAttrs( const TQStringList& attrs ); 00145 TQStringList attrs() const { return mAttrs; } 00146 00147 void setScope( const TQString scope ) { mScope = scope; } 00148 00152 void startQuery( const TQString& filter ); 00153 00157 void cancelQuery(); 00158 00159 protected slots: 00160 void slotData( TDEIO::Job*, const TQByteArray &data ); 00161 void slotInfoMessage( TDEIO::Job*, const TQString &info ); 00162 void slotDone(); 00163 00164 protected: 00165 void startParseLDIF(); 00166 void parseLDIF( const TQByteArray& data ); 00167 void endParseLDIF(); 00168 00169 TQString mHost; 00170 TQString mPort; 00171 TQString mBase; 00172 TQString mScope; 00173 TQStringList mAttrs; 00174 00175 TQGuardedPtr<TDEIO::SimpleJob> mJob; 00176 bool mActive; 00177 00178 LdapObject mCurrentObject; 00179 TQCString mBuf; 00180 TQCString mLastAttrName; 00181 TQCString mLastAttrValue; 00182 bool mIsBase64; 00183 00184 private: 00185 class LdapClientPrivate; 00186 LdapClientPrivate* d; 00187 }; 00188 00192 struct LdapResult { 00193 TQString name; 00194 TQString email; 00195 int clientNumber; 00196 }; 00197 typedef TQValueList<LdapResult> LdapResultList; 00198 00199 00207 class KABC_EXPORT LdapSearch : public TQObject 00208 { 00209 Q_OBJECT 00210 00211 public: 00212 LdapSearch(); 00213 00214 void startSearch( const TQString& txt ); 00215 void cancelSearch(); 00216 bool isAvailable() const; 00217 00218 signals: 00221 void searchData( const TQStringList& ); 00224 void searchData( const TDEABC::LdapResultList& ); 00225 void searchDone(); 00226 00227 private slots: 00228 void slotLDAPResult( const TDEABC::LdapObject& ); 00229 void slotLDAPError( const TQString& ); 00230 void slotLDAPDone(); 00231 void slotDataTimer(); 00232 00233 private: 00234 void finish(); 00235 void makeSearchData( TQStringList& ret, LdapResultList& resList ); 00236 TQValueList< LdapClient* > mClients; 00237 TQString mSearchText; 00238 TQTimer mDataTimer; 00239 int mActiveClients; 00240 bool mNoLDAPLookup; 00241 TQValueList< LdapObject > mResults; 00242 00243 private: 00244 class LdapSearchPrivate* d; 00245 }; 00246 00247 } 00248 #endif // KABC_LDAPCLIENT_H