Commit f4262afc authored by Patrick Keroulas's avatar Patrick Keroulas

* #28472 : Fix compile issue. Change variable names. Need to test

* subscription overload.
parent 68a75984
......@@ -57,33 +57,33 @@
int modId;
void buddy_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry) {
void pres_client_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry) {
(void) th;
PresSubClient *b = (PresSubClient *) entry->user_data;
b->reportPresence();
}
/* Callback called when *client* subscription state has changed. */
void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) {
PresSubClient *buddy;
void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) {
PresSubClient *pres_client;
PJ_UNUSED_ARG(event);
/* Note: #937: no need to acuire PJSUA_LOCK here. Since the buddy has
* a dialog attached to it, lock_buddy() will use the dialog
/* Note: #937: no need to acuire PJSUA_LOCK here. Since the pres_client has
* a dialog attached to it, lock_pres_client() will use the dialog
* lock, which we are currently holding!
*/
buddy = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
if (buddy) {
buddy->incLock();
DEBUG("Presence subscription to '%s' is '%s'", buddy->getURI().c_str(),
pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
if (pres_client) {
pres_client->incLock();
DEBUG("Presence subscription to '%s' is '%s'", pres_client->getURI().c_str(),
pjsip_evsub_get_state_name(sub) ? pjsip_evsub_get_state_name(sub) : "null");
pjsip_evsub_state state = pjsip_evsub_get_state(sub);
if(state == PJSIP_EVSUB_STATE_ACCEPTED){
DEBUG("PresSubClient accepted.");
buddy->accept();
pres_client->accept();
}
else if (state == PJSIP_EVSUB_STATE_TERMINATED) {
int resub_delay = -1;
......@@ -94,17 +94,17 @@ void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) {
// BUDDY_SUB_TERM_REASON_LEN:
// pjTermReason->slen
// );
pj_strdup_with_null(buddy->pool, &buddy->term_reason, pjsip_evsub_get_termination_reason(sub));
pj_strdup_with_null(pres_client->pool, &pres_client->term_reason, pjsip_evsub_get_termination_reason(sub));
// buddy->setTermReason(termReason);
// buddy->setTermCode(200);
buddy->term_code = 200;
// pres_client->setTermCode(200);
pres_client->term_code = 200;
/* Determine whether to resubscribe automatically */
if (event && event->type == PJSIP_EVENT_TSX_STATE) {
const pjsip_transaction *tsx = event->body.tsx_state.tsx;
if (pjsip_method_cmp(&tsx->method, &pjsip_subscribe_method) == 0) {
// buddy->setTermCode(tsx->status_code);
buddy->term_code = tsx->status_code;
// pres_client->setTermCode(tsx->status_code);
pres_client->term_code = tsx->status_code;
switch (tsx->status_code) {
case PJSIP_SC_CALL_TSX_DOES_NOT_EXIST:
/* 481: we refreshed too late? resubscribe
......@@ -116,12 +116,12 @@ void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) {
* on the initial SUBSCRIBE (if server returns this
* response for some reason).
*/
if (buddy->dlg->remote.contact)
if (pres_client->dlg->remote.contact)
resub_delay = 500;
break;
}
} else if (pjsip_method_cmp(&tsx->method, &pjsip_notify_method) == 0) {
if (buddy->isTermReason("deactivated") || buddy->isTermReason("timeout")) {
if (pres_client->isTermReason("deactivated") || pres_client->isTermReason("timeout")) {
/* deactivated: The subscription has been terminated,
* but the subscriber SHOULD retry immediately with
* a new subscription.
......@@ -133,7 +133,7 @@ void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) {
* "timeout".
*/
resub_delay = 500;
} else if (buddy->isTermReason("probation") || buddy->isTermReason("giveup")) {
} else if (pres_client->isTermReason("probation") || pres_client->isTermReason("giveup")) {
/* probation: The subscription has been terminated,
* but the client SHOULD retry at some later time.
* If a "retry-after" parameter is also present, the
......@@ -171,57 +171,57 @@ void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event) {
// pj_assert(PRES_TIMER >= 3);
resub_delay = PRES_TIMER * 1000;// - 2500 + (pj_rand() % 5000);
}
buddy->sub = sub;
buddy->rescheduleTimer(PJ_TRUE, resub_delay);
pres_client->sub = sub;
pres_client->rescheduleTimer(PJ_TRUE, resub_delay);
}/* else {
This will clear the last termination code/reason
buddy->term_code = 0;
buddy->term_reason.ptr = NULL;
pres_client->term_code = 0;
pres_client->term_reason.ptr = NULL;
}*/
/* Clear subscription */
/* if (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_TERMINATED) {
pjsip_evsub_terminate(buddy->sub, PJ_FALSE); // = NULL;
buddy->status.info_cnt = 0;
buddy->dlg = NULL;
buddy->rescheduleTimer(PJ_FALSE, 0);
pjsip_evsub_terminate(pres_client->sub, PJ_FALSE); // = NULL;
pres_client->status.info_cnt = 0;
pres_client->dlg = NULL;
pres_client->rescheduleTimer(PJ_FALSE, 0);
// pjsip_evsub_set_mod_data(sub, modId, NULL);
}*/
// pj_log_pop_indent();
buddy->decLock();
pres_client->decLock();
}
}
/* Callback when transaction state has changed. */
void buddy_evsub_on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx, pjsip_event *event) {
void pres_client_evsub_on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx, pjsip_event *event) {
PresSubClient *buddy;
PresSubClient *pres_client;
pjsip_contact_hdr *contact_hdr;
/* Note: #937: no need to acuire PJSUA_LOCK here. Since the buddy has
* a dialog attached to it, lock_buddy() will use the dialog
/* Note: #937: no need to acuire PJSUA_LOCK here. Since the pres_client has
* a dialog attached to it, lock_pres_client() will use the dialog
* lock, which we are currently holding!
*/
buddy = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
if (!buddy) {
pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
if (!pres_client) {
return;
}
buddy->incLock();
pres_client->incLock();
/* We only use this to update buddy's Contact, when it's not
/* We only use this to update pres_client's Contact, when it's not
* set.
*/
if (buddy->contact.slen != 0) {
if (pres_client->contact.slen != 0) {
/* Contact already set */
buddy->decLock();
pres_client->decLock();
return;
}
/* Only care about 2xx response to outgoing SUBSCRIBE */
if (tsx->status_code / 100 != 2 || tsx->role != PJSIP_UAC_ROLE || event->type != PJSIP_EVENT_RX_MSG
|| pjsip_method_cmp(&tsx->method, pjsip_get_subscribe_method()) != 0) {
buddy->decLock();
pres_client->decLock();
return;
}
......@@ -229,36 +229,36 @@ void buddy_evsub_on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx, pjsip_ev
contact_hdr = (pjsip_contact_hdr*) pjsip_msg_find_hdr(event->body.rx_msg.rdata->msg_info.msg, PJSIP_H_CONTACT,
NULL);
if (!contact_hdr || !contact_hdr->uri) {
buddy->decLock();
pres_client->decLock();
return;
}
buddy->contact.ptr = (char*) pj_pool_alloc(buddy->pool, PJSIP_MAX_URL_SIZE);
buddy->contact.slen = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri, buddy->contact.ptr,
pres_client->contact.ptr = (char*) pj_pool_alloc(pres_client->pool, PJSIP_MAX_URL_SIZE);
pres_client->contact.slen = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri, pres_client->contact.ptr,
PJSIP_MAX_URL_SIZE);
if (buddy->contact.slen < 0)
buddy->contact.slen = 0;
if (pres_client->contact.slen < 0)
pres_client->contact.slen = 0;
buddy->decLock();
pres_client->decLock();
}
/* Callback called when we receive NOTIFY */
static void buddy_evsub_on_rx_notify(pjsip_evsub *sub, pjsip_rx_data *rdata, int *p_st_code, pj_str_t **p_st_text,
static void pres_client_evsub_on_rx_notify(pjsip_evsub *sub, pjsip_rx_data *rdata, int *p_st_code, pj_str_t **p_st_text,
pjsip_hdr *res_hdr, pjsip_msg_body **p_body) {
PresSubClient *buddy;
PresSubClient *pres_client;
/* Note: #937: no need to acuire PJSUA_LOCK here. Since the buddy has
* a dialog attached to it, lock_buddy() will use the dialog
/* Note: #937: no need to acuire PJSUA_LOCK here. Since the pres_client has
* a dialog attached to it, lock_pres_client() will use the dialog
* lock, which we are currently holding!
*/
buddy = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
if (!buddy){
ERROR("Couldn't create new buddy");
pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
if (!pres_client){
ERROR("Couldn't create new pres_client");
return;
}
pjsip_pres_get_status(sub, &buddy->status);
buddy->reportPresence();
pjsip_pres_get_status(sub, &pres_client->status);
pres_client->reportPresence();
/* The default is to send 200 response to NOTIFY.
* Just leave it there..
......@@ -269,7 +269,7 @@ static void buddy_evsub_on_rx_notify(pjsip_evsub *sub, pjsip_rx_data *rdata, int
PJ_UNUSED_ARG(res_hdr);
PJ_UNUSED_ARG(p_body);
buddy->decLock();
pres_client->decLock();
}
PresSubClient::PresSubClient(const std::string& uri_, SIPAccount *acc_) :
......@@ -291,14 +291,14 @@ PresSubClient::PresSubClient(const std::string& uri_, SIPAccount *acc_) :
lock_count(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, "Pres_sub_client", 512, 512, NULL);
}
PresSubClient::~PresSubClient() {
while(lock_count >0) {
usleep(200);
}
DEBUG("Destroying buddy object with uri %s", uri.ptr);
DEBUG("Destroying PresSubClient object with uri %s", uri.ptr);
rescheduleTimer(PJ_FALSE, 0);
unsubscribe();
......@@ -310,8 +310,8 @@ bool PresSubClient::isSubscribed() {
}
std::string PresSubClient::getURI() {
std::string buddyURI(uri.ptr, uri.slen);
return buddyURI;
std::string res(uri.ptr, uri.slen);
return res;
}
bool PresSubClient::isTermReason(std::string reason) {
......@@ -329,10 +329,10 @@ void PresSubClient::rescheduleTimer(bool reschedule, unsigned msec) {
if (reschedule) {
pj_time_val delay;
WARN("Resubscribing buddy %.*s in %u ms (reason: %.*s)",
WARN("Resubscribing pres_client %.*s in %u ms (reason: %.*s)",
uri.slen, uri.ptr, msec, (int) term_reason.slen, term_reason.ptr);
monitor = PJ_TRUE;
pj_timer_entry_init(&timer, 0, this, &buddy_timer_cb);
pj_timer_entry_init(&timer, 0, this, &pres_client_timer_cb);
delay.sec = 0;
delay.msec = msec;
pj_time_val_normalize(&delay);
......@@ -419,9 +419,9 @@ pj_status_t PresSubClient::updateSubscription() {
/* Event subscription callback. */
pj_bzero(&pres_callback, sizeof(pres_callback));
pres_callback.on_evsub_state = &buddy_evsub_on_state;
pres_callback.on_tsx_state = &buddy_evsub_on_tsx_state;
pres_callback.on_rx_notify = &buddy_evsub_on_rx_notify;
pres_callback.on_evsub_state = &pres_client_evsub_on_state;
pres_callback.on_tsx_state = &pres_client_evsub_on_tsx_state;
pres_callback.on_rx_notify = &pres_client_evsub_on_rx_notify;
DEBUG("PresSubClient %s: subscribing presence,using account %s..",
uri.ptr, acc->getAccountID().c_str());
......@@ -433,10 +433,10 @@ pj_status_t PresSubClient::updateSubscription() {
if (acc->contact.slen) {
contact = acc->contact;
} else {
tmp_pool = pjsua_pool_create("tmpbuddy", 512, 256);
tmp_pool = pjsua_pool_create("tmppres_client", 512, 256);
status = pjsua_acc_create_uac_contact(tmp_pool, &contact,
acc_id, &buddy->uri);
acc_id, &pres_client->uri);
if (status != PJ_SUCCESS) {
pjsua_perror(THIS_FILE, "Unable to generate Contact header",
status);
......@@ -484,22 +484,22 @@ pj_status_t PresSubClient::updateSubscription() {
if (acc->cfg.transport_id != PJSUA_INVALID_ID) {
pjsip_tpselector tp_sel;
pjsua_init_tpselector(acc->cfg.transport_id, &tp_sel);
pjsip_dlg_set_transport(buddy->dlg, &tp_sel);
pjsip_dlg_set_transport(pres_client->dlg, &tp_sel);
}
/* Set route-set */
if (!pj_list_empty(&acc->route_set)) {
pjsip_dlg_set_route_set(buddy->dlg, &acc->route_set);
pjsip_dlg_set_route_set(pres_client->dlg, &acc->route_set);
}
/* Set credentials */
if (acc->cred_cnt) {
pjsip_auth_clt_set_credentials(&buddy->dlg->auth_sess
pjsip_auth_clt_set_credentials(&pres_client->dlg->auth_sess
acc->cred_cnt, acc->cred);
}
/* Set authentication preference */
pjsip_auth_clt_set_prefs(&buddy->dlg->auth_sess, &acc->cfg.auth_pref);
pjsip_auth_clt_set_prefs(&pres_client->dlg->auth_sess, &acc->cfg.auth_pref);
#endif
modId = ((SIPVoIPLink*) acc->getVoIPLink())->getModId();
pjsip_evsub_set_mod_data(sub, modId, this);
......
......@@ -28,8 +28,8 @@
* as that of the covered work.
*/
#ifndef SIPBUDDY_H
#define SIPBUDDY_H
#ifndef PRES_SUB_CLIENT_H
#define PRES_SUB_CLIENT_H
#include <pjsip-simple/presence.h>
#include <pj/timer.h>
......@@ -47,17 +47,17 @@ class SIPAccount;
/**
* Transaction functions of event subscription client side.
*/
static void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
static void buddy_evsub_on_tsx_state(pjsip_evsub *sub,
static void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
static void pres_client_evsub_on_tsx_state(pjsip_evsub *sub,
pjsip_transaction *tsx,
pjsip_event *event);
static void buddy_evsub_on_rx_notify(pjsip_evsub *sub,
static void pres_client_evsub_on_rx_notify(pjsip_evsub *sub,
pjsip_rx_data *rdata,
int *p_st_code,
pj_str_t **p_st_text,
pjsip_hdr *res_hdr,
pjsip_msg_body **p_body);
static void buddy_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry);
static void pres_client_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry);
class PresSubClient {
......@@ -74,20 +74,20 @@ class PresSubClient {
*/
~PresSubClient();
/**
* Compare with another buddy's uris.
* @param b Other buddy pointer
* Compare with another pres_client's uris.
* @param b Other pres_client pointer
*/
bool match(PresSubClient *b);
/**
* The PBX must approve the subrciption before the buddy is added in the buddy list.
* The PBX must approve the subrciption before the pres_client is added in the pres_client list.
*/
void accept();
/**
* Send a SUBCRIBE to the PXB or directly to a buddy in the IP2IP context.
* Send a SUBCRIBE to the PXB or directly to a pres_client in the IP2IP context.
*/
bool subscribe();
/**
* Send a SUBCRIBE to the PXB or directly to a buddy in the IP2IP context but
* Send a SUBCRIBE to the PXB or directly to a pres_client in the IP2IP context but
* the 0s timeout make the dialog expire immediatly.
*/
bool unsubscribe();
......@@ -96,22 +96,22 @@ class PresSubClient {
*/
bool isSubscribed();
/**
* Return the buddy URI
* Return the pres_client URI
*/
std::string getURI();
friend void buddy_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
friend void buddy_evsub_on_tsx_state(pjsip_evsub *sub,
friend void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
friend void pres_client_evsub_on_tsx_state(pjsip_evsub *sub,
pjsip_transaction *tsx,
pjsip_event *event);
friend void buddy_evsub_on_rx_notify(pjsip_evsub *sub,
friend void pres_client_evsub_on_rx_notify(pjsip_evsub *sub,
pjsip_rx_data *rdata,
int *p_st_code,
pj_str_t **p_st_text,
pjsip_hdr *res_hdr,
pjsip_msg_body **p_body);
friend void buddy_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry);
friend void pres_client_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry);
/**
* TODO: explain this:
......@@ -151,16 +151,16 @@ class PresSubClient {
unsigned getTermCode();
SIPAccount *acc; /**< Associated SIP account pointer */
pj_str_t uri; /**< Buddy URI. */
pj_str_t uri; /**< pres_client URI. */
pj_str_t contact; /**< Contact learned from subscrp. */
pj_str_t display; /**< Buddy display name. */
pj_str_t display; /**< pres_client display name. */
pjsip_dialog *dlg; /**< The underlying dialog. */
pj_bool_t monitor; /**< Should we monitor? */
pj_str_t name; /**< Buddy name. */
pj_str_t name; /**< pres_client name. */
pj_caching_pool cp_;
pj_pool_t *pool; /**< Pool for this buddy. */
pjsip_pres_status status; /**< Buddy presence status. */
pjsip_evsub *sub; /**< Buddy presence subscription */
pj_pool_t *pool; /**< Pool for this pres_client. */
pjsip_pres_status status; /**< pres_client presence status. */
pjsip_evsub *sub; /**< pres_client presence subscription */
unsigned term_code; /**< Subscription termination code */
pj_str_t term_reason;/**< Subscription termination reason */
pj_timer_entry timer; /**< Resubscription timer */
......@@ -168,4 +168,4 @@ class PresSubClient {
int lock_count;
};
#endif /* SIPBUDDY_H */
#endif /* PRES_SUB_CLIENT_H */
......@@ -1404,10 +1404,6 @@ bool SIPAccount::matches(const std::string &userName, const std::string &server,
return false;
}
SIPPresence * SIPAccount::getPresence(){
return presence_;
}
// returns even number in range [lower, upper]
uint16_t
SIPAccount::getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range)
......
......@@ -536,7 +536,7 @@ class SIPAccount : public Account {
*/
SIPPresence * getPresence();
unsigned generateAudioPort() const;
// unsigned generateAudioPort() const;
uint16_t generateAudioPort() const;
#ifdef SFL_VIDEO
uint16_t generateVideoPort() const;
......
......@@ -154,30 +154,35 @@ void SIPPresence::subscribePresSubClient(const std::string& uri, const bool& fla
break;
}
if(pres_sub_client_list_.size() >= MAX_N_PRES_SUB_CLIENT){
WARN("Can't add PresSubClient, max number reached.");
return;
}
if(flag){
PresSubClient *b = new PresSubClient(uri, acc_);
if(!(b->subscribe())){
PresSubClient *c = new PresSubClient(uri, acc_);
if(!(c->subscribe())){
WARN("Failed send subscribe.");
delete b;
delete c;
}
// the buddy has to be accepted before being added in the list
}
}
void SIPPresence::addPresSubClient(PresSubClient *b){
void SIPPresence::addPresSubClient(PresSubClient *c){
if(pres_sub_client_list_.size() < MAX_N_PRES_SUB_CLIENT){
pres_sub_client_list_.push_back(b);
pres_sub_client_list_.push_back(c);
DEBUG("-New Presence_subscription_client client added in the list[l=%i].",pres_sub_client_list_.size());
}
else{
WARN("-Max Presence_subscription_client is reach.");
delete b;
// let the client alive //delete c;
}
}
void SIPPresence::removePresSubClient(PresSubClient *b){
void SIPPresence::removePresSubClient(PresSubClient *c){
DEBUG("-Presence_subscription_client removed from the buddy list.");
pres_sub_client_list_.remove(b);
pres_sub_client_list_.remove(c);
}
......@@ -202,7 +207,7 @@ void SIPPresence::addPresSubServer(PresSubServer *s) {
}
else{
WARN("-Max Presence_subscription_server is reach.");
delete s;
// let de server alive // delete s;
}
}
......
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