From afc5a07e90bac68b3b9ac41971559365147ba2ca Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Thu, 16 Aug 2007 10:20:56 +0000 Subject: [PATCH 1/1] 2007-08-16 Murray Cumming * src/maemo/easysetup/modest-easysetup-wizard.c: (get_entered_account_title), (on_before_next), (entry_is_empty), (create_account): * src/maemo/modest-account-settings-dialog.c: (get_entered_account_title), (on_button_signature), (check_data), (save_configuration), (entry_is_empty): Strip the account title of whitespace at the start and end before using it or checking it. This means that an all-whitespace title is not allowed, fixing projects.maemo.org bug NB#64977. pmo-trunk-r3000 --- ChangeLog2 | 12 ++++ src/maemo/easysetup/modest-easysetup-wizard.c | 59 ++++++++++++++--- src/maemo/modest-account-settings-dialog.c | 85 +++++++++++++++++++------ 3 files changed, 130 insertions(+), 26 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index c9aa565..1fdd0b6 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,15 @@ +2007-08-16 Murray Cumming + + * src/maemo/easysetup/modest-easysetup-wizard.c: + (get_entered_account_title), (on_before_next), (entry_is_empty), + (create_account): + * src/maemo/modest-account-settings-dialog.c: + (get_entered_account_title), (on_button_signature), (check_data), + (save_configuration), (entry_is_empty): + Strip the account title of whitespace at the start and end before + using it or checking it. This means that an all-whitespace title + is not allowed, fixing projects.maemo.org bug NB#64977. + 2007-08-15 Murray Cumming * src/modest-ui-actions.h: diff --git a/src/maemo/easysetup/modest-easysetup-wizard.c b/src/maemo/easysetup/modest-easysetup-wizard.c index 56377c8..4be58b7 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard.c +++ b/src/maemo/easysetup/modest-easysetup-wizard.c @@ -1329,6 +1329,30 @@ static void set_default_custom_servernames (ModestEasysetupWizardDialog *account } } +static gchar* +get_entered_account_title (ModestEasysetupWizardDialog *account_wizard) +{ + const gchar* account_title = + gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title)); + if (!account_title || (strlen (account_title) == 0)) + return NULL; + else { + /* Strip it of whitespace at the start and end: */ + gchar *result = g_strdup (account_title); + result = g_strstrip (result); + + if (!result) + return NULL; + + if (strlen (result) == 0) { + g_free (result); + return NULL; + } + + return result; + } +} + static gboolean on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page) { @@ -1340,8 +1364,8 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget * */ if (current_page == account_wizard->page_account_details) { /* Check that the title is not already in use: */ - const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title)); - if ((!account_title) || (strlen(account_title) == 0)) + gchar* account_title = get_entered_account_title (account_wizard); + if (!account_title) return FALSE; /* Aavoid a clash with an existing display name: */ @@ -1431,8 +1455,19 @@ static gboolean entry_is_empty (GtkWidget *entry) const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry)); if ((!text) || (strlen(text) == 0)) return TRUE; - else - return FALSE; + else { + /* Strip it of whitespace at the start and end: */ + gchar *stripped = g_strdup (text); + stripped = g_strstrip (stripped); + + if (!stripped) + return TRUE; + + const gboolean result = (strlen (stripped) == 0); + + g_free (stripped); + return result; + } } static void @@ -1541,7 +1576,7 @@ create_account (ModestEasysetupWizardDialog *self, gboolean enabled) { ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self); - const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title)); + gchar* display_name = get_entered_account_title (self); /* Some checks: */ if (!display_name) @@ -1551,8 +1586,10 @@ create_account (ModestEasysetupWizardDialog *self, gboolean enabled) * and changed that name accordingly, * but let's check again just in case: */ - if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name)) + if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name)) { + g_free (display_name); return FALSE; + } /* Increment the non-user visible name if necessary, * based on the display name: */ @@ -1623,8 +1660,10 @@ create_account (ModestEasysetupWizardDialog *self, gboolean enabled) !modest_protocol_info_is_secure(protocol_security_incoming)) { GList* methods = check_for_supported_auth_methods(self); - if (!methods) + if (!methods) { + g_free (display_name); return FALSE; + } else protocol_authentication_incoming = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data)); } @@ -1654,6 +1693,7 @@ create_account (ModestEasysetupWizardDialog *self, gboolean enabled) if (!created) { /* TODO: Provide a Logical ID for the text: */ show_error (GTK_WIDGET (self), _("An error occurred while creating the incoming account.")); + g_free (display_name); return FALSE; } @@ -1729,6 +1769,7 @@ create_account (ModestEasysetupWizardDialog *self, gboolean enabled) if (!created) { /* TODO: Provide a Logical ID for the text: */ show_error (GTK_WIDGET (self), _("An error occurred while creating the outgoing account.")); + g_free (display_name); return FALSE; } @@ -1744,6 +1785,7 @@ create_account (ModestEasysetupWizardDialog *self, gboolean enabled) if (!created) { /* TODO: Provide a Logical ID for the text: */ show_error (GTK_WIDGET (self), _("An error occurred while creating the account.")); + g_free (display_name); return FALSE; } @@ -1782,6 +1824,7 @@ create_account (ModestEasysetupWizardDialog *self, gboolean enabled) self->saved_account_name = g_strdup (account_name); g_free (account_name); - + g_free (display_name); + return result; } diff --git a/src/maemo/modest-account-settings-dialog.c b/src/maemo/modest-account-settings-dialog.c index 9e4b479..34f183f 100644 --- a/src/maemo/modest-account-settings-dialog.c +++ b/src/maemo/modest-account-settings-dialog.c @@ -368,6 +368,31 @@ create_page_account_details (ModestAccountSettingsDialog *self) return GTK_WIDGET (box); } +static gchar* +get_entered_account_title (ModestAccountSettingsDialog *dialog) +{ + const gchar* account_title = + gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title)); + if (!account_title || (strlen (account_title) == 0)) + return NULL; + else { + /* Strip it of whitespace at the start and end: */ + gchar *result = g_strdup (account_title); + result = g_strstrip (result); + + if (!result) + return NULL; + + if (strlen (result) == 0) { + g_free (result); + return NULL; + } + + return result; + } +} + + static void on_button_signature (GtkButton *button, gpointer user_data) { @@ -380,10 +405,12 @@ on_button_signature (GtkButton *button, gpointer user_data) gboolean use_signature = FALSE; gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name, &use_signature); - const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title)); + gchar* account_title = get_entered_account_title (self); modest_signature_editor_dialog_set_settings ( MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog), use_signature, signature, account_title); + g_free (account_title); + account_title = NULL; g_free (signature); signature = NULL; } @@ -900,8 +927,8 @@ static gboolean check_data (ModestAccountSettingsDialog *self) { /* Check that the title is not already in use: */ - const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title)); - if ((!account_title) || (strlen(account_title) == 0)) + gchar* account_title = get_entered_account_title (self); + if (!account_title) return FALSE; /* Should be prevented already anyway. */ if (strcmp(account_title, self->original_account_title) != 0) { @@ -913,14 +940,19 @@ check_data (ModestAccountSettingsDialog *self) /* Warn the user via a dialog: */ hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing")); + g_free (account_title); return FALSE; } } + + g_free (account_title); + account_title = NULL; /* Check that the email address is valid: */ const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email)); - if ((!email_address) || (strlen(email_address) == 0)) + if ((!email_address) || (strlen(email_address) == 0)) { return FALSE; + } if (!modest_text_utils_validate_email_address (email_address, NULL)) { /* Warn the user via a dialog: */ @@ -935,23 +967,27 @@ check_data (ModestAccountSettingsDialog *self) /* make sure the domain name for the incoming server is valid */ const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver)); - if ((!hostname) || (strlen(hostname) == 0)) + if ((!hostname) || (strlen(hostname) == 0)) { return FALSE; + } + if (!modest_text_utils_validate_domain_name (hostname)) { /* Warn the user via a dialog: */ /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/ hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername")); - /* Return focus to the email address entry: */ - gtk_widget_grab_focus (self->entry_incomingserver); + /* Return focus to the email address entry: */ + gtk_widget_grab_focus (self->entry_incomingserver); gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1); return FALSE; } /* make sure the domain name for the outgoing server is valid */ const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver)); - if ((!hostname2) || (strlen(hostname2) == 0)) + if ((!hostname2) || (strlen(hostname2) == 0)) { return FALSE; + } + if (!modest_text_utils_validate_domain_name (hostname2)) { /* Warn the user via a dialog: */ /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/ @@ -965,7 +1001,7 @@ check_data (ModestAccountSettingsDialog *self) /* Check that the port numbers are acceptable: */ if (!check_hildon_number_editor_and_warn_value_not_in_range ( - HILDON_NUMBER_EDITOR (self->entry_incoming_port), PORT_MIN, PORT_MAX)){ + HILDON_NUMBER_EDITOR (self->entry_incoming_port), PORT_MIN, PORT_MAX)) { return FALSE; } @@ -1030,9 +1066,6 @@ check_data (ModestAccountSettingsDialog *self) } } - - - return TRUE; } /* @@ -1509,18 +1542,23 @@ save_configuration (ModestAccountSettingsDialog *dialog) /* Set the changed account title last, to simplify the previous code: */ - const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title)); - if ((!account_title) || (strlen(account_title) == 0)) + gchar* account_title = get_entered_account_title (dialog); + if (!account_title) return FALSE; /* Should be prevented already anyway. */ if (strcmp(account_title, account_name) != 0) { /* Change the title: */ - gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name, + const gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name, MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */); - if (!test) + if (!test) { + g_free (account_title); return FALSE; + } } + g_free (account_title); + account_title = NULL; + /* Save connection-specific SMTP server accounts: */ if (dialog->specific_window) { return modest_connection_specific_smtp_window_save_server_accounts ( @@ -1538,8 +1576,19 @@ static gboolean entry_is_empty (GtkWidget *entry) const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry)); if ((!text) || (strlen(text) == 0)) return TRUE; - else - return FALSE; + else { + /* Strip it of whitespace at the start and end: */ + gchar *stripped = g_strdup (text); + stripped = g_strstrip (stripped); + + if (!stripped) + return TRUE; + + const gboolean result = (strlen (stripped) == 0); + + g_free (stripped); + return result; + } } static void -- 1.7.9.5