sippresence.h 7.08 KB
Newer Older
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
/*
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
 *
 *  Author: Patrick Keroulas  <patrick.keroulas@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
 */

#ifndef SIPPRESENCE_H
#define SIPPRESENCE_H

#include <vector>
#include <string>
#include <list>

39
#include "noncopyable.h"
40
41
42
43
44
45
#include "pjsip/sip_types.h"
#include "pjsip/sip_msg.h"
#include "pjsip/sip_multipart.h"
#include "pjsip-simple/publish.h"
#include "pjsip-simple/presence.h"
#include "pjsip-simple/rpid.h"
46
#include <pj/pool.h>
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

struct pres_msg_data
{
    /**
     * Additional message headers as linked list. Application can add
     * headers to the list by creating the header, either from the heap/pool
     * or from temporary local variable, and add the header using
     * linked list operation. See pjsip_apps.c for some sample codes.
     */
    pjsip_hdr	hdr_list;

    /**
     * MIME type of optional message body.
     */
    pj_str_t	content_type;

    /**
     * Optional message body to be added to the message, only when the
     * message doesn't have a body.
     */
    pj_str_t	msg_body;

    /**
     * Content type of the multipart body. If application wants to send
     * multipart message bodies, it puts the parts in \a parts and set
     * the content type in \a multipart_ctype. If the message already
     * contains a body, the body will be added to the multipart bodies.
     */
    pjsip_media_type  multipart_ctype;

    /**
     * List of multipart parts. If application wants to send multipart
     * message bodies, it puts the parts in \a parts and set the content
     * type in \a multipart_ctype. If the message already contains a body,
     * the body will be added to the multipart bodies.
     */
    pjsip_multipart_part multipart_parts;
};


87
//extern void pres_process_msg_data(pjsip_tx_data *tdata, const pres_msg_data *msg_data);
88
89
90


class SIPAccount;
91
92
class PresSubClient;
class PresSubServer;
93
94
95
96
97
/**
 * TODO Clean this:
 */
struct pj_caching_pool;

98
99
100
101
102
103
104
105
106

/**
 * @file sippresence.h
 * @brief A SIP Presence manages buddy subscription in both PBX and IP2IP contexts.
 */

class SIPPresence {

public:
107

108
109
110
111
112
113
114
115
116
117
    /**
     * Constructor
     * @param acc the associated sipaccount
     */
    SIPPresence(SIPAccount * acc);
    /**
     * Destructor
     */
    ~SIPPresence();

118
119
120
121
122
123
124
125
126
127
128
129
    /**
     * Return associated sipaccount
     */
    SIPAccount * getAccount();
    /**
     * Return presence data.
     */
    pjsip_pres_status * getStatus();
    /**
     * Return presence module ID which is actually the same as the VOIP link
     */
    int getModId();
130
131
132
133
134
    /**
     *  Return a pool for generic functions.
     */
    pj_pool_t*  getPool();
    /**
135
136
137
138
     * Activate the module (PUBLISH/SUBSCRIBE)
     */
    void enable(const bool& flag);
     /**
139
140
141
     * Fill xml document, the header and the body
     */
    void fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data);
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    /**
     * Modify the presence data
     * @param status is basically "open" or "close"
     */
    void updateStatus(const std::string &status, const std::string &note);
    /**
     * Send the presence data in a PUBLISH to the PBX or in a NOTIFY
     * to a remote subscriber (IP2IP)
     */
    void sendPresence(const std::string &status, const std::string &note);
    /**
     * Send a signal to the client on DBus. The signal contain the status
     * of a remote user.
     */
156
    void reportPresSubClientNotification(const std::string& uri, pjsip_pres_status * status);
157
158
159
160
    /**
     * Send a SUBSCRIBE request to PBX/IP2IP
     * @param buddyUri  Remote user that we want to subscribe
     */
161
    void subscribePresSubClient(const std::string& uri, const bool& flag);
162
163
    /**
     * Add a buddy in the buddy list.
164
     * @param b     PresSubClient pointer
165
     */
166
    void addPresSubClient(PresSubClient *b);
167
168
    /**
     * Remove a buddy from the list.
169
     * @param b     PresSubClient pointer
170
     */
171
    void removePresSubClient(PresSubClient *b);
172

173
174
175
176
177
    /**
     * IP2IP context.
     * Report new Subscription to the client, waiting for approval.
     * @param s     PresenceSubcription pointer.
     */
178
    void reportNewPresSubServerRequest(PresSubServer *s);
179
180
181
     /**
     * IP2IP context.
     * Process new subscription based on client decision.
182
183
     * @param flag     client decision.
     * @param uri       uri of the remote subscriber
184
     */
185
    void approvePresSubServer(const bool& flag, const std::string& uri);
186
    /**
187
188
189
     * IP2IP context.
     * Add a server associated to a subscriber in the list.
     * @param s     PresenceSubcription pointer.
190
     */
191
    void addPresSubServer(PresSubServer *s);
192
    /**
193
194
195
     * IP2IP context.
     * Remove a server associated to a subscriber from the list.
     * @param s     PresenceSubcription pointer.
196
     */
197
    void removePresSubServer(PresSubServer *s);
198
199
200
201
    /**
     * IP2IP context.
     * Iterate through the subscriber list and send NOTIFY to each.
     */
202
    void notifyPresSubServer();
203

204
205
206
207
208
209
210
211
    /**
     * Lock methods
     */
    void lock();
    void unlock();
    bool tryLock();
    bool isLocked();

212
213
214
215
    pjsip_pres_status pres_status_data; /**< Presence Data.*/
    pj_bool_t       online_status; /**< Our online status.	*/
    pjsip_publishc  *publish_sess;  /**< Client publication session.*/
    pj_bool_t   publish_state; /**< Last published online status.*/
216
    pj_bool_t   enabled; /**< Allow for status publish,*/
217
218

private:
219
    NON_COPYABLE(SIPPresence);
220

221
    SIPAccount * acc_; /**<  Associated SIP account. */
222
223
    std::list< PresSubServer *> pres_sub_server_list_; /**< Subscribers list.*/
    std::list< PresSubClient *> pres_sub_client_list_; /**< Subcribed buddy list.*/
224

225
226
227
    pj_mutex_t	*mutex_;	    /**< Mutex protection for this data	*/
    unsigned	mutex_nesting_level_; /**< Mutex nesting level.	*/
    pj_thread_t	*mutex_owner_; /**< Mutex owner.			*/
228
    pj_caching_pool     cp_;	    /**< Global pool factory.		*/
229
230
    pj_pool_t	*pool_;	    /**< pjsua's private pool.		*/

231

232
233
234
};

#endif