static LinphoneAccountCreatorStatus validate_uri(const char* username, const char* domain, const char* route, const char* display_name) { LinphoneAddress* addr; LinphoneAccountCreatorStatus status = LinphoneAccountCreatorOK; LinphoneProxyConfig* proxy = linphone_proxy_config_new(); linphone_proxy_config_set_identity(proxy, "sip:[email protected]"); if (route && linphone_proxy_config_set_route(proxy, route) != 0) { status = LinphoneAccountCreatorRouteInvalid; goto end; } if (username) { addr = linphone_proxy_config_normalize_sip_uri(proxy, username); } else { addr = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy)); } if (addr == NULL) { status = LinphoneAccountCreatorUsernameInvalid; goto end; } if (domain && linphone_address_set_domain(addr, domain) != 0) { status = LinphoneAccountCreatorDomainInvalid; } if (display_name && (!strlen(display_name) || linphone_address_set_display_name(addr, display_name) != 0)) { status = LinphoneAccountCreatorDisplayNameInvalid; } linphone_address_unref(addr); end: linphone_proxy_config_destroy(proxy); return status; }
static int sip_login_do_login(SipSetupContext * ctx, const char *uri, const char *passwd){ LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); LinphoneCore *lc=linphone_proxy_config_get_core(cfg); LinphoneAuthInfo *auth; osip_from_t *parsed_uri; char *tmp; osip_from_init(&parsed_uri); osip_from_parse(parsed_uri,uri); if (parsed_uri->displayname==NULL || strlen(parsed_uri->displayname)==0){ guess_display_name(parsed_uri); } osip_from_to_str(parsed_uri,&tmp); linphone_proxy_config_set_identity(cfg,tmp); if (passwd ) { auth=linphone_auth_info_new(parsed_uri->url->username,NULL,passwd,NULL,NULL); linphone_core_add_auth_info(lc,auth); } linphone_proxy_config_enable_register(cfg,TRUE); linphone_proxy_config_done(cfg); osip_free(tmp); osip_from_free(parsed_uri); ms_message("SipLogin: done"); return 0; }
static int sip_login_do_login(SipSetupContext * ctx, const char *uri, const char *passwd){ LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); LinphoneCore *lc=linphone_proxy_config_get_core(cfg); LinphoneAuthInfo *auth; LinphoneAddress *parsed_uri; char *tmp; parsed_uri=linphone_address_new(uri); if (parsed_uri==NULL){ return -1; } if (linphone_address_get_display_name(parsed_uri)!=NULL){ guess_display_name(parsed_uri); } tmp=linphone_address_as_string(parsed_uri); linphone_proxy_config_set_identity(cfg,tmp); if (passwd ) { auth=linphone_auth_info_new(linphone_address_get_username(parsed_uri),NULL,passwd,NULL,NULL); linphone_core_add_auth_info(lc,auth); } linphone_proxy_config_enable_register(cfg,TRUE); linphone_proxy_config_done(cfg); ms_free(tmp); linphone_address_destroy(parsed_uri); ms_message("SipLogin: done"); return 0; }
static LinphoneAccountCreatorStatus validate_uri(const char* username, const char* domain, const char* route, const char* display_name) { LinphoneProxyConfig* proxy = linphone_proxy_config_new(); LinphoneAddress* addr; linphone_proxy_config_set_identity(proxy, "sip:[email protected]"); if (route && linphone_proxy_config_set_route(proxy, route) != 0) { linphone_proxy_config_destroy(proxy); return LinphoneAccountCreatorRouteInvalid; } if (username) { addr = linphone_proxy_config_normalize_sip_uri(proxy, username); } else { addr = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy)); } linphone_proxy_config_destroy(proxy); if (addr == NULL) { return LinphoneAccountCreatorUsernameInvalid; } if (domain) { ms_error("TODO: detect invalid domain"); linphone_address_set_domain(addr, domain); } if (display_name) { ms_error("TODO: detect invalid display name"); linphone_address_set_display_name(addr, display_name); } linphone_address_unref(addr); return LinphoneAccountCreatorOk; }
LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyConfig *cfg){ LinphoneCore *lc=linphone_proxy_config_get_core(cfg); const char *identity=linphone_proxy_config_get_identity(cfg); LinphoneAddress *id_addr=linphone_address_new(identity); Account *account=account_manager_get_account(m,id_addr); LinphoneAuthInfo *ai; char *tmp; bool_t create_account=FALSE; if (!account){ account=account_new(id_addr,m->unique_id); ms_message("No account for %s exists, going to create one.",identity); create_account=TRUE; m->accounts=ms_list_append(m->accounts,account); } /*modify the username of the identity of the proxy config*/ linphone_address_set_username(id_addr, linphone_address_get_username(account->modified_identity)); tmp=linphone_address_as_string(id_addr); linphone_proxy_config_set_identity(cfg,tmp); ms_free(tmp); if (create_account){ account_create_on_server(account,cfg); } ai=linphone_auth_info_new(linphone_address_get_username(account->modified_identity), NULL, account->password,NULL,NULL,linphone_address_get_domain(account->modified_identity)); linphone_core_add_auth_info(lc,ai); linphone_auth_info_destroy(ai); linphone_address_unref(id_addr); return account->modified_identity; }
static void register_with_refresh_base_3(LinphoneCore* lc , bool_t refresh ,const char* domain ,const char* route ,bool_t late_auth_info ,LCSipTransports transport ,LinphoneRegistrationState expected_final_state) { int retry=0; char* addr; LinphoneProxyConfig* proxy_cfg; stats* counters; LinphoneAddress *from; const char* server_addr; LinphoneAuthInfo *info; BC_ASSERT_PTR_NOT_NULL(lc); if (!lc) return; counters = get_stats(lc); reset_counters(counters); linphone_core_set_sip_transports(lc,&transport); proxy_cfg = linphone_proxy_config_new(); from = create_linphone_address(domain); linphone_proxy_config_set_identity(proxy_cfg,addr=linphone_address_as_string(from)); ms_free(addr); server_addr = linphone_address_get_domain(from); linphone_proxy_config_enable_register(proxy_cfg,TRUE); linphone_proxy_config_set_expires(proxy_cfg,1); if (route) { linphone_proxy_config_set_route(proxy_cfg,route); linphone_proxy_config_set_server_addr(proxy_cfg,route); } else { linphone_proxy_config_set_server_addr(proxy_cfg,server_addr); } linphone_address_destroy(from); linphone_core_add_proxy_config(lc,proxy_cfg); linphone_core_set_default_proxy(lc,proxy_cfg); while (counters->number_of_LinphoneRegistrationOk<1+(refresh!=0) && retry++ <(1100 /*only wait 11 s if final state is progress*/+(expected_final_state==LinphoneRegistrationProgress?0:2000))) { linphone_core_iterate(lc); if (counters->number_of_auth_info_requested>0 && linphone_proxy_config_get_state(proxy_cfg) == LinphoneRegistrationFailed && late_auth_info) { if (!linphone_core_get_auth_info_list(lc)) { BC_ASSERT_EQUAL(linphone_proxy_config_get_error(proxy_cfg),LinphoneReasonUnauthorized, int, "%d"); info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain,NULL); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } } if (linphone_proxy_config_get_error(proxy_cfg) == LinphoneReasonBadCredentials || (counters->number_of_auth_info_requested>2 &&linphone_proxy_config_get_error(proxy_cfg) == LinphoneReasonUnauthorized)) /*no need to continue if auth cannot be found*/ break; /*no need to continue*/ ms_usleep(10000); }
void linphone_proxy_config_is_server_config_changed_test() { LinphoneProxyConfig* proxy_config = linphone_proxy_config_new(); linphone_proxy_config_done(proxy_config); /*test done without edit*/ linphone_proxy_config_set_identity(proxy_config,"sip:toto@titi"); linphone_proxy_config_edit(proxy_config); linphone_proxy_config_set_identity(proxy_config,"sips:toto@titi"); BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d"); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org"); linphone_proxy_config_edit(proxy_config); linphone_proxy_config_set_server_addr(proxy_config,"sip:toto.com"); BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d"); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org"); linphone_proxy_config_edit(proxy_config); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org:4444"); BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d"); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org"); linphone_proxy_config_edit(proxy_config); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org;transport=tcp"); BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d"); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org"); linphone_proxy_config_edit(proxy_config); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org;param=blue"); BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressWeakEqual, int, "%d"); linphone_proxy_config_edit(proxy_config); linphone_proxy_config_set_contact_parameters(proxy_config,"blabla=blue"); BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressEqual, int, "%d"); linphone_proxy_config_edit(proxy_config); linphone_proxy_config_enable_register(proxy_config,TRUE); BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressEqual, int, "%d"); linphone_proxy_config_destroy(proxy_config); }
static void linphone_interpret_url_test(void) { LinphoneCoreVTable v_table; LinphoneCore* lc; const char* sips_address = "sips:[email protected]"; LinphoneAddress* address; LinphoneProxyConfig *proxy_config; char *tmp; memset ( &v_table,0,sizeof ( v_table ) ); lc = linphone_core_new ( &v_table,NULL,NULL,NULL ); BC_ASSERT_PTR_NOT_NULL_FATAL ( lc ); proxy_config =linphone_core_create_proxy_config(lc); linphone_proxy_config_set_identity(proxy_config, "sip:[email protected]"); linphone_proxy_config_enable_register(proxy_config, FALSE); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org"); linphone_core_add_proxy_config(lc, proxy_config); linphone_core_set_default_proxy_config(lc,proxy_config); linphone_proxy_config_unref(proxy_config); address = linphone_core_interpret_url(lc, sips_address); BC_ASSERT_PTR_NOT_NULL_FATAL(address); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_scheme(address), "sips"); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_username(address), "margaux"); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_domain(address), "sip.linphone.org"); linphone_address_destroy(address); address = linphone_core_interpret_url(lc,"23"); BC_ASSERT_PTR_NOT_NULL(address); BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip"); BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "23"); BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org"); linphone_address_destroy(address); address = linphone_core_interpret_url(lc,"#24"); BC_ASSERT_PTR_NOT_NULL(address); BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip"); BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "#24"); BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org"); tmp = linphone_address_as_string(address); BC_ASSERT_TRUE(strcmp (tmp,"sip:%[email protected]") == 0); linphone_address_destroy(address); address = linphone_core_interpret_url(lc,tmp); BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip"); BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "#24"); BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org"); linphone_address_destroy(address); ms_free(tmp); linphone_core_destroy (lc); }
static void register_with_refresh_base_2(LinphoneCore* lc, bool_t refresh,const char* domain,const char* route,bool_t late_auth_info,LCSipTransports transport) { int retry=0; char* addr; LinphoneProxyConfig* proxy_cfg; stats* counters; LinphoneAddress *from; const char* server_addr; LinphoneAuthInfo *info; CU_ASSERT_PTR_NOT_NULL(lc); if (!lc) return; counters = get_stats(lc); reset_counters(counters); linphone_core_set_sip_transports(lc,&transport); proxy_cfg = linphone_proxy_config_new(); from = create_linphone_address(domain); linphone_proxy_config_set_identity(proxy_cfg,addr=linphone_address_as_string(from)); ms_free(addr); server_addr = linphone_address_get_domain(from); linphone_proxy_config_enable_register(proxy_cfg,TRUE); linphone_proxy_config_expires(proxy_cfg,1); if (route) { linphone_proxy_config_set_route(proxy_cfg,route); linphone_proxy_config_set_server_addr(proxy_cfg,route); } else { linphone_proxy_config_set_server_addr(proxy_cfg,server_addr); } linphone_address_destroy(from); linphone_core_add_proxy_config(lc,proxy_cfg); linphone_core_set_default_proxy(lc,proxy_cfg); while (counters->number_of_LinphoneRegistrationOk<1+(refresh!=0) && retry++ <310) { linphone_core_iterate(lc); if (counters->number_of_auth_info_requested>0 && late_auth_info) { info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } ms_usleep(100000); } CU_ASSERT_TRUE(linphone_proxy_config_is_registered(proxy_cfg)); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationNone,0); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationProgress,1); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationOk,1+(refresh!=0)); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationFailed,late_auth_info?1:0); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationCleared,0); }
static char* _get_identity(const LinphoneAccountCreator *creator) { char *identity = NULL; if (creator->username && creator->domain) { //we must escape username LinphoneProxyConfig* proxy = linphone_proxy_config_new(); LinphoneAddress* addr; linphone_proxy_config_set_identity(proxy, "sip:[email protected]"); addr = linphone_proxy_config_normalize_sip_uri(proxy, creator->username); linphone_address_set_domain(addr, creator->domain); identity = linphone_address_as_string(addr); linphone_address_destroy(addr); linphone_proxy_config_destroy(proxy); } return identity; }
void SIP_Account::on_buttonBox_accepted() { QString a; QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8")); QTextCodec *codec = QTextCodec::codecForCStrings(); LinphoneProxyConfig *cfg = _cfg; bool was_editing = true; if (!cfg){ was_editing = false; cfg=linphone_proxy_config_new(); } a = ui->lineEdit_account->text(); linphone_proxy_config_set_identity(cfg, a.toUtf8().data()); a = ui->lineEdit_proxy->text(); linphone_proxy_config_set_server_addr(cfg, a.toUtf8().data()); a = ui->lineEdit_route->text(); linphone_proxy_config_set_route(cfg, a.toUtf8().data()); linphone_proxy_config_expires(cfg, ui->spinBox_Regtime->value()); bool publish = ui->checkBox_publish->isChecked(); bool_t published = FALSE; if (publish) published = TRUE; linphone_proxy_config_enable_publish(cfg, published); bool reg = ui->checkBox_register->isChecked(); bool_t reged = FALSE; if (reg) reged = TRUE; linphone_proxy_config_enable_register(cfg, reged); if (was_editing){ if (linphone_proxy_config_done(cfg)==-1) return; } else { if (linphone_core_add_proxy_config(linphone_qt_get_core(),cfg)==-1) return; linphone_core_set_default_proxy(linphone_qt_get_core(),cfg); } _cfg = cfg; preferencewindow->linphone_qt_show_sip_accounts(); w->qt_load_identities(); this->clear_proxy(); this->close(); }
LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCreator *creator) { LinphoneAuthInfo *info; LinphoneProxyConfig *cfg = linphone_core_create_proxy_config(creator->core); char *identity_str = ms_strdup_printf("sip:%s@%s", creator->username, creator->domain); LinphoneAddress *identity = linphone_address_new(identity_str); if (creator->display_name) { linphone_address_set_display_name(identity, creator->display_name); } linphone_proxy_config_set_identity(cfg, linphone_address_as_string(identity)); linphone_proxy_config_set_server_addr(cfg, creator->domain); linphone_proxy_config_set_route(cfg, creator->route); linphone_proxy_config_enable_publish(cfg, FALSE); linphone_proxy_config_enable_register(cfg, TRUE); ms_free(identity_str); if (strcmp(creator->domain, "sip.linphone.org") == 0) { linphone_proxy_config_enable_avpf(cfg, TRUE); // If account created on sip.linphone.org, we configure linphone to use TLS by default if (linphone_core_sip_transport_supported(creator->core, LinphoneTransportTls)) { LinphoneAddress *addr = linphone_address_new(linphone_proxy_config_get_server_addr(cfg)); char *tmp; linphone_address_set_transport(addr, LinphoneTransportTls); tmp = linphone_address_as_string(addr); linphone_proxy_config_set_server_addr(cfg, tmp); linphone_proxy_config_set_route(cfg, tmp); ms_free(tmp); linphone_address_destroy(addr); } linphone_core_set_stun_server(creator->core, "stun.linphone.org"); linphone_core_set_firewall_policy(creator->core, LinphonePolicyUseIce); } info = linphone_auth_info_new(linphone_address_get_username(identity), NULL, creator->password, NULL, NULL, linphone_address_get_domain(identity)); linphone_core_add_auth_info(creator->core, info); linphone_address_destroy(identity); if (linphone_core_add_proxy_config(creator->core, cfg) != -1) { linphone_core_set_default_proxy(creator->core, cfg); return cfg; } linphone_core_remove_auth_info(creator->core, info); linphone_proxy_config_unref(cfg); return NULL; }
bool SipClient::setIdentity(const QString &identity, const QString &password) { m_identity = identity; m_password = password; /* Create Proxy Config*/ m_proxyCfg = linphone_core_create_proxy_config(lc); /*parse identity*/ LinphoneAddress *from = linphone_address_new(identity.toLatin1().data()); if (from == NULL) { qDebug() << __PRETTY_FUNCTION__ << " " << identity << " is not a valid sip uri, must be like sip:[email protected]"; return false; } m_authInfo = linphone_auth_info_new(linphone_address_get_username(from), NULL, password.toLatin1().data(), NULL, NULL, NULL); linphone_core_add_auth_info(lc, m_authInfo); /* Configure proxy entries */ /* Set identity with user name and domain*/ linphone_proxy_config_set_identity(m_proxyCfg, identity.toLatin1().data()); /* Extract domain address from identity*/ const char *server_addr = linphone_address_get_domain(from); /* We assume domain = proxy server address*/ linphone_proxy_config_set_server_addr(m_proxyCfg, server_addr); /* Activate registration for this proxy config*/ linphone_proxy_config_enable_register(m_proxyCfg, TRUE); /* Release resource*/ linphone_address_destroy(from); /* Add proxy config to linphone core*/ linphone_core_add_proxy_config(lc, m_proxyCfg); /* Set to default proxy*/ linphone_core_set_default_proxy(lc, m_proxyCfg); return true; }
static char* _get_identity(const LinphoneAccountCreator *creator) { char *identity = NULL; if (creator->username && creator->domain) { //we must escape username LinphoneProxyConfig* proxy = linphone_proxy_config_new(); LinphoneAddress* addr; // creator->domain may contain some port or some transport (eg. toto.org:443;transport=tcp), // we will accept that char * tmpidentity = ms_strdup_printf("sip:username@%s", creator->domain); linphone_proxy_config_set_identity(proxy, tmpidentity); ms_free(tmpidentity); addr = linphone_proxy_config_normalize_sip_uri(proxy, creator->username); identity = linphone_address_as_string(addr); linphone_address_destroy(addr); linphone_proxy_config_destroy(proxy); } return identity; }
LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LpConfig *config, int index) { const char *tmp; const char *identity; const char *proxy; LinphoneProxyConfig *cfg; char key[50]; sprintf(key,"proxy_%i",index); if (!lp_config_has_section(config,key)){ return NULL; } cfg=linphone_proxy_config_new(); identity=lp_config_get_string(config,key,"reg_identity",NULL); proxy=lp_config_get_string(config,key,"reg_proxy",NULL); linphone_proxy_config_set_identity(cfg,identity); linphone_proxy_config_set_server_addr(cfg,proxy); tmp=lp_config_get_string(config,key,"reg_route",NULL); if (tmp!=NULL) linphone_proxy_config_set_route(cfg,tmp); linphone_proxy_config_expires(cfg,lp_config_get_int(config,key,"reg_expires",600)); linphone_proxy_config_enableregister(cfg,lp_config_get_int(config,key,"reg_sendregister",0)); linphone_proxy_config_enable_publish(cfg,lp_config_get_int(config,key,"publish",0)); linphone_proxy_config_set_dial_escape_plus(cfg,lp_config_get_int(config,key,"dial_escape_plus",0)); linphone_proxy_config_set_dial_prefix(cfg,lp_config_get_string(config,key,"dial_prefix",NULL)); tmp=lp_config_get_string(config,key,"type",NULL); if (tmp!=NULL && strlen(tmp)>0) linphone_proxy_config_set_sip_setup(cfg,tmp); return cfg; }
void account_create_on_server(Account *account, const LinphoneProxyConfig *refcfg){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneAddress *tmp_identity=linphone_address_clone(account->modified_identity); LinphoneProxyConfig *cfg; LinphoneAuthInfo *ai; char *tmp; LinphoneAddress *server_addr; LCSipTransports tr; vtable.registration_state_changed=account_created_on_server_cb; vtable.auth_info_requested=account_created_auth_requested_cb; lc=configure_lc_from(&vtable,bc_tester_read_dir_prefix,NULL,account); tr.udp_port=LC_SIP_TRANSPORT_RANDOM; tr.tcp_port=LC_SIP_TRANSPORT_RANDOM; tr.tls_port=LC_SIP_TRANSPORT_RANDOM; linphone_core_set_sip_transports(lc,&tr); cfg=linphone_core_create_proxy_config(lc); linphone_address_set_secure(tmp_identity, FALSE); linphone_address_set_password(tmp_identity,account->password); linphone_address_set_header(tmp_identity,"X-Create-Account","yes"); tmp=linphone_address_as_string(tmp_identity); linphone_proxy_config_set_identity(cfg,tmp); ms_free(tmp); linphone_address_unref(tmp_identity); server_addr=linphone_address_new(linphone_proxy_config_get_server_addr(refcfg)); linphone_address_set_secure(server_addr, FALSE); linphone_address_set_transport(server_addr,LinphoneTransportTcp); /*use tcp for account creation, we may not have certificates configured at this stage*/ linphone_address_set_port(server_addr,0); tmp=linphone_address_as_string(server_addr); linphone_proxy_config_set_server_addr(cfg,tmp); ms_free(tmp); linphone_address_unref(server_addr); linphone_proxy_config_set_expires(cfg,3600); linphone_core_add_proxy_config(lc,cfg); if (wait_for_until(lc,NULL,&account->auth_requested,1,10000)==FALSE){ ms_fatal("Account for %s could not be created on server.", linphone_proxy_config_get_identity(refcfg)); } linphone_proxy_config_edit(cfg); tmp_identity=linphone_address_clone(account->modified_identity); linphone_address_set_secure(tmp_identity, FALSE); tmp=linphone_address_as_string(tmp_identity); linphone_proxy_config_set_identity(cfg,tmp); /*remove the X-Create-Account header*/ linphone_address_unref(tmp_identity); ms_free(tmp); linphone_proxy_config_done(cfg); ai=linphone_auth_info_new(linphone_address_get_username(account->modified_identity), NULL, account->password,NULL,NULL,linphone_address_get_domain(account->modified_identity)); linphone_core_add_auth_info(lc,ai); linphone_auth_info_destroy(ai); if (wait_for_until(lc,NULL,&account->created,1,3000)==FALSE){ ms_fatal("Account for %s is not working on server.", linphone_proxy_config_get_identity(refcfg)); } linphone_core_remove_proxy_config(lc,cfg); linphone_proxy_config_unref(cfg); if (wait_for_until(lc,NULL,&account->done,1,3000)==FALSE){ ms_error("Account creation could not clean the registration context."); } linphone_core_destroy(lc); }
extern "C" void Java_com_acsoftware_android_domophone_LibLP_nRegister(JNIEnv* env, jobject thiz, jstring jIdent, jstring jHost) { char buffer[256] = {0}; const char* ident = jIdent?env->GetStringUTFChars(jIdent, NULL):NULL; const char* host = jHost?env->GetStringUTFChars(jHost, NULL):NULL; if ( _RegistrationInProgress || !lc || !ident || !host || strlen(ident)+strlen(host) >= 256 ) return; // [self timerInitialize]; if ( Java_com_acsoftware_android_domophone_LibLP_nRegistered(env, thiz, jIdent, jHost) != 2 ) { _RegistrationInProgress = 1; //lastIdent = Ident; //lastHost = Host; CallMethod(env, "BeforeRegisterEvent"); Java_com_acsoftware_android_domophone_LibLP_nTerminateCall(env, thiz); Java_com_acsoftware_android_domophone_LibLP_nUnregister(env, thiz); linphone_core_clear_all_auth_info(lc); linphone_core_clear_proxy_config(lc); LCSipTransports transportValue; linphone_core_get_sip_transports(lc, &transportValue); if (transportValue.tcp_port == 0) transportValue.tcp_port=transportValue.udp_port + transportValue.tls_port; transportValue.udp_port=0; transportValue.tls_port=0; linphone_core_set_sip_transports(lc, &transportValue); LinphoneProxyConfig* proxy_cfg = linphone_proxy_config_new(); snprintf(buffer, 256, "sip:%s@%s", ident, host); linphone_proxy_config_set_identity(proxy_cfg, buffer); snprintf(buffer, 256, "sip:%s", host); linphone_proxy_config_set_server_addr(proxy_cfg, buffer); linphone_proxy_config_enable_register(proxy_cfg, true); linphone_proxy_config_expires(proxy_cfg, DEFAULT_EXPIRES); linphone_core_add_proxy_config(lc,proxy_cfg); linphone_core_set_default_proxy(lc,proxy_cfg); linphone_core_set_network_reachable(lc, true); } else { CallMethod(env, "SipRegisteredEvent"); } if ( ident ) { env->ReleaseStringUTFChars(jIdent, ident); } if ( host ) { env->ReleaseStringUTFChars(jHost, host); } };
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; }