]> sjero.net Git - linphone/commitdiff
workaround bug in eXosip with unSUBSCRIBEs.
authorSimon Morlat <simon.morlat@linphone.org>
Wed, 17 Mar 2010 08:42:33 +0000 (09:42 +0100)
committerSimon Morlat <simon.morlat@linphone.org>
Wed, 17 Mar 2010 08:42:33 +0000 (09:42 +0100)
coreapi/friend.c
coreapi/linphonecore.c
coreapi/sal_eXosip2.c
coreapi/sal_eXosip2_presence.c

index d5377952d3c2780f67970c5c6833343fbb32e9e8..c7d621a5e5e74442b70ff89d48ebbe52e7c51a89 100644 (file)
@@ -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);
index 230776bda3fc644033d65a930724ec50629a6ddf..35efadc5601ec87c3dcbb8dfbcb96beba0943fea 100644 (file)
@@ -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
index 8fa1ec01617741deb8b0b3ebe13480f600b5f061..ecd5bd24f14b1f1f001e5b287149eb3b9c30f438 100644 (file)
@@ -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);
index 8b17dfea670f0e39f58aff1f695c69c29a746b1a..9e77a173a59e0a27068c4c1312712ec3807a6928 100644 (file)
@@ -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;