Commit d1f1d98a authored by Patrick Keroulas's avatar Patrick Keroulas

* #36742, presence, manage the server support properly for

* SUBSCRIBE/PUBLISH
parent d9882528
......@@ -61,8 +61,15 @@ PresenceManager::subscribeBuddy(const std::string& accountID, const std::string&
if (!sipaccount)
ERROR("Could not find account %s",accountID.c_str());
else{
DEBUG("%subscribePresence (acc:%s, buddy:%s)",flag? "S":"Uns", accountID.c_str(), uri.c_str());
sipaccount->getPresence()->subscribeClient(uri,flag);
SIPPresence *pres = sipaccount->getPresence();
if (pres)
{
if((pres->isEnabled()) && pres->isSupported(PRESENCE_FUNCTION_SUBSCRIBE))
{
DEBUG("%subscribePresence (acc:%s, buddy:%s)",flag? "S":"Uns", accountID.c_str(), uri.c_str());
pres->subscribeClient(uri,flag);
}
}
}
}
......@@ -77,8 +84,15 @@ PresenceManager::publish(const std::string& accountID, const bool& status, const
if (!sipaccount)
ERROR("Could not find account %s.",accountID.c_str());
else{
DEBUG("Send Presence (acc:%s, status %s).",accountID.c_str(),status? "online":"offline");
sipaccount->getPresence()->sendPresence(status, note);
SIPPresence *pres = sipaccount->getPresence();
if (pres)
{
if((pres->isEnabled()) && pres->isSupported(PRESENCE_FUNCTION_PUBLISH))
{
DEBUG("Send Presence (acc:%s, status %s).",accountID.c_str(),status? "online":"offline");
pres->sendPresence(status, note);
}
}
}
}
......
......@@ -95,6 +95,8 @@ PresSubClient::pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event)
pres_client->getURI().c_str(),
PJ_TRUE);
pres->getAccount()->supportPresence(PRESENCE_FUNCTION_SUBSCRIBE, PJ_TRUE);
} else if (state == PJSIP_EVSUB_STATE_TERMINATED) {
int resub_delay = -1;
pj_strdup_with_null(pres_client->pool_, &pres_client->term_reason_, pjsip_evsub_get_termination_reason(sub));
......@@ -166,12 +168,8 @@ PresSubClient::pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event)
std::string account_host = std::string(pj_gethostname()->ptr, pj_gethostname()->slen);
std::string sub_host = sip_utils::getHostFromUri(pres_client->getURI());
if((!subscribe_allowed) && (account_host == sub_host)
&& pres_client->getPresence()->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)){ // avoid mutiple details reload
if((!subscribe_allowed) && (account_host == sub_host))
pres_client->getPresence()->getAccount()->supportPresence(PRESENCE_FUNCTION_SUBSCRIBE, PJ_FALSE);
Manager::instance().saveConfig();
Manager::instance().getClient()->getConfigurationManager()->accountsChanged();
}
} else if (pjsip_method_cmp(&tsx->method, &pjsip_notify_method) == 0) {
if (pres_client->isTermReason("deactivated") || pres_client->isTermReason("timeout")) {
......
......@@ -45,6 +45,7 @@
#ifdef SFL_PRESENCE
#include "sippresence.h"
#include "client/configurationmanager.h"
#endif
#include <unistd.h>
......@@ -505,6 +506,12 @@ void SIPAccount::unserialize(const Conf::YamlNode &mapNode)
std::string pres;
mapNode.getValue(PRESENCE_ENABLED_KEY, &pres);
enablePresence(pres == Conf::TRUE_STR);
mapNode.getValue(PRESENCE_PUBLISH_SUPPORTED_KEY, &pres);
if (presence_)
presence_->support(PRESENCE_FUNCTION_PUBLISH, pres == Conf::TRUE_STR);
mapNode.getValue(PRESENCE_SUBSCRIBE_SUPPORTED_KEY, &pres);
if (presence_)
presence_->support(PRESENCE_FUNCTION_SUBSCRIBE, pres == Conf::TRUE_STR);
#endif
std::string dtmfType;
......@@ -888,6 +895,7 @@ void SIPAccount::registerVoIPLink()
#ifdef SFL_PRESENCE
getPresence()->subscribeClient(getFromUri(), true); //self presence subscription
getPresence()->sendPresence(true,""); // try to publish whatever the status is.
#endif
}
......@@ -1507,32 +1515,38 @@ SIPPresence * SIPAccount::getPresence() const
void
SIPAccount::enablePresence(const bool& enabled)
{
DEBUG("Presence enable for :%s : %s.",
DEBUG("Presence enable for %s : %s.",
accountID_.c_str(),
enabled? Conf::TRUE_STR : Conf::FALSE_STR);
if (presence_){
if (presence_)
presence_->enable(enabled);
if(enabled)// try to publish and subscribe by default when presence is enabled
{
supportPresence(PRESENCE_FUNCTION_PUBLISH, enabled);
supportPresence(PRESENCE_FUNCTION_SUBSCRIBE, enabled);
}
}
}
/**
* Enable the presence function (PUBLISH/SUBSCRIBE)
* Set the presence (PUBLISH/SUBSCRIBE) support flags
* and process the change.
*/
void
SIPAccount::supportPresence(int function, const bool& enabled)
{
DEBUG("Presence support for :%s (%s: %s).",
if(getPresence()->isSupported(function) == enabled)
return;
DEBUG("Presence support for %s (%s: %s).",
accountID_.c_str(),
(function==PRESENCE_FUNCTION_PUBLISH)? "publish" : "subscribe",
enabled? Conf::TRUE_STR : Conf::FALSE_STR);
if (presence_)
presence_->support(function, enabled);
// force presence to disable when nothing is supported
if(!(getPresence()->isSupported(PRESENCE_FUNCTION_PUBLISH)) &&
!(getPresence()->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)))
enablePresence(false);
Manager::instance().saveConfig();
Manager::instance().getClient()->getConfigurationManager()->accountsChanged();
}
#endif
......
......@@ -180,8 +180,8 @@ void SIPPresence::sendPresence(bool status, const std::string &note)
{
updateStatus(status, note);
if ((not publish_supported_) or (not enabled_))
return;
//if ((not publish_supported_) or (not enabled_))
// return;
if (acc_->isIP2IP())
notifyPresSubServer(); // to each subscribers
......@@ -210,14 +210,15 @@ void SIPPresence::reportPresSubClientNotification(const std::string& uri, pjsip_
void SIPPresence::subscribeClient(const std::string& uri, bool flag)
{
std::string account_host = std::string(pj_gethostname()->ptr, pj_gethostname()->slen);
std::string sub_host = sip_utils::getHostFromUri(uri);
/* if an account has a server that doesn't support SUBSCRIBE, it's still possible
* to subscribe to someone on another server */
/*
std::string account_host = std::string(pj_gethostname()->ptr, pj_gethostname()->slen);
std::string sub_host = sip_utils::getHostFromUri(uri);
if (((not subscribe_supported_) && (account_host == sub_host))
or (not enabled_))
return;
*/
/* Check if the buddy was already subscribed */
for (const auto & c : sub_client_list_) {
......@@ -400,8 +401,6 @@ SIPPresence::publish_cb(struct pjsip_publishc_cbparam *param)
"Publish not supported.");
pres->getAccount()->supportPresence(PRESENCE_FUNCTION_PUBLISH, PJ_FALSE);
Manager::instance().saveConfig();
Manager::instance().getClient()->getConfigurationManager()->accountsChanged();
}
} else {
......@@ -412,6 +411,8 @@ SIPPresence::publish_cb(struct pjsip_publishc_cbparam *param)
pjsip_publishc_destroy(param->pubc);
pres->publish_sess_ = NULL;
}
pres->getAccount()->supportPresence(PRESENCE_FUNCTION_PUBLISH, PJ_TRUE);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment