From 5e0c3388e16b53a9c3b1a85ca916480aca6fa891 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Mon, 30 Jan 2012 23:47:29 +0100 Subject: [PATCH] tunnel extension ported to windows (mingw) and working --- README | 2 -- README.mingw | 2 +- coreapi/linphone_tunnel.cc | 32 +++++++++++++++++++++++ coreapi/linphone_tunnel.h | 8 ++++-- coreapi/linphonecore.c | 31 ++--------------------- coreapi/linphonecore.h | 4 --- gtk/propertybox.c | 52 ++++++++++++++++++++++++-------------- tunnel | 2 +- 8 files changed, 75 insertions(+), 58 deletions(-) diff --git a/README b/README index 630ca8b7..7e68bb19 100644 --- a/README +++ b/README @@ -18,8 +18,6 @@ This is Linphone, a free (GPL) video softphone based on the SIP protocol. with their corresponding -dev or -devel package if you don't use source packages. -Note that you need to build and install the tunnel library PRIOR to build linphone. - For windows compilation see README.mingw. For macOS X, see README.macos diff --git a/README.mingw b/README.mingw index 93ba70d4..c35236dc 100644 --- a/README.mingw +++ b/README.mingw @@ -55,7 +55,7 @@ It is recommended that you create a directory somewhere with a path without any c:\sources\ Within msys-git bash, do cd /c/sources -git clone git://git.savannah.nongnu.org/linphone.git --recursive +git clone git://git.linphone.org/linphone.git --recursive Building diff --git a/coreapi/linphone_tunnel.cc b/coreapi/linphone_tunnel.cc index 120b1b12..5a341ac7 100644 --- a/coreapi/linphone_tunnel.cc +++ b/coreapi/linphone_tunnel.cc @@ -135,3 +135,35 @@ LinphoneTunnelState linphone_tunnel_get_state(LinphoneTunnel *tunnel){ return LinphoneTunnelDisabled; } } + +static void tunnel_add_servers_from_config(LinphoneTunnel *tunnel, const char* confaddress){ + char *addresses=(char*)ms_strdup(confaddress); + char *str1; + for(str1=addresses;;str1=NULL){ + char *port; + char *address=strtok(str1," "); // Not thread safe + if (!address) break; + port=strchr(address, ':'); + if (!port) ms_fatal("Bad tunnel address %s", address); + *port++='\0'; + linphone_tunnel_add_server(tunnel, address, atoi(port)); + } + ms_free(addresses); +} + +/** + * Update tunnel using configuration. + */ +void linphone_tunnel_update(LinphoneTunnel *tunnel){ + bool_t enabled; + const char* addresses=linphone_tunnel_get_server_addresses(tunnel); + linphone_tunnel_clean_servers(tunnel); + if (addresses){ + tunnel_add_servers_from_config(tunnel,addresses); + } + enabled=linphone_tunnel_get_state(tunnel)==LinphoneTunnelEnabled && addresses!=NULL; + linphone_tunnel_enable(tunnel, enabled); +} + + + diff --git a/coreapi/linphone_tunnel.h b/coreapi/linphone_tunnel.h index 6a2d5218..fe9675ea 100644 --- a/coreapi/linphone_tunnel.h +++ b/coreapi/linphone_tunnel.h @@ -51,8 +51,8 @@ void linphone_tunnel_set_http_proxy_auth_info(LinphoneTunnel*tunnel, const char* * LinphoneTunnelState describes the tunnel activation states. */ typedef enum _LinphoneTunnelState{ - LinphoneTunnelDisabled, /**max_calls=lp_config_get_int(config,"misc","max_calls",NB_MAX_CALLS); } -#ifdef TUNNEL_ENABLED -static void tunnel_add_servers_from_config(LinphoneTunnel *tunnel, const char* confaddress){ - char *addresses=(char*)ms_strdup(confaddress); - char *str1; - for(str1=addresses;;str1=NULL){ - char *port; - char *address=strtok(str1," "); // Not thread safe - if (!address) break; - port=strchr(address, ':'); - if (!port) ms_fatal("Bad tunnel address %s", address); - *port++='\0'; - linphone_tunnel_add_server(tunnel, address, atoi(port)); - } - ms_free(addresses); -} -#endif -void linphone_core_update_tunnel(LinphoneCore *lc){ -#ifdef TUNNEL_ENABLED - bool_t enabled; - const char* addresses=linphone_tunnel_get_server_addresses(lc->tunnel); - if (addresses){ - linphone_tunnel_clean_servers(lc->tunnel); - tunnel_add_servers_from_config(lc->tunnel,addresses); - } - enabled=linphone_tunnel_get_state(lc->tunnel)==LinphoneTunnelEnabled && addresses!=NULL; - linphone_tunnel_enable(lc->tunnel, enabled); -#endif -} + static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path, const char *factory_config_path, void * userdata) @@ -1125,7 +1098,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta ui_config_read(lc); #ifdef TUNNEL_ENABLED lc->tunnel=linphone_core_tunnel_new(lc); - linphone_core_update_tunnel(lc); + if (lc->tunnel) linphone_tunnel_update(lc->tunnel); #endif if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Ready")); diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index a3cd8d3e..306569f1 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1083,10 +1083,6 @@ void linphone_core_init_default_params(LinphoneCore*lc, LinphoneCallParams *para */ bool_t linphone_core_tunnel_available(void); -/** - * Update tunnel using configuration. - */ -void linphone_core_update_tunnel(LinphoneCore *lc); typedef struct LinphoneTunnel LinphoneTunnel; /** * get tunnel instance if available diff --git a/gtk/propertybox.c b/gtk/propertybox.c index c45f34e3..dc4086b4 100644 --- a/gtk/propertybox.c +++ b/gtk/propertybox.c @@ -1003,33 +1003,48 @@ void linphone_gtk_edit_tunnel_closed(GtkWidget *button){ gtk_widget_destroy(pb); } -#ifdef TUNNEL_ENABLED + static void tunnel_get_server_host_and_port(LinphoneTunnel *tunnel, char *host, int size, int *port){ char *colon; - char *addresses=(char*)ms_strdup(linphone_tunnel_get_server_addresses(tunnel)); - char *str1=addresses; - char *address=strtok(str1," "); // Not thread safe - if (!address) return; - colon=strchr(address, ':'); - if (!colon) return; - *colon++='\0'; + char *addresses; + char *str1; + char *address; + const char* configured_addresses; + +#ifdef TUNNEL_ENABLED + configured_addresses=linphone_tunnel_get_server_addresses(tunnel); +#else + configured_addresses=NULL; +#endif + if (configured_addresses==NULL){ + host[0]=0; + *port=0; + return; + } + addresses=ms_strdup(configured_addresses); + str1=addresses; + address=strtok(str1," "); // Not thread safe + if (!address) return; + colon=strchr(address, ':'); + if (!colon) return; + *colon++='\0'; *port=atoi(colon); - memcpy(host,address,size); - ms_free(addresses); + strncpy(host,address,size); + ms_free(addresses); } -#endif + void linphone_gtk_edit_tunnel(GtkButton *button){ -#ifdef TUNNEL_ENABLED LinphoneCore *lc=linphone_gtk_get_core(); GtkWidget *w=linphone_gtk_create_window("tunnel_config"); LinphoneTunnel *tunnel=linphone_core_get_tunnel(lc); - char host[50]={'\0'}; + char host[128]={'\0'}; int port=0; tunnel_get_server_host_and_port(tunnel, host, sizeof(host), &port); LinphoneTunnelState state=linphone_tunnel_get_state(tunnel); gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"host")),host); + if (port==0) port=443; gtk_spin_button_set_value(GTK_SPIN_BUTTON(linphone_gtk_get_widget(w,"port")), port); if (state == LinphoneTunnelEnabled){ @@ -1040,16 +1055,14 @@ void linphone_gtk_edit_tunnel(GtkButton *button){ g_object_weak_ref(G_OBJECT(w),(GWeakNotify)linphone_gtk_edit_tunnel_closed,w); - gtk_widget_show(w); -#endif + gtk_widget_show(w); } void linphone_gtk_tunnel_ok(GtkButton *button){ -#ifdef TUNNEL_ENABLED // Save information to config file LinphoneCore *lc=linphone_gtk_get_core(); GtkWidget *w=gtk_widget_get_toplevel(GTK_WIDGET(button)); - char address[50]={'\0'}; + char address[128]={'\0'}; LinphoneTunnel *tunnel=linphone_core_get_tunnel(lc); gint port = (gint)gtk_spin_button_get_value(GTK_SPIN_BUTTON(linphone_gtk_get_widget(w,"port"))); @@ -1057,15 +1070,16 @@ void linphone_gtk_tunnel_ok(GtkButton *button){ const char *host=gtk_entry_get_text(GTK_ENTRY(linphone_gtk_get_widget(w,"host"))); snprintf(address, sizeof address, "%s:%i", host, port); +#ifdef TUNNEL_ENABLED linphone_tunnel_set_server_addresses(tunnel, address); if (enabled){ linphone_tunnel_set_state(tunnel, LinphoneTunnelEnabled); } else{ linphone_tunnel_set_state(tunnel,LinphoneTunnelDisabled); } - linphone_core_update_tunnel(lc); - gtk_widget_destroy(w); + linphone_tunnel_update(tunnel); #endif + gtk_widget_destroy(w); } diff --git a/tunnel b/tunnel index 7ab47085..31379dba 160000 --- a/tunnel +++ b/tunnel @@ -1 +1 @@ -Subproject commit 7ab47085cf698660e9fe17c2c4f3255cd5d5a8a5 +Subproject commit 31379dba112c6d6bafe0522bc72e907458eba1a7 -- 2.39.2