Commit 53dcc192 authored by Gautier Pelloux-Prayer's avatar Gautier Pelloux-Prayer
Browse files

account_creator: change return values to distinguish network error from XMLRPC...

account_creator: change return values to distinguish network error from XMLRPC answer + fix some crashs
parent 9333714b
......@@ -162,7 +162,7 @@ static LinphoneAccountCreatorStatus validate_uri(const char* username, const cha
}
linphone_address_unref(addr);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
static bool_t is_matching_regex(const char *entry, const char* regex) {
......@@ -198,11 +198,11 @@ LinphoneAccountCreatorStatus linphone_account_creator_set_username(LinphoneAccou
return LinphoneAccountCreatorUsernameInvalid;
} else if (regex && !is_matching_regex(username, regex)) {
return LinphoneAccountCreatorUsernameInvalid;
} else if ((status = validate_uri(username, NULL, NULL, NULL)) != LinphoneAccountCreatorOk) {
} else if ((status = validate_uri(username, NULL, NULL, NULL)) != LinphoneAccountCreatorOK) {
return status;
}
set_string(&creator->username, username, TRUE);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
const char * linphone_account_creator_get_username(const LinphoneAccountCreator *creator) {
......@@ -215,7 +215,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_set_password(LinphoneAccou
return LinphoneAccountCreatorPasswordTooShort;
}
set_string(&creator->password, password, FALSE);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
const char * linphone_account_creator_get_password(const LinphoneAccountCreator *creator) {
......@@ -227,7 +227,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_set_transport(LinphoneAcco
return LinphoneAccountCreatorTransportNotSupported;
}
creator->transport = transport;
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
LinphoneTransportType linphone_account_creator_get_transport(const LinphoneAccountCreator *creator) {
......@@ -239,7 +239,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_set_domain(LinphoneAccount
return LinphoneAccountCreatorDomainInvalid;
}
set_string(&creator->domain, domain, TRUE);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
const char * linphone_account_creator_get_domain(const LinphoneAccountCreator *creator) {
......@@ -251,7 +251,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_set_route(LinphoneAccountC
return LinphoneAccountCreatorRouteInvalid;
}
set_string(&creator->route, route, TRUE);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
const char * linphone_account_creator_get_route(const LinphoneAccountCreator *creator) {
......@@ -263,7 +263,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_set_display_name(LinphoneA
return LinphoneAccountCreatorDisplayNameInvalid;
}
set_string(&creator->display_name, display_name, FALSE);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
const char * linphone_account_creator_get_display_name(const LinphoneAccountCreator *creator) {
......@@ -275,7 +275,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_set_email(LinphoneAccountC
return LinphoneAccountCreatorEmailInvalid;
}
set_string(&creator->email, email, TRUE);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
const char * linphone_account_creator_get_email(const LinphoneAccountCreator *creator) {
......@@ -297,10 +297,10 @@ LinphoneAccountCreatorCbs * linphone_account_creator_get_callbacks(const Linphon
static void _test_existence_cb(LinphoneXmlRpcRequest *request) {
LinphoneAccountCreator *creator = (LinphoneAccountCreator *)linphone_xml_rpc_request_get_user_data(request);
if (creator->callbacks->existence_tested != NULL) {
LinphoneAccountCreatorStatus status = LinphoneAccountCreatorFailed;
if ((linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk)
&& (linphone_xml_rpc_request_get_int_response(request) == 0)) {
status = LinphoneAccountCreatorOk;
LinphoneAccountCreatorStatus status = LinphoneAccountCreatorReqFailed;
if (linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) {
int resp = linphone_xml_rpc_request_get_int_response(request);
status = (resp == 0) ? LinphoneAccountCreatorAccountNotExist : LinphoneAccountCreatorAccountExist;
}
creator->callbacks->existence_tested(creator, status);
}
......@@ -312,9 +312,9 @@ LinphoneAccountCreatorStatus linphone_account_creator_test_existence(LinphoneAcc
if (!creator->username || !creator->domain) {
if (creator->callbacks->existence_tested != NULL) {
creator->callbacks->existence_tested(creator, LinphoneAccountCreatorFailed);
creator->callbacks->existence_tested(creator, LinphoneAccountCreatorReqFailed);
}
return LinphoneAccountCreatorFailed;
return LinphoneAccountCreatorReqFailed;
}
identity = ms_strdup_printf("%s@%s", creator->username, creator->domain);
request = linphone_xml_rpc_request_new_with_args("check_account", LinphoneXmlRpcArgInt,
......@@ -325,16 +325,16 @@ LinphoneAccountCreatorStatus linphone_account_creator_test_existence(LinphoneAcc
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
linphone_xml_rpc_request_unref(request);
ms_free(identity);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
static void _test_validation_cb(LinphoneXmlRpcRequest *request) {
LinphoneAccountCreator *creator = (LinphoneAccountCreator *)linphone_xml_rpc_request_get_user_data(request);
if (creator->callbacks->validation_tested != NULL) {
LinphoneAccountCreatorStatus status = LinphoneAccountCreatorFailed;
if ((linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk)
&& (linphone_xml_rpc_request_get_int_response(request) == 1)) {
status = LinphoneAccountCreatorOk;
LinphoneAccountCreatorStatus status = LinphoneAccountCreatorReqFailed;
if (linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) {
int resp = linphone_xml_rpc_request_get_int_response(request);
status = (resp == 0) ? LinphoneAccountCreatorAccountNotValidated : LinphoneAccountCreatorAccountValidated;
}
creator->callbacks->validation_tested(creator, status);
}
......@@ -346,9 +346,9 @@ LinphoneAccountCreatorStatus linphone_account_creator_test_validation(LinphoneAc
if (!creator->username || !creator->domain) {
if (creator->callbacks->validation_tested != NULL) {
creator->callbacks->validation_tested(creator, LinphoneAccountCreatorFailed);
creator->callbacks->validation_tested(creator, LinphoneAccountCreatorReqFailed);
}
return LinphoneAccountCreatorFailed;
return LinphoneAccountCreatorReqFailed;
}
identity = ms_strdup_printf("%s@%s", creator->username, creator->domain);
......@@ -360,16 +360,16 @@ LinphoneAccountCreatorStatus linphone_account_creator_test_validation(LinphoneAc
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
linphone_xml_rpc_request_unref(request);
ms_free(identity);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
static void _create_account_cb(LinphoneXmlRpcRequest *request) {
LinphoneAccountCreator *creator = (LinphoneAccountCreator *)linphone_xml_rpc_request_get_user_data(request);
if (creator->callbacks->create_account != NULL) {
LinphoneAccountCreatorStatus status = LinphoneAccountCreatorFailed;
if ((linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk)
&& (linphone_xml_rpc_request_get_int_response(request) == 0)) {
status = LinphoneAccountCreatorOk;
LinphoneAccountCreatorStatus status = LinphoneAccountCreatorReqFailed;
if (linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) {
int resp = linphone_xml_rpc_request_get_int_response(request);
status = (resp == 0) ? LinphoneAccountCreatorAccountCreated : LinphoneAccountCreatorAccountNotCreated;
}
creator->callbacks->create_account(creator, status);
}
......@@ -379,11 +379,11 @@ LinphoneAccountCreatorStatus linphone_account_creator_create_account(LinphoneAcc
LinphoneXmlRpcRequest *request;
char *identity;
if (!creator->username || !creator->domain) {
if (!creator->username || !creator->domain || !creator->email) {
if (creator->callbacks->create_account != NULL) {
creator->callbacks->create_account(creator, LinphoneAccountCreatorFailed);
creator->callbacks->create_account(creator, LinphoneAccountCreatorReqFailed);
}
return LinphoneAccountCreatorFailed;
return LinphoneAccountCreatorReqFailed;
}
identity = ms_strdup_printf("%s@%s", creator->username, creator->domain);
......@@ -398,7 +398,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_create_account(LinphoneAcc
linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
linphone_xml_rpc_request_unref(request);
ms_free(identity);
return LinphoneAccountCreatorOk;
return LinphoneAccountCreatorOK;
}
LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCreator *creator) {
......
......@@ -36,18 +36,27 @@ extern "C" {
* Enum describing the status of a LinphoneAccountCreator operation.
**/
typedef enum _LinphoneAccountCreatorStatus {
LinphoneAccountCreatorOk = 0,
LinphoneAccountCreatorFailed = 1 << 0,
LinphoneAccountCreatorEmailInvalid = 1 << 1,
LinphoneAccountCreatorUsernameInvalid = 1 << 2,
LinphoneAccountCreatorUsernameTooShort = 1 << 3,
LinphoneAccountCreatorUsernameInvalidSize = 1 << 4,
LinphoneAccountCreatorPasswordTooShort = 1 << 5,
LinphoneAccountCreatorDomainInvalid = 1 << 6,
LinphoneAccountCreatorRouteInvalid = 1 << 7,
LinphoneAccountCreatorDisplayNameInvalid = 1 << 8,
LinphoneAccountCreatorTransportNotSupported = 1 << 9,
LinphoneAccountCreatorOK,
LinphoneAccountCreatorReqFailed,
LinphoneAccountCreatorAccountCreated,
LinphoneAccountCreatorAccountNotCreated,
LinphoneAccountCreatorAccountExist,
LinphoneAccountCreatorAccountNotExist,
LinphoneAccountCreatorAccountValidated,
LinphoneAccountCreatorAccountNotValidated,
LinphoneAccountCreatorEmailInvalid,
LinphoneAccountCreatorUsernameInvalid,
LinphoneAccountCreatorUsernameTooShort,
LinphoneAccountCreatorUsernameInvalidSize,
LinphoneAccountCreatorPasswordTooShort,
LinphoneAccountCreatorDomainInvalid,
LinphoneAccountCreatorRouteInvalid,
LinphoneAccountCreatorDisplayNameInvalid,
LinphoneAccountCreatorTransportNotSupported,
} LinphoneAccountCreatorStatus;
/**
......@@ -245,21 +254,21 @@ LINPHONE_PUBLIC LinphoneAccountCreatorCbs * linphone_account_creator_get_callbac
/**
* Send an XML-RPC request to test the existence of a Linphone account.
* @param[in] creator LinphoneAccountCreator object
* @return LinphoneAccountCreatorOk if the request has been sent, LinphoneAccountCreatorFailed otherwise
* @return LinphoneAccountCreatorOk if the request has been sent, LinphoneAccountCreatorReqFailed otherwise
**/
LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_test_existence(LinphoneAccountCreator *creator);
/**
* Send an XML-RPC request to test the validation of a Linphone account.
* @param[in] creator LinphoneAccountCreator object
* @return LinphoneAccountCreatorOk if the request has been sent, LinphoneAccountCreatorFailed otherwise
* @return LinphoneAccountCreatorOk if the request has been sent, LinphoneAccountCreatorReqFailed otherwise
**/
LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_test_validation(LinphoneAccountCreator *creator);
/**
* Send an XML-RPC request to create a Linphone account.
* @param[in] creator LinphoneAccountCreator object
* @return LinphoneAccountCreatorOk if the request has been sent, LinphoneAccountCreatorFailed otherwise
* @return LinphoneAccountCreatorOk if the request has been sent, LinphoneAccountCreatorReqFailed otherwise
**/
LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_create_account(LinphoneAccountCreator *creator);
......
......@@ -33,7 +33,7 @@ static LinphoneAccountCreator * linphone_gtk_assistant_get_creator(GtkWidget *w)
static void linphone_gtk_create_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status) {
GtkWidget *assistant = (GtkWidget *)linphone_account_creator_get_user_data(creator);
if (status == LinphoneAccountCreatorOk) {
if (status == LinphoneAccountCreatorAccountCreated) {
// 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
......@@ -50,7 +50,7 @@ static void create_account(GtkWidget *assistant) {
static void linphone_gtk_test_account_validation_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status) {
GtkWidget *assistant = (GtkWidget *)linphone_account_creator_get_user_data(creator);
if (status == LinphoneAccountCreatorOk) {
if (status == LinphoneAccountCreatorAccountValidated) {
// Go to page_9_finish
gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), 9);
} else {
......@@ -209,14 +209,18 @@ static gboolean update_interface_with_username_availability(GtkWidget *page) {
GtkWidget *assistant = gtk_widget_get_toplevel(page);
GtkImage* isUsernameOk = GTK_IMAGE(linphone_gtk_get_widget(assistant, "p4_image_username_ok"));
GtkLabel* usernameError = GTK_LABEL(linphone_gtk_get_widget(assistant, "p4_label_error"));
int account_existing = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(page), "is_username_used"));
int account_status = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(page), "is_username_used"));
if (account_existing == 0) {
if (account_status == LinphoneAccountCreatorAccountNotExist) {
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) {
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);
} else {
gtk_label_set_text(usernameError, "Username is already in use!");
gtk_label_set_text(usernameError, _("Failed to check username availability. Please try again later."));
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);
}
......@@ -227,8 +231,7 @@ static gboolean update_interface_with_username_availability(GtkWidget *page) {
static void linphone_gtk_test_account_existence_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status) {
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)));
gboolean account_existing = (status != LinphoneAccountCreatorOk);
g_object_set_data(G_OBJECT(page), "is_username_used", GINT_TO_POINTER(account_existing));
g_object_set_data(G_OBJECT(page), "is_username_used", GINT_TO_POINTER(status));
gdk_threads_add_idle((GSourceFunc)update_interface_with_username_availability, page);
}
......@@ -323,7 +326,7 @@ static void linphone_gtk_assistant_init(GtkWidget *w) {
linphone_account_creator_cbs_set_validation_tested(cbs, linphone_gtk_test_account_validation_cb);
linphone_account_creator_cbs_set_create_account(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);
}
......
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