00001
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 <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 KPIM {
00037
00038
class LdapClient;
00039
typedef QValueList<QByteArray> LdapAttrValue;
00040
typedef QMap<QString,LdapAttrValue > LdapAttrMap;
00041
00049 class LdapObject
00050 {
00051
public:
00052
LdapObject()
00053 : dn( QString::null ), client( 0 ) {}
00054
explicit LdapObject(
const QString& _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
QString toString()
const;
00064
00065
void clear();
00066
00067
QString dn;
00068
QString objectClass;
00069
LdapAttrMap attrs;
00070
LdapClient* client;
00071
00072
protected:
00073
void assign(
const LdapObject& that );
00074
00075
private:
00076
00077 };
00078
00086 class LdapClient :
public QObject
00087 {
00088 Q_OBJECT
00089
00090
public:
00091
LdapClient(
int clientNumber,
QObject* parent = 0,
const char* name = 0 );
00092
virtual ~
LdapClient();
00093
00095 bool isActive()
const {
return mActive; }
00096
00097
int clientNumber() const;
00098
int completionWeight() const;
00099
void setCompletionWeight(
int );
00100
00101
QString host()
const {
return mHost; }
00102
QString port()
const {
return mPort; }
00103
QString base()
const {
return mBase; }
00104
QString bindDN() const;
00105
QString pwdBindDN() const;
00110 QStringList attrs()
const {
return mAttrs; }
00111
00112 signals:
00114
void done();
00115
00117
void error(
const QString& );
00118
00122
void result(
const KPIM::LdapObject& );
00123
00124
public slots:
00128
void setHost(
const QString& host );
00129
00134
void setPort(
const QString& port );
00135
00139
void setBase(
const QString& base );
00140
00144
void setBindDN(
const QString& bindDN );
00145
00149
void setPwdBindDN(
const QString& pwdBindDN );
00150
00155
void setAttrs(
const QStringList& attrs );
00156
00157
void setScope(
const QString scope ) { mScope = scope; }
00158
00162
void startQuery(
const QString& filter );
00163
00167
void cancelQuery();
00168
00169
protected slots:
00170
void slotData( KIO::Job*,
const QByteArray &data );
00171
void slotInfoMessage( KIO::Job*,
const QString &info );
00172
void slotDone();
00173
00174
protected:
00175
void startParseLDIF();
00176
void parseLDIF(
const QByteArray& data );
00177
void endParseLDIF();
00178
void finishCurrentObject();
00179
00180
QString mHost;
00181
QString mPort;
00182
QString mBase;
00183
QString mScope;
00184
QStringList mAttrs;
00185
00186
QGuardedPtr<KIO::SimpleJob> mJob;
00187
bool mActive;
00188
bool mReportObjectClass;
00189
00190
LdapObject mCurrentObject;
00191
QCString mBuf;
00192
QCString mLastAttrName;
00193
QCString mLastAttrValue;
00194
bool mIsBase64;
00195
00196
private:
00197
class LdapClientPrivate;
00198 LdapClientPrivate* d;
00199 };
00200
00204 struct LdapResult {
00205 QString name;
00206 QStringList email;
00207 int clientNumber;
00208 int completionWeight;
00209 };
00210
typedef QValueList<LdapResult> LdapResultList;
00211
00212
00220 class LdapSearch :
public QObject
00221 {
00222 Q_OBJECT
00223
00224
public:
00225
LdapSearch();
00226
00227
void startSearch(
const QString& txt );
00228
void cancelSearch();
00229
bool isAvailable()
const;
00230
00231
QValueList< LdapClient* > clients()
const {
return mClients; }
00232
00233 signals:
00236
void searchData(
const QStringList& );
00239
void searchData(
const KPIM::LdapResultList& );
00240
void searchDone();
00241
00242
private slots:
00243
void slotLDAPResult(
const KPIM::LdapObject& );
00244
void slotLDAPError(
const QString& );
00245
void slotLDAPDone();
00246
void slotDataTimer();
00247
void slotFileChanged(
const QString& );
00248
00249
private:
00250
void readConfig();
00251
void finish();
00252
void makeSearchData(
QStringList& ret,
LdapResultList& resList );
00253
QValueList< LdapClient* > mClients;
00254
QString mSearchText;
00255
QTimer mDataTimer;
00256
int mActiveClients;
00257
bool mNoLDAPLookup;
00258
QValueList< LdapObject > mResults;
00259
QString mConfigFile;
00260
00261
private:
00262
class LdapSearchPrivate* d;
00263 };
00264
00265 }
00266
#endif // KPIM_LDAPCLIENT_H