]> sjero.net Git - linphone/commitdiff
support for in call MESSAGEs
authorSimon Morlat <simon.morlat@linphone.org>
Thu, 1 Apr 2010 09:41:13 +0000 (11:41 +0200)
committerSimon Morlat <simon.morlat@linphone.org>
Thu, 1 Apr 2010 09:41:13 +0000 (11:41 +0200)
refer improvements.

console/commands.c
console/linphonec.c
coreapi/callbacks.c
coreapi/chat.c
coreapi/linphonecore.c
coreapi/private.h
coreapi/sal_eXosip2.c
coreapi/sal_eXosip2_presence.c

index 82044797e7b2ce14a3098aeb85a0a73dc4cbb0bb..8232a26fda2e5a03e42fe290ff34d5865e352f9f 100644 (file)
@@ -53,6 +53,7 @@ extern char *lpc_strip_blanks(char *input);
 static int lpc_cmd_help(LinphoneCore *, char *);
 static int lpc_cmd_proxy(LinphoneCore *, char *);
 static int lpc_cmd_call(LinphoneCore *, char *);
+static int lpc_cmd_chat(LinphoneCore *, char *);
 static int lpc_cmd_answer(LinphoneCore *, char *);
 static int lpc_cmd_autoanswer(LinphoneCore *, char *);
 static int lpc_cmd_terminate(LinphoneCore *, char *);
@@ -122,6 +123,10 @@ LPC_COMMAND commands[] = {
                "'call <sip-url>' "
                ": initiate a call to the specified destination."
                },
+       { "chat", lpc_cmd_chat, "Chat with a SIP uri",
+               "'chat <sip-url> \"message\"' "
+               ": send a chat message \"message\" to the specified destination."
+               },
        { "terminate", lpc_cmd_terminate, "Terminate the current call",
                NULL },
        { "answer", lpc_cmd_answer, "Answer a call",
@@ -388,6 +393,35 @@ lpc_cmd_call(LinphoneCore *lc, char *args)
        return 1;
 }
 
+static int
+lpc_cmd_chat(LinphoneCore *lc, char *args)
+{
+       char *arg1 = args;
+       char *arg2 = NULL;
+       char *ptr = args;
+
+       if (!args) return 0;
+
+       /* Isolate first and second arg */
+       while(*ptr && !isspace(*ptr)) ++ptr;
+       if ( *ptr )
+       {
+               *ptr='\0';
+               arg2=ptr+1;
+               while(*arg2 && isspace(*arg2)) ++arg2;
+       }
+       else
+       {
+               /* missing one parameter */
+               return 0;
+       }
+       LinphoneChatRoom *cr = linphone_core_create_chat_room(lc,arg1);
+       linphone_chat_room_send_message(cr,arg2);
+       linphone_chat_room_destroy(cr);
+
+       return 1;
+}
+
 const char *linphonec_get_callee(){
        return callee_name;
 }
index ff68fbecd37099fee0a160241f6326b993c40815..a64c3ba2719558cf3e45abe334f46682b50499ad 100644 (file)
@@ -115,6 +115,7 @@ static char **linephonec_readline_completion(const char *text,
 static void linphonec_call_received(LinphoneCore *lc, const char *from);
 static void linphonec_prompt_for_auth(LinphoneCore *lc, const char *realm,
        const char *username);
+static void linphonec_display_refer (LinphoneCore * lc,const char *refer_to);
 static void linphonec_display_something (LinphoneCore * lc, const char *something);
 static void linphonec_display_url (LinphoneCore * lc, const char *something, const char *url);
 static void linphonec_display_warning (LinphoneCore * lc, const char *something);
@@ -188,7 +189,8 @@ LinphoneCoreVTable linphonec_vtable
        .display_question=(DisplayQuestionCb)stub,
        .text_received=linphonec_text_received,
        .general_state=linphonec_general_state,
-       .dtmf_received=linphonec_dtmf_received
+       .dtmf_received=linphonec_dtmf_received,
+       .refer_received=linphonec_display_refer
 }
 #endif /*_WIN32_WCE*/
 ;
@@ -201,6 +203,16 @@ LinphoneCoreVTable linphonec_vtable
  *
  ***************************************************************************/
 
+/*
+ * Linphone core callback
+ */
+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);
+       fflush(stdout);
+}
+
 /*
  * Linphone core callback
  */
index 7da3b4b3074b5d766ecc9f16da4e1d7755405d6f..edc8cfa5e738fb0e246db73245046406b59c5633 100644 (file)
@@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "linphonecore.h"
 #include "private.h"
 #include "mediastreamer2/mediastream.h"
+#include "sal_eXosip2.h"
 
 static void linphone_connect_incoming(LinphoneCore *lc, LinphoneCall *call){
        if (lc->vtable.show)
@@ -391,7 +392,19 @@ 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)
                lc->vtable.refer_received(lc,referto);
 }
index c1a8849647f0c640ea054e0d4c6c0e7f98c74fd7..73a5f7c9a1ef08205c46d87613de7adbe253ab94 100644 (file)
  
 void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg){
        const char *identity=linphone_core_get_identity(cr->lc);
-       SalOp *op=sal_op_new(cr->lc->sal);
-
-       sal_op_set_route(op,cr->route);
+       SalOp *op;
+       if(linphone_core_is_in_communication_with(cr->lc,cr->peer))
+       {
+               ms_message("send SIP message into the call\n");
+               op = cr->lc->call->op;
+       }
+       else
+       {
+               op = sal_op_new(cr->lc->sal);
+               sal_op_set_route(op,cr->route);
+       }
        sal_text_send(op,identity,cr->peer,msg);
 }
 
index 3e911cee1d730925eb8422afaa8d08ab41f1fe69..263277070707a0cb76ae9bbf43f200a54938897c 100644 (file)
@@ -1769,6 +1769,25 @@ const char * linphone_core_get_route(LinphoneCore *lc){
        return route;
 }
 
+bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to)
+{
+       char *tmp;
+       bool_t returned;
+       const LinphoneAddress *la=linphone_core_get_remote_uri(lc);
+       if(la == NULL)
+       {
+               return FALSE;
+       }
+       tmp = linphone_address_as_string(la);
+       if(!strcmp(tmp,to))
+               returned = TRUE;
+       else
+               returned = FALSE;
+       if(tmp)
+               ms_free(tmp);
+       return returned;
+}
+
 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
        const MSList *elem;
        LinphoneProxyConfig *found_cfg=NULL;
index 50de9c9c6fd194bebf780de26516a05cfa72aa94..d3da450b95c37eacc3837be10f9c01a3e45d112f 100644 (file)
@@ -177,6 +177,7 @@ void linphone_core_start_media_streams(LinphoneCore *lc, struct _LinphoneCall *c
 void linphone_core_stop_media_streams(LinphoneCore *lc, struct _LinphoneCall *call);
 const char * linphone_core_get_identity(LinphoneCore *lc);
 const char * linphone_core_get_route(LinphoneCore *lc);
+bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to);
 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose);
 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progresses);
 void linphone_core_stop_waiting(LinphoneCore *lc);
index b160a03bd8b7e17751aa3eac8090a09384b848ac..82bae962a05bc10cfe2b93853047d332ee1177f2 100644 (file)
@@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 /*this function is not declared in some versions of eXosip*/
 extern void *eXosip_call_get_reference(int cid);
 
+static void text_received(Sal *sal, eXosip_event_t *ev);
+
 static void _osip_list_set_empty(osip_list_t *l, void (*freefunc)(void*)){
        void *data;
        while((data=osip_list_get(l,0))!=NULL){
@@ -1075,6 +1077,45 @@ static void call_message_new(Sal *sal, eXosip_event_t *ev){
                                eXosip_unlock();
                        }
                }
+               if(MSG_IS_MESSAGE(ev->request)){
+                       /* SIP messages could be received into call */
+                       text_received(sal, ev);
+                       eXosip_lock();
+                       eXosip_call_build_answer(ev->tid,200,&ans);
+                       if (ans)
+                               eXosip_call_send_answer(ev->tid,200,ans);
+                       eXosip_unlock();
+               }
+               if(MSG_IS_REFER(ev->request)){
+                       osip_header_t *h=NULL;
+                       ms_message("Receiving REFER request !");
+                       osip_message_header_get_byname(ev->request,"Refer-To",0,&h);
+                       eXosip_lock();
+                       eXosip_call_build_answer(ev->tid,202,&ans);
+                       if (ans)
+                               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);
+                       }
+               }
+               if(MSG_IS_NOTIFY(ev->request)){
+                       osip_header_t *h=NULL;
+                       ms_message("Receiving NOTIFY request !");
+                       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");
+                               }
+                       }
+                       eXosip_lock();
+                       eXosip_call_build_answer(ev->tid,200,&ans);
+                       if (ans)
+                               eXosip_call_send_answer(ev->tid,200,ans);
+                       eXosip_unlock();
+               }
        }else ms_warning("call_message_new: No request ?");
 }
 
@@ -1146,7 +1187,8 @@ 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){
-                               sal->callbacks.refer_received(sal,NULL,h->hvalue);
+                               SalOp *op=(SalOp*)ev->external_reference;
+                               sal->callbacks.refer_received(sal,op,h->hvalue);
                        }
                }else ms_warning("Ignored REFER not coming from this local loopback interface.");
        }else if (strncmp(ev->request->sip_method, "UPDATE", 6) == 0){
index 9d56410242e17e48a1341767c151187d737e05c6..ed775abc33e554f8fda3c489b4dc093943563278 100644 (file)
@@ -71,18 +71,44 @@ void sal_remove_in_subscribe(Sal *sal, SalOp *op){
 
 int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg){
        osip_message_t *sip=NULL;
-       if (from)
-               sal_op_set_from(op,from);
-       if (to)
-               sal_op_set_to(op,to);
 
-       eXosip_lock();
-       eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
-           sal_op_get_from(op),sal_op_get_route(op));
-       osip_message_set_content_type(sip,"text/plain");
-       osip_message_set_body(sip,msg,strlen(msg));
-       eXosip_message_send_request(sip);
-       eXosip_unlock();
+       if(op->cid == -1)
+       {
+               /* we are not currently in communication with the destination */
+               if (from)
+                       sal_op_set_from(op,from);
+               if (to)
+                       sal_op_set_to(op,to);
+
+               eXosip_lock();
+               eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
+                       sal_op_get_from(op),sal_op_get_route(op));
+               osip_message_set_content_type(sip,"text/plain");
+               osip_message_set_body(sip,msg,strlen(msg));
+               eXosip_message_send_request(sip);
+               eXosip_unlock();
+       }
+       else
+       {
+               /* we are currently in communication with the destination */
+               eXosip_lock();
+               //First we generate an INFO message to get the current call_id and a good cseq
+               eXosip_call_build_info(op->did,&sip);
+               if(sip == NULL)
+               {
+                       ms_warning("could not get a build info to send MESSAGE, maybe no previous call established ?");
+                       osip_message_free(sip);
+                       eXosip_unlock();
+                       return -1;
+               }
+               osip_free(sip->sip_method);
+               //change the sip_message to be a MESSAGE ...
+               osip_message_set_method(sip,osip_strdup("MESSAGE"));
+               osip_message_set_content_type(sip,"text/plain");
+               osip_message_set_body(sip,msg,strlen(msg));
+               eXosip_message_send_request(sip);
+               eXosip_unlock();
+       }
        return 0;
 }