diff --git a/linphone/console/commands.c b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/console/commands.c index 8204479..8232a26 100644 --- a/linphone/console/commands.c +++ b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/console/commands.c @@ -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 ' " ": initiate a call to the specified destination." }, + { "chat", lpc_cmd_chat, "Chat with a SIP uri", + "'chat \"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; } diff --git a/linphone/coreapi/chat.c b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/chat.c index c1a8849..73a5f7c 100644 --- a/linphone/coreapi/chat.c +++ b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/chat.c @@ -51,9 +51,17 @@ 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); } diff --git a/linphone/coreapi/linphonecore.c b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/linphonecore.c index 3e911ce..2632770 100644 --- a/linphone/coreapi/linphonecore.c +++ b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/linphonecore.c @@ -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; diff --git a/linphone/coreapi/private.h b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/private.h index 50de9c9..d3da450 100644 --- a/linphone/coreapi/private.h +++ b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/private.h @@ -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); diff --git a/linphone/coreapi/sal_eXosip2.c b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/sal_eXosip2.c index b160a03..18def9c 100644 --- a/linphone/coreapi/sal_eXosip2.c +++ b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/sal_eXosip2.c @@ -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,15 @@ 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(); + } }else ms_warning("call_message_new: No request ?"); } diff --git a/linphone/coreapi/sal_eXosip2_presence.c b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/sal_eXosip2_presence.c index 9d56410..c635141 100644 --- a/linphone/coreapi/sal_eXosip2_presence.c +++ b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/sal_eXosip2_presence.c @@ -71,18 +71,46 @@ 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); + static int cseq_of_original_build = 0; + static int cseq_since_last_original_build = 0; - 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; }