~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/sxe/sxemanager.h

  • Committer: Package Import Robot
  • Author(s): Jan Niehusmann
  • Date: 2014-07-01 21:49:34 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140701214934-gt4dkgm94byi4vnn
Tags: 0.15-1
* New upstream version
* set debhelper compat level to 9
* set Standards-Version to 3.9.5 (no further changes)
* add lintian override regarding license-problem-non-free-RFC
* use qconf to regenerate configure script
* implement hardening using buildflags instead of hardening-wrapper

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 *
19
19
 */
20
20
 
26
26
#include "sxesession.h"
27
27
 
28
28
namespace XMPP {
29
 
    class Client;
30
 
    class Jid;
31
 
    class Message;
 
29
        class Client;
 
30
        class Jid;
 
31
        class Message;
32
32
}
33
33
 
34
34
using namespace XMPP;
49
49
 */
50
50
class SxeManager : public QObject
51
51
{
52
 
    Q_OBJECT
53
 
 
54
 
    /*! \brief A simple struct used to keep track of the detected SXE sessions.*/
55
 
    struct DetectedSession {
56
 
        QString session;
57
 
        Jid jid;
58
 
        QTime time;
59
 
    };
60
 
 
61
 
    /*! \brief A simple class to keep track of the state of a session negotiation process.*/
62
 
    class SxeNegotiation{
63
 
    public:
64
 
        enum Role {Participant, Joiner};
65
 
        enum State {NotStarted, InvitationSent, ConnectionRequested, InvitationAccepted, DocumentBegan, /*DocumentEnded,*/ HistoryOffered, HistoryAccepted, Finished, Aborted};
66
 
 
67
 
        /*! \brief Describes our role in the negotiation.*/
68
 
        Role role;
69
 
        /*! \brief Describes the current state of the negotiation.*/
70
 
        State state;
71
 
        /*! \brief The identifier for the session.*/
72
 
        QString sessionId;
73
 
        /*! \brief The JID that will be used for delivering the sxe messages once session is established.*/
74
 
        Jid target;
75
 
        /*! \brief The JID where negotiation messages are sent.*/
76
 
        Jid peer;
77
 
        /*! \brief The user's own JID used in the session.*/
78
 
        Jid ownJid;
79
 
        /*! \brief Set if the target is a groupchat.*/
80
 
        bool groupChat;
81
 
        /*! \brief The document to be sent as the initial document during the negotiation.
82
 
         *      This is only relevant when Role == Participant.
83
 
         */
84
 
        QDomDocument initialDoc;
85
 
        /*! \brief A list of features proposed for the session.*/
86
 
        QList<QString> features;
87
 
        /*! \brief The session created for this negotiation.*/
88
 
        QPointer<SxeSession> session;
89
 
    };
90
 
    
 
52
        Q_OBJECT
 
53
 
 
54
        /*! \brief A simple struct used to keep track of the detected SXE sessions.*/
 
55
        struct DetectedSession {
 
56
                QString session;
 
57
                Jid jid;
 
58
                QTime time;
 
59
        };
 
60
 
 
61
        /*! \brief A simple class to keep track of the state of a session negotiation process.*/
 
62
        class SxeNegotiation{
 
63
        public:
 
64
                enum Role {Participant, Joiner};
 
65
                enum State {NotStarted, InvitationSent, ConnectionRequested, InvitationAccepted, DocumentBegan, /*DocumentEnded,*/ HistoryOffered, HistoryAccepted, Finished, Aborted};
 
66
 
 
67
                /*! \brief Describes our role in the negotiation.*/
 
68
                Role role;
 
69
                /*! \brief Describes the current state of the negotiation.*/
 
70
                State state;
 
71
                /*! \brief The identifier for the session.*/
 
72
                QString sessionId;
 
73
                /*! \brief The JID that will be used for delivering the sxe messages once session is established.*/
 
74
                Jid target;
 
75
                /*! \brief The JID where negotiation messages are sent.*/
 
76
                Jid peer;
 
77
                /*! \brief The user's own JID used in the session.*/
 
78
                Jid ownJid;
 
79
                /*! \brief Set if the target is a groupchat.*/
 
80
                bool groupChat;
 
81
                /*! \brief The document to be sent as the initial document during the negotiation.
 
82
                 *        This is only relevant when Role == Participant.
 
83
                 */
 
84
                QDomDocument initialDoc;
 
85
                /*! \brief A list of features proposed for the session.*/
 
86
                QList<QString> features;
 
87
                /*! \brief The session created for this negotiation.*/
 
88
                QPointer<SxeSession> session;
 
89
        };
 
90
 
91
91
public:
92
 
    /*! \brief Constructor.
93
 
     *  Creates a new manager for the specified Client and PsiAccount
94
 
     */
95
 
    SxeManager(XMPP::Client* client, PsiAccount* pa);
96
 
    /*! \brief Return a list of pointers to sessions to the specified contact.
97
 
     *  If no such session exits, returns 0.
98
 
     */
99
 
    QList< QPointer<SxeSession> > findSession(const Jid &target);
100
 
    /*! \brief Return a pointer to the specified session.
101
 
     *  If such session doesn't exits, returns 0.
102
 
     */
103
 
    QPointer<SxeSession> findSession(const QString &session);
104
 
    /*! \brief Add a callback for invitations.*/
105
 
    void addInvitationCallback(bool (*callback)(const Jid &peer, const QList<QString> &features));
106
 
    /*! \brief Starts a new session negotiation to the specified contact with given list of features.*/
107
 
    void startNewSession(const Jid &target, const Jid &ownJid, bool groupChat, const QDomDocument &initialDoc, QList<QString> features = QList<QString>());
108
 
    /*! \brief Join an existing session.*/
109
 
    void joinSession(const Jid &target, const Jid &ownJid, bool groupChat, const QString &session);
110
 
    /*! \brief Checks that \a jid supports SXE and \a features. */
111
 
    bool checkSupport(const Jid &jid, const QList<QString> &features);
 
92
        /*! \brief Constructor.
 
93
         *  Creates a new manager for the specified Client and PsiAccount
 
94
         */
 
95
        SxeManager(XMPP::Client* client, PsiAccount* pa);
 
96
        /*! \brief Return a list of pointers to sessions to the specified contact.
 
97
         *  If no such session exits, returns 0.
 
98
         */
 
99
        QList< QPointer<SxeSession> > findSession(const Jid &target);
 
100
        /*! \brief Return a pointer to the specified session.
 
101
         *  If such session doesn't exits, returns 0.
 
102
         */
 
103
        QPointer<SxeSession> findSession(const QString &session);
 
104
        /*! \brief Add a callback for invitations.*/
 
105
        void addInvitationCallback(bool (*callback)(const Jid &peer, const QList<QString> &features));
 
106
        /*! \brief Starts a new session negotiation to the specified contact with given list of features.*/
 
107
        void startNewSession(const Jid &target, const Jid &ownJid, bool groupChat, const QDomDocument &initialDoc, QList<QString> features = QList<QString>());
 
108
        /*! \brief Join an existing session.*/
 
109
        void joinSession(const Jid &target, const Jid &ownJid, bool groupChat, const QString &session);
 
110
        /*! \brief Checks that \a jid supports SXE and \a features. */
 
111
        bool checkSupport(const Jid &jid, const QList<QString> &features);
 
112
 
 
113
        inline Client *client() { return client_; }
112
114
 
113
115
signals:
114
 
    /*! \brief Emitted when \a session has been established.*/
115
 
    void sessionNegotiated(SxeSession* session);
116
 
    /*! \brief Emitted when \a an invitation to \a jid was declined and joining an alternative session \a session was suggested.*/
117
 
    void alternativeSession(const Jid &jid, const QString &session);
 
116
        /*! \brief Emitted when \a session has been established.*/
 
117
        void sessionNegotiated(SxeSession* session);
 
118
        /*! \brief Emitted when \a an invitation to \a jid was declined and joining an alternative session \a session was suggested.*/
 
119
        void alternativeSession(const Jid &jid, const QString &session);
118
120
 
119
121
private:
120
 
    /*! \brief Process a message that contains a negotiation element.
121
 
     *  Returns a pointer to the new session if negotiation finished.
122
 
     */
123
 
    QPointer<SxeSession> processNegotiationMessage(const Message &message);
124
 
    /*! \brief Process a negotiation element as a Participant.
125
 
        Appends the appropriate responses to \a response.
126
 
        Returns false iff the negotiation object was deleted. */
127
 
    bool processNegotiationAsParticipant(const QDomNode &negotiationElement, SxeNegotiation* negotiation, QDomNode response);
128
 
    /*! \brief Process a negotiation element as a Joiner.
129
 
        Appends the appropriate responses to \a response.
130
 
        Returns false iff the negotiation object was deleted. */
131
 
    bool processNegotiationAsJoiner(const QDomNode &negotiationElement, SxeNegotiation* negotiation, QDomNode response, const Message &message);
132
 
    /*! \brief Returns a pointer to a new session instance.*/
133
 
    QPointer<SxeSession> createSxeSession(const Jid &target, QString session, const Jid &ownJid, bool groupChat, const QList<QString> &features);
134
 
    /*! \brief Aborts the negotiation of \a session started with \a peer.*/
135
 
    void abortNegotiation(QString session, const Jid &peer, bool groupChat);
136
 
    /*! \brief Aborts the negotiation with the peer and deletes the session.*/
137
 
    void abortNegotiation(SxeNegotiation* negotiation);
138
 
    /*! \brief Records the session that the message refers to as a DetectedSession if no entry for the session exists yet.*/
139
 
    void recordDetectedSession(const Message &message);
140
 
    /*! \brief Returns a pointer to a new negotiation instance based on \a message.*/
141
 
    SxeNegotiation* createNegotiation(const Message &message);
142
 
    /*! \brief Returns a pointer to a new negotiation instance.*/
143
 
    SxeNegotiation* createNegotiation(SxeNegotiation::Role role, SxeNegotiation::State state, const QString &sessionId, const Jid &target, const Jid &ownJid, bool groupChat);
144
 
    /*! \brief Returns a pointer to an existing negotiation object of \a session with \a jid.*/
145
 
    SxeNegotiation* findNegotiation(const Jid &jid, const QString &session);
146
 
    /*! \brief Remove the negotiation object of \a session with \a jid.*/
147
 
    void removeNegotiation(SxeNegotiation* negotiation);
148
 
    
149
 
 
150
 
    /*! \brief A pointer to the Client to listen to.*/
151
 
    XMPP::Client* client_;
152
 
    /*! \brief A pointer to the PsiAccount to listen to.*/
153
 
    PsiAccount* pa_;
154
 
    /*! \brief A list of of established sessions.*/
155
 
    QList< QPointer<SxeSession> > sessions_;
156
 
    /*! \brief A list of negotiations in process.*/
157
 
    QMultiHash<QString, SxeNegotiation* > negotiations_;
158
 
    /*! \brief A timer used to remove unfinished negotiations after a timeout.*/
159
 
    QTimer negotiationTimer_;
160
 
    /*! \brief A list of of detected sessions.*/
161
 
    QList<DetectedSession> DetectedSessions_;
162
 
    /*! \brief A list of Jids corresponding to self.*/
163
 
    QList<QString> ownJids_;
164
 
    /*! \brief A list of callbacks used to determine whether an invitation should be accepted.*/
165
 
    QList<bool (*)(const Jid &peer, const QList<QString> &features)> invitationCallbacks_;
166
 
    /*! \brief A counter used for including a unique id in each sent sxe element.*/
167
 
    int sxeId_;
168
 
    /*! \brief A list of messages waiting to be sent out.*/
169
 
    QList<Message> queuedMessages_;
 
122
        /*! \brief Process a message that contains a negotiation element.
 
123
         *  Returns a pointer to the new session if negotiation finished.
 
124
         */
 
125
        QPointer<SxeSession> processNegotiationMessage(const Message &message);
 
126
        /*! \brief Process a negotiation element as a Participant.
 
127
                Appends the appropriate responses to \a response.
 
128
                Returns false iff the negotiation object was deleted. */
 
129
        bool processNegotiationAsParticipant(const QDomNode &negotiationElement, SxeNegotiation* negotiation, QDomNode response);
 
130
        /*! \brief Process a negotiation element as a Joiner.
 
131
                Appends the appropriate responses to \a response.
 
132
                Returns false iff the negotiation object was deleted. */
 
133
        bool processNegotiationAsJoiner(const QDomNode &negotiationElement, SxeNegotiation* negotiation, QDomNode response, const Message &message);
 
134
        /*! \brief Returns a pointer to a new session instance.*/
 
135
        QPointer<SxeSession> createSxeSession(const Jid &target, QString session, const Jid &ownJid, bool groupChat, const QList<QString> &features);
 
136
        /*! \brief Aborts the negotiation of \a session started with \a peer.*/
 
137
        void abortNegotiation(QString session, const Jid &peer, bool groupChat);
 
138
        /*! \brief Aborts the negotiation with the peer and deletes the session.*/
 
139
        void abortNegotiation(SxeNegotiation* negotiation);
 
140
        /*! \brief Records the session that the message refers to as a DetectedSession if no entry for the session exists yet.*/
 
141
        void recordDetectedSession(const Message &message);
 
142
        /*! \brief Returns a pointer to a new negotiation instance based on \a message.*/
 
143
        SxeNegotiation* createNegotiation(const Message &message);
 
144
        /*! \brief Returns a pointer to a new negotiation instance.*/
 
145
        SxeNegotiation* createNegotiation(SxeNegotiation::Role role, SxeNegotiation::State state, const QString &sessionId, const Jid &target, const Jid &ownJid, bool groupChat);
 
146
        /*! \brief Returns a pointer to an existing negotiation object of \a session with \a jid.*/
 
147
        SxeNegotiation* findNegotiation(const Jid &jid, const QString &session);
 
148
        /*! \brief Remove the negotiation object of \a session with \a jid.*/
 
149
        void removeNegotiation(SxeNegotiation* negotiation);
 
150
 
 
151
 
 
152
        /*! \brief A pointer to the Client to listen to.*/
 
153
        XMPP::Client* client_;
 
154
        /*! \brief A pointer to the PsiAccount to listen to.*/
 
155
        PsiAccount* pa_;
 
156
        /*! \brief A list of of established sessions.*/
 
157
        QList< QPointer<SxeSession> > sessions_;
 
158
        /*! \brief A list of negotiations in process.*/
 
159
        QMultiHash<QString, SxeNegotiation* > negotiations_;
 
160
        /*! \brief A timer used to remove unfinished negotiations after a timeout.*/
 
161
        QTimer negotiationTimer_;
 
162
        /*! \brief A list of of detected sessions.*/
 
163
        QList<DetectedSession> DetectedSessions_;
 
164
        /*! \brief A list of Jids corresponding to self.*/
 
165
        QList<QString> ownJids_;
 
166
        /*! \brief A list of callbacks used to determine whether an invitation should be accepted.*/
 
167
        QList<bool (*)(const Jid &peer, const QList<QString> &features)> invitationCallbacks_;
 
168
        /*! \brief A counter used for including a unique id in each sent sxe element.*/
 
169
        int sxeId_;
 
170
        /*! \brief A list of messages waiting to be sent out.*/
 
171
        QList<Message> queuedMessages_;
170
172
 
171
173
private slots:
172
 
    /*! \brief Receives incoming message and determines what to do with them.*/
173
 
    void messageReceived(const Message &message);
174
 
    /*! \brief Send given whiteboard element to receiver in a message.*/
175
 
    void sendSxe(QDomElement sxe, const Jid & receiver, bool groupChat);
176
 
    /*! \brief Removes and deletes the session.*/
177
 
    void removeSession(SxeSession* session);
178
 
    /*! \brief Removes the "detected session" record of the given session.*/
179
 
    void removeDetectedSession(SxeSession* session);
180
 
    /*! \brief Removes and deletes the possible sessions for the groupchat.*/
181
 
    void groupChatLeft(const Jid &);
182
 
    /*! \brief Keeps a record of groupchats.*/
183
 
    void groupChatJoined(const Jid &, const Jid &ownJid);
184
 
    /*! \brief Removes inactive and unfinished session negotiations.*/
185
 
    void negotiationTimeout();
 
174
        /*! \brief Receives incoming message and determines what to do with them.*/
 
175
        void messageReceived(const Message &message);
 
176
        /*! \brief Send given whiteboard element to receiver in a message.*/
 
177
        void sendSxe(QDomElement sxe, const Jid & receiver, bool groupChat);
 
178
        /*! \brief Removes and deletes the session.*/
 
179
        void removeSession(SxeSession* session);
 
180
        /*! \brief Removes the "detected session" record of the given session.*/
 
181
        void removeDetectedSession(SxeSession* session);
 
182
        /*! \brief Removes and deletes the possible sessions for the groupchat.*/
 
183
        void groupChatLeft(const Jid &);
 
184
        /*! \brief Keeps a record of groupchats.*/
 
185
        void groupChatJoined(const Jid &, const Jid &ownJid);
 
186
        /*! \brief Removes inactive and unfinished session negotiations.*/
 
187
        void negotiationTimeout();
186
188
};
187
189
 
188
190
#endif