23 #include <kldap/ldapoperation.h>
24 #include <kldap/ldif.h>
25 #include <kldap/ldapcontrol.h>
26 #include <kldap/ldapdefs.h>
31 using namespace KLDAP;
35 m_state( Disconnected ),
45 if ( m_state != Disconnected )
55 m_conn.setServer( m_server );
56 if ( m_conn.connect() != 0 ) {
57 kWarning() <<
"failed to connect: " << m_conn.connectionError();
68 QMetaObject::invokeMethod(
this,
"quit", Qt::QueuedConnection );
69 QMetaObject::invokeMethod(
this,
"deleteLater", Qt::QueuedConnection );
77 m_state = Disconnected;
80 void LdapSession::authenticate()
83 LdapOperation op( m_conn );
85 int retval = op.bind_s();
87 kDebug() <<
"connected!";
88 m_state = Authenticated;
91 if ( retval == KLDAP_INVALID_CREDENTIALS ||
92 retval == KLDAP_INSUFFICIENT_ACCESS ||
93 retval == KLDAP_INAPPROPRIATE_AUTH ||
94 retval == KLDAP_UNWILLING_TO_PERFORM ) {
96 if ( m_server.auth() != LdapServer::SASL ) {
97 m_server.setBindDn( m_server.user() );
99 m_conn.setServer( m_server );
103 kDebug() <<
"error" << retval;
114 job->moveToThread(
this );
115 connect( job, SIGNAL(result(
KJob*)), SLOT(jobDone(
KJob*)) );
116 QMutexLocker locker( &m_mutex );
117 m_jobQueue.enqueue( job );
118 QMetaObject::invokeMethod(
this,
"executeNext", Qt::QueuedConnection );
125 QMetaObject::invokeMethod(
this,
"executeNext", Qt::QueuedConnection );
130 void LdapSession::executeNext()
132 if ( m_state != Authenticated || m_currentJob )
134 QMutexLocker locker( &m_mutex );
135 if ( m_jobQueue.isEmpty() )
137 m_currentJob = m_jobQueue.dequeue();
139 QMetaObject::invokeMethod( m_currentJob,
"triggerStart", Qt::QueuedConnection );
152 void LdapSession::jobDone(
KJob* job)
154 if ( m_currentJob == job )
156 QMutexLocker locker( &m_mutex );
157 m_jobQueue.removeAll( static_cast<LdapQueryJob*>( job ) );
159 QMetaObject::invokeMethod(
this,
"executeNext", Qt::QueuedConnection );
163 #include "ldapsession.moc"
void disconnectAndDelete()
call this instead of the dtor
void connectToServerInternal()
LdapServer server() const
LdapConnection & connection()
void disconnectFromServerInternal()
LdapQueryJob * get(const LdapUrl &url)
void connectToServer(const LdapServer &server)
call this instead of start()
LdapSession(QObject *parent=0)