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..2a1f256 100644 --- a/linphone/coreapi/chat.c +++ b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/chat.c @@ -51,9 +51,16 @@ 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)) + { + 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..2c7c937 100644 --- a/linphone/coreapi/linphonecore.c +++ b/my_version_to_patch/linphone_with_chat_message_supported_via_proxy/coreapi/linphonecore.c @@ -1769,6 +1769,19 @@ const char * linphone_core_get_route(LinphoneCore *lc){ return route; } +bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to) +{ + if(!linphone_core_in_call(lc)) + { + return FALSE; + } + if(!strcmp(sal_op_get_to(lc->call->op),to) || !strcmp(sal_op_get_from(lc->call->op),to) ) + { + return TRUE; + } + return FALSE; +} + 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..cca04fd 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,11 @@ static void call_message_new(Sal *sal, eXosip_event_t *ev){ eXosip_unlock(); } } + if(MSG_IS_MESSAGE(ev->request)){ + /* SIP messages are received here when registered on a proxy */ + text_received(sal, ev); + eXosip_message_send_answer(ev->tid,200,NULL); + } }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..f1cb31e 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,72 @@ 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 */ + osip_message_t *tmpsip=NULL; + int temp; + char c_temp[256]; + + eXosip_call_build_info(op->did,&tmpsip); + if(tmpsip == NULL) + { + ms_warning("could not get a build info to send MESSAGE, maybe no previous call established ?"); + osip_message_free(tmpsip); + return -1; + } + 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)); + + //replace the CALL-ID + if(osip_call_id_clone(tmpsip->call_id, &(sip->call_id)) != OSIP_SUCCESS) + { + ms_warning("could not clone the call ID to send MESSAGE"); + osip_message_free(sip); + osip_message_free(tmpsip); + eXosip_unlock(); + return -2; + } + //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); + eXosip_unlock(); + } return 0; }