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; }
LinphoneEvent *linphone_event_new_with_op(LinphoneCore *lc, SalOp *op, LinphoneSubscriptionDir dir, const char *name){ LinphoneEvent *lev=linphone_event_new_base(lc, dir, name, op); if (dir==LinphoneSubscriptionIncoming){ lev->resource_addr=linphone_address_clone((LinphoneAddress*)sal_op_get_to_address(op)); lev->from=linphone_address_clone((LinphoneAddress*)sal_op_get_from_address(lev->op)); }else{ lev->resource_addr=linphone_address_clone((LinphoneAddress*)sal_op_get_from_address(op)); } return lev; }
LinphoneEvent *linphone_core_subscribe(LinphoneCore *lc, const LinphoneAddress *resource, const char *event, int expires, const LinphoneContent *body){ LinphoneEvent *lev=linphone_event_new(lc, LinphoneSubscriptionOutgoing, event); SalBody salbody; linphone_configure_op(lc,lev->op,resource,NULL,TRUE); sal_op_set_manual_refresher_mode(lev->op,!lp_config_get_int(lc->config,"sip","refresh_generic_subscribe",1)); lev->resource_addr=linphone_address_clone(resource); lev->from=linphone_address_clone((LinphoneAddress*)sal_op_get_from_address(lev->op)); sal_subscribe(lev->op,NULL,NULL,event,expires,sal_body_from_content(&salbody,body)); linphone_event_set_state(lev,LinphoneSubscriptionOutoingInit); return lev; }
Account *account_new(LinphoneAddress *identity, const char *unique_id){ char *modified_username; Account *obj=ms_new0(Account,1); /* we need to inhibit leak detector because the two LinphoneAddress will remain behond the scope of the test being run */ belle_sip_object_inhibit_leak_detector(TRUE); obj->identity=linphone_address_clone(identity); obj->password=sal_get_random_token(8); obj->modified_identity=linphone_address_clone(identity); modified_username=ms_strdup_printf("%s_%s",linphone_address_get_username(identity), unique_id); linphone_address_set_username(obj->modified_identity, modified_username); ms_free(modified_username); belle_sip_object_inhibit_leak_detector(FALSE); return obj; };
int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr){ LinphoneAddress *fr=linphone_address_clone(addr); linphone_address_clean(fr); if (lf->uri!=NULL) linphone_address_destroy(lf->uri); lf->uri=fr; return 0; }
void linphone_core_manager_start(LinphoneCoreManager *mgr, const char* rc_file, int check_for_proxies) { LinphoneProxyConfig* proxy; int proxy_count; /*BC_ASSERT_EQUAL(ms_list_size(linphone_core_get_proxy_config_list(lc)),proxy_count, int, "%d");*/ if (check_for_proxies && rc_file) /**/ proxy_count=ms_list_size(linphone_core_get_proxy_config_list(mgr->lc)); else proxy_count=0; if (proxy_count){ #define REGISTER_TIMEOUT 20 /* seconds */ int success = wait_for_until(mgr->lc,NULL,&mgr->stat.number_of_LinphoneRegistrationOk, proxy_count,(REGISTER_TIMEOUT * 1000 * proxy_count)); if( !success ){ ms_error("Did not register after %d seconds for %d proxies", REGISTER_TIMEOUT, proxy_count); } } BC_ASSERT_EQUAL(mgr->stat.number_of_LinphoneRegistrationOk,proxy_count, int, "%d"); enable_codec(mgr->lc,"PCMU",8000); linphone_core_get_default_proxy(mgr->lc,&proxy); if (proxy) { mgr->identity = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy)); linphone_address_clean(mgr->identity); } }
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; }
/** * Duplicate a LinphoneChatMessage **/ LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* msg) { /*struct _LinphoneChatMessage { char* message; LinphoneChatRoom* chat_room; LinphoneChatMessageStateChangeCb cb; void* cb_ud; void* message_userdata; char* external_body_url; LinphoneAddress* from; time_t time; SalCustomHeader *custom_headers; LinphoneChatMessageState state; };*/ LinphoneChatMessage* new_message = linphone_chat_room_create_message(msg->chat_room,msg->message); if (msg->external_body_url) new_message->external_body_url=ms_strdup(msg->external_body_url); new_message->cb=msg->cb; new_message->cb_ud=msg->cb_ud; new_message->message_userdata=msg->message_userdata; new_message->cb=msg->cb; new_message->time=msg->time; new_message->state=msg->state; new_message->storage_id=msg->storage_id; if (msg->from) new_message->from=linphone_address_clone(msg->from); return new_message; }
AddressAPIPtr AddressAPI::clone() const { CORE_MUTEX FBLOG_DEBUG("AddressAPI::clone", "this=" << this); AddressAPIPtr ret(new AddressAPI(linphone_address_clone(mAddress))); ret->own(); return ret; }
int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr){ LinphoneAddress *fr = linphone_address_clone(addr); LinphoneVcard *vcard = NULL; linphone_address_clean(fr); if (lf->uri != NULL) linphone_address_unref(lf->uri); lf->uri = fr; vcard = linphone_friend_get_vcard(lf); if (vcard) { linphone_vcard_edit_main_sip_address(vcard, linphone_address_as_string_uri_only(fr)); } return 0; }
static void simple_subscribe_with_early_notify(void) { LinphoneCoreManager* marie = presence_linphone_core_manager_new("marie"); LinphoneCoreManager* pauline = presence_linphone_core_manager_new("pauline"); LinphoneAddress *marie_identity_addr = linphone_address_clone(marie->identity); LpConfig *pauline_lp; char* pauline_identity=linphone_address_as_string_uri_only(pauline->identity); char* marie_identity; LinphoneFriend* pauline_s_friend; LinphoneFriend* marie_s_friend=linphone_core_create_friend_with_address(marie->lc,pauline_identity); pauline_lp = linphone_core_get_config(pauline->lc); lp_config_set_int(pauline_lp,"sip","notify_pending_state",1); linphone_friend_edit(marie_s_friend); linphone_friend_enable_subscribes(marie_s_friend,TRUE); linphone_friend_done(marie_s_friend); linphone_core_add_friend(marie->lc,marie_s_friend); ms_free(pauline_identity); /*to simulate pending state.*/ linphone_address_set_port(marie_identity_addr,0); marie_identity=linphone_address_as_string_uri_only(marie_identity_addr); pauline_s_friend=linphone_core_create_friend_with_address(pauline->lc,marie_identity); linphone_core_add_friend(pauline->lc,pauline_s_friend); ms_free(marie_identity); BC_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_NotifyPresenceReceived,1)); BC_ASSERT_EQUAL(linphone_friend_get_subscription_state(marie_s_friend), LinphoneSubscriptionPending,int, "%d"); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityOnline,marie->stat.number_of_LinphonePresenceActivityOnline+1); BC_ASSERT_EQUAL(marie->stat.number_of_NotifyPresenceReceived,2, int, "%d"); linphone_friend_unref(marie_s_friend); linphone_friend_unref(pauline_s_friend); linphone_address_unref(marie_identity_addr); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; if (!lf || !addr) { return; } if (lf->uri == NULL) { LinphoneAddress *fr = linphone_address_clone(addr); linphone_address_clean(fr); lf->uri = fr; } vcard = linphone_friend_get_vcard(lf); if (!vcard) { return; } linphone_vcard_add_sip_address(vcard, linphone_address_as_string_uri_only(addr)); }
void linphone_core_manager_start(LinphoneCoreManager *mgr, int check_for_proxies) { LinphoneProxyConfig* proxy; int proxy_count; /*BC_ASSERT_EQUAL(ms_list_size(linphone_core_get_proxy_config_list(lc)),proxy_count, int, "%d");*/ if (check_for_proxies){ /**/ proxy_count=ms_list_size(linphone_core_get_proxy_config_list(mgr->lc)); }else{ proxy_count=0; /*this is to prevent registration to go on*/ linphone_core_set_network_reachable(mgr->lc, FALSE); } if (proxy_count){ #define REGISTER_TIMEOUT 20 /* seconds */ int success = wait_for_until(mgr->lc,NULL,&mgr->stat.number_of_LinphoneRegistrationOk, proxy_count,(REGISTER_TIMEOUT * 1000 * proxy_count)); if( !success ){ ms_error("Did not register after %d seconds for %d proxies", REGISTER_TIMEOUT, proxy_count); } } BC_ASSERT_EQUAL(mgr->stat.number_of_LinphoneRegistrationOk,proxy_count, int, "%d"); enable_codec(mgr->lc,"PCMU",8000); proxy = linphone_core_get_default_proxy_config(mgr->lc); if (proxy) { if (mgr->identity){ linphone_address_destroy(mgr->identity); } mgr->identity = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy)); linphone_address_clean(mgr->identity); } if (linphone_core_get_stun_server(mgr->lc) != NULL){ /*before we go, ensure that the stun server is resolved, otherwise all ice related test will fail*/ BC_ASSERT_TRUE(wait_for_stun_resolution(mgr)); } if (!check_for_proxies){ /*now that stun server resolution is done, we can start registering*/ linphone_core_set_network_reachable(mgr->lc, TRUE); } }
void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; char *address = NULL; if (!lf || !addr) { return; } if (lf->uri == NULL) { LinphoneAddress *fr = linphone_address_clone(addr); linphone_address_clean(fr); lf->uri = fr; } vcard = lf->vcard; if (!vcard) { return; } address = linphone_address_as_string_uri_only(addr); linphone_vcard_add_sip_address(vcard, address); ms_free(address); }
/** * Set destination of the message *@param message #LinphoneChatMessage obj *@param to #LinphoneAddress destination of this message (copied) */ void linphone_chat_message_set_to(LinphoneChatMessage* message, const LinphoneAddress* to) { if(message->to) linphone_address_destroy(message->to); message->to=linphone_address_clone(to); }
/** * Set origin of the message *@param message #LinphoneChatMessage obj *@param from #LinphoneAddress origin of this message (copied) */ void linphone_chat_message_set_from(LinphoneChatMessage* message, const LinphoneAddress* from) { if(message->from) linphone_address_destroy(message->from); message->from=linphone_address_clone(from); }
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); }