From 047809f6ec96653ebeab2824c9ed7110a53604e4 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 17 Mar 2010 09:42:33 +0100 Subject: [PATCH] workaround bug in eXosip with unSUBSCRIBEs. --- coreapi/friend.c | 1 - coreapi/linphonecore.c | 2 +- coreapi/sal_eXosip2.c | 15 +++++++++++++++ coreapi/sal_eXosip2_presence.c | 35 +++++++++++++++++++++++++++++++--- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index d5377952d..c7d621a5e 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -302,7 +302,6 @@ static void linphone_friend_unsubscribe(LinphoneFriend *lf){ } void linphone_friend_close_subscriptions(LinphoneFriend *lf){ - linphone_friend_notify(lf,LINPHONE_STATUS_OFFLINE); linphone_friend_unsubscribe(lf); if (lf->insub){ sal_notify_close(lf->insub); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 230776bda..35efadc56 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1401,7 +1401,7 @@ extern const char *eXosip_get_version(); static void apply_user_agent(LinphoneCore *lc){ char ua_string[256]; - snprintf(ua_string,sizeof(ua_string),"%s/%s (eXosip2/%s)",_ua_name,_ua_version, + snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version, #ifdef HAVE_EXOSIP_GET_VERSION eXosip_get_version() #else diff --git a/coreapi/sal_eXosip2.c b/coreapi/sal_eXosip2.c index 8fa1ec016..ecd5bd24f 100644 --- a/coreapi/sal_eXosip2.c +++ b/coreapi/sal_eXosip2.c @@ -158,6 +158,9 @@ void sal_op_release(SalOp *op){ } if (op->nid!=-1){ sal_remove_in_subscribe(op->base.root,op); + if (op->call_id) + osip_call_id_free(op->call_id); + op->call_id=NULL; } if (op->pending_auth){ sal_remove_pending_auth(op->base.root,op); @@ -1135,6 +1138,17 @@ static void other_request(Sal *sal, eXosip_event_t *ev){ } } +static void masquerade_via(osip_message_t *msg, const char *ip, const char *port){ + osip_via_t *via=NULL; + osip_message_get_via(msg,0,&via); + if (via){ + osip_free(via->port); + via->port=osip_strdup(port); + osip_free(via->host); + via->host=osip_strdup(ip); + } +} + static bool_t register_again_with_updated_contact(SalOp *op, osip_message_t *orig_request, osip_message_t *last_answer){ osip_message_t *msg; const char *received; @@ -1173,6 +1187,7 @@ static bool_t register_again_with_updated_contact(SalOp *op, osip_message_t *ori } snprintf(port,sizeof(port),"%i",rport); ctt->url->port=osip_strdup(port); + masquerade_via(msg,received,port); eXosip_register_send_register(op->rid,msg); eXosip_unlock(); osip_contact_to_str(ctt,&tmp); diff --git a/coreapi/sal_eXosip2_presence.c b/coreapi/sal_eXosip2_presence.c index 8b17dfea6..9e77a173a 100644 --- a/coreapi/sal_eXosip2_presence.c +++ b/coreapi/sal_eXosip2_presence.c @@ -49,7 +49,19 @@ static SalOp * sal_find_in_subscribe(Sal *sal, int nid){ return NULL; } -static void sal_add_in_subscribe(Sal *sal, SalOp *op){ +static SalOp * sal_find_in_subscribe_by_call_id(Sal *sal, osip_call_id_t *call_id){ + const MSList *elem; + SalOp *op; + for(elem=sal->in_subscribes;elem!=NULL;elem=elem->next){ + op=(SalOp*)elem->data; + if (op->call_id && osip_call_id_match(op->call_id,call_id)==0) + return op; + } + return NULL; +} + +static void sal_add_in_subscribe(Sal *sal, SalOp *op, osip_message_t *subs){ + osip_call_id_clone(subs->call_id,&op->call_id); sal->in_subscribes=ms_list_append(sal->in_subscribes,op); } @@ -423,6 +435,7 @@ int sal_notify_close(SalOp *op){ const char *identity=sal_op_get_contact(op); if (identity==NULL) identity=sal_op_get_to(op); osip_message_set_contact(msg,identity); + add_presence_body(msg,SalPresenceOffline); eXosip_insubscription_send_request(op->did,msg); }else ms_error("sal_notify_close(): could not create notify for incoming subscription" " did=%i, nid=%i",op->did,op->nid); @@ -582,7 +595,7 @@ int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus p return 0; } -void sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){ +static void _sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){ SalOp *op=sal_op_new(sal); char *tmp; op->did=ev->did; @@ -594,10 +607,26 @@ void sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){ osip_from_to_str(ev->request->to,&tmp); sal_op_set_to(op,tmp); ms_free(tmp); - sal_add_in_subscribe(sal,op); + sal_add_in_subscribe(sal,op,ev->request); sal->callbacks.subscribe_received(op,sal_op_get_from(op)); } +void sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){ + /*workaround a bug in eXosip: incoming SUBSCRIBES within dialog with expires: 0 are + recognized as new incoming subscribes*/ + SalOp *op=sal_find_in_subscribe_by_call_id(sal,ev->request->call_id); + if (op){ + osip_header_t *h; + osip_message_header_get_byname(ev->request,"expires",0,&h); + if (h && h->hvalue && atoi(h->hvalue)==0){ + ms_warning("This susbscribe is not a new one but terminates an old one."); + ev->did=op->did; + ev->nid=op->nid; + sal_exosip_subscription_closed(sal,ev); + }else ms_warning("Probably a refresh subscribe"); + }else _sal_exosip_subscription_recv(sal,ev); +} + void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){ SalOp *op=sal_find_out_subscribe(sal,ev->sid); char *tmp;