~ubuntu-branches/ubuntu/oneiric/psi/oneiric

« back to all changes in this revision

Viewing changes to iris/src/irisnet/noncore/stuntransaction.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009  Barracuda Networks, Inc.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
17
 * 02110-1301  USA
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef STUNTRANSACTION_H
 
22
#define STUNTRANSACTION_H
 
23
 
 
24
#include <QObject>
 
25
#include <QByteArray>
 
26
 
 
27
namespace QCA {
 
28
        class SecureArray;
 
29
}
 
30
 
 
31
namespace XMPP {
 
32
 
 
33
class StunMessage;
 
34
 
 
35
class StunTransaction : public QObject
 
36
{
 
37
        Q_OBJECT
 
38
 
 
39
public:
 
40
        enum Mode
 
41
        {
 
42
                Udp, // handle retransmissions
 
43
                Tcp  // send once
 
44
        };
 
45
 
 
46
        enum Error
 
47
        {
 
48
                ErrorGeneric,
 
49
                ErrorTimeout
 
50
        };
 
51
 
 
52
        StunTransaction(QObject *parent = 0);
 
53
        ~StunTransaction();
 
54
 
 
55
        // pass a message with transaction id unset.  it will be filled in.
 
56
        //   after calling this function, immediately obtain the result by
 
57
        //   calling packet(), and send it.  the start() function will not
 
58
        //   perform the first send attempt.  it leaves that to you.
 
59
        // FIXME: stuser/stpass are a hack
 
60
        void start(Mode mode, const StunMessage &request, const QString &stuser = QString(), const QString &stpass = QString());
 
61
 
 
62
        QByteArray transactionId() const;
 
63
        QByteArray packet() const;
 
64
 
 
65
        // transmission/timeout parameters, from RFC 5389.  by default,
 
66
        //   they are set to the recommended values from the RFC.
 
67
        void setRTO(int i);
 
68
        void setRc(int i);
 
69
        void setRm(int i);
 
70
        void setTi(int i);
 
71
 
 
72
        // note: not DOR-DS safe.  this will either emit signals and return
 
73
        //   true, or not emit signals and return false.
 
74
        bool writeIncomingMessage(const StunMessage &msg);
 
75
 
 
76
signals:
 
77
        // indicates you should retransmit the value of packet()
 
78
        void retransmit();
 
79
        void finished(const XMPP::StunMessage &response);
 
80
        void error(XMPP::StunTransaction::Error error);
 
81
 
 
82
private:
 
83
        Q_DISABLE_COPY(StunTransaction)
 
84
 
 
85
        class Private;
 
86
        friend class Private;
 
87
        Private *d;
 
88
};
 
89
 
 
90
// keep track of many open transactions.  note that retransmit() may be
 
91
//   emitted as a direct result of calling certain member functions of this
 
92
//   class as well as any other class that might use it (such as StunBinding).
 
93
//   so, be careful with what you do in your retransmit slot.
 
94
class StunTransactionPool : public QObject
 
95
{
 
96
        Q_OBJECT
 
97
 
 
98
public:
 
99
        StunTransactionPool(StunTransaction::Mode mode, QObject *parent = 0);
 
100
        ~StunTransactionPool();
 
101
 
 
102
        StunTransaction::Mode mode() const;
 
103
 
 
104
        // generate a random id not used by any transaction in the pool
 
105
        QByteArray generateId() const;
 
106
 
 
107
        // you must start the transaction before inserting it.
 
108
        // note: not DOR-DS safe.  this function will cause retransmit() to be
 
109
        //   emitted.
 
110
        void insert(StunTransaction *trans);
 
111
 
 
112
        void remove(StunTransaction *trans);
 
113
 
 
114
        // note: not DOR-DS safe.  this will either cause transactions to emit
 
115
        //   signals and return true, or not cause signals and return false.
 
116
        bool writeIncomingMessage(const StunMessage &msg);
 
117
 
 
118
        QString realm() const;
 
119
        void setUsername(const QString &username);
 
120
        void setPassword(const QCA::SecureArray &password);
 
121
        void setRealm(const QString &realm);
 
122
 
 
123
        void setShortTermCredentialsEnabled(bool enabled);
 
124
        void continueAfterParams();
 
125
 
 
126
        QString username() const;
 
127
        QString password() const;
 
128
 
 
129
signals:
 
130
        // note: not DOR-SS safe.  writeIncomingMessage() must not be called
 
131
        //   during this signal.
 
132
        void retransmit(XMPP::StunTransaction *trans);
 
133
 
 
134
        void needAuthParams();
 
135
 
 
136
private:
 
137
        Q_DISABLE_COPY(StunTransactionPool)
 
138
 
 
139
        class Private;
 
140
        friend class Private;
 
141
        Private *d;
 
142
};
 
143
 
 
144
}
 
145
 
 
146
#endif