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'",
112 std::ostringstream
os;
114 const std::string error =
os.str() +
"/"
120 switch (
tsx->status_code) {
133 msg =
"Bad subscribe refresh.";
138 msg =
"Subscribe context not set for this buddy.";
143 msg =
"Subscribe not allowed for this buddy.";
148 msg =
"Wrong server.";
158 pres_client->getPresence()->getAccount()->getAccountID(), error,
msg);
204 msg =
event->body.tsx_state.src.rdata->msg_info.msg;
257 JAMI_WARN(
"Unable to find pres_client.");
307 JAMI_WARN(
"Unable to find pres_client from ev_sub.");
352 JAMI_DBG(
"Destroying pres_client object with uri %.*s", (
int) uri_.slen, uri_.ptr);
367 return {uri_.ptr, (
size_t)uri_.slen};
379 return status_.info[0].basic_open;
385 return {status_.info[0].rpid.note.ptr, (
size_t)status_.info[0].rpid.note.slen};
389PresSubClient::isTermReason(
const std::string&
reason)
391 const std::string_view
myReason(term_reason_.ptr, (
size_t)term_reason_.slen);
396PresSubClient::rescheduleTimer(
bool reschedule,
unsigned msec)
406 JAMI_WARN(
"pres_client %.*s will resubscribe in %u ms (reason: %.*s)",
410 (
int) term_reason_.slen,
436PresSubClient::reportPresence()
447 for (
i = 0;
i < 50;
i++) {
450 std::this_thread::sleep_for(std::chrono::milliseconds(
i / 10));
464 std::this_thread::sleep_for(std::chrono::milliseconds(
i / 10));
472 if (lock_flag_ == 0) {
473 JAMI_DBG(
"pres_client failed to lock : timeout");
501 JAMI_WARN(
"PresSubClient already unsubscribed.");
507 JAMI_WARN(
"pres_client already unsubscribed sub=TERMINATED.");
514 JAMI_WARN(
"pres_client %.*s: unsubscribing..", (
int) uri_.slen, uri_.ptr);
541 JAMI_DBG(
"PreseSubClient %.*s: already subscribed. Refresh it.", (
int) uri_.slen, uri_.ptr);
552 pres_callback.on_tsx_state = &pres_client_evsub_on_tsx_state;
553 pres_callback.on_rx_notify = &pres_client_evsub_on_rx_notify;
556 JAMI_DBG(
"PresSubClient %.*s: subscribing ", (
int) uri_.slen, uri_.ptr);
563 JAMI_ERR(
"Unable to create dialog \n");
573 JAMI_ERR(
"Unable to initialize credentials for subscribe session authentication");
585 JAMI_WARN(
"Unable to create presence client (%d)", status);
603 JAMI_ERR(
"Unable to initialize credentials for invite session authentication");
624 JAMI_WARN(
"Unable to create initial SUBSCRIBE (%d)", status);
638 JAMI_WARN(
"Unable to send initial SUBSCRIBE (%d)", status);
649 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.
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).