Commit 2cf1e6d9 authored by jehan's avatar jehan

implement text messaging

parent 38898c61
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
</tool> </tool>
</toolChain> </toolChain>
</folderInfo> </folderInfo>
<sourceEntries>
<entry excluding="coreapi/sal_eXosip2.h" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration> </configuration>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
...@@ -69,6 +72,9 @@ ...@@ -69,6 +72,9 @@
</tool> </tool>
</toolChain> </toolChain>
</folderInfo> </folderInfo>
<sourceEntries>
<entry excluding="coreapi/sal_eXosip2.h|coreapi/sal_eXosip2.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration> </configuration>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
......
...@@ -45,7 +45,8 @@ liblinphone_la_SOURCES+= bellesip_sal/sal_address_impl.c \ ...@@ -45,7 +45,8 @@ liblinphone_la_SOURCES+= bellesip_sal/sal_address_impl.c \
bellesip_sal/sal_op_impl.c \ bellesip_sal/sal_op_impl.c \
bellesip_sal/sal_op_call.c \ bellesip_sal/sal_op_call.c \
bellesip_sal/sal_op_registration.c \ bellesip_sal/sal_op_registration.c \
bellesip_sal/sal_sdp.c bellesip_sal/sal_sdp.c \
bellesip_sal/sal_op_message.c
else else
liblinphone_la_SOURCES+= sal_eXosip2.c sal_eXosip2.h\ liblinphone_la_SOURCES+= sal_eXosip2.c sal_eXosip2.h\
sal_eXosip2_sdp.c \ sal_eXosip2_sdp.c \
......
...@@ -63,8 +63,12 @@ static void process_request_event(void *sal, const belle_sip_request_event_t *ev ...@@ -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_dialog_t* dialog=belle_sip_request_event_get_dialog(event);
belle_sip_header_address_t* origin_address; belle_sip_header_address_t* origin_address;
belle_sip_header_address_t* 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_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) { if (dialog) {
op=(SalOp*)belle_sip_dialog_get_application_data(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 ...@@ -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=sal_op_new((Sal*)sal);
op->dir=SalOpDirIncoming; op->dir=SalOpDirIncoming;
sal_op_call_fill_cbs(op); 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 { } else {
ms_error("sal process_request_event not implemented yet for method [%s]",belle_sip_request_get_method(req)); ms_error("sal process_request_event not implemented yet for method [%s]",belle_sip_request_get_method(req));
return; return;
} }
if (!op->base.from_address) { 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_header))
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_header)));
,belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from)));
sal_op_set_from_address(op,(SalAddress*)address); sal_op_set_from_address(op,(SalAddress*)address);
belle_sip_object_unref(address); belle_sip_object_unref(address);
} }
if (!op->base.to_address) { if (!op->base.to_address) {
to=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_to_t); 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)) address=belle_sip_header_address_create(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(to))
......
...@@ -87,11 +87,7 @@ belle_sip_request_t* sal_op_build_request(SalOp *op,const char* method) { ...@@ -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*/ /*presence Subscribe/notify*/
int sal_subscribe_presence(SalOp *op, const char *from, const char *to){ int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
......
...@@ -36,13 +36,15 @@ aliases=localhost sipopen.example.org sip.example.org ...@@ -36,13 +36,15 @@ aliases=localhost sipopen.example.org sip.example.org
# 'sip.linphone.org' used in SIP messages. Bind address won't appear: # 'sip.linphone.org' used in SIP messages. Bind address won't appear:
# transports=sips:sip.linphone.org:6060;maddr=192.168.0.29 # transports=sips:sip.linphone.org:6060;maddr=192.168.0.29
# Default value: sip:* # 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 # An absolute path of a directory where TLS server certificate and
# private key can be found, concatenated inside an 'agent.pem' file. # private key can be found, concatenated inside an 'agent.pem' file.
# Default value: /etc/flexisip/tls # Default value: /etc/flexisip/tls
#tls-certificates-dir=/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. ## STUN server parameters.
......
...@@ -82,6 +82,8 @@ typedef struct _stats { ...@@ -82,6 +82,8 @@ typedef struct _stats {
int number_of_LinphoneCallIncomingEarlyMedia; int number_of_LinphoneCallIncomingEarlyMedia;
int number_of_LinphoneCallUpdated; int number_of_LinphoneCallUpdated;
int number_of_LinphoneCallReleased; int number_of_LinphoneCallReleased;
int number_of_LinphoneMessageReceived;
}stats; }stats;
static stats global_stat; static stats global_stat;
...@@ -243,7 +245,7 @@ static LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* ...@@ -243,7 +245,7 @@ static LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char*
reset_counters(counters); reset_counters(counters);
CU_ASSERT_EQUAL(ms_list_size(linphone_core_get_proxy_config_list(lc)),proxy_count); 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_LinphoneRegistrationOk<proxy_count && retry++ <20) {
linphone_core_iterate(lc); linphone_core_iterate(lc);
ms_usleep(100000); ms_usleep(100000);
} }
...@@ -293,6 +295,15 @@ static void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCal ...@@ -293,6 +295,15 @@ static void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCal
} }
} }
static void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message) {
char* from=linphone_address_as_string(from_address);
ms_message("Message from [%s] is [%s]",from,message);
ms_free(from);
stats* counters = (stats*)linphone_core_get_user_data(lc);
counters->number_of_LinphoneMessageReceived++;
}
static bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value) { static bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value) {
int retry=0; int retry=0;
while (*counter<value && retry++ <20) { while (*counter<value && retry++ <20) {
...@@ -318,21 +329,27 @@ typedef struct _LinphoneCoreManager { ...@@ -318,21 +329,27 @@ typedef struct _LinphoneCoreManager {
LinphoneCoreVTable v_table; LinphoneCoreVTable v_table;
LinphoneCore* lc; LinphoneCore* lc;
stats stat; stats stat;
LinphoneAddress* identity;
} LinphoneCoreManager; } LinphoneCoreManager;
static LinphoneCoreManager* linphone_core_manager_new(const char* rc_file) { static LinphoneCoreManager* linphone_core_manager_new(const char* rc_file) {
LinphoneCoreManager* mgr= malloc(sizeof(LinphoneCoreManager)); LinphoneCoreManager* mgr= malloc(sizeof(LinphoneCoreManager));
LinphoneProxyConfig* proxy;
memset (mgr,0,sizeof(LinphoneCoreManager)); memset (mgr,0,sizeof(LinphoneCoreManager));
mgr->v_table.registration_state_changed=registration_state_changed; mgr->v_table.registration_state_changed=registration_state_changed;
mgr->v_table.call_state_changed=call_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); mgr->lc=configure_lc_from(&mgr->v_table,rc_file,1);
enable_codec(mgr->lc,"PCMU",8000); enable_codec(mgr->lc,"PCMU",8000);
linphone_core_set_user_data(mgr->lc,&mgr->stat); 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; return mgr;
} }
static void linphone_core_manager_destroy(LinphoneCoreManager* mgr) { static void linphone_core_manager_destroy(LinphoneCoreManager* mgr) {
linphone_core_destroy(mgr->lc); linphone_core_destroy(mgr->lc);
linphone_address_destroy(mgr->identity);
free(mgr); free(mgr);
} }
...@@ -340,11 +357,10 @@ static bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_m ...@@ -340,11 +357,10 @@ static bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_m
LinphoneProxyConfig* proxy; LinphoneProxyConfig* proxy;
linphone_core_get_default_proxy(callee_mgr->lc,&proxy); linphone_core_get_default_proxy(callee_mgr->lc,&proxy);
CU_ASSERT_PTR_NOT_NULL_FATAL(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");*/ /*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)); 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() { ...@@ -523,6 +539,17 @@ static void call_srtp() {
linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline); 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 () { int init_test_suite () {
...@@ -574,6 +601,9 @@ CU_pSuite pSuite = CU_add_suite("liblinphone", init, uninit); ...@@ -574,6 +601,9 @@ CU_pSuite pSuite = CU_add_suite("liblinphone", init, uninit);
if (NULL == CU_add_test(pSuite, "call_srtp", call_srtp)) { if (NULL == CU_add_test(pSuite, "call_srtp", call_srtp)) {
return CU_get_error(); return CU_get_error();
} }
if (NULL == CU_add_test(pSuite, "text_message", text_message)) {
return CU_get_error();
}
return 0; return 0;
} }
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
......
...@@ -4,6 +4,7 @@ sip_tcp_port=5082 ...@@ -4,6 +4,7 @@ sip_tcp_port=5082
sip_tls_port=5083 sip_tls_port=5083
default_proxy=0 default_proxy=0
ping_with_options=0 ping_with_options=0
register_only_when_network_is_up=0
[auth_info_0] [auth_info_0]
username=marie username=marie
......
...@@ -4,6 +4,7 @@ sip_tcp_port=5072 ...@@ -4,6 +4,7 @@ sip_tcp_port=5072
sip_tls_port=5073 sip_tls_port=5073
default_proxy=0 default_proxy=0
ping_with_options=0 ping_with_options=0
register_only_when_network_is_up=0
[auth_info_0] [auth_info_0]
username=pauline username=pauline
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment