kmservertest.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <config.h>
00034
00035 #include "kmservertest.h"
00036
00037 #include <klocale.h>
00038 #include <kmessagebox.h>
00039 #include <kdebug.h>
00040 #include <kurl.h>
00041 #include <kio/scheduler.h>
00042 #include <kio/slave.h>
00043 #include <kio/job.h>
00044 #include <kio/global.h>
00045
00046
00047 KMServerTest::KMServerTest( const QString & protocol, const QString & host, int port )
00048 : QObject(),
00049 mProtocol( protocol ), mHost( host ),
00050 mSSL( false ), mJob( 0 ), mSlave( 0 )
00051 {
00052 KIO::Scheduler::connect(
00053 SIGNAL(slaveError(KIO::Slave *, int, const QString &)),
00054 this, SLOT(slotSlaveResult(KIO::Slave *, int, const QString &)));
00055
00056 if ( port == 993 || port == 995 || port == 465 )
00057 port = 0;
00058
00059 startOffSlave( port );
00060 }
00061
00062
00063 KMServerTest::~KMServerTest()
00064 {
00065 if (mJob) mJob->kill(TRUE);
00066 }
00067
00068
00069 KIO::MetaData KMServerTest::slaveConfig() const {
00070 KIO::MetaData md;
00071 md.insert( "nologin", "on" );
00072 return md;
00073 }
00074
00075 void KMServerTest::startOffSlave( int port ) {
00076 KURL url;
00077 url.setProtocol( mSSL ? mProtocol + 's' : mProtocol );
00078 url.setHost( mHost );
00079 if ( port )
00080 url.setPort( port );
00081
00082 mSlave = KIO::Scheduler::getConnectedSlave( url, slaveConfig() );
00083 if ( !mSlave ) {
00084 slotSlaveResult( 0, 1 );
00085 return;
00086 }
00087 connect( mSlave, SIGNAL(metaData(const KIO::MetaData&)),
00088 SLOT(slotMetaData(const KIO::MetaData&)) );
00089
00090 QByteArray packedArgs;
00091 QDataStream stream( packedArgs, IO_WriteOnly );
00092
00093 stream << (int) 'c';
00094
00095 mJob = KIO::special( url, packedArgs, false );
00096 KIO::Scheduler::assignJobToSlave( mSlave, mJob );
00097 connect( mJob, SIGNAL(result(KIO::Job*)), SLOT(slotResult(KIO::Job*)) );
00098 connect( mJob, SIGNAL(infoMessage(KIO::Job*,const QString&)),
00099 SLOT(slotData(KIO::Job*,const QString&)) );
00100 }
00101
00102
00103
00104 void KMServerTest::slotData(KIO::Job *, const QString &data)
00105 {
00106 if ( mList.empty() )
00107 mList = QStringList::split(' ', data);
00108 kdDebug(5006) << data << endl;
00109 kdDebug(5006) << "count = " << mList.count() << endl;
00110 }
00111
00112
00113 void KMServerTest::slotMetaData( const KIO::MetaData & md ) {
00114 KIO::MetaData::const_iterator it = md.find( "PLAIN AUTH METHODS" );
00115 if ( it != md.end() )
00116 mAuthNone = it.data();
00117 it = md.find( "TLS AUTH METHODS" );
00118 if ( it != md.end() )
00119 mAuthTLS = it.data();
00120 it = md.find( "SSL AUTH METHODS" );
00121 if ( it != md.end() )
00122 mAuthSSL = it.data();
00123 }
00124
00125
00126 void KMServerTest::slotResult(KIO::Job *job)
00127 {
00128 slotSlaveResult(mSlave, job->error());
00129 }
00130
00131
00132 void KMServerTest::slotSlaveResult(KIO::Slave *aSlave, int error,
00133 const QString &)
00134 {
00135 if (aSlave != mSlave) return;
00136 if (error != KIO::ERR_SLAVE_DIED && mSlave)
00137 {
00138 KIO::Scheduler::disconnectSlave(mSlave);
00139 mSlave = 0;
00140 }
00141 if (!mSSL) {
00142 mSSL = true;
00143 if ( error )
00144 mList.clear();
00145 else
00146 mList.append("NORMAL-CONNECTION");
00147 startOffSlave();
00148 } else {
00149 if (!error) mList.append("SSL");
00150
00151 if (mList.isEmpty())
00152 mJob->showErrorDialog( 0L );
00153
00154 mJob = 0;
00155
00156 emit capabilities(mList);
00157 emit capabilities(mList, mAuthNone, mAuthSSL, mAuthTLS);
00158 }
00159 }
00160
00161
00162 #include "kmservertest.moc"
This file is part of the documentation for kmail Library Version 3.2.2.