Skip to content
Snippets Groups Projects
Commit 8ee06563 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

presence: use string_view

Change-Id: Ib051f426235aab617b300c4e45a7d2e1e4e991a9
parent 37d31306
Branches
No related tags found
No related merge requests found
......@@ -128,10 +128,9 @@ getSubscriptions(const std::string& accountID)
ret.reserve(subs.size());
for (const auto& s : subs) {
ret.push_back(
{{DRing::Presence::BUDDY_KEY, s->getURI()},
{DRing::Presence::STATUS_KEY,
s->isPresent() ? DRing::Presence::ONLINE_KEY : DRing::Presence::OFFLINE_KEY},
{DRing::Presence::LINESTATUS_KEY, s->getLineStatus()}});
{{DRing::Presence::BUDDY_KEY, std::string(s->getURI())},
{DRing::Presence::STATUS_KEY, s->isPresent() ? DRing::Presence::ONLINE_KEY : DRing::Presence::OFFLINE_KEY},
{DRing::Presence::LINESTATUS_KEY, std::string(s->getLineStatus())}});
}
} else
JAMI_ERR("Presence not initialized");
......
......@@ -56,7 +56,7 @@ void
PresSubClient::pres_client_timer_cb(pj_timer_heap_t* /*th*/, pj_timer_entry* entry)
{
PresSubClient* c = (PresSubClient*) entry->user_data;
JAMI_DBG("timeout for %s", c->getURI().c_str());
JAMI_DBG("timeout for %.*s", (int)c->getURI().size(), c->getURI().data());
}
/* Callback called when *client* subscription state has changed. */
......@@ -73,8 +73,8 @@ PresSubClient::pres_client_evsub_on_state(pjsip_evsub* sub, pjsip_event* event)
return;
}
JAMI_DBG("Subscription for pres_client '%s' is '%s'",
pres_client->getURI().c_str(),
JAMI_DBG("Subscription for pres_client '%.*s' is '%s'",
(int)pres_client->getURI().size(), pres_client->getURI().data(),
pjsip_evsub_get_state_name(sub) ? pjsip_evsub_get_state_name(sub) : "null");
pjsip_evsub_state state = pjsip_evsub_get_state(sub);
......@@ -85,7 +85,7 @@ PresSubClient::pres_client_evsub_on_state(pjsip_evsub* sub, pjsip_event* event)
pres_client->enable(true);
emitSignal<DRing::PresenceSignal::SubscriptionStateChanged>(pres->getAccount()
->getAccountID(),
pres_client->getURI().c_str(),
std::string(pres_client->getURI()),
PJ_TRUE);
pres->getAccount()->supportPresence(PRESENCE_FUNCTION_SUBSCRIBE, true);
......@@ -98,7 +98,7 @@ PresSubClient::pres_client_evsub_on_state(pjsip_evsub* sub, pjsip_event* event)
emitSignal<DRing::PresenceSignal::SubscriptionStateChanged>(pres->getAccount()
->getAccountID(),
pres_client->getURI().c_str(),
std::string(pres_client->getURI()),
PJ_FALSE);
pres_client->term_code_ = 200;
......@@ -112,8 +112,7 @@ PresSubClient::pres_client_evsub_on_state(pjsip_evsub* sub, pjsip_event* event)
std::ostringstream os;
os << pres_client->term_code_;
const std::string error = os.str() + "/"
+ std::string(pres_client->term_reason_.ptr,
pres_client->term_reason_.slen);
+ sip_utils::as_view(pres_client->term_reason_);
std::string msg;
bool subscribe_allowed = PJ_FALSE;
......@@ -158,9 +157,8 @@ PresSubClient::pres_client_evsub_on_state(pjsip_evsub* sub, pjsip_event* event)
emitSignal<DRing::PresenceSignal::ServerError>(
pres_client->getPresence()->getAccount()->getAccountID(), error, msg);
std::string account_host = std::string(pj_gethostname()->ptr,
pj_gethostname()->slen);
std::string sub_host = sip_utils::getHostFromUri(pres_client->getURI());
auto account_host = sip_utils::as_view(*pj_gethostname());
auto sub_host = sip_utils::getHostFromUri(pres_client->getURI());
if (not subscribe_allowed and account_host == sub_host)
pres_client->getPresence()
......@@ -363,11 +361,10 @@ PresSubClient::isSubscribed()
return monitored_;
}
std::string
std::string_view
PresSubClient::getURI()
{
std::string res(uri_.ptr, uri_.slen);
return res;
return {uri_.ptr, (size_t)uri_.slen};
}
SIPPresence*
......@@ -382,16 +379,16 @@ PresSubClient::isPresent()
return status_.info[0].basic_open;
}
std::string
std::string_view
PresSubClient::getLineStatus()
{
return std::string(status_.info[0].rpid.note.ptr, status_.info[0].rpid.note.slen);
return {status_.info[0].rpid.note.ptr, (size_t)status_.info[0].rpid.note.slen};
}
bool
PresSubClient::isTermReason(const std::string& reason)
{
const std::string myReason(term_reason_.ptr, term_reason_.slen);
const std::string_view myReason(term_reason_.ptr, (size_t)term_reason_.slen);
return not myReason.compare(reason);
}
......@@ -429,7 +426,7 @@ PresSubClient::rescheduleTimer(bool reschedule, unsigned msec)
void
PresSubClient::enable(bool flag)
{
JAMI_DBG("pres_client %s is %s monitored.", getURI().c_str(), flag ? "" : "NOT");
JAMI_DBG("pres_client %.*s is %s monitored.", (int)getURI().size(), getURI().data(), flag ? "" : "NOT");
if (flag and not monitored_)
pres_->addPresSubClient(this);
monitored_ = flag;
......
......@@ -89,7 +89,7 @@ public:
/**
* Return the pres_client URI
*/
std::string getURI();
std::string_view getURI();
/**
* Is the buddy present
......@@ -99,7 +99,7 @@ public:
/**
* A message from the URIs
*/
std::string getLineStatus();
std::string_view getLineStatus();
/**
* TODO: explain this:
......
......@@ -159,19 +159,18 @@ stripSipUriPrefix(std::string_view sipUri)
return sipUri;
}
std::string
getHostFromUri(const std::string& sipUri)
std::string_view
getHostFromUri(std::string_view uri)
{
std::string hostname(sipUri);
size_t found = hostname.find('@');
if (found != std::string::npos)
hostname.erase(0, found + 1);
auto found = uri.find('@');
if (found != std::string_view::npos)
uri = uri.substr(found + 1);
found = hostname.find('>');
if (found != std::string::npos)
hostname.erase(found, 1);
found = uri.find('>');
if (found != std::string_view::npos)
uri = uri.substr(0, found);
return hostname;
return uri;
}
void
......
......@@ -96,7 +96,7 @@ std::string parseDisplayName(const pjsip_name_addr* sip_name_addr);
std::string parseDisplayName(const pjsip_from_hdr* header);
std::string parseDisplayName(const pjsip_contact_hdr* header);
std::string getHostFromUri(const std::string& sipUri);
std::string_view getHostFromUri(std::string_view sipUri);
void addContactHeader(const pj_str_t* contactStr, pjsip_tx_data* tdata);
void addUserAgenttHeader(const std::string& userAgent, pjsip_tx_data* tdata);
......
......@@ -178,16 +178,15 @@ SIPPresence::sendPresence(bool status, const std::string& note)
}
void
SIPPresence::reportPresSubClientNotification(const std::string& uri, pjsip_pres_status* status)
SIPPresence::reportPresSubClientNotification(std::string_view uri, pjsip_pres_status* status)
{
/* Update our info. See pjsua_buddy_get_info() for additionnal ideas*/
const std::string acc_ID = acc_->getAccountID();
const std::string basic(status->info[0].basic_open ? "open" : "closed");
const std::string& acc_ID = acc_->getAccountID();
const std::string note(status->info[0].rpid.note.ptr, status->info[0].rpid.note.slen);
JAMI_DBG(" Received status of PresSubClient %s(acc:%s): status=%s note=%s",
uri.c_str(),
JAMI_DBG(" Received status of PresSubClient %.*s(acc:%s): status=%s note=%s",
(int)uri.size(), uri.data(),
acc_ID.c_str(),
basic.c_str(),
status->info[0].basic_open ? "open" : "closed",
note.c_str());
if (uri == acc_->getFromUri()) {
......@@ -197,7 +196,7 @@ SIPPresence::reportPresSubClientNotification(const std::string& uri, pjsip_pres_
}
// report status to client signal
emitSignal<DRing::PresenceSignal::NewBuddyNotification>(acc_ID,
uri,
std::string(uri),
status->info[0].basic_open,
note);
}
......
......@@ -146,7 +146,7 @@ public:
* Send a signal to the client on DBus. The signal contain the status
* of a remote user.
*/
void reportPresSubClientNotification(const std::string& uri, pjsip_pres_status* status);
void reportPresSubClientNotification(std::string_view uri, pjsip_pres_status* status);
/**
* Send a SUBSCRIBE request to PBX/IP2IP
* @param buddyUri Remote user that we want to subscribe
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment