23 #include <tqapplication.h>
28 #include <tdeglobal.h>
29 #include <kstandarddirs.h>
30 #include <klineedit.h>
32 #include <tdeconfig.h>
33 #include <kstringhandler.h>
34 #include <tdetempfile.h>
37 #include <tdeio/netaccess.h>
38 #include <tdeabc/ldif.h>
39 #include <tdeabc/ldapurl.h>
41 #include "resourceldaptdeio.h"
42 #include "resourceldaptdeioconfig.h"
47 void tqt_enter_modal( TQWidget *widget );
48 void tqt_leave_modal( TQWidget *widget );
50 class ResourceLDAPTDEIO::ResourceLDAPTDEIOPrivate
54 bool mTLS,mSSL,mSubTree;
61 TQString mRealm, mBindDN;
63 int mVer, mSizeLimit, mTimeLimit, mRDNPrefix;
72 ResourceLDAPTDEIO::ResourceLDAPTDEIO(
const TDEConfig *config )
75 d =
new ResourceLDAPTDEIOPrivate;
77 TQMap<TQString, TQString> attrList;
78 TQStringList attributes = config->
readListEntry(
"LdapAttributes" );
79 for ( uint pos = 0; pos < attributes.count(); pos += 2 )
80 mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] );
87 mFilter = config->
readEntry(
"LdapFilter" );
93 d->mMech = config->
readEntry(
"LdapMech" );
94 d->mRealm = config->
readEntry(
"LdapRealm" );
95 d->mBindDN = config->
readEntry(
"LdapBindDN" );
97 d->mTimeLimit = config->
readNumEntry(
"LdapTimeLimit", 0 );
98 d->mSizeLimit = config->
readNumEntry(
"LdapSizeLimit", 0 );
99 d->mRDNPrefix = config->
readNumEntry(
"LdapRDNPrefix", 0 );
100 d->mCachePolicy = config->
readNumEntry(
"LdapCachePolicy", 0 );
101 d->mAutoCache = config->
readBoolEntry(
"LdapAutoCache",
true );
105 mUser = mPassword = mHost = mFilter = mDn =
"";
106 d->mMech = d->mRealm = d->mBindDN =
"";
107 d->mTLS = d->mSSL = d->mSubTree = d->mSASL =
false;
108 d->mVer = 3; d->mRDNPrefix = 0;
109 d->mTimeLimit = d->mSizeLimit = 0;
110 d->mCachePolicy = Cache_No;
111 d->mAutoCache =
true;
114 type() +
"_" + identifier();
118 ResourceLDAPTDEIO::~ResourceLDAPTDEIO()
123 void ResourceLDAPTDEIO::enter_loop()
125 TQWidget dummy(0,0,(WFlags)(WType_Dialog | WShowModal));
126 dummy.setFocusPolicy( TQWidget::NoFocus );
127 tqt_enter_modal(&dummy);
129 tqt_leave_modal(&dummy);
132 void ResourceLDAPTDEIO::entries( TDEIO::Job*,
const TDEIO::UDSEntryList & list )
134 TDEIO::UDSEntryListConstIterator it = list.begin();
135 TDEIO::UDSEntryListConstIterator
end = list.end();
136 for (; it !=
end; ++it) {
137 TDEIO::UDSEntry::ConstIterator it2 = (*it).begin();
138 for( ; it2 != (*it).end(); it2++ ) {
139 if ( (*it2).m_uds == TDEIO::UDS_URL ) {
140 KURL tmpurl( (*it2).m_str );
141 d->mResultDn = tmpurl.path();
142 kdDebug(7125) <<
"findUid(): " << d->mResultDn <<
endl;
143 if ( d->mResultDn.startsWith(
"/") ) d->mResultDn.remove(0,1);
150 void ResourceLDAPTDEIO::listResult( TDEIO::Job *job)
152 d->mError = job->error();
153 if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED )
154 mErrorMsg = job->errorString();
160 TQString ResourceLDAPTDEIO::findUid(
const TQString &uid )
163 TDEIO::UDSEntry entry;
165 mErrorMsg = d->mResultDn =
"";
167 url.setAttributes(
"dn");
168 url.setFilter(
"(" + mAttributes[
"uid" ] +
"=" + uid +
")" + mFilter );
169 url.setExtension(
"x-dir",
"one" );
171 kdDebug(7125) <<
"ResourceLDAPTDEIO::findUid() uid: " << uid <<
" url " <<
172 url.prettyURL() <<
endl;
174 TDEIO::ListJob * listJob = TDEIO::listDir( url,
false );
176 TQ_SIGNAL( entries( TDEIO::Job *,
const TDEIO::UDSEntryList& ) ),
177 TQ_SLOT( entries( TDEIO::Job*,
const TDEIO::UDSEntryList& ) ) );
178 connect( listJob, TQ_SIGNAL( result( TDEIO::Job* ) ),
179 this, TQ_SLOT( listResult( TDEIO::Job* ) ) );
185 TQCString ResourceLDAPTDEIO::addEntry(
const TQString &attr,
const TQString &value,
bool mod )
188 if ( !attr.isEmpty() ) {
189 if ( mod ) tmp += LDIF::assembleLine(
"replace", attr ) +
"\n";
190 tmp += LDIF::assembleLine( attr, value ) +
"\n";
191 if ( mod ) tmp +=
"-\n";
196 bool ResourceLDAPTDEIO::AddresseeToLDIF( TQByteArray &ldif,
const Addressee &addr,
197 const TQString &olddn )
204 if ( olddn.isEmpty() ) {
206 switch ( d->mRDNPrefix ) {
208 dn = mAttributes[
"uid" ] +
"=" + addr.
uid() +
"," +mDn;
212 dn = mAttributes[
"commonName" ] +
"=" + addr.
assembledName() +
"," +mDn;
218 if ( olddn.startsWith( mAttributes[
"uid" ] ) ) {
219 dn = mAttributes[
"uid" ] +
"=" + addr.
uid() +
"," + olddn.section(
',', 1 );
220 }
else if ( olddn.startsWith( mAttributes[
"commonName" ] ) ) {
221 dn = mAttributes[
"commonName" ] +
"=" + addr.
assembledName() +
"," +
222 olddn.section(
',', 1 );
227 if ( olddn.lower() != dn.lower() ) {
228 tmp = LDIF::assembleLine(
"dn", olddn ) +
"\n";
229 tmp +=
"changetype: modrdn\n";
230 tmp += LDIF::assembleLine(
"newrdn", dn.section(
',', 0, 0 ) ) +
"\n";
231 tmp +=
"deleteoldrdn: 1\n\n";
236 tmp += LDIF::assembleLine(
"dn", dn ) +
"\n";
237 if ( mod ) tmp +=
"changetype: modify\n";
239 tmp +=
"objectClass: top\n";
240 TQStringList obclass = TQStringList::split(
',', mAttributes[
"objectClass" ] );
241 for ( TQStringList::iterator it = obclass.begin(); it != obclass.end(); it++ ) {
242 tmp += LDIF::assembleLine(
"objectClass", *it ) +
"\n";
246 tmp += addEntry( mAttributes[
"commonName" ], addr.
assembledName(), mod );
247 tmp += addEntry( mAttributes[
"formattedName" ], addr.formattedName(), mod );
248 tmp += addEntry( mAttributes[
"givenName" ], addr.givenName(), mod );
249 tmp += addEntry( mAttributes[
"familyName" ], addr.familyName(), mod );
250 tmp += addEntry( mAttributes[
"uid" ], addr.
uid(), mod );
254 tmp += addEntry( mAttributes[
"phoneNumber" ], number.
number().utf8(), mod );
256 tmp += addEntry( mAttributes[
"telephoneNumber" ], number.
number().utf8(), mod );
258 tmp += addEntry( mAttributes[
"facsimileTelephoneNumber" ], number.
number().utf8(), mod );
260 tmp += addEntry( mAttributes[
"mobile" ], number.
number().utf8(), mod );
262 tmp += addEntry( mAttributes[
"pager" ], number.
number().utf8(), mod );
264 tmp += addEntry( mAttributes[
"description" ], addr.note(), mod );
265 tmp += addEntry( mAttributes[
"title" ], addr.title(), mod );
266 tmp += addEntry( mAttributes[
"organization" ], addr.organization(), mod );
270 tmp += addEntry( mAttributes[
"street" ], ad.
street(), mod );
271 tmp += addEntry( mAttributes[
"state" ], ad.
region(), mod );
272 tmp += addEntry( mAttributes[
"city" ], ad.
locality(), mod );
273 tmp += addEntry( mAttributes[
"postalcode" ], ad.
postalCode(), mod );
276 TQStringList emails = addr.
emails();
277 TQStringList::ConstIterator mailIt = emails.begin();
279 if ( !mAttributes[
"mail" ].isEmpty() ) {
281 LDIF::assembleLine(
"replace", mAttributes[
"mail" ] ) +
"\n";
282 if ( mailIt != emails.end() ) {
283 tmp += LDIF::assembleLine( mAttributes[
"mail" ], *mailIt ) +
"\n";
286 if ( mod && mAttributes[
"mail" ] != mAttributes[
"mailAlias" ] ) tmp +=
"-\n";
289 if ( !mAttributes[
"mailAlias" ].isEmpty() ) {
290 if ( mod && mAttributes[
"mail" ] != mAttributes[
"mailAlias" ] ) tmp +=
291 LDIF::assembleLine(
"replace", mAttributes[
"mailAlias" ] ) +
"\n";
292 for ( ; mailIt != emails.end(); ++mailIt ) {
293 tmp += LDIF::assembleLine( mAttributes[
"mailAlias" ], *mailIt ) +
"\n" ;
295 if ( mod ) tmp +=
"-\n";
298 if ( !mAttributes[
"jpegPhoto" ].isEmpty() ) {
300 TQBuffer buffer( pic );
301 buffer.open( IO_WriteOnly );
302 addr.photo().data().save( &buffer,
"JPEG" );
305 LDIF::assembleLine(
"replace", mAttributes[
"jpegPhoto" ] ) +
"\n";
306 tmp += LDIF::assembleLine( mAttributes[
"jpegPhoto" ], pic, 76 ) +
"\n";
307 if ( mod ) tmp +=
"-\n";
311 kdDebug(7125) <<
"ldif: " << TQString(TQString::fromUtf8(tmp)) <<
endl;
316 void ResourceLDAPTDEIO::setReadOnly(
bool value )
320 Resource::setReadOnly( value );
323 void ResourceLDAPTDEIO::init()
325 if ( mPort == 0 ) mPort = 389;
333 if ( !mAttributes.contains(
"objectClass") )
334 mAttributes.insert(
"objectClass",
"inetOrgPerson" );
335 if ( !mAttributes.contains(
"commonName") )
336 mAttributes.insert(
"commonName",
"cn" );
337 if ( !mAttributes.contains(
"formattedName") )
338 mAttributes.insert(
"formattedName",
"displayName" );
339 if ( !mAttributes.contains(
"familyName") )
340 mAttributes.insert(
"familyName",
"sn" );
341 if ( !mAttributes.contains(
"givenName") )
342 mAttributes.insert(
"givenName",
"givenName" );
343 if ( !mAttributes.contains(
"mail") )
344 mAttributes.insert(
"mail",
"mail" );
345 if ( !mAttributes.contains(
"mailAlias") )
346 mAttributes.insert(
"mailAlias",
"" );
347 if ( !mAttributes.contains(
"phoneNumber") )
348 mAttributes.insert(
"phoneNumber",
"homePhone" );
349 if ( !mAttributes.contains(
"telephoneNumber") )
350 mAttributes.insert(
"telephoneNumber",
"telephoneNumber" );
351 if ( !mAttributes.contains(
"facsimileTelephoneNumber") )
352 mAttributes.insert(
"facsimileTelephoneNumber",
"facsimileTelephoneNumber" );
353 if ( !mAttributes.contains(
"mobile") )
354 mAttributes.insert(
"mobile",
"mobile" );
355 if ( !mAttributes.contains(
"pager") )
356 mAttributes.insert(
"pager",
"pager" );
357 if ( !mAttributes.contains(
"description") )
358 mAttributes.insert(
"description",
"description" );
360 if ( !mAttributes.contains(
"title") )
361 mAttributes.insert(
"title",
"title" );
362 if ( !mAttributes.contains(
"street") )
363 mAttributes.insert(
"street",
"street" );
364 if ( !mAttributes.contains(
"state") )
365 mAttributes.insert(
"state",
"st" );
366 if ( !mAttributes.contains(
"city") )
367 mAttributes.insert(
"city",
"l" );
368 if ( !mAttributes.contains(
"organization") )
369 mAttributes.insert(
"organization",
"o" );
370 if ( !mAttributes.contains(
"postalcode") )
371 mAttributes.insert(
"postalcode",
"postalCode" );
373 if ( !mAttributes.contains(
"uid") )
374 mAttributes.insert(
"uid",
"uid" );
375 if ( !mAttributes.contains(
"jpegPhoto") )
376 mAttributes.insert(
"jpegPhoto",
"jpegPhoto" );
378 d->mLDAPUrl =
KURL();
380 d->mLDAPUrl.setUser( mUser );
381 d->mLDAPUrl.setPass( mPassword );
383 d->mLDAPUrl.setProtocol( d->mSSL ?
"ldaps" :
"ldap");
384 d->mLDAPUrl.setHost( mHost );
385 d->mLDAPUrl.setPort( mPort );
386 d->mLDAPUrl.setDn( mDn );
388 if (!mAttributes.empty()) {
389 TQMap<TQString,TQString>::Iterator it;
391 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
392 if ( !it.data().isEmpty() && it.key() !=
"objectClass" )
393 attr.append( it.data() );
395 d->mLDAPUrl.setAttributes( attr );
398 d->mLDAPUrl.setScope( d->mSubTree ? LDAPUrl::Sub : LDAPUrl::One );
399 if ( !mFilter.isEmpty() && mFilter !=
"(objectClass=*)" )
400 d->mLDAPUrl.setFilter( mFilter );
401 d->mLDAPUrl.setExtension(
"x-dir",
"base" );
402 if ( d->mTLS ) d->mLDAPUrl.setExtension(
"x-tls",
"" );
403 d->mLDAPUrl.setExtension(
"x-ver", TQString::number( d->mVer ) );
405 d->mLDAPUrl.setExtension(
"x-sizelimit", TQString::number( d->mSizeLimit ) );
407 d->mLDAPUrl.setExtension(
"x-timelimit", TQString::number( d->mTimeLimit ) );
409 d->mLDAPUrl.setExtension(
"x-sasl",
"" );
410 if ( !d->mBindDN.isEmpty() ) d->mLDAPUrl.setExtension(
"bindname", d->mBindDN );
411 if ( !d->mMech.isEmpty() ) d->mLDAPUrl.setExtension(
"x-mech", d->mMech );
412 if ( !d->mRealm.isEmpty() ) d->mLDAPUrl.setExtension(
"x-realm", d->mRealm );
415 d->mReadOnly = readOnly();
417 kdDebug(7125) <<
"resource_ldaptdeio url: " << d->mLDAPUrl.prettyURL() <<
endl;
420 void ResourceLDAPTDEIO::writeConfig(
TDEConfig *config )
422 Resource::writeConfig( config );
430 config->
writeEntry(
"LdapAnonymous", mAnonymous );
433 config->
writeEntry(
"LdapSubTree", d->mSubTree );
437 config->
writeEntry(
"LdapTimeLimit", d->mTimeLimit );
438 config->
writeEntry(
"LdapSizeLimit", d->mSizeLimit );
439 config->
writeEntry(
"LdapRDNPrefix", d->mRDNPrefix );
441 config->
writeEntry(
"LdapBindDN", d->mBindDN );
442 config->
writeEntry(
"LdapCachePolicy", d->mCachePolicy );
443 config->
writeEntry(
"LdapAutoCache", d->mAutoCache );
445 TQStringList attributes;
446 TQMap<TQString, TQString>::Iterator it;
447 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it )
448 attributes << it.key() << it.data();
450 config->
writeEntry(
"LdapAttributes", attributes );
453 Ticket *ResourceLDAPTDEIO::requestSaveTicket()
455 if ( !addressBook() ) {
460 return createTicket(
this );
463 void ResourceLDAPTDEIO::releaseSaveTicket(
Ticket *ticket )
468 bool ResourceLDAPTDEIO::doOpen()
473 void ResourceLDAPTDEIO::doClose()
477 void ResourceLDAPTDEIO::createCache()
480 if ( d->mCachePolicy == Cache_NoConnection && d->mAutoCache ) {
481 d->mTmp =
new KTempFile( d->mCacheDst,
"tmp" );
482 d->mTmp->setAutoDelete(
true );
486 void ResourceLDAPTDEIO::activateCache()
488 if ( d->mTmp && d->mError == 0 ) {
490 rename( TQFile::encodeName( d->mTmp->name() ), TQFile::encodeName( d->mCacheDst ) );
498 TDEIO::Job *ResourceLDAPTDEIO::loadFromCache()
500 TDEIO::Job *job = NULL;
501 if ( d->mCachePolicy == Cache_Always ||
502 ( d->mCachePolicy == Cache_NoConnection &&
503 d->mError == TDEIO::ERR_COULD_NOT_CONNECT ) ) {
506 d->mAd =
Address( Address::Home );
508 d->mLdif.startParsing();
510 Resource::setReadOnly(
true );
512 KURL url( d->mCacheDst );
513 job = TDEIO::get( url,
true,
false );
514 connect( job, TQ_SIGNAL( data( TDEIO::Job*,
const TQByteArray& ) ),
515 this, TQ_SLOT( data( TDEIO::Job*,
const TQByteArray& ) ) );
520 bool ResourceLDAPTDEIO::load()
522 kdDebug(7125) <<
"ResourceLDAPTDEIO::load()" <<
endl;
528 d->mAd =
Address( Address::Home );
530 d->mLdif.startParsing();
533 Resource::setReadOnly( d->mReadOnly );
536 if ( d->mCachePolicy != Cache_Always ) {
537 job = TDEIO::get( d->mLDAPUrl,
true,
false );
538 connect( job, TQ_SIGNAL( data( TDEIO::Job*,
const TQByteArray& ) ),
539 this, TQ_SLOT( data( TDEIO::Job*,
const TQByteArray& ) ) );
540 connect( job, TQ_SIGNAL( result( TDEIO::Job* ) ),
541 this, TQ_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) );
545 job = loadFromCache();
547 connect( job, TQ_SIGNAL( result( TDEIO::Job* ) ),
548 this, TQ_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) );
551 if ( mErrorMsg.isEmpty() ) {
552 kdDebug(7125) <<
"ResourceLDAPTDEIO load ok!" <<
endl;
555 kdDebug(7125) <<
"ResourceLDAPTDEIO load finished with error: " << mErrorMsg <<
endl;
556 addressBook()->error( mErrorMsg );
561 bool ResourceLDAPTDEIO::asyncLoad()
566 d->mAd =
Address( Address::Home );
568 d->mLdif.startParsing();
570 Resource::setReadOnly( d->mReadOnly );
573 if ( d->mCachePolicy != Cache_Always ) {
574 TDEIO::Job *job = TDEIO::get( d->mLDAPUrl,
true,
false );
575 connect( job, TQ_SIGNAL( data( TDEIO::Job*,
const TQByteArray& ) ),
576 this, TQ_SLOT( data( TDEIO::Job*,
const TQByteArray& ) ) );
577 connect( job, TQ_SIGNAL( result( TDEIO::Job* ) ),
578 this, TQ_SLOT( result( TDEIO::Job* ) ) );
585 void ResourceLDAPTDEIO::data( TDEIO::Job *,
const TQByteArray &data )
588 d->mLdif.setLDIF( data );
590 d->mTmp->file()->writeBlock( data );
600 ret = d->mLdif.nextItem();
603 kdDebug(7125) <<
"new entry: " << d->mLdif.dn() <<
endl;
606 name = d->mLdif.attr().lower();
607 value = d->mLdif.val();
608 if ( name == mAttributes[
"commonName" ].lower() ) {
609 if ( !d->mAddr.formattedName().isEmpty() ) {
610 TQString fn = d->mAddr.formattedName();
611 d->mAddr.setNameFromString( TQString::fromUtf8( value, value.size() ) );
612 d->mAddr.setFormattedName( fn );
614 d->mAddr.setNameFromString( TQString::fromUtf8( value, value.size() ) );
615 }
else if ( name == mAttributes[
"formattedName" ].lower() ) {
616 d->mAddr.setFormattedName( TQString::fromUtf8( value, value.size() ) );
617 }
else if ( name == mAttributes[
"givenName" ].lower() ) {
618 d->mAddr.setGivenName( TQString::fromUtf8( value, value.size() ) );
619 }
else if ( name == mAttributes[
"mail" ].lower() ) {
620 d->mAddr.insertEmail( TQString::fromUtf8( value, value.size() ),
true );
621 }
else if ( name == mAttributes[
"mailAlias" ].lower() ) {
622 d->mAddr.insertEmail( TQString::fromUtf8( value, value.size() ),
false );
623 }
else if ( name == mAttributes[
"phoneNumber" ].lower() ) {
625 phone.
setNumber( TQString::fromUtf8( value, value.size() ) );
626 d->mAddr.insertPhoneNumber( phone );
627 }
else if ( name == mAttributes[
"telephoneNumber" ].lower() ) {
628 PhoneNumber phone( TQString::fromUtf8( value, value.size() ),
630 d->mAddr.insertPhoneNumber( phone );
631 }
else if ( name == mAttributes[
"facsimileTelephoneNumber" ].lower() ) {
632 PhoneNumber phone( TQString::fromUtf8( value, value.size() ),
634 d->mAddr.insertPhoneNumber( phone );
635 }
else if ( name == mAttributes[
"mobile" ].lower() ) {
636 PhoneNumber phone( TQString::fromUtf8( value, value.size() ),
638 d->mAddr.insertPhoneNumber( phone );
639 }
else if ( name == mAttributes[
"pager" ].lower() ) {
640 PhoneNumber phone( TQString::fromUtf8( value, value.size() ),
641 PhoneNumber::Pager );
642 d->mAddr.insertPhoneNumber( phone );
643 }
else if ( name == mAttributes[
"description" ].lower() ) {
644 d->mAddr.setNote( TQString::fromUtf8( value, value.size() ) );
645 }
else if ( name == mAttributes[
"title" ].lower() ) {
646 d->mAddr.setTitle( TQString::fromUtf8( value, value.size() ) );
647 }
else if ( name == mAttributes[
"street" ].lower() ) {
648 d->mAd.setStreet( TQString::fromUtf8( value, value.size() ) );
649 }
else if ( name == mAttributes[
"state" ].lower() ) {
650 d->mAd.setRegion( TQString::fromUtf8( value, value.size() ) );
651 }
else if ( name == mAttributes[
"city" ].lower() ) {
652 d->mAd.setLocality( TQString::fromUtf8( value, value.size() ) );
653 }
else if ( name == mAttributes[
"postalcode" ].lower() ) {
654 d->mAd.setPostalCode( TQString::fromUtf8( value, value.size() ) );
655 }
else if ( name == mAttributes[
"organization" ].lower() ) {
656 d->mAddr.setOrganization( TQString::fromUtf8( value, value.size() ) );
657 }
else if ( name == mAttributes[
"familyName" ].lower() ) {
658 d->mAddr.setFamilyName( TQString::fromUtf8( value, value.size() ) );
659 }
else if ( name == mAttributes[
"uid" ].lower() ) {
660 d->mAddr.setUid( TQString::fromUtf8( value, value.size() ) );
661 }
else if ( name == mAttributes[
"jpegPhoto" ].lower() ) {
662 TDEABC::Picture photo;
663 TQImage img( value );
664 if ( !img.isNull() ) {
665 photo.setData( img );
666 photo.setType(
"image/jpeg" );
667 d->mAddr.setPhoto( photo );
672 case LDIF::EndEntry: {
673 d->mAddr.setResource(
this );
674 d->mAddr.insertAddress( d->mAd );
675 d->mAddr.setChanged(
false );
676 insertAddressee( d->mAddr );
679 d->mAd =
Address( Address::Home );
685 }
while ( ret != LDIF::MoreData );
688 void ResourceLDAPTDEIO::loadCacheResult( TDEIO::Job *job )
691 d->mError = job->error();
692 if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) {
693 mErrorMsg = job->errorString();
695 if ( !mErrorMsg.isEmpty() )
696 emit loadingError(
this, mErrorMsg );
698 emit loadingFinished(
this );
701 void ResourceLDAPTDEIO::result( TDEIO::Job *job )
705 d->mError = job->error();
706 if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) {
707 mErrorMsg = job->errorString();
715 cjob = loadFromCache();
717 connect( cjob, TQ_SIGNAL( result( TDEIO::Job* ) ),
718 this, TQ_SLOT( loadCacheResult( TDEIO::Job* ) ) );
720 if ( !mErrorMsg.isEmpty() )
721 emit loadingError(
this, mErrorMsg );
723 emit loadingFinished(
this );
727 bool ResourceLDAPTDEIO::save(
Ticket* )
731 d->mSaveIt = begin();
732 TDEIO::Job *job = TDEIO::put( d->mLDAPUrl, -1,
true,
false,
false );
733 connect( job, TQ_SIGNAL( dataReq( TDEIO::Job*, TQByteArray& ) ),
734 this, TQ_SLOT( saveData( TDEIO::Job*, TQByteArray& ) ) );
735 connect( job, TQ_SIGNAL( result( TDEIO::Job* ) ),
736 this, TQ_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) );
738 if ( mErrorMsg.isEmpty() ) {
739 kdDebug(7125) <<
"ResourceLDAPTDEIO save ok!" <<
endl;
742 kdDebug(7125) <<
"ResourceLDAPTDEIO finished with error: " << mErrorMsg <<
endl;
743 addressBook()->error( mErrorMsg );
748 bool ResourceLDAPTDEIO::asyncSave(
Ticket* )
750 kdDebug(7125) <<
"ResourceLDAPTDEIO asyncSave" <<
endl;
751 d->mSaveIt = begin();
752 TDEIO::Job *job = TDEIO::put( d->mLDAPUrl, -1,
true,
false,
false );
753 connect( job, TQ_SIGNAL( dataReq( TDEIO::Job*, TQByteArray& ) ),
754 this, TQ_SLOT( saveData( TDEIO::Job*, TQByteArray& ) ) );
755 connect( job, TQ_SIGNAL( result( TDEIO::Job* ) ),
756 this, TQ_SLOT( saveResult( TDEIO::Job* ) ) );
760 void ResourceLDAPTDEIO::syncLoadSaveResult( TDEIO::Job *job )
762 d->mError = job->error();
763 if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED )
764 mErrorMsg = job->errorString();
772 void ResourceLDAPTDEIO::saveResult( TDEIO::Job *job )
774 d->mError = job->error();
775 if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED )
776 emit savingError(
this, job->errorString() );
778 emit savingFinished(
this );
781 void ResourceLDAPTDEIO::saveData( TDEIO::Job*, TQByteArray& data )
783 while ( d->mSaveIt !=
end() &&
784 !(*d->mSaveIt).changed() ) d->mSaveIt++;
786 if ( d->mSaveIt ==
end() ) {
787 kdDebug(7125) <<
"ResourceLDAPTDEIO endData" <<
endl;
792 kdDebug(7125) <<
"ResourceLDAPTDEIO saveData: " << (*d->mSaveIt).assembledName() <<
endl;
794 AddresseeToLDIF( data, *d->mSaveIt, findUid( (*d->mSaveIt).uid() ) );
797 (*d->mSaveIt).setChanged(
false );
802 void ResourceLDAPTDEIO::removeAddressee(
const Addressee& addr )
804 TQString dn = findUid( addr.
uid() );
806 kdDebug(7125) <<
"ResourceLDAPTDEIO: removeAddressee: " << dn <<
endl;
808 if ( !mErrorMsg.isEmpty() ) {
809 addressBook()->error( mErrorMsg );
812 if ( !dn.isEmpty() ) {
813 kdDebug(7125) <<
"ResourceLDAPTDEIO: found uid: " << dn <<
endl;
815 url.setPath(
"/" + dn );
816 url.setExtension(
"x-dir",
"base" );
817 url.setScope( LDAPUrl::Base );
818 if ( TDEIO::NetAccess::del( url, NULL ) ) mAddrMap.erase( addr.
uid() );
821 mAddrMap.erase( addr.
uid() );
826 void ResourceLDAPTDEIO::setUser(
const TQString &user )
831 TQString ResourceLDAPTDEIO::user()
const
836 void ResourceLDAPTDEIO::setPassword(
const TQString &password )
838 mPassword = password;
841 TQString ResourceLDAPTDEIO::password()
const
846 void ResourceLDAPTDEIO::setDn(
const TQString &dn )
851 TQString ResourceLDAPTDEIO::dn()
const
856 void ResourceLDAPTDEIO::setHost(
const TQString &host )
861 TQString ResourceLDAPTDEIO::host()
const
866 void ResourceLDAPTDEIO::setPort(
int port )
871 int ResourceLDAPTDEIO::port()
const
876 void ResourceLDAPTDEIO::setVer(
int ver )
881 int ResourceLDAPTDEIO::ver()
const
886 void ResourceLDAPTDEIO::setSizeLimit(
int sizelimit )
888 d->mSizeLimit = sizelimit;
891 int ResourceLDAPTDEIO::sizeLimit()
893 return d->mSizeLimit;
896 void ResourceLDAPTDEIO::setTimeLimit(
int timelimit )
898 d->mTimeLimit = timelimit;
901 int ResourceLDAPTDEIO::timeLimit()
903 return d->mTimeLimit;
906 void ResourceLDAPTDEIO::setFilter(
const TQString &filter )
911 TQString ResourceLDAPTDEIO::filter()
const
916 void ResourceLDAPTDEIO::setIsAnonymous(
bool value )
921 bool ResourceLDAPTDEIO::isAnonymous()
const
926 void ResourceLDAPTDEIO::setIsTLS(
bool value )
931 bool ResourceLDAPTDEIO::isTLS()
const
935 void ResourceLDAPTDEIO::setIsSSL(
bool value )
940 bool ResourceLDAPTDEIO::isSSL()
const
945 void ResourceLDAPTDEIO::setIsSubTree(
bool value )
950 bool ResourceLDAPTDEIO::isSubTree()
const
955 void ResourceLDAPTDEIO::setAttributes(
const TQMap<TQString, TQString> &attributes )
957 mAttributes = attributes;
960 TQMap<TQString, TQString> ResourceLDAPTDEIO::attributes()
const
965 void ResourceLDAPTDEIO::setRDNPrefix(
int value )
967 d->mRDNPrefix = value;
970 int ResourceLDAPTDEIO::RDNPrefix()
const
972 return d->mRDNPrefix;
975 void ResourceLDAPTDEIO::setIsSASL(
bool value )
980 bool ResourceLDAPTDEIO::isSASL()
const
985 void ResourceLDAPTDEIO::setMech(
const TQString &mech )
990 TQString ResourceLDAPTDEIO::mech()
const
995 void ResourceLDAPTDEIO::setRealm(
const TQString &realm )
1000 TQString ResourceLDAPTDEIO::realm()
const
1005 void ResourceLDAPTDEIO::setBindDN(
const TQString &binddn )
1007 d->mBindDN = binddn;
1010 TQString ResourceLDAPTDEIO::bindDN()
const
1015 void ResourceLDAPTDEIO::setCachePolicy(
int pol )
1017 d->mCachePolicy = pol;
1020 int ResourceLDAPTDEIO::cachePolicy()
const
1022 return d->mCachePolicy;
1025 void ResourceLDAPTDEIO::setAutoCache(
bool value )
1027 d->mAutoCache = value;
1030 bool ResourceLDAPTDEIO::autoCache()
1032 return d->mAutoCache;
1035 TQString ResourceLDAPTDEIO::cacheDst()
const
1037 return d->mCacheDst;
1041 #include "resourceldaptdeio.moc"
static TQString obscure(const TQString &str)
Postal address information.
TQString street() const
Returns the street.
bool isEmpty() const
Returns true, if the address is empty.
TQString postalCode() const
Returns the postal code.
TQString region() const
Returns the region.
TQString locality() const
Returns the locality.
TQStringList emails() const
Return list of all email addresses.
TQString assembledName() const
Return the name that consists of all name parts.
Address address(int type) const
Return address, which matches the given type.
PhoneNumber phoneNumber(int type) const
Return phone number, which matches the given type.
TQString uid() const
Return unique identifier.
TQString number() const
Returns the number.
void setNumber(const TQString &)
Sets the number.
Helper class for handling coordinated save of address books.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
int readNumEntry(const TQString &pKey, int nDefault=0) const
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
int readListEntry(const TQString &pKey, TQStrList &list, char sep=',') const
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
static TDEStandardDirs * dirs()
TQString saveLocation(const char *type, const TQString &suffix=TQString::null, bool create=true) const
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
static data, shared by ALL addressee objects
TQString name(StdAccel id)
const TDEShortcut & end()