From 2cf1e6d964537e2a0543082af7d3036f1caf9874 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Sun, 4 Nov 2012 20:16:35 +0100 Subject: [PATCH] implement text messaging --- .cproject | 6 +++++ coreapi/Makefile.am | 3 ++- coreapi/bellesip_sal/sal_impl.c | 30 ++++++++++++++++++--- coreapi/bellesip_sal/sal_op_impl.c | 6 +---- tester/flexisip.conf | 6 +++-- tester/liblinphone_tester.c | 42 +++++++++++++++++++++++++----- tester/marie_rc | 1 + tester/pauline_rc | 1 + 8 files changed, 77 insertions(+), 18 deletions(-) diff --git a/.cproject b/.cproject index da5a8e1df..c44aac2bb 100644 --- a/.cproject +++ b/.cproject @@ -34,6 +34,9 @@ + + + @@ -69,6 +72,9 @@ + + + diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 028db827c..61ee670a0 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -45,7 +45,8 @@ liblinphone_la_SOURCES+= bellesip_sal/sal_address_impl.c \ bellesip_sal/sal_op_impl.c \ bellesip_sal/sal_op_call.c \ bellesip_sal/sal_op_registration.c \ - bellesip_sal/sal_sdp.c + bellesip_sal/sal_sdp.c \ + bellesip_sal/sal_op_message.c else liblinphone_la_SOURCES+= sal_eXosip2.c sal_eXosip2.h\ sal_eXosip2_sdp.c \ diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index cb22d53f9..855596610 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -63,8 +63,12 @@ static void process_request_event(void *sal, const belle_sip_request_event_t *ev belle_sip_dialog_t* dialog=belle_sip_request_event_get_dialog(event); belle_sip_header_address_t* origin_address; belle_sip_header_address_t* address; - belle_sip_header_from_t* from; + belle_sip_header_from_t* from_header; belle_sip_header_to_t* to; + belle_sip_header_content_type_t* content_type; + from_header=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_from_t); + + char* from; if (dialog) { op=(SalOp*)belle_sip_dialog_get_application_data(dialog); @@ -72,18 +76,36 @@ static void process_request_event(void *sal, const belle_sip_request_event_t *ev op=sal_op_new((Sal*)sal); op->dir=SalOpDirIncoming; sal_op_call_fill_cbs(op); + } else if (strcmp("MESSAGE",belle_sip_request_get_method(req))==0) { + content_type=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_content_type_t); + if (content_type + && strcmp("text",belle_sip_header_content_type_get_type(content_type))==0 + && strcmp("plain",belle_sip_header_content_type_get_subtype(content_type))==0) { + address=belle_sip_header_address_create(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(from_header)) + ,belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from_header))); + from=belle_sip_object_to_string(BELLE_SIP_OBJECT(address)); + ((Sal*)sal)->callbacks.text_received((Sal*)sal,from,belle_sip_message_get_body(BELLE_SIP_MESSAGE(req))); + belle_sip_object_unref(address); + belle_sip_free(from); + return; + } else { + ms_error("Unsupported MESSAGE with content type [%s/%s]",belle_sip_header_content_type_get_type(content_type) + ,belle_sip_header_content_type_get_subtype(content_type)); + return; + } } else { ms_error("sal process_request_event not implemented yet for method [%s]",belle_sip_request_get_method(req)); return; } if (!op->base.from_address) { - from=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_from_t); - address=belle_sip_header_address_create(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(from)) - ,belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from))); + address=belle_sip_header_address_create(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(from_header)) + ,belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from_header))); sal_op_set_from_address(op,(SalAddress*)address); belle_sip_object_unref(address); } + + if (!op->base.to_address) { to=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_to_t); address=belle_sip_header_address_create(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(to)) diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index a178ade97..5cce9bb1a 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -87,11 +87,7 @@ belle_sip_request_t* sal_op_build_request(SalOp *op,const char* method) { } -/*Messaging */ -int sal_text_send(SalOp *op, const char *from, const char *to, const char *text){ - ms_fatal("sal_text_send not implemented yet"); - return -1; -} + /*presence Subscribe/notify*/ int sal_subscribe_presence(SalOp *op, const char *from, const char *to){ diff --git a/tester/flexisip.conf b/tester/flexisip.conf index b9d5b94a0..22acf0937 100755 --- a/tester/flexisip.conf +++ b/tester/flexisip.conf @@ -36,13 +36,15 @@ aliases=localhost sipopen.example.org sip.example.org # 'sip.linphone.org' used in SIP messages. Bind address won't appear: # transports=sips:sip.linphone.org:6060;maddr=192.168.0.29 # Default value: sip:* -transports=sip:192.168.56.101:5060 sips:192.168.56.101:5061 +#transports=sip:192.168.56.101:5060 sips:192.168.56.101:5061 +transports=sip:127.0.0.1:5060 sips:127.0.0.1:5061 # An absolute path of a directory where TLS server certificate and # private key can be found, concatenated inside an 'agent.pem' file. # Default value: /etc/flexisip/tls #tls-certificates-dir=/etc/flexisip/tls -tls-certificates-dir=/media/sf_workspaces/workspace-macosx/flexisip +#tls-certificates-dir=/media/sf_workspaces/workspace-macosx/flexisip +tls-certificates-dir=/Users/jehanmonnier/workspaces/workspace-macosx/flexisip ## ## STUN server parameters. diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index def062827..23c50f88b 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -82,6 +82,8 @@ typedef struct _stats { int number_of_LinphoneCallIncomingEarlyMedia; int number_of_LinphoneCallUpdated; int number_of_LinphoneCallReleased; + + int number_of_LinphoneMessageReceived; }stats; static stats global_stat; @@ -243,7 +245,7 @@ static LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* reset_counters(counters); CU_ASSERT_EQUAL(ms_list_size(linphone_core_get_proxy_config_list(lc)),proxy_count); - while (counters->number_of_LinphoneRegistrationOk<3 && retry++ <20) { + while (counters->number_of_LinphoneRegistrationOknumber_of_LinphoneMessageReceived++; +} + static bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value) { int retry=0; while (*counterv_table.registration_state_changed=registration_state_changed; mgr->v_table.call_state_changed=call_state_changed; - + mgr->v_table.text_received=text_message_received; mgr->lc=configure_lc_from(&mgr->v_table,rc_file,1); enable_codec(mgr->lc,"PCMU",8000); linphone_core_set_user_data(mgr->lc,&mgr->stat); + linphone_core_get_default_proxy(mgr->lc,&proxy); + mgr->identity = linphone_address_new(linphone_proxy_config_get_identity(proxy)); + linphone_address_clean(mgr->identity); return mgr; } static void linphone_core_manager_destroy(LinphoneCoreManager* mgr) { linphone_core_destroy(mgr->lc); + linphone_address_destroy(mgr->identity); free(mgr); } @@ -340,11 +357,10 @@ static bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_m LinphoneProxyConfig* proxy; linphone_core_get_default_proxy(callee_mgr->lc,&proxy); CU_ASSERT_PTR_NOT_NULL_FATAL(proxy); - LinphoneAddress* dest_identity = linphone_address_new(linphone_proxy_config_get_identity(proxy)); - linphone_address_clean(dest_identity); - CU_ASSERT_PTR_NOT_NULL_FATAL(linphone_core_invite_address(caller_mgr->lc,dest_identity)); - linphone_address_destroy(dest_identity); + + CU_ASSERT_PTR_NOT_NULL_FATAL(linphone_core_invite_address(caller_mgr->lc,callee_mgr->identity)); + /*linphone_core_invite(caller_mgr->lc,"pauline");*/ CU_ASSERT_TRUE_FATAL(wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallIncomingReceived,1)); @@ -523,6 +539,17 @@ static void call_srtp() { linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } +static void text_message() { + LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc"); + char* to = linphone_address_as_string(marie->identity); + LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc,to); + linphone_chat_room_send_message(chat_room,"Bla bla bla bla"); + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1)); + + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} int init_test_suite () { @@ -574,6 +601,9 @@ CU_pSuite pSuite = CU_add_suite("liblinphone", init, uninit); if (NULL == CU_add_test(pSuite, "call_srtp", call_srtp)) { return CU_get_error(); } + if (NULL == CU_add_test(pSuite, "text_message", text_message)) { + return CU_get_error(); + } return 0; } int main (int argc, char *argv[]) { diff --git a/tester/marie_rc b/tester/marie_rc index b0cb5c761..95c30a0e1 100644 --- a/tester/marie_rc +++ b/tester/marie_rc @@ -4,6 +4,7 @@ sip_tcp_port=5082 sip_tls_port=5083 default_proxy=0 ping_with_options=0 +register_only_when_network_is_up=0 [auth_info_0] username=marie diff --git a/tester/pauline_rc b/tester/pauline_rc index cba6b564f..07e0efa25 100644 --- a/tester/pauline_rc +++ b/tester/pauline_rc @@ -4,6 +4,7 @@ sip_tcp_port=5072 sip_tls_port=5073 default_proxy=0 ping_with_options=0 +register_only_when_network_is_up=0 [auth_info_0] username=pauline