1 | /*
|
---|
2 | * ibb.h - Inband bytestream
|
---|
3 | * Copyright (C) 2001, 2002 Justin Karneges
|
---|
4 | *
|
---|
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.
|
---|
9 | *
|
---|
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.
|
---|
14 | *
|
---|
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
|
---|
18 | *
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef JABBER_IBB_H
|
---|
22 | #define JABBER_IBB_H
|
---|
23 |
|
---|
24 | #include<qobject.h>
|
---|
25 | #include<qdom.h>
|
---|
26 | #include<qstring.h>
|
---|
27 | #include<qptrlist.h>
|
---|
28 | #include"bytestream.h"
|
---|
29 | #include"im.h"
|
---|
30 |
|
---|
31 | namespace XMPP
|
---|
32 | {
|
---|
33 | class Client;
|
---|
34 | class IBBManager;
|
---|
35 |
|
---|
36 | // this is an IBB connection. use it much like a qsocket
|
---|
37 | class IBBConnection : public ByteStream
|
---|
38 | {
|
---|
39 | Q_OBJECT
|
---|
40 | public:
|
---|
41 | enum { ErrRequest, ErrData };
|
---|
42 | enum { Idle, Requesting, WaitingForAccept, Active };
|
---|
43 | IBBConnection(IBBManager *);
|
---|
44 | ~IBBConnection();
|
---|
45 |
|
---|
46 | void connectToJid(const Jid &peer, const QDomElement &comment);
|
---|
47 | void accept();
|
---|
48 | void close();
|
---|
49 |
|
---|
50 | int state() const;
|
---|
51 | Jid peer() const;
|
---|
52 | QString streamid() const;
|
---|
53 | QDomElement comment() const;
|
---|
54 |
|
---|
55 | bool isOpen() const;
|
---|
56 | void write(const QByteArray &);
|
---|
57 | QByteArray read(int bytes=0);
|
---|
58 | int bytesAvailable() const;
|
---|
59 | int bytesToWrite() const;
|
---|
60 |
|
---|
61 | signals:
|
---|
62 | void connected();
|
---|
63 |
|
---|
64 | private slots:
|
---|
65 | void ibb_finished();
|
---|
66 | void trySend();
|
---|
67 |
|
---|
68 | private:
|
---|
69 | class Private;
|
---|
70 | Private *d;
|
---|
71 |
|
---|
72 | void reset(bool clear=false);
|
---|
73 |
|
---|
74 | friend class IBBManager;
|
---|
75 | void waitForAccept(const Jid &peer, const QString &sid, const QDomElement &comment, const QString &iq_id);
|
---|
76 | void takeIncomingData(const QByteArray &, bool close);
|
---|
77 | };
|
---|
78 |
|
---|
79 | typedef QPtrList<IBBConnection> IBBConnectionList;
|
---|
80 | typedef QPtrListIterator<IBBConnection> IBBConnectionListIt;
|
---|
81 | class IBBManager : public QObject
|
---|
82 | {
|
---|
83 | Q_OBJECT
|
---|
84 | public:
|
---|
85 | IBBManager(Client *);
|
---|
86 | ~IBBManager();
|
---|
87 |
|
---|
88 | Client *client() const;
|
---|
89 |
|
---|
90 | IBBConnection *takeIncoming();
|
---|
91 |
|
---|
92 | signals:
|
---|
93 | void incomingReady();
|
---|
94 |
|
---|
95 | private slots:
|
---|
96 | void ibb_incomingRequest(const Jid &from, const QString &id, const QDomElement &);
|
---|
97 | void ibb_incomingData(const Jid &from, const QString &streamid, const QString &id, const QByteArray &data, bool close);
|
---|
98 |
|
---|
99 | private:
|
---|
100 | class Private;
|
---|
101 | Private *d;
|
---|
102 |
|
---|
103 | QString genKey() const;
|
---|
104 |
|
---|
105 | friend class IBBConnection;
|
---|
106 | IBBConnection *findConnection(const QString &sid, const Jid &peer="") const;
|
---|
107 | QString genUniqueKey() const;
|
---|
108 | void link(IBBConnection *);
|
---|
109 | void unlink(IBBConnection *);
|
---|
110 | void doAccept(IBBConnection *c, const QString &id);
|
---|
111 | void doReject(IBBConnection *c, const QString &id, int, const QString &);
|
---|
112 | };
|
---|
113 |
|
---|
114 | class JT_IBB : public Task
|
---|
115 | {
|
---|
116 | Q_OBJECT
|
---|
117 | public:
|
---|
118 | enum { ModeRequest, ModeSendData };
|
---|
119 | JT_IBB(Task *, bool serve=false);
|
---|
120 | ~JT_IBB();
|
---|
121 |
|
---|
122 | void request(const Jid &, const QDomElement &comment);
|
---|
123 | void sendData(const Jid &, const QString &streamid, const QByteArray &data, bool close);
|
---|
124 | void respondSuccess(const Jid &, const QString &id, const QString &streamid);
|
---|
125 | void respondError(const Jid &, const QString &id, int code, const QString &str);
|
---|
126 | void respondAck(const Jid &to, const QString &id);
|
---|
127 |
|
---|
128 | void onGo();
|
---|
129 | bool take(const QDomElement &);
|
---|
130 |
|
---|
131 | QString streamid() const;
|
---|
132 | Jid jid() const;
|
---|
133 | int mode() const;
|
---|
134 |
|
---|
135 | signals:
|
---|
136 | void incomingRequest(const Jid &from, const QString &id, const QDomElement &);
|
---|
137 | void incomingData(const Jid &from, const QString &streamid, const QString &id, const QByteArray &data, bool close);
|
---|
138 |
|
---|
139 | private:
|
---|
140 | class Private;
|
---|
141 | Private *d;
|
---|
142 | };
|
---|
143 | }
|
---|
144 |
|
---|
145 | #endif
|
---|