Commit e9abeb45 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Improve API of linphone account creator.

parent 1dee00dd
......@@ -26,6 +26,7 @@ struct _LinphoneAccountCreator {
LinphoneAccountCreatorCb existence_test_cb;
LinphoneAccountCreatorCb validation_test_cb;
LinphoneAccountCreatorCb validate_cb;
LinphoneCore *core;
void *existence_test_cb_ud;
void *validation_test_cb_ud;
void *validate_cb_ud;
......@@ -35,12 +36,13 @@ struct _LinphoneAccountCreator {
char *domain;
char *route;
char *email;
bool_t subscribe;
bool_t subscribe_to_newsletter;
};
LinphoneAccountCreator * linphone_account_creator_new(LinphoneCore *core, const char *xmlrpc_url) {
LinphoneAccountCreator *creator;
creator = ms_new0(LinphoneAccountCreator, 1);
creator->core = core;
creator->xmlrpc_session = linphone_xml_rpc_session_new(core, xmlrpc_url);
return creator;
}
......@@ -85,12 +87,12 @@ const char * linphone_account_creator_get_email(const LinphoneAccountCreator *cr
return creator->email;
}
void linphone_account_creator_set_subscribe(LinphoneAccountCreator *creator, bool_t subscribe) {
creator->subscribe = subscribe;
void linphone_account_creator_enable_newsletter_subscription(LinphoneAccountCreator *creator, bool_t subscribe) {
creator->subscribe_to_newsletter = subscribe;
}
bool_t linphone_account_creator_get_subscribe(const LinphoneAccountCreator *creator) {
return creator->subscribe;
bool_t linphone_account_creator_newsletter_subscription_enabled(const LinphoneAccountCreator *creator) {
return creator->subscribe_to_newsletter;
}
void linphone_account_creator_set_test_existence_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorCb cb, void *user_data) {
......@@ -190,7 +192,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_validate(LinphoneAccountCr
LinphoneXmlRpcArgString, identity,
LinphoneXmlRpcArgString, creator->password,
LinphoneXmlRpcArgString, creator->email,
LinphoneXmlRpcArgInt, (creator->subscribe == TRUE) ? 1 : 0,
LinphoneXmlRpcArgInt, (creator->subscribe_to_newsletter == TRUE) ? 1 : 0,
LinphoneXmlRpcArgNone);
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
linphone_xml_rpc_request_unref(request);
......@@ -198,6 +200,51 @@ LinphoneAccountCreatorStatus linphone_account_creator_validate(LinphoneAccountCr
return LinphoneAccountCreatorOk;
}
LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCreator *creator) {
LinphoneAddress *identity;
LinphoneAuthInfo *info;
LinphoneProxyConfig *cfg = linphone_core_create_proxy_config(creator->core);
char *identity_str = ms_strdup_printf("sip:%s@%s", creator->username, creator->domain);
linphone_proxy_config_set_identity(cfg, identity_str);
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);
}
identity = linphone_address_new(linphone_proxy_config_get_identity(cfg));
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;
}
void linphone_account_creator_destroy(LinphoneAccountCreator *creator){
linphone_xml_rpc_session_unref(creator->xmlrpc_session);
if (creator->username) ms_free(creator->username);
......
......@@ -138,18 +138,18 @@ LINPHONE_PUBLIC void linphone_account_creator_set_email(LinphoneAccountCreator *
LINPHONE_PUBLIC const char * linphone_account_creator_get_email(const LinphoneAccountCreator *creator);
/**
* Set the subscribe (to the newsletter) field.
* Enable the newsletter subscription.
* @param[in] creator LinphoneAccountCreator object
* @param[in] subscribe A boolean telling whether to subscribe to the newsletter or not.
**/
LINPHONE_PUBLIC void linphone_account_creator_set_subscribe(LinphoneAccountCreator *creator, bool_t subscribe);
LINPHONE_PUBLIC void linphone_account_creator_enable_newsletter_subscription(LinphoneAccountCreator *creator, bool_t subscribe);
/**
* Get the subscribe (to the newsletter) field.
* Tell whether to subscribe to the newsletter or not.
* @param[in] creator LinphoneAccountCreator object
* @return A boolean telling whether to subscribe to the newsletter or not.
**/
LINPHONE_PUBLIC bool_t linphone_account_creator_get_subscribe(const LinphoneAccountCreator *creator);
LINPHONE_PUBLIC bool_t linphone_account_creator_newsletter_subscription_enabled(const LinphoneAccountCreator *creator);
/**
* Set the callback called when the account existence test is finished.
......@@ -196,6 +196,13 @@ LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_test_valid
**/
LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_validate(LinphoneAccountCreator *creator);
/**
* Configure an account (create a proxy config and authentication info for it).
* @param[in] creator LinphoneAccountCreator object
* @return A LinphoneProxyConfig object if successful, NULL otherwise
**/
LINPHONE_PUBLIC LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCreator *creator);
/**
* @}
*/
......
......@@ -367,7 +367,6 @@ LINPHONE_PUBLIC const char* linphone_privacy_to_string(LinphonePrivacy privacy);
#ifdef IN_LINPHONE
#include "account_creator.h"
#include "buffer.h"
#include "call_log.h"
#include "call_params.h"
......@@ -376,7 +375,6 @@ LINPHONE_PUBLIC const char* linphone_privacy_to_string(LinphonePrivacy privacy);
#include "linphonefriend.h"
#include "xmlrpc.h"
#else
#include "linphone/account_creator.h"
#include "linphone/buffer.h"
#include "linphone/call_log.h"
#include "linphone/call_params.h"
......@@ -1336,6 +1334,13 @@ LINPHONE_PUBLIC LinphoneAuthInfo * linphone_auth_info_new_from_config_file(LpCon
*/
#ifdef IN_LINPHONE
#include "account_creator.h"
#else
#include "linphone/account_creator.h"
#endif
struct _LinphoneChatRoom;
/**
* @addtogroup chatroom
......
......@@ -46,6 +46,7 @@ static void linphone_gtk_account_validate_cb(LinphoneAccountCreator *creator, Li
// Go to page_8_error
gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), 8);
}
gtk_assistant_commit(GTK_ASSISTANT(assistant));
}
static void create_account(GtkWidget *assistant) {
......@@ -86,49 +87,10 @@ static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page
check_account_validation(assistant);
break;
case 9:
{
LinphoneAddress *identity;
LinphoneAuthInfo *info;
LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(assistant);
LinphoneProxyConfig *cfg = linphone_core_create_proxy_config(linphone_gtk_get_core());
char *identity_str = ms_strdup_printf("sip:%s@%s", linphone_account_creator_get_username(creator), linphone_account_creator_get_domain(creator));
linphone_proxy_config_set_identity(cfg, identity_str);
linphone_proxy_config_set_server_addr(cfg, linphone_account_creator_get_domain(creator));
linphone_proxy_config_set_route(cfg, linphone_account_creator_get_route(creator));
linphone_proxy_config_enable_publish(cfg, FALSE);
linphone_proxy_config_enable_register(cfg, TRUE);
ms_free(identity_str);
if (strcmp(linphone_account_creator_get_domain(creator), "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(linphone_gtk_get_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(linphone_gtk_get_core(), "stun.linphone.org");
linphone_core_set_firewall_policy(linphone_gtk_get_core(), LinphonePolicyUseIce);
}
identity = linphone_address_new(linphone_proxy_config_get_identity(cfg));
info = linphone_auth_info_new(linphone_address_get_username(identity), NULL,
linphone_account_creator_get_password(creator), NULL, NULL, linphone_address_get_domain(identity));
linphone_core_add_auth_info(linphone_gtk_get_core(), info);
linphone_address_destroy(identity);
if (linphone_core_add_proxy_config(linphone_gtk_get_core(), cfg) != -1) {
linphone_core_set_default_proxy(linphone_gtk_get_core(), cfg);
linphone_gtk_load_identities();
}
gtk_assistant_commit(GTK_ASSISTANT(assistant));
if (linphone_account_creator_configure(linphone_gtk_assistant_get_creator(assistant)) != NULL) {
linphone_gtk_load_identities();
}
gtk_assistant_commit(GTK_ASSISTANT(assistant));
break;
default:
break;
......@@ -190,7 +152,7 @@ static int linphone_gtk_assistant_forward(int curpage, gpointer data) {
linphone_account_creator_set_username(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "username"))));
linphone_account_creator_set_password(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "password"))));
linphone_account_creator_set_email(creator, gtk_entry_get_text(GTK_ENTRY(g_object_get_data(G_OBJECT(box), "email"))));
linphone_account_creator_set_subscribe(creator, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(box), "newsletter"))));
linphone_account_creator_enable_newsletter_subscription(creator, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(box), "newsletter"))));
curpage = 5; // Go to page_5_linphone_account_creation_in_progress
break;
case 6:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment