Commit 3d5d12d8 authored by Simon Morlat's avatar Simon Morlat
Browse files

implement expiration of old contact during double registration, and avoid...

implement expiration of old contact during double registration, and avoid sending an updated register if server already fixed the contact.
parent 2d669353
......@@ -478,6 +478,7 @@ static void sip_config_read(LinphoneCore *lc)
sal_use_rport(lc->sal,lp_config_get_int(lc->config,"sip","use_rport",1));
sal_use_101(lc->sal,lp_config_get_int(lc->config,"sip","use_101",1));
sal_reuse_authorization(lc->sal, lp_config_get_int(lc->config,"sip","reuse_authorization",0));
sal_expire_old_registration_contacts(lc->sal,lp_config_get_int(lc->config,"sip","expire_old_registration_contacts",0));
tmp=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
linphone_core_set_use_rfc2833_for_dtmf(lc,tmp);
......
......@@ -291,6 +291,7 @@ void sal_set_keepalive_period(Sal *ctx,unsigned int value);
unsigned int sal_get_keepalive_period(Sal *ctx);
void sal_use_session_timers(Sal *ctx, int expires);
void sal_use_double_registrations(Sal *ctx, bool_t enabled);
void sal_expire_old_registration_contacts(Sal *ctx, bool_t enabled);
void sal_reuse_authorization(Sal *ctx, bool_t enabled);
void sal_use_one_matching_codec_policy(Sal *ctx, bool_t one_matching_codec);
void sal_use_rport(Sal *ctx, bool_t use_rports);
......
......@@ -33,7 +33,7 @@ static bool_t call_failure(Sal *sal, eXosip_event_t *ev);
static void text_received(Sal *sal, eXosip_event_t *ev);
static void masquerade_via(osip_message_t *msg, const char *ip, const char *port);
static bool_t fix_message_contact(SalOp *op, osip_message_t *request,osip_message_t *last_answer);
static bool_t fix_message_contact(SalOp *op, osip_message_t *request,osip_message_t *last_answer, bool_t expire_last_contact);
static void update_contact_from_response(SalOp *op, osip_message_t *response);
void _osip_list_set_empty(osip_list_t *l, void (*freefunc)(void*)){
......@@ -283,6 +283,7 @@ Sal * sal_init(){
sal->reuse_authorization=FALSE;
sal->rootCa = 0;
sal->verify_server_certs=TRUE;
sal->expire_old_contact=FALSE;
return sal;
}
......@@ -429,6 +430,10 @@ void sal_use_double_registrations(Sal *ctx, bool_t enabled){
ctx->double_reg=enabled;
}
void sal_expire_old_registration_contacts(Sal *ctx, bool_t enabled){
ctx->expire_old_contact=enabled;
}
void sal_use_rport(Sal *ctx, bool_t use_rports){
ctx->use_rports=use_rports;
}
......@@ -1733,7 +1738,7 @@ static void masquerade_via(osip_message_t *msg, const char *ip, const char *port
}
static bool_t fix_message_contact(SalOp *op, osip_message_t *request,osip_message_t *last_answer) {
static bool_t fix_message_contact(SalOp *op, osip_message_t *request,osip_message_t *last_answer, bool_t expire_last_contact) {
osip_contact_t *ctt=NULL;
const char *received;
int rport;
......@@ -1746,6 +1751,20 @@ static bool_t fix_message_contact(SalOp *op, osip_message_t *request,osip_messag
ms_warning("fix_message_contact(): no contact to update");
return FALSE;
}
if (expire_last_contact){
osip_contact_t *oldct=ctt;
osip_generic_param_t *param=NULL;
ctt=NULL;
osip_contact_clone(oldct,&ctt);
osip_list_add(&request->contacts,ctt,0);
osip_contact_param_get_byname(oldct,"expires",&param);
if (param){
if (param->gvalue) osip_free(param->gvalue);
param->gvalue=osip_strdup("0");
}else{
osip_contact_param_add(oldct,osip_strdup("expires"),osip_strdup("0"));
}
}
if (ctt->url->host!=NULL){
osip_free(ctt->url->host);
}
......@@ -1772,29 +1791,35 @@ static bool_t register_again_with_updated_contact(SalOp *op, osip_message_t *ori
char* tmp;
osip_message_t *msg=NULL;
Sal* sal=op->base.root;
int i=0;
bool_t found_valid_contact=FALSE;
if (sal->double_reg==FALSE ) return FALSE;
if (extract_received_rport(last_answer,&received,&rport,&transport)==-1) return FALSE;
osip_message_get_contact(orig_request,0,&ctt);
osip_contact_to_str(ctt,&tmp);
ori_contact_address = sal_address_new(tmp);
do{
ctt=NULL;
osip_message_get_contact(last_answer,i,&ctt);
if (ctt==NULL) osip_message_get_contact(orig_request,0,&ctt);
if (ctt){
osip_contact_to_str(ctt,&tmp);
ori_contact_address = sal_address_new(tmp);
/*check if contact is up to date*/
if (strcmp(sal_address_get_domain(ori_contact_address),received) ==0
&& sal_address_get_port_int(ori_contact_address) == rport
&& sal_address_get_transport(ori_contact_address) == transport) {
ms_message("Register has up to date contact, doing nothing.");
osip_free(tmp);
sal_address_destroy(ori_contact_address);
return FALSE;
} else ms_message("contact do not match, need to update the register (%s with %s:%i;transport=%s)"
,tmp
,received
,rport
,sal_transport_to_string(transport));
osip_free(tmp);
sal_address_destroy(ori_contact_address);
/*check if contact is up to date*/
if (strcmp(sal_address_get_domain(ori_contact_address),received) ==0
&& sal_address_get_port_int(ori_contact_address) == rport
&& sal_address_get_transport(ori_contact_address) == transport) {
ms_message("Register response has up to date contact, doing nothing.");
found_valid_contact=TRUE;
}
osip_free(tmp);
sal_address_destroy(ori_contact_address);
}else break;
i++;
}while(!found_valid_contact);
if (!found_valid_contact)
ms_message("Contact do not match, resending register.");
else return FALSE;
eXosip_lock();
eXosip_register_build_register(op->rid,op->expires,&msg);
......@@ -1803,7 +1828,7 @@ static bool_t register_again_with_updated_contact(SalOp *op, osip_message_t *ori
ms_warning("Fail to create a contact updated register.");
return FALSE;
}
if (fix_message_contact(op,msg,last_answer)) {
if (fix_message_contact(op,msg,last_answer,op->base.root->expire_old_contact)) {
eXosip_register_send_register(op->rid,msg);
eXosip_unlock();
ms_message("Resending new register with updated contact");
......
......@@ -47,6 +47,7 @@ struct Sal{
bool_t use_101;
bool_t reuse_authorization;
bool_t verify_server_certs;
bool_t expire_old_contact;
};
struct SalOp{
......
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