From 1f089fd82f19b27281639c5d04d0c3a7ef935652 Mon Sep 17 00:00:00 2001 From: Margaux Clerc Date: Wed, 30 Jan 2013 15:46:28 +0100 Subject: [PATCH] Add time in LinphoneChatMessage and SalMessage --- coreapi/callbacks.c | 2 +- coreapi/chat.c | 17 ++++++++---- coreapi/linphonecore.h | 9 ++++++- coreapi/private.h | 3 ++- coreapi/sal.h | 1 + coreapi/sal_eXosip2.c | 25 ++++++++++++++++- coreapi/sal_eXosip2_presence.c | 4 +++ gtk/chat.c | 49 +++++++++++++++++----------------- gtk/linphone.h | 2 +- gtk/main.c | 3 ++- gtk/main.ui | 5 +++- 11 files changed, 83 insertions(+), 37 deletions(-) diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 8baad9af..552d3480 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -845,7 +845,7 @@ static bool_t is_duplicate_msg(LinphoneCore *lc, const char *msg_id){ static void text_received(Sal *sal, const SalMessage *msg){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal); if (is_duplicate_msg(lc,msg->message_id)==FALSE){ - linphone_core_message_received(lc,msg->from,msg->text,msg->url); + linphone_core_message_received(lc,msg); } } diff --git a/coreapi/chat.c b/coreapi/chat.c index 00f23737..c502efa9 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -103,13 +103,13 @@ void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc, } -void linphone_core_message_received(LinphoneCore *lc, const char *from, const char *raw_msg,const char* external_url){ +void linphone_core_message_received(LinphoneCore *lc, const SalMessage *sal_msg){ MSList *elem; LinphoneChatRoom *cr=NULL; LinphoneAddress *addr; char *cleanfrom; LinphoneChatMessage* msg; - addr=linphone_address_new(from); + addr=linphone_address_new(sal_msg->from); linphone_address_clean(addr); for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){ cr=(LinphoneChatRoom*)elem->data; @@ -123,10 +123,12 @@ void linphone_core_message_received(LinphoneCore *lc, const char *from, const ch /* create a new chat room */ cr=linphone_core_create_chat_room(lc,cleanfrom); } - msg = linphone_chat_room_create_message(cr, raw_msg); + msg = linphone_chat_room_create_message(cr, sal_msg->text); linphone_chat_message_set_from(msg, cr->peer_url); - if (external_url) { - linphone_chat_message_set_external_body_url(msg, external_url); + msg->time=sal_msg->time; + + if (sal_msg->url) { + linphone_chat_message_set_external_body_url(msg, sal_msg->url); } linphone_address_destroy(addr); linphone_chat_room_message_received(cr,lc,msg); @@ -221,6 +223,11 @@ void linphone_chat_message_set_from(LinphoneChatMessage* message, const Linphone LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message) { return message->from; } + +time_t linphone_chat_message_get_time(const LinphoneChatMessage* message) { + return message->time; +} + const char * linphone_chat_message_get_text(const LinphoneChatMessage* message) { return message->message; } diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 6eb40163..f780d2f6 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -735,7 +735,14 @@ void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,co * Get text part of this message * @return text or NULL if no text. */ -const char * linphone_chat_message_get_text(const LinphoneChatMessage* message); +const char * linphone_chat_message_get_text(const LinphoneChatMessage* message); + +/** + * Get the time the message was sent + * @return time_t or NULL if no time + */ +time_t linphone_chat_message_get_time(const LinphoneChatMessage* message); + /** * user pointer get function */ diff --git a/coreapi/private.h b/coreapi/private.h index c421b2bc..ca79a722 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -103,6 +103,7 @@ struct _LinphoneChatMessage { void* message_userdata; char* external_body_url; LinphoneAddress* from; + time_t time; }; typedef struct StunCandidate{ @@ -279,7 +280,7 @@ void linphone_proxy_config_write_to_config_file(struct _LpConfig* config,Linphon int linphone_proxy_config_normalize_number(LinphoneProxyConfig *cfg, const char *username, char *result, size_t result_len); -void linphone_core_message_received(LinphoneCore *lc, const char *from, const char *raw_msg,const char* external_url); +void linphone_core_message_received(LinphoneCore *lc, const SalMessage *msg); void linphone_core_play_tone(LinphoneCore *lc); diff --git a/coreapi/sal.h b/coreapi/sal.h index b751dfc0..46294b60 100644 --- a/coreapi/sal.h +++ b/coreapi/sal.h @@ -195,6 +195,7 @@ typedef struct SalMessage{ const char *text; const char *url; const char *message_id; + time_t time; }SalMessage; #define SAL_MEDIA_DESCRIPTION_MAX_MESSAGE_ATTRIBUTES 5 diff --git a/coreapi/sal_eXosip2.c b/coreapi/sal_eXosip2.c index 076f3d93..91ec0467 100644 --- a/coreapi/sal_eXosip2.c +++ b/coreapi/sal_eXosip2.c @@ -52,7 +52,6 @@ void sal_get_default_local_ip(Sal *sal, int address_family,char *ip, size_t iple } } - static SalOp * sal_find_call(Sal *sal, int cid){ const MSList *elem; SalOp *op; @@ -1766,6 +1765,9 @@ static bool_t comes_from_local_if(osip_message_t *msg){ return FALSE; } +static const char *days[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; +static const char *months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; + static void text_received(Sal *sal, eXosip_event_t *ev){ osip_body_t *body=NULL; char *from=NULL,*msg=NULL; @@ -1775,6 +1777,26 @@ static void text_received(Sal *sal, eXosip_event_t *ev){ int external_body_size=0; SalMessage salmsg; char message_id[256]={0}; + osip_header_t *date=NULL; + struct tm ret={}; + char tmp1[80]={0}; + char tmp2[80]={0}; + int i,j; + + osip_message_get_date(ev->request,0,&date); + if(date==NULL){ + ms_error("Could not get the date of message"); + return; + } + sscanf(date->hvalue,"%3c,%d%s%d%d:%d:%d",tmp1,&ret.tm_mday,tmp2, + &ret.tm_year,&ret.tm_hour,&ret.tm_min,&ret.tm_sec); + ret.tm_year-=1900; + for(i=0;i<7;i++) { + if(strcmp(tmp1,days[i])==0) ret.tm_wday=i; + } + for(j=0;j<12;j++) { + if(strcmp(tmp2,months[j])==0) ret.tm_mon=j; + } content_type= osip_message_get_content_type(ev->request); if (!content_type) { @@ -1815,6 +1837,7 @@ static void text_received(Sal *sal, eXosip_event_t *ev){ salmsg.text=msg; salmsg.url=external_body_size>0 ? unquoted_external_body_url : NULL; salmsg.message_id=message_id; + salmsg.time=mktime(&ret); sal->callbacks.text_received(sal,&salmsg); osip_free(from); } diff --git a/coreapi/sal_eXosip2_presence.c b/coreapi/sal_eXosip2_presence.c index 078ec24b..870d9670 100644 --- a/coreapi/sal_eXosip2_presence.c +++ b/coreapi/sal_eXosip2_presence.c @@ -83,6 +83,9 @@ void sal_remove_in_subscribe(Sal *sal, SalOp *op){ int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){ osip_message_t *sip=NULL; + time_t t; + time(&t); + char buf[26]; if(op->cid == -1) { @@ -97,6 +100,7 @@ int sal_message_send(SalOp *op, const char *from, const char *to, const char* co eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op), sal_op_get_from(op),sal_op_get_route(op)); if (sip!=NULL){ + osip_message_set_date(sip,ctime_r(&t,buf)); osip_message_set_content_type(sip,content_type); if (msg) osip_message_set_body(sip,msg,strlen(msg)); sal_add_other(op->base.root,op,sip); diff --git a/gtk/chat.c b/gtk/chat.c index 19bcc342..3eea9255 100644 --- a/gtk/chat.c +++ b/gtk/chat.c @@ -90,7 +90,8 @@ void udpate_tab_chat_header(GtkWidget *chat_view,const LinphoneAddress *uri,Linp } -void linphone_gtk_push_text(GtkWidget *w, const LinphoneAddress *from, const char *message, gboolean me,LinphoneChatRoom *cr){ +void linphone_gtk_push_text(GtkWidget *w, const LinphoneAddress *from, + const char *message, gboolean me,LinphoneChatRoom *cr, time_t t){ GtkTextView *text=GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textview")); GtkTextBuffer *buffer=gtk_text_view_get_buffer(text); GtkTextIter iter,begin,end; @@ -129,15 +130,19 @@ void linphone_gtk_push_text(GtkWidget *w, const LinphoneAddress *from, const cha } g_object_set_data(G_OBJECT(linphone_gtk_get_main_window()),"history",hash); + + gtk_text_buffer_get_end_iter(buffer,&iter); + list=g_list_append(list,GINT_TO_POINTER(gtk_text_iter_get_line(&iter))); if(me){ - gtk_text_buffer_get_end_iter(buffer,&iter); - list=g_list_append(list,GINT_TO_POINTER(gtk_text_iter_get_line(&iter))); gtk_text_buffer_insert_with_tags_by_name(buffer,&iter,"Message in progress.. ",-1, "italic","right","small","font_grey",NULL); - gtk_text_buffer_get_end_iter(buffer,&iter); - gtk_text_buffer_insert(buffer,&iter,"\n",-1); - g_object_set_data(G_OBJECT(w),"list",list); + } else { + gtk_text_buffer_insert_with_tags_by_name(buffer,&iter,ctime(&t),-1, + "italic","right","small","font_grey",NULL); } + gtk_text_buffer_get_end_iter(buffer,&iter); + gtk_text_buffer_insert(buffer,&iter,"\n",-1); + g_object_set_data(G_OBJECT(w),"list",list); GtkTextMark *mark=gtk_text_buffer_create_mark(buffer,NULL,&iter,FALSE); gtk_text_view_scroll_mark_onscreen(text,mark); @@ -193,11 +198,6 @@ void update_chat_state_message(LinphoneChatMessageState state){ break; default : result="Message in progress.. "; } - - /*GDateTime *dt=g_date_time_new_now_local(); - char *time=g_date_time_format(dt,"%k:%M"); - gchar result2[80]; - sprintf(result2,"%s %s",result,time);*/ gtk_text_buffer_insert_with_tags_by_name(b,&iter,result,-1, "italic","right","small","font_grey",NULL); @@ -221,10 +221,10 @@ void linphone_gtk_send_text(){ entered=gtk_entry_get_text(GTK_ENTRY(entry)); if (strlen(entered)>0) { LinphoneChatMessage *msg; + msg=linphone_chat_room_create_message(cr,entered); linphone_gtk_push_text(w, linphone_gtk_get_used_identity(), - entered,TRUE,cr); - msg=linphone_chat_room_create_message(cr,entered); + entered,TRUE,cr,linphone_chat_message_get_time(msg)); linphone_chat_room_send_message2(cr,msg,on_chat_state_changed,NULL); gtk_entry_set_text(GTK_ENTRY(entry),""); } @@ -338,25 +338,25 @@ void linphone_gtk_chat_close(GtkWidget *button){ } -void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message){ +void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, + LinphoneChatMessage *msg){ GtkWidget *main_window=linphone_gtk_get_main_window(); GtkWidget *friendlist=linphone_gtk_get_widget(main_window,"contact_list"); GtkWidget *w; - /*GDateTime *dt=g_date_time_new_now_local(); - char *time=g_date_time_format(dt,"%k:%M");*/ + w=(GtkWidget*)g_object_get_data(G_OBJECT(friendlist),"chatview"); if(w!=NULL){ - linphone_gtk_load_chatroom(room,from,w); + linphone_gtk_load_chatroom(room,linphone_chat_message_get_from(msg),w); } else { - w=linphone_gtk_init_chatroom(room,from); + w=linphone_gtk_init_chatroom(room,linphone_chat_message_get_from(msg)); g_object_set_data(G_OBJECT(friendlist),"chatview",(gpointer)w); - g_object_set_data(G_OBJECT(friendlist),"from",(gpointer)from); + g_object_set_data(G_OBJECT(friendlist),"from",(gpointer)linphone_chat_message_get_from(msg)); } - const char *display=linphone_address_get_display_name(from); + const char *display=linphone_address_get_display_name(linphone_chat_message_get_from(msg)); if (display==NULL || display[0]=='\0') { - display=linphone_address_get_username(from); + display=linphone_address_get_username(linphone_chat_message_get_from(msg)); } #ifdef HAVE_GTK_OSXs @@ -365,16 +365,15 @@ void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const #else if(!gtk_window_is_active(GTK_WINDOW(main_window))){ if(!GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_notified"))){ - /*gchar result2[80]; - sprintf(result2,"%s \n %s sent at %s",message,display,time);*/ - linphone_gtk_notify(NULL,message); + linphone_gtk_notify(NULL,linphone_chat_message_get_text(msg)); g_object_set_data(G_OBJECT(w),"is_notified",GINT_TO_POINTER(TRUE)); } else { g_object_set_data(G_OBJECT(w),"is_notified",GINT_TO_POINTER(FALSE)); } } #endif - linphone_gtk_push_text(w,from,message,FALSE,room); + linphone_gtk_push_text(w,linphone_chat_message_get_from(msg), + linphone_chat_message_get_text(msg),FALSE,room,linphone_chat_message_get_time(msg)); linphone_gtk_update_chat_picture(); //gtk_window_present(GTK_WINDOW(w)); /*gtk_window_set_urgency_hint(GTK_WINDOW(w),TRUE);*/ diff --git a/gtk/linphone.h b/gtk/linphone.h index ee584b03..55b30c82 100644 --- a/gtk/linphone.h +++ b/gtk/linphone.h @@ -74,7 +74,7 @@ void linphone_gtk_fill_soundcards(GtkWidget *pb); void linphone_gtk_fill_webcams(GtkWidget *pb); void linphone_gtk_load_identities(void); LinphoneChatRoom * linphone_gtk_create_chatroom(const LinphoneAddress *with); -void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message); +void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg); void linphone_gtk_call_log_update(GtkWidget *w); void linphone_gtk_create_log_window(void); void linphone_gtk_log_show(void); diff --git a/gtk/main.c b/gtk/main.c index bc333645..a2461269 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -230,7 +230,8 @@ static void linphone_gtk_init_liblinphone(const char *config_file, vtable.display_warning=linphone_gtk_display_warning; vtable.display_url=linphone_gtk_display_url; vtable.call_log_updated=linphone_gtk_call_log_updated; - vtable.text_received=linphone_gtk_text_received; + //vtable.text_received=linphone_gtk_text_received; + vtable.message_received=linphone_gtk_text_received; vtable.refer_received=linphone_gtk_refer_received; vtable.buddy_info_updated=linphone_gtk_buddy_info_updated; vtable.call_encryption_changed=linphone_gtk_call_encryption_changed; diff --git a/gtk/main.ui b/gtk/main.ui index 97e9b470..76e96e80 100644 --- a/gtk/main.ui +++ b/gtk/main.ui @@ -959,6 +959,7 @@ True True + 2 0 @@ -987,6 +988,7 @@ False True + 6 2 @@ -1116,7 +1118,7 @@ False False - 12 + 6 0 @@ -1384,6 +1386,7 @@ True True + 6 1 -- 2.39.2