30#include <opendht/crypto.h>
33#define MAX_N_SUB_SERVER 50
34#define MAX_N_SUB_CLIENT 50
44 , publish_supported_(
false)
45 , subscribe_supported_(
false)
58 throw std::runtime_error(
"Unable to allocate pool for presence");
71 sub_client_list_.clear();
72 sub_server_list_.clear();
121 return publish_supported_;
123 return subscribe_supported_;
138 else if (
note ==
"busy")
145 pj_bzero(&status_data_,
sizeof(status_data_));
146 status_data_.info_cnt = 1;
147 status_data_.info[0].basic_open = status;
177 const std::string
note(status->info[0].rpid.note.ptr, status->info[0].rpid.note.slen);
178 JAMI_DBG(
" Received status of PresSubClient %.*s(acc:%s): status=%s note=%s",
182 status->info[0].basic_open ?
"open" :
"closed",
187 status_ = status->info[0].basic_open;
193 status->info[0].basic_open,
211 for (
const auto& c : sub_client_list_) {
212 if (c->getURI() == uri) {
223 JAMI_WARN(
"Unable to add PresSubClient, max number reached.");
241 sub_client_list_.push_back(c);
242 JAMI_DBG(
"New Presence_subscription_client added (list[%zu]).", sub_client_list_.size());
244 JAMI_WARN(
"Max Presence_subscription_client is reach.");
252 JAMI_DBG(
"Remove Presence_subscription_client from the buddy list.");
253 sub_client_list_.remove(c);
259 for (
const auto& s : sub_server_list_) {
260 if (s->matches((
char*) uri.c_str())) {
271 sub_server_list_.push_back(s);
273 JAMI_WARN(
"Max Presence_subscription_server is reach.");
281 sub_server_list_.remove(s);
282 JAMI_DBG(
"Presence_subscription_server removed");
288 JAMI_DBG(
"Iterating through IP2IP Presence_subscription_server:");
290 for (
const auto& s : sub_server_list_)
303 return mutex_.try_lock();
339 constexpr pj_str_t type = CONST_PJ_STR(
"application");
342 tdata->msg->body = body;
354 SIPPresence*
pres = (SIPPresence*)
param->token;
366 }
else if (
param->code == 412) {
373 JAMI_WARN(
"Client (PUBLISH) failed (%s)", error.c_str());
377 "Publish not supported.");
383 if (
param->expiration < 1) {
399SIPPresence::send_publish(SIPPresence*
pres)
404 JAMI_DBG(
"Send PUBLISH (%s).",
pres->getAccount()->getAccountID().c_str());
406 SIPAccount* acc =
pres->getAccount();
418 JAMI_ERR(
"Error creating PUBLISH request %d", status);
443 JAMI_ERR(
"Error creating PIDF for PUBLISH request");
459 JAMI_WARN(
"Previous request is in progress, ");
461 JAMI_ERR(
"Error sending PUBLISH request");
469 if (
pres->publish_sess_) {
479SIPPresence::publish(SIPPresence*
pres)
483 SIPAccount* acc =
pres->getAccount();
493 JAMI_ERR(
"Failed to create a publish session.");
502 JAMI_ERR(
"Failed to init a publish session");
508 if (acc->hasCredentials()
510 static_cast<int>(acc->getCredentialCount()),
513 JAMI_ERR(
"Unable to initialize credentials for invite session authentication");
520 if (
regc and acc->hasServiceRoute())
524 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).