35 #include "kmservertest.h"
37 #include <tdelocale.h>
38 #include <tdemessagebox.h>
41 #include <tdeapplication.h>
42 #include <tdeio/scheduler.h>
43 #include <tdeio/slave.h>
44 #include <tdeio/job.h>
45 #include <tdeio/global.h>
48 KMServerTest::KMServerTest(
const TQString & protocol,
const TQString & host,
int port )
50 mProtocol( protocol ), mHost( host ),
51 mSSL( false ), mJob( 0 ), mSlave( 0 ), mConnectionErrorCount( 0 )
53 TDEIO::Scheduler::connect(
54 TQ_SIGNAL(slaveError(TDEIO::Slave *,
int,
const TQString &)),
55 this, TQ_SLOT(slotSlaveResult(TDEIO::Slave *,
int,
const TQString &)));
57 if ( port == 993 || port == 995 || port == 465 )
60 startOffSlave( port );
64 KMServerTest::~KMServerTest()
66 if (mJob) mJob->kill(TRUE);
70 TDEIO::MetaData KMServerTest::slaveConfig()
const {
72 md.insert(
"nologin",
"on" );
76 void KMServerTest::startOffSlave(
int port ) {
78 url.setProtocol( mSSL ? mProtocol +
's' : mProtocol );
83 mSlave = TDEIO::Scheduler::getConnectedSlave( url, slaveConfig() );
85 slotSlaveResult( 0, 1 );
88 connect( mSlave, TQ_SIGNAL(metaData(
const TDEIO::MetaData&)),
89 TQ_SLOT(slotMetaData(
const TDEIO::MetaData&)) );
91 TQByteArray packedArgs;
92 TQDataStream stream( packedArgs, IO_WriteOnly );
96 mJob = TDEIO::special( url, packedArgs,
false );
97 TDEIO::Scheduler::assignJobToSlave( mSlave, mJob );
98 connect( mJob, TQ_SIGNAL(result(TDEIO::Job*)), TQ_SLOT(slotResult(TDEIO::Job*)) );
99 connect( mJob, TQ_SIGNAL(infoMessage(TDEIO::Job*,
const TQString&)),
100 TQ_SLOT(slotData(TDEIO::Job*,
const TQString&)) );
105 void KMServerTest::slotData(TDEIO::Job *,
const TQString &data)
108 mListSSL = TQStringList::split(
' ', data);
110 mListNormal = TQStringList::split(
' ', data);
114 void KMServerTest::slotMetaData(
const TDEIO::MetaData & md ) {
115 TDEIO::MetaData::const_iterator it = md.find(
"PLAIN AUTH METHODS" );
116 if ( it != md.end() ) {
117 mAuthNone = it.data();
118 kdDebug(5006) <<
"mAuthNone: " << mAuthNone << endl;
120 it = md.find(
"TLS AUTH METHODS" );
121 if ( it != md.end() ) {
122 mAuthTLS = it.data();
123 kdDebug(5006) <<
"mAuthTLS: " << mAuthTLS << endl;
125 it = md.find(
"SSL AUTH METHODS" );
126 if ( it != md.end() ) {
127 mAuthSSL = it.data();
128 kdDebug(5006) <<
"mAuthSSL: " << mAuthSSL << endl;
133 void KMServerTest::slotResult(TDEIO::Job *job)
135 slotSlaveResult(mSlave, job->error());
139 void KMServerTest::slotSlaveResult(TDEIO::Slave *aSlave,
int error,
140 const TQString &errorText)
142 if (aSlave != mSlave)
return;
143 if ( mSSL && error == 0 ) {
147 mListSSL.append(
"SSL");
150 if (error != TDEIO::ERR_SLAVE_DIED && mSlave)
153 TDEIO::Scheduler::disconnectSlave(mSlave);
156 if ( error == TDEIO::ERR_COULD_NOT_CONNECT )
160 if ( mConnectionErrorCount == 0 )
164 ++mConnectionErrorCount;
169 KMessageBox::error( kapp->activeWindow(),
170 TDEIO::buildErrorString( error, errorText ),
172 emit capabilities( mListNormal, mListSSL );
173 emit capabilities( mListNormal, mListSSL, mAuthNone, mAuthSSL, mAuthTLS );
178 mListNormal.append(
"NORMAL-CONNECTION");
183 emit capabilities( mListNormal, mListSSL );
184 emit capabilities( mListNormal, mListSSL, mAuthNone, mAuthSSL, mAuthTLS );
189 #include "kmservertest.moc"