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

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

* approvement
parent 9df4c619
......@@ -184,8 +184,8 @@ class CallManager
void subscribePresence(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 confirmPresenceSubscription(const bool& confirm);
private:
void approvePresenceSubscription(const bool& flag, const std::string& uri);
private:
#if HAVE_ZRTP
sfl::AudioZrtpSession * getAudioZrtpSession(const std::string& callID);
......
......@@ -839,11 +839,14 @@
<arg type="s" name="note" direction="in"/>
</method>
<method name="confirmPresenceSubscription" tp:name-for-bindings="confirmPresenceSubscription">
<arg type="b" name="confirm" direction="in"/>
<method name="approvePresenceSubscription" tp:name-for-bindings="approvePresenceSubscription">
<tp:added version="0.9.7"/>
<arg type="b" name="flag" direction="in"/>
<arg type="s" name="uri" direction="in"/>
</method>
<signal name="newPresenceNotification" tp:name-for-bindings="newPresenceNotification">
<tp:added version="0.9.7"/>
<arg type="s" name="buddyUri"/>
<arg type="s" name="status"/>
<arg type="s" name="lineStatus"/>
......
......@@ -426,14 +426,14 @@ CallManager::sendTextMessage(const std::string& callID, const std::string& messa
void
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);
}
void
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);
}
......@@ -445,8 +445,8 @@ CallManager::sendPresence(const std::string& accountID, const std::string& statu
}
void
CallManager::confirmPresenceSubscription(const bool& confirm)
CallManager::approvePresenceSubscription(const bool& flag, const std::string& uri)
{
DEBUG("confirmPresenceSubscription :");
Manager::instance().confirmPresenceSubscription(confirm);
DEBUG("approvePresenceSubscription %s : %s.",uri.c_str(), flag? "yes":"no");
Manager::instance().approvePresenceSubscription(flag, uri);
}
......@@ -2950,13 +2950,13 @@ void ManagerImpl::sendPresence(const std::string& accountID, const std::string&
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");
account->getPresence()->confirmNewServerSubscription(confirm);
account->getPresence()->approveServerSubscription(flag, uri);
}
void
void
ManagerImpl::registerAccounts()
{
AccountMap allAccounts(getAllAccounts());
......
......@@ -1049,7 +1049,7 @@ class ManagerImpl {
/**
* Accept or not a PresenceSubscription request for IP2IP account
*/
void confirmPresenceSubscription(const bool& confirm);
void approvePresenceSubscription(const bool& flag, const std::string& uri);
private:
NON_COPYABLE(ManagerImpl);
......
......@@ -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;
pj_str_t *str = &method->name;
std::string request(str->ptr, str->slen);
pj_str_t contact;
// pj_str_t contact;
pj_status_t status;
pjsip_dialog *dlg;
pjsip_evsub *sub;
......@@ -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)
return PJ_FALSE;
DEBUG("Incomming pres_on_rx_subscribe_request for %s.", request.c_str());
//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);
/* debug msg */
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);
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 */
SIPAccount *acc = (SIPAccount *) Manager::instance().getSipAccount(accountId);
pjsip_endpoint *endpt = ((SIPVoIPLink*) acc->getVoIPLink())->getEndpoint();
SIPPresence * pres = acc->getPresence();
pres->lock();
/* 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);
if (status != PJ_SUCCESS) {
char errmsg[PJ_ERR_MSG_SIZE];
......@@ -141,21 +145,18 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) {
/* Attach our data to the subscription: */
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);
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)
pj_ansi_strcpy(remote, "<-- url is too long-->");
else
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);
/* Need client approvement.*/
//pres->reportNewServerSubscription(presenceSub);
pres->reportNewServerSubscription(presenceSub); /* Notify the client.*/
pres->addServerSubscription(presenceSub);
/* Capture the value of Expires header. */
expires_hdr = (pjsip_expires_hdr*) pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL);
if (expires_hdr)
......@@ -218,7 +219,8 @@ PresenceSubscription::PresenceSubscription(SIPPresence * pres, pjsip_evsub *evsu
, sub(evsub)
, remote(r)
, dlg(d)
, expires (-1)
, expires(-1)
, approved(false)
{}
......@@ -234,15 +236,13 @@ int PresenceSubscription::getExpires(){
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.
return (!(strcmp(remote,s->remote))) ;
return (!(strcmp(remote,s))) ;
}
bool PresenceSubscription::isActive(){
if (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_ACTIVE )
return true;
return false;
void PresenceSubscription::approve(const bool& flag){
approved = flag;
}
/**
......@@ -281,7 +281,7 @@ void PresenceSubscription::notify() {
* being requested) state and we don't send NOTIFY to these subs until
* the user accepted the request.
*/
if (isActive()) {
if ((pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_ACTIVE) && (approved)) {
DEBUG("Notifying %s.", remote);
pjsip_tx_data *tdata;
......
......@@ -69,17 +69,16 @@ public:
PresenceSubscription(SIPPresence * pres, pjsip_evsub *evsub, char *r,pjsip_dialog *d);
char *remote; /**< Remote URI. */
char *remote; /**< Remote URI. */
void setExpires(int ms);
int getExpires();
bool matches(PresenceSubscription * s);
bool isActive();
bool matches(char *s);
void approve(const bool& flag);
/**
* Send the tirst notification.
* 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 notify();
......@@ -93,7 +92,8 @@ private:
SIPPresence *pres_;
pjsip_evsub *sub; /**< The evsub. */
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(){
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,
pjsip_endpoint *endpt, pj_pool_t *pool) const
{
......
......@@ -82,7 +82,7 @@ void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) {
pjsip_evsub_state state = pjsip_evsub_get_state(sub);
if(state == PJSIP_EVSUB_STATE_ACCEPTED){
DEBUG("Accept buddy.");
DEBUG("Buddy accepted.");
buddy->accept();
}
else if (state == PJSIP_EVSUB_STATE_TERMINATED) {
......@@ -286,7 +286,8 @@ SIPBuddy::SIPBuddy(const std::string& uri_, SIPAccount *acc_) :
term_reason(),
timer(),
user_data(NULL),
lock_count(0) {
lock_count(0)
{
pj_caching_pool_init(&cp_, &pj_pool_factory_default_policy, 0);
pool = pj_pool_create(&cp_.factory, "buddy", 512, 512, NULL);
}
......
......@@ -23,7 +23,6 @@
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* 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
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
......
......@@ -43,21 +43,13 @@
/*TODO : clean this*/
static pj_caching_pool cp;
SIPPresence::SIPPresence(SIPAccount *acc)
: pres_status_data()
, online_status()
, rpid({PJRPID_ELEMENT_TYPE_PERSON,
pj_str("20"),/*TODO : unhardcode this*/
PJRPID_ACTIVITY_BUSY,
pj_str("")})
, publish_sess()
, publish_state()
, publish_enabled(true)
, acc_(acc)
, newPresenceSubscription_(NULL)
, serverSubscriptions_ ()
, buddies_ ()
, mutex_()
......@@ -66,12 +58,13 @@ SIPPresence::SIPPresence(SIPAccount *acc)
, pool_()
, cp_()
{
// init default status
/* init default status */
updateStatus("open","Available");
cp_ = &cp;
pj_caching_pool_init(cp_, NULL, 0);
pool_ = pj_pool_create(&(cp_->factory), "pres", 1000, 1000, NULL);
/* init pool */
pj_caching_pool_init(&cp_, &pj_pool_factory_default_policy, 0);
pool_ = pj_pool_create(&cp_.factory, "pres", 1000, 1000, NULL);
/* Create mutex */
if(pj_mutex_create_recursive(pool_, "pres",&mutex_) != PJ_SUCCESS)
ERROR("Unable to create mutex");
......@@ -79,8 +72,13 @@ SIPPresence::SIPPresence(SIPAccount *acc)
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(){
......@@ -100,10 +98,13 @@ pj_pool_t* SIPPresence::getPool(){
}
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,
pj_str("20"),
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. */
if(note=="away")
......@@ -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){
updateStatus(status,note);
if (acc_->isIP2IP())
notifyServerSubscription();
notifyServerSubscription(); // to each subscribers
else
pres_publish(this);
pres_publish(this); // to sipvoip server
}
......@@ -177,27 +178,24 @@ void SIPPresence::removeBuddy(SIPBuddy *b){
void SIPPresence::reportNewServerSubscription(PresenceSubscription *s){
newPresenceSubscription_ = s;
//newPresenceSubscription_ = s;
Manager::instance().getClient()->getCallManager()->newPresenceSubscription(s->remote);
}
void SIPPresence::confirmNewServerSubscription(const bool& confirm){
if(newPresenceSubscription_=NULL)
return;
if(confirm){
DEBUG("-Confirm new PresenceSubscription for %s",newPresenceSubscription_->remote);
addServerSubscription(newPresenceSubscription_);
}
else{
DEBUG("-Refused new PresenceSubscription for %s",newPresenceSubscription_->remote);
newPresenceSubscription_ = NULL;
void SIPPresence::approveServerSubscription(const bool& flag, const std::string& uri){
std::list< PresenceSubscription *>::iterator serverIt;
for (serverIt = serverSubscriptions_.begin(); serverIt != serverSubscriptions_.end(); serverIt++){
if((*serverIt)->matches((char *) uri.c_str())){
DEBUG("-Approve subscription for %s.",(*serverIt)->remote);
(*serverIt)->approve(flag);
// return; // 'return' would prevent multiple-time subscribers from spam
}
}
}
void SIPPresence::addServerSubscription(PresenceSubscription *s) {
DEBUG("-PresenceServer subscription added.");
DEBUG("-PresenceServer subscription added: %s.",s->remote);
serverSubscriptions_.push_back(s);
}
......
......@@ -43,7 +43,7 @@
#include "pjsip-simple/publish.h"
#include "pjsip-simple/presence.h"
#include "pjsip-simple/rpid.h"
#include <pj/pool.h>
struct pres_msg_data
{
......@@ -182,9 +182,10 @@ public:
/**
* IP2IP context.
* Process new subscription based on client decision.
* @param s PresenceSubcription pointer.
* @param flag client decision.
* @param uri uri of the remote subscriber
*/
void confirmNewServerSubscription(const bool& confirm);
void approveServerSubscription(const bool& flag, const std::string& uri);
/**
* IP2IP context.
* Add a server associated to a subscriber in the list.
......@@ -213,7 +214,6 @@ public:
pjsip_pres_status pres_status_data; /**< Presence Data.*/
pj_bool_t online_status; /**< Our online status. */
pjrpid_element rpid; /**< RPID element information.*/
pjsip_publishc *publish_sess; /**< Client publication session.*/
pj_bool_t publish_state; /**< Last published online status.*/
pj_bool_t publish_enabled; /**< Allow for status publish,*/
......@@ -221,16 +221,17 @@ public:
private:
NON_COPYABLE(SIPPresence);
SIPAccount * acc_; /**< Associated SIP account. */
std::list< PresenceSubscription *> serverSubscriptions_; /**< Subscribers list.*/
std::list< SIPBuddy *> buddies_; /**< Subcribed buddy list.*/
pj_mutex_t *mutex_; /**< Mutex protection for this data */
unsigned mutex_nesting_level_; /**< Mutex nesting level. */
pj_thread_t *mutex_owner_; /**< Mutex owner. */
pj_caching_pool *cp_; /**< Global pool factory. */
pj_caching_pool cp_; /**< Global pool factory. */
pj_pool_t *pool_; /**< pjsua's private pool. */
SIPAccount * acc_; /**< Associated SIP account. */
PresenceSubscription *newPresenceSubscription_; /**< Latest Subscribers waiting for approval */
std::list< PresenceSubscription *> serverSubscriptions_; /**< Subscribers list.*/
std::list< SIPBuddy *> buddies_; /**< Subcribed buddy list.*/
};
#endif
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