2
* jidlink.cpp - establish a link between Jabber IDs
3
* Copyright (C) 2001, 2002 Justin Karneges
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include"xmpp_jidlink.h"
31
//----------------------------------------------------------------------------
33
//----------------------------------------------------------------------------
34
class JidLink::Private
44
JidLink::JidLink(Client *client)
45
:QObject(client->jidLinkManager())
61
void JidLink::reset(bool clear)
76
void JidLink::connectToJid(const Jid &jid, int type, const QDomElement &comment)
80
d->bs = d->client->s5bManager()->createConnection();
82
d->bs = new IBBConnection(d->client->ibbManager());
88
d->state = Connecting;
93
S5BConnection *c = (S5BConnection *)d->bs;
94
status(StatDTCPRequesting);
95
c->connectToJid(jid, d->client->s5bManager()->genUniqueSID(jid));
98
IBBConnection *c = (IBBConnection *)d->bs;
99
status(StatIBBRequesting);
100
c->connectToJid(jid, comment);
106
if(d->type == DTCP) {
107
S5BConnection *c = (S5BConnection *)d->bs;
108
connect(c, SIGNAL(connected()), SLOT(dtcp_connected()));
109
connect(c, SIGNAL(accepted()), SLOT(dtcp_accepted()));
112
IBBConnection *c = (IBBConnection *)d->bs;
113
connect(c, SIGNAL(connected()), SLOT(ibb_connected()));
116
connect(d->bs, SIGNAL(connectionClosed()), SLOT(bs_connectionClosed()));
117
connect(d->bs, SIGNAL(error(int)), SLOT(bs_error(int)));
118
connect(d->bs, SIGNAL(bytesWritten(int)), SLOT(bs_bytesWritten(int)));
119
connect(d->bs, SIGNAL(readyRead()), SLOT(bs_readyRead()));
122
void JidLink::unlink()
124
d->bs->disconnect(this);
127
void JidLink::accept()
129
if(d->state != WaitingForAccept)
132
QTimer::singleShot(0, this, SLOT(doRealAccept()));
135
void JidLink::doRealAccept()
137
if(d->type == DTCP) {
138
((S5BConnection *)d->bs)->accept();
139
d->state = Connecting;
143
((IBBConnection *)d->bs)->accept();
149
bool JidLink::setStream(ByteStream *bs)
153
if(bs->inherits("XMPP::S5BConnection"))
155
else if(bs->inherits("XMPP::IBBConnection"))
163
d->state = WaitingForAccept;
168
d->peer = ((S5BConnection *)d->bs)->peer();
170
d->peer = ((IBBConnection *)d->bs)->peer();
175
int JidLink::type() const
180
Jid JidLink::peer() const
185
int JidLink::state() const
190
bool JidLink::isOpen() const
192
if(d->state == Active)
198
void JidLink::close()
205
void JidLink::write(const QByteArray &a)
207
if(d->state == Active)
211
QByteArray JidLink::read(int bytes)
214
return d->bs->read(bytes);
219
int JidLink::bytesAvailable() const
222
return d->bs->bytesAvailable();
227
int JidLink::bytesToWrite() const
229
if(d->state == Active)
230
return d->bs->bytesToWrite();
235
void JidLink::dtcp_accepted()
237
status(StatDTCPAccepted);
240
void JidLink::dtcp_connected()
243
status(StatDTCPConnected);
247
void JidLink::ibb_connected()
250
status(StatIBBConnected);
254
void JidLink::bs_connectionClosed()
260
void JidLink::bs_error(int)
266
void JidLink::bs_readyRead()
271
void JidLink::bs_bytesWritten(int x)
277
//----------------------------------------------------------------------------
279
//----------------------------------------------------------------------------
280
class JidLinkManager::Private
286
QPtrList<JidLink> incomingList;
289
JidLinkManager::JidLinkManager(Client *par)
296
JidLinkManager::~JidLinkManager()
298
d->incomingList.setAutoDelete(true);
299
d->incomingList.clear();
303
JidLink *JidLinkManager::takeIncoming()
305
if(d->incomingList.isEmpty())
308
JidLink *j = d->incomingList.getFirst();
309
d->incomingList.removeRef(j);
313
void JidLinkManager::insertStream(ByteStream *bs)
315
JidLink *j = new JidLink(d->client);
317
d->incomingList.append(j);