From 66044e773d7951957f61ad9c29483212b1285ba9 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 28 Jul 2014 15:15:35 +0200 Subject: [PATCH 1/6] Factorization of linphone_configure_op for every linphone core requests --- coreapi/linphonecall.c | 10 +++++----- coreapi/proxy.c | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index edfd973d2..f8c6d1d72 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -701,7 +701,6 @@ void linphone_call_set_compatible_incoming_call_parameters(LinphoneCall *call, c LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){ LinphoneCall *call=ms_new0(LinphoneCall,1); - char *from_str; const SalMediaDescription *md; LinphoneFirewallPolicy fpol; @@ -721,12 +720,13 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro /*the following sends an option request back to the caller so that we get a chance to discover our nat'd address before answering.*/ call->ping_op=sal_op_new(lc->sal); - from_str=linphone_address_as_string_uri_only(from); + + linphone_configure_op(lc, call->ping_op, from, NULL, FALSE); + sal_op_set_route(call->ping_op,sal_op_get_network_origin(op)); sal_op_set_user_pointer(call->ping_op,call); - sal_op_set_realm(call->ping_op,linphone_proxy_config_get_realm(linphone_core_lookup_known_proxy(call->core, to))); - sal_ping(call->ping_op,linphone_core_find_best_identity(lc,from),from_str); - ms_free(from_str); + + sal_ping(call->ping_op,sal_op_get_from(call->ping_op), sal_op_get_to(call->ping_op)); } } diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 619c98814..e6a33d556 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -412,6 +412,7 @@ void _linphone_proxy_config_unregister(LinphoneProxyConfig *obj) { static void linphone_proxy_config_register(LinphoneProxyConfig *obj){ if (obj->reg_sendregister){ LinphoneAddress* proxy=linphone_address_new(obj->reg_proxy); + LinphoneAddress* to=linphone_address_new(obj->reg_identity); char* proxy_string; LinphoneAddress *contact; ms_message("LinphoneProxyConfig [%p] about to register (LinphoneCore version: %s)",obj,linphone_core_get_version()); @@ -420,12 +421,18 @@ static void linphone_proxy_config_register(LinphoneProxyConfig *obj){ if (obj->op) sal_op_release(obj->op); obj->op=sal_op_new(obj->lc->sal); + + linphone_configure_op(obj->lc, obj->op, to, NULL, FALSE); + linphone_address_destroy(to); + if ((contact=guess_contact_for_register(obj))) { sal_op_set_contact_address(obj->op,contact); linphone_address_destroy(contact); } + sal_op_set_user_pointer(obj->op,obj); - sal_op_set_realm(obj->op, obj->realm); + + if (sal_register(obj->op,proxy_string,obj->reg_identity,obj->expires)==0) { linphone_proxy_config_set_state(obj,LinphoneRegistrationProgress,"Registration in progress"); } else { @@ -967,11 +974,15 @@ int linphone_proxy_config_send_publish(LinphoneProxyConfig *proxy, LinphonePrese if (proxy->state==LinphoneRegistrationOk || proxy->state==LinphoneRegistrationCleared){ if (proxy->publish_op==NULL){ + LinphoneAddress *to=linphone_address_new(linphone_proxy_config_get_identity(proxy)); proxy->publish_op=sal_op_new(proxy->lc->sal); - sal_op_set_route(proxy->publish_op,proxy->reg_proxy); - sal_op_set_from(proxy->publish_op,linphone_proxy_config_get_identity(proxy)); - sal_op_set_to(proxy->publish_op,linphone_proxy_config_get_identity(proxy)); - sal_op_set_realm(proxy->publish_op,linphone_proxy_config_get_realm(proxy)); + + linphone_configure_op(proxy->lc, proxy->publish_op, + to, NULL, FALSE); + + if (to!=NULL){ + linphone_address_destroy(to); + } if (lp_config_get_int(proxy->lc->config,"sip","publish_msg_with_contact",0)){ SalAddress *addr=sal_address_new(linphone_proxy_config_get_identity(proxy)); sal_op_set_contact_address(proxy->publish_op,addr); From d8cc5b600f3771b101f52c2da0761b78a3b4e947 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Tue, 29 Jul 2014 14:11:21 +0200 Subject: [PATCH 2/6] Add JNI wrapper for linphone proxy config realm parameter --- coreapi/linphonecore_jni.cc | 13 +++++++++++++ .../org/linphone/core/LinphoneProxyConfig.java | 17 +++++++++++++++-- .../linphone/core/LinphoneProxyConfigImpl.java | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 609493b3e..1f01ccadf 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -3033,6 +3033,19 @@ JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_getQual return jvalue; } +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_setRealm(JNIEnv *env, jobject thiz, jlong ptr, jstring jrealm) { + if (jrealm){ + const char *realm=env->GetStringUTFChars(jrealm, NULL); + linphone_proxy_config_set_realm((LinphoneProxyConfig *)ptr, realm); + env->ReleaseStringUTFChars(jrealm,realm); + } +} + +JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_getRealm(JNIEnv *env, jobject thiz, jlong ptr) { + jstring jvalue = env->NewStringUTF(linphone_proxy_config_get_realm((LinphoneProxyConfig *)ptr)); + return jvalue; +} + extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv* env,jobject thiz,jlong ptr) { return (jint)linphone_call_get_duration((LinphoneCall *) ptr); } diff --git a/java/common/org/linphone/core/LinphoneProxyConfig.java b/java/common/org/linphone/core/LinphoneProxyConfig.java index 711a53668..8b668da2e 100644 --- a/java/common/org/linphone/core/LinphoneProxyConfig.java +++ b/java/common/org/linphone/core/LinphoneProxyConfig.java @@ -224,6 +224,19 @@ public interface LinphoneProxyConfig { */ String getQualityReportingCollector(); + /** + * Set the outbound proxy realm. It is used in digest authentication to avoid + * re-authentication if a previous token has already been provided. + * @param The new outbound proxy realm. + */ + void setRealm(String realm); + + /** + * Get the outbound proxy realm. + * @return The outbound proxy realm. + */ + String getRealm(); + /** * Set optional contact parameters that will be added to the contact information sent in the registration. * @param contact_params a string containing the additional parameters in text form, like "myparam=something;myparam2=something_else" @@ -287,12 +300,12 @@ public interface LinphoneProxyConfig { * @return the publish expiration time in second. Default value is the registration expiration value. */ public int getPublishExpires(); - + /** * attached a user data to a proxy config **/ void setUserData(Object obj); - + /** * Returns user data from a proxy config. return null if any * @return an Object. diff --git a/java/impl/org/linphone/core/LinphoneProxyConfigImpl.java b/java/impl/org/linphone/core/LinphoneProxyConfigImpl.java index b7c301297..5113f958c 100644 --- a/java/impl/org/linphone/core/LinphoneProxyConfigImpl.java +++ b/java/impl/org/linphone/core/LinphoneProxyConfigImpl.java @@ -321,6 +321,7 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig { isValid(); return getQualityReportingInterval(nativePtr); } + private native void setQualityReportingCollector(long nativePtr, String collector); @Override public void setQualityReportingCollector(String collector) { @@ -334,6 +335,21 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig { isValid(); return getQualityReportingCollector(nativePtr); } + + private native void setRealm(long nativePtr, String realm); + @Override + public void setRealm(String realm) { + isValid(); + setRealm(nativePtr, realm); + } + private native String getRealm(long nativePtr); + @Override + public String getRealm() { + + isValid(); + return getRealm(nativePtr); + } + private native void setPublishExpires(long nativePtr, int expires); @Override public void setPublishExpires(int expires) { From ce24877b9d1fa7443de62c5a2f795d4542507775 Mon Sep 17 00:00:00 2001 From: Johan Pascal Date: Tue, 29 Jul 2014 21:16:01 +0200 Subject: [PATCH 3/6] File transfer: add a cancel function to the core - allow cancellation during upload or download + fix bug in file transfer message tester --- coreapi/chat.c | 48 +++++++++++++--- coreapi/linphonecore.h | 3 +- coreapi/private.h | 5 +- tester/message_tester.c | 121 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 158 insertions(+), 19 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index e445d2bfa..28c1741ba 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -48,10 +48,13 @@ static size_t linphone_chat_message_compute_filepart_header_size(const char *fil } static void process_io_error(void *data, const belle_sip_io_error_event_t *event){ LinphoneChatMessage* msg=(LinphoneChatMessage *)data; + ms_error("I/O Error during file upload or download to/from %s - msg [%p] chat room[%p]", msg->chat_room->lc->file_transfer_server, msg, msg->chat_room); msg->cb(msg, LinphoneChatMessageStateNotDelivered, msg->chat_room->lc); } static void process_auth_requested(void *data, belle_sip_auth_event_t *event){ - printf("We have a auth requested!\n"); + LinphoneChatMessage* msg=(LinphoneChatMessage *)data; + ms_error("Error during file upload or download : auth requested to connect %s - msg [%p] chat room[%p]", msg->chat_room->lc->file_transfer_server, msg, msg->chat_room); + msg->cb(msg, LinphoneChatMessageStateNotDelivered, msg->chat_room->lc); } /** @@ -157,9 +160,14 @@ static void linphone_chat_message_process_response_from_post_file(void *data, co cbs.process_io_error=process_io_error; cbs.process_auth_requested=process_auth_requested; l=belle_http_request_listener_create_from_callbacks(&cbs,msg); + msg->http_request=req; /* update the reference to the http request to be able to cancel it during upload */ belle_http_provider_send_request(msg->chat_room->lc->http_provider,req,l); } - if (code == 200 ) { /* file has been uplaoded correctly, get server reply and send it */ + if (code == 200 ) { /* file has been uploaded correctly, get server reply and send it */ + /* TODO Check that the transfer has not been cancelled, note this shall be removed once the belle sip API will provide a cancel request as we shall never reach this part if the transfer is actually cancelled */ + if (msg->http_request == NULL) { + return; + } const char *body = belle_sip_message_get_body((belle_sip_message_t *)event->response); msg->message = ms_strdup(body); linphone_content_uninit(msg->file_transfer_information); @@ -338,6 +346,7 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM cbs.process_io_error=process_io_error; cbs.process_auth_requested=process_auth_requested; l=belle_http_request_listener_create_from_callbacks(&cbs,msg); /* give msg to listener to be able to start the actual file upload when server answer a 204 No content */ + msg->http_request = req; /* keep a reference on the request to be able to cancel it */ belle_http_provider_send_request(cr->lc->http_provider,req,l); linphone_chat_message_unref(msg); return; @@ -371,8 +380,8 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM content_type=ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"",msg->external_body_url); sal_message_send(op,identity,cr->peer,content_type, NULL); ms_free(content_type); - } else { - if (msg->content_type == NULL) { + } else { /* the message is either text or have a file transfer using RCS recommendation */ + if (msg->content_type == NULL) { /* if no content type is specified, it is a text message */ sal_text_send(op, identity, cr->peer,msg->message); } else { sal_message_send(op, identity, cr->peer, msg->content_type, msg->message); @@ -450,7 +459,7 @@ void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessag /* create a new chat room */ cr=linphone_core_create_chat_room(lc,cleanfrom); } - if (sal_msg->content_type != NULL) { /* content_type field is, for now, used only for rcs file transfer bu twe shall strcmp it with "application/vnd.gsma.rcs-ft-http+xml" */ + if (sal_msg->content_type != NULL) { /* content_type field is, for now, used only for rcs file transfer but we shall strcmp it with "application/vnd.gsma.rcs-ft-http+xml" */ xmlChar *file_url = NULL; xmlDocPtr xmlMessageBody; xmlNodePtr cur; @@ -668,6 +677,7 @@ LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr, con msg->is_read=TRUE; msg->content_type = NULL; /* this property is used only when transfering file */ msg->file_transfer_information = NULL; /* this property is used only when transfering file */ + msg->http_request = NULL; return msg; } @@ -953,9 +963,12 @@ const LinphoneContent *linphone_chat_message_get_file_transfer_information(const } static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t *msg, void *data, size_t offset, const uint8_t *buffer, size_t size){ - //printf("Receive %ld bytes\n\n%s\n\n", size, (char *)buffer); LinphoneChatMessage* chatMsg=(LinphoneChatMessage *)data; LinphoneCore *lc = chatMsg->chat_room->lc; + /* TODO: while belle sip doesn't implement the cancel http request method, test if a request is still linked to the message before forwarding the data to callback */ + if (chatMsg->http_request == NULL) { + return; + } /* call back given by application level */ if (lc->vtable.file_transfer_received != NULL) { lc->vtable.file_transfer_received(lc, chatMsg, chatMsg->file_transfer_information, (char *)buffer, size); @@ -1036,7 +1049,7 @@ static void linphone_chat_process_response_from_get_file(void *data, const belle * * @param message #LinphoneChatMessage */ -void linphone_chat_message_start_file_download(const LinphoneChatMessage *message) { +void linphone_chat_message_start_file_download(LinphoneChatMessage *message) { belle_http_request_listener_callbacks_t cbs={0}; belle_http_request_listener_t *l; belle_generic_uri_t *uri; @@ -1059,8 +1072,25 @@ void linphone_chat_message_start_file_download(const LinphoneChatMessage *messag cbs.process_auth_requested=process_auth_requested; l=belle_http_request_listener_create_from_callbacks(&cbs, (void *)message); belle_sip_object_data_set(BELLE_SIP_OBJECT(req),"message",(void *)message,NULL); + message->http_request = req; /* keep a reference on the request to be able to cancel the download */ belle_http_provider_send_request(message->chat_room->lc->http_provider,req,l); } + +/** + * Cancel an ongoing file transfer attached to this message.(upload or download) + * @param msg #LinphoneChatMessage + */ +void linphone_chat_room_cancel_file_transfer(LinphoneChatMessage *msg) { + ms_message("Cancelled file transfer %s - msg [%p] chat room[%p]", (msg->external_body_url==NULL)?msg->chat_room->lc->file_transfer_server:msg->external_body_url, msg, msg->chat_room); + /* TODO: here we shall call the cancel http request from bellesip API when it is available passing msg->http_request */ + /* waiting for this API, just set to NULL the reference to the request in the message and any request */ + msg->http_request = NULL; + if (msg->cb) { + msg->cb(msg, LinphoneChatMessageStateNotDelivered, msg->chat_room->lc); + } +} + + /** * Set origin of the message *@param message #LinphoneChatMessage obj @@ -1288,11 +1318,11 @@ LinphoneChatMessage* linphone_chat_room_create_file_transfer_message(LinphoneCha linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr)); linphone_chat_message_set_from(msg, linphone_address_new(linphone_core_get_identity(cr->lc))); msg->content_type=NULL; /* this will be set to application/vnd.gsma.rcs-ft-http+xml when we will transfer the xml reply from server to the peers */ + msg->http_request=NULL; /* this will store the http request during file upload to the server */ return msg; } + /** * @} */ - - diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 518ad7c4d..280ca7358 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1331,7 +1331,8 @@ LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_to(const Linpho LINPHONE_PUBLIC const char* linphone_chat_message_get_external_body_url(const LinphoneChatMessage* message); LINPHONE_PUBLIC void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url); LINPHONE_PUBLIC const LinphoneContent* linphone_chat_message_get_file_transfer_information(const LinphoneChatMessage* message); -LINPHONE_PUBLIC void linphone_chat_message_start_file_download(const LinphoneChatMessage*message); +LINPHONE_PUBLIC void linphone_chat_message_start_file_download(LinphoneChatMessage* message); +LINPHONE_PUBLIC void linphone_chat_room_cancel_file_transfer(LinphoneChatMessage* msg); LINPHONE_PUBLIC const char* linphone_chat_message_get_appdata(const LinphoneChatMessage* message); LINPHONE_PUBLIC void linphone_chat_message_set_appdata(LinphoneChatMessage* message, const char* data); LINPHONE_PUBLIC const char* linphone_chat_message_get_text(const LinphoneChatMessage* message); diff --git a/coreapi/private.h b/coreapi/private.h index f1f6fdf38..2df416fba 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -163,8 +163,9 @@ struct _LinphoneChatMessage { bool_t is_read; unsigned int storage_id; SalOp *op; - LinphoneContent *file_transfer_information; - char *content_type; + LinphoneContent *file_transfer_information; /**< used to store file transfer information when the message is of file transfer type */ + char *content_type; /**< is used to specified the type of message to be sent, used only for file transfer message */ + belle_http_request_t *http_request; /**< keep a reference to the http_request in case of file transfer in order to be able to cancel the transfer */ }; BELLE_SIP_DECLARE_VPTR(LinphoneChatMessage); diff --git a/tester/message_tester.c b/tester/message_tester.c index daafac426..102f4832e 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -46,11 +46,11 @@ void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMess ms_free(from); counters = get_stats(lc); counters->number_of_LinphoneMessageReceived++; - if (linphone_chat_message_get_file_transfer_information(message)) - counters->number_of_LinphoneMessageReceivedWithFile++; if (counters->last_received_chat_message) linphone_chat_message_unref(counters->last_received_chat_message); linphone_chat_message_ref(counters->last_received_chat_message=message); - if (linphone_chat_message_get_external_body_url(message)) { + if (linphone_chat_message_get_file_transfer_information(message)) { + counters->number_of_LinphoneMessageReceivedWithFile++; + } else if (linphone_chat_message_get_external_body_url(message)) { counters->number_of_LinphoneMessageExtBodyReceived++; if (message_external_body_url) { CU_ASSERT_STRING_EQUAL(linphone_chat_message_get_external_body_url(message),message_external_body_url); @@ -75,7 +75,7 @@ void file_transfer_received(LinphoneCore *lc, LinphoneChatMessage *message, cons /*next chunk*/ file = (FILE*)linphone_chat_message_get_user_data(message); - if (size==0) { /* tranfer complerte */ + if (size==0) { /* tranfer complete */ stats* counters = get_stats(lc); linphone_chat_room_destroy(linphone_chat_message_get_chat_room(message)); linphone_chat_message_destroy(message); @@ -377,10 +377,10 @@ static void file_transfer_message(void) { linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); - if (marie->stat.last_received_info_message ) { - linphone_chat_message_start_file_download((const LinphoneChatMessage*)marie->stat.last_received_info_message); + if (marie->stat.last_received_chat_message ) { + linphone_chat_message_start_file_download(marie->stat.last_received_chat_message); } - CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1)); + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageExtBodyReceived,1)); CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1); @@ -439,6 +439,111 @@ static void file_transfer_message_io_error(void) { linphone_core_manager_destroy(pauline); } +static void file_transfer_message_upload_cancelled(void) { + int i; + char* to; + LinphoneChatRoom* chat_room; + LinphoneChatMessage* message; + LinphoneContent content; + const char* big_file_content="big file"; /* setting dummy file content to something */ + LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); + reset_counters(&marie->stat); + reset_counters(&pauline->stat); + + /* setting dummy file content to something */ + for (i=0;ilc,"https://www.linphone.org:444/lft.php"); + + /* create a chatroom on pauline's side */ + to = linphone_address_as_string(marie->identity); + chat_room = linphone_core_create_chat_room(pauline->lc,to); + + /* create a file transfer message */ + memset(&content,0,sizeof(content)); + content.type="text"; + content.subtype="plain"; + content.size=sizeof(big_file); /*total size to be transfered*/ + content.name = "bigfile.txt"; + message = linphone_chat_room_create_file_transfer_message(chat_room, &content); + + linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); + + /*wait for file to be 50% uploaded and cancel the transfer */ + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.progress_of_LinphoneFileTransfer, 50)); + linphone_chat_room_cancel_file_transfer(message); + + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageNotDelivered,1)); + + CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageNotDelivered,1); + CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,0); + + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} + +static void file_transfer_message_download_cancelled(void) { + int i; + char* to; + LinphoneChatRoom* chat_room; + LinphoneChatMessage* message; + LinphoneContent content; + const char* big_file_content="big file"; /* setting dummy file content to something */ + LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); + reset_counters(&marie->stat); + reset_counters(&pauline->stat); + + /* setting dummy file content to something */ + for (i=0;ilc,"https://www.linphone.org:444/lft.php"); + + /* create a chatroom on pauline's side */ + to = linphone_address_as_string(marie->identity); + chat_room = linphone_core_create_chat_room(pauline->lc,to); + + /* create a file transfer message */ + memset(&content,0,sizeof(content)); + content.type="text"; + content.subtype="plain"; + content.size=sizeof(big_file); /*total size to be transfered*/ + content.name = "bigfile.txt"; + message = linphone_chat_room_create_file_transfer_message(chat_room, &content); + + linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); + + /* wait for marie to receive pauline's message */ + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); + + + if (marie->stat.last_received_chat_message ) { /* get last message and use it to download file */ + linphone_chat_message_start_file_download(marie->stat.last_received_chat_message); + /* wait for file to be 50% downloaded */ + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.progress_of_LinphoneFileTransfer, 50)); + /* and cancel the transfer */ + linphone_chat_room_cancel_file_transfer(marie->stat.last_received_chat_message); + } + //CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1)); + + CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1); + CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,0); + + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} + static void text_message_with_send_error(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); @@ -672,6 +777,8 @@ test_t message_tests[] = { { "Text message with external body", text_message_with_external_body }, { "File transfer message", file_transfer_message }, { "File transfer message with io error", file_transfer_message_io_error }, + { "File transfer message upload cancelled", file_transfer_message_upload_cancelled }, + { "File transfer message download cancelled", file_transfer_message_download_cancelled }, { "Text message denied", text_message_denied }, { "Info message", info_message }, { "Info message with body", info_message_with_body }, From 97050ac654d47bf8da87388904defd8ca19d8259 Mon Sep 17 00:00:00 2001 From: Johan Pascal Date: Wed, 30 Jul 2014 17:14:56 +0200 Subject: [PATCH 4/6] File Transfer: manage i/o error during file download from server - note : not functional, test is bugged and commented. To be fixed. --- coreapi/chat.c | 50 +++++++++++++++++------ coreapi/help/filetransfer.c | 20 +++++----- coreapi/linphonecore.h | 5 ++- tester/message_tester.c | 79 ++++++++++++++++++++++++++++++++++--- 4 files changed, 123 insertions(+), 31 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index 28c1741ba..b115343e0 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -46,15 +46,35 @@ const char *multipart_boundary=MULTIPART_BOUNDARY; static size_t linphone_chat_message_compute_filepart_header_size(const char *filename, const char *content_type) { return strlen(FILEPART_HEADER_1)+strlen(filename)+strlen(FILEPART_HEADER_2)+strlen(content_type)+strlen(FILEPART_HEADER_3); } -static void process_io_error(void *data, const belle_sip_io_error_event_t *event){ + +static void process_io_error_upload(void *data, const belle_sip_io_error_event_t *event){ LinphoneChatMessage* msg=(LinphoneChatMessage *)data; - ms_error("I/O Error during file upload or download to/from %s - msg [%p] chat room[%p]", msg->chat_room->lc->file_transfer_server, msg, msg->chat_room); - msg->cb(msg, LinphoneChatMessageStateNotDelivered, msg->chat_room->lc); + ms_error("I/O Error during file upload to %s - msg [%p] chat room[%p]", msg->chat_room->lc->file_transfer_server, msg, msg->chat_room); + if (msg->cb) { + msg->cb(msg, LinphoneChatMessageStateNotDelivered, msg->chat_room->lc); + } } -static void process_auth_requested(void *data, belle_sip_auth_event_t *event){ +static void process_auth_requested_upload(void *data, belle_sip_auth_event_t *event){ LinphoneChatMessage* msg=(LinphoneChatMessage *)data; - ms_error("Error during file upload or download : auth requested to connect %s - msg [%p] chat room[%p]", msg->chat_room->lc->file_transfer_server, msg, msg->chat_room); - msg->cb(msg, LinphoneChatMessageStateNotDelivered, msg->chat_room->lc); + ms_error("Error during file upload : auth requested to connect %s - msg [%p] chat room[%p]", msg->chat_room->lc->file_transfer_server, msg, msg->chat_room); + if (msg->cb) { + msg->cb(msg, LinphoneChatMessageStateNotDelivered, msg->chat_room->lc); + } +} + +static void process_io_error_download(void *data, const belle_sip_io_error_event_t *event){ + LinphoneChatMessage* msg=(LinphoneChatMessage *)data; + ms_error("I/O Error during file download %s - msg [%p] chat room[%p]", msg->external_body_url, msg, msg->chat_room); + if (msg->cb) { + msg->cb(msg, LinphoneChatMessageStateFileTransferError, msg->chat_room->lc); + } +} +static void process_auth_requested_download(void *data, belle_sip_auth_event_t *event){ + LinphoneChatMessage* msg=(LinphoneChatMessage *)data; + ms_error("Error during file download : auth requested to get %s - msg [%p] chat room[%p]", msg->external_body_url, msg, msg->chat_room); + if (msg->cb) { + msg->cb(msg, LinphoneChatMessageStateFileTransferError, msg->chat_room->lc); + } } /** @@ -157,8 +177,8 @@ static void linphone_chat_message_process_response_from_post_file(void *data, co belle_sip_free(content_type); belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req),BELLE_SIP_BODY_HANDLER(bh)); cbs.process_response=linphone_chat_message_process_response_from_post_file; - cbs.process_io_error=process_io_error; - cbs.process_auth_requested=process_auth_requested; + cbs.process_io_error=process_io_error_upload; + cbs.process_auth_requested=process_auth_requested_upload; l=belle_http_request_listener_create_from_callbacks(&cbs,msg); msg->http_request=req; /* update the reference to the http request to be able to cancel it during upload */ belle_http_provider_send_request(msg->chat_room->lc->http_provider,req,l); @@ -343,8 +363,8 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM NULL, NULL); cbs.process_response=linphone_chat_message_process_response_from_post_file; - cbs.process_io_error=process_io_error; - cbs.process_auth_requested=process_auth_requested; + cbs.process_io_error=process_io_error_upload; + cbs.process_auth_requested=process_auth_requested_upload; l=belle_http_request_listener_create_from_callbacks(&cbs,msg); /* give msg to listener to be able to start the actual file upload when server answer a 204 No content */ msg->http_request = req; /* keep a reference on the request to be able to cancel it */ belle_http_provider_send_request(cr->lc->http_provider,req,l); @@ -867,6 +887,7 @@ const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState case LinphoneChatMessageStateInProgress:return "LinphoneChatMessageStateInProgress"; case LinphoneChatMessageStateDelivered:return "LinphoneChatMessageStateDelivered"; case LinphoneChatMessageStateNotDelivered:return "LinphoneChatMessageStateNotDelivered"; + case LinphoneChatMessageStateFileTransferError:return "LinphoneChatMessageStateFileTransferError"; default: return "Unknown state"; } @@ -1048,8 +1069,9 @@ static void linphone_chat_process_response_from_get_file(void *data, const belle * Start the download of the file from remote server * * @param message #LinphoneChatMessage + * @param status_cb LinphoneChatMessageStateChangeCb status callback invoked when file is downloaded or could not be downloaded */ -void linphone_chat_message_start_file_download(LinphoneChatMessage *message) { +void linphone_chat_message_start_file_download(LinphoneChatMessage *message, LinphoneChatMessageStateChangedCb status_cb) { belle_http_request_listener_callbacks_t cbs={0}; belle_http_request_listener_t *l; belle_generic_uri_t *uri; @@ -1068,11 +1090,13 @@ void linphone_chat_message_start_file_download(LinphoneChatMessage *message) { cbs.process_response_headers=linphone_chat_process_response_headers_from_get_file; cbs.process_response=linphone_chat_process_response_from_get_file; - cbs.process_io_error=process_io_error; - cbs.process_auth_requested=process_auth_requested; + cbs.process_io_error=process_io_error_download; + cbs.process_auth_requested=process_auth_requested_download; l=belle_http_request_listener_create_from_callbacks(&cbs, (void *)message); belle_sip_object_data_set(BELLE_SIP_OBJECT(req),"message",(void *)message,NULL); message->http_request = req; /* keep a reference on the request to be able to cancel the download */ + message->cb = status_cb; + message->state = LinphoneChatMessageStateInProgress; /* start the download, status is In Progress */ belle_http_provider_send_request(message->chat_room->lc->http_provider,req,l); } diff --git a/coreapi/help/filetransfer.c b/coreapi/help/filetransfer.c index 819330f57..5e8c2054b 100644 --- a/coreapi/help/filetransfer.c +++ b/coreapi/help/filetransfer.c @@ -115,16 +115,6 @@ static void file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, } -/* - * Call back called when a message is received - */ -static void message_received(LinphoneCore *lc, LinphoneChatRoom *cr, LinphoneChatMessage *msg) { - const LinphoneContent *file_transfer_info = linphone_chat_message_get_file_transfer_information(msg); - printf ("Do you really want to download %s (size %ld)?[Y/n]\nOk, let's go\n", file_transfer_info->name, (long int)file_transfer_info->size); - - linphone_chat_message_start_file_download(msg); - -} /* * Call back to get delivery status of a message * */ @@ -136,6 +126,16 @@ static void linphone_file_transfer_state_changed(LinphoneChatMessage* msg,Linpho free(to); } +/* + * Call back called when a message is received + */ +static void message_received(LinphoneCore *lc, LinphoneChatRoom *cr, LinphoneChatMessage *msg) { + const LinphoneContent *file_transfer_info = linphone_chat_message_get_file_transfer_information(msg); + printf ("Do you really want to download %s (size %ld)?[Y/n]\nOk, let's go\n", file_transfer_info->name, (long int)file_transfer_info->size); + + linphone_chat_message_start_file_download(msg, linphone_file_transfer_state_changed); + +} LinphoneCore *lc; int main(int argc, char *argv[]){ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 280ca7358..0c9358094 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1258,7 +1258,8 @@ typedef enum _LinphoneChatMessageState { LinphoneChatMessageStateIdle, /**< Initial state */ LinphoneChatMessageStateInProgress, /**< Delivery in progress */ LinphoneChatMessageStateDelivered, /**< Message succesffully delivered an acknoleged by remote end point */ - LinphoneChatMessageStateNotDelivered /**< Message was not delivered */ + LinphoneChatMessageStateNotDelivered, /**< Message was not delivered */ + LinphoneChatMessageStateFileTransferError /**< Message was received(and acknowledged) but cannot get file from server */ } LinphoneChatMessageState; /** @@ -1331,7 +1332,7 @@ LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_to(const Linpho LINPHONE_PUBLIC const char* linphone_chat_message_get_external_body_url(const LinphoneChatMessage* message); LINPHONE_PUBLIC void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url); LINPHONE_PUBLIC const LinphoneContent* linphone_chat_message_get_file_transfer_information(const LinphoneChatMessage* message); -LINPHONE_PUBLIC void linphone_chat_message_start_file_download(LinphoneChatMessage* message); +LINPHONE_PUBLIC void linphone_chat_message_start_file_download(LinphoneChatMessage* message, LinphoneChatMessageStateChangedCb status_cb); LINPHONE_PUBLIC void linphone_chat_room_cancel_file_transfer(LinphoneChatMessage* msg); LINPHONE_PUBLIC const char* linphone_chat_message_get_appdata(const LinphoneChatMessage* message); LINPHONE_PUBLIC void linphone_chat_message_set_appdata(LinphoneChatMessage* message, const char* data); diff --git a/tester/message_tester.c b/tester/message_tester.c index 102f4832e..d71f2db53 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -124,7 +124,7 @@ void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *me const LinphoneAddress* to_address = linphone_chat_message_get_to(message); char *address = linphone_chat_message_is_outgoing(message)?linphone_address_as_string(to_address):linphone_address_as_string(from_address); stats* counters = get_stats(lc); - printf(" File transfer [%d%%] %s of type [%s/%s] %s [%s] \n", (int)progress + ms_message(" File transfer [%d%%] %s of type [%s/%s] %s [%s] \n", (int)progress ,(linphone_chat_message_is_outgoing(message)?"sent":"received") , content->type , content->subtype @@ -157,6 +157,9 @@ void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,Linph case LinphoneChatMessageStateInProgress: counters->number_of_LinphoneMessageInProgress++; break; + case LinphoneChatMessageStateFileTransferError: + counters->number_of_LinphoneMessageNotDelivered++; + break; default: ms_error("Unexpected state [%s] for message [%p]",linphone_chat_message_state_to_string(state),msg); } @@ -378,18 +381,19 @@ static void file_transfer_message(void) { linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); if (marie->stat.last_received_chat_message ) { - linphone_chat_message_start_file_download(marie->stat.last_received_chat_message); + linphone_chat_message_start_file_download(marie->stat.last_received_chat_message, liblinphone_tester_chat_message_state_change); } CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageExtBodyReceived,1)); CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1); + CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } -static void file_transfer_message_io_error(void) { +static void file_transfer_message_io_error_upload(void) { int i; char* to; LinphoneChatRoom* chat_room; @@ -439,6 +443,67 @@ static void file_transfer_message_io_error(void) { linphone_core_manager_destroy(pauline); } + +#ifdef TEST_IS_BUGGED_NO_CALL_TO_IO_ERROR_CALLBACK +static void file_transfer_message_io_error_download(void) { + int i; + char* to; + LinphoneChatRoom* chat_room; + LinphoneChatMessage* message; + LinphoneContent content; + const char* big_file_content="big file"; /* setting dummy file content to something */ + LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); + reset_counters(&marie->stat); + reset_counters(&pauline->stat); + + /* setting dummy file content to something */ + for (i=0;ilc,"https://www.linphone.org:444/lft.php"); + + /* create a chatroom on pauline's side */ + to = linphone_address_as_string(marie->identity); + chat_room = linphone_core_create_chat_room(pauline->lc,to); + + /* create a file transfer message */ + memset(&content,0,sizeof(content)); + content.type="text"; + content.subtype="plain"; + content.size=sizeof(big_file); /*total size to be transfered*/ + content.name = "bigfile.txt"; + message = linphone_chat_room_create_file_transfer_message(chat_room, &content); + + linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); + + /* wait for marie to receive pauline's message */ + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); + + + if (marie->stat.last_received_chat_message ) { /* get last message and use it to download file */ + linphone_chat_message_start_file_download(marie->stat.last_received_chat_message, liblinphone_tester_chat_message_state_change); + /* wait for file to be 50% downloaded */ + CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.progress_of_LinphoneFileTransfer, 50)); + /* and simulate network error */ + sal_set_recv_error(marie->lc->sal, -1); + } + + CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1); + CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1); + CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageNotDelivered,1); + CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,0); + + sal_set_recv_error(marie->lc->sal, 0); + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} +#endif + static void file_transfer_message_upload_cancelled(void) { int i; char* to; @@ -529,16 +594,17 @@ static void file_transfer_message_download_cancelled(void) { if (marie->stat.last_received_chat_message ) { /* get last message and use it to download file */ - linphone_chat_message_start_file_download(marie->stat.last_received_chat_message); + linphone_chat_message_start_file_download(marie->stat.last_received_chat_message, liblinphone_tester_chat_message_state_change); /* wait for file to be 50% downloaded */ CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.progress_of_LinphoneFileTransfer, 50)); /* and cancel the transfer */ linphone_chat_room_cancel_file_transfer(marie->stat.last_received_chat_message); } - //CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1)); CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1); + CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,0); + CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageNotDelivered,1); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); @@ -776,7 +842,8 @@ test_t message_tests[] = { { "Text message with send error", text_message_with_send_error }, { "Text message with external body", text_message_with_external_body }, { "File transfer message", file_transfer_message }, - { "File transfer message with io error", file_transfer_message_io_error }, + { "File transfer message with io error at upload", file_transfer_message_io_error_upload }, +/* { "File transfer message with io error at download", file_transfer_message_io_error_download },*/ { "File transfer message upload cancelled", file_transfer_message_upload_cancelled }, { "File transfer message download cancelled", file_transfer_message_download_cancelled }, { "Text message denied", text_message_denied }, From bef17939019267e054db0e3924df10d15f6eb930 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 30 Jul 2014 23:13:38 +0200 Subject: [PATCH 5/6] update MS2 --- mediastreamer2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediastreamer2 b/mediastreamer2 index b84ad6280..12a820ca4 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit b84ad6280a29fb55ff0de3b26c710c2c31f83055 +Subproject commit 12a820ca46211cdae6b8ab502d12c4064ba6c518 From b45a3767275f2a5ae7146ef318527396f98b6645 Mon Sep 17 00:00:00 2001 From: Margaux Clerc Date: Thu, 31 Jul 2014 11:15:29 +0200 Subject: [PATCH 6/6] Fix crash in chatroom destroy --- coreapi/chat.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index b115343e0..6679d9034 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -300,7 +300,8 @@ LinphoneChatRoom* linphone_core_get_or_create_chat_room(LinphoneCore* lc, const static void linphone_chat_room_delete_composing_idle_timer(LinphoneChatRoom *cr) { if (cr->composing_idle_timer) { - sal_cancel_timer(cr->lc->sal, cr->composing_idle_timer); + if(cr->lc->sal) + sal_cancel_timer(cr->lc->sal, cr->composing_idle_timer); belle_sip_object_unref(cr->composing_idle_timer); cr->composing_idle_timer = NULL; } @@ -308,7 +309,8 @@ static void linphone_chat_room_delete_composing_idle_timer(LinphoneChatRoom *cr) static void linphone_chat_room_delete_composing_refresh_timer(LinphoneChatRoom *cr) { if (cr->composing_refresh_timer) { - sal_cancel_timer(cr->lc->sal, cr->composing_refresh_timer); + if(cr->lc->sal) + sal_cancel_timer(cr->lc->sal, cr->composing_refresh_timer); belle_sip_object_unref(cr->composing_refresh_timer); cr->composing_refresh_timer = NULL; } @@ -316,7 +318,8 @@ static void linphone_chat_room_delete_composing_refresh_timer(LinphoneChatRoom * static void linphone_chat_room_delete_remote_composing_refresh_timer(LinphoneChatRoom *cr) { if (cr->remote_composing_refresh_timer) { - sal_cancel_timer(cr->lc->sal, cr->remote_composing_refresh_timer); + if(cr->lc->sal) + sal_cancel_timer(cr->lc->sal, cr->remote_composing_refresh_timer); belle_sip_object_unref(cr->remote_composing_refresh_timer); cr->remote_composing_refresh_timer = NULL; }