4 Copyright (C) 2010 Belledonne Communications SARL
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * @defgroup registration_tutorials Basic registration
24 *This program is a _very_ simple usage example of liblinphone.
25 *Desmonstrating how to initiate a SIP registration from a sip uri identity passed from the command line.
26 *first argument must be like sip:jehan@sip.linphone.org , second must be password .
28 *ex registration sip:jehan@sip.linphone.org secret
29 *<br>Registration is cleared on SIGINT
31 *@include registration.c
37 #include "linphonecore.h"
39 #include "linphone/linphonecore.h"
44 static bool_t running=TRUE;
46 static void stop(int signum){
51 * Registration state notification callback
53 static void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message){
54 printf("New registration state %s for user id [%s] at proxy [%s]\n"
55 ,linphone_registration_state_to_string(cstate)
56 ,linphone_proxy_config_get_identity(cfg)
57 ,linphone_proxy_config_get_addr(cfg));
61 int main(int argc, char *argv[]){
62 LinphoneCoreVTable vtable={0};
67 /* takes sip uri identity from the command line arguments */
72 /* takes password from the command line arguments */
80 linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
83 Fill the LinphoneCoreVTable with application callbacks.
84 All are optional. Here we only use the registration_state_changed callbacks
85 in order to get notifications about the progress of the registration.
87 vtable.registration_state_changed=registration_state_changed;
90 Instanciate a LinphoneCore object given the LinphoneCoreVTable
92 lc=linphone_core_new(&vtable,NULL,NULL,NULL);
94 LinphoneProxyConfig* proxy_cfg;
95 /*create proxy config*/
96 proxy_cfg = linphone_proxy_config_new();
98 LinphoneAddress *from = linphone_address_new(identity);
100 printf("%s not a valid sip uri, must be like sip:toto@sip.linphone.org \n",identity);
103 LinphoneAuthInfo *info;
105 info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL); /*create authentication structure from identity*/
106 linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/
109 // configure proxy entries
110 linphone_proxy_config_set_identity(proxy_cfg,identity); /*set identity with user name and domain*/
111 const char* server_addr = linphone_address_get_domain(from); /*extract domain address from identity*/
112 linphone_proxy_config_set_server_addr(proxy_cfg,server_addr); /* we assume domain = proxy server address*/
113 linphone_proxy_config_enable_register(proxy_cfg,TRUE); /*activate registration for this proxy config*/
114 linphone_address_destroy(from); /*release resource*/
116 linphone_core_add_proxy_config(lc,proxy_cfg); /*add proxy config to linphone core*/
117 linphone_core_set_default_proxy(lc,proxy_cfg); /*set to default proxy*/
120 /* main loop for receiving notifications and doing background linphonecore work: */
122 linphone_core_iterate(lc); /* first iterate initiates registration */
126 linphone_core_get_default_proxy(lc,&proxy_cfg); /* get default proxy config*/
127 linphone_proxy_config_edit(proxy_cfg); /*start editing proxy configuration*/
128 linphone_proxy_config_enable_register(proxy_cfg,FALSE); /*de-activate registration for this proxy config*/
129 linphone_proxy_config_done(proxy_cfg); /*initiate REGISTER with expire = 0*/
131 while(linphone_proxy_config_get_state(proxy_cfg) != LinphoneRegistrationCleared){
132 linphone_core_iterate(lc); /*to make sure we receive call backs before shutting down*/
137 printf("Shutting down...\n");
138 linphone_core_destroy(lc);