void display_history_message(GtkWidget *chat_view,MSList *messages,const LinphoneAddress *with){ if(messages != NULL){ MSList *it; char *from_str; char *with_str; gchar *tmp; for(it=messages;it!=NULL;it=it->next){ LinphoneChatMessage *msg=(LinphoneChatMessage *)it->data; from_str=linphone_address_as_string_uri_only(linphone_chat_message_get_from(msg)); with_str=linphone_address_as_string_uri_only(with); linphone_gtk_push_text(chat_view,strcmp(from_str,with_str)==0? with : linphone_chat_message_get_from(msg), strcmp(from_str,with_str)==0? FALSE : TRUE, linphone_chat_message_get_chat_room(msg),msg,TRUE); } tmp=g_object_get_data(G_OBJECT(chat_view),"from_message"); if (tmp){ g_object_set_data(G_OBJECT(chat_view),"from_message",NULL); g_free(tmp); } ms_free(from_str); ms_free(with_str); linphone_gtk_free_list(messages); } }
/** * function invoked to report file transfer progress. * */ void file_transfer_progress_indication(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total) { LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(message); LinphoneCore *lc = linphone_chat_room_get_core(cr); const LinphoneAddress* from_address = linphone_chat_message_get_from(message); 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); int progress = (int)((offset * 100)/total); ms_message(" File transfer [%d%%] %s of type [%s/%s] %s [%s] \n", progress ,(linphone_chat_message_is_outgoing(message)?"sent":"received") , linphone_content_get_type(content) , linphone_content_get_subtype(content) ,(linphone_chat_message_is_outgoing(message)?"to":"from") , address); counters->progress_of_LinphoneFileTransfer = progress; free(address); }
/** * function invoked when a file transfer is received. **/ static void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const LinphoneBuffer *buffer){ FILE* file=NULL; if (!linphone_chat_message_get_user_data(message)) { /*first chunk, creating file*/ file = fopen("receive_file.dump","wb"); linphone_chat_message_set_user_data(message,(void*)file); /*store fd for next chunks*/ } file = (FILE*)linphone_chat_message_get_user_data(message); if (linphone_buffer_is_empty(buffer)) { printf("File transfert completed\n"); linphone_chat_room_destroy(linphone_chat_message_get_chat_room(message)); linphone_chat_message_destroy(message); fclose(file); running=FALSE; } else { /* store content on a file*/ if (fwrite(linphone_buffer_get_content(buffer),linphone_buffer_get_size(buffer),1,file)==-1){ ms_warning("file_transfer_received() write failed: %s",strerror(errno)); } } }
void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state) { LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg); LinphoneCore *lc = linphone_chat_room_get_core(cr); stats* counters = get_stats(lc); ms_message("Message [%s] [%s]",linphone_chat_message_get_text(msg), linphone_chat_message_state_to_string(state)); switch (state) { case LinphoneChatMessageStateDelivered: counters->number_of_LinphoneMessageDelivered++; break; case LinphoneChatMessageStateNotDelivered: counters->number_of_LinphoneMessageNotDelivered++; break; 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); } }
/** * function invoked when a file transfer is received. * */ void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const LinphoneBuffer *buffer){ FILE* file=NULL; char receive_file[256]; LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(message); LinphoneCore *lc = linphone_chat_room_get_core(cr); snprintf(receive_file,sizeof(receive_file), "%s/receive_file.dump", liblinphone_tester_writable_dir_prefix); if (!linphone_chat_message_get_user_data(message)) { /*first chunk, creating file*/ file = fopen(receive_file,"wb"); linphone_chat_message_set_user_data(message,(void*)file); /*store fd for next chunks*/ } file = (FILE*)linphone_chat_message_get_user_data(message); if (linphone_buffer_is_empty(buffer)) { /* tranfer complete */ stats* counters = get_stats(lc); counters->number_of_LinphoneMessageExtBodyReceived++; fclose(file); } else { /* store content on a file*/ if (fwrite(linphone_buffer_get_content(buffer),linphone_buffer_get_size(buffer),1,file)==-1){ ms_error("file_transfer_received(): write() failed: %s",strerror(errno)); } } }