libtdepim

ldapclient.h
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 KPIM_LDAPCLIENT_H
23#define KPIM_LDAPCLIENT_H
24
25
26#include <tqobject.h>
27#include <tqstring.h>
28#include <tqcstring.h>
29#include <tqstringlist.h>
30#include <tqmemarray.h>
31#include <tqguardedptr.h>
32#include <tqtimer.h>
33
34#include <tdeio/job.h>
35#include <tdeabc/ldif.h>
36#include <tdeconfig.h>
37
38#include <tdemacros.h>
39
40namespace KPIM {
41
42class LdapClient;
43typedef TQValueList<TQByteArray> LdapAttrValue;
44typedef TQMap<TQString,LdapAttrValue > LdapAttrMap;
45
46class LdapServer
47{
48 public:
49 LdapServer()
50 : mPort( 389 ),
51 mTimeLimit(0),
52 mSizeLimit(0),
53 mVersion(2),
54 mSecurity(Sec_None),
55 mAuth( LdapServer::Anonymous )
56 {}
57
58 enum Security{ Sec_None, TLS, SSL };
59 enum Auth{ Anonymous, Simple, SASL };
60 TQString host() const { return mHost; }
61 int port() const { return mPort; }
62 const TQString &baseDN() const { return mBaseDN; }
63 const TQString &user() const { return mUser; }
64 const TQString &bindDN() const { return mBindDN; }
65 const TQString &pwdBindDN() const { return mPwdBindDN; }
66 int timeLimit() const { return mTimeLimit; }
67 int sizeLimit() const { return mSizeLimit; }
68 int version() const { return mVersion; }
69 int security() const { return mSecurity; }
70 int auth() const { return mAuth; }
71 const TQString &mech() const { return mMech; }
72
73 void setHost( const TQString &host ) { mHost = host; }
74 void setPort( int port ) { mPort = port; }
75 void setBaseDN( const TQString &baseDN ) { mBaseDN = baseDN; }
76 void setUser( const TQString &user ) { mUser = user; }
77 void setBindDN( const TQString &bindDN ) { mBindDN = bindDN; }
78 void setPwdBindDN( const TQString &pwdBindDN ) { mPwdBindDN = pwdBindDN; }
79 void setTimeLimit( int timelimit ) { mTimeLimit = timelimit; }
80 void setSizeLimit( int sizelimit ) { mSizeLimit = sizelimit; }
81 void setVersion( int version ) { mVersion = version; }
82 void setSecurity( int security ) { mSecurity = security; } //0-No, 1-TLS, 2-SSL - KDE4: add an enum to Lda
83 void setAuth( int auth ) { mAuth = auth; } //0-Anonymous, 1-simple, 2-SASL - KDE4: add an enum to LdapCon
84 void setMech( const TQString &mech ) { mMech = mech; }
85
86 private:
87 TQString mHost;
88 int mPort;
89 TQString mBaseDN;
90 TQString mUser;
91 TQString mBindDN;
92 TQString mPwdBindDN;
93 TQString mMech;
94 int mTimeLimit, mSizeLimit, mVersion, mSecurity, mAuth;
95};
96
97
106{
107 public:
108 LdapObject()
109 : dn( TQString() ), client( 0 ) {}
110 explicit LdapObject( const TQString& _dn, LdapClient* _cl ) : dn( _dn ), client( _cl ) {}
111 LdapObject( const LdapObject& that ) { assign( that ); }
112
113 LdapObject& operator=( const LdapObject& that )
114 {
115 assign( that );
116 return *this;
117 }
118
119 TQString toString() const;
120
121 void clear();
122
123 TQString dn;
124 TQString objectClass;
125 LdapAttrMap attrs;
126 LdapClient* client;
127
128 protected:
129 void assign( const LdapObject& that );
130
131 private:
132 //class LdapObjectPrivate* d;
133};
134
142class TDE_EXPORT LdapClient : public TQObject
143{
144 TQ_OBJECT
145
146
147 public:
148 LdapClient( int clientNumber, TQObject* parent = 0, const char* name = 0 );
149 virtual ~LdapClient();
150
152 bool isActive() const { return mActive; }
153
154 int clientNumber() const;
155 int completionWeight() const;
156 void setCompletionWeight( int );
157
158 const LdapServer& server() { return mServer; }
159 void setServer( const LdapServer &server ) { mServer = server; }
164 TQStringList attrs() const { return mAttrs; }
165
166 signals:
168 void done();
169
171 void error( const TQString& );
172
176 void result( const KPIM::LdapObject& );
177
178 public slots: // why are those slots?
183 void setAttrs( const TQStringList& attrs );
184
185 void setScope( const TQString scope ) { mScope = scope; }
186
190 void startQuery( const TQString& filter );
191
195 void cancelQuery();
196
197 protected slots:
198 void slotData( TDEIO::Job*, const TQByteArray &data );
199 void slotInfoMessage( TDEIO::Job*, const TQString &info );
200 void slotDone();
201
202 protected:
203 void startParseLDIF();
204 void parseLDIF( const TQByteArray& data );
205 void endParseLDIF();
206 void finishCurrentObject();
207
208 LdapServer mServer;
209 TQString mScope;
210 TQStringList mAttrs;
211
212 TQGuardedPtr<TDEIO::SimpleJob> mJob;
213 bool mActive;
214 bool mReportObjectClass;
215
216 LdapObject mCurrentObject;
217
218 private:
219 TDEABC::LDIF mLdif;
220 int mClientNumber;
221 int mCompletionWeight;
222
223// class LdapClientPrivate;
224// LdapClientPrivate* d;
225};
226
231 TQString name;
232 TQStringList email;
235};
236typedef TQValueList<LdapResult> LdapResultList;
237
238
246class TDE_EXPORT LdapSearch : public TQObject
247{
248 TQ_OBJECT
249
250
251 public:
252 LdapSearch();
253
254 static TDEConfig *config();
255 static void readConfig( LdapServer &server, TDEConfig *config, int num, bool active );
256 static void writeConfig( const LdapServer &server, TDEConfig *config, int j, bool active );
257
258 void startSearch( const TQString& txt );
259 void cancelSearch();
260 bool isAvailable() const;
261 void updateCompletionWeights();
262
263 TQValueList< LdapClient* > clients() const { return mClients; }
264
265 signals:
268 void searchData( const TQStringList& );
271 void searchData( const KPIM::LdapResultList& );
272 void searchDone();
273
274 private slots:
275 void slotLDAPResult( const KPIM::LdapObject& );
276 void slotLDAPError( const TQString& );
277 void slotLDAPDone();
278 void slotDataTimer();
279 void slotFileChanged( const TQString& );
280
281 private:
282 void readWeighForClient( LdapClient *client, TDEConfig *config, int clientNumber );
283 void readConfig();
284 void finish();
285 void makeSearchData( TQStringList& ret, LdapResultList& resList );
286 TQValueList< LdapClient* > mClients;
287 TQString mSearchText;
288 TQTimer mDataTimer;
289 int mActiveClients;
290 bool mNoLDAPLookup;
291 TQValueList< LdapObject > mResults;
292 TQString mConfigFile;
293
294 private:
295 static TDEConfig *s_config;
296 class LdapSearchPrivate* d;
297};
298
299}
300#endif // KPIM_LDAPCLIENT_H
This class is internal.
Definition: ldapclient.h:143
void result(const KPIM::LdapObject &)
TQStringList attrs() const
Definition: ldapclient.h:164
bool isActive() const
Definition: ldapclient.h:152
void error(const TQString &)
This class is internal.
Definition: ldapclient.h:106
This class is internal.
Definition: ldapclient.h:247
void searchData(const TQStringList &)
Results, assembled as "Full Name <email>" (This signal can be emitted many times)
void searchData(const KPIM::LdapResultList &)
Another form for the results, with separate fields (This signal can be emitted many times)
TDEPIM classes for drag and drop of mails.
Structure describing one result returned by a LDAP query.
Definition: ldapclient.h:230
TQString name
full name
Definition: ldapclient.h:231
TQStringList email
emails
Definition: ldapclient.h:232
int completionWeight
for sorting in a completion list
Definition: ldapclient.h:234
int clientNumber
for sorting in a ldap-only lookup
Definition: ldapclient.h:233