Bonjour nick name is in Latin1 encoding
[kdenetwork.git] / kopete / protocols / jabber / jabberclient.cpp
blobbfb30315cfa2721998dfcecbaad2e7b69eff1b4b
2 /***************************************************************************
3 jabberclient.cpp - Generic Jabber Client Class
4 -------------------
5 begin : Sat May 25 2005
6 copyright : (C) 2005 by Till Gerken <till@tantalo.net>
7 (C) 2006 by Michaƫl Larouche <larouche@kde.org>
8 Copyright 2006 by Tommi Rantala <tommi.rantala@cs.helsinki.fi>
10 Kopete (C) 2001-2006 Kopete developers
11 <kopete-devel@kde.org>.
12 ***************************************************************************/
14 /***************************************************************************
15 * *
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published by *
18 * the Free Software Foundation; either version 2 of the License, or *
19 * (at your option) any later version. *
20 * *
21 ***************************************************************************/
23 #include "jabberclient.h"
25 #include <kdebug.h>
27 #include <QTimer>
28 #include <QRegExp>
29 #include <QtCrypto>
31 #include <bsocket.h>
32 #include <filetransfer.h>
33 #include <jinglesessionmanager.h>
34 #include <xmpp_tasks.h>
36 #include "privacymanager.h"
38 #define JABBER_PENALTY_TIME 2
40 class JabberClient::Private
42 public:
43 Private()
44 : jabberClient(0L), jabberClientStream(0L), jabberClientConnector(0L), jabberTLS(0L),
45 jabberTLSHandler(0L), privacyManager(0L)
47 ~Private()
49 if ( jabberClient )
51 jabberClient->close ();
54 delete jabberClient;
55 delete jabberClientStream;
56 delete jabberClientConnector;
57 delete jabberTLSHandler;
58 delete jabberTLS;
59 // privacyManager will be deleted with jabberClient, its parent's parent
62 // connection details
63 XMPP::Jid jid;
64 QString password;
66 // XMPP backend
67 XMPP::Client *jabberClient;
68 XMPP::ClientStream *jabberClientStream;
69 XMPP::AdvancedConnector *jabberClientConnector;
70 QCA::TLS *jabberTLS;
71 XMPP::QCATLSHandler *jabberTLSHandler;
72 QCA::Initializer qcaInit;
73 PrivacyManager *privacyManager;
75 // ignore TLS warnings
76 bool ignoreTLSWarnings;
78 // current S5B server instance
79 static XMPP::S5BServer *s5bServer;
80 // address list being handled by the S5B server instance
81 static QStringList s5bAddressList;
82 // port of S5B server
83 static int s5bServerPort;
85 // local IP address
86 QString localAddress;
88 // whether TLS (or direct SSL in case of the old protocol) should be used
89 bool forceTLS;
91 // whether direct SSL connections should be used
92 bool useSSL;
94 // use XMPP 1.0 or the older protocol version
95 bool useXMPP09;
97 // whether SSL support should be probed in case the old protocol is used
98 bool probeSSL;
100 // override the default server name and port (only pre-XMPP 1.0)
101 bool overrideHost;
102 QString server;
103 int port;
105 // allow transmission of plaintext passwords
106 bool allowPlainTextPassword;
108 // enable file transfers
109 bool fileTransfersEnabled;
111 // current penalty time
112 int currentPenaltyTime;
114 // client information
115 QString clientName, clientVersion, osName;
117 // timezone information
118 QString timeZoneName;
119 int timeZoneOffset;
121 // Caps(JEP-0115: Entity Capabilities) information
122 QString capsNode, capsVersion;
123 DiscoItem::Identity discoIdentity;
126 XMPP::S5BServer *JabberClient::Private::s5bServer = 0L;
127 QStringList JabberClient::Private::s5bAddressList;
128 int JabberClient::Private::s5bServerPort = 8010;
130 JabberClient::JabberClient ()
131 : d(new Private())
133 cleanUp ();
135 // initiate penalty timer
136 QTimer::singleShot ( JABBER_PENALTY_TIME * 1000, this, SLOT ( slotUpdatePenaltyTime () ) );
140 JabberClient::~JabberClient ()
142 delete d;
145 void JabberClient::cleanUp ()
147 if ( d->jabberClient )
149 d->jabberClient->close ();
152 delete d->jabberClient;
153 delete d->jabberClientStream;
154 delete d->jabberClientConnector;
155 delete d->jabberTLSHandler;
156 delete d->jabberTLS;
157 // privacyManager will be deleted with jabberClient, its parent's parent
159 d->jabberClient = 0L;
160 d->jabberClientStream = 0L;
161 d->jabberClientConnector = 0L;
162 d->jabberTLSHandler = 0L;
163 d->jabberTLS = 0L;
164 d->privacyManager = 0L;
166 d->currentPenaltyTime = 0;
168 d->jid = XMPP::Jid ();
169 d->password.clear();
171 setForceTLS ( false );
172 setUseSSL ( false );
173 setUseXMPP09 ( false );
174 setProbeSSL ( false );
176 setOverrideHost ( false );
178 setAllowPlainTextPassword ( true );
180 setFileTransfersEnabled ( false );
181 setS5BServerPort ( 8010 );
183 setClientName ( QString() );
184 setClientVersion ( QString() );
185 setOSName ( QString() );
187 setTimeZone ( "UTC", 0 );
189 setIgnoreTLSWarnings ( false );
193 void JabberClient::slotUpdatePenaltyTime ()
196 if ( d->currentPenaltyTime >= JABBER_PENALTY_TIME )
197 d->currentPenaltyTime -= JABBER_PENALTY_TIME;
198 else
199 d->currentPenaltyTime = 0;
201 QTimer::singleShot ( JABBER_PENALTY_TIME * 1000, this, SLOT ( slotUpdatePenaltyTime () ) );
205 void JabberClient::setIgnoreTLSWarnings ( bool flag )
208 d->ignoreTLSWarnings = flag;
212 bool JabberClient::ignoreTLSWarnings ()
215 return d->ignoreTLSWarnings;
219 bool JabberClient::setS5BServerPort ( int port )
222 d->s5bServerPort = port;
224 if ( fileTransfersEnabled () )
226 return s5bServer()->start ( port );
229 return true;
233 int JabberClient::s5bServerPort () const
236 return d->s5bServerPort;
240 XMPP::S5BServer *JabberClient::s5bServer ()
243 if ( !d->s5bServer )
245 d->s5bServer = new XMPP::S5BServer ();
246 QObject::connect ( d->s5bServer, SIGNAL ( destroyed () ), this, SLOT ( slotS5BServerGone () ) );
249 * Try to start the server at the default port here.
250 * We have no way of notifying the caller of an error.
251 * However, since the caller will usually also
252 * use setS5BServerPort() to ensure the correct
253 * port, we can return an error code there.
255 if ( fileTransfersEnabled () )
257 s5bServer()->start ( d->s5bServerPort );
261 return d->s5bServer;
265 void JabberClient::slotS5BServerGone ()
268 d->s5bServer = 0L;
270 if ( d->jabberClient )
271 d->jabberClient->s5bManager()->setServer( 0L );
275 void JabberClient::addS5BServerAddress ( const QString &address )
277 QStringList newList;
279 d->s5bAddressList.append ( address );
281 // now filter the list without dupes
282 foreach( QStringList::const_reference str, d->s5bAddressList )
284 if ( !newList.contains ( str ) )
285 newList.append ( str );
288 s5bServer()->setHostList ( newList );
292 void JabberClient::removeS5BServerAddress ( const QString &address )
294 QStringList newList;
296 int idx = d->s5bAddressList.indexOf( address );
298 if ( idx != -1 )
299 d->s5bAddressList.removeAt(idx);
301 if ( d->s5bAddressList.isEmpty () )
303 delete d->s5bServer;
304 d->s5bServer = 0L;
306 else
308 // now filter the list without dupes
309 foreach( QStringList::const_reference str, d->s5bAddressList )
311 if ( !newList.contains ( str ) )
312 newList.append ( str );
315 s5bServer()->setHostList ( newList );
320 void JabberClient::setForceTLS ( bool flag )
323 d->forceTLS = flag;
327 bool JabberClient::forceTLS () const
330 return d->forceTLS;
334 void JabberClient::setUseSSL ( bool flag )
337 d->useSSL = flag;
341 bool JabberClient::useSSL () const
344 return d->useSSL;
348 void JabberClient::setUseXMPP09 ( bool flag )
351 d->useXMPP09 = flag;
355 bool JabberClient::useXMPP09 () const
358 return d->useXMPP09;
362 void JabberClient::setProbeSSL ( bool flag )
365 d->probeSSL = flag;
369 bool JabberClient::probeSSL () const
372 return d->probeSSL;
376 void JabberClient::setOverrideHost ( bool flag, const QString &server, int port )
379 d->overrideHost = flag;
380 d->server = server;
381 d->port = port;
385 bool JabberClient::overrideHost () const
388 return d->overrideHost;
392 void JabberClient::setAllowPlainTextPassword ( bool flag )
395 d->allowPlainTextPassword = flag;
399 bool JabberClient::allowPlainTextPassword () const
402 return d->allowPlainTextPassword;
406 void JabberClient::setFileTransfersEnabled ( bool flag, const QString &localAddress )
409 d->fileTransfersEnabled = flag;
410 d->localAddress = localAddress;
414 QString JabberClient::localAddress () const
417 return d->localAddress;
421 bool JabberClient::fileTransfersEnabled () const
424 return d->fileTransfersEnabled;
428 void JabberClient::setClientName ( const QString &clientName )
431 d->clientName = clientName;
435 QString JabberClient::clientName () const
438 return d->clientName;
442 void JabberClient::setClientVersion ( const QString &clientVersion )
445 d->clientVersion = clientVersion;
449 QString JabberClient::clientVersion () const
452 return d->clientVersion;
456 void JabberClient::setOSName ( const QString &osName )
459 d->osName = osName;
463 QString JabberClient::osName () const
466 return d->osName;
470 void JabberClient::setCapsNode( const QString &capsNode )
472 d->capsNode = capsNode;
475 QString JabberClient::capsNode() const
477 return d->capsNode;
480 void JabberClient::setCapsVersion( const QString &capsVersion )
482 d->capsVersion = capsVersion;
485 QString JabberClient::capsVersion() const
487 return d->capsVersion;
490 QString JabberClient::capsExt() const
492 if(d->jabberClient)
494 return d->jabberClient->capsExt();
497 return QString();
499 void JabberClient::setDiscoIdentity( DiscoItem::Identity identity )
501 d->discoIdentity = identity;
504 DiscoItem::Identity JabberClient::discoIdentity() const
506 return d->discoIdentity;
509 void JabberClient::setTimeZone ( const QString &timeZoneName, int timeZoneOffset )
512 d->timeZoneName = timeZoneName;
513 d->timeZoneOffset = timeZoneOffset;
517 QString JabberClient::timeZoneName () const
520 return d->timeZoneName;
524 int JabberClient::timeZoneOffset () const
527 return d->timeZoneOffset;
531 int JabberClient::getPenaltyTime ()
534 int currentTime = d->currentPenaltyTime;
536 d->currentPenaltyTime += JABBER_PENALTY_TIME;
538 return currentTime;
542 XMPP::Client *JabberClient::client () const
545 return d->jabberClient;
549 XMPP::ClientStream *JabberClient::clientStream () const
552 return d->jabberClientStream;
556 XMPP::AdvancedConnector *JabberClient::clientConnector () const
559 return d->jabberClientConnector;
563 XMPP::Task *JabberClient::rootTask () const
566 if ( client () )
568 return client()->rootTask ();
570 else
572 return 0l;
577 XMPP::FileTransferManager *JabberClient::fileTransferManager () const
580 if ( client () )
582 return client()->fileTransferManager ();
584 else
586 return 0L;
591 PrivacyManager *JabberClient::privacyManager () const
593 return d->privacyManager;
596 XMPP::Jid JabberClient::jid () const
599 return d->jid;
603 JabberClient::ErrorCode JabberClient::connect ( const XMPP::Jid &jid, const QString &password, bool auth )
606 * Close any existing connection.
608 if ( d->jabberClient )
610 d->jabberClient->close ();
612 d->jid = jid;
613 d->password = password;
616 * Return an error if we should force TLS but it's not available.
618 if ( ( forceTLS () || useSSL () || probeSSL () ) && !QCA::isSupported ("tls" ) )
620 qDebug ("no TLS");
621 return NoTLS;
625 * Instantiate connector, responsible for dealing with the socket.
626 * This class uses KDE's socket code, which in turn makes use of
627 * the global proxy settings.
629 d->jabberClientConnector = new XMPP::AdvancedConnector;
631 d->jabberClientConnector->setOptSSL ( useSSL () );
633 if ( useXMPP09 () )
635 if ( overrideHost () )
637 d->jabberClientConnector->setOptHostPort ( d->server, d->port );
640 d->jabberClientConnector->setOptProbe ( probeSSL () );
645 * Setup authentication layer
647 if ( QCA::isSupported ("tls") )
649 d->jabberTLS = new QCA::TLS;
650 d->jabberTLS->setTrustedCertificates(QCA::systemStore());
651 d->jabberTLSHandler = new QCATLSHandler(d->jabberTLS);
652 d->jabberTLSHandler->setXMPPCertCheck(true);
654 QObject::connect ( d->jabberTLSHandler, SIGNAL ( tlsHandshaken() ), SLOT ( slotTLSHandshaken () ) );
658 * Instantiate client stream which handles the network communication by referring
659 * to a connector (proxying etc.) and a TLS handler (security layer)
661 d->jabberClientStream = new XMPP::ClientStream ( d->jabberClientConnector, d->jabberTLSHandler );
664 using namespace XMPP;
665 QObject::connect ( d->jabberClientStream, SIGNAL ( needAuthParams(bool, bool, bool) ),
666 this, SLOT ( slotCSNeedAuthParams (bool, bool, bool) ) );
667 QObject::connect ( d->jabberClientStream, SIGNAL ( authenticated () ),
668 this, SLOT ( slotCSAuthenticated () ) );
669 QObject::connect ( d->jabberClientStream, SIGNAL ( connectionClosed () ),
670 this, SLOT ( slotCSDisconnected () ) );
671 QObject::connect ( d->jabberClientStream, SIGNAL ( delayedCloseFinished () ),
672 this, SLOT ( slotCSDisconnected () ) );
673 QObject::connect ( d->jabberClientStream, SIGNAL ( warning (int) ),
674 this, SLOT ( slotCSWarning (int) ) );
675 QObject::connect ( d->jabberClientStream, SIGNAL ( error (int) ),
676 this, SLOT ( slotCSError (int) ) );
679 d->jabberClientStream->setOldOnly ( useXMPP09 () );
682 * Initiate anti-idle timer (will be triggered every 55 seconds).
684 d->jabberClientStream->setNoopTime ( 55000 );
687 * Allow plaintext password authentication or not?
689 d->jabberClientStream->setAllowPlain( allowPlainTextPassword () ? XMPP::ClientStream::AllowPlain : XMPP::ClientStream::NoAllowPlain );
692 * Setup client layer.
694 d->jabberClient = new XMPP::Client ( this );
697 * Setup privacy manager
699 d->privacyManager = new PrivacyManager ( rootTask() );
702 * Enable file transfer (IP and server will be set after connection
703 * has been established.
705 if ( fileTransfersEnabled () )
707 d->jabberClient->setFileTransferEnabled ( true );
710 using namespace XMPP;
711 QObject::connect ( d->jabberClient->fileTransferManager(), SIGNAL ( incomingReady() ),
712 this, SLOT ( slotIncomingFileTransfer () ) );
716 /*if (jingleEnabled())
719 #ifdef JINGLE_SUPPORT
720 d->jabberClient->setJingleEnabled(true);
723 using namespace XMPP;
724 QObject::connect ( d->jabberClient->jingleSessionManager(), SIGNAL ( incomingSession() ),
725 this, SLOT ( slotIncomingJingleSession () ) );
727 #else
728 d->jabberClient->setJingleEnabled(false);
729 #endif
730 /*}*/
732 /* This should only be done here to connect the signals, otherwise it is a
733 * bad idea.
736 using namespace XMPP;
737 QObject::connect ( d->jabberClient, SIGNAL ( subscription (const Jid &, const QString &, const QString &) ),
738 this, SLOT ( slotSubscription (const Jid &, const QString &) ) );
739 QObject::connect ( d->jabberClient, SIGNAL ( rosterRequestFinished ( bool, int, const QString & ) ),
740 this, SLOT ( slotRosterRequestFinished ( bool, int, const QString & ) ) );
741 QObject::connect ( d->jabberClient, SIGNAL ( rosterItemAdded (const RosterItem &) ),
742 this, SLOT ( slotNewContact (const RosterItem &) ) );
743 QObject::connect ( d->jabberClient, SIGNAL ( rosterItemUpdated (const RosterItem &) ),
744 this, SLOT ( slotContactUpdated (const RosterItem &) ) );
745 QObject::connect ( d->jabberClient, SIGNAL ( rosterItemRemoved (const RosterItem &) ),
746 this, SLOT ( slotContactDeleted (const RosterItem &) ) );
747 QObject::connect ( d->jabberClient, SIGNAL ( resourceAvailable (const Jid &, const Resource &) ),
748 this, SLOT ( slotResourceAvailable (const Jid &, const Resource &) ) );
749 QObject::connect ( d->jabberClient, SIGNAL ( resourceUnavailable (const Jid &, const Resource &) ),
750 this, SLOT ( slotResourceUnavailable (const Jid &, const Resource &) ) );
751 QObject::connect ( d->jabberClient, SIGNAL ( messageReceived (const Message &) ),
752 this, SLOT ( slotReceivedMessage (const Message &) ) );
753 QObject::connect ( d->jabberClient, SIGNAL ( groupChatJoined (const Jid &) ),
754 this, SLOT ( slotGroupChatJoined (const Jid &) ) );
755 QObject::connect ( d->jabberClient, SIGNAL ( groupChatLeft (const Jid &) ),
756 this, SLOT ( slotGroupChatLeft (const Jid &) ) );
757 QObject::connect ( d->jabberClient, SIGNAL ( groupChatPresence (const Jid &, const Status &) ),
758 this, SLOT ( slotGroupChatPresence (const Jid &, const Status &) ) );
759 QObject::connect ( d->jabberClient, SIGNAL ( groupChatError (const Jid &, int, const QString &) ),
760 this, SLOT ( slotGroupChatError (const Jid &, int, const QString &) ) );
761 //QObject::connect ( d->jabberClient, SIGNAL (debugText (const QString &) ),
762 // this, SLOT ( slotPsiDebug (const QString &) ) );
763 QObject::connect ( d->jabberClient, SIGNAL ( xmlIncoming(const QString& ) ),
764 this, SLOT ( slotIncomingXML (const QString &) ) );
765 QObject::connect ( d->jabberClient, SIGNAL ( xmlOutgoing(const QString& ) ),
766 this, SLOT ( slotOutgoingXML (const QString &) ) );
769 d->jabberClient->setClientName ( clientName () );
770 d->jabberClient->setClientVersion ( clientVersion () );
771 d->jabberClient->setOSName ( osName () );
773 // Set caps information
774 d->jabberClient->setCapsNode( capsNode() );
775 d->jabberClient->setCapsVersion( capsVersion() );
777 // Set Disco Identity
778 d->jabberClient->setIdentity( discoIdentity() );
780 d->jabberClient->setTimeZone ( timeZoneName (), timeZoneOffset () );
782 // Additional features
783 d->jabberClient->setFeatures(Features("http://jabber.org/protocol/xhtml-im"));
785 d->jabberClient->connectToServer ( d->jabberClientStream, jid, auth );
787 return Ok;
791 void JabberClient::disconnect ()
794 if ( d->jabberClient )
796 d->jabberClient->close ();
798 else
800 cleanUp ();
805 void JabberClient::disconnect( XMPP::Status &reason )
807 if ( d->jabberClient )
809 if ( d->jabberClientStream->isActive() )
811 XMPP::JT_Presence *pres = new JT_Presence(rootTask());
812 reason.setIsAvailable( false );
813 pres->pres( reason );
814 pres->go();
816 d->jabberClientStream->close();
817 d->jabberClient->close();
820 else
822 cleanUp();
826 bool JabberClient::isConnected () const
829 if ( d->jabberClient )
831 return d->jabberClient->isActive ();
834 return false;
838 void JabberClient::joinGroupChat ( const QString &host, const QString &room, const QString &nick )
841 client()->groupChatJoin ( host, room, nick );
845 void JabberClient::joinGroupChat ( const QString &host, const QString &room, const QString &nick, const QString &password )
847 client()->groupChatJoin ( host, room, nick, password );
851 void JabberClient::leaveGroupChat ( const QString &host, const QString &room )
854 client()->groupChatLeave ( host, room );
858 void JabberClient::setGroupChatStatus( const QString & host, const QString & room, const XMPP::Status & status )
860 client()->groupChatSetStatus( host, room, status);
863 void JabberClient::changeGroupChatNick( const QString & host, const QString & room, const QString & nick, const XMPP::Status & status )
865 client()->groupChatChangeNick( host, room, nick, status );
869 void JabberClient::sendMessage ( const XMPP::Message &message )
872 client()->sendMessage ( message );
876 void JabberClient::send ( const QString &packet )
879 client()->send ( packet );
883 void JabberClient::requestRoster ()
886 client()->rosterRequest ();
890 void JabberClient::slotPsiDebug ( const QString & _msg )
892 QString msg = _msg;
894 msg = msg.replace( QRegExp( "<password>[^<]*</password>\n" ), "<password>[Filtered]</password>\n" );
895 msg = msg.replace( QRegExp( "<digest>[^<]*</digest>\n" ), "<digest>[Filtered]</digest>\n" );
897 emit debugMessage ( "Psi: " + msg );
901 void JabberClient::slotIncomingXML ( const QString & _msg )
903 QString msg = _msg;
905 msg = msg.replace( QRegExp( "<password>[^<]*</password>\n" ), "<password>[Filtered]</password>\n" );
906 msg = msg.replace( QRegExp( "<digest>[^<]*</digest>\n" ), "<digest>[Filtered]</digest>\n" );
908 emit debugMessage ( "XML IN: " + msg );
909 emit incomingXML ( msg );
912 void JabberClient::slotOutgoingXML ( const QString & _msg )
914 QString msg = _msg;
916 msg = msg.replace( QRegExp( "<password>[^<]*</password>\n" ), "<password>[Filtered]</password>\n" );
917 msg = msg.replace( QRegExp( "<digest>[^<]*</digest>\n" ), "<digest>[Filtered]</digest>\n" );
919 emit debugMessage ( "XML OUT: " + msg );
920 emit outgoingXML ( msg );
923 void JabberClient::slotTLSHandshaken ()
926 emit debugMessage ( "TLS handshake done, testing certificate validity..." );
928 // FIXME: in the future, this should be handled by KDE, not QCA
930 QCA::TLS::IdentityResult identityResult = d->jabberTLS->peerIdentityResult();
931 QCA::Validity validityResult = d->jabberTLS->peerCertificateValidity();
933 if ( identityResult == QCA::TLS::Valid && validityResult == QCA::ValidityGood )
935 emit debugMessage ( "Identity and certificate valid, continuing." );
937 // valid certificate, continue
938 d->jabberTLSHandler->continueAfterHandshake ();
940 else
942 emit debugMessage ( "Certificate is not valid, asking user what to do next." );
944 // certificate is not valid, query the user
945 if ( ignoreTLSWarnings () )
947 emit debugMessage ( "We are supposed to ignore TLS warnings, continuing." );
948 d->jabberTLSHandler->continueAfterHandshake ();
951 emit tlsWarning ( identityResult, validityResult );
956 void JabberClient::continueAfterTLSWarning ()
959 if ( d->jabberTLSHandler )
961 d->jabberTLSHandler->continueAfterHandshake ();
966 void JabberClient::slotCSNeedAuthParams ( bool user, bool pass, bool realm )
968 emit debugMessage ( "Sending auth credentials..." );
970 if ( user )
972 d->jabberClientStream->setUsername ( jid().node () );
975 if ( pass )
977 d->jabberClientStream->setPassword ( d->password );
980 if ( realm )
982 d->jabberClientStream->setRealm ( jid().domain () );
985 d->jabberClientStream->continueAfterParams ();
989 void JabberClient::slotCSAuthenticated ()
991 emit debugMessage ( "Connected to Jabber server." );
994 * Determine local IP address.
995 * FIXME: This is ugly!
997 if ( localAddress().isEmpty () )
999 // code for Iris-type bytestreams
1000 ByteStream *irisByteStream = d->jabberClientConnector->stream();
1001 if ( irisByteStream->inherits ( "BSocket" ) || irisByteStream->inherits ( "XMPP::BSocket" ) )
1003 d->localAddress = ( (BSocket *)irisByteStream )->address().toString ();
1007 if ( fileTransfersEnabled () )
1009 // setup file transfer
1010 addS5BServerAddress ( localAddress () );
1011 d->jabberClient->s5bManager()->setServer ( s5bServer () );
1015 //update the ressource:
1016 d->jid = d->jabberClientStream->jid();
1018 // start the client operation
1019 d->jabberClient->start ( jid().domain (), jid().node (), d->password, jid().resource () );
1021 if (!d->jabberClientStream->old())
1023 XMPP::JT_Session *j = new XMPP::JT_Session(rootTask());
1024 QObject::connect(j, SIGNAL(finished()), this, SLOT(slotSessionStarted()));
1025 j->go(true);
1027 else
1029 emit connected();
1033 void JabberClient::slotSessionStarted()
1035 XMPP::JT_Session *j = static_cast<XMPP::JT_Session*>(sender());
1036 if ( j->success() )
1037 emit connected();
1038 else
1039 emit csError ( -1 );
1043 void JabberClient::slotCSDisconnected ()
1046 /* FIXME:
1047 * We should delete the XMPP::Client instance here,
1048 * but timers etc prevent us from doing so. (Psi does
1049 * not like to be deleted from a slot).
1052 emit debugMessage ( "Disconnected, freeing up file transfer port..." );
1054 // delete local address from S5B server
1055 removeS5BServerAddress ( localAddress () );
1057 emit csDisconnected ();
1061 void JabberClient::slotCSWarning ( int warning )
1064 emit debugMessage ( "Client stream warning." );
1067 * FIXME: process all other warnings
1069 switch ( warning )
1071 //case XMPP::ClientStream::WarnOldVersion:
1072 case XMPP::ClientStream::WarnNoTLS:
1073 if ( forceTLS () )
1075 disconnect ();
1076 emit error ( NoTLS );
1077 return;
1079 break;
1082 d->jabberClientStream->continueAfterWarning ();
1086 void JabberClient::slotCSError ( int error )
1089 emit debugMessage ( "Client stream error." );
1091 emit csError ( error );
1095 void JabberClient::slotRosterRequestFinished ( bool success, int /*statusCode*/, const QString &/*statusString*/ )
1098 emit rosterRequestFinished ( success );
1102 void JabberClient::slotIncomingFileTransfer ()
1105 emit incomingFileTransfer ();
1109 void JabberClient::slotNewContact ( const XMPP::RosterItem &item )
1112 emit newContact ( item );
1116 void JabberClient::slotContactDeleted ( const RosterItem &item )
1119 emit contactDeleted ( item );
1123 void JabberClient::slotContactUpdated ( const RosterItem &item )
1126 emit contactUpdated ( item );
1130 void JabberClient::slotResourceAvailable ( const Jid &jid, const Resource &resource )
1133 emit resourceAvailable ( jid, resource );
1137 void JabberClient::slotResourceUnavailable ( const Jid &jid, const Resource &resource )
1140 emit resourceUnavailable ( jid, resource );
1144 void JabberClient::slotReceivedMessage ( const Message &message )
1147 emit messageReceived ( message );
1151 void JabberClient::slotGroupChatJoined ( const Jid &jid )
1154 emit groupChatJoined ( jid );
1158 void JabberClient::slotGroupChatLeft ( const Jid &jid )
1161 emit groupChatLeft ( jid );
1165 void JabberClient::slotGroupChatPresence ( const Jid &jid, const Status &status)
1168 emit groupChatPresence ( jid, status );
1172 void JabberClient::slotGroupChatError ( const Jid &jid, int error, const QString &reason)
1175 emit groupChatError ( jid, error, reason );
1179 void JabberClient::slotSubscription ( const Jid &jid, const QString &type )
1182 emit subscription ( jid, type );
1187 #include "jabberclient.moc"