summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/libiris/iris/jabber/xmpp_jidlink.h
blob: 806203cc457b2cbd612677388ba9dbc406172867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * jidlink.h - establish a link between Jabber IDs
 * Copyright (C) 2001, 2002  Justin Karneges
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

/*
   NOTE: this is not to be confused with JEP-0041
*/

#ifndef JABBER_JIDLINK_H
#define JABBER_JIDLINK_H

#include <tqobject.h>
#include <tqstring.h>
#include "xmpp.h"

class ByteStream;

namespace XMPP
{
	class Client;

	class JidLink : public TQObject
	{
		TQ_OBJECT
  
	public:
		enum { None, DTCP, IBB };
		enum { Idle, Connecting, WaitingForAccept, Active };
		enum { ErrConnect, ErrStream };
		enum { StatDTCPRequesting, StatDTCPAccepted, StatDTCPConnected, StatIBBRequesting, StatIBBConnected };
		JidLink(Client *client);
		~JidLink();

		void connectToJid(const Jid &jid, int type, const TQDomElement &comment);
		void accept();

		int type() const;
		Jid peer() const;
		int state() const;

		bool isOpen() const;
		void close();
		void write(const TQByteArray &);
		TQByteArray read(int bytes=0);
		int bytesAvailable() const;
		int bytesToWrite() const;

	signals:
		void connected();
		void connectionClosed();
		void readyRead();
		void bytesWritten(int);
		void error(int);
		void status(int);

	private slots:
		void dtcp_connected();
		void dtcp_accepted();
		void ibb_connected();

		void bs_connectionClosed();
		void bs_error(int);
		void bs_readyRead();
		void bs_bytesWritten(int);

		void doRealAccept();

	private:
		class Private;
		Private *d;

		void reset(bool clear=false);

		void link();
		void unlink();

		friend class JidLinkManager;
		bool setStream(ByteStream *);
	};

	// the job of JidLinkManager is to keep track of streams and properly shut them down
	class JidLinkManager : public TQObject
	{
		TQ_OBJECT
  
	public:
		JidLinkManager(Client *);
		~JidLinkManager();

		JidLink *takeIncoming();

		void insertStream(ByteStream *);

	private:
		class Private;
		Private *d;
	};
}

#endif