]> sjero.net Git - linphone/commitdiff
refer improvements, and caught refers
authorSimon Morlat <simon.morlat@linphone.org>
Thu, 8 Apr 2010 08:19:23 +0000 (10:19 +0200)
committerSimon Morlat <simon.morlat@linphone.org>
Thu, 8 Apr 2010 08:19:23 +0000 (10:19 +0200)
console/linphonec.c
coreapi/callbacks.c
coreapi/linphonecore.c
coreapi/linphonecore.h
coreapi/presence.c
coreapi/sal.h
coreapi/sal_eXosip2.c
coreapi/sal_eXosip2_presence.c
gtk-glade/main.c

index a64c3ba2719558cf3e45abe334f46682b50499ad..2d1ce98b31640c079acac2d24c5b4973fd20973b 100644 (file)
@@ -120,7 +120,8 @@ static void linphonec_display_something (LinphoneCore * lc, const char *somethin
 static void linphonec_display_url (LinphoneCore * lc, const char *something, const char *url);
 static void linphonec_display_warning (LinphoneCore * lc, const char *something);
 static void stub () {}
-static void linphonec_notify_received(LinphoneCore *lc,LinphoneFriend *fid);
+static void linphonec_notify_received(LinphoneCore *lc,const char *from,const char *msg);
+static void linphonec_notify_presence_received(LinphoneCore *lc,LinphoneFriend *fid);
 static void linphonec_new_unknown_subscriber(LinphoneCore *lc,
                LinphoneFriend *lf, const char *url);
 static void linphonec_bye_received(LinphoneCore *lc, const char *from);
@@ -176,6 +177,7 @@ LinphoneCoreVTable linphonec_vtable
        .inv_recv = linphonec_call_received,
        .bye_recv = linphonec_bye_received,
        .notify_recv = linphonec_notify_received,
+       .notify_presence_recv = linphonec_notify_presence_received,
        .new_unknown_subscriber = linphonec_new_unknown_subscriber,
        .auth_info_requested = linphonec_prompt_for_auth,
        .display_status = linphonec_display_status,
@@ -209,7 +211,7 @@ LinphoneCoreVTable linphonec_vtable
 static void
 linphonec_display_refer (LinphoneCore * lc,const char *refer_to)
 {
-       fprintf (stdout, "The distant end point asked to transfer the call to %s,don't forget to terminate the call\n%s", refer_to,prompt);
+       fprintf (stdout, "The distant end point asked to transfer the call to %s,don't forget to terminate the call if not\n%s", refer_to,prompt);
        fflush(stdout);
 }
 
@@ -294,7 +296,21 @@ linphonec_prompt_for_auth(LinphoneCore *lc, const char *realm, const char *usern
  * Linphone core callback
  */
 static void
-linphonec_notify_received(LinphoneCore *lc,LinphoneFriend *fid)
+linphonec_notify_received(LinphoneCore *lc,const char *from,const char *msg)
+{
+       printf("Notify type %s from %s\n", msg, from);
+       if(!strcmp(msg,"refer"))
+       {
+               printf("The distant SIP end point get the refer we can close the call\n");
+               linphonec_parse_command_line(linphonec, "terminate");
+       }
+}
+
+/*
+ * Linphone core callback
+ */
+static void
+linphonec_notify_presence_received(LinphoneCore *lc,LinphoneFriend *fid)
 {
        char *tmp=linphone_address_as_string(linphone_friend_get_address(fid));
        printf("Friend %s is %s\n", tmp, linphone_online_status_to_string(linphone_friend_get_status(fid)));
@@ -608,7 +624,7 @@ int _tmain(int argc, _TCHAR* wargv[]) {
        linphonec_vtable.show =(ShowInterfaceCb) stub;
        linphonec_vtable.inv_recv = linphonec_call_received;
        linphonec_vtable.bye_recv = linphonec_bye_received;
-       linphonec_vtable.notify_recv = linphonec_notify_received;
+       linphonec_vtable.notify_presence_recv = linphonec_notify_received;
        linphonec_vtable.new_unknown_subscriber = linphonec_new_unknown_subscriber;
        linphonec_vtable.auth_info_requested = linphonec_prompt_for_auth;
        linphonec_vtable.display_status = linphonec_display_status;
index 54615315e5a6813ca48d696de2f785e4b8e09bd2..30c4b2ef728017aac6ee7a2185ecb7514a03afa4 100644 (file)
@@ -392,21 +392,11 @@ static void dtmf_received(SalOp *op, char dtmf){
 }
 
 static void refer_received(Sal *sal, SalOp *op, const char *referto){
-       osip_message_t *msg;
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
-       if(op != NULL)
-       {
-               eXosip_call_build_notify(op->tid,EXOSIP_SUBCRSTATE_ACTIVE,&msg);
-               if(msg != NULL)
-               {
-                       osip_message_set_header(msg,(const char *)"event","refer");
-                       osip_message_set_content_type(msg,"message/sipfrag");
-                       osip_message_set_body(msg,"SIP/2.0 100 Trying",sizeof("SIP/2.0 100 Trying"));
-                       eXosip_call_send_request(op->tid,msg);
-               }
-       }
-       if (lc->vtable.refer_received)
+       if (lc->vtable.refer_received){
                lc->vtable.refer_received(lc,referto);
+               if (op) sal_refer_accept(op);
+       }
 }
 
 static void text_received(Sal *sal, const char *from, const char *msg){
@@ -414,7 +404,15 @@ static void text_received(Sal *sal, const char *from, const char *msg){
        linphone_core_text_received(lc,from,msg);
 }
 
-static void notify(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg){
+static void notify(SalOp *op, const char *from, const char *msg){
+       LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
+
+       ms_message("get a %s notify from %s",msg,from);
+       if(lc->vtable.notify_recv)
+               lc->vtable.notify_recv(lc,from,msg);
+}
+
+static void notify_presence(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
        linphone_notify_recv(lc,op,ss,status);
 }
@@ -462,6 +460,7 @@ SalCallbacks linphone_sal_callbacks={
        refer_received,
        text_received,
        notify,
+       notify_presence,
        subscribe_received,
        subscribe_closed,
        internal_message,
index d77379451e4f53093be61984b9af213374cb6c61..3d82d677b7ba65597f1a176cb7531a46d4985d91 100644 (file)
@@ -1997,7 +1997,7 @@ int linphone_core_refer(LinphoneCore *lc, const char *url)
                ms_warning("No established call to refer.");
                return -1;
        }
-       lc->call=NULL;
+       //lc->call=NULL; //Do not do that you will lose the call afterward . . .
        real_url=linphone_address_as_string (real_parsed_url);
        sal_refer(call->op,real_url);
        ms_free(real_url);
index 9e2c20d23b7226a8cc7f05bdf178e91b1a28b782..46d9e29441c5e2f0a0647cf38232cbb97274b343 100644 (file)
@@ -391,7 +391,9 @@ typedef void (*DisplayQuestionCb)(struct _LinphoneCore *lc, const char *message)
 /** Callback prototype */
 typedef void (*LinphoneCoreCbFunc)(struct _LinphoneCore *lc,void * user_data);
 /** Callback prototype */
-typedef void (*NotifyReceivedCb)(struct _LinphoneCore *lc, LinphoneFriend * fid);
+typedef void (*NotifyReceivedCb)(struct _LinphoneCore *lc, const char *from, const char *msg);
+/** Callback prototype */
+typedef void (*NotifyPresenceReceivedCb)(struct _LinphoneCore *lc, LinphoneFriend * fid);
 /** Callback prototype */
 typedef void (*NewUnknownSubscriberCb)(struct _LinphoneCore *lc, LinphoneFriend *lf, const char *url);
 /** Callback prototype */
@@ -418,7 +420,7 @@ typedef struct _LinphoneVTable
        ShowInterfaceCb show; /**< Notifies the application that it should show up*/
        InviteReceivedCb inv_recv; /**< Notifies incoming calls */
        ByeReceivedCb bye_recv; /**< Notify calls terminated by far end*/
-       NotifyReceivedCb notify_recv; /**< Notify received presence events*/
+       NotifyPresenceReceivedCb notify_presence_recv; /**< Notify received presence events*/
        NewUnknownSubscriberCb new_unknown_subscriber; /**< Notify about unknown subscriber */
        AuthInfoRequested auth_info_requested; /**< Ask the application some authentication information */
        DisplayStatusCb display_status; /**< Callback that notifies various events with human readable text.*/
@@ -432,6 +434,7 @@ typedef struct _LinphoneVTable
        DtmfReceived dtmf_received; /**< A dtmf has been received received */
        ReferReceived refer_received; /**< A refer was received */
        BuddyInfoUpdated buddy_info_updated; /**< a LinphoneFriend's BuddyInfo has changed*/
+       NotifyReceivedCb notify_recv; /**< Other notifications*/
 } LinphoneCoreVTable;
 
 /**
index 4367130d5e605da284bda1046c56711ed928458a..8d9d39474525b66299b9f22de290376699b3bf6a 100644 (file)
@@ -130,7 +130,7 @@ void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeState ss, Sal
                tmp=linphone_address_as_string(friend);
                lf->status=estatus;
                lf->subscribe_active=TRUE;
-               lc->vtable.notify_recv(lc,(LinphoneFriend*)lf);
+               lc->vtable.notify_presence_recv(lc,(LinphoneFriend*)lf);
                ms_free(tmp);
        }else{
                ms_message("But this person is not part of our friend list, so we don't care.");
index 6c930244376d5f5d17544f166b9879f36b345d41..23780f6b322d61f68287dfcc95c57b6d3ffefb9b 100644 (file)
@@ -183,7 +183,8 @@ typedef void (*SalOnVfuRequest)(SalOp *op);
 typedef void (*SalOnDtmfReceived)(SalOp *op, char dtmf);
 typedef void (*SalOnRefer)(Sal *sal, SalOp *op, const char *referto);
 typedef void (*SalOnTextReceived)(Sal *sal, const char *from, const char *msg);
-typedef void (*SalOnNotify)(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg);
+typedef void (*SalOnNotify)(SalOp *op, const char *from, const char *value);
+typedef void (*SalOnNotifyPresence)(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg);
 typedef void (*SalOnSubscribeReceived)(SalOp *salop, const char *from);
 typedef void (*SalOnSubscribeClosed)(SalOp *salop, const char *from);
 typedef void (*SalOnInternalMsg)(Sal *sal, const char *msg);
@@ -206,6 +207,7 @@ typedef struct SalCallbacks{
        SalOnRefer refer_received;
        SalOnTextReceived text_received;
        SalOnNotify notify;
+       SalOnNotifyPresence notify_presence;
        SalOnSubscribeReceived subscribe_received;
        SalOnSubscribeClosed subscribe_closed;
        SalOnInternalMsg internal_message;
@@ -256,6 +258,7 @@ int sal_call_accept(SalOp*h);
 int sal_call_decline(SalOp *h, SalReason reason, const char *redirection /*optional*/);
 SalMediaDescription * sal_call_get_final_media_description(SalOp *h);
 int sal_refer(SalOp *h, const char *refer_to);
+int sal_refer_accept(SalOp *h);
 int sal_call_send_dtmf(SalOp *h, char dtmf);
 int sal_call_terminate(SalOp *h);
 bool_t sal_call_autoanswer_asked(SalOp *op);
index 82bae962a05bc10cfe2b93853047d332ee1177f2..4e0f6a05a848b6fe93fe9e6721280419d5ca2bc6 100644 (file)
@@ -278,6 +278,8 @@ void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs){
                ctx->callbacks.dtmf_received=(SalOnDtmfReceived)unimplemented_stub;
        if (ctx->callbacks.notify==NULL)
                ctx->callbacks.notify=(SalOnNotify)unimplemented_stub;
+       if (ctx->callbacks.notify_presence==NULL)
+               ctx->callbacks.notify_presence=(SalOnNotifyPresence)unimplemented_stub;
        if (ctx->callbacks.subscribe_received==NULL)
                ctx->callbacks.subscribe_received=(SalOnSubscribeReceived)unimplemented_stub;
        if (ctx->callbacks.text_received==NULL)
@@ -533,6 +535,26 @@ int sal_ping(SalOp *op, const char *from, const char *to){
        return -1;
 }
 
+int sal_refer_accept(SalOp *op){
+       osip_message_t *msg=NULL;
+       int err=0;
+       eXosip_lock();
+       err = eXosip_call_build_notify(op->did,EXOSIP_SUBCRSTATE_ACTIVE,&msg);
+       if(msg != NULL)
+       {
+               osip_message_set_header(msg,(const char *)"event","refer");
+               osip_message_set_content_type(msg,"message/sipfrag");
+               osip_message_set_body(msg,"SIP/2.0 100 Trying",sizeof("SIP/2.0 100 Trying"));
+               eXosip_call_send_request(op->did,msg);
+       }
+       else
+       {
+               ms_error("could not get a notify built\n");
+       }
+       eXosip_unlock();
+       return err;
+}
+
 int sal_refer(SalOp *h, const char *refer_to){
        osip_message_t *msg=NULL;
        int err=0;
@@ -934,7 +956,7 @@ static bool_t call_failure(Sal *sal, eXosip_event_t *ev){
        SalError error=SalErrorUnknown;
        SalReason sr=SalReasonUnknown;
        
-       op=(SalOp*)ev->external_reference;
+       op=(SalOp*)find_op(sal,ev);
 
        if (op==NULL) {
                ms_warning("Call failure reported for a closed call, ignored.");
@@ -995,7 +1017,7 @@ static bool_t call_failure(Sal *sal, eXosip_event_t *ev){
 
 
 static void process_media_control_xml(Sal *sal, eXosip_event_t *ev){
-       SalOp *op=(SalOp*)ev->external_reference;
+       SalOp *op=find_op(sal,ev);
        osip_body_t *body=NULL;
 
        if (op==NULL){
@@ -1018,7 +1040,7 @@ static void process_media_control_xml(Sal *sal, eXosip_event_t *ev){
 }
 
 static void process_dtmf_relay(Sal *sal, eXosip_event_t *ev){
-       SalOp *op=(SalOp*)ev->external_reference;
+       SalOp *op=find_op(sal,ev);
        osip_body_t *body=NULL;
 
        if (op==NULL){
@@ -1088,6 +1110,8 @@ static void call_message_new(Sal *sal, eXosip_event_t *ev){
                }
                if(MSG_IS_REFER(ev->request)){
                        osip_header_t *h=NULL;
+                       SalOp *op=find_op(sal,ev);
+                       
                        ms_message("Receiving REFER request !");
                        osip_message_header_get_byname(ev->request,"Refer-To",0,&h);
                        eXosip_lock();
@@ -1096,25 +1120,30 @@ static void call_message_new(Sal *sal, eXosip_event_t *ev){
                                eXosip_call_send_answer(ev->tid,202,ans);
                        eXosip_unlock();
                        if (h){
-                               SalOp *op=(SalOp*)ev->external_reference;
                                sal->callbacks.refer_received(sal,op,h->hvalue);
                        }
+                       else
+                       {
+                               ms_warning("cannot do anything with the refer without destination\n");
+                       }
                }
                if(MSG_IS_NOTIFY(ev->request)){
                        osip_header_t *h=NULL;
+                       char *from=NULL;
+                       SalOp *op=find_op(sal,ev);
+
                        ms_message("Receiving NOTIFY request !");
+                       osip_from_to_str(ev->request->from,&from);
                        osip_message_header_get_byname(ev->request,"Event",0,&h);
-                       if (h){
-                               if(!strcmp(h->hvalue,"refer"))
-                               {
-                                       ms_message("get the notify of the Refer sent");
-                               }
-                       }
+                       if(h)
+                               sal->callbacks.notify(op,from,h->hvalue);
+                       /*answer that we received the notify*/
                        eXosip_lock();
                        eXosip_call_build_answer(ev->tid,200,&ans);
                        if (ans)
                                eXosip_call_send_answer(ev->tid,200,ans);
                        eXosip_unlock();
+                       osip_free(from);
                }
        }else ms_warning("call_message_new: No request ?");
 }
@@ -1187,8 +1216,7 @@ static void other_request(Sal *sal, eXosip_event_t *ev){
                        osip_message_header_get_byname(ev->request,"Refer-To",0,&h);
                        eXosip_message_send_answer(ev->tid,200,NULL);
                        if (h){
-                               SalOp *op=(SalOp*)ev->external_reference;
-                               sal->callbacks.refer_received(sal,op,h->hvalue);
+                               sal->callbacks.refer_received(sal,NULL,h->hvalue);
                        }
                }else ms_warning("Ignored REFER not coming from this local loopback interface.");
        }else if (strncmp(ev->request->sip_method, "UPDATE", 6) == 0){
@@ -1343,6 +1371,7 @@ static void other_request_reply(Sal *sal,eXosip_event_t *ev){
 }
 
 static bool_t process_event(Sal *sal, eXosip_event_t *ev){
+       ms_message("linphone process event get a message %d\n",ev->type);
        switch(ev->type){
                case EXOSIP_CALL_ANSWERED:
                        ms_message("CALL_ANSWERED\n");
index ed775abc33e554f8fda3c489b4dc093943563278..3555907109a4aa340c033be1d98ae77ed3983223 100644 (file)
@@ -711,7 +711,7 @@ void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){
                op->did=-1;
                ms_message("And outgoing subscription terminated by remote.");
        }
-       sal->callbacks.notify(op,op->sid!=-1 ? SalSubscribeActive : SalSubscribeTerminated, estatus,NULL);
+       sal->callbacks.notify_presence(op,op->sid!=-1 ? SalSubscribeActive : SalSubscribeTerminated, estatus,NULL);
        osip_free(tmp);
 }
 
@@ -752,7 +752,7 @@ void sal_exosip_subscription_closed(Sal *sal,eXosip_event_t *ev){
        sal_remove_out_subscribe(sal,op);
        op->sid=-1;
        op->did=-1;
-       sal->callbacks.notify(op,SalSubscribeTerminated, SalPresenceOffline,NULL);
+       sal->callbacks.notify_presence(op,SalSubscribeTerminated, SalPresenceOffline,NULL);
 }
 
 
index 64927abaca428bdf862ea5516a4a73057b02fcac..6785c3d44319f822e9cd2242820ff7de772116b3 100644 (file)
@@ -59,7 +59,7 @@ static LinphoneCoreVTable vtable={
        .show=linphone_gtk_show,
        .inv_recv=linphone_gtk_inv_recv,
        .bye_recv=linphone_gtk_bye_recv,
-       .notify_recv=linphone_gtk_notify_recv,
+       .notify_presence_recv=linphone_gtk_notify_recv,
        .new_unknown_subscriber=linphone_gtk_new_unknown_subscriber,
        .auth_info_requested=linphone_gtk_auth_info_requested,
        .display_status=linphone_gtk_display_status,