]> sjero.net Git - linphone/blob - coreapi/siplogin.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / coreapi / siplogin.c
1 /*
2 linphone
3 Copyright (C) 2009  Simon MORLAT (simon.morlat@linphone.org)
4
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.
9
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.
14
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.
18 */
19
20 #include "linphonecore.h"
21 #include "private.h"
22 #include <ctype.h>
23
24 static void sip_login_init_instance(SipSetupContext *ctx){
25         LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx);
26         /*disable registration until the user logs in*/
27         linphone_proxy_config_enable_register(cfg,FALSE);
28 }
29
30 static void guess_display_name(LinphoneAddress *from){
31         char *dn=(char*)ms_malloc(strlen(linphone_address_get_username(from))+3);
32         const char *it;
33         char *wptr=dn;
34         bool_t begin=TRUE;
35         bool_t surname=0;
36         for(it=linphone_address_get_username(from);*it!='\0';++it){
37                 if (begin){
38                         *wptr=toupper(*it);
39                         begin=FALSE;
40                 }else if (*it=='.'){
41                         if (surname) break;
42                         *wptr=' ';
43                         begin=TRUE;
44                         surname=TRUE;
45                 }else *wptr=*it;
46                 wptr++;
47         }
48         linphone_address_set_display_name(from,dn);
49         ms_free(dn);
50 }
51
52 static int sip_login_do_login(SipSetupContext * ctx, const char *uri, const char *passwd){
53         LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx);
54         LinphoneCore *lc=linphone_proxy_config_get_core(cfg);
55         LinphoneAuthInfo *auth;
56         LinphoneAddress *parsed_uri;
57         char *tmp;
58
59         parsed_uri=linphone_address_new(uri);
60         if (parsed_uri==NULL){
61                 return -1;
62         }
63         if (linphone_address_get_display_name(parsed_uri)!=NULL){
64                 guess_display_name(parsed_uri);
65         }
66         tmp=linphone_address_as_string(parsed_uri);
67         linphone_proxy_config_set_identity(cfg,tmp);
68         if (passwd ) {
69                 auth=linphone_auth_info_new(linphone_address_get_username(parsed_uri),NULL,passwd,NULL,NULL);
70                 linphone_core_add_auth_info(lc,auth);
71         }
72         linphone_proxy_config_enable_register(cfg,TRUE);
73         linphone_proxy_config_done(cfg);
74         ms_free(tmp);
75         linphone_address_destroy(parsed_uri);
76         ms_message("SipLogin: done");
77         return 0;
78 }
79
80 static int sip_login_do_logout(SipSetupContext * ctx){
81         LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx);
82         linphone_proxy_config_enable_register(cfg,FALSE);
83         linphone_proxy_config_done(cfg);
84         return 0;
85 }
86
87 /* a simple SipSetup built-in plugin to allow specify the user/password for proxy config at runtime*/
88
89 #ifndef _MSC_VER
90
91 SipSetup linphone_sip_login={
92         .name="SipLogin",
93         .capabilities=SIP_SETUP_CAP_LOGIN,
94         .init_instance=sip_login_init_instance,
95         .login_account=sip_login_do_login,
96         .logout_account=sip_login_do_logout
97 };
98
99 #else
100 SipSetup linphone_sip_login={
101         "SipLogin",
102         SIP_SETUP_CAP_LOGIN,
103         0,
104         NULL,
105         NULL,
106         sip_login_init_instance,
107         NULL,
108         NULL,
109         NULL,
110         sip_login_do_login,
111         NULL,
112         NULL,
113         NULL,
114         NULL,
115         NULL,
116         NULL,
117         NULL,
118         NULL,
119         sip_login_do_logout
120 };
121
122
123
124 #endif