Hi!

I have 2 problems with jabber protocol in KDE4's kopete.

1. I use tsocks command line utility to redirect kopete through socks
proxy at work. Kopete from KDE3 works ok with this, however when i try
to run KDE4's kopete, i get "Operation not supported".
2. We have here at work internal jabber server based on ancient
jabberd 1.4 and again, kopete from KDE3 works ok with it, but KDE4's
kopete shows message box about error in stream and crashes.

Both issues are gone when i ported jabber protocol to QtNetwork. As i
see, oscar protocol plugin was converted to QtNetwork as well.

Please review and if ok commit, i don't have an svn account.
Index: protocols/jabber/jabberbytestream.h
===================================================================
--- protocols/jabber/jabberbytestream.h	(revision 829340)
+++ protocols/jabber/jabberbytestream.h	(working copy)
@@ -21,7 +21,7 @@
 #define JABBERBYTESTREAM_H
 
 #include <bytestream.h>
-#include <k3bufferedsocket.h>
+#include <QTcpSocket>
 #include <kopete_export.h>
 
 
@@ -38,11 +38,11 @@
 
 	virtual ~JabberByteStream ();
 
-	bool connect ( QString host, QString service );
+	void connect ( QString host, int port );
 	virtual bool isOpen () const;
 	virtual void close ();
 
-	KNetwork::KBufferedSocket *socket () const;
+	QTcpSocket *socket () const;
 
 signals:
 	void connected ();
@@ -58,7 +58,7 @@
 	void slotError ( int );
 
 private:
-	KNetwork::KBufferedSocket *mSocket;
+	QTcpSocket *mSocket;
 	bool mClosing;
 
 };
Index: protocols/jabber/jabberconnector.cpp
===================================================================
--- protocols/jabber/jabberconnector.cpp	(revision 829340)
+++ protocols/jabber/jabberconnector.cpp	(working copy)
@@ -27,7 +27,7 @@
 {
 	kDebug ( JABBER_DEBUG_GLOBAL ) << "New Jabber connector.";
 
-	mErrorCode = KNetwork::KSocketBase::NoError;
+	mErrorCode = 0;
 
 	mByteStream = new JabberByteStream ( this );
 
@@ -54,14 +54,9 @@
 	 * For XMPP 1.0, we need to enable this!
 	 */
 
-	mErrorCode = KNetwork::KSocketBase::NoError;
+	mErrorCode = 0;
 
-	if ( !mByteStream->connect ( mHost, QString::number ( mPort ) ) )
-	{
-		// Houston, we have a problem
-		mErrorCode = mByteStream->socket()->error ();
-		emit error ();
-	}
+	mByteStream->connect ( mHost, mPort );
 
 }
 
Index: protocols/jabber/jabberaccount.cpp
===================================================================
--- protocols/jabber/jabberaccount.cpp	(revision 829340)
+++ protocols/jabber/jabberaccount.cpp	(working copy)
@@ -38,6 +38,7 @@
 #include <qstring.h>
 #include <qregexp.h>
 #include <qtimer.h>
+#include <QAbstractSocket>
 
 #include <kcomponentdata.h>
 #include <kconfig.h>
@@ -45,7 +46,6 @@
 #include <kmessagebox.h>
 #include <klocale.h>
 #include <kaboutdata.h>
-#include <k3socketbase.h>
 #include <kpassworddialog.h>
 #include <kinputdialog.h>
 #include <kicon.h>
@@ -854,55 +854,28 @@
 		case XMPP::ClientStream::ErrConnection:
 			switch(connectorCode)
 			{
- 				case KNetwork::KSocketBase::LookupFailure:
+ 				case QAbstractSocket::HostNotFoundError:
 					errorClass = Kopete::Account::InvalidHost;
 					errorCondition = i18n("Host not found.");
 					break;
-				case KNetwork::KSocketBase::AddressInUse:
+				case QAbstractSocket::AddressInUseError:
 					errorCondition = i18n("Address is already in use.");
 					break;
-				case KNetwork::KSocketBase::AlreadyCreated:
-					errorCondition = i18n("Cannot recreate the socket.");
-					break;
-				case KNetwork::KSocketBase::AlreadyBound:
-					errorCondition = i18n("Cannot bind the socket again.");
-					break;
-				case KNetwork::KSocketBase::AlreadyConnected:
-					errorCondition = i18n("Socket is already connected.");
-					break;
-				case KNetwork::KSocketBase::NotConnected:
-					errorCondition = i18n("Socket is not connected.");
-					break;
-				case KNetwork::KSocketBase::NotBound:
-					errorCondition = i18n("Socket is not bound.");
-					break;
-				case KNetwork::KSocketBase::NotCreated:
-					errorCondition = i18n("Socket has not been created.");
-					break;
-				case KNetwork::KSocketBase::WouldBlock:
-					errorCondition = i18n("The socket operation would block. You should not see this error: please use \"Report Bug\" from the Help menu.");
-					break;
-				case KNetwork::KSocketBase::ConnectionRefused:
+				case QAbstractSocket::ConnectionRefusedError:
 					errorCondition = i18n("Connection refused.");
 					break;
-				case KNetwork::KSocketBase::ConnectionTimedOut:
-					errorCondition = i18n("Connection timed out.");
-					break;
-				case KNetwork::KSocketBase::InProgress:
+				case QAbstractSocket::UnfinishedSocketOperationError:
 					errorCondition = i18n("Connection attempt already in progress.");
 					break;
-				case KNetwork::KSocketBase::NetFailure:
+				case QAbstractSocket::NetworkError:
 					errorCondition = i18n("Network failure.");
 					break;
-				case KNetwork::KSocketBase::NotSupported:
-					errorCondition = i18n("Operation is not supported.");
-					break;
-				case KNetwork::KSocketBase::Timeout:
+				case QAbstractSocket::SocketTimeoutError:
 					errorCondition = i18n("Socket timed out.");
 					break;
 				default:
 					errorClass = Kopete::Account::ConnectionReset;
-					//errorCondition = i18n("Sorry, something unexpected happened that I do not know more about.");
+					errorCondition = i18n("Sorry, something unexpected happened that I do not know more about.");
 					break;
 			}
 			if(!errorCondition.isEmpty())
Index: protocols/jabber/jabberclient.cpp
===================================================================
--- protocols/jabber/jabberclient.cpp	(revision 829340)
+++ protocols/jabber/jabberclient.cpp	(working copy)
@@ -987,7 +987,7 @@
 		JabberByteStream *kdeByteStream = dynamic_cast<JabberByteStream*>(d->jabberClientConnector->stream());
 		if ( kdeByteStream )
 		{
-			d->localAddress = kdeByteStream->socket()->localAddress().nodeName ();
+			d->localAddress = kdeByteStream->socket()->peerName();
 		}
 	}
 
Index: protocols/jabber/jabberbytestream.cpp
===================================================================
--- protocols/jabber/jabberbytestream.cpp	(revision 829340)
+++ protocols/jabber/jabberbytestream.cpp	(working copy)
@@ -19,9 +19,8 @@
 
 #include <qobject.h>
 #include <kdebug.h>
+#include <ksocketfactory.h>
 #include "jabberbytestream.h"
-#include <k3bufferedsocket.h>
-#include <k3resolver.h>
 #include "jabberprotocol.h"
 
 JabberByteStream::JabberByteStream ( QObject *parent )
@@ -32,28 +31,22 @@
 	// reset close tracking flag
 	mClosing = false;
 
-	mSocket = new KNetwork::KBufferedSocket;
-
-	// make sure we get a signal whenever there's data to be read
-	mSocket->enableRead ( true );
-
-	// connect signals and slots
-	QObject::connect ( mSocket, SIGNAL ( gotError ( int ) ), this, SLOT ( slotError ( int ) ) );
-	QObject::connect ( mSocket, SIGNAL ( connected ( const KNetwork::KResolverEntry& ) ), this, SLOT ( slotConnected () ) );
-	QObject::connect ( mSocket, SIGNAL ( closed () ), this, SLOT ( slotConnectionClosed () ) );
-	QObject::connect ( mSocket, SIGNAL ( readyRead () ), this, SLOT ( slotReadyRead () ) );
-	QObject::connect ( mSocket, SIGNAL ( bytesWritten ( qint64 ) ), this, SLOT ( slotBytesWritten ( qint64 ) ) );
-
+	mSocket = NULL;
 }
 
-bool JabberByteStream::connect ( QString host, QString service )
+void JabberByteStream::connect ( QString host, int port )
 {
-	kDebug ( JABBER_DEBUG_GLOBAL ) << "Connecting to " << host << ", service " << service;
+	kDebug ( JABBER_DEBUG_GLOBAL ) << k_funcinfo << "Connecting to " << host << ", port " << port << endl;
 
 	mClosing = false;
 
-	return socket()->connect ( host, service );
+	mSocket = KSocketFactory::connectToHost("xmpp", host, port);
 
+	QObject::connect ( mSocket, SIGNAL ( QAbstractSocket::SocketError ), this, SLOT ( slotError ( QAbstractSocket::SocketError ) ) );
+	QObject::connect ( mSocket, SIGNAL ( connected () ), this, SLOT ( slotConnected () ) );
+	QObject::connect ( mSocket, SIGNAL ( closed () ), this, SLOT ( slotConnectionClosed () ) );
+	QObject::connect ( mSocket, SIGNAL ( readyRead () ), this, SLOT ( slotReadyRead () ) );
+	QObject::connect ( mSocket, SIGNAL ( bytesWritten ( qint64 ) ), this, SLOT ( slotBytesWritten ( qint64 ) ) );
 }
 
 bool JabberByteStream::isOpen () const
@@ -70,8 +63,13 @@
 
 	// close the socket and set flag that we are closing it ourselves
 	mClosing = true;
-	socket()->close();
-
+        if (mSocket) {
+             kDebug ( JABBER_DEBUG_GLOBAL ) << k_funcinfo << "socket is not null" << endl;
+	     mSocket->close();
+             kDebug ( JABBER_DEBUG_GLOBAL ) << k_funcinfo << "socket closed" << endl;
+             delete mSocket;
+             mSocket=NULL;
+        }
 }
 
 int JabberByteStream::tryWrite ()
@@ -85,7 +83,7 @@
 
 }
 
-KNetwork::KBufferedSocket *JabberByteStream::socket () const
+QTcpSocket *JabberByteStream::socket () const
 {
 
 	return mSocket;
@@ -143,8 +141,7 @@
 void JabberByteStream::slotError ( int code )
 {
 	kDebug ( JABBER_DEBUG_GLOBAL ) << "Socket error '" <<  mSocket->errorString() <<  "' - Code : " << code;
-	if(KNetwork::KSocketBase::isFatalError( code ))
-		emit error ( code );
+	emit error ( code );
 }
 
 #include "jabberbytestream.moc"
_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel

Reply via email to