1 | |
2 | /*************************************************************************** |
3 | gwconnector.cpp - Socket Connector for KNetwork |
4 | ------------------- |
5 | begin : Wed Jul 7 2004 |
6 | copyright : (C) 2004 by Till Gerken <till@tantalo.net> |
7 | |
8 | Kopete (C) 2004-2007 Kopete developers <kopete-devel@kde.org> |
9 | ***************************************************************************/ |
10 | |
11 | /*************************************************************************** |
12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU Lesser General Public License as * |
15 | * published by the Free Software Foundation; either version 2.1 of the * |
16 | * License, or (at your option) any later version. * |
17 | * * |
18 | ***************************************************************************/ |
19 | |
20 | #include "gwconnector.h" |
21 | #include <k3bufferedsocket.h> |
22 | #include <kdebug.h> |
23 | #include <k3resolver.h> |
24 | |
25 | #include "gwerror.h" |
26 | #include "gwbytestream.h" |
27 | |
28 | KNetworkConnector::KNetworkConnector ( QObject *parent ) |
29 | : Connector ( parent ) |
30 | { |
31 | kDebug () << "New KNetwork connector." ; |
32 | |
33 | mErrorCode = 0; |
34 | |
35 | mByteStream = new KNetworkByteStream ( this ); |
36 | |
37 | connect ( mByteStream, SIGNAL (connected()), this, SLOT (slotConnected()) ); |
38 | connect ( mByteStream, SIGNAL (error(int)), this, SLOT (slotError(int)) ); |
39 | mPort = 0; |
40 | } |
41 | |
42 | KNetworkConnector::~KNetworkConnector () |
43 | { |
44 | |
45 | delete mByteStream; |
46 | |
47 | } |
48 | |
49 | void KNetworkConnector::connectToServer ( const QString & /*server*/ ) |
50 | { |
51 | kDebug () << "Initiating connection to " << mHost; |
52 | Q_ASSERT( !mHost.isNull() ); |
53 | Q_ASSERT( mPort ); |
54 | /* |
55 | * FIXME: we should use a SRV lookup to determine the |
56 | * actual server to connect to. As this is currently |
57 | * not supported yet, we're using setOptHostPort(). |
58 | * For XMPP 1.0, we need to enable this! |
59 | */ |
60 | |
61 | mErrorCode = 0; |
62 | |
63 | mByteStream->connect ( mHost, QString::number ( mPort ) ); |
64 | } |
65 | |
66 | void KNetworkConnector::slotConnected () |
67 | { |
68 | kDebug() << "We are connected." ; |
69 | |
70 | // FIXME: setPeerAddress() is something different, find out correct usage later |
71 | //KInetSocketAddress inetAddress = mStreamSocket->address().asInet().makeIPv6 (); |
72 | //setPeerAddress ( QHostAddress ( inetAddress.ipAddress().addr () ), inetAddress.port () ); |
73 | |
74 | emit connected (); |
75 | |
76 | } |
77 | |
78 | void KNetworkConnector::slotError ( int code ) |
79 | { |
80 | kDebug() << "Error detected: " << code; |
81 | |
82 | mErrorCode = code; |
83 | emit error (); |
84 | } |
85 | |
86 | int KNetworkConnector::errorCode () |
87 | { |
88 | |
89 | return mErrorCode; |
90 | |
91 | } |
92 | |
93 | ByteStream *KNetworkConnector::stream () const |
94 | { |
95 | |
96 | return mByteStream; |
97 | |
98 | } |
99 | |
100 | void KNetworkConnector::done () |
101 | { |
102 | kDebug () ; |
103 | mByteStream->close (); |
104 | } |
105 | |
106 | void KNetworkConnector::setOptHostPort ( const QString &host, quint16 port ) |
107 | { |
108 | kDebug () << "Manually specifying host " << host << " and port " << port; |
109 | |
110 | mHost = host; |
111 | mPort = port; |
112 | |
113 | } |
114 | |
115 | void KNetworkConnector::setOptSSL ( bool ssl ) |
116 | { |
117 | kDebug () << "Setting SSL to " << ssl; |
118 | |
119 | setUseSSL ( ssl ); |
120 | |
121 | } |
122 | |
123 | #include "gwconnector.moc" |
124 | |