libkdepim
ldapclient.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KPIM_LDAPCLIENT_H
00023 #define KPIM_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 <kio/job.h>
00035 #include <kabc/ldif.h>
00036 #include <kconfig.h>
00037
00038 #include <kdepimmacros.h>
00039
00040 namespace KPIM {
00041
00042 class LdapClient;
00043 typedef TQValueList<TQByteArray> LdapAttrValue;
00044 typedef TQMap<TQString,LdapAttrValue > LdapAttrMap;
00045
00046 class LdapServer
00047 {
00048 public:
00049 LdapServer()
00050 : mPort( 389 ),
00051 mTimeLimit(0),
00052 mSizeLimit(0),
00053 mVersion(2),
00054 mSecurity(Sec_None),
00055 mAuth( LdapServer::Anonymous )
00056 {}
00057
00058 enum Security{ Sec_None, TLS, SSL };
00059 enum Auth{ Anonymous, Simple, SASL };
00060 TQString host() const { return mHost; }
00061 int port() const { return mPort; }
00062 const TQString &baseDN() const { return mBaseDN; }
00063 const TQString &user() const { return mUser; }
00064 const TQString &bindDN() const { return mBindDN; }
00065 const TQString &pwdBindDN() const { return mPwdBindDN; }
00066 int timeLimit() const { return mTimeLimit; }
00067 int sizeLimit() const { return mSizeLimit; }
00068 int version() const { return mVersion; }
00069 int security() const { return mSecurity; }
00070 int auth() const { return mAuth; }
00071 const TQString &mech() const { return mMech; }
00072
00073 void setHost( const TQString &host ) { mHost = host; }
00074 void setPort( int port ) { mPort = port; }
00075 void setBaseDN( const TQString &baseDN ) { mBaseDN = baseDN; }
00076 void setUser( const TQString &user ) { mUser = user; }
00077 void setBindDN( const TQString &bindDN ) { mBindDN = bindDN; }
00078 void setPwdBindDN( const TQString &pwdBindDN ) { mPwdBindDN = pwdBindDN; }
00079 void setTimeLimit( int timelimit ) { mTimeLimit = timelimit; }
00080 void setSizeLimit( int sizelimit ) { mSizeLimit = sizelimit; }
00081 void setVersion( int version ) { mVersion = version; }
00082 void setSecurity( int security ) { mSecurity = security; }
00083 void setAuth( int auth ) { mAuth = auth; }
00084 void setMech( const TQString &mech ) { mMech = mech; }
00085
00086 private:
00087 TQString mHost;
00088 int mPort;
00089 TQString mBaseDN;
00090 TQString mUser;
00091 TQString mBindDN;
00092 TQString mPwdBindDN;
00093 TQString mMech;
00094 int mTimeLimit, mSizeLimit, mVersion, mSecurity, mAuth;
00095 };
00096
00097
00105 class LdapObject
00106 {
00107 public:
00108 LdapObject()
00109 : dn( TQString() ), client( 0 ) {}
00110 explicit LdapObject( const TQString& _dn, LdapClient* _cl ) : dn( _dn ), client( _cl ) {}
00111 LdapObject( const LdapObject& that ) { assign( that ); }
00112
00113 LdapObject& operator=( const LdapObject& that )
00114 {
00115 assign( that );
00116 return *this;
00117 }
00118
00119 TQString toString() const;
00120
00121 void clear();
00122
00123 TQString dn;
00124 TQString objectClass;
00125 LdapAttrMap attrs;
00126 LdapClient* client;
00127
00128 protected:
00129 void assign( const LdapObject& that );
00130
00131 private:
00132
00133 };
00134
00142 class KDE_EXPORT LdapClient : public TQObject
00143 {
00144 Q_OBJECT
00145 TQ_OBJECT
00146
00147 public:
00148 LdapClient( int clientNumber, TQObject* parent = 0, const char* name = 0 );
00149 virtual ~LdapClient();
00150
00152 bool isActive() const { return mActive; }
00153
00154 int clientNumber() const;
00155 int completionWeight() const;
00156 void setCompletionWeight( int );
00157
00158 const LdapServer& server() { return mServer; }
00159 void setServer( const LdapServer &server ) { mServer = server; }
00164 TQStringList attrs() const { return mAttrs; }
00165
00166 signals:
00168 void done();
00169
00171 void error( const TQString& );
00172
00176 void result( const KPIM::LdapObject& );
00177
00178 public slots:
00183 void setAttrs( const TQStringList& attrs );
00184
00185 void setScope( const TQString scope ) { mScope = scope; }
00186
00190 void startQuery( const TQString& filter );
00191
00195 void cancelQuery();
00196
00197 protected slots:
00198 void slotData( KIO::Job*, const TQByteArray &data );
00199 void slotInfoMessage( KIO::Job*, const TQString &info );
00200 void slotDone();
00201
00202 protected:
00203 void startParseLDIF();
00204 void parseLDIF( const TQByteArray& data );
00205 void endParseLDIF();
00206 void finishCurrentObject();
00207
00208 LdapServer mServer;
00209 TQString mScope;
00210 TQStringList mAttrs;
00211
00212 TQGuardedPtr<KIO::SimpleJob> mJob;
00213 bool mActive;
00214 bool mReportObjectClass;
00215
00216 LdapObject mCurrentObject;
00217
00218 private:
00219 KABC::LDIF mLdif;
00220 int mClientNumber;
00221 int mCompletionWeight;
00222
00223
00224
00225 };
00226
00230 struct LdapResult {
00231 TQString name;
00232 TQStringList email;
00233 int clientNumber;
00234 int completionWeight;
00235 };
00236 typedef TQValueList<LdapResult> LdapResultList;
00237
00238
00246 class KDE_EXPORT LdapSearch : public TQObject
00247 {
00248 Q_OBJECT
00249 TQ_OBJECT
00250
00251 public:
00252 LdapSearch();
00253
00254 static KConfig *config();
00255 static void readConfig( LdapServer &server, KConfig *config, int num, bool active );
00256 static void writeConfig( const LdapServer &server, KConfig *config, int j, bool active );
00257
00258 void startSearch( const TQString& txt );
00259 void cancelSearch();
00260 bool isAvailable() const;
00261 void updateCompletionWeights();
00262
00263 TQValueList< LdapClient* > clients() const { return mClients; }
00264
00265 signals:
00268 void searchData( const TQStringList& );
00271 void searchData( const KPIM::LdapResultList& );
00272 void searchDone();
00273
00274 private slots:
00275 void slotLDAPResult( const KPIM::LdapObject& );
00276 void slotLDAPError( const TQString& );
00277 void slotLDAPDone();
00278 void slotDataTimer();
00279 void slotFileChanged( const TQString& );
00280
00281 private:
00282 void readWeighForClient( LdapClient *client, KConfig *config, int clientNumber );
00283 void readConfig();
00284 void finish();
00285 void makeSearchData( TQStringList& ret, LdapResultList& resList );
00286 TQValueList< LdapClient* > mClients;
00287 TQString mSearchText;
00288 TQTimer mDataTimer;
00289 int mActiveClients;
00290 bool mNoLDAPLookup;
00291 TQValueList< LdapObject > mResults;
00292 TQString mConfigFile;
00293
00294 private:
00295 static KConfig *s_config;
00296 class LdapSearchPrivate* d;
00297 };
00298
00299 }
00300 #endif // KPIM_LDAPCLIENT_H
|