From: Dirk-Jan C. Binnema Date: Wed, 1 Aug 2007 15:45:03 +0000 (+0000) Subject: * validate the domain names X-Git-Tag: git_migration_finished~2665 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=193d70ae22fc51b52d327e63791a025d5a4dcba8 * validate the domain names Fixes: NB#64809 pmo-trunk-r2892 --- diff --git a/src/maemo/modest-account-settings-dialog.c b/src/maemo/modest-account-settings-dialog.c index 33cd6d0..4001977 100644 --- a/src/maemo/modest-account-settings-dialog.c +++ b/src/maemo/modest-account-settings-dialog.c @@ -851,6 +851,9 @@ static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self) return GTK_WIDGET (scrollwin); } + + + static gboolean check_data (ModestAccountSettingsDialog *self) { @@ -871,8 +874,8 @@ check_data (ModestAccountSettingsDialog *self) return FALSE; } } - - /* Check that the email address is valud: */ + + /* 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)) return FALSE; @@ -888,8 +891,39 @@ check_data (ModestAccountSettingsDialog *self) return FALSE; } - /* Find a suitable authentication method when secure authentication is desired */ + /* 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)) + 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); + 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)) + 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"));*/ + hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername")); + + /* Return focus to the email address entry: */ + gtk_widget_grab_focus (self->entry_outgoingserver); + gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1); + return FALSE; + } + + + /* Find a suitable authentication method when secure authentication is desired */ + gint port_num = hildon_number_editor_get_value ( HILDON_NUMBER_EDITOR (self->entry_incoming_port)); const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username)); @@ -942,11 +976,10 @@ check_data (ModestAccountSettingsDialog *self) } } } + + - /* TODO: The UI Spec wants us to check that the servernames are valid, - * but does not specify how. - */ - + return TRUE; } /* diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 6b67214..f01e706 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -79,7 +79,7 @@ struct _url_match_t { { "(file|rtsp|http|ftp|https)://[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]+[-A-Za-z0-9_$%&=?/~#]",\ NULL, NULL },\ { "www\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\ - NULL, "http://" },\ + NULL, "http://" }, \ { "ftp\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\ NULL, "ftp://" },\ { "(voipto|callto|chatto|jabberto|xmpp):[-_a-z@0-9.\\+]+", \ @@ -1069,6 +1069,32 @@ modest_text_utils_get_display_date (time_t date) return g_strdup(date_buf); } + +gboolean +modest_text_utils_validate_domain_name (const gchar *domain) +{ + gboolean valid = FALSE; + regex_t rx; + const gchar* domain_regex = "^[a-z0-9]([.]?[a-z0-9-])*[a-z0-9]$"; + + if (!domain) + return FALSE; + + /* domain name: all alphanum or '-' or '.', + * but beginning/ending in alphanum */ + if (regcomp (&rx, domain_regex, REG_ICASE|REG_EXTENDED|REG_NOSUB)) { + g_warning ("BUG: error in regexp"); + return FALSE; + } + + valid = (regexec (&rx, domain, 1, NULL, 0) == 0); + regfree (&rx); + + return valid; +} + + + gboolean modest_text_utils_validate_email_address (const gchar *email_address, const gchar **invalid_char_position) { diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 401907f..5425d60 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -268,6 +268,17 @@ gchar* modest_text_utils_get_display_date (time_t date); gchar * modest_text_utils_get_display_size (guint64 size); + +/** + * modest_text_utils_validate_domain_name: + * @email_address: a NULL-terminated string + * + * validates the domain name passed as argument + * + * Returns: TRUE if the domain name is valid, FALSE otherwise + **/ +gboolean modest_text_utils_validate_domain_name (const gchar *domain); + /** * modest_text_utils_validate_email_address: * @email_address: a string