Ring Daemon 16.0.0
Loading...
Searching...
No Matches
sippresence.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 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 "pjsip-simple/rpid.h"
32#include <pj/pool.h>
33
34#define PRESENCE_FUNCTION_PUBLISH 0
35#define PRESENCE_FUNCTION_SUBSCRIBE 1
36#define PRESENCE_LOCK_FLAG 1
37#define PRESENCE_CLIENT_LOCK_FLAG 2
38
39namespace jami {
40
78
79class SIPAccount;
80class PresSubClient;
81class PresSubServer;
82
89{
90public:
100
104 SIPAccount* getAccount() const;
112 int getModId() const;
116 pj_pool_t* getPool() const;
121 void enable(bool enabled);
127 void support(int function, bool enabled);
136 void updateStatus(bool status, const std::string& note);
141 void sendPresence(bool status, const std::string& note);
146 void reportPresSubClientNotification(std::string_view uri, pjsip_pres_status* status);
151 void subscribeClient(const std::string& uri, bool flag);
162
169 void approvePresSubServer(const std::string& uri, bool flag);
186 void notifyPresSubServer();
187
188 bool isEnabled() { return enabled_; }
189
190 bool isSupported(int function);
191
192 const std::list<PresSubClient*>& getClientSubscriptions() const { return sub_client_list_; }
193
194 bool isOnline() { return status_; }
195
196 std::string getNote() { return note_; }
197
198 void lock();
199 bool tryLock();
200 void unlock();
201
202private:
204
205 static pj_status_t publish(SIPPresence* pres);
206 static void publish_cb(struct pjsip_publishc_cbparam* param);
207 static pj_status_t send_publish(SIPPresence* pres);
208
209 pjsip_publishc* publish_sess_;
210 pjsip_pres_status status_data_;
212 pj_bool_t enabled_;
213 pj_bool_t publish_supported_;
214 pj_bool_t subscribe_supported_;
216 bool status_;
217 std::string note_;
218 SIPAccount* acc_;
219 std::list<PresSubServer*> sub_server_list_;
220 std::list<PresSubClient*> sub_client_list_;
222 std::recursive_mutex mutex_;
223 pj_caching_pool cp_;
224 pj_pool_t* pool_;
225};
226
227} // namespace jami
228
229#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 ring_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:54
pjsip_multipart_part multipart_parts
List of multipart parts.
Definition sippresence.h:76
pjsip_hdr hdr_list
Additional message headers as linked list.
Definition sippresence.h:49
pjsip_media_type multipart_ctype
Content type of the multipart body.
Definition sippresence.h:68
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:60