Commit 6b9c5e25 authored by Patrick Keroulas's avatar Patrick Keroulas
Browse files

* #28472 : fix mem bug on IP2IP subscribe receive, improve subscription

* approvement
parent 9df4c619
...@@ -184,8 +184,8 @@ class CallManager ...@@ -184,8 +184,8 @@ class CallManager
void subscribePresence(const std::string& accountID, const std::string& buddySipUri); void subscribePresence(const std::string& accountID, const std::string& buddySipUri);
void unsubscribePresence(const std::string& accountID, const std::string& buddySipUri); void unsubscribePresence(const std::string& accountID, const std::string& buddySipUri);
void sendPresence(const std::string& accountID, const std::string& status, const std::string& note); void sendPresence(const std::string& accountID, const std::string& status, const std::string& note);
void confirmPresenceSubscription(const bool& confirm); void approvePresenceSubscription(const bool& flag, const std::string& uri);
private: private:
#if HAVE_ZRTP #if HAVE_ZRTP
sfl::AudioZrtpSession * getAudioZrtpSession(const std::string& callID); sfl::AudioZrtpSession * getAudioZrtpSession(const std::string& callID);
......
...@@ -839,11 +839,14 @@ ...@@ -839,11 +839,14 @@
<arg type="s" name="note" direction="in"/> <arg type="s" name="note" direction="in"/>
</method> </method>
<method name="confirmPresenceSubscription" tp:name-for-bindings="confirmPresenceSubscription"> <method name="approvePresenceSubscription" tp:name-for-bindings="approvePresenceSubscription">
<arg type="b" name="confirm" direction="in"/> <tp:added version="0.9.7"/>
<arg type="b" name="flag" direction="in"/>
<arg type="s" name="uri" direction="in"/>
</method> </method>
<signal name="newPresenceNotification" tp:name-for-bindings="newPresenceNotification"> <signal name="newPresenceNotification" tp:name-for-bindings="newPresenceNotification">
<tp:added version="0.9.7"/>
<arg type="s" name="buddyUri"/> <arg type="s" name="buddyUri"/>
<arg type="s" name="status"/> <arg type="s" name="status"/>
<arg type="s" name="lineStatus"/> <arg type="s" name="lineStatus"/>
......
...@@ -426,14 +426,14 @@ CallManager::sendTextMessage(const std::string& callID, const std::string& messa ...@@ -426,14 +426,14 @@ CallManager::sendTextMessage(const std::string& callID, const std::string& messa
void void
CallManager::subscribePresence(const std::string& accountID, const std::string& buddySipUri) CallManager::subscribePresence(const std::string& accountID, const std::string& buddySipUri)
{ {
DEBUG("subscribePresence (acc:%s, buddy:%)",accountID.c_str(), buddySipUri.c_str()); DEBUG("subscribePresence (acc:%s, buddy:%s)",accountID.c_str(), buddySipUri.c_str());
Manager::instance().subscribePresence(accountID,buddySipUri); Manager::instance().subscribePresence(accountID,buddySipUri);
} }
void void
CallManager::unsubscribePresence(const std::string& accountID, const std::string& buddySipUri) CallManager::unsubscribePresence(const std::string& accountID, const std::string& buddySipUri)
{ {
DEBUG("unsubscribePresence (acc:%s, buddy:%)",accountID.c_str(), buddySipUri.c_str()); DEBUG("unsubscribePresence (acc:%s, buddy:%s)",accountID.c_str(), buddySipUri.c_str());
Manager::instance().unsubscribePresence(accountID,buddySipUri); Manager::instance().unsubscribePresence(accountID,buddySipUri);
} }
...@@ -445,8 +445,8 @@ CallManager::sendPresence(const std::string& accountID, const std::string& statu ...@@ -445,8 +445,8 @@ CallManager::sendPresence(const std::string& accountID, const std::string& statu
} }
void void
CallManager::confirmPresenceSubscription(const bool& confirm) CallManager::approvePresenceSubscription(const bool& flag, const std::string& uri)
{ {
DEBUG("confirmPresenceSubscription :"); DEBUG("approvePresenceSubscription %s : %s.",uri.c_str(), flag? "yes":"no");
Manager::instance().confirmPresenceSubscription(confirm); Manager::instance().approvePresenceSubscription(flag, uri);
} }
...@@ -2950,13 +2950,13 @@ void ManagerImpl::sendPresence(const std::string& accountID, const std::string& ...@@ -2950,13 +2950,13 @@ void ManagerImpl::sendPresence(const std::string& accountID, const std::string&
account->getPresence()->sendPresence(status,note); account->getPresence()->sendPresence(status,note);
} }
void ManagerImpl::confirmPresenceSubscription(const bool& confirm) void ManagerImpl::approvePresenceSubscription(const bool& flag, const std::string& uri)
{ {
SIPAccount *account = Manager::instance().getSipAccount("IP2IP"); SIPAccount *account = Manager::instance().getSipAccount("IP2IP");
account->getPresence()->confirmNewServerSubscription(confirm); account->getPresence()->approveServerSubscription(flag, uri);
} }
void void
ManagerImpl::registerAccounts() ManagerImpl::registerAccounts()
{ {
AccountMap allAccounts(getAllAccounts()); AccountMap allAccounts(getAllAccounts());
......
...@@ -1049,7 +1049,7 @@ class ManagerImpl { ...@@ -1049,7 +1049,7 @@ class ManagerImpl {
/** /**
* Accept or not a PresenceSubscription request for IP2IP account * Accept or not a PresenceSubscription request for IP2IP account
*/ */
void confirmPresenceSubscription(const bool& confirm); void approvePresenceSubscription(const bool& flag, const std::string& uri);
private: private:
NON_COPYABLE(ManagerImpl); NON_COPYABLE(ManagerImpl);
......
...@@ -71,7 +71,7 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) { ...@@ -71,7 +71,7 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) {
pjsip_method *method = &rdata->msg_info.msg->line.req.method; pjsip_method *method = &rdata->msg_info.msg->line.req.method;
pj_str_t *str = &method->name; pj_str_t *str = &method->name;
std::string request(str->ptr, str->slen); std::string request(str->ptr, str->slen);
pj_str_t contact; // pj_str_t contact;
pj_status_t status; pj_status_t status;
pjsip_dialog *dlg; pjsip_dialog *dlg;
pjsip_evsub *sub; pjsip_evsub *sub;
...@@ -89,20 +89,24 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) { ...@@ -89,20 +89,24 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) {
if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, pjsip_get_subscribe_method()) != 0) if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, pjsip_get_subscribe_method()) != 0)
return PJ_FALSE; return PJ_FALSE;
DEBUG("Incomming pres_on_rx_subscribe_request for %s.", request.c_str()); /* debug msg */
std::string name(rdata->msg_info.to->name.ptr, rdata->msg_info.to->name.slen);
//std::string name(rdata->msg_info.to->name.ptr, rdata->msg_info.to->name.slen); std::string server(rdata->msg_info.from->name.ptr, rdata->msg_info.from->name.slen);
//std::string server(rdata->msg_info.from->name.ptr, rdata->msg_info.from->name.slen); DEBUG("Incomming pres_on_rx_subscribe_request for %s, name:%s, server:%s."
, request.c_str()
, name.c_str()
, server.c_str());
/* get parents*/
std::string accountId = "IP2IP"; /* this code is only used for IP2IP accounts */ std::string accountId = "IP2IP"; /* this code is only used for IP2IP accounts */
SIPAccount *acc = (SIPAccount *) Manager::instance().getSipAccount(accountId); SIPAccount *acc = (SIPAccount *) Manager::instance().getSipAccount(accountId);
pjsip_endpoint *endpt = ((SIPVoIPLink*) acc->getVoIPLink())->getEndpoint(); pjsip_endpoint *endpt = ((SIPVoIPLink*) acc->getVoIPLink())->getEndpoint();
SIPPresence * pres = acc->getPresence(); SIPPresence * pres = acc->getPresence();
pres->lock(); pres->lock();
/* Create UAS dialog: */ /* Create UAS dialog: */
contact = pj_str(strdup(acc->getContactHeader().c_str())); std::string c(acc->getContactHeader());
const pj_str_t contact = pj_str((char*) c.c_str());
status = pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, &contact, &dlg); status = pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, &contact, &dlg);
if (status != PJ_SUCCESS) { if (status != PJ_SUCCESS) {
char errmsg[PJ_ERR_MSG_SIZE]; char errmsg[PJ_ERR_MSG_SIZE];
...@@ -141,21 +145,18 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) { ...@@ -141,21 +145,18 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) {
/* Attach our data to the subscription: */ /* Attach our data to the subscription: */
char* remote = (char*) pj_pool_alloc(dlg->pool, PJSIP_MAX_URL_SIZE); char* remote = (char*) pj_pool_alloc(dlg->pool, PJSIP_MAX_URL_SIZE);
status = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, dlg->remote.info->uri, remote, PJSIP_MAX_URL_SIZE); status = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, dlg->remote.info->uri, remote, PJSIP_MAX_URL_SIZE);
pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, dlg->local.info->uri, contact.ptr, PJSIP_MAX_URL_SIZE);
PresenceSubscription *presenceSub = new PresenceSubscription(pres, sub, remote, dlg);
if (status < 1) if (status < 1)
pj_ansi_strcpy(remote, "<-- url is too long-->"); pj_ansi_strcpy(remote, "<-- url is too long-->");
else else
remote[status] = '\0'; remote[status] = '\0';
//pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, dlg->local.info->uri, contact.ptr, PJSIP_MAX_URL_SIZE);
/* Create a new PresenceSubription server and wait for client approve */
PresenceSubscription *presenceSub = new PresenceSubscription(pres, sub, remote, dlg);
pjsip_evsub_set_mod_data(sub, pres->getModId(), presenceSub); pjsip_evsub_set_mod_data(sub, pres->getModId(), presenceSub);
pres->reportNewServerSubscription(presenceSub); /* Notify the client.*/
/* Need client approvement.*/
//pres->reportNewServerSubscription(presenceSub);
pres->addServerSubscription(presenceSub); pres->addServerSubscription(presenceSub);
/* Capture the value of Expires header. */ /* Capture the value of Expires header. */
expires_hdr = (pjsip_expires_hdr*) pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL); expires_hdr = (pjsip_expires_hdr*) pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL);
if (expires_hdr) if (expires_hdr)
...@@ -218,7 +219,8 @@ PresenceSubscription::PresenceSubscription(SIPPresence * pres, pjsip_evsub *evsu ...@@ -218,7 +219,8 @@ PresenceSubscription::PresenceSubscription(SIPPresence * pres, pjsip_evsub *evsu
, sub(evsub) , sub(evsub)
, remote(r) , remote(r)
, dlg(d) , dlg(d)
, expires (-1) , expires(-1)
, approved(false)
{} {}
...@@ -234,15 +236,13 @@ int PresenceSubscription::getExpires(){ ...@@ -234,15 +236,13 @@ int PresenceSubscription::getExpires(){
return pres_; return pres_;
}*/ }*/
bool PresenceSubscription::matches(PresenceSubscription * s){ bool PresenceSubscription::matches(char *s){
// servers match if they have the same remote uri and the account ID. // servers match if they have the same remote uri and the account ID.
return (!(strcmp(remote,s->remote))) ; return (!(strcmp(remote,s))) ;
} }
bool PresenceSubscription::isActive(){ void PresenceSubscription::approve(const bool& flag){
if (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_ACTIVE ) approved = flag;
return true;
return false;
} }
/** /**
...@@ -281,7 +281,7 @@ void PresenceSubscription::notify() { ...@@ -281,7 +281,7 @@ void PresenceSubscription::notify() {
* being requested) state and we don't send NOTIFY to these subs until * being requested) state and we don't send NOTIFY to these subs until
* the user accepted the request. * the user accepted the request.
*/ */
if (isActive()) { if ((pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_ACTIVE) && (approved)) {
DEBUG("Notifying %s.", remote); DEBUG("Notifying %s.", remote);
pjsip_tx_data *tdata; pjsip_tx_data *tdata;
......
...@@ -69,17 +69,16 @@ public: ...@@ -69,17 +69,16 @@ public:
PresenceSubscription(SIPPresence * pres, pjsip_evsub *evsub, char *r,pjsip_dialog *d); PresenceSubscription(SIPPresence * pres, pjsip_evsub *evsub, char *r,pjsip_dialog *d);
char *remote; /**< Remote URI. */ char *remote; /**< Remote URI. */
void setExpires(int ms); void setExpires(int ms);
int getExpires(); int getExpires();
bool matches(PresenceSubscription * s); bool matches(char *s);
bool isActive(); void approve(const bool& flag);
/** /**
* Send the tirst notification. * Send the tirst notification.
* FIXME : pjsip_pres_notify crash because the header can't be cloned * FIXME : pjsip_pres_notify crash because the header can't be cloned
* So far, the first notify is sent in sipvoip_pres.c instead. * So far, the first notify is sent in pres_on_rx_subscribe_request() instead.
*/ */
void init(); void init();
void notify(); void notify();
...@@ -93,7 +92,8 @@ private: ...@@ -93,7 +92,8 @@ private:
SIPPresence *pres_; SIPPresence *pres_;
pjsip_evsub *sub; /**< The evsub. */ pjsip_evsub *sub; /**< The evsub. */
pjsip_dialog *dlg; /**< Dialog. */ pjsip_dialog *dlg; /**< Dialog. */
int expires; /**< "expires" value in the request. */ int expires; /**< "expires" value in the request. */
bool approved; /**< The client approved this subscription*/
}; };
......
...@@ -1297,80 +1297,6 @@ SIPPresence * SIPAccount::getPresence(){ ...@@ -1297,80 +1297,6 @@ SIPPresence * SIPAccount::getPresence(){
return presence_; return presence_;
} }
/*
void SIPAccount::sendPresence(const std::string &status, const std::string &note){
pres_update(status,note);
if (isIP2IP())
notifyServerSubscription();
else
pres_publish(this);
}
void SIPAccount::subscribeBuddy(const std::string& buddySipUri){
std::list< SIPBuddy *>::iterator buddyIt;
for (buddyIt = buddies_.begin(); buddyIt != buddies_.end(); buddyIt++)
if((*buddyIt)->getURI()==buddySipUri){
DEBUG("-Buddy:%s exist in the list. Replace it.",buddySipUri.c_str());
delete *buddyIt;
removeBuddy(*buddyIt);
break;
}
SIPBuddy *b = new SIPBuddy(buddySipUri, this);
b->subscribe();
addBuddy(b);
}
void SIPAccount::unsubscribeBuddy(const std::string& buddySipUri){
std::list< SIPBuddy *>::iterator buddyIt;
for (buddyIt = buddies_.begin(); buddyIt != buddies_.end(); buddyIt++)
if((*buddyIt)->getURI()==buddySipUri){
DEBUG("-Found buddy:%s in the buddy list.",buddySipUri.c_str());
delete *buddyIt;
removeBuddy(*buddyIt);
return;
}
}
void SIPAccount::addBuddy(SIPBuddy *b){
DEBUG("-New buddy subscription added in the buddy list.");
buddies_.push_back(b);
}
void SIPAccount::removeBuddy(SIPBuddy *b){
DEBUG("-Buddy subscription removed from the buddy list.");
buddies_.remove(b);
}*/
/*
* Presence Management for IP2IP accounts
*
* when the account receive a SUBSCRIBE from an IP account,
* a new PresenceSubscription of this account is added to PresenceSubscription list.
* Then notifications can be send to each serverSubscriptions element
*/
/* Presence : Method used to add serverSubscription to PresenceSubscription list in case of IP2IP accounts */
/*void SIPAccount::addServerSubscription(PresenceSubscription *s) {
DEBUG("-PresenceServer subscription added.");
serverSubscriptions_.push_back(s);
}*/
/* Presence : Method used to remove serverSubscription to PresenceSubscription list in: case of IP2IP accounts */
/*void SIPAccount::removeServerSubscription(PresenceSubscription *s) {
serverSubscriptions_.remove(s);
DEBUG("-PresenceServer removed");
}*/
/* Presence : Method used to notify each serverSubscription of a new presencein case of IP2IP accounts */
/*void SIPAccount::notifyServerSubscription() {
std::list< PresenceSubscription *>::iterator serverIt;
DEBUG("-Iterating through PresenceServers:");
for (serverIt = serverSubscriptions_.begin(); serverIt != serverSubscriptions_.end(); serverIt++)
(*serverIt)->notify();
}*/
bool SIPAccount::matches(const std::string &userName, const std::string &server, bool SIPAccount::matches(const std::string &userName, const std::string &server,
pjsip_endpoint *endpt, pj_pool_t *pool) const pjsip_endpoint *endpt, pj_pool_t *pool) const
{ {
......
...@@ -82,7 +82,7 @@ void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) { ...@@ -82,7 +82,7 @@ void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) {
pjsip_evsub_state state = pjsip_evsub_get_state(sub); pjsip_evsub_state state = pjsip_evsub_get_state(sub);
if(state == PJSIP_EVSUB_STATE_ACCEPTED){ if(state == PJSIP_EVSUB_STATE_ACCEPTED){
DEBUG("Accept buddy."); DEBUG("Buddy accepted.");
buddy->accept(); buddy->accept();
} }
else if (state == PJSIP_EVSUB_STATE_TERMINATED) { else if (state == PJSIP_EVSUB_STATE_TERMINATED) {
...@@ -286,7 +286,8 @@ SIPBuddy::SIPBuddy(const std::string& uri_, SIPAccount *acc_) : ...@@ -286,7 +286,8 @@ SIPBuddy::SIPBuddy(const std::string& uri_, SIPAccount *acc_) :
term_reason(), term_reason(),
timer(), timer(),
user_data(NULL), user_data(NULL),
lock_count(0) { lock_count(0)
{
pj_caching_pool_init(&cp_, &pj_pool_factory_default_policy, 0); pj_caching_pool_init(&cp_, &pj_pool_factory_default_policy, 0);
pool = pj_pool_create(&cp_.factory, "buddy", 512, 512, NULL); pool = pj_pool_create(&cp_.factory, "buddy", 512, 512, NULL);
} }
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
* combining it with the OpenSSL project's OpenSSL library (or a * combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the * modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, LOTES-TM LLC * terms of the OpenSSL or SSLeay licenses, LOTES-TM LLC
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination * Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well * shall include the source code for the parts of OpenSSL used as well
* as that of the covered work. * as that of the covered work.
......
...@@ -43,21 +43,13 @@ ...@@ -43,21 +43,13 @@
/*TODO : clean this*/
static pj_caching_pool cp;
SIPPresence::SIPPresence(SIPAccount *acc) SIPPresence::SIPPresence(SIPAccount *acc)
: pres_status_data() : pres_status_data()
, online_status() , online_status()
, rpid({PJRPID_ELEMENT_TYPE_PERSON,
pj_str("20"),/*TODO : unhardcode this*/
PJRPID_ACTIVITY_BUSY,
pj_str("")})
, publish_sess() , publish_sess()
, publish_state() , publish_state()
, publish_enabled(true) , publish_enabled(true)
, acc_(acc) , acc_(acc)
, newPresenceSubscription_(NULL)
, serverSubscriptions_ () , serverSubscriptions_ ()
, buddies_ () , buddies_ ()
, mutex_() , mutex_()
...@@ -66,12 +58,13 @@ SIPPresence::SIPPresence(SIPAccount *acc) ...@@ -66,12 +58,13 @@ SIPPresence::SIPPresence(SIPAccount *acc)
, pool_() , pool_()
, cp_() , cp_()
{ {
// init default status /* init default status */
updateStatus("open","Available"); updateStatus("open","Available");
cp_ = &cp; /* init pool */
pj_caching_pool_init(cp_, NULL, 0); pj_caching_pool_init(&cp_, &pj_pool_factory_default_policy, 0);
pool_ = pj_pool_create(&(cp_->factory), "pres", 1000, 1000, NULL); pool_ = pj_pool_create(&cp_.factory, "pres", 1000, 1000, NULL);
/* Create mutex */ /* Create mutex */
if(pj_mutex_create_recursive(pool_, "pres",&mutex_) != PJ_SUCCESS) if(pj_mutex_create_recursive(pool_, "pres",&mutex_) != PJ_SUCCESS)
ERROR("Unable to create mutex"); ERROR("Unable to create mutex");
...@@ -79,8 +72,13 @@ SIPPresence::SIPPresence(SIPAccount *acc) ...@@ -79,8 +72,13 @@ SIPPresence::SIPPresence(SIPAccount *acc)
SIPPresence::~SIPPresence(){ SIPPresence::~SIPPresence(){
/*TODO free buddy/subcriber lists and the pool*/ /* Flush the lists */
std::list< PresenceSubscription *>::iterator serverIt;
std::list< SIPBuddy *>::iterator buddyIt;
for (buddyIt = buddies_.begin(); buddyIt != buddies_.end(); buddyIt++)
delete *buddyIt;
for (serverIt = serverSubscriptions_.begin(); serverIt != serverSubscriptions_.end(); serverIt++)
delete *serverIt;
} }
SIPAccount * SIPPresence::getAccount(){ SIPAccount * SIPPresence::getAccount(){
...@@ -100,10 +98,13 @@ pj_pool_t* SIPPresence::getPool(){ ...@@ -100,10 +98,13 @@ pj_pool_t* SIPPresence::getPool(){
} }
void SIPPresence::updateStatus(const std::string &status, const std::string &note){ void SIPPresence::updateStatus(const std::string &status, const std::string &note){
//char* pj_note = (char*) pj_pool_alloc(pool_, "50");
pjrpid_element rpid = {PJRPID_ELEMENT_TYPE_PERSON, pjrpid_element rpid = {PJRPID_ELEMENT_TYPE_PERSON,
pj_str("20"), pj_str("20"),
PJRPID_ACTIVITY_UNKNOWN, PJRPID_ACTIVITY_UNKNOWN,
pj_str(strdup(note.c_str()))}; /*TODO : del strdup*/ pj_str((char *) note.c_str())};
//pj_str(strdup(note.c_str()))}; /*TODO : del strdup*/
/* fill activity if user not available. */ /* fill activity if user not available. */
if(note=="away") if(note=="away")
...@@ -124,9 +125,9 @@ void SIPPresence::updateStatus(const std::string &status, const std::string &not ...@@ -124,9 +125,9 @@ void SIPPresence::updateStatus(const std::string &status, const std::string &not
void SIPPresence::sendPresence(const std::string &status, const std::string &note){ void SIPPresence::sendPresence(const std::string &status, const std::string &note){
updateStatus(status,note); updateStatus(status,note);
if (acc_->isIP2IP()) if (acc_->isIP2IP())
notifyServerSubscription(); notifyServerSubscription(); // to each subscribers
else else
pres_publish(this); pres_publish(this); // to sipvoip server
} }
...@@ -177,27 +178,24 @@ void SIPPresence::removeBuddy(SIPBuddy *b){ ...@@ -177,27 +178,24 @@ void SIPPresence::removeBuddy(SIPBuddy *b){
void SIPPresence::reportNewServerSubscription(PresenceSubscription *s){ void SIPPresence::reportNewServerSubscription(PresenceSubscription *s){
newPresenceSubscription_ = s; //newPresenceSubscription_ = s;
Manager::instance().getClient()->getCallManager()->newPresenceSubscription(s->remote); Manager::instance().getClient()->getCallManager()->newPresenceSubscription(s->remote);
} }
void SIPPresence::confirmNewServerSubscription(const bool& confirm){ void SIPPresence::approveServerSubscription(const bool& flag, const std::string& uri){
if(newPresenceSubscription_=NULL) std::list< PresenceSubscription *>::iterator serverIt;
return; for (serverIt = serverSubscriptions_.begin(); serverIt != serverSubscriptions_.end(); serverIt++){
if((*serverIt)->matches((char *) uri.c_str())){
if(confirm){ DEBUG("-Approve subscription for %s.",(*serverIt)->remote);
DEBUG("-Confirm new PresenceSubscription for %s",newPresenceSubscription_->remote); (*serverIt)->approve(flag);
addServerSubscription(newPresenceSubscription_); // return; // 'return' would prevent multiple-time subscribers from spam
} }
else{
DEBUG("-Refused new PresenceSubscription for %s",newPresenceSubscription_->remote);
newPresenceSubscription_ = NULL;
} }
} }
void SIPPresence::addServerSubscription(PresenceSubscription *s) { void SIPPresence::addServerSubscription(PresenceSubscription *s) {
DEBUG("-PresenceServer subscription added."); DEBUG("-PresenceServer subscription added: %s.",s->remote);
serverSubscriptions_.push_back(s); serverSubscriptions_.push_back(s);
}