Skip to content
Snippets Groups Projects
Commit 6eb9a6f6 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #29736: presence: cleanup

parent 23d95cfe
Branches
Tags
No related merge requests found
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
SIPPresence::SIPPresence(SIPAccount *acc) SIPPresence::SIPPresence(SIPAccount *acc)
: pres_status_data() : pres_status_data()
, publish_sess() , publish_sess()
, enabled(true) , enabled_(true)
, acc_(acc) , acc_(acc)
, pres_sub_server_list_() //IP2IP context , pres_sub_server_list_() //IP2IP context
, pres_sub_client_list_() , pres_sub_client_list_()
...@@ -71,42 +71,51 @@ SIPPresence::SIPPresence(SIPAccount *acc) ...@@ -71,42 +71,51 @@ SIPPresence::SIPPresence(SIPAccount *acc)
} }
SIPPresence::~SIPPresence(){ SIPPresence::~SIPPresence()
{
/* Flush the lists */ /* Flush the lists */
for (auto c : pres_sub_client_list_) for (auto c : pres_sub_client_list_)
removePresSubClient(c) ; removePresSubClient(c) ;
for (auto s : pres_sub_server_list_) for (auto s : pres_sub_server_list_)
removePresSubServer(s); removePresSubServer(s);
} }
SIPAccount * SIPPresence::getAccount() const { SIPAccount * SIPPresence::getAccount() const
{
return acc_; return acc_;
} }
pjsip_pres_status * SIPPresence::getStatus() { pjsip_pres_status * SIPPresence::getStatus()
{
return &pres_status_data; return &pres_status_data;
} }
int SIPPresence::getModId() const { int SIPPresence::getModId() const
{
return ((SIPVoIPLink*)(acc_->getVoIPLink()))->getModId(); return ((SIPVoIPLink*)(acc_->getVoIPLink()))->getModId();
} }
pj_pool_t* SIPPresence::getPool() const { pj_pool_t* SIPPresence::getPool() const
{
return pool_; return pool_;
} }
void SIPPresence::enable(const bool& flag){ void SIPPresence::enable(const bool& flag)
enabled = flag; {
enabled_ = flag;
} }
void SIPPresence::updateStatus(const bool& status, const std::string &note){ void SIPPresence::updateStatus(const bool& status, const std::string &note)
{
//char* pj_note = (char*) pj_pool_alloc(pool_, "50"); //char* pj_note = (char*) pj_pool_alloc(pool_, "50");
pjrpid_element rpid = { pjrpid_element rpid = {
PJRPID_ELEMENT_TYPE_PERSON, PJRPID_ELEMENT_TYPE_PERSON,
pj_str("20"), pj_str("20"),
PJRPID_ACTIVITY_UNKNOWN, PJRPID_ACTIVITY_UNKNOWN,
pj_str((char *) note.c_str())}; pj_str((char *) note.c_str())
};
/* fill activity if user not available. */ /* fill activity if user not available. */
if (note == "away") if (note == "away")
...@@ -124,18 +133,22 @@ void SIPPresence::updateStatus(const bool& status, const std::string &note){ ...@@ -124,18 +133,22 @@ void SIPPresence::updateStatus(const bool& status, const std::string &note){
/* "contact" field is optionnal */ /* "contact" field is optionnal */
} }
void SIPPresence::sendPresence(const bool& status, const std::string &note){ void SIPPresence::sendPresence(const bool& status, const std::string &note)
{
updateStatus(status, note); updateStatus(status, note);
if(enabled){
if (not enabled_)
return;
if (acc_->isIP2IP()) if (acc_->isIP2IP())
notifyPresSubServer(); // to each subscribers notifyPresSubServer(); // to each subscribers
else else
pres_publish(this); // to the PBX server pres_publish(this); // to the PBX server
} }
}
void SIPPresence::reportPresSubClientNotification(const std::string& uri, pjsip_pres_status * status){ void SIPPresence::reportPresSubClientNotification(const std::string& uri, pjsip_pres_status * status)
{
/* Update our info. See pjsua_buddy_get_info() for additionnal ideas*/ /* Update our info. See pjsua_buddy_get_info() for additionnal ideas*/
const std::string basic(status->info[0].basic_open ? "open" : "closed"); const std::string basic(status->info[0].basic_open ? "open" : "closed");
const std::string note(status->info[0].rpid.note.ptr, status->info[0].rpid.note.slen); const std::string note(status->info[0].rpid.note.ptr, status->info[0].rpid.note.slen);
...@@ -144,7 +157,8 @@ void SIPPresence::reportPresSubClientNotification(const std::string& uri, pjsip_ ...@@ -144,7 +157,8 @@ void SIPPresence::reportPresSubClientNotification(const std::string& uri, pjsip_
Manager::instance().getClient()->getPresenceManager()->newBuddySubscription(uri, status->info[0].basic_open, note); Manager::instance().getClient()->getPresenceManager()->newBuddySubscription(uri, status->info[0].basic_open, note);
} }
void SIPPresence::subscribeClient(const std::string& uri, const bool& flag){ void SIPPresence::subscribeClient(const std::string& uri, const bool& flag)
{
/* Check if the buddy was already subscribed */ /* Check if the buddy was already subscribed */
for (auto c : pres_sub_client_list_) for (auto c : pres_sub_client_list_)
if (c->getURI() == uri) { if (c->getURI() == uri) {
...@@ -161,36 +175,41 @@ void SIPPresence::subscribeClient(const std::string& uri, const bool& flag){ ...@@ -161,36 +175,41 @@ void SIPPresence::subscribeClient(const std::string& uri, const bool& flag){
if (flag) { if (flag) {
PresSubClient *c = new PresSubClient(uri, this); PresSubClient *c = new PresSubClient(uri, this);
if (!(c->subscribe())) { if (!(c->subscribe())) {
WARN("Failed send subscribe."); WARN("Failed send subscribe.");
delete c; delete c;
} }
// the buddy has to be accepted before being added in the list // the buddy has to be accepted before being added in the list
} }
} }
void SIPPresence::addPresSubClient(PresSubClient *c){ void SIPPresence::addPresSubClient(PresSubClient *c)
{
if (pres_sub_client_list_.size() < MAX_N_PRES_SUB_CLIENT) { if (pres_sub_client_list_.size() < MAX_N_PRES_SUB_CLIENT) {
pres_sub_client_list_.push_back(c); pres_sub_client_list_.push_back(c);
DEBUG("New Presence_subscription_client client added in the list[l=%i].", pres_sub_client_list_.size()); DEBUG("New Presence_subscription_client client added in the list[l=%i].", pres_sub_client_list_.size());
} } else {
else{
WARN("Max Presence_subscription_client is reach."); WARN("Max Presence_subscription_client is reach.");
// let the client alive //delete c; // let the client alive //delete c;
} }
} }
void SIPPresence::removePresSubClient(PresSubClient *c){ void SIPPresence::removePresSubClient(PresSubClient *c)
{
DEBUG("Presence_subscription_client removed from the buddy list."); DEBUG("Presence_subscription_client removed from the buddy list.");
pres_sub_client_list_.remove(c); pres_sub_client_list_.remove(c);
} }
void SIPPresence::reportnewServerSubscriptionRequest(PresSubServer *s){ void SIPPresence::reportnewServerSubscriptionRequest(PresSubServer *s)
{
Manager::instance().getClient()->getPresenceManager()->newServerSubscriptionRequest(s->remote); Manager::instance().getClient()->getPresenceManager()->newServerSubscriptionRequest(s->remote);
} }
void SIPPresence::approvePresSubServer(const std::string& uri, const bool& flag){ void SIPPresence::approvePresSubServer(const std::string& uri, const bool& flag)
{
for (auto s : pres_sub_server_list_) for (auto s : pres_sub_server_list_)
if (s->matches((char *) uri.c_str())) { if (s->matches((char *) uri.c_str())) {
DEBUG("Approve Presence_subscription_server for %s: %s.", s->remote, flag ? "true" : "false"); DEBUG("Approve Presence_subscription_server for %s: %s.", s->remote, flag ? "true" : "false");
...@@ -200,24 +219,27 @@ void SIPPresence::approvePresSubServer(const std::string& uri, const bool& flag) ...@@ -200,24 +219,27 @@ void SIPPresence::approvePresSubServer(const std::string& uri, const bool& flag)
} }
void SIPPresence::addPresSubServer(PresSubServer *s) { void SIPPresence::addPresSubServer(PresSubServer *s)
{
if (pres_sub_server_list_.size() < MAX_N_PRES_SUB_SERVER) { if (pres_sub_server_list_.size() < MAX_N_PRES_SUB_SERVER) {
DEBUG("Presence_subscription_server added: %s.", s->remote); DEBUG("Presence_subscription_server added: %s.", s->remote);
pres_sub_server_list_.push_back(s); pres_sub_server_list_.push_back(s);
} } else {
else{
WARN("Max Presence_subscription_server is reach."); WARN("Max Presence_subscription_server is reach.");
// let de server alive // delete s; // let de server alive // delete s;
} }
} }
void SIPPresence::removePresSubServer(PresSubServer *s) { void SIPPresence::removePresSubServer(PresSubServer *s)
{
pres_sub_server_list_.remove(s); pres_sub_server_list_.remove(s);
DEBUG("Presence_subscription_server removed"); DEBUG("Presence_subscription_server removed");
} }
void SIPPresence::notifyPresSubServer() { void SIPPresence::notifyPresSubServer()
{
DEBUG("Iterating through Presence_subscription_server:"); DEBUG("Iterating through Presence_subscription_server:");
for (auto s : pres_sub_server_list_) for (auto s : pres_sub_server_list_)
s->notify(); s->notify();
} }
...@@ -233,6 +255,7 @@ void SIPPresence::unlock() ...@@ -233,6 +255,7 @@ void SIPPresence::unlock()
{ {
if (--mutex_nesting_level_ == 0) if (--mutex_nesting_level_ == 0)
mutex_owner_ = NULL; mutex_owner_ = NULL;
pj_mutex_unlock(mutex_); pj_mutex_unlock(mutex_);
} }
...@@ -252,6 +275,7 @@ void SIPPresence::fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data) ...@@ -252,6 +275,7 @@ void SIPPresence::fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data)
const pjsip_hdr *hdr; const pjsip_hdr *hdr;
hdr = msg_data->hdr_list.next; hdr = msg_data->hdr_list.next;
while (hdr && hdr != &msg_data->hdr_list) { while (hdr && hdr != &msg_data->hdr_list) {
pjsip_hdr *new_hdr; pjsip_hdr *new_hdr;
new_hdr = (pjsip_hdr*) pjsip_hdr_clone(tdata->pool, hdr); new_hdr = (pjsip_hdr*) pjsip_hdr_clone(tdata->pool, hdr);
......
...@@ -202,7 +202,7 @@ public: ...@@ -202,7 +202,7 @@ public:
void notifyPresSubServer(); void notifyPresSubServer();
bool isEnabled() const { bool isEnabled() const {
return enabled; return enabled_;
} }
const std::list< PresSubClient *> getClientSubscriptions() { const std::list< PresSubClient *> getClientSubscriptions() {
...@@ -214,7 +214,7 @@ public: ...@@ -214,7 +214,7 @@ public:
pjsip_pres_status pres_status_data; /**< Presence Data.*/ pjsip_pres_status pres_status_data; /**< Presence Data.*/
pjsip_publishc *publish_sess; /**< Client publication session.*/ pjsip_publishc *publish_sess; /**< Client publication session.*/
pj_bool_t enabled; /**< Allow for status publish,*/ pj_bool_t enabled_; /**< Allow for status publish,*/
private: private:
NON_COPYABLE(SIPPresence); NON_COPYABLE(SIPPresence);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment