Ring Daemon
Loading...
Searching...
No Matches
sippresence.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef SIPPRESENCE_H
19#define SIPPRESENCE_H
20
21#include <string>
22#include <list>
23#include <mutex>
24
25#include "noncopyable.h"
26#include "pjsip/sip_types.h"
27#include "pjsip/sip_msg.h"
28#include "pjsip/sip_multipart.h"
29#include "pjsip-simple/publish.h"
30#include "pjsip-simple/presence.h"
31#include <pj/pool.h>
32
33#define PRESENCE_FUNCTION_PUBLISH 0
34#define PRESENCE_FUNCTION_SUBSCRIBE 1
35#define PRESENCE_LOCK_FLAG 1
36#define PRESENCE_CLIENT_LOCK_FLAG 2
37
38namespace jami {
39
77
78class SIPAccount;
79class PresSubClient;
80class PresSubServer;
81
88{
89public:
99
103 SIPAccount* getAccount() const;
111 int getModId() const;
115 pj_pool_t* getPool() const;
120 void enable(bool enabled);
126 void support(int function, bool enabled);
135 void updateStatus(bool status, const std::string& note);
140 void sendPresence(bool status, const std::string& note);
145 void reportPresSubClientNotification(std::string_view uri, pjsip_pres_status* status);
150 void subscribeClient(const std::string& uri, bool flag);
161
168 void approvePresSubServer(const std::string& uri, bool flag);
185 void notifyPresSubServer();
186
187 bool isEnabled() { return enabled_; }
188
189 bool isSupported(int function);
190
191 const std::list<PresSubClient*>& getClientSubscriptions() const { return sub_client_list_; }
192
193 bool isOnline() { return status_; }
194
195 std::string getNote() { return note_; }
196
197 void lock();
198 bool tryLock();
199 void unlock();
200
201private:
203
204 static pj_status_t publish(SIPPresence* pres);
205 static void publish_cb(struct pjsip_publishc_cbparam* param);
206 static pj_status_t send_publish(SIPPresence* pres);
207
208 pjsip_publishc* publish_sess_;
209 pjsip_pres_status status_data_;
211 pj_bool_t enabled_;
212 pj_bool_t publish_supported_;
213 pj_bool_t subscribe_supported_;
215 bool status_;
216 std::string note_;
217 SIPAccount* acc_;
218 std::list<PresSubServer*> sub_server_list_;
219 std::list<PresSubClient*> sub_client_list_;
221 std::recursive_mutex mutex_;
222 pj_caching_pool cp_;
223 pj_pool_t* pool_;
224};
225
226} // namespace jami
227
228#endif
int getModId() const
Return presence module ID which is actually the same as the VOIP link.
~SIPPresence()
Destructor.
pjsip_pres_status * getStatus()
Return presence data.
void fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data)
Fill xml document, the header and the body.
void approvePresSubServer(const std::string &uri, bool flag)
IP2IP context.
void reportPresSubClientNotification(std::string_view uri, pjsip_pres_status *status)
Send a signal to the client on DBus.
void updateStatus(bool status, const std::string &note)
Modify the presence data.
void removePresSubServer(PresSubServer *s)
IP2IP context.
void subscribeClient(const std::string &uri, bool flag)
Send a SUBSCRIBE request to PBX/IP2IP.
const std::list< PresSubClient * > & getClientSubscriptions() const
void removePresSubClient(PresSubClient *b)
Remove a buddy from the list.
bool isSupported(int function)
SIPAccount * getAccount() const
Return associated sipaccount.
void enable(bool enabled)
Activate the module.
void notifyPresSubServer()
IP2IP context.
void addPresSubClient(PresSubClient *b)
Add a buddy in the buddy list.
pj_pool_t * getPool() const
Return a pool for generic functions.
void sendPresence(bool 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 addPresSubServer(PresSubServer *s)
IP2IP context.
std::string getNote()
void support(int function, bool enabled)
Support the presence function publish/subscribe.
void emitSignal(Args... args)
Definition jami_signal.h:64
Simple macro to hide class' copy constructor and assignment operator.
#define NON_COPYABLE(ClassName)
Definition noncopyable.h:30
pj_str_t content_type
MIME type of optional message body.
Definition sippresence.h:53
pjsip_multipart_part multipart_parts
List of multipart parts.
Definition sippresence.h:75
pjsip_hdr hdr_list
Additional message headers as linked list.
Definition sippresence.h:48
pjsip_media_type multipart_ctype
Content type of the multipart body.
Definition sippresence.h:67
pj_str_t msg_body
Optional message body to be added to the message, only when the message doesn't have a body.
Definition sippresence.h:59