Commit 6f9f860a authored by Simon Morlat's avatar Simon Morlat

allow multiple transports in gtk application, allow to configure transport per...

allow multiple transports in gtk application, allow to configure transport per proxy (not yet finished)
parent ab7e606d
......@@ -112,11 +112,21 @@ void linphone_address_set_domain(LinphoneAddress *uri, const char *host){
* Sets the port number.
**/
void linphone_address_set_port(LinphoneAddress *uri, int port){
#ifdef USE_BELLESIP
sal_address_set_port(uri,port);
#else
sal_address_set_port_int(uri,port);
#endif
}
/**
* Set a transport.
**/
void linphone_address_set_transport(LinphoneAddress *uri, LinphoneTransportType tp){
sal_address_set_transport(uri,(SalTransport)tp);
}
/**
* Get the transport.
**/
LinphoneTransportType linphone_address_get_transport(const LinphoneAddress *uri){
return (LinphoneTransportType)sal_address_get_transport(uri);
}
/**
......@@ -142,6 +152,13 @@ char *linphone_address_as_string_uri_only(const LinphoneAddress *u){
return sal_address_as_string_uri_only(u);
}
/**
* Returns true if address refers to a secure location (sips)
**/
bool_t linphone_address_is_secure(const LinphoneAddress *uri){
return sal_address_is_secure(uri);
}
static bool_t strings_equals(const char *s1, const char *s2){
if (s1==NULL && s2==NULL) return TRUE;
if (s1!=NULL && s2!=NULL && strcmp(s1,s2)==0) return TRUE;
......
......@@ -43,6 +43,14 @@ const char *sal_address_get_scheme(const SalAddress *addr){
} else
return NULL;
}
bool_t sal_address_is_secure(const SalAddress *addr){
belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr);
belle_sip_uri_t* uri = belle_sip_header_address_get_uri(header_addr);
if (uri) return belle_sip_uri_is_secure(uri);
return FALSE;
}
const char *sal_address_get_display_name(const SalAddress* addr){
belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr);
return belle_sip_header_address_get_displayname(header_addr);
......@@ -52,17 +60,17 @@ const char *sal_address_get_display_name_unquoted(const SalAddress *addr){
return sal_address_get_display_name(addr);
}
#define SAL_ADDRESS_GET(addr,param) \
belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr);\
{belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr);\
belle_sip_uri_t* uri = belle_sip_header_address_get_uri(header_addr);\
if (uri) {\
return belle_sip_uri_get_##param(uri);\
} else\
return NULL;
return NULL;}
#define SAL_ADDRESS_SET(addr,param,value) \
#define SAL_ADDRESS_SET(addr,param,value) {\
belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr);\
belle_sip_uri_t* uri = belle_sip_header_address_get_uri(header_addr);\
belle_sip_uri_set_##param(uri,value);
belle_sip_uri_set_##param(uri,value);}
const char *sal_address_get_username(const SalAddress *addr){
SAL_ADDRESS_GET(addr,user)
......@@ -137,7 +145,9 @@ void sal_address_set_param(SalAddress *addr,const char* name,const char* value){
}
void sal_address_set_transport(SalAddress* addr,SalTransport transport){
SAL_ADDRESS_SET(addr,transport_param,sal_transport_to_string(transport));
if (!sal_address_is_secure(addr)){
SAL_ADDRESS_SET(addr,transport_param,sal_transport_to_string(transport));
}
}
void sal_address_set_transport_name(SalAddress* addr,const char *transport){
......
......@@ -1892,6 +1892,13 @@ static int apply_transports(LinphoneCore *lc){
return 0;
}
/**
* Returns TRUE if given transport type is supported by the library, FALSE otherwise.
**/
bool_t linphone_core_sip_transport_supported(const LinphoneCore *lc, LinphoneTransportType tp){
return sal_transport_available(lc->sal,(SalTransport)tp);
}
/**
* Sets the ports to be used for each of transport (UDP or TCP)
*
......
......@@ -89,6 +89,19 @@ typedef struct _LCSipTransports{
} LCSipTransports;
/**
* Enum describing transport type for LinphoneAddress.
**/
enum _LinphoneTransportType{
LinphoneTransportUdp,
LinphoneTransportTcp,
LinphoneTransportTls,
LinphoneTransportDtls
};
/*this enum MUST be kept in sync with the SalTransport from sal.h*/
typedef enum _LinphoneTransportType LinphoneTransportType;
/**
* Object that represents a SIP address.
*
......@@ -191,6 +204,9 @@ LINPHONE_PUBLIC void linphone_address_set_domain(LinphoneAddress *uri, const cha
LINPHONE_PUBLIC void linphone_address_set_port(LinphoneAddress *uri, int port);
/*remove tags, params etc... so that it is displayable to the user*/
LINPHONE_PUBLIC void linphone_address_clean(LinphoneAddress *uri);
LINPHONE_PUBLIC bool_t linphone_address_is_secure(const LinphoneAddress *uri);
LINPHONE_PUBLIC LinphoneTransportType linphone_address_get_transport(const LinphoneAddress *uri);
LINPHONE_PUBLIC void linphone_address_set_transport(LinphoneAddress *uri,LinphoneTransportType type);
LINPHONE_PUBLIC char *linphone_address_as_string(const LinphoneAddress *u);
LINPHONE_PUBLIC char *linphone_address_as_string_uri_only(const LinphoneAddress *u);
LINPHONE_PUBLIC bool_t linphone_address_weak_equal(const LinphoneAddress *a1, const LinphoneAddress *a2);
......@@ -1526,6 +1542,8 @@ LINPHONE_PUBLIC int linphone_core_get_sip_port(LinphoneCore *lc);
LINPHONE_PUBLIC int linphone_core_set_sip_transports(LinphoneCore *lc, const LCSipTransports *transports);
LINPHONE_PUBLIC int linphone_core_get_sip_transports(LinphoneCore *lc, LCSipTransports *transports);
LINPHONE_PUBLIC bool_t linphone_core_sip_transport_supported(const LinphoneCore *lc, LinphoneTransportType tp);
/**
*
* Give access to the UDP sip socket. Can be useful to configure this socket as persistent I.E kCFStreamNetworkServiceType set to kCFStreamNetworkServiceTypeVoIP)
......
This diff is collapsed.
......@@ -102,49 +102,6 @@ void linphone_gtk_update_my_contact(GtkWidget *w){
linphone_gtk_load_identities();
}
void linphone_gtk_update_my_port(GtkWidget *w){
GtkWidget *pb=gtk_widget_get_toplevel(GTK_WIDGET(w));
LCSipTransports tr;
LinphoneCore *lc=linphone_gtk_get_core();
GtkComboBox *combo = GTK_COMBO_BOX(linphone_gtk_get_widget(pb, "proto_combo"));
gint port = (gint)gtk_spin_button_get_value(GTK_SPIN_BUTTON(w));
if (port == 1) { // We use default port if not specified
if (strcmp(gtk_combo_box_get_active_text(combo), "SIP (UDP)") == 0) {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
5060);
}
else if (strcmp(gtk_combo_box_get_active_text(combo), "SIP (TCP)") == 0) {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
5060);
}
else if (strcmp(gtk_combo_box_get_active_text(combo), "SIP (TLS)") == 0) {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
5061);
}
}
linphone_core_get_sip_transports(lc,&tr);
gchar *selected = gtk_combo_box_get_active_text(combo);
if (strcmp(selected, "SIP (TCP)") == 0) {
tr.tcp_port = (gint)gtk_spin_button_get_value(GTK_SPIN_BUTTON(w));
tr.udp_port = 0;
tr.tls_port = 0;
}
else if (strcmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(linphone_gtk_get_widget(pb, "proto_combo"))), "SIP (UDP)") == 0) {
tr.udp_port = (gint)gtk_spin_button_get_value(GTK_SPIN_BUTTON(w));
tr.tcp_port = 0;
tr.tls_port = 0;
}
else if (strcmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(linphone_gtk_get_widget(pb, "proto_combo"))), "SIP (TLS)") == 0){
tr.udp_port = 0;
tr.tcp_port = 0;
tr.tls_port = (gint)gtk_spin_button_get_value(GTK_SPIN_BUTTON(w));
}
linphone_core_set_sip_transports(lc,&tr);
}
void linphone_gtk_set_propety_entry(GtkWidget *w, gboolean stunServer, gboolean ip){
GtkWidget *stun_entry=linphone_gtk_get_widget(gtk_widget_get_toplevel(w),"stun_server");
GtkWidget *ip_entry=linphone_gtk_get_widget(gtk_widget_get_toplevel(w),"nat_address");
......@@ -691,6 +648,48 @@ static void linphone_gtk_proxy_closed(GtkWidget *w){
}
}
static void fill_transport_combo_box(GtkWidget *combo, LinphoneTransportType choice, gboolean is_sensitive){
GtkTreeModel *model;
GtkTreeIter iter;
if ((model=gtk_combo_box_get_model(GTK_COMBO_BOX(combo)))==NULL){
/*case where combo box is created with no model*/
GtkCellRenderer *renderer=gtk_cell_renderer_text_new();
model=GTK_TREE_MODEL(gtk_list_store_new(1,G_TYPE_STRING));
gtk_combo_box_set_model(GTK_COMBO_BOX(combo),model);
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo),renderer,TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo),renderer,"markup",0,NULL);
}
gtk_list_store_append(GTK_LIST_STORE(model),&iter);
gtk_list_store_set(GTK_LIST_STORE(model),&iter,0,"UDP",-1);
gtk_list_store_append(GTK_LIST_STORE(model),&iter);
gtk_list_store_set(GTK_LIST_STORE(model),&iter,0,"TCP",-1);
if (linphone_core_sip_transport_supported(linphone_gtk_get_core(),LinphoneTransportTls)){
gtk_list_store_append(GTK_LIST_STORE(model),&iter);
gtk_list_store_set(GTK_LIST_STORE(model),&iter,0,"TLS",-1);
}
gtk_combo_box_set_active(GTK_COMBO_BOX(combo),(int)choice);
gtk_widget_set_sensitive(combo,is_sensitive);
}
static void update_proxy_transport(GtkWidget *w){
const char *addr=gtk_entry_get_text(GTK_ENTRY(linphone_gtk_get_widget(w,"proxy")));
LinphoneAddress *laddr=linphone_address_new(addr);
if (laddr){
GtkWidget *combo=linphone_gtk_get_widget(w,"transport");
if (linphone_address_is_secure(laddr)){
fill_transport_combo_box(combo,LinphoneTransportTls,FALSE);
}else{
fill_transport_combo_box(combo,linphone_address_get_transport(laddr),TRUE);
}
linphone_address_destroy(laddr);
}
}
void linphone_gtk_proxy_address_changed(GtkEditable *editable){
update_proxy_transport(gtk_widget_get_toplevel(GTK_WIDGET(editable)));
}
void linphone_gtk_show_proxy_config(GtkWidget *pb, LinphoneProxyConfig *cfg){
GtkWidget *w=linphone_gtk_create_window("sip_account");
const char *tmp;
......@@ -698,8 +697,7 @@ void linphone_gtk_show_proxy_config(GtkWidget *pb, LinphoneProxyConfig *cfg){
linphone_proxy_config_edit(cfg);
gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"identity")),
linphone_proxy_config_get_identity(cfg));
gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"proxy")),
linphone_proxy_config_get_addr(cfg));
gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"proxy")),linphone_proxy_config_get_addr(cfg));
tmp=linphone_proxy_config_get_route(cfg);
if (tmp) gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"route")),tmp);
tmp=linphone_proxy_config_get_contact_parameters(cfg);
......@@ -901,14 +899,6 @@ void linphone_gtk_lang_changed(GtkComboBox *combo){
}
}
void linphone_gtk_proto_changed(GtkComboBox *combo){
GtkWidget *pb=gtk_widget_get_toplevel(GTK_WIDGET(combo));
GtkWidget *proto_port = linphone_gtk_get_widget(pb, "proto_port");
// When we change the network protocol, we call update_my_port to move the port number from the old protocol to the new one
linphone_gtk_update_my_port(proto_port);
}
static void linphone_gtk_ui_level_adapt(GtkWidget *top) {
gboolean ui_advanced;
const char *simple_ui = linphone_gtk_get_ui_config("simple_ui", "parameters.codec_tab parameters.transport_frame parameters.ports_frame");
......@@ -1074,6 +1064,48 @@ void linphone_gtk_fill_video_renderers(GtkWidget *pb){
if (active!=-1) gtk_combo_box_set_active(GTK_COMBO_BOX(combo),active);
}
typedef struct {
guint timeout_id;
LCSipTransports tp;
}PortConfigCtx;
static void port_config_free(PortConfigCtx *ctx){
g_free(ctx);
}
static void apply_transports(PortConfigCtx *ctx){
GtkWidget *mw=linphone_gtk_get_main_window();
LCSipTransports tp;
LinphoneCore *lc=linphone_gtk_get_core();
linphone_core_get_sip_transports(lc,&tp);
tp.udp_port=ctx->tp.udp_port;
tp.tcp_port=ctx->tp.tcp_port;
linphone_core_set_sip_transports(lc,&tp);
g_object_set_data(G_OBJECT(mw),"port_config",NULL);
}
static void transport_changed(GtkWidget *parameters){
GtkWidget *mw=linphone_gtk_get_main_window();
PortConfigCtx *cfg=(PortConfigCtx*)g_object_get_data(G_OBJECT(mw),"port_config");
if (cfg==NULL){
cfg=g_new0(PortConfigCtx,1);
g_object_set_data_full(G_OBJECT(mw),"port_config",cfg,(GDestroyNotify)port_config_free);
}
if (cfg->timeout_id!=0)
g_source_remove(cfg->timeout_id);
cfg->tp.udp_port=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(linphone_gtk_get_widget(parameters,"sip_udp_port")));
cfg->tp.tcp_port=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(linphone_gtk_get_widget(parameters,"sip_tcp_port")));
cfg->timeout_id=g_timeout_add_seconds(2,(GSourceFunc)apply_transports,cfg);
}
void linphone_gtk_udp_port_value_changed(GtkSpinButton *button){
transport_changed(gtk_widget_get_toplevel((GtkWidget*)button));
}
void linphone_gtk_tcp_port_value_changed(GtkSpinButton *button){
transport_changed(gtk_widget_get_toplevel((GtkWidget*)button));
}
void linphone_gtk_show_parameters(void){
GtkWidget *mw=linphone_gtk_get_main_window();
GtkWidget *pb=(GtkWidget*)g_object_get_data(G_OBJECT(mw),"parameters");
......@@ -1101,21 +1133,11 @@ void linphone_gtk_show_parameters(void){
linphone_core_ipv6_enabled(lc));
linphone_core_get_sip_transports(lc,&tr);
if (tr.tcp_port > 0) {
gtk_combo_box_set_active(GTK_COMBO_BOX(linphone_gtk_get_widget(pb,"proto_combo")), 1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"proto_port")),
tr.tcp_port);
}
else if (tr.tls_port > 0) {
gtk_combo_box_set_active(GTK_COMBO_BOX(linphone_gtk_get_widget(pb,"proto_combo")), 2);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"proto_port")),
tr.tls_port);
}
else {
gtk_combo_box_set_active(GTK_COMBO_BOX(linphone_gtk_get_widget(pb,"proto_combo")), 0);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"proto_port")),
gtk_spin_button_set_value(GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"sip_udp_port")),
tr.udp_port);
}
gtk_spin_button_set_value(GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb,"sip_tcp_port")),
tr.tcp_port);
linphone_core_get_audio_port_range(lc, &min_port, &max_port);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(linphone_gtk_get_widget(pb, "audio_min_rtp_port")), min_port);
......@@ -1214,10 +1236,6 @@ void linphone_gtk_show_parameters(void){
ui_advanced);
linphone_gtk_ui_level_adapt(pb);
g_signal_connect(G_OBJECT(linphone_gtk_get_widget(pb,"proto_port")),"value-changed",(GCallback)linphone_gtk_update_my_port,NULL);
g_signal_connect(G_OBJECT(linphone_gtk_get_widget(pb,"proto_combo")),"changed",(GCallback)linphone_gtk_proto_changed,NULL);
if (linphone_core_tunnel_available()){
gtk_widget_set_visible(GTK_WIDGET(linphone_gtk_get_widget(pb,"tunnel_edit_button")), TRUE);
gtk_widget_set_visible(GTK_WIDGET(linphone_gtk_get_widget(pb,"tunnel_label")), TRUE);
......
This diff is collapsed.
......@@ -85,12 +85,9 @@ const char *sal_address_get_display_name(const SalAddress* addr);
const 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);
#ifdef USE_BELLESIP
int sal_address_get_port(const SalAddress *addr);
#else
const char * sal_address_get_port(const SalAddress *addr);
int sal_address_get_port_int(const SalAddress *addr);
#endif
bool_t sal_address_is_secure(const SalAddress *addr);
SalTransport sal_address_get_transport(const SalAddress* addr);
const char* sal_address_get_transport_name(const SalAddress* addr);
......@@ -479,6 +476,7 @@ void sal_signing_key_delete(SalSigningKey *key);
void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs);
int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int is_secure);
int sal_unlisten_ports(Sal *ctx);
int sal_transport_available(Sal *ctx, SalTransport t);
void sal_set_dscp(Sal *ctx, int dscp);
int sal_reset_transports(Sal *ctx);
ortp_socket_t sal_get_socket(Sal *ctx);
......
127.0.0.1 sip2.linphone.org sip.example.org sipopen.example.org auth.example.org auth1.example.org auth2.example.org altname.linphone.org sip.wildcard1.linphone.org altname.wildcard2.linphone.org
94.23.19.176 sip2.linphone.org sip.example.org sipopen.example.org auth.example.org auth1.example.org auth2.example.org altname.linphone.org sip.wildcard1.linphone.org altname.wildcard2.linphone.org
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