kmail Library API Documentation

kmservertest.cpp

00001 /* -*- c++ -*- 00002 kmservertest.cpp 00003 00004 This file is part of KMail, the KDE mail client. 00005 Copyright (c) 2001-2002 Michael Haeckel <haeckel@kde.org> 00006 Copyright (c) 2003 Marc Mutz <mutz@kde.org> 00007 00008 KMail is free software; you can redistribute it and/or modify it 00009 under the terms of the GNU General Public License, version 2, as 00010 published by the Free Software Foundation. 00011 00012 KMail is distributed in the hope that it will be useful, but 00013 WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the Qt library by Trolltech AS, Norway (or with modified versions 00024 of Qt that use the same license as Qt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 Qt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 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 <kapplication.h> 00042 #include <kio/scheduler.h> 00043 #include <kio/slave.h> 00044 #include <kio/job.h> 00045 #include <kio/global.h> 00046 00047 //----------------------------------------------------------------------------- 00048 KMServerTest::KMServerTest( const QString & protocol, const QString & host, int port ) 00049 : QObject(), 00050 mProtocol( protocol ), mHost( host ), 00051 mSSL( false ), mJob( 0 ), mSlave( 0 ), mConnectionErrorCount( 0 ) 00052 { 00053 KIO::Scheduler::connect( 00054 SIGNAL(slaveError(KIO::Slave *, int, const QString &)), 00055 this, SLOT(slotSlaveResult(KIO::Slave *, int, const QString &))); 00056 00057 if ( port == 993 || port == 995 || port == 465 ) 00058 port = 0; 00059 00060 startOffSlave( port ); 00061 } 00062 00063 //----------------------------------------------------------------------------- 00064 KMServerTest::~KMServerTest() 00065 { 00066 if (mJob) mJob->kill(TRUE); 00067 } 00068 00069 00070 KIO::MetaData KMServerTest::slaveConfig() const { 00071 KIO::MetaData md; 00072 md.insert( "nologin", "on" ); 00073 return md; 00074 } 00075 00076 void KMServerTest::startOffSlave( int port ) { 00077 KURL url; 00078 url.setProtocol( mSSL ? mProtocol + 's' : mProtocol ); 00079 url.setHost( mHost ); 00080 if ( port ) 00081 url.setPort( port ); 00082 00083 mSlave = KIO::Scheduler::getConnectedSlave( url, slaveConfig() ); 00084 if ( !mSlave ) { 00085 slotSlaveResult( 0, 1 ); 00086 return; 00087 } 00088 connect( mSlave, SIGNAL(metaData(const KIO::MetaData&)), 00089 SLOT(slotMetaData(const KIO::MetaData&)) ); 00090 00091 QByteArray packedArgs; 00092 QDataStream stream( packedArgs, IO_WriteOnly ); 00093 00094 stream << (int) 'c'; 00095 00096 mJob = KIO::special( url, packedArgs, false ); 00097 KIO::Scheduler::assignJobToSlave( mSlave, mJob ); 00098 connect( mJob, SIGNAL(result(KIO::Job*)), SLOT(slotResult(KIO::Job*)) ); 00099 connect( mJob, SIGNAL(infoMessage(KIO::Job*,const QString&)), 00100 SLOT(slotData(KIO::Job*,const QString&)) ); 00101 } 00102 00103 00104 //----------------------------------------------------------------------------- 00105 void KMServerTest::slotData(KIO::Job *, const QString &data) 00106 { 00107 if ( mSSL ) 00108 mListSSL = QStringList::split(' ', data); 00109 else 00110 mListNormal = QStringList::split(' ', data); 00111 } 00112 00113 00114 void KMServerTest::slotMetaData( const KIO::MetaData & md ) { 00115 KIO::MetaData::const_iterator it = md.find( "PLAIN AUTH METHODS" ); 00116 if ( it != md.end() ) { 00117 mAuthNone = it.data(); 00118 kdDebug(5006) << "mAuthNone: " << mAuthNone << endl; 00119 } 00120 it = md.find( "TLS AUTH METHODS" ); 00121 if ( it != md.end() ) { 00122 mAuthTLS = it.data(); 00123 kdDebug(5006) << "mAuthTLS: " << mAuthTLS << endl; 00124 } 00125 it = md.find( "SSL AUTH METHODS" ); 00126 if ( it != md.end() ) { 00127 mAuthSSL = it.data(); 00128 kdDebug(5006) << "mAuthSSL: " << mAuthSSL << endl; 00129 } 00130 } 00131 00132 //----------------------------------------------------------------------------- 00133 void KMServerTest::slotResult(KIO::Job *job) 00134 { 00135 slotSlaveResult(mSlave, job->error()); 00136 } 00137 00138 //----------------------------------------------------------------------------- 00139 void KMServerTest::slotSlaveResult(KIO::Slave *aSlave, int error, 00140 const QString &errorText) 00141 { 00142 if (aSlave != mSlave) return; 00143 if (error != KIO::ERR_SLAVE_DIED && mSlave) 00144 { 00145 // disconnect slave after every connect 00146 KIO::Scheduler::disconnectSlave(mSlave); 00147 mSlave = 0; 00148 } 00149 if ( error == KIO::ERR_COULD_NOT_CONNECT ) 00150 { 00151 // if one of the two connection tests fails we ignore the error 00152 // if both fail the host is probably not correct so we display the error 00153 if ( mConnectionErrorCount == 0 ) 00154 { 00155 error = 0; 00156 } 00157 ++mConnectionErrorCount; 00158 } 00159 if ( error ) 00160 { 00161 mJob = 0; 00162 KMessageBox::error( kapp->activeWindow(), 00163 KIO::buildErrorString( error, errorText ), 00164 i18n("Error") ); 00165 emit capabilities( mListNormal, mListSSL ); 00166 emit capabilities( mListNormal, mListSSL, mAuthNone, mAuthSSL, mAuthTLS ); 00167 return; 00168 } 00169 if (!mSSL) { 00170 mSSL = true; 00171 mListNormal.append("NORMAL-CONNECTION"); 00172 startOffSlave(); 00173 } else { 00174 mListSSL.append("SSL"); 00175 mJob = 0; 00176 00177 emit capabilities( mListNormal, mListSSL ); 00178 emit capabilities( mListNormal, mListSSL, mAuthNone, mAuthSSL, mAuthTLS ); 00179 } 00180 } 00181 00182 00183 #include "kmservertest.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:24 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003