void linphone_subscription_state_change(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state) { stats* counters = get_stats(lc); LinphoneCoreManager *mgr=get_manager(lc); LinphoneContent* content; const LinphoneAddress* from_addr = linphone_event_get_from(lev); char* from = linphone_address_as_string(from_addr); content = linphone_core_create_content(lc); linphone_content_set_type(content,"application"); linphone_content_set_subtype(content,"somexml2"); linphone_content_set_buffer(content,notify_content,strlen(notify_content)); ms_message("Subscription state [%s] from [%s]",linphone_subscription_state_to_string(state),from); ms_free(from); switch(state){ case LinphoneSubscriptionNone: break; case LinphoneSubscriptionIncomingReceived: counters->number_of_LinphoneSubscriptionIncomingReceived++; mgr->lev=lev; if (!mgr->decline_subscribe) linphone_event_accept_subscription(lev); else linphone_event_deny_subscription(lev, LinphoneReasonDeclined); break; case LinphoneSubscriptionOutgoingInit: counters->number_of_LinphoneSubscriptionOutgoingInit++; break; case LinphoneSubscriptionPending: counters->number_of_LinphoneSubscriptionPending++; break; case LinphoneSubscriptionActive: counters->number_of_LinphoneSubscriptionActive++; if (linphone_event_get_subscription_dir(lev)==LinphoneSubscriptionIncoming){ mgr->lev=lev; linphone_event_notify(lev,content); } break; case LinphoneSubscriptionTerminated: counters->number_of_LinphoneSubscriptionTerminated++; mgr->lev=NULL; break; case LinphoneSubscriptionError: counters->number_of_LinphoneSubscriptionError++; mgr->lev=NULL; break; case LinphoneSubscriptionExpiring: counters->number_of_LinphoneSubscriptionExpiring++; mgr->lev=NULL; break; } linphone_content_unref(content); }
void linphone_subscription_state_change(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state) { stats* counters = get_stats(lc); LinphoneCoreManager *mgr=get_manager(lc); LinphoneContent content; content.type="application"; content.subtype="somexml2"; content.data=(void*)notify_content; content.size=strlen(notify_content); switch(state){ case LinphoneSubscriptionNone: break; case LinphoneSubscriptionIncomingReceived: counters->number_of_LinphoneSubscriptionIncomingReceived++; if (!mgr->decline_subscribe) linphone_event_accept_subscription(lev); else linphone_event_deny_subscription(lev, LinphoneReasonDeclined); break; case LinphoneSubscriptionOutoingInit: counters->number_of_LinphoneSubscriptionOutgoingInit++; break; case LinphoneSubscriptionPending: counters->number_of_LinphoneSubscriptionPending++; break; case LinphoneSubscriptionActive: counters->number_of_LinphoneSubscriptionActive++; if (linphone_event_get_subscription_dir(lev)==LinphoneSubscriptionIncoming){ mgr->lev=lev; linphone_event_notify(lev,&content); } break; case LinphoneSubscriptionTerminated: counters->number_of_LinphoneSubscriptionTerminated++; mgr->lev=NULL; break; case LinphoneSubscriptionError: counters->number_of_LinphoneSubscriptionError++; mgr->lev=NULL; break; } }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; MyAppData *data=ms_new0(MyAppData,1); char* identity=NULL; char* password=NULL; int i; LinphoneProxyConfig* proxy_cfg; LinphoneAddress *from; LinphoneAuthInfo *info; 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; vtable.subscription_state_changed=subscription_state_changed; /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,data); /*create proxy config*/ proxy_cfg = linphone_proxy_config_new(); /*parse identity*/ from = linphone_address_new(identity); if (from==NULL){ printf("%s not a valid sip uri, must be like sip:[email protected] \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_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){ LinphoneContentPrivate content; content.type="application"; content.subtype="goodxml"; content.data="really cool"; content.size=strlen((const char*)content.data); linphone_event_notify(data->ev,LINPHONE_CONTENT(&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; }