Commit b5497652 authored by Simon Morlat's avatar Simon Morlat

automatically surround displayname without quotes, to allow users to use non ascii characters.

parent ff1bcf92
......@@ -57,6 +57,14 @@ const char *linphone_address_get_display_name(const LinphoneAddress* u){
return sal_address_get_display_name(u);
}
/**
* Returns the display name without quotes.
* @note WARNING: the returned string must be freed by user.
**/
char *linphone_address_get_display_name_unquoted(const LinphoneAddress *addr){
return sal_address_get_display_name_unquoted(addr);
}
/**
* Returns the username.
**/
......
/*
linphone
Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org)
Copyright (C) 2000 - 2010 Simon MORLAT (simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -64,6 +64,7 @@ LinphoneAddress * linphone_address_new(const char *uri);
LinphoneAddress * linphone_address_clone(const LinphoneAddress *uri);
const char *linphone_address_get_scheme(const LinphoneAddress *u);
const char *linphone_address_get_display_name(const LinphoneAddress* u);
char *linphone_address_get_display_name_unquoted(const LinphoneAddress *u);
const char *linphone_address_get_username(const LinphoneAddress *u);
const char *linphone_address_get_domain(const LinphoneAddress *u);
void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name);
......
......@@ -45,6 +45,7 @@ SalAddress * sal_address_new(const char *uri);
SalAddress * sal_address_clone(const SalAddress *addr);
const char *sal_address_get_scheme(const SalAddress *addr);
const char *sal_address_get_display_name(const SalAddress* addr);
char *sal_address_get_display_name_unquoted(const SalAddress *addr);
const char *sal_address_get_username(const SalAddress *addr);
const char *sal_address_get_domain(const SalAddress *addr);
void sal_address_set_display_name(SalAddress *addr, const char *display_name);
......
......@@ -1575,7 +1575,17 @@ int sal_unregister(SalOp *h){
return 0;
}
static void sal_address_quote_displayname(SalAddress *addr){
osip_from_t *u=(osip_from_t*)addr;
if (u->displayname!=NULL && u->displayname[0]!='\0'
&& u->displayname[0]!='"'){
int len=strlen(u->displayname)+1+2;
char *quoted=osip_malloc(len);
snprintf(quoted,len,"\"%s\"",u->displayname);
osip_free(u->displayname);
u->displayname=quoted;
}
}
SalAddress * sal_address_new(const char *uri){
osip_from_t *from;
......@@ -1584,6 +1594,7 @@ SalAddress * sal_address_new(const char *uri){
osip_from_free(from);
return NULL;
}
sal_address_quote_displayname ((SalAddress*)from);
return (SalAddress*)from;
}
......@@ -1605,6 +1616,18 @@ const char *sal_address_get_display_name(const SalAddress* addr){
return null_if_empty(u->displayname);
}
char *sal_address_get_display_name_unquoted(const SalAddress *addr){
const osip_from_t *u=(const osip_from_t*)addr;
const char *dn=null_if_empty(u->displayname);
char *ret=NULL;
if (dn!=NULL) {
char *tmp=osip_strdup_without_quote(dn);
ret=ms_strdup(tmp);
osip_free(tmp);
}
return ret;
}
const char *sal_address_get_username(const SalAddress *addr){
const osip_from_t *u=(const osip_from_t*)addr;
return null_if_empty(u->url->username);
......@@ -1621,8 +1644,10 @@ void sal_address_set_display_name(SalAddress *addr, const char *display_name){
osip_free(u->displayname);
u->displayname=NULL;
}
if (display_name!=NULL)
if (display_name!=NULL && display_name[0]!='\0'){
u->displayname=osip_strdup(display_name);
sal_address_quote_displayname(addr);
}
}
void sal_address_set_username(SalAddress *addr, const char *username){
......
......@@ -308,7 +308,7 @@ void linphone_gtk_show_friends(void){
LinphoneFriend *lf=(LinphoneFriend*)itf->data;
const LinphoneAddress *f_uri=linphone_friend_get_address(lf);
char *uri=linphone_address_as_string(f_uri);
const char *name=linphone_address_get_display_name(f_uri);
char *name=linphone_address_get_display_name_unquoted (f_uri);
const char *display=name;
char *escaped=NULL;
if (lookup){
......@@ -341,6 +341,7 @@ void linphone_gtk_show_friends(void){
}
}
ms_free(uri);
if (name!=NULL) ms_free(name);
}
}
......@@ -372,16 +373,17 @@ void linphone_gtk_remove_contact(GtkWidget *button){
void linphone_gtk_show_contact(LinphoneFriend *lf){
GtkWidget *w=linphone_gtk_create_window("contact");
char *uri;
const char *name;
char *name;
const LinphoneAddress *f_uri=linphone_friend_get_address(lf);
uri=linphone_address_as_string_uri_only(f_uri);
name=linphone_address_get_display_name(f_uri);
name=linphone_address_get_display_name_unquoted (f_uri);
if (uri) {
gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"sip_address")),uri);
ms_free(uri);
}
if (name){
gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"name")),name);
ms_free(name);
}
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(w,"show_presence")),
linphone_friend_get_send_subscribe(lf));
......
......@@ -72,7 +72,7 @@ void linphone_gtk_show_idle_view(void){
void display_peer_name_in_label(GtkWidget *label, const char *uri){
LinphoneAddress *from;
const char *displayname=NULL;
char *displayname=NULL;
char *id=NULL;
char *uri_label;
......@@ -83,18 +83,15 @@ void display_peer_name_in_label(GtkWidget *label, const char *uri){
from=linphone_address_new(uri);
if (from!=NULL){
if (linphone_address_get_display_name(from))
displayname=linphone_address_get_display_name(from);
displayname=linphone_address_get_display_name_unquoted (from);
id=linphone_address_as_string_uri_only(from);
}else id=ms_strdup(uri);
if (displayname!=NULL)
if (displayname!=NULL){
uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>",
displayname,id);
else
ms_free(displayname);
}else
uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id);
gtk_label_set_markup(GTK_LABEL(label),uri_label);
ms_free(id);
......
......@@ -395,7 +395,7 @@ static void set_video_window_decorations(GdkWindow *w){
linphone_address_clean(uri);
if (linphone_address_get_display_name(uri)!=NULL){
display_name=ms_strdup(linphone_address_get_display_name(uri));
display_name=linphone_address_get_display_name_unquoted (uri);
}else{
display_name=linphone_address_as_string(uri);
}
......
......@@ -802,8 +802,11 @@ void linphone_gtk_show_parameters(void){
/* SIP CONFIG */
contact=linphone_core_get_primary_contact_parsed(lc);
if (contact){
if (linphone_address_get_display_name(contact))
gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(pb,"displayname")),linphone_address_get_display_name(contact));
if (linphone_address_get_display_name(contact)) {
char *dn=linphone_address_get_display_name_unquoted (contact);
gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(pb,"displayname")),dn);
ms_free(dn);
}
if (linphone_address_get_username(contact))
gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(pb,"username")),linphone_address_get_username(contact));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment