3 Copyright (C) 2009 Simon MORLAT (simon.morlat@linphone.org)
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "../config.h"
24 #include "linphonecore.h"
27 static void sip_login_init_instance(SipSetupContext *ctx){
28 LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx);
29 /*disable registration until the user logs in*/
30 linphone_proxy_config_enable_register(cfg,FALSE);
33 static void guess_display_name(LinphoneAddress *from){
34 char *dn=(char*)ms_malloc(strlen(linphone_address_get_username(from))+3);
39 for(it=linphone_address_get_username(from);*it!='\0';++it){
51 linphone_address_set_display_name(from,dn);
55 static int sip_login_do_login(SipSetupContext * ctx, const char *uri, const char *passwd){
56 LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx);
57 LinphoneCore *lc=linphone_proxy_config_get_core(cfg);
58 LinphoneAuthInfo *auth;
59 LinphoneAddress *parsed_uri;
62 parsed_uri=linphone_address_new(uri);
63 if (parsed_uri==NULL){
66 if (linphone_address_get_display_name(parsed_uri)!=NULL){
67 guess_display_name(parsed_uri);
69 tmp=linphone_address_as_string(parsed_uri);
70 linphone_proxy_config_set_identity(cfg,tmp);
72 auth=linphone_auth_info_new(linphone_address_get_username(parsed_uri),NULL,passwd,NULL,NULL);
73 linphone_core_add_auth_info(lc,auth);
75 linphone_proxy_config_enable_register(cfg,TRUE);
76 linphone_proxy_config_done(cfg);
78 linphone_address_destroy(parsed_uri);
79 ms_message("SipLogin: done");
83 static int sip_login_do_logout(SipSetupContext * ctx){
84 LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx);
85 linphone_proxy_config_enable_register(cfg,FALSE);
86 linphone_proxy_config_done(cfg);
90 /* a simple SipSetup built-in plugin to allow specify the user/password for proxy config at runtime*/
94 SipSetup linphone_sip_login={
96 .capabilities=SIP_SETUP_CAP_LOGIN,
97 .init_instance=sip_login_init_instance,
98 .login_account=sip_login_do_login,
99 .logout_account=sip_login_do_logout
103 SipSetup linphone_sip_login={
109 sip_login_init_instance,