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 <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"
KDE Logo
This file is part of the documentation for kmail Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:04 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003