~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/sip/sippresence.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
 
3
 *
 
4
 *  Author: Patrick Keroulas  <patrick.keroulas@savoirfairelinux.com>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 
19
 *
 
20
 *  Additional permission under GNU GPL version 3 section 7:
 
21
 *
 
22
 *  If you modify this program, or any covered work, by linking or
 
23
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
24
 *  modified version of that library), containing parts covered by the
 
25
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
26
 *  grants you additional permission to convey the resulting work.
 
27
 *  Corresponding Source for a non-source form of such a combination
 
28
 *  shall include the source code for the parts of OpenSSL used as well
 
29
 *  as that of the covered work.
 
30
 */
 
31
 
 
32
#ifndef SIPPRESENCE_H
 
33
#define SIPPRESENCE_H
 
34
 
 
35
#include <string>
 
36
#include <list>
 
37
 
 
38
#include "noncopyable.h"
 
39
#include "pjsip/sip_types.h"
 
40
#include "pjsip/sip_msg.h"
 
41
#include "pjsip/sip_multipart.h"
 
42
#include "pjsip-simple/publish.h"
 
43
#include "pjsip-simple/presence.h"
 
44
#include "pjsip-simple/rpid.h"
 
45
#include <pj/pool.h>
 
46
 
 
47
#define PRESENCE_FUNCTION_PUBLISH   0
 
48
#define PRESENCE_FUNCTION_SUBSCRIBE 1
 
49
#define PRESENCE_LOCK_FLAG          1
 
50
#define PRESENCE_CLIENT_LOCK_FLAG   2
 
51
 
 
52
struct pres_msg_data {
 
53
    /**
 
54
     * Additional message headers as linked list. Application can add
 
55
     * headers to the list by creating the header, either from the heap/pool
 
56
     * or from temporary local variable, and add the header using
 
57
     * linked list operation. See pjsip_apps.c for some sample codes.
 
58
     */
 
59
    pjsip_hdr    hdr_list;
 
60
 
 
61
    /**
 
62
     * MIME type of optional message body.
 
63
     */
 
64
    pj_str_t    content_type;
 
65
 
 
66
    /**
 
67
     * Optional message body to be added to the message, only when the
 
68
     * message doesn't have a body.
 
69
     */
 
70
    pj_str_t    msg_body;
 
71
 
 
72
    /**
 
73
     * Content type of the multipart body. If application wants to send
 
74
     * multipart message bodies, it puts the parts in \a parts and set
 
75
     * the content type in \a multipart_ctype. If the message already
 
76
     * contains a body, the body will be added to the multipart bodies.
 
77
     */
 
78
    pjsip_media_type  multipart_ctype;
 
79
 
 
80
    /**
 
81
     * List of multipart parts. If application wants to send multipart
 
82
     * message bodies, it puts the parts in \a parts and set the content
 
83
     * type in \a multipart_ctype. If the message already contains a body,
 
84
     * the body will be added to the multipart bodies.
 
85
     */
 
86
    pjsip_multipart_part multipart_parts;
 
87
};
 
88
 
 
89
 
 
90
 
 
91
class SIPAccount;
 
92
class PresSubClient;
 
93
class PresSubServer;
 
94
/**
 
95
 * TODO Clean this:
 
96
 */
 
97
struct pj_caching_pool;
 
98
 
 
99
 
 
100
/**
 
101
 * @file sippresence.h
 
102
 * @brief A SIP Presence manages buddy subscription in both PBX and IP2IP contexts.
 
103
 */
 
104
 
 
105
class SIPPresence {
 
106
 
 
107
    public:
 
108
 
 
109
        /**
 
110
         * Constructor
 
111
         * @param acc the associated sipaccount
 
112
         */
 
113
        SIPPresence(SIPAccount * acc);
 
114
        /**
 
115
         * Destructor
 
116
         */
 
117
        ~SIPPresence();
 
118
 
 
119
        /**
 
120
         * Return associated sipaccount
 
121
         */
 
122
        SIPAccount * getAccount() const;
 
123
        /**
 
124
         * Return presence data.
 
125
         */
 
126
        pjsip_pres_status * getStatus();
 
127
        /**
 
128
         * Return presence module ID which is actually the same as the VOIP link
 
129
         */
 
130
        int getModId() const;
 
131
        /**
 
132
         *  Return a pool for generic functions.
 
133
         */
 
134
        pj_pool_t*  getPool() const;
 
135
        /**
 
136
         * Activate the module.
 
137
         * @param enable Flag
 
138
         */
 
139
        void enable(bool enabled);
 
140
        /**
 
141
         * Support the presence function publish/subscribe.
 
142
         * @param function Publish or subscribe to enable
 
143
         * @param enable Flag
 
144
         */
 
145
        void support(int function, bool enabled);
 
146
        /**
 
147
        * Fill xml document, the header and the body
 
148
        */
 
149
        void fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data);
 
150
        /**
 
151
         * Modify the presence data
 
152
         * @param status is basically "open" or "close"
 
153
         */
 
154
        void updateStatus(bool status, const std::string &note);
 
155
        /**
 
156
         * Send the presence data in a PUBLISH to the PBX or in a NOTIFY
 
157
         * to a remote subscriber (IP2IP)
 
158
         */
 
159
        void sendPresence(bool status, const std::string &note);
 
160
        /**
 
161
         * Send a signal to the client on DBus. The signal contain the status
 
162
         * of a remote user.
 
163
         */
 
164
        void reportPresSubClientNotification(const std::string& uri, pjsip_pres_status * status);
 
165
        /**
 
166
         * Send a SUBSCRIBE request to PBX/IP2IP
 
167
         * @param buddyUri  Remote user that we want to subscribe
 
168
         */
 
169
        void subscribeClient(const std::string& uri, bool flag);
 
170
        /**
 
171
         * Add a buddy in the buddy list.
 
172
         * @param b     PresSubClient pointer
 
173
         */
 
174
        void addPresSubClient(PresSubClient *b);
 
175
        /**
 
176
         * Remove a buddy from the list.
 
177
         * @param b     PresSubClient pointer
 
178
         */
 
179
        void removePresSubClient(PresSubClient *b);
 
180
 
 
181
        /**
 
182
        * IP2IP context.
 
183
        * Process new subscription based on client decision.
 
184
        * @param flag     client decision.
 
185
        * @param uri       uri of the remote subscriber
 
186
        */
 
187
        void approvePresSubServer(const std::string& uri, bool flag);
 
188
        /**
 
189
         * IP2IP context.
 
190
         * Add a server associated to a subscriber in the list.
 
191
         * @param s     PresenceSubcription pointer.
 
192
         */
 
193
        void addPresSubServer(PresSubServer *s);
 
194
        /**
 
195
         * IP2IP context.
 
196
         * Remove a server associated to a subscriber from the list.
 
197
         * @param s     PresenceSubcription pointer.
 
198
         */
 
199
        void removePresSubServer(PresSubServer *s);
 
200
        /**
 
201
         * IP2IP context.
 
202
         * Iterate through the subscriber list and send NOTIFY to each.
 
203
         */
 
204
        void notifyPresSubServer();
 
205
 
 
206
        bool isEnabled(){
 
207
            return enabled_;
 
208
        }
 
209
 
 
210
        bool isSupported(int function);
 
211
 
 
212
        std::list< PresSubClient *> getClientSubscriptions() {
 
213
            return sub_client_list_;
 
214
        }
 
215
 
 
216
        bool isOnline(){
 
217
            return status_;
 
218
        }
 
219
 
 
220
        std::string getNote(){
 
221
            return note_;
 
222
        }
 
223
 
 
224
        void lock();
 
225
        bool tryLock();
 
226
        void unlock();
 
227
 
 
228
    private:
 
229
        NON_COPYABLE(SIPPresence);
 
230
 
 
231
        static pj_status_t publish(SIPPresence *pres);
 
232
        static void publish_cb(struct pjsip_publishc_cbparam *param);
 
233
        static pj_status_t send_publish(SIPPresence *pres);
 
234
 
 
235
        pjsip_publishc  *publish_sess_;  /**< Client publication session.*/
 
236
        pjsip_pres_status status_data_; /**< Presence Data to be published.*/
 
237
 
 
238
        pj_bool_t enabled_;
 
239
        pj_bool_t publish_supported_; /**< the server allow for status publishing */
 
240
        pj_bool_t subscribe_supported_; /**< the server allow for buddy subscription */
 
241
 
 
242
        bool status_; /**< Status received from the server*/
 
243
        std::string note_; /**< Note received  from the server*/
 
244
        SIPAccount * acc_; /**<  Associated SIP account. */
 
245
        std::list< PresSubServer *> sub_server_list_; /**< Subscribers list.*/
 
246
        std::list< PresSubClient *> sub_client_list_; /**< Subcribed buddy list.*/
 
247
 
 
248
        pj_mutex_t      *mutex_;
 
249
        unsigned         mutex_nesting_level_;
 
250
        pj_thread_t     *mutex_owner_;
 
251
        pj_caching_pool  cp_;
 
252
        pj_pool_t       *pool_;
 
253
};
 
254
 
 
255
#endif