File indexing completed on 2024-04-28 07:54:09
0001 0002 /*************************************************************************** 0003 jabberconnector.cpp - Socket Connector for Jabber 0004 ------------------- 0005 begin : Wed Jul 7 2004 0006 copyright : (C) 2004 by Till Gerken <till@tantalo.net> 0007 0008 Kopete (C) 2004 Kopete developers <kopete-devel@kde.org> 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * This program is free software; you can redistribute it and/or modify * 0014 * it under the terms of the GNU Lesser General Public License as * 0015 * published by the Free Software Foundation; either either version 2 0016 of the License, or (at your option) any later version.1 of the * 0017 * License, or (at your option) any later version. * 0018 * * 0019 ***************************************************************************/ 0020 0021 #include "jabber_protocol_debug.h" 0022 #include "jabberconnector.h" 0023 // #include "jabberprotocol.h" 0024 0025 JabberConnector::JabberConnector ( QObject *parent ) 0026 : XMPP::Connector ( parent ) 0027 { 0028 qCDebug(JABBER_PROTOCOL_LOG) << "New Jabber connector."; 0029 0030 mErrorCode = 0; 0031 0032 mByteStream = new JabberByteStream ( this ); 0033 0034 connect ( mByteStream, &JabberByteStream::connected, this, &JabberConnector::slotConnected ); 0035 connect ( mByteStream, &ByteStream::error, this, &JabberConnector::slotError ); 0036 0037 } 0038 0039 JabberConnector::~JabberConnector () 0040 { 0041 0042 delete mByteStream; 0043 0044 } 0045 0046 void JabberConnector::connectToServer ( const QString &server ) 0047 { 0048 qCDebug(JABBER_PROTOCOL_LOG) << "Initiating connection to " << server; 0049 0050 /* 0051 * FIXME: we should use a SRV lookup to determine the 0052 * actual server to connect to. As this is currently 0053 * not supported yet, we're using setOptHostPort(). 0054 * For XMPP 1.0, we need to enable this! 0055 */ 0056 0057 mErrorCode = 0; 0058 0059 qCDebug(JABBER_PROTOCOL_LOG) << mHost << mPort; 0060 mByteStream->connect ( mHost, mPort ); 0061 0062 } 0063 0064 void JabberConnector::slotConnected () 0065 { 0066 qCDebug(JABBER_PROTOCOL_LOG) << "We are connected."; 0067 0068 // FIXME: setPeerAddress() is something different, find out correct usage later 0069 //KInetSocketAddress inetAddress = mStreamSocket->address().asInet().makeIPv6 (); 0070 //setPeerAddress ( QHostAddress ( inetAddress.ipAddress().addr () ), inetAddress.port () ); 0071 0072 emit connected (); 0073 0074 } 0075 0076 void JabberConnector::slotError ( int code ) 0077 { 0078 qCDebug(JABBER_PROTOCOL_LOG) << "Error detected: " << code; 0079 0080 mErrorCode = code; 0081 emit error (); 0082 0083 } 0084 0085 int JabberConnector::errorCode () 0086 { 0087 0088 return mErrorCode; 0089 0090 } 0091 0092 ByteStream *JabberConnector::stream () const 0093 { 0094 0095 return mByteStream; 0096 0097 } 0098 0099 void JabberConnector::done () 0100 { 0101 0102 mByteStream->close (); 0103 0104 } 0105 0106 void JabberConnector::setOptHostPort ( const QString &host, quint16 port ) 0107 { 0108 qCDebug(JABBER_PROTOCOL_LOG) << "Manually specifying host " << host << " and port " << port; 0109 0110 mHost = host; 0111 mPort = port; 0112 0113 } 0114 0115 void JabberConnector::setOptSSL ( bool ssl ) 0116 { 0117 qCDebug(JABBER_PROTOCOL_LOG) << "Setting SSL to " << ssl; 0118 0119 setUseSSL ( ssl ); 0120 0121 } 0122 0123 void JabberConnector::setOptProbe ( bool ) 0124 { 0125 // FIXME: Implement this. 0126 } 0127 0128 #include "moc_jabberconnector.cpp"