From d31befda34a6baaaec1bbebf8b5dc6229219cbbf Mon Sep 17 00:00:00 2001 From: rjarosz Date: Mon, 7 May 2007 19:05:40 +0000 Subject: [PATCH] Clean up unnecessary stream and connector classes and use QTcpSocket and QAbstractSocket. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/KDE/kdenetwork@662271 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/protocols/oscar/aim/aimaccount.cpp | 5 +- kopete/protocols/oscar/icq/icqaccount.cpp | 5 +- kopete/protocols/oscar/liboscar/CMakeLists.txt | 4 - kopete/protocols/oscar/liboscar/bytestream.cpp | 263 ------------------- kopete/protocols/oscar/liboscar/bytestream.h | 76 ------ kopete/protocols/oscar/liboscar/client.cpp | 22 +- kopete/protocols/oscar/liboscar/client.h | 10 +- kopete/protocols/oscar/liboscar/connection.cpp | 12 +- kopete/protocols/oscar/liboscar/connection.h | 12 +- kopete/protocols/oscar/liboscar/connector.cpp | 62 ----- kopete/protocols/oscar/liboscar/connector.h | 59 ----- kopete/protocols/oscar/liboscar/coreprotocol.cpp | 6 +- .../protocols/oscar/liboscar/oscarbytestream.cpp | 149 ----------- kopete/protocols/oscar/liboscar/oscarbytestream.h | 72 ------ .../protocols/oscar/liboscar/oscarclientstream.cpp | 288 +++++++-------------- .../protocols/oscar/liboscar/oscarclientstream.h | 265 +++++++------------ kopete/protocols/oscar/liboscar/oscarconnector.cpp | 108 -------- kopete/protocols/oscar/liboscar/oscarconnector.h | 69 ----- kopete/protocols/oscar/liboscar/stream.cpp | 4 +- kopete/protocols/oscar/liboscar/stream.h | 35 +-- .../oscar/liboscar/tests/connectiontest.cpp | 4 +- .../protocols/oscar/liboscar/tests/logintest.cpp | 12 +- kopete/protocols/oscar/liboscar/tests/logintest.h | 2 - kopete/protocols/oscar/oscaraccount.cpp | 12 +- kopete/protocols/oscar/oscaraccount.h | 4 +- 25 files changed, 246 insertions(+), 1314 deletions(-) delete mode 100644 kopete/protocols/oscar/liboscar/bytestream.cpp delete mode 100644 kopete/protocols/oscar/liboscar/bytestream.h delete mode 100644 kopete/protocols/oscar/liboscar/connector.cpp delete mode 100644 kopete/protocols/oscar/liboscar/connector.h delete mode 100644 kopete/protocols/oscar/liboscar/oscarbytestream.cpp delete mode 100644 kopete/protocols/oscar/liboscar/oscarbytestream.h rewrite kopete/protocols/oscar/liboscar/oscarclientstream.h (62%) delete mode 100644 kopete/protocols/oscar/liboscar/oscarconnector.cpp delete mode 100644 kopete/protocols/oscar/liboscar/oscarconnector.h diff --git a/kopete/protocols/oscar/aim/aimaccount.cpp b/kopete/protocols/oscar/aim/aimaccount.cpp index 3b0d7baeb..3071c4eb5 100644 --- a/kopete/protocols/oscar/aim/aimaccount.cpp +++ b/kopete/protocols/oscar/aim/aimaccount.cpp @@ -647,7 +647,6 @@ void AIMAccount::connectWithPassword( const QString &password ) QString screenName = accountId(); QString server = configGroup()->readEntry( "Server", QString::fromLatin1( "login.oscar.aol.com" ) ); uint port = configGroup()->readEntry( "Port", 5190 ); - Connection* c = setupConnection( server, port ); //set up the settings for the account Oscar::Settings* oscarSettings = engine()->clientSettings(); @@ -659,8 +658,10 @@ void AIMAccount::connectWithPassword( const QString &password ) Oscar::DWORD status = protocol()->statusManager()->oscarStatusOf( pres ); engine()->setStatus( status, mInitialStatusMessage ); updateVersionUpdaterStamp(); + + Connection* c = setupConnection(); engine()->start( server, port, accountId(), password.left(16) ); - engine()->connectToServer( c, server, true /* doAuth */ ); + engine()->connectToServer( c, server, port, true /* doAuth */ ); mInitialStatusMessage.clear(); } diff --git a/kopete/protocols/oscar/icq/icqaccount.cpp b/kopete/protocols/oscar/icq/icqaccount.cpp index f2c13a349..5eca48752 100644 --- a/kopete/protocols/oscar/icq/icqaccount.cpp +++ b/kopete/protocols/oscar/icq/icqaccount.cpp @@ -227,7 +227,6 @@ void ICQAccount::connectWithPassword( const QString &password ) kDebug(14153) << k_funcinfo << "Logging in as " << icqNumber << endl ; QString server = configGroup()->readEntry( "Server", QString::fromLatin1( "login.oscar.aol.com" ) ); uint port = configGroup()->readEntry( "Port", 5190 ); - Connection* c = setupConnection( server, port ); //set up the settings for the account Oscar::Settings* oscarSettings = engine()->clientSettings(); @@ -249,8 +248,10 @@ void ICQAccount::connectWithPassword( const QString &password ) engine()->setStatus( status, mInitialStatusMessage, pres.xtrazStatus(), pres.description() ); updateVersionUpdaterStamp(); + + Connection* c = setupConnection(); engine()->start( server, port, accountId(), password.left(8) ); - engine()->connectToServer( c, server, true /* doAuth */ ); + engine()->connectToServer( c, server, port, true /* doAuth */ ); mInitialStatusMessage.clear(); } diff --git a/kopete/protocols/oscar/liboscar/CMakeLists.txt b/kopete/protocols/oscar/liboscar/CMakeLists.txt index 271bc6e57..8f2b78829 100644 --- a/kopete/protocols/oscar/liboscar/CMakeLists.txt +++ b/kopete/protocols/oscar/liboscar/CMakeLists.txt @@ -11,7 +11,6 @@ ${KOPETE_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR} set(liboscar_SRCS oscarutils.cpp client.cpp - connector.cpp inputprotocolbase.cpp coreprotocol.cpp flapprotocol.cpp @@ -19,12 +18,9 @@ set(liboscar_SRCS oftprotocol.cpp ofttransfer.cpp transfer.cpp - bytestream.cpp oscarclientstream.cpp safedelete.cpp stream.cpp - oscarconnector.cpp - oscarbytestream.cpp buffer.cpp rateclassmanager.cpp contactmanager.cpp diff --git a/kopete/protocols/oscar/liboscar/bytestream.cpp b/kopete/protocols/oscar/liboscar/bytestream.cpp deleted file mode 100644 index af011261e..000000000 --- a/kopete/protocols/oscar/liboscar/bytestream.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* - * bytestream.cpp - base class for bytestreams - * Copyright (C) 2003 Justin Karneges - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include"bytestream.h" - -#include - -// CS_NAMESPACE_BEGIN - -//! \class ByteStream bytestream.h -//! \brief Base class for "bytestreams" -//! -//! This class provides a basic framework for a "bytestream", here defined -//! as a bi-directional, asynchronous pipe of data. It can be used to create -//! several different kinds of bytestream-applications, such as a console or -//! TCP connection, or something more abstract like a security layer or tunnel, -//! all with the same interface. The provided functions make creating such -//! classes simpler. ByteStream is a pure-virtual class, so you do not use it -//! on its own, but instead through a subclass such as \a BSocket. -//! -//! The signals connectionClosed(), delayedCloseFinished(), readyRead(), -//! bytesWritten(), and error() serve the exact same function as those from -//! QSocket. -//! -//! The simplest way to create a ByteStream is to reimplement isOpen(), close(), -//! and tryWrite(). Call appendRead() whenever you want to make data available for -//! reading. ByteStream will take care of the buffers with regards to the caller, -//! and will call tryWrite() when the write buffer gains data. It will be your -//! job to call tryWrite() whenever it is acceptable to write more data to -//! the underlying system. -//! -//! If you need more advanced control, reimplement read(), write(), bytesAvailable(), -//! and/or bytesToWrite() as necessary. -//! -//! Use appendRead(), appendWrite(), takeRead(), and takeWrite() to modify the -//! buffers. If you have more advanced requirements, the buffers can be accessed -//! directly with readBuf() and writeBuf(). -//! -//! Also available are the static convenience functions ByteStream::appendArray() -//! and ByteStream::takeArray(), which make dealing with byte queues very easy. - -class ByteStream::Private -{ -public: - Private() {} - - QByteArray readBuf, writeBuf; -}; - -//! -//! Constructs a ByteStream object with parent \a parent. -ByteStream::ByteStream(QObject *parent) -:QObject(parent) -{ - d = new Private; -} - -//! -//! Destroys the object and frees allocated resources. -ByteStream::~ByteStream() -{ - delete d; -} - -//! -//! Returns TRUE if the stream is open, meaning that you can write to it. -bool ByteStream::isOpen() const -{ - return false; -} - -//! -//! Closes the stream. If there is data in the write buffer then it will be -//! written before actually closing the stream. Once all data has been written, -//! the delayedCloseFinished() signal will be emitted. -//! \sa delayedCloseFinished() -void ByteStream::close() -{ -} - -//! -//! Writes array \a a to the stream. -void ByteStream::write(const QByteArray &a) -{ - if(!isOpen()) - return; - - bool doWrite = bytesToWrite() == 0 ? true: false; - appendWrite(a); - if(doWrite) - tryWrite(); -} - -//! -//! Reads bytes \a bytes of data from the stream and returns them as an array. If \a bytes is 0, then -//! \a read will return all available data. -QByteArray ByteStream::read(int bytes) -{ - return takeRead(bytes); -} - -//! -//! Returns the number of bytes available for reading. -int ByteStream::bytesAvailable() const -{ - return d->readBuf.size(); -} - -//! -//! Returns the number of bytes that are waiting to be written. -int ByteStream::bytesToWrite() const -{ - return d->writeBuf.size(); -} - -//! -//! Clears the read buffer. -void ByteStream::clearReadBuffer() -{ - d->readBuf.resize(0); -} - -//! -//! Clears the write buffer. -void ByteStream::clearWriteBuffer() -{ - d->writeBuf.resize(0); -} - -//! -//! Appends \a block to the end of the read buffer. -void ByteStream::appendRead(const QByteArray &block) -{ - appendArray(&d->readBuf, block); -} - -//! -//! Appends \a block to the end of the write buffer. -void ByteStream::appendWrite(const QByteArray &block) -{ - appendArray(&d->writeBuf, block); -} - -//! -//! Returns \a size bytes from the start of the read buffer. -//! If \a size is 0, then all available data will be returned. -//! If \a del is TRUE, then the bytes are also removed. -QByteArray ByteStream::takeRead(int size, bool del) -{ - return takeArray(&d->readBuf, size, del); -} - -//! -//! Returns \a size bytes from the start of the write buffer. -//! If \a size is 0, then all available data will be returned. -//! If \a del is TRUE, then the bytes are also removed. -QByteArray ByteStream::takeWrite(int size, bool del) -{ - return takeArray(&d->writeBuf, size, del); -} - -//! -//! Returns a reference to the read buffer. -QByteArray & ByteStream::readBuf() -{ - return d->readBuf; -} - -//! -//! Returns a reference to the write buffer. -QByteArray & ByteStream::writeBuf() -{ - return d->writeBuf; -} - -//! -//! Attempts to try and write some bytes from the write buffer, and returns the number -//! successfully written or -1 on error. The default implementation returns -1. -int ByteStream::tryWrite() -{ - return -1; -} - -//! -//! Append array \a b to the end of the array pointed to by \a a. -void ByteStream::appendArray(QByteArray *a, const QByteArray &b) -{ - int oldsize = a->size(); - a->resize(oldsize + b.size()); - memcpy(a->data() + oldsize, b.data(), b.size()); -} - -//! -//! Returns \a size bytes from the start of the array pointed to by \a from. -//! If \a size is 0, then all available data will be returned. -//! If \a del is TRUE, then the bytes are also removed. -QByteArray ByteStream::takeArray(QByteArray *from, int size, bool del) -{ - QByteArray a; - if(size == 0) { - a = *from; - if(del) - from->resize(0); - } - else { - if(size > (int)from->size()) - size = from->size(); - a.resize(size); - char *r = from->data(); - memcpy(a.data(), r, size); - if(del) { - int newsize = from->size()-size; - memmove(r, r+size, newsize); - from->resize(newsize); - } - } - return a; -} -/* - void connectionClosed(); - void delayedCloseFinished(); - void readyRead(); - void bytesWritten(int); - void error(QAbstractSocket::SocketError); - -//! \fn void ByteStream::connectionClosed() -//! This signal is emitted when the remote end of the stream closes. - -//! \fn void ByteStream::delayedCloseFinished() -//! This signal is emitted when all pending data has been written to the stream -//! after an attempt to close. - -//! \fn void ByteStream::readyRead() -//! This signal is emitted when data is available to be read. - -//! \fn void ByteStream::bytesWritten(int x); -//! This signal is emitted when data has been successfully written to the stream. -//! \a x is the number of bytes written. - -//! \fn void ByteStream::error(QAbstractSocket::SocketError code) -//! This signal is emitted when an error occurs in the stream. The reason for -//! error is indicated by \a code. -*/ -// CS_NAMESPACE_END - -#include "bytestream.moc" diff --git a/kopete/protocols/oscar/liboscar/bytestream.h b/kopete/protocols/oscar/liboscar/bytestream.h deleted file mode 100644 index e5a2b9999..000000000 --- a/kopete/protocols/oscar/liboscar/bytestream.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * bytestream.h - base class for bytestreams - * Copyright (C) 2003 Justin Karneges - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef CS_BYTESTREAM_H -#define CS_BYTESTREAM_H - -#include -#include - -// CS_NAMESPACE_BEGIN - -// CS_EXPORT_BEGIN -class ByteStream : public QObject -{ - Q_OBJECT -public: - enum Error { ErrRead, ErrWrite, ErrCustom = 10 }; - ByteStream(QObject *parent=0); - virtual ~ByteStream()=0; - - virtual bool isOpen() const; - virtual void close(); - virtual void write(const QByteArray &); - virtual QByteArray read(int bytes=0); - virtual int bytesAvailable() const; - virtual int bytesToWrite() const; - - static void appendArray(QByteArray *a, const QByteArray &b); - static QByteArray takeArray(QByteArray *from, int size=0, bool del=true); - -Q_SIGNALS: - void connectionClosed(); - void delayedCloseFinished(); - void readyRead(); - void bytesWritten(int); - void error(QAbstractSocket::SocketError); - -protected: - void clearReadBuffer(); - void clearWriteBuffer(); - void appendRead(const QByteArray &); - void appendWrite(const QByteArray &); - QByteArray takeRead(int size=0, bool del=true); - QByteArray takeWrite(int size=0, bool del=true); - QByteArray & readBuf(); - QByteArray & writeBuf(); - virtual int tryWrite(); - -private: -//! \if _hide_doc_ - class Private; - Private *d; -//! \endif -}; -// CS_EXPORT_END - -// CS_NAMESPACE_END - -#endif diff --git a/kopete/protocols/oscar/liboscar/client.cpp b/kopete/protocols/oscar/liboscar/client.cpp index 6c7dfaeb1..27b98cfed 100644 --- a/kopete/protocols/oscar/liboscar/client.cpp +++ b/kopete/protocols/oscar/liboscar/client.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include //for kDebug() #include @@ -43,7 +44,6 @@ #include "messagereceivertask.h" #include "onlinenotifiertask.h" #include "oscarclientstream.h" -#include "oscarconnector.h" #include "oscarsettings.h" #include "oscarutils.h" #include "ownuserinfotask.h" @@ -204,7 +204,7 @@ Oscar::Settings* Client::clientSettings() const return d->settings; } -void Client::connectToServer( Connection *c, const QString& server, bool auth ) +void Client::connectToServer( Connection *c, const QString& host, quint16 port, bool auth ) { d->connections.append( c ); if ( auth == true ) @@ -214,7 +214,7 @@ void Client::connectToServer( Connection *c, const QString& server, bool auth ) } connect( c, SIGNAL( socketError( int, const QString& ) ), this, SLOT( determineDisconnection( int, const QString& ) ) ); - c->connectToServer(server, auth); + c->connectToServer( host, port ); } void Client::start( const QString &host, const uint port, const QString &userId, const QString &pass ) @@ -404,7 +404,7 @@ void Client::lt_loginFinished() void Client::startStageTwo() { //create a new connection and set it up - Connection* c = createConnection( d->host, QString::number( d->port ) ); + Connection* c = createConnection(); new CloseConnectionTask( c->rootTask() ); //create the new login task @@ -415,7 +415,7 @@ void Client::startStageTwo() //connect QObject::connect( c, SIGNAL( connected() ), this, SLOT( streamConnected() ) ); - connectToServer( c, d->host, false ) ; + connectToServer( c, d->host, d->port, false ) ; } @@ -1358,14 +1358,14 @@ void Client::haveServerForRedirect( const QString& host, const QByteArray& cooki realPort = QString::fromLatin1("5190"); } - Connection* c = createConnection( realHost, realPort ); + Connection* c = createConnection(); //create the new login task m_loginTaskTwo = new StageTwoLoginTask( c->rootTask() ); m_loginTaskTwo->setCookie( cookie ); QObject::connect( m_loginTaskTwo, SIGNAL( finished() ), this, SLOT( serverRedirectFinished() ) ); //connect - connectToServer( c, d->host, false ); + connectToServer( c, realHost, realPort.toInt(), false ); QObject::connect( c, SIGNAL( connected() ), this, SLOT( streamConnected() ) ); if ( srt ) @@ -1523,13 +1523,11 @@ void Client::disconnectChatRoom( Oscar::WORD exchange, const QString& room ) c = 0; } -Connection* Client::createConnection( const QString& host, const QString& port ) +Connection* Client::createConnection() { - KNetworkConnector* knc = new KNetworkConnector( 0 ); - knc->setOptHostPort( host, port.toUInt() ); - ClientStream* cs = new ClientStream( knc, 0 ); + ClientStream* cs = new ClientStream( new QTcpSocket(), 0 ); cs->setNoopTime( 60000 ); - Connection* c = new Connection( knc, cs, "BOS" ); + Connection* c = new Connection( cs, "BOS" ); cs->setConnection( c ); c->setClient( this ); return c; diff --git a/kopete/protocols/oscar/liboscar/client.h b/kopete/protocols/oscar/liboscar/client.h index 4edc4cb4d..10c0441cc 100644 --- a/kopete/protocols/oscar/liboscar/client.h +++ b/kopete/protocols/oscar/liboscar/client.h @@ -106,15 +106,17 @@ public: * Start a connection to the server using the supplied @ref ClientStream. * This is only a transport layer connection. * @param s initialised connection object to use for the connection. - * @param server the server to connect to - but this is also set on the connector used to construct the clientstream?? + * @param host the host name of server to connect to + * @param port the port of server to connect to * @param auth indicate whether we're connecting to the authorizer or the bos server */ - void connectToServer( Connection *c, const QString& server, bool auth = true ); + void connectToServer( Connection *c, const QString& host, quint16 port, bool auth = true ); /** * Start the login process for Oscar - * @param host - probably could obtain this back from the connector - used for outgoing tasks to determine destination + * @param host Used for outgoing tasks to determine destination * @param user The user name to log in as. + * @param port The port of server to connect to * @param pass The password to use when logging in */ void start( const QString &host, const uint port, const QString &userId, const QString &pass ); @@ -567,7 +569,7 @@ private: /** Delete the static tasks */ void deleteStaticTasks(); - Connection* createConnection( const QString& host, const QString& port ); + Connection* createConnection(); /** * Request the icq away message diff --git a/kopete/protocols/oscar/liboscar/connection.cpp b/kopete/protocols/oscar/liboscar/connection.cpp index adda93dea..177c2d4d0 100644 --- a/kopete/protocols/oscar/liboscar/connection.cpp +++ b/kopete/protocols/oscar/liboscar/connection.cpp @@ -21,7 +21,6 @@ #include "connection.h" #include "client.h" -#include "connector.h" #include "oscarclientstream.h" #include "rateclassmanager.h" #include "task.h" @@ -43,7 +42,6 @@ public: RateClassManager* rateClassManager; ClientStream* clientStream; - Connector* connector; Client* client; Task* root; @@ -51,14 +49,13 @@ public: -Connection::Connection( Connector* connector, ClientStream* cs, const char* name ) +Connection::Connection( ClientStream* cs, const char* name ) : QObject( 0 ) { setObjectName( QLatin1String(name) ); d = new ConnectionPrivate(); d->clientStream = cs; d->client = 0; - d->connector = connector; d->rateClassManager = new RateClassManager( this ); d->root = new Task( this, true /* isRoot */ ); m_loggedIn = false; @@ -70,7 +67,6 @@ Connection::~Connection() { delete d->rateClassManager; delete d->clientStream; - delete d->connector; delete d; } @@ -80,12 +76,12 @@ void Connection::setClient( Client* c ) connect( c, SIGNAL( loggedIn() ), this, SLOT( loggedIn() ) ); } -void Connection::connectToServer( const QString& host, bool auth ) +void Connection::connectToServer( const QString& host, quint16 port ) { connect( d->clientStream, SIGNAL( error( int ) ), this, SLOT( streamSocketError( int ) ) ); connect( d->clientStream, SIGNAL( readyRead() ), this, SLOT( streamReadyRead() ) ); connect( d->clientStream, SIGNAL( connected() ), this, SIGNAL( connected() ) ); - d->clientStream->connectToServer( host, auth ); + d->clientStream->connectToServer( host, port ); } void Connection::close() @@ -241,7 +237,7 @@ void Connection::loggedIn() void Connection::streamSocketError( int code ) { - emit socketError( code, d->clientStream->errorText() ); + emit socketError( code, d->clientStream->errorString() ); } #include "connection.moc" diff --git a/kopete/protocols/oscar/liboscar/connection.h b/kopete/protocols/oscar/liboscar/connection.h index 0947da7a7..11343e556 100644 --- a/kopete/protocols/oscar/liboscar/connection.h +++ b/kopete/protocols/oscar/liboscar/connection.h @@ -27,8 +27,6 @@ Kopete (c) 2002-2005 by the Kopete developers class ConnectionPrivate; class Client; class ClientStream; -class Connector; -class ByteStream; class Transfer; class RateClassManager; class ContactManager; @@ -51,12 +49,12 @@ class LIBOSCAR_EXPORT Connection : public QObject Q_OBJECT public: - Connection( Connector* connector, ClientStream* cs, const char* name = 0 ); + Connection( ClientStream* cs, const char* name = 0 ); ~Connection(); void setClient( Client* ); - void connectToServer( const QString& server, bool auth = true ); + void connectToServer( const QString& host, quint16 port ); /** * Close the connection and reset the connection data */ @@ -152,12 +150,6 @@ public: /** Convenience function to get the root task for use in Tasks */ Task* rootTask() const; - /** Get the raw connector for this connection, in case we need it */ - Connector* connector(); - - /** Get the byte stream for this connection, in case we need it */ - ByteStream* byteStream(); - void send( Transfer* t ) const; void forcedSend( Transfer* t ) const; diff --git a/kopete/protocols/oscar/liboscar/connector.cpp b/kopete/protocols/oscar/liboscar/connector.cpp deleted file mode 100644 index 846d14d64..000000000 --- a/kopete/protocols/oscar/liboscar/connector.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - Kopete Oscar Protocol - connector.cpp - the Oscar socket connector - - Copyright (c) 2004 Matt Rogers - - Based on Iris, Copyright (C) 2003 Justin Karneges - - Kopete (c) 2002-2004 by the Kopete developers - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include "connector.h" - -Connector::Connector(QObject *parent) -:QObject(parent) -{ - setPeerAddressNone(); -} - -Connector::~Connector() -{ -} - -bool Connector::havePeerAddress() const -{ - return haveaddr; -} - -QHostAddress Connector::peerAddress() const -{ - return addr; -} - -quint16 Connector::peerPort() const -{ - return port; -} - -void Connector::setPeerAddressNone() -{ - haveaddr = false; - addr = QHostAddress(); - port = 0; -} - -void Connector::setPeerAddress(const QHostAddress &_addr, quint16 _port) -{ - haveaddr = true; - addr = _addr; - port = _port; -} - -#include "connector.moc" diff --git a/kopete/protocols/oscar/liboscar/connector.h b/kopete/protocols/oscar/liboscar/connector.h deleted file mode 100644 index b238c1b48..000000000 --- a/kopete/protocols/oscar/liboscar/connector.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - Kopete Oscar Protocol - connector.h - the Oscar socket connector - - Copyright (c) 2004 Matt Rogers - Based on code Copyright (c) 2004 SuSE Linux AG - Based on Iris, Copyright (C) 2003 Justin Karneges - - Kopete (c) 2002-2004 by the Kopete developers - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef LIBOSCAR_CONNECTOR_H -#define LIBOSCAR_CONNECTOR_H - - -#include -#include "qhostaddress.h" - -class ByteStream; - -class Connector : public QObject -{ - Q_OBJECT -public: - Connector(QObject *parent=0); - virtual ~Connector(); - - virtual void connectToServer(const QString &server)=0; - virtual ByteStream *stream() const=0; - virtual void done()=0; - - bool havePeerAddress() const; - QHostAddress peerAddress() const; - quint16 peerPort() const; - -signals: - void connected(); - void error(); - -protected: - void setPeerAddressNone(); - void setPeerAddress(const QHostAddress &addr, quint16 port); - -private: - bool haveaddr; - QHostAddress addr; - quint16 port; -}; - -#endif diff --git a/kopete/protocols/oscar/liboscar/coreprotocol.cpp b/kopete/protocols/oscar/liboscar/coreprotocol.cpp index 5057f41c2..05ac7a536 100644 --- a/kopete/protocols/oscar/liboscar/coreprotocol.cpp +++ b/kopete/protocols/oscar/liboscar/coreprotocol.cpp @@ -98,9 +98,7 @@ void CoreProtocol::addIncomingData( const QByteArray & incomingBytes ) { kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Received " << incomingBytes.count() << " bytes. " << endl; // store locally - int oldsize = m_in.size(); - m_in.resize( oldsize + incomingBytes.size() ); - memcpy( m_in.data() + oldsize, incomingBytes.data(), incomingBytes.size() ); + m_in.append( incomingBytes ); m_state = Available; // convert every event in the chunk to a Transfer, signalling it back to the clientstream @@ -241,7 +239,7 @@ int CoreProtocol::wireToTransfer( const QByteArray& wire ) void CoreProtocol::reset() { - m_in.resize( 0 ); + m_in.clear(); } void CoreProtocol::slotOutgoingData( const QByteArray &out ) diff --git a/kopete/protocols/oscar/liboscar/oscarbytestream.cpp b/kopete/protocols/oscar/liboscar/oscarbytestream.cpp deleted file mode 100644 index 9ea8d5ad7..000000000 --- a/kopete/protocols/oscar/liboscar/oscarbytestream.cpp +++ /dev/null @@ -1,149 +0,0 @@ - -/*************************************************************************** - gwbytestream.cpp - Byte Stream using KNetwork sockets - ------------------- - begin : Wed Jul 7 2004 - copyright : (C) 2004 by Till Gerken - - Kopete (C) 2004 Kopete developers - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#include "oscarbytestream.h" - -#include -#include - -#include -#include - -KNetworkByteStream::KNetworkByteStream( QObject *parent ) - : ByteStream ( parent ) -{ - kDebug( 14151 ) << k_funcinfo << "Instantiating new KNetwork byte stream." << endl; - - // reset close tracking flag - mClosing = false; - - mSocket = 0; -} - -bool KNetworkByteStream::connect( QString host, unsigned short port ) -{ - kDebug( 14151 ) << k_funcinfo << "Connecting to " << host << ", port " << port << endl; - - if( mSocket ) - delete mSocket; - - mSocket = KSocketFactory::connectToHost( QLatin1String( "tcp" ), host, port, this ); - - // connect signals and slots - QObject::connect( mSocket, SIGNAL ( error ( QAbstractSocket::SocketError ) ), this, SLOT ( slotError ( QAbstractSocket::SocketError ) ) ); - QObject::connect( mSocket, SIGNAL ( connected () ), this, SLOT ( slotConnected () ) ); - QObject::connect( mSocket, SIGNAL ( disconnected () ), this, SLOT ( slotDisconnected () ) ); - QObject::connect( mSocket, SIGNAL ( readyRead () ), this, SLOT ( slotReadyRead () ) ); - QObject::connect( mSocket, SIGNAL ( bytesWritten ( qint64 ) ), this, SLOT ( slotBytesWritten ( qint64 ) ) ); - - return true; -} - -bool KNetworkByteStream::isOpen() const -{ - // determine if socket is open - return mSocket && mSocket->isOpen(); -} - -void KNetworkByteStream::close () -{ -#ifdef OSCAR_EXCEContactVE_DEBUG - kDebug ( 14151 ) << k_funcinfo << "Closing stream." << endl; -#endif - // close the socket and set flag that we are closing it ourselves - mClosing = true; - if( mSocket ) - mSocket->close(); -} - -int KNetworkByteStream::tryWrite () -{ - // send all data from the buffers to the socket - QByteArray writeData = takeWrite(); -#ifdef OSCAR_EXCEContactVE_DEBUG - kDebug(14151) << k_funcinfo << "writing " << writeData.size() << " bytes." << endl; -#endif - if( !mSocket ) - return false; - - mSocket->write( writeData.data (), writeData.size () ); - return writeData.size(); -} - -QTcpSocket *KNetworkByteStream::socket() const -{ - return mSocket; -} - -KNetworkByteStream::~KNetworkByteStream() -{ - // If socket is open than it has data in buffer, so delete socket later - if ( mSocket->isOpen() ) - QObject::connect( mSocket, SIGNAL(closed()), mSocket, SLOT(deleteLater()) ); - else - delete mSocket; -} - -void KNetworkByteStream::slotConnected() -{ - emit connected(); -} - -void KNetworkByteStream::slotDisconnected() -{ - kDebug( 14151 ) << k_funcinfo << "Socket has been closed." << endl; - - // depending on who closed the socket, emit different signals - if ( mClosing ) - { - kDebug( 14151 ) << "..by ourselves!" << endl; - kDebug( 14151 ) << "socket error is " << mSocket->errorString() << endl; - emit connectionClosed (); - } - else - { - kDebug( 14151 ) << "..by the other end" << endl; - emit delayedCloseFinished (); - } -} - -void KNetworkByteStream::slotReadyRead() -{ - // stuff all available data into our buffers - QByteArray readBuffer = mSocket->readAll(); - - appendRead( readBuffer ); - - emit readyRead(); -} - -void KNetworkByteStream::slotBytesWritten( qint64 bytes ) -{ - emit bytesWritten( bytes ); -} -void KNetworkByteStream::slotError( QAbstractSocket::SocketError code ) -{ - kDebug( 14151 ) << k_funcinfo << "Socket error " << (int)code << endl; - - emit error ( code ); -} - -#include "oscarbytestream.moc" - -// kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off; diff --git a/kopete/protocols/oscar/liboscar/oscarbytestream.h b/kopete/protocols/oscar/liboscar/oscarbytestream.h deleted file mode 100644 index 0dfa69689..000000000 --- a/kopete/protocols/oscar/liboscar/oscarbytestream.h +++ /dev/null @@ -1,72 +0,0 @@ - -/*************************************************************************** - gwbytestream.h - Byte Stream using KNetwork sockets - adapted from jabberbytestream.h - ------------------- - begin : Wed Jul 7 2004 - copyright : (C) 2004 by Till Gerken - - Kopete (C) 2004 Kopete developers - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef KNETWORKBYTESTREAM_H -#define KNETWORKBYTESTREAM_H - -#include "ksocketfactory.h" -#include "bytestream.h" - - -/** - * Low level socket class, using KDE's KNetwork socket classes - * @author Till Gerken - */ - -class KNetworkByteStream : public ByteStream -{ - -Q_OBJECT - -public: - KNetworkByteStream ( QObject *parent = 0 ); - - ~KNetworkByteStream (); - - bool connect ( QString host, unsigned short port ); - virtual bool isOpen () const; - virtual void close (); - - // can be NULL ! - QTcpSocket *socket () const; - -Q_SIGNALS: - void connected (); - -protected: - virtual int tryWrite (); - -private Q_SLOTS: - void slotConnected (); - void slotDisconnected (); - void slotReadyRead (); - void slotBytesWritten ( qint64 ); - void slotError ( QAbstractSocket::SocketError ); - -private: - class QTcpSocket *mSocket; - bool mClosing; - -}; - -#endif - -// kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off; - diff --git a/kopete/protocols/oscar/liboscar/oscarclientstream.cpp b/kopete/protocols/oscar/liboscar/oscarclientstream.cpp index ec907734f..ca3ca7e93 100644 --- a/kopete/protocols/oscar/liboscar/oscarclientstream.cpp +++ b/kopete/protocols/oscar/liboscar/oscarclientstream.cpp @@ -2,11 +2,12 @@ oscarclientstream.cpp - Kopete Oscar Protocol Copyright (c) 2004 Matt Rogers + Copyright (c) 2007 Roman Jarosz Based on code Copyright (c) 2004 SuSE Linux AG Based on Iris, Copyright (C) 2003 Justin Karneges - Kopete (c) 2002-2004 by the Kopete developers + Kopete (c) 2002-2007 by the Kopete developers ************************************************************************* * * @@ -20,101 +21,62 @@ #include "oscarclientstream.h" -#include -#include -#include -#include -//Added by qt3to4: -#include +#include +#include #include -#include "bytestream.h" #include "connection.h" -#include "connector.h" #include "coreprotocol.h" -#include "rateclassmanager.h" #include "transfer.h" #define LIBOSCAR_DEBUG 0 void cs_dump( const QByteArray &bytes ); -enum { - Idle, - Connecting, - Active, - Closing -}; - -enum { - ClientMode, - ServerMode -}; - class ClientStream::Private { public: Private() { - conn = 0; - bs = 0; + socket = 0; connection = 0; - - haveLocalAddr = false; - doBinding = true; - - reset(); - } - void reset() - { - state = Idle; - notify = 0; newTransfers = false; } - - QString username; - QString password; - QString server; - bool doAuth; //send the initial login sequences to get the cookie - bool haveLocalAddr; - QHostAddress localAddr; - quint16 localPort; - bool doBinding; - - Connector *conn; - ByteStream *bs; + + QString host; + quint16 port; + + QAbstractSocket *socket; CoreProtocol client; Connection* connection; - QString defRealm; - - int mode; - int state; - int notify; bool newTransfers; - - int errCond; - QString errText; - QQueue in; + QQueue in; QTimer noopTimer; // used to send icq keepalive int noop_time; }; -ClientStream::ClientStream(Connector *conn, QObject *parent) -:Stream(parent) +ClientStream::ClientStream( QAbstractSocket *socket, QObject *parent ) +: Stream( parent ) { - //qDebug("CLIENTSTREAM::ClientStream"); - d = new Private; - d->mode = ClientMode; - d->conn = conn; - connect( d->conn, SIGNAL(connected()), SLOT(cr_connected()) ); - connect( d->conn, SIGNAL(error()), SLOT(cr_error()) ); - connect( &d->client, SIGNAL( outgoingData( const QByteArray& ) ), SLOT ( cp_outgoingData( const QByteArray & ) ) ); - connect( &d->client, SIGNAL( incomingData() ), SLOT ( cp_incomingData() ) ); + d->socket = socket; + + connect( d->socket, SIGNAL(connected()), SLOT(socketConnected()) ); + connect( d->socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError)) ); + + connect(d->socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); + connect(d->socket, SIGNAL(readyRead()), SLOT(socketReadyRead())); + connect(d->socket, SIGNAL(bytesWritten(qint64)), SLOT(socketBytesWritten(qint64))); + + + connect( &d->client, SIGNAL(outgoingData(const QByteArray&)), + SLOT (cp_outgoingData(const QByteArray & )) ); + connect( &d->client, SIGNAL(incomingData()), + SLOT (cp_incomingData()) ); d->noop_time = 0; connect(&d->noopTimer, SIGNAL(timeout()), SLOT(doNoop())); @@ -122,118 +84,85 @@ ClientStream::ClientStream(Connector *conn, QObject *parent) ClientStream::~ClientStream() { - reset(); - delete d; -} - -void ClientStream::reset(bool all) -{ - d->reset(); d->noopTimer.stop(); - // client - if(d->mode == ClientMode) + if ( d->socket->isOpen() ) { - // reset connector - if ( d->bs ) + kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Socket open, disconnecting..." << endl; + d->socket->disconnectFromHost(); + + if ( !d->socket->waitForDisconnected( 10000 ) ) { - d->bs->close(); - if ( d->bs ) - { - disconnect( d->bs, 0, this, 0 ); - d->bs = 0; - } + kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Disconnection error!" << endl; + d->socket->close(); } - if ( d->conn ) - d->conn->done(); - - // reset state machine - d->client.reset(); } - if(all) - d->in.clear(); -} - -void ClientStream::connectToServer(const QString& server, bool auth) -{ - reset(true); - d->state = Connecting; - d->doAuth = auth; - d->server = server; - d->conn->connectToServer( d->server ); + delete d->socket; + delete d; } -void ClientStream::continueAfterWarning() +void ClientStream::connectToServer( const QString& host, quint16 port ) { -/* unneeded? - if(d->state == WaitVersion) { - d->state = Connecting; - processNext(); - } - else if(d->state == WaitTLS) { - d->state = Connecting; - processNext(); + d->noopTimer.stop(); + if ( d->socket->isOpen() ) + { + kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Socket open, disconnecting..." << endl; + d->socket->disconnectFromHost(); + + if ( !d->socket->waitForDisconnected( 10000 ) ) + { + kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Disconnection error!" << endl; + d->socket->close(); + } } -*/ -} - -void ClientStream::accept() -{ + d->client.reset(); + d->in.clear(); + d->newTransfers = false; + + d->host = host; + d->port = port; + d->socket->connectToHost( d->host, d->port ); } -bool ClientStream::isActive() const +bool ClientStream::isOpen() const { - return (d->state != Idle); + return d->socket->isOpen(); } -bool ClientStream::isAuthenticated() const -{ - return (d->state == Active); -} - -void ClientStream::setNoopTime(int mills) +void ClientStream::setNoopTime( int mills ) { d->noop_time = mills; - if(d->noop_time == 0) { + if( d->noop_time == 0 ) + { d->noopTimer.stop(); return; } - if( d->state != Active ) + if( !d->socket->isOpen() ) return; d->noopTimer.start( d->noop_time ); } -void ClientStream::setLocalAddr(const QHostAddress &addr, quint16 port) +int ClientStream::error() const { - d->haveLocalAddr = true; - d->localAddr = addr; - d->localPort = port; + return d->socket->error(); } -int ClientStream::errorCondition() const +QString ClientStream::errorString() const { - return d->errCond; -} - -QString ClientStream::errorText() const -{ - return d->errText; + return d->socket->errorString(); } void ClientStream::close() { - if(d->state == Active) { - d->state = Closing; -// d->client.shutdown(); + if( d->socket->isOpen() ) + { processNext(); - } - else if(d->state != Idle && d->state != Closing) { - reset(); + d->socket->disconnectFromHost(); } } @@ -247,7 +176,6 @@ Connection* ClientStream::connection() const return d->connection; } - bool ClientStream::transfersAvailable() const { return ( !d->in.isEmpty() ); @@ -255,7 +183,7 @@ bool ClientStream::transfersAvailable() const Transfer* ClientStream::read() { - if(d->in.isEmpty()) + if( d->in.isEmpty() ) return 0; //first from queue... else return d->in.dequeue(); @@ -311,8 +239,7 @@ void cs_dump( const QByteArray &bytes ) void ClientStream::cp_outgoingData( const QByteArray& outgoingBytes ) { // take formatted bytes from CoreProtocol and put them on the wire - if ( d->bs ) - d->bs->write( outgoingBytes ); + d->socket->write( outgoingBytes ); } void ClientStream::cp_incomingData() @@ -330,67 +257,51 @@ void ClientStream::cp_incomingData() d->client.state() << endl; } -void ClientStream::cr_connected() + +void ClientStream::socketConnected() { - d->bs = d->conn->stream(); - connect(d->bs, SIGNAL(connectionClosed()), SLOT(bs_connectionClosed())); - connect(d->bs, SIGNAL(delayedCloseFinished()), SLOT(bs_delayedCloseFinished())); - connect(d->bs, SIGNAL(readyRead()), SLOT(bs_readyRead())); - connect(d->bs, SIGNAL(bytesWritten(int)), SLOT(bs_bytesWritten(int))); - connect(d->bs, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(bs_error(QAbstractSocket::SocketError))); - - d->state = Active; + kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << endl; + if ( d->noop_time ) d->noopTimer.start( d->noop_time ); - QByteArray spare = d->bs->read(); - - QPointer self = this; emit connected(); - if(!self) - return; } -void ClientStream::cr_error() +void ClientStream::socketDisconnected() { kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << endl; - reset(); - emit error(ErrConnection); -} -void ClientStream::bs_connectionClosed() -{ - reset(); - emit connectionClosed(); + d->noopTimer.stop(); + d->client.reset(); + emit disconnected(); } -void ClientStream::bs_delayedCloseFinished() +void ClientStream::socketError( QAbstractSocket::SocketError socketError ) { - // we don't care about this (we track all important data ourself) -} + kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << " error: " << socketError << endl; -void ClientStream::bs_error(QAbstractSocket::SocketError) -{ - // TODO + d->noopTimer.stop(); + d->socket->close(); + d->client.reset(); + + emit Stream::error( socketError ); } -void ClientStream::bs_readyRead() +void ClientStream::socketReadyRead() { - QByteArray a; - //qDebug( "size of storage for incoming data is %i bytes.", a.size() ); - if ( d->bs ) - a = d->bs->read(); + QByteArray buffer = d->socket->readAll(); #if LIBOSCAR_DEBUG - QByteArray cs(a.data(), a.size()+1); - kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "recv: " << a.size() << "bytes" << endl; - cs_dump( a ); + QByteArray cs(buffer.data(), buffer.size()+1); + kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "recv: " << buffer.size() << "bytes" << endl; + cs_dump( buffer ); #endif - d->client.addIncomingData(a); + d->client.addIncomingData( buffer ); } -void ClientStream::bs_bytesWritten(int bytes) +void ClientStream::socketBytesWritten( qint64 bytes ) { #if LIBOSCAR_DEBUG kDebug(OSCAR_RAW_DEBUG) << k_funcinfo << bytes << " bytes written" << endl; @@ -400,10 +311,6 @@ void ClientStream::bs_bytesWritten(int bytes) #endif } -void ClientStream::srvProcessNext() -{ -} - void ClientStream::doReadyRead() { emit readyRead(); @@ -417,14 +324,9 @@ void ClientStream::processNext() } } -bool ClientStream::handleNeed() -{ - return false; -} - void ClientStream::doNoop() { - if ( d->state != Active ) + if ( !d->socket->isOpen() ) return; FLAP f = { 0x05, d->connection->flapSequence(), 0 }; @@ -433,10 +335,6 @@ void ClientStream::doNoop() write( t ); } -void ClientStream::handleError() -{ -} - #include "oscarclientstream.moc" //kate: tab-width 4; indent-mode csands; diff --git a/kopete/protocols/oscar/liboscar/oscarclientstream.h b/kopete/protocols/oscar/liboscar/oscarclientstream.h dissimilarity index 62% index 99ff1e4d1..9cb1a1b2f 100644 --- a/kopete/protocols/oscar/liboscar/oscarclientstream.h +++ b/kopete/protocols/oscar/liboscar/oscarclientstream.h @@ -1,167 +1,98 @@ -/* - oscarclientstream.h - Kopete Oscar Protocol - - Copyright (c) 2004 Matt Rogers - - Based on code Copyright (c) 2004 SuSE Linux AG - Based on Iris, Copyright (C) 2003 Justin Karneges - - Kopete (c) 2002-2004 by the Kopete developers - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef OSCAR_CLIENTSTREAM_H -#define OSCAR_CLIENTSTREAM_H - -#include "stream.h" -#include "liboscar_export.h" - -#include - -// forward defines -class ByteStream; -class Client; -class Connector; -class Connection; -class Transfer; -class QHostAddress; - -class LIBOSCAR_EXPORT ClientStream : public Stream -{ - Q_OBJECT -public: - enum Error { - ErrConnection = ErrCustom, // Connection error, ask Connector-subclass what's up - ErrNeg, // Negotiation error, see condition - ErrAuth, // Auth error, see condition - ErrBind // Resource binding error - }; - - enum Warning { - WarnOldVersion, // server uses older XMPP/Jabber "0.9" protocol // can be customized for novell versions - WarnNoTLS // there is no chance for TLS at this point - }; - - enum NegCond { - HostGone, // host no longer hosted - HostUnknown, // unknown host - RemoteConnectionFailed, // unable to connect to a required remote resource - SeeOtherHost, // a 'redirect', see errorText() for other host - UnsupportedVersion // unsupported XMPP version - }; - - enum AuthCond { - GenericAuthError, // all-purpose "can't login" error - NoMech, // No appropriate auth mech available - BadProto, // Bad SASL auth protocol - BadServ, // Server failed mutual auth - InvalidUserId, // bad user id - InvalidMech, // bad mechanism - InvalidRealm, // bad realm - MechTooWeak, // can't use mech with this authzid - NotAuthorized, // bad user, bad password, bad creditials - TemporaryAuthFailure // please try again later! - }; - - enum BindCond { - BindNotAllowed, // not allowed to bind a resource - BindConflict // resource in-use - }; - - explicit ClientStream(Connector *conn, QObject *parent=0); - ~ClientStream(); - - void connectToServer(const QString& server, bool auth=true); - void accept(); // server - bool isActive() const; - bool isAuthenticated() const; - - // login params - void setUsername(const QString &s); - void setPassword(const QString &s); - - void setLocalAddr(const QHostAddress &addr, quint16 port); - - void close(); - - /** Connection related stuff */ - void setConnection( Connection* c ); - Connection* connection() const; - - - /** - * Are there any messages waiting to be read - */ - bool transfersAvailable() const; - - /** - * Read a message received from the server - */ - Transfer * read(); - - /** - * Send a message to the server - */ - void write( Transfer* request ); - - int errorCondition() const; - QString errorText() const; - - // extrahttp://bugs.kde.org/show_bug.cgi?id=85158 -/*# void writeDirect(const QString &s); // must be for debug testing*/ - void setNoopTime(int mills); - -Q_SIGNALS: - void connected(); - void securityLayerActivated(int); - void authenticated(); // this signal is ordinarily emitted in processNext - void warning(int); -public Q_SLOTS: - void continueAfterWarning(); - -private Q_SLOTS: - void cr_connected(); - void cr_error(); - /** - * collects wire ready outgoing data from the core protocol and sends - */ - void cp_outgoingData( const QByteArray& ); - /** - * collects parsed incoming data as a transfer from the core protocol and queues - */ - void cp_incomingData(); - - void bs_connectionClosed(); - void bs_delayedCloseFinished(); - void bs_error(QAbstractSocket::SocketError); // server only - void bs_readyRead(); - void bs_bytesWritten(int); - - void doNoop(); - void doReadyRead(); - -private: - class Private; - Private *d; - - void reset(bool all=false); - void processNext(); - bool handleNeed(); - void handleError(); - void srvProcessNext(); - - /** - * convert internal method representation to wire - */ - static char* encode_method(quint8 method); -}; - -#endif +/* + oscarclientstream.h - Kopete Oscar Protocol + + Copyright (c) 2004 Matt Rogers + Copyright (c) 2007 Roman Jarosz + + Based on code Copyright (c) 2004 SuSE Linux AG + Based on Iris, Copyright (C) 2003 Justin Karneges + + Kopete (c) 2002-2007 by the Kopete developers + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef OSCARCLIENTSTREAM_H +#define OSCARCLIENTSTREAM_H + +#include "stream.h" +#include "liboscar_export.h" + +#include + +class Connection; + +class LIBOSCAR_EXPORT ClientStream : public Stream +{ + Q_OBJECT +public: + explicit ClientStream( QAbstractSocket *socket, QObject *parent = 0 ); + ~ClientStream(); + + void connectToServer( const QString& host, quint16 port ); + + bool isOpen() const; + + void close(); + + /** Connection related stuff */ + void setConnection( Connection* c ); + Connection* connection() const; + + /** + * Are there any messages waiting to be read + */ + bool transfersAvailable() const; + + /** + * Read a message received from the server + */ + Transfer * read(); + + /** + * Send a message to the server + */ + void write( Transfer* request ); + + int error() const; + QString errorString() const; + + void setNoopTime( int mills ); + +Q_SIGNALS: + void connected(); + +private Q_SLOTS: + /** + * collects wire ready outgoing data from the core protocol and sends + */ + void cp_outgoingData( const QByteArray& ); + /** + * collects parsed incoming data as a transfer from the core protocol and queues + */ + void cp_incomingData(); + + void socketConnected(); + void socketDisconnected(); + void socketError( QAbstractSocket::SocketError ); + void socketReadyRead(); + void socketBytesWritten( qint64 ); + + void doNoop(); + void doReadyRead(); + +private: + class Private; + Private *d; + + void processNext(); +}; + +#endif diff --git a/kopete/protocols/oscar/liboscar/oscarconnector.cpp b/kopete/protocols/oscar/liboscar/oscarconnector.cpp deleted file mode 100644 index 1d94b3c57..000000000 --- a/kopete/protocols/oscar/liboscar/oscarconnector.cpp +++ /dev/null @@ -1,108 +0,0 @@ - -/*************************************************************************** - gwconnector.cpp - Socket Connector for KNetwork - ------------------- - begin : Wed Jul 7 2004 - copyright : (C) 2004 by Till Gerken - - Kopete (C) 2004 Kopete developers - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License as * - * published by the Free Software Foundation; either version 2.1 of the * - * License, or (at your option) any later version. * - * * - ***************************************************************************/ - -#include "oscarconnector.h" -#include "oscarbytestream.h" - -#include - -#include - -KNetworkConnector::KNetworkConnector( QObject *parent ) - : Connector( parent ) -{ - kDebug( 14151 ) << k_funcinfo << "New KNetwork connector." << endl; - - mErrorCode = QAbstractSocket::UnknownSocketError; // no 'NoError' here :( - - mByteStream = new KNetworkByteStream( this ); - - connect( mByteStream, SIGNAL ( connected () ), this, SLOT ( slotConnected () ) ); - connect( mByteStream, SIGNAL ( error ( QAbstractSocket::SocketError ) ), this, SLOT ( slotError ( QAbstractSocket::SocketError ) ) ); - mPort = 0; -} - -KNetworkConnector::~KNetworkConnector() -{ - delete mByteStream; -} - -void KNetworkConnector::connectToServer( const QString &server ) -{ - kDebug( 14151 ) << k_funcinfo << "Initiating connection to " << mHost << endl; - Q_ASSERT( !mHost.isEmpty() ); - Q_ASSERT( mPort ); - - mErrorCode = QAbstractSocket::UnknownSocketError; - - if ( !mByteStream->connect ( mHost, mPort ) ) - { - // Houston, we have a problem - mErrorCode = mByteStream->socket()->error(); - emit error(); - } -} - -void KNetworkConnector::slotConnected() -{ - kDebug( 14151 ) << k_funcinfo << "We are connected." << endl; - - // FIXME: setPeerAddress() is something different, find out correct usage later - //KInetSocketAddress inetAddress = mStreamSocket->address().asInet().makeIPv6 (); - //setPeerAddress ( QHostAddress ( inetAddress.ipAddress().addr () ), inetAddress.port () ); - - emit connected (); -} - -void KNetworkConnector::slotError( QAbstractSocket::SocketError code ) -{ - kDebug( 14151 ) << k_funcinfo << "Error detected: " << (int)code << endl; - - mErrorCode = code; - emit error (); -} - -QAbstractSocket::SocketError KNetworkConnector::errorCode() -{ - return mErrorCode; -} - -ByteStream *KNetworkConnector::stream() const -{ - return mByteStream; -} - -void KNetworkConnector::done() -{ - kDebug ( 14151 ) << k_funcinfo << endl; - mByteStream->close (); -} - -void KNetworkConnector::setOptHostPort( const QString &host, quint16 port ) -{ - kDebug ( 14151 ) << k_funcinfo << "Manually specifying host " << host << " and port " << port << endl; - - mHost = host; - mPort = port; - -} - -#include "oscarconnector.moc" - -// kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off; diff --git a/kopete/protocols/oscar/liboscar/oscarconnector.h b/kopete/protocols/oscar/liboscar/oscarconnector.h deleted file mode 100644 index 9361b0e34..000000000 --- a/kopete/protocols/oscar/liboscar/oscarconnector.h +++ /dev/null @@ -1,69 +0,0 @@ - -/*************************************************************************** - oscarconnector.h - Socket Connector for KNetwork - ------------------- - begin : Wed Jul 7 2004 - copyright : (C) 2004 by Till Gerken - (C) 2004 by Matt Rogers - - Kopete (C) 2004 Kopete developers - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License as * - * published by the Free Software Foundation; either version 2.1 of the * - * License, or (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef OSCARCONNECTOR_H -#define OSCARCONNECTOR_H - -#include "oscarbytestream.h" -#include "connector.h" -#include "liboscar_export.h" - -class ByteStream; -class KNetworkByteStream; -class KResolverEntry; - -/** -@author Till Gerken -@author Matt Rogers -*/ -class LIBOSCAR_EXPORT KNetworkConnector : public Connector -{ - -Q_OBJECT - -public: - KNetworkConnector( QObject *parent = 0 ); - - virtual ~KNetworkConnector(); - - virtual void connectToServer( const QString &server ); - virtual ByteStream *stream() const; - virtual void done(); - - void setOptHostPort( const QString &host, quint16 port ); - - QAbstractSocket::SocketError errorCode(); - -private slots: - void slotConnected(); - void slotError( QAbstractSocket::SocketError ); - -private: - QString mHost; - quint16 mPort; - QAbstractSocket::SocketError mErrorCode; - - KNetworkByteStream *mByteStream; - -}; - -#endif - -// kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off; diff --git a/kopete/protocols/oscar/liboscar/stream.cpp b/kopete/protocols/oscar/liboscar/stream.cpp index 029674167..770f43e42 100644 --- a/kopete/protocols/oscar/liboscar/stream.cpp +++ b/kopete/protocols/oscar/liboscar/stream.cpp @@ -19,8 +19,8 @@ #include "stream.h" -Stream::Stream(QObject *parent) -:QObject(parent) +Stream::Stream( QObject *parent ) +: QObject( parent ) { } diff --git a/kopete/protocols/oscar/liboscar/stream.h b/kopete/protocols/oscar/liboscar/stream.h index 9fbacbda5..cc8e06ef9 100644 --- a/kopete/protocols/oscar/liboscar/stream.h +++ b/kopete/protocols/oscar/liboscar/stream.h @@ -20,8 +20,8 @@ #include -#ifndef OSCAR_STREAM_H -#define OSCAR_STREAM_H +#ifndef OSCARSTREAM_H +#define OSCARSTREAM_H class Transfer; @@ -29,30 +29,18 @@ class Stream : public QObject { Q_OBJECT public: - enum Error { ErrParse, ErrProtocol, ErrStream, ErrCustom = 10 }; - enum StreamCond { - GenericStreamError, - Conflict, - ConnectionTimeout, - InternalServerError, - InvalidFrom, -/*# InvalidXml, // not required*/ - PolicyViolation, - ResourceConstraint, - SystemShutdown - }; - - Stream(QObject *parent=0); + Stream( QObject *parent = 0 ); virtual ~Stream(); - virtual void close()=0; - virtual int errorCondition() const=0; - virtual QString errorText() const=0; + virtual void close() = 0; + virtual int error() const = 0; + virtual QString errorString() const = 0; /** * Are there any messages waiting to be read */ virtual bool transfersAvailable() const = 0; // adapt to messages + /** * Read a message received from the server */ @@ -61,15 +49,12 @@ public: /** * Send a message to the server */ - virtual void write( Transfer *request) = 0; - + virtual void write( Transfer *request ) = 0; signals: - void connectionClosed(); - void delayedCloseFinished(); + void disconnected(); void readyRead(); //signals that there is a transfer ready to be read -// void stanzaWritten(); - void error(int); + void error( int ); }; #endif diff --git a/kopete/protocols/oscar/liboscar/tests/connectiontest.cpp b/kopete/protocols/oscar/liboscar/tests/connectiontest.cpp index 8bf7eac8c..c9b16a5a3 100644 --- a/kopete/protocols/oscar/liboscar/tests/connectiontest.cpp +++ b/kopete/protocols/oscar/liboscar/tests/connectiontest.cpp @@ -23,7 +23,7 @@ OSCAR_TEST_MAIN( ConnectionTest ) void ConnectionTest::checkSupportedFamiliesSingle() { - Connection* c = new Connection( 0, 0, 0 ); + Connection* c = new Connection( 0, 0 ); QVERIFY( c->supportedFamilies().isEmpty() ); c->addToSupportedFamilies( 1 ); QVERIFY( c->supportedFamilies().count() == 1 ); @@ -39,7 +39,7 @@ void ConnectionTest::checkSupportedFamiliesSingle() void ConnectionTest::checkSupportedFamiliesList() { - Connection* c = new Connection( 0, 0, 0 ); + Connection* c = new Connection( 0, 0 ); QVERIFY( c->supportedFamilies().isEmpty() ); QList families; families.append( 1 ); diff --git a/kopete/protocols/oscar/liboscar/tests/logintest.cpp b/kopete/protocols/oscar/liboscar/tests/logintest.cpp index 6dbc96462..3a1316aaf 100644 --- a/kopete/protocols/oscar/liboscar/tests/logintest.cpp +++ b/kopete/protocols/oscar/liboscar/tests/logintest.cpp @@ -1,19 +1,18 @@ //Licensed under the GNU General Public License #include "logintest.h" +#include LoginTest::LoginTest(int argc, char ** argv) : QApplication( argc, argv ) { // set up client stream - myConnector = new KNetworkConnector( 0 ); - myConnector->setOptHostPort( "login.oscar.aol.com", 5190 ); - myTestObject = new ClientStream( myConnector, myConnector); + myTestObject = new ClientStream( new QTcpSocket(), 0 ); // notify when the transport layer is connected //connect( myTestObject, SIGNAL( connected() ), SLOT( slotConnected() ) ); myClient = new Client(); - - myConnection = new Connection( myConnector, myTestObject, "AUTHORIZER" ); + + myConnection = new Connection( myTestObject, "AUTHORIZER" ); myConnection->setClient( myClient ); // do test once the event loop is running QTimer::singleShot( 0, this, SLOT( slotDoTest() ) ); @@ -23,7 +22,6 @@ LoginTest::LoginTest(int argc, char ** argv) : QApplication( argc, argv ) LoginTest::~LoginTest() { delete myTestObject; - delete myConnector; delete myClient; } @@ -35,7 +33,7 @@ void LoginTest::slotDoTest() myClient->setIsIcq( true ); myClient->start( server, 5190, "userid", "password" ); - myClient->connectToServer( myConnection, server, true ); + myClient->connectToServer( myConnection, server, 5190, true ); connected = true; } diff --git a/kopete/protocols/oscar/liboscar/tests/logintest.h b/kopete/protocols/oscar/liboscar/tests/logintest.h index 898a3d997..befa9f733 100644 --- a/kopete/protocols/oscar/liboscar/tests/logintest.h +++ b/kopete/protocols/oscar/liboscar/tests/logintest.h @@ -15,7 +15,6 @@ #include #include "oscarclientstream.h" -#include "oscarconnector.h" #include "client.h" #include "connection.h" #include "coreprotocol.h" @@ -42,7 +41,6 @@ public slots: //void slotsend(int layer); private: - KNetworkConnector *myConnector; ClientStream *myTestObject; Client* myClient; Connection* myConnection; diff --git a/kopete/protocols/oscar/oscaraccount.cpp b/kopete/protocols/oscar/oscaraccount.cpp index 2da1d9d15..5fc2fc10d 100644 --- a/kopete/protocols/oscar/oscaraccount.cpp +++ b/kopete/protocols/oscar/oscaraccount.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -53,7 +54,6 @@ #include "oscarmessage.h" #include "oscarutils.h" #include "oscarclientstream.h" -#include "oscarconnector.h" #include "contactmanager.h" #include "oscarlistnonservercontacts.h" #include "kopetetransfermanager.h" @@ -559,16 +559,12 @@ bool OscarAccount::changeContactGroupInSSI( const QString& contact, const QStrin return true; } -Connection* OscarAccount::setupConnection( const QString& server, uint port ) +Connection* OscarAccount::setupConnection() { - //set up the connector - KNetworkConnector* knc = new KNetworkConnector( 0 ); - knc->setOptHostPort( server, port ); - //set up the clientstream - ClientStream* cs = new ClientStream( knc, 0 ); + ClientStream* cs = new ClientStream( new QTcpSocket(), 0 ); - Connection* c = new Connection( knc, cs, "AUTHORIZER" ); + Connection* c = new Connection( cs, "AUTHORIZER" ); c->setClient( d->engine ); return c; diff --git a/kopete/protocols/oscar/oscaraccount.h b/kopete/protocols/oscar/oscaraccount.h index 72be583d4..e25106067 100644 --- a/kopete/protocols/oscar/oscaraccount.h +++ b/kopete/protocols/oscar/oscaraccount.h @@ -121,9 +121,9 @@ public slots: protected: /** - * Setup a connection for a derived account based on the host and port + * Setup a connection for a derived account */ - Connection* setupConnection( const QString& server, uint port ); + Connection* setupConnection(); /** * Adds a contact to a meta contact -- 2.11.4.GIT