diff --git a/linphone_official/console/commands.c b/linphone_modified/console/commands.c index d32e626..3a8ac73 100644 --- a/linphone_official/console/commands.c +++ b/linphone_modified/console/commands.c @@ -75,6 +75,7 @@ static int lpc_cmd_ports(LinphoneCore *lc, char *args); static int lpc_cmd_speak(LinphoneCore *lc, char *args); static int lpc_cmd_codec(LinphoneCore *lc, char *args); static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args); +static int lpc_cmd_chat_in_call(LinphoneCore *lc, char *args); /* Command handler helpers */ static void linphonec_proxy_add(LinphoneCore *lc); @@ -120,6 +121,10 @@ LPC_COMMAND commands[] = { "'call ' " ": initiate a call to the specified destination." }, + { "chat", lpc_cmd_chat_in_call, "Chat during call", + "'chat \"message\"' " + ": send a chat message into the current call." + }, { "terminate", lpc_cmd_terminate, "Terminate the current call", NULL }, { "answer", lpc_cmd_answer, "Answer a call", @@ -1683,6 +1688,27 @@ static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){ return 1; } +static int lpc_cmd_chat_in_call(LinphoneCore *lc, char *args){ + + if ( ! args || ! *args ) + { + return 0; + } + if ( lc->call == NULL ) + { + linphonec_out("You have to be in call to send chat message into call.\n"); + } + else + { + int returned; + char *tmp = strchr(args ,'\n'); + if (tmp) *tmp = 0; + if((returned = linphone_send_message_into_call(lc,lc->call,args)) != 0) + printf("problem sending message %d\n",returned); + } + return 1; +} + /*************************************************************************** * * Command table management funx diff --git a/linphone_official/coreapi/chat.c b/linphone_modified/coreapi/chat.c index 9552627..6f88f9e 100644 --- a/linphone_official/coreapi/chat.c +++ b/linphone_modified/coreapi/chat.c @@ -25,7 +25,8 @@ #include "linphonecore.h" #include "private.h" #include - + #include + LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to){ LinphoneAddress *parsed_url=NULL; char *route; @@ -112,3 +113,70 @@ void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud){ void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr){ return cr->user_data; } + +int linphone_send_message_into_call(struct _LinphoneCore *lc,struct _LinphoneCall *call, const char *msg){ + const char *identity=linphone_core_get_identity(lc); + char *to; + LinphoneAddress *parsed_url=NULL; + char *route; + osip_message_t *sip=NULL; + osip_message_t *tmpsip=NULL; + osip_transaction_t *tr = NULL; + int temp; + char c_temp[256]; + static int cseq_of_original_build = 0; + static int cseq_since_last_original_build = 0; + + if(call == NULL) + { + lc->vtable.display_warning(lc,_("could not send MESSAGE the call do not exist")); + return -1; //we are not in call cannot send message into it + } + //build an INFO SIP message to get the good CallId and the good first Cseq for SIP MESSAGE + eXosip_call_build_info(call->did,&tmpsip); + if(tmpsip == NULL) + { + lc->vtable.display_warning(lc,_("could not get a build info to send MESSAGE, maybe no previous call established ?")); + osip_message_free(tmpsip); + return -4; + } + //get the to header into string + osip_to_to_str(tmpsip->to,&to); + if (!linphone_core_interpret_url(lc,to,&parsed_url,&route)) + { + lc->vtable.display_warning(lc,_("could not interpret urls to send MESSAGE")); + osip_message_free(tmpsip); + return -5; + } + //building our request + eXosip_message_build_request(&sip,"MESSAGE", linphone_address_as_string(parsed_url), identity , route); + osip_message_set_content_type(sip,"text/plain"); + osip_message_set_body(sip,msg,strlen(msg)); + //replace the CALL-ID + if(osip_call_id_clone(tmpsip->call_id, &(sip->call_id)) != OSIP_SUCCESS) + { + lc->vtable.display_warning(lc,_("could not clone the call ID to send MESSAGE")); + osip_message_free(sip); + osip_message_free(tmpsip); + return -6; + } + //Increment the orginal CSEQ + temp = atoi(osip_cseq_get_number(tmpsip->cseq)); + ms_message("we just get cseq : %d => %s\n",temp, osip_cseq_get_number(tmpsip->cseq)); + if(temp != cseq_of_original_build) + { + //it means that we are in a different call we have to restart counting Cseq + cseq_of_original_build = temp; + cseq_since_last_original_build = cseq_of_original_build; + ms_message("new Cseq: %d\n",cseq_of_original_build); + } + cseq_since_last_original_build++; + snprintf(c_temp,sizeof(c_temp),"%d",cseq_since_last_original_build); + ms_message("we will use cseq : %d => %s\n",cseq_since_last_original_build, c_temp); + osip_cseq_set_number(sip->cseq,osip_strdup(c_temp)); + + eXosip_message_send_request(sip); + osip_message_free(tmpsip); + return 0; +} + diff --git a/linphone_official/coreapi/exevents.c b/linphone_modified/coreapi/exevents.c index 36ed2b6..4a02f40 100644 --- a/linphone_official/coreapi/exevents.c +++ b/linphone_modified/coreapi/exevents.c @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include static int linphone_answer_sdp(LinphoneCore *lc, eXosip_event_t *ev, sdp_message_t *sdp); +static void linphone_other_request(LinphoneCore *lc, eXosip_event_t *ev); static bool_t linphone_call_matches_event(LinphoneCall *call, eXosip_event_t *ev){ return call->cid==ev->cid; @@ -940,6 +941,15 @@ void linphone_call_message_new(LinphoneCore *lc, eXosip_event_t *ev){ eXosip_call_send_answer(ev->tid,200,ans); } } + if(MSG_IS_MESSAGE(ev->request)){ + linphone_core_text_received(lc,ev); + eXosip_call_build_answer(ev->tid,200,&ans); + if (ans) + { + ms_message("generate an answer to the SIP MESSAGE\n"); + eXosip_call_send_answer(ev->tid,200,ans); + } + } }else ms_warning("linphone_call_message_new: No request ?"); } diff --git a/linphone_official/coreapi/linphonecore.h b/linphone_modified/coreapi/linphonecore.h index 0796a6d..0a3db51 100644 --- a/linphone_official/coreapi/linphonecore.h +++ b/linphone_modified/coreapi/linphonecore.h @@ -459,6 +459,7 @@ void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg); void linphone_chat_room_destroy(LinphoneChatRoom *cr); void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud); void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr); +int linphone_send_message_into_call(struct _LinphoneCore *lc,struct _LinphoneCall *call, const char *msg); /* describes the different groups of states */ typedef enum _gstate_group {