diff --git a/linphone/console/linphonec.c b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/console/linphonec.c index a64c3ba..2d1ce98 100644 --- a/linphone/console/linphonec.c +++ b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/console/linphonec.c @@ -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; diff --git a/linphone/coreapi/callbacks.c b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/callbacks.c index 5461531..14ddeed 100644 --- a/linphone/coreapi/callbacks.c +++ b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/callbacks.c @@ -396,6 +396,7 @@ static void refer_received(Sal *sal, SalOp *op, const char *referto){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal); if(op != NULL) { + eXosip_lock(); eXosip_call_build_notify(op->tid,EXOSIP_SUBCRSTATE_ACTIVE,&msg); if(msg != NULL) { @@ -404,6 +405,7 @@ static void refer_received(Sal *sal, SalOp *op, const char *referto){ osip_message_set_body(msg,"SIP/2.0 100 Trying",sizeof("SIP/2.0 100 Trying")); eXosip_call_send_request(op->tid,msg); } + eXosip_unlock(); } if (lc->vtable.refer_received) lc->vtable.refer_received(lc,referto); @@ -414,7 +416,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 +472,7 @@ SalCallbacks linphone_sal_callbacks={ refer_received, text_received, notify, + notify_presence, subscribe_received, subscribe_closed, internal_message, diff --git a/linphone/coreapi/linphonecore.c b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/linphonecore.c index d773794..3d82d67 100644 --- a/linphone/coreapi/linphonecore.c +++ b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/linphonecore.c @@ -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); diff --git a/linphone/coreapi/linphonecore.h b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/linphonecore.h index 9e2c20d..e1dfda4 100644 --- a/linphone/coreapi/linphonecore.h +++ b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/linphonecore.h @@ -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 */ @@ -419,6 +421,7 @@ typedef struct _LinphoneVTable 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.*/ diff --git a/linphone/coreapi/presence.c b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/presence.c index 4367130..8d9d394 100644 --- a/linphone/coreapi/presence.c +++ b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/presence.c @@ -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."); diff --git a/linphone/coreapi/sal.h b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/sal.h index 6c93024..bea4260 100644 --- a/linphone/coreapi/sal.h +++ b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/sal.h @@ -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; diff --git a/linphone/coreapi/sal_eXosip2.c b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/sal_eXosip2.c index 82bae96..30963e8 100644 --- a/linphone/coreapi/sal_eXosip2.c +++ b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/sal_eXosip2.c @@ -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) @@ -1099,22 +1101,28 @@ static void call_message_new(Sal *sal, eXosip_event_t *ev){ 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=(SalOp*)ev->external_reference; + 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(); + ms_free(from); } }else ms_warning("call_message_new: No request ?"); } @@ -1343,6 +1351,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"); diff --git a/linphone/coreapi/sal_eXosip2_presence.c b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/sal_eXosip2_presence.c index ed775ab..3555907 100644 --- a/linphone/coreapi/sal_eXosip2_presence.c +++ b/my_version_to_patch/linphone_with_improved_refer_and_catch_refer/coreapi/sal_eXosip2_presence.c @@ -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); }