Commit b41b9204 authored by Erwan Croze's avatar Erwan Croze 👋🏻
Browse files

Refactoring of account creator + tester of account creator

parent 54a0a0ff
This diff is collapsed.
......@@ -1389,43 +1389,73 @@ BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneXmlRpcSession);
* Account creator interface *
****************************************************************************/
struct _LinphoneAccountCreatorCbs {
struct _LinphoneAccountCreatorRequestCbs {
belle_sip_object_t base;
void *user_data;
LinphoneAccountCreatorCbsStatusCb is_account_used;
LinphoneAccountCreatorCbsStatusCb create_account;
LinphoneAccountCreatorCbsStatusCb activate_account;
LinphoneAccountCreatorCbsStatusCb is_account_activated;
LinphoneAccountCreatorCbsStatusCb is_phone_number_used;
LinphoneAccountCreatorCbsStatusCb link_phone_number_with_account;
LinphoneAccountCreatorCbsStatusCb activate_phone_number_link;
LinphoneAccountCreatorCbsStatusCb recover_phone_account;
LinphoneAccountCreatorCbsStatusCb is_account_linked;
LinphoneAccountCreatorCbsStatusCb update_hash;
LinphoneAccountCreatorRequestFunc create_account_request_cb; /**< Request to create account */
LinphoneAccountCreatorRequestFunc is_account_exist_request_cb; /**< Request to know if account exist */
LinphoneAccountCreatorRequestFunc activate_account_request_cb; /**< Request to activate account */
LinphoneAccountCreatorRequestFunc is_account_activated_request_cb; /**< Request to know if account is activated */
LinphoneAccountCreatorRequestFunc link_account_request_cb; /**< Request to link account with an alias */
LinphoneAccountCreatorRequestFunc activate_alias_request_cb; /**< Request to activate the link of alias */
LinphoneAccountCreatorRequestFunc is_alias_used_request_cb; /**< Request to know if alias is used */
LinphoneAccountCreatorRequestFunc is_account_linked_request_cb; /**< Request to know if account is linked with an alias */
LinphoneAccountCreatorRequestFunc recover_account_request_cb; /**< Request to recover account */
LinphoneAccountCreatorRequestFunc update_account_request_cb; /**< Request to update account */
};
BELLE_SIP_DECLARE_VPTR(LinphoneAccountCreatorRequestCbs);
struct _LinphoneAccountCreatorResponseCbs {
belle_sip_object_t base;
void *user_data;
LinphoneAccountCreatorResponseFunc create_account_response_cb; /**< Response of create_account request */
LinphoneAccountCreatorResponseFunc is_account_exist_response_cb; /**< Response of is_account_exist request */
LinphoneAccountCreatorResponseFunc activate_account_response_cb; /**< Response of activate_account request */
LinphoneAccountCreatorResponseFunc is_account_activated_response_cb; /**< Response of is_account_activated request */
LinphoneAccountCreatorResponseFunc link_account_response_cb; /**< Response of link_account request */
LinphoneAccountCreatorResponseFunc activate_alias_response_cb; /**< Response of activation alias */
LinphoneAccountCreatorResponseFunc is_alias_used_response_cb; /**< Response of is_alias_used request */
LinphoneAccountCreatorResponseFunc is_account_linked_response_cb; /**< Response of is_account_linked request */
LinphoneAccountCreatorResponseFunc recover_account_response_cb; /**< Response of recover_account request */
LinphoneAccountCreatorResponseFunc update_account_response_cb; /**< Response of update_account request */
};
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneAccountCreatorCbs);
BELLE_SIP_DECLARE_VPTR(LinphoneAccountCreatorResponseCbs);
struct _LinphoneAccountCreator {
belle_sip_object_t base;
void *user_data;
LinphoneAccountCreatorCbs *callbacks;
LinphoneXmlRpcSession *xmlrpc_session;
LinphoneCore *core;
char *xmlrpc_url;
char *username;
char *phone_number;
char *password;
char *domain;
char *route;
char *email;
bool_t subscribe_to_newsletter;
char *display_name;
LinphoneTransportType transport;
char *activation_code;
char *ha1;
char *phone_country_code;
char *language;
/* AccountCreator */
LinphoneAccountCreatorRequestCbs *requests_cbs; /**< Account creator requests cbs */
LinphoneAccountCreatorResponseCbs *responses_cbs; /**< Account creator responses cbs */
LinphoneXmlRpcSession *xmlrpc_session; /**< XML-RPC session */
LinphoneProxyConfig *proxy_cfg; /**< Default proxy config */
/* User */
char *username; /**< Username */
char *display_name; /**< Display name */
/* Password */
char *password; /**< Plain text password */
char *ha1; /**< Hash password */
/* Phone Number(Alias) */
char *phone_number; /**< User phone number*/
char *phone_country_code; /**< User phone number country code */
/* Email(Alias) */
char *email; /**< User email */
/* Misc */
char *language; /**< User language */
char *activation_code; /**< Account validation code */
};
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneAccountCreator);
......@@ -1576,7 +1606,8 @@ LINPHONE_PUBLIC LinphoneImEncryptionEngine *linphone_im_encryption_engine_new(Li
BELLE_SIP_DECLARE_TYPES_BEGIN(linphone,10000)
BELLE_SIP_TYPE_ID(LinphoneAccountCreator),
BELLE_SIP_TYPE_ID(LinphoneAccountCreatorCbs),
BELLE_SIP_TYPE_ID(LinphoneAccountCreatorRequestCbs),
BELLE_SIP_TYPE_ID(LinphoneAccountCreatorResponseCbs),
BELLE_SIP_TYPE_ID(LinphoneBuffer),
BELLE_SIP_TYPE_ID(LinphoneContactProvider),
BELLE_SIP_TYPE_ID(LinphoneContactSearch),
......
......@@ -31,9 +31,9 @@ static LinphoneAccountCreator * linphone_gtk_assistant_get_creator(GtkWidget *w)
return (LinphoneAccountCreator *)g_object_get_data(G_OBJECT(w), "creator");
}
static void linphone_gtk_create_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, const char* resp) {
static void linphone_gtk_create_account_cb(LinphoneAccountCreator *creator, LinphoneRequestStatus status, const char* resp) {
GtkWidget *assistant = (GtkWidget *)linphone_account_creator_get_user_data(creator);
if (status == LinphoneAccountCreatorAccountCreated) {
if (status == LinphoneRequestAccountCreated) {
// Go to page_6_linphone_account_validation_wait
gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), 6);
} else { // Error when attempting to create the account
......@@ -48,9 +48,9 @@ static void create_account(GtkWidget *assistant) {
linphone_account_creator_create_account(creator);
}
static void linphone_gtk_test_account_validation_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, const char* resp) {
static void linphone_gtk_test_account_validation_cb(LinphoneAccountCreator *creator, LinphoneRequestStatus status, const char* resp) {
GtkWidget *assistant = (GtkWidget *)linphone_account_creator_get_user_data(creator);
if (status == LinphoneAccountCreatorAccountActivated) {
if (status == LinphoneRequestAccountActivated) {
// Go to page_9_finish
gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), 9);
} else {
......@@ -61,7 +61,9 @@ static void linphone_gtk_test_account_validation_cb(LinphoneAccountCreator *crea
static void check_account_validation(GtkWidget *assistant) {
LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(assistant);
linphone_account_creator_is_account_activated(creator);
(linphone_account_creator_requests_cbs_get_is_account_activated_cb(
linphone_account_creator_get_requests_cbs(creator))
)(creator);
}
void linphone_gtk_assistant_closed(GtkWidget *w) {
......@@ -79,9 +81,7 @@ void linphone_gtk_assistant_prepare(GtkWidget *assistant) {
check_account_validation(assistant);
break;
case 9:
if (linphone_account_creator_configure(linphone_gtk_assistant_get_creator(assistant)) != NULL) {
linphone_gtk_load_identities();
}
linphone_gtk_load_identities();
gtk_assistant_commit(GTK_ASSISTANT(assistant));
break;
default:
......@@ -128,12 +128,8 @@ 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;
......@@ -143,8 +139,6 @@ 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;
......@@ -215,11 +209,11 @@ static gboolean update_interface_with_username_availability(GtkWidget *page) {
GtkLabel* usernameError = GTK_LABEL(linphone_gtk_get_widget(assistant, "p4_label_error"));
int account_status = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(page), "is_username_used"));
if (account_status == LinphoneAccountCreatorAccountNotExist) {
if (account_status == LinphoneRequestAccountNotExist) {
g_object_set_data(G_OBJECT(page), "is_username_available", GINT_TO_POINTER(1));
gtk_image_set_from_stock(isUsernameOk, GTK_STOCK_OK, GTK_ICON_SIZE_LARGE_TOOLBAR);
gtk_label_set_text(usernameError, "");
} else if (account_status == LinphoneAccountCreatorAccountExist) {
} else if (account_status == LinphoneRequestAccountExist) {
gtk_label_set_text(usernameError, _("Username is already in use!"));
g_object_set_data(G_OBJECT(page), "is_username_available", GINT_TO_POINTER(0));
gtk_image_set_from_stock(isUsernameOk, GTK_STOCK_NO, GTK_ICON_SIZE_LARGE_TOOLBAR);
......@@ -232,7 +226,7 @@ static gboolean update_interface_with_username_availability(GtkWidget *page) {
return FALSE;
}
static void linphone_gtk_test_account_existence_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, const char* resp) {
static void linphone_gtk_test_account_existence_cb(LinphoneAccountCreator *creator, LinphoneRequestStatus status, const char* resp) {
GtkWidget *assistant = (GtkWidget *)linphone_account_creator_get_user_data(creator);
GtkWidget *page = gtk_assistant_get_nth_page(GTK_ASSISTANT(assistant), gtk_assistant_get_current_page(GTK_ASSISTANT(assistant)));
g_object_set_data(G_OBJECT(page), "is_username_used", GINT_TO_POINTER(status));
......@@ -243,7 +237,9 @@ static gboolean check_username_availability(GtkWidget *assistant) {
LinphoneAccountCreator *creator = linphone_gtk_assistant_get_creator(assistant);
GtkWidget *page = gtk_assistant_get_nth_page(GTK_ASSISTANT(assistant), gtk_assistant_get_current_page(GTK_ASSISTANT(assistant)));
g_object_set_data(G_OBJECT(page), "usernameAvailabilityTimerID", GUINT_TO_POINTER(0));
linphone_account_creator_is_account_used(creator);
(linphone_account_creator_requests_cbs_get_is_account_exist_cb(
linphone_account_creator_get_requests_cbs(creator))
)(creator);
return FALSE;
}
......@@ -257,8 +253,6 @@ 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"));
......@@ -324,11 +318,11 @@ void linphone_gtk_account_creation_password_changed(GtkEntry *entry) {
static void linphone_gtk_assistant_init(GtkWidget *w) {
LinphoneAccountCreator *creator = linphone_account_creator_new(linphone_gtk_get_core(), "https://subscribe.linphone.org:444/wizard.php");
LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
LinphoneAccountCreatorResponseCbs *cbs = linphone_account_creator_get_responses_cbs(creator);
linphone_account_creator_set_user_data(creator, w);
linphone_account_creator_cbs_set_is_account_used(cbs, linphone_gtk_test_account_existence_cb);
linphone_account_creator_cbs_set_is_account_activated(cbs, linphone_gtk_test_account_validation_cb);
linphone_account_creator_cbs_set_create_account(cbs, linphone_gtk_create_account_cb);
linphone_account_creator_responses_cbs_set_is_account_exist_cb(cbs, linphone_gtk_test_account_existence_cb);
linphone_account_creator_responses_cbs_set_is_account_activated_cb(cbs, linphone_gtk_test_account_validation_cb);
linphone_account_creator_responses_cbs_set_create_account_cb(cbs, linphone_gtk_create_account_cb);
g_object_set_data(G_OBJECT(w), "creator", creator);
gtk_assistant_set_forward_page_func(GTK_ASSISTANT(w), linphone_gtk_assistant_forward, w, NULL);
......
This diff is collapsed.
......@@ -28,64 +28,127 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/**
* The LinphoneAccountCreator object used to create an account on a server via XML-RPC.
* @ingroup misc
* The LinphoneAccountCreator object used to configure an account on a server via XML-RPC.
* @ingroup account_creator
**/
typedef struct _LinphoneAccountCreator LinphoneAccountCreator;
/**
* An object to handle the callbacks for handling the LinphoneAccountCreator operations.
* @ingroup misc
* An object to handle the requests callbacks for handling the LinphoneAccountCreator server requests.
* @ingroup account_creator
**/
typedef struct _LinphoneAccountCreatorCbs LinphoneAccountCreatorCbs;
typedef struct _LinphoneAccountCreatorRequestCbs LinphoneAccountCreatorRequestCbs;
/**
* Enum describing the status of a LinphoneAccountCreator operation.
* @ingroup misc
* An object to handle the responses callbacks for handling the LinphoneAccountCreator operations.
* @ingroup account_creator
**/
typedef enum _LinphoneAccountCreatorStatus {
LinphoneAccountCreatorOK,
LinphoneAccountCreatorReqFailed,
typedef struct _LinphoneAccountCreatorResponseCbs LinphoneAccountCreatorResponseCbs;
LinphoneAccountCreatorAccountCreated,
LinphoneAccountCreatorAccountNotCreated,
LinphoneAccountCreatorAccountExist,
LinphoneAccountCreatorAccountExistWithAlias,
LinphoneAccountCreatorAccountNotExist,
LinphoneAccountCreatorAccountActivated,
LinphoneAccountCreatorAccountAlreadyActivated,
LinphoneAccountCreatorAccountNotActivated,
/**
* Enum describing Phone number checking.
* @ingroup account_creator_checking
**/
typedef enum _LinphonePhoneNumberCheck {
LinphonePhoneNumberOk = 0x1, /**< Phone number ok */
LinphonePhoneNumberTooShort = 0x2, /**< Phone number too short */
LinphonePhoneNumberTooLong = 0x4, /**< Phone number too long */
LinphonePhoneNumberCountryCodeInvalid = 0x8, /**< Country code invalid */
LinphonePhoneNumberInvalid = 0x10, /**< Phone number invalid */
} LinphonePhoneNumberCheck;
LinphoneAccountCreatorAccountLinked,
LinphoneAccountCreatorAccountNotLinked,
/**
* A mask of #LinphonePhoneNumberCheck values
* @ingroup account_creator_checking
*/
typedef unsigned int LinphonePhoneNumberMask;
LinphoneAccountCreatorEmailInvalid,
/**
* Enum describing Username checking.
* @ingroup account_creator_checking
**/
typedef enum _LinphoneUsernameCheck {
LinphoneUsernameOk, /**< Username ok */
LinphoneUsernameTooShort, /**< Username too short */
LinphoneUsernameTooLong, /**< Username too long */
LinphoneUsernameInvalidCharacters, /**< Contain invalid characters */
LinphoneUsernameInvalid, /**< Invalid username */
} LinphoneUsernameCheck;
LinphoneAccountCreatorUsernameInvalid,
LinphoneAccountCreatorUsernameTooShort,
LinphoneAccountCreatorUsernameTooLong,
LinphoneAccountCreatorUsernameInvalidSize,
/**
* Enum describing Email checking.
* @ingroup account_creator_checking
**/
typedef enum _LinphoneEmailCheck {
LinphoneEmailOk, /**< Email ok */
LinphoneEmailMalformed, /**< Email malformed */
LinphoneEmailInvalidCharacters, /**< Contain invalid characters */
} LinphoneEmailCheck;
LinphoneAccountCreatorPhoneNumberInvalid,
LinphoneAccountCreatorPhoneNumberTooShort,
LinphoneAccountCreatorPhoneNumberTooLong,
LinphoneAccountCreatorPhoneNumberUsedAccount,
LinphoneAccountCreatorPhoneNumberUsedAlias,
LinphoneAccountCreatorPhoneNumberNotUsed,
/**
* Enum describing Password checking.
* @ingroup account_creator_checking
**/
typedef enum _LinphonePasswordCheck {
LinphonePasswordOk, /**< Password ok */
LinphonePasswordTooShort, /**< Password too short */
LinphonePasswordTooLong, /**< Password too long */
LinphonePasswordInvalidCharacters, /**< Contain invalid characters */
LinphonePasswordMissingCharacters, /**< Missing specific characters */
} LinphonePasswordCheck;
LinphoneAccountCreatorPasswordTooShort,
LinphoneAccountCreatorPasswordTooLong,
/**
* Enum describing language checking.
* @ingroup account_creator_checking
**/
typedef enum _LinphoneLanguageCheck {
LinphoneLanguageOk, /**< Language ok */
} LinphoneLanguageCheck;
LinphoneAccountCreatorDomainInvalid,
LinphoneAccountCreatorRouteInvalid,
LinphoneAccountCreatorDisplayNameInvalid,
LinphoneAccountCreatorTransportNotSupported,
LinphoneAccountCreatorCountryCodeInvalid,
/**
* Enum describing Activation code checking.
* @ingroup account_creator_checking
**/
typedef enum _LinphoneActivationCodeCheck {
LinphoneActivationCodeOk, /**< Activation code ok */
LinphoneActivationCodeTooShort, /**< Activation code too short */
LinphoneActivationCodeTooLong, /**< Activation code too long */
LinphoneActivationCodeInvalidCharacters, /**< Contain invalid characters */
} LinphoneActivationCodeCheck;
LinphoneAccountCreatorErrorServer,
} LinphoneAccountCreatorStatus;
/**
* Enum describing the status of server request.
* @ingroup account_creator_request
**/
typedef enum _LinphoneRequestStatus {
/** Request status **/
LinphoneRequestOk, /**< Request passed */
LinphoneRequestFailed, /**< Request failed */
LinphoneRequestMissingArguments, /**< Request failed due to missing argument(s) */
LinphoneRequestMissingCallbacks, /**< Request failed due to missing callback(s) */
/** Account status **/
/* Creation */
LinphoneRequestAccountCreated, /**< Account created */
LinphoneRequestAccountNotCreated, /**< Account not created */
/* Existence */
LinphoneRequestAccountExist, /**< Account exist */
LinphoneRequestAccountExistWithAlias, /**< Account exist with alias */
LinphoneRequestAccountNotExist, /**< Account not exist */
LinphoneRequestAliasIsAccount, /**< Account was created with Alias */
LinphoneRequestAliasExist, /**< Alias exist */
LinphoneRequestAliasNotExist, /**< Alias not exist */
/* Activation */
LinphoneRequestAccountActivated, /**< Account activated */
LinphoneRequestAccountAlreadyActivated, /**< Account already activated */
LinphoneRequestAccountNotActivated, /**< Account not activated */
/* Linking */
LinphoneRequestAccountLinked, /**< Account linked */
LinphoneRequestAccountNotLinked, /**< Account not linked */
/** Server **/
LinphoneRequestErrorServer, /**< Error server */
} LinphoneRequestStatus;
struct SalAddress;
......
This diff is collapsed.
......@@ -3,11 +3,12 @@ domain=sip.accounttest.org
password_max_length=8
password_min_length=3
username_length=4
username_max_length=8
username_max_length=14
username_min_length=3
username_regex=^[a-z0-9_.\-]*$
xmlrpc_url=https://sip2.linphone.org:445/wizard.php
[proxy]
[proxy_default_values]
reg_proxy=<sip:sip2.linphone.org:5072>
realm=sip.accounttest.org
reg_identity=sip:user@sip.accounttest.org
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