static void file_transfer_message_upload_cancelled(void) { int i; char* to; LinphoneChatRoom* chat_room; LinphoneChatMessage* message; LinphoneChatMessageCbs *cbs; 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;i<sizeof(big_file);i+=strlen(big_file_content)) memcpy(big_file+i, big_file_content, strlen(big_file_content)); big_file[0]=*"S"; big_file[sizeof(big_file)-1]=*"E"; /* Globally configure an http file transfer server. */ linphone_core_set_file_transfer_server(pauline->lc,"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 */ content = linphone_core_create_content(pauline->lc); linphone_content_set_type(content,"text"); linphone_content_set_subtype(content,"plain"); linphone_content_set_size(content,sizeof(big_file)); /*total size to be transfered*/ linphone_content_set_name(content,"bigfile.txt"); message = linphone_chat_room_create_file_transfer_message(chat_room, content); { int dummy=0; wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } cbs = linphone_chat_message_get_callbacks(message); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); linphone_chat_message_cbs_set_file_transfer_send(cbs, memory_file_transfer_send); linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); linphone_chat_room_send_chat_message(chat_room,message); /*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_message_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_content_unref(content); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; const char* dest_friend=NULL; int i; const char* big_file_content="big file"; LinphoneChatRoom* chat_room; LinphoneContent* content; LinphoneChatMessage* chat_message; LinphoneChatMessageCbs *cbs; /*seting dummy file content to something*/ for (i=0;i<sizeof(big_file);i+=strlen(big_file_content)) memcpy(big_file+i, big_file_content, strlen(big_file_content)); big_file[0]=*"S"; big_file[sizeof(big_file)-1]=*"E"; signal(SIGINT,stop); //#define DEBUG #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif vtable.message_received=message_received; /* Instantiate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,NULL); dest_friend = linphone_core_get_primary_contact(lc); printf("Send message to me : %s\n", dest_friend); /** * Globally configure an http file transfer server. */ //linphone_core_set_file_transfer_server(lc,"http://npasc.al/lft.php"); linphone_core_set_file_transfer_server(lc,"https://www.linphone.org:444/lft.php"); /*Next step is to create a chat room*/ chat_room = linphone_core_get_chat_room_from_uri(lc,dest_friend); content = linphone_core_create_content(lc); linphone_content_set_type(content,"text"); linphone_content_set_subtype(content,"plain"); linphone_content_set_size(content,sizeof(big_file)); /*total size to be transfered*/ linphone_content_set_name(content,"bigfile.txt"); /*now create a chat message with custom content*/ chat_message = linphone_chat_room_create_file_transfer_message(chat_room,content); if (chat_message == NULL) { printf("returned message is null\n"); } /** * Fill the application callbacks. The file_transfer_received callback is used in order to get notifications * about incoming file reception, file_transfer_send to feed file to be transfered and * file_transfer_progress_indication to print progress. */ cbs = linphone_chat_message_get_callbacks(chat_message); linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); linphone_chat_message_cbs_set_file_transfer_send(cbs, file_transfer_send); linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); /*initiating file transfer*/ linphone_chat_room_send_chat_message(chat_room, chat_message); /* main loop for receiving incoming messages and doing background linphone core work: */ while(running){ linphone_core_iterate(lc); ms_usleep(50000); } printf("Shutting down...\n"); linphone_content_unref(content); linphone_core_destroy(lc); printf("Exited\n"); return 0; }