mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-24 06:38:08 +00:00
Changes in account_creator
-Add deprecated tag to domain and route function -Add custom constructor for linphone account
This commit is contained in:
parent
a02b4c60ce
commit
ed9c2fd478
5 changed files with 130 additions and 27 deletions
|
|
@ -42,8 +42,11 @@ static const char* ha1_for_passwd(const char* username, const char* realm, const
|
|||
return ha1;
|
||||
}
|
||||
|
||||
static unsigned int validate_uri(LinphoneCore *lc, LinphoneProxyConfig *proxy, const char* username, const char* display_name) {
|
||||
static unsigned int validate_uri(const char* username, const char* domain, const char* display_name) {
|
||||
LinphoneAddress* addr;
|
||||
int status = 0;
|
||||
LinphoneProxyConfig* proxy = linphone_proxy_config_new();
|
||||
linphone_proxy_config_set_identity(proxy, "sip:userame@domain.com");
|
||||
|
||||
if (username) {
|
||||
addr = linphone_proxy_config_normalize_sip_uri(proxy, username);
|
||||
|
|
@ -51,16 +54,22 @@ static unsigned int validate_uri(LinphoneCore *lc, LinphoneProxyConfig *proxy, c
|
|||
addr = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy));
|
||||
}
|
||||
|
||||
if (addr == NULL)
|
||||
return 1;
|
||||
|
||||
if (display_name && (!strlen(display_name) || linphone_address_set_display_name(addr, display_name) != 0)) {
|
||||
linphone_address_unref(addr);
|
||||
return 1;
|
||||
if (addr == NULL) {
|
||||
status = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (domain && linphone_address_set_domain(addr, domain) != 0) {
|
||||
status = 1;
|
||||
}
|
||||
|
||||
if (display_name && (!strlen(display_name) || linphone_address_set_display_name(addr, display_name) != 0)) {
|
||||
status = 1;
|
||||
}
|
||||
linphone_address_unref(addr);
|
||||
return 0;
|
||||
end:
|
||||
linphone_proxy_config_destroy(proxy);
|
||||
return status;
|
||||
}
|
||||
|
||||
static char* _get_identity(const LinphoneAccountCreator *creator) {
|
||||
|
|
@ -71,6 +80,7 @@ static char* _get_identity(const LinphoneAccountCreator *creator) {
|
|||
LinphoneAddress* addr;
|
||||
|
||||
addr = linphone_proxy_config_normalize_sip_uri(proxy, creator->username ? creator->username : creator->phone_number);
|
||||
if (addr == NULL) return NULL;
|
||||
|
||||
identity = linphone_address_as_string(addr);
|
||||
linphone_address_unref(addr);
|
||||
|
|
@ -102,18 +112,18 @@ LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCr
|
|||
LinphoneProxyConfig *cfg = creator->proxy_cfg;
|
||||
char *identity_str = _get_identity(creator);
|
||||
LinphoneAddress *identity = linphone_address_new(identity_str);
|
||||
// char *route = NULL;
|
||||
// char *domain = NULL;
|
||||
char *route = NULL;
|
||||
char *domain = NULL;
|
||||
ms_free(identity_str);
|
||||
if (creator->display_name) {
|
||||
linphone_address_set_display_name(identity, creator->display_name);
|
||||
}
|
||||
// if (creator->route) {
|
||||
// route = ms_strdup_printf("%s;transport=%s", creator->route, linphone_transport_to_string(creator->transport));
|
||||
// }
|
||||
// if (creator->domain) {
|
||||
// domain = ms_strdup_printf("%s;transport=%s", creator->domain, linphone_transport_to_string(creator->transport));
|
||||
// }
|
||||
if (creator->route) {
|
||||
route = ms_strdup_printf("%s", creator->route);
|
||||
}
|
||||
if (creator->domain) {
|
||||
domain = ms_strdup_printf("%s", creator->domain);
|
||||
}
|
||||
linphone_proxy_config_set_identity_address(cfg, identity);
|
||||
if (creator->phone_country_code) {
|
||||
linphone_proxy_config_set_dial_prefix(cfg, creator->phone_country_code);
|
||||
|
|
@ -123,14 +133,16 @@ LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCr
|
|||
snprintf(buff, sizeof(buff), "%d", dial_prefix_number);
|
||||
linphone_proxy_config_set_dial_prefix(cfg, buff);
|
||||
}
|
||||
// if (linphone_proxy_config_get_server_addr(cfg) == NULL)
|
||||
// linphone_proxy_config_set_server_addr(cfg, domain);
|
||||
// if (linphone_proxy_config_get_route(cfg) == NULL)
|
||||
// linphone_proxy_config_set_route(cfg, route);
|
||||
if (linphone_proxy_config_get_server_addr(cfg) == NULL)
|
||||
linphone_proxy_config_set_server_addr(cfg, domain);
|
||||
if (linphone_proxy_config_get_route(cfg) == NULL)
|
||||
linphone_proxy_config_set_route(cfg, route);
|
||||
|
||||
linphone_proxy_config_enable_publish(cfg, FALSE);
|
||||
linphone_proxy_config_enable_register(cfg, TRUE);
|
||||
|
||||
if (strcmp(linphone_proxy_config_get_realm(creator->proxy_cfg), "sip.linphone.org") == 0) {
|
||||
if (linphone_proxy_config_get_realm(cfg) != NULL
|
||||
&& strcmp(linphone_proxy_config_get_realm(cfg), "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)) {
|
||||
|
|
@ -289,6 +301,8 @@ static void _linphone_account_creator_destroy(LinphoneAccountCreator *creator) {
|
|||
if (creator->email) ms_free(creator->email);
|
||||
if (creator->language) ms_free(creator->language);
|
||||
if (creator->activation_code) ms_free(creator->activation_code);
|
||||
if (creator->domain) ms_free(creator->domain);
|
||||
if (creator->route) ms_free(creator->route);
|
||||
}
|
||||
|
||||
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneAccountCreator);
|
||||
|
|
@ -302,11 +316,15 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneAccountCreator, belle_sip_object_t,
|
|||
|
||||
LinphoneAccountCreator * linphone_account_creator_new(LinphoneCore *core, const char *xmlrpc_url) {
|
||||
LinphoneAccountCreator *creator;
|
||||
const char* domain = lp_config_get_string(core->config, "assistant", "domain", NULL);
|
||||
creator = belle_sip_object_new(LinphoneAccountCreator);
|
||||
creator->requests_cbs = linphone_core_get_account_creator_request_engine_cbs(core);
|
||||
creator->responses_cbs = linphone_account_creator_reponses_cbs_new();
|
||||
creator->core = core;
|
||||
creator->xmlrpc_session = (xmlrpc_url) ? linphone_xml_rpc_session_new(core, xmlrpc_url) : NULL;
|
||||
if (domain) {
|
||||
linphone_account_creator_set_domain(creator, domain);
|
||||
}
|
||||
creator->proxy_cfg = linphone_core_create_proxy_config(core);
|
||||
if (creator->requests_cbs != NULL && linphone_account_creator_requests_cbs_get_constructor_cb(creator->requests_cbs) != NULL)
|
||||
linphone_account_creator_requests_cbs_get_constructor_cb(creator->requests_cbs)(creator);
|
||||
|
|
@ -346,7 +364,7 @@ LinphoneUsernameCheck linphone_account_creator_set_username(LinphoneAccountCreat
|
|||
return LinphoneUsernameInvalid;
|
||||
} else if (regex && !is_matching_regex(username, regex)) {
|
||||
return LinphoneUsernameInvalidCharacters;
|
||||
} else if (validate_uri(creator->core, creator->proxy_cfg, username, NULL) != 0) {
|
||||
} else if (validate_uri(username, NULL, NULL) != 0) {
|
||||
return LinphoneUsernameInvalid;
|
||||
}
|
||||
|
||||
|
|
@ -455,7 +473,7 @@ const char * linphone_account_creator_get_language(const LinphoneAccountCreator
|
|||
}
|
||||
|
||||
LinphoneUsernameCheck linphone_account_creator_set_display_name(LinphoneAccountCreator *creator, const char *display_name) {
|
||||
if (validate_uri(creator->core, creator->proxy_cfg, NULL, display_name) != 0) {
|
||||
if (validate_uri(NULL, display_name, NULL) != 0) {
|
||||
return LinphoneUsernameInvalid;
|
||||
}
|
||||
set_string(&creator->display_name, display_name, FALSE);
|
||||
|
|
@ -481,6 +499,31 @@ const char * linphone_account_creator_get_email(const LinphoneAccountCreator *cr
|
|||
return creator->email;
|
||||
}
|
||||
|
||||
LinphoneRequestStatus linphone_account_creator_set_domain(LinphoneAccountCreator *creator, const char *domain) {
|
||||
if (domain && validate_uri(NULL, domain, NULL) != 0) {
|
||||
return LinphoneRequestFailed;
|
||||
}
|
||||
|
||||
set_string(&creator->domain, domain, TRUE);
|
||||
return LinphoneRequestOk;
|
||||
}
|
||||
|
||||
const char * linphone_account_creator_get_domain(const LinphoneAccountCreator *creator) {
|
||||
return creator->domain;
|
||||
}
|
||||
|
||||
LinphoneRequestStatus linphone_account_creator_set_route(LinphoneAccountCreator *creator, const char *route) {
|
||||
if (!route || linphone_proxy_config_set_route(creator->proxy_cfg, route) != 0)
|
||||
return LinphoneRequestFailed;
|
||||
|
||||
set_string(&creator->route, route, TRUE);
|
||||
return LinphoneRequestOk;
|
||||
}
|
||||
|
||||
const char * linphone_account_creator_get_route(const LinphoneAccountCreator *creator) {
|
||||
return creator->route;
|
||||
}
|
||||
|
||||
LinphoneAccountCreatorResponseCbs * linphone_account_creator_get_responses_cbs(const LinphoneAccountCreator *creator) {
|
||||
return creator->responses_cbs;
|
||||
}
|
||||
|
|
@ -582,6 +625,15 @@ LinphoneRequestStatus linphone_account_creator_update_account(LinphoneAccountCre
|
|||
|
||||
/************************** Start Account Creator Linphone **************************/
|
||||
|
||||
LinphoneRequestStatus linphone_account_creator_constructor_custom(LinphoneAccountCreator *creator) {
|
||||
linphone_proxy_config_set_realm(creator->proxy_cfg, "sip.linphone.org");
|
||||
linphone_proxy_config_set_route(creator->proxy_cfg, "sip.linphone.org");
|
||||
linphone_proxy_config_set_server_addr(creator->proxy_cfg, "sip.linphone.org");
|
||||
linphone_proxy_config_set_identity(creator->proxy_cfg, "sip:username@sip.linphone.org");
|
||||
|
||||
return LinphoneRequestOk;
|
||||
}
|
||||
|
||||
/****************** START OF ACCOUNT USED SECTION *****************************/
|
||||
static void _is_account_exist_response_cb(LinphoneXmlRpcRequest *request) {
|
||||
LinphoneAccountCreator *creator = (LinphoneAccountCreator *)linphone_xml_rpc_request_get_user_data(request);
|
||||
|
|
|
|||
|
|
@ -2074,7 +2074,7 @@ static void linphone_core_internal_subscription_state_changed(LinphoneCore *lc,
|
|||
|
||||
static void _linphone_core_init_account_creator_request_cbs(LinphoneCore *lc) {
|
||||
LinphoneAccountCreatorRequestCbs *cbs = linphone_account_creator_requests_cbs_new();
|
||||
cbs->account_creator_request_constructor_cb = NULL;
|
||||
cbs->account_creator_request_constructor_cb = linphone_account_creator_constructor_custom;
|
||||
cbs->account_creator_request_destructor_cb = NULL;
|
||||
cbs->create_account_request_cb = linphone_account_creator_create_account_custom;
|
||||
cbs->is_account_exist_request_cb = linphone_account_creator_is_account_exist_custom;
|
||||
|
|
@ -2104,6 +2104,8 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
|
|||
|
||||
linphone_task_list_init(&lc->hooks);
|
||||
|
||||
_linphone_core_init_account_creator_request_cbs(lc);
|
||||
|
||||
linphone_core_cbs_set_notify_received(internal_cbs, linphone_core_internal_notify_received);
|
||||
linphone_core_cbs_set_subscription_state_changed(internal_cbs, linphone_core_internal_subscription_state_changed);
|
||||
_linphone_core_add_callbacks(lc, internal_cbs, TRUE);
|
||||
|
|
@ -2169,8 +2171,6 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
|
|||
linphone_configuring_terminated(lc, LinphoneConfiguringSkipped, NULL);
|
||||
} // else linphone_core_start will be called after the remote provisioning (see linphone_core_iterate)
|
||||
lc->bw_controller = ms_bandwidth_controller_new();
|
||||
|
||||
_linphone_core_init_account_creator_request_cbs(lc);
|
||||
}
|
||||
|
||||
LinphoneCore *_linphone_core_new_with_config(LinphoneCoreCbs *cbs, struct _LpConfig *config, void *userdata) {
|
||||
|
|
|
|||
|
|
@ -1460,6 +1460,10 @@ struct _LinphoneAccountCreator {
|
|||
/* Misc */
|
||||
char *language; /**< User language */
|
||||
char *activation_code; /**< Account validation code */
|
||||
|
||||
/* Deprecated */
|
||||
char *domain;
|
||||
char *route;
|
||||
};
|
||||
|
||||
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneAccountCreator);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,9 @@ void linphone_gtk_assistant_prepare(GtkWidget *assistant) {
|
|||
check_account_validation(assistant);
|
||||
break;
|
||||
case 9:
|
||||
linphone_gtk_load_identities();
|
||||
if (linphone_account_creator_configure(linphone_gtk_assistant_get_creator(assistant)) != NULL) {
|
||||
linphone_gtk_load_identities();
|
||||
}
|
||||
gtk_assistant_commit(GTK_ASSISTANT(assistant));
|
||||
break;
|
||||
default:
|
||||
|
|
@ -126,8 +128,12 @@ static int linphone_gtk_assistant_forward(int curpage, gpointer data) {
|
|||
case 2:
|
||||
{
|
||||
GtkEntry *username_entry = GTK_ENTRY(linphone_gtk_get_widget(w, "p2_entry_username"));
|
||||
GtkEntry *domain_entry = GTK_ENTRY(linphone_gtk_get_widget(w, "p2_entry_domain"));
|
||||
GtkEntry *proxy_entry = GTK_ENTRY(linphone_gtk_get_widget(w, "p2_entry_proxy"));
|
||||
GtkEntry *password_entry = GTK_ENTRY(linphone_gtk_get_widget(w, "p2_entry_password"));
|
||||
linphone_account_creator_set_username(creator, gtk_entry_get_text(username_entry));
|
||||
linphone_account_creator_set_domain(creator, gtk_entry_get_text(domain_entry));
|
||||
linphone_account_creator_set_route(creator, gtk_entry_get_text(proxy_entry));
|
||||
linphone_account_creator_set_password(creator, gtk_entry_get_text(password_entry));
|
||||
curpage = 9; // Go to page_9_finish
|
||||
break;
|
||||
|
|
@ -137,6 +143,8 @@ static int linphone_gtk_assistant_forward(int curpage, gpointer data) {
|
|||
GtkEntry *username_entry = GTK_ENTRY(linphone_gtk_get_widget(w, "p3_entry_username"));
|
||||
GtkEntry *password_entry = GTK_ENTRY(linphone_gtk_get_widget(w, "p3_entry_password"));
|
||||
linphone_account_creator_set_username(creator, gtk_entry_get_text(username_entry));
|
||||
linphone_account_creator_set_domain(creator, "sip.linphone.org");
|
||||
linphone_account_creator_set_route(creator, "sip.linphone.org");
|
||||
linphone_account_creator_set_password(creator, gtk_entry_get_text(password_entry));
|
||||
curpage = 9; // Go to page_9_finish
|
||||
break;
|
||||
|
|
@ -249,6 +257,8 @@ void linphone_gtk_account_creation_username_changed(GtkEntry *entry) {
|
|||
|
||||
LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(assistant);
|
||||
linphone_account_creator_set_username(creator, gtk_entry_get_text(username));
|
||||
linphone_account_creator_set_domain(creator, "sip.linphone.org");
|
||||
linphone_account_creator_set_route(creator, "sip.linphone.org");
|
||||
|
||||
if (check_username_validity(gtk_entry_get_text(username))) {
|
||||
guint timerID = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(page), "usernameAvailabilityTimerID"));
|
||||
|
|
|
|||
|
|
@ -266,6 +266,36 @@ LINPHONE_PUBLIC LinphoneEmailCheck linphone_account_creator_set_email(LinphoneAc
|
|||
**/
|
||||
LINPHONE_PUBLIC const char * linphone_account_creator_get_email(const LinphoneAccountCreator *creator);
|
||||
|
||||
/**
|
||||
* Set the domain.
|
||||
* @param[in] creator LinphoneAccountCreator object
|
||||
* @param[in] domain The domain to set
|
||||
* @return LinphoneRequestOk if everything is OK, or a specific error otherwise.
|
||||
**/
|
||||
LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneRequestStatus linphone_account_creator_set_domain(LinphoneAccountCreator *creator, const char *domain);
|
||||
|
||||
/**
|
||||
* Get the domain.
|
||||
* @param[in] creator LinphoneAccountCreator object
|
||||
* @return The domain of the LinphoneAccountCreator
|
||||
**/
|
||||
LINPHONE_DEPRECATED LINPHONE_PUBLIC const char * linphone_account_creator_get_domain(const LinphoneAccountCreator *creator);
|
||||
|
||||
/**
|
||||
* Set the route.
|
||||
* @param[in] creator LinphoneAccountCreator object
|
||||
* @param[in] route The route to set
|
||||
* @return LinphoneRequestOk if everything is OK, or a specific error otherwise.
|
||||
**/
|
||||
LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneRequestStatus linphone_account_creator_set_route(LinphoneAccountCreator *creator, const char *route);
|
||||
|
||||
/**
|
||||
* Get the route.
|
||||
* @param[in] creator LinphoneAccountCreator object
|
||||
* @return The route of the LinphoneAccountCreator
|
||||
**/
|
||||
LINPHONE_DEPRECATED LINPHONE_PUBLIC const char * linphone_account_creator_get_route(const LinphoneAccountCreator *creator);
|
||||
|
||||
/**
|
||||
* Get the LinphoneAccountCreatorResponseCbs object associated with a LinphoneAccountCreator.
|
||||
* @param[in] creator LinphoneAccountCreator object
|
||||
|
|
@ -284,6 +314,13 @@ LINPHONE_PUBLIC LinphoneAccountCreatorRequestCbs * linphone_account_creator_get_
|
|||
|
||||
/************************** Start Account Creator Linphone **************************/
|
||||
|
||||
/**
|
||||
* Account creator custom to set Linphone default values
|
||||
* @param[in] creator LinphoneAccountCreator object
|
||||
* @return LinphoneRequestOk if the request has been sent, LinphoneRequestFailed otherwise
|
||||
**/
|
||||
LINPHONE_PUBLIC LinphoneRequestStatus linphone_account_creator_constructor_custom(LinphoneAccountCreator *creator);
|
||||
|
||||
/**
|
||||
* Send an XML-RPC request to test the existence of a Linphone account.
|
||||
* @param[in] creator LinphoneAccountCreator object
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue