Liblinphone  3.12.0
Generic subscribe/notify example

This program is a very simple usage example of liblinphone. It demonstrates how to listen to a SIP subscription. It then sends notify requests back periodically. first argument must be like sip:jehan.nosp@m.@sip.nosp@m..linp.nosp@m.hone.nosp@m..org , second must be password .
ex registration sip:jehan.nosp@m.@sip.nosp@m..linp.nosp@m.hone.nosp@m..org secret
Registration is cleared on SIGINT

/*
linphone
Copyright (C) 2010 Belledonne Communications SARL
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone/core.h"
#include <signal.h>
static bool_t running=TRUE;
static void stop(int signum){
running=FALSE;
}
static void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message){
printf("New registration state %s for user id [%s] at proxy [%s]\n"
,linphone_proxy_config_get_addr(cfg));
}
int main(int argc, char *argv[]){
LinphoneCoreVTable vtable={0};
LinphoneProxyConfig* proxy_cfg;
char* identity=NULL;
char* password=NULL;
const char* server_addr;
/* takes sip uri identity from the command line arguments */
if (argc>1){
identity=argv[1];
}
/* takes password from the command line arguments */
if (argc>2){
password=argv[2];
}
signal(SIGINT,stop);
#ifdef DEBUG
linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
#endif
/*
Fill the LinphoneCoreVTable with application callbacks.
All are optional. Here we only use the registration_state_changed callbacks
in order to get notifications about the progress of the registration.
*/
vtable.registration_state_changed=registration_state_changed;
/*
Instanciate a LinphoneCore object given the LinphoneCoreVTable
*/
lc=linphone_core_new(&vtable,NULL,NULL,NULL);
/*create proxy config*/
/*parse identity*/
from = linphone_address_new(identity);
if (from==NULL){
printf("%s not a valid sip uri, must be like sip:toto@sip.linphone.org \n",identity);
goto end;
}
if (password!=NULL){
info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL,NULL); /*create authentication structure from identity*/
linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/
}
// configure proxy entries
linphone_proxy_config_set_identity(proxy_cfg,identity); /*set identity with user name and domain*/
server_addr = linphone_address_get_domain(from); /*extract domain address from identity*/
linphone_proxy_config_set_server_addr(proxy_cfg,server_addr); /* we assume domain = proxy server address*/
linphone_proxy_config_enable_register(proxy_cfg,TRUE); /*activate registration for this proxy config*/
linphone_address_unref(from); /*release resource*/
linphone_core_add_proxy_config(lc,proxy_cfg); /*add proxy config to linphone core*/
linphone_core_set_default_proxy(lc,proxy_cfg); /*set to default proxy*/
/* main loop for receiving notifications and doing background linphonecore work: */
while(running){
linphone_core_iterate(lc); /* first iterate initiates registration */
ms_usleep(50000);
}
proxy_cfg = linphone_core_get_default_proxy_config(lc); /* get default proxy config*/
linphone_proxy_config_edit(proxy_cfg); /*start editing proxy configuration*/
linphone_proxy_config_enable_register(proxy_cfg,FALSE); /*de-activate registration for this proxy config*/
linphone_proxy_config_done(proxy_cfg); /*initiate REGISTER with expire = 0*/
linphone_core_iterate(lc); /*to make sure we receive call backs before shutting down*/
ms_usleep(50000);
}
end:
printf("Shutting down...\n");
printf("Exited\n");
return 0;
}
LinphoneRegistrationState
enum _LinphoneRegistrationState LinphoneRegistrationState
LinphoneRegistrationState describes proxy registration states.
linphone_registration_state_to_string
const char * linphone_registration_state_to_string(LinphoneRegistrationState cs)
Human readable version of the LinphoneRegistrationState.
linphone_core_set_default_proxy
#define linphone_core_set_default_proxy(lc, config)
Definition: core.h:1960
LinphoneCore
struct _LinphoneCore LinphoneCore
Linphone core main object created by function linphone_core_new() .
Definition: types.h:472
linphone_proxy_config_set_server_addr
LinphoneStatus linphone_proxy_config_set_server_addr(LinphoneProxyConfig *cfg, const char *server_addr)
Sets the proxy address.
linphone_address_get_username
const char * linphone_address_get_username(const LinphoneAddress *u)
Returns the username.
linphone_proxy_config_edit
void linphone_proxy_config_edit(LinphoneProxyConfig *cfg)
Starts editing a proxy configuration.
linphone_address_unref
void linphone_address_unref(LinphoneAddress *addr)
Decrement reference count of LinphoneAddress object.
linphone_core_enable_logs
LINPHONE_DEPRECATED void linphone_core_enable_logs(FILE *file)
Enable logs in supplied FILE*.
LinphoneProxyConfig
struct _LinphoneProxyConfig LinphoneProxyConfig
The LinphoneProxyConfig object represents a proxy configuration to be used by the LinphoneCore object...
Definition: types.h:940
linphone_proxy_config_get_state
LinphoneRegistrationState linphone_proxy_config_get_state(const LinphoneProxyConfig *cfg)
Get the registration state of the given proxy config.
LinphoneAuthInfo
struct _LinphoneAuthInfo LinphoneAuthInfo
Object holding authentication information.
Definition: types.h:231
linphone_proxy_config_get_identity
const LINPHONE_DEPRECATED char * linphone_proxy_config_get_identity(const LinphoneProxyConfig *cfg)
linphone_proxy_config_enable_register
void linphone_proxy_config_enable_register(LinphoneProxyConfig *cfg, bool_t val)
Indicates either or not, REGISTRATION must be issued for this LinphoneProxyConfig .
linphone_core_add_auth_info
void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
Adds authentication information to the LinphoneCore.
linphone_core_iterate
void linphone_core_iterate(LinphoneCore *lc)
Main loop function.
linphone_address_new
LinphoneAddress * linphone_address_new(const char *addr)
Constructs a LinphoneAddress object by parsing the user supplied address, given as a string.
linphone_core_new
LINPHONE_DEPRECATED LinphoneCore * linphone_core_new(const LinphoneCoreVTable *vtable, const char *config_path, const char *factory_config_path, void *userdata)
Instanciates a LinphoneCore object.
linphone_auth_info_new
LinphoneAuthInfo * linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain)
Creates a LinphoneAuthInfo object with supplied information.
linphone_proxy_config_new
LINPHONE_DEPRECATED LinphoneProxyConfig * linphone_proxy_config_new(void)
Creates an empty proxy config.
linphone_proxy_config_done
LinphoneStatus linphone_proxy_config_done(LinphoneProxyConfig *cfg)
Commits modification made to the proxy configuration.
LinphoneRegistrationCleared
Unregistration succeeded.
Definition: types.h:999
linphone_proxy_config_set_identity
LINPHONE_DEPRECATED LinphoneStatus linphone_proxy_config_set_identity(LinphoneProxyConfig *cfg, const char *identity)
LinphoneAddress
struct SalAddress LinphoneAddress
Object that represents a SIP address.
Definition: types.h:186
linphone_address_get_domain
const char * linphone_address_get_domain(const LinphoneAddress *u)
Returns the domain name.
_LinphoneCoreVTable
This structure holds all callbacks that the application should implement.
Definition: core.h:180
linphone_core_add_proxy_config
LinphoneStatus linphone_core_add_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *config)
Add a proxy configuration.
_LinphoneCoreVTable::registration_state_changed
LinphoneCoreRegistrationStateChangedCb registration_state_changed
Notifies registration state changes.
Definition: core.h:182
linphone_core_get_default_proxy_config
LinphoneProxyConfig * linphone_core_get_default_proxy_config(LinphoneCore *lc)
linphone_core_destroy
LINPHONE_DEPRECATED void linphone_core_destroy(LinphoneCore *lc)
Destroys a LinphoneCore.