From f3a7dfcee542e1059d6893823a34cf08ddc48a53 Mon Sep 17 00:00:00 2001 From: smorlat Date: Mon, 7 Sep 2009 13:58:54 +0000 Subject: [PATCH] work in progress: add an optional screen login. git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@638 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- linphone/coreapi/Makefile.am | 3 +- linphone/coreapi/authentication.c | 2 +- linphone/coreapi/linphonecore.c | 1 + linphone/coreapi/linphonecore.h | 1 + linphone/coreapi/proxy.c | 8 ++ linphone/coreapi/siplogin.c | 50 ++++++++++ linphone/coreapi/sipsetup.c | 6 +- linphone/coreapi/sipsetup.h | 3 +- linphone/gtk-glade/Makefile.am | 4 +- linphone/gtk-glade/linphone.h | 3 +- linphone/gtk-glade/loginframe.c | 68 ++++++++++++++ linphone/gtk-glade/main.c | 12 +++ linphone/gtk-glade/main.glade | 150 +++++++++++++++++++++++++++++- linphone/gtk-glade/propertybox.c | 2 +- 14 files changed, 304 insertions(+), 9 deletions(-) create mode 100644 linphone/coreapi/siplogin.c create mode 100644 linphone/gtk-glade/loginframe.c diff --git a/linphone/coreapi/Makefile.am b/linphone/coreapi/Makefile.am index 1d851b436..7919e2f7d 100644 --- a/linphone/coreapi/Makefile.am +++ b/linphone/coreapi/Makefile.am @@ -25,7 +25,8 @@ liblinphone_la_SOURCES=\ lpconfig.c lpconfig.h \ chat.c \ general_state.c \ - sipsetup.c sipsetup.h + sipsetup.c sipsetup.h \ + siplogin.c liblinphone_la_LDFLAGS= -version-info $(LIBLINPHONE_SO_VERSION) -no-undefined diff --git a/linphone/coreapi/authentication.c b/linphone/coreapi/authentication.c index c19aea1e6..4e7eba4fc 100644 --- a/linphone/coreapi/authentication.c +++ b/linphone/coreapi/authentication.c @@ -2,7 +2,7 @@ * authentication.c * * Fri Jul 16 12:08:34 2004 - * Copyright 2004 Simon MORLAT + * Copyright 2004-2009 Simon MORLAT * simon.morlat@linphone.org ****************************************************************************/ diff --git a/linphone/coreapi/linphonecore.c b/linphone/coreapi/linphonecore.c index 782d9afed..382566a21 100644 --- a/linphone/coreapi/linphonecore.c +++ b/linphone/coreapi/linphonecore.c @@ -776,6 +776,7 @@ void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE); return; } + if (dest==NULL) dest="87.98.157.38"; /*a public IP address*/ if (linphone_core_get_local_ip_for(dest,result)==0) return; /*else fallback to exosip routine that will attempt to find the most realistic interface */ diff --git a/linphone/coreapi/linphonecore.h b/linphone/coreapi/linphonecore.h index bf0be2383..e59fc8ef2 100644 --- a/linphone/coreapi/linphonecore.h +++ b/linphone/coreapi/linphonecore.h @@ -332,6 +332,7 @@ LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(struct _LpConfig void linphone_proxy_config_write_to_config_file(struct _LpConfig* config,LinphoneProxyConfig *obj, int index); void linphone_proxy_config_set_sip_setup(LinphoneProxyConfig *cfg, const char *type); SipSetupContext *linphone_proxy_config_get_sip_setup_context(LinphoneProxyConfig *cfg); +SipSetup *linphone_proxy_config_get_sip_setup(LinphoneProxyConfig *cfg); typedef struct _LinphoneAccountCreator{ struct _LinphoneCore *lc; diff --git a/linphone/coreapi/proxy.c b/linphone/coreapi/proxy.c index eea60409e..1fc307d09 100644 --- a/linphone/coreapi/proxy.c +++ b/linphone/coreapi/proxy.c @@ -648,6 +648,14 @@ static void linphone_proxy_config_activate_sip_setup(LinphoneProxyConfig *cfg){ } +SipSetup *linphone_proxy_config_get_sip_setup(LinphoneProxyConfig *cfg){ + if (cfg->ssctx!=NULL) return cfg->ssctx->funcs; + if (cfg->type!=NULL){ + return sip_setup_lookup(cfg->type); + } + return NULL; +} + void linphone_proxy_config_update(LinphoneProxyConfig *cfg){ if (cfg->commit){ if (cfg->type && cfg->ssctx==NULL){ diff --git a/linphone/coreapi/siplogin.c b/linphone/coreapi/siplogin.c new file mode 100644 index 000000000..1e55bc444 --- /dev/null +++ b/linphone/coreapi/siplogin.c @@ -0,0 +1,50 @@ +/* +linphone +Copyright (C) 2009 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 +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif + +#include "linphonecore.h" + + +static void sip_login_init_instance(SipSetupContext *ctx){ + LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); + /*disable registration until the user logs in*/ + linphone_proxy_config_enable_register(cfg,FALSE); +} + +static int sip_login_do_login(SipSetupContext * ctx, const char *uri, const char *passwd){ + LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); + LinphoneCore *lc=linphone_proxy_config_get_core(cfg); + LinphoneAuthInfo *auth=linphone_auth_info_new(ctx->username,NULL,passwd,NULL,NULL); + linphone_proxy_config_set_identity(cfg,uri); + linphone_core_add_auth_info(lc,auth); + linphone_proxy_config_enable_register(cfg,TRUE); + return 0; +} + +/* a simple SipSetup built-in plugin to allow specify the user/password for proxy config at runtime*/ +SipSetup linphone_sip_login={ + .name="SipLogin", + .capabilities=SIP_SETUP_CAP_LOGIN, + .init_instance=sip_login_init_instance, + .login_account=sip_login_do_login, +}; + diff --git a/linphone/coreapi/sipsetup.c b/linphone/coreapi/sipsetup.c index 5dd63fe90..5e056e669 100644 --- a/linphone/coreapi/sipsetup.c +++ b/linphone/coreapi/sipsetup.c @@ -1,6 +1,6 @@ /* linphone -Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org) +Copyright (C) 2009 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 @@ -23,7 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "linphonecore.h" +extern SipSetup linphone_sip_login; + static SipSetup *all_sip_setups[]={ + &linphone_sip_login, NULL }; @@ -38,6 +41,7 @@ void sip_setup_register_all(void){ ms_load_plugins(LINPHONE_PLUGINS_DIR); while(*p!=NULL){ sip_setup_register(*p); + p++; } } diff --git a/linphone/coreapi/sipsetup.h b/linphone/coreapi/sipsetup.h index 9e0a642c8..2145d2d1a 100644 --- a/linphone/coreapi/sipsetup.h +++ b/linphone/coreapi/sipsetup.h @@ -42,7 +42,8 @@ typedef struct _SipSetupContext SipSetupContext; #define SIP_SETUP_CAP_STUN_PROVIDER (1<<1) #define SIP_SETUP_CAP_RELAY_PROVIDER (1<<2) #define SIP_SETUP_CAP_BUDDY_LOOKUP (1<<3) -#define SIP_SETUP_CAP_ACCOUNT_MANAGER (1<<4) +#define SIP_SETUP_CAP_ACCOUNT_MANAGER (1<<4) /*can create accounts*/ +#define SIP_SETUP_CAP_LOGIN (1<<5) /*can login to any account for a given proxy */ typedef enum _BuddyLookupStatus{ BuddyLookupNone, diff --git a/linphone/gtk-glade/Makefile.am b/linphone/gtk-glade/Makefile.am index 58b6438d0..2f23e201b 100644 --- a/linphone/gtk-glade/Makefile.am +++ b/linphone/gtk-glade/Makefile.am @@ -17,8 +17,7 @@ PIXMAPS= linphone2.png \ EXTRA_DIST= $(PIXMAPS) \ $(GLADE_FILES) \ - linphone.iss \ - linphone.dev + linphone.iss if BUILD_GLADE_UI @@ -39,6 +38,7 @@ linphone_3_SOURCES= \ utils.c \ setupwizard.c\ incall_view.c \ + loginframe.c \ linphone.h linphone_3_LDADD=$(top_builddir)/oRTP/src/libortp.la \ diff --git a/linphone/gtk-glade/linphone.h b/linphone/gtk-glade/linphone.h index ea20d5b68..daeaaf97d 100644 --- a/linphone/gtk-glade/linphone.h +++ b/linphone/gtk-glade/linphone.h @@ -76,10 +76,11 @@ gchar *linphone_gtk_get_display_name(const char *sip_uri); void linphone_gtk_show_directory_search(void); -/*functions controlling the in-call view*/ +/*functions controlling the different views*/ void linphone_gtk_show_in_call_view(void); void linphone_gtk_show_idle_view(void); void linphone_gtk_in_call_view_set_calling(const char *uri); void linphone_gtk_in_call_view_set_in_call(const char *uri); void linphone_gtk_in_call_view_update_duration(int duration); void linphone_gtk_in_call_view_terminate(const char *error_msg); +void linphone_gtk_show_login_frame(LinphoneProxyConfig *cfg); diff --git a/linphone/gtk-glade/loginframe.c b/linphone/gtk-glade/loginframe.c new file mode 100644 index 000000000..c50f75f77 --- /dev/null +++ b/linphone/gtk-glade/loginframe.c @@ -0,0 +1,68 @@ +/* +linphone, gtk-glade interface. +Copyright (C) 2009 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 +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "linphone.h" + +void linphone_gtk_show_login_frame(LinphoneProxyConfig *cfg){ + GtkWidget *mw=linphone_gtk_get_main_window(); + GtkWidget *label=linphone_gtk_get_widget(mw,"login_label"); + gchar *str; + gtk_widget_hide(linphone_gtk_get_widget(mw,"idle_view")); + gtk_widget_show(linphone_gtk_get_widget(mw,"login_frame")); + gtk_widget_set_sensitive(linphone_gtk_get_widget(mw,"main_menu"),FALSE); + gtk_widget_set_sensitive(linphone_gtk_get_widget(mw,"modes"),FALSE); + str=g_strdup_printf(_("Please enter login information for %s"),linphone_proxy_config_get_domain(cfg)); + gtk_label_set_text(GTK_LABEL(label),str); + g_free(str); + +} + +void linphone_gtk_exit_login_frame(void){ + GtkWidget *mw=linphone_gtk_get_main_window(); + gtk_widget_show(linphone_gtk_get_widget(mw,"idle_view")); + gtk_widget_hide(linphone_gtk_get_widget(mw,"login_frame")); + gtk_widget_set_sensitive(linphone_gtk_get_widget(mw,"main_menu"),TRUE); + gtk_widget_set_sensitive(linphone_gtk_get_widget(mw,"modes"),TRUE); +} + +enum { + NetworkKindAdsl, + NetworkKindOpticalFiber +}; + +void linphone_gtk_login_frame_connect_clicked(GtkWidget *button){ + GtkWidget *mw=gtk_widget_get_toplevel(button); + const char *username; + const char *password; + int netkind_id; + LinphoneCore *lc=linphone_gtk_get_core(); + + username=gtk_entry_get_text(GTK_ENTRY(linphone_gtk_get_widget(mw,"login_username"))); + password=gtk_entry_get_text(GTK_ENTRY(linphone_gtk_get_widget(mw,"login_password"))); + netkind_id=gtk_combo_box_get_active(GTK_COMBO_BOX(linphone_gtk_get_widget(mw,"login_internet_kind"))); + + if (netkind_id==NetworkKindAdsl){ + linphone_core_set_upload_bandwidth(lc,256); + linphone_core_set_download_bandwidth(lc,512); + }else if (netkind_id==NetworkKindOpticalFiber){ + /*infinite*/ + linphone_core_set_upload_bandwidth(lc,0); + linphone_core_set_download_bandwidth(lc,0); + } +} diff --git a/linphone/gtk-glade/main.c b/linphone/gtk-glade/main.c index 3ebb05810..90439a476 100644 --- a/linphone/gtk-glade/main.c +++ b/linphone/gtk-glade/main.c @@ -963,6 +963,18 @@ static void linphone_gtk_configure_main_window(){ gtk_widget_hide(linphone_gtk_get_widget(w,"run_assistant")); } +void linphone_gtk_manage_login(void){ + LinphoneCore *lc=linphone_gtk_get_core(); + LinphoneProxyConfig *cfg=NULL; + linphone_core_get_default_proxy(lc,&cfg); + if (cfg){ + SipSetup *ss=linphone_proxy_config_get_sip_setup(cfg); + if (ss && (sip_setup_get_capabilities(ss) & SIP_SETUP_CAP_LOGIN)){ + linphone_gtk_show_login_frame(cfg); + } + } +} + static void linphone_gtk_init_main_window(){ linphone_gtk_configure_main_window(); load_uri_history(); diff --git a/linphone/gtk-glade/main.glade b/linphone/gtk-glade/main.glade index a9ffec5e4..ffcdab03f 100644 --- a/linphone/gtk-glade/main.glade +++ b/linphone/gtk-glade/main.glade @@ -88,7 +88,7 @@ _Modes True - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -1118,6 +1118,154 @@ Online users 1 + + + 0 + + + True + 12 + + + True + vertical + + + True + 0 + + + True + 12 + + + True + 3 + 2 + + + True + Username + + + + + True + Password + + + 1 + 2 + + + + + True + Internet connection: + + + 2 + 3 + + + + + True + True + + + + 1 + 2 + + + + + True + True + False + + + + 1 + 2 + 1 + 2 + + + + + True + ADSL +Fiber Channel + + + 1 + 2 + 2 + 3 + + + + + + + + + True + Login information + True + + + label_item + + + + + 0 + + + + + True + + + gtk-connect + True + True + True + True + + + False + False + 0 + + + + + 1 + + + + + + + + + True + <b>Welcome !</b> + True + + + label_item + + + + + 2 + + 1 diff --git a/linphone/gtk-glade/propertybox.c b/linphone/gtk-glade/propertybox.c index 05a187ecf..dd87a5da4 100644 --- a/linphone/gtk-glade/propertybox.c +++ b/linphone/gtk-glade/propertybox.c @@ -1,6 +1,6 @@ /* linphone, gtk-glade interface. -Copyright (C) 2008 Simon MORLAT (simon.morlat@linphone.org) +Copyright (C) 2008-2009 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