diff --git a/linphone/coreapi/authentication.c b/linphone/coreapi/authentication.c index ac1636df2..437626bd6 100644 --- a/linphone/coreapi/authentication.c +++ b/linphone/coreapi/authentication.c @@ -29,8 +29,6 @@ #include "lpconfig.h" extern LinphoneProxyConfig *linphone_core_get_proxy_config_from_rid(LinphoneCore *lc, int rid); -extern void linphone_proxy_config_set_realm(LinphoneProxyConfig *cfg, const char *realm); -extern void linphone_core_retry_proxy_register(LinphoneCore *lc, const char *realm); LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1,const char *realm) @@ -122,17 +120,43 @@ static bool_t key_match(const char *tmp1, const char *tmp2){ } +static char * remove_quotes(char * input){ + char *tmp; + if (*input=='"') input++; + tmp=strchr(input,'"'); + if (tmp) *tmp='\0'; + return input; +} + +static int realm_match(const char *realm1, const char *realm2){ + if (realm1==NULL && realm2==NULL) return TRUE; + if (realm1!=NULL && realm2!=NULL){ + if (strcmp(realm1,realm2)==0) return TRUE; + else{ + char tmp1[128]; + char tmp2[128]; + char *p1,*p2; + strncpy(tmp1,realm1,sizeof(tmp1)-1); + strncpy(tmp2,realm2,sizeof(tmp1)-1); + p1=remove_quotes(tmp1); + p2=remove_quotes(tmp2); + return strcmp(p1,p2)==0; + } + } + return FALSE; +} + static int auth_info_compare(const void *pinfo,const void *pref){ LinphoneAuthInfo *info=(LinphoneAuthInfo*)pinfo; LinphoneAuthInfo *ref=(LinphoneAuthInfo*)pref; - if (key_match(info->realm,ref->realm) && key_match(info->username,ref->username)) return 0; + if (realm_match(info->realm,ref->realm) && key_match(info->username,ref->username)) return 0; return -1; } static int auth_info_compare_only_realm(const void *pinfo,const void *pref){ LinphoneAuthInfo *info=(LinphoneAuthInfo*)pinfo; LinphoneAuthInfo *ref=(LinphoneAuthInfo*)pref; - if (key_match(info->realm,ref->realm) ) return 0; + if (realm_match(info->realm,ref->realm) ) return 0; return -1; } diff --git a/linphone/coreapi/linphonecore.c b/linphone/coreapi/linphonecore.c index bf3c4aa3c..a87a822fe 100644 --- a/linphone/coreapi/linphonecore.c +++ b/linphone/coreapi/linphonecore.c @@ -910,11 +910,29 @@ int linphone_core_get_sip_port(LinphoneCore *lc) } static bool_t exosip_running=FALSE; +static char _ua_name[64]="Linphone"; +static char _ua_version[64]=LINPHONE_VERSION; + +static void set_user_agent(){ + char ua_string[256]; + snprintf(ua_string,sizeof(ua_string),"%s/%s (eXosip2/%s)",_ua_name,_ua_version, +#ifdef HAVE_EXOSIP_GET_VERSION + eXosip_get_version() +#else + "unknown" +#endif + ); + eXosip_set_user_agent(ua_string); +} + +void linphone_core_set_user_agent(const char *name, const char *ver){ + strncpy(_ua_name,name,sizeof(_ua_name)-1); + strncpy(_ua_version,ver,sizeof(_ua_version)); +} void linphone_core_set_sip_port(LinphoneCore *lc,int port) { const char *anyaddr; - char ua_string[256]; int err=0; if (port==lc->sip_conf.sip_port) return; lc->sip_conf.sip_port=port; @@ -942,14 +960,7 @@ void linphone_core_set_sip_port(LinphoneCore *lc,int port) eXosip_set_rsvp_mode (lc->rsvp_enable); eXosip_set_rpc_mode (lc->rpc_enable); #endif - snprintf(ua_string,sizeof(ua_string),"Linphone/%s (eXosip2/%s)",LINPHONE_VERSION, -#ifdef HAVE_EXOSIP_GET_VERSION - eXosip_get_version() -#else - "unknown" -#endif -); - eXosip_set_user_agent(ua_string); + set_user_agent("Linphone",LINPHONE_VERSION); exosip_running=TRUE; } diff --git a/linphone/coreapi/linphonecore.h b/linphone/coreapi/linphonecore.h index 8978dedf6..d2314f577 100644 --- a/linphone/coreapi/linphonecore.h +++ b/linphone/coreapi/linphonecore.h @@ -275,6 +275,7 @@ char *linphone_friend_get_url(LinphoneFriend *lf); /* name */ bool_t linphone_friend_get_send_subscribe(const LinphoneFriend *lf); LinphoneSubscribePolicy linphone_friend_get_inc_subscribe_policy(const LinphoneFriend *lf); LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf); +#define linphone_friend_in_list(lf) ((lf)->lc!=NULL) #define linphone_friend_url(lf) ((lf)->url) @@ -311,6 +312,7 @@ void linphone_proxy_config_edit(LinphoneProxyConfig *obj); int linphone_proxy_config_done(LinphoneProxyConfig *obj); void linphone_proxy_config_enable_publish(LinphoneProxyConfig *obj, bool_t val); bool_t linphone_proxy_config_is_registered(const LinphoneProxyConfig *obj); +const char *linphone_proxy_config_get_domain(const LinphoneProxyConfig *cfg); #define linphone_proxy_config_get_route(obj) ((obj)->reg_route) #define linphone_proxy_config_get_identity(obj) ((obj)->reg_identity) #define linphone_proxy_config_publish_enabled(obj) ((obj)->publish) @@ -519,7 +521,8 @@ typedef struct _LinphoneCore void linphone_core_enable_logs(FILE *file); void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc); void linphone_core_disable_logs(void); - +/*sets the user-agent string in sip messages, must be set before linphone_core_new() or linphone_core_init() */ +void linphone_core_set_user_agent(const char *ua_name, const char *version); const char *linphone_core_get_version(void); LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable, diff --git a/linphone/coreapi/proxy.c b/linphone/coreapi/proxy.c index e5c149033..9756f759b 100644 --- a/linphone/coreapi/proxy.c +++ b/linphone/coreapi/proxy.c @@ -44,6 +44,7 @@ void linphone_proxy_config_destroy(LinphoneProxyConfig *obj){ if (obj->reg_identity!=NULL) ms_free(obj->reg_identity); if (obj->reg_route!=NULL) ms_free(obj->reg_route); if (obj->ssctx!=NULL) sip_setup_context_free(obj->ssctx); + if (obj->realm!=NULL) ms_free(obj->realm); if (obj->type!=NULL) ms_free(obj->type); } @@ -51,6 +52,7 @@ bool_t linphone_proxy_config_is_registered(const LinphoneProxyConfig *obj){ return obj->registered; } +#if 0 static void linphone_proxy_config_register(LinphoneProxyConfig *obj){ osip_message_t *msg; eXosip_lock(); @@ -58,6 +60,7 @@ static void linphone_proxy_config_register(LinphoneProxyConfig *obj){ eXosip_register_send_register(obj->rid,msg); eXosip_unlock(); } +#endif void linphone_proxy_config_register_again_with_updated_contact(LinphoneProxyConfig *obj, osip_message_t *orig_request, osip_message_t *last_answer){ osip_message_t *msg; @@ -116,7 +119,7 @@ int linphone_proxy_config_set_server_addr(LinphoneProxyConfig *obj, const char * void linphone_proxy_config_set_identity(LinphoneProxyConfig *obj, const char *identity){ int err=0; - osip_from_t *url; + osip_from_t *url=NULL; if (identity!=NULL && strlen(identity)>0){ osip_from_init(&url); err=osip_from_parse(url,identity); @@ -125,14 +128,23 @@ void linphone_proxy_config_set_identity(LinphoneProxyConfig *obj, const char *id osip_from_free(url); return; } - osip_from_free(url); } else err=-2; if (obj->reg_identity!=NULL) { ms_free(obj->reg_identity); obj->reg_identity=NULL; } if (err==-2) obj->reg_identity=NULL; - else obj->reg_identity=ms_strdup(identity); + else { + obj->reg_identity=ms_strdup(identity); + if (obj->realm) + ms_free(obj->realm); + obj->realm=ms_strdup(url->url->host); + } + if (url) osip_from_free(url); +} + +const char *linphone_proxy_config_get_domain(const LinphoneProxyConfig *cfg){ + return cfg->realm; } void linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route) @@ -448,8 +460,7 @@ void linphone_core_set_default_proxy(LinphoneCore *lc, LinphoneProxyConfig *conf } lc->default_proxy=config; -} - +} void linphone_core_set_default_proxy_index(LinphoneCore *lc, int index){ if (index<0) linphone_core_set_default_proxy(lc,NULL); @@ -482,20 +493,6 @@ LinphoneProxyConfig *linphone_core_get_proxy_config_from_rid(LinphoneCore *lc, i else return (LinphoneProxyConfig*)elem->data; } -void linphone_core_retry_proxy_register(LinphoneCore *lc, const char *realm) -{ - MSList *elem; - for (elem=lc->sip_conf.proxies;elem!=NULL;elem=ms_list_next(elem)){ - LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data; - /*ms_message("linphone_core_retry_proxy_register: cfg->auth_pending=%i, cfg->realm=%s, realm=%s", - cfg->auth_pending,cfg->realm,realm);*/ - if (cfg->auth_pending && cfg->realm!=NULL && strcmp(cfg->realm,realm)==0){ - ms_message("Restarting REGISTER request for %s.",cfg->reg_proxy); - linphone_proxy_config_register(cfg); - } - } -} - const MSList *linphone_core_get_proxy_config_list(const LinphoneCore *lc){ return lc->sip_conf.proxies; } diff --git a/linphone/coreapi/sipsetup.h b/linphone/coreapi/sipsetup.h index 1a038c629..38ef35d00 100644 --- a/linphone/coreapi/sipsetup.h +++ b/linphone/coreapi/sipsetup.h @@ -65,6 +65,7 @@ typedef struct _BuddyInfo{ char lastname[64]; char displayname[64]; char sip_uri[128]; + char email[128]; BuddyAddress address; }BuddyInfo; diff --git a/linphone/gtk-glade/buddylookup.c b/linphone/gtk-glade/buddylookup.c index bb24ca9df..96725ed77 100644 --- a/linphone/gtk-glade/buddylookup.c +++ b/linphone/gtk-glade/buddylookup.c @@ -30,7 +30,6 @@ enum { }; void linphone_gtk_buddy_lookup_window_destroyed(GtkWidget *w){ - g_message("BuddyLookup window is destroyed !"); guint tid=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"typing_timeout")); if (tid!=0){ g_source_remove(tid); @@ -39,7 +38,6 @@ void linphone_gtk_buddy_lookup_window_destroyed(GtkWidget *w){ if (tid!=0){ g_source_remove(tid); } - } void linphone_gtk_show_buddy_lookup_window(SipSetupContext *ctx){ @@ -76,50 +74,65 @@ void linphone_gtk_show_buddy_lookup_window(SipSetupContext *ctx){ gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(results),LOOKUP_RESULT_ADDRESS); g_object_set_data(G_OBJECT(w),"SipSetupContext",ctx); - //g_object_weak_ref(G_OBJECT(w),(GWeakNotify)linphone_gtk_buddy_lookup_window_destroyed,w); - g_signal_connect_swapped(G_OBJECT(results),"destroy",(GCallback)linphone_gtk_buddy_lookup_window_destroyed,w); + g_object_weak_ref(G_OBJECT(w),(GWeakNotify)linphone_gtk_buddy_lookup_window_destroyed,w); + //g_signal_connect_swapped(G_OBJECT(w),"destroy",(GCallback)linphone_gtk_buddy_lookup_window_destroyed,w); gtk_progress_bar_set_fraction(pb,0); gtk_progress_bar_set_text(pb,NULL); + gtk_dialog_add_button(GTK_DIALOG(w),GTK_STOCK_CLOSE,GTK_RESPONSE_CLOSE); + g_object_set_data(G_OBJECT(w),"last_state",GINT_TO_POINTER(-1)); gtk_widget_show(w); } +static void enable_add_buddy_button(GtkWidget *w, gboolean val){ + gtk_widget_set_sensitive(linphone_gtk_get_widget(w,"add_buddy"),val); +} + static gboolean linphone_gtk_process_buddy_lookup(GtkWidget *w){ BuddyLookupStatus bls; SipSetupContext *ctx; + int last_state; + gchar *tmp; + MSList *results=NULL; GtkProgressBar *pb=GTK_PROGRESS_BAR(linphone_gtk_get_widget(w,"progressbar")); ctx=(SipSetupContext*)g_object_get_data(G_OBJECT(w),"SipSetupContext"); + last_state=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"last_state")); bls=sip_setup_context_get_buddy_lookup_status(ctx); - MSList *results=NULL; + if (last_state==bls) return TRUE; switch(bls){ case BuddyLookupNone: - case BuddyLookupFailure: gtk_progress_bar_set_fraction(pb,0); gtk_progress_bar_set_text(pb,NULL); break; + case BuddyLookupFailure: + gtk_progress_bar_set_fraction(pb,0); + gtk_progress_bar_set_text(pb,_("Error communicating with server.")); + break; case BuddyLookupConnecting: - gtk_progress_bar_set_fraction(pb,20); + gtk_progress_bar_set_fraction(pb,0.2); gtk_progress_bar_set_text(pb,_("Connecting...")); break; case BuddyLookupConnected: - gtk_progress_bar_set_fraction(pb,40); + gtk_progress_bar_set_fraction(pb,0.4); gtk_progress_bar_set_text(pb,_("Connected")); break; case BuddyLookupReceivingResponse: - gtk_progress_bar_set_fraction(pb,80); + gtk_progress_bar_set_fraction(pb,0.8); gtk_progress_bar_set_text(pb,_("Receiving data...")); break; case BuddyLookupDone: - gtk_progress_bar_set_fraction(pb,100); - gtk_progress_bar_set_text(pb,_("Done !")); sip_setup_context_get_buddy_lookup_results(ctx,&results); - if (results){ - linphone_gtk_display_lookup_results( + linphone_gtk_display_lookup_results( linphone_gtk_get_widget(w,"search_results"), results); - sip_setup_context_free_results(results); - } + gtk_progress_bar_set_fraction(pb,1); + tmp=g_strdup_printf(_("Found %i contact(s)"),ms_list_size(results)); + gtk_progress_bar_set_text(pb,tmp); + g_free(tmp); + if (results) sip_setup_context_free_results(results); break; } + enable_add_buddy_button(w,bls==BuddyLookupDone); + g_object_set_data(G_OBJECT(w),"last_state",GINT_TO_POINTER(bls)); return TRUE; } @@ -135,8 +148,10 @@ static gboolean keyword_typing_finished(GtkWidget *w){ guint tid2; ctx=(SipSetupContext*)g_object_get_data(G_OBJECT(w),"SipSetupContext"); sip_setup_context_lookup_buddy(ctx,keyword); - tid2=g_timeout_add(250,(GSourceFunc)linphone_gtk_process_buddy_lookup,w); - g_object_set_data(G_OBJECT(w),"buddylookup_processing",GINT_TO_POINTER(tid2)); + if (g_object_get_data(G_OBJECT(w),"buddylookup_processing")==NULL){ + tid2=g_timeout_add(20,(GSourceFunc)linphone_gtk_process_buddy_lookup,w); + g_object_set_data(G_OBJECT(w),"buddylookup_processing",GINT_TO_POINTER(tid2)); + } } return FALSE; } @@ -183,7 +198,7 @@ void linphone_gtk_add_buddy_from_database(GtkWidget *button){ char *name; char *addr; LinphoneFriend *lf; - gtk_tree_model_get (model, &iter,LOOKUP_RESULT_SIP_URI , &uri,LOOKUP_RESULT_NAME, &name -1); + gtk_tree_model_get (model, &iter,LOOKUP_RESULT_SIP_URI , &uri,LOOKUP_RESULT_NAME, &name, -1); addr=g_strdup_printf("%s <%s>",name,uri); lf=linphone_friend_new_with_addr(addr); g_free(addr); diff --git a/linphone/gtk-glade/buddylookup.glade b/linphone/gtk-glade/buddylookup.glade index 7a278ef17..bdbbce007 100644 --- a/linphone/gtk-glade/buddylookup.glade +++ b/linphone/gtk-glade/buddylookup.glade @@ -1,115 +1,155 @@ - + - - Search people... - - + + 5 + Search contacts in directory + GTK_WIN_POS_CENTER_ON_PARENT + linphone2.png + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + True - 5 - 0 + 2 - + True - 12 + 5 + 0 - + True + 12 - + True - True - True - - - - False - - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_ETCHED_IN - - 300 - 140 + True True + True + + + False + - - - 6 - 1 - - - - - True - True - True - 0 - - + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_ETCHED_IN + + + 512 + 140 + True + True + + + + + 6 + 1 + + + + + True + True + True + + + + False + 2 + + + + True - + True - gtk-add + False + True + True + 0 + + + + True + + + True + gtk-add + + + False + False + + + + + True + Add to my list + + + 1 + + + + False False - - - - - True - Add to my list - - - 1 + 5 + + 3 + - - False - 5 - 2 - - - - - True - True - True - - - - False - 3 - - - - - - True - <b>Search somebody</b> - True + + + True + <b>Search somebody</b> + True + + + label_item + + - label_item + 1 + + + + + True + GTK_BUTTONBOX_END + + + + + + + + + False + GTK_PACK_END diff --git a/linphone/gtk-glade/friendlist.c b/linphone/gtk-glade/friendlist.c index 863a12087..b933245aa 100644 --- a/linphone/gtk-glade/friendlist.c +++ b/linphone/gtk-glade/friendlist.c @@ -364,12 +364,10 @@ void linphone_gtk_contact_ok(GtkWidget *button){ GtkWidget *w=gtk_widget_get_toplevel(button); LinphoneFriend *lf=(LinphoneFriend*)g_object_get_data(G_OBJECT(w),"friend_ref"); char *fixed_uri=NULL; - gboolean editing=FALSE,show_presence,allow_presence; + gboolean show_presence,allow_presence; const gchar *name,*uri; if (lf==NULL){ lf=linphone_friend_new(); - }else{ - editing=TRUE; } name=gtk_entry_get_text(GTK_ENTRY(linphone_gtk_get_widget(w,"name"))); uri=gtk_entry_get_text(GTK_ENTRY(linphone_gtk_get_widget(w,"sip_address"))); @@ -385,7 +383,7 @@ void linphone_gtk_contact_ok(GtkWidget *button){ linphone_friend_set_name(lf,name); linphone_friend_send_subscribe(lf,show_presence); linphone_friend_set_inc_subscribe_policy(lf,allow_presence==TRUE ? LinphoneSPAccept : LinphoneSPDeny); - if (editing){ + if (linphone_friend_in_list(lf)) { linphone_friend_done(lf); }else{ linphone_core_add_friend(linphone_gtk_get_core(),lf); @@ -394,16 +392,6 @@ void linphone_gtk_contact_ok(GtkWidget *button){ gtk_widget_destroy(w); } -SipSetupContext* linphone_gtk_get_default_sip_setup_context(void){ - LinphoneCore *lc=linphone_gtk_get_core(); - LinphoneProxyConfig *cfg=NULL; - linphone_core_get_default_proxy(lc,&cfg); - if (cfg){ - return linphone_proxy_config_get_sip_setup_context(cfg); - } - return NULL; -} - static GtkWidget *linphone_gtk_create_contact_menu(GtkWidget *contact_list){ GtkWidget *menu=gtk_menu_new(); GtkWidget *menu_item; @@ -414,7 +402,14 @@ static GtkWidget *linphone_gtk_create_contact_menu(GtkWidget *contact_list){ GtkTreeIter iter; GtkTreeModel *model; GtkWidget *image; - SipSetupContext* ssc=linphone_gtk_get_default_sip_setup_context(); + LinphoneCore *lc=linphone_gtk_get_core(); + LinphoneProxyConfig *cfg=NULL; + SipSetupContext * ssc=NULL; + + linphone_core_get_default_proxy(lc,&cfg); + if (cfg){ + ssc=linphone_proxy_config_get_sip_setup_context(cfg); + } g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK (gtk_widget_destroy), NULL); select = gtk_tree_view_get_selection(GTK_TREE_VIEW(contact_list)); @@ -451,10 +446,11 @@ static GtkWidget *linphone_gtk_create_contact_menu(GtkWidget *contact_list){ gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); g_signal_connect_swapped(G_OBJECT(menu_item),"activate",(GCallback)linphone_gtk_remove_contact,contact_list); - g_message("ssc=%p",ssc); if (ssc && (sip_setup_context_get_capabilities(ssc) & SIP_SETUP_CAP_BUDDY_LOOKUP)) { - menu_item=gtk_image_menu_item_new_with_label(_("Search contact")); - image=gtk_image_new_from_stock(GTK_STOCK_FIND,GTK_ICON_SIZE_MENU); + gchar *tmp=g_strdup_printf(_("Add new contact from %s directory"),linphone_proxy_config_get_domain(cfg)); + menu_item=gtk_image_menu_item_new_with_label(tmp); + g_free(tmp); + image=gtk_image_new_from_stock(GTK_STOCK_ADD,GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item),image); gtk_widget_show(image); gtk_widget_show(menu_item); diff --git a/linphone/gtk-glade/main.c b/linphone/gtk-glade/main.c index 37f65bd71..13d742447 100644 --- a/linphone/gtk-glade/main.c +++ b/linphone/gtk-glade/main.c @@ -117,6 +117,7 @@ const char *linphone_gtk_get_config_file(){ } static void linphone_gtk_init_liblinphone(const char *file){ + linphone_core_set_user_agent("Linphone", LINPHONE_VERSION); the_core=linphone_core_new(&vtable,file,NULL); }