30#include <opendht/crypto.h>
36#define MAX_N_SUB_SERVER 50
37#define MAX_N_SUB_CLIENT 50
47 , publish_supported_(
false)
48 , subscribe_supported_(
false)
61 throw std::runtime_error(
"Unable to allocate pool for presence");
74 sub_client_list_.clear();
75 sub_server_list_.clear();
124 return publish_supported_;
126 return subscribe_supported_;
144 else if (
note ==
"busy")
151 pj_bzero(&status_data_,
sizeof(status_data_));
152 status_data_.info_cnt = 1;
153 status_data_.info[0].basic_open = status;
183 const std::string
note(status->info[0].rpid.note.ptr, status->info[0].rpid.note.slen);
184 JAMI_DBG(
" Received status of PresSubClient %.*s(acc:%s): status=%s note=%s",
185 (
int)uri.size(), uri.data(),
187 status->info[0].basic_open ?
"open" :
"closed",
192 status_ = status->info[0].basic_open;
198 status->info[0].basic_open,
216 for (
const auto& c : sub_client_list_) {
217 if (c->getURI() == uri) {
228 JAMI_WARN(
"Unable to add PresSubClient, max number reached.");
246 sub_client_list_.push_back(c);
247 JAMI_DBG(
"New Presence_subscription_client added (list[%zu]).", sub_client_list_.size());
249 JAMI_WARN(
"Max Presence_subscription_client is reach.");
257 JAMI_DBG(
"Remove Presence_subscription_client from the buddy list.");
258 sub_client_list_.remove(c);
264 for (
const auto& s : sub_server_list_) {
265 if (s->matches((
char*) uri.c_str())) {
276 sub_server_list_.push_back(s);
278 JAMI_WARN(
"Max Presence_subscription_server is reach.");
286 sub_server_list_.remove(s);
287 JAMI_DBG(
"Presence_subscription_server removed");
293 JAMI_DBG(
"Iterating through IP2IP Presence_subscription_server:");
295 for (
const auto& s : sub_server_list_)
308 return mutex_.try_lock();
346 constexpr pj_str_t type = CONST_PJ_STR(
"application");
349 tdata->msg->body = body;
361 SIPPresence*
pres = (SIPPresence*)
param->token;
375 }
else if (
param->code == 412) {
383 JAMI_WARN(
"Client (PUBLISH) failed (%s)", error.c_str());
387 "Publish not supported.");
393 if (
param->expiration < 1) {
409SIPPresence::send_publish(SIPPresence*
pres)
414 JAMI_DBG(
"Send PUBLISH (%s).",
pres->getAccount()->getAccountID().c_str());
416 SIPAccount* acc =
pres->getAccount();
432 JAMI_ERR(
"Error creating PUBLISH request %d", status);
457 JAMI_ERR(
"Error creating PIDF for PUBLISH request");
473 JAMI_WARN(
"Previous request is in progress, ");
475 JAMI_ERR(
"Error sending PUBLISH request");
483 if (
pres->publish_sess_) {
493SIPPresence::publish(SIPPresence*
pres)
497 SIPAccount* acc =
pres->getAccount();
507 JAMI_ERR(
"Failed to create a publish session.");
516 JAMI_ERR(
"Failed to init a publish session");
522 if (acc->hasCredentials()
524 acc->getCredentialCount(),
527 JAMI_ERR(
"Unable to initialize credentials for invite session authentication");
534 if (
regc and acc->hasServiceRoute())
539 status = send_publish(
pres);
const std::string & getAccountID() const
Get the account ID.
const std::string & getUserAgentName()
Get the user-agent.
static LIBJAMI_TEST_EXPORT Manager & instance()
SIPVoIPLink & sipVoIPLink() const
bool subscribe()
Send a SUBCRIBE to the PXB or directly to a pres_client in the IP2IP context.
bool isIP2IP() const override
Returns true if this is the IP2IP account.
std::string getFromUri() const override
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 ¬e)
Modify the presence data.
SIPPresence(SIPAccount *acc)
Constructor.
void removePresSubServer(PresSubServer *s)
IP2IP context.
void subscribeClient(const std::string &uri, bool flag)
Send a SUBSCRIBE request to PBX/IP2IP.
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 ¬e)
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.
void support(int function, bool enabled)
Support the presence function publish/subscribe.
pjsip_endpoint * getEndpoint()
pjsip_route_hdr * createRouteSet(const std::string &route, pj_pool_t *hdr_pool)
constexpr std::string_view as_view(const pj_str_t &str) noexcept
constexpr const pj_str_t CONST_PJ_STR(T(&a)[N]) noexcept
void emitSignal(Args... args)
static const pjsip_publishc_opt my_publish_opt
A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink)
A SIP Presence manages buddy subscription in both PBX and IP2IP contexts.
#define PRESENCE_FUNCTION_SUBSCRIBE
#define PRESENCE_FUNCTION_PUBLISH
Specific VoIPLink for SIP (SIP core for incoming and outgoing events).