From 40071c3388be6c6a7391b5762c25f1690c5daf0f Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 18 Jun 2013 16:18:45 +0200 Subject: [PATCH] re-enable tutorials fix bugs in events add tutorial for subscribe/notify --- configure.ac | 7 +- coreapi/Makefile.am | 2 +- coreapi/event.c | 1 + coreapi/help/Makefile.am | 15 ++-- coreapi/help/notify.c | 181 +++++++++++++++++++++++++++++++++++++++ coreapi/linphonecore.h | 15 ++-- 6 files changed, 202 insertions(+), 19 deletions(-) create mode 100644 coreapi/help/notify.c diff --git a/configure.ac b/configure.ac index 4893e1b33..5c3b8bb92 100644 --- a/configure.ac +++ b/configure.ac @@ -62,7 +62,6 @@ case $target in ;; armv6-apple-darwin|armv7-apple-darwin|i386-apple-darwin|armv7s-apple-darwin) CFLAGS="$CFLAGS -DTARGET_OS_IPHONE " - build_tests=no ios_found=yes ;; x86_64-apple-darwin*|i686-apple-darwin*) @@ -81,8 +80,6 @@ AC_SUBST(GUI_FLAGS) dnl localization tools IT_PROG_INTLTOOL([0.40], [no-xml]) -AM_CONDITIONAL(BUILD_TESTS,test x$build_tests != xno) - dnl Initialize libtool LT_INIT([win32-dll shared disable-static]) @@ -757,7 +754,7 @@ AC_ARG_ENABLE(tests_enabled, no) tests_enabled=false ;; *) AC_MSG_ERROR(bad value ${enableval} for --disable-tests) ;; esac], - [tests_enabled=false] + [tests_enabled=yes] ) AM_CONDITIONAL(ENABLE_TESTS, test x$tests_enabled = xyes) @@ -780,7 +777,7 @@ case "$target_os" in CUNIT_LIBS+=" -lncurses" ;; esac -AM_CONDITIONAL([BUILD_CUNIT_TESTS], [test x$found_cunit = xyes && test x$enable_tests != xno]) +AM_CONDITIONAL([BUILD_CUNIT_TESTS], [test x$found_cunit = xyes && test x$tests_enabled != xfalse]) if test "$found_cunit" = "no" ; then AC_MSG_WARN([Could not find cunit framework, tests are not compiled.]) else diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 12e056a55..c9c1b62b8 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -95,7 +95,7 @@ liblinphone_la_LIBADD= \ $(SQLITE3_LIBS) -if BUILD_TESTS +if ENABLE_TESTS noinst_PROGRAMS=test_lsd test_ecc test_numbers test_lsd_SOURCES=test_lsd.c diff --git a/coreapi/event.c b/coreapi/event.c index 55a92d9f7..264b24472 100644 --- a/coreapi/event.c +++ b/coreapi/event.c @@ -47,6 +47,7 @@ static LinphoneEvent * linphone_event_new_base(LinphoneCore *lc, LinphoneSubscri lev->dir=dir; lev->op=op; lev->refcnt=1; + lev->name=ms_strdup(name); sal_op_set_user_pointer(lev->op,lev); return lev; } diff --git a/coreapi/help/Makefile.am b/coreapi/help/Makefile.am index 902d23c9c..8beceab22 100644 --- a/coreapi/help/Makefile.am +++ b/coreapi/help/Makefile.am @@ -33,8 +33,8 @@ clean-local: if ENABLE_TESTS #tutorials -if BUILD_TESTS -noinst_PROGRAMS=helloworld registration buddy_status chatroom + +noinst_PROGRAMS=helloworld registration buddy_status chatroom notify helloworld_SOURCES=helloworld.c LINPHONE_TUTOS=$(helloworld_SOURCES) @@ -57,17 +57,20 @@ chatroom_SOURCES=chatroom.c LINPHONE_TUTOS+=$(chatroom_SOURCES) chatroom_LDADD=$(helloworld_LDADD) -endif - + +notify_SOURCES=notify.c +LINPHONE_TUTOS+=$(notify_SOURCES) + +notify_LDADD=$(helloworld_LDADD) + endif AM_CFLAGS=\ + -I$(top_srcdir)/coreapi \ $(STRICT_OPTIONS) \ -DIN_LINPHONE \ $(ORTP_CFLAGS) \ - $(OSIP_CFLAGS) \ $(MEDIASTREAMER_CFLAGS) \ - $(EXOSIP_CFLAGS) \ -DENABLE_TRACE \ -DLOG_DOMAIN=\"LinphoneCore\" \ $(IPV6_CFLAGS) \ diff --git a/coreapi/help/notify.c b/coreapi/help/notify.c new file mode 100644 index 000000000..eb8cfbda3 --- /dev/null +++ b/coreapi/help/notify.c @@ -0,0 +1,181 @@ + +/* +linphone +Copyright (C) 2013 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +/** + * @defgroup notify_tutorials Generic subscribe/notify example + * @ingroup tutorials + *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@sip.linphone.org , second must be password . + *
+ *ex registration sip:jehan@sip.linphone.org secret + *
Registration is cleared on SIGINT + *
+ *@include registration.c + + * + */ + +#ifdef IN_LINPHONE +#include "linphonecore.h" +#else +#include "linphone/linphonecore.h" +#endif + +#include + +static bool_t running=TRUE; + +static void stop(int signum){ + running=FALSE; +} + +typedef struct MyAppData{ + LinphoneEvent *ev; +}MyAppData; + +/** + * Registration state notification callback + */ +static void registration_state_changed(LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message){ + printf("New registration state %s for user id [%s] at proxy [%s]\n" + ,linphone_registration_state_to_string(cstate) + ,linphone_proxy_config_get_identity(cfg) + ,linphone_proxy_config_get_addr(cfg)); +} + +static void subscription_state_changed(LinphoneCore *lc, LinphoneEvent *ev, LinphoneSubscriptionState state){ + MyAppData *data=(MyAppData*)linphone_core_get_user_data(lc); + if (state==LinphoneSubscriptionIncomingReceived){ + printf("Receiving new subscription for event %s\n",linphone_event_get_name(ev)); + if (data->ev==NULL) { + linphone_event_accept_subscription(ev); + data->ev=linphone_event_ref(ev); + }else{ + linphone_event_deny_subscription(ev,LinphoneReasonBusy); + } + }else if (state==LinphoneSubscriptionTerminated){ + if (data->ev==ev){ + linphone_event_unref(data->ev); + data->ev=NULL; + } + } +} + +LinphoneCore *lc; +int main(int argc, char *argv[]){ + LinphoneCoreVTable vtable={0}; + MyAppData *data=ms_new0(MyAppData,1); + char* identity=NULL; + char* password=NULL; + int i; + + /* 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; + vtable.subscription_state_changed=subscription_state_changed; + + /* + Instanciate a LinphoneCore object given the LinphoneCoreVTable + */ + lc=linphone_core_new(&vtable,NULL,NULL,data); + + LinphoneProxyConfig* proxy_cfg; + /*create proxy config*/ + proxy_cfg = linphone_proxy_config_new(); + /*parse identity*/ + LinphoneAddress *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; + } + LinphoneAuthInfo *info; + if (password!=NULL){ + info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,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*/ + const char* 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_destroy(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*/ + + i=0; + /* main loop for receiving notifications and doing background linphonecore work: */ + while(running){ + linphone_core_iterate(lc); /* first iterate initiates registration */ + ms_usleep(50000); + ++i; + if (data->ev && i%100==0){ + LinphoneContent content; + content.type="application"; + content.subtype="goodxml"; + content.data="really cool"; + content.size=strlen((const char*)content.data); + linphone_event_notify(data->ev,&content); + } + } + + linphone_core_get_default_proxy(lc,&proxy_cfg); /* 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*/ + + if (data->ev){ + linphone_event_terminate(data->ev); + } + + while(linphone_proxy_config_get_state(proxy_cfg) != LinphoneRegistrationCleared){ + linphone_core_iterate(lc); /*to make sure we receive call backs before shutting down*/ + ms_usleep(50000); + } + +end: + printf("Shutting down...\n"); + linphone_core_destroy(lc); + ms_free(data); + printf("Exited\n"); + return 0; +} + diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 35a683bc6..bb4f4afe5 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -286,9 +286,9 @@ LINPHONE_PUBLIC const char *linphone_call_params_get_custom_header(const Linphon **/ typedef enum _LinphonePrivacy { /** - * Default privacy as defined either globally or by proxy using #linphone_proxy_config_set_privacy + * Privacy services must not perform any privacy function */ - LinphonePrivacyDefault=0x0, + LinphonePrivacyNone=0x0, /** * Request that privacy services provide a user-level privacy * function. @@ -316,16 +316,17 @@ typedef enum _LinphonePrivacy { * */ LinphonePrivacyId=0x8, - /** - * Privacy services must not perform any privacy function - */ - LinphonePrivacyNone=0x10, /** * Privacy service must perform the specified services or * fail the request * **/ - LinphonePrivacyCritical=0x20 + LinphonePrivacyCritical=0x10, + + /** + * Default privacy as defined either globally or by proxy using #linphone_proxy_config_set_privacy + */ + LinphonePrivacyDefault=0x8000, } LinphonePrivacy; /* * a mask of #LinphonePrivacy values