2
* Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
4
* Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com>
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.
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.
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.
20
* Additional permission under GNU GPL version 3 section 7:
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.
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"
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
52
struct pres_msg_data {
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.
62
* MIME type of optional message body.
64
pj_str_t content_type;
67
* Optional message body to be added to the message, only when the
68
* message doesn't have a body.
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.
78
pjsip_media_type multipart_ctype;
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.
86
pjsip_multipart_part multipart_parts;
97
struct pj_caching_pool;
101
* @file sippresence.h
102
* @brief A SIP Presence manages buddy subscription in both PBX and IP2IP contexts.
111
* @param acc the associated sipaccount
113
SIPPresence(SIPAccount * acc);
120
* Return associated sipaccount
122
SIPAccount * getAccount() const;
124
* Return presence data.
126
pjsip_pres_status * getStatus();
128
* Return presence module ID which is actually the same as the VOIP link
130
int getModId() const;
132
* Return a pool for generic functions.
134
pj_pool_t* getPool() const;
136
* Activate the module.
139
void enable(bool enabled);
141
* Support the presence function publish/subscribe.
142
* @param function Publish or subscribe to enable
145
void support(int function, bool enabled);
147
* Fill xml document, the header and the body
149
void fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data);
151
* Modify the presence data
152
* @param status is basically "open" or "close"
154
void updateStatus(bool status, const std::string ¬e);
156
* Send the presence data in a PUBLISH to the PBX or in a NOTIFY
157
* to a remote subscriber (IP2IP)
159
void sendPresence(bool status, const std::string ¬e);
161
* Send a signal to the client on DBus. The signal contain the status
164
void reportPresSubClientNotification(const std::string& uri, pjsip_pres_status * status);
166
* Send a SUBSCRIBE request to PBX/IP2IP
167
* @param buddyUri Remote user that we want to subscribe
169
void subscribeClient(const std::string& uri, bool flag);
171
* Add a buddy in the buddy list.
172
* @param b PresSubClient pointer
174
void addPresSubClient(PresSubClient *b);
176
* Remove a buddy from the list.
177
* @param b PresSubClient pointer
179
void removePresSubClient(PresSubClient *b);
183
* Process new subscription based on client decision.
184
* @param flag client decision.
185
* @param uri uri of the remote subscriber
187
void approvePresSubServer(const std::string& uri, bool flag);
190
* Add a server associated to a subscriber in the list.
191
* @param s PresenceSubcription pointer.
193
void addPresSubServer(PresSubServer *s);
196
* Remove a server associated to a subscriber from the list.
197
* @param s PresenceSubcription pointer.
199
void removePresSubServer(PresSubServer *s);
202
* Iterate through the subscriber list and send NOTIFY to each.
204
void notifyPresSubServer();
210
bool isSupported(int function);
212
std::list< PresSubClient *> getClientSubscriptions() {
213
return sub_client_list_;
220
std::string getNote(){
229
NON_COPYABLE(SIPPresence);
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);
235
pjsip_publishc *publish_sess_; /**< Client publication session.*/
236
pjsip_pres_status status_data_; /**< Presence Data to be published.*/
239
pj_bool_t publish_supported_; /**< the server allow for status publishing */
240
pj_bool_t subscribe_supported_; /**< the server allow for buddy subscription */
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.*/
249
unsigned mutex_nesting_level_;
250
pj_thread_t *mutex_owner_;