35 #include "kmservertest.h"
38 #include <kmessagebox.h>
41 #include <kapplication.h>
42 #include <kio/scheduler.h>
43 #include <kio/slave.h>
45 #include <kio/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 KIO::Scheduler::connect(
54 TQT_SIGNAL(slaveError(KIO::Slave *,
int,
const TQString &)),
55 this, TQT_SLOT(slotSlaveResult(KIO::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 KIO::MetaData KMServerTest::slaveConfig()
const {
72 md.insert(
"nologin",
"on" );
76 void KMServerTest::startOffSlave(
int port ) {
78 url.setProtocol( mSSL ? mProtocol +
's' : mProtocol );
83 mSlave = KIO::Scheduler::getConnectedSlave( url, slaveConfig() );
85 slotSlaveResult( 0, 1 );
88 connect( mSlave, TQT_SIGNAL(metaData(
const KIO::MetaData&)),
89 TQT_SLOT(slotMetaData(
const KIO::MetaData&)) );
91 TQByteArray packedArgs;
92 TQDataStream stream( packedArgs, IO_WriteOnly );
96 mJob = KIO::special( url, packedArgs,
false );
97 KIO::Scheduler::assignJobToSlave( mSlave, mJob );
98 connect( mJob, TQT_SIGNAL(result(KIO::Job*)), TQT_SLOT(slotResult(KIO::Job*)) );
99 connect( mJob, TQT_SIGNAL(infoMessage(KIO::Job*,
const TQString&)),
100 TQT_SLOT(slotData(KIO::Job*,
const TQString&)) );
105 void KMServerTest::slotData(KIO::Job *,
const TQString &data)
108 mListSSL = TQStringList::split(
' ', data);
110 mListNormal = TQStringList::split(
' ', data);
114 void KMServerTest::slotMetaData(
const KIO::MetaData & md ) {
115 KIO::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(KIO::Job *job)
135 slotSlaveResult(mSlave, job->error());
139 void KMServerTest::slotSlaveResult(KIO::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 != KIO::ERR_SLAVE_DIED && mSlave)
153 KIO::Scheduler::disconnectSlave(mSlave);
156 if ( error == KIO::ERR_COULD_NOT_CONNECT )
160 if ( mConnectionErrorCount == 0 )
164 ++mConnectionErrorCount;
169 KMessageBox::error( TQT_TQWIDGET(kapp->activeWindow()),
170 KIO::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"