23#include <pjsip/sip_module.h>
24#include <pjsip/sip_types.h>
25#include <pjsip/sip_event.h>
26#include <pjsip/sip_transaction.h>
27#include <pjsip/sip_dialog.h>
28#include <pjsip/sip_endpoint.h>
33#include <pjsip/sip_ua_layer.h>
34#include <pjsip-simple/evsub.h>
53int PresSubClient::modId_ = 0;
58 PresSubClient* c = (PresSubClient*)
entry->user_data;
59 JAMI_DBG(
"timeout for %.*s", (
int) c->getURI().size(), c->getURI().data());
76 JAMI_DBG(
"Subscription for pres_client '%.*s' is '%s'",
109 std::ostringstream
os;
116 switch (
tsx->status_code) {
129 msg =
"Bad subscribe refresh.";
134 msg =
"Subscribe context not set for this buddy.";
139 msg =
"Subscribe not allowed for this buddy.";
144 msg =
"Wrong server.";
200 msg =
event->body.tsx_state.src.rdata->msg_info.msg;
249 JAMI_WARN(
"Unable to find pres_client.");
296 JAMI_WARN(
"Unable to find pres_client from ev_sub.");
341 JAMI_DBG(
"Destroying pres_client object with uri %.*s", (
int) uri_.slen, uri_.ptr);
356 return {uri_.ptr, (
size_t) uri_.slen};
368 return status_.info[0].basic_open;
374 return {status_.info[0].rpid.note.ptr, (
size_t) status_.info[0].rpid.note.slen};
378PresSubClient::isTermReason(
const std::string&
reason)
380 const std::string_view
myReason(term_reason_.ptr, (
size_t) term_reason_.slen);
395 JAMI_WARN(
"pres_client %.*s will resubscribe in %u ms (reason: %.*s)",
399 (
int) term_reason_.slen,
422PresSubClient::reportPresence()
433 for (
i = 0;
i < 50;
i++) {
436 std::this_thread::sleep_for(std::chrono::milliseconds(
i / 10));
450 std::this_thread::sleep_for(std::chrono::milliseconds(
i / 10));
458 if (lock_flag_ == 0) {
459 JAMI_DBG(
"pres_client failed to lock : timeout");
487 JAMI_WARN(
"PresSubClient already unsubscribed.");
493 JAMI_WARN(
"pres_client already unsubscribed sub=TERMINATED.");
500 JAMI_WARN(
"pres_client %.*s: unsubscribing..", (
int) uri_.slen, uri_.ptr);
527 JAMI_DBG(
"PreseSubClient %.*s: already subscribed. Refresh it.", (
int) uri_.slen, uri_.ptr);
538 pres_callback.on_tsx_state = &pres_client_evsub_on_tsx_state;
539 pres_callback.on_rx_notify = &pres_client_evsub_on_rx_notify;
542 JAMI_DBG(
"PresSubClient %.*s: subscribing ", (
int) uri_.slen, uri_.ptr);
549 JAMI_ERR(
"Unable to create dialog \n");
559 JAMI_ERR(
"Unable to initialize credentials for subscribe session authentication");
571 JAMI_WARN(
"Unable to create presence client (%d)", status);
589 JAMI_ERR(
"Unable to initialize credentials for invite session authentication");
608 JAMI_WARN(
"Unable to create initial SUBSCRIBE (%d)", status);
622 JAMI_WARN(
"Unable to send initial SUBSCRIBE (%d)", status);
633 return (
b->getURI() ==
getURI());
static LIBJAMI_TEST_EXPORT Manager & instance()
void enable(bool flag)
Enable the monitoring and report signal to the client.
bool isPresent()
Is the buddy present.
PresSubClient(const std::string &uri, SIPPresence *pres)
Constructor.
bool unsubscribe()
Send a SUBCRIBE to the PXB or directly to a pres_client in the IP2IP context but the 0s timeout make ...
bool match(PresSubClient *b)
Compare with another pres_client's uris.
bool isSubscribed()
Return the monitor variable.
bool lock()
Data lock function.
bool subscribe()
Send a SUBCRIBE to the PXB or directly to a pres_client in the IP2IP context.
std::string_view getURI()
Return the pres_client URI.
void unlock()
Data unlock function.
std::string_view getLineStatus()
A message from the URIs.
~PresSubClient()
Destructor.
SIPPresence * getPresence()
Get associated parent presence_module.
const pjsip_cred_info * getCredInfo() const
unsigned getCredentialCount() const
Get the number of credentials defined for this account.
bool hasServiceRoute() const
bool hasCredentials() const
std::string getFromUri() const override
std::string getServiceRoute() const
pjsip_regc * getRegistrationInfo()
Get the registration structure that is used for PJSIP in the registration process.
void fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data)
Fill xml document, the header and the body.
void reportPresSubClientNotification(std::string_view uri, pjsip_pres_status *status)
Send a signal to the client on DBus.
SIPAccount * getAccount() const
Return associated sipaccount.
void addPresSubClient(PresSubClient *b)
Add a buddy in the buddy list.
pj_pool_t * getPool() const
Return a pool for generic functions.
#define JAMI_WARNING(formatstr,...)
std::string_view getHostFromUri(std::string_view uri)
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)
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_LOCK_FLAG
#define PRESENCE_CLIENT_LOCK_FLAG
Specific VoIPLink for SIP (SIP core for incoming and outgoing events).